@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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ai-sdk/harness-claude-code",
3
- "version": "1.0.181",
3
+ "version": "1.0.184",
4
4
  "type": "module",
5
5
  "license": "Apache-2.0",
6
6
  "sideEffects": false,
@@ -26,24 +26,24 @@
26
26
  }
27
27
  },
28
28
  "dependencies": {
29
- "@ai-sdk/harness": "1.0.177",
29
+ "@ai-sdk/harness": "1.0.180",
30
30
  "@ai-sdk/provider": "4.0.37",
31
- "@ai-sdk/provider-utils": "5.0.76",
31
+ "@ai-sdk/provider-utils": "5.0.79",
32
32
  "ws": "^8.21.0"
33
33
  },
34
34
  "peerDependencies": {
35
35
  "zod": "^3.25.76 || ^4.1.8"
36
36
  },
37
37
  "devDependencies": {
38
- "@anthropic-ai/claude-agent-sdk": "0.3.290",
39
- "@modelcontextprotocol/sdk": "1.32.1",
38
+ "@anthropic-ai/claude-agent-sdk": "0.3.319",
39
+ "@modelcontextprotocol/sdk": "1.32.2",
40
40
  "@types/node": "22.19.19",
41
41
  "@types/ws": "^8.5.13",
42
42
  "@vercel/ai-tsconfig": "0.0.0",
43
43
  "@vercel/ai-tsdown-config": "0.0.0",
44
44
  "tsdown": "^0.23.0",
45
45
  "typescript": "6.0.3",
46
- "zod": "3.25.76"
46
+ "zod": "4.6.7"
47
47
  },
