@archmax-ai/harness 0.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (351) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +219 -0
  3. package/dist/agent.d.ts +174 -0
  4. package/dist/agent.js +140 -0
  5. package/dist/agent.js.map +1 -0
  6. package/dist/assembly/compose.d.ts +170 -0
  7. package/dist/assembly/compose.js +391 -0
  8. package/dist/assembly/compose.js.map +1 -0
  9. package/dist/assembly/delegation-registry.d.ts +5 -0
  10. package/dist/assembly/delegation-registry.js +118 -0
  11. package/dist/assembly/delegation-registry.js.map +1 -0
  12. package/dist/assembly/index.d.ts +192 -0
  13. package/dist/assembly/index.js +265 -0
  14. package/dist/assembly/index.js.map +1 -0
  15. package/dist/assembly/plain.d.ts +7 -0
  16. package/dist/assembly/plain.js +41 -0
  17. package/dist/assembly/plain.js.map +1 -0
  18. package/dist/authoring-skill/archmax-harness/README.md +76 -0
  19. package/dist/authoring-skill/archmax-harness/SKILL.md +241 -0
  20. package/dist/authoring-skill/archmax-harness/references/backend-integration.md +626 -0
  21. package/dist/authoring-skill/archmax-harness/references/cases.md +41 -0
  22. package/dist/authoring-skill/archmax-harness/references/diagnostics.md +51 -0
  23. package/dist/authoring-skill/archmax-harness/references/hook-and-test-scripts.md +1070 -0
  24. package/dist/authoring-skill/archmax-harness/references/hooks-and-scripts.md +82 -0
  25. package/dist/authoring-skill/archmax-harness/references/wiring.md +101 -0
  26. package/dist/authoring-skill/archmax-harness/references/workflow-schema.md +1631 -0
  27. package/dist/authoring-skill/archmax-harness/references/workflow-yaml.md +241 -0
  28. package/dist/behaviour/support.d.ts +232 -0
  29. package/dist/behaviour/support.js +339 -0
  30. package/dist/behaviour/support.js.map +1 -0
  31. package/dist/cli/banner.d.ts +11 -0
  32. package/dist/cli/banner.js +29 -0
  33. package/dist/cli/banner.js.map +1 -0
  34. package/dist/cli/bootstrap.d.ts +33 -0
  35. package/dist/cli/bootstrap.js +153 -0
  36. package/dist/cli/bootstrap.js.map +1 -0
  37. package/dist/cli/command.d.ts +39 -0
  38. package/dist/cli/command.js +97 -0
  39. package/dist/cli/command.js.map +1 -0
  40. package/dist/cli/state-flow.d.ts +46 -0
  41. package/dist/cli/state-flow.js +268 -0
  42. package/dist/cli/state-flow.js.map +1 -0
  43. package/dist/cli/style.d.ts +41 -0
  44. package/dist/cli/style.js +64 -0
  45. package/dist/cli/style.js.map +1 -0
  46. package/dist/cli/turn.d.ts +41 -0
  47. package/dist/cli/turn.js +161 -0
  48. package/dist/cli/turn.js.map +1 -0
  49. package/dist/cli.d.ts +10 -0
  50. package/dist/cli.js +426 -0
  51. package/dist/cli.js.map +1 -0
  52. package/dist/core/code-description.d.ts +22 -0
  53. package/dist/core/code-description.js +38 -0
  54. package/dist/core/code-description.js.map +1 -0
  55. package/dist/core/deepagents.d.ts +183 -0
  56. package/dist/core/deepagents.js +128 -0
  57. package/dist/core/deepagents.js.map +1 -0
  58. package/dist/core/events.d.ts +350 -0
  59. package/dist/core/events.js +205 -0
  60. package/dist/core/events.js.map +1 -0
  61. package/dist/core/frontmatter.d.ts +15 -0
  62. package/dist/core/frontmatter.js +32 -0
  63. package/dist/core/frontmatter.js.map +1 -0
  64. package/dist/core/listing-redact.d.ts +37 -0
  65. package/dist/core/listing-redact.js +88 -0
  66. package/dist/core/listing-redact.js.map +1 -0
  67. package/dist/core/match.d.ts +26 -0
  68. package/dist/core/match.js +75 -0
  69. package/dist/core/match.js.map +1 -0
  70. package/dist/core/message-readers.d.ts +84 -0
  71. package/dist/core/message-readers.js +159 -0
  72. package/dist/core/message-readers.js.map +1 -0
  73. package/dist/core/messages.d.ts +49 -0
  74. package/dist/core/messages.js +85 -0
  75. package/dist/core/messages.js.map +1 -0
  76. package/dist/core/mount-prompt.d.ts +28 -0
  77. package/dist/core/mount-prompt.js +55 -0
  78. package/dist/core/mount-prompt.js.map +1 -0
  79. package/dist/core/mount-redact.d.ts +28 -0
  80. package/dist/core/mount-redact.js +32 -0
  81. package/dist/core/mount-redact.js.map +1 -0
  82. package/dist/core/mounts.d.ts +88 -0
  83. package/dist/core/mounts.js +147 -0
  84. package/dist/core/mounts.js.map +1 -0
  85. package/dist/core/path-mapping.d.ts +52 -0
  86. package/dist/core/path-mapping.js +113 -0
  87. package/dist/core/path-mapping.js.map +1 -0
  88. package/dist/core/platform-prompt.generated.d.ts +2 -0
  89. package/dist/core/platform-prompt.generated.js +4 -0
  90. package/dist/core/platform-prompt.generated.js.map +1 -0
  91. package/dist/core/prompt.d.ts +42 -0
  92. package/dist/core/prompt.js +75 -0
  93. package/dist/core/prompt.js.map +1 -0
  94. package/dist/core/session-id.d.ts +38 -0
  95. package/dist/core/session-id.js +61 -0
  96. package/dist/core/session-id.js.map +1 -0
  97. package/dist/core/session-store.d.ts +85 -0
  98. package/dist/core/session-store.js +149 -0
  99. package/dist/core/session-store.js.map +1 -0
  100. package/dist/core/session-zone.d.ts +54 -0
  101. package/dist/core/session-zone.js +82 -0
  102. package/dist/core/session-zone.js.map +1 -0
  103. package/dist/core/skill-prompt.d.ts +31 -0
  104. package/dist/core/skill-prompt.js +54 -0
  105. package/dist/core/skill-prompt.js.map +1 -0
  106. package/dist/core/skill-redact.d.ts +15 -0
  107. package/dist/core/skill-redact.js +27 -0
  108. package/dist/core/skill-redact.js.map +1 -0
  109. package/dist/core/skills.d.ts +172 -0
  110. package/dist/core/skills.js +214 -0
  111. package/dist/core/skills.js.map +1 -0
  112. package/dist/core/tool-mocks.d.ts +23 -0
  113. package/dist/core/tool-mocks.js +39 -0
  114. package/dist/core/tool-mocks.js.map +1 -0
  115. package/dist/core/tool-telemetry.d.ts +16 -0
  116. package/dist/core/tool-telemetry.js +40 -0
  117. package/dist/core/tool-telemetry.js.map +1 -0
  118. package/dist/core/usage.d.ts +114 -0
  119. package/dist/core/usage.js +226 -0
  120. package/dist/core/usage.js.map +1 -0
  121. package/dist/core/workspace-context.d.ts +136 -0
  122. package/dist/core/workspace-context.js +178 -0
  123. package/dist/core/workspace-context.js.map +1 -0
  124. package/dist/core/workspace-prompt.d.ts +7 -0
  125. package/dist/core/workspace-prompt.js +102 -0
  126. package/dist/core/workspace-prompt.js.map +1 -0
  127. package/dist/core/workspace-router.d.ts +61 -0
  128. package/dist/core/workspace-router.js +145 -0
  129. package/dist/core/workspace-router.js.map +1 -0
  130. package/dist/core/workspace.d.ts +85 -0
  131. package/dist/core/workspace.js +193 -0
  132. package/dist/core/workspace.js.map +1 -0
  133. package/dist/core/zones.d.ts +181 -0
  134. package/dist/core/zones.js +202 -0
  135. package/dist/core/zones.js.map +1 -0
  136. package/dist/env.d.ts +99 -0
  137. package/dist/env.js +271 -0
  138. package/dist/env.js.map +1 -0
  139. package/dist/index.d.ts +265 -0
  140. package/dist/index.js +197 -0
  141. package/dist/index.js.map +1 -0
  142. package/dist/kernel/kernel.d.ts +192 -0
  143. package/dist/kernel/kernel.js +751 -0
  144. package/dist/kernel/kernel.js.map +1 -0
  145. package/dist/lifecycle/hook-shape.d.ts +44 -0
  146. package/dist/lifecycle/hook-shape.js +66 -0
  147. package/dist/lifecycle/hook-shape.js.map +1 -0
  148. package/dist/lifecycle/runner.d.ts +177 -0
  149. package/dist/lifecycle/runner.js +372 -0
  150. package/dist/lifecycle/runner.js.map +1 -0
  151. package/dist/lifecycle/transcript.d.ts +27 -0
  152. package/dist/lifecycle/transcript.js +43 -0
  153. package/dist/lifecycle/transcript.js.map +1 -0
  154. package/dist/machine/allow.d.ts +65 -0
  155. package/dist/machine/allow.js +107 -0
  156. package/dist/machine/allow.js.map +1 -0
  157. package/dist/machine/delegation.d.ts +9 -0
  158. package/dist/machine/delegation.js +10 -0
  159. package/dist/machine/delegation.js.map +1 -0
  160. package/dist/machine/diagnostic.d.ts +14 -0
  161. package/dist/machine/diagnostic.js +2 -0
  162. package/dist/machine/diagnostic.js.map +1 -0
  163. package/dist/machine/lint-spec.d.ts +4 -0
  164. package/dist/machine/lint-spec.js +266 -0
  165. package/dist/machine/lint-spec.js.map +1 -0
  166. package/dist/machine/load-spec.d.ts +90 -0
  167. package/dist/machine/load-spec.js +120 -0
  168. package/dist/machine/load-spec.js.map +1 -0
  169. package/dist/machine/machine.d.ts +273 -0
  170. package/dist/machine/machine.js +551 -0
  171. package/dist/machine/machine.js.map +1 -0
  172. package/dist/machine/mount-grants.d.ts +25 -0
  173. package/dist/machine/mount-grants.js +24 -0
  174. package/dist/machine/mount-grants.js.map +1 -0
  175. package/dist/machine/slug.d.ts +14 -0
  176. package/dist/machine/slug.js +17 -0
  177. package/dist/machine/slug.js.map +1 -0
  178. package/dist/machine/spec-schema.d.ts +662 -0
  179. package/dist/machine/spec-schema.js +717 -0
  180. package/dist/machine/spec-schema.js.map +1 -0
  181. package/dist/machine/tool-names.d.ts +98 -0
  182. package/dist/machine/tool-names.js +144 -0
  183. package/dist/machine/tool-names.js.map +1 -0
  184. package/dist/machine/triggers.d.ts +114 -0
  185. package/dist/machine/triggers.js +165 -0
  186. package/dist/machine/triggers.js.map +1 -0
  187. package/dist/machine/types.d.ts +186 -0
  188. package/dist/machine/types.js +12 -0
  189. package/dist/machine/types.js.map +1 -0
  190. package/dist/machine/validate-spec.d.ts +42 -0
  191. package/dist/machine/validate-spec.js +29 -0
  192. package/dist/machine/validate-spec.js.map +1 -0
  193. package/dist/machine/variables.d.ts +196 -0
  194. package/dist/machine/variables.js +415 -0
  195. package/dist/machine/variables.js.map +1 -0
  196. package/dist/public/cli.d.ts +15 -0
  197. package/dist/public/cli.js +14 -0
  198. package/dist/public/cli.js.map +1 -0
  199. package/dist/public/messages.d.ts +33 -0
  200. package/dist/public/messages.js +33 -0
  201. package/dist/public/messages.js.map +1 -0
  202. package/dist/public/sandbox.d.ts +99 -0
  203. package/dist/public/sandbox.js +32 -0
  204. package/dist/public/sandbox.js.map +1 -0
  205. package/dist/public/spec.d.ts +147 -0
  206. package/dist/public/spec.js +149 -0
  207. package/dist/public/spec.js.map +1 -0
  208. package/dist/public/testing.d.ts +71 -0
  209. package/dist/public/testing.js +39 -0
  210. package/dist/public/testing.js.map +1 -0
  211. package/dist/rubrics/rubrics.d.ts +135 -0
  212. package/dist/rubrics/rubrics.js +145 -0
  213. package/dist/rubrics/rubrics.js.map +1 -0
  214. package/dist/runtime/contract.d.ts +73 -0
  215. package/dist/runtime/contract.js +96 -0
  216. package/dist/runtime/contract.js.map +1 -0
  217. package/dist/sandbox/assets/parts/core.js +22 -0
  218. package/dist/sandbox/assets/parts/lifecycle-hook.js +47 -0
  219. package/dist/sandbox/bridge.d.ts +16 -0
  220. package/dist/sandbox/bridge.js +95 -0
  221. package/dist/sandbox/bridge.js.map +1 -0
  222. package/dist/sandbox/executor.d.ts +46 -0
  223. package/dist/sandbox/executor.js +119 -0
  224. package/dist/sandbox/executor.js.map +1 -0
  225. package/dist/sandbox/imports.d.ts +33 -0
  226. package/dist/sandbox/imports.js +67 -0
  227. package/dist/sandbox/imports.js.map +1 -0
  228. package/dist/sandbox/prelude.d.ts +12 -0
  229. package/dist/sandbox/prelude.js +51 -0
  230. package/dist/sandbox/prelude.js.map +1 -0
  231. package/dist/sandbox/ptc-gateway.d.ts +104 -0
  232. package/dist/sandbox/ptc-gateway.js +167 -0
  233. package/dist/sandbox/ptc-gateway.js.map +1 -0
  234. package/dist/sandbox/runtime.d.ts +59 -0
  235. package/dist/sandbox/runtime.js +51 -0
  236. package/dist/sandbox/runtime.js.map +1 -0
  237. package/dist/sandbox/tools.d.ts +34 -0
  238. package/dist/sandbox/tools.js +147 -0
  239. package/dist/sandbox/tools.js.map +1 -0
  240. package/dist/sessions/operations.d.ts +79 -0
  241. package/dist/sessions/operations.js +121 -0
  242. package/dist/sessions/operations.js.map +1 -0
  243. package/dist/sessions/resolve.d.ts +97 -0
  244. package/dist/sessions/resolve.js +145 -0
  245. package/dist/sessions/resolve.js.map +1 -0
  246. package/dist/sessions/resume.d.ts +242 -0
  247. package/dist/sessions/resume.js +288 -0
  248. package/dist/sessions/resume.js.map +1 -0
  249. package/dist/sessions/scope.d.ts +99 -0
  250. package/dist/sessions/scope.js +145 -0
  251. package/dist/sessions/scope.js.map +1 -0
  252. package/dist/sessions/summary.d.ts +65 -0
  253. package/dist/sessions/summary.js +56 -0
  254. package/dist/sessions/summary.js.map +1 -0
  255. package/dist/testing/assertions.d.ts +30 -0
  256. package/dist/testing/assertions.js +231 -0
  257. package/dist/testing/assertions.js.map +1 -0
  258. package/dist/testing/case-document.d.ts +141 -0
  259. package/dist/testing/case-document.js +51 -0
  260. package/dist/testing/case-document.js.map +1 -0
  261. package/dist/testing/case-schema.d.ts +29 -0
  262. package/dist/testing/case-schema.js +519 -0
  263. package/dist/testing/case-schema.js.map +1 -0
  264. package/dist/testing/discovery.d.ts +10 -0
  265. package/dist/testing/discovery.js +24 -0
  266. package/dist/testing/discovery.js.map +1 -0
  267. package/dist/testing/driver.d.ts +78 -0
  268. package/dist/testing/driver.js +117 -0
  269. package/dist/testing/driver.js.map +1 -0
  270. package/dist/testing/grade.d.ts +116 -0
  271. package/dist/testing/grade.js +261 -0
  272. package/dist/testing/grade.js.map +1 -0
  273. package/dist/testing/interpreter.d.ts +55 -0
  274. package/dist/testing/interpreter.js +103 -0
  275. package/dist/testing/interpreter.js.map +1 -0
  276. package/dist/testing/mock-middleware.d.ts +5 -0
  277. package/dist/testing/mock-middleware.js +33 -0
  278. package/dist/testing/mock-middleware.js.map +1 -0
  279. package/dist/testing/runner.d.ts +205 -0
  280. package/dist/testing/runner.js +266 -0
  281. package/dist/testing/runner.js.map +1 -0
  282. package/dist/testing/target.d.ts +27 -0
  283. package/dist/testing/target.js +21 -0
  284. package/dist/testing/target.js.map +1 -0
  285. package/dist/validate/validate.d.ts +41 -0
  286. package/dist/validate/validate.js +669 -0
  287. package/dist/validate/validate.js.map +1 -0
  288. package/dist/workflow/agent-tools.d.ts +10 -0
  289. package/dist/workflow/agent-tools.js +10 -0
  290. package/dist/workflow/agent-tools.js.map +1 -0
  291. package/dist/workflow/checkpointer.d.ts +52 -0
  292. package/dist/workflow/checkpointer.js +200 -0
  293. package/dist/workflow/checkpointer.js.map +1 -0
  294. package/dist/workflow/control-tools.d.ts +174 -0
  295. package/dist/workflow/control-tools.js +468 -0
  296. package/dist/workflow/control-tools.js.map +1 -0
  297. package/dist/workflow/governance.d.ts +104 -0
  298. package/dist/workflow/governance.js +546 -0
  299. package/dist/workflow/governance.js.map +1 -0
  300. package/dist/workflow/middleware.d.ts +85 -0
  301. package/dist/workflow/middleware.js +283 -0
  302. package/dist/workflow/middleware.js.map +1 -0
  303. package/dist/workflow/on-error.d.ts +25 -0
  304. package/dist/workflow/on-error.js +58 -0
  305. package/dist/workflow/on-error.js.map +1 -0
  306. package/dist/workflow/parks.d.ts +46 -0
  307. package/dist/workflow/parks.js +513 -0
  308. package/dist/workflow/parks.js.map +1 -0
  309. package/dist/workflow/paths.d.ts +67 -0
  310. package/dist/workflow/paths.js +108 -0
  311. package/dist/workflow/paths.js.map +1 -0
  312. package/dist/workflow/prompt-cache.d.ts +70 -0
  313. package/dist/workflow/prompt-cache.js +103 -0
  314. package/dist/workflow/prompt-cache.js.map +1 -0
  315. package/dist/workflow/prompt-pruning.d.ts +20 -0
  316. package/dist/workflow/prompt-pruning.js +83 -0
  317. package/dist/workflow/prompt-pruning.js.map +1 -0
  318. package/dist/workflow/render-prompt.d.ts +45 -0
  319. package/dist/workflow/render-prompt.js +140 -0
  320. package/dist/workflow/render-prompt.js.map +1 -0
  321. package/dist/workflow/runtime-config.d.ts +7 -0
  322. package/dist/workflow/runtime-config.js +9 -0
  323. package/dist/workflow/runtime-config.js.map +1 -0
  324. package/dist/workflow/session-artifacts.d.ts +90 -0
  325. package/dist/workflow/session-artifacts.js +134 -0
  326. package/dist/workflow/session-artifacts.js.map +1 -0
  327. package/dist/workflow/session-view.d.ts +31 -0
  328. package/dist/workflow/session-view.js +94 -0
  329. package/dist/workflow/session-view.js.map +1 -0
  330. package/dist/workflow/snapshot.d.ts +14 -0
  331. package/dist/workflow/snapshot.js +97 -0
  332. package/dist/workflow/snapshot.js.map +1 -0
  333. package/dist/workflow/state.d.ts +347 -0
  334. package/dist/workflow/state.js +322 -0
  335. package/dist/workflow/state.js.map +1 -0
  336. package/dist/workflow/sub-workflow.d.ts +174 -0
  337. package/dist/workflow/sub-workflow.js +392 -0
  338. package/dist/workflow/sub-workflow.js.map +1 -0
  339. package/dist/workflow/tool-service.d.ts +48 -0
  340. package/dist/workflow/tool-service.js +291 -0
  341. package/dist/workflow/tool-service.js.map +1 -0
  342. package/dist/workflow/turn-boundary.d.ts +39 -0
  343. package/dist/workflow/turn-boundary.js +128 -0
  344. package/dist/workflow/turn-boundary.js.map +1 -0
  345. package/dist/workflow/turn-runner.d.ts +40 -0
  346. package/dist/workflow/turn-runner.js +122 -0
  347. package/dist/workflow/turn-runner.js.map +1 -0
  348. package/dist/workflow/workflow-tools.d.ts +46 -0
  349. package/dist/workflow/workflow-tools.js +90 -0
  350. package/dist/workflow/workflow-tools.js.map +1 -0
  351. package/package.json +119 -0
