@archmax-ai/harness 0.9.0 → 1.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 (207) hide show
  1. package/README.md +58 -14
  2. package/dist/agent.d.ts +4 -6
  3. package/dist/agent.js +4 -6
  4. package/dist/agent.js.map +1 -1
  5. package/dist/assembly/compose.d.ts +5 -24
  6. package/dist/assembly/compose.js +28 -42
  7. package/dist/assembly/compose.js.map +1 -1
  8. package/dist/assembly/delegation-registry.js +3 -14
  9. package/dist/assembly/delegation-registry.js.map +1 -1
  10. package/dist/assembly/index.d.ts +8 -15
  11. package/dist/assembly/index.js +21 -28
  12. package/dist/assembly/index.js.map +1 -1
  13. package/dist/assembly/plain.js +1 -2
  14. package/dist/assembly/plain.js.map +1 -1
  15. package/dist/authoring-skill/archmax-harness/README.md +5 -5
  16. package/dist/authoring-skill/archmax-harness/SKILL.md +72 -30
  17. package/dist/authoring-skill/archmax-harness/references/backend-integration.md +33 -24
  18. package/dist/authoring-skill/archmax-harness/references/cases.md +41 -8
  19. package/dist/authoring-skill/archmax-harness/references/{hook-and-test-scripts.md → code-state-and-test-scripts.md} +599 -339
  20. package/dist/authoring-skill/archmax-harness/references/code-states-and-scripts.md +115 -0
  21. package/dist/authoring-skill/archmax-harness/references/diagnostics.md +40 -7
  22. package/dist/authoring-skill/archmax-harness/references/wiring.md +19 -10
  23. package/dist/authoring-skill/archmax-harness/references/workflow-schema.md +404 -293
  24. package/dist/authoring-skill/archmax-harness/references/workflow-yaml.md +151 -62
  25. package/dist/cli/state-flow.d.ts +1 -1
  26. package/dist/cli/state-flow.js +18 -28
  27. package/dist/cli/state-flow.js.map +1 -1
  28. package/dist/cli/turn.d.ts +1 -1
  29. package/dist/cli/turn.js +1 -1
  30. package/dist/core/code-description.d.ts +3 -3
  31. package/dist/core/code-description.js +3 -3
  32. package/dist/core/deepagents.d.ts +5 -12
  33. package/dist/core/deepagents.js +4 -17
  34. package/dist/core/deepagents.js.map +1 -1
  35. package/dist/core/events.d.ts +23 -42
  36. package/dist/core/events.js +21 -24
  37. package/dist/core/events.js.map +1 -1
  38. package/dist/core/message-readers.d.ts +4 -5
  39. package/dist/core/message-readers.js +3 -8
  40. package/dist/core/message-readers.js.map +1 -1
  41. package/dist/core/messages.d.ts +0 -22
  42. package/dist/core/messages.js +1 -32
  43. package/dist/core/messages.js.map +1 -1
  44. package/dist/core/mounts.js +3 -3
  45. package/dist/core/platform-prompt.generated.js +1 -1
  46. package/dist/core/platform-prompt.generated.js.map +1 -1
  47. package/dist/core/session-zone.d.ts +1 -1
  48. package/dist/core/session-zone.js +1 -1
  49. package/dist/core/workspace-context.d.ts +1 -1
  50. package/dist/core/workspace.d.ts +1 -1
  51. package/dist/core/workspace.js +1 -1
  52. package/dist/core/zones.d.ts +4 -4
  53. package/dist/core/zones.js +5 -5
  54. package/dist/core/zones.js.map +1 -1
  55. package/dist/env.d.ts +9 -9
  56. package/dist/index.d.ts +3 -7
  57. package/dist/index.js +2 -4
  58. package/dist/index.js.map +1 -1
  59. package/dist/kernel/kernel.d.ts +31 -61
  60. package/dist/kernel/kernel.js +54 -112
  61. package/dist/kernel/kernel.js.map +1 -1
  62. package/dist/machine/lint-spec.js +53 -12
  63. package/dist/machine/lint-spec.js.map +1 -1
  64. package/dist/machine/machine.d.ts +36 -18
  65. package/dist/machine/machine.js +62 -51
  66. package/dist/machine/machine.js.map +1 -1
  67. package/dist/machine/spec-schema.d.ts +32 -180
  68. package/dist/machine/spec-schema.js +52 -113
  69. package/dist/machine/spec-schema.js.map +1 -1
  70. package/dist/machine/tool-names.d.ts +34 -16
  71. package/dist/machine/tool-names.js +41 -16
  72. package/dist/machine/tool-names.js.map +1 -1
  73. package/dist/machine/types.d.ts +14 -46
  74. package/dist/machine/types.js +0 -2
  75. package/dist/machine/types.js.map +1 -1
  76. package/dist/machine/validate-spec.d.ts +1 -1
  77. package/dist/public/sandbox.d.ts +59 -95
  78. package/dist/public/sandbox.js +22 -23
  79. package/dist/public/sandbox.js.map +1 -1
  80. package/dist/public/spec.d.ts +13 -20
  81. package/dist/public/spec.js +12 -20
  82. package/dist/public/spec.js.map +1 -1
  83. package/dist/runtime/contract.d.ts +11 -12
  84. package/dist/runtime/contract.js +16 -16
  85. package/dist/runtime/contract.js.map +1 -1
  86. package/dist/sandbox/assets/parts/code-state.js +17 -0
  87. package/dist/sandbox/executor.d.ts +25 -7
  88. package/dist/sandbox/executor.js +56 -57
  89. package/dist/sandbox/executor.js.map +1 -1
  90. package/dist/sandbox/imports.d.ts +10 -10
  91. package/dist/sandbox/imports.js +11 -11
  92. package/dist/sandbox/imports.js.map +1 -1
  93. package/dist/sandbox/prelude.d.ts +5 -6
  94. package/dist/sandbox/prelude.js +38 -35
  95. package/dist/sandbox/prelude.js.map +1 -1
  96. package/dist/sandbox/ptc-gateway.d.ts +19 -18
  97. package/dist/sandbox/ptc-gateway.js +26 -22
  98. package/dist/sandbox/ptc-gateway.js.map +1 -1
  99. package/dist/sessions/resume.d.ts +2 -2
  100. package/dist/sessions/resume.js +1 -1
  101. package/dist/sessions/resume.js.map +1 -1
  102. package/dist/sessions/scope.d.ts +0 -10
  103. package/dist/sessions/scope.js +0 -17
  104. package/dist/sessions/scope.js.map +1 -1
  105. package/dist/sessions/summary.d.ts +1 -1
  106. package/dist/testing/assertions.js +9 -4
  107. package/dist/testing/assertions.js.map +1 -1
  108. package/dist/testing/driver.js +3 -0
  109. package/dist/testing/driver.js.map +1 -1
  110. package/dist/testing/interpreter.d.ts +2 -2
  111. package/dist/testing/runner.d.ts +2 -2
  112. package/dist/validate/validate.d.ts +1 -1
  113. package/dist/validate/validate.js +39 -70
  114. package/dist/validate/validate.js.map +1 -1
  115. package/dist/workflow/automated-controls.d.ts +63 -0
  116. package/dist/workflow/automated-controls.js +158 -0
  117. package/dist/workflow/automated-controls.js.map +1 -0
  118. package/dist/workflow/automated.d.ts +112 -0
  119. package/dist/workflow/automated.js +163 -0
  120. package/dist/workflow/automated.js.map +1 -0
  121. package/dist/workflow/code-state.d.ts +46 -0
  122. package/dist/workflow/code-state.js +26 -0
  123. package/dist/workflow/code-state.js.map +1 -0
  124. package/dist/workflow/control-tools.d.ts +54 -23
  125. package/dist/workflow/control-tools.js +99 -79
  126. package/dist/workflow/control-tools.js.map +1 -1
  127. package/dist/workflow/file-values.d.ts +4 -4
  128. package/dist/workflow/file-values.js +1 -1
  129. package/dist/workflow/file-values.js.map +1 -1
  130. package/dist/workflow/governance.d.ts +11 -22
  131. package/dist/workflow/governance.js +47 -104
  132. package/dist/workflow/governance.js.map +1 -1
  133. package/dist/workflow/grader-state.d.ts +55 -0
  134. package/dist/workflow/grader-state.js +182 -0
  135. package/dist/workflow/grader-state.js.map +1 -0
  136. package/dist/workflow/history.d.ts +11 -0
  137. package/dist/{lifecycle/transcript.js → workflow/history.js} +24 -8
  138. package/dist/workflow/history.js.map +1 -0
  139. package/dist/workflow/middleware.d.ts +14 -17
  140. package/dist/workflow/middleware.js +109 -95
  141. package/dist/workflow/middleware.js.map +1 -1
  142. package/dist/workflow/move-events.d.ts +21 -0
  143. package/dist/workflow/move-events.js +20 -0
  144. package/dist/workflow/move-events.js.map +1 -0
  145. package/dist/workflow/on-error.js +0 -2
  146. package/dist/workflow/on-error.js.map +1 -1
  147. package/dist/workflow/parks.d.ts +9 -2
  148. package/dist/workflow/parks.js +16 -10
  149. package/dist/workflow/parks.js.map +1 -1
  150. package/dist/workflow/paths.d.ts +9 -9
  151. package/dist/workflow/paths.js +19 -19
  152. package/dist/workflow/paths.js.map +1 -1
  153. package/dist/workflow/render-prompt.d.ts +7 -5
  154. package/dist/workflow/render-prompt.js +22 -37
  155. package/dist/workflow/render-prompt.js.map +1 -1
  156. package/dist/workflow/signature-checks.d.ts +2 -2
  157. package/dist/workflow/snapshot.js +5 -29
  158. package/dist/workflow/snapshot.js.map +1 -1
  159. package/dist/workflow/state.d.ts +14 -42
  160. package/dist/workflow/state.js +20 -33
  161. package/dist/workflow/state.js.map +1 -1
  162. package/dist/workflow/sub-workflow.d.ts +3 -3
  163. package/dist/workflow/sub-workflow.js +3 -7
  164. package/dist/workflow/sub-workflow.js.map +1 -1
  165. package/dist/workflow/tool-service.d.ts +1 -9
  166. package/dist/workflow/tool-service.js +21 -24
  167. package/dist/workflow/tool-service.js.map +1 -1
  168. package/dist/workflow/turn-boundary.d.ts +2 -2
  169. package/dist/workflow/turn-boundary.js +10 -15
  170. package/dist/workflow/turn-boundary.js.map +1 -1
  171. package/dist/workflow/turn-runner.js +5 -6
  172. package/dist/workflow/turn-runner.js.map +1 -1
  173. package/package.json +1 -1
  174. package/skills/archmax-harness/README.md +5 -5
  175. package/skills/archmax-harness/SKILL.md +72 -30
  176. package/skills/archmax-harness/references/backend-integration.md +33 -24
  177. package/skills/archmax-harness/references/cases.md +41 -8
  178. package/skills/archmax-harness/references/{hook-and-test-scripts.md → code-state-and-test-scripts.md} +599 -339
  179. package/skills/archmax-harness/references/code-states-and-scripts.md +115 -0
  180. package/skills/archmax-harness/references/diagnostics.md +40 -7
  181. package/skills/archmax-harness/references/wiring.md +19 -10
  182. package/skills/archmax-harness/references/workflow-schema.md +404 -293
  183. package/skills/archmax-harness/references/workflow-yaml.md +151 -62
  184. package/dist/authoring-skill/archmax-harness/references/hooks-and-scripts.md +0 -89
  185. package/dist/lifecycle/hook-shape.d.ts +0 -44
  186. package/dist/lifecycle/hook-shape.js +0 -66
  187. package/dist/lifecycle/hook-shape.js.map +0 -1
  188. package/dist/lifecycle/runner.d.ts +0 -197
  189. package/dist/lifecycle/runner.js +0 -419
  190. package/dist/lifecycle/runner.js.map +0 -1
  191. package/dist/lifecycle/tool-calls.d.ts +0 -9
  192. package/dist/lifecycle/tool-calls.js +0 -57
  193. package/dist/lifecycle/tool-calls.js.map +0 -1
  194. package/dist/lifecycle/transcript.d.ts +0 -31
  195. package/dist/lifecycle/transcript.js.map +0 -1
  196. package/dist/rubrics/rubrics.d.ts +0 -135
  197. package/dist/rubrics/rubrics.js +0 -145
  198. package/dist/rubrics/rubrics.js.map +0 -1
  199. package/dist/sandbox/assets/parts/core.js +0 -22
  200. package/dist/sandbox/assets/parts/lifecycle-hook.js +0 -47
  201. package/dist/sandbox/bridge.d.ts +0 -16
  202. package/dist/sandbox/bridge.js +0 -95
  203. package/dist/sandbox/bridge.js.map +0 -1
  204. package/dist/workflow/visits.d.ts +0 -21
  205. package/dist/workflow/visits.js +0 -45
  206. package/dist/workflow/visits.js.map +0 -1
  207. package/skills/archmax-harness/references/hooks-and-scripts.md +0 -89
