@intentius/chant 0.124.13 → 0.124.14

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 (907) hide show
  1. package/bin/chant +11 -0
  2. package/dist/agents/checks.js +326 -0
  3. package/dist/agents/discover.js +885 -0
  4. package/dist/agents/importer.js +17 -0
  5. package/dist/agents/index.js +12 -0
  6. package/dist/agents/types.js +19 -0
  7. package/dist/apply.js +151 -0
  8. package/dist/attrref.js +70 -0
  9. package/dist/audit/catalog.js +350 -0
  10. package/dist/audit/core.js +252 -0
  11. package/dist/audit/discover.js +633 -0
  12. package/dist/audit/fetch.js +666 -0
  13. package/dist/audit/lineage.js +91 -0
  14. package/dist/audit/nginx.js +366 -0
  15. package/dist/audit/prior-art.js +132 -0
  16. package/dist/audit/proof.js +321 -0
  17. package/dist/audit/report-html.js +194 -0
  18. package/dist/audit/report-model.js +198 -0
  19. package/dist/audit/report.js +102 -0
  20. package/dist/audit/rules-doc.js +144 -0
  21. package/dist/audit/secrets.js +405 -0
  22. package/dist/audit/terraform-state.js +140 -0
  23. package/dist/audit/wrangler.js +262 -0
  24. package/dist/behaviour-delta.js +401 -0
  25. package/dist/behaviour-engine.js +357 -0
  26. package/dist/behaviour-graph.js +83 -0
  27. package/dist/behaviour-http.js +188 -0
  28. package/dist/behaviour-kinds.js +172 -0
  29. package/dist/behaviour-overlay.js +50 -0
  30. package/dist/behaviour-predict.js +188 -0
  31. package/dist/behaviour-request.js +194 -0
  32. package/dist/behaviour.js +1325 -0
  33. package/dist/build-params.js +108 -0
  34. package/dist/build.js +668 -0
  35. package/dist/builder.js +44 -0
  36. package/dist/cdk/advise.js +30 -0
  37. package/dist/cdk/assembly.js +122 -0
  38. package/dist/cdk/graph.js +444 -0
  39. package/dist/cdk/tier-map.js +64 -0
  40. package/dist/cdk/types.js +24 -0
  41. package/dist/change-set.js +312 -0
  42. package/dist/child-project.js +21 -0
  43. package/dist/claimed-fields.js +135 -0
  44. package/dist/cli/build-options.js +70 -0
  45. package/dist/cli/build-params-cli.js +139 -0
  46. package/dist/cli/command-group.js +123 -0
  47. package/dist/cli/commands/audit-agents.js +326 -0
  48. package/dist/cli/commands/audit.js +571 -0
  49. package/dist/cli/commands/build.js +920 -0
  50. package/dist/cli/commands/carve-apply.js +153 -0
  51. package/dist/cli/commands/carve-bridge.js +201 -0
  52. package/dist/cli/commands/carve-emit.js +332 -0
  53. package/dist/cli/commands/carve-status.js +119 -0
  54. package/dist/cli/commands/carve.js +204 -0
  55. package/dist/cli/commands/check-lexicon-docs.js +79 -0
  56. package/dist/cli/commands/check-lexicon-examples.js +177 -0
  57. package/dist/cli/commands/check-lexicon-intrinsics.js +291 -0
  58. package/dist/cli/commands/check-lexicon-mcp.js +82 -0
  59. package/dist/cli/commands/check-lexicon-plugin.d.ts.map +1 -1
  60. package/dist/cli/commands/check-lexicon-plugin.js +104 -0
  61. package/dist/cli/commands/check-lexicon.js +766 -0
  62. package/dist/cli/commands/describe.js +85 -0
  63. package/dist/cli/commands/diff.js +175 -0
  64. package/dist/cli/commands/doctor.js +350 -0
  65. package/dist/cli/commands/import-agents.js +155 -0
  66. package/dist/cli/commands/import.js +670 -0
  67. package/dist/cli/commands/init-lexicon/templates/codegen.js +194 -0
  68. package/dist/cli/commands/init-lexicon/templates/docs.js +100 -0
  69. package/dist/cli/commands/init-lexicon/templates/examples.js +29 -0
  70. package/dist/cli/commands/init-lexicon/templates/lint.js +34 -0
  71. package/dist/cli/commands/init-lexicon/templates/lsp.js +37 -0
  72. package/dist/cli/commands/init-lexicon/templates/plugin.js +108 -0
  73. package/dist/cli/commands/init-lexicon/templates/project.js +240 -0
  74. package/dist/cli/commands/init-lexicon/templates/spec.js +56 -0
  75. package/dist/cli/commands/init-lexicon/templates/tests.js +66 -0
  76. package/dist/cli/commands/init-lexicon.js +172 -0
  77. package/dist/cli/commands/init.js +381 -0
  78. package/dist/cli/commands/lexicon-rolling-upgrade.js +145 -0
  79. package/dist/cli/commands/lexicon-surface-diff.js +145 -0
  80. package/dist/cli/commands/licenses.js +125 -0
  81. package/dist/cli/commands/lint.d.ts.map +1 -1
  82. package/dist/cli/commands/lint.js +948 -0
  83. package/dist/cli/commands/list.js +63 -0
  84. package/dist/cli/commands/migrate.d.ts.map +1 -1
  85. package/dist/cli/commands/migrate.js +423 -0
  86. package/dist/cli/commands/onboard.js +403 -0
  87. package/dist/cli/commands/pinned-upgrade.js +191 -0
  88. package/dist/cli/commands/update.js +194 -0
  89. package/dist/cli/commands/vendor.js +217 -0
  90. package/dist/cli/conflict-check.js +104 -0
  91. package/dist/cli/debug.js +8 -0
  92. package/dist/cli/format.js +104 -0
  93. package/dist/cli/handlers/build.js +267 -0
  94. package/dist/cli/handlers/carve-apply.js +30 -0
  95. package/dist/cli/handlers/carve-bridge.js +28 -0
  96. package/dist/cli/handlers/carve-emit.js +50 -0
  97. package/dist/cli/handlers/carve-status.js +26 -0
  98. package/dist/cli/handlers/carve.js +40 -0
  99. package/dist/cli/handlers/change-set.js +46 -0
  100. package/dist/cli/handlers/components.js +730 -0
  101. package/dist/cli/handlers/dev.js +113 -0
  102. package/dist/cli/handlers/emulator.js +233 -0
  103. package/dist/cli/handlers/explain.js +54 -0
  104. package/dist/cli/handlers/fan-out.js +422 -0
  105. package/dist/cli/handlers/gate-resume.js +275 -0
  106. package/dist/cli/handlers/generate.js +84 -0
  107. package/dist/cli/handlers/graph.js +969 -0
  108. package/dist/cli/handlers/init.js +102 -0
  109. package/dist/cli/handlers/lifecycle.js +1727 -0
  110. package/dist/cli/handlers/lint.js +62 -0
  111. package/dist/cli/handlers/migrate.js +48 -0
  112. package/dist/cli/handlers/misc.js +391 -0
  113. package/dist/cli/handlers/operator.js +1162 -0
  114. package/dist/cli/handlers/override-approve.js +102 -0
  115. package/dist/cli/handlers/pr.js +503 -0
  116. package/dist/cli/handlers/promote.js +342 -0
  117. package/dist/cli/handlers/run-generate.js +206 -0
  118. package/dist/cli/handlers/run-wave.js +66 -0
  119. package/dist/cli/handlers/run.js +1191 -0
  120. package/dist/cli/handlers/scenario.js +325 -0
  121. package/dist/cli/handlers/search.js +924 -0
  122. package/dist/cli/handlers/serve.js +32 -0
  123. package/dist/cli/handlers/vendor.js +154 -0
  124. package/dist/cli/index.js +3 -0
  125. package/dist/cli/is-entry-point.js +23 -0
  126. package/dist/cli/lsp/capabilities.js +28 -0
  127. package/dist/cli/lsp/diagnostics.js +34 -0
  128. package/dist/cli/lsp/server.js +329 -0
  129. package/dist/cli/main.d.ts.map +1 -1
  130. package/dist/cli/main.js +2540 -0
  131. package/dist/cli/mcp/lifecycle-tools.js +80 -0
  132. package/dist/cli/mcp/op-tools.js +306 -0
  133. package/dist/cli/mcp/resource-handlers.js +258 -0
  134. package/dist/cli/mcp/resources/context.js +85 -0
  135. package/dist/cli/mcp/server.js +353 -0
  136. package/dist/cli/mcp/tools/build.js +111 -0
  137. package/dist/cli/mcp/tools/composites.js +95 -0
  138. package/dist/cli/mcp/tools/explain.js +166 -0
  139. package/dist/cli/mcp/tools/import.js +49 -0
  140. package/dist/cli/mcp/tools/lint.js +41 -0
  141. package/dist/cli/mcp/tools/scaffold.js +111 -0
  142. package/dist/cli/mcp/tools/search.js +112 -0
  143. package/dist/cli/mcp/types.js +1 -0
  144. package/dist/cli/mcp/workspace-plugins.js +91 -0
  145. package/dist/cli/mcp/workspace-tools.d.ts +1 -1
  146. package/dist/cli/mcp/workspace-tools.js +564 -0
  147. package/dist/cli/mcp-config.js +70 -0
  148. package/dist/cli/plugins.js +313 -0
  149. package/dist/cli/registry.js +23 -0
  150. package/dist/cli/reporters/stylish.js +329 -0
  151. package/dist/cli/version.js +15 -0
  152. package/dist/cli/watch.js +79 -0
  153. package/dist/codegen/bound-property-types.js +82 -0
  154. package/dist/codegen/coverage.js +119 -0
  155. package/dist/codegen/docs-file-markers.js +60 -0
  156. package/dist/codegen/docs-pages.js +115 -0
  157. package/dist/codegen/docs-rule-scanning.js +164 -0
  158. package/dist/codegen/docs-rules.js +76 -0
  159. package/dist/codegen/docs-sections.js +117 -0
  160. package/dist/codegen/docs-sidebar.js +65 -0
  161. package/dist/codegen/docs-types.js +4 -0
  162. package/dist/codegen/docs.js +356 -0
  163. package/dist/codegen/fetch.js +340 -0
  164. package/dist/codegen/generate-post-synth-barrel.js +63 -0
  165. package/dist/codegen/generate-registry.js +71 -0
  166. package/dist/codegen/generate-runtime-index.js +56 -0
  167. package/dist/codegen/generate-typescript.js +119 -0
  168. package/dist/codegen/generate.js +115 -0
  169. package/dist/codegen/json-patch.js +141 -0
  170. package/dist/codegen/json-schema-to-ts.js +344 -0
  171. package/dist/codegen/json-schema.js +246 -0
  172. package/dist/codegen/lexicon-regen.js +412 -0
  173. package/dist/codegen/naming.js +217 -0
  174. package/dist/codegen/okf-lexicon.js +245 -0
  175. package/dist/codegen/package.js +150 -0
  176. package/dist/codegen/pinned-upgrade.d.ts.map +1 -1
  177. package/dist/codegen/pinned-upgrade.js +494 -0
  178. package/dist/codegen/registry.js +60 -0
  179. package/dist/codegen/rehype-base-url.mjs +68 -0
  180. package/dist/codegen/rolling-upgrade.js +217 -0
  181. package/dist/codegen/surface-snapshot.js +537 -0
  182. package/dist/codegen/testdata/postgres-tags.json +242 -0
  183. package/dist/codegen/topo-sort.js +36 -0
  184. package/dist/codegen/typecheck.js +115 -0
  185. package/dist/codegen/validate.js +200 -0
  186. package/dist/codegen/version-bump.js +35 -0
  187. package/dist/components/auto-release.js +143 -0
  188. package/dist/components/builders.js +47 -0
  189. package/dist/components/capability-plugin-loader.js +175 -0
  190. package/dist/components/capability-plugin-schema.js +46 -0
  191. package/dist/components/capability-plugin.js +99 -0
  192. package/dist/components/capability.js +60 -0
  193. package/dist/components/changed-files.js +72 -0
  194. package/dist/components/cli-support.js +427 -0
  195. package/dist/components/component.js +120 -0
  196. package/dist/components/component.schema.json +271 -0
  197. package/dist/components/config-defaults.js +130 -0
  198. package/dist/components/deploy-units.js +60 -0
  199. package/dist/components/discover.d.ts.map +1 -1
  200. package/dist/components/discover.js +189 -0
  201. package/dist/components/driver-output.js +86 -0
  202. package/dist/components/driver.js +728 -0
  203. package/dist/components/fan-out-output.js +165 -0
  204. package/dist/components/fan-out-record.js +94 -0
  205. package/dist/components/fan-out-run.js +373 -0
  206. package/dist/components/fan-out-support.js +60 -0
  207. package/dist/components/fan-out.js +273 -0
  208. package/dist/components/gate-plan.js +41 -0
  209. package/dist/components/gated-wave-pipeline.js +46 -0
  210. package/dist/components/index.js +24 -0
  211. package/dist/components/layers.js +28 -0
  212. package/dist/components/manifest-persistence.js +108 -0
  213. package/dist/components/pilots/alb-ecs.pilot.js +59 -0
  214. package/dist/components/pilots/dynamodb.pilot.js +51 -0
  215. package/dist/components/pilots/jar-emr.pilot.js +65 -0
  216. package/dist/components/pilots/lambda.pilot.js +52 -0
  217. package/dist/components/pilots/neo4j-fanout.pilot.js +68 -0
  218. package/dist/components/pilots/project.js +12 -0
  219. package/dist/components/pr-pipeline.js +134 -0
  220. package/dist/components/pr-run.js +363 -0
  221. package/dist/components/presets/ecs-fargate.js +72 -0
  222. package/dist/components/presets/index.js +28 -0
  223. package/dist/components/presets/lambda.js +34 -0
  224. package/dist/components/presets/single-host-compose.js +41 -0
  225. package/dist/components/promote.js +549 -0
  226. package/dist/components/registry.js +34 -0
  227. package/dist/components/run-progress.js +33 -0
  228. package/dist/components/sandbox/driver.d.ts.map +1 -1
  229. package/dist/components/sandbox/driver.js +93 -0
  230. package/dist/components/sandbox/run.js +115 -0
  231. package/dist/components/starter-plugin.js +104 -0
  232. package/dist/components/verbs/__tests__/mock-cloud-executor.js +68 -0
  233. package/dist/components/verbs/__tests__/mock-process-runner.js +45 -0
  234. package/dist/components/verbs/__tests__/mock-sbom-generator.js +56 -0
  235. package/dist/components/verbs/bom-writer.js +287 -0
  236. package/dist/components/verbs/build-archive.js +188 -0
  237. package/dist/components/verbs/build.js +142 -0
  238. package/dist/components/verbs/cloud-executor.js +110 -0
  239. package/dist/components/verbs/component-bom.js +125 -0
  240. package/dist/components/verbs/ensure-secret.js +50 -0
  241. package/dist/components/verbs/index.js +61 -0
  242. package/dist/components/verbs/license-policy.js +75 -0
  243. package/dist/components/verbs/lockfile-sbom-generator.js +191 -0
  244. package/dist/components/verbs/process-runner.js +78 -0
  245. package/dist/components/verbs/r2-sync.js +93 -0
  246. package/dist/components/verbs/reproducibility.js +62 -0
  247. package/dist/components/verbs/run-agent.js +577 -0
  248. package/dist/components/verbs/sbom-generator.js +119 -0
  249. package/dist/components/verbs/sbom.js +97 -0
  250. package/dist/components/verbs/shell.js +32 -0
  251. package/dist/components/verbs/sign.js +221 -0
  252. package/dist/components/verbs/stub.js +28 -0
  253. package/dist/components/verbs/tool-sbom-generator.js +154 -0
  254. package/dist/components/verbs/verify.js +112 -0
  255. package/dist/components/verbs/vex.js +131 -0
  256. package/dist/components/verbs/vuln-gate.js +152 -0
  257. package/dist/components/verbs/vuln-scan.js +288 -0
  258. package/dist/components/verbs/wait-verify.js +106 -0
  259. package/dist/components/verbs/wrangler.js +179 -0
  260. package/dist/components/wave-plan.js +102 -0
  261. package/dist/composite.js +305 -0
  262. package/dist/config-import.d.ts.map +1 -1
  263. package/dist/config-import.js +22 -0
  264. package/dist/config-sandbox.js +122 -0
  265. package/dist/config-static.js +206 -0
  266. package/dist/config.js +605 -0
  267. package/dist/content-digest.js +23 -0
  268. package/dist/declarable.js +114 -0
  269. package/dist/deep-observation.js +437 -0
  270. package/dist/detectLexicon.js +54 -0
  271. package/dist/discovery/cache.js +70 -0
  272. package/dist/discovery/collect.js +208 -0
  273. package/dist/discovery/cycles.js +95 -0
  274. package/dist/discovery/entity-wire-codec.js +391 -0
  275. package/dist/discovery/entity-wire.js +42 -0
  276. package/dist/discovery/files.js +121 -0
  277. package/dist/discovery/fold-import.d.ts.map +1 -1
  278. package/dist/discovery/fold-import.js +4178 -0
  279. package/dist/discovery/fold-rank.js +292 -0
  280. package/dist/discovery/graph.js +115 -0
  281. package/dist/discovery/import.d.ts.map +1 -1
  282. package/dist/discovery/import.js +65 -0
  283. package/dist/discovery/index.js +333 -0
  284. package/dist/discovery/param-deps.js +487 -0
  285. package/dist/discovery/resolve.js +39 -0
  286. package/dist/discovery/sandbox/bundle.js +214 -0
  287. package/dist/discovery/sandbox/child-errors.js +26 -0
  288. package/dist/discovery/sandbox/config-run.js +100 -0
  289. package/dist/discovery/sandbox/config-wire.js +183 -0
  290. package/dist/discovery/sandbox/driver.d.ts.map +1 -1
  291. package/dist/discovery/sandbox/driver.js +333 -0
  292. package/dist/discovery/sandbox/fork.js +229 -0
  293. package/dist/discovery/sandbox/policy-run.js +142 -0
  294. package/dist/discovery/sandbox/policy-wire.js +152 -0
  295. package/dist/discovery/sandbox/run.js +77 -0
  296. package/dist/discovery/specifier-resolve.js +320 -0
  297. package/dist/discovery/walk.js +284 -0
  298. package/dist/effect-receipt.js +340 -0
  299. package/dist/env.js +55 -0
  300. package/dist/errors.js +62 -0
  301. package/dist/fold/fold.js +1434 -0
  302. package/dist/fold/foldable-helpers.js +229 -0
  303. package/dist/fold/subset.js +696 -0
  304. package/dist/fold-provenance.js +414 -0
  305. package/dist/gate-decision.js +260 -0
  306. package/dist/gate-resume-run.js +154 -0
  307. package/dist/gated-waves.js +165 -0
  308. package/dist/governance.js +43 -0
  309. package/dist/graph-declared.js +45 -0
  310. package/dist/graph-detail.js +207 -0
  311. package/dist/graph-dot.js +54 -0
  312. package/dist/graph-effective.js +107 -0
  313. package/dist/graph-ir.js +623 -0
  314. package/dist/graph-layout.js +184 -0
  315. package/dist/graph-lens.js +105 -0
  316. package/dist/graph-mermaid.js +83 -0
  317. package/dist/graph-ops.js +39 -0
  318. package/dist/graph-refs.js +156 -0
  319. package/dist/held-elsewhere.js +87 -0
  320. package/dist/identity.js +251 -0
  321. package/dist/import/base-parser.js +34 -0
  322. package/dist/import/embedded.js +255 -0
  323. package/dist/import/generator.js +1 -0
  324. package/dist/import/ir-utils.js +85 -0
  325. package/dist/import/parser-options.js +45 -0
  326. package/dist/import/parser.js +1 -0
  327. package/dist/index.js +118 -0
  328. package/dist/intrinsic-interpolation.js +73 -0
  329. package/dist/intrinsic.js +31 -0
  330. package/dist/join-key.js +35 -0
  331. package/dist/kubectl-context.js +150 -0
  332. package/dist/lexicon-config.js +58 -0
  333. package/dist/lexicon-integrity.js +47 -0
  334. package/dist/lexicon-manifest.js +70 -0
  335. package/dist/lexicon-module.d.ts.map +1 -1
  336. package/dist/lexicon-module.js +241 -0
  337. package/dist/lexicon-output.js +218 -0
  338. package/dist/lexicon-plugin-helpers.js +104 -0
  339. package/dist/lexicon-schema.js +136 -0
  340. package/dist/lexicon.js +130 -0
  341. package/dist/lifecycle/affected.js +224 -0
  342. package/dist/lifecycle/assert-live.js +110 -0
  343. package/dist/lifecycle/build-ledger-store.js +160 -0
  344. package/dist/lifecycle/build-ledger.js +155 -0
  345. package/dist/lifecycle/change-set.js +356 -0
  346. package/dist/lifecycle/converge-ledger.js +161 -0
  347. package/dist/lifecycle/deep-diff.js +233 -0
  348. package/dist/lifecycle/deep-observe.js +147 -0
  349. package/dist/lifecycle/digest.js +143 -0
  350. package/dist/lifecycle/disruption.js +135 -0
  351. package/dist/lifecycle/gate-applied.js +113 -0
  352. package/dist/lifecycle/gate-audit.js +341 -0
  353. package/dist/lifecycle/gate-ledger-select.js +89 -0
  354. package/dist/lifecycle/gate-ledger.js +193 -0
  355. package/dist/lifecycle/gate-origin.js +117 -0
  356. package/dist/lifecycle/gate-pending.js +58 -0
  357. package/dist/lifecycle/git.js +1182 -0
  358. package/dist/lifecycle/identity.js +58 -0
  359. package/dist/lifecycle/index.js +26 -0
  360. package/dist/lifecycle/lease.js +283 -0
  361. package/dist/lifecycle/ledger-port.js +1 -0
  362. package/dist/lifecycle/legacy-digest.js +91 -0
  363. package/dist/lifecycle/live-diff.js +274 -0
  364. package/dist/lifecycle/local-note.js +15 -0
  365. package/dist/lifecycle/member-ledger.js +122 -0
  366. package/dist/lifecycle/observation-baseline.js +155 -0
  367. package/dist/lifecycle/observe.js +375 -0
  368. package/dist/lifecycle/oras-referrer-lookup.js +82 -0
  369. package/dist/lifecycle/override-ledger.js +54 -0
  370. package/dist/lifecycle/plan-digest.js +110 -0
  371. package/dist/lifecycle/plan-ledger.js +129 -0
  372. package/dist/lifecycle/receipt-plan.js +192 -0
  373. package/dist/lifecycle/release-ledger.js +155 -0
  374. package/dist/lifecycle/release-read.js +64 -0
  375. package/dist/lifecycle/replay.js +193 -0
  376. package/dist/lifecycle/rollback.js +102 -0
  377. package/dist/lifecycle/run-ledger.js +183 -0
  378. package/dist/lifecycle/scenario-eval.js +204 -0
  379. package/dist/lifecycle/scenario.js +214 -0
  380. package/dist/lifecycle/snapshot.js +239 -0
  381. package/dist/lifecycle/status.js +447 -0
  382. package/dist/lifecycle/symptoms.js +117 -0
  383. package/dist/lifecycle/teardown.js +255 -0
  384. package/dist/lifecycle/types.js +1 -0
  385. package/dist/lifecycle/unobserved-gate.js +33 -0
  386. package/dist/lifecycle/wave-plans.js +68 -0
  387. package/dist/lifecycle/work-item-id.js +36 -0
  388. package/dist/lifecycle/work-lease.js +393 -0
  389. package/dist/lint/component-checks.js +87 -0
  390. package/dist/lint/config.js +483 -0
  391. package/dist/lint/declarative.js +122 -0
  392. package/dist/lint/discover.d.ts.map +1 -1
  393. package/dist/lint/discover.js +138 -0
  394. package/dist/lint/engine.js +246 -0
  395. package/dist/lint/knowledge-checks.js +64 -0
  396. package/dist/lint/named-checks.js +22 -0
  397. package/dist/lint/output-checks.js +87 -0
  398. package/dist/lint/output-docs.js +163 -0
  399. package/dist/lint/parser.js +33 -0
  400. package/dist/lint/pipeline-change-gate.js +70 -0
  401. package/dist/lint/policy-import.d.ts +1 -1
  402. package/dist/lint/policy-import.d.ts.map +1 -1
  403. package/dist/lint/policy-import.js +62 -0
  404. package/dist/lint/policy-sandbox.js +86 -0
  405. package/dist/lint/policy.js +122 -0
  406. package/dist/lint/post-synth.js +87 -0
  407. package/dist/lint/presets/relaxed.json +26 -0
  408. package/dist/lint/presets/strict.json +24 -24
  409. package/dist/lint/receipt-checks.js +83 -0
  410. package/dist/lint/rule-loader.d.ts.map +1 -1
  411. package/dist/lint/rule-loader.js +89 -0
  412. package/dist/lint/rule-registry.js +86 -0
  413. package/dist/lint/rule.js +1 -0
  414. package/dist/lint/rules/__fixtures__/comp/comp000-discovery-error/broken-a.component.js +7 -0
  415. package/dist/lint/rules/__fixtures__/comp/comp000-discovery-error/broken-b.component.js +7 -0
  416. package/dist/lint/rules/__fixtures__/comp/comp001/fail/orphan-lib.component.js +9 -0
  417. package/dist/lint/rules/__fixtures__/comp/comp001/pass/emr-job.component.js +11 -0
  418. package/dist/lint/rules/__fixtures__/comp/comp001/pass/jar-lib.component.js +9 -0
  419. package/dist/lint/rules/__fixtures__/comp/comp002/fail/search-service.component.js +25 -0
  420. package/dist/lint/rules/__fixtures__/comp/comp002/pass/jar-lib.component.js +8 -0
  421. package/dist/lint/rules/__fixtures__/comp/comp002/pass/search-service.component.js +21 -0
  422. package/dist/lint/rules/__fixtures__/comp/comp003/fail/migrator.component.js +8 -0
  423. package/dist/lint/rules/__fixtures__/comp/comp003/pass/agent-turn.component.js +24 -0
  424. package/dist/lint/rules/__fixtures__/comp/comp003/pass/migrator.component.js +17 -0
  425. package/dist/lint/rules/__fixtures__/comp/comp003/pass/orders-table.component.js +8 -0
  426. package/dist/lint/rules/__fixtures__/comp/comp004/fail/neo4j-cluster.component.js +18 -0
  427. package/dist/lint/rules/__fixtures__/comp/comp004/pass/neo4j-cluster.component.js +20 -0
  428. package/dist/lint/rules/__fixtures__/comp/comp004/pass/orders-table.component.js +8 -0
  429. package/dist/lint/rules/__fixtures__/comp/comp005/fail/search-service.component.js +12 -0
  430. package/dist/lint/rules/__fixtures__/comp/comp005/pass/search-service.component.js +16 -0
  431. package/dist/lint/rules/__fixtures__/comp/comp006/fail/legacy-tool.component.js +8 -0
  432. package/dist/lint/rules/__fixtures__/comp/comp006/pass/legacy-tool.component.js +12 -0
  433. package/dist/lint/rules/__fixtures__/comp/comp007/fail/inventory-table.component.js +11 -0
  434. package/dist/lint/rules/__fixtures__/comp/comp007/fail/orders-table.component.js +11 -0
  435. package/dist/lint/rules/__fixtures__/comp/comp007/pass/orders-table.component.js +10 -0
  436. package/dist/lint/rules/__fixtures__/comp/comp007/pass/search-service.component.js +16 -0
  437. package/dist/lint/rules/comp/comp001-publishes-never-applies.js +69 -0
  438. package/dist/lint/rules/comp/comp002-dangling-wiring-ref.js +84 -0
  439. package/dist/lint/rules/comp/comp003-mutating-no-rollback.js +103 -0
  440. package/dist/lint/rules/comp/comp004-gate-needs-durable-runtime.js +70 -0
  441. package/dist/lint/rules/comp/comp005-capability-kind-is-noun.js +109 -0
  442. package/dist/lint/rules/comp/comp006-shell-needs-reason.js +49 -0
  443. package/dist/lint/rules/comp/comp007-composition-sprawl.js +64 -0
  444. package/dist/lint/rules/comp/index.js +33 -0
  445. package/dist/lint/rules/comp/support.js +129 -0
  446. package/dist/lint/rules/composite-scope.js +51 -0
  447. package/dist/lint/rules/cor017-composite-name-match.js +93 -0
  448. package/dist/lint/rules/cor018-composite-prefer-lexicon-type.js +136 -0
  449. package/dist/lint/rules/cor021-env-literal-name.js +100 -0
  450. package/dist/lint/rules/cor022-receipt-leaf.js +118 -0
  451. package/dist/lint/rules/cor024-receipt-secret-pointer.js +199 -0
  452. package/dist/lint/rules/declarable-naming-convention.js +62 -0
  453. package/dist/lint/rules/evl001-non-literal-expression.js +66 -0
  454. package/dist/lint/rules/evl002-control-flow-resource.js +69 -0
  455. package/dist/lint/rules/evl003-dynamic-property-access.js +44 -0
  456. package/dist/lint/rules/evl004-spread-non-const.js +94 -0
  457. package/dist/lint/rules/evl005-resource-block-body.js +41 -0
  458. package/dist/lint/rules/evl007-invalid-siblings.js +105 -0
  459. package/dist/lint/rules/evl009-composite-no-constant.js +158 -0
  460. package/dist/lint/rules/evl010-composite-no-transform.js +59 -0
  461. package/dist/lint/rules/evl011-symbolic-in-template.js +106 -0
  462. package/dist/lint/rules/export-required.js +115 -0
  463. package/dist/lint/rules/file-declarable-limit.js +88 -0
  464. package/dist/lint/rules/flat-declarations.js +62 -0
  465. package/dist/lint/rules/index.js +90 -0
  466. package/dist/lint/rules/no-cyclic-declarable-ref.js +138 -0
  467. package/dist/lint/rules/no-redundant-type-import.js +76 -0
  468. package/dist/lint/rules/no-redundant-value-cast.js +41 -0
  469. package/dist/lint/rules/no-string-ref.js +59 -0
  470. package/dist/lint/rules/no-unused-declarable-import.js +75 -0
  471. package/dist/lint/rules/no-unused-declarable.js +142 -0
  472. package/dist/lint/rules/op/index.js +28 -0
  473. package/dist/lint/rules/op/ops012-activity-contract.js +54 -0
  474. package/dist/lint/rules/op/ops013-step-output-ref.js +88 -0
  475. package/dist/lint/rules/op/ops014-converge-rule-refusals.js +114 -0
  476. package/dist/lint/rules/op/ops015-gate-approval.js +45 -0
  477. package/dist/lint/rules/op/support.js +11 -0
  478. package/dist/lint/rules/op/sys010-key-over-plain-http.js +100 -0
  479. package/dist/lint/rules/property-kind.js +56 -0
  480. package/dist/lint/rules/single-concern-file.js +71 -0
  481. package/dist/lint/rules/sys001-no-literal-key.js +60 -0
  482. package/dist/lint/selectors.js +168 -0
  483. package/dist/lint/suppressions.js +129 -0
  484. package/dist/lint/typescript.js +17 -0
  485. package/dist/live-endpoint.js +113 -0
  486. package/dist/live-read-session.js +76 -0
  487. package/dist/lsp/lexicon-providers.js +163 -0
  488. package/dist/lsp/types.js +5 -0
  489. package/dist/managed-fields.js +293 -0
  490. package/dist/mcp/types.js +4 -0
  491. package/dist/notify-verify.js +0 -1
  492. package/dist/notify.js +0 -1
  493. package/dist/notify.schema.json +72 -0
  494. package/dist/observation.js +266 -0
  495. package/dist/okf-read.js +134 -0
  496. package/dist/okf.js +275 -0
  497. package/dist/op/__fixtures__/decide-stub-backend.js +125 -0
  498. package/dist/op/activities/activity-contracts.js +313 -0
  499. package/dist/op/activities/apply.js +582 -0
  500. package/dist/op/activities/build.js +18 -0
  501. package/dist/op/activities/change-coverage.js +40 -0
  502. package/dist/op/activities/change-set.js +64 -0
  503. package/dist/op/activities/converge.js +492 -0
  504. package/dist/op/activities/decide.js +211 -0
  505. package/dist/op/activities/env-teardown.js +110 -0
  506. package/dist/op/activities/factory.js +591 -0
  507. package/dist/op/activities/forge-pull-request.js +82 -0
  508. package/dist/op/activities/gh-host.js +78 -0
  509. package/dist/op/activities/guard-validate.js +165 -0
  510. package/dist/op/activities/http-check.js +40 -0
  511. package/dist/op/activities/index.js +59 -0
  512. package/dist/op/activities/lexicon-upgrade.js +629 -0
  513. package/dist/op/activities/lifecycle.js +109 -0
  514. package/dist/op/activities/pipeline-audit.js +147 -0
  515. package/dist/op/activities/policy.js +26 -0
  516. package/dist/op/activities/predict-behaviour.js +341 -0
  517. package/dist/op/activities/propose-upgrade.js +165 -0
  518. package/dist/op/activities/reconcile.js +997 -0
  519. package/dist/op/activities/shell.js +118 -0
  520. package/dist/op/activities/source-release.js +97 -0
  521. package/dist/op/activities/source-rollback.js +165 -0
  522. package/dist/op/activities/teardown.js +17 -0
  523. package/dist/op/activities/util.js +6 -0
  524. package/dist/op/activities/wait.js +51 -0
  525. package/dist/op/activities/work-evidence.js +35 -0
  526. package/dist/op/activities/workflow-audit.js +133 -0
  527. package/dist/op/activity-contract-registry.js +106 -0
  528. package/dist/op/activity-contract.js +232 -0
  529. package/dist/op/activity-failure.js +31 -0
  530. package/dist/op/activity-profiles.js +129 -0
  531. package/dist/op/activity-registry.js +105 -0
  532. package/dist/op/activity-runtime.js +28 -0
  533. package/dist/op/builders.js +801 -0
  534. package/dist/op/change-signal.js +118 -0
  535. package/dist/op/composites/apply-op.js +151 -0
  536. package/dist/op/composites/behaviour-op.js +65 -0
  537. package/dist/op/composites/converge-op.js +141 -0
  538. package/dist/op/composites/index.js +19 -0
  539. package/dist/op/composites/lexicon-upgrade-op.js +107 -0
  540. package/dist/op/composites/pipeline-audit-op.js +50 -0
  541. package/dist/op/composites/reconcile-op.js +84 -0
  542. package/dist/op/composites/watch-op.js +69 -0
  543. package/dist/op/composites/workflow-audit-op.js +57 -0
  544. package/dist/op/converge-rule.js +205 -0
  545. package/dist/op/cron.js +146 -0
  546. package/dist/op/decide-backend.js +181 -0
  547. package/dist/op/decide-config.js +68 -0
  548. package/dist/op/decide-read-inputs.js +141 -0
  549. package/dist/op/discover.d.ts.map +1 -1
  550. package/dist/op/discover.js +213 -0
  551. package/dist/op/duration.js +21 -0
  552. package/dist/op/emulator-freshness.js +80 -0
  553. package/dist/op/emulator-lifecycle.js +269 -0
  554. package/dist/op/factory.js +83 -0
  555. package/dist/op/gate-approval.js +172 -0
  556. package/dist/op/gate-name.js +86 -0
  557. package/dist/op/gate-plan-context.js +167 -0
  558. package/dist/op/gate-point-run.js +67 -0
  559. package/dist/op/gate-point.js +111 -0
  560. package/dist/op/gate-resume-plan.js +155 -0
  561. package/dist/op/gate-resume.js +31 -0
  562. package/dist/op/gate-review.js +290 -0
  563. package/dist/op/gate-run-locator.js +85 -0
  564. package/dist/op/gate-summary.js +100 -0
  565. package/dist/op/gate-wait.js +56 -0
  566. package/dist/op/gate.js +449 -0
  567. package/dist/op/generate-pipeline.js +124 -0
  568. package/dist/op/index.js +51 -0
  569. package/dist/op/lifecycle-receipt-store.js +45 -0
  570. package/dist/op/local-executor.js +1164 -0
  571. package/dist/op/local-output.js +140 -0
  572. package/dist/op/op-ir.js +317 -0
  573. package/dist/op/op-verb-class.js +131 -0
  574. package/dist/op/op-waves-notify.js +136 -0
  575. package/dist/op/op-waves-run.js +1657 -0
  576. package/dist/op/op-waves.js +409 -0
  577. package/dist/op/operator.js +743 -0
  578. package/dist/op/receipt-store.js +94 -0
  579. package/dist/op/resource.js +23 -0
  580. package/dist/op/run-context.js +28 -0
  581. package/dist/op/run-live.js +256 -0
  582. package/dist/op/runtime.js +21 -0
  583. package/dist/op/runtimes/local.js +195 -0
  584. package/dist/op/source-archive.js +131 -0
  585. package/dist/op/step-output-ref.js +397 -0
  586. package/dist/op/steward-beside.js +169 -0
  587. package/dist/op/steward-points.js +138 -0
  588. package/dist/op/steward-turn.js +59 -0
  589. package/dist/op/steward.js +317 -0
  590. package/dist/op/types.js +25 -0
  591. package/dist/op/work-lease-decl.js +81 -0
  592. package/dist/op/work-lease-run.js +393 -0
  593. package/dist/override-gate.js +284 -0
  594. package/dist/owner-chain.js +74 -0
  595. package/dist/ownership.js +92 -0
  596. package/dist/params.js +61 -0
  597. package/dist/plan-summary.js +711 -0
  598. package/dist/point-decision.js +211 -0
  599. package/dist/pr-forge.js +810 -0
  600. package/dist/pr-loop.js +203 -0
  601. package/dist/project-codegen.js +191 -0
  602. package/dist/project-root.js +74 -0
  603. package/dist/project-validation.js +50 -0
  604. package/dist/provenance.js +157 -0
  605. package/dist/pseudo-parameter.js +40 -0
  606. package/dist/reconcile.js +450 -0
  607. package/dist/resource-attributes.js +33 -0
  608. package/dist/runtime-adapter.js +77 -0
  609. package/dist/runtime.js +66 -0
  610. package/dist/secret-materialization.js +153 -0
  611. package/dist/secret-provenance.js +250 -0
  612. package/dist/serializer-walker.js +112 -0
  613. package/dist/serializer.js +1 -0
  614. package/dist/sort.js +45 -0
  615. package/dist/stack-output.js +115 -0
  616. package/dist/telemetry-attribution.js +149 -0
  617. package/dist/terraform/__fixtures__/build-graph.js +63 -0
  618. package/dist/terraform/adopt-state.js +40 -0
  619. package/dist/terraform/aws-resources.js +384 -0
  620. package/dist/terraform/bridge.js +204 -0
  621. package/dist/terraform/carve-provider.js +155 -0
  622. package/dist/terraform/carve.js +138 -0
  623. package/dist/terraform/data-source-shape.js +57 -0
  624. package/dist/terraform/emit-source.js +36 -0
  625. package/dist/terraform/excise.js +123 -0
  626. package/dist/terraform/graduate.js +128 -0
  627. package/dist/terraform/graph.js +435 -0
  628. package/dist/terraform/hcl2json.js +60 -0
  629. package/dist/terraform/manifest.js +149 -0
  630. package/dist/terraform/parse.js +81 -0
  631. package/dist/terraform/providers/aws.js +146 -0
  632. package/dist/terraform/providers/gcp.js +294 -0
  633. package/dist/terraform/providers/index.js +17 -0
  634. package/dist/terraform/providers/kubernetes.js +253 -0
  635. package/dist/terraform/score.js +151 -0
  636. package/dist/terraform/state.js +67 -0
  637. package/dist/terraform/tier-map.js +74 -0
  638. package/dist/terraform/types.js +13 -0
  639. package/dist/terraform/unified-diff.js +132 -0
  640. package/dist/testing.js +295 -0
  641. package/dist/toml-emit.js +153 -0
  642. package/dist/toml-parse.js +355 -0
  643. package/dist/toml-utils.js +60 -0
  644. package/dist/toml.js +428 -0
  645. package/dist/ts-loader.d.ts +46 -0
  646. package/dist/ts-loader.d.ts.map +1 -0
  647. package/dist/ts-loader.js +103 -0
  648. package/dist/types.js +1 -0
  649. package/dist/utils.js +61 -0
  650. package/dist/validation.js +20 -0
  651. package/dist/vendor/js-yaml-load.js +1662 -0
  652. package/dist/workspace/__fixtures__/contract-repo.js +103 -0
  653. package/dist/workspace/__fixtures__/decide-workspace.js +112 -0
  654. package/dist/workspace/__fixtures__/sessions.js +91 -0
  655. package/dist/workspace/__fixtures__/two-member-workspace.js +34 -0
  656. package/dist/workspace/agent-cli.js +99 -0
  657. package/dist/workspace/agent.schema.json +390 -0
  658. package/dist/workspace/answers-ledger.js +89 -0
  659. package/dist/workspace/box-cli.js +142 -0
  660. package/dist/workspace/box-factory-write.js +196 -0
  661. package/dist/workspace/box-factory-write.schema.json +342 -0
  662. package/dist/workspace/box-factory.js +88 -0
  663. package/dist/workspace/box-intent.js +126 -0
  664. package/dist/workspace/box-isolation.js +169 -0
  665. package/dist/workspace/box-listing-write.schema.json +204 -0
  666. package/dist/workspace/box-listing.js +298 -0
  667. package/dist/workspace/box-publish.js +352 -0
  668. package/dist/workspace/box-publish.schema.json +498 -0
  669. package/dist/workspace/box-services.js +39 -0
  670. package/dist/workspace/broker-protocol.js +359 -0
  671. package/dist/workspace/broker-protocol.schema.json +228 -0
  672. package/dist/workspace/change-set.schema.json +460 -0
  673. package/dist/workspace/changes-cli.js +56 -0
  674. package/dist/workspace/changes.js +446 -0
  675. package/dist/workspace/changes.schema.json +642 -0
  676. package/dist/workspace/chant-migrations/chud-lexicon-exit-fly-site.js +198 -0
  677. package/dist/workspace/chant-migrations/chud-lexicon-exit-live-names.js +155 -0
  678. package/dist/workspace/chant-migrations/chud-lexicon-exit-rollback.js +214 -0
  679. package/dist/workspace/chant-migrations/chud-lexicon-exit-ship-inputs.js +180 -0
  680. package/dist/workspace/chant-migrations/chud-lexicon-exit-ship-policy.js +99 -0
  681. package/dist/workspace/chant-migrations/chud-lexicon-exit.js +847 -0
  682. package/dist/workspace/chant-migrations.js +113 -0
  683. package/dist/workspace/check.schema.json +433 -0
  684. package/dist/workspace/checks/box-isolation.js +62 -0
  685. package/dist/workspace/checks/boxes.js +491 -0
  686. package/dist/workspace/checks/diagrams.js +104 -0
  687. package/dist/workspace/checks/generated.js +419 -0
  688. package/dist/workspace/checks/ledgers.js +212 -0
  689. package/dist/workspace/checks/links.js +191 -0
  690. package/dist/workspace/checks/live.js +100 -0
  691. package/dist/workspace/checks/pipelines.js +188 -0
  692. package/dist/workspace/checks/records.js +169 -0
  693. package/dist/workspace/checks.js +426 -0
  694. package/dist/workspace/ci-green-cli.js +125 -0
  695. package/dist/workspace/ci-green-forge.js +83 -0
  696. package/dist/workspace/ci-green-workflow.js +199 -0
  697. package/dist/workspace/ci-green.js +325 -0
  698. package/dist/workspace/ci-last-green.schema.json +158 -0
  699. package/dist/workspace/compose-graph.js +235 -0
  700. package/dist/workspace/compose-reports.js +146 -0
  701. package/dist/workspace/composites.js +264 -0
  702. package/dist/workspace/composites.schema.json +617 -0
  703. package/dist/workspace/conformance/__fixture__/app/package.json +7 -0
  704. package/dist/workspace/conformance/__fixture__/app/src/server.mjs +29 -0
  705. package/dist/workspace/conformance/__fixture__/decisions/decision.kind.mjs +54 -0
  706. package/dist/workspace/conformance/__fixture__/decisions/decision.schema.json +512 -0
  707. package/dist/workspace/conformance/__fixture__/decisions/fix-001-how-the-app-is-deployed.md +40 -0
  708. package/dist/workspace/conformance/__fixture__/delivery/chant.config.ts +7 -0
  709. package/dist/workspace/conformance/__fixture__/delivery/lexicon/index.ts +26 -0
  710. package/dist/workspace/conformance/__fixture__/delivery/package.json +7 -0
  711. package/dist/workspace/conformance/__fixture__/delivery/src/app.component.ts +14 -0
  712. package/dist/workspace/conformance/__fixture__/delivery/src/app.ts +4 -0
  713. package/dist/workspace/conformance/__fixtures__/reference-broker.js +205 -0
  714. package/dist/workspace/conformance/__writer_fixture__/answers/answer.kind.mjs +32 -0
  715. package/dist/workspace/conformance/__writer_fixture__/answers/answer.schema.json +135 -0
  716. package/dist/workspace/conformance/__writer_fixture__/contracts/contract.kind.mjs +37 -0
  717. package/dist/workspace/conformance/__writer_fixture__/contracts/contract.schema.json +213 -0
  718. package/dist/workspace/conformance/__writer_fixture__/decisions/points.json +228 -0
  719. package/dist/workspace/conformance/__writer_fixture__/drivers/driver.kind.mjs +15 -0
  720. package/dist/workspace/conformance/__writer_fixture__/drivers/driver.schema.json +38 -0
  721. package/dist/workspace/conformance/__writer_fixture__/sessions/session.kind.mjs +54 -0
  722. package/dist/workspace/conformance/__writer_fixture__/sessions/session.schema.json +289 -0
  723. package/dist/workspace/conformance/__writer_fixture__/work/W-001-the-writer-suite-works-this-item.md +25 -0
  724. package/dist/workspace/conformance/__writer_fixture__/work/work.kind.mjs +60 -0
  725. package/dist/workspace/conformance/__writer_fixture__/work/work.schema.json +603 -0
  726. package/dist/workspace/conformance/broker.js +736 -0
  727. package/dist/workspace/conformance/index.js +673 -0
  728. package/dist/workspace/conformance/vitest.js +108 -0
  729. package/dist/workspace/conformance/writer.js +1080 -0
  730. package/dist/workspace/decide.js +879 -0
  731. package/dist/workspace/decision-points.schema.json +135 -135
  732. package/dist/workspace/declaration-write-cli.js +74 -0
  733. package/dist/workspace/declaration-write.js +238 -0
  734. package/dist/workspace/declaration.js +938 -0
  735. package/dist/workspace/declaration.schema.json +1413 -1413
  736. package/dist/workspace/declared-kinds.js +106 -0
  737. package/dist/workspace/environments.js +164 -0
  738. package/dist/workspace/evidence.schema.json +279 -0
  739. package/dist/workspace/export-cli.js +185 -0
  740. package/dist/workspace/export.js +499 -0
  741. package/dist/workspace/factory-rules.js +175 -0
  742. package/dist/workspace/generated-files.js +92 -0
  743. package/dist/workspace/glob.js +45 -0
  744. package/dist/workspace/graph-cache.js +352 -0
  745. package/dist/workspace/graph-cli.js +348 -0
  746. package/dist/workspace/graph.schema.json +1338 -0
  747. package/dist/workspace/identity-gate-rule.js +75 -0
  748. package/dist/workspace/identity.js +126 -0
  749. package/dist/workspace/import.js +283 -0
  750. package/dist/workspace/init.js +620 -0
  751. package/dist/workspace/intent-cli.js +263 -0
  752. package/dist/workspace/intent-joins.js +201 -0
  753. package/dist/workspace/intent-record.js +352 -0
  754. package/dist/workspace/intent-record.schema.json +864 -0
  755. package/dist/workspace/intent.js +1582 -0
  756. package/dist/workspace/intent.schema.json +2420 -0
  757. package/dist/workspace/json-edit.js +221 -0
  758. package/dist/workspace/jsonc.js +235 -0
  759. package/dist/workspace/kind-readers.js +103 -0
  760. package/dist/workspace/kinds.js +587 -0
  761. package/dist/workspace/lexicon-symbols.js +112 -0
  762. package/dist/workspace/lineage-adopt-cli.js +102 -0
  763. package/dist/workspace/lineage-adopt.js +360 -0
  764. package/dist/workspace/lineage-check.js +282 -0
  765. package/dist/workspace/lineage-cli.js +121 -0
  766. package/dist/workspace/lineage-hash-index.js +284 -0
  767. package/dist/workspace/lineage-init.js +507 -0
  768. package/dist/workspace/lineage-lock.js +387 -0
  769. package/dist/workspace/lineage-merge.js +45 -0
  770. package/dist/workspace/lineage-migrations.d.ts.map +1 -1
  771. package/dist/workspace/lineage-migrations.js +329 -0
  772. package/dist/workspace/lineage-provenance.js +36 -0
  773. package/dist/workspace/lineage-update.js +138 -0
  774. package/dist/workspace/lineage-upgrade-cli.js +131 -0
  775. package/dist/workspace/lineage-upgrade.js +889 -0
  776. package/dist/workspace/lineage-vendor.js +171 -0
  777. package/dist/workspace/lineage-version.js +128 -0
  778. package/dist/workspace/lineage-versions.js +275 -0
  779. package/dist/workspace/links.js +330 -0
  780. package/dist/workspace/ls-generated.js +95 -0
  781. package/dist/workspace/ls.js +277 -0
  782. package/dist/workspace/ls.schema.json +333 -0
  783. package/dist/workspace/member-commands.js +508 -0
  784. package/dist/workspace/member-handles.js +216 -0
  785. package/dist/workspace/member-pipeline.js +258 -0
  786. package/dist/workspace/member-run.js +117 -0
  787. package/dist/workspace/member-write.schema.json +193 -0
  788. package/dist/workspace/nested-graph.js +156 -0
  789. package/dist/workspace/nesting.js +38 -0
  790. package/dist/workspace/patch.js +301 -0
  791. package/dist/workspace/patch.schema.json +321 -0
  792. package/dist/workspace/pin-cli.js +55 -0
  793. package/dist/workspace/pin-integrity.js +100 -0
  794. package/dist/workspace/plan-summary.schema.json +155 -0
  795. package/dist/workspace/point-answer.schema.json +129 -129
  796. package/dist/workspace/points-cli.js +291 -0
  797. package/dist/workspace/points-write.schema.json +660 -0
  798. package/dist/workspace/points.js +521 -0
  799. package/dist/workspace/points.schema.json +916 -0
  800. package/dist/workspace/pr-report.schema.json +108 -0
  801. package/dist/workspace/principal-classes.js +245 -0
  802. package/dist/workspace/reason-codes.js +326 -0
  803. package/dist/workspace/record-assets.js +151 -0
  804. package/dist/workspace/record-decided.js +105 -0
  805. package/dist/workspace/record-sessions.js +96 -0
  806. package/dist/workspace/record-source.js +114 -0
  807. package/dist/workspace/records-amend.schema.json +284 -0
  808. package/dist/workspace/records-checkout.js +76 -0
  809. package/dist/workspace/records-cli.js +707 -0
  810. package/dist/workspace/records-close.js +116 -0
  811. package/dist/workspace/records-close.schema.json +278 -0
  812. package/dist/workspace/records-new.schema.json +202 -0
  813. package/dist/workspace/records-review.schema.json +367 -0
  814. package/dist/workspace/records-since.js +317 -0
  815. package/dist/workspace/records-since.schema.json +218 -0
  816. package/dist/workspace/records-write.js +1229 -0
  817. package/dist/workspace/records.js +1345 -0
  818. package/dist/workspace/records.schema.json +604 -0
  819. package/dist/workspace/reference-kinds/app/package.json +10 -0
  820. package/dist/workspace/reference-kinds/app/workspace-kinds.json +45 -0
  821. package/dist/workspace/returns.js +303 -0
  822. package/dist/workspace/root-refusal.js +75 -0
  823. package/dist/workspace/run-statement.schema.json +622 -0
  824. package/dist/workspace/runs-cli.js +584 -0
  825. package/dist/workspace/runs-write.schema.json +994 -0
  826. package/dist/workspace/runs.js +708 -0
  827. package/dist/workspace/runs.schema.json +1257 -0
  828. package/dist/workspace/runtimes.js +76 -0
  829. package/dist/workspace/session-kinds.js +83 -0
  830. package/dist/workspace/signers.schema.json +206 -0
  831. package/dist/workspace/source-block.js +125 -0
  832. package/dist/workspace/squash.js +177 -0
  833. package/dist/workspace/status-gates.js +162 -0
  834. package/dist/workspace/status-stewards.js +330 -0
  835. package/dist/workspace/status.js +514 -0
  836. package/dist/workspace/status.schema.json +998 -0
  837. package/dist/workspace/steward-index.js +191 -0
  838. package/dist/workspace/symbols.js +188 -0
  839. package/dist/workspace/template-manifest.js +227 -0
  840. package/dist/workspace/template-pins.js +115 -0
  841. package/dist/workspace/trailer-joins.js +65 -0
  842. package/dist/workspace/trailers.js +111 -0
  843. package/dist/workspace/tree.js +136 -0
  844. package/dist/workspace/trust/attestor.js +63 -0
  845. package/dist/workspace/trust/dsse.js +108 -0
  846. package/dist/workspace/trust/evidence-cli.js +175 -0
  847. package/dist/workspace/trust/evidence.js +161 -0
  848. package/dist/workspace/trust/gate-seal.js +226 -0
  849. package/dist/workspace/trust/policy.js +190 -0
  850. package/dist/workspace/trust/provenance.js +180 -0
  851. package/dist/workspace/trust/rotation.js +298 -0
  852. package/dist/workspace/trust/run-commits.js +101 -0
  853. package/dist/workspace/trust/run-statement.js +182 -0
  854. package/dist/workspace/trust/seal.js +272 -0
  855. package/dist/workspace/trust/signers-cli.js +152 -0
  856. package/dist/workspace/trust/ssh-commit.js +178 -0
  857. package/dist/workspace/trust/test-repo.js +118 -0
  858. package/dist/workspace/trust/trust-files.js +193 -0
  859. package/dist/workspace/trust/verify-cli.js +63 -0
  860. package/dist/workspace/trust/verify.js +192 -0
  861. package/dist/workspace/which-chant.js +141 -0
  862. package/dist/workspace/wip-cli.js +95 -0
  863. package/dist/workspace/wip-write.schema.json +504 -0
  864. package/dist/workspace/wip.js +631 -0
  865. package/dist/workspace/wip.schema.json +334 -0
  866. package/dist/workspace/work-cli.js +448 -0
  867. package/dist/workspace/work-evidence.js +122 -0
  868. package/dist/workspace/work-evidence.schema.json +222 -0
  869. package/dist/workspace/work-history.schema.json +421 -0
  870. package/dist/workspace/work-lease.schema.json +246 -0
  871. package/dist/workspace/work-size.js +77 -0
  872. package/dist/workspace/work.js +283 -0
  873. package/dist/workspace/workspace-kinds.schema.json +259 -259
  874. package/dist/workspace/workspace-principals.schema.json +53 -53
  875. package/dist/workspace/write-lock-cli.js +105 -0
  876. package/dist/workspace/write-lock.js +424 -0
  877. package/dist/workspace/write-lock.schema.json +172 -0
  878. package/dist/workspace/write-scope.js +484 -0
  879. package/dist/yaml.js +459 -0
  880. package/package.json +2 -2
  881. package/src/cli/commands/check-lexicon-plugin.ts +2 -0
  882. package/src/cli/commands/lint.ts +3 -0
  883. package/src/cli/commands/migrate.ts +2 -0
  884. package/src/cli/compiled-cli.e2e.test.ts +165 -0
  885. package/src/cli/main.ts +121 -27
  886. package/src/cli/mcp/workspace-tools.ts +1 -1
  887. package/src/codegen/pinned-upgrade.ts +2 -0
  888. package/src/components/discover.ts +2 -0
  889. package/src/components/sandbox/driver.ts +3 -1
  890. package/src/config-import.ts +3 -0
  891. package/src/discovery/fold-import.ts +23 -14
  892. package/src/discovery/import.ts +2 -0
  893. package/src/discovery/sandbox/driver.ts +3 -1
  894. package/src/lexicon-module.ts +3 -0
  895. package/src/lint/config.ts +1 -1
  896. package/src/lint/discover.ts +28 -8
  897. package/src/lint/policy-import.ts +4 -1
  898. package/src/lint/rule-loader.ts +2 -0
  899. package/src/op/discover.ts +3 -0
  900. package/src/ts-loader.test.ts +23 -0
  901. package/src/ts-loader.ts +122 -0
  902. package/src/workspace/chant-migrations/chud-lexicon-exit.ts +1 -1
  903. package/src/workspace/declaration.ts +1 -1
  904. package/src/workspace/kinds.ts +1 -1
  905. package/src/workspace/lineage-migrations.ts +2 -0
  906. package/src/workspace/points.ts +1 -1
  907. package/src/workspace/principal-classes.ts +1 -1
