diff --git a/apps/web/src/components/chat/MessagesTimeline.logic.test.ts b/apps/web/src/components/chat/MessagesTimeline.logic.test.ts index 9f99af25c2..45fe344d04 100644 --- a/apps/web/src/components/chat/MessagesTimeline.logic.test.ts +++ b/apps/web/src/components/chat/MessagesTimeline.logic.test.ts @@ -565,6 +565,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 a804753110..cf03a217a3 100644 --- a/apps/web/src/components/chat/MessagesTimeline.logic.ts +++ b/apps/web/src/components/chat/MessagesTimeline.logic.ts @@ -379,6 +379,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 @@ -422,12 +435,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; } @@ -466,8 +474,8 @@ function deriveTurnFolds(input: { } const hiddenEntryIds = new Set(); for (const entry of group.entries) { - if (entry.id === group.terminalEntry?.id) { - continue; + if (entry.id !== group.terminalEntry?.id && !timelineEntryIsPersistentResourceCard(entry)) { + hiddenEntryIds.add(entry.id); } // Agent-spawn CTA rows never fold: workflows outlive their launching // turn (dynamic spawns, background execution), and folding the CTA @@ -687,21 +695,12 @@ export function deriveMessagesTimelineRows(input: { continue; } -<<<<<<< HEAD - if (timelineEntry.kind === "turn-plan") { - nextRows.push({ - kind: "turn-plan", - id: timelineEntry.id, - createdAt: timelineEntry.createdAt, - turnPlan: timelineEntry.turnPlan, -======= if (timelineEntry.kind === "event") { nextRows.push({ kind: "event", id: timelineEntry.id, createdAt: timelineEntry.createdAt, projectedItem: timelineEntry.projectedItem, ->>>>>>> 79c36e6204 (Complete orchestration V2 frontend cutover) }); continue; } @@ -797,17 +796,8 @@ function isRowUnchanged(a: MessagesTimelineRow, b: MessagesTimelineRow): boolean case "proposed-plan": return a.proposedPlan === (b as typeof a).proposedPlan; -<<<<<<< HEAD - case "turn-plan": { - const bp = b as typeof a; - // Plans rewrite in place: compare the snapshot's identity fields so an - // unchanged plan keeps its row reference (virtualization stability). - return a.createdAt === bp.createdAt && a.turnPlan.plan === bp.turnPlan.plan; - } -======= case "event": return a.projectedItem === (b as typeof a).projectedItem; ->>>>>>> 79c36e6204 (Complete orchestration V2 frontend cutover) case "work": return Equal.equals(a.groupedEntries, (b as typeof a).groupedEntries);