@@ -0,0 +1,112 @@
1
+ /**
2
+ * Automated states — grader and code states — as the runtime runs them.
3
+ *
4
+ * Every model call of a session crosses `wrapModelCall`, the `jumpTo: "model"`
5
+ * routes that skip `beforeModel` included. So that is where an automated state
6
+ * is run: when the session's position is a grader or a code state, the call is
7
+ * **serviced in place of the agent's model** — {@link runAutomatedStep} runs the
8
+ * state and returns a marker message carrying its outcome — and `afterModel`
9
+ * strips the marker and commits the outcome ({@link automatedOutcomeOf}). A move
10
+ * jumps back to the model, where the next state's call is serviced the same way
11
+ * (an automated state, with no model call), made for real (an agent state), or
12
+ * spent on a park's handoff (a human state). One step per graph iteration: each
13
+ * committed as its own checkpointed step, and a runaway cycle bounded by the
14
+ * session's recursion limit like any runaway turn.
15
+ *
16
+ * The outcome rides in the marker, not in memory, so a process that dies
17
+ * between the model node and `afterModel` replays the commit from the marker.
18
+ */
19
+ import type { BaseChatModel } from "@langchain/core/language_models/chat_models";
20
+ import { AIMessage } from "@langchain/core/messages";
21
+ import type { RunnableConfig } from "@langchain/core/runnables";
22
+ import type { StructuredTool } from "@langchain/core/tools";
23
+ import type { WorkflowEventEmitter } from "../core/events.js";
24
+ import type { MountPrefixes } from "../core/mounts.js";
25
+ import type { PricingTable, UsageSummary } from "../core/usage.js";
26
+ import type { WorkflowMachine } from "../machine/machine.js";
27
+ import { type VariableStore } from "../machine/variables.js";
28
+ import type { ScriptExecutor } from "../sandbox/executor.js";
29
+ import type { PtcToolGateway } from "../sandbox/ptc-gateway.js";
30
+ import { type CodeScriptResolver } from "./code-state.js";
31
+ import type { FileValueCheck } from "./signature-checks.js";
32
+ import { type TrailStep } from "./state.js";
33
+ /** An automated state's type. */
34
+ export type AutomatedType = "grader" | "code";
35
+ /**
36
+ * What one automated run settled as — exactly one of: it advanced (its decision
37
+ * stood and it finished cleanly), it raised, a terminal state completed, or it
38
+ * failed (an error, a timeout, a spent budget, or a non-terminal state that
39
+ * finished undecided).
40
+ */
41
+ export type AutomatedResult = {
42
+ kind: "advanced";
43
+ to: string;
44
+ reason: string;
45
+ evidence?: string[];
46
+ } | {
47
+ kind: "raised";
48
+ code: string;
49
+ reason: string;
50
+ } | {
51
+ kind: "completed";
52
+ } | {
53
+ kind: "failed";
54
+ reason: string;
55
+ };
56
+ /** A settled run, as the marker carries it to the commit: serializable, and the whole of what it commits. */
57
+ export interface AutomatedOutcome {
58
+ state: string;
59
+ type: AutomatedType;
60
+ result: AutomatedResult;
61
+ /** The run's variable writes. */
62
+ variables?: VariableStore;
63
+ /** What the run's own model calls cost (a grader's). */
64
+ usage?: UsageSummary;
65
+ /** The sub-runs its calls dispatched, as trail steps. */
66
+ trail?: TrailStep[];
67
+ }
68
+ /** The outcome a marker message carries, when the message is one. */
69
+ export declare function automatedOutcomeOf(message: unknown): AutomatedOutcome | undefined;
70
+ export interface AutomatedStatesContext {
71
+ machine: WorkflowMachine;
72
+ emit: WorkflowEventEmitter;
73
+ mountPrefixes: MountPrefixes;
74
+ /** Governs every tool an automated state calls, against the live state. */
75
+ ptcGateway: PtcToolGateway;
76
+ /** Runs a code state's script, reading it from the authoring backend. */
77
+ codeExecutor: ScriptExecutor;
78
+ resolveScript: CodeScriptResolver;
79
+ /** The model a grader state runs on, and its id when the instance exposes one. */
80
+ graderModel(state: string): {
81
+ model: BaseChatModel;
82
+ id?: string;
83
+ };
84
+ pricing?: PricingTable;
85
+ /** The `file` type's runtime check for a session in a state; omitted, a `file` value is held to its shape alone. */
86
+ files?: (state: string, variables: VariableStore) => FileValueCheck;
87
+ /** The sub-runs the session's calls dispatched since the last drain, as trail steps. */
88
+ dispatchSteps(sessionId: string, state: string): TrailStep[];
89
+ }
90
+ export interface AutomatedStepRequest {
91
+ sessionId: string;
92
+ /** The checkpointed session. */
93
+ session: unknown;
94
+ /** Every tool the assembly registered, before any state narrows it. */
95
+ tools: StructuredTool[];
96
+ /** The turn's config, naming the calling state. */
97
+ config: RunnableConfig;
98
+ signal?: AbortSignal;
99
+ }
100
+ /**
101
+ * Run the automated state the session stands in — one step — and return the
102
+ * marker message standing in for the model call that was not made.
103
+ *
104
+ * The state is offered exactly its surface (`disclosedTools`): the registered
105
+ * tools it names, minus the agent's control declarations, plus its own controls
106
+ * bound to this run's recorder — every one wrapped by the gateway, whose live
107
+ * context is pointed at this state first. Narrative events are emitted once the
108
+ * run has settled, so nothing announces a move the run's error then discarded.
109
+ */
110
+ export declare function runAutomatedStep(ctx: AutomatedStatesContext, request: AutomatedStepRequest): Promise<AIMessage>;
111
+ /** The runtime note an automated move or raise leaves for the session to read. */
112
+ export declare function automatedNoteText(outcome: AutomatedOutcome): string | undefined;
@@ -0,0 +1,163 @@
1
+ import { AIMessage } from "@langchain/core/messages";
2
+ import { v4 as uuidv4 } from "@langchain/core/utils/uuid";
3
+ import { TRIGGER_VARIABLE } from "../machine/variables.js";
4
+ import { createAutomatedControls, createStepRecorder } from "./automated-controls.js";
5
+ import { runCodeState } from "./code-state.js";
6
+ import { runGraderState } from "./grader-state.js";
7
+ import { sessionHistory } from "./history.js";
8
+ import { reportAdvance } from "./move-events.js";
9
+ import { currentWorkflowState, readVariables, readWorkflowState } from "./state.js";
10
+ /** Where the marker message carries its outcome. */
11
+ const AUTOMATED_STEP_KEY = "archmax_automated_step";
12
+ /** The outcome a marker message carries, when the message is one. */
13
+ export function automatedOutcomeOf(message) {
14
+ const kwargs = message?.additional_kwargs;
15
+ const outcome = kwargs?.[AUTOMATED_STEP_KEY];
16
+ return outcome && typeof outcome === "object" ? outcome : undefined;
17
+ }
18
+ /** The variables as a script reads them: a flat `name → value` map. */
19
+ function flatVariables(store) {
20
+ return Object.fromEntries(Object.entries(store).map(([name, entry]) => [name, entry.value]));
21
+ }
22
+ /** How a run settles, from its decision and whether it finished cleanly. */
23
+ function settle(machine, state, type, decision, error) {
24
+ // A raise ends the session whatever the run did next; an error discards a move.
25
+ if (decision?.kind === "raise")
26
+ return { kind: "raised", code: decision.code, reason: decision.reason };
27
+ if (error !== undefined)
28
+ return { kind: "failed", reason: error };
29
+ if (decision?.kind === "advance") {
30
+ return {
31
+ kind: "advanced",
32
+ to: decision.to,
33
+ reason: decision.reason,
34
+ ...(decision.evidence.length > 0 ? { evidence: decision.evidence } : {}),
35
+ };
36
+ }
37
+ if (machine.isTerminal(state))
38
+ return { kind: "completed" };
39
+ return {
40
+ kind: "failed",
41
+ reason: `${type} state '${state}' finished without calling archmax_advance or archmax_raise`,
42
+ };
43
+ }
44
+ /**
45
+ * Run the automated state the session stands in — one step — and return the
46
+ * marker message standing in for the model call that was not made.
47
+ *
48
+ * The state is offered exactly its surface (`disclosedTools`): the registered
49
+ * tools it names, minus the agent's control declarations, plus its own controls
50
+ * bound to this run's recorder — every one wrapped by the gateway, whose live
51
+ * context is pointed at this state first. Narrative events are emitted once the
52
+ * run has settled, so nothing announces a move the run's error then discarded.
53
+ */
54
+ export async function runAutomatedStep(ctx, request) {
55
+ const { machine, emit } = ctx;
56
+ const { sessionId, session, config } = request;
57
+ const state = currentWorkflowState(session, machine.entry);
58
+ const type = machine.isGraderState(state) ? "grader" : "code";
59
+ const declared = machine.spec.states[state];
60
+ const refresh = (variables) => ctx.ptcGateway.refresh(sessionId, { state, config, replyOnly: false, variables });
61
+ refresh(readVariables(session));
62
+ const recorder = createStepRecorder(state, session, refresh);
63
+ const history = sessionHistory(session);
64
+ const surface = machine.disclosedTools(state);
65
+ const controls = machine.controlTools(state);
66
+ const own = request.tools.filter((tool) => surface.has(tool.name) && !controls.has(tool.name));
67
+ const tools = ctx.ptcGateway.wrap([...own, ...createAutomatedControls(ctx, recorder, history)], { origin: type === "grader" ? "agent" : "script", sessionId });
68
+ const startedAt = Date.now();
69
+ let error;
70
+ let usage;
71
+ if (type === "code") {
72
+ emit({ type: "code-start", state, script: declared?.script ?? "" });
73
+ const trigger = readWorkflowState(session).trigger?.id;
74
+ const input = { state, ...(trigger ? { trigger } : {}), variables: flatVariables(recorder.store()) };
75
+ ({ error } = await runCodeState({
76
+ emit,
77
+ executor: ctx.codeExecutor,
78
+ resolveScript: ctx.resolveScript,
79
+ sessionId,
80
+ state,
81
+ script: declared?.script ?? "",
82
+ input,
83
+ tools,
84
+ surface: [...surface],
85
+ ...(request.signal ? { signal: request.signal } : {}),
86
+ }));
87
+ }
88
+ else {
89
+ emit({ type: "grader-start", state });
90
+ const { model, id } = ctx.graderModel(state);
91
+ ({ error, usage } = await runGraderState({
92
+ machine,
93
+ emit,
94
+ ...(ctx.pricing ? { pricing: ctx.pricing } : {}),
95
+ state,
96
+ model,
97
+ ...(id ? { modelId: id } : {}),
98
+ tools,
99
+ recorder,
100
+ ...(request.signal ? { signal: request.signal } : {}),
101
+ }));
102
+ }
103
+ const decision = recorder.decision;
104
+ const result = settle(machine, state, type, decision, error);
105
+ const failed = result.kind === "failed";
106
+ emit({
107
+ type: type === "code" ? "code-result" : "grader-result",
108
+ state,
109
+ status: failed ? "error" : "ok",
110
+ durationMs: Date.now() - startedAt,
111
+ ...(failed ? { reason: result.reason } : {}),
112
+ });
113
+ if (result.kind === "advanced") {
114
+ reportAdvance(emit, sessionId, {
115
+ from: state,
116
+ to: result.to,
117
+ reason: result.reason,
118
+ ...(decision?.callId ? { callId: decision.callId } : {}),
119
+ parks: machine.isHumanState(result.to),
120
+ });
121
+ }
122
+ else if (result.kind === "raised") {
123
+ emit({
124
+ type: "raised",
125
+ state,
126
+ sessionId,
127
+ code: result.code,
128
+ reason: result.reason,
129
+ ...(decision?.callId ? { callId: decision.callId } : {}),
130
+ });
131
+ // The session leaves the state it failed in as a completing one does; nothing is entered.
132
+ emit({ type: "state-leave", state, next: state });
133
+ }
134
+ // The built-in `trigger` is the turn's, set at its boundary: never a run's write.
135
+ const { [TRIGGER_VARIABLE]: _trigger, ...variables } = recorder.delta;
136
+ const trail = ctx.dispatchSteps(sessionId, state);
137
+ const outcome = {
138
+ state,
139
+ type,
140
+ result,
141
+ ...(Object.keys(variables).length > 0 ? { variables } : {}),
142
+ ...(usage ? { usage } : {}),
143
+ ...(trail.length > 0 ? { trail } : {}),
144
+ };
145
+ return new AIMessage({
146
+ content: "",
147
+ id: `automated_${uuidv4()}`,
148
+ additional_kwargs: { [AUTOMATED_STEP_KEY]: outcome },
149
+ });
150
+ }
151
+ /** The runtime note an automated move or raise leaves for the session to read. */
152
+ export function automatedNoteText(outcome) {
153
+ const { state, type, result } = outcome;
154
+ const who = type === "grader" ? `The '${state}' grader` : `'${state}'`;
155
+ if (result.kind === "advanced") {
156
+ return `[${type}] ${who} moved the run to '${result.to}': ${result.reason}. You are now in '${result.to}'.`;
157
+ }
158
+ if (result.kind === "raised") {
159
+ return `[${type}] ${who} ended the session as failed ('${result.code}'): ${result.reason}`;
160
+ }
161
+ return undefined;
162
+ }
163
+ //# sourceMappingURL=automated.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"automated.js","sourceRoot":"","sources":["../../src/workflow/automated.ts"],"names":[],"mappings":"AAmBA,OAAO,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AAGrD,OAAO,EAAE,EAAE,IAAI,MAAM,EAAE,MAAM,4BAA4B,CAAC;AAK1D,OAAO,EAAE,gBAAgB,EAAsB,MAAM,yBAAyB,CAAC;AAG/E,OAAO,EAAE,uBAAuB,EAAE,kBAAkB,EAA0B,MAAM,yBAAyB,CAAC;AAC9G,OAAO,EAAE,YAAY,EAA2B,MAAM,iBAAiB,CAAC;AACxE,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,EAAE,cAAc,EAAE,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AG,CAAC;IACvE,IAAI,MAAM,CAAC,IAAI,KAAK,UAAU,EAAE,CAAC;QAC/B,OAAO,IAAI,IAAI,KAAK,GAAG,sBAAsB,MAAM,CAAC,EAAE,MAAM,MAAM,CAAC,MAAM,qBAAqB,MAAM,CAAC,EAAE,IAAI,CAAC;IAC9G,CAAC;IACD,IAAI,MAAM,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;QAC7B,OAAO,IAAI,IAAI,KAAK,GAAG,kCAAkC,MAAM,CAAC,IAAI,OAAO,MAAM,CAAC,MAAM,EAAE,CAAC;IAC7F,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC"}
@@ -0,0 +1,46 @@
1
+ /**
2
+ * A code state's run: its `script`, read from the authoring backend, evaluated
3
+ * in the sandbox with its state's input and its state's tools — nothing else.
4
+ *
5
+ * The run decides nothing here: the script moves the session through
6
+ * `tools.archmax_advance` or ends it through `tools.archmax_raise`, which the
7
+ * step recorder holds, and the orchestrator (`automated.ts`) reads the outcome
8
+ * from that record and from whether the script finished cleanly.
9
+ */
10
+ import type { StructuredTool } from "@langchain/core/tools";
11
+ import type { WorkflowEventEmitter } from "../core/events.js";
12
+ import type { ScriptExecutor } from "../sandbox/executor.js";
13
+ /** Resolves a code state's declared `script` to its authoring-backend path, or refuses it with a reason. */
14
+ export type CodeScriptResolver = (declared: string) => {
15
+ ok: true;
16
+ path: string;
17
+ } | {
18
+ ok: false;
19
+ reason: string;
20
+ };
21
+ export interface CodeStateRun {
22
+ emit: WorkflowEventEmitter;
23
+ /** The executor reading sources from the authoring backend. */
24
+ executor: ScriptExecutor;
25
+ resolveScript: CodeScriptResolver;
26
+ sessionId: string;
27
+ state: string;
28
+ /** The state's declared `script`. */
29
+ script: string;
30
+ /** The script's input: `{ state, trigger?, variables }`. */
31
+ input: Record<string, unknown>;
32
+ /** The code state's tools, governed. */
33
+ tools: StructuredTool[];
34
+ /** The names those tools are listed and reached by. */
35
+ surface: readonly string[];
36
+ signal?: AbortSignal;
37
+ }
38
+ /**
39
+ * Run a code state's script. Settles with the error that stopped it, if one did
40
+ * — a script that cannot be placed or read, a foreign import, a throw, a
41
+ * timeout, a cancelled turn — and with nothing when it ran to its end. Each
42
+ * console line is reported as it was logged.
43
+ */
44
+ export declare function runCodeState(run: CodeStateRun): Promise<{
45
+ error?: string;
46
+ }>;
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Run a code state's script. Settles with the error that stopped it, if one did
3
+ * — a script that cannot be placed or read, a foreign import, a throw, a
4
+ * timeout, a cancelled turn — and with nothing when it ran to its end. Each
5
+ * console line is reported as it was logged.
6
+ */
7
+ export async function runCodeState(run) {
8
+ const resolved = run.resolveScript(run.script);
9
+ if (!resolved.ok)
10
+ return { error: resolved.reason };
11
+ const outcome = await run.executor.runCodeState(resolved.path, {
12
+ sessionId: run.sessionId,
13
+ args: run.input,
14
+ tools: run.tools,
15
+ surface: run.surface,
16
+ ...(run.signal ? { signal: run.signal } : {}),
17
+ });
18
+ for (const line of outcome.logs) {
19
+ if (line.trim())
20
+ run.emit({ type: "code-output", state: run.state, line: line.trimEnd() });
21
+ }
22
+ if (outcome.ok)
23
+ return {};
24
+ return { error: outcome.error?.message ?? "the script failed" };
25
+ }
26
+ //# sourceMappingURL=code-state.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"code-state.js","sourceRoot":"","sources":["../../src/workflow/code-state.ts"],"names":[],"mappings":"AAkCA;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY,CAAC,GAAiB;IAClD,MAAM,QAAQ,GAAG,GAAG,CAAC,aAAa,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;IAC/C,IAAI,CAAC,QAAQ,CAAC,EAAE;QAAE,OAAO,EAAE,KAAK,EAAE,QAAQ,CAAC,MAAM,EAAE,CAAC;IACpD,MAAM,OAAO,GAAG,MAAM,GAAG,CAAC,QAAQ,CAAC,YAAY,CAAC,QAAQ,CAAC,IAAI,EAAE;QAC7D,SAAS,EAAE,GAAG,CAAC,SAAS;QACxB,IAAI,EAAE,GAAG,CAAC,KAAK;QACf,KAAK,EAAE,GAAG,CAAC,KAAK;QAChB,OAAO,EAAE,GAAG,CAAC,OAAO;QACpB,GAAG,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KAC9C,CAAC,CAAC;IACH,KAAK,MAAM,IAAI,IAAI,OAAO,CAAC,IAAI,EAAE,CAAC;QAChC,IAAI,IAAI,CAAC,IAAI,EAAE;YAAE,GAAG,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,aAAa,EAAE,KAAK,EAAE,GAAG,CAAC,KAAK,EAAE,IAAI,EAAE,IAAI,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;IAC7F,CAAC;IACD,IAAI,OAAO,CAAC,EAAE;QAAE,OAAO,EAAE,CAAC;IAC1B,OAAO,EAAE,KAAK,EAAE,OAAO,CAAC,KAAK,EAAE,OAAO,IAAI,mBAAmB,EAAE,CAAC;AAClE,CAAC"}
@@ -1,23 +1,25 @@
1
1
  /**
2
2
  * The control tools: `archmax_advance`, `archmax_wait`, `archmax_reset`,
3
- * `archmax_raise`, `archmax_get_variables`, `archmax_set_variables`.
3
+ * `archmax_raise`, `archmax_get_variables`, `archmax_set_variables` — and
4
+ * `archmax_get_history`, which only a grader state is offered.
4
5
  *
5
6
  * Each is a declaration whose body never runs in a wired assembly: governance
6
- * intercepts the call in `wrapToolCall`, where checkpointed state is in hand, and
7
- * services it with the handler here. A handler returns the tool message the
8
- * model reads and, when the call changed the run, the `Command` committing it.
7
+ * intercepts the session's agent's call in `wrapToolCall`, where checkpointed
8
+ * state is in hand, and services it with the handler here. A handler returns the
9
+ * tool message the model reads and, when the call changed the run, the `Command`
10
+ * committing it. An automated state's controls (`automated-controls.ts`) reuse
11
+ * the same schemas, handlers and {@link transitionUpdate}.
9
12
  */
