clearotron 0.5.1 → 0.6.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (390) hide show
  1. package/.env.example +7 -7
  2. package/INSTALL.md +10 -10
  3. package/QUICKSTART.md +6 -6
  4. package/README.md +2 -2
  5. package/THIRD-PARTY-NOTICES.md +4 -4
  6. package/bin/README.md +2 -2
  7. package/bin/clearotron.mjs +1 -1
  8. package/bin/connect.mjs +1 -1
  9. package/bin/disconnect.mjs +1 -1
  10. package/bin/example.mjs +2 -2
  11. package/bin/grant.mjs +1 -1
  12. package/bin/onboard.mjs +78 -23
  13. package/bin/start.mjs +88 -33
  14. package/bin/update.mjs +13 -3
  15. package/build-info.json +2 -2
  16. package/docs/DELIVERY.md +1 -1
  17. package/docs/PORTAL.md +1 -1
  18. package/docs/RELEASES.md +1 -1
  19. package/docs/architecture/02-architecture.md +10 -2
  20. package/docs/architecture/03-run-lifecycle.md +6 -2
  21. package/docs/architecture/04-configuration-reference.md +3 -3
  22. package/docs/architecture/05-config-governance.md +5 -4
  23. package/docs/architecture/08-development-guide.md +4 -4
  24. package/docs/architecture/09-security-and-data.md +1 -1
  25. package/{driver/skills/clearance-search/SKILL.md → docs/architecture/retired-manuals/clearance-search-spine.md} +17 -30
  26. package/{driver/skills/clearance-search/templates/email/generic.md → docs/architecture/retired-manuals/email-generic.md} +1 -1
  27. package/{driver/skills/clearance-search → docs/architecture/retired-manuals}/template-formatting.md +3 -4
  28. package/docs/configuration.md +1 -1
  29. package/docs/decisions/0002-no-dark-functionality.md +5 -0
  30. package/driver/CHANGELOG.md +69 -0
  31. package/driver/README.md +11 -1
  32. package/driver/accepted-order.mjs +13 -5
  33. package/driver/attempt-rows.mjs +64 -0
  34. package/driver/attributed-span.mjs +1 -1
  35. package/driver/authority-trees.mjs +1 -1
  36. package/driver/band-shape.mjs +21 -3
  37. package/driver/best-draft.mjs +3 -3
  38. package/driver/blind-frame-record.mjs +2 -2
  39. package/driver/cancel.mjs +3 -2
  40. package/driver/carry-through.mjs +2 -2
  41. package/driver/citation-census.json +3 -3
  42. package/driver/clearance-variants-record.mjs +4 -10
  43. package/driver/common-law-coverage-status.mjs +3 -3
  44. package/driver/common-law-receipts.mjs +2 -2
  45. package/driver/commonlaw-carry-floor.json +3 -3
  46. package/driver/compare.mjs +1 -1
  47. package/driver/config-inventory.mjs +6 -79
  48. package/driver/consumption-ledger.mjs +2 -1
  49. package/driver/contract-arm2-baseline.json +2 -3
  50. package/driver/contract-dictation-registry.mjs +5 -0
  51. package/driver/contract-e3-backlog.mjs +45 -66
  52. package/driver/contract-e3-baseline.json +16 -16
  53. package/driver/contract-vocabulary.mjs +8 -6
  54. package/driver/corrections-feedforward.mjs +3 -1
  55. package/driver/coverage-form-io.mjs +7 -8
  56. package/driver/coverage-tool.mjs +1 -1
  57. package/driver/declination-tool.mjs +2 -2
  58. package/driver/degraded-parts.mjs +9 -9
  59. package/driver/demo-container.mjs +5 -4
  60. package/driver/demo-posture.mjs +17 -0
  61. package/driver/deploy-live-run-guard.mjs +19 -7
  62. package/driver/derived-state.mjs +2 -2
  63. package/driver/dev-portal.mjs +2 -1
  64. package/driver/dispatch-record.mjs +1 -1
  65. package/driver/disposition-tool.mjs +2 -1
  66. package/driver/doubt-closure-tool.mjs +2 -2
  67. package/driver/driver.config.mjs +35 -724
  68. package/driver/e2e-rounds.mjs +3 -4
  69. package/driver/engine/CONTRACT.md +3 -0
  70. package/driver/engine/README.md +2 -0
  71. package/driver/engine/anthropic-agent.mjs +13 -42
  72. package/driver/engine/auth.mjs +74 -0
  73. package/driver/engine/child-record.mjs +1 -1
  74. package/driver/engine/deny-authority-write.mjs +2 -2
  75. package/driver/engine/jx-turn.mjs +10 -2
  76. package/driver/engine/mcp/README.md +1 -1
  77. package/driver/engine/mcp/band-server.mjs +20 -13
  78. package/driver/engine/mcp/codex-config.mjs +1 -1
  79. package/driver/engine/mcp/declination-server.mjs +2 -3
  80. package/driver/engine/mcp/dispositions-server.mjs +3 -3
  81. package/driver/engine/mcp/gather-config.mjs +24 -19
  82. package/driver/engine/mcp/grid-provenance.mjs +1 -1
  83. package/driver/engine/mcp/held-answers.mjs +5 -5
  84. package/driver/engine/mcp/perplexity-server.mjs +16 -7
  85. package/driver/engine/mcp/recording-server.mjs +7 -6
  86. package/driver/engine/mcp/register-server.mjs +29 -0
  87. package/driver/engine/mcp/stdio-server.mjs +5 -5
  88. package/driver/engine/mcp/supplemental.mjs +9 -9
  89. package/driver/engine/openai-agent.mjs +5 -2
  90. package/driver/engine/registry.mjs +103 -0
  91. package/driver/engine/run-choices.mjs +162 -0
  92. package/driver/engine/stamps.mjs +35 -0
  93. package/driver/enqueue-schema.mjs +4 -4
  94. package/driver/envelope-settle.mjs +3 -2
  95. package/driver/feedback-issues.mjs +1 -1
  96. package/driver/feedback-mint.mjs +3 -2
  97. package/driver/feedback-store.mjs +3 -2
  98. package/driver/findings-model.mjs +1 -1
  99. package/driver/flag-snapshot.mjs +5 -4
  100. package/driver/floor-duty.mjs +3 -3
  101. package/driver/foreign-record-links.mjs +1 -1
  102. package/driver/frame-diff-record.mjs +2 -8
  103. package/driver/framework.mjs +1 -1
  104. package/driver/gate-metrics.mjs +10 -11
  105. package/driver/gateway.mjs +220 -839
  106. package/driver/goods-evidence.mjs +26 -14
  107. package/driver/jx-lanes.mjs +3 -3
  108. package/driver/jx-units.mjs +31 -37
  109. package/driver/jx.mjs +44 -59
  110. package/driver/knockout-assess-record.mjs +3 -3
  111. package/driver/knockout-caveats.mjs +21 -0
  112. package/driver/knockout-correction-record.mjs +58 -28
  113. package/driver/knockout-frame-record.mjs +2 -2
  114. package/driver/knockout-register-read.mjs +38 -21
  115. package/driver/knockout-register-record.mjs +5 -6
  116. package/driver/knockout-review-record.mjs +12 -11
  117. package/driver/ladder/model-gauge.mjs +88 -0
  118. package/driver/ladder/next-rung.mjs +296 -0
  119. package/driver/ladder/rescue.mjs +146 -0
  120. package/driver/ladder/stage-tools.mjs +57 -0
  121. package/driver/ladder/turn-failure.mjs +166 -0
  122. package/driver/log.mjs +2 -2
  123. package/driver/matter-frame-record.mjs +4 -4
  124. package/driver/methodology-witness.mjs +2 -2
  125. package/driver/named-band.mjs +60 -3
  126. package/driver/narrative-refutation-record.mjs +145 -42
  127. package/driver/one-build-per-run.mjs +62 -0
  128. package/driver/outbox-backoff.mjs +4 -4
  129. package/driver/owner-screen.mjs +0 -10
  130. package/driver/owner-use-check.mjs +2 -28
  131. package/driver/package.json +1 -1
  132. package/driver/partial-payload-baseline.json +1 -1
  133. package/driver/parts-not-completed.mjs +1 -1
  134. package/driver/pipeline-knockout.mjs +1015 -1001
  135. package/driver/pipeline.mjs +714 -9351
  136. package/driver/placement-decisions.mjs +2 -2
  137. package/driver/placement-form-io.mjs +7 -9
  138. package/driver/placement-union.mjs +0 -6
  139. package/driver/plan-stability.mjs +7 -10
  140. package/driver/portal-acks.mjs +3 -2
  141. package/driver/portal-confirmation.mjs +48 -0
  142. package/driver/portal-families.mjs +3 -2
  143. package/driver/portal-local-auth.mjs +1 -2
  144. package/driver/portal-routes/README.md +24 -0
  145. package/driver/portal-routes/admin.mjs +425 -0
  146. package/driver/portal-routes/compose.mjs +66 -0
  147. package/driver/portal-routes/config.mjs +118 -0
  148. package/driver/portal-routes/connect.mjs +283 -0
  149. package/driver/portal-routes/feedback.mjs +178 -0
  150. package/driver/portal-routes/me.mjs +165 -0
  151. package/driver/portal-routes/queue.mjs +64 -0
  152. package/driver/portal-routes/report.mjs +106 -0
  153. package/driver/portal-routes/run.mjs +508 -0
  154. package/driver/portal-routes/runs.mjs +127 -0
  155. package/driver/portal-routes/usage.mjs +82 -0
  156. package/driver/portal-runs.mjs +588 -0
  157. package/driver/portal-service.mjs +82 -2593
  158. package/driver/portal-static.mjs +3 -1
  159. package/driver/predelivery-lint.mjs +101 -9
  160. package/driver/production-pool-guard.mjs +1 -1
  161. package/driver/profiles.mjs +5 -4
  162. package/driver/progress.mjs +29 -24
  163. package/driver/publish/README.md +10 -5
  164. package/driver/publish/archive-tags.mjs +3 -2
  165. package/driver/publish/demo-marking.mjs +2 -2
  166. package/driver/publish/index.mjs +215 -140
  167. package/driver/publish/knockout.mjs +153 -107
  168. package/driver/publish/office-record-links.mjs +22 -0
  169. package/driver/publish/parse.mjs +20 -5
  170. package/driver/publish/pool-admin.mjs +9 -3
  171. package/driver/publish/render.mjs +11 -3
  172. package/driver/publish/report-dates.mjs +3 -4
  173. package/driver/publish/report-registry.mjs +7 -10
  174. package/driver/publish/seed-pool.mjs +3 -2
  175. package/driver/publish/shell.mjs +106 -0
  176. package/driver/publish/templates/report.css +9 -7
  177. package/driver/queue-order.mjs +4 -3
  178. package/driver/record-carry.mjs +0 -9
  179. package/driver/record-discard.mjs +1 -4
  180. package/driver/record-fold.mjs +3 -3
  181. package/driver/record-goods.mjs +79 -23
  182. package/driver/reference-score.mjs +2 -3
  183. package/driver/register-capabilities.mjs +0 -6
  184. package/driver/register-count.mjs +3 -2
  185. package/driver/register-digest-record.mjs +7 -7
  186. package/driver/register-fixture-marker.mjs +3 -3
  187. package/driver/register-plan.mjs +2 -2
  188. package/driver/register-records.mjs +2 -2
  189. package/driver/register-taint.mjs +3 -3
  190. package/driver/register-unit-record.mjs +48 -9
  191. package/driver/register-unreachable.mjs +4 -3
  192. package/driver/registry-fidelity.mjs +79 -34
  193. package/driver/repair-composers.mjs +14 -9
  194. package/driver/repair-digest.mjs +4 -6
  195. package/driver/repair-scope.mjs +3 -3
  196. package/driver/repair-targets.mjs +24 -9
  197. package/driver/repairs.mjs +44 -58
  198. package/driver/replay-archive.mjs +7 -7
  199. package/driver/report-card-record.mjs +3 -3
  200. package/driver/report-overview-record.mjs +4 -4
  201. package/driver/research-answers.mjs +38 -6
  202. package/driver/research-checks.mjs +4 -4
  203. package/driver/result-noun-fields.mjs +28 -11
  204. package/driver/review-addresses.mjs +163 -0
  205. package/driver/rule-shape.mjs +1 -1
  206. package/driver/run-delivered.mjs +340 -0
  207. package/driver/run-economics.mjs +8 -26
  208. package/driver/run-failed.mjs +545 -0
  209. package/driver/run-integrity.mjs +1 -1
  210. package/driver/run-outcome.mjs +314 -0
  211. package/driver/run-park.mjs +23 -0
  212. package/driver/run-quote.mjs +32 -0
  213. package/driver/run-record.mjs +352 -0
  214. package/driver/run-requirements.mjs +22 -0
  215. package/driver/run-shell.mjs +55 -0
  216. package/driver/runner.mjs +71 -33
  217. package/driver/saved-register-pages.mjs +4 -4
  218. package/driver/score-redaction.mjs +2 -2
  219. package/driver/search-policy.mjs +12 -13
  220. package/driver/settle-stamp.mjs +4 -3
  221. package/driver/skeptic-record.mjs +2 -2
  222. package/driver/skeptic-search.mjs +1 -1
  223. package/driver/skills/README.md +7 -7
  224. package/driver/skills/blind-frame/SKILL.md +1 -2
  225. package/driver/skills/case-law-citation/SKILL.md +9 -37
  226. package/driver/skills/case-law-citation/sources/courtlistener.md +1 -3
  227. package/driver/skills/case-law-citation/sources/eurlex.md +8 -11
  228. package/driver/skills/case-law-citation/sources/legaldatahunter.md +1 -1
  229. package/driver/skills/clearance-common-law/SKILL.md +45 -111
  230. package/driver/skills/clearance-common-law/perplexity-prompts.md +7 -79
  231. package/driver/skills/clearance-register/SKILL.md +15 -33
  232. package/driver/skills/clearance-register/digest.md +35 -96
  233. package/driver/skills/clearance-register/providers/clarivate.md +2 -2
  234. package/driver/skills/clearance-register/providers/corsearch.md +5 -5
  235. package/driver/skills/clearance-register/providers/euipo.md +1 -2
  236. package/driver/skills/clearance-register/providers/free-tier.md +0 -19
  237. package/driver/skills/clearance-register/providers/signa.md +6 -25
  238. package/driver/skills/clearance-register/providers/uspto-local.md +0 -24
  239. package/driver/skills/clearance-register/register-recipes.md +8 -15
  240. package/driver/skills/clearance-register/status-rules.md +6 -24
  241. package/driver/skills/clearance-register/unit.md +11 -20
  242. package/driver/skills/clearance-search/delivery-contract.md +24 -120
  243. package/driver/skills/clearance-search/field-doctrine-pharma.md +1 -5
  244. package/driver/skills/clearance-search/firm-wide-reasoning.md +24 -43
  245. package/driver/skills/clearance-search/phase2-execution.md +29 -77
  246. package/driver/skills/clearance-search/report-prose.md +3 -4
  247. package/driver/skills/clearance-search/risk-framework-demo.md +1 -1
  248. package/driver/skills/clearance-search/risk-framework-triage.manifest.json +3 -3
  249. package/driver/skills/clearance-search/risk-framework-triage.md +7 -9
  250. package/driver/skills/clearance-search/risk-framework.manifest.json +1 -1
  251. package/driver/skills/clearance-search/risk-framework.md +1 -1
  252. package/driver/skills/clearance-search/synthesis-rules.md +30 -107
  253. package/driver/skills/clearance-search/worked-examples.md +5 -5
  254. package/driver/skills/clearance-variants/SKILL.md +46 -45
  255. package/driver/skills/clearance-variants/transliteration-scripts.md +4 -4
  256. package/driver/skills/frame-diff/SKILL.md +1 -1
  257. package/driver/skills/knockout-assess/SKILL.md +6 -14
  258. package/driver/skills/knockout-frame/SKILL.md +1 -1
  259. package/driver/skills/matter-frame/SKILL.md +7 -12
  260. package/driver/skills/matter-frame/watchlist-reference.md +1 -4
  261. package/driver/skills/narrative-refutation/SKILL.md +20 -30
  262. package/driver/skills/placement-inquiry/SKILL.md +10 -20
  263. package/driver/skills-store-provenance.mjs +1 -1
  264. package/driver/stage-context.mjs +32 -35
  265. package/driver/stage-freshness.mjs +127 -11
  266. package/driver/stages-knockout.mjs +49 -22
  267. package/driver/stages.mjs +89 -288
  268. package/driver/status-snapshot.mjs +2 -1
  269. package/driver/steps/correction-cycle.mjs +311 -0
  270. package/driver/steps/corrections.mjs +644 -0
  271. package/driver/steps/delivery.mjs +1287 -0
  272. package/driver/steps/frame-comparison.mjs +927 -0
  273. package/driver/steps/intake.mjs +84 -0
  274. package/driver/steps/open-run.mjs +419 -0
  275. package/driver/steps/overview-and-cards.mjs +899 -0
  276. package/driver/steps/placement-and-digest.mjs +23 -0
  277. package/driver/steps/register-sweep.mjs +1563 -0
  278. package/driver/steps/skeptic-and-follow-up.mjs +836 -0
  279. package/driver/steps/synthesis.mjs +261 -0
  280. package/driver/steps/verdict-gate.mjs +968 -0
  281. package/driver/suite-census.json +456 -96
  282. package/driver/surface-exit-verdict.mjs +0 -8
  283. package/driver/synthesis-record.mjs +72 -6
  284. package/driver/terminal-clamp.mjs +10 -0
  285. package/driver/tokens.mjs +8 -62
  286. package/driver/tool-calls.mjs +2 -2
  287. package/driver/unexecuted-asserts.json +2 -2
  288. package/driver/unit-state-verdict.mjs +1 -1
  289. package/driver/usage-ledger.mjs +2 -1
  290. package/driver/verify-knockout.mjs +20 -35
  291. package/driver/verify.mjs +47 -36
  292. package/driver/web-grid.mjs +3 -4
  293. package/driver/whatif-memo-run.mjs +2 -2
  294. package/driver/whatif-queue.mjs +4 -3
  295. package/driver/withheld-families.mjs +14 -15
  296. package/driver/worker-heartbeat.mjs +3 -2
  297. package/driver/write-up-form.mjs +0 -3
  298. package/mcp-server/CHANGELOG.md +8 -0
  299. package/mcp-server/http-server.mjs +11 -12
  300. package/mcp-server/lib/brief.mjs +22 -4
  301. package/mcp-server/lib/events.mjs +2 -2
  302. package/mcp-server/lib/evidence.mjs +3 -2
  303. package/mcp-server/lib/findings.mjs +2 -1
  304. package/mcp-server/lib/knockout.mjs +9 -10
  305. package/mcp-server/lib/ops.mjs +9 -9
  306. package/mcp-server/lib/runs.mjs +9 -10
  307. package/mcp-server/lib/trace.mjs +1 -1
  308. package/mcp-server/lib/whatif.mjs +2 -3
  309. package/mcp-server/package.json +1 -1
  310. package/mcp-server/server.mjs +5 -5
  311. package/node_modules/buffers/package.json +1 -1
  312. package/package.json +2 -1
  313. package/portal-ui/dist/assets/{index-fPqAU0sx.js → index-CYaO2ygd.js} +26 -14
  314. package/portal-ui/dist/assets/{index-AtB9ZpDH.css → index-izLa9apq.css} +2 -2
  315. package/portal-ui/dist/index.html +4 -4
  316. package/portal-ui/package.json +3 -3
  317. package/providers/README.md +1 -1
  318. package/providers/_shared/answer-memory.mjs +4 -5
  319. package/providers/_shared/execute-plan.mjs +48 -1
  320. package/providers/_shared/records-from-search.mjs +46 -0
  321. package/providers/clarivate/README.md +2 -2
  322. package/providers/clarivate/src/adapter.js +147 -0
  323. package/providers/clarivate/src/core.js +1 -14
  324. package/{driver/engine/mcp/clarivate-server.mjs → providers/clarivate/src/mount.js} +5 -10
  325. package/providers/corsearch/README.md +3 -3
  326. package/providers/corsearch/src/adapter.js +80 -0
  327. package/providers/corsearch/src/core.js +14 -11
  328. package/{driver/engine/mcp/corsearch-server.mjs → providers/corsearch/src/mount.js} +5 -10
  329. package/providers/euipo/README.md +2 -2
  330. package/providers/euipo/src/adapter.js +85 -0
  331. package/providers/euipo/src/core.js +1 -1
  332. package/providers/euipo/src/euipo-client.js +1 -2
  333. package/{driver/engine/mcp/euipo-server.mjs → providers/euipo/src/mount.js} +5 -10
  334. package/providers/free-tier/README.md +2 -2
  335. package/providers/free-tier/src/adapter.js +127 -0
  336. package/{driver/engine/mcp/free-tier-server.mjs → providers/free-tier/src/mount.js} +5 -10
  337. package/providers/jx-subclass/coverage.mjs +1 -6
  338. package/providers/jx-subclass/score-truth.mjs +2 -1
  339. package/providers/oauth-mcp-bridge/CHANGELOG.md +8 -0
  340. package/providers/oauth-mcp-bridge/package.json +1 -1
  341. package/providers/perplexity/src/core.js +2 -2
  342. package/providers/signa/README.md +2 -2
  343. package/providers/signa/src/adapter.js +157 -0
  344. package/providers/signa/src/capabilities.js +0 -3
  345. package/providers/signa/src/core.js +2 -2
  346. package/{driver/engine/mcp/signa-server.mjs → providers/signa/src/mount.js} +7 -12
  347. package/providers/signa/src/offices.generated.js +17 -15
  348. package/providers/uspto-local/README.md +1 -1
  349. package/providers/uspto-local/bin/verify-index.mjs +1 -1
  350. package/providers/uspto-local/src/adapter.js +75 -0
  351. package/{driver/engine/mcp/uspto-local-server.mjs → providers/uspto-local/src/mount.js} +5 -10
  352. package/scripts/band-shape-probe.mjs +2 -2
  353. package/scripts/citation-line-check.mjs +7 -7
  354. package/scripts/compare.mjs +1 -1
  355. package/scripts/dead-names.mjs +2 -2
  356. package/scripts/e2e-first-time.mjs +19 -7
  357. package/scripts/e2e.mjs +13 -13
  358. package/scripts/engine-probe.mjs +1 -1
  359. package/scripts/env-audit.mjs +7 -4
  360. package/scripts/env-classify.mjs +5 -1
  361. package/scripts/feedback-mint.mjs +1 -1
  362. package/scripts/freeze-example-run.mjs +7 -7
  363. package/scripts/mint-suite-census.mjs +2 -2
  364. package/scripts/nightly-notice.mjs +1 -1
  365. package/scripts/release-cut-decision.mjs +7 -2
  366. package/scripts/release-note-required.mjs +26 -9
  367. package/scripts/release-notes-lint.mjs +3 -2
  368. package/scripts/release-version-pr-checks.mjs +1 -1
  369. package/scripts/render-check.mjs +1 -1
  370. package/scripts/settings-render-check.mjs +23 -3
  371. package/scripts/test-run.mjs +5 -5
  372. package/scripts/travelling-predicates.mjs +1 -1
  373. package/scripts/undeclared-field-census.mjs +1 -1
  374. package/scripts/unexecuted-asserts.mjs +3 -3
  375. package/scripts/verify-publishable.mjs +1 -1
  376. package/shared/client-door.mjs +1 -1
  377. package/shared/connect-clients.mjs +1 -1
  378. package/shared/connector-signin-probe.mjs +1 -1
  379. package/shared/customer-store.mjs +3 -2
  380. package/shared/env-aliases.mjs +1 -1
  381. package/shared/invocation.mjs +14 -2
  382. package/shared/names-in-force.mjs +2 -0
  383. package/shared/register-selection.mjs +2 -2
  384. package/shared/store-in-repo.mjs +3 -3
  385. package/shared/summary-blocks.mjs +0 -3
  386. package/shared/trigger-lane.mjs +1 -1
  387. package/shared/vacuous-pass.mjs +2 -2
  388. package/shared/verb-shim.mjs +4 -2
  389. package/vendor/buffers/package.json +1 -1
  390. package/node_modules/exceljs/README.md +0 -3023
