@archmax-ai/harness 0.8.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 (219) hide show
  1. package/README.md +58 -14
  2. package/dist/agent.d.ts +4 -4
  3. package/dist/agent.js +4 -4
  4. package/dist/assembly/compose.d.ts +5 -24
  5. package/dist/assembly/compose.js +40 -41
  6. package/dist/assembly/compose.js.map +1 -1
  7. package/dist/assembly/delegation-registry.js +3 -14
  8. package/dist/assembly/delegation-registry.js.map +1 -1
  9. package/dist/assembly/index.d.ts +18 -15
  10. package/dist/assembly/index.js +50 -32
  11. package/dist/assembly/index.js.map +1 -1
  12. package/dist/assembly/plain.js +1 -2
  13. package/dist/assembly/plain.js.map +1 -1
  14. package/dist/authoring-skill/archmax-harness/README.md +5 -5
  15. package/dist/authoring-skill/archmax-harness/SKILL.md +72 -30
  16. package/dist/authoring-skill/archmax-harness/references/backend-integration.md +35 -23
  17. package/dist/authoring-skill/archmax-harness/references/cases.md +44 -10
  18. package/dist/authoring-skill/archmax-harness/references/{hook-and-test-scripts.md → code-state-and-test-scripts.md} +617 -313
  19. package/dist/authoring-skill/archmax-harness/references/code-states-and-scripts.md +115 -0
  20. package/dist/authoring-skill/archmax-harness/references/diagnostics.md +40 -7
  21. package/dist/authoring-skill/archmax-harness/references/wiring.md +19 -10
  22. package/dist/authoring-skill/archmax-harness/references/workflow-schema.md +416 -276
  23. package/dist/authoring-skill/archmax-harness/references/workflow-yaml.md +161 -62
  24. package/dist/cli/state-flow.d.ts +1 -1
  25. package/dist/cli/state-flow.js +18 -28
  26. package/dist/cli/state-flow.js.map +1 -1
  27. package/dist/cli/turn.d.ts +1 -1
  28. package/dist/cli/turn.js +2 -3
  29. package/dist/cli/turn.js.map +1 -1
  30. package/dist/core/clock.d.ts +26 -0
  31. package/dist/core/clock.js +64 -0
  32. package/dist/core/clock.js.map +1 -0
  33. package/dist/core/code-description.d.ts +3 -3
  34. package/dist/core/code-description.js +3 -3
  35. package/dist/core/deepagents.d.ts +5 -5
  36. package/dist/core/deepagents.js +4 -4
  37. package/dist/core/events.d.ts +23 -42
  38. package/dist/core/events.js +21 -24
  39. package/dist/core/events.js.map +1 -1
  40. package/dist/core/message-readers.d.ts +22 -2
  41. package/dist/core/message-readers.js +31 -0
  42. package/dist/core/message-readers.js.map +1 -1
  43. package/dist/core/messages.d.ts +1 -23
  44. package/dist/core/messages.js +2 -35
  45. package/dist/core/messages.js.map +1 -1
  46. package/dist/core/mounts.js +3 -3
  47. package/dist/core/platform-prompt.generated.js +1 -1
  48. package/dist/core/platform-prompt.generated.js.map +1 -1
  49. package/dist/core/session-zone.d.ts +1 -1
  50. package/dist/core/session-zone.js +1 -1
  51. package/dist/core/workspace-context.d.ts +1 -1
  52. package/dist/core/workspace.d.ts +1 -1
  53. package/dist/core/workspace.js +1 -1
  54. package/dist/core/zones.d.ts +4 -4
  55. package/dist/core/zones.js +5 -5
  56. package/dist/core/zones.js.map +1 -1
  57. package/dist/env.d.ts +9 -9
  58. package/dist/index.d.ts +3 -7
  59. package/dist/index.js +2 -4
  60. package/dist/index.js.map +1 -1
  61. package/dist/kernel/kernel.d.ts +31 -61
  62. package/dist/kernel/kernel.js +57 -114
  63. package/dist/kernel/kernel.js.map +1 -1
  64. package/dist/machine/allow.d.ts +17 -2
  65. package/dist/machine/allow.js +16 -6
  66. package/dist/machine/allow.js.map +1 -1
  67. package/dist/machine/lint-spec.js +68 -12
  68. package/dist/machine/lint-spec.js.map +1 -1
  69. package/dist/machine/machine.d.ts +39 -16
  70. package/dist/machine/machine.js +72 -49
  71. package/dist/machine/machine.js.map +1 -1
  72. package/dist/machine/spec-schema.d.ts +34 -179
  73. package/dist/machine/spec-schema.js +93 -106
  74. package/dist/machine/spec-schema.js.map +1 -1
  75. package/dist/machine/tool-names.d.ts +34 -10
  76. package/dist/machine/tool-names.js +41 -10
  77. package/dist/machine/tool-names.js.map +1 -1
  78. package/dist/machine/tool-paths.d.ts +6 -0
  79. package/dist/machine/tool-paths.js +10 -0
  80. package/dist/machine/tool-paths.js.map +1 -1
  81. package/dist/machine/types.d.ts +14 -38
  82. package/dist/machine/types.js.map +1 -1
  83. package/dist/machine/validate-spec.d.ts +1 -1
  84. package/dist/machine/variables.d.ts +2 -0
  85. package/dist/machine/variables.js.map +1 -1
  86. package/dist/public/sandbox.d.ts +62 -66
  87. package/dist/public/sandbox.js +22 -23
  88. package/dist/public/sandbox.js.map +1 -1
  89. package/dist/public/spec.d.ts +12 -19
  90. package/dist/public/spec.js +11 -19
  91. package/dist/public/spec.js.map +1 -1
  92. package/dist/runtime/contract.d.ts +11 -12
  93. package/dist/runtime/contract.js +16 -16
  94. package/dist/runtime/contract.js.map +1 -1
  95. package/dist/sandbox/assets/parts/code-state.js +17 -0
  96. package/dist/sandbox/executor.d.ts +25 -7
  97. package/dist/sandbox/executor.js +56 -47
  98. package/dist/sandbox/executor.js.map +1 -1
  99. package/dist/sandbox/imports.d.ts +10 -10
  100. package/dist/sandbox/imports.js +11 -11
  101. package/dist/sandbox/imports.js.map +1 -1
  102. package/dist/sandbox/prelude.d.ts +5 -6
  103. package/dist/sandbox/prelude.js +38 -35
  104. package/dist/sandbox/prelude.js.map +1 -1
  105. package/dist/sandbox/ptc-gateway.d.ts +19 -18
  106. package/dist/sandbox/ptc-gateway.js +26 -22
  107. package/dist/sandbox/ptc-gateway.js.map +1 -1
  108. package/dist/sessions/operations.js +4 -5
  109. package/dist/sessions/operations.js.map +1 -1
  110. package/dist/sessions/resume.d.ts +12 -7
  111. package/dist/sessions/resume.js +12 -9
  112. package/dist/sessions/resume.js.map +1 -1
  113. package/dist/sessions/summary.d.ts +1 -1
  114. package/dist/testing/assertions.js +9 -4
  115. package/dist/testing/assertions.js.map +1 -1
  116. package/dist/testing/case-document.d.ts +2 -0
  117. package/dist/testing/case-document.js.map +1 -1
  118. package/dist/testing/case-schema.d.ts +1 -1
  119. package/dist/testing/case-schema.js +17 -1
  120. package/dist/testing/case-schema.js.map +1 -1
  121. package/dist/testing/driver.d.ts +4 -0
  122. package/dist/testing/driver.js +22 -3
  123. package/dist/testing/driver.js.map +1 -1
  124. package/dist/testing/grade.js +3 -3
  125. package/dist/testing/grade.js.map +1 -1
  126. package/dist/testing/interpreter.d.ts +2 -2
  127. package/dist/testing/interpreter.js +1 -0
  128. package/dist/testing/interpreter.js.map +1 -1
  129. package/dist/testing/runner.d.ts +2 -2
  130. package/dist/validate/validate.d.ts +1 -1
  131. package/dist/validate/validate.js +39 -70
  132. package/dist/validate/validate.js.map +1 -1
  133. package/dist/workflow/automated-controls.d.ts +63 -0
  134. package/dist/workflow/automated-controls.js +158 -0
  135. package/dist/workflow/automated-controls.js.map +1 -0
  136. package/dist/workflow/automated.d.ts +112 -0
  137. package/dist/workflow/automated.js +163 -0
  138. package/dist/workflow/automated.js.map +1 -0
  139. package/dist/workflow/checkpointer.d.ts +7 -0
  140. package/dist/workflow/checkpointer.js +28 -0
  141. package/dist/workflow/checkpointer.js.map +1 -1
  142. package/dist/workflow/code-state.d.ts +46 -0
  143. package/dist/workflow/code-state.js +26 -0
  144. package/dist/workflow/code-state.js.map +1 -0
  145. package/dist/workflow/control-tools.d.ts +54 -23
  146. package/dist/workflow/control-tools.js +121 -77
  147. package/dist/workflow/control-tools.js.map +1 -1
  148. package/dist/workflow/file-values.d.ts +4 -4
  149. package/dist/workflow/file-values.js +1 -1
  150. package/dist/workflow/file-values.js.map +1 -1
  151. package/dist/workflow/governance.d.ts +13 -22
  152. package/dist/workflow/governance.js +51 -87
  153. package/dist/workflow/governance.js.map +1 -1
  154. package/dist/workflow/grader-state.d.ts +55 -0
  155. package/dist/workflow/grader-state.js +182 -0
  156. package/dist/workflow/grader-state.js.map +1 -0
  157. package/dist/workflow/history.d.ts +11 -0
  158. package/dist/workflow/history.js +64 -0
  159. package/dist/workflow/history.js.map +1 -0
  160. package/dist/workflow/middleware.d.ts +14 -17
  161. package/dist/workflow/middleware.js +106 -74
  162. package/dist/workflow/middleware.js.map +1 -1
  163. package/dist/workflow/move-events.d.ts +21 -0
  164. package/dist/workflow/move-events.js +20 -0
  165. package/dist/workflow/move-events.js.map +1 -0
  166. package/dist/workflow/parks.d.ts +9 -2
  167. package/dist/workflow/parks.js +16 -8
  168. package/dist/workflow/parks.js.map +1 -1
  169. package/dist/workflow/paths.d.ts +9 -9
  170. package/dist/workflow/paths.js +19 -19
  171. package/dist/workflow/paths.js.map +1 -1
  172. package/dist/workflow/render-prompt.d.ts +7 -5
  173. package/dist/workflow/render-prompt.js +22 -37
  174. package/dist/workflow/render-prompt.js.map +1 -1
  175. package/dist/workflow/signature-checks.d.ts +2 -2
  176. package/dist/workflow/snapshot.js +5 -29
  177. package/dist/workflow/snapshot.js.map +1 -1
  178. package/dist/workflow/state.d.ts +19 -6
  179. package/dist/workflow/state.js +24 -8
  180. package/dist/workflow/state.js.map +1 -1
  181. package/dist/workflow/sub-workflow.d.ts +3 -3
  182. package/dist/workflow/tool-service.d.ts +1 -9
  183. package/dist/workflow/tool-service.js +21 -24
  184. package/dist/workflow/tool-service.js.map +1 -1
  185. package/dist/workflow/turn-boundary.d.ts +2 -2
  186. package/dist/workflow/turn-boundary.js +10 -7
  187. package/dist/workflow/turn-boundary.js.map +1 -1
  188. package/dist/workflow/turn-runner.js +30 -2
  189. package/dist/workflow/turn-runner.js.map +1 -1
  190. package/package.json +1 -1
  191. package/skills/archmax-harness/README.md +5 -5
  192. package/skills/archmax-harness/SKILL.md +72 -30
  193. package/skills/archmax-harness/references/backend-integration.md +35 -23
  194. package/skills/archmax-harness/references/cases.md +44 -10
  195. package/skills/archmax-harness/references/{hook-and-test-scripts.md → code-state-and-test-scripts.md} +617 -313
  196. package/skills/archmax-harness/references/code-states-and-scripts.md +115 -0
  197. package/skills/archmax-harness/references/diagnostics.md +40 -7
  198. package/skills/archmax-harness/references/wiring.md +19 -10
  199. package/skills/archmax-harness/references/workflow-schema.md +416 -276
  200. package/skills/archmax-harness/references/workflow-yaml.md +161 -62
  201. package/dist/authoring-skill/archmax-harness/references/hooks-and-scripts.md +0 -88
  202. package/dist/lifecycle/hook-shape.d.ts +0 -44
  203. package/dist/lifecycle/hook-shape.js +0 -66
  204. package/dist/lifecycle/hook-shape.js.map +0 -1
  205. package/dist/lifecycle/runner.d.ts +0 -183
  206. package/dist/lifecycle/runner.js +0 -373
  207. package/dist/lifecycle/runner.js.map +0 -1
  208. package/dist/lifecycle/transcript.d.ts +0 -27
  209. package/dist/lifecycle/transcript.js +0 -43
  210. package/dist/lifecycle/transcript.js.map +0 -1
  211. package/dist/rubrics/rubrics.d.ts +0 -135
  212. package/dist/rubrics/rubrics.js +0 -145
  213. package/dist/rubrics/rubrics.js.map +0 -1
  214. package/dist/sandbox/assets/parts/core.js +0 -22
  215. package/dist/sandbox/assets/parts/lifecycle-hook.js +0 -47
  216. package/dist/sandbox/bridge.d.ts +0 -16
  217. package/dist/sandbox/bridge.js +0 -95
  218. package/dist/sandbox/bridge.js.map +0 -1
  219. package/skills/archmax-harness/references/hooks-and-scripts.md +0 -88