10
13
  import { ToolMessage } from "@langchain/core/messages";
11
14
  import type { StructuredTool } from "@langchain/core/tools";
12
15
  import { Command } from "@langchain/langgraph";
13
16
  import { z } from "zod";
14
17
  import { type MountPrefixes } from "../core/zones.js";
15
- import type { LifecycleContext, LifecycleRunner } from "../lifecycle/runner.js";
16
18
  import type { WorkflowMachine } from "../machine/machine.js";
17
19
  import { ADVANCE_TOOL, GET_VARIABLES_TOOL, RAISE_TOOL, RESET_TOOL, SET_VARIABLES_TOOL, WAIT_TOOL } from "../machine/tool-names.js";
18
20
  import { type UnresolvedGlob, type VariableStore } from "../machine/variables.js";
19
21
  import { type FileValueCheck } from "./signature-checks.js";
20
- import { type PendingDecision, type PendingInput, type RaiseRecord, type WorkflowStateFields } from "./state.js";
22
+ import { type MoveKind, type PendingDecision, type PendingInput, type RaiseRecord, type WorkflowStateFields, type WorkflowUpdate } from "./state.js";
21
23
  export { ADVANCE_TOOL, GET_VARIABLES_TOOL, RAISE_TOOL, RESET_TOOL, SET_VARIABLES_TOOL, WAIT_TOOL };
