diff --git a/src/ccs.ts b/src/ccs.ts index 5cc90df5..7c686bf9 100644 --- a/src/ccs.ts +++ b/src/ccs.ts @@ -2,7 +2,13 @@ import { spawn, ChildProcess } from 'child_process'; import * as path from 'path'; import * as fs from 'fs'; import { detectClaudeCli } from './utils/claude-detector'; -import { getSettingsPath, loadSettings, getCcsDir } from './utils/config-manager'; +import { + getSettingsPath, + loadSettings, + getCcsDir, + setGlobalConfigDir, + detectCloudSyncPath, +} from './utils/config-manager'; import { validateGlmKey, validateMiniMaxKey } from './utils/api-key-validator'; import { ErrorManager } from './utils/error-manager'; import { execClaudeWithCLIProxy, CLIProxyProvider } from './cliproxy'; @@ -298,7 +304,6 @@ async function main(): Promise { process.exit(1); } - const { setGlobalConfigDir, detectCloudSyncPath } = await import('./utils/config-manager'); setGlobalConfigDir(configDirValue); // Security warning: cloud sync paths expose OAuth tokens @@ -306,25 +311,26 @@ async function main(): Promise { if (cloudService) { console.error(warn(`CCS directory is under ${cloudService}.`)); console.error(' OAuth tokens in cliproxy/auth/ will be synced to cloud.'); + console.error(' Consider: CCS_DIR=/path/outside/cloud ccs ...'); } // Remove consumed args so they don't leak to Claude CLI args.splice(configDirIdx, spliceCount); } else if (process.env.CCS_DIR) { // Also warn for CCS_DIR env var pointing to cloud sync - const { detectCloudSyncPath } = await import('./utils/config-manager'); const cloudService = detectCloudSyncPath(process.env.CCS_DIR); if (cloudService) { console.error(warn(`CCS directory is under ${cloudService}.`)); console.error(' OAuth tokens in cliproxy/auth/ will be synced to cloud.'); + console.error(' Consider: CCS_DIR=/path/outside/cloud ccs ...'); } } else if (process.env.CCS_HOME) { // Also warn for CCS_HOME env var pointing to cloud sync - const { detectCloudSyncPath } = await import('./utils/config-manager'); const cloudService = detectCloudSyncPath(process.env.CCS_HOME); if (cloudService) { console.error(warn(`CCS directory is under ${cloudService}.`)); console.error(' OAuth tokens in cliproxy/auth/ will be synced to cloud.'); + console.error(' Consider: CCS_DIR=/path/outside/cloud ccs ...'); } } diff --git a/src/web-server/health-service.ts b/src/web-server/health-service.ts index 4947c71a..69703484 100644 --- a/src/web-server/health-service.ts +++ b/src/web-server/health-service.ts @@ -139,7 +139,7 @@ export function fixHealthIssue(checkId: string): { success: boolean; message: st switch (checkId) { case 'ccs-dir': fs.mkdirSync(ccsDir, { recursive: true }); - return { success: true, message: 'Created ~/.ccs directory' }; + return { success: true, message: `Created ${ccsDir} directory` }; case 'config-file': { // Use appropriate config based on unified mode diff --git a/src/web-server/usage/disk-cache.ts b/src/web-server/usage/disk-cache.ts index 45aa981e..523169c9 100644 --- a/src/web-server/usage/disk-cache.ts +++ b/src/web-server/usage/disk-cache.ts @@ -55,11 +55,12 @@ function ensureCacheDir(): void { */ export function readDiskCache(): UsageDiskCache | null { try { - if (!fs.existsSync(getCacheFile())) { + const cacheFile = getCacheFile(); + if (!fs.existsSync(cacheFile)) { return null; } - const data = fs.readFileSync(getCacheFile(), 'utf-8'); + const data = fs.readFileSync(cacheFile, 'utf-8'); const cache: UsageDiskCache = JSON.parse(data); // Version check - invalidate if schema changed @@ -117,9 +118,10 @@ export function writeDiskCache( }; // Write atomically using temp file + rename - const tempFile = getCacheFile() + '.tmp'; + const cacheFile = getCacheFile(); + const tempFile = cacheFile + '.tmp'; fs.writeFileSync(tempFile, JSON.stringify(cache), 'utf-8'); - fs.renameSync(tempFile, getCacheFile()); + fs.renameSync(tempFile, cacheFile); console.log(ok('Disk cache updated')); } catch (err) { @@ -149,8 +151,9 @@ export function getCacheAge(cache: UsageDiskCache | null): string { */ export function clearDiskCache(): void { try { - if (fs.existsSync(getCacheFile())) { - fs.unlinkSync(getCacheFile()); + const cacheFile = getCacheFile(); + if (fs.existsSync(cacheFile)) { + fs.unlinkSync(cacheFile); console.log(ok('Disk cache cleared')); } } catch (err) {