@agent-compose/sdk 0.8.4 → 0.8.6

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 (106) hide show
  1. package/README.md +213 -189
  2. package/dist/agent/agent-context.d.ts +9 -1
  3. package/dist/agent/agent-loop.d.ts +14 -6
  4. package/dist/agent/perf-sampler.d.ts +27 -2
  5. package/dist/agent/run-agent.d.ts +1 -1
  6. package/dist/client.d.ts +250 -59
  7. package/dist/directives.d.ts +14 -0
  8. package/dist/display.d.ts +7 -0
  9. package/dist/errors.d.ts +1 -1
  10. package/dist/generated/agentc-commands.d.ts +34 -0
  11. package/dist/index.d.ts +13 -11
  12. package/dist/index.js +1692 -194
  13. package/dist/request-context/request-context.d.ts +1 -1
  14. package/dist/runtimes/_cli-agent.d.ts +278 -58
  15. package/dist/runtimes/claude-code.d.ts +90 -1
  16. package/dist/runtimes/claude.d.ts +1 -1
  17. package/dist/runtimes/codex.d.ts +94 -6
  18. package/dist/runtimes/codex.mid-turn-hook.test.d.ts +10 -0
  19. package/dist/runtimes/openai-desktop.d.ts +50 -0
  20. package/dist/runtimes/openai-desktop.js +1689 -211
  21. package/dist/runtimes/openai-desktop.test.d.ts +20 -0
  22. package/dist/runtimes/opencode.d.ts +48 -11
  23. package/dist/runtimes/opencode.test.d.ts +14 -0
  24. package/dist/runtimes/tool-pulse.test.d.ts +17 -0
  25. package/dist/sandbox/baked-clis.d.ts +75 -0
  26. package/dist/sandbox/devbox.d.ts +5 -5
  27. package/dist/sandbox/exec-stream.d.ts +1 -2
  28. package/dist/sandbox/network-policy.d.ts +23 -5
  29. package/dist/sandbox/registry.d.ts +12 -0
  30. package/dist/sandbox/sizes.d.ts +11 -5
  31. package/dist/sandbox.d.ts +5 -3
  32. package/dist/step-invocation/protocol.d.ts +3 -4
  33. package/dist/step-invocation/server.d.ts +2 -2
  34. package/dist/step-invocation/types.d.ts +2 -2
  35. package/dist/types/api-conversations.d.ts +513 -27
  36. package/dist/types/api-factory.d.ts +183 -3
  37. package/dist/types/api-projects.d.ts +480 -0
  38. package/dist/types/api-runs.d.ts +8 -0
  39. package/dist/types/api-scopes.d.ts +32 -3
  40. package/dist/types/conversation-stream.d.ts +27 -1
  41. package/dist/types/execution-context.d.ts +1 -1
  42. package/dist/types/protocol.d.ts +182 -2
  43. package/dist/types/runtime.d.ts +80 -2
  44. package/dist/types/workflow-metadata.d.ts +2 -4
  45. package/dist/types/workflow-plan.d.ts +1 -3
  46. package/dist/utils/bundler.d.ts +23 -0
  47. package/dist/workflow-steps/observability.d.ts +2 -3
  48. package/dist/workflow-steps/runner.d.ts +5 -8
  49. package/dist/workflow-steps/types.d.ts +8 -10
  50. package/dist/workflow-steps/workflow.d.ts +2 -1
  51. package/dist/workflows/engine.d.ts +3 -5
  52. package/dist/workflows/invoke-child.d.ts +2 -2
  53. package/package.json +2 -2
  54. package/src/agent/agent-context.ts +193 -116
  55. package/src/agent/agent-loop.ts +16 -9
  56. package/src/agent/desktop-open.ts +13 -1
  57. package/src/agent/perf-sampler.ts +54 -3
  58. package/src/agent/run-agent.ts +1 -1
  59. package/src/client.ts +418 -80
  60. package/src/directives.ts +21 -1
  61. package/src/display.ts +12 -0
  62. package/src/errors.ts +1 -0
  63. package/src/generated/agentc-commands.ts +571 -0
  64. package/src/index.ts +65 -18
  65. package/src/pause/pause-core.ts +2 -1
  66. package/src/request-context/request-context.ts +1 -1
  67. package/src/runtimes/_cli-agent.ts +607 -132
  68. package/src/runtimes/claude-code.ts +427 -20
  69. package/src/runtimes/claude.ts +1 -1
  70. package/src/runtimes/codex.ts +188 -19
  71. package/src/runtimes/openai-desktop.ts +82 -19
  72. package/src/runtimes/opencode.ts +195 -26
  73. package/src/sandbox/baked-clis.ts +86 -0
  74. package/src/sandbox/devbox.ts +5 -5
  75. package/src/sandbox/exec-stream.ts +1 -2
  76. package/src/sandbox/network-policy.ts +51 -7
  77. package/src/sandbox/providers/e2b.ts +63 -19
  78. package/src/sandbox/providers/vercel.ts +6 -6
  79. package/src/sandbox/registry.ts +19 -1
  80. package/src/sandbox/sizes.ts +11 -5
  81. package/src/sandbox.ts +9 -2
  82. package/src/step-invocation/invoker.ts +2 -6
  83. package/src/step-invocation/protocol.ts +3 -4
  84. package/src/step-invocation/server.ts +2 -2
  85. package/src/types/api-conversations.ts +424 -29
  86. package/src/types/api-factory.ts +189 -3
  87. package/src/types/api-projects.ts +443 -0
  88. package/src/types/api-runs.ts +5 -0
  89. package/src/types/api-scopes.ts +32 -3
  90. package/src/types/conversation-stream.ts +29 -1
  91. package/src/types/execution-context.ts +1 -1
  92. package/src/types/protocol.ts +180 -2
  93. package/src/types/runtime.ts +71 -2
  94. package/src/types/sandbox-environment.ts +1 -2
  95. package/src/types/workflow-metadata.ts +2 -4
  96. package/src/types/workflow-plan.ts +1 -3
  97. package/src/utils/bundler.ts +88 -19
  98. package/src/workflow-steps/observability.ts +2 -3
  99. package/src/workflow-steps/runner.ts +5 -8
  100. package/src/workflow-steps/types.ts +8 -10
  101. package/src/workflow-steps/workflow.ts +2 -1
  102. package/src/workflows/engine.ts +3 -5
  103. package/src/workflows/invoke-child.ts +2 -2
  104. package/dist/pause/__tests__/errors.test.d.ts +0 -1
  105. package/dist/pause/__tests__/wrappers.test.d.ts +0 -1
  106. package/dist/step-invocation/__tests__/protocol.test.d.ts +0 -1