22
24
  /** The one refusal shape: an error-status tool message, so the model self-corrects and a view classifies it. */
23
25
  export declare function refusal(name: string, toolCallId: string, text: string): ToolMessage;
@@ -71,36 +73,66 @@ export declare const setVariablesSchema: z.ZodObject<{
71
73
  export declare function createControlTools(opts?: {
72
74
  child?: boolean;
73
75
  }): StructuredTool[];
76
+ /** One move along a declared edge, as a trail step and a park will record it. */
77
+ export interface Move {
78
+ to: string;
79
+ /** Who moved the session: its agent, a grader state or a code state. */
80
+ kind: MoveKind;
81
+ reason: string;
82
+ /** Attached evidence paths, already validated; only into a human state. */
83
+ evidence?: readonly string[];
84
+ }
85
+ /**
86
+ * The update a move commits — the target position, the trail step, a cleared
87
+ * rejection marker and a fresh turn budget — plus, into a human state, the park
88
+ * record opened in its closing phase. The one derivation every mover shares: the
89
+ * session's agent through {@link handleAdvance}, and an automated state's run.
90
+ * Messages are the caller's (a tool reply, a runtime note).
91
+ */
92
+ export declare function transitionUpdate(machine: WorkflowMachine, state: unknown, move: Move): {
93
+ update: WorkflowUpdate;
94
+ park?: PendingDecision;
95
+ };
96
+ /**
97
+ * Why `from` may not be left for `to` right now, or `undefined` when it may: the
98
+ * kernel's transition verdict — the state's `requires` against `variables`, then
99
+ * the declared edge. Every refusal is recoverable: the mover sets what is owed,
100
+ * or picks a valid target.
101
+ */
102
+ export declare function transitionRefusal(machine: WorkflowMachine, from: string, to: string, variables: VariableStore): string | undefined;
103
+ /**
104
+ * Evidence an advance attaches, validated for the target: accepted only into a
105
+ * human state, and only paths the session itself could read.
106
+ */
107
+ export declare function advanceEvidence(machine: WorkflowMachine, to: string, attached: readonly string[], mounts?: MountPrefixes): EvidenceValidation;
74
108
  export interface AdvanceRequest {
75
109
  /** Tool call id, echoed on the resulting ToolMessage. */
76
110
  toolCallId: string;
77
- /** The id this call is reported under on the event stream (the provider's, else the generated fallback). */
78
- callId?: string;
79
111
  args: Record<string, unknown>;
80
112
  /** Checkpointed agent state at the time of the call. */
81
113
  state: unknown;
82
- /** Lifecycle context; its `iterations` are seeded from state and committed back. */
83
- ctx: LifecycleContext;
84
114
  }
85
115
  export interface AdvanceOutcome {
86
116
  message: Command | ToolMessage;
87
117
  moved?: {
88
118
  from: string;
89
119
  to: string;
120
+ reason: string;
90
121
  /** The decision record committed when `to` is a human state. */
91
122
  park?: PendingDecision;
92
123
  };
93
124
  }
94
125
  /**
95
- * Attempt a transition and commit the outcome: `workflowState` and the `agent`
96
- * trail step on success, `iterations` always, and — into a human state —
97
- * the pending-decision record with the park opened in its closing phase.
126
+ * Service the session's agent's `archmax_advance`: validate the arguments, the
127
+ * evidence and the transition, then commit {@link transitionUpdate} with the
128
+ * reply the agent reads. A refusal leaves the session exactly where it was — no
129
+ * trail step — and replies without erroring the message, so the agent corrects
130
+ * the call rather than reading a failed run.
98
131
  */
99
132
  export declare function handleAdvance(opts: {
100
133
  machine: WorkflowMachine;
101
- lifecycle: LifecycleRunner;
102
134
  mountPrefixes?: MountPrefixes;
103
- }, request: AdvanceRequest): Promise<AdvanceOutcome>;
135
+ }, request: AdvanceRequest): AdvanceOutcome;
104
136
  /** The accepted `until` forms, quoted verbatim in every rejection. */
