Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

ThreadRelationshipsControl.tsx

694 lines28.1 KB

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