Skip to content

Commit c42975f

Browse files
feat(web): fold settled turn work behind a Worked-for collapsible
Codex-style turn folding in the chat timeline, derived entirely from existing client-side data (no backend changes): - Settled turns collapse their commentary messages and tool work log behind a 'Worked for Xs' row anchored where the turn's work begins; the terminal assistant message stays visible below the fold. Clicking the row toggles the hidden history. - The active turn is never folded — live commentary and collapsed tool groups render exactly as before, with the working timer still at the bottom. - An interrupted latest turn folds with 'You stopped after Xs' (state comes from latestTurn, the only turn whose interruption survives in client data). Pressing stop leaves that turn expanded so the user keeps their place; the next turn or a reload folds it. - The completion divider ('Worked for ...' between hairlines) is replaced by the fold row; deriveCompletionDividerBeforeEntryId, completionSummary plumbing, and hasToolActivityForTurn are removed. - Work log entries now carry turnId (from the underlying activity) so tool activity can be attributed to a turn's fold. - Commentary (non-terminal assistant) rows lose the reserved metadata spacing. Folding concept ported from PR #2962 (stale, full-stack, Codex-specific assistantPhase plumbing) reimplemented web-only per discussion. Co-Authored-By: Claude Fable 5 <[email protected]>
1 parent 4b1a774 commit c42975f

8 files changed

Lines changed: 483 additions & 256 deletions

