Commit Graph
993 Commits
Author SHA1 Message Date
swaitsandClaude 724edc61f3 fix(build): the shipped program checks integer overflow, as the tested one does
The release profile left overflow-checks off, so an integer that
overflows wrapped silently in the program that ships and panicked in
the build the tests run: the tests were checking a program nobody runs.
Money itself is Decimal and goes through the kernel's checked
arithmetic; this covers the integers around it (counts, sequence
numbers, minor units, lengths).

Checked: a release build passes -C overflow-checks=on to the workspace's
crates and to their dependencies.

Co-Authored-By: Claude <noreply@anthropic.com>
2026-11-09 17:32:57 -07:00
swaitsandClaude 09a8707e20 test(core): the legacy close bound is held a tenth of a unit past it
V-D3's test checked the bound B(n) = max(u, (n-1)u/2) at the bound and
one whole unit past it, so a bound a unit too wide would have passed.
It now refuses a drift a tenth of a unit past the bound, on both signs,
for two, three, four and five members: the bound is exactly the one
derived from BS-partner-1 statement 6, not something near it.

Co-Authored-By: Claude <noreply@anthropic.com>
2026-11-09 17:32:57 -07:00
swaitsandClaude 5544a3e66f ci: check runs as five parts on five runners, from one definition
The check job took 72 minutes on one runner for 0ef1ef2c2 (56 of them
tests, one binary at a time: the viewer's read_only.rs 901 s, its unit
tests 759 s, hostile_args.rs 294 s), so a red test was more than an hour
away and a morning of pushes queued behind each other.

`just check` is now a list of parts (lint, gui-unit, gui-tests, cli,
rest), each one `just check-shard <part>`. A laptop runs them in order;
CI runs each on its own runner. One definition serves both, so what CI
checks is what `just check` checks. Nothing can fall out of it:
- `rest` is the workspace less the crates another part names, so a new
  crate is tested without being added to a list;
- the viewer's two parts are every target `cargo test -p ledger-gui`
  runs (library, executable, each tests/ file, doc tests);
- the lint part fails unless check.yml's list of parts is the justfile's.
The parity floor's comparison runs once, in the lint part.

Co-Authored-By: Claude <noreply@anthropic.com>
2026-11-09 17:29:42 -07:00
swaitsandClaude 32725fb669 fix(core): Decimal arithmetic in ledger-core goes through the kernel (K-U11a)
Bar item 1: money arithmetic lives in kernel/ and nowhere else.
scripts/raw-decimal-arith.sh listed 210 places in ledger-core that did
not: raw +, -, * and unary minus (which panic past Decimal's range), and
checked_add / checked_sub / checked_mul / checked_div calls that
resolved to rust_decimal's inherent methods (which round silently past
28 digits) and not to the kernel's Amount. 199 of them now call the
kernel: Amount's methods by their full path, total / total_of for the
hand-rolled sums, normal_balance, and money.rs's sign and in-range
helpers.

The rewrite was done by a script from the compiler's own line and
column for each site, so no site was copied by hand; the few that
needed a decision are explicit:
- a balance sheet that cannot add liabilities and equity is not
  balanced (it panicked);
- a template's shares, a party's percents, a reconciliation's book and
  cleared balances and a reversal's document movements refuse with
  TooLargeToCompute or their own message where they panicked;
- tax_capital's split refuses where a product by the sign could not be
  taken, and collects its remainders as Options.
No figure moves: every site computes what it computed, by the same
operations in the same order.

Left, each for a named reason (the detector prints these 11):
money.rs 139 and 150 and periods.rs 149 and 202 (K-U10a rewrites them),
audit.rs 355 and 511 (V-D3 is in them), ledger.rs 4048 (a share times
the closed total: checked_mul_rounded, with K-U10a), and four rescale
calls (money.rs 302, reports.rs 637, schedules.rs 370 and 377) that
need a kernel function of their own.

Co-Authored-By: Claude <noreply@anthropic.com>
2026-11-09 17:22:17 -07:00
swaitsandClaude e0c78a783b refactor(core): a line's sign and an in-range sum, said once over the kernel
Twenty modules each wrote 'debit plus, credit minus' and 'a + b' for
themselves, on raw Decimal operators. Five helpers in money.rs say them
once, over the kernel's signed, flip and Amount: neg, signed_amount (a
line's amount as a movement), on_side (plus on an account's normal side,
minus on the other), and add_in_range / sub_in_range for sums of posted
lines, which the line cap keeps far inside Decimal's range.

Two tests hold them to the raw operators bit for bit, the scale and the
sign of a zero included. The second fails today, and it is right to:
the kernel's default checked_sub is an add of the negation, and
rust_decimal answers 0.00 + (-0.00) with -0.00 where 0.00 - 0.00 is
0.00. K-U10a gives Decimal its own exact_sub (rust_decimal's own
difference, checked for exactness); the test passes once it is merged
under this branch.

