Skip to content

Commit 5b01707

Browse files
baxenclaude
andcommitted
feat(channels): bring back channel templates on Agents2 teams
A channel template is a name, the Agents2 teams a new channel starts with and a starting Canvas, saved on this device in buzz.channel-templates.v1 like teams are. Settings > Channel templates creates, edits and deletes them. Create channel offers a Template select when any exist. Picking one adds each member of its teams that is the owner's agent in this community, and seeds the Canvas, through the existing channel setup, so the session still owns applying, confirming and retrying it. A team deleted since is skipped. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Bradley Axen <[email protected]>
1 parent caa7312 commit 5b01707

13 files changed

Lines changed: 691 additions & 10 deletions

‎docs/plugin-architecture.md‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -269,9 +269,12 @@ exact registration identity and mounted lifetime revoke callbacks on removal.
269269

270270
The channel template extension point (`ctx.channelTemplates`) was removed with the
271271
v1 Agents system. The host sidebar owns personal groups and the existing + creation
272-
buttons. Create sends only name, privacy, duration and destination group; the
273-
session still retries frozen setup receipts saved by earlier builds, including their
274-
agents and Canvas, without any template or agent catalog.
272+
buttons. Channel templates are now device-local (`buzz.channel-templates.v1`,
273+
`features/channel-templates/local.ts`): a name, Agents2 team ids and a starting
274+
Canvas, managed under Settings → Channel templates. Picking one in Create resolves
275+
its teams to their members that are the owner's agents in this community and sends
276+
them with the Canvas as ordinary channel setup, which the session applies and
277+
retries as before.
275278

276279
Hosted communities (`block.hosted-communities`) is a Block-specific bundled plugin
277280
under Settings → Communities. It manages Block-hosted relays through a Builderlab

