sim/stores, every movement recordedStatus: done
Priority: 2
Size: M
Arch: ownership
Phase: implement
Design ref: none (code structure). VB-172’s map, docs/architecture/ownership.md, sections 5.3, 5.7 and 7.1; Kim’s answers of 3 November (QUESTION_ARCHIVE.md, “VB-172: the ownership map”, questions 1 to 3 and 7).
Goal: Household and village food has ten writer modules and no owner, and only harvests, gifts, meat, milk and butter leave a record. Give it one owner, a new module sim/stores, through which every other module changes food, and record every movement in the ledger, so a household’s balance can be read from it (VB-092, tools/balance.js). Kim chose to record everything in this task (answer 3), so it changes behaviour on purpose: the golden file is re-recorded, and only the ledgers may change in it.
Acceptance criteria:
src/sim/stores.js (VB['sim/stores'], an @sys header, under 400 lines), listed in src/manifest.json after sim/records and before sim/hunger. It owns household.grain, rations, unthreshed, ledger and spoilt; village.grain; and paid pawn.stake; owed shares and their debtor remain obligations in heirs/cottage (later target-v2 decision below).put(st, holder, good, n, why), take(st, holder, good, n, why) (returns what it took, never more than is held), move(st, from, to, good, n, why) (what one loses the other gains), cook(st, hh, n), sheaf(st, hh, n), thresh(st, hh). A holder is a household, a village or a pawn. A negative or non-finite amount, or a dissolved household, throws: it is a bug in the caller.sim/hunger), gifts and the village store (sim/help), the kinds’ sow, cook, haul and thresh (sim/kinds), shares and handing on (sim/heirs), owed shares (sim/cottage), provisions (sim/farmclaims, sim/settle), grain spoiling (spoilGrain), and the village store’s spoilage (clock.js:62, which moves out of the clock; Kim’s answer 7). Pruning the ledger to three years (clock.js:107) moves too.node tools/writes.js --field <f> lists only sim/stores for each owned field, apart from seeding (sim/scenarios) and the save codec.{t, kind, n, ...} on each side: the kinds already there (harvest, gift, meat, milk, butter) unchanged, and new ones for seed, meal, cooking, spoilage, share (with the pawn), handing on and provisions. The village store gets a ledger of its own (village.ledger, pruned like a household’s); a pawn’s stake and owed share are entries in its household’s ledger naming the pawn.tests/stores.js, in npm test): for founders 7 and populous 7 (tiny map) over 3 years, each household’s change in grain, rations and sheaves over a year equals the sum of its ledger entries for that year, within 1e-6 per entry; the same for each village store.tests/lib/invariants.js): every ledger entry has a known kind, a finite n and a time no later than st.t; village.ledger exists. @state lines updated.households and villages keys change, and node tests/golden.js --dump shows only ledger lines differing. tools/sim.js (founders 7 small, 10 years; populous 7 small, 8 years) prints the same yearly lines before and after. tools/balance.js gives the same numbers.npm run verify passes.
Notes:clock.js:60) and the other stores (larder, hay, wood, stone, manure) are the next boundary (the map, 7.6); they wait for a task that touches them (Kim’s answer 1).QUESTIONS.md, is still open).sim/stores a good argument (grain, rations and sheaves for now), so typed goods (section 4.3) extend it without new operations; and leave pawn.owed and owedFrom out of sim/stores: they are the first obligations (section 4.4). This task is on the path of every slice (docs/roadmap.md, section 7).Implementation report (6 November 2026):
docs/review-vb174.md.npm test passes all 71 scripts; npm run verify passes
all 84 scripts in 284.4 s using system Chromium and software-render fixture
mode (previous recorded verify: 83 scripts, 241.7 s). All four late saves,
five long invariant runs, saved continuation, golden states, browsers and
15 history counters pass. Build freshness and diff whitespace checks pass.