docs(spec): format claims reduced to wanderbooks' picks and product rules

B-27's journal format gate is wholly the product's: its full text is now
WB-format-1 to WB-format-4 (the gate and the frozen envelope; the journal
features and when a command asks for one; the format upgrade with the
owner's passphrase and a proven backup; one SQLite projection file per
schema), with the enforcement and tests split among them. Its id
BS-format-1 stays retired, and the one engine-independent sentence it
carried — a reader that does not know a record's format version refuses
it, never misreads it and never calls it corrupt — is now bookspec's
BS-ledger-4, statement 4.

B-34 keeps its pick (plain ASCII transliterated and reported, CR LF,
DOCNUM the entry's id, closes left out, every entry through the as-of
day, D-36), its enforcement and its tests; what is wanderbooks' only is
WB-format-5 to WB-format-7: the export tool's as_of and warnings, the
package README's words and the names of entries on A/R and A/P, the rest
of the package's text and fonts, and the pinned deunicode 1.6.0 table.
The accounting text itself (encoding, line structure, signs, accounts by
name, classes) lives in bookspec's BS-format-2.

Co-Authored-By: DeepSeek V4.1 Flash <noreply@opencode.ai>
This commit is contained in:
swaitsandDeepSeek V4.1 Flash committed 2026-11-08 12:49:50 -07:00
1 parent 0aeb913756
commit 280d3a1b6d
2 files changed
+264 -348

No files matched your search

