From a3655290764c91bf6f66e8cbf1c63174a74c53e6 Mon Sep 17 00:00:00 2001 From: Taylor Ho Date: Mon, 16 Nov 2026 22:10:30 -0800 Subject: [PATCH 01/10] feat(solo): let chat owners change agent access Reuse member role menus and confirmed administration for existing Solo agents. Verify signed agent profiles before signing and publication; retain the human-role, addition and ownership-transfer restrictions. Co-authored-by: Carl Signed-off-by: Taylor Ho --- docs/buzz-help.md | 3 + docs/solo/sharing.md | 6 +- .../channels/MemberAdministration.test.tsx | 59 ++++++- src/bundled/channels/MemberAdministration.tsx | 3 +- .../administration-protocol.ts | 16 +- .../channel-members/administration.test.ts | 82 ++++++++- .../channel-members/administration.ts | 14 ++ tests/browser/fixture.mjs | 8 +- tests/browser/solo-agent-roles.spec.mjs | 155 ++++++++++++++++++ 9 files changed, 333 insertions(+), 13 deletions(-) create mode 100644 tests/browser/solo-agent-roles.spec.mjs diff --git a/docs/buzz-help.md b/docs/buzz-help.md index e87e10650e..bb87edaab0 100644 --- a/docs/buzz-help.md +++ b/docs/buzz-help.md @@ -472,6 +472,9 @@ and are asked to sign in again in Buzz. the chat; anyone else outside the chat is only named: not added and not notified, and the picker row says so. People already in the chat are notified as usual. The toolbar's agent menu lists agents only. + A Solo chat owner can open an existing agent’s menu in **Share access**, + choose **Admin**, **Participating** or **Viewing only**, and confirm. These + role choices apply only to agents already in the chat. New chats start **Ongoing** unless **Chat settings** chooses **Temporary**, which archives the chat after a set time without activity. To start every new chat temporary, open the community's **Settings → Local settings** and choose diff --git a/docs/solo/sharing.md b/docs/solo/sharing.md index d40d97ce75..5c53ee1308 100644 --- a/docs/solo/sharing.md +++ b/docs/solo/sharing.md @@ -45,8 +45,10 @@ Where the viewer cannot add agents, a note says to mention an agent in the chat instead. Current access uses the channel groups (**People**, **Agents**) with Owner and Admin tags, and each row has the channel members' actions menu, so the chat owner -can remove someone. The verified roster shows loading or failure, never treating a -failed read as an empty audience. +can remove someone. The owner can also change an existing agent to **Admin**, +**Participating** or **Viewing only** from that menu, with confirmation. These +role choices apply only to agents already in the chat. The verified roster shows +loading or failure, never treating a failed read as an empty audience. Invitations use the same groups and controls as channels: **Your agents** first, then **People**, **Other agents** and **Your other agents**, omitting empty groups. diff --git a/src/bundled/channels/MemberAdministration.test.tsx b/src/bundled/channels/MemberAdministration.test.tsx index 3981fea461..2560343592 100644 --- a/src/bundled/channels/MemberAdministration.test.tsx +++ b/src/bundled/channels/MemberAdministration.test.tsx @@ -63,7 +63,7 @@ async function setup( messageNavigation = true, initialReads?: { names?: Promise; roster?: Promise }, ownership?: "own" | "other" | "invalid", - visibility: "private" | "public" = "private", + visibility: "private" | "public" | "solo" = "private", targetPicture?: string, targetProfiled = true, ) { @@ -116,7 +116,13 @@ async function setup( kind: 39000, created_at: tick, content: "", - tags: [["d", id], ["t", "stream"], [visibility], ["name", "Design"]], + tags: [ + ["d", id], + ["t", "stream"], + [visibility === "solo" ? "private" : visibility], + ...(visibility === "solo" ? [["t", "buzz.solo"]] : []), + ["name", "Design"], + ], }), signed(relay, { kind: 39001, @@ -773,6 +779,55 @@ it("keeps resolved rows and focus while refreshing, and reopens warm without a s } }); +it.each([ + ["owner", true, true], + ["owner", false, false], + ["admin", true, false], +] as const)( + "Solo %s sees agent=%s role controls only when permitted", + async (actor, agent, allowed) => { + const t = await setup( + actor, + "admin", + true, + undefined, + agent, + undefined, + false, + true, + undefined, + undefined, + "solo", + ); + await t.user.click( + screen.getByRole("button", { name: /^Actions for Morgan$/ }), + ); + await screen.findByRole("menuitem", { name: "View profile" }); + expect(screen.queryAllByRole("menuitemradio")).toHaveLength( + allowed ? 3 : 0, + ); + expect( + screen.queryByRole("menuitem", { name: "Transfer ownership" }), + ).not.toBeInTheDocument(); + if (!allowed) return; + await t.user.click( + screen.getByRole("menuitemradio", { name: "Viewing only" }), + ); + const dialog = await screen.findByRole("dialog", { + name: "Change access to Viewing only?", + }); + expect(t.publish).not.toHaveBeenCalled(); + await t.user.click( + within(dialog).getByRole("button", { name: "Set to viewing only" }), + ); + await vi.waitFor(() => + expect( + t.session.memberAdministration.snapshot(id).operation?.status, + ).toBe("confirmed"), + ); + expect(t.publish).toHaveBeenCalledOnce(); + }, +); it("presents verified roles, protects owners/self, and confirms a separate deliberate role intent", async () => { const t = await setup(); await expectProfileOnly(t.user, "Carl"); diff --git a/src/bundled/channels/MemberAdministration.tsx b/src/bundled/channels/MemberAdministration.tsx index 29f68170b8..bdbc32c2c5 100644 --- a/src/bundled/channels/MemberAdministration.tsx +++ b/src/bundled/channels/MemberAdministration.tsx @@ -317,7 +317,8 @@ export function MemberRow({ const permitted = !invitationAction && capability.available && state.status === "ready"; const canEdit = - permitted && canManageMember(state.authority, session.viewer ?? "", pubkey); + permitted && + canManageMember(state.authority, session.viewer ?? "", pubkey, agent); const canTransfer = permitted && canTransferOwnership(state.authority, session.viewer ?? "", pubkey, agent); diff --git a/src/features/channel-members/administration-protocol.ts b/src/features/channel-members/administration-protocol.ts index 98a173bfbd..e894b28c22 100644 --- a/src/features/channel-members/administration-protocol.ts +++ b/src/features/channel-members/administration-protocol.ts @@ -22,6 +22,8 @@ export type MemberChange = Readonly<{ export type MemberAuthority = Readonly<{ roles: Readonly>; canManage: boolean; + /** Solo owners may edit existing agents, without enabling other role changes. */ + canManageAgents: boolean; canRemove: boolean; canRemoveOwnedAgent: boolean; /** A NIP-CL system channel, where administration may also add members. */ @@ -95,11 +97,12 @@ export function memberAuthority( "Member roles are inconsistent. Refresh members and roles.", ); const activeChannel = type !== "dm" && archived !== "true"; - // In Solo chats only owners and admins remove people; nobody changes roles. + // Solo role edits are limited to the owner's existing agent participants. const solo = !!soloLabels(channelIdentity(metadata).labels); return Object.freeze({ roles: Object.freeze(roles), canManage: activeChannel && !solo && elevated.has(viewer), + canManageAgents: activeChannel && solo && elevated.get(viewer) === "owner", canRemove: activeChannel && elevated.has(viewer), canRemoveOwnedAgent: activeChannel && !solo && !!roles[viewer] && roles[viewer] !== "unknown", @@ -111,10 +114,11 @@ export function canManageMember( state: MemberAuthority, viewer: string, key: string, + agent = false, ) { const role = state.roles[key]; return ( - state.canManage && + (state.canManage || (state.canManageAgents && agent)) && key !== viewer && !!role && role !== "owner" && @@ -163,8 +167,8 @@ export function authorizeMemberChange( viewer: string, change: MemberChange, owner?: string, - /** Whether `change.pubkey` is an agent; unknown counts as one. */ - agent = true, + /** Verified target identity; unknown cannot grant access or receive ownership. */ + agent?: boolean, ) { if (change.expectedRole === "none") { // This sentinel is reserved for the system-channel setup path. @@ -190,8 +194,8 @@ export function authorizeMemberChange( : change.role === "remove" ? canRemoveMember(state, viewer, change.pubkey, owner) : change.role === "owner" - ? canTransferOwnership(state, viewer, change.pubkey, agent) - : canManageMember(state, viewer, change.pubkey) && + ? canTransferOwnership(state, viewer, change.pubkey, agent !== false) + : canManageMember(state, viewer, change.pubkey, agent === true) && isEditableMemberRole(change.role)) || (change.expectedRole !== "absent" && state.roles[change.pubkey] !== change.expectedRole) || diff --git a/src/features/channel-members/administration.test.ts b/src/features/channel-members/administration.test.ts index 201df030d8..2e385767e8 100644 --- a/src/features/channel-members/administration.test.ts +++ b/src/features/channel-members/administration.test.ts @@ -441,7 +441,7 @@ it("lets a Solo chat owner remove a participant", async () => { ], }); }); -it("never lets a Solo chat owner change roles", async () => { +it("never lets a Solo chat owner change a person's role", async () => { const h = soloHarness(); await h.owner.capability.run(id, change); expect(h.sign).not.toHaveBeenCalled(); @@ -552,6 +552,7 @@ it.each(["ack", "lost", "read"])( authority: { roles: {}, canManage: false, + canManageAgents: false, canRemove: false, canRemoveOwnedAgent: false, system: false, @@ -593,6 +594,7 @@ it.each(["access", "invalid ID"])( authority: { roles: {}, canManage: false, + canManageAgents: false, canRemove: false, canRemoveOwnedAgent: false, system: false, @@ -620,6 +622,7 @@ it.each(["clear", "dispose"] as const)( authority: { roles: {}, canManage: false, + canManageAgents: false, canRemove: false, canRemoveOwnedAgent: false, system: false, @@ -808,6 +811,7 @@ it.each(["cache", "access"] as const)( authority: { roles: {}, canManage: false, + canManageAgents: false, canRemove: false, canRemoveOwnedAgent: false, system: false, @@ -823,6 +827,7 @@ it.each(["cache", "access"] as const)( expect(admin.snapshot(id).authority).toEqual({ roles: {}, canManage: false, + canManageAgents: false, canRemove: false, canRemoveOwnedAgent: false, system: false, @@ -1175,6 +1180,79 @@ function transferHarness( h.setProfiles(profiles); return h; } +function soloAgent(actor = "owner", role = "bot", profiles = [agentProfile()]) { + const h = transferHarness(actor, role, profiles); + h.setEvents([ + h.record(39000, [ + ["d", id], + ["t", "stream"], + ["t", SOLO_LABEL], + ]), + ...h.events().slice(1), + ]); + return h; +} +it("lets the chat owner edit another owner's agent without granting identity-less authority", async () => { + const h = soloAgent("owner", "bot", [agentProfile(relayKey)]); + const intent = { ...change, expectedRole: "bot" } as const; + const state = memberAuthority(h.events(), id, viewer, author); + expect(() => authorizeMemberChange(state, viewer, intent)).toThrow(); + await h.owner.capability.run(id, intent); + expect(h.publish).toHaveBeenCalledOnce(); +}); +it.each([ + ["bot", "admin"], + ["admin", "member"], + ["admin", "guest"], +] as const)( + "lets a Solo owner change an agent from %s to %s", + async (before, role) => { + const h = soloAgent("owner", before); + await h.owner.capability.run(id, { ...change, expectedRole: before, role }); + expect(h.publish).toHaveBeenCalledOnce(); + expect(h.owner.capability.snapshot(id).operation?.status).toBe("confirmed"); + }, +); +it.each(["admin", "member", "guest"])( + "denies a Solo %s an agent role edit", + async (actor) => { + const h = soloAgent(actor); + await h.owner.capability.run(id, { ...change, expectedRole: "bot" }); + expect(h.sign).not.toHaveBeenCalled(); + }, +); +it.each(["person", "missing", "transfer", "addition"])( + "keeps Solo %s restrictions", + async (failure) => { + const h = soloAgent( + "owner", + "member", + failure === "person" + ? [personProfile()] + : failure === "missing" + ? [] + : [agentProfile()], + ); + await h.owner.capability.run(id, { + ...change, + ...(failure === "transfer" ? { role: "owner" } : {}), + ...(failure === "addition" + ? { pubkey: author, expectedRole: "absent" } + : {}), + }); + expect(h.sign).not.toHaveBeenCalled(); + }, +); +it("rechecks the Solo target profile after signing", async () => { + const h = soloAgent(); + h.sign.mockImplementationOnce(async (template) => { + h.setProfiles([personProfile()]); + return finalizeEvent(structuredClone(template), key); + }); + await h.owner.capability.run(id, { ...change, expectedRole: "bot" }); + expect(h.sign).toHaveBeenCalledOnce(); + expect(h.publish).not.toHaveBeenCalled(); +}); it("transfers ownership in one event that steps the viewer down to admin", async () => { const h = transferHarness(); await h.owner.capability.run(id, transfer); @@ -1202,6 +1280,7 @@ it("never offers a transfer to a co-owner", () => { const state = { roles: { [viewer]: "owner" as const, [target]: "owner" as const }, canManage: true, + canManageAgents: false, canRemove: true, canRemoveOwnedAgent: false, system: false, @@ -1231,6 +1310,7 @@ it("authorizes a system-channel add only for a non-member other than the viewer const state = { roles: { [viewer]: "owner" as const, [author]: "member" as const }, canManage: true, + canManageAgents: false, canRemove: true, canRemoveOwnedAgent: false, system: true, diff --git a/src/features/channel-members/administration.ts b/src/features/channel-members/administration.ts index b5c9524bb6..5d74fd8a6b 100644 --- a/src/features/channel-members/administration.ts +++ b/src/features/channel-members/administration.ts @@ -10,6 +10,7 @@ import { lifecycleChannelId } from "../relay/channel-lifecycle-protocol"; import { authorizeMemberChange, canRemoveMember, + canManageMember, memberAdministrationTemplate, memberAuthority, memberChangeConfirmed, @@ -34,6 +35,7 @@ const empty: MemberAdministrationState = Object.freeze({ authority: Object.freeze({ roles: Object.freeze({}), canManage: false, + canManageAgents: false, canRemove: false, canRemoveOwnedAgent: false, system: false, @@ -242,6 +244,18 @@ export function createMemberAdministration({ !event || !!foldProfiles([event]).get(change.pubkey)?.isAgent; if (agent) throw new Error(transferRefusal); } + if ( + authority.canManageAgents && + change.role !== "remove" && + change.role !== "owner" && + canManageMember(authority, viewer, change.pubkey, true) + ) { + // A fresh signed profile must confirm the Solo-only exception + // on both preflights; roster roles and display hints aren't proof. + const event = await profile(); + agent = + !!event && !!foldProfiles([event]).get(change.pubkey)?.isAgent; + } authorizeMemberChange(authority, viewer, change, owner, agent); }; await authorize(); diff --git a/tests/browser/fixture.mjs b/tests/browser/fixture.mjs index ff2aae97e1..58e8361e22 100644 --- a/tests/browser/fixture.mjs +++ b/tests/browser/fixture.mjs @@ -67,6 +67,7 @@ export const test = base.extend({ sortingSidebar: [false, { option: true }], initialSidebarSort: [{}, { option: true }], channelLifecycle: [false, { option: true }], + memberRoleChanges: [false, { option: true }], leaveRosterBeforeAck: [false, { option: true }], guestPermalinks: [false, { option: true }], lifecycleRole: ["owner", { option: true }], @@ -161,6 +162,7 @@ export const test = base.extend({ sortingSidebar, initialSidebarSort, channelLifecycle, + memberRoleChanges, leaveRosterBeforeAck, guestPermalinks, lifecycleRole, @@ -2171,13 +2173,17 @@ export const test = base.extend({ // The production broker advertises read-state writes for every session, // not only tests opting into complete snapshot reads. acceptPublication: acceptReadPublication, - ...(actionProfile || channelLifecycle + ...(actionProfile || channelLifecycle || memberRoleChanges ? { latencyMs: 40, holdOlder: false, acceptPublication: (community, event) => { expect(verifyEvent(event)).toBe(true); expect(event.pubkey).toBe(viewer); + if (memberRoleChanges && event.kind === 9000) { + report.publications.push({ community, event }); + return; + } if ( channelLifecycle && [9002, 9008, 9021, 9022, 41012].includes(event.kind) diff --git a/tests/browser/solo-agent-roles.spec.mjs b/tests/browser/solo-agent-roles.spec.mjs new file mode 100644 index 0000000000..ceb0f722c7 --- /dev/null +++ b/tests/browser/solo-agent-roles.spec.mjs @@ -0,0 +1,155 @@ +import { test, expect } from "./fixture.mjs"; +import { openPage } from "./navigation.mjs"; +import { generateSecretKey } from "nostr-tools"; +import { animationsSettled } from "./animations.mjs"; + +const chat = "33333333-3333-4333-8333-333333333333"; +test.use({ + productionBroker: true, + pluginFixtures: true, + channelLifecycle: true, + memberRoleChanges: true, + channelIds: ["alpha", chat], + channelNames: { alpha: "Project updates", [chat]: "Design review" }, + soloChannels: [chat], + ownSoloChannels: [chat], + historyCounts: { alpha: 0, [chat]: 0 }, + viewport: { width: 1100, height: 900 }, +}); + +async function capture(page, info, name) { + const dialog = page.getByRole("dialog"); + await animationsSettled(dialog, { subtree: true }); + const menu = page.getByRole("menu"); + if (await menu.count()) await animationsSettled(menu, { subtree: true }); + await dialog.screenshot({ path: info.outputPath(name) }); +} + +// Browser-only: production app routing, portalled menu hit-testing, keyboard +// selection and nested confirmation focus through the real broker signer/write. +// Only upstream signed membership policy is modeled; role matrices live in Vitest. +test("the Solo owner changes an existing agent's access from its menu", async ({ + page, + app, +}, info) => { + const agent = app.serveProfile(generateSecretKey(), { + name: "Review assistant", + is_agent: true, + }); + app.serveMembers(chat, [agent.pubkey]); + const grants = () => + app.report.publications.filter(({ event }) => event.kind === 9000); + await page.route("**/api/relay/primary/query", async (route) => { + const response = await route.fetch(); + const events = await response.json(); + const role = grants().length ? "admin" : "bot"; + await route.fulfill({ + response, + json: events.map((event) => { + if ( + ![39001, 39002].includes(event.kind) || + !event.tags.some(([tag, value]) => tag === "d" && value === chat) + ) + return event; + const tags = event.tags.filter( + ([tag, key]) => tag !== "p" || key !== agent.pubkey, + ); + if (event.kind === 39002) tags.push(["p", agent.pubkey, "", role]); + else if (role === "admin") tags.push(["p", agent.pubkey, "admin"]); + return app.signRelay({ + ...event, + tags, + created_at: event.created_at + 100 + grants().length, + }); + }), + }); + }); + await page.addInitScript(() => { + localStorage.setItem("buzz-appearance.v1", "dark"); + localStorage.setItem("buzz-accent.v1", "cobalt"); + }); + await page.goto(app.origin); + await openPage(page, "Messages"); + await page.evaluate( + ({ chat, viewer }) => + window.fixtureNavigation.open({ + version: 1, + kind: "conversation", + channelId: chat, + scope: { viewer, communityOrigin: "https://primary.example" }, + }), + { chat, viewer: app.viewer }, + ); + await page.getByRole("button", { name: /^Share access to / }).click(); + const actions = page.getByRole("button", { + name: "Actions for Review assistant", + exact: true, + }); + await actions.click(); + const menu = page.getByRole("menu"); + await expect(menu).toBeVisible(); + await capture(page, info, "agent-access-menu.png"); + await expect( + menu.getByRole("menuitemradio", { name: "Participating", exact: true }), + ).toHaveAttribute("aria-checked", "true"); + await expect(menu.getByRole("menuitemradio")).toHaveCount(3); + await expect( + menu.getByRole("menuitem", { name: "Transfer ownership" }), + ).toHaveCount(0); + await page.keyboard.press("Escape"); + await expect(actions).toBeFocused(); + await actions.press("Enter"); + const admin = page.getByRole("menuitemradio", { name: "Admin", exact: true }); + await admin.focus(); + await page.keyboard.press("Enter"); + const confirm = page.getByRole("dialog", { name: "Change access to Admin?" }); + const save = confirm.getByRole("button", { + name: "Set as admin", + exact: true, + }); + await expect(save).toBeFocused(); + expect(grants()).toHaveLength(0); + await capture(page, info, "agent-access-confirmation.png"); + await confirm.getByRole("button", { name: "Cancel", exact: true }).click(); + await expect(actions).toBeFocused(); + expect(grants()).toHaveLength(0); + await actions.click(); + await page.getByRole("menuitemradio", { name: "Admin", exact: true }).click(); + await save.click(); + await expect( + page.getByRole("dialog", { name: "Share access", exact: true }), + ).toBeVisible(); + await expect.poll(() => grants().length).toBe(1); + expect(grants()[0].event.tags).toEqual([ + ["h", chat], + ["p", agent.pubkey], + ["role", "admin"], + ]); + await actions.click(); + await expect( + page.getByRole("menuitemradio", { name: "Admin", exact: true }), + ).toHaveAttribute("aria-checked", "true"); + await page.keyboard.press("Escape"); + for (const theme of ["light", "dark"]) { + for (const width of [1100, 390]) { + await page.setViewportSize({ width, height: 900 }); + await page.evaluate((theme) => { + document.documentElement.dataset.colorMode = theme; + document.documentElement.style.fontSize = "20px"; + }, theme); + await expect(page.locator("html")).toHaveAttribute( + "data-color-mode", + theme, + ); + await actions.click(); + for (const label of ["Admin", "Participating", "Viewing only"]) { + await expect( + page.getByRole("menuitemradio", { name: label, exact: true }), + ).toBeInViewport({ ratio: 1 }); + } + await page.keyboard.press("Escape"); + await expect(actions).toBeFocused(); + } + } + expect(app.report.unexpected).toEqual([]); +}); From 4704c2795088ef420b61340c833e8df0deba45a4 Mon Sep 17 00:00:00 2001 From: Taylor Ho Date: Wed, 18 Nov 2026 10:06:36 -0800 Subject: [PATCH 02/10] fix(solo): make existing member role changes conditional Use a dedicated relay command carrying the current role. Allow owners to lower access for existing participants and verify agent ownership for promotions. Keep the menu, confirmation, and broker contract aligned. Co-authored-by: Carl Signed-off-by: Taylor Ho --- src-tauri/src/relay/channel_writes.rs | 30 +++++-- .../channels/MemberAdministration.test.tsx | 33 +++++++- src/bundled/channels/MemberAdministration.tsx | 43 ++++++---- .../administration-contract.json | 55 +++++++++++++ .../administration-protocol.ts | 79 ++++++++++++------ .../channel-members/administration.test.ts | 82 ++++++++++++++----- .../channel-members/administration.ts | 57 +++++++++---- tests/browser/fixture.mjs | 5 +- tests/browser/solo-agent-roles.spec.mjs | 22 +++-- 9 files changed, 306 insertions(+), 100 deletions(-) diff --git a/src-tauri/src/relay/channel_writes.rs b/src-tauri/src/relay/channel_writes.rs index 77ddd5c1bd..56460f791c 100644 --- a/src-tauri/src/relay/channel_writes.rs +++ b/src-tauri/src/relay/channel_writes.rs @@ -127,15 +127,27 @@ fn archive(event: &EventTemplate) -> bool { .all(|b| b.is_ascii_hexdigit() && !b.is_ascii_uppercase()) } fn member_administration(event: &EventTemplate) -> bool { - matches!(event.kind, 9000 | 9001) - && event.content.is_empty() - && event.created_at <= 9_007_199_254_740_991 - && event.tags.len() == if event.kind == 9000 { 3 } else { 2 } - && tag(event, 0, "h").is_some_and(uuid) - && (ownership_transfer(event).is_some() - || (tag(event, 1, "p").is_some_and(super::hex_key) - && (event.kind == 9001 - || matches!(tag(event, 2, "role"), Some("admin" | "member" | "guest"))))) + if !event.content.is_empty() + || event.created_at > 9_007_199_254_740_991 + || !tag(event, 0, "h").is_some_and(uuid) + { + return false; + } + let target = tag(event, 1, "p").is_some_and(super::hex_key); + let role = matches!(tag(event, 2, "role"), Some("admin" | "member" | "guest")); + match (event.kind, event.tags.len()) { + (9000, 3) => ownership_transfer(event).is_some() || (target && role), + (9001, 2) => target, + (9050, 4) => { + target + && role + && matches!( + tag(event, 3, "expected_role"), + Some("admin" | "member" | "guest" | "bot") + ) + } + _ => false, + } } /// The stepping-down owner of `[h, ["p", heir, "owner"], ["p", owner, "admin"]]`. fn ownership_transfer(event: &EventTemplate) -> Option<&str> { diff --git a/src/bundled/channels/MemberAdministration.test.tsx b/src/bundled/channels/MemberAdministration.test.tsx index 2560343592..d6a5099795 100644 --- a/src/bundled/channels/MemberAdministration.test.tsx +++ b/src/bundled/channels/MemberAdministration.test.tsx @@ -781,10 +781,10 @@ it("keeps resolved rows and focus while refreshing, and reopens warm without a s it.each([ ["owner", true, true], - ["owner", false, false], + ["owner", false, true], ["admin", true, false], ] as const)( - "Solo %s sees agent=%s role controls only when permitted", + "Solo %s sees downgrade controls for a current Admin (agent=%s)", async (actor, agent, allowed) => { const t = await setup( actor, @@ -826,8 +826,37 @@ it.each([ ).toBe("confirmed"), ); expect(t.publish).toHaveBeenCalledOnce(); + expect(t.publish.mock.calls[0]?.[0]).toMatchObject({ + kind: 9050, + tags: expect.arrayContaining([["expected_role", "admin"]]), + }); }, ); +it("offers only a downgrade for a Solo participant with an unattested agent profile", async () => { + const t = await setup( + "owner", + "member", + true, + undefined, + true, + undefined, + false, + true, + undefined, + undefined, + "solo", + ); + await t.user.click( + screen.getByRole("button", { name: /^Actions for Morgan$/ }), + ); + await screen.findByRole("menuitemradio", { name: "Viewing only" }); + expect( + screen.getByRole("menuitemradio", { name: "Participating" }), + ).toHaveAttribute("aria-checked", "true"); + expect( + screen.queryByRole("menuitemradio", { name: "Admin" }), + ).not.toBeInTheDocument(); +}); it("presents verified roles, protects owners/self, and confirms a separate deliberate role intent", async () => { const t = await setup(); await expectProfileOnly(t.user, "Carl"); diff --git a/src/bundled/channels/MemberAdministration.tsx b/src/bundled/channels/MemberAdministration.tsx index bdbc32c2c5..d02db36651 100644 --- a/src/bundled/channels/MemberAdministration.tsx +++ b/src/bundled/channels/MemberAdministration.tsx @@ -14,7 +14,7 @@ import { } from "react"; import type { RelaySession } from "../../features/relay/session"; import { - canManageMember, + canSetMemberRole, canRemoveMember, canTransferOwnership, editableMemberRoles, @@ -316,9 +316,21 @@ export function MemberRow({ const role = state.authority.roles[pubkey] ?? "unknown"; const permitted = !invitationAction && capability.available && state.status === "ready"; - const canEdit = - permitted && - canManageMember(state.authority, session.viewer ?? "", pubkey, agent); + const currentAccess = role === "bot" ? "member" : role; + const roleChanges = permitted + ? editableMemberRoles.filter( + (next) => + next !== currentAccess && + canSetMemberRole( + state.authority, + session.viewer ?? "", + pubkey, + next, + verifiedOwner, + ), + ) + : []; + const canEdit = roleChanges.length > 0; const canTransfer = permitted && canTransferOwnership(state.authority, session.viewer ?? "", pubkey, agent); @@ -372,23 +384,26 @@ export function MemberRow({ {canEdit && ( { - const target = editableMemberRoles.find( - (value) => value === next, - ); - if (target && target !== role) { + const target = roleChanges.find((value) => value === next); + if (target) { // The shared popup outlives the choice; the confirmation takes over. menus.close(); choose(target); } }} > - {editableMemberRoles.map((next) => ( - - {memberAccessLabel(next)} - - ))} + {editableMemberRoles + .filter( + (next) => + next === currentAccess || roleChanges.includes(next), + ) + .map((next) => ( + + {memberAccessLabel(next)} + + ))} )} {canEdit && } diff --git a/src/features/channel-members/administration-contract.json b/src/features/channel-members/administration-contract.json index cc035c0b78..73ad0e5951 100644 --- a/src/features/channel-members/administration-contract.json +++ b/src/features/channel-members/administration-contract.json @@ -1,5 +1,22 @@ { "accepted": [ + { + "name": "conditional Solo role change", + "event": { + "kind": 9050, + "created_at": 1700000010, + "content": "", + "tags": [ + ["h", "11111111-1111-4111-8111-111111111111"], + [ + "p", + "eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee" + ], + ["role", "member"], + ["expected_role", "admin"] + ] + } + }, { "name": "remove", "event": { @@ -65,6 +82,44 @@ } ], "rejected": [ + { + "name": "Solo role change without expected role", + "event": { + "kind": 9050, + "created_at": 1700000010, + "content": "", + "tags": [ + ["h", "11111111-1111-4111-8111-111111111111"], + [ + "p", + "eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee" + ], + ["role", "member"], + ["expected_role", "admin"], + ["role", "guest"] + ] + } + }, + { + "name": "Solo role change targeting an owner role", + "event": { + "kind": 9050, + "created_at": 1700000010, + "content": "", + "tags": [ + ["h", "11111111-1111-4111-8111-111111111111"], + [ + "p", + "eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee" + ], + ["role", "member"], + ["expected_role", "admin"], + ["role", "guest"], + ["role", "guest"], + ["expected_role", "owner"] + ] + } + }, { "name": "wrong kind", "event": { diff --git a/src/features/channel-members/administration-protocol.ts b/src/features/channel-members/administration-protocol.ts index e894b28c22..1aa868d31b 100644 --- a/src/features/channel-members/administration-protocol.ts +++ b/src/features/channel-members/administration-protocol.ts @@ -10,6 +10,7 @@ import { } from "../relay/channel-lifecycle-protocol.ts"; export const editableMemberRoles = ["admin", "member", "guest"] as const; +export const SOLO_MEMBER_ROLE_KIND = 9050; export type EditableMemberRole = (typeof editableMemberRoles)[number]; export type MemberRole = EditableMemberRole | "owner" | "bot" | "unknown"; export type MemberChange = Readonly<{ @@ -22,8 +23,8 @@ export type MemberChange = Readonly<{ export type MemberAuthority = Readonly<{ roles: Readonly>; canManage: boolean; - /** Solo owners may edit existing agents, without enabling other role changes. */ - canManageAgents: boolean; + /** Solo owners use the conditional role-update command for current members. */ + canManageSolo: boolean; canRemove: boolean; canRemoveOwnedAgent: boolean; /** A NIP-CL system channel, where administration may also add members. */ @@ -97,12 +98,15 @@ export function memberAuthority( "Member roles are inconsistent. Refresh members and roles.", ); const activeChannel = type !== "dm" && archived !== "true"; - // Solo role edits are limited to the owner's existing agent participants. const solo = !!soloLabels(channelIdentity(metadata).labels); return Object.freeze({ roles: Object.freeze(roles), canManage: activeChannel && !solo && elevated.has(viewer), - canManageAgents: activeChannel && solo && elevated.get(viewer) === "owner", + canManageSolo: + type === "stream" && + activeChannel && + solo && + elevated.get(viewer) === "owner", canRemove: activeChannel && elevated.has(viewer), canRemoveOwnedAgent: activeChannel && !solo && !!roles[viewer] && roles[viewer] !== "unknown", @@ -110,20 +114,25 @@ export function memberAuthority( }); } -export function canManageMember( +function isRoleTarget(state: MemberAuthority, viewer: string, key: string) { + const role = state.roles[key]; + return key !== viewer && !!role && role !== "owner" && role !== "unknown"; +} + +export function canSetMemberRole( state: MemberAuthority, viewer: string, key: string, - agent = false, + next: EditableMemberRole, + agentOwner?: string, ) { - const role = state.roles[key]; - return ( - (state.canManage || (state.canManageAgents && agent)) && - key !== viewer && - !!role && - role !== "owner" && - role !== "unknown" - ); + if (!isRoleTarget(state, viewer, key)) return false; + if (state.canManage) return true; + if (!state.canManageSolo) return false; + const current = state.roles[key]; + if (next === "admin") return current !== "admin" && agentOwner === viewer; + if (next === "guest") return current !== "guest"; + return current === "admin" || (current === "guest" && !!agentOwner); } /** Ownership permits removal only; it never grants role-edit authority. */ @@ -158,7 +167,8 @@ export function canTransferOwnership( !state.system && state.roles[viewer] === "owner" && state.roles[key] !== "bot" && - canManageMember(state, viewer, key) + state.canManage && + isRoleTarget(state, viewer, key) ); } @@ -167,7 +177,7 @@ export function authorizeMemberChange( viewer: string, change: MemberChange, owner?: string, - /** Verified target identity; unknown cannot grant access or receive ownership. */ + /** A possibly-agent target cannot receive ownership. */ agent?: boolean, ) { if (change.expectedRole === "none") { @@ -195,8 +205,14 @@ export function authorizeMemberChange( ? canRemoveMember(state, viewer, change.pubkey, owner) : change.role === "owner" ? canTransferOwnership(state, viewer, change.pubkey, agent !== false) - : canManageMember(state, viewer, change.pubkey, agent === true) && - isEditableMemberRole(change.role)) || + : isEditableMemberRole(change.role) && + canSetMemberRole( + state, + viewer, + change.pubkey, + change.role, + owner, + )) || (change.expectedRole !== "absent" && state.roles[change.pubkey] !== change.expectedRole) || change.expectedRole === change.role @@ -232,10 +248,15 @@ export function memberAdministrationTemplate( channelId: string, viewer: string, change: MemberChange, + soloRoleUpdate: boolean, ): EventTemplate { const h = ["h", lifecycleChannelId(channelId)]; return { - kind: change.role === "remove" ? 9001 : 9000, + kind: soloRoleUpdate + ? SOLO_MEMBER_ROLE_KIND + : change.role === "remove" + ? 9001 + : 9000, created_at: Math.floor(Date.now() / 1000), content: "", // The relay decides each person in order, so the heir's promotion lets @@ -247,6 +268,7 @@ export function memberAdministrationTemplate( h, ["p", change.pubkey], ...(change.role === "remove" ? [] : [["role", change.role]]), + ...(soloRoleUpdate ? [["expected_role", change.expectedRole]] : []), ], }; } @@ -256,7 +278,8 @@ export function validateMemberAdministrationTemplate( event: EventTemplate, viewer: string, ) { - const [h, p, last] = event?.tags ?? []; + const [h, p, last, expected] = event?.tags ?? []; + const soloRoleUpdate = event?.kind === SOLO_MEMBER_ROLE_KIND; const transfer = event?.kind === 9000 && p?.length === 3 && @@ -268,28 +291,34 @@ export function validateMemberAdministrationTemplate( PUBKEY.test(viewer); if ( !event || - ![9000, 9001].includes(event.kind) || + ![9000, 9001, SOLO_MEMBER_ROLE_KIND].includes(event.kind) || event.content !== "" || !Number.isSafeInteger(event.created_at) || event.created_at < 0 || !Array.isArray(event.tags) || - event.tags.length !== (event.kind === 9000 ? 3 : 2) || + event.tags.length !== (soloRoleUpdate ? 4 : event.kind === 9000 ? 3 : 2) || h?.length !== 2 || h[0] !== "h" || p?.length !== (transfer ? 3 : 2) || p[0] !== "p" || !PUBKEY.test(p[1] ?? "") || p[1] === viewer || - (event.kind === 9000 && + (event.kind !== 9001 && !transfer && (last?.length !== 2 || last[0] !== "role" || - !isEditableMemberRole(last[1]))) + !isEditableMemberRole(last[1]))) || + (soloRoleUpdate && + (expected?.length !== 2 || + expected[0] !== "expected_role" || + !(expected[1] === "bot" || isEditableMemberRole(expected[1])))) ) throw new Error("Invalid member administration command"); lifecycleChannelId(h[1] ?? ""); } -function isEditableMemberRole(role: unknown): role is EditableMemberRole { +export function isEditableMemberRole( + role: unknown, +): role is EditableMemberRole { return editableMemberRoles.some((value) => value === role); } diff --git a/src/features/channel-members/administration.test.ts b/src/features/channel-members/administration.test.ts index 2e385767e8..6d816baa4c 100644 --- a/src/features/channel-members/administration.test.ts +++ b/src/features/channel-members/administration.test.ts @@ -552,7 +552,7 @@ it.each(["ack", "lost", "read"])( authority: { roles: {}, canManage: false, - canManageAgents: false, + canManageSolo: false, canRemove: false, canRemoveOwnedAgent: false, system: false, @@ -594,7 +594,7 @@ it.each(["access", "invalid ID"])( authority: { roles: {}, canManage: false, - canManageAgents: false, + canManageSolo: false, canRemove: false, canRemoveOwnedAgent: false, system: false, @@ -622,7 +622,7 @@ it.each(["clear", "dispose"] as const)( authority: { roles: {}, canManage: false, - canManageAgents: false, + canManageSolo: false, canRemove: false, canRemoveOwnedAgent: false, system: false, @@ -811,7 +811,7 @@ it.each(["cache", "access"] as const)( authority: { roles: {}, canManage: false, - canManageAgents: false, + canManageSolo: false, canRemove: false, canRemoveOwnedAgent: false, system: false, @@ -827,7 +827,7 @@ it.each(["cache", "access"] as const)( expect(admin.snapshot(id).authority).toEqual({ roles: {}, canManage: false, - canManageAgents: false, + canManageSolo: false, canRemove: false, canRemoveOwnedAgent: false, system: false, @@ -1192,27 +1192,44 @@ function soloAgent(actor = "owner", role = "bot", profiles = [agentProfile()]) { ]); return h; } -it("lets the chat owner edit another owner's agent without granting identity-less authority", async () => { - const h = soloAgent("owner", "bot", [agentProfile(relayKey)]); - const intent = { ...change, expectedRole: "bot" } as const; - const state = memberAuthority(h.events(), id, viewer, author); - expect(() => authorizeMemberChange(state, viewer, intent)).toThrow(); - await h.owner.capability.run(id, intent); - expect(h.publish).toHaveBeenCalledOnce(); -}); it.each([ - ["bot", "admin"], - ["admin", "member"], - ["admin", "guest"], + ["admin", "member", personProfile()], + ["admin", "guest", personProfile()], + ["member", "guest", personProfile()], + ["admin", "member", agentProfile(relayKey)], + ["bot", "guest", agentProfile(relayKey)], + ["guest", "member", agentProfile(relayKey)], + ["bot", "admin", agentProfile()], ] as const)( - "lets a Solo owner change an agent from %s to %s", - async (before, role) => { - const h = soloAgent("owner", before); + "lets a Solo owner change access from %s to %s when permitted", + async (before, role, profile) => { + const h = soloAgent("owner", before, [profile]); await h.owner.capability.run(id, { ...change, expectedRole: before, role }); - expect(h.publish).toHaveBeenCalledOnce(); + expect(h.publish.mock.calls[0]?.[0]).toMatchObject({ + kind: 9050, + tags: [ + ["h", id], + ["p", target], + ["role", role], + ["expected_role", before], + ], + }); expect(h.owner.capability.snapshot(id).operation?.status).toBe("confirmed"); }, ); +it.each([ + ["member", "admin", agentProfile(relayKey)], + ["member", "admin", agentProfile(key, 200, false)], + ["guest", "member", agentProfile(key, 200, false)], + ["guest", "member", personProfile()], +] as const)( + "refuses an unauthorized Solo promotion from %s to %s", + async (before, role, profile) => { + const h = soloAgent("owner", before, [profile]); + await h.owner.capability.run(id, { ...change, expectedRole: before, role }); + expect(h.sign).not.toHaveBeenCalled(); + }, +); it.each(["admin", "member", "guest"])( "denies a Solo %s an agent role edit", async (actor) => { @@ -1253,6 +1270,27 @@ it("rechecks the Solo target profile after signing", async () => { expect(h.sign).toHaveBeenCalledOnce(); expect(h.publish).not.toHaveBeenCalled(); }); +it("discards a standard role write if the channel becomes Solo while signing", async () => { + const h = harness("owner", "admin"); + h.sign.mockImplementationOnce(async (template) => { + h.setEvents([ + h.record(39000, [ + ["d", id], + ["t", "stream"], + ["t", SOLO_LABEL], + ]), + ...h.events().slice(1), + ]); + return finalizeEvent(structuredClone(template), key); + }); + await h.owner.capability.run(id, { + ...change, + expectedRole: "admin", + role: "guest", + }); + expect(h.sign).toHaveBeenCalledOnce(); + expect(h.publish).not.toHaveBeenCalled(); +}); it("transfers ownership in one event that steps the viewer down to admin", async () => { const h = transferHarness(); await h.owner.capability.run(id, transfer); @@ -1280,7 +1318,7 @@ it("never offers a transfer to a co-owner", () => { const state = { roles: { [viewer]: "owner" as const, [target]: "owner" as const }, canManage: true, - canManageAgents: false, + canManageSolo: false, canRemove: true, canRemoveOwnedAgent: false, system: false, @@ -1310,7 +1348,7 @@ it("authorizes a system-channel add only for a non-member other than the viewer const state = { roles: { [viewer]: "owner" as const, [author]: "member" as const }, canManage: true, - canManageAgents: false, + canManageSolo: false, canRemove: true, canRemoveOwnedAgent: false, system: true, diff --git a/src/features/channel-members/administration.ts b/src/features/channel-members/administration.ts index 5d74fd8a6b..bcfaeadf37 100644 --- a/src/features/channel-members/administration.ts +++ b/src/features/channel-members/administration.ts @@ -10,7 +10,8 @@ import { lifecycleChannelId } from "../relay/channel-lifecycle-protocol"; import { authorizeMemberChange, canRemoveMember, - canManageMember, + canSetMemberRole, + isEditableMemberRole, memberAdministrationTemplate, memberAuthority, memberChangeConfirmed, @@ -35,7 +36,7 @@ const empty: MemberAdministrationState = Object.freeze({ authority: Object.freeze({ roles: Object.freeze({}), canManage: false, - canManageAgents: false, + canManageSolo: false, canRemove: false, canRemoveOwnedAgent: false, system: false, @@ -244,22 +245,47 @@ export function createMemberAdministration({ !event || !!foldProfiles([event]).get(change.pubkey)?.isAgent; if (agent) throw new Error(transferRefusal); } + const soloRoleUpdate = + authority.canManageSolo && isEditableMemberRole(change.role); + let targetOwner = owner; if ( - authority.canManageAgents && - change.role !== "remove" && - change.role !== "owner" && - canManageMember(authority, viewer, change.pubkey, true) + soloRoleUpdate && + !canSetMemberRole( + authority, + viewer, + change.pubkey, + change.role, + ) && + canSetMemberRole( + authority, + viewer, + change.pubkey, + change.role, + viewer, + ) ) { - // A fresh signed profile must confirm the Solo-only exception - // on both preflights; roster roles and display hints aren't proof. + // Promotions require fresh ownership proof on both preflights. const event = await profile(); - agent = - !!event && !!foldProfiles([event]).get(change.pubkey)?.isAgent; + targetOwner = event && (await attestedOwner(event)); + signal.throwIfAborted(); + assertAccess(id); } - authorizeMemberChange(authority, viewer, change, owner, agent); + authorizeMemberChange( + authority, + viewer, + change, + targetOwner, + agent, + ); + return soloRoleUpdate; }; - await authorize(); - const template = memberAdministrationTemplate(id, viewer, change); + const soloRoleUpdate = await authorize(); + const template = memberAdministrationTemplate( + id, + viewer, + change, + soloRoleUpdate, + ); validateMemberAdministrationTemplate(template, viewer); const signed = await writer.sign(structuredClone(template), signal); signal.throwIfAborted(); @@ -272,7 +298,10 @@ export function createMemberAdministration({ getEventHash(signed) !== signed.id ) throw new Error("Signer changed the member administration command"); - await authorize(); + if ((await authorize()) !== soloRoleUpdate) + throw new Error( + "Chat type changed. Refresh members and roles before trying again.", + ); signal.throwIfAborted(); if (active?.() === false) throw new DOMException("Member change cancelled", "AbortError"); diff --git a/tests/browser/fixture.mjs b/tests/browser/fixture.mjs index 58e8361e22..d7abcd1a80 100644 --- a/tests/browser/fixture.mjs +++ b/tests/browser/fixture.mjs @@ -302,7 +302,7 @@ export const test = base.extend({ }, ); const ownerAgentKey = - lifecycleOwnerAgent || agentMessageDeletion + lifecycleOwnerAgent || agentMessageDeletion || memberRoleChanges ? generateSecretKey() : undefined; const ownerAgent = ownerAgentKey ? getPublicKey(ownerAgentKey) : undefined; @@ -2180,7 +2180,7 @@ export const test = base.extend({ acceptPublication: (community, event) => { expect(verifyEvent(event)).toBe(true); expect(event.pubkey).toBe(viewer); - if (memberRoleChanges && event.kind === 9000) { + if (memberRoleChanges && event.kind === 9050) { report.publications.push({ community, event }); return; } @@ -2696,6 +2696,7 @@ export const test = base.extend({ return event; }, signRelay: (template) => finalizeEvent(template, relayKey), + ownerAgent, membershipSnapshot(role) { expect(["owner", "admin", "member"]).toContain(role); return sign(13534, [["member", viewer, role]], "", relayKey); diff --git a/tests/browser/solo-agent-roles.spec.mjs b/tests/browser/solo-agent-roles.spec.mjs index ceb0f722c7..1a467bd35a 100644 --- a/tests/browser/solo-agent-roles.spec.mjs +++ b/tests/browser/solo-agent-roles.spec.mjs @@ -1,6 +1,5 @@ import { test, expect } from "./fixture.mjs"; import { openPage } from "./navigation.mjs"; -import { generateSecretKey } from "nostr-tools"; import { animationsSettled } from "./animations.mjs"; const chat = "33333333-3333-4333-8333-333333333333"; @@ -32,13 +31,11 @@ test("the Solo owner changes an existing agent's access from its menu", async ({ page, app, }, info) => { - const agent = app.serveProfile(generateSecretKey(), { - name: "Review assistant", - is_agent: true, - }); - app.serveMembers(chat, [agent.pubkey]); + const agent = app.ownerAgent; + expect(agent).toBeDefined(); + app.serveMembers(chat, [agent]); const grants = () => - app.report.publications.filter(({ event }) => event.kind === 9000); + app.report.publications.filter(({ event }) => event.kind === 9050); await page.route("**/api/relay/primary/query", async (route) => { const response = await route.fetch(); const events = await response.json(); @@ -52,10 +49,10 @@ test("the Solo owner changes an existing agent's access from its menu", async ({ ) return event; const tags = event.tags.filter( - ([tag, key]) => tag !== "p" || key !== agent.pubkey, + ([tag, key]) => tag !== "p" || key !== agent, ); - if (event.kind === 39002) tags.push(["p", agent.pubkey, "", role]); - else if (role === "admin") tags.push(["p", agent.pubkey, "admin"]); + if (event.kind === 39002) tags.push(["p", agent, "", role]); + else if (role === "admin") tags.push(["p", agent, "admin"]); return app.signRelay({ ...event, tags, @@ -82,7 +79,7 @@ test("the Solo owner changes an existing agent's access from its menu", async ({ ); await page.getByRole("button", { name: /^Share access to / }).click(); const actions = page.getByRole("button", { - name: "Actions for Review assistant", + name: "Actions for Owner Agent", exact: true, }); await actions.click(); @@ -122,8 +119,9 @@ test("the Solo owner changes an existing agent's access from its menu", async ({ await expect.poll(() => grants().length).toBe(1); expect(grants()[0].event.tags).toEqual([ ["h", chat], - ["p", agent.pubkey], + ["p", agent], ["role", "admin"], + ["expected_role", "bot"], ]); await actions.click(); await expect( From a470947dc66a981307e6f6a87ddd690b51c12784 Mon Sep 17 00:00:00 2001 From: Taylor Ho Date: Wed, 18 Nov 2026 10:06:54 -0800 Subject: [PATCH 03/10] docs(solo): describe owner role controls Describe downgrades for current members, verified agent promotions, and which chat permissions Viewing only grants. Co-authored-by: Carl Signed-off-by: Taylor Ho --- docs/buzz-help.md | 8 +++++--- docs/channels.md | 6 ++++-- docs/solo/sharing.md | 11 +++++++---- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/docs/buzz-help.md b/docs/buzz-help.md index bb87edaab0..61df88f417 100644 --- a/docs/buzz-help.md +++ b/docs/buzz-help.md @@ -472,9 +472,11 @@ and are asked to sign in again in Buzz. the chat; anyone else outside the chat is only named: not added and not notified, and the picker row says so. People already in the chat are notified as usual. The toolbar's agent menu lists agents only. - A Solo chat owner can open an existing agent’s menu in **Share access**, - choose **Admin**, **Participating** or **Viewing only**, and confirm. These - role choices apply only to agents already in the chat. + On relays that support Solo role updates, the chat owner can use a current + member’s menu in **Share access** to lower their access. + The owner can restore **Participating** for a verified + agent and grant **Admin** to their own verified agents. **Viewing only** + gives read-only access to that chat. New chats start **Ongoing** unless **Chat settings** chooses **Temporary**, which archives the chat after a set time without activity. To start every new chat temporary, open the community's **Settings → Local settings** and choose diff --git a/docs/channels.md b/docs/channels.md index af9314f814..90d1a6c4ac 100644 --- a/docs/channels.md +++ b/docs/channels.md @@ -1040,8 +1040,10 @@ to its underlying conversation/message without that panel. The header **Access** button opens the one access dialog every conversation uses. It is titled **Channel access** in channels and **Chat access** in a Solo chat (see -[Sharing a Solo chat](solo/sharing.md)). A Solo chat owner can remove people and -agents there but cannot change roles. +[Sharing a Solo chat](solo/sharing.md)). A Solo chat owner can remove current +non-owner members. On relays that support Solo role updates, the owner can +lower their access, restore participation for verified agents, and grant Admin +to their own verified agents. One search field, with an accessible name but no visible label, filters current members and lists people, agents and Teams to invite under **Not in this channel**. With an empty query, channels and Solo chats show invitations only when the viewer is diff --git a/docs/solo/sharing.md b/docs/solo/sharing.md index 5c53ee1308..1002c85a03 100644 --- a/docs/solo/sharing.md +++ b/docs/solo/sharing.md @@ -45,10 +45,13 @@ Where the viewer cannot add agents, a note says to mention an agent in the chat instead. Current access uses the channel groups (**People**, **Agents**) with Owner and Admin tags, and each row has the channel members' actions menu, so the chat owner -can remove someone. The owner can also change an existing agent to **Admin**, -**Participating** or **Viewing only** from that menu, with confirmation. These -role choices apply only to agents already in the chat. The verified roster shows -loading or failure, never treating a failed read as an empty audience. +can remove someone. On relays that support Solo role updates, the owner can +confirm a lower role for any current non-owner, including people and agents. +**Viewing only** gives read-only access +to the chat. A verified agent can move from **Viewing only** to **Participating**, +and the chat owner can grant **Admin** to their own verified agents. The +verified roster shows loading or failure, never treating a failed read as an +empty audience. Invitations use the same groups and controls as channels: **Your agents** first, then **People**, **Other agents** and **Your other agents**, omitting empty groups. From d5540464819b3bb83952ea0deaa660b2ff0f3c02 Mon Sep 17 00:00:00 2001 From: Taylor Ho Date: Wed, 18 Nov 2026 14:46:33 -0800 Subject: [PATCH 04/10] fix(solo): preserve the invitation template default Keep automatic Admin grants on the existing invitation command when the caller omits the manual role-update option. Co-authored-by: Carl Signed-off-by: Taylor Ho --- src/features/channel-members/administration-protocol.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/features/channel-members/administration-protocol.ts b/src/features/channel-members/administration-protocol.ts index 1aa868d31b..c90b24e806 100644 --- a/src/features/channel-members/administration-protocol.ts +++ b/src/features/channel-members/administration-protocol.ts @@ -248,7 +248,7 @@ export function memberAdministrationTemplate( channelId: string, viewer: string, change: MemberChange, - soloRoleUpdate: boolean, + soloRoleUpdate = false, ): EventTemplate { const h = ["h", lifecycleChannelId(channelId)]; return { From a7f7e0302869610dc42bb50c0b91368b80ecc1cf Mon Sep 17 00:00:00 2001 From: Taylor Ho Date: Wed, 18 Nov 2026 14:46:38 -0800 Subject: [PATCH 05/10] test(solo): isolate role update validation cases Exercise missing and invalid expected roles, the tag name, and the requested role independently in the shared signing fixture. Co-authored-by: Carl Signed-off-by: Taylor Ho --- .../administration-contract.json | 60 ++++++++++++++++--- 1 file changed, 53 insertions(+), 7 deletions(-) diff --git a/src/features/channel-members/administration-contract.json b/src/features/channel-members/administration-contract.json index 73ad0e5951..cb4ded1d76 100644 --- a/src/features/channel-members/administration-contract.json +++ b/src/features/channel-members/administration-contract.json @@ -94,14 +94,12 @@ "p", "eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee" ], - ["role", "member"], - ["expected_role", "admin"], - ["role", "guest"] + ["role", "member"] ] } }, { - "name": "Solo role change targeting an owner role", + "name": "Solo role change with owner as expected role", "event": { "kind": 9050, "created_at": 1700000010, @@ -113,13 +111,61 @@ "eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee" ], ["role", "member"], - ["expected_role", "admin"], - ["role", "guest"], - ["role", "guest"], ["expected_role", "owner"] ] } }, + { + "name": "Solo role change with absent as expected role", + "event": { + "kind": 9050, + "created_at": 1700000010, + "content": "", + "tags": [ + ["h", "11111111-1111-4111-8111-111111111111"], + [ + "p", + "eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee" + ], + ["role", "member"], + ["expected_role", "absent"] + ] + } + }, + { + "name": "Solo role change with a misnamed expected-role tag", + "event": { + "kind": 9050, + "created_at": 1700000010, + "content": "", + "tags": [ + ["h", "11111111-1111-4111-8111-111111111111"], + [ + "p", + "eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee" + ], + ["role", "member"], + ["old_role", "admin"] + ] + } + }, + { + "name": "Solo role change with owner as the new role", + "event": { + "kind": 9050, + "created_at": 1700000010, + "content": "", + "tags": [ + ["h", "11111111-1111-4111-8111-111111111111"], + [ + "p", + "eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee" + ], + ["role", "owner"], + ["expected_role", "admin"] + ] + } + }, { "name": "wrong kind", "event": { From a2613308727122b0e00c820a2f3c2de832d083b4 Mon Sep 17 00:00:00 2001 From: Taylor Ho Date: Wed, 18 Nov 2026 14:46:42 -0800 Subject: [PATCH 06/10] test(solo): scope role screenshots to the active surface Wait for the action menu only while it is open and capture the confirmation using its own dialog locator. Co-authored-by: Carl Signed-off-by: Taylor Ho --- tests/browser/solo-agent-roles.spec.mjs | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/tests/browser/solo-agent-roles.spec.mjs b/tests/browser/solo-agent-roles.spec.mjs index 1a467bd35a..32b3bb4c90 100644 --- a/tests/browser/solo-agent-roles.spec.mjs +++ b/tests/browser/solo-agent-roles.spec.mjs @@ -16,11 +16,8 @@ test.use({ viewport: { width: 1100, height: 900 }, }); -async function capture(page, info, name) { - const dialog = page.getByRole("dialog"); +async function capture(dialog, info, name) { await animationsSettled(dialog, { subtree: true }); - const menu = page.getByRole("menu"); - if (await menu.count()) await animationsSettled(menu, { subtree: true }); await dialog.screenshot({ path: info.outputPath(name) }); } @@ -85,7 +82,9 @@ test("the Solo owner changes an existing agent's access from its menu", async ({ await actions.click(); const menu = page.getByRole("menu"); await expect(menu).toBeVisible(); - await capture(page, info, "agent-access-menu.png"); + await animationsSettled(menu, { subtree: true }); + const share = page.getByRole("dialog", { name: "Share access", exact: true }); + await capture(share, info, "agent-access-menu.png"); await expect( menu.getByRole("menuitemradio", { name: "Participating", exact: true }), ).toHaveAttribute("aria-checked", "true"); @@ -106,16 +105,14 @@ test("the Solo owner changes an existing agent's access from its menu", async ({ }); await expect(save).toBeFocused(); expect(grants()).toHaveLength(0); - await capture(page, info, "agent-access-confirmation.png"); + await capture(confirm, info, "agent-access-confirmation.png"); await confirm.getByRole("button", { name: "Cancel", exact: true }).click(); await expect(actions).toBeFocused(); expect(grants()).toHaveLength(0); await actions.click(); await page.getByRole("menuitemradio", { name: "Admin", exact: true }).click(); await save.click(); - await expect( - page.getByRole("dialog", { name: "Share access", exact: true }), - ).toBeVisible(); + await expect(share).toBeVisible(); await expect.poll(() => grants().length).toBe(1); expect(grants()[0].event.tags).toEqual([ ["h", chat], From a21eb01ce24d28902ad82f91ae3f82e69d5f3da8 Mon Sep 17 00:00:00 2001 From: Taylor Ho Date: Wed, 18 Nov 2026 15:26:58 -0800 Subject: [PATCH 07/10] fix(solo): gate role edits on relay support Carry the relay advertisement through the existing web and desktop member administration writers. Hide Solo role controls and reject manual role edits before signing when the advertisement is absent. Co-authored-by: Carl Signed-off-by: Taylor Ho --- browser-host/relay-broker.mjs | 3 + .../channels/MemberAdministration.test.tsx | 3 + .../administration-protocol.ts | 2 + .../channel-members/administration.test.ts | 43 ++++++++++++-- .../channel-members/administration.ts | 12 +++- src/features/relay/native.test.ts | 15 +++++ src/features/relay/native.ts | 14 ++++- src/features/relay/transport.ts | 15 ++++- tests/browser/fixture.mjs | 11 +++- tests/browser/solo-agent-roles.spec.mjs | 58 +++++++++++++------ 10 files changed, 142 insertions(+), 34 deletions(-) diff --git a/browser-host/relay-broker.mjs b/browser-host/relay-broker.mjs index 1b9fbbbded..b514ccd632 100644 --- a/browser-host/relay-broker.mjs +++ b/browser-host/relay-broker.mjs @@ -336,6 +336,9 @@ async function relayAuthority(fetch, relay) { channelIdentity: Array.isArray(nip11.supported_extensions) && nip11.supported_extensions.includes("nip-cl"), + soloMemberRoleUpdates: + Array.isArray(nip11.supported_extensions) && + nip11.supported_extensions.includes("buzz-solo-member-role"), // NIP-AR sync: REQ with `"artifact": "current"` keeps a set current. artifactSync: nip11.artifacts?.sync?.version === 1, artifactSupport: diff --git a/src/bundled/channels/MemberAdministration.test.tsx b/src/bundled/channels/MemberAdministration.test.tsx index d6a5099795..baa8b0d1b4 100644 --- a/src/bundled/channels/MemberAdministration.test.tsx +++ b/src/bundled/channels/MemberAdministration.test.tsx @@ -190,6 +190,9 @@ async function setup( memberAdministration: { sign: async (template) => signed(viewer, template), publish, + ...(visibility === "solo" + ? { soloMemberRoleUpdates: true as const } + : {}), }, } : {}), diff --git a/src/features/channel-members/administration-protocol.ts b/src/features/channel-members/administration-protocol.ts index c90b24e806..7ecd9ec6d6 100644 --- a/src/features/channel-members/administration-protocol.ts +++ b/src/features/channel-members/administration-protocol.ts @@ -38,6 +38,7 @@ export function memberAuthority( channelId: string, viewer: string, relayAuthor: string, + soloMemberRoleUpdates = false, ): MemberAuthority { if (events.some((event) => ![39000, 39001, 39002].includes(event.kind))) throw new Error("Unexpected channel membership response"); @@ -103,6 +104,7 @@ export function memberAuthority( roles: Object.freeze(roles), canManage: activeChannel && !solo && elevated.has(viewer), canManageSolo: + soloMemberRoleUpdates && type === "stream" && activeChannel && solo && diff --git a/src/features/channel-members/administration.test.ts b/src/features/channel-members/administration.test.ts index 6d816baa4c..6fe5cd09a5 100644 --- a/src/features/channel-members/administration.test.ts +++ b/src/features/channel-members/administration.test.ts @@ -46,7 +46,11 @@ function deferred() { }); return { promise, resolve }; } -function harness(actor = "owner", role: string | undefined = "member") { +function harness( + actor = "owner", + role: string | undefined = "member", + soloMemberRoleUpdates = false, +) { let clock = 100; const record = (kind: number, tags: string[][]) => finalizeEvent({ kind, tags, content: "", created_at: clock++ }, relayKey); @@ -98,7 +102,11 @@ function harness(actor = "owner", role: string | undefined = "member") { const acceptDiscovery = vi.fn(); const owner = createMemberAdministration({ reader: { read }, - writer: { sign, publish }, + writer: { + sign, + publish, + ...(soloMemberRoleUpdates ? { soloMemberRoleUpdates: true } : {}), + }, viewer, relayAuthor: author, canAccess: () => access, @@ -938,8 +946,12 @@ function agentProfile(ownerKey = key, created_at = 200, valid = true) { new Uint8Array(32).fill(4), ); } -function ownedAgent(actor = "member", role = "bot") { - const h = harness(actor, role); +function ownedAgent( + actor = "member", + role = "bot", + soloMemberRoleUpdates = false, +) { + const h = harness(actor, role, soloMemberRoleUpdates); let profiles = [agentProfile()]; h.read.mockImplementation(async (filters) => filters.some((filter) => filter.kinds?.includes(0)) ? profiles : h.events(), @@ -1180,8 +1192,14 @@ function transferHarness( h.setProfiles(profiles); return h; } -function soloAgent(actor = "owner", role = "bot", profiles = [agentProfile()]) { - const h = transferHarness(actor, role, profiles); +function soloAgent( + actor = "owner", + role = "bot", + profiles = [agentProfile()], + soloMemberRoleUpdates = true, +) { + const h = ownedAgent(actor, role, soloMemberRoleUpdates); + h.setProfiles(profiles); h.setEvents([ h.record(39000, [ ["d", id], @@ -1192,6 +1210,19 @@ function soloAgent(actor = "owner", role = "bot", profiles = [agentProfile()]) { ]); return h; } +it("refuses a Solo role update before signing on an older relay and still allows removal", async () => { + const h = soloAgent("owner", "bot", [agentProfile()], false); + const capability = h.owner.capability; + await capability.refresh(id); + expect(capability.snapshot(id).authority.canManageSolo).toBe(false); + await capability.run(id, { ...change, expectedRole: "bot", role: "guest" }); + expect(capability.snapshot(id).operation?.status).toBe("failed"); + expect(h.sign).not.toHaveBeenCalled(); + expect(h.publish).not.toHaveBeenCalled(); + await capability.run(id, removeAgent); + expect(capability.snapshot(id).operation?.status).toBe("confirmed"); + expect(h.publish.mock.calls[0]?.[0].kind).toBe(9001); +}); it.each([ ["admin", "member", personProfile()], ["admin", "guest", personProfile()], diff --git a/src/features/channel-members/administration.ts b/src/features/channel-members/administration.ts index bcfaeadf37..1a6383b557 100644 --- a/src/features/channel-members/administration.ts +++ b/src/features/channel-members/administration.ts @@ -1,7 +1,7 @@ import { getEventHash } from "nostr-tools"; import type { RelayReader } from "../relay/reader"; import { retryRead } from "../relay/read-retry"; -import type { RelayWriter } from "../relay/transport"; +import type { ReadTransport } from "../relay/transport"; import { newer, type RelayEvent } from "../relay/events"; import { attestedOwner } from "../agents/owner-attestation"; import { foldProfiles } from "../relay/profiles"; @@ -55,7 +55,7 @@ export function createMemberAdministration({ acceptDiscovery, }: { reader?: RelayReader | undefined; - writer?: RelayWriter | undefined; + writer?: ReadTransport["memberAdministration"]; viewer: string; relayAuthor: string; canAccess(id: string): boolean; @@ -96,7 +96,13 @@ export function createMemberAdministration({ assertAccess(id); return { events, - authority: memberAuthority(events, id, viewer, relayAuthor), + authority: memberAuthority( + events, + id, + viewer, + relayAuthor, + writer?.soloMemberRoleUpdates === true, + ), }; } async function perform( diff --git a/src/features/relay/native.test.ts b/src/features/relay/native.test.ts index cf35df6a04..5bc51d63bf 100644 --- a/src/features/relay/native.test.ts +++ b/src/features/relay/native.test.ts @@ -247,6 +247,21 @@ it("reads back expired delivery with strong consistency without re-signing or pu vi.mocked(invoke).mock.calls.some(([command]) => command === "relay_sign"), ).toBe(false); }); +it.each([ + [undefined, undefined], + [["nip-cl"], undefined], + ["buzz-solo-member-role", undefined], + [["nip-cl", "buzz-solo-member-role"], true], +])( + "requires an explicit NIP-11 advertisement for Solo role updates: %o", + async (supported_extensions, expected) => { + discovery = { supported_extensions }; + expect( + (await connectNativeTransport(community)).memberAdministration + ?.soloMemberRoleUpdates, + ).toBe(expected); + }, +); it.each([ {}, { supported_extensions: null }, diff --git a/src/features/relay/native.ts b/src/features/relay/native.ts index dc49283ef1..980404ba4c 100644 --- a/src/features/relay/native.ts +++ b/src/features/relay/native.ts @@ -454,6 +454,9 @@ export async function connectNativeTransport( const channelIdentity = Array.isArray(info.supported_extensions) && info.supported_extensions.includes("nip-cl"); + const soloMemberRoleUpdates = + Array.isArray(info.supported_extensions) && + info.supported_extensions.includes("buzz-solo-member-role"); const artifactSupport = Array.isArray(info.supported_extensions) && info.supported_extensions.includes("nip-ar"); @@ -598,9 +601,14 @@ export async function connectNativeTransport( validateLifecycleTemplate, ), channelDetails: commandWriter("channel-details", validateDetailsTemplate), - memberAdministration: commandWriter("member-administration", (event) => - validateMemberAdministrationTemplate(event, transport.viewer ?? ""), - ), + memberAdministration: { + ...commandWriter("member-administration", (event) => + validateMemberAdministrationTemplate(event, transport.viewer ?? ""), + ), + ...(soloMemberRoleUpdates + ? { soloMemberRoleUpdates: true as const } + : {}), + }, identityArchive: commandWriter( "identity-archive", validateArchiveRequestTemplate, diff --git a/src/features/relay/transport.ts b/src/features/relay/transport.ts index 182827f287..feb4544dde 100644 --- a/src/features/relay/transport.ts +++ b/src/features/relay/transport.ts @@ -140,7 +140,10 @@ export interface ReadTransport { readonly channelLifecycle?: RelayWriter; /** Name/about/private-only metadata writer, separate from lifecycle and outbox. */ readonly channelDetails?: RelayWriter; - readonly memberAdministration?: RelayWriter; + readonly memberAdministration?: RelayWriter & { + /** NIP-11 advertises `buzz-solo-member-role` for kind:9050 updates. */ + readonly soloMemberRoleUpdates?: true; + }; /** NIP-AR kind-45010 config artifacts only; never supplied to the outbox. */ readonly configArtifacts?: RelayWriter; /** Narrow NIP-IA 9035/9036 signer/publisher; never supplied to the message outbox. */ @@ -553,6 +556,7 @@ export async function connectBrokerTransport( sidebarMuteWrites?: boolean; channelKit?: boolean; channelIdentity?: boolean; + soloMemberRoleUpdates?: boolean; searchSort?: boolean; artifactSync?: boolean; sidebarPreferenceWrites?: boolean; @@ -1130,7 +1134,14 @@ export async function connectBrokerTransport( ? { channelDetails: routeWriter("channel-details") } : {}), ...(session.memberAdministration === true - ? { memberAdministration: routeWriter("member-administration") } + ? { + memberAdministration: { + ...routeWriter("member-administration"), + ...(session.soloMemberRoleUpdates === true + ? { soloMemberRoleUpdates: true as const } + : {}), + }, + } : {}), ...(session.channelLifecycle === true ? { channelLifecycle: routeWriter("channel-lifecycle") } diff --git a/tests/browser/fixture.mjs b/tests/browser/fixture.mjs index d7abcd1a80..33cef332ca 100644 --- a/tests/browser/fixture.mjs +++ b/tests/browser/fixture.mjs @@ -2211,8 +2211,13 @@ export const test = base.extend({ discovery: (community) => ({ self: getPublicKey(relayKey), // Solo details publications below retain label changes as well as names. - ...(ownSoloChannels.length - ? { supported_extensions: ["nip-cl"] } + ...(ownSoloChannels.length || memberRoleChanges + ? { + supported_extensions: [ + ...(ownSoloChannels.length ? ["nip-cl"] : []), + ...(memberRoleChanges ? ["buzz-solo-member-role"] : []), + ], + } : {}), ...(readState ? { @@ -2525,7 +2530,7 @@ export const test = base.extend({ communityAliases: fixtureAliases, identity: () => userKey.slice(), agentLibrary: () => ({ definitions: [], identities: [] }), - ...(readState || channelLifecycle + ...(readState || channelLifecycle || memberRoleChanges ? {} : { authority: async () => ({ diff --git a/tests/browser/solo-agent-roles.spec.mjs b/tests/browser/solo-agent-roles.spec.mjs index 32b3bb4c90..0356042138 100644 --- a/tests/browser/solo-agent-roles.spec.mjs +++ b/tests/browser/solo-agent-roles.spec.mjs @@ -21,6 +21,26 @@ async function capture(dialog, info, name) { await dialog.screenshot({ path: info.outputPath(name) }); } +async function openSoloAccess(page, app) { + await page.goto(app.origin); + await openPage(page, "Messages"); + await page.evaluate( + ({ chat, viewer }) => + window.fixtureNavigation.open({ + version: 1, + kind: "conversation", + channelId: chat, + scope: { viewer, communityOrigin: "https://primary.example" }, + }), + { chat, viewer: app.viewer }, + ); + await page.getByRole("button", { name: /^Share access to / }).click(); + return page.getByRole("button", { + name: "Actions for Owner Agent", + exact: true, + }); +} + // Browser-only: production app routing, portalled menu hit-testing, keyboard // selection and nested confirmation focus through the real broker signer/write. // Only upstream signed membership policy is modeled; role matrices live in Vitest. @@ -62,23 +82,7 @@ test("the Solo owner changes an existing agent's access from its menu", async ({ localStorage.setItem("buzz-appearance.v1", "dark"); localStorage.setItem("buzz-accent.v1", "cobalt"); }); - await page.goto(app.origin); - await openPage(page, "Messages"); - await page.evaluate( - ({ chat, viewer }) => - window.fixtureNavigation.open({ - version: 1, - kind: "conversation", - channelId: chat, - scope: { viewer, communityOrigin: "https://primary.example" }, - }), - { chat, viewer: app.viewer }, - ); - await page.getByRole("button", { name: /^Share access to / }).click(); - const actions = page.getByRole("button", { - name: "Actions for Owner Agent", - exact: true, - }); + const actions = await openSoloAccess(page, app); await actions.click(); const menu = page.getByRole("menu"); await expect(menu).toBeVisible(); @@ -148,3 +152,23 @@ test("the Solo owner changes an existing agent's access from its menu", async ({ } expect(app.report.unexpected).toEqual([]); }); + +test.describe("relay without Solo role update support", () => { + test.use({ memberRoleChanges: false, lifecycleOwnerAgent: true }); + + test("keeps existing member actions without offering role changes", async ({ + page, + app, + }) => { + const agent = app.ownerAgent; + expect(agent).toBeDefined(); + app.serveMembers(chat, [agent]); + await (await openSoloAccess(page, app)).click(); + const menu = page.getByRole("menu"); + await expect( + menu.getByRole("menuitem", { name: "Remove from chat" }), + ).toBeVisible(); + await expect(menu.getByRole("menuitemradio")).toHaveCount(0); + expect(app.report.unexpected).toEqual([]); + }); +}); From 0e2251a892486e2f854dda53ce9d82e4ce56f14e Mon Sep 17 00:00:00 2001 From: Taylor Ho Date: Wed, 18 Nov 2026 16:50:18 -0800 Subject: [PATCH 08/10] fix(solo): restrict role edits to private chats Require signed private visibility in the shared Solo role authority and cover menu visibility, removal, and the publication preflight. Co-authored-by: Carl Signed-off-by: Taylor Ho --- docs/buzz-help.md | 4 +- docs/channels.md | 6 +- docs/solo/sharing.md | 5 +- .../channels/MemberAdministration.test.tsx | 40 +++++++++-- .../administration-protocol.ts | 2 + .../channel-members/administration.test.ts | 70 +++++++++++++------ 6 files changed, 94 insertions(+), 33 deletions(-) diff --git a/docs/buzz-help.md b/docs/buzz-help.md index 61df88f417..e39b63fa20 100644 --- a/docs/buzz-help.md +++ b/docs/buzz-help.md @@ -472,8 +472,8 @@ and are asked to sign in again in Buzz. the chat; anyone else outside the chat is only named: not added and not notified, and the picker row says so. People already in the chat are notified as usual. The toolbar's agent menu lists agents only. - On relays that support Solo role updates, the chat owner can use a current - member’s menu in **Share access** to lower their access. + In a **Private** Solo chat on a relay that supports role updates, the owner can + use a current member’s menu in **Share access** to lower their access. The owner can restore **Participating** for a verified agent and grant **Admin** to their own verified agents. **Viewing only** gives read-only access to that chat. diff --git a/docs/channels.md b/docs/channels.md index 90d1a6c4ac..c493c50798 100644 --- a/docs/channels.md +++ b/docs/channels.md @@ -1041,9 +1041,9 @@ to its underlying conversation/message without that panel. The header **Access** button opens the one access dialog every conversation uses. It is titled **Channel access** in channels and **Chat access** in a Solo chat (see [Sharing a Solo chat](solo/sharing.md)). A Solo chat owner can remove current -non-owner members. On relays that support Solo role updates, the owner can -lower their access, restore participation for verified agents, and grant Admin -to their own verified agents. +non-owner members. In a Private Solo chat on a relay that supports role updates, +the owner can lower their access, restore participation for verified agents, +and grant Admin to their own verified agents. One search field, with an accessible name but no visible label, filters current members and lists people, agents and Teams to invite under **Not in this channel**. With an empty query, channels and Solo chats show invitations only when the viewer is diff --git a/docs/solo/sharing.md b/docs/solo/sharing.md index 1002c85a03..c6f4d97fbe 100644 --- a/docs/solo/sharing.md +++ b/docs/solo/sharing.md @@ -45,8 +45,9 @@ Where the viewer cannot add agents, a note says to mention an agent in the chat instead. Current access uses the channel groups (**People**, **Agents**) with Owner and Admin tags, and each row has the channel members' actions menu, so the chat owner -can remove someone. On relays that support Solo role updates, the owner can -confirm a lower role for any current non-owner, including people and agents. +can remove someone. In a Private chat on a relay that supports Solo role updates, +the owner can confirm a lower role for any current non-owner, including people +and agents. **Viewing only** gives read-only access to the chat. A verified agent can move from **Viewing only** to **Participating**, and the chat owner can grant **Admin** to their own verified agents. The diff --git a/src/bundled/channels/MemberAdministration.test.tsx b/src/bundled/channels/MemberAdministration.test.tsx index baa8b0d1b4..bf2c5c27ce 100644 --- a/src/bundled/channels/MemberAdministration.test.tsx +++ b/src/bundled/channels/MemberAdministration.test.tsx @@ -63,10 +63,17 @@ async function setup( messageNavigation = true, initialReads?: { names?: Promise; roster?: Promise }, ownership?: "own" | "other" | "invalid", - visibility: "private" | "public" | "solo" = "private", + visibility: "private" | "public" | "solo" | "view-only-solo" = "private", targetPicture?: string, targetProfiled = true, ) { + const solo = visibility === "solo" || visibility === "view-only-solo"; + const visibilityFlag = + visibility === "solo" + ? "private" + : visibility === "view-only-solo" + ? "public" + : visibility; const viewer = keypair(), relay = keypair(), target = keypair(), @@ -119,8 +126,9 @@ async function setup( tags: [ ["d", id], ["t", "stream"], - [visibility === "solo" ? "private" : visibility], - ...(visibility === "solo" ? [["t", "buzz.solo"]] : []), + [visibilityFlag], + ...(solo ? [["t", "buzz.solo"]] : []), + ...(visibility === "view-only-solo" ? [["join_role", "guest"]] : []), ["name", "Design"], ], }), @@ -190,9 +198,7 @@ async function setup( memberAdministration: { sign: async (template) => signed(viewer, template), publish, - ...(visibility === "solo" - ? { soloMemberRoleUpdates: true as const } - : {}), + ...(solo ? { soloMemberRoleUpdates: true as const } : {}), }, } : {}), @@ -860,6 +866,28 @@ it("offers only a downgrade for a Solo participant with an unattested agent prof screen.queryByRole("menuitemradio", { name: "Admin" }), ).not.toBeInTheDocument(); }); +it("keeps removal in a View only Solo chat without showing role choices", async () => { + const t = await setup( + "owner", + "admin", + true, + undefined, + false, + undefined, + false, + true, + undefined, + undefined, + "view-only-solo", + ); + await t.user.click( + screen.getByRole("button", { name: "Actions for Morgan" }), + ); + expect( + await screen.findByRole("menuitem", { name: "Remove from chat" }), + ).toBeInTheDocument(); + expect(screen.queryAllByRole("menuitemradio")).toHaveLength(0); +}); it("presents verified roles, protects owners/self, and confirms a separate deliberate role intent", async () => { const t = await setup(); await expectProfileOnly(t.user, "Carl"); diff --git a/src/features/channel-members/administration-protocol.ts b/src/features/channel-members/administration-protocol.ts index 7ecd9ec6d6..3bee31fa7a 100644 --- a/src/features/channel-members/administration-protocol.ts +++ b/src/features/channel-members/administration-protocol.ts @@ -1,5 +1,6 @@ import type { EventTemplate } from "nostr-tools"; import { soloLabels } from "../solo/labels.ts"; +import { channelVisibility } from "../relay/channel-details-protocol.ts"; import { channelIdentity } from "../relay/channel-labels.ts"; import type { RelayEvent } from "../relay/events.ts"; import { @@ -108,6 +109,7 @@ export function memberAuthority( type === "stream" && activeChannel && solo && + channelVisibility(metadata) === "private" && elevated.get(viewer) === "owner", canRemove: activeChannel && elevated.has(viewer), canRemoveOwnedAgent: diff --git a/src/features/channel-members/administration.test.ts b/src/features/channel-members/administration.test.ts index 6fe5cd09a5..f7b6ededf4 100644 --- a/src/features/channel-members/administration.test.ts +++ b/src/features/channel-members/administration.test.ts @@ -1197,31 +1197,61 @@ function soloAgent( role = "bot", profiles = [agentProfile()], soloMemberRoleUpdates = true, + visibilityTags = [["private"]], ) { const h = ownedAgent(actor, role, soloMemberRoleUpdates); h.setProfiles(profiles); - h.setEvents([ - h.record(39000, [ - ["d", id], - ["t", "stream"], - ["t", SOLO_LABEL], - ]), - ...h.events().slice(1), - ]); - return h; + const setVisibility = (tags: string[][]) => + h.setEvents([ + h.record(39000, [["d", id], ["t", "stream"], ["t", SOLO_LABEL], ...tags]), + ...h.events().slice(1), + ]); + setVisibility(visibilityTags); + return { ...h, setVisibility }; } -it("refuses a Solo role update before signing on an older relay and still allows removal", async () => { - const h = soloAgent("owner", "bot", [agentProfile()], false); - const capability = h.owner.capability; - await capability.refresh(id); - expect(capability.snapshot(id).authority.canManageSolo).toBe(false); - await capability.run(id, { ...change, expectedRole: "bot", role: "guest" }); - expect(capability.snapshot(id).operation?.status).toBe("failed"); - expect(h.sign).not.toHaveBeenCalled(); +it.each([ + { name: "an older relay", supported: false, tags: [["private"]] }, + { + name: "a View only chat", + supported: true, + tags: [["public"], ["join_role", "guest"]], + }, + { name: "unknown visibility", supported: true, tags: [] }, + { + name: "contradictory visibility", + supported: true, + tags: [["private"], ["public"]], + }, +])( + "refuses a Solo role update before signing with $name and still allows removal", + async ({ supported, tags }) => { + const h = soloAgent("owner", "bot", [agentProfile()], supported, tags); + const capability = h.owner.capability; + await capability.refresh(id); + expect(capability.snapshot(id).authority.canManageSolo).toBe(false); + await capability.run(id, { ...change, expectedRole: "bot", role: "guest" }); + expect(capability.snapshot(id).operation?.status).toBe("failed"); + expect(h.sign).not.toHaveBeenCalled(); + expect(h.publish).not.toHaveBeenCalled(); + await capability.run(id, removeAgent); + expect(capability.snapshot(id).operation?.status).toBe("confirmed"); + expect(h.publish.mock.calls[0]?.[0].kind).toBe(9001); + }, +); +it("discards a Solo role edit if the chat becomes View only during signing", async () => { + const h = soloAgent(); + h.sign.mockImplementationOnce(async (template) => { + h.setVisibility([["public"], ["join_role", "guest"]]); + return finalizeEvent(structuredClone(template), key); + }); + await h.owner.capability.run(id, { + ...change, + expectedRole: "bot", + role: "guest", + }); + expect(h.sign).toHaveBeenCalledOnce(); expect(h.publish).not.toHaveBeenCalled(); - await capability.run(id, removeAgent); - expect(capability.snapshot(id).operation?.status).toBe("confirmed"); - expect(h.publish.mock.calls[0]?.[0].kind).toBe(9001); + expect(h.owner.capability.snapshot(id).operation?.status).toBe("failed"); }); it.each([ ["admin", "member", personProfile()], From 456dac4867acc0f6c9c3db9c0fab90a539d7c4c5 Mon Sep 17 00:00:00 2001 From: Taylor Ho Date: Thu, 19 Nov 2026 13:17:28 -0800 Subject: [PATCH 09/10] docs(solo): describe conditional member role changes Co-authored-by: Carl Signed-off-by: Taylor Ho --- docs/channels.md | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/docs/channels.md b/docs/channels.md index c493c50798..152037de32 100644 --- a/docs/channels.md +++ b/docs/channels.md @@ -1300,18 +1300,21 @@ disposal, but cannot retract a request already sent. Unsent work is canceled; recovery is in-memory, not durable across session disposal or restart. The development broker and native transport advertise a separate -`memberAdministration` capability and admit only exact `9000` Admin/Member/Guest -changes, the signer's own ownership transfer or `9001` other-member removals -through purpose-bound routes. Generic -invitation signing is unchanged; the relay still enforces the authoritative ACL. +`memberAdministration` capability. Its purpose-bound routes admit ordinary +channel `9000` Admin/Member/Guest changes and the signer's own ownership transfer, +as well as `9001` other-member removals. The relay enforces the authoritative ACL. Hosts without this writer can read verified roles but expose no management controls. Native support requires a rebuilt binary; no unrestricted writer fallback is used. -**Accepted protocol limitation:** role commands are existing relay upserts, not -conditional updates. A departure after final preflight can be undone by the role -command re-adding the target; a concurrent role edit can be overwritten. Client -checks/readback reduce uncertainty but do not provide atomic conflict rejection. -Preventing these races requires separately scoped relay support. +In Private Solo chats, the writer uses kind `9050` for role changes when the +relay advertises `buzz-solo-member-role` in its NIP-11 information document. +The command includes the target's expected current role. The relay updates an +existing member only if that role still matches, so it rejects the edit if the +member left or their role changed before the write. + +Ordinary channel `9000` role changes are unconditional relay upserts. A command +can re-add a member who departed after the final preflight or overwrite a +concurrent role edit. Client checks and readback reduce uncertainty. Regression coverage lives in `administration.test.ts`, `MemberAdministration.test.tsx`, `native.test.ts`, and `browser-host/relay-broker-api.test.mjs`; From b741f17a171d77efda11999eb81dec6efeeea24a Mon Sep 17 00:00:00 2001 From: Taylor Ho Date: Thu, 19 Nov 2026 13:17:31 -0800 Subject: [PATCH 10/10] test(solo): cover bot role updates in native signing Co-authored-by: Carl Signed-off-by: Taylor Ho --- .../administration-contract.json | 17 +++++++++++++++++ src/features/relay/native.test.ts | 15 ++++++++------- 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/src/features/channel-members/administration-contract.json b/src/features/channel-members/administration-contract.json index cb4ded1d76..8507b1b1ca 100644 --- a/src/features/channel-members/administration-contract.json +++ b/src/features/channel-members/administration-contract.json @@ -17,6 +17,23 @@ ] } }, + { + "name": "conditional Solo role change from bot to admin", + "event": { + "kind": 9050, + "created_at": 1700000010, + "content": "", + "tags": [ + ["h", "11111111-1111-4111-8111-111111111111"], + [ + "p", + "eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee" + ], + ["role", "admin"], + ["expected_role", "bot"] + ] + } + }, { "name": "remove", "event": { diff --git a/src/features/relay/native.test.ts b/src/features/relay/native.test.ts index 5bc51d63bf..6664535f3f 100644 --- a/src/features/relay/native.test.ts +++ b/src/features/relay/native.test.ts @@ -2163,14 +2163,15 @@ it("routes member administration through the native purpose-bound writer, never await expect(writer.sign(event, signal)).rejects.toThrow(); const template = memberContract.accepted[0]?.event; assert.exists(template); - const channelTag = template.tags[0]; - assert.exists(channelTag); - await expect( - writer.sign( - { ...template, tags: [channelTag, ["p", viewer.pubkey]] }, - signal, + const selfTarget = { + ...template, + tags: template.tags.map((tag) => + tag[0] === "p" ? ["p", viewer.pubkey] : tag, ), - ).rejects.toThrow(); + }; + await expect(writer.sign(selfTarget, signal)).rejects.toThrow( + "Invalid member administration command", + ); await expect( writer.publish(signed(relay, template), signal), ).rejects.toThrow();