pumpkinai-config 1.4.1 → 1.5.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/claude-api.js CHANGED
@@ -49,6 +49,16 @@ function getUserInput(question) {
49
49
  });
50
50
  }
51
51
 
52
+ // 检查 @anthropic-ai/claude-code 是否已安装
53
+ function checkClaudeInstalled() {
54
+ try {
55
+ const output = execSync('npm list -g @anthropic-ai/claude-code --depth=0', { encoding: 'utf8' });
56
+ return output.includes('@anthropic-ai/claude-code');
57
+ } catch (error) {
58
+ return false;
59
+ }
60
+ }
61
+
52
62
  // 获取 @anthropic-ai/claude-code 版本号
53
63
  function getClaudeVersion() {
54
64
  try {
@@ -65,17 +75,25 @@ function installClaude() {
65
75
  const osType = getOS();
66
76
  let command;
67
77
 
68
- log('\n[安装] 开始安装 @anthropic-ai/claude-code...', 'cyan');
78
+ log('\n[检查] 检查 @anthropic-ai/claude-code 安装状态...', 'cyan');
79
+
80
+ // 先检查是否已安装
81
+ if (checkClaudeInstalled()) {
82
+ log('[成功] @anthropic-ai/claude-code 已安装,跳过安装步骤', 'green');
83
+ return true;
84
+ }
85
+
86
+ log('[安装] 开始安装 @anthropic-ai/claude-code...', 'cyan');
69
87
 
70
88
  if (osType === 'windows') {
71
- command = 'npm install -g @anthropic-ai/claude-code@2.0.59 --registry https://registry.npmmirror.com';
89
+ command = 'npm install -g @anthropic-ai/claude-code --registry https://registry.npmmirror.com';
72
90
  } else {
73
91
  // 检查是否已经是 root 用户(通过 sudo 运行或直接 root)
74
92
  const isRoot = process.getuid && process.getuid() === 0;
75
93
  if (isRoot) {
76
- command = 'npm install -g @anthropic-ai/claude-code@2.0.59 --registry https://registry.npmmirror.com';
94
+ command = 'npm install -g @anthropic-ai/claude-code --registry https://registry.npmmirror.com';
77
95
  } else {
78
- command = 'sudo npm install -g @anthropic-ai/claude-code@2.0.59 --registry https://registry.npmmirror.com';
96
+ command = 'sudo npm install -g @anthropic-ai/claude-code --registry https://registry.npmmirror.com';
79
97
  }
80
98
  }
81
99
 
package/claude-setup.js CHANGED
@@ -49,6 +49,16 @@ function getUserInput(question) {
49
49
  });
50
50
  }
51
51
 
52
+ // 检查 @anthropic-ai/claude-code 是否已安装
53
+ function checkClaudeInstalled() {
54
+ try {
55
+ const output = execSync('npm list -g @anthropic-ai/claude-code --depth=0', { encoding: 'utf8' });
56
+ return output.includes('@anthropic-ai/claude-code');
57
+ } catch (error) {
58
+ return false;
59
+ }
60
+ }
61
+
52
62
  // 获取 @anthropic-ai/claude-code 版本号
53
63
  function getClaudeVersion() {
54
64
  try {
@@ -65,17 +75,25 @@ function installClaude() {
65
75
  const osType = getOS();
66
76
  let command;
67
77
 
68
- log('\n[安装] 开始安装 @anthropic-ai/claude-code...', 'cyan');
78
+ log('\n[检查] 检查 @anthropic-ai/claude-code 安装状态...', 'cyan');
79
+
80
+ // 先检查是否已安装
81
+ if (checkClaudeInstalled()) {
82
+ log('[成功] @anthropic-ai/claude-code 已安装,跳过安装步骤', 'green');
83
+ return true;
84
+ }
85
+
86
+ log('[安装] 开始安装 @anthropic-ai/claude-code...', 'cyan');
69
87
 
70
88
  if (osType === 'windows') {
71
- command = 'npm install -g @anthropic-ai/claude-code@2.0.59 --registry https://registry.npmmirror.com';
89
+ command = 'npm install -g @anthropic-ai/claude-code --registry https://registry.npmmirror.com';
72
90
  } else {
73
91
  // 检查是否已经是 root 用户(通过 sudo 运行或直接 root)
74
92
  const isRoot = process.getuid && process.getuid() === 0;
75
93
  if (isRoot) {
76
- command = 'npm install -g @anthropic-ai/claude-code@2.0.59 --registry https://registry.npmmirror.com';
94
+ command = 'npm install -g @anthropic-ai/claude-code --registry https://registry.npmmirror.com';
77
95
  } else {
78
- command = 'sudo npm install -g @anthropic-ai/claude-code@2.0.59 --registry https://registry.npmmirror.com';
96
+ command = 'sudo npm install -g @anthropic-ai/claude-code --registry https://registry.npmmirror.com';
79
97
  }
80
98
  }
81
99
 
package/codex-api.js CHANGED
@@ -61,6 +61,16 @@ function getUserInput(question) {
61
61
  });
62
62
  }
63
63
 
64
+ // 检查 @openai/codex 是否已安装
65
+ function checkCodexInstalled() {
66
+ try {
67
+ const output = execSync('npm list -g @openai/codex --depth=0', { encoding: 'utf8' });
68
+ return output.includes('@openai/codex');
69
+ } catch (error) {
70
+ return false;
71
+ }
72
+ }
73
+
64
74
  // 获取 @openai/codex 版本号
65
75
  function getCodexVersion() {
66
76
  try {
@@ -77,7 +87,15 @@ function installCodex() {
77
87
  const osType = getOS();
78
88
  let command;
79
89
 
80
- log('\n[安装] 开始安装 @openai/codex...', 'cyan');
90
+ log('\n[检查] 检查 @openai/codex 安装状态...', 'cyan');
91
+
92
+ // 先检查是否已安装
93
+ if (checkCodexInstalled()) {
94
+ log('[成功] @openai/codex 已安装,跳过安装步骤', 'green');
95
+ return true;
96
+ }
97
+
98
+ log('[安装] 开始安装 @openai/codex...', 'cyan');
81
99
 
82
100
  if (osType === 'windows') {
83
101
  command = 'npm install -g @openai/codex --registry https://registry.npmmirror.com';
package/codex-setup.js CHANGED
@@ -61,6 +61,16 @@ function getUserInput(question) {
61
61
  });
62
62
  }
63
63
 
64
+ // 检查 @openai/codex 是否已安装
65
+ function checkCodexInstalled() {
66
+ try {
67
+ const output = execSync('npm list -g @openai/codex --depth=0', { encoding: 'utf8' });
68
+ return output.includes('@openai/codex');
69
+ } catch (error) {
70
+ return false;
71
+ }
72
+ }
73
+
64
74
  // 获取 @openai/codex 版本号
65
75
  function getCodexVersion() {
66
76
  try {
@@ -77,7 +87,15 @@ function installCodex() {
77
87
  const osType = getOS();
78
88
  let command;
79
89
 
80
- log('\n[安装] 开始安装 @openai/codex...', 'cyan');
90
+ log('\n[检查] 检查 @openai/codex 安装状态...', 'cyan');
91
+
92
+ // 先检查是否已安装
93
+ if (checkCodexInstalled()) {
94
+ log('[成功] @openai/codex 已安装,跳过安装步骤', 'green');
95
+ return true;
96
+ }
97
+
98
+ log('[安装] 开始安装 @openai/codex...', 'cyan');
81
99
 
82
100
  if (osType === 'windows') {
83
101
  command = 'npm install -g @openai/codex --registry https://registry.npmmirror.com';
package/package.json CHANGED
@@ -1,14 +1,17 @@
1
1
  {
2
2
  "name": "pumpkinai-config",
3
- "version": "1.4.1",
3
+ "version": "1.5.0",
4
4
  "description": "PumpkinAI 一键安装配置工具 - 支持 Codex 和 Claude Code",
5
- "main": "main-config.js",
5
+ "main": "codex-setup.js",
6
6
  "bin": {
7
- "main-config": "./main-config.js"
7
+ "codex-config": "./codex-setup.js",
8
+ "codex-api": "./codex-api.js",
9
+ "claude-config": "./claude-setup.js",
10
+ "claude-api": "./claude-api.js"
8
11
  },
9
12
  "scripts": {
10
- "test": "node main-config.js",
11
- "start": "node main-config.js"
13
+ "test": "node codex-setup.js",
14
+ "start": "node codex-setup.js"
12
15
  },
13
16
  "keywords": [
14
17
  "codex",
package/claude-fix.js DELETED
@@ -1,138 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- /**
4
- * Claude Code 报错修复工具
5
- * 彻底清理并重新安装 Claude Code
6
- */
7
-
8
- const fs = require('fs');
9
- const path = require('path');
10
- const os = require('os');
11
- const { execSync } = require('child_process');
12
-
13
- // 颜色输出
14
- const colors = {
15
- red: '\x1b[31m',
16
- green: '\x1b[32m',
17
- yellow: '\x1b[33m',
18
- blue: '\x1b[34m',
19
- magenta: '\x1b[35m',
20
- cyan: '\x1b[36m',
21
- reset: '\x1b[0m',
22
- dim: '\x1b[2m'
23
- };
24
-
25
- function log(message, color = 'reset') {
26
- console.log(`${colors[color]}${message}${colors.reset}`);
27
- }
28
-
29
- // 获取用户目录
30
- function getHomeDir() {
31
- if (process.platform !== 'win32' && process.env.SUDO_USER) {
32
- const actualUser = process.env.SUDO_USER;
33
- return process.platform === 'darwin' ? `/Users/${actualUser}` : `/home/${actualUser}`;
34
- }
35
- return os.homedir();
36
- }
37
-
38
- // 彻底重新安装 Claude Code
39
- async function reinstallClaudeCode() {
40
- console.clear();
41
- log('\n[报错修复] 开始彻底重新安装 Claude Code...\n', 'cyan');
42
-
43
- const homeDir = getHomeDir();
44
-
45
- // 1. 删除 .claude 文件夹
46
- const claudeDir = path.join(homeDir, '.claude');
47
- if (fs.existsSync(claudeDir)) {
48
- log('[清理] 删除 .claude 文件夹...', 'yellow');
49
- try {
50
- fs.rmSync(claudeDir, { recursive: true, force: true });
51
- log('[成功] .claude 文件夹已删除', 'green');
52
- } catch (error) {
53
- log(`[警告] 删除 .claude 文件夹失败: ${error.message}`, 'yellow');
54
- }
55
- } else {
56
- log('[跳过] .claude 文件夹不存在', 'dim');
57
- }
58
-
59
- // 2. 删除 .claude.json
60
- const claudeJson = path.join(homeDir, '.claude.json');
61
- if (fs.existsSync(claudeJson)) {
62
- log('[清理] 删除 .claude.json...', 'yellow');
63
- try {
64
- fs.unlinkSync(claudeJson);
65
- log('[成功] .claude.json 已删除', 'green');
66
- } catch (error) {
67
- log(`[警告] 删除 .claude.json 失败: ${error.message}`, 'yellow');
68
- }
69
- } else {
70
- log('[跳过] .claude.json 不存在', 'dim');
71
- }
72
-
73
- // 3. 删除 .claude.json.backup
74
- const claudeJsonBackup = path.join(homeDir, '.claude.json.backup');
75
- if (fs.existsSync(claudeJsonBackup)) {
76
- log('[清理] 删除 .claude.json.backup...', 'yellow');
77
- try {
78
- fs.unlinkSync(claudeJsonBackup);
79
- log('[成功] .claude.json.backup 已删除', 'green');
80
- } catch (error) {
81
- log(`[警告] 删除 .claude.json.backup 失败: ${error.message}`, 'yellow');
82
- }
83
- } else {
84
- log('[跳过] .claude.json.backup 不存在', 'dim');
85
- }
86
-
87
- // 4. 卸载 claude-code
88
- log('\n[卸载] 卸载 @anthropic-ai/claude-code...', 'yellow');
89
- try {
90
- const osType = process.platform;
91
- let uninstallCmd;
92
- if (osType === 'win32') {
93
- uninstallCmd = 'npm uninstall -g @anthropic-ai/claude-code';
94
- } else {
95
- const isRoot = process.getuid && process.getuid() === 0;
96
- uninstallCmd = isRoot ? 'npm uninstall -g @anthropic-ai/claude-code' : 'sudo npm uninstall -g @anthropic-ai/claude-code';
97
- }
98
- execSync(uninstallCmd, { stdio: 'inherit' });
99
- log('[成功] @anthropic-ai/claude-code 已卸载', 'green');
100
- } catch (error) {
101
- log('[提示] 卸载过程中出现问题,可能未安装', 'yellow');
102
- }
103
-
104
- log('\n[完成] 清理完成,现在请选择套餐重新安装配置\n', 'green');
105
- }
106
-
107
- // 主函数
108
- async function main() {
109
- await reinstallClaudeCode();
110
-
111
- // 等待用户按键
112
- log('按任意键返回菜单...', 'dim');
113
-
114
- return new Promise((resolve) => {
115
- if (process.stdin.isTTY) {
116
- process.stdin.setRawMode(true);
117
- }
118
- process.stdin.resume();
119
- process.stdin.once('data', () => {
120
- if (process.stdin.isTTY) {
121
- process.stdin.setRawMode(false);
122
- }
123
- resolve();
124
- });
125
- });
126
- }
127
-
128
- // 如果直接运行此脚本
129
- if (require.main === module) {
130
- main().then(() => {
131
- process.exit(0);
132
- }).catch(error => {
133
- log(`\n[错误] ${error.message}`, 'red');
134
- process.exit(1);
135
- });
136
- }
137
-
138
- module.exports = { main, reinstallClaudeCode };
package/claude-network.js DELETED
@@ -1,372 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- /**
4
- * Claude Code 网络修复工具
5
- * 检测当前域名并允许切换到备用域名
6
- */
7
-
8
- const fs = require('fs');
9
- const path = require('path');
10
- const os = require('os');
11
- const { execSync } = require('child_process');
12
-
13
- // 颜色输出
14
- const colors = {
15
- red: '\x1b[31m',
16
- green: '\x1b[32m',
17
- yellow: '\x1b[33m',
18
- blue: '\x1b[34m',
19
- magenta: '\x1b[35m',
20
- cyan: '\x1b[36m',
21
- reset: '\x1b[0m',
22
- dim: '\x1b[2m',
23
- bright: '\x1b[1m'
24
- };
25
-
26
- function log(message, color = 'reset') {
27
- console.log(`${colors[color]}${message}${colors.reset}`);
28
- }
29
-
30
- // 可用域名列表
31
- const domainOptions = [
32
- { name: '主域名', url: 'https://code.ppchat.vip' },
33
- { name: '备用域名1', url: 'https://code2.ppchat.vip' },
34
- { name: '备用域名2', url: 'https://code.pumpkinai.vip' },
35
- { name: '清理DNS缓存-推荐', url: 'dns_flush' }
36
- ];
37
-
38
- // 检测操作系统
39
- function getOS() {
40
- const platform = os.platform();
41
- if (platform === 'win32') return 'windows';
42
- if (platform === 'darwin') return 'mac';
43
- return 'linux';
44
- }
45
-
46
- // 获取用户目录
47
- function getHomeDir() {
48
- if (process.platform !== 'win32' && process.env.SUDO_USER) {
49
- const actualUser = process.env.SUDO_USER;
50
- return process.platform === 'darwin' ? `/Users/${actualUser}` : `/home/${actualUser}`;
51
- }
52
- return os.homedir();
53
- }
54
-
55
- // 获取当前使用的域名
56
- function getCurrentDomain() {
57
- const homeDir = getHomeDir();
58
- const settingsPath = path.join(homeDir, '.claude', 'settings.json');
59
-
60
- // 优先从 settings.json 读取
61
- if (fs.existsSync(settingsPath)) {
62
- try {
63
- const settings = JSON.parse(fs.readFileSync(settingsPath, 'utf8'));
64
- if (settings.env && settings.env.ANTHROPIC_BASE_URL) {
65
- return settings.env.ANTHROPIC_BASE_URL;
66
- }
67
- } catch (error) {}
68
- }
69
-
70
- // 从环境变量读取
71
- if (process.env.ANTHROPIC_BASE_URL) {
72
- return process.env.ANTHROPIC_BASE_URL;
73
- }
74
-
75
- return null;
76
- }
77
-
78
- // 更新 settings.json 中的域名
79
- function updateSettingsJson(newUrl) {
80
- const homeDir = getHomeDir();
81
- const settingsPath = path.join(homeDir, '.claude', 'settings.json');
82
-
83
- try {
84
- if (fs.existsSync(settingsPath)) {
85
- const settings = JSON.parse(fs.readFileSync(settingsPath, 'utf8'));
86
- if (!settings.env) settings.env = {};
87
- settings.env.ANTHROPIC_BASE_URL = newUrl;
88
- fs.writeFileSync(settingsPath, JSON.stringify(settings, null, 2), 'utf8');
89
-
90
- // 如果是通过 sudo 运行的,修改文件所有者
91
- if (process.platform !== 'win32' && process.env.SUDO_USER) {
92
- const actualUser = process.env.SUDO_USER;
93
- const group = process.platform === 'darwin' ? 'staff' : actualUser;
94
- try {
95
- execSync(`chown ${actualUser}:${group} ${settingsPath}`);
96
- } catch (error) {}
97
- }
98
-
99
- return true;
100
- }
101
- } catch (error) {
102
- log(`[警告] 更新 settings.json 失败: ${error.message}`, 'yellow');
103
- }
104
- return false;
105
- }
106
-
107
- // 更新系统环境变量中的域名
108
- function updateSystemEnv(newUrl) {
109
- const osType = getOS();
110
- const homeDir = getHomeDir();
111
-
112
- try {
113
- if (osType === 'windows') {
114
- execSync(`setx ANTHROPIC_BASE_URL "${newUrl}"`, { stdio: 'pipe' });
115
- return true;
116
- } else if (osType === 'mac') {
117
- const zshrcPath = path.join(homeDir, '.zshrc');
118
- if (fs.existsSync(zshrcPath)) {
119
- let content = fs.readFileSync(zshrcPath, 'utf8');
120
- const regex = /export ANTHROPIC_BASE_URL=.*/g;
121
- if (content.match(regex)) {
122
- content = content.replace(regex, `export ANTHROPIC_BASE_URL="${newUrl}"`);
123
- fs.writeFileSync(zshrcPath, content, 'utf8');
124
-
125
- if (process.env.SUDO_USER) {
126
- const actualUser = process.env.SUDO_USER;
127
- try {
128
- execSync(`chown ${actualUser}:staff ${zshrcPath}`);
129
- } catch (error) {}
130
- }
131
- return true;
132
- }
133
- }
134
- } else {
135
- const bashrcPath = path.join(homeDir, '.bashrc');
136
- if (fs.existsSync(bashrcPath)) {
137
- let content = fs.readFileSync(bashrcPath, 'utf8');
138
- const regex = /export ANTHROPIC_BASE_URL=.*/g;
139
- if (content.match(regex)) {
140
- content = content.replace(regex, `export ANTHROPIC_BASE_URL="${newUrl}"`);
141
- fs.writeFileSync(bashrcPath, content, 'utf8');
142
-
143
- if (process.env.SUDO_USER) {
144
- const actualUser = process.env.SUDO_USER;
145
- try {
146
- execSync(`chown ${actualUser}:${actualUser} ${bashrcPath}`);
147
- } catch (error) {}
148
- }
149
- return true;
150
- }
151
- }
152
- }
153
- } catch (error) {
154
- log(`[警告] 更新系统环境变量失败: ${error.message}`, 'yellow');
155
- }
156
- return false;
157
- }
158
-
159
- // 清理 DNS 缓存
160
- function flushDnsCache() {
161
- const osType = getOS();
162
- log('\n[DNS] 正在清理 DNS 缓存...', 'cyan');
163
-
164
- try {
165
- if (osType === 'windows') {
166
- execSync('ipconfig /flushdns', { stdio: 'pipe' });
167
- log('[成功] DNS 缓存已清理 (ipconfig /flushdns)', 'green');
168
- } else if (osType === 'mac') {
169
- // macOS 需要 sudo 权限
170
- const isRoot = process.getuid && process.getuid() === 0;
171
- if (isRoot) {
172
- execSync('dscacheutil -flushcache && killall -HUP mDNSResponder', { stdio: 'pipe' });
173
- } else {
174
- execSync('sudo dscacheutil -flushcache && sudo killall -HUP mDNSResponder', { stdio: 'pipe' });
175
- }
176
- log('[成功] DNS 缓存已清理 (dscacheutil -flushcache)', 'green');
177
- } else {
178
- // Linux - 不同发行版命令不同,尝试常见的
179
- const isRoot = process.getuid && process.getuid() === 0;
180
- try {
181
- if (isRoot) {
182
- execSync('systemd-resolve --flush-caches 2>/dev/null || resolvectl flush-caches 2>/dev/null || true', { stdio: 'pipe' });
183
- } else {
184
- execSync('sudo systemd-resolve --flush-caches 2>/dev/null || sudo resolvectl flush-caches 2>/dev/null || true', { stdio: 'pipe' });
185
- }
186
- log('[成功] DNS 缓存已清理', 'green');
187
- } catch (e) {
188
- log('[提示] DNS 缓存清理命令不适用于此系统,已跳过', 'yellow');
189
- }
190
- }
191
- return true;
192
- } catch (error) {
193
- log(`[警告] DNS 缓存清理失败: ${error.message}`, 'yellow');
194
- return false;
195
- }
196
- }
197
-
198
- // 切换域名
199
- function switchDomain(newUrl) {
200
- log(`\n[切换] 正在切换到: ${newUrl}`, 'cyan');
201
-
202
- // 1. 更新 settings.json
203
- const settingsUpdated = updateSettingsJson(newUrl);
204
- if (settingsUpdated) {
205
- log('[成功] settings.json 已更新', 'green');
206
- } else {
207
- log('[跳过] settings.json 不存在或更新失败', 'yellow');
208
- }
209
-
210
- // 2. 更新系统环境变量
211
- const envUpdated = updateSystemEnv(newUrl);
212
- if (envUpdated) {
213
- log('[成功] 系统环境变量已更新', 'green');
214
- } else {
215
- log('[跳过] 系统环境变量更新失败或不存在', 'yellow');
216
- }
217
-
218
- if (settingsUpdated || envUpdated) {
219
- log('\n[完成] 域名切换成功!', 'green');
220
- const osType = getOS();
221
- if (osType === 'windows') {
222
- log('[提示] 请重新打开终端使环境变量生效', 'yellow');
223
- } else if (osType === 'mac') {
224
- log('[提示] 请重新打开终端或运行: source ~/.zshrc', 'yellow');
225
- } else {
226
- log('[提示] 请重新打开终端或运行: source ~/.bashrc', 'yellow');
227
- }
228
- } else {
229
- log('\n[警告] 没有配置文件被更新,请先运行安装配置', 'yellow');
230
- }
231
- }
232
-
233
- let selectedIndex = 0;
234
-
235
- // 渲染域名选择菜单
236
- function renderMenu() {
237
- console.clear();
238
- log('\n', 'reset');
239
- log(' ' + '='.repeat(54), 'cyan');
240
- log(' 网络修复 - 域名切换', 'magenta');
241
- log(' ' + '='.repeat(54), 'cyan');
242
- log('', 'reset');
243
-
244
- const currentDomain = getCurrentDomain();
245
-
246
- log(' 请选择要使用的域名 (↑↓选择, Enter确认, ESC返回):\n', 'cyan');
247
-
248
- domainOptions.forEach((option, index) => {
249
- const isSelected = index === selectedIndex;
250
- const prefix = isSelected ? ' ▶ ' : ' ';
251
- const nameColor = isSelected ? '\x1b[1m\x1b[33m' : '\x1b[0m';
252
- const numLabel = `${index + 1}. `;
253
-
254
- // 检查是否是当前使用的域名
255
- const isCurrent = option.url && currentDomain === option.url;
256
- const currentIndicator = isCurrent ? ' \x1b[32m← 当前使用\x1b[0m' : '';
257
-
258
- console.log(`${prefix}${nameColor}${numLabel}${option.name}${currentIndicator}\x1b[0m`);
259
- if (option.url && option.url !== 'dns_flush') {
260
- const descColor = isSelected ? '\x1b[36m' : '\x1b[2m';
261
- console.log(` ${descColor}${option.url}\x1b[0m`);
262
- }
263
- console.log('');
264
- });
265
-
266
- log(' ' + '='.repeat(54), 'cyan');
267
-
268
- if (currentDomain) {
269
- log(`\n 当前域名: ${currentDomain}`, 'dim');
270
- } else {
271
- log('\n 当前域名: 未配置', 'dim');
272
- }
273
- }
274
-
275
- // 主函数
276
- async function main() {
277
- // 启用原始模式以捕获按键
278
- if (process.stdin.isTTY) {
279
- process.stdin.setRawMode(true);
280
- }
281
- process.stdin.resume();
282
- process.stdin.setEncoding('utf8');
283
-
284
- renderMenu();
285
-
286
- return new Promise((resolve) => {
287
- const handleKeyPress = (key) => {
288
- // Ctrl+C 退出
289
- if (key === '\u0003') {
290
- console.clear();
291
- process.exit(0);
292
- }
293
-
294
- // ESC 返回
295
- if (key === '\u001b') {
296
- if (process.stdin.isTTY) {
297
- process.stdin.setRawMode(false);
298
- }
299
- process.stdin.removeAllListeners('data');
300
- resolve(false);
301
- return;
302
- }
303
-
304
- // 上箭头
305
- if (key === '\u001b[A' || key === 'k') {
306
- selectedIndex = selectedIndex > 0 ? selectedIndex - 1 : domainOptions.length - 1;
307
- renderMenu();
308
- }
309
-
310
- // 下箭头
311
- if (key === '\u001b[B' || key === 'j') {
312
- selectedIndex = selectedIndex < domainOptions.length - 1 ? selectedIndex + 1 : 0;
313
- renderMenu();
314
- }
315
-
316
- // Enter 确认
317
- if (key === '\r' || key === '\n') {
318
- const selected = domainOptions[selectedIndex];
319
-
320
- // 切换域名
321
- if (process.stdin.isTTY) {
322
- process.stdin.setRawMode(false);
323
- }
324
- process.stdin.removeAllListeners('data');
325
-
326
- // 根据选项执行不同操作
327
- if (selected.url === 'dns_flush') {
328
- flushDnsCache();
329
- } else {
330
- switchDomain(selected.url);
331
- }
332
-
333
- // 等待用户按键返回
334
- log('\n按任意键返回菜单...', 'dim');
335
-
336
- if (process.stdin.isTTY) {
337
- process.stdin.setRawMode(true);
338
- }
339
- process.stdin.resume();
340
- process.stdin.once('data', () => {
341
- if (process.stdin.isTTY) {
342
- process.stdin.setRawMode(false);
343
- }
344
- selectedIndex = 0;
345
- resolve(false);
346
- });
347
- return;
348
- }
349
-
350
- // 数字键快捷选择
351
- const num = parseInt(key);
352
- if (num >= 1 && num <= domainOptions.length) {
353
- selectedIndex = num - 1;
354
- renderMenu();
355
- }
356
- };
357
-
358
- process.stdin.on('data', handleKeyPress);
359
- });
360
- }
361
-
362
- // 如果直接运行此脚本
363
- if (require.main === module) {
364
- main().then(() => {
365
- process.exit(0);
366
- }).catch(error => {
367
- log(`\n[错误] ${error.message}`, 'red');
368
- process.exit(1);
369
- });
370
- }
371
-
372
- module.exports = { main, getCurrentDomain, switchDomain };
package/codex-network.js DELETED
@@ -1,307 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- /**
4
- * Codex 网络修复工具
5
- * 检测当前域名并允许切换到备用域名
6
- * 只修改 config.toml 配置文件,不修改环境变量
7
- */
8
-
9
- const fs = require('fs');
10
- const path = require('path');
11
- const os = require('os');
12
- const { execSync } = require('child_process');
13
-
14
- // 颜色输出
15
- const colors = {
16
- red: '\x1b[31m',
17
- green: '\x1b[32m',
18
- yellow: '\x1b[33m',
19
- blue: '\x1b[34m',
20
- magenta: '\x1b[35m',
21
- cyan: '\x1b[36m',
22
- reset: '\x1b[0m',
23
- dim: '\x1b[2m',
24
- bright: '\x1b[1m'
25
- };
26
-
27
- function log(message, color = 'reset') {
28
- console.log(`${colors[color]}${message}${colors.reset}`);
29
- }
30
-
31
- // 可用域名列表 (Codex 使用 /v1 后缀)
32
- const domainOptions = [
33
- { name: '主域名', url: 'https://code.ppchat.vip/v1' },
34
- { name: '备用域名1', url: 'https://code2.ppchat.vip/v1' },
35
- { name: '备用域名2', url: 'https://code.pumpkinai.vip/v1' },
36
- { name: '清理DNS缓存-推荐', url: 'dns_flush' }
37
- ];
38
-
39
- // 检测操作系统
40
- function getOS() {
41
- const platform = os.platform();
42
- if (platform === 'win32') return 'windows';
43
- if (platform === 'darwin') return 'mac';
44
- return 'linux';
45
- }
46
-
47
- // 获取用户目录
48
- function getHomeDir() {
49
- if (process.platform !== 'win32' && process.env.SUDO_USER) {
50
- const actualUser = process.env.SUDO_USER;
51
- return process.platform === 'darwin' ? `/Users/${actualUser}` : `/home/${actualUser}`;
52
- }
53
- return os.homedir();
54
- }
55
-
56
- // 获取当前使用的域名 (从 config.toml 读取)
57
- function getCurrentDomain() {
58
- const homeDir = getHomeDir();
59
- const configPath = path.join(homeDir, '.codex', 'config.toml');
60
-
61
- if (fs.existsSync(configPath)) {
62
- try {
63
- const content = fs.readFileSync(configPath, 'utf8');
64
- // 匹配 base_url = "xxx" 格式
65
- const match = content.match(/base_url\s*=\s*"([^"]+)"/);
66
- if (match) {
67
- return match[1];
68
- }
69
- } catch (error) {}
70
- }
71
-
72
- return null;
73
- }
74
-
75
- // 更新 config.toml 中的域名
76
- function updateConfigToml(newUrl) {
77
- const homeDir = getHomeDir();
78
- const configPath = path.join(homeDir, '.codex', 'config.toml');
79
-
80
- try {
81
- if (fs.existsSync(configPath)) {
82
- let content = fs.readFileSync(configPath, 'utf8');
83
-
84
- // 替换 base_url 的值
85
- const regex = /base_url\s*=\s*"[^"]+"/;
86
- if (content.match(regex)) {
87
- content = content.replace(regex, `base_url = "${newUrl}"`);
88
- fs.writeFileSync(configPath, content, 'utf8');
89
-
90
- // 如果是通过 sudo 运行的,修改文件所有者
91
- if (process.platform !== 'win32' && process.env.SUDO_USER) {
92
- const actualUser = process.env.SUDO_USER;
93
- const group = process.platform === 'darwin' ? 'staff' : actualUser;
94
- try {
95
- execSync(`chown ${actualUser}:${group} ${configPath}`);
96
- } catch (error) {}
97
- }
98
-
99
- return true;
100
- } else {
101
- log('[警告] config.toml 中未找到 base_url 配置', 'yellow');
102
- return false;
103
- }
104
- } else {
105
- log('[警告] config.toml 文件不存在,请先运行安装配置', 'yellow');
106
- return false;
107
- }
108
- } catch (error) {
109
- log(`[警告] 更新 config.toml 失败: ${error.message}`, 'yellow');
110
- }
111
- return false;
112
- }
113
-
114
- // 清理 DNS 缓存
115
- function flushDnsCache() {
116
- const osType = getOS();
117
- log('\n[DNS] 正在清理 DNS 缓存...', 'cyan');
118
-
119
- try {
120
- if (osType === 'windows') {
121
- execSync('ipconfig /flushdns', { stdio: 'pipe' });
122
- log('[成功] DNS 缓存已清理 (ipconfig /flushdns)', 'green');
123
- } else if (osType === 'mac') {
124
- // macOS 需要 sudo 权限
125
- const isRoot = process.getuid && process.getuid() === 0;
126
- if (isRoot) {
127
- execSync('dscacheutil -flushcache && killall -HUP mDNSResponder', { stdio: 'pipe' });
128
- } else {
129
- execSync('sudo dscacheutil -flushcache && sudo killall -HUP mDNSResponder', { stdio: 'pipe' });
130
- }
131
- log('[成功] DNS 缓存已清理 (dscacheutil -flushcache)', 'green');
132
- } else {
133
- // Linux - 不同发行版命令不同,尝试常见的
134
- const isRoot = process.getuid && process.getuid() === 0;
135
- try {
136
- if (isRoot) {
137
- execSync('systemd-resolve --flush-caches 2>/dev/null || resolvectl flush-caches 2>/dev/null || true', { stdio: 'pipe' });
138
- } else {
139
- execSync('sudo systemd-resolve --flush-caches 2>/dev/null || sudo resolvectl flush-caches 2>/dev/null || true', { stdio: 'pipe' });
140
- }
141
- log('[成功] DNS 缓存已清理', 'green');
142
- } catch (e) {
143
- log('[提示] DNS 缓存清理命令不适用于此系统,已跳过', 'yellow');
144
- }
145
- }
146
- return true;
147
- } catch (error) {
148
- log(`[警告] DNS 缓存清理失败: ${error.message}`, 'yellow');
149
- return false;
150
- }
151
- }
152
-
153
- // 切换域名
154
- function switchDomain(newUrl) {
155
- log(`\n[切换] 正在切换到: ${newUrl}`, 'cyan');
156
-
157
- // 更新 config.toml
158
- const configUpdated = updateConfigToml(newUrl);
159
- if (configUpdated) {
160
- log('[成功] config.toml 已更新', 'green');
161
- log('\n[完成] 域名切换成功!', 'green');
162
- log('[提示] 新域名将在下次启动 Codex 时生效', 'yellow');
163
- } else {
164
- log('\n[警告] 配置文件更新失败,请先运行安装配置', 'yellow');
165
- }
166
- }
167
-
168
- let selectedIndex = 0;
169
-
170
- // 渲染域名选择菜单
171
- function renderMenu() {
172
- console.clear();
173
- log('\n', 'reset');
174
- log(' ' + '='.repeat(54), 'cyan');
175
- log(' Codex 网络修复 - 域名切换', 'magenta');
176
- log(' ' + '='.repeat(54), 'cyan');
177
- log('', 'reset');
178
-
179
- const currentDomain = getCurrentDomain();
180
-
181
- log(' 请选择要使用的域名 (↑↓选择, Enter确认, ESC返回):\n', 'cyan');
182
-
183
- domainOptions.forEach((option, index) => {
184
- const isSelected = index === selectedIndex;
185
- const prefix = isSelected ? ' ▶ ' : ' ';
186
- const nameColor = isSelected ? '\x1b[1m\x1b[33m' : '\x1b[0m';
187
- const numLabel = `${index + 1}. `;
188
-
189
- // 检查是否是当前使用的域名
190
- const isCurrent = option.url && currentDomain === option.url;
191
- const currentIndicator = isCurrent ? ' \x1b[32m← 当前使用\x1b[0m' : '';
192
-
193
- console.log(`${prefix}${nameColor}${numLabel}${option.name}${currentIndicator}\x1b[0m`);
194
- if (option.url && option.url !== 'dns_flush') {
195
- const descColor = isSelected ? '\x1b[36m' : '\x1b[2m';
196
- console.log(` ${descColor}${option.url}\x1b[0m`);
197
- }
198
- console.log('');
199
- });
200
-
201
- log(' ' + '='.repeat(54), 'cyan');
202
-
203
- if (currentDomain) {
204
- log(`\n 当前域名: ${currentDomain}`, 'dim');
205
- } else {
206
- log('\n 当前域名: 未配置', 'dim');
207
- }
208
- }
209
-
210
- // 主函数
211
- async function main() {
212
- // 启用原始模式以捕获按键
213
- if (process.stdin.isTTY) {
214
- process.stdin.setRawMode(true);
215
- }
216
- process.stdin.resume();
217
- process.stdin.setEncoding('utf8');
218
-
219
- renderMenu();
220
-
221
- return new Promise((resolve) => {
222
- const handleKeyPress = (key) => {
223
- // Ctrl+C 退出
224
- if (key === '\u0003') {
225
- console.clear();
226
- process.exit(0);
227
- }
228
-
229
- // ESC 返回
230
- if (key === '\u001b') {
231
- if (process.stdin.isTTY) {
232
- process.stdin.setRawMode(false);
233
- }
234
- process.stdin.removeAllListeners('data');
235
- resolve(false);
236
- return;
237
- }
238
-
239
- // 上箭头
240
- if (key === '\u001b[A' || key === 'k') {
241
- selectedIndex = selectedIndex > 0 ? selectedIndex - 1 : domainOptions.length - 1;
242
- renderMenu();
243
- }
244
-
245
- // 下箭头
246
- if (key === '\u001b[B' || key === 'j') {
247
- selectedIndex = selectedIndex < domainOptions.length - 1 ? selectedIndex + 1 : 0;
248
- renderMenu();
249
- }
250
-
251
- // Enter 确认
252
- if (key === '\r' || key === '\n') {
253
- const selected = domainOptions[selectedIndex];
254
-
255
- // 切换域名
256
- if (process.stdin.isTTY) {
257
- process.stdin.setRawMode(false);
258
- }
259
- process.stdin.removeAllListeners('data');
260
-
261
- // 根据选项执行不同操作
262
- if (selected.url === 'dns_flush') {
263
- flushDnsCache();
264
- } else {
265
- switchDomain(selected.url);
266
- }
267
-
268
- // 等待用户按键返回
269
- log('\n按任意键返回菜单...', 'dim');
270
-
271
- if (process.stdin.isTTY) {
272
- process.stdin.setRawMode(true);
273
- }
274
- process.stdin.resume();
275
- process.stdin.once('data', () => {
276
- if (process.stdin.isTTY) {
277
- process.stdin.setRawMode(false);
278
- }
279
- selectedIndex = 0;
280
- resolve(false);
281
- });
282
- return;
283
- }
284
-
285
- // 数字键快捷选择
286
- const num = parseInt(key);
287
- if (num >= 1 && num <= domainOptions.length) {
288
- selectedIndex = num - 1;
289
- renderMenu();
290
- }
291
- };
292
-
293
- process.stdin.on('data', handleKeyPress);
294
- });
295
- }
296
-
297
- // 如果直接运行此脚本
298
- if (require.main === module) {
299
- main().then(() => {
300
- process.exit(0);
301
- }).catch(error => {
302
- log(`\n[错误] ${error.message}`, 'red');
303
- process.exit(1);
304
- });
305
- }
306
-
307
- module.exports = { main, getCurrentDomain, switchDomain };
package/main-config.js DELETED
@@ -1,371 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- /**
4
- * PumpkinAI 一键安装配置工具
5
- * 整合 Claude Code 和 Codex 的安装配置
6
- */
7
-
8
- // 颜色输出
9
- const colors = {
10
- red: '\x1b[31m',
11
- green: '\x1b[32m',
12
- yellow: '\x1b[33m',
13
- blue: '\x1b[34m',
14
- magenta: '\x1b[35m',
15
- cyan: '\x1b[36m',
16
- reset: '\x1b[0m',
17
- dim: '\x1b[2m',
18
- bright: '\x1b[1m'
19
- };
20
-
21
- function log(message, color = 'reset') {
22
- console.log(`${colors[color]}${message}${colors.reset}`);
23
- }
24
-
25
- // 主菜单选项
26
- const mainMenuOptions = [
27
- { name: 'Claude Code', desc: 'Anthropic Claude AI 编程助手' },
28
- { name: 'Codex', desc: 'OpenAI Codex 编程助手' },
29
- { name: '退出', desc: '' }
30
- ];
31
-
32
- // Claude Code 子菜单选项
33
- const claudeSubMenuOptions = [
34
- { name: '按请求计费套餐', desc: 'API地址: https://code.ppchat.vip' },
35
- { name: '按token计费套餐', desc: 'API地址: https://new.aicode.us.com' },
36
- { name: '报错修复', desc: '' }
37
- ];
38
-
39
- // Codex 子菜单选项
40
- const codexSubMenuOptions = [
41
- { name: '按请求计费套餐', desc: 'API地址: https://code.ppchat.vip/v1' },
42
- { name: '按量token计费套餐', desc: 'API地址: https://new.aicode.us.com/v1' },
43
- { name: '报错修复', desc: '' }
44
- ];
45
-
46
- // 报错修复子菜单选项 (Claude)
47
- const fixSubMenuOptions = [
48
- { name: '彻底重新安装', desc: '删除所有配置并重装 Claude Code' },
49
- { name: '网络修复', desc: '切换API域名 (主域名/备用域名)' }
50
- ];
51
-
52
- // 报错修复子菜单选项 (Codex)
53
- const codexFixSubMenuOptions = [
54
- { name: '网络修复', desc: '切换API域名 (主域名/备用域名)' }
55
- ];
56
-
57
- // 脚本映射
58
- const scriptMap = {
59
- 'Claude Code': {
60
- '按请求计费套餐': './claude-setup.js',
61
- '按量token计费套餐': './claude-api.js'
62
- },
63
- 'Codex': {
64
- '按请求计费套餐': './codex-setup.js',
65
- '按token计费套餐': './codex-api.js'
66
- }
67
- };
68
-
69
- let selectedIndex = 0;
70
- let currentMenu = 'main'; // 'main', 'claude_sub', 'codex_sub', 'fix_sub', 'codex_fix_sub'
71
-
72
- // 显示 Logo
73
- function showLogo() {
74
- console.log(' \x1b[38;5;208m██████╗ \x1b[38;5;214m██╗ ██╗\x1b[38;5;220m███╗ ███╗\x1b[38;5;226m██████╗ \x1b[38;5;190m██╗ ██╗\x1b[38;5;154m██╗\x1b[38;5;118m███╗ ██╗\x1b[0m');
75
- console.log(' \x1b[38;5;208m██╔══██╗\x1b[38;5;214m██║ ██║\x1b[38;5;220m████╗ ████║\x1b[38;5;226m██╔══██╗\x1b[38;5;190m██║ ██╔╝\x1b[38;5;154m██║\x1b[38;5;118m████╗ ██║\x1b[0m');
76
- console.log(' \x1b[38;5;208m██████╔╝\x1b[38;5;214m██║ ██║\x1b[38;5;220m██╔████╔██║\x1b[38;5;226m██████╔╝\x1b[38;5;190m█████╔╝ \x1b[38;5;154m██║\x1b[38;5;118m██╔██╗ ██║\x1b[0m');
77
- console.log(' \x1b[38;5;208m██╔═══╝ \x1b[38;5;214m██║ ██║\x1b[38;5;220m██║╚██╔╝██║\x1b[38;5;226m██╔═══╝ \x1b[38;5;190m██╔═██╗ \x1b[38;5;154m██║\x1b[38;5;118m██║╚██╗██║\x1b[0m');
78
- console.log(' \x1b[38;5;208m██║ \x1b[38;5;214m╚██████╔╝\x1b[38;5;220m██║ ╚═╝ ██║\x1b[38;5;226m██║ \x1b[38;5;190m██║ ██╗\x1b[38;5;154m██║\x1b[38;5;118m██║ ╚████║\x1b[0m');
79
- console.log(' \x1b[38;5;208m╚═╝ \x1b[38;5;214m ╚═════╝ \x1b[38;5;220m╚═╝ ╚═╝\x1b[38;5;226m╚═╝ \x1b[38;5;190m╚═╝ ╚═╝\x1b[38;5;154m╚═╝\x1b[38;5;118m╚═╝ ╚═══╝\x1b[0m');
80
- log('\n PumpkinAI 一键配置工具', 'magenta');
81
- log(' ' + '='.repeat(54), 'cyan');
82
- }
83
-
84
- // 渲染通用菜单
85
- function renderGenericMenu(title, options) {
86
- console.clear();
87
- log('\n', 'reset');
88
- showLogo();
89
- log('', 'reset');
90
-
91
- log(` ${title}\n`, 'cyan');
92
-
93
- options.forEach((option, index) => {
94
- const isSelected = index === selectedIndex;
95
- const prefix = isSelected ? ' ▶ ' : ' ';
96
- const nameColor = isSelected ? '\x1b[1m\x1b[33m' : '\x1b[0m';
97
- const descColor = isSelected ? '\x1b[36m' : '\x1b[2m';
98
- const numLabel = `${index + 1}. `;
99
-
100
- console.log(`${prefix}${nameColor}${numLabel}${option.name}\x1b[0m`);
101
- if (option.desc) {
102
- console.log(` ${descColor}${option.desc}\x1b[0m`);
103
- }
104
- console.log('');
105
- });
106
-
107
- log(' ' + '='.repeat(54), 'cyan');
108
- }
109
-
110
- // 渲染当前菜单
111
- function renderMenu() {
112
- switch (currentMenu) {
113
- case 'main':
114
- renderGenericMenu('请选择要配置的工具 (↑↓选择, Enter确认):', mainMenuOptions);
115
- break;
116
- case 'claude_sub':
117
- renderGenericMenu('Claude Code - 请选择购买的套餐 (↑↓选择, Enter确认, ESC返回):', claudeSubMenuOptions);
118
- break;
119
- case 'codex_sub':
120
- renderGenericMenu('Codex - 请选择购买的套餐 (↑↓选择, Enter确认, ESC返回):', codexSubMenuOptions);
121
- break;
122
- case 'fix_sub':
123
- renderGenericMenu('Claude 报错修复 - 请选择操作 (↑↓选择, Enter确认, ESC返回):', fixSubMenuOptions);
124
- break;
125
- case 'codex_fix_sub':
126
- renderGenericMenu('Codex 报错修复 - 请选择操作 (↑↓选择, Enter确认, ESC返回):', codexFixSubMenuOptions);
127
- break;
128
- }
129
- }
130
-
131
- // 获取当前菜单选项
132
- function getCurrentOptions() {
133
- switch (currentMenu) {
134
- case 'main': return mainMenuOptions;
135
- case 'claude_sub': return claudeSubMenuOptions;
136
- case 'codex_sub': return codexSubMenuOptions;
137
- case 'fix_sub': return fixSubMenuOptions;
138
- case 'codex_fix_sub': return codexFixSubMenuOptions;
139
- default: return mainMenuOptions;
140
- }
141
- }
142
-
143
-
144
- // 处理主菜单选择
145
- function handleMainMenuSelection() {
146
- const selected = mainMenuOptions[selectedIndex];
147
-
148
- if (selected.name === '退出') {
149
- console.clear();
150
- process.exit(0);
151
- }
152
-
153
- if (selected.name === 'Claude Code') {
154
- currentMenu = 'claude_sub';
155
- } else {
156
- currentMenu = 'codex_sub';
157
- }
158
- selectedIndex = 0;
159
- renderMenu();
160
- }
161
-
162
- // 处理 Claude Code 子菜单选择
163
- async function handleClaudeSubMenuSelection() {
164
- const selected = claudeSubMenuOptions[selectedIndex];
165
-
166
- if (selected.name === '报错修复') {
167
- currentMenu = 'fix_sub';
168
- selectedIndex = 0;
169
- renderMenu();
170
- return false;
171
- }
172
-
173
- // 执行对应脚本
174
- const scriptPath = scriptMap['Claude Code'][selected.name];
175
- console.clear();
176
- log(`\n[启动] 正在运行 Claude Code (${selected.name}) 配置...\n`, 'green');
177
-
178
- try {
179
- const script = require(scriptPath);
180
- await script.main();
181
- return true;
182
- } catch (error) {
183
- log(`\n[错误] ${error.message}`, 'red');
184
- process.exit(1);
185
- }
186
- }
187
-
188
- // 处理 Codex 子菜单选择
189
- async function handleCodexSubMenuSelection() {
190
- const selected = codexSubMenuOptions[selectedIndex];
191
-
192
- if (selected.name === '报错修复') {
193
- currentMenu = 'codex_fix_sub';
194
- selectedIndex = 0;
195
- renderMenu();
196
- return false;
197
- }
198
-
199
- // 执行对应脚本
200
- const scriptPath = scriptMap['Codex'][selected.name];
201
- console.clear();
202
- log(`\n[启动] 正在运行 Codex (${selected.name}) 配置...\n`, 'green');
203
-
204
- try {
205
- const script = require(scriptPath);
206
- await script.main();
207
- return true;
208
- } catch (error) {
209
- log(`\n[错误] ${error.message}`, 'red');
210
- process.exit(1);
211
- }
212
- }
213
-
214
- // 处理 Claude 报错修复子菜单选择
215
- async function handleFixSubMenuSelection() {
216
- const selected = fixSubMenuOptions[selectedIndex];
217
-
218
- if (selected.name === '彻底重新安装') {
219
- // 调用 claude-fix.js 中的修复功能
220
- const claudeFix = require('./claude-fix.js');
221
- await claudeFix.main();
222
- currentMenu = 'claude_sub';
223
- selectedIndex = 0;
224
- return false;
225
- }
226
-
227
- if (selected.name === '网络修复') {
228
- // 调用 claude-network.js 中的网络修复功能
229
- const claudeNetwork = require('./claude-network.js');
230
- await claudeNetwork.main();
231
- currentMenu = 'fix_sub';
232
- selectedIndex = 0;
233
- return false;
234
- }
235
-
236
- return false;
237
- }
238
-
239
- // 处理 Codex 报错修复子菜单选择
240
- async function handleCodexFixSubMenuSelection() {
241
- const selected = codexFixSubMenuOptions[selectedIndex];
242
-
243
- if (selected.name === '网络修复') {
244
- // 调用 codex-network.js 中的网络修复功能
245
- const codexNetwork = require('./codex-network.js');
246
- await codexNetwork.main();
247
- currentMenu = 'codex_fix_sub';
248
- selectedIndex = 0;
249
- return false;
250
- }
251
-
252
- return false;
253
- }
254
-
255
- // 处理子菜单选择
256
- async function handleSubMenuSelection() {
257
- switch (currentMenu) {
258
- case 'claude_sub':
259
- return await handleClaudeSubMenuSelection();
260
- case 'codex_sub':
261
- return await handleCodexSubMenuSelection();
262
- case 'fix_sub':
263
- return await handleFixSubMenuSelection();
264
- case 'codex_fix_sub':
265
- return await handleCodexFixSubMenuSelection();
266
- default:
267
- return false;
268
- }
269
- }
270
-
271
- // 主函数
272
- async function main() {
273
- // 启用原始模式以捕获按键
274
- if (process.stdin.isTTY) {
275
- process.stdin.setRawMode(true);
276
- }
277
- process.stdin.resume();
278
- process.stdin.setEncoding('utf8');
279
-
280
- renderMenu();
281
-
282
- return new Promise((resolve) => {
283
- const handleKeyPress = async (key) => {
284
- const options = getCurrentOptions();
285
-
286
- // Ctrl+C 退出
287
- if (key === '\u0003') {
288
- console.clear();
289
- process.exit(0);
290
- }
291
-
292
- // ESC 返回上级菜单
293
- if (key === '\u001b') {
294
- if (currentMenu === 'fix_sub') {
295
- currentMenu = 'claude_sub';
296
- selectedIndex = 0;
297
- renderMenu();
298
- return;
299
- } else if (currentMenu === 'codex_fix_sub') {
300
- currentMenu = 'codex_sub';
301
- selectedIndex = 0;
302
- renderMenu();
303
- return;
304
- } else if (currentMenu === 'claude_sub' || currentMenu === 'codex_sub') {
305
- currentMenu = 'main';
306
- selectedIndex = 0;
307
- renderMenu();
308
- return;
309
- }
310
- }
311
-
312
- // 上箭头
313
- if (key === '\u001b[A' || key === 'k') {
314
- selectedIndex = selectedIndex > 0 ? selectedIndex - 1 : options.length - 1;
315
- renderMenu();
316
- }
317
-
318
- // 下箭头
319
- if (key === '\u001b[B' || key === 'j') {
320
- selectedIndex = selectedIndex < options.length - 1 ? selectedIndex + 1 : 0;
321
- renderMenu();
322
- }
323
-
324
- // Enter 确认
325
- if (key === '\r' || key === '\n') {
326
- if (currentMenu === 'main') {
327
- handleMainMenuSelection();
328
- } else {
329
- if (process.stdin.isTTY) {
330
- process.stdin.setRawMode(false);
331
- }
332
- process.stdin.removeAllListeners('data');
333
- const done = await handleSubMenuSelection();
334
- if (done) {
335
- resolve();
336
- } else {
337
- // 重新启用监听
338
- if (process.stdin.isTTY) {
339
- process.stdin.setRawMode(true);
340
- }
341
- process.stdin.on('data', handleKeyPress);
342
- renderMenu();
343
- }
344
- }
345
- }
346
-
347
- // 数字键快捷选择
348
- const num = parseInt(key);
349
- if (num >= 1 && num <= options.length - 1) {
350
- selectedIndex = num - 1;
351
- renderMenu();
352
- }
353
- if (key === '0') {
354
- selectedIndex = options.length - 1;
355
- renderMenu();
356
- }
357
- };
358
-
359
- process.stdin.on('data', handleKeyPress);
360
- });
361
- }
362
-
363
- // 如果直接运行此脚本
364
- if (require.main === module) {
365
- main().catch(error => {
366
- log(`\n[错误] ${error.message}`, 'red');
367
- process.exit(1);
368
- });
369
- }
370
-
371
- module.exports = { main };