Skip to content

Commit 9ff2ef8

Browse files
author
Larry
committed
Group inventory by community and use compact rows outside the current community
Signed-off-by: Larry <627498bd4bd1f281a16431e3c6cce3b5c25b6692798c78672298aefbf2f8f8b5@buzz.block.builderlab.xyz>
1 parent 9ab4a17 commit 9ff2ef8

8 files changed

Lines changed: 301 additions & 44 deletions

‎src/bundled/agents/AgentCard.test.tsx‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,3 +160,13 @@ it("opens identities in a popover and returns focus on Escape", async () => {
160160
await user.keyboard("{Escape}");
161161
expect(trigger).toHaveFocus();
162162
});
163+
164+
it("keeps the exact identity label and row heading in the final card shell", () => {
165+
render(
166+
<AgentCard name="Solo" identities={[]} layout="row" headingLevel={4} />,
167+
);
168+
expect(screen.getByRole("article", { name: "Agent Solo" })).toHaveClass(
169+
"agent-inventory-row",
170+
);
171+
expect(screen.getByRole("heading", { level: 4, name: "Solo" })).toBeVisible();
172+
});

‎src/bundled/agents/AgentCard.tsx‎

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,13 @@ export function AgentCard({
3737
onDelete,
3838
children,
3939
identityLabel = (identity) => identity.name,
40+
layout = "tile",
41+
headingLevel = 3,
4042
}: {
4143
children?: ReactNode;
4244
identityLabel?: (identity: { pubkey: string; name: string }) => string;
45+
layout?: "tile" | "row";
46+
headingLevel?: 3 | 4;
4347
name: string;
4448
avatar?: string | undefined;
4549
identities: AgentLibrary["identities"];
@@ -49,6 +53,7 @@ export function AgentCard({
4953
onDuplicate?: ((agent: AgentView) => void) | undefined;
5054
onDelete?: ((agent: AgentView) => void) | undefined;
5155
}) {
56+
const Heading = headingLevel === 4 ? "h4" : "h3";
5257
const trigger = useRef<HTMLButtonElement>(null);
5358
const presence = usePresenceStatus(
5459
session?.presence,
@@ -95,7 +100,7 @@ export function AgentCard({
95100
return (
96101
<article
97102
aria-label={`Agent ${name}`}
98-
className={`relative flex min-w-0 flex-col gap-4 rounded-2xl border border-primary ${children ? "p-4" : "px-4 py-8"}`}
103+
className={`relative min-w-0 ${layout === "row" ? "agent-inventory-row" : `flex flex-col gap-4 rounded-2xl border border-primary ${children ? "p-4" : "px-4 py-8"}`}`}
99104
>
100105
{onEdit && (
101106
<div className="absolute right-2 top-2">
@@ -199,17 +204,28 @@ export function AgentCard({
199204
alt={name}
200205
fallback={name}
201206
src={picture ?? null}
202-
size={children ? "large" : "fill"}
207+
size={layout === "row" ? "default" : children ? "large" : "fill"}
203208
shape="squircle"
204209
statusBadge={presence === "unknown" ? undefined : presence}
205210
/>
206211
</div>
207-
<h3 className="m-0 min-w-0 max-w-full truncate text-label" title={name}>
212+
<Heading
213+
className="m-0 min-w-0 max-w-full truncate text-label"
214+
title={name}
215+
>
208216
{name}
209-
</h3>
217+
</Heading>
210218
</div>
211219
{children && (
212-
<div className="flex min-w-0 flex-col gap-3">{children}</div>
220+
<div
221+
className={
222+
layout === "row"
223+
? `flex min-w-0 flex-wrap items-center gap-2 ${onEdit ? "pr-8" : ""}`
224+
: "flex min-w-0 flex-col gap-3"
225+
}
226+
>
227+
{children}
228+
</div>
213229
)}
214230
{identities.length && !children ? (
215231
<div className="-mt-3 flex justify-center">

‎src/bundled/agents/AgentControls.css‎

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,65 @@
1212
.agent-model-popup {
1313
max-height: min(36rem, var(--available-height));
1414
}
15+
16+
.agent-inventory-row {
17+
display: grid;
18+
grid-template-columns: minmax(0, 1fr) minmax(0, auto);
19+
align-items: center;
20+
gap: var(--space-4);
21+
padding: var(--space-3) var(--space-4);
22+
}
23+
.agent-inventory-row + .agent-inventory-row {
24+
border-top: 1px solid var(--border-primary);
25+
}
26+
.agent-inventory-row > :last-child {
27+
justify-content: flex-end;
28+
}
29+
.agent-inventory-row details[open] {
30+
flex-basis: 100%;
31+
}
32+
@media (max-width: 640px) {
33+
.agent-inventory-row {
34+
grid-template-columns: minmax(0, 1fr);
35+
gap: var(--space-2);
36+
}
37+
.agent-inventory-row > :last-child {
38+
justify-content: flex-start;
39+
}
40+
}
41+
42+
.agent-inventory-details > summary {
43+
display: flex;
44+
align-items: center;
45+
justify-content: center;
46+
width: 32px;
47+
height: 32px;
48+
border-radius: var(--radius-control);
49+
list-style: none;
50+
}
51+
.agent-inventory-details > summary::-webkit-details-marker {
52+
display: none;
53+
}
54+
.agent-inventory-details > summary:hover {
55+
background: var(--bg-hover);
56+
}
57+
.agent-inventory-details > summary:focus-visible {
58+
outline: 2px solid var(--border-focus);
59+
}
60+
.agent-inventory-details[open] > summary svg {
61+
transform: rotate(180deg);
62+
}
63+
@media (max-width: 640px) {
64+
.agent-inventory-row .agent-control-field {
65+
flex-basis: 100%;
66+
}
67+
}
68+
69+
@media (max-width: 640px) {
70+
.agent-relay-inventory .agent-inventory-row {
71+
grid-template-columns: minmax(0, 1fr) minmax(0, auto);
72+
}
73+
.agent-relay-inventory .agent-inventory-row > :last-child {
74+
justify-content: flex-end;
75+
}
76+
}

‎src/bundled/agents/InventoryIdentityCard.test.tsx‎

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ function setup(
8282
key={row.pubkey}
8383
row={row}
8484
decision={inventoryDecision(row, destination)}
85+
community=""
8586
state={{ ...control.snapshot(), status: "ready", data: f.data }}
8687
control={control}
8788
session={owned.session}
@@ -122,7 +123,7 @@ it("browses durable parked identities while disconnected without reading old fil
122123
expect(within(card).getByText(npubEncode("cd".repeat(32)))).not.toBeVisible();
123124
fireEvent.click(
124125
within(card).queryByText("Identity & sources") ??
125-
within(card).getByText("Identity & sources"),
126+
within(card).getByLabelText(/^Details for /),
126127
);
127128
expect(within(card).getByText(npubEncode("cd".repeat(32)))).toBeVisible();
128129
expect(within(card).getByText("Development Buzz")).toBeVisible();
@@ -145,7 +146,10 @@ it("offers Clone for a configured other-community setup and keeps its exact cont
145146
const card = await screen.findByRole("article", {
146147
name: "Agent Fixture agent",
147148
});
148-
expect(within(card).getByText("Identity & sources")).toBeVisible();
149+
expect(card).toHaveClass("agent-inventory-row");
150+
expect(
151+
within(card).getByLabelText("Details for Fixture agent"),
152+
).toBeVisible();
149153
// The app runs this setup, so its lifecycle and settings stay reachable here.
150154
expect(within(card).getByRole("button", { name: "Start" })).toBeVisible();
151155
expect(
@@ -182,7 +186,7 @@ it("makes Import primary and explains how secondary Clone creates a different id
182186
});
183187
const importButton = within(card).getByRole("button", { name: "Import" });
184188
expect(within(card).getByRole("button", { name: "Clone" })).not.toBeVisible();
185-
fireEvent.click(within(card).getByText("Identity & sources"));
189+
fireEvent.click(within(card).getByLabelText(/^Details for /));
186190
const cloneButton = within(card).getByRole("button", { name: "Clone" });
187191
expect(importButton).toBeEnabled();
188192
expect(cloneButton).toBeEnabled();
@@ -239,7 +243,7 @@ it.each([
239243
expect(!!within(card).queryByRole("button", { name: "Import" })).toBe(
240244
showImport,
241245
);
242-
fireEvent.click(within(card).getByText("Identity & sources"));
246+
fireEvent.click(within(card).getByLabelText(/^Details for /));
243247
expect(!!within(card).queryByRole("button", { name: "Clone" })).toBe(
244248
showClone,
245249
);
@@ -268,7 +272,7 @@ it("dispatches the chosen source and exact key without importing credentials", (
268272
});
269273
fireEvent.click(within(card).getByRole("button", { name: "Import" }));
270274
expect(onImport).toHaveBeenCalledWith("cd".repeat(32), "development");
271-
fireEvent.click(within(card).getByText("Identity & sources"));
275+
fireEvent.click(within(card).getByLabelText(/^Details for /));
272276
fireEvent.click(within(card).getByRole("button", { name: "Clone" }));
273277
expect(onUseHere).toHaveBeenCalledWith(
274278
"cd".repeat(32),

‎src/bundled/agents/InventoryIdentityCard.tsx‎

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import type {
77
} from "../../features/agents/control";
88
import type { RelaySession } from "../../features/relay/session";
99
import type { Profile } from "../../features/relay/contracts";
10+
import { CaretDownIcon } from "../../shared/design-system/icons/index";
1011
import { Button } from "../../shared/design-system/ui/Button";
1112
import { AgentCard } from "./AgentCard";
1213
import { ManagedAgentActions } from "./ManagedAgentActions";
@@ -17,6 +18,7 @@ import { type AgentInventoryIdentity, localSetups } from "./inventory-model";
1718
export function InventoryIdentityCard({
1819
row,
1920
decision,
21+
community,
2022
state,
2123
control,
2224
session,
@@ -33,6 +35,7 @@ export function InventoryIdentityCard({
3335
}: {
3436
row: AgentInventoryIdentity;
3537
decision: ReturnType<typeof inventoryDecision>;
38+
community: string;
3639
state: AgentControlState;
3740
control: AgentControl;
3841
session: RelaySession;
@@ -90,6 +93,8 @@ export function InventoryIdentityCard({
9093
);
9194
return (
9295
<AgentCard
96+
layout={tile ? "tile" : "row"}
97+
headingLevel={community ? 4 : 3}
9398
name={row.displayName}
9499
avatar={avatar}
95100
identities={[{ pubkey: row.pubkey, name: row.displayName }]}
@@ -103,6 +108,8 @@ export function InventoryIdentityCard({
103108
<ManagedAgentActions
104109
key={agent.id}
105110
agent={agent}
111+
// A section already names its own community; other setups still show theirs.
112+
showCommunity={row.localSetups.get(community) !== agent}
106113
state={state}
107114
control={control}
108115
imported={agent.id === importedId}
@@ -190,8 +197,23 @@ export function InventoryIdentityCard({
190197
{decision.blocked}
191198
</p>
192199
)}
193-
<details className="min-w-0 text-body-sm text-secondary">
194-
<summary className="cursor-pointer">Identity &amp; sources</summary>
200+
<details
201+
className={
202+
tile
203+
? "min-w-0 text-body-sm text-secondary"
204+
: "agent-inventory-details min-w-0 text-body-sm text-secondary"
205+
}
206+
>
207+
<summary
208+
className="cursor-pointer"
209+
aria-label={tile ? undefined : `Details for ${row.displayName}`}
210+
>
211+
{tile ? (
212+
"Identity & sources"
213+
) : (
214+
<CaretDownIcon size={18} aria-hidden="true" />
215+
)}
216+
</summary>
195217
<div className="flex min-w-0 flex-col gap-2 pt-2">
196218
{[...row.knownCommunities]
197219
.filter((community) => community && !row.localSetups.has(community))

‎src/bundled/agents/InventoryView.test.tsx‎

Lines changed: 81 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ it("renders four exclusive sections with all setups on one exact-key card", asyn
198198
).not.toBeVisible();
199199
fireEvent.click(
200200
within(card).queryByText("Identity & sources") ??
201-
within(card).getByText("Identity & sources"),
201+
within(card).getByLabelText(/^Details for /),
202202
);
203203
expect(
204204
within(card).getByText("Installed Buzz · Development Buzz"),
@@ -220,6 +220,86 @@ it("renders four exclusive sections with all setups on one exact-key card", asyn
220220
).toBeVisible();
221221
});
222222

223+
it("nests local rows by saved community once, with unknown last", async () => {
224+
setup("connected", (f) => {
225+
const agent = { ...f.agent };
226+
f.data.agents = [
227+
{
228+
...agent,
229+
id: "z",
230+
name: "Several setups",
231+
relayUrl: "wss://z.example",
232+
},
233+
{
234+
...agent,
235+
id: "a",
236+
name: "Several setups",
237+
relayUrl: "wss://a.example",
238+
},
239+
{
240+
...agent,
241+
id: "b",
242+
pubkey: "bb".repeat(32),
243+
name: "Second",
244+
relayUrl: "wss://b.example",
245+
},
246+
{
247+
...agent,
248+
id: "unknown",
249+
pubkey: "aa".repeat(32),
250+
name: "Legacy",
251+
relayUrl: "",
252+
configured: false,
253+
},
254+
];
255+
});
256+
const group = await screen.findByRole("region", {
257+
name: "Local agents in other communities",
258+
});
259+
expect(
260+
within(group)
261+
.getAllByRole("heading", { level: 3 })
262+
.map((h) => h.textContent),
263+
).toEqual(["https://a.example", "https://b.example", "Community unknown"]);
264+
const first = within(group).getByRole("region", {
265+
name: "https://a.example",
266+
});
267+
const row = within(first).getByRole("article", {
268+
name: "Agent Several setups",
269+
});
270+
expect(
271+
screen.getAllByRole("article", { name: "Agent Several setups" }),
272+
).toHaveLength(1);
273+
expect(within(row).getByRole("heading", { level: 4 })).toHaveTextContent(
274+
"Several setups",
275+
);
276+
// Every saved setup of the key keeps its exact controls on the one row.
277+
expect(within(row).getAllByRole("button", { name: "Stop" })).toHaveLength(2);
278+
fireEvent.click(within(row).getByLabelText(/^Details for /));
279+
// The z setup keeps its own controls, so it names its community there.
280+
expect(within(row).getByText("wss://z.example")).toBeVisible();
281+
expect(within(row).queryByText("wss://a.example")).toBeNull();
282+
expect(within(row).queryByRole("button", { name: "Use here" })).toBeNull();
283+
fireEvent.click(within(row).getByLabelText("Details for Several setups"));
284+
expect(within(row).getByRole("button", { name: "Clone" })).toBeVisible();
285+
expect(
286+
within(group).getByRole("region", { name: "Community unknown" }),
287+
).toHaveTextContent("Legacy");
288+
});
289+
290+
it("does not invent a community for library-only relay identities", async () => {
291+
setup("connected", () => {}, []);
292+
const group = await screen.findByRole("region", {
293+
name: "Relay-only agents",
294+
});
295+
const unknown = within(group).getByRole("region", {
296+
name: "Community unknown",
297+
});
298+
expect(
299+
within(unknown).getByRole("article", { name: "Agent Not imported" }),
300+
).toBeVisible();
301+
});
302+
223303
it("retains the chosen source when an identity card unmounts and returns", () => {
224304
const { rows, redraw, onImport } = setup("connected", (f) => {
225305
f.data.parked = [

0 commit comments

Comments
 (0)