Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions apps/server/src/orchestration/ActivityPayloadProjection.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,28 @@ describe("projectActivityPayload", () => {
expect(JSON.stringify(projected.payload).length).toBeLessThan(500);
});

it("keeps preview normalization and fence-only fallback while scanning lines", () => {
const preview = projectActivityPayload(
activity({
itemType: "command_execution",
data: { rawOutput: `\`\`\`\n actual\tresult \n${"x".repeat(5000)}` },
}),
);
const fences = projectActivityPayload(
activity({
itemType: "command_execution",
data: { rawOutput: "```\r\n \t \n```\n" },
}),
);

expect((preview.payload as { data: { rawOutput: unknown } }).data.rawOutput).toEqual({
content: "actual result",
});
expect((fences.payload as { data: { rawOutput: unknown } }).data.rawOutput).toEqual({
content: "2 lines",
});
});

it("keeps bounded Claude and ACP command output summaries", () => {
const claude = projectActivityPayload(
activity({
Expand Down
38 changes: 21 additions & 17 deletions apps/server/src/orchestration/ActivityPayloadProjection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,22 +144,29 @@ function projectCommandValue(data: Record<string, unknown>): unknown {
}

function summarizeToolTextOutput(value: string): string | null {
const lines: string[] = [];
for (const rawLine of value.split(/\r?\n/u)) {
const line = rawLine.replace(/\s+/g, " ").trim();
let meaningfulLineCount = 0;
let offset = 0;

while (offset <= value.length) {
const newlineIndex = value.indexOf("\n", offset);
const lineEnd = newlineIndex === -1 ? value.length : newlineIndex;
const line = value.slice(offset, lineEnd).replace(/\s+/g, " ").trim();
if (line.length > 0) {
lines.push(line);
meaningfulLineCount += 1;
if (line !== "```") {
const summary = line.length <= 84 ? line : `${line.slice(0, 83).trimEnd()}…`;
// V8 can retain the full tool output behind a short sliced string.
// Join a tiny character array so the returned preview owns its bytes.
return Array.from(summary).join("");
}
}
if (newlineIndex === -1) {
break;
}
offset = newlineIndex + 1;
}

const firstLine = lines.find((line) => line !== "```");
if (firstLine) {
return firstLine.length <= 84 ? firstLine : `${firstLine.slice(0, 83).trimEnd()}…`;
}
if (lines.length > 1) {
return `${lines.length.toLocaleString()} lines`;
}
return null;
return meaningfulLineCount > 1 ? `${meaningfulLineCount.toLocaleString()} lines` : null;
}

/**
Expand Down Expand Up @@ -488,9 +495,6 @@ function toolLifecycleIdentity(activity: OrchestrationThreadActivity): string |
* update within the turn — a later update belongs to a subsequent call that
* reuses the same identity and is still in flight. Rows without a lifecycle
* identity pass through, matching the clients, which never collapse them.
* Live `thread.activity-appended` events are untouched: updates still stream
* in real time and the completion supersedes them on the client as before.
*
* Deliberate divergence from client collapse: clients fold only *adjacent*
* lifecycle rows, so a superseded update separated from its completion by an
* interleaved parallel call renders as its own row today, and this drop
Expand All @@ -517,7 +521,7 @@ function dropSupersededToolUpdatedActivities(
if (!identity) {
continue;
}
const key = `${activity.turnId ?? ""}${identity}`;
const key = `${activity.turnId ?? ""}\u0000${identity}`;
const indices = completionIndicesByKey.get(key);
if (indices) {
indices.push(index);
Expand All @@ -537,7 +541,7 @@ function dropSupersededToolUpdatedActivities(
if (!identity) {
return true;
}
const indices = completionIndicesByKey.get(`${activity.turnId ?? ""}${identity}`);
const indices = completionIndicesByKey.get(`${activity.turnId ?? ""}\u0000${identity}`);
return !indices?.some((completionIndex) => completionIndex > index);
});
}
Expand Down
2 changes: 1 addition & 1 deletion apps/server/src/orchestration/Layers/CheckpointReactor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ const make = Effect.gen(function* () {

const resolveThreadDetail = Effect.fn("resolveThreadDetail")(function* (threadId: ThreadId) {
return yield* projectionSnapshotQuery
.getThreadDetailById(threadId)
.getThreadDetailById(threadId, { activityKinds: [] })
.pipe(Effect.map(Option.getOrUndefined));
});

Expand Down
Loading
Loading