clearotron 0.5.1-beta.2 → 0.6.0-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (379) hide show
  1. package/.env.example +7 -7
  2. package/INSTALL.md +10 -10
  3. package/QUICKSTART.md +6 -6
  4. package/README.md +2 -2
  5. package/THIRD-PARTY-NOTICES.md +4 -4
  6. package/bin/README.md +2 -2
  7. package/bin/clearotron.mjs +1 -1
  8. package/bin/connect.mjs +1 -1
  9. package/bin/disconnect.mjs +1 -1
  10. package/bin/example.mjs +2 -2
  11. package/bin/grant.mjs +1 -1
  12. package/bin/onboard.mjs +78 -23
  13. package/bin/start.mjs +49 -18
  14. package/bin/update.mjs +13 -3
  15. package/build-info.json +2 -2
  16. package/docs/DELIVERY.md +1 -1
  17. package/docs/PORTAL.md +1 -1
  18. package/docs/RELEASES.md +1 -1
  19. package/docs/architecture/02-architecture.md +10 -2
  20. package/docs/architecture/03-run-lifecycle.md +6 -2
  21. package/docs/architecture/04-configuration-reference.md +3 -3
  22. package/docs/architecture/05-config-governance.md +5 -4
  23. package/docs/architecture/08-development-guide.md +4 -4
  24. package/docs/architecture/09-security-and-data.md +1 -1
  25. package/{driver/skills/clearance-search/SKILL.md → docs/architecture/retired-manuals/clearance-search-spine.md} +17 -30
  26. package/{driver/skills/clearance-search/templates/email/generic.md → docs/architecture/retired-manuals/email-generic.md} +1 -1
  27. package/{driver/skills/clearance-search → docs/architecture/retired-manuals}/template-formatting.md +3 -4
  28. package/docs/configuration.md +1 -1
  29. package/docs/decisions/0002-no-dark-functionality.md +5 -0
  30. package/driver/CHANGELOG.md +147 -0
  31. package/driver/README.md +11 -1
  32. package/driver/accepted-order.mjs +13 -5
  33. package/driver/attempt-rows.mjs +64 -0
  34. package/driver/attributed-span.mjs +1 -1
  35. package/driver/authority-trees.mjs +1 -1
  36. package/driver/best-draft.mjs +3 -3
  37. package/driver/blind-frame-record.mjs +2 -2
  38. package/driver/cancel.mjs +3 -2
  39. package/driver/carry-through.mjs +2 -2
  40. package/driver/citation-census.json +3 -3
  41. package/driver/clearance-variants-record.mjs +4 -10
  42. package/driver/common-law-coverage-status.mjs +3 -3
  43. package/driver/common-law-receipts.mjs +2 -2
  44. package/driver/compare.mjs +1 -1
  45. package/driver/config-inventory.mjs +6 -79
  46. package/driver/consumption-ledger.mjs +2 -1
  47. package/driver/contract-dictation-registry.mjs +5 -0
  48. package/driver/contract-e3-backlog.mjs +45 -66
  49. package/driver/contract-e3-baseline.json +16 -16
  50. package/driver/contract-vocabulary.mjs +8 -6
  51. package/driver/corrections-feedforward.mjs +3 -1
  52. package/driver/coverage-form-io.mjs +7 -8
  53. package/driver/coverage-tool.mjs +1 -1
  54. package/driver/declination-tool.mjs +2 -2
  55. package/driver/degraded-parts.mjs +9 -9
  56. package/driver/demo-container.mjs +5 -4
  57. package/driver/deploy-live-run-guard.mjs +19 -7
  58. package/driver/derived-state.mjs +2 -2
  59. package/driver/dev-portal.mjs +2 -1
  60. package/driver/dispatch-record.mjs +1 -1
  61. package/driver/disposition-tool.mjs +2 -1
  62. package/driver/doubt-closure-tool.mjs +2 -2
  63. package/driver/driver.config.mjs +35 -724
  64. package/driver/e2e-rounds.mjs +3 -4
  65. package/driver/engine/CONTRACT.md +3 -0
  66. package/driver/engine/README.md +2 -0
  67. package/driver/engine/anthropic-agent.mjs +8 -37
  68. package/driver/engine/auth.mjs +74 -0
  69. package/driver/engine/child-record.mjs +1 -1
  70. package/driver/engine/deny-authority-write.mjs +2 -2
  71. package/driver/engine/jx-turn.mjs +10 -2
  72. package/driver/engine/mcp/README.md +1 -1
  73. package/driver/engine/mcp/band-server.mjs +6 -6
  74. package/driver/engine/mcp/codex-config.mjs +1 -1
  75. package/driver/engine/mcp/declination-server.mjs +2 -3
  76. package/driver/engine/mcp/dispositions-server.mjs +3 -3
  77. package/driver/engine/mcp/gather-config.mjs +24 -19
  78. package/driver/engine/mcp/grid-provenance.mjs +1 -1
  79. package/driver/engine/mcp/held-answers.mjs +5 -5
  80. package/driver/engine/mcp/perplexity-server.mjs +16 -7
  81. package/driver/engine/mcp/recording-server.mjs +7 -6
  82. package/driver/engine/mcp/register-server.mjs +29 -0
  83. package/driver/engine/mcp/stdio-server.mjs +5 -5
  84. package/driver/engine/mcp/supplemental.mjs +9 -9
  85. package/driver/engine/openai-agent.mjs +5 -2
  86. package/driver/engine/registry.mjs +103 -0
  87. package/driver/engine/run-choices.mjs +162 -0
  88. package/driver/engine/stamps.mjs +35 -0
  89. package/driver/enqueue-schema.mjs +4 -4
  90. package/driver/envelope-settle.mjs +3 -2
  91. package/driver/feedback-issues.mjs +1 -1
  92. package/driver/feedback-mint.mjs +3 -2
  93. package/driver/feedback-store.mjs +3 -2
  94. package/driver/findings-model.mjs +1 -1
  95. package/driver/flag-snapshot.mjs +5 -4
  96. package/driver/floor-duty.mjs +3 -3
  97. package/driver/foreign-record-links.mjs +1 -1
  98. package/driver/frame-diff-record.mjs +2 -8
  99. package/driver/framework.mjs +1 -1
  100. package/driver/gate-metrics.mjs +10 -11
  101. package/driver/gateway.mjs +220 -839
  102. package/driver/goods-evidence.mjs +10 -6
  103. package/driver/jx-lanes.mjs +3 -3
  104. package/driver/jx-units.mjs +31 -37
  105. package/driver/jx.mjs +44 -59
  106. package/driver/knockout-assess-record.mjs +3 -3
  107. package/driver/knockout-caveats.mjs +21 -0
  108. package/driver/knockout-correction-record.mjs +58 -28
  109. package/driver/knockout-frame-record.mjs +2 -2
  110. package/driver/knockout-register-read.mjs +38 -21
  111. package/driver/knockout-register-record.mjs +5 -6
  112. package/driver/knockout-review-record.mjs +12 -11
  113. package/driver/ladder/model-gauge.mjs +88 -0
  114. package/driver/ladder/next-rung.mjs +296 -0
  115. package/driver/ladder/rescue.mjs +146 -0
  116. package/driver/ladder/stage-tools.mjs +57 -0
  117. package/driver/ladder/turn-failure.mjs +166 -0
  118. package/driver/log.mjs +2 -2
  119. package/driver/matter-frame-record.mjs +4 -4
  120. package/driver/methodology-witness.mjs +2 -2
  121. package/driver/narrative-refutation-record.mjs +145 -42
  122. package/driver/one-build-per-run.mjs +62 -0
  123. package/driver/outbox-backoff.mjs +4 -4
  124. package/driver/owner-screen.mjs +0 -10
  125. package/driver/owner-use-check.mjs +2 -28
  126. package/driver/package.json +1 -1
  127. package/driver/partial-payload-baseline.json +1 -1
  128. package/driver/parts-not-completed.mjs +1 -1
  129. package/driver/pipeline-knockout.mjs +1015 -1001
  130. package/driver/pipeline.mjs +511 -9265
  131. package/driver/placement-decisions.mjs +2 -2
  132. package/driver/placement-form-io.mjs +7 -9
  133. package/driver/placement-union.mjs +0 -6
  134. package/driver/plan-stability.mjs +7 -10
  135. package/driver/portal-acks.mjs +3 -2
  136. package/driver/portal-confirmation.mjs +48 -0
  137. package/driver/portal-families.mjs +3 -2
  138. package/driver/portal-local-auth.mjs +1 -2
  139. package/driver/portal-routes/README.md +24 -0
  140. package/driver/portal-routes/admin.mjs +425 -0
  141. package/driver/portal-routes/compose.mjs +66 -0
  142. package/driver/portal-routes/config.mjs +118 -0
  143. package/driver/portal-routes/connect.mjs +283 -0
  144. package/driver/portal-routes/feedback.mjs +178 -0
  145. package/driver/portal-routes/me.mjs +165 -0
  146. package/driver/portal-routes/queue.mjs +64 -0
  147. package/driver/portal-routes/report.mjs +106 -0
  148. package/driver/portal-routes/run.mjs +508 -0
  149. package/driver/portal-routes/runs.mjs +127 -0
  150. package/driver/portal-routes/usage.mjs +82 -0
  151. package/driver/portal-runs.mjs +588 -0
  152. package/driver/portal-service.mjs +78 -2592
  153. package/driver/portal-static.mjs +3 -1
  154. package/driver/predelivery-lint.mjs +92 -9
  155. package/driver/production-pool-guard.mjs +1 -1
  156. package/driver/profiles.mjs +5 -4
  157. package/driver/progress.mjs +29 -24
  158. package/driver/publish/README.md +10 -5
  159. package/driver/publish/archive-tags.mjs +3 -2
  160. package/driver/publish/demo-marking.mjs +2 -2
  161. package/driver/publish/index.mjs +215 -140
  162. package/driver/publish/knockout.mjs +153 -107
  163. package/driver/publish/office-record-links.mjs +22 -0
  164. package/driver/publish/parse.mjs +20 -5
  165. package/driver/publish/pool-admin.mjs +9 -3
  166. package/driver/publish/render.mjs +11 -3
  167. package/driver/publish/report-dates.mjs +3 -4
  168. package/driver/publish/report-registry.mjs +7 -10
  169. package/driver/publish/seed-pool.mjs +3 -2
  170. package/driver/publish/shell.mjs +106 -0
  171. package/driver/publish/templates/report.css +3 -1
  172. package/driver/queue-order.mjs +4 -3
  173. package/driver/record-carry.mjs +0 -9
  174. package/driver/record-discard.mjs +1 -4
  175. package/driver/record-fold.mjs +3 -3
  176. package/driver/record-goods.mjs +5 -5
  177. package/driver/reference-score.mjs +2 -3
  178. package/driver/register-capabilities.mjs +0 -6
  179. package/driver/register-count.mjs +3 -2
  180. package/driver/register-digest-record.mjs +7 -7
  181. package/driver/register-fixture-marker.mjs +3 -3
  182. package/driver/register-plan.mjs +2 -2
  183. package/driver/register-records.mjs +2 -2
  184. package/driver/register-taint.mjs +3 -3
  185. package/driver/register-unit-record.mjs +48 -9
  186. package/driver/register-unreachable.mjs +4 -3
  187. package/driver/registry-fidelity.mjs +79 -34
  188. package/driver/repair-composers.mjs +14 -9
  189. package/driver/repair-digest.mjs +4 -6
  190. package/driver/repair-scope.mjs +3 -3
  191. package/driver/repair-targets.mjs +24 -9
  192. package/driver/repairs.mjs +44 -58
  193. package/driver/replay-archive.mjs +7 -7
  194. package/driver/report-card-record.mjs +3 -3
  195. package/driver/report-overview-record.mjs +4 -4
  196. package/driver/research-answers.mjs +38 -6
  197. package/driver/research-checks.mjs +4 -4
  198. package/driver/result-noun-fields.mjs +28 -11
  199. package/driver/review-addresses.mjs +163 -0
  200. package/driver/rule-shape.mjs +1 -1
  201. package/driver/run-delivered.mjs +340 -0
  202. package/driver/run-economics.mjs +8 -26
  203. package/driver/run-failed.mjs +545 -0
  204. package/driver/run-integrity.mjs +1 -1
  205. package/driver/run-outcome.mjs +314 -0
  206. package/driver/run-park.mjs +23 -0
  207. package/driver/run-quote.mjs +32 -0
  208. package/driver/run-record.mjs +352 -0
  209. package/driver/run-requirements.mjs +22 -0
  210. package/driver/run-shell.mjs +55 -0
  211. package/driver/runner.mjs +71 -33
  212. package/driver/saved-register-pages.mjs +4 -4
  213. package/driver/score-redaction.mjs +2 -2
  214. package/driver/search-policy.mjs +12 -13
  215. package/driver/settle-stamp.mjs +4 -3
  216. package/driver/skeptic-record.mjs +2 -2
  217. package/driver/skeptic-search.mjs +1 -1
  218. package/driver/skills/README.md +7 -7
  219. package/driver/skills/blind-frame/SKILL.md +1 -2
  220. package/driver/skills/case-law-citation/SKILL.md +9 -37
  221. package/driver/skills/case-law-citation/sources/courtlistener.md +1 -3
  222. package/driver/skills/case-law-citation/sources/eurlex.md +8 -11
  223. package/driver/skills/case-law-citation/sources/legaldatahunter.md +1 -1
  224. package/driver/skills/clearance-common-law/SKILL.md +45 -111
  225. package/driver/skills/clearance-common-law/perplexity-prompts.md +7 -79
  226. package/driver/skills/clearance-register/SKILL.md +15 -33
  227. package/driver/skills/clearance-register/digest.md +31 -92
  228. package/driver/skills/clearance-register/providers/clarivate.md +2 -2
  229. package/driver/skills/clearance-register/providers/corsearch.md +5 -5
  230. package/driver/skills/clearance-register/providers/euipo.md +1 -2
  231. package/driver/skills/clearance-register/providers/free-tier.md +0 -19
  232. package/driver/skills/clearance-register/providers/signa.md +6 -25
  233. package/driver/skills/clearance-register/providers/uspto-local.md +0 -24
  234. package/driver/skills/clearance-register/register-recipes.md +8 -15
  235. package/driver/skills/clearance-register/status-rules.md +6 -24
  236. package/driver/skills/clearance-register/unit.md +11 -20
  237. package/driver/skills/clearance-search/delivery-contract.md +24 -120
  238. package/driver/skills/clearance-search/field-doctrine-pharma.md +1 -5
  239. package/driver/skills/clearance-search/firm-wide-reasoning.md +24 -43
  240. package/driver/skills/clearance-search/phase2-execution.md +29 -77
  241. package/driver/skills/clearance-search/report-prose.md +3 -4
  242. package/driver/skills/clearance-search/risk-framework-demo.md +1 -1
  243. package/driver/skills/clearance-search/risk-framework-triage.manifest.json +3 -3
  244. package/driver/skills/clearance-search/risk-framework-triage.md +7 -9
  245. package/driver/skills/clearance-search/risk-framework.manifest.json +1 -1
  246. package/driver/skills/clearance-search/risk-framework.md +1 -1
  247. package/driver/skills/clearance-search/synthesis-rules.md +30 -107
  248. package/driver/skills/clearance-search/worked-examples.md +5 -5
  249. package/driver/skills/clearance-variants/SKILL.md +46 -45
  250. package/driver/skills/clearance-variants/transliteration-scripts.md +4 -4
  251. package/driver/skills/frame-diff/SKILL.md +1 -1
  252. package/driver/skills/knockout-assess/SKILL.md +6 -14
  253. package/driver/skills/knockout-frame/SKILL.md +1 -1
  254. package/driver/skills/matter-frame/SKILL.md +7 -12
  255. package/driver/skills/matter-frame/watchlist-reference.md +1 -4
  256. package/driver/skills/narrative-refutation/SKILL.md +20 -30
  257. package/driver/skills/placement-inquiry/SKILL.md +8 -18
  258. package/driver/skills-store-provenance.mjs +1 -1
  259. package/driver/stage-context.mjs +32 -35
  260. package/driver/stage-freshness.mjs +127 -11
  261. package/driver/stages-knockout.mjs +49 -22
  262. package/driver/stages.mjs +88 -283
  263. package/driver/status-snapshot.mjs +2 -1
  264. package/driver/steps/correction-cycle.mjs +311 -0
  265. package/driver/steps/corrections.mjs +644 -0
  266. package/driver/steps/delivery.mjs +1287 -0
  267. package/driver/steps/frame-comparison.mjs +922 -0
  268. package/driver/steps/intake.mjs +84 -0
  269. package/driver/steps/open-run.mjs +419 -0
  270. package/driver/steps/overview-and-cards.mjs +899 -0
  271. package/driver/steps/placement-and-digest.mjs +23 -0
  272. package/driver/steps/register-sweep.mjs +1563 -0
  273. package/driver/steps/skeptic-and-follow-up.mjs +831 -0
  274. package/driver/steps/synthesis.mjs +261 -0
  275. package/driver/steps/verdict-gate.mjs +968 -0
  276. package/driver/suite-census.json +403 -91
  277. package/driver/surface-exit-verdict.mjs +0 -8
  278. package/driver/synthesis-record.mjs +72 -6
  279. package/driver/terminal-clamp.mjs +10 -0
  280. package/driver/tokens.mjs +8 -62
  281. package/driver/tool-calls.mjs +2 -2
  282. package/driver/unit-state-verdict.mjs +1 -1
  283. package/driver/usage-ledger.mjs +2 -1
  284. package/driver/verify-knockout.mjs +20 -35
  285. package/driver/verify.mjs +47 -36
  286. package/driver/web-grid.mjs +3 -4
  287. package/driver/whatif-memo-run.mjs +2 -2
  288. package/driver/whatif-queue.mjs +4 -3
  289. package/driver/withheld-families.mjs +14 -15
  290. package/driver/worker-heartbeat.mjs +3 -2
  291. package/driver/write-up-form.mjs +0 -3
  292. package/mcp-server/CHANGELOG.md +8 -0
  293. package/mcp-server/http-server.mjs +1 -1
  294. package/mcp-server/lib/brief.mjs +22 -4
  295. package/mcp-server/lib/events.mjs +2 -2
  296. package/mcp-server/lib/evidence.mjs +3 -2
  297. package/mcp-server/lib/findings.mjs +2 -1
  298. package/mcp-server/lib/knockout.mjs +9 -10
  299. package/mcp-server/lib/ops.mjs +9 -9
  300. package/mcp-server/lib/runs.mjs +9 -10
  301. package/mcp-server/lib/trace.mjs +1 -1
  302. package/mcp-server/lib/whatif.mjs +2 -3
  303. package/mcp-server/package.json +1 -1
  304. package/mcp-server/server.mjs +5 -5
  305. package/package.json +2 -1
  306. package/portal-ui/dist/assets/{index-fPqAU0sx.js → index-D5rkCjDc.js} +26 -14
  307. package/portal-ui/dist/index.html +1 -1
  308. package/portal-ui/package.json +3 -3
  309. package/providers/README.md +1 -1
  310. package/providers/_shared/answer-memory.mjs +4 -5
  311. package/providers/_shared/execute-plan.mjs +48 -1
  312. package/providers/_shared/records-from-search.mjs +46 -0
  313. package/providers/clarivate/README.md +2 -2
  314. package/providers/clarivate/src/adapter.js +147 -0
  315. package/providers/clarivate/src/core.js +1 -14
  316. package/{driver/engine/mcp/clarivate-server.mjs → providers/clarivate/src/mount.js} +5 -10
  317. package/providers/corsearch/README.md +3 -3
  318. package/providers/corsearch/src/adapter.js +80 -0
  319. package/providers/corsearch/src/core.js +14 -11
  320. package/{driver/engine/mcp/corsearch-server.mjs → providers/corsearch/src/mount.js} +5 -10
  321. package/providers/euipo/README.md +2 -2
  322. package/providers/euipo/src/adapter.js +85 -0
  323. package/providers/euipo/src/core.js +1 -1
  324. package/providers/euipo/src/euipo-client.js +1 -2
  325. package/{driver/engine/mcp/euipo-server.mjs → providers/euipo/src/mount.js} +5 -10
  326. package/providers/free-tier/README.md +2 -2
  327. package/providers/free-tier/src/adapter.js +127 -0
  328. package/{driver/engine/mcp/free-tier-server.mjs → providers/free-tier/src/mount.js} +5 -10
  329. package/providers/jx-subclass/coverage.mjs +1 -6
  330. package/providers/jx-subclass/score-truth.mjs +2 -1
  331. package/providers/oauth-mcp-bridge/CHANGELOG.md +8 -0
  332. package/providers/oauth-mcp-bridge/package.json +1 -1
  333. package/providers/perplexity/src/core.js +2 -2
  334. package/providers/signa/README.md +2 -2
  335. package/providers/signa/src/adapter.js +157 -0
  336. package/providers/signa/src/capabilities.js +0 -3
  337. package/providers/signa/src/core.js +2 -2
  338. package/{driver/engine/mcp/signa-server.mjs → providers/signa/src/mount.js} +7 -12
  339. package/providers/signa/src/offices.generated.js +17 -15
  340. package/providers/uspto-local/README.md +1 -1
  341. package/providers/uspto-local/bin/verify-index.mjs +1 -1
  342. package/providers/uspto-local/src/adapter.js +75 -0
  343. package/{driver/engine/mcp/uspto-local-server.mjs → providers/uspto-local/src/mount.js} +5 -10
  344. package/scripts/band-shape-probe.mjs +2 -2
  345. package/scripts/citation-line-check.mjs +7 -7
  346. package/scripts/compare.mjs +1 -1
  347. package/scripts/dead-names.mjs +2 -2
  348. package/scripts/e2e-first-time.mjs +19 -7
  349. package/scripts/e2e.mjs +13 -13
  350. package/scripts/engine-probe.mjs +1 -1
  351. package/scripts/env-audit.mjs +7 -4
  352. package/scripts/env-classify.mjs +5 -1
  353. package/scripts/feedback-mint.mjs +1 -1
  354. package/scripts/freeze-example-run.mjs +7 -7
  355. package/scripts/mint-suite-census.mjs +2 -2
  356. package/scripts/nightly-notice.mjs +1 -1
  357. package/scripts/release-cut-decision.mjs +7 -2
  358. package/scripts/release-note-required.mjs +26 -9
  359. package/scripts/release-notes-lint.mjs +3 -2
  360. package/scripts/release-version-pr-checks.mjs +1 -1
  361. package/scripts/settings-render-check.mjs +23 -3
  362. package/scripts/test-run.mjs +5 -5
  363. package/scripts/travelling-predicates.mjs +1 -1
  364. package/scripts/undeclared-field-census.mjs +1 -1
  365. package/scripts/unexecuted-asserts.mjs +1 -1
  366. package/scripts/verify-publishable.mjs +1 -1
  367. package/shared/client-door.mjs +1 -1
  368. package/shared/connect-clients.mjs +1 -1
  369. package/shared/connector-signin-probe.mjs +1 -1
  370. package/shared/env-aliases.mjs +1 -1
  371. package/shared/invocation.mjs +14 -2
  372. package/shared/names-in-force.mjs +2 -0
  373. package/shared/register-selection.mjs +2 -2
  374. package/shared/store-in-repo.mjs +3 -3
  375. package/shared/summary-blocks.mjs +0 -3
  376. package/shared/trigger-lane.mjs +1 -1
  377. package/shared/vacuous-pass.mjs +2 -2
  378. package/shared/verb-shim.mjs +4 -2
  379. package/node_modules/exceljs/README.md +0 -3023
