From 5459da5f9d7158bff8515fd69aeff315da92902c Mon Sep 17 00:00:00 2001 From: Ark0N Date: Sat, 6 Jun 2026 04:06:29 +0200 Subject: [PATCH] fix(state-store): scope legacy ~/.claudeman migration to the default instance MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The instance-isolation sweep routed every ~/.codeman write through dataPath() except the legacy ~/.claudeman → ~/.codeman migration in the StateStore constructor, which stayed hardcoded. Gate the whole legacy block on the default (prod) instance so a named instance (e.g. CODEMAN_INSTANCE=beta) never reads or renames into the shared ~/.codeman / ~/codeman-cases layout. Prod behavior is unchanged (CODEMAN_INSTANCE empty → migration still runs). Note: swapping newDir to getDataDir() was rejected — its mkdirSync side-effect would make !existsSync(newDir) false and silently disable the migration. Co-Authored-By: Claude Opus 4.8 (1M context) --- src/state-store.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/state-store.ts b/src/state-store.ts index faad0710..ffab99f4 100644 --- a/src/state-store.ts +++ b/src/state-store.ts @@ -39,7 +39,7 @@ import { TokenUsageEntry, } from './types.js'; import { Debouncer, MAX_SESSION_TOKENS } from './utils/index.js'; -import { dataPath } from './config/instance.js'; +import { dataPath, CODEMAN_INSTANCE } from './config/instance.js'; /** Debounce delay for batching state writes (ms) */ const SAVE_DEBOUNCE_MS = 500; @@ -90,8 +90,10 @@ export class StateStore { private _saveInFlight: Promise | null = null; constructor(filePath?: string) { - // Migrate legacy data directory (~/.claudeman → ~/.codeman) - if (!filePath) { + // Migrate legacy data directory (~/.claudeman → ~/.codeman). Default (prod) + // instance only — a named instance (e.g. beta) must never touch the shared + // ~/.codeman / ~/codeman-cases layout, preserving instance isolation. + if (!filePath && !CODEMAN_INSTANCE) { const legacyDir = join(homedir(), '.claudeman'); const newDir = join(homedir(), '.codeman'); if (existsSync(legacyDir) && !existsSync(newDir)) {