allowanceStatus: done (2026-11-08)
Priority: 1
Size: M
Arch: kin-help
Phase: implement
Design ref: Exchange, goodwill and obligations (The gift: the gift and Acceptance, Proposed; The floor, Allowance, Agreed 8 Nov); Goods, production and animals (Help in hunger); docs/architecture/target-v2.md, sections 4.1 (rules, commands), 4.5 (Exchange) and 5.1; VB-182’s plan.
Goal: Slice 1’s first step, with behaviour unchanged: help in hunger gives through Exchange’s first mechanism, the gift, behind a command verb, and a gift goes ahead only when it keeps the giver at or above its floor and within its allowance. The registry gets its second rule, allowance, with the two terms that reproduce today’s rule. Help keeps its own rules: whom it asks, in what order, and for how much.
Acceptance criteria:
floorOf(st, hh) in sim/hunger, the seed reserve and HELP.floorDays (20, a new tunable in src/sim/rules.js) days of dailyNeed.allowance (sim/registry), declared by sim/relations, combine: 'sum', clamped at 0 below, in rations, for a context {giver, receiver, from, to} (pawn ids or null, households or a village) that the caller reuses, so value allocates nothing:
slack (source sim/hunger): the giving household’s grain above its floor, 0 or more;reserve (source sim/help; a stand-in for generosity until traits, slice 7): minus the holder’s buffer beyond HELP.floorDays, times the household’s need; for a household without a holder, today’s HELP.bufferDays[1]; from −40 days of need to 0.
Ranges are bounds the registry’s explain checks, so give slack a finite bound above any store (say 1e7 rations) and say so in a comment.src/sim/exchange.js (VB['sim/exchange'], @sys line, after sim/hunger in src/manifest.json, under 400 lines), owning no state (target-v2: Exchange owns no goods and no balances), with the gift only:
assessGift(st, offer) for {from, to, good, n, source}: {floorOk, allowance, accept, why}; accept needs floorOk and n no larger than the allowance (with a tolerance of 1e-9, see the notes). A village store has no floor and no allowance: it gives what it holds. (Written first as assess, and as checking only the floor when one side has no agent; see the implementation notes.) Source player passes below the floor and is not bound by allowance (The player’s gift: Decided 3 Nov, Agreed 8 Nov); the warning that names who goes hungry is VB-221’s.settleGift(st, offer): gift’s moves and records as they are today, moved from help.js:29: the grain through sim/stores with the same reasons, the two holders’ gift events, the ties gain (HELP.tieGain, through strengthenTie), in today’s order of writes.give in src/sim/commands.js: actor the giving holder, or {household} for a household without one, or {village} for the store (as the meeting’s verbs name a settlement); target the receiving household, or {village} for the yearly filling; args {good, n}; refused with assessGift’s reason when not accepted. settleGift joins the acts in WRAPPED (tests/commands.js), called only by the verb; tests/commands.js checks a gift carried out and its refusals.sim/help issues give (source help) for kin gifts, the store’s gifts and the yearly filling, and keeps kinHouseholds, shareFood and fillStores as its own rules; surplus stays its name for what a household would spare (Refactor rules: no renames).tests/exchange.js in npm test: a gift within the allowance and above the floor settles, with an entry on each side and the ties raised; one that would take the giver below its floor is refused with a reason naming the floor, unless its source is player; one larger than the allowance is refused; explain(allowance) names slack and reserve, and its value equals today’s surplus within 1e-9 on every household of populous 7 (tiny map) at the end of year 1. tests/help.js passes unchanged.allowance value for each kin household asked, at most a few hundred a game day at medium-y60: under 0.05 ms a game day. Report node tools/sim.js --load on small-y40 with --years 1 --report perf before and after (the hunger and meals line).BACKLOG.md: tests/golden.json unchanged, npm run verify passes. Work counters: only ruleValue may change; record it with node tests/counters.js --update and list it in the PR. node tests/dependencies.js and node tools/writes.js show no new writer of food or ties outside sim/stores and sim/relations.sim/exchange reads stores, the floor and the registry, and writes only through sim/stores and sim/relations; sim/help now reaches the gift only through issue.
Notes:min(want, surplus) with surplus = grain - seedReserve - buffer * need (help.js:9); the allowance’s sum (grain - floor) + -(buffer - floorDays) * need can differ from it in the last bits. So help proposes today’s size, and assess checks it against the allowance within 1e-9, rather than help asking for the allowance; say in the implementation notes which way was taken, and that the golden file held.sim/stores’ callers. Slice 2’s tasks touch sim/commands too (VB-169); merge with care.bb1d45c (the floor, allowance with slack and reserve), bd7e86f (sim/exchange, the verb give, help through it),
8c619d9 (tests/exchange.js).src/sim/exchange.js (53 lines) owns no state. Its functions are assessGift and settleGift, not target-v2’s assess and
settle: sim/claims already defines a settle, and tests/commands.js finds the acts that only verbs may call by their bare names,
so settleGift is in WRAPPED and sim/commands destructures it.reserve term already covers a household without a holder (today’s 60 days), and checking
only its floor would let it give down to 20 days if asked for more. A village store has neither a floor nor an allowance. Help proposes
today’s size (min(want, surplus)) and assessGift checks it within 1e-9, so sizes are today’s to the last bit; on populous 7 (tiny)
after a year, the allowance equals surplus exactly on all 25 households.holdingOf), {household} for one without a holder (refused when it has one), or
{village} for the store; its target a household or {village}. Grain only; a positive, finite amount; not to oneself.allowance’s terms call dailyNeed and seedReserve, which allocate small arrays; the registry’s value itself allocates nothing.
It is read about twice a game day at small-y40, so this is not a hot path. If slice 4’s fair reads it in a loop, make those two
helpers non-allocating first.tests/registry.js finds death.hazard by its id, since allowance (declared in sim/relations, which loads earlier) is now listed
first; it also checks allowance’s two terms.npm run verify: 90 scripts passed in 218.5 s. node tests/golden.js: the golden state matches. node tests/counters.js passed, but not because the counters were unchanged: ruleValue rose by one read in the fixture’s 900
living pawn-days (0.1%: the yearly filling’s allowance check), inside the test’s 10% tolerance. Found and re-recorded by VB-217 (flagged
there); the other counters are unchanged. npm test: 77
scripts pass. node tests/dependencies.js passes; node tools/writes.js --field household.grain (and village.grain, pawn.ties)
lists only sim/stores and sim/relations, and seeding as before.small-y40 (tools/sim.js --load ... --years 1), at 210ba50 and after: the same yearly line (729 living, 26 births,
the same deaths, 196 hungry household-days, mean grain 178.1). --report perf gave hunger and meals 1.90 and 2.44 ms a game day, but
every system was about 15% slower in the second run (talk 38.9 and 45.2), so that is the machine. Measured directly instead: about 2
allowance reads a game day (--report counts: ruleValue 731 a day against 729 living, whose death.hazard is one each), and one
gift’s check costs 1.0 µs (200,000 assessGift calls on small-y40’s households): about 0.002 ms a game day, under the line of 0.05.