diff --git a/docs/agents.md b/docs/agents.md index 88b101aabe..30772c5b12 100644 --- a/docs/agents.md +++ b/docs/agents.md @@ -108,6 +108,48 @@ model can read what they return. Protection reviews these calls and their results as it does other Buzz tools. See [configuration](configuration.md#owner-mcp-community-flag). +## Bestie Inbox access + +The optional run-only `AgentHandle.inbox(context)` delegates the owner's bounded +notification projection to the account's current local Bestie. Inbox starts off +until the owner enables it; choosing or reselecting a Bestie preserves its saved +Inbox preference. A former Bestie's switch is a retained preference, not active +access. Settings and authorization share the marked-section policy in +`bestie-features.ts`: incomplete or damaged markers deny access; edits inside +complete sections remain enabled. This is not separate per-use consent. + +The tool passes the runtime's conversation context separately from model +arguments. Before reading notifications and again before release, the service +freshly reads exact relay-authored metadata and membership with strong consistency. +Only an explicitly private DM or private Solo chat containing exactly the owner +and Bestie qualifies. Missing context, ordinary channels, public/group contexts, +and unavailable or ambiguous evidence deny access. A newer observed membership or +privacy change beats an older allowed response. Each phase also strongly reads +the account choice, then rechecks the saved feature and current owner session. +Outside-run plugin handles and standalone command connections have no Inbox +capability. These checks are bounded evidence, not an atomic relay transaction. + +The service requires a ready, complete channel discovery snapshot before loading +notifications and checks it again before release. While discovery is pending, +failed or partial, a call starts or retries the existing discovery read and returns +a retryable error without reading notifications. Items require observed, ready +unread evidence and a ready Inbox feed with no unresolved edit/deletion targets. +Stale, failed, loading or retired evidence returns a retryable error, never a +successful partial/empty list. Loading, failed or stale remote read-marker sync +also withholds results, even when a local unread action has changed the publication +status. The next call retries outstanding remote marker observation and +notification read errors through the existing owners. Valid local-only and pending +publication states remain usable; remote reconciliation is not required on every +host. The captured runner lifetime is checked after the read, so retirement or +retype cannot release a late result. The MCP client also checks a supplied +cancellation signal before and after the read; ordinary Interrupt does not supply +a per-turn fence in every harness. + +Inbox grants no channel membership, history access or posting rights. Read-context +eligibility is enforced; non-disclosure elsewhere and not copying Inbox content to +memory remain prompt rules, not output confinement. Already returned tool data can +remain in harness history. No posting preview/approval workflow is added. + ## External app authorization The build flag `BUZZ_EXTERNAL_MCP_COMMUNITIES` lists the allowed community diff --git a/docs/buzz-help.md b/docs/buzz-help.md index 58608781f8..4ae3cd727f 100644 --- a/docs/buzz-help.md +++ b/docs/buzz-help.md @@ -818,7 +818,30 @@ available rather than silently discarding it. Bestie choice unchanged; it does not delete a newly created agent. A hosted Bestie whose provider holds its instructions (Builderlab does) shows a **Bestie** tab where **Remembers you** edits them through the provider; - check-ins stay unavailable for hosted agents. + check-ins and Inbox access stay unavailable for hosted agents. +- In your agent's **Bestie** tab, **Behavior** groups **Remembers you** and + **Checks in**. Check-ins need memory on and run once an hour while Buzz is open + and the Watching plugin is on. Each wake uses tokens. +- In that tab, **What your Bestie can read** separates Inbox + access from private-channel membership. **Inbox** lets a local Bestie + help triage notifications, including those from private channels and DMs. It + does not join those conversations, grant their history, or allow replies there. + It starts off until you turn it on. Choosing a Bestie again preserves its + saved Inbox preference. A former Bestie's Inbox switch saves that preference, + but access stays inactive until it is your current Bestie. Reads are allowed + only in an explicitly private DM or Solo chat containing just you and Bestie. + Private-channel rows let you remove Bestie, + add it to one channel, or add it to all your currently eligible private + channels—not future ones. Added here, it joins as a guest and cannot post; + existing participants keep their roles. A channel owner or admin can change + its access to **Participating** to let it post. This panel does not add it to DMs. + Changing Inbox access does not change membership, + and removing channel membership does not turn off Inbox access. + If Inbox cannot finish checking notification updates or read markers, the tool + asks you to retry instead of returning an empty, partial or stale Inbox. + Inbox access does not add message approval before Bestie posts. Private read access is enforced; + its instructions also say to keep Inbox content private to you. That is not a + technical guarantee against later disclosure or retention in session history. - **Settings → Agent setup → Harness defaults** is where supported agent types offer installation, sign-in, and default-model controls. Available controls depend on the type. Do not assume a provider is configured or signed in. diff --git a/docs/unread.md b/docs/unread.md index 371663b758..e5ec093e0a 100644 --- a/docs/unread.md +++ b/docs/unread.md @@ -209,6 +209,11 @@ timeline and the thread being read, without reading unopened threads' replies. - `markUnreadLocal(target)` is durable **on this browser profile/device only**. Automatic reading does not clear it. An explicit mark-through clears that target's local mark. `syncedManualUnread` is `false`. +- `sync().observationOwed` reports missing remote marker observation independently + of publication status and the last enumeration's completeness. Local intent and + publication progress do not clear it. A successful marker refresh does; + continuous replay can clear only the gap it interrupted, not an earlier failure. + Local-only hosts have no remote observation debt. - `refresh()` retries evidence/marker observation; `retrySync()` refreshes markers and retries pending publication. `ReadMutationResult.durability === "saved"` means the local transaction committed, not that the relay accepted it. diff --git a/src/bundled/bestie/BestieTab.test.tsx b/src/bundled/bestie/BestieTab.test.tsx index ee2d8845a9..658b3ef591 100644 --- a/src/bundled/bestie/BestieTab.test.tsx +++ b/src/bundled/bestie/BestieTab.test.tsx @@ -5,6 +5,7 @@ import userEvent from "@testing-library/user-event"; import { afterEach, expect, it, vi } from "vitest"; import type { Agent, AgentChange, Agents } from "../../features/agents/service"; import type { RelayData } from "../../features/relay/service"; +import type { ChannelSummary } from "../../features/relay/contracts"; import { readView, writeView } from "../../shared/view-state"; import { setDefaultAgent } from "../../features/solo/default-agent"; import { onBestieMade } from "../agents/BestieChoice"; @@ -15,7 +16,7 @@ import { startHostedRead, } from "./former"; import { validateObject } from "../../features/agents/attention"; -import { checkinHourly, memory, withFeature } from "./features"; +import { checkinHourly, inbox, memory, withFeature } from "./features"; afterEach(() => { cleanup(); @@ -329,6 +330,14 @@ it("turns a hosted Bestie's memory on and off through its provider, and never to }); expect(get).toHaveBeenCalledTimes(1); expect(remembers).not.toBeChecked(); + const access = screen.getByRole("region", { + name: "What your Bestie can read", + }); + expect(within(access).queryByRole("switch", { name: "Inbox" })).toBeNull(); + expect( + within(access).getByText("Not available with remote agents yet."), + ).toBeVisible(); + expect(set).not.toHaveBeenCalled(); await user.click(remembers); await vi.waitFor(() => expect(set).toHaveBeenCalledTimes(1)); expect(set.mock.calls[0]?.[0]).toBe(withFeature("Be brief.", memory, true)); @@ -347,7 +356,7 @@ it("turns a hosted Bestie's memory on and off through its provider, and never to ).not.toBeInTheDocument(); expect( screen.getAllByText("Not available with remote agents yet."), - ).toHaveLength(1); + ).toHaveLength(2); }); it("never replaces a hosted Bestie's instructions edited elsewhere since the tab read them", async () => { @@ -430,7 +439,7 @@ it("asks before making a remote former Bestie your Bestie again, and Cancel chan await act(async () => { render(); }); - const again = screen.getByRole("button", { name: "Make my Bestie again" }); + const again = screen.getByRole("button", { name: "Make your Bestie again" }); expect(again).toBeEnabled(); await user.click(again); const ask = await screen.findByRole("alertdialog", { @@ -486,7 +495,7 @@ it("turns memory on and off as a marked section of the instructions", async () = const remembers = screen.getByRole("switch", { name: "Remembers you" }); expect(remembers).not.toBeChecked(); expect( - screen.getByText(/Nothing Bestie remembered is deleted/), + screen.getByText(/Turning this off removes the rules, not its memories/), ).toBeVisible(); await user.click(remembers); @@ -512,6 +521,96 @@ it("turns memory on and off as a marked section of the instructions", async () = }); }); +it("keeps Inbox consent in read access, separate from memory and channel membership", async () => { + const user = userEvent.setup(); + const { relay } = community(ada.pubkey); + const { agents, save } = host(); + const Tab = bestieTab(relay, agents).component; + const instructions = withFeature("Be brief.", memory, true); + const agent = { ...ada, config: { instructions } } as Agent; + const { rerender } = render(); + const access = screen.getByRole("region", { + name: "What your Bestie can read", + }); + const readInbox = within(access).getByRole("switch", { + name: "Inbox", + }); + expect(readInbox).not.toBeChecked(); + expect( + within(access).queryByRole("switch", { name: "Remembers you" }), + ).toBeNull(); + expect( + within(access).getByRole("heading", { name: "Private channels" }), + ).toBeVisible(); + expect(access).toHaveTextContent( + "Adding it to a private channel here gives it read-only access.", + ); + expect(readInbox).toHaveAccessibleDescription( + "Let Bestie help triage notifications in your Inbox, including those from private channels and DMs. This doesn’t add it to those conversations or let it reply there.", + ); + await user.click(readInbox); + const on = withFeature(instructions, inbox, true); + expect(save).toHaveBeenLastCalledWith(ada.key, { + config: { instructions: on }, + }); + rerender(); + expect(readInbox).toBeChecked(); + await user.click(readInbox); + expect(save).toHaveBeenLastCalledWith(ada.key, { config: { instructions } }); + expect(screen.getByRole("switch", { name: "Remembers you" })).toBeChecked(); +}); + +it("explains a former Bestie's saved Inbox preference and turns it off without changing memory or channels", async () => { + const user = userEvent.setup(); + const { relay, mainAgent } = community(bea.pubkey); + const { agents, save } = host(); + const session = relay.snapshot().session; + const channel = { + id: "plans", + name: "plans", + channelType: "stream", + private: true, + members: [OWNER, ada.pubkey], + } as ChannelSummary; + vi.spyOn(session.channels, "list").mockReturnValue({ + status: "ready", + channels: [channel], + }); + const add = vi.fn(); + const remove = vi.fn(); + Object.assign(session, { + memberAdditions: { add }, + memberAdministration: { run: remove }, + }); + const instructions = withFeature("Be brief.", memory, true); + const agent = { + ...ada, + config: { instructions: withFeature(instructions, inbox, true) }, + } as Agent; + const Tab = formerBestieTab(relay, agents).component; + const { rerender } = render(); + const readInbox = screen.getByRole("switch", { name: "Inbox" }); + expect(readInbox).toBeChecked(); + expect(readInbox).toBeEnabled(); + expect(readInbox).toHaveAccessibleDescription( + "Inactive while Ada is not your Bestie. This saves your preference for when you choose it again.", + ); + await user.click(readInbox); + expect(save).toHaveBeenCalledExactlyOnceWith(ada.key, { + config: { instructions }, + }); + rerender(); + expect(readInbox).not.toBeChecked(); + expect(screen.getByRole("switch", { name: "Remembers you" })).toBeChecked(); + expect(session.directMessages.open).not.toHaveBeenCalled(); + expect(mainAgent.write).not.toHaveBeenCalled(); + expect(add).not.toHaveBeenCalled(); + expect(remove).not.toHaveBeenCalled(); + expect( + screen.getByRole("button", { name: "Remove Ada from #plans" }), + ).toBeVisible(); +}); + it("keeps memory on through the owner's edits, and offers Restore for edited markers", async () => { const user = userEvent.setup(); const { relay } = community(ada.pubkey); @@ -550,7 +649,7 @@ it("keeps memory on through the owner's edits, and offers Restore for edited mar expect(screen.queryByRole("button", { name: "Restore" })).toBeNull(); expect(screen.getByText(/Fix its start and end lines there/)).toBeVisible(); // Check-ins wait on memory. - expect(screen.getByRole("switch", { name: "Every hour" })).toHaveAttribute( + expect(screen.getByRole("switch", { name: "Checks in" })).toHaveAttribute( "aria-disabled", "true", ); @@ -591,11 +690,12 @@ it("offers no switch while the agent's instructions can't be read here", () => { } />, ); - expect(screen.queryByRole("switch", { name: "Remembers you" })).toBeNull(); - // Each setting's row says why, check-ins too. + expect(screen.queryAllByRole("switch")).toEqual([]); expect( - screen.getAllByText("This agent's instructions could not be read"), - ).toHaveLength(2); + within( + screen.getByRole("region", { name: "What your Bestie can read" }), + ).getByText("This agent's instructions could not be read"), + ).toBeVisible(); expect(save).not.toHaveBeenCalled(); }); @@ -612,7 +712,12 @@ it("checks in every hour only while memory is on, with a timer in the owner's DM configBase: base, }; const { rerender } = render(); - const hourly = () => screen.getByRole("switch", { name: "Every hour" }); + const behavior = screen.getByRole("region", { name: "Behavior" }); + expect( + within(behavior).getByRole("switch", { name: "Remembers you" }), + ).toBeVisible(); + const hourly = () => + within(behavior).getByRole("switch", { name: "Checks in" }); // Memory is off, so check-ins can't be turned on. expect(hourly()).toHaveAttribute("aria-disabled", "true"); expect(screen.getByText("Turn on Remembers you first.")).toBeVisible(); @@ -704,7 +809,7 @@ it("checks in every hour only while memory is on, with a timer in the owner's DM expect(hourly()).not.toHaveAttribute("aria-disabled", "true"); }); -/** Ada with memory on and check-ins off, ready to turn Every hour on. */ +/** Ada with memory on and check-ins off, ready to turn Checks in on. */ function remembering(attentionEnabled = false) { return { ...ada, @@ -721,7 +826,7 @@ it("undoes a failed check-in's timer, so none runs behind a switch that reads of const { agents, save } = host(); const Tab = bestieTab(relay, agents).component; render(); - const hourly = screen.getByRole("switch", { name: "Every hour" }); + const hourly = screen.getByRole("switch", { name: "Checks in" }); save .mockResolvedValueOnce() .mockRejectedValueOnce(new Error("Instructions changed elsewhere")); @@ -743,6 +848,23 @@ it("undoes a failed check-in's timer, so none runs behind a switch that reads of expect(screen.queryByRole("alert")).toBeNull(); }); +it("leaves Attention on after a failed check-in when it was already on", async () => { + const user = userEvent.setup(); + const { relay } = community(ada.pubkey); + const { agents, save } = host(); + const Tab = bestieTab(relay, agents).component; + render(); + save + .mockResolvedValueOnce() + .mockRejectedValueOnce(new Error("Instructions changed elsewhere")); + await user.click(screen.getByRole("switch", { name: "Checks in" })); + await screen.findByRole("alert"); + expect(save.mock.calls[2]).toEqual([ + ada.key, + { attention: { [INTEREST]: null, [TIMER]: null } }, + ]); +}); + it("offers to remove a timer left without its section when undoing fails too", async () => { const user = userEvent.setup(); const { relay } = community(ada.pubkey); @@ -753,7 +875,7 @@ it("offers to remove a timer left without its section when undoing fails too", a .mockResolvedValueOnce() .mockRejectedValueOnce(new Error("Instructions changed elsewhere")) .mockRejectedValueOnce(new Error("Offline")); - await user.click(screen.getByRole("switch", { name: "Every hour" })); + await user.click(screen.getByRole("switch", { name: "Checks in" })); expect(await screen.findByRole("alert")).toHaveTextContent( "Instructions changed elsewhere Its timer may still be saved; remove it below.", ); @@ -770,12 +892,12 @@ it("offers to remove a timer left without its section when undoing fails too", a ), } as unknown as Agent; rerender(); - expect(screen.getByRole("switch", { name: "Every hour" })).not.toBeChecked(); + expect(screen.getByRole("switch", { name: "Checks in" })).not.toBeChecked(); save.mockClear(); await user.click( screen.getByRole("button", { name: "Remove", - description: "Every hour's timer is still saved", + description: "Check-in timer is still saved", }), ); expect(save.mock.calls[0]).toEqual([ @@ -804,12 +926,12 @@ it("says a check-in paused in Attention is paused, and how to restart it", async }, } as unknown as Agent; render(); - const hourly = screen.getByRole("switch", { name: "Every hour" }); + const hourly = screen.getByRole("switch", { name: "Checks in" }); // Still on, so Off still removes it. expect(hourly).toBeChecked(); expect( screen.getByText( - "Paused in Attention. Turn Every hour off and on again to restart it.", + "Paused in Attention. Turn check-ins off and on again to restart.", ), ).toBeVisible(); await user.click(hourly); @@ -840,16 +962,20 @@ it("shows a Former Bestie tab while a former Bestie has a setting on, with a way const Tab = tab.component; render(); expect( - screen.getByText("Ada is no longer your Bestie. These are still on."), + screen.getByText( + "Ada is no longer your Bestie. Manage its saved settings and channel access below.", + ), ).toBeVisible(); expect(screen.getByRole("switch", { name: "Remembers you" })).toBeChecked(); - const hourly = screen.getByRole("switch", { name: "Every hour" }); + const hourly = screen.getByRole("switch", { name: "Checks in" }); expect(hourly).toHaveAttribute("aria-disabled", "true"); expect(screen.getByText("Only your Bestie checks in.")).toBeVisible(); - expect(screen.getByText("Private channels Ada can read")).toBeVisible(); + expect( + screen.getByRole("heading", { name: "Private channels" }), + ).toBeVisible(); await user.click( - screen.getByRole("button", { name: "Make my Bestie again" }), + screen.getByRole("button", { name: "Make your Bestie again" }), ); const confirmation = await screen.findByRole("alertdialog", { name: "Make Ada your bestie?", @@ -1147,7 +1273,9 @@ it("keeps a hosted former Bestie's tab after a failed read, until a read shows n get.mockRejectedValueOnce(new Error("Builderlab is down.")); const Tab = tab.component; render(); - await user.click(await screen.findByRole("button", { name: "Retry" })); + const retry = (await screen.findAllByRole("button", { name: "Retry" }))[0]; + if (!retry) throw new Error("Expected a memory retry button"); + await user.click(retry); expect( await screen.findByRole("switch", { name: "Remembers you" }), ).not.toBeChecked(); @@ -1175,10 +1303,12 @@ it("keeps a hosted former Bestie's tab when memory saved on but reading it back get.mockRejectedValueOnce(new Error("Builderlab is down.")); await user.click(remembers); await vi.waitFor(() => expect(set).toHaveBeenCalledTimes(1)); - expect(await screen.findByText("Builderlab is down.")).toBeVisible(); + expect((await screen.findAllByText("Builderlab is down."))[0]).toBeVisible(); // The earlier off may be out of date, so the tab stays to read again. expect(tab.when?.(remote)).toBe(true); - await user.click(screen.getByRole("button", { name: "Retry" })); + const retry = screen.getAllByRole("button", { name: "Retry" })[0]; + if (!retry) throw new Error("Expected a memory retry button"); + await user.click(retry); expect( await screen.findByRole("switch", { name: "Remembers you" }), ).toBeChecked(); @@ -1254,7 +1384,7 @@ it("lets a former Bestie's leftover check-in be turned off", async () => { }, } as unknown as Agent; render(); - const hourly = screen.getByRole("switch", { name: "Every hour" }); + const hourly = screen.getByRole("switch", { name: "Checks in" }); expect(hourly).toBeChecked(); expect(hourly).not.toHaveAttribute("aria-disabled", "true"); await user.click(hourly); diff --git a/src/bundled/bestie/BestieTab.tsx b/src/bundled/bestie/BestieTab.tsx index 6f6b178566..812383aaf1 100644 --- a/src/bundled/bestie/BestieTab.tsx +++ b/src/bundled/bestie/BestieTab.tsx @@ -1,4 +1,4 @@ -import { useEffect, useRef, useState } from "react"; +import { useEffect, useId, useRef, useState } from "react"; import { watchSlug } from "../../features/agents/attention"; import type { Agent, @@ -10,7 +10,7 @@ import type { RelayData } from "../../features/relay/service"; import type { RelaySession } from "../../features/relay/session"; import { BestieIcon } from "../../shared/design-system/icons"; import { Button } from "../../shared/design-system/ui/Button"; -import { InlineHeader } from "../../shared/design-system/ui/Header"; +import { Header } from "../../shared/design-system/ui/Header"; import { MenuGroup, MenuGroupLabel, @@ -25,6 +25,7 @@ import { SwitchPreferenceRow } from "../../shared/design-system/ui/SwitchPrefere import { bestieName, useBestieChoice } from "../agents/BestieChoice"; import { FEATURES, + inbox, type Feature, featureState, restoredFeature, @@ -191,6 +192,8 @@ function BestieTab({ (choice) => choice.pubkey !== agent.pubkey, ); const name = agent.name || "This agent"; + const accessHeading = useId(); + const behaviorHeading = useId(); const switches = (features: readonly Feature[]) => features.map((feature) => ( } - title={`${name} is no longer your Bestie. These are still on.`} + title={`${name} is no longer your Bestie. Manage its saved settings and channel access below.`} trailing={ } /> @@ -259,7 +262,7 @@ function BestieTab({ {!former && bestie.remove && ( (