@archmax-ai/harness 0.9.0 → 1.0.1

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 +2 -2
  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
@@ -2,37 +2,37 @@
2
2
  * What each supported runtime version implies for the surfaces that used to
3
3
  * version themselves.
4
4
  *
5
- * Sandbox 2 = hooks are default-export functions returning `ok()` / `veto()` /
6
- * `correct()`,
7
- * plus typed `@archmax-ai/harness/*` import stripping. The test-case format has not
8
- * changed across runtime versions, which is exactly why it did not need an axis
9
- * of its own.
5
+ * Version 3 = the state types `agent`, `human`, `grader` and `code`, with no
6
+ * `before`/`after` hooks; sandbox 3 = a code state's script is a default-export
7
+ * function called with the state's input that moves the session through
8
+ * `tools.archmax_advance`, plus typed `@archmax-ai/harness/*` import stripping.
9
+ * Versions 1 and 2 (the hook contract) are retired: a workspace declaring one is
10
+ * refused rather than half-run. The test-case format has not changed across
11
+ * runtime versions, which is exactly why it did not need an axis of its own.
10
12
  *
11
13
  * This table is the single source of the supported set — adding a runtime
12
14
  * version is one entry here.
13
15
  */
14
16
  const CONTRACT_SURFACES = {
15
- "1": { sandbox: 1, testFormat: "1" },
16
- "2": { sandbox: 2, testFormat: "1" },
17
+ "3": { sandbox: 3, testFormat: "1" },
17
18
  };
19
+ /** Default contract version applied when metadata is omitted. */
20
+ export const DEFAULT_RUNTIME_VERSION = "3";
18
21
  /** The sandbox script contract applied when nothing resolves a runtime version. */
19
- export const DEFAULT_SANDBOX_VERSION = CONTRACT_SURFACES["2"].sandbox;
22
+ export const DEFAULT_SANDBOX_VERSION = CONTRACT_SURFACES[DEFAULT_RUNTIME_VERSION].sandbox;
20
23
  /** The runtime engine this package implements. */
21
24
  export const RUNTIME_ENGINE = "archmax-harness";
22
- /** Default contract version applied when metadata is omitted. */
23
- export const DEFAULT_RUNTIME_VERSION = "1";
24
25
  /** The contract resolved for workspaces that omit `runtime` metadata. */
25
26
  export const DEFAULT_RUNTIME_CONTRACT = {
26
27
  engine: RUNTIME_ENGINE,
27
28
  version: DEFAULT_RUNTIME_VERSION,
28
29
  };
29
30
  /**
30
- * The explicit set of runtime contracts the installed runtime supports.
31
- * Version 2 identifies the v2 authoring contract (two-file `workflow.yaml` /
32
- * `WORKFLOW.md` layout, declarative `tests:` block, typed sandbox imports,
33
- * verdict-returning hook functions). Load behavior is
34
- * layout-driven, not version-driven — the version is declarative metadata for
35
- * support checking, validation, and docs. Version 1 remains supported.
31
+ * The explicit set of runtime contracts the installed runtime supports. Version
32
+ * 3 identifies the current authoring contract (two-file `workflow.yaml` /
33
+ * `WORKFLOW.md` layout, declarative `tests:` block, typed sandbox imports, the
34
+ * four state types). Load behavior is layout-driven, not version-driven — the
35
+ * version is declarative metadata for support checking, validation, and docs.
36
36
  */
37
37
  export const SUPPORTED_RUNTIME_CONTRACTS = Object.keys(CONTRACT_SURFACES).map((version) => ({ engine: RUNTIME_ENGINE, version }));
38
38
  /** Render a contract as `engine@version` for messages and artifacts. */