‎src/app/App.tsx‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ function ConnectedApp({ services }: { services: AppServices }) {
186186
<ChannelSidebar
187187
relay={services.relay}
188188
navigator={services.navigation}
189+
agents2={services.agents2}
189190
target={route.target}
190191
meEnabled={route.pages.some(
191192
(page) => page.key === "buzz.me/me",

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ test("the app runtime exposes ready bundled pages and removes them on disable",
130130
"block.builderlab",
131131
"block.hosted-communities",
132132
"buzz.channels",
133+
"buzz.channels",
133134
"buzz.emoji",
134135
"buzz.pairing",
135136
],
@@ -191,6 +192,7 @@ test("the app runtime exposes ready bundled pages and removes them on disable",
191192
"block.builderlab",
192193
"block.hosted-communities",
193194
"buzz.channels",
195+
"buzz.channels",
194196
"buzz.emoji",
195197
"buzz.pairing",
196198
],
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// @vitest-environment jsdom
2+
import "@testing-library/jest-dom/vitest";
3+
import { cleanup, render, screen } from "@testing-library/react";
4+
import userEvent from "@testing-library/user-event";
5+
import { afterEach, expect, it } from "vitest";
6+
import type { Agents2 } from "../../features/agents2/service";
7+
import { channelTemplates } from "../../features/channel-templates/local";
8+
import { ChannelTemplateSettings } from "./ChannelTemplateSettings";
9+
10+
afterEach(() => {
11+
cleanup();
12+
localStorage.clear();
13+
});
14+
15+
const snapshot = {
16+
status: "ready",
17+
agents: [],
18+
running: [],
19+
teams: [
20+
{ id: "t1", name: "Core", instructions: "", members: [] },
21+
{ id: "t2", name: "Docs", instructions: "", members: [] },
22+
],
23+
};
24+
const agents2 = {
25+
snapshot: () => snapshot,
26+
subscribe: () => () => {},
27+
} as unknown as Agents2;
28+
29+
it("makes, edits and deletes a template of teams and a Canvas", async () => {
30+
const user = userEvent.setup();
31+
render(<ChannelTemplateSettings agents2={agents2} active={() => true} />);
32+
await user.click(screen.getByRole("button", { name: "New template" }));
33+
await user.type(screen.getByRole("textbox", { name: "Name" }), "Launch");
34+
await user.click(screen.getByRole("checkbox", { name: "Docs" }));
35+
await user.type(
36+
screen.getByRole("textbox", { name: /Starting Canvas/ }),
37+
"# Goal",
38+
);
39+
await user.click(screen.getByRole("button", { name: "Save template" }));
40+
expect(channelTemplates.snapshot()).toMatchObject([
41+
{ name: "Launch", teams: ["t2"], canvas: "# Goal" },
42+
]);
43+
expect(screen.getByText("Docs · Canvas")).toBeVisible();
44+
45+
await user.click(screen.getByRole("button", { name: "Edit Launch" }));
46+
await user.click(screen.getByRole("checkbox", { name: "Core" }));
47+
await user.click(screen.getByRole("button", { name: "Save template" }));
48+
expect(channelTemplates.snapshot()[0]?.teams).toEqual(["t2", "t1"]);
49+
50+
await user.click(screen.getByRole("button", { name: "Edit Launch" }));
51+
await user.click(screen.getByRole("button", { name: "Delete" }));
52+
expect(channelTemplates.snapshot()).toEqual([]);
53+
expect(screen.getByText("No channel templates yet")).toBeVisible();
54+
});
Lines changed: 216 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,216 @@
1+
import { useState } from "react";
2+
import { useTeams } from "../../features/agents2/react";
3+
import type { Agents2, Team } from "../../features/agents2/service";
4+
import {
5+
channelTemplates,
6+
useChannelTemplates,
7+
type ChannelTemplate,
8+
} from "../../features/channel-templates/local";
9+
import { CopyIcon, PlusIcon } from "../../shared/design-system/icons";
10+
import { Button } from "../../shared/design-system/ui/Button";
11+
import { Checkbox } from "../../shared/design-system/ui/Checkbox";
12+
import { Dialog } from "../../shared/design-system/ui/Dialog";
13+
import { EmptyState } from "../../shared/design-system/ui/EmptyState";
14+
import { Field } from "../../shared/design-system/ui/Field";
15+
import { Header } from "../../shared/design-system/ui/Header";
16+
import { Input } from "../../shared/design-system/ui/Input";
17+
import { PreferenceRow } from "../../shared/design-system/ui/PreferenceRow";
18+
import { SettingsGroup } from "../../shared/design-system/ui/SettingsGroup";
19+
import { Textarea } from "../../shared/design-system/ui/Textarea";
20+
import styles from "./ChannelTemplates.module.css";
21+
22+
/** Templates a new channel can start from: its teams and its Canvas. */
23+
export function ChannelTemplateSettings({
24+
agents2,
25+
active,
26+
}: {
27+
agents2?: Agents2 | undefined;
28+
active(): boolean;
29+
}) {
30+
const templates = useChannelTemplates();
31+
const teams = useTeams(agents2);
32+
// A template's id while it is edited, or "new" for one being made.
33+
const [editing, setEditing] = useState<string>();
34+
const template = templates.find((item) => item.id === editing);
35+
const newTemplate = () => {
36+
if (active()) setEditing("new");
37+
};
38+
return (
39+
<section aria-label="Channel templates settings">
40+
<Header title="Channel templates" />
41+
{templates.length ? (
42+
<div className={styles.stack}>
43+
<SettingsGroup>
44+
{templates.map((item) => (
45+
<PreferenceRow
46+
key={item.id}
47+
title={item.name}
48+
subtitle={summary(item, teams)}
49+
trailing={
50+
<Button
51+
aria-label={`Edit ${item.name}`}
52+
onClick={() => {
53+
if (active()) setEditing(item.id);
54+
}}
55+
>
56+
Edit
57+
</Button>
58+
}
59+
/>
60+
))}
61+
</SettingsGroup>
62+
<div className={styles.actions}>
63+
<Button onClick={newTemplate}>
64+
<PlusIcon size={14} aria-hidden="true" /> New template
65+
</Button>
66+
</div>
67+
</div>
68+
) : (
69+
<EmptyState
70+
icon={<CopyIcon />}
71+
title="No channel templates yet"
72+
description="Start new channels with your teams and a Canvas already in place."
73+
action={<Button onClick={newTemplate}>New template</Button>}
74+
/>
75+
)}
76+
{(editing === "new" || template) && (
77+
<TemplateDialog
78+
key={editing}
79+
teams={teams}
80+
{...(template ? { template } : {})}
81+
onClose={() => setEditing(undefined)}
82+
/>
83+
)}
84+
</section>
85+
);
86+
}
87+
88+
function summary(template: ChannelTemplate, teams: readonly Team[]) {
89+
const names = template.teams.flatMap(
90+
(id) => teams.find((team) => team.id === id)?.name ?? [],
91+
);
92+
return (
93+
[names.join(", "), template.canvas.trim() ? "Canvas" : ""]
94+
.filter(Boolean)
95+
.join(" · ") || "Empty"
96+
);
97+
}
98+
99+
function TemplateDialog({
100+
teams,
101+
template,
102+
onClose,
103+
}: {
104+
teams: readonly Team[];
105+
template?: ChannelTemplate;
106+
onClose(): void;
107+
}) {
108+
const [name, setName] = useState(template?.name ?? "");
109+
const [chosen, setChosen] = useState<readonly string[]>(
110+
template?.teams ?? [],
111+
);
112+
const [canvas, setCanvas] = useState(template?.canvas ?? "");
113+
const [error, setError] = useState("");
114+
const act = (work: () => void) => {
115+
setError("");
116+
try {
117+
work();
118+
onClose();
119+
} catch (reason) {
120+
setError(reason instanceof Error ? reason.message : String(reason));
121+
}
122+
};
123+
return (
124+
<Dialog
125+
open
126+
onOpenChange={(open) => {
127+
if (!open) onClose();
128+
}}
129+
title={template ? "Edit template" : "New template"}
130+
closeLabel="Close template"
131+
actions={
132+
<>
133+
{template && (
134+
<Button
135+
variant="destructive"
136+
onClick={() => act(() => channelTemplates.remove(template.id))}
137+
>
138+
Delete
139+
</Button>
140+
)}
141+
<Button
142+
variant="prominent"
143+
type="submit"
144+
form="channel-template-form"
145+
disabled={!name.trim()}
146+
>
147+
Save template
148+
</Button>
149+
</>
150+
}
151+
>
152+
<form
153+
id="channel-template-form"
154+
className={styles.stack}
155+
onSubmit={(event) => {
156+
event.preventDefault();
157+
act(() =>
158+
channelTemplates.save({
159+
...(template ? { id: template.id } : {}),
160+
name,
161+
teams: chosen,
162+
canvas,
163+
}),
164+
);
165+
}}
166+
>
167+
<Field label="Name">
168+
<Input
169+
autoFocus
170+
value={name}
171+
onChange={(event) => setName(event.target.value)}
172+
/>
173+
</Field>
174+
<fieldset className={styles.teams}>
175+
<legend className="text-label-sm">Teams</legend>
176+
{teams.length ? (
177+
teams.map((team) => (
178+
<Checkbox
179+
key={team.id}
180+
label={team.name}
181+
checked={chosen.includes(team.id)}
182+
onCheckedChange={(checked) =>
183+
setChosen((last) =>
184+
checked
185+
? [...last, team.id]
186+
: last.filter((id) => id !== team.id),
187+
)
188+
}
189+
/>
190+
))
191+
) : (
192+
<p className="m-0 text-body-sm text-secondary">
193+
Make teams on the Agents page.
194+
</p>
195+
)}
196+
</fieldset>
197+
<Field
198+
label="Starting Canvas"
199+
description="Markdown, copied into each new channel made from this template."
200+
>
201+
<Textarea
202+
rows={8}
203+
value={canvas}
204+
onChange={(event) => setCanvas(event.target.value)}
205+
placeholder={"# Goal\n\n# Scope\n\n# Success criteria"}
206+
/>
207+
</Field>
208+
{error && (
209+
<p role="alert" className={styles.error}>
210+
{error}
211+
</p>
212+
)}
213+
</form>
214+
</Dialog>
215+
);
216+
}

‎src/bundled/channels/ChannelTemplates.module.css‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,11 @@
3030
.row > :first-child {
3131
flex-shrink: 1;
3232
}
33+
.teams {
34+
display: grid;
35+
gap: var(--space-2);
36+
min-width: 0;
37+
margin: 0;
38+
padding: 0;
39+
border: 0;
40+
}

0 commit comments

Comments
 (0)