@@ -59,16 +59,16 @@
59
59
  // CHECK membership. Derive identity FROM the marks and the membership guard becomes the decision: a seat
60
60
  // that rates the wrong marks no longer fails a check — it writes to a different chunk file and passes.
61
61
  // That is the guard and the thing it guards collapsing into each other.
62
- import { existsSync, mkdirSync, writeFileSync, readFileSync } from "node:fs";
62
+ import { existsSync, writeFileSync, readFileSync } from "node:fs";
63
63
  import { captureCall, stampVerdict } from "./call-capture.mjs";
64
64
  import { join } from "node:path";
65
- import { driverDir } from "../shared/driver-dir.mjs";
66
65
  import { refuseUndeclared as refuseUndeclaredShared, keepIfAbsent, lastAccepted, acceptedEnvelope } from "./preserve-merge.mjs";
67
66
  // THE VALIDATOR'S OWN PREDICATE, imported rather than restated. Two spellings of one closed set is how
68
67
  // the call and the stage come to disagree about what is legal, which is the defect this check closes.
69
68
  import { normalizeKnockoutQualifier, KNOCKOUT_RATING_QUALIFIERS, heldCitationsOnly, classGroupsDefect, frozenLadder, validators } from "./verify-knockout.mjs";
70
69
  // A FINDING'S KEYS, likewise: the validator's one list, so a key the call records is a key the stage accepts.
