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

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 +81 -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 +414 -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 +700 -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,81 @@
1
+ # @ai-sdk/harness
2
+
3
+ ## 1.0.0-canary.10
4
+
5
+ ### Patch Changes
6
+
7
+ - ai@7.0.0-canary.174
8
+
9
+ ## 1.0.0-canary.9
10
+
11
+ ### Patch Changes
12
+
13
+ - ai@7.0.0-canary.173
14
+
15
+ ## 1.0.0-canary.8
16
+
17
+ ### Patch Changes
18
+
19
+ - aae0138: fix(harness): make listening for sandbox bridge readiness compatible with Bun
20
+
21
+ ## 1.0.0-canary.7
22
+
23
+ ### Patch Changes
24
+
25
+ - 3d87086: fix(harness): guard against invalid resuming a session vs continuing a turn
26
+ - 1ea15a3: fix(harness): fix various bugs with harness skills not being correctly processed by the harness adapters
27
+ - Updated dependencies [aeda373]
28
+ - Updated dependencies [25a64f8]
29
+ - Updated dependencies [375fdd7]
30
+ - Updated dependencies [f18b08f]
31
+ - Updated dependencies [b4507d5]
32
+ - @ai-sdk/provider-utils@5.0.0-canary.48
33
+ - ai@7.0.0-canary.172
34
+
35
+ ## 1.0.0-canary.6
36
+
37
+ ### Patch Changes
38
+
39
+ - Updated dependencies [89ad56f]
40
+ - Updated dependencies [f9a496f]
41
+ - Updated dependencies [3295831]
42
+ - ai@7.0.0-canary.171
43
+
44
+ ## 1.0.0-canary.5
45
+
46
+ ### Patch Changes
47
+
48
+ - d77bed4: chore(harness): separate harness spec types (v1) from consumer-facing types
49
+ - Updated dependencies [bae5e2b]
50
+ - Updated dependencies [69d7128]
51
+ - ai@7.0.0-canary.170
52
+ - @ai-sdk/provider-utils@5.0.0-canary.47
53
+
54
+ ## 1.0.0-canary.4
55
+
56
+ ### Patch Changes
57
+
58
+ - 3d9a50c: feat(harness): implement harness adapters for Claude Code, Codex, Pi
59
+
60
+ ## 1.0.0-canary.3
61
+
62
+ ### Patch Changes
63
+
64
+ - 21d3d60: feat(harness): implement harness specification
65
+ - Updated dependencies [a5018ab]
66
+ - Updated dependencies [21d3d60]
67
+ - Updated dependencies [426dbbb]
68
+ - Updated dependencies [7fd3360]
69
+ - ai@7.0.0-canary.169
70
+
71
+ ## 1.0.0-canary.2
72
+
73
+ ### Patch Changes
74
+
75
+ - 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.
76
+
77
+ ## 0.0.0-canary.1
78
+
79
+ ### Major Changes
80
+
81
+ - 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';