Co-Authored-By: Claude <noreply@anthropic.com>
2026-11-09 17:22:16 -07:00
swaitsandClaude abafa94a53 merge: the audit checks a close's split at the allocation's unit, and a legacy close by its member count (V-D3)
The audit took a cent for every currency, so a JPY close (split in whole
yen) was checked a hundred times too finely, and a code with no minor
unit too coarsely. The unit now comes from the one helper the split
itself uses. Before the true-up, a last-absorbs close's last member may
carry half a unit for each of the others (BS-partner-1 statement 6), so
the bound is max(u, (n-1)u/2), derived and marked so, not one unit.

Co-Authored-By: Claude <noreply@anthropic.com>
2026-11-09 17:02:26 -07:00
swaitsandClaude Sonnet 5.5 b810e6102b test(core): what exact tie ranking moves
Keeps the old ranking (the rounded quotient's remainder, built from the
kernel's own share_of, round_places and apportion) as a reference and
measures, over realistic inputs (whole-cent amounts to 1,000,000.00, two
to five parties, whole-percentage or small-integer weights), how often it
differs from the exact ranking. Run with --nocapture for the table.

What it shows: the rankings part only at an exact tie between unequal
parts over a total whose division does not terminate. Equal weights never
differ (every remainder is equal, so both give the leftover cents to the
earlier parts); two parties never differ (a tie leaves each share ending
in exactly half a cent, a terminating quotient); percentages summing to
100 never differ (the quotient is exact). A difference is at most one
cent a part and the parts still sum to the whole. The tests assert that
structure and print the rates.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-09 16:39:12 -07:00
swaitsandClaude 8ad55e82a8 docs(routing): keep checking Muse Code for Ember, and use it from the day it is listed
Muse Ember was released today and the Muse Code provider does not list it
yet; only OpenCode does. The owner's rule: do not take the OpenCode
listing, check the Muse Code provider before each batch of delegations,
and route run-only work to Ember once it is there. Until then run-only
tasks stay on the scout row.

Co-Authored-By: Claude <noreply@anthropic.com>
2026-11-09 16:38:39 -07:00
swaitsandClaude 05da2dd867 docs(routing): which model gets which delegated work, and a log to check it against
The owner's rule from 2026-11-09: delegated work is routed by what the
task is (scouting, running things, bulk implementation, hard
implementation, review), not by a random draw, and the routing is
adjusted from evidence. `docs/routing.md` is the current table with the
exact provider and model ids; `docs/delegation-log.md` gets one line per
task once it is verified or abandoned.

One row is open: the plan names Muse Ember through Muse Code for run-only
tasks, and that provider does not list it here (OpenCode does). The file
says so, and those tasks go to the scout row until the owner chooses.

Co-Authored-By: Claude <noreply@anthropic.com>
2026-11-09 16:27:26 -07:00
swaitsandClaude 95ae7717db test(core): a script that lists Decimal arithmetic done outside the kernel
The bar's first rule is that money arithmetic lives in `kernel/` and the
engine never gets a second copy: Kani and Lean prove the accounting laws
over the kernel's functions, so a sum or a sign flip written anywhere else
is arithmetic nothing has proved. Until now nothing measured how much of
it there is.

`scripts/raw-decimal-arith.sh [package [file.rs ...]]` lists every place
in a crate's own source, outside `kernel/` and the proof harnesses, that
does `Decimal` arithmetic without the kernel: raw operators, rust_decimal's
own `checked_*` and rounding methods, and `Iterator::sum`/`product`.

ledger-core today: 210 places. 101 raw operators, 104 calls to
rust_decimal's inherent `checked_add`/`sub`/`mul`/`div`, 4 `rescale`, one
`.sum()`. The earlier count of 100 saw only the operators, because
clippy's arithmetic lint does not look at method calls.

The method calls matter as much as the operators. `a.checked_add(b)` on a
`Decimal` is rust_decimal's method, not the kernel's, even with `Amount`
in scope, and rust_decimal rounds a result that needs more than 96 bits
where the kernel (K-U10) refuses it. A total that was rounded on the way
is not the sum of its lines, which is the one thing a ledger may not get
wrong quietly.

How it finds them: clippy cannot limit `arithmetic_side_effects` to one
type, so the script runs it twice, once flagging every type and once with
`Decimal` allowed, and keeps what drops out. The methods come from
`disallowed_methods`, which is exact about the type. A place under an
`#[allow]` for either lint is not listed; the last line counts those, so
a waiver cannot arrive unseen.

Not a gate yet: it exits 1 while the count is above zero, and `just check`
does not call it. K-U11 brings ledger-core to zero, then it goes in.

Co-Authored-By: Claude <noreply@anthropic.com>
2026-11-09 16:22:31 -07:00
swaitsandClaude 129a90dcf1 fix(test): recorded failures are replayed again; a seed file no test reads fails the build
A failure a property test once found is kept as a seed and replayed on
every run: that is what makes a fixed bug stay fixed. Proptest finds
the seed file from the test's source path and says nothing when the
file is not there, so a seed file left behind by a moved test is never
read again, silently.

Four findings, one cause:

- The kernel bridge's three recorded failures (the constructive split
  with a short remainder, and two cash-application cases) sat in
  tests/kernel_bridge.proptest-regressions. Since 0cf013b57 the bridge
  is a folder (tests/kernel_bridge/main.rs), and a folder test reads
  tests/proptest-regressions/main.txt. The three had not been replayed
  since. Moved there.
