yingclaw 1.0.0 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/cli.js +39 -19
- package/package.json +1 -1
package/bin/cli.js
CHANGED
|
@@ -289,11 +289,10 @@ program
|
|
|
289
289
|
.description('查看当前配置和 Key 有效性')
|
|
290
290
|
.action(showStatus);
|
|
291
291
|
|
|
292
|
-
//
|
|
292
|
+
// 无参数时显示交互式菜单
|
|
293
293
|
if (process.argv.length === 2) {
|
|
294
294
|
(async () => {
|
|
295
295
|
const chalk = (await import('chalk')).default;
|
|
296
|
-
const boxen = (await import('boxen')).default;
|
|
297
296
|
|
|
298
297
|
console.log(await getBanner());
|
|
299
298
|
|
|
@@ -302,25 +301,46 @@ if (process.argv.length === 2) {
|
|
|
302
301
|
try { execSync('claude --version', { stdio: 'pipe' }); return true; } catch { return false; }
|
|
303
302
|
})();
|
|
304
303
|
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
chalk.cyan(' 3. ') + chalk.white('claude') + chalk.dim(' 开始使用'),
|
|
311
|
-
{ padding: { top: 0, bottom: 0, left: 2, right: 2 }, borderStyle: 'round', borderColor: 'cyan', margin: { top: 1, bottom: 1 } }
|
|
312
|
-
));
|
|
313
|
-
} else if (!config) {
|
|
314
|
-
console.log(boxen(
|
|
315
|
-
chalk.bold('Claude Code 已安装,还差一步:\n\n') +
|
|
316
|
-
chalk.cyan(' claw setup') + chalk.dim(' 配置国产模型 API Key'),
|
|
317
|
-
{ padding: { top: 0, bottom: 0, left: 2, right: 2 }, borderStyle: 'round', borderColor: 'yellow', margin: { top: 1, bottom: 1 } }
|
|
318
|
-
));
|
|
304
|
+
// 根据当前状态生成提示
|
|
305
|
+
if (config) {
|
|
306
|
+
console.log(chalk.green(` 当前:${PROVIDERS[config.provider]?.name || config.provider} · ${config.model}\n`));
|
|
307
|
+
} else if (claudeInstalled) {
|
|
308
|
+
console.log(chalk.yellow(' Claude Code 已安装,还未配置 API\n'));
|
|
319
309
|
} else {
|
|
320
|
-
console.log(chalk.
|
|
321
|
-
await showStatus();
|
|
322
|
-
return;
|
|
310
|
+
console.log(chalk.dim(' 首次使用,请先安装 Claude Code\n'));
|
|
323
311
|
}
|
|
312
|
+
|
|
313
|
+
const action = await select({
|
|
314
|
+
message: chalk.cyan('选择操作'),
|
|
315
|
+
choices: [
|
|
316
|
+
{ name: '🤖 启动 Claude Code', value: 'launch', disabled: !config && '需先完成配置' },
|
|
317
|
+
{ name: '📦 安装 Claude Code', value: 'install' },
|
|
318
|
+
{ name: '⚙️ 配置 API Key 和模型', value: 'setup' },
|
|
319
|
+
{ name: '🔄 切换模型', value: 'switch', disabled: !config && '需先完成配置' },
|
|
320
|
+
{ name: '📊 查看当前配置', value: 'status', disabled: !config && '需先完成配置' },
|
|
321
|
+
{ name: '退出', value: 'exit' },
|
|
322
|
+
],
|
|
323
|
+
});
|
|
324
|
+
|
|
325
|
+
if (action === 'exit') return;
|
|
326
|
+
|
|
327
|
+
// 把选中的命令转发给 commander
|
|
328
|
+
const cmdMap = {
|
|
329
|
+
launch: () => {
|
|
330
|
+
if (!config) return;
|
|
331
|
+
spawn('claude', [], {
|
|
332
|
+
stdio: 'inherit',
|
|
333
|
+
env: { ...process.env, ANTHROPIC_BASE_URL: config.baseUrl, ANTHROPIC_API_KEY: config.apiKey },
|
|
334
|
+
}).on('error', () => {
|
|
335
|
+
console.log(chalk.yellow('\nClaude Code 未找到,请先选择"安装 Claude Code"'));
|
|
336
|
+
});
|
|
337
|
+
},
|
|
338
|
+
install: () => program.parseAsync(['node', 'claw', 'install-claude']),
|
|
339
|
+
setup: () => program.parseAsync(['node', 'claw', 'setup']),
|
|
340
|
+
switch: () => program.parseAsync(['node', 'claw', 'switch']),
|
|
341
|
+
status: () => program.parseAsync(['node', 'claw', 'status']),
|
|
342
|
+
};
|
|
343
|
+
await cmdMap[action]();
|
|
324
344
|
})();
|
|
325
345
|
} else {
|
|
326
346
|
program.parse(process.argv);
|