@pikecode/api-key-manager 2.0.6 → 2.0.7

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pikecode/api-key-manager",
3
- "version": "2.0.6",
3
+ "version": "2.0.7",
4
4
  "description": "A CLI tool for managing and switching multiple API provider configurations",
5
5
  "main": "src/index.js",
6
6
  "bin": {
@@ -63,11 +63,18 @@ class LaunchArgsHelper {
63
63
  ? ` ${UIHelper.colors.muted(arg.description)}`
64
64
  : '';
65
65
 
66
- return {
66
+ const choice = {
67
67
  name: `${UIHelper.colors.accent(arg.label || arg.name)} ${commandText}${descriptionText}`,
68
68
  value: arg.name,
69
69
  checked: Boolean(arg.checked)
70
70
  };
71
+
72
+ // 添加禁用状态支持
73
+ if (arg.disabled) {
74
+ choice.disabled = arg.disabled;
75
+ }
76
+
77
+ return choice;
71
78
  });
72
79
  }
73
80
 
@@ -90,7 +90,15 @@ class EnvSwitcher extends BaseCommand {
90
90
  this.clearScreen();
91
91
  const provider = await this.validateProvider(providerName);
92
92
  const isCodex = provider.ideName === 'codex';
93
- const availableArgs = LaunchArgsHelper.getAvailableLaunchArgs(isCodex);
93
+
94
+ // 根据 IDE 类型检查会话历史并获取过滤后的参数
95
+ let availableArgs;
96
+ const { getCodexLaunchArgsWithHistory, getClaudeLaunchArgsWithHistory } = require('../utils/launch-args');
97
+ if (isCodex) {
98
+ availableArgs = await getCodexLaunchArgsWithHistory(true);
99
+ } else {
100
+ availableArgs = await getClaudeLaunchArgsWithHistory(true);
101
+ }
94
102
 
95
103
  const defaultLaunchArgs = Array.isArray(provider.lastUsedArgs) && provider.lastUsedArgs.length > 0
96
104
  ? provider.lastUsedArgs
@@ -3,6 +3,10 @@
3
3
  * 统一管理 Claude Code 和 Codex CLI 的启动参数
4
4
  */
5
5
 
6
+ const fs = require('fs-extra');
7
+ const path = require('path');
8
+ const os = require('os');
9
+
6
10
  const claudeLaunchArgs = [
7
11
  {
8
12
  name: '--continue',
@@ -144,12 +148,119 @@ function checkExclusiveArgs(selectedArgs, availableArgs) {
144
148
  return null;
145
149
  }
146
150
 
151
+ /**
152
+ * 检查 Codex 是否有会话历史
153
+ * @returns {Promise<boolean>} 如果存在会话历史返回 true
154
+ */
155
+ async function hasCodexSessionHistory() {
156
+ try {
157
+ const codexHome = process.env.CODEX_HOME || path.join(os.homedir(), '.codex');
158
+
159
+ // 检查会话目录中是否有实际的会话数据
160
+ const sessionsDir = path.join(codexHome, 'sessions');
161
+ if (await fs.pathExists(sessionsDir)) {
162
+ const entries = await fs.readdir(sessionsDir);
163
+ if (entries.length > 0) {
164
+ return true;
165
+ }
166
+ }
167
+
168
+ // 检查会话历史数据库是否存在且非空
169
+ const threadHistoryDb = path.join(codexHome, 'thread_history_1.sqlite');
170
+ if (await fs.pathExists(threadHistoryDb)) {
171
+ const stat = await fs.stat(threadHistoryDb);
172
+ if (stat.size > 0) {
173
+ return true;
174
+ }
175
+ }
176
+
177
+ return false;
178
+ } catch {
179
+ return false;
180
+ }
181
+ }
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
+ /**
206
+ * 获取 Codex 启动参数,根据会话历史动态禁用/隐藏 resume 选项
207
+ * @param {boolean} filterByHistory - 是否根据会话历史过滤参数(默认 true)
208
+ * @returns {Promise<Array>} 可用的启动参数数组
209
+ */
210
+ async function getCodexLaunchArgsWithHistory(filterByHistory = true) {
211
+ const args = codexLaunchArgs.map(arg => ({ ...arg }));
212
+
213
+ if (!filterByHistory) {
214
+ return args;
215
+ }
216
+
217
+ const hasHistory = await hasCodexSessionHistory();
218
+ if (!hasHistory) {
219
+ // 如果没有会话历史,标记 resume 选项为禁用
220
+ const resumeArg = args.find(arg => arg.name === 'resume');
221
+ if (resumeArg) {
222
+ resumeArg.disabled = true;
223
+ resumeArg.description = '没有可用的会话历史';
224
+ }
225
+ }
226
+
227
+ return args;
228
+ }
229
+
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
+
147
255
  module.exports = {
148
256
  getClaudeLaunchArgs,
149
257
  getCodexLaunchArgs,
258
+ getClaudeLaunchArgsWithHistory,
259
+ getCodexLaunchArgsWithHistory,
150
260
  getLaunchArgs,
151
261
  checkExclusiveArgs,
152
262
  validateLaunchArgs,
153
263
  assertSupportedLaunchArgs,
154
- assertSafeImportLaunchArgs
264
+ assertSafeImportLaunchArgs,
265
+ hasCodexSessionHistory
155
266
  };