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 21, 17:15 UTC
fix(acp): root tool content replacements replace streamed output (#35862)
Julius Marminge committed
Nov 12, 2026 at 19:31 UTC
15cf8b122c64710a763c39a61fff4ce614529a02
2 files changed
+101
-19
apps/server/src/orchestration-v2/Adapters/AcpRegistryAdapterV2.test.ts
+63
@@ -2090,6 +2090,69 @@ describe("AcpRegistryAdapterV2", () => {
2090
}).pipe(Effect.provide(layerTest), Effect.scoped),
2091
);
2092
2093
+ it.effect("replaces streamed root tool output with a later content list", () =>
2094
+ Effect.gen(function* () {
2095
+ const { update } = claudeFrames;
2096
+ const text = (value: string) => [{ type: "content", content: { type: "text", text: value } }];
2097
+ const session = yield* openClaudeReplaySession([
2098
+ ...claudeFrames.open,
2099
+ ...claudeFrames.prompt(1),
2100
+ update(CLAUDE_ROOT_SESSION, {
2101
+ sessionUpdate: "tool_call_update",
2102
+ toolCallId: "root-tool",
2103
+ title: "Stream",
2104
+ status: "in_progress",
2105
+ content: text("one"),
2106
+ }),
2107
+ update(CLAUDE_ROOT_SESSION, {
2108
+ sessionUpdate: "tool_call_content_chunk",
2109
+ toolCallId: "root-tool",
2110
+ content: { type: "content", content: { type: "text", text: "two" } },
2111
+ }),
2112
+ update(CLAUDE_ROOT_SESSION, {
2113
+ sessionUpdate: "tool_call_update",
2114
+ toolCallId: "root-tool",
2115
+ status: "completed",
2116
+ content: text("replacement"),
2117
+ }),
2118
+ update(CLAUDE_ROOT_SESSION, {
2119
+ sessionUpdate: "tool_call_content_chunk",
2120
+ toolCallId: "root-tool",
2121
+ content: { type: "content", content: { type: "text", text: "-more" } },
2122
+ }),
2123
+ update(CLAUDE_ROOT_SESSION, {
2124
+ sessionUpdate: "tool_call_content_chunk",
2125
+ toolCallId: "root-tool",
2126
+ content: {
2127
+ type: "diff",
2128
+ changes: [{ operation: "add", path: "/a.txt" }],
2129
+ patch: { format: "git_patch", text: "PATCH" },
2130
+ },
2131
+ }),
2132
+ claudeMarker("tools complete"),
2133
+ claudeFrames.idle("end_turn"),
2134
+ claudeFrames.closeRequest,
2135
+ claudeFrames.closed,
2136
+ ]);
2137
+ yield* session.runtime.startTurn(session.turnInput(1));
2138
+ const events = yield* session.throughMarker("tools complete");
2139
+ const outputs = events.flatMap((event) =>
2140
+ event.type === "turn_item.updated" &&
2141
+ event.turnItem.nativeItemRef?.nativeId === "root-tool" &&
2142
+ "output" in event.turnItem
2143
+ ? [event.turnItem.output]
2144
+ : [],
2145
+ );
2146
+ assert.deepEqual(outputs, [
2147
+ text("one"),
2148
+ text("onetwo"),
2149
+ text("replacement"),
2150
+ text("replacement-more"),
2151
+ { type: "Text", text: "replacement-morePATCH" },
2152
+ ]);
2153
+ }).pipe(Effect.provide(layerTest), Effect.scoped),
2154
+ );
2155
+
2156
it.effect("keeps stopped child tools interrupted when a late output chunk arrives", () =>
2157
Effect.gen(function* () {
2158
const { update } = claudeFrames;
packages/provider-acp/src/server/adapter.ts
+38
-19
@@ -1013,6 +1013,25 @@ function makeProviderThread(input: {
1013
};
1014
}
1015
1016
+function appendToolContentText(content: unknown, text: string): unknown[] {
1017
+ const next: unknown[] = Array.isArray(content) ? [...content] : [];
1018
+ const last = unknownRecord(next.at(-1));
1019
+ const lastContent = unknownRecord(last?.content);
1020
+ if (
1021
+ last?.type === "content" &&
1022
+ lastContent?.type === "text" &&
1023
+ typeof lastContent.text === "string"
1024
+ ) {
1025
+ next[next.length - 1] = {
1026
+ ...last,
1027
+ content: { ...lastContent, text: `${lastContent.text}${text}` },
1028
+ };
1029
+ } else {
1030
+ next.push({ type: "content", content: { type: "text", text } });
1031
+ }
1032
+ return next;
1033
+}
1034
+
1035
function acpMcpToolCallOutput(rawOutput: unknown): unknown {
1036
const record = unknownRecord(rawOutput);
1037
if (record === undefined) return rawOutput;
@@ -3130,26 +3149,9 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* (
3149
if (toolCall.content.type !== "content") return;
3150
const text = acpContentBlockDisplayText(toolCall.content.content);
3151
if (text === undefined || text.length === 0) return;
3133
- const content: unknown[] = Array.isArray(previous?.data.content)
3134
- ? [...previous.data.content]
3135
- : [];
3136
- const last = unknownRecord(content.at(-1));
3137
- const lastContent = unknownRecord(last?.content);
3138
- if (
3139
- last?.type === "content" &&
3140
- lastContent?.type === "text" &&
3141
- typeof lastContent.text === "string"
3142
- ) {
3143
- content[content.length - 1] = {
3144
- ...last,
3145
- content: { ...lastContent, text: `${lastContent.text}${text}` },
3146
- };
3147
- } else {
3148
- content.push({ type: "content", content: { type: "text", text } });
3149
- }
3152
toolCall = {
3153
toolCallId: toolCall.toolCallId,
3152
- data: { content },
3154
+ data: { content: appendToolContentText(previous?.data.content, text) },
3155
};
3156
}
3157
const merged = mergeToolCallState(previous, toolCall);
@@ -5583,7 +5585,24 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* (
5585
status: "inProgress" as const,
5586
data: { toolCallId: update.toolCallId },
5587
};
5586
- yield* emitTool(context, appendToolOutputText(previous, text));
5588
+ // Text chunks extend the content list so a later content replacement still shows.
5589
+ yield* emitTool(
5590
+ context,
5591
+ update.content.type === "content" && previous.data.rawOutput === undefined
5592
+ ? {
5593
+ ...previous,
5594
+ data: {
5595
+ ...previous.data,
5596
+ content: appendToolContentText(previous.data.content, text),
5597
+ },
5598
+ }
5599
+ : previous.data.rawOutput === undefined
5600
+ ? setToolOutputText(
5601
+ previous,
5602
+ `${textFromUnknown(previous.data.content) ?? ""}${text}`,
5603
+ )
5604
+ : appendToolOutputText(previous, text),
5605
+ );
5606
}
5607
break;
5608
}