buzz icon indicating copy to clipboard operation
buzz copied to clipboard

fix(desktop): mention channel-member agents and invocable relay agents

Open nvisionlife opened this issue 3 months ago • 1 comments

Problem

On a client that manages no agents locally, @-mention autocomplete shows no agents at all — not channel members, not relay-directory entries. Reported in #3671, #3125, #3776, and #4128.

useMentions.ts gated every candidate on the locally-managed agent set:

if (!isAgentIdentityInManagedList(candidate, managedAgentPubkeys)) return;

managedAgentPubkeys is derived solely from managedAgentsQuery.data. When a viewer manages nothing locally that set is empty, so every candidate with isAgent === true is dropped right there — both the channel-member candidates and the relay-directory candidates that mentionCandidates builds further down.

Everything written downstream to handle this — mentionableAgentPubkeys, shouldHideAgentFromMentions, relayAgentIsSharedWithUser — sits after that gate and therefore never runs. shouldHideAgentFromMentions's "invocable => always show" branch is unreachable in the shipped build.

Fix

Two changes, both in the first-pass gate:

  1. isAgentAutocompleteEligible (renamed from isAgentIdentityInManagedList) also admits candidate.isMember === true, so agents that are members of the channel you are typing in pass.
  2. useMentions passes getMentionableAgentPubkeys(...) — local managed ∪ relay agents shared with the viewer — instead of the local-only set, so an agent that is invocable but not a channel member also passes.

Both are needed for the full intended behavior. (1) fixes the reported channel-member symptom; without (2), every eligible relay-directory candidate that is not a channel member is still dropped before the relay-aware filter can admit it — those candidates are pushed with isMember: false, so clause (1) can never match them.

Security posture is unchanged: admission still runs through relayAgentIsSharedWithUser, so an agent that does not allowlist you never enters the set. The added test relay agent that excludes the viewer stays hidden pins that.

MembersSidebar deliberately not widened

MembersSidebar.tsx keeps passing managedAgentPubkeys. Only the helper name changes there. Adding an agent to a channel should answer to channel membership policy, not to an agent's respond_to setting, and conflating the two would let mention semantics silently widen who can be added to a channel. The new isMember === true clause is inert at that call site — the sidebar already returns early for anyone in memberPubkeys.

Tests

New cases in agentAutocompleteEligibility.test.mjs:

  • isAgentAutocompleteEligible: keeps people, channel members, and current managed agent identities — the member clause.
  • relay agent allowlisting the viewer survives the composed mention gate — composes the gate with shouldHideAgentFromMentions for a relay agent that is invocable but not a member, and pins the pre-fix behaviour (local-only set => dropped) so the regression cannot come back quietly.
  • relay agent that excludes the viewer stays hidden — the negative case.

Verified on this branch:

  • pnpm test — 3925 passed, 0 failed
  • tsc --noEmit — clean
  • biome check . — no errors (2 pre-existing useTemplate infos in personaCatalogRelay.test.mjs, untouched)
  • check:file-sizes, check:px-text, check:pubkey-truncation — pass

Note for whoever iterates on this: useMentions.ts sits right at the 1000-line ratchet, so the change had to be net-neutral. Dropping managedAgentPubkeys from the mentionCandidates dependency array is also required — after the swap it is no longer read inside that memo, and leaving it trips lint/correctness/useExhaustiveDependencies.

Not covered here

A Playwright spec driving the autocomplete itself is not included. The unit tests pin the gate's behaviour, not the wiring from useMentions into the dropdown. The E2E bridge does have the pieces for it — handleListRelayAgents plus the mock.relayAgents and mock.managedAgents config seeds — so a spec that seeds one allowlisting relay agent, no managed agents, and asserts on the @ menu looks reachable without new infrastructure. Happy to add it here if a reviewer wants it in the same PR.

Credit

Supersedes #4357, which is the origin of the channel-member clause and its test. That work is carried here with authorship preserved via Co-authored-by, plus the relay-agent half of the gate and the composed-gate regression tests.

Adjacent, not fixed here

respond_to: "anyone" is a trap for profiles published without channel_ids. relayAgentIsSharedWithUser requires agent.channelIds.some((id) => sharedChannelIds.has(id)) for that route, and agents_from_events defaults channel_ids to [] when the profile omits it — so switching an agent from allowlist to the seemingly-broader anyone makes it vanish from other people's autocomplete. Happy to file that separately if it is not already tracked.

nvisionlife avatar Aug 03 '26 01:08 nvisionlife

This fixes an issue I am dealing with! Thank you!

kevinsakiro avatar Aug 03 '26 01:08 kevinsakiro

Thank you for putting this together.

ErnestoEverhard avatar Aug 03 '26 02:08 ErnestoEverhard