aihezu 1.5.1 → 1.5.2

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 CHANGED
@@ -1,6 +1,5 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- const { execSync } = require('child_process');
4
3
  const path = require('path');
5
4
  const os = require('os');
6
5
  const fs = require('fs');
@@ -29,7 +28,8 @@ try {
29
28
  const timestamp = getLocalTimestamp();
30
29
  const backupJson = `${claudeJson}-backup-${timestamp}`;
31
30
  console.log(`\n📦 备份 ~/.claude.json 到 ${path.basename(backupJson)}`);
32
- execSync(`mv "${claudeJson}" "${backupJson}"`);
31
+ // 使用 Node.js 原生 API,跨平台兼容
32
+ fs.renameSync(claudeJson, backupJson);
33
33
  hasClaudeJson = true;
34
34
  }
35
35
  } catch (e) {
package/bin/ccinstall.js CHANGED
@@ -71,14 +71,12 @@ rl.question('您是从其他服务切换过来的吗?(y/n,如果是首次使
71
71
  }
72
72
  }
73
73
 
74
- // 确保 env 对象存在
75
- if (!settings.env) {
76
- settings.env = {};
77
- }
78
-
79
- // 设置配置
80
- settings.env.ANTHROPIC_AUTH_TOKEN = apiKey;
81
- settings.env.ANTHROPIC_BASE_URL = 'https://cc.aihezu.dev/api';
74
+ // 完全替换 env 对象,清除所有旧的环境变量配置
75
+ // 这样可以避免旧配置(如 ANTHROPIC_MODEL 等)干扰新配置
76
+ settings.env = {
77
+ ANTHROPIC_AUTH_TOKEN: apiKey,
78
+ ANTHROPIC_BASE_URL: 'https://cc.aihezu.dev/api'
79
+ };
82
80
 
83
81
  // 写入配置文件
84
82
  fs.writeFileSync(settingsPath, JSON.stringify(settings, null, 2), 'utf8');
package/lib/cache.js CHANGED
@@ -1,4 +1,3 @@
1
- const { execSync } = require('child_process');
2
1
  const path = require('path');
3
2
  const os = require('os');
4
3
  const fs = require('fs');
@@ -61,12 +60,12 @@ function cleanCache(options = {}) {
61
60
 
62
61
  if (stat.isDirectory()) {
63
62
  console.log(`📦 备份并清理目录: ${item}/`);
64
- execSync(`mv "${itemPath}" "${backupPath}"`);
65
63
  } else {
66
64
  console.log(`📦 备份并清理文件: ${item}`);
67
- execSync(`mv "${itemPath}" "${backupPath}"`);
68
65
  }
69
66
 
67
+ // 使用 Node.js 原生 API,跨平台兼容
68
+ fs.renameSync(itemPath, backupPath);
70
69
  cleanedCount++;
71
70
  }
72
71
  } catch (e) {
@@ -84,7 +83,8 @@ function cleanCache(options = {}) {
84
83
 
85
84
  if (stat.isDirectory()) {
86
85
  console.log(`🗑️ 删除旧备份: ${item}/`);
87
- execSync(`rm -rf "${itemPath}"`);
86
+ // 使用 Node.js 原生 API,跨平台兼容
87
+ fs.rmSync(itemPath, { recursive: true, force: true });
88
88
  cleanedCount++;
89
89
  }
90
90
  }
package/lib/hosts.js CHANGED
@@ -86,18 +86,37 @@ function modifyHostsFile() {
86
86
  console.log(' - api.anthropic.com -> 127.0.0.1');
87
87
 
88
88
  // 刷新 DNS 缓存
89
+ console.log('🔄 刷新 DNS 缓存...');
89
90
  try {
90
91
  if (isWindows) {
91
- execSync('ipconfig /flushdns', { stdio: 'ignore' });
92
+ // Windows: 需要管理员权限
93
+ execSync('ipconfig /flushdns', { stdio: 'pipe' });
94
+ console.log(' ✅ DNS 缓存已刷新');
92
95
  } else if (os.platform() === 'darwin') {
93
- execSync('sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder', { stdio: 'ignore' });
96
+ // macOS: 如果已经是 root/sudo 运行,直接执行;否则会失败但不影响主要功能
97
+ try {
98
+ execSync('dscacheutil -flushcache; killall -HUP mDNSResponder', { stdio: 'pipe' });
99
+ console.log(' ✅ DNS 缓存已刷新');
100
+ } catch (e) {
101
+ console.log(' ⚠️ DNS 缓存刷新失败,请稍后手动执行:');
102
+ console.log(' sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder');
103
+ }
94
104
  } else {
95
105
  // Linux
96
- execSync('sudo systemd-resolve --flush-caches 2>/dev/null || sudo service nscd restart 2>/dev/null || true', { stdio: 'ignore' });
106
+ try {
107
+ execSync('systemd-resolve --flush-caches 2>/dev/null || service nscd restart 2>/dev/null', { stdio: 'pipe' });
108
+ console.log(' ✅ DNS 缓存已刷新');
109
+ } catch (e) {
110
+ console.log(' ⚠️ DNS 缓存刷新失败,请稍后手动执行:');
111
+ console.log(' sudo systemd-resolve --flush-caches');
112
+ }
97
113
  }
98
- console.log('🔄 DNS 缓存已刷新');
99
114
  } catch (e) {
100
- console.log('ℹ️ DNS 缓存刷新失败(可能需要手动刷新)');
115
+ if (isWindows) {
116
+ console.log(' ⚠️ DNS 缓存刷新失败,请以管理员身份运行命令提示符');
117
+ } else {
118
+ console.log(' ℹ️ DNS 缓存刷新失败(可能需要 root 权限)');
119
+ }
101
120
  }
102
121
 
103
122
  return true;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aihezu",
3
- "version": "1.5.1",
3
+ "version": "1.5.2",
4
4
  "description": "Claude Code CLI 清理工具 - 快速备份和清理 Claude Code 的本地配置和缓存,同时修改 hosts 文件实现本地代理",
5
5
  "main": "bin/ccclear.js",
6
6
  "bin": {