@agent-compose/sdk 0.7.0 → 0.8.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 (116) hide show
  1. package/README.md +66 -39
  2. package/dist/agent/__tests__/runtime-json-schema.test.d.ts +10 -0
  3. package/dist/agent/agent-context.d.ts +21 -1
  4. package/dist/agent/agent-loop.d.ts +24 -1
  5. package/dist/client.d.ts +338 -534
  6. package/dist/directives.d.ts +112 -0
  7. package/dist/display.d.ts +242 -0
  8. package/dist/errors.d.ts +24 -1
  9. package/dist/index.d.ts +24 -12
  10. package/dist/index.js +3545 -1667
  11. package/dist/pause/wrappers.d.ts +31 -9
  12. package/dist/runtimes/_acp-client.d.ts +46 -1
  13. package/dist/runtimes/_cli-agent.d.ts +49 -4
  14. package/dist/runtimes/_jsonl-guard.d.ts +103 -0
  15. package/dist/runtimes/amp.d.ts +2 -2
  16. package/dist/runtimes/claude-code.d.ts +59 -0
  17. package/dist/runtimes/claude-code.test.d.ts +14 -0
  18. package/dist/runtimes/claude.d.ts +16 -0
  19. package/dist/runtimes/claude.test.d.ts +8 -0
  20. package/dist/runtimes/codex.d.ts +9 -3
  21. package/dist/runtimes/cursor.d.ts +2 -2
  22. package/dist/runtimes/droid.d.ts +2 -2
  23. package/dist/runtimes/jsonl-guard.test.d.ts +19 -0
  24. package/dist/runtimes/openai-desktop.js +2691 -864
  25. package/dist/runtimes/opencode.d.ts +2 -2
  26. package/dist/runtimes/vercel.js +12 -1
  27. package/dist/sandbox/devbox.d.ts +42 -0
  28. package/dist/sandbox/exec-stream.d.ts +14 -0
  29. package/dist/sandbox/network-policy.d.ts +100 -0
  30. package/dist/sandbox/provider-def.d.ts +79 -0
  31. package/dist/sandbox/providers/desktop.d.ts +10 -0
  32. package/dist/sandbox/providers/e2b.d.ts +17 -0
  33. package/dist/sandbox/providers/local.d.ts +11 -0
  34. package/dist/sandbox/providers/vercel.d.ts +18 -0
  35. package/dist/sandbox/registry.d.ts +45 -0
  36. package/dist/sandbox/sizes.d.ts +68 -0
  37. package/dist/sandbox.d.ts +24 -299
  38. package/dist/step-invocation/__tests__/foreground-recovery.test.d.ts +1 -0
  39. package/dist/step-invocation/invoker.d.ts +10 -0
  40. package/dist/step-invocation/protocol.d.ts +5 -0
  41. package/dist/types/api-compliance.d.ts +71 -0
  42. package/dist/types/api-conversations.d.ts +492 -0
  43. package/dist/types/api-factory.d.ts +309 -0
  44. package/dist/types/api-projects.d.ts +131 -0
  45. package/dist/types/api-runs.d.ts +377 -0
  46. package/dist/types/api-scopes.d.ts +102 -0
  47. package/dist/types/conversation-stream.d.ts +191 -0
  48. package/dist/types/execution-context.d.ts +12 -2
  49. package/dist/types/protocol.d.ts +30 -1
  50. package/dist/types/sandbox-environment.d.ts +8 -5
  51. package/dist/types/sandbox.d.ts +74 -4
  52. package/dist/types/workflow-metadata.d.ts +33 -8
  53. package/dist/types/workflow-plan.d.ts +10 -0
  54. package/dist/types/workflow.d.ts +18 -205
  55. package/dist/utils/bundler.d.ts +12 -1
  56. package/dist/workflow-steps/index.d.ts +1 -1
  57. package/dist/workflow-steps/observability.d.ts +8 -1
  58. package/dist/workflow-steps/runner.d.ts +3 -3
  59. package/dist/workflow-steps/step.d.ts +15 -1
  60. package/dist/workflow-steps/types.d.ts +19 -5
  61. package/dist/workflow-steps/workflow.d.ts +22 -1
  62. package/dist/workflows/engine.d.ts +3 -2
  63. package/dist/workflows/invoke-child.d.ts +2 -2
  64. package/package.json +1 -1
  65. package/src/agent/agent-context.ts +186 -3
  66. package/src/agent/agent-loop.ts +31 -2
  67. package/src/client.ts +909 -621
  68. package/src/directives.ts +184 -0
  69. package/src/display.ts +788 -0
  70. package/src/errors.ts +39 -0
  71. package/src/index.ts +104 -10
  72. package/src/pause/wrappers.ts +44 -9
  73. package/src/runtimes/_acp-client.ts +72 -3
  74. package/src/runtimes/_cli-agent.ts +159 -36
  75. package/src/runtimes/_jsonl-guard.ts +219 -0
  76. package/src/runtimes/claude-code.ts +246 -0
  77. package/src/runtimes/claude.ts +32 -2
  78. package/src/runtimes/codex.ts +55 -3
  79. package/src/runtimes/openai-desktop.ts +59 -14
  80. package/src/sandbox/devbox.ts +48 -0
  81. package/src/sandbox/exec-stream.ts +48 -0
  82. package/src/sandbox/network-policy.ts +181 -0
  83. package/src/sandbox/provider-def.ts +94 -0
  84. package/src/sandbox/providers/desktop.ts +57 -0
  85. package/src/sandbox/providers/e2b.ts +354 -0
  86. package/src/sandbox/providers/local.ts +106 -0
  87. package/src/sandbox/providers/vercel.ts +331 -0
  88. package/src/sandbox/registry.ts +198 -0
  89. package/src/sandbox/sizes.ts +95 -0
  90. package/src/sandbox.ts +59 -1275
  91. package/src/step-invocation/invoker.ts +151 -28
  92. package/src/step-invocation/protocol.ts +8 -0
  93. package/src/types/api-compliance.ts +79 -0
  94. package/src/types/api-conversations.ts +522 -0
  95. package/src/types/api-factory.ts +336 -0
  96. package/src/types/api-projects.ts +140 -0
  97. package/src/types/api-runs.ts +412 -0
  98. package/src/types/api-scopes.ts +102 -0
  99. package/src/types/conversation-stream.ts +231 -0
  100. package/src/types/execution-context.ts +10 -2
  101. package/src/types/protocol.ts +33 -0
  102. package/src/types/sandbox-environment.ts +28 -9
  103. package/src/types/sandbox.ts +73 -4
  104. package/src/types/workflow-metadata.ts +35 -8
  105. package/src/types/workflow-plan.ts +11 -0
  106. package/src/types/workflow.ts +25 -292
  107. package/src/utils/bundler.ts +32 -5
  108. package/src/utils/errors.ts +16 -1
  109. package/src/workflow-steps/index.ts +1 -0
  110. package/src/workflow-steps/observability.ts +19 -8
  111. package/src/workflow-steps/runner.ts +4 -4
  112. package/src/workflow-steps/step.ts +49 -1
  113. package/src/workflow-steps/types.ts +20 -5
  114. package/src/workflow-steps/workflow.ts +22 -1
  115. package/src/workflows/engine.ts +3 -2
  116. package/src/workflows/invoke-child.ts +2 -2
