Skip to content

Commit 43747ae

Browse files
morgmartMorgaritaclaudeCarl
authored
feat(mentions): quieter mention menu that marks agents and their owners (#2328)
People and agents looked the same in the mention menu, so it was easy to tag someone's agent by mistake (AIDA-2362). This makes both mention menus (inline `@` and the toolbar picker) quieter and makes agents easy to tell apart. ## What changes - Identity keys no longer show on mention rows. - An agent icon appears after an agent's name. Screen readers hear "Agent". - Other people's agents show "Managed by <owner>". - The outside-channel detail is shortened to "Not in channel". - The "Narrow your search to see more members." footer is removed. - People search now passes each agent's declared owner, so namesakes get readable labels ("Wes's Honey") instead of key suffixes. ## Implementation notes - `CompletionSuggestion` gains an optional `agent` flag. The host's `completionResult` keeps it only when it's `true`. - "Managed by" uses only the NIP-OA attested owner (`profiles.owner`), read at render time because attestation settles after the profile lands. It is skipped when the owner has only a fallback name. - Rows carry their exact key (`data-mention-choice` on picker rows, `data-completion-id` on completion options), so browser journeys still select namesakes by exact identity. ## Not in this PR Sorting changes, hiding agents you can't tag, linking the owner name, and naming for unknown people. ## Testing - `tsc --noEmit`, biome. - vitest across mentions, conversation, identity-names, solo, messages and direct-messages: 3,023 passed. - Playwright, locally with `--workers=1`, on the 16 affected specs: chromium 145 passed, webkit 130 passed. - Pushed with `--no-verify`. The local pre-push hook timed out in unrelated suites on a heavily loaded machine, so CI is the source of truth. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Signed-off-by: morgmart <[email protected]> Co-authored-by: Morgarita <6e967af659416160ab4f2fd56d74c8c6f273791ee7bfc9468a1be37c387947be@buzz.block.builderlab.xyz> Co-authored-by: Claude Opus 5.5 <[email protected]> Co-authored-by: Carl <c217fe6b9d958f41c3a5e030dccc7f626775a923089cb6491305eade75ea1f1b@buzz.block.builderlab.xyz>
1 parent 918ec18 commit 43747ae

32 files changed

Lines changed: 886 additions & 307 deletions

‎docs/plugin-architecture.md‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2162,7 +2162,8 @@ still revokes unpublished work, without exposing ARIA controls for a missing lis
21622162

21632163
Providers receive immutable observation/range evidence and `publish(result)`—not
21642164
DOM, focus or replacement commands. Results contain stable IDs, labels, optional
2165-
detail/decorative previews and either text, an exact `{ pubkey, name }` mention,
2165+
detail/decorative previews, an optional `agent` flag (marked and announced only
2166+
for the bundled mention and channel providers) and either text, an exact `{ pubkey, name }` mention,
21662167
or a `mentions` array of up to 32 such recipients. Batch edit primitives are
21672168
copied and frozen before display, and accepted as a single editor transaction.
21682169
The host copies edit/query primitives and caps publications at 50 choices. A

‎src/bundled/mentions/MentionCompletion.tsx‎

Lines changed: 112 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { useProfileGeneration } from "../../features/relay/react";
22
import { TeamMentionAvatars } from "./TeamMentionAvatars";
33
import {
4+
useCallback,
45
useContext,
56
useEffect,
67
useRef,
@@ -27,10 +28,31 @@ import {
2728

2829
// Demand bookkeeping only, not another profile cache. Missing names do not issue
2930
// the same network request on every query keystroke; explicit retry remains available.
30-
const demands = new WeakMap<
31-
ComposerSession,
32-
{ generation: number; evictions: number; ids: Set<string> }
33-
>();
31+
// `failed` outlives the per-keystroke mount: a failed read stays reported, with
32+
// Retry, until a later read of those names succeeds or the demand resets.
33+
type Demand = {
34+
generation: number;
35+
evictions: number;
36+
ids: Set<string>;
37+
failed: Set<string>;
38+
};
39+
const demands = new WeakMap<ComposerSession, Demand>();
40+
const failureListeners = new WeakMap<ComposerSession, Set<() => void>>();
41+
function settle(
42+
session: ComposerSession,
43+
demand: Demand,
44+
ids: readonly string[],
45+
failed: boolean,
46+
) {
47+
// A reset demand (purge, eviction) starts over; its old outcome is stale.
48+
if (demands.get(session) !== demand) return;
49+
for (const id of ids) {
50+
// A batch that failed may still have answered for some of its names.
51+
if (failed && !session.profiles.snapshot().has(id)) demand.failed.add(id);
52+
else demand.failed.delete(id);
53+
}
54+
for (const listener of failureListeners.get(session) ?? []) listener();
55+
}
3456
export function MentionCompletion({
3557
session,
3658
scope,
@@ -72,7 +94,32 @@ export function MentionCompletion({
7294
ids: string[];
7395
}>(undefined);
7496
const [attempt, retry] = useState(0);
75-
const [error, setError] = useState(false);
97+
// A failed read reports only names still unresolved: a member loaded since
98+
// (by any reader) or known unnamed, or one no longer in the roster, is not.
99+
const error = useSyncExternalStore(
100+
useCallback(
101+
(listener: () => void) => {
102+
const listeners = failureListeners.get(session) ?? new Set();
103+
failureListeners.set(session, listeners);
104+
listeners.add(listener);
105+
const unsubscribe = session.profiles.subscribe(listener);
106+
return () => {
107+
listeners.delete(listener);
108+
unsubscribe();
109+
};
110+
},
111+
[session],
112+
),
113+
() => {
114+
const failed = demands.get(session)?.failed;
115+
if (draftRoster || !failed?.size) return false;
116+
const loaded = session.profiles.snapshot();
117+
const unnamed = session.profiles.unnamed?.();
118+
return members.some(
119+
(key) => failed.has(key) && !loaded.has(key) && !unnamed?.has(key),
120+
);
121+
},
122+
);
76123
const profileGeneration = useProfileGeneration(session.profiles);
77124
// Evictions also count cancelled reads, so a shrink asks again for this roster.
78125
const readEvictions = () => session.profiles.evictions?.() ?? 0;
@@ -92,8 +139,14 @@ export function MentionCompletion({
92139
demand?.generation !== profileGeneration ||
93140
demand.evictions !== evictions
94141
) {
95-
demand = { generation: profileGeneration, evictions, ids: new Set() };
142+
demand = {
143+
generation: profileGeneration,
144+
evictions,
145+
ids: new Set(),
146+
failed: new Set(),
147+
};
96148
demands.set(session, demand);
149+
for (const listener of failureListeners.get(session) ?? []) listener();
97150
}
98151
const requested = demand.ids;
99152
// An open channel reserves room for its whole roster (ConversationChannel).
@@ -113,16 +166,15 @@ export function MentionCompletion({
113166
.slice(0, attempt > 0 ? limit : Math.max(0, limit - asked));
114167
if (!ids.length) return;
115168
for (const id of ids) requested.add(id);
116-
let live = true;
117-
// Retry is explicit: a foreground read rereads known absences.
169+
// Retry is explicit: a foreground read rereads known absences. The
170+
// outcome belongs to the session's demand, not this keystroke's mount.
171+
const current = demand;
118172
void session.profiles
119173
.ensure(ids, attempt > 0 ? "foreground" : "background")
120-
.catch(() => {
121-
if (live) setError(true);
122-
});
123-
return () => {
124-
live = false;
125-
};
174+
.then(
175+
() => settle(session, current, ids, false),
176+
() => settle(session, current, ids, true),
177+
);
126178
}, [session, memberKey, attempt, draftRoster, profileGeneration, evictions]);
127179
useEffect(() => {
128180
const members = memberKey ? memberKey.split(":") : [];
@@ -141,7 +193,6 @@ export function MentionCompletion({
141193
const membershipMissing =
142194
!draftRoster && (!inviteAgents || !!channel) && !channel?.members;
143195
const membershipError = !draftRoster && list.error;
144-
const missing = !draftRoster && members.some((key) => !profiles.has(key));
145196
// A multi-word query that continues no known name is prose, not a search.
146197
if (
147198
!admitted &&
@@ -154,50 +205,55 @@ export function MentionCompletion({
154205
if (withdraw) withdraw();
155206
};
156207
}
157-
// Each shown row asks both; one pass each instead of one scan per row.
208+
// Each shown row asks; one pass instead of one scan per row.
158209
const memberKeys = new Set(members);
159-
const agentKeys = new Set(
160-
model.candidates.flatMap((c) => (c.agent ? [c.recipient.pubkey] : [])),
161-
);
162210
const available = [
163211
...matching.map(
164-
({ recipient, label, elsewhere, disabled, fullName }) => ({
165-
disabled,
166-
canSelect: (key: string) =>
167-
(key !== " " || !teams.blocksSpace) &&
168-
model.canSelect(recipient.pubkey, key === " "),
169-
id: recipient.pubkey,
170-
label,
171-
detail:
212+
({ recipient, label, elsewhere, disabled, fullName, agent }) => {
213+
const detail =
172214
disabled ??
173215
// A verified full name sits beside the detail.
174-
[
216+
([
175217
fullName !== label ? fullName : undefined,
218+
model.managedBy.get(recipient.pubkey),
176219
memberKeys.has(recipient.pubkey)
177-
? recipient.pubkey
220+
? undefined
178221
: inviteAgents
179-
? `${parentAdmission ? "Adds to channel" : "Adds to chat"} · ${recipient.pubkey}`
222+
? parentAdmission
223+
? "Adds to channel"
224+
: "Adds to chat"
180225
: outsideMentionDetail(channel, elsewhere),
181226
]
182227
.filter(Boolean)
183-
.join(" · "),
184-
preview: (
185-
<Avatar
186-
alt=""
187-
fallback={label}
188-
src={avatarMedia(
189-
profiles.get(recipient.pubkey)?.picture ??
190-
model.directory.people.find(
191-
(person) => person.pubkey === recipient.pubkey,
192-
)?.picture,
193-
session.media,
194-
)}
195-
size="default"
196-
shape={agentKeys.has(recipient.pubkey) ? "squircle" : "circle"}
197-
/>
198-
),
199-
edit: { mention: recipient },
200-
}),
228+
.join(" · ") ||
229+
undefined);
230+
return {
231+
disabled,
232+
canSelect: (key: string) =>
233+
(key !== " " || !teams.blocksSpace) &&
234+
model.canSelect(recipient.pubkey, key === " "),
235+
id: recipient.pubkey,
236+
label,
237+
agent,
238+
...(detail ? { detail } : {}),
239+
preview: (
240+
<Avatar
241+
alt=""
242+
fallback={label}
243+
src={avatarMedia(
244+
profiles.get(recipient.pubkey)?.picture ??
245+
model.directory.people.find(
246+
(person) => person.pubkey === recipient.pubkey,
247+
)?.picture,
248+
session.media,
249+
)}
250+
size="default"
251+
shape={agent ? "squircle" : "circle"}
252+
/>
253+
),
254+
edit: { mention: recipient },
255+
};
256+
},
201257
),
202258
...matchingTeams.map((team) => ({
203259
id: team.id,
@@ -295,22 +351,18 @@ export function MentionCompletion({
295351
? { status: "Channel membership unavailable." }
296352
: admitted && membershipError
297353
? { status: "Could not refresh channel membership." }
298-
: error || missing
354+
: // Only a failed read: a member who never set a name is
355+
// a complete answer, not an error.
356+
error
299357
? {
300358
status:
301-
"Some names unavailable. Exact public keys still identify recipients.",
359+
"Could not load some names. Retry to refresh.",
302360
}
303361
: model.directory.loading
304362
? { status: "Searching community…" }
305-
: model.directory.more ||
306-
model.truncated ||
307-
matching.length + matchingTeams.length > 50
308-
? {
309-
status: "Narrow your search to see more members.",
310-
}
311-
: teams.status
312-
? { status: teams.status }
313-
: {}),
363+
: teams.status
364+
? { status: teams.status }
365+
: {}),
314366
...((admitted && teams.canRetry) ||
315367
model.directory.error ||
316368
(admitted &&
@@ -319,8 +371,7 @@ export function MentionCompletion({
319371
agents.error ||
320372
membershipMissing ||
321373
membershipError ||
322-
error ||
323-
missing))
374+
error))
324375
? {
325376
retry: () => {
326377
teams.retry();
@@ -329,7 +380,6 @@ export function MentionCompletion({
329380
!!inviteAgents || teams.includeLegacy,
330381
);
331382
void session.archives?.refresh();
332-
setError(false);
333383
retry((value) => value + 1);
334384
if (membershipMissing || membershipError)
335385
session.channels.refreshList?.();

‎src/bundled/mentions/MentionPicker.tsx‎

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {
1515
AtIcon,
1616
CaretDownIcon,
1717
CheckIcon,
18+
RobotIcon,
1819
} from "../../shared/design-system/icons/index";
1920
import { useEffect, useId, useRef, useState } from "react";
2021
import { useTeamMentions } from "./use-team-mentions";
@@ -390,6 +391,7 @@ export function MentionPicker({
390391
disabled: reason,
391392
fullName,
392393
}) => {
394+
const managedBy = model.managedBy.get(recipient.pubkey);
393395
// Each addressed agent's row shows a check; fill is only
394396
// the keyboard and pointer highlight.
395397
const addressed = !!audience?.recipients.some(
@@ -400,15 +402,15 @@ export function MentionPicker({
400402
return (
401403
<NavigationItem
402404
variant="option"
403-
data-mention-choice=""
405+
// The exact key the row picks; its label may not show it.
406+
data-mention-choice={recipient.pubkey}
404407
type="button"
405408
key={recipient.pubkey}
406409
{...highlight.rowProps(personKey(recipient.pubkey))}
407410
selected={audience ? false : focused}
408411
highlighted={audience ? focused : false}
409412
aria-current={false}
410413
aria-pressed={audience ? addressed : undefined}
411-
aria-label={`${label} ${recipient.pubkey}`}
412414
disabled={disabled || !!reason}
413415
onClick={() => chooseRecipient(recipient)}
414416
label={
@@ -420,14 +422,25 @@ export function MentionPicker({
420422
label={label}
421423
positions={matched(label)}
422424
/>
425+
{agent && (
426+
<span
427+
aria-hidden="true"
428+
className={styles.agentMark}
429+
>
430+
<RobotIcon />
431+
</span>
432+
)}
433+
{agent && <span className="sr-only"> Agent</span>}
423434
</span>
424435
{reason && <small>{reason}</small>}
425436
{((fullName && fullName !== label) ||
437+
managedBy ||
426438
!members?.includes(recipient.pubkey)) && (
427439
<small className="text-caption text-subtle">
428440
{/* A verified full name sits beside the detail. */}
429441
{[
430442
fullName !== label ? fullName : undefined,
443+
managedBy,
431444
members?.includes(recipient.pubkey)
432445
? undefined
433446
: inviteAgents
@@ -442,14 +455,8 @@ export function MentionPicker({
442455
)}
443456
</span>
444457
}
445-
title={recipient.pubkey}
446458
trailing={
447-
<span className="flex items-center gap-2">
448-
<code>{recipient.pubkey.slice(0, 12)}</code>
449-
{addressed && (
450-
<CheckIcon size={16} aria-hidden="true" />
451-
)}
452-
</span>
459+
addressed && <CheckIcon size={16} aria-hidden="true" />
453460
}
454461
icon={
455462
<Avatar
@@ -505,9 +512,6 @@ export function MentionPicker({
505512
onClick={() => chooseTeam(team)}
506513
/>
507514
))}
508-
{model.truncated && (
509-
<p>Narrow your search to see more members.</p>
510-
)}
511515
{members && !candidates.length && !teams.choices.length && (
512516
<p>No matching channel members.</p>
513517
)}

‎src/bundled/mentions/Mentions.module.css‎

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,6 @@
3131
display: grid;
3232
gap: var(--space-1);
3333
}
34-
.mentionChoices code {
35-
font-size: var(--text-caption);
36-
line-height: var(--text-caption--line-height);
37-
letter-spacing: var(--text-caption--letter-spacing);
38-
overflow-wrap: anywhere;
39-
}
4034
.mentionContent p {
4135
color: var(--text-subtle);
4236
}
@@ -46,3 +40,11 @@
4640
margin: 0;
4741
min-width: 0;
4842
}
43+
/* Inside the name, so the row keeps one text baseline (as message bylines). */
44+
.agentMark {
45+
display: inline-block;
46+
width: 1em;
47+
height: 1em;
48+
margin-inline-start: var(--space-1);
49+
vertical-align: -0.125em;
50+
}

0 commit comments

Comments
 (0)