Status: done (2026-11-18)
Priority: 2
Size: M
Arch: debt
Phase: implement
Design ref: Exchange, Loans, obligations and cases (Obligations); Inheritance, Handover and shares (Shares still owed); docs/architecture/target-v2.md, section 4.4 (Obligations)
Goal: Slice 5’s loans, rents, labour owed and wages are obligations. Today the one kind there is, a sibling’s share still owed, lives on the pawn (pawn.owed, pawn.owedFrom) and is paid by a loop over pawns at the moving round (src/sim/cottage.js). Give every explicit claim one owner, sim/obligations, with a due-queue, and move the shares into it without changing behaviour, so the loans that follow add a kind, not a module.
Acceptance criteria:
sim/obligations (VB-012 convention, @sys and @state lines, under 400 lines, in src/owners.json as the owner of what it writes; remove the planned name if plannedOwners holds it) keeps st.obligations (array by id, ids never reused) of {id, kind, debtor, creditor, owes, due, every?, enforcer, status, delivered, since}, with debtor and creditor as plain party refs ({kind: 'household' | 'village' | 'pawn', id}), owes as rations or work hours, and status one of open, part, met, overdue, defaulted, forgiven, lapsed.st.obligationsDue sorted by hour then id; a step touches only what is due (rule 4); met, forgiven and lapsed ones leave both and are told once in the record (rule 1). Both are caches with one writer, rebuilt and compared in a test.create, fulfil (part or whole, with a reason, goods through sim/stores), forgive, transfer (to a successor) and due(st, party); no other module writes the records.share (debtor: the farm’s household; creditor: the sibling as a pawn), paid at the moving round from grain above the reserve in the same order as today (by the sibling’s id), with the same events; pawn.owed and pawn.owedFrom go, and every reader (cottage’s start in life, the panels, the tools) reads due instead.WORLD in src/sim/saves.js), plain data (tests/plaindata.js), invariants (checkState: every live obligation’s parties exist, delivered at most owed, the due-queue holds exactly the open ones), a counter for the due step in VB.COUNTERS.BACKLOG.md): node tools/same.js --base REF prints same, counters unchanged but the new one, npm run verify passes; the PR says what fell (the pawn fields, the loop over the living at the round). (Unticked: it prints differing leaves, since the state fields moved, and one record line was added on purpose, the lapse of a dead sibling’s share; the leaves are named in the notes, and no others differ. Counters and verify hold.)
Cost: open shares at medium-ref are counted in the PR (tens expected); the round’s loop over the living (payOwed, st.living) becomes a walk over the open shares; the due-queue step is a comparison a step when nothing is due.
Order: first in slice 5, beside VB-311 and VB-313 (different files). VB-312 (loans) and VB-319 (wages) add kinds to it.
Notes:payOwed (src/sim/cottage.js) walks st.living, not every pawn: the cost and what fell say so.QUESTIONS.md, VB-184, question 7) and does not change this task.finishCottage verb into src/sim/cottage.js.src/sim/obligations.js (236 lines, layer social, after sim/stores in the manifest) owns st.obligations and two caches, the due-queue st.obligationsDue and the parties’ live ones st.obligationsBy ({debtor, creditor}, a party’s key to its sorted ids); all three absent until the first obligation, as st.trusts is. Operations: create, due(st, party, as, kind), owed, fulfil (one id or several of one debtor and creditor, the oldest first; goods in one movement through Stores.move, or booked only when they came another way, as animals led by sim/herds), forgive, lapse, transfer, step, and rebuilt (the caches from the records, for the test and the invariants). A kind is a row of KINDS (its term). The shares: oweShare (called by sim/heirs), shareOwed (the page, through Sim.shareOwed), openShares (the round’s walk, payOwed in sim/cottage). An old save’s pawn.owed becomes an obligation at load (sim/saves), and the two fields are deleted.pawn.owed and pawn.owedFrom (two pawn fields with no owner, written by sim/heirs and sim/cottage, read by the page); the round’s loop over st.living in payOwed, now a walk over the siblings with an open share. What grew: one module, 236 lines, and a step row of the clock that is one comparison when nothing is due.payOwed pays every open share whenever a round is held). Paying from the queue’s step would move the payment out of its place in the round (after service, before prestige) and stop the debug round from paying. The step only moves a share to its next term; overdue is for kinds with one term (VB-315).oweShare keeps pawn.owedFrom’s quirk: when a second farm comes to owe a sibling, what the first still owes passes to it; and a share whose debtor household dissolved stays open, unpaid. VB-1155 mends both (a change to behaviour, with numbers).WORLD in src/sim/saves.js lists tile fields; st.obligations is state, saved by the codec like every st field, so nothing was added there. An obligation is a claim, not a stored quantity: no line in tools/stocks.js.lapse is an operation beside the four named, since lapsed is a status and nothing else reaches it.tests/obligations.js (new, in the fast tier): the record, the queue’s order, part and whole, overdue, the next term, transfer, forgive and lapse told once, the caches rebuilt and compared after each, the shares at the round (by the sibling’s id, the oldest share first, the same event text), save and load, an old save, the dead sibling’s lapse. checkState holds the invariants. npm run verify: 188/188 passed, 11 targets out (advisory; not compared with the base). node tests/smoke.js passes. Counters: obligationsDue added at 0 in tests/counters.json; no other line touched.node tools/same.js --base 1e13cb9 does not print same, and cannot: the state’s fields moved (Refactor rules, renames). The leaves that differ, and no others:
pawns[20].owed, pawns[21].owed, pawns[21].owedFrom (and cenv.people, the same pawns) and the new obligations, obligationsBy, obligationsDue. Its one share of 211 rations is paid 6 in year 1 and 205 in year 2 in both trees.pawns[].events, recordFold, recordYears). At year 6 there: 16 obligations, 8 met, 1 lapsed, 6 open, 1 part. No other key differs in any year.obligationsDue counter at medium-ref (the Cost line): tests/fixtures was not on the machine. VB-1156, for the collecting task VB-662.