Skip to content

Commit c0ddfb3

Browse files
authored
feat(web): subagent spawns render as an expandable work row (pingdotgg#11433)
1 parent b0c6c3b commit c0ddfb3

6 files changed

Lines changed: 563 additions & 76 deletions

File tree

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
/**
2-
* Agents right-panel surface: the fleet view over the native subagent fold,
3-
* and the ONLY place the roster renders (the chat carries one CTA row per
4-
* spawn batch).
2+
* Agents right-panel surface: the fleet view over the native subagent fold.
3+
* The chat carries one expandable row per spawn batch and links here.
54
*
65
* Visualization rules (from live-test feedback):
76
* - Spawn order is stable. Activity and completion update rows in place.

‎apps/web/src/components/chat/MessagesTimeline.logic.test.ts‎

Lines changed: 137 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1122,6 +1122,141 @@ describe("deriveMessagesTimelineRows", () => {
11221122
]);
11231123
});
11241124

1125+
it("folds a settled subagent spawn row and keeps a live one outside the fold", () => {
1126+
const firstMessage: ChatMessage = {
1127+
id: MessageId.make("assistant-first-entry"),
1128+
role: "assistant",
1129+
text: "Fanning out.",
1130+
turnId: TurnId.make("turn-1"),
1131+
createdAt: "2026-01-01T00:00:01Z",
1132+
updatedAt: "2026-01-01T00:00:02Z",
1133+
streaming: false,
1134+
};
1135+
const entriesWith = (agentSpawn: { workflowId: string | null; agentTaskIds: string[] }) =>
1136+
deriveTimelineEntries(
1137+
[
1138+
firstMessage,
1139+
{
1140+
...firstMessage,
1141+
id: MessageId.make("assistant-final-entry"),
1142+
text: "Done.",
1143+
createdAt: "2026-01-01T00:00:05Z",
1144+
updatedAt: "2026-01-01T00:00:06Z",
1145+
},
1146+
],
1147+
[],
1148+
[
1149+
{
1150+
id: "spawn-entry",
1151+
createdAt: "2026-01-01T00:00:03Z",
1152+
turnId: firstMessage.turnId,
1153+
label: "Ran 2 subagents",
1154+
tone: "tool",
1155+
agentSpawn,
1156+
},
1157+
],
1158+
);
1159+
const direct = entriesWith({ workflowId: null, agentTaskIds: ["agent-a", "agent-b"] });
1160+
const workflow = entriesWith({ workflowId: "wf-1", agentTaskIds: ["wf-1", "agent-a"] });
1161+
const derive = (
1162+
timelineEntries: typeof direct,
1163+
liveAgentTaskIds: ReadonlySet<string> | undefined,
1164+
expandedSpawnEntryIds?: ReadonlySet<string>,
1165+
expandedTurnIds?: ReadonlySet<TurnId>,
1166+
) =>
1167+
deriveMessagesTimelineRows({
1168+
timelineEntries,
1169+
isWorking: false,
1170+
activeTurnStartedAt: null,
1171+
turnDiffSummaries: [],
1172+
supportsConversationRollback: false,
1173+
liveAgentTaskIds,
1174+
expandedSpawnEntryIds,
1175+
...(expandedTurnIds ? { expandedTurnIds } : {}),
1176+
}).map((row) => row.id);
1177+
const folded = ["turn-fold:turn-1", "assistant-final-entry"];
1178+
const unfolded = ["turn-fold:turn-1", "spawn-entry", "assistant-final-entry"];
1179+
1180+
const activeRows = (
1181+
timelineEntries: typeof direct,
1182+
liveAgentTaskIds: ReadonlySet<string>,
1183+
runningTurnId = "turn-1",
1184+
) =>
1185+
deriveMessagesTimelineRows({
1186+
timelineEntries: timelineEntries.slice(0, 2),
1187+
isWorking: true,
1188+
runningTurnId: runningTurnId as TurnId,
1189+
activeTurnStartedAt: "2026-01-01T00:00:00Z",
1190+
turnDiffSummaries: [],
1191+
supportsConversationRollback: false,
1192+
liveAgentTaskIds,
1193+
}).map((row) => row.kind);
1194+
expect(activeRows(direct, new Set(["agent-b"]))).not.toContain("thinking");
1195+
expect(activeRows(workflow, new Set(["wf-1"]))).not.toContain("thinking");
1196+
expect(activeRows(direct, new Set())).toContain("thinking");
1197+
expect(activeRows(direct, new Set(["agent-b"]), "turn-2")).toContain("thinking");
1198+
1199+
for (const [toolLifecycleStatus, tone, sourceActivityKind] of [
1200+
["inProgress", "tool", "tool.updated"],
1201+
["completed", "tool", "tool.completed"],
1202+
// Claude background Bash completions arrive without a command or item type.
1203+
["completed", "info", "task.completed"],
1204+
] as const) {
1205+
const laterTool = {
1206+
id: "later-tool",
1207+
kind: "work" as const,
1208+
createdAt: "2026-01-01T00:00:04Z",
1209+
entry: {
1210+
id: "later-tool",
1211+
turnId: "turn-1" as TurnId,
1212+
createdAt: "2026-01-01T00:00:04Z",
1213+
label: "Read file",
1214+
tone,
1215+
sourceActivityKind,
1216+
toolLifecycleStatus,
1217+
},
1218+
};
1219+
for (const trailingEntries of [[], [laterTool]]) {
1220+
const rows = deriveMessagesTimelineRows({
1221+
timelineEntries: [...direct.slice(0, 2), ...trailingEntries],
1222+
isWorking: true,
1223+
runningTurnId: "turn-1" as TurnId,
1224+
activeTurnStartedAt: "2026-01-01T00:00:00Z",
1225+
turnDiffSummaries: [],
1226+
supportsConversationRollback: false,
1227+
liveAgentTaskIds: new Set(["agent-b"]),
1228+
});
1229+
expect(rows.filter((row) => row.kind === "work-live")).toMatchObject([
1230+
{
1231+
id: "live-activity-row",
1232+
entry: { id: trailingEntries.length ? "later-tool" : "spawn-entry" },
1233+
active: true,
1234+
},
1235+
]);
1236+
expect(rows.some((row) => row.kind === "work" || row.kind === "thinking")).toBe(false);
1237+
}
1238+
}
1239+
1240+
expect(derive(direct, new Set())).toEqual(folded);
1241+
expect(derive(direct, new Set(["agent-b"]))).toEqual(unfolded);
1242+
// A workflow coordinator between phases keeps its batch out of the fold.
1243+
expect(derive(workflow, new Set(["wf-1"]))).toEqual(unfolded);
1244+
expect(derive(workflow, new Set())).toEqual(folded);
1245+
// No live set is known.
1246+
expect(derive(direct, undefined)).toEqual(unfolded);
1247+
// The user has it open: it stays visible under the collapsed fold and
1248+
// keeps its place when the fold is expanded.
1249+
expect(derive(direct, new Set(), new Set(["spawn-entry"]))).toEqual(unfolded);
1250+
expect(
1251+
derive(direct, new Set(), new Set(["spawn-entry"]), new Set(["turn-1" as TurnId])),
1252+
).toEqual([
1253+
"turn-fold:turn-1",
1254+
"assistant-first-entry",
1255+
"spawn-entry",
1256+
"assistant-final-entry",
1257+
]);
1258+
});
1259+
11251260
it("only enables assistant copy for the terminal assistant message in a turn", () => {
11261261
const rows = deriveMessagesTimelineRows({
11271262
timelineEntries: [
@@ -2286,7 +2421,7 @@ describe("deriveMessagesTimelineRows", () => {
22862421
it.each([
22872422
[undefined, true],
22882423
["inProgress", true],
2289-
["completed", false],
2424+
["completed", true],
22902425
["failed", null],
22912426
["declined", false],
22922427
["stopped", false],
@@ -2329,6 +2464,7 @@ describe("deriveMessagesTimelineRows", () => {
23292464
expect(rows.at(-1)).toMatchObject({ kind: "thinking", id: "live-activity-row" });
23302465
} else {
23312466
expect(workLiveRow).toMatchObject({ active });
2467+
if (active) expect(rows.some((row) => row.kind === "thinking")).toBe(false);
23322468
}
23332469
},
23342470
);

‎apps/web/src/components/chat/MessagesTimeline.logic.ts‎

Lines changed: 46 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -577,6 +577,7 @@ function deriveTurnFolds(input: {
577577
terminalAssistantMessageIds: ReadonlySet<string>;
578578
latestTurn: TimelineLatestTurn | null;
579579
unfoldedTurnIds: ReadonlySet<TurnId>;
580+
liveAgentTaskIds: ReadonlySet<string> | undefined;
580581
}): ReadonlyMap<string, TurnFold> {
581582
interface TurnGroup {
582583
entries: Array<TimelineEntry>;
@@ -661,11 +662,22 @@ function deriveTurnFolds(input: {
661662
if (entry.kind === "work" && entry.entry.questionAnswer !== undefined) {
662663
continue;
663664
}
664-
// Agent-spawn CTA rows never fold: workflows outlive their launching
665-
// turn (dynamic spawns, background execution), and folding the CTA
666-
// when the turn settles makes a still-running fleet invisible.
665+
// Workflows outlive their launching turn (dynamic spawns, background
666+
// execution), so a spawn row with a live member or coordinator stays
667+
// outside the fold instead of hiding a still-running fleet. Settled
668+
// spawns fold with the rest of the turn. Without a live set (no agent
669+
// panel model, as in the held paint during a thread switch) every
670+
// spawn row stays out.
667671
if (entry.kind === "work" && entry.entry.agentSpawn !== undefined) {
668-
continue;
672+
const live = input.liveAgentTaskIds;
673+
const { workflowId, agentTaskIds } = entry.entry.agentSpawn;
674+
if (
675+
live === undefined ||
676+
(workflowId !== null && live.has(workflowId)) ||
677+
agentTaskIds.some((taskId) => live.has(taskId))
678+
) {
679+
continue;
680+
}
669681
}
670682
hiddenEntryIds.add(entry.id);
671683
}
@@ -858,6 +870,13 @@ export function deriveMessagesTimelineRows(input: {
858870
activeTurnStartedAt: string | null;
859871
turnDiffSummaries: ReadonlyArray<TurnDiffSummary>;
860872
supportsConversationRollback: boolean;
873+
/**
874+
* Task ids of subagents still working; their spawn row stays outside turn
875+
* folds. Undefined means unknown, which keeps every spawn row out.
876+
*/
877+
liveAgentTaskIds?: ReadonlySet<string> | undefined;
878+
/** Spawn rows the user opened stay visible while their turn fold is collapsed. */
879+
expandedSpawnEntryIds?: ReadonlySet<string> | undefined;
861880
}): MessagesTimelineRow[] {
862881
const turnDiffSummaryByAssistantMessageId = new Map<MessageId, TurnDiffSummary>();
863882
for (const summary of input.turnDiffSummaries) {
@@ -892,11 +911,15 @@ export function deriveMessagesTimelineRows(input: {
892911
terminalAssistantMessageIds,
893912
latestTurn: input.latestTurn ?? null,
894913
unfoldedTurnIds: activeVisualResponseTurnIds,
914+
liveAgentTaskIds: input.liveAgentTaskIds,
895915
});
896916
const collapsedEntryIds = new Set<string>();
897917
for (const fold of foldsByAnchorEntryId.values()) {
898918
if (!input.expandedTurnIds?.has(fold.turnId)) {
899919
for (const entryId of fold.hiddenEntryIds) {
920+
// An opened spawn row keeps its fold membership but is not pulled
921+
// away mid-read when its last member settles.
922+
if (input.expandedSpawnEntryIds?.has(entryId)) continue;
900923
collapsedEntryIds.add(entryId);
901924
}
902925
}
@@ -922,7 +945,6 @@ export function deriveMessagesTimelineRows(input: {
922945
if (
923946
!entryBelongsToActiveTurn(entry, index) ||
924947
entry.kind !== "work" ||
925-
entry.entry.agentSpawn !== undefined ||
926948
entry.entry.questionAnswer !== undefined ||
927949
entry.entry.sourceActivityKind === "context-compaction" ||
928950
entry.entry.tone === "error"
@@ -937,9 +959,14 @@ export function deriveMessagesTimelineRows(input: {
937959
);
938960
const activeWorkAnchor = activeToolEntries[0];
939961
const latestVisibleToolEntry = visibleActiveToolEntries.at(-1);
940-
const latestRunningToolEntry = visibleActiveToolEntries.findLast((entry) =>
941-
workEntryIsActiveTurnActivity(entry.entry),
942-
);
962+
const latestRunningToolEntry = visibleActiveToolEntries.findLast((entry) => {
963+
const spawn = entry.entry.agentSpawn;
964+
return spawn
965+
? entry === latestVisibleToolEntry &&
966+
((spawn.workflowId !== null && input.liveAgentTaskIds?.has(spawn.workflowId)) ||
967+
spawn.agentTaskIds.some((taskId) => input.liveAgentTaskIds?.has(taskId)))
968+
: workEntryIsActiveTurnActivity(entry.entry);
969+
});
943970
const latestToolFailed =
944971
latestRunningToolEntry === undefined &&
945972
latestVisibleToolEntry !== undefined &&
@@ -948,7 +975,10 @@ export function deriveMessagesTimelineRows(input: {
948975
const latestToolKeepsActivityLive =
949976
latestRunningToolEntry !== undefined ||
950977
(latestVisibleToolEntry !== undefined &&
951-
workEntryIndicatesToolSuccess(latestVisibleToolEntry.entry));
978+
latestVisibleToolEntry.entry.agentSpawn === undefined &&
979+
(workEntryIndicatesToolSuccess(latestVisibleToolEntry.entry) ||
980+
(latestVisibleToolEntry.entry.toolLifecycleStatus === "completed" &&
981+
!workEntryDisplayIndicatesToolFailure(latestVisibleToolEntry.entry))));
952982
const activeWorkPlacementEntryId = latestVisibleToolEntry?.id;
953983
const activeWorkRow =
954984
activeWorkAnchor && latestVisibleToolEntry && !latestToolFailed
@@ -990,7 +1020,7 @@ export function deriveMessagesTimelineRows(input: {
9901020
if (activeWorkRow === null) return;
9911021
nextRows.push(activeWorkRow);
9921022
hasActivityRow ||= activeWorkRow.active;
993-
if (!activeWorkRow.expanded) return;
1023+
if (!activeWorkRow.expanded || activeWorkRow.entry.agentSpawn) return;
9941024
nextRows.push(
9951025
expandedWorkGroupRow(
9961026
activeWorkRow.groupId,
@@ -1053,6 +1083,12 @@ export function deriveMessagesTimelineRows(input: {
10531083
timelineEntry.entry.questionAnswer !== undefined ||
10541084
timelineEntry.entry.tone === "error"
10551085
) {
1086+
const spawn = timelineEntry.entry.agentSpawn;
1087+
if (spawn && entryBelongsToActiveTurn(timelineEntry, index)) {
1088+
hasActivityRow ||=
1089+
(spawn.workflowId !== null && input.liveAgentTaskIds?.has(spawn.workflowId)) ||
1090+
spawn.agentTaskIds.some((taskId) => input.liveAgentTaskIds?.has(taskId));
1091+
}
10561092
nextRows.push({
10571093
kind: "work",
10581094
id: timelineEntry.id,

0 commit comments

Comments
 (0)