- K-U8 found a control-total case (a sum that touches Decimal's top,
  f = [0, -1, -79228162514264337593543950335, 0, 5]) and the seed was
  never checked in; it lay untracked in the unit's worktree. Added as
  tests/proptest-regressions/control.txt, where control.rs reads it.
- ledger-mcp's proptest-regressions/local_files.txt recorded failures
  of a module removed in b26c099a6 (files reach the books as uploads
  by hash now). No test can read it. Removed.
- Nothing checked any of this. tests/seed_files.rs walks every crate
  and fails when a seed file has no property test that reads it.

How the reading rule was established, not assumed: a marker line in
each candidate file, and proptest's "unparsable line" warning names
the file it really opens.

With the seeds back, the bridge passes whole (101 tests), so nothing
had regressed behind the gap. The guard was red before the move (it
named both orphans) and is green after: 21 seed files, each read by a
property test.

Co-Authored-By: Claude <noreply@anthropic.com>
2026-11-09 16:02:06 -07:00
swaitsandClaude 0ef1ef2c22 build: pin bookspec at 79cb439, the payroll and control laws
check / check (push) Canceled after 0s
portable-macos / portable (macos-latest) (push) Canceled after 0s
portable-windows / portable (windows-latest) (push) Canceled after 0s
two-user / two-user (push) Canceled after 0s
K-U7 moved payroll's net pay into the kernel and K-U8 moved the control,
aging and reconciliation identities there. Their laws were written once,
in bookspec's Lean: law 45 (net pay is gross less every deduction, and a
payroll plan balances at any number of employees) and law 46 (the control
difference, the aging total and the reconciliation total). The checker and
the Lean package move to that rev together, so the pin test holds.

Proved at this pin: the Kani fast set, 97 harnesses, none failed and every
cover reached; Lean, 212 theorems on the standard axioms only. The Kani
set was verified in two runs (93, then the 4 the whole-set time cap cut
off on a loaded machine), and the Lean half in a shell of its own.

Co-Authored-By: Claude <noreply@anthropic.com>
2026-11-09 15:48:40 -07:00
swaitsandClaude 1fbd1da263 docs(agents): the crates that exist, not the ones once planned
The engine-first section still listed ledger-store, ledger-import and
ledger-reader as future crates beside two that were never built
(ledger-oracle, books-app). It now names the ten crates around the core,
as docs/architecture.md does; the rule is unchanged: they depend inward
toward the core, never the reverse.

Co-Authored-By: Claude <noreply@anthropic.com>
2026-11-09 15:38:00 -07:00
swaitsandClaude 995b3e5eaf ci(check): a running check on main finishes; a newer push waits its turn
The check job takes about fifty minutes and was cancelled by every newer
push to the same branch. On 2026-11-09 a morning of merges cancelled every
run, so main went hours with no finished check. On main the running check
now finishes and the newest push runs next (GitHub keeps only the newest
waiting run in a group), so no half-run check is thrown away and the tip is
always the next thing checked. Pull requests keep the old rule: a newer
push cancels the older run.

Co-Authored-By: Claude <noreply@anthropic.com>
2026-11-09 15:38:00 -07:00
swaitsandClaude Sonnet 5.5 294cb99a58 fix(core): a tie between shares goes to the earlier part, exactly (held for the owner's decision)
split_by_weights_into's largest-remainder policy ranked the leftover
cents by the rounded quotient's remainder (Decimal keeps 28 significant
digits), so an exact tie was decided by the quotient's last digit, not
given to the earlier part as apportion's docs and bookspec's Lean model
(Apportion.lean: remW = x*w % W, ties to the earlier member) say.
20.00 by 4/1/1 over 6 gave 13.33, 3.34, 3.33 where the exact tie of
remainders (0.02 over 6 each) belongs to the first: 13.34, 3.33, 3.33.

It now ranks the exact integer remainder whole x weight - part x total
(the quantity share_floor_with returns), sign-flipped for a negative
total so the order stays the share's own. The parts still sum to the
whole and each is within one step; only which part takes a tied cent
changes. Stored entries never move (posted is forever); a report
recomputed for a past period can move a cent between parties.

The finding test is flipped into the law (ties_go_to_the_earlier_part),
the bridge's ranking property now includes ties, and the spec block,
k-u3.md and verification.md say ties go to the earlier part, exactly.

This branch is held: the owner decides whether the cents may move
(see tests/kernel_bridge/ties.rs for what it moves).

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-09 15:37:06 -07:00
swaitsandClaude 5cad55023f fix(test): the backup folder test names a folder the host calls rooted; the portable jobs report every failure
The portable-windows gate has been red on main for four pushes
(7a5cb6873 to 652f9da87). The settings test V-D2 added set
backup.folder to /mnt/backup/books. A backup folder is a folder on the
server's own computer, so the key is checked by the host's path rules,
and on Windows that path names no disk: the check refused it, rightly,
and the test's unwrap panicked. The rule and the code are unchanged;
the test now names a folder the host takes (D:\backup\books there).

cargo test stops at the first failing test binary, so that one test hid
whatever fails after it. The two portable jobs take most of an hour
each; they now run with --no-fail-fast, so one red run shows every
failure.

