@ai-sdk/harness 0.0.0 → 1.0.0-canary.3

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 (68) hide show
  1. package/CHANGELOG.md +24 -0
  2. package/LICENSE +13 -0
  3. package/README.md +142 -0
  4. package/agent/index.ts +17 -0
  5. package/bridge/index.ts +10 -0
  6. package/dist/agent/index.d.ts +1480 -0
  7. package/dist/agent/index.js +2554 -0
  8. package/dist/agent/index.js.map +1 -0
  9. package/dist/bridge/index.d.ts +111 -0
  10. package/dist/bridge/index.js +414 -0
  11. package/dist/bridge/index.js.map +1 -0
  12. package/dist/index.d.ts +1510 -0
  13. package/dist/index.js +15834 -0
  14. package/dist/index.js.map +1 -0
  15. package/dist/observability/index.d.ts +97 -0
  16. package/dist/observability/index.js +225 -0
  17. package/dist/observability/index.js.map +1 -0
  18. package/dist/utils/index.d.ts +196 -0
  19. package/dist/utils/index.js +327 -0
  20. package/dist/utils/index.js.map +1 -0
  21. package/package.json +104 -1
  22. package/src/agent/harness-agent-session.ts +352 -0
  23. package/src/agent/harness-agent-settings.ts +131 -0
  24. package/src/agent/harness-agent-tool-approval-continuation.ts +94 -0
  25. package/src/agent/harness-agent.ts +750 -0
  26. package/src/agent/harness-diagnostics.ts +88 -0
  27. package/src/agent/internal/bootstrap-recipe.ts +124 -0
  28. package/src/agent/internal/bridge-port-registry.ts +52 -0
  29. package/src/agent/internal/harness-stream-text-result.ts +720 -0
  30. package/src/agent/internal/permission-mode.ts +50 -0
  31. package/src/agent/internal/resolve-observability.ts +128 -0
  32. package/src/agent/internal/resume-state-validation.ts +51 -0
  33. package/src/agent/internal/run-prompt.ts +811 -0
  34. package/src/agent/internal/strip-work-dir.ts +68 -0
  35. package/src/agent/internal/to-harness-stream.ts +75 -0
  36. package/src/agent/internal/translate-stream-part.ts +221 -0
  37. package/src/agent/internal/turn-telemetry.ts +359 -0
  38. package/src/agent/prewarm.ts +46 -0
  39. package/src/bridge/index.ts +700 -0
  40. package/src/errors/harness-capability-unsupported-error.ts +41 -0
  41. package/src/errors/harness-error.ts +22 -0
  42. package/src/index.ts +3 -0
  43. package/src/observability/file-reporter.ts +209 -0
  44. package/src/observability/index.ts +13 -0
  45. package/src/observability/trace-tree-reporter.ts +122 -0
  46. package/src/utils/classify-disk-log.ts +43 -0
  47. package/src/utils/index.ts +7 -0
  48. package/src/utils/sandbox-channel.ts +453 -0
  49. package/src/v1/harness-v1-bootstrap.ts +46 -0
  50. package/src/v1/harness-v1-bridge-protocol.ts +310 -0
  51. package/src/v1/harness-v1-builtin-tool.ts +138 -0
  52. package/src/v1/harness-v1-call-warning.ts +22 -0
  53. package/src/v1/harness-v1-diagnostic.ts +66 -0
  54. package/src/v1/harness-v1-metadata.ts +13 -0
  55. package/src/v1/harness-v1-network-sandbox-session.ts +123 -0
  56. package/src/v1/harness-v1-observability.ts +20 -0
  57. package/src/v1/harness-v1-permission-mode.ts +11 -0
  58. package/src/v1/harness-v1-prompt-control.ts +41 -0
  59. package/src/v1/harness-v1-prompt.ts +11 -0
  60. package/src/v1/harness-v1-resume-state.ts +46 -0
  61. package/src/v1/harness-v1-sandbox-provider.ts +76 -0
  62. package/src/v1/harness-v1-session.ts +268 -0
  63. package/src/v1/harness-v1-skill.ts +22 -0
  64. package/src/v1/harness-v1-stream-part.ts +363 -0
  65. package/src/v1/harness-v1-tool-spec.ts +31 -0
  66. package/src/v1/harness-v1.ts +83 -0
  67. package/src/v1/index.ts +93 -0
  68. package/utils/index.ts +1 -0
