Skip to content

Commit 0acb18c

Browse files
committed
feat(web): subagent rows without a thread expand to show prompt and report
Droid runs subagents without creating a child thread, so the timeline row had no click target and its prompt/report only showed in a desktop hover card. Touch screens could not see either. Rows with no child thread but a prompt or report are now buttons that expand inline: prompt as plain text, report as markdown. Expansion is kept in the work-group view state and anchors scroll to the row like other disclosures. Rows with a child thread still open it.
1 parent 27e0c68 commit 0acb18c

4 files changed

Lines changed: 168 additions & 43 deletions

File tree

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ export function V2EventTimelineRow({ row }: { row: Extract<TimelineRow, { kind:
4141
return (
4242
<V2LifecycleRow
4343
environmentId={ctx.activeThreadEnvironmentId}
44+
rowId={row.id}
4445
item={item}
4546
resourceSummary={row.resourceSummary}
4647
createdAt={row.createdAt}
@@ -305,6 +306,7 @@ const V2SubagentGroup = memo(function V2SubagentGroup({
305306
<V2LifecycleRow
306307
environmentId={ctx.activeThreadEnvironmentId}
307308
key={item.id}
309+
rowId={row.id}
308310
item={item}
309311
createdAt={row.createdAt}
310312
timestampFormat={ctx.timestampFormat}

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

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as DateTime from "effect/DateTime";
22
import { describe, expect, it } from "vite-plus/test";
33

4-
import { subagentResumedSince } from "./V2LifecycleRow.logic";
4+
import { subagentInlineDetail, subagentResumedSince } from "./V2LifecycleRow.logic";
55

66
const failedAt = "2026-10-09T12:21:00.000Z";
77
const beforeFailure = DateTime.makeUnsafe("2026-10-09T12:05:00.000Z");
@@ -30,3 +30,32 @@ describe("subagentResumedSince", () => {
3030
);
3131
});
3232
});
33+
34+
describe("subagentInlineDetail", () => {
35+
it("shows the prompt and report of a subagent that has no thread to open", () => {
36+
expect(
37+
subagentInlineDetail({
38+
hasThread: false,
39+
prompt: " Find where models are labelled. ",
40+
report: "\nShort answer: no.\n",
41+
}),
42+
).toEqual({ prompt: "Find where models are labelled.", report: "Short answer: no." });
43+
});
44+
45+
it("leaves a subagent with its own thread to that thread", () => {
46+
expect(subagentInlineDetail({ hasThread: true, prompt: "Prompt", report: "Report" })).toBe(
47+
null,
48+
);
49+
});
50+
51+
it("drops the generic end-of-task line, and has nothing to show without text", () => {
52+
expect(
53+
subagentInlineDetail({
54+
hasThread: false,
55+
prompt: "Prompt",
56+
report: "Child task ended with status completed",
57+
}),
58+
).toEqual({ prompt: "Prompt", report: null });
59+
expect(subagentInlineDetail({ hasThread: false, prompt: " ", report: null })).toBe(null);
60+
});
61+
});

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,25 @@ const ACTIVE_SUBAGENT_STATUSES = new Set<OrchestrationV2Subagent["status"]>([
77
"waiting",
88
]);
99

10+
/** Some providers report this when a child ends without a report of its own. */
11+
export const GENERIC_CHILD_END = /^Child task ended with status\b/i;
12+
13+
/**
14+
* What a subagent row expands to. Providers that run subagents without a thread of their own
15+
* leave the prompt and report on the row, and touch screens cannot hover for its preview.
16+
*/
17+
export function subagentInlineDetail(input: {
18+
readonly hasThread: boolean;
19+
readonly prompt: string | null | undefined;
20+
readonly report: string | null | undefined;
21+
}): { readonly prompt: string | null; readonly report: string | null } | null {
22+
if (input.hasThread) return null;
23+
const prompt = input.prompt?.trim() || null;
24+
const trimmedReport = input.report?.trim();
25+
const report = trimmedReport && !GENERIC_CHILD_END.test(trimmedReport) ? trimmedReport : null;
26+
return prompt === null && report === null ? null : { prompt, report };
27+
}
28+
1029
/**
1130
* Whether a subagent started another run after a notification reported its
1231
* final outcome, so that outcome no longer describes it. Claude resumes a

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

Lines changed: 117 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { ThreadHoverCardPopup } from "../ThreadHoverCard";
2+
import ChatMarkdown from "../ChatMarkdown";
23
import { AgentElapsed } from "./AgentElapsed";
34
import { projectedSubagentsToRuntime } from "@t3tools/client-runtime/state/subagentRuntime";
4-
import type { ReactNode } from "react";
5+
import { type ReactNode, use, useState } from "react";
56
import { useThreadShell, useProject } from "../../state/entities";
67
import { SubagentTooltipContent } from "./SubagentTooltipContent";
78
import { useAtomValue } from "@effect/atom-react";
@@ -53,7 +54,12 @@ import { getTriggerDisplayModelName } from "./providerIconUtils";
5354
import { ProviderInstanceIcon, providerTextColor } from "./ProviderInstanceIcon";
5455
import { cn } from "~/lib/utils";
5556
import { TimelineSystemDivider } from "./TimelineSystemDivider";
56-
import { subagentResumedSince } from "./V2LifecycleRow.logic";
57+
import { TimelineRowCtx } from "./timelineRowContext";
58+
import {
59+
GENERIC_CHILD_END,
60+
subagentInlineDetail,
61+
subagentResumedSince,
62+
} from "./V2LifecycleRow.logic";
5763
import { Button, InlineButton } from "../ui/button";
5864
import { T3Wordmark } from "../T3Wordmark";
5965

@@ -75,6 +81,8 @@ export type { HandoffTimelineRun } from "@t3tools/client-runtime/handoff";
7581

7682
export function V2LifecycleRow(props: {
7783
readonly item: OrchestrationV2TurnItem;
84+
/** The timeline row this item renders in, which keeps its place when the row expands. */
85+
readonly rowId: string;
7886
readonly environmentId: EnvironmentId;
7987
readonly resourceSummary?: boolean | undefined;
8088
readonly createdAt: string;
@@ -199,11 +207,13 @@ export function V2LifecycleRow(props: {
199207
status={item.status}
200208
driver={item.driver}
201209
title={formatSubagentDisplayTitle(item.title ?? "Subagent")}
210+
prompt={item.prompt}
202211
result={item.result}
203212
progress={item.progress}
204213
startedAt={item.startedAt}
205214
completedAt={item.completedAt}
206215
threadId={item.childThreadId}
216+
anchorRowId={props.rowId}
207217
onOpenThread={props.onOpenThread}
208218
/>
209219
);
@@ -236,8 +246,6 @@ const SETTLED_SUBAGENT_STATUSES = new Set<OrchestrationV2TurnItem["status"]>([
236246
"interrupted",
237247
]);
238248

239-
const GENERIC_CHILD_END = /^Child task ended with status\b/i;
240-
241249
function plainDetail(text: string): string {
242250
return text
243251
.replace(/\[([^\]]+)\]\([^)]*\)/g, "$1")
@@ -376,6 +384,7 @@ export function SubagentNotificationLink(props: {
376384
status={agent.status}
377385
driver={agent.driver}
378386
title={formatSubagentDisplayTitle(agent.title ?? "Subagent")}
387+
prompt={agent.prompt}
379388
result={agent.result}
380389
progress={agent.progress}
381390
startedAt={agent.startedAt}
@@ -402,23 +411,30 @@ function SubagentTimelineLink(props: {
402411
readonly origin: OrchestrationV2Subagent["origin"];
403412
readonly driver: ProviderDriverKind;
404413
readonly title: string;
414+
readonly prompt: string;
405415
readonly result: string | null;
406416
readonly progress: string | undefined;
407417
readonly status: OrchestrationV2TurnItem["status"];
408418
readonly startedAt: DateTime.Utc | null;
409419
readonly completedAt: DateTime.Utc | null;
410420
readonly threadId: ThreadId | null;
421+
readonly anchorRowId?: string;
411422
readonly onOpenThread: (threadId: ThreadId) => void;
412423
readonly event?: {
413424
readonly status: OrchestrationV2TurnItem["status"] | null;
414425
readonly label: string;
415426
readonly timestamp: string;
416427
};
417428
}) {
429+
const ctx = use(TimelineRowCtx);
418430
const agent = useAtomValue(
419431
environmentThreadDetails.threadAtom(props.parentRef),
420432
(thread) => thread?.projection.subagents.find((agent) => agent.id === props.subagentId) ?? null,
421433
);
434+
const detailKey = `subagent-detail:${props.subagentId}`;
435+
const [expanded, setExpanded] = useState(() =>
436+
ctx.workGroupViewState.expandedEntries.has(detailKey),
437+
);
422438
const threadId = props.threadId;
423439
const liveStatus = agent?.status ?? props.status;
424440
const status = props.event ? props.event.status : liveStatus;
@@ -429,6 +445,18 @@ function SubagentTimelineLink(props: {
429445
const rawDetail = settled ? result || progress : progress || result;
430446
const detail =
431447
rawDetail && !GENERIC_CHILD_END.test(rawDetail) ? plainDetail(rawDetail) || null : null;
448+
const inlineDetail = subagentInlineDetail({
449+
hasThread: threadId !== null,
450+
prompt: agent?.prompt ?? props.prompt,
451+
report: rawDetail,
452+
});
453+
const toggleDetail = () => {
454+
const next = !expanded;
455+
ctx.onToggleWorkEntry(props.anchorRowId ?? detailKey, !next);
456+
if (next) ctx.workGroupViewState.expandedEntries.add(detailKey);
457+
else ctx.workGroupViewState.expandedEntries.delete(detailKey);
458+
setExpanded(next);
459+
};
432460
const failed = status === "failed";
433461
const timing = {
434462
status: liveStatus,
@@ -477,54 +505,101 @@ function SubagentTimelineLink(props: {
477505
<span className="shrink-0 text-xs text-muted-foreground tabular-nums">
478506
{props.event ? props.event.timestamp : <SubagentElapsed agent={timing} />}
479507
</span>
480-
{threadId !== null ? (
508+
{threadId !== null || inlineDetail !== null ? (
481509
<ChevronRightIcon
482510
aria-hidden
483-
className="size-3.5 shrink-0 text-muted-foreground/60 transition-colors group-hover/subagent:text-foreground"
511+
className={cn(
512+
"size-3.5 shrink-0 text-muted-foreground/60 transition-[color,transform] group-hover/subagent:text-foreground",
513+
threadId === null && expanded && "rotate-90",
514+
)}
484515
/>
485516
) : null}
486517
</>
487518
);
488519
const className =
489520
"group/subagent flex w-full min-w-0 items-center gap-2.5 rounded-md px-2 py-1.5 text-left";
521+
const interactiveClassName = cn(
522+
className,
523+
"cursor-pointer transition-colors hover:bg-accent/20 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring/70",
524+
);
490525
return (
491-
<Tooltip>
492-
<TooltipTrigger
493-
delay={200}
494-
render={
495-
threadId === null ? (
496-
<div data-v2-item-type="subagent" aria-description={statusLabel} className={className}>
497-
{content}
498-
</div>
499-
) : (
500-
<button
501-
type="button"
502-
data-v2-item-type="subagent"
503-
aria-label={`Open ${props.title}`}
504-
aria-description={statusLabel}
505-
onClick={() => props.onOpenThread(threadId)}
506-
className={cn(
507-
className,
508-
"cursor-pointer transition-colors hover:bg-accent/20 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring/70",
509-
)}
510-
>
511-
{content}
512-
</button>
513-
)
514-
}
515-
/>
516-
<ThreadHoverCardPopup>
517-
<SubagentTimelineTooltip
518-
{...props}
519-
elapsed={agent ? <AgentElapsed agent={projectedSubagentsToRuntime([agent])[0]!} /> : null}
520-
model={agent?.model ?? null}
521-
modelSelection={agent?.modelSelection}
522-
status={liveStatus}
523-
result={agent?.result ?? props.result}
524-
progress={agent?.progress ?? props.progress}
526+
<div>
527+
<Tooltip>
528+
<TooltipTrigger
529+
delay={200}
530+
render={
531+
threadId !== null ? (
532+
<button
533+
type="button"
534+
data-v2-item-type="subagent"
535+
aria-label={`Open ${props.title}`}
536+
aria-description={statusLabel}
537+
onClick={() => props.onOpenThread(threadId)}
538+
className={interactiveClassName}
539+
>
540+
{content}
541+
</button>
542+
) : inlineDetail !== null ? (
543+
<button
544+
type="button"
545+
data-v2-item-type="subagent"
546+
aria-expanded={expanded}
547+
aria-description={statusLabel}
548+
onClick={toggleDetail}
549+
className={interactiveClassName}
550+
>
551+
{content}
552+
</button>
553+
) : (
554+
<div
555+
data-v2-item-type="subagent"
556+
aria-description={statusLabel}
557+
className={className}
558+
>
559+
{content}
560+
</div>
561+
)
562+
}
525563
/>
526-
</ThreadHoverCardPopup>
527-
</Tooltip>
564+
<ThreadHoverCardPopup>
565+
<SubagentTimelineTooltip
566+
{...props}
567+
elapsed={
568+
agent ? <AgentElapsed agent={projectedSubagentsToRuntime([agent])[0]!} /> : null
569+
}
570+
model={agent?.model ?? null}
571+
modelSelection={agent?.modelSelection}
572+
status={liveStatus}
573+
result={agent?.result ?? props.result}
574+
progress={agent?.progress ?? props.progress}
575+
/>
576+
</ThreadHoverCardPopup>
577+
</Tooltip>
578+
{expanded && inlineDetail !== null ? (
579+
<div className="ms-10 me-2 mt-1 mb-2 space-y-2 text-xs">
580+
{inlineDetail.prompt !== null ? (
581+
<div>
582+
<p className="mb-1 text-3xs font-medium text-muted-foreground">Prompt</p>
583+
<p className="max-h-40 overflow-auto rounded-md border border-border/45 bg-muted/15 p-2 whitespace-pre-wrap break-words text-muted-foreground select-text">
584+
{inlineDetail.prompt}
585+
</p>
586+
</div>
587+
) : null}
588+
{inlineDetail.report !== null ? (
589+
<div>
590+
<p className="mb-1 text-3xs font-medium text-muted-foreground">Report</p>
591+
<ChatMarkdown
592+
text={inlineDetail.report}
593+
cwd={ctx.markdownCwd}
594+
threadRef={ctx.threadRef ?? undefined}
595+
skills={ctx.skills}
596+
lineBreaks
597+
/>
598+
</div>
599+
) : null}
600+
</div>
601+
) : null}
602+
</div>
528603
);
529604
}
530605

0 commit comments

Comments
 (0)