Skip to content

Commit ed0e183

Browse files
committed
fix(web): show incomplete and content-only tool call output
1 parent 4e5b4f1 commit ed0e183

5 files changed

Lines changed: 115 additions & 14 deletions

File tree

‎apps/server/src/orchestration-v2/WireProjection.test.ts‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,12 @@ describe("orchestration V2 wire projection", () => {
278278
expect(projectTurnItemForDetail(item)).toMatchObject({ diffStr: "+new code" });
279279
expect(projectTurnItemForDetail(item)).not.toHaveProperty("oldStr");
280280
expect(projectTurnItemForDetail(item)).not.toHaveProperty("newStr");
281+
const { diffStr: _diff, ...contentOnly } = item;
282+
expect(projectTurnItemForDetail(contentOnly)).toMatchObject({
283+
oldStr: "old code",
284+
newStr: "new code",
285+
});
286+
expect(projectTurnItemForWire(contentOnly)).not.toHaveProperty("newStr");
281287
const failed = projectTurnItemForWire({
282288
...item,
283289
status: "failed",

‎apps/server/src/orchestration-v2/WireProjection.ts‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,12 @@ export function projectTurnItemForDetail(item: OrchestrationV2TurnItem): Orchest
206206
...(item.diffStr === undefined
207207
? {}
208208
: { diffStr: truncateDetail(item.diffStr, MAX_ON_DEMAND_BYTES) }),
209+
...(!item.diffStr?.trim() && item.oldStr !== undefined
210+
? { oldStr: truncateDetail(item.oldStr, MAX_ON_DEMAND_BYTES) }
211+
: {}),
212+
...(!item.diffStr?.trim() && item.newStr !== undefined
213+
? { newStr: truncateDetail(item.newStr, MAX_ON_DEMAND_BYTES) }
214+
: {}),
209215
};
210216
case "handoff":
211217
return projectTurnItemForWire(item);

‎apps/web/src/components/DiffPanel.tsx‎

Lines changed: 42 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import { useOpenInPreferredEditor } from "../editorPreferences";
2626
import { useFileContextMenuHandler } from "../fileContextMenu";
2727
import { type DraftId } from "../composerDraftStore";
2828
import { openDiffFilePrimaryAction } from "../diffFileActions";
29-
import { toolCallPatch } from "../lib/toolCallDiff";
29+
import { toolCallDiff } from "../lib/toolCallDiff";
3030
import { useCheckpointDiff, useTurnItemDetail } from "~/state/queries";
3131
import { revisionedQuery } from "~/state/revisionedQuery";
3232
import { cn } from "~/lib/utils";
@@ -371,14 +371,16 @@ export default function DiffPanel({
371371
const preview = branchDiffPreview.data;
372372
const gitDiff = selectedGitSource?.diff;
373373

374+
const toolCallPreview =
375+
toolCallSelection && toolCallItem?.type === "file_change" ? toolCallDiff(toolCallItem) : null;
374376
const selectedPatch = toolCallSelection
375-
? toolCallItem?.type === "file_change"
376-
? toolCallPatch(toolCallItem)
377-
: undefined
377+
? toolCallPreview?.patch
378378
: selectedTurn
379379
? activeCheckpointDiff.data?.diff
380380
: gitDiff;
381-
const isSelectedPatchTruncated = isGitSelection && selectedGitSource?.truncated === true;
381+
const isSelectedPatchTruncated =
382+
toolCallPreview?.truncated === true ||
383+
(isGitSelection && selectedGitSource?.truncated === true);
382384
const selectedPatchQuery = toolCallSelection
383385
? toolCallDetail
384386
: selectedTurn
@@ -404,6 +406,14 @@ export default function DiffPanel({
404406
...(toolCallSelection ? { ignoreWhitespace: diffIgnoreWhitespace } : {}),
405407
},
406408
);
409+
const recordedToolCallFileCount =
410+
toolCallSelection && toolCallItem?.type === "file_change"
411+
? (toolCallItem.changes?.length ?? 0)
412+
: 0;
413+
const omittedToolCallFiles =
414+
renderablePatch?.kind === "files"
415+
? Math.max(0, recordedToolCallFileCount - renderablePatch.files.length)
416+
: 0;
407417
const fileStats = new Map(lazySource?.files?.map((file) => [file.path, file]));
408418
const sourceLineStat =
409419
isGitSelection && selectedGitSource?.files
@@ -1023,15 +1033,40 @@ export default function DiffPanel({
10231033
{isSelectedPatchTruncated && !lazySource && (
10241034
<p className="shrink-0 border-b border-border/70 bg-muted/40 px-3 py-1.5 text-2xs text-muted-foreground">
10251035
This preview exceeds the size limit. Changes shown are incomplete.
1026-
{selectedGitSource?.files ? " Totals include all changes." : ""}
1036+
{isGitSelection && selectedGitSource?.files ? " Totals include all changes." : ""}
1037+
</p>
1038+
)}
1039+
{omittedToolCallFiles > 0 && (
1040+
<p className="shrink-0 border-b border-border/70 bg-muted/40 px-3 py-1.5 text-2xs text-muted-foreground">
1041+
This tool call changed {recordedToolCallFileCount} files. The recorded patch omits{" "}
1042+
{omittedToolCallFiles} of them.
10271043
</p>
10281044
)}
10291045
{selectedPatchError && !renderablePatch && (
10301046
<div className="px-3">
10311047
<p className="mb-2 text-2xs text-error/80">{selectedPatchError}</p>
10321048
</div>
10331049
)}
1034-
{!renderablePatch && !lazySource ? (
1050+
{!renderablePatch && toolCallPreview && toolCallPreview.content.length > 0 ? (
1051+
<div className="min-h-0 flex-1 space-y-3 overflow-auto p-3 text-xs">
1052+
<p className="text-muted-foreground">
1053+
The provider recorded file content without a diff.
1054+
</p>
1055+
{toolCallPreview.content.map(({ label, text }) => (
1056+
<div key={label} className="space-y-1">
1057+
<p className="text-muted-foreground">{label}</p>
1058+
<pre
1059+
className={cn(
1060+
"overflow-auto font-mono text-2xs",
1061+
wordWrap && "whitespace-pre-wrap wrap-break-word",
1062+
)}
1063+
>
1064+
{text === "" ? "Empty content." : text}
1065+
</pre>
1066+
</div>
1067+
))}
1068+
</div>
1069+
) : !renderablePatch && !lazySource ? (
10351070
isLoadingSelectedPatch ? (
10361071
<DiffPanelLoadingState
10371072
label={

‎apps/web/src/lib/toolCallDiff.test.ts‎

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import { describe, expect, it } from "vite-plus/test";
22
import { getRenderablePatch, resolveFileDiffPath } from "./diffRendering";
3-
import { toolCallPatch } from "./toolCallDiff";
3+
import { toolCallDiff } from "./toolCallDiff";
44

5-
describe("toolCallPatch", () => {
5+
describe("toolCallDiff", () => {
66
it("renders recorded hunks without reading a repository, including renamed paths", () => {
77
for (const changes of [
88
undefined,
99
[{ operation: "update", oldPath: "old.ts", path: "new.ts" }],
1010
]) {
11-
const patch = toolCallPatch({
11+
const { patch } = toolCallDiff({
1212
fileName: "old.ts",
1313
diffStr: "@@ -1 +1 @@\n-before\n+after\n",
1414
...(changes ? { changes } : {}),
@@ -27,11 +27,11 @@ describe("toolCallPatch", () => {
2727
for (const operation of ["add", "delete"]) {
2828
for (const ending of ["", "\n"]) {
2929
const rendered = getRenderablePatch(
30-
toolCallPatch({
30+
toolCallDiff({
3131
fileName: "file with spaces.ts",
3232
diffStr: `first\nsecond${ending}`,
3333
changes: [{ operation, path: "file with spaces.ts" }],
34-
}),
34+
}).patch,
3535
);
3636
expect(rendered?.kind).toBe("files");
3737
if (rendered?.kind !== "files") throw new Error("Expected a file diff");
@@ -42,6 +42,36 @@ describe("toolCallPatch", () => {
4242
}
4343
});
4444

45+
it("keeps content-only writes out of the patch and preserves empty recorded content", () => {
46+
expect(toolCallDiff({ fileName: "a.ts", oldStr: "before", newStr: "" })).toEqual({
47+
patch: undefined,
48+
content: [
49+
{ label: "Recorded content before", text: "before" },
50+
{ label: "Recorded content after", text: "" },
51+
],
52+
truncated: false,
53+
});
54+
expect(toolCallDiff({ fileName: "a.ts", newStr: "after" }).content).toEqual([
55+
{ label: "Recorded content after", text: "after" },
56+
]);
57+
});
58+
59+
it("removes transport truncation markers before converting file contents", () => {
60+
const suffix = "\n… output truncated for transport";
61+
const diff = toolCallDiff({
62+
fileName: "a.ts",
63+
diffStr: `first\nsecond${suffix}`,
64+
changes: [{ operation: "add", path: "a.ts" }],
65+
});
66+
expect(diff.truncated).toBe(true);
67+
expect(diff.patch).not.toContain("output truncated");
68+
expect(getRenderablePatch(diff.patch)?.kind).toBe("files");
69+
expect(toolCallDiff({ fileName: "a.ts", newStr: `content${suffix}` })).toMatchObject({
70+
content: [{ label: "Recorded content after", text: "content" }],
71+
truncated: true,
72+
});
73+
});
74+
4575
it("preserves complete patches and unsupported provider output", () => {
4676
for (const diffStr of [
4777
undefined,
@@ -50,7 +80,7 @@ describe("toolCallPatch", () => {
5080
"--- a/a.ts\n+++ b/a.ts\n@@ -1 +1 @@\n-a\n+b\n",
5181
]) {
5282
expect(
53-
toolCallPatch({ fileName: "a.ts", ...(diffStr === undefined ? {} : { diffStr }) }),
83+
toolCallDiff({ fileName: "a.ts", ...(diffStr === undefined ? {} : { diffStr }) }).patch,
5484
).toBe(diffStr);
5585
}
5686
});

‎apps/web/src/lib/toolCallDiff.ts‎

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type { OrchestrationV2TurnItem } from "@t3tools/contracts";
22

33
type FileChange = Extract<OrchestrationV2TurnItem, { type: "file_change" }>;
44

5-
export function toolCallPatch(item: Pick<FileChange, "diffStr" | "fileName" | "changes">) {
5+
function toolCallPatch(item: Pick<FileChange, "diffStr" | "fileName" | "changes">) {
66
let patch = item.diffStr;
77
if (!patch || patch.startsWith("diff --git ") || patch.startsWith("--- ")) return patch;
88
const change = item.changes?.[0];
@@ -22,3 +22,27 @@ export function toolCallPatch(item: Pick<FileChange, "diffStr" | "fileName" | "c
2222
const after = change?.operation === "delete" ? "/dev/null" : JSON.stringify(`b/${newPath}`);
2323
return `diff --git ${JSON.stringify(`a/${oldPath}`)} ${JSON.stringify(`b/${newPath}`)}\n--- ${before}\n+++ ${after}\n${patch.trimStart()}`;
2424
}
25+
26+
function recordedText(value: string | undefined) {
27+
const suffix = "\n… output truncated for transport";
28+
const truncated = value !== undefined && value.endsWith(suffix);
29+
return { text: truncated ? value.slice(0, -suffix.length) : value, truncated };
30+
}
31+
32+
export function toolCallDiff(
33+
item: Pick<FileChange, "diffStr" | "fileName" | "changes" | "oldStr" | "newStr">,
34+
) {
35+
const diff = recordedText(item.diffStr);
36+
const before = recordedText(item.oldStr);
37+
const after = recordedText(item.newStr);
38+
return {
39+
patch: toolCallPatch({ ...item, ...(diff.text === undefined ? {} : { diffStr: diff.text }) }),
40+
content: diff.text?.trim()
41+
? []
42+
: [
43+
{ label: "Recorded content before", text: before.text },
44+
{ label: "Recorded content after", text: after.text },
45+
].filter((entry): entry is { label: string; text: string } => entry.text !== undefined),
46+
truncated: diff.truncated || before.truncated || after.truncated,
47+
};
48+
}

0 commit comments

Comments
 (0)