Skip to content

Commit 45e4c83

Browse files
authored
feat(ui): show live subagent activity rows (#121840)
* feat(ui): show live subagent activity rows * test(ui): split subagent activity coverage
1 parent 768f53d commit 45e4c83

17 files changed

Lines changed: 926 additions & 35 deletions

‎ui/src/i18n/locales/en.ts‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5351,6 +5351,14 @@ export const en: TranslationMap = {
53515351
output: "Output",
53525352
promptUnavailable: "Prompt unavailable.",
53535353
outputPending: "No output yet.",
5354+
subagentActivity: {
5355+
label: "Subagent activity",
5356+
working: "Subagent working",
5357+
finished: "Subagent finished",
5358+
failed: "Subagent failed",
5359+
cancelled: "Subagent cancelled",
5360+
moreWorking: "+{count} more working",
5361+
},
53545362
},
53555363
sessionDiff: {
53565364
title: "Changes",

‎ui/src/lib/chat/chat-types.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,8 @@ export type ToolCard = {
196196
outputText?: string;
197197
/** Structured tool result details (e.g. the edit tool's precomputed diff). */
198198
details?: unknown;
199+
/** Monotonic edit counts while a live tool call is still receiving input. */
200+
liveDiffStat?: { added: number; removed: number };
199201
isError?: boolean;
200202
/** True when the card comes from the live tool stream of the current run. */
201203
live?: boolean;

‎ui/src/lib/chat/tool-cards.ts‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { asNullableObjectRecord as readRecord } from "@openclaw/normalization-core/record-coerce";
12
import { truncateUtf16Safe } from "@openclaw/normalization-core/utf16-slice";
23
// Control UI chat domain owns pure tool-card extraction rules.
34
import {
@@ -298,6 +299,16 @@ function extractToolCards(message: unknown, prefix = "tool"): ToolCard[] {
298299
const content = normalizeContent(m.content);
299300
const messageIsError = readToolErrorFlag(m);
300301
const isLiveToolStream = m["__openclawToolStreamLive"] === true;
302+
const liveDiff = readRecord(m["__openclawToolStreamDiffStat"]);
303+
const liveDiffStat =
304+
typeof liveDiff?.added === "number" &&
305+
Number.isInteger(liveDiff.added) &&
306+
liveDiff.added >= 0 &&
307+
typeof liveDiff.removed === "number" &&
308+
Number.isInteger(liveDiff.removed) &&
309+
liveDiff.removed >= 0
310+
? { added: liveDiff.added, removed: liveDiff.removed }
311+
: undefined;
301312
const cards: ToolCard[] = [];
302313
const fallbackMatchedCards = new WeakSet<ToolCard>();
303314
const transcriptMessageId = resolveTranscriptMessageId(m);
@@ -320,6 +331,7 @@ function extractToolCards(message: unknown, prefix = "tool"): ToolCard[] {
320331
...(isLiveToolStream
321332
? { live: true, completed: m["__openclawToolStreamResultReceived"] === true }
322333
: {}),
334+
...(liveDiffStat ? { liveDiffStat } : {}),
323335
messageId: transcriptMessageId,
324336
});
325337
continue;

‎ui/src/pages/chat/background-tasks.e2e.test.ts‎

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ const runningSubagent = {
3636
status: "running",
3737
title: "Map model routing code",
3838
agentId: "main",
39+
sessionKey: chatSessionKey,
3940
ownerKey: chatSessionKey,
4041
childSessionKey: "agent:main:subagent:routing",
4142
createdAt: baseTime - 5_000,
@@ -323,6 +324,111 @@ suite.define(() => {
323324
);
324325
});
325326

327+
it("streams two subagent activity rows and retains final diff chips", async () => {
328+
const activityDir = path.join(artifactDir, "subagent-activity");
329+
await mkdir(activityDir, { recursive: true });
330+
await suite.withPage(
331+
{
332+
locale: "en-US",
333+
recordVideo: { dir: activityDir, size: { width: 1280, height: 800 } },
334+
serviceWorkers: "block",
335+
viewport: { width: 1280, height: 800 },
336+
},
337+
async ({ page }) => {
338+
const gateway = await installMockGateway(page, {
339+
historyMessages: [
340+
{
341+
content: [{ type: "text", text: "Parallel subagent activity proof." }],
342+
role: "assistant",
343+
timestamp: Date.now(),
344+
},
345+
],
346+
methodResponses: { "tasks.list": { tasks: [] } },
347+
});
348+
349+
const response = await page.goto(`${suite.server.baseUrl}chat`);
350+
expect(response?.status()).toBe(200);
351+
await page.getByText("Parallel subagent activity proof.").waitFor({ timeout: 10_000 });
352+
353+
const first = {
354+
...runningSubagent,
355+
id: "task-parallel-one",
356+
taskId: "task-parallel-one",
357+
childSessionKey: "agent:main:subagent:parallel-one",
358+
title: "Review session ownership",
359+
lastActivity: "Reviewing session ownership",
360+
diffStat: { files: 2, added: 14, removed: 3 },
361+
};
362+
const second = {
363+
...runningSubagent,
364+
id: "task-parallel-two",
365+
taskId: "task-parallel-two",
366+
childSessionKey: "agent:main:subagent:parallel-two",
367+
title: "Review tool card rendering",
368+
lastActivity: "Checking tool card rendering",
369+
diffStat: { files: 1, added: 5, removed: 0 },
370+
};
371+
await gateway.emitGatewayEvent("task", { action: "upserted", task: first });
372+
await gateway.emitGatewayEvent("task", { action: "upserted", task: second });
373+
374+
const activity = page.locator(".chat-subagent-activity");
375+
await expect.poll(() => activity.locator(".chat-subagent-activity__row").count()).toBe(2);
376+
const firstRow = activity.locator('[data-subagent-task-id="task-parallel-one"]');
377+
const secondRow = activity.locator('[data-subagent-task-id="task-parallel-two"]');
378+
expect(await firstRow.textContent()).toContain("Reviewing session ownership");
379+
expect(await secondRow.textContent()).toContain("Checking tool card rendering");
380+
expect(await firstRow.locator(".chat-diffstat__add").textContent()).toBe("+14");
381+
expect(await firstRow.locator(".chat-diffstat__del").textContent()).toBe("-3");
382+
await page.screenshot({
383+
path: path.join(activityDir, "01-two-subagents-streaming.png"),
384+
fullPage: true,
385+
});
386+
387+
await gateway.emitGatewayEvent("task", {
388+
action: "upserted",
389+
task: {
390+
...first,
391+
updatedAt: baseTime + 1_000,
392+
lastActivity: "Cross-checking requester ownership",
393+
},
394+
});
395+
await firstRow.getByText("Cross-checking requester ownership").waitFor();
396+
397+
await gateway.emitGatewayEvent("task", {
398+
action: "upserted",
399+
task: {
400+
id: first.id,
401+
taskId: first.taskId,
402+
kind: first.kind,
403+
runtime: first.runtime,
404+
status: "completed",
405+
title: first.title,
406+
agentId: first.agentId,
407+
sessionKey: first.sessionKey,
408+
ownerKey: first.ownerKey,
409+
childSessionKey: first.childSessionKey,
410+
createdAt: first.createdAt,
411+
startedAt: first.startedAt,
412+
updatedAt: baseTime + 2_000,
413+
endedAt: baseTime + 2_000,
414+
terminalSummary: "Ownership review complete",
415+
},
416+
});
417+
418+
await firstRow.getByText("Subagent finished").waitFor();
419+
expect(await firstRow.textContent()).toContain("Ownership review complete");
420+
expect(await firstRow.locator(".chat-diffstat__add").textContent()).toBe("+14");
421+
expect(await firstRow.locator(".chat-diffstat__del").textContent()).toBe("-3");
422+
expect(await secondRow.textContent()).toContain("Subagent working");
423+
expect(await secondRow.textContent()).toContain("Checking tool card rendering");
424+
await page.screenshot({
425+
path: path.join(activityDir, "02-one-subagent-finished.png"),
426+
fullPage: true,
427+
});
428+
},
429+
);
430+
});
431+
326432
it("shows one detached exec after the agent turn ends", async () => {
327433
await suite.withPage(
328434
{

‎ui/src/pages/chat/chat-session-rail.test.ts‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,12 @@ function backgroundTasksToggleProps(): BackgroundTasksProps {
5252
loading: false,
5353
error: null,
5454
tasks: null,
55+
subagentActivity: {
56+
rows: [],
57+
overflowWorking: 0,
58+
taskIds: new Set<string>(),
59+
nextExpiryAt: null,
60+
},
5561
view: { kind: "list" },
5662
taskDetails: new Map(),
5763
taskDetailErrors: new Map(),

‎ui/src/pages/chat/chat-view.test.ts‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -777,6 +777,12 @@ function createBackgroundTasks(
777777
loading: false,
778778
error: null,
779779
tasks: [],
780+
subagentActivity: {
781+
rows: [],
782+
overflowWorking: 0,
783+
taskIds: new Set<string>(),
784+
nextExpiryAt: null,
785+
},
780786
view: { kind: "list" },
781787
cancellingTaskIds: new Set<string>(),
782788
finishedCollapsed: false,

‎ui/src/pages/chat/components/chat-background-tasks-status.ts‎

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,15 @@ import {
1414
import type { TaskSummary } from "../../../lib/tasks/task-summary.ts";
1515
import { STATUS_TONES } from "./chat-background-tasks-shared.ts";
1616
import type { BackgroundTasksProps } from "./chat-background-tasks.types.ts";
17+
import { renderSubagentActivity } from "./chat-subagent-activity.ts";
1718

1819
type BackgroundTasksStatus = { count: number; startedMs: number | null };
1920

2021
/** Summary for the bottom-of-thread status row: active-task count plus the
2122
* oldest active start time so the row ticks one elapsed label, not one per
2223
* task. `startedMs` is null when no active task has a usable timestamp. */
23-
function activeBackgroundTasksStatus(
24-
props: BackgroundTasksProps | undefined,
25-
): BackgroundTasksStatus | null {
26-
const active = props?.tasks?.filter(isActiveTask) ?? [];
24+
function activeBackgroundTasksStatus(tasks: readonly TaskSummary[]): BackgroundTasksStatus | null {
25+
const active = tasks.filter(isActiveTask);
2726
if (active.length === 0) {
2827
return null;
2928
}
@@ -72,8 +71,8 @@ function renderStatusPreviewRow(task: TaskSummary): TemplateResult {
7271
/** Hover/focus preview on the status row: the latest tasks at a glance
7372
* without opening the rail. Content is read-only — a tooltip is a transient
7473
* surface, so actions stay in the rail the click opens. */
75-
function renderStatusPreview(props: BackgroundTasksProps): TemplateResult {
76-
const { active, recent } = partitionTasks(props.tasks ?? []);
74+
function renderStatusPreview(remainingTasks: readonly TaskSummary[]): TemplateResult {
75+
const { active, recent } = partitionTasks(remainingTasks);
7776
const tasks = [...active, ...recent];
7877
const preview = tasks.slice(0, STATUS_PREVIEW_LIMIT);
7978
const overflow = tasks.length - preview.length;
@@ -96,12 +95,22 @@ function renderStatusPreview(props: BackgroundTasksProps): TemplateResult {
9695
export function renderBackgroundTasksStatusRow(
9796
backgroundTasks: BackgroundTasksProps | undefined,
9897
): TemplateResult | typeof nothing {
99-
const status = activeBackgroundTasksStatus(backgroundTasks);
10098
// Disconnected snapshots are stale: task events cannot arrive, so a ticking
10199
// "running" claim would be a lie. The rail owns the disconnected state.
102-
if (!backgroundTasks?.connected || !status) {
100+
if (!backgroundTasks?.connected) {
103101
return nothing;
104102
}
103+
const subagentActivity = renderSubagentActivity(backgroundTasks.subagentActivity);
104+
const remainingTasks = (backgroundTasks.tasks ?? []).filter(
105+
(task) => !backgroundTasks.subagentActivity.taskIds.has(task.id),
106+
);
107+
const status = activeBackgroundTasksStatus(remainingTasks);
108+
if (subagentActivity === nothing && !status) {
109+
return nothing;
110+
}
111+
if (!status) {
112+
return subagentActivity;
113+
}
105114
const label =
106115
status.count === 1
107116
? t("chat.backgroundTasks.statusRunningOne")
@@ -114,7 +123,7 @@ export function renderBackgroundTasksStatusRow(
114123
// Keep the live announcement separate from the tooltip: rich preview
115124
// content must not enter the polite region, while the popup must anchor to
116125
// the link itself or its center drifts with the claw and elapsed time.
117-
return html`
126+
const aggregate = html`
118127
<div class="chat-tasks-status" id=${backgroundTasks.statusRowId}>
119128
<span class="chat-tasks-status__claw" aria-hidden="true">${icons.claw}</span>
120129
${status.startedMs !== null
@@ -128,8 +137,9 @@ export function renderBackgroundTasksStatusRow(
128137
<span class="agent-chat__sr-only" role="status">${label}</span>
129138
<openclaw-tooltip class="chat-tasks-status__preview">
130139
<button class="chat-tasks-status__link" type="button" @click=${openRail}>${label}</button>
131-
${renderStatusPreview(backgroundTasks)}
140+
${renderStatusPreview(remainingTasks)}
132141
</openclaw-tooltip>
133142
</div>
134143
`;
144+
return subagentActivity === nothing ? aggregate : html`${subagentActivity}${aggregate}`;
135145
}

0 commit comments

Comments
 (0)