@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,350 @@
1
+ /**
2
+ * Workflow lifecycle diagnostics the harness emits during assembly and while a
3
+ * machine-governed workflow runs. Every runtime diagnostic flows through this
4
+ * single typed stream; callers subscribe via `onEvent` on
5
+ * `CreateWorkflowAgentOptions`. With no subscriber, the harness installs
6
+ * {@link consoleEventHandler} (`[workflow]` / `[interpreter]` / `[rubrics]`
7
+ * console output).
8
+ *
9
+ * Two visual tiers: **node-change** events (`state-enter`, `state-leave`) render
10
+ * at the outer level; **action** events (`hook-*`, `advance`, `agent-text`)
11
+ * happen within a node and render indented beneath it.
12
+ *
13
+ * `callId` pairing rule: every event a tool call causes carries that call's
14
+ * `callId` — its own `tool-called`/`tool-result` pair and the effects it produced
15
+ * (`advance`, `parked`, `variables-set`, the sub-workflow pair). An event no call
16
+ * caused (a turn's opening arrival, a human-node park, run-start seeding) omits
17
+ * the field rather than carrying a synthetic id, so the set of events one call
18
+ * produced is derivable from ids alone. No governed call is exempt,
19
+ * `archmax_advance` included.
20
+ */
21
+ export type WorkflowEventLevel = "info" | "warn" | "error";
22
+ /**
23
+ * The `advance.from` marker for a turn's opening arrival at its state: a
24
+ * transition with no prior state. Mirrors LangGraph's `START` constant, kept as
25
+ * a local literal so this module stays free of a LangGraph dependency.
26
+ */
27
+ export declare const SESSION_ORIGIN = "__start__";
28
+ /**
29
+ * Where a tool call came from, on the tool events. Absent means the model called
30
+ * the tool directly; a value marks a programmatic call from inside a sandbox
31
+ * script (`script`) or a lifecycle hook (`lifecycle`).
32
+ */
33
+ export type ToolEventOrigin = "script" | "lifecycle";
34
+ /** How a programmatic tool call's origin reads in human-facing output. */
35
+ export declare function originLabel(origin: ToolEventOrigin): string;
36
+ /**
37
+ * Event payloads, without the severity level (added by the emitter). Every
38
+ * `state` field carries a **state slug** — never a `title`, so a retitled node
39
+ * emits byte-identical events.
40
+ */
41
+ export type WorkflowEventPayload = {
42
+ type: "interpreter-enabled";
43
+ } | {
44
+ type: "skills-loaded";
45
+ names: string[];
46
+ } | {
47
+ type: "hooks-summary";
48
+ summary: string;
49
+ } | {
50
+ type: "graph-topology";
51
+ topology: string;
52
+ } | {
53
+ type: "warning";
54
+ scope: string;
55
+ message: string;
56
+ } | {
57
+ type: "workflow-reset";
58
+ entry: string;
59
+ } | {
60
+ type: "state-enter";
61
+ state: string;
62
+ } | {
63
+ type: "state-leave";
64
+ state: string;
65
+ next: string;
66
+ } | {
67
+ type: "state-error-routed";
68
+ state: string;
69
+ to: string;
70
+ reason: string;
71
+ } | {
72
+ type: "hook-start";
73
+ state: string;
74
+ phase: "before" | "after";
75
+ label: string;
76
+ } | {
77
+ type: "hook-output";
78
+ state: string;
79
+ line: string;
80
+ } | {
81
+ type: "hook-passed";
82
+ state: string;
83
+ phase: "before" | "after";
84
+ } | {
85
+ type: "hook-verdict";
86
+ state: string;
87
+ phase: "before" | "after";
88
+ label: string;
89
+ /** The hook's verdict, kept as the exact kernel vocabulary (never widened). */
90
+ verdict: "ok" | "correct" | "veto";
91
+ reason: string;
92
+ missing?: string[];
93
+ } | {
94
+ type: "hook-rejected";
95
+ state: string;
96
+ phase: "before" | "after";
97
+ reason: string;
98
+ } | {
99
+ type: "advance";
100
+ from: string;
101
+ to: string;
102
+ reason?: string;
103
+ /**
104
+ * The `archmax_advance` call that drove this transition, matching its
105
+ * `tool-called`/`tool-result` pair. Absent for the turn's opening arrival
106
+ * (`from` is {@link SESSION_ORIGIN}), which the turn boundary commits
107
+ * rather than a call.
108
+ */
109
+ callId?: string;
110
+ } | {
111
+ type: "parked";
112
+ /** @deprecated Older spelling of {@link state}; emitted for one release. */
113
+ node: string;
114
+ /** The state the session parked at: a human state, or the state that waits. */
115
+ state?: string;
116
+ sessionId: string;
117
+ /**
118
+ * Which channel the session awaits: a human's decision, or an external
119
+ * event delivered as a trigger — so a subscriber can tell a waiting run
120
+ * from an ended one without reading checkpoints.
121
+ */
122
+ awaiting: "decision" | "input";
123
+ /**
124
+ * For an agent park, why the agent is waiting — its own `archmax_wait`
125
+ * reason. This is what a surface shows: an in-place park declares no
126
+ * awaited trigger ids, since any delivered firing resumes it.
127
+ */
128
+ reason?: string;
129
+ /**
130
+ * Absolute time the park asked to be resumed at, when the wait declared
131
+ * an `until`. A hint for whoever schedules the wake-up — the runtime holds
132
+ * no timer.
133
+ */
134
+ resumeAt?: string;
135
+ /**
136
+ * The `archmax_wait` call that asked for this park, matching that call's
137
+ * `tool-called`/`tool-result` pair. Absent for a human-node park: the run
138
+ * routed there, and no call asked for it.
139
+ */
140
+ callId?: string;
141
+ } | {
142
+ type: "decided";
143
+ node: string;
144
+ state?: string;
145
+ to: string;
146
+ sessionId: string;
147
+ } | {
148
+ type: "park-message";
149
+ node: string;
150
+ state?: string;
151
+ sessionId: string;
152
+ direction: "inbound" | "outbound";
153
+ text: string;
154
+ } | {
155
+ type: "delivered";
156
+ node: string;
157
+ state?: string;
158
+ /** The trigger id that resumed the park. */
159
+ trigger: string;
160
+ /**
161
+ * The state the run continues in — the parked node itself, since a
162
+ * delivery resumes in place rather than routing an edge.
163
+ */
164
+ to: string;
165
+ sessionId: string;
166
+ } | {
167
+ type: "agent-text";
168
+ state: string;
169
+ text: string;
170
+ messageId?: string;
171
+ partial?: boolean;
172
+ } | {
173
+ type: "agent-text-delta";
174
+ state: string;
175
+ text: string;
176
+ messageId?: string;
177
+ } | {
178
+ type: "tool-called";
179
+ state: string;
180
+ tool: string;
181
+ callId?: string;
182
+ args?: Record<string, unknown>;
183
+ detail?: string;
184
+ origin?: ToolEventOrigin;
185
+ } | {
186
+ type: "tool-result";
187
+ state: string;
188
+ tool: string;
189
+ callId: string;
190
+ status: "ok" | "error";
191
+ durationMs: number;
192
+ output: string;
193
+ truncated: boolean;
194
+ origin?: ToolEventOrigin;
195
+ } | {
196
+ type: "variables-set";
197
+ /** State the write was made from, or absent for run-start seeding. */
198
+ state?: string;
199
+ names: string[];
200
+ locked: boolean;
201
+ /**
202
+ * The `archmax_set_variables` call that wrote them, matching that call's
203
+ * `tool-called`/`tool-result` pair. Absent for run-start seeding, which no
204
+ * call made.
205
+ */
206
+ callId?: string;
207
+ } | {
208
+ type: "title-set";
209
+ /** The stored (trimmed) value. */
210
+ title: string;
211
+ /** State the write was made from, or absent for run-start seeding. */
212
+ state?: string;
213
+ /**
214
+ * The `archmax_set_variables` call that wrote it, matching that call's
215
+ * `tool-called`/`tool-result` pair. Absent when no call made the write.
216
+ */
217
+ callId?: string;
218
+ } | {
219
+ type: "tool-blocked";
220
+ state: string;
221
+ tool: string;
222
+ reason: string;
223
+ callId?: string;
224
+ args?: Record<string, unknown>;
225
+ origin?: ToolEventOrigin;
226
+ } | {
227
+ type: "rubric-start";
228
+ state: string;
229
+ name: string;
230
+ dispatchId: string;
231
+ } | {
232
+ type: "rubric-result";
233
+ state: string;
234
+ name: string;
235
+ dispatchId: string;
236
+ status: "ok" | "error";
237
+ durationMs: number;
238
+ } | {
239
+ type: "sub-workflow-start";
240
+ /** The state the call was made from. */
241
+ state: string;
242
+ /** The child workflow slug. */
243
+ workflow: string;
244
+ dispatchId: string;
245
+ /**
246
+ * The tool call that started it, when one did. Concurrent sub-runs differ
247
+ * in both this and `dispatchId`.
248
+ */
249
+ toolCallId?: string;
250
+ /** How many delegations deep this sub-run is; `1` directly under a root run. */
251
+ depth: number;
252
+ /** The ancestor chain above it, when there is one. */
253
+ chain?: string[];
254
+ } | {
255
+ type: "sub-workflow-result";
256
+ state: string;
257
+ workflow: string;
258
+ dispatchId: string;
259
+ /** The tool call this answers, matching its `sub-workflow-start`. */
260
+ toolCallId?: string;
261
+ /**
262
+ * How the dispatch settled. `parked` is not an outcome but a suspension:
263
+ * the child reached a human node (or waited), so the *parent* suspended
264
+ * with it and the dispatch resumes when the decision arrives.
265
+ */
266
+ status: "ok" | "error" | "parked";
267
+ durationMs: number;
268
+ /** Why it failed; absent on success. */
269
+ reason?: string;
270
+ /**
271
+ * The variables the sub-run returned, by **name** — absent when its target
272
+ * declares no `returns`. Names only, never values (this is a diagnostic
273
+ * channel); the values reach the parent as its `result:` variable.
274
+ */
275
+ returns?: string[];
276
+ } | {
277
+ type: "model-usage";
278
+ state: string;
279
+ inputTokens: number;
280
+ outputTokens: number;
281
+ cacheReadTokens?: number;
282
+ cacheCreationTokens?: number;
283
+ model?: string;
284
+ costUsd?: number;
285
+ } | {
286
+ type: "prompt-shaping";
287
+ cache: string;
288
+ withheld: string[];
289
+ };
290
+ /**
291
+ * Metadata stamped on every delivered event: emission time, a sequence number
292
+ * that is strictly increasing across all events delivered to the same handler
293
+ * (i.e. the same assembled agent), and — when a session context is bound — the
294
+ * session the event belongs to, so one handler can demultiplex concurrent runs.
295
+ */
296
+ export interface WorkflowEventEnvelope {
297
+ ts: number;
298
+ seq: number;
299
+ sessionId?: string;
300
+ /**
301
+ * The sub-workflow dispatch this event was emitted inside, when it was. A
302
+ * sub-run has its own session but shares its caller's event handler, so
303
+ * without this a child's `state-enter` would read as the parent moving to
304
+ * that state. Absent for everything a run does on its own behalf.
305
+ */
306
+ subWorkflowDispatchId?: string;
307
+ }
308
+ /** A lifecycle event as delivered to subscribers: payload, severity, envelope. */
309
+ export type WorkflowLifecycleEvent = WorkflowEventPayload & {
310
+ level: WorkflowEventLevel;
311
+ } & WorkflowEventEnvelope;
312
+ /** Callback signature for {@link WorkflowLifecycleEvent} subscribers. */
313
+ export type WorkflowEventHandler = (event: WorkflowLifecycleEvent) => void;
314
+ /** Payload with an optional explicit level override (else derived per type). */
315
+ export type WorkflowEventInput = WorkflowEventPayload & {
316
+ level?: WorkflowEventLevel;
317
+ };
318
+ /** Internal emitter shape: accepts payloads, fills in the level, delivers. */
319
+ export type WorkflowEventEmitter = (event: WorkflowEventInput) => void;
320
+ /** What the ambient binding contributes to every event's envelope. */
321
+ export interface EventContext {
322
+ sessionId: string;
323
+ /** Set while a sub-run executes, so its events can be told from its parent's. */
324
+ subWorkflowDispatchId?: string;
325
+ }
326
+ /**
327
+ * Run `fn` with the ambient event-envelope context bound. Nested calls
328
+ * **inherit** what they do not override: a sub-run binds its dispatch id without
329
+ * having to restate the session id it is running on.
330
+ */
331
+ export declare function withEventContext<T>(context: Partial<EventContext> & {
332
+ sessionId?: string;
333
+ }, fn: () => T): T;
334
+ /**
335
+ * Build the runtime's event emitter: fills in each event's severity level and
336
+ * envelope (`ts`, `seq`, ambient `sessionId`) and delivers it to `handler`,
337
+ * defaulting to {@link consoleEventHandler} so diagnostics are never silently
338
+ * dropped.
339
+ */
340
+ export declare function createWorkflowEventEmitter(handler?: WorkflowEventHandler): WorkflowEventEmitter;
341
+ /**
342
+ * The default console line for an event, or `null` for events the console
343
+ * output does not show (`tool-called`, `agent-text`).
344
+ */
345
+ export declare function renderEventLine(event: WorkflowLifecycleEvent): string | null;
346
+ /**
347
+ * Default subscriber: renders events with the established console prefixes.
348
+ * Installed by the harness when the caller supplies no `onEvent` handler.
349
+ */
350
+ export declare const consoleEventHandler: WorkflowEventHandler;
@@ -0,0 +1,205 @@
1
+ /**
2
+ * Workflow lifecycle diagnostics the harness emits during assembly and while a
3
+ * machine-governed workflow runs. Every runtime diagnostic flows through this
4
+ * single typed stream; callers subscribe via `onEvent` on
5
+ * `CreateWorkflowAgentOptions`. With no subscriber, the harness installs
6
+ * {@link consoleEventHandler} (`[workflow]` / `[interpreter]` / `[rubrics]`
7
+ * console output).
8
+ *
9
+ * Two visual tiers: **node-change** events (`state-enter`, `state-leave`) render
10
+ * at the outer level; **action** events (`hook-*`, `advance`, `agent-text`)
11
+ * happen within a node and render indented beneath it.
12
+ *
13
+ * `callId` pairing rule: every event a tool call causes carries that call's
14
+ * `callId` — its own `tool-called`/`tool-result` pair and the effects it produced
15
+ * (`advance`, `parked`, `variables-set`, the sub-workflow pair). An event no call
16
+ * caused (a turn's opening arrival, a human-node park, run-start seeding) omits
17
+ * the field rather than carrying a synthetic id, so the set of events one call
18
+ * produced is derivable from ids alone. No governed call is exempt,
19
+ * `archmax_advance` included.
20
+ */
21
+ import { AsyncLocalStorage } from "node:async_hooks";
22
+ /**
23
+ * The `advance.from` marker for a turn's opening arrival at its state: a
24
+ * transition with no prior state. Mirrors LangGraph's `START` constant, kept as
25
+ * a local literal so this module stays free of a LangGraph dependency.
26
+ */
27
+ export const SESSION_ORIGIN = "__start__";
28
+ /** How a programmatic tool call's origin reads in human-facing output. */
29
+ export function originLabel(origin) {
30
+ return origin === "script" ? "script" : "lifecycle hook";
31
+ }
32
+ function defaultLevel(event) {
33
+ switch (event.type) {
34
+ case "warning":
35
+ case "tool-blocked":
36
+ case "hook-rejected":
37
+ return "warn";
38
+ case "tool-result":
39
+ case "rubric-result":
40
+ case "sub-workflow-result":
41
+ return event.status === "error" ? "warn" : "info";
42
+ default:
43
+ return "info";
44
+ }
45
+ }
46
+ /**
47
+ * Ambient session binding for the event envelope. The turn runner binds it
48
+ * around each invoke so every event emitted while a session executes — from any
49
+ * emitter instance — carries that session's id without threading it through
50
+ * every emit call site.
51
+ */
52
+ const eventContext = new AsyncLocalStorage();
53
+ /**
54
+ * Run `fn` with the ambient event-envelope context bound. Nested calls
55
+ * **inherit** what they do not override: a sub-run binds its dispatch id without
56
+ * having to restate the session id it is running on.
57
+ */
58
+ export function withEventContext(context, fn) {
59
+ const current = eventContext.getStore();
60
+ const merged = {
61
+ sessionId: context.sessionId ?? current?.sessionId ?? "",
62
+ ...(context.subWorkflowDispatchId ?? current?.subWorkflowDispatchId
63
+ ? {
64
+ subWorkflowDispatchId: context.subWorkflowDispatchId ?? current?.subWorkflowDispatchId,
65
+ }
66
+ : {}),
67
+ };
68
+ return eventContext.run(merged, fn);
69
+ }
70
+ /**
71
+ * Per-handler sequence counters. Many emitter instances deliver to one
72
+ * handler (one assembled agent), so the counter is keyed by the handler to
73
+ * keep `seq` strictly increasing across everything that agent observes.
74
+ */
75
+ const seqByHandler = new WeakMap();
76
+ function nextSeq(handler) {
77
+ let counter = seqByHandler.get(handler);
78
+ if (!counter) {
79
+ counter = { n: 0 };
80
+ seqByHandler.set(handler, counter);
81
+ }
82
+ return ++counter.n;
83
+ }
84
+ /**
85
+ * Build the runtime's event emitter: fills in each event's severity level and
86
+ * envelope (`ts`, `seq`, ambient `sessionId`) and delivers it to `handler`,
87
+ * defaulting to {@link consoleEventHandler} so diagnostics are never silently
88
+ * dropped.
89
+ */
90
+ export function createWorkflowEventEmitter(handler) {
91
+ const deliver = handler ?? consoleEventHandler;
92
+ return (event) => {
93
+ const { level, ...payload } = event;
94
+ const sessionId = payload.sessionId ?? eventContext.getStore()?.sessionId;
95
+ const dispatchId = eventContext.getStore()?.subWorkflowDispatchId;
96
+ deliver({
97
+ ...payload,
98
+ level: level ?? defaultLevel(payload),
99
+ ts: Date.now(),
100
+ seq: nextSeq(deliver),
101
+ ...(sessionId ? { sessionId } : {}),
102
+ ...(dispatchId ? { subWorkflowDispatchId: dispatchId } : {}),
103
+ });
104
+ };
105
+ }
106
+ /**
107
+ * The default console line for an event, or `null` for events the console
108
+ * output does not show (`tool-called`, `agent-text`).
109
+ */
110
+ export function renderEventLine(event) {
111
+ switch (event.type) {
112
+ case "interpreter-enabled":
113
+ return "[interpreter] enabled (ptc: all agent tools)";
114
+ case "skills-loaded":
115
+ return `[skills] loaded: ${event.names.join(", ")}`;
116
+ case "hooks-summary":
117
+ return `[workflow] lifecycle: ${event.summary}`;
118
+ case "graph-topology":
119
+ return `[workflow] LangGraph graph:\n ${event.topology}`;
120
+ case "warning":
121
+ return `[${event.scope}] ${event.message}`;
122
+ case "workflow-reset":
123
+ return `[workflow] reset to entry '${event.entry}'`;
124
+ case "state-enter":
125
+ return `[workflow] entering node '${event.state}'`;
126
+ case "state-leave":
127
+ return `[workflow] leaving node '${event.state}' -> workflowState=${event.next}`;
128
+ case "state-error-routed":
129
+ return `[workflow] '${event.state}' failed -> routing to on_error '${event.to}': ${event.reason}`;
130
+ case "hook-start":
131
+ return `[workflow] ${event.phase} '${event.state}': running ${event.label}`;
132
+ case "hook-output":
133
+ return `[workflow:${event.state}] ${event.line}`;
134
+ case "hook-passed":
135
+ return `[workflow] '${event.state}' ${event.phase}-script passed`;
136
+ case "hook-verdict": {
137
+ const missing = event.missing?.length ? ` (missing: ${event.missing.join(", ")})` : "";
138
+ return `[workflow:${event.state}] ${event.label}: ${event.verdict.toUpperCase()} — ${event.reason}${missing}`;
139
+ }
140
+ case "hook-rejected":
141
+ return `[workflow] '${event.state}' ${event.phase} REJECTED: ${event.reason}`;
142
+ case "advance":
143
+ return event.from === SESSION_ORIGIN
144
+ ? `[workflow] entering start state '${event.to}'`
145
+ : `[workflow] advanced '${event.from}' -> '${event.to}'${event.reason ? `: ${event.reason}` : ""}`;
146
+ case "parked":
147
+ return event.awaiting === "input"
148
+ ? `[workflow] parked in '${event.node}' awaiting an event${event.reason ? `: ${event.reason}` : ""}${event.resumeAt ? ` (due ${event.resumeAt})` : ""} (session ${event.sessionId})`
149
+ : `[workflow] parked at human node '${event.node}' awaiting a decision (session ${event.sessionId})`;
150
+ case "decided":
151
+ return `[workflow] decision at '${event.node}' routed to '${event.to}' (session ${event.sessionId})`;
152
+ case "park-message":
153
+ return (`[workflow] ${event.direction === "inbound" ? "message to" : "reply from"} the run parked ` +
154
+ `at '${event.node}' (session ${event.sessionId})`);
155
+ case "delivered":
156
+ return `[workflow] '${event.trigger}' delivered to '${event.node}', resuming it (session ${event.sessionId})`;
157
+ case "variables-set":
158
+ return `[workflow] variables set${event.state ? ` in ${event.state}` : ""}: ${event.names.join(", ")}${event.locked ? " (locked)" : ""}`;
159
+ case "title-set":
160
+ // Printed in full: the write check bounds a title to one short line, so
161
+ // there is nothing here to cap or elide.
162
+ return `[workflow] title set${event.state ? ` in ${event.state}` : ""}: ${event.title}`;
163
+ case "tool-blocked":
164
+ // A refused programmatic call says so: the reason names a tool and a
165
+ // state, and without this an author would look for the call in the
166
+ // model's transcript, where it never appears.
167
+ return event.origin ? `${event.reason} (called from a ${originLabel(event.origin)})` : event.reason;
168
+ case "prompt-shaping":
169
+ return (`[workflow] prompt cache ${event.cache}` +
170
+ (event.withheld.length ? ` (withheld: ${event.withheld.join(", ")})` : ""));
171
+ case "sub-workflow-start":
172
+ return `[workflow] running sub-workflow '${event.workflow}' from '${event.state}'`;
173
+ case "sub-workflow-result":
174
+ if (event.status === "parked") {
175
+ return `[workflow] sub-workflow '${event.workflow}' parked, suspending the run with it`;
176
+ }
177
+ return event.status === "ok"
178
+ ? `[workflow] sub-workflow '${event.workflow}' completed (${event.durationMs}ms)`
179
+ : `[workflow] sub-workflow '${event.workflow}' failed: ${event.reason ?? "unknown error"}`;
180
+ case "tool-called":
181
+ case "agent-text":
182
+ case "agent-text-delta":
183
+ case "tool-result":
184
+ case "rubric-start":
185
+ case "rubric-result":
186
+ case "model-usage":
187
+ // Accounting is not console output: the CLI renders its own usage footer
188
+ // from its own subscriber, so a line here would duplicate it.
189
+ return null;
190
+ }
191
+ }
192
+ /**
193
+ * Default subscriber: renders events with the established console prefixes.
194
+ * Installed by the harness when the caller supplies no `onEvent` handler.
195
+ */
196
+ export const consoleEventHandler = (event) => {
197
+ const line = renderEventLine(event);
198
+ if (line == null)
199
+ return;
200
+ if (event.level === "info")
201
+ console.log(line);
202
+ else
203
+ console.warn(line);
204
+ };
205
+ //# sourceMappingURL=events.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"events.js","sourceRoot":"","sources":["../../src/core/events.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAIrD;;;;GAIG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,WAAW,CAAC;AAS1C,0EAA0E;AAC1E,MAAM,UAAU,WAAW,CAAC,MAAuB;IACjD,OAAO,MAAM,KAAK,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,gBAAgB,CAAC;AAC3D,CAAC;AAwTD,SAAS,YAAY,CAAC,KAA2B;IAC/C,QAAQ,KAAK,CAAC,IAAI,EAAE,CAAC;QACnB,KAAK,SAAS,CAAC;QACf,KAAK,cAAc,CAAC;QACpB,KAAK,eAAe;YAClB,OAAO,MAAM,CAAC;QAChB,KAAK,aAAa,CAAC;QACnB,KAAK,eAAe,CAAC;QACrB,KAAK,qBAAqB;YACxB,OAAO,KAAK,CAAC,MAAM,KAAK,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC;QACpD;YACE,OAAO,MAAM,CAAC;IAClB,CAAC;AACH,CAAC;AAED;;;;;GAKG;AACH,MAAM,YAAY,GAAG,IAAI,iBAAiB,EAAgB,CAAC;AAS3D;;;;GAIG;AACH,MAAM,UAAU,gBAAgB,CAAI,OAAuD,EAAE,EAAW;IACtG,MAAM,OAAO,GAAG,YAAY,CAAC,QAAQ,EAAE,CAAC;IACxC,MAAM,MAAM,GAAiB;QAC3B,SAAS,EAAE,OAAO,CAAC,SAAS,IAAI,OAAO,EAAE,SAAS,IAAI,EAAE;QACxD,GAAG,CAAC,OAAO,CAAC,qBAAqB,IAAI,OAAO,EAAE,qBAAqB;YACjE,CA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;
4
+ /** Markdown content after the closing `---` delimiter. */
5
+ body: string;
6
+ }
7
+ /**
8
+ * Parse a `---`-delimited YAML frontmatter block followed by a Markdown body,
9
+ * the convention shared by `SUBAGENT.md` and `WORKFLOW.md`. Returns `null` when
10
+ * the input has no frontmatter delimiters or the YAML block fails to parse.
11
+ *
12
+ * Delegates delimiter handling (CRLF/LF, trailing-newline, BOM) to gray-matter
13
+ * while parsing the YAML with the project's `yaml` engine.
14
+ */
15
+ export declare function parseFrontmatter(raw: string): ParsedFrontmatter | null;
@@ -0,0 +1,32 @@
1
+ import matter from "gray-matter";
2
+ import { parse as parseYaml } from "yaml";
3
+ /**
4
+ * gray-matter engine that reuses this project's `yaml` package (YAML 1.2)
5
+ * instead of gray-matter's bundled `js-yaml` (YAML 1.1), so frontmatter parses
6
+ * with the same semantics as the rest of the runtime. gray-matter hands the
7
+ * block over with CRLF line endings intact, and a trailing `\r` would otherwise
8
+ * end up inside parsed string values, so normalize before parsing.
9
+ */
10
+ const YAML_ENGINE = {
11
+ yaml: (input) => (parseYaml(input.replace(/\r(?=\n|$)/g, "")) ?? {}),
12
+ };
13
+ /**
14
+ * Parse a `---`-delimited YAML frontmatter block followed by a Markdown body,
15
+ * the convention shared by `SUBAGENT.md` and `WORKFLOW.md`. Returns `null` when
16
+ * the input has no frontmatter delimiters or the YAML block fails to parse.
17
+ *
18
+ * Delegates delimiter handling (CRLF/LF, trailing-newline, BOM) to gray-matter
19
+ * while parsing the YAML with the project's `yaml` engine.
20
+ */
21
+ export function parseFrontmatter(raw) {
22
+ if (!matter.test(raw))
23
+ return null;
24
+ try {
25
+ const parsed = matter(raw, { engines: YAML_ENGINE });
26
+ return { data: parsed.data, body: parsed.content };
27
+ }
28
+ catch {
29
+ return null;
30
+ }
31
+ }
32
+ //# sourceMappingURL=frontmatter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"frontmatter.js","sourceRoot":"","sources":["../../src/core/frontmatter.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,aAAa,CAAC;AACjC,OAAO,EAAE,KAAK,IAAI,SAAS,EAAE,MAAM,MAAM,CAAC;AAE1C;;;;;;GAMG;AACH,MAAM,WAAW,GAAG;IAClB,IAAI,EAAE,CAAC,KAAa,EAAU,EAAE,CAC9B,CAAC,SAAS,CAAC,KAAK,CAAC,OAAO,CAAC,aAAa,EAAE,EAAE,CAAC,CAAC,IAAI,EAAE,CAAW;CAChE,CAAC;AASF;;;;;;;GAOG;AACH,MAAM,UAAU,gBAAgB,CAAC,GAAW;IAC1C,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC;QAAE,OAAO,IAAI,CAAC;IAEnC,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,MAAM,CAAC,GAAG,EAAE,EAAE,OAAO,EAAE,WAAW,EAAE,CAAC,CAAC;QACrD,OAAO,EAAE,IAAI,EAAE,MAAM,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,CAAC,OAAO,EAAE,CAAC;IACrD,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC"}
@@ -0,0 +1,37 @@
1
+ /**
2
+ * The line-oriented listing filter both governed-capability redactions run on.
3
+ *
4
+ * The kernel refuses a path the state may not reach, which is enforcement — but
5
+ * a scoped tool asks about a *directory*, not a file: `ls skills/`, `glob
6
+ * catalogs/**\/*.csv`, and `grep` over the root all name a scope the state may
7
+ * legitimately reach and would hand back everything in it. Blocking those calls
8
+ * outright is the wrong trade (a state with one enabled capability could then
9
+ * not list it), so the result is filtered instead.
10
+ *
11
+ * This is the only place governance touches a tool **result** rather than a
12
+ * call, and it exists because invisibility is a requirement of governance in its
13
+ * own right: a name the model never sees is a capability it never tries.
14
+ *
15
+ * Filtering is line-oriented because the upstream filesystem tools render
16
+ * line-oriented text: `ls` one entry per line, `glob` one path per line, `grep`
17
+ * a `<path>:` header followed by indented ` <line>: <text>` matches. A header
18
+ * for a hidden owner therefore suppresses its continuation lines too —
19
+ * otherwise the matched *content* would survive its filename.
20
+ */
21
+ /**
22
+ * Drop from `text` every line about an owner `isHidden` refuses.
23
+ *
24
+ * `ownerOf` maps a result line's path to the governed thing that owns it (a
25
+ * skill slug, a mount name) or `null` when it owns none — a line no owner claims
26
+ * is always kept, since the state's other rules govern it.
27
+ *
28
+ * Returns the text unchanged when nothing was hidden, so a result the filter has
29
+ * no opinion about is passed through by identity rather than rebuilt.
30
+ */
31
+ export declare function redactListing(text: string, ownerOf: (path: string) => string | null, isHidden: (owner: string) => boolean): string;
32
+ /**
33
+ * The scoped file tools whose results are filtered. `read_file` is absent on
34
+ * purpose: it names one path, which the kernel already refuses, and filtering a
35
+ * file's *contents* would hand the model a silently truncated document.
36
+ */
37
+ export declare const REDACTED_TOOLS: ReadonlySet<string>;