Skip to content

Commit 151c241

Browse files
authored
fix(client-runtime): format subagent descriptions as display names (#14999)
1 parent 4f7760e commit 151c241

2 files changed

Lines changed: 50 additions & 2 deletions

File tree

‎packages/client-runtime/src/state/threadExecution.test.ts‎

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,49 @@ describe("threadRuntimeCanArchive", () => {
478478
});
479479

480480
describe("presentPendingBackgroundWork", () => {
481+
it.each(["Subagent:", "Subagent: "])(
482+
"falls back to the subagent noun when %s has no display name",
483+
(description) => {
484+
const presentation = presentPendingBackgroundWork([
485+
{ taskId: "unnamed", kind: "subagent", description },
486+
]);
487+
488+
expect(presentation?.title).toBe("Waiting on a subagent");
489+
expect(presentation?.items[0]?.label).toBe("subagent");
490+
},
491+
);
492+
493+
it.each([
494+
"/root/luna_window_properties",
495+
"Subagent: /root/luna_window_properties",
496+
"/root/parent/luna_window_properties",
497+
])("uses the subagent display name for %s", (description) => {
498+
const childThreadId = ThreadId.make("thread:luna");
499+
const presentation = presentPendingBackgroundWork([
500+
{ taskId: "luna", kind: "subagent", description, childThreadId },
501+
]);
502+
503+
expect(presentation).toEqual({
504+
title: "Waiting on subagent Luna Window Properties",
505+
items: [{ taskId: "luna", kind: "subagent", label: "Luna Window Properties", childThreadId }],
506+
});
507+
});
508+
509+
it("formats subagent names in a mixed roster and preserves command descriptions", () => {
510+
const presentation = presentPendingBackgroundWork([
511+
{ taskId: "cmd", kind: "command", description: "/root/run_tests" },
512+
{ taskId: "luna", kind: "subagent", description: "/root/luna_window_properties" },
513+
{ taskId: "review", kind: "subagent", description: "Review src/math.ts" },
514+
]);
515+
516+
expect(presentation?.title).toBe("Waiting on 2 subagents and 1 command");
517+
expect(presentation?.items.map((item) => item.label)).toEqual([
518+
"Luna Window Properties",
519+
"Review src/math.ts",
520+
"/root/run_tests",
521+
]);
522+
});
523+
481524
it("names a single piece of work by kind", () => {
482525
expect(
483526
presentPendingBackgroundWork([

‎packages/client-runtime/src/state/threadExecution.ts‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import {
2525
type ThreadRunSummary,
2626
type ThreadRuntimeSummary,
2727
} from "./models.ts";
28+
import { formatSubagentDisplayTitle } from "./subagentDisplay.ts";
2829

2930
const ACTIVITY_RUN_STATUSES = new Set(["preparing", "starting", "running", "waiting"]);
3031
const INTERRUPTIBLE_RUN_STATUSES = new Set(["preparing", "starting", "running"]);
@@ -295,13 +296,17 @@ export function presentPendingBackgroundWork(
295296
const items = tasks
296297
.map((task): PendingBackgroundWorkItem => {
297298
const description = task.description?.trim();
299+
const label =
300+
task.kind === "subagent" && description !== undefined
301+
? formatSubagentDisplayTitle(description).trim()
302+
: description;
298303
return {
299304
taskId: task.taskId,
300305
kind: task.kind,
301306
label:
302-
description === undefined || description.length === 0
307+
label === undefined || label.length === 0
303308
? BACKGROUND_WORK_KINDS[task.kind].singular
304-
: description,
309+
: label,
305310
childThreadId: task.kind === "subagent" ? task.childThreadId : undefined,
306311
};
307312
})

0 commit comments

Comments
 (0)