@@ -6,7 +6,7 @@
6
6
  * at creation time.
7
7
  */
8
8
 
9
- import { SandboxNotFoundError, RateLimitError } from "e2b";
9
+ import { SandboxNotFoundError, RateLimitError, NotFoundError } from "e2b";
10
10
  import pRetry from "p-retry";
11
11
  import type { FailedAttemptError } from "p-retry";
12
12
  import type { SandboxProvider } from "../types/sandbox.js";
@@ -45,6 +45,24 @@ function isTransientSandboxError(error: unknown): boolean {
45
45
  .test(message);
46
46
  }
47
47
 
48
+ /** Did a CREATE fail because its create SOURCE (template alias / snapshot id)
49
+ * does not resolve on the provider — vs any other create fault? The server's
50
+ * recovery-boot fall-through keys on this: a ring snapshot licensed on an
51
+ * INDETERMINATE existence probe that turns out to be gone must fall through
52
+ * the ring toward the base image, while every other create fault (quota,
53
+ * auth, 5xx, network) must propagate — falling through on those would trade
54
+ * a still-recoverable machine state for a base boot. E2B maps the create-
55
+ * time 404 ("template not found") to its typed `NotFoundError`; the message
56
+ * match is the fallback for untyped transports (Vercel). Lives in the SDK
57
+ * because the server holds its OWN `e2b` module instance — an `instanceof`
58
+ * against the class from the wrong copy is always false. */
59
+ export function isSandboxSourceNotFoundError(error: unknown): boolean {
60
+ if (error instanceof NotFoundError) return true;
61
+ const message = error instanceof Error ? error.message : String(error ?? "");
62
+ return /(?:template|snapshot)[^\n]{0,80}not[\s_-]?found|not[\s_-]?found[^\n]{0,80}(?:template|snapshot)/i
63
+ .test(message);
64
+ }
65
+
48
66
  /** The ONE place the sandbox retry policy lives. Provisioning, reconnecting, and
49
67
  * snapshotting all race with the sandbox being paused/reclaimed; this runs the call
50
68
  * through p-retry's generic backoff, retrying ONLY the transient race (and failing
@@ -148,15 +148,21 @@ export function sandboxSizeLabel(size: SandboxSize): string {
148
148
  /** Stable E2B template ALIAS for the platform base at a given size
149
149
  * (`agent-compose-base-<size>`). Aliases — not snapshot ids — so the refs are
150
150
  * multi-account-clean: the same string resolves in any E2B account that built
151
- * the templates. Built by `infra/e2b-template/build.ts`; the E2B provider
152
- * boots this when a run on E2B declares no explicit `bootFrom`/template. */
151
+ * the templates. Built by `infra/e2b-template/build.ts`. An EXPLICIT
152
+ * `bootFrom`/template target only — nothing boots it by default: template-less
153
+ * E2B creates resolve `e2bAgentEnvTemplate` (the session-identical image)
154
+ * instead, so the run and session lanes can never diverge on baked tooling. */
153
155
  export function e2bBaseTemplate(size: SandboxSize): string {
154
156
  return `agent-compose-base-${size}`;
155
157
  }