@@ -37,7 +37,7 @@
37
37
 
38
38
  import { readFileSync, writeFileSync, readdirSync, existsSync, statSync, copyFileSync } from "node:fs";
39
39
  import { join } from "node:path";
40
- import { DRIVER_DIR } from "../shared/driver-dir.mjs"; //
40
+ import { DRIVER_DIR, readJsonOrNull } from "./run-record.mjs";
41
41
 
42
42
  export const RECEIPT_VERSION = 2;
43
43
 
@@ -49,7 +49,6 @@ export function receiptPath(poolRoot, id) {
49
49
  return join(String(poolRoot ?? ""), "..", `_e2e-doors-${String(id).toUpperCase()}.json`);
50
50
  }
51
51
 
52
- const readJson = (p) => { try { return JSON.parse(readFileSync(p, "utf8")); } catch { return null; } };
53
52
  const iso = (ms) => new Date(ms).toISOString();
54
53
 
55
54
  /**
@@ -281,7 +280,7 @@ export function findRunsByRef(ref, workspaceRoot) {
281
280
  for (const e of entries) {
282
281
  const p = join(dir, e.name);
283
282
  if (e.isFile() && e.name === "status.json") {
284
- const st = readJson(p);
283
+ const st = readJsonOrNull(p);
285
284
  if (st && String(st.ref ?? "").startsWith(String(ref))) {
286
285
  let mtime = 0;
287
286
  try { mtime = statSync(p).mtimeMs; } catch { /* the sort key degrades; the hit still counts */ }
