Skip to content

Commit 7e655ba

Browse files
kazemek21claude
andcommitted
feat(agents): let agents change Buzz settings with owner permission
Agents get generic settings_list, settings_get and settings_set tools over a catalog each feature defines with its own live setter: appearance mode, interface size, accent, vibe and new-thread placement. Only Buzz's Agents UI can allow it, per agent and device; it is off by default, revoking takes effect at once, and each write rechecks the permission, the run and the owner's Stop after the call's last await. Codex, Pi, Claude Code and Goose each give the turn check settings need; standalone turns are refused. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Kyle Zemek <[email protected]>
1 parent 1da5031 commit 7e655ba

41 files changed

Lines changed: 2182 additions & 14 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎docs/buzz-help.md‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,14 @@ available rather than silently discarding it.
302302
- When a request to an agent running on this device fails, the activity under
303303
the message offers **Retry**, which asks the agent again, and **Dismiss**,
304304
which hides the failure.
305+
- **Change Buzz settings** in an agent's **Agent details** on the Agents page
306+
(not its profile) lets that agent, while it runs on this device, read and
307+
change some Buzz settings here: appearance mode, interface size, accent
308+
color, vibe level and where new threads open. It is off until its owner
309+
turns it on, applies only to agents running on this device, and turning it
310+
off stops the next change at once. Stopping a turn also stops its changes,
311+
and watch or timer turns can't make them. A change shows as not saved when
312+
it is active but could not be saved on this device.
305313

306314
## Optional features and limits
307315

‎src/app/device-settings.test.ts‎

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
// @vitest-environment jsdom
2+
import { afterEach, expect, it, vi } from "vitest";
3+
import { createAppearance } from "../shared/theme/service";
4+
import { deviceSettings } from "./device-settings";
5+
6+
afterEach(() => {
7+
vi.restoreAllMocks();
8+
localStorage.clear();
9+
});
10+
11+
/** Sets `key` to `value` as an agent's settings_set would. */
12+
const set = (
13+
settings: ReturnType<typeof deviceSettings>,
14+
key: string,
15+
value: unknown,
16+
) => settings.apply(settings.admit(key, value), value as string | number);
17+
18+
it("offers appearance and new-thread placement, and nothing else", () => {
19+
const appearance = createAppearance(window);
20+
expect(
21+
deviceSettings(appearance)
22+
.list()
23+
.map(({ key, value, saved }) => ({ key, value, saved })),
24+
).toEqual([
25+
{ key: "appearance.mode", value: "system", saved: true },
26+
{ key: "appearance.interface_size", value: 100, saved: true },
27+
{ key: "appearance.accent", value: "citrus", saved: true },
28+
{ key: "appearance.vibe", value: "low", saved: true },
29+
{ key: "conversations.thread_placement", value: "side", saved: true },
30+
]);
31+
appearance.dispose();
32+
});
33+
34+
it("changes appearance as its own controls do: live, saved and announced", () => {
35+
const appearance = createAppearance(window);
36+
const settings = deviceSettings(appearance);
37+
const listener = vi.fn();
38+
appearance.subscribe(listener);
39+
expect(set(settings, "appearance.mode", "dark")).toMatchObject({
40+
value: "dark",
41+
saved: true,
42+
});
43+
expect(document.documentElement.dataset.colorMode).toBe("dark");
44+
expect(set(settings, "appearance.interface_size", 120).value).toBe(120);
45+
expect(
46+
document.documentElement.style.getPropertyValue("--buzz-text-scale"),
47+
).toBe("1.2");
48+
expect(set(settings, "appearance.accent", "cobalt").value).toBe("cobalt");
49+
expect(set(settings, "appearance.vibe", "high").value).toBe("high");
50+
expect(listener).toHaveBeenCalledTimes(4);
51+
appearance.dispose();
52+
// Another window, or the next launch, reads what was saved.
53+
const next = createAppearance(window);
54+
expect(
55+
deviceSettings(next)
56+
.list()
57+
.slice(0, 4)
58+
.map(({ value }) => value),
59+
).toEqual(["dark", 120, "cobalt", "high"]);
60+
next.dispose();
61+
});
62+
63+
it("refuses an accent's legacy alias rather than mapping it", () => {
64+
const appearance = createAppearance(window);
65+
const settings = deviceSettings(appearance);
66+
for (const value of ["flame", "gray", "Cobalt"])
67+
expect(() => set(settings, "appearance.accent", value)).toThrow(
68+
/appearance.accent takes/,
69+
);
70+
expect(appearance.snapshot().accent).toBe("citrus");
71+
appearance.dispose();
72+
});
73+
74+
it("answers saved false with the owner's reason when storage refuses", () => {
75+
const appearance = createAppearance(window);
76+
const settings = deviceSettings(appearance);
77+
vi.spyOn(Storage.prototype, "setItem").mockImplementation(() => {
78+
throw new Error("QuotaExceededError");
79+
});
80+
expect(set(settings, "appearance.mode", "dark")).toMatchObject({
81+
value: "dark",
82+
saved: false,
83+
problem: expect.stringMatching(/could not be saved/),
84+
});
85+
expect(set(settings, "conversations.thread_placement", "main")).toEqual(
86+
expect.objectContaining({
87+
value: "main",
88+
saved: false,
89+
problem: expect.stringMatching(/could not be saved/),
90+
}),
91+
);
92+
vi.mocked(Storage.prototype.setItem).mockRestore();
93+
expect(set(settings, "conversations.thread_placement", "side").saved).toBe(
94+
true,
95+
);
96+
appearance.dispose();
97+
});
98+
99+
it("changes nothing after the appearance it was made with is disposed", () => {
100+
const appearance = createAppearance(window);
101+
const settings = deviceSettings(appearance);
102+
appearance.dispose();
103+
expect(() => set(settings, "appearance.mode", "dark")).toThrow(
104+
"Buzz is closing",
105+
);
106+
expect(localStorage.length).toBe(0);
107+
});
108+
109+
it("moves new threads, saved and announced to open settings screens", () => {
110+
const appearance = createAppearance(window);
111+
const settings = deviceSettings(appearance);
112+
const changed = vi.fn();
113+
window.addEventListener("buzz-thread-placement-changed", changed);
114+
expect(set(settings, "conversations.thread_placement", "main")).toEqual({
115+
key: "conversations.thread_placement",
116+
description: expect.any(String),
117+
schema: { type: "string", enum: ["side", "main"] },
118+
applies: expect.stringMatching(/New thread tabs only/),
119+
value: "main",
120+
saved: true,
121+
});
122+
expect(changed).toHaveBeenCalledOnce();
123+
expect(localStorage.getItem("buzz-thread-placement.v1")).toBe("main");
124+
window.removeEventListener("buzz-thread-placement-changed", changed);
125+
appearance.dispose();
126+
});

