@agent-compose/sdk 0.8.4 → 0.8.5

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 (44) hide show
  1. package/dist/agent/agent-context.d.ts +9 -1
  2. package/dist/agent/agent-loop.d.ts +10 -1
  3. package/dist/client.d.ts +171 -33
  4. package/dist/directives.d.ts +14 -0
  5. package/dist/generated/verb-synopsis.d.ts +34 -0
  6. package/dist/index.d.ts +6 -4
  7. package/dist/index.js +1024 -39
  8. package/dist/runtimes/_cli-agent.d.ts +106 -0
  9. package/dist/runtimes/claude-code.d.ts +31 -1
  10. package/dist/runtimes/openai-desktop.d.ts +50 -0
  11. package/dist/runtimes/openai-desktop.js +1048 -57
  12. package/dist/runtimes/openai-desktop.test.d.ts +20 -0
  13. package/dist/runtimes/tool-pulse.test.d.ts +17 -0
  14. package/dist/sandbox/devbox.d.ts +5 -5
  15. package/dist/sandbox/registry.d.ts +12 -0
  16. package/dist/sandbox/sizes.d.ts +11 -5
  17. package/dist/sandbox.d.ts +1 -1
  18. package/dist/step-invocation/types.d.ts +1 -1
  19. package/dist/types/api-conversations.d.ts +85 -12
  20. package/dist/types/api-factory.d.ts +111 -1
  21. package/dist/types/conversation-stream.d.ts +22 -1
  22. package/dist/types/protocol.d.ts +118 -1
  23. package/dist/types/runtime.d.ts +71 -0
  24. package/package.json +1 -1
  25. package/src/agent/agent-context.ts +43 -9
  26. package/src/agent/agent-loop.ts +11 -5
  27. package/src/agent/desktop-open.ts +13 -1
  28. package/src/client.ts +256 -38
  29. package/src/directives.ts +21 -1
  30. package/src/generated/verb-synopsis.ts +544 -0
  31. package/src/index.ts +17 -3
  32. package/src/runtimes/_cli-agent.ts +313 -22
  33. package/src/runtimes/claude-code.ts +249 -12
  34. package/src/runtimes/openai-desktop.ts +82 -19
  35. package/src/sandbox/devbox.ts +5 -5
  36. package/src/sandbox/providers/e2b.ts +60 -16
  37. package/src/sandbox/registry.ts +19 -1
  38. package/src/sandbox/sizes.ts +11 -5
  39. package/src/sandbox.ts +1 -0
  40. package/src/types/api-conversations.ts +65 -13
  41. package/src/types/api-factory.ts +121 -1
  42. package/src/types/conversation-stream.ts +24 -1
  43. package/src/types/protocol.ts +113 -1
  44. package/src/types/runtime.ts +63 -0
@@ -60,6 +60,29 @@ export declare function runnerBusySentinelFragment(busyPath: string, tasksPath:
60
60
  * `date +%s%3N` in the same exec, so host clock skew is irrelevant) is
61
61
  * stale: three missed writes. */
62
62
  export declare const RUNNER_HEARTBEAT_STALE_MS: number;
63
+ /** The sh fragment the heartbeat subshell runs each beat to rewrite the
64
+ * pulse file: `<guest epoch ms>,<cpu jiffies>,<written bytes>,<procs>`
65
+ * for every process in the runner's own session (the setsid tree — the
66
+ * CLI, its foreground tool, their children). Comma-separated so the
67
+ * probe can carry it as ONE whitespace-delimited field. Exported for
68
+ * tests. */
69
+ export declare function toolPulseFragment(pulsePath: string): string;
70
+ /** One tool-run pulse sample, parsed off the probe's trailing field. */
71
+ export interface TurnToolPulse {
72
+ /** Guest epoch ms when the sample was written. */
73
+ atMs: number;
74
+ /** Aggregate utime+stime jiffies across the runner's session. */
75
+ cpuJiffies: number;
76
+ /** Aggregate written bytes (wchar) across the runner's session. */
77
+ ioBytes: number;
78
+ /** Live processes in the session. */
79
+ procs: number;
80
+ }
81
+ /** Parse the pulse token (`at,cpu,io,procs`). Null on anything malformed —
82
+ * evidence-absent, never an error. Exported for tests. */
83
+ export declare function parseToolPulseToken(token: string): TurnToolPulse | null;
84
+ /** Bound on the pulse token read (4 numeric fields + commas). */
85
+ export declare const TOOL_PULSE_TOKEN_MAX_CHARS = 96;
63
86
  /** Watchdog cadence while a tail stream is attached. Each tick is one fresh
64
87
  * short exec; a healthy stream makes every tick a no-op. */
