Skip to content

Commit 235907b

Browse files
author
am
committed
fix(mentions): ignore generated agent suffixes on space
exclude synthetic agent suffixes from continuation checks while retaining real aliases and longer names. cover generated suffixes with and without key qualifiers and literal agent names. Signed-off-by: am <6e30cd56c30e030cd31bb0939b94a7c257c9a09d5ba2d92cf2735da45629f248@buzz.block.builderlab.xyz>
1 parent 365b2da commit 235907b

3 files changed

Lines changed: 52 additions & 10 deletions

File tree

‎src/bundled/mentions/README.md‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,8 +185,9 @@ set of choices when all of these are true:
185185
**continues** the query: the normalized name is longer, starts with the
186186
normalized query, and the next code point is not a letter, mark, or digit
187187
(`Jose Luis` and `Jose-Luis` continue `jose`; `Josefa` does not). A label's
188-
key qualifier only tells namesakes apart, so `Honey · 4prr` does not
189-
continue `honey`.
188+
key qualifier or generated `(agent)` suffix only tells namesakes apart, so
189+
`Honey · 4prr` and a generated `Honey (agent)` do not continue `honey`.
190+
A literal name `Honey (agent)` still continues `honey`.
190191

191192
The **local** choices are the ones known without the directory search: the
192193
channel's members and the agents the client offers for mention (section 1, items

‎src/bundled/mentions/mention-ranking.ts‎

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,8 @@ export function rankMentions(
8484
/**
8585
* Space is intent only for one exact key across the full, uncapped choice set.
8686
* Every choice can continue the name; only choices `among` can equal it. A key
87-
* qualifier only tells namesakes apart, so it never continues the name.
87+
* qualifier or generated `(agent)` suffix only tells namesakes apart, so it
88+
* never continues the name.
8889
*/
8990
export const exactMention = (
9091
choices: readonly MentionChoice[],
@@ -96,10 +97,15 @@ export const exactMention = (
9697
(c) => [...c.aliases, c.label],
9798
query,
9899
(c) => c.aliases.length > 0 && among(c),
99-
(c) => [
100-
...c.aliases,
101-
c.qualifier && c.label.endsWith(` · ${c.qualifier}`)
102-
? c.label.slice(0, -(c.qualifier.length + 3))
103-
: c.label,
104-
],
100+
(c) => {
101+
const label =
102+
c.qualifier && c.label.endsWith(` · ${c.qualifier}`)
103+
? c.label.slice(0, -(c.qualifier.length + 3))
104+
: c.label;
105+
// Literal names still block through aliases; generated suffixes do not.
106+
return c.agent &&
107+
c.aliases.some((name) => `${name.trim()} (agent)` === label)
108+
? c.aliases
109+
: [...c.aliases, label];
110+
},
105111
)?.recipient.pubkey;

‎src/bundled/mentions/session-agents.test.tsx‎

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2540,7 +2540,7 @@ it.each([
25402540
},
25412541
);
25422542
type DirectoryPage = {
2543-
people: { pubkey: string; name: string }[];
2543+
people: { pubkey: string; name: string; isAgent?: true }[];
25442544
hasMore: boolean;
25452545
};
25462546
/** Other members map to a profile name, or null for a profile still loading. */
@@ -2693,6 +2693,41 @@ it("Space keeps a member's name when an identically named outside namesake is qu
26932693
h.dispose();
26942694
}
26952695
});
2696+
it.each([
2697+
{ name: "Jose", namesake: false, space: true },
2698+
{ name: "Jose", namesake: true, space: true },
2699+
{ name: "Jose (agent)", namesake: false, space: false },
2700+
])(
2701+
"Space distinguishes an agent qualifier from the real name (%j)",
2702+
async ({ name, namesake, space }) => {
2703+
const h = spaceFixture("Jose");
2704+
try {
2705+
await waitFor(() =>
2706+
expect(h.people).toHaveBeenCalledWith("jose", 1, expect.anything()),
2707+
);
2708+
expect(h.result()?.spaceId).toBe(h.member);
2709+
await h.finish({
2710+
people: [
2711+
{ pubkey: outsideJose, name, isAgent: true },
2712+
...(namesake
2713+
? [{ pubkey: "e".repeat(64), name, isAgent: true as const }]
2714+
: []),
2715+
],
2716+
hasMore: false,
2717+
});
2718+
await waitFor(() =>
2719+
expect(
2720+
h.result()?.items.find((item) => item.id === outsideJose)?.label,
2721+
).toMatch(namesake ? /^Jose \(agent\) · / : /^Jose \(agent\)$/),
2722+
);
2723+
expect(h.result()?.spaceId).toBe(space ? h.member : undefined);
2724+
expect(h.canSpace(h.member)).toBe(space);
2725+
expect(h.canSpace(outsideJose)).toBe(false);
2726+
} finally {
2727+
h.dispose();
2728+
}
2729+
},
2730+
);
26962731
it("Space leaves a member's name as prose once the directory finds a longer outside name", async () => {
26972732
const h = spaceFixture("Jose");
26982733
try {

0 commit comments

Comments
 (0)