clearotron 0.5.1 → 0.6.0-beta.0

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 (379) 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 +49 -18
  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 +60 -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/best-draft.mjs +3 -3
  37. package/driver/blind-frame-record.mjs +2 -2
  38. package/driver/cancel.mjs +3 -2
  39. package/driver/carry-through.mjs +2 -2
  40. package/driver/citation-census.json +3 -3
  41. package/driver/clearance-variants-record.mjs +4 -10
  42. package/driver/common-law-coverage-status.mjs +3 -3
  43. package/driver/common-law-receipts.mjs +2 -2
  44. package/driver/compare.mjs +1 -1
  45. package/driver/config-inventory.mjs +6 -79
  46. package/driver/consumption-ledger.mjs +2 -1
  47. package/driver/contract-dictation-registry.mjs +5 -0
  48. package/driver/contract-e3-backlog.mjs +45 -66
  49. package/driver/contract-e3-baseline.json +16 -16
  50. package/driver/contract-vocabulary.mjs +8 -6
  51. package/driver/corrections-feedforward.mjs +3 -1
  52. package/driver/coverage-form-io.mjs +7 -8
  53. package/driver/coverage-tool.mjs +1 -1
  54. package/driver/declination-tool.mjs +2 -2
  55. package/driver/degraded-parts.mjs +9 -9
  56. package/driver/demo-container.mjs +5 -4
  57. package/driver/deploy-live-run-guard.mjs +19 -7
  58. package/driver/derived-state.mjs +2 -2
  59. package/driver/dev-portal.mjs +2 -1
  60. package/driver/dispatch-record.mjs +1 -1
  61. package/driver/disposition-tool.mjs +2 -1
  62. package/driver/doubt-closure-tool.mjs +2 -2
  63. package/driver/driver.config.mjs +35 -724
  64. package/driver/e2e-rounds.mjs +3 -4
  65. package/driver/engine/CONTRACT.md +3 -0
  66. package/driver/engine/README.md +2 -0
  67. package/driver/engine/anthropic-agent.mjs +8 -37
  68. package/driver/engine/auth.mjs +74 -0
  69. package/driver/engine/child-record.mjs +1 -1
  70. package/driver/engine/deny-authority-write.mjs +2 -2
  71. package/driver/engine/jx-turn.mjs +10 -2
  72. package/driver/engine/mcp/README.md +1 -1
  73. package/driver/engine/mcp/band-server.mjs +6 -6
  74. package/driver/engine/mcp/codex-config.mjs +1 -1
  75. package/driver/engine/mcp/declination-server.mjs +2 -3
  76. package/driver/engine/mcp/dispositions-server.mjs +3 -3
  77. package/driver/engine/mcp/gather-config.mjs +24 -19
  78. package/driver/engine/mcp/grid-provenance.mjs +1 -1
  79. package/driver/engine/mcp/held-answers.mjs +5 -5
  80. package/driver/engine/mcp/perplexity-server.mjs +16 -7
  81. package/driver/engine/mcp/recording-server.mjs +7 -6
  82. package/driver/engine/mcp/register-server.mjs +29 -0
  83. package/driver/engine/mcp/stdio-server.mjs +5 -5
  84. package/driver/engine/mcp/supplemental.mjs +9 -9
  85. package/driver/engine/openai-agent.mjs +5 -2
  86. package/driver/engine/registry.mjs +103 -0
  87. package/driver/engine/run-choices.mjs +162 -0
  88. package/driver/engine/stamps.mjs +35 -0
  89. package/driver/enqueue-schema.mjs +4 -4
  90. package/driver/envelope-settle.mjs +3 -2
  91. package/driver/feedback-issues.mjs +1 -1
  92. package/driver/feedback-mint.mjs +3 -2
  93. package/driver/feedback-store.mjs +3 -2
  94. package/driver/findings-model.mjs +1 -1
  95. package/driver/flag-snapshot.mjs +5 -4
  96. package/driver/floor-duty.mjs +3 -3
  97. package/driver/foreign-record-links.mjs +1 -1
  98. package/driver/frame-diff-record.mjs +2 -8
  99. package/driver/framework.mjs +1 -1
  100. package/driver/gate-metrics.mjs +10 -11
  101. package/driver/gateway.mjs +220 -839
  102. package/driver/goods-evidence.mjs +10 -6
  103. package/driver/jx-lanes.mjs +3 -3
  104. package/driver/jx-units.mjs +31 -37
  105. package/driver/jx.mjs +44 -59
  106. package/driver/knockout-assess-record.mjs +3 -3
  107. package/driver/knockout-caveats.mjs +21 -0
  108. package/driver/knockout-correction-record.mjs +58 -28
  109. package/driver/knockout-frame-record.mjs +2 -2
  110. package/driver/knockout-register-read.mjs +38 -21
  111. package/driver/knockout-register-record.mjs +5 -6
  112. package/driver/knockout-review-record.mjs +12 -11
  113. package/driver/ladder/model-gauge.mjs +88 -0
  114. package/driver/ladder/next-rung.mjs +296 -0
  115. package/driver/ladder/rescue.mjs +146 -0
  116. package/driver/ladder/stage-tools.mjs +57 -0
  117. package/driver/ladder/turn-failure.mjs +166 -0
  118. package/driver/log.mjs +2 -2
  119. package/driver/matter-frame-record.mjs +4 -4
  120. package/driver/methodology-witness.mjs +2 -2
  121. package/driver/narrative-refutation-record.mjs +145 -42
  122. package/driver/one-build-per-run.mjs +62 -0
  123. package/driver/outbox-backoff.mjs +4 -4
  124. package/driver/owner-screen.mjs +0 -10
  125. package/driver/owner-use-check.mjs +2 -28
  126. package/driver/package.json +1 -1
  127. package/driver/partial-payload-baseline.json +1 -1
  128. package/driver/parts-not-completed.mjs +1 -1
  129. package/driver/pipeline-knockout.mjs +1015 -1001
  130. package/driver/pipeline.mjs +511 -9265
  131. package/driver/placement-decisions.mjs +2 -2
  132. package/driver/placement-form-io.mjs +7 -9
  133. package/driver/placement-union.mjs +0 -6
  134. package/driver/plan-stability.mjs +7 -10
  135. package/driver/portal-acks.mjs +3 -2
  136. package/driver/portal-confirmation.mjs +48 -0
  137. package/driver/portal-families.mjs +3 -2
  138. package/driver/portal-local-auth.mjs +1 -2
  139. package/driver/portal-routes/README.md +24 -0
  140. package/driver/portal-routes/admin.mjs +425 -0
  141. package/driver/portal-routes/compose.mjs +66 -0
  142. package/driver/portal-routes/config.mjs +118 -0
  143. package/driver/portal-routes/connect.mjs +283 -0
  144. package/driver/portal-routes/feedback.mjs +178 -0
  145. package/driver/portal-routes/me.mjs +165 -0
  146. package/driver/portal-routes/queue.mjs +64 -0
  147. package/driver/portal-routes/report.mjs +106 -0
  148. package/driver/portal-routes/run.mjs +508 -0
  149. package/driver/portal-routes/runs.mjs +127 -0
  150. package/driver/portal-routes/usage.mjs +82 -0
  151. package/driver/portal-runs.mjs +588 -0
  152. package/driver/portal-service.mjs +78 -2592
  153. package/driver/portal-static.mjs +3 -1
  154. package/driver/predelivery-lint.mjs +92 -9
  155. package/driver/production-pool-guard.mjs +1 -1
  156. package/driver/profiles.mjs +5 -4
  157. package/driver/progress.mjs +29 -24
  158. package/driver/publish/README.md +10 -5
  159. package/driver/publish/archive-tags.mjs +3 -2
  160. package/driver/publish/demo-marking.mjs +2 -2
  161. package/driver/publish/index.mjs +215 -140
  162. package/driver/publish/knockout.mjs +153 -107
  163. package/driver/publish/office-record-links.mjs +22 -0
  164. package/driver/publish/parse.mjs +20 -5
  165. package/driver/publish/pool-admin.mjs +9 -3
  166. package/driver/publish/render.mjs +11 -3
  167. package/driver/publish/report-dates.mjs +3 -4
  168. package/driver/publish/report-registry.mjs +7 -10
  169. package/driver/publish/seed-pool.mjs +3 -2
  170. package/driver/publish/shell.mjs +106 -0
  171. package/driver/publish/templates/report.css +3 -1
  172. package/driver/queue-order.mjs +4 -3
  173. package/driver/record-carry.mjs +0 -9
  174. package/driver/record-discard.mjs +1 -4
  175. package/driver/record-fold.mjs +3 -3
  176. package/driver/record-goods.mjs +5 -5
  177. package/driver/reference-score.mjs +2 -3
  178. package/driver/register-capabilities.mjs +0 -6
  179. package/driver/register-count.mjs +3 -2
  180. package/driver/register-digest-record.mjs +7 -7
  181. package/driver/register-fixture-marker.mjs +3 -3
  182. package/driver/register-plan.mjs +2 -2
  183. package/driver/register-records.mjs +2 -2
  184. package/driver/register-taint.mjs +3 -3
  185. package/driver/register-unit-record.mjs +48 -9
  186. package/driver/register-unreachable.mjs +4 -3
  187. package/driver/registry-fidelity.mjs +79 -34
  188. package/driver/repair-composers.mjs +14 -9
  189. package/driver/repair-digest.mjs +4 -6
  190. package/driver/repair-scope.mjs +3 -3
  191. package/driver/repair-targets.mjs +24 -9
  192. package/driver/repairs.mjs +44 -58
  193. package/driver/replay-archive.mjs +7 -7
  194. package/driver/report-card-record.mjs +3 -3
  195. package/driver/report-overview-record.mjs +4 -4
  196. package/driver/research-answers.mjs +38 -6
  197. package/driver/research-checks.mjs +4 -4
  198. package/driver/result-noun-fields.mjs +28 -11
  199. package/driver/review-addresses.mjs +163 -0
  200. package/driver/rule-shape.mjs +1 -1
  201. package/driver/run-delivered.mjs +340 -0
  202. package/driver/run-economics.mjs +8 -26
  203. package/driver/run-failed.mjs +545 -0
  204. package/driver/run-integrity.mjs +1 -1
  205. package/driver/run-outcome.mjs +314 -0
  206. package/driver/run-park.mjs +23 -0
  207. package/driver/run-quote.mjs +32 -0
  208. package/driver/run-record.mjs +352 -0
  209. package/driver/run-requirements.mjs +22 -0
  210. package/driver/run-shell.mjs +55 -0
  211. package/driver/runner.mjs +71 -33
  212. package/driver/saved-register-pages.mjs +4 -4
  213. package/driver/score-redaction.mjs +2 -2
  214. package/driver/search-policy.mjs +12 -13
  215. package/driver/settle-stamp.mjs +4 -3
  216. package/driver/skeptic-record.mjs +2 -2
  217. package/driver/skeptic-search.mjs +1 -1
  218. package/driver/skills/README.md +7 -7
  219. package/driver/skills/blind-frame/SKILL.md +1 -2
  220. package/driver/skills/case-law-citation/SKILL.md +9 -37
  221. package/driver/skills/case-law-citation/sources/courtlistener.md +1 -3
  222. package/driver/skills/case-law-citation/sources/eurlex.md +8 -11
  223. package/driver/skills/case-law-citation/sources/legaldatahunter.md +1 -1
  224. package/driver/skills/clearance-common-law/SKILL.md +45 -111
  225. package/driver/skills/clearance-common-law/perplexity-prompts.md +7 -79
  226. package/driver/skills/clearance-register/SKILL.md +15 -33
  227. package/driver/skills/clearance-register/digest.md +31 -92
  228. package/driver/skills/clearance-register/providers/clarivate.md +2 -2
  229. package/driver/skills/clearance-register/providers/corsearch.md +5 -5
  230. package/driver/skills/clearance-register/providers/euipo.md +1 -2
  231. package/driver/skills/clearance-register/providers/free-tier.md +0 -19
  232. package/driver/skills/clearance-register/providers/signa.md +6 -25
  233. package/driver/skills/clearance-register/providers/uspto-local.md +0 -24
  234. package/driver/skills/clearance-register/register-recipes.md +8 -15
  235. package/driver/skills/clearance-register/status-rules.md +6 -24
  236. package/driver/skills/clearance-register/unit.md +11 -20
  237. package/driver/skills/clearance-search/delivery-contract.md +24 -120
  238. package/driver/skills/clearance-search/field-doctrine-pharma.md +1 -5
  239. package/driver/skills/clearance-search/firm-wide-reasoning.md +24 -43
  240. package/driver/skills/clearance-search/phase2-execution.md +29 -77
  241. package/driver/skills/clearance-search/report-prose.md +3 -4
  242. package/driver/skills/clearance-search/risk-framework-demo.md +1 -1
  243. package/driver/skills/clearance-search/risk-framework-triage.manifest.json +3 -3
  244. package/driver/skills/clearance-search/risk-framework-triage.md +7 -9
  245. package/driver/skills/clearance-search/risk-framework.manifest.json +1 -1
  246. package/driver/skills/clearance-search/risk-framework.md +1 -1
  247. package/driver/skills/clearance-search/synthesis-rules.md +30 -107
  248. package/driver/skills/clearance-search/worked-examples.md +5 -5
  249. package/driver/skills/clearance-variants/SKILL.md +46 -45
  250. package/driver/skills/clearance-variants/transliteration-scripts.md +4 -4
  251. package/driver/skills/frame-diff/SKILL.md +1 -1
  252. package/driver/skills/knockout-assess/SKILL.md +6 -14
  253. package/driver/skills/knockout-frame/SKILL.md +1 -1
  254. package/driver/skills/matter-frame/SKILL.md +7 -12
  255. package/driver/skills/matter-frame/watchlist-reference.md +1 -4
  256. package/driver/skills/narrative-refutation/SKILL.md +20 -30
  257. package/driver/skills/placement-inquiry/SKILL.md +8 -18
  258. package/driver/skills-store-provenance.mjs +1 -1
  259. package/driver/stage-context.mjs +32 -35
  260. package/driver/stage-freshness.mjs +127 -11
  261. package/driver/stages-knockout.mjs +49 -22
  262. package/driver/stages.mjs +88 -283
  263. package/driver/status-snapshot.mjs +2 -1
  264. package/driver/steps/correction-cycle.mjs +311 -0
  265. package/driver/steps/corrections.mjs +644 -0
  266. package/driver/steps/delivery.mjs +1287 -0
  267. package/driver/steps/frame-comparison.mjs +922 -0
  268. package/driver/steps/intake.mjs +84 -0
  269. package/driver/steps/open-run.mjs +419 -0
  270. package/driver/steps/overview-and-cards.mjs +899 -0
  271. package/driver/steps/placement-and-digest.mjs +23 -0
  272. package/driver/steps/register-sweep.mjs +1563 -0
  273. package/driver/steps/skeptic-and-follow-up.mjs +831 -0
  274. package/driver/steps/synthesis.mjs +261 -0
  275. package/driver/steps/verdict-gate.mjs +968 -0
  276. package/driver/suite-census.json +403 -91
  277. package/driver/surface-exit-verdict.mjs +0 -8
  278. package/driver/synthesis-record.mjs +72 -6
  279. package/driver/terminal-clamp.mjs +10 -0
  280. package/driver/tokens.mjs +8 -62
  281. package/driver/tool-calls.mjs +2 -2
  282. package/driver/unit-state-verdict.mjs +1 -1
  283. package/driver/usage-ledger.mjs +2 -1
  284. package/driver/verify-knockout.mjs +20 -35
  285. package/driver/verify.mjs +47 -36
  286. package/driver/web-grid.mjs +3 -4
  287. package/driver/whatif-memo-run.mjs +2 -2
  288. package/driver/whatif-queue.mjs +4 -3
  289. package/driver/withheld-families.mjs +14 -15
  290. package/driver/worker-heartbeat.mjs +3 -2
  291. package/driver/write-up-form.mjs +0 -3
  292. package/mcp-server/CHANGELOG.md +4 -0
  293. package/mcp-server/http-server.mjs +1 -1
  294. package/mcp-server/lib/brief.mjs +22 -4
  295. package/mcp-server/lib/events.mjs +2 -2
  296. package/mcp-server/lib/evidence.mjs +3 -2
  297. package/mcp-server/lib/findings.mjs +2 -1
  298. package/mcp-server/lib/knockout.mjs +9 -10
  299. package/mcp-server/lib/ops.mjs +9 -9
  300. package/mcp-server/lib/runs.mjs +9 -10
  301. package/mcp-server/lib/trace.mjs +1 -1
  302. package/mcp-server/lib/whatif.mjs +2 -3
  303. package/mcp-server/package.json +1 -1
  304. package/mcp-server/server.mjs +5 -5
  305. package/package.json +2 -1
  306. package/portal-ui/dist/assets/{index-fPqAU0sx.js → index-D5rkCjDc.js} +26 -14
  307. package/portal-ui/dist/index.html +1 -1
  308. package/portal-ui/package.json +3 -3
  309. package/providers/README.md +1 -1
  310. package/providers/_shared/answer-memory.mjs +4 -5
  311. package/providers/_shared/execute-plan.mjs +48 -1
  312. package/providers/_shared/records-from-search.mjs +46 -0
  313. package/providers/clarivate/README.md +2 -2
  314. package/providers/clarivate/src/adapter.js +147 -0
  315. package/providers/clarivate/src/core.js +1 -14
  316. package/{driver/engine/mcp/clarivate-server.mjs → providers/clarivate/src/mount.js} +5 -10
  317. package/providers/corsearch/README.md +3 -3
  318. package/providers/corsearch/src/adapter.js +80 -0
  319. package/providers/corsearch/src/core.js +14 -11
  320. package/{driver/engine/mcp/corsearch-server.mjs → providers/corsearch/src/mount.js} +5 -10
  321. package/providers/euipo/README.md +2 -2
  322. package/providers/euipo/src/adapter.js +85 -0
  323. package/providers/euipo/src/core.js +1 -1
  324. package/providers/euipo/src/euipo-client.js +1 -2
  325. package/{driver/engine/mcp/euipo-server.mjs → providers/euipo/src/mount.js} +5 -10
  326. package/providers/free-tier/README.md +2 -2
  327. package/providers/free-tier/src/adapter.js +127 -0
  328. package/{driver/engine/mcp/free-tier-server.mjs → providers/free-tier/src/mount.js} +5 -10
  329. package/providers/jx-subclass/coverage.mjs +1 -6
  330. package/providers/jx-subclass/score-truth.mjs +2 -1
  331. package/providers/oauth-mcp-bridge/CHANGELOG.md +4 -0
  332. package/providers/oauth-mcp-bridge/package.json +1 -1
  333. package/providers/perplexity/src/core.js +2 -2
  334. package/providers/signa/README.md +2 -2
  335. package/providers/signa/src/adapter.js +157 -0
  336. package/providers/signa/src/capabilities.js +0 -3
  337. package/providers/signa/src/core.js +2 -2
  338. package/{driver/engine/mcp/signa-server.mjs → providers/signa/src/mount.js} +7 -12
  339. package/providers/signa/src/offices.generated.js +17 -15
  340. package/providers/uspto-local/README.md +1 -1
  341. package/providers/uspto-local/bin/verify-index.mjs +1 -1
  342. package/providers/uspto-local/src/adapter.js +75 -0
  343. package/{driver/engine/mcp/uspto-local-server.mjs → providers/uspto-local/src/mount.js} +5 -10
  344. package/scripts/band-shape-probe.mjs +2 -2
  345. package/scripts/citation-line-check.mjs +7 -7
  346. package/scripts/compare.mjs +1 -1
  347. package/scripts/dead-names.mjs +2 -2
  348. package/scripts/e2e-first-time.mjs +19 -7
  349. package/scripts/e2e.mjs +13 -13
  350. package/scripts/engine-probe.mjs +1 -1
  351. package/scripts/env-audit.mjs +7 -4
  352. package/scripts/env-classify.mjs +5 -1
  353. package/scripts/feedback-mint.mjs +1 -1
  354. package/scripts/freeze-example-run.mjs +7 -7
  355. package/scripts/mint-suite-census.mjs +2 -2
  356. package/scripts/nightly-notice.mjs +1 -1
  357. package/scripts/release-cut-decision.mjs +7 -2
  358. package/scripts/release-note-required.mjs +26 -9
  359. package/scripts/release-notes-lint.mjs +3 -2
  360. package/scripts/release-version-pr-checks.mjs +1 -1
  361. package/scripts/settings-render-check.mjs +23 -3
  362. package/scripts/test-run.mjs +5 -5
  363. package/scripts/travelling-predicates.mjs +1 -1
  364. package/scripts/undeclared-field-census.mjs +1 -1
  365. package/scripts/unexecuted-asserts.mjs +1 -1
  366. package/scripts/verify-publishable.mjs +1 -1
  367. package/shared/client-door.mjs +1 -1
  368. package/shared/connect-clients.mjs +1 -1
  369. package/shared/connector-signin-probe.mjs +1 -1
  370. package/shared/env-aliases.mjs +1 -1
  371. package/shared/invocation.mjs +14 -2
  372. package/shared/names-in-force.mjs +2 -0
  373. package/shared/register-selection.mjs +2 -2
  374. package/shared/store-in-repo.mjs +3 -3
  375. package/shared/summary-blocks.mjs +0 -3
  376. package/shared/trigger-lane.mjs +1 -1
  377. package/shared/vacuous-pass.mjs +2 -2
  378. package/shared/verb-shim.mjs +4 -2
  379. package/node_modules/exceljs/README.md +0 -3023
