Status: done (2026-11-11)
Priority: 3
Size: S
Design ref: none (code structure). docs/architecture/target-v2.md, section 4.1 (the rules registry).
Goal: The registry’s list of contributions is how upward influence is listed (target-v2 3.2), but source is a label no one checks: the hunger and frailty terms of death.hazard are registered in sim/deaths with source: 'sim/hunger', and allowance’s goodwill term in sim/exchange with source: 'sim/relations'. They cannot move home today, because contribute needs the rule declared first and sim/hunger loads before sim/deaths.
Acceptance criteria:
contribute accepts a contribution to a rule not yet declared; seal fails if any rule is still missing. A rule’s spec may name its contributions’ order (order: [keys]); without it they combine in the order registered. Both rules keep today’s order, so floating-point results and the golden file hold.npm test holds each contribution’s source to the module whose file registers it. The hunger and frailty terms move to sim/hunger; the goodwill term moves to sim/relations, or its source becomes sim/exchange: say which and why.product rule’s contributions declare tight ranges, checked as today in explain; a sum rule’s range is optional, and allowance’s three bounds of ±1e9 go (ALLOWANCE_BOUND, and sim/hunger’s import of sim/relations for it).value still allocates nothing (tests/registry.js); node tests/perf.js --counter-cost unchanged within noise.BACKLOG.md: behaviour unchanged, tests/golden.json and tests/counters.json unchanged, npm run verify’s hard checks pass, its targets reported with their residuals.
Notes:value (a cycle between rules failing at seal) is taken out of this task: no rule reads another, and it returns with the first rule that would. The first criterion stays whole, though the review proposed cutting the declared order too: sim/hunger loads before sim/deaths, so moving the hunger and frailty terms to their source (the second criterion) needs a contribution to a rule not yet declared, and the order named to keep the golden file. The flag as it was raised: the registry is 79 lines for 2 rules, 5 contributions and 2 read sites, and this task adds four features to it. The source lint and the tighter ranges answer what exists today. A declared order and the rejection of cycles between rules serve rules that are not written yet (no rule reads another); they could wait for the third or fourth rule, which would make this task smaller.sim/registry.js and sim/deaths.js); either order works.contribute to an undeclared rule waits in a map and attaches when the rule is declared; seal fails naming rules never declared. A spec’s order: [keys] sorts the contributions at seal and must name each exactly once. death.hazard (['hunger', 'frailty']) and allowance (['slack', 'goodwill', 'reserve']) declare theirs, equal to the load order they had, so the floating-point sums are unchanged.tests/lint.js): a line that contributes names a source equal to its own module. The hunger and frailty terms now live in sim/hunger.source became sim/exchange (the term stays in sim/exchange). Its limit needs the household’s dailyNeed (sim/hunger), and sim/relations loads before sim/hunger, so moving it home would be an upward lookup; sim/exchange already owns the allowance’s deals.explain checks one only when given), required on a product rule’s (checked when the rule is declared or the term attaches). ALLOWANCE_BOUND is gone with its three ranges, and the need terms’ [-1e9, 1e9] too. allowance’s clamp is [0, Infinity] (a clamp may be open on one side).ALLOWANCE_BOUND and its imports in sim/hunger, sim/help, sim/exchange; one wrong source label x2 and one x1 corrected; 5 invented bounds; deaths no longer imports HUNGER/HEALTH. Upward calls by layer: 25 to 24 (sim/hunger’s lookup of sim/relations), baseline lowered by 1. The registry grew by about 25 lines.
npm test whole, node tests/golden.js, node tests/counters.js unchanged. New cases in tests/registry.js (early contribution, order, seal failure, open ranges).
sim/exchange rather than moving to sim/relations, for the load-order reason above.Infinity rather than a large constant.