65
88
  export declare const TAIL_WATCHDOG_INTERVAL_MS = 15000;
@@ -75,6 +98,33 @@ export declare const TAIL_ABANDON_AFTER_STREAM_DEATHS = 3;
75
98
  * (envd HTTP, ~65ms RTT), consumed from the byte offset. Latency-tuned:
76
99
  * this is the degraded path, correctness never depends on it being fast. */
77
100
  export declare const DURABLE_POLL_INTERVAL_MS = 1000;
101
+ /** Consecutive provider-attested "sandbox gone" probe failures ⇒ dead. */
102
+ export declare const PROBE_DEATH_GONE_STREAK = 3;
103
+ /** Not-found evidence must also persist this long (guards a momentary
104
+ * control-plane 404 blip from killing a live turn). */
105
+ export declare const PROBE_DEATH_GONE_WINDOW_MS = 15000;
106
+ /** Consecutive GENERIC probe-transport failures (timeouts, connection
107
+ * faults) ⇒ dead — only together with the window below. */
108
+ export declare const PROBE_DEATH_FAIL_STREAK = 20;
109
+ /** …and the failure run must span at least this long with zero durable
110
+ * evidence of any kind. */
111
+ export declare const PROBE_DEATH_FAIL_WINDOW_MS = 120000;
112
+ /** Provider evidence that the SANDBOX itself is gone — E2B's
113
+ * SandboxNotFoundError / NotFoundError classes (matched by name so no
114
+ * provider import rides in the runtime layer), or their messages after any
115
+ * wrapping ("Paused sandbox X not found" was run 3's exact shape). */
116
+ export declare function isSandboxGoneError(err: unknown): boolean;
117
+ /** One probe-failure run's bookkeeping (reset to zeros on ANY evidence). */
118
+ export interface ProbeDeathState {
119
+ /** Consecutive probe execs that THREW (no verdict at all). */
120
+ failStreak: number;
121
+ /** Consecutive throws that were provider "sandbox gone" evidence. */
122
+ goneStreak: number;
123
+ /** Wall-clock start of the current failure run (0 = no run). */
124
+ firstFailAtMs: number;
125
+ }
126
+ /** The death-door decision, pure for tests. Null = keep polling. */
127
+ export declare function probeDeathVerdict(s: ProbeDeathState, nowMs: number): "dead-gone" | "dead-silent" | null;
78
128
  /** The claude CLI's stderr complaint when `--resume <id>` names a thread
79
129
  * that does not exist on this machine (the 2026-08-18 split-brain
80
130
  * forensic). When a nonzero exit's stderr carries it, the transport
@@ -99,6 +149,10 @@ export interface TurnProbeReading {
99
149
  * sample yet, or a garbled token — evidence-absent, never an error.
100
150
  * Telemetry-only: no liveness verdict may ever read it. */
101
151
  perf?: GuestPerfSample;
152
+ /** Latest tool-run pulse (the `.pulse` token field, 2026-08-29), when the
153
+ * guest wrote one AND it parsed clean. Telemetry-only, same rule as
154
+ * `perf`: no liveness verdict may ever read it. */
155
+ pulse?: TurnToolPulse;
102
156
  }
103
157
  /** The probe exec: one line, six fields, always exit 0 — faults surface as
104
158
  * parse failures, not exec failures. Reads the guest's own clock in the
@@ -112,6 +166,7 @@ export declare function turnLivenessProbeCommand(paths: {
112
166
  perfPath: string;
113
167
  pid: number;
114
168
  sentinel: string;
169
+ pulsePath?: string;
115
170
  }): string;
116
171
  /** Parse the probe's line. Null = unusable output (a wedged or faulted exec)
117
172
  * — the caller treats that as "probe-failed", never as a verdict. The
@@ -467,6 +522,16 @@ export interface CliAgentSpec {
467
522
  /** Serialise one mid-turn user message into ONE stdin line. No
468
523
  * trailing newline. */
