Skip to content

Commit f777aa3

Browse files
t3dotggclaude
andcommitted
feat(clients): live row shows the agent's latest thought
The live activity row only showed the running tool, so a thought (often a finding) vanished a few ms later when the next tool call started. The live group now keeps the latest thought's first sentence as a gray work-log row with the brain icon, above the running tool, wrapped up to four lines, on web and mobile. The sentence rule lives in client-runtime so both clients share it. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
1 parent 758dc29 commit f777aa3

10 files changed

Lines changed: 236 additions & 13 deletions

File tree

‎apps/mobile/src/features/threads/ThreadFeed.tsx‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1608,6 +1608,7 @@ function renderFeedEntry(
16081608
summaryToolIcon={entry.summaryToolIcon}
16091609
hasFailure={entry.hasFailure}
16101610
shimmer={entry.shimmer}
1611+
thought={entry.thought}
16111612
onToggle={() => props.onToggleWorkGroup(entry.groupId, entry.id)}
16121613
/>
16131614
);
@@ -2908,6 +2909,8 @@ export const ThreadFeed = memo(function ThreadFeed(props: ThreadFeedProps) {
29082909
case "run-fold":
29092910
return resolveThreadFeedFixedItemSize(entry.type);
29102911
case "work-toggle":
2912+
// A live thought wraps up to four lines, so that row measures itself.
2913+
return entry.thought ? undefined : WORK_GROUP_TOGGLE_HEIGHT;
29112914
case "thinking":
29122915
return WORK_GROUP_TOGGLE_HEIGHT;
29132916
case "activity-group":

‎apps/mobile/src/features/threads/thread-work-log.tsx‎

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1222,11 +1222,11 @@ export function ThreadWorkGroupToggle(props: {
12221222
readonly toolIcon?: ToolActivityIcon;
12231223
readonly hasFailure: boolean;
12241224
readonly shimmer: boolean;
1225+
readonly thought?: string | undefined;
12251226
readonly onToggle: () => void;
12261227
}) {
1227-
const accessibilityLabel = props.hasFailure
1228-
? `${props.summary}, tool call failed`
1229-
: props.summary;
1228+
const statusLabel = props.hasFailure ? `${props.summary}, tool call failed` : props.summary;
1229+
const accessibilityLabel = props.thought ? `${props.thought} ${statusLabel}` : statusLabel;
12301230
const icon =
12311231
props.summaryToolIcon ??
12321232
(props.toolSurface
@@ -1235,6 +1235,28 @@ export function ThreadWorkGroupToggle(props: {
12351235

12361236
return (
12371237
<WorkLogBlock layout="group-header">
1238+
{props.thought ? (
1239+
// The latest thought sits above the status line as an ordinary work-log
1240+
// row, wrapped up to four lines.
1241+
<Pressable
1242+
accessible={false}
1243+
onPress={props.onToggle}
1244+
className="flex-row items-start gap-1.5 rounded-md px-0.5 active:bg-subtle"
1245+
>
1246+
<WorkLogIconSlot>
1247+
<WorkLogIcon icon="brain" color={props.iconSubtleColor} />
1248+
</WorkLogIconSlot>
1249+
<Text
1250+
key={props.rowSizing.textSizeKey}
1251+
selectable={false}
1252+
numberOfLines={4}
1253+
ellipsizeMode="tail"
1254+
className="min-w-0 flex-1 py-0.5 text-sm text-foreground-muted"
1255+
>
1256+
{props.thought}
1257+
</Text>
1258+
</Pressable>
1259+
) : null}
12381260
<WorkLogPressable
12391261
accessibilityRole="button"
12401262
accessibilityState={{ expanded: props.expanded }}

‎apps/mobile/src/lib/threadActivity.test.ts‎

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2211,7 +2211,8 @@ it.each(["First paragraph.\n\nSecond paragraph.", ""])(
22112211
);
22122212
if (text) {
22132213
expect(rows.find((row) => row.type === "work-toggle")).toMatchObject({
2214-
summary: "First paragraph. Second paragraph.",
2214+
summary: "Thinking",
2215+
thought: "First paragraph.",
22152216
live: true,
22162217
});
22172218
} else {
@@ -2225,6 +2226,32 @@ it.each(["First paragraph.\n\nSecond paragraph.", ""])(
22252226
},
22262227
);
22272228

2229+
it("keeps the latest thought under the live tool status", () => {
2230+
const at = "2026-06-20T00:00:02.000Z";
2231+
const thought: OrchestrationV2TurnItem = {
2232+
...base("found-thought", at, 1),
2233+
type: "reasoning",
2234+
status: "completed",
2235+
streaming: false,
2236+
text: "Found the cause: no commits yet. Checking the UI next.",
2237+
};
2238+
const tool = { ...command(at), status: "running" as const, completedAt: null };
2239+
const rows = deriveThreadFeedPresentation(
2240+
buildThreadFeed([projected(userMessage(), 0), projected(thought, 1), projected(tool, 2)]),
2241+
{ runId, status: "running", startedAt: at, completedAt: null },
2242+
new Set(),
2243+
new Set(),
2244+
at,
2245+
);
2246+
expect(rows.find((row) => row.type === "work-toggle")).toMatchObject({
2247+
thought: "Found the cause: no commits yet.",
2248+
live: true,
2249+
});
2250+
expect(rows.find((row) => row.type === "work-toggle")).not.toMatchObject({
2251+
summary: "Thinking",
2252+
});
2253+
});
2254+
22282255
it("stops stranded thinking after a steer and follows the next thought or tool", () => {
22292256
const at = "2026-06-20T00:00:02.000Z";
22302257
const thought = (id: string): OrchestrationV2TurnItem => ({
@@ -2248,7 +2275,8 @@ it("stops stranded thinking after a steer and follows the next thought or tool",
22482275
at,
22492276
);
22502277
expect(rows([first]).find((row) => row.type === "work-toggle")).toMatchObject({
2251-
summary: "first-thought",
2278+
summary: "Thinking",
2279+
thought: "first-thought",
22522280
live: true,
22532281
shimmer: true,
22542282
});
@@ -2272,9 +2300,11 @@ it("stops stranded thinking after a steer and follows the next thought or tool",
22722300
]) {
22732301
const live = rows(items).filter((row) => row.type === "work-toggle" && row.shimmer);
22742302
expect(live).toHaveLength(1);
2275-
expect(live[0]).toMatchObject({
2276-
summary: items.at(-1)!.type === "reasoning" ? "next-thought" : "Running vp",
2277-
});
2303+
expect(live[0]).toMatchObject(
2304+
items.at(-1)!.type === "reasoning"
2305+
? { summary: "Thinking", thought: "next-thought" }
2306+
: { summary: "Running vp" },
2307+
);
22782308
}
22792309
expect(first.status).toBe("running");
22802310
});

‎apps/mobile/src/lib/threadActivity.ts‎

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {
1616
} from "@t3tools/client-runtime/work-log/command-label";
1717
import {
1818
contextCompactionLabel,
19+
liveThoughtLine,
1920
toolItemForDisplay,
2021
workEntryDisplayIndicatesToolFailure,
2122
liveActivityToolStatus,
@@ -193,6 +194,8 @@ type ThreadFeedEntryContent =
193194
readonly hasFailure: boolean;
194195
readonly live: boolean;
195196
readonly shimmer: boolean;
197+
/** First sentence of the latest thought, shown above the live status line. */
198+
readonly thought?: string;
196199
}
197200
| {
198201
readonly type: "run-fold";
@@ -1470,8 +1473,17 @@ function appendToolGroupRows(
14701473
const shimmer = activeTail && (active || latestActivity.status === "success");
14711474
const singleActivity = activities.length === 1 ? latestActivity : null;
14721475
const groupSummary = summarizeToolGroup(activities.map((activity) => activity.workEntry));
1476+
const latestThought =
1477+
live && !expanded
1478+
? activities.findLast(
1479+
(activity) =>
1480+
activity.workEntry.itemType === "reasoning" &&
1481+
(activity.workEntry.detail?.trim() ?? "") !== "",
1482+
)?.workEntry.detail
1483+
: undefined;
1484+
const thought = latestThought ? liveThoughtLine(latestThought) : "";
14731485
const summary = live
1474-
? expanded && latestActivity.workEntry.itemType === "reasoning"
1486+
? (expanded || thought) && latestActivity.workEntry.itemType === "reasoning"
14751487
? latestActivity.lifecycleStatus === "inProgress"
14761488
? "Thinking"
14771489
: "Thought"
@@ -1526,6 +1538,7 @@ function appendToolGroupRows(
15261538
...(groupToolSurface ? { toolSurface: groupToolSurface } : {}),
15271539
...(groupToolIcon ? { toolIcon: groupToolIcon } : {}),
15281540
...(summaryToolIcon ? { summaryToolIcon } : {}),
1541+
...(thought ? { thought } : {}),
15291542
hasFailure: (() => {
15301543
const lastToolLike = activities.findLast((activity) => activity.toolLike);
15311544
return (

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

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1994,6 +1994,60 @@ describe("deriveMessagesTimelineRows", () => {
19941994
expect(rows.some((row) => row.kind === "thinking")).toBe(false);
19951995
});
19961996

1997+
it("carries the latest thought on the live row while a later tool runs", () => {
1998+
type WorkEntry = Extract<
1999+
Parameters<typeof deriveMessagesTimelineRows>[0]["timelineEntries"][number],
2000+
{ kind: "work" }
2001+
>;
2002+
const work = (
2003+
id: string,
2004+
at: string,
2005+
fields: Omit<WorkEntry["entry"], "id" | "createdAt" | "runId" | "label">,
2006+
): WorkEntry => ({
2007+
id: `${id}-entry`,
2008+
kind: "work",
2009+
createdAt: at,
2010+
entry: { id, createdAt: at, runId: "turn-1" as never, label: id, ...fields },
2011+
});
2012+
const rows = deriveMessagesTimelineRows({
2013+
timelineEntries: [
2014+
work("old-thought", "2026-01-01T00:00:01Z", {
2015+
itemType: "reasoning",
2016+
detail: "First idea.",
2017+
tone: "thinking" as const,
2018+
toolLifecycleStatus: "completed" as const,
2019+
}),
2020+
work("new-thought", "2026-01-01T00:00:02Z", {
2021+
itemType: "reasoning",
2022+
detail: "Found the cause.",
2023+
tone: "thinking" as const,
2024+
toolLifecycleStatus: "completed" as const,
2025+
}),
2026+
work("running-command", "2026-01-01T00:00:03Z", {
2027+
command: "rg cause",
2028+
requestKind: "command",
2029+
tone: "tool" as const,
2030+
toolLifecycleStatus: "inProgress" as const,
2031+
}),
2032+
],
2033+
latestRun: {
2034+
runId: "turn-1" as never,
2035+
status: "running",
2036+
startedAt: "2026-01-01T00:00:00Z",
2037+
completedAt: null,
2038+
},
2039+
isWorking: true,
2040+
activeTurnStartedAt: "2026-01-01T00:00:00Z",
2041+
turnDiffSummaries: [],
2042+
supportsConversationRollback: false,
2043+
});
2044+
2045+
expect(rows.find((row) => row.kind === "work-live")).toMatchObject({
2046+
entry: { id: "running-command" },
2047+
thought: { id: "new-thought" },
2048+
});
2049+
});
2050+
19972051
it("keeps an actually running tool in the shared activity row", () => {
19982052
const rows = deriveMessagesTimelineRows({
19992053
timelineEntries: [

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -501,6 +501,8 @@ type MessagesTimelineRowContent =
501501
groupId: string;
502502
expanded: boolean;
503503
active: boolean;
504+
/** Latest reasoning in the live group, shown above the status line. */
505+
thought?: WorkLogEntry;
504506
}
505507
| {
506508
kind: "working";
@@ -1338,6 +1340,9 @@ export function deriveMessagesTimelineRows(input: {
13381340
latestVisibleToolEntry.entry.toolLifecycleStatus !== "declined" &&
13391341
workEntryDisplayIndicatesToolFailure(latestVisibleToolEntry.entry);
13401342

1343+
const latestThoughtEntry = visibleActiveToolEntries.findLast(
1344+
(entry) => entry.entry.itemType === "reasoning" && (entry.entry.detail?.trim() ?? "") !== "",
1345+
);
13411346
const activeWorkPlacementEntryId = latestVisibleToolEntry?.id;
13421347
const activeWorkRow =
13431348
activeWorkAnchor && latestVisibleToolEntry && !latestToolFailed
@@ -1354,6 +1359,7 @@ export function deriveMessagesTimelineRows(input: {
13541359
groupId,
13551360
expanded: input.expandedWorkGroupIds?.has(groupId) ?? false,
13561361
active: latestToolKeepsActivityLive,
1362+
...(latestThoughtEntry ? { thought: latestThoughtEntry.entry } : {}),
13571363
};
13581364
})()
13591365
: null;

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

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ import { canForkProjectedAssistantItem } from "@t3tools/client-runtime/state/thr
4040
import { notificationChildThreadId } from "@t3tools/client-runtime/state/thread-execution";
4141
import { replaceComposerContextReferences } from "@t3tools/shared/composerContextReferences";
4242
import {
43+
liveThoughtLine,
4344
resolveWorkEntryToolPresentation,
4445
resolveViewedImageAsset,
4546
workEntryViewedImagePath,
@@ -3640,18 +3641,51 @@ function LiveWorkEntryTimelineRow({ row }: { row: Extract<TimelineRow, { kind: "
36403641
: "";
36413642
const label = questionHeading || liveWorkEntryLabel(row.entry, ctx.workspaceRoot, row.active);
36423643
const failed = workEntryDisplayIndicatesToolFailure(row.entry);
3644+
// The expanded group already lists the thought, so the preview steps aside.
3645+
const thoughtLine = row.thought && !row.expanded ? liveThoughtLine(row.thought.detail ?? "") : "";
3646+
// While the thought itself streams, the status line just says Thinking.
3647+
const thoughtIsStatus = thoughtLine !== "" && row.entry === row.thought;
36433648

36443649
return (
36453650
<button
36463651
type="button"
3647-
className="group/live-work flex min-h-6 w-full max-w-full cursor-pointer items-center rounded-md text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring/70"
3648-
aria-label={failed ? `${label}, tool call failed` : undefined}
3652+
className={cn(
3653+
"group/live-work flex w-full max-w-full cursor-pointer rounded-md text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring/70",
3654+
thoughtLine ? "flex-col items-start" : "min-h-6 items-center",
3655+
)}
3656+
aria-label={
3657+
failed ? `${thoughtLine ? `${thoughtLine} ` : ""}${label}, tool call failed` : undefined
3658+
}
36493659
aria-expanded={row.expanded}
36503660
onClick={() => ctx.onToggleWorkGroup(row.groupId, row.id)}
36513661
>
3662+
{thoughtLine ? (
3663+
// The latest thought's first sentence sits above the status line as an
3664+
// ordinary work-log row, so a finding never hides behind the next tool call.
3665+
<WorkLogRow
3666+
icon={
3667+
<span className="flex size-4 items-center justify-center text-icon-muted">
3668+
<ToolActivityIconView
3669+
icon={undefined}
3670+
fallbackName="brain"
3671+
className="block size-4 shrink-0 stroke-2"
3672+
muted
3673+
/>
3674+
</span>
3675+
}
3676+
label={<span className="line-clamp-4">{thoughtLine}</span>}
3677+
wrapLabel
3678+
/>
3679+
) : null}
36523680
<LiveActivityRow
36533681
label={
3654-
row.entry.questionAnswer && hasQuestionAnswer(row.entry.questionAnswer) ? (
3682+
thoughtIsStatus ? (
3683+
row.active ? (
3684+
"Thinking"
3685+
) : (
3686+
"Thought"
3687+
)
3688+
) : row.entry.questionAnswer && hasQuestionAnswer(row.entry.questionAnswer) ? (
36553689
<span className="flex min-w-0 gap-1.5">
36563690
<span className="min-w-0 truncate">{label}</span>
36573691
<span className="min-w-0 truncate text-foreground">

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,13 @@ type RowContent = {
4646

4747
function WorkLogLine({ icon, label, trailing, wrapLabel }: RowContent) {
4848
return (
49-
<div className="flex min-h-6 min-w-0 items-center gap-1.5 text-sm leading-relaxed select-none [&_*]:select-none">
49+
<div
50+
className={cn(
51+
"flex min-h-6 min-w-0 gap-1.5 text-sm leading-relaxed select-none [&_*]:select-none",
52+
// A wrapped label keeps its icon beside the first line.
53+
wrapLabel ? "items-start" : "items-center",
54+
)}
55+
>
5056
{icon ? (
5157
<span className="relative flex size-6 shrink-0 items-center justify-center">{icon}</span>
5258
) : null}

‎packages/client-runtime/src/work-log/presentation.test.ts‎

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { T3_MCP_TOOL_NAMES } from "@t3tools/shared/t3McpToolPresentation";
77
import {
88
commandDetailRepeatsCommand,
99
extractCommandOutputText,
10+
liveThoughtLine,
1011
resolveViewedImageAsset,
1112
resolveWorkEntryToolPresentation,
1213
summarizeToolGroup,
@@ -960,3 +961,37 @@ describe("device group summaries", () => {
960961
).toBe("Used 1 tool");
961962
});
962963
});
964+
965+
describe("liveThoughtLine", () => {
966+
it("keeps the first sentence, including a closing quote", () => {
967+
expect(
968+
liveThoughtLine(
969+
'Found the cause: the repo has no commits, so `git worktree add` fails with "invalid reference: main." Now checking the UI.',
970+
),
971+
).toBe(
972+
'Found the cause: the repo has no commits, so git worktree add fails with "invalid reference: main."',
973+
);
974+
});
975+
976+
it("does not cut at dots inside file names or long dashes", () => {
977+
expect(
978+
liveThoughtLine("I read ThreadLaunchService.ts \u2014 it skips the fetch. Next step."),
979+
).toBe("I read ThreadLaunchService.ts \u2014 it skips the fetch.");
980+
});
981+
982+
it("uses a bold-only opening line as the whole line", () => {
983+
expect(
984+
liveThoughtLine("**Narrowing dispatch files**\n\nI should check the adapter. Then more."),
985+
).toBe("Narrowing dispatch files");
986+
});
987+
988+
it("returns unpunctuated text whole and flattens markdown", () => {
989+
expect(liveThoughtLine("- Checking [the docs](https://x.dev) for **limits**")).toBe(
990+
"Checking the docs for limits",
991+
);
992+
expect(liveThoughtLine("This is *really* ~~not~~ _fine_ in snake_case_names.")).toBe(
993+
"This is really not fine in snake_case_names.",
994+
);
995+
expect(liveThoughtLine(" ")).toBe("");
996+
});
997+
});

0 commit comments

Comments
 (0)