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
@@ -43,10 +43,9 @@
43
43
  // real checks move here, to the values as received, where a refusal names the row the seat can act on
44
44
  // instead of a shape it cannot see. THE VALIDATOR IS NOT DELETED: archived runs were hand-written
45
45
  // under the old dictation and must keep parsing. A new way in, never a replacement.
46
- import { readFileSync, writeFileSync, mkdirSync, existsSync, readdirSync } from "node:fs";
46
+ import { readFileSync, writeFileSync, existsSync, readdirSync } from "node:fs";
47
47
  import { captureCall, stampVerdict } from "./call-capture.mjs";
48
48
  import { join } from "node:path";
49
- import { driverDir } from "../shared/driver-dir.mjs";
50
49
 
51
50
  export const FINDINGS_FILE = "register-findings.md";
52
51
  const SCHEMA_VERSION = 1;
@@ -62,6 +61,7 @@ const SCHEMA_VERSION = 1;
62
61
  */
63
62
  import { applyFates } from "./hit-list.mjs"; // — the digest marks the list
64
63
  import { formKey } from "../providers/_shared/script-form.mjs"; // — the one fold for "is this the same form of the mark"
64
+ import { driverDir, paths as runPaths, readJson } from "./run-record.mjs";
65
65
 
66
66
  export const FACTS_FILE = "register-digest-facts.json";
67
67
  /** — the slim hit list the digest marks; a projection of the merged band. */
