mirror of
https://github.com/tiennm99/ccs.git
synced 2026-07-16 10:16:49 +00:00
fix(config): dynamic health message, cache getters, static imports, cloud hint
- Fix hardcoded 'Created ~/.ccs directory' in health-service.ts fixHealthIssue() - Cache getCacheFile() in local vars: readDiskCache, writeDiskCache, clearDiskCache - Convert dynamic imports of setGlobalConfigDir/detectCloudSyncPath to static - Add remediation hint to cloud sync warning: 'Consider: CCS_DIR=/path/outside/cloud'
This commit is contained in:
+10
-4
@@ -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<void> {
|
||||
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<void> {
|
||||
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 ...');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user