refactor: rule references cite bookspec ids

Every B-n citation in crates/, docs/, deploy/, scripts/ and .github/ now names its bookspec id BS-<area>-<n> (D-68), via scripts/rewrite-rule-refs.py: the map is parsed from docs/spec/rules.md's index, rules.md-prefixed and bare forms are rewritten, sub-references (rule 11, item 7, INVARIANT 2) survive, and plan/, docs/spec/rules.md and docs/spec/claims/ are untouched. Program-output string literals that cited a rule were reverted by hand so user-visible output and its goldens are unchanged; DatedRule.catalog, metadata no output prints, now holds BS-1099-1. One SOURCE line that cited only 'R-?' now also cites BS-statement-5.

Co-Authored-By: Muse Wonder 1.0
This commit is contained in:
swaitsandMuse Wonder 1.0 committed 2026-11-08 19:40:22 -07:00
1 parent 7a177a3cfc
commit 489360f598
221 files changed
+1706 -1580

No files matched your search

+1 -1
View File
@@ -470,7 +470,7 @@ impl App {
///
/// ```text
/// GOAL: the viewer shows what the agent was told it shows.
/// SOURCE: rules.md B-30 (one default period; a start after the end is
/// SOURCE: BS-period-3 (one default period; a start after the end is
/// refused, never swapped); plan/served.md P3 defect 15.
/// INVARIANTS:
/// 1. A target's dates are taken as the server resolved them, an
+1 -1
View File
@@ -151,7 +151,7 @@ mod tests {
.unwrap()
}
/// INVARIANT 2's cash flow items (rules.md B-14 rule 12, D-35): a
/// INVARIANT 2's cash flow items (BS-statement-3 rule 12, D-35): a
/// sale of equipment for an IOU is a Todo naming the entry, with the
/// statement's fix; equipment bought on an operating card is Info; a
/// sale for cash asks nothing.
+12 -12
View File
@@ -29,7 +29,7 @@ pub struct EntryInfo {
pub status: EntryStatus,
/// Total debits; None when they can't be summed exactly (a draft's
/// lines are as an earlier version journaled them, of any size:
/// rules.md B-28).
/// BS-entry-4).
pub amount: Option<Decimal>,
/// Accounts touched, debits first: "6300 Software".
pub accounts: Vec<AccountId>,
@@ -182,10 +182,10 @@ pub fn period_month(period: &str) -> Option<(i32, u32)> {
/// 4. open_invoices = Σ what each of its customer record's invoices
/// owes today (Books::owed_today: read from the ledger lines tagged
/// with it, so a reversed payment or a void counts as it should,
/// rules.md B-38); open_bills the same for its vendor record's bills.
/// BS-arap-2); open_bills the same for its vendor record's bills.
/// 4a. Each of 3 and 4 is None when it can't be summed exactly (a
/// document is restored as an earlier version journaled it, of any
/// size: rules.md B-28), never a wrong number.
/// size: BS-entry-4), never a wrong number.
/// 5. form_1099: its vendor record's line in Books::vendor_1099(year)
/// (the server's books.vendor_1099), when it has a vendor record in
/// that report and the report can be made (the year's threshold is
@@ -222,7 +222,7 @@ pub struct PartyInfo {
/// ```text
/// GOAL: say when monthly depreciation hasn't been run, without crying
/// wolf over the month still under way.
/// SOURCE: docs/spec/rules.md B-15 (monthly straight-line depreciation);
/// SOURCE: BS-asset-1 (monthly straight-line depreciation);
/// CONVENTION (a month's depreciation is posted when the month
/// ends: ledger-store dates it the month's last day).
/// INVARIANTS:
@@ -355,7 +355,7 @@ pub enum PartyPeriod {
/// get back?" (owner, 2026-10-15) with the books' own numbers.
/// SOURCE: ledger_core::parties::activity_with (paid, received, in kind)
/// and ledger_core::parties::flow (what for), with Books::money
/// and Books::members, as PartyInfo uses them; rules.md B-35.
/// and Books::members, as PartyInfo uses them; BS-partner-3.
/// INVARIANTS:
/// 1. paid, received: Books::activity(party, span)'s, exactly: basis
/// cash (money), books.party's default. paid_in_kind and
@@ -919,8 +919,8 @@ impl Books {
}
/// What omitted dates mean today, for these books: the one rule the
/// server's report tools, `books.show` and the viewer share (rules.md
/// B-30).
/// server's report tools, `books.show` and the viewer share (
/// BS-period-3).
pub fn periods(&self) -> ledger_core::calendar::PeriodDefaults {
ledger_core::calendar::period_defaults(&self.settings.company, self.today)
}
@@ -938,7 +938,7 @@ impl Books {
}
/// The period a report or register opens on when nobody chose one:
/// the fiscal year to date (rules.md B-30), as the agent's report
/// the fiscal year to date (BS-period-3), as the agent's report
/// tools give it for no dates.
pub fn default_period(&self) -> (NaiveDate, NaiveDate) {
self.periods().statement_range()
@@ -1320,7 +1320,7 @@ impl Books {
}
/// A document as of today: what it is, read from the ledger lines
/// tagged with it (ledger_core::Ledger::doc_state, rules.md B-38), the
/// tagged with it (ledger_core::Ledger::doc_state, BS-arap-2), the
/// figures books.ar_aging and books.party read. One dated after today
/// (a post-dated bill) is read as of its own date: what it will owe
/// when it is issued, so the forward-looking views keep it; it is
@@ -1763,7 +1763,7 @@ impl Books {
/// their capital (a reimbursement with a distribution) leaves out the
/// money that wasn't theirs.
/// What moved in kind isn't what money paid for: when the party's part
/// has property in it (rules.md B-35), the property lines (asset
/// has property in it (BS-partner-3), the property lines (asset
/// accounts neither cash nor receivables, the K-1 worksheet's test)
/// stay out, so a property contribution, and its reversal, show
/// nothing, and a distribution of money and equipment shows the
@@ -2011,8 +2011,8 @@ impl Books {
///
/// Every month the span touches is one activity scan, so callers clip
/// the span to the months they show ([`Books::last_months`]): books
/// an earlier version wrote may run from chrono's first day (rules.md
/// B-28). Chrono's last month ends the walk, never a panic.
/// an earlier version wrote may run from chrono's first day (
/// BS-entry-4). Chrono's last month ends the walk, never a panic.
pub fn party_months(&self, party: PartyId, span: (NaiveDate, NaiveDate)) -> Vec<PartyMonth> {
let mut out = Vec::new();
let mut m = span.0.with_day(1);
+3 -3
View File
@@ -242,12 +242,12 @@ pub fn build(dir: &Path, today: NaiveDate) -> Result<(), StoreError> {
Some("depreciation"),
)?;
let bank_fees = acct(&mut s, "6900", "Bank Fees", Expense, None)?;
// The projects (classes with their facts, rules.md B-37).
// The projects (classes with their facts, BS-statement-5).
let client_class = s.add_project(
"Client work",
&ledger_core::ProjectFacts {
// Its invoices' lines and the contractors it pays are tagged
// to it (rules.md B-37 item 8), so its snapshot is its
// to it (BS-statement-5 item 8), so its snapshot is its
// revenue less its direct costs.
description: Some(
"Design work for the studio's clients: every client invoice, and the contractors who work on it."
@@ -306,7 +306,7 @@ pub fn build(dir: &Path, today: NaiveDate) -> Result<(), StoreError> {
.map(|n| s.add_customer(n))
.collect::<Result<_, _>>()?;
// Work on spec for a customer, hoping they adopt it: its costs are
// expenses, and nothing is receivable (rules.md B-37 item 4).
// expenses, and nothing is receivable (BS-statement-5 item 4).
let tidepool_started = start + Months::new(13);
let tidepool = s.add_project(
"Tidepool app",
+3 -3
View File
@@ -31,8 +31,8 @@ pub fn money(d: Decimal) -> String {
}
}
/// What the viewer shows for a figure the books can't compute (rules.md
/// B-28: an earlier version's draft lines, shares, or bases past exact
/// What the viewer shows for a figure the books can't compute (
/// BS-entry-4: an earlier version's draft lines, shares, or bases past exact
/// arithmetic): said in words, never a number.
pub const CANT_COMPUTE: &str = "too large to compute";
@@ -233,7 +233,7 @@ mod tests {
use std::str::FromStr;
/// money_or / dollars_or: a figure as money_ or dollars does, and one
/// the books can't compute in words, never a number (rules.md B-28).
/// the books can't compute in words, never a number (BS-entry-4).
#[test]
fn a_figure_or_why_not() {
let v = Decimal::new(-123_456, 2);
+1 -1
View File
@@ -31,7 +31,7 @@ pub struct State {
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
pub enum RegisterRange {
/// What a register opens on when nobody chose dates: the fiscal year
/// to date (rules.md B-30, `Books::default_period`), its opening
/// to date (BS-period-3, `Books::default_period`), its opening
/// balance carried in.
#[default]
Default,
+2 -2
View File
@@ -5,11 +5,11 @@
//! `depreciation_schedule`, `Asset::basis_figures`), what is posted too
//! (`Ledger::accumulated_posted`, its runs). Book value is what the books
//! carry (cost less the depreciation posted), never the schedule's figure,
//! which sits beside it as "scheduled" (B-24). Book value and the federal
//! which sits beside it as "scheduled" (BS-asset-3). Book value and the federal
//! tax figures sit side by side and are never confused: book cost is what
//! was paid or, for a member's contribution, its fair market value; the
//! §723 basis, the depreciable basis and the §704(c) built-in gain follow
//! the basis rule (docs/spec/rules.md B-25).
//! the basis rule (BS-asset-4).
use super::page;
use crate::app::Shell;
+2 -2
View File
@@ -182,7 +182,7 @@ fn runway(ui: &mut Ui, b: &Books) {
return;
}
// Exact or refused: books near the arithmetic's limit show a
// note, never a crash (rules.md B-28).
// note, never a crash (BS-entry-4).
let Some(net) = ledger_core::kernel::total_try(&months, |&(_, _, i, o)| {
ledger_core::kernel::Amount::checked_sub(i, o)
})
@@ -335,7 +335,7 @@ fn coming_up(ui: &mut Ui, b: &Books, shell: &mut Shell<'_>) {
let Some(inv) = b.ledger.get_invoice(id) else {
continue;
};
// As of today, from the lines tagged with it (rules.md B-38): a
// As of today, from the lines tagged with it (BS-arap-2): a
// reversed payment reopens it, a void closes it.
let state = b.doc_today(ledger_core::DocRef::Invoice(id));
let balance = crate::books::owed_of(&state);
+4 -4
View File
@@ -224,7 +224,7 @@ pub fn detail(ui: &mut Ui, b: &Books, e: &EntryInfo, shell: &mut Shell<'_>) {
widgets::amount_cell(ui, "Credit", amt_w, p.muted, false, false);
});
// None: past exact arithmetic (a draft line an earlier
// version journaled, of any size: rules.md B-28).
// version journaled, of any size: BS-entry-4).
let (mut dr, mut cr) = (Some(Decimal::ZERO), Some(Decimal::ZERO));
for line in entry.lines() {
ui.horizontal(|ui| {
@@ -302,7 +302,7 @@ pub fn detail(ui: &mut Ui, b: &Books, e: &EntryInfo, shell: &mut Shell<'_>) {
ui.add_space(18.0);
// The invoice or bill it records: its lines as the document
// gives them, each project a link (rules.md B-37 item 8).
// gives them, each project a link (BS-statement-5 item 8).
if let Some(doc) = document_of(b, e.id) {
section(ui, &doc.title);
document_lines(ui, &doc, &class_names, total_w, amt_w, shell);
@@ -681,7 +681,7 @@ pub fn render(ui: &mut Ui, b: &Books, a: &Attachment, shell: &mut Shell<'_>, wid
}
}
/// A party's part of an entry in words (rules.md B-35): which way it
/// A party's part of an entry in words (BS-partner-3): which way it
/// went and how much ("paid $64.00", "received $740.00, in kind"), what of
/// it is still owed, the share it came from when the entry names several
/// ("(50%)", "(derived)"), and a reversal said as one ("paid $1,480.00
@@ -756,7 +756,7 @@ mod tests {
/// A tagged line keeps its project tag inside its cell, in a narrow
/// pane too: the name is cut to leave the tag room, so the amounts
/// stay in their columns (an invoice's revenue line and its document
/// line, each tagged; rules.md B-37 item 8).
/// line, each tagged; BS-statement-5 item 8).
#[test]
fn a_tagged_line_keeps_its_amounts_in_their_column() {
use ledger_core::arap::DocumentLine;
+2 -2
View File
@@ -1,7 +1,7 @@
//! Invoices and bills: what customers owe the company (money in) and what
//! it owes vendors (money out), each figure derived from the document's
//! ledger lines that stand (rules.md B-38), the list tied to the
//! receivables or payables account (B-23); and one document's page, with
//! ledger lines that stand (BS-arap-2), the list tied to the
//! receivables or payables account (BS-ledger-8); and one document's page, with
//! its lines and its timeline. Read only (D-28): the agent issues, pays
//! and voids them.
+4 -4
View File
@@ -560,7 +560,7 @@ pub fn show_list(ui: &mut Ui, b: &Books, shell: &mut Shell<'_>) {
});
}
/// The party's totals with property in kind (basis all, rules.md B-35
/// The party's totals with property in kind (basis all, BS-partner-3
/// item 4), when it gave or took any in the period: "With property
/// contributed or distributed: paid $X, received $Y". None when nothing
/// moved in kind (the cash totals are then the whole story).
@@ -775,7 +775,7 @@ pub fn show_party(ui: &mut Ui, b: &Books, id: PartyId, shell: &mut Shell<'_>) {
r.context_menu(|ui| widgets::copy_item(ui, "Copy amount", &v.to_string()));
}
});
// Basis all (rules.md B-35 item 4): property in kind, when any.
// Basis all (BS-partner-3 item 4): property in kind, when any.
if let Some(text) = in_kind_text(&flow) {
ui.add_space(6.0);
ui.add(
@@ -1194,7 +1194,7 @@ fn records_card(ui: &mut Ui, b: &Books, party: &Party, info: &PartyInfo, go: &mu
);
}
/// The projects for or with the party (rules.md B-37), by name: status
/// The projects for or with the party (BS-statement-5), by name: status
/// and net to date; a row opens its project.
fn projects_card(ui: &mut Ui, b: &Books, ids: &[ledger_core::ClassId], go: &mut Option<Route>) {
let p = pal(ui.ctx());
@@ -1416,7 +1416,7 @@ fn documents_card(ui: &mut Ui, b: &Books, info: &PartyInfo, go: &mut Option<Rout
docs.sort_by(|a, b| b.1.cmp(&a.1).then(a.0.cmp(&b.0)));
for (name, date, due, state, total, balance, entry) in docs {
// Late and its status as of today, from the ledger
// lines tagged with it (rules.md B-38; P4b.2 gap 10):
// lines tagged with it (BS-arap-2; P4b.2 gap 10):
// a reversed payment makes it owed again, a void
// never late.
let late = matches!(state, Ok(Some(st)) if st.overdue_days > 0);
+5 -5
View File
@@ -1,9 +1,9 @@
//! Projects: every class, with its facts (what it is, where it stands, who
//! it is for), and one project completely: its snapshot (revenue, direct
//! costs, contribution before overhead and its margin, to date or this
//! fiscal year, rules.md B-37 item 7), revenue and costs by month with the
//! fiscal year, BS-statement-5 item 7), revenue and costs by month with the
//! running net, costs by category and by account, its entries, documents,
//! decisions and history (rules.md B-37). Every figure is ledger-core's (`project_figures`,
//! decisions and history (BS-statement-5). Every figure is ledger-core's (`project_figures`,
//! `project_to_date`, `project_entries`), the same the server's
//! `books.projects` and `books.project` return; this module only arranges
//! them, and never writes.
@@ -29,7 +29,7 @@ use rust_decimal::Decimal;
pub struct State {
/// Only projects with this status (None: every one).
pub status: Option<ProjectStatus>,
/// A project's snapshot shows this fiscal year to date (B-30's
/// A project's snapshot shows this fiscal year to date (BS-period-3's
/// omitted dates), not to date.
pub fiscal: bool,
}
@@ -419,7 +419,7 @@ impl Snap {
}
/// The note on contribution: what it counts and what it leaves out.
pub const CONTRIBUTION_NOTE: &str = "Revenue less this project's direct costs: every expense line tagged to it, fixed and variable alike (what management accounting calls a segment margin, not a variable-cost contribution margin). Company overhead that isn't tagged to a project (rent, software, insurance, the owner's time) isn't counted, so a project in the black can still leave the company in the red. A management-accounting view (rules.md B-37 item 7), not a GAAP figure.";
pub const CONTRIBUTION_NOTE: &str = "Revenue less this project's direct costs: every expense line tagged to it, fixed and variable alike (what management accounting calls a segment margin, not a variable-cost contribution margin). Company overhead that isn't tagged to a project (rent, software, insurance, the owner's time) isn't counted, so a project in the black can still leave the company in the red. A management-accounting view (B-37 item 7), not a GAAP figure.";
/// The snapshot: a header with where it stands to date and the to date /
/// fiscal year switch, then its tiles (`shown`: to date, or for `year`,
@@ -730,7 +730,7 @@ pub struct PageFigures {
/// The by-month chart's span ([`chart_span`]) and figures, when
/// anything tagged is posted.
pub months: Option<((NaiveDate, NaiveDate), ledger_core::ProjectFigures)>,
/// The fiscal year to date (B-30's omitted dates, as `books.project`),
/// The fiscal year to date (BS-period-3's omitted dates, as `books.project`),
/// only when the snapshot shows it.
pub year: Option<ledger_core::ProjectFigures>,
}
+9 -9
View File
@@ -24,7 +24,7 @@ use std::collections::BTreeMap;
/// The range a report covers. The default (a report nobody chose dates
/// for) is the fiscal year to date: what an omitted date means
/// everywhere (rules.md B-30, `Books::default_period`; a test pins that
/// everywhere (BS-period-3, `Books::default_period`; a test pins that
/// they agree).
#[derive(Clone, Copy, Debug, PartialEq, Eq, Default)]
pub enum Range {
@@ -408,7 +408,7 @@ fn column_ranges(st: &State, b: &Books) -> Vec<(NaiveDate, NaiveDate, String)> {
/// The period compared against, if any: None too when it falls before
/// chrono's first day (a range from the books' first entry, which an
/// earlier version may have dated there: rules.md B-28).
/// earlier version may have dated there: BS-entry-4).
fn prior(st: &State, s: NaiveDate, e: NaiveDate) -> Option<(NaiveDate, NaiveDate)> {
match st.compare {
Compare::None => None,
@@ -1079,7 +1079,7 @@ fn tax(b: &Books, s: NaiveDate, e: NaiveDate) -> Table {
t
}
/// A report the books can't compute (rules.md B-28: books an earlier
/// A report the books can't compute (BS-entry-4: books an earlier
/// version wrote may hold amounts past exact arithmetic): no figures, and a
/// note saying why, never a guess.
fn cant_compute(mut t: Table, why: &ledger_core::LedgerError) -> Table {
@@ -1518,8 +1518,8 @@ fn report(ui: &mut Ui, b: &Books, kind: ReportKind, shell: &mut Shell<'_>, picke
let e = widgets::date_picker(ui, "to", e);
// The human's own pickers: a "from" set past the "to" reads
// as the two in order. Never a books.show target's dates:
// App::show takes only a resolved range in order (rules.md
// B-30) and ignores any other, so this never changes what the
// App::show takes only a resolved range in order (
// BS-period-3) and ignores any other, so this never changes what the
// agent was told the viewer shows.
st.range = Range::Custom(s.min(e), e.max(s));
}
@@ -1555,7 +1555,7 @@ fn report(ui: &mut Ui, b: &Books, kind: ReportKind, shell: &mut Shell<'_>, picke
let (s, e) = st.range.dates(b);
// A split over a range from the books' first entry, which an earlier
// version may have dated thousands of years back (rules.md B-28),
// version may have dated thousands of years back (BS-entry-4),
// would be more columns than anyone can read or the frame can build:
// shown as one total, with a note saying so.
let split_note = splittable
@@ -2282,8 +2282,8 @@ fn vendor_1099(ui: &mut Ui, b: &Books, year: i32, shell: &mut Shell<'_>) {
let w = match b.vendor_1099_worksheet(year) {
Ok(w) => w,
Err(e) => {
// Never guess a threshold or the cash accounts (rules.md
// B-19): say why there's no worksheet, in the engine's words.
// Never guess a threshold or the cash accounts (
// BS-1099-1): say why there's no worksheet, in the engine's words.
ui.label(RichText::new(e).color(p.muted));
return;
}
@@ -2719,7 +2719,7 @@ mod tests {
// The figures, by hand: the loan (not a financing setting) is an
// operating receipt, 2,500.00; what the members paid personally
// (85.00 and 216.40, 301.40) is borrowed from them through 2100
// and spent (D-42, rules.md B-14 rule 11); the members'
// and spent (D-42, BS-statement-3 rule 11); the members'
// contributions are financing, each named (1,200.00 and 800.00);
// the reimbursement repays 2100 (301.40); the tablet is disclosed
// (630.00), the reversed laptop gone.
+2 -2
View File
@@ -618,8 +618,8 @@ pub fn fit_font(
/// A date picker for `d` (`id` its egui id salt), returning the date
/// picked. The picker's calendar holds years -9999 through 9999; a date
/// outside them (books an earlier version wrote may hold one, rules.md
/// B-28) is shown as text and kept, never truncated into another year.
/// outside them (books an earlier version wrote may hold one,
/// BS-entry-4) is shown as text and kept, never truncated into another year.
pub fn date_picker(ui: &mut Ui, id: &str, d: chrono::NaiveDate) -> chrono::NaiveDate {
use chrono::Datelike;
let jiff_date = i16::try_from(d.year())