@@ -1 +1 @@
1
- {"version":3,"file":"contract.js","sourceRoot":"","sources":["../../src/runtime/contract.ts"],"names":[],"mappings":"AA+BA;;;;;;;;;;;;GAYG;AACH,MAAM,iBAAiB,GAAsE;IAC3F,GAAG,EAAE,EAAE,OAAO,EAAE,CAAC,EAAE,UAAU,EAAE,GAAG,EAAE;IACpC,GAAG,EAAE,EAAE,OAAO,EAAE,CAAC,EAAE,UAAU,EAAE,GAAG,EAAE;CACrC,CAAC;AAEF,mFAAmF;AACnF,MAAM,CAAC,MAAM,uBAAuB,GAAG,iBAAiB,CAAC,GAAG,CAAE,CAAC,OAAO,CAAC;AASvE,kDAAkD;AAClD,MAAM,CAAC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CAAC,GAAG,CAAC,qBAAqB,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CACnE,CAAC;QACF,IAAI,CAAC,IAAI,GAAG,iCAAiC,CAAC;QAC9C,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;IAC7B,CAAC;CACF"}
@@ -0,0 +1,17 @@
1
+ // Code-state context: the contract marker and the `defineCodeState` authoring
2
+ // alias. These globals are absent from the PTC context.
3
+ //
4
+ // A code state's script moves the session itself — `tools.archmax_advance` — or
5
+ // ends it — `tools.archmax_raise`; nothing it returns is read, so there is no
6
+ // verdict vocabulary here.
7
+
8
+ globalThis.SANDBOX_CONTRACT = { context: "code", version: globalThis.__SANDBOX_VERSION };
9
+
10
+ // `export default defineCodeState(fn)` and `export default async function (...)`
11
+ // both register the state's function: the executor rewrites `export default` to
12
+ // an assignment of `__stateDef`, so `defineCodeState` is an identity that also
13
+ // registers.
14
+ globalThis.defineCodeState = (fn) => {
15
+ globalThis.__stateDef = fn;
16
+ return fn;
17
+ };
@@ -1,15 +1,15 @@
1
1
  import type { StructuredTool } from "@langchain/core/tools";
2
2
  import type { Workspace } from "../core/workspace.js";
3
3
  import { type SandboxRuntime } from "./runtime.js";
4
+ /** The REPL namespace of the agent's own sandbox tools: one per session scope, kept across states. */
4
5
  export declare const AGENT_SESSION = "agent";
