Replay completed tool results from provider history

This commit is contained in:
Mohamed Boudra
2026-05-26 11:36:27 +07:00
parent bde0efc9b0
commit 483790d8c9
2 changed files with 45 additions and 2 deletions
@@ -56,6 +56,49 @@ describe("convertClaudeHistoryEntry", () => {
expect(Array.isArray(mapBlocks.mock.calls[0][0])).toBe(true);
});
test("replays persisted Claude tool results as completed tool calls", () => {
const entry = {
type: "user",
message: {
role: "user",
content: [
{
type: "tool_result",
tool_use_id: "toolu_persisted",
content: "done",
},
],
},
toolUseResult: {
stdout: "done",
stderr: "",
interrupted: false,
},
};
const completedToolCall: AgentTimelineItem[] = [
{
type: "tool_call",
callId: "toolu_persisted",
name: "Bash",
status: "completed",
detail: {
type: "shell",
command: "echo done",
output: "done",
exitCode: 0,
},
error: null,
},
];
const mapPersistedToolResultBlocks = (): AgentTimelineItem[] => completedToolCall;
expect(convertClaudeHistoryEntry(entry, mapPersistedToolResultBlocks)).toEqual(
completedToolCall,
);
});
test("returns user messages when no tool blocks exist", () => {
const entry = {
type: "user",
@@ -1188,7 +1188,7 @@ function isToolResultUserEntry(entry: unknown): boolean {
}
function isSyntheticHistoryUserEntry(entry: Record<string, unknown>): boolean {
return isSyntheticUserEntry(entry);
return isSyntheticUserEntry(entry) && !isToolResultUserEntry(entry);
}
function firstTrimmedString(sources: readonly unknown[]): string | null {
@@ -4666,7 +4666,7 @@ function convertClaudeHistoryEntryPreamble(
if (entry.isCompactSummary) {
return { shortCircuit: [] };
}
if (entry.type === "user" && isSyntheticUserEntry(entry)) {
if (entry.type === "user" && isSyntheticHistoryUserEntry(entry)) {
return { shortCircuit: [] };
}