Open History to see the last commit
1import { useAtomValue } from "@effect/atom-react";
2import { ThreadDetailsControl } from "./ThreadDetailsControl";
3import { ThreadHoverCardPopup } from "../ThreadHoverCard";
4import { ThreadDetailsSection } from "./ThreadDetailsSection";
5import { SectionHeaderStatus } from "../ui/collapsible-section-header";
6import { SubagentTooltipContent } from "./SubagentTooltipContent";
7import { PullRequestGlyph } from "../pullRequest/pullRequestIcons";
8import { scopedThreadKey, scopeThreadRef } from "@t3tools/client-runtime/environment";
9import {
10 deriveWorkflowGroups,
11 projectedSubagentsToRuntime,
12 type RuntimeSubagent,
13} from "@t3tools/client-runtime/state/subagentRuntime";
14import { formatSubagentDisplayTitle } from "@t3tools/client-runtime/state/subagent-display";
15import { deriveProviderSubagentStatus } from "@t3tools/client-runtime/state/thread-execution";
16import {
17 deriveThreadRelationshipGraph,
18 immediateThreadRelationships,
19 isParentThreadRelationship,
20 threadRelationshipRowStatus,
21 orderWebThreadLineageRows,
22 resolveMergeBackTargetThreadId,
23 type ThreadRelationshipEdge,
24 type ThreadRelationshipWalkRow,
25} from "@t3tools/client-runtime/state/thread-relationships";
26import {
27 canDetachThreadProviderSession,
28 resolveLatestMergeBackRun,
29} from "@t3tools/client-runtime/state/thread-workflows";
30import {
31 isOrchestrationV2WorkActive,
32 isProviderNativeSubagentThread,
33 NodeId,
34 type EnvironmentId,
35 type OrchestrationV2Subagent,
36 type OrchestrationV2ThreadShell,
37 type ThreadId,
38} from "@t3tools/contracts";
39import { deriveSubagentElapsedMs } from "@t3tools/shared/orchestrationTiming";
40import { groupBy } from "effect/Array";
41import * as DateTime from "effect/DateTime";
42import { useNavigate } from "@tanstack/react-router";
43import {
44 ArrowRightIcon,
45 BotIcon,
46 ChevronDownIcon,
47 CornerLeftUpIcon,
48 GitForkIcon,
49 LoaderCircleIcon,
50 MoreHorizontalIcon,
51 PlusIcon,
52 SquareIcon,
53 UnplugIcon,
54} from "lucide-react";
55import { useState, type ReactNode } from "react";
56
57import { useArchivedThreadSnapshots } from "../../lib/archivedThreadsState";
58import { buildThreadRouteParams } from "../../threadRoutes";
59import {
60 useProjects,
61 useThreadProjection,
62 useThreadRelationshipShells,
63} from "../../state/entities";
64import { useEnvironmentProviders } from "../../state/environments";
65import { threadEnvironment } from "../../state/threads";
66import { orchestrationEnvironment } from "../../state/orchestration";
67import { useAtomCommand } from "../../state/use-atom-command";
68import { AgentElapsed } from "./AgentElapsed";
69import { ThreadRelationshipIcon, threadRelationshipStatusLabel } from "./ThreadRelationshipIcon";
70import { ThreadLineageWorkflowRow } from "./ThreadLineageWorkflowRow";
71
72import { Menu, MenuItem, MenuPopup, MenuTrigger } from "../ui/menu";
73import { Tooltip, TooltipPopup, TooltipTrigger } from "../ui/tooltip";
74import { toastManager } from "../ui/toast";
75import { cn } from "~/lib/utils";
76import {
77 THREAD_DETAILS_PANEL_CHEVRON_CLASS,
78 THREAD_DETAILS_PANEL_ICON_CLASS,
79 THREAD_DETAILS_PANEL_LABEL_CLASS,
80 THREAD_DETAILS_PANEL_SPLIT_GROUP_CLASS,
81 THREAD_DETAILS_PANEL_ROW_CONTENT_CLASS,
82 THREAD_DETAILS_PANEL_SPLIT_SEPARATOR_CLASS,
83} from "./threadDetailsPanelStyles";
84
85const THREAD_LINEAGE_INITIAL_COUNT = 6;
86const THREAD_LINEAGE_PAGE_COUNT = 12;
87
88function resolveThreadLineageWindow<Row>(
89 rows: ReadonlyArray<Row>,
90 visibleCount: number,
91): { readonly visibleRows: ReadonlyArray<Row>; readonly hiddenCount: number } {
92 const visibleRows = rows.slice(0, visibleCount);
93 return { visibleRows, hiddenCount: rows.length - visibleRows.length };
94}
95
96function ThreadLineageRowList(props: {
97 readonly hiddenCount: number;
98 readonly onShowMore: () => void;
99 readonly children: ReactNode;
100}) {
101 return (
102 <>
103 {/* ScrollArea's max-height viewport measures badly inside this scrolling panel. */}
104 <ul
105 aria-label="Related threads"
106 className="m-0 max-h-[13.5rem] list-none overflow-y-auto overscroll-contain p-0 has-data-workflow-expanded:max-h-[min(28rem,55dvh)]"
107 >
108 {props.children}
109 </ul>
110 {props.hiddenCount > 0 ? (
111 <button
112 type="button"
113 onClick={props.onShowMore}
114 className={`flex h-8 w-full cursor-pointer items-center rounded-lg ${THREAD_DETAILS_PANEL_ROW_CONTENT_CLASS} text-sm font-medium text-muted-foreground/70 hover:bg-black/[0.055] hover:text-foreground/80 dark:hover:bg-white/[0.075]`}
115 >
116 <PlusIcon aria-hidden className="size-4 shrink-0" />
117 Show {Math.min(props.hiddenCount, THREAD_LINEAGE_PAGE_COUNT)} more
118 </button>
119 ) : null}
120 </>
121 );
122}
123
124function ThreadLineageGroup(props: {
125 readonly label: string | null;
126 readonly rows: ReadonlyArray<ThreadRelationshipWalkRow>;
127 readonly expanded: boolean;
128 readonly children: (rows: ReadonlyArray<ThreadRelationshipWalkRow>) => ReactNode;
129}) {
130 const [expanded, setExpanded] = useState(props.expanded);
131 const [visibleCount, setVisibleCount] = useState(THREAD_LINEAGE_INITIAL_COUNT);
132 const { visibleRows, hiddenCount } = resolveThreadLineageWindow(props.rows, visibleCount);
133 const failedCount = props.rows.filter(
134 ({ edge }) => edge.status === "failed" || edge.status === "error",
135 ).length;
136 if (props.rows.length === 0) return null;
137 return (
138 <div>
139 {props.label ? (
140 <ThreadDetailsControl aria-expanded={expanded} onClick={() => setExpanded(!expanded)}>
141 <BotIcon aria-hidden className={THREAD_DETAILS_PANEL_ICON_CLASS} />
142 <span className={THREAD_DETAILS_PANEL_LABEL_CLASS}>{props.label}</span>
143 <span aria-hidden className="min-w-2 flex-1" />
144 {failedCount > 0 ? <SectionHeaderStatus>{failedCount} failed</SectionHeaderStatus> : null}
145 {expanded ? null : (
146 <span className="text-xs font-normal tabular-nums text-muted-foreground">
147 {props.rows.length}
148 </span>
149 )}
150 <ChevronDownIcon
151 aria-hidden
152 className={cn(
153 THREAD_DETAILS_PANEL_CHEVRON_CLASS,
154 "transition-transform",
155 !expanded && "rotate-180 redesign:-rotate-90",
156 )}
157 />
158 </ThreadDetailsControl>
159 ) : null}
160 {expanded ? (
161 <ThreadLineageRowList
162 hiddenCount={hiddenCount}
163 onShowMore={() => setVisibleCount((count) => count + THREAD_LINEAGE_PAGE_COUNT)}
164 >
165 {props.children(visibleRows)}
166 </ThreadLineageRowList>
167 ) : null}
168 </div>
169 );
170}
171
172function relationshipLabel(edge: ThreadRelationshipEdge, currentThreadId: ThreadId) {
173 if (edge.kind === "transfer") return "Context transfer";
174 if (edge.kind === "subagent") {
175 return edge.sourceThreadId === currentThreadId ? "Subagent" : "Parent agent";
176 }
177 return edge.sourceThreadId === currentThreadId ? "Fork" : "Parent thread";
178}
179
180function relationshipThreadTitle(input: {
181 readonly title: string;
182 readonly isSubagent: boolean;
183}): string {
184 if (!input.isSubagent) return input.title;
185 return formatSubagentDisplayTitle(input.title);
186}
187
188function currentSubagent<Agent extends RuntimeSubagent>(
189 agent: Agent | undefined,
190 childThread: OrchestrationV2ThreadShell | null | undefined,
191): Agent | undefined {
192 if (!agent || !childThread || isOrchestrationV2WorkActive(agent.status)) return agent;
193 const liveStatus =
194 childThread.activityRunStatus ?? (childThread.status === "queued" ? "queued" : null);
195 const newerRun =
196 childThread.latestRunRequestedAt &&
197 DateTime.toEpochMillis(childThread.latestRunRequestedAt) >
198 Date.parse(agent.completedAt ?? agent.startedAt ?? agent.updatedAt);
199 if (!liveStatus && !newerRun) return agent;
200 const status = liveStatus ?? childThread.status;
201 const startedAt = liveStatus ? childThread.activityRunStartedAt : childThread.latestRunStartedAt;
202 const completedAt = liveStatus ? null : childThread.latestRunCompletedAt;
203 return {
204 ...agent,
205 status:
206 status === "preparing" || status === "starting" || status === "queued"
207 ? "pending"
208 : status === "rolled_back"
209 ? "interrupted"
210 : status,
211 startedAt: startedAt ? DateTime.formatIso(startedAt) : null,
212 completedAt: completedAt ? DateTime.formatIso(completedAt) : null,
213 progress: null,
214 result: null,
215 error: null,
216 };
217}
218
219export function ThreadRelationshipsPanel(props: {
220 readonly environmentId: EnvironmentId;
221 readonly threadId: ThreadId;
222}) {
223 const ref = scopeThreadRef(props.environmentId, props.threadId);
224 const projection = useThreadProjection(ref)?.projection ?? null;
225 const providersByEnvironment = useEnvironmentProviders();
226 const relationshipShells = useThreadRelationshipShells(ref);
227 const allProjects = useProjects();
228 const archived = useArchivedThreadSnapshots([props.environmentId]);
229 const archivedShells = archived.snapshots.find(
230 (entry) => entry.environmentId === props.environmentId,
231 )?.snapshot.threads;
232 const currentThread =
233 projection?.thread ??
234 relationshipShells.find((thread) => thread.id === props.threadId) ??
235 archivedShells?.find((thread) => thread.id === props.threadId);
236 const parentThreadId =
237 currentThread?.forkedFrom?.type === "run"
238 ? currentThread.forkedFrom.threadId
239 : currentThread?.lineage.parentThreadId;
240 const parentShell = parentThreadId
241 ? (relationshipShells.find((thread) => thread.id === parentThreadId) ??
242 archivedShells?.find((thread) => thread.id === parentThreadId))
243 : undefined;
244 const parentRef =
245 parentShell && isProviderNativeSubagentThread(parentShell)
246 ? scopeThreadRef(props.environmentId, parentShell.id)
247 : null;
248 const parentProjection = useThreadProjection(parentRef)?.projection;
249 const navigate = useNavigate();
250 const mergeBack = useAtomCommand(threadEnvironment.mergeBack);
251 const stopSession = useAtomCommand(threadEnvironment.stopSession);
252 const interruptTurn = useAtomCommand(threadEnvironment.interruptTurn);
253 const stopWorkflowCommand = useAtomCommand(orchestrationEnvironment.stopWorkflow);
254 const canOperateWorkflow = useAtomValue(
255 orchestrationEnvironment.stopWorkflow.permissionAtom(props.environmentId),
256 );
257 const [busyAction, setBusyAction] = useState<"merge" | "detach" | null>(null);
258 const [stoppingId, setStoppingId] = useState<string | null>(null);
259 // Derive graphs after hooks to preserve their compiler cache.
260 const providers = providersByEnvironment.get(props.environmentId);
261 const projects = allProjects.filter((project) => project.environmentId === props.environmentId);
262 const parentNativeStatus = parentProjection
263 ? deriveProviderSubagentStatus(parentProjection)?.status
264 : undefined;
265 const projected = projection?.subagents ?? [];
266 const runtimeSubagents = projectedSubagentsToRuntime(projected);
267 const byId = new Map(runtimeSubagents.map((agent) => [agent.id, agent]));
268 const subagentsByThreadId = new Map(
269 projected
270 .filter((subagent) => subagent.childThreadId !== null)
271 .map((subagent) => [
272 subagent.childThreadId,
273 {
274 ...byId.get(subagent.id)!,
275 id: subagent.id,
276 threadId: subagent.threadId,
277 runId: subagent.runId,
278 nativeTaskRef: subagent.nativeTaskRef,
279 nativeStatus: subagent.status,
280 driver: subagent.driver,
281 providerInstanceId: subagent.providerInstanceId,
282 origin: subagent.origin,
283 modelSelection: subagent.modelSelection,
284 },
285 ]),
286 );
287 const workflowGroupsById = new Map(
288 deriveWorkflowGroups(runtimeSubagents).map((group) => [group.workflow.id, group]),
289 );
290 const shells: ReadonlyArray<OrchestrationV2ThreadShell> = [
291 ...relationshipShells,
292 ...(archivedShells ?? []),
293 ];
294 const graph = deriveThreadRelationshipGraph({ threads: shells, projection });
295 const currentProject = projects.find((project) => project.id === currentThread?.projectId);
296 const latestMergeBackRun = projection === null ? null : resolveLatestMergeBackRun(projection);
297 const mergeTargetThreadId = resolveMergeBackTargetThreadId(projection);
298 const relationshipRows = orderWebThreadLineageRows({
299 graph,
300 rows: immediateThreadRelationships(graph, props.threadId),
301 currentThreadId: props.threadId,
302 mergeTargetThreadId,
303 }).map((row) => {
304 const agent =
305 row.edge.kind === "subagent" && !isParentThreadRelationship(row.edge, props.threadId)
306 ? subagentsByThreadId.get(row.threadId)
307 : undefined;
308 const workflowGroup = agent === undefined ? undefined : workflowGroupsById.get(agent.id);
309 return workflowGroup === undefined
310 ? row
311 : { ...row, edge: { ...row.edge, status: workflowGroup.workflow.status } };
312 });
313 const canMerge = mergeTargetThreadId !== null && latestMergeBackRun !== null;
314 const canDetach = projection ? canDetachThreadProviderSession(projection) : false;
315
316 const {
317 related = [],
318 active = [],
319 previous = [],
320 } = groupBy(relationshipRows, ({ edge }) => {
321 if (edge.kind !== "subagent" || isParentThreadRelationship(edge, props.threadId))
322 return "related";
323 return ["completed", "failed", "error", "cancelled", "interrupted", "idle"].includes(
324 edge.status ?? "",
325 )
326 ? "previous"
327 : "active";
328 });
329 const groups = [
330 { id: "related", label: null, rows: related, expanded: true },
331 { id: "active", label: null, rows: active, expanded: true },
332 { id: "previous", label: "Previous agents", rows: previous, expanded: false },
333 ];
334 const runningCount =
335 (projection?.subagents.filter(
336 (agent) => agent.childThreadId === null && agent.status === "running",
337 ).length ?? 0) + active.filter(({ edge }) => edge.status === "running").length;
338
339 if (relationshipRows.length === 0 && runningCount === 0) {
340 return null;
341 }
342
343 const openThread = (threadId: ThreadId) => {
344 void navigate({
345 to: "/$environmentId/$threadId",
346 params: buildThreadRouteParams(scopeThreadRef(props.environmentId, threadId)),
347 });
348 };
349
350 const merge = async () => {
351 if (!latestMergeBackRun || mergeTargetThreadId === null || busyAction !== null) return;
352 setBusyAction("merge");
353 const result = await mergeBack({
354 environmentId: props.environmentId,
355 input: {
356 sourceThreadId: props.threadId,
357 targetThreadId: mergeTargetThreadId,
358 runId: latestMergeBackRun.id,
359 },
360 });
361 setBusyAction(null);
362 if (result._tag === "Success") openThread(mergeTargetThreadId);
363 };
364
365 const detach = async () => {
366 if (!canDetach || busyAction !== null) return;
367 setBusyAction("detach");
368 await stopSession({
369 environmentId: props.environmentId,
370 input: { threadId: props.threadId },
371 });
372 setBusyAction(null);
373 };
374
375 const stopSubagent = async (
376 childThreadId: ThreadId,
377 agent: Pick<OrchestrationV2Subagent, "id" | "threadId">,
378 ) => {
379 if (stoppingId !== null) return;
380 setStoppingId(childThreadId);
381 const result = await interruptTurn({
382 environmentId: props.environmentId,
383 input: { threadId: agent.threadId, subagentId: agent.id },
384 });
385 setStoppingId(null);
386 if (result._tag === "Failure") {
387 toastManager.add({ type: "error", title: "Could not stop subagent" });
388 }
389 };
390
391 const stopWorkflow = async (subagentId: string) => {
392 if (stoppingId !== null) return;
393 setStoppingId(subagentId);
394 const result = await stopWorkflowCommand({
395 environmentId: props.environmentId,
396 input: { threadId: props.threadId, subagentId: NodeId.make(subagentId) },
397 });
398 setStoppingId(null);
399 if (result._tag === "Failure") {
400 toastManager.add({ type: "error", title: "Could not stop workflow" });
401 }
402 };
403
404 const parentTitle =
405 mergeTargetThreadId === null
406 ? null
407 : (graph.nodes.get(mergeTargetThreadId)?.thread?.title ?? null);
408
409 return (
410 <ThreadDetailsSection
411 headingId="thread-details-lineage-heading"
412 title={runningCount > 0 ? `Lineage · ${runningCount} running` : "Lineage"}
413 // A lone "Previous agents" row names itself; the heading returns for status or actions.
414 showHeading={runningCount > 0 || canDetach || related.length > 0 || active.length > 0}
415 data-thread-relationships-panel
416 actions={
417 canDetach ? (
418 <Menu>
419 <MenuTrigger
420 render={
421 <ThreadDetailsControl
422 size="icon-xs"
423 variant="ghost"
424 part="icon"
425 aria-label="More thread actions"
426 disabled={busyAction !== null}
427 />
428 }
429 >
430 <MoreHorizontalIcon className="size-3.5" />
431 </MenuTrigger>
432 <MenuPopup align="end" className="min-w-60 max-w-(--available-width)">
433 <MenuItem onClick={() => void detach()}>
434 <UnplugIcon className="size-3.5" />
435 Disconnect agent session
436 </MenuItem>
437 </MenuPopup>
438 </Menu>
439 ) : null
440 }
441 >
442 {groups.map((group) => (
443 <ThreadLineageGroup key={`${scopedThreadKey(ref)}:${group.id}`} {...group}>
444 {(visibleRows) =>
445 visibleRows.map(({ threadId, edge }) => {
446 const node = graph.nodes.get(threadId);
447 const isSubagent = edge.kind === "subagent";
448 const isMergeTarget = threadId === mergeTargetThreadId;
449 const isParent = isParentThreadRelationship(edge, props.threadId);
450 const rowStatus =
451 (isParent && threadId === parentRef?.threadId
452 ? (node?.thread?.activityRunStatus ?? parentNativeStatus)
453 : undefined) ?? threadRelationshipRowStatus(graph, { threadId, edge });
454 const RelationshipIcon = isParent
455 ? CornerLeftUpIcon
456 : isSubagent
457 ? BotIcon
458 : GitForkIcon;
459 const relationship = relationshipLabel(edge, props.threadId);
460 const projectedAgent =
461 isSubagent && !isParent ? subagentsByThreadId.get(threadId) : undefined;
462 const workflowGroup =
463 projectedAgent === undefined
464 ? undefined
465 : workflowGroupsById.get(projectedAgent.id);
466 const agent = workflowGroup
467 ? projectedAgent
468 : currentSubagent(projectedAgent, node?.thread);
469 const failed = rowStatus === "failed" || rowStatus === "error";
470 const canStop =
471 agent &&
472 (agent.origin === "app_owned" ||
473 (agent.origin === "provider_native" &&
474 agent.driver === "claudeAgent" &&
475 agent.runId != null &&
476 agent.nativeTaskRef?.strength === "strong" &&
477 agent.nativeTaskRef.nativeId !== null &&
478 ["pending", "running", "waiting"].includes(agent.nativeStatus))) &&
479 agent.startedAt &&
480 ["pending", "running", "waiting"].includes(agent.status);
481 const threadTitle = relationshipThreadTitle({
482 title:
483 workflowGroup?.workflow.workflowName ??
484 node?.thread?.title ??
485 agent?.title ??
486 threadId,
487 isSubagent,
488 });
489 const provider = providers?.find(
490 (entry) =>
491 entry.instanceId ===
492 (agent?.providerInstanceId ?? node?.thread?.providerInstanceId),
493 );
494 const providerDriver = agent?.driver ?? provider?.driver;
495 const canStopWorkflow =
496 canOperateWorkflow &&
497 workflowGroup?.workflow.status === "running" &&
498 agent?.origin === "provider_native" &&
499 providerDriver === "claudeAgent";
500 const trailingVisibilityClass = (workflowGroup ? canStopWorkflow : canStop)
501 ? "group-hover:opacity-0 group-focus-within:opacity-0 pointer-coarse:opacity-0 [@media(hover:none)]:opacity-0"
502 : "";
503 const project = projects.find((project) => project.id === node?.thread?.projectId);
504 const relationshipHint = node?.missing
505 ? "This related thread is unavailable"
506 : `Open ${relationship.toLowerCase()} in this chat`;
507 const RelationshipPopup = agent ? ThreadHoverCardPopup : TooltipPopup;
508 const relationshipTooltip = agent ? (
509 <SubagentTooltipContent
510 title={threadTitle}
511 model={agent.model}
512 providerInstanceId={agent.providerInstanceId}
513 origin={agent.origin}
514 modelSelection={agent.modelSelection}
515 provider={provider}
516 providers={providers}
517 driver={providerDriver}
518 elapsed={<AgentElapsed agent={agent} />}
519 status={agent.status}
520 result={agent.result}
521 progress={agent.progress}
522 parentThread={currentThread ?? undefined}
523 childThread={node?.thread ?? undefined}
524 parentProject={currentProject}
525 childProject={project}
526 />
527 ) : (
528 relationshipHint
529 );
530 const relationshipContent = (
531 <>
532 <ThreadRelationshipIcon
533 driver={isSubagent && !isParent ? providerDriver : undefined}
534 provider={provider}
535 fallbackIcon={RelationshipIcon}
536 status={rowStatus}
537 />
538 <span className="min-w-0 flex-1">
539 <span className="block truncate text-left text-sm font-medium leading-4 text-foreground/85">
540 {threadTitle}
541 </span>
542 </span>
543 {agent ? null : (
544 <ArrowRightIcon className="size-3 shrink-0 text-muted-foreground opacity-0 transition-opacity group-hover:opacity-100" />
545 )}
546 {agent &&
547 !failed &&
548 (deriveSubagentElapsedMs(agent, 0) !== null || canStopWorkflow) ? (
549 <span
550 className={`shrink-0 text-2xs font-normal tabular-nums text-muted-foreground ${canStopWorkflow ? "min-w-6 text-end" : ""} ${trailingVisibilityClass}`}
551 >
552 <AgentElapsed agent={agent} compact />
553 </span>
554 ) : !isMergeTarget ? (
555 <span
556 className={
557 workflowGroup
558 ? "sr-only"
559 : `shrink-0 text-2xs ${failed ? "text-destructive" : "text-muted-foreground"} ${trailingVisibilityClass}`
560 }
561 >
562 {threadRelationshipStatusLabel(rowStatus)}
563 </span>
564 ) : null}
565 </>
566 );
567 const relationshipLink = (
568 <Tooltip>
569 <TooltipTrigger
570 delay={200}
571 render={
572 <ThreadDetailsControl
573 size="sm"
574 variant="ghost"
575 part={workflowGroup ? "primary" : "row"}
576 disabled={node?.missing === true}
577 onClick={() => openThread(threadId)}
578 />
579 }
580 >
581 {relationshipContent}
582 </TooltipTrigger>
583 <RelationshipPopup side="left">{relationshipTooltip}</RelationshipPopup>
584 </Tooltip>
585 );
586 if (workflowGroup && agent) {
587 return (
588 <ThreadLineageWorkflowRow
589 key={threadId}
590 group={workflowGroup}
591 providerInstanceId={agent.providerInstanceId}
592 provider={provider}
593 providers={providers}
594 driver={providerDriver}
595 onOpenThread={(memberThreadId) => openThread(memberThreadId as ThreadId)}
596 isThreadAvailable={(memberThreadId) =>
597 graph.nodes.get(memberThreadId as ThreadId)?.missing === false
598 }
599 onStop={canStopWorkflow ? () => void stopWorkflow(agent.id) : undefined}
600 stopping={stoppingId === agent.id}
601 stopDisabled={stoppingId !== null}
602 header={relationshipLink}
603 />
604 );
605 }
606 return (
607 <li key={threadId} className="group relative flex h-8 items-center rounded-lg">
608 {isMergeTarget ? (
609 <div className={THREAD_DETAILS_PANEL_SPLIT_GROUP_CLASS}>
610 <Tooltip>
611 <TooltipTrigger
612 delay={200}
613 render={
614 <ThreadDetailsControl
615 size="sm"
616 variant="ghost"
617 part="primary"
618 aria-label={`${threadTitle} ${threadRelationshipStatusLabel(rowStatus)}`}
619 disabled={node?.missing === true}
620 onClick={() => openThread(threadId)}
621 />
622 }
623 >
624 {relationshipContent}
625 </TooltipTrigger>
626 <RelationshipPopup side="left">{relationshipTooltip}</RelationshipPopup>
627 </Tooltip>
628 <span
629 aria-hidden="true"
630 className={THREAD_DETAILS_PANEL_SPLIT_SEPARATOR_CLASS}
631 />
632 <Tooltip>
633 <TooltipTrigger
634 render={
635 <ThreadDetailsControl
636 size="sm"
637 variant="ghost"
638 part="secondary"
639 aria-label={
640 parentTitle
641 ? `Merge back to ${parentTitle}`
642 : "Merge back to source conversation"
643 }
644 disabled={!canMerge || busyAction !== null}
645 onClick={() => void merge()}
646 >
647 {busyAction === "merge" ? (
648 <LoaderCircleIcon className="size-3 animate-spin" />
649 ) : (
650 <PullRequestGlyph.merged className="size-3" />
651 )}
652 </ThreadDetailsControl>
653 }
654 />
655 <TooltipPopup side="left">
656 {latestMergeBackRun === null
657 ? "Complete a run in this fork before merging it back"
658 : parentTitle
659 ? `Merge this conversation back into ${parentTitle}`
660 : "Merge this conversation back into its source"}
661 </TooltipPopup>
662 </Tooltip>
663 <span className="shrink-0 border border-transparent ps-1 pe-2.5 text-2xs font-medium text-muted-foreground">
664 {threadRelationshipStatusLabel(rowStatus)}
665 </span>
666 </div>
667 ) : (
668 relationshipLink
669 )}
670 {canStop && agent ? (
671 <div className="pointer-events-none absolute right-1 top-1/2 -translate-y-1/2 opacity-0 group-hover:pointer-events-auto group-hover:opacity-100 group-focus-within:pointer-events-auto group-focus-within:opacity-100 pointer-coarse:pointer-events-auto pointer-coarse:opacity-100 [@media(hover:none)]:pointer-events-auto [@media(hover:none)]:opacity-100">
672 <Tooltip>
673 <TooltipTrigger
674 render={
675 <ThreadDetailsControl
676 size="icon-xs"
677 variant="ghost"
678 part="icon"
679 tone="destructive"
680 aria-label={`Stop subagent ${threadTitle}`}
681 disabled={stoppingId !== null}
682 onClick={() => void stopSubagent(threadId, agent)}
683 />
684 }
685 >
686 {stoppingId === threadId ? (
687 <LoaderCircleIcon aria-hidden className="size-3 animate-spin" />
688 ) : (
689 <SquareIcon aria-hidden className="size-3 fill-current" />
690 )}
691 </TooltipTrigger>
692 <TooltipPopup side="left">Stop subagent</TooltipPopup>
693 </Tooltip>
694 </div>
695 ) : null}
696 </li>
697 );
698 })
699 }
700 </ThreadLineageGroup>
701 ))}
702 </ThreadDetailsSection>
703 );
704}