From 73d8597e010fb2a4c902348f49ac14c574391908 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Mon, 29 Jun 2026 13:08:51 -0700 Subject: [PATCH] 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 --- .../chat/MessagesTimeline.logic.test.ts | 73 +++++++++++++++++++ .../components/chat/MessagesTimeline.logic.ts | 22 ++++-- 2 files changed, 88 insertions(+), 7 deletions(-) diff --git a/apps/web/src/components/chat/MessagesTimeline.logic.test.ts b/apps/web/src/components/chat/MessagesTimeline.logic.test.ts index 236bb9a383..f846e1affe 100644 --- a/apps/web/src/components/chat/MessagesTimeline.logic.test.ts +++ b/apps/web/src/components/chat/MessagesTimeline.logic.test.ts @@ -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; diff --git a/apps/web/src/components/chat/MessagesTimeline.logic.ts b/apps/web/src/components/chat/MessagesTimeline.logic.ts index ea32e23beb..81840db724 100644 --- a/apps/web/src/components/chat/MessagesTimeline.logic.ts +++ b/apps/web/src/components/chat/MessagesTimeline.logic.ts @@ -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(); for (const entry of group.entries) { - if (entry.id !== group.terminalEntry?.id) { + if (entry.id !== group.terminalEntry?.id && !timelineEntryIsPersistentResourceCard(entry)) { hiddenEntryIds.add(entry.id); } }