Skip to content

Commit 4afef86

Browse files
loganjLarry
andauthored
fix(desktop): restore mention chip identity icons (#7338)
## Summary Restore the missing **@ glyph for people and robot icon for agents** after #7133, and incorporate the requested compact public-key display. - Wrapping mention chips render their existing bounded icon-bearing leading fragment. - Readonly chips show bound keys using the same `8 leading…4 trailing` formatter as the channel member list: `Scout (150b20bd…15dc)`. - Full literal labels and exact keys remain authoritative in metadata, profile targets, title/accessible-name attributes, editor text, saved bodies and recipient tags. Display abbreviations are never used for recipient lookup. - Copy/paste restores the full literal label for a complete compact chip; partial selections remain plain text. Two keys sharing the same abbreviation still round-trip to their separate exact recipients. - No recipient-resolution, authorization, wire-format, composer, or CSS changes. Existing labels, icons, cloud markers and ordinary mentions remain intact. ## Verification Published candidate `9365ab9bc9d9c5d10802580cd576f8e378ff492f`, based on main `e09f715c9d0ee2cb7bf8a39061e601f3a502f588`: - **6,444 desktop unit tests passed** on this candidate's final source tree. - **44 mock-Chromium tests passed, zero retries in the final run** across mention recipients, clipboard and cloud provenance: exact recipient selection, ambiguity rejection, send/edit/reopen, forwarding, full/partial copy, mismatched-key rejection, matching-abbreviation collisions and 100%/150% narrow-window geometry. - TypeScript, desktop Biome/check guards, protected-feature production build and E2E build passed. - The compact-renderer regression fails with the formatting call removed. Original missing-icon and hidden-text accessibility regressions have red/green evidence. - Fresh self-review traced rendering, full-key metadata, copy classifier, paste normalization and identity trust. The same display formatter owns the accepted compact form on both clipboard sides. Iteration exposed an existing team-insertion separator flake (passed final full run) and two new fixture assumptions: non-member sends require invitation, and Chromium rich paste may retain an NBSP separator. Tests now exercise invitation and normalize only that separator when comparing the captured full body and exact tags; no product change was needed for either. Earlier local repository-wide `just ci` completed in two invocations because its initial call hit the ten-minute tool limit during Tauri compilation. Unchanged native/mobile/backend evidence is reused; the desktop delta received the full checks above and new remote CI. Native VoiceOver, real Tauri selection, dark theme and non-Chromium observation were not performed. Browser artifacts exercise real frontend with mocked Tauri/relay boundaries, not an installed release. ## Review and visual evidence Current-head CI and automated review must complete after this update; the old `2997bfb5` green results do not establish this new head. Required human review remains separate from agent approvals. No merge/install/restart authorization. Before/after icon evidence: #7338 (comment) Updated compact-key screenshots are posted below. The editor intentionally retains the full literal address; only readonly chip display is abbreviated. Origin: buzz://message?channel=3355d33a-b72a-423a-b064-a58275f9a8af&id=38b3a27e689f5a9604e273d45f4e3122fceba76081e7bcd3bbdbf439524a5a18 --------- Signed-off-by: Logan Johnson <[email protected]> Co-authored-by: Larry <627498bd4bd1f281a16431e3c6cce3b5c25b6692798c78672298aefbf2f8f8b5@buzz.block.builderlab.xyz>
1 parent 5d10783 commit 4afef86

15 files changed

Lines changed: 448 additions & 21 deletions

‎desktop/src/features/messages/lib/mentionClipboard.test.mjs‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,3 +440,25 @@ test("does not treat an uncapped label's ellipsis as a truncation", () => {
440440
// whole must not gain a second accepted form.
441441
assert.equal(matchChipTextToLabel("John…", "John Smith", "@"), "fragment");
442442
});
443+
444+
test("whole compact mention labels are restored only for their declared exact key", () => {
445+
const key = `150b20bd${"a".repeat(52)}15dc`;
446+
const label = `Scout (${key}) 2`;
447+
const compact = "Scout (150b20bd…15dc) 2";
448+
assert.equal(matchChipTextToLabel(compact, label, "@", key), "truncated");
449+
assert.equal(
450+
matchChipTextToLabel(`@${compact}`, label, "@", key),
451+
"truncated",
452+
);
453+
assert.equal(matchChipTextToLabel(compact, label, "@"), "fragment");
454+
assert.equal(
455+
matchChipTextToLabel(compact, label, "@", "b".repeat(64)),
456+
"fragment",
457+
);
458+
assert.equal(matchChipTextToLabel(compact, label, "#", key), "fragment");
459+
assert.equal(
460+
matchChipTextToLabel("Scout (150b20bd…15dc)", label, "@", key),
461+
"fragment",
462+
);
463+
assert.equal(matchChipTextToLabel("Scout", label, "@", key), "fragment");
464+
});

‎desktop/src/features/messages/lib/mentionClipboard.ts‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { formatMentionDisplayLabel } from "@/shared/lib/mentionDisplay";
12
import { truncateInlineChipLabel } from "@/shared/ui/mentionChip";
23

34
import { getMentionOffsets } from "./hasMention";
@@ -77,6 +78,7 @@ export function matchChipTextToLabel(
7778
text: string,
7879
label: string,
7980
sigil: "@" | "#",
81+
pubkey?: string,
8082
): ChipTextMatch {
8183
const body = canonicalMentionLabel(text);
8284
const matches = (form: string) => body === form || body === `${sigil}${form}`;
@@ -87,6 +89,13 @@ export function matchChipTextToLabel(
8789
if (truncated !== label && matches(canonicalMentionLabel(truncated))) {
8890
return "truncated";
8991
}
92+
// Read-only mentions abbreviate a bound key, never the identity carried by
93+
// the clipboard. Restore the full literal label only for the whole display.
94+
const compact =
95+
sigil === "@" ? formatMentionDisplayLabel(label, pubkey) : label;
96+
if (compact !== label && matches(canonicalMentionLabel(compact))) {
97+
return "truncated";
98+
}
9099
return "fragment";
91100
}
92101

‎desktop/src/features/messages/lib/normalizeMentionClipboard.test.mjs‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,3 +265,19 @@ test("an ordinary chip still flattens to a registrable mention", () => {
265265
[JOHN_SMITH_PUBKEY],
266266
);
267267
});
268+
269+
test("compact mention paste expands only complete bound labels", () => {
270+
const key = `150b20bd${"a".repeat(52)}15dc`;
271+
const label = `Scout (${key}) 2`;
272+
const html = (text) =>
273+
`<span data-mention="" data-mention-pubkey="${key}" ` +
274+
`data-mention-label="${label}">${text}</span>`;
275+
assert.equal(
276+
normalizeMentionClipboardContent(html("Scout (150b20bd…15dc) 2")).text,
277+
`@${label}`,
278+
);
279+
assert.equal(
280+
normalizeMentionClipboardContent(html("Scout (150b20bd…15dc)")).text,
281+
"Scout (150b20bd…15dc)",
282+
);
283+
});

‎desktop/src/features/messages/lib/normalizeMentionClipboard.ts‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import {
22
CHANNEL_LABEL_ATTRIBUTE,
33
matchChipTextToLabel,
44
MENTION_LABEL_ATTRIBUTE,
5+
MENTION_PUBKEY_ATTRIBUTE,
56
} from "./mentionClipboard";
67

78
/**
@@ -173,7 +174,14 @@ export function normalizeMentionClipboardContent(
173174
// from the same attribute the records carry keeps the two provably
174175
// consistent, whatever the classifier goes on to tolerate.
175176
const match =
176-
label === null ? "full" : matchChipTextToLabel(text, label, sigil);
177+
label === null
178+
? "full"
179+
: matchChipTextToLabel(
180+
text,
181+
label,
182+
sigil,
183+
el.getAttribute(MENTION_PUBKEY_ATTRIBUTE) ?? undefined,
184+
);
177185
span.textContent =
178186
match === "fragment"
179187
? text

‎desktop/src/features/messages/lib/timelineMentionCopy.test.mjs‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,3 +187,18 @@ test("copy inlines a blockified chip but preserves its block ancestor", () => {
187187
else delete prototype.innerText;
188188
}
189189
});
190+
191+
test("copy expands compact key text but preserves the exact label and identity", () => {
192+
const label = `Scout (${JOHN_SMITH_PUBKEY}) 2`;
193+
const flavors = copyRenderedBody(
194+
`<span data-mention="" data-mention-pubkey="${JOHN_SMITH_PUBKEY}" ` +
195+
`data-mention-label="${label}" class="mention-chip">` +
196+
'<span class="inline-chip-leading-fragment">Scout</span> (7c7c7c7c…7c7c) 2</span>',
197+
);
198+
assert.ok(flavors);
199+
assert.ok(flavors.html.includes(`@${label}`));
200+
assert.ok(
201+
flavors.html.includes(`data-mention-pubkey="${JOHN_SMITH_PUBKEY}"`),
202+
);
203+
assert.ok(!flavors.html.includes("…"));
204+
});

‎desktop/src/features/messages/lib/timelineMentionCopy.ts‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,12 @@ function restoreChipSigils(root: HTMLElement): boolean {
5050
const label = element.getAttribute(MENTION_LABEL_ATTRIBUTE);
5151
if (
5252
label &&
53-
matchChipTextToLabel(element.textContent ?? "", label, "@") !== "fragment"
53+
matchChipTextToLabel(
54+
element.textContent ?? "",
55+
label,
56+
"@",
57+
element.getAttribute(MENTION_PUBKEY_ATTRIBUTE) ?? undefined,
58+
) !== "fragment"
5459
) {
5560
element.textContent = `@${label}`;
5661
restored = true;
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import assert from "node:assert/strict";
2+
import test from "node:test";
3+
import { formatMentionDisplayLabel } from "./mentionDisplay.ts";
4+
import { truncatePubkey } from "./pubkey.ts";
5+
6+
const KEY = `150b20bd${"a".repeat(52)}15dc`;
7+
8+
test("compact mention display uses the member-list formatter and keeps collision suffixes", () => {
9+
for (const suffix of ["", " 2", " 10"]) {
10+
assert.equal(
11+
formatMentionDisplayLabel(`Bad Janet (${KEY})${suffix}`, KEY),
12+
`Bad Janet (${truncatePubkey(KEY)})${suffix}`,
13+
);
14+
}
15+
assert.equal(formatMentionDisplayLabel(KEY, KEY), truncatePubkey(KEY));
16+
assert.equal(
17+
formatMentionDisplayLabel(KEY.toUpperCase(), KEY),
18+
truncatePubkey(KEY.toUpperCase()),
19+
);
20+
});
21+
22+
test("display leaves unbound, mismatched, malformed and ordinary labels literal", () => {
23+
for (const [label, key] of [
24+
[`Bad Janet (${KEY})`, undefined],
25+
[`Bad Janet (${KEY})`, "b".repeat(64)],
26+
[`Bad Janet (${KEY})`, "bad-key"],
27+
[`Bad Janet (${KEY}) 1`, KEY],
28+
[`Bad Janet (${KEY}) notes`, KEY],
29+
[`Release ${KEY}`, KEY],
30+
["Bad Janet", KEY],
31+
])
32+
assert.equal(formatMentionDisplayLabel(label, key), label);
33+
});
34+
35+
test("matching compact keys do not become identity keys", () => {
36+
const other = KEY.replace("aaaa", "bbbb");
37+
assert.notEqual(KEY, other);
38+
assert.equal(
39+
formatMentionDisplayLabel(`Scout (${KEY})`, KEY),
40+
formatMentionDisplayLabel(`Scout (${other})`, other),
41+
);
42+
assert.equal(
43+
formatMentionDisplayLabel(`Scout (${KEY})`, other),
44+
`Scout (${KEY})`,
45+
);
46+
});
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { truncatePubkey } from "./pubkey";
2+
3+
/** Compact only a bound mention's key; its literal label remains authoritative. */
4+
export function formatMentionDisplayLabel(
5+
label: string,
6+
pubkey: string | undefined,
7+
): string {
8+
if (!pubkey || !/^[0-9a-f]{64}$/i.test(pubkey)) return label;
9+
if (label.toLowerCase() === pubkey.toLowerCase()) {
10+
return truncatePubkey(label);
11+
}
12+
const qualified = label.match(
13+
/^(.*) \(([0-9a-f]{64})\)((?: (?:[2-9]|[1-9][0-9]+))?)$/i,
14+
);
15+
if (qualified?.[2].toLowerCase() !== pubkey.toLowerCase()) return label;
16+
return `${qualified[1]} (${truncatePubkey(qualified[2])})${qualified[3]}`;
17+
}

‎desktop/src/shared/ui/markdown.test.mjs‎

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1400,7 +1400,12 @@ test("resolved human mentions replace the authored at-sign with the shared icon"
14001400
);
14011401

14021402
assert.match(html, /data-mention=""/);
1403-
assert.match(html, /inline-chip-icon-human/);
1403+
assert.match(
1404+
html,
1405+
/inline-chip-leading-fragment[^>]*inline-chip-icon-human[^>]*>alice<\/span>/,
1406+
);
1407+
assert.match(html, /aria-label="alice"/);
1408+
assert.doesNotMatch(html, /aria-hidden="true"[^>]*>alice</);
14041409
assert.match(html, />alice</);
14051410
assert.doesNotMatch(html, />@alice</);
14061411
});
@@ -1432,7 +1437,12 @@ test("agent mentions retain the bot treatment instead of the human icon", () =>
14321437

14331438
assert.match(html, /data-mention=""/);
14341439
assert.match(html, /agent-mention-highlight/);
1435-
assert.match(html, /inline-chip-icon-agent/);
1440+
assert.match(
1441+
html,
1442+
/inline-chip-leading-fragment[^>]*inline-chip-icon-agent[^>]*>alice<\/span>/,
1443+
);
1444+
assert.match(html, /aria-label="alice"/);
1445+
assert.doesNotMatch(html, /aria-hidden="true"[^>]*>alice</);
14361446
assert.match(html, />alice</);
14371447
assert.doesNotMatch(html, />@alice</);
14381448
});

