@ai-sdk/harness-claude-code 1.0.199 → 1.0.201

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/dist/index.js CHANGED
@@ -346,7 +346,7 @@ const startMessageSchema = harnessV1BridgeStartBaseSchema.extend({
346
346
  z.discriminatedUnion("type", [startMessageSchema, ...harnessV1BridgeInboundCommandSchemas]);
347
347
  //#endregion
348
348
  //#region src/version.ts
349
- const VERSION = "1.0.199";
349
+ const VERSION = "1.0.201";
350
350
  //#endregion
351
351
  //#region src/claude-code-harness.ts
352
352
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ai-sdk/harness-claude-code",
3
- "version": "1.0.199",
3
+ "version": "1.0.201",
4
4
  "type": "module",
5
5
  "license": "Apache-2.0",
6
6
  "sideEffects": false,
@@ -26,9 +26,9 @@
26
26
  }
27
27
  },
28
28
  "dependencies": {
29
- "@ai-sdk/harness": "1.0.195",
29
+ "@ai-sdk/harness": "1.0.197",
30
30
  "@ai-sdk/provider": "4.0.39",
31
- "@ai-sdk/provider-utils": "5.0.85",
31
+ "@ai-sdk/provider-utils": "5.0.86",
32
32
  "ws": "^8.21.0"
33
33
  },