105
137
  export declare const WAIT_UNTIL_FORMS: string;
106
138
  export type WaitUntilResult = {
@@ -150,9 +182,9 @@ export interface ResetOutcome {
150
182
  };
151
183
  }
152
184
  /**
153
- * Service a reset: move back to the entry state and clear what gates progress
154
- * (correction budgets, `beforeDone`). Evidence — messages, files, variables, the
155
- * trail — is left alone: a reset moves the machine, not the history.
185
+ * Service a reset: move back to the entry state. Evidence — messages, files,
186
+ * variables, the trail — is left alone: a reset moves the machine, not the
187
+ * history.
156
188
  */
157
189
  export declare function handleReset(machine: WorkflowMachine, request: ResetRequest): ResetOutcome;
158
190
  export interface RaiseRequest {
@@ -170,9 +202,9 @@ export interface RaiseOutcome {
170
202
  * Service a raise: end the session as a failure in the state it was called in.
171
203
  * Commits the record and `status: failed`, and drops a pending rejection — the
172
204
  * agent's own account of the failure is what the session ends with. The turn
173
- * ends at the next model hook; nothing routes and no hook runs. Refused, with the
174
- * session left in place, for invalid arguments or a message making other calls:
175
- * those run concurrently, so a raise beside them could not mean one thing.
205
+ * ends at the next model hook; nothing routes and nothing further runs. Refused,
206
+ * with the session left in place, for invalid arguments or a message making other
207
+ * calls: those run concurrently, so a raise beside them could not mean one thing.
176
208
  */
177
209
  export declare function handleRaise(machine: WorkflowMachine, request: RaiseRequest): RaiseOutcome;
178
210
  export interface VariableToolRequest {
@@ -209,8 +241,7 @@ fileRefusal?: string): SetVariablesOutcome;
209
241
  export declare function fileReturnsRefusal(machine: WorkflowMachine, state: unknown, args: Record<string, unknown>, check: FileValueCheck): Promise<string | undefined>;
210
242
  /** Wrap an `archmax_set_variables` outcome as the update that commits its delta. */
211
243
  export declare function setVariablesCommand(outcome: SetVariablesOutcome): Command | ToolMessage;
212
- /** The variables a state still owes before it may be left — its `requires` minus what is set. */
213
- export declare function unmetRequirements(required: string[], store: VariableStore): string[];
244
+ export { unmetRequirements } from "../kernel/kernel.js";
214
245
  /**
215
246
  * The wording for a `${{…}}` reference in the agent's own tool arguments that
216
247
  * could not be resolved: a correctable refusal carrying the two fixes it might