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
@@ -12,16 +12,15 @@
12
12
  // THE ISSUE DATE IS THE FIRST ONE: what the pool's meta.json kept, or the delivery the run recorded when the pool
13
13
  // holds no copy (a demo, or a run republished into an empty pool), and the clock only when neither exists, which is
14
14
  // a first publish. `renderedAt` is this publish, recorded apart from both.
15
- import { readFileSync } from "node:fs";
16
15
  import { join } from "node:path";
16
+ import { readJsonOrNull } from "../run-record.mjs";
17
17
 
18
- const readJson = (file) => { try { return JSON.parse(readFileSync(file, "utf8")); } catch { return null; } };
19
18
  const instant = (value) => (typeof value === "string" && !Number.isNaN(Date.parse(value)) ? value : null);
20
19
 
21
20
  /** `{searchedAt, issuedAt, renderedAt}` as ISO strings. `searchedAt` is null when the run records no start. */
22
21
  export function reportDates({ runDir, poolRunDir, now = new Date() }) {
23
- const status = readJson(join(runDir, "status.json"));
24
- const kept = readJson(join(poolRunDir, "meta.json"));
22
+ const status = readJsonOrNull(join(runDir, "status.json"));
23
+ const kept = readJsonOrNull(join(poolRunDir, "meta.json"));
25
24
  return {
26
25
  searchedAt: instant(status?.startedAt),
27
26
  issuedAt: instant(kept?.issuedAt) ?? instant(status?.deliveredAt) ?? now.toISOString(),
@@ -12,16 +12,13 @@
12
12
  // publishReport unconditionally, so `republish <a knockout run>` failed on a missing report.md and no
13
13
  // knockout report could ever be re-rendered. A report shape you cannot re-render is a report shape you
14
14
  // cannot fix after delivery.
15
- import { existsSync, readFileSync } from 'node:fs';
15
+ import { existsSync } from 'node:fs';
16
16
  import { join } from 'node:path';
17
- import { driverDir } from '../../shared/driver-dir.mjs'; //
17
+ import { paths, readJson, readJsonOrNull } from "../run-record.mjs";
18
18
  import { publishReport } from './index.mjs';
19
19
  import { publishKnockout } from './knockout.mjs';
20
20
  import { worstBand } from '../verify-knockout.mjs';
21
21
 
22
- const readJson = (p) => JSON.parse(readFileSync(p, 'utf8'));
23
- const readJsonOr = (p, fallback = null) => { try { return readJson(p); } catch { return fallback; } };
24
-
25
22
  /** The template a PUBLISHED run was rendered under, read from its meta.
26
23
  *
27
24
  * `meta.template` has been stamped by both publishers since long before it was read by anything; this is
@@ -43,7 +40,7 @@ export async function republishRun({ runId, meta, pool, poolUrl, runDir, skipReg
43
40
  const template = templateOfMeta(meta);
44
41
  if (template !== 'knockout') {
45
42
  if (!existsSync(join(runDir, 'report.md'))) throw new Error(`${runDir} has no report.md — not a clearance run workspace.`);
46
- const prof = readJsonOr(driverDir(runDir, 'profile.json'));
43
+ const prof = readJsonOrNull(paths(runDir).profile);
47
44
  return publishReport({
48
45
  runId,
49
46
  codename: meta?.codename || '',
@@ -66,16 +63,16 @@ export async function republishRun({ runId, meta, pool, poolUrl, runDir, skipReg
66
63
  const findingsPath = join(runDir, 'knockout-findings.json');
67
64
  if (!existsSync(findingsPath)) throw new Error(`${runDir} has no knockout-findings.json — not a knockout run workspace.`);
68
65
  const findings = readJson(findingsPath);
69
- const framework = readJsonOr(driverDir(runDir, 'framework.json'));
66
+ const framework = readJsonOrNull(paths(runDir).framework);
70
67
  if (!framework) throw new Error(`${runDir} has no _driver/framework.json — a knockout cannot be re-rendered without the bands it was rated under.`);
71
- const searchPolicy = readJsonOr(driverDir(runDir, 'search-policy.json'));
72
- const prof = readJsonOr(driverDir(runDir, 'profile.json'));
68
+ const searchPolicy = readJsonOrNull(paths(runDir).searchPolicy);
69
+ const prof = readJsonOrNull(paths(runDir).profile);
73
70
  return publishKnockout({
74
71
  runId,
75
72
  codename: meta?.codename || '',
76
73
  runDir,
77
74
  findings,
78
- plan: readJsonOr(join(runDir, 'knockout-plan.json')),
75
+ plan: readJsonOrNull(join(runDir, 'knockout-plan.json')),
79
76
  framework,
80
77
  // Recomputed from the frozen framework + the frozen findings, exactly as the lane computed it. The
81
78
  // stored meta.overall is not trusted as an input: it is an OUTPUT of this same join, and feeding an
@@ -34,8 +34,9 @@
34
34
  // shape that reads like "seeded nothing, all good", because "the archive is empty" and "the archive is
35
35
  // empty and nobody noticed why" look identical from the browser.
36
36
 
37
- import { existsSync, readdirSync, readFileSync } from "node:fs";
37
+ import { existsSync, readdirSync } from "node:fs";
38
38
  import { join } from "node:path";
39
+ import { readJson } from "../run-record.mjs";
39
40
 
40
41
  /** A pool "run" is a directory holding meta.json. Mirrors pool-admin.mjs's listRuns and regenIndex's
41
42
  * scan filter — `customer` is the per-customer page tree, not a run. */
@@ -79,7 +80,7 @@ export function frozenSamples(examplesDir) {
79
80
  continue;
80
81
  }
81
82
  let meta;
82
- try { meta = JSON.parse(readFileSync(manifest, "utf8")); }
83
+ try { meta = readJson(manifest); }
83
84
  catch (e) { problems.push(`${manifest} is not readable JSON (${String(e?.message ?? e)})`); continue; }
84
85
  if (!meta?.runId) { problems.push(`${manifest} names no runId — it is not a frozen example manifest`); continue; }
85
86
  if (!hasRun) { problems.push(`${dir} names runId ${meta.runId} but has no run/ directory to publish`); continue; }
@@ -0,0 +1,106 @@
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
+ // publish/shell.mjs — what publishing a report does whichever report it is. Both publishers call it; what a report says stays
4
+ // with its own renderer.
5
+ //
6
+ // A PART THAT FAILS DOES NOT STOP THE REPORT, and both publishers answer alike (design ruling, 2026-11-10). A workbook that
7
+ // cannot be built or a data file that cannot be written leaves the report in place, and nothing the run publishes names the
8
+ // missing file. A staff-page refresh that fails is recorded after the report is in place. The report page and `meta.json`
9
+ // are not parts: a failure to write either still throws, because then there is no report to deliver.
10
+ import { chmodSync, copyFileSync, mkdirSync, rmSync, writeFileSync } from 'node:fs';
11
+ import { join } from 'node:path';
12
+
13
+ import { runLog } from '../log.mjs';
14
+ import { RUN_DIR_MODE } from '../run-record.mjs';
15
+
16
+ export const grpRead = (p, mode) => { try { chmodSync(p, mode); } catch { /* best-effort */ } };
17
+
18
+ const reasonOf = (e) => String(e?.message ?? e);
19
+ const record = (runDir, row) => { if (runDir) { try { runLog(runDir, row); } catch { /* meta.json and the return carry it too */ } } };
20
+ const removePart = (p) => { try { rmSync(p, { force: true }); } catch { /* nothing names it, so a leftover is never offered */ } };
21
+
22
+ /**
23
+ * Create a run's folder in the report pool and return the ways a publisher puts a file there.
24
+ *
25
+ * The run dir inherits the web-server group + the set-GID bit AUTOMATICALLY from the set-GID pool root
26
+ * (mode 2750, web-server group) — so files written inside take that group and the web server (Caddy in
27
+ * the reference deployment, mode 0640) can read them. Do NOT chmod this dir: the service account is not
28
+ * a member of the web-server group, and POSIX silently strips S_ISGID when a non-member sets it, leaving
29
+ * the dir 0750 → new files fall back to the service account's primary group → every report 403s. (An explicit
30
+ * `grpRead(poolRunDir, 0o2750)` here, added 2026-06-02, WAS that 403 bug; removed 2026-06-08.)
31
+ *
32
+ * The two parts a report can ship without go through the folder too. `buildWorkbook(name, build)` awaits `build(path)` and
33
+ * returns `{ auditFile, auditError, built }`: the file's name and what `build` returned, or a null name and the reason when
34
+ * it threw, with any part of the file it left removed. `writeDataFile(name, produce)` writes `produce()` as JSON and
35
+ * returns the name, or null when either threw, so a caller claims a data file only when it exists. `copyPart(src, name)`
36
+ * copies a run file into the folder the same way, and returns the name or null. All three record a failure in `runDir`'s
37
+ * log when they are given one.
38
+ */
39
+ export function openPoolRun(poolRoot, runId, { runDir = null } = {}) {
40
+ const poolRunDir = join(poolRoot, runId);
41
+ mkdirSync(poolRunDir, { recursive: true, mode: RUN_DIR_MODE }); // owner and group only; mkdir keeps the pool root's set-GID
42
+ const writeRO = (name, data) => { const p = join(poolRunDir, name); writeFileSync(p, data); grpRead(p, 0o640); };
43
+ const copyRO = (src, name) => { const p = join(poolRunDir, name); copyFileSync(src, p); grpRead(p, 0o640); };
44
+ const buildWorkbook = async (name, build) => {
45
+ const p = join(poolRunDir, name);
46
+ try {
47
+ const built = await build(p);
48
+ grpRead(p, 0o640);
49
+ return { auditFile: name, auditError: null, built };
50
+ } catch (e) {
51
+ removePart(p);
52
+ const auditError = reasonOf(e);
53
+ console.warn(`[audit-workbook] not built, the report ships without it: ${auditError.slice(0, 140)}`);
54
+ record(runDir, { event: 'workbook-not-built', file: name, error: auditError.slice(0, 300) });
55
+ return { auditFile: null, auditError, built: null };
56
+ }
57
+ };
58
+ const writeDataFile = (name, produce) => {
59
+ try { writeRO(name, JSON.stringify(produce(), null, 2)); return name; }
60
+ catch (e) {
61
+ removePart(join(poolRunDir, name));
62
+ const error = reasonOf(e);
63
+ console.warn(`[report-data] ${name} not written, the report ships without it: ${error.slice(0, 140)}`);
64
+ record(runDir, { event: 'data-file-not-written', file: name, error: error.slice(0, 300) });
65
+ return null;
66
+ }
67
+ };
68
+ const copyPart = (src, name) => {
69
+ try { copyRO(src, name); return name; }
70
+ catch (e) {
71
+ removePart(join(poolRunDir, name));
72
+ const error = reasonOf(e);
73
+ console.warn(`[publish] ${name} not copied, the report ships without it: ${error.slice(0, 140)}`);
74
+ record(runDir, { event: 'data-file-not-written', file: name, error: error.slice(0, 300) });
75
+ return null;
76
+ }
77
+ };
78
+ return { poolRunDir, writeRO, copyRO, copyPart, buildWorkbook, writeDataFile };
79
+ }
80
+
81
+ /**
82
+ * Write the run's `meta.json` and refresh the pool's index, and return the index's count (null when the caller asked for
83
+ * no refresh). `meta.json` is the last file a publisher writes, because the index lists only folders that hold one: every
84
+ * document is in place before the run becomes visible. `regenIndex` is passed in because it lives with the clearance
85
+ * publisher, which imports this module.
86
+ */
87
+ export function finishPoolRun({ writeRO, meta, poolRoot, skipRegen, regenIndex }) {
88
+ writeRO('meta.json', JSON.stringify(meta, null, 2));
89
+ return skipRegen ? null : regenIndex(poolRoot);
90
+ }
91
+
92
+ /**
93
+ * Refresh the staff pages once the report and its `meta.json` are in place. A failure is recorded and returned, never
94
+ * thrown: the report is already delivered, and the next publish refreshes the pages again. `regenSurfaces` is passed in for
95
+ * the reason `regenIndex` is. Returns null when the refresh ran or was not asked for.
96
+ */
97
+ export async function refreshStaffPages({ regenSurfaces, poolRoot, skipRegen, runDir = null }) {
98
+ if (skipRegen) return null;
99
+ try { await regenSurfaces(poolRoot); return null; }
100
+ catch (e) {
101
+ const error = reasonOf(e);
102
+ console.warn(`[publish] staff pages not refreshed, the report is in place: ${error.slice(0, 140)}`);
103
+ record(runDir, { event: 'staff-pages-not-refreshed', error: error.slice(0, 300) });
104
+ return error;
105
+ }
106
+ }
@@ -41,7 +41,7 @@
41
41
  The visible sentence loses its bottom margin (the fold row carries the spacing instead) so a folded
42
42
  caption occupies the same vertical run as an unfolded one. `details.sub-more` is styled here and NOT
43
43
  in the frozen renderer, and the existing @media print rule that forces every <details> open already
44
- covers it — the exported PDF carries the whole caption, which is #470's rule for print. */
44
+ covers it — the exported PDF carries the whole caption, which is the rule for print. */
45
45
  details.sub-more{margin:0 0 30px;max-width:700px}
46
46
  details.sub-more>summary{cursor:pointer;list-style:none;font-size:12.5px;font-weight:700;
47
47
  letter-spacing:.06em;text-transform:uppercase;color:var(--faint)}
@@ -59,7 +59,9 @@
59
59
  /* the framework that owns the ticks, named where they are read. Normal case and un-tracked on
60
60
  purpose: `.label` is an uppercase eyebrow, and a proper name in the eyebrow's own letterforms reads
61
61
  as a second heading rather than as the thing being cited. */
62
- .gauge .label .gauge-fw{display:block;margin-top:5px;font-size:11px;font-weight:600;letter-spacing:0;
62
+ .gauge .gauge-head{margin-bottom:18px}
63
+ .gauge .gauge-head .label{margin-bottom:0}
64
+ .gauge .gauge-fw{margin-top:5px;font-size:11px;font-weight:600;letter-spacing:0;
63
65
  text-transform:none;color:var(--slate)}
64
66
  .scale{position:relative;height:11px;border-radius:8px;margin:34px 0 10px;
65
67
  background:linear-gradient(90deg,var(--clear) 0%,var(--low) 26%,var(--med) 52%,var(--high) 79%,var(--severe) 100%)}
@@ -395,19 +397,19 @@
395
397
  hash pins the renderer's bytes and the render arms grep its HTML, and on screen a mis-ruled
396
398
  disclosure is correct. It is the private print control that walks a rendered page on both lanes
397
399
  and refuses a disclosure ruled by neither mechanism, and it runs by hand. Two folds have now
398
- shipped mis-ruled and been caught there rather than in CI. `details.sub-more` (#470) was in NEITHER, so the exported PDF — the
400
+ shipped mis-ruled and been caught there rather than in CI. `details.sub-more` was in NEITHER, so the exported PDF — the
399
401
  client-facing legal document — printed an inert "MORE" label and a right-pointing COLLAPSED marker
400
402
  in the hero, directly above text that was already fully expanded. Measured in Chrome: the caption's
401
403
  own content was carried correctly and only the control leaked, which is why the commit that added
402
404
  the fold could check the half it thought about and ship the half it did not. */
403
405
  details.drill>summary,details.method>summary,details.sub-more>summary,
404
406
  /* An answer's "More" is a pure toggle: it carries no content of its own, so on paper it would be an
405
- inert label over text the rule below has already expanded — the defect #470 shipped. */
407
+ inert label over text the rule below has already expanded — a defect that once shipped. */
406
408
  details.ans-more>summary{display:none!important}
407
409
  /* The caption fold made this line load-bearing for the document's CONTENT, not just its completeness. The
408
410
  legal/practical reads now live inside .drillbody, so without this rule the exported PDF would
409
411
  carry the one-line verdicts and none of the reasoning behind them. The export prints everything a
410
- reader could open — ruled on #470, deliberately unchanged. Ticked-card selection (.print-hidden)
412
+ reader could open — a deliberate rule, unchanged. Ticked-card selection (.print-hidden)
411
413
  and internal notes (.int-note, hidden above) are the only two things print ever drops. */
412
414
  details>*:not(summary){display:block!important}
413
415
  details>summary{list-style:none;cursor:default}
@@ -463,7 +465,7 @@
463
465
  /* ── P5 (charter 2026-07-30) — content model: legal/practical split · manageable category · the
464
466
  four answers. This file is NOT hash-frozen; the render emits the markup, the rules live here. */
465
467
  /* the legal vs practical pair — two labelled reads, never blurred.
466
- #470: these moved out of the card body and into the "Full detail & provenance" drawer, where they
468
+ These moved out of the card body and into the "Full detail & provenance" drawer, where they
467
469
  LEAD, so they are sized for the drawer's own reading text (.drillbody is 13.5px/1.62) instead of the
468
470
  tighter card body they used to sit in. The first block has no top margin — .drillbody's padding is
469
471
  the gap — and the last one is spaced off the structured <ul> that follows it. */
@@ -490,7 +492,7 @@
490
492
  browser's default weight, under the browser's default triangle, at the foot of a document whose
491
493
  every other section carries a numbered spine header. The section that states what the search did
492
494
  NOT cover was the one region on the page a reader's eye had no reason to stop at.
493
- This is the styling half of #763 and it costs no hash bump — the markup is unchanged. */
495
+ This is the styling half of that change and it costs no hash bump — the markup is unchanged. */
494
496
  details.scope>summary{cursor:pointer;list-style:none;margin:22px 0 0;padding:12px 0 10px;
495
497
  border-top:1px solid var(--line);font-size:15px;font-weight:700;letter-spacing:-.01em;color:var(--ink)}
496
498
  details.scope>summary::-webkit-details-marker{display:none}
@@ -20,14 +20,15 @@
20
20
  // out there it can never match the `*.json` claim glob, checkRunCaps's `*.{json,processing,postponed}`
21
21
  // parse set, or prelim-driver.path's watch — and reordering must NOT wake the runner.
22
22
 
23
- import { readFileSync, writeFileSync, renameSync, mkdirSync, readdirSync } from "node:fs";
23
+ import { writeFileSync, renameSync, mkdirSync, readdirSync } from "node:fs";
24
24
  import { join, dirname } from "node:path"; import { studioDirFor } from "../shared/pre-rename-spellings.mjs";
25
+ import { readJson } from "./run-record.mjs";
25
26
 
26
27
  export function queueOrderPath(qdir) { return join(dirname(qdir), ".queue-order.json"); }
27
28
 
28
29
  export function readQueueOrder(qdir) {
29
30
  try {
30
- const j = JSON.parse(readFileSync(queueOrderPath(qdir), "utf8"));
31
+ const j = readJson(queueOrderPath(qdir));
31
32
  return Array.isArray(j?.order) ? j.order.filter((s) => typeof s === "string" && s) : [];
32
33
  } catch { return []; } // absent, unreadable or corrupt ⇒ assert nothing, fall through to enqueuedAt
33
34
  }
@@ -55,7 +56,7 @@ export function orderedQueueFiles(qdir, files) {
55
56
  const listed = rank.get(f.replace(/\.json$/, ""));
56
57
  if (listed !== undefined) return { f, tier: 0, pos: listed, at: "" };
57
58
  let at = "";
58
- try { at = String(JSON.parse(readFileSync(join(qdir, f), "utf8")).enqueuedAt ?? ""); } catch { /* sorts by name */ }
59
+ try { at = String(readJson(join(qdir, f)).enqueuedAt ?? ""); } catch { /* sorts by name */ }
59
60
  return { f, tier: 1, pos: 0, at };
60
61
  });
61
62
  keyed.sort((a, b) => a.tier - b.tier || a.pos - b.pos || a.at.localeCompare(b.at) || a.f.localeCompare(b.f));
@@ -66,10 +66,6 @@ export const RECORD_CARRY_SCHEMA_VERSION = 4;
66
66
  * clean run came to read as a total loss. Legitimate for a run archived before and
67
67
  * for the probe; a fresh run reporting it is a defect, flagged by the predelivery lint.
68
68
  */
69
- export const TRACE_BASES = ["recorded", "reconstructed"];
70
-
71
- /** How far a record got. Ordered; index = distance travelled. */
72
- export const REACH_STAGES = ["retrieved", "screened", "placed", "findings-surface", "finding"];
73
69
 
74
70
  /**
75
71
  * WHERE THE REASON WAS AUTHORED — the ruling's "weigh where the reason is authored", made a field so a
@@ -85,9 +81,6 @@ export const REACH_STAGES = ["retrieved", "screened", "placed", "findings-surfac
85
81
  */
86
82
  export const REASON_SOURCES = ["step-structural", "step-stated", "step-silent", "absent"];
87
83
 
88
- /** The seam a record failed to cross. `null` when it became a finding. */
89
- export const SEAMS = ["screen", "placement", "digest", "synthesis"];
90
-
91
84
  /**
92
85
  * WHAT THIS TRACE COVERS AND WHAT IT DOES NOT — carried IN THE ARTIFACT, not just in a PR body.
93
86
  *
@@ -431,8 +424,6 @@ const bump = (o, k) => { o[k] = (o[k] ?? 0) + 1; };
431
424
  * checked first because execute-plan.mjs writes it ALONGSIDE `error`, never instead of it, and the
432
425
  * capability gap is the more specific fact. PURE.
433
426
  */
434
- export const SLICE_CLASSES = ["counted-not-fetched", "capability-gap", "provider-error", "count-unavailable"];
435
-
436
427
  // — the fourth class. `counted-not-fetched` claimed the run HAS a count, which for a slice the
437
428
  // register refused to size is the same false claim removed, wearing the new machine field. This
438
429
  // one is distinct from the two refusals above: the slice DID run and may have returned records — it is
@@ -53,7 +53,7 @@
53
53
 
54
54
  import { appendFileSync, mkdirSync } from "node:fs";
55
55
  import { join } from "node:path";
56
- import { driverDir } from "../shared/driver-dir.mjs"; //
56
+ import { driverDir } from "./run-record.mjs"; //
57
57
 
58
58
  import { normalizeRecordUri } from "./registry-fidelity.mjs";
59
59
 
@@ -72,9 +72,6 @@ export const DISCARD_LEDGER_NAME = "record-discard.jsonl";
72
72
  */
73
73
  export const DISCARD_SEAMS = ["placement", "digest", "synthesis"];
74
74
 
75
- /** What a pass did with a record. `carried` cancels an earlier `discarded` at the same seam. */
76
- export const DISCARD_VERDICTS = ["carried", "discarded"];
77
-
78
75
  const clip = (s, n = 300) => {
79
76
  const t = String(s ?? "").replace(/\s+/g, " ").trim();
80
77
  return t.length > n ? `${t.slice(0, n - 1)}…` : t;
@@ -29,9 +29,9 @@
29
29
  // in force.
30
30
  import { readFileSync, writeFileSync, existsSync, renameSync, rmSync, mkdirSync } from "node:fs";
31
31
  import { dirname } from "node:path";
32
- import { driverDir } from "../shared/driver-dir.mjs";
33
32
  import { consolidateFindings, remapActionOrdinals, remapFourAnswersOrdinals, parseFindingsJson } from "./findings-model.mjs";
34
33
  import { parseFrameworkManifest } from "./framework.mjs";
34
+ import { driverDir, paths, readJson } from "./run-record.mjs";
35
35
 
36
36
  export const FOLD_FILE = "fold.json";
37
37
  export const UNFOLDED_FILE = "findings-unfolded.json";
@@ -63,7 +63,7 @@ export function foldRecord(doc, manifest = null) {
63
63
 
64
64
  /** The fold state of a run, or null before any seam. Never throws. */
65
65
  export function readFold(runDir) {
66
- try { return JSON.parse(readFileSync(driverDir(String(runDir ?? ""), FOLD_FILE), "utf8")); } catch { return null; }
66
+ try { return readJson(driverDir(String(runDir ?? ""), FOLD_FILE)); } catch { return null; }
67
67
  }
68
68
 
69
69
  function writeFold(runDir, { seamPassed, map = null, merges = [], error = null }) {
@@ -138,7 +138,7 @@ export function foldFindingsFile(runDir, findingsPath, manifest, { seam = false
138
138
  /** The fold an accepted save makes, with the run's frozen framework manifest. Never throws. */
139
139
  export function foldAfterSave(runDir, findingsPath) {
140
140
  let manifest = null;
141
- try { manifest = parseFrameworkManifest(readFileSync(driverDir(String(runDir ?? ""), "framework.json"), "utf8")); }
141
+ try { manifest = parseFrameworkManifest(readFileSync(paths(String(runDir ?? "")).framework, "utf8")); }
142
142
  catch { manifest = null; } // a run with no frozen manifest folds as the seam does for it
143
143
  return foldFindingsFile(runDir, findingsPath, manifest);
144
144
  }
@@ -15,14 +15,15 @@
15
15
  // UNKNOWN IS NOT A MISMATCH. A record with no goods on file passes a goods filter, the way a record that
16
16
  // names no class passes the class scope (band-shape.mjs `inScope`): a filter must never hide a record for
17
17
  // what the run simply does not hold.
18
+ import { createHash } from "node:crypto";
18
19
  import { readFileSync, readdirSync, existsSync } from "node:fs";
19
20
  import { join } from "node:path";
20
- import { driverDir } from "../shared/driver-dir.mjs";
21
21
  import { normalizeRecordUri } from "./registry-fidelity.mjs";
22
22
  import { foldDiacritics } from "./form-neighbourhood.mjs";
23
23
  import { parseVariantManifestModel } from "./variant-manifest-model.mjs";
24
24
  import { canonicalJurisdictionCode } from "./jurisdiction-codes.mjs";
25
25
  import { savedStatusPages, savedPageStatement, usSerialOf } from "./saved-register-pages.mjs";
26
+ import { paths, readJson } from "./run-record.mjs";
26
27
 
27
28
  /**
28
29
  * The registers whose language is English (ruled 2026-10-12): there, a goods statement with no language tag
@@ -218,7 +219,7 @@ export function bandGoodsIndex(runDir) {
218
219
  const goods = recordGoods(body, { english: untaggedIsEnglish(key) });
219
220
  if (goods.length) index.set(key, goods);
220
221
  };
221
- const ledger = driverDir(runDir, "register-record-bodies.jsonl");
222
+ const ledger = paths(runDir).registerRecordBodies;
222
223
  if (existsSync(ledger)) {
223
224
  let text = "";
224
225
  try { text = readFileSync(ledger, "utf8"); } catch { text = ""; }
@@ -233,7 +234,7 @@ export function bandGoodsIndex(runDir) {
233
234
  let names = [];
234
235
  try { names = readdirSync(dir).filter((n) => n.endsWith(".json")); } catch { names = []; }
235
236
  for (const n of names) {
236
- try { const body = JSON.parse(readFileSync(join(dir, n), "utf8")); take(body?._uri ?? body?.uri, body); } catch { /* unreadable: skip */ }
237
+ try { const body = readJson(join(dir, n)); take(body?._uri ?? body?.uri, body); } catch { /* unreadable: skip */ }
237
238
  }
238
239
  }
239
240
  return index;
@@ -280,6 +281,14 @@ export function rowGoods(row, pages = null) {
280
281
  const page = mark && serial ? savedPageStatement(pages, serial, whole.classes[0], whole.text) : null;
281
282
  out.push(page ? { ...whole, text: page.text, page: { question: page.question } } : { ...whole, ...mark });
282
283
  }
284
+ // A CLASS WHOSE TEXT THE MERGED BAND SET ASIDE (named-band.mjs `rowAsHanded`, outside the order's classes) is an entry
285
+ // marked `setAside` with no text: the class is on the record, and its wording is not here, which establishes nothing
286
+ // about it. It is never the register listing no goods, and never a search not made.
287
+ // Where the merge saved the shape's own goods test's answer on the record's whole wording (`setAsideTestAnswer`), the
288
+ // entry carries it, and only a test on the same word list reads it (`goodsWordCounter`'s `setAsideTest`).
289
+ const aside = Array.isArray(row?.goods_set_aside?.classes) ? row.goods_set_aside.classes : [];
290
+ const test = row?.goods_set_aside?.test && typeof row.goods_set_aside.test === "object" ? row.goods_set_aside.test : null;
291
+ for (const n of aside) out.push({ classes: [String(n)], text: "", setAside: true, ...(test ? { test } : {}) });
283
292
  return out.length ? out : null;
284
293
  }
285
294
 
@@ -292,16 +301,19 @@ export const statementCut = (goods) => (goods ?? []).some((g) => g?.cut === true
292
301
 
293
302
  /** Is a statement of these goods one whose completeness is not established (`rowGoods`, `recordGoods`)? PURE. */
294
303
  export const completenessUnknown = (goods) => (goods ?? []).some((g) => g?.unknown === true);
295
- /** Could words cut off, or not shown, from these goods be the client's? Then a statement matching none is unknown. PURE. */
296
- const notWhole = (goods) => statementCut(goods) || completenessUnknown(goods);
304
+ /** Was a class's wording set aside from the merged band (`rowGoods`)? Its words may be the client's. PURE. */
305
+ export const statementSetAside = (goods) => (goods ?? []).some((g) => g?.setAside === true);
306
+ /** Could words cut off, not shown, or set aside from these goods be the client's? Then a statement matching none is unknown. PURE. */
307
+ const notWhole = (goods) => statementCut(goods) || completenessUnknown(goods) || statementSetAside(goods);
297
308
 
298
- /** How many records rest on each kind of goods evidence: a held body, a row's whole statements, a row's statements cut short or not established whole, or none. PURE. */
309
+ /** How many records rest on each kind of goods evidence: a held body, a row's whole statements, a row's statements cut short or not established whole, a row whose other classes' wording was set aside, or none. PURE. */
299
310
  export function goodsEvidence(records, goods) {
300
- const out = { held: 0, complete: 0, cut: 0, unknown: 0, none: 0 };
311
+ const out = { held: 0, complete: 0, cut: 0, unknown: 0, setAside: 0, none: 0 };
301
312
  for (const r of Array.isArray(records) ? records : []) {
302
313
  if (goods?.held?.(r)) { out.held++; continue; }
303
314
  const g = goods ? goods.of(r) : null;
304
- if (!g) out.none++; else if (statementCut(g)) out.cut++; else if (completenessUnknown(g)) out.unknown++; else out.complete++;
315
+ if (!g) out.none++; else if (statementCut(g)) out.cut++; else if (completenessUnknown(g)) out.unknown++;
316
+ else if (statementSetAside(g)) out.setAside++; else out.complete++;
305
317
  }
306
318
  return out;
307
319
  }
@@ -338,13 +350,16 @@ export function goodsWordForms(word) {
338
350
  * word or phrase matches its singular and plural forms (`goodsWordForms`), at word boundaries, never as the
339
351
  * start of a longer word. PURE.
340
352
  */
341
- export function goodsWordCounter(words, { stems = false } = {}) {
353
+ export function goodsWordCounter(words, { stems = false, setAsideTest = false, testKey = null } = {}) {
342
354
  // A phrase's words are separated by spaces or hyphens alike: "mobile phone" is "mobile-phone".
343
355
  const phrase = (w) => w.split(/[\s-]+/).filter(Boolean).map((x) => (stems ? `(?:${goodsWordForms(x).map(escape).join("|")})` : escape(x))).join("[\\s-]+");
344
- const res = (Array.isArray(words) ? words : [words])
345
- .map((w) => fold(w).trim()).filter(Boolean)
346
- .map((w) => new RegExp(`(^|[^\\p{L}\\p{N}])${phrase(w)}($|[^\\p{L}\\p{N}])`, "u"));
356
+ const list = (Array.isArray(words) ? words : [words]).map((w) => fold(w).trim()).filter(Boolean);
357
+ const res = list.map((w) => new RegExp(`(^|[^\\p{L}\\p{N}])${phrase(w)}($|[^\\p{L}\\p{N}])`, "u"));
358
+ const key = setAsideTest ? (testKey ?? goodsTestKey(words, { stems })) : null;
347
359
  return (goods) => {
360
+ // A record whose wording the merge set aside is read on the answer the merge saved for this same list.
361
+ const saved = key ? savedAnswer(goods, key) : undefined;
362
+ if (saved !== undefined) return !res.length || saved == null ? null : list.filter((w) => saved.has(w)).length;
348
363
  const readable = (goods ?? []).filter((g) => g.en !== false);
349
364
  if (!res.length || !readable.length) return null;
350
365
  const text = fold(readable.map((g) => (g.alt ? `${g.text}\n${g.alt}` : g.text)).join("\n"));
@@ -353,6 +368,34 @@ export function goodsWordCounter(words, { stems = false } = {}) {
353
368
  };
354
369
  }
355
370
 
371
+ /**
372
+ * THE SHAPE'S OWN TEST, ANSWERED ON THE WORDING THE MERGE HELD. Before a class's wording is set aside (named-band.mjs
373
+ * `rowAsHanded`), the merge runs the band shape's goods test (`shapeGoodsTest`) on the record's whole wording, every
374
+ * statement joined as the test joins them, and saves the answer on the record with a key for the word list: the words
375
+ * matched, an empty list for a known zero, or null where the test could not tell (wording cut, completeness not
376
+ * established, or a class in no language the engine reads). A test on that same list returns the saved answer for the
377
+ * record as a whole, so a phrase across the boundary of a removed statement is neither lost nor made. Any other list,
378
+ * such as a lookup's own goods words, is not answered, and a set-aside class stays "cannot tell" to it. The answer
379
+ * describes the wording at the merge: a register page the run saves later is read by `band_record`, not by it. PURE.
380
+ */
381
+ export function goodsTestKey(words, { stems = false } = {}) {
382
+ const list = [...new Set((Array.isArray(words) ? words : [words]).map((w) => fold(w).trim()).filter(Boolean))].sort();
383
+ return createHash("sha256").update(JSON.stringify({ stems: Boolean(stems), words: list })).digest("hex").slice(0, 16);
384
+ }
385
+ export function setAsideTestAnswer(statements, { words = [], stems = false } = {}) {
386
+ const list = (Array.isArray(words) ? words : [words]).map((w) => String(w ?? "").trim()).filter(Boolean);
387
+ if (!list.length || !Array.isArray(statements) || !statements.length) return null;
388
+ return { key: goodsTestKey(list, { stems }), matched: goodsWordsMatched(list, { stems })(statements) };
389
+ }
390
+ // The answer the merge saved for a record, where it saved one for this word list: the folded words matched, or null
391
+ // where the test could not tell. undefined where nothing was saved for this list, and the record is read as it stands.
392
+ const savedAnswer = (goods, key) => {
393
+ const aside = (goods ?? []).filter((g) => g?.setAside === true);
394
+ if (!aside.length || !aside.every((g) => g?.test?.key === key)) return undefined;
395
+ const matched = aside[0].test.matched;
396
+ return Array.isArray(matched) ? new Set(matched.map((w) => fold(w).trim())) : null;
397
+ };
398
+
356
399
  /**
357
400
  * Does a class of these goods have no statement the engine can read? A record whose readable statements match
358
401
  * no word, while one of its classes is written only in a language the engine cannot use, is unknown to the
@@ -375,10 +418,13 @@ export function classUnread(goods) {
375
418
  * null when the record has no goods on file or there are no words. A shape line shows them as "k of N:
376
419
  * the words", which is the goods ground made visible on the line. PURE.
377
420
  */
378
- export function goodsWordsMatched(words, { stems = false } = {}) {
421
+ export function goodsWordsMatched(words, { stems = false, setAsideTest = false } = {}) {
379
422
  const list = (Array.isArray(words) ? words : [words]).map((w) => String(w ?? "").trim()).filter(Boolean);
423
+ const key = setAsideTest ? goodsTestKey(list, { stems }) : null;
380
424
  const tests = list.map((w) => [w, goodsWordCounter([w], { stems })]);
381
425
  return (goods) => {
426
+ const saved = key ? savedAnswer(goods, key) : undefined;
427
+ if (saved !== undefined) return !list.length || saved == null ? null : list.filter((w) => saved.has(fold(w).trim()));
382
428
  if (!list.length || !(goods ?? []).some((g) => g.en !== false)) return null;
383
429
  const hit = tests.filter(([, t]) => t(goods) === 1).map(([w]) => w);
384
430
  return hit.length === 0 && (classUnread(goods) || notWhole(goods)) ? null : hit;
@@ -399,7 +445,7 @@ export function goodsWordMatcher(words) {
399
445
  */
400
446
  export function instructedOrder(P, job = null) {
401
447
  let scope = null;
402
- try { scope = JSON.parse(readFileSync(P.instructedScope, "utf8")); } catch { scope = null; }
448
+ try { scope = readJson(P.instructedScope); } catch { scope = null; }
403
449
  const order = { ...(job ?? {}) };
404
450
  for (const k of ["goods", "jurisdictions", "geography"]) if (scope?.[k] != null) order[k] = scope[k];
405
451
  return order;
@@ -419,26 +465,36 @@ export function instructedOrder(P, job = null) {
419
465
  * band's, so the shape tests goods whenever either is held. The saved pages are read once, for the first record with
420
466
  * no body held.
421
467
  */
422
- export function bandShapeGoods(P, records = []) {
468
+ /**
469
+ * The words the band shape's goods test reads: the particular goods when the variants stage names them, as stems, else
470
+ * the goods words (ruled 2026-10-12), with the manifest they came from. The merge reads the same list, to record the
471
+ * test's answer for wording it sets aside (named-band.mjs `rowAsHanded`). IMPURE: reads the run's variant manifest.
472
+ */
473
+ export function shapeGoodsTest(P) {
423
474
  let model = null;
424
475
  try { if (existsSync(P.variantManifestModel)) model = parseVariantManifestModel(readFileSync(P.variantManifestModel, "utf8")); } catch { model = null; }
476
+ const product = Array.isArray(model?.product_words) && model.product_words.length;
477
+ const words = product ? model.product_words : Array.isArray(model?.goods_words) ? model.goods_words : [];
478
+ // the word list the shape groups on is matched as stems, whichever source it came from
479
+ return { model, words, stems: true, source: product ? "product_words" : words.length ? "goods_words" : "none" };
480
+ }
481
+
482
+ export function bandShapeGoods(P, records = []) {
483
+ const { model, words, source, stems } = shapeGoodsTest(P);
425
484
  let searched = "";
426
485
  try {
427
- const plan = JSON.parse(readFileSync(P.registerPlan, "utf8"));
486
+ const plan = readJson(P.registerPlan);
428
487
  searched = String((plan?.entries ?? []).find((e) => /\+goods($|-)/.test(String(e?.qid ?? "")))?.term ?? "");
429
488
  } catch { searched = ""; }
430
489
  const manifestDominant = String(model?.dominant_element ?? "");
431
490
  const index = bandGoodsIndex(P.runDir);
432
- // The particular goods when the variants stage names them, as stems, else the goods words (ruled 2026-10-12).
433
- const product = Array.isArray(model?.product_words) && model.product_words.length;
434
- const words = product ? model.product_words : Array.isArray(model?.goods_words) ? model.goods_words : [];
435
- const stems = true; // the word list the shape groups on is matched as stems, whichever source it came from
436
- const hits = goodsWordCounter(words, { stems });
491
+ // A set-aside class is read through the answer the merge recorded for this same list (`setAsideTestAnswer`).
492
+ const hits = goodsWordCounter(words, { stems, setAsideTest: true });
437
493
  const held = (r) => goodsFor(index, r);
438
494
  let pages = null;
439
495
  const saved = () => (pages ??= savedStatusPages(P.runDir)());
440
496
  const rowsHold = Array.isArray(records) && records.some((r) => r && typeof r === "object" && rowGoods(r));
441
- const goods = index.size || rowsHold ? { of: (r) => held(r) ?? rowGoods(r, saved()), held: (r) => held(r) != null, hits, matched: goodsWordsMatched(words, { stems }) } : null;
442
- const goodsTest = { source: product ? "product_words" : words.length ? "goods_words" : "none", words };
497
+ const goods = index.size || rowsHold ? { of: (r) => held(r) ?? rowGoods(r, saved()), held: (r) => held(r) != null, hits, matched: goodsWordsMatched(words, { stems, setAsideTest: true }) } : null;
498
+ const goodsTest = { source, words };
443
499
  return { goods, goodsTest, goodsWordCount: words.length, dominantTerm: searched || manifestDominant, manifestDominant };
444
500
  }
@@ -336,7 +336,6 @@ function containsWordRun(a, b) {
336
336
  //
337
337
  // An entry in a gold set's `register` array is a REGISTERED RIGHT by construction of the array it sits
338
338
  // in — no per-entry flag is needed and no gold set is edited. What was missing is entirely candidate-side.
339
- export const EVIDENCE_CLASSES = ["register", "common-law", "case-law", "unknown"];
340
339
 
341
340
  /**
342
341
  * Fold a run finding's own typed source into the class the scorer reasons about.
@@ -1862,7 +1861,7 @@ export function readJxLanes(doc) {
1862
1861
  const v = doc.fold?.depth?.[name];
1863
1862
  if (!v || typeof v !== "object") {
1864
1863
  return { recorded: false, asked: d.depth ?? null, ran: null, shortfall: null,
1865
- why: "the run did not state what depth this lane actually got (no fold.depth) — a pre-#893 artifact, "
1864
+ why: "the run did not state what depth this lane actually got (no fold.depth) — an earlier artifact, "
1866
1865
  + "or a run that never reached the delivery statement. Whether the ask was met CANNOT be established" };
1867
1866
  }
1868
1867
  return { recorded: true, asked: v.asked ?? null, ran: v.ran ?? null,
@@ -1890,7 +1889,7 @@ export function readJxLanes(doc) {
1890
1889
  statement: typeof doc.fold?.executes === "string" ? doc.fold.executes : null,
1891
1890
  slices: doc.fold?.slices ?? null,
1892
1891
  statementWhy: typeof doc.fold?.executes === "string" ? null
1893
- : "the run did not state which jx slices it executed (no fold.executes) — a pre-#552 artifact, or a fold that never ran",
1892
+ : "the run did not state which jx slices it executed (no fold.executes) — an earlier artifact, or a fold that never ran",
1894
1893
  };
1895
1894
  }
1896
1895
 
@@ -45,9 +45,3 @@ export function capabilitiesFor(providerId) {
45
45
  }
46
46
  return caps;
47
47
  }
48
-
49
- /** The ACTIVE provider's capabilities (driver.config.mjs owns the toggle; this never re-reads the env). */
50
- export async function activeCapabilities() {
51
- const { REGISTER_PROVIDER } = await import("./driver.config.mjs");
52
- return capabilitiesFor(REGISTER_PROVIDER);
53
- }
@@ -87,7 +87,7 @@
87
87
  // mark generates 3–8. `CLEAROTRON_KNOCKOUT_VARIANT_CAP` lowers it per deployment; nothing raises it above
88
88
  // the code cap, because the ceiling is a spend guarantee and a knob that can lift it is not one.
89
89
 
90
- import { existsSync, readFileSync, appendFileSync } from "node:fs";
90
+ import { appendFileSync } from "node:fs";
91
91
  import { join } from "node:path";
92
92
 
93
93
  import { kebab } from "./search-policy.mjs"; import { moreThan } from "../shared/register-floor.mjs";
@@ -96,6 +96,7 @@ import { reachableRegions } from "./register-availability.mjs"; // — pure; t
96
96
  import { variantForms, VARIANT_RULES, VARIANT_CAP } from "./register-variants.mjs";
97
97
  import { isCapabilityGap } from "../providers/_shared/execute-plan.mjs";
98
98
  import { plainDeferralReason, plainCause } from "./deferral-row.mjs"; // — the reader's line for a count left open
99
+ import { readJson } from "./run-record.mjs";
99
100
 
100
101
  /** The three questions, in report order. `matchMode` is the provider-neutral predicate name.
101
102
  *
@@ -245,7 +246,7 @@ async function runBatched(items, limit, fn) {
245
246
  function fixtureCounter(dir) {
246
247
  return async (mark, predicate) => {
247
248
  let doc;
248
- try { doc = JSON.parse(readFileSync(join(dir, `${kebab(mark)}.json`), "utf8")); }
249
+ try { doc = readJson(join(dir, `${kebab(mark)}.json`)); }
249
250
  catch (e) { return { ok: false, total: null, reason: `count fixture missing for ${kebab(mark)}: ${e.message}` }; }
250
251
  // THE KEY IS THE QUESTION ASKED, NOT THE COLUMN IT FEEDS. A variant probe asks the provider's
251
252
  // EXACT predicate about a generated form, so its fixture is that form's own file under `identical`