+256 -346
View File
@@ -1,6 +1,10 @@
# Claims: format # Claims: format
Wanderbooks' claims for bookspec area **format**: what each rule requires, where the engine enforces it, and which tests check it. Being reduced to the engine's pick and its evidence as P14 unit S-D lands; the accounting text moves to bookspec's `spec/format.md`. Wanderbooks' claims for bookspec area **format**: what each rule requires,
where the engine enforces it, and which tests check it. The accounting text
lives in bookspec's records (`rules/format/`); here stay the option
wanderbooks picks, its enforcement and tests, and the product rules that are
only wanderbooks' (`WB-format-<n>`).
Rules: B-27, B-34. Rules: B-27, B-34.
@@ -10,373 +14,246 @@ Rules: B-27, B-34.
**bookspec:** `BS-format-1` **bookspec:** `BS-format-1`
**Status:** CHOICE (the owner, 2026-10-16; `plan/served.md` 5.1 and P0); **Claims:** no (retired 2026-11-08, D-71: wholly wanderbooks'); its one
CHOICE (P0 review, 2026-10-16: a line's own hash is checked before the engine-independent sentence — a reader that does not know a record's format
line is called newer; the envelope and its hash are frozen across version refuses it, never misreads it and never calls it corrupt — is now
formats); CHOICE (the owner, 2026-10-20, D-39, and `plan/served.md` statement 4 of `BS-ledger-4`.
3.9: older books move to a newer format only with the owner's go-ahead,
asked at every open until given)
Every journal line has a type, and a version of wanderbooks reads a fixed **Pick:** `older-reader-says-newer`: CHOICE (the owner, 2026-10-16; P0 review,
set of them (`ledger_store::format::EVENT_TYPES`). A newer version may 2026-10-16: a line's own hash is checked before the line is called newer, and
write a type an older one doesn't know, or declare a newer journal format the envelope and its hash are frozen across formats; D-39, 2026-10-20: older
with a `journal.format_set {format, features}` line before the first event books move to a newer format only with the owner's go-ahead, asked at every
that needs it. An older reader stops at the first line it can't read and open until given). The retired record's one option names wanderbooks' pick;
says so: it never skips a line (the books it showed would differ from the the rest of the rule is the product rules below.
record without saying so), and it never calls newer books corrupt.
What every journal format shares is frozen, so that an older reader can **Enforced:** none (the id is retired; the gate is enforced by
always follow the chain one line past the first line it can't read. A `ledger_store::format` under the product rules below).
line is the envelope `{seq, ts, type, payload, prev}` and nothing beside
it; its hash (what the next line's `prev` holds) is the SHA-256 of its
canonical JSON: keys sorted at every depth, no whitespace. A newer format
puts its new fields inside `payload`, never in the envelope, and never
changes how a line is hashed. A line with a key beside the envelope's is
refused as newer, never read with the key dropped, and its hash covers
the key, so the next line still checks it.
Damage stays corruption. A line's seq and `prev` are checked before the **Checked:** none at this id (its checks are the product rules').
gate, and its own hash is checked by the next line's `prev`; so when the
gate refuses a line, the reader reads the next one first, taking only its
`prev` (any JSON object with a string `prev`: it may use floats, a string
seq or keys of a format this version doesn't read). If that `prev` doesn't
match, the refused line was altered after it was written (a flipped bit in
its type reads like an unknown type): corrupt. If it matches, the refused
line is intact; the reader says so, and that it can't check the lines
after it. If there is no next line, or it has no `prev` this version can
read, nothing checks the refused line: the reader says it needs a newer
wanderbooks or the line is damaged, and to run verify after updating, and
never that it is intact. A newer format number is newer whatever the rest
of its declaration looks like (a newer format may shape its features
differently); a malformed declaration of a format this version reads is
corrupt. A blank line, or one that isn't UTF-8 JSON, is damage, to the
writer and the viewer alike: both read the journal as bytes split on
newlines. A writer never declares a format it couldn't read back, or
lowers the format in force. Opening the books checks every complete line
before it changes anything: a cut-off last line is set aside only when the
lines before it pass, so an older version never alters newer books.
A line an earlier version can't read is announced by a journal feature ### Product rules
**WB-format-1 The gate: an older reader stops at the first line it can't read,
says the books are newer, and never calls them corrupt.** Every journal line
has a type, and a version of wanderbooks reads a fixed set of them
(`ledger_store::format::EVENT_TYPES`). A newer version may write a type an
older one doesn't know, or declare a newer journal format with a
`journal.format_set {format, features}` line before the first event that needs
it. An older reader stops at the first line it can't read and says so: it
never skips a line (the books it showed would differ from the record without
saying so), and it never calls newer books corrupt.
What every journal format shares is frozen, so that an older reader can always
follow the chain one line past the first line it can't read. A line is the
envelope `{seq, ts, type, payload, prev}` and nothing beside it; its hash
(what the next line's `prev` holds) is the SHA-256 of its canonical JSON: keys
sorted at every depth, no whitespace. A newer format puts its new fields
inside `payload`, never in the envelope, and never changes how a line is
hashed. A line with a key beside the envelope's is refused as newer, never
read with the key dropped, and its hash covers the key, so the next line still
checks it.
Damage stays corruption. A line's seq and `prev` are checked before the gate,
and its own hash is checked by the next line's `prev`; so when the gate
refuses a line, the reader reads the next one first, taking only its `prev`
(any JSON object with a string `prev`: it may use floats, a string seq or keys
of a format this version doesn't read). If that `prev` doesn't match, the
refused line was altered after it was written (a flipped bit in its type reads
like an unknown type): corrupt. If it matches, the refused line is intact; the
reader says so, and that it can't check the lines after it. If there is no
next line, or it has no `prev` this version can read, nothing checks the
refused line: the reader says it needs a newer wanderbooks or the line is
damaged, and to run verify after updating, and never that it is intact. A
newer format number is newer whatever the rest of its declaration looks like
(a newer format may shape its features differently); a malformed declaration
of a format this version reads is corrupt. A blank line, or one that isn't
UTF-8 JSON, is damage, to the writer and the viewer alike: both read the
journal as bytes split on newlines. A writer never declares a format it
couldn't read back, or lowers the format in force. Opening the books checks
every complete line before it changes anything: a cut-off last line is set
aside only when the lines before it pass, so an older version never alters
newer books.
*Enforced:* `ledger_store::format` (`JournalFormat::admit`, `declared`, `gate`, `settle`, `declaration`), `journal::ENVELOPE_KEYS`, `JournalLine::parse`, `journal::read_journal_and_format`, `Snapshot::read_new`, `Store::open`, `Snapshot::check_disk`, `Store::declare_journal_format`, `StoreError::NewerJournal` (its `verified` flag picks the message).
*Checked:* `ledger-store` `tests/format.rs` (`old_reader_gets_newer_journal`, `a_damaged_line_that_looks_newer_is_corrupt_when_the_next_line_checks_it`, `an_unreadable_last_line_is_reported_as_newer_or_damaged`, `a_newer_line_the_next_line_chains_onto_is_newer_and_intact`, `a_newer_format_frames_its_lines_its_own_way`, `an_unknown_envelope_key_is_newer_and_checked_through`, `a_refused_line_followed_by_a_garbled_line_is_unverified`, `a_line_that_is_not_utf8_is_corrupt_for_the_viewer_and_the_writer`, `an_old_reader_never_repairs_newer_books`, `a_blank_line_is_corrupt_for_the_viewer_and_the_writer`, `damaged_journals_are_still_corrupt`) and the unit tests in `format.rs`; `ledger-gui` `tests/newer_journal.rs`; `ledger-cli` `tests/startup.rs`; the `fuzz_store_replay` target (the writer and the viewer agree on newer versus bad).
**WB-format-2 The journal features: a line an earlier version can't read is
announced before the first line that needs it.** A line an earlier version
can't read is announced by a journal feature
(`ledger_store::format::KNOWN_FEATURES`): a new event type, or a field or (`ledger_store::format::KNOWN_FEATURES`): a new event type, or a field or
value on an event type an earlier version knows but would misread. The value on an event type an earlier version knows but would misread. The books
books declare it in a `journal.format_set` before the first line that declare it in a `journal.format_set` before the first line that needs it, so
needs it, so an earlier reader stops at the declaration; this version an earlier reader stops at the declaration; this version declares every
declares every feature it knows at once (below), never one at a time on feature it knows at once (below), never one at a time on the way. P3's:
the way. P3's: `members_cumulative` (B-13: a members close counted from `members_cumulative` (B-13: a members close counted from its count's first
its count's first close, `"rounding": "cumulative_since"`), close, `"rounding": "cumulative_since"`), `account_renamed` (an
`account_renamed` (an `account.renamed`, B-31), `require_tax_category` (a `account.renamed`, B-31), `require_tax_category` (a `settings.set` naming
`settings.set` naming `policy.require_tax_category`, B-32), `policy.require_tax_category`, B-32), `tax_categories_gain_exempt` (an
`tax_categories_gain_exempt` (an `account.tax_set` naming `account.tax_set` naming `form_4797_gain_loss` or `tax_exempt_income`,
`form_4797_gain_loss` or `tax_exempt_income`, categories an earlier version categories an earlier version refuses), `disposal_before_service` (an
refuses), `disposal_before_service` (an `asset.disposed` dated before the `asset.disposed` dated before the asset's in-service date, on or after the day
asset's in-service date, on or after the day it was acquired: an earlier it was acquired: an earlier version refuses a disposal before its purchase
version refuses a disposal before its purchase date), `depreciation_catch_up` date), `depreciation_catch_up` (an `asset.depreciation_posted` whose amount
(an `asset.depreciation_posted` whose amount isn't its month's own: months isn't its month's own: months skipped or reversed caught up in it, B-15; an
skipped or reversed caught up in it, B-15; an earlier version reads it as the earlier version reads it as the month's own, shows the months it caught up as
month's own, shows the months it caught up as not yet run, and running them not yet run, and running them there posts them twice), `party_creditors`
there posts them twice), (`party.creditor_set`: defect 24, B-35), `payment_instruments`
`party_creditors` (`party.creditor_set`: defect 24, B-35), (`instrument.added`, `entry.instrument_set`: defect 12, B-19),
`payment_instruments` (`instrument.added`, `entry.instrument_set`: `vendor_1099_decisions` (`vendor.1099_set` with who decided, a
defect 12, B-19), `vendor_1099_decisions` (`vendor.1099_set` with who `not_reportable` decision, its reason or the date it takes effect, and
decided, a `not_reportable` decision, its reason or the date it takes `vendor.w9_flag_set`: defects 18 and 23, D-40, B-19), `schedule_convention` (a
effect, and `vendor.w9_flag_set`: defects 18 and 23, D-40, B-19), daily schedule's `schedule.registered` carries `convention: daily`; an older
`schedule_convention` (a daily schedule's `schedule.registered` carries version would read it as equal months, B-16; and a `settings.set` naming
`convention: daily`; an older version would read it as equal months, `books.schedule_convention`, a key an earlier version refuses),
B-16; and a `settings.set` naming `books.schedule_convention`, a key an `month_reposting` (a schedule month or a depreciation period posted again
earlier version refuses), `month_reposting` (a schedule month or a depreciation period after a reversal un-posted it; an older version would refuse the second
posted again after a reversal un-posted it; an older version would refuse `schedule.posted`, and its projection ignore the second
the second `schedule.posted`, and its projection ignore the second `asset.depreciation_posted`, B-15), `asset_basis` (an `asset.basis_set`, a new
`asset.depreciation_posted`, B-15), `asset_basis` (an event type: an asset's basis facts with the value at contribution and the
`asset.basis_set`, a new event type: an asset's basis facts with the §704(c) method, B-25) and `projects` (a `project.set`, a new event type: a
value at contribution and the §704(c) method, B-25) and `projects` (a class's project facts; an `attachment.linked` to the subject kind `project`,
`project.set`, a new event type: a class's project facts; an which an older version would call corrupt; a `decision.recorded` with
`attachment.linked` to the subject kind `project`, which an older version `projects`, which an older version would drop silently: B-37). After P3:
would call corrupt; a `decision.recorded` with `projects`, which an older `document_line_projects` (an `invoice.created` or `bill.created` line carrying
version would drop silently: B-37). After P3: `document_line_projects` `class_id`, its project, B-37 item 8; an older version would restore the
(an `invoice.created` or `bill.created` line carrying `class_id`, its document without it, silently). It is a feature of its own, not part of
project, B-37 item 8; an older version would restore the document without `projects`: books that declared `projects` before it existed wait for their
it, silently). It is a feature of its own, not part of `projects`: books owner's next upgrade before a document's line names a project. `documents_v2`
that declared `projects` before it existed wait for their owner's next (plan P4b S4, one feature for S4 to S7: D-52) is the next: a `settings.set` of
upgrade before a document's line names a project. `documents_v2` (plan the `invoicing.*`, `bills.*`, `company.email` or `company.website` keys, which
P4b S4, one feature for S4 to S7: D-52) is the next: a `settings.set` of an earlier version refuses (S4.2); a `party.updated` with an email, a default
the `invoicing.*`, `bills.*`, `company.email` or `company.website` keys, terms fact (S4.2), or a contact-block fact — a phone, a contact person, a
which an earlier version refuses (S4.2); a `party.updated` with an email, billing or shipping address, a billing email (D-55); an `invoice.created` or
a default terms fact (S4.2), or a contact-block fact — a phone, a contact `bill.created` carrying a number, terms, a bill-to or seller snapshot, a
person, a billing or shipping address, a billing email (D-55); an customer reference or memo, a vendor reference, a receipt date or a
`invoice.created` or `bill.created` duplicate's reason, or a line naming its account, quantity or unit price
carrying a number, terms, a bill-to or seller snapshot, a customer (S4.3); S5's `invoice.sent` (who sent an invoice, how, to whom and when: a
reference or memo, a vendor reference, a receipt date or a duplicate's record that moves no figure); S6's payments with `line`, `discount`,
reason, or a line naming its account, quantity or unit price (S4.3);
S5's `invoice.sent` (who sent an invoice, how, to whom and when: a record
that moves no figure); S6's payments with `line`, `discount`,
`discount_line`, `discount_reason`, `fee` or `fee_line`; and S7's `discount_line`, `discount_reason`, `fee` or `fee_line`; and S7's
`invoice.written_off`. An older version would `invoice.written_off`. An older version would restore the document without
restore the document without them silently: every invoice line would post them silently: every invoice line would post to the revenue role and every
to the revenue role and every bill line to general expenses, and every new bill line to general expenses, and every new event type would be refused. P6's
event type would be refused. P6's is `attachment_text` (an is `attachment_text` (an `attachment.text_extracted`, `attachment.annotated`
`attachment.text_extracted`, `attachment.annotated` or `entry.settles`, a or `entry.settles`, a new event type, and an `attachment.withdrawn` carrying
new event type, and an `attachment.withdrawn` carrying `duplicate_of`; an `duplicate_of`; an older version would refuse the types, or withdraw a
older version would refuse the types, or withdraw a duplicate without duplicate without saying what it duplicates, B-44). P4's is `drafts_v2` (an
saying what it duplicates, B-44). P4's is `drafts_v2` (an `entry.draft_state_set` or `entry.draft_discarded`, both new event types: an
`entry.draft_state_set` or `entry.draft_discarded`, both new event types: older version would refuse them, or, reading around them, keep a discarded
an older version would refuse them, or, reading around them, keep a draft that holds a period open and call a waiting draft one being built,
discarded draft that holds a period open and call a waiting draft one B-43). P5's is `source_revisions` (a `convention.source_revised`,
being built, B-43). P5's is `source_revisions` (a `decision.source_revised` or `open_item.source_revised`, new event types: an
`convention.source_revised`, `decision.source_revised` or older version would refuse them, or show the old source as the record's
`open_item.source_revised`, new event types: an older version would authority). P8's is `audits` (an `audit.run`, `receipt.attested`,
refuse them, or show the old source as the record's authority). A command asks for `entry.reviewed` or `period.attested`, all new event types, and the settings
being built, B-43). P8's is `audits` (an `audit.run`, `receipt.attested`, `policy.attestation_bar` and `policy.cpa_package_requires_audit`: an older
`entry.reviewed` or `period.attested`, all new event types, and the version would refuse the types and the keys, or drop the claims a handoff
settings `policy.attestation_bar` and `policy.cpa_package_requires_audit`: rests on, B-45).
an older version would refuse the types and the keys, or drop the claims a
handoff rests on, B-45). A command asks for A command asks for the feature it needs (`Store::ensure_feature`) before its
the feature it needs (`Store::ensure_feature`) before its first journaled first journaled line, and only when the line it is about to write uses it, so
line, and only when the line it is about to write uses it, so a write a write refused for waiting on the upgrade journals nothing, never an entry
refused for waiting on the upgrade journals nothing, never an entry
without the line that says what it is without the line that says what it is
(`a_write_waiting_for_the_upgrade_journals_nothing`), and a write that (`a_write_waiting_for_the_upgrade_journals_nothing`), and a write that needs
needs nothing new is never refused. A tool journaling nothing new is never refused. A tool journaling several commands as one asks
several commands as one asks before the first of them, never between before the first of them, never between them (a refusal there would leave the
them (a refusal there would leave the tool's work half done): tool's work half done): `books.set_w9` asks for `vendor_1099_decisions` before
`books.set_w9` asks for `vendor_1099_decisions` before the W-9 when the the W-9 when the vendor's W-9 flag follows it. A value in a line of a known
vendor's W-9 flag follows it. A value in a line of a known type that only type that only a newer version writes (a 1099 decision or reason kind, a
a newer version writes (a 1099 decision or reason kind, a payment payment method's kind) is newer, never corrupt.
method's kind) is newer, never corrupt.
**The other way round: the format upgrade.** This version's format is *Enforced:* `ledger_store::format` (`JournalFormat::declared`, `require_format`, `require_feature`), `Store::ensure_feature`, `Store::declare_journal_format`, `StoreError::FormatUpgradePending`, `format::setting_feature`, `format::tax_category_feature`.
the newest it reads with every feature it knows (`format::current`). Books *Checked:* `ledger-store` `tests/settings.rs` (`a_change_needs_journal_format_2`), `tests/format_upgrade.rs` (`a_write_waiting_for_the_upgrade_journals_nothing`, a newer feature still refused); `tests/p2_compat.rs` (every P3 setting key and tax category needs a feature); the unit tests in `format.rs`.
it creates declare it in their second line, so they wait for nothing.
Books an older version wrote declare less (format 1, written before the **WB-format-3 The other way round: the format upgrade, with the owner's
gate, declares nothing): they *wait for a format upgrade*, which is a fact go-ahead and a proven backup.** This version's format is the newest it reads
of their journal alone (`JournalFormat::upgrade`). They open and replay as with every feature it knows (`format::current`). Books it creates declare it
they are, byte for byte; everything that needs nothing new is written as in their second line, so they wait for nothing. Books an older version wrote
ever; a write that would need the newer format or a feature they haven't declare less (format 1, written before the gate, declares nothing): they *wait
declared is refused before anything is journaled for a format upgrade*, which is a fact of their journal alone
(`StoreError::FormatUpgradePending`, guard `format_upgrade_pending`), never (`JournalFormat::upgrade`). They open and replay as they are, byte for byte;
declared on the way. Every setting key and tax category an earlier version everything that needs nothing new is written as ever; a write that would need
didn't read needs a feature (`format::setting_feature`, the newer format or a feature they haven't declared is refused before anything
`format::tax_category_feature`: the P3 data-safety review, 2026-10-21, is journaled (`StoreError::FormatUpgradePending`, guard
found `books.schedule_convention`, both new tax categories, a disposal `format_upgrade_pending`), never declared on the way. Every setting key and
before the in-service date and a depreciation catch-up journaled without tax category an earlier version didn't read needs a feature
one, each leaving books P2 refused or misread before consent; (`format::setting_feature`, `format::tax_category_feature`: the P3 data-safety
`tests/p2_compat.rs`). Only the owner's go-ahead moves them, with the owner review, 2026-10-21, found `books.schedule_convention`, both new tax
passphrase (the server checks it, Argon2id): in the app, which asks at categories, a disposal before the in-service date and a depreciation catch-up
journaled without one, each leaving books P2 refused or misread before
consent; `tests/p2_compat.rs`). Only the owner's go-ahead moves them, with the
owner passphrase (the server checks it, Argon2id): in the app, which asks at
every open until it is given, or with `wanderbooks books upgrade ID` at a every open until it is given, or with `wanderbooks books upgrade ID` at a
terminal, whose commands that open the books also ask; never an agent, and terminal, whose commands that open the books also ask; never an agent, and no
no tool. Before the upgrade the server commits the books to their own tool. Before the upgrade the server commits the books to their own backup
backup repository and proves the copy holds them exactly as they are repository and proves the copy holds them exactly as they are (journal, stored
(journal, stored files, vault and keys, byte for byte), all under the files, vault and keys, byte for byte), all under the books' lock; a backup
books' lock; a backup that can't be made or proven upgrades nothing. The that can't be made or proven upgrades nothing. The upgrade is then one
upgrade is then one `journal.format_set` declaring the whole format, so a `journal.format_set` declaring the whole format, so a book's format moves
book's format moves exactly once per version; books already in it are left exactly once per version; books already in it are left alone. An adoption's
alone. An adoption's copy is new books of this version and moves to its copy is new books of this version and moves to its format as it is made (the
format as it is made (the original keeps its own). The upgrade never original keeps its own). The upgrade never weakens the gate: books declaring a
weakens the gate: books declaring a feature this version doesn't know are feature this version doesn't know are newer, as above.
newer, as above.
**Each projection schema in a file of its own** (the lead's decision, *Enforced:* `ledger_store::format` (`current`, `JournalFormat::upgrade`), `Store::create`, `Store::upgrade_format`, `Root::adopt`, `ledger_store::backup::prove_archive`, ledger-mcp `Backups::upgrade_format` and `local.rs` (the passphrase), ledger-host `host.rs` (the lease intent, handed to the server) and `commands.rs` (`books upgrade`, asking at open), ledger-gui `owner.rs` (the notice and the dialog).
2026-10-21, for 3.9's "before consent, the way back is always there"). The *Checked:* `ledger-store` `tests/format_upgrade.rs` (new books in this version's format, a change waiting for the upgrade, every old-books fixture upgrading to its figures, a newer feature still refused), the unit tests in `format.rs` and `backup.rs` (`the_archive_proves_to_hold_the_book_as_it_is_keys_and_all`), `tests/root.rs` (adoption); `ledger-mcp` `local.rs` (`format_upgrade_waits_for_consent`, `no_upgrade_without_a_backup`, `no_upgrade_unless_the_backup_just_made_is_proven`); `ledger-host` `lease.rs` (`a_consent_never_shows_its_passphrase`); `ledger-cli` `tests/format_upgrade.rs` (from end to end); `ledger-gui` `tests/format_upgrade.rs`.
books' SQLite projection is derived from the journal, and its schema moves
with the version (`schema::SCHEMA_VERSION`), but an older version refuses a **WB-format-4 Each projection schema in a file of its own.** (The lead's
database of a newer schema (`SchemaTooNew`). So each schema keeps its own decision, 2026-10-21, for 3.9's "before consent, the way back is always
file, `wanderbooks.v{N}.db` (`store::db_file_for`): a version opens or there".) The books' SQLite projection is derived from the journal, and its
schema moves with the version (`schema::SCHEMA_VERSION`), but an older version
refuses a database of a newer schema (`SchemaTooNew`). So each schema keeps
its own file, `wanderbooks.v{N}.db` (`store::db_file_for`): a version opens or
creates only its own; its own missing, it is built from the journal; the creates only its own; its own missing, it is built from the journal; the
legacy `wanderbooks.db` (every version through P2, schema 12) is used only legacy `wanderbooks.db` (every version through P2, schema 12) is used only
while it already holds this version's schema, so books needing no while it already holds this version's schema, so books needing no migration
migration aren't rebuilt for nothing; a file of any other schema, older or aren't rebuilt for nothing; a file of any other schema, older or newer, is
newer, is never migrated, written, refused or deleted, and stays byte for never migrated, written, refused or deleted, and stays byte for byte for the
byte for the version that wrote it (going back finds it as it left it, or version that wrote it (going back finds it as it left it, or builds its own).
builds its own). A file named for this version's schema that holds another A file named for this version's schema that holds another is damaged, kept
is damaged, kept aside and rebuilt, as a corrupt one is. `books.verify` aside and rebuilt, as a corrupt one is. `books.verify` (`database`,
(`database`, `other_databases`) and `wanderbooks doctor` say which file is `other_databases`) and `wanderbooks doctor` say which file is in use and which
in use and which others are there; none is deleted for being stale. others are there; none is deleted for being stale.
**Enforced:** `ledger_store::format` (`JournalFormat::admit`, `declared`, *Enforced:* `store::db_file_for`, `store::database_in_use` (and `Snapshot::check_disk`, which checks the file it names), `Store::database_file`, `Store::other_databases`, `StoreError::SchemaTooNew`.
`gate`, `settle`, `declaration`, `current`, `JournalFormat::upgrade`, *Checked:* `ledger-store` `tests/schema_files.rs` (a P2-shaped books dir, its `wanderbooks.db` used at its schema and left byte for byte past it; an older schema's file left byte for byte and whole while this version's is built and kept up; a newer schema's file left alone, not refused; a damaged file of this version's schema rebuilt; new books' file named for their schema).
`require_format`, `require_feature`), `journal::ENVELOPE_KEYS`,
`JournalLine::parse`, `journal::read_journal_and_format`, ---
`Snapshot::read_new`, `Store::open`, `Store::create`, `store::db_file_for`,
`store::database_in_use` (and `Snapshot::check_disk`, which checks the file
it names), `Store::database_file`, `Store::other_databases`,
`Store::declare_journal_format`, `Store::upgrade_format`,
`Store::ensure_feature`, `Root::adopt`, `StoreError::NewerJournal` (its
`verified` flag picks the message), `StoreError::FormatUpgradePending`,
`ledger_store::backup::prove_archive`, ledger-mcp `Backups::upgrade_format`
and `local.rs` (the passphrase), ledger-host `host.rs` (the lease intent,
handed to the server) and `commands.rs` (`books upgrade`, asking at open),
ledger-gui `owner.rs` (the notice and the dialog).
**Checked:** `ledger-store` `tests/format.rs` (`old_reader_gets_newer_journal`,
`a_damaged_line_that_looks_newer_is_corrupt_when_the_next_line_checks_it`,
`an_unreadable_last_line_is_reported_as_newer_or_damaged`,
`a_newer_line_the_next_line_chains_onto_is_newer_and_intact`,
`a_newer_format_frames_its_lines_its_own_way`,
`an_unknown_envelope_key_is_newer_and_checked_through`,
`a_refused_line_followed_by_a_garbled_line_is_unverified`,
`a_line_that_is_not_utf8_is_corrupt_for_the_viewer_and_the_writer`,
`an_old_reader_never_repairs_newer_books`,
`a_blank_line_is_corrupt_for_the_viewer_and_the_writer`,
`damaged_journals_are_still_corrupt`) and the unit tests in `format.rs`;
`ledger-gui` `tests/newer_journal.rs`; `ledger-cli` `tests/startup.rs`;
the `fuzz_store_replay` target (the writer and the viewer agree on newer
versus bad). The upgrade: `ledger-store` `tests/format_upgrade.rs` (new
books in this version's format, a change waiting for the upgrade, every
old-books fixture upgrading to its figures, a newer feature still
refused), the unit tests in `format.rs` and `backup.rs`
(`the_archive_proves_to_hold_the_book_as_it_is_keys_and_all`),
`tests/settings.rs` (`a_change_needs_journal_format_2`), `tests/root.rs`
(adoption), `tests/schema_files.rs` (a P2-shaped books dir, its
`wanderbooks.db` used at its schema and left byte for byte past it; an
older schema's file left byte for byte and whole while this version's is
built and kept up; a newer schema's file left alone, not refused; a damaged
file of this version's schema rebuilt; new books' file named for their
schema); `ledger-mcp` `local.rs` (`format_upgrade_waits_for_consent`,
`no_upgrade_without_a_backup`,
`no_upgrade_unless_the_backup_just_made_is_proven`); `ledger-host`
`lease.rs` (`a_consent_never_shows_its_passphrase`); `ledger-cli`
`tests/format_upgrade.rs`
(from end to end); `ledger-gui` `tests/format_upgrade.rs`.
## B-34 The QuickBooks Desktop file (IIF): plain ASCII, every entry through as_of, closes left out, classes carried ## B-34 The QuickBooks Desktop file (IIF): plain ASCII, every entry through as_of, closes left out, classes carried
**bookspec:** `BS-format-2` **bookspec:** `BS-format-2`
**Status:** AUTHORITY (Intuit, `sources/intuit-iif.md`: IIF files are **Claims:** yes
ASCII text, tab-separated, with no escape; an account is known by its
NAME, a subaccount's NAME its path joined by colons; lists come before
what uses them; DOCNUM is "the transaction's number"; the kit's 2007+
example file ends every line CR LF; QuickBooks Desktop holds an account
name of 31 characters, an account number of 7 and a memo of 4,095; "The
parent and subaccount must be the same account type"; a journal entry
to accounts receivable or payable needs a customer or vendor, and takes
one such account a transaction; a class list's keyword is CLASS, "Only
the NAME column is required", a subclass's NAME its parents' first,
joined by colons, and the kit declares its classes before the
transactions that name them, line by line in CLASS; Intuit's qbXML
Onscreen Reference, `ClassAdd`: a class's Name at most 31 characters in
QuickBooks Desktop, as an account's); CONVENTION (a
QuickBooks integrator and an IIF importer, same file: a longer name is
cut on a chart import but not in a journal's lines; a double quote is a
text delimiter; Conductor's QuickBooks Desktop API: a class's name
case-insensitive, so no two alike ignoring case); CHOICE (owner, 2026-10-20, plan D-36: plain ASCII, what isn't
ASCII transliterated and listed; CR LF; DOCNUM the entry's id; closing
entries left out; every entry since the company began until the CPA
says otherwise); Unicode Standard Annex #14 (the mandatory line breaks)
1. **One transaction per posted entry dated on or before as_of**, from **Pick:** `plain-ascii-transliterated-and-listed`, `cr-lf`,
the first, in the order posted, **except period-closing entries**: `docnum-is-the-entry-id`, `closes-left-out` and `everything-through-as-of`:
QuickBooks keeps no closing entries (it works out retained earnings CHOICE (the owner, 2026-10-20, D-36): plain ASCII, what isn't ASCII
itself; its "closing date" only locks a period), so an imported close transliterated (deunicode 1.6.0, pinned exactly, see WB-format-7) and listed,
would zero its period's profit. The file's balances are the trial rather than the books' own text; CR LF, rather than the host's line ending;
balance as of as_of without the closes, and its income and expenses DOCNUM the entry's id, rather than the file's place in it; closing entries
each period's profit and loss; the members' shares are in the left out, rather than written; every entry since the company began, until the
package's members' equity statement and K-1 worksheet. CPA says otherwise. Whether the file should hold only the fiscal year instead
`books.export` iif takes as_of (default today), never a range. goes to the CPA before the 2027 package (D-36); for the first year the two are
Whether the file should hold only the fiscal year instead goes to the the same. Also CONVENTION: a class name exactly as the books have it is kept
CPA before the 2027 package (D-36); for the first year the two are unless another class's own name is the same ignoring case (the P4 follow-ups'
the same. review, finding 4, 2026-10-22: before, all the classes whose names matched
2. **DOCNUM is the entry's id** in the books, on the TRNS and every SPL, were renamed).
so the CPA can trace a QuickBooks transaction to its entry and its
receipts.
3. **The file is ASCII and every line ends CR LF.** In a field (a NAME,
an ACCNUM, a MEMO) a tab or a mandatory line break (LF, VT, FF, CR,
NEL, U+2028, U+2029) is a space; any other control character is '?';
printable ASCII is itself, but a double quote, which is a single one
(QuickBooks reads a double quote as a text delimiter); any other
character is its transliteration by deunicode 1.6.0, pinned exactly
("René" "Rene", "北京" "Bei Jing", "—" "--", "“" "'", "😀" "grinning";
a transliterated word's trailing space dropped at the end or before a
space), or '?' when it has none. Every other file in the package keeps
the books' text (the PDFs carry Inter and Noto fallbacks for Chinese,
Japanese, Korean, Arabic, Hebrew, Thai and Devanagari, Arabic and
Hebrew set right to left; no emoji font, so an emoji prints as an
empty box).
4. **An account's own name**, so written, has each ':' replaced by '-'
(a fullwidth colon too), is trimmed ('?' if nothing is left) and cut
to 31 characters (QuickBooks Desktop's limit; cut by QuickBooks, the
ACCNT line and the transactions' would no longer match); its NAME is
its parents' NAMEs and its own, joined by ':'. A subaccount whose
QuickBooks type differs from its parent's (a bank account under a
header that is no bank, an asset's cost under a "Fixed assets" header)
is written at the top level, its own subaccounts with it: QuickBooks
gives a subaccount its parent's type, and the type decides where its
balance shows. Each parent is declared before its subaccounts, the
accounts otherwise in the order of their codes. Accounts whose NAMEs
would match ignoring case, which QuickBooks would merge, get
" (code)" after their own names (the name cut to make room, the code
written like a name, "no number" for a blank one), level by level from
the top and again until no two match; a match left after that (two
codes written alike, ignoring case, or alike in their first 30
characters) is refused.
5. **ACCNUM is the account's code**, written as a field and trimmed, or
left blank (ACCNUM is optional; the NAME identifies the account) when
it is longer than 7 characters (QuickBooks Desktop's limit) or another
account's would be written the same, ignoring case. **A MEMO** is cut
to 4,095 characters (QuickBooks Desktop's limit).
6. **Nothing changes silently.** Each account name, number or place and
each memo the file writes differently from the books (`Iif::changes`)
is said, both texts quoted and escaped, one line each, in the
`warnings` of `books.export` and `books.export_cpa_package` and in the
package README (the viewer's note counts them): each account's name,
number and place a line; the memos grouped by what is written
differently, each run of changed characters once with every entry it
is in (`"—" is written "--" in the memos of entries 3, 5, 9`), then
the memos cut. No line holds a full TIN (B-26): a run of nine digits,
in any script's digits and separators, is masked, and so is every
numeral of a text that holds one once written as a field (digits a
tab apart, letters deunicode writes as digits); a memo line whose
digits are masked says so.
7. **No customer or vendor NAME.** Intuit's IIF help makes NAME
optional and states no need of it in a journal; QuickBooks Desktop
asks for a customer or vendor on a journal entry to accounts
receivable or payable, and takes one A/R or A/P account a transaction
(Intuit staff and help, `sources/intuit-iif.md`). Writing names would
need the customer and vendor lists declared as well, with names unique
across them. So the file names none, and the package README names the
entries with a line on an A/R or A/P account (`Iif::receivable_payable`),
so the CPA can add the name if QuickBooks asks.
8. **Each line's class (project, B-37) is its CLASS**, and every class in
the books is declared in a `!CLASS` list (NAME) after the accounts and
before the transactions, as the kit declares its lists; books with no
class write no list. A class's NAME is written as an account's own
name is (rules 3 and 4: plain ASCII, a ':' a '-' since a colon starts
a subclass, trimmed, '?' if nothing is left, cut to 31 characters);
classes whose NAMEs would match ignoring case get " (id)" after their
names (the name cut to make room), round after round until none does,
as accounts get " (code)", except that among names that match, those
already written differently from the books (made safe, or tagged)
yield first, another " (id)" each time need be (CONVENTION: the CPA sees
the books' own names wherever they can stand): a class's name
written exactly as the books have it is kept unless another class's
own name is the same ignoring case (classes 1 "Café", 2 "Cafe" and 3
"Cafe (1)": "Cafe (1) (1)", the other two kept; review of the P4 follow-ups, finding 4,
2026-10-22: before, all three were renamed; and a fourth "Cafe (1) (1)"
makes class 1 "Cafe (1) (1) (1)", where a cap of two tags once renamed
class 4 instead). A tag that would change nothing (a name cut to 31
characters, ending in its own " (id)") isn't made: the name it meets
is tagged instead. Each class name written differently is
listed with rule 6's (`class 2's name "Café rebrand" is written "Cafe
rebrand"`), and the package README's "written differently" paragraph
says class names are held to 31 characters, no two alike. A line
whose class isn't declared is refused, never written classless. Before
2026-10-22 the file left CLASS empty on every line and the README
didn't say so (the P3 cutover review's open point 1).
**Enforced:** `ledger_import::iif` (`field`, `iif_accounts`, **Enforced:** `ledger_import::iif` (`field`, `iif_accounts`, `iif_classes`,
`iif_classes`, `journal_to_iif`, `Iif::warnings`), `ledger_package::export_iif` and `journal_to_iif`, `Iif::warnings`, `Iif::changes`, `Iif::receivable_payable`),
`build_package`, `ledger-mcp` `books.export` and `ledger_package::export_iif` and `build_package`, `ledger-mcp` `books.export`
`books.export_cpa_package`. and `books.export_cpa_package`. **Checked:** `ledger-import` `iif.rs` unit
**Checked:** `ledger-import` `iif.rs` unit tests (every one of the tests (every one of the 1,112,064 Unicode scalar values written as printable
1,112,064 Unicode scalar values written as printable ASCII, alone and ASCII, alone and beside a letter, and kept by a second pass; the
beside a letter, and kept by a second pass; the transliteration table transliteration table pinned); `tests/spec_import.rs`
pinned); `tests/spec_import.rs` (`iif_docnum_is_the_entry_id`, (`iif_docnum_is_the_entry_id`,
`iif_writes_plain_ascii_and_lists_every_change`, `iif_writes_plain_ascii_and_lists_every_change`, `iif_every_line_ends_cr_lf`,
`iif_every_line_ends_cr_lf`, `iif_distinct_accounts_never_share_a_name`, `iif_distinct_accounts_never_share_a_name`,
`iif_a_subaccount_of_another_type_stands_at_the_top_level`, `iif_a_subaccount_of_another_type_stands_at_the_top_level`,
`iif_declares_each_parent_before_its_subaccounts`, `iif_declares_each_parent_before_its_subaccounts`,
`iif_fits_quickbooks_desktop_limits`, `iif_fits_quickbooks_desktop_limits`,
`iif_warnings_group_the_memos_by_what_is_written_differently`, `iif_warnings_group_the_memos_by_what_is_written_differently`,
`iif_warnings_never_hold_a_tin`, `iif_warnings_never_hold_a_tin`, `iif_change_warnings_are_one_line_each`,
`iif_change_warnings_are_one_line_each`,
`iif_keeps_a_tin_readable_to_the_package_scan`, `iif_keeps_a_tin_readable_to_the_package_scan`,
`iif_writes_each_lines_class_and_declares_the_classes_first`, `iif_writes_each_lines_class_and_declares_the_classes_first`,
`iif_class_names_fit_quickbooks_and_every_change_is_listed`, `iif_class_names_fit_quickbooks_and_every_change_is_listed`,
@@ -384,8 +261,8 @@ pinned); `tests/spec_import.rs` (`iif_docnum_is_the_entry_id`,
`iif_refuses_an_undeclared_or_unfit_class`, the properties `iif_refuses_an_undeclared_or_unfit_class`, the properties
`iif_round_trips_random_books`, `iif_round_trips_random_books`,
`iif_names_never_clash_and_every_change_is_listed` and `iif_names_never_clash_and_every_change_is_listed` and
`iif_class_names_never_clash`); `ledger-package` `iif_class_names_never_clash`); `ledger-package` `tests/package.rs`
`tests/package.rs` (`iif_leaves_out_period_closes`, (`iif_leaves_out_period_closes`,
`the_readme_lists_what_the_iif_writes_differently`, `the_readme_lists_what_the_iif_writes_differently`,
`the_readme_names_the_entries_on_receivables_and_payables`, `the_readme_names_the_entries_on_receivables_and_payables`,
`the_package_iif_carries_each_lines_project`, `the_package_iif_carries_each_lines_project`,
@@ -398,3 +275,36 @@ appendix: the file line by line and its changes, derived by hand);
`mcp_journeys.rs` (`mcp_import_export`, `mcp_journeys.rs` (`mcp_import_export`,
`the_default_period_never_shortens_the_iif_or_the_package`). `the_default_period_never_shortens_the_iif_or_the_package`).
### Product rules
**WB-format-5 The tool surface and the package's words.** `books.export` iif
takes `as_of` (default today), never a range, and DOCNUM lets the CPA trace a
QuickBooks transaction to its entry and its receipts (its supporting
documents, B-20). Each change the file reports is said in the `warnings`
of `books.export` and `books.export_cpa_package` and in the package README
(the viewer's note counts them); no line of them holds a full TIN (B-26). The
package README names the entries with a line on an A/R or A/P account
(`Iif::receivable_payable`), so the CPA can add the name if QuickBooks asks,
and its "written differently" paragraph says class names are held to 31
characters, no two alike, and lists each class name written differently with
the accounts' (`class 2's name "Café rebrand" is written "Cafe rebrand"`).
*Enforced:* ledger-mcp `books.export` and `books.export_cpa_package`, `ledger_package::build_package` (the README), `ledger_import::iif::Iif::warnings`.
*Checked:* `ledger-package` `tests/package.rs` (`the_readme_lists_what_the_iif_writes_differently`, `the_readme_names_the_entries_on_receivables_and_payables`); `ledger-import` `tests/spec_import.rs` (`iif_warnings_group_the_memos_by_what_is_written_differently`, `iif_change_warnings_are_one_line_each`, `iif_warnings_never_hold_a_tin`, `iif_class_names_fit_quickbooks_and_every_change_is_listed`); `ledger-cli` `oracle_mcp.rs` (`iif_without_as_of_is_as_of_today_and_ties_to_the_trial_balance`), `mcp_journeys.rs` (`the_default_period_never_shortens_the_iif_or_the_package`).
**WB-format-6 The rest of the package keeps the books' text.** Every other
file in the package keeps the books' text (the PDFs carry Inter and Noto
fallbacks for Chinese, Japanese, Korean, Arabic, Hebrew, Thai and Devanagari,
Arabic and Hebrew set right to left; no emoji font, so an emoji prints as an
empty box). The members' shares are in the package's members' equity statement
and K-1 worksheet, not in the IIF.
*Enforced:* `ledger_import::fonts` (`INTER`, `FALLBACKS`: Inter and the five Noto fallbacks, bundled once in the binary), `ledger_package::build_package`, `ledger_package::reports::member_capitals`, `ledger_package::k1_tax`.
*Checked:* `ledger-package` `tests/package.rs` (the package's files); `ledger-import` `tests/spec_import.rs` (`pdf_keeps_chinese_japanese_and_korean_names`, `pdf_prints_every_bundled_script_as_written`: each of the five fallbacks is embedded, and Arabic and Hebrew read left to right in the extracted text).
**WB-format-7 The transliteration table is deunicode 1.6.0, pinned exactly.**
"René" is "Rene", "北京" is "Bei Jing", "—" is "--", "“" is "'", "😀" is
"grinning". The table is a dependency pinned to one version, so two writers of
the same text write the same characters; the test writes every one of the
1,112,064 Unicode scalar values, alone and beside a letter, and a second pass
keeps it.
*Enforced:* `ledger-import` `Cargo.toml` (`deunicode = { version = "=1.6.0", default-features = false }`), `ledger_import::iif::field`.
*Checked:* `ledger-import` `iif.rs` unit tests (every Unicode scalar value as printable ASCII; the transliteration table pinned).
+8 -2
View File
@@ -73,8 +73,14 @@ None.
**Pick:** none (AUTHORITY). **Pick:** none (AUTHORITY).
**Enforced:** posted entries immutable. **Checked:** Lean `Step.extends`, **Enforced:** posted entries immutable; `ledger_store::format`
`Steps.extends`; property `prop_posted_entries_immutable`. (`JournalFormat::admit`, `gate`): a record in a format version this
version does not know is refused as newer, neither misread nor skipped,
and never called corrupt (statement 4). **Checked:** Lean `Step.extends`,
`Steps.extends`; property `prop_posted_entries_immutable`; `ledger-store`
`tests/format.rs` (`old_reader_gets_newer_journal`,
`a_newer_line_the_next_line_chains_onto_is_newer_and_intact`,
`damaged_journals_are_still_corrupt`).
### Product rules ### Product rules