@pikecode/api-key-manager 2.0.7 → 2.0.9
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/package.json +1 -1
- package/src/commands/switch.js +3 -3
- package/src/utils/env-launcher.js +17 -2
- package/src/utils/launch-args.js +3 -51
package/package.json
CHANGED
package/src/commands/switch.js
CHANGED
|
@@ -91,13 +91,13 @@ class EnvSwitcher extends BaseCommand {
|
|
|
91
91
|
const provider = await this.validateProvider(providerName);
|
|
92
92
|
const isCodex = provider.ideName === 'codex';
|
|
93
93
|
|
|
94
|
-
//
|
|
94
|
+
// 只对 Codex 检查会话历史,Claude Code 让用户自由选择
|
|
95
95
|
let availableArgs;
|
|
96
|
-
const { getCodexLaunchArgsWithHistory, getClaudeLaunchArgsWithHistory } = require('../utils/launch-args');
|
|
97
96
|
if (isCodex) {
|
|
97
|
+
const { getCodexLaunchArgsWithHistory } = require('../utils/launch-args');
|
|
98
98
|
availableArgs = await getCodexLaunchArgsWithHistory(true);
|
|
99
99
|
} else {
|
|
100
|
-
availableArgs =
|
|
100
|
+
availableArgs = LaunchArgsHelper.getAvailableLaunchArgs(isCodex);
|
|
101
101
|
}
|
|
102
102
|
|
|
103
103
|
const defaultLaunchArgs = Array.isArray(provider.lastUsedArgs) && provider.lastUsedArgs.length > 0
|
|
@@ -59,16 +59,31 @@ async function executeWithEnv(config, launchArgs = []) {
|
|
|
59
59
|
|
|
60
60
|
return new Promise((resolve, reject) => {
|
|
61
61
|
const child = spawn('claude', args, {
|
|
62
|
-
stdio: 'inherit',
|
|
62
|
+
stdio: ['inherit', 'inherit', 'pipe'],
|
|
63
63
|
env,
|
|
64
64
|
shell: false
|
|
65
65
|
});
|
|
66
66
|
|
|
67
|
+
let stderrOutput = '';
|
|
68
|
+
|
|
69
|
+
// 捕获 stderr 用于检查错误信息
|
|
70
|
+
child.stderr.on('data', (data) => {
|
|
71
|
+
const output = data.toString();
|
|
72
|
+
stderrOutput += output;
|
|
73
|
+
// 同时输出 stderr 给用户
|
|
74
|
+
process.stderr.write(data);
|
|
75
|
+
});
|
|
76
|
+
|
|
67
77
|
child.on('close', (code, signal) => {
|
|
68
78
|
if (code === 0 || code === 130 || signal === 'SIGINT') {
|
|
69
79
|
resolve();
|
|
70
80
|
} else {
|
|
71
|
-
|
|
81
|
+
// 检查是否是"没有可恢复会话"的错误
|
|
82
|
+
if (stderrOutput.includes('No conversation found to continue')) {
|
|
83
|
+
reject(new Error('没有可恢复的会话\n提示: 请选择不带 --continue 参数重新开始'));
|
|
84
|
+
} else {
|
|
85
|
+
reject(new Error(`Claude Code 异常退出,退出代码: ${code}\n提示: 请检查 API 配置是否正确`));
|
|
86
|
+
}
|
|
72
87
|
}
|
|
73
88
|
});
|
|
74
89
|
|
package/src/utils/launch-args.js
CHANGED
|
@@ -180,37 +180,15 @@ async function hasCodexSessionHistory() {
|
|
|
180
180
|
}
|
|
181
181
|
}
|
|
182
182
|
|
|
183
|
-
/**
|
|
184
|
-
* 检查 Claude Code 是否有会话历史
|
|
185
|
-
* @returns {Promise<boolean>} 如果存在会话历史返回 true
|
|
186
|
-
*/
|
|
187
|
-
async function hasClaudeSessionHistory() {
|
|
188
|
-
try {
|
|
189
|
-
const claudeHome = path.join(os.homedir(), '.claude');
|
|
190
|
-
const historyFile = path.join(claudeHome, 'history.jsonl');
|
|
191
|
-
|
|
192
|
-
if (await fs.pathExists(historyFile)) {
|
|
193
|
-
const stat = await fs.stat(historyFile);
|
|
194
|
-
if (stat.size > 0) {
|
|
195
|
-
return true;
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
return false;
|
|
200
|
-
} catch {
|
|
201
|
-
return false;
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
|
|
205
183
|
/**
|
|
206
184
|
* 获取 Codex 启动参数,根据会话历史动态禁用/隐藏 resume 选项
|
|
207
|
-
* @param {boolean}
|
|
185
|
+
* @param {boolean} _filterByHistory - 是否根据会话历史过滤参数(默认 true)
|
|
208
186
|
* @returns {Promise<Array>} 可用的启动参数数组
|
|
209
187
|
*/
|
|
210
|
-
async function getCodexLaunchArgsWithHistory(
|
|
188
|
+
async function getCodexLaunchArgsWithHistory(_filterByHistory = true) {
|
|
211
189
|
const args = codexLaunchArgs.map(arg => ({ ...arg }));
|
|
212
190
|
|
|
213
|
-
if (!
|
|
191
|
+
if (!_filterByHistory) {
|
|
214
192
|
return args;
|
|
215
193
|
}
|
|
216
194
|
|
|
@@ -227,35 +205,9 @@ async function getCodexLaunchArgsWithHistory(filterByHistory = true) {
|
|
|
227
205
|
return args;
|
|
228
206
|
}
|
|
229
207
|
|
|
230
|
-
/**
|
|
231
|
-
* 获取 Claude Code 启动参数,根据会话历史动态禁用/隐藏 --continue 选项
|
|
232
|
-
* @param {boolean} filterByHistory - 是否根据会话历史过滤参数(默认 true)
|
|
233
|
-
* @returns {Promise<Array>} 可用的启动参数数组
|
|
234
|
-
*/
|
|
235
|
-
async function getClaudeLaunchArgsWithHistory(filterByHistory = true) {
|
|
236
|
-
const args = claudeLaunchArgs.map(arg => ({ ...arg }));
|
|
237
|
-
|
|
238
|
-
if (!filterByHistory) {
|
|
239
|
-
return args;
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
const hasHistory = await hasClaudeSessionHistory();
|
|
243
|
-
if (!hasHistory) {
|
|
244
|
-
// 如果没有会话历史,标记 --continue 选项为禁用
|
|
245
|
-
const continueArg = args.find(arg => arg.name === '--continue');
|
|
246
|
-
if (continueArg) {
|
|
247
|
-
continueArg.disabled = true;
|
|
248
|
-
continueArg.description = '没有可用的会话历史';
|
|
249
|
-
}
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
return args;
|
|
253
|
-
}
|
|
254
|
-
|
|
255
208
|
module.exports = {
|
|
256
209
|
getClaudeLaunchArgs,
|
|
257
210
|
getCodexLaunchArgs,
|
|
258
|
-
getClaudeLaunchArgsWithHistory,
|
|
259
211
|
getCodexLaunchArgsWithHistory,
|
|
260
212
|
getLaunchArgs,
|
|
261
213
|
checkExclusiveArgs,
|