VB.count, asserted at tiny scaleStatus: done
Priority: 1
Size: S
Arch: yardstick
Phase: implement
Design ref: none (measurement). docs/roadmap.md, section 6 (work counters; how counters stay out of the state); AGENTS.md, Rules for cost, rule 10 (Decided, Kim, 3 November).
Goal: Timing is noisy and needs long runs. A count of the work a loop does is exact, needs no reference machine and never flakes. Count the work of the loops that grow with history or with pairs, outside st, and assert the counts at tiny scale in npm test, so a change that makes a loop do more work fails when it lands, not when the late game freezes. Every later check of slice 0 reads these counters.
Acceptance criteria:
src/vb.js creates VB.count, a plain object of numbers outside st, and VB.COUNTERS, the declared names with one line of meaning each; VB.resetCounts() sets them to 0. Counters are never saved and never read by the simulation (rule 10).routeSearch (A* searches, findRoute), routeExpand (tiles taken off its heap), routeHit (routes served from st.pathCache), routeRefresh (cached routes refreshRoutes tests);talkWeighed (partners weighed in talkHour), contactPairs (pairs compared in noteContacts);walkStep (agents the 6-minute step walks, advance in sim/clock), walkDaily (pawn records walked by dailyLife’s loops and by Culture.dailyStep), walkTies (ties decayed in dailyLife);roundPairs (pairs of a man and a woman the moving round weighs), heirRank (every heirRanking call, including nested and indirect callers); tests derive roundRank as its delta across movingRound.tests/lint.js): in the modules, VB.count appears only as VB.count.<name> += <expr> or VB.count.<name>++ with a declared name. Anything else fails with its line: a read, a branch on a counter, an undeclared name. This is the one allowance for state outside st, and tests/lintrules.js plants a read and sees it fail.tests/counters.js in npm test, under 3 s: a tiny world (tests/lib/tiny.js) of two villages for 30 game days, then one moving round. Each counter per living pawn-day is checked against tests/counters.json and fails outside ±10% of the recorded value. --update re-records it: a change that moves a counter on purpose re-records it and lists the counters in its PR, as for the golden file (add the rule to BACKLOG.md’s golden rule).tests/perf.js --counter-cost reports deterministic tally/addition work and a conditional estimate at an assumed 5 ns per addition; timing noise does not establish a measured 2% bound.tools/sim.js --report counts prints each counter per game day and per living pawn-day for the run (and with --json).tests/golden.json unchanged: counting changes nothing in st.AGENTS.md: a line in Commands for tests/counters.js and --report counts; a line in Conventions that a new loop over a growing collection, or over pairs, adds a counter.ready if VB-193 is done too.
Cost: one local addition per counted inner-loop pass, plus one counter publication per call; 3 s in npm test, in parallel with the other scripts.
Notes:ruleValue comes with the rules registry (VB-197).Implementation notes (4 November 2026, revised after PR #51 review):
heirRank increments unconditionally inside heirRanking, covering countDemand, nested rankings and marriage/handovers; the optional diagnostic work object and parameter changes are removed. Tests derive roundRank as the difference across the round (42 calls on the original fixture, formerly 22).VB or globalThis.VB. Its error explains the requirement for braces around conditional increments.tests/counters.json covers all 11 counters plus derived roundRank over two tiny villages, 30 days and one round (900 living pawn-days). A second 42-pawn fixture compares 40 candidate pairs, covering more than the main fixture’s four pairs. Tests also cover direct, nested and countDemand ranking paths.--report counts share tools/counts.js lifetime integration, including births, partial days, deaths at zero and intervals resumed from a save. The test checks these boundaries explicitly. The CLI resets after seeding/loading; zero-duration rates are zero.routeSearch now increments only after the same-tile early return. Baseline changes: new heirRank, corrected roundRank (22 to 42 calls); shared lifetime integration introduces only floating-point rounding differences in the other normalized entries. No simulation behavior changes; tests/golden.json stays unchanged.tests/perf.js --counter-cost instead reports deterministic local tally work plus a conservative bound on per-call publications. Any conversion to milliseconds is conditional on the explicit 5 ns/addition assumption, not a timing guarantee.