@devries-cameron20 / t3code Mirror · read-only / commits / eb565e13ab
Fork 0

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, 13:15 UTC

fix(claude): Open diff shows Claude edits as a diff instead of raw JSON (#26529)

Shoubhit Dash committed Oct 29, 2026 at 10:24 UTC eb565e13abebe1a71736b4651e4131f52b1950ba
4 files changed +192 -1
apps/server/package.json
+1
@@ -58,6 +58,7 @@
58 "@t3tools/source-control-github": "workspace:*",
59 "@t3tools/source-control-gitlab": "workspace:*",
60 "character-entities": "2.0.2",
61 + "diff": "8.0.3",
62 "effect": "catalog:",
63 "jose": "catalog:",
64 "node-pty": "^1.2.0-beta.15",
apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts
+146
@@ -8740,6 +8740,152 @@ describe("ClaudeAdapterV2 background wake turns", () => {
8740 ),
8741 );
8742
8743 + it.effect.each([
8744 + {
8745 + case: "an Edit",
8746 + toolName: "Edit",
8747 + toolInput: {
8748 + file_path: "/workspace/src/math.ts",
8749 + old_string: " return a - b;",
8750 + new_string: " return a + b;",
8751 + },
8752 + toolUseResult: {
8753 + filePath: "/workspace/src/math.ts",
8754 + oldString: " return a - b;",
8755 + newString: " return a + b;",
8756 + originalFile: "export function add(a: number, b: number) {\n return a - b;\n}\n",
8757 + structuredPatch: [
8758 + {
8759 + oldStart: 1,
8760 + oldLines: 3,
8761 + newStart: 1,
8762 + newLines: 3,
8763 + lines: [
8764 + " export function add(a: number, b: number) {",
8765 + "- return a - b;",
8766 + "+ return a + b;",
8767 + " }",
8768 + ],
8769 + },
8770 + ],
8771 + userModified: false,
8772 + replaceAll: false,
8773 + },
8774 + diffStr:
8775 + "--- /workspace/src/math.ts\n+++ /workspace/src/math.ts\n@@ -1,3 +1,3 @@\n export function add(a: number, b: number) {\n- return a - b;\n+ return a + b;\n }\n",
8776 + },
8777 + {
8778 + case: "a Write that creates a file",
8779 + toolName: "Write",
8780 + toolInput: { file_path: "/workspace/notes.md", content: "# Notes\n\nShip it.\n" },
8781 + toolUseResult: {
8782 + type: "create",
8783 + filePath: "/workspace/notes.md",
8784 + content: "# Notes\n\nShip it.\n",
8785 + structuredPatch: [],
8786 + originalFile: null,
8787 + userModified: false,
8788 + },
8789 + diffStr: "--- /dev/null\n+++ /workspace/notes.md\n@@ -0,0 +1,3 @@\n+# Notes\n+\n+Ship it.\n",
8790 + },
8791 + {
8792 + case: "a Write that creates an empty file",
8793 + toolName: "Write",
8794 + toolInput: { file_path: "/workspace/.keep", content: "" },
8795 + toolUseResult: {
8796 + type: "create",
8797 + filePath: "/workspace/.keep",
8798 + content: "",
8799 + structuredPatch: [],
8800 + originalFile: null,
8801 + userModified: false,
8802 + },
8803 + diffStr: undefined,
8804 + },
8805 + ])("stores the diff panel patch for $case", (testCase) =>
8806 + Effect.scoped(
8807 + Effect.gen(function* () {
8808 + const harness = yield* makeWakeHarness;
8809 + const toolUseId = `toolu_01${testCase.toolName}Patch`;
8810 +
8811 + yield* harness.runtime.startTurn(
8812 + makeClaudeTestTurnInput({
8813 + threadId: harness.threadId,
8814 + providerThread: harness.providerThread,
8815 + now: yield* DateTime.now,
8816 + attemptId: RunAttemptId.make(`attempt-claude-${testCase.toolName}-patch`),
8817 + text: "Change it.",
8818 + attachments: [],
8819 + }),
8820 + );
8821 + yield* Queue.offer(
8822 + harness.sdkMessages,
8823 + claudeSdkFrame({
8824 + type: "assistant",
8825 + message: {
8826 + model: "claude-sonnet-4-6",
8827 + id: `msg_${testCase.toolName}_patch`,
8828 + type: "message",
8829 + role: "assistant",
8830 + content: [
8831 + {
8832 + type: "tool_use",
8833 + id: toolUseId,
8834 + name: testCase.toolName,
8835 + input: testCase.toolInput,
8836 + },
8837 + ],
8838 + },
8839 + parent_tool_use_id: null,
8840 + uuid: "00000000-0000-4000-8000-000000000793",
8841 + session_id: WAKE_NATIVE_SESSION,
8842 + }),
8843 + );
8844 + yield* Queue.offer(
8845 + harness.sdkMessages,
8846 + claudeSdkFrame({
8847 + type: "user",
8848 + message: {
8849 + role: "user",
8850 + content: [
8851 + {
8852 + type: "tool_result",
8853 + tool_use_id: toolUseId,
8854 + content: `The file ${testCase.toolInput.file_path} has been updated successfully.`,
8855 + },
8856 + ],
8857 + },
8858 + parent_tool_use_id: null,
8859 + uuid: "00000000-0000-4000-8000-000000000794",
8860 + session_id: WAKE_NATIVE_SESSION,
8861 + tool_use_result: testCase.toolUseResult,
8862 + }),
8863 + );
8864 + yield* Queue.offer(
8865 + harness.sdkMessages,
8866 + makeResultFrame({ uuid: "00000000-0000-4000-8000-000000000795", result: "Done." }),
8867 + );
8868 + yield* harness.awaitTerminal(1);
8869 +
8870 + const fileChange = harness.events.findLast(
8871 + (event) =>
8872 + event.type === "turn_item.updated" &&
8873 + event.turnItem.nativeItemRef?.nativeId === toolUseId,
8874 + );
8875 + assert.deepEqual(
8876 + fileChange?.type === "turn_item.updated" && fileChange.turnItem.type === "file_change"
8877 + ? { diffStr: fileChange.turnItem.diffStr }
8878 + : undefined,
8879 + { diffStr: testCase.diffStr },
8880 + );
8881 + }).pipe(
8882 + Effect.provide(
8883 + Layer.mergeAll(IdAllocator.layer, McpProviderSessions.layer, NodeServices.layer),
8884 + ),
8885 + ),
8886 + ),
8887 + );
8888 +
8889 it.effect("answers an approval a held wake turn raises without waiting for the echo", () =>
8890 Effect.scoped(
8891 Effect.gen(function* () {
apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts
+42 -1
@@ -106,6 +106,7 @@ import {
106 resolveIdleCompaction,
107 } from "@t3tools/contracts";
108
109 +import { FILE_HEADERS_ONLY, formatPatch, structuredPatch } from "diff";
110 import * as Cause from "effect/Cause";
111 import * as Clock from "effect/Clock";
112 import * as Context from "effect/Context";
@@ -2965,6 +2966,44 @@ function claudeNativeToolOutputText(output: ClaudeNativeToolOutput): string {
2966 return typeof value === "string" ? value : value === undefined ? "" : jsonStringifyForTool(value);
2967 }
2968
2969 +const decodeClaudeFileEditResult = Schema.decodeUnknownOption(
2970 + Schema.Struct({
2971 + type: Schema.optional(Schema.String),
2972 + filePath: Schema.String,
2973 + content: Schema.optional(Schema.String),
2974 + structuredPatch: Schema.mutable(
2975 + Schema.Array(
2976 + Schema.Struct({
2977 + oldStart: Schema.Number,
2978 + oldLines: Schema.Number,
2979 + newStart: Schema.Number,
2980 + newLines: Schema.Number,
2981 + lines: Schema.mutable(Schema.Array(Schema.String)),
2982 + }),
2983 + ),
2984 + ),
2985 + }),
2986 +);
2987 +
2988 +function claudeFileChangeText(output: ClaudeNativeToolOutput): string {
2989 + const result =
2990 + output.type === "structured_tool_use_result"
2991 + ? Option.getOrUndefined(decodeClaudeFileEditResult(output.value))
2992 + : undefined;
2993 + if (result === undefined) return claudeNativeToolOutputText(output);
2994 + const patch =
2995 + result.structuredPatch.length === 0 && result.type === "create" && result.content !== undefined
2996 + ? structuredPatch("/dev/null", result.filePath, "", result.content)
2997 + : {
2998 + oldFileName: result.filePath,
2999 + newFileName: result.filePath,
3000 + oldHeader: undefined,
3001 + newHeader: undefined,
3002 + hunks: result.structuredPatch,
3003 + };
3004 + return patch.hunks.length === 0 ? "" : formatPatch(patch, FILE_HEADERS_ONLY);
3005 +}
3006 +
3007 function claudeCommandOutputText(output: ClaudeNativeToolOutput): string {
3008 const value = claudeNativeToolOutputValue(output);
3009 if (typeof value === "object" && value !== null) {
@@ -5498,7 +5537,9 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
5537 const outputText =
5538 itemType === "command_execution"
5539 ? claudeCommandOutputText(input.output)
5501 - : claudeNativeToolOutputText(input.output);
5540 + : itemType === "file_change"
5541 + ? claudeFileChangeText(input.output)
5542 + : claudeNativeToolOutputText(input.output);
5543 const turnItem: OrchestrationV2TurnItem =
5544 itemType === "command_execution"
5545 ? {
pnpm-lock.yaml
+3
@@ -897,6 +897,9 @@ importers:
897 character-entities:
898 specifier: 2.0.2
899 version: 2.0.2
900 + diff:
901 + specifier: 8.0.3
902 + version: 8.0.3
903 effect:
904 specifier: 4.0.5
905 version: 4.0.5