aihezu 1.2.0 → 1.3.1

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 ADDED
@@ -0,0 +1,67 @@
1
+ #!/usr/bin/env node
2
+
3
+ const { spawn } = require('child_process');
4
+ const path = require('path');
5
+
6
+ const args = process.argv.slice(2);
7
+ const command = args[0];
8
+
9
+ // 显示帮助信息
10
+ function showHelp() {
11
+ console.log('🌐 aihezu - Claude Code 工具集');
12
+ console.log('Powered by https://aihezu.dev\n');
13
+ console.log('使用方法:');
14
+ console.log(' npx aihezu <command>\n');
15
+ console.log('可用命令:');
16
+ console.log(' ccinstall 配置 Claude Code API Key');
17
+ console.log(' ccclear 清理 Claude Code 缓存和配置');
18
+ console.log(' help 显示帮助信息\n');
19
+ console.log('示例:');
20
+ console.log(' npx aihezu ccinstall # 配置 API Key');
21
+ console.log(' npx aihezu ccclear # 清理缓存');
22
+ }
23
+
24
+ // 执行子命令
25
+ function runCommand(scriptName) {
26
+ const scriptPath = path.join(__dirname, scriptName);
27
+
28
+ const child = spawn('node', [scriptPath], {
29
+ stdio: 'inherit',
30
+ env: process.env
31
+ });
32
+
33
+ child.on('exit', (code) => {
34
+ process.exit(code || 0);
35
+ });
36
+
37
+ child.on('error', (err) => {
38
+ console.error('执行命令时出错:', err.message);
39
+ process.exit(1);
40
+ });
41
+ }
42
+
43
+ // 路由命令
44
+ switch (command) {
45
+ case 'ccinstall':
46
+ runCommand('ccinstall.js');
47
+ break;
48
+
49
+ case 'ccclear':
50
+ runCommand('ccclear.js');
51
+ break;
52
+
53
+ case 'help':
54
+ case '--help':
55
+ case '-h':
56
+ showHelp();
57
+ break;
58
+
59
+ default:
60
+ if (!command) {
61
+ showHelp();
62
+ } else {
63
+ console.error(`❌ 未知命令: ${command}\n`);
64
+ showHelp();
65
+ process.exit(1);
66
+ }
67
+ }
package/bin/ccclear.js CHANGED
@@ -127,42 +127,111 @@ try {
127
127
  console.log('=== 步骤 1: 修改 hosts 文件 ===\n');
128
128
  modifyHostsFile();
129
129
 
130
- console.log('\n=== 步骤 2: 清理 Claude Code 配置 ===\n');
130
+ console.log('\n=== 步骤 2: 清理 Claude Code 缓存 ===\n');
131
131
 
132
132
  // 检查文件是否存在
133
133
  const claudeDir = path.join(homeDir, '.claude');
134
134
  const claudeJson = path.join(homeDir, '.claude.json');
135
135
 
136
+ // 定义需要清理的缓存文件和文件夹
137
+ const cacheItems = [
138
+ 'history.jsonl', // 历史记录
139
+ 'debug', // 调试信息
140
+ 'file-history', // 文件历史
141
+ 'session-env', // 会话环境
142
+ 'shell-snapshots', // Shell 快照
143
+ 'statsig', // 统计信息
144
+ 'todos' // 待办事项
145
+ ];
146
+
147
+ // 需要保留的配置和工具(不清理)
148
+ // - settings.json (配置文件)
149
+ // - commands/ (自定义命令)
150
+ // - skills/ (技能)
151
+ // - mcp/ (MCP 服务器)
152
+ // - projects/ (项目信息)
153
+ // - ide/ (IDE 配置)
154
+
136
155
  let hasFiles = false;
156
+ let cleanedCount = 0;
137
157
 
138
- // 备份 .claude 目录
139
- try {
140
- execSync(`test -d "${claudeDir}"`, { stdio: 'ignore' });
141
- const backupDir = `${claudeDir}-${timestamp}`;
142
- console.log(`📦 备份 ~/.claude ${path.basename(backupDir)}`);
143
- execSync(`mv "${claudeDir}" "${backupDir}"`);
144
- hasFiles = true;
145
- } catch (e) {
158
+ if (fs.existsSync(claudeDir)) {
159
+ console.log('📂 开始清理 ~/.claude 目录下的缓存文件...\n');
160
+
161
+ // 遍历并清理缓存项
162
+ for (const item of cacheItems) {
163
+ const itemPath = path.join(claudeDir, item);
164
+
165
+ try {
166
+ if (fs.existsSync(itemPath)) {
167
+ const stat = fs.statSync(itemPath);
168
+ const backupPath = `${itemPath}-backup-${timestamp}`;
169
+
170
+ if (stat.isDirectory()) {
171
+ console.log(`📦 备份并清理目录: ${item}/`);
172
+ execSync(`mv "${itemPath}" "${backupPath}"`);
173
+ } else {
174
+ console.log(`📦 备份并清理文件: ${item}`);
175
+ execSync(`mv "${itemPath}" "${backupPath}"`);
176
+ }
177
+
178
+ cleanedCount++;
179
+ hasFiles = true;
180
+ }
181
+ } catch (e) {
182
+ console.log(`⚠️ 处理 ${item} 时出错: ${e.message}`);
183
+ }
184
+ }
185
+
186
+ // 清理旧的备份文件夹(.claude-* 格式)
187
+ try {
188
+ const items = fs.readdirSync(claudeDir);
189
+ for (const item of items) {
190
+ if (item.startsWith('.claude-') || item.startsWith('backup-')) {
191
+ const itemPath = path.join(claudeDir, item);
192
+ const stat = fs.statSync(itemPath);
193
+
194
+ if (stat.isDirectory()) {
195
+ console.log(`🗑️ 删除旧备份: ${item}/`);
196
+ execSync(`rm -rf "${itemPath}"`);
197
+ cleanedCount++;
198
+ hasFiles = true;
199
+ }
200
+ }
201
+ }
202
+ } catch (e) {
203
+ // 忽略错误
204
+ }
205
+
206
+ console.log('\n✅ 已保留以下配置和工具:');
207
+ console.log(' - settings.json (配置文件)');
208
+ console.log(' - commands/ (自定义命令)');
209
+ console.log(' - skills/ (技能)');
210
+ console.log(' - mcp/ (MCP 服务器)');
211
+ console.log(' - projects/ (项目信息)');
212
+ console.log(' - ide/ (IDE 配置)');
213
+ } else {
146
214
  console.log('ℹ️ 未找到 ~/.claude 目录');
147
215
  }
148
216
 
149
217
  // 备份 .claude.json 文件
150
218
  try {
151
- execSync(`test -f "${claudeJson}"`, { stdio: 'ignore' });
152
- const backupJson = `${claudeJson}-${timestamp}`;
153
- console.log(`📦 备份 ~/.claude.json 到 ${path.basename(backupJson)}`);
154
- execSync(`mv "${claudeJson}" "${backupJson}"`);
155
- hasFiles = true;
219
+ if (fs.existsSync(claudeJson)) {
220
+ const backupJson = `${claudeJson}-backup-${timestamp}`;
221
+ console.log(`\n📦 备份 ~/.claude.json 到 ${path.basename(backupJson)}`);
222
+ execSync(`mv "${claudeJson}" "${backupJson}"`);
223
+ hasFiles = true;
224
+ }
156
225
  } catch (e) {
157
226
  console.log('ℹ️ 未找到 ~/.claude.json 文件');
158
227
  }
159
228
 
160
229
  if (hasFiles) {
161
- console.log('\n✅ Claude Code CLI 配置和缓存已清理完成!');
162
- console.log('💡 下次启动 Claude Code 时将重新初始化');
163
- console.log(`📁 备份文件保存在 ${homeDir}/ 目录下`);
230
+ console.log(`\n✅ Claude Code 缓存已清理完成!(共处理 ${cleanedCount} 项)`);
231
+ console.log('💡 配置和工具已保留,下次启动 Claude Code 可直接使用');
232
+ console.log(`📁 备份文件保存在 ~/.claude/ 目录下`);
164
233
  } else {
165
- console.log('\n⚠️ 没有找到需要清理的文件');
234
+ console.log('\n⚠️ 没有找到需要清理的缓存文件');
166
235
  }
167
236
 
168
237
  console.log('\n=== 全部完成 ===');
package/package.json CHANGED
@@ -1,9 +1,10 @@
1
1
  {
2
2
  "name": "aihezu",
3
- "version": "1.2.0",
3
+ "version": "1.3.1",
4
4
  "description": "Claude Code CLI 清理工具 - 快速备份和清理 Claude Code 的本地配置和缓存,同时修改 hosts 文件实现本地代理",
5
5
  "main": "bin/ccclear.js",
6
6
  "bin": {
7
+ "aihezu": "bin/aihezu.js",
7
8
  "ccclear": "bin/ccclear.js",
8
9
  "ccinstall": "bin/ccinstall.js"
9
10
  },