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, 09:30 UTC
perf(acp): stop re-saving the whole terminal log on every output chunk (#24024)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: maria-rcks <maria@kuuro.net>
Victor Vogel committed
Oct 31, 2026 at 03:44 UTC
62efa4bf5e515b25f7b288aa84577a2c0e58fd69
3 files changed
+100
-1
apps/server/scripts/acp-mock-agent.ts
+31
@@ -58,6 +58,7 @@ const failSetModeConfigOption = process.env.T3_ACP_FAIL_SET_MODE_CONFIG_OPTION =
58
const emitEmptyDefaultAgentOption = process.env.T3_ACP_EMIT_EMPTY_DEFAULT_AGENT_OPTION === "1";
59
const promptResponseText = process.env.T3_ACP_PROMPT_RESPONSE_TEXT;
60
const promptDelayMs = Number(process.env.T3_ACP_PROMPT_DELAY_MS ?? "0");
61
+const terminalOutputBytes = Number(process.env.T3_ACP_EMIT_TERMINAL_OUTPUT_BYTES ?? "0");
62
const supportsSessionLifecycle = process.env.T3_ACP_SESSION_LIFECYCLE === "1";
63
const supportsAcpMcp = process.env.T3_ACP_MCP_ACP === "1";
64
const supportsV2Management = process.env.T3_ACP_V2_MANAGEMENT === "1";
@@ -991,6 +992,36 @@ const program = Effect.gen(function* () {
992
return yield* finishPrompt(requestedSessionId, "end_turn");
993
}
994
995
+ if (terminalOutputBytes > 0) {
996
+ const terminalId = "long-output";
997
+ yield* agent.client.sessionUpdate({
998
+ sessionId: requestedSessionId,
999
+ update: { sessionUpdate: "terminal_update", terminalId, command: "print long output" },
1000
+ });
1001
+ // 4 KiB chunks of 64-char numbered lines, like a long build log.
1002
+ for (let line = 0; line * 64 < terminalOutputBytes; line += 64) {
1003
+ let chunk = "";
1004
+ for (let i = line + 1; i <= line + 64; i++) {
1005
+ chunk += `${String(i).padStart(8, "0")} ${"x".repeat(54)}\n`;
1006
+ }
1007
+ yield* agent.client.sessionUpdate({
1008
+ sessionId: requestedSessionId,
1009
+ update: {
1010
+ sessionUpdate: "terminal_output_chunk",
1011
+ terminalId,
1012
+ data: Buffer.from(chunk)
1013
+ .subarray(0, terminalOutputBytes - line * 64)
1014
+ .toString("base64"),
1015
+ },
1016
+ });
1017
+ }
1018
+ yield* agent.client.sessionUpdate({
1019
+ sessionId: requestedSessionId,
1020
+ update: { sessionUpdate: "terminal_update", terminalId, exitStatus: { exitCode: 0 } },
1021
+ });
1022
+ return yield* finishPrompt(requestedSessionId, "end_turn");
1023
+ }
1024
+
1025
if (emitNotice) {
1026
// A notice in fx 0.0.14's shape for a skipped skill, between two chunks of one message.
1027
const chunk = (text: string) =>
apps/server/src/orchestration-v2/Adapters/AcpAdapterV2.test.ts
+64
@@ -3157,6 +3157,70 @@ describe("AcpAdapterV2", () => {
3157
}).pipe(Effect.provide(layerTest), Effect.scoped),
3158
);
3159
3160
+ it.effect("projects only the tail of long ACP terminal output", () =>
3161
+ Effect.gen(function* () {
3162
+ const childProcessSpawner = yield* ChildProcessSpawner.ChildProcessSpawner;
3163
+ const path = yield* Path.Path;
3164
+ const mockAgentPath = yield* path.fromFileUrl(
3165
+ new URL("../../../scripts/acp-mock-agent.ts", import.meta.url),
3166
+ );
3167
+ const instanceId = ProviderInstanceId.make("acp-test-long-terminal");
3168
+ const adapter = yield* makeAcpAdapterV2({
3169
+ instanceId,
3170
+ flavor: {
3171
+ driver: ACP_TEST_DRIVER,
3172
+ capabilities: AcpProviderCapabilitiesV2,
3173
+ makeRuntime: makeMockRuntime({
3174
+ childProcessSpawner,
3175
+ mockAgentPath,
3176
+ environment: { T3_ACP_EMIT_TERMINAL_OUTPUT_BYTES: String(1024 * 1024) },
3177
+ }),
3178
+ },
3179
+ selfInvocation: yield* resolveSelfInvocation(),
3180
+ });
3181
+ const threadId = ThreadId.make("thread-acp-long-terminal");
3182
+ const runtimePolicy = ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({
3183
+ runtimeMode: "full-access",
3184
+ interactionMode: "default",
3185
+ cwd: process.cwd(),
3186
+ });
3187
+ const modelSelection = { instanceId, model: "default" } as const;
3188
+ const runtime = yield* adapter.openSession({
3189
+ threadId,
3190
+ providerSessionId: ProviderSessionId.make("provider-session-acp-long-terminal"),
3191
+ modelSelection,
3192
+ runtimePolicy,
3193
+ });
3194
+ const providerThread = yield* runtime.ensureThread({
3195
+ threadId,
3196
+ modelSelection,
3197
+ runtimePolicy,
3198
+ });
3199
+ const now = yield* DateTime.now;
3200
+ yield* runtime.startTurn(
3201
+ makeTurnInput({ threadId, providerThread, instanceId, runtimePolicy, now, ordinal: 1 }),
3202
+ );
3203
+ const outputs = Array.from(
3204
+ yield* runtime.events.pipe(
3205
+ Stream.takeUntil((event) => event.type === "turn.terminal"),
3206
+ Stream.runCollect,
3207
+ ),
3208
+ ).flatMap((event) =>
3209
+ event.type === "turn_item.updated" && event.turnItem.type === "command_execution"
3210
+ ? [event.turnItem.output ?? ""]
3211
+ : [],
3212
+ );
3213
+ const fullOutput = Array.from(
3214
+ { length: (1024 * 1024) / 64 },
3215
+ (_, index) => `${String(index + 1).padStart(8, "0")} ${"x".repeat(54)}\n`,
3216
+ ).join("");
3217
+
3218
+ assert.isAtLeast(outputs.length, 2);
3219
+ assert.isAtMost(Math.max(...outputs.map((output) => output.length)), 320 * 1024);
3220
+ assert.equal(outputs.at(-1), fullOutput.slice(-320 * 1024));
3221
+ }).pipe(Effect.provide(layerTest), Effect.scoped),
3222
+ );
3223
+
3224
it.live(
3225
"loads the persisted ACP session during startup without creating a throwaway session",
3226
() =>
packages/provider-acp/src/server/adapter.ts
+5
-1
@@ -1380,6 +1380,9 @@ interface SnapshotMessageState {
1380
const ACP_STOP_CONFIRM_TIMEOUT_MS = 10_000;
1381
const TOOL_UPDATE_PERSIST_EVERY = 10;
1382
1383
+// CommandOutputHub reads the last 256 KiB; retain more so its display cut stays unchanged.
1384
+const MAX_AGENT_TERMINAL_OUTPUT_CHARS = 320 * 1024;
1385
+
1386
// Agents can resend whole calls while streaming arguments.
1387
function shouldPersistToolUpdate(
1388
context: Pick<ActiveAcpTurn, "toolUpdatesSkipped">,
@@ -4458,6 +4461,7 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* (
4461
embeddedToolCallIds === undefined || embeddedToolCallIds.size === 0
4462
? [`acp-agent-terminal:${update.terminalId}`]
4463
: [...embeddedToolCallIds];
4464
+ const output = next.output.slice(-MAX_AGENT_TERMINAL_OUTPUT_CHARS);
4465
for (const toolCallId of projectedToolCallIds) {
4466
const existing = context.tools.get(toolCallId);
4467
const seeded: AcpToolCallState =
@@ -4478,7 +4482,7 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* (
4482
status,
4483
...(next.command === undefined ? {} : { command: next.command }),
4484
},
4481
- next.output,
4485
+ output,
4486
),
4487
);
4488
}