Skip to content

Commit ac8093a

Browse files
t3dotggclaude
andcommitted
feat(web): show when an agent opened a thread
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
1 parent 079e4bc commit ac8093a

13 files changed

Lines changed: 179 additions & 6 deletions

File tree

‎apps/server/src/mcp/OrchestratorMcpService.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2130,6 +2130,7 @@ const make = Effect.gen(function* () {
21302130
interactionMode,
21312131
branch: parent.thread.branch,
21322132
worktreePath: parent.thread.worktreePath,
2133+
openedByThreadId: parent.thread.id,
21332134
})
21342135
.pipe(
21352136
Effect.mapError((error) =>

‎apps/server/src/mcp/toolkits/project/handlers.test.ts‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import * as McpToolAccess from "../../McpToolAccess.ts";
2828
import * as ProjectHandlers from "./handlers.ts";
2929
import { ProjectToolkit } from "./tools.ts";
3030

31-
it.effect("attributes a launched thread's first message to the calling thread", () =>
31+
it.effect("attributes a launched thread and its first message to the calling thread", () =>
3232
Effect.gen(function* () {
3333
const sourceThreadId = ThreadId.make("source-thread");
3434
const projectId = ProjectId.make("project");
@@ -46,6 +46,7 @@ it.effect("attributes a launched thread's first message to the calling thread",
4646
deletedAt: null,
4747
} as OrchestrationV2ThreadShell;
4848
let launchedSender: ThreadId | undefined;
49+
let launchedOpener: ThreadId | undefined;
4950
const layerDependencies = Layer.mergeAll(
5051
NodeCrypto.layer,
5152
Layer.succeed(McpInvocationContext.McpInvocationContext, {
@@ -66,6 +67,7 @@ it.effect("attributes a launched thread's first message to the calling thread",
6667
Layer.mock(ThreadLaunch.ThreadLaunchService)({
6768
launch: (input) => {
6869
launchedSender = input.initialMessage?.senderThreadId;
70+
launchedOpener = input.openedByThreadId;
6971
return Effect.succeed({
7072
threadId: input.threadId,
7173
projection: {
@@ -96,6 +98,7 @@ it.effect("attributes a launched thread's first message to the calling thread",
9698
.pipe(Stream.unwrap, Stream.runCollect, Effect.provide(layerDependencies));
9799
expect(result.at(-1)?.result).toMatchObject({ projectId, modelSelection });
98100
expect(launchedSender).toBe(sourceThreadId);
101+
expect(launchedOpener).toBe(sourceThreadId);
99102
}),
100103
);
101104

@@ -384,6 +387,7 @@ it.effect("a client launches at its ceiling with the project's default model", (
384387
expect(result.at(-1)?.result).toMatchObject({ projectId, modelSelection });
385388
expect(launched[0]?.runtimeMode).toBe("auto-accept-edits");
386389
expect(launched[0]?.initialMessage?.senderThreadId).toBeUndefined();
390+
expect(launched[0]?.openedByThreadId).toBeUndefined();
387391

388392
const escalated = yield* handle({ title: "Fix", projectId, runtimeMode: "full-access" });
389393
expect(escalated.at(-1)?.result).toMatchObject({ code: "runtime_mode_escalation_denied" });

‎apps/server/src/mcp/toolkits/project/handlers.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ export const layer = McpToolAccess.toLayer(ProjectToolkit, {
133133
attachments,
134134
},
135135
}),
136+
...(caller === undefined ? {} : { openedByThreadId: caller.id }),
136137
createdBy: "agent",
137138
creationSource: "mcp",
138139
}).pipe(

‎apps/server/src/orchestration-v2/Orchestrator.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2188,6 +2188,9 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
21882188
relationshipToParent: null,
21892189
rootThreadId: command.threadId,
21902190
},
2191+
...(command.openedByThreadId === undefined
2192+
? {}
2193+
: { openedByThreadId: command.openedByThreadId }),
21912194
forkedFrom: null,
21922195
createdAt: now,
21932196
updatedAt: now,

‎apps/server/src/orchestration-v2/ProjectionStore.ts‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1411,6 +1411,9 @@ export function threadShellFromProjection(
14111411
? {}
14121412
: { activeOrderKey: projection.thread.activeOrderKey }),
14131413
lineage: projection.thread.lineage,
1414+
...(projection.thread.openedByThreadId === undefined
1415+
? {}
1416+
: { openedByThreadId: projection.thread.openedByThreadId }),
14141417
forkedFrom: projection.thread.forkedFrom,
14151418
activeProviderThreadId: projection.thread.activeProviderThreadId,
14161419
...(projection.thread.historyOrigin === undefined
@@ -1679,6 +1682,9 @@ function shellFromState(input: {
16791682
? {}
16801683
: { activeOrderKey: input.state.thread.activeOrderKey }),
16811684
lineage: input.state.thread.lineage,
1685+
...(input.state.thread.openedByThreadId === undefined
1686+
? {}
1687+
: { openedByThreadId: input.state.thread.openedByThreadId }),
16821688
forkedFrom: input.state.thread.forkedFrom,
16831689
activeProviderThreadId: input.state.thread.activeProviderThreadId,
16841690
...(input.state.thread.historyOrigin === undefined

‎apps/server/src/orchestration-v2/ThreadLaunchService.test.ts‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,25 @@ it.effect("retains automation and sender attribution while a message waits in th
394394
}).pipe(Effect.provide(harness.layer));
395395
});
396396

397+
it.effect("records the launching thread on the new thread and its shell", () => {
398+
const harness = makeHarness();
399+
return Effect.gen(function* () {
400+
const launches = yield* ThreadLaunch.ThreadLaunchService;
401+
const threads = yield* ThreadManagement.ThreadManagementService;
402+
const openedByThreadId = ThreadId.make("thread:launcher");
403+
const launched = yield* launches.launch({
404+
...launchInput({ command: "command:opened-by", thread: "thread:opened-by" }),
405+
openedByThreadId,
406+
createdBy: "agent",
407+
creationSource: "mcp",
408+
});
409+
const projection = yield* threads.getThreadProjection(launched.threadId);
410+
assert.equal(projection.thread.openedByThreadId, openedByThreadId);
411+
const shell = yield* threads.getThreadShell(launched.threadId);
412+
assert.equal(shell?.openedByThreadId, openedByThreadId);
413+
}).pipe(Effect.provide(harness.layer));
414+
});
415+
397416
it.effect("returns a visible preparing message while provisioning is still blocked", () =>
398417
Effect.gen(function* () {
399418
const worktreeEntered = yield* Deferred.make<void>();

‎apps/server/src/orchestration-v2/ThreadLaunchService.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ export interface ThreadLaunchInput {
8484
readonly interactionMode: ProviderInteractionMode;
8585
readonly workspaceStrategy: ThreadLaunchWorkspaceStrategy;
8686
readonly initialMessage?: ThreadLaunchInitialMessage;
87+
/** Thread whose agent launched this one, recorded on the new thread. */
88+
readonly openedByThreadId?: ThreadId;
8789
readonly importedNativeThread?: {
8890
readonly ref: {
8991
readonly driver: ProviderDriverKind;
@@ -783,6 +785,9 @@ const make = Effect.gen(function* () {
783785
interactionMode: input.interactionMode,
784786
branch: initialBranch,
785787
worktreePath: initialWorktreePath,
788+
...(input.openedByThreadId === undefined
789+
? {}
790+
: { openedByThreadId: input.openedByThreadId }),
786791
...(input.importedNativeThread === undefined
787792
? {}
788793
: { importedNativeThread: input.importedNativeThread }),

‎apps/web/src/components/LegacySidebar.tsx‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { Spinner } from "~/components/ui/spinner";
44
import {
55
ArchiveIcon,
66
ArrowUpDownIcon,
7+
BotIcon,
78
ChevronRightIcon,
89
FolderPlusIcon,
910
Globe2Icon,
@@ -49,6 +50,7 @@ import {
4950
AuthPreviewOperateScope,
5051
type ContextMenuItem,
5152
type EnvironmentId,
53+
isAgentOpenedThread,
5254
ProjectId,
5355
type ScopedThreadRef,
5456
type ResolvedKeybindingsConfig,
@@ -826,6 +828,13 @@ const SidebarThreadRow = memo(function SidebarThreadRow(props: SidebarThreadRowP
826828
<TooltipPopup side="top">{thread.title}</TooltipPopup>
827829
</Tooltip>
828830
)}
831+
{isAgentOpenedThread(thread.source) ? (
832+
<BotIcon
833+
aria-label="Opened by an agent"
834+
role="img"
835+
className="size-3 shrink-0 text-muted-foreground/65"
836+
/>
837+
) : null}
829838
</div>
830839
<div className="ml-auto flex shrink-0 items-center gap-1.5">
831840
{canOperatePreview && discoveredPorts.length > 0 && (

‎apps/web/src/components/Sidebar.tsx‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ import {
5454
} from "@t3tools/client-runtime/environment";
5555
import {
5656
AuthOrchestrationOperateScope,
57+
isAgentOpenedThread,
5758
type EnvironmentMachineKind,
5859
type ScopedThreadRef,
5960
type ThreadId,
@@ -64,6 +65,7 @@ import {
6465
AlarmClockIcon,
6566
AlarmClockOffIcon,
6667
ArrowRightLeftIcon,
68+
BotIcon,
6769
CheckIcon,
6870
CircleAlertIcon,
6971
CircleCheckIcon,
@@ -525,6 +527,12 @@ function SidebarThreadTooltip({
525527
</div>
526528
</div>
527529
) : null}
530+
{isAgentOpenedThread(thread.source) ? (
531+
<div className="flex min-w-0 items-center gap-2">
532+
<BotIcon className="size-3 shrink-0 stroke-muted-foreground" />
533+
<div className="min-w-0 truncate text-foreground/75">Opened by an agent</div>
534+
</div>
535+
) : null}
528536
{previousProviderNames.length > 0 ? (
529537
<div className="flex min-w-0 items-center gap-2">
530538
<ArrowRightLeftIcon className="size-3 shrink-0 stroke-muted-foreground" />
@@ -1748,6 +1756,15 @@ const SidebarThreadRow = memo(function SidebarThreadRow(props: {
17481756
<TooltipPopup side="top">Unsent draft</TooltipPopup>
17491757
</Tooltip>
17501758
) : null;
1759+
// Quiet marker for threads an agent opened; the hover card and thread details name it.
1760+
const agentOpenedIndicator = isAgentOpenedThread(thread.source) ? (
1761+
<BotIcon
1762+
aria-label="Opened by an agent"
1763+
role="img"
1764+
data-testid={`sidebar-agent-opened-${thread.id}`}
1765+
className="size-3 shrink-0 text-muted-foreground/65"
1766+
/>
1767+
) : null;
17511768
const showPin =
17521769
props.isPinned && (!sortable?.isDragging || (props.dragOverPinned && props.dropVerb === null));
17531770
const pinIndicator = showPin ? (
@@ -1830,6 +1847,7 @@ const SidebarThreadRow = memo(function SidebarThreadRow(props: {
18301847
</span>
18311848
{draftIndicator}
18321849
{title}
1850+
{agentOpenedIndicator}
18331851
{pinIndicator}
18341852
{terminalStatusIcon}
18351853
{isRegeneratingTitle ? (
@@ -2000,6 +2018,7 @@ const SidebarThreadRow = memo(function SidebarThreadRow(props: {
20002018
) : (
20012019
<span className="flex-1" />
20022020
)}
2021+
{agentOpenedIndicator}
20032022
{pinIndicator}
20042023
{/* The visible state owns this slot's width: status at rest,
20052024
actions on hover/keyboard focus or while the popover is open. Keeping

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

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {
1717
threadRelationshipRowStatus,
1818
orderWebThreadLineageRows,
1919
resolveMergeBackTargetThreadId,
20+
resolveThreadOpener,
2021
type ThreadRelationshipEdge,
2122
type ThreadRelationshipWalkRow,
2223
} from "@t3tools/client-runtime/state/thread-relationships";
@@ -59,7 +60,9 @@ import { Menu, MenuItem, MenuPopup, MenuTrigger } from "../ui/menu";
5960
import { Tooltip, TooltipPopup, TooltipTrigger } from "../ui/tooltip";
6061
import { toastManager } from "../ui/toast";
6162
import {
63+
THREAD_DETAILS_PANEL_ICON_CLASS,
6264
THREAD_DETAILS_PANEL_LINK_SPLIT_GROUP_CLASS,
65+
THREAD_DETAILS_PANEL_LOCKED_ROW_CLASS,
6366
THREAD_DETAILS_PANEL_ROW_CONTENT_CLASS,
6467
THREAD_DETAILS_PANEL_SPLIT_SEPARATOR_CLASS,
6568
} from "./threadDetailsPanelStyles";
@@ -153,6 +156,36 @@ function ThreadLineageGroup(props: {
153156
);
154157
}
155158

159+
/** First Lineage row for a thread an agent opened, linking the opener when known. */
160+
function ThreadOpenerRow(props: {
161+
readonly openerTitle: string | null;
162+
readonly onOpen: (() => void) | null;
163+
}) {
164+
const content = (
165+
<>
166+
<BotIcon aria-hidden className={THREAD_DETAILS_PANEL_ICON_CLASS} />
167+
<span className="min-w-0 flex-1 truncate text-left text-sm leading-4">
168+
<span className="font-normal text-muted-foreground">Opened by </span>
169+
<span className="font-medium text-foreground/85">{props.openerTitle ?? "an agent"}</span>
170+
</span>
171+
</>
172+
);
173+
return (
174+
<li className="group flex h-8 items-center rounded-lg" data-thread-opener>
175+
{props.onOpen ? (
176+
<ThreadDetailsControl size="sm" variant="ghost" part="row" onClick={props.onOpen}>
177+
{content}
178+
<ArrowRightIcon className="size-3 shrink-0 text-muted-foreground opacity-0 transition-opacity group-hover:opacity-100" />
179+
</ThreadDetailsControl>
180+
) : (
181+
<span className={`flex items-center ${THREAD_DETAILS_PANEL_LOCKED_ROW_CLASS}`}>
182+
{content}
183+
</span>
184+
)}
185+
</li>
186+
);
187+
}
188+
156189
function relationshipLabel(edge: ThreadRelationshipEdge, currentThreadId: ThreadId) {
157190
if (edge.kind === "transfer") return "Context transfer";
158191
if (edge.kind === "subagent") {
@@ -252,6 +285,8 @@ export function ThreadRelationshipsPanel(props: {
252285
}),
253286
[graph, mergeTargetThreadId, props.threadId],
254287
);
288+
const opener = currentThread ? resolveThreadOpener(currentThread) : null;
289+
const openerThread = opener?.threadId ? graph.nodes.get(opener.threadId)?.thread : null;
255290
const canMerge = mergeTargetThreadId !== null && latestMergeBackRun !== null;
256291
const canDetach = projection ? canDetachThreadProviderSession(projection) : false;
257292

@@ -279,7 +314,7 @@ export function ThreadRelationshipsPanel(props: {
279314
(agent) => agent.childThreadId === null && agent.status === "running",
280315
).length ?? 0) + active.filter(({ edge }) => edge.status === "running").length;
281316

282-
if (relationshipRows.length === 0 && runningCount === 0) {
317+
if (relationshipRows.length === 0 && runningCount === 0 && opener === null) {
283318
return null;
284319
}
285320

@@ -364,6 +399,14 @@ export function ThreadRelationshipsPanel(props: {
364399
) : null
365400
}
366401
>
402+
{opener ? (
403+
<ul aria-label="Opened by" className="m-0 list-none p-0">
404+
<ThreadOpenerRow
405+
openerTitle={openerThread?.title ?? null}
406+
onOpen={openerThread ? () => openThread(openerThread.id) : null}
407+
/>
408+
</ul>
409+
) : null}
367410
{groups.map((group) => (
368411
<ThreadLineageGroup key={`${scopedThreadKey(ref)}:${group.id}`} {...group}>
369412
{(visibleRows) =>

0 commit comments

Comments
 (0)