Skip to content

Commit 8c8dbae

Browse files
t3dotggclaude
andcommitted
fix(web): a working run's tool calls share one card
Text between calls no longer starts a new card. The card sits below the run's text and grows to 4 rows, with no empty space. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 34be187 commit 8c8dbae

5 files changed

Lines changed: 82 additions & 76 deletions

File tree

‎apps/web/src/components/chat/MessagesTimeline.logic.test.ts‎

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2276,6 +2276,60 @@ describe("deriveMessagesTimelineRows", () => {
22762276
]);
22772277
});
22782278

2279+
it("keeps a working run's calls in one card below its text with tool call cards", () => {
2280+
const command = (id: string, second: number, status: "completed" | "inProgress") => ({
2281+
id: `${id}-entry`,
2282+
kind: "work" as const,
2283+
createdAt: `2026-01-01T00:00:0${second}Z`,
2284+
entry: {
2285+
id,
2286+
createdAt: `2026-01-01T00:00:0${second}Z`,
2287+
runId: "turn-1" as never,
2288+
label: `Ran ${id}`,
2289+
command: id,
2290+
requestKind: "command" as const,
2291+
tone: "tool" as const,
2292+
toolLifecycleStatus: status,
2293+
},
2294+
});
2295+
const rows = deriveMessagesTimelineRows({
2296+
timelineEntries: [
2297+
command("pwd", 5, "completed"),
2298+
{
2299+
id: "assistant-commentary-entry",
2300+
kind: "message",
2301+
createdAt: "2026-01-01T00:00:06Z",
2302+
message: {
2303+
id: "assistant-commentary" as never,
2304+
role: "assistant",
2305+
text: "Next, a short sleep.",
2306+
runId: "turn-1" as never,
2307+
createdAt: "2026-01-01T00:00:06Z",
2308+
updatedAt: "2026-01-01T00:00:06Z",
2309+
streaming: false,
2310+
},
2311+
},
2312+
command("sleep", 7, "inProgress"),
2313+
],
2314+
latestRun: {
2315+
runId: "turn-1" as never,
2316+
status: "running",
2317+
startedAt: "2026-01-01T00:00:00Z",
2318+
completedAt: null,
2319+
},
2320+
isWorking: true,
2321+
activeTurnStartedAt: "2026-01-01T00:00:00Z",
2322+
turnDiffSummaries: [],
2323+
supportsConversationRollback: false,
2324+
toolCallCards: true,
2325+
});
2326+
2327+
expect(rows.map((row) => row.kind)).toEqual(["working", "message", "work-live"]);
2328+
expect(
2329+
rows.find((row) => row.kind === "work-live")?.groupedEntries.map((entry) => entry.id),
2330+
).toEqual(["pwd", "sleep"]);
2331+
});
2332+
22792333
it("does not revive stale in-progress tools before a fresh send has a turn id", () => {
22802334
const rows = deriveMessagesTimelineRows({
22812335
timelineEntries: [

‎apps/web/src/components/chat/MessagesTimeline.logic.ts‎

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1397,6 +1397,8 @@ export function deriveMessagesTimelineRows(input: {
13971397
availableRevertTurnCounts?: ReadonlySet<number> | undefined;
13981398
liveAgentTaskIds?: ReadonlySet<string> | undefined;
13991399
worktreeSetup?: WorktreeSetupSnapshot | null;
1400+
/** Beta tool call cards: the working run's calls share one card below its text. */
1401+
toolCallCards?: boolean;
14001402
}): MessagesTimelineRow[] {
14011403
const timelineEntries = timelineRowEntries(input.timelineEntries);
14021404
const turnDiffSummaryByAssistantMessageId = new Map<MessageId, TurnDiffSummary>();
@@ -1480,6 +1482,14 @@ export function deriveMessagesTimelineRows(input: {
14801482
let tailAttemptId: string | null | undefined;
14811483
for (let index = timelineEntries.length - 1; index >= activeTurnHeaderIndex; index -= 1) {
14821484
const entry = timelineEntries[index]!;
1485+
if (
1486+
input.toolCallCards &&
1487+
entry.kind === "message" &&
1488+
entry.message.role === "assistant" &&
1489+
runIdIsActiveResponse(entry.message.runId)
1490+
) {
1491+
continue;
1492+
}
14831493
if (
14841494
entry.kind !== "work" ||
14851495
entry.entry.tone === "error" ||
@@ -1517,7 +1527,9 @@ export function deriveMessagesTimelineRows(input: {
15171527
latestRunningToolEntry !== undefined ||
15181528
(latestVisibleToolEntry !== undefined &&
15191529
workEntryIndicatesToolSuccess(latestVisibleToolEntry.entry));
1530+
// A card keeps showing its failed call; the old rows swap it for a thinking row.
15201531
const latestToolFailed =
1532+
input.toolCallCards !== true &&
15211533
latestRunningToolEntry === undefined &&
15221534
latestVisibleToolEntry !== undefined &&
15231535
latestVisibleToolEntry.entry.toolLifecycleStatus !== "declined" &&
@@ -1661,7 +1673,7 @@ export function deriveMessagesTimelineRows(input: {
16611673
appendWorkingRow();
16621674
}
16631675

1664-
if (timelineEntry.id === activeWorkPlacementEntryId) {
1676+
if (timelineEntry.id === activeWorkPlacementEntryId && !input.toolCallCards) {
16651677
appendActiveWorkRows();
16661678
}
16671679

@@ -2024,6 +2036,8 @@ export function deriveMessagesTimelineRows(input: {
20242036
: undefined,
20252037
});
20262038
}
2039+
// Only the run's own text can follow its calls, so the end is the bottom of the run.
2040+
if (input.toolCallCards) appendActiveWorkRows();
20272041

20282042
const setupHandedOff =
20292043
input.worktreeSetup !== null &&

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import { resolveWorkGroupScrollAnchor } from "@t3tools/client-runtime/work-log/s
2020
import type { WorkflowOpening } from "@t3tools/client-runtime/state/subagentRuntime";
2121
import { observeResize } from "~/lib/observeResize";
2222
import { useStableCallback } from "~/hooks/useStableCallback";
23+
import { useClientSettings } from "~/hooks/useSettings";
2324

2425
const NOOP_USE_ARTIFACT_TEMPLATE = () => {};
2526
const NOOP_OPEN_ATTACHMENT = (_attachment: ChatFileAttachment) => {};
@@ -657,6 +658,7 @@ const ConversationTimeline = memo(function ConversationTimeline({
657658
? new Set(paintedExpandedAttemptIds).add(activeFindAttemptId)
658659
: paintedExpandedAttemptIds;
659660

661+
const toolCallCards = useClientSettings((settings) => settings.toolCallCards);
660662
const rawRows = useIncrementalTimelineRows(`${listIdentityKey}\0${workspaceRoot ?? ""}`, {
661663
timelineEntries,
662664
latestRun,
@@ -672,6 +674,7 @@ const ConversationTimeline = memo(function ConversationTimeline({
672674
threadStartCheckpointReady,
673675
availableRevertTurnCounts,
674676
worktreeSetup,
677+
toolCallCards,
675678
});
676679
const rows = useStableRows(rawRows, listIdentityKey);
677680
// Run status/timestamps change per stream event; keep them out of shared row context.

‎apps/web/src/components/chat/TimelineWorkGroupRows.tsx‎

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,7 @@ import {
5858
} from "./TimelineWorkEntryRow.logic";
5959
import { formatWorkingTimerNow } from "./TimelineWorkGroupRows.logic";
6060
import { useClientSettings } from "../../hooks/useSettings";
61-
import {
62-
LiveToolCard,
63-
SettledToolCard,
64-
ToolCardBody,
65-
ToolGroupLine,
66-
groupHasTools,
67-
useEntriesInWorkingRun,
68-
} from "./ToolCallCard";
61+
import { LiveToolCard, ToolCardBody, ToolGroupLine, groupHasTools } from "./ToolCallCard";
6962

7063
export const WorkGroupSection = memo(function WorkGroupSection({
7164
anchorKey,
@@ -82,7 +75,6 @@ export const WorkGroupSection = memo(function WorkGroupSection({
8275
}) {
8376
const { workspaceRoot, routeThreadKey, onToggleWorkEntry } = use(TimelineRowCtx);
8477
const toolCallCards = useClientSettings((settings) => settings.toolCallCards);
85-
const inWorkingRun = useEntriesInWorkingRun(groupedEntries);
8678
const onToggleStandaloneEntry = (collapsed: boolean) =>
8779
onToggleWorkEntry(disclosureAnchorKey, collapsed);
8880
const nonEmptyEntries = groupedEntries.filter((entry) =>
@@ -108,9 +100,6 @@ export const WorkGroupSection = memo(function WorkGroupSection({
108100
return inCard ? <ToolCardBody>{entries}</ToolCardBody> : entries;
109101
}
110102

111-
if (toolCallCards && inWorkingRun && groupHasTools(nonEmptyEntries)) {
112-
return <SettledToolCard entries={nonEmptyEntries} />;
113-
}
114103
return (
115104
<section aria-label="Activity">
116105
{nonEmptyEntries.map((workEntry) => (

‎apps/web/src/components/chat/ToolCallCard.tsx‎

Lines changed: 9 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,7 @@ import { use, type ReactNode } from "react";
33
import { formatDuration, type WorkLogEntry } from "../../session-logic";
44
import { cn } from "~/lib/utils";
55
import { WorkLogList } from "./WorkLog";
6-
import { summarizeToolGroup } from "@t3tools/client-runtime/work-log/presentation";
7-
import {
8-
TimelineRowActivityCtx,
9-
TimelineRowCtx,
10-
type TimelineRow,
11-
type TimelineWorkEntry,
12-
} from "./timelineRowContext";
6+
import { TimelineRowCtx, type TimelineRow, type TimelineWorkEntry } from "./timelineRowContext";
137
import { ToolActivityIconView } from "./TimelineToolActivityIcon";
148
import { workEntryIconName } from "./TimelineWorkEntryRow.logic";
159
import { SimpleWorkEntryRow } from "./TimelineWorkEntryRow";
@@ -121,14 +115,11 @@ function CardHeader(props: {
121115
);
122116
}
123117

124-
/**
125-
* The newest calls and thoughts, in a body that is always 4 rows tall, so a card never grows
126-
* as calls arrive and never shrinks when it settles.
127-
*/
118+
/** The newest calls and thoughts. Rows only append, so the card grows to 4 rows and stops. */
128119
function ToolCardTail({ entries }: { entries: ReadonlyArray<TimelineWorkEntry> }) {
129120
const { workspaceRoot } = use(TimelineRowCtx);
130121
return (
131-
<div className="min-h-30 border-t border-border px-1 py-1">
122+
<div className="border-t border-border px-1 py-1">
132123
<WorkLogList density="card">
133124
{entries.map((entry) => (
134125
<SimpleWorkEntryRow key={entry.id} workEntry={entry} workspaceRoot={workspaceRoot} />
@@ -138,16 +129,11 @@ function ToolCardTail({ entries }: { entries: ReadonlyArray<TimelineWorkEntry> }
138129
);
139130
}
140131

141-
function useRunIsWorking(runId: string | null | undefined) {
142-
const { isWorking, latestRunId } = use(TimelineRowActivityCtx);
143-
return isWorking && runId != null && runId === latestRunId;
144-
}
145-
146132
function toolNoun(count: number) {
147133
return count === 1 ? "tool" : "tools";
148134
}
149135

150-
/** Tools running now: a card with the newest calls, so progress is visible without a click. */
136+
/** The working run's calls in one card, so progress is visible without a click. */
151137
export function LiveToolCard({ row }: { row: Extract<TimelineRow, { kind: "work-live" }> }) {
152138
const ctx = use(TimelineRowCtx);
153139
const stats = toolGroupStats(row.groupedEntries);
@@ -181,23 +167,17 @@ export function LiveToolCard({ row }: { row: Extract<TimelineRow, { kind: "work-
181167
);
182168
}
183169

184-
/**
185-
* Finished tools. While the run still works they keep the live card's size, so nothing below
186-
* moves; once the run ends they settle to one quiet line that opens into the card.
187-
*/
170+
/** Finished tools: one quiet line that opens into the card. */
188171
export function ToolGroupLine({ row }: { row: Extract<TimelineRow, { kind: "work-toggle" }> }) {
189172
const ctx = use(TimelineRowCtx);
190173
const stats = toolGroupStats(row.groupedEntries);
191174
const duration = stats.durationMs !== null ? formatDuration(stats.durationMs) : null;
192-
const holdCard = useRunIsWorking(row.runId) && !row.expanded;
193175
return (
194176
<div
195177
className={
196-
holdCard
197-
? toolCardClassName.whole
198-
: row.expanded
199-
? toolCardClassName.top
200-
: "mt-1.5 rounded-md border border-transparent hover:bg-foreground/[0.03]"
178+
row.expanded
179+
? toolCardClassName.top
180+
: "mt-1.5 rounded-md border border-transparent hover:bg-foreground/[0.03]"
201181
}
202182
>
203183
<CardHeader
@@ -229,47 +209,13 @@ export function ToolGroupLine({ row }: { row: Extract<TimelineRow, { kind: "work
229209
</>
230210
}
231211
expanded={row.expanded}
232-
className={row.expanded || holdCard ? "rounded-t-xl" : "rounded-md"}
212+
className={row.expanded ? "rounded-t-xl" : "rounded-md"}
233213
onToggle={() => ctx.onToggleWorkGroup(row.groupId, row.id)}
234214
/>
235-
{holdCard ? (
236-
<ToolCardTail entries={liveToolCardTail(row.groupedEntries, LIVE_TAIL_ROWS)} />
237-
) : null}
238215
</div>
239216
);
240217
}
241218

242-
/**
243-
* A single finished call while its run still works. It keeps the live card's size; once the
244-
* run ends the call shows as a plain row.
245-
*/
246-
export function SettledToolCard({ entries }: { entries: ReadonlyArray<TimelineWorkEntry> }) {
247-
const stats = toolGroupStats(entries);
248-
const { summary } = summarizeToolGroup(entries);
249-
const duration = stats.durationMs !== null ? formatDuration(stats.durationMs) : null;
250-
return (
251-
<div className={toolCardClassName.whole}>
252-
<CardHeader
253-
entries={entries}
254-
label={summary}
255-
accessibleLabel={[summary, stats.failedCount > 0 ? `${stats.failedCount} failed` : null]
256-
.filter(Boolean)
257-
.join(", ")}
258-
failedCount={stats.failedCount}
259-
trailing={duration}
260-
expanded={false}
261-
className="rounded-t-xl"
262-
/>
263-
<ToolCardTail entries={liveToolCardTail(entries, LIVE_TAIL_ROWS)} />
264-
</div>
265-
);
266-
}
267-
268-
/** True when the entries belong to the run that is working now. */
269-
export function useEntriesInWorkingRun(entries: ReadonlyArray<WorkLogEntry>) {
270-
return useRunIsWorking(entries[0]?.runId);
271-
}
272-
273219
/** Bottom of an open card: the full list of calls. */
274220
export function ToolCardBody({ children }: { children: ReactNode }) {
275221
return (

0 commit comments

Comments
 (0)