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
package/driver/runner.mjs CHANGED
@@ -22,7 +22,7 @@ import "../shared/env-local.mjs"; // side effect: apply <repo>/.env when THIS
22
22
  import "./engine/mcp/http-dispatcher.mjs"; // side effect: raise undici headersTimeout (code-side fetches)
23
23
  import { readdirSync, renameSync, existsSync, mkdirSync, readFileSync, writeFileSync, appendFileSync, rmSync, statSync } from "node:fs";
24
24
  import { join, dirname, basename } from "node:path"; import { studioDirFor } from "../shared/pre-rename-spellings.mjs";
25
- import { driverDir, ensureDriverDir } from "../shared/driver-dir.mjs"; // — one definition of where `_driver/` is
25
+ import { crossBuildResumeRefusal } from "./one-build-per-run.mjs"; // a run is finished on the build it started on (owner, 2026-11-09)
26
26
  // The queue's filename vocabulary, in ONE place — the rule, extended by to the prose-sidecar and
27
27
  // claim-sidecar names, because a harness check retyped four of them from memory and false-alarmed on the
28
28
  // other nine. Behaviour here is unchanged: the same object and the same three suffixes, sourced.
@@ -65,7 +65,7 @@ import { drainWhatIfQueues, liveRunDirs } from "./whatif-worker.mjs";
65
65
  // throw. A self-contained LEGACY job (prose inline in the JSON, no sidecars) assembles unchanged: the overlay
66
66
  // loop is a no-op. A present, non-empty sidecar overrides the manifest's value for that field (sidecar wins).
