11import { ThreadHoverCardPopup } from "../ThreadHoverCard" ;
2+ import ChatMarkdown from "../ChatMarkdown" ;
23import { AgentElapsed } from "./AgentElapsed" ;
34import { projectedSubagentsToRuntime } from "@t3tools/client-runtime/state/subagentRuntime" ;
4- import type { ReactNode } from "react" ;
5+ import { type ReactNode , use , useState } from "react" ;
56import { useThreadShell , useProject } from "../../state/entities" ;
67import { SubagentTooltipContent } from "./SubagentTooltipContent" ;
78import { useAtomValue } from "@effect/atom-react" ;
@@ -53,7 +54,12 @@ import { getTriggerDisplayModelName } from "./providerIconUtils";
5354import { ProviderInstanceIcon , providerTextColor } from "./ProviderInstanceIcon" ;
5455import { cn } from "~/lib/utils" ;
5556import { 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" ;
5763import { Button , InlineButton } from "../ui/button" ;
5864import { T3Wordmark } from "../T3Wordmark" ;
5965
@@ -75,6 +81,8 @@ export type { HandoffTimelineRun } from "@t3tools/client-runtime/handoff";
7581
7682export 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 = / ^ C h i l d t a s k e n d e d w i t h s t a t u s \b / i;
240-
241249function 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