The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(desktop): dedupe profile mention completions
zhongwater123ed2d01a3c38d
diff --git a/apps/desktop/src/app/chat/composer/hooks/use-at-completions-contrib.test.tsx b/apps/desktop/src/app/chat/composer/hooks/use-at-completions-contrib.test.tsxindex 85ec5d6023e..d1eeda85655 100644--- a/apps/desktop/src/app/chat/composer/hooks/use-at-completions-contrib.test.tsx+++ b/apps/desktop/src/app/chat/composer/hooks/use-at-completions-contrib.test.tsx@@ -25,11 +25,9 @@ function addSource(id: string, provide: ComposerAtCompletionSource['provide']) {)}-function gatewayStub() {+function gatewayStub(items = [{ text: '@file:src/research-notes.md', display: 'research-notes.md', meta: 'file' }]) {return {- request: vi.fn(async () => ({- items: [{ text: '@file:src/research-notes.md', display: 'research-notes.md', meta: 'file' }]- }))+ request: vi.fn(async () => ({ items }))}}@@ -75,6 +73,24 @@ describe('contributed @ completion sources', () => {expect(rows.some(l => l.includes('research-notes.md'))).toBe(true)})+ it('deduplicates contributed and core profile handles without collapsing distinct references', async () => {+ vi.useFakeTimers()+ addSource('bots', q => ('researcher'.startsWith(q) ? [{ insert: '@Researcher', meta: 'Bot · Researcher' }] : []))++ const gateway = gatewayStub([+ { text: '@researcher', display: '@researcher', meta: 'Research and intelligence analyst' },+ { text: '@researcher-homelab', display: '@researcher-homelab', meta: 'agent profile' },+ { text: '@file:src/researcher.md', display: 'researcher.md', meta: 'file' }+ ])++ const { result } = renderHook(() => useAtCompletions({ gateway: gateway as never, sessionId: 's1', cwd: '/repo' }))++ const rows = await searchAndRead(result, 'rese')+ expect(rows.filter(label => label.toLowerCase() === '@researcher')).toEqual(['@Researcher'])+ expect(rows).toContain('@researcher-homelab')+ expect(rows.some(label => label.includes('researcher.md'))).toBe(true)+ })+it('drops rows when the query does not match the source filter', async () => {vi.useFakeTimers()addSource('bots', q => ('researcher'.startsWith(q) ? [{ insert: '@researcher', meta: 'Bot' }] : []))diff --git a/apps/desktop/src/app/chat/composer/hooks/use-at-completions.ts b/apps/desktop/src/app/chat/composer/hooks/use-at-completions.tsindex 33bc2f3c87f..1dc481e818e 100644--- a/apps/desktop/src/app/chat/composer/hooks/use-at-completions.ts+++ b/apps/desktop/src/app/chat/composer/hooks/use-at-completions.ts@@ -15,6 +15,8 @@ import { useLiveCompletionAdapter } from './use-live-completion-adapter'const KIND_RE = /^@(file|folder|url|image|tool|git):(.*)$/const REF_STARTERS = new Set(['file', 'folder', 'url', 'image', 'tool', 'git'])+// These bare tokens are context actions, not profile handles.+const SIMPLE_CONTEXT_REFS = new Set(['@diff', '@staged'])const STARTER_META: Record<string, string> = {file: 'Attach a file reference',@@ -37,6 +39,26 @@ function starterEntries(query: string): CompletionEntry[] {}))}+function mergeCompletionEntries(preferred: CompletionEntry[], fallback: CompletionEntry[]): CompletionEntry[] {+ const seenHandles = new Set<string>()++ return [...preferred, ...fallback].filter(entry => {+ const key = normalize(entry.text)++ if (!/^@[^:\s]+$/.test(key) || SIMPLE_CONTEXT_REFS.has(key)) {+ return true+ }++ if (seenHandles.has(key)) {+ return false+ }++ seenHandles.add(key)++ return true+ })+}+interface AtItemMetadata extends Record<string, string> {icon: stringdisplay: string@@ -147,7 +169,7 @@ export function useAtCompletions(options: {const extras = contributedEntries(query)if (!gateway) {- return { items: [...extras, ...starters], query }+ return { items: mergeCompletionEntries(extras, starters), query }}const word = REF_STARTERS.has(query) ? `@${query}:` : `@${query}`@@ -174,9 +196,9 @@ export function useAtCompletions(options: {const items = result.items ?? []const base = items.length > 0 ? items : starters- return { items: [...extras, ...base], query }+ return { items: mergeCompletionEntries(extras, base), query }} catch {- return { items: [...extras, ...starters], query }+ return { items: mergeCompletionEntries(extras, starters), query }}},[cacheKey, contributedEntries, gateway, sessionId, cwd]