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" )
@@ -371,6 +379,7 @@ export function SubagentNotificationLink(props: {
371379 status = { agent . status }
372380 driver = { agent . driver }
373381 title = { formatSubagentDisplayTitle ( agent . title ?? "Subagent" ) }
382+ prompt = { agent . prompt }
374383 result = { agent . result }
375384 progress = { agent . progress }
376385 startedAt = { agent . startedAt }
@@ -397,23 +406,30 @@ function SubagentTimelineLink(props: {
397406 readonly origin : OrchestrationV2Subagent [ "origin" ] ;
398407 readonly driver : ProviderDriverKind ;
399408 readonly title : string ;
409+ readonly prompt : string ;
400410 readonly result : string | null ;
401411 readonly progress : string | undefined ;
402412 readonly status : OrchestrationV2TurnItem [ "status" ] ;
403413 readonly startedAt : DateTime . Utc | null ;
404414 readonly completedAt : DateTime . Utc | null ;
405415 readonly threadId : ThreadId | null ;
416+ readonly anchorRowId ?: string ;
406417 readonly onOpenThread : ( threadId : ThreadId ) => void ;
407418 readonly event ?: {
408419 readonly status : OrchestrationV2TurnItem [ "status" ] | null ;
409420 readonly label : string ;
410421 readonly timestamp : string ;
411422 } ;
412423} ) {
424+ const ctx = use ( TimelineRowCtx ) ;
413425 const agent = useAtomValue (
414426 environmentThreadDetails . threadAtom ( props . parentRef ) ,
415427 ( thread ) => thread ?. projection . subagents . find ( ( agent ) => agent . id === props . subagentId ) ?? null ,
416428 ) ;
429+ const detailKey = `subagent-detail:${ props . subagentId } ` ;
430+ const [ expanded , setExpanded ] = useState ( ( ) =>
431+ ctx . workGroupViewState . expandedEntries . has ( detailKey ) ,
432+ ) ;
417433 const threadId = props . threadId ;
418434 const liveStatus = agent ?. status ?? props . status ;
419435 const status = props . event ? props . event . status : liveStatus ;
@@ -424,6 +440,18 @@ function SubagentTimelineLink(props: {
424440 const rawDetail = settled ? result || progress : progress || result ;
425441 const detail =
426442 rawDetail && ! GENERIC_CHILD_END . test ( rawDetail ) ? plainDetail ( rawDetail ) || null : null ;
443+ const inlineDetail = subagentInlineDetail ( {
444+ hasThread : threadId !== null ,
445+ prompt : agent ?. prompt ?? props . prompt ,
446+ report : rawDetail ,
447+ } ) ;
448+ const toggleDetail = ( ) => {
449+ const next = ! expanded ;
450+ ctx . onToggleWorkEntry ( props . anchorRowId ?? detailKey , ! next ) ;
451+ if ( next ) ctx . workGroupViewState . expandedEntries . add ( detailKey ) ;
452+ else ctx . workGroupViewState . expandedEntries . delete ( detailKey ) ;
453+ setExpanded ( next ) ;
454+ } ;
427455 const failed = status === "failed" ;
428456 const timing = {
429457 status : liveStatus ,
@@ -465,54 +493,101 @@ function SubagentTimelineLink(props: {
465493 < span className = "shrink-0 text-xs text-muted-foreground tabular-nums" >
466494 { props . event ? props . event . timestamp : < SubagentElapsed agent = { timing } /> }
467495 </ span >
468- { threadId !== null ? (
496+ { threadId !== null || inlineDetail !== null ? (
469497 < ChevronRightIcon
470498 aria-hidden
471- className = "size-3.5 shrink-0 text-muted-foreground/60 transition-colors group-hover/subagent:text-foreground"
499+ className = { cn (
500+ "size-3.5 shrink-0 text-muted-foreground/60 transition-[color,transform] group-hover/subagent:text-foreground" ,
501+ threadId === null && expanded && "rotate-90" ,
502+ ) }
472503 />
473504 ) : null }
474505 </ >
475506 ) ;
476507 const className =
477508 "group/subagent flex w-full min-w-0 items-center gap-2.5 rounded-md px-2 py-1.5 text-left" ;
509+ const interactiveClassName = cn (
510+ className ,
511+ "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" ,
512+ ) ;
478513 return (
479- < Tooltip >
480- < TooltipTrigger
481- delay = { 200 }
482- render = {
483- threadId === null ? (
484- < div data-v2-item-type = "subagent" aria-description = { statusLabel } className = { className } >
485- { content }
486- </ div >
487- ) : (
488- < button
489- type = "button"
490- data-v2-item-type = "subagent"
491- aria-label = { `Open ${ props . title } ` }
492- aria-description = { statusLabel }
493- onClick = { ( ) => props . onOpenThread ( threadId ) }
494- className = { cn (
495- className ,
496- "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" ,
497- ) }
498- >
499- { content }
500- </ button >
501- )
502- }
503- />
504- < ThreadHoverCardPopup >
505- < SubagentTimelineTooltip
506- { ...props }
507- elapsed = { agent ? < AgentElapsed agent = { projectedSubagentsToRuntime ( [ agent ] ) [ 0 ] ! } /> : null }
508- model = { agent ?. model ?? null }
509- modelSelection = { agent ?. modelSelection }
510- status = { liveStatus }
511- result = { agent ?. result ?? props . result }
512- progress = { agent ?. progress ?? props . progress }
514+ < div >
515+ < Tooltip >
516+ < TooltipTrigger
517+ delay = { 200 }
518+ render = {
519+ threadId !== null ? (
520+ < button
521+ type = "button"
522+ data-v2-item-type = "subagent"
523+ aria-label = { `Open ${ props . title } ` }
524+ aria-description = { statusLabel }
525+ onClick = { ( ) => props . onOpenThread ( threadId ) }
526+ className = { interactiveClassName }
527+ >
528+ { content }
529+ </ button >
530+ ) : inlineDetail !== null ? (
531+ < button
532+ type = "button"
533+ data-v2-item-type = "subagent"
534+ aria-expanded = { expanded }
535+ aria-description = { statusLabel }
536+ onClick = { toggleDetail }
537+ className = { interactiveClassName }
538+ >
539+ { content }
540+ </ button >
541+ ) : (
542+ < div
543+ data-v2-item-type = "subagent"
544+ aria-description = { statusLabel }
545+ className = { className }
546+ >
547+ { content }
548+ </ div >
549+ )
550+ }
513551 />
514- </ ThreadHoverCardPopup >
515- </ Tooltip >
552+ < ThreadHoverCardPopup >
553+ < SubagentTimelineTooltip
554+ { ...props }
555+ elapsed = {
556+ agent ? < AgentElapsed agent = { projectedSubagentsToRuntime ( [ agent ] ) [ 0 ] ! } /> : null
557+ }
558+ model = { agent ?. model ?? null }
559+ modelSelection = { agent ?. modelSelection }
560+ status = { liveStatus }
561+ result = { agent ?. result ?? props . result }
562+ progress = { agent ?. progress ?? props . progress }
563+ />
564+ </ ThreadHoverCardPopup >
565+ </ Tooltip >
566+ { expanded && inlineDetail !== null ? (
567+ < div className = "ms-10 me-2 mt-1 mb-2 space-y-2 text-xs" >
568+ { inlineDetail . prompt !== null ? (
569+ < div >
570+ < p className = "mb-1 text-3xs font-medium text-muted-foreground" > Prompt</ p >
571+ < 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" >
572+ { inlineDetail . prompt }
573+ </ p >
574+ </ div >
575+ ) : null }
576+ { inlineDetail . report !== null ? (
577+ < div >
578+ < p className = "mb-1 text-3xs font-medium text-muted-foreground" > Report</ p >
579+ < ChatMarkdown
580+ text = { inlineDetail . report }
581+ cwd = { ctx . markdownCwd }
582+ threadRef = { ctx . threadRef ?? undefined }
583+ skills = { ctx . skills }
584+ lineBreaks
585+ />
586+ </ div >
587+ ) : null }
588+ </ div >
589+ ) : null }
590+ </ div >
516591 ) ;
517592}
518593
0 commit comments