@@ -1,26 +1,29 @@
1
1
  /**
2
- * The two opinionated pause wrappers (ADR-0006 §"SDK surface"), each a thin
3
- * closure over `ctx.pause`:
2
+ * The three opinionated pause wrappers (ADR-0006 §"SDK surface", ADR-0042),
3
+ * each a thin closure over `ctx.pause`:
4
4
  *
5
5
  * - `sleep` — a lightweight timed pause; resolves on its own TTL,
6
6
  * skips the snapshot, returns void.
7
7
  * - `waitForEvent` — pause until an event resumes by correlation key.
8
- *
9
- * A typed human/agent decision is NOT a wrapper — it's a plain `ctx.pause`
10
- * with a `schema` (and `payload.options` for the dashboard's answer UI). The
11
- * pause primitive carries the reason (the ask) and the resume value (the
12
- * resolution); there is no separate `requestDecision`.
8
+ * - `requestDecision` — a typed human/agent decision (wire `kind:
9
+ * "decision"`): the prompt/options/approvers ride
10
+ * `payload` for the dashboard's answer UI, and the
11
+ * resume value is the frozen `{ decision: string }`
12
+ * convention. `approvers` travel as RAW member refs
13
+ * (user ids or emails) — the SERVER resolves them
14
+ * against the team roster at pause-insert time and
15
+ * stamps the gate-bearing snapshots (ADR-0042 §2).
13
16
  *
14
17
  * Built from a `PauseFn` so the wrapper logic lives in one place and the step
15
18
  * runner just spreads them onto the context next to `pause`.
16
19
  */
17
- import type { z } from "zod";
20
+ import { z } from "zod";
18
21
  import type { StepPauseRequest } from "../step-invocation/types.js";
19
22
  import type { PauseRequest } from "./pause-core.js";
20
23
  /** The public `ctx.pause` callable (always `kind: "custom"`). */
21
24
  export type PauseFn = <T = unknown>(req: PauseRequest<T>) => Promise<T>;
22
25
  /** Internal: pause with an explicit wire `kind`. The wrappers stamp
23
- * `sleep`/`event` through this; the public `ctx.pause` is always
26
+ * `decision`/`sleep`/`event` through this; the public `ctx.pause` is always
24
27
  * `custom` and never exposes it. */
25
28
  export type KindedPauseFn = <T = unknown>(req: PauseRequest<T>, kind: StepPauseRequest["kind"]) => Promise<T>;
