Skip to content

Commit 6c35fbd

Browse files
juliusmarmingecodex
andcommitted
fix(web): preserve bounded command output summaries
Co-authored-by: codex <[email protected]>
1 parent f607ebc commit 6c35fbd

3 files changed

Lines changed: 110 additions & 5 deletions

File tree

‎apps/server/src/orchestration/ActivityPayloadProjection.test.ts‎

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,59 @@ describe("projectActivityPayload agent-field survival", () => {
4444
expect(data.somethingClientNeverReads).toBeUndefined();
4545
});
4646

47+
it("keeps a bounded Codex command output summary", () => {
48+
const projected = projectActivityPayload(
49+
activity({
50+
itemType: "command_execution",
51+
data: {
52+
item: {
53+
command: "/bin/zsh -lc 'printf hello'",
54+
aggregatedOutput: `hello from codex\n${"x".repeat(5000)}`,
55+
},
56+
},
57+
}),
58+
);
59+
const data = (projected.payload as Record<string, unknown>).data as Record<string, unknown>;
60+
expect(data.item).toEqual({
61+
command: "/bin/zsh -lc 'printf hello'",
62+
aggregatedOutput: "hello from codex",
63+
});
64+
expect(JSON.stringify(projected.payload).length).toBeLessThan(500);
65+
});
66+
67+
it("keeps bounded Claude and ACP command output summaries", () => {
68+
const claude = projectActivityPayload(
69+
activity({
70+
itemType: "command_execution",
71+
data: {
72+
command: "printf hello",
73+
rawOutput: { stdout: `hello from claude\n${"y".repeat(5000)}` },
74+
},
75+
}),
76+
);
77+
const acp = projectActivityPayload(
78+
activity({
79+
itemType: "command_execution",
80+
data: {
81+
command: "printf hello",
82+
content: [
83+
{
84+
type: "content",
85+
content: { type: "text", text: `hello from acp\n${"z".repeat(5000)}` },
86+
},
87+
],
88+
},
89+
}),
90+
);
91+
92+
const claudeData = (claude.payload as Record<string, unknown>).data as Record<string, unknown>;
93+
const acpData = (acp.payload as Record<string, unknown>).data as Record<string, unknown>;
94+
expect(claudeData.rawOutput).toEqual({ content: "hello from claude" });
95+
expect(acpData.rawOutput).toEqual({ content: "hello from acp" });
96+
expect(JSON.stringify(claude.payload).length).toBeLessThan(500);
97+
expect(JSON.stringify(acp.payload).length).toBeLessThan(500);
98+
});
99+
47100
it("slims Codex-shaped mcp_tool_call items to rendered fields plus a result summary", () => {
48101
const projected = projectActivityPayload(
49102
activity({

‎apps/server/src/orchestration/ActivityPayloadProjection.ts‎

Lines changed: 55 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,14 +91,35 @@ function projectCommandData(data: Record<string, unknown>): Record<string, unkno
9191
projectedItem.command = item.command;
9292
}
9393

94+
const aggregatedOutput = asTrimmedString(item.aggregatedOutput);
95+
if (aggregatedOutput) {
96+
const summary = summarizeToolTextOutput(aggregatedOutput);
97+
if (summary) {
98+
projectedItem.aggregatedOutput = summary;
99+
}
100+
}
101+
94102
const input = asRecord(item.input);
95103
if (input && "command" in input) {
96104
projectedItem.input = { command: input.command };
97105
}
98106

99107
const result = asRecord(item.result);
100-
if (result && "command" in result) {
101-
projectedItem.result = { command: result.command };
108+
if (result) {
109+
const projectedResult: Record<string, unknown> = {};
110+
if ("command" in result) {
111+
projectedResult.command = result.command;
112+
}
113+
const content = asTrimmedString(result.content);
114+
if (content) {
115+
const summary = summarizeToolTextOutput(content);
116+
if (summary) {
117+
projectedResult.content = summary;
118+
}
119+
}
120+
if (Object.keys(projectedResult).length > 0) {
121+
projectedItem.result = projectedResult;
122+
}
102123
}
103124

104125
return Object.keys(projectedItem).length > 0 ? projectedItem : undefined;
@@ -232,6 +253,12 @@ function projectMcpToolCallData(data: Record<string, unknown>): Record<string, u
232253
}
233254

234255
function projectRawOutput(value: unknown): Record<string, unknown> | undefined {
256+
const direct = asTrimmedString(value);
257+
if (direct) {
258+
const summary = summarizeToolTextOutput(direct);
259+
return summary ? { content: summary } : undefined;
260+
}
261+
235262
const rawOutput = asRecord(value);
236263
if (!rawOutput) {
237264
return undefined;
@@ -256,9 +283,34 @@ function projectRawOutput(value: unknown): Record<string, unknown> | undefined {
256283
return summary ? { content: summary } : undefined;
257284
}
258285

286+
const stderr = asTrimmedString(rawOutput.stderr);
287+
if (stderr) {
288+
const summary = summarizeToolTextOutput(stderr);
289+
return summary ? { content: summary } : undefined;
290+
}
291+
259292
return undefined;
260293
}
261294

295+
function projectAcpContent(value: unknown): Record<string, unknown> | undefined {
296+
if (!Array.isArray(value)) {
297+
return undefined;
298+
}
299+
300+
const text = value
301+
.map((entryValue) => {
302+
const entry = asRecord(entryValue);
303+
const content = asRecord(entry?.content);
304+
return entry?.type === "content" && content?.type === "text"
305+
? asTrimmedString(content.text)
306+
: null;
307+
})
308+
.filter((entry): entry is string => entry !== null)
309+
.join("\n");
310+
const summary = summarizeToolTextOutput(text);
311+
return summary ? { content: summary } : undefined;
312+
}
313+
262314
/**
263315
* Removes activity payload fields that no current client reads while retaining
264316
* the full payload in persistence and the event store.
@@ -305,7 +357,7 @@ export function projectActivityPayload(
305357
projectedData.kind = data.kind;
306358
}
307359

308-
const rawOutput = projectRawOutput(data.rawOutput);
360+
const rawOutput = projectRawOutput(data.rawOutput) ?? projectAcpContent(data.content);
309361
if (rawOutput) {
310362
projectedData.rawOutput = rawOutput;
311363
}

‎apps/web/src/session-logic.command-output.test.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ describe("deriveWorkLogEntries command output", () => {
4444
});
4545
});
4646

47-
it("uses Claude ACP stdout instead of repeating the command", () => {
47+
it("uses a projected Claude output summary instead of repeating the command", () => {
4848
const [entry] = deriveWorkLogEntries([
4949
makeCommandActivity("claude-command", {
5050
itemType: "command_execution",
@@ -54,7 +54,7 @@ describe("deriveWorkLogEntries command output", () => {
5454
kind: "execute",
5555
command: "printf hello",
5656
rawOutput: {
57-
stdout: "hello from claude\n",
57+
content: "hello from claude",
5858
},
5959
},
6060
}),

0 commit comments

Comments
 (0)