156
158
 
157
- /** Stable E2B template ALIAS for the agent runtime (base + claude binary) at a
158
- * given size (`agent-env-<size>`). The agent default templates boot from this
159
- * via `bootFrom: { snapshotId: e2bAgentEnvTemplate(size) }`. Multi-account-clean
159
+ /** Stable E2B template ALIAS for the agent runtime (base + claude binary +
160
+ * dev toolbelt + session desktop) at a given size (`agent-env-<size>`).
161
+ * THE default E2B boot image, both lanes: every cloud SESSION boots it
162
+ * (server/src/sandbox/persistent.ts), and every template-less E2B workflow
163
+ * RUN boots it too (the e2b provider's size-matched default). The agent
164
+ * default templates boot from this via
165
+ * `bootFrom: { snapshotId: e2bAgentEnvTemplate(size) }`. Multi-account-clean
160
166
  * for the same reason as `e2bBaseTemplate`. */
161
167
  export function e2bAgentEnvTemplate(size: SandboxSize): string {
162
168
  return `agent-env-${size}`;
package/src/sandbox.ts CHANGED
@@ -5,8 +5,9 @@
5
5
  * - `sandbox/network-policy.ts` — egress policy shape + per-provider translators
6
6
  * - `sandbox/sizes.ts` — machine sizes + E2B template aliases
7
7
  * - `sandbox/devbox.ts` — the ADR-0038 per-member desktop machine alias
8
+ * - `sandbox/baked-clis.ts` — harness CLI versions the session image bakes
8
9
  * - `sandbox/provider-def.ts` — provider contract, create opts, fleet tag
9
- * - `sandbox/exec-stream.ts` — SSE exec-stream parser (broker clients)
10
+ * - `sandbox/exec-stream.ts` — SSE exec-stream parser
10
11
  * - `sandbox/providers/*` — vercel / e2b / e2b-desktop / local providers
11
12
  * - `sandbox/registry.ts` — provider registry + fleet management
12
13
  */
@@ -19,7 +20,7 @@ export type {
19
20
  SandboxNetworkSubnetPolicy,
20
21
  SandboxNetworkPolicy,
21
22
  } from "./sandbox/network-policy.js";
22
- export { DOT_SEGMENT_PATH_RE2, toVercelNetworkPolicy, toE2bNetwork } from "./sandbox/network-policy.js";
23
+ export { DOT_SEGMENT_PATH_RE2, openEgressExcept, toVercelNetworkPolicy, toE2bNetwork } from "./sandbox/network-policy.js";
23
24
 
24
25
  export type { SandboxSize } from "./sandbox/sizes.js";
25
26
  export {
@@ -48,6 +49,11 @@ export {
48
49
  e2bDevboxTemplateRef,
49
50
  } from "./sandbox/devbox.js";
50
51
 
52
+ export {
53
+ CLAUDE_CODE_VERSION, CODEX_CLI_VERSION, OPENCODE_CLI_VERSION, RTK_VERSION,
54
+ CLAUDE_CODE_NO_SELF_UPDATE_ENV, CODEX_NO_SELF_UPDATE_CONFIG_LINE, OPENCODE_NO_SELF_UPDATE_CONFIG,
55
+ } from "./sandbox/baked-clis.js";
56
+
51
57
  export { AGENT_COMPOSE_TAG } from "./sandbox/provider-def.js";
52
58
  export type { SandboxCreateOpts, OwnedSandbox } from "./sandbox/provider-def.js";
53
59
 
@@ -65,6 +71,7 @@ export {
65
71
  reconnectSandbox,
66
72
  deleteSandboxSnapshot,
67
73
  snapshotResolves,
74
+ isSandboxSourceNotFoundError,
68
75
  getSandboxQuotas,
69
76
  listOwnedSandboxes,
70
77
  killSandboxById,
@@ -526,12 +526,8 @@ export async function invokeStep<TOutput = unknown>(
526
526
 
527
527
  let result: { stdout: string; stderr: string; exitCode: number };
528
528
  try {
529
- // Run the agent as ROOT (ADR-0019 follow-up). The factory drive (Archil)
530
- // presents its S3-synced files root-owned and exposes no uid-mapped mount,
531
- // so a non-root agent EACCESes on every shared file — the reason for the
532
- // expensive boot-time `chmod -R` walk. As root the agent writes them
533
- // directly: the walk disappears entirely. Egress is edge-enforced with NO
534
- // root exemption (see sandbox.ts), so root is confined exactly like the
529
+ // Run the agent as ROOT (ADR-0019 follow-up). Egress is edge-enforced with
530
+ // NO root exemption (see sandbox.ts), so root is confined exactly like the
535
531
  // non-root user. `HOME=/root` so the spawned `claude` finds root's skills.
536
532
  //
537
533
  // Same pipeline pattern as `launchStep`: tee the runner's stdout to the
@@ -38,12 +38,11 @@ export function stepPauseLinePrefix(token: string): string {
38
38
  return `${STEP_PAUSE_PREFIX}${token}:`;
39
39
  }
40
40
 
41
- /** Sandbox-side path where dispatch writes the compiled runner bundle.
42
- * Both modes (full-mode `dispatch.ts` and step-mode `invokeStep`) spawn
43
- * the runner from this path; single source of truth. */
41
+ /** Sandbox-side path where the sandbox bootstrap writes the compiled runner
42
+ * bundle; `invokeStep` spawns the runner from this path. */
44
43
  export const RUNNER_BUNDLE_PATH = "/tmp/runner.bundle.js";
45
44
 
46
- /** Command the invoker (and dispatch) spawns inside the sandbox. */
45
+ /** Command the invoker spawns inside the sandbox. */
47
46
  export const RUNNER_COMMAND = `node ${RUNNER_BUNDLE_PATH}`;
48
47
 
49
48
  /** Names of the env vars the invoker stamps onto the runner subprocess.
@@ -153,8 +153,8 @@ function scrubProtocolEnvs(): void {
153
153
  * from process.env so user code (including any workflow module imported
154
154
  * inside the handler) cannot read AC_STEP_RESULT_TOKEN — that keeps the
155
155
  * result channel uncorruptible by stdout output from anywhere in the
156
- * workflow's dep tree. RUN_ID remains available to match full-mode
157
- * runner behaviour.
156
+ * workflow's dep tree. RUN_ID remains available: SDK code inside the step
157
+ * (`agent()`, the client's parent-run link) reads it.
158
158
  */
159
159
  export async function serveStep<TInput, TOutput>(
160
160
  handler: StepHandler<TInput, TOutput>,