@@ -29,11 +29,11 @@
29
29
  // is absent — which `pipeline.mjs` stamps unconditionally on every fresh run. That branch is the
30
30
  // resume-and-replay compatibility path for pre-flag plans and archived runs, kept deliberately, and it
31
31
  // is left exactly as it is.
32
- import { writeFileSync, mkdirSync, readFileSync, appendFileSync } from "node:fs";
32
+ import { writeFileSync, mkdirSync, readFileSync, appendFileSync, existsSync, renameSync } from "node:fs";
33
33
  import { captureCall, stampVerdict } from "./call-capture.mjs";
34
34
  import { join, dirname, basename } from "node:path";
35
- import { driverDir } from "../shared/driver-dir.mjs";
36
35
  import { refuseUndeclared as refuseUndeclaredShared, keepIfAbsent, lastAccepted, acceptedEnvelope } from "./preserve-merge.mjs";
36
+ import { paths, readJson } from "./run-record.mjs";
37
37
 
38
38
  /**
39
39
  * THE REPAIR TAIL FOR THIS STAGE'S BESPOKE FOLLOWUPS — one implementation, used by all of them.
@@ -77,7 +77,7 @@ export function unitPaths(runDir, axis) {
77
77
  * writer per file, and an interleaved append from six units would be a journal nobody can attribute.
78
78
  */