26
29
  export interface WaitForEventRequest<T> {
@@ -30,8 +33,27 @@ export interface WaitForEventRequest<T> {
30
33
  schema?: z.ZodType<T>;
31
34
  ttlMs?: number;
32
35
  }
36
+ export interface DecisionRequest {
37
+ prompt: string;
38
+ /** Choices the decision UI offers as buttons; free text is always open. */
39
+ options?: Array<string | {
40
+ label: string;
41
+ value: string;
42
+ }>;
43
+ /** Team member refs (user ids or emails, ≤ 10) — with any named, ONLY a
44
+ * named approver may resolve the decision, and each gets an Activity
45
+ * ping. Resolution is server-side at pause creation. */
46
+ approvers?: string[];
47
+ /** DecisionDraft artifact rendered alongside the prompt. */
48
+ draft?: Record<string, unknown>;
49
+ ttlMs?: number;
50
+ correlationKey?: string;
51
+ }
33
52
  export interface PauseWrappers {
34
53
  sleep(durationMs: number): Promise<void>;
35
54
  waitForEvent<T = unknown>(req: WaitForEventRequest<T>): Promise<T>;
55
+ requestDecision(req: DecisionRequest): Promise<{
56
+ decision: string;
57
+ }>;
36
58
  }
37
59
  export declare function buildPauseWrappers(pause: KindedPauseFn): PauseWrappers;
@@ -37,6 +37,26 @@ import type { ToolCallGateResult } from "../types/runtime.js";
37
37
  * ACP wire change — never silently. The package version is pinned separately
38
38
  * in package.json; this integer is the real compatibility gate (ADR-0020). */
39
39
  export declare const ACP_PROTOCOL_VERSION = 1;
40
+ /** Session-lifecycle capabilities the agent advertised at `initialize`,
41
+ * surfaced (not discarded) so callers can pick a resume strategy
42
+ * (ADR-0037 §3). The in-sandbox CLI-agent runtimes ignore both — they
43
+ * resume via the CLI's own on-disk rollout (ADR-0020 Q4); the bridge
44
+ * daemon attempts `session/resume` only when `resume` is true. */
45
+ export interface AcpSessionCaps {
46
+ /** Agent supports `session/load` — full-history replay as
47
+ * `agent_message_chunk`s. Deliberately NOT used for resume: replaying
48
+ * history would re-emit the transcript as new parts and duplicate the
49
+ * conversation (ADR-0037 alternative D). */
50
+ loadSession: boolean;
51
+ /** Agent supports `session/resume` — context restore with NO replay. */
52
+ resume: boolean;
53
+ }
54
+ /** One entry of the agent's slash-command palette, as announced by the ACP
55
+ * `available_commands_update` session notification. */
56
+ export interface AcpAvailableCommand {
57
+ name: string;
58
+ description: string;
59
+ }
40
60
  /** Collaborators `AcpClientPeer` needs from `CliAgentRunner`, kept as a small
41
61
  * injected surface so the peer stays transport-agnostic and unit-testable. */
42
62
  export interface AcpClientPeerDeps {
@@ -57,6 +77,14 @@ export interface AcpClientPeerDeps {
57
77
  /** Turn-scoped abort signal from `sendMessage`. On abort the peer sends
58
78
  * `session/cancel` for the live session. */
59
79
  signal?: AbortSignal;
80
+ /** The agent announced (or changed) its slash-command palette — an ACP
81
+ * `available_commands_update` session NOTIFICATION, which can arrive at
82
+ * any time (typically right after session/new, outside any prompt), so
83
+ * it rides a callback rather than the per-turn message stream. Each call
84
+ * carries the ENTIRE palette (replace semantics). Optional: the
85
+ * in-sandbox runtimes ignore it; the bridge daemon reports it to the
86
+ * server for composer autocomplete. */
87
+ onAvailableCommands?: (commands: AcpAvailableCommand[]) => void;
60
88
  }
61
89
  /**
62
90
  * Map ONE ACP `session/update` to zero-or-more `AgentMessage`s. The single
@@ -100,10 +128,14 @@ export declare class AcpClientPeer {
100
128
  * Negotiate the wire protocol at `initialize`. Pins `protocolVersion` to
101
129
  * integer 1 and advertises NO fs / terminal capabilities. Returns the
102
130
  * version the agent negotiated — `CliAgentRunner` compares it to
103
- * `ACP_PROTOCOL_VERSION` to decide ACP-path vs. legacy-JSONL fallback.
131
+ * `ACP_PROTOCOL_VERSION` to decide ACP-path vs. legacy-JSONL fallback —
132
+ * plus the agent's advertised session-lifecycle capabilities (`caps`),
133
+ * which the bridge daemon caches as `agent_sessions.resume_supported`
134
+ * (ADR-0037 §3). Absent capability blocks mean "not supported".
104
135
  */
105
136
  initialize(): Promise<{
106
137
  protocolVersion: number;
138
+ caps: AcpSessionCaps;
107
139
  }>;
108
140
  /**
109
141
  * Start a session and return its id (threaded back onto the synthesised
@@ -113,6 +145,19 @@ export declare class AcpClientPeer {
113
145
  * in the manual live step).
114
146
  */
115
147
  startSession(cwd: string): Promise<string>;
148
+ /**
149
+ * Resume an existing session by id — ACP `session/resume` (ADR-0037 §3).
150
+ * ADDITIVE and opt-in: the in-sandbox CLI-agent runtimes never call this
151
+ * (their resume path is the CLI's own persisted rollout, see
152
+ * `startSession`); the bridge daemon calls it only when `initialize`
153
+ * advertised `caps.resume`. Unlike `session/load` there is NO history
154
+ * replay — the agent restores its internal context and returns nothing,
155
+ * so nothing is re-emitted through the caller's part sink. Throws on an
156
+ * unknown/expired session id (JSON-RPC error from the agent) — the caller
157
+ * marks the durable row stale and falls back to `startSession` + full
158
+ * re-render. `this.sessionId` is only adopted on success.
159
+ */
160
+ resumeSession(cwd: string, acpSessionId: string): Promise<void>;
116
161
  /**
117
162
  * Drive one `session/prompt` turn, yielding `AgentMessage`s as the agent
118
163
  * streams `session/update` notifications. Resolves the generator when the
@@ -27,6 +27,21 @@ import type { AgentMessage, ModelExecutionContract, RuntimeOptions, SandboxProvi
27
27
  import type { ProcessorContext, ToolCall } from "../processors/processor.js";
28
28
  /** Single-quote a value for safe interpolation into a `sh -c` command line. */
29
29
  export declare function shellQuote(value: string): string;
30
+ /**
31
+ * A UNIQUE per-turn prompt path. Uniqueness is load-bearing, not cosmetic:
32
+ * E2B's envd cannot overwrite an existing non-root file in /tmp — it opens
33
+ * with O_CREAT as root (then chowns to the user), and the sandbox kernel's
34
+ * `fs.protected_regular` policy denies O_CREAT opens by a non-owner of an
35
+ * existing file in a sticky world-writable directory — so ANY reused path
36
+ * fails with "error opening file: … permission denied" on every turn after
37
+ * the first (same boot or across suspend/resume; reproduced against e2b
38
+ * 2.30.5). Cloud sessions construct a fresh runner per turn, so an
39
+ * iteration counter alone reuses `…-0.in` per conversation — the exact
40
+ * production failure. The timestamp+counter+random suffix is collision-proof
41
+ * across runner instances AND concurrent turns in one sandbox; the readable
42
+ * prefix (kind/agent/iteration) stays for debugging.
43
+ */
44
+ export declare function uniquePromptPath(kind: string, agentId: string, iteration: number): string;
30
45
  /** Hard deadline (ms) for the ACP `initialize` handshake AND the prompt turn.
31
46
  * `peer.initialize()` resolves only when the agent answers; a real CLI that
32
47
  * never speaks ACP (or blocks on stdin) would otherwise hang forever and the
@@ -54,6 +69,13 @@ export declare const ACP_TURN_IDLE_TIMEOUT_MS: number;
54
69
  * implements duplex) falls back to JSONL cleanly via the capability check in
55
70
  * `sendMessage`. */
56
71
  export declare const ACP_TRANSPORT_READY = true;
72
+ /** Reasoning-effort level a CLI turn may carry (T2 session effort). The
73
+ * per-CLI mapping lives in each spec's `buildCommand` — Claude Code takes a
74
+ * thinking-token budget via `MAX_THINKING_TOKENS`, codex takes
75
+ * `-c model_reasoning_effort=<level>`. Specs without a real knob
76
+ * (opencode/droid/cursor) never receive one: the server hides + rejects
77
+ * effort for those runtimes. */
78
+ export type CliReasoningEffort = "low" | "medium" | "high";
57
79
  /** Per-CLI behaviour. The base owns the lifecycle (init/done/error) and the
58
80
  * transport (spawn + JSONL parse); a spec owns the CLI-specific bits. */
59
81
  export interface CliAgentSpec {
@@ -78,12 +100,15 @@ export interface CliAgentSpec {
78
100
  * JSONL user message for a `--stream-json-input` CLI (amp). */
79
101
  promptPayload(prompt: string): string;
80
102
  /** Build the one-shot shell command for a turn. `promptPath` is a file in the
81
- * sandbox holding `promptPayload(prompt)`; `sessionId` continues a thread. */
103
+ * sandbox holding `promptPayload(prompt)`; `sessionId` continues a thread.
104
+ * `effort` is present only when the caller configured a reasoning effort
105
+ * AND the spec has a real knob for it (see `CliReasoningEffort`). */
82
106
  buildCommand(args: {
83
107
  promptPath: string;
84
108
  sessionId?: string;
85
109
  model?: string;
86
110
  cwd?: string;
111
+ effort?: CliReasoningEffort;
87
112
  }): string;
88
113
  /** Map one parsed JSONL stdout event to `AgentMessage`s. The base emits
89
114
  * `init`/`done`/`error` lifecycle itself, so a spec maps only content +
@@ -114,6 +139,7 @@ export declare class CliAgentRunner implements ModelExecutionContract {
114
139
  private readonly options;
115
140
  private readonly spec;
116
141
  private readonly configModel?;
142
+ private readonly configEffort?;
117
143
  readonly kind: string;
118
144
  /** Whether the live ACP path will actually run for this runner: the spec
119
145
  * declares an `acp` invocation, the transport is ready, AND the live provider
@@ -155,7 +181,7 @@ export declare class CliAgentRunner implements ModelExecutionContract {
155
181
  * exercising the real `sendMessageAcp` even while the production default is
156
182
  * dormant. Not a public API. */
157
183
  private acpTransportReady;
158
- constructor(sandbox: SandboxProvider, options: RuntimeOptions, spec: CliAgentSpec, configModel?: string | undefined);
184
+ constructor(sandbox: SandboxProvider, options: RuntimeOptions, spec: CliAgentSpec, configModel?: string | undefined, configEffort?: CliReasoningEffort | undefined);
159
185
  /** TEST-ONLY: flip the live-ACP readiness gate on for this runner instance so
160
186
  * the ACP lifecycle / fallback tests can exercise `sendMessageAcp` while the
161
187
  * production default (`ACP_TRANSPORT_READY`) stays dormant. Not part of the
@@ -240,11 +266,30 @@ export declare class CliAgentRunner implements ModelExecutionContract {
240
266
  private spawnAcpProcess;
241
267
  /**
242
268
  * Legacy JSONL transport (the version-mismatch fallback, ADR-0020 increment
243
- * 5 retires it). Unchanged behaviour: write the prompt to a file, run the
269
+ * 5 retires it) — and the ONLY transport on server→sandbox providers (no
270
+ * `spawnDuplex`, so ACP never engages). Write the prompt to a file, run the
244
271
  * one-shot command, line-buffer stdout, `mapEvent` each parsed line, and cap
245
272
  * with the runner-synthesised `done`. Does NOT re-yield `init` (the caller
246
273
  * already did).
274
+ *
275
+ * Deadline + termination semantics (both load-bearing on the server→E2B
276
+ * cloud-session path):
277
+ * - `timeoutMs: 0` disables the PROVIDER's own command deadline. E2B's
278
+ * `CommandStartOpts` defaults to 60s — a fraction of a real coding
279
+ * turn — and connect-web normalises `<= 0` to "no deadline" (the same
280
+ * idiom `launchStep` uses for the hours-long step runner). The local
281
+ * and Vercel providers already treat 0/absent as "no deadline". The
282
+ * turn's deadline belongs to the CALLER: the abort signal here, the
283
+ * bridge waiter's idle/absolute caps, or the in-VM step deadline.
284
+ * - Abort and early generator exit KILL the in-sandbox CLI process via
285
+ * the provider's kill-capable background handle (`runBackground` —
286
+ * present on E2B, the provider every server-driven turn runs on), so a
287
+ * cancelled/timed-out/superseded turn can never leave an orphan agent
288
+ * mutating the working tree. Providers without `runBackground` (local
289
+ * child_process, Vercel) fall back to `commands.run`: no kill handle,
290
+ * abort only stops consumption — the pre-ACP behaviour of the in-VM
291
+ * JSONL fallback, bounded by the sandbox VM's own lifetime.
247
292
  */
248
293
  private sendMessageJsonl;
249
294
  }
250
- export declare function createCliAgentRuntime(spec: CliAgentSpec, configModel?: string): import("../index.js").AgentRuntime<SandboxProvider>;
295
+ export declare function createCliAgentRuntime(spec: CliAgentSpec, configModel?: string, configEffort?: CliReasoningEffort): import("../index.js").AgentRuntime<SandboxProvider>;
@@ -0,0 +1,103 @@
1
+ /**
2
+ * JSONL frame guard — keeps oversized lines OFF the server→sandbox command
3
+ * stream.
4
+ *
5
+ * The live failure this exists for: a cloud session's turn stream rides
6
+ * `sandbox.commands.run` over E2B's connect-web gRPC command stream, and that
7
+ * transport dies at the wire on large payloads — connect-web throws
8
+ * `13: [internal] protocol error: received unsupported compressed output`
9
+ * the moment an envelope arrives with the compressed flag set
10
+ * (@connectrpc/connect-web connect-transport.js), which is what E2B's edge
11
+ * does to it on big frames. A single `claude` stream-json event echoing a
12
+ * whole Read file (hundreds of KB on ONE JSONL line) is exactly such a
13
+ * payload: the stream faults mid-turn, the platform classifies it as a
14
+ * protocol transport fault (server cloud-executor.ts), recycles the VM, and
15
+ * the turn's work is lost.
16
+ *
17
+ * The structural fix: the full content is already durable INSIDE the sandbox
18
+ * (the file on disk, the CLI's own session transcript), so the wire never
19
+ * needs it. A tiny dependency-free node filter runs in-sandbox, piped after
20
+ * the CLI, and rewrites any oversized JSONL line before it can reach the
21
+ * vulnerable stream: long strings inside the event are truncated with an
22
+ * EXPLICIT elision marker (a silent cut is how models and humans end up
23
+ * trusting hallucinated file contents), and a line that cannot be capped
24
+ * structurally is hard-truncated so the stream survives at the cost of that
25
+ * one event. The prompt travels the other direction over `files.write` —
26
+ * E2B's envd HTTP API, a different transport documented immune to this
27
+ * failure (see the `files.read` comment in sandbox/providers/e2b.ts) — and
28
+ * the guard script itself is delivered the same immune way.
29
+ *
30
+ * Exit codes: piping would normally replace the CLI's exit code with the
31
+ * filter's, so the wrapper prints a per-turn random sentinel line carrying
32
+ * `$?` after the CLI exits and the filter re-raises it as its own exit code.
33
+ * EOF without a sentinel means the producer died abnormally (killed
34
+ * mid-pipe) — the filter exits JSONL_GUARD_NO_SENTINEL_EXIT so a crashed CLI
35
+ * can never masquerade as a clean turn.
36
+ *
37
+ * `capJsonlLine` is deliberately SELF-CONTAINED (no imports, no captured
38
+ * helpers): `jsonlGuardScript()` embeds it via `Function.prototype.toString`
39
+ * so the exact logic the unit tests pin is the logic that runs in-sandbox —
40
+ * one implementation, two call sites.
41
+ */
42
+ /** Trigger threshold: a JSONL line at or under this many bytes passes
43
+ * through byte-identical; over it, the guard rewrites. Chosen well under
44
+ * whatever E2B's edge chokes on (the observed kills were multi-hundred-KB
45
+ * single lines) while comfortably above any sane tool result. */
46
+ export declare const JSONL_GUARD_LINE_CAP_BYTES: number;
47
+ /** How many bytes of an oversized string survive elision (the head — tool
48
+ * output fronts-loads the signal: file starts, command output starts). */
49
+ export declare const JSONL_GUARD_KEEP_BYTES: number;
50
+ /** The guard's exit code when its stdin hit EOF WITHOUT the exit sentinel:
51
+ * the producer pipeline died abnormally (killed / crashed sh), so the turn
52
+ * must surface as an error, never a clean done. */
53
+ export declare const JSONL_GUARD_NO_SENTINEL_EXIT = 121;
54
+ /** Stable prefix of the elision marker appended to every truncated string.
55
+ * Exported so consumers/tests can detect an elided payload; a unit test
56
+ * pins that `capJsonlLine`'s embedded copy matches this constant. */
57
+ export declare const JSONL_ELISION_MARKER_PREFIX = "[agent-compose: PAYLOAD ELIDED IN TRANSIT";
58
+ /**
59
+ * Cap one JSONL line to at most `maxBytes` bytes.
60
+ *
61
+ * - At or under `maxBytes`: returned byte-identical (never re-serialized).
62
+ * - Over it and parseable as a JSON object/array: every string longer than
63
+ * `keepBytes` is truncated to its first `keepBytes` bytes plus an honest
64
+ * elision marker telling the reader the full content still exists in the
65
+ * sandbox and how to get it. If the result still exceeds `maxBytes`
66
+ * (many big strings), the per-string budget shrinks 8× and then 64× before
67
+ * giving up.
68
+ * - Unparseable, or uncappable even at the smallest budget: hard byte
69
+ * truncation to `maxBytes`. The line stops being valid JSON, so the
70
+ * consumer's parse skips it — one event lost, stream alive (strictly
71
+ * better than the whole turn dying).
72
+ *
73
+ * SELF-CONTAINED by contract: no imports, no outer-scope references except
74
+ * globals (`Buffer`, `JSON`) — `jsonlGuardScript()` ships `this.toString()`
75
+ * into the sandbox. Keep it that way.
76
+ */
77
+ export declare function capJsonlLine(line: string, maxBytes: number, keepBytes: number): string;
78
+ /**
79
+ * The in-sandbox filter's source: a dependency-free node script that
80
+ * line-buffers stdin, re-emits every line through `capJsonlLine`, and turns
81
+ * the exit sentinel into its own exit code.
82
+ *
83
+ * node <script> <sentinel> <maxBytes> <keepBytes>
84
+ */
85
+ export declare function jsonlGuardScript(): string;
86
+ /**
87
+ * Wrap a turn command so its stdout crosses the command stream through the
88
+ * guard. Self-deciding in-sandbox: when `node` is absent (a bare sandbox a
89
+ * self-provisioned CLI runs on), the command runs unguarded — the pre-guard
90
+ * status quo — instead of failing every turn.
91
+ *
92
+ * The command runs in a SUBSHELL so a `$?`-carrying sentinel line always
93
+ * prints after it exits, however it exits (a brace group would let a shell
94
+ * `exit` skip the printf). stderr stays un-piped — the provider's stderr
95
+ * accumulation is unchanged.
96
+ */
97
+ export declare function wrapJsonlCommand(args: {
98
+ cmd: string;
99
+ guardPath: string;
100
+ sentinel: string;
101
+ maxBytes: number;
102
+ keepBytes: number;
103
+ }): string;
@@ -18,6 +18,6 @@ export interface AmpRuntimeConfig {
18
18
  /** Amp uses its configured model; reserved for forward-compatibility. */
19
19
  model?: string;
20
20
  }
21
- export declare function createAmpRuntime(config?: AmpRuntimeConfig): import("../index.js").AgentRuntime<import("../index.js").SandboxProvider>;
22
- declare const _default: import("../index.js").AgentRuntime<import("../index.js").SandboxProvider>;
21
+ export declare function createAmpRuntime(config?: AmpRuntimeConfig): import("../index.js").AgentRuntime<import("../sandbox.js").SandboxProvider>;
22
+ declare const _default: import("../index.js").AgentRuntime<import("../sandbox.js").SandboxProvider>;
23
23
  export default _default;
@@ -0,0 +1,59 @@
1
+ /**
2
+ * Claude Code CLI runtime — drives the `claude` coding CLI headless INSIDE
3
+ * the sandbox (`claude -p --output-format stream-json`) and maps its JSONL
4
+ * event stream onto the AgentMessage contract.
5
+ *
6
+ * This is a different mechanism from `claudeRuntime` (claude.ts): that one
7
+ * drives the Anthropic Agent SDK in the CALLING process, which makes it
8
+ * unusable wherever the caller is the server (a cloud session's turns) —
9
+ * "never execute user-provided source in the server process". This runtime
10
+ * is a CLI-agent spec like codex/opencode: the agent loop runs entirely
11
+ * in-sandbox and we only stream-parse the events it prints, so the
12
+ * server→sandbox cloud-executor path can host it (CLOUD_SESSION_RUNTIMES).
13
+ *
14
+ * Transports, mirroring codexSpec exactly:
15
+ * - ACP: the Zed adapter (`npx @zed-industries/claude-code-acp`) — the SAME
16
+ * pinned adapter the local bridge daemon launches (cli/src/bridge/acp.ts
17
+ * imports the pin from here). Engages only where the provider exposes
18
+ * `commands.spawnDuplex` (the in-VM/local view); the server→sandbox
19
+ * E2B/Vercel view has no duplex, so cloud-session turns always drive the
20
+ * JSONL path below. Cold start: the adapter is npx-fetched on first
21
+ * launch (~10-30s once per sandbox lifetime; node/npm are in the
22
+ * agent-env image).
23
+ * - JSONL: `claude -p --output-format stream-json --verbose`, resume via
24
+ * `--resume <session_id>`. The `claude` binary is BAKED into the
25
+ * `agent-env-<size>` E2B image at /usr/local/bin/claude
26
+ * (infra/e2b-template/build.ts), so there is no install cold-start on the
27
+ * platform path; the `install` below is the bare-sandbox fallback.
28
+ *
29
+ * Auth (in-sandbox env, in the CLI's own precedence order):
30
+ * - `CLAUDE_CODE_OAUTH_TOKEN` — a user subscription (BYOS setup-token /
31
+ * OAuth grant); rides the user's plan directly against Anthropic.
32
+ * - `ANTHROPIC_API_KEY` (+ `ANTHROPIC_BASE_URL`) — an API key; for cloud
33
+ * sessions this is the gateway-minted session virtual key pointed at the
34
+ * token-metering gateway's Anthropic passthrough (ADR-0039).
35
+ */
36
+ import { type CliAgentSpec, type CliReasoningEffort } from "./_cli-agent.js";
37
+ /** Pinned Claude Code ACP adapter (Zed's npm shim — `claude` has no native
38
+ * ACP mode). Pinned EXACT, not a range: the adapter's README warns of
39
+ * breaking changes; bump deliberately and re-verify a live turn. The local
40
+ * bridge daemon (cli/src/bridge/acp.ts) imports this same pin so both
41
+ * executors launch the identical adapter. Verified against 0.16.2. */
42
+ export declare const CLAUDE_CODE_ACP_ADAPTER = "@zed-industries/claude-code-acp@0.16.2";
43
+ /** Extended-thinking token budget per effort level — Claude Code's real knob
44
+ * is the `MAX_THINKING_TOKENS` env var (its documented settings env), set
45
+ * per invocation below. Values mirror the platform turn loop's
46
+ * `EFFORT_BUDGET_TOKENS` (server model-client) so "high" means the same
47
+ * thing in a channel and in a claude-code session. */
48
+ export declare const CLAUDE_CODE_THINKING_TOKENS: Record<CliReasoningEffort, number>;
49
+ export declare const claudeCodeSpec: CliAgentSpec;
50
+ export interface ClaudeCodeRuntimeConfig {
51
+ /** Claude model id (`--model`). Omit to use the CLI's configured default. */
52
+ model?: string;
53
+ /** Extended-thinking effort (`MAX_THINKING_TOKENS`). Omit for the CLI's
54
+ * default behaviour (no forced budget). */
55
+ effort?: CliReasoningEffort;
56
+ }
57
+ export declare function createClaudeCodeRuntime(config?: ClaudeCodeRuntimeConfig): import("../index.js").AgentRuntime<import("../sandbox.js").SandboxProvider>;
58
+ declare const _default: import("../index.js").AgentRuntime<import("../sandbox.js").SandboxProvider>;
59
+ export default _default;
@@ -0,0 +1,14 @@
1
+ /**
2
+ * claude-code CLI-agent spec — the in-sandbox `claude -p --output-format
3
+ * stream-json` transport for cloud sessions (the cloud-hostable counterpart
4
+ * of the in-process `claudeRuntime`).
5
+ *
6
+ * - buildCommand: headless stream-json invocation, stdin prompt, resume
7
+ * via --resume, cwd via `cd`, IS_SANDBOX=1 (root-user permission skip);
8
+ * - mapEvent: assistant content blocks → text/thinking/tool_use, user
9
+ * tool_result echoes → tool_result, result → usage on success and an
10
+ * honest STRING error on failure;
11
+ * - the ACP invocation pins the SAME Zed adapter the local bridge daemon
12
+ * launches, so both executors drive one adapter version.
13
+ */
14
+ export {};
@@ -30,6 +30,22 @@ export interface ClaudeRuntimeConfig {
30
30
  * `agentc init`; default `"all"` makes them usable. Pass `[]` to disable. */
31
31
  skills?: string[] | "all";
32
32
  }
33
+ /** Bounded tail of the Claude Code process's stderr. The Agent SDK's
34
+ * process-exit error carries ONLY the exit code ("Claude Code process
35
+ * exited with code 1") — the CLI's actual complaint goes to stderr, which
36
+ * query() surfaces exclusively through the `stderr` callback. Without
37
+ * capturing it, a startup failure (bad flag, root refusal, dead config)
38
+ * reaches the run card as an uninformative exit code. Same 2000-char cap
39
+ * as the CLI-agent runtimes' exit-code tail (_cli-agent.ts). */
40
+ export declare const STDERR_TAIL_CAP = 2000;
41
+ export declare class StderrTail {
42
+ private buf;
43
+ append(data: string): void;
44
+ /** The captured tail, trimmed — empty string when nothing was written. */
45
+ get text(): string;
46
+ /** Suffix an error message with the tail (no-op when stderr was silent). */
47
+ decorate(message: string): string;
48
+ }
33
49
  export declare class ClaudeRunner implements ModelExecutionContract {
34
50
  private readonly options;
35
51
  private readonly config;
@@ -0,0 +1,8 @@
1
+ /**
2
+ * ClaudeRunner stderr-tail capture — the Agent SDK's process-exit error
3
+ * ("Claude Code process exited with code 1") carries no detail; the CLI's
4
+ * actual complaint goes to stderr, surfaced only through query()'s `stderr`
5
+ * callback. The runner must capture a bounded tail and attach it to the
6
+ * error message so a startup failure is diagnosable from the run card.
7
+ */
8
+ export {};
@@ -12,7 +12,10 @@
12
12
  * Verified against codex-cli 0.124.0: `codex exec --json` + resume-by-thread,
13
13
  * with the command_execution / reasoning / agent_message item shapes below.
14
14
  */
15
- import { type CliAgentSpec } from "./_cli-agent.js";
15
+ import { type CliAgentSpec, type CliReasoningEffort } from "./_cli-agent.js";
16
+ /** True when an error-item message is a known codex advisory (log-level
17
+ * noise), not a real error. Exported for tests. */
18
+ export declare function isCodexAdvisoryNoise(text: string): boolean;
16
19
  /** Exported for the fixture-based parity tests (ADR-0020): the legacy JSONL
17
20
  * `mapEvent` is the golden the ACP normaliser is asserted equal to. Not part
18
21
  * of the public runtime surface — `createCodexRuntime` stays the entry point. */
@@ -20,7 +23,10 @@ export declare const codexSpec: CliAgentSpec;
20
23
  export interface CodexRuntimeConfig {
21
24
  /** Codex model id (`-m`). Omit to use the codex CLI's configured default. */
22
25
  model?: string;
26
+ /** Reasoning effort (`-c model_reasoning_effort=<level>`). Omit to use the
27
+ * codex CLI's configured default. */
28
+ effort?: CliReasoningEffort;
23
29
  }
24
- export declare function createCodexRuntime(config?: CodexRuntimeConfig): import("../index.js").AgentRuntime<import("../index.js").SandboxProvider>;
25
- declare const _default: import("../index.js").AgentRuntime<import("../index.js").SandboxProvider>;
30
+ export declare function createCodexRuntime(config?: CodexRuntimeConfig): import("../index.js").AgentRuntime<import("../sandbox.js").SandboxProvider>;
31
+ declare const _default: import("../index.js").AgentRuntime<import("../sandbox.js").SandboxProvider>;
26
32
  export default _default;
@@ -4,6 +4,6 @@ export interface CursorRuntimeConfig {
4
4
  /** Cursor model id; ACP mode ignores it (account default) — applies to the `-p` fallback. */
5
5
  model?: string;
6
6
  }
7
- export declare function createCursorRuntime(config?: CursorRuntimeConfig): import("../index.js").AgentRuntime<import("../index.js").SandboxProvider>;
8
- declare const _default: import("../index.js").AgentRuntime<import("../index.js").SandboxProvider>;
7
+ export declare function createCursorRuntime(config?: CursorRuntimeConfig): import("../index.js").AgentRuntime<import("../sandbox.js").SandboxProvider>;
8
+ declare const _default: import("../index.js").AgentRuntime<import("../sandbox.js").SandboxProvider>;
9
9
  export default _default;
@@ -4,6 +4,6 @@ export interface DroidRuntimeConfig {
4
4
  /** `custom:<displayName>-<index>` matching the provisioned settings.json. */
5
5
  model?: string;
6
6
  }
7
- export declare function createDroidRuntime(config?: DroidRuntimeConfig): import("../index.js").AgentRuntime<import("../index.js").SandboxProvider>;
8
- declare const _default: import("../index.js").AgentRuntime<import("../index.js").SandboxProvider>;
7
+ export declare function createDroidRuntime(config?: DroidRuntimeConfig): import("../index.js").AgentRuntime<import("../sandbox.js").SandboxProvider>;
8
+ declare const _default: import("../index.js").AgentRuntime<import("../sandbox.js").SandboxProvider>;
9
9
  export default _default;
@@ -0,0 +1,19 @@
1
+ /**
2
+ * JSONL frame guard — the canary for the session-machine recycling failure.
3
+ *
4
+ * The live incident: a cloud session's turn stream rides `commands.run` over
5
+ * E2B's connect-web gRPC command stream, and a single multi-hundred-KB JSONL
6
+ * line (a `claude` stream-json event echoing a whole Read file) kills that
7
+ * stream with `13: [internal] protocol error: received unsupported compressed
8
+ * output` — the platform recycles the VM and the turn's work is lost.
9
+ *
10
+ * These tests pin the fix at three altitudes:
11
+ * 1. `capJsonlLine` (unit) — the shared cap logic.
12
+ * 2. The GENERATED guard script, executed by a REAL `node` subprocess —
13
+ * the exact bytes that run in-sandbox, including the exit-code sentinel.
14
+ * 3. The runner end-to-end through `makeLocalSandboxProvider` — a real
15
+ * `sh` pipeline: a synthetic oversized tool_result crosses the command
16
+ * boundary UN-FATALLY, arrives with the elision marker, and the turn
17
+ * completes with `done`.
18
+ */
19
+ export {};