aihezu 1.1.1 → 1.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/ccclear.js +14 -1
- package/bin/ccinstall.js +81 -0
- package/package.json +3 -2
package/bin/ccclear.js
CHANGED
|
@@ -6,7 +6,20 @@ const os = require('os');
|
|
|
6
6
|
const fs = require('fs');
|
|
7
7
|
|
|
8
8
|
const homeDir = os.homedir();
|
|
9
|
-
|
|
9
|
+
|
|
10
|
+
// 生成本地时间戳,格式:YYYYMMDDHHMMSS
|
|
11
|
+
function getLocalTimestamp() {
|
|
12
|
+
const now = new Date();
|
|
13
|
+
const year = now.getFullYear();
|
|
14
|
+
const month = String(now.getMonth() + 1).padStart(2, '0');
|
|
15
|
+
const day = String(now.getDate()).padStart(2, '0');
|
|
16
|
+
const hours = String(now.getHours()).padStart(2, '0');
|
|
17
|
+
const minutes = String(now.getMinutes()).padStart(2, '0');
|
|
18
|
+
const seconds = String(now.getSeconds()).padStart(2, '0');
|
|
19
|
+
return `${year}${month}${day}${hours}${minutes}${seconds}`;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const timestamp = getLocalTimestamp();
|
|
10
23
|
|
|
11
24
|
console.log('🧹 Claude Code CLI 清理工具');
|
|
12
25
|
console.log('🌐 Powered by https://aihezu.dev\n');
|
package/bin/ccinstall.js
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const readline = require('readline');
|
|
4
|
+
const path = require('path');
|
|
5
|
+
const os = require('os');
|
|
6
|
+
const fs = require('fs');
|
|
7
|
+
|
|
8
|
+
const homeDir = os.homedir();
|
|
9
|
+
const settingsPath = path.join(homeDir, '.claude', 'settings.json');
|
|
10
|
+
|
|
11
|
+
console.log('🔧 Claude Code API 配置工具');
|
|
12
|
+
console.log('🌐 Powered by https://aihezu.dev\n');
|
|
13
|
+
|
|
14
|
+
// 创建 readline 接口
|
|
15
|
+
const rl = readline.createInterface({
|
|
16
|
+
input: process.stdin,
|
|
17
|
+
output: process.stdout
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
// 提示用户输入 API Key
|
|
21
|
+
rl.question('请输入您的 API Key: ', (apiKey) => {
|
|
22
|
+
if (!apiKey || apiKey.trim() === '') {
|
|
23
|
+
console.error('❌ API Key 不能为空');
|
|
24
|
+
rl.close();
|
|
25
|
+
process.exit(1);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
apiKey = apiKey.trim();
|
|
29
|
+
|
|
30
|
+
try {
|
|
31
|
+
// 确保 .claude 目录存在
|
|
32
|
+
const claudeDir = path.join(homeDir, '.claude');
|
|
33
|
+
if (!fs.existsSync(claudeDir)) {
|
|
34
|
+
console.log('📁 创建 ~/.claude 目录...');
|
|
35
|
+
fs.mkdirSync(claudeDir, { recursive: true });
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// 读取或创建 settings.json
|
|
39
|
+
let settings = {};
|
|
40
|
+
if (fs.existsSync(settingsPath)) {
|
|
41
|
+
console.log('📖 读取现有配置文件...');
|
|
42
|
+
const content = fs.readFileSync(settingsPath, 'utf8');
|
|
43
|
+
try {
|
|
44
|
+
settings = JSON.parse(content);
|
|
45
|
+
} catch (e) {
|
|
46
|
+
console.log('⚠️ 现有配置文件格式错误,将创建新的配置');
|
|
47
|
+
// 备份错误的配置文件
|
|
48
|
+
const timestamp = new Date().toISOString().replace(/[:.]/g, '-');
|
|
49
|
+
const backupPath = `${settingsPath}.backup-${timestamp}`;
|
|
50
|
+
fs.writeFileSync(backupPath, content);
|
|
51
|
+
console.log(`📦 已备份原配置文件到: ${path.basename(backupPath)}`);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// 确保 env 对象存在
|
|
56
|
+
if (!settings.env) {
|
|
57
|
+
settings.env = {};
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// 设置配置
|
|
61
|
+
settings.env.ANTHROPIC_AUTH_TOKEN = apiKey;
|
|
62
|
+
settings.env.ANTHROPIC_BASE_URL = 'https://cc.aihezu.dev/api';
|
|
63
|
+
|
|
64
|
+
// 写入配置文件
|
|
65
|
+
fs.writeFileSync(settingsPath, JSON.stringify(settings, null, 2), 'utf8');
|
|
66
|
+
|
|
67
|
+
console.log('\n✅ 配置成功!');
|
|
68
|
+
console.log('📝 已更新配置文件:', settingsPath);
|
|
69
|
+
console.log('\n配置内容:');
|
|
70
|
+
console.log(' ANTHROPIC_AUTH_TOKEN:', apiKey);
|
|
71
|
+
console.log(' ANTHROPIC_BASE_URL:', 'https://cc.aihezu.dev/api');
|
|
72
|
+
console.log('\n💡 您现在可以开始使用 Claude Code 了!');
|
|
73
|
+
console.log('🌐 更多服务请访问: https://aihezu.dev');
|
|
74
|
+
|
|
75
|
+
} catch (error) {
|
|
76
|
+
console.error('❌ 配置失败:', error.message);
|
|
77
|
+
process.exit(1);
|
|
78
|
+
} finally {
|
|
79
|
+
rl.close();
|
|
80
|
+
}
|
|
81
|
+
});
|
package/package.json
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "aihezu",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "Claude Code CLI 清理工具 - 快速备份和清理 Claude Code 的本地配置和缓存,同时修改 hosts 文件实现本地代理",
|
|
5
5
|
"main": "bin/ccclear.js",
|
|
6
6
|
"bin": {
|
|
7
|
-
"ccclear": "bin/ccclear.js"
|
|
7
|
+
"ccclear": "bin/ccclear.js",
|
|
8
|
+
"ccinstall": "bin/ccinstall.js"
|
|
8
9
|
},
|
|
9
10
|
"scripts": {
|
|
10
11
|
"test": "node bin/ccclear.js"
|