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
@@ -0,0 +1,162 @@
1
+ // SPDX-License-Identifier: AGPL-3.0-only
2
+ // Copyright 2026 Cordillera Sàrl. Additional terms under section 7 of the AGPL-3.0 apply — see ADDITIONAL-TERMS.md
3
+ // run-choices.mjs — the engine and the register a run started on, frozen in the run so a resume keeps them.
4
+ //
5
+ // Both used to be read from the environment at every activation and recorded nowhere. A run parked on one engine
6
+ // and resumed after the machine's setting changed carried on under the other, and nothing in its record said so.
7
+ // The choice is now written once, when the run starts, and belongs to the run from then on:
8
+ //
9
+ // - a later change to the machine's setting applies to new runs only;
10
+ // - a resumed run keeps its recorded engine, and one this driver cannot serve is refused by name rather than
11
+ // swapped for the machine's default;
12
+ // - a run with no record is left without one. Nothing here writes a record for a run that has already started,
13
+ // because that would date today's setting back to a start nobody recorded.
14
+ //
15
+ // The record holds the two names and nothing else. Each must name an engine this driver ships or a register it
16
+ // knows, so no other string (a credential included) can be written into it.
17
+ //
18
+ // A LEAF: it reads the shipped-engine table, not the engine registry. The jurisdiction lanes' turn runner reads the
19
+ // record, tool servers reach that runner, and the registry would bring both engine adapters and every setting they
20
+ // read into each tool server's imports. The registry's `engineForRun` serves a run's turns from this record.
21
+ import { existsSync, readFileSync, renameSync, writeFileSync } from "node:fs";
22
+ import { driverDir, ensureDriverDir } from "../../shared/driver-dir.mjs";
23
+ import { ENGINE_BINARIES, PROVIDERS, REGISTER_PROVIDER, activeProvider } from "../driver.config.mjs";
24
+
25
+ export const RUN_CHOICES_FILE = "run-choices.json";
26
+
27
+ const nameOf = (v) => (v == null ? null : String(v).trim().toLowerCase() || null);
28
+
29
+ /**
30
+ * Write the run's engine and register, once. A record already on disk is never rewritten: the call answers
31
+ * with what is there and `written: false`, so a cold start that is retried keeps its first choice.
32
+ * `register` is null when the machine has none set; that is recorded as it was, not guessed.
33
+ */
34
+ export function recordRunChoices(runDir, { engine, register }) {
35
+ const held = readRunChoices(runDir);
36
+ if (held.state !== "none") return { written: false, ...held };
37
+ const e = nameOf(engine), r = nameOf(register);
38
+ if (!e || !Object.hasOwn(ENGINE_BINARIES, e))
39
+ throw new Error(`run-choices: "${e}" is not an engine this driver ships (${Object.keys(ENGINE_BINARIES).join(", ")})`);
40
+ if (r !== null && !Object.hasOwn(PROVIDERS, r))
41
+ throw new Error(`run-choices: "${r}" is not a register this driver knows (${Object.keys(PROVIDERS).join(", ")})`);
42
+ ensureDriverDir(runDir);
43
+ const p = driverDir(runDir, RUN_CHOICES_FILE);
44
+ writeFileSync(`${p}.tmp`, JSON.stringify({ schema: 1, engine: e, register: r }, null, 2) + "\n");
45
+ renameSync(`${p}.tmp`, p);
46
+ return { written: true, state: "recorded", engine: e, register: r };
47
+ }
48
+
49
+ /**
50
+ * What the run recorded: `{ state: "recorded", engine, register }`, `{ state: "none" }` for a run that has no
51
+ * record, or `{ state: "unreadable", detail }` for one whose record does not read back as the two names.
52
+ */
53
+ export function readRunChoices(runDir) {
54
+ if (!runDir) return { state: "none" };
55
+ const p = driverDir(runDir, RUN_CHOICES_FILE);
56
+ if (!existsSync(p)) return { state: "none" };
57
+ let o;
58
+ try { o = JSON.parse(readFileSync(p, "utf8")); }
59
+ catch (err) { return { state: "unreadable", detail: `does not parse: ${String(err?.message ?? err).slice(0, 200)}` }; }
60
+ const engine = nameOf(o?.engine), register = nameOf(o?.register);
61
+ if (!engine) return { state: "unreadable", detail: "names no engine" };
62
+ if (o?.register != null && typeof o.register !== "string") return { state: "unreadable", detail: "its register is not a name" };
63
+ return { state: "recorded", engine, register };
64
+ }
65
+
66
+ /**
67
+ * A resumed run whose recorded engine or register this process cannot serve.
68
+ *
69
+ * It is a PARK, not a failure. It is raised before any check spends anything and before the run's markers are cleared,
70
+ * so the run keeps every stage it finished, and `dependency` names what it waits for. The pipeline holds the run until
71
+ * a process that serves the recorded choice resumes it. There is no deadline, and the run is never moved to the
72
+ * machine's choice. `run` is the run's identity, because this is raised before the pipeline holds one.
73
+ *
74
+ * `kind` is one of:
75
+ * register this runner cannot serve the run's register: a credential or a capability it needs is missing here;
76
+ * engine this driver has no adapter for the run's engine;
77
+ * engine-program the run's engine program is not installed here;
78
+ * engine-sign-in the run's engine refused a turn for a configuration fault (signed out, no key).
79
+ */
80
+ export const RUN_CHOICE_KINDS = Object.freeze(["register", "engine", "engine-program", "engine-sign-in"]);
81
+ export class RunChoiceUnavailable extends Error {
82
+ constructor({ kind, recorded, machine = null, detail = null, run = null }) {
83
+ if (!RUN_CHOICE_KINDS.includes(kind)) throw new Error(`RunChoiceUnavailable: unknown kind "${kind}"`);
84
+ const what = kind === "register" ? `the ${recorded} register` : `the ${recorded} engine`;
85
+ const why = kind === "register" ? "this runner cannot serve it"
86
+ : kind === "engine" ? "this driver has no adapter for it"
87
+ : kind === "engine-program" ? "its program is not installed here"
88
+ : "it cannot take a turn here";
89
+ super(`run ${run?.codename ?? "(unnamed)"} started on ${what}, and ${why}${detail ? ` (${String(detail).slice(0, 300)})` : ""}. It is parked with its work kept, and resumes on ${what}.`);
90
+ this.name = "RunChoiceUnavailable";
91
+ this.dependency = { kind, recorded, machine, detail: detail == null ? null : String(detail).slice(0, 300) };
92
+ this.run = run;
93
+ // For the park's own record, as the rate-limit park writes its two lines: what it waits for, and what ends the wait.
94
+ this.waitingOn = `${what}, which this run started on (${why})`;
95
+ this.resolvedBy = kind === "register"
96
+ ? `${what}'s credentials and capabilities set for this runner, on this build; the run resumes where it stopped`
97
+ : `${what} made available to this runner (installed and signed in), on this build; the run resumes where it stopped`;
98
+ }
99
+ }
100
+
101
+ /**
102
+ * Which recorded choice this process cannot serve, before anything is checked or spent, or null. The engine is
103
+ * unservable here only when no adapter is registered for it; a missing program or sign-in is found by the engine doors.
104
+ * The register is not decided here: a recorded register is served wherever this runner holds what it needs, whatever
105
+ * the machine's default, and the register's own door finds out (`registerEnvFor`, steps/open-run.mjs). PURE.
106
+ */
107
+ export function unservedChoice(recorded, { engineRegistered }) {
108
+ if (recorded?.state !== "recorded") return null;
109
+ if (!engineRegistered) return { kind: "engine", recorded: recorded.engine, machine: null };
110
+ return null;
111
+ }
112
+
113
+ /**
114
+ * The environment the register's door checks for this run: a copy of `env` naming the run's recorded register, or `env`
115
+ * itself for a run with no record or one that started with none set. A copy, so one run's register never changes the
116
+ * process environment every concurrent run shares. PURE.
117
+ */
118
+ export function registerEnvFor(recorded, env = process.env) {
119
+ return recorded?.state === "recorded" && recorded.register ? { ...env, CLEAROTRON_DATABASE: recorded.register } : env;
120
+ }
121
+
122
+ /**
123
+ * The register door a run meets: null where it skips the door, else `{ env, parks }`. `env` is what the door checks
124
+ * (`registerEnvFor`), and `parks` says a refusal parks the run rather than failing it, which it does only for a
125
+ * recorded register that is not the machine's. A run whose record fetches are injected (an offline replay) skips the
126
+ * door. So does a Knockout on the machine's own register, as it always has; a Knockout recorded on another register
127
+ * meets the door, because its counts and filings are that register's. PURE.
128
+ */
129
+ export function registerDoor(recorded, { machineRegister = null, knockout = false, fetchesInjected = false, env = process.env } = {}) {
130
+ if (fetchesInjected) return null;
131
+ const differs = recorded?.state === "recorded" && Boolean(recorded.register) && recorded.register !== (machineRegister ?? null);
132
+ if (knockout && !differs) return null;
133
+ return { env: registerEnvFor(recorded, env), parks: differs };
134
+ }
135
+
136
+ /**
137
+ * The register that serves this run: the one it recorded when it started, or the machine's for a run with no record or
138
+ * one that started with none set, whatever the machine's default is now. It is the one place a run's register is
139
+ * decided. A recorded register this runner cannot serve parks the run at the register's door before any stage. PURE
140
+ * but for reading the record.
141
+ */
142
+ export function registerForRun(runDir) {
143
+ const rec = readRunChoices(runDir);
144
+ return rec.state === "recorded" && rec.register ? rec.register : (REGISTER_PROVIDER ?? null);
145
+ }
146
+
147
+ /** The register the run recorded, or null for a run with no record or one that started with none set. PURE but for the read. */
148
+ export function recordedRegister(runDir) {
149
+ const rec = readRunChoices(runDir);
150
+ return rec.state === "recorded" && rec.register ? rec.register : null;
151
+ }
152
+
153
+ /**
154
+ * The register adapter for a run's register (`ctx.register`), or the machine's when none is named: the one way a place
155
+ * that reads a register for a run asks for its adapter. A name this driver does not know throws, as `activeProvider` does.
156
+ */
157
+ export function registerAdapter(register = null) {
158
+ if (!register) return activeProvider();
159
+ const a = PROVIDERS[register];
160
+ if (!a) throw new Error(`[register-provider] unknown register "${register}". Known: ${Object.keys(PROVIDERS).join(", ")}`);
161
+ return a;
162
+ }
@@ -0,0 +1,35 @@
1
+ // SPDX-License-Identifier: AGPL-3.0-only
2
+ // Copyright 2026 Cordillera Sàrl. Additional terms under section 7 of the AGPL-3.0 apply — see ADDITIONAL-TERMS.md
3
+ // stamps.mjs — what the `engine` word on a saved attempt row means.
4
+ //
5
+ // It imports nothing, so the rollup readers can ask it without joining an import loop or loading an adapter.
6
+ // The word on a row is wider than the registered engines: this table is about rows already on disk.
7
+ //
8
+ // A CLOSED TABLE, NOT A PREFIX RULE. `anthropic-*` → anthropic is shorter and would silently adopt any
9
+ // future engine whose name began that way, which is how a vendor claim becomes a guess. An engine this
10
+ // table does not know is reported BY NAME and blocks the single-vendor claim, because "I do not know who
11
+ // billed this" and "one vendor" are different answers and only one of them is safe to print.
12
+ //
13
+ // THE NATIVE-LANGUAGE ROWS STAMP THE VENDOR ITSELF. jxBillingStamp (jx-lanes.mjs) writes as the row's
14
+ // engine the provider the engine door resolved, `anthropic` or `openai` (engine/auth.mjs), so those two
15
+ // names are engines this table must place. Without them an Anthropic-only run with a native-language turn
16
+ // named `anthropic` as an engine that bills to no vendor, in the same sentence that named anthropic as its
17
+ // one vendor. Two exact names, still a closed table.
18
+ //
19
+ // `catalog` says how to key a row with no `modelUsed`: "tier" reads its `model` through Claude's catalog
20
+ // (`resolveModel`), "served" keys it as the id it carries, and a stamp without the field has no honest key.
21
+ // `nativeLanguage` marks a row whose `model` is the id that served the turn and not the tier it asked for.
22
+ const ENGINE_STAMPS = Object.freeze({
23
+ "anthropic-agent": { vendor: "anthropic", catalog: "tier" },
24
+ "anthropic-direct": { vendor: "anthropic" },
25
+ "anthropic-completions": { vendor: "anthropic" },
26
+ "openai-agent": { vendor: "openai" },
27
+ "anthropic": { vendor: "anthropic", catalog: "tier", nativeLanguage: true },
28
+ "openai": { vendor: "openai", catalog: "served", nativeLanguage: true },
29
+ });
30
+
31
+ /** What this table says about a stamp, or an empty record when it does not name it. */
32
+ export const engineStamp = (engine) => (Object.hasOwn(ENGINE_STAMPS, String(engine ?? "")) ? ENGINE_STAMPS[String(engine)] : {});
33
+
34
+ /** The vendor an engine bills to, or null when the table does not name one. */
35
+ export const vendorOf = (engine) => engineStamp(engine).vendor ?? null;
@@ -183,7 +183,7 @@ export function undeclaredFieldsWarning(names) {
183
183
  return `job carries ${names.length} field(s) no door declares: ${list} — DECLARED_JOB_FIELDS does not `
184
184
  + `name them, so nothing validates them, no door gate can rule on them, and any assembling door `
185
185
  + `drops them silently. Declare them in driver/enqueue-schema.mjs if they are meaningful, or stop `
186
- + `writing them. #1085`;
186
+ + `writing them.`;
187
187
  }
