mirror of
https://github.com/tiennm99/ccs.git
synced 2026-10-13 06:15:03 +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:
1 parent
9699e01725
commit
706cca8b3e
3 files changed
+20
-11
No files matched your search
+10
-4
@@ -2,7 +2,13 @@ import { spawn, ChildProcess } from 'child_process';
|
|||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
import * as fs from 'fs';
|
import * as fs from 'fs';
|
||||||
import { detectClaudeCli } from './utils/claude-detector';
|
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 { validateGlmKey, validateMiniMaxKey } from './utils/api-key-validator';
|
||||||
import { ErrorManager } from './utils/error-manager';
|
import { ErrorManager } from './utils/error-manager';
|
||||||
import { execClaudeWithCLIProxy, CLIProxyProvider } from './cliproxy';
|
import { execClaudeWithCLIProxy, CLIProxyProvider } from './cliproxy';
|
||||||
@@ -298,7 +304,6 @@ async function main(): Promise<void> {
|
|||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
const { setGlobalConfigDir, detectCloudSyncPath } = await import('./utils/config-manager');
|
|
||||||
setGlobalConfigDir(configDirValue);
|
setGlobalConfigDir(configDirValue);
|
||||||
|
|
||||||
// Security warning: cloud sync paths expose OAuth tokens
|
// Security warning: cloud sync paths expose OAuth tokens
|
||||||
@@ -306,25 +311,26 @@ async function main(): Promise<void> {
|
|||||||
if (cloudService) {
|
if (cloudService) {
|
||||||
console.error(warn(`CCS directory is under ${cloudService}.`));
|
console.error(warn(`CCS directory is under ${cloudService}.`));
|
||||||
console.error(' OAuth tokens in cliproxy/auth/ will be synced to cloud.');
|
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
|
// Remove consumed args so they don't leak to Claude CLI
|
||||||
args.splice(configDirIdx, spliceCount);
|
args.splice(configDirIdx, spliceCount);
|
||||||
} else if (process.env.CCS_DIR) {
|
} else if (process.env.CCS_DIR) {
|
||||||
// Also warn for CCS_DIR env var pointing to cloud sync
|
// 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);
|
const cloudService = detectCloudSyncPath(process.env.CCS_DIR);
|
||||||
if (cloudService) {
|
if (cloudService) {
|
||||||
console.error(warn(`CCS directory is under ${cloudService}.`));
|
console.error(warn(`CCS directory is under ${cloudService}.`));
|
||||||
console.error(' OAuth tokens in cliproxy/auth/ will be synced to cloud.');
|
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) {
|
} else if (process.env.CCS_HOME) {
|
||||||
// Also warn for CCS_HOME env var pointing to cloud sync
|
// 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);
|
const cloudService = detectCloudSyncPath(process.env.CCS_HOME);
|
||||||
if (cloudService) {
|
if (cloudService) {
|
||||||
console.error(warn(`CCS directory is under ${cloudService}.`));
|
console.error(warn(`CCS directory is under ${cloudService}.`));
|
||||||
console.error(' OAuth tokens in cliproxy/auth/ will be synced to cloud.');
|
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) {
|
switch (checkId) {
|
||||||
case 'ccs-dir':
|
case 'ccs-dir':
|
||||||
fs.mkdirSync(ccsDir, { recursive: true });
|
fs.mkdirSync(ccsDir, { recursive: true });
|
||||||
return { success: true, message: 'Created ~/.ccs directory' };
|
return { success: true, message: `Created ${ccsDir} directory` };
|
||||||
|
|
||||||
case 'config-file': {
|
case 'config-file': {
|
||||||
// Use appropriate config based on unified mode
|
// Use appropriate config based on unified mode
|
||||||
|
|||||||
@@ -55,11 +55,12 @@ function ensureCacheDir(): void {
|
|||||||
*/
|
*/
|
||||||
export function readDiskCache(): UsageDiskCache | null {
|
export function readDiskCache(): UsageDiskCache | null {
|
||||||
try {
|
try {
|
||||||
if (!fs.existsSync(getCacheFile())) {
|
const cacheFile = getCacheFile();
|
||||||
|
if (!fs.existsSync(cacheFile)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
const data = fs.readFileSync(getCacheFile(), 'utf-8');
|
const data = fs.readFileSync(cacheFile, 'utf-8');
|
||||||
const cache: UsageDiskCache = JSON.parse(data);
|
const cache: UsageDiskCache = JSON.parse(data);
|
||||||
|
|
||||||
// Version check - invalidate if schema changed
|
// Version check - invalidate if schema changed
|
||||||
@@ -117,9 +118,10 @@ export function writeDiskCache(
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Write atomically using temp file + rename
|
// 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.writeFileSync(tempFile, JSON.stringify(cache), 'utf-8');
|
||||||
fs.renameSync(tempFile, getCacheFile());
|
fs.renameSync(tempFile, cacheFile);
|
||||||
|
|
||||||
console.log(ok('Disk cache updated'));
|
console.log(ok('Disk cache updated'));
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
@@ -149,8 +151,9 @@ export function getCacheAge(cache: UsageDiskCache | null): string {
|
|||||||
*/
|
*/
|
||||||
export function clearDiskCache(): void {
|
export function clearDiskCache(): void {
|
||||||
try {
|
try {
|
||||||
if (fs.existsSync(getCacheFile())) {
|
const cacheFile = getCacheFile();
|
||||||
fs.unlinkSync(getCacheFile());
|
if (fs.existsSync(cacheFile)) {
|
||||||
|
fs.unlinkSync(cacheFile);
|
||||||
console.log(ok('Disk cache cleared'));
|
console.log(ok('Disk cache cleared'));
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
|||||||
Reference in new issue
Block a user