@@ -0,0 +1,1080 @@
1
+ /**
2
+ * Workspace writer conformance (#3159, ws-074).
3
+ *
4
+ * The repo is the database (ws-074): every durable fact about a workspace is
5
+ * a file in the repository or a line on its ledger branch, written only
6
+ * through chant's write contract, and a tool keeps nothing but secrets,
7
+ * telemetry, caches and its substrate's runtime state outside it. The reader
8
+ * suite beside this module holds a reader to the read contract. This one
9
+ * holds a writer, such as hud or studio's factory, to the write contract:
10
+ *
11
+ * 1. Writes go through chant. The suite drives a script of writes
12
+ * ({@link WRITER_SCRIPT}) through the writer's `write(step)`. Each step
13
+ * must make exactly one chant call, the step's write-contract command
14
+ * with its arguments (and its JSON flag, where the command has one),
15
+ * giving chant the step's fields on stdin. The document the writer
16
+ * returns is the one chant printed, it validates against the command's
17
+ * output schema, and it is not a refusal.
18
+ * 2. Every change is chant's. The workspace's files (outside `.git`) and its
19
+ * git refs are read before and after each step. A file may change only
20
+ * when it is the path the command reports writing, and a ref only when
21
+ * it is the lease ref or the `chant/lifecycle` commit the command
22
+ * reports.
23
+ * 3. Amnesia. The writer is given a state directory of its own, outside
24
+ * the workspace, and declares what it keeps there (`privateState`). After
25
+ * the script the suite asks the writer for the facts it shows
26
+ * (`facts()`), closes it, deletes everything in the state directory,
27
+ * builds the writer again and asks again: the two answers must be equal.
28
+ * The suite also reads every fact the script produced back through the
29
+ * read contract, the uncommitted records included.
30
+ * 4. No facts outside the repo. A file left in the state directory that
31
+ * `privateState` does not declare is a problem, and so is an entry of
32
+ * the writer's optional `holds()` that names a record, run or lease the
33
+ * repository does not have, unless it names itself one of the four
34
+ * exceptions.
35
+ *
36
+ * 5. Concurrent writes (#3173, ws-089). When the writer performs `records
37
+ * amend`, the suite has it make three amendments of the script's
38
+ * decision at once, each from the digest the suite read
39
+ * (`--expect <digest>`), as two people and an agent would. Exactly one
40
+ * must be written; the other two must come back as chant's
41
+ * record-conflict refusal, naming the winner's digest, returned to the
42
+ * suite unchanged rather than retried blindly or hidden. The suite then
43
+ * has the writer retry each from the digest its refusal named, and each
44
+ * retry must be written. See {@link CONCURRENT_AMENDS}.
45
+ *
46
+ * `facts()` may only read: every chant call it makes must be a read-contract
47
+ * command, and it must leave the workspace as it was.
48
+ *
49
+ * The workspace is generated for each run, from the reader suite's fixture
50
+ * and the `__writer_fixture__/` overlay this package ships beside this module:
51
+ * the reference workspace's work, answer and session kinds (with the
52
+ * contract and driver kinds a session's verdicts may also name), its
53
+ * decision points, and one open work item, W-001. Nothing is written
54
+ * anywhere else.
55
+ *
56
+ * Actions a writer does not list in `actions` are not applicable to it. The
57
+ * suite still performs those steps itself, directly through chant, so a later
58
+ * step that depends on one (an amend on the decision a `records new` made,
59
+ * an evidence entry under a claimed lease) has what it needs.
60
+ */
61
+ import { execFileSync } from "node:child_process";
62
+ import { createHash } from "node:crypto";
63
+ import { cpSync, existsSync, mkdirSync, mkdtempSync, readdirSync, readFileSync, realpathSync, rmSync, writeFileSync } from "node:fs";
64
+ import { createRequire } from "node:module";
65
+ import { tmpdir } from "node:os";
66
+ import { dirname, join, resolve } from "node:path";
67
+ import { fileURLToPath } from "node:url";
68
+ import { isDeepStrictEqual } from "node:util";
69
+ import { createConformanceWorkspace, defaultChantCommand, runChant, treeChanges } from "./index.js";
70
+ // Nothing at the top level of this module may use a binding imported from
71
+ // ./index: index re-exports this module, so this module is evaluated first.
72
+ /** The write-contract commands a writer performs, as the suite names them. */
73
+ export const WRITE_CONTRACT_ACTIONS = [
74
+ "records new",
75
+ "records amend",
76
+ "records review",
77
+ "records close",
78
+ "points ask",
79
+ "points answer",
80
+ "points retract",
81
+ "work claim",
82
+ "work renew",
83
+ "work evidence",
84
+ "work release",
85
+ "runs start",
86
+ "runs end",
87
+ "runs record",
88
+ "box listing set",
89
+ "wip save",
90
+ "wip restore",
91
+ ];
92
+ /** Each action's output schema, in `src/workspace/` beside this module's directory. */
93
+ export const WRITE_CONTRACT_SCHEMAS = {
94
+ "records new": "records-new.schema.json",
95
+ "records amend": "records-amend.schema.json",
96
+ "records review": "records-review.schema.json",
97
+ "records close": "records-close.schema.json",
98
+ "points ask": "points-write.schema.json",
99
+ "points answer": "points-write.schema.json",
100
+ "points retract": "points-write.schema.json",
101
+ "work claim": "work-lease.schema.json",
102
+ "work renew": "work-lease.schema.json",
103
+ "work evidence": "work-evidence.schema.json",
104
+ "work release": "work-lease.schema.json",
105
+ "runs start": "runs-write.schema.json",
106
+ "runs end": "runs-write.schema.json",
107
+ "runs record": "runs-write.schema.json",
108
+ "box listing set": "box-listing-write.schema.json",
109
+ "wip save": "wip-write.schema.json",
110
+ "wip restore": "wip-write.schema.json",
111
+ };
112
+ /**
113
+ * The flags a writer may add to each command. The record, points, evidence,
114
+ * run and listing writes always print their document, so a writer adds
115
+ * nothing or `--json`; a lease prints its document only with `--json`.
116
+ */
117
+ export const WRITE_CONTRACT_JSON_FLAGS = {
118
+ "records new": [[], ["--json"]],
119
+ "records amend": [[], ["--json"]],
120
+ "records review": [[], ["--json"]],
121
+ "records close": [[], ["--json"]],
122
+ "points ask": [[], ["--json"]],
123
+ "points answer": [[], ["--json"]],
124
+ "points retract": [[], ["--json"]],
125
+ "work claim": [["--json"]],
126
+ "work renew": [["--json"]],
127
+ "work evidence": [[], ["--json"]],
128
+ "work release": [["--json"]],
129
+ "runs start": [[], ["--json"]],
130
+ "runs end": [[], ["--json"]],
131
+ "runs record": [[], ["--json"]],
132
+ "box listing set": [[], ["--json"]],
133
+ "wip save": [[], ["--json"]],
134
+ "wip restore": [[], ["--json"]],
135
+ };
136
+ /**
137
+ * The arguments that perform `action` with `params`, after `chant workspace
138
+ * <action>`, and the JSON the command reads on stdin. A writer can build its
139
+ * calls with this, or with its own code that makes the same call.
140
+ */
141
+ export function writeArgv(action, params) {
142
+ const p = params;
143
+ const json = (v) => JSON.stringify(v);
144
+ switch (action) {
145
+ case "records new": {
146
+ const q = p;
147
+ return { args: [q.kind, "--from", "-"], input: json(q.fields) };
148
+ }
149
+ case "records amend": {
150
+ const q = p;
151
+ return { args: [q.id, "--kind", q.kind, "--set", "-", ...(q.expect !== undefined ? ["--expect", q.expect] : [])], input: json(q.fields) };
152
+ }
153
+ case "records review": {
154
+ const q = p;
155
+ return { args: [q.id, "--kind", q.kind, "--verdict", q.verdict, "--by", q.by, ...(q.note !== undefined ? ["--note", q.note] : [])] };
156
+ }
157
+ case "records close": {
158
+ const q = p;
159
+ return { args: [q.id, "--kind", q.kind] };
160
+ }
161
+ case "points ask": {
162
+ const q = p;
163
+ const subject = q.subject !== undefined ? ["--subject", q.subject] : [];
164
+ // An ad-hoc ask (#3403): the question and candidates read from stdin, and the inputs given as JSON.
165
+ if (q.candidates !== undefined)
166
+ return { args: [q.point, "--inputs", json(q.inputs), "--candidates", "-", ...subject, "--kind", q.kind], input: json(q.candidates) };
167
+ return { args: [q.point, "--inputs", "-", ...subject, "--kind", q.kind], input: json(q.inputs) };
168
+ }
169
+ case "points answer": {
170
+ const q = p;
171
+ return { args: [q.id, "--answer", q.answer, "--by", q.by, ...(q.note !== undefined ? ["--note", q.note] : []), "--kind", q.kind] };
172
+ }
173
+ case "points retract": {
174
+ const q = p;
175
+ return { args: [q.id, "--by", q.by, ...(q.note !== undefined ? ["--note", q.note] : []), "--kind", q.kind] };
176
+ }
177
+ case "work claim": {
178
+ const q = p;
179
+ return { args: [q.id, "--holder", q.holder, "--kind", q.kind] };
180
+ }
181
+ case "work renew": {
182
+ const q = p;
183
+ return { args: [q.id, "--holder", q.holder, "--token", q.token, "--kind", q.kind] };
184
+ }
185
+ case "work evidence": {
186
+ const q = p;
187
+ return { args: [q.id, "--holder", q.holder, "--token", q.token, "--from", "-", "--kind", q.kind], input: json(q.entry) };
188
+ }
189
+ case "work release": {
190
+ const q = p;
191
+ return { args: [q.id, "--holder", q.holder, "--token", q.token, "--outcome", q.outcome, "--kind", q.kind] };
192
+ }
193
+ case "runs start":
194
+ case "runs record": {
195
+ const q = p;
196
+ return { args: ["--from", "-"], input: json(q.run) };
197
+ }
198
+ case "runs end": {
199
+ const q = p;
200
+ return { args: [q.id, "--from", "-"], input: json(q.fields) };
201
+ }
202
+ case "box listing set": {
203
+ const q = p;
204
+ return { args: [q.member, "--from", "-", ...(q.cover !== undefined ? ["--cover", q.cover] : [])], input: json(q.fields) };
205
+ }
206
+ case "wip save": {
207
+ const q = p;
208
+ return { args: [...(q.label !== undefined ? ["--label", q.label] : []), ...(q.by !== undefined ? ["--by", q.by] : [])] };
209
+ }
210
+ case "wip restore": {
211
+ const q = p;
212
+ return { args: [q.snapshot, ...(q.by !== undefined ? ["--by", q.by] : [])] };
213
+ }
214
+ default:
215
+ throw new Error(`not a write-contract action: ${String(action)}`);
216
+ }
217
+ }
218
+ /** The kind files of the writer workspace, from its root. */
219
+ export const WRITER_KINDS = {
220
+ decision: "decisions/decision.kind.mjs",
221
+ session: "sessions/session.kind.mjs",
222
+ answer: "answers/answer.kind.mjs",
223
+ work: "work/work.kind.mjs",
224
+ };
225
+ /** The member of the writer workspace whose box block the script lists (#3308). */
226
+ export const WRITER_BOX = "app";
227
+ /**
228
+ * The files the suite makes for a run outside the workspace, for a step to
229
+ * hand chant: the cover image the listing step copies in (#3308), a PNG.
230
+ */
231
+ export const WRITER_INPUTS = {
232
+ cover: {
233
+ name: "cover.png",
234
+ bytes: Buffer.from("iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg==", "base64"),
235
+ },
236
+ };
237
+ /** Write {@link WRITER_INPUTS} into `dir`. */
238
+ export function writeWriterInputs(dir) {
239
+ mkdirSync(dir, { recursive: true });
240
+ for (const f of Object.values(WRITER_INPUTS))
241
+ writeFileSync(join(dir, f.name), f.bytes);
242
+ return { dir };
243
+ }
244
+ /** The principals the script writes as. */
245
+ export const WRITER_PRINCIPALS = { holder: "conformance-writer", reviewer: "conformance-reviewer", by: "conformance" };
246
+ const step = (id, action, params) => ({ id, action, params });
247
+ const leaseToken = (done) => String(done.claim?.lease?.token ?? "");
248
+ const RUN_STARTED = { harness: { name: "conformance", version: "1" }, model: "none", provider: "none", by: WRITER_PRINCIPALS.by, unit: "W-001" };
249
+ /**
250
+ * The writes the suite drives, in order, each action at least once: a
251
+ * decision made, amended and reviewed; a review session opened and closed; a
252
+ * decision point asked, answered with a note, the answer retracted and the
253
+ * question answered again (#3351); an ad-hoc question asked with its own
254
+ * question and candidates, as an agent asks the room, and answered (#3403); the work item's lease claimed, renewed,
255
+ * evidence attached under it and released; one run started and ended, and one
256
+ * recorded whole; the box's listing set, with a cover image copied in; and a
257
+ * snapshot of the working tree taken and restored (#3172).
258
+ */
259
+ export const WRITER_SCRIPT = [
260
+ step("decision", "records new", () => ({
261
+ kind: WRITER_KINDS.decision,
262
+ fields: {
263
+ schema: 1,
264
+ title: "How a writer writes the workspace",
265
+ state: "proposed",
266
+ area: "delivery",
267
+ source: { kind: "workspace", member: "delivery" },
268
+ question: "How does a tool write a fact about this workspace?",
269
+ options: [{ id: "a", label: "through chant's write contract", how: "Each fact is one chant write command.", tradeoff: "One chant call per fact." }],
270
+ choice: null,
271
+ rejected: [],
272
+ supersedes: [],
273
+ evidence: [{ title: "INTENTIUS/chant#3159, the writer conformance suite", url: "https://github.com/INTENTIUS/chant/issues/3159" }],
274
+ decided_by: null,
275
+ decided_on: null,
276
+ reviews: [],
277
+ constrains: ["member:delivery"],
278
+ },
279
+ })),
280
+ step("amend", "records amend", (d) => ({ id: String(d.decision.id), kind: WRITER_KINDS.decision, fields: { title: "How a writer writes the workspace, through chant" } })),
281
+ step("review", "records review", (d) => ({ id: String(d.decision.id), kind: WRITER_KINDS.decision, verdict: "agree", by: WRITER_PRINCIPALS.reviewer, note: "Written through chant, read back after amnesia." })),
282
+ step("session", "records new", (d) => ({
283
+ kind: WRITER_KINDS.session,
284
+ fields: {
285
+ schema: 1,
286
+ id: "S-0001",
287
+ title: "The writer suite walks its decision",
288
+ state: "open",
289
+ agenda: [{ record: String(d.decision.id) }],
290
+ attendance: [{ principal: WRITER_PRINCIPALS.reviewer, class: "person" }],
291
+ opened: "2026-01-01T00:00:00Z",
292
+ closed: null,
293
+ verdicts: [],
294
+ // A review comment anchored in the app, as a UI review batch keeps it (#3350).
295
+ comments: [
296
+ {
297
+ text: "The status line should say which build is running.",
298
+ by: WRITER_PRINCIPALS.reviewer,
299
+ anchor: { route: "/", elements: [{ selector: "#status", tag: "p", text: "Running.", state: "anchored", basis: "id" }] },
300
+ answers: [{ round: 0, disposition: "needs-discussion", note: "Which build: the commit or the release?", by: WRITER_PRINCIPALS.holder, at: "2026-01-01T00:02:00Z" }],
301
+ },
302
+ ],
303
+ rounds: [{ round: 0, note: null, by: WRITER_PRINCIPALS.reviewer, at: "2026-01-01T00:01:00Z", ended: "2026-01-01T00:03:00Z" }],
304
+ },
305
+ })),
306
+ step("close", "records close", (d) => ({ id: String(d.session.id), kind: WRITER_KINDS.session })),
307
+ step("ask", "points ask", () => ({
308
+ point: "slice-tier",
309
+ kind: WRITER_KINDS.answer,
310
+ subject: "W-001",
311
+ inputs: { "work-item.criteria": 1, "work-item.files": 1, "work-item.words": 40, "work-item.fits_small": false, "work-item.fits_medium": false },
312
+ })),
313
+ step("answer", "points answer", (d) => ({ id: String(d.ask.id), kind: WRITER_KINDS.answer, answer: "medium", by: WRITER_PRINCIPALS.reviewer, note: "Two criteria and one file, but past the small limits." })),
314
+ step("retract", "points retract", (d) => ({ id: String(d.ask.id), kind: WRITER_KINDS.answer, by: WRITER_PRINCIPALS.reviewer, note: "Answered for the wrong work item." })),
315
+ step("reanswer", "points answer", (d) => ({ id: String(d.ask.id), kind: WRITER_KINDS.answer, answer: "large", by: WRITER_PRINCIPALS.reviewer })),
316
+ // #3403: an agent's question to the room, its text and options arriving with the ask.
317
+ step("adhoc", "points ask", () => ({
318
+ point: "agent-question",
319
+ kind: WRITER_KINDS.answer,
320
+ subject: "W-001",
321
+ inputs: { "ask.id": "conformance-ask-1", "ask.by": WRITER_PRINCIPALS.holder },
322
+ candidates: {
323
+ question: "Should the writer suite's item ship behind a flag?",
324
+ criteria: { flag: "Behind a flag, off by default.", now: "On for everyone at once." },
325
+ },
326
+ })),
327
+ step("adhoc-answer", "points answer", (d) => ({ id: String(d.adhoc.id), kind: WRITER_KINDS.answer, answer: "flag", by: WRITER_PRINCIPALS.reviewer })),
328
+ step("claim", "work claim", () => ({ id: "W-001", kind: WRITER_KINDS.work, holder: WRITER_PRINCIPALS.holder })),
329
+ step("renew", "work renew", (d) => ({ id: "W-001", kind: WRITER_KINDS.work, holder: WRITER_PRINCIPALS.holder, token: leaseToken(d) })),
330
+ step("evidence", "work evidence", (d) => ({
331
+ id: "W-001",
332
+ kind: WRITER_KINDS.work,
333
+ holder: WRITER_PRINCIPALS.holder,
334
+ token: leaseToken(d),
335
+ entry: { criterion: "AC-1", result: "pass", title: "The writer conformance suite's evidence step", url: "https://github.com/INTENTIUS/chant/issues/3159" },
336
+ })),
337
+ step("release", "work release", (d) => ({ id: "W-001", kind: WRITER_KINDS.work, holder: WRITER_PRINCIPALS.holder, token: leaseToken(d), outcome: "done" })),
338
+ step("run-start", "runs start", () => ({ run: { id: "writer-run-1", startedAt: "2026-01-01T00:00:00Z", ...RUN_STARTED } })),
339
+ step("run-end", "runs end", (d) => ({
340
+ id: String(d["run-start"].run.id),
341
+ fields: { endedAt: "2026-01-01T00:05:00Z", outcome: "done", usage: { turns: 2, inputTokens: 100, outputTokens: 50 }, cost: { amount: 0.02, currency: "USD", source: "conformance" }, commits: [] },
342
+ })),
343
+ step("run-record", "runs record", () => ({
344
+ run: {
345
+ id: "writer-run-2",
346
+ startedAt: "2026-01-01T01:00:00Z",
347
+ endedAt: "2026-01-01T01:01:00Z",
348
+ outcome: "done",
349
+ usage: { turns: 1, inputTokens: 10, outputTokens: 5 },
350
+ cost: { amount: 0.01, currency: "USD", source: "conformance" },
351
+ commits: [],
352
+ ...RUN_STARTED,
353
+ },
354
+ })),
355
+ step("listing", "box listing set", (_d, inputs) => ({
356
+ member: WRITER_BOX,
357
+ fields: { published: true, title: "The writer suite's box", line: "Listed through chant, read back after amnesia." },
358
+ ...(inputs ? { cover: join(inputs.dir, WRITER_INPUTS.cover.name) } : {}),
359
+ })),
360
+ // #3172: a checkpoint of everything the script left uncommitted, and putting it back.
361
+ step("checkpoint", "wip save", () => ({ label: "turn:1", by: WRITER_PRINCIPALS.by })),
362
+ step("undo", "wip restore", (done) => ({ snapshot: String(done.checkpoint?.snapshot?.commit ?? ""), by: WRITER_PRINCIPALS.by })),
363
+ ];
364
+ /**
365
+ * The concurrent case (#3173): three amendments of the script's decision the
366
+ * writer makes at once, each setting its question, as two people and an
367
+ * agent answering the same record would. The suite gives each the digest it
368
+ * read as `expect`.
369
+ */
370
+ export const CONCURRENT_AMENDS = [
371
+ { id: "concurrent-alice", fields: { question: "How does a tool write a fact about this workspace, as alice reads it?" } },
372
+ { id: "concurrent-bob", fields: { question: "How does a tool write a fact about this workspace, as bob reads it?" } },
373
+ { id: "concurrent-agent", fields: { question: "How does a tool write a fact about this workspace, as the agent reads it?" } },
374
+ ];
375
+ /** The amend step of {@link CONCURRENT_AMENDS} entry `c`, on record `id`, from digest `expect`. */
376
+ export function concurrentAmendStep(c, id, expect) {
377
+ const params = { id, kind: WRITER_KINDS.decision, fields: c.fields, expect };
378
+ return { id: c.id, action: "records amend", params, ...writeArgv("records amend", params) };
379
+ }
380
+ /** The four things ws-074 lets a tool keep outside the repo. */
381
+ export const PRIVATE_STATE_CATEGORIES = ["cache", "telemetry", "secret", "runtime"];
382
+ const here = dirname(fileURLToPath(import.meta.url));
383
+ const workspaceSrc = resolve(here, "..");
384
+ /** The overlay the writer workspace adds to the reader suite's fixture, shipped under `src/`. */
385
+ export const WRITER_FIXTURE_DIR = join(here, "__writer_fixture__");
386
+ const writeValidators = new Map();
387
+ /** An action's output schema and a draft 2020-12 validator for it, from this package's own ajv 8. */
388
+ export function writeContractSchema(action) {
389
+ const file = WRITE_CONTRACT_SCHEMAS[action];
390
+ let v = writeValidators.get(file);
391
+ if (!v) {
392
+ const schema = JSON.parse(readFileSync(join(workspaceSrc, file), "utf-8"));
393
+ const mod = createRequire(import.meta.url)("ajv/dist/2020");
394
+ const Ajv = (mod.default ?? mod);
395
+ v = { validate: new Ajv({ strict: true, allErrors: true }).compile(schema), schema };
396
+ writeValidators.set(file, v);
397
+ }
398
+ return v;
399
+ }
400
+ /** A digest of every file under `dir`, skipping `.git` and node_modules: the working tree. */
401
+ export function worktreeDigest(dir) {
402
+ const out = {};
403
+ const walk = (at, prefix) => {
404
+ for (const e of readdirSync(at, { withFileTypes: true })) {
405
+ if (e.name === "node_modules" || (prefix === "" && e.name === ".git"))
406
+ continue;
407
+ const rel = prefix ? `${prefix}/${e.name}` : e.name;
408
+ if (e.isDirectory())
409
+ walk(join(at, e.name), rel);
410
+ else if (e.isFile())
411
+ out[rel] = createHash("sha256").update(readFileSync(join(at, e.name))).digest("hex");
412
+ }
413
+ };
414
+ walk(dir, "");
415
+ return out;
416
+ }
417
+ /** Every git ref in `dir` and what it points at, with `HEAD` as the branch it names and its commit. */
418
+ export function gitRefs(dir) {
419
+ const out = {};
420
+ const text = execFileSync("git", ["for-each-ref", "--format=%(refname) %(objectname)"], { cwd: dir, encoding: "utf-8", stdio: ["ignore", "pipe", "pipe"] });
421
+ for (const line of text.split("\n")) {
422
+ const at = line.indexOf(" ");
423
+ if (at > 0)
424
+ out[line.slice(0, at)] = line.slice(at + 1);
425
+ }
426
+ const head = (args) => {
427
+ try {
428
+ return execFileSync("git", args, { cwd: dir, encoding: "utf-8", stdio: ["ignore", "pipe", "pipe"] }).trim();
429
+ }
430
+ catch {
431
+ return "";
432
+ }
433
+ };
434
+ out.HEAD = `${head(["symbolic-ref", "-q", "HEAD"])} ${head(["rev-parse", "-q", "--verify", "HEAD"])}`;
435
+ return out;
436
+ }
437
+ /** The refs that differ between two {@link gitRefs}, with what each now points at (empty when removed). */
438
+ export function refChanges(before, after) {
439
+ const out = {};
440
+ for (const [r, v] of Object.entries(after))
441
+ if (before[r] !== v)
442
+ out[r] = v;
443
+ for (const r of Object.keys(before))
444
+ if (after[r] === undefined)
445
+ out[r] = "";
446
+ return out;
447
+ }
448
+ /** Whether `argv` is a read-contract call: one a reader may make, which writes nothing. */
449
+ export function isReadCall(argv) {
450
+ if (argv[0] !== "workspace")
451
+ return false;
452
+ const [, verb, sub] = argv;
453
+ switch (verb) {
454
+ case "ls":
455
+ case "graph":
456
+ case "check":
457
+ case "status":
458
+ return true;
459
+ case "records":
460
+ return !["new", "amend", "review", "close", "pin"].includes(sub ?? "");
461
+ case "runs":
462
+ return !["start", "end", "record"].includes(sub ?? "");
463
+ case "points":
464
+ return !["ask", "answer", "retract"].includes(sub ?? "");
465
+ case "work":
466
+ return sub === "history";
467
+ case "wip":
468
+ return !["save", "restore", "push", "fetch"].includes(sub ?? "");
469
+ default:
470
+ return false;
471
+ }
472
+ }
473
+ /**
474
+ * Whether an argument a writer passed is the step's: the same text, or for a
475
+ * step argument that is JSON (an ad-hoc ask's inputs, #3403) the same value,
476
+ * whatever its key order or spacing.
477
+ */
478
+ function sameArg(given, want) {
479
+ if (given === want)
480
+ return true;
481
+ if (given === undefined || !/^[[{]/.test(want))
482
+ return false;
483
+ try {
484
+ return isDeepStrictEqual(JSON.parse(given), JSON.parse(want));
485
+ }
486
+ catch {
487
+ return false;
488
+ }
489
+ }
490
+ /**
491
+ * What is wrong with the chant calls one step made: anything but exactly
492
+ * one call, of `workspace <action>` with the step's arguments in order and
493
+ * the action's JSON flag, given the step's fields on stdin. Empty when the
494
+ * calls conform.
495
+ */
496
+ export function writerCallProblems(step, calls) {
497
+ const name = `${step.id} (${step.action})`;
498
+ if (calls.length !== 1)
499
+ return [`${name}: made ${calls.length} chant calls (${calls.map((c) => c.argv.join(" ")).join("; ")}), expected exactly one`];
500
+ const { argv, input } = calls[0];
501
+ const prefix = ["workspace", ...step.action.split(" ")];
502
+ if (prefix.some((t, i) => argv[i] !== t))
503
+ return [`${name}: ran chant ${argv.join(" ")}, which is not workspace ${step.action}`];
504
+ const rest = argv.slice(prefix.length);
505
+ const at = rest.findIndex((_, i) => step.args.every((a, j) => sameArg(rest[i + j], a)));
506
+ if (step.args.length > 0 && at === -1)
507
+ return [`${name}: ran chant ${argv.join(" ")}, which does not pass ${step.args.join(" ")} in order`];
508
+ const extra = step.args.length > 0 ? [...rest.slice(0, at), ...rest.slice(at + step.args.length)] : rest;
509
+ const allowed = WRITE_CONTRACT_JSON_FLAGS[step.action];
510
+ if (!allowed.some((flags) => flags.length === extra.length && flags.every((f, i) => extra[i] === f))) {
511
+ return [`${name}: ran chant ${argv.join(" ")}; beyond the command and its arguments it may add only ${allowed.map((f) => (f.length ? f.join(" ") : "nothing")).join(" or ")}, and it added ${extra.join(" ") || "nothing"}`];
512
+ }
513
+ if (step.input === undefined)
514
+ return input === undefined || input === "" ? [] : [`${name}: gave chant ${argv.join(" ")} something on stdin, and the command reads nothing there`];
515
+ let given;
516
+ try {
517
+ given = input === undefined ? undefined : JSON.parse(input);
518
+ }
519
+ catch {
520
+ given = undefined;
521
+ }
522
+ return isDeepStrictEqual(given, JSON.parse(step.input)) ? [] : [`${name}: gave chant ${argv.join(" ")} other fields on stdin than the step's`];
523
+ }
524
+ /** Everything wrong with the document one step returned (`doc`), given what chant printed (`printed`). Empty when it conforms. */
525
+ export function writerDocumentProblems(step, printed, doc) {
526
+ const name = `${step.id} (${step.action})`;
527
+ if (printed.stdout.trim() === "")
528
+ return [`${name}: chant ${printed.argv.join(" ")} printed nothing${printed.stderr ? `; stderr: ${printed.stderr.trim()}` : ""}`];
529
+ let parsed;
530
+ try {
531
+ parsed = JSON.parse(printed.stdout);
532
+ }
533
+ catch (e) {
534
+ return [`${name}: chant ${printed.argv.join(" ")} printed something that is not JSON (${e.message}); stderr: ${printed.stderr.trim()}`];
535
+ }
536
+ const problems = [];
537
+ if (!isDeepStrictEqual(doc, parsed))
538
+ problems.push(`${name}: the writer must return the document chant printed, unchanged, and it returned something else`);
539
+ const { schema, validate } = writeContractSchema(step.action);
540
+ if (!validate(parsed))
541
+ problems.push(`${name}: the document does not validate against ${WRITE_CONTRACT_SCHEMAS[step.action]}: ${JSON.stringify(validate.errors)}`);
542
+ const head = (parsed ?? {});
543
+ if (head.$schema !== schema.$id)
544
+ problems.push(`${name}: $schema is ${JSON.stringify(head.$schema)}, expected ${schema.$id}`);
545
+ const no = head.error ?? head.refused;
546
+ if (no)
547
+ problems.push(`${name}: chant did not write: ${no.code}: ${no.message}`);
548
+ return problems;
549
+ }
550
+ /** The files and refs a step's document says chant wrote. */
551
+ export function reportedWrites(action, doc) {
552
+ const d = (doc ?? {});
553
+ const str = (v) => (typeof v === "string" ? v : undefined);
554
+ if (action.startsWith("work ") && action !== "work evidence") {
555
+ // The lease ref holds a lease blob whose value the document does not
556
+ // print, so any value of the ref it names is chant's ("*").
557
+ const history = (d.history ?? {});
558
+ const refs = {};
559
+ if (str(history.commit))
560
+ refs["refs/heads/chant/lifecycle"] = String(history.commit);
561
+ if (str(d.ref))
562
+ refs[String(d.ref)] = "*";
563
+ return { paths: [], refs };
564
+ }
565
+ if (action.startsWith("runs ")) {
566
+ const ledger = (d.ledger ?? {});
567
+ return { paths: [], refs: str(ledger.commit) ? { "refs/heads/chant/lifecycle": String(ledger.commit) } : {} };
568
+ }
569
+ if (action === "box listing set")
570
+ return { paths: Array.isArray(d.paths) ? d.paths.filter((p) => typeof p === "string") : [], refs: {} };
571
+ if (action === "wip save" || action === "wip restore") {
572
+ // The one snapshot ref, at the snapshot taken (the restore's checkpoint), and any ref a push recorded under refs/chant/replica/.
573
+ const snapshot = (action === "wip save" ? d.snapshot : d.checkpoint?.snapshot);
574
+ const refs = {};
575
+ if (str(d.ref) && str(snapshot?.commit))
576
+ refs[String(d.ref)] = String(snapshot.commit);
577
+ const replication = (d.replication ?? null);
578
+ for (const p of replication?.pushed ?? [])
579
+ refs[`refs/chant/replica/${replication.remote}/${p.ref.slice("refs/".length)}`] = p.commit;
580
+ return { paths: Array.isArray(d.paths) ? d.paths.filter((p) => typeof p === "string") : [], refs };
581
+ }
582
+ return { paths: str(d.path) ? [String(d.path)] : [], refs: {} };
583
+ }
584
+ /**
585
+ * What changed in the workspace during one step that the step's document
586
+ * does not report: a file other than the path chant wrote, or a ref other
587
+ * than the lease ref and the ledger commit chant wrote.
588
+ */
589
+ export function unreportedChanges(step, doc, files, refs) {
590
+ const name = `${step.id} (${step.action})`;
591
+ const reported = reportedWrites(step.action, doc);
592
+ const problems = [];
593
+ const changed = treeChanges(files.before, files.after).filter((c) => !reported.paths.includes(c.replace(/ \((added|changed|removed)\)$/, "")));
594
+ if (changed.length > 0)
595
+ problems.push(`${name}: files changed that chant did not report writing: ${changed.join(", ")}`);
596
+ const refsChanged = Object.entries(refChanges(refs.before, refs.after)).filter(([r, v]) => !(r in reported.refs && (reported.refs[r] === "*" || reported.refs[r] === v)));
597
+ if (refsChanged.length > 0)
598
+ problems.push(`${name}: git refs changed that chant did not report writing: ${refsChanged.map(([r]) => r).join(", ")}`);
599
+ return problems;
600
+ }
601
+ /** Build the step a script step is at, from the documents of the steps before it and where the suite put its inputs. */
602
+ export function buildStep(s, done, inputs) {
603
+ const params = s.params(done, inputs);
604
+ return { id: s.id, action: s.action, params, ...writeArgv(s.action, params) };
605
+ }
606
+ /** The box listings `status --json` prints, by member: what a home site shows of each box (#3308). */
607
+ export async function readListing(run) {
608
+ const doc = JSON.parse((await run(["workspace", "status", "dev", "--json"])).stdout);
609
+ return Object.fromEntries((doc.members ?? []).filter((m) => m.box?.listing).map((m) => [m.name, m.box.listing]));
610
+ }
611
+ /** Each branch's work-in-progress snapshots `wip --json` lists (#3172), by branch: each snapshot's kind and label, newest first. */
612
+ export async function readWip(run) {
613
+ const doc = JSON.parse((await run(["workspace", "wip", "--json"])).stdout);
614
+ return Object.fromEntries((doc.branches ?? []).map((b) => [b.branch, b.snapshots.map((s) => [s.kind, s.label])]));
615
+ }
616
+ /** The smallest writer that conforms: each step is its one command, and its facts are read through the read contract. */
617
+ export const referenceWriter = (chant) => ({
618
+ async write(step) {
619
+ const run = await chant.run(["workspace", ...step.action.split(" "), ...step.args, ...WRITE_CONTRACT_JSON_FLAGS[step.action][0]], step.input === undefined ? undefined : { input: step.input });
620
+ return JSON.parse(run.stdout);
621
+ },
622
+ async facts() {
623
+ const out = {};
624
+ for (const [name, kind] of Object.entries(WRITER_KINDS)) {
625
+ const run = await chant.run(["workspace", "records", "--kind", kind, "--json"]);
626
+ const doc = JSON.parse(run.stdout);
627
+ out[name] = doc.records.map((r) => [r.id, r.state]).sort();
628
+ }
629
+ const runs = JSON.parse((await chant.run(["workspace", "runs", "--json"])).stdout);
630
+ out.runs = runs.runs.map((r) => [r.id, r.state]).sort();
631
+ out.listing = await readListing((argv) => chant.run(argv));
632
+ out.wip = await readWip((argv) => chant.run(argv));
633
+ return out;
634
+ },
635
+ });
636
+ /**
637
+ * Generate the writer conformance workspace: the reader suite's workspace
638
+ * ({@link createConformanceWorkspace}), with `__writer_fixture__/` copied over
639
+ * it, the four kinds declared in its `records`, a box block on
640
+ * {@link WRITER_BOX} for the listing step, and that committed.
641
+ */
642
+ export function createWriterConformanceWorkspace(options = {}) {
643
+ const ws = createConformanceWorkspace({ chantCommand: options.chantCommand, timeoutMs: options.timeoutMs });
644
+ try {
645
+ cpSync(WRITER_FIXTURE_DIR, ws.dir, { recursive: true });
646
+ const declFile = join(ws.dir, "chant.workspace.json");
647
+ const decl = JSON.parse(readFileSync(declFile, "utf-8"));
648
+ decl.records = Object.values(WRITER_KINDS).map((kind) => ({ kind }));
649
+ const box = decl.members?.find((m) => m.name === WRITER_BOX);
650
+ if (box)
651
+ box.box = {};
652
+ writeFileSync(declFile, `${JSON.stringify(decl, null, 2)}\n`);
653
+ const git = (...args) => execFileSync("git", ["-c", "user.name=chant", "-c", "user.email=chant@localhost", "-c", "commit.gpgsign=false", ...args], {
654
+ cwd: ws.dir,
655
+ env: { ...process.env, GIT_CONFIG_GLOBAL: process.platform === "win32" ? "NUL" : "/dev/null", GIT_CONFIG_NOSYSTEM: "1" },
656
+ stdio: ["ignore", "pipe", "pipe"],
657
+ });
658
+ git("add", "-A");
659
+ git("commit", "--quiet", "-m", "the writer conformance workspace");
660
+ return ws;
661
+ }
662
+ catch (e) {
663
+ ws.dispose();
664
+ const err = e;
665
+ throw new Error(`could not generate the writer conformance workspace: ${err.message}${err.stderr ? `\n${String(err.stderr)}` : ""}`);
666
+ }
667
+ }
668
+ /** The actions to exercise and the ones skipped, from `actions`. Throws on a name that is not a write-contract action. */
669
+ export function selectActions(actions) {
670
+ if (actions === undefined)
671
+ return { checked: [...WRITE_CONTRACT_ACTIONS], skipped: [] };
672
+ const unknown = actions.filter((a) => !WRITE_CONTRACT_ACTIONS.includes(a));
673
+ if (unknown.length > 0)
674
+ throw new Error(`not write-contract actions: ${unknown.join(", ")}; the actions are ${WRITE_CONTRACT_ACTIONS.join(", ")}`);
675
+ if (actions.length === 0)
676
+ throw new Error("actions is empty; list at least one write-contract action");
677
+ return { checked: WRITE_CONTRACT_ACTIONS.filter((a) => actions.includes(a)), skipped: WRITE_CONTRACT_ACTIONS.filter((a) => !actions.includes(a)) };
678
+ }
679
+ /** Every file under `dir`, from it, with / separators. */
680
+ function filesUnder(dir) {
681
+ const out = [];
682
+ const walk = (at, prefix) => {
683
+ for (const e of readdirSync(at, { withFileTypes: true })) {
684
+ const rel = prefix ? `${prefix}/${e.name}` : e.name;
685
+ if (e.isDirectory())
686
+ walk(join(at, e.name), rel);
687
+ else
688
+ out.push(rel);
689
+ }
690
+ };
691
+ if (existsSync(dir))
692
+ walk(dir, "");
693
+ return out.sort();
694
+ }
695
+ /** The files in the state directory that `privateState` does not declare, and problems with the declaration itself. */
696
+ export function undeclaredState(files, privateState) {
697
+ const problems = [];
698
+ for (const p of privateState) {
699
+ const is = typeof p.is === "string" ? [p.is] : [...p.is];
700
+ const wrong = is.filter((c) => !PRIVATE_STATE_CATEGORIES.includes(c));
701
+ if (is.length === 0 || wrong.length > 0)
702
+ problems.push(`state: ${p.path} is declared as ${JSON.stringify(p.is)}; private state is ${PRIVATE_STATE_CATEGORIES.join(", ")} (ws-074)`);
703
+ }
704
+ const declared = (f) => privateState.some((p) => f === p.path || f.startsWith(`${p.path.replace(/\/+$/, "")}/`));
705
+ const loose = files.filter((f) => !declared(f));
706
+ if (loose.length > 0)
707
+ problems.push(`state: the writer keeps ${loose.join(", ")} in its state directory, and privateState does not declare it`);
708
+ return problems;
709
+ }
710
+ /** A short JSON rendering of a value for a problem message. */
711
+ function brief(v) {
712
+ const s = JSON.stringify(v) ?? String(v);
713
+ return s.length > 400 ? `${s.slice(0, 400)}...` : s;
714
+ }
715
+ /**
716
+ * Hold a writer to the write contract, with no test runner: drive
717
+ * {@link WRITER_SCRIPT} through it on a generated workspace, check each step,
718
+ * then the amnesia test and what the writer holds, and return what is wrong.
719
+ * The writer conforms when `problems` is empty.
720
+ *
721
+ * ```js
722
+ * import { test } from "node:test";
723
+ * import assert from "node:assert/strict";
724
+ * import { runWorkspaceWriterConformance } from "@intentius/chant/workspace/conformance";
725
+ *
726
+ * test("my writer writes only through chant", { timeout: 600_000 }, async () => {
727
+ * const report = await runWorkspaceWriterConformance(myWriter, {
728
+ * actions: ["records review", "points answer"],
729
+ * privateState: [{ path: "events.db", is: "cache" }],
730
+ * });
731
+ * assert.deepEqual(report.problems, []);
732
+ * });
733
+ * ```
734
+ */
735
+ export async function runWorkspaceWriterConformance(writer, options = {}) {
736
+ const { checked, skipped } = selectActions(options.actions);
737
+ const chantCommand = options.chantCommand ?? defaultChantCommand();
738
+ const timeoutMs = options.timeoutMs ?? 120000;
739
+ const privateState = options.privateState ?? [];
740
+ const ws = createWriterConformanceWorkspace({ chantCommand, timeoutMs });
741
+ const stateDir = realpathSync(mkdtempSync(join(tmpdir(), "chant-writer-state-")));
742
+ const inputsDir = realpathSync(mkdtempSync(join(tmpdir(), "chant-writer-inputs-")));
743
+ const inputs = writeWriterInputs(inputsDir);
744
+ const calls = [];
745
+ const transport = {
746
+ async run(argv, opts) {
747
+ const run = await runChant(chantCommand, [...argv], ws.dir, timeoutMs, opts?.input);
748
+ calls.push(run);
749
+ return run;
750
+ },
751
+ };
752
+ const direct = async (argv, input) => {
753
+ const run = await runChant(chantCommand, argv, ws.dir, timeoutMs, input);
754
+ try {
755
+ return JSON.parse(run.stdout);
756
+ }
757
+ catch {
758
+ throw new Error(`chant ${argv.join(" ")} printed no JSON (exit ${run.status}): ${run.stderr.trim()}`);
759
+ }
760
+ };
761
+ const after = { facts: [], state: [], amnesia: [], holds: [], readBack: [], concurrent: [] };
762
+ const facts = { before: undefined, after: undefined };
763
+ const results = [];
764
+ try {
765
+ let built = writer(transport, { stateDir });
766
+ const done = {};
767
+ for (const s of WRITER_SCRIPT) {
768
+ const st = buildStep(s, done, inputs);
769
+ if (!checked.includes(st.action)) {
770
+ const doc = await direct(["workspace", ...st.action.split(" "), ...st.args, ...WRITE_CONTRACT_JSON_FLAGS[st.action][0]], st.input);
771
+ done[st.id] = doc;
772
+ const no = (doc.error ?? doc.refused);
773
+ results.push({ id: st.id, action: st.action, by: "suite", args: st.args, problems: no ? [`${st.id} (${st.action}): the suite's own write failed: ${no.code}: ${no.message}`] : [] });
774
+ continue;
775
+ }
776
+ const files = { before: worktreeDigest(ws.dir), after: {} };
777
+ const refs = { before: gitRefs(ws.dir), after: {} };
778
+ calls.length = 0;
779
+ let doc;
780
+ let problems;
781
+ try {
782
+ doc = await built.write(st);
783
+ problems = writerCallProblems(st, calls);
784
+ if (problems.length === 0)
785
+ problems = writerDocumentProblems(st, calls[0], doc);
786
+ }
787
+ catch (e) {
788
+ const stderr = calls[0]?.stderr.trim();
789
+ problems = [`${st.id} (${st.action}): the writer threw: ${e.message}${stderr ? `; chant's stderr: ${stderr}` : ""}`];
790
+ }
791
+ files.after = worktreeDigest(ws.dir);
792
+ refs.after = gitRefs(ws.dir);
793
+ // What chant printed is what the later steps build on, whatever the writer returned.
794
+ const printed = calls.length === 1 ? (() => { try {
795
+ return JSON.parse(calls[0].stdout);
796
+ }
797
+ catch {
798
+ return undefined;
799
+ } })() : undefined;
800
+ done[st.id] = printed ?? (doc ?? {});
801
+ problems.push(...unreportedChanges(st, done[st.id], files, refs));
802
+ results.push({ id: st.id, action: st.action, by: "writer", args: st.args, problems });
803
+ }
804
+ // Concurrent writes (#3173): three amendments of one record at once, each from the digest read.
805
+ if (checked.includes("records amend")) {
806
+ after.concurrent.push(...(await concurrentAmends(built, calls, direct, String(done.decision?.id ?? ""), ws.dir)));
807
+ }
808
+ // What the writer shows, read only through the read contract.
809
+ const readFacts = async (w, when) => {
810
+ const files = worktreeDigest(ws.dir);
811
+ const refs = gitRefs(ws.dir);
812
+ calls.length = 0;
813
+ let value;
814
+ try {
815
+ value = await w.facts();
816
+ }
817
+ catch (e) {
818
+ after.facts.push(`facts: ${when}, facts() threw: ${e.message}`);
819
+ }
820
+ const writes = calls.filter((c) => !isReadCall(c.argv));
821
+ if (writes.length > 0)
822
+ after.facts.push(`facts: ${when}, facts() made calls outside the read contract: ${writes.map((c) => c.argv.join(" ")).join("; ")}`);
823
+ const changed = treeChanges(files, worktreeDigest(ws.dir));
824
+ if (changed.length > 0)
825
+ after.facts.push(`facts: ${when}, facts() changed files: ${changed.join(", ")}`);
826
+ const refsChanged = Object.keys(refChanges(refs, gitRefs(ws.dir)));
827
+ if (refsChanged.length > 0)
828
+ after.facts.push(`facts: ${when}, facts() changed git refs: ${refsChanged.join(", ")}`);
829
+ return value;
830
+ };
831
+ facts.before = await readFacts(built, "before amnesia");
832
+ if (facts.before === undefined || facts.before === null)
833
+ after.facts.push("facts: facts() returned nothing; it returns the facts the tool shows, read the way the tool reads them");
834
+ // What the writer holds: each fact in the repo, or one of the four exceptions.
835
+ if (built.holds) {
836
+ let held = [];
837
+ try {
838
+ held = await built.holds();
839
+ }
840
+ catch (e) {
841
+ after.holds.push(`holds: holds() threw: ${e.message}`);
842
+ }
843
+ const records = new Map();
844
+ const recordIds = async (kind) => {
845
+ if (!records.has(kind)) {
846
+ const doc = await direct(["workspace", "records", "--kind", kind, "--json"]);
847
+ records.set(kind, new Set((doc.records ?? []).map((r) => r.id)));
848
+ }
849
+ return records.get(kind);
850
+ };
851
+ let runIds;
852
+ for (const h of held) {
853
+ if ("record" in h) {
854
+ if (!(await recordIds(h.kind)).has(h.record))
855
+ after.holds.push(`holds: the writer holds record ${h.record} of ${h.kind}, which the repository does not have`);
856
+ }
857
+ else if ("run" in h) {
858
+ runIds ?? (runIds = new Set(((await direct(["workspace", "runs", "--json"])).runs ?? []).map((r) => r.id)));
859
+ if (!runIds.has(h.run))
860
+ after.holds.push(`holds: the writer holds run ${h.run}, which the run ledger does not have`);
861
+ }
862
+ else if ("lease" in h) {
863
+ const doc = await direct(["workspace", "work", "history", h.lease, "--kind", h.kind, "--json"]);
864
+ if (!Array.isArray(doc.claims) || doc.claims.length === 0)
865
+ after.holds.push(`holds: the writer holds a lease on ${h.lease}, which has no lease history`);
866
+ }
867
+ else if ("exempt" in h) {
868
+ if (!PRIVATE_STATE_CATEGORIES.includes(h.exempt))
869
+ after.holds.push(`holds: ${h.what} is held as ${JSON.stringify(h.exempt)}; outside the repo a tool keeps only ${PRIVATE_STATE_CATEGORIES.join(", ")} (ws-074)`);
870
+ }
871
+ else {
872
+ after.holds.push(`holds: ${brief(h)} is not a record, run, lease or exemption`);
873
+ }
874
+ }
875
+ }
876
+ // Amnesia: close the writer, delete its state, build it again, and ask again.
877
+ try {
878
+ await built.close?.();
879
+ }
880
+ catch (e) {
881
+ after.amnesia.push(`amnesia: close() threw: ${e.message}`);
882
+ }
883
+ after.state.push(...undeclaredState(filesUnder(stateDir), privateState));
884
+ rmSync(stateDir, { recursive: true, force: true });
885
+ mkdirSync(stateDir, { recursive: true });
886
+ built = writer(transport, { stateDir });
887
+ facts.after = await readFacts(built, "after amnesia");
888
+ if (!isDeepStrictEqual(facts.before, facts.after)) {
889
+ after.amnesia.push(`amnesia: after its private state was deleted, the writer shows other facts; before: ${brief(facts.before)}; after: ${brief(facts.after)}`);
890
+ }
891
+ try {
892
+ await built.close?.();
893
+ }
894
+ catch {
895
+ // Closed again after the comparison; a failure here is not the writer's contract.
896
+ }
897
+ // Every fact the script produced, read back through the read contract.
898
+ const uncommitted = new Map();
899
+ for (const kind of Object.values(WRITER_KINDS)) {
900
+ const doc = await direct(["workspace", "records", "--uncommitted", "--kind", kind, "--json"]);
901
+ uncommitted.set(kind, new Map((doc.records ?? []).map((r) => [r.id, r.worktree])));
902
+ }
903
+ const runs = new Map(((await direct(["workspace", "runs", "--json"])).runs ?? []).map((r) => [r.id, r.state]));
904
+ const history = await direct(["workspace", "work", "history", "W-001", "--kind", WRITER_KINDS.work, "--json"]);
905
+ const listings = await readListing((argv) => runChant(chantCommand, argv, ws.dir, timeoutMs));
906
+ const wipDoc = await direct(["workspace", "wip", "--json"]);
907
+ const snapshots = new Set((wipDoc.branches ?? []).flatMap((b) => b.snapshots.map((x) => x.commit)));
908
+ const claims = (history.claims ?? []);
909
+ const questions = new Map(((await direct(["workspace", "points", "--kind", WRITER_KINDS.answer, "--json"])).questions ?? []).map((q) => [q.id, q]));
910
+ for (const s of WRITER_SCRIPT) {
911
+ const doc = done[s.id] ?? {};
912
+ if (s.action.startsWith("records ") || s.action.startsWith("points ")) {
913
+ const kind = String(doc.kind?.file ?? "");
914
+ const id = String(doc.id ?? "");
915
+ if (!uncommitted.get(kind)?.has(id))
916
+ after.readBack.push(`read back: ${s.id} (${s.action}) wrote ${id}, and records --uncommitted --kind ${kind} does not list it`);
917
+ else if (s.action === "points retract" && !(questions.get(id)?.retractions?.length ?? 0))
918
+ after.readBack.push(`read back: ${s.id} (${s.action}) retracted the answer to ${id}, and points --json lists no retraction for it`);
919
+ else if (s.action === "points ask") {
920
+ const asked = doc.question?.asked;
921
+ if (asked && !isDeepStrictEqual(questions.get(id)?.asked, asked))
922
+ after.readBack.push(`read back: ${s.id} (${s.action}) asked ${id} with its own question and candidates, and points --json does not list them as asked`);
923
+ }
924
+ }
925
+ else if (s.action === "work evidence") {
926
+ if (!uncommitted.get(WRITER_KINDS.work)?.has(String(doc.item ?? "")))
927
+ after.readBack.push(`read back: ${s.id} (${s.action}) amended ${String(doc.item)}, and records --uncommitted does not list it`);
928
+ }
929
+ else if (s.action.startsWith("work ")) {
930
+ const token = String(doc.lease?.token ?? "");
931
+ const claim = claims.find((c) => c.token === token);
932
+ if (!claim)
933
+ after.readBack.push(`read back: ${s.id} (${s.action}) wrote a lease with token ${token}, and work history does not list it`);
934
+ else if (s.action === "work release" && claim.release?.outcome !== "done")
935
+ after.readBack.push(`read back: ${s.id} (${s.action}) released the lease as done, and work history says ${brief(claim.release)}`);
936
+ }
937
+ else if (s.action.startsWith("runs ")) {
938
+ const id = String(doc.run?.id ?? "");
939
+ const want = s.action === "runs start" ? undefined : "ended";
940
+ if (!runs.has(id))
941
+ after.readBack.push(`read back: ${s.id} (${s.action}) wrote run ${id}, and runs does not list it`);
942
+ else if (want && runs.get(id) !== want)
943
+ after.readBack.push(`read back: ${s.id} (${s.action}) ended run ${id}, and runs says it is ${runs.get(id)}`);
944
+ }
945
+ else if (s.action === "box listing set") {
946
+ const member = String(doc.member ?? "");
947
+ if (!isDeepStrictEqual(listings[member], doc.listing))
948
+ after.readBack.push(`read back: ${s.id} (${s.action}) set ${member}'s listing to ${brief(doc.listing)}, and status --json says ${brief(listings[member] ?? null)}`);
949
+ }
950
+ else if (s.action === "wip save" || s.action === "wip restore") {
951
+ const snap = (s.action === "wip save" ? doc.snapshot : doc.checkpoint?.snapshot);
952
+ const commit = String(snap?.commit ?? "");
953
+ if (!snapshots.has(commit))
954
+ after.readBack.push(`read back: ${s.id} (${s.action}) wrote snapshot ${commit}, and wip --json does not list it`);
955
+ }
956
+ }
957
+ const problems = [...results.flatMap((r) => r.problems), ...after.concurrent, ...after.facts, ...after.state, ...after.amnesia, ...after.holds, ...after.readBack];
958
+ return { problems, checked, skipped, results, after, facts, workspaceDir: ws.dir };
959
+ }
960
+ finally {
961
+ rmSync(stateDir, { recursive: true, force: true });
962
+ rmSync(inputsDir, { recursive: true, force: true });
963
+ ws.dispose();
964
+ }
965
+ }
966
+ /**
967
+ * The concurrent case (#3173, ws-089): the writer makes the three
968
+ * {@link CONCURRENT_AMENDS} of record `id` at once, each from the digest the
969
+ * suite read. Exactly one is written and the others are refused with
970
+ * record-conflict naming its digest; each is then retried from the digest
971
+ * its refusal named, and written. Returns the problems, each starting
972
+ * `concurrent:`.
973
+ */
974
+ export async function concurrentAmends(built, calls, direct, id, dir) {
975
+ const problems = [];
976
+ const digestOf = async () => {
977
+ const doc = await direct(["workspace", "records", "--kind", WRITER_KINDS.decision, "--json"]);
978
+ const r = (doc.records ?? []).find((x) => x.id === id);
979
+ return r ? { digest: r.digest, path: r.path } : undefined;
980
+ };
981
+ const start = await digestOf();
982
+ if (!start)
983
+ return [`concurrent: the script's decision ${id || "(none)"} can't be read back to amend`];
984
+ const files = { before: worktreeDigest(dir), after: {} };
985
+ const refs = { before: gitRefs(dir), after: {} };
986
+ const steps = CONCURRENT_AMENDS.map((c) => concurrentAmendStep(c, id, start.digest));
987
+ calls.length = 0;
988
+ const docs = await Promise.all(steps.map(async (st) => {
989
+ try {
990
+ return { st, doc: await built.write(st) };
991
+ }
992
+ catch (e) {
993
+ problems.push(`concurrent: ${st.id} (${st.action}): the writer threw: ${e.message}`);
994
+ return { st, doc: undefined };
995
+ }
996
+ }));
997
+ // Each step's call: the one that gave chant its fields.
998
+ const printed = new Map();
999
+ for (const { st, doc } of docs) {
1000
+ const mine = calls.filter((c) => c.input !== undefined && st.input !== undefined && isDeepStrictEqual(safeJson(c.input), JSON.parse(st.input)));
1001
+ const callProblems = writerCallProblems(st, mine);
1002
+ if (callProblems.length > 0) {
1003
+ problems.push(...callProblems.map((p) => `concurrent: ${p}`));
1004
+ continue;
1005
+ }
1006
+ const out = safeJson(mine[0].stdout);
1007
+ printed.set(st.id, out);
1008
+ if (!isDeepStrictEqual(doc, out))
1009
+ problems.push(`concurrent: ${st.id} (${st.action}): the writer must return the document chant printed, unchanged, refusal included, and it returned something else`);
1010
+ const { validate } = writeContractSchema(st.action);
1011
+ if (!validate(out))
1012
+ problems.push(`concurrent: ${st.id} (${st.action}): the document does not validate against ${WRITE_CONTRACT_SCHEMAS[st.action]}: ${JSON.stringify(validate.errors)}`);
1013
+ }
1014
+ if (problems.length > 0)
1015
+ return problems;
1016
+ const won = steps.filter((st) => printed.get(st.id)?.error === undefined);
1017
+ const lost = steps.filter((st) => printed.get(st.id)?.error !== undefined);
1018
+ if (won.length !== 1) {
1019
+ problems.push(`concurrent: ${won.length} of the three amendments from digest ${start.digest} were written (${won.map((s) => s.id).join(", ") || "none"}); exactly one may be`);
1020
+ return problems;
1021
+ }
1022
+ const d1 = String(printed.get(won[0].id)?.digest ?? "");
1023
+ for (const st of lost) {
1024
+ const doc = printed.get(st.id);
1025
+ const code = doc.error.code;
1026
+ const conflict = doc.conflict;
1027
+ if (code !== "record-conflict")
1028
+ problems.push(`concurrent: ${st.id} was refused with ${code}, not record-conflict`);
1029
+ else if (conflict?.digest !== d1 || conflict?.expected !== start.digest)
1030
+ problems.push(`concurrent: ${st.id}'s conflict names ${brief(conflict)}, not expected ${start.digest} and digest ${d1}`);
1031
+ }
1032
+ files.after = worktreeDigest(dir);
1033
+ refs.after = gitRefs(dir);
1034
+ const changed = treeChanges(files.before, files.after).filter((c) => c.replace(/ \((added|changed|removed)\)$/, "") !== start.path);
1035
+ if (changed.length > 0)
1036
+ problems.push(`concurrent: files changed that chant did not report writing: ${changed.join(", ")}`);
1037
+ if (Object.keys(refChanges(refs.before, refs.after)).length > 0)
1038
+ problems.push(`concurrent: git refs changed: ${Object.keys(refChanges(refs.before, refs.after)).join(", ")}`);
1039
+ if (problems.length > 0)
1040
+ return problems;
1041
+ // Each loser retries from the digest it was told, one after the other.
1042
+ let digest = d1;
1043
+ for (const st of lost) {
1044
+ const retry = concurrentAmendStep(CONCURRENT_AMENDS.find((c) => c.id === st.id), id, digest);
1045
+ calls.length = 0;
1046
+ let doc;
1047
+ try {
1048
+ doc = await built.write(retry);
1049
+ }
1050
+ catch (e) {
1051
+ problems.push(`concurrent: ${st.id}'s retry: the writer threw: ${e.message}`);
1052
+ continue;
1053
+ }
1054
+ const p = writerCallProblems({ ...retry, id: `${st.id} retry` }, calls);
1055
+ if (p.length > 0) {
1056
+ problems.push(...p.map((x) => `concurrent: ${x}`));
1057
+ continue;
1058
+ }
1059
+ const out = safeJson(calls[0].stdout);
1060
+ if (out?.error !== undefined) {
1061
+ problems.push(`concurrent: ${st.id}'s retry from ${digest} was refused: ${brief(out.error)}`);
1062
+ continue;
1063
+ }
1064
+ if (!isDeepStrictEqual(doc, out))
1065
+ problems.push(`concurrent: ${st.id}'s retry: the writer must return the document chant printed, unchanged`);
1066
+ digest = String(out?.digest ?? "");
1067
+ }
1068
+ const end = await digestOf();
1069
+ if (problems.length === 0 && end?.digest !== digest)
1070
+ problems.push(`concurrent: after the retries records --json gives ${id} digest ${end?.digest}, and the last retry printed ${digest}`);
1071
+ return problems;
1072
+ }
1073
+ function safeJson(text) {
1074
+ try {
1075
+ return JSON.parse(text);
1076
+ }
1077
+ catch {
1078
+ return undefined;
1079
+ }
1080
+ }