fix(standalone): respect CLAUDE_ROOT for config path

This commit is contained in:
777genius 2026-04-11 09:07:31 +03:00
parent 92dbae84ec
commit f97d9c6e2c
3 changed files with 44 additions and 6 deletions

View file

@ -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, () =>

View file

@ -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<void> {
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();

View file

@ -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')
);
});
});