Co-Authored-By: Claude <noreply@anthropic.com>
2026-11-09 15:17:30 -07:00
swaitsandMuse Wonder 1.0 02087ef3fb fix(core): a legacy close's drift before its true-up is the rule's, not one unit
Before a count is trued up, check_split flagged any drift beyond one unit. BS-partner-1 statement 6 allows a legacy last-absorbs close more than that with four or more members, so the audit raised a false finding on legitimate legacy books.

The rule does not state an audit bound; this bound is DERIVED from statement 6's per-member facts, and the derivation is in check_split's spec block: with n members and unit u, each member but the last was rounded to within u/2, and the last absorbed the sum of those roundings, so |e_last| <= (n-1)*u/2. Floored at u (statement 6's allowance for each run break and each per-close close), the pre-true-up bound is B(n) = max(u, (n-1)*u/2): 1.5 units with four members, 2 with five. A drift of exactly B(n) is legitimate and not flagged; past it is. After the true-up, statement 5's strict bound still holds: a drift of a unit or more is flagged.

WB-ledger-16 invariant 8 now states B(n) and marks it derived.

Tests: a_legacy_last_absorbs_close_drifts_by_member_count_before_its_true_up (BS-partner-1 statement 6 before the true-up, statement 5 after it; WB-ledger-16 invariant 8): four- and five-member closes at their largest legitimate drift are not flagged, one unit past it they are, and after the true-up the strict >= unit bound holds.

Co-Authored-By: Muse Wonder 1.0
2026-11-09 14:50:38 -07:00
swaitsandMuse Wonder 1.0 5b1596f977 fix(core): the audit checks a close's split at the allocation's unit
audit::closes took its unit as minor_units().unwrap_or(2), while the members allocation splits at allocation_places() (minor_units().unwrap_or(MAX_LINE_SCALE)). For a currency code with no minor unit the audit therefore checked a split made at the finest a line carries against a cent: far looser than the split it checks, so real drift passed.

Add Currency::allocation_unit(), the one helper that turns allocation_places() into an amount, and take the audit's unit from it, so the split and its check cannot drift apart (BS-partner-1 statement 4: the allocation is the split to the base currency's smallest unit). A JPY close is now checked at a whole yen.

Test: a_jpy_close_is_checked_at_the_allocations_unit (BS-partner-1 statement 4, WB-ledger-16 invariant 8).

Co-Authored-By: Muse Wonder 1.0
2026-11-09 14:48:59 -07:00
swaitsandClaude Opus 5.5 4da1c5b30f fix(proofs): K-U7's overflow harness takes i64::MIN, with the native subtraction
K-U7 and K-U8 found the same thing from two sides: the integer model's
subtraction negated the subtrahend first, so x - i64::MIN was refused
where it fits. K-U7 assumed the minimum away and asserted the refusal;
K-U8 made i64 and i32 subtract natively. With both merged the
assumption goes: the harness ranges over the whole i64 domain, minimum
included, and asserts -1 - i64::MIN = i64::MAX.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-09 13:52:41 -07:00
swaitsandClaude Opus 5.5 8aa0ed985d merge: the control, aging and reconciliation identities in the kernel (K-U8; reviewed, fixes applied)
Three identities the books rest on are kernel functions now, proved
rather than only summed: an aging's five buckets add to the document
total (aging_total), a control account's difference from its documents
and unattached lines (control_difference), and the K-1 reconciliation's
total (reconciliation_total). Kani proves each, None exactly on
overflow; bridge properties check them against an exact integer
reference and the replaced chains on 20,000 cases, scale included; law
46 in bookspec's Lean. The CPA package's aging now refuses a total past
exact arithmetic instead of panicking. The harnesses found the integer
model's subtraction negating first, so x - MIN was refused where it fits;
i64 and i32 now use the native subtraction.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-09 13:52:10 -07:00
swaitsandClaude Opus 5.5 a37612d07c merge: payroll's net pay in the kernel (K-U7; reviewed, fixes applied)
Net pay is gross less the withholdings and deductions, now one kernel
fold (net_pay) with the plan's totals through the kernel's checked
totals; payroll_remit_plan refuses a total past exact arithmetic instead
of panicking. Proved: Kani (net pay equals gross less the deductions,
None exactly when a running difference overflows, the plan balances for
an employee), bridge properties against an exact integer reference at
every prefix, and law 45 in bookspec's Lean for any number of employees.
No figure moves; every golden unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-09 13:52:02 -07:00
swaitsandClaude Sonnet 5.5 b31824b2ca test(core): K-U7 review: None-iff-overflow proof, covers that can fail, a sharper bridge
- Kani net_pay_none_iff_a_prefix_overflows proves what the doc claimed:
  None exactly when some running difference leaves the i64 range, else
  the exact i128 result. It found that i64's Amount::checked_sub negates
  first, so a deduction of i64::MIN (no negation) is refused where the
  difference would fit (-1 - i64::MIN). Conservative, and Decimal's range
  is symmetric, so the engine is unaffected; the harness assumes it away
  and asserts the refusal at the fixed case; the kernel doc says so.
