Skip to content

Commit d595806

Browse files
loganjLarry
andauthored
fix(desktop): authorize remote mentions at publication (#7124)
🤖 ## Summary In Buzz Desktop, you could own an agent running on another device but be unable to mention it in a channel where it had not yet joined: it was filtered out before you could invite it. A selected agent could also disappear from the message's recipients when permissions changed. This lets you select an eligible agent in the existing **@ menu**, invite it from the message composer, and send to that agent—or see an error and keep your draft rather than silently sending without it. #### Where the experience changes | Screen / control | Before → after | | --- | --- | | A channel's **Message #…** composer, or a message's **Reply in thread to …** composer | Type `@` (or use the existing @ button), choose your agent, write the message and press **Send message**. An owned agent not yet in the channel can now reach the existing **“Mention people outside this channel?”** dialog when its response settings allow you to address it. | | That dialog's **Invite** button | Previously the membership requirement could block the agent before the invitation. Now Invite checks permission to add it, adds it as an agent member of the **channel** (not just the thread), then rechecks membership and response permission before sending the waiting message. An agent already in the channel needs no invitation. | | Existing direct message, or the new-message screen with the **To:** field | A mention is checked against the conversation the message will actually enter, including a newly created direct message, rather than the old or not-yet-created destination. This does not add an Invite control to direct messages. | | Editing a message / sending attachments | The selected agent remains part of the send or edit attempt through attachment upload and the final permission check. Lost permission produces a visible error instead of dropping that recipient. | **Invite is not the only chat choice.** The existing **Do nothing** button sends the message *without inviting or notifying the nonmembers*; their names remain references in the text. Where you cannot invite, that choice is labelled **Send anyway**. To abandon the send instead, dismiss the dialog with Escape. Invitation actions are disabled while preparation is pending, preventing duplicate clicks. **Leaving and returning must not resurrect a cancelled send.** Switching threads or leaving the composer cancels its pending invitation, even if you return to the same thread. Cancellation before dispatch sends no message; an accepted membership change cannot be automatically undone. An ordinary send without a pending invitation remains bound to its original destination rather than following you into another conversation. **Failed sends must not overwrite your next draft.** If you leave a thread, return and replace or deliberately clear its draft while an older send is pending, the older failure cannot restore deleted text, recipients or files; success cannot erase the newer draft—even if its text is identical. An untouched draft cleared automatically for sending remains recoverable on failure. This protection also covers reopening the composer and starting a newer send. The channel timeline also keeps its existing **new-messages / Jump to latest** button available when newer messages are waiting to be displayed. For example, after sharing a reply to the channel and closing the thread panel, you can click the catch-up button to reveal buffered messages. Closing the thread does **not** guarantee the shared row appears automatically or force you away from reading history. ### Related issue Built on [#7122](#7122), base branch `split/owned-agent-discovery`, which lets Desktop find and verify owned agents independently of this device. Current integration head: `1144465d00273cf74b7c22544ae5a3299bd98560`, built on exact published root `3a56d17824522580fe04cae463b54f4c7ba66021`. Root #7122 has its own CI and security gates; this PR must not land ahead of that dependency. Finding an agent is not channel membership, online status or a promise of a reply. This PR changes what the existing message controls can do with those agents; it adds no profile, presence, cloud marker or remote start/stop UI. Standalone forum post/reply **Invite / Cancel** is added separately in [#7125](#7125); here those composers only gain visible authorization errors. Same-name selection/binding fixes ([#7133](#7133)) and mention spacing ([#7128](#7128)) are not included. Extracted from [#7114](#7114) (historical source `98fe33ec`). [Behavior and draft-recovery contract](https://github.com/block/buzz/blob/1144465d00273cf74b7c22544ae5a3299bd98560/docs/remote-mention-routing.md) · [Originating discussion](buzz://message?channel=f7a9536a-1738-4bad-a888-b3ea25010ef1&id=7aa1f0ab23dce514bd8a0221441cf005bf428914621171472b79747c50820848). ### Testing ![Channel composer after Send: RemoteScout is not a channel member; Invite adds it before sending, while Do nothing sends without inviting or notifying it](https://raw.githubusercontent.com/block/buzz/b20345da0bd648ecbc78988637c89893a33ca2f3/pr-7124--remote-invite.png) *Earlier candidate, mock desktop browser: the existing channel dialog now reachable for an eligible owned agent on another device. The two buttons have different send outcomes; Do nothing is not Cancel.* [Success and denial captures](#7124 (comment)) · [Pending-state capture](#7124 (comment)). These show the relevant UI, not live agent availability, native authorization or the later draft-storage/catch-up repairs. No before-state screenshot is available. Existing coverage exercises exact recipients, invitation rejection/cancellation, new direct-message destinations, uploads, edits, thread re-entry and stored-draft deletion. The timeline regression checks the shared reply becomes visible using the available catch-up action. **Integration validation (2026-09-02):** independently reviewed the routing delta onto root `3a56d178`: seven original patches unchanged; two reconciliations retain generic publication-error toasts alongside authorization errors and retain non-authored editability updates. Added two production-hook regression tests (normal and queued-media publication) requiring visible generic error, recovered draft and released pending state. - Writer validation: **5,995 Desktop tests**, **42 focused tests**, **22 mock-IPC browser journeys** (18 routing, 2 root provenance, 2 destination binding), and **1 voice-note failure journey** passed; lint, types, size guards and E2E build also passed. - The broad suite ran before the final formatting-only test amendment, not as an exact-final-head rerun. Independent AST comparison confirmed that amendment is semantics-preserving; **4 fresh assertions at final `1144465d`** passed. Publication rechecked final-head TypeScript, amended-test formatting and `git diff --check` successfully. No new full repository `just ci` run is claimed. - Browser tests use an isolated E2E build and **mock IPC**, not live relay/native authorization. Historical screenshots above are explicitly earlier UI evidence, not exact-head runtime certification. Packaged Tauri/live-relay behavior was not independently witnessed. - **Published-head gates:** [current CI run](https://github.com/block/buzz/actions/runs/33657948560) and [renewed exact-head formal review request](#7124 (comment)) must clear before landing. [Earlier CI run](https://github.com/block/buzz/actions/runs/33438436438) and the two earlier approvals cover `7ffead0f`, not this new head. Root CI/security clearance remains separate; the independent scoped integration approval is not merge authorization. To try it: in a channel or thread, select an owned nonmember agent, Send, then Invite or Escape and retry. Deny the add or revoke its response permission before sending: expect a visible error and recoverable draft, not a message missing the agent. During a pending send, return to the source thread, edit or clear the draft, then leave again: late completion must not overwrite that choice. **Limits:** permission checks and sending are separate operations; cancellation cannot retract a dispatched message. Draft protection is same-window, not new cross-window deletion synchronization. Standalone forum transport failure can still restore text/media without the exact selected recipients. Native compatibility is inherited: open-source builds may still recognize a valid legacy, self-declared agent already in the channel when verified ownership is absent or rejected; that does not establish ownership or unlock this owned-nonmember invitation path. Invalid policy from a verified owner is still rejected. No agent response is guaranteed. --------- Signed-off-by: Logan Johnson <[email protected]> Co-authored-by: Larry <627498bd4bd1f281a16431e3c6cce3b5c25b6692798c78672298aefbf2f8f8b5@buzz.block.builderlab.xyz>
1 parent ce9decb commit d595806

29 files changed

Lines changed: 3268 additions & 368 deletions

‎desktop/playwright.config.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ export default defineConfig({
8181
"**/mention-clipboard.spec.ts",
8282
"**/cloud-provenance.spec.ts",
8383
"**/mention-recipients.spec.ts",
84+
"**/remote-owned-mentions.spec.ts",
8485
"**/team-mentions.spec.ts",
8586
"**/persistent-agent-audience.spec.ts",
8687
"**/relay-reconnect.spec.ts",

‎desktop/src/features/agents/AGENTS.md‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,11 @@ with a TypeScript lookup table or an id comparison in a component.
293293
managed agent. Independently operated relay agents with NIP-OA ownership
294294
remain eligible in every build when their verified owner's signed
295295
`respond_to` policy admits the viewer and relay membership includes the
296-
target channel. Marked builds require that verified owner coordinate but do
296+
target channel at publication. Owned nonmembers may be offered for preparation
297+
and Invite; this is not permission to publish. Final authorization refreshes
298+
the exact destination and retains captured selected identities across uploads
299+
and edits. Denial preserves the draft, never silently removes a selected key.
300+
See `docs/remote-mention-routing.md`. Marked builds require that verified owner coordinate but do
297301
not require it to equal the viewer; OSS builds retain compatibility with
298302
self-authored legacy directory records. Keep native discovery and send-time
299303
revalidation fail closed on invalid ownership or managed policy evidence,

‎desktop/src/features/agents/lib/agentAutocompleteEligibility.test.mjs‎

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -548,3 +548,92 @@ test("coalesceAgentAutocompleteCandidates: leaves non-agents alone", () => {
548548

549549
assert.deepEqual(coalesce([first, second]), [first, second]);
550550
});
551+
552+
test("owners remain admitted by allowlist policy without listing themselves", () => {
553+
assert.equal(
554+
relayAgentCanRespondInChannel(
555+
{
556+
ownerPubkey: CURRENT_PUBKEY,
557+
respondTo: "allowlist",
558+
respondToAllowlist: [],
559+
channelIds: ["general"],
560+
},
561+
"general",
562+
CURRENT_PUBKEY,
563+
),
564+
true,
565+
);
566+
});
567+
568+
test("owned discovery does not require a shared channel, but sending does", () => {
569+
for (const respondTo of ["owner-only", "allowlist", "anyone"]) {
570+
const agent = {
571+
pubkey: PUB_B,
572+
ownerPubkey: CURRENT_PUBKEY,
573+
respondTo,
574+
respondToAllowlist: [],
575+
channelIds: [],
576+
};
577+
assert.equal(
578+
relayAgentIsSharedWithUser(agent, new Set(), CURRENT_PUBKEY),
579+
true,
580+
);
581+
assert.equal(
582+
relayAgentCanRespondInChannel(agent, "general", CURRENT_PUBKEY),
583+
false,
584+
);
585+
}
586+
});
587+
588+
test("DM ownership is independent of local configuration and still requires membership", () => {
589+
const base = {
590+
currentPubkey: CURRENT_PUBKEY,
591+
managedAgentPubkeys: [PUB_A],
592+
sharedChannelIds: new Set(),
593+
relayAgents: [
594+
{
595+
pubkey: PUB_B,
596+
ownerPubkey: CURRENT_PUBKEY,
597+
respondTo: "allowlist",
598+
respondToAllowlist: [],
599+
channelIds: ["dm"],
600+
},
601+
{
602+
pubkey: PUB_C,
603+
ownerPubkey: OTHER_OWNER_PUBKEY,
604+
respondTo: "anyone",
605+
respondToAllowlist: [],
606+
channelIds: ["dm"],
607+
},
608+
{
609+
pubkey: PUB_D,
610+
ownerPubkey: CURRENT_PUBKEY,
611+
respondTo: "nobody",
612+
respondToAllowlist: [],
613+
channelIds: ["dm"],
614+
},
615+
],
616+
};
617+
assert.deepEqual(
618+
getMentionableAgentPubkeys({
619+
...base,
620+
eligibilityScope: { type: "owned", channelId: "dm" },
621+
}),
622+
new Set([PUB_A, PUB_B]),
623+
);
624+
assert.deepEqual(
625+
getMentionableAgentPubkeys({
626+
...base,
627+
eligibilityScope: { type: "owned", channelId: "other" },
628+
}),
629+
new Set([PUB_A]),
630+
);
631+
assert.deepEqual(
632+
getMentionableAgentPubkeys({
633+
...base,
634+
eligibilityScope: { type: "owned", channelId: null },
635+
phase: "prepare",
636+
}),
637+
new Set([PUB_A, PUB_B]),
638+
);
639+
});

‎desktop/src/features/agents/lib/agentAutocompleteEligibility.ts‎

Lines changed: 43 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,17 @@ export function relayAgentIsSharedWithUser(
3434
? normalizePubkey(currentPubkey)
3535
: null;
3636

37+
// Ownership is relay identity, not local key custody. Like the harness's
38+
// author gate, every supported policy except nobody admits the owner.
3739
if (
38-
agent.respondTo === "owner-only" &&
40+
(agent.respondTo === "owner-only" ||
41+
agent.respondTo === "allowlist" ||
42+
agent.respondTo === "anyone") &&
3943
normalizedCurrentPubkey &&
40-
agent.ownerPubkey
44+
agent.ownerPubkey &&
45+
normalizePubkey(agent.ownerPubkey) === normalizedCurrentPubkey
4146
) {
42-
return normalizePubkey(agent.ownerPubkey) === normalizedCurrentPubkey;
47+
return true;
4348
}
4449

4550
if (agent.respondTo === "allowlist" && normalizedCurrentPubkey) {
@@ -71,6 +76,7 @@ export function relayAgentCanRespondInChannel(
7176
export type AgentEligibilityScope =
7277
| { type: "community" }
7378
| { type: "channel"; channelId: string }
79+
| { type: "owned"; channelId: string | null }
7480
| { type: "managed-only" };
7581

7682
export function getMentionableAgentPubkeys({
@@ -79,9 +85,11 @@ export function getMentionableAgentPubkeys({
7985
managedAgentPubkeys,
8086
relayAgents,
8187
sharedChannelIds,
88+
phase = "publish",
8289
}: {
8390
currentPubkey?: string | null;
8491
eligibilityScope: AgentEligibilityScope;
92+
phase?: "prepare" | "publish";
8593
managedAgentPubkeys: Iterable<string>;
8694
relayAgents: readonly RelayAgent[] | undefined;
8795
sharedChannelIds: ReadonlySet<string>;
@@ -94,13 +102,38 @@ export function getMentionableAgentPubkeys({
94102
const isAllowed =
95103
eligibilityScope.type === "managed-only"
96104
? false
97-
: eligibilityScope.type === "community"
98-
? relayAgentIsSharedWithUser(agent, sharedChannelIds, currentPubkey)
99-
: relayAgentCanRespondInChannel(
100-
agent,
101-
eligibilityScope.channelId,
102-
currentPubkey,
103-
);
105+
: eligibilityScope.type === "owned"
106+
? Boolean(
107+
currentPubkey &&
108+
agent.ownerPubkey &&
109+
normalizePubkey(agent.ownerPubkey) ===
110+
normalizePubkey(currentPubkey) &&
111+
relayAgentIsSharedWithUser(
112+
agent,
113+
sharedChannelIds,
114+
currentPubkey,
115+
) &&
116+
(phase === "prepare" ||
117+
(eligibilityScope.channelId !== null &&
118+
agent.channelIds.includes(eligibilityScope.channelId))),
119+
)
120+
: eligibilityScope.type === "community"
121+
? relayAgentIsSharedWithUser(agent, sharedChannelIds, currentPubkey)
122+
: phase === "prepare" &&
123+
currentPubkey &&
124+
agent.ownerPubkey &&
125+
normalizePubkey(agent.ownerPubkey) ===
126+
normalizePubkey(currentPubkey)
127+
? relayAgentIsSharedWithUser(
128+
agent,
129+
sharedChannelIds,
130+
currentPubkey,
131+
)
132+
: relayAgentCanRespondInChannel(
133+
agent,
134+
eligibilityScope.channelId,
135+
currentPubkey,
136+
);
104137
if (isAllowed) {
105138
pubkeys.add(normalizePubkey(agent.pubkey));
106139
}

0 commit comments

Comments
 (0)