@ai-sdk/harness 0.0.0 → 1.0.0-beta.14

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