Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions server/projects.js
Original file line number Diff line number Diff line change
Expand Up @@ -2538,6 +2538,44 @@ async function getGeminiCliSessionMessages(sessionId) {
return [];
}

async function deleteGeminiCliSession(sessionId) {
const geminiTmpDir = path.join(os.homedir(), '.gemini', 'tmp');
let projectDirs;
try {
projectDirs = await fs.readdir(geminiTmpDir);
} catch {
throw new Error(`Gemini CLI session not found: ${sessionId}`);
}

for (const projectDir of projectDirs) {
const chatsDir = path.join(geminiTmpDir, projectDir, 'chats');
let chatFiles;
try {
chatFiles = await fs.readdir(chatsDir);
} catch {
continue;
}

for (const chatFile of chatFiles) {
if (!chatFile.endsWith('.json')) continue;
try {
const filePath = path.join(chatsDir, chatFile);
const data = await fs.readFile(filePath, 'utf8');
const session = JSON.parse(data);
const fileSessionId = session.sessionId || chatFile.replace('.json', '');
if (fileSessionId === sessionId) {
await fs.unlink(filePath);
return true;
}
} catch {
continue;
}
}
}

throw new Error(`Gemini CLI session file not found: ${sessionId}`);
}

export {
getProjects,
getSessions,
Expand All @@ -2557,5 +2595,6 @@ export {
deleteCodexSession,
getGeminiCliSessions,
getGeminiCliSessionMessages,
deleteGeminiCliSession,
searchConversations
};
14 changes: 13 additions & 1 deletion server/routes/gemini.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import express from 'express';
import sessionManager from '../sessionManager.js';
import { sessionNamesDb } from '../database/db.js';
import { deleteGeminiCliSession } from '../projects.js';

const router = express.Router();

Expand All @@ -12,7 +13,18 @@ router.delete('/sessions/:sessionId', async (req, res) => {
return res.status(400).json({ success: false, error: 'Invalid session ID format' });
}

await sessionManager.deleteSession(sessionId);
// Try deleting from UI sessions and CLI sessions
let deleted = false;
try {
await sessionManager.deleteSession(sessionId);
deleted = true;
} catch { }

try {
await deleteGeminiCliSession(sessionId);
deleted = true;
} catch { }

sessionNamesDb.deleteName(sessionId, 'gemini');
res.json({ success: true });
} catch (error) {
Expand Down
2 changes: 2 additions & 0 deletions src/hooks/useProjectsState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,8 @@ export function useProjectsState({
prevProjects.map((project) => ({
...project,
sessions: project.sessions?.filter((session) => session.id !== sessionIdToDelete) ?? [],
codexSessions: project.codexSessions?.filter((session) => session.id !== sessionIdToDelete) ?? [],
geminiSessions: project.geminiSessions?.filter((session) => session.id !== sessionIdToDelete) ?? [],
sessionMeta: {
...project.sessionMeta,
total: Math.max(0, (project.sessionMeta?.total as number | undefined ?? 0) - 1),
Expand Down