- payroll_plan_balances: covers that the assumes did not already force
  (net of one unit, payables holding employer shares alone, federal or
  state posted); the harness doc says it rebuilds the plan on i64 rather
  than calling payroll_entry_plan, and what that does and does not prove.
- Docs name the Lean theorems that carry any number of employees
  (payroll_run_net_eq, payroll_run_plan_balances) where they had
  claimed it.
- Bridge: compare to_string as well as value (Decimal equality ignores
  scale); a strategy near Decimal::MAX/MIN where the reference also
  returns None, which required the reference to check every running
  difference as the kernel's fold does, not only the last.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-09 13:50:54 -07:00
swaitsandClaude Sonnet 5.5 46dccd5d76 fix(core): payroll_remit_plan refuses past exact arithmetic instead of panicking
The remittance plan totalled the payables with a raw `total +=`, which
panics on Decimal overflow, on a pub fn returning a bare plan. Its
callers refused first through sum_exact_of, but that was an unenforced
precondition (BS-entry-4: every derived figure is checked arithmetic).
It now returns Result<_, LedgerError>, totalling through
kernel::total_of and refusing TooLargeToCompute; Ledger and the store
propagate it and keep their pre-checks. A test shows payables past the
range, up and down, are refused, not a panic.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-09 13:50:54 -07:00
swaitsandClaude Sonnet 5.5 80c93179b5 test(core): bound the rounded figures against the exact value
A rounded step can later return to scale 2, so the bound is four whole
units in cents, not one unit at the final scale.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-09 13:17:12 -07:00
swaitsandClaude Sonnet 5.5 c20ccbeab4 docs(proofs): name the audit's rules by bookspec id only
The retired-reference gate flags the old B-n numbers in prose.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-09 13:12:08 -07:00
swaitsandClaude Sonnet 5.5 5faa954215 docs(proofs): fix a backtick
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-09 12:53:12 -07:00
swaitsandClaude Sonnet 5.5 c8cfd32723 test(core): the control harnesses prove None only on overflow; i32/i64 checked_sub is native
The tightened harnesses assert Some whenever every i128 prefix fits in i64.
That found the default Amount::checked_sub refusing x - MIN on i32/i64 where
the difference fits; both now use the native subtraction. The bridge pins
aging_total(0,0,0,0,MAX) to Some(MAX), bounds the rounded figures to one
unit of the exact value, and covers scales 0..=28. Two smaller worksheet
harnesses (nine terms on i32, seven on i32) found no verdict in 400 s and
300 s: recorded, no harness.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-09 12:53:09 -07:00
swaitsandClaude Opus 5.5 652f9da877 build: pin bookspec at ed6e379, payouts, tags, prepaid contributions
portable-macos / portable (macos-latest) (push) Canceled after 0s
portable-windows / portable (windows-latest) (push) Canceled after 0s
two-user / two-user (push) Canceled after 0s
check / check (push) Canceled after 0s
bookspec main now carries X-H1e2: the last examples slice, two rules left
without one (BS-asset-9, BS-partner-16, which the engine does not do).
112 of 139 examples run and pass, the other 27 are for options
wanderbooks did not pick.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-09 12:51:31 -07:00
swaitsandClaude Sonnet 5.5 632a1a543c fix(package): the agings refuse a total past exact arithmetic instead of panicking
The CSV total and the statement's column totals used raw Decimal += and a
five-term sum, which panic at the edge. They now go through
kernel::total_of and kernel::aging_total and return TooLargeToCompute as an
error (BS-entry-4). Only the error path changes; no golden moves.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-09 12:39:11 -07:00
swaitsandClaude Opus 5.5 26a9ddf6cf merge: the adapter runs payouts, asset tags, prepaid contributions and several payees (X-H1e2's wanderbooks half; reviewed)
Wanderbooks passes every bookspec example for its picks: 112 run, 112
passed, 27 for options it did not pick. A payout goes through the same
payout_plan the MCP tool uses, a tag through Store::set_asset_tag, the
K-1 contribution columns and the 1099 payments through the worksheet and
the report. No engine change. The claims say what the engine does not do
for BS-asset-9 (no 704(c) method unless a command gives one) and
BS-partner-16 (members are a setting handed to each close).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-09 12:36:03 -07:00
swaitsandClaude Sonnet 5.5 b4b233e486 test(core): Kani and bridge for the kernel control identities
Kani proves, on arbitrary i64s with an exact i128 specification, that
aging_total is the sum of its five buckets, control_difference is
balance - documents - unattached and vanishes exactly when the account
agrees with its subledger, and reconciliation_total is beginning + gain
+ without - distributed; in-range figures always total (law 45). The
book/tax worksheet statement did not finish in the solver (500 s at nine
terms, 110 s at seven), so Lean's reconciliation_identity carries it and
a bridge property checks it on i64 and Decimal; written down in
docs/proofs/k-u8.md rather than weakened.

The bridge compares i64 against Decimal and Decimal against an
independent exact i128 reference over the whole mantissa range, pins the
Decimal edges (each overflowing step is None, never a panic), and checks
the kernel against the three hand-written chains it replaced, as strings
including scale, on 20,000 random Decimals: identical. The reference
also shows rust_decimal rounds an add to a coarser scale wherever the
exact result needs more than 96 bits at the operands' scale (K-U4's
finding, wider than the MAX edge); pinned as a canary for K-U10.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-09 12:13:32 -07:00
swaitsandClaude Sonnet 5.5 3c78eb5bed docs(claims): the bookspec examples that check BS-revenue-1, BS-asset-3, BS-partner-15, -17, BS-1099-5 and BS-statement-9
Each claim's Checked line names the examples that now run it on the engine, and
the example for each option wanderbooks did not pick, which is skipped. Two
claims say what the engine does not: BS-partner-16's pick states what the books
do by convention at a close, since no command closes a period at a change of
shares, and BS-asset-9's is the books' convention, not an engine default (a
contributed asset's 704(c) method is unset until a command gives one), so no
example shows either pick apart.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-09 12:05:15 -07:00
swaitsandClaude Sonnet 5.5 a87e2d0a7a test(core): the adapter runs a platform's payout, an asset's tag and the K-1's tax-basis note through the engine
The bookspec schema gained a `payout` event, a `tag_asset` event, an
`asset_tag` query and a note on the tax-basis property line (BS-revenue-1,
BS-asset-3, BS-partner-17). The adapter runs each through the engine and
rebuilds none of it: a payout goes through `payouts::payout_plan`, which
refuses unless gross less fee is the deposit to the cent, and its plan's lines
post as one entry; a tag goes through `Store::set_asset_tag`, which refuses a
tag of a wrong form and one another asset holds or ever held; the tax-basis
line's note is `Note::PrepaidAtBook` read off the worksheet. The engine's
InvalidPayout, InvalidAssetTag and AssetTagTaken are worded as the examples
word them.

Thirteen examples were added and every one the engine's picks reach passes:
five are for options wanderbooks did not pick (no-tags, every-prepaid-is-cash,
every-prepaid-is-property, left-open, whole-payment-to-each) and are skipped,
so the skipped count is 22 + 5 = 27 and 112 of 139 run. A prepaid contract
credited straight to capital is property (1,500.00 each) and a service paid
through Due to Members is cash (1,000.00 each); the contract enters the tax
capital at its book amount with the note; a 1,000.00 check naming Dana Studio
at 600.00 counts 600.00 toward Dana's 1099.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-09 12:05:15 -07:00
swaitsandClaude Sonnet 5.5 0df463b703 refactor(core): the control, aging and reconciliation identities in the kernel
Three identities were still hand-written chains at their call sites:
an aging row's five buckets summing to what is owed (BS-arap-1), the
control check's difference, balance less documents less unattached
lines (BS-arap-2), and the K-1 reconciliation total, beginning plus
built-in gain plus property without a basis less property distributed
(BS-partner-4). They move to kernel::aging_total, control_difference
and reconciliation_total, generic over Amount, returning None on
overflow, so each is a named law with a harness and a Lean theorem
rather than a sum.

Behaviour is identical: the same checked steps in the same order, so
figures, scales and TooLargeToCompute refusals are unchanged; every
golden passes untouched. The next commit's bridge compares the old
chains and the kernel as strings on 20,000 random Decimals of any scale.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-09 11:48:10 -07:00
swaits 90d34585fd Merge branch 'main' into t3/payroll-net-pay-kernel 2026-11-09 11:44:50 -07:00
swaitsandClaude Opus 5.5 e45c62348a build: pin bookspec at 6d85d8b, schedules that take the pick and the books' own facts
check / check (push) Canceled after 0s
portable-macos / portable (macos-latest) (push) Canceled after 0s
portable-windows / portable (windows-latest) (push) Canceled after 0s
two-user / two-user (push) Canceled after 0s
bookspec main now carries X-H1e1: a schedule may leave its method to the
engine, yen schedules, the IIF export's choices, settings, role
assignments and the tax summary in the schema; eight rules remain
without an example. Lean audits standard axioms only; 104 of 126
examples run and pass, the other 22 are for options wanderbooks did not
pick.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-09 11:23:56 -07:00
swaitsandMuse Wonder 1.0 2295d15be8 test(core): the payroll plan harness carries one employee
The two-employee payroll_plan_balances timed out in CBMC: over 80
minutes at full CPU, killed with no result (sixteen symbolic figures
into eight totals and check_lines). The earlier note's 297.6s figure
came from a misattributed background result and is withdrawn here;
the harness as committed had never verified.

One employee reaches every plan line, both FICA shares on both sides,
net_pay and check_lines, and verifies in 62.0s (65.6s wall). Lean's
payroll_plan_balances carries the plan at its totals for any number
of employees, since a run's totals are sums of the same eight
figures. The bound and why are written in the harness and the note.

Co-Authored-By: Muse Wonder 1.0
2026-11-09 11:22:13 -07:00
swaitsandClaude Opus 5.5 1add7df419 merge: the adapter runs schedules that take the pick, yen schedules, the IIF's options and the books' own facts (X-H1e1's wanderbooks half; reviewed, re-checked)
Wanderbooks passes every bookspec example for its picks: 104 run, 104
passed, 22 for options it did not pick. A schedule plan is answered as
the engine holds it (a yen month 333, a dollar month 33.33); the IIF
line ending is cr-lf only when every line ends so; bookspec's setting
keys map to the engine's in one place.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-09 11:18:25 -07:00
swaitsandClaude Sonnet 5.5 e49b6d3427 test(core): the adapter maps bookspec's setting keys to the engine's
Bookspec now closes its setting keys (fiscal_year_start); the engine's key is
company.fiscal_year_start. The event and the query both go through one map
(BS-ledger-9).

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-09 11:17:14 -07:00
swaitsandClaude Sonnet 5.5 bab7ac72ca test(core): the adapter's line-ending answer needs every break to be CR LF
contains(CR LF) answered cr-lf for a file mixing CR LF and bare LF. Now the
count of LF must equal the count of CR LF for cr-lf, with none CR LF for lf,
and a mix is mixed. The claims say the engine has no host notion, so
host_line_ending is unused (BS-format-4).

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-09 11:17:14 -07:00
swaitsandDeepSeek V4.1 Flash 695aee7a1e docs(claims): the new bookspec examples that check the picks
The Checked lines gain the examples that now exercise each pick: the
schedule examples with no convention and a mid-month start (BS-prepaid-2,
and the equal-months one under BS-prepaid-3's start-on-any-day), the yen
schedules under the minor unit and the cent rule (BS-prepaid-4), the two
IIF line endings, DOCNUMs, spans, closes and the nameless receivable line
(BS-format-4, -5, -6, -8, -9), the setting recorded in the books
(BS-ledger-9), the role assignment read back from them (BS-ledger-18) and
the category rounding once and per account (BS-ledger-21). Each names the
enforcement it goes through and the two tests that run it, so the
traceability gate keeps every claim backed.

Co-Authored-By: DeepSeek V4.1 Flash <noreply@opencode.ai>
2026-11-09 10:49:49 -07:00
swaitsandDeepSeek V4.1 Flash 688ab951d3 test(core): the adapter runs schedules that take the pick, settings, role accounts, tax summaries and an export's line ending
A schedule may now leave its convention to the engine, so an example can
show BS-prepaid-2's pick: the adapter registers such a schedule by the
day, wanderbooks' method (D-11, D-37), and the equal-months examples are
skipped as the runner skips another engine's option. The yen examples run
through `Store::register_schedule`, whose `schedule_minor_unit` feature
rounds a monthly-even month to the currency's minor unit (D-72, K-U5);
`answer_schedule_plan` now prints each month as the plan holds it, so a
yen month is 333 and not 333.00.

The new events and queries go through the engine's own commands, never a
reimplementation: `set_setting` is `Store::change_settings` with its
`Source` (who decided and when), the setting query reads
`Ledger::settings`, the role account query reads `Ledger::role_account`,
the tax summary is `tax::tax_summary`'s once-rounded lines, and the line
ending is the `ledger_import` file's own CR LF. The BS-format-9 example
uses an entry posted as an earlier version wrote it, so its memo is the
example's and no document's wording stands between the file and the
check. The skip count moves from 16 to 22, the six new unpicked-option
examples (the cent rule, the file's place, one fiscal year, closes
written, the platform line ending and per-account rounding).

Co-Authored-By: DeepSeek V4.1 Flash <noreply@opencode.ai>
2026-11-09 10:49:44 -07:00
swaitsandMuse Wonder 1.0 fbe7eb7125 test(core): Kani and bridge for the kernel payroll
Three Kani harnesses on i64, fixed arrays (five deductions, a
two-employee plan of eight lines): net_pay_is_gross_less_deductions
(19.5s verification), net_pay_nonnegative_when (7.0s) and
payroll_plan_balances through check_lines (297.6s), each with covers.
The bridge checks i64 against Decimal and Decimal against an
independent exact i128 reference, with the edges (Decimal::MAX/MIN,
mid-fold overflow) giving None, never a panic.

All three prove law 45 (bookspec, BS-entry-1/BS-entry-3/BS-entry-4).
The traceability gate passes against the k-u7 bookspec branch: 63
kernel functions, 48 fully backed, 45 law rows. docs/proofs/k-u7.md
is the unit's record.

Co-Authored-By: Muse Wonder 1.0
2026-11-09 10:37:16 -07:00
swaitsandMuse Wonder 1.0 e8f60532b1 refactor(core): payroll's net pay in the kernel
Net pay was a hand fold of Decimal::checked_sub in payroll.rs, and
payroll_entry_plan totalled its seven columns with local checked folds.
Both now go through the kernel: kernel::net_pay (gross less every
deduction, folded left to right, None past exact arithmetic) and
kernel::total_of/total_try for the plan's columns, the net over each
line's kernel net pay.

The fold order preserves the old behaviour exactly, including at the
edge: each running difference must be representable, so [MAX, MAX,
-MAX] from a zero gross refuses where summing first would cancel.
Figures, scale, zero-skipping and the TooLargeToCompute refusals are
unchanged; every golden and test passes as before. The rules are
BS-entry-3 (exact amounts), BS-entry-4 (every payroll figure computed
with checked arithmetic) and BS-entry-1 (the plan balances).

payroll_remit_plan's bare total and name_payroll_parties' grouped
checked_add stay: both callers refuse through sum_exact_of first, in
the same order, and a grouped accumulation has no kernel shape. See
docs/proofs/k-u7.md.

Co-Authored-By: Muse Wonder 1.0
2026-11-09 10:37:11 -07:00
swaitsandClaude Opus 5.5 2105e85bae merge: the cash-flow and party citations name statements by position (S-E5; re-checked)
bookspec dropped BS-statement-3's and BS-partner-3's Rule n labels,
which had drifted from their positions (S-C8: Rule 11 was statement 16).
Wanderbooks' cash-flow code, its tests, the claims and the docs cited
them by label; 110 now name the statement, each checked against the
pinned record by content (wrapped ones included). A test refuses a bare
old label beside those records' citations; 515 sub-references checked.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-09 10:21:58 -07:00
swaitsandDeepSeek V4.1 Flash c49ddc0d6b test(core): no bare old rule label beside a cash-flow or party citation
BS-statement-3 and BS-partner-3 no longer open their statements with
"Rule n", so a numbered rule label in the cash-flow or party files can
only be the drifted old citation. sub_refs now refuses a bare "Rule n" /
"rule n" there, and elsewhere only on a line that cites one of those two
records. Ordinary uses of the word ("this rule holds", "the run rule
0.02") are not labels, and a label straight after a bookspec id is
already the id check's finding. Self-tests cover both scopes and the
non-label cases. The checked-reference floor rises to 515, the count
after the citations moved to positions.

Co-Authored-By: DeepSeek V4.1 Flash <noreply@opencode.ai>
2026-11-09 10:21:07 -07:00
swaitsandDeepSeek V4.1 Flash 409845e665 docs: the cash-flow and party citations name statements by position
bookspec unit S-C8 dropped BS-statement-3's and BS-partner-3's "Rule n"
labels: they had drifted from the statements' positions, and every
reference is now a position, "BS-statement-3 statement k". This rewrites
wanderbooks' citations from the old labels to the positions.

Method: the map was confirmed against the pinned records at b61fa50 by
reading each statement before use. BS-statement-3: Rule 1 -> statement 2,
2 -> 3, 3 -> 4, 4 -> 5; Rule 5 by the sentence's meaning (gross lines 6,
operating classes 7, governments 8, payroll 9, kinds 10, the family 6-10);
6 -> 11, 7 -> 12, 8 -> 13, 9 -> 14, 10 -> 15, 11 -> 16, 12 -> 17.
BS-partner-3: 1 -> 1, 2 -> 2, 3 -> 3-4, 4 -> 5-6, 5 -> 7, 6 -> 8, 7 -> 9,
8 -> 10, 9 -> 11. Each sentence was read against the statement it now
cites; a "rule n" meaning an IRS rule, an engine rule, or another
record's rule was left alone (odd_cent.rs's close true-up, the asset
register's note numbering, and testing.md's "run rule 0.02").

Rewritten: 44 references in src/cashflow.rs, 22 in
tests/spec_cash_flow.rs, 3 in tests/spec_reports.rs, 5 in
docs/spec/claims/statement.md (whose stale "rules 1-12" count is now
"18 statements"), 21 in the vendored ASC notes, 10 in docs/testing.md,
2 in docs/verification.md, 2 in kernel/entries.rs, and 1 in the CLI's
journey test.

Co-Authored-By: DeepSeek V4.1 Flash <noreply@opencode.ai>
2026-11-09 10:21:04 -07:00
swaitsandClaude Opus 5.5 01acb159f0 build: pin bookspec at b61fa50, the percentage law
check / check (push) Canceled after 0s
portable-macos / portable (macos-latest) (push) Canceled after 0s
portable-windows / portable (windows-latest) (push) Canceled after 0s
two-user / two-user (push) Canceled after 0s
bookspec main now carries law 44 (K-U6): a percentage of a positive whole
within half a step of the exact ratio, a ratio split's sides summing to
the amount. Lean audits standard axioms only; the traceability gate
finds a law for all 62 kernel functions' harnesses it checks.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-09 09:50:06 -07:00
swaitsandClaude Opus 5.5 650a89c94e merge: percentages and ratios in the kernel (K-U6; reviewed, fixes applied)
A project's contribution margin as a percent of its revenue, and a
government's part of a payment split from the company's, are now kernel
functions (percent_of, split_ratio) with Kani harnesses, bridge
properties against an exact integer reference, and law 44 in bookspec's
Lean. A review fuzzed old against new as strings: no figure moves. Fixed
in review: a split's zero rest could be -0, and the split harness proved
divisibility at a step of 1, where every number divides. The viewer's
display percentages stay as they are; its f64 chart percentage is a
money path K-U9 must make Decimal.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-09 09:39:28 -07:00
swaitsandDeepSeek V4.1 Flash 142de09ff2 docs(core): state the ratio split's part scale
The part keeps the share's scale when the share is already a whole
multiple of the step and takes the step's otherwise, so callers that need
a fixed scale rescale (as contribution_margin_pct does for its one-place
display). Say so in `split_ratio`'s invariant list.

Co-Authored-By: DeepSeek V4.1 Flash <noreply@opencode.ai>
2026-11-09 09:38:13 -07:00