5
- export declare const PROCESS_SESSION = "process";
6
+ /** The REPL namespace a code state's script runs in: fresh per run, disposed when it settles. */
7
+ export declare const CODE_SESSION = "code";
6
8
  export interface ScriptRunParams {
7
9
  sessionId: string;
8
10
  sessionNamespace: string;
9
11
  args?: Record<string, unknown>;
10
12
  tools?: StructuredTool[];
11
- /** Run as a lifecycle hook: the hook prelude, the hook input, a verdict back. */
12
- lifecycle?: boolean;
13
13
  /**
14
14
  * `runCode` only: prepend the context's prelude, so inline code runs under
15
15
  * the same contract as an authored file. The agent's `archmax_eval` sets it;
@@ -17,10 +17,9 @@ export interface ScriptRunParams {
17
17
  */
18
18
  prelude?: boolean;
19
19
  /**
20
- * The tool names a `ptc` script lists under `tools`: the active state's
21
- * surface, re-applied at the start of this evaluation. Set by the agent's two
22
- * sandbox tools only; absent, `tools` lists every tool the session injected,
23
- * which is what a lifecycle hook keeps.
20
+ * The tool names a script lists and reaches under `tools`: the active state's
21
+ * surface, re-applied at the start of this evaluation. Absent, `tools` is
22
+ * every tool the session injected (a bare executor, in a test).
24
23
  */
25
24
  surface?: readonly string[];
26
25
  /**
@@ -39,9 +38,28 @@ export interface ScriptOutcome {
39
38
  };
40
39
  formatted: string;
41
40
  }
41
+ /** What a code state's run is given: its session, its input, its state's tools. */
42
+ export interface CodeStateRunParams {
43
+ sessionId: string;
44
+ /** The state's input: the default export's argument (without `tools`) and the global `args`. */
45
+ args: Record<string, unknown>;
46
+ /** The code state's tools, already governed. */
47
+ tools: StructuredTool[];
48
+ /** The names `tools` lists and reaches — the code state's surface. */
49
+ surface: readonly string[];
50
+ /** The turn's abort signal: once it aborts, the run settles with an error. */
51
+ signal?: AbortSignal;
52
+ }
42
53
  export interface ScriptExecutor {
43
54
  runFile(filePath: string, params: ScriptRunParams): Promise<ScriptOutcome>;
44
55
  runCode(code: string, params: ScriptRunParams): Promise<ScriptOutcome>;
56
+ /**
57
+ * Run a code state's script (`code` context) in a REPL of its own: fresh for
58
+ * the run and disposed when it settles, so its injected `tools` are exactly its
59
+ * state's and nothing it defines reaches the next run. The default export is
60
+ * called with `args` plus `tools`; its return value is not read.
61
+ */
62
+ runCodeState(filePath: string, params: CodeStateRunParams): Promise<ScriptOutcome>;
45
63
  dispose(sessionId: string, sessionNamespace?: string): void;
46
64
  }
47
65
  export interface ScriptExecutorOptions {
@@ -1,30 +1,28 @@
1
1
  import { toCamelCase, transformForEval } from "@langchain/quickjs";
2
2
  import { normalizeRelPath } from "../core/workspace.js";
3
3
  import { readPrelude } from "./prelude.js";
4
- import { prepareHookSource } from "./imports.js";
5
- import { TOOL_CALLS_QUERY } from "../machine/tool-names.js";
4
+ import { prepareScriptSource } from "./imports.js";
6
5
  import { DEFAULT_SANDBOX_VERSION } from "../runtime/contract.js";
7
6
  import { createQuickJsSandboxRuntime } from "./runtime.js";
8
7
  /**
9
8
  * Sandboxed execution for the two sandbox tools (`archmax_eval`, `archmax_run`)
10
- * and for lifecycle hooks.
9
+ * and for code states.
11
10
  *
12
11
  * Script *sources* are read through the {@link Workspace} backend (not the
13
12
  * local filesystem), so scripts work against whatever Deep Agents backend the
14
13
  * runtime is configured with. Inline code and an authored file evaluate in the
15
14
  * same REPL session for a scope and under the same PTC contract — the only
16
- * difference is where the source came from.
15
+ * difference is where the source came from. A code state's script runs in a
16
+ * REPL of its own, fresh per run.
17
17
  */
18
18
  const DEFAULT_TIMEOUT_MS = 5_000;
19
+ /** The REPL namespace of the agent's own sandbox tools: one per session scope, kept across states. */
19
20
  export const AGENT_SESSION = "agent";
20
- export const PROCESS_SESSION = "process";
21
+ /** The REPL namespace a code state's script runs in: fresh per run, disposed when it settles. */
22
+ export const CODE_SESSION = "code";
21
23
  function errorOutcome(message) {
22
24
  return { ok: false, value: undefined, logs: [], error: { message }, formatted: `error: ${message}` };
23
25
  }
24
- /** Lifecycle hooks get the hook contract; everything else the PTC contract. */
25
- function sandboxContext(params) {
26
- return params.lifecycle ? "lifecycle-hook" : "ptc";
27
- }
28
26
  const argsAssignment = (args) => `globalThis.args = ${JSON.stringify(args ?? {})};`;
29
27
  /**
30
28
  * The line that scopes `tools` to a surface, after the `ptc` prelude installed
@@ -41,35 +39,23 @@ function ownNames(tools) {
41
39
  return Object.fromEntries(tools.map((tool) => [tool.name, toCamelCase(tool.name)]).filter(([own, key]) => own !== key));
42
40
  }
43
41
  /**
44
- * The code a lifecycle hook runs as. The hook body is evaluated as its own
45
- * async IIFE (`transformForEval`) so its completion value can be read — a
46
- * bare-body hook may end in `veto("…")` — and a registered `export default`
47
- * function is then called with the hook input: the arguments plus `tools`.
48
- * Whatever came back is reduced to a verdict by the prelude.
42
+ * The code a code state's script runs as. The body is evaluated as its own
43
+ * async IIFE (`transformForEval`) — a bare-body script simply runs — and a
44
+ * registered `export default` function is then called with the state's input:
45
+ * the arguments plus the scoped `tools`. The value is `undefined` either way: a
46
+ * code state moves the session through its tools, never through a return.
49
47
  */
50
- function buildHookCode(prepared, filePath, prelude, args) {
51
- const query = toCamelCase(TOOL_CALLS_QUERY);
48
+ function buildCodeStateCode(prepared, filePath, preamble, args) {
52
49
  return [
53
- prelude,
54
- "globalThis.__hookDef = undefined;",
50
+ ...preamble,
51
+ "globalThis.__stateDef = undefined;",
55
52
  argsAssignment(args),
56
- // The sandbox keeps the tools it was first handed: the `toolCalls` function is
57
- // taken out of `tools` on the first run and kept, hidden, for every run after.
58
- `if (typeof tools !== "undefined" && typeof tools.${query} === "function") {`,
59
- ` const query = tools.${query};`,
60
- ` delete tools.${query};`,
61
- " globalThis.__archmaxToolCalls = async (filter) => JSON.parse(await query(filter ?? {}));",
62
- "}",
63
- "globalThis.args.toolCalls = globalThis.__archmaxToolCalls;",
64
53
  `globalThis.__scriptPath = ${JSON.stringify(normalizeRelPath(filePath))};`,
65
- `globalThis.__hookBody = await ${transformForEval(prepared)};`,
66
- "globalThis.__hookVerdict(",
67
- " typeof globalThis.__hookDef === \"function\"",
68
- " ? await globalThis.__hookDef(Object.assign({}, globalThis.args, {",
69
- " tools: typeof tools === \"undefined\" ? undefined : tools,",
70
- " }))",
71
- " : globalThis.__hookBody,",
72
- ");",
54
+ `await ${transformForEval(prepared)};`,
55
+ "if (typeof globalThis.__stateDef === \"function\") {",
56
+ " await globalThis.__stateDef(Object.assign({}, globalThis.args, { tools }));",
57
+ "}",
58
+ "undefined;",
73
59
  ].join("\n");
74
60
  }
75
61
  export function createScriptExecutor(opts) {
@@ -91,28 +77,12 @@ export function createScriptExecutor(opts) {
91
77
  });
92
78
  return session.eval(code, timeoutMs, params.signal);
93
79
  }
94
- async function runHook(source, filePath, params) {
95
- // Typed `@archmax-ai/harness/*` imports are stripped (the prelude provides the
96
- // globals) and `export default` becomes the hook registration; any other
97
- // import — or a source that does not parse — fails closed here, host-side.
98
- let code;
99
- try {
100
- const prelude = readPrelude("lifecycle-hook", sandboxVersion);
101
- code = buildHookCode(prepareHookSource(source, { file: filePath }), filePath, prelude, params.args);
102
- }
103
- catch (err) {
104
- return errorOutcome(err.message);
105
- }
106
- return evalCode(code, params);
107
- }
108
80
  return {
109
81
  async runFile(filePath, params) {
110
82
  const source = await workspace.readText(filePath);
111
83
  if (source == null)
112
84
  return errorOutcome(`cannot read script '${filePath}' from the agent workspace.`);
113
- if (params.lifecycle)
114
- return runHook(source, filePath, params);
115
- const prelude = readPrelude(sandboxContext(params), sandboxVersion);
85
+ const prelude = readPrelude("ptc", sandboxVersion);
116
86
  const code = [
117
87
  prelude,
118
88
  ...scopeCall(params.surface, params.tools),
@@ -127,19 +97,48 @@ export function createScriptExecutor(opts) {
127
97
  return evalCode(code, params);
128
98
  // Same contract as an authored file: the PTC prelude runs first so inline
129
99
  // code sees the same `SANDBOX_CONTRACT` marker, the same scoped `tools` and
130
- // the same absence of the hook-only vocabulary.
131
- const preamble = [
132
- readPrelude(sandboxContext(params), sandboxVersion),
133
- ...scopeCall(params.surface, params.tools),
134
- ];
100
+ // the same absence of the code-state vocabulary.
101
+ const preamble = [readPrelude("ptc", sandboxVersion), ...scopeCall(params.surface, params.tools)];
135
102
  return evalCode(`${preamble.join("\n")}\n${code}`, params);
136
103
  },
104
+ async runCodeState(filePath, params) {
105
+ const source = await workspace.readText(filePath);
106
+ if (source == null)
107
+ return errorOutcome(`cannot read script '${filePath}' from the authoring backend.`);
108
+ // Typed `@archmax-ai/harness/*` imports are stripped (the prelude provides the
109
+ // globals) and `export default` becomes the state's registration; any
110
+ // other import — or a source that does not parse — fails closed here,
111
+ // host-side, before a REPL exists.
112
+ let code;
113
+ try {
114
+ const preamble = [readPrelude("code", sandboxVersion), ...scopeCall(params.surface, params.tools)];
115
+ code = buildCodeStateCode(prepareScriptSource(source, { file: filePath }), filePath, preamble, params.args);
116
+ }
117
+ catch (err) {
118
+ return errorOutcome(err.message);
119
+ }
120
+ // Fresh per run: a REPL keeps the tools it was first handed for good, and a
121
+ // code state's are its own state's.
122
+ const key = sessionKey(params.sessionId, CODE_SESSION);
123
+ runtime.dispose(key);
124
+ try {
125
+ return await evalCode(code, {
126
+ sessionId: params.sessionId,
127
+ sessionNamespace: CODE_SESSION,
128
+ tools: params.tools,
129
+ ...(params.signal ? { signal: params.signal } : {}),
130
+ });
131
+ }
132
+ finally {
133
+ runtime.dispose(key);
134
+ }
135
+ },
137
136
  dispose(sessionId, sessionNamespace) {
138
137
  if (sessionNamespace) {
139
138
  runtime.dispose(sessionKey(sessionId, sessionNamespace));
140
139
  return;
141
140
  }
142
- for (const ns of [AGENT_SESSION, PROCESS_SESSION]) {
141
+ for (const ns of [AGENT_SESSION, CODE_SESSION]) {
143
142
  runtime.dispose(sessionKey(sessionId, ns));
144
143
  }
145
144
  },
@@ -1 +1 @@
1
- {"version":3,"file":"executor.js","sourceRoot":"","sources":["../../src/sandbox/executor.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAEnE,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AACxD,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AACjD,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAC5D,OAAO,EAAE,uBAAuB,EAAuB,MAAM,wBAAwB,CAAC;AACtF,OAAO,EAAE,2BAA2B,EAAuB,MAAM,cAAc,CAAC;AAEhF;;;;;;;;;GASG;AAEH,MAAM,kBAAkB,GAAG,KAAK,CAAC;AACjC,MAAM,CAAC,MAAM,aAAa,GAAG,OAAO,CAAC;AACrC,MAAM,CAAC,MAAM,eAAe,GAAG,SAAS,CAAC;AAuDz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SAAS,EAAE,MAAM,CAAC,SAAS;oBAC3B,gBAAgB,EAAE,YAAY;oBAC9B,KAAK,EAAE,MAAM,CAAC,KAAK;oBACnB,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;iBACpD,CAAC,CAAC;YACL,CAAC;oBAAS,CAAC;gBACT,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;YACvB,CAAC;QACH,CAAC;QAED,OAAO,CAAC,SAAS,EAAE,gBAAgB;YACjC,IAAI,gBAAgB,EAAE,CAAC;gBACrB,OAAO,CAAC,OAAO,CAAC,UAAU,CAAC,SAAS,EAAE,gBAAgB,CAAC,CAAC,CAAC;gBACzD,OAAO;YACT,CAAC;YACD,KAAK,MAAM,EAAE,IAAI,CAAC,aAAa,EAAE,YAAY,CAAC,EAAE,CAAC;gBAC/C,OAAO,CAAC,OAAO,CAAC,UAAU,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC,CAAC;YAC7C,CAAC;QACH,CAAC;KACF,CAAC;AACJ,CAAC"}
@@ -1,19 +1,19 @@
1
1
  /**
2
- * Source preparation for lifecycle hook scripts.
2
+ * Source preparation for code-state scripts.
3
3
  *
4
4
  * `@langchain/quickjs`'s `transformForEval` (which `ReplSession.eval` applies to
5
5
  * everything it runs) silently **drops** `import` and `export` statements and
6
- * rejects nothing — so a hook's `export default async function hook(...)`
7
- * would vanish and a foreign import would pass unnoticed. This module does the
8
- * three things the transform will not:
6
+ * rejects nothing — so a script's `export default async function (...)` would
7
+ * vanish and a foreign import would pass unnoticed. This module does the three
8
+ * things the transform will not:
9
9
  *
10
10
  * - **reject** any import that is not a `@archmax-ai/harness/*` type carrier (sandbox
11
11
  * scripts are self-contained — inline the logic or use `tools.*`);
12
12
  * - **strip** the `@archmax-ai/harness/*` imports, preserving line count so sandbox
13
13
  * stack traces keep pointing at the right source lines;
14
- * - **rewrite** `export default <expr>` to `globalThis.__hookDef = <expr>`, so
15
- * the hook function survives evaluation as a script and the executor can call
16
- * it with the hook input.
14
+ * - **rewrite** `export default <expr>` to `globalThis.__stateDef = <expr>`, so
15
+ * the state's function survives evaluation as a script and the executor can
16
+ * call it with the state's input.
17
17
  */
18
18
  /** Thrown (host-side) when a sandbox script imports a non-`@archmax-ai/harness/*` specifier. */
19
19
  export declare class ForbiddenSandboxImportError extends Error {
@@ -24,10 +24,10 @@ export declare class ForbiddenSandboxImportError extends Error {
24
24
  /** All import specifiers in a source that are NOT `@archmax-ai/harness/*` (for validation). */
25
25
  export declare function findForeignImports(source: string): string[];
26
26
  /**
27
- * Prepare a hook source for evaluation: strip `@archmax-ai/harness/*` imports, rewrite
28
- * `export default` to the `__hookDef` registration, and throw
27
+ * Prepare a code-state script for evaluation: strip `@archmax-ai/harness/*`
28
+ * imports, rewrite `export default` to the `__stateDef` registration, and throw
29
29
  * {@link ForbiddenSandboxImportError} on any other import specifier.
30
30
  */
31
- export declare function prepareHookSource(source: string, opts?: {
31
+ export declare function prepareScriptSource(source: string, opts?: {
32
32
  file?: string;
33
33
  }): string;
@@ -1,19 +1,19 @@
1
1
  /**
2
- * Source preparation for lifecycle hook scripts.
2
+ * Source preparation for code-state scripts.
3
3
  *
4
4
  * `@langchain/quickjs`'s `transformForEval` (which `ReplSession.eval` applies to
5
5
  * everything it runs) silently **drops** `import` and `export` statements and
6
- * rejects nothing — so a hook's `export default async function hook(...)`
7
- * would vanish and a foreign import would pass unnoticed. This module does the
8
- * three things the transform will not:
6
+ * rejects nothing — so a script's `export default async function (...)` would
7
+ * vanish and a foreign import would pass unnoticed. This module does the three
8
+ * things the transform will not:
9
9
  *
10
10
  * - **reject** any import that is not a `@archmax-ai/harness/*` type carrier (sandbox
11
11
  * scripts are self-contained — inline the logic or use `tools.*`);
12
12
  * - **strip** the `@archmax-ai/harness/*` imports, preserving line count so sandbox
13
13
  * stack traces keep pointing at the right source lines;
14
- * - **rewrite** `export default <expr>` to `globalThis.__hookDef = <expr>`, so
15
- * the hook function survives evaluation as a script and the executor can call
16
- * it with the hook input.
14
+ * - **rewrite** `export default <expr>` to `globalThis.__stateDef = <expr>`, so
15
+ * the state's function survives evaluation as a script and the executor can
16
+ * call it with the state's input.
17
17
  */
18
18
  /** Import specifiers the sandbox accepts (and strips) in script sources. */
19
19
  const ALLOWED_SPECIFIER_PREFIX = "@archmax-ai/harness";
@@ -52,16 +52,16 @@ export function findForeignImports(source) {
52
52
  return foreign;
53
53
  }
54
54
  /**
55
- * Prepare a hook source for evaluation: strip `@archmax-ai/harness/*` imports, rewrite
56
- * `export default` to the `__hookDef` registration, and throw
55
+ * Prepare a code-state script for evaluation: strip `@archmax-ai/harness/*`
56
+ * imports, rewrite `export default` to the `__stateDef` registration, and throw
57
57
  * {@link ForbiddenSandboxImportError} on any other import specifier.
58
58
  */
59
- export function prepareHookSource(source, opts = {}) {
59
+ export function prepareScriptSource(source, opts = {}) {
60
60
  const stripped = String(source).replace(IMPORT_RE, (whole, _lead, specifier) => {
61
61
  if (!specifierAllowed(specifier))
62
62
  throw new ForbiddenSandboxImportError(specifier, opts.file);
63
63
  return "\n".repeat(whole.split("\n").length - 1);
64
64
  });
65
- return stripped.replace(EXPORT_DEFAULT_RE, "$1$2globalThis.__hookDef = ");
65
+ return stripped.replace(EXPORT_DEFAULT_RE, "$1$2globalThis.__stateDef = ");
66
66
  }
67
67
  //# sourceMappingURL=imports.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"imports.js","sourceRoot":"","sources":["../../src/sandbox/imports.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,4EAA4E;AAC5E,MAAM,wBAAwB,GAAG,qBAAqB,CAAC;AAEvD;;;GAGG;AACH,MAAM,SAAS,GAAG,qEAAqE,CAAC;AAExF,8CAA8C;AAC9C,MAAM,iBAAiB,GAAG,0CAA0C,CAAC;AAErE,gGAAgG;AAChG,MAAM,OAAO,2BAA4B,SAA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BAAgB,CAAC,SAAS,CAAC;YAAE,OAAO,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;IAC5D,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC;AAGD;;;;GAIG;AACH,MAAM,UAAU,mBAAmB,CAAC,MAAc,EAAE,OAA0B,EAAE;IAC9E,MAAM,QAAQ,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,SAAS,EAAE,CAAC,KAAK,EAAE,KAAa,EAAE,SAAiB,EAAE,EAAE;QAC7F,IAAI,CAAC,gBAAgB,CAAC,SAAS,CAAC;YAAE,MAAM,IAAI,2BAA2B,CAAC,SAAS,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC;QAC9F,OAAO,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IACnD,CAAC,CAAC,CAAC;IACH,OAAO,QAAQ,CAAC,OAAO,CAAC,iBAAiB,EAAE,8BAA8B,CAAC,CAAC;AAC7E,CAAC"}
@@ -1,12 +1,11 @@
1
1
  import { type SandboxContext } from "../runtime/contract.js";
2
2
  /**
3
- * Assemble the QuickJS prelude for a sandbox context. The lifecycle-hook context
4
- * is the verdict helpers (`ok`/`veto`/`correct`), `defineHook`, and the verdict
5
- * reducer; the PTC context is the contract marker alone. Cached per
3
+ * Assemble the QuickJS prelude for a sandbox context: `ptc` is the contract
4
+ * marker and the scoped `tools` view; `code` adds the code-state part — its own
5
+ * marker and the `defineCodeState` alias — to the same view. Cached per
6
6
  * `(context, version)`.
7
7
  *
8
- * There are exactly two preludes: no compatibility prelude exists for a
9
- * superseded vocabulary, so a hook source using one throws in the sandbox and
10
- * the phase vetoes fail-closed.
8
+ * There are exactly two preludes and no compatibility prelude for a superseded
9
+ * vocabulary, so a source using one throws in the sandbox and fails closed.
11
10
  */
12
11
  export declare function readPrelude(context?: SandboxContext, version?: number): string;
@@ -16,26 +16,23 @@ function readPart(name) {
16
16
  return content;
17
17
  }
18
18
  /**
19
- * The PTC context's whole prelude: the versioned contract marker and the view
20
- * that scopes `tools` to the active state. The model's own code (`archmax_eval`,
21
- * `archmax_run`) gets no hook vocabulary — `tools` and `args` are injected
22
- * separately by the executor and the QuickJS session.
19
+ * The scoped `tools` view, shared by both contexts. The session injects every
20
+ * tool it was handed once, at its first evaluation, and keeps that object for
21
+ * its lifetime — for the agent's REPL, across every state the session moves
22
+ * through. So the scoping happens in here: one Proxy, installed once, whose
23
+ * listing *and* lookup are the surface the executor names per evaluation
24
+ * (`__archmaxScope`). A name outside the surface is `undefined`, exactly as it
25
+ * is absent from `Object.keys(tools)` and from `in`: a script reaches the
26
+ * state's tools and nothing else. Its identity never changes, so a reference an
27
+ * earlier evaluation kept reads the current state. The session keys each tool by
28
+ * its camelCase name, but a model writes the name it calls the tool by
29
+ * (`tools.read_file`), so the executor also hands over each tool's own name →
30
+ * its key, and every lookup resolves through that; the listing stays the keys.
31
+ * A call without an input passes `{}`: the session reads its argument handle
32
+ * unconditionally, so a bare `tools.archmax_get_history()` would otherwise fail.
33
+ * An IIFE: the evaluation hoists top-level declarations onto `globalThis`.
23
34
  */
24
- const PTC_PRELUDE = [
25
- `globalThis.SANDBOX_CONTRACT = { context: "ptc", version: globalThis.__SANDBOX_VERSION };`,
26
- // The session injects every PTC tool once, at its first evaluation, and keeps
27
- // that object for its lifetime — across every state the run moves through. So
28
- // the scoping happens in here: one Proxy, installed once, whose listing is the
29
- // surface the executor names per evaluation (`__archmaxScope`). Its identity
30
- // never changes, so a reference an earlier evaluation kept reads the current
31
- // state. `get` still resolves a registered name outside the view, so calling
32
- // one reaches governance and its refusal, not a TypeError. The session keys
33
- // each tool by its camelCase name, but a model writes the name it calls the
34
- // tool by (`tools.read_file`), so the executor also hands over each tool's own
35
- // name → its key, and every lookup resolves through that; the listing stays
36
- // the keys. An IIFE: the evaluation hoists top-level declarations onto
37
- // `globalThis`.
38
- `(() => {
35
+ const SCOPED_TOOLS_VIEW = `(() => {
39
36
  if (globalThis.__archmaxScope) return;
40
37
  const all = globalThis.tools != null && typeof globalThis.tools === "object" ? globalThis.tools : {};
41
38
  const injected = (name) => typeof name === "string" && Object.prototype.hasOwnProperty.call(all, name);
@@ -44,16 +41,19 @@ const PTC_PRELUDE = [
44
41
  const keyOf = (name) =>
45
42
  !injected(name) && typeof name === "string" && Object.prototype.hasOwnProperty.call(keys, name) ? keys[name] : name;
46
43
  const visible = (name) => injected(name) && (surface === null || surface.has(name));
44
+ const callers = {};
45
+ const caller = (key) =>
46
+ (callers[key] ??= (input, ...rest) => all[key](input === undefined ? {} : input, ...rest));
47
47
  const view = new Proxy({}, {
48
48
  get: (_target, name) => {
49
49
  const key = keyOf(name);
50
- return injected(key) ? all[key] : undefined;
50
+ return visible(key) ? caller(key) : undefined;
51
51
  },
52
52
  has: (_target, name) => visible(keyOf(name)),
53
53
  ownKeys: () => Object.keys(all).filter(visible),
54
54
  getOwnPropertyDescriptor: (_target, name) => {
55
55
  const key = keyOf(name);
56
- return visible(key) ? { value: all[key], writable: false, enumerable: true, configurable: true } : undefined;
56
+ return visible(key) ? { value: caller(key), writable: false, enumerable: true, configurable: true } : undefined;
57
57
  },
58
58
  });
59
59
  Object.defineProperty(globalThis, "__archmaxScope", {
@@ -63,30 +63,33 @@ const PTC_PRELUDE = [
63
63
  globalThis.tools = view;
64
64
  },
65
65
  });
66
- })();`,
66
+ })();`;
67
+ /**
68
+ * The PTC context's prelude: the versioned contract marker and the scoped
69
+ * `tools` view. The agent's own code (`archmax_eval`, `archmax_run`) gets no
70
+ * code-state vocabulary — `tools` and `args` are injected separately by the
71
+ * executor and the QuickJS session.
72
+ */
73
+ const PTC_PRELUDE = [
74
+ `globalThis.SANDBOX_CONTRACT = { context: "ptc", version: globalThis.__SANDBOX_VERSION };`,
75
+ SCOPED_TOOLS_VIEW,
67
76
  ].join("\n");
68
77
  /**
69
- * Assemble the QuickJS prelude for a sandbox context. The lifecycle-hook context
70
- * is the verdict helpers (`ok`/`veto`/`correct`), `defineHook`, and the verdict
71
- * reducer; the PTC context is the contract marker alone. Cached per
78
+ * Assemble the QuickJS prelude for a sandbox context: `ptc` is the contract
79
+ * marker and the scoped `tools` view; `code` adds the code-state part — its own
80
+ * marker and the `defineCodeState` alias — to the same view. Cached per
72
81
  * `(context, version)`.
73
82
  *
74
- * There are exactly two preludes: no compatibility prelude exists for a
75
- * superseded vocabulary, so a hook source using one throws in the sandbox and
76
- * the phase vetoes fail-closed.
83
+ * There are exactly two preludes and no compatibility prelude for a superseded
84
+ * vocabulary, so a source using one throws in the sandbox and fails closed.
77
85
  */
78
- export function readPrelude(context = "lifecycle-hook", version = DEFAULT_SANDBOX_VERSION) {
86
+ export function readPrelude(context = "ptc", version = DEFAULT_SANDBOX_VERSION) {
79
87
  const key = `${context}@${version}`;
80
88
  const cached = assembledCache.get(key);
81
89
  if (cached !== undefined)
82
90
  return cached;
83
91
  const header = `globalThis.__SANDBOX_VERSION = ${JSON.stringify(version)};`;
84
- const parts = context === "ptc"
85
- ? [PTC_PRELUDE]
86
- : [
87
- readPart("core"),
88
- readPart("lifecycle-hook"),
89
- ];
92
+ const parts = context === "ptc" ? [PTC_PRELUDE] : [SCOPED_TOOLS_VIEW, readPart("code-state")];
90
93
  const assembled = [header, ...parts].join("\n");
91
94
  assembledCache.set(key, assembled);
92
95
  return assembled;
@@ -1 +1 @@
1
- {"version":3,"file":"prelude.js","sourceRoot":"","sources":["../../src/sandbox/prelude.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,uBAAuB,EAAuB,MAAM,wBAAwB,CAAC;AAEtF,MAAM,UAAU,GAAG,IAAI,GAAG,EAAkB,CAAC;AAC7C,MAAM,cAAc,GAAG,IAAI,GAA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