aihezu 1.8.0 → 2.0.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/aihezu.js +97 -55
- package/bin/ccclear.js +6 -51
- package/bin/ccinstall.js +8 -479
- package/commands/clear.js +34 -0
- package/commands/install.js +164 -0
- package/lib/cache.js +51 -71
- package/lib/hosts.js +73 -71
- package/package.json +12 -10
- package/services/claude.js +64 -0
- package/services/codex.js +119 -0
- package/services/gemini.js +50 -0
package/bin/aihezu.js
CHANGED
|
@@ -1,72 +1,114 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
-
const
|
|
3
|
+
const fs = require('fs');
|
|
4
4
|
const path = require('path');
|
|
5
|
+
const readline = require('readline');
|
|
6
|
+
|
|
7
|
+
const commands = {
|
|
8
|
+
install: require('../commands/install'),
|
|
9
|
+
clear: require('../commands/clear')
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
const services = {
|
|
13
|
+
claude: require('../services/claude'),
|
|
14
|
+
codex: require('../services/codex'),
|
|
15
|
+
gemini: require('../services/gemini')
|
|
16
|
+
};
|
|
5
17
|
|
|
6
18
|
const args = process.argv.slice(2);
|
|
7
|
-
const command = args[0];
|
|
8
|
-
const commandArgs = args.slice(1);
|
|
9
19
|
|
|
10
|
-
// 显示帮助信息
|
|
11
20
|
function showHelp() {
|
|
12
|
-
console.log('
|
|
13
|
-
console.log('
|
|
14
|
-
console.log('
|
|
15
|
-
console.log('
|
|
16
|
-
console.log('
|
|
17
|
-
console.log('
|
|
18
|
-
console.log('
|
|
19
|
-
console.log('
|
|
20
|
-
console.log('示例:');
|
|
21
|
-
console.log('
|
|
22
|
-
console.log('
|
|
23
|
-
console.log('
|
|
24
|
-
console.log('
|
|
25
|
-
console.log(' npx aihezu ccclear # 清理缓存');
|
|
21
|
+
console.log('用法: aihezu <command> [service]');
|
|
22
|
+
console.log('\n命令:');
|
|
23
|
+
console.log(' install <service> 配置服务 (API Key, URL, 网络设置)');
|
|
24
|
+
console.log(' clear <service> 清理缓存并刷新网络设置');
|
|
25
|
+
console.log('\n服务:');
|
|
26
|
+
console.log(' claude Claude Code');
|
|
27
|
+
console.log(' codex Codex');
|
|
28
|
+
console.log(' gemini Google Gemini');
|
|
29
|
+
console.log('\n示例:');
|
|
30
|
+
console.log(' aihezu install claude');
|
|
31
|
+
console.log(' aihezu clear codex');
|
|
32
|
+
console.log(' aihezu install (交互式安装)');
|
|
33
|
+
console.log(' aihezu help (显示帮助信息)');
|
|
26
34
|
}
|
|
27
35
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
36
|
+
async function askQuestion(rl, question) {
|
|
37
|
+
return new Promise(resolve => rl.question(question, answer => resolve(answer.trim())));
|
|
38
|
+
}
|
|
31
39
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
env: process.env
|
|
35
|
-
});
|
|
40
|
+
async function main() {
|
|
41
|
+
// Removed global rl creation
|
|
36
42
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
43
|
+
try {
|
|
44
|
+
if (args.length === 0 || args[0] === 'help') { // Handle 'aihezu' or 'aihezu help'
|
|
45
|
+
showHelp();
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
40
48
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
process.exit(1);
|
|
44
|
-
});
|
|
45
|
-
}
|
|
49
|
+
const commandName = args[0];
|
|
50
|
+
let serviceName = args[1];
|
|
46
51
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
case 'ccinstall':
|
|
50
|
-
case 'install':
|
|
51
|
-
runCommand('ccinstall.js', commandArgs);
|
|
52
|
-
break;
|
|
53
|
-
|
|
54
|
-
case 'ccclear':
|
|
55
|
-
runCommand('ccclear.js', commandArgs);
|
|
56
|
-
break;
|
|
57
|
-
|
|
58
|
-
case 'help':
|
|
59
|
-
case '--help':
|
|
60
|
-
case '-h':
|
|
61
|
-
showHelp();
|
|
62
|
-
break;
|
|
63
|
-
|
|
64
|
-
default:
|
|
65
|
-
if (!command) {
|
|
66
|
-
showHelp();
|
|
67
|
-
} else {
|
|
68
|
-
console.error(`❌ 未知命令: ${command}\n`);
|
|
52
|
+
if (!commands[commandName]) {
|
|
53
|
+
console.error(`❌ 未知命��: ${commandName}`);
|
|
69
54
|
showHelp();
|
|
70
55
|
process.exit(1);
|
|
71
56
|
}
|
|
57
|
+
|
|
58
|
+
if (!serviceName) {
|
|
59
|
+
if (commandName === 'install') {
|
|
60
|
+
// Init rl ONLY here for selection
|
|
61
|
+
const rl = readline.createInterface({
|
|
62
|
+
input: process.stdin,
|
|
63
|
+
output: process.stdout
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
try {
|
|
67
|
+
// Interactive service selection for 'install' command
|
|
68
|
+
console.log('\n请选择要安装的服务:');
|
|
69
|
+
const serviceKeys = Object.keys(services);
|
|
70
|
+
serviceKeys.forEach((key, index) => {
|
|
71
|
+
console.log(` [${index + 1}] ${services[key].displayName}`);
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
let chosenIndex;
|
|
75
|
+
let validChoice = false;
|
|
76
|
+
while (!validChoice) {
|
|
77
|
+
const answer = await askQuestion(rl, '请输入选项编号: ');
|
|
78
|
+
chosenIndex = parseInt(answer, 10) - 1;
|
|
79
|
+
if (chosenIndex >= 0 && chosenIndex < serviceKeys.length) {
|
|
80
|
+
serviceName = serviceKeys[chosenIndex];
|
|
81
|
+
validChoice = true;
|
|
82
|
+
} else {
|
|
83
|
+
console.log('无效的选择,请输入列表中的数字。');
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
console.log(`✅ 已选择: ${services[serviceName].displayName}`);
|
|
87
|
+
} finally {
|
|
88
|
+
// Close rl immediately after selection and BEFORE calling the command
|
|
89
|
+
rl.close();
|
|
90
|
+
}
|
|
91
|
+
} else {
|
|
92
|
+
// For 'clear' or other commands, service name is mandatory
|
|
93
|
+
console.error(`❌ 请为 '${commandName}' 命令指定一个服务名称。`);
|
|
94
|
+
showHelp();
|
|
95
|
+
process.exit(1);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
const service = services[serviceName.toLowerCase()];
|
|
100
|
+
if (!service) {
|
|
101
|
+
console.error(`❌ 未知服务: ${serviceName}`);
|
|
102
|
+
console.log('可用服务: ' + Object.keys(services).map(key => services[key].displayName).join(', '));
|
|
103
|
+
process.exit(1);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// Execute
|
|
107
|
+
await commands[commandName](service, args.slice(2));
|
|
108
|
+
} catch (error) {
|
|
109
|
+
console.error('❌ 发生错误:', error);
|
|
110
|
+
process.exit(1);
|
|
111
|
+
}
|
|
72
112
|
}
|
|
113
|
+
|
|
114
|
+
main();
|
package/bin/ccclear.js
CHANGED
|
@@ -1,55 +1,10 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
-
const
|
|
4
|
-
const
|
|
5
|
-
const fs = require('fs');
|
|
6
|
-
const { modifyHostsFile } = require('../lib/hosts');
|
|
7
|
-
const { cleanCache, getLocalTimestamp } = require('../lib/cache');
|
|
3
|
+
const clearCommand = require('../commands/clear');
|
|
4
|
+
const claudeService = require('../services/claude');
|
|
8
5
|
|
|
9
|
-
|
|
6
|
+
console.warn("⚠️ DEPRECATION WARNING: 'ccclear' is deprecated.");
|
|
7
|
+
console.warn(" Please use 'aihezu clear claude' in the future.\n");
|
|
10
8
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
try {
|
|
15
|
-
// 首先修改 hosts 文件
|
|
16
|
-
console.log('=== 步骤 1: 修改 hosts 文件 ===\n');
|
|
17
|
-
modifyHostsFile();
|
|
18
|
-
|
|
19
|
-
console.log('\n=== 步骤 2: 清理 Claude Code 缓存 ===\n');
|
|
20
|
-
|
|
21
|
-
const claudeJson = path.join(homeDir, '.claude.json');
|
|
22
|
-
const cleanedCount = cleanCache();
|
|
23
|
-
|
|
24
|
-
// 备份 .claude.json 文件
|
|
25
|
-
let hasClaudeJson = false;
|
|
26
|
-
try {
|
|
27
|
-
if (fs.existsSync(claudeJson)) {
|
|
28
|
-
const timestamp = getLocalTimestamp();
|
|
29
|
-
const backupJson = `${claudeJson}-backup-${timestamp}`;
|
|
30
|
-
console.log(`\n📦 备份 ~/.claude.json 到 ${path.basename(backupJson)}`);
|
|
31
|
-
// 使用 Node.js 原生 API,跨平台兼容
|
|
32
|
-
fs.renameSync(claudeJson, backupJson);
|
|
33
|
-
hasClaudeJson = true;
|
|
34
|
-
}
|
|
35
|
-
} catch (e) {
|
|
36
|
-
console.log('ℹ️ 未找到 ~/.claude.json 文件');
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
const totalCleaned = cleanedCount + (hasClaudeJson ? 1 : 0);
|
|
40
|
-
|
|
41
|
-
if (totalCleaned > 0) {
|
|
42
|
-
console.log(`\n✅ Claude Code 缓存已清理完成!(共处理 ${totalCleaned} 项)`);
|
|
43
|
-
console.log('💡 配置和工具已保留,下次启动 Claude Code 可直接使用');
|
|
44
|
-
console.log(`📁 备份文件保存在 ~/.claude/ 目录下`);
|
|
45
|
-
} else {
|
|
46
|
-
console.log('\n⚠️ 没有找到需要清理的缓存文件');
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
console.log('\n=== 全部完成 ===');
|
|
50
|
-
console.log('更多服务请访问 AI 合租官网:https://aihezu.dev');
|
|
51
|
-
|
|
52
|
-
} catch (error) {
|
|
53
|
-
console.error('❌ 操作失败:', error.message);
|
|
54
|
-
process.exit(1);
|
|
55
|
-
}
|
|
9
|
+
// Forward to new logic
|
|
10
|
+
clearCommand(claudeService);
|