@devries-cameron20 / t3code Mirror · read-only / commits / f5ae8088c3
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 21, 16:00 UTC

fix(provider-pi): running shell output no longer stores a snapshot row per update (#36429)

Julius Marminge committed Nov 13, 2026 at 16:34 UTC f5ae8088c354ec6e75fee258d716afa52a4cbac1
2 files changed +62 -4
packages/provider-pi/src/server/adapter.test.ts
+29 -4
@@ -4078,6 +4078,23 @@ describe("PiAdapterV2", () => {
4078 running.turnItem.status === "running" &&
4079 running.turnItem.input === "echo hello",
4080 );
4081 + // Pi resends the whole output so far every 100 ms; each snapshot item is a stored row.
4082 + // Past its limit Pi sends only the tail, with the running total in details.truncation.
4083 + for (const [text, totalBytes] of [
4084 + ["hel", undefined],
4085 + ["hello", undefined],
4086 + ["lo\n\u00e9!", 9],
4087 + ] as const) {
4088 + yield* fake.emit({
4089 + type: "tool_execution_update",
4090 + toolCallId: "shell-call",
4091 + toolName,
4092 + partialResult: {
4093 + content: [{ type: "text", text }],
4094 + ...(totalBytes === undefined ? {} : { details: { truncation: { totalBytes } } }),
4095 + },
4096 + });
4097 + }
4098 yield* fake.emit({
4099 type: "tool_execution_end",
4100 toolCallId: "shell-call",
@@ -4089,10 +4106,18 @@ describe("PiAdapterV2", () => {
4106 ...(legacy ? {} : { structuredContent: { exit_code: exitCode } }),
4107 },
4108 });
4092 - const completed = yield* takeEvent(
4093 - (event) =>
4094 - event.type === "turn_item.updated" && event.turnItem.type === "command_execution",
4095 - );
4109 + const chunks: Array<string> = [];
4110 + let completed: ProviderAdapter.ProviderAdapterV2Event;
4111 + while (true) {
4112 + completed = yield* takeEvent(
4113 + (event) =>
4114 + event.type === "command_output.delta" ||
4115 + (event.type === "turn_item.updated" && event.turnItem.type === "command_execution"),
4116 + );
4117 + if (completed.type !== "command_output.delta") break;
4118 + chunks.push(completed.chunk);
4119 + }
4120 + assert.deepStrictEqual(chunks, ["hel", "lo", "\n\u00e9!"]);
4121 assert.isTrue(
4122 completed.type === "turn_item.updated" &&
4123 completed.turnItem.type === "command_execution" &&
packages/provider-pi/src/server/adapter.ts
+33
@@ -359,6 +359,7 @@ interface ActivePiTurn {
359 readonly streamItems: Map<string, PiStreamItemState>;
360 readonly toolArgs: Map<string, unknown>;
361 readonly toolStartedAt: Map<string, DateTime.Utc>;
362 + readonly commandOutputBytes: Map<string, number>;
363 interrupted: boolean;
364 nativeAborted: boolean;
365 sawAgentActivity: boolean;
@@ -1193,6 +1194,33 @@ export const makePiAdapterV2 = Effect.fn("makePiAdapterV2")(function* (
1194 { discard: true },
1195 );
1196
1197 + // Pi resends the whole output tail on every update; stored snapshots grow quadratically.
1198 + const emitCommandOutputDelta = (turn: ActivePiTurn, toolCallId: string, result: unknown) =>
1199 + Effect.suspend(() => {
1200 + const text = contentText(recordField(result, "content"));
1201 + const tail = Buffer.from(text, "utf8");
1202 + const totalBytes =
1203 + recordNumber(recordField(recordField(result, "details"), "truncation"), "totalBytes") ??
1204 + tail.length;
1205 + const previousBytes = turn.commandOutputBytes.get(toolCallId) ?? 0;
1206 + turn.commandOutputBytes.set(toolCallId, totalBytes);
1207 + if (totalBytes <= previousBytes) return Effect.void;
1208 + let start = Math.max(0, tail.length - (totalBytes - previousBytes));
1209 + while (start < tail.length && (tail[start]! & 0xc0) === 0x80) start++;
1210 + const chunk = tail.subarray(start).toString("utf8");
1211 + if (chunk.length === 0) return Effect.void;
1212 + return emit({
1213 + type: "command_output.delta",
1214 + driver: PI_PROVIDER,
1215 + threadId: turn.turnInput.threadId,
1216 + itemId: idAllocator.derive.turnItemFromProviderItem({
1217 + driver: PI_PROVIDER,
1218 + nativeItemId: toolCallId,
1219 + }),
1220 + chunk,
1221 + });
1222 + });
1223 +
1224 const emitToolItem = Effect.fnUntraced(function* (
1225 turn: ActivePiTurn,
1226 event: PiRpcRecord,
@@ -1203,6 +1231,10 @@ export const makePiAdapterV2 = Effect.fn("makePiAdapterV2")(function* (
1231 // Pi tags every phase of a call made through ctx.executeTool, such as from a codemode script.
1232 const parentToolCallId = recordString(event, "parentToolCallId");
1233 if (toolCallId === undefined) return;
1234 + if (phase === "update" && (toolName === "bash" || toolName === "powershell")) {
1235 + yield* emitCommandOutputDelta(turn, toolCallId, event["partialResult"]);
1236 + return;
1237 + }
1238 if (phase === "start") {
1239 turn.toolArgs.set(toolCallId, event["args"]);
1240 }
@@ -2906,6 +2938,7 @@ export const makePiAdapterV2 = Effect.fn("makePiAdapterV2")(function* (
2938 streamItems: new Map(),
2939 toolArgs: new Map(),
2940 toolStartedAt: new Map(),
2941 + commandOutputBytes: new Map(),
2942 interrupted: false,
2943 nativeAborted: false,
2944 sawAgentActivity: false,