mirror of
https://github.com/tiennm99/ccs.git
synced 2026-09-01 20:18:38 +00:00
Issue #1161. Sweeps 127 files to import from src/config/config-loader-facade.ts instead of unified-config-loader or utils/config-manager directly. WRITE callers (32 files): replaced raw saveUnifiedConfig / mutateUnifiedConfig / updateUnifiedConfig calls with the facade's cache-coherent wrappers saveConfig / mutateConfig / updateConfig. This fixes a latent stale-cache window where direct writes through the underlying loader bypassed the facade's memoization. READ callers (95 files): mechanical import-path migration only — function names unchanged because the facade re-exports them. No behavior change. Also updated: - tests/unit/utils/browser/browser-setup.test.ts (DI interface rename) - src/management/checks/image-analysis-check.ts (dynamic import rename) - src/web-server/health-service.ts (dynamic require rename) - src/ccs.ts (path prefix fix from sweep script) After sweep: zero raw write callers remain outside src/config/. Direct imports of config-manager remain only for symbols not in the facade (getConfigPath, getCcsDirSource, etc). Behavior unchanged; full suite passes 1824/1824. Out of scope: switching loadOrCreateUnifiedConfig() callers to getCachedConfig() — needs per-callsite cache-safety analysis. Tracked as follow-up. Refs #1161
73 lines
2.1 KiB
TypeScript
73 lines
2.1 KiB
TypeScript
/**
|
|
* Default Command Handler
|
|
*
|
|
* Sets or clears the default profile.
|
|
*/
|
|
|
|
import { initUI, color, dim, ok, fail } from '../../utils/ui';
|
|
|
|
import { exitWithError } from '../../errors';
|
|
import { ExitCode } from '../../errors/exit-codes';
|
|
import { CommandContext, parseArgs } from './types';
|
|
import { isUnifiedMode } from '../../config/config-loader-facade';
|
|
|
|
/**
|
|
* Handle the default command (set default profile)
|
|
*/
|
|
export async function handleDefault(ctx: CommandContext, args: string[]): Promise<void> {
|
|
await initUI();
|
|
const { profileName } = parseArgs(args);
|
|
|
|
if (!profileName) {
|
|
console.log(fail('Profile name is required'));
|
|
console.log('');
|
|
console.log(`Usage: ${color('ccs auth default <profile>', 'command')}`);
|
|
exitWithError('Profile name is required', ExitCode.PROFILE_ERROR);
|
|
}
|
|
|
|
try {
|
|
// Use unified or legacy based on config mode
|
|
if (isUnifiedMode()) {
|
|
ctx.registry.setDefaultUnified(profileName);
|
|
} else {
|
|
ctx.registry.setDefaultProfile(profileName);
|
|
}
|
|
|
|
console.log(ok(`Default profile set: ${profileName}`));
|
|
console.log('');
|
|
console.log('Now you can use:');
|
|
console.log(
|
|
` ${color('ccs "your prompt"', 'command')} ${dim(`# Uses ${profileName} profile`)}`
|
|
);
|
|
console.log('');
|
|
} catch (error) {
|
|
exitWithError((error as Error).message, ExitCode.PROFILE_ERROR);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Handle the reset-default command (clear the custom default)
|
|
*/
|
|
export async function handleResetDefault(ctx: CommandContext): Promise<void> {
|
|
await initUI();
|
|
|
|
try {
|
|
// Use unified or legacy based on config mode
|
|
if (isUnifiedMode()) {
|
|
ctx.registry.clearDefaultUnified();
|
|
} else {
|
|
ctx.registry.clearDefaultProfile();
|
|
}
|
|
|
|
console.log(ok('Default profile cleared'));
|
|
console.log('');
|
|
console.log('CCS will now use the original behavior:');
|
|
console.log(` ${dim('# Uses your primary Claude account')}`);
|
|
console.log(` ${color('ccs "your prompt"', 'command')}`);
|
|
console.log('');
|
|
} catch (error) {
|
|
console.log(fail((error as Error).message));
|
|
process.exit(1);
|
|
}
|
|
}
|