@ai-sdk/harness-claude-code 1.0.181 → 1.0.184
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 +31 -0
- package/dist/bridge/index.mjs +90 -13
- package/dist/bridge/index.mjs.map +1 -1
- package/dist/bridge/package.json +3 -3
- package/dist/bridge/pnpm-lockfile.yaml +146 -141
- package/dist/index.d.ts +89 -82
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +24 -17
- package/dist/index.js.map +1 -1
- package/package.json +6 -6
- package/src/bridge/create-emit-stream-event.ts +20 -0
- package/src/bridge/index.ts +32 -20
- package/src/bridge/package.json +3 -3
- package/src/claude-code-bridge-protocol.ts +1 -0
- package/src/claude-code-harness.ts +36 -21
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,36 @@
|
|
|
1
1
|
# @ai-sdk/harness-claude-code
|
|
2
2
|
|
|
3
|
+
## 1.0.184
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 5c3842f: feat(harness-claude-code): add opt-in auto permission mode with host approval for classifier escalations and raw effective permission-mode reporting.
|
|
8
|
+
- Updated dependencies [4311fa1]
|
|
9
|
+
- Updated dependencies [4311fa1]
|
|
10
|
+
- @ai-sdk/provider-utils@5.0.79
|
|
11
|
+
- @ai-sdk/harness@1.0.180
|
|
12
|
+
|
|
13
|
+
## 1.0.183
|
|
14
|
+
|
|
15
|
+
### Patch Changes
|
|
16
|
+
|
|
17
|
+
- 0fc1f13: chore(harness): update harness adapter underlying SDKs to their latest releases
|
|
18
|
+
- c849d37: feat(harness): use public-key cryptography instead of token for sandbox bridge communication
|
|
19
|
+
- fcd763a: fix(harness-claude-code): fix incorrect low-level property being passed to Claude Agent SDK
|
|
20
|
+
- Updated dependencies [c849d37]
|
|
21
|
+
- Updated dependencies [7f1c01e]
|
|
22
|
+
- Updated dependencies [88b9575]
|
|
23
|
+
- @ai-sdk/harness@1.0.179
|
|
24
|
+
- @ai-sdk/provider-utils@5.0.78
|
|
25
|
+
|
|
26
|
+
## 1.0.182
|
|
27
|
+
|
|
28
|
+
### Patch Changes
|
|
29
|
+
|
|
30
|
+
- Updated dependencies [9f37b45]
|
|
31
|
+
- @ai-sdk/provider-utils@5.0.77
|
|
32
|
+
- @ai-sdk/harness@1.0.178
|
|
33
|
+
|
|
3
34
|
## 1.0.181
|
|
4
35
|
|
|
5
36
|
### Patch Changes
|
package/dist/bridge/index.mjs
CHANGED
|
@@ -1,14 +1,76 @@
|
|
|
1
1
|
import { appendFile, lstat, mkdir, realpath, writeFile } from "node:fs/promises";
|
|
2
2
|
import { existsSync, readFileSync } from "node:fs";
|
|
3
|
-
import { randomUUID } from "node:crypto";
|
|
3
|
+
import { createPublicKey, randomBytes, randomUUID, verify } from "node:crypto";
|
|
4
4
|
import { argv, env, pid, stdout } from "node:process";
|
|
5
5
|
import { WebSocketServer } from "ws";
|
|
6
|
+
import { Buffer as Buffer$1 } from "node:buffer";
|
|
6
7
|
import * as claudeAgentSdk from "@anthropic-ai/claude-agent-sdk";
|
|
7
8
|
import * as mcpServerModule from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
8
9
|
import { isDeepStrictEqual } from "node:util";
|
|
9
10
|
import { z } from "zod/v4";
|
|
10
11
|
import path from "node:path";
|
|
11
12
|
//#region ../harness/dist/bridge/index.js
|
|
13
|
+
const BRIDGE_AUTH_TIMEOUT_MS = 1e4;
|
|
14
|
+
const BRIDGE_AUTH_MESSAGE_PREFIX = "ai-sdk-harness-bridge-auth-v1\0";
|
|
15
|
+
const PROOF_FRAME_REGEXP = /^\{"type":"bridge-auth-proof","signature":"([A-Za-z0-9_-]{86})"\}$/;
|
|
16
|
+
function createBridgeAuthMessage({ challenge }) {
|
|
17
|
+
return Buffer$1.from(`${BRIDGE_AUTH_MESSAGE_PREFIX}${challenge}`, "utf8");
|
|
18
|
+
}
|
|
19
|
+
function serializeBridgeAuthChallengeFrame({ challenge }) {
|
|
20
|
+
return JSON.stringify({
|
|
21
|
+
type: "bridge-auth-challenge",
|
|
22
|
+
challenge
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
function parseBridgeAuthProofFrame({ text }) {
|
|
26
|
+
return PROOF_FRAME_REGEXP.exec(text)?.[1];
|
|
27
|
+
}
|
|
28
|
+
const PUBLIC_KEY_REGEXP = /^[A-Za-z0-9_-]{43}$/;
|
|
29
|
+
const UNAUTHORIZED_CLOSE_CODE = 1008;
|
|
30
|
+
const INVALID_PUBLIC_KEY_MESSAGE = "The bridge requires a valid Ed25519 public key for authentication.";
|
|
31
|
+
function parseBridgeAuthPublicKey({ publicKey }) {
|
|
32
|
+
if (publicKey == null || !PUBLIC_KEY_REGEXP.test(publicKey)) throw new Error(INVALID_PUBLIC_KEY_MESSAGE);
|
|
33
|
+
let key;
|
|
34
|
+
try {
|
|
35
|
+
key = createPublicKey({
|
|
36
|
+
key: {
|
|
37
|
+
kty: "OKP",
|
|
38
|
+
crv: "Ed25519",
|
|
39
|
+
x: publicKey
|
|
40
|
+
},
|
|
41
|
+
format: "jwk"
|
|
42
|
+
});
|
|
43
|
+
} catch {
|
|
44
|
+
throw new Error(INVALID_PUBLIC_KEY_MESSAGE);
|
|
45
|
+
}
|
|
46
|
+
if (key.asymmetricKeyType !== "ed25519") throw new Error(INVALID_PUBLIC_KEY_MESSAGE);
|
|
47
|
+
return key;
|
|
48
|
+
}
|
|
49
|
+
function authenticateBridgeConnection({ ws, publicKey, timeoutMs = BRIDGE_AUTH_TIMEOUT_MS, onAuthenticated }) {
|
|
50
|
+
const challenge = randomBytes(32).toString("hex");
|
|
51
|
+
const timeout = setTimeout(() => ws.terminate(), timeoutMs);
|
|
52
|
+
timeout.unref?.();
|
|
53
|
+
const onError = () => {};
|
|
54
|
+
ws.on("error", onError);
|
|
55
|
+
ws.once("close", () => clearTimeout(timeout));
|
|
56
|
+
ws.once("message", (raw, isBinary) => {
|
|
57
|
+
clearTimeout(timeout);
|
|
58
|
+
const text = isBinary ? void 0 : rawDataToString(raw);
|
|
59
|
+
const signature = text == null ? void 0 : parseBridgeAuthProofFrame({ text });
|
|
60
|
+
if (signature == null || !verify(null, createBridgeAuthMessage({ challenge }), publicKey, Buffer$1.from(signature, "base64url"))) {
|
|
61
|
+
ws.close(UNAUTHORIZED_CLOSE_CODE, "unauthorized");
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
ws.off("error", onError);
|
|
65
|
+
onAuthenticated();
|
|
66
|
+
});
|
|
67
|
+
ws.send(serializeBridgeAuthChallengeFrame({ challenge }));
|
|
68
|
+
}
|
|
69
|
+
function rawDataToString(raw) {
|
|
70
|
+
const buffer = Array.isArray(raw) ? Buffer$1.concat(raw) : Buffer$1.isBuffer(raw) ? raw : Buffer$1.from(raw);
|
|
71
|
+
if (buffer.byteLength > 1024) return void 0;
|
|
72
|
+
return buffer.toString("utf8");
|
|
73
|
+
}
|
|
12
74
|
const name = "AI_HarnessBridgeCapabilityUnsupportedError";
|
|
13
75
|
/**
|
|
14
76
|
* Signals an unsupported capability discovered inside a sandbox bridge.
|
|
@@ -207,7 +269,7 @@ async function runBridge(options) {
|
|
|
207
269
|
clearTimeout(hostDisconnectTimer);
|
|
208
270
|
hostDisconnectTimer = void 0;
|
|
209
271
|
};
|
|
210
|
-
const
|
|
272
|
+
const authPublicKey = parseBridgeAuthPublicKey({ publicKey: options.publicKey ?? env["BRIDGE_AUTH_PUBLIC_KEY"] });
|
|
211
273
|
const bridgeWsPort = options.port ?? parseInt(env.BRIDGE_WS_PORT ?? "0", 10);
|
|
212
274
|
const bridgeMetaPath = `${bridgeStateDir}/bridge-meta.json`;
|
|
213
275
|
const startConfigPath = `${bridgeStateDir}/start-config.json`;
|
|
@@ -588,11 +650,12 @@ async function runBridge(options) {
|
|
|
588
650
|
}) + "\n");
|
|
589
651
|
options.onListening?.(currentBoundPort);
|
|
590
652
|
});
|
|
591
|
-
wss.on("connection", (ws
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
653
|
+
wss.on("connection", (ws) => authenticateBridgeConnection({
|
|
654
|
+
ws,
|
|
655
|
+
publicKey: authPublicKey,
|
|
656
|
+
onAuthenticated: () => acceptConnection(ws)
|
|
657
|
+
}));
|
|
658
|
+
const acceptConnection = (ws) => {
|
|
596
659
|
sendControl(ws, {
|
|
597
660
|
type: "bridge-hello",
|
|
598
661
|
state: currentTurnState,
|
|
@@ -630,7 +693,7 @@ async function runBridge(options) {
|
|
|
630
693
|
}
|
|
631
694
|
});
|
|
632
695
|
ws.on("error", () => {});
|
|
633
|
-
}
|
|
696
|
+
};
|
|
634
697
|
process.on("uncaughtException", (err) => {
|
|
635
698
|
emitError({
|
|
636
699
|
error: err,
|
|
@@ -768,6 +831,17 @@ function createEmitStreamEvent({ state, emit, emitWarning, emitTerminalError, on
|
|
|
768
831
|
});
|
|
769
832
|
streamStarted = true;
|
|
770
833
|
}
|
|
834
|
+
if (type === "system" && (msg.subtype === "init" || msg.subtype === "status")) {
|
|
835
|
+
emit({
|
|
836
|
+
type: "raw",
|
|
837
|
+
rawValue: {
|
|
838
|
+
type,
|
|
839
|
+
subtype: msg.subtype,
|
|
840
|
+
...msg.permissionMode != null ? { permissionMode: msg.permissionMode } : {}
|
|
841
|
+
}
|
|
842
|
+
});
|
|
843
|
+
return;
|
|
844
|
+
}
|
|
771
845
|
if (type === "system" && msg.subtype === "api_retry") {
|
|
772
846
|
if (typeof msg.error_status === "number" && UNRECOVERABLE_API_RETRY_STATUSES.has(msg.error_status)) {
|
|
773
847
|
emitTerminalError(`HTTP ${msg.error_status}: ${msg.error ?? "provider request failed"}`);
|
|
@@ -1596,13 +1670,16 @@ await runBridge({
|
|
|
1596
1670
|
});
|
|
1597
1671
|
function createPermissionOptions(input) {
|
|
1598
1672
|
const permissionMode = input.start.permissionMode ?? "allow-all";
|
|
1673
|
+
const autoMode = input.start.autoMode === true && permissionMode !== "allow-all";
|
|
1599
1674
|
const inactiveNativeTools = new Set(input.inactiveNativeTools);
|
|
1600
1675
|
const permissionSettings = createPermissionSettings({
|
|
1601
1676
|
permissionMode,
|
|
1677
|
+
autoMode,
|
|
1602
1678
|
inactiveNativeTools
|
|
1603
1679
|
});
|
|
1604
1680
|
const baseOptions = {
|
|
1605
|
-
permissionMode: permissionMode === "allow-all" ? "bypassPermissions" : permissionMode === "allow-edits" ? "acceptEdits" : "default",
|
|
1681
|
+
permissionMode: permissionMode === "allow-all" ? "bypassPermissions" : autoMode ? "auto" : permissionMode === "allow-edits" ? "acceptEdits" : "default",
|
|
1682
|
+
...autoMode ? { allowedTools: ["mcp__harness-tools__*"] } : {},
|
|
1606
1683
|
allowDangerouslySkipPermissions: permissionMode === "allow-all",
|
|
1607
1684
|
...permissionSettings ? { settings: permissionSettings } : {}
|
|
1608
1685
|
};
|
|
@@ -1613,7 +1690,7 @@ function createPermissionOptions(input) {
|
|
|
1613
1690
|
return {
|
|
1614
1691
|
...baseOptions,
|
|
1615
1692
|
canUseTool: async (toolName, toolInput, options) => {
|
|
1616
|
-
if (!await needsHostApproval({
|
|
1693
|
+
if (toolName.startsWith("mcp__harness-tools__") || !autoMode && !await needsHostApproval({
|
|
1617
1694
|
toolName,
|
|
1618
1695
|
toolInput,
|
|
1619
1696
|
permissionMode,
|
|
@@ -1711,7 +1788,7 @@ function createQuestionPreToolUseHook(input) {
|
|
|
1711
1788
|
}
|
|
1712
1789
|
function createPermissionSettings(input) {
|
|
1713
1790
|
const askRules = /* @__PURE__ */ new Set();
|
|
1714
|
-
for (const [nativeName, kind] of Object.entries(NATIVE_TOOL_KINDS)) if (input.inactiveNativeTools.has(nativeName) || (input.permissionMode === "allow-reads" ? kind === "edit" || kind === "bash" : input.permissionMode === "allow-edits" ? kind === "bash" : false)) askRules.add(`${nativeName}(*)`);
|
|
1791
|
+
for (const [nativeName, kind] of Object.entries(NATIVE_TOOL_KINDS)) if (input.inactiveNativeTools.has(nativeName) || !input.autoMode && (input.permissionMode === "allow-reads" ? kind === "edit" || kind === "bash" : input.permissionMode === "allow-edits" ? kind === "bash" : false)) askRules.add(`${nativeName}(*)`);
|
|
1715
1792
|
if (askRules.size === 0) return void 0;
|
|
1716
1793
|
return {
|
|
1717
1794
|
permissions: { ask: [...askRules] },
|
|
@@ -2026,7 +2103,7 @@ async function runTurn(start, turn) {
|
|
|
2026
2103
|
} } : {},
|
|
2027
2104
|
includePartialMessages: true,
|
|
2028
2105
|
hooks: {
|
|
2029
|
-
PreToolUse: [...permissionMode === "allow-all" ? [] : [{ hooks: [approvalPreToolUseHook] }], {
|
|
2106
|
+
PreToolUse: [...permissionMode === "allow-all" || start.autoMode === true ? [] : [{ hooks: [approvalPreToolUseHook] }], {
|
|
2030
2107
|
matcher: "AskUserQuestion",
|
|
2031
2108
|
hooks: [questionPreToolUseHook],
|
|
2032
2109
|
...start.questionTimeoutMs !== void 0 ? { timeout: Math.ceil(start.questionTimeoutMs / 1e3) } : {}
|
|
@@ -2042,7 +2119,7 @@ async function runTurn(start, turn) {
|
|
|
2042
2119
|
mcpServers,
|
|
2043
2120
|
settingSources: ["user"],
|
|
2044
2121
|
cwd: workdir,
|
|
2045
|
-
|
|
2122
|
+
abortController: abortCtl
|
|
2046
2123
|
}
|
|
2047
2124
|
};
|
|
2048
2125
|
let deferredToolUseId = start.deferredToolUseId;
|