67
67
  function assembleJob(procPath, qdir, base) {
68
- const job = JSON.parse(readFileSync(procPath, "utf8"));
68
+ const job = readJson(procPath);
69
69
  // Prose sidecars share the job's BARE base (<id>.markName.md, …). A manifest mis-named `<id>.manifest.json`
70
70
  // — an observed forwarding-agent fumble (live, 2026-06-19) — leaves `base` as "<id>.manifest", so the
71
71
  // bare-base sidecars stop matching and the mark name never overlays → the job parks "missing mark name(s)".
@@ -267,7 +267,7 @@ export function checkRunCaps({ account, caps, queueDirs, inHandTagged = true, no
267
267
  let files = [];
268
268
  try { files = readdirSync(qd).filter(isLiveQueueMarker); } catch { continue; }
269
269
  for (const f of files) {
270
- try { const j = JSON.parse(readFileSync(join(qd, f), "utf8")); if (inLane(j.profileKey, j.tenant)) queued++; }
270
+ try { const j = readJson(join(qd, f)); if (inLane(j.profileKey, j.tenant)) queued++; }
271
271
  catch { /* mid-rename / prose sidecar — skip */ }
272
272
  }
273
273
  }
@@ -552,6 +552,7 @@ import { procStarttime, parseClaimSidecar, claimAgeMs, claimerIsAlive } from "./
552
552
  import { isEntrypoint } from "../shared/is-entrypoint.mjs"; // — one entry-point test, all spellings
553
553
  import { beat } from "./worker-heartbeat.mjs"; // — is anything draining this install
554
554
  import { BRAND } from "../shared/brand.mjs"; // — the operator name in the allowance note, from the tenant seam
555
+ import { ensureDriverDir, paths, readJson } from "./run-record.mjs"; // — one definition of where `_driver/` is
555
556
  export { procStarttime, parseClaimSidecar, claimAgeMs, claimerIsAlive };
556
557
 
557
558
  // — a queue running WITHOUT the birth stamp says so, once, out loud. Where no stamp can be read
@@ -567,7 +568,7 @@ export function claimToken(pid = process.pid) {
567
568
  if (!st && !starttimeGapAnnounced) {
568
569
  starttimeGapAnnounced = true;
569
570
  note("[runner] no birth stamp for this pid on this host — neither /proc/<pid>/stat nor `ps` " +
570
- "answered, so claims record a BARE PID and the #665 PID-reuse " +
571
+ "answered, so claims record a BARE PID and the PID-reuse " +
571
572
  "defence is inactive. Fail-safe direction (a claim whose liveness cannot be proved counts as " +
572
573
  "ALIVE): no run is ever double-claimed and no lawyer double-delivered to. What is lost: a " +
573
574
  "`.processing` held by a RECYCLED pid is not freed by liveness and waits for the max-claim-age " +
@@ -710,7 +711,7 @@ function preRunFailNotify(agentId, base, job, reason) {
710
711
  return Boolean(p);
711
712
  }
712
713
 
713
- // B3 — guaranteed failure-notice backstop for PRE-TRY throws. pipelineInner's run-level catch owns every
714
+ // B3 — guaranteed failure-notice backstop for PRE-TRY throws. The run-level catch in `runShell` owns every
714
715
  // failure inside its try{} (it RETURNS {ok:false, failedStage, …} after notifying — the
715
716
  // _driver/failure.json + outbox packet); a throw that reaches runPrepared's catch instead (res.failedStage
716
717
  // unset) came from the SETUP code before that try — corrupt profile sidecar, missing framework manifest,
@@ -735,7 +736,7 @@ async function backstopFailureNotice({ res, job, agentId, base, codename, studio
735
736
  const owned = codename ? findRunDirFor({ codename, slug, studioRoot, archiveRoot }) : null;
736
737
  if (!owned) { preRunFailNotify(agentId, base, job, shortReason); return; }
737
738
  if (owned.kind === "archived" || existsSync(join(owned.dir, ".delivered"))) return; // report already delivered
738
- if (existsSync(driverDir(owned.dir, "failure.json"))) return; // already noticed
739
+ if (existsSync(paths(owned.dir).failure)) return; // already noticed
739
740
  const packet = buildFailurePacket({
740
741
  // canonical runId form (charter P1 §3): `<slug>-<date>-<codename>` — owned.dir's leaf IS
741
742
  // "<date>-<codename>", so the dated id is derivable even here (matches status.runId + rescan).
@@ -745,13 +746,13 @@ async function backstopFailureNotice({ res, job, agentId, base, codename, studio
745
746
  // same per-send invariant as the pipeline's failure path: a fresh notice supersedes an older .sent
746
747
  // and its per-channel receipts (B4 — stale receipts would make clearotron-deliver skip this notice)
747
748
  try { rmSync(join(owned.dir, ".sent"), { force: true }); } catch { /* none */ }
748
- try { rmSync(driverDir(owned.dir, "send-receipts.json"), { force: true }); } catch { /* none */ }
749
+ try { rmSync(paths(owned.dir).sendReceipts, { force: true }); } catch { /* none */ }
749
750
  ensureDriverDir(owned.dir);
750
- writeFileSync(driverDir(owned.dir, "failure.json"), JSON.stringify(packet, null, 2) + "\n");
751
+ writeFileSync(paths(owned.dir).failure, JSON.stringify(packet, null, 2) + "\n");
751
752
  // status flip mirrors the pipeline path (best-effort — packet + marker are the guaranteed lane)
752
753
  try {
753
754
  const sp = join(owned.dir, "status.json");
754
- const s = JSON.parse(readFileSync(sp, "utf8"));
755
+ const s = readJson(sp);
755
756
  writeFileSync(sp, JSON.stringify({ ...s, state: "failed", failedStage: "pre-run", reason: shortReason, reasonTruncated, reasonFull, sendPending: true }, null, 2) + "\n");
756
757
  } catch { /* a pre-seed throw leaves no status.json — the packet still notifies */ }
757
758
  mkdirSync(config.outboxDir, { recursive: true });
@@ -1079,6 +1080,18 @@ export function parkCause(res = {}) {
1079
1080
  // CONCURRENTLY across a queue's prepared jobs — each owns its own .processing/.pid + run dir, and the
1080
1081
  // matter-dedup was already settled serially in claimAndPrep. The run-slot cap (acquireRunSlot) bounds how
1081
1082
  // many pipelines actually run at once.
1083
+ /** The refusal for resuming this claim's run on the running build, recorded in the run's log, or null. */
1084
+ function resumeRefusalFor({ job, identity, studioRoot, archiveRoot }) {
1085
+ const owned = findRunDirFor({ codename: identity.codename, slug: deriveSlug(job), dateISO: identity.dateISO ?? null, studioRoot, archiveRoot });
1086
+ if (!owned?.dir) return null; // no run folder: the pipeline's own resume refuses that, by name
1087
+ const refused = crossBuildResumeRefusal(owned.dir);
1088
+ if (refused) {
1089
+ note(`[runner] ${identity.codename}: ${refused}`);
1090
+ try { runLog(owned.dir, { event: "resume-refused", reason: refused }); } catch { /* the queue's failure record carries it too */ }
1091
+ }
1092
+ return refused;
1093
+ }
1094
+
1082
1095
  async function runPrepared({ procPath, base, job }, qdir, agentId, resumeMeta = null) {
1083
1096
  const studioRoot = config.studioRootForAgent(agentId);
1084
1097
  const archiveRoot = config.archiveRootForAgent(agentId);
@@ -1107,13 +1120,16 @@ async function runPrepared({ procPath, base, job }, qdir, agentId, resumeMeta =
1107
1120
  // whole recovery. Stated plainly because the previous wording said the dir "certainly exists", and an
1108
1121
  // arm built on that claim reddened main for one commit.
1109
1122
  inFlightRuns.set(procPath, { slug: deriveSlug(job), codename: identity.codename, dateISO: identity.dateISO ?? null, agentId, studioRoot, archiveRoot });
1123
+ // A POSTPONED CLAIM OR A CRASH RECLAIM OF A RUN STARTED ON ANOTHER BUILD IS REFUSED here, before the pipeline is
1124
+ // entered, and the refusal takes the failure path below like any other, the client's notice included.
1125
+ const refused = resumeMeta ? resumeRefusalFor({ job, identity, studioRoot, archiveRoot }) : null;
1110
1126
  let res;
1111
1127
  try {
1112
1128
  // Run as the forwarding agent, with the run-dir + archive rooted in THAT agent's workspace (so the
1113
1129
  // agent's sandboxed write tool can reach them). Delivery still publishes to the central pool. resumeMeta
1114
1130
  // (set by resumePostponed / the crash-reclaim) reuses the prior codename's valid stages via the pipeline
1115
1131
  // resume path; a fresh job dispatches its pre-minted identity as a cold start (minted:true).
1116
- res = await pipeline(job, {
1132
+ res = refused ? { ok: false, reason: refused } : await pipeline(job, {
1117
1133
  agent: agentId, studioRoot, archiveRoot,
1118
1134
  // A2 — pass the dispatch-persisted dateISO so the RESUME targets the EXACT `${dateISO}-${codename}`
1119
1135
  // run dir. Without it the pipeline re-resolves the date via a date-agnostic findRunDate() that could
@@ -1468,7 +1484,7 @@ export function claimDuePostponed(qdir) {
1468
1484
  for (const f of readdirSync(qdir).filter((f) => f.endsWith(".postponed"))) {
1469
1485
  const base = f.replace(/\.postponed$/, "");
1470
1486
  let meta = {};
1471
- try { meta = JSON.parse(readFileSync(join(qdir, `${base}.postponed.meta`), "utf8")); } catch { /* missing meta -> resume now (fail-open) */ }
1487
+ try { meta = readJson(join(qdir, `${base}.postponed.meta`)); } catch { /* missing meta -> resume now (fail-open) */ }
1472
1488
  if (postponedDueAt(meta, config.rateLimitDefaultBackoffMs) > now) continue; // window not elapsed yet
1473
1489
  // STOPPED WHILE PARKED. This is the resume path that most needs the check: a rate-limit park can
1474
1490
  // sit for hours, which is exactly when someone gives up and presses Stop — and a park has no turn
@@ -1571,7 +1587,7 @@ function queueOwnedCodenames() {
1571
1587
  try {
1572
1588
  for (const f of readdirSync(q)) {
1573
1589
  if (!f.endsWith(".postponed.meta") && !f.endsWith(".processing.meta")) continue;
1574
- try { const m = JSON.parse(readFileSync(join(q, f), "utf8")); if (m?.codename) owned.add(m.codename); } catch { /* skip */ }
1590
+ try { const m = readJson(join(q, f)); if (m?.codename) owned.add(m.codename); } catch { /* skip */ }
1575
1591
  }
1576
1592
  } catch { /* queue dir absent */ }
1577
1593
  }
@@ -1602,7 +1618,7 @@ function queueTerminalCodenames() {
1602
1618
  try {
1603
1619
  for (const f of readdirSync(q)) {
1604
1620
  if (!suffixes.some((sfx) => f.endsWith(sfx))) continue;
1605
- try { const m = JSON.parse(readFileSync(join(q, f), "utf8")); if (m?.codename) settled.add(m.codename); } catch { /* skip */ }
1621
+ try { const m = readJson(join(q, f)); if (m?.codename) settled.add(m.codename); } catch { /* skip */ }
1606
1622
  }
1607
1623
  } catch { /* queue dir absent */ }
1608
1624
  }
@@ -1646,7 +1662,16 @@ export function resumeClaimIsAbandoned(resumingPath, now = Date.now(), {
1646
1662
  // needs to see it once would be the person least able to find it.
1647
1663
  const announcedTerminalSkips = new Set();
1648
1664
 
1649
- export function scanDueRunDirOrphans(now = Date.now()) {
1665
+ /** Is there a `.published` at `publishedPath` written no earlier than the park at `parkPath`? Unreadable reads as yes. */
1666
+ export function publishedSincePark(publishedPath, parkPath) {
1667
+ if (!existsSync(publishedPath)) return false;
1668
+ try { return statSync(publishedPath).mtimeMs >= statSync(parkPath).mtimeMs; } catch { return true; }
1669
+ }
1670
+
1671
+ /** Every run folder this watcher will resume on its own, due now or later: what an update has to wait for. */
1672
+ export const parkedRunDirOrphans = (now = Date.now()) => scanDueRunDirOrphans(now, { dueOnly: false });
1673
+
1674
+ export function scanDueRunDirOrphans(now = Date.now(), { dueOnly = true } = {}) {
1650
1675
  const owned = queueOwnedCodenames();
1651
1676
  const settled = queueTerminalCodenames();
1652
1677
  const out = [];
@@ -1688,11 +1713,18 @@ export function scanDueRunDirOrphans(now = Date.now()) {
1688
1713
  // `.resuming` stays in this list for the ORDINARY path: a live self-resume must not be re-fired.
1689
1714
  // It is excluded only when this run IS the abandoned claim recovered above, which is the whole
1690
1715
  // of the change — the fail-safe polarity is unchanged and an unprovable claim still counts alive.
1691
- const inFlight = [".delivered", ".failed", ".published", ".resuming", ".cancelled", ".cancel"]
1716
+ //
1717
+ // `.published` skips only when it is at least as new as the park. A run that published and then failed in a
1718
+ // later delivery step parks like any other, and its `.published` is older than the park: the resume finds the
1719
+ // record and delivers it without publishing again. A resume deletes the park it resumes (steps/open-run.mjs),
1720
+ // so a park older than the publish is one this watcher must leave alone, as it always has. An unreadable time
1721
+ // reads as moved on.
1722
+ const inFlight = [".delivered", ".failed", ".resuming", ".cancelled", ".cancel"]
1692
1723
  .filter((m) => !(abandoned && m === ".resuming"));
1693
1724
  if (inFlight.some((m) => existsSync(join(runDir, m)))) continue;
1725
+ if (publishedSincePark(join(runDir, ".published"), sentPath)) continue;
1694
1726
  let sent;
1695
- try { sent = JSON.parse(readFileSync(sentPath, "utf8")); } catch { continue; }
1727
+ try { sent = readJson(sentPath); } catch { continue; }
1696
1728
  if (!sent.job || !sent.agent || !sent.codename) continue; // pre-fix sentinel without payload — leave for manual handling
1697
1729
  if (owned.has(sent.codename)) continue; // the queue owns this resume — don't double-fire
1698
1730
  // ── — THE OTHER TWO WAYS A STOP IS SPELLED ──────────────────────────
@@ -1721,7 +1753,7 @@ export function scanDueRunDirOrphans(now = Date.now()) {
1721
1753
  }
1722
1754
  continue;
1723
1755
  }
1724
- if (postponedDueAt(sent, config.rateLimitDefaultBackoffMs) > now) continue; // backoff window not elapsed
1756
+ if (dueOnly && postponedDueAt(sent, config.rateLimitDefaultBackoffMs) > now) continue; // backoff window not elapsed
1725
1757
  out.push({ runDir, sentPath, job: sent.job, agent: sent.agent, codename: sent.codename, fromStage: sent.fromStage ?? null, reparks: Number(sent.reparks) || 0, payload: sent });
1726
1758
  }
1727
1759
  }
@@ -1783,13 +1815,19 @@ export async function resumeRunDirOrphans(orphans, { runPipeline = pipeline } =
1783
1815
  // already on disk, and threading them would put the same fact in two places to disagree.
1784
1816
  try {
1785
1817
  let sent = {};
1786
- try { sent = JSON.parse(readFileSync(claimPath, "utf8")); } catch { /* pre-fix sentinel — log what we have */ }
1818
+ try { sent = readJson(claimPath); } catch { /* pre-fix sentinel — log what we have */ }
1787
1819
  runLog(o.runDir, { event: "park-resumed", via: "run-dir-sentinel",
1788
1820
  probeAttempt: Number(sent?.probeAttempt) || 0, parkedAt: sent?.postponedAt ?? null,
1789
1821
  kind: sent?.kind ?? null, fromStage: o.fromStage ?? sent?.fromStage ?? null });
1790
1822
  } catch { /* spine append is best-effort */ }
1791
1823
  note(`[runner] self-resuming run-dir POSTPONED ${o.codename} (agent=${o.agent} from=${o.fromStage ?? "auto"}; window elapsed)`);
1792
1824
  try {
1825
+ // A run started on another build is not resumed, and a re-park cannot change that, so the refusal is final at once.
1826
+ const refused = crossBuildResumeRefusal(o.runDir);
1827
+ if (refused) {
1828
+ try { runLog(o.runDir, { event: "resume-refused", reason: refused }); } catch { /* the .failed sentinel below carries it */ }
1829
+ throw Object.assign(new Error(refused), { final: true });
1830
+ }
1793
1831
  await runPipeline(o.job, {
1794
1832
  agent: o.agent, codename: o.codename, fromStage: o.fromStage ?? undefined,
1795
1833
  studioRoot: config.studioRootForAgent(o.agent), archiveRoot: config.archiveRootForAgent(o.agent),
@@ -1802,8 +1840,8 @@ export async function resumeRunDirOrphans(orphans, { runPipeline = pipeline } =
1802
1840
  // it goes terminal (.failed + status), the same honest circuit breaker the pipeline itself uses.
1803
1841
  const reparks = (Number(o.reparks) || 0) + 1;
1804
1842
  const REPARK_MAX = 3;
1805
- if (reparks >= REPARK_MAX) {
1806
- const reasonText = `self-resume errored ${reparks}× — last: ${String(err?.message ?? err).slice(0, 300)}`;
1843
+ if (err?.final || reparks >= REPARK_MAX) {
1844
+ const reasonText = err?.final ? String(err.message) : `self-resume errored ${reparks}× — last: ${String(err?.message ?? err).slice(0, 300)}`;
1807
1845
  // — derived ONCE, outside both best-effort try blocks below, because both sinks need it:
1808
1846
  // the status write and the failure notice. Computing it inside the status `try` scoped it away
1809
1847
  // from the packet, which is the shape that had the packet re-cutting the string on its own.
@@ -1813,7 +1851,7 @@ export async function resumeRunDirOrphans(orphans, { runPipeline = pipeline } =
1813
1851
  writeFileSync(join(o.runDir, ".failed"), JSON.stringify({ stage: "self-resume", reason: reasonText, reparks, ts: new Date().toISOString() }, null, 2) + "\n");
1814
1852
  try {
1815
1853
  const statusPath = join(o.runDir, "status.json");
1816
- const status = JSON.parse(readFileSync(statusPath, "utf8"));
1854
+ const status = readJson(statusPath);
1817
1855
  // — cut VISIBLY. This is a terminal status write and it carried a bare 200-char slice,
1818
1856
  // so the cap that hides a cause hid it here too — and reasonText has already lost its own
1819
1857
  // tail to a 300-char slice one level up, which is the second cut nobody was told about.
@@ -1829,12 +1867,12 @@ export async function resumeRunDirOrphans(orphans, { runPipeline = pipeline } =
1829
1867
  // string with a bare slice, so the notice and status.json could disagree about whether the
1830
1868
  // sentence was finished. One cap, one marker, both sinks.
1831
1869
  failedStage: "self-resume", shortReason: rt.reason, reasonVerbatim: reasonText,
1832
- terminalKind: "exhausted", priorAttempts: reparks,
1870
+ terminalKind: err?.final ? undefined : "exhausted", priorAttempts: reparks,
1833
1871
  });
1834
1872
  try { rmSync(join(o.runDir, ".sent"), { force: true }); } catch { /* none */ }
1835
- try { rmSync(driverDir(o.runDir, "send-receipts.json"), { force: true }); } catch { /* none */ }
1873
+ try { rmSync(paths(o.runDir).sendReceipts, { force: true }); } catch { /* none */ }
1836
1874
  ensureDriverDir(o.runDir);
1837
- writeFileSync(driverDir(o.runDir, "failure.json"), JSON.stringify(packet, null, 2) + "\n");
1875
+ writeFileSync(paths(o.runDir).failure, JSON.stringify(packet, null, 2) + "\n");
1838
1876
  mkdirSync(config.outboxDir, { recursive: true });
1839
1877
  writeFileSync(join(config.outboxDir, `${packet.runId}.pending`), `${o.agent}\n`);
1840
1878
  } catch { /* notice best-effort — .failed + status remain the record */ }
@@ -1880,10 +1918,10 @@ async function claimAndRun(jsonFile, qdir, agentId) {
1880
1918
  * Exported for the test; returns what it did so callers can log it. */
1881
1919
  export function armUnannouncedDelivery(runDir, label = "") {
1882
1920
  try {
1883
- if (!existsSync(driverDir(runDir, "delivery.json"))) return "no-packet";
1921
+ if (!existsSync(paths(runDir).delivery)) return "no-packet";
1884
1922
  if (existsSync(join(runDir, ".sent"))) return "already-sent";
1885
1923
  let status = {};
1886
- try { status = JSON.parse(readFileSync(join(runDir, "status.json"), "utf8")); } catch { /* absent/corrupt ⇒ treat as unarmed */ }
1924
+ try { status = readJson(join(runDir, "status.json")); } catch { /* absent/corrupt ⇒ treat as unarmed */ }
1887
1925
  if (status?.sendPending === true) return "already-pending";
1888
1926
  const merged = { ...status, state: "delivered", sendPending: true, updatedAt: new Date().toISOString() };
1889
1927
  const tmp = join(runDir, `status.json.${process.pid}.${Date.now().toString(36)}.tmp`);
@@ -1901,8 +1939,8 @@ export function armUnannouncedDelivery(runDir, label = "") {
1901
1939
 
1902
1940
  export function runDirDelivered(dir) {
1903
1941
  if (existsSync(join(dir, ".delivered"))) return true;
1904
- if (existsSync(driverDir(dir, "delivery.json"))) return true;
1905
- try { return JSON.parse(readFileSync(join(dir, "status.json"), "utf8"))?.state === "delivered"; } catch { return false; }
1942
+ if (existsSync(paths(dir).delivery)) return true;
1943
+ try { return readJson(join(dir, "status.json"))?.state === "delivered"; } catch { return false; }
1906
1944
  }
1907
1945
 
1908
1946
  // B1 — where (if anywhere) a codename's run already lives on disk. The live leaf is "<date>-<codename>";
@@ -2023,7 +2061,7 @@ function reclaimOrphanedClaims(qdir, agentId) {
2023
2061
  continue;
2024
2062
  }
2025
2063
  let meta = null;
2026
- try { meta = JSON.parse(readFileSync(`${procPath}.meta`, "utf8")); } catch { /* no/corrupt meta — legacy fresh re-claim */ }
2064
+ try { meta = readJson(`${procPath}.meta`); } catch { /* no/corrupt meta — legacy fresh re-claim */ }
2027
2065
  if (meta?.codename) {
2028
2066
  let job = null;
2029
2067
  try { job = assembleJob(procPath, qdir, base); } catch { /* malformed manifest — the .json path fails it at intake properly */ }
@@ -2085,9 +2123,9 @@ function reclaimOrphanedClaims(qdir, agentId) {
2085
2123
  priorAttempts: priorReclaims,
2086
2124
  });
2087
2125
  try { rmSync(join(owned.dir, ".sent"), { force: true }); } catch { /* none */ }
2088
- try { rmSync(driverDir(owned.dir, "send-receipts.json"), { force: true }); } catch { /* none */ }
2126
+ try { rmSync(paths(owned.dir).sendReceipts, { force: true }); } catch { /* none */ }
2089
2127
  ensureDriverDir(owned.dir);
2090
- writeFileSync(driverDir(owned.dir, "failure.json"), JSON.stringify(packet, null, 2) + "\n");
2128
+ writeFileSync(paths(owned.dir).failure, JSON.stringify(packet, null, 2) + "\n");
2091
2129
  mkdirSync(config.outboxDir, { recursive: true });
2092
2130
  writeFileSync(join(config.outboxDir, `${packet.runId}.pending`), `${agentId}\n`);
2093
2131
  } catch (e) { note(`[runner] ${base} reclaim-terminal bookkeeping failed (non-fatal — the queue marker still ends it): ${e?.message ?? e}`); }
@@ -2268,7 +2306,7 @@ function hasQueuedWork() {
2268
2306
  // postponedDueAt is the single source of truth, so the idle gate and the resume gate never disagree
2269
2307
  // (a null-resetsAt run is NOT yet work until its postponedAt backoff elapses).
2270
2308
  if (f.endsWith(".postponed")) {
2271
- try { const m = JSON.parse(readFileSync(join(q, `${f}.meta`), "utf8")); return postponedDueAt(m, config.rateLimitDefaultBackoffMs) <= now; }
2309
+ try { const m = readJson(join(q, `${f}.meta`)); return postponedDueAt(m, config.rateLimitDefaultBackoffMs) <= now; }
2272
2310
  catch { return true; }
2273
2311
  }
2274
2312
  return false;
@@ -2385,7 +2423,7 @@ export async function watch({
2385
2423
  beatEveryMs = WATCH_TICK_MS,
2386
2424
  startBeating = (fn, everyMs) => { const t = setInterval(fn, everyMs); t.unref?.(); return () => clearInterval(t); },
2387
2425
  } = {}) {
2388
- note(`[runner] watch: polling every ${Math.round(tickMs / 1000)}s (no systemd here); a due park or an unclaimed job is picked up on the next tick. Ctrl-C to stop.`);
2426
+ note(`[runner] watch: checking every ${Math.round(tickMs / 1000)}s for a search to start or to resume. Ctrl-C to stop.`);
2389
2427
  for (let n = 0; ; n++) {
2390
2428
  if (stopped()) break;
2391
2429
  // One bad tick must never end the loop — that would put us back where a laptop started, with nothing
@@ -23,9 +23,9 @@
23
23
  //
24
24
  // A pure leaf: node:fs, node:path and shared/driver-dir.mjs only, so the goods reader and the band tool server can
25
25
  // both import it.
26
- import { readFileSync, readdirSync } from "node:fs";
26
+ import { readdirSync } from "node:fs";
27
27
  import { join } from "node:path";
28
- import { driverDir } from "../shared/driver-dir.mjs";
28
+ import { paths, readJson } from "./run-record.mjs";
29
29
 
30
30
  // The research server's own name for a call's file: the time it was kept, with ":" and "." made "-", the server's
31
31
  // process id, and the number of the call.
@@ -101,7 +101,7 @@ export function statusPagesIn(result) { // @internal — driven by its test
101
101
  */
102
102
  export function savedStatusPages(runDir) {
103
103
  if (!runDir) return () => new Map();
104
- const dir = driverDir(runDir, "web-results");
104
+ const dir = paths(runDir).webResults;
105
105
  const read = new Map();
106
106
  return () => {
107
107
  let names = [];
@@ -109,7 +109,7 @@ export function savedStatusPages(runDir) {
109
109
  const pages = new Map();
110
110
  for (const name of names) {
111
111
  if (!read.has(name)) {
112
- let result; try { result = JSON.parse(readFileSync(join(dir, name), "utf8")); } catch { continue; }
112
+ let result; try { result = readJson(join(dir, name)); } catch { continue; }
113
113
  read.set(name, statusPagesIn(result));
114
114
  }
115
115
  for (const { serial, goods } of read.get(name)) {
@@ -227,8 +227,8 @@ export function protectedStrings(root) {
227
227
  if (bare.length >= 5 && !LEGAL_FORM.has(bare.toLowerCase())) { names.add(bare); if (!given.has(bare.toLowerCase())) derived.add(bare); }
228
228
  }
229
229
  }
230
- // THE FLOOR STAYS AND THE CASE IT MISSES IS NAMED. A fleet decision on an internal page rather than
231
- // this file's preference: keep the floor, and name the case it does not cover.
230
+ // THE FLOOR STAYS AND THE CASE IT MISSES IS NAMED. A maintainers' decision rather than this file's
231
+ // preference: keep the floor, and name the case it does not cover.
232
232
  //
233
233
  // WHAT IT BUYS: a two-character token is cheap to collide with, and every standalone occurrence of one
234
234
  // would go — including words of this harness's own vocabulary. Lowering the floor is a real option and
@@ -34,7 +34,7 @@
34
34
  // BETA POSTURE: runs delivered under the old numbering KEEP it — an archived run re-renders through
35
35
  // RETIRED_POLICIES below, which still carries "Depth 4" for the level it was sold as.
36
36
 
37
- import { readFileSync, readdirSync } from "node:fs";
37
+ import { readdirSync } from "node:fs";
38
38
  import { join, dirname } from "node:path";
39
39
  import { fileURLToPath } from "node:url";
40
40
  import { createHash } from "node:crypto";
@@ -43,6 +43,7 @@ import { PRODUCT_IDS, productSpec, productFor, maxNamesFor, productName, checkPr
43
43
  // own static graph to compose-read + territory-tiers for exactly this reason (see its header).
44
44
  import { registerCoverageCause, offerableTerritories } from "./register-coverage.mjs";
45
45
  import { PROMPT_TERRITORIES } from "./compose-read.mjs"; // — the names a reader can choose from, which is the universe the disclosure counts against
46
+ import { readJson } from "./run-record.mjs";
46
47
 
47
48
  // ── The closed product registry ──────────────────────────────────────────────────────────────────────
48
49
  //
@@ -228,8 +229,6 @@ export const PRODUCT_POLICIES = {
228
229
  // Pinned with the same provenance in the-doubt-carries-its-placement-tier.test.mjs (RULED_CUTS).
229
230
  doubtClosure: "headline-candidate",
230
231
  recallFollowupMax: 1,
231
- envelopeRounds: "one", // one closing round, not to exhaustion
232
- coverageClosureRounds: "one",
233
232
  },
234
233
  components: { registerProbe: false, jxLanes: false, commonLawGrid: true },
235
234
  web: { questionPreset: "medium", resultsPerCell: 15 },
@@ -280,8 +279,6 @@ export const PRODUCT_POLICIES = {
280
279
  // ruling to the most expensive product is not mine to do. Raised as a question rather than
281
280
  // assumed —.
282
281
  recallFollowupMax: 2,
283
- envelopeRounds: "as-today",
284
- coverageClosureRounds: "as-today",
285
282
  },
286
283
  components: { registerProbe: false, jxLanes: false, commonLawGrid: true },
287
284
  web: { questionPreset: "high", resultsPerCell: 20 },
@@ -302,8 +299,6 @@ export const PRODUCT_POLICIES = {
302
299
  groundedProfiles: "every-finding",
303
300
  doubtClosure: "every-doubt",
304
301
  recallFollowupMax: 2, // RECALL_FOLLOWUP_MAX
305
- envelopeRounds: "as-today",
306
- coverageClosureRounds: "as-today",
307
302
  },
308
303
  components: { registerProbe: false, jxLanes: true, commonLawGrid: true },
309
304
  web: { questionPreset: "xhigh", resultsPerCell: 25 },
@@ -459,7 +454,7 @@ export function depthFor(policy) {
459
454
  // Reading only `product` meant ctx.searchPolicy resolved to `default-ungraded` on EVERY run: the whole
460
455
  // ladder ran at one-country depth, every rung returned "", and nothing anywhere failed. Both names are
461
456
  // accepted because both shapes reach this function — the frozen policy and a bare {product} selector.
462
- const key = String(policy?.level ?? policy?.product ?? "").trim();
457
+ const key = productKeyOf(policy);
463
458
  const row = PRODUCT_POLICIES[key]?.depth;
464
459
  if (row) return Object.freeze({ ...row, source: key });
465
460
  // A product this build KNOWS but does not grade is not the same thing as one it does not recognise.
@@ -470,6 +465,11 @@ export function depthFor(policy) {
470
465
  source: known ? `ungraded:${key}` : "default-ungraded" });
471
466
  }
472
467
 
468
+ /** The product a policy names: `level` on a run's frozen policy, `product` on a bare selector. "" when neither. */
469
+ export function productKeyOf(policy) {
470
+ return String(policy?.level ?? policy?.product ?? "").trim();
471
+ }
472
+
473
473
  export function isRegisterOnly(policy) {
474
474
  return policy?.pipeline === "clearance" && policy?.components?.commonLawGrid === false;
475
475
  }
@@ -529,10 +529,9 @@ export const BUILT = { knockout: true, jxLanes: true, registerProbe: true };
529
529
  // dir answering with a demo roster. Deleting the switch is the fix that cannot recur; plumbing a
530
530
  // snapshot into each new caller is the one that waits for the next caller.
531
531
  //
532
- // An incident kill did not go away with them: `CLEAROTRON_NATIVE_LANGUAGE_<code>` is fail-OPEN by construction
533
- // (`?? "1"` — on unless explicitly "0"), so a lane can still be silenced without a deploy, and it works
534
- // the same in every process whether or not it has an environment. That is the shape to copy if another
535
- // one is ever genuinely needed. `BUILT` remains one edit away for machinery that truly is unfinished.
532
+ // The last of them, the per-language off switch `CLEAROTRON_NATIVE_LANGUAGE_<code>`, is retired too
533
+ // (2026-11-11): no deployment set it, and the owner ruled it removed. `BUILT` remains one edit away for
534
+ // machinery that truly is unfinished.
536
535
 
537
536
  // Admission gate over a RESOLVED policy: null = runnable, else a clarify message. Split from resolution so
538
537
  // the runner can distinguish "which product is this" (resolveSearchPolicy) from "may it run HERE, NOW".
@@ -1115,7 +1114,7 @@ export function loadRecipes({ dir = process.env.CLEAROTRON_RECIPES_DIR || null,
1115
1114
  try { files = readdirSync(join(dir, customer)).filter((f) => f.endsWith(".json")); } catch (e) { if (!absent(e)) throw e; continue; }
1116
1115
  for (const f of files) {
1117
1116
  const slug = f.replace(/\.json$/, "");
1118
- const r = JSON.parse(readFileSync(join(dir, customer, f), "utf8")); // parse error = loud (config bug)
1117
+ const r = readJson(join(dir, customer, f)); // parse error = loud (config bug)
1119
1118
  // A RETIRED extra is dropped here, not refused. Refusing to SAVE one is right — that is the door
1120
1119
  // where somebody is asking for a behaviour that no longer exists. Refusing to LOAD one would be a
1121
1120
  // different and much worse thing: a key that has never done anything would take out every run that
@@ -28,8 +28,9 @@
28
28
  // `writeRO` does, and never touches the directory. Writing into a pool run dir after publish is already
29
29
  // how the product works — pool-admin.mjs rewrites `meta.json` there long after the run settles.
30
30
 
31
- import { writeFileSync, readFileSync, chmodSync } from "node:fs";
31
+ import { writeFileSync, chmodSync } from "node:fs";
32
32
  import { join } from "node:path";
33
+ import { readJson } from "./run-record.mjs";
33
34
 
34
35
  /** The stamp's filename inside the pool run directory. One name, read and written from here only. */
35
36
  export const SETTLE_FILE = "settle.json";
@@ -87,7 +88,7 @@ export function writeSettleStamp(poolRunDir, { state, signoff = null, tier = nul
87
88
  export function readSettleStamp(dir) {
88
89
  if (!dir) return null;
89
90
  try {
90
- const s = JSON.parse(readFileSync(join(dir, SETTLE_FILE), "utf8"));
91
+ const s = readJson(join(dir, SETTLE_FILE));
91
92
  if (!s || typeof s !== "object" || Array.isArray(s)) return null;
92
93
  if (s.schema_version !== SETTLE_SCHEMA_VERSION) return null;
93
94
  if (typeof s.state !== "string" || !s.state) return null;
@@ -132,5 +133,5 @@ export function backfillSettleStamp(poolRunDir, runDir, { readStatus = defaultRe
132
133
 
133
134
  function defaultReadStatus(runDir) {
134
135
  if (!runDir) return null;
135
- try { return JSON.parse(readFileSync(join(runDir, "status.json"), "utf8")); } catch { return null; }
136
+ try { return readJson(join(runDir, "status.json")); } catch { return null; }
136
137
  }
@@ -36,8 +36,8 @@
36
36
  import { readFileSync, writeFileSync, mkdirSync } from "node:fs";
37
37
  import { captureCall, stampVerdict } from "./call-capture.mjs";
38
38
  import { join } from "node:path";
39
- import { driverDir } from "../shared/driver-dir.mjs"; //
40
39
  import { REGISTER_AXES } from "./coverage-ledger.mjs";
40
+ import { paths } from "./run-record.mjs";
41
41
 
42
42
  export const FLAGS_FILE = "skeptic-flags.md";
43
43
 
@@ -56,7 +56,7 @@ export function escalatedAxes(flagsText, axes) {
56
56
 
57
57
  /** Where the call's evidence lives — the driver's own record of what the seat handed it. */
58
58
  export function skepticCallPaths(runDir) {
59
- const dir = driverDir(runDir, "skeptic-calls");
59
+ const dir = paths(runDir).skepticCalls;
60
60
  return { dir, payload: join(dir, "call-001.json") };
61
61
  }
62
62
 
@@ -35,7 +35,7 @@
35
35
  // 0, lines_scanned: N }` — a measured zero, from an instrument the answer itself shows can count.
36
36
  import { readFileSync, realpathSync, statSync } from "node:fs";
37
37
  import { resolve, sep, isAbsolute } from "node:path";
38
- import { DRIVER_DIR } from "../shared/driver-dir.mjs"; //
38
+ import { DRIVER_DIR } from "./run-record.mjs"; //
39
39
  import { answerBudget } from "../shared/answer-parts.mjs"; // the reply size this server was given
40
40
  import { RESEARCH_ANSWERS_MD, RESEARCH_AFTER_REVIEW_MD } from "./research-answers.mjs"; // the two artifacts whose lines come back whole
41
41
 
@@ -40,8 +40,9 @@ instead; and `clearance-search/templates/search-request-form.html`, named only i
40
40
  (`CLEAROTRON_INSTRUCTIONS_DIR`) wins per file, this tree is the fallback, and a configured-but-unreadable overlay throws
41
41
  rather than silently falling back to the Generic defaults.
42
42
  - `../methodology-witness.mjs` — records the sha of every file each stage read, per run.
43
- - `../test/skill-contract-enumerations.test.mjs` and `../test/prose-voice.test.mjs` read these files rather than a
44
- copy: what a skill teaches vs. what the code enforces, and the house prose contract.
43
+ - `../test/every-manual-is-read-and-names-what-exists.test.mjs` and `../test/prose-voice.test.mjs` read these files
44
+ rather than a copy: that every manual is read by a stage and names only tools and files that exist, and the house
45
+ prose contract.
45
46
 
46
47
  ## The provider boundary
47
48
 
@@ -60,10 +61,9 @@ are clean. The authoring rules and the empirical-verification checklist a new pr
60
61
 
61
62
  ## Where to start
62
63
 
63
- `clearance-search/SKILL.md` — the orchestrator's own skill, and the one file describing the whole workflow end to end.
64
- Then `clearance-register/SKILL.md`, the more elaborated of the two execution skills: a spine plus per-mode files
64
+ `clearance-register/SKILL.md`, the more elaborated of the two execution skills: a spine plus per-mode files
65
65
  (`unit.md`, `digest.md`) and per-provider files (`providers/`). The other, `clearance-common-law`, is one spine plus
66
- `perplexity-prompts.md`, its two grid modes (deterministic `grid_spec_path` dispatch vs. the legacy authored
67
- program) being sections inside it — the per-mode split and `providers/` are register-only, not a shape every
66
+ `perplexity-prompts.md` — the per-mode split and `providers/` are register-only, not a shape every
68
67
  execution skill shares. `clearance-search/phase2-execution.md` is methodology, not sequencing — the pipeline is
69
- sequenced in code, in `../stages.mjs` and `../pipeline.mjs`.
68
+ sequenced in code, in `../stages.mjs` and `../pipeline.mjs`. The old orchestrator manual is kept as a record at
69
+ [clearance-search-spine.md](../../docs/architecture/retired-manuals/clearance-search-spine.md); no stage reads it.
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: blind-frame
3
- description: The frame-STARVED independent re-derivation for the v3 preliminary trademark search workflow. **Invoked exclusively by the `clearance-search` orchestrator/driver**, in parallel with the gather sweeps — do not call directly. Reads ONLY the raw instruction (mark, goods, classes, territories, manner of use) and NOT the matter frame, then re-derives the threat model cold across four layers — element + neighbours both directions, field by goods-overlap, sources by real channel, ranking by goods-overlap — and emits a structured model the frame-diff stage diffs against what the run actually scoped. Its job is to test the frame, not to reason inside it.
3
+ description: The frame-STARVED independent re-derivation for the v3 preliminary trademark search workflow. **Run by the driver**, in parallel with the gather sweeps — do not call directly. Reads ONLY the raw instruction (mark, goods, classes, territories, manner of use) and NOT the matter frame, then re-derives the threat model cold across four layers — element + neighbours both directions, field by goods-overlap, sources by real channel, ranking by goods-overlap — and emits a structured model the frame-diff stage diffs against what the run actually scoped. Its job is to test the frame, not to reason inside it.
4
4
  ---
5
5
 
6
6
  ## Purpose
@@ -63,7 +63,6 @@ The tool takes these values, and the shape below is what it validates them again
63
63
 
64
64
  ```json
65
65
  {
66
- "schema_version": 1,
67
66
  "dominant_element": "the spine, verbatim",
68
67
  "variants": [
69
68
  {"value": "VELTRI", "direction": "drop", "rationale": "drop the trailing N — VELTRIN→VELTRI"}