‎apps/web/src/components/ChatView.tsx‎

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ import {
5050
parseStandaloneComposerSlashCommand,
5151
} from "../composer-logic";
5252
import {
53-
deriveCompletionDividerBeforeEntryId,
5453
derivePendingApprovals,
5554
derivePendingUserInputs,
5655
derivePhase,
@@ -61,9 +60,7 @@ import {
6160
findLatestProposedPlan,
6261
deriveWorkLogEntries,
6362
hasActionableProposedPlan,
64-
hasToolActivityForTurn,
6563
isLatestTurnSettled,
66-
formatElapsed,
6764
} from "../session-logic";
6865
import { type LegendListRef } from "@legendapp/list/react";
6966
import {
@@ -1521,10 +1518,6 @@ export default function ChatView(props: ChatViewProps) {
15211518
() => deriveWorkLogEntries(threadActivities, activeLatestTurn?.turnId ?? undefined),
15221519
[activeLatestTurn?.turnId, threadActivities],
15231520
);
1524-
const latestTurnHasToolActivity = useMemo(
1525-
() => hasToolActivityForTurn(threadActivities, activeLatestTurn?.turnId),
1526-
[activeLatestTurn?.turnId, threadActivities],
1527-
);
15281521
const pendingApprovals = useMemo(
15291522
() => derivePendingApprovals(threadActivities),
15301523
[threadActivities],
@@ -1859,25 +1852,6 @@ export default function ChatView(props: ChatViewProps) {
18591852
return byUserMessageId;
18601853
}, [inferredCheckpointTurnCountByTurnId, timelineEntries, turnDiffSummaryByAssistantMessageId]);
18611854

1862-
const completionSummary = useMemo(() => {
1863-
if (!latestTurnSettled) return null;
1864-
if (!activeLatestTurn?.startedAt) return null;
1865-
if (!activeLatestTurn.completedAt) return null;
1866-
if (!latestTurnHasToolActivity) return null;
1867-
1868-
const elapsed = formatElapsed(activeLatestTurn.startedAt, activeLatestTurn.completedAt);
1869-
return elapsed ? `Worked for ${elapsed}` : null;
1870-
}, [
1871-
activeLatestTurn?.completedAt,
1872-
activeLatestTurn?.startedAt,
1873-
latestTurnHasToolActivity,
1874-
latestTurnSettled,
1875-
]);
1876-
const completionDividerBeforeEntryId = useMemo(() => {
1877-
if (!latestTurnSettled) return null;
1878-
if (!completionSummary) return null;
1879-
return deriveCompletionDividerBeforeEntryId(timelineEntries, activeLatestTurn);
1880-
}, [activeLatestTurn, completionSummary, latestTurnSettled, timelineEntries]);
18811855
const gitCwd = activeProject
18821856
? projectScriptCwd({
18831857
project: { cwd: activeProject.cwd },
@@ -3889,8 +3863,7 @@ export default function ChatView(props: ChatViewProps) {
38893863
activeTurnStartedAt={activeWorkStartedAt}
38903864
listRef={legendListRef}
38913865
timelineEntries={timelineEntries}
3892-
completionDividerBeforeEntryId={completionDividerBeforeEntryId}
3893-
completionSummary={completionSummary}
3866+
latestTurn={activeLatestTurn}
38943867
turnDiffSummaryByAssistantMessageId={turnDiffSummaryByAssistantMessageId}
38953868
activeThreadEnvironmentId={activeThread.environmentId}
38963869
routeThreadKey={routeThreadKey}

‎apps/web/src/components/chat/MessagesTimeline.browser.tsx‎

Lines changed: 75 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,7 @@ function buildProps() {
5757
activeTurnId: null,
5858
activeTurnStartedAt: null,
5959
listRef: createRef<LegendListRef | null>(),
60-
completionDividerBeforeEntryId: null,
61-
completionSummary: null,
60+
latestTurn: null,
6261
turnDiffSummaryByAssistantMessageId: new Map(),
6362
routeThreadKey: "environment-local:thread-1",
6463
onOpenTurnDiff: vi.fn(),
@@ -415,4 +414,78 @@ describe("MessagesTimeline", () => {
415414
await screen.unmount();
416415
}
417416
});
417+
418+
it("folds settled-turn work behind a Worked-for row and expands it on click", async () => {
419+
const screen = await render(
420+
<MessagesTimeline
421+
{...buildProps()}
422+
timelineEntries={[
423+
{
424+
id: "entry-commentary",
425+
kind: "message" as const,
426+
createdAt: "2026-04-13T12:00:00.000Z",
427+
message: {
428+
id: "message-commentary" as never,
429+
role: "assistant" as const,
430+
text: "Let me look around first.",
431+
turnId: "turn-1" as never,
432+
createdAt: "2026-04-13T12:00:00.000Z",
433+
completedAt: "2026-04-13T12:00:02.000Z",
434+
streaming: false,
435+
},
436+
},
437+
{
438+
id: "entry-work",
439+
kind: "work" as const,
440+
createdAt: "2026-04-13T12:00:05.000Z",
441+
entry: {
442+
id: "work-1",
443+
createdAt: "2026-04-13T12:00:05.000Z",
444+
turnId: "turn-1" as never,
445+
label: "read files",
446+
detail: "Inspecting repository state",
447+
tone: "tool" as const,
448+
},
449+
},
450+
{
451+
id: "entry-final",
452+
kind: "message" as const,
453+
createdAt: "2026-04-13T12:00:20.000Z",
454+
message: {
455+
id: "message-final" as never,
456+
role: "assistant" as const,
457+
text: "All done.",
458+
turnId: "turn-1" as never,
459+
createdAt: "2026-04-13T12:00:20.000Z",
460+
completedAt: "2026-04-13T12:00:30.000Z",
461+
streaming: false,
462+
},
463+
},
464+
]}
465+
/>,
466+
);
467+
468+
try {
469+
const foldButton = page.getByRole("button", { name: "Worked for 30s" });
470+
await expect.element(foldButton).toBeVisible();
471+
await expect.element(foldButton).toHaveAttribute("aria-expanded", "false");
472+
473+
expect(document.body.textContent).toContain("All done.");
474+
expect(document.body.textContent).not.toContain("Let me look around first.");
475+
expect(document.body.textContent).not.toContain("Inspecting repository state");
476+
477+
await foldButton.click();
478+
479+
await expect.element(foldButton).toHaveAttribute("aria-expanded", "true");
480+
expect(document.body.textContent).toContain("Let me look around first.");
481+
expect(document.body.textContent).toContain("Inspecting repository state");
482+
483+
await foldButton.click();
484+
485+
await expect.element(foldButton).toHaveAttribute("aria-expanded", "false");
486+
expect(document.body.textContent).not.toContain("Inspecting repository state");
487+
} finally {
488+
await screen.unmount();
489+
}
490+
});
418491
});

0 commit comments

Comments
 (0)