48
48
  "engines": {
49
49
  "node": ">=22"
@@ -6,6 +6,7 @@ type Emit = (message: Record<string, unknown>) => void;
6
6
  export type ClaudeMessage = {
7
7
  type?: string;
8
8
  subtype?: string;
9
+ permissionMode?: string;
9
10
  parent_tool_use_id?: string | null;
10
11
  model?: string;
11
12
  error?: string;
@@ -221,6 +222,25 @@ export function createEmitStreamEvent({
221
222
  streamStarted = true;
222
223
  }
223
224
 
225
+ if (
226
+ type === 'system' &&
227
+ (msg.subtype === 'init' || msg.subtype === 'status')
228
+ ) {
229
+ // Expose the effective mode without forwarding the large init payload
230
+ // (tools, MCP servers, skills, plugins, and other session metadata).
231
+ emit({
232
+ type: 'raw',
233
+ rawValue: {
234
+ type,
235
+ subtype: msg.subtype,
236
+ ...(msg.permissionMode != null
237
+ ? { permissionMode: msg.permissionMode }
238
+ : {}),
239
+ },
240
+ });
241
+ return;
242
+ }
243
+
224
244
  if (type === 'system' && msg.subtype === 'api_retry') {
225
245
  if (
226
246
  typeof msg.error_status === 'number' &&
@@ -214,9 +214,12 @@ function createPermissionOptions(input: {
214
214
  toolCwds: Map<string, string>;
215
215
  }): Record<string, unknown> {
216
216
  const permissionMode = input.start.permissionMode ?? 'allow-all';
217
+ const autoMode =
218
+ input.start.autoMode === true && permissionMode !== 'allow-all';
217
219
  const inactiveNativeTools = new Set(input.inactiveNativeTools);
218
220
  const permissionSettings = createPermissionSettings({
219
221
  permissionMode,
222
+ autoMode,
220
223
  inactiveNativeTools,
221
224
  });
222
225
 
@@ -224,9 +227,14 @@ function createPermissionOptions(input: {
224
227
  permissionMode:
225
228
  permissionMode === 'allow-all'
226
229
  ? 'bypassPermissions'
227
- : permissionMode === 'allow-edits'
228
- ? 'acceptEdits'
229
- : 'default',
230
+ : autoMode
231
+ ? 'auto'
232
+ : permissionMode === 'allow-edits'
233
+ ? 'acceptEdits'
234
+ : 'default',
235
+ // Host tools are authorized by HarnessAgent's toolApproval, not the
236
+ // Claude Code classifier. Do not allow unrelated MCP servers here.
237
+ ...(autoMode ? { allowedTools: ['mcp__harness-tools__*'] } : {}),
230
238
  allowDangerouslySkipPermissions: permissionMode === 'allow-all',
231
239
  ...(permissionSettings ? { settings: permissionSettings } : {}),
232
240
  };
@@ -252,16 +260,18 @@ function createPermissionOptions(input: {
252
260
  options: { toolUseID: string; blockedPath?: string },
253
261
  ) => {
254
262
  if (
255
- !(await needsHostApproval({
256
- toolName,
257
- toolInput,
258
- permissionMode,
259
- inactiveNativeTools,
260
- cwd: input.toolCwds.get(options.toolUseID) ?? '',
261
- readableSkillRoots: input.start.readableSkillRoots ?? [],
262
- additionalDirectories: input.start.additionalDirectories ?? [],
263
- blockedPath: options.blockedPath,
264
- }))
263
+ toolName.startsWith('mcp__harness-tools__') ||
264
+ (!autoMode &&
265
+ !(await needsHostApproval({
266
+ toolName,
267
+ toolInput,
268
+ permissionMode,
269
+ inactiveNativeTools,
270
+ cwd: input.toolCwds.get(options.toolUseID) ?? '',
271
+ readableSkillRoots: input.start.readableSkillRoots ?? [],
272
+ additionalDirectories: input.start.additionalDirectories ?? [],
273
+ blockedPath: options.blockedPath,
274
+ })))
265
275
  ) {
266
276
  return { behavior: 'allow', updatedInput: toolInput };
267
277
  }
@@ -397,17 +407,19 @@ function createQuestionPreToolUseHook(input: {
397
407
 
398
408
  function createPermissionSettings(input: {
399
409
  permissionMode: 'allow-reads' | 'allow-edits' | 'allow-all';
410
+ autoMode: boolean;
400
411
  inactiveNativeTools: ReadonlySet<string>;
401
412
  }): Record<string, unknown> | undefined {
402
413
  const askRules = new Set<string>();
403
414
  for (const [nativeName, kind] of Object.entries(NATIVE_TOOL_KINDS)) {
404
415
  if (
405
416
  input.inactiveNativeTools.has(nativeName) ||
406
- (input.permissionMode === 'allow-reads'
407
- ? kind === 'edit' || kind === 'bash'
408
- : input.permissionMode === 'allow-edits'
409
- ? kind === 'bash'
410
- : false)
417
+ (!input.autoMode &&
418
+ (input.permissionMode === 'allow-reads'
419
+ ? kind === 'edit' || kind === 'bash'
420
+ : input.permissionMode === 'allow-edits'
421
+ ? kind === 'bash'
422
+ : false))
411
423
  ) {
412
424
  askRules.add(`${nativeName}(*)`);
413
425
  }
@@ -892,7 +904,7 @@ async function runTurn(start: StartMessage, turn: BridgeTurn): Promise<void> {
892
904
  // `compaction` event; return an empty output so compaction proceeds.
893
905
  hooks: {
894
906
  PreToolUse: [
895
- ...(permissionMode === 'allow-all'
907
+ ...(permissionMode === 'allow-all' || start.autoMode === true
896
908
  ? []
897
909
  : [{ hooks: [approvalPreToolUseHook] }]),
898
910
  {
@@ -939,7 +951,7 @@ async function runTurn(start: StartMessage, turn: BridgeTurn): Promise<void> {
939
951
  mcpServers,
940
952
  settingSources: ['user'],
941
953
  cwd: workdir,
942
- abortSignal: abortCtl.signal,
954
+ abortController: abortCtl,
943
955
  },
944
956
  };
945
957
  let deferredToolUseId = start.deferredToolUseId;
@@ -4,9 +4,9 @@
4
4
  "private": true,
5
5
  "type": "module",
6
6
  "dependencies": {
7
- "@anthropic-ai/claude-agent-sdk": "0.3.290",
8
- "@anthropic-ai/claude-code": "2.1.290",
9
- "@modelcontextprotocol/sdk": "1.32.1",
7
+ "@anthropic-ai/claude-agent-sdk": "0.3.319",
8
+ "@anthropic-ai/claude-code": "2.1.319",
9
+ "@modelcontextprotocol/sdk": "1.32.2",
10
10
  "ws": "8.21.0",
11
11
  "zod": "4.4.3"
12
12
  }
@@ -50,6 +50,7 @@ export const startMessageSchema = harnessV1BridgeStartBaseSchema.extend({
50
50
  maxBudgetUsd: z.number().optional(),
51
51
  additionalDirectories: z.array(z.string()).optional(),
52
52
  strictMcpConfig: z.boolean().optional(),
53
+ autoMode: z.boolean().optional(),
53
54
  questionTimeoutMs: z.number().optional(),
54
55
  excludeDynamicSections: z.boolean().optional(),
55
56
  agentProgressSummaries: z.boolean().optional(),
@@ -26,7 +26,8 @@ import {
26
26
  applyCredentialForwarding,
27
27
  classifyDiskLog,
28
28
  resolveSandboxCredentialEnvironment,
29
- createBridgeToken,
29
+ BRIDGE_AUTH_PUBLIC_KEY_ENV,
30
+ createBridgeAuthKeyPair,
30
31
  createBridgeWebSocketConnect,
31
32
  experimental_createBridgeUserMessageSubmitter,
32
33
  createBridgeErrorHandler,
@@ -43,6 +44,7 @@ import {
43
44
  shellQuote,
44
45
  validateBridgeSandboxSettings,
45
46
  warnCredentialBrokeringUnavailable,
47
+ warnMintBridgeTokenIgnored,
46
48
  waitForBridgeReady,
47
49
  writeSkills,
48
50
  type BridgeHello,
@@ -89,6 +91,13 @@ const CLAUDE_CODE_CLIENT_APP = `ai-sdk-harness-claude-code/${VERSION}`;
89
91
 
90
92
  export type ClaudeCodeHarnessSettings = {
91
93
  readonly auth?: ClaudeCodeAuthenticationMode;
94
+ /**
95
+ * Requests Claude Code's classifier-based `auto` permission mode for
96
+ * `allow-reads` and `allow-edits`. Only escalated calls ask the host.
97
+ * Defaults to false; `allow-all` continues to bypass permissions.
98
+ * Observe raw init/status parts for the effective permission mode.
99
+ */
100
+ readonly autoMode?: boolean;
92
101
  /**
93
102
  * Customizes each credential value before it is forwarded into a sandbox
94
103
  * process. This does not restrict which credentials the harness adapter can
@@ -217,9 +226,10 @@ export type ClaudeCodeHarnessSettings = {
217
226
  * contain connection details, so avoid logging it as is.
218
227
  */
219
228
  readonly onDebug?: (event: SandboxChannelDebugEvent) => void;
229
+ // TODO: Remove in the next major version.
220
230
  /**
221
- * Creates the authentication token used by the sandbox bridge. Defaults to
222
- * a random 32-byte hexadecimal token.
231
+ * @deprecated Sandbox bridge authentication now uses adapter-generated
232
+ * Ed25519 keys. This setting is ignored and emits a warning.
223
233
  */
224
234
  readonly mintBridgeToken?: HarnessV1MintBridgeTokenCallback;
225
235
  };
@@ -870,7 +880,7 @@ const CLAUDE_CODE_BUILTIN_TOOLS = {
870
880
  */
871
881
  const claudeCodeBridgeCoordsSchema = z.object({
872
882
  port: z.number(),
873
- token: z.string(),
883
+ privateKey: z.string(),
874
884
  lastSeenEventId: z.number(),
875
885
  startId: z.string().optional(),
876
886
  sandboxId: z.string().optional(),
@@ -906,6 +916,10 @@ type ClaudeCodeBridgeCoords = z.infer<typeof claudeCodeBridgeCoordsSchema>;
906
916
  export function createClaudeCode(
907
917
  settings: ClaudeCodeHarnessSettings = {},
908
918
  ): HarnessV1<typeof CLAUDE_CODE_BUILTIN_TOOLS> {
919
+ warnMintBridgeTokenIgnored({
920
+ harnessId: 'claude-code',
921
+ mintBridgeToken: settings.mintBridgeToken,
922
+ });
909
923
  if (
910
924
  settings.mcpServers != null &&
911
925
  Object.prototype.hasOwnProperty.call(settings.mcpServers, 'harness-tools')
@@ -934,10 +948,8 @@ export function createClaudeCode(
934
948
  const sandboxId = 'id' in sandboxSession ? sandboxSession.id : undefined;
935
949
  validateBridgeSandboxSettings({
936
950
  sandboxSession,
937
- sandboxId,
938
951
  portOverride: settings.port,
939
952
  portEndpointOverride: settings.portEndpoint,
940
- mintBridgeToken: settings.mintBridgeToken,
941
953
  });
942
954
  const lifecycleState = startOpts.continueFrom ?? startOpts.resumeFrom;
943
955
  const isResume = lifecycleState != null;
@@ -1076,7 +1088,7 @@ export function createClaudeCode(
1076
1088
  * Rung 1 — ATTACH. When lifecycle state carries live bridge coordinates,
1077
1089
  * try to reopen a socket to the still-running bridge. Parked sessions wait
1078
1090
  * for the next `start`; suspended turns request replay of everything past
1079
- * the persisted cursor. No spawn, no fresh token (the existing bridge
1091
+ * the persisted cursor. No spawn, no fresh key (the existing bridge
1080
1092
  * still authorises the persisted one). If the bridge is gone the open
1081
1093
  * throws and we fall through to a spawn-based recovery.
1082
1094
  */
@@ -1086,11 +1098,11 @@ export function createClaudeCode(
1086
1098
  sandboxSession,
1087
1099
  port: coords.port,
1088
1100
  portEndpointOverride: settings.portEndpoint,
1089
- token: coords.token,
1090
1101
  });
1091
1102
  const attachChannel: ClaudeCodeChannel = new SandboxChannel({
1092
1103
  connect: createBridgeWebSocketConnect({
1093
1104
  endpoint: attachEndpoint,
1105
+ privateKey: coords.privateKey,
1094
1106
  webSocketConstructor: WebSocket,
1095
1107
  onHello,
1096
1108
  }),
@@ -1125,6 +1137,7 @@ export function createClaudeCode(
1125
1137
  maxBudgetUsd: settings.maxBudgetUsd,
1126
1138
  additionalDirectories: settings.additionalDirectories,
1127
1139
  strictMcpConfig: settings.strictMcpConfig,
1140
+ autoMode: settings.autoMode,
1128
1141
  questionTimeoutMs: settings.questionTimeoutMs,
1129
1142
  excludeDynamicSections: settings.excludeDynamicSections,
1130
1143
  agentProgressSummaries: settings.agentProgressSummaries,
@@ -1136,7 +1149,7 @@ export function createClaudeCode(
1136
1149
  continueOnFirstPrompt: false,
1137
1150
  rerunContinue: false,
1138
1151
  bridgePort: coords.port,
1139
- bridgeToken: coords.token,
1152
+ bridgePrivateKey: coords.privateKey,
1140
1153
  sandboxId,
1141
1154
  sandboxCredentialEnvironment,
1142
1155
  debug: startOpts.observability?.debug,
@@ -1183,12 +1196,9 @@ export function createClaudeCode(
1183
1196
  sandboxSession,
1184
1197
  portOverride: settings.port,
1185
1198
  });
1186
- const token =
1187
- settings.mintBridgeToken == null
1188
- ? createBridgeToken()
1189
- : settings.mintBridgeToken(sandboxId!);
1199
+ const bridgeAuth = createBridgeAuthKeyPair();
1190
1200
  const env = {
1191
- BRIDGE_CHANNEL_TOKEN: token,
1201
+ [BRIDGE_AUTH_PUBLIC_KEY_ENV]: bridgeAuth.publicKey,
1192
1202
  BRIDGE_WS_PORT: String(port),
1193
1203
  ...(respawnStrategy === 'replay'
1194
1204
  ? { BRIDGE_REPLAY_FROM_DISK: '1' }
@@ -1198,7 +1208,7 @@ export function createClaudeCode(
1198
1208
  /*
1199
1209
  * On a fresh start the workdir and bridge-state directory must be
1200
1210
  * created. The env is sent fresh on every spawn —
1201
- * `BRIDGE_CHANNEL_TOKEN` rotates per start.
1211
+ * the bridge authentication key pair rotates per start.
1202
1212
  */
1203
1213
  if (respawnStrategy === undefined) {
1204
1214
  await toolSafeSandboxSession.run({
@@ -1258,12 +1268,12 @@ export function createClaudeCode(
1258
1268
  sandboxSession,
1259
1269
  port: boundPort,
1260
1270
  portEndpointOverride: settings.portEndpoint,
1261
- token,
1262
1271
  });
1263
1272
 
1264
1273
  const channel: ClaudeCodeChannel = new SandboxChannel({
1265
1274
  connect: createBridgeWebSocketConnect({
1266
1275
  endpoint: bridgeEndpoint,
1276
+ privateKey: bridgeAuth.privateKey,
1267
1277
  webSocketConstructor: WebSocket,
1268
1278
  openRetryTimeoutMs: timeoutMs,
1269
1279
  startAbortSignal: startOpts.abortSignal,
@@ -1305,6 +1315,7 @@ export function createClaudeCode(
1305
1315
  maxBudgetUsd: settings.maxBudgetUsd,
1306
1316
  additionalDirectories: settings.additionalDirectories,
1307
1317
  strictMcpConfig: settings.strictMcpConfig,
1318
+ autoMode: settings.autoMode,
1308
1319
  questionTimeoutMs: settings.questionTimeoutMs,
1309
1320
  excludeDynamicSections: settings.excludeDynamicSections,
1310
1321
  agentProgressSummaries: settings.agentProgressSummaries,
@@ -1326,7 +1337,7 @@ export function createClaudeCode(
1326
1337
  }
1327
1338
  : {}),
1328
1339
  bridgePort: boundPort,
1329
- bridgeToken: token,
1340
+ bridgePrivateKey: bridgeAuth.privateKey,
1330
1341
  sandboxId,
1331
1342
  sandboxCredentialEnvironment,
1332
1343
  debug: startOpts.observability?.debug,
@@ -1362,6 +1373,7 @@ function createSession({
1362
1373
  maxBudgetUsd,
1363
1374
  additionalDirectories,
1364
1375
  strictMcpConfig,
1376
+ autoMode,
1365
1377
  questionTimeoutMs,
1366
1378
  excludeDynamicSections,
1367
1379
  agentProgressSummaries,
@@ -1375,7 +1387,7 @@ function createSession({
1375
1387
  rerunContinue,
1376
1388
  deferredToolUseId,
1377
1389
  bridgePort,
1378
- bridgeToken,
1390
+ bridgePrivateKey,
1379
1391
  sandboxId,
1380
1392
  sandboxCredentialEnvironment,
1381
1393
  debug,
@@ -1400,6 +1412,7 @@ function createSession({
1400
1412
  maxBudgetUsd: number | undefined;
1401
1413
  additionalDirectories: ReadonlyArray<string> | undefined;
1402
1414
  strictMcpConfig: boolean | undefined;
1415
+ autoMode: boolean | undefined;
1403
1416
  questionTimeoutMs: number | undefined;
1404
1417
  excludeDynamicSections: boolean | undefined;
1405
1418
  agentProgressSummaries: boolean | undefined;
@@ -1423,7 +1436,7 @@ function createSession({
1423
1436
  */
1424
1437
  deferredToolUseId?: string;
1425
1438
  bridgePort: number;
1426
- bridgeToken: string;
1439
+ bridgePrivateKey: string;
1427
1440
  sandboxId: string | undefined;
1428
1441
  sandboxCredentialEnvironment: Record<string, string> | undefined;
1429
1442
  debug: HarnessV1DebugConfig | undefined;
@@ -1813,6 +1826,7 @@ function createSession({
1813
1826
  ? { additionalDirectories: [...additionalDirectories] }
1814
1827
  : {}),
1815
1828
  ...(strictMcpConfig !== undefined ? { strictMcpConfig } : {}),
1829
+ ...(autoMode !== undefined ? { autoMode } : {}),
1816
1830
  ...(questionTimeoutMs !== undefined ? { questionTimeoutMs } : {}),
1817
1831
  ...(excludeDynamicSections !== undefined
1818
1832
  ? { excludeDynamicSections }
@@ -1903,6 +1917,7 @@ function createSession({
1903
1917
  ? { additionalDirectories: [...additionalDirectories] }
1904
1918
  : {}),
1905
1919
  ...(strictMcpConfig !== undefined ? { strictMcpConfig } : {}),
1920
+ ...(autoMode !== undefined ? { autoMode } : {}),
1906
1921
  ...(questionTimeoutMs !== undefined ? { questionTimeoutMs } : {}),
1907
1922
  ...(excludeDynamicSections !== undefined
1908
1923
  ? { excludeDynamicSections }
@@ -1968,7 +1983,7 @@ function createSession({
1968
1983
  : { sandboxCredentialEnvironment }),
1969
1984
  bridge: {
1970
1985
  port: bridgePort,
1971
- token: bridgeToken,
1986
+ privateKey: bridgePrivateKey,
1972
1987
  lastSeenEventId,
1973
1988
  ...(activeStartId == null ? {} : { startId: activeStartId }),
1974
1989
  ...(sandboxId == null ? {} : { sandboxId }),
@@ -2128,7 +2143,7 @@ function createSession({
2128
2143
  : { sandboxCredentialEnvironment }),
2129
2144
  bridge: {
2130
2145
  port: bridgePort,
2131
- token: bridgeToken,
2146
+ privateKey: bridgePrivateKey,
2132
2147
  lastSeenEventId,
2133
2148
  ...(activeStartId == null ? {} : { startId: activeStartId }),
2134
2149
  ...(sandboxId == null ? {} : { sandboxId }),