TypeScript
fix(client-runtime): format subagent descriptions as display names (#14999)
Yash Singh151c241cd2cc
diff --git a/packages/client-runtime/src/state/threadExecution.test.ts b/packages/client-runtime/src/state/threadExecution.test.tsindex 70ed818cadc..7ebd468400f 100644--- a/packages/client-runtime/src/state/threadExecution.test.ts+++ b/packages/client-runtime/src/state/threadExecution.test.ts@@ -478,6 +478,49 @@ describe("threadRuntimeCanArchive", () => {});describe("presentPendingBackgroundWork", () => {+ it.each(["Subagent:", "Subagent: "])(+ "falls back to the subagent noun when %s has no display name",+ (description) => {+ const presentation = presentPendingBackgroundWork([+ { taskId: "unnamed", kind: "subagent", description },+ ]);++ expect(presentation?.title).toBe("Waiting on a subagent");+ expect(presentation?.items[0]?.label).toBe("subagent");+ },+ );++ it.each([+ "/root/luna_window_properties",+ "Subagent: /root/luna_window_properties",+ "/root/parent/luna_window_properties",+ ])("uses the subagent display name for %s", (description) => {+ const childThreadId = ThreadId.make("thread:luna");+ const presentation = presentPendingBackgroundWork([+ { taskId: "luna", kind: "subagent", description, childThreadId },+ ]);++ expect(presentation).toEqual({+ title: "Waiting on subagent Luna Window Properties",+ items: [{ taskId: "luna", kind: "subagent", label: "Luna Window Properties", childThreadId }],+ });+ });++ it("formats subagent names in a mixed roster and preserves command descriptions", () => {+ const presentation = presentPendingBackgroundWork([+ { taskId: "cmd", kind: "command", description: "/root/run_tests" },+ { taskId: "luna", kind: "subagent", description: "/root/luna_window_properties" },+ { taskId: "review", kind: "subagent", description: "Review src/math.ts" },+ ]);++ expect(presentation?.title).toBe("Waiting on 2 subagents and 1 command");+ expect(presentation?.items.map((item) => item.label)).toEqual([+ "Luna Window Properties",+ "Review src/math.ts",+ "/root/run_tests",+ ]);+ });+it("names a single piece of work by kind", () => {expect(presentPendingBackgroundWork([diff --git a/packages/client-runtime/src/state/threadExecution.ts b/packages/client-runtime/src/state/threadExecution.tsindex 0893fadb62c..5101acc062e 100644--- a/packages/client-runtime/src/state/threadExecution.ts+++ b/packages/client-runtime/src/state/threadExecution.ts@@ -25,6 +25,7 @@ import {type ThreadRunSummary,type ThreadRuntimeSummary,} from "./models.ts";+import { formatSubagentDisplayTitle } from "./subagentDisplay.ts";const ACTIVITY_RUN_STATUSES = new Set(["preparing", "starting", "running", "waiting"]);const INTERRUPTIBLE_RUN_STATUSES = new Set(["preparing", "starting", "running"]);@@ -295,13 +296,17 @@ export function presentPendingBackgroundWork(const items = tasks.map((task): PendingBackgroundWorkItem => {const description = task.description?.trim();+ const label =+ task.kind === "subagent" && description !== undefined+ ? formatSubagentDisplayTitle(description).trim()+ : description;return {taskId: task.taskId,kind: task.kind,label:- description === undefined || description.length === 0+ label === undefined || label.length === 0? BACKGROUND_WORK_KINDS[task.kind].singular- : description,+ : label,childThreadId: task.kind === "subagent" ? task.childThreadId : undefined,};})