Skip to content

Commit 1ea52f5

Browse files
committed
fix(agents): preserve fallback tool-call hints
1 parent cafbd74 commit 1ea52f5

2 files changed

Lines changed: 12 additions & 4 deletions

File tree

src/agents/command/attempt-execution.helpers.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@ import {
1212
startsWithSilentToken,
1313
stripLeadingSilentToken,
1414
} from "../../auto-reply/tokens.js";
15-
import { resolveToolUseId, type ToolContentBlock } from "../../chat/tool-content.js";
15+
import {
16+
isToolCallBlock,
17+
resolveToolUseId,
18+
type ToolContentBlock,
19+
} from "../../chat/tool-content.js";
1620
import {
1721
type ClaudeCliFallbackSeed,
1822
readClaudeCliFallbackSeed,
@@ -320,7 +324,7 @@ function extractFallbackTurnText(message: FallbackTurnLikeMessage): string {
320324
// Tool calls: render as a compact "(tool: name)" hint so the fallback
321325
// model sees the conversation flow without the full tool argument blob,
322326
// which is rarely useful out of context and chews through char budget.
323-
if (rec.type === "tool_use" && typeof rec.name === "string") {
327+
if (isToolCallBlock(rec) && typeof rec.name === "string") {
324328
parts.push(`(tool call: ${rec.name})`);
325329
continue;
326330
}

src/agents/command/attempt-execution.test.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ describe("formatClaudeCliFallbackPrelude", () => {
166166
role: "assistant",
167167
content: [
168168
{ type: "text", text: "Earlier assistant reply" },
169-
{ type: "tool_use", name: "Bash" },
169+
{ type: "toolcall", name: "Bash" },
170170
],
171171
},
172172
{
@@ -269,7 +269,10 @@ describe("buildClaudeCliFallbackContextPrelude", () => {
269269
message: {
270270
role: "assistant",
271271
model: "claude-sonnet-4-6",
272-
content: [{ type: "text", text: "prior answer about blue-green" }],
272+
content: [
273+
{ type: "text", text: "prior answer about blue-green" },
274+
{ type: "tool_use", id: "toolu_1", name: "Bash", input: { command: "pwd" } },
275+
],
273276
},
274277
},
275278
];
@@ -285,6 +288,7 @@ describe("buildClaudeCliFallbackContextPrelude", () => {
285288
expect(prelude).toContain("## Prior session context (from claude-cli)");
286289
expect(prelude).toContain("user: prior question about deploys");
287290
expect(prelude).toContain("assistant: prior answer about blue-green");
291+
expect(prelude).toContain("(tool call: Bash)");
288292
} finally {
289293
await fs.rm(tmpHome, { recursive: true, force: true });
290294
}

0 commit comments

Comments
 (0)