@ai-sdk/harness 0.0.0-6b196531-20260710185421

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 (77) hide show
  1. package/CHANGELOG.md +414 -0
  2. package/LICENSE +13 -0
  3. package/README.md +176 -0
  4. package/agent/index.ts +56 -0
  5. package/bridge/index.ts +10 -0
  6. package/dist/agent/index.d.ts +1631 -0
  7. package/dist/agent/index.js +3491 -0
  8. package/dist/agent/index.js.map +1 -0
  9. package/dist/bridge/index.d.ts +129 -0
  10. package/dist/bridge/index.js +482 -0
  11. package/dist/bridge/index.js.map +1 -0
  12. package/dist/index.d.ts +1587 -0
  13. package/dist/index.js +517 -0
  14. package/dist/index.js.map +1 -0
  15. package/dist/utils/index.d.ts +329 -0
  16. package/dist/utils/index.js +1241 -0
  17. package/dist/utils/index.js.map +1 -0
  18. package/package.json +100 -0
  19. package/src/agent/harness-agent-session.ts +518 -0
  20. package/src/agent/harness-agent-settings.ts +187 -0
  21. package/src/agent/harness-agent-tool-approval-continuation.ts +94 -0
  22. package/src/agent/harness-agent-tool-types.ts +15 -0
  23. package/src/agent/harness-agent-types.ts +50 -0
  24. package/src/agent/harness-agent.ts +865 -0
  25. package/src/agent/internal/bootstrap-recipe.ts +124 -0
  26. package/src/agent/internal/bridge-port-registry.ts +52 -0
  27. package/src/agent/internal/harness-stream-text-result.ts +731 -0
  28. package/src/agent/internal/lifecycle-state-validation.ts +95 -0
  29. package/src/agent/internal/permission-mode.ts +50 -0
  30. package/src/agent/internal/resolve-observability.ts +128 -0
  31. package/src/agent/internal/run-prompt.ts +901 -0
  32. package/src/agent/internal/sandbox-bootstrap.ts +266 -0
  33. package/src/agent/internal/strip-work-dir.ts +68 -0
  34. package/src/agent/internal/to-harness-stream.ts +75 -0
  35. package/src/agent/internal/tool-filtering.ts +114 -0
  36. package/src/agent/internal/translate-stream-part.ts +221 -0
  37. package/src/agent/internal/turn-telemetry.ts +361 -0
  38. package/src/agent/observability/file-reporter.ts +206 -0
  39. package/src/agent/observability/index.ts +15 -0
  40. package/src/agent/observability/trace-tree-reporter.ts +122 -0
  41. package/src/agent/observability/types.ts +86 -0
  42. package/src/agent/prepare-harness-sandbox-template.ts +68 -0
  43. package/src/agent/prepare-sandbox-for-harness.ts +165 -0
  44. package/src/bridge/index.ts +797 -0
  45. package/src/errors/harness-capability-unsupported-error.ts +41 -0
  46. package/src/errors/harness-error.ts +22 -0
  47. package/src/index.ts +3 -0
  48. package/src/utils/ai-gateway-auth.ts +15 -0
  49. package/src/utils/bridge-diagnostics.ts +213 -0
  50. package/src/utils/bridge-ready.ts +277 -0
  51. package/src/utils/classify-disk-log.ts +43 -0
  52. package/src/utils/index.ts +31 -0
  53. package/src/utils/sandbox-channel.ts +525 -0
  54. package/src/utils/sandbox-home-dir.ts +22 -0
  55. package/src/utils/shell-quote.ts +3 -0
  56. package/src/utils/write-skills.ts +141 -0
  57. package/src/v1/harness-v1-bootstrap.ts +46 -0
  58. package/src/v1/harness-v1-bridge-protocol.ts +342 -0
  59. package/src/v1/harness-v1-builtin-tool.ts +138 -0
  60. package/src/v1/harness-v1-call-warning.ts +22 -0
  61. package/src/v1/harness-v1-diagnostic.ts +66 -0
  62. package/src/v1/harness-v1-lifecycle-state.ts +65 -0
  63. package/src/v1/harness-v1-metadata.ts +13 -0
  64. package/src/v1/harness-v1-network-sandbox-session.ts +123 -0
  65. package/src/v1/harness-v1-observability.ts +20 -0
  66. package/src/v1/harness-v1-permission-mode.ts +11 -0
  67. package/src/v1/harness-v1-prompt-control.ts +41 -0
  68. package/src/v1/harness-v1-prompt.ts +11 -0
  69. package/src/v1/harness-v1-sandbox-provider.ts +76 -0
  70. package/src/v1/harness-v1-session.ts +280 -0
  71. package/src/v1/harness-v1-skill.ts +36 -0
  72. package/src/v1/harness-v1-stream-part.ts +363 -0
  73. package/src/v1/harness-v1-tool-filtering.ts +25 -0
  74. package/src/v1/harness-v1-tool-spec.ts +31 -0
  75. package/src/v1/harness-v1.ts +94 -0
  76. package/src/v1/index.ts +99 -0
  77. package/utils/index.ts +1 -0