‎src/app/device-settings.ts‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { threadPlacementSetting } from "../features/messages/thread-preferences";
2+
import { createDeviceSettings } from "../shared/device-settings";
3+
import type { Appearance } from "../shared/theme/service";
4+
import { appearanceSettings } from "../shared/theme/settings";
5+
6+
// The settings agents can change when their owner allows it. Each feature owns
7+
// its definitions; add one here to offer it through the settings tools. Keep
8+
// out secrets, sign-in, permissions, protection, spending, models and anything
9+
// destructive or that changes how the owner reaches agents.
10+
export const deviceSettings = (appearance: Appearance) =>
11+
createDeviceSettings([
12+
...appearanceSettings(appearance),
13+
threadPlacementSetting,
14+
]);

‎src/app/services.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import { AccountActionsService } from "../features/account-actions/service";
3232
import { ShortcutsService } from "../features/shortcuts/service";
3333
import { DecisionsService } from "../features/decisions/service";
3434
import { AgentsService } from "../features/agents/service";
35+
import { deviceSettings } from "./device-settings";
3536
import { createShortcutBindings } from "../features/shortcuts/preferences";
3637
import { ConversationService } from "../features/conversation/service";
3738
import { createAppearance } from "../shared/theme/service";
@@ -139,6 +140,8 @@ export function createServices() {
139140
undefined,
140141
localActivity,
141142
decisions,
143+
undefined,
144+
deviceSettings(appearance),
142145
);
143146
ctx.effect(() =>
144147
localAgents.bind({

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

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -718,3 +718,72 @@ it("retains the inline save action outside an agent pane", () => {
718718
"settings",
719719
);
720720
});
721+
722+
it.each([true, false])(
723+
"shows the Change Buzz settings switch only for a host that may change it (%s)",
724+
async (settingsAccess) => {
725+
const agent = {
726+
key: "a".repeat(64),
727+
pubkey: "a".repeat(64),
728+
owner: "f".repeat(64),
729+
name: "Ada",
730+
type: "test/echo",
731+
place: "here",
732+
relay: "wss://current.example",
733+
config: {},
734+
attention: {},
735+
skipped: {},
736+
timers: {},
737+
attentionEnabled: true,
738+
} satisfies Agent;
739+
const type = {
740+
key: agent.type,
741+
pluginId: "test",
742+
revision: "1",
743+
id: "echo",
744+
title: "Echo",
745+
defaults: () => ({ config: {} }),
746+
tabs: [
747+
{
748+
id: "settings",
749+
title: "Settings",
750+
role: "settings",
751+
component: Settings,
752+
},
753+
],
754+
} as RegisteredAgentType;
755+
const agents = {
756+
subscribe: () => () => {},
757+
snapshot: () => ({ agents: [agent] }),
758+
find: () => agent,
759+
allowSettings: vi.fn(),
760+
configHistory: () => undefined,
761+
addedTabs: () => [],
762+
registerTab: () => {},
763+
controlAttention: () => {},
764+
memberships: () => [],
765+
} as unknown as Agents;
766+
render(
767+
<AgentDetails
768+
agents={agents}
769+
agent={agent}
770+
type={type}
771+
types={[type]}
772+
channels={[]}
773+
memories={undefined}
774+
onRemoved={() => {}}
775+
messageAction={() => null}
776+
settingsAccess={settingsAccess}
777+
/>,
778+
);
779+
await userEvent
780+
.setup()
781+
.click(screen.getByRole("tab", { name: "Settings" }));
782+
expect(
783+
screen.getByRole("button", { name: "Copy public key" }),
784+
).toBeVisible();
785+
expect(
786+
screen.queryAllByRole("switch", { name: /Change Buzz settings/ }),
787+
).toHaveLength(settingsAccess ? 1 : 0);
788+
},
789+
);

‎src/bundled/agents/AgentDetails.tsx‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import {
3030
AgentArchiveRetry,
3131
AgentDelete,
3232
AgentRemoveHere,
33+
AgentSettingsAccess,
3334
inSeveral,
3435
} from "../../features/agents/AgentManage";
3536
import {
@@ -89,6 +90,7 @@ export function AgentDetails({
8990
openConversation,
9091
communities,
9192
openSettings,
93+
settingsAccess,
9294
}: {
9395
agents: Agents;
9496
agent: Agent;
@@ -107,6 +109,9 @@ export function AgentDetails({
107109
openConversation?: AgentViewProps["openConversation"];
108110
communities?: CommunityReader | undefined;
109111
openSettings?: ((section: string) => void) | undefined;
112+
/** Shows the owner's Change Buzz settings switch, which only Buzz's Agents
113+
* page may change. */
114+
settingsAccess?: boolean;
110115
}) {
111116
const ProfileActions = type?.ProfileActions ?? Fragment;
112117
const { pack, src: backdrop } = useAgentPortraitSource(agent, agent.relay);
@@ -525,6 +530,9 @@ export function AgentDetails({
525530
/>
526531
}
527532
/>
533+
{settingsAccess && (
534+
<AgentSettingsAccess agents={agents} agent={agent} />
535+
)}
528536
<AgentArchiveRetry agents={agents} agent={agent} />
529537
{inSeveral(agents, agent) && (
530538
<PreferenceRow

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,7 @@ function setup(
315315
}),
316316
),
317317
save: vi.fn(async () => {}),
318+
allowSettings: vi.fn(async () => {}),
318319
previewRetype: vi.fn(
319320
() =>
320321
({
@@ -3230,6 +3231,10 @@ it("keeps the copy and delete rows in Settings, below the agent identity", async
32303231
expect(
32313232
within(identity).queryByRole("button", { name: "Delete agent" }),
32323233
).not.toBeInTheDocument();
3234+
// Buzz's Agents page is where the owner may let it change Buzz settings.
3235+
expect(
3236+
screen.getByRole("switch", { name: /Change Buzz settings/ }),
3237+
).toBeVisible();
32333238
await user.click(screen.getByRole("button", { name: "Copy public key" }));
32343239
expect(copy).toHaveBeenCalledWith(expect.stringMatching(/^npub1/));
32353240
expect(

‎src/bundled/agents/AgentsPage.tsx‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -522,6 +522,7 @@ export function AgentsPage({
522522
}
523523
onRemoved={() => browse()}
524524
openSettings={openSettings}
525+
settingsAccess
525526
openConversation={conversationOpener(
526527
navigator,
527528
connection.viewer && connection.origin

‎src/bundled/claude-code/runtime.test.ts‎

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3155,3 +3155,80 @@ it("drops a mention stopped while queued behind an Attention refresh", async ()
31553155
f.runtime.dispose();
31563156
}
31573157
});
3158+
3159+
it("changes Buzz settings only in a delivered turn the owner hasn't stopped", async () => {
3160+
const { deliver, claudes, interruptible, agent } = setup([], { hold: true });
3161+
const set = vi.fn((_key: unknown, value: unknown, check?: () => void) => {
3162+
check?.();
3163+
return { key: "example.mood", value };
3164+
});
3165+
Object.assign(agent, { settings: { list: () => [], get: vi.fn(), set } });
3166+
await deliver({ type: "mention", event: message("1", "@Claude hi") });
3167+
await flush(10);
3168+
const claude = claudes().find((process) => process.prompts.length);
3169+
const change = async (id: number) =>
3170+
(await mcp(claude, id, "tools/call", {
3171+
name: "settings_set",
3172+
arguments: { key: "example.mood", value: "busy" },
3173+
})) as { isError?: boolean; content: { text: string }[] } | undefined;
3174+
expect((await change(1))?.isError).toBeUndefined();
3175+
await interruptible.mock.calls[0]?.[0]();
3176+
const stopped = await change(2);
3177+
expect(stopped?.isError).toBe(true);
3178+
expect(stopped?.content[0]?.text).toMatch(/stopped or has ended/);
3179+
claude?.finish();
3180+
await flush(10);
3181+
});
3182+
3183+
it("refuses Buzz settings in a watch's standalone turn", async () => {
3184+
const { deliver, claudes, agent } = setup([], { hold: true });
3185+
const set = vi.fn((_key: unknown, value: unknown, check?: () => void) => {
3186+
check?.();
3187+
return { key: "example.mood", value };
3188+
});
3189+
Object.assign(agent, { settings: { list: () => [], get: vi.fn(), set } });
3190+
await deliver(timer("daily", "ops"));
3191+
await flush(10);
3192+
const claude = claudes().find((process) => process.prompts.length);
3193+
const refused = (await mcp(claude, 1, "tools/call", {
3194+
name: "settings_set",
3195+
arguments: { key: "example.mood", value: "busy" },
3196+
})) as { isError?: boolean; content: { text: string }[] } | undefined;
3197+
expect(refused?.isError).toBe(true);
3198+
expect(refused?.content[0]?.text).toMatch(/stopped or has ended/);
3199+
claude?.finish();
3200+
await flush(10);
3201+
});
3202+
3203+
it("refuses Buzz settings to a reply steered into a turn the owner stopped", async () => {
3204+
const { deliver, claudes, interruptible, agent } = setup([], { hold: true });
3205+
const set = vi.fn((_key: unknown, value: unknown, check?: () => void) => {
3206+
check?.();
3207+
return { key: "example.mood", value };
3208+
});
3209+
Object.assign(agent, { settings: { list: () => [], get: vi.fn(), set } });
3210+
await deliver({ type: "mention", event: message("1", "@Claude hi") });
3211+
await flush(10);
3212+
await deliver({
3213+
type: "mention",
3214+
event: message("2", "@Claude also", {
3215+
tags: [
3216+
["h", channel],
3217+
["e", "1".repeat(64), "", "reply"],
3218+
],
3219+
}),
3220+
});
3221+
await flush(10);
3222+
const working = claudes().filter((process) => process.prompts.length);
3223+
expect(working).toHaveLength(1);
3224+
expect(interruptible).toHaveBeenCalledTimes(2);
3225+
await interruptible.mock.calls[0]?.[0]();
3226+
const refused = (await mcp(working[0], 1, "tools/call", {
3227+
name: "settings_set",
3228+
arguments: { key: "example.mood", value: "busy" },
3229+
})) as { isError?: boolean; content: { text: string }[] } | undefined;
3230+
expect(refused?.isError).toBe(true);
3231+
expect(refused?.content[0]?.text).toMatch(/stopped or has ended/);
3232+
working[0]?.finish();
3233+
await flush(10);
3234+
});

0 commit comments

Comments
 (0)