@@ -410,7 +409,7 @@ export function selectRound(rounds, requestedToken = null) {
410
409
  */
411
410
  export function previousRunDir({ refs = [], workspaceRoot = null, runDir = null } = {}) {
412
411
  if (!runDir) return { error: "no run dir given — previousRunDir needs the run it should find the predecessor of" };
413
- const st = readJson(join(runDir, "status.json"));
412
+ const st = readJsonOrNull(join(runDir, "status.json"));
414
413
  if (!st) return { error: `${join(runDir, "status.json")} is missing or does not parse — a run's own ref is the only way to say which round it belongs to` };
415
414
  const thisRef = String(st.ref ?? "");
416
415
  if (!thisRef) return { error: `${join(runDir, "status.json")} carries no \`ref\`, so this run belongs to no nameable round` };
@@ -102,6 +102,9 @@ These are the one place the record holds the program's words: an expired sign-in
102
102
  `stop_sequence` and nothing else. `stopReason` stays verbatim beside them, and none of the three moves a
103
103
  verdict.
104
104
 
105
+ An adapter whose repair turns need a home that outlasts one turn also exports `makeStageHome(stage)` and
106
+ `releaseStageHome(home)`; `runStage` makes the home once per stage and passes it to each turn as `stageHome`.
107
+
105
108
  `runStage()` folds that into what the pipeline consumes — `{ok, json, attempts, text, sessionKey, …}` —
106
109
  and journals usage/wall/status on the way past.
107
110
 
@@ -16,6 +16,8 @@ does not exist — that is the design, and [`CONTRACT.md`](CONTRACT.md) is the d
16
16
  | `auth.mjs` | `resolveAuthMode()` — subscription, API key or (Claude only) cloud account, resolved once per turn and stamped on the telemetry |
17
17
  | `probe.mjs` | Drives one cheap turn through whichever adapter is configured, to prove the engine can complete a turn at all. What `npm run setup` spends |
18
18
  | `common.mjs` | Helpers both adapters share |
19
+ | `registry.mjs` | Which adapters this driver ships and which one `CLEAROTRON_AI` selects; the gateway asks it and names no engine |
20
+ | `stamps.mjs` | What the `engine` word on a saved attempt row means: the vendor billed, how its model is keyed, whether it is a native-language row |
19
21
  | `deny-authority-write.mjs` | A PreToolUse hook. `--add-dir` has no read-only form, so the read-only intent over the skills tree is enforced here |
20
22
  | [`mcp/`](mcp/README.md) | The tool servers a stage mounts, and the per-stage grant table |
21
23
 
@@ -21,8 +21,8 @@ import { statSync } from "node:fs";
21
21
  import { tmpdir } from "node:os";
22
22
  import { join, dirname } from "node:path";
23
23
  import { fileURLToPath } from "node:url";
24
- import { resolveSpawnCwd, spawnGraceMs } from "./common.mjs";
25
- import { resolveEngineProgram } from "../driver.config.mjs"; // — the one place that finds the program; it reads every spelling of the setting
24
+ import { WRITE_DISCIPLINE, absolutizeSkillRefs, resolveSpawnCwd, spawnGraceMs } from "./common.mjs";
25
+ import { resolveEngineProgram, resolveModel } from "../driver.config.mjs"; // — the one place that finds the program; it reads every spelling of the setting
26
26
  import { authorityTrees } from "../authority-trees.mjs";
27
27
  import { recordEngineChild, clearEngineChild } from "./child-record.mjs"; //
28
28
  import { engineEnv } from "./engine-env.mjs"; // — the program's environment, by list (see spawnEnv)
@@ -202,7 +202,7 @@ export function claudeModel(model) {
202
202
  // does not know, it says so and the turn fails loudly — which is the honest end of a bad pin.
203
203
  return /^claude-(?:[a-z]+-\d|\d)/.test(bare) ? bare : fam;
204
204
  }
205
- throw new Error(`anthropic-agent: no claude model mapped for "${model}" — this engine runs claude only. Pass opus/sonnet/haiku/fable or a concrete claude-* id. (It used to substitute sonnet silently and log the alias you asked for: #238 corruption 3.)`);
205
+ throw new Error(`anthropic-agent: no claude model mapped for "${model}" — this engine runs claude only. Pass opus/sonnet/haiku/fable or a concrete claude-* id. (It used to substitute sonnet silently and log the alias you asked for.)`);
206
206
  }
207
207
 
208
208
  // ── thinking tier → `claude --effort` ────────────────────────────────────────────────────────────────
@@ -239,39 +239,8 @@ export function mapUsage(u) {
239
239
  return { input, output, cacheRead, cacheWrite, total: input + output + cacheRead + cacheWrite };
240
240
  }
241
241
 
242
- // The Write-tool discipline the stages assume but claude -p doesn't infer from "write your output to <path>".
243
- // Byte-identical with engine/common.mjs's copy (this module deliberately imports nothing but node built-ins);
244
- // engine.common.test.mjs asserts the two never drift. See that copy's header for the repair exception's why.
245
- export const WRITE_DISCIPLINE =
246
- "OUTPUT DISCIPLINE — read carefully: when the task instructs you to write output to an absolute file path, " +
247
- "you MUST create that file by CALLING THE WRITE TOOL with that exact path and the full content. Output you " +
248
- "place only in your text reply is DISCARDED and the task is scored as FAILED. Do the actual work, write every " +
249
- "required file via the Write tool (overwrite if it exists), and only THEN reply — with just the path(s) you " +
250
- "wrote and a 2-3 line summary. Never claim a file is written unless you invoked the Write tool to write it. " +
251
- "EXCEPTION — REPAIRS: when the task instructs you to FIX or CORRECT an EXISTING file, use the Edit tool and " +
252
- "change only what the correction names — a file corrected with the Edit tool counts as written. Rewriting a " +
253
- "whole file to fix a few lines risks degrading content that already passed. If the file does not exist, the " +
254
- "rule above stands: create it in full with the Write tool.";
255
-
256
- // The shared stage prompts reference skills by the convention `skills/foo/SKILL.md` — a workspace agent
257
- // resolves these against its workspace cwd, but `claude -p` (cwd = a neutral tmpdir, to avoid loading the
258
- // repo CLAUDE.md) resolves them against /tmp → missing_file (the 2026-06-16 matter-frame blocker). Rewrite
259
- // every `skills/…md` token to an ABSOLUTE path under the configured compute-skills tree (`config.skillsDir`,
260
- // default <driverDir>/skills as of the Phase-3 skills move; was <workspaceDir>/skills before). The refs keep
261
- // their `skills/` prefix, so we join them onto the PARENT of skillsDir — i.e. join(dirname(skillsDir),
262
- // "skills/foo.md"). Engine-localized: the caller's original message is NEVER mutated. The
263
- // negative lookbehind on [\w/.] makes the rewrite IDEMPOTENT — an already-absolute path that contains
264
- // `skills/` (the rewritten form, or a corrective/warm re-wrap of an absolutized message) is preceded by
265
- // `/` and so is never double-prefixed.
266
- const SKILL_REF = /(?<![\w/.])skills\/[A-Za-z0-9._/-]+\.md/g;
267
- // `resolve` (optional) maps a `skills/...` ref to the file that should actually be read — the layered
268
- // overlay-over-base lookup (driver.config.resolveSkillPath). Without it the legacy single-dir behaviour
269
- // stands, so this stays a pure function over its inputs and every existing caller/test is unaffected.
270
- export function absolutizeSkillRefs(message, skillsDir, resolve = null) {
271
- if (!message || (!skillsDir && !resolve)) return message;
272
- const base = skillsDir ? dirname(skillsDir) : null; // skillsDir ends in /skills; refs carry their own `skills/` prefix
273
- return message.replace(SKILL_REF, (m) => (resolve ? resolve(m) : join(base, m)));
274
- }
242
+ // The Write-tool discipline and the skill-reference rewrite are shared with the Codex adapter: engine/common.mjs.
243
+ export { WRITE_DISCIPLINE, absolutizeSkillRefs };
275
244
 
276
245
  // Returns { args, input }: `args` is the flag list with `-p` as a BARE flag (no positional prompt), and
277
246
  // `input` is the absolutized prompt to write to the child's STDIN. The prompt is NOT an argv element:
@@ -499,7 +468,7 @@ export function writeBoundarySettings({ skillsRoots = [], profilesDir = null, ru
499
468
  // and ships with it, so "missing" means a broken deploy, and a broken deploy that stops loudly beats one
500
469
  // that runs every clearance with no boundary and says nothing.
501
470
  try { statSync(hook); }
502
- catch { throw new Error(`write_boundary_hook_missing:${hook} (the #595 deny-hook is not in this deployment; a missing hook command fails OPEN in the CLI, so the dispatch is refused rather than run unprotected)`); }
471
+ catch { throw new Error(`write_boundary_hook_missing:${hook} (the deny-hook is not in this deployment; a missing hook command fails OPEN in the CLI, so the dispatch is refused rather than run unprotected)`); }
503
472
  const payload = Buffer.from(JSON.stringify({ trees, runDir: runDir ?? null }), "utf8").toString("base64");
504
473
  return JSON.stringify({
505
474
  hooks: {
@@ -537,6 +506,8 @@ export const anthropicAgentEngine = {
537
506
  // doctrine tree, the profile store and `<runDir>/_driver/` at the moment of the write. That is a real
538
507
  // boundary and this engine has it.
539
508
  writeBoundary: "enforced",
509
+ // The id a turn's rows record as asked for: the tier through Claude's catalog, `opus` → `anthropic/claude-opus`.
510
+ resolveModelId(model) { return resolveModel(model); },
540
511
  async runTurn({ message, model, thinking, timeoutSec, resumeRef, mcpConfig, allowedTools, cwd, skillsDir, skillsGrantRoots, profilesDir, resolveSkill, runDir, seatWrites = null, grantDispatch = null, stallSec, progressFiles, streamFile = null } = {}) {
541
512
  if (!message) throw new Error("anthropic-agent.runTurn: message is required");
542
513
  const { args, input, grantNote } = buildClaudeArgs({ message, model, thinking, resumeRef, mcpConfig, allowedTools, cwd, skillsDir, skillsGrantRoots, profilesDir, resolveSkill, runDir, seatWrites, grantDispatch });
@@ -168,3 +168,77 @@ export function resolveAuthMode({ engineName, env = process.env } = {}) {
168
168
 
169
169
  return { provider: name || "unknown", mode: "unknown", apiBilled: false };
170
170
  }
171
+
172
+ /**
173
+ * What a reader calls the account a cloud mode bills: "Google Cloud", "Microsoft Azure", "Amazon Bedrock"
174
+ * or "Gateway". Null for no cloud.
175
+ *
176
+ * ONE TABLE OF CLOUD NAMES, NOT TWO. `CLOUD_CREDENTIAL_CHECK` in engine/auth.mjs already names each cloud
177
+ * the way a reader knows it, for the advice a refused sign-in prints, and this reads it rather than keeping
178
+ * a second list that could name a cloud differently on the page. It writes the gateway "the gateway", for
179
+ * use inside a sentence; a label on a page drops the article and starts with a capital, and that one
180
+ * adjustment is the whole of what this adds.
181
+ */
182
+ export function cloudName(cloud) {
183
+ const who = CLOUD_CREDENTIAL_CHECK[cloud]?.who;
184
+ if (!who) return null;
185
+ const bare = who.replace(/^the /, "");
186
+ return bare.charAt(0).toUpperCase() + bare.slice(1);
187
+ }
188
+
189
+ /**
190
+ * WHY A BILLING SETTING REFUSES EVERY SEARCH, as data: which refusal it is and the names involved, so the
191
+ * config page words it once, in plain English, without reading the resolver's sentence apart.
192
+ *
193
+ * `kind` is one of:
194
+ * switch-beside-mode subscription or api-key, and a cloud's switch on beside it (`clouds`)
195
+ * two-clouds cloud, and more than one cloud switched on (`clouds`)
196
+ * no-cloud cloud, and no cloud switched on and no gateway address (`clouds` lists every
197
+ * switch, and `gateway` the gateway's setting, as the choices to make)
198
+ * not-a-mode a word that is not a billing mode (`modes` are the ones this engine takes)
199
+ * cloud-on-codex cloud, on the Codex engine, which a cloud account cannot pay for (`engineSetting`
200
+ * and `engineChoice` name the Claude engine only where it would pay: one cloud
201
+ * switched on, or none and a gateway address; otherwise that move is one more refusal)
202
+ * unclassified a refusal this list does not name; the page says only that searches are refused.
203
+ * Not "other": that is an assistant's id in connect-clients.mjs, and a surface may
204
+ * not name one in code
205
+ *
206
+ * `defaulted` says the billing setting is blank, so `subscription` is the default and not a word anybody
207
+ * wrote: a page that said "payment is set to subscription" would send a reader looking for a line their
208
+ * settings file does not have. It is the state measured on Foundry, a switch on and the word unset.
209
+ *
210
+ * THE SAME PREDICATES AS THE RESOLVER, IN ITS ORDER. `resolveAuthMode` refuses by throwing a sentence and
211
+ * nothing else, so the kind is read back from the same environment through the same functions it uses
212
+ * (`billingMode`, `cloudsSwitchedOn`), in the order it checks them. Called only once it has thrown.
213
+ *
214
+ * NAMES, NEVER A VALUE. `mode` is sent only when it is one of the three modes; the word in a `not-a-mode`
215
+ * refusal is whatever was typed, and it is not sent at all.
216
+ */
217
+ export function billingRefusalReason(id, env = process.env) {
218
+ const mode = billingMode(env);
219
+ const setting = "CLEAROTRON_AI_BILLING";
220
+ const clouds = (ids) => ids.map((c) => ({ name: cloudName(c), setting: CLOUD_SWITCH[c] }));
221
+ const defaulted = String(env[setting] ?? "").trim() === "";
222
+ const base = { setting, mode: null, defaulted, clouds: [], modes: [], gateway: null, engineSetting: null, engineChoice: null };
223
+ if (id === "openai-agent") {
224
+ if (mode === "cloud") {
225
+ // The resolver's own test for a cloud the Claude engine would pay through, in its words: one switch,
226
+ // or no switch and a gateway address.
227
+ const on = cloudsSwitchedOn(env);
228
+ const claudeWouldPay = on.length === 1 || (!on.length && Boolean(env.ANTHROPIC_BASE_URL));
229
+ return { ...base, kind: "cloud-on-codex", mode, modes: ["subscription", "api-key"],
230
+ ...(claudeWouldPay ? { engineSetting: "CLEAROTRON_AI", engineChoice: "anthropic-agent" } : {}) };
231
+ }
232
+ if (mode !== "subscription" && mode !== "api-key") return { ...base, kind: "not-a-mode", modes: ["subscription", "api-key"] };
233
+ }
234
+ if (id === "anthropic-agent") {
235
+ const on = cloudsSwitchedOn(env);
236
+ if ((mode === "subscription" || mode === "api-key") && on.length) return { ...base, kind: "switch-beside-mode", mode, clouds: clouds(on) };
237
+ if (mode === "cloud" && on.length > 1) return { ...base, kind: "two-clouds", mode, clouds: clouds(on) };
238
+ if (mode === "cloud" && !on.length) {
239
+ return { ...base, kind: "no-cloud", mode, clouds: clouds(Object.keys(CLOUD_SWITCH)), gateway: "ANTHROPIC_BASE_URL" };
240
+ }
241
+ if (!BILLING_MODES.includes(mode)) return { ...base, kind: "not-a-mode", modes: [...BILLING_MODES] };
242
+ }
243
+ return { ...base, kind: "unclassified", mode: BILLING_MODES.includes(mode) ? mode : null };
244
+ }
@@ -44,7 +44,7 @@
44
44
 
45
45
  import { writeFileSync, readFileSync, rmSync } from "node:fs";
46
46
  import { spawnSync } from "node:child_process";
47
- import { driverDir } from "../../shared/driver-dir.mjs";
47
+ import { driverDir } from "../run-record.mjs";
48
48
  import { procStarttime, parseClaimSidecar } from "../claim-liveness.mjs";
49
49
  import { endWindowsTree } from "./engine-spawn.mjs"; // Windows has no process group to signal
50
50
 
@@ -45,7 +45,7 @@
45
45
 
46
46
  import { readFileSync, appendFileSync } from "node:fs";
47
47
 
48
- import { driverDir } from "../../shared/driver-dir.mjs"; //
48
+ import { paths } from "../run-record.mjs"; //
49
49
  import { denyReason } from "../authority-trees.mjs";
50
50
  import { isEntrypoint } from "../../shared/is-entrypoint.mjs"; //
51
51
 
@@ -136,7 +136,7 @@ const deny = (reason) => {
136
136
  // journal lands, because a boundary that depends on a successful write is not one.
137
137
  function journal(runDir, row) {
138
138
  if (!runDir) return;
139
- try { appendFileSync(driverDir(runDir, "authority-denials.jsonl"), JSON.stringify(row) + "\n"); } catch { /* the deny still stands */ }
139
+ try { appendFileSync(paths(runDir).authorityDenials, JSON.stringify(row) + "\n"); } catch { /* the deny still stands */ }
140
140
  }
141
141
 
142
142
  function main() {
@@ -132,15 +132,23 @@ export async function makeJxTurnRunner({
132
132
  thinking = JX_THINKING,
133
133
  // Names the lane in the one message a caller shows a human when the configuration refuses.
134
134
  lane = "the jx lanes",
135
+ // The run the lanes serve. A run that recorded its engine when it started keeps it here as its stages do
136
+ // (engine/run-choices.mjs), so its lanes never run on another engine. Absent, or a run with no record: the
137
+ // machine's setting, read as below.
138
+ runDir = null,
135
139
  } = {}) {
140
+ const rec = runDir ? (await import("./run-choices.mjs")).readRunChoices(runDir) : { state: "none" };
141
+ if (rec.state === "unreadable") return { error: `this run's engine record ${rec.detail}, so ${lane} do not run on the machine's engine in its place` };
142
+ if (rec.state === "recorded" && !ENGINE_BINARIES[rec.engine])
143
+ return { error: `this run started on the "${rec.engine}" engine, which this driver does not ship; ${lane} keep that engine rather than switch` };
136
144
  // NO AI CHOSEN IS NOT THE DEFAULT AI. With CLEAROTRON_AI unset this door resolved the code's default, so an
137
145
  // install with no AI chosen got a turn runner on that AI's program, billed to whatever it was signed in to:
138
146
  // the portal booted "brief reading ON — engine=anthropic-agent", and Describe-it would have spent a turn
139
147
  // there (measured on a fresh install of 0.5.1-beta.0, 2026-11-07). A search with no AI chosen is refused at
140
148
  // order time, before a lane could ask; the portal's reader asks at boot. So the door refuses here, in the
141
149
  // order-time gate's own words, and reads the setting as that gate reads it: blank is not chosen.
142
- if (!String(env.CLEAROTRON_AI ?? "").trim()) return { error: whatIsMissing([{ about: "ai" }]) };
143
- const id = String(env.CLEAROTRON_AI).trim().toLowerCase();
150
+ if (rec.state !== "recorded" && !String(env.CLEAROTRON_AI ?? "").trim()) return { error: whatIsMissing([{ about: "ai" }]) };
151
+ const id = rec.state === "recorded" ? rec.engine : String(env.CLEAROTRON_AI).trim().toLowerCase();
144
152
  if (!ENGINE_BINARIES[id]) return { error: `CLEAROTRON_AI=${id} is not an engine this driver ships` };
145
153
 
146
154
  let auth;
@@ -54,7 +54,7 @@ wiring as a `config.toml` through `codex-config.mjs`, and `../../test/engine.gat
54
54
  | `codex-config.mjs` | The same wiring rendered as a codex `config.toml`, so `gather-config.mjs` stays the one source |
55
55
  | `stdio-server.mjs` | `serve()` — the shared JSON-RPC stdio scaffolding, and the writer of the per-run `_driver/tool-calls.jsonl`, where a `started` line with no `settled` line is the only evidence that a killed call ever happened |
56
56
  | `http-dispatcher.mjs` | Side-effect import: raises undici's 300s headers timeout for long grid/register calls |
57
- | `corsearch-server.mjs`, `clarivate-server.mjs`, `euipo-server.mjs`, `signa-server.mjs`, `uspto-local-server.mjs`, `free-tier-server.mjs` | One per register provider, all under the neutral `register_*` names |
57
+ | `register-server.mjs` | The one server for every register provider, mounting `providers/<id>/src/mount.js` by name, under the neutral `register_*` names |
58
58
  | `supplemental.mjs` | Mint-and-execute for model-proposed register queries; bound by each server that serves `register_propose_supplemental` |
59
59
  | `perplexity-server.mjs` | `perplexity_research` (the common-law grid and open-web research); calls the Perplexity agent API under `PERPLEXITY_API_KEY`. It served `record_dispositions` too until — a record tool on a key FOUR stages hold, so three of them were granted a writer into the common-law lane's ruling ledger that no doctrine of theirs ordered |
60
60
  | `band-server.mjs` | Read-only lookups over the run's frozen register band; every call appended to the reading audit |
@@ -18,7 +18,7 @@
18
18
  // CLEAROTRON_GATHER_SESSION_KEY / CLEAROTRON_GATHER_AGENT (attribution for the reading log).
19
19
  import { readFileSync, readdirSync, appendFileSync, existsSync, mkdirSync } from "node:fs";
20
20
  import { join, dirname } from "node:path";
21
- import { driverDir } from "../../../shared/driver-dir.mjs"; //
21
+ import { paths, readJson } from "../../run-record.mjs"; //
22
22
  import { serve } from "./stdio-server.mjs";
23
23
  import { answerBudget, quotedBytes } from "../../../shared/answer-parts.mjs";
24
24
  import { classifyRecord, prepareTargets, SHAPE_TIERS, isLiveRecord, niceClassKey, withoutPlacementOrders } from "../../band-shape.mjs";
@@ -34,9 +34,9 @@ const SESSION = process.env.CLEAROTRON_GATHER_SESSION_KEY || "";
34
34
  const AGENT = process.env.CLEAROTRON_GATHER_AGENT || "";
35
35
 
36
36
  const bandPath = () => join(RUN_DIR, "register-named-band.json");
37
- const shapeJsonPath = () => driverDir(RUN_DIR, "band-shape.json");
37
+ const shapeJsonPath = () => paths(RUN_DIR).bandShape;
38
38
  const shapeMdPath = () => join(RUN_DIR, "band-shape.md");
39
- const readingLogPath = () => driverDir(RUN_DIR, "reading-log.jsonl");
39
+ const readingLogPath = () => paths(RUN_DIR).readingLog;
40
40
  // — THE RUN'S OWN RECORD LEDGER, which this tool did not know about.
41
41
  //
42
42
  // A fetch writes here; `_records/` is populated from it by a union that does not run until the END of
@@ -48,7 +48,7 @@ const readingLogPath = () => driverDir(RUN_DIR, "reading-log.jsonl");
48
48
  //
49
49
  // Run-scoped by construction, so no prefix filter is needed: this file lives in the run dir and every
50
50
  // line in it belongs to this run.
51
- const recordLedgerPath = () => driverDir(RUN_DIR, "register-record-bodies.jsonl");
51
+ const recordLedgerPath = () => paths(RUN_DIR).registerRecordBodies;
52
52
 
53
53
  /**
54
54
  * The record body this run has already fetched, or null.
@@ -88,7 +88,7 @@ function logRead(tool, args, result) {
88
88
  } catch { /* best-effort — a log failure must never break a lookup */ }
89
89
  }
90
90
 
91
- const loadJson = (p) => JSON.parse(readFileSync(p, "utf8"));
91
+ const loadJson = (p) => readJson(p);
92
92
 
93
93
  // ── bounded serving: the transport cap is TOKENS, not the 256KB Read cap ─────────────────────────────────
94
94
  // The engine carries a tool result over MCP, and claude -p caps one tool output at
@@ -232,7 +232,7 @@ function resolveRecordFile(dir, uri) {
232
232
  for (const f of files) {
233
233
  if (!f.toLowerCase().startsWith(base + "-")) continue; // an instance suffix, or an unrelated id
234
234
  let body;
235
- try { body = JSON.parse(readFileSync(join(dir, f), "utf8")); } catch { continue; }
235
+ try { body = readJson(join(dir, f)); } catch { continue; }
236
236
  if (typeof body?._uri === "string" && normalizeRecordUri(body._uri) === canon)
237
237
  confirmed.push({ file: join(dir, f), uri: body._uri });
238
238
  }
@@ -5,7 +5,7 @@
5
5
  // exact server/tool wiring. Two inputs, both produced today by the gateway gather block:
6
6
  import { fileURLToPath } from "node:url";
7
7
  import { dirname, join } from "node:path";
8
- import { tomlString } from "../../../shared/toml-string.mjs"; import { driverDir } from "../../../shared/driver-dir.mjs";
8
+ import { tomlString } from "../../../shared/toml-string.mjs"; import { driverDir } from "../../run-record.mjs";
9
9
 
10
10
  // • mcpConfig — the claude-shaped JSON string `{mcpServers:{name:{command,args,env,connectionTimeoutMs?}}}`
11
11
  // (buildGatherMcpConfig → JSON.stringify)
@@ -36,9 +36,8 @@
36
36
  import { serve } from "./stdio-server.mjs";
37
37
  import { recordDeclinations } from "../../declination-tool.mjs";
38
38
  import { MAX_DECLINATIONS_PER_CALL, DECLINATION_REASONS, DECLINATION_REASON_TOKENS } from "../../declination-call.mjs";
39
- import { readFileSync } from "node:fs";
40
39
  import { join } from "node:path";
41
- import { driverDir } from "../../../shared/driver-dir.mjs"; //
40
+ import { driverDir, readJson } from "../../run-record.mjs"; //
42
41
 
43
42
  const DECLINATION_SPEC = "declination-spec.json";
44
43
 
@@ -55,7 +54,7 @@ const DECLINATION_SPEC = "declination-spec.json";
55
54
  * which is the failure the doubt-closure transport's own loader records in the same words.
56
55
  */
57
56
  function loadDeclinationSpec(runDir) {
58
- const spec = JSON.parse(readFileSync(driverDir(runDir, DECLINATION_SPEC), "utf8"));
57
+ const spec = readJson(driverDir(runDir, DECLINATION_SPEC));
59
58
  return {
60
59
  runDir,
61
60
  rows: Array.isArray(spec?.rows) ? spec.rows : [],
@@ -49,7 +49,6 @@
49
49
  // makes and the only one that matters for a grant review. `validateGridSpec` is imported from the
50
50
  // perplexity core for the same reason it always was: the spec is that core's format, and re-deriving a
51
51
  // validator here would be a second opinion about one file's shape.
52
- import { readFileSync } from "node:fs";
53
52
  import { serve } from "./stdio-server.mjs";
54
53
  import { validateGridSpec } from "../../../providers/perplexity/src/core.js";
55
54
  import { underStudioSegment } from "../../../shared/path-seps.mjs"; // Windows builds the path with "\"
@@ -61,6 +60,7 @@ import { MAX_ROWS_PER_CALL } from "../../disposition-call.mjs";
61
60
  // own module and its own file, never a row in the disposition form — see record_coverage_status below.
62
61
  import { recordCoverageStatus, COMMON_LAW_COVERAGE_STATUSES } from "../../common-law-coverage-status.mjs";
63
62
  import { insideRun } from "../../../shared/inside-run.mjs"; // a path a tool is handed is served only inside this run
63
+ import { readJson } from "../../run-record.mjs";
64
64
 
65
65
  // ── B — THE TYPED DISPOSITION TRANSPORT ─────────────────────────────────────────────────────────────
66
66
  //
@@ -82,7 +82,7 @@ function specFrom(params) {
82
82
  if (runDir && !insideRun(runDir, grid_spec_path))
83
83
  return { error: "ERROR: grid_spec_path is outside this run's folder. The driver writes the spec inside the run; use the path it gave you." };
84
84
  let spec;
85
- try { spec = validateGridSpec(JSON.parse(readFileSync(grid_spec_path, "utf8"))); }
85
+ try { spec = validateGridSpec(readJson(grid_spec_path)); }
86
86
  catch (err) { return { error: `ERROR: grid_spec_path unreadable/invalid (${err.message}). The driver writes this file; do not hand-author it.` }; }
87
87
  if (!underStudioSegment(spec.output_path)) // either spelling: an install keeps the studio segment it has
88
88
  return { error: `ERROR: grid spec.output_path must be within a studio/clearance-search run dir; got ${spec.output_path}` };
@@ -159,7 +159,7 @@ serve({
159
159
  // a time. The wording below is the refusal text, so the advertisement and the refusal now say
160
160
  // the same thing in the same words.
161
161
  segment_index: { type: "integer", description: "The NUMBER of the numbered passage you relied on, in the snippet of the receipt you ruled on (1, 2, …). Required for rows the answer marks as owing proof of reading." },
162
- fragment: { type: "string", description: "OPTIONAL, and never refused — #1172. The driver extracts the quote it stores from `segment_index` ALONE, so pointing at the passage is the whole obligation. If a few characters of that passage come easily, send them and they are recorded as a transcription check; if the script is one you cannot reproduce, omit it and nothing is lost. Do not translate: a translation is not a copy, and an empty field is better than a wrong one." },
162
+ fragment: { type: "string", description: "OPTIONAL, and never refused. The driver extracts the quote it stores from `segment_index` ALONE, so pointing at the passage is the whole obligation. If a few characters of that passage come easily, send them and they are recorded as a transcription check; if the script is one you cannot reproduce, omit it and nothing is lost. Do not translate: a translation is not a copy, and an empty field is better than a wrong one." },
163
163
  // — THE HONEST EXIT. Declared here because a seat can only take an exit it can see: the
164
164
  // one row that killed a production run was refused 217 times by a seat that had no way to say
165
165
  // it could not rule, and the schema is the half its tool-calling binds to.
@@ -10,6 +10,7 @@
10
10
  import { fileURLToPath } from "node:url";
11
11
  import { dirname, join } from "node:path";
12
12
  import { requireRegisterProvider } from "../../driver.config.mjs";
13
+ import { recordedRegister } from "../run-choices.mjs"; // the register a run recorded, which serves it
13
14
  import { fixtureRecordsDir } from "../../register-fixture-marker.mjs";
14
15
  import { ledgerPath, runRecordLogPath } from "../../../providers/_shared/ledger-path.mjs";
15
16
  import { CORRECTION_POSITIONS_ENV } from "./correction-positions.mjs"; // the positions a correction hands its save
@@ -55,14 +56,14 @@ const REGISTER_TOOLS = [
55
56
  // names exist" and the INTERSECTION for "what every provider grants", without re-introducing the
56
57
  // default deleted.
57
58
  export const REGISTER_SERVERS = {
58
- corsearch: { script: "corsearch-server.mjs", tools: REGISTER_TOOLS },
59
+ corsearch: { script: "register-server.mjs", args: ["corsearch"], tools: REGISTER_TOOLS },
59
60
  // clarivate: 7 of the 8. `register_expand_phoneme` is ABSENT ON PURPOSE — the ranked-similarity
60
61
  // surface that would preview phoneme variants is not available on this provider (HTTP 403),
61
62
  // and doctrine 2 forbids stubbing it with something weaker. Phonetic SEARCH still works
62
63
  // (match_mode:"phonetic"); only the variant PREVIEW is unavailable. The gap is declared in
63
64
  // providers/clarivate/src/capabilities.js (phonemeExpansion:false) and pinned by
64
65
  // test/engine.gather.test.mjs, so it can never become a silent omission.
65
- clarivate: { script: "clarivate-server.mjs", tools: REGISTER_TOOLS.filter((t) => t !== "register_expand_phoneme") },
66
+ clarivate: { script: "register-server.mjs", args: ["clarivate"], tools: REGISTER_TOOLS.filter((t) => t !== "register_expand_phoneme") },
66
67
  // signa: 5 of the 8, and the grant is what the server SERVES. It was 2 until and 4 until.
67
68
  // The 2 was set on 2026-07-21 by 7ef96c7c when signa really was the thin provider — and it never
68
69
  // moved again. The five
@@ -118,7 +119,7 @@ export const REGISTER_SERVERS = {
118
119
  // " signa's core still carries NO figurative data" in driver/test/register-capabilities.test.mjs
119
120
  // reds if a vienna/figurative field appears in providers/signa/src or if hasPublicRecordUrl goes
120
121
  // true. If it reds, re-read this reason before you touch the test.
121
- signa: { script: "signa-server.mjs",
122
+ signa: { script: "register-server.mjs", args: ["signa"],
122
123
  tools: ["register_search", "register_record_fetch", "register_enumerate", "register_execute_plan",
123
124
  "register_propose_supplemental"] },
124
125
  // euipo: 7 of the 8, the same count as clarivate and for the same missing tool.
@@ -132,7 +133,7 @@ export const REGISTER_SERVERS = {
132
133
  // only {imageFormat, viennaClasses} with no bytes and no URL, which reads like an empty field.
133
134
  // `GET /trademarks/{n}/image` answers 200 with real image bytes. The tool serves the Vienna
134
135
  // figurative-element codes — the comparable data — rather than the bytes.
135
- euipo: { script: "euipo-server.mjs", tools: REGISTER_TOOLS.filter((t) => t !== "register_expand_phoneme") },
136
+ euipo: { script: "register-server.mjs", args: ["euipo"], tools: REGISTER_TOOLS.filter((t) => t !== "register_expand_phoneme") },
136
137
  // uspto-local: 6 of the 8, and the only provider here that is a FILE rather than an API — the guard
137
138
  // it fails on is USPTO_LOCAL_DB, not a key. Two tools are absent on purpose, neither stubbed:
138
139
  // register_image_fetch — the USPTO bulk product is text. It carries the drawing CODE (hence
@@ -142,7 +143,7 @@ export const REGISTER_SERVERS = {
142
143
  // slice is stamped unsupported at compile time and disclosed as a deferred coverage row.
143
144
  // Both gaps are declared in providers/uspto-local/src/capabilities.js and the exact six are pinned by
144
145
  // test/engine.gather.test.mjs, so neither can become a silent omission.
145
- "uspto-local": { script: "uspto-local-server.mjs",
146
+ "uspto-local": { script: "register-server.mjs", args: ["uspto-local"],
146
147
  tools: REGISTER_TOOLS.filter((t) => t !== "register_expand_phoneme" && t !== "register_image_fetch") },
147
148
  // free-tier: EUIPO + the local US index as ONE register — 7 of the 8. The surface is the UNION
148
149
  // of what its members can serve, not the intersection, because a tool one member serves is still a
@@ -153,7 +154,7 @@ export const REGISTER_SERVERS = {
153
154
  // register_expand_phoneme — ABSENT, and here the intersection and the union agree: NEITHER member
154
155
  // has a phonetic surface, so predicates.phonetic is null and a phonetic slice defers rather than
155
156
  // degrading into a contains under the phonetic name.
156
- "free-tier": { script: "free-tier-server.mjs",
157
+ "free-tier": { script: "register-server.mjs", args: ["free-tier"],
157
158
  tools: REGISTER_TOOLS.filter((t) => t !== "register_expand_phoneme") },
158
159
  };
159
160
 
@@ -793,19 +794,19 @@ export function providerUnavailableRegisterTools(provider = null) {
793
794
  return new Set(REGISTER_TOOLS.filter((t) => !served.has(t)));
794
795
  }
795
796
 
796
- function registerEntry() {
797
+ function registerEntry(register = null) {
797
798
  // `|| "corsearch"` lived here too — a SECOND silent default, behind the first one, so fixing
798
799
  // driver.config alone would have left the gather stages resolving to a vendor we hold no licence
799
800
  // with. requireRegisterProvider throws instead, with the same message the driver gives.
800
- const p = requireRegisterProvider();
801
+ const p = register ?? requireRegisterProvider();
801
802
  const entry = REGISTER_SERVERS[p];
802
- if (!entry) throw new Error(`[gather-config] no MCP server built for REGISTER_PROVIDER="${p}" yet — wrap providers/${p}/src/core like corsearch-server.mjs (pure glue, exposing the register_* names), then add it to REGISTER_SERVERS.`);
803
+ if (!entry) throw new Error(`[gather-config] no MCP server built for REGISTER_PROVIDER="${p}" yet — wrap providers/${p}/src/core in a mount.js like corsearch's (pure glue, exposing the register_* names), then add it to REGISTER_SERVERS.`);
803
804
  return entry;
804
805
  }
805
806
 
806
807
  // Resolve a local key to its {script, tools}. `register` is dynamic; everything else is static LOCAL.
807
- function localEntry(key) {
808
- return key === "register" ? registerEntry() : LOCAL[key];
808
+ function localEntry(key, register = null) {
809
+ return key === "register" ? registerEntry(register) : LOCAL[key];
809
810
  }
810
811
 
811
812
  // group → { localKeys[], bridgeKeys[], extraTools[] }
@@ -879,7 +880,7 @@ export const claudeToolAnswerBytes = (env = process.env) =>
879
880
  // The mcp-config server env carries ONLY the per-run, non-secret values (session key + ledger paths +
880
881
  // agent + the run dir the band tools serve, and the answer size above). Creds (CORSEARCH_SESSION_KEY /
881
882
  // PERPLEXITY_API_KEY / EUIPO_*) are inherited from the engine env.
882
- function serverEnv({ sessionKey, agent, runDir, recordAxis, bandGroups = false, correctionPositions = null }) {
883
+ function serverEnv({ sessionKey, agent, runDir, recordAxis, bandGroups = false, correctionPositions = null, register = null }) {
883
884
  const e = {};
884
885
  // — see buildGatherMcpConfig: a register server without a run is refused there, so by the time
885
886
  // the record-log line below runs, `runDir` is present for every config that could use it.
@@ -898,7 +899,10 @@ function serverEnv({ sessionKey, agent, runDir, recordAxis, bandGroups = false,
898
899
  // — THE RUN'S REGISTER, so a recording tool gates a record link at the call as verify.mjs gates the
899
900
  // saved file (record-origins.mjs). Handed over explicitly: Codex gives a server only its own `env` and
900
901
  // the names it forwards, so a value left to inheritance reaches a Claude server and never a Codex one.
901
- if (process.env.CLEAROTRON_DATABASE) e.CLEAROTRON_DATABASE = process.env.CLEAROTRON_DATABASE;
902
+ // The run's recorded register (engine/run-choices.mjs), which each tool server reads as its own; the machine's, as
903
+ // before, for a run with no record.
904
+ const reg = register ?? process.env.CLEAROTRON_DATABASE;
905
+ if (reg) e.CLEAROTRON_DATABASE = reg;
902
906
  // — the ledger paths are RESOLVED HERE and handed to the child explicitly, not forwarded as raw
903
907
  // env. Two reasons, and the second is the one that kept this rename parked for months:
904
908
  // · the old line was `if (process.env[v]) e[v] = …`, and NO box sets those vars — prod, test and dev
@@ -948,7 +952,8 @@ export function withSendUntil(mcpConfigJson, sendUntilMs) {
948
952
  return JSON.stringify(cfg);
949
953
  }
950
954
 
951
- export function buildGatherMcpConfig(groups = [], { sessionKey, agent, runDir, recordAxis, bandGroups = false, correctionPositions = null } = {}) {
955
+ export function buildGatherMcpConfig(groups = [], { sessionKey, agent, runDir, recordAxis, bandGroups = false, correctionPositions = null,
956
+ register = recordedRegister(runDir) } = {}) {
952
957
  const localKeys = new Set(), bridgeKeys = new Set();
953
958
  for (const g of groups) { const r = resolveGroup(g); r.local.forEach((k) => localKeys.add(k)); r.bridges.forEach((k) => bridgeKeys.add(k)); }
954
959
  const mcpServers = {};
@@ -972,14 +977,14 @@ export function buildGatherMcpConfig(groups = [], { sessionKey, agent, runDir, r
972
977
  // is the more fundamental refusal and the one an operator acts on, so it must still come out ahead of
973
978
  // this one — a box with neither a provider nor a run should be told about the provider.
974
979
  if (localKeys.has("register")) {
975
- localEntry("register");
980
+ localEntry("register", register);
976
981
  if (!runDir) {
977
982
  throw new Error("gather-config: a register server needs the run it is fetching for — record bodies "
978
983
  + "belong to their run, and the box-global ledger is retired. Pass runDir.");
979
984
  }
980
985
  }
981
- const env = serverEnv({ sessionKey, agent, runDir, recordAxis, bandGroups, correctionPositions });
982
- for (const k of localKeys) mcpServers[k] = { command: NODE, args: [join(MCP_DIR, localEntry(k).script)], env };
986
+ const env = serverEnv({ sessionKey, agent, runDir, recordAxis, bandGroups, correctionPositions, register });
987
+ for (const k of localKeys) mcpServers[k] = { command: NODE, args: [join(MCP_DIR, localEntry(k, register).script), ...(localEntry(k, register).args ?? [])], env };
983
988
  // A FIXTURE RUN NEVER REACHES A LIVE REGISTER, and its job says so: the same key serves its canned answers.
984
989
  if (localKeys.has("register") && runDir && fixtureRecordsDir(runDir)) mcpServers.register.args = [join(MCP_DIR, "fixture-register-server.mjs")];
985
990
  // — THE BRIDGES GET THE AUDIT ENV, AND ONLY THAT. Until now they were spawned with no env at
@@ -1518,7 +1523,7 @@ export const RECORDING_STAGES_KEEPING_RETRIEVAL = Object.freeze(
1518
1523
  Object.keys(RECORDING).filter((k) => RECORDING[k].keepsRetrieval === true).sort(),
1519
1524
  );
1520
1525
 
1521
- export function allowedToolsFor(groups = []) {
1526
+ export function allowedToolsFor(groups = [], { register = null } = {}) {
1522
1527
  // — THE SEED IS NO LONGER UNCONDITIONAL. `Read` always; `Write`/`Edit` only where some group's seat
1523
1528
  // still authors a file. A recording row that declares `seatWrites: false` has its artifact written by the
1524
1529
  // driver, so the hand-write tools are a superseded path left executable — and this is the seeding that
@@ -1535,7 +1540,7 @@ export function allowedToolsFor(groups = []) {
1535
1540
  const tools = seatWritesForGroups(groups) ? new Set(["Read", "Write", "Edit"]) : new Set(["Read"]);
1536
1541
  for (const g of groups) {
1537
1542
  const r = resolveGroup(g);
1538
- for (const k of r.local) (r.only ?? localEntry(k).tools).forEach((t) => tools.add(`mcp__${k}__${t}`));
1543
+ for (const k of r.local) (r.only ?? localEntry(k, register).tools).forEach((t) => tools.add(`mcp__${k}__${t}`));
1539
1544
  for (const k of r.bridges) tools.add(`mcp__${k}__*`); // whole bridge server (its tools are namespaced)
1540
1545
  r.extra.forEach((t) => tools.add(t));
1541
1546
  }
@@ -28,7 +28,7 @@ export function gridProvenancePath(outputPath) {
28
28
  */
29
29
  export function gridProvenanceRecord({ ran, present, requested, model = null }) {
30
30
  return {
31
- _what: "#1846 — which provider served common-law-grid.json, written beside it because the ledger itself is saved verbatim.",
31
+ _what: "which provider served common-law-grid.json, written beside it because the ledger itself is saved verbatim.",
32
32
  provider: "perplexity",
33
33
  surface: "agent API, sandbox tool",
34
34
  tool: "perplexity_research",
@@ -18,9 +18,9 @@
18
18
  // close asks it once more (execute-plan.mjs, timedOutBefore). An answer in a slice the run took out of its band
19
19
  // because a check could not prove it ran is asked again too, whatever wrote the band since.
20
20
 
21
- import { readFileSync, readdirSync, statSync } from "node:fs";
21
+ import { readdirSync, statSync } from "node:fs";
22
22
  import { join } from "node:path";
23
- import { driverDir } from "../../../shared/driver-dir.mjs";
23
+ import { paths, readJson } from "../../run-record.mjs";
24
24
  import { OUTSTANDING_REASON } from "../../../providers/_shared/follow-up-searches.mjs";
25
25
  import { awaitsReadingTurn } from "../../../providers/_shared/plan-guards.mjs";
26
26
  import { releasedFamilyQids } from "../../withheld-families.mjs";
@@ -57,7 +57,7 @@ function readBlocks(path) {
57
57
  if (hit && hit.stamp === stamp) return hit.blocks;
58
58
  let blocks = [];
59
59
  try {
60
- const j = JSON.parse(readFileSync(path, "utf8"));
60
+ const j = readJson(path);
61
61
  blocks = (Array.isArray(j) ? j : []).filter((b) => b?.qid).map((b) => ({
62
62
  qid: b.qid, state: b.state ?? null, error: b.error === true, total_hits: b.total_hits ?? null,
63
63
  count: b.count ?? (Array.isArray(b.records) ? b.records.length : null),
@@ -97,7 +97,7 @@ function readRunQuestions(runDir) {
97
97
  const units = join(runDir, "register-units");
98
98
  const blocksByQid = new Map();
99
99
  const plans = [];
100
- try { plans.push({ axis: null, plan: JSON.parse(readFileSync(driverDir(runDir, "register-plan.json"), "utf8")) }); } catch { /* no frozen plan */ }
100
+ try { plans.push({ axis: null, plan: readJson(paths(runDir).registerPlan) }); } catch { /* no frozen plan */ }
101
101
  let files = [];
102
102
  try { files = readdirSync(units); } catch { files = []; }
103
103
  const takenOut = slicesTakenOutByAxis(runDir);
@@ -107,7 +107,7 @@ function readRunQuestions(runDir) {
107
107
  for (const b of blocks) if (b?.qid) blocksByQid.set(String(b.qid), b);
108
108
  }
109
109
  if (f.endsWith("-supplemental-plan.json")) {
110
- try { plans.push({ axis: f.slice(0, -"-supplemental-plan.json".length), plan: JSON.parse(readFileSync(join(units, f), "utf8")) }); } catch { /* torn: skipped */ }
110
+ try { plans.push({ axis: f.slice(0, -"-supplemental-plan.json".length), plan: readJson(join(units, f)) }); } catch { /* torn: skipped */ }
111
111
  }
112
112
  }
113
113
  return { plans, blocksByQid };