src/core/catering — what to write next¶
Two files that turn three JSON files into four questions. Pure Node — see ../README.md for the layering rule.
| File | Exports | Owner |
|---|---|---|
catering.ts |
MIN_OBSERVATIONS, LANE_LIMITS, TopicSignal, CateringPlan, roundHalfEven, rateOf, isConfident, hasEvidence, buildCatering, planSize, publishedPathsFromLedger |
WP07 |
worklist.ts |
LANE_EMPTY_STATES, formatThousands, formatPercent, renderWorklist, writeCateringWorklist |
WP07 |
The four lanes¶
buildCatering joins the content index (../contract), the publish ledger (../governance/ledger) and per-content engagement (loadPerformance), and answers:
| Lane | Question | Ranking |
|---|---|---|
| A — undistributed | What scores well and was never published off-site? | health desc, path asc; top 15 |
| B — proven | Which topics landed? | rate at or above the median; top 6 |
| C — quiet | Which topics consistently did not? | rate below the median; top 6 |
| D — refresh | What earned attention and has since gone stale? | index order; top 10 |
Lane A is the cheapest work on the list — no writing required. Lane C exists because the alternative is repeating those topics by default; low engagement is not the same as low value, and a compliance post can matter and still be unpopular.
Contracts worth knowing before you change anything¶
Nothing here reads per-reader data. Every ranking comes from the author's own aggregate counters. There is no field in PerfStats that identifies a person, which is why the whole module is a pure function of three files and has no IO of its own beyond the write in writeCateringWorklist.
The arithmetic is Python-compatible on purpose. roundHalfEven is Python's round() — JavaScript's Math.round rounds half up, which diverges on exactly the values a percentage table is full of. formatThousands and formatPercent are hand-rolled rather than toLocaleString, because a worklist that renders 1 234 after you fly to Berlin is not a contract.
The median is deliberately a pseudo-median. signals[len(signals) // 2] on a list sorted by rate descending: for an even-length list that is the lower-middle element, not the mean of the two middles. >= median goes to "proven", so a tie lands in the optimistic lane. It is upstream behaviour, pinned by the golden fixture. Do not "fix" it without regenerating the golden worklist from the Python lane.
Below MIN_OBSERVATIONS = 2 posts a topic has no signal, and with zero observations Lane B says so in words rather than showing an empty table. An empty lane and an un-evidenced lane are different states and read differently.
renderWorklist is byte-golden. src/test/golden.test.ts compares it against worklist.md, generated by the Python catering.render(). Same headings, same columns, same empty states, same prose — so a human opening .cms/distribution/worklists/ cannot tell which lane wrote which file, which is the entire point of having two lanes. If you need to change the wording, change it in the Python lane, regenerate the fixture, and copy it here. Never edit the fixture to match the code. The five empty-state sentences are LANE_EMPTY_STATES, exported so the dashboard host can ship the same strings to the screen instead of copying them; src/webview/dashboard/catering.ts keeps the one unavoidable mirror, because a browser bundle cannot reach a module that imports node:fs.
Health renders as an em dash when unscored. -1 is "the engine never scored this", not zero, and a worklist that printed 0 would rank an unscored page as the worst thing on the site.
Tests¶
src/test/core.test.ts pins roundHalfEven (0.5→0, 1.5→2, 2.5→2, 0.12345→0.1234), formatThousands and formatPercent. src/test/golden.test.ts builds a plan from worklist-inputs.json — 11 records and 7 performance rows chosen to exercise every lane boundary, including health exactly 70, health -1, a draft, a structural page and a stale-with-engagements page — and asserts the rendered markdown matches worklist.md byte for byte.