mirror of
https://github.com/tiennm99/ccs.git
synced 2026-07-16 18:16:08 +00:00
Split monolithic ccs.ts (1071 lines) into modular command handlers: Main file reduction: - ccs.ts: 1071 → 593 lines (44.6% reduction) - Maintains routing logic + profile detection + GLMT proxy New utility modules: - src/utils/shell-executor.ts: Cross-platform shell execution - src/utils/package-manager-detector.ts: Package manager detection New command handlers: - src/commands/version-command.ts: Version display - src/commands/help-command.ts: Help text and usage - src/commands/install-command.ts: Install/uninstall stubs - src/commands/doctor-command.ts: Health checks - src/commands/sync-command.ts: CCS synchronization - src/commands/shell-completion-command.ts: Shell completion Validation: - 39/39 tests passing (100% success rate) - TypeScript compilation: ✅ Zero errors - ESLint: ✅ Zero violations - Manual testing: ✅ All commands working Code review: EXCELLENT rating, 0 critical issues, zero regressions Tier1 plan: 2/2 phases complete - both ESLint strictness and modular architecture successfully implemented.
90 lines
3.0 KiB
TypeScript
90 lines
3.0 KiB
TypeScript
/**
|
|
* Version Command Handler
|
|
*
|
|
* Handle --version command for CCS.
|
|
*/
|
|
|
|
import * as path from 'path';
|
|
import * as fs from 'fs';
|
|
import * as os from 'os';
|
|
import { colored } from '../utils/helpers';
|
|
import { getConfigPath } from '../utils/config-manager';
|
|
|
|
// Get version from package.json
|
|
const CCS_VERSION = JSON.parse(
|
|
fs.readFileSync(path.join(__dirname, '../../package.json'), 'utf8')
|
|
).version;
|
|
|
|
/**
|
|
* Handle version command
|
|
*/
|
|
export function handleVersionCommand(): void {
|
|
console.log(colored(`CCS (Claude Code Switch) v${CCS_VERSION}`, 'bold'));
|
|
console.log('');
|
|
|
|
console.log(colored('Installation:', 'cyan'));
|
|
const installLocation = process.argv[1] || '(not found)';
|
|
console.log(` ${colored('Location:'.padEnd(17), 'cyan')} ${installLocation}`);
|
|
|
|
const ccsDir = path.join(os.homedir(), '.ccs');
|
|
console.log(` ${colored('CCS Directory:'.padEnd(17), 'cyan')} ${ccsDir}`);
|
|
|
|
const configPath = getConfigPath();
|
|
console.log(` ${colored('Config:'.padEnd(17), 'cyan')} ${configPath}`);
|
|
|
|
const profilesJson = path.join(os.homedir(), '.ccs', 'profiles.json');
|
|
console.log(` ${colored('Profiles:'.padEnd(17), 'cyan')} ${profilesJson}`);
|
|
|
|
// Delegation status
|
|
const delegationSessionsPath = path.join(os.homedir(), '.ccs', 'delegation-sessions.json');
|
|
const delegationConfigured = fs.existsSync(delegationSessionsPath);
|
|
|
|
const readyProfiles: string[] = [];
|
|
|
|
// Check for profiles with valid API keys
|
|
for (const profile of ['glm', 'kimi']) {
|
|
const settingsPath = path.join(os.homedir(), '.ccs', `${profile}.settings.json`);
|
|
if (fs.existsSync(settingsPath)) {
|
|
try {
|
|
const settings = JSON.parse(fs.readFileSync(settingsPath, 'utf8'));
|
|
const apiKey = settings.env?.ANTHROPIC_AUTH_TOKEN;
|
|
if (apiKey && !apiKey.match(/YOUR_.*_API_KEY_HERE/) && !apiKey.match(/sk-test.*/)) {
|
|
readyProfiles.push(profile);
|
|
}
|
|
} catch (_error) {
|
|
// Invalid JSON, skip
|
|
}
|
|
}
|
|
}
|
|
|
|
const hasValidApiKeys = readyProfiles.length > 0;
|
|
const delegationEnabled = delegationConfigured || hasValidApiKeys;
|
|
|
|
if (delegationEnabled) {
|
|
console.log(` ${colored('Delegation:'.padEnd(17), 'cyan')} Enabled`);
|
|
} else {
|
|
console.log(` ${colored('Delegation:'.padEnd(17), 'cyan')} Not configured`);
|
|
}
|
|
|
|
console.log('');
|
|
|
|
if (readyProfiles.length > 0) {
|
|
console.log(colored('Delegation Ready:', 'cyan'));
|
|
console.log(
|
|
` ${colored('[OK]', 'yellow')} ${readyProfiles.join(', ')} profiles are ready for delegation`
|
|
);
|
|
console.log('');
|
|
} else if (delegationEnabled) {
|
|
console.log(colored('Delegation Ready:', 'cyan'));
|
|
console.log(` ${colored('[!]', 'yellow')} Delegation configured but no valid API keys found`);
|
|
console.log('');
|
|
}
|
|
|
|
console.log(`${colored('Documentation:', 'cyan')} https://github.com/kaitranntt/ccs`);
|
|
console.log(`${colored('License:', 'cyan')} MIT`);
|
|
console.log('');
|
|
console.log(colored("Run 'ccs --help' for usage information", 'yellow'));
|
|
|
|
process.exit(0);
|
|
}
|