refreshJobs posts from themStatus: done (2026-11-09)
Priority: 2
Size: M
Arch: life
Phase: implement
Design ref: none (code structure). docs/architecture/target-v2.md, section 4.5 (Opportunities: “each kind’s record in KINDS gains available(st, holder); today’s posting rules in refreshJobs move there almost line for line”), principle 4; docs/roadmap.md, section 3.2 (the first step of the jobs rework); docs/review-life.md, section 3.
Goal: Today one loop in refreshJobs (src/sim/jobs.js:45-94) holds every rule for when a job is posted: hoe and sow in the sowing window, weed, reap, haul, reclaim, manure, firewood below the goal, threshing, water, cooking, mending, and the jobs of meadows, the byre, plots and claims through their modules. Slice 2 needs “what could be done here” for one pawn (VB-209) and slice 3 for every holder, so the rule must live with each kind. Move each kind’s posting rule into its KINDS record as available, and make refreshJobs a loop that asks the kinds, with behaviour unchanged.
Acceptance criteria:
refreshJobs has available(st, holder, at, c, post) in src/sim/kinds.js (or a shared one for the kinds a module posts together, meadowJobs, byreJobs, plotJobs, claimJobs, delegating to that module’s function). Here at is the field, meadow or farm it is asked about. It calls post(key, site, extra) for each job it would post, so no array is made per call. Its comment states the rule in words.refreshJobs keeps today’s order: farms in order, then for each farm its fields, its meadows and the farm itself, asking at each the kinds of that scope in today’s order; then village fences, plots and claims. Job ids, and so matching, are unchanged.available: startProject and startMeadow (a household looks for land at the start of work) are called where they are today, and named in a comment as slice 3’s hidden plans (VB-164).BACKLOG.md: tests/golden.json and the work counters unchanged; npm run verify passes; the PR says what fell (the lines of refreshJobs, and the rule for each kind now in one place beside its record).node tools/sim.js --load tests/fixtures/medium-y5.gz --years 1 --report perf and the same on small-y40, before and after on one machine (on 7 November, 30 days: 33.5 ms a game day at medium-y5, 22.8 at small-y40; stale fixtures). sim/kinds stays under 400 lines; if it would not, the field kinds’ rules go into a module of their own listed before it.
Notes:sim/jobs, so they run one after the other.available reads the household’s stores and the field’s or meadow’s stage as the loop does today; LandRights.may and typed goods arrive with slices 3 and 5. Keep the signature open to a holder that is a village (fences, plots) as well as a household.jobs.js:22), matching visits jobs by id (jobs.js:126, 181), and two new jobs on different fields can appear in the same hour (reaping one field and hauling another), so asking kind by kind across all fields would renumber them.sim/kinds: each kind posted from refreshJobs has available(st, holder, at, c, post, f) in its record, with its rule in words above it.
holder is the household (or the village), at the field, farm or village asked about, and f the household’s farm. The sixth
argument is needed because a field does not know its farm, and a field job’s key and extra name the farm. The rule calls
post(key, site, extra) once for each job it would post. A rule shared by several kinds names each job’s kind (post(key, site, extra,
kind)). A job that the farm’s household does not own also names its owner (..., kind, owner).
f.fence) and at a village (v.fence, with the farm argument left out).meadowWork (rake, mow and hay; meadowJobs and hayWanted),
byreWork (fodder, slaughter, salt and milk; byreJobs), plotWork (fell, grub and a plot’s steps and cottage stages; plotJobs),
claimWork (restore; claimJobs), landProject (clear, break and meadow; the farm’s land project) and boothWork (the cottage
stages; boothJob).plotWork).RECLAIM and cookWanted moved beside their kinds. callCooks in sim/jobs now imports cookWanted.ASK in sim/kinds lists [kind, rule] entries in today’s order, for each place the rules are asked: field, farm (meadows, manure,
byre), farmAfterPlans (land project, booth, wood, thresh, water, cook, mend), village (mend), and island (plots, then claims).
refreshJobs asks each list in turn, through one post closure and one ask closure made per call. The default owner is the farm’s
household, shared by the farm’s jobs as before. A village’s or plot’s job gets a new owner object for each job, as before, so the
saves’ shared references do not change.stages: the field stages at which each can be available. ASK.fieldAt gives a stage’s rules in the order of
ASK.field, and refreshJobs asks only those at each field. Without this index, refreshJobs alone was about 30% slower than the inline
loop (six indirect calls a field an hour; see Cost below). No two field kinds share a stage, so at most one field rule is asked at a
field. Reclaim is listed at two stages. The posting order is unchanged. The rules still check the stage themselves, so a caller can ask a
single kind (VB-209).startProject and startMeadow are choices, not availabilities. They stay in refreshJobs, between the farm’s two lists, where
they were. A comment names them as slice 3’s hidden plans (VB-164).refreshJobs went from 50 lines (jobs.js:45-94) to 28, including its comments. Its 43 lines of posting, over farms, villages,
plots and claims, became an 11-line loop over the farms and two lines for the villages and the island. It holds no posting rule. Each rule is now one place, in its
kind’s record. sim/jobs went from 224 to 197 lines and no longer imports from sim/hunger, sim/byre or sim/expansion.
sim/kinds went from 199 to 313 lines, under the 400 limit, so the field kinds keep their rules in it.tests/golden.json matches and tests/counters.json is unchanged (node tests/golden.js, node tests/counters.js).small-y40 (33.0 MB, year 41).refreshJobs alone, on the loaded fixture: every hour of four days, one in each season, 60 times over; 7 pairs each.
node tools/sim.js --load tests/fixtures/<fixture>.gz --years 1 --report perf, 4 pairs each, in ms a
game day. Both are within noise; the run-to-run spread, about 50%, is far wider than the 5% bar.
npm test and npm run verify pass.