‎desktop/src/shared/ui/markdown/MarkdownMention.tsx‎

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,12 @@ import type * as React from "react";
22
import { AgentManagementMarker } from "@/features/agents/ui/OtherSetupAgentMarker";
33
import { UserProfilePopover } from "@/features/profile/ui/UserProfilePopover";
44
import { cn } from "@/shared/lib/cn";
5-
import { WRAPPING_INLINE_CHIP_CLASSES } from "@/shared/ui/mentionChip";
5+
import { formatMentionDisplayLabel } from "@/shared/lib/mentionDisplay";
6+
import {
7+
inlineChipIconClasses,
8+
inlineChipLeadingEnd,
9+
WRAPPING_INLINE_CHIP_CLASSES,
10+
} from "@/shared/ui/mentionChip";
611
import { InlineChip } from "@/shared/ui/InlineChip";
712
import { useMarkdownRuntime } from "./runtimeContext";
813

@@ -28,6 +33,9 @@ export function createMarkdownMention(interactive: boolean) {
2833
pubkey !== undefined &&
2934
agentMentionPubkeysByName?.[mentionName] === pubkey;
3035
const mentionLabel = mentionText.replace(/^@/, "");
36+
const displayLabel = formatMentionDisplayLabel(mentionLabel, pubkey);
37+
const icon = isAgentMention ? "agent" : "human";
38+
const leadingEnd = inlineChipLeadingEnd(displayLabel);
3139
// Only chips that actually open a profile get the clickable affordance.
3240
// A mention whose pubkey didn't resolve stays a plain chip — a pointer
3341
// cursor there promises a click that does nothing.
@@ -46,10 +54,19 @@ export function createMarkdownMention(interactive: boolean) {
4654
)}
4755
title={mentionLabel}
4856
aria-label={mentionLabel}
49-
icon={isAgentMention ? "agent" : "human"}
57+
icon={icon}
5058
interactive={opensProfile}
5159
>
52-
{mentionLabel}
60+
{/* Wrapping chips hide the outer icon; keep it with a bounded prefix. */}
61+
<span
62+
className={cn(
63+
"inline-chip-leading-fragment",
64+
inlineChipIconClasses(icon),
65+
)}
66+
>
67+
{displayLabel.slice(0, leadingEnd)}
68+
</span>
69+
{displayLabel.slice(leadingEnd)}
5370
{isAgentMention ? <AgentManagementMarker pubkey={pubkey} /> : null}
5471
</InlineChip>
5572
);

0 commit comments

Comments
 (0)