diff --git a/src/auth/profile-detector.ts b/src/auth/profile-detector.ts index a3fad69b..bde28265 100644 --- a/src/auth/profile-detector.ts +++ b/src/auth/profile-detector.ts @@ -11,11 +11,11 @@ import * as fs from 'fs'; import * as path from 'path'; -import * as os from 'os'; import { findSimilarStrings, expandPath } from '../utils/helpers'; import { Config, Settings, ProfileMetadata } from '../types'; import { UnifiedConfig, CopilotConfig } from '../config/unified-config-types'; import { loadUnifiedConfig, isUnifiedMode } from '../config/unified-config-loader'; +import { getCcsDir } from '../utils/config-manager'; export type ProfileType = 'settings' | 'account' | 'cliproxy' | 'copilot' | 'default'; @@ -84,8 +84,9 @@ class ProfileDetector { private readonly profilesPath: string; constructor() { - this.configPath = path.join(os.homedir(), '.ccs', 'config.json'); - this.profilesPath = path.join(os.homedir(), '.ccs', 'profiles.json'); + const ccsDir = getCcsDir(); + this.configPath = path.join(ccsDir, 'config.json'); + this.profilesPath = path.join(ccsDir, 'profiles.json'); } /** diff --git a/src/auth/profile-registry.ts b/src/auth/profile-registry.ts index 151781ee..e076e8eb 100644 --- a/src/auth/profile-registry.ts +++ b/src/auth/profile-registry.ts @@ -1,12 +1,12 @@ import * as fs from 'fs'; import * as path from 'path'; -import * as os from 'os'; import { ProfileMetadata } from '../types'; import { loadOrCreateUnifiedConfig, saveUnifiedConfig, isUnifiedMode, } from '../config/unified-config-loader'; +import { getCcsDir } from '../utils/config-manager'; /** * Profile Registry (Simplified) @@ -43,7 +43,7 @@ export class ProfileRegistry { private profilesPath: string; constructor() { - this.profilesPath = path.join(os.homedir(), '.ccs', 'profiles.json'); + this.profilesPath = path.join(getCcsDir(), 'profiles.json'); } /** diff --git a/src/delegation/headless-executor.ts b/src/delegation/headless-executor.ts index a2eceec1..b282936a 100644 --- a/src/delegation/headless-executor.ts +++ b/src/delegation/headless-executor.ts @@ -7,7 +7,6 @@ import { spawn } from 'child_process'; import * as path from 'path'; -import * as os from 'os'; import * as fs from 'fs'; import { SessionManager } from './session-manager'; import { SettingsParser } from './settings-parser'; @@ -15,6 +14,7 @@ import { ui, warn, info } from '../utils/ui'; import { type ExecutionOptions, type ExecutionResult, type StreamMessage } from './executor/types'; import { StreamBuffer, formatToolVerbose } from './executor/stream-parser'; import { buildExecutionResult } from './executor/result-aggregator'; +import { getCcsDir } from '../utils/config-manager'; // Re-export types for consumers export type { ExecutionOptions, ExecutionResult, StreamMessage } from './executor/types'; @@ -63,7 +63,7 @@ export class HeadlessExecutor { } // Get settings path for profile - const settingsPath = path.join(os.homedir(), '.ccs', `${profile}.settings.json`); + const settingsPath = path.join(getCcsDir(), `${profile}.settings.json`); // Validate settings file exists if (!fs.existsSync(settingsPath)) { diff --git a/src/delegation/session-manager.ts b/src/delegation/session-manager.ts index b9fba1f6..c407daad 100644 --- a/src/delegation/session-manager.ts +++ b/src/delegation/session-manager.ts @@ -6,7 +6,7 @@ import * as fs from 'fs'; import * as path from 'path'; -import * as os from 'os'; +import { getCcsDir } from '../utils/config-manager'; interface SessionData { sessionId: string; @@ -39,7 +39,7 @@ class SessionManager { private readonly sessionsPath: string; constructor() { - this.sessionsPath = path.join(os.homedir(), '.ccs', 'delegation-sessions.json'); + this.sessionsPath = path.join(getCcsDir(), 'delegation-sessions.json'); } /** diff --git a/src/glmt/glmt-transformer.ts b/src/glmt/glmt-transformer.ts index ad1a404d..5c4a41e7 100644 --- a/src/glmt/glmt-transformer.ts +++ b/src/glmt/glmt-transformer.ts @@ -10,8 +10,8 @@ import * as fs from 'fs'; import * as path from 'path'; -import * as os from 'os'; import { DeltaAccumulator } from './delta-accumulator'; +import { getCcsDir } from '../utils/config-manager'; import { RequestTransformer, StreamParser, @@ -48,7 +48,7 @@ export class GlmtTransformer { const debugEnabled = process.env.CCS_DEBUG === '1'; this.debugLog = config.debugLog ?? debugEnabled; - this.debugLogDir = config.debugLogDir || path.join(os.homedir(), '.ccs', 'logs'); + this.debugLogDir = config.debugLogDir || path.join(getCcsDir(), 'logs'); // Initialize pipeline components this.requestTransformer = new RequestTransformer({ diff --git a/src/management/checks/config-check.ts b/src/management/checks/config-check.ts index e56846a8..c05d8457 100644 --- a/src/management/checks/config-check.ts +++ b/src/management/checks/config-check.ts @@ -7,6 +7,7 @@ import * as path from 'path'; import * as os from 'os'; import { ok, fail, warn, info } from '../../utils/ui'; import { HealthCheck, IHealthChecker, createSpinner } from './types'; +import { getCcsDir } from '../../utils/config-manager'; const ora = createSpinner(); @@ -20,7 +21,7 @@ export class ConfigFilesChecker implements IHealthChecker { private readonly ccsDir: string; constructor() { - this.ccsDir = path.join(os.homedir(), '.ccs'); + this.ccsDir = getCcsDir(); } run(results: HealthCheck): void { diff --git a/src/management/checks/profile-check.ts b/src/management/checks/profile-check.ts index e29a0143..d1cd555b 100644 --- a/src/management/checks/profile-check.ts +++ b/src/management/checks/profile-check.ts @@ -4,9 +4,9 @@ import * as fs from 'fs'; import * as path from 'path'; -import * as os from 'os'; import { ok, fail, warn, info } from '../../utils/ui'; import { HealthCheck, IHealthChecker, createSpinner } from './types'; +import { getCcsDir } from '../../utils/config-manager'; const ora = createSpinner(); @@ -18,7 +18,7 @@ export class ProfilesChecker implements IHealthChecker { private readonly ccsDir: string; constructor() { - this.ccsDir = path.join(os.homedir(), '.ccs'); + this.ccsDir = getCcsDir(); } run(results: HealthCheck): void { @@ -130,7 +130,7 @@ export class InstancesChecker implements IHealthChecker { private readonly ccsDir: string; constructor() { - this.ccsDir = path.join(os.homedir(), '.ccs'); + this.ccsDir = getCcsDir(); } run(results: HealthCheck): void { @@ -169,7 +169,7 @@ export class DelegationChecker implements IHealthChecker { private readonly ccsDir: string; constructor() { - this.ccsDir = path.join(os.homedir(), '.ccs'); + this.ccsDir = getCcsDir(); } run(results: HealthCheck): void { diff --git a/src/management/checks/system-check.ts b/src/management/checks/system-check.ts index 65b1b39e..f25c60ca 100644 --- a/src/management/checks/system-check.ts +++ b/src/management/checks/system-check.ts @@ -3,13 +3,12 @@ */ import * as fs from 'fs'; -import * as path from 'path'; -import * as os from 'os'; import { spawn } from 'child_process'; import { getClaudeCliInfo } from '../../utils/claude-detector'; import { escapeShellArg } from '../../utils/shell-executor'; import { ok, fail } from '../../utils/ui'; import { HealthCheck, IHealthChecker, createSpinner } from './types'; +import { getCcsDir } from '../../utils/config-manager'; const ora = createSpinner(); @@ -99,7 +98,7 @@ export class CcsDirectoryChecker implements IHealthChecker { private readonly ccsDir: string; constructor() { - this.ccsDir = path.join(os.homedir(), '.ccs'); + this.ccsDir = getCcsDir(); } run(results: HealthCheck): void { diff --git a/src/management/instance-manager.ts b/src/management/instance-manager.ts index 27ecd8d2..2063a39c 100644 --- a/src/management/instance-manager.ts +++ b/src/management/instance-manager.ts @@ -8,8 +8,8 @@ import * as fs from 'fs'; import * as path from 'path'; -import * as os from 'os'; import SharedManager from './shared-manager'; +import { getCcsDir } from '../utils/config-manager'; /** * Instance Manager Class @@ -19,7 +19,7 @@ class InstanceManager { private readonly sharedManager: SharedManager; constructor() { - this.instancesDir = path.join(os.homedir(), '.ccs', 'instances'); + this.instancesDir = path.join(getCcsDir(), 'instances'); this.sharedManager = new SharedManager(); } diff --git a/src/management/shared-manager.ts b/src/management/shared-manager.ts index 65ea5ed1..ca6d29be 100644 --- a/src/management/shared-manager.ts +++ b/src/management/shared-manager.ts @@ -10,6 +10,7 @@ import * as fs from 'fs'; import * as path from 'path'; import * as os from 'os'; import { ok, info, warn } from '../utils/ui'; +import { getCcsDir } from '../utils/config-manager'; interface SharedItem { name: string; @@ -28,9 +29,10 @@ class SharedManager { constructor() { this.homeDir = os.homedir(); - this.sharedDir = path.join(this.homeDir, '.ccs', 'shared'); + const ccsDir = getCcsDir(); + this.sharedDir = path.join(ccsDir, 'shared'); this.claudeDir = path.join(this.homeDir, '.claude'); - this.instancesDir = path.join(this.homeDir, '.ccs', 'instances'); + this.instancesDir = path.join(ccsDir, 'instances'); this.sharedItems = [ { name: 'commands', type: 'directory' }, { name: 'skills', type: 'directory' }, diff --git a/src/utils/update-checker.ts b/src/utils/update-checker.ts index c4a0e41d..019e0c6e 100644 --- a/src/utils/update-checker.ts +++ b/src/utils/update-checker.ts @@ -4,10 +4,10 @@ import * as fs from 'fs'; import * as path from 'path'; -import * as os from 'os'; import * as https from 'https'; +import { getCcsDir } from './config-manager'; -const CACHE_DIR = path.join(os.homedir(), '.ccs', 'cache'); +const CACHE_DIR = path.join(getCcsDir(), 'cache'); const UPDATE_CHECK_FILE = path.join(CACHE_DIR, 'update-check.json'); const CHECK_INTERVAL = 24 * 60 * 60 * 1000; // 24 hours const GITHUB_API_URL = 'https://api.github.com/repos/kaitranntt/ccs/releases/latest';