diff --git a/src/main/ai-vault/cached-session-list-scope-only.test.ts b/src/main/ai-vault/cached-session-list-scope-only.test.ts new file mode 100644 index 00000000000..ddcf56df19b --- /dev/null +++ b/src/main/ai-vault/cached-session-list-scope-only.test.ts @@ -0,0 +1,37 @@ +import { afterEach, beforeEach, expect, it, vi } from 'vitest' + +const { scanAiVaultSessionsInService } = vi.hoisted(() => ({ + scanAiVaultSessionsInService: vi.fn() +})) + +vi.mock('./scan-service/session-scanner-service-spawn', async (importOriginal) => ({ + ...(await importOriginal()), + scanAiVaultSessionsInService +})) + +import { listAiVaultSessions, resetAiVaultSessionListCacheForTests } from './cached-session-list' + +beforeEach(() => { + vi.spyOn(process, 'platform', 'get').mockReturnValue('darwin') + resetAiVaultSessionListCacheForTests() + scanAiVaultSessionsInService.mockResolvedValue({ sessions: [], issues: [], scannedAt: 'scan' }) +}) + +afterEach(() => { + resetAiVaultSessionListCacheForTests() + vi.restoreAllMocks() + scanAiVaultSessionsInService.mockReset() +}) + +it('answers a scope-only request from a cached full list for the same paths, never the reverse', async () => { + const scopePaths = ['/repo/app'] + + await listAiVaultSessions({ scopePaths }) + await listAiVaultSessions({ scopePaths, scopeOnly: true }) + expect(scanAiVaultSessionsInService).toHaveBeenCalledTimes(1) + + resetAiVaultSessionListCacheForTests() + await listAiVaultSessions({ scopePaths, scopeOnly: true }) + await listAiVaultSessions({ scopePaths }) + expect(scanAiVaultSessionsInService).toHaveBeenCalledTimes(3) +}) diff --git a/src/main/ai-vault/cached-session-list.ts b/src/main/ai-vault/cached-session-list.ts index 414d4370b4e..9d54fd2554c 100644 --- a/src/main/ai-vault/cached-session-list.ts +++ b/src/main/ai-vault/cached-session-list.ts @@ -145,9 +145,11 @@ export async function listAiVaultSessions( if (args?.force === true) { clearAiVaultBackgroundRestartCircuit() } + // A full list for the same paths holds every row a scope-only one would, so All -> Project needs no rescan. + const fullKey = args?.scopeOnly ? aiVaultLocalScanScopeKey({ ...args, scopeOnly: false }) : key if ( args?.force !== true && - cachedList?.key === key && + (cachedList?.key === key || cachedList?.key === fullKey) && cachedList.expiresAt > now && aiVaultCachedDepthServes(cachedList.depth, depth, args?.scopePaths) ) { diff --git a/src/main/ai-vault/session-scanner-scope-discovery.ts b/src/main/ai-vault/session-scanner-scope-discovery.ts index 617204d642e..ca8e5d9b0e8 100644 --- a/src/main/ai-vault/session-scanner-scope-discovery.ts +++ b/src/main/ai-vault/session-scanner-scope-discovery.ts @@ -77,7 +77,7 @@ export function cwdBucketScopePrefixes( for (const scopePath of scopePaths) { for (const candidate of scopePathCandidates(scopePath)) { for (const prefix of layout.encodeScopePrefixes(candidate)) { - prefixes.add(prefix.toLowerCase()) + prefixes.add(prefix.normalize('NFC').toLowerCase()) } } } @@ -111,11 +111,12 @@ export async function listProjectDirs( recordRefusal(issues, rootDir, err, layout.agent) return [] } - // Case-folded: Windows cwds differ in case, and each bucket's cwd is still checked afterwards. + // Case- and NFC-folded: Windows cwds differ in case, macOS names can be NFD, and each bucket's cwd is still checked. return entries .filter( (entry) => - entry.isDirectory() && layout.isDirInScope(entry.name.toLowerCase(), scopeProjectPrefixes) + entry.isDirectory() && + layout.isDirInScope(entry.name.normalize('NFC').toLowerCase(), scopeProjectPrefixes) ) .map((entry) => join(rootDir, entry.name)) } diff --git a/src/main/ai-vault/session-scanner-scope-only.test.ts b/src/main/ai-vault/session-scanner-scope-only.test.ts index a38a781f8dd..4776a43de7b 100644 --- a/src/main/ai-vault/session-scanner-scope-only.test.ts +++ b/src/main/ai-vault/session-scanner-scope-only.test.ts @@ -149,6 +149,29 @@ describe('scanAiVaultSessions scopeOnly', () => { await expect(workspaceSessionIds(root, scopePaths, { scopeOnly: true })).resolves.toEqual(main) }) + it('matches a CodeBuddy bucket whose name uses the other Unicode form', async () => { + const root = await tempRoot() + const cwd = '/repo/cafe\u0301' + const dir = join(isolatedScanRoots(root).codebuddyProjectsDir, 'repo-cafe\u0301') + await mkdir(dir, { recursive: true }) + await writeFile( + join(dir, 'nfd.jsonl'), + JSON.stringify({ + type: 'message', + timestamp: '2026-06-01T00:00:00.000Z', + sessionId: 'nfd', + cwd, + role: 'user', + content: [{ type: 'input_text', text: 'hi' }] + }) + ) + const scopePaths = [cwd.normalize('NFC')] + + const main = await workspaceSessionIds(root, scopePaths, {}) + expect(main).toEqual(['nfd']) + await expect(workspaceSessionIds(root, scopePaths, { scopeOnly: true })).resolves.toEqual(main) + }) + it('keeps every in-scope session main shows when the scope holds more than the limit', async () => { const root = await tempRoot() const claudeRoot = isolatedScanRoots(root).claudeProjectsDir