Keep persistent cards visible in folded turns

- Treat persistent resource cards as foldable turn entries
- Preserve cards that arrive before commentary when collapsing settled turns
This commit is contained in:
Julius Marminge committed 2026-06-29 13:08:51 -07:00
1 parent 30fa9443d6
commit 73d8597e01
2 files changed
+88 -7

No files matched your search

@@ -553,6 +553,79 @@ describe("deriveMessagesTimelineRows", () => {
).toBeDefined();
});
it("keeps persistent cards after the Worked-for row when they arrive before commentary", () => {
const timelineEntries = [
{
id: "user-entry",
kind: "message" as const,
createdAt: "2026-01-01T00:00:00Z",
message: {
id: "user-1" as never,
role: "user" as const,
text: "Spawn a subagent",
runId: null,
createdAt: "2026-01-01T00:00:00Z",
updatedAt: "2026-01-01T00:00:00Z",
streaming: false,
},
},
{
id: "subagent-card-entry",
kind: "event" as const,
createdAt: "2026-01-01T00:00:03Z",
projectedItem: {
item: {
type: "subagent",
runId: "turn-1",
},
} as never,
},
{
id: "assistant-commentary-entry",
kind: "message" as const,
createdAt: "2026-01-01T00:00:05Z",
message: {
id: "assistant-commentary" as never,
role: "assistant" as const,
text: "I spawned the subagent.",
runId: "turn-1" as never,
createdAt: "2026-01-01T00:00:05Z",
updatedAt: "2026-01-01T00:00:06Z",
streaming: false,
},
},
{
id: "assistant-final-entry",
kind: "message" as const,
createdAt: "2026-01-01T00:00:20Z",
message: {
id: "assistant-final" as never,
role: "assistant" as const,
text: "Subagent says: Hello.",
runId: "turn-1" as never,
createdAt: "2026-01-01T00:00:20Z",
updatedAt: "2026-01-01T00:00:22Z",
streaming: false,
},
},
];
const collapsedRows = deriveMessagesTimelineRows({
timelineEntries,
isWorking: false,
activeTurnStartedAt: null,
turnDiffSummaryByAssistantMessageId: new Map(),
revertTurnCountByUserMessageId: new Map(),
});
expect(collapsedRows.map((row) => row.id)).toEqual([
"user-entry",
"turn-fold:turn-1",
"subagent-card-entry",
"assistant-final-entry",
]);
});
it("collapses only output from a superseded V2 attempt within the active logical run", () => {
const runId = "run-steered" as never;
const supersededAttemptId = "attempt-1" as never;
@@ -293,6 +293,19 @@ function deriveUnsettledRunId(latestRun: TimelineLatestRun | null): RunId | null
return isSettled ? null : latestRun.runId;
}
function timelineEntryFoldRunId(entry: TimelineEntry): RunId | null {
if (entry.kind === "message" && entry.message.role === "assistant") {
return entry.message.runId ?? null;
}
if (entry.kind === "work") {
return entry.entry.runId ?? null;
}
if (entry.kind === "event" && timelineEntryIsPersistentResourceCard(entry)) {
return entry.projectedItem.item.runId;
}
return null;
}
/**
* Settled turns fold their commentary and tool activity behind a
* "Worked for ..." row anchored at the turn's first foldable entry; the
@@ -336,12 +349,7 @@ function deriveTurnFolds(input: {
pendingUserBoundary = entry.message.createdAt;
continue;
}
const runId =
entry.kind === "message" && entry.message.role === "assistant"
? (entry.message.runId ?? null)
: entry.kind === "work"
? (entry.entry.runId ?? null)
: null;
const runId = timelineEntryFoldRunId(entry);
if (!runId) {
continue;
}
@@ -380,7 +388,7 @@ function deriveTurnFolds(input: {
}
const hiddenEntryIds = new Set<string>();
for (const entry of group.entries) {
if (entry.id !== group.terminalEntry?.id) {
if (entry.id !== group.terminalEntry?.id && !timelineEntryIsPersistentResourceCard(entry)) {
hiddenEntryIds.add(entry.id);
}
}