@@ -309,7 +309,7 @@ export const DIGEST_SECTIONS = Object.freeze({
309
309
 
310
310
  /** Where the call's evidence lives — the driver's own record of what the seat handed it. */
311
311
  export function registerDigestCallPaths(runDir) {
312
- const dir = driverDir(runDir, "register-digest-calls");
312
+ const dir = runPaths(runDir).registerDigestCalls;
313
313
  return { dir, payload: join(dir, "call-001.json"), refusals: join(dir, "refusals.jsonl"), model: join(dir, "model.json") };
314
314
  }
315
315
 
@@ -336,7 +336,7 @@ export function recordedFindingUris(runDir) {
336
336
  for (const name of names) {
337
337
  if (!/^call-\d+\.json$/.test(name)) continue;
338
338
  try {
339
- const doc = JSON.parse(readFileSync(join(registerDigestCallPaths(runDir).dir, name), "utf8"));
339
+ const doc = readJson(join(registerDigestCallPaths(runDir).dir, name));
340
340
  for (const row of doc?.params?.findings_rows ?? []) {
341
341
  const uri = row?.uri ?? row?.record_id;
342
342
  if (uri) out.add(String(uri).toLowerCase());
@@ -445,7 +445,7 @@ export const joinKey = (u) => lc(u).replace(/^https?:\/\/[^/]+/, "");
445
445
  */
446
446
  export function readDigestFacts(runDir) {
447
447
  let raw;
448
- try { raw = JSON.parse(readFileSync(driverDir(String(runDir ?? ""), FACTS_FILE), "utf8")); }
448
+ try { raw = readJson(driverDir(String(runDir ?? ""), FACTS_FILE)); }
449
449
  // THE STAMP IS READ EVEN WHEN THE FACTS ARE NOT, and this line is the whole of the stamp-lands-first
450
450
  // ordering being worth anything. `emptyFacts()` hardcodes `armed:false`, so returning it bare made the
451
451
  // STAMPED-BUT-NO-FACTS state — the exact state that ordering exists to catch — unreachable: the call
@@ -944,7 +944,7 @@ export function recordRegisterDigest(runDir, received, { facts = null, now = ()
944
944
  if (Array.isArray(received?.fates) && received.fates.length) {
945
945
  try {
946
946
  applyFates(join(String(runDir ?? ""), HIT_LIST_FILE), received.fates, {
947
- readJson: (f) => { try { return JSON.parse(readFileSync(f, "utf8")); } catch { return null; } },
947
+ readJson: (f) => { try { return readJson(f); } catch { return null; } },
948
948
  writeJson: (f, o) => writeFileSync(f, JSON.stringify(o, null, 2) + "\n"),
949
949
  });
950
950
  } catch { /* the marking is a projection; the accepted call stands regardless */ }
@@ -1030,7 +1030,7 @@ export function refusalsFor(runDir) {
1030
1030
  * The last model this run accepted, or null. The patch path's base.
1031
1031
  */
1032
1032
  export function lastAcceptedModel(runDir) {
1033
- try { return JSON.parse(readFileSync(registerDigestCallPaths(String(runDir ?? "")).model, "utf8")); }
1033
+ try { return readJson(registerDigestCallPaths(String(runDir ?? "")).model); }
1034
1034
  catch { return null; }
1035
1035
  }
1036
1036
 
@@ -3,8 +3,8 @@
3
3
  //
4
4
  // register-fixture-marker.mjs — whether this run's register answers come from a fixture directory. From the job, never
5
5
  // the environment: it is a fact about the run, and every tool server a stage spawns reads it here.
6
- import { existsSync, readFileSync, writeFileSync } from "node:fs";
7
- import { driverDir, ensureDriverDir } from "../shared/driver-dir.mjs";
6
+ import { existsSync, writeFileSync } from "node:fs";
7
+ import { driverDir, ensureDriverDir, readJson } from "./run-record.mjs";
8
8
 
9
9
  export const REGISTER_FIXTURE_MARKER = "register-fixtures.json";
10
10
 
@@ -18,5 +18,5 @@ export function writeFixtureMarker(runDir, records) {
18
18
  export function fixtureRecordsDir(runDir) {
19
19
  const p = driverDir(runDir, REGISTER_FIXTURE_MARKER);
20
20
  if (!existsSync(p)) return null;
21
- try { return JSON.parse(readFileSync(p, "utf8"))?.records ?? null; } catch { return null; }
21
+ try { return readJson(p)?.records ?? null; } catch { return null; }
22
22
  }
@@ -2983,13 +2983,13 @@ export function searchedJurisdictionsFromPlan(plan, execution) {
2983
2983
  // They live HERE, with the derivation, rather than in pipeline.mjs: `pipeline.mjs` imports
2984
2984
  // `gateway.mjs`, so the gateway cannot import back from it, and this module is already imported by both.
2985
2985
  export const PLAN_AUDIT_HEAD =
2986
- `DETERMINISTIC PLAN-EXECUTION CHECK (spec-48 WS2 / spec-49 doctrine): this run executed a FROZEN register plan; the code-derived receipt below states what actually ran.`;
2986
+ `DETERMINISTIC PLAN-EXECUTION CHECK: this run executed a FROZEN register plan; the code-derived receipt below states what actually ran.`;
2987
2987
  // T8 (G5, doctrine): the old directive graded EVERY crowd/incomplete/skipped slice under a clean
2988
2988
  // claim as a mechanical BLOCKING flag — the rejected PR- shape (a state label driving the verdict).
2989
2989
  // Graded: only a slice that NEVER RAN blocks; a sanctioned skip and a crowd descriptor are JUDGMENT
2990
2990
  // inputs — the seat reasons over them, it never manufactures a verdict from a label.
2991
2991
  export const PLAN_AUDIT_CLASSES =
2992
- `THE FOUR CLASSES, GRADED: (1) a slice listed MISSING NEVER RAN — nothing resting on it may be stated as searched-clean, and nothing may describe what such a search would have shown; (2) a crowd-gated SKIPPED fringe is SANCTIONED (#361 — its parent proved intractable): the parent crowd is dilution context, never a searched-clean slice; (3) a CROWD/INCOMPLETE descriptor is a signal FOR JUDGMENT and never a verdict input — the lawyer's materiality reasoning over it STANDS (off-field, dilution evidence), and a state label never manufactures a CONDITIONAL by itself; (4) a waiting family nobody asked (ruling 204) is in one of two states. AWAITING JUDGMENT while the reading turn can still ask it: a question still open to you. WITHHELD BY JUDGMENT once the reading turn chose not to ask it and recorded why: a settled judgment, not an open question. Either way it has no parent crowd, says nothing about the field, and nothing resting on it may be stated as searched-clean.`;
2992
+ `THE FOUR CLASSES, GRADED: (1) a slice listed MISSING NEVER RAN — nothing resting on it may be stated as searched-clean, and nothing may describe what such a search would have shown; (2) a crowd-gated SKIPPED fringe is SANCTIONED (its parent proved intractable): the parent crowd is dilution context, never a searched-clean slice; (3) a CROWD/INCOMPLETE descriptor is a signal FOR JUDGMENT and never a verdict input — the lawyer's materiality reasoning over it STANDS (off-field, dilution evidence), and a state label never manufactures a CONDITIONAL by itself; (4) a waiting family nobody asked (ruling 204) is in one of two states. AWAITING JUDGMENT while the reading turn can still ask it: a question still open to you. WITHHELD BY JUDGMENT once the reading turn chose not to ask it and recorded why: a settled judgment, not an open question. Either way it has no parent crowd, says nothing about the field, and nothing resting on it may be stated as searched-clean.`;
2993
2993
 
2994
2994
  export function deriveCoverageSkeleton(plan, join) {
2995
2995
  const missing = new Set(join.missing);
@@ -13,11 +13,11 @@
13
13
  // 3. NO JUDGMENT IS ADDED by code. The fields are what the register said: mark, owner, status, classes, territory, and
14
14
  // the record's own address.
15
15
 
16
- import { readFileSync } from "node:fs";
17
16
  import { join } from "node:path";
18
17
 
19
18
  import { recordOriginsFor } from "./record-origins.mjs"; // — provider-derived, never CLEAROTRON_DATABASE
20
19
  import { recordGoods, rowGoods, untaggedIsEnglish } from "./record-goods.mjs";
20
+ import { readJson } from "./run-record.mjs";
21
21
 
22
22
  /**
23
23
  * Was this listing made by the reading step? Its sentences say what that step did. A listing written before it keeps the
@@ -320,7 +320,7 @@ export function fixtureLister(dir) {
320
320
  return async (term, question = {}) => {
321
321
  const file = join(dir, fixtureFileName(term, question));
322
322
  let doc;
323
- try { doc = JSON.parse(readFileSync(file, "utf8")); }
323
+ try { doc = readJson(file); }
324
324
  catch (e) { return { ok: false, records: null, reason: `record fixture missing for ${term}: ${e.message}` }; }
325
325
  if (!Array.isArray(doc?.records)) return { ok: false, records: null, reason: `record fixture for ${term} carries no records[]` };
326
326
  return { ok: true, records: doc.records, total: Number.isFinite(doc.total) ? doc.total : doc.records.length };
@@ -43,7 +43,7 @@
43
43
 
44
44
  import { readFileSync, existsSync, readdirSync } from "node:fs";
45
45
 
46
- import { driverDir } from "../shared/driver-dir.mjs"; //
46
+ import { driverDir, paths, readJson } from "./run-record.mjs";
47
47
 
48
48
  export const TAINT_FAIL_RE = /^timeout$|^status_timeout$/;
49
49
 
@@ -134,9 +134,9 @@ export function readUnacknowledgedTaintAxes(runDir) {
134
134
 
135
135
  function readTaintReceipt(runDir) {
136
136
  try {
137
- const p = driverDir(runDir, "register-taint.json");
137
+ const p = paths(runDir).registerTaint;
138
138
  if (!existsSync(p)) return null;
139
- const rec = JSON.parse(readFileSync(p, "utf8"));
139
+ const rec = readJson(p);
140
140
  return rec && typeof rec === "object" ? rec : null;
141
141
  } catch { return null; }
142
142
  }
@@ -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.`,