@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/CHANGELOG.md CHANGED
@@ -1,5 +1,22 @@
1
1
  # @ai-sdk/harness-claude-code
2
2
 
3
+ ## 1.0.201
4
+
5
+ ### Patch Changes
6
+
7
+ - 3435be9: fix(harness-claude-code): route bare-name host tool calls through built-in tool aliases and classify them as host-executed calls throughout streaming and permission handling
8
+ - 4bd3cb2: fix(harness-claude-code): preserve selected `AskUserQuestion` options when an answer also includes free-form text by sending the text as per-question notes
9
+ - Updated dependencies [743e15b]
10
+ - @ai-sdk/provider-utils@5.0.86
11
+ - @ai-sdk/harness@1.0.197
12
+
13
+ ## 1.0.200
14
+
15
+ ### Patch Changes
16
+
17
+ - Updated dependencies [974e80e]
18
+ - @ai-sdk/harness@1.0.196
19
+
3
20
  ## 1.0.199
4
21
 
5
22
  ### Patch Changes
@@ -904,6 +904,13 @@ function toClaudeSkillsOption(skills) {
904
904
  return skills && skills.length > 0 ? "all" : void 0;
905
905
  }
906
906
  //#endregion
907
+ //#region src/bridge/host-tool-names.ts
908
+ const HOST_TOOL_PREFIX = "mcp__harness-tools__";
909
+ function resolveHostToolName(toolName, toolAliases) {
910
+ const resolvedName = toolAliases != null && Object.hasOwn(toolAliases, toolName) ? toolAliases[toolName] : toolName;
911
+ return resolvedName.startsWith("mcp__harness-tools__") ? resolvedName.slice(20) : void 0;
912
+ }
913
+ //#endregion
907
914
  //#region src/bridge/create-emit-stream-event.ts
