@ai-sdk/harness 0.0.0-07500555-20260730161446

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 (78) hide show
  1. package/CHANGELOG.md +531 -0
  2. package/LICENSE +13 -0
  3. package/README.md +176 -0
  4. package/agent/index.ts +61 -0
  5. package/bridge/index.ts +10 -0
  6. package/dist/agent/index.d.ts +1678 -0
  7. package/dist/agent/index.js +3789 -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 +489 -0
  11. package/dist/bridge/index.js.map +1 -0
  12. package/dist/index.d.ts +1597 -0
  13. package/dist/index.js +517 -0
  14. package/dist/index.js.map +1 -0
  15. package/dist/utils/index.d.ts +333 -0
  16. package/dist/utils/index.js +1273 -0
  17. package/dist/utils/index.js.map +1 -0
  18. package/package.json +100 -0
  19. package/src/agent/harness-agent-session.ts +594 -0
  20. package/src/agent/harness-agent-settings.ts +211 -0
  21. package/src/agent/harness-agent-tool-approval-continuation.ts +94 -0
  22. package/src/agent/harness-agent-tool-result-continuation.ts +62 -0
  23. package/src/agent/harness-agent-tool-types.ts +15 -0
  24. package/src/agent/harness-agent-types.ts +52 -0
  25. package/src/agent/harness-agent.ts +901 -0
  26. package/src/agent/internal/bootstrap-recipe.ts +124 -0
  27. package/src/agent/internal/bridge-port-registry.ts +52 -0
  28. package/src/agent/internal/harness-stream-text-result.ts +783 -0
  29. package/src/agent/internal/lifecycle-state-validation.ts +108 -0
  30. package/src/agent/internal/permission-mode.ts +50 -0
  31. package/src/agent/internal/resolve-observability.ts +128 -0
  32. package/src/agent/internal/run-prompt.ts +1101 -0
  33. package/src/agent/internal/sandbox-bootstrap.ts +266 -0
  34. package/src/agent/internal/strip-work-dir.ts +68 -0
  35. package/src/agent/internal/to-harness-stream.ts +75 -0
  36. package/src/agent/internal/tool-filtering.ts +114 -0
  37. package/src/agent/internal/translate-stream-part.ts +222 -0
  38. package/src/agent/internal/turn-telemetry.ts +361 -0
  39. package/src/agent/observability/file-reporter.ts +206 -0
  40. package/src/agent/observability/index.ts +15 -0
  41. package/src/agent/observability/trace-tree-reporter.ts +122 -0
  42. package/src/agent/observability/types.ts +86 -0
  43. package/src/agent/prepare-harness-sandbox-template.ts +68 -0
  44. package/src/agent/prepare-sandbox-for-harness.ts +165 -0
  45. package/src/bridge/index.ts +807 -0
  46. package/src/errors/harness-capability-unsupported-error.ts +41 -0
  47. package/src/errors/harness-error.ts +22 -0
  48. package/src/index.ts +3 -0
  49. package/src/utils/ai-gateway-auth.ts +15 -0
  50. package/src/utils/bridge-diagnostics.ts +213 -0
  51. package/src/utils/bridge-ready.ts +277 -0
  52. package/src/utils/classify-disk-log.ts +43 -0
  53. package/src/utils/index.ts +31 -0
  54. package/src/utils/sandbox-channel.ts +583 -0
  55. package/src/utils/sandbox-home-dir.ts +22 -0
  56. package/src/utils/shell-quote.ts +3 -0
  57. package/src/utils/write-skills.ts +141 -0
  58. package/src/v1/harness-v1-bootstrap.ts +46 -0
  59. package/src/v1/harness-v1-bridge-protocol.ts +342 -0
  60. package/src/v1/harness-v1-builtin-tool.ts +138 -0
  61. package/src/v1/harness-v1-call-warning.ts +22 -0
  62. package/src/v1/harness-v1-diagnostic.ts +66 -0
  63. package/src/v1/harness-v1-lifecycle-state.ts +77 -0
  64. package/src/v1/harness-v1-metadata.ts +13 -0
  65. package/src/v1/harness-v1-network-sandbox-session.ts +123 -0
  66. package/src/v1/harness-v1-observability.ts +20 -0
  67. package/src/v1/harness-v1-permission-mode.ts +11 -0
  68. package/src/v1/harness-v1-prompt-control.ts +41 -0
  69. package/src/v1/harness-v1-prompt.ts +11 -0
  70. package/src/v1/harness-v1-sandbox-provider.ts +76 -0
  71. package/src/v1/harness-v1-session.ts +280 -0
  72. package/src/v1/harness-v1-skill.ts +36 -0
  73. package/src/v1/harness-v1-stream-part.ts +363 -0
  74. package/src/v1/harness-v1-tool-filtering.ts +25 -0
  75. package/src/v1/harness-v1-tool-spec.ts +31 -0
  76. package/src/v1/harness-v1.ts +94 -0
  77. package/src/v1/index.ts +100 -0
  78. package/utils/index.ts +1 -0
