diff --git a/src/main/services/infrastructure/LocalFileSystemProvider.ts b/src/main/services/infrastructure/LocalFileSystemProvider.ts index 9d7ee499..ceb5a3fb 100644 --- a/src/main/services/infrastructure/LocalFileSystemProvider.ts +++ b/src/main/services/infrastructure/LocalFileSystemProvider.ts @@ -43,11 +43,25 @@ export class LocalFileSystemProvider implements FileSystemProvider { async readdir(dirPath: string): Promise { const entries = await fs.promises.readdir(dirPath, { withFileTypes: true }); - return entries.map((entry) => ({ - name: entry.name, - isFile: () => entry.isFile(), - isDirectory: () => entry.isDirectory(), - })); + // Stat all entries concurrently to populate mtimeMs, used by SessionSearcher's + // mtime-based cache invalidation. Failures are silently ignored (mtimeMs stays undefined). + return Promise.all( + entries.map(async (entry) => { + let mtimeMs: number | undefined; + try { + const stat = await fs.promises.stat(`${dirPath}/${entry.name}`); + mtimeMs = stat.mtimeMs; + } catch { + // ignore + } + return { + name: entry.name, + mtimeMs, + isFile: () => entry.isFile(), + isDirectory: () => entry.isDirectory(), + }; + }) + ); } createReadStream(filePath: string, opts?: ReadStreamOptions): fs.ReadStream { diff --git a/src/renderer/store/slices/sessionDetailSlice.ts b/src/renderer/store/slices/sessionDetailSlice.ts index 7eb2dd8c..9a158f49 100644 --- a/src/renderer/store/slices/sessionDetailSlice.ts +++ b/src/renderer/store/slices/sessionDetailSlice.ts @@ -197,16 +197,19 @@ export const createSessionDetailSlice: StateCreator | null = null; let contextStats: Map | null = null; let phaseInfo: ContextPhaseInfo | null = null; - // Fetch agent configs from .claude/agents/ (only when project changes) + // Fetch agent configs from .claude/agents/ (only when project changes). + // Fire-and-forget: don't block transcript rendering — color badges update async. if (connectionMode !== 'ssh' && projectRoot && projectRoot !== agentConfigsCachedForProject) { - try { - const configs = await api.readAgentConfigs(projectRoot); - if (requestGeneration !== sessionDetailFetchGeneration) return; - agentConfigsCachedForProject = projectRoot; - set({ agentConfigs: configs }); - } catch (err) { - logger.error('Failed to read agent configs:', err); - } + agentConfigsCachedForProject = projectRoot; // Optimistic set to prevent duplicate fetches + api + .readAgentConfigs(projectRoot) + .then((configs) => { + set({ agentConfigs: configs }); + }) + .catch((err) => { + logger.error('Failed to read agent configs:', err); + agentConfigsCachedForProject = ''; // Reset so it retries next time + }); } if (connectionMode !== 'ssh' && conversation?.items) {