Skip to content

Commit 9726a97

Browse files
committed
chore: prepare release for vpatch
1 parent 3afd8d5 commit 9726a97

1 file changed

Lines changed: 135 additions & 61 deletions

File tree

cli/commands.js

Lines changed: 135 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -219,71 +219,145 @@ function backupConfig() {
219219
}
220220
}
221221

222+
// Helper to find original ccr binary
223+
function getOriginalCcrPath() {
224+
try {
225+
// Try to find it in dependencies
226+
return require.resolve('@musistudio/claude-code-router/index.js');
227+
} catch (e) {
228+
return null;
229+
}
230+
}
231+
232+
// Proxy command to original router
233+
function proxyToOriginal(args) {
234+
const originalPath = getOriginalCcrPath();
235+
if (!originalPath) {
236+
console.error(chalk.red('❌ Original @musistudio/claude-code-router not found.'));
237+
return;
238+
}
239+
240+
const child = spawn('node', [originalPath, ...args], {
241+
stdio: 'inherit',
242+
env: process.env
243+
});
244+
245+
child.on('exit', (code) => {
246+
if (code !== 0) {
247+
process.exit(code || 1);
248+
}
249+
});
250+
}
251+
222252
// CLI command handler
223253
async function main() {
224254
const [command, ...args] = process.argv.slice(2);
255+
const advancedCommands = ['test', 'benchmark', 'analytics', 'status', 'config', 'health', 'update'];
256+
257+
// If it's an advanced command or no command is given
258+
if (advancedCommands.includes(command) || !command || command === '--help' || command === '-h') {
259+
switch (command) {
260+
case 'update':
261+
console.log(chalk.blue('🔄 Checking for updates and updating...'));
262+
const updateProcess = spawn('pnpm', ['add', '-g', '@halilertekin/claude-code-router-config@latest'], {
263+
stdio: 'inherit',
264+
env: process.env
265+
});
266+
updateProcess.on('exit', (code) => {
267+
if (code === 0) {
268+
console.log(chalk.green('✅ Successfully updated to the latest version!'));
269+
} else {
270+
console.error(chalk.red(`❌ Update failed with code ${code}. Please try running manually: pnpm add -g @halilertekin/claude-code-router-config@latest`));
271+
}
272+
});
273+
break;
225274

226-
switch (command) {
227-
case 'test':
228-
const provider = args[0];
229-
const model = args[1];
230-
if (provider) {
231-
await testProvider(provider, model);
232-
} else {
233-
console.error(chalk.red('❌ Please specify a provider: ccr test <provider> [model]'));
234-
}
235-
break;
236-
237-
case 'benchmark':
238-
const options = {
239-
allProviders: args.includes('--all'),
240-
compareSpeed: args.includes('--compare-speed')
241-
};
242-
await benchmarkProviders(options);
243-
break;
244-
245-
case 'status':
246-
const statusOptions = {
247-
detailed: args.includes('--detailed'),
248-
showCosts: args.includes('--show-costs')
249-
};
250-
await showDetailedStatus(statusOptions);
251-
break;
252-
253-
case 'config':
254-
const configCommand = args[0];
255-
switch (configCommand) {
256-
case 'validate':
257-
validateConfig();
258-
break;
259-
case 'backup':
260-
backupConfig();
261-
break;
262-
default:
263-
console.log(chalk.yellow('Available config commands:'));
264-
console.log(' validate - Check configuration validity');
265-
console.log(' backup - Backup current configuration');
266-
}
267-
break;
268-
269-
default:
270-
console.log(chalk.blue('Claude Code Router - Advanced CLI'));
271-
console.log(chalk.gray('─'.repeat(40)));
272-
console.log(chalk.yellow('Available commands:'));
273-
console.log('');
274-
console.log('Testing & Benchmarking:');
275-
console.log(' ccr test <provider> [model] - Test provider connection');
276-
console.log(' ccr benchmark [--all] [--compare-speed] - Benchmark providers');
277-
console.log(' ccr status [--detailed] [--show-costs] - Show router status');
278-
console.log('');
279-
console.log('Configuration Management:');
280-
console.log(' ccr config validate - Validate configuration');
281-
console.log(' ccr config backup - Backup configuration');
282-
console.log('');
283-
console.log('Examples:');
284-
console.log(' ccr test openai gpt-4o');
285-
console.log(' ccr benchmark --all --compare-speed');
286-
console.log(' ccr status --detailed --show-costs');
275+
case 'test':
276+
const provider = args[0];
277+
const model = args[1];
278+
if (provider) {
279+
await testProvider(provider, model);
280+
} else {
281+
console.error(chalk.red('❌ Please specify a provider: ccr test <provider> [model]'));
282+
}
283+
break;
284+
285+
case 'benchmark':
286+
const options = {
287+
allProviders: args.includes('--all'),
288+
compareSpeed: args.includes('--compare-speed')
289+
};
290+
await benchmarkProviders(options);
291+
break;
292+
293+
case 'status':
294+
if (args.includes('--detailed')) {
295+
const statusOptions = {
296+
detailed: true,
297+
showCosts: args.includes('--show-costs')
298+
};
299+
await showDetailedStatus(statusOptions);
300+
} else {
301+
// Pass basic status to original router
302+
proxyToOriginal(['status', ...args]);
303+
}
304+
break;
305+
306+
case 'analytics':
307+
// Forward to analytics script
308+
const analyticsPath = path.join(__dirname, 'analytics.js');
309+
spawn('node', [analyticsPath, ...args], { stdio: 'inherit' });
310+
break;
311+
312+
case 'health':
313+
const healthPath = path.join(__dirname, '../logging/health-monitor.js');
314+
spawn('node', [healthPath, ...args], { stdio: 'inherit' });
315+
break;
316+
317+
case 'config':
318+
const configCommand = args[0];
319+
switch (configCommand) {
320+
case 'validate':
321+
validateConfig();
322+
break;
323+
case 'backup':
324+
backupConfig();
325+
break;
326+
default:
327+
console.log(chalk.yellow('Available config commands:'));
328+
console.log(' validate - Check configuration validity');
329+
console.log(' backup - Backup current configuration');
330+
}
331+
break;
332+
333+
default:
334+
console.log(chalk.blue('Claude Code Router - Advanced CLI (v1.2.4)'));
335+
console.log(chalk.gray('─'.repeat(45)));
336+
337+
console.log(chalk.yellow('🚀 Advanced CLI Tools:'));
338+
console.log(' test <provider> [model] - Test provider connection');
339+
console.log(' benchmark [--all] [--compare-speed] - Benchmark providers');
340+
console.log(' analytics [period] - View usage statistics');
341+
console.log(' status --detailed [--show-costs] - Show detailed router status');
342+
console.log(' config validate - Validate configuration');
343+
console.log(' config backup - Backup configuration');
344+
console.log(' health [--all-providers] - Check provider health');
345+
346+
console.log(chalk.yellow('\n📦 Core Router Commands (Proxy):'));
347+
console.log(' start - Start router server');
348+
console.log(' stop - Stop router server');
349+
console.log(' restart - Restart router server');
350+
console.log(' status - Show server status');
351+
console.log(' code - Start with Claude Code');
352+
console.log(' model - Switch models at runtime');
353+
console.log(' activate - Export env variables');
354+
355+
console.log(chalk.yellow('\n💡 Tip:'));
356+
console.log(' Run ' + chalk.cyan('ccr start') + ' to start the proxy server, then ' + chalk.cyan('ccr code') + ' to open Claude.');
357+
}
358+
} else {
359+
// Forward unknown commands to the original router
360+
proxyToOriginal([command, ...args]);
287361
}
288362
}
289363

0 commit comments

Comments
 (0)