Skip to content

Commit 2fbf4fd

Browse files
committed
fix(ui): preserve configured agent labels
1 parent 3851849 commit 2fbf4fd

5 files changed

Lines changed: 61 additions & 13 deletions

File tree

‎ui/src/components/app-sidebar-agent-menu.ts‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,7 @@ function sidebarAgentMenuRows(params: {
135135
const agentId = normalizeAgentId(entry.id);
136136
return (
137137
agentId.toLowerCase().includes(query) ||
138-
(params.identities.get(agentId)?.name?.trim() || normalizeAgentLabel(entry))
139-
.toLowerCase()
140-
.includes(query)
138+
normalizeAgentLabel(entry, params.identities.get(agentId)).toLowerCase().includes(query)
141139
);
142140
});
143141
return { rows, showFilter: true };
@@ -164,7 +162,7 @@ function sidebarAgentMenuRows(params: {
164162
function renderAgentRow(agent: AgentMenuAgent, params: SidebarAgentMenuParams) {
165163
const agentId = normalizeAgentId(agent.id);
166164
const identity = params.identities.get(agentId) ?? null;
167-
const label = identity?.name?.trim() || normalizeAgentLabel(agent);
165+
const label = normalizeAgentLabel(agent, identity);
168166
const active = agentId === params.activeId;
169167
const unread = active ? 0 : params.agentUnreadCount(agentId);
170168
const approvals = params.agentApprovalCount(agentId);

‎ui/src/components/app-sidebar-render.ts‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,7 @@ export function renderAppSidebarBrand(host: AppSidebarRenderHost) {
8282
const agentId = normalizeAgentId(entry.id);
8383
return agentId !== cardAgentId && host.agentUnreadCount(agentId) > 0;
8484
});
85-
const cardName =
86-
cardIdentity?.name?.trim() || (cardAgent ? normalizeAgentLabel(cardAgent) : cardAgentId);
85+
const cardName = cardAgent ? normalizeAgentLabel(cardAgent, cardIdentity) : cardAgentId;
8786
const approvalCount = host.sessionData.approvalBadgeSnapshot().agentCounts.get(cardAgentId) ?? 0;
8887
const gateway = host.sessionDataContext?.gateway;
8988
const avatarAuthToken = gateway

‎ui/src/components/sidebar-menus-render.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ export function renderSidebarAgentMenuForController(controller: SidebarMenusCont
8484
position,
8585
basePath: host.basePath,
8686
activeId,
87-
activeName: identity?.name?.trim() || (agent ? normalizeAgentLabel(agent) : activeId),
87+
activeName: agent ? normalizeAgentLabel(agent, identity) : activeId,
8888
agents,
8989
identities,
9090
filter: controller.agentMenuFilter,

‎ui/src/lib/agents/display.ts‎

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ import { normalizeLowercaseStringOrEmpty, normalizeOptionalString } from "../str
2323
type AgentRosterEntry = {
2424
id: string;
2525
kind?: "agent" | "system";
26+
name?: string;
27+
identity?: { name?: string };
2628
};
2729

2830
/** Ordinary agent targets; system rows remain available to diagnostic surfaces. */
@@ -319,13 +321,16 @@ type ConfigSnapshot = {
319321
};
320322
};
321323

322-
export function normalizeAgentLabel(agent: {
323-
id: string;
324-
name?: string;
325-
identity?: { name?: string };
326-
}) {
324+
export function normalizeAgentLabel(
325+
agent: AgentRosterEntry,
326+
hydratedIdentity?: { name?: string } | null,
327+
) {
328+
// Roster labels own operator target identity; workspace identity only fills gaps.
327329
return (
328-
normalizeOptionalString(agent.name) ?? normalizeOptionalString(agent.identity?.name) ?? agent.id
330+
normalizeOptionalString(agent.name) ??
331+
normalizeOptionalString(agent.identity?.name) ??
332+
normalizeOptionalString(hydratedIdentity?.name) ??
333+
agent.id
329334
);
330335
}
331336

‎ui/src/test-helpers/app-sidebar-cases/agent-menu.ts‎

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,52 @@ describe("AppSidebar agent chip", () => {
5252
expect(request).toHaveBeenCalledWith("agent.identity.get", { agentId: "main" });
5353
});
5454

55+
it("keeps the configured roster label when identity hydration returns a fallback", async () => {
56+
const request = vi.fn(async (_method: string, params: { agentId: string }) =>
57+
params.agentId === "main"
58+
? { agentId: "main", name: "Workspace Molty", avatar: "🦞" }
59+
: { agentId: "rust-claw", name: "Assistant", avatar: "🦀" },
60+
);
61+
const gatewayHarness = createGatewayHarness({ request } as unknown as GatewayBrowserClient);
62+
const agentIdentity = createAgentIdentityCapability(gatewayHarness.gateway);
63+
const { sidebar } = await mountSidebar(
64+
gatewayHarness.gateway,
65+
createSessions("main", ["agent:main:main"]),
66+
"panel",
67+
{
68+
defaultId: "main",
69+
mainKey: "main",
70+
scope: "per-sender",
71+
agents: [{ id: "main" }, { id: "rust-claw", name: "rust-claw" }],
72+
},
73+
[],
74+
agentIdentity,
75+
);
76+
77+
sidebar.connected = true;
78+
await vi.waitFor(() => {
79+
expect(sidebar.querySelector(".sidebar-agent-card__name")?.textContent?.trim()).toBe(
80+
"Workspace Molty",
81+
);
82+
});
83+
sidebar.querySelector<HTMLButtonElement>(".sidebar-agent-card__main")?.click();
84+
await vi.waitFor(() => {
85+
expect(request).toHaveBeenCalledWith("agent.identity.get", { agentId: "rust-claw" });
86+
const labels = [
87+
...sidebar.querySelectorAll(".sidebar-agent-menu .agent-select__option-label"),
88+
].map((element) => element.textContent?.trim());
89+
expect(labels).toEqual(["Workspace Molty", "rust-claw"]);
90+
});
91+
await vi.waitFor(() => {
92+
const rustRow = [
93+
...sidebar.querySelectorAll<HTMLElement>(".sidebar-agent-menu__agent-switch"),
94+
].find((row) => row.textContent?.includes("rust-claw"));
95+
expect(
96+
rustRow?.querySelector(".agent-select__avatar--text")?.getAttribute("data-avatar"),
97+
).toBe("🦀");
98+
});
99+
});
100+
55101
it("hydrates agents added while the switcher remains open", async () => {
56102
const request = vi.fn(async (_method: string, params: { agentId: string }) => ({
57103
agentId: params.agentId,

0 commit comments

Comments
 (0)