diff --git a/apps/frontend/src/main/insights/session-manager.ts b/apps/frontend/src/main/insights/session-manager.ts index a6122a5c..f2a22368 100644 --- a/apps/frontend/src/main/insights/session-manager.ts +++ b/apps/frontend/src/main/insights/session-manager.ts @@ -219,7 +219,7 @@ export class SessionManager { for (const [projectId, cachedSession] of this.sessions) { if (cachedSession.id === sessionId) { cachedSession.modelConfig = modelConfig; - cachedSession.updatedAt = new Date(); + cachedSession.updatedAt = session.updatedAt; this.sessions.set(projectId, cachedSession); break; } diff --git a/apps/frontend/src/main/insights/session-storage.ts b/apps/frontend/src/main/insights/session-storage.ts index c191a331..6da26683 100644 --- a/apps/frontend/src/main/insights/session-storage.ts +++ b/apps/frontend/src/main/insights/session-storage.ts @@ -27,10 +27,10 @@ export class SessionStorage { * Load a specific session from disk */ loadSessionById(projectPath: string, sessionId: string): InsightsSession | null { - const sessionPath = this.paths.getSessionPath(projectPath, sessionId); - if (!existsSync(sessionPath)) return null; - try { + const sessionPath = this.paths.getSessionPath(projectPath, sessionId); + if (!existsSync(sessionPath)) return null; + const content = readFileSync(sessionPath, 'utf-8'); const session = JSON.parse(content) as InsightsSession; // Convert date strings back to Date objects @@ -58,13 +58,18 @@ export class SessionStorage { * Save session to disk */ saveSession(projectPath: string, session: InsightsSession): void { - const sessionsDir = this.paths.getSessionsDir(projectPath); - if (!existsSync(sessionsDir)) { - mkdirSync(sessionsDir, { recursive: true }); - } + try { + const sessionsDir = this.paths.getSessionsDir(projectPath); + if (!existsSync(sessionsDir)) { + mkdirSync(sessionsDir, { recursive: true }); + } - const sessionPath = this.paths.getSessionPath(projectPath, session.id); - writeFileSync(sessionPath, JSON.stringify(session, null, 2), 'utf-8'); + const sessionPath = this.paths.getSessionPath(projectPath, session.id); + writeFileSync(sessionPath, JSON.stringify(session, null, 2), 'utf-8'); + } catch (error) { + console.error(`[SessionStorage] Failed to save session ${session.id}:`, error); + throw error; + } } /** @@ -141,10 +146,10 @@ export class SessionStorage { * Delete a session from disk */ deleteSession(projectPath: string, sessionId: string): boolean { - const sessionPath = this.paths.getSessionPath(projectPath, sessionId); - if (!existsSync(sessionPath)) return false; - try { + const sessionPath = this.paths.getSessionPath(projectPath, sessionId); + if (!existsSync(sessionPath)) return false; + unlinkSync(sessionPath); return true; } catch { diff --git a/apps/frontend/src/renderer/components/ChatHistorySidebar.tsx b/apps/frontend/src/renderer/components/ChatHistorySidebar.tsx index 4e9e1371..4cfa66e4 100644 --- a/apps/frontend/src/renderer/components/ChatHistorySidebar.tsx +++ b/apps/frontend/src/renderer/components/ChatHistorySidebar.tsx @@ -307,8 +307,8 @@ export function ChatHistorySidebar({ onCancelEdit={handleCancelEdit} onEditTitleChange={setEditTitle} onDelete={() => setDeleteSessionId(session.id)} - onArchive={onArchiveSession ? () => onArchiveSession(session.id).catch((e) => console.error('Archive failed:', e)) : undefined} - onUnarchive={onUnarchiveSession ? () => onUnarchiveSession(session.id).catch((e) => console.error('Unarchive failed:', e)) : undefined} + onArchive={onArchiveSession ? () => onArchiveSession(session.id) : undefined} + onUnarchive={onUnarchiveSession ? () => onUnarchiveSession(session.id) : undefined} isArchived={!!session.archivedAt} isSelectionMode={isSelectionMode} isSelected={selectedIds.has(session.id)}