71
70
  import { KNOCKOUT_FINDING_KEYS } from "./findings-model.mjs";
71
+ import { driverDir, readJson } from "./run-record.mjs";
72
72
 
73
73
  const SCHEMA_VERSION = 1;
74
74
 
@@ -423,7 +423,7 @@ const sourceDefectsPath = (runDir, chunkNo) => join(knockoutAssessCallPaths(Stri
423
423
  * correction. A row never leaves on its own account: the claim may survive a finding dropped or renamed, and only an accepted read settles it.
424
424
  */
425
425
  export function knockoutAssessSourceDefects(runDir, chunkNo) {
426
- try { return JSON.parse(readFileSync(sourceDefectsPath(runDir, chunkNo), "utf8")); } catch { return []; }
426
+ try { return readJson(sourceDefectsPath(runDir, chunkNo)); } catch { return []; }
427
427
  }
428
428
 
429
429
  // CODE DOES NOT JUDGE THE CLAIM. It reads whether the finding changed, and leaves whether that answers the problem to the check.
@@ -0,0 +1,21 @@
1
+ // SPDX-License-Identifier: AGPL-3.0-only
2
+ // Copyright 2026 Cordillera Sàrl. Additional terms under section 7 of the AGPL-3.0 apply — see ADDITIONAL-TERMS.md
3
+ // knockout-caveats.mjs — the sentences a knockout's engine appends itself, and how to tell them from the rater's.
4
+ import { CAPABILITY_SKIPPED_NOTE } from "./search-policy.mjs";
5
+
6
+ export const SURVIVOR_BOUNDARY_RE = /not knocked out at this screen's depth/i;
7
+
8
+ /**
9
+ * Is this caveat the ENGINE'S OWN WORDS rather than the rater's?
10
+ *
11
+ * The engine appends two, both stated in code because the assessing model cannot see the facts behind
12
+ * them: the survivor boundary, and the capability-skipped note. Neither is something "the rater
13
+ * supplied", and telling them apart is the whole of — the standing-caveat lint asked
14
+ * "did the rater supply caveats?" of an array the engine had already written into, so from the moment
15
+ * the survivor sentence was appended the answer was always yes and the check could never fire again.
16
+ */
17
+ export function isEngineAppendedCaveat(text) {
18
+ const t = String(text ?? "");
19
+ if (SURVIVOR_BOUNDARY_RE.test(t)) return true;
20
+ return Object.values(CAPABILITY_SKIPPED_NOTE).some((note) => t.trim() === String(note).trim());
21
+ }
@@ -10,6 +10,8 @@
10
10
  // WHAT STANDS, STANDS BY CONSTRUCTION. A call may touch only the names a defect concerns, and a name no defect concerns cannot
11
11
  // drift, nor its block in the summary, because no field reaches them. Inside an affected name the repair reaches what it needs,
12
12
  // and says which defect each moved finding serves. A call sends only what changes, and its rows merge onto the chunk the run holds.
13
+ // ONE STATEMENT, WHEREVER IT PRINTS. A finding is copied onto each name it bears on, so a line a defect names on one name can stand
14
+ // on another that no defect names. A call may correct that same finding there (design, 2026-11-09), and nothing else on that name.
13
15
  //
14
16
  // THE CHUNK IS THE RECORD, so a corrected batch composes as a rated one does, through the same steps and the same gate, and
15
17
  // a resumed run reads the correction back rather than losing it. An accepted repair stands when later work fails: only a change
@@ -23,10 +25,10 @@ import { copyFileSync, existsSync, readFileSync, writeFileSync } from "node:fs";
23
25
  import { basename, dirname, join } from "node:path";
24
26
 
25
27
  import { captureCall, stampVerdict } from "./call-capture.mjs";
26
- import { DRIVER_DIR, driverDir } from "../shared/driver-dir.mjs";
27
28
  import { acceptedEnvelope } from "./preserve-merge.mjs";
28
29
  import { acceptKnockoutAssess, knockoutAssessCallPaths, knockoutAssessChunkFile, refuseUndeclared } from "./knockout-assess-record.mjs";
29
30
  import { validators as koValidators } from "./verify-knockout.mjs";
31
+ import { DRIVER_DIR, driverDir, paths, readJsonOrNull } from "./run-record.mjs";
30
32
 
31
33
  const TOKEN = "knockoutcorrection";
32
34
  const SCHEMA_VERSION = 1;
@@ -36,12 +38,11 @@ export const knockoutCorrectionFile = (runDir, chunkNo) => join(String(runDir ??
36
38
  export const KNOCKOUT_CORRECTION_RE = /^knockout-correction-\d+\.json$/;
37
39
 
38
40
  /** The driver's own account of the round: the record the check read, and each defect with its address. */
39
- export const correctionWorkPath = (runDir) => driverDir(runDir, "knockout-correction-work.json");
40
- const chunkBasePath = (runDir, chunkNo) => driverDir(runDir, `knockout-correction-base-${Number(chunkNo)}.json`);
41
+ export const correctionWorkPath = (runDir) => paths(runDir).knockoutCorrectionWork;
42
+ export const chunkBasePath = (runDir, chunkNo) => driverDir(runDir, `knockout-correction-base-${Number(chunkNo)}.json`);
41
43
  const correctionCallDir = (runDir, chunkNo) => driverDir(runDir, join("knockout-correction-calls", `chunk-${Number(chunkNo)}`));
42
44
 
43
45
  const nameKey = (s) => String(s ?? "").trim().toLowerCase();
44
- const readJson = (path) => { try { return JSON.parse(readFileSync(path, "utf8")); } catch { return null; } };
45
46
  /** A finding's identity across a renumbering: the gate re-ranks on the band, so an ordinal does not survive a move. */
46
47
  export const sameFinding = (a, b) => nameKey(a?.name) === nameKey(b?.name) && nameKey(a?.owner) === nameKey(b?.owner);
47
48
  const withoutOrdinal = (f) => { const { ordinal: _ordinal, ...rest } = f ?? {}; return JSON.stringify(rest); };
@@ -62,7 +63,7 @@ export function correctionWork({ rated, material, chunks }) {
62
63
  return { schema_version: SCHEMA_VERSION, rated, defects };
63
64
  }
64
65
 
65
- export const readCorrectionWork = (runDir) => readJson(correctionWorkPath(runDir));
66
+ export const readCorrectionWork = (runDir) => readJsonOrNull(correctionWorkPath(runDir));
66
67
 
67
68
  /** Keep each chunk a defect touches as it was rated. Written once: a resumed round must not take a corrected chunk for the base. */
68
69
  export function keepChunkBases(runDir, chunkNos) {
@@ -91,7 +92,26 @@ export function chunkScope(work, chunkNo, base) {
91
92
  }
92
93
  byMark.set(key, row);
93
94
  }
94
- return { defects, byMark };
95
+ return { defects, byMark, namedFindings: defects.flatMap((d) => (d.names ? [d.names] : [])) };
96
+ }
97
+
98
+ const isNamedFinding = (f, named) => (named ?? []).some((n) => sameFinding(f, n));
99
+
100
+ /**
101
+ * The ordinals a call's row changes or removes on a name no defect concerns that no defect's answer lists, beyond the findings
102
+ * a defect names. Empty when every change is answered for. PURE.
103
+ *
104
+ * A correction may reach a name no defect concerns where its repair genuinely needs to (design ruling, 2026-11-10: the
105
+ * Knockout corrects the way the clearance does, recording what moved and why and putting it to the recheck). What it
106
+ * owes for that is the reason, in the answer to the defect it serves, so the recheck can read the connection.
107
+ */
108
+ function unansweredOrdinals(row, mark, scope, answers) {
109
+ const listed = new Set((Array.isArray(answers) ? answers : []).flatMap((a) => (Array.isArray(a?.findings) ? a.findings : [])));
110
+ const ratedAt = (o) => (mark?.findings ?? []).find((x) => x?.ordinal === o);
111
+ // A finding a defect names, sent back still that finding, is the repair itself; every other change or removal is not.
112
+ const sent = (Array.isArray(row?.findings) ? row.findings : []).filter((f) => { const was = ratedAt(f?.ordinal); return !(was && isNamedFinding(was, scope.namedFindings) && sameFinding(f, was)); });
113
+ const changed = [...sent.map((f) => f?.ordinal), ...(Array.isArray(row?.remove_findings) ? row.remove_findings : [])];
114
+ return changed.filter((o) => !listed.has(o));
95
115
  }
96
116
 
97
117
  /** One name's block in a chunk summary: its `## NAME` sub-header to the next. Null where it has none. PURE. */
@@ -115,9 +135,9 @@ function patchedFindings(mark, row, stop) {
115
135
  }
116
136
 
117
137
  /**
118
- * The chunk with one call applied, or why it cannot be. PURE. \`held\` is the chunk as it now stands. A name no defect concerns,
119
- * and its block in the summary, stay as they are; a defect's repair may reach whatever findings of its own name it needs, and
120
- * says which (\`mergedAnswers\`), so the check that follows can read the connection.
138
+ * The chunk with one call applied, or why it cannot be. PURE. \`held\` is the chunk as it now stands. A defect's repair may reach
139
+ * whatever findings of its own name it needs, and a name no defect concerns where the repair depends on it, listing each such
140
+ * finding in an answer's \`findings\` with the reason (\`mergedAnswers\`), so the check that follows can read the connection.
121
141
  */
122
142
  export function applyCorrectionCall({ held, call, scope }) {
123
143
  const refuse = (what) => ({ ok: false, reason: `${TOKEN}_${what}` });
@@ -127,9 +147,10 @@ export function applyCorrectionCall({ held, call, scope }) {
127
147
  const moved = [];
128
148
  for (const row of Array.isArray(call?.marks) ? call.marks : []) {
129
149
  const name = String(row?.name ?? "");
130
- if (!scope.byMark.has(nameKey(name))) return refuse(`scope:${name}: no material defect concerns this name. Leave it as it stands.`);
131
150
  const i = marks.findIndex((m) => nameKey(m?.name) === nameKey(name));
151
+ const concerned = scope.byMark.has(nameKey(name));
132
152
  if (i < 0) return refuse(`scope:${name}: this name is not in the chunk you were handed.`);
153
+ if (!concerned && unansweredOrdinals(row, marks[i], scope, call?.answers).length) return refuse(`scope:${name}: No defect concerns this name. List each finding you change or remove on it in the \`findings\` of the defect your repair serves, and say why in that answer.`);
133
154
  const { findings: _findings, remove_findings: _removed, ...fields } = row;
134
155
  const next = { ...marks[i], ...fields };
135
156
  if (row.findings !== undefined || row.remove_findings !== undefined) {
@@ -147,10 +168,7 @@ export function applyCorrectionCall({ held, call, scope }) {
147
168
  moved.push(name);
148
169
  }
149
170
  const chunkSummary = call?.chunkSummary ?? held?.chunkSummary;
150
- for (const m of marks) {
151
- if (scope.byMark.has(nameKey(m?.name))) continue;
152
- if (summaryBlock(chunkSummary, m.name) !== summaryBlock(held?.chunkSummary, m.name)) return refuse(`summary:${m.name}: no defect concerns this name, so its block in chunkSummary stays as it was.`);
153
- }
171
+ // A block that moves under a name no defect concerns is recorded and rechecked with that name (movedOutsideScope), not refused.
154
172
  for (const name of moved) {
155
173
  const m = marks.find((x) => nameKey(x?.name) === nameKey(name));
156
174
  const block = summaryBlock(chunkSummary, name);
@@ -217,14 +235,14 @@ export function recordKnockoutCorrection(runDir, received, { boundOrdinal = null
217
235
 
218
236
  const work = readCorrectionWork(dir);
219
237
  const file = knockoutAssessChunkFile(dir, chunkNo);
220
- const held = readJson(file), base = readJson(chunkBasePath(dir, chunkNo));
238
+ const held = readJsonOrNull(file), base = readJsonOrNull(chunkBasePath(dir, chunkNo));
221
239
  if (!work || !held || !base) return refused(`${TOKEN}_state: this run holds no correction for chunk ${chunkNo}.`);
222
240
  const scope = chunkScope(work, chunkNo, base);
223
241
 
224
242
  const applied = applyCorrectionCall({ held, call: rest, scope });
225
243
  if (!applied.ok) return refused(applied.reason);
226
244
  const receipt = knockoutCorrectionFile(dir, chunkNo);
227
- const answers = mergedAnswers(readJson(receipt)?.answers, receivedAnswers, scope, { base, chunk: applied.chunk });
245
+ const answers = mergedAnswers(readJsonOrNull(receipt)?.answers, receivedAnswers, scope, { base, chunk: applied.chunk });
228
246
  if (!answers.ok) return refused(answers.reason);
229
247
 
230
248
  // THE SAME GATES A RATED CHUNK PASSED, at the call, while the seat can still repair what they name.
@@ -273,14 +291,14 @@ export function rollBackName(runDir, work, name) {
273
291
  const defects = (work?.defects ?? []).filter((d) => nameKey(d.mark) === nameKey(name));
274
292
  const chunkNo = defects[0]?.chunk;
275
293
  if (chunkNo == null) return;
276
- const base = readJson(chunkBasePath(runDir, chunkNo)), held = readJson(knockoutAssessChunkFile(runDir, chunkNo));
294
+ const base = readJsonOrNull(chunkBasePath(runDir, chunkNo)), held = readJsonOrNull(knockoutAssessChunkFile(runDir, chunkNo));
277
295
  const rated = (base?.marks ?? []).find((m) => nameKey(m?.name) === nameKey(name));
278
296
  if (!base || !held || !rated) return;
279
297
  const was = summaryBlock(base.chunkSummary, name), now = summaryBlock(held.chunkSummary, name);
280
298
  const chunkSummary = was != null && now != null ? held.chunkSummary.replace(now, () => was) : held.chunkSummary;
281
299
  const text = JSON.stringify({ ...held, chunkSummary, marks: held.marks.map((m) => (nameKey(m?.name) === nameKey(name) ? rated : m)) }, null, 2) + "\n";
282
300
  writeFileSync(knockoutAssessChunkFile(runDir, chunkNo), text);
283
- const receipt = readJson(knockoutCorrectionFile(runDir, chunkNo));
301
+ const receipt = readJsonOrNull(knockoutCorrectionFile(runDir, chunkNo));
284
302
  const ns = new Set(defects.map((d) => d.n));
285
303
  if (receipt) writeFileSync(knockoutCorrectionFile(runDir, chunkNo), JSON.stringify({ ...receipt, chunkSha: chunkSha(text),
286
304
  answers: (receipt.answers ?? []).filter((a) => !ns.has(a.defect)), rolledBack: [...new Set([...(receipt.rolledBack ?? []), ...ns])] }, null, 2) + "\n");
@@ -297,7 +315,7 @@ export function knockoutCorrectionRefusalsFor(runDir, chunkNo = 0) {
297
315
  /** The answers every chunk of the round has given, by defect. */
298
316
  export function correctionAnswers(runDir, chunkNos) {
299
317
  const out = new Map();
300
- for (const c of chunkNos) for (const a of readJson(knockoutCorrectionFile(runDir, c))?.answers ?? []) out.set(a.defect, a);
318
+ for (const c of chunkNos) for (const a of readJsonOrNull(knockoutCorrectionFile(runDir, c))?.answers ?? []) out.set(a.defect, a);
301
319
  return out;
302
320
  }
303
321
 
@@ -326,17 +344,29 @@ export function correctionOutcomes(work, after, answers = new Map()) {
326
344
  }
327
345
 
328
346
  /**
329
- * What moved under a name no defect concerns, or an empty answer: its record, or its block in the batch summary. A call cannot reach
330
- * these, so a row here is a fault between the chunk and the record, and the caller keeps the rated record. PURE.
347
+ * What moved under a name no defect concerns: its record, or its block in the batch summary, each with its before and after.
348
+ * The correction may reach such a name where its repair needs to, and says why in its answers; the recheck reads every one
349
+ * listed here. A finding a defect names, corrected where it prints on this name, is allowed, and it is listed all the same,
350
+ * with the defects whose finding it is: the review accounts for every name that changed. `complete: false` when either record
351
+ * cannot be read: an absent record cannot show that nothing moved, and the recheck then reads the whole batch. PURE.
331
352
  */
332
353
  export function movedOutsideScope(work, after) {
333
- const concerned = new Set((work?.defects ?? []).map((d) => nameKey(d.mark)));
334
- const marks = [], blocks = [];
335
- for (const was of work?.rated?.marks ?? []) {
354
+ const defects = work?.defects ?? [];
355
+ const concerned = new Set(defects.map((d) => nameKey(d.mark)));
356
+ const shape = (m) => (m ? JSON.stringify({ ...m, findings: (m.findings ?? []).map(withoutOrdinal) }) : null);
357
+ const namedOn = (m, names) => JSON.stringify((m?.findings ?? []).filter((f) => sameFinding(f, names)).map(withoutOrdinal));
358
+ const marks = [], blocks = [], moved = [];
359
+ if (!Array.isArray(work?.rated?.marks) || !Array.isArray(after?.marks)) return { marks, blocks, moved, complete: false };
360
+ for (const was of work.rated.marks) {
336
361
  if (concerned.has(nameKey(was?.name))) continue;
337
- const now = (after?.marks ?? []).find((m) => nameKey(m?.name) === nameKey(was?.name)) ?? null;
338
- if (JSON.stringify(was) !== JSON.stringify(now)) marks.push(was.name);
339
- if (summaryBlock(work.rated?.batch?.executiveSummary, was.name) !== summaryBlock(after?.batch?.executiveSummary, was.name)) blocks.push(was.name);
362
+ const now = after.marks.find((m) => nameKey(m?.name) === nameKey(was?.name)) ?? null;
363
+ const blockWas = summaryBlock(work.rated?.batch?.executiveSummary, was.name), blockNow = summaryBlock(after?.batch?.executiveSummary, was.name);
364
+ const record = shape(was) !== shape(now), block = blockWas !== blockNow;
365
+ if (record) marks.push(was.name);
366
+ if (block) blocks.push(was.name);
367
+ if (!record && !block) continue;
368
+ const linked = defects.filter((d) => d.names && namedOn(was, d.names) !== namedOn(now, d.names)).map((d) => d.n);
369
+ moved.push({ name: was.name, defects: linked, before: { mark: was, block: blockWas }, after: { mark: now, block: blockNow } });
340
370
  }
341
- return { marks, blocks };
371
+ return { marks, blocks, moved, complete: true };
342
372
  }
@@ -44,7 +44,6 @@
44
44
  import { mkdirSync, writeFileSync, readFileSync } from "node:fs";
45
45
  import { captureCall, stampVerdict } from "./call-capture.mjs";
46
46
  import { join } from "node:path";
47
- import { driverDir } from "../shared/driver-dir.mjs";
48
47
  import { refuseUndeclared as refuseUndeclaredShared, keepIfAbsent, lastAccepted, acceptedEnvelope } from "./preserve-merge.mjs";
49
48
  // The collision predicate itself, imported. See the duplication note above: two copies of a rule are how
50
49
  // two gates come to disagree about what they are enforcing.
@@ -52,6 +51,7 @@ import { kebabCollisions } from "./search-policy.mjs";
52
51
  // The plan's own checks for the web search's lists, one definition: the call is refused with the plan's
53
52
  // sentence, so the seat hears the rule once, in the same words, whichever door it reaches first.
54
53
  import { placesDefect, spellingsDefect, useKindDefect, alternativesDefect } from "./verify-knockout.mjs";
54
+ import { paths as runPaths } from "./run-record.mjs";
55
55
 
56
56
  const SCHEMA_VERSION = 1;
57
57
 
@@ -67,7 +67,7 @@ export function knockoutFrameFiles(runDir) {
67
67
  * directory cannot be overwritten by a sibling.
68
68
  */
69
69
  export function knockoutFrameCallPaths(runDir) {
70
- const dir = driverDir(runDir, "knockout-frame-calls");
70
+ const dir = runPaths(runDir).knockoutFrameCalls;
71
71
  return { dir, payload: join(dir, "call-001.json"), accepted: join(dir, "accepted.json"),
72
72
  refusals: join(dir, "refusals.jsonl") };
73
73
  }
@@ -24,10 +24,10 @@
24
24
  //
25
25
  // NO MODEL TOUCHES A ROW. The step names record ids; this module joins them to what the register answered.
26
26
 
27
- import { appendFileSync, mkdirSync, readdirSync, readFileSync, renameSync, writeFileSync } from "node:fs";
27
+ import { appendFileSync, mkdirSync, readdirSync, renameSync, writeFileSync } from "node:fs";
28
28
  import { dirname, join } from "node:path";
29
+ import { createHash } from "node:crypto";
29
30
 
30
- import { driverDir } from "../shared/driver-dir.mjs";
31
31
  import { kebab } from "./search-policy.mjs";
32
32
  import { resolveRegions } from "./register-plan.mjs";
33
33
  import { reachableRegions } from "./register-availability.mjs";
@@ -35,6 +35,7 @@ import { RECORD_BASIS, fixtureLister, toRecord } from "./register-records.mjs";
35
35
  import { ENUMERATE_CEILING_DEFAULT } from "../providers/_shared/enumerate.mjs";
36
36
  export { writeFixtureMarker } from "./register-fixture-marker.mjs";
37
37
  import { withFilingGoods } from "./filing-goods.mjs";
38
+ import { driverDir, readJson } from "./run-record.mjs";
38
39
 
39
40
  export const QUESTION_PLAN_FILE = "register-plan.json";
40
41
  export const BAND_DIR = "register-units";
@@ -115,7 +116,7 @@ export function knockoutQuestionPlan({ marks, classes = null, jurisdictions = nu
115
116
  /** The questions the frame's added classes owe one name, from the run's frozen plan: each class's identical-name question. */
116
117
  export function addedClassQuestions(runDir, name) {
117
118
  let plan = null;
118
- try { plan = JSON.parse(readFileSync(questionPlanPath(runDir), "utf8")); } catch { return []; }
119
+ try { plan = readJson(questionPlanPath(runDir)); } catch { return []; }
119
120
  return addedOf(plan, name);
120
121
  }
121
122
  const addedOf = (plan, name) => (plan?.entries ?? []).filter((e) => e?.axis === knockoutAxis(name) && e?.added_class_reason)
@@ -125,7 +126,7 @@ const addedOf = (plan, name) => (plan?.entries ?? []).filter((e) => e?.axis ===
125
126
  export function knockoutBandBlocks(runDir, name) {
126
127
  const out = new Map();
127
128
  let doc;
128
- try { doc = JSON.parse(readFileSync(knockoutBandPath(runDir, name), "utf8")); } catch { return out; }
129
+ try { doc = readJson(knockoutBandPath(runDir, name)); } catch { return out; }
129
130
  for (const b of Array.isArray(doc) ? doc : []) if (b?.qid) out.set(String(b.qid), b);
130
131
  return out;
131
132
  }
@@ -134,7 +135,7 @@ export function knockoutBandBlocks(runDir, name) {
134
135
  export function knockoutProposals(runDir, name) {
135
136
  const path = join(String(runDir ?? ""), BAND_DIR, `${knockoutAxis(name)}-supplemental-plan.json`);
136
137
  try {
137
- const doc = JSON.parse(readFileSync(path, "utf8"));
138
+ const doc = readJson(path);
138
139
  return { entries: Array.isArray(doc?.entries) ? doc.entries : [], rejected: Array.isArray(doc?.rejected) ? doc.rejected : [] };
139
140
  } catch { return { entries: [], rejected: [] }; }
140
141
  }
@@ -578,7 +579,7 @@ export function knockoutListView(runDir, { qid, record_id: recordId = null }, go
578
579
  try { files = readdirSync(dir).filter((f) => f.endsWith("-band.json")); } catch { files = []; }
579
580
  for (const f of files) {
580
581
  let doc;
581
- try { doc = JSON.parse(readFileSync(join(dir, f), "utf8")); } catch { continue; }
582
+ try { doc = readJson(join(dir, f)); } catch { continue; }
582
583
  for (const b of Array.isArray(doc) ? doc : []) if (String(b?.qid ?? "") === want) found = b;
583
584
  if (found) break;
584
585
  }
@@ -602,7 +603,7 @@ export function knockoutListView(runDir, { qid, record_id: recordId = null }, go
602
603
 
603
604
  /** All the wording held for one filing: its whole held record where one was written, else the statements its view carries. */
604
605
  function heldWording(record, runDir) {
605
- try { if (record.fullRecord) return { full_record: JSON.parse(readFileSync(join(String(runDir ?? ""), record.fullRecord), "utf8")) }; }
606
+ try { if (record.fullRecord) return { full_record: readJson(join(String(runDir ?? ""), record.fullRecord)) }; }
606
607
  catch { /* the view below is what is left to read */ }
607
608
  return { goods: record.goods };
608
609
  }
@@ -632,36 +633,52 @@ const MATCH_MODES = Object.freeze({ exact: "exact", default: "default", phonetic
632
633
  * never as a zero. For offline runs and tests alone, and it sends nothing anywhere. Returns the executor's summary text.
633
634
  */
634
635
  export async function executeQuestionsWithLister(lister, { plan_path: planPath, axis, output_path: outputPath, qids = null }) {
635
- const plan = JSON.parse(readFileSync(planPath, "utf8"));
636
+ const plan = readJson(planPath);
636
637
  const wanted = Array.isArray(qids) && qids.length ? new Set(qids.map(String)) : null;
637
- const entries = (plan?.entries ?? []).filter((e) => e?.axis === axis && (!wanted || wanted.has(String(e?.qid))));
638
- if (!entries.length) return { type: "text", text: `ERROR: the plan carries no entries for axis "${axis}".` };
638
+ const asked = (plan?.entries ?? []).filter((e) => e?.axis === axis && (!wanted || wanted.has(String(e?.qid))));
639
+ if (!asked.length) return { type: "text", text: `ERROR: the plan carries no entries for axis "${axis}".` };
639
640
  let band = [];
640
- try { const had = JSON.parse(readFileSync(outputPath, "utf8")); if (Array.isArray(had)) band = had; } catch { /* first write */ }
641
- const owned = new Set(entries.map((e) => String(e.qid)));
642
- const states = {};
643
- const blocks = [];
641
+ try { const had = readJson(outputPath); if (Array.isArray(had)) band = had; } catch { /* first write */ }
644
642
  // What the name's own question was asked over: a question over other classes is a narrower one, and is keyed as one.
645
643
  let nameClasses = null;
646
644
  try {
647
- const frozen = JSON.parse(readFileSync(driverDir(dirname(dirname(outputPath)), QUESTION_PLAN_FILE), "utf8"));
645
+ const frozen = readJson(driverDir(dirname(dirname(outputPath)), QUESTION_PLAN_FILE));
648
646
  nameClasses = (frozen?.entries ?? []).find((f) => f?.axis === axis && f?.provenance === "mark" && !f?.added_class_reason)?.nice_classes ?? null;
649
647
  } catch { nameClasses = null; }
650
648
  const sameClasses = (a) => JSON.stringify([...(a ?? [])].map(String).sort()) === JSON.stringify([...(nameClasses ?? [])].map(String).sort());
649
+ /** What one question sends the register, term by term. */
650
+ const sentFor = (e) => (Array.isArray(e?.terms) ? e.terms : [e?.term]).map((term) => ({ term, classes: sameClasses(e.nice_classes) ? [] : (e.nice_classes ?? []),
651
+ regions: e.regions ?? [], matchMode: MATCH_MODES[e?.predicate] ?? "default", goods: e.goods_text ?? null, scoped: true }));
652
+ const sentKey = (e) => createHash("sha256").update(JSON.stringify(sentFor(e))).digest("hex").slice(0, 16);
653
+ // NEVER PAID FOR TWICE (2026-11-11). A register answer is paid for, and it does not change within the run. So a
654
+ // question this run already holds an answer to is not sent again, whoever asks it and however often: a resume, a
655
+ // step run again, or the code asking what the plan owes on every pass. Its answer stands in the band. A failed
656
+ // answer is no answer, so that question is asked again, as finishing the run would ask it.
657
+ //
658
+ // AN ANSWER STANDS ONLY FOR THE QUESTION IT ANSWERED. The plan is written again on every pass from the framed names,
659
+ // and a name's own questions keep their ids when the frame changes their words or classes. So each block records
660
+ // what was sent for it (`sent`), and a held answer stands only where the question now sends exactly that. A block
661
+ // that records nothing of what was sent cannot show it answered this question, so the question is asked again.
662
+ const answered = new Map(band.filter((b) => b?.qid && b.error !== true).map((b) => [String(b.qid), b]));
663
+ const holds = (e) => answered.get(String(e.qid))?.sent === sentKey(e);
664
+ const held = asked.filter(holds);
665
+ const entries = asked.filter((e) => !holds(e));
666
+ const states = Object.fromEntries(held.map((e) => [e.qid, answered.get(String(e.qid)).state ?? "held"]));
667
+ if (!entries.length) return { type: "text", text: JSON.stringify({ skipped: [], held: held.map((e) => e.qid), states }) };
668
+ const owned = new Set(entries.map((e) => String(e.qid)));
669
+ const blocks = [];
651
670
  for (const e of entries) {
652
- const terms = Array.isArray(e?.terms) ? e.terms : [e?.term];
653
- const base = { qid: e.qid, query: { term: e.term ?? null, terms: e.terms ?? null, predicate: e.predicate ?? null } };
671
+ const base = { qid: e.qid, query: { term: e.term ?? null, terms: e.terms ?? null, predicate: e.predicate ?? null }, sent: sentKey(e) };
654
672
  const rows = [];
655
673
  const seen = new Set();
656
674
  const warnings = [];
657
675
  let total = 0;
658
676
  let failure = null;
659
677
  if (e?.unsupported) failure = String(e.unsupported_reason ?? "this register cannot express this question");
660
- for (const t of failure ? [] : terms) {
678
+ for (const { term: t, ...asks } of failure ? [] : sentFor(e)) {
661
679
  let r;
662
680
  try {
663
- r = await lister(t, { classes: sameClasses(e.nice_classes) ? [] : (e.nice_classes ?? []), regions: e.regions ?? [],
664
- matchMode: MATCH_MODES[e?.predicate] ?? "default", goods: e.goods_text ?? null, scoped: true });
681
+ r = await lister(t, asks);
665
682
  } catch (err) { r = { ok: false, reason: `record listing threw: ${String(err?.message ?? err).slice(0, 200)}` }; }
666
683
  if (!r?.ok || !Array.isArray(r?.records)) { failure = String(r?.reason ?? "the question was not answered"); break; }
667
684
  total += Number.isFinite(r.total) ? r.total : r.records.length;
@@ -685,7 +702,7 @@ export async function executeQuestionsWithLister(lister, { plan_path: planPath,
685
702
  mkdirSync(dirname(outputPath), { recursive: true });
686
703
  writeFileSync(`${outputPath}.tmp`, JSON.stringify([...band.filter((b) => !owned.has(String(b?.qid))), ...blocks], null, 2) + "\n");
687
704
  renameSync(`${outputPath}.tmp`, outputPath);
688
- return { type: "text", text: JSON.stringify({ skipped: [], states }) };
705
+ return { type: "text", text: JSON.stringify({ skipped: [], ...(held.length ? { held: held.map((e) => e.qid) } : {}), states }) };
689
706
  }
690
707
 
691
708
  /**
@@ -17,9 +17,9 @@ import { existsSync, readFileSync, writeFileSync } from "node:fs";
17
17
  import { basename, dirname, join } from "node:path";
18
18
 
19
19
  import { captureCall, stampVerdict } from "./call-capture.mjs";
20
- import { DRIVER_DIR, driverDir } from "../shared/driver-dir.mjs";
21
20
  import { refuseUndeclared, lastAccepted, acceptedEnvelope } from "./preserve-merge.mjs";
22
21
  import { addedClassQuestions, carriedIds, formQid, formsOfName, knockoutBandBlocks, knockoutProposals, namesAddedClass, openingQid, questionsOwed } from "./knockout-register-read.mjs";
22
+ import { DRIVER_DIR, paths as runPaths, readJsonOrNull } from "./run-record.mjs";
23
23
 
24
24
  const TOKEN = "knockoutregisterread";
25
25
  const SCHEMA_VERSION = 1;
@@ -37,7 +37,7 @@ export const knockoutRegisterFile = (runDir) => join(String(runDir ?? ""), "knoc
37
37
 
38
38
  /** One file per call, refusals included, beside the other transports' capture directories. */
39
39
  export function knockoutRegisterCallPaths(runDir) {
40
- const dir = driverDir(runDir, "knockout-register-calls");
40
+ const dir = runPaths(runDir).knockoutRegisterCalls;
41
41
  return { dir, accepted: join(dir, "accepted.json"), refusals: join(dir, "refusals.jsonl") };
42
42
  }
43
43
 
@@ -85,7 +85,6 @@ export function acceptKnockoutRegister(call) {
85
85
  return { ok: true, model: { schema_version: SCHEMA_VERSION, marks } };
86
86
  }
87
87
 
88
- const readJson = (path) => { try { return JSON.parse(readFileSync(path, "utf8")); } catch { return null; } };
89
88
 
90
89
  /** Why one name's row cannot stand against what this run holds, or null. The record says what the step decided; this checks only that it adds up. */
91
90
  function rowDefect(row, n, { counts, plan, runDir }) {
@@ -131,12 +130,12 @@ function rowDefect(row, n, { counts, plan, runDir }) {
131
130
  * `standing` is the rows that hold whatever the verdict on the others.
132
131
  */
133
132
  export function checkKnockoutRegisterAgainstRun(model, runDir) {
134
- const scope = readJson(driverDir(runDir, "instructed-scope.json"));
133
+ const scope = readJsonOrNull(runPaths(runDir).instructedScope);
135
134
  const instructed = (Array.isArray(scope?.marks) ? scope.marks : []).map((n) => String(n));
136
135
  if (!instructed.length) return { ok: false, standing: [], reason: `${TOKEN}_scope: the run's instructed scope could not be read, so the names cannot be checked.` };
137
136
  const byName = new Map(model.marks.map((m) => [nameKey(m.name), m]));
138
137
  const known = new Set(instructed.map(nameKey));
139
- const context = { counts: readJson(driverDir(runDir, "register-counts.json")), plan: readJson(join(runDir, "knockout-plan.json")), runDir };
138
+ const context = { counts: readJsonOrNull(runPaths(runDir).registerCounts), plan: readJsonOrNull(join(runDir, "knockout-plan.json")), runDir };
140
139
  const defects = model.marks.filter((m) => !known.has(nameKey(m.name))).map((m) => `${TOKEN}_names: "${m.name}" is not an instructed name. Names verbatim from the instructed scope.`);
141
140
  const missing = instructed.filter((n) => !byName.has(nameKey(n)));
142
141
  if (missing.length) defects.push(`${TOKEN}_names: no row for ${missing.map((n) => `"${n}"`).join(", ")}. Send one row per instructed name.`);
@@ -168,7 +167,7 @@ export function validateKnockoutRegisterFile(file, content) {
168
167
  if (!shape.ok) return shape;
169
168
  const dir = dirname(file);
170
169
  const runDir = basename(dir) === DRIVER_DIR ? dirname(dir) : dir;
171
- if (!existsSync(driverDir(runDir, "instructed-scope.json"))) return { ok: false, reason: "the run's instructed scope is not on disk, so this record cannot be checked." };
170
+ if (!existsSync(runPaths(runDir).instructedScope)) return { ok: false, reason: "the run's instructed scope is not on disk, so this record cannot be checked." };
172
171
  return checkKnockoutRegisterAgainstRun(shape.model, runDir);
173
172
  }
174
173
 
@@ -43,7 +43,6 @@
43
43
  // its own accepted call, bound by the ordinal in its label, so nothing the first pass sent carries into it.
44
44
  import { writeFileSync, readFileSync, existsSync } from "node:fs";
45
45
  import { join, dirname, basename } from "node:path";
46
- import { driverDir, DRIVER_DIR } from "../shared/driver-dir.mjs";
47
46
  import { captureCall, stampVerdict } from "./call-capture.mjs";
48
47
  import { refuseUndeclared as refuseUndeclaredShared, lastAccepted, acceptedEnvelope } from "./preserve-merge.mjs";
49
48
  import { knockoutVisibleProse } from "./predelivery-lint.mjs"; // the walk is the authority on what a reader sees
@@ -52,6 +51,7 @@ import { plainRegisterFlags } from "./plain-register.mjs"; // the pinned
52
51
  // for saying WHICH line was probably meant; it never decides whether an address resolves.
53
52
  import { queryKey } from "./connotation-search.mjs";
54
53
  import { PERMITTED_SOURCES, registerRecordIdsHeld, urlHeldFor } from "./verify-knockout.mjs";
54
+ import { DRIVER_DIR, driverDir, paths as runPaths, readJson } from "./run-record.mjs";
55
55
 
56
56
  const SCHEMA_VERSION = 1;
57
57
 
@@ -115,7 +115,7 @@ export const MATERIAL_KINDS = Object.freeze({ band: false, missing: true, exclus
115
115
 
116
116
  /** One file per call, refusals included, beside the other transports' capture directories. A later pass keeps its own. */
117
117
  export function knockoutReviewCallPaths(runDir, pass = 0) {
118
- const dir = pass ? driverDir(runDir, join("knockout-review-calls", `pass-${Number(pass)}`)) : driverDir(runDir, "knockout-review-calls");
118
+ const dir = pass ? driverDir(runDir, join("knockout-review-calls", `pass-${Number(pass)}`)) : runPaths(runDir).knockoutReviewCalls;
119
119
  return { dir, accepted: join(dir, "accepted.json"), refusals: join(dir, "refusals.jsonl") };
120
120
  }
121
121
 
@@ -413,7 +413,7 @@ export function validateKnockoutReviewFile(file, text) {
413
413
  return { ok: false, reason: `the merged record is not on disk at ${findingsFile}, so no address could be checked` };
414
414
  }
415
415
  let merged;
416
- try { merged = JSON.parse(readFileSync(findingsFile, "utf8")); }
416
+ try { merged = readJson(findingsFile); }
417
417
  catch (e) { return { ok: false, reason: `the merged record will not parse, so no address could be checked: ${e.message}` }; }
418
418
  const fault = joinFault(doc, merged, runDir);
419
419
  return fault ? { ok: false, reason: fault } : { ok: true };
@@ -457,20 +457,21 @@ function materialFault(m, merged, runDir) {
457
457
  // one name. A question the run asked is held too, by its qid. Anything else is refused, in words about those sources and not the run.
458
458
  const records = registerRecordIdsHeld(runDir);
459
459
  let questions = new Set();
460
- try { questions = new Set((JSON.parse(readFileSync(driverDir(runDir, "register-records.json"), "utf8")).marks ?? []).flatMap((e) => (e?.terms ?? []).map((t) => String(t?.qid ?? "")))); } catch { questions = new Set(); }
460
+ try { questions = new Set((readJson(runPaths(runDir).registerRecords).marks ?? []).flatMap((e) => (e?.terms ?? []).map((t) => String(t?.qid ?? "")))); } catch { questions = new Set(); }
461
461
  const urlHeld = urlHeldFor(runDir);
462
462
  const stranger = (m.rests_on ?? []).find((r) => !records.has(r) && !questions.has(r) && !urlHeld(r));
463
463
  return stranger ? `the material row on "${m.mark}" rests on "${stranger}", which is not traceable to ${PERMITTED_SOURCES}, or a question this run asked. Copy a recordId, question qid, or URL from what this run holds.` : null;
464
464
  }
465
465
 
466
466
  /**
467
- * The rewrites of a first pass that still have a line to land on after a correction: those on a name no defect named, and the
468
- * standing caveats. A corrected name is renumbered and reworded, and the batch summary with it, so the second pass reads those
469
- * afresh. PURE.
467
+ * The rewrites of a first pass that still have a line to land on after a correction: those on a name the correction did not
468
+ * change, and the standing caveats. A changed name, whether a defect named it or the correction reached it, is renumbered and
469
+ * reworded, and the batch summary with it, so the second pass reads those afresh. `changedNames` null means the correction's
470
+ * reach could not be compared: no rewrite on a name is taken to be independent of it, and only the caveats stand. PURE.
470
471
  */
471
- export function rewritesThatSurvive(review, correctedNames) {
472
- const corrected = new Set([...correctedNames].map((n) => String(n ?? "").trim().toLowerCase()));
473
- const stands = (r) => r?.at?.field === "batch.standardCaveats" || (r?.at?.mark != null && !corrected.has(String(r.at.mark).trim().toLowerCase()));
472
+ export function rewritesThatSurvive(review, changedNames) {
473
+ const corrected = changedNames == null ? null : new Set([...changedNames].map((n) => String(n ?? "").trim().toLowerCase()));
474
+ const stands = (r) => r?.at?.field === "batch.standardCaveats" || (corrected != null && r?.at?.mark != null && !corrected.has(String(r.at.mark).trim().toLowerCase()));
474
475
  return { ...review, rewrites: (review?.rewrites ?? []).filter(stands) };
475
476
  }
476
477
 
@@ -581,7 +582,7 @@ export function recordKnockoutReview(runDir, received, { boundOrdinal = null, no
581
582
  }
582
583
 
583
584
  // Where the record is on disk the seat hears the join now, in its turn. Where it is not, the stage's own check says it could not look.
584
- const held = (() => { try { return JSON.parse(readFileSync(join(dir, "knockout-findings.json"), "utf8")); } catch { return null; } })();
585
+ const held = (() => { try { return readJson(join(dir, "knockout-findings.json")); } catch { return null; } })();
585
586
  const fault = held ? joinFault(verdict.model, held, dir) : null;
586
587
  if (fault) {
587
588
  journal(fault);
@@ -0,0 +1,88 @@
1
+ // SPDX-License-Identifier: AGPL-3.0-only
2
+ // Copyright 2026 Cordillera Sàrl. Additional terms under section 7 of the AGPL-3.0 apply — see ADDITIONAL-TERMS.md
3
+ // model-gauge.mjs — which model a turn asked for, which one the wire says served it, and which program ran it.
4
+ //
5
+ // The stage ladder (gateway.mjs runStageLadder) writes these on every attempt row and run event, and fails a turn
6
+ // whose model the wire contradicts (turn-failure.mjs nameTheFailure). Both functions read the turn and the
7
+ // machine and change nothing.
8
+
9
+ import { modelFamily, modelSnapshotKind, preflightEngineBinary, olderThanFloor, ENGINE_BINARIES } from "../driver.config.mjs";
10
+ import { probeCliVersion } from "../engine/cli-version.mjs";
11
+ import { modelIdOf } from "../engine/registry.mjs";
12
+
13
+ // ── corruption 3 — WHAT WAS ASKED FOR vs WHAT ACTUALLY RAN ─────────────────────────────────
14
+ //
15
+ // Until this landed, every model figure on every record was a pure function of the REQUESTED alias:
16
+ // `resolveModel(model)` / `engine.resolveModelId(model)`, computed here without ever looking at the
17
+ // provider's answer. So `--model gemini` logged `google/gemini-3.1-pro-preview` and ran sonnet (the
18
+ // engine's alias table substituted, silently), a haiku stage that bounced to sonnet logged haiku,
19
+ // and every attribution downstream — the A/B arm's manifest, tokens.mjs' per-model rollup, the
20
+ // billing classes — was keyed to a model that had not run. Patching the log would not have fixed
21
+ // it; the log was already saying what the code believed.
22
+ //
23
+ // TWO FIELDS, NEVER COLLAPSED INTO ONE:
24
+ // modelUsed — the requested resolution, unchanged in meaning and value: run-economics.mjs and
25
+ // tokens.mjs both read it, and a field that quietly changes meaning is its own corruption.
26
+ // modelActual — the id the WIRE reported (engine tuple `modelWire`), or NULL when the stream never
27
+ // said: an engine that does not emit one (codex), a turn killed before any event, a
28
+ // spawn error. It NEVER falls back to the requested alias, and `modelBasis` ("actual" or
29
+ // "unknown") never dresses a requested value as an observed one. `providerReported` is
30
+ // the provider word the same stream gave (tuple `providerWire`), null on the same terms.
31
+ export function modelGauge(engine, model, turn) {
32
+ const modelRequested = modelIdOf(engine, model);
33
+ const modelActual = (typeof turn.modelWire === "string" && turn.modelWire) ? turn.modelWire : null;
34
+ const modelBasis = modelActual ? "actual" : "unknown";
35
+ const providerReported = (typeof turn.providerWire === "string" && turn.providerWire) ? turn.providerWire : null;
36
+ // WHETHER THE OBSERVED ID NAMES A FIXED BUILD. `modelBasis: "actual"` says the provider answered,
37
+ // not that the answer is pinned: two of the three tiers come back as undated aliases the provider
38
+ // may repoint, and recorded beside a dated one they read identically. null when there is nothing to
39
+ // judge, never collapsed into "alias".
40
+ const modelSnapshot = modelSnapshotKind(modelActual);
41
+ // The comparison is by FAMILY (driver.config modelFamily), because `--model haiku` legitimately comes
42
+ // back as `claude-haiku-4-5-20251001`. THREE-VALUED: null when either side names no family this
43
+ // build recognises — an unknown is recorded as unknown and never as agreement.
44
+ const famRequested = modelFamily(modelRequested), famActual = modelFamily(modelActual);
45
+ const modelMismatch = (famRequested && famActual) ? famRequested !== famActual : null;
46
+ return { modelRequested, modelActual, modelBasis, providerReported, modelSnapshot, famRequested, famActual, modelMismatch };
47
+ }
48
+
49
+ // WHICH BUILD OF THE TOOL SERVED THIS TURN. `modelSnapshot` above answers "did the model move";
50
+ // this answers "did the tool move", and the two have one symptom — a run whose judgment differs from
51
+ // last week's. Captured at dispatch rather than read back afterwards, because the binary a reader
52
+ // could probe later is not necessarily the one that ran.
53
+ //
54
+ // Written as an object with its own `probe` field, so an unreadable version is a RECORDED state
55
+ // rather than a missing one. Omitting it on failure would collapse "asked and could not say" into
56
+ // "written before anybody asked", which is the distinction the field exists for. One spawn per
57
+ // binary per process; a probe never throws, because taking down a dispatch to record a version
58
+ // would be a worse defect than the gap it closes.
59
+ // `source` says WHICH copy served (explicit / path / installed), and it is attached here, outside the
60
+ // probe's cache: that cache is keyed by the file, and one file can be reached by more than one route.
61
+ export function servingProgram() {
62
+ try {
63
+ const pre = preflightEngineBinary(process.env);
64
+ const probed = probeCliVersion(pre?.resolved ?? null);
65
+ // ── THE FLOOR, COMPARED WHERE THE RUN CAN SEE IT ────────────────────────────────────────
66
+ //
67
+ // The build declares a minimum version for each engine's program, and until now nothing
68
+ // compared a running copy against it. The floor was passed to the installer, so a copy this
69
+ // product installs cannot land beneath it — but resolution walks PATH first and takes the
70
+ // first hit, so a copy already on the machine wins and was never measured against anything.
71
+ // That is the common case, not the edge one: most machines have their own copy. A stage then
72
+ // runs on a program below the floor and is served whatever that program serves, silently.
73
+ //
74
+ // RECORDED, NOT REFUSED. Refusing here would stop every run on any machine whose copy is
75
+ // behind — including ones already deployed and working — and that is a decision about those
76
+ // deployments rather than a defect fix. What was missing is the fact, so the fact is what is
77
+ // written: an operator, and anyone reading the run afterwards, can now see it. Whether it
78
+ // should also refuse is a separate question and is not answered here.
79
+ //
80
+ // THREE-VALUED and written unconditionally, like the model fields below: true, false, or null
81
+ // when either side names no version this build can compare — an unknown is an unknown, never
82
+ // an all-clear. The floor itself rides along so the record says what it was measured against
83
+ // rather than leaving a later reader to guess which build's floor applied.
84
+ const floor = ENGINE_BINARIES[pre?.engine]?.floor ?? null;
85
+ const belowFloor = floor ? olderThanFloor(probed?.version ?? null, floor) : null;
86
+ return { ...probed, source: pre?.source ?? null, floor, belowFloor };
87
+ } catch (e) { return { version: null, probe: "unreadable", why: String(e?.message ?? e).slice(0, 160), source: null, floor: null, belowFloor: null }; }
88
+ }