@@ -1,183 +0,0 @@
1
- import type { RunnableConfig } from "@langchain/core/runnables";
2
- import type { StructuredTool } from "@langchain/core/tools";
3
- import { type ScriptExecutor, type ScriptOutcome } from "../sandbox/executor.js";
4
- import type { WorkflowMachine } from "../machine/machine.js";
5
- import type { Hook } from "../machine/types.js";
6
- import { type Rubric } from "../rubrics/rubrics.js";
7
- import type { VariableStore } from "../machine/variables.js";
8
- import { type WorkflowEventHandler } from "../core/events.js";
9
- export type LifecycleVerdict = "ok" | "correct" | "veto";
10
- /** What a hook said, once its return value has been read. */
11
- export interface LifecycleDecision {
12
- verdict: LifecycleVerdict;
13
- reason: string;
14
- rubric?: string;
15
- }
16
- /**
17
- * Interpret a lifecycle hook's return value into a decision, an error, or
18
- * `null` (no opinion — proceed).
19
- *
20
- * **One contract for every hook kind**, the one `HookResult` declares: a verdict
21
- * object decides, a bare `false` vetoes, returning nothing is `ok`, and any
22
- * *other* object fails closed with its keys named. A hook's return value is its
23
- * verdict and nothing else, so an object that is not one is a verdict its author
24
- * got wrong; reading it as `ok` would silently permit what the hook meant to
25
- * block, with nothing said.
26
- *
27
- * A **script** hook's value arrives already reduced — the sandbox wrapper
28
- * applies the same rules and throws on the last one — so what reaches here from
29
- * a script is a verdict or an error outcome. The rules are restated because a
30
- * custom `hookExecutors` kind hands its value through raw, and a consumer's
31
- * executor is held to the same contract as a script: one governance vocabulary,
32
- * whoever implements the kind.
33
- */
34
- export declare function parseLifecycleDecision(outcome: ScriptOutcome): LifecycleDecision | {
35
- error: string;
36
- } | null;
37
- export interface LifecycleContext {
38
- sessionId: string;
39
- tools: StructuredTool[];
40
- messages: unknown[];
41
- taskTool?: StructuredTool;
42
- config: RunnableConfig;
43
- /**
44
- * Grade-and-retry iterations already spent, keyed per hook by
45
- * {@link iterationKey} — not per state. Two `after` hooks on one state have
46
- * independent budgets, and a hook that passes cannot clear the count of the
47
- * one still asking for corrections (issue #62).
48
- */
49
- iterations: Record<string, number>;
50
- /**
51
- * The trigger that started the run (`id` + optional `args`), read from
52
- * checkpointed state. Merged into every hook's script arguments so a
53
- * `before`/`after` script can read how the run began.
54
- */
55
- trigger?: {
56
- id: string;
57
- };
58
- /**
59
- * The run's variables at the time the hook runs, as a plain `name → value`
60
- * map. Read-only by construction: the sandbox gets a serialized copy. A hook
61
- * that could *write* variables would be editing the governance inputs of the
62
- * state it judges, which is why the variable tools are excluded from PTC.
63
- */
64
- variables?: Record<string, unknown>;
65
- /**
66
- * The same variables as the checkpointed **store** — value plus lock state —
67
- * for the kernel's `requires` gate. Must be the run's real store: omitted, the
68
- * kernel sees an empty store and refuses to leave any state that declares
69
- * `requires`.
70
- */
71
- variableStore?: VariableStore;
72
- /**
73
- * The abort signal of the turn the hook runs in, read where the hook runs,
74
- * not `config`'s, which is captured at the session's last model call. Once it
75
- * aborts, a script hook's eval settles with an error and its calls are refused.
76
- */
77
- signal?: AbortSignal;
78
- }
79
- /**
80
- * A phase rejection: why the hook phase blocked, and whether the failure is
81
- * **terminal** — a hook execution error or an exhausted correction budget,
82
- * which retrying in place cannot fix (the turn ends rejected, subject to
83
- * `on_error` routing) — as opposed to a recoverable rejection (a deliberate
84
- * veto or a correction with attempts remaining), where the agent stays in the
85
- * state to try again.
86
- */
87
- export interface PhaseRejection {
88
- reason: string;
89
- terminal: boolean;
90
- }
91
- /**
92
- * The result of {@link LifecycleRunner.attemptTransition}: whether the
93
- * transition passed its hooks, and the resulting judge-correction counts for
94
- * the caller to commit to the checkpoint. Correction counts advance even on a
95
- * rejection (a consumed judge correction), so they are returned in both cases.
96
- * `terminal` marks a rejection retrying cannot fix (see {@link PhaseRejection}).
97
- */
98
- export type TransitionOutcome = {
99
- ok: true;
100
- from: string;
101
- to: string;
102
- corrections: Record<string, number>;
103
- } | {
104
- ok: false;
105
- reason: string;
106
- terminal: boolean;
107
- corrections: Record<string, number>;
108
- };
109
- /**
110
- * Executes one lifecycle hook of a given kind, returning the raw
111
- * {@link ScriptOutcome} the runner reduces (parse → kernel verdict → events), so
112
- * every hook kind flows through the same fail-closed path. `script` and
113
- * `rubric` are built in; consumers register additional kinds via
114
- * `createAgent`'s `hookExecutors` option. An executor that throws or returns an
115
- * error outcome vetoes the transition.
116
- */
117
- export type HookExecutor = (hook: Hook, ctx: LifecycleContext, args: Record<string, unknown>) => Promise<ScriptOutcome>;
118
- /**
119
- * Resolves a hook's declared `script:` value to the authoring-plane path its
120
- * source lives at, or refuses it with a reason (see `resolveHookScript`).
121
- */
122
- export type HookScriptResolver = (declared: string) => {
123
- ok: true;
124
- path: string;
125
- } | {
126
- ok: false;
127
- reason: string;
128
- };
129
- /** The built-in hook kinds, which consumer executors may not shadow. */
130
- export declare const BUILTIN_HOOK_KINDS: readonly ["script", "rubric"];
131
- /**
132
- * Runs deterministic `before`/`after` hooks (scripts or grading rubrics) at the
133
- * machine's fixed points, in the same backend-backed interpreter as the model's
134
- * own sandbox tool calls.
135
- */
136
- export declare class LifecycleRunner {
137
- private readonly machine;
138
- private readonly executor;
139
- private readonly rubrics;
140
- private readonly ptcNames;
141
- private readonly emit;
142
- /** Hook kind → executor. Built-ins (`script`, `rubric`) plus registered custom kinds. */
143
- private readonly hookExecutors;
144
- /**
145
- * Maps a hook's declared `script:` value to the path its source is read from.
146
- * Injected so the runner stays ignorant of workspace layout: the harness binds
147
- * it to the running workflow (workflow-relative, confined to `hooks/`). The
148
- * identity default keeps a bare runner working.
149
- */
150
- private readonly resolveScript;
151
- /** Deprecations already reported — each is said once per assembly. */
152
- constructor(machine: WorkflowMachine, executor: ScriptExecutor, rubrics: Map<string, Rubric>, ptcNames: string[], hookExecutors?: Record<string, HookExecutor>, onEvent?: WorkflowEventHandler, opts?: {
153
- resolveScript?: HookScriptResolver;
154
- });
155
- resolvePtcTools(allTools: unknown[]): StructuredTool[];
156
- /**
157
- * The runtime's own dispatch for an inline grader, through the framework
158
- * `task` tool. Reached only by {@link runRubric} — never wired into a script's
159
- * sandbox, which has no name to dispatch by.
160
- */
161
- private rubricDispatch;
162
- private runScript;
163
- private runRubric;
164
- /**
165
- * Dispatch a single tagged hook through its kind's registered executor.
166
- * An unknown kind (no registered executor) produces an error outcome that
167
- * reduces to a fail-closed veto — the same path as any hook execution error.
168
- */
169
- private runHook;
170
- private applyDecision;
171
- runPhase(state: string, phase: "before" | "after", ctx: LifecycleContext, extraArgs?: Record<string, unknown>, veto?: boolean): Promise<PhaseRejection | null>;
172
- private runSingleHook;
173
- attemptTransition(from: string, to: string, ctx: LifecycleContext, reason?: string,
174
- /**
175
- * The tool call driving this attempt, when one is. Carried onto the `advance`
176
- * event so a consumer can attribute the transition to the call that made it;
177
- * a transition the runtime itself performs passes nothing.
178
- */
179
- options?: {
180
- callId?: string;
181
- }): Promise<TransitionOutcome>;
182
- dispose(sessionId: string): void;
183
- }
@@ -1,373 +0,0 @@
1
- import { runContextFromMessages } from "../core/messages.js";
2
- import { createSubagentBridgeDispatch } from "../sandbox/bridge.js";
3
- import { PROCESS_SESSION, } from "../sandbox/executor.js";
4
- import { resolvePtcTools } from "../sandbox/tools.js";
5
- import { afterHookLabel, hookKind, hookMaxIterations, iterationKey } from "./hook-shape.js";
6
- import { hookTranscript } from "./transcript.js";
7
- import { buildRubricTaskDescription, isRubricVerdict, resolveRubricResponseFormat, rubricId, } from "../rubrics/rubrics.js";
8
- import { createWorkflowEventEmitter, } from "../core/events.js";
9
- import { decide, reduceHookFact } from "../kernel/kernel.js";
10
- /**
11
- * Interpret a lifecycle hook's return value into a decision, an error, or
12
- * `null` (no opinion — proceed).
13
- *
14
- * **One contract for every hook kind**, the one `HookResult` declares: a verdict
15
- * object decides, a bare `false` vetoes, returning nothing is `ok`, and any
16
- * *other* object fails closed with its keys named. A hook's return value is its
17
- * verdict and nothing else, so an object that is not one is a verdict its author
18
- * got wrong; reading it as `ok` would silently permit what the hook meant to
19
- * block, with nothing said.
20
- *
21
- * A **script** hook's value arrives already reduced — the sandbox wrapper
22
- * applies the same rules and throws on the last one — so what reaches here from
23
- * a script is a verdict or an error outcome. The rules are restated because a
24
- * custom `hookExecutors` kind hands its value through raw, and a consumer's
25
- * executor is held to the same contract as a script: one governance vocabulary,
26
- * whoever implements the kind.
27
- */
28
- export function parseLifecycleDecision(outcome) {
29
- if (!outcome.ok)
30
- return { error: outcome.error?.message ?? "script error" };
31
- const value = outcome.value;
32
- if (isRubricVerdict(value)) {
33
- return {
34
- verdict: value.verdict,
35
- reason: value.reason,
36
- ...(value.rubric !== undefined ? { rubric: value.rubric } : {}),
37
- };
38
- }
39
- if (value === false)
40
- return { verdict: "veto", reason: "precondition not met" };
41
- if (value !== null && typeof value === "object") {
42
- return {
43
- error: `hook returned ${describeNonVerdict(value)}, which is not a verdict — return ` +
44
- `{ verdict: "ok" | "correct" | "veto", reason }, false, or nothing at all`,
45
- };
46
- }
47
- return null;
48
- }
49
- /**
50
- * Name a non-verdict object by its keys, never its values, so a diagnostic
51
- * cannot leak what the hook was inspecting. Mirrors `__hookShape` in the
52
- * sandbox prelude, which does the same for a script hook.
53
- */
54
- function describeNonVerdict(value) {
55
- if (Array.isArray(value))
56
- return "an array";
57
- const keys = Object.keys(value);
58
- if (keys.length === 0)
59
- return "an object with no keys";
60
- const shown = keys
61
- .slice(0, 6)
62
- .map((key) => `'${key}'`)
63
- .join(", ");
64
- return `an object with ${keys.length > 6 ? "keys including " : "keys "}${shown}`;
65
- }
66
- /** The built-in hook kinds, which consumer executors may not shadow. */
67
- export const BUILTIN_HOOK_KINDS = ["script", "rubric"];
68
- /** Short raw-output excerpt surfaced when a judge response cannot be parsed. */
69
- function snippet(value) {
70
- let text;
71
- try {
72
- text = typeof value === "string" ? value : JSON.stringify(value);
73
- }
74
- catch {
75
- text = String(value);
76
- }
77
- if (text === undefined || text === "undefined")
78
- text = "(no output)";
79
- return text.length > 200 ? `${text.slice(0, 200)}…` : text;
80
- }
81
- /**
82
- * Runs deterministic `before`/`after` hooks (scripts or grading rubrics) at the
83
- * machine's fixed points, in the same backend-backed interpreter as the model's
84
- * own sandbox tool calls.
85
- */
86
- export class LifecycleRunner {
87
- machine;
88
- executor;
89
- rubrics;
90
- ptcNames;
91
- emit;
92
- /** Hook kind → executor. Built-ins (`script`, `rubric`) plus registered custom kinds. */
93
- hookExecutors;
94
- /**
95
- * Maps a hook's declared `script:` value to the path its source is read from.
96
- * Injected so the runner stays ignorant of workspace layout: the harness binds
97
- * it to the running workflow (workflow-relative, confined to `hooks/`). The
98
- * identity default keeps a bare runner working.
99
- */
100
- resolveScript;
101
- /** Deprecations already reported — each is said once per assembly. */
102
- constructor(machine, executor, rubrics, ptcNames, hookExecutors, onEvent, opts = {}) {
103
- this.machine = machine;
104
- this.executor = executor;
105
- this.rubrics = rubrics;
106
- this.ptcNames = ptcNames;
107
- this.emit = createWorkflowEventEmitter(onEvent);
108
- this.resolveScript = opts.resolveScript ?? ((declared) => ({ ok: true, path: declared }));
109
- // Built-ins first; consumer executors add kinds alongside them (built-ins
110
- // are non-shadowable, enforced at assembly).
111
- this.hookExecutors = new Map([
112
- ["script", (hook, ctx, args) => this.runScript(String(hook.script), ctx, args)],
113
- ]);
114
- for (const [kind, exec] of Object.entries(hookExecutors ?? {})) {
115
- this.hookExecutors.set(kind, exec);
116
- }
117
- }
118
- resolvePtcTools(allTools) {
119
- return resolvePtcTools(allTools, this.ptcNames);
120
- }
121
- /**
122
- * The runtime's own dispatch for an inline grader, through the framework
123
- * `task` tool. Reached only by {@link runRubric} — never wired into a script's
124
- * sandbox, which has no name to dispatch by.
125
- */
126
- rubricDispatch(ctx, lifecycleArgs) {
127
- if (!ctx.taskTool)
128
- return undefined;
129
- const base = createSubagentBridgeDispatch(ctx.taskTool, ctx.config, {
130
- emit: this.emit,
131
- ...(typeof lifecycleArgs.state === "string" ? { state: lifecycleArgs.state } : {}),
132
- });
133
- return async (input) => {
134
- const rubric = this.rubrics.get(input.subagentType);
135
- const description = input.description?.trim() ||
136
- buildRubricTaskDescription({ ...lifecycleArgs, ...runContextFromMessages(ctx.messages) });
137
- const responseSchema = input.responseSchema ?? (rubric ? resolveRubricResponseFormat(rubric) : undefined);
138
- return base({
139
- description,
140
- subagentType: input.subagentType,
141
- ...(responseSchema !== undefined
142
- ? { responseSchema: responseSchema }
143
- : {}),
144
- });
145
- };
146
- }
147
- async runScript(script, ctx, args) {
148
- // A hook that cannot be placed is a hook that cannot be trusted: refusing
149
- // here produces an error outcome, and an errored hook vetoes fail-closed —
150
- // the same posture as a hook that throws.
151
- const resolved = this.resolveScript(script);
152
- if (!resolved.ok) {
153
- return {
154
- ok: false,
155
- value: undefined,
156
- logs: [],
157
- error: { message: resolved.reason },
158
- formatted: `error: ${resolved.reason}`,
159
- };
160
- }
161
- return this.executor.runFile(resolved.path, {
162
- sessionId: ctx.sessionId,
163
- sessionNamespace: PROCESS_SESSION,
164
- args,
165
- tools: ctx.tools,
166
- // No `task()` for a script hook: an inline rubric has no name a script
167
- // could pass, so there is nothing to dispatch by. A script that wants a
168
- // model verdict gets a `rubric` hook declared beside it in the same list.
169
- lifecycle: true,
170
- ...(ctx.signal ? { signal: ctx.signal } : {}),
171
- });
172
- }
173
- async runRubric(name, ctx, args) {
174
- const dispatch = this.rubricDispatch(ctx, args);
175
- if (!dispatch) {
176
- const message = `rubric '${name}' could not be dispatched (no task tool)`;
177
- return { ok: false, value: undefined, logs: [], error: { message }, formatted: `error: ${message}` };
178
- }
179
- const rubric = this.rubrics.get(name);
180
- const responseSchema = rubric ? resolveRubricResponseFormat(rubric) : undefined;
181
- try {
182
- const value = await dispatch({
183
- subagentType: name,
184
- // The grader's payload keeps the compact `userRequest`/`history` view a
185
- // rubric's `instructions` are written against.
186
- description: buildRubricTaskDescription({ ...args, ...runContextFromMessages(ctx.messages) }),
187
- ...(responseSchema !== undefined ? { responseSchema } : {}),
188
- });
189
- // Fail closed on unreadable grader output, exactly like a thrown error: a
190
- // grader whose verdict cannot be read has approved nothing.
191
- const verdict = value && typeof value === "object" && isRubricVerdict(value)
192
- ? { ...value, rubric: name }
193
- : {
194
- verdict: "veto",
195
- reason: `rubric '${name}' returned no parseable verdict: ${snippet(value)}`,
196
- rubric: name,
197
- };
198
- return { ok: true, value: verdict, logs: [], formatted: JSON.stringify(verdict) };
199
- }
200
- catch (err) {
201
- const message = err.message ?? String(err);
202
- return { ok: false, value: undefined, logs: [], error: { message }, formatted: `error: ${message}` };
203
- }
204
- }
205
- /**
206
- * Dispatch a single tagged hook through its kind's registered executor.
207
- * An unknown kind (no registered executor) produces an error outcome that
208
- * reduces to a fail-closed veto — the same path as any hook execution error.
209
- */
210
- async runHook(hook, ctx, args, at) {
211
- const kind = hookKind(hook);
212
- // `rubric` is serviced here rather than through the executor map, because
213
- // dispatching an inline grader needs the hook's *position* — that is the id
214
- // the runtime registered it under, and a `HookExecutor` sees only the hook.
215
- // The kind is still non-shadowable: assembly checks `BUILTIN_HOOK_KINDS`.
216
- if (kind === "rubric") {
217
- return this.runRubric(rubricId(at.state, at.phase, at.index), ctx, args);
218
- }
219
- const executor = kind ? this.hookExecutors.get(kind) : undefined;
220
- if (!executor) {
221
- const message = kind
222
- ? `no executor registered for hook kind '${kind}'`
223
- : `malformed hook (expected a single-key tagged object)`;
224
- return { ok: false, value: undefined, logs: [], error: { message }, formatted: `error: ${message}` };
225
- }
226
- return executor(hook, ctx, args);
227
- }
228
- applyDecision(state, label, decision, ctx, opts) {
229
- this.emit({
230
- type: "hook-verdict",
231
- state,
232
- phase: opts.phase,
233
- label,
234
- verdict: decision.verdict,
235
- reason: decision.reason,
236
- });
237
- const budget = iterationKey(state, opts.phase, opts.index);
238
- const used = ctx.iterations[budget] ?? 0;
239
- // Iteration budget, uniform across hook kinds: the hook-level
240
- // `max_iterations` sidecar wins (it describes *this* state's retry loop); a
241
- // rubric hook falls back to the rubric's own `max_iterations`; otherwise 0
242
- // (a `correct` hard-vetoes).
243
- const rubric = decision.rubric ? this.rubrics.get(decision.rubric) : undefined;
244
- const maxIterations = opts.maxIterations ?? rubric?.max_iterations ?? 0;
245
- // The reduction rule lives in the decision kernel; the runner only executes
246
- // hooks and applies the verdict (correction bookkeeping + events).
247
- const verdict = reduceHookFact({ ...decision, maxIterations, iterationsUsed: used }, { phase: opts.phase, veto: opts.veto, to: opts.to });
248
- if (verdict.decision === "block") {
249
- if (verdict.correctionConsumed)
250
- ctx.iterations[budget] = used + 1;
251
- const reason = verdict.reason ?? decision.reason;
252
- this.emit({ type: "hook-rejected", state, phase: opts.phase, reason });
253
- // Exhausted iteration budget (after-phase correction flow only) cannot be
254
- // fixed by retrying in place; a deliberate veto, an in-budget correction,
255
- // or a before-phase rejection can. The kernel decides which this is, from
256
- // the same reduction that wrote the reason.
257
- return { reason, terminal: verdict.budgetExhausted === true };
258
- }
259
- // Only this hook's own budget is released: a passing hook ahead of a
260
- // correcting one must not hand the latter a fresh budget every attempt.
261
- delete ctx.iterations[budget];
262
- return null;
263
- }
264
- async runPhase(state, phase, ctx, extraArgs, veto = false) {
265
- const hooks = this.machine.lifecycleHooks()[state];
266
- const list = phase === "before" ? hooks?.before : hooks?.after;
267
- if (!list || list.length === 0)
268
- return null;
269
- // The hook input (`HookArgs` in the sandbox): the trigger reaches a hook as
270
- // its bare id — a run's *input* lives in `variables` — and the transcript as
271
- // plain messages.
272
- const scriptArgs = {
273
- state,
274
- phase,
275
- ...(ctx.trigger ? { trigger: ctx.trigger.id } : {}),
276
- variables: ctx.variables ?? {},
277
- messages: hookTranscript(ctx.messages),
278
- ...extraArgs,
279
- };
280
- const to = typeof extraArgs?.to === "string" ? extraArgs.to : undefined;
281
- // Run hooks in declaration order, short-circuiting on the first that fails.
282
- // The index travels: an inline rubric has no name, so its position in this
283
- // list is its identity — for dispatch and for its own retry budget.
284
- for (const [index, hook] of list.entries()) {
285
- const reject = await this.runSingleHook(state, phase, hook, ctx, scriptArgs, { veto, to, index });
286
- if (reject)
287
- return reject;
288
- }
289
- return null;
290
- }
291
- async runSingleHook(state, phase, hook, ctx, scriptArgs, opts) {
292
- const label = afterHookLabel(hook, opts.index);
293
- this.emit({ type: "hook-start", state, phase, label });
294
- const outcome = await this.runHook(hook, ctx, scriptArgs, {
295
- state,
296
- phase,
297
- index: opts.index,
298
- });
299
- for (const line of outcome.logs) {
300
- if (line.trim()) {
301
- this.emit({ type: "hook-output", state, line: line.trimEnd() });
302
- }
303
- }
304
- const parsed = parseLifecycleDecision(outcome);
305
- if (parsed && "error" in parsed) {
306
- this.emit({ type: "hook-rejected", state, phase, reason: parsed.error });
307
- // A hook that could not execute is a terminal failure: retrying the
308
- // same turn re-runs the same broken hook.
309
- return { reason: parsed.error, terminal: true };
310
- }
311
- if (!parsed) {
312
- if (phase === "before") {
313
- this.emit({ type: "hook-passed", state, phase });
314
- }
315
- return null;
316
- }
317
- const maxIterations = hookMaxIterations(hook);
318
- return this.applyDecision(state, label, parsed, ctx, {
319
- phase,
320
- veto: opts.veto,
321
- to: opts.to,
322
- index: opts.index,
323
- ...(maxIterations !== undefined ? { maxIterations } : {}),
324
- });
325
- }
326
- async attemptTransition(from, to, ctx, reason,
327
- /**
328
- * The tool call driving this attempt, when one is. Carried onto the `advance`
329
- * event so a consumer can attribute the transition to the call that made it;
330
- * a transition the runtime itself performs passes nothing.
331
- */
332
- options) {
333
- // Work on a copy of the correction counts so the attempt never mutates the
334
- // caller's context; the resulting counts are returned for the caller to
335
- // commit to the checkpoint.
336
- const corrections = { ...ctx.iterations };
337
- const localCtx = { ...ctx, iterations: corrections };
338
- // Edge validity is a pure, statically-decidable rule — route it through the
339
- // decision kernel so runtime and `agent validate` agree. Hook reduction runs
340
- // per-hook inside `runPhase` (also kernel-backed via `applyDecision`).
341
- const edgeVerdict = decide(this.machine, { kind: "transition", from, to, hookFacts: [] }, [], undefined, ctx.variableStore ?? {});
342
- if (edgeVerdict.decision === "block") {
343
- return {
344
- ok: false,
345
- reason: edgeVerdict.reason ?? `cannot advance from '${from}' to '${to}'.`,
346
- // An invalid edge is always recoverable: the agent picks a valid target.
347
- terminal: false,
348
- corrections,
349
- };
350
- }
351
- const trimmedReason = reason?.trim();
352
- const afterReject = await this.runPhase(from, "after", localCtx, { from, to, ...(trimmedReason ? { reason: trimmedReason } : {}) }, true);
353
- if (afterReject) {
354
- return { ok: false, reason: afterReject.reason, terminal: afterReject.terminal, corrections };
355
- }
356
- const beforeReject = await this.runPhase(to, "before", localCtx);
357
- if (beforeReject) {
358
- return { ok: false, reason: beforeReject.reason, terminal: beforeReject.terminal, corrections };
359
- }
360
- this.emit({
361
- type: "advance",
362
- from,
363
- to,
364
- ...(trimmedReason ? { reason: trimmedReason } : {}),
365
- ...(options?.callId ? { callId: options.callId } : {}),
366
- });
367
- return { ok: true, from, to, corrections };
368
- }
369
- dispose(sessionId) {
370
- this.executor.dispose(sessionId, PROCESS_SESSION);
371
- }
372
- }
373
- //# sourceMappingURL=runner.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"runner.js","sourceRoot":"","sources":["../../src/lifecycle/runner.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;AAC7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CAAC,CAAC,EAAE,CAAC;YACnD,GAAG,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;SACvD,CAAC,CAAC;QACH,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,EAAE,EAAE,WAAW,EAAE,CAAC;IAC7C,CAAC;IAED,OAAO,CAAC,SAAiB;QACvB,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,SAAS,EAAE,eAAe,CAAC,CAAC;IACpD,CAAC;CACF"}
@@ -1,27 +0,0 @@
1
- /**
2
- * One transcript message as a hook reads it: plain data, no LangChain classes.
3
- * `role` is `user`, `assistant`, `tool`, `system`, or `runtime` — the last for
4
- * a note the runtime wrote (an arrival, a decision, an error route), which a
5
- * model cannot read as a person speaking and a hook should not either.
6
- */
7
- export interface HookMessage {
8
- role: string;
9
- text: string;
10
- /** Assistant messages only: the tool calls the message made. */
11
- toolCalls?: {
12
- name: string;
13
- args: unknown;
14
- }[];
15
- /** Tool results only: the tool that produced the text. */
16
- tool?: string;
17
- /** Runtime notes only: which kind of note this is. */
18
- note?: string;
19
- }
20
- /** How much of the transcript a hook is handed: the most recent messages. */
21
- export declare const HOOK_TRANSCRIPT_LIMIT = 24;
22
- /**
23
- * The recent transcript as a hook receives it in `messages`, newest last. A
24
- * runtime note is carried in the transcript as a tool-call pair; only the half
25
- * holding the text is kept, as one `runtime` entry.
26
- */
27
- export declare function hookTranscript(messages: unknown[], limit?: number): HookMessage[];
@@ -1,43 +0,0 @@
1
- import { contentToString, messageTypeOf, runtimeNoteKind } from "../core/messages.js";
2
- const ROLE_BY_TYPE = {
3
- human: "user",
4
- ai: "assistant",
5
- system: "system",
6
- tool: "tool",
7
- function: "tool",
8
- };
9
- /** How much of the transcript a hook is handed: the most recent messages. */
10
- export const HOOK_TRANSCRIPT_LIMIT = 24;
11
- /**
12
- * The recent transcript as a hook receives it in `messages`, newest last. A
13
- * runtime note is carried in the transcript as a tool-call pair; only the half
14
- * holding the text is kept, as one `runtime` entry.
15
- */
16
- export function hookTranscript(messages, limit = HOOK_TRANSCRIPT_LIMIT) {
17
- const out = [];
18
- for (const raw of Array.isArray(messages) ? messages : []) {
19
- const msg = raw;
20
- const type = messageTypeOf(raw);
21
- const text = contentToString(msg.content);
22
- const note = runtimeNoteKind(raw);
23
- if (note !== null) {
24
- if (text.trim() === "")
25
- continue;
26
- out.push({ role: "runtime", text, note });
27
- continue;
28
- }
29
- const entry = { role: ROLE_BY_TYPE[type] ?? (type || "unknown"), text };
30
- const calls = msg.tool_calls;
31
- if ((type === "ai" || type === "assistant") && Array.isArray(calls) && calls.length > 0) {
32
- entry.toolCalls = calls.map((c) => {
33
- const call = c;
34
- return { name: String(call.name ?? ""), args: call.args ?? {} };
35
- });
36
- }
37
- if (entry.role === "tool" && typeof msg.name === "string")
38
- entry.tool = msg.name;
39
- out.push(entry);
40
- }
41
- return out.slice(-limit);
42
- }
43
- //# sourceMappingURL=transcript.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"transcript.js","sourceRoot":"","sources":["../../src/lifecycle/transcript.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAmBtF,MAAM,YAAY,GAA2B;IAC3C,KAAK,EAAE,MAAM;IACb,EAAE,EAAE,WAAW;IACf,MAAM,EAAE,QAAQ;IAChB,IAAI,EAAE,MAAM;IACZ,QAAQ,EAAE,MAAM;CACjB,CAAC;AAEF,6EAA6E;AAC7E,MAAM,CAAC,MAAM,qBAAqB,GAAG,EAAE,CAAC;AAExC;;;;GAIG;AACH,MAAM,UAAU,cAAc,CAAC,QAAmB,EAAE,KAAK,GAAG,qBAAqB;IAC/E,MAAM,GAAG,GAAkB,EAAE,CAAC;IAC9B,KAAK,MAAM,GAAG,IAAI,KAAK,CAAC,OAAO,CAAC,QAAQ,CA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