Skip to content

Commit 3858b55

Browse files
delkcBuzzsawcodexGoose
authored
feat(bestie): choose your bestie from the empty state (#2173)
## Why The pinned Bestie DM from #1935 needs a clear starting point when no Bestie is saved. The old page instead launches a separate Builderlab setup flow. This replaces that path with one chooser for existing agents and new agents. ## What - Explain what a bestie means, then offer a searchable picker with avatars, names, and distinct identity labels. - Open the picker below its field, capped at roughly four avatar rows, with search above scrollable results. - Reuse **Create agent**, save the choice to the account, and open the canonical DM. - Keep remote agents eligible, but ask before saving: “Some bestie features aren’t available with remote agents.” Cancel leaves the choice unchanged and keeps any newly created agent. - Show the chooser in place when the saved agent is gone, and clear the account choice after completed deletion. ## How The chooser uses `session.agentChoices`, the shared creation dialog, the existing `main-agent` record, and the pinned DM from #1935. It adds no messaging path or remote capability setup. The shared Combobox gains an opt-in compact popup; other callers keep their current behavior. Deletion checks the current account record before writing `agent: null`. Native signing now admits that cleared value. Existing browser journeys retain their plugin/default and navigation contracts with the new heading; browser cases added/removed: **0/0**. The retired hosted-setup UI assertions are replaced by mounted chooser/save/recovery coverage. ## Risk This removes the separate Builderlab-specific Bestie onboarding, not Builderlab agent creation. The remote warning does not turn on memory or check-ins. Account cleanup is a read/replace, not an atomic compare-and-swap: another device's choice in that gap can be overwritten. A cleanup error reports that deletion completed but the Bestie choice could not be cleared. ## Testing Clay tried the running native app and iterated on the empty-state copy, searchable picker, and popup size/placement. The remote confirmation was opened through the production chooser in an isolated Chromium fixture with a sample hosted agent; no real agent was created or account choice saved. Still deferred: live Builderlab creation → confirmation → account save → DM; deletion and reload persistence on the rebased head; native remote-warning focus behavior; and the full light/dark, viewport, and enlarged-text acceptance pass. These checks remain outstanding; this PR does not claim completed acceptance. ## Bigger picture #1935, Riley’s Bestie tab (#2034), and its memory switch (#2035) are merged. This branch includes main through `23338bc84`, preserving both alongside the empty-state chooser. **Overlap with Riley's #2047:** both replace the empty Bestie page and clear a deleted choice. This PR contains the chooser UI Clay tested today. Riley's PR sits above the Bestie settings/memory/check-in stack, restricts Bestie to local agents, and wires selection into that setup. This PR deliberately allows remote agents with a warning. The tab and memory switch have landed independently. This chooser remains compatible with both; later check-in and setup work must preserve the remote-agent policy. That follow-up must reconcile the duplicate chooser/deletion work and handle nonlocal capabilities without silently restoring a local-only restriction. No changes to Riley's branches are included here. Generated with Goose --------- Signed-off-by: Clay Delk <[email protected]> Co-authored-by: Buzzsaw <a760f3ee1dc0daf403313e35766d0d983a8898aaa9ca95a034727165c63a8680@claysworld.communities.buzz.xyz> Co-authored-by: Codex <[email protected]> Co-authored-by: Goose <[email protected]>
1 parent 018c23e commit 3858b55

29 files changed

Lines changed: 1136 additions & 791 deletions

‎docs/buzz-help.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,11 @@ the interface unless an available tool actually supports that action.
126126
agent discovery fails. If a replacement save fails, the last confirmed Bestie
127127
remains selected and the confirmation offers another attempt. Being the bestie
128128
does not prove an agent is ready or running.
129+
- With the **Bestie** plugin on and no saved choice, **Choose your bestie agent**
130+
offers a searchable agent picker and **Create agent**. Choosing a known remote
131+
agent, including one created through Builderlab, asks for confirmation:
132+
“Some bestie features aren’t available with remote agents.” Cancel leaves the
133+
Bestie choice unchanged; it does not delete a newly created agent.
129134
- **Settings → Agent setup → Harness defaults** is where supported agent types
130135
offer installation, sign-in, and default-model controls. Available controls
131136
depend on the type. Do not assume a provider is configured or signed in.

‎docs/solo/README.md‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,10 @@ behavior on the label, so a rename touches copy only.
136136
the default agent for this account/community. **Agents → right-click or "..." →
137137
Make my bestie** explicitly saves that agent as the bestie; its card then shows
138138
**Bestie**. That choice is saved to the account as a private `main-agent` record,
139-
so every install adopts it once per session. Only this explicit choice writes
140-
the record; a deleted agent left on it is stood in for until the next choice.
139+
so every install adopts it once per session. Explicit choices write the
140+
record. A finished deletion writes no Bestie when a fresh account read still
141+
names the deleted agent. A different choice visible to that read stays; the
142+
read/replace cannot protect a concurrent choice on another device before publish.
141143
The choice stays until it is changed or the agent is deleted, and it is still
142144
tagged when its runtime is signed out or broken. Without a choice, or after the
143145
chosen agent is deleted, the first managed agent, then the first selectable

‎src-tauri/src/identity.rs‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -541,11 +541,12 @@ fn validate_sidebar_payload(coordinate: &str, value: &serde_json::Value) -> Resu
541541
"main-agent" => {
542542
let agent = data.get("agent").ok_or_else(invalid)?;
543543
if data.len() != 2
544-
|| !agent.as_str().is_some_and(|v| {
545-
v.len() == 64
546-
&& v.bytes()
547-
.all(|b| b.is_ascii_digit() || (b'a'..=b'f').contains(&b))
548-
})
544+
|| !(agent.is_null()
545+
|| agent.as_str().is_some_and(|v| {
546+
v.len() == 64
547+
&& v.bytes()
548+
.all(|b| b.is_ascii_digit() || (b'a'..=b'f').contains(&b))
549+
}))
549550
{
550551
return Err(invalid());
551552
}

‎src-tauri/src/identity/tests.rs‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -733,7 +733,7 @@ pub(crate) fn write_denied_fixture() -> (IdentityHost, impl Fn()) {
733733
}
734734

735735
#[tokio::test]
736-
async fn main_agent_signer_admits_only_one_agent() {
736+
async fn main_agent_signer_admits_one_agent_or_a_cleared_choice() {
737737
use serde_json::json;
738738
let host = super::IdentityHost::fixture();
739739
let payload = json!({"version": 1, "agent": "ab".repeat(32)});
@@ -746,9 +746,18 @@ async fn main_agent_signer_admits_only_one_agent() {
746746
host.decode_sidebar(vec![event]).await.unwrap()["main-agent"],
747747
payload
748748
);
749+
let payload = json!({"version": 1, "agent": null});
750+
let event = host
751+
.sign_sidebar("main-agent".into(), payload.clone(), 101)
752+
.await
753+
.unwrap();
754+
host.admit_sidebar(event.clone()).await.unwrap();
755+
assert_eq!(
756+
host.decode_sidebar(vec![event]).await.unwrap()["main-agent"],
757+
payload
758+
);
749759
for invalid in [
750760
json!({"version": 1}),
751-
json!({"version": 1, "agent": null}),
752761
json!({"version": 2, "agent": "ab".repeat(32)}),
753762
json!({"version": 1, "agent": "AB".repeat(32)}),
754763
json!({"version": 1, "agent": "ab".repeat(31)}),

‎src/app/pages.integration.test.mjs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ test("the app runtime exposes ready bundled pages and removes them on disable",
322322
assert.equal(bestiePage.primary, true);
323323
assert.match(
324324
renderToStaticMarkup(createElement(bestiePage.component)),
325-
/Meet your Bestie/,
325+
/Choose a community to continue with your Bestie\./,
326326
);
327327
await services.plugins.change("disable", "buzz.bestie");
328328
assert.equal(
Lines changed: 294 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,294 @@
1+
// @vitest-environment jsdom
2+
import "@testing-library/jest-dom/vitest";
3+
import {
4+
cleanup,
5+
render,
6+
screen,
7+
waitFor,
8+
within,
9+
} from "@testing-library/react";
10+
import userEvent from "@testing-library/user-event";
11+
import { afterEach, expect, it, vi } from "vitest";
12+
import type { Agent, Agents } from "../../features/agents/service";
13+
import type { RelaySession } from "../../features/relay/session";
14+
import { BestieChooser } from "./BestieChooser";
15+
16+
vi.mock("../agents/AgentCreateDialog", () => ({
17+
AgentCreateDialog: ({
18+
onCreated,
19+
}: {
20+
onCreated(agent: { pubkey: string }): void;
21+
}) => (
22+
<button type="button" onClick={() => onCreated({ pubkey: pollen })}>
23+
Finish creation
24+
</button>
25+
),
26+
}));
27+
28+
afterEach(() => {
29+
cleanup();
30+
localStorage.clear();
31+
});
32+
33+
const pollen = "b".repeat(64);
34+
const instruction = "Choose an eligible agent or create a new one:";
35+
36+
function deferred() {
37+
let resolve!: () => void;
38+
const promise = new Promise<void>((done) => {
39+
resolve = done;
40+
});
41+
return { promise, resolve };
42+
}
43+
44+
function fixture(
45+
write: (agent: string | null) => Promise<void>,
46+
initial = [{ pubkey: pollen, name: "Pollen", managed: true }],
47+
place: Agent["place"] = "here",
48+
) {
49+
let selectable = initial;
50+
const makeSnapshot = () =>
51+
({
52+
status: "ready" as const,
53+
complete: true,
54+
pending: false,
55+
selectable,
56+
identities: selectable,
57+
definitions: [],
58+
archives: { status: "ready" as const, archived: [] },
59+
templates: {
60+
status: "ready" as const,
61+
complete: true,
62+
pending: false,
63+
identities: selectable,
64+
definitions: [],
65+
},
66+
}) as const;
67+
let choices = makeSnapshot();
68+
const session = {
69+
mainAgent: { read: async () => undefined, write: vi.fn(write) },
70+
agentChoices: {
71+
snapshot: () => choices,
72+
subscribe: () => () => {},
73+
retain: () => () => {},
74+
ensure: () => {},
75+
refresh: vi.fn(async () => {}),
76+
},
77+
} as unknown as RelaySession;
78+
const agents = {
79+
subscribe: () => () => {},
80+
snapshot: () => undefined,
81+
types: () => empty,
82+
find: (pubkey: string) => ({ pubkey, place }),
83+
} as unknown as Agents;
84+
return {
85+
session,
86+
removeChoice: () => {
87+
selectable = [];
88+
choices = makeSnapshot();
89+
},
90+
mount: () =>
91+
render(
92+
<BestieChooser
93+
session={session}
94+
scope="community:viewer"
95+
agents={agents}
96+
/>,
97+
),
98+
};
99+
}
100+
101+
const empty: readonly never[] = [];
102+
103+
async function selectPollen() {
104+
const user = userEvent.setup();
105+
await user.click(screen.getByRole("combobox", { name: instruction }));
106+
await user.click(await screen.findByRole("option", { name: /^Pollen / }));
107+
return user;
108+
}
109+
110+
it("searches namesakes, shows distinct identities, and selects with the keyboard", async () => {
111+
const other = "c".repeat(64);
112+
const f = fixture(async () => {}, [
113+
{ pubkey: pollen, name: "Pollen", managed: true },
114+
{ pubkey: other, name: "Pollen", managed: true },
115+
{ pubkey: "d".repeat(64), name: "Fizz", managed: true },
116+
]);
117+
f.mount();
118+
const user = userEvent.setup();
119+
const trigger = screen.getByRole("combobox", { name: instruction });
120+
await user.click(trigger);
121+
const search = await screen.findByRole("combobox", { name: "Search" });
122+
await user.type(search, "Nobody");
123+
expect(await screen.findByText("No matching agents.")).toBeVisible();
124+
expect(f.session.mainAgent?.write).not.toHaveBeenCalled();
125+
await user.clear(search);
126+
await user.type(search, "poll");
127+
await waitFor(() => {
128+
const options = screen.getAllByRole("option");
129+
expect(options).toHaveLength(2);
130+
expect(options[0]?.textContent).not.toBe(options[1]?.textContent);
131+
});
132+
await user.keyboard("{Escape}");
133+
await waitFor(() => expect(trigger).toHaveFocus());
134+
expect(f.session.mainAgent?.write).not.toHaveBeenCalled();
135+
await user.click(trigger);
136+
const reopened = await screen.findByRole("combobox", { name: "Search" });
137+
expect(reopened).toHaveValue("");
138+
await user.type(reopened, "poll");
139+
await user.keyboard("{ArrowDown}{End}{Enter}");
140+
await waitFor(() =>
141+
expect(f.session.mainAgent?.write).toHaveBeenCalledWith(other),
142+
);
143+
});
144+
145+
it("holds the selected agent disabled until the account save settles", async () => {
146+
const gate = deferred();
147+
const f = fixture(async () => gate.promise);
148+
f.mount();
149+
await selectPollen();
150+
expect(f.session.mainAgent?.write).toHaveBeenCalledWith(pollen);
151+
expect(screen.getByRole("combobox", { name: instruction })).toBeDisabled();
152+
expect(screen.getByRole("status")).toHaveTextContent("Saving your Bestie…");
153+
gate.resolve();
154+
await waitFor(() =>
155+
expect(screen.getByRole("combobox", { name: instruction })).toBeEnabled(),
156+
);
157+
});
158+
159+
it("keeps the chooser available when the account save fails", async () => {
160+
const f = fixture(async () => {
161+
throw new Error("save failed");
162+
});
163+
f.mount();
164+
await selectPollen();
165+
expect(await screen.findByRole("alert")).toHaveTextContent(
166+
"Your bestie couldn't be saved to your account. Try again.",
167+
);
168+
expect(screen.getByRole("combobox", { name: instruction })).toBeEnabled();
169+
});
170+
171+
it("rejects a choice that became stale before selection", async () => {
172+
const f = fixture(async () => {});
173+
f.mount();
174+
const user = userEvent.setup();
175+
await user.click(screen.getByRole("combobox", { name: instruction }));
176+
const option = await screen.findByRole("option", { name: /^Pollen / });
177+
f.removeChoice();
178+
await user.click(option);
179+
expect(await screen.findByRole("alert")).toHaveTextContent(
180+
"That agent is no longer available. Choose another.",
181+
);
182+
expect(f.session.mainAgent?.write).not.toHaveBeenCalled();
183+
});
184+
185+
it.each(["hosted", "elsewhere"] as const)(
186+
"warns before saving an agent running %s and allows cancellation or confirmation",
187+
async (place) => {
188+
const f = fixture(async () => {}, undefined, place);
189+
f.mount();
190+
const user = await selectPollen();
191+
const dialog = await screen.findByRole("alertdialog", {
192+
name: "Use Pollen as your bestie?",
193+
});
194+
expect(dialog).toHaveAccessibleDescription(
195+
"Some bestie features aren’t available with remote agents.",
196+
);
197+
expect(f.session.mainAgent?.write).not.toHaveBeenCalled();
198+
await user.click(within(dialog).getByRole("button", { name: "Cancel" }));
199+
await waitFor(() => expect(dialog).not.toBeInTheDocument());
200+
expect(f.session.mainAgent?.write).not.toHaveBeenCalled();
201+
await selectPollen();
202+
await user.click(
203+
await screen.findByRole("button", { name: "Use as bestie" }),
204+
);
205+
await waitFor(() =>
206+
expect(f.session.mainAgent?.write).toHaveBeenCalledWith(pollen),
207+
);
208+
},
209+
);
210+
211+
it("rechecks a remote agent's eligibility when its confirmation is accepted", async () => {
212+
const f = fixture(async () => {}, undefined, "hosted");
213+
f.mount();
214+
const user = await selectPollen();
215+
await screen.findByRole("alertdialog");
216+
f.removeChoice();
217+
await user.click(screen.getByRole("button", { name: "Use as bestie" }));
218+
expect(await screen.findByRole("alert")).toHaveTextContent(
219+
"That agent is no longer available. Choose another.",
220+
);
221+
expect(f.session.mainAgent?.write).not.toHaveBeenCalled();
222+
});
223+
224+
it("keeps a remote choice open for retry after a save fails", async () => {
225+
const gate = deferred();
226+
let attempts = 0;
227+
const f = fixture(
228+
async () => {
229+
if (++attempts === 1) throw new Error("offline");
230+
await gate.promise;
231+
},
232+
undefined,
233+
"hosted",
234+
);
235+
f.mount();
236+
const user = await selectPollen();
237+
await user.click(
238+
await screen.findByRole("button", { name: "Use as bestie" }),
239+
);
240+
const dialog = await screen.findByRole("alertdialog");
241+
expect(await within(dialog).findByRole("alert")).toHaveTextContent(
242+
"Your bestie couldn't be saved to your account. Try again.",
243+
);
244+
await user.click(
245+
within(dialog).getByRole("button", { name: "Use as bestie" }),
246+
);
247+
try {
248+
expect(
249+
within(dialog).getByRole("button", { name: "Cancel" }),
250+
).toBeDisabled();
251+
await user.keyboard("{Escape}");
252+
expect(dialog).toBeInTheDocument();
253+
} finally {
254+
gate.resolve();
255+
}
256+
await waitFor(() => expect(dialog).not.toBeInTheDocument());
257+
expect(f.session.mainAgent?.write).toHaveBeenCalledTimes(2);
258+
});
259+
260+
it("warns after creating a hosted agent without automatically saving it as Bestie", async () => {
261+
const f = fixture(async () => {}, undefined, "hosted");
262+
f.mount();
263+
const user = userEvent.setup();
264+
await user.click(screen.getByRole("button", { name: "Create agent" }));
265+
await user.click(screen.getByRole("button", { name: "Finish creation" }));
266+
await screen.findByRole("alertdialog", {
267+
name: "Use Pollen as your bestie?",
268+
});
269+
expect(f.session.agentChoices.refresh).toHaveBeenCalled();
270+
expect(f.session.mainAgent?.write).not.toHaveBeenCalled();
271+
await user.click(screen.getByRole("button", { name: "Use as bestie" }));
272+
await waitFor(() =>
273+
expect(f.session.mainAgent?.write).toHaveBeenCalledWith(pollen),
274+
);
275+
});
276+
277+
it("retries the handoff after agent creation refresh fails", async () => {
278+
const f = fixture(async () => {});
279+
vi.mocked(f.session.agentChoices.refresh)
280+
.mockRejectedValueOnce(new Error("inventory failed"))
281+
.mockResolvedValue(undefined);
282+
f.mount();
283+
const user = userEvent.setup();
284+
await user.click(screen.getByRole("button", { name: "Create agent" }));
285+
await user.click(screen.getByRole("button", { name: "Finish creation" }));
286+
expect(await screen.findByRole("alert")).toHaveTextContent(
287+
"inventory failed",
288+
);
289+
expect(f.session.mainAgent?.write).not.toHaveBeenCalled();
290+
await user.click(screen.getByRole("button", { name: "Try again" }));
291+
await waitFor(() =>
292+
expect(f.session.mainAgent?.write).toHaveBeenCalledWith(pollen),
293+
);
294+
});

0 commit comments

Comments
 (0)