@ai-sdk/harness 1.0.0-canary.2 → 1.0.0-canary.4
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.
- package/CHANGELOG.md +17 -0
- package/README.md +130 -3
- package/agent/index.ts +17 -0
- package/bridge/index.ts +10 -0
- package/dist/agent/index.d.ts +1500 -0
- package/dist/agent/index.js +2580 -0
- package/dist/agent/index.js.map +1 -0
- package/dist/bridge/index.d.ts +111 -0
- package/dist/bridge/index.js +414 -0
- package/dist/bridge/index.js.map +1 -0
- package/dist/index.d.ts +1337 -33
- package/dist/index.js +15801 -9
- package/dist/index.js.map +1 -1
- package/dist/observability/index.d.ts +97 -0
- package/dist/observability/index.js +225 -0
- package/dist/observability/index.js.map +1 -0
- package/dist/utils/index.d.ts +196 -0
- package/dist/utils/index.js +327 -0
- package/dist/utils/index.js.map +1 -0
- package/package.json +44 -4
- package/src/agent/harness-agent-session.ts +358 -0
- package/src/agent/harness-agent-settings.ts +131 -0
- package/src/agent/harness-agent-tool-approval-continuation.ts +94 -0
- package/src/agent/harness-agent.ts +778 -0
- package/src/agent/harness-diagnostics.ts +88 -0
- package/src/agent/internal/bootstrap-recipe.ts +124 -0
- package/src/agent/internal/bridge-port-registry.ts +52 -0
- package/src/agent/internal/harness-stream-text-result.ts +720 -0
- package/src/agent/internal/lifecycle-state-validation.ts +61 -0
- package/src/agent/internal/permission-mode.ts +50 -0
- package/src/agent/internal/resolve-observability.ts +128 -0
- package/src/agent/internal/run-prompt.ts +811 -0
- package/src/agent/internal/strip-work-dir.ts +68 -0
- package/src/agent/internal/to-harness-stream.ts +75 -0
- package/src/agent/internal/translate-stream-part.ts +221 -0
- package/src/agent/internal/turn-telemetry.ts +359 -0
- package/src/agent/prewarm.ts +46 -0
- package/src/bridge/index.ts +700 -0
- package/src/index.ts +1 -5
- package/src/observability/file-reporter.ts +209 -0
- package/src/observability/index.ts +13 -0
- package/src/observability/trace-tree-reporter.ts +122 -0
- package/src/utils/classify-disk-log.ts +43 -0
- package/src/utils/index.ts +7 -0
- package/src/utils/sandbox-channel.ts +453 -0
- package/src/v1/harness-v1-bootstrap.ts +46 -0
- package/src/v1/harness-v1-bridge-protocol.ts +310 -0
- package/src/v1/harness-v1-builtin-tool.ts +138 -0
- package/src/v1/harness-v1-call-warning.ts +22 -0
- package/src/v1/harness-v1-diagnostic.ts +66 -0
- package/src/v1/harness-v1-lifecycle-state.ts +59 -0
- package/src/v1/harness-v1-metadata.ts +13 -0
- package/src/v1/harness-v1-network-sandbox-session.ts +1 -1
- package/src/v1/harness-v1-observability.ts +20 -0
- package/src/v1/harness-v1-permission-mode.ts +11 -0
- package/src/v1/harness-v1-prompt-control.ts +41 -0
- package/src/v1/harness-v1-prompt.ts +11 -0
- package/src/v1/harness-v1-session.ts +278 -0
- package/src/v1/harness-v1-skill.ts +22 -0
- package/src/v1/harness-v1-stream-part.ts +363 -0
- package/src/v1/harness-v1-tool-spec.ts +31 -0
- package/src/v1/harness-v1.ts +83 -0
- package/src/v1/index.ts +95 -0
- package/utils/index.ts +1 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,22 @@
|
|
|
1
1
|
# @ai-sdk/harness
|
|
2
2
|
|
|
3
|
+
## 1.0.0-canary.4
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 3d9a50c: feat(harness): implement harness adapters for Claude Code, Codex, Pi
|
|
8
|
+
|
|
9
|
+
## 1.0.0-canary.3
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- 21d3d60: feat(harness): implement harness specification
|
|
14
|
+
- Updated dependencies [a5018ab]
|
|
15
|
+
- Updated dependencies [21d3d60]
|
|
16
|
+
- Updated dependencies [426dbbb]
|
|
17
|
+
- Updated dependencies [7fd3360]
|
|
18
|
+
- ai@7.0.0-canary.169
|
|
19
|
+
|
|
3
20
|
## 1.0.0-canary.2
|
|
4
21
|
|
|
5
22
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
# AI SDK - Harness
|
|
1
|
+
# AI SDK - Harness Specification and Agent
|
|
2
2
|
|
|
3
3
|
_This package is **experimental**._
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
`HarnessAgent` implementation plus the underlying harness specification, including an expanded network session sandbox interface to support harness sandbox needs.
|
|
6
6
|
|
|
7
7
|
## Setup
|
|
8
8
|
|
|
@@ -12,4 +12,131 @@ npm i @ai-sdk/harness
|
|
|
12
12
|
|
|
13
13
|
## Usage
|
|
14
14
|
|
|
15
|
-
|
|
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,17 @@
|
|
|
1
|
+
export { HarnessAgent } from '../src/agent/harness-agent';
|
|
2
|
+
export type {
|
|
3
|
+
HarnessAgentSettings,
|
|
4
|
+
HarnessAgentToolApprovalConfiguration,
|
|
5
|
+
} from '../src/agent/harness-agent-settings';
|
|
6
|
+
export { HarnessAgentSession } from '../src/agent/harness-agent-session';
|
|
7
|
+
export {
|
|
8
|
+
collectHarnessAgentToolApprovalContinuations,
|
|
9
|
+
type HarnessAgentToolApprovalContinuation,
|
|
10
|
+
} from '../src/agent/harness-agent-tool-approval-continuation';
|
|
11
|
+
export { prewarmHarness } from '../src/agent/prewarm';
|
|
12
|
+
export type {
|
|
13
|
+
HarnessDebugConfig,
|
|
14
|
+
HarnessDebugLevel,
|
|
15
|
+
HarnessDiagnostic,
|
|
16
|
+
HarnessDiagnosticConsumer,
|
|
17
|
+
} from '../src/agent/harness-diagnostics';
|