Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions packages/client-runtime/src/state/threadExecution.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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([
Expand Down
9 changes: 7 additions & 2 deletions packages/client-runtime/src/state/threadExecution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"]);
Expand Down Expand Up @@ -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,
};
})
Expand Down
Loading