@@ -0,0 +1,1631 @@
1
+ # workflow.yaml — exhaustive schema reference
2
+
3
+ The complete, field-by-field reference for authoring a `workflow.yaml` (and its
4
+ optional `WORKFLOW.md` prose addendum) plus the surrounding workspace. Targets
5
+ **runtime contract version `"2"`**.
6
+
7
+ ## Contents
8
+
9
+ - [File shape](#file-shape)
10
+ - [Root fields](#root-fields)
11
+ - [States (`MachineState`)](#states-machinestate)
12
+ - [Transitions](#transitions)
13
+ - [Tool governance](#tool-governance)
14
+ - [Skill governance](#skill-governance)
15
+ - [Mount governance](#mount-governance)
16
+ - [Lifecycle hooks](#lifecycle-hooks)
17
+ — full script contract + worked examples in
18
+ [`hook-and-test-scripts.md`](hook-and-test-scripts.md)
19
+ - [Budgets & error routing](#budgets--error-routing)
20
+ - [Human states](#human-states)
21
+ - [Sub-workflows are tools](#sub-workflows-are-tools)
22
+ - [Removed keys you may meet in an older workflow](#removed-keys-you-may-meet-in-an-older-workflow)
23
+ - [Workspace layout: skills, scripts](#workspace-layout)
24
+ - [Cases](#cases)
25
+ - [Code description docblocks](#code-description-docblocks)
26
+ - [Read-only zones](#read-only-zones)
27
+ - [Annotated example: order-lookup](#annotated-example-order-lookup)
28
+
29
+ ---
30
+
31
+ ## File shape
32
+
33
+ **Two-file layout** under `workflows/<name>/`:
34
+
35
+ - **`workflow.yaml`** — the canonical, enforced machine spec: a **pure YAML
36
+ mapping** (no `---` frontmatter fences, no markdown). Parsed with YAML 1.2
37
+ semantics and validated against the schema. Top-level keys: `title`,
38
+ `instructions`, `runtime`, `settings`, `tests`, `tools`, `skills`, `mounts`,
39
+ `extensions`, `editor`, `states`.
40
+ - **`WORKFLOW.md`** (optional, beside it) — a plain-markdown prose addendum with
41
+ **no frontmatter**. A frontmatter block in `WORKFLOW.md` when `workflow.yaml`
42
+ exists is a **validation error**. The runtime renders the system prompt's
43
+ workflow header deterministically from the spec (`title` + `instructions`, and
44
+ NO state of the graph) and appends the `WORKFLOW.md` prose after it — prose is
45
+ never load-bearing and cannot disagree with enforcement. The graph is disclosed
46
+ per model call, for the ACTIVE STATE ONLY.
47
+ There is no "frontmatter wins" rule anymore; `workflow.yaml` is the only
48
+ authority.
49
+
50
+ **Removed**: the single-file `WORKFLOW.md` layout (YAML frontmatter + markdown
51
+ body, without a `workflow.yaml`) no longer loads — it is a load error. Migrate by
52
+ moving the frontmatter into `workflow.yaml` and stripping the fences from the
53
+ prose.
54
+
55
+ ## Root fields
56
+
57
+ ```yaml
58
+ title?: string # the workflow's HUMAN-READABLE name (metadata only).
59
+ # Identity is the WORKFLOW SLUG — the directory name
60
+ # (`workflows/<slug>/`, also the CLI argument), authored
61
+ # in the SAME kebab-case as state slugs
62
+ # (`order-lookup`); validate ERRORS on a missing or
63
+ # non-kebab workflow slug, exactly as for a state slug.
64
+ # A top-level `name:` is REMOVED — it is
65
+ # a load/validate ERROR; rename it to `title:`.
66
+ instructions?: string # the workflow's STANDING instructions — free-form
67
+ # markdown, direction that holds for the WHOLE run
68
+ # (conventions, house rules, what "done" means).
69
+ # Author it as a LITERAL block (`|-`), not folded
70
+ # (`>-`): it renders as markdown, and folding
71
+ # collapses blank lines into one run-on paragraph.
72
+ # Rendered verbatim as an `## Instructions` block at
73
+ # the top of the workflow prompt section (unlike a
74
+ # state's `instructions`, which are per model call) —
75
+ # so it lands in the static,
76
+ # cacheable prefix. validate WARNS when absent,
77
+ # ERRORS when present but not a non-empty string.
78
+ # A top-level `description:` is REMOVED and now
79
+ # simply ignored; use `instructions:`, rereading the
80
+ # text as direction, not narration.
81
+ # A test case's `description` is UNAFFECTED. A
82
+ # TRANSITION's `description` is now REQUIRED and
83
+ # non-empty (see `transitions` below).
84
+
85
+ disabled?: boolean # `true` = this machine STARTS NO NEW TURNS. Bounds
86
+ # STARTING, not finishing.
87
+ # REFUSES: `archmax run` (one line, non-zero exit, no
88
+ # session minted); a host `invoke`; a firing on a fresh
89
+ # session; a FOLLOW-UP message to a settled session
90
+ # (a new turn is new work) — all rejected AT THE TURN
91
+ # BOUNDARY with `status: rejected` and
92
+ # "Refusing to start: workflow '<slug>' is disabled.",
93
+ # before any state, hook or model call; and a caller's
94
+ # `archmax_workflow_<slug>` call (blocked call, refusal
95
+ # kind `disabled`, before a child is composed — it also
96
+ # beats a declared MOCK, so a case can never assert a
97
+ # delegation production would refuse).
98
+ # STILL WORKS: assembly; `decide` / `reply` / `deliver`
99
+ # (each resumes an unfinished turn, so parked human
100
+ # decisions are never trapped); `archmax validate` (full,
101
+ # plus a warning); and a CALLER's assembly — the tool is
102
+ # still bound, so disabling one leaf never takes its
103
+ # callers offline (validate WARNS on each state that
104
+ # allows a disabled target).
105
+ # `archmax test` SKIPS the suite and exits 0 — not run is
106
+ # not failed. There is NO flag to force cases to run.
107
+ # Read FAIL-CLOSED: anything but an absent key, `null` or
108
+ # boolean `false` disables the workflow, so `disabled:
109
+ # "no"` STOPS runs; validate ERRORS on a non-boolean.
110
+ # NOT a kill switch for work in flight, and NOT a
111
+ # per-state/per-trigger switch (that is a forbid list).
112
+
113
+ runtime?:
114
+ engine?: string # "archmax-harness"
115
+ version?: string | number # target contract — use "2"
116
+
117
+ settings?:
118
+ model?: string # MODEL ID ONLY — the id every state of this workflow runs
119
+ # on, over the endpoint/credentials the assembly already
120
+ # has. Overrides ARCHMAX_MODEL; a state's `model` overrides
121
+ # it. NOT a block: `{ id, temperature }` is a load error —
122
+ # sampling and endpoint are env/host configuration.
123
+ # Opaque: nothing validates the id against a list.
124
+ # Does NOT change the case grader (tests.judge.model).
125
+ timeoutMs?: number # default 15000; per eval/lifecycle script (sandbox budget)
126
+ memoryLimitBytes?: number
127
+ maxPtcCalls?: number | null
128
+ maxResultChars?: number
129
+ prompt_cache?:
130
+ enabled?: boolean # default true (provider prompt caching)
131
+ ttl?: "5m" | "1h" # default "5m"
132
+
133
+ tests?: # cases suite config (declarative data;
134
+ # tests.config.js is REMOVED — see Cases)
135
+ maxConcurrency?: number # only 1 (or absent) accepted — concurrency is
136
+ # not implemented; >1 is a validate error and
137
+ # fails `archmax test` loudly
138
+ caseTimeoutMs?: number # per-case WALL-CLOCK budget, default 120000 —
139
+ # deliberately named differently from
140
+ # settings.timeoutMs (per-script sandbox budget)
141
+ judge?: # {} = enable the grader with the
142
+ model?: string # env-configured default model
143
+ modelOptions?: { temperature?: number, maxTokens?: number }
144
+ # applied over the env model config, via the
145
+ # factory's `judge` role; other keys are errors
146
+
147
+ tools?:
148
+ allow_always?: AllowEntry[] # grants added to every state's allowlist
149
+ forbid_always?: ForbidEntry[]
150
+ # DENIED in EVERY state, and absolute: nothing reaches
151
+ # past it — no state grant, allow_always entry,
152
+ # argument guard or consumer rule. Same entry
153
+ # grammar as allow, plus the tool "*" meaning
154
+ # EVERY tool: { tool: "*", paths: ["logs/**"] }
155
+ # denies that path to everything. "*" in an
156
+ # ALLOW list is a load error.
157
+ # Guards narrow what is denied; globs match
158
+ # dotfiles (secrets/** covers secrets/.env).
159
+ # Inherited by every sub-workflow, naming the
160
+ # workflow that declared it. There is NO
161
+ # `policy:` block — writing one is a load error.
162
+
163
+ skills?:
164
+ allow_always?: string[] # SKILL SLUGS enabled in EVERY state of this workflow —
165
+ # the bundle directory names under skills/, kebab-case.
166
+ # NEVER paths, NEVER globs: the unit you govern is the
167
+ # capability. This is the skills half of
168
+ # tools.allow_always: a GRANT, which a state's own
169
+ # `skills.allow` ADDS to (the enabled set is the UNION),
170
+ # so no state repeats it and no state can subtract from
171
+ # it. ABSENT = none granted workflow-wide, exactly like
172
+ # `allow_always: []` — write the empty list when every
173
+ # capability here is state-specific.
174
+ # validate ERRORS on: a slug no source provides (it
175
+ # lists the known ones), a path/glob/non-string entry,
176
+ # a bundle whose SKILL.md `name:` ≠ its directory; and
177
+ # WARNS on a state entry this list already grants
178
+ # everywhere, and on a state's `allow: []` beside it
179
+ # (an empty state list subtracts nothing).
180
+ forbid_always?: string[] # SKILL SLUGS out of reach of EVERY state, whatever any
181
+ # list grants. Deny beats allow. (The retired root
182
+ # `allow` ceiling is a load error: one skills model.)
183
+
184
+ mounts?:
185
+ allow_always?: MountGrant[] # MOUNT NAMES reachable in EVERY state of this workflow —
186
+ # the keys of the HOST's mount table with their slashes
187
+ # stripped (`reference`, `catalogs/eu`, `AGENTS.md`).
188
+ # NEVER globs: scope paths WITHIN a reachable mount with
189
+ # a tools.allow entry. Only a mount the host declared
190
+ # `governed: true` needs a grant — an UNGOVERNED mount is
191
+ # visible in every state already, and a grant naming one
192
+ # is inert (validate warns). The skills model exactly: a
193
+ # GRANT a state's `mounts.allow` ADDS to (the reachable
194
+ # set is the UNION), never a ceiling. ABSENT = this
195
+ # workflow reaches no governed mount; validate says so
196
+ # ONCE, naming them — write `allow_always: []` to mean it.
197
+ # An entry is a NAME, or `{ mount: <name>, access: read |
198
+ # read_write }` to say what this level gives. The host's
199
+ # readOnly is a CEILING: `read_write` on a read-only mount
200
+ # opens nothing (validate warns); `read` NARROWS a
201
+ # writable one, and no narrower level widens it back.
202
+ # validate ERRORS on a name the table does not mount.
203
+ forbid_always?: string[] # MOUNT NAMES out of reach of EVERY state, governed or
204
+ # not, whatever any list grants. Deny beats allow.
205
+ # Inherited by every sub-workflow, naming the workflow
206
+ # that declared it. A NAME only — a denial is total, so
207
+ # there is no `access` to qualify. (A root `mounts.allow`
208
+ # is a load error: one mounts model.)
209
+
210
+ extensions?:
211
+ hooks?: string[] # custom hook kinds (beyond script/rubric) the
212
+ # runtime registers executors for; undeclared
213
+ # unknown hook kinds are validation errors
214
+
215
+ editor?: Record<string, unknown> # HOST PRESENTATION METADATA — an authoring
216
+ # UI's own state (canvas state positions keyed by
217
+ # slug, edge routing). The one key the runtime
218
+ # never reads: not shape-checked, not prompted,
219
+ # not governed, and excluded from the spec hash.
220
+ # Do NOT author it by hand and do NOT invent a
221
+ # use for it — but PRESERVE it verbatim when you
222
+ # rewrite a spec that already carries one, or the
223
+ # builder that wrote it loses every state position.
224
+ # The root is otherwise STRICT: any other
225
+ # unrecognized key is a load error.
226
+
227
+ states: Record<slug, MachineState> # REQUIRED; ≥1 state, ≥1 with a trigger
228
+ # the KEY is the state's SLUG (see below)
229
+ ```
230
+
231
+ ## States (`MachineState`)
232
+
233
+ Each key under `states` is the state's **slug**: its identity, and the only thing
234
+ that resolves it — `transitions[].to`, `on_error`, the `to` the agent passes to
235
+ `archmax_advance`, emitted events, session artifacts, and cases
236
+ `reachedState` assertions are all slugs. Author slugs as **hyphen-separated kebab-case** — lowercase alphanumeric
237
+ segments joined by single hyphens (`^[a-z0-9]+(-[a-z0-9]+)*$`, e.g.
238
+ `identify-case`, `report-requested`); no underscores, capitals, doubled hyphens,
239
+ or leading/trailing hyphens —
240
+ `validate` reports a nonconforming slug — or a state declared under an empty key,
241
+ which has no identity at all — as an **error**. A slug is a reference target, so
242
+ rename one only deliberately, and update every reference to it.
243
+
244
+ ```yaml
245
+ states:
246
+ <state-slug>:
247
+ requires?: [string] # RUN VARIABLES this state must have set before it can
248
+ # be left: archmax_advance out of it is refused,
249
+ # recoverably, while any is unset. Variables are not
250
+ # declared anywhere, so this list — together with a
251
+ # TRIGGER's `requires` (see below) — is
252
+ # the only spec-visible statement that a variable will
253
+ # exist, which is what makes a ${{name}} guard
254
+ # reference GUARANTEED rather than dependent on agent
255
+ # behavior. Name here anything a downstream guard
256
+ # reads.
257
+ title?: string # HUMAN-READABLE label. Presentational only: carried
258
+ # in a human state's pending-decision record and shown
259
+ # in host surfaces. REACHES NO MODEL CALL. Never a
260
+ # routing target — `to` always takes a slug — so
261
+ # rewording it changes no behavior. Not unique.
262
+ # NOT a substitute for `instructions` (behavior
263
+ # guidance) or a transition `description` (routing).
264
+
265
+ type?: "agent" | "human"
266
+ # default "agent". "human" = a person routes.
267
+ # (`workflow` was removed: a state CALLS another
268
+ # workflow by allowing `archmax_workflow_<slug>`.)
269
+
270
+
271
+ triggers?: Record<triggerId, TriggerDeclaration | null>
272
+ # marks a start state. The KEY is the trigger id
273
+ # and THIS state is that trigger's entry state —
274
+ # the one place a trigger is declared.
275
+ # manual: = CLI/Deep-Agent entry
276
+ # (prompt = input)
277
+ # <other id>: = tool/event trigger
278
+ # a null/empty value = the id and nothing more
279
+ # SEVERAL keys = the state is the entry for EVERY
280
+ # id, in declaration order (one state, one
281
+ # behavior, several ways in).
282
+ # The value is the declaration (see below):
283
+ # session/message/connection/requires/returns
284
+ # plus any key the HOST adds — preserved,
285
+ # lint-warned, never interpreted.
286
+ # NO `entry:` and NO `name:` inside a declaration:
287
+ # the state it sits on IS the entry and the key
288
+ # it sits under IS the id. Either one fails load
289
+ # naming the key. There is also no root
290
+ # `triggers:` block.
291
+ # An id is AUTHORED, so deleting or reordering a
292
+ # sibling never moves it — hosts key deployments
293
+ # on that id.
294
+ # two states declaring the same trigger id is a
295
+ # validation ERROR (start states must be
296
+ # unambiguous). A trigger has ONE entry state; a
297
+ # mapping with several keys is several triggers
298
+ # entering one state. A repeated id on one state
299
+ # is impossible — YAML mappings cannot repeat a key.
300
+ # A shared entry state has ONE behavior: branch on
301
+ # `${{trigger}}` / `args.trigger` where the paths
302
+ # differ, or use separate states.
303
+
304
+ summary?: string # ONE-LINE label for AUTHORS AND HOSTS (an editor's
305
+ # node caption, a generated diagram). RENDERED INTO
306
+ # NO PART OF THE PROMPT — the model never reads it,
307
+ # so it is free, and it can NOT carry routing logic.
308
+ # The routing text the agent reads is the SOURCE
309
+ # state's transition `description`s; nothing about a
310
+ # target state is disclosed at all.
311
+
312
+ instructions?: string # behavior guidance.
313
+ # agent node: surfaced to the LLM while active.
314
+ # Write the state's behavior INLINE here; a
315
+ # skill bundle (skills/<slug>/) is a capability
316
+ # with data or scripts, enabled by slug — not a
317
+ # per-state instruction sheet.
318
+ # human state: describes the decision for the packet
319
+
320
+ before?: HookSpec # gate ENTRY to this state (fail-closed)
321
+ after?: HookSpec # gate the archmax_advance OUT (or run at completion
322
+ # for a terminal state)
323
+
324
+ tools?:
325
+ allow?: AllowEntry[] # grants beyond the always-on tools (plus
326
+ # allow_always grants and the always-allowed
327
+ # archmax_advance); an entry naming
328
+ # an always-on tool NARROWS it.
329
+ forbid?: ForbidEntry[] # what this state DENIES while active — beating the
330
+ # workflow's allow_always, this state's own allow,
331
+ # and the always-on surface alike. Deny beats allow.
332
+ # Not inherited by a sub-workflow; a lifecycle hook
333
+ # is exempt from it (runtime authority).
334
+
335
+ skills?:
336
+ allow?: string[] # which CAPABILITIES this state ADDS, by SLUG — on top
337
+ # of the root's `skills.allow_always`, which is enabled
338
+ # here whatever this says. ABSENT = adds none, the same
339
+ # as `allow: []`. An empty list is NOT a deny (validate
340
+ # warns about one that reads like it) — `forbid` is.
341
+ forbid?: string[] # SLUGS this state does NOT get, subtracting from the
342
+ # workflow's allow_always and from its own allow.
343
+ # Refused as `skill.forbidden` (vs `skill.not-allowed`
344
+ # where nothing granted it).
345
+ # Enabling a slug is a GRANT: skills/<slug>/** becomes
346
+ # readable and its scripts runnable with NO tools.allow
347
+ # path entry. Not enabling one makes the bundle
348
+ # unreachable (read/ls/glob/grep/archmax_run all
349
+ # blocked, rule `skill.not-allowed`, above every
350
+ # declaration) AND undisclosed — its slug and
351
+ # description never enter this state's prompt, and a
352
+ # listing of skills/ does not show it.
353
+ # A tools.allow entry still NARROWS within the enabled
354
+ # set: the two compose as enabled AND allowed.
355
+ # Lifecycle HOOKS are exempt — a `before` hook reading
356
+ # skills/order-data/assets/orders.json still works in a
357
+ # state that enables nothing, so you can gate the
358
+ # agent's use of a capability while keeping the hook
359
+ # that enforces it.
360
+
361
+ mounts?:
362
+ allow?: MountGrant[] # which MOUNTS this state ADDS, by NAME — on top of the
363
+ # root's `mounts.allow_always`, which is reachable here
364
+ # whatever this says. ABSENT = adds none, the same as
365
+ # `allow: []`. An empty list is NOT a deny (validate
366
+ # warns about one that reads like it) — `forbid` is.
367
+ # An entry may name its access:
368
+ # allow: [{ mount: shared, access: read }]
369
+ # reads a writable mount without writing it here. The
370
+ # host's posture is the ceiling — `read_write` cannot
371
+ # open a read-only mount — and a `read` at either level
372
+ # holds, so a state never widens what the workflow
373
+ # narrowed. A write refused by THIS key is
374
+ # `mount.read-only`; one refused by the WIRING is
375
+ # `zone.read-only`.
376
+ forbid?: string[] # MOUNT NAMES this state does NOT get, subtracting from
377
+ # the workflow's allow_always, from its own allow, and
378
+ # from an UNGOVERNED mount's standing visibility alike.
379
+ # Refused as `mount.forbidden` (vs `mount.not-allowed`
380
+ # where nothing enabled it).
381
+ # A governed mount this state does not have is
382
+ # unreachable (read/ls/glob/grep all blocked, above
383
+ # every declaration) AND undisclosed — absent from the
384
+ # volatile prompt block, and filtered out of every
385
+ # ls/glob/grep result, the WORKSPACE ROOT LISTING
386
+ # included. Lifecycle HOOKS are exempt from this key
387
+ # (runtime authority), but not from `forbid_always`.
388
+
389
+ model?: string # MODEL ID ONLY — this state's turns run on it (and the
390
+ # handoff message of a park it holds). Most specific of
391
+ # state.model > settings.model > the assembly's default
392
+ # (createAgent `model`/`modelFactory`, else ARCHMAX_MODEL).
393
+ # Same id as settings.model ⇒ validate WARNS (inert).
394
+ # A rubric keeps its own `model`; a sub-workflow resolves
395
+ # its OWN spec's ids — nothing is inherited across it.
396
+ # A host passing an explicit `model` INSTANCE to
397
+ # createAgent outranks every declared id (one assembly
398
+ # warning names them); `modelFactory` is what honours one.
399
+
400
+ budget?: # per-state execution budget
401
+ maxTurns?: number # bounds this turn's agent loop
402
+ timeoutMs?: number # aborts the turn when exceeded
403
+ on_error?: string # state to route to on a TERMINAL failure
404
+ # (see Budgets & error routing)
405
+
406
+ transitions?: Transition[] # outgoing edges. EMPTY/absent ⇒ terminal state.
407
+ # `parallel:`/`join:` are REMOVED — a run traverses
408
+ # one state at a time; sequence what were branches.
409
+ #
410
+ # Transition = {
411
+ # to: string # a declared state's SLUG
412
+ # description: string # REQUIRED, non-empty
413
+ # type?: "approve" | "reject" | "refine" | "none"
414
+ # }
415
+ #
416
+ # THE AGENT SEES THIS STATE'S EDGES AND NOTHING
417
+ # ELSE OF THE GRAPH — no other state's slug, title,
418
+ # summary, hooks or transitions, and no count of
419
+ # the states. So `description` is the whole of what
420
+ # it knows about where an edge leads, and a missing
421
+ # or blank one is a LOAD ERROR naming
422
+ # states.<slug>.transitions.<i>.description.
423
+ #
424
+ # Write it for a reader standing in THIS state,
425
+ # which knows nothing about the target:
426
+ # GOOD: "The refund is over $50." (when)
427
+ # BAD: "Go to refund-review." (where)
428
+ # A routing condition CANNOT live in the target's
429
+ # summary/instructions — those are never disclosed
430
+ # to the state routing into it.
431
+ #
432
+ # The rendered line marks a target that is a human
433
+ # decision node or terminal (each changes the call
434
+ # or what follows it); nothing else of the target.
435
+
436
+ # human states only (ignored on agent states):
437
+ evidence?: string[] # workspace-relative paths always shown in the packet —
438
+ # a baseline the advancing agent adds to (see Human states)
439
+ approvers?: string[] # informational; not enforced
440
+ ```
441
+
442
+ ## Parking and sessions
443
+
444
+ A state parks the run **itself**: once it has asked for what it needs, its agent
445
+ calls `archmax_wait({ reason })` and the run suspends right there — no transition,
446
+ no model call spent parking. A delivered event resumes that same state, which
447
+ reads what arrived and then picks its own outgoing transition:
448
+
449
+ ```yaml
450
+ clarify:
451
+ title: Ask a clarifying question
452
+ instructions: >-
453
+ Ask exactly one clarifying question, then call archmax_wait with a reason
454
+ naming what you are waiting for. When the reply arrives you continue here:
455
+ read it, and if it identifies the order, advance to answer.
456
+ transitions:
457
+ - { to: answer, description: The reply identifies the order. }
458
+ - { to: closed, description: The conversation closed before a usable reply. }
459
+ ```
460
+
461
+ What to know:
462
+
463
+ - `archmax_wait` is available in **every** state, terminal ones included — a run
464
+ that has answered and now awaits a reply parks where it answered instead of
465
+ finishing. `tools: { forbid_always: [archmax_wait] }` removes it workflow-wide.
466
+ - The park is durable: status `awaiting_input` (classified **open**, never
467
+ finished), a checkpointed record of the state and the reason, and the process
468
+ may exit.
469
+ - **Any** delivered trigger id resumes a park — the id is recorded as the run's
470
+ current trigger (`args.trigger`, `${{trigger}}`), never matched against an edge.
471
+ The delivered variables arrive **locked**, and the arrival is written into the
472
+ transcript as an `[event]` **runtime note** — a synthetic `archmax_note` tool
473
+ call and its result, which is how the runtime says something to a run in a
474
+ channel a model cannot read as a person. Nothing may call `archmax_note`, and
475
+ derived views (`calledTool`, `usedNoTools`, the CLI's flow) skip the pair.
476
+ - The removed `type: wait` state kind is now an unknown state kind (`validate`
477
+ reports it as one), and a per-transition `on:` key is ignored. Call
478
+ `archmax_wait` instead.
479
+ - When what the state waits for is a **time** rather than a reply, the call says so:
480
+ `archmax_wait({ reason, until: "1d" })` — a duration (`30m`, `2h`, `1d`) or an
481
+ ISO-8601 instant, normalized to an absolute `resumeAt` on the park record, the
482
+ session summary, and the park event. The runtime **schedules nothing**: `resumeAt`
483
+ tells the host's cron when to `deliver`, and an earlier event resumes the park
484
+ regardless. An unparseable `until` is a tool error and the run does not park.
485
+ - A state that polls ("look for the transaction, else wait a day and retry") bounds
486
+ its own loop with `budget.maxParks` and sends the overrun somewhere with
487
+ `on_error`; the runtime counts parks per state in the checkpoint and refuses the
488
+ park that would exceed the bound as a turn failure:
489
+
490
+ ```yaml
491
+ check-bank:
492
+ summary: Look for the transaction; wait a day and retry if it has not posted.
493
+ budget: { maxParks: 5 }
494
+ on_error: escalate
495
+ transitions:
496
+ - { to: reconcile, description: The transaction was found. }
497
+ ```
498
+ - A finished session re-invoked is a **new turn** — it continues in the state the
499
+ previous turn ended in, *not* at the trigger's entry state, which applies only to
500
+ a session's first turn. Give a state re-entry transitions if a conversation must
501
+ move on from it; otherwise the agent's way out is `archmax_reset`. To continue
502
+ mid-state instead, park rather than finish.
503
+
504
+ A trigger's **declaration** sits under the `triggers:` of the state it enters,
505
+ keyed by its id. It says which conversation a firing belongs to and what the run
506
+ owes its caller:
507
+
508
+ ```yaml
509
+ states:
510
+ intake:
511
+ triggers:
512
+ email_received:
513
+ session: conversation_id
514
+ email_reply:
515
+ session: triggers.-1.conversationId # newest arrival's conversation id
516
+ # unknown/finished conversation → fresh run
517
+ enrich:
518
+ triggers:
519
+ manual: # the one entry: CLI, host firing, or a caller
520
+ requires: [order_id] # a firing must supply these to start
521
+ returns: [enrichment_file, delayed] # the run guarantees these when it completes
522
+ ```
523
+
524
+ - There is no `entry:` key and no root block: the state a declaration sits on is
525
+ the trigger's entry state, written once. `entry:` or `name:` inside a
526
+ declaration fails load naming the key — each would be a second spelling of
527
+ wiring the SDK already reads, and a loose declaration that swallowed one would
528
+ start the run somewhere you did not say.
529
+ - `requires:` / `returns:` are the run's **signature**, and both are enforced. A
530
+ firing that does not supply every `requires` name does not start; a run that
531
+ reaches a terminal state without every `returns` name set is rejected (a run
532
+ that *parks* is not checked — it has not finished). Both take the same grammar
533
+ as a state's `requires:`: a list of run-variable names, nothing more — what a
534
+ variable holds belongs in the `instructions` that set it. The names are
535
+ rendered into the prompt under the trigger's entry state, so the agent is told
536
+ what to produce before it can be failed for omitting it. A trigger's
537
+ `requires:` also **guarantees** the variable for `${{…}}` guards, so `validate`
538
+ stops warning about a guard bound to it. This is what makes delegation
539
+ checkable — see [Sub-workflows are tools](#sub-workflows-are-tools).
540
+ - `session:` is a **dotted path over the run's variables** — the same syntax
541
+ `${{…}}` guards use, including array indices and negative indices
542
+ (`-1` = last). No script, no callback: name where the host already puts the
543
+ conversation id. A `${{…}}`-wrapped value is rejected — write the bare path.
544
+ - Related triggers that must land in the same conversation declare the **same
545
+ path**. Each declares it itself: there is no shared lookup to change from
546
+ elsewhere in the document, and the duplication is the deliberate cost of a
547
+ state being legible on its own.
548
+ - A trigger with no `session:` path — or a firing whose path does not resolve —
549
+ gives that run a session of its own (its session id). Every run has exactly one
550
+ session, so there is no absent case.
551
+ - `message:` and `connection:` are **host-resolved** keys: shape-checked,
552
+ preserved and readable back (`messagePathForTrigger`, `connectionForTrigger`),
553
+ but nothing in the runtime acts on them. `message:` takes `session:`'s dotted
554
+ path — where a firing's words are — or the literal `false` for a trigger whose
555
+ firings carry no message; `connection:` is an opaque non-empty slug naming an
556
+ access connection in the host's own configuration. Author them only if the host
557
+ you are targeting reads them.
558
+ - A declaration key the SDK does not define is a **warning**, not a load failure:
559
+ it is ignored, and the workflow still runs. Structural problems — a
560
+ non-mapping `triggers:`, a declaration that is neither a mapping nor empty, one
561
+ id declared by two states, a malformed `session`/`message` path, an empty
562
+ `connection`, an `entry:` or `name:` key — still fail load.
563
+ - A host's own keys ride **inside the declaration**, keyed by the trigger id:
564
+
565
+ ```yaml
566
+ states:
567
+ intake:
568
+ triggers: # one state, two event sources
569
+ outlook-mail: { type: ap, piece: microsoft-outlook, event: newEmail }
570
+ slack-message:
571
+ type: ap
572
+ piece: slack
573
+ event: newMessage
574
+ session: triggers.-1.threadId
575
+ connection: acme-slack
576
+ ```
577
+
578
+ One state, one behavior, one governance block; `${{trigger}}` and a hook's
579
+ `args.trigger` still read which one actually fired.
580
+ - Every declared trigger **starts** a session. An event that must only ever reach
581
+ a live one — a ticket closing, a payment settling — is declared nowhere: the
582
+ host names the session it delivers into (`archmax deliver <session> --trigger
583
+ <id>`, `agent.workflow.send(sessionId, …)`), or passes a `sessionPath` with the
584
+ firing. A firing naming a trigger no state declares, with no session to reach,
585
+ is refused.
586
+
587
+ Call `archmax_wait` when an **external event** is what lets the work continue (an
588
+ email reply, a webhook, a scheduled reminder the host fires); author a `human`
589
+ state when a **person** picks the edge. Both park the session durably; they differ
590
+ in the resolution channel and in where the run continues — a decision advances
591
+ along the chosen edge, a delivery resumes the parked state.
592
+
593
+ **Runtime control tools** carry the `archmax_` prefix — `archmax_advance`,
594
+ `archmax_reset`, `archmax_wait`, `archmax_run`, `archmax_get_variables`,
595
+ `archmax_set_variables` — and are the names to write in `tools.allow`,
596
+ `tools.allow_always`, and the `forbid`/`forbid_always` lists. These are the only spellings:
597
+ an entry naming an unprefixed variant governs a tool that does not exist,
598
+ silently granting nothing. A host tool may never claim the prefix. Deep Agents' built-ins
599
+ (`read_file`, `task`, …) keep their own names.
600
+
601
+ - A state with **no `tools` block** gets the **always-on tools only**
602
+ (`ls`, `read_file`, `write_file`, `edit_file`, `glob`, `grep`, `write_todos`,
603
+ `archmax_eval`, `archmax_run`, `task`, plus the always-allowed `archmax_advance` and `allow_always`
604
+ grants — minus
605
+ whatever a `forbid` list denies there, and read-only-zone protection).
606
+ Governance is closed by default; there is no way to declare a fully open state.
607
+ - `tools.forbid` on a state **denies** while that state is active, beating every
608
+ grant that would otherwise reach it (see [Tool governance](#tool-governance)).
609
+ - A state with **no transitions** is **terminal**: the run ends when the agent
610
+ finishes its turn there; it cannot call `archmax_advance`.
611
+
612
+ ## Transitions
613
+
614
+ ```yaml
615
+ transitions:
616
+ - to: string # REQUIRED target state SLUG (must exist); never a title
617
+ description?: string # shown to the agent (or human) to pick the edge
618
+ type?: "approve" | "reject" | "refine" | "none" # default "none"
619
+ ```
620
+
621
+ - On **agent** states the agent chooses one edge via
622
+ `archmax_advance({ to, reason })`; `type` is metadata only.
623
+ - On **human** states each transition is a selectable outcome (a UI renders one
624
+ button per edge, labeled by `type`). `refine` conventionally loops back to a
625
+ prior state with the reviewer's comment as correction. Max one transition per
626
+ `type` on a human state.
627
+
628
+ ## Tool governance
629
+
630
+ `AllowEntry` forms:
631
+
632
+ ```yaml
633
+ # 1. bare tool name (any args)
634
+ - read_file
635
+
636
+ # 2. object with glob arg matchers (matches if the arg satisfies ANY glob)
637
+ - tool: write_file
638
+ args:
639
+ file_path: ["reports/*.json"]
640
+
641
+ # 3. `paths` shorthand for args.file_path (string or array)
642
+ - tool: write_file
643
+ paths: ["reports/*.json"]
644
+ ```
645
+
646
+ An object entry may also carry `connection` (the connection slug a
647
+ platform-provided tool resolves through when its collection has several) and
648
+ `source` (any string: a host's own label for where the tool came from) — the
649
+ runtime matches governance by `tool` name alone and never reads `source`.
650
+
651
+ **The model is closed by default, and a denial beats every grant.** Every state always has the
652
+ **always-on tools** (`ls`, `read_file`, `write_file`, `edit_file`, `glob`,
653
+ `grep`, `write_todos`, `archmax_eval`, `archmax_run`). One built-in is **never
654
+ disclosed** and grantable by nothing: `task`, the runtime's own dispatch for
655
+ grading rubrics — a rubric grades the agent rather than serving it, so naming
656
+ `task` in an allow entry is a `validate` error and the kernel refuses the call.
657
+ The planning scratchpad `write_todos` and the sandbox
658
+ `archmax_eval` are standard equipment — always disclosed, always permitted,
659
+ no setting; only a `forbid` list refuses them. The interpreter is safe as a
660
+ default because the `tools.*` calls its code makes are decided against the active
661
+ state by the same kernel: it adds computation over what the state permits, not
662
+ access. `archmax_run` — executing an authored script **file** — is always on on
663
+ the same terms (the script is a file the state could already read); declare it
664
+ per state to **narrow** which files may run there. Any other tool
665
+ must be declared in the state's `tools.allow` or workflow-level
666
+ `tools.allow_always`. A `tools.allow` entry naming an always-on tool **narrows**
667
+ it for that state.
668
+ Denial is declared beside the grant, in the same two positions and with the same
669
+ entries: `tools.forbid_always` at the root denies in every state,
670
+ `tools.forbid` on a state denies while it is active — subtracting from the
671
+ workflow's grant, the state's own `allow` and the always-on surface alike.
672
+ **Deny beats allow, and no narrower level widens a denial.** A forbid entry may
673
+ name the tool `*` (every tool); `*` in an allow list is a load error. A lifecycle
674
+ hook is exempt from the state's `allow` **and** its `forbid` — runtime authority,
675
+ outside that surface both ways — but never from `forbid_always`.
676
+
677
+ Precedence (highest first):
678
+
679
+ 0. **Skill and mount governance** — a path inside a skill bundle the active state
680
+ does not enable is refused before anything below is consulted (rule
681
+ `skill.not-allowed`), and so is a path under a mount the state does not have
682
+ (`mount.not-allowed` / `mount.forbidden`, or `mount.read-only` for a write into
683
+ one a grant narrowed to reads). Nothing widens either: not a wildcard
684
+ `tools.allow` entry, not `allow_always`, not a consumer rule.
685
+ 1. **Declared denials** — `tools.forbid_always` denies in every state,
686
+ `tools.forbid` denies in the active state, both regardless of any allow list
687
+ (and regardless of always-allowed): deny beats allow, and no narrower level
688
+ widens a denial.
689
+ 2. **Always allowed**: `archmax_advance` (baked in, every state).
690
+ 3. **Per-state `tools.allow`** — the listed tools/arg-shapes. An entry for an
691
+ always-on tool (or one also in `allow_always`) takes precedence
692
+ (**narrower wins** — the state's arg globs apply, not the broader grant).
693
+ 4. **Essential built-ins** — always permitted when no state entry narrows
694
+ them. Listing one in `allow_always` is inert (`archmax validate` warns).
695
+ 5. **Workflow `tools.allow_always`** — grants tools that are not always on in every
696
+ state.
697
+ 6. **Default**: everything else is blocked.
698
+
699
+ **Progressive disclosure.** The model is only shown the active state's tool
700
+ surface: always-on tools + `allow_always` + the state's entries + `archmax_advance`
701
+ (hidden in terminal states), minus every tool denied there by name. Disclosure is
702
+ name-level (arg-constrained tools stay visible; the kernel enforces args at
703
+ call time) and never replaces enforcement. **Skills are disclosed the same way**:
704
+ each model call names only the skills the active state enables, with their
705
+ descriptions — a disabled bundle's slug never reaches the prompt, and `ls skills/`
706
+ does not list it.
707
+
708
+ ## Skill governance
709
+
710
+ Govern a **capability** by its slug, not by path globs. The two levels compose
711
+ exactly as tools do: `skills.allow_always` at the spec root is enabled in **every**
712
+ state, and a state's `skills.allow` **adds** to it. **A skill is enabled only where
713
+ a list names it** — an absent state block adds nothing, exactly as an absent
714
+ `tools.allow` grants no tool — and a capability is declared **once**, at the level
715
+ where the decision was made:
716
+
717
+ ```yaml
718
+ skills:
719
+ allow_always: [order-data] # enabled in every state, named once
720
+
721
+ states:
722
+ orders-question: {} # no block, and it still has order-data
723
+ refund-review:
724
+ skills:
725
+ allow: [refund-policy] # this state adds one, and has both
726
+ identify-case:
727
+ skills:
728
+ forbid: [order-data] # routes only: opts out of the grant
729
+ ```
730
+
731
+ A state's `allow: []` is not a deny — a state's `allow` only ever adds
732
+ (`validate` warns about an entry that reads like a denial). **`skills.forbid` is
733
+ what subtracts**: it removes a slug from that state's enabled set, the workflow's
734
+ `allow_always` included, so one state opts out of a capability every other state
735
+ keeps; `skills.forbid_always` at the root puts a bundle out of reach everywhere.
736
+ There is no root `skills.allow` ceiling — writing one is a load error.
737
+
738
+ Why by slug, and not with `tools.allow` paths:
739
+
740
+ - **One declaration covers the whole bundle.** Enabling `order-data` makes
741
+ `skills/order-data/**` readable and its scripts runnable. The path-glob
742
+ alternative needs an entry per tool (`read_file`, `ls`, `glob`, `grep`,
743
+ `archmax_run`) and gets subtly wrong the moment a bundle grows a directory.
744
+ - **Path entries do not un-advertise.** A blocked read still leaves the skill's
745
+ name and description in the prompt of every state, so the model keeps reaching
746
+ for a capability it cannot have. A skill that is not enabled is not disclosed.
747
+ - **The two still compose** as *enabled AND allowed*: a `tools.allow` entry
748
+ narrows **within** the enabled set. `{ tool: archmax_run, paths:
749
+ ["skills/<slug>/scripts/**"] }` remains worth writing beside the list that
750
+ enables `<slug>` — the skills list puts every other capability out
751
+ of reach, while the entry confines execution to *this* capability's scripts.
752
+ Capability governance and execution governance are different questions.
753
+ - **`archmax_run` can only ever be narrowed.** A non-overridable kernel rule
754
+ (`script.skill-only`) confines it to skill bundles, so a script the agent writes
755
+ into `scratchpad/` is unrunnable, a lifecycle hook script is unrunnable, and
756
+ `{ tool: archmax_run, paths: ["**"] }` grants nothing — `validate` reports such
757
+ an entry as inert.
758
+
759
+ - **No skill enabled means no script at all.** Since `script.skill-only` confines
760
+ `archmax_run` to bundles, a state that enables no skill — nothing on
761
+ `allow_always`, nothing on its own list — can execute nothing: the tool stays on
762
+ the surface and refuses every path.
763
+
764
+ `archmax validate` warns when a state entry names a slug `allow_always` already
765
+ grants everywhere, when a state's `allow: []` beside such a grant subtracts
766
+ nothing, and once when a spec declares no root `skills` block at all in a workspace
767
+ that serves bundles, naming what the workflow cannot reach. Any root block silences
768
+ that last one — write `skills: { allow_always: [] }` when a workflow grants no
769
+ capability workflow-wide.
770
+
771
+ Hooks are **exempt**: a `before`/`after` script reads authored data on runtime
772
+ authority, so a state may enable nothing and still be gated by a hook that reads
773
+ the very bundle the model cannot. That is the shape to reach for when a capability
774
+ should *enforce* something without being *usable*.
775
+
776
+ **`tools.forbid` on a state denies there**, and `tools.forbid_always` at the
777
+ root denies everywhere. Both beat every grant. Migrating a workflow off the
778
+ retired `policy` block:
779
+
780
+ - `policy.forbid_tools: [x]` → `tools.forbid_always: [x]`.
781
+ - `policy.forbid_paths: [g]` → `tools.forbid_always: [{ tool: write_file, paths:
782
+ [g] }, { tool: edit_file, paths: [g] }]` for the identical meaning (it only
783
+ ever blocked those two), or `[{ tool: "*", paths: [g] }]` to deny reads too.
784
+
785
+ ## Mount governance
786
+
787
+ A **mount** is a folder (or a single file) the *host* routes into the agent's
788
+ workspace: `skills/`, `AGENTS.md`, and whatever else the wiring composes
789
+ (`reference/`, `catalogs/eu/`). The host owns which backend serves a mount, its
790
+ write posture, and whether the spec governs it; the spec owns which states reach
791
+ it, and what they may do there. **Neither is inferred from the other**, so you
792
+ cannot make a folder appear by naming it — ask the host to mount it.
793
+
794
+ A mount the host declares **governed** (`{ backend, governed: true }` in the
795
+ wiring) is closed by default, exactly like a skill bundle: reachable only from the
796
+ states a `mounts` list enables. An **ungoverned** mount — every mount of a
797
+ zero-config workspace, and every mount of a host that marks nothing — is visible
798
+ in every state, and only a `forbid` takes it away. So a spec with no `mounts`
799
+ block runs unchanged over any table.
800
+
801
+ The two levels compose exactly as `skills` does:
802
+
803
+ ```yaml
804
+ mounts:
805
+ allow_always: [reference] # reachable in every state, named once
806
+ forbid_always: [catalogs/uk] # out of reach everywhere, and in every
807
+ # child session this workflow delegates to
808
+
809
+ states:
810
+ intake: {} # no block, and it still has reference/
811
+ triage:
812
+ mounts:
813
+ allow: [catalogs/eu] # this state adds one, and has both
814
+ route:
815
+ mounts:
816
+ forbid: [reference] # opts out of the workflow's grant
817
+ ```
818
+
819
+ A state's `allow: []` is not a deny — a state's `allow` only ever adds
820
+ (`validate` warns about an entry that reads like a denial). **`mounts.forbid` is
821
+ what subtracts**, the workflow's `allow_always` and an ungoverned mount's standing
822
+ visibility alike. There is no root `mounts.allow` ceiling — writing one is a load
823
+ error.
824
+
825
+ ### Read or read/write
826
+
827
+ A grant entry is either a bare mount name — taking the posture the host wired — or
828
+ a mapping naming the access this level gives:
829
+
830
+ ```yaml
831
+ mounts:
832
+ allow_always:
833
+ - reference # the host's posture
834
+ - { mount: shared, access: read_write } # writable where the host allows it
835
+
836
+ states:
837
+ review:
838
+ mounts:
839
+ allow: [{ mount: shared, access: read }] # reads it, cannot write it here
840
+ ```
841
+
842
+ The host's `readOnly` is a **ceiling**, not a default to argue with:
843
+
844
+ - `access: read_write` on a mount the workspace serves read-only opens nothing,
845
+ and `validate` warns that the entry is inert. Ask the host to mount it
846
+ `{ readOnly: false }` instead.
847
+ - `access: read` is a restriction, so it behaves like every other restriction
848
+ here: whichever level asks for it gets it, and **no narrower level widens it
849
+ back**. A state cannot re-open what the workflow narrowed.
850
+ - A `forbid` entry is a name only. A denial is total, so there is no access to
851
+ qualify — `{ mount: x, access: read }` in a `forbid` list is a load error.
852
+
853
+ Two refusals, because they are two different edits: a write into a mount the
854
+ **host** serves read-only is `zone.read-only` (fix the wiring), and a write into
855
+ one a **grant** narrowed is `mount.read-only` (fix the spec).
856
+
857
+ ### What the agent sees
858
+
859
+ A governed mount the state does not have is not merely refused — it is not shown:
860
+
861
+ - `ls`, `glob` and `grep` results lose every entry under it, the **workspace root
862
+ listing included**, so the agent is never shown a directory it then cannot read.
863
+ - The static "Workspace zones" prompt section names ungoverned mounts only, one
864
+ line each with a `read-only` or `read/write` marker. The
865
+ governed mounts of *this* state are listed in the volatile "Current state"
866
+ block, read-only or read/write per the state's own grant — which is why the
867
+ cacheable prompt prefix stays byte-identical across states.
868
+ - Every call is still decided by the kernel (`mount.not-allowed`,
869
+ `mount.forbidden`, `mount.read-only`), whether or not a listing showed the path.
870
+ Redaction is the courtesy; the kernel is the enforcement.
871
+
872
+ ### Nested and file mounts
873
+
874
+ A mount key may be several segments deep (`catalogs/eu`), and a mount name is that
875
+ key with its slashes stripped — that is the token a `mounts` list takes, never a
876
+ glob (`reference/**` is a load error; scope paths *within* an enabled mount with a
877
+ `tools.allow` entry). A path is matched to a mount by **longest prefix**, so
878
+ `catalogs/eu` wins over a `catalogs` mounted beside it, and a sibling
879
+ `catalogs/uk` matches neither. A file mount (`AGENTS.md`) matches its exact path,
880
+ so `AGENTS.md.bak` is not captured.
881
+
882
+ ### Diagnostics
883
+
884
+ `archmax validate` reports, given the host's mount table:
885
+
886
+ - **error** — a name the table does not mount at all, naming the mounts it does;
887
+ - a grant naming an **ungoverned** mount (it grants nothing: the mount is visible
888
+ everywhere already — use `forbid` to take one away);
889
+ - an `access: read_write` on a mount the host serves **read-only**;
890
+ - a name in both `allow_always` and a state's `allow` (unless the state entry
891
+ narrows the access, which does real work);
892
+ - a state's `allow: []` beside a non-empty `allow_always`;
893
+ - a `forbid` naming a governed mount nothing would have enabled there;
894
+ - a `forbid_always` name some `allow` list also grants;
895
+ - a `tools.allow` path entry that can only match inside a mount the state does not
896
+ enable (the grant reaches nothing);
897
+ - **once**, when a spec declares no root `mounts` block at all in a workspace that
898
+ governs mounts, naming what the workflow cannot reach. Any root block silences
899
+ it — write `mounts: { allow_always: [] }` when a workflow reaches none.
900
+
901
+ Hooks and rubric graders are bound by `mounts.forbid_always` and **not** by a
902
+ state's `forbid` or its enabled set: they run on runtime authority, exactly as for
903
+ tools, so a `before` hook can read a mount the model in that state cannot.
904
+
905
+ ## Session variables in guards
906
+
907
+ A `tools.allow` argument glob may reference a **run variable** — `${{name}}` or
908
+ `${{name.dotted.path}}` — resolved against the run's variables at call time:
909
+
910
+ ```yaml
911
+ tools:
912
+ allow:
913
+ - { tool: gmail__send, args: { to: ["${{from_email}}"] } }
914
+ - { tool: crm__lookup, args: { region: ["${{account.region}}"] } }
915
+ - { tool: write_file, paths: ["reports/${{case_id}}/**"] }
916
+ ```
917
+
918
+ There is **no `variables:` block** — a variable exists once something sets it:
919
+ the host at assembly (`variables`, every seed locked), the agent mid-run
920
+ (`archmax_set_variables`), or one of the two built-ins.
921
+
922
+ **Two reserved names.** Do not claim either for something else:
923
+
924
+ | | `trigger` | `title` |
925
+ |---|---|---|
926
+ | Set by | the runtime, at every arrival | the **agent**, prompted by the platform prompt |
927
+ | Locked | always | **never**, by any route |
928
+ | Guaranteed set | yes | no — absent until written |
929
+ | In a trigger's `requires:` | accepted | accepted (seeded unlocked) |
930
+ | In a trigger's `returns:` | refused | refused |
931
+
932
+ `trigger` holds the current turn's trigger id. `title` holds a short one-line label
933
+ naming the task the run is doing; the platform system prompt asks the agent to set
934
+ one as its first activity and update it when the task changes significantly, so a
935
+ host can name a run instead of showing a session id. A write must be a non-empty
936
+ single-line string of at most 200 characters (stored trimmed) and must not pass
937
+ `lock: true` — both are refused, atomically, like every other `set_variables`
938
+ rejection. A host may seed a `title`; it lands **unlocked** (the one exception to
939
+ "every seed is locked") as an opening label, and it will not overwrite one an
940
+ earlier turn established.
941
+
942
+ Do not confuse it with the spec-root and per-state `title:` keys, which are static
943
+ human labels for the *workflow* and the *state*. The run variable names the **run**.
944
+
945
+ Because nothing guarantees `title` is set, a guard on `${{title}}` still draws the
946
+ assembly-time warning — correctly.
947
+
948
+ Two declarations *guarantee* one: a state's `requires:` (checked when leaving that
949
+ state) and a **trigger's** `requires:` (checked before the run starts, so a firing
950
+ that omits it never runs). A trigger's `returns:` is the mirror — the variables a
951
+ run guarantees it has set by the time it completes. See a trigger's declaration.
952
+
953
+ A value belongs to the **session**: what one state records is readable by every
954
+ state after it and by every later turn, so a downstream guard can bind to an
955
+ upstream fact. Design for that — `requires` in an early state plus `lock: true` is
956
+ how a later `${{name}}` becomes guaranteed rather than hopeful.
957
+
958
+ **Paths.** Segments descend one level; a numeric segment indexes an array and a
959
+ negative one counts from the end (`${{order.items.-1.sku}}` is the last item).
960
+ Traversal reads own properties only, so `${{tags.length}}` and
961
+ `${{v.constructor}}` do **not** resolve. A reference must resolve to a single
962
+ scalar.
963
+
964
+ **Authoring rules that matter:**
965
+
966
+ - **Lock anything a guard reads.** Host seeds are locked automatically (`title`
967
+ excepted, which is never locked); for an agent-established fact pass `lock: true`. An unlocked variable can be
968
+ overwritten by any later state — that rewrite is permitted, being one writer
969
+ twice, and the later value simply wins — so a guard bound to an unlocked name is
970
+ a weak guard. A lock is the only thing that makes a fact settled.
971
+ - **Guarantee the reference.** Name it in the `requires` of a state that runs
972
+ first, or seed it. Otherwise assembly only *warns*, and the run **fails** at
973
+ the guarded call if the agent never set it — an unresolvable reference is
974
+ terminal, not a retryable block, because a guard the runtime cannot evaluate
975
+ is not a guard.
976
+ - **A positional index makes the guard move.** `${{order.items.-1.sku}}` permits
977
+ a different value as the array grows. Sometimes exactly right ("the newest
978
+ attachment"); when you want a *stable* guard, store the value you mean as its
979
+ own named variable.
980
+ - **An `archmax_set_variables` typo creates a new variable** rather than erroring — there
981
+ are no declarations to check against. `requires` is the safety net that turns
982
+ that into a visible failure.
983
+
984
+ Substituted values are matched **literally** (a value holding `*` matches `*`,
985
+ not everything), so a variable can never widen the guard it lands in.
986
+
987
+ ### The same references work in the agent's own tool arguments
988
+
989
+ `${{…}}` is not only an authoring syntax. Anywhere a tool argument is text, the
990
+ runtime substitutes references from the run's variables **before** the call is
991
+ governed or executed — and a reference may sit *inside* a longer string, and
992
+ repeat:
993
+
994
+ ```
995
+ "Thanks — your refund is on its way.
996
+
997
+ --- Original message ---
998
+
999
+ ${{inbound.text}}"
1000
+ ```
1001
+
1002
+ So the agent quotes a stored value by naming it rather than retyping it. Three
1003
+ consequences worth authoring around:
1004
+
1005
+ - **A reference is exact.** A copy the model retypes can truncate, paraphrase, or
1006
+ drift; a reference cannot. When a state's job is to emit a large stored value,
1007
+ its `instructions` should **name the variable to interpolate** rather than
1008
+ telling the agent to include the original text.
1009
+ - **The guard and the argument meet on the value.** Substitution runs ahead of the
1010
+ kernel, so `args: { to: ["${{from_email}}"] }` and an argument of
1011
+ `"${{from_email}}"` resolve independently to the same string — they agree by
1012
+ construction, not by the model having retyped an address correctly.
1013
+ - **A bad reference here is recoverable**, unlike a bad guard. The call is refused
1014
+ with the reference named and the agent retries; only an unresolvable *guard* is
1015
+ terminal, because that is a defect the agent cannot fix.
1016
+
1017
+ The transcript keeps the reference — the substituted value goes to the tool and to
1018
+ the `tool-called` event a run trail renders, and no further, so the value's tokens
1019
+ are not re-sent on every later model call. An cases `calledTool` assertion
1020
+ therefore states the **reference** the agent wrote; pin the delivered text through
1021
+ the tool's effect instead (the file it wrote, the variable it set).
1022
+
1023
+ To write the characters `${{…}}` literally — authoring a guard through
1024
+ `write_file`, or writing about the syntax — double the dollar: `$${{name}}`.
1025
+
1026
+ This is **model-facing only**. An `archmax_eval` or hook script already holds the
1027
+ run's variables as `args.variables` and composes strings in JavaScript, so
1028
+ `${{…}}` in a script's `tools.*` call is ordinary text.
1029
+
1030
+ ## Lifecycle hooks
1031
+
1032
+ ```yaml
1033
+ # single hooks (the yaml wires the hook, nothing more):
1034
+ before:
1035
+ script: hooks/check.js # hand-authored, self-contained JS file;
1036
+ # resolves to workflows/<slug>/hooks/check.js
1037
+ after: { rubric: reply-tone, max_iterations: 2 } # per hook, not per state
1038
+ # a script after hook may carry the same budget:
1039
+ # after: { script: hooks/review.js, max_iterations: 2 }
1040
+
1041
+ # or a list, run in sequence (short-circuits on veto):
1042
+ before:
1043
+ - { script: hooks/pre.js }
1044
+ - rubric: { instructions: judge the tone }
1045
+ ```
1046
+
1047
+ - A `HookSpec` is one hook or a list, run in order and short-circuiting on the
1048
+ first non-ok. Each hook is either `{ script: <path> }` (JS in the QuickJS
1049
+ sandbox) or `{ rubric: <declaration> }` (the grader itself, inline).
1050
+ - **A script hook's path is workflow-relative and lives under `hooks/`.**
1051
+ `{ script: hooks/check.js }` resolves to `workflows/<slug>/hooks/check.js` on the
1052
+ authoring plane. An absolute path, a `..` climb, or anything outside `hooks/`
1053
+ (including the former `skills/<name>/scripts/…` spelling) is a load error and a
1054
+ `validate` error. Hook scripts are **not** agent-readable and **not** runnable
1055
+ with `archmax_run`: the runtime runs them, and that separation is what stops an
1056
+ agent probing the guard that gates it.
1057
+ - **Reserved sidecar key** on a script or custom hook: `max_iterations` (see
1058
+ Verdicts below). It is **refused beside a `rubric`**, whose budget is inside its
1059
+ declaration. There is no `instructions`, `model` or `specification` sidecar on
1060
+ any hook.
1061
+ - **Script hooks are hand-authored.** The script is an ordinary,
1062
+ self-contained `.js` file you design and write directly against the sandbox
1063
+ contract; it **must** open with a leading JSDoc title + description (plain
1064
+ prose, no special tags) — see
1065
+ [Code description docblocks](#code-description-docblocks).
1066
+ `archmax validate` errors on a missing script file or a
1067
+ foreign (non-`@archmax-ai/harness/*`) import; it does not check the docblock on a
1068
+ hook script. The runtime never generates: a missing
1069
+ script at run time vetoes (fail-closed).
1070
+ (A rubric's contract is its own `instructions`.)
1071
+ - **Phases**: `before` runs before the agent acts in the state and gates entry;
1072
+ `after` runs after the agent calls `archmax_advance`, before the transition
1073
+ commits (the "veto window"), or at completion for a terminal state.
1074
+ - **Verdicts**: `ok` (proceed), `correct` (agent gets another attempt), `veto`
1075
+ (block). Return the vocabulary or nothing: a bare `false` is **not** a veto, it
1076
+ is no verdict, which fails closed. Both hook kinds
1077
+ can return `correct` from an `after` hook — a script by evaluating to
1078
+ `{ verdict: "correct", reason: "..." }`, a rubric in its response —
1079
+ and both get the same bounded flow.
1080
+ - **`max_iterations`** bounds how many times a `correct` may send the agent back
1081
+ before the hook becomes a hard veto: inside the declaration for a rubric, a
1082
+ sidecar for a script or custom hook, else 0. It is counted **per hook by
1083
+ position**, so two graders on one state never share a budget. An
1084
+ exhausted budget is a *terminal failure* — see
1085
+ [Budgets & error routing](#budgets--error-routing).
1086
+ - **`before` hooks are ok/veto only**: a `correct` verdict from a `before` hook
1087
+ is treated as veto, and `max_iterations` on a `before` hook is a validation
1088
+ error.
1089
+ - **Fail-closed**: a hook that *errors* vetoes the transition. A rubric
1090
+ whose response cannot be parsed into a verdict also fails closed (**veto**),
1091
+ never coerced to ok — as does a `model` id the host cannot serve.
1092
+
1093
+ The hook contract — a default-export function called with one object:
1094
+
1095
+ ```js
1096
+ export default async function hook({
1097
+ state, phase /* "before"|"after" */, trigger, variables, messages,
1098
+ from, to, reason, // from/to/reason present on "after"
1099
+ tools, // privileged tool bridge, e.g. tools.readFile
1100
+ }) {
1101
+ return ok(); // or veto(reason) / correct(reason)
1102
+ }
1103
+ ```
1104
+
1105
+ Returning nothing is `ok`; a thrown error vetoes (fail-closed); the reason of a
1106
+ `veto` is shown to the agent so it can correct itself. Full contract, field
1107
+ semantics, and complete worked `before`/`after` examples:
1108
+ [`hook-and-test-scripts.md`](hook-and-test-scripts.md).
1109
+
1110
+ ## Budgets & error routing
1111
+
1112
+ ```yaml
1113
+ states:
1114
+ refund-request:
1115
+ budget:
1116
+ maxTurns: 24 # bounds this turn's agent loop
1117
+ # timeoutMs: 60000 # aborts the turn when exceeded
1118
+ on_error: escalation # terminal-failure target
1119
+ escalation: { instructions: "Explain the failure and hand off." } # terminal
1120
+ ```
1121
+
1122
+ Two failure classes, routed differently:
1123
+
1124
+ - **Recoverable rejections keep the agent in place**: an invalid edge in
1125
+ `archmax_advance`, a deliberate hook `veto`, or an in-budget `correct` — the
1126
+ agent sees the reason and retries within the same state.
1127
+ - **Terminal failures route to `on_error`**: a hook *execution error*, an
1128
+ exhausted iteration budget (`max_iterations` used up), or an exhausted
1129
+ `budget` (`maxTurns`/`timeoutMs`). With `on_error: <state>` declared, the run
1130
+ routes to that state (the failure reason arrives as an `[error]` runtime note)
1131
+ instead of ending; without it, the failure ends the run.
1132
+
1133
+ **Recommendation**: declare `on_error` on states with strict `after` hooks, so
1134
+ an exhausted judge doesn't hard-fail the run. The bundled example demonstrates
1135
+ this: its `refund-request` state pairs `budget.maxTurns: 24` with
1136
+ `on_error: escalation`, a terminal escalation state.
1137
+
1138
+ ## Human states
1139
+
1140
+ `type: human` state:
1141
+ - Parks the session with a checkpointed **pending-decision record** built from
1142
+ `instructions`, evidence file paths, and the transition descriptions/`type`s.
1143
+ Nothing is rendered to a file; `archmax run`/`archmax sessions` present that
1144
+ context on demand.
1145
+ - **Evidence is declared plus attached.** The state's `evidence:` is the baseline
1146
+ every reviewer sees; the agent advancing in may attach what this run produced —
1147
+ `archmax_advance({ to: "refund-review", reason: "…", evidence: ["scratchpad/carrier-report.md"] })`
1148
+ — and the record lists declared paths first, attached after, de-duplicated.
1149
+ Attachments are refused (transition untaken, agent may retry) when `to` is not a
1150
+ human state, when a path is not one the agent can read (`scratchpad/…`,
1151
+ `scratchpad/…`, an authored mount), or when more than 20 are attached. Each
1152
+ attachment belongs to the one decision it was made for. Author `evidence:` for
1153
+ what must always be shown; leave run-specific artifacts to the attachment.
1154
+ - A **human** selects the outgoing edge (optionally with a comment). The LLM does
1155
+ not choose. On resume the graph routes deterministically to the chosen target.
1156
+ - The target turn is told what happened by a `[decision]` **runtime note**
1157
+ naming the edge, the comment, and the state the run is now in. It is a note,
1158
+ not a human message: a model reads authorship from a message's channel, and a
1159
+ routing event that looks like a person's request gets treated as one — routed
1160
+ onward, answered in place, or waited on — instead of being the cue to do the
1161
+ target state's work. Do not write instructions that tell a state to "answer
1162
+ the user's latest message" when its only inbound edge is a human decision.
1163
+ - Resume programmatically with `agent.workflow.decide(sessionId, { target, comment })` or via
1164
+ the CLI `archmax decide <sessionId> <target>`.
1165
+
1166
+ ## Sub-workflows are tools
1167
+
1168
+ A state that may run another workflow names it in `tools.allow`. That entry is
1169
+ the whole declaration — there is no state kind and no second key.
1170
+
1171
+ ```yaml
1172
+ enrich:
1173
+ instructions: >-
1174
+ Enrich the account by calling archmax_workflow_enrich-account with its id,
1175
+ then record what it returned with archmax_set_variables.
1176
+ requires:
1177
+ - enrichment # nothing captures the result — this makes it mandatory
1178
+ tools:
1179
+ allow:
1180
+ - archmax_workflow_enrich-account # the slug, verbatim
1181
+ budget: { timeoutMs: 120000 } # bounds the whole turn, calls included
1182
+ on_error: enrichment-failed
1183
+ transitions:
1184
+ - to: draft-reply
1185
+ description: The account has been enriched.
1186
+ ```
1187
+
1188
+ - **The target's signature is the call signature.** Its `manual` trigger's
1189
+ `requires:` are the tool's required parameters; its `returns:` are what the
1190
+ result carries:
1191
+
1192
+ ```
1193
+ archmax_workflow_enrich-account({ account_id: "acct-42" })
1194
+ → { message: "Enriched acct-42.",
1195
+ returns: { enrichment_file: "scratchpad/e/acct-42.json", risk_level: "low" } }
1196
+ ```
1197
+
1198
+ A target declaring no `returns:` answers with the closing message alone.
1199
+ - **Nothing captures the result.** The agent records what it needs with
1200
+ `archmax_set_variables`, or a script writes it. Declare the state's `requires:`
1201
+ so it cannot advance without doing so — that is what replaces the old automatic
1202
+ capture.
1203
+ - **One call runs one sub-run.** There is no fan-out argument: an agent fans out
1204
+ with parallel tool calls, a script with `Promise.all`. Both are bounded by
1205
+ the dispatcher's `maxConcurrent`, and each call succeeds or fails on its
1206
+ own.
1207
+ - **A script is the deterministic fan-out.** Delegation tools are on the PTC
1208
+ surface, so a script decides how many calls to make:
1209
+
1210
+ ```js
1211
+ // the bridge camelCases tool names; a tool result arrives as text
1212
+ const results = await Promise.all(
1213
+ orders.map((o) => tools.archmaxWorkflowEnrichAccount({ account_id: o.id })),
1214
+ );
1215
+ const returns = results.map((r) => JSON.parse(r).returns);
1216
+ ```
1217
+
1218
+ A script's delegation **cannot park**: a child that reaches a human state fails
1219
+ that call closed with `parked`.
1220
+ - **Governance is ordinary.** The surface is closed by default, so a state naming
1221
+ no target may call none; `tools.forbid_always` blocks a delegation tool like any
1222
+ other.
1223
+ - **A failure is a tool error** the calling agent can handle; the state's
1224
+ `on_error` catches the turn if it cannot. Depth, cycle, missing-input and
1225
+ **disabled-target** refusals are blocked calls — nothing ran, so correct the call
1226
+ and retry.
1227
+ - **A `disabled: true` target is refused at dispatch, not at assembly.** The tool is
1228
+ still bound and the caller still assembles (disabling one leaf must not take every
1229
+ caller — or its parked sessions — offline); the call is a blocked call of kind
1230
+ `disabled`, and it beats a declared mock. `validate` **warns** on each state that
1231
+ allows a disabled target: the caller's spec is not wrong.
1232
+ - **A caller enters the child's `manual` entry** — the one entry the CLI, a host
1233
+ firing and a call all use. There is no opt-in on the target: whether a
1234
+ delegation may happen is decided by the caller's `tools.allow` entry. A target
1235
+ with no `manual` entry has no state to start in and fails closed. `session:` and
1236
+ `message:` on that trigger are host-facing keys a delegation ignores: a sub-run
1237
+ shares its parent's session, and carries no message. `sub-workflow` is no longer
1238
+ a trigger id — load and `validate` report it with the rename.
1239
+ - **Declare the child's signature** on that trigger — the contract, enforced both
1240
+ ways and at both ingresses:
1241
+
1242
+ ```yaml
1243
+ states:
1244
+ enrich:
1245
+ triggers:
1246
+ manual:
1247
+ requires: [order_id] # a caller must supply these
1248
+ returns: [enrichment_file, delayed] # the child guarantees it sets these
1249
+ ```
1250
+
1251
+ Develop it standalone on the same contract:
1252
+ `archmax run enrich-order --variables '{"order_id":"ORD-1003"}'`. `${{trigger}}`
1253
+ reads `manual` either way, so the machine cannot branch on having been called.
1254
+
1255
+ A dispatch missing a `requires` name is **refused before the child is
1256
+ composed**; a child that completes without every `returns` name set is
1257
+ **rejected** rather than handing back half a contract (a child that *parks* is
1258
+ not checked — it has not finished). Both are lists of names only: what a
1259
+ variable holds belongs in the state `instructions` that set it. The names are
1260
+ rendered into the child's prompt under its entry state, so it is told what to
1261
+ produce before it can be failed for omitting it.
1262
+ - **The call answers with the returns, by name.** A signed target answers
1263
+ `{ message, returns: { enrichment_file, delayed } }`; one declaring no
1264
+ `returns:` answers with the closing message alone. The message keeps its own
1265
+ key rather than being folded into the data — prose the model reads, values a
1266
+ guard or a script reads by name. **Nothing captures it into a variable**: the
1267
+ agent records what it needs with `archmax_set_variables`, or a script writes it,
1268
+ and the calling state's `requires:` is what makes that mandatory.
1269
+ - **Mocks are held to the same contract.** An `archmax_workflow_<slug>` mock for a
1270
+ signed target supplies `returns:`, and one that omits a declared name fails the
1271
+ mocked dispatch — a mock stands in for the sub-run, never for its agreement.
1272
+ - **No prose crosses the boundary.** A sub-run gets no instruction from its
1273
+ caller — it works from its own state `instructions` plus the arguments it was
1274
+ seeded with as locked variables, both of which reach the model through the
1275
+ system prompt. Nothing to author, nothing to keep in sync.
1276
+ - **Same agent, isolated context, shared session.** Same model, backend, host
1277
+ tools; its **own** grading rubrics, from its own spec; a fresh transcript; the child's *own* per-state
1278
+ `tools.allow`. It shares the run's session, so it writes `scratchpad/…` and
1279
+ `scratchpad/…` exactly as the parent does and the parent reads them afterwards.
1280
+ - **Nothing crosses implicitly.** Down: only the arguments the call passed —
1281
+ the calling run's own variables are not copied. Up: only the result message
1282
+ and the files. Everything the child sets is discarded when it finishes.
1283
+ - **Give each concurrent sub-run its own output path** — they share one run zone.
1284
+ - **Bounds** — the dispatcher's `bounds: { maxDepth: 3, maxConcurrent: 4 }`. No longer a spec key: the strict schema rejects `settings.sub_workflows` by name.
1285
+ Excess concurrency queues; depth and cycles are refused.
1286
+ - **Params are the sub-run's initial variables** — same construction, same name
1287
+ rule, same lock as a host's `variables`. So a delegated machine also runs
1288
+ **standalone** with those inputs supplied directly:
1289
+ `archmax run <child> --variables '{"order_id":"ORD-1003"}'` — no `--trigger`,
1290
+ because a caller and the CLI enter the same `manual` entry. That is how you
1291
+ develop one in isolation, on exactly the contract a caller holds it to.
1292
+ - **A child may stop for a person.** A `type: human` state in a delegated machine
1293
+ suspends the sub-run *and* the delegating run; `archmax decide <sessionId>
1294
+ <target>` resolves the **child's** decision, the sub-run finishes, and the
1295
+ parent carries on with its result. This holds for a **fan-out** too: each
1296
+ dispatch is its own checkpointed task, so resolving one decision re-runs only
1297
+ that sub-run — siblings that finished keep their results.
1298
+ - **Fails closed** — rejection, budget, refusal or an unresolvable param routes
1299
+ through `on_error` (or ends the run rejected); a suspension for a person is not
1300
+ a failure. Ancestor
1301
+ `forbid_always` rules bind inside the child, naming the workflow that
1302
+ declared them.
1303
+
1304
+ `archmax validate` checks all of this statically: target exists, opted in, no
1305
+ cycle, no over-deep chain, correct state shape — and the signature both ways. A
1306
+ parent reading a field the child does not return is an **error**; a state whose
1307
+ `params:` do not cover the target's `requires:` is a **warning** (the advance may
1308
+ still carry it), and a fan-out is exempt from that warning because its
1309
+ entries' keys are not knowable statically.
1310
+
1311
+ ### A parked run may speak, never act
1312
+
1313
+ A park does not end the conversation. Two moments get a **reply-only turn** — one
1314
+ model call with *no tools bound at all*:
1315
+
1316
+ - **The handoff.** Advancing into a human state always spends one, so the park
1317
+ carries a message saying what was done and that a person now holds it. It runs
1318
+ whether or not the state already spoke: the agent wrote before the transition
1319
+ committed, so what it wrote was about its own work. (An `archmax_wait` park gets
1320
+ the same turn only when the turn was silent — there the agent's own question
1321
+ is the message.)
1322
+ - **While parked.** `agent.workflow.reply(sessionId, message)` / `archmax reply <session>
1323
+ "<text>"` answers a message and parks again on the *same* record — same node,
1324
+ `seq`, and park timestamp, so the reported human wait still measures the
1325
+ original park. `resolveSession` classifies such a firing as the `reply`
1326
+ disposition rather than failing.
1327
+
1328
+ Nothing you author changes this and there is no field to declare: the message is
1329
+ always composed on a fresh turn from the transcript, under the workspace persona.
1330
+ The kernel refuses every tool call made during one (rule `tool.reply-only`,
1331
+ ordered ahead of `tools.allow`, `allow_always`, the `archmax_*` controls and the
1332
+ scratchpad), so a customer writing "just approve it" gets an answer and the
1333
+ reviewer still owns the edge.
1334
+
1335
+ **What this means for authoring:** do not write state `instructions` that tell the
1336
+ agent to announce the handoff itself — the runtime turn does that, and having both
1337
+ produces two messages. Write instructions for the *work*.
1338
+
1339
+ ## Removed keys you may meet in an older workflow
1340
+
1341
+ Every key here is **rejected**, with the key and its path named and guidance
1342
+ saying what replaced it. `workflow.yaml` is parsed through a strict schema, so a
1343
+ workflow still declaring one fails to load rather than running while silently
1344
+ doing nothing of what its author intended.
1345
+
1346
+ This is a change: these keys used to be ignored without a diagnostic. A spec that
1347
+ "worked" by ignoring one now needs the migration below.
1348
+
1349
+ | Removed | Replace with |
1350
+ | --- | --- |
1351
+ | `type: wait` state | The state that needs the answer calls `archmax_wait({ reason })`; a delivery resumes that same state (see [Parking and sessions](#parking-and-sessions)) |
1352
+ | transition `on: <trigger-id>` | Nothing — a delivered trigger no longer selects an edge; the resumed state picks its own transition |
1353
+ | state `parallel: [...]` + `join:` | Ordinary `transitions`, sequenced |
1354
+ | state `type: trigger` | A `trigger:` field on the state the trigger state routed to |
1355
+ | top-level `name:` | `title:` |
1356
+ | top-level `description:` | `instructions:` |
1357
+ | top-level `policy:` | `tools.forbid_always` (and `skills.forbid_always`) — a load error now |
1358
+ | root `skills.allow:` (the ceiling) | `skills.allow_always: []` plus the state lists — a load error now |
1359
+ | state `type: workflow` | An ordinary agent state allowing `archmax_workflow_<target>` and calling it (see [Sub-workflows are tools](#sub-workflows-are-tools)) |
1360
+ | state `workflow: <slug>` | The `archmax_workflow_<slug>` entry in that state's `tools.allow` — the allow entry *is* the declaration |
1361
+ | state `params:` | The call's arguments |
1362
+ | state `for_each:` | One call per entry — parallel tool calls from the agent, or `Promise.all` in a script |
1363
+ | state `result:` | The tool result; add `requires: [<name>]` to the state so it must record what it needs |
1364
+ | `archmax_advance({ params })` | The call's arguments |
1365
+
1366
+ **No fan-out.** There is no concurrent branching: a run traverses **one state at a
1367
+ time**, moved only by `archmax_advance`, a human decision, or `on_error` routing.
1368
+ Sequence the states that were branches:
1369
+
1370
+ ```yaml
1371
+ # REMOVED — do not author this
1372
+ states:
1373
+ gather:
1374
+ parallel: [check-inventory, check-credit]
1375
+ join: summarize
1376
+
1377
+ # author this instead
1378
+ states:
1379
+ check-inventory:
1380
+ transitions: [{ to: check-credit }]
1381
+ check-credit:
1382
+ transitions: [{ to: summarize }]
1383
+ summarize: { instructions: "..." }
1384
+ ```
1385
+
1386
+ Concurrent composition **is** sub-workflows: a state calling a delegation tool
1387
+ once per unit of work — the calls run concurrently (see
1388
+ [Sub-workflows are tools](#sub-workflows-are-tools)). Sequence anything that is not that —
1389
+ it costs latency, not correctness.
1390
+
1391
+ ## Workspace layout
1392
+
1393
+ ```
1394
+ workflows/<name>/workflow.yaml # the machine (canonical spec)
1395
+ workflows/<name>/WORKFLOW.md # OPTIONAL prose addendum (no frontmatter)
1396
+ workflows/<name>/hooks/*.js # lifecycle hook scripts — run BY THE HARNESS.
1397
+ # Authoring plane: the agent cannot read or run
1398
+ # anything under workflows/
1399
+ workflows/<name>/tests/ # cases (*.test.yaml, one case per
1400
+ # file; fixture files referenced with `from:`)
1401
+ skills/<capability>/SKILL.md # a capability, bundled (Agent Skills format).
1402
+ # Shared guidance for content that generalizes
1403
+ # across MULTIPLE states — single-state
1404
+ # behavior goes inline in that state's
1405
+ # `instructions` (never one SKILL.md per state)
1406
+ skills/<capability>/scripts/*.js # its archmax_run sources — run BY THE AGENT
1407
+ # (lifecycle hook scripts are NOT here: they
1408
+ # live in workflows/<name>/hooks/, are run by
1409
+ # the runtime, and the agent cannot read them)
1410
+ skills/<capability>/assets/* # its inputs (read-only)
1411
+ scratchpad/ # THE working area: intermediate files and the
1412
+ # artifacts a state produces. The run IS the
1413
+ # workspace root — resolves to
1414
+ # sessions/<sessionId>/scratchpad/. Always
1415
+ # writable, per-session
1416
+ large_tool_results/ # runtime-offloaded tool results (read-only)
1417
+ conversation_history/ # runtime-offloaded history (read-only)
1418
+ AGENTS.md # workspace persona/system prompt
1419
+ ```
1420
+
1421
+ This is the **complete** directory contract — there are no other magic
1422
+ locations, so design the full file set up front instead of exploring.
1423
+ Reference these paths **workspace-relative, without a leading slash**
1424
+ (`skills/order-data/assets/orders.json`, `scratchpad/refund.json`) — in `instructions`, `evidence`,
1425
+ allow-entry globs, and paths referenced inside hook scripts alike.
1426
+
1427
+ The authoring-plane prefix (`workflows/`) is **reserved**: a
1428
+ host cannot mount it (`MountCollisionError` at assembly), an allow entry naming
1429
+ it is a `validate` **error**, and a script that reads it is blocked with a
1430
+ diagnostic naming the prefix. Never write an allow entry, an `evidence` path, or a
1431
+ case `workspace:` key under it.
1432
+
1433
+ ### Grading rubrics — inline on the hook
1434
+
1435
+ A grader is the **value** of the hook that applies it, not a file beside the spec
1436
+ and not a named entry a hook points at:
1437
+
1438
+ ```yaml
1439
+ states:
1440
+ respond:
1441
+ after:
1442
+ - rubric:
1443
+ instructions: |- # REQUIRED — the criteria and the verdict
1444
+ Judge the tone of the last assistant message. Return `ok`,
1445
+ `correct` or `veto`, always with a concise `reason`.
1446
+ max_iterations?: number # the grade-and-retry budget, counted per hook
1447
+ model?: string # a model id to grade on, resolved through the
1448
+ # assembly's modelFactory (third argument)
1449
+ metadata?: object # host data the runtime never reads
1450
+ ```
1451
+
1452
+ A rubric has **no name**, and there is deliberately **no `title`, `description`
1453
+ or `response_format`**: nothing routes to a rubric, nothing labels one in a prompt
1454
+ (a display label goes in `metadata`), and a rubric only ever grades — so every
1455
+ dispatch requests the verdict schema unconditionally.
1456
+
1457
+ Verdict shape: `{ verdict: "ok"|"correct"|"veto", reason: string }`.
1458
+
1459
+ Two states needing the same grader declare it **twice**: a state legible on its
1460
+ own beats a de-duplicated document. Its identity is its position (state, phase,
1461
+ index), which is what the runtime dispatches it under and what its retry budget
1462
+ is keyed against — so two graders on one state never share a budget.
1463
+
1464
+ The agent learns nothing of it: the rendered graph says a phase carries a hook of
1465
+ kind `rubric`, there is no `task` tool to call one with, and no sandbox context
1466
+ has `task()`.
1467
+
1468
+ ## Cases
1469
+
1470
+ Declarative YAML case documents under `workflows/<name>/tests/*.test.yaml`
1471
+ (or `.test.yml`) — **one case per file**; the case id is the tests/-relative
1472
+ path minus the extension. `archmax test <workflow>` interprets them
1473
+ **host-side**: no QuickJS sandbox runs a case (the sandbox serves only
1474
+ lifecycle hooks and `archmax_run` inside the driven agent). These are distinct
1475
+ from the runtime's own colocated unit tests. Only `*.test.yaml`/`*.test.yml`
1476
+ files are discovered — a leftover `*.test.js` is ignored without a diagnostic.
1477
+
1478
+ A workflow declaring `disabled: true` runs **no** cases: the suite is reported as
1479
+ **skipped** and the exit code is **0** (not run is not failed, so retiring a
1480
+ workflow never reddens CI). There is no flag to force them; `archmax validate` is
1481
+ the static feedback while a workflow is out of service.
1482
+
1483
+ **Suite config lives in the `tests:` block of `workflow.yaml`**
1484
+ (`maxConcurrency`, `caseTimeoutMs`, `judge` — see [Root fields](#root-fields)).
1485
+ `tests.config.js` is **REMOVED**: its presence is a hard error in
1486
+ `archmax test` and `archmax validate`. There is no `reporters` option.
1487
+ `judge: {}` enables the grader with the env-configured default model.
1488
+
1489
+ **The complete case schema (top-level keys, the flat step-entry list, the
1490
+ assertion grammar, start conditions, mocks, `from:` fixture references) plus
1491
+ worked examples — routing,
1492
+ tool mocking, human-in-the-loop decide flows, triggered starts — and the
1493
+ JS→YAML migration table are in
1494
+ [`hook-and-test-scripts.md`](hook-and-test-scripts.md).**
1495
+
1496
+ Every case carries two mandatory prose fields, both length-capped: a `title`
1497
+ (a short label, ≤ 60 chars, printed beside the verdict) and a `description`
1498
+ (≤ 200 chars — the scenario driven and what is asserted). `archmax validate`
1499
+ **errors** on a missing or over-long field; longer rationale belongs in a YAML
1500
+ comment above the document (see
1501
+ [Code description docblocks](#code-description-docblocks)). A case is one
1502
+ conversation on one session; `steps` is one flat list where actions (`send`,
1503
+ `decide`) and assertions are peers, each assertion evaluating against the
1504
+ nearest action above it. Unknown keys anywhere in a case are validation
1505
+ errors — fail closed.
1506
+
1507
+ ```yaml
1508
+ # Nothing is mocked — the case reads the real orders.json fixture, so the
1509
+ # denial is re-derived by the refund policy hook rather than asserted directly.
1510
+ title: Refund denied for a shipped order
1511
+ description: >-
1512
+ A refund for shipped A-1002 parks at refund-review; the reviewer confirms the
1513
+ denial via refund-closed, the run succeeds, and the reply names the order.
1514
+ steps:
1515
+ - send: "Hi, I'm support@acmecorp.com. Please refund order A-1002."
1516
+ - parked: true
1517
+ - reachedState: refund-review
1518
+ - decide:
1519
+ to: refund-closed
1520
+ comment: "The denial matches policy."
1521
+ - succeeded: true
1522
+ - reply:
1523
+ includes: "A-1002"
1524
+ ```
1525
+
1526
+ ## Code description docblocks
1527
+
1528
+ **Every** code file in the workspace — both kinds: lifecycle hook scripts and
1529
+ `archmax_run` sources — MUST begin with a leading JSDoc block (`/** ... */`): a
1530
+ title line, a blank line, then prose stating what the code does **and how**.
1531
+ Cases are YAML documents, not code — they carry no JSDoc block;
1532
+ their mandatory `title` and `description` fields are short and capped instead,
1533
+ with any longer rationale in a YAML comment above the document. The canonical
1534
+ statement of the
1535
+ rule, with the required depth per file kind, is
1536
+ [SKILL.md → Code files are description-first](../SKILL.md#code-files-are-description-first).
1537
+
1538
+ - The block is the **human-facing contract**: admin UIs display only this
1539
+ description, and the code below it must honor it. Author
1540
+ description-first; when behavior changes, update the description, then edit
1541
+ the code to match — never leave the two contradicting each other.
1542
+ - Write it deep enough to review on its own: inputs read, the sequence of
1543
+ checks or assertions, and each outcome the code can produce. A one-line label
1544
+ is not enough.
1545
+ - It is inert at runtime — the QuickJS sandbox executes the source verbatim
1546
+ (typed `@archmax-ai/harness/*` imports excepted; they are stripped).
1547
+ - The prose ends at the first `@tag` line (tags are allowed but not part of
1548
+ the description), so keep the title and body above any tag. There is no
1549
+ `@specification` tag and no generation marker: the block is a human
1550
+ description, not a machine contract.
1551
+ - `archmax validate` **errors** when an cases is missing its
1552
+ `description` (the case schema requires it). Hook scripts and `archmax_run`
1553
+ sources are **not** checked — there the JSDoc rule is an authoring standard
1554
+ you uphold yourself.
1555
+ - Backends/UIs extract it with the package's exported
1556
+ `parseCodeDescription(source)` helper rather than scraping comments.
1557
+
1558
+ ## Read-only zones
1559
+
1560
+ Writes (via `write_file`/`edit_file`) targeting any read-only authored mount —
1561
+ the conventional directories plus root files such as `AGENTS.md`, or whatever the
1562
+ wiring code mounted — are blocked, by the mount itself and by governance
1563
+ (`zone.read-only`). A mount key of several segments (`catalogs/eu`) is matched by
1564
+ **longest prefix**, so a nested mount is a read-only zone exactly as a
1565
+ single-segment one is, and a sibling under the same first segment (`catalogs/uk`)
1566
+ is not.
1567
+
1568
+ A mount the host mounted **writable** is not a read-only zone — its paths are
1569
+ governed like ordinary run paths — but a state may still be given it read-only,
1570
+ with `mounts: { allow: [{ mount: <name>, access: read }] }`. A write refused by
1571
+ that grant is `mount.read-only`; one refused by the wiring is `zone.read-only`.
1572
+ See [Mount governance](#mount-governance).
1573
+
1574
+ The run root is writable, and it has exactly one named working area:
1575
+ `scratchpad/**`, permitted (read and write) in **every** state regardless of
1576
+ `tools.allow`. Agent-visible `scratchpad/…` resolves to
1577
+ `sessions/<sessionId>/scratchpad/…`, so concurrent sessions never collide.
1578
+
1579
+ Because that permission is unconditional, an allow entry naming a path *inside*
1580
+ `scratchpad/` does not constrain where within the area a write lands — `archmax
1581
+ validate` warns when a write entry's paths are all scratchpad paths. To govern
1582
+ *where* a result lands, name an ordinary run path instead (any run-root path
1583
+ outside the reserved areas — `reports/x.json`, or a root-level file); those are
1584
+ matched against the state's `tools.allow` like any other argument. The framework
1585
+ owns no second artifact area.
1586
+
1587
+ ## Annotated example: order-lookup
1588
+
1589
+ The bundled reference workspace lives at
1590
+ `examples/customer-support/workflows/order-lookup/` and demonstrates the full
1591
+ v2 layout: `workflow.yaml` (the machine, including the `tests:` block and
1592
+ script/rubric hook wiring) plus a frontmatter-free `WORKFLOW.md` prose addendum
1593
+ (ASCII graph + domain constraints). Read both in full for a real, working
1594
+ example. It declares a top-level `title` and a `title` on every state, with the
1595
+ slugs below as the reference targets, plus a top-level `instructions` block
1596
+ holding the rules that hold across every state — where the data and artifacts
1597
+ live, the tenancy rule, and naming an order's exact status — so no state repeats
1598
+ them. Its shape:
1599
+
1600
+ - `identify-case` (`triggers: { manual: , email_reply: }`, `before: check-requester.js`) routes to one
1601
+ of three cases via transition descriptions.
1602
+ - `orders-question` (terminal) answers from `skills/order-data/assets/orders.json`; an
1603
+ `after: { rubric: order-reply-tone }` grades the reply at completion.
1604
+ - `refund-request` records a decision to `scratchpad/refund.json` (no allow entry
1605
+ narrows it — the working area is open in every state; what holds the agent to a
1606
+ correct file is the hook), runs `after: check-refund.js`, and pairs
1607
+ `budget.maxTurns: 24` with `on_error: escalation` so a terminal failure
1608
+ (hook error, exhausted corrections, exhausted budget) routes to escalation
1609
+ instead of ending the run. On success it advances to `refund-review`.
1610
+ - `refund-review` (`type: human`, `evidence: [scratchpad/refund.json]`) — a person
1611
+ approves (→ terminal `refund-closed`) or refines (→ back to `refund-request`).
1612
+ - `escalation` (terminal) is the error handler entered only via
1613
+ `refund-request`'s `on_error`.
1614
+ - `general-question` (terminal) answers and writes `scratchpad/answer.json`.
1615
+
1616
+ ### Source of truth in code
1617
+
1618
+ If you need to confirm a detail, these files define the schema in the runtime:
1619
+
1620
+ | Concern | File |
1621
+ | --- | --- |
1622
+ | Spec types (`MachineState`, `Transition`, `HookSpec`, `AllowEntry`, `WorkflowTestsConfig`) | `src/machine/types.ts` |
1623
+ | Two-file loading (`workflow.yaml` + prose addendum) | `src/machine/load-spec.ts` |
1624
+ | Spec parsing, `ALWAYS_ALLOWED_TOOLS` | `src/machine/machine.ts` |
1625
+ | allow-entry matching, hook normalization | `src/machine/allow.ts` |
1626
+ | Rendered workflow header + per-state graph block | `src/workflow/render-prompt.ts` |
1627
+ | Lifecycle running + verdicts | `src/lifecycle/` |
1628
+ | Governance kernel (precedence) | `src/kernel/kernel.ts` |
1629
+ | `archmax_advance` tool | `src/workflow/advance-state.ts` |
1630
+ | Checkpointed state, `WORKFLOW_STATUSES` | `src/workflow/state.ts` |
1631
+ | Grading rubrics, verdict schema | `src/rubrics/rubrics.ts` |