@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,145 @@
1
+ import { MANUAL_TRIGGER, parseSessionPath, resolveSessionId, } from "../machine/triggers.js";
2
+ import { isFinished, WORKFLOW_STATUSES } from "../workflow/state.js";
3
+ /**
4
+ * Thrown when a firing maps to a session whose turn is still in progress: a
5
+ * session has a single writer, so the firing must wait. A human-parked session
6
+ * is *not* this case — it resolves to `reply`.
7
+ */
8
+ export class SessionNotResumableError extends Error {
9
+ sessionId;
10
+ status;
11
+ constructor(sessionId, status) {
12
+ super(`Session '${sessionId}' has a turn in progress (status '${status ?? "unknown"}'). A ` +
13
+ `session has a single writer: retry once the turn parks or ends.`);
14
+ this.sessionId = sessionId;
15
+ this.status = status;
16
+ this.name = "SessionNotResumableError";
17
+ }
18
+ }
19
+ /** Thrown when a firing names a trigger no state of the workflow declares. */
20
+ export class UnknownSessionTriggerError extends Error {
21
+ trigger;
22
+ constructor(trigger) {
23
+ super(`No state declares trigger '${trigger}', and no parked session is awaiting it, so there ` +
24
+ `is nowhere for this firing to go. Declare it under the 'triggers:' of the state a run ` +
25
+ `should start in, or deliver the firing to a session parked on it — naming the session, ` +
26
+ `or a 'sessionPath' to find it by.`);
27
+ this.trigger = trigger;
28
+ this.name = "UnknownSessionTriggerError";
29
+ }
30
+ }
31
+ /**
32
+ * Derive a firing's session id: the explicit one, else the invoking trigger's
33
+ * declared path resolved over the firing's variables, else a minted id (the
34
+ * firing is its own session). Every turn belongs to exactly one session.
35
+ */
36
+ export function deriveSessionId(path, input, nativeId) {
37
+ const explicit = input.sessionId?.trim();
38
+ if (explicit)
39
+ return { sessionId: explicit, native: false };
40
+ if (path) {
41
+ const resolved = resolveSessionId(path, input.variables ?? {});
42
+ if (resolved !== undefined)
43
+ return { sessionId: resolved, native: false };
44
+ return { sessionId: nativeId, native: true, unresolvedPath: path };
45
+ }
46
+ return { sessionId: nativeId, native: true };
47
+ }
48
+ /**
49
+ * Resolve and classify a firing. Never invokes the graph: the caller decides
50
+ * whether to start the run or deliver into it.
51
+ */
52
+ export async function resolveSession(machine, lookup, input, onWarning) {
53
+ const triggerId = input.trigger?.id ?? MANUAL_TRIGGER;
54
+ const { sessionId, native, unresolvedPath } = deriveSessionId(sessionPathFor(machine, triggerId, input.sessionPath), input, lookup.mintSessionId());
55
+ if (unresolvedPath) {
56
+ onWarning?.(`Trigger '${triggerId}' declares session path '${unresolvedPath.raw}', which this firing's ` +
57
+ `variables do not resolve. The firing is its own session ('${sessionId}') and cannot be ` +
58
+ `continued by a later firing for the same conversation.`);
59
+ }
60
+ // Where a *first* turn begins. A session that already has a position keeps it
61
+ // (below), so an unknown trigger id is only fatal at a session's opening.
62
+ const entryState = machine.startStateForTrigger(triggerId);
63
+ const openAt = (startState) => ({
64
+ sessionId,
65
+ disposition: "turn",
66
+ startState,
67
+ native,
68
+ });
69
+ const firstTurn = () => {
70
+ if (!entryState)
71
+ throw new UnknownSessionTriggerError(triggerId);
72
+ return openAt(entryState);
73
+ };
74
+ // A minted id names a session that does not exist yet: nothing to look up.
75
+ if (native)
76
+ return firstTurn();
77
+ const session = await lookup.findSession(sessionId);
78
+ // Projected from the session's own checkpoint: an absent or unreadable session
79
+ // is one that has not run yet.
80
+ if (!session)
81
+ return firstTurn();
82
+ if (isFinished(session.status)) {
83
+ // The previous turn ended; this firing is the next turn of the same
84
+ // conversation, continuing from the state that turn left it in (the trigger's
85
+ // entry state applies to a session's opening only). Only a position the
86
+ // *current* definition still declares is reported: the graph falls back to
87
+ // the trigger's entry state for one it cannot route to, and resolution must
88
+ // say the same thing.
89
+ const retained = session.workflowState;
90
+ const routable = retained != null && Object.hasOwn(machine.spec.states, retained);
91
+ return openAt(routable ? retained : (entryState ?? machine.entry));
92
+ }
93
+ // Parked at a human state: a person holds the run, so the firing cannot move
94
+ // it — but it is a message in a live conversation, so it is answered where the
95
+ // session stands and the park is left exactly as it was.
96
+ if (session.status === WORKFLOW_STATUSES.awaitingDecision) {
97
+ return {
98
+ sessionId,
99
+ disposition: "reply",
100
+ ...(session.workflowState
101
+ ? { state: session.workflowState, node: session.workflowState }
102
+ : {}),
103
+ native: false,
104
+ };
105
+ }
106
+ if (session.status !== WORKFLOW_STATUSES.awaitingInput) {
107
+ throw new SessionNotResumableError(sessionId, session.status);
108
+ }
109
+ // Parked awaiting an event, and any event will do: the session resumes the
110
+ // state it parked in, so there is no awaited id to match the firing against.
111
+ // The open turn takes the firing rather than a competing turn starting.
112
+ return {
113
+ sessionId,
114
+ disposition: "resume",
115
+ state: session.workflowState,
116
+ node: session.workflowState,
117
+ native: false,
118
+ };
119
+ }
120
+ /**
121
+ * The path this firing reads its id from: the caller's override if it supplied
122
+ * one, else what the invoking trigger declares on the state it enters — one
123
+ * parser for both.
124
+ */
125
+ function sessionPathFor(machine, triggerId, override) {
126
+ if (override === undefined || override.trim() === "") {
127
+ return machine.sessionPathForTrigger(triggerId);
128
+ }
129
+ const parsed = parseSessionPath(override);
130
+ if (parsed.error)
131
+ throw new InvalidSessionPathError(override, parsed.error);
132
+ return parsed.path;
133
+ }
134
+ /** Thrown when a caller-supplied session path is not a usable dotted path. */
135
+ export class InvalidSessionPathError extends Error {
136
+ path;
137
+ reason;
138
+ constructor(path, reason) {
139
+ super(`the caller-supplied path '${path}' is not a usable session path: ${reason}`);
140
+ this.path = path;
141
+ this.reason = reason;
142
+ this.name = "InvalidSessionPathError";
143
+ }
144
+ }
145
+ //# sourceMappingURL=resolve.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resolve.js","sourceRoot":"","sources":["../../src/sessions/resolve.ts"],"names":[],"mappings":"AAWA,OAAO,EACL,cAAc,EACd,gBAAgB,EAChB,gBAAgB,GAEjB,MAAM,wBAAwB,CAAC;AAEhC,OAAO,EAAE,UAAU,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AA6BrE;;;;GAIG;AACH,MAAM,OAAO,wBAAyB,SAAQ,KAAK;IAEtC;IACA;IAFX,YACW,SAAiB,EACjB,MAA0B;QAEnC,KAAK,CACH,YAAY,SAAS,qCAAqC,MAAM,IAAI,SAAS,QAAQ;YACnF,iEAAiE,CACpE,CAAC;QANO,cAAS,GAAT,SAAS,CAAQ;QACjB,WAAM,GAAN,MAAM,CAAoB;QAMnC,IAAI,CAAC,IAAI,GAAG,0BAA0B,CAAC;IACzC,CAAC;CACF;AAED,8EAA8E;AAC9E,MAAM,OAAO,0BAA2B,SAAQ,KAAK;IAC9B;IAArB,YAAqB,OAAe;QAClC,KAAK,CACH,8BAA8B,OAAO,oDAAoD;YACvF,wFAAwF;YACxF,yFAAyF;YACzF,mCAAmC,CACtC,CAAC;QANiB,YAAO,GAAP,OAAO,CAAQ;QAOlC,IAAI,CAAC,IAAI,GAAG,4BAA4B,CAAC;IAC3C,CAAC;CACF;AAyBD;;;;GAIG;AACH,MAAM,UAAU,eAAe,CAC7B,IAA6B,EAC7B,KAA0B,EAC1B,QAAgB;IAEhB,MAAM,QAAQ,GAAG,KAAK,CAAC,SAAS,EAAE,IAAI,EAAE,CAAC;IACzC,IAAI,QAA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.js";
3
+ import { type UsageSummary } from "../core/usage.js";
4
+ import { type VariableStore } from "../machine/variables.js";
5
+ import { type ParkChannel, type PendingDecision, type PendingInput, type TrailStep, type WorkflowStatus } from "../workflow/state.js";
6
+ export type { IntrospectableStateGraph };
7
+ /** The value a decision resumes a session parked at a human state with. */
8
+ export interface DecisionResolution {
9
+ /**
10
+ * The state the person selected to route to — one of the parked state's
11
+ * declared transition targets. The person picks the edge; no model interprets
12
+ * the choice.
13
+ */
14
+ target: string;
15
+ /** Optional free-form comment explaining the choice; recorded and passed on. */
16
+ comment?: string;
17
+ }
18
+ /**
19
+ * The value a reply resumes a parked session with: something the person said
20
+ * while a decision is pending. Answered, never acted on — the session stays
21
+ * parked at the same state, and only a {@link DecisionResolution} moves it.
22
+ */
23
+ export interface MessageResolution {
24
+ message: string;
25
+ }
26
+ /**
27
+ * Whether a resume payload is a message rather than a decision or a delivery.
28
+ * Told apart **structurally** — a `target` routes, a `trigger` is delivered (and
29
+ * may carry a message with it), a `message` alone is answered — never by reading
30
+ * the words: "yes, approve it" typed into the chat is not a decision.
31
+ */
32
+ export declare function isMessageResume(resume: unknown): resume is MessageResolution;
33
+ /**
34
+ * A firing delivered into a parked session: the trigger id the session adopts as
35
+ * its current one, plus the variables the event carried. Nothing is routed by
36
+ * the id: the session continues in the state it parked in.
37
+ */
38
+ export interface TriggerDelivery {
39
+ trigger: {
40
+ id: string;
41
+ };
42
+ variables?: Record<string, unknown>;
43
+ /**
44
+ * What a person said with the firing — a chat message that arrived while the
45
+ * session waited. Appended to the transcript as the person's own message in
46
+ * the same resume that delivers the firing, so it can neither land on a session
47
+ * whose park is gone nor be separated from the arrival by a crash between two
48
+ * writes. Blank is the same as absent.
49
+ */
50
+ message?: string;
51
+ }
52
+ /**
53
+ * The three ways a parked session resumes: a person decides, a person replies,
54
+ * the host delivers — one union, so `send()` takes one argument shape.
55
+ */
56
+ export type ResumePayload = {
57
+ decision: DecisionResolution;
58
+ } | {
59
+ message: string;
60
+ } | {
61
+ delivery: TriggerDelivery;
62
+ };
63
+ /** Thrown when a decision or reply targets a session that is not parked at a human state. */
64
+ export declare class SessionNotParkedError extends Error {
65
+ readonly sessionId: string;
66
+ constructor(sessionId: string);
67
+ }
68
+ /** Thrown when a decision names a target that is not one of the parked state's transitions. */
69
+ export declare class InvalidDecisionTargetError extends Error {
70
+ readonly sessionId: string;
71
+ readonly target: string | undefined;
72
+ readonly validTargets: string[];
73
+ constructor(sessionId: string, target: string | undefined, validTargets: string[]);
74
+ }
75
+ /** Thrown when a reply is sent to a parked session without any content. */
76
+ export declare class EmptyMessageError extends Error {
77
+ readonly sessionId: string;
78
+ constructor(sessionId: string);
79
+ }
80
+ /** Thrown when a delivery targets a session that is not parked awaiting input. */
81
+ export declare class SessionNotAwaitingInputError extends Error {
82
+ readonly sessionId: string;
83
+ constructor(sessionId: string);
84
+ }
85
+ /** Thrown when a delivery carries no trigger id to record as the session's current one. */
86
+ export declare class MissingDeliveryTriggerError extends Error {
87
+ readonly sessionId: string;
88
+ constructor(sessionId: string);
89
+ }
90
+ /**
91
+ * The child a parked session's pending decision belongs to. When a delegated
92
+ * child parks at its own human state, the calling session parks with it and
93
+ * presents the child's decision as its own; this says so, and names the child.
94
+ * A decision on the parent (`decide`, `send({ decision })`) is handed to that
95
+ * child — the caller addresses the parent session throughout.
96
+ */
97
+ export interface DelegatedPark {
98
+ /** The child workflow's slug. */
99
+ workflow: string;
100
+ /** The child's own session id (`<parent>~<identity>`), when the parent's id was known to the reader. */
101
+ sessionId?: string;
102
+ /** The dispatch identity the child's session id derives from: `<state>:<workflow>:<ordinal>`. */
103
+ identity: string;
104
+ /** The dispatch this park belongs to, as the `sub-workflow-*` events name it. */
105
+ dispatchId: string;
106
+ /** The tool call in the parent's transcript the child answers. */
107
+ toolCallId: string;
108
+ /** The parent state that made the call — where the parent parks, and resumes. */
109
+ state: string;
110
+ }
111
+ /** Outcome of resuming a session parked at a human state with a decision. */
112
+ export interface DecideOutcome {
113
+ /** Session status after the resume settled (`running`, `completed`, …). */
114
+ status?: WorkflowStatus;
115
+ /** Workflow state the session landed in after resuming. */
116
+ workflowState?: string;
117
+ /**
118
+ * Whether the session parked again, on **either** channel: a decision can
119
+ * route into another human state or into a state that then waits for an event.
120
+ */
121
+ reparked: boolean;
122
+ /** Which channel it re-parked on, when it did. Pairs with {@link state}. */
123
+ parkedChannel?: ParkChannel;
124
+ /** The state the session re-parked at — a human state or a waiting state. */
125
+ state?: string;
126
+ /** @deprecated Older spelling of {@link state}; kept for one release. */
127
+ node?: string;
128
+ /** Present when the pending decision is a delegated child's, not this session's own. */
129
+ delegation?: DelegatedPark;
130
+ /** What the session last said to the person — a finished turn's answer, or a park's message. Empty when it said nothing. */
131
+ reply: string;
132
+ /** Full message history after the resume, for building a session view. */
133
+ messages: unknown[];
134
+ /** The session's full committed audit trail after the resume settled. */
135
+ auditTrail: TrailStep[];
136
+ }
137
+ /**
138
+ * Outcome of replying to a session parked at a human state. Always a re-park at
139
+ * the same state: a message is answered, never acted on.
140
+ */
141
+ export interface ReplyOutcome extends DecideOutcome {
142
+ /** The state the session is (still) parked at. */
143
+ state: string;
144
+ /** @deprecated Older spelling of {@link state}; kept for one release. */
145
+ node: string;
146
+ /** Always `decision`: a message is answered where a person still holds the session. */
147
+ parkedChannel: ParkChannel;
148
+ }
149
+ /** @deprecated Older spelling of {@link ReplyOutcome}; kept for one release. */
150
+ export type RespondOutcome = ReplyOutcome;
151
+ /** What a delivery produced: a decision's shape plus the variables it seeded. */
152
+ export interface DeliverOutcome extends DecideOutcome {
153
+ /** The session's variables after the delivery seeded its own. */
154
+ variables: VariableStore;
155
+ /** Which channel the session re-parked in, when it did. */
156
+ parkedChannel?: ParkChannel;
157
+ }
158
+ /** Everything any resume settles to — the union of the three outcomes above. */
159
+ export interface ResumeOutcome extends DecideOutcome {
160
+ variables: VariableStore;
161
+ /** The park record a re-parked session presents, when it re-parked. */
162
+ pending?: PendingDecision | PendingInput;
163
+ /** Cumulative usage from the checkpoint, when anything was spent. */
164
+ usage?: UsageSummary;
165
+ }
166
+ /** How `send()` entered the session. */
167
+ export type SendDisposition = "turn" | "decide" | "reply" | "deliver";
168
+ /**
169
+ * What one `send()` on a session produced, whichever way it entered: a turn, a
170
+ * decision, a reply or a delivery. One shape for a host and the CLI.
171
+ */
172
+ export interface Outcome {
173
+ /** Completed, parked (on either channel), or rejected by governance. */
174
+ kind: "completed" | "parked" | "rejected";
175
+ /** How the session was entered. */
176
+ disposition: SendDisposition;
177
+ /** Session status after the turn settled. */
178
+ status?: WorkflowStatus;
179
+ /** The state the session is in — for a park, the state it is parked at. */
180
+ state?: string;
181
+ /** Which channel a parked session awaits. */
182
+ parkedChannel?: ParkChannel;
183
+ /** The park record a parked session presents: what a person or a host needs to resume it. */
184
+ pending?: PendingDecision | PendingInput;
185
+ /**
186
+ * When `kind` is `parked` on the `decision` channel because a **delegated
187
+ * child** parked: which child, and which call. Absent for the session's own
188
+ * park. A host reads this instead of folding `sub-workflow-*` events or
189
+ * shape-testing the child's interrupt.
190
+ */
191
+ delegation?: DelegatedPark;
192
+ /** What the session last said to the person. Empty when it said nothing. */
193
+ reply: string;
194
+ /** Full message history after the turn. */
195
+ messages: unknown[];
196
+ /** The session's committed audit trail. */
197
+ auditTrail: TrailStep[];
198
+ /** The session's variables, keyed by name. */
199
+ variables: VariableStore;
200
+ /** Cumulative usage from the checkpoint, when anything was spent. */
201
+ usage?: UsageSummary;
202
+ }
203
+ /**
204
+ * Read a session that must be parked in `status`, or `null`. "Parked" is two
205
+ * conditions — the checkpointed status *and* a pending interrupt — so every
206
+ * resume asks it here.
207
+ */
208
+ export declare function readParkedSession(graph: IntrospectableStateGraph, sessionId: string, status: string): Promise<Record<string, unknown> | null>;
209
+ /**
210
+ * The settled values of a turn or a resume, read into a {@link ResumeOutcome}.
211
+ * `sessionId` is the session the values belong to, when the caller knows it; it
212
+ * lets a delegated park name the child's session id.
213
+ */
214
+ export declare function settle(result: Record<string, unknown>, sessionId?: string): ResumeOutcome;
215
+ /** The {@link Outcome} a settled {@link ResumeOutcome} amounts to. */
216
+ export declare function outcomeOf(settled: ResumeOutcome, disposition: SendDisposition): Outcome;
217
+ /**
218
+ * Resume a parked session with a decision, a reply or a delivery. Everything is
219
+ * validated before the graph is touched; the invoke result *is* the resumed state.
220
+ */
221
+ export declare function resume(graph: IntrospectableStateGraph, sessionId: string, payload: ResumePayload, config?: RunnableConfig): Promise<ResumeOutcome>;
222
+ /**
223
+ * Resume a session parked at a human state with the person's decision. Throws
224
+ * {@link SessionNotParkedError} when the session is not awaiting a decision, and
225
+ * {@link InvalidDecisionTargetError} when `target` is not a declared transition.
226
+ */
227
+ export declare function decide(graph: IntrospectableStateGraph, sessionId: string, resolution: DecisionResolution, config?: RunnableConfig): Promise<DecideOutcome>;
228
+ /**
229
+ * Reply to a session parked at a human state and get its answer: a turn with no
230
+ * tools, after which the session stays parked at the same state with the same
231
+ * pending decision. Throws {@link SessionNotParkedError} and {@link EmptyMessageError}.
232
+ */
233
+ export declare function reply(graph: IntrospectableStateGraph, sessionId: string, message: string, config?: RunnableConfig): Promise<ReplyOutcome>;
234
+ /** @deprecated Older spelling of {@link reply}; kept for one release. */
235
+ export declare const respond: typeof reply;
236
+ /**
237
+ * Resume a parked session with a delivered firing: the session continues in the
238
+ * state it parked in, the delivered id becomes its current trigger, and the
239
+ * variables seed what the event carried. Throws {@link SessionNotAwaitingInputError}
240
+ * and {@link MissingDeliveryTriggerError}.
241
+ */
242
+ export declare function deliver(graph: IntrospectableStateGraph, sessionId: string, delivery: TriggerDelivery, config?: RunnableConfig): Promise<DeliverOutcome>;