diff --git a/packages/core/src/config/config.ts b/packages/core/src/config/config.ts index e4c0fef6eb..50af69f022 100644 --- a/packages/core/src/config/config.ts +++ b/packages/core/src/config/config.ts @@ -1349,6 +1349,7 @@ export class Config implements McpContext { setSessionId(sessionId: string): void { this.sessionId = sessionId; + this.storage.setSessionId(sessionId); } setTerminalBackground(terminalBackground: string | undefined): void { diff --git a/packages/core/src/config/storage.test.ts b/packages/core/src/config/storage.test.ts index 15b49d12f1..06ea04be33 100644 --- a/packages/core/src/config/storage.test.ts +++ b/packages/core/src/config/storage.test.ts @@ -13,6 +13,7 @@ vi.unmock('./storageMigration.js'); import * as os from 'node:os'; import * as path from 'node:path'; import * as fs from 'node:fs'; +import { sessionId as defaultSessionId } from '../utils/session.js'; vi.mock('fs', async (importOriginal) => { const actual = await importOriginal(); @@ -161,10 +162,10 @@ describe('Storage – additional helpers', () => { expect(Storage.getGlobalBinDir()).toBe(expected); }); - it('getProjectTempPlansDir returns ~/.gemini/tmp//plans when no sessionId is provided', async () => { + it('getProjectTempPlansDir returns ~/.gemini/tmp///plans when no sessionId is provided', async () => { await storage.initialize(); const tempDir = storage.getProjectTempDir(); - const expected = path.join(tempDir, 'plans'); + const expected = path.join(tempDir, defaultSessionId, 'plans'); expect(storage.getProjectTempPlansDir()).toBe(expected); }); diff --git a/packages/core/src/config/storage.ts b/packages/core/src/config/storage.ts index 10e88543ba..e903662607 100644 --- a/packages/core/src/config/storage.ts +++ b/packages/core/src/config/storage.ts @@ -16,6 +16,7 @@ import { resolveToRealPath, normalizePath, } from '../utils/paths.js'; +import { sessionId as defaultSessionId } from '../utils/session.js'; import { ProjectRegistry } from './projectRegistry.js'; import { StorageMigration } from './storageMigration.js'; @@ -28,16 +29,20 @@ export const AUTO_SAVED_POLICY_FILENAME = 'auto-saved.toml'; export class Storage { private readonly targetDir: string; - private readonly sessionId: string | undefined; + private sessionId: string; private projectIdentifier: string | undefined; private initPromise: Promise | undefined; private customPlansDir: string | undefined; - constructor(targetDir: string, sessionId?: string) { + constructor(targetDir: string, sessionId: string = defaultSessionId) { this.targetDir = targetDir; this.sessionId = sessionId; } + setSessionId(sessionId: string): void { + this.sessionId = sessionId; + } + setCustomPlansDir(dir: string | undefined): void { this.customPlansDir = dir; } @@ -280,10 +285,7 @@ export class Storage { } getProjectTempPlansDir(): string { - if (this.sessionId) { - return path.join(this.getProjectTempDir(), this.sessionId, 'plans'); - } - return path.join(this.getProjectTempDir(), 'plans'); + return path.join(this.getProjectTempDir(), this.sessionId, 'plans'); } getProjectTempTrackerDir(): string { @@ -311,10 +313,7 @@ export class Storage { } getProjectTempTasksDir(): string { - if (this.sessionId) { - return path.join(this.getProjectTempDir(), this.sessionId, 'tasks'); - } - return path.join(this.getProjectTempDir(), 'tasks'); + return path.join(this.getProjectTempDir(), this.sessionId, 'tasks'); } async listProjectChatFiles(): Promise<