package/CHANGELOG.md ADDED
@@ -0,0 +1,414 @@
1
+ # @ai-sdk/harness
2
+
3
+ ## 0.0.0-6b196531-20260710185421
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [036463b]
8
+ - Updated dependencies [9988975]
9
+ - Updated dependencies [036463b]
10
+ - Updated dependencies [6b19653]
11
+ - @ai-sdk/provider-utils@0.0.0-6b196531-20260710185421
12
+ - ai@0.0.0-6b196531-20260710185421
13
+
14
+ ## 1.0.25
15
+
16
+ ### Patch Changes
17
+
18
+ - 44e988a: fix(harness): fix harness tool approval regression
19
+
20
+ ## 1.0.24
21
+
22
+ ### Patch Changes
23
+
24
+ - Updated dependencies [b9ac19f]
25
+ - Updated dependencies [a4186d6]
26
+ - ai@7.0.20
27
+
28
+ ## 1.0.23
29
+
30
+ ### Patch Changes
31
+
32
+ - 39c8276: fix(harness): improve opaque sandbox bridge error handling
33
+ - 91fe6d8: fix(harness): emit `finish-step` stream parts correctly per the underlying model steps
34
+ - 0be5014: fix(harness): fix obsolete portions of harness package readme
35
+
36
+ ## 1.0.22
37
+
38
+ ### Patch Changes
39
+
40
+ - Updated dependencies [be7f05a]
41
+ - Updated dependencies [ee55a07]
42
+ - Updated dependencies [aad737d]
43
+ - Updated dependencies [0f93c57]
44
+ - ai@7.0.19
45
+ - @ai-sdk/provider@4.0.3
46
+ - @ai-sdk/provider-utils@5.0.7
47
+
48
+ ## 1.0.21
49
+
50
+ ### Patch Changes
51
+
52
+ - Updated dependencies [ac306ed]
53
+ - @ai-sdk/provider-utils@5.0.6
54
+ - ai@7.0.18
55
+
56
+ ## 1.0.20
57
+
58
+ ### Patch Changes
59
+
60
+ - b7aa06a: fix(harness): include step numbers on harness step-end telemetry events.
61
+ - ai@7.0.17
62
+
63
+ ## 1.0.19
64
+
65
+ ### Patch Changes
66
+
67
+ - Updated dependencies [a8f9b6d]
68
+ - ai@7.0.16
69
+
70
+ ## 1.0.18
71
+
72
+ ### Patch Changes
73
+
74
+ - ai@7.0.15
75
+
76
+ ## 1.0.17
77
+
78
+ ### Patch Changes
79
+
80
+ - 5c5c0f5: Add experimental streaming transcription support for transcription models, including OpenAI `gpt-realtime-whisper` and xAI WebSocket STT.
81
+ - Updated dependencies [5c5c0f5]
82
+ - ai@7.0.14
83
+ - @ai-sdk/provider@4.0.2
84
+ - @ai-sdk/provider-utils@5.0.5
85
+
86
+ ## 1.0.16
87
+
88
+ ### Patch Changes
89
+
90
+ - ai@7.0.13
91
+
92
+ ## 1.0.15
93
+
94
+ ### Patch Changes
95
+
96
+ - Updated dependencies [ecfeb6f]
97
+ - Updated dependencies [a193137]
98
+ - Updated dependencies [c6f5e62]
99
+ - ai@7.0.12
100
+ - @ai-sdk/provider-utils@5.0.4
101
+
102
+ ## 1.0.14
103
+
104
+ ### Patch Changes
105
+
106
+ - Updated dependencies [0a87626]
107
+ - ai@7.0.11
108
+
109
+ ## 1.0.13
110
+
111
+ ### Patch Changes
112
+
113
+ - Updated dependencies [8c616f0]
114
+ - ai@7.0.10
115
+ - @ai-sdk/provider-utils@5.0.3
116
+
117
+ ## 1.0.12
118
+
119
+ ### Patch Changes
120
+
121
+ - 7859cea: feat(harness): add tool filtering via `activeTools` and `inactiveTools`
122
+ - c857346: feat(harness): add utility functions for certain duplicated layers in harnesses
123
+
124
+ ## 1.0.11
125
+
126
+ ### Patch Changes
127
+
128
+ - ai@7.0.9
129
+
130
+ ## 1.0.10
131
+
132
+ ### Patch Changes
133
+
134
+ - Updated dependencies [0274f34]
135
+ - @ai-sdk/provider@4.0.1
136
+ - ai@7.0.8
137
+ - @ai-sdk/provider-utils@5.0.2
138
+
139
+ ## 1.0.9
140
+
141
+ ### Patch Changes
142
+
143
+ - Updated dependencies [d598481]
144
+ - ai@7.0.7
145
+
146
+ ## 1.0.8
147
+
148
+ ### Patch Changes
149
+
150
+ - Updated dependencies [989402d]
151
+ - ai@7.0.6
152
+
153
+ ## 1.0.7
154
+
155
+ ### Patch Changes
156
+
157
+ - Updated dependencies [a2750db]
158
+ - ai@7.0.5
159
+
160
+ ## 1.0.6
161
+
162
+ ### Patch Changes
163
+
164
+ - Updated dependencies [6a436e3]
165
+ - @ai-sdk/provider-utils@5.0.1
166
+ - ai@7.0.4
167
+
168
+ ## 1.0.5
169
+
170
+ ### Patch Changes
171
+
172
+ - ai@7.0.3
173
+
174
+ ## 1.0.4
175
+
176
+ ### Patch Changes
177
+
178
+ - c493634: fix(harness): fix harness Zod usage to be v3/v4 compatible
179
+
180
+ ## 1.0.3
181
+
182
+ ### Patch Changes
183
+
184
+ - 51d10a0: feat(harness): add `prepareSandboxForHarness` utility to prepare a caller-owned sandbox for one or more harnesses
185
+
186
+ ## 1.0.2
187
+
188
+ ### Patch Changes
189
+
190
+ - ai@7.0.2
191
+
192
+ ## 1.0.1
193
+
194
+ ### Patch Changes
195
+
196
+ - ai@7.0.1
197
+
198
+ ## 1.0.0
199
+
200
+ ### Major Changes
201
+
202
+ - 9d6dbe0: feat(harness): add sandbox specific expansion for harness abstraction, add `sandbox-just-bash` and `sandbox-vercel`
203
+
204
+ ### Patch Changes
205
+
206
+ - e5d4a24: chore(harness): update ws package
207
+ - aae0138: fix(harness): make listening for sandbox bridge readiness compatible with Bun
208
+ - be83911: fix(harness): reject bridge startup when the WebSocket port cannot be bound
209
+ - 3d87086: fix(harness): guard against invalid resuming a session vs continuing a turn
210
+ - d77bed4: chore(harness): separate harness spec types (v1) from consumer-facing types
211
+ - 21d3d60: feat(harness): implement harness specification
212
+ - 3d9a50c: feat(harness): implement harness adapters for Claude Code, Codex, Pi
213
+ - 57e0a59: fix(harness): ensure finish chunk's total usage is actually coming from total usage
214
+ - 6c7a3e5: Start the `1.0.0` canary release line for the experimental harness and sandbox packages. They were unintentionally published as `0.0.0-canary.*` because they were scaffolded with a `0.0.0-canary.0` premajor version, which semver could not advance past on a major bump.
215
+ - 1ea15a3: fix(harness): fix various bugs with harness skills not being correctly processed by the harness adapters
216
+ - a83a367: feat(harness): allow pre-snapshot `sandboxConfig.onBootstrap` callback in `HarnessAgent`
217
+ - b8396f0: trigger initial beta release
218
+ - 534dac6: fix(harness): fix incomplete OIDC token support for AI Gateway auth in harness adapters
219
+
220
+ ## 1.0.0-beta.27
221
+
222
+ ### Patch Changes
223
+
224
+ - ai@7.0.0-beta.187
225
+
226
+ ## 1.0.0-beta.26
227
+
228
+ ### Patch Changes
229
+
230
+ - a83a367: feat(harness): allow pre-snapshot `sandboxConfig.onBootstrap` callback in `HarnessAgent`
231
+
232
+ ## 1.0.0-beta.25
233
+
234
+ ### Patch Changes
235
+
236
+ - ai@7.0.0-beta.186
237
+
238
+ ## 1.0.0-beta.24
239
+
240
+ ### Patch Changes
241
+
242
+ - Updated dependencies [75763b0]
243
+ - ai@7.0.0-beta.185
244
+
245
+ ## 1.0.0-beta.23
246
+
247
+ ### Patch Changes
248
+
249
+ - 57e0a59: fix(harness): ensure finish chunk's total usage is actually coming from total usage
250
+
251
+ ## 1.0.0-beta.22
252
+
253
+ ### Patch Changes
254
+
255
+ - Updated dependencies [0416e3e]
256
+ - @ai-sdk/provider@4.0.0-beta.20
257
+ - ai@7.0.0-beta.184
258
+ - @ai-sdk/provider-utils@5.0.0-beta.50
259
+
260
+ ## 1.0.0-beta.21
261
+
262
+ ### Patch Changes
263
+
264
+ - ai@7.0.0-beta.183
265
+
266
+ ## 1.0.0-beta.20
267
+
268
+ ### Patch Changes
269
+
270
+ - e5d4a24: chore(harness): update ws package
271
+ - Updated dependencies [cc6ab90]
272
+ - ai@7.0.0-beta.182
273
+
274
+ ## 1.0.0-beta.19
275
+
276
+ ### Patch Changes
277
+
278
+ - Updated dependencies [6a2caf9]
279
+ - ai@7.0.0-beta.181
280
+
281
+ ## 1.0.0-beta.18
282
+
283
+ ### Patch Changes
284
+
285
+ - Updated dependencies [81a284b]
286
+ - ai@7.0.0-beta.180
287
+
288
+ ## 1.0.0-beta.17
289
+
290
+ ### Patch Changes
291
+
292
+ - 534dac6: fix(harness): fix incomplete OIDC token support for AI Gateway auth in harness adapters
293
+
294
+ ## 1.0.0-beta.16
295
+
296
+ ### Patch Changes
297
+
298
+ - ai@7.0.0-beta.179
299
+
300
+ ## 1.0.0-beta.15
301
+
302
+ ### Patch Changes
303
+
304
+ - Updated dependencies [b097c52]
305
+ - ai@7.0.0-beta.178
306
+
307
+ ## 1.0.0-beta.14
308
+
309
+ ### Patch Changes
310
+
311
+ - b8396f0: trigger initial beta release
312
+ - Updated dependencies [b8396f0]
313
+ - @ai-sdk/provider-utils@5.0.0-beta.49
314
+ - @ai-sdk/provider@4.0.0-beta.19
315
+ - ai@7.0.0-beta.177
316
+
317
+ ## 1.0.0-canary.13
318
+
319
+ ### Patch Changes
320
+
321
+ - ai@7.0.0-canary.176
322
+
323
+ ## 1.0.0-canary.12
324
+
325
+ ### Patch Changes
326
+
327
+ - Updated dependencies [6ec57f5]
328
+ - ai@7.0.0-canary.175
329
+
330
+ ## 1.0.0-canary.11
331
+
332
+ ### Patch Changes
333
+
334
+ - be83911: fix(harness): reject bridge startup when the WebSocket port cannot be bound
335
+
336
+ ## 1.0.0-canary.10
337
+
338
+ ### Patch Changes
339
+
340
+ - ai@7.0.0-canary.174
341
+
342
+ ## 1.0.0-canary.9
343
+
344
+ ### Patch Changes
345
+
346
+ - ai@7.0.0-canary.173
347
+
348
+ ## 1.0.0-canary.8
349
+
350
+ ### Patch Changes
351
+
352
+ - aae0138: fix(harness): make listening for sandbox bridge readiness compatible with Bun
353
+
354
+ ## 1.0.0-canary.7
355
+
356
+ ### Patch Changes
357
+
358
+ - 3d87086: fix(harness): guard against invalid resuming a session vs continuing a turn
359
+ - 1ea15a3: fix(harness): fix various bugs with harness skills not being correctly processed by the harness adapters
360
+ - Updated dependencies [aeda373]
361
+ - Updated dependencies [25a64f8]
362
+ - Updated dependencies [375fdd7]
363
+ - Updated dependencies [f18b08f]
364
+ - Updated dependencies [b4507d5]
365
+ - @ai-sdk/provider-utils@5.0.0-canary.48
366
+ - ai@7.0.0-canary.172
367
+
368
+ ## 1.0.0-canary.6
369
+
370
+ ### Patch Changes
371
+
372
+ - Updated dependencies [89ad56f]
373
+ - Updated dependencies [f9a496f]
374
+ - Updated dependencies [3295831]
375
+ - ai@7.0.0-canary.171
376
+
377
+ ## 1.0.0-canary.5
378
+
379
+ ### Patch Changes
380
+
381
+ - d77bed4: chore(harness): separate harness spec types (v1) from consumer-facing types
382
+ - Updated dependencies [bae5e2b]
383
+ - Updated dependencies [69d7128]
384
+ - ai@7.0.0-canary.170
385
+ - @ai-sdk/provider-utils@5.0.0-canary.47
386
+
387
+ ## 1.0.0-canary.4
388
+
389
+ ### Patch Changes
390
+
391
+ - 3d9a50c: feat(harness): implement harness adapters for Claude Code, Codex, Pi
392
+
393
+ ## 1.0.0-canary.3
394
+
395
+ ### Patch Changes
396
+
397
+ - 21d3d60: feat(harness): implement harness specification
398
+ - Updated dependencies [a5018ab]
399
+ - Updated dependencies [21d3d60]
400
+ - Updated dependencies [426dbbb]
401
+ - Updated dependencies [7fd3360]
402
+ - ai@7.0.0-canary.169
403
+
404
+ ## 1.0.0-canary.2
405
+
406
+ ### Patch Changes
407
+
408
+ - 6c7a3e5: Start the `1.0.0` canary release line for the experimental harness and sandbox packages. They were unintentionally published as `0.0.0-canary.*` because they were scaffolded with a `0.0.0-canary.0` premajor version, which semver could not advance past on a major bump.
409
+
410
+ ## 0.0.0-canary.1
411
+
412
+ ### Major Changes
413
+
414
+ - 9d6dbe0: feat(harness): add sandbox specific expansion for harness abstraction, add `sandbox-just-bash` and `sandbox-vercel`
package/LICENSE ADDED
@@ -0,0 +1,13 @@
1
+ Copyright 2023 Vercel, Inc.
2
+
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+
7
+ http://www.apache.org/licenses/LICENSE-2.0
8
+
9
+ Unless required by applicable law or agreed to in writing, software
10
+ distributed under the License is distributed on an "AS IS" BASIS,
11
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ See the License for the specific language governing permissions and
13
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,176 @@
1
+ # AI SDK - Harness Specification and Agent
2
+
3
+ _This package is **experimental**._
4
+
5
+ `HarnessAgent` implementation plus the underlying harness specification, including an expanded network session sandbox interface to support harness sandbox needs.
6
+
7
+ ## Setup
8
+
9
+ ```bash
10
+ npm i ai zod @ai-sdk/harness @ai-sdk/harness-claude-code @ai-sdk/sandbox-vercel
11
+ ```
12
+
13
+ ## Usage
14
+
15
+ ```ts
16
+ import { HarnessAgent } from '@ai-sdk/harness/agent';
17
+ import { claudeCode } from '@ai-sdk/harness-claude-code';
18
+ import { createVercelSandbox } from '@ai-sdk/sandbox-vercel';
19
+ import { tool } from 'ai';
20
+ import { z } from 'zod/v4';
21
+
22
+ const agent = new HarnessAgent({
23
+ harness: claudeCode,
24
+ id: 'auth-agent',
25
+ instructions:
26
+ 'You are a careful refactoring assistant. Prefer minimal diffs.',
27
+ sandbox: createVercelSandbox({
28
+ runtime: 'node24',
29
+ ports: [4000],
30
+ }),
31
+ sandboxConfig: {
32
+ bootstrapHash: 'ripgrep-v1',
33
+ onBootstrap: async ({ session, abortSignal }) => {
34
+ const streamResult = await session.run({
35
+ command:
36
+ 'command -v rg >/dev/null || (apt-get update && apt-get install -y ripgrep)',
37
+ abortSignal,
38
+ });
39
+ if (result.exitCode !== 0) {
40
+ throw new Error(`Failed to install ripgrep: ${result.stderr}`);
41
+ }
42
+ },
43
+ onSession: async ({ session, sessionWorkDir, abortSignal }) => {
44
+ await session.writeTextFile({
45
+ path: `${sessionWorkDir}/README.md`,
46
+ content: 'Workspace notes for this session.',
47
+ abortSignal,
48
+ });
49
+ },
50
+ },
51
+ tools: {
52
+ deploy: tool({
53
+ description: 'Deploy to a target environment',
54
+ inputSchema: z.object({ env: z.enum(['staging', 'production']) }),
55
+ execute: async ({ env }) => ({ url: `https://${env}.example.com` }),
56
+ }),
57
+ },
58
+ });
59
+
60
+ const session = await agent.createSession();
61
+
62
+ try {
63
+ const generateResult = await agent.generate({
64
+ session,
65
+ prompt: 'Fix the failing test in src/auth.ts',
66
+ });
67
+ console.log(generateResult.text);
68
+
69
+ // Streaming
70
+ const streamResult = await agent.stream({
71
+ session,
72
+ prompt: 'Now write a regression test',
73
+ });
74
+ for await (const part of streamResult.stream) {
75
+ if (part.type === 'text-delta') {
76
+ process.stdout.write(part.text);
77
+ }
78
+ }
79
+ } finally {
80
+ await session.destroy();
81
+ }
82
+ ```
83
+
84
+ Use `session.detach()` to park a bridge-backed session for later attach, `session.stop()` to save state and stop the sandbox, or `session.destroy()` to clean up without keeping resume state. Bridge-backed adapters such as Claude Code, Codex, OpenCode, and DeepAgents require a sandbox provider that exposes ports — `@ai-sdk/sandbox-vercel` is the supported choice today. `@ai-sdk/sandbox-just-bash` is suitable only for host-runtime or otherwise non-bridge flows, such as Pi.
85
+
86
+ `sandbox` is a required `HarnessV1SandboxProvider` — the agent calls `provider.createSession()` when a session starts. Use `sandboxConfig` for agent specific sandbox configuration that works independently from the sandbox provider that is used:
87
+
88
+ - Use `sandboxConfig.onSession` to prepare the acquired sandbox before the harness adapter starts. The hook runs for fresh and resumed sessions, so keep it idempotent.
89
+ - Use `sandboxConfig.onBootstrap` for expensive sandbox setup that should be baked into a reusable snapshot, such as installing tools or cloning a large repository. Provide `sandboxConfig.bootstrapHash` with it and change that value whenever the bootstrap output should invalidate the cached snapshot.
90
+ - Use `sandboxConfig.workDir` to set a stable working directory for the agent, relative to the sandbox's default working directory; otherwise regular sessions use the existing `<harnessId>-<sessionId>` directory. In that case, the `onBootstrap` callback receives the sandbox's default working directory.
91
+
92
+ Use `prepareHarnessSandboxTemplate()` to create or refresh the sandbox provider's
93
+ own reusable template for one harness before serving traffic. This is the
94
+ replacement for `prewarmHarness()`, which remains as a deprecated alias.
95
+
96
+ Use `prepareSandboxForHarness()` when you own an existing sandbox and want to
97
+ prepare it before creating your own snapshot. It applies the selected harness
98
+ bootstrap recipes and `sandboxConfig.onBootstrap`, returns the computed
99
+ preparation identity and per-harness recipe identities, and leaves snapshotting
100
+ or stopping the sandbox to your code. Later, create a sandbox from that snapshot
101
+ and pass the native sandbox object to `createVercelSandbox({ sandbox })` for the
102
+ `HarnessAgent`. When you reuse a caller-provided sandbox with a bridge-backed
103
+ harness, declare the available port pool, for example
104
+ `createVercelSandbox({ sandbox, bridgePorts: [4000] })`.
105
+
106
+ ### Available harnesses
107
+
108
+ See the [harness adapters documentation](https://ai-sdk.dev/v7/docs/ai-sdk-harnesses/harness-adapters).
109
+
110
+ ## Implementing a harness
111
+
112
+ Implement the `HarnessV1` factory and a `HarnessV1Session` whose `doPromptTurn` emits events; the agent surface, streaming, tool execution, and multi-turn state are handled for you. Read `startOpts.sandboxSession` for the network sandbox session the agent created and will stop on cleanup. Call `sandboxSession.restricted()` for the tool-safe file-IO/exec/spawn surface.
113
+
114
+ ```ts
115
+ import type { HarnessV1, HarnessV1Session } from '@ai-sdk/harness';
116
+
117
+ export function myHarness(): HarnessV1 {
118
+ return {
119
+ specificationVersion: 'harness-v1',
120
+ harnessId: 'my-harness',
121
+ builtinTools: {},
122
+ doStart: async startOpts => {
123
+ const usage = {
124
+ inputTokens: { total: 0, noCache: 0 },
125
+ outputTokens: { total: 0, text: 0 },
126
+ };
127
+ const resumeState = {
128
+ type: 'resume-session' as const,
129
+ harnessId: 'my-harness',
130
+ specificationVersion: 'harness-v1' as const,
131
+ data: {},
132
+ };
133
+ const continueState = {
134
+ type: 'continue-turn' as const,
135
+ harnessId: 'my-harness',
136
+ specificationVersion: 'harness-v1' as const,
137
+ data: {},
138
+ };
139
+ const session: HarnessV1Session = {
140
+ sessionId: startOpts.sessionId,
141
+ isResume:
142
+ startOpts.resumeFrom != null || startOpts.continueFrom != null,
143
+ doPromptTurn: async promptOpts => {
144
+ const done = Promise.resolve().then(() => {
145
+ promptOpts.emit({ type: 'text-start', id: 't' });
146
+ promptOpts.emit({ type: 'text-delta', id: 't', delta: 'Hello.' });
147
+ promptOpts.emit({ type: 'text-end', id: 't' });
148
+ promptOpts.emit({
149
+ type: 'finish',
150
+ finishReason: { unified: 'stop', raw: 'stop' },
151
+ totalUsage: usage,
152
+ });
153
+ });
154
+ return { submitToolResult: async () => {}, done };
155
+ },
156
+ doContinueTurn: async continueOpts => {
157
+ const done = Promise.resolve().then(() => {
158
+ continueOpts.emit({
159
+ type: 'finish',
160
+ finishReason: { unified: 'stop', raw: 'stop' },
161
+ totalUsage: usage,
162
+ });
163
+ });
164
+ return { submitToolResult: async () => {}, done };
165
+ },
166
+ doCompact: async () => {},
167
+ doDetach: async () => resumeState,
168
+ doStop: async () => resumeState,
169
+ doDestroy: async () => {},
170
+ doSuspendTurn: async () => continueState,
171
+ };
172
+ return session;
173
+ },
174
+ };
175
+ }
176
+ ```
package/agent/index.ts ADDED
@@ -0,0 +1,56 @@
1
+ export { HarnessAgent } from '../src/agent/harness-agent';
2
+ export type { HarnessAllTools } from '../src/agent/harness-agent-tool-types';
3
+ export type {
4
+ HarnessAgentSandboxConfig,
5
+ HarnessAgentSettings,
6
+ HarnessAgentToolApprovalConfiguration,
7
+ } from '../src/agent/harness-agent-settings';
8
+ export type {
9
+ HarnessAgentAdapter,
10
+ HarnessAgentAdapterSession,
11
+ HarnessAgentBuiltinTool,
12
+ HarnessAgentBuiltinToolName,
13
+ HarnessAgentBuiltinTools,
14
+ HarnessAgentBuiltinToolUseKind,
15
+ HarnessAgentContinueTurnOptions,
16
+ HarnessAgentContinueTurnState,
17
+ HarnessAgentLifecycleState,
18
+ HarnessAgentPendingToolApproval,
19
+ HarnessAgentPermissionMode,
20
+ HarnessAgentPrompt,
21
+ HarnessAgentPromptControl,
22
+ HarnessAgentPromptTurnOptions,
23
+ HarnessAgentResumeSessionState,
24
+ HarnessAgentSkill,
25
+ HarnessAgentStartOptions,
26
+ HarnessAgentStreamPart,
27
+ HarnessAgentToolSpec,
28
+ } from '../src/agent/harness-agent-types';
29
+ export { HarnessAgentSession } from '../src/agent/harness-agent-session';
30
+ export {
31
+ collectHarnessAgentToolApprovalContinuations,
32
+ type HarnessAgentToolApprovalContinuation,
33
+ } from '../src/agent/harness-agent-tool-approval-continuation';
34
+ export {
35
+ prepareHarnessSandboxTemplate,
36
+ prewarmHarness,
37
+ } from '../src/agent/prepare-harness-sandbox-template';
38
+ export {
39
+ prepareSandboxForHarness,
40
+ type PrepareSandboxForHarnessResult,
41
+ } from '../src/agent/prepare-sandbox-for-harness';
42
+ export type {
43
+ HarnessDebugConfig,
44
+ HarnessDebugLevel,
45
+ HarnessDiagnostic,
46
+ HarnessDiagnosticConsumer,
47
+ } from '../src/agent/observability/types';
48
+ export { HarnessError } from '../src/errors/harness-error';
49
+ export { HarnessCapabilityUnsupportedError } from '../src/errors/harness-capability-unsupported-error';
50
+ export {
51
+ createFileReporter,
52
+ createTraceTreeReporter,
53
+ type FileReporter,
54
+ type FileReporterOptions,
55
+ type TraceTreeReporterOptions,
56
+ } from '../src/agent/observability';
@@ -0,0 +1,10 @@
1
+ export { runBridge } from '../src/bridge';
2
+ export type {
3
+ RunBridgeOptions,
4
+ BridgeTurn,
5
+ BridgeEvent,
6
+ BridgeState,
7
+ BridgeHandle,
8
+ BridgeDebugConfig,
9
+ BridgeDebugLevel,
10
+ } from '../src/bridge';