The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 22, 03:15 UTC
fix(opencode): edits that delete text keep their empty replacement (#30643)
Co-authored-by: johan vaz <johanvaz@Nathalines-MacBook-Pro.local> Co-authored-by: GPT-6.1 Sol (Codex) <noreply@openai.com>
Johan Vaz committed
Nov 6, 2026 at 12:34 UTC
28aed0dcb986ba1f834e9a26d82eb856a4c787fd
2 files changed
+62
-3
packages/provider-opencode/src/server/toolItems.test.ts
+52
-1
@@ -1,3 +1,5 @@
1
+import { ThreadId, TurnItemId } from "@t3tools/contracts";
2
+import * as DateTime from "effect/DateTime";
3
import { describe, expect, it } from "vite-plus/test";
4
import {
5
MAX_TOOL_OUTPUT_IMAGES,
@@ -5,7 +7,7 @@ import {
7
toolOutputImages,
8
} from "@t3tools/shared/toolOutput";
9
8
-import { openCodeToolOutput } from "./toolItems.ts";
10
+import { openCodeToolOutput, openCodeToolTurnItem } from "./toolItems.ts";
11
12
describe("openCodeToolOutput", () => {
13
it("preserves inline raster file content and leaves other files unserved", () => {
@@ -41,3 +43,52 @@ describe("openCodeToolOutput", () => {
43
expect(images[1]?.data).toBe("AQ==");
44
});
45
});
46
+
47
+describe("openCodeToolTurnItem", () => {
48
+ it.each([
49
+ {
50
+ name: "deletion",
51
+ toolName: "edit",
52
+ input: { oldString: "old\n", newString: "", newText: "fallback" },
53
+ expected: { oldStr: "old\n", newStr: "" },
54
+ },
55
+ {
56
+ name: "whitespace replacement",
57
+ toolName: "edit",
58
+ input: { oldString: " \t", newString: "\n\t" },
59
+ expected: { oldStr: " \t", newStr: "\n\t" },
60
+ },
61
+ {
62
+ name: "empty write",
63
+ toolName: "write",
64
+ input: { content: "" },
65
+ expected: { newStr: "" },
66
+ },
67
+ ])("preserves exact file content for $name", ({ toolName, input, expected }) => {
68
+ const item = openCodeToolTurnItem(
69
+ {
70
+ id: TurnItemId.make("tool-item"),
71
+ threadId: ThreadId.make("thread"),
72
+ runId: null,
73
+ nodeId: null,
74
+ providerThreadId: null,
75
+ providerTurnId: null,
76
+ nativeItemRef: null,
77
+ parentItemId: null,
78
+ ordinal: 0,
79
+ status: "completed",
80
+ title: toolName,
81
+ startedAt: null,
82
+ completedAt: null,
83
+ updatedAt: DateTime.makeUnsafe("2026-11-04T00:00:00Z"),
84
+ },
85
+ {
86
+ name: toolName,
87
+ input: { filePath: "src/index.ts", ...input },
88
+ output: undefined,
89
+ completedMetadata: undefined,
90
+ },
91
+ );
92
+ expect(item).toMatchObject({ type: "file_change", fileName: "src/index.ts", ...expected });
93
+ });
94
+});
packages/provider-opencode/src/server/toolItems.ts
+10
-2
@@ -73,6 +73,14 @@ function recordString(input: unknown, ...keys: ReadonlyArray<string>): string |
73
return undefined;
74
}
75
76
+function recordText(input: Record<string, unknown>, ...keys: ReadonlyArray<string>) {
77
+ for (const key of keys) {
78
+ const value = input[key];
79
+ if (typeof value === "string") return value;
80
+ }
81
+ return undefined;
82
+}
83
+
84
function recordNumber(input: unknown, ...keys: ReadonlyArray<string>): number | undefined {
85
if (typeof input !== "object" || input === null) return undefined;
86
for (const key of keys) {
@@ -137,8 +145,8 @@ export function openCodeToolTurnItem(
145
};
146
}
147
case "file_change": {
140
- const oldStr = recordString(input, "oldString", "oldText");
141
- const newStr = recordString(input, "newString", "content", "newText");
148
+ const oldStr = recordText(input, "oldString", "oldText");
149
+ const newStr = recordText(input, "newString", "content", "newText");
150
const diffStr =
151
recordString(tool.completedMetadata, "diff", "patch") ??
152
(base.status === "failed" && output?.trim() ? output : undefined);