908
915
  function createClaudeStreamEventState() {
909
916
  return {
@@ -934,7 +941,6 @@ const UNRECOVERABLE_API_RETRY_STATUSES = /* @__PURE__ */ new Set([
934
941
  403,
935
942
  404
936
943
  ]);
937
- const HOST_TOOL_PREFIX = "mcp__harness-tools__";
938
944
  const RAW_TASK_MESSAGE_SUBTYPES = /* @__PURE__ */ new Set([
939
945
  "background_tasks_changed",
940
946
  "task_started",
@@ -943,9 +949,9 @@ const RAW_TASK_MESSAGE_SUBTYPES = /* @__PURE__ */ new Set([
943
949
  "task_notification"
944
950
  ]);
945
951
  function isExternalMcpTool(nativeName) {
946
- return nativeName.startsWith("mcp__") && !nativeName.startsWith(HOST_TOOL_PREFIX);
952
+ return nativeName.startsWith("mcp__") && !nativeName.startsWith("mcp__harness-tools__");
947
953
  }
948
- function createEmitStreamEvent({ state, emit, emitWarning, emitTerminalError, onCompactionBoundary, toCommonName }) {
954
+ function createEmitStreamEvent({ state, emit, emitWarning, emitTerminalError, onCompactionBoundary, toCommonName, toHostToolName = resolveHostToolName }) {
949
955
  let streamStarted = false;
950
956
  return (msg) => {
951
957
  const type = msg.type;
@@ -1019,7 +1025,8 @@ function createEmitStreamEvent({ state, emit, emitWarning, emitTerminalError, on
1019
1025
  message: msg,
1020
1026
  state,
1021
1027
  send: emit,
1022
- toCommonName
1028
+ toCommonName,
1029
+ toHostToolName
1023
1030
  });
1024
1031
  return;
1025
1032
  }
@@ -1034,8 +1041,8 @@ function createEmitStreamEvent({ state, emit, emitWarning, emitTerminalError, on
1034
1041
  state.structuredOutputToolUseIds.add(block.id);
1035
1042
  continue;
1036
1043
  }
1037
- if (block.name.startsWith(HOST_TOOL_PREFIX)) {
1038
- const hostToolName = block.name.slice(20);
1044
+ const hostToolName = toHostToolName(block.name);
1045
+ if (hostToolName !== void 0) {
1039
1046
  state.pendingStepToolUseIds.add(block.id);
1040
1047
  state.mcpToolCalls.set(block.id, {
1041
1048
  toolName: hostToolName,
@@ -1263,7 +1270,7 @@ function formatApiRetryWarning(msg) {
1263
1270
  if (msg.error) details.push(msg.error);
1264
1271
  return details.length > 0 ? `Claude Code API retry: ${details.join("; ")}` : "Claude Code API retry";
1265
1272
  }
1266
- function handleStreamEvent({ event, message, state, send, toCommonName }) {
1273
+ function handleStreamEvent({ event, message, state, send, toCommonName, toHostToolName }) {
1267
1274
  if (!event) return;
1268
1275
  if (event.type === "message_start") {
1269
1276
  state.modelResponseStreaming = true;
@@ -1327,7 +1334,7 @@ function handleStreamEvent({ event, message, state, send, toCommonName }) {
1327
1334
  const nativeName = event.content_block.name;
1328
1335
  if (nativeName === "StructuredOutput") return;
1329
1336
  if (nativeName === "AskUserQuestion") return;
1330
- const hostToolName = nativeName.startsWith(HOST_TOOL_PREFIX) ? nativeName.slice(20) : void 0;
1337
+ const hostToolName = toHostToolName(nativeName);
1331
1338
  const dynamic = isExternalMcpTool(nativeName);
1332
1339
  partialBlocks.set(index, {
1333
1340
  id,
@@ -1668,26 +1675,34 @@ function toClaudeCodeQuestionResult(input) {
1668
1675
  message: `The user ${output.action} the questions.`
1669
1676
  };
1670
1677
  const canonicalInput = toHarnessQuestionsInput(input.nativeInput);
1678
+ const annotations = /* @__PURE__ */ new Map();
1671
1679
  const answers = Object.fromEntries(canonicalInput.questions.flatMap((question, questionIndex) => {
1672
1680
  const answer = output.answers[question.id];
1673
1681
  if (answer == null) return [];
1674
1682
  const nativeQuestion = input.nativeInput.questions[questionIndex];
1675
- return [[nativeQuestion.question, toClaudeCodeAnswer({
1683
+ const selectedAnswer = toClaudeCodeAnswer({
1676
1684
  nativeQuestion,
1677
- optionIds: answer.optionIds,
1678
- freeform: answer.freeform
1679
- })]];
1685
+ optionIds: answer.optionIds
1686
+ });
1687
+ if (selectedAnswer !== "" && answer.freeform !== void 0) annotations.set(nativeQuestion.question, {
1688
+ ...input.nativeInput.annotations?.[nativeQuestion.question],
1689
+ notes: answer.freeform
1690
+ });
1691
+ return [[nativeQuestion.question, selectedAnswer === "" ? answer.freeform ?? "" : selectedAnswer]];
1680
1692
  }));
1681
1693
  return {
1682
1694
  behavior: "allow",
1683
1695
  updatedInput: {
1684
1696
  ...input.nativeInput,
1685
- answers
1697
+ answers,
1698
+ ...annotations.size > 0 ? { annotations: {
1699
+ ...input.nativeInput.annotations,
1700
+ ...Object.fromEntries(annotations)
1701
+ } } : {}
1686
1702
  }
1687
1703
  };
1688
1704
  }
1689
1705
  function toClaudeCodeAnswer(input) {
1690
- if (input.freeform !== void 0) return input.freeform;
1691
1706
  const labels = input.optionIds.flatMap((optionId) => {
1692
1707
  const index = positionalIdIndex({
1693
1708
  id: optionId,
@@ -1826,8 +1841,9 @@ function createPermissionOptions(input) {
1826
1841
  return {
1827
1842
  ...baseOptions,
1828
1843
  canUseTool: async (toolName, toolInput, options) => {
1829
- if (toolName.startsWith("mcp__harness-tools__") || !autoMode && !await needsHostApproval({
1844
+ if (input.toHostToolName(toolName) !== void 0 || !autoMode && !await needsHostApproval({
1830
1845
  toolName,
1846
+ toHostToolName: input.toHostToolName,
1831
1847
  toolInput,
1832
1848
  permissionMode,
1833
1849
  inactiveNativeTools,
@@ -1960,7 +1976,7 @@ function createGatewayModelOverrides(model, env) {
1960
1976
  return Object.keys(overrides).length > 0 ? overrides : void 0;
1961
1977
  }
1962
1978
  async function needsHostApproval(input) {
1963
- if (input.toolName.startsWith("mcp__harness-tools__")) return false;
1979
+ if (input.toHostToolName(input.toolName) !== void 0) return false;
1964
1980
  if (input.inactiveNativeTools.has(input.toolName) || nativeToolRequiresApproval({
1965
1981
  nativeName: input.toolName,
1966
1982
  permissionMode: input.permissionMode
@@ -2055,6 +2071,7 @@ function createApprovalPreToolUseHook(input) {
2055
2071
  cwd: hookInput.cwd
2056
2072
  }) : await needsHostApproval({
2057
2073
  toolName,
2074
+ toHostToolName: input.toHostToolName,
2058
2075
  toolInput: hookInput.tool_input,
2059
2076
  cwd: hookInput.cwd,
2060
2077
  readableSkillRoots: input.readableSkillRoots,
@@ -2091,6 +2108,16 @@ async function runTurn(start, turn) {
2091
2108
  if (turn.abortSignal.aborted) abortCtl.abort();
2092
2109
  else turn.abortSignal.addEventListener("abort", onHostAbort, { once: true });
2093
2110
  const streamEventState = createClaudeStreamEventState();
2111
+ const reservedToolNames = /* @__PURE__ */ new Set([
2112
+ ...claudeAgentSdk.BUILTIN_TOOL_NAMES ?? [],
2113
+ ...Object.keys(claudeAgentSdk.LEGACY_TOOL_NAME_ALIASES ?? {}),
2114
+ ...Object.keys(NATIVE_TOOL_KINDS),
2115
+ ...Object.keys(NATIVE_TO_COMMON),
2116
+ ...Object.values(PUBLIC_TO_NATIVE),
2117
+ "StructuredOutput"
2118
+ ]);
2119
+ const toolAliases = Object.fromEntries((start.tools ?? []).filter((tool) => !reservedToolNames.has(tool.name) && !tool.name.startsWith("mcp__")).map((tool) => [tool.name, `${HOST_TOOL_PREFIX}${tool.name}`]));
2120
+ const toHostToolName = (toolName) => resolveHostToolName(toolName, toolAliases);
2094
2121
  const mcpServers = { ...start.mcpServers };
2095
2122
  if (start.tools && start.tools.length > 0) {
2096
2123
  const server = new mcpModule.McpServer({
@@ -2193,6 +2220,7 @@ async function runTurn(start, turn) {
2193
2220
  const approvalDecisions = /* @__PURE__ */ new Map();
2194
2221
  const toolCwds = /* @__PURE__ */ new Map();
2195
2222
  const permissionOptions = createPermissionOptions({
2223
+ toHostToolName,
2196
2224
  toolCwds,
2197
2225
  approvalDecisions,
2198
2226
  start,
@@ -2219,6 +2247,7 @@ async function runTurn(start, turn) {
2219
2247
  const modelOverrides = createGatewayModelOverrides(start.model, sdkEnv);
2220
2248
  const deferredToolUseIds = /* @__PURE__ */ new Set();
2221
2249
  const approvalPreToolUseHook = createApprovalPreToolUseHook({
2250
+ toHostToolName,
2222
2251
  toolCwds,
2223
2252
  readableSkillRoots: start.readableSkillRoots ?? [],
2224
2253
  additionalDirectories: start.additionalDirectories ?? [],
@@ -2285,6 +2314,7 @@ async function runTurn(start, turn) {
2285
2314
  ...permissionOptions,
2286
2315
  ...Object.keys(settings).length > 0 ? { settings } : {},
2287
2316
  mcpServers,
2317
+ ...Object.keys(toolAliases).length > 0 ? { toolAliases } : {},
2288
2318
  settingSources: ["user"],
2289
2319
  cwd: workdir,
2290
2320
  abortController: abortCtl
@@ -2365,7 +2395,8 @@ async function runTurn(start, turn) {
2365
2395
  emitWarning: turn.emitWarning,
2366
2396
  emitTerminalError,
2367
2397
  onCompactionBoundary: (boundary) => compaction.onBoundary(boundary),
2368
- toCommonName
2398
+ toCommonName,
2399
+ toHostToolName
2369
2400
  });
2370
2401
  async function* messages() {
2371
2402
  for (;;) {