@@ -0,0 +1,1510 @@
1
+ import * as _ai_sdk_provider_utils from '@ai-sdk/provider-utils';
2
+ import { Experimental_SandboxSession, UserModelMessage, ToolSet, FlexibleSchema, Tool } from '@ai-sdk/provider-utils';
3
+ import { z } from 'zod/v4';
4
+ import * as _ai_sdk_provider from '@ai-sdk/provider';
5
+ import { JSONValue, LanguageModelV4ToolCall, LanguageModelV4ToolApprovalRequest, LanguageModelV4ToolResult, LanguageModelV4FinishReason, LanguageModelV4Usage, SharedV4ProviderMetadata, JSONSchema7, AISDKError } from '@ai-sdk/provider';
6
+
7
+ /**
8
+ * One file to write into the sandbox as part of an adapter's bootstrap recipe.
9
+ * Paths should live under {@link HarnessV1Bootstrap.bootstrapDir}.
10
+ */
11
+ interface HarnessV1BootstrapFile {
12
+ readonly path: string;
13
+ readonly content: string;
14
+ }
15
+ /**
16
+ * One command to run in the sandbox as part of an adapter's bootstrap recipe.
17
+ * Commands run sequentially after all files have been written; a non-zero exit
18
+ * aborts the bootstrap.
19
+ */
20
+ interface HarnessV1BootstrapCommand {
21
+ readonly command: string;
22
+ readonly workingDirectory?: string;
23
+ }
24
+ /**
25
+ * Adapter-owned bootstrap recipe. The adapter declares the files and commands
26
+ * needed to set up its bridge inside any sandbox. The harness framework hashes
27
+ * the recipe into an identity used by sandbox providers for snapshot-based
28
+ * reuse, and applies the recipe idempotently before the bridge spawns.
29
+ */
30
+ interface HarnessV1Bootstrap {
31
+ /**
32
+ * Stable id of the adapter that owns this recipe. Conventionally matches
33
+ * {@link HarnessV1.harnessId}. Contributes to the recipe hash.
34
+ */
35
+ readonly harnessId: string;
36
+ /**
37
+ * Absolute path inside the sandbox where this recipe writes its state.
38
+ * The marker file lives directly under it. Files declared in {@link files}
39
+ * should also use this prefix so an adapter upgrade can sweep stale state
40
+ * by clearing the directory.
41
+ */
42
+ readonly bootstrapDir: string;
43
+ /** Files to write into the sandbox before any command runs. */
44
+ readonly files: ReadonlyArray<HarnessV1BootstrapFile>;
45
+ /** Commands to run after files are written, in order. */
46
+ readonly commands: ReadonlyArray<HarnessV1BootstrapCommand>;
47
+ }
48
+
49
+ /**
50
+ * Network sandbox session returned by `HarnessV1SandboxProvider.createSession()`. The
51
+ * harness keeps this for the lifetime of a session. It is itself a
52
+ * {@link SandboxSession} (file I/O, exec, spawn) and adds the infra surface on
53
+ * top: port resolution, lifecycle, and network-policy mutation.
54
+ *
55
+ * Code that should only touch the filesystem and spawn processes receives the
56
+ * reduced view from {@link HarnessV1NetworkSandboxSession.restricted}, never the
57
+ * network sandbox session itself — so it cannot stop the sandbox or change its
58
+ * network policy.
59
+ */
60
+ interface HarnessV1NetworkSandboxSession extends Experimental_SandboxSession {
61
+ /**
62
+ * Stable identifier for the underlying sandbox resource. Used by the
63
+ * harness session manager as the durable lookup key for cross-process
64
+ * resume — the framework persists this on the resume payload so a future
65
+ * process can call `HarnessV1SandboxProvider.resume?({ sessionId })` and
66
+ * reach the same resource. Providers populate it from their native
67
+ * identifier (Vercel: the sandbox name; just-bash: a UUID minted at
68
+ * create time).
69
+ */
70
+ readonly id: string;
71
+ /**
72
+ * The sandbox's default working directory — the absolute path that
73
+ * `run`/`spawn` resolve relative commands against when no `workingDirectory`
74
+ * is given. Read from the live sandbox (it is provider-specific and
75
+ * configurable at create time: Vercel defaults to `/vercel/sandbox`,
76
+ * just-bash to `/home/user`), never hardcoded.
77
+ *
78
+ * The framework composes each session's working directory underneath this
79
+ * path (`<defaultWorkingDirectory>/<harnessId>-<sessionId>`) so adapters do
80
+ * not bake a provider-specific base into their own paths.
81
+ */
82
+ readonly defaultWorkingDirectory: string;
83
+ /** Ports the sandbox exposes; resolvable to public URLs via `getPortUrl`. */
84
+ readonly ports: ReadonlyArray<number>;
85
+ /**
86
+ * Resolve a publicly-reachable URL for a sandbox-exposed port. Bridge-backed
87
+ * adapters call this to open their WebSocket to the in-sandbox bridge.
88
+ */
89
+ readonly getPortUrl: (options: {
90
+ port: number;
91
+ protocol?: 'http' | 'https' | 'ws';
92
+ }) => PromiseLike<string>;
93
+ /** Stop the sandbox. Idempotent. */
94
+ readonly stop: () => PromiseLike<void>;
95
+ /**
96
+ * Destroy/delete the sandbox resource when supported. Optional because some
97
+ * providers only have a stop/dispose concept. Implementations must handle
98
+ * both a still-running sandbox and a previously stopped sandbox.
99
+ */
100
+ readonly destroy?: () => PromiseLike<void>;
101
+ /**
102
+ * Update the sandbox's outbound network policy. Optional — implementations
103
+ * without a local enforcement primitive (e.g. just-bash) omit this. Callers
104
+ * use optional-call (`sandboxSession.setNetworkPolicy?.(policy)`); a
105
+ * missing implementation is a no-op.
106
+ */
107
+ readonly setNetworkPolicy?: (policy: HarnessV1NetworkPolicy) => PromiseLike<void>;
108
+ /**
109
+ * Replace the set of ports exposed by the sandbox. Full-replacement
110
+ * semantics: ports omitted from the array are deregistered. Optional —
111
+ * implementations that cannot expose ports (e.g. just-bash) omit this.
112
+ */
113
+ readonly setPorts?: (ports: ReadonlyArray<number>, options?: {
114
+ abortSignal?: AbortSignal;
115
+ }) => PromiseLike<void>;
116
+ /**
117
+ * Reduced view of this session, typed as the bare {@link SandboxSession}
118
+ * (file I/O, exec, spawn) — nothing that could stop the sandbox or change
119
+ * its network policy. Pass this to user-tool `execute()` calls and other
120
+ * code that must not reach the infra surface.
121
+ *
122
+ * The returned object points at exactly the same underlying sandbox
123
+ * resource as the network sandbox session it was produced from; it is only a
124
+ * narrower surface over the same resource, not a separate sandbox.
125
+ */
126
+ readonly restricted: () => Experimental_SandboxSession;
127
+ }
128
+ /**
129
+ * Outbound network policy applied by the sandbox runtime.
130
+ *
131
+ * `'allow-all'` and `'deny-all'` are convenience presets. `'custom'` is an
132
+ * allow-list with an optional CIDR deny-list that takes precedence:
133
+ *
134
+ * - Reachable hosts are the union of `allowedHosts` and `allowedCIDRs`.
135
+ * - `deniedCIDRs` wins over both, useful for blocking cloud-metadata IPs while
136
+ * otherwise allowing broad access.
137
+ *
138
+ * The two `'custom'` branches share the same discriminator but each requires
139
+ * a different allow field. Specifying `'custom'` with only `deniedCIDRs`
140
+ * (deny-only) is rejected at compile time — functionally it would be
141
+ * equivalent to `'deny-all'`.
142
+ */
143
+ type HarnessV1NetworkPolicy = {
144
+ mode: 'allow-all';
145
+ } | {
146
+ mode: 'deny-all';
147
+ } | {
148
+ mode: 'custom';
149
+ allowedHosts: ReadonlyArray<string>;
150
+ allowedCIDRs?: ReadonlyArray<string>;
151
+ deniedCIDRs?: ReadonlyArray<string>;
152
+ } | {
153
+ mode: 'custom';
154
+ allowedHosts?: ReadonlyArray<string>;
155
+ allowedCIDRs: ReadonlyArray<string>;
156
+ deniedCIDRs?: ReadonlyArray<string>;
157
+ };
158
+
159
+ /** Severity of a diagnostic, ordered most → least severe. */
160
+ declare const harnessV1DebugLevelSchema: z.ZodEnum<{
161
+ error: "error";
162
+ warn: "warn";
163
+ info: "info";
164
+ debug: "debug";
165
+ trace: "trace";
166
+ }>;
167
+ type HarnessV1DebugLevel = z.infer<typeof harnessV1DebugLevelSchema>;
168
+ /**
169
+ * Per-session diagnostics configuration the framework hands an adapter (and the
170
+ * host sends on `start.debug`). When absent or `enabled` is false the adapter
171
+ * captures and emits nothing. `subsystems` filters structured events by dotted
172
+ * prefix; console capture is independent of the subsystem filter.
173
+ */
174
+ declare const harnessV1DebugConfigSchema: z.ZodObject<{
175
+ enabled: z.ZodOptional<z.ZodBoolean>;
176
+ level: z.ZodOptional<z.ZodEnum<{
177
+ error: "error";
178
+ warn: "warn";
179
+ info: "info";
180
+ debug: "debug";
181
+ trace: "trace";
182
+ }>>;
183
+ subsystems: z.ZodOptional<z.ZodArray<z.ZodString>>;
184
+ }, z.core.$strip>;
185
+ type HarnessV1DebugConfig = z.infer<typeof harnessV1DebugConfigSchema>;
186
+ /**
187
+ * A diagnostic as emitted by a harness adapter. Structurally identical to the
188
+ * host-facing `HarnessDiagnostic` today, but kept separate: this is the spec's
189
+ * emission shape, that is the external consumption shape.
190
+ */
191
+ type HarnessV1Diagnostic = {
192
+ /** Severity. */
193
+ readonly level: HarnessV1DebugLevel;
194
+ /** Human-readable line (console capture) or message (structured event). */
195
+ readonly message: string;
196
+ /** Dotted subsystem (`sandbox.log.<source>` for console capture). */
197
+ readonly subsystem: string;
198
+ /** `'log'` = captured console line; `'event'` = structured emission. */
199
+ readonly kind: 'log' | 'event';
200
+ /** Originating source label (console capture). */
201
+ readonly source?: string;
202
+ /** Which standard stream the line came from (console capture). */
203
+ readonly stream?: 'stdout' | 'stderr';
204
+ /** Structured attributes (structured events only). */
205
+ readonly attrs?: Record<string, unknown>;
206
+ /** Error payload (structured events only). */
207
+ readonly error?: {
208
+ name?: string;
209
+ message: string;
210
+ stack?: string;
211
+ };
212
+ /** The harness session this diagnostic originated from. */
213
+ readonly sessionId?: string;
214
+ /** Emission time (epoch ms). */
215
+ readonly timestamp: number;
216
+ };
217
+
218
+ /**
219
+ * Diagnostics wiring the framework hands to an adapter's `doStart`. `report` is
220
+ * the general emission sink: a bridge adapter normalizes each wire frame into a
221
+ * `HarnessV1Diagnostic` (via `harnessV1DiagnosticFromBridgeFrame`) and calls it;
222
+ * a non-bridge adapter constructs a `HarnessV1Diagnostic` from its host-side
223
+ * logs/errors and calls it directly. `debug` gates what the adapter emits.
224
+ * Absent when the consumer has not enabled diagnostics.
225
+ */
226
+ type HarnessV1Observability = {
227
+ /** Per-session debug config gating what the adapter captures/emits. */
228
+ readonly debug?: HarnessV1DebugConfig;
229
+ /** General emission sink — any adapter reports a `HarnessV1Diagnostic` here. */
230
+ readonly report?: (diagnostic: HarnessV1Diagnostic) => void;
231
+ };
232
+
233
+ /**
234
+ * Baseline permission mode for adapter-native built-in tools.
235
+ *
236
+ * Custom host-executed tools are not controlled by this setting. They use
237
+ * `HarnessAgentSettings.toolApproval`, similar to AI SDK's per-tool approval
238
+ * status map.
239
+ */
240
+ type HarnessV1PermissionMode = 'allow-reads' | 'allow-edits' | 'allow-all';
241
+
242
+ /**
243
+ * Prompt shape passed to `HarnessV1Session.doPromptTurn`.
244
+ *
245
+ * A harness session represents an ongoing third-party agent runtime that
246
+ * owns its own conversation history. Each prompt turn carries only the
247
+ * fresh user input for that turn, either as a plain string or as a single
248
+ * `UserModelMessage`.
249
+ */
250
+ type HarnessV1Prompt = string | UserModelMessage;
251
+
252
+ /**
253
+ * Bidirectional control surface returned by `doPromptTurn`.
254
+ *
255
+ * The host uses these methods to feed asynchronous responses back to the
256
+ * adapter while a turn is running. All methods are optional except those
257
+ * the adapter actively supports (host-executed tools require
258
+ * `submitToolResult`; approvals require `submitToolApproval`; mid-turn
259
+ * messages require `submitUserMessage`).
260
+ */
261
+ type HarnessV1PromptControl = {
262
+ /**
263
+ * Provide a result for a `tool-call` the adapter emitted. The adapter
264
+ * forwards the result to the underlying runtime so the model can continue.
265
+ */
266
+ submitToolResult(input: {
267
+ toolCallId: string;
268
+ output: unknown;
269
+ isError?: boolean;
270
+ }): PromiseLike<void>;
271
+ /**
272
+ * Respond to a `tool-approval-request` the adapter emitted.
273
+ */
274
+ submitToolApproval?(input: {
275
+ approvalId: string;
276
+ approved: boolean;
277
+ reason?: string;
278
+ }): PromiseLike<void>;
279
+ /**
280
+ * Inject a fresh user message into a turn that is still in flight.
281
+ * Supported only by runtimes that accept interactive input.
282
+ */
283
+ submitUserMessage?(text: string): PromiseLike<void>;
284
+ /**
285
+ * Resolves when the adapter has finished the turn (success or failure).
286
+ * Rejects with the underlying error when the turn fails.
287
+ */
288
+ readonly done: PromiseLike<void>;
289
+ };
290
+
291
+ type HarnessV1PendingToolApproval = {
292
+ readonly approvalId: string;
293
+ readonly toolCallId: string;
294
+ readonly toolName: string;
295
+ readonly input: string;
296
+ readonly kind: 'builtin' | 'custom';
297
+ readonly providerExecuted?: boolean;
298
+ readonly nativeName?: string;
299
+ };
300
+ /**
301
+ * Opaque payload returned by resumable session lifecycle methods and accepted
302
+ * by a future `HarnessV1.doStart({ resumeFrom })` to resume the same
303
+ * underlying session.
304
+ *
305
+ * The contents are entirely adapter-defined. Consumers (including
306
+ * `HarnessAgent`) treat the value as opaque; adapters describe and validate
307
+ * their own schemas via `HarnessV1.resumeStateSchema`.
308
+ */
309
+ type HarnessV1ResumeState = {
310
+ /**
311
+ * Identifier of the harness that produced this state. Used by adapters to
312
+ * refuse mismatched resume payloads.
313
+ */
314
+ readonly harnessId: string;
315
+ /**
316
+ * Spec version of the harness that produced this state.
317
+ */
318
+ readonly specificationVersion: 'harness-v1';
319
+ /**
320
+ * Adapter-defined payload. May be persisted as JSON; the adapter is
321
+ * responsible for any necessary encoding.
322
+ */
323
+ readonly data: JSONValue;
324
+ /**
325
+ * Framework-owned pending approval records. These are intentionally outside
326
+ * adapter-defined `data` so callers can persist the entire resume payload
327
+ * without the harness framework owning storage.
328
+ */
329
+ readonly pendingToolApprovals?: readonly HarnessV1PendingToolApproval[];
330
+ };
331
+
332
+ /**
333
+ * A self-contained instruction bundle the underlying runtime can load into
334
+ * its context. Adapters decide how to surface skills to the runtime — the
335
+ * `claude` CLI auto-discovers skills materialised as Markdown files in
336
+ * `.claude/skills`, while the `codex` CLI has no skill mechanism and the
337
+ * adapter inlines them into every user message.
338
+ */
339
+ type HarnessV1Skill = {
340
+ /** Stable identifier for the skill (kebab-case slug). */
341
+ readonly name: string;
342
+ /**
343
+ * Short, model-facing description. For runtimes that auto-select skills
344
+ * (Claude Code), this is what the runtime sees to decide whether the
345
+ * skill is relevant; for runtimes that load every skill on every turn
346
+ * (Codex), it appears alongside the content.
347
+ */
348
+ readonly description: string;
349
+ /** Full skill content the model loads when the skill is active. */
350
+ readonly content: string;
351
+ };
352
+
353
+ /**
354
+ * Warning emitted by a harness adapter during a call.
355
+ *
356
+ * Surfaces non-fatal issues such as unsupported options or quirks of the
357
+ * underlying agent runtime. Mirrors the shape of `SharedV4Warning` but lives
358
+ * in the harness namespace.
359
+ */
360
+ type HarnessV1CallWarning = {
361
+ type: 'unsupported-setting';
362
+ setting: string;
363
+ details?: string;
364
+ } | {
365
+ type: 'unsupported-tool';
366
+ tool: string;
367
+ details?: string;
368
+ } | {
369
+ type: 'other';
370
+ message: string;
371
+ };
372
+
373
+ /**
374
+ * Adapter-namespaced opaque data attached to harness events.
375
+ *
376
+ * Mirrors the `providerMetadata` pattern from `@ai-sdk/provider`, but lives
377
+ * in the harness namespace because a harness is a peer concept to a
378
+ * provider, not a kind of provider.
379
+ *
380
+ * Keys are harness ids (e.g. `'claude-code'`). Inner values are arbitrary
381
+ * JSON-serializable data the adapter chooses to surface to callers.
382
+ */
383
+ type HarnessV1Metadata = Record<string, Record<string, JSONValue>>;
384
+
385
+ /**
386
+ * One event emitted by a harness adapter during a prompt turn.
387
+ *
388
+ * Mirrors `LanguageModelV4StreamPart` on the variants it shares so a
389
+ * `HarnessAgent` can pipe events through to AI SDK consumers with minimal
390
+ * translation. Primitive types from the V4 spec (`LanguageModelV4ToolCall`,
391
+ * `LanguageModelV4ToolResult`, `LanguageModelV4ToolApprovalRequest`,
392
+ * `LanguageModelV4Usage`, `LanguageModelV4FinishReason`) are reused
393
+ * verbatim — type-compat tests assert this stays the case.
394
+ *
395
+ * The metadata field is named `harnessMetadata` (not `providerMetadata`)
396
+ * because a harness is a peer to a provider, not a kind of provider. The
397
+ * agent rebinds it when forwarding to AI SDK consumers.
398
+ */
399
+ type HarnessV1StreamPart = {
400
+ type: 'stream-start';
401
+ warnings?: ReadonlyArray<HarnessV1CallWarning>;
402
+ /**
403
+ * The model the runtime actually resolved to for this turn, when the
404
+ * adapter learns it at stream start (e.g. Claude Code's `init` message
405
+ * reports the resolved/default model). Surfaced into telemetry as
406
+ * `gen_ai.request.model`. Omitted when the adapter doesn't know it here.
407
+ */
408
+ modelId?: string;
409
+ } | {
410
+ type: 'text-start';
411
+ id: string;
412
+ harnessMetadata?: HarnessV1Metadata;
413
+ } | {
414
+ type: 'text-delta';
415
+ id: string;
416
+ delta: string;
417
+ harnessMetadata?: HarnessV1Metadata;
418
+ } | {
419
+ type: 'text-end';
420
+ id: string;
421
+ harnessMetadata?: HarnessV1Metadata;
422
+ } | {
423
+ type: 'reasoning-start';
424
+ id: string;
425
+ harnessMetadata?: HarnessV1Metadata;
426
+ } | {
427
+ type: 'reasoning-delta';
428
+ id: string;
429
+ delta: string;
430
+ harnessMetadata?: HarnessV1Metadata;
431
+ } | {
432
+ type: 'reasoning-end';
433
+ id: string;
434
+ harnessMetadata?: HarnessV1Metadata;
435
+ } | (LanguageModelV4ToolCall & {
436
+ nativeName?: string;
437
+ }) | LanguageModelV4ToolApprovalRequest | LanguageModelV4ToolResult | {
438
+ type: 'finish-step';
439
+ finishReason: LanguageModelV4FinishReason;
440
+ usage: LanguageModelV4Usage;
441
+ harnessMetadata?: HarnessV1Metadata;
442
+ } | {
443
+ type: 'finish';
444
+ finishReason: LanguageModelV4FinishReason;
445
+ totalUsage: LanguageModelV4Usage;
446
+ harnessMetadata?: HarnessV1Metadata;
447
+ } | {
448
+ type: 'file-change';
449
+ event: 'create' | 'modify' | 'delete';
450
+ path: string;
451
+ harnessMetadata?: HarnessV1Metadata;
452
+ } | {
453
+ type: 'compaction';
454
+ trigger: 'manual' | 'auto';
455
+ summary: string;
456
+ tokensBefore?: number;
457
+ tokensAfter?: number;
458
+ harnessMetadata?: HarnessV1Metadata;
459
+ } | {
460
+ type: 'error';
461
+ error: unknown;
462
+ } | {
463
+ type: 'raw';
464
+ rawValue: unknown;
465
+ };
466
+ declare const harnessV1StreamStartPartSchema: z.ZodObject<{
467
+ type: z.ZodLiteral<"stream-start">;
468
+ warnings: z.ZodOptional<z.ZodReadonly<z.ZodArray<z.ZodType<HarnessV1CallWarning, unknown, z.core.$ZodTypeInternals<HarnessV1CallWarning, unknown>>>>>;
469
+ modelId: z.ZodOptional<z.ZodString>;
470
+ }, z.core.$strip>;
471
+ declare const harnessV1TextStartPartSchema: z.ZodObject<{
472
+ type: z.ZodLiteral<"text-start">;
473
+ id: z.ZodString;
474
+ harnessMetadata: z.ZodOptional<z.ZodType<HarnessV1Metadata, unknown, z.core.$ZodTypeInternals<HarnessV1Metadata, unknown>>>;
475
+ }, z.core.$strip>;
476
+ declare const harnessV1TextDeltaPartSchema: z.ZodObject<{
477
+ type: z.ZodLiteral<"text-delta">;
478
+ id: z.ZodString;
479
+ delta: z.ZodString;
480
+ harnessMetadata: z.ZodOptional<z.ZodType<HarnessV1Metadata, unknown, z.core.$ZodTypeInternals<HarnessV1Metadata, unknown>>>;
481
+ }, z.core.$strip>;
482
+ declare const harnessV1TextEndPartSchema: z.ZodObject<{
483
+ type: z.ZodLiteral<"text-end">;
484
+ id: z.ZodString;
485
+ harnessMetadata: z.ZodOptional<z.ZodType<HarnessV1Metadata, unknown, z.core.$ZodTypeInternals<HarnessV1Metadata, unknown>>>;
486
+ }, z.core.$strip>;
487
+ declare const harnessV1ReasoningStartPartSchema: z.ZodObject<{
488
+ type: z.ZodLiteral<"reasoning-start">;
489
+ id: z.ZodString;
490
+ harnessMetadata: z.ZodOptional<z.ZodType<HarnessV1Metadata, unknown, z.core.$ZodTypeInternals<HarnessV1Metadata, unknown>>>;
491
+ }, z.core.$strip>;
492
+ declare const harnessV1ReasoningDeltaPartSchema: z.ZodObject<{
493
+ type: z.ZodLiteral<"reasoning-delta">;
494
+ id: z.ZodString;
495
+ delta: z.ZodString;
496
+ harnessMetadata: z.ZodOptional<z.ZodType<HarnessV1Metadata, unknown, z.core.$ZodTypeInternals<HarnessV1Metadata, unknown>>>;
497
+ }, z.core.$strip>;
498
+ declare const harnessV1ReasoningEndPartSchema: z.ZodObject<{
499
+ type: z.ZodLiteral<"reasoning-end">;
500
+ id: z.ZodString;
501
+ harnessMetadata: z.ZodOptional<z.ZodType<HarnessV1Metadata, unknown, z.core.$ZodTypeInternals<HarnessV1Metadata, unknown>>>;
502
+ }, z.core.$strip>;
503
+ declare const harnessV1ToolCallPartSchema: z.ZodObject<{
504
+ type: z.ZodLiteral<"tool-call">;
505
+ toolCallId: z.ZodString;
506
+ toolName: z.ZodString;
507
+ input: z.ZodString;
508
+ providerExecuted: z.ZodOptional<z.ZodBoolean>;
509
+ dynamic: z.ZodOptional<z.ZodBoolean>;
510
+ providerMetadata: z.ZodOptional<z.ZodType<SharedV4ProviderMetadata, unknown, z.core.$ZodTypeInternals<SharedV4ProviderMetadata, unknown>>>;
511
+ nativeName: z.ZodOptional<z.ZodString>;
512
+ }, z.core.$strip>;
513
+ declare const harnessV1ToolApprovalRequestPartSchema: z.ZodObject<{
514
+ type: z.ZodLiteral<"tool-approval-request">;
515
+ approvalId: z.ZodString;
516
+ toolCallId: z.ZodString;
517
+ providerMetadata: z.ZodOptional<z.ZodType<SharedV4ProviderMetadata, unknown, z.core.$ZodTypeInternals<SharedV4ProviderMetadata, unknown>>>;
518
+ }, z.core.$strip>;
519
+ declare const harnessV1ToolResultPartSchema: z.ZodObject<{
520
+ type: z.ZodLiteral<"tool-result">;
521
+ toolCallId: z.ZodString;
522
+ toolName: z.ZodString;
523
+ result: z.ZodType<NonNullable<JSONValue>, unknown, z.core.$ZodTypeInternals<NonNullable<JSONValue>, unknown>>;
524
+ isError: z.ZodOptional<z.ZodBoolean>;
525
+ preliminary: z.ZodOptional<z.ZodBoolean>;
526
+ dynamic: z.ZodOptional<z.ZodBoolean>;
527
+ providerMetadata: z.ZodOptional<z.ZodType<SharedV4ProviderMetadata, unknown, z.core.$ZodTypeInternals<SharedV4ProviderMetadata, unknown>>>;
528
+ }, z.core.$strip>;
529
+ declare const harnessV1FinishStepPartSchema: z.ZodObject<{
530
+ type: z.ZodLiteral<"finish-step">;
531
+ finishReason: z.ZodType<LanguageModelV4FinishReason, unknown, z.core.$ZodTypeInternals<LanguageModelV4FinishReason, unknown>>;
532
+ usage: z.ZodType<LanguageModelV4Usage, unknown, z.core.$ZodTypeInternals<LanguageModelV4Usage, unknown>>;
533
+ harnessMetadata: z.ZodOptional<z.ZodType<HarnessV1Metadata, unknown, z.core.$ZodTypeInternals<HarnessV1Metadata, unknown>>>;
534
+ }, z.core.$strip>;
535
+ declare const harnessV1FinishPartSchema: z.ZodObject<{
536
+ type: z.ZodLiteral<"finish">;
537
+ finishReason: z.ZodType<LanguageModelV4FinishReason, unknown, z.core.$ZodTypeInternals<LanguageModelV4FinishReason, unknown>>;
538
+ totalUsage: z.ZodType<LanguageModelV4Usage, unknown, z.core.$ZodTypeInternals<LanguageModelV4Usage, unknown>>;
539
+ harnessMetadata: z.ZodOptional<z.ZodType<HarnessV1Metadata, unknown, z.core.$ZodTypeInternals<HarnessV1Metadata, unknown>>>;
540
+ }, z.core.$strip>;
541
+ declare const harnessV1FileChangePartSchema: z.ZodObject<{
542
+ type: z.ZodLiteral<"file-change">;
543
+ event: z.ZodEnum<{
544
+ create: "create";
545
+ modify: "modify";
546
+ delete: "delete";
547
+ }>;
548
+ path: z.ZodString;
549
+ harnessMetadata: z.ZodOptional<z.ZodType<HarnessV1Metadata, unknown, z.core.$ZodTypeInternals<HarnessV1Metadata, unknown>>>;
550
+ }, z.core.$strip>;
551
+ declare const harnessV1ErrorPartSchema: z.ZodObject<{
552
+ type: z.ZodLiteral<"error">;
553
+ error: z.ZodUnknown;
554
+ }, z.core.$strip>;
555
+ declare const harnessV1RawPartSchema: z.ZodObject<{
556
+ type: z.ZodLiteral<"raw">;
557
+ rawValue: z.ZodUnknown;
558
+ }, z.core.$strip>;
559
+ /**
560
+ * Assembled discriminated union over every `HarnessV1StreamPart` variant. Left
561
+ * un-annotated so it keeps its precise inferred type — the protocol layer
562
+ * composes the individual member schemas, and the type test asserts the
563
+ * inferred union equals `HarnessV1StreamPart`.
564
+ */
565
+ declare const harnessV1StreamPartSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
566
+ type: z.ZodLiteral<"stream-start">;
567
+ warnings: z.ZodOptional<z.ZodReadonly<z.ZodArray<z.ZodType<HarnessV1CallWarning, unknown, z.core.$ZodTypeInternals<HarnessV1CallWarning, unknown>>>>>;
568
+ modelId: z.ZodOptional<z.ZodString>;
569
+ }, z.core.$strip>, z.ZodObject<{
570
+ type: z.ZodLiteral<"text-start">;
571
+ id: z.ZodString;
572
+ harnessMetadata: z.ZodOptional<z.ZodType<HarnessV1Metadata, unknown, z.core.$ZodTypeInternals<HarnessV1Metadata, unknown>>>;
573
+ }, z.core.$strip>, z.ZodObject<{
574
+ type: z.ZodLiteral<"text-delta">;
575
+ id: z.ZodString;
576
+ delta: z.ZodString;
577
+ harnessMetadata: z.ZodOptional<z.ZodType<HarnessV1Metadata, unknown, z.core.$ZodTypeInternals<HarnessV1Metadata, unknown>>>;
578
+ }, z.core.$strip>, z.ZodObject<{
579
+ type: z.ZodLiteral<"text-end">;
580
+ id: z.ZodString;
581
+ harnessMetadata: z.ZodOptional<z.ZodType<HarnessV1Metadata, unknown, z.core.$ZodTypeInternals<HarnessV1Metadata, unknown>>>;
582
+ }, z.core.$strip>, z.ZodObject<{
583
+ type: z.ZodLiteral<"reasoning-start">;
584
+ id: z.ZodString;
585
+ harnessMetadata: z.ZodOptional<z.ZodType<HarnessV1Metadata, unknown, z.core.$ZodTypeInternals<HarnessV1Metadata, unknown>>>;
586
+ }, z.core.$strip>, z.ZodObject<{
587
+ type: z.ZodLiteral<"reasoning-delta">;
588
+ id: z.ZodString;
589
+ delta: z.ZodString;
590
+ harnessMetadata: z.ZodOptional<z.ZodType<HarnessV1Metadata, unknown, z.core.$ZodTypeInternals<HarnessV1Metadata, unknown>>>;
591
+ }, z.core.$strip>, z.ZodObject<{
592
+ type: z.ZodLiteral<"reasoning-end">;
593
+ id: z.ZodString;
594
+ harnessMetadata: z.ZodOptional<z.ZodType<HarnessV1Metadata, unknown, z.core.$ZodTypeInternals<HarnessV1Metadata, unknown>>>;
595
+ }, z.core.$strip>, z.ZodObject<{
596
+ type: z.ZodLiteral<"tool-call">;
597
+ toolCallId: z.ZodString;
598
+ toolName: z.ZodString;
599
+ input: z.ZodString;
600
+ providerExecuted: z.ZodOptional<z.ZodBoolean>;
601
+ dynamic: z.ZodOptional<z.ZodBoolean>;
602
+ providerMetadata: z.ZodOptional<z.ZodType<SharedV4ProviderMetadata, unknown, z.core.$ZodTypeInternals<SharedV4ProviderMetadata, unknown>>>;
603
+ nativeName: z.ZodOptional<z.ZodString>;
604
+ }, z.core.$strip>, z.ZodObject<{
605
+ type: z.ZodLiteral<"tool-approval-request">;
606
+ approvalId: z.ZodString;
607
+ toolCallId: z.ZodString;
608
+ providerMetadata: z.ZodOptional<z.ZodType<SharedV4ProviderMetadata, unknown, z.core.$ZodTypeInternals<SharedV4ProviderMetadata, unknown>>>;
609
+ }, z.core.$strip>, z.ZodObject<{
610
+ type: z.ZodLiteral<"tool-result">;
611
+ toolCallId: z.ZodString;
612
+ toolName: z.ZodString;
613
+ result: z.ZodType<NonNullable<JSONValue>, unknown, z.core.$ZodTypeInternals<NonNullable<JSONValue>, unknown>>;
614
+ isError: z.ZodOptional<z.ZodBoolean>;
615
+ preliminary: z.ZodOptional<z.ZodBoolean>;
616
+ dynamic: z.ZodOptional<z.ZodBoolean>;
617
+ providerMetadata: z.ZodOptional<z.ZodType<SharedV4ProviderMetadata, unknown, z.core.$ZodTypeInternals<SharedV4ProviderMetadata, unknown>>>;
618
+ }, z.core.$strip>, z.ZodObject<{
619
+ type: z.ZodLiteral<"finish-step">;
620
+ finishReason: z.ZodType<LanguageModelV4FinishReason, unknown, z.core.$ZodTypeInternals<LanguageModelV4FinishReason, unknown>>;
621
+ usage: z.ZodType<LanguageModelV4Usage, unknown, z.core.$ZodTypeInternals<LanguageModelV4Usage, unknown>>;
622
+ harnessMetadata: z.ZodOptional<z.ZodType<HarnessV1Metadata, unknown, z.core.$ZodTypeInternals<HarnessV1Metadata, unknown>>>;
623
+ }, z.core.$strip>, z.ZodObject<{
624
+ type: z.ZodLiteral<"finish">;
625
+ finishReason: z.ZodType<LanguageModelV4FinishReason, unknown, z.core.$ZodTypeInternals<LanguageModelV4FinishReason, unknown>>;
626
+ totalUsage: z.ZodType<LanguageModelV4Usage, unknown, z.core.$ZodTypeInternals<LanguageModelV4Usage, unknown>>;
627
+ harnessMetadata: z.ZodOptional<z.ZodType<HarnessV1Metadata, unknown, z.core.$ZodTypeInternals<HarnessV1Metadata, unknown>>>;
628
+ }, z.core.$strip>, z.ZodObject<{
629
+ type: z.ZodLiteral<"file-change">;
630
+ event: z.ZodEnum<{
631
+ create: "create";
632
+ modify: "modify";
633
+ delete: "delete";
634
+ }>;
635
+ path: z.ZodString;
636
+ harnessMetadata: z.ZodOptional<z.ZodType<HarnessV1Metadata, unknown, z.core.$ZodTypeInternals<HarnessV1Metadata, unknown>>>;
637
+ }, z.core.$strip>, z.ZodObject<{
638
+ type: z.ZodLiteral<"compaction">;
639
+ trigger: z.ZodEnum<{
640
+ manual: "manual";
641
+ auto: "auto";
642
+ }>;
643
+ summary: z.ZodString;
644
+ tokensBefore: z.ZodOptional<z.ZodNumber>;
645
+ tokensAfter: z.ZodOptional<z.ZodNumber>;
646
+ harnessMetadata: z.ZodOptional<z.ZodType<HarnessV1Metadata, unknown, z.core.$ZodTypeInternals<HarnessV1Metadata, unknown>>>;
647
+ }, z.core.$strip>, z.ZodObject<{
648
+ type: z.ZodLiteral<"error">;
649
+ error: z.ZodUnknown;
650
+ }, z.core.$strip>, z.ZodObject<{
651
+ type: z.ZodLiteral<"raw">;
652
+ rawValue: z.ZodUnknown;
653
+ }, z.core.$strip>]>;
654
+
655
+ /**
656
+ * Description of a host-defined tool that the harness should make available
657
+ * to the underlying agent runtime.
658
+ *
659
+ * Adapters translate this into whatever shape their runtime expects (e.g.
660
+ * Claude Code's tool definitions, Codex CLI's tool config, an MCP server
661
+ * exposed to the runtime, …). The adapter does not execute the tool; when
662
+ * the runtime calls it, the adapter emits a `tool-call` event and waits for
663
+ * `submitToolResult` from the caller.
664
+ */
665
+ type HarnessV1ToolSpec = {
666
+ /**
667
+ * Tool name the agent runtime sees. Must match the name on incoming
668
+ * `tool-call` events.
669
+ */
670
+ readonly name: string;
671
+ /**
672
+ * Human-readable description handed to the runtime, used to help the model
673
+ * decide when to call the tool.
674
+ */
675
+ readonly description?: string;
676
+ /**
677
+ * JSON Schema describing the expected input for the tool. Optional because
678
+ * some runtimes accept tools without schemas (free-form arguments).
679
+ */
680
+ readonly inputSchema?: JSONSchema7;
681
+ };
682
+
683
+ /**
684
+ * Options passed to `HarnessV1.doStart`.
685
+ *
686
+ * `sandboxSession` and `sessionWorkDir` are coupled and always present. The
687
+ * framework creates the sandbox and per-session working directory before
688
+ * calling the adapter, so adapters never need to derive provider-specific paths.
689
+ */
690
+ type HarnessV1StartOptions = {
691
+ /**
692
+ * Stable identifier for this harness session. Used as the underlying
693
+ * resource name where the adapter has a notion of a named session
694
+ * (sandbox name, native session id, …).
695
+ */
696
+ readonly sessionId: string;
697
+ /**
698
+ * Skills made available to the underlying runtime for the lifetime of
699
+ * the session. Adapters decide how to surface them — the `claude` CLI
700
+ * picks them up from `.claude/skills/*.md`, while the `codex` adapter
701
+ * inlines them into every user message.
702
+ */
703
+ readonly skills?: ReadonlyArray<HarnessV1Skill>;
704
+ /**
705
+ * Optional resume payload returned by a prior session lifecycle method. When
706
+ * provided, the adapter should resume the existing session rather than create
707
+ * a fresh one.
708
+ */
709
+ readonly resumeFrom?: HarnessV1ResumeState;
710
+ /**
711
+ * Approval policy for built-in adapter-native tool use. Custom host-executed
712
+ * tools are approved by the framework before results are submitted back to
713
+ * the adapter.
714
+ */
715
+ readonly permissionMode?: HarnessV1PermissionMode;
716
+ /**
717
+ * Signal that aborts startup. The adapter must propagate cancellation to
718
+ * any spawned processes or network calls.
719
+ */
720
+ readonly abortSignal?: AbortSignal;
721
+ /**
722
+ * Diagnostics wiring. The framework populates this; the adapter only
723
+ * forwards `observability.onDiagnostic` into its `SandboxChannel` and
724
+ * `observability.debug` into the bridge `start` message. Absent when the
725
+ * consumer has not enabled diagnostics.
726
+ */
727
+ readonly observability?: HarnessV1Observability;
728
+ /**
729
+ * Network sandbox session the adapter operates against. It is owned and
730
+ * lifecycled by `HarnessAgent`. Adapters call `restricted()` for the
731
+ * tool-safe filesystem/exec/spawn surface, and use the infra methods
732
+ * (`getPortUrl`, `ports`, `setNetworkPolicy`) for bridge wiring. Adapters
733
+ * must not call `stop()` themselves; the agent does that during cleanup.
734
+ */
735
+ readonly sandboxSession: HarnessV1NetworkSandboxSession;
736
+ /**
737
+ * Absolute path the adapter runs the agent in for this session. Composed by
738
+ * the framework as `<sandboxSession.defaultWorkingDirectory>/<harnessId>-<sessionId>`
739
+ * and created before `doStart`, so the adapter uses it directly instead of
740
+ * deriving its own provider-specific path.
741
+ */
742
+ readonly sessionWorkDir: string;
743
+ };
744
+ /**
745
+ * Options passed to `HarnessV1Session.doPromptTurn`.
746
+ */
747
+ type HarnessV1PromptTurnOptions = {
748
+ /**
749
+ * Fresh input for this turn — either a plain string or a single
750
+ * `ModelMessage`. The harness session owns its own conversation history,
751
+ * so prior turns are never replayed across the contract.
752
+ */
753
+ readonly prompt: HarnessV1Prompt;
754
+ /**
755
+ * Host-defined tools to make available to the underlying runtime for this
756
+ * turn. The harness emits `tool-call` events when the runtime calls one
757
+ * and waits for `submitToolResult`.
758
+ */
759
+ readonly tools?: ReadonlyArray<HarnessV1ToolSpec>;
760
+ /**
761
+ * Free-form instructions for the session. The framework supplies the same
762
+ * value on every turn; the adapter is responsible for applying it once, by
763
+ * prepending it to the first user message of a fresh (non-resumed) session.
764
+ * On a resumed session the adapter must not re-apply it — the original first
765
+ * message already carried it and lives in the runtime's persisted history.
766
+ */
767
+ readonly instructions?: string;
768
+ /**
769
+ * Signal that aborts the in-flight turn. The adapter must cancel any
770
+ * underlying work and resolve `done` (with an error if appropriate).
771
+ */
772
+ readonly abortSignal?: AbortSignal;
773
+ /**
774
+ * Callback invoked once for each event the adapter produces during the
775
+ * turn. The adapter is responsible for the ordering and completeness of
776
+ * events. `done` resolves once the adapter has emitted all events for the
777
+ * turn (success or failure).
778
+ */
779
+ readonly emit: (event: HarnessV1StreamPart) => void;
780
+ };
781
+ type HarnessV1PromptOptions = HarnessV1PromptTurnOptions;
782
+ /**
783
+ * Options passed to `HarnessV1Session.doContinueTurn`.
784
+ *
785
+ * Unlike `doPromptTurn`, there is no `prompt`: `doContinueTurn` continues the
786
+ * in-flight turn rather than starting a new one. It is used to continue a turn
787
+ * that was previously suspended temporarily, e.g. by the workflow slice loop.
788
+ */
789
+ type HarnessV1ContinueTurnOptions = {
790
+ /**
791
+ * Host-defined tools to make available for the continued turn. Same shape
792
+ * as `doPromptTurn`'s `tools`. An adapter that purely attaches to a live turn
793
+ * may ignore them; an adapter that re-drives the turn (rerun) needs them.
794
+ */
795
+ readonly tools?: ReadonlyArray<HarnessV1ToolSpec>;
796
+ /**
797
+ * Signal that aborts the continued turn. The adapter must cancel any
798
+ * underlying work and resolve `done` (with an error if appropriate).
799
+ */
800
+ readonly abortSignal?: AbortSignal;
801
+ /**
802
+ * Callback invoked once for each event the adapter produces while the
803
+ * continued turn runs. Same contract as `doPromptTurn`'s `emit`.
804
+ */
805
+ readonly emit: (event: HarnessV1StreamPart) => void;
806
+ };
807
+ type HarnessV1ContinueOptions = HarnessV1ContinueTurnOptions;
808
+ /**
809
+ * Active harness session, returned by `HarnessV1.doStart`.
810
+ *
811
+ * A session is the unit of state continuity across multiple prompts (one
812
+ * sandbox, one conversation history, one running agent runtime). The host
813
+ * holds onto the session across `doPromptTurn` calls and ends the local
814
+ * instance via `doDetach`, `doStop`, or `doDestroy`.
815
+ */
816
+ type HarnessV1Session = {
817
+ /**
818
+ * Stable identifier for this session. Same value the host passed in via
819
+ * `HarnessV1StartOptions.sessionId`.
820
+ */
821
+ readonly sessionId: string;
822
+ /**
823
+ * Whether this session was created from a resume payload. Fresh sessions
824
+ * report `false`; resumed sessions report `true`.
825
+ */
826
+ readonly isResume: boolean;
827
+ /**
828
+ * The model id the underlying runtime is configured to use, if the adapter
829
+ * knows it (e.g. from its settings). Surfaced into telemetry as
830
+ * `gen_ai.request.model` and the trace span labels. Omitted when the adapter
831
+ * defers to the runtime's own default and has no concrete id.
832
+ */
833
+ readonly modelId?: string;
834
+ /**
835
+ * Run one prompt turn. Returns a control handle the host uses to feed
836
+ * tool results, approvals, and user messages back into the turn while it
837
+ * is in flight. The handle's `done` promise resolves when the turn ends.
838
+ */
839
+ doPromptTurn(options: HarnessV1PromptTurnOptions): PromiseLike<HarnessV1PromptControl>;
840
+ /**
841
+ * Request that the underlying runtime compact its context. The runtime owns
842
+ * the compaction — the harness neither implements nor schedules it; this is
843
+ * only the trigger. When compaction completes, the adapter surfaces a
844
+ * `compaction` stream part on the next/active turn.
845
+ *
846
+ * Required, but not every runtime can honour it: adapters whose transport
847
+ * exposes no manual compaction (e.g. Codex over `codex exec`, which still
848
+ * auto-compacts on its own) throw `HarnessCapabilityUnsupportedError`.
849
+ * `customInstructions`, when supported, steer the compaction summary.
850
+ */
851
+ doCompact(customInstructions?: string): PromiseLike<void>;
852
+ /**
853
+ * Continue the in-flight turn **without a new user prompt**, returning the
854
+ * same control surface as `doPromptTurn`. Used to keep consuming a turn that
855
+ * was interrupted at a process boundary (the workflow slice loop), after the
856
+ * session itself has been resumed via `doStart({ resumeFrom })`:
857
+ *
858
+ * - When the runtime's turn is still live and reachable (bridge `attach` /
859
+ * `replay`), the adapter subscribes to its events and resolves `done` on
860
+ * the turn's `finish` — **without** re-driving it. Lossless.
861
+ * - When the live turn is gone (bridge respawned `rerun`, or a host-resident
862
+ * runtime like Pi whose turn cannot survive its process), the adapter
863
+ * re-drives the runtime's own thread from its persisted state. Lossy: work
864
+ * in flight at the interruption is recomputed.
865
+ *
866
+ * Required on every adapter. The behaviour an adapter can guarantee follows
867
+ * from its architecture; the contract is uniform.
868
+ */
869
+ doContinueTurn(options: HarnessV1ContinueTurnOptions): PromiseLike<HarnessV1PromptControl>;
870
+ /**
871
+ * Gracefully freeze the active turn **at a precise cursor while keeping the
872
+ * runtime alive**, returning the resume payload.
873
+ *
874
+ * This is the slice-boundary primitive. The adapter stops host-side
875
+ * consumption of the in-flight turn without telling the runtime to stop:
876
+ * for a bridge adapter it closes the host socket (the bridge keeps the turn
877
+ * running and accumulates events for replay) and resolves the active
878
+ * `doPromptTurn`/`doContinueTurn` `done` **cleanly** (not as an error) once buffered
879
+ * events have drained, so the cursor in the returned state equals the last
880
+ * event delivered to the host — guaranteeing the next slice's attach replays
881
+ * with no gap and no duplicate. A host-resident adapter (Pi) cannot keep its
882
+ * turn alive, so it persists what it can and the in-flight tail is recomputed
883
+ * on continue.
884
+ *
885
+ * Like `doDetach`, the sandbox/runtime is left running. Unlike `doDetach`,
886
+ * this is for an active turn at a slice boundary rather than a between-turn
887
+ * session handoff. Required on every adapter.
888
+ */
889
+ doSuspendTurn(): PromiseLike<HarnessV1ResumeState>;
890
+ /**
891
+ * Detach from the underlying runtime without tearing it down, returning a
892
+ * payload the host can later pass to `HarnessV1.doStart({ resumeFrom })`
893
+ * to reconnect. After `doDetach`, no further methods on this session
894
+ * instance may be called.
895
+ *
896
+ * Required. Adapters that cannot keep a live runtime parked still return the
897
+ * best resume state they can while leaving the sandbox running.
898
+ */
899
+ doDetach(): PromiseLike<HarnessV1ResumeState>;
900
+ /**
901
+ * Persist enough state to resume later, then stop the underlying runtime.
902
+ * After `doStop`, no further methods on this session instance may be called.
903
+ */
904
+ doStop(): PromiseLike<HarnessV1ResumeState>;
905
+ /**
906
+ * Stop the underlying runtime without returning resume state. After
907
+ * `doDestroy`, no further methods on this session instance may be called.
908
+ */
909
+ doDestroy(): PromiseLike<void>;
910
+ };
911
+
912
+ /**
913
+ * Versioned specification for a harness adapter — the integration point for
914
+ * one third-party coding-agent runtime (Claude Code, Codex, …).
915
+ *
916
+ * Modelled after `LanguageModelV4`: a tagged spec version, a small set of
917
+ * descriptive fields, and one entry-point method (`doStart`) that yields a
918
+ * session. There is intentionally no static "capabilities" object —
919
+ * optional features are signalled by the presence or absence of optional
920
+ * methods on the prompt-control handle. Adapters that cannot satisfy a request
921
+ * (manual compaction not supported, required port exposure unavailable, …)
922
+ * throw `HarnessCapabilityUnsupportedError` from the method that needs the
923
+ * capability.
924
+ */
925
+ type HarnessV1<TBuiltinTools extends ToolSet = ToolSet> = {
926
+ /**
927
+ * Spec version this adapter implements. Always the literal `'harness-v1'`.
928
+ */
929
+ readonly specificationVersion: 'harness-v1';
930
+ /**
931
+ * Stable identifier for this harness, used as the key inside
932
+ * `HarnessV1Metadata` objects. Conventionally a kebab-case slug matching
933
+ * the package name (`'claude-code'`, `'codex'`).
934
+ */
935
+ readonly harnessId: string;
936
+ /**
937
+ * Tools the adapter's underlying runtime exposes natively, as a `ToolSet`
938
+ * keyed by what the bridge emits on `tool-call` events
939
+ * (`commonName ?? nativeName`). Each entry is a `HarnessV1BuiltinTool`
940
+ * (a `Tool` plus harness-specific `nativeName` / `commonName` metadata).
941
+ *
942
+ * The agent merges this with consumer-supplied user tools when validating
943
+ * inbound tool calls and when typing the consumer-facing stream.
944
+ */
945
+ readonly builtinTools: TBuiltinTools;
946
+ /**
947
+ * Whether the adapter can emit approval requests for built-in tools when
948
+ * `permissionMode` is not `'allow-all'`.
949
+ *
950
+ * Custom host-executed tool approvals are handled by `HarnessAgent`, so this
951
+ * only describes adapter-native tool approval support.
952
+ */
953
+ readonly supportsBuiltinToolApprovals?: boolean;
954
+ /**
955
+ * Optional schema for resume payloads returned by the session lifecycle.
956
+ * When present, the adapter promises that exported state validated by this
957
+ * schema can be re-imported in a future `doStart({ resumeFrom })` call.
958
+ * Hosts use this to persist and re-hydrate resume payloads safely.
959
+ */
960
+ readonly resumeStateSchema?: FlexibleSchema<unknown>;
961
+ /**
962
+ * Optional bootstrap recipe. When defined, the harness session manager
963
+ * computes a stable identity from the recipe, passes it (along with a
964
+ * one-time recipe-application hook) to the sandbox provider, and applies
965
+ * the recipe idempotently after the provider returns the handle.
966
+ *
967
+ * Adapters with no bootstrap needs omit this. Adapters that need to install
968
+ * deps or ship bridge files into the sandbox declare them here so the
969
+ * provider can cache the result across sessions via snapshots when
970
+ * supported.
971
+ */
972
+ readonly getBootstrap?: (options?: {
973
+ abortSignal?: AbortSignal;
974
+ }) => PromiseLike<HarnessV1Bootstrap>;
975
+ /**
976
+ * Start a fresh session (or resume via `resumeFrom`). The host then issues
977
+ * prompts against the returned session, ending with `doDetach`, `doStop`, or
978
+ * `doDestroy`.
979
+ */
980
+ doStart(options: HarnessV1StartOptions): PromiseLike<HarnessV1Session>;
981
+ };
982
+
983
+ /**
984
+ * Cross-harness vocabulary of common built-in tool names with their baseline
985
+ * input schemas. Adapters that declare a built-in with one of these
986
+ * `commonName`s must accept (at least) every input the baseline schema
987
+ * accepts. Extra optional fields are encouraged.
988
+ *
989
+ * Used both as runtime values (spread into `ToolSet`s for inspection) and as
990
+ * a vocabulary source — `HarnessV1BuiltinToolName` is derived from its keys.
991
+ */
992
+ declare const HARNESS_V1_BUILTIN_TOOLS: {
993
+ readonly read: Tool<{
994
+ file_path: string;
995
+ }, unknown, _ai_sdk_provider_utils.Context>;
996
+ readonly write: Tool<{
997
+ file_path: string;
998
+ content: string;
999
+ }, unknown, _ai_sdk_provider_utils.Context>;
1000
+ readonly edit: Tool<{
1001
+ file_path: string;
1002
+ old_string: string;
1003
+ new_string: string;
1004
+ }, unknown, _ai_sdk_provider_utils.Context>;
1005
+ readonly bash: Tool<{
1006
+ command: string;
1007
+ }, unknown, _ai_sdk_provider_utils.Context>;
1008
+ readonly grep: Tool<{
1009
+ pattern: string;
1010
+ }, unknown, _ai_sdk_provider_utils.Context>;
1011
+ readonly glob: Tool<{
1012
+ pattern: string;
1013
+ }, unknown, _ai_sdk_provider_utils.Context>;
1014
+ readonly webSearch: Tool<{
1015
+ query: string;
1016
+ }, unknown, _ai_sdk_provider_utils.Context>;
1017
+ };
1018
+ type HarnessV1BuiltinToolName = keyof typeof HARNESS_V1_BUILTIN_TOOLS;
1019
+ declare const HARNESS_V1_BUILTIN_TOOL_NAMES: ReadonlyArray<HarnessV1BuiltinToolName>;
1020
+ type HarnessV1BuiltinToolUseKind = 'readonly' | 'edit' | 'bash';
1021
+ /**
1022
+ * A tool that the adapter's underlying runtime exposes natively. Extends the
1023
+ * AI SDK `Tool` shape with two optional harness-specific fields:
1024
+ *
1025
+ * - `nativeName`: the name as the underlying runtime knows it. Required
1026
+ * only when the tool's key in the harness's `builtinTools` is not the
1027
+ * native name — i.e. when the tool maps to a `commonName` (e.g. key
1028
+ * `'bash'` for Claude Code's native `'Bash'`). Tools without a common
1029
+ * equivalent are keyed by their native name directly, so `nativeName`
1030
+ * is redundant and omitted.
1031
+ * - `commonName`: cross-harness label drawn from
1032
+ * `HARNESS_V1_BUILTIN_TOOL_NAMES`. Set when the tool maps to a familiar
1033
+ * capability; consumers use it to recognize, e.g., that Claude Code's
1034
+ * `Bash` and Codex's `shell` are the same kind of tool.
1035
+ *
1036
+ * Always set both fields together via the `commonTool` helper, or neither
1037
+ * (declare the tool with the AI SDK's `tool()` directly).
1038
+ */
1039
+ type HarnessV1BuiltinTool<INPUT = unknown, OUTPUT = unknown> = Tool<INPUT, OUTPUT, any> & {
1040
+ readonly nativeName?: string;
1041
+ readonly commonName?: HarnessV1BuiltinToolName;
1042
+ readonly toolUseKind?: HarnessV1BuiltinToolUseKind;
1043
+ };
1044
+ type InputOf<T> = T extends Tool<infer I, any, any> ? I : never;
1045
+ type StandardInputOf<N extends HarnessV1BuiltinToolName> = InputOf<(typeof HARNESS_V1_BUILTIN_TOOLS)[N]>;
1046
+ type SupersetCheck<TStandard, TAdapter, TOk> = TStandard extends TAdapter ? TOk : [
1047
+ 'ERROR: adapter input schema must be a superset of the standard schema',
1048
+ {
1049
+ expected: TStandard;
1050
+ got: TAdapter;
1051
+ }
1052
+ ];
1053
+ /**
1054
+ * Declare a built-in tool that maps to a cross-harness common name. The
1055
+ * adapter's input schema must accept every input the standard schema for
1056
+ * `commonName` accepts. Extra optional fields are encouraged.
1057
+ *
1058
+ * If the schema is missing a field the standard requires (or has an
1059
+ * incompatible type), the return type collapses to a tagged error tuple,
1060
+ * which fails the surrounding `as const satisfies ToolSet` assignment and
1061
+ * surfaces a readable TypeScript error at the offending entry.
1062
+ */
1063
+ declare function commonTool<TName extends HarnessV1BuiltinToolName, TInput>(commonName: TName, opts: {
1064
+ readonly nativeName: string;
1065
+ readonly toolUseKind?: HarnessV1BuiltinToolUseKind;
1066
+ readonly description?: string;
1067
+ readonly inputSchema: FlexibleSchema<TInput>;
1068
+ }): SupersetCheck<StandardInputOf<TName>, TInput, HarnessV1BuiltinTool<TInput>>;
1069
+
1070
+ /**
1071
+ * Provider that produces network sandbox sessions for harness sessions. Lives at
1072
+ * module scope as a stable, synchronous object — analogous to
1073
+ * `LanguageModelV4` providers, no I/O performed at construction. The actual
1074
+ * sandbox is created (or wrapped) when `HarnessAgent` calls `createSession()`.
1075
+ */
1076
+ interface HarnessV1SandboxProvider {
1077
+ readonly specificationVersion: 'harness-sandbox-v1';
1078
+ readonly providerId: string;
1079
+ /**
1080
+ * Pool of ports the consumer reserved on a caller-provided sandbox for
1081
+ * concurrent harness sessions. The session manager leases one port per
1082
+ * session and releases on stop or destroy.
1083
+ *
1084
+ * Only meaningful when the provider wraps a caller-provided sandbox
1085
+ * (the caller pre-declared the ports). In create-new modes the provider
1086
+ * mints a fresh sandbox per session, so no leasing is needed; providers
1087
+ * leave this undefined.
1088
+ */
1089
+ readonly bridgePorts?: ReadonlyArray<number>;
1090
+ readonly createSession: (options?: {
1091
+ /**
1092
+ * Stable per-session identifier. When supplied, the provider names the
1093
+ * underlying resource deterministically so a future call to `resume`
1094
+ * (potentially from a different process) can find the same sandbox.
1095
+ * Omitted from prewarm and other paths that don't need a resumable
1096
+ * resource — in that case the provider falls back to its native
1097
+ * auto-naming.
1098
+ */
1099
+ sessionId?: string;
1100
+ abortSignal?: AbortSignal;
1101
+ /**
1102
+ * Stable identity for snapshot-based reuse. Providers that support
1103
+ * persistence/snapshots use this as part of the persistent sandbox
1104
+ * name; subsequent calls with the same identity resume from snapshot.
1105
+ *
1106
+ * Ignored when the provider is wrapping a caller-provided sandbox.
1107
+ */
1108
+ identity?: string;
1109
+ /**
1110
+ * Called exactly once per identity, on fresh creation. Snapshot-capable
1111
+ * providers wire this into the platform's one-time-setup hook so the
1112
+ * side effects are baked into the snapshot. Providers without snapshot
1113
+ * support run it immediately after fresh create.
1114
+ *
1115
+ * Not called when the provider is wrapping a caller-provided sandbox
1116
+ * (the caller owns the sandbox; the framework applies its own
1117
+ * idempotent bootstrap post-create instead).
1118
+ */
1119
+ onFirstCreate?: (session: Experimental_SandboxSession, opts: {
1120
+ abortSignal?: AbortSignal;
1121
+ }) => Promise<void>;
1122
+ }) => PromiseLike<HarnessV1NetworkSandboxSession>;
1123
+ /**
1124
+ * Reattach to an existing sandbox previously created with the same
1125
+ * `sessionId`. Optional — providers that cannot rehydrate by id (e.g.
1126
+ * just-bash) omit this; the harness throws
1127
+ * `HarnessCapabilityUnsupportedError` when resume is attempted against
1128
+ * them.
1129
+ *
1130
+ * The provider derives the sandbox identifier from `sessionId` using the
1131
+ * same deterministic naming scheme it used in `createSession`. Returns a
1132
+ * network sandbox session bound to the existing resource.
1133
+ */
1134
+ readonly resumeSession?: (options: {
1135
+ sessionId: string;
1136
+ abortSignal?: AbortSignal;
1137
+ }) => PromiseLike<HarnessV1NetworkSandboxSession>;
1138
+ }
1139
+
1140
+ /**
1141
+ * The subset of a host-defined tool that travels on the `start` message. The
1142
+ * runtime only needs the name, description, and JSON-Schema input to surface
1143
+ * the tool; `execute` stays on the host.
1144
+ */
1145
+ declare const harnessV1BridgeToolWireSchema: z.ZodObject<{
1146
+ name: z.ZodString;
1147
+ description: z.ZodOptional<z.ZodString>;
1148
+ inputSchema: z.ZodOptional<z.ZodUnknown>;
1149
+ }, z.core.$strip>;
1150
+ type HarnessV1BridgeToolWire = z.infer<typeof harnessV1BridgeToolWireSchema>;
1151
+ declare const harnessV1BridgePermissionModeSchema: z.ZodEnum<{
1152
+ "allow-all": "allow-all";
1153
+ "allow-reads": "allow-reads";
1154
+ "allow-edits": "allow-edits";
1155
+ }>;
1156
+ /**
1157
+ * Common fields of the inbound `start` message. Each adapter extends this with
1158
+ * its runtime-specific configuration (e.g. `thinking`/`continue` for Claude
1159
+ * Code, `reasoningEffort`/`webSearch`/`skills`/`resumeThreadId` for Codex) and
1160
+ * assembles the final inbound union from the shared command members below.
1161
+ *
1162
+ * `debug` carries the general `HarnessV1DebugConfig` — diagnostics config is not
1163
+ * a bridge concept, it just happens to ride the `start` frame for bridge-backed
1164
+ * adapters.
1165
+ */
1166
+ declare const harnessV1BridgeStartBaseSchema: z.ZodObject<{
1167
+ type: z.ZodLiteral<"start">;
1168
+ prompt: z.ZodString;
1169
+ tools: z.ZodOptional<z.ZodArray<z.ZodObject<{
1170
+ name: z.ZodString;
1171
+ description: z.ZodOptional<z.ZodString>;
1172
+ inputSchema: z.ZodOptional<z.ZodUnknown>;
1173
+ }, z.core.$strip>>>;
1174
+ model: z.ZodOptional<z.ZodString>;
1175
+ debug: z.ZodOptional<z.ZodObject<{
1176
+ enabled: z.ZodOptional<z.ZodBoolean>;
1177
+ level: z.ZodOptional<z.ZodEnum<{
1178
+ error: "error";
1179
+ warn: "warn";
1180
+ info: "info";
1181
+ debug: "debug";
1182
+ trace: "trace";
1183
+ }>>;
1184
+ subsystems: z.ZodOptional<z.ZodArray<z.ZodString>>;
1185
+ }, z.core.$strip>>;
1186
+ permissionMode: z.ZodOptional<z.ZodEnum<{
1187
+ "allow-all": "allow-all";
1188
+ "allow-reads": "allow-reads";
1189
+ "allow-edits": "allow-edits";
1190
+ }>>;
1191
+ }, z.core.$strip>;
1192
+ /**
1193
+ * Sent the instant the bridge accepts an authenticated WS connection. The host
1194
+ * waits for it before sending `start`/`resume`, because some sandbox runtimes
1195
+ * complete the upstream WS handshake before the connection is wired through to
1196
+ * the bridge process — anything sent in that gap is dropped. Carries the
1197
+ * bridge's lifecycle `state` and highest emitted `seq` for reconnect.
1198
+ */
1199
+ declare const harnessV1BridgeHelloSchema: z.ZodObject<{
1200
+ type: z.ZodLiteral<"bridge-hello">;
1201
+ state: z.ZodOptional<z.ZodString>;
1202
+ lastSeq: z.ZodOptional<z.ZodNumber>;
1203
+ }, z.core.$strip>;
1204
+ /**
1205
+ * The bridge's reply to an inbound `detach`. Carries the adapter-specific
1206
+ * payload the host serializes into `HarnessV1ResumeState`.
1207
+ */
1208
+ declare const harnessV1BridgeDetachSchema: z.ZodObject<{
1209
+ type: z.ZodLiteral<"bridge-detach">;
1210
+ data: z.ZodUnknown;
1211
+ }, z.core.$strip>;
1212
+ /**
1213
+ * A resume coordinate the bridge proactively announces (e.g. Codex's thread id)
1214
+ * so the host can cache it for a later resume without waiting for `detach`.
1215
+ */
1216
+ declare const harnessV1BridgeThreadSchema: z.ZodObject<{
1217
+ type: z.ZodLiteral<"bridge-thread">;
1218
+ threadId: z.ZodString;
1219
+ }, z.core.$strip>;
1220
+ /**
1221
+ * One captured console line from inside the sandbox. The bridge line-buffers
1222
+ * `process.stdout`/`process.stderr` and emits one of these per complete line.
1223
+ * Routed host-side to the diagnostics sink, never to the consumer stream.
1224
+ */
1225
+ declare const harnessV1BridgeSandboxLogSchema: z.ZodObject<{
1226
+ type: z.ZodLiteral<"sandbox-log">;
1227
+ source: z.ZodString;
1228
+ stream: z.ZodEnum<{
1229
+ stdout: "stdout";
1230
+ stderr: "stderr";
1231
+ }>;
1232
+ line: z.ZodString;
1233
+ }, z.core.$strip>;
1234
+ /**
1235
+ * A structured diagnostic an adapter emits from inside the bridge via
1236
+ * `turn.bridgeLog(...)`. Gated by the session's debug level + subsystem filter.
1237
+ */
1238
+ declare const harnessV1BridgeDebugEventSchema: z.ZodObject<{
1239
+ type: z.ZodLiteral<"debug-event">;
1240
+ level: z.ZodEnum<{
1241
+ error: "error";
1242
+ warn: "warn";
1243
+ info: "info";
1244
+ debug: "debug";
1245
+ trace: "trace";
1246
+ }>;
1247
+ subsystem: z.ZodString;
1248
+ message: z.ZodString;
1249
+ attrs: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
1250
+ error: z.ZodOptional<z.ZodObject<{
1251
+ name: z.ZodOptional<z.ZodString>;
1252
+ message: z.ZodString;
1253
+ stack: z.ZodOptional<z.ZodString>;
1254
+ }, z.core.$strip>>;
1255
+ }, z.core.$strip>;
1256
+ /**
1257
+ * Every frame a bridge can send to the host: the stream-part events plus the
1258
+ * transport/control frames. This is the schema the host `SandboxChannel`
1259
+ * validates inbound frames against.
1260
+ */
1261
+ declare const harnessV1BridgeOutboundMessageSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
1262
+ type: z.ZodLiteral<"stream-start">;
1263
+ warnings: z.ZodOptional<z.ZodReadonly<z.ZodArray<z.ZodType<HarnessV1CallWarning, unknown, z.core.$ZodTypeInternals<HarnessV1CallWarning, unknown>>>>>;
1264
+ modelId: z.ZodOptional<z.ZodString>;
1265
+ }, z.core.$strip>, z.ZodObject<{
1266
+ type: z.ZodLiteral<"text-start">;
1267
+ id: z.ZodString;
1268
+ harnessMetadata: z.ZodOptional<z.ZodType<HarnessV1Metadata, unknown, z.core.$ZodTypeInternals<HarnessV1Metadata, unknown>>>;
1269
+ }, z.core.$strip>, z.ZodObject<{
1270
+ type: z.ZodLiteral<"text-delta">;
1271
+ id: z.ZodString;
1272
+ delta: z.ZodString;
1273
+ harnessMetadata: z.ZodOptional<z.ZodType<HarnessV1Metadata, unknown, z.core.$ZodTypeInternals<HarnessV1Metadata, unknown>>>;
1274
+ }, z.core.$strip>, z.ZodObject<{
1275
+ type: z.ZodLiteral<"text-end">;
1276
+ id: z.ZodString;
1277
+ harnessMetadata: z.ZodOptional<z.ZodType<HarnessV1Metadata, unknown, z.core.$ZodTypeInternals<HarnessV1Metadata, unknown>>>;
1278
+ }, z.core.$strip>, z.ZodObject<{
1279
+ type: z.ZodLiteral<"reasoning-start">;
1280
+ id: z.ZodString;
1281
+ harnessMetadata: z.ZodOptional<z.ZodType<HarnessV1Metadata, unknown, z.core.$ZodTypeInternals<HarnessV1Metadata, unknown>>>;
1282
+ }, z.core.$strip>, z.ZodObject<{
1283
+ type: z.ZodLiteral<"reasoning-delta">;
1284
+ id: z.ZodString;
1285
+ delta: z.ZodString;
1286
+ harnessMetadata: z.ZodOptional<z.ZodType<HarnessV1Metadata, unknown, z.core.$ZodTypeInternals<HarnessV1Metadata, unknown>>>;
1287
+ }, z.core.$strip>, z.ZodObject<{
1288
+ type: z.ZodLiteral<"reasoning-end">;
1289
+ id: z.ZodString;
1290
+ harnessMetadata: z.ZodOptional<z.ZodType<HarnessV1Metadata, unknown, z.core.$ZodTypeInternals<HarnessV1Metadata, unknown>>>;
1291
+ }, z.core.$strip>, z.ZodObject<{
1292
+ type: z.ZodLiteral<"tool-call">;
1293
+ toolCallId: z.ZodString;
1294
+ toolName: z.ZodString;
1295
+ input: z.ZodString;
1296
+ providerExecuted: z.ZodOptional<z.ZodBoolean>;
1297
+ dynamic: z.ZodOptional<z.ZodBoolean>;
1298
+ providerMetadata: z.ZodOptional<z.ZodType<_ai_sdk_provider.SharedV4ProviderMetadata, unknown, z.core.$ZodTypeInternals<_ai_sdk_provider.SharedV4ProviderMetadata, unknown>>>;
1299
+ nativeName: z.ZodOptional<z.ZodString>;
1300
+ }, z.core.$strip>, z.ZodObject<{
1301
+ type: z.ZodLiteral<"tool-approval-request">;
1302
+ approvalId: z.ZodString;
1303
+ toolCallId: z.ZodString;
1304
+ providerMetadata: z.ZodOptional<z.ZodType<_ai_sdk_provider.SharedV4ProviderMetadata, unknown, z.core.$ZodTypeInternals<_ai_sdk_provider.SharedV4ProviderMetadata, unknown>>>;
1305
+ }, z.core.$strip>, z.ZodObject<{
1306
+ type: z.ZodLiteral<"tool-result">;
1307
+ toolCallId: z.ZodString;
1308
+ toolName: z.ZodString;
1309
+ result: z.ZodType<NonNullable<_ai_sdk_provider.JSONValue>, unknown, z.core.$ZodTypeInternals<NonNullable<_ai_sdk_provider.JSONValue>, unknown>>;
1310
+ isError: z.ZodOptional<z.ZodBoolean>;
1311
+ preliminary: z.ZodOptional<z.ZodBoolean>;
1312
+ dynamic: z.ZodOptional<z.ZodBoolean>;
1313
+ providerMetadata: z.ZodOptional<z.ZodType<_ai_sdk_provider.SharedV4ProviderMetadata, unknown, z.core.$ZodTypeInternals<_ai_sdk_provider.SharedV4ProviderMetadata, unknown>>>;
1314
+ }, z.core.$strip>, z.ZodObject<{
1315
+ type: z.ZodLiteral<"finish-step">;
1316
+ finishReason: z.ZodType<_ai_sdk_provider.LanguageModelV4FinishReason, unknown, z.core.$ZodTypeInternals<_ai_sdk_provider.LanguageModelV4FinishReason, unknown>>;
1317
+ usage: z.ZodType<_ai_sdk_provider.LanguageModelV4Usage, unknown, z.core.$ZodTypeInternals<_ai_sdk_provider.LanguageModelV4Usage, unknown>>;
1318
+ harnessMetadata: z.ZodOptional<z.ZodType<HarnessV1Metadata, unknown, z.core.$ZodTypeInternals<HarnessV1Metadata, unknown>>>;
1319
+ }, z.core.$strip>, z.ZodObject<{
1320
+ type: z.ZodLiteral<"finish">;
1321
+ finishReason: z.ZodType<_ai_sdk_provider.LanguageModelV4FinishReason, unknown, z.core.$ZodTypeInternals<_ai_sdk_provider.LanguageModelV4FinishReason, unknown>>;
1322
+ totalUsage: z.ZodType<_ai_sdk_provider.LanguageModelV4Usage, unknown, z.core.$ZodTypeInternals<_ai_sdk_provider.LanguageModelV4Usage, unknown>>;
1323
+ harnessMetadata: z.ZodOptional<z.ZodType<HarnessV1Metadata, unknown, z.core.$ZodTypeInternals<HarnessV1Metadata, unknown>>>;
1324
+ }, z.core.$strip>, z.ZodObject<{
1325
+ type: z.ZodLiteral<"file-change">;
1326
+ event: z.ZodEnum<{
1327
+ create: "create";
1328
+ modify: "modify";
1329
+ delete: "delete";
1330
+ }>;
1331
+ path: z.ZodString;
1332
+ harnessMetadata: z.ZodOptional<z.ZodType<HarnessV1Metadata, unknown, z.core.$ZodTypeInternals<HarnessV1Metadata, unknown>>>;
1333
+ }, z.core.$strip>, z.ZodObject<{
1334
+ type: z.ZodLiteral<"compaction">;
1335
+ trigger: z.ZodEnum<{
1336
+ manual: "manual";
1337
+ auto: "auto";
1338
+ }>;
1339
+ summary: z.ZodString;
1340
+ tokensBefore: z.ZodOptional<z.ZodNumber>;
1341
+ tokensAfter: z.ZodOptional<z.ZodNumber>;
1342
+ harnessMetadata: z.ZodOptional<z.ZodType<HarnessV1Metadata, unknown, z.core.$ZodTypeInternals<HarnessV1Metadata, unknown>>>;
1343
+ }, z.core.$strip>, z.ZodObject<{
1344
+ type: z.ZodLiteral<"error">;
1345
+ error: z.ZodUnknown;
1346
+ }, z.core.$strip>, z.ZodObject<{
1347
+ type: z.ZodLiteral<"raw">;
1348
+ rawValue: z.ZodUnknown;
1349
+ }, z.core.$strip>, z.ZodObject<{
1350
+ type: z.ZodLiteral<"bridge-hello">;
1351
+ state: z.ZodOptional<z.ZodString>;
1352
+ lastSeq: z.ZodOptional<z.ZodNumber>;
1353
+ }, z.core.$strip>, z.ZodObject<{
1354
+ type: z.ZodLiteral<"bridge-detach">;
1355
+ data: z.ZodUnknown;
1356
+ }, z.core.$strip>, z.ZodObject<{
1357
+ type: z.ZodLiteral<"bridge-thread">;
1358
+ threadId: z.ZodString;
1359
+ }, z.core.$strip>, z.ZodObject<{
1360
+ type: z.ZodLiteral<"sandbox-log">;
1361
+ source: z.ZodString;
1362
+ stream: z.ZodEnum<{
1363
+ stdout: "stdout";
1364
+ stderr: "stderr";
1365
+ }>;
1366
+ line: z.ZodString;
1367
+ }, z.core.$strip>, z.ZodObject<{
1368
+ type: z.ZodLiteral<"debug-event">;
1369
+ level: z.ZodEnum<{
1370
+ error: "error";
1371
+ warn: "warn";
1372
+ info: "info";
1373
+ debug: "debug";
1374
+ trace: "trace";
1375
+ }>;
1376
+ subsystem: z.ZodString;
1377
+ message: z.ZodString;
1378
+ attrs: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
1379
+ error: z.ZodOptional<z.ZodObject<{
1380
+ name: z.ZodOptional<z.ZodString>;
1381
+ message: z.ZodString;
1382
+ stack: z.ZodOptional<z.ZodString>;
1383
+ }, z.core.$strip>>;
1384
+ }, z.core.$strip>]>;
1385
+ type HarnessV1BridgeOutboundMessage = z.infer<typeof harnessV1BridgeOutboundMessageSchema>;
1386
+ type HarnessV1BridgeSandboxLog = z.infer<typeof harnessV1BridgeSandboxLogSchema>;
1387
+ type HarnessV1BridgeDebugEvent = z.infer<typeof harnessV1BridgeDebugEventSchema>;
1388
+ /**
1389
+ * Normalize a bridge diagnostics wire frame into the transport-agnostic
1390
+ * `HarnessV1Diagnostic` an adapter reports to the framework. A captured console
1391
+ * line maps `stderr` → `warn` and `stdout` → `info`; a structured event passes
1392
+ * its fields through. This is the seam where the bridge's serialization is
1393
+ * lifted into the general emission shape every harness shares.
1394
+ */
1395
+ declare function harnessV1DiagnosticFromBridgeFrame(frame: HarnessV1BridgeSandboxLog | HarnessV1BridgeDebugEvent, context: {
1396
+ sessionId?: string;
1397
+ timestamp: number;
1398
+ }): HarnessV1Diagnostic;
1399
+ declare const harnessV1BridgeToolResultInboundSchema: z.ZodObject<{
1400
+ type: z.ZodLiteral<"tool-result">;
1401
+ toolCallId: z.ZodString;
1402
+ output: z.ZodUnknown;
1403
+ isError: z.ZodOptional<z.ZodBoolean>;
1404
+ }, z.core.$strip>;
1405
+ declare const harnessV1BridgeToolApprovalResponseInboundSchema: z.ZodObject<{
1406
+ type: z.ZodLiteral<"tool-approval-response">;
1407
+ approvalId: z.ZodString;
1408
+ approved: z.ZodBoolean;
1409
+ reason: z.ZodOptional<z.ZodString>;
1410
+ }, z.core.$strip>;
1411
+ declare const harnessV1BridgeUserMessageInboundSchema: z.ZodObject<{
1412
+ type: z.ZodLiteral<"user-message">;
1413
+ text: z.ZodString;
1414
+ }, z.core.$strip>;
1415
+ declare const harnessV1BridgeAbortInboundSchema: z.ZodObject<{
1416
+ type: z.ZodLiteral<"abort">;
1417
+ }, z.core.$strip>;
1418
+ declare const harnessV1BridgeShutdownInboundSchema: z.ZodObject<{
1419
+ type: z.ZodLiteral<"shutdown">;
1420
+ }, z.core.$strip>;
1421
+ /**
1422
+ * Reconnect: after re-establishing the socket the host asks the bridge to
1423
+ * replay every buffered event with `seq > lastSeenEventId`.
1424
+ */
1425
+ declare const harnessV1BridgeResumeInboundSchema: z.ZodObject<{
1426
+ type: z.ZodLiteral<"resume">;
1427
+ lastSeenEventId: z.ZodNumber;
1428
+ }, z.core.$strip>;
1429
+ /**
1430
+ * The bridge replies with `bridge-detach` carrying any cached resume payload,
1431
+ * then exits.
1432
+ */
1433
+ declare const harnessV1BridgeDetachInboundSchema: z.ZodObject<{
1434
+ type: z.ZodLiteral<"detach">;
1435
+ }, z.core.$strip>;
1436
+ /**
1437
+ * The inbound command members shared by every bridge adapter. Spread these
1438
+ * alongside the adapter's own `start` schema to build the final inbound union:
1439
+ * `z.discriminatedUnion('type', [adapterStartSchema, ...harnessV1BridgeInboundCommandSchemas])`.
1440
+ */
1441
+ declare const harnessV1BridgeInboundCommandSchemas: readonly [z.ZodObject<{
1442
+ type: z.ZodLiteral<"tool-result">;
1443
+ toolCallId: z.ZodString;
1444
+ output: z.ZodUnknown;
1445
+ isError: z.ZodOptional<z.ZodBoolean>;
1446
+ }, z.core.$strip>, z.ZodObject<{
1447
+ type: z.ZodLiteral<"tool-approval-response">;
1448
+ approvalId: z.ZodString;
1449
+ approved: z.ZodBoolean;
1450
+ reason: z.ZodOptional<z.ZodString>;
1451
+ }, z.core.$strip>, z.ZodObject<{
1452
+ type: z.ZodLiteral<"user-message">;
1453
+ text: z.ZodString;
1454
+ }, z.core.$strip>, z.ZodObject<{
1455
+ type: z.ZodLiteral<"abort">;
1456
+ }, z.core.$strip>, z.ZodObject<{
1457
+ type: z.ZodLiteral<"shutdown">;
1458
+ }, z.core.$strip>, z.ZodObject<{
1459
+ type: z.ZodLiteral<"resume">;
1460
+ lastSeenEventId: z.ZodNumber;
1461
+ }, z.core.$strip>, z.ZodObject<{
1462
+ type: z.ZodLiteral<"detach">;
1463
+ }, z.core.$strip>];
1464
+ /**
1465
+ * The JSON line the bridge writes to stdout once its WebSocket server is bound,
1466
+ * announcing the port the host should connect to.
1467
+ */
1468
+ declare const harnessV1BridgeReadySchema: z.ZodObject<{
1469
+ type: z.ZodLiteral<"bridge-ready">;
1470
+ port: z.ZodNumber;
1471
+ }, z.core.$strip>;
1472
+ type HarnessV1BridgeReady = z.infer<typeof harnessV1BridgeReadySchema>;
1473
+
1474
+ declare const symbol$1: unique symbol;
1475
+ /**
1476
+ * Base error type for failures originating in or signalled by a harness
1477
+ * adapter. Specific failure modes (e.g. unsupported capability) extend this
1478
+ * class.
1479
+ */
1480
+ declare class HarnessError extends AISDKError {
1481
+ private readonly [symbol$1];
1482
+ constructor({ message, cause }: {
1483
+ message: string;
1484
+ cause?: unknown;
1485
+ });
1486
+ static isInstance(error: unknown): error is HarnessError;
1487
+ }
1488
+
1489
+ declare const symbol: unique symbol;
1490
+ /**
1491
+ * Thrown when a caller asks the harness to do something the adapter (or the
1492
+ * supplied sandbox) does not support, e.g. requesting manual compaction from
1493
+ * an adapter that only auto-compacts, or invoking `getPortUrl` on a sandbox
1494
+ * that does not expose one.
1495
+ *
1496
+ * The caller supplies the full human-readable message. Optional `harnessId`
1497
+ * is recorded as structured context for tooling.
1498
+ */
1499
+ declare class HarnessCapabilityUnsupportedError extends HarnessError {
1500
+ private readonly [symbol];
1501
+ readonly harnessId?: string;
1502
+ constructor({ message, harnessId, cause, }: {
1503
+ message: string;
1504
+ harnessId?: string;
1505
+ cause?: unknown;
1506
+ });
1507
+ static isInstance(error: unknown): error is HarnessCapabilityUnsupportedError;
1508
+ }
1509
+
1510
+ export { HARNESS_V1_BUILTIN_TOOLS, HARNESS_V1_BUILTIN_TOOL_NAMES, HarnessCapabilityUnsupportedError, HarnessError, type HarnessV1, type HarnessV1Bootstrap, type HarnessV1BootstrapCommand, type HarnessV1BootstrapFile, type HarnessV1BridgeDebugEvent, type HarnessV1BridgeOutboundMessage, type HarnessV1BridgeReady, type HarnessV1BridgeSandboxLog, type HarnessV1BridgeToolWire, type HarnessV1BuiltinTool, type HarnessV1BuiltinToolName, type HarnessV1BuiltinToolUseKind, type HarnessV1CallWarning, type HarnessV1ContinueOptions, type HarnessV1ContinueTurnOptions, type HarnessV1DebugConfig, type HarnessV1DebugLevel, type HarnessV1Diagnostic, type HarnessV1Metadata, type HarnessV1NetworkPolicy, type HarnessV1NetworkSandboxSession, type HarnessV1Observability, type HarnessV1PendingToolApproval, type HarnessV1PermissionMode, type HarnessV1Prompt, type HarnessV1PromptControl, type HarnessV1PromptOptions, type HarnessV1PromptTurnOptions, type HarnessV1ResumeState, type HarnessV1SandboxProvider, type HarnessV1Session, type HarnessV1Skill, type HarnessV1StartOptions, type HarnessV1StreamPart, type HarnessV1ToolSpec, commonTool, harnessV1BridgeAbortInboundSchema, harnessV1BridgeDebugEventSchema, harnessV1BridgeDetachInboundSchema, harnessV1BridgeDetachSchema, harnessV1BridgeHelloSchema, harnessV1BridgeInboundCommandSchemas, harnessV1BridgeOutboundMessageSchema, harnessV1BridgePermissionModeSchema, harnessV1BridgeReadySchema, harnessV1BridgeResumeInboundSchema, harnessV1BridgeSandboxLogSchema, harnessV1BridgeShutdownInboundSchema, harnessV1BridgeStartBaseSchema, harnessV1BridgeThreadSchema, harnessV1BridgeToolApprovalResponseInboundSchema, harnessV1BridgeToolResultInboundSchema, harnessV1BridgeToolWireSchema, harnessV1BridgeUserMessageInboundSchema, harnessV1DebugConfigSchema, harnessV1DebugLevelSchema, harnessV1DiagnosticFromBridgeFrame, harnessV1ErrorPartSchema, harnessV1FileChangePartSchema, harnessV1FinishPartSchema, harnessV1FinishStepPartSchema, harnessV1RawPartSchema, harnessV1ReasoningDeltaPartSchema, harnessV1ReasoningEndPartSchema, harnessV1ReasoningStartPartSchema, harnessV1StreamPartSchema, harnessV1StreamStartPartSchema, harnessV1TextDeltaPartSchema, harnessV1TextEndPartSchema, harnessV1TextStartPartSchema, harnessV1ToolApprovalRequestPartSchema, harnessV1ToolCallPartSchema, harnessV1ToolResultPartSchema };