79
79
  export function unitCallPaths(runDir, axis) {
80
- const dir = driverDir(runDir, "register-unit-calls");
80
+ const dir = paths(runDir).registerUnitCalls;
81
81
  // PER AXIS, and the accepted base with it: the driver dispatches one seat per axis, so a base keyed
82
82
  // on the run would let one axis's repair inherit another axis's note.
83
83
  return { dir, payload: join(dir, `${axis}.json`), accepted: join(dir, `${axis}-accepted.json`), refusals: join(dir, `${axis}-refusals.jsonl`) };
@@ -111,9 +111,41 @@ export function bandAccount(band) {
111
111
  return acct;
112
112
  }
113
113
 
114
+ /**
115
+ * THE HONEST EMPTY BAND FOR AN AXIS THE PLAN GIVES NO WORK. On a plan run the driver sends a unit for every axis the
116
+ * manifest's markers suggest, and the frozen plan can hold no entries for one of them. The plan executor refuses an empty
117
+ * axis, so such a unit had no band, and its note was then refused as an account of nothing, though no work was owed. The
118
+ * driver writes the band empty before the unit runs, as it already does for the code-side saturation probe: zero planned
119
+ * entries and zero blocks, consistently. A band already there is never touched, so a resumed unit keeps its own. Returns
120
+ * the axes seeded. IMPURE.
121
+ */
122
+ export function seedUnplannedBands(runDir, plan, axes) {
123
+ if (!Array.isArray(plan?.entries)) return [];
124
+ const planned = new Set(plan.entries.map((e) => e?.axis));
125
+ const seeded = [];
126
+ for (const axis of axes ?? []) {
127
+ if (planned.has(axis)) continue;
128
+ const { dir, band } = unitPaths(runDir, axis);
129
+ if (existsSync(band)) continue;
130
+ mkdirSync(dir, { recursive: true });
131
+ writeFileSync(`${band}.tmp`, "[]\n");
132
+ renameSync(`${band}.tmp`, band);
133
+ seeded.push(axis);
134
+ }
135
+ return seeded;
136
+ }
137
+
138
+ /** How many entries the frozen plan holds for this axis, or null on a run without a readable plan. Never throws. */
139
+ export function plannedEntries(runDir, axis) {
140
+ try {
141
+ const plan = readJson(paths(String(runDir ?? "")).registerPlan);
142
+ return Array.isArray(plan?.entries) ? plan.entries.filter((e) => e?.axis === axis).length : null;
143
+ } catch { return null; }
144
+ }
145
+
114
146
  /** Read and account for this axis's band, or null when it cannot be read. */
115
147
  export function readBandAccount(runDir, axis) {
116
- try { return bandAccount(JSON.parse(readFileSync(unitPaths(runDir, axis).band, "utf8"))); }
148
+ try { return bandAccount(readJson(unitPaths(runDir, axis).band)); }
117
149
  catch { return null; }
118
150
  }
119
151
 
@@ -127,10 +159,13 @@ export function readBandAccount(runDir, axis) {
127
159
  * /not applicable|n\/a|no .*(hits|results)/ — so the null-result render says "no results" in those
128
160
  * words rather than hoping a shorter note happens to match.
129
161
  */
130
- export function renderUnitNote({ axis, account, nullResult = false, note = "" } = {}) {
162
+ export function renderUnitNote({ axis, account, nullResult = false, note = "", planned = null } = {}) {
131
163
  const a = account ?? { blocks: 0, enumerated: 0, incomplete: 0, unknown: 0, records: 0 };
132
164
  const out = [`# Register unit — ${axis}`, ""];
133
- if (nullResult) {
165
+ // No instructed work, told apart from unfinished instructed work: the frozen plan gave this axis nothing, and nothing ran.
166
+ if (planned === 0 && a.blocks === 0) {
167
+ out.push("No searches were planned for this axis.", "");
168
+ } else if (nullResult) {
134
169
  out.push(`This axis returned no results: ${a.enumerated} enumerated quer${a.enumerated === 1 ? "y" : "ies"} carried no records.`, "");
135
170
  } else {
136
171
  out.push(`Searched this axis over ${a.blocks} band block${a.blocks === 1 ? "" : "s"}: `
@@ -185,7 +220,7 @@ export function mergeUnitNoteCall(stored, received) {
185
220
  };
186
221
  }
187
222
 
188
- export function acceptUnitNote(params, { account = null } = {}) {
223
+ export function acceptUnitNote(params, { account = null, planned = null } = {}) {
189
224
  const axis = String(params?.axis ?? "").trim();
190
225
  if (!axis) return { ok: false, reason: "unit_axis_missing: `axis` names which unit this note is for — the driver dispatches one seat per axis and the note is filed under that name" };
191
226
  if (!account) {
@@ -196,11 +231,15 @@ export function acceptUnitNote(params, { account = null } = {}) {
196
231
  return { ok: false, reason: `unit_note_shape:${axis} — \`note\` is one short observation, a single paragraph. The counts are the driver's; this is for what the counts cannot say` };
197
232
  }
198
233
  const nullResult = Boolean(params?.null_result);
234
+ if (nullResult && account.blocks === 0) {
235
+ // No search ran, so there is no result to call null: a clean negative over an empty band is the claim this lane exists to refuse.
236
+ return { ok: false, reason: `unit_null_result_unsearched:${axis} — no search ran on this axis, so it has no result to call null. Leave \`null_result\` unset and say in \`note\` why no search result is held` };
237
+ }
199
238
  if (nullResult && account.records > 0) {
200
239
  // The one contradiction worth refusing: a null-result claim over a band that carried records.
201
240
  return { ok: false, reason: `unit_null_result_contradicted:${axis}:${account.records} — you declared this axis a null result and its band carries ${account.records} record(s). The band is what the lawyer reads; a note that calls it empty is the claim this lane cannot afford to get wrong` };
202
241
  }
203
- const content = renderUnitNote({ axis, account, nullResult, note: note ?? "" });
242
+ const content = renderUnitNote({ axis, account, nullResult, note: note ?? "", planned });
204
243
  // The shipped floor, checked here so a drift surfaces as a refusal the seat sees rather than as a
205
244
  // stage failure the driver reports about a file it wrote itself.
206
245
  const floor = /not applicable|n\/a|no .*(hits|results)/i.test(content) ? 40 : 80;
@@ -236,7 +275,7 @@ export function recordUnitNote(runDir, received, { now = () => new Date().toISOS
236
275
  return { written: null, refused: undeclared, captured: closeCapture({ ok: false, refused: undeclared }), capture_failed: captureFailed };
237
276
  }
238
277
  const call = mergeUnitNoteCall(lastAcceptedUnitNote(dir0, axis), received);
239
- const v = acceptUnitNote(call, { account: readBandAccount(dir0, axis) });
278
+ const v = acceptUnitNote(call, { account: readBandAccount(dir0, axis), planned: plannedEntries(dir0, axis) });
240
279
  if (!v.ok) {
241
280
  // BEST-EFFORT, and it must stay that way: a journal write that failed a refusal would turn a defect
242
281
  // the seat can fix into one it cannot see. The refusal is the return value; this is the audit trail.
@@ -27,9 +27,10 @@ import { PROVIDERS, activeProvider, missingCredentials } from "./driver.config.m
27
27
  import { capabilitiesFor } from "./register-capabilities.mjs";
28
28
  import { unavailableOffices } from "./register-availability.mjs";
29
29
 
30
- /** The ACTIVE provider's contract, or null. Never throws — an unwired provider is not this file's error. */
31
- export function registerCapabilities() {
32
- try { return capabilitiesFor(activeProvider().id); } catch { return null; }
30
+ /** A register's contract: the run's (`ctx.register`), or the machine's when none is named; null when unknown. Never
31
+ * throws — an unwired provider is not this file's error. */
32
+ export function registerCapabilities(register = null) {
33
+ try { return capabilitiesFor(register ?? activeProvider().id); } catch { return null; }
33
34
  }
34
35
 
35
36
  /**
@@ -17,11 +17,12 @@
17
17
 
18
18
  import { readFileSync, writeFileSync, mkdirSync, existsSync, readdirSync, openSync, readSync, closeSync } from "node:fs"; import { runPrefixSpellings } from "../shared/pre-rename-spellings.mjs";
19
19
  import { join } from "node:path";
20
- import { driverDir, ensureDriverDir } from "../shared/driver-dir.mjs"; // — one definition of where `_driver/` is
21
20
  import { ledgerPath, runRecordLogPath, ledgerDeprecationNotice, retiredGlobalRecordLogNotice }
22
21
  from "../providers/_shared/ledger-path.mjs";
22
+ import { recordedRegister } from "./engine/run-choices.mjs"; // the register the run recorded, which named its receipts
23
23
  import { envFrom } from "../shared/env-aliases.mjs"; // — resolves EITHER spelling; names the retired one because that is the live-writable half
24
24
  import { USE_SOURCE_QUALITY } from "./findings-model.mjs"; // — the attested vocabulary; an unknown value falls back to the heuristic
25
+ import { ensureDriverDir, paths, readJson } from "./run-record.mjs"; // — one definition of where `_driver/` is
25
26
 
26
27
  // — `DEFAULT_RECORD_LOG` IS GONE, and it went because the question it answered no longer has one
27
28
  // answer. It was `ledgerPath("record")` frozen at import, in the DRIVER — a long-lived process running
@@ -37,6 +38,16 @@ function rowMatchesRun(row, runPrefix) {
37
38
  return runPrefixSpellings(runPrefix).some((rp) => stripGatewayNs(row.sessionKey).startsWith(rp)
38
39
  || stripGatewayNs(row.sessionId ?? "").startsWith(rp)); // either spelling: a run resumed across the rename
39
40
  }
41
+ // A line that holds none of the run's prefix spellings cannot be one of its rows, so it is skipped before it
42
+ // is parsed. The call log is shared by every run on the machine, and most of its lines belong to other runs.
43
+ // The test is safe only while each spelling is text that JSON writes unescaped; a prefix with any other
44
+ // character keeps the old path and parses every line.
45
+ export function lineMayMatchRun(runPrefix) {
46
+ if (!runPrefix) return () => false;
47
+ const spellings = runPrefixSpellings(runPrefix);
48
+ if (!spellings.every((rp) => /^[A-Za-z0-9._:-]+$/.test(rp))) return () => true;
49
+ return (line) => spellings.some((rp) => line.includes(rp));
50
+ }
40
51
 
41
52
 
42
53
  // ── THE LEDGER IS READ LINE BY LINE, AND AN UNREADABLE ONE IS LOUD ───────────────────────────
@@ -139,14 +150,25 @@ const keepRecord = (map, uri, body) => { if (recordBodyHasContent(body) || !reco
139
150
  // read failure rather than an empty map, and the failure travels to the caller as `ledgerError`.
140
151
  export function collectRecordBodies(recordLogPath, runPrefix) {
141
152
  const map = new Map();
142
- noteLedger(forEachLedgerLine(recordLogPath, (line) => {
153
+ walkRunRows(recordLogPath, runPrefix, (row) => foldBody(map, row));
154
+ return map;
155
+ }
156
+
157
+ // Each row of a log that belongs to the run, parsed, in file order. A read failure is noted for the caller.
158
+ function walkRunRows(path, runPrefix, onRow) {
159
+ const mayMatch = lineMayMatchRun(runPrefix);
160
+ noteLedger(forEachLedgerLine(path, (line) => {
161
+ if (!mayMatch(line)) return;
143
162
  let row;
144
163
  try { row = JSON.parse(line); } catch { return; }
145
164
  if (!runPrefix || !rowMatchesRun(row, runPrefix)) return;
146
- const body = Array.isArray(row.body) ? row.body[0] : row.body;
147
- if (row.target && body && typeof body === "object") keepRecord(map, String(row.target).toLowerCase(), body);
165
+ onRow(row);
148
166
  }));
149
- return map;
167
+ }
168
+
169
+ function foldBody(map, row) {
170
+ const body = Array.isArray(row.body) ? row.body[0] : row.body;
171
+ if (row.target && body && typeof body === "object") keepRecord(map, String(row.target).toLowerCase(), body);
150
172
  }
151
173
 
152
174
  // WP-receipts (2026-07-05): the fetch RECEIPT per record URI — when the record was pulled and under
@@ -155,35 +177,41 @@ export function collectRecordBodies(recordLogPath, runPrefix) {
155
177
  export function collectRecordReceipts(recordLogPath, runPrefix) { // — no default; see above
156
178
  const map = new Map();
157
179
  const real = new Set(); // the records whose receipt is from a body carrying the record, which a placeholder's never replaces
158
- noteLedger(forEachLedgerLine(recordLogPath, (line) => {
159
- let row;
160
- try { row = JSON.parse(line); } catch { return; }
161
- if (!runPrefix || !rowMatchesRun(row, runPrefix)) return;
162
- if (!row.target || !row.ts) return;
163
- const key = String(row.target).toLowerCase();
164
- const full = recordBodyHasContent(row.body);
165
- if (!full && real.has(key)) return;
166
- if (full) real.add(key);
167
- map.set(key, { fetched_at: String(row.ts), context: stripGatewayNs(row.sessionKey ?? "") || null });
168
- }));
180
+ walkRunRows(recordLogPath, runPrefix, (row) => foldReceipt(map, real, row));
169
181
  return map;
170
182
  }
171
183
 
184
+ function foldReceipt(map, real, row) {
185
+ if (!row.target || !row.ts) return;
186
+ const key = String(row.target).toLowerCase();
187
+ const full = recordBodyHasContent(row.body);
188
+ if (!full && real.has(key)) return;
189
+ if (full) real.add(key);
190
+ map.set(key, { fetched_at: String(row.ts), context: stripGatewayNs(row.sessionKey ?? "") || null });
191
+ }
192
+
193
+ // The bodies and the receipts from ONE pass over the record log: the same two maps the two readers above
194
+ // return, for the price of one read.
195
+ export function collectRecordBodiesAndReceipts(recordLogPath, runPrefix) {
196
+ const bodies = new Map();
197
+ const receipts = new Map();
198
+ const real = new Set();
199
+ walkRunRows(recordLogPath, runPrefix, (row) => { foldBody(bodies, row); foldReceipt(receipts, real, row); });
200
+ return { bodies, receipts };
201
+ }
202
+
172
203
  // Per-URI fetch call metadata (http_status / ok / cache_hit) from the CALL ledger the plugin already
173
204
  // writes — joined into receipts.json so "verified" is provable with the transport outcome attached.
174
205
  export function collectFetchCallMeta(callLogPath, runPrefix) {
175
206
  const map = new Map();
176
- noteLedger(forEachLedgerLine(callLogPath, (line) => {
177
- let row;
178
- try { row = JSON.parse(line); } catch { return; }
179
- if (!runPrefix || !rowMatchesRun(row, runPrefix)) return;
207
+ walkRunRows(callLogPath, runPrefix, (row) => {
180
208
  if (row.tool !== "record_fetch" || !row.target) return;
181
209
  map.set(String(row.target).toLowerCase(), {
182
210
  ...(row.http_status !== undefined ? { http_status: row.http_status } : {}),
183
211
  ...(row.ok !== undefined ? { ok: row.ok } : {}),
184
212
  ...(row.cache_hit !== undefined ? { cache_hit: row.cache_hit } : {}),
185
213
  });
186
- }));
214
+ });
187
215
  return map;
188
216
  }
189
217
 
@@ -191,7 +219,11 @@ export function collectFetchCallMeta(callLogPath, runPrefix) {
191
219
  // verifies against ("identifiers in the report match the record-fetch artifact field-for-field").
192
220
  // V4-1: each artifact embeds its `_uri` so the run dir is a READABLE record set (the filename squash is
193
221
  // lossy for hyphenated ids); readRecordArtifacts below re-derives legacy filenames best-effort.
194
- export function writeRecordArtifacts(runDir, recordsByUri, receiptsByUri = null) {
222
+ //
223
+ // `onDisk` is what readRecordArtifactFiles read from this run dir just before. A file whose name and text
224
+ // already match what would be written is left as it is: the largest runs assemble their records 8 to 14
225
+ // times, and rewriting every file each time wrote the whole set again.
226
+ export function writeRecordArtifacts(runDir, recordsByUri, receiptsByUri = null, onDisk = null) {
195
227
  if (!recordsByUri?.size) return 0;
196
228
  const dir = join(runDir, "_records");
197
229
  mkdirSync(dir, { recursive: true });
@@ -202,7 +234,10 @@ export function writeRecordArtifacts(runDir, recordsByUri, receiptsByUri = null)
202
234
  // legacy readers): a FRESH receipt for this uri wins; otherwise a receipt already embedded in the
203
235
  // body (an inherited artifact) survives the rewrite — the run dir stays self-contained.
204
236
  const receipt = receiptsByUri?.get(uri);
205
- try { writeFileSync(join(dir, name), JSON.stringify({ ...body, _uri: uri, ...(receipt ? { _receipt: receipt } : {}) }, null, 2) + "\n"); n++; } catch { /* best-effort */ }
237
+ const text = JSON.stringify({ ...body, _uri: uri, ...(receipt ? { _receipt: receipt } : {}) }, null, 2) + "\n";
238
+ const held = onDisk?.get(uri);
239
+ if (held && held.file === name && held.text === text) { n++; continue; }
240
+ try { writeFileSync(join(dir, name), text); n++; } catch { /* best-effort */ }
206
241
  }
207
242
  return n;
208
243
  }
@@ -210,18 +245,26 @@ export function writeRecordArtifacts(runDir, recordsByUri, receiptsByUri = null)
210
245
  // V4-1: read the run dir's archived record set back. The inverse of writeRecordArtifacts — `_uri` is the
211
246
  // embedded key; legacy artifacts (pre-V4) re-derive `/mark/<cc>/<rest>` from `<cc>-<rest>.json`.
212
247
  export function readRecordArtifacts(runDir) {
248
+ const map = new Map();
249
+ for (const [uri, { body }] of readRecordArtifactFiles(runDir, false)) map.set(uri, body);
250
+ return map;
251
+ }
252
+
253
+ // The same read, keeping for each record the file it came from and, when asked, the text that file held,
254
+ // so writeRecordArtifacts can tell which files already hold what it would write.
255
+ export function readRecordArtifactFiles(runDir, keepText = true) {
213
256
  const map = new Map();
214
257
  const dir = join(runDir, "_records");
215
258
  let files;
216
259
  try { files = readdirSync(dir); } catch { return map; }
217
260
  for (const f of files.filter((x) => x.endsWith(".json")).sort()) {
218
- let body;
219
- try { body = JSON.parse(readFileSync(join(dir, f), "utf8")); } catch { continue; }
261
+ let text, body;
262
+ try { text = readFileSync(join(dir, f), "utf8"); body = JSON.parse(text); } catch { continue; }
220
263
  if (!body || typeof body !== "object" || Array.isArray(body)) continue;
221
264
  const uri = typeof body._uri === "string" && body._uri
222
265
  ? body._uri.toLowerCase()
223
266
  : `/mark/${f.slice(0, 2)}/${f.slice(3, -5)}`.toLowerCase();
224
- map.set(uri, body);
267
+ map.set(uri, { body, file: f, text: keepText ? text : null });
225
268
  }
226
269
  return map;
227
270
  }
@@ -257,16 +300,17 @@ export function assembleRunRecords(runDir, runPrefix,
257
300
  // any other service account, splitting the provider ledger — plus the legacy name/dir fallbacks.
258
301
  callLogPath = ledgerPath("call")) {
259
302
  lastLedgerError = null; // this assembly's own verdict, not a previous one's
260
- const fromRunDir = readRecordArtifacts(runDir);
261
- const fromLedger = collectRecordBodies(recordLogPath, runPrefix);
303
+ const onDisk = readRecordArtifactFiles(runDir);
304
+ const fromRunDir = new Map([...onDisk].map(([uri, { body }]) => [uri, body]));
305
+ const { bodies: fromLedger, receipts: fromLedgerReceipts } = collectRecordBodiesAndReceipts(recordLogPath, runPrefix);
262
306
  const records = new Map(fromRunDir);
263
307
  for (const [uri, body] of fromLedger) keepRecord(records, uri, body);
264
308
  // WP-receipts: receipts assemble the same way the records do — artifact-embedded ones (inherited run
265
309
  // dir) ∪ this-session ledger rows (fresh fetch wins) — so a re-assembled run dir keeps its proof.
266
310
  const receipts = new Map();
267
311
  for (const [uri, body] of fromRunDir) if (body?._receipt && typeof body._receipt === "object") receipts.set(uri, body._receipt);
268
- for (const [uri, receipt] of collectRecordReceipts(recordLogPath, runPrefix)) receipts.set(uri, receipt);
269
- writeRecordArtifacts(runDir, records, receipts);
312
+ for (const [uri, receipt] of fromLedgerReceipts) receipts.set(uri, receipt);
313
+ writeRecordArtifacts(runDir, records, receipts, onDisk);
270
314
  // — the ledger's own verdict travels with the result. A caller that cannot tell "no records were
271
315
  // fetched" from "the ledger could not be read" will report the second as the first, which is what let
272
316
  // a 641 MB file silently empty every run's record set for hours.
@@ -319,7 +363,8 @@ export function assembleRunRecords(runDir, runPrefix,
319
363
  try {
320
364
  if (records.size) {
321
365
  const callMeta = fetchCalls; // — one read of the call ledger per assembly, not two
322
- const provider = (envFrom(process.env, "CLEAROTRON_DATABASE") || "").toLowerCase() || null;
366
+ // The register the run recorded; the machine's, as before, for a run with no record.
367
+ const provider = recordedRegister(runDir) ?? ((envFrom(process.env, "CLEAROTRON_DATABASE") || "").toLowerCase() || null);
323
368
  // — WHICH CORPUS ANSWERED, ON THE MACHINE RECORD.
324
369
  //
325
370
  // put `environment` on euipo_search's response envelope and taught two skill files to carry
@@ -331,7 +376,7 @@ export function assembleRunRecords(runDir, runPrefix,
331
376
  // family this program keeps finding. So the driver writes it, beside the provider it already
332
377
  // writes, from the same kind of read.
333
378
  //
334
- // UNSET WRITES null, NEVER "sandbox". euipo-server.mjs makes the same choice at the other end and
379
+ // UNSET WRITES null, NEVER "sandbox". the euipo mount makes the same choice at the other end and
335
380
  // says why: a default here would reinstate the silent wrong-corpus read the field exists to
336
381
  // prevent. null says "this run did not record it", which is a fact; "sandbox" would be a claim.
337
382
  // A live EUIPO call cannot reach this state anyway — core.js refuses to run with the variable
@@ -356,7 +401,7 @@ export function assembleRunRecords(runDir, runPrefix,
356
401
  };
357
402
  });
358
403
  ensureDriverDir(runDir);
359
- writeFileSync(driverDir(runDir, "receipts.json"), JSON.stringify({ schema_version: 1, receipts: rows }, null, 2) + "\n");
404
+ writeFileSync(paths(runDir).receipts, JSON.stringify({ schema_version: 1, receipts: rows }, null, 2) + "\n");
360
405
  }
361
406
  } catch { /* best-effort — the records map above remains the gate substrate */ }
362
407
  // That legacy-name notice is REPLACED, not deleted. That one told an operator which of four
@@ -627,7 +672,7 @@ export function collectOppositionDeadlines(runDir) {
627
672
  if (node.record_id || (typeof node.uri === "string" && node.uri.startsWith("/mark/"))) fold(node);
628
673
  for (const v of Object.values(node)) walk(v);
629
674
  };
630
- const tryWalk = (path) => { try { if (existsSync(path)) walk(JSON.parse(readFileSync(path, "utf8"))); } catch { /* skip unreadable */ } };
675
+ const tryWalk = (path) => { try { if (existsSync(path)) walk(readJson(path)); } catch { /* skip unreadable */ } };
631
676
  tryWalk(join(runDir, "register-named-band.json"));
632
677
  try {
633
678
  const unitDir = join(runDir, "register-units");
@@ -54,6 +54,7 @@ import { basename } from "node:path";
54
54
  // nothing enumerated them, so the guard could not walk them. They are imported and registered.
55
55
  import { buildFrameReopenFollowup, buildEscalationFollowup, buildEnvelopeCloseFollowup, buildFrameReopenRetryMessage, DECIDE_WAITING_FAMILIES, followupScopeLines } from "./stages.mjs";
56
56
  import { refutationStandingLines, refutationOpenItemsLine, REFUTATION_RECORDING_LINES, writerExclusionLines } from "./stages.mjs";
57
+ import { addressListLines } from "./review-addresses.mjs";
57
58
  import { buildReconcileFollowup } from "./recall-reconciliation.mjs";
58
59
  import { buildFlushFollowup } from "./digest-queue.mjs";
59
60
 
@@ -341,6 +342,7 @@ export const REPAIR_COMPOSERS = [
341
342
  `SCOPE — THE REVIEWER DECLARED WHICH FINDINGS ITS FLAGS ARE ABOUT, AND THIS IS THE COMPLETE LIST: ${
342
343
  scope.ordinals.length ? scope.ordinals.map((o) => `#${o}`).join(", ") : NO_FINDING_NAMED}.`,
343
344
  positions.length ? `THE EXCLUDED POSITIONS ITS FLAGS ARE ABOUT: ${positions.join("; ")}. ${answers}` : "",
345
+ Array.isArray(scope.lineLabels) && scope.lineLabels.length ? `THE LINES AND SECTIONS ITS FLAGS ARE ABOUT: ${scope.lineLabels.join("; ")}.` : "",
344
346
  // The scope sentence is the one ruled 2026-10-30: the passages a document flag identifies are inside the scope.
345
347
  `Change the named finding objects, any finding you record for the named excluded positions, and the document passages the flags identify. Preserve unaffected findings and passages. If a correction requires another change, record what changed and why. EVERY OTHER FINDING OBJECT IN ${findings} MUST COME BACK BYTE-IDENTICAL — do not re-derive it, do not re-word it, do not re-order its keys. The driver compares them and records anything that moved.`,
346
348
  KNOCK_ON,
@@ -423,23 +425,26 @@ export const REPAIR_COMPOSERS = [
423
425
  trigger: "verdict-recheck",
424
426
  stage: "narrative-refutation",
425
427
  key: "narrative-refutation:verdict-recheck",
426
- compose: ({ narrative, findings, seniorEyeReview, correctionsScope, appliedTable, restoredTable, evidenceTable, planAuditCarry, writerExclusions = null }) => lines(
428
+ compose: ({ narrative, findings, seniorEyeReview, correctionsScope, appliedTable, restoredTable, evidenceTable, planAuditCarry, writerExclusions = null, reviewAddresses = null }) => lines(
427
429
  `This is a fresh session: your earlier refutation is not in your context, and you do NOT redo it from scratch. Your prior verdict and its flags are in ${seniorEyeReview} — open it first — and the source files you refuted against are listed below.`,
428
430
  // — WHEN THE SCOPE WAS DECLARED, THE RE-READ IS NARROWED TO IT. The recheck cost 270-510 s on
429
431
  // every measured run, and its whole job is to judge whether the corrections are RIGHT — not to
430
432
  // re-derive which parts of two long documents changed. The driver already knows: it holds the
431
433
  // pre-corrective snapshot and compared every finding outside the declared scope.
432
- correctionsScope?.scoped
433
- ? `The synthesis author applied your flagged corrections. Read narrowly. Named findings in ${findings}: ${correctionsScope.named.length ? correctionsScope.named.map((o) => `#${o}`).join(", ") : NO_FINDING_NAMED}. Review those findings, the excluded positions your flags name, and the document passages your flags identify in ${narrative}, together with conclusions that depend on the corrections. Judge whether each correction answers its flag; the recorded outcome alone is not proof.${correctionsScope.positions?.length ? " For each excluded position your flags named, check the resulting finding or renewed exclusion against the evidence and the specific objection you raised. A newly recorded ground alone does not settle the flag. Retain the flag if its factual error, reasoning error, or relevant uncertainty remains." : ""} THE DRIVER COMPARED EVERY OTHER FINDING OBJECT against the pre-correction file${correctionsScope.moved.length ? ` and ${correctionsScope.moved.length} moved anyway — ${correctionsScope.moved.map((o) => `#${o}`).join(", ")}; read those too and say whether the change is defended` : " and none moved, so you do not need to re-read them"}. Then re-write ${seniorEyeReview}: the verdict (CLEAR / CONDITIONAL / BLOCKING) on the FIRST line, then any corrections that still stand.`
434
+ // Narrowed only when the driver could compare everything outside the flags; a parts comparison that could not be
435
+ // completed (a missing record or narrative, or an address two rows share) takes the whole re-read below instead.
436
+ correctionsScope?.scoped && correctionsScope.lines?.complete !== false
437
+ ? `The synthesis author applied your flagged corrections. Read narrowly. Named findings in ${findings}: ${correctionsScope.named.length ? correctionsScope.named.map((o) => `#${o}`).join(", ") : NO_FINDING_NAMED}. Review those findings, the excluded positions your flags name, and the document passages your flags identify in ${narrative}, together with conclusions that depend on the corrections. Judge whether each correction answers its flag; the recorded outcome alone is not proof.${correctionsScope.positions?.length ? " For each excluded position your flags named, check the resulting finding or renewed exclusion against the evidence and the specific objection you raised. A newly recorded ground alone does not settle the flag. Retain the flag if its factual error, reasoning error, or relevant uncertainty remains." : ""} THE DRIVER COMPARED EVERY OTHER FINDING OBJECT against the pre-correction file${correctionsScope.moved.length ? ` and ${correctionsScope.moved.length} moved anyway — ${correctionsScope.moved.map((o) => `#${o}`).join(", ")}; read those too and say whether the change is defended` : " and none moved, so you do not need to re-read them"}.${correctionsScope.lines?.complete ? ` THE DRIVER ALSO COMPARED EVERY COVERAGE LINE, ACTION, MARK ASSESSMENT READ AND NARRATIVE SECTION NO FLAG NAMES${correctionsScope.lines.moved.length ? ` and ${correctionsScope.lines.moved.length} moved anyway — ${correctionsScope.lines.moved.map((l) => l.label).join("; ")}; read those too and say whether the change is defended` : " and none moved"}.` : ""} Then re-write ${seniorEyeReview}: the verdict (CLEAR / CONDITIONAL / BLOCKING) on the FIRST line, then any corrections that still stand.`
434
438
  : `The synthesis author applied your flagged corrections and re-emitted the narrative ${narrative} AND the machine findings ${findings}. Re-read BOTH updated files — verify the structured findings (owners, tiers, dispositions; a killed finding must be "withdrawn") carry your corrections — re-verify your prior concerns, then re-write ${seniorEyeReview}: the verdict (CLEAR / CONDITIONAL / BLOCKING) on the FIRST line, then any corrections that still stand.`,
435
439
  // THOSE TWO FILES ARE THE ONLY EVIDENCE THAT EXISTS YET. report.md is BUILT FROM the narrative at
436
440
  // report-overview / report-card, both of which run AFTER this gate, so they hold the PREVIOUS
437
441
  // round's text by construction. A real run died here: the reviewer read them, found its own
438
442
  // blocked assertions still present, and returned BLOCKING — two steps before the stage that would
439
443
  // have rebuilt them. Blocking on that staleness is unwinnable, so say plainly that it is expected.
440
- `Judge ONLY ${narrative} and ${findings}. The report and the client summary are GENERATED FROM the narrative by stages that run after this gate, so on disk they still carry the previous round's text — that is expected and is NOT evidence a correction failed to land. Do not read them as the deliverable and do not block on them.`,
444
+ `Judge ONLY ${narrative} and ${findings}. The report is GENERATED FROM the narrative by stages that run after this gate, so on disk it still carries the previous round's text — that is expected and is NOT evidence a correction failed to land. Do not read it as the deliverable and do not block on it.`,
441
445
  // The writer's exclusions a recheck reads: the ones that changed and the ones its flags named, then the others for reference.
442
446
  ...writerExclusionLines(writerExclusions),
447
+ ...addressListLines(reviewAddresses),
443
448
  appliedTable,
444
449
  // — WHAT THE DRIVER PUT BACK, and why the reviewer has to be told rather than
445
450
  // merely handed the file. Every other row in this document is the seat's judgment; a restored row
@@ -490,17 +495,17 @@ export const REPAIR_COMPOSERS = [
490
495
  // correction. VALUES IN: the list `repair-scope.mjs listForReview` computed from the writer's record before
491
496
  // and after the repair. The standing tools and notes, the open-items check and the recording lines are the
492
497
  // full review's own, read from one shared text in stages.mjs.
493
- compose: ({ findings, changes, resting, renumbered, coverageChanged, evidence, registerOnly = false, job = {}, skepticFlags, frameReopenReceipt, floorDecisions = null, writerExclusions = null }) => lines(
498
+ compose: ({ findings, changes, resting, renumbered, coverageChanged, evidence, registerOnly = false, job = {}, skepticFlags, frameReopenReceipt, floorDecisions = null, writerExclusions = null, reviewAddresses = null }) => lines(
494
499
  `This is a review of a repair, not a full review. Earlier in this run the narrative was reviewed in full, and the corrections that review raised went to the writer. The delivery check then found a fault, and the writer repaired the record.`,
495
500
  `Review only what that repair changed, listed below under WHAT THE REPAIR CHANGED, and any statement elsewhere in the narrative or in the findings record, ${findings}, that rests on a changed item. Such a statement no longer holds if the change leaves it untrue, without its support, or incomplete.`,
496
501
  `Everything else stands as this run's earlier reviews left it. Do not flag a statement that rests on no changed item.`,
497
502
  `From your own manual, skills/narrative-refutation/SKILL.md, use only the checks that bear on these items. Its whole-report checks, its length target for a review and its expectation that a clean review is rare belong to the full review, not to this one. A clean result is a normal outcome here.`,
498
503
  `Check each changed item against the evidence named for it, and each statement that rests on a changed item against the new values.`,
499
- `Say what each flag is about. For a finding, put its number from the list below in \`on\`. For a writer's exclusion, put a record id from its entry in \`positions\`. For anything else, begin the flag's text with the item's name exactly as the list gives it, for example: the coverage line for "<area>".`,
504
+ `Say what each flag is about. For a finding, put its number from the list below in \`on\`. For a writer's exclusion, put a record id from its entry in \`positions\`. For a coverage line, an action, a mark assessment read or a narrative section with a listed address, put that address in \`lines\`. For anything else, begin the flag's text with the item's name exactly as the list gives it.`,
500
505
  renumbered ? `Where a finding below shows two numbers, put the first in \`on\`. The second is its number in findings.json.` : "",
501
506
  `Your verdict is about the repair. CLEAR: what changed is sound, and every statement that rests on a changed item still holds. CONDITIONAL: a flag needs a correction. BLOCKING: the change makes the report unsafe to sign, under your manual's verdict logic.`,
502
507
  `Your flags go to one correction pass by the writer, and nothing reviews that pass again. Make each fix exact.`,
503
- ...refutationStandingLines({ registerOnly, job, floorDecisions, writerExclusions }),
508
+ ...refutationStandingLines({ registerOnly, job, floorDecisions, writerExclusions, addressLines: addressListLines(reviewAddresses) }),
504
509
  // A repair that rewrites coverage lines can drop an open item; when coverage is untouched, the full review
505
510
  // already checked this.
506
511
  coverageChanged ? refutationOpenItemsLine({ skepticFlags, frameReopenReceipt }) : "",
@@ -569,8 +574,8 @@ export const REPAIR_COMPOSERS = [
569
574
  // THE WRITER'S RATING LINE ALLOWS A GOODS REASSESSMENT. Read beside a check that hands newly available goods
570
575
  // text, "never re-derive" overrode the repair it sits in; the writer's branch says which check does what.
571
576
  toolWritten?.tool === "record_synthesis"
572
- ? `Where a check identifies a mismatch in a copied risk tier or Level/Composite label, copy the quoted finding value exactly. Where a check supplies newly available goods text, reassess only the affected finding on that text; change its rating only if the evidence requires it.`
573
- : `Risk tiers and Level/Composite labels are COPIED from the findings values quoted in the check — never re-derive or re-word them.`,
577
+ ? `Where a check identifies a mismatch in a copied risk tier, copy the quoted finding value exactly. Where a check supplies newly available goods text, reassess only the affected finding on that text; change its rating only if the evidence requires it.`
578
+ : `Risk tiers are COPIED from the findings values quoted in the check — never re-derive or re-word them.`,
574
579
  toolWritten?.tool === "record_synthesis"
575
580
  ? `Fix ONLY what the checks name, and the answers that depend on those changes; change nothing else.`
576
581
  : `Fix ONLY what the checks name; change nothing else.`,
@@ -31,21 +31,19 @@
31
31
  // which is what makes a classifier gap reportable HERE: the pipeline logs one to run.jsonl, and
32
32
  // this module never opens that file, so the park row is the only carrier it can read.
33
33
 
34
- import { readFileSync } from "node:fs";
35
34
  import { join } from "node:path";
36
- import { driverDir } from "../shared/driver-dir.mjs"; //
37
35
  import { failureSignature, classifyFailureReason, bareStage, REFUSAL_TERMINAL_KIND,
38
36
  unnamedStructuredFailure } from "./repairs.mjs";
39
37
  import { enumerateRuns } from "../mcp-server/lib/runs.mjs";
40
38
  import { isEntrypoint } from "../shared/is-entrypoint.mjs"; // — realpath both sides, or a symlinked invocation exits 0 silently
39
+ import { paths, readJsonOrNull } from "./run-record.mjs";
41
40
 
42
41
  const DAY_MS = 86400000;
43
42
 
44
- function readJsonDefault(p) { try { return JSON.parse(readFileSync(p, "utf8")); } catch { return null; } }
45
43
 
46
44
  // The failure events one run contributes inside the window. `run` is an enumerateRuns row (status +
47
45
  // runDir). A torn packet or a malformed history row degrades to less detail — never a throw.
48
- export function failureEventsForRun(run, { sinceMs = 0, readJson = readJsonDefault } = {}) {
46
+ export function failureEventsForRun(run, { sinceMs = 0, readJson = readJsonOrNull } = {}) {
49
47
  const status = run.status ?? {};
50
48
  const events = [];
51
49
  const runId = run.runId ?? "?";
@@ -68,7 +66,7 @@ export function failureEventsForRun(run, { sinceMs = 0, readJson = readJsonDefau
68
66
  events.push({ kind: "refusal", runId, ts, sig: null, stage: bareStage(status.failedStage), failClass: null,
69
67
  terminalKind: REFUSAL_TERMINAL_KIND, sample: String(status.reason ?? "").replace(/\s+/g, " ").trim().slice(0, 160) || null });
70
68
  } else if (ts >= sinceMs) {
71
- const packet = run.runDir ? readJson(driverDir(run.runDir, "failure.json")) : null;
69
+ const packet = run.runDir ? readJson(paths(run.runDir).failure) : null;
72
70
  if (packet?.failureSignature) {
73
71
  events.push({
74
72
  kind: "terminal", runId, ts, sig: packet.failureSignature, stage: bareStage(packet.failedStage),
@@ -130,7 +128,7 @@ export function failureEventsForRun(run, { sinceMs = 0, readJson = readJsonDefau
130
128
 
131
129
  // One group per signature over the window: which runs hit it, how many terminals vs parks, and a
132
130
  // sample reason. Sorted most-recurrent first (run count, then terminals, then recency).
133
- export function aggregateFailureRecurrence({ enumerate = enumerateRuns, now = Date.now(), days = 7, readJson = readJsonDefault } = {}) {
131
+ export function aggregateFailureRecurrence({ enumerate = enumerateRuns, now = Date.now(), days = 7, readJson = readJsonOrNull } = {}) {
134
132
  const nowMs = typeof now === "number" ? now : (Date.parse(now) || Date.now());
135
133
  const sinceMs = nowMs - days * DAY_MS;
136
134
  const bySig = new Map();
@@ -15,9 +15,9 @@
15
15
  // that list prints and the reviewer is asked to repeat, so a flag can be joined back to its item.
16
16
  import { readFileSync, writeFileSync, renameSync, rmSync, mkdirSync } from "node:fs";
17
17
  import { join, dirname } from "node:path";
18
- import { driverDir } from "../shared/driver-dir.mjs";
19
18
  import { synthesisCallPaths } from "./synthesis-record.mjs";
20
19
  import { REPORT_LINE_KEY, REPORT_LINE_LABEL } from "./corrections-feedforward.mjs";
20
+ import { paths, readJson } from "./run-record.mjs";
21
21
 
22
22
  const isObj = (v) => v != null && typeof v === "object" && !Array.isArray(v);
23
23
  const collapse = (s) => String(s).replace(/\s+/g, " ").trim();
@@ -281,11 +281,11 @@ export function snapshotRepairBase(runDir) {
281
281
 
282
282
  /** The kept base's params, or null. Never throws. */
283
283
  export function readRepairBase(runDir) {
284
- try { return JSON.parse(readFileSync(repairBasePath(runDir), "utf8"))?.params ?? null; } catch { return null; }
284
+ try { return readJson(repairBasePath(runDir))?.params ?? null; } catch { return null; }
285
285
  }
286
286
 
287
287
  /** The review after a repair's own record: what it was handed, how each point was classed, what the pass did. */
288
- export function postRepairRecordPath(runDir) { return driverDir(String(runDir ?? ""), "post-repair-review.json"); }
288
+ export function postRepairRecordPath(runDir) { return paths(String(runDir ?? "")).postRepairReview; }
289
289
 
290
290
  export function writePostRepairRecord(runDir, rec) {
291
291
  try { writeAtomic(postRepairRecordPath(runDir), JSON.stringify({ ts: new Date().toISOString(), ...rec }, null, 2) + "\n"); return true; }
@@ -85,17 +85,26 @@ const withdrawnCitationLine = (ordinal) => `Your text cites finding ${ordinal},
85
85
  + `Check the affected statement against the surviving assessment, and correct or remove it if unsupported. Keep unaffected text unchanged.`;
86
86
 
87
87
  /**
88
- * The faults the writer's repair is given for one a register of the record holds: one line per withdrawn finding it
89
- * cites, each named by the number the writer's record carries. The check judged the delivered record, which the fold
90
- * may have renumbered; `toModel` maps a delivered ordinal to the writer's, or to null for one the fold does not know,
91
- * which keeps its number as written. A citation of a finding the run does not have is not sent: the ruled line is for a
92
- * withdrawn one. PURE.
88
+ * The faults the writer's repair is given for one a register of the record holds, each finding named by the number the
89
+ * writer's record carries. The check judged the delivered record, which the fold may have renumbered; `toModel` maps a
90
+ * delivered ordinal to the writer's, or to null for one the fold does not know, which keeps its number as written.
91
+ * In the four answers each withdrawn finding gets its ruled line, and the findings the run does not have get the general
92
+ * instruction together, since the ruled line says "withdrew". A forward step gets the general instruction, with the
93
+ * step it concerns named, because the step's support is what is rechecked. PURE.
93
94
  */
94
95
  export function writersCitationFaults(fault, toModel) {
95
- if (fault?.register !== "four_answers" || !Array.isArray(fault.cites)) return [fault];
96
- const numbers = [...new Set(fault.cites.filter((c) => c.withdrawn).map((c) => toModel(c.ordinal) ?? c.ordinal))];
97
- return numbers.map((ordinal) => ({ ...fault, cites: fault.cites.filter((c) => (toModel(c.ordinal) ?? c.ordinal) === ordinal),
98
- detail: withdrawnCitationLine(ordinal) }));
96
+ if (!["four_answers", "actions"].includes(fault?.register) || !Array.isArray(fault.cites)) return [fault];
97
+ const number = (c) => toModel(c.ordinal) ?? c.ordinal;
98
+ if (fault.register === "actions") {
99
+ const seen = new Map(fault.cites.map((c) => [`${c.action}:${number(c)}`, { action: c.action, ordinal: number(c), withdrawn: Boolean(c.withdrawn) }]));
100
+ return [{ ...fault, detail: actionCitationDetail([...seen.values()]) }];
101
+ }
102
+ const withdrawnOnes = [...new Set(fault.cites.filter((c) => c.withdrawn).map(number))].map((ordinal) => ({ ...fault,
103
+ cites: fault.cites.filter((c) => c.withdrawn && number(c) === ordinal), detail: withdrawnCitationLine(ordinal) }));
104
+ const absent = fault.cites.filter((c) => !c.withdrawn);
105
+ if (!absent.length) return withdrawnOnes;
106
+ const numbers = [...new Set(absent.map(number))];
107
+ return [...withdrawnOnes, { ...fault, cites: absent, detail: overviewCitationDetail(numbers.map((ordinal) => ({ ordinal, withdrawn: false }))) }];
99
108
  }
100
109
 
101
110
  /**
@@ -122,6 +131,12 @@ const CITATION_CORRECTION = "The listed references point to findings that have b
122
131
  + "Cite a surviving finding only where its evidence supports the statement; otherwise correct the statement. "
123
132
  + "Preserve unaffected work and record the corrections through the existing correction tool.";
124
133
 
134
+ /** A forward step's citations in the same words, each reference naming the step that holds it. PURE. */
135
+ function actionCitationDetail(cites) {
136
+ const each = cites.map((c) => `action ${c.action}, finding ${c.ordinal} (${c.withdrawn ? "withdrawn" : "absent"})`);
137
+ return `References: ${each.join("; ")}. ${CITATION_CORRECTION}`;
138
+ }
139
+
125
140
  /** The overview's citation fault in words, for its repair. PURE. */
126
141
  export function overviewCitationDetail(cites) {
127
142
  const each = cites.map((c) => `finding ${c.ordinal} (${c.withdrawn ? "withdrawn" : "absent"})`);