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

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 +87 -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
package/CHANGELOG.md ADDED
@@ -0,0 +1,87 @@
1
+ # @ai-sdk/harness
2
+
3
+ ## 1.0.0-canary.11
4
+
5
+ ### Patch Changes
6
+
7
+ - be83911: fix(harness): reject bridge startup when the WebSocket port cannot be bound
8
+
9
+ ## 1.0.0-canary.10
10
+
11
+ ### Patch Changes
12
+
13
+ - ai@7.0.0-canary.174
14
+
15
+ ## 1.0.0-canary.9
16
+
17
+ ### Patch Changes
18
+
19
+ - ai@7.0.0-canary.173
20
+
21
+ ## 1.0.0-canary.8
22
+
23
+ ### Patch Changes
24
+
25
+ - aae0138: fix(harness): make listening for sandbox bridge readiness compatible with Bun
26
+
27
+ ## 1.0.0-canary.7
28
+
29
+ ### Patch Changes
30
+
31
+ - 3d87086: fix(harness): guard against invalid resuming a session vs continuing a turn
32
+ - 1ea15a3: fix(harness): fix various bugs with harness skills not being correctly processed by the harness adapters
33
+ - Updated dependencies [aeda373]
34
+ - Updated dependencies [25a64f8]
35
+ - Updated dependencies [375fdd7]
36
+ - Updated dependencies [f18b08f]
37
+ - Updated dependencies [b4507d5]
38
+ - @ai-sdk/provider-utils@5.0.0-canary.48
39
+ - ai@7.0.0-canary.172
40
+
41
+ ## 1.0.0-canary.6
42
+
43
+ ### Patch Changes
44
+
45
+ - Updated dependencies [89ad56f]
46
+ - Updated dependencies [f9a496f]
47
+ - Updated dependencies [3295831]
48
+ - ai@7.0.0-canary.171
49
+
50
+ ## 1.0.0-canary.5
51
+
52
+ ### Patch Changes
53
+
54
+ - d77bed4: chore(harness): separate harness spec types (v1) from consumer-facing types
55
+ - Updated dependencies [bae5e2b]
56
+ - Updated dependencies [69d7128]
57
+ - ai@7.0.0-canary.170
58
+ - @ai-sdk/provider-utils@5.0.0-canary.47
59
+
60
+ ## 1.0.0-canary.4
61
+
62
+ ### Patch Changes
63
+
64
+ - 3d9a50c: feat(harness): implement harness adapters for Claude Code, Codex, Pi
65
+
66
+ ## 1.0.0-canary.3
67
+
68
+ ### Patch Changes
69
+
70
+ - 21d3d60: feat(harness): implement harness specification
71
+ - Updated dependencies [a5018ab]
72
+ - Updated dependencies [21d3d60]
73
+ - Updated dependencies [426dbbb]
74
+ - Updated dependencies [7fd3360]
75
+ - ai@7.0.0-canary.169
76
+
77
+ ## 1.0.0-canary.2
78
+
79
+ ### Patch Changes
80
+
81
+ - 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.
82
+
83
+ ## 0.0.0-canary.1
84
+
85
+ ### Major Changes
86
+
87
+ - 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,142 @@
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-sdk/harness
11
+ ```
12
+
13
+ ## Usage
14
+
15
+ ```ts
16
+ import { HarnessAgent } from '@ai-sdk/harness/agent';
17
+ import { createClaudeCode } from '@ai-sdk/harness-claude-code';
18
+ import { createVercelSandbox } from '@ai-sdk/sandbox-vercel';
19
+ import { tool } from 'ai';
20
+ import { z } from 'zod';
21
+
22
+ const agent = new HarnessAgent({
23
+ harness: createClaudeCode(),
24
+ id: 'auth-agent',
25
+ system: 'You are a careful refactoring assistant. Prefer minimal diffs.',
26
+ sandbox: createVercelSandbox({
27
+ runtime: 'node24',
28
+ ports: [4000],
29
+ }),
30
+ onSandboxSession: async ({ session, sessionWorkDir, abortSignal }) => {
31
+ await session.writeTextFile({
32
+ path: `${sessionWorkDir}/README.md`,
33
+ content: 'Workspace notes for this session.',
34
+ abortSignal,
35
+ });
36
+ },
37
+ tools: {
38
+ deploy: tool({
39
+ description: 'Deploy to a target environment',
40
+ inputSchema: z.object({ env: z.enum(['staging', 'production']) }),
41
+ execute: async ({ env }) => ({ url: await deployTo(env) }),
42
+ }),
43
+ },
44
+ harnessOptions: {
45
+ 'claude-code': { thinking: 'adaptive' },
46
+ },
47
+ });
48
+
49
+ const session = await agent.createSession();
50
+
51
+ try {
52
+ const result = await agent.generate({
53
+ session,
54
+ prompt: 'Fix the failing test in src/auth.ts',
55
+ });
56
+ console.log(result.text);
57
+
58
+ // Streaming
59
+ const stream = await agent.stream({
60
+ session,
61
+ prompt: 'Now write a regression test',
62
+ });
63
+ for await (const part of stream.fullStream) {
64
+ if (part.type === 'text-delta') {
65
+ process.stdout.write(part.text);
66
+ }
67
+ }
68
+ } finally {
69
+ await session.destroy();
70
+ }
71
+ ```
72
+
73
+ `sandbox` is a required `HarnessV1SandboxProvider` — the agent calls `provider.createSession()` when a session starts. Use `onSandboxSession` to prepare the acquired sandbox before the harness adapter starts. The hook runs for fresh and resumed sessions, so keep it idempotent. 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 (claude-code, codex) require a provider that exposes ports — `@ai-sdk/sandbox-vercel` is the supported choice today. `@ai-sdk/sandbox-just-bash` is suitable only for non-bridge flows.
74
+
75
+ ### Available harnesses
76
+
77
+ - `@ai-sdk/harness-claude-code`
78
+ - `@ai-sdk/harness-codex`
79
+ - `@ai-sdk/harness-opencode` (WIP)
80
+ - `@ai-sdk/harness-goose` (WIP)
81
+ - `@ai-sdk/harness-mastra` (WIP)
82
+ - `@ai-sdk/harness-deepagents` (WIP)
83
+ - `@ai-sdk/harness-openai-agents` (WIP)
84
+ - `@ai-sdk/harness-pi` (WIP)
85
+
86
+ ## Implementing a harness
87
+
88
+ Implement the `HarnessV1` factory and a `HarnessV1Session` whose `doPrompt` 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.
89
+
90
+ ```ts
91
+ import type { HarnessV1, HarnessV1Session } from '@ai-sdk/harness';
92
+
93
+ export function myHarness(): HarnessV1 {
94
+ return {
95
+ specificationVersion: 'harness-v1',
96
+ harnessId: 'my-harness',
97
+ builtinTools: [],
98
+ doStart: async startOpts => {
99
+ const session: HarnessV1Session = {
100
+ sessionId: startOpts.sessionId,
101
+ isResume: false,
102
+ doPromptTurn: async promptOpts => {
103
+ promptOpts.emit({ type: 'text-start', id: 't' });
104
+ promptOpts.emit({ type: 'text-delta', id: 't', delta: 'Hello.' });
105
+ promptOpts.emit({ type: 'text-end', id: 't' });
106
+ promptOpts.emit({
107
+ type: 'finish',
108
+ finishReason: { unified: 'stop', raw: 'stop' },
109
+ totalUsage: {
110
+ inputTokens: {
111
+ total: 0,
112
+ noCache: 0,
113
+ cacheRead: undefined,
114
+ cacheWrite: undefined,
115
+ },
116
+ outputTokens: { total: 0, text: 0, reasoning: undefined },
117
+ },
118
+ });
119
+ return { submitToolResult: async () => {}, done: Promise.resolve() };
120
+ },
121
+ doContinueTurn: async () => ({
122
+ submitToolResult: async () => {},
123
+ done: Promise.resolve(),
124
+ }),
125
+ doCompact: async () => {},
126
+ doStop: async () => ({
127
+ harnessId: 'my-harness',
128
+ specificationVersion: 'harness-v1',
129
+ data: {},
130
+ }),
131
+ doDestroy: async () => {},
132
+ doSuspendTurn: async () => ({
133
+ harnessId: 'my-harness',
134
+ specificationVersion: 'harness-v1',
135
+ data: {},
136
+ }),
137
+ };
138
+ return session;
139
+ },
140
+ };
141
+ }
142
+ ```
package/agent/index.ts ADDED
@@ -0,0 +1,47 @@
1
+ export { HarnessAgent } from '../src/agent/harness-agent';
2
+ export type {
3
+ HarnessAgentSettings,
4
+ HarnessAgentToolApprovalConfiguration,
5
+ } from '../src/agent/harness-agent-settings';
6
+ export type {
7
+ HarnessAgentAdapter,
8
+ HarnessAgentAdapterSession,
9
+ HarnessAgentBuiltinTool,
10
+ HarnessAgentBuiltinToolName,
11
+ HarnessAgentBuiltinTools,
12
+ HarnessAgentBuiltinToolUseKind,
13
+ HarnessAgentContinueTurnOptions,
14
+ HarnessAgentContinueTurnState,
15
+ HarnessAgentLifecycleState,
16
+ HarnessAgentPendingToolApproval,
17
+ HarnessAgentPermissionMode,
18
+ HarnessAgentPrompt,
19
+ HarnessAgentPromptControl,
20
+ HarnessAgentPromptTurnOptions,
21
+ HarnessAgentResumeSessionState,
22
+ HarnessAgentSkill,
23
+ HarnessAgentStartOptions,
24
+ HarnessAgentStreamPart,
25
+ HarnessAgentToolSpec,
26
+ } from '../src/agent/harness-agent-types';
27
+ export { HarnessAgentSession } from '../src/agent/harness-agent-session';
28
+ export {
29
+ collectHarnessAgentToolApprovalContinuations,
30
+ type HarnessAgentToolApprovalContinuation,
31
+ } from '../src/agent/harness-agent-tool-approval-continuation';
32
+ export { prewarmHarness } from '../src/agent/prewarm';
33
+ export type {
34
+ HarnessDebugConfig,
35
+ HarnessDebugLevel,
36
+ HarnessDiagnostic,
37
+ HarnessDiagnosticConsumer,
38
+ } from '../src/agent/observability/types';
39
+ export { HarnessError } from '../src/errors/harness-error';
40
+ export { HarnessCapabilityUnsupportedError } from '../src/errors/harness-capability-unsupported-error';
41
+ export {
42
+ createFileReporter,
43
+ createTraceTreeReporter,
44
+ type FileReporter,
45
+ type FileReporterOptions,
46
+ type TraceTreeReporterOptions,
47
+ } 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';