ccbot-cli 2.1.0 → 2.2.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/install.js +74 -0
- package/package.json +1 -1
package/bin/install.js
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
const fs = require('fs');
|
|
4
4
|
const path = require('path');
|
|
5
5
|
const os = require('os');
|
|
6
|
+
const { execSync } = require('child_process');
|
|
6
7
|
|
|
7
8
|
const pkg = require(path.join(__dirname, '..', 'package.json'));
|
|
8
9
|
const VERSION = pkg.version;
|
|
@@ -68,6 +69,64 @@ function warn(msg) { console.log(` ${c.ylw('⚠')} ${msg}`); }
|
|
|
68
69
|
function info(msg) { console.log(` ${c.blu('ℹ')} ${msg}`); }
|
|
69
70
|
function fail(msg) { console.log(` ${c.red('✘')} ${msg}`); }
|
|
70
71
|
|
|
72
|
+
// ── 检测/安装 Claude Code CLI ──
|
|
73
|
+
|
|
74
|
+
function detectClaudeCLI() {
|
|
75
|
+
try {
|
|
76
|
+
const ver = execSync('claude --version', { stdio: 'pipe' }).toString().trim();
|
|
77
|
+
return ver;
|
|
78
|
+
} catch { return null; }
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function installClaudeCLI() {
|
|
82
|
+
info('Claude Code CLI 未检测到,正在安装...');
|
|
83
|
+
try {
|
|
84
|
+
execSync('npm install -g @anthropic-ai/claude-code', { stdio: 'inherit' });
|
|
85
|
+
const ver = detectClaudeCLI();
|
|
86
|
+
if (ver) { ok(`Claude Code CLI 安装成功 (${ver})`); return true; }
|
|
87
|
+
fail('安装后仍未检测到 claude 命令');
|
|
88
|
+
return false;
|
|
89
|
+
} catch (e) {
|
|
90
|
+
fail(`安装失败: ${e.message}`);
|
|
91
|
+
return false;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function checkClaudeCLI() {
|
|
96
|
+
const ver = detectClaudeCLI();
|
|
97
|
+
if (ver) {
|
|
98
|
+
ok(`Claude Code CLI: ${c.cyn(ver)}`);
|
|
99
|
+
return true;
|
|
100
|
+
}
|
|
101
|
+
return installClaudeCLI();
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// ── 环境变量检查 ──
|
|
105
|
+
|
|
106
|
+
const SENSITIVE_PATTERNS = [
|
|
107
|
+
{ pattern: /^ANTHROPIC_API_KEY$/i, name: 'ANTHROPIC_API_KEY' },
|
|
108
|
+
{ pattern: /^CLAUDE_API_KEY$/i, name: 'CLAUDE_API_KEY' },
|
|
109
|
+
{ pattern: /^OPENAI_API_KEY$/i, name: 'OPENAI_API_KEY' },
|
|
110
|
+
{ pattern: /^OPENAI_ORG_ID$/i, name: 'OPENAI_ORG_ID' },
|
|
111
|
+
];
|
|
112
|
+
|
|
113
|
+
function checkEnvKeys() {
|
|
114
|
+
const found = [];
|
|
115
|
+
for (const key of Object.keys(process.env)) {
|
|
116
|
+
const match = SENSITIVE_PATTERNS.find(p => p.pattern.test(key));
|
|
117
|
+
if (match) found.push(key);
|
|
118
|
+
}
|
|
119
|
+
if (found.length === 0) {
|
|
120
|
+
ok('未检测到敏感 API Key 环境变量');
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
found.forEach(key => {
|
|
124
|
+
warn(`检测到: ${c.ylw(key)} — 建议从系统环境变量中移除`);
|
|
125
|
+
});
|
|
126
|
+
info('Claude Code 使用 OAuth 认证,通常无需 API Key 环境变量');
|
|
127
|
+
info(`如需保留,请确认是否为有效密钥,避免泄露风险`);
|
|
128
|
+
}
|
|
129
|
+
|
|
71
130
|
// ── 认证 ──
|
|
72
131
|
|
|
73
132
|
function detectClaudeAuth(settings) {
|
|
@@ -448,6 +507,11 @@ async function main() {
|
|
|
448
507
|
|
|
449
508
|
if (target) {
|
|
450
509
|
if (!['claude', 'codex'].includes(target)) { fail('--target 必须是 claude 或 codex'); process.exit(1); }
|
|
510
|
+
if (target === 'claude') {
|
|
511
|
+
divider('环境预检');
|
|
512
|
+
checkClaudeCLI();
|
|
513
|
+
checkEnvKeys();
|
|
514
|
+
}
|
|
451
515
|
const ctx = installCore(target);
|
|
452
516
|
if (target === 'claude') await postClaude(ctx);
|
|
453
517
|
else await postCodex();
|
|
@@ -461,6 +525,7 @@ async function main() {
|
|
|
461
525
|
choices: [
|
|
462
526
|
{ name: `安装到 Claude Code ${c.d('(~/.claude/')}${c.d(')')}`, value: 'install-claude' },
|
|
463
527
|
{ name: `安装到 Codex CLI ${c.d('(~/.codex/')}${c.d(')')}`, value: 'install-codex' },
|
|
528
|
+
{ name: `检查 Claude Code CLI 环境`, value: 'check-env' },
|
|
464
529
|
{ name: `${c.red('卸载')} Claude Code`, value: 'uninstall-claude' },
|
|
465
530
|
{ name: `${c.red('卸载')} Codex CLI`, value: 'uninstall-codex' },
|
|
466
531
|
],
|
|
@@ -468,6 +533,9 @@ async function main() {
|
|
|
468
533
|
|
|
469
534
|
switch (action) {
|
|
470
535
|
case 'install-claude': {
|
|
536
|
+
divider('环境预检');
|
|
537
|
+
checkClaudeCLI();
|
|
538
|
+
checkEnvKeys();
|
|
471
539
|
const ctx = installCore('claude');
|
|
472
540
|
await postClaude(ctx);
|
|
473
541
|
finish(ctx); break;
|
|
@@ -477,6 +545,12 @@ async function main() {
|
|
|
477
545
|
await postCodex();
|
|
478
546
|
finish(ctx); break;
|
|
479
547
|
}
|
|
548
|
+
case 'check-env': {
|
|
549
|
+
divider('环境检查');
|
|
550
|
+
checkClaudeCLI();
|
|
551
|
+
checkEnvKeys();
|
|
552
|
+
break;
|
|
553
|
+
}
|
|
480
554
|
case 'uninstall-claude': runUninstall('claude'); break;
|
|
481
555
|
case 'uninstall-codex': runUninstall('codex'); break;
|
|
482
556
|
}
|