34
34
  "peerDependencies": {
@@ -1,5 +1,6 @@
1
1
  import { randomUUID } from 'node:crypto';
2
2
  import { isDeepStrictEqual } from 'node:util';
3
+ import { HOST_TOOL_PREFIX, resolveHostToolName } from './host-tool-names';
3
4
 
4
5
  type Emit = (message: Record<string, unknown>) => void;
5
6
 
@@ -160,7 +161,6 @@ export function createClaudeStreamEventState(): ClaudeStreamEventState {
160
161
  }
161
162
 
162
163
  const UNRECOVERABLE_API_RETRY_STATUSES = new Set([401, 403, 404]);
163
- const HOST_TOOL_PREFIX = 'mcp__harness-tools__';
164
164
  const RAW_TASK_MESSAGE_SUBTYPES = new Set([
165
165
  'background_tasks_changed',
166
166
  'task_started',
@@ -182,6 +182,7 @@ export function createEmitStreamEvent({
182
182
  emitTerminalError,
183
183
  onCompactionBoundary,
184
184
  toCommonName,
185
+ toHostToolName = resolveHostToolName,
185
186
  }: {
186
187
  state: ClaudeStreamEventState;
187
188
  emit: Emit;
@@ -193,6 +194,7 @@ export function createEmitStreamEvent({
193
194
  tokensAfter?: number;
194
195
  }) => void;
195
196
  toCommonName: (nativeName: string) => string;
197
+ toHostToolName?: (nativeName: string) => string | undefined;
196
198
  }): (event: ClaudeMessage) => void {
197
199
  let streamStarted = false;
198
200
 
@@ -342,6 +344,7 @@ export function createEmitStreamEvent({
342
344
  state,
343
345
  send: emit,
344
346
  toCommonName,
347
+ toHostToolName,
345
348
  });
346
349
  return;
347
350
  }
@@ -362,8 +365,8 @@ export function createEmitStreamEvent({
362
365
  state.structuredOutputToolUseIds.add(block.id);
363
366
  continue;
364
367
  }
365
- if (block.name.startsWith(HOST_TOOL_PREFIX)) {
366
- const hostToolName = block.name.slice(HOST_TOOL_PREFIX.length);
368
+ const hostToolName = toHostToolName(block.name);
369
+ if (hostToolName !== undefined) {
367
370
  state.pendingStepToolUseIds.add(block.id);
368
371
  state.mcpToolCalls.set(block.id, {
369
372
  toolName: hostToolName,
@@ -731,12 +734,14 @@ function handleStreamEvent({
731
734
  state,
732
735
  send,
733
736
  toCommonName,
737
+ toHostToolName,
734
738
  }: {
735
739
  event: ClaudeMessage['event'] | undefined;
736
740
  message: ClaudeMessage;
737
741
  state: ClaudeStreamEventState;
738
742
  send: Emit;
739
743
  toCommonName: (nativeName: string) => string;
744
+ toHostToolName: (nativeName: string) => string | undefined;
740
745
  }): void {
741
746
  if (!event) return;
742
747
 
@@ -805,9 +810,7 @@ function handleStreamEvent({
805
810
  if (nativeName === 'AskUserQuestion') {
806
811
  return;
807
812
  }
808
- const hostToolName = nativeName.startsWith(HOST_TOOL_PREFIX)
809
- ? nativeName.slice(HOST_TOOL_PREFIX.length)
810
- : undefined;
813
+ const hostToolName = toHostToolName(nativeName);
811
814
  const dynamic = isExternalMcpTool(nativeName);
812
815
  partialBlocks.set(index, { id, kind: 'tool-input' });
813
816
  send({
@@ -0,0 +1,14 @@
1
+ export const HOST_TOOL_PREFIX = 'mcp__harness-tools__';
2
+
3
+ export function resolveHostToolName(
4
+ toolName: string,
5
+ toolAliases?: Readonly<Record<string, string>>,
6
+ ): string | undefined {
7
+ const resolvedName =
8
+ toolAliases != null && Object.hasOwn(toolAliases, toolName)
9
+ ? toolAliases[toolName]!
10
+ : toolName;
11
+ return resolvedName.startsWith(HOST_TOOL_PREFIX)
12
+ ? resolvedName.slice(HOST_TOOL_PREFIX.length)
13
+ : undefined;
14
+ }
@@ -57,7 +57,9 @@ import {
57
57
  } from './create-emit-stream-event';
58
58
  import { jsonSchemaToZodObject } from './json-schema-to-zod';
59
59
  import { areFileToolPathsTrusted } from './permission-paths';
60
+ import { HOST_TOOL_PREFIX, resolveHostToolName } from './host-tool-names';
60
61
  import {
62
+ PUBLIC_TO_NATIVE,
61
63
  resolveInactiveNativeTools,
62
64
  resolveNativeTools,
63
65
  } from './tool-filtering';
@@ -214,6 +216,7 @@ type Emit = (msg: Record<string, unknown>) => void;
214
216
 
215
217
  function createPermissionOptions(input: {
216
218
  start: StartMessage;
219
+ toHostToolName: (toolName: string) => string | undefined;
217
220
  inactiveNativeTools: readonly string[];
218
221
  turn: BridgeTurn;
219
222
  emit: Emit;
@@ -272,10 +275,11 @@ function createPermissionOptions(input: {
272
275
  options: { toolUseID: string; blockedPath?: string },
273
276
  ) => {
274
277
  if (
275
- toolName.startsWith('mcp__harness-tools__') ||
278
+ input.toHostToolName(toolName) !== undefined ||
276
279
  (!autoMode &&
277
280
  !(await needsHostApproval({
278
281
  toolName,
282
+ toHostToolName: input.toHostToolName,
279
283
  toolInput,
280
284
  permissionMode,
281
285
  inactiveNativeTools,
@@ -484,6 +488,7 @@ function createGatewayModelOverrides(
484
488
 
485
489
  async function needsHostApproval(input: {
486
490
  toolName: string;
491
+ toHostToolName: (toolName: string) => string | undefined;
487
492
  toolInput: unknown;
488
493
  cwd: string;
489
494
  readableSkillRoots: readonly string[];
@@ -492,7 +497,7 @@ async function needsHostApproval(input: {
492
497
  permissionMode: 'allow-reads' | 'allow-edits' | 'allow-all';
493
498
  inactiveNativeTools: ReadonlySet<string>;
494
499
  }): Promise<boolean> {
495
- if (input.toolName.startsWith('mcp__harness-tools__')) return false;
500
+ if (input.toHostToolName(input.toolName) !== undefined) return false;
496
501
  if (
497
502
  input.inactiveNativeTools.has(input.toolName) ||
498
503
  nativeToolRequiresApproval({
@@ -606,6 +611,7 @@ async function isProtectedClaudeFileWrite(input: {
606
611
  */
607
612
  function createApprovalPreToolUseHook(input: {
608
613
  permissionMode: 'allow-reads' | 'allow-edits' | 'allow-all';
614
+ toHostToolName: (toolName: string) => string | undefined;
609
615
  autoMode: boolean;
610
616
  inactiveNativeTools: ReadonlySet<string>;
611
617
  decisions: Map<string, { approved: boolean; reason?: string }>;
@@ -653,6 +659,7 @@ function createApprovalPreToolUseHook(input: {
653
659
  })
654
660
  : await needsHostApproval({
655
661
  toolName,
662
+ toHostToolName: input.toHostToolName,
656
663
  toolInput: hookInput.tool_input,
657
664
  cwd: hookInput.cwd,
658
665
  readableSkillRoots: input.readableSkillRoots,
@@ -729,6 +736,25 @@ async function runTurn(start: StartMessage, turn: BridgeTurn): Promise<void> {
729
736
 
730
737
  const streamEventState = createClaudeStreamEventState();
731
738
 
739
+ const reservedToolNames = new Set([
740
+ ...(claudeAgentSdk.BUILTIN_TOOL_NAMES ?? []),
741
+ ...Object.keys(claudeAgentSdk.LEGACY_TOOL_NAME_ALIASES ?? {}),
742
+ ...Object.keys(NATIVE_TOOL_KINDS),
743
+ ...Object.keys(NATIVE_TO_COMMON),
744
+ ...Object.values(PUBLIC_TO_NATIVE),
745
+ 'StructuredOutput',
746
+ ]);
747
+ const toolAliases = Object.fromEntries(
748
+ (start.tools ?? [])
749
+ .filter(
750
+ tool =>
751
+ !reservedToolNames.has(tool.name) && !tool.name.startsWith('mcp__'),
752
+ )
753
+ .map(tool => [tool.name, `${HOST_TOOL_PREFIX}${tool.name}`]),
754
+ );
755
+ const toHostToolName = (toolName: string) =>
756
+ resolveHostToolName(toolName, toolAliases);
757
+
732
758
  const mcpServers: Record<string, unknown> = { ...start.mcpServers };
733
759
  if (start.tools && start.tools.length > 0) {
734
760
  const server = new mcpModule.McpServer({
@@ -878,6 +904,7 @@ async function runTurn(start: StartMessage, turn: BridgeTurn): Promise<void> {
878
904
  >();
879
905
  const toolCwds = new Map<string, string>();
880
906
  const permissionOptions = createPermissionOptions({
907
+ toHostToolName,
881
908
  toolCwds,
882
909
  approvalDecisions,
883
910
  start,
@@ -896,6 +923,7 @@ async function runTurn(start: StartMessage, turn: BridgeTurn): Promise<void> {
896
923
  const modelOverrides = createGatewayModelOverrides(start.model, sdkEnv);
897
924
  const deferredToolUseIds = new Set<string>();
898
925
  const approvalPreToolUseHook = createApprovalPreToolUseHook({
926
+ toHostToolName,
899
927
  toolCwds,
900
928
  readableSkillRoots: start.readableSkillRoots ?? [],
901
929
  additionalDirectories: start.additionalDirectories ?? [],
@@ -1014,6 +1042,7 @@ async function runTurn(start: StartMessage, turn: BridgeTurn): Promise<void> {
1014
1042
  ...permissionOptions,
1015
1043
  ...(Object.keys(settings).length > 0 ? { settings } : {}),
1016
1044
  mcpServers,
1045
+ ...(Object.keys(toolAliases).length > 0 ? { toolAliases } : {}),
1017
1046
  settingSources: ['user'],
1018
1047
  cwd: workdir,
1019
1048
  abortController: abortCtl,
@@ -1130,6 +1159,7 @@ async function runTurn(start: StartMessage, turn: BridgeTurn): Promise<void> {
1130
1159
  emitTerminalError,
1131
1160
  onCompactionBoundary: boundary => compaction.onBoundary(boundary),
1132
1161
  toCommonName,
1162
+ toHostToolName,
1133
1163
  });
1134
1164
 
1135
1165
  /*
@@ -51,19 +51,26 @@ export function toClaudeCodeQuestionResult(input: {
51
51
  }
52
52
 
53
53
  const canonicalInput = toHarnessQuestionsInput(input.nativeInput);
54
+ const annotations = new Map<string, { notes: string }>();
54
55
  const answers = Object.fromEntries(
55
56
  canonicalInput.questions.flatMap((question, questionIndex) => {
56
57
  const answer = output.answers[question.id];
57
58
  if (answer == null) return [];
58
59
  const nativeQuestion = input.nativeInput.questions[questionIndex];
60
+ const selectedAnswer = toClaudeCodeAnswer({
61
+ nativeQuestion,
62
+ optionIds: answer.optionIds,
63
+ });
64
+ if (selectedAnswer !== '' && answer.freeform !== undefined) {
65
+ annotations.set(nativeQuestion.question, {
66
+ ...input.nativeInput.annotations?.[nativeQuestion.question],
67
+ notes: answer.freeform,
68
+ });
69
+ }
59
70
  return [
60
71
  [
61
72
  nativeQuestion.question,
62
- toClaudeCodeAnswer({
63
- nativeQuestion,
64
- optionIds: answer.optionIds,
65
- freeform: answer.freeform,
66
- }),
73
+ selectedAnswer === '' ? (answer.freeform ?? '') : selectedAnswer,
67
74
  ],
68
75
  ];
69
76
  }),
@@ -71,16 +78,25 @@ export function toClaudeCodeQuestionResult(input: {
71
78
 
72
79
  return {
73
80
  behavior: 'allow',
74
- updatedInput: { ...input.nativeInput, answers },
81
+ updatedInput: {
82
+ ...input.nativeInput,
83
+ answers,
84
+ ...(annotations.size > 0
85
+ ? {
86
+ annotations: {
87
+ ...input.nativeInput.annotations,
88
+ ...Object.fromEntries(annotations),
89
+ },
90
+ }
91
+ : {}),
92
+ },
75
93
  };
76
94
  }
77
95
 
78
96
  function toClaudeCodeAnswer(input: {
79
97
  nativeQuestion: ClaudeCodeQuestion;
80
98
  optionIds: string[];
81
- freeform: string | undefined;
82
99
  }): string {
83
- if (input.freeform !== undefined) return input.freeform;
84
100
  const labels = input.optionIds.flatMap(optionId => {
85
101
  const index = positionalIdIndex({ id: optionId, prefix: 'option-' });
86
102
  const option =
@@ -2,7 +2,7 @@ import type { StartMessage } from '../claude-code-bridge-protocol';
2
2
 
3
3
  type BuiltinToolFiltering = StartMessage['builtinToolFiltering'];
4
4
 
5
- const PUBLIC_TO_NATIVE: Readonly<Record<string, string>> = {
5
+ export const PUBLIC_TO_NATIVE: Readonly<Record<string, string>> = {
6
6
  read: 'Read',
7
7
  write: 'Write',
8
8
  edit: 'Edit',