fix(desktop): decide mention eligibility for external agents from relay proofs
Problem
External / remote agents cannot be @-mentioned from Desktop even when they are channel members with valid NIP-OA and kind:10100.
#2149 made the local managed-agent list a hard pre-gate for agent-class identities. Directory eligibility (respond_to / allowlist) never runs for them.
Sharp edge (#2987): an unattested agent can still show as a person and be mentionable; correctly registering it as an agent is what hides it.
Fix
Replace the managed-list pre-gate with one predicate built from relay proofs:
mentionable =
locallyManaged(agent) // native path (membership not required)
|| (
member(agent, channel)
&& (
respond_to == anyone
|| respond_to == allowlist && viewer ∈ allowlist
|| respond_to == owner-only && verifiedOwner(agent) == viewer
)
)
- Local managed store is one proof, not the gatekeeper.
- No kind:10100 declaration → hidden from everyone except the NIP-OA-verified owner (owner-on-another-device; harness already admits the owner).
- Non-member externals stay hidden even if
anyone(add-via-mention /channel_add_policyis out of scope — see #3864). - Liveness is not required (offline is a queue; stopped managed agents are already offered).
Out of scope
| Follow-up | Why separate |
|---|---|
| Add-member search | Same managed-list cut; fix is channel_add_policy — #3864 |
| Desktop directory writer | Native agents still don't publish full 10100; third-party cross-machine half of #3125 / #2508 needs a writer (#3708+) |
Thin CLI set-add-policy clobber |
#3663 |
Related
Closes the @-mention core of #2987. Helps cross-machine owner cases #2349 / #3277. Same root as open PRs #3110 / #3448 / #3609 — this variant keeps undeclared agents fail-closed (except verified owner), requires membership for externals, and supports owner-only via verified OA.
Test plan
- [x] Unit matrix: anyone / allowlist / owner-only / no declaration / non-member / managed / pubkey normalize
- [x]
pnpm test,tsc --noEmit, biome on touched paths - [x] e2e
mentions.spec.ts— external agent (alice,anyone, shared channel) visible (was the bug pin; now regression) - [x] Live: headless OA + 10100 agents appear in @, event carries
p, harness responds
Scope note (post-#3178 / directory clarification)
This PR only changes mention eligibility over proofs the Desktop already loads: local managed set, kind:10100 policy, and kind:0 NIP-OA ownerPubkey.
It does not read kind:30177 (owner instance catalog — see #3178 for CLI owner-scoped lookup) and does not change mint/write of 10100. Native Desktop still may lack a full directory write; third-party mention of those agents remains limited until a writer exists. External agents with full 10100 + membership are the multi-client happy path this gate unlocks.
Ownership for the owner-only / no-declaration paths is the same NIP-OA class #3178 enforces on CLI; we consume Desktop’s existing ownerPubkey projection and do not re-verify conditions in TS.
Independent validation from a live Hermes/Buzz setup:
- Hermes publishes a NIP-OA-attested owner and a kind:10100 profile with
respond_to: "owner-only". - Manually typed
@Hermesroutes correctly, but Desktop autocomplete drops the agent before policy eligibility because it is not in the local managed-agent list. - Requiring verified ownership and current channel membership restores autocomplete for the owner without changing gateway behavior.
Two fail-closed edge cases were important during independent review:
- An unrelated unmanaged channel-member agent with unknown policy must remain hidden.
- An owner-attested unmanaged agent that is not a channel member must remain hidden even if its pubkey is otherwise in the mentionable set.
I verified this PR's stated predicate covers both boundaries: external agents require channel membership plus an admissible relay policy, and owner-only requires the normalized NIP-OA-verified owner to match the viewer.
Local validation of the narrow reproduction/fix path passed the complete just ci gate, including desktop and mobile suites, plus a policy truth table covering normalized owner match, mismatch, missing/empty owner, unrelated unmanaged member, and owned non-member-but-mentionable.
This PR is the closest and most complete existing fix for the Hermes case; no additional duplicate PR opened.
Independent focused verification of the relay-only mention path against Buzz Desktop v0.5.2:
- full Desktop unit suite: 3,777 passed;
- TypeScript typecheck, repository checks, and E2E build passed;
- focused Playwright coverage: 2/2 passed.
The Playwright cases exercise the boundary this PR intends to preserve:
- an allowlisted relay-directory agent outside the current channel remains absent from mention autocomplete;
- the same relay-only agent becomes mentionable after joining the current channel;
- the sent event contains exactly one
ptag for that agent; - the
start_managed_agentcommand count does not change when the message is sent.
That last assertion is worth retaining in the upstream regression test: eligibility for a relay-hosted agent must not imply local lifecycle ownership or start a duplicate harness.
This is supporting evidence for #3676, not a competing implementation.
@wpfleger96 Can we get a look at this.
I reproduced the owner-side failure described in #3204 on a real Buzz 0.5.2 install: the agent is relay-confirmed as a channel member and can receive DMs, but it is absent from both the Agents surface and the @ picker because the picker only trusts the local managed-agent projection.
I checked out this PR at 6b591523d9fc7220c4b18f102d314857ae306c26 and validated the revised eligibility path:
cd desktop && pnpm test: 3,784/3,784 passingcd desktop && pnpm typecheck: passing- The new unit cases cover the reproduced shape: an external/channel-member agent with verified ownership remains mentionable even without a local managed record or directory declaration.
One CI blocker remains in the touched code:
src/features/messages/lib/useMentions.ts:244:35
lint/correctness/useExhaustiveDependencies
This hook specifies more dependencies than necessary: mentionableAgentPubkeys.
mentionableAgentPubkeys is no longer referenced inside mentionCandidates after this refactor. Removing it from the dependency array makes the focused Biome check pass; I verified that one-line cleanup locally together with the full test suite and typecheck above.
The sanitized live-install reproduction is documented at https://github.com/block/buzz/issues/3204#issuecomment-5140259539.
One additional regression check after installing the Playwright browser:
pnpm exec playwright test tests/e2e/mentions.spec.ts \
--project=smoke \
--grep '@ trigger prioritizes channel members'
The existing test initially fails because it still expects alice to be absent. In the mock bridge, Alice is an in-channel relay agent with respond_to: "anyone", so the new behavior correctly includes her. Updating that assertion to toBeVisible() and including aliceIndex < fizzIndex in the member-priority checks makes the test pass.
Validated local delta on top of this PR:
- await expect(dropdown.getByText("alice")).toHaveCount(0);
+ await expect(dropdown.getByText("alice")).toBeVisible();
along with the analogous aliceIndex ordering assertion. This gives the PR an end-to-end regression for the same eligibility change covered by the new unit tests.
I packaged the two validated follow-ups as an apply-ready PR against your head branch: https://github.com/Shipitrealgood/buzz/pull/1. It removes the stale hook dependency and updates the focused E2E expectation/order assertion. Full Desktop tests (3,784), typecheck, focused Biome, and focused Playwright smoke all pass at c2136e9b7c877e7cc48da95729a0a82df9a028d7.
@daguiler76 Both follow-ups are merged. Your PR landed on the head branch as a fast-forward, so the commit is yours as validated — same SHA (c2136e9), authorship and sign-off intact.
Before merging we verified independently: full diff review, desktop suite 3,784/3,784, typecheck, and the focused Biome check on the touched file — all clean. We'd reached the same dep-array conclusion reviewing the refactor, so your patch matched what we expected to write. On the e2e change: confirmed against the mock bridge fixture — alice (respond_to: "anyone", shared channel) models exactly the external-agent shape this PR un-hides, so the old toHaveCount(0) was pinning the #2987 behavior this PR exists to fix; your update turns that spec into an end-to-end regression test for it. Appreciated on both counts.
One scope note on your latest #3204 reproduction (the single-install case — persona-definition rows offered while running channel-member instances are omitted): that's a distinct candidate-assembly defect at the persona/instance coalescing seam, which predates this PR and is deliberately untouched by it. This PR covers the eligibility-gate half of #3204 (your remote-machine case); the join defect is worth its own track so it doesn't get lost when the eligibility work lands.
The integration branch for full-fix testing (test/external-agent-eligibility = current main + this PR + #3864) has been rebuilt on the new tip.
🤖 Generated with Claude Code
I reproduced the issue on windows see https://github.com/block/buzz/issues/3277#issuecomment-5148662049
closing. Believe covered in #4913