@pikecode/api-key-manager 2.0.6 → 2.0.8

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.8",
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
+ // 只对 Codex 检查会话历史,Claude Code 让用户自由选择
95
+ let availableArgs;
96
+ if (isCodex) {
97
+ const { getCodexLaunchArgsWithHistory } = require('../utils/launch-args');
98
+ availableArgs = await getCodexLaunchArgsWithHistory(true);
99
+ } else {
100
+ availableArgs = LaunchArgsHelper.getAvailableLaunchArgs(isCodex);
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,71 @@ 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
+ * 获取 Codex 启动参数,根据会话历史动态禁用/隐藏 resume 选项
185
+ * @param {boolean} _filterByHistory - 是否根据会话历史过滤参数(默认 true)
186
+ * @returns {Promise<Array>} 可用的启动参数数组
187
+ */
188
+ async function getCodexLaunchArgsWithHistory(_filterByHistory = true) {
189
+ const args = codexLaunchArgs.map(arg => ({ ...arg }));
190
+
191
+ if (!_filterByHistory) {
192
+ return args;
193
+ }
194
+
195
+ const hasHistory = await hasCodexSessionHistory();
196
+ if (!hasHistory) {
197
+ // 如果没有会话历史,标记 resume 选项为禁用
198
+ const resumeArg = args.find(arg => arg.name === 'resume');
199
+ if (resumeArg) {
200
+ resumeArg.disabled = true;
201
+ resumeArg.description = '没有可用的会话历史';
202
+ }
203
+ }
204
+
205
+ return args;
206
+ }
207
+
147
208
  module.exports = {
148
209
  getClaudeLaunchArgs,
149
210
  getCodexLaunchArgs,
211
+ getCodexLaunchArgsWithHistory,
150
212
  getLaunchArgs,
151
213
  checkExclusiveArgs,
152
214
  validateLaunchArgs,
153
215
  assertSupportedLaunchArgs,
154
- assertSafeImportLaunchArgs
216
+ assertSafeImportLaunchArgs,
217
+ hasCodexSessionHistory
155
218
  };