188
188
 
189
189
  // — "DID THE REQUEST NAME ANY CLASSES?", ONCE.
@@ -206,7 +206,7 @@ export function undeclaredFieldsWarning(names) {
206
206
  // which is softer — and softer is why it would survive a reading and not a run.
207
207
  //
208
208
  // So the door owns the vocabulary and the framing builders read it. `driver/stages.mjs` still carries
209
- // its own correct copy (that file belongs to another lane's active work); the three are pinned against
209
+ // its own correct copy; the three are pinned against
210
210
  // each other in driver/test/knockout-classes-predicate.test.mjs, so a copy that drifts is a red suite
211
211
  // rather than a prompt aimed at the wrong goods.
212
212
  export function requestNamesClasses(job) {
@@ -409,7 +409,7 @@ export function validateJob(job, { atClaim = false } = {}) {
409
409
  const sidecarNote = `promptParts declares the prose rides as SIDECAR files and none arrived — expected `
410
410
  + `one or more of ${Object.values(PROSE_PARTS).map((x) => `<base>${x}`).join(", ")} beside the manifest. `
411
411
  + `A mis-named manifest is the observed cause: sidecars key on the BARE base, so <base>.manifest.json `
412
- + `leaves them unmatched. #1085`;
412
+ + `leaves them unmatched.`;
413
413
  if (sidecarsMissing) warnings.push(sidecarNote);
414
414
 
415
415
  if (!hasMark) errs.push(sidecarsMissing ? `missing mark name(s) — ${sidecarNote}` : "missing mark name(s)");
@@ -924,7 +924,7 @@ export function validateJob(job, { atClaim = false } = {}) {
924
924
  job.deadline = new Date(t).toISOString();
925
925
  }
926
926
  }
927
- if (!job.ref && !job.tmp) warnings.push("no ref/tmp (TMP Reference No.) — proceeding with no reference");
927
+ if (!job.ref && !job.tmp) warnings.push("No reference number was given, so this search has none.");
928
928
  // Repair-first phase 3 (the teal-causeway msgId defect): a 32-hex msgId is the SANITIZED HASH base
929
929
  // (the job-id derivation), not a Graph message id — the delivery send-tool's inReplyTo lookup will fail and the
930
930
  // notice/delivery falls back off the client thread. Never blocks (still deliverable via fallback);
@@ -34,10 +34,11 @@
34
34
  // that envelopeDecision prices belong to the late, ledger-level arm, which is untouched and still runs.
35
35
  // Deliberately, therefore, nothing here reads job.deadline — and no string it produces mentions time.
36
36
 
37
- import { existsSync, readFileSync, writeFileSync, renameSync } from "node:fs";
37
+ import { existsSync, writeFileSync, renameSync } from "node:fs";
38
38
  import { isCapabilityGapReason } from "./coverage-ledger.mjs";
39
39
  import { fullyDeferredAxes } from "./register-plan.mjs";
40
40
  import { readPartNotCompleted } from "./parts-not-completed.mjs";
41
+ import { readJson } from "./run-record.mjs";
41
42
 
42
43
  export const SETTLE_SCHEMA_VERSION = 1;
43
44
 
@@ -83,7 +84,7 @@ export function partitionReceiptDeferrals(plan, receipt, { sticky = new Set() }
83
84
  export function readEnvelopeDecision(P) {
84
85
  try {
85
86
  const p = P?.envelopeDecision;
86
- return p && existsSync(p) ? JSON.parse(readFileSync(p, "utf8")) : null;
87
+ return p && existsSync(p) ? readJson(p) : null;
87
88
  } catch { return null; } // unreadable ⇒ treated as absent ⇒ re-settled ⇒ overwritten
88
89
  }
89
90
 
@@ -118,7 +118,7 @@ export function issueForFlag(flag) {
118
118
  `| Flag record | \`${flag?.id ?? "—"}.json\` in the feedback store |`,
119
119
  ``,
120
120
  `---`,
121
- `_Minted from a report flag (#260/#264). Nothing here is triaged: no status label, no rating, and no_`,
121
+ `_Minted from a report flag. Nothing here is triaged: no status label, no rating, and no_`,
122
122
  `_reading of what the lawyer meant. A human decides what this becomes._`,
123
123
  ].join("\n");
124
124
 
@@ -14,9 +14,10 @@
14
14
  // duplicate issue is a nuisance a human closes in ten seconds, and a lost flag is lawyer feedback nobody
15
15
  // knows was given.
16
16
 
17
- import { readFileSync, readdirSync, writeFileSync } from "node:fs";
17
+ import { readdirSync, writeFileSync } from "node:fs";
18
18
  import { join } from "node:path";
19
19
  import { issueForFlag } from "./feedback-issues.mjs";
20
+ import { readJson } from "./run-record.mjs";
20
21
 
21
22
  /** A flag that has not yet become an issue. */
22
23
  export const isPending = (flag) => !!flag && !flag.issue;
@@ -43,7 +44,7 @@ export async function mintPending({ dir, createIssue, log = () => {}, now = () =
43
44
  const path = join(dir, name);
44
45
  let flag;
45
46
  // A half-written or hand-edited file is not a reason to stop draining the other seventy-four.
46
- try { flag = JSON.parse(readFileSync(path, "utf8")); }
47
+ try { flag = readJson(path); }
47
48
  catch { log(`skip ${name}: not readable as JSON`); skipped++; continue; }
48
49
  if (!isPending(flag)) { skipped++; continue; }
49
50
 
@@ -23,8 +23,9 @@
23
23
  // would have hidden.
24
24
 
25
25
  import { randomUUID } from "node:crypto";
26
- import { mkdirSync, readFileSync, readdirSync, writeFileSync } from "node:fs";
26
+ import { mkdirSync, readdirSync, writeFileSync } from "node:fs";
27
27
  import { join } from "node:path";
28
+ import { readJson } from "./run-record.mjs";
28
29
 
29
30
  /** good/bad, as the issue rules it: "Good flags matter as much as bad." */
30
31
  export const VERDICTS = new Set(["good", "bad"]);
@@ -111,7 +112,7 @@ export function listFlags(dir) {
111
112
  catch { return []; }
112
113
  const out = [];
113
114
  for (const n of names) {
114
- try { out.push(JSON.parse(readFileSync(join(dir, n), "utf8"))); }
115
+ try { out.push(readJson(join(dir, n))); }
115
116
  catch { /* a half-written or hand-edited file is not a reason to lose the other 74 */ }
116
117
  }
117
118
  return out.sort((a, b) => String(b.capturedAt ?? "").localeCompare(String(a.capturedAt ?? "")));
@@ -1815,7 +1815,7 @@ function validateNet(f, ord, mode) {
1815
1815
  // `findings?_` and would aim the repair turn at register-coverage-ledger.json — forbidding the model
1816
1816
  // to rewrite the only file that could fix it.
1817
1817
  // It reaches the wire as a validator `reason` (verify.mjs checkFindingsSibling), which is the only shape
1818
- // gateway.mjs:1204 judgeArtifacts mints as `invalid_file:<path>:<token>`; a bespoke throw would match nothing.
1818
+ // judgeArtifacts() in gateway.mjs mints as `invalid_file:<path>:<token>`; a bespoke throw would match nothing.
1819
1819
  // The precedent is one line up the file: findings_mark_assessment_* was named plural for the same
1820
1820
  // routing reason.
1821
1821
  //
@@ -41,10 +41,11 @@
41
41
  // than being unable to ask. Failing closed here would mean a file-read error takes the whole portal
42
42
  // down — trading a rare wrong-greyed-out option for a total outage.
43
43
 
44
- import { writeFileSync, readFileSync, mkdirSync, existsSync } from "node:fs";
44
+ import { writeFileSync, mkdirSync, existsSync } from "node:fs";
45
45
  import { dirname, join } from "node:path";
46
46
  import { BUILT } from "./search-policy.mjs";
47
47
  import { isEntrypoint } from "../shared/is-entrypoint.mjs"; // — one entry-point test, all spellings
48
+ import { readJson } from "./run-record.mjs";
48
49
 
49
50
  /**
50
51
  * How a flag's absence is felt by a user. This field is what stops the staff screen lying.
@@ -239,7 +240,7 @@ export function buildFlagSnapshot(env, { capturedAt, registerProvider = null, re
239
240
  */
240
241
  export const PRODUCTION_POSTURE = {
241
242
  source: "production unit environment, read 2026-08-04 with owner authorisation; the flag half "
242
- + "retired 2026-08-20 when #1149 item 8 deleted every switch it named",
243
+ + "retired 2026-08-20 when every switch it named was deleted",
243
244
  // The three it named are gone — deleted BECAUSE production ran them on while the source shipped them
244
245
  // off, which is the delta this block existed to expose. There is nothing left to differ about, and
245
246
  // saying that in an empty object beats leaving three names that no code reads.
@@ -261,7 +262,7 @@ export function postureDelta(snapshot, expected = PRODUCTION_POSTURE) {
261
262
  if (!Object.keys(expected.flags ?? {}).length) {
262
263
  rows.push({ what: "flags", here: Object.keys(snapshot.flags ?? {}).length, production: 0,
263
264
  effect: "no flag is declared on either side — the flag half of this comparison checked nothing, "
264
- + "which is not the same as finding no difference (#1149 item 8 deleted all four)" });
265
+ + "which is not the same as finding no difference (all four were deleted)" });
265
266
  }
266
267
  for (const [name, want] of Object.entries(expected.flags ?? {})) {
267
268
  const here = snapshot.flags?.[name]?.on === true;
@@ -386,7 +387,7 @@ export function readFlagSnapshot(poolRoot) {
386
387
  // The file's pre-rename name is read when the new one is not there yet, so an upgraded install does
387
388
  // not read as "no snapshot" until its first write under the new name.
388
389
  const legacy = join(poolRoot, "_state", "prelim-flag-snapshot.json");
389
- const raw = JSON.parse(readFileSync(existsSync(snapshotPath(poolRoot)) || !existsSync(legacy) ? snapshotPath(poolRoot) : legacy, "utf8"));
390
+ const raw = readJson(existsSync(snapshotPath(poolRoot)) || !existsSync(legacy) ? snapshotPath(poolRoot) : legacy);
390
391
  if (!raw || typeof raw !== "object" || typeof raw.flags !== "object") return null;
391
392
  return raw;
392
393
  } catch {
@@ -32,9 +32,9 @@
32
32
  // placement-carry, and for the same reason: the dictation that orders the record ids ships WITH this
33
33
  // check, so every run predating it reports its whole floor unmet. That is the correct reading of those
34
34
  // runs, not a broken check.
35
- import { existsSync, writeFileSync, readFileSync } from "node:fs";
36
- import { driverDir, ensureDriverDir } from "../shared/driver-dir.mjs"; // — one definition of where `_driver/` is
35
+ import { existsSync, writeFileSync } from "node:fs";
37
36
  import { entryUris } from "./placement-carry.mjs";
37
+ import { driverDir, ensureDriverDir, paths, readJson } from "./run-record.mjs"; // — one definition of where `_driver/` is
38
38
 
39
39
  export const FLOOR_DUTY_SCHEMA_VERSION = 1;
40
40
 
@@ -109,7 +109,7 @@ export function floorDutyBlocksSkip(runDir, stageName) {
109
109
  if (stageName !== FLOOR_DUTY_STAGE) return false;
110
110
  if (!floorDutyArmed(runDir)) return false;
111
111
  let artifact;
112
- try { artifact = JSON.parse(readFileSync(driverDir(String(runDir ?? ""), "floor-duty.json"), "utf8")); }
112
+ try { artifact = readJson(paths(String(runDir ?? "")).floorDuty); }
113
113
  catch { return false; }
114
114
  return Boolean(floorDutyBlock(artifact, { armed: true }));
115
115
  }
@@ -15,7 +15,7 @@
15
15
  // Blanking is blankForeignRecordLinks (findings-model.mjs): a register link becomes "", the value that
16
16
  // already means "this register publishes no page for the record".
17
17
  import { writeFileSync } from "node:fs";
18
- import { driverDir } from "../shared/driver-dir.mjs";
18
+ import { driverDir } from "./run-record.mjs";
19
19
  import { blankForeignRecordLinks } from "./findings-model.mjs";
20
20
  import { activeRecordOrigins } from "./record-origins.mjs";
21
21
  import { runLog } from "./log.mjs";
@@ -49,10 +49,10 @@
49
49
  import { readFileSync, writeFileSync, mkdirSync } from "node:fs";
50
50
  import { captureCall, stampVerdict } from "./call-capture.mjs";
51
51
  import { join } from "node:path";
52
- import { driverDir } from "../shared/driver-dir.mjs"; //
53
52
  import { parseFrameDiff } from "./frame-diff-model.mjs";
54
53
  import { parseBlindFrameModel } from "./blind-frame-model.mjs";
55
54
  import { dominantElementFromManifest } from "./scope-ledger.mjs";
55
+ import { paths } from "./run-record.mjs";
56
56
 
57
57
  export const MODEL_FILE = "frame-diff.json";
58
58
  export const PROSE_FILE = "frame-diff.md";
@@ -100,7 +100,7 @@ export function boundDominantElement(runDir) {
100
100
 
101
101
  /** Where the call's evidence lives — the driver's own record of what the seat handed it. */
102
102
  export function frameDiffCallPaths(runDir) {
103
- const dir = driverDir(runDir, "frame-diff-calls");
103
+ const dir = paths(runDir).frameDiffCalls;
104
104
  return { dir, payload: join(dir, "call-001.json") };
105
105
  }
106
106
 
@@ -243,9 +243,3 @@ export function recordFrameDiff(runDir, received, { now = () => new Date().toISO
243
243
  capture_failed: captureFailed,
244
244
  };
245
245
  }
246
-
247
- /** Read back what was written — used by the tool's answer so the seat is told the stored state. */
248
- export function readRecordedFrameDiff(runDir) {
249
- try { return parseFrameDiff(readFileSync(join(String(runDir ?? ""), MODEL_FILE), "utf8")); }
250
- catch { return null; }
251
- }
@@ -31,7 +31,7 @@ export const manifestPathFor = (fwPath) => String(fwPath).replace(/\.md$/, ".man
31
31
  // {
32
32
  // "schema_version": 1,
33
33
  // "framework_key": "house-default", // the rated_under_framework tripwire token
34
- // "title": "Generic default risk framework",
34
+ // "title": "Standard risk scale",
35
35
  // "source_deck": "<the deck of record this transcribes>",
36
36
  // "entity_label": "the company", // how the deck names the client side in prose
37
37
  // "bands": [{ "label": "Very High", "tone": "severe" }, ...], // ordered highest → lowest
@@ -28,16 +28,15 @@
28
28
  import { readFileSync, readdirSync, existsSync, statSync } from "node:fs";
29
29
  import { join } from "node:path";
30
30
  import { FATES } from "./hit-list.mjs"; // — THE fate set, imported, never re-declared
31
- import { driverDir } from "../shared/driver-dir.mjs"; //
32
31
  import { slugStability, groupByMark } from "./plan-stability.mjs";
33
32
 
34
33
  // doc 50: the composite table is imported (one source, legacy runs only); a v4 finding's canonical
35
34
  // word is its own `band` — telemetry compares against whichever the finding carries.
36
35
  import { CLIENT_TIER_BY_COMPOSITE as TIER_BY_COMPOSITE } from "./findings-model.mjs";
37
36
  import { isEntrypoint } from "../shared/is-entrypoint.mjs"; // — realpath both sides, or a symlinked invocation exits 0 silently
37
+ import { paths, readJson, readJsonOrNull } from "./run-record.mjs";
38
38
  const canonicalWord = (f) => f?.band != null ? String(f.band) : TIER_BY_COMPOSITE[f?.composite];
39
39
  const norm = (s) => String(s ?? "").toLowerCase().replace(/[^a-z0-9]+/g, " ").trim();
40
- const readJson = (p) => { try { return JSON.parse(readFileSync(p, "utf8")); } catch { return null; } };
41
40
  const readText = (p) => { try { return readFileSync(p, "utf8"); } catch { return ""; } };
42
41
 
43
42
  export function findRunDirs(roots) {
@@ -69,11 +68,11 @@ function deferralSlice(directive) {
69
68
  }
70
69
 
71
70
  export function deferralsRendered(runDir) {
72
- const rec = readJson(driverDir(runDir, "frame-reopen.json"));
71
+ const rec = readJsonOrNull(paths(runDir).frameReopenReceipt);
73
72
  const defs = rec?.deferrals ?? [];
74
73
  if (!defs.length) return null;
75
74
  const report = norm(readText(join(runDir, "report.md")));
76
- const f = readJson(join(runDir, "findings.json"));
75
+ const f = readJsonOrNull(join(runDir, "findings.json"));
77
76
  const covText = norm((f?.coverage ?? []).map((c) => `${c.area} ${c.note ?? ""}`).join(" "));
78
77
  let rendered = 0;
79
78
  for (const d of defs) {
@@ -108,7 +107,7 @@ export function skepticConsumed(runDir) {
108
107
  if (!bullets.length) return null;
109
108
  // An absent register is not a run where nothing was consumed — it is a run this metric cannot read.
110
109
  // Returning 0-of-N here would print as a total collapse in skeptic uptake.
111
- const parsed = readJson(join(runDir, "findings.json"));
110
+ const parsed = readJsonOrNull(join(runDir, "findings.json"));
112
111
  if (!parsed) return null;
113
112
  const register = norm(findingsText(parsed));
114
113
  let consumed = 0;
@@ -124,7 +123,7 @@ export function skepticConsumed(runDir) {
124
123
  // "Scored" = composite>=3 (legacy) or band-rated at all (doc 50 v4 — off-field carries no band, so
125
124
  // band-presence IS the rated line; telemetry only, so no manifest rank needed here).
126
125
  export function scoredFetched(runDir) {
127
- const f = readJson(join(runDir, "findings.json"));
126
+ const f = readJsonOrNull(join(runDir, "findings.json"));
128
127
  const scored = (f?.findings ?? []).filter((x) => (x?.composite ?? 0) >= 3 || x?.band != null);
129
128
  if (!scored.length) return null;
130
129
  // ── THE FATE CODES, WHERE THE RUN HAS THEM ──────────────────────────────────
@@ -147,7 +146,7 @@ export function scoredFetched(runDir) {
147
146
  // uppercase. Both sides are lowercased before joining, as the `_records/` path below already does. An
148
147
  // un-normalised join here would miss ALL of them, not some — and a total miss reads as a clean
149
148
  // `fetched: 0`, which is this metric's alert, not its absence.
150
- const lines = readJson(join(runDir, "register-hit-list.json"))?.lines;
149
+ const lines = readJsonOrNull(join(runDir, "register-hit-list.json"))?.lines;
151
150
  // NOT COMPUTED WHERE THE CODES ARE NOT THERE. The reading step is not asked for fate codes, and a list whose
152
151
  // lines carry none says nothing about what judgment opened: read as a measurement, every scored finding would
153
152
  // count as unfetched, an alarm about nothing. It says it could not be computed instead.
@@ -209,7 +208,7 @@ export function scoredFetched(runDir) {
209
208
  const fetched = new Set();
210
209
  for (const file of readdirSync(recDir)) {
211
210
  if (!file.endsWith(".json")) continue;
212
- const uri = readJson(join(recDir, file))?._uri;
211
+ const uri = readJsonOrNull(join(recDir, file))?._uri;
213
212
  if (uri) fetched.add(String(uri).toLowerCase());
214
213
  }
215
214
  let ok = 0;
@@ -228,7 +227,7 @@ export function scoredFetched(runDir) {
228
227
  // archived runs it was built for. Read a null here as "no such surface", never as a failing join.
229
228
  export function clientTierMatch(runDir) {
230
229
  const cs = readText(join(runDir, "client-summary.md"));
231
- const f = readJson(join(runDir, "findings.json"));
230
+ const f = readJsonOrNull(join(runDir, "findings.json"));
232
231
  if (!cs.trim() || !f?.findings?.length) return null;
233
232
  const blocks = [...cs.matchAll(/^## +([^\n—-]+).*\n([\s\S]*?)(?=^## |\s*$)/gm)];
234
233
  let total = 0, match = 0;
@@ -252,7 +251,7 @@ function pct(agg) { return agg.den ? Math.round((100 * agg.num) / agg.den) : nul
252
251
  // states the linted constraints in the drafting prompts; this is the before/after meter.
253
252
  export function lintFirstPassTax(runDir) {
254
253
  try {
255
- const sink = JSON.parse(readFileSync(driverDir(runDir, "predelivery-lint.json"), "utf8"));
254
+ const sink = readJson(paths(runDir).predeliveryLint);
256
255
  if (!Array.isArray(sink?.initialFailures)) return null;
257
256
  return { initialFailures: sink.initialFailures.length };
258
257
  } catch { return null; }
@@ -263,7 +262,7 @@ export function lintFirstPassTax(runDir) {
263
262
  // both covered, keyed on trigger). Read off the append-only run.jsonl spine, so it survives everything
264
263
  // including in-place overwrites. Returns null when the run never tripped (legacy runs by construction).
265
264
  export function documentGrowth(runDir) {
266
- const raw = readText(driverDir(runDir, "run.jsonl"));
265
+ const raw = readText(paths(runDir).run);
267
266
  if (!raw) return null;
268
267
  const trips = [];
269
268
  for (const ln of raw.split("\n")) {