package/CHANGELOG.md ADDED
@@ -0,0 +1,531 @@
1
+ # @ai-sdk/harness
2
+
3
+ ## 0.0.0-07500555-20260730161446
4
+
5
+ ### Patch Changes
6
+
7
+ - 5f65e61: feat(harness): add support for `stopWhen` control to `HarnessAgent` (e.g. `isStepCount(1)`)
8
+ - Updated dependencies [589d87c]
9
+ - Updated dependencies [7f6650b]
10
+ - Updated dependencies [106ea59]
11
+ - @ai-sdk/provider@0.0.0-07500555-20260730161446
12
+ - ai@0.0.0-07500555-20260730161446
13
+ - @ai-sdk/provider-utils@0.0.0-07500555-20260730161446
14
+
15
+ ## 1.0.39
16
+
17
+ ### Patch Changes
18
+
19
+ - 86a84c9: fix(harness): settle a turn aborted by the caller's abortSignal with an `abort` stream part instead of an AbortError `error` part, matching `streamText`'s abort contract
20
+ - ai@7.0.34
21
+
22
+ ## 1.0.38
23
+
24
+ ### Patch Changes
25
+
26
+ - Updated dependencies [02ffdcb]
27
+ - Updated dependencies [76cb673]
28
+ - Updated dependencies [e808fa5]
29
+ - Updated dependencies [33647d7]
30
+ - @ai-sdk/provider-utils@5.0.12
31
+ - ai@7.0.33
32
+
33
+ ## 1.0.37
34
+
35
+ ### Patch Changes
36
+
37
+ - b460541: fix(harness): properly support client-side / host-side tools and handle unfinished turn semantics
38
+ - 079591e: fix (harness): emit the message-level `start` part on HarnessAgent streams so `toUIMessageStream` persistence mode can inject the response message id
39
+ - Updated dependencies [6cd7c74]
40
+ - Updated dependencies [e35bcae]
41
+ - Updated dependencies [a4eb3f3]
42
+ - ai@7.0.32
43
+
44
+ ## 1.0.36
45
+
46
+ ### Patch Changes
47
+
48
+ - Updated dependencies [70f18c3]
49
+ - Updated dependencies [cd06458]
50
+ - ai@7.0.31
51
+ - @ai-sdk/provider-utils@5.0.11
52
+
53
+ ## 1.0.35
54
+
55
+ ### Patch Changes
56
+
57
+ - ai@7.0.30
58
+
59
+ ## 1.0.34
60
+
61
+ ### Patch Changes
62
+
63
+ - ai@7.0.29
64
+
65
+ ## 1.0.33
66
+
67
+ ### Patch Changes
68
+
69
+ - Updated dependencies [0bc8d4f]
70
+ - ai@7.0.28
71
+
72
+ ## 1.0.32
73
+
74
+ ### Patch Changes
75
+
76
+ - Updated dependencies [ac01b79]
77
+ - Updated dependencies [31c7be8]
78
+ - Updated dependencies [2696562]
79
+ - ai@7.0.27
80
+ - @ai-sdk/provider-utils@5.0.10
81
+
82
+ ## 1.0.31
83
+
84
+ ### Patch Changes
85
+
86
+ - Updated dependencies [27d294d]
87
+ - ai@7.0.26
88
+
89
+ ## 1.0.30
90
+
91
+ ### Patch Changes
92
+
93
+ - Updated dependencies [4be62c1]
94
+ - Updated dependencies [7805e4a]
95
+ - Updated dependencies [7805e4a]
96
+ - Updated dependencies [f8e82fd]
97
+ - Updated dependencies [cd12954]
98
+ - @ai-sdk/provider-utils@5.0.9
99
+ - ai@7.0.25
100
+
101
+ ## 1.0.29
102
+
103
+ ### Patch Changes
104
+
105
+ - Updated dependencies [e193290]
106
+ - Updated dependencies [e193290]
107
+ - @ai-sdk/provider-utils@5.0.8
108
+ - ai@7.0.24
109
+
110
+ ## 1.0.28
111
+
112
+ ### Patch Changes
113
+
114
+ - Updated dependencies [930f949]
115
+ - ai@7.0.23
116
+
117
+ ## 1.0.27
118
+
119
+ ### Patch Changes
120
+
121
+ - Updated dependencies [8f89c25]
122
+ - ai@7.0.22
123
+
124
+ ## 1.0.26
125
+
126
+ ### Patch Changes
127
+
128
+ - Updated dependencies [308a519]
129
+ - ai@7.0.21
130
+
131
+ ## 1.0.25
132
+
133
+ ### Patch Changes
134
+
135
+ - 44e988a: fix(harness): fix harness tool approval regression
136
+
137
+ ## 1.0.24
138
+
139
+ ### Patch Changes
140
+
141
+ - Updated dependencies [b9ac19f]
142
+ - Updated dependencies [a4186d6]
143
+ - ai@7.0.20
144
+
145
+ ## 1.0.23
146
+
147
+ ### Patch Changes
148
+
149
+ - 39c8276: fix(harness): improve opaque sandbox bridge error handling
150
+ - 91fe6d8: fix(harness): emit `finish-step` stream parts correctly per the underlying model steps
151
+ - 0be5014: fix(harness): fix obsolete portions of harness package readme
152
+
153
+ ## 1.0.22
154
+
155
+ ### Patch Changes
156
+
157
+ - Updated dependencies [be7f05a]
158
+ - Updated dependencies [ee55a07]
159
+ - Updated dependencies [aad737d]
160
+ - Updated dependencies [0f93c57]
161
+ - ai@7.0.19
162
+ - @ai-sdk/provider@4.0.3
163
+ - @ai-sdk/provider-utils@5.0.7
164
+
165
+ ## 1.0.21
166
+
167
+ ### Patch Changes
168
+
169
+ - Updated dependencies [ac306ed]
170
+ - @ai-sdk/provider-utils@5.0.6
171
+ - ai@7.0.18
172
+
173
+ ## 1.0.20
174
+
175
+ ### Patch Changes
176
+
177
+ - b7aa06a: fix(harness): include step numbers on harness step-end telemetry events.
178
+ - ai@7.0.17
179
+
180
+ ## 1.0.19
181
+
182
+ ### Patch Changes
183
+
184
+ - Updated dependencies [a8f9b6d]
185
+ - ai@7.0.16
186
+
187
+ ## 1.0.18
188
+
189
+ ### Patch Changes
190
+
191
+ - ai@7.0.15
192
+
193
+ ## 1.0.17
194
+
195
+ ### Patch Changes
196
+
197
+ - 5c5c0f5: Add experimental streaming transcription support for transcription models, including OpenAI `gpt-realtime-whisper` and xAI WebSocket STT.
198
+ - Updated dependencies [5c5c0f5]
199
+ - ai@7.0.14
200
+ - @ai-sdk/provider@4.0.2
201
+ - @ai-sdk/provider-utils@5.0.5
202
+
203
+ ## 1.0.16
204
+
205
+ ### Patch Changes
206
+
207
+ - ai@7.0.13
208
+
209
+ ## 1.0.15
210
+
211
+ ### Patch Changes
212
+
213
+ - Updated dependencies [ecfeb6f]
214
+ - Updated dependencies [a193137]
215
+ - Updated dependencies [c6f5e62]
216
+ - ai@7.0.12
217
+ - @ai-sdk/provider-utils@5.0.4
218
+
219
+ ## 1.0.14
220
+
221
+ ### Patch Changes
222
+
223
+ - Updated dependencies [0a87626]
224
+ - ai@7.0.11
225
+
226
+ ## 1.0.13
227
+
228
+ ### Patch Changes
229
+
230
+ - Updated dependencies [8c616f0]
231
+ - ai@7.0.10
232
+ - @ai-sdk/provider-utils@5.0.3
233
+
234
+ ## 1.0.12
235
+
236
+ ### Patch Changes
237
+
238
+ - 7859cea: feat(harness): add tool filtering via `activeTools` and `inactiveTools`
239
+ - c857346: feat(harness): add utility functions for certain duplicated layers in harnesses
240
+
241
+ ## 1.0.11
242
+
243
+ ### Patch Changes
244
+
245
+ - ai@7.0.9
246
+
247
+ ## 1.0.10
248
+
249
+ ### Patch Changes
250
+
251
+ - Updated dependencies [0274f34]
252
+ - @ai-sdk/provider@4.0.1
253
+ - ai@7.0.8
254
+ - @ai-sdk/provider-utils@5.0.2
255
+
256
+ ## 1.0.9
257
+
258
+ ### Patch Changes
259
+
260
+ - Updated dependencies [d598481]
261
+ - ai@7.0.7
262
+
263
+ ## 1.0.8
264
+
265
+ ### Patch Changes
266
+
267
+ - Updated dependencies [989402d]
268
+ - ai@7.0.6
269
+
270
+ ## 1.0.7
271
+
272
+ ### Patch Changes
273
+
274
+ - Updated dependencies [a2750db]
275
+ - ai@7.0.5
276
+
277
+ ## 1.0.6
278
+
279
+ ### Patch Changes
280
+
281
+ - Updated dependencies [6a436e3]
282
+ - @ai-sdk/provider-utils@5.0.1
283
+ - ai@7.0.4
284
+
285
+ ## 1.0.5
286
+
287
+ ### Patch Changes
288
+
289
+ - ai@7.0.3
290
+
291
+ ## 1.0.4
292
+
293
+ ### Patch Changes
294
+
295
+ - c493634: fix(harness): fix harness Zod usage to be v3/v4 compatible
296
+
297
+ ## 1.0.3
298
+
299
+ ### Patch Changes
300
+
301
+ - 51d10a0: feat(harness): add `prepareSandboxForHarness` utility to prepare a caller-owned sandbox for one or more harnesses
302
+
303
+ ## 1.0.2
304
+
305
+ ### Patch Changes
306
+
307
+ - ai@7.0.2
308
+
309
+ ## 1.0.1
310
+
311
+ ### Patch Changes
312
+
313
+ - ai@7.0.1
314
+
315
+ ## 1.0.0
316
+
317
+ ### Major Changes
318
+
319
+ - 9d6dbe0: feat(harness): add sandbox specific expansion for harness abstraction, add `sandbox-just-bash` and `sandbox-vercel`
320
+
321
+ ### Patch Changes
322
+
323
+ - e5d4a24: chore(harness): update ws package
324
+ - aae0138: fix(harness): make listening for sandbox bridge readiness compatible with Bun
325
+ - be83911: fix(harness): reject bridge startup when the WebSocket port cannot be bound
326
+ - 3d87086: fix(harness): guard against invalid resuming a session vs continuing a turn
327
+ - d77bed4: chore(harness): separate harness spec types (v1) from consumer-facing types
328
+ - 21d3d60: feat(harness): implement harness specification
329
+ - 3d9a50c: feat(harness): implement harness adapters for Claude Code, Codex, Pi
330
+ - 57e0a59: fix(harness): ensure finish chunk's total usage is actually coming from total usage
331
+ - 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.
332
+ - 1ea15a3: fix(harness): fix various bugs with harness skills not being correctly processed by the harness adapters
333
+ - a83a367: feat(harness): allow pre-snapshot `sandboxConfig.onBootstrap` callback in `HarnessAgent`
334
+ - b8396f0: trigger initial beta release
335
+ - 534dac6: fix(harness): fix incomplete OIDC token support for AI Gateway auth in harness adapters
336
+
337
+ ## 1.0.0-beta.27
338
+
339
+ ### Patch Changes
340
+
341
+ - ai@7.0.0-beta.187
342
+
343
+ ## 1.0.0-beta.26
344
+
345
+ ### Patch Changes
346
+
347
+ - a83a367: feat(harness): allow pre-snapshot `sandboxConfig.onBootstrap` callback in `HarnessAgent`
348
+
349
+ ## 1.0.0-beta.25
350
+
351
+ ### Patch Changes
352
+
353
+ - ai@7.0.0-beta.186
354
+
355
+ ## 1.0.0-beta.24
356
+
357
+ ### Patch Changes
358
+
359
+ - Updated dependencies [75763b0]
360
+ - ai@7.0.0-beta.185
361
+
362
+ ## 1.0.0-beta.23
363
+
364
+ ### Patch Changes
365
+
366
+ - 57e0a59: fix(harness): ensure finish chunk's total usage is actually coming from total usage
367
+
368
+ ## 1.0.0-beta.22
369
+
370
+ ### Patch Changes
371
+
372
+ - Updated dependencies [0416e3e]
373
+ - @ai-sdk/provider@4.0.0-beta.20
374
+ - ai@7.0.0-beta.184
375
+ - @ai-sdk/provider-utils@5.0.0-beta.50
376
+
377
+ ## 1.0.0-beta.21
378
+
379
+ ### Patch Changes
380
+
381
+ - ai@7.0.0-beta.183
382
+
383
+ ## 1.0.0-beta.20
384
+
385
+ ### Patch Changes
386
+
387
+ - e5d4a24: chore(harness): update ws package
388
+ - Updated dependencies [cc6ab90]
389
+ - ai@7.0.0-beta.182
390
+
391
+ ## 1.0.0-beta.19
392
+
393
+ ### Patch Changes
394
+
395
+ - Updated dependencies [6a2caf9]
396
+ - ai@7.0.0-beta.181
397
+
398
+ ## 1.0.0-beta.18
399
+
400
+ ### Patch Changes
401
+
402
+ - Updated dependencies [81a284b]
403
+ - ai@7.0.0-beta.180
404
+
405
+ ## 1.0.0-beta.17
406
+
407
+ ### Patch Changes
408
+
409
+ - 534dac6: fix(harness): fix incomplete OIDC token support for AI Gateway auth in harness adapters
410
+
411
+ ## 1.0.0-beta.16
412
+
413
+ ### Patch Changes
414
+
415
+ - ai@7.0.0-beta.179
416
+
417
+ ## 1.0.0-beta.15
418
+
419
+ ### Patch Changes
420
+
421
+ - Updated dependencies [b097c52]
422
+ - ai@7.0.0-beta.178
423
+
424
+ ## 1.0.0-beta.14
425
+
426
+ ### Patch Changes
427
+
428
+ - b8396f0: trigger initial beta release
429
+ - Updated dependencies [b8396f0]
430
+ - @ai-sdk/provider-utils@5.0.0-beta.49
431
+ - @ai-sdk/provider@4.0.0-beta.19
432
+ - ai@7.0.0-beta.177
433
+
434
+ ## 1.0.0-canary.13
435
+
436
+ ### Patch Changes
437
+
438
+ - ai@7.0.0-canary.176
439
+
440
+ ## 1.0.0-canary.12
441
+
442
+ ### Patch Changes
443
+
444
+ - Updated dependencies [6ec57f5]
445
+ - ai@7.0.0-canary.175
446
+
447
+ ## 1.0.0-canary.11
448
+
449
+ ### Patch Changes
450
+
451
+ - be83911: fix(harness): reject bridge startup when the WebSocket port cannot be bound
452
+
453
+ ## 1.0.0-canary.10
454
+
455
+ ### Patch Changes
456
+
457
+ - ai@7.0.0-canary.174
458
+
459
+ ## 1.0.0-canary.9
460
+
461
+ ### Patch Changes
462
+
463
+ - ai@7.0.0-canary.173
464
+
465
+ ## 1.0.0-canary.8
466
+
467
+ ### Patch Changes
468
+
469
+ - aae0138: fix(harness): make listening for sandbox bridge readiness compatible with Bun
470
+
471
+ ## 1.0.0-canary.7
472
+
473
+ ### Patch Changes
474
+
475
+ - 3d87086: fix(harness): guard against invalid resuming a session vs continuing a turn
476
+ - 1ea15a3: fix(harness): fix various bugs with harness skills not being correctly processed by the harness adapters
477
+ - Updated dependencies [aeda373]
478
+ - Updated dependencies [25a64f8]
479
+ - Updated dependencies [375fdd7]
480
+ - Updated dependencies [f18b08f]
481
+ - Updated dependencies [b4507d5]
482
+ - @ai-sdk/provider-utils@5.0.0-canary.48
483
+ - ai@7.0.0-canary.172
484
+
485
+ ## 1.0.0-canary.6
486
+
487
+ ### Patch Changes
488
+
489
+ - Updated dependencies [89ad56f]
490
+ - Updated dependencies [f9a496f]
491
+ - Updated dependencies [3295831]
492
+ - ai@7.0.0-canary.171
493
+
494
+ ## 1.0.0-canary.5
495
+
496
+ ### Patch Changes
497
+
498
+ - d77bed4: chore(harness): separate harness spec types (v1) from consumer-facing types
499
+ - Updated dependencies [bae5e2b]
500
+ - Updated dependencies [69d7128]
501
+ - ai@7.0.0-canary.170
502
+ - @ai-sdk/provider-utils@5.0.0-canary.47
503
+
504
+ ## 1.0.0-canary.4
505
+
506
+ ### Patch Changes
507
+
508
+ - 3d9a50c: feat(harness): implement harness adapters for Claude Code, Codex, Pi
509
+
510
+ ## 1.0.0-canary.3
511
+
512
+ ### Patch Changes
513
+
514
+ - 21d3d60: feat(harness): implement harness specification
515
+ - Updated dependencies [a5018ab]
516
+ - Updated dependencies [21d3d60]
517
+ - Updated dependencies [426dbbb]
518
+ - Updated dependencies [7fd3360]
519
+ - ai@7.0.0-canary.169
520
+
521
+ ## 1.0.0-canary.2
522
+
523
+ ### Patch Changes
524
+
525
+ - 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.
526
+
527
+ ## 0.0.0-canary.1
528
+
529
+ ### Major Changes
530
+
531
+ - 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
+ ```