Status: done (2026-11-21) Priority: 2 Size: M Design ref: none (code structure). docs/architecture/target-v2.md sections 2 and 4.1; docs/cost.md (Rules for cost, 4) Goal: Eight modules each hand-roll a list sorted by due time: st.workDue and st.legDue (sim/agents, two near-identical binary searches, slotOf and legSlot), st.plans.due (sim/plans, a sort after each change), st.asking (sim/wishes), st.visits (sim/visits), st.offers (sim/offers), st.occasions (sim/occasions), st.obligationsDue (sim/obligations). One pure helper holds the search, the insert, the removal and the taking of what is due; each queue stays the state of its owner, in its saved shape. Acceptance criteria:
sim/due is a pure helper in the kernel layer (no state of its own, no domain import, no randomness): where an entry stands in a list sorted by a due key and a tie key, its insert, its removal, and the taking of the entries due by a time. It allocates nothing on the paths st.workDue and st.legDue use (the step’s hot path): no closure or array made per call.@state line and its saved shape: no change to src/owners.json writers, to src/sim/saves.js or to a save’s leaves. A queue whose order or cadence the helper cannot give without changing behaviour stays as it is, and the task file says which and why in a line.slotOf and legSlot of sim/agents are gone; no module is left with its own binary search over a due list.node tools/same.js --base REF prints same at the defaults and at --scenario founders --seeds 7 --map small --years 3; both lines are in the result. node tests/counters.js is unchanged.tests/suites.js; @sys, src/manifest.json, docs/architecture/modules.md name the module; npm run format and npm run verify pass; the lint and width baselines do not rise.
Notes / questions:while (q.length && q[0].due <= t)) of the per-entry loops, since a take would change which entries inserted during the loop are handled in it; the identity removals of offers, occasions, obligations (indexOf) and asking (findIndex by pawn), since an occasion’s due moves before it is taken out and asking’s ties are not ordered by pawn, so a search by key would not find them.