diff --git a/src/main/services/infrastructure/ConfigManager.ts b/src/main/services/infrastructure/ConfigManager.ts index d12ef4bc..20c7aa6f 100644 --- a/src/main/services/infrastructure/ConfigManager.ts +++ b/src/main/services/infrastructure/ConfigManager.ts @@ -9,7 +9,7 @@ * - Handle JSON parse errors gracefully */ -import { getHomeDir, setClaudeBasePathOverride } from '@main/utils/pathDecoder'; +import { getClaudeBasePath, setClaudeBasePathOverride } from '@main/utils/pathDecoder'; import { validateRegexPattern } from '@main/utils/regexValidation'; import { createLogger } from '@shared/utils/logger'; import * as fs from 'fs'; @@ -23,9 +23,11 @@ import type { SshConnectionProfile } from '@shared/types/api'; const logger = createLogger('Service:ConfigManager'); -const CONFIG_DIR = path.join(getHomeDir(), '.claude'); const CONFIG_FILENAME = 'claude-devtools-config.json'; -const DEFAULT_CONFIG_PATH = path.join(CONFIG_DIR, CONFIG_FILENAME); + +function getDefaultConfigPath(): string { + return path.join(getClaudeBasePath(), CONFIG_FILENAME); +} // =========================================================================== // Types @@ -377,7 +379,7 @@ export class ConfigManager { private triggerManager: TriggerManager; constructor(configPath?: string) { - this.configPath = configPath ?? DEFAULT_CONFIG_PATH; + this.configPath = configPath ?? getDefaultConfigPath(); this.config = this.loadConfig(); setClaudeBasePathOverride(this.config.general.claudeRootPath); this.triggerManager = new TriggerManager(this.config.notifications.triggers, () => diff --git a/src/main/standalone.ts b/src/main/standalone.ts index 13d5ff45..71a56b19 100644 --- a/src/main/standalone.ts +++ b/src/main/standalone.ts @@ -18,15 +18,17 @@ import { createLogger } from '@shared/utils/logger'; -import { HttpServer } from './services/infrastructure/HttpServer'; import { getProjectsBasePath, getTodosBasePath, setClaudeBasePathOverride, } from './utils/pathDecoder'; -import { LocalFileSystemProvider, NotificationManager, ServiceContext } from './services'; +import { LocalFileSystemProvider } from './services/infrastructure/LocalFileSystemProvider'; import type { HttpServices } from './http'; +import type { HttpServer } from './services/infrastructure/HttpServer'; +import type { NotificationManager } from './services/infrastructure/NotificationManager'; +import type { ServiceContext } from './services/infrastructure/ServiceContext'; import type { SshConnectionManager } from './services/infrastructure/SshConnectionManager'; import type { UpdaterService } from './services/infrastructure/UpdaterService'; @@ -99,6 +101,13 @@ async function start(): Promise { logger.info(`Using CLAUDE_ROOT: ${CLAUDE_ROOT}`); } + // Import services after applying CLAUDE_ROOT so ConfigManager picks up the correct base path. + const [{ HttpServer }, { NotificationManager }, { ServiceContext }] = await Promise.all([ + import('./services/infrastructure/HttpServer'), + import('./services/infrastructure/NotificationManager'), + import('./services/infrastructure/ServiceContext'), + ]); + const projectsDir = getProjectsBasePath(); const todosDir = getTodosBasePath(); diff --git a/test/main/services/infrastructure/ConfigManager.claudeRoot.test.ts b/test/main/services/infrastructure/ConfigManager.claudeRoot.test.ts new file mode 100644 index 00000000..0f9f26b7 --- /dev/null +++ b/test/main/services/infrastructure/ConfigManager.claudeRoot.test.ts @@ -0,0 +1,27 @@ +import * as os from 'os'; +import * as path from 'path'; +import { afterEach, describe, expect, it, vi } from 'vitest'; + +describe('ConfigManager CLAUDE_ROOT support', () => { + afterEach(async () => { + vi.resetModules(); + const pathDecoder = await import('../../../../src/main/utils/pathDecoder'); + pathDecoder.setClaudeBasePathOverride(null); + }); + + it('resolves the default config path from the current Claude base path override', async () => { + vi.resetModules(); + + const overrideRoot = path.join(os.tmpdir(), 'claude-root-test'); + const pathDecoder = await import('../../../../src/main/utils/pathDecoder'); + pathDecoder.setClaudeBasePathOverride(overrideRoot); + + const { configManager } = await import( + '../../../../src/main/services/infrastructure/ConfigManager' + ); + + expect(configManager.getConfigPath()).toBe( + path.join(overrideRoot, 'claude-devtools-config.json') + ); + }); +});