469
524
  messageLine(text: string): string;
525
+ /** Serialise ONE in-band interrupt control line (claude: a stream-json
526
+ * `control_request` with subtype "interrupt") — the ESC equivalent.
527
+ * The CLI's control layer handles these immediately, MID-STEP
528
+ * included: the running tool call aborts (its tool_result records the
529
+ * harness's own rejection text), the run ends with an
530
+ * `error_during_execution` result within ~100ms, and the session file
531
+ * stays `--resume`-able with the whole turn context. Verified live
532
+ * against claude 2.1.236. Absent → the runtime has no in-band
533
+ * interrupt; callers fall back to kill semantics. */
534
+ interruptLine?(requestId: string): string;
470
535
  };
471
536
  }
472
537
  export declare class CliAgentRunner implements ModelExecutionContract {
@@ -527,6 +592,22 @@ export declare class CliAgentRunner implements ModelExecutionContract {
527
592
  * answers "unsupported" and the caller leaves the message owed. `chain`
528
593
  * serializes appends so each delivery targets a deterministic line count. */
529
594
  private turnInject;
595
+ /** The CURRENT turn's detached-runner wrapper pid (the setsid group
596
+ * leader echoed by the launch / recovered from the durable pidfile) —
597
+ * durable-transport turns only. Null between turns and on transports
598
+ * without a detached guest. See the contract doc (types/runtime.ts). */
599
+ private turnPid;
600
+ /** Advisory guest-pid identity for the live turn's runner tree — see the
601
+ * contract doc (types/runtime.ts). Never a liveness verdict. */
602
+ currentRunnerPid(): number | null;
603
+ /** Safe-to-persist durable byte offset — end of the last line whose
604
+ * messages have ALL been yielded (boot-time turn adoption; contract in
605
+ * types/runtime.ts). One line behind the parse cursor by design. */
606
+ private turnConsumedOffset;
607
+ /** End offset of the line currently being yielded from — promoted to
608
+ * `turnConsumedOffset` when the NEXT line is pulled (or at stream end). */
609
+ private turnPendingLineEnd;
610
+ currentTurnDurableOffset(): number | null;
530
611
  /** Deliver one user message INTO the live turn — see the contract doc
531
612
  * (types/runtime.ts). Appends a stream-input line to the turn's durable
532
613
  * inbox and waits for the in-guest feeder's delivered-counter ack; only
@@ -536,6 +617,31 @@ export declare class CliAgentRunner implements ModelExecutionContract {
536
617
  * the appended line may still be read when the current step finishes,
537
618
  * but it was NOT seen yet. Never throws. */
538
619
  injectUserMessage(text: string): Promise<"delivered" | "pending" | "closed" | "unsupported">;
620
+ /** Request an in-band step interrupt of the LIVE turn — the ESC
621
+ * equivalent; see the contract doc (types/runtime.ts). Appends the
622
+ * spec's interrupt control line to the turn's durable inbox; the guest
623
+ * feeder forwards it into the CLI's stdin, whose control layer handles
624
+ * it immediately — MID-STEP included, unlike queued user messages (the
625
+ * inject "pending" wall applies to turn-loop consumption, not the
626
+ * control layer). Only "delivered" means the control line reached the
627
+ * CLI's stdin; callers escalate anything else to kill semantics. Never
628
+ * throws. */
629
+ interruptTurn(): Promise<"delivered" | "pending" | "closed" | "unsupported">;
630
+ /** The one durable append+ack path both mid-turn producers share
631
+ * (`injectUserMessage`'s enveloped message line, `interruptTurn`'s raw
632
+ * control line). Serialized on the inject chain so every append targets
633
+ * a deterministic inbox line count. */
634
+ private appendTurnStreamLine;
635
+ /** The most recent probe reading's tool-run pulse (2026-08-29), plus the
636
+ * guest clock it was read against — telemetry only, refreshed by each
637
+ * `probeTurnLiveness` call. Null between turns / before any probe. */
638
+ private lastTurnPulse;
639
+ /** Peek the newest tool-run pulse the durable probe carried — the
640
+ * executor's evidence ticker reads it AFTER its liveness check to fan
641
+ * the tool-progress fact to clients. Never probes on its own. */
642
+ peekTurnPulse(): (TurnToolPulse & {
643
+ guestNowMs: number;
644
+ }) | null;
539
645
  /** Durable three-valued liveness for the current turn — see the contract
540
646
  * doc (types/runtime.ts). Never throws; never blocks past the probe's
541
647
  * explicit exec timeout. */
@@ -33,7 +33,7 @@
33
33
  * sessions this is the gateway-minted session virtual key pointed at the
34
34
  * token-metering gateway's Anthropic passthrough (ADR-0039).
35
35
  */
36
- import type { AgentMessageTaskNotification } from "../index.js";
36
+ import type { AgentMessage, AgentMessageCompaction, AgentMessageTaskNotification, AgentMessageTaskProgress } from "../index.js";
37
37
  import { type CliAgentSpec, type CliReasoningEffort } from "./_cli-agent.js";
38
38
  /** Pinned Claude Code ACP adapter (Zed's npm shim — `claude` has no native
39
39
  * ACP mode). Pinned EXACT, not a range: the adapter's README warns of
@@ -46,12 +46,42 @@ export declare const CLAUDE_CODE_ACP_ADAPTER = "@zed-industries/claude-code-acp@
46
46
  * is skipped, absent fields stay absent, everything is clamped. Exported
47
47
  * for tests. */
48
48
  export declare function parseTaskNotifications(text: string, timestamp: string): AgentMessageTaskNotification[];
49
+ /** One user-role TEXT blob from the stream, mapped with sidechain awareness.
50
+ * Task-notification blocks parse into structure wherever they appear (their
51
+ * arrival side is resume-dependent — see the transport notes above). What
52
+ * remains is then split by attribution: TOP-LEVEL text (no parent id) stays
53
+ * unmapped exactly as before — prompt echoes and system reminders are not
54
+ * agent output. SIDECHAIN text (parent id present) is a message landing in
55
+ * a child subagent's thread — a delivered SendMessage steer — and forwards
56
+ * as `subagent_user_message`, except harness plumbing (`<system-reminder>`
57
+ * wrappers the CLI injects into child threads), which no renderer should
58
+ * see. Exported for tests. */
59
+ export declare function sidechainAwareUserText(text: string, parentToolUseId: string | undefined, timestamp: string): AgentMessage[];
49
60
  /** One `system`/`task_notification` stream-json event mapped onto the same
50
61
  * structured message the XML parse produces, or null when the event names
51
62
  * no task id. Pure and tolerant over untrusted harness JSON: absent fields
52
63
  * stay absent, everything is clamped; `output_file` (internal plumbing) is
53
64
  * deliberately not forwarded. Exported for tests. */
54
65
  export declare function parseSystemTaskNotification(p: Record<string, unknown>, timestamp: string): AgentMessageTaskNotification | null;
66
+ /** One `system`/`task_progress` event mapped onto the structured progress
67
+ * message, or null only when it names no task. Workflow tasks carry the
68
+ * cumulative `workflow_progress` entries; a plain background Agent-task
69
+ * heartbeat (no workflow entries — verified live on 2.1.241, ~10s cadence
70
+ * while the task runs) forwards with `workflow: []` so the platform can
71
+ * DECLARE the running task as session background work (the delegation-
72
+ * survives-the-human contract: parks, user interrupts, and supersedes all
73
+ * read the declared-children registry). Completion evidence still rides
74
+ * `task_notification`. Pure and tolerant over untrusted harness JSON:
75
+ * malformed entries are skipped, everything is clamped (phases keep the
76
+ * FIRST 32 — they are seeded up front; agents keep the LAST 128 — late
77
+ * spawns matter more than a long-settled prefix). Exported for tests. */
78
+ export declare function parseSystemTaskProgress(p: Record<string, unknown>, timestamp: string): AgentMessageTaskProgress | null;
79
+ /** One `system` event of the compaction family mapped onto the structured
80
+ * lifecycle message, or null when the event is not compaction-shaped (a
81
+ * plain `status` event with neither the compacting status nor a
82
+ * compact_result stays unmapped). Pure and tolerant over untrusted harness
83
+ * JSON. Exported for tests. */
84
+ export declare function parseSystemCompaction(p: Record<string, unknown>, timestamp: string): AgentMessageCompaction | null;
55
85
  /** Claude Code's real reasoning knob is its own `--effort <level>` flag
56
86
  * (low|medium|high|xhigh|max — verified against `claude -p --help`). The
57
87
  * CliReasoningEffort union IS the CLI's vocabulary, so the level rides the
@@ -3,11 +3,35 @@
3
3
  *
4
4
  * Works against DesktopSandboxProvider — no E2B SDK dependency here.
5
5
  * The action→screenshot loop runs until the model emits text, then yields it.
6
+ *
7
+ * COORDINATE SPACES (incident note). Every screenshot is downscaled to the
8
+ * model's DISPLAY geometry (1024×720) before it is sent, so the model emits
9
+ * coordinates in the SCALED screenshot's space — never the real desktop's.
10
+ * An earlier revision executed those coordinates against the real desktop
11
+ * using hardcoded real-geometry constants, so on any sandbox whose actual
12
+ * geometry differed, every click landed in the wrong place. The provider has
13
+ * no geometry call, so the real geometry is read from each screenshot buffer
14
+ * itself (sharp metadata), and the resulting per-capture `CaptureScale` maps
15
+ * the model's coordinates back onto the exact frame it saw. The old constants
16
+ * survive ONLY as a fallback for the metadata-missing case.
6
17
  */
7
18
  import type { DesktopSandboxProvider, AgentMessage, ModelExecutionContract, RuntimeOptions } from "../index.js";
8
19
  export interface OpenAIDesktopRunnerOptions extends RuntimeOptions {
9
20
  openaiKey: string;
10
21
  }
22
+ /** One model-emitted desktop action. Coordinates arrive in DISPLAY (model)
23
+ * space and are rescaled through the CURRENT capture's `CaptureScale`
24
+ * before dispatch. Exported so tests can type their fixtures. */
25
+ export interface ComputerAction {
26
+ type: string;
27
+ coordinate?: [number, number];
28
+ startCoordinate?: [number, number];
29
+ endCoordinate?: [number, number];
30
+ text?: string;
31
+ key?: string;
32
+ direction?: string;
33
+ ticks?: number;
34
+ }
11
35
  export declare class OpenAIDesktopRunner implements ModelExecutionContract {
12
36
  private sandbox;
13
37
  readonly kind = "openai-desktop";
@@ -20,5 +44,31 @@ export declare class OpenAIDesktopRunner implements ModelExecutionContract {
20
44
  sessionId?: string;
21
45
  }): AsyncGenerator<AgentMessage>;
22
46
  }
47
+ /** Real-desktop pixels per model-DISPLAY pixel, derived from ONE capture.
48
+ * Coordinates the model emits against that capture are multiplied by these
49
+ * factors (and rounded) before touching the provider. */
50
+ export interface CaptureScale {
51
+ scaleX: number;
52
+ scaleY: number;
53
+ }
54
+ /** One captured frame: the model-facing image plus the scale that maps the
55
+ * model's coordinates back onto this frame's real desktop. */
56
+ export interface ScaledCapture {
57
+ /** Base64 PNG resized to DISPLAY_WIDTH×DISPLAY_HEIGHT (fit "fill"). */
58
+ b64: string;
59
+ scale: CaptureScale;
60
+ }
61
+ /** Derive a capture's scale from its real pixel dimensions. The constants
62
+ * are a FALLBACK only — used when sharp cannot read the frame's metadata;
63
+ * a real dimension always wins. */
64
+ export declare function scaleFromDimensions(width: number | undefined, height: number | undefined): CaptureScale;
65
+ /** Capture one frame: read the REAL geometry from the raw screenshot's own
66
+ * metadata, downscale to the model's DISPLAY geometry, and return both the
67
+ * image and the scale that maps model coordinates back onto this frame. */
68
+ export declare function captureScaledScreenshot(sandbox: DesktopSandboxProvider): Promise<ScaledCapture>;
69
+ /** Dispatch one model action against the provider, mapping every coordinate
70
+ * through the CURRENT capture's scale. Non-coordinate payloads — scroll
71
+ * deltas (ticks), typed text, key chords — pass through untouched. */
72
+ export declare function executeAction(sandbox: DesktopSandboxProvider, action: ComputerAction, scale: CaptureScale): Promise<void>;
23
73
  declare const _default: import("../index.js").AgentRuntime<DesktopSandboxProvider>;
24
74
  export default _default;