@pikecode/api-key-manager 1.3.91 → 2.0.1
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/README.md +79 -52
- package/bin/akm.js +47 -30
- package/package.json +13 -8
- package/src/CommandRegistry.js +2 -2
- package/src/commands/add/prompts.js +200 -171
- package/src/commands/add/providerSaver.js +6 -7
- package/src/commands/add.js +6 -2
- package/src/commands/backup.js +99 -45
- package/src/commands/current.js +41 -20
- package/src/commands/edit.js +3 -289
- package/src/commands/health.js +75 -31
- package/src/commands/list.js +39 -19
- package/src/commands/remove.js +2 -2
- package/src/commands/switch/provider-edit-questions-helper.js +29 -7
- package/src/commands/switch/provider-manager.js +39 -40
- package/src/commands/switch.js +9 -8
- package/src/config.js +68 -45
- package/src/index.js +1 -1
- package/src/utils/atomic-file.js +47 -0
- package/src/utils/claude-settings.js +4 -3
- package/src/utils/codex-files.js +227 -38
- package/src/utils/codex-launcher.js +16 -8
- package/src/utils/concurrency.js +30 -0
- package/src/utils/env-launcher.js +17 -1
- package/src/utils/import-validator.js +210 -0
- package/src/utils/launch-args.js +60 -1
- package/src/utils/provider-status-checker.js +49 -24
- package/src/utils/shell-snippets.js +32 -0
- package/src/utils/terminal-format.js +22 -4
- package/src/utils/ui-helper.js +0 -1
- package/src/utils/update-checker.js +3 -3
- package/src/utils/validator.js +81 -10
package/README.md
CHANGED
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
- 🧹 **配置清理** — 清理 Claude Code 配置文件中的冗余数据
|
|
17
17
|
- 📋 **克隆配置** — 快速克隆现有供应商配置
|
|
18
18
|
- ✅ **配置验证** — 验证 Token 有效性和 API 可用性
|
|
19
|
-
- 🔐
|
|
19
|
+
- 🔐 **权限保护** — 本地文件存储,Unix 自动设置 0600 权限
|
|
20
20
|
- 💾 **备份恢复** — 配置导出、导入、备份功能
|
|
21
21
|
- 🌍 **跨平台** — macOS / Linux / Windows
|
|
22
22
|
|
|
@@ -49,35 +49,35 @@ akm current
|
|
|
49
49
|
|
|
50
50
|
### 核心命令
|
|
51
51
|
|
|
52
|
-
| 命令
|
|
53
|
-
|
|
54
|
-
| `akm` / `akm switch`
|
|
55
|
-
| `akm add`
|
|
52
|
+
| 命令 | 说明 |
|
|
53
|
+
| ----------------------- | ------------------------------ |
|
|
54
|
+
| `akm` / `akm switch` | 交互式选择和切换供应商 |
|
|
55
|
+
| `akm add` | 添加新的供应商配置 |
|
|
56
56
|
| `akm remove [provider]` | 删除供应商配置(支持批量删除) |
|
|
57
|
-
| `akm list`
|
|
58
|
-
| `akm current`
|
|
59
|
-
| `akm edit [provider]`
|
|
57
|
+
| `akm list` | 列出所有供应商 |
|
|
58
|
+
| `akm current` | 显示当前激活的配置 |
|
|
59
|
+
| `akm edit [provider]` | 编辑供应商配置 |
|
|
60
60
|
|
|
61
61
|
### 运维命令
|
|
62
62
|
|
|
63
|
-
| 命令
|
|
64
|
-
|
|
65
|
-
| `akm export [file]`
|
|
66
|
-
| `akm import <file>`
|
|
67
|
-
| `akm backup`
|
|
63
|
+
| 命令 | 说明 |
|
|
64
|
+
| ------------------------- | -------------------- |
|
|
65
|
+
| `akm export [file]` | 导出配置到文件 |
|
|
66
|
+
| `akm import <file>` | 从文件导入配置 |
|
|
67
|
+
| `akm backup` | 备份和恢复配置 |
|
|
68
68
|
| `akm validate [provider]` | 验证供应商配置有效性 |
|
|
69
|
-
| `akm clone [source]`
|
|
69
|
+
| `akm clone [source]` | 克隆现有供应商配置 |
|
|
70
70
|
|
|
71
71
|
### 工具命令
|
|
72
72
|
|
|
73
|
-
| 命令
|
|
74
|
-
|
|
75
|
-
| `akm stats [provider]`
|
|
76
|
-
| `akm health [provider]`
|
|
77
|
-
| `akm batch <operation>`
|
|
78
|
-
| `akm benchmark`
|
|
79
|
-
| `akm claude <subcommand>` | Claude Code 配置管理 (clean/analyze)
|
|
80
|
-
| `akm mcp <subcommand>`
|
|
73
|
+
| 命令 | 说明 |
|
|
74
|
+
| ------------------------- | ------------------------------------- |
|
|
75
|
+
| `akm stats [provider]` | 显示供应商使用统计 |
|
|
76
|
+
| `akm health [provider]` | 检查配置健康状态 |
|
|
77
|
+
| `akm batch <operation>` | 批量操作供应商 |
|
|
78
|
+
| `akm benchmark` | 供应商性能测试和对比 |
|
|
79
|
+
| `akm claude <subcommand>` | Claude Code 配置管理 (clean/analyze) |
|
|
80
|
+
| `akm mcp <subcommand>` | MCP 服务器管理 (list/add/edit/remove) |
|
|
81
81
|
|
|
82
82
|
---
|
|
83
83
|
|
|
@@ -99,12 +99,14 @@ akm add --codex
|
|
|
99
99
|
添加流程分两步:
|
|
100
100
|
|
|
101
101
|
**步骤 1 — 填写供应商信息:**
|
|
102
|
+
|
|
102
103
|
- 选择 IDE 类型(Claude Code / Codex CLI)
|
|
103
104
|
- 输入供应商名称
|
|
104
105
|
- 选择认证模式(Claude Code 有两种)
|
|
105
106
|
- 输入 API 基础 URL 和 Token
|
|
106
107
|
|
|
107
108
|
**步骤 2 — 可选配置:**
|
|
109
|
+
|
|
108
110
|
- 启动参数
|
|
109
111
|
- 模型配置
|
|
110
112
|
|
|
@@ -112,10 +114,10 @@ akm add --codex
|
|
|
112
114
|
|
|
113
115
|
Claude Code 支持两种认证模式:
|
|
114
116
|
|
|
115
|
-
| 模式
|
|
116
|
-
|
|
117
|
-
| API Key
|
|
118
|
-
| Auth Token | `ANTHROPIC_AUTH_TOKEN` + `ANTHROPIC_BASE_URL` | 部分服务商
|
|
117
|
+
| 模式 | 环境变量 | 适用场景 |
|
|
118
|
+
| ---------- | --------------------------------------------- | ---------------- |
|
|
119
|
+
| API Key | `ANTHROPIC_API_KEY` + `ANTHROPIC_BASE_URL` | 大多数第三方代理 |
|
|
120
|
+
| Auth Token | `ANTHROPIC_AUTH_TOKEN` + `ANTHROPIC_BASE_URL` | 部分服务商 |
|
|
119
121
|
|
|
120
122
|
Codex CLI 使用 `OPENAI_API_KEY` + `OPENAI_BASE_URL`。
|
|
121
123
|
|
|
@@ -159,15 +161,17 @@ akm list --status
|
|
|
159
161
|
# 按 IDE 类型过滤
|
|
160
162
|
akm list --claude
|
|
161
163
|
akm list --codex
|
|
164
|
+
akm list --json
|
|
162
165
|
|
|
163
|
-
#
|
|
164
|
-
akm list --show-token
|
|
165
|
-
|
|
166
|
-
# 查看当前激活的配置
|
|
166
|
+
# 查看当前激活的配置(list/current 默认完整显示 Token)
|
|
167
167
|
akm current
|
|
168
|
-
akm current --
|
|
168
|
+
akm current --shell zsh
|
|
169
|
+
akm current --json
|
|
169
170
|
```
|
|
170
171
|
|
|
172
|
+
`--show-token` 作为兼容参数继续接受;本地 `list`、`current`、创建摘要和供应商详情均直接显示完整 Token。
|
|
173
|
+
分享配置时仍建议使用默认的无密钥导出。
|
|
174
|
+
|
|
171
175
|
### 克隆供应商
|
|
172
176
|
|
|
173
177
|
快速基于现有配置创建新供应商:
|
|
@@ -193,6 +197,7 @@ akm remove my-provider
|
|
|
193
197
|
```
|
|
194
198
|
|
|
195
199
|
**批量删除流程:**
|
|
200
|
+
|
|
196
201
|
1. 使用空格键选择多个要删除的供应商
|
|
197
202
|
2. 按 Enter 确认选择
|
|
198
203
|
3. 预览将要删除的供应商列表
|
|
@@ -209,6 +214,7 @@ akm edit my-provider
|
|
|
209
214
|
```
|
|
210
215
|
|
|
211
216
|
**可编辑内容:**
|
|
217
|
+
|
|
212
218
|
- 供应商名称
|
|
213
219
|
- 认证模式
|
|
214
220
|
- API 基础 URL
|
|
@@ -259,17 +265,29 @@ akm backup --list
|
|
|
259
265
|
# 恢复备份
|
|
260
266
|
akm backup --restore <file>
|
|
261
267
|
|
|
262
|
-
#
|
|
268
|
+
# 导出无密钥配置(默认,可作为模板分享)
|
|
263
269
|
akm export my-config.json
|
|
264
270
|
|
|
265
|
-
#
|
|
266
|
-
akm export
|
|
271
|
+
# 显式导出包含完整 Token 的配置(敏感文件)
|
|
272
|
+
akm export private-backup.json --include-secrets
|
|
273
|
+
|
|
274
|
+
# 预览导出,不写入文件
|
|
275
|
+
akm export my-config.json --dry-run
|
|
267
276
|
|
|
268
277
|
# 导入配置
|
|
269
278
|
akm import my-config.json
|
|
270
279
|
akm import my-config.json --overwrite
|
|
280
|
+
akm import my-config.json --dry-run
|
|
271
281
|
```
|
|
272
282
|
|
|
283
|
+
导出文件在 Unix 系统上会设置为 `0600`。默认导出会把 `authToken` 设为 `null`,并写入
|
|
284
|
+
`secretsIncluded: false`,导入后需要重新设置密钥;只有明确使用 `--include-secrets` 时才会
|
|
285
|
+
写出原始密钥。
|
|
286
|
+
`health` 默认只做本地配置健康检查;使用 `--connectivity` 才会真实调用 API,可能产生费用。
|
|
287
|
+
`--json` 和 `--dry-run` 适合脚本或自动化流程。
|
|
288
|
+
|
|
289
|
+
如果配置文件在当前操作期间被另一个 `akm` 进程修改,保存会停止并提示重新执行,避免覆盖较新的配置。
|
|
290
|
+
|
|
273
291
|
### 配置验证
|
|
274
292
|
|
|
275
293
|
```bash
|
|
@@ -350,25 +368,25 @@ akm personal -q
|
|
|
350
368
|
|
|
351
369
|
### 状态图标
|
|
352
370
|
|
|
353
|
-
| 图标 | 含义
|
|
354
|
-
|
|
355
|
-
| 🟢
|
|
356
|
-
| 🟡
|
|
357
|
-
| 🔴
|
|
358
|
-
| ⏳
|
|
359
|
-
| ⚪
|
|
371
|
+
| 图标 | 含义 |
|
|
372
|
+
| ---- | --------------- |
|
|
373
|
+
| 🟢 | API 可用 |
|
|
374
|
+
| 🟡 | 有限可用/响应慢 |
|
|
375
|
+
| 🔴 | API 不可用 |
|
|
376
|
+
| ⏳ | 正在检测 |
|
|
377
|
+
| ⚪ | 未知状态 |
|
|
360
378
|
|
|
361
379
|
### 快捷键
|
|
362
380
|
|
|
363
|
-
| 按键
|
|
364
|
-
|
|
365
|
-
| ↑/↓
|
|
366
|
-
| Space
|
|
367
|
-
| A
|
|
368
|
-
| I
|
|
369
|
-
| Enter
|
|
370
|
-
| ESC
|
|
371
|
-
| Ctrl+C | 退出程序
|
|
381
|
+
| 按键 | 功能 |
|
|
382
|
+
| ------ | ---------------- |
|
|
383
|
+
| ↑/↓ | 上下导航 |
|
|
384
|
+
| Space | 切换选中(多选) |
|
|
385
|
+
| A | 全选 |
|
|
386
|
+
| I | 反选 |
|
|
387
|
+
| Enter | 确认 |
|
|
388
|
+
| ESC | 返回上级 / 取消 |
|
|
389
|
+
| Ctrl+C | 退出程序 |
|
|
372
390
|
|
|
373
391
|
---
|
|
374
392
|
|
|
@@ -454,7 +472,9 @@ Codex CLI:
|
|
|
454
472
|
akm my-codex
|
|
455
473
|
```
|
|
456
474
|
|
|
457
|
-
akm
|
|
475
|
+
akm 会把活跃认证切换为 `auth_mode = "apikey"`,并写入新的 `OPENAI_API_KEY`。
|
|
476
|
+
原 ChatGPT 登录态不会混入活跃认证文件,修改前内容会保存在 `~/.codex/akm-backups/`。
|
|
477
|
+
`auth.json` 与 `config.toml` 作为一组更新;任一文件写入失败时会自动恢复两者的原始内容。
|
|
458
478
|
|
|
459
479
|
### Claude Code 切换后环境变量不生效
|
|
460
480
|
|
|
@@ -484,9 +504,16 @@ chmod 600 ~/.akm-config.json
|
|
|
484
504
|
|
|
485
505
|
## 系统要求
|
|
486
506
|
|
|
487
|
-
- Node.js >=
|
|
507
|
+
- Node.js >= 20.0.0
|
|
488
508
|
- macOS / Linux / Windows
|
|
489
509
|
|
|
510
|
+
### 2.0 升级提示
|
|
511
|
+
|
|
512
|
+
- Node.js 最低版本由 14 提升到 20。
|
|
513
|
+
- 默认导出改为无密钥模板;完整备份必须显式使用 `--include-secrets`。
|
|
514
|
+
- 远程 API 地址必须使用 HTTPS,HTTP 仅允许 localhost 和回环地址。
|
|
515
|
+
- 导入配置不能携带跳过审批或沙盒的最高权限启动参数。
|
|
516
|
+
|
|
490
517
|
## 许可证
|
|
491
518
|
|
|
492
519
|
MIT License
|
package/bin/akm.js
CHANGED
|
@@ -9,9 +9,9 @@ const { checkForUpdates } = require('../src/utils/update-checker');
|
|
|
9
9
|
|
|
10
10
|
// 命令分组定义
|
|
11
11
|
const COMMAND_GROUPS = {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
核心命令: ['add', 'switch', 'remove', 'list', 'current', 'edit'],
|
|
13
|
+
运维命令: ['export', 'import', 'backup', 'validate', 'clone'],
|
|
14
|
+
工具命令: ['stats', 'health', 'batch', 'benchmark', 'claude', 'mcp']
|
|
15
15
|
};
|
|
16
16
|
|
|
17
17
|
// Set up CLI
|
|
@@ -39,7 +39,9 @@ program.configureHelp({
|
|
|
39
39
|
|
|
40
40
|
// 参数
|
|
41
41
|
const argList = helper.visibleArguments(cmd).map(arg => {
|
|
42
|
-
return helper.formatHelp
|
|
42
|
+
return helper.formatHelp
|
|
43
|
+
? ` ${helper.argumentTerm(arg).padEnd(termWidth)} ${helper.argumentDescription(arg)}`
|
|
44
|
+
: '';
|
|
43
45
|
});
|
|
44
46
|
if (argList.length > 0) {
|
|
45
47
|
output += `${chalk.bold('参数:')}\n${argList.join('\n')}\n\n`;
|
|
@@ -78,7 +80,10 @@ program.configureHelp({
|
|
|
78
80
|
const groupedNames = Object.values(COMMAND_GROUPS).flat();
|
|
79
81
|
const ungrouped = commands
|
|
80
82
|
.filter(sub => !groupedNames.includes(sub.name()))
|
|
81
|
-
.map(
|
|
83
|
+
.map(
|
|
84
|
+
sub =>
|
|
85
|
+
` ${chalk.cyan(helper.subcommandTerm(sub).padEnd(termWidth))} ${helper.subcommandDescription(sub)}`
|
|
86
|
+
);
|
|
82
87
|
|
|
83
88
|
if (ungrouped.length > 0) {
|
|
84
89
|
output += `${chalk.bold.yellow('其他命令:')}\n${ungrouped.join('\n')}\n\n`;
|
|
@@ -114,9 +119,9 @@ program
|
|
|
114
119
|
.description('添加新的API密钥配置')
|
|
115
120
|
.option('--codex', '直接添加 Codex CLI 供应商')
|
|
116
121
|
.option('--claude', '直接添加 Claude Code 供应商')
|
|
117
|
-
.action(async
|
|
122
|
+
.action(async options => {
|
|
118
123
|
try {
|
|
119
|
-
const ideName = options.codex ? 'codex' :
|
|
124
|
+
const ideName = options.codex ? 'codex' : options.claude ? 'claude' : null;
|
|
120
125
|
await registry.executeCommand('add', { ideName });
|
|
121
126
|
} catch (error) {
|
|
122
127
|
console.error(chalk.red('❌ 添加失败:'), error.message);
|
|
@@ -135,7 +140,7 @@ program
|
|
|
135
140
|
.option('--no-args', '以空参数启动(不使用任何启动参数)')
|
|
136
141
|
.action(async (provider, options) => {
|
|
137
142
|
try {
|
|
138
|
-
const filter = options.codex ? 'codex' :
|
|
143
|
+
const filter = options.codex ? 'codex' : options.claude ? 'claude' : null;
|
|
139
144
|
await registry.executeCommand('switch', provider, {
|
|
140
145
|
filter,
|
|
141
146
|
quick: options.quick,
|
|
@@ -152,7 +157,7 @@ program
|
|
|
152
157
|
.command('remove')
|
|
153
158
|
.argument('[provider]', '要删除的供应商名称')
|
|
154
159
|
.description('删除API密钥配置')
|
|
155
|
-
.action(async
|
|
160
|
+
.action(async provider => {
|
|
156
161
|
try {
|
|
157
162
|
await registry.executeCommand('remove', provider);
|
|
158
163
|
} catch (error) {
|
|
@@ -168,11 +173,15 @@ program
|
|
|
168
173
|
.option('--codex', '仅显示 Codex CLI 供应商')
|
|
169
174
|
.option('--claude', '仅显示 Claude Code 供应商')
|
|
170
175
|
.option('--status', '检测供应商在线状态')
|
|
171
|
-
.option('--
|
|
172
|
-
.
|
|
176
|
+
.option('--json', '以 JSON 输出配置')
|
|
177
|
+
.option('--show-token', '兼容参数:Token 默认完整显示')
|
|
178
|
+
.action(async options => {
|
|
173
179
|
try {
|
|
174
|
-
const filter = options.codex ? 'codex' :
|
|
175
|
-
await registry.executeCommand('list', filter, {
|
|
180
|
+
const filter = options.codex ? 'codex' : options.claude ? 'claude' : null;
|
|
181
|
+
await registry.executeCommand('list', filter, {
|
|
182
|
+
checkStatus: options.status,
|
|
183
|
+
json: options.json
|
|
184
|
+
});
|
|
176
185
|
} catch (error) {
|
|
177
186
|
console.error(chalk.red('❌ 列表失败:'), error.message);
|
|
178
187
|
process.exit(1);
|
|
@@ -183,10 +192,12 @@ program
|
|
|
183
192
|
program
|
|
184
193
|
.command('current')
|
|
185
194
|
.description('显示当前活跃的配置')
|
|
186
|
-
.option('--show-token', '
|
|
187
|
-
.
|
|
195
|
+
.option('--show-token', '兼容参数:Token 默认完整显示')
|
|
196
|
+
.option('--shell <shell>', '环境变量命令格式: bash/zsh/powershell/cmd')
|
|
197
|
+
.option('--json', '以 JSON 输出当前配置')
|
|
198
|
+
.action(async options => {
|
|
188
199
|
try {
|
|
189
|
-
await registry.executeCommand('current',
|
|
200
|
+
await registry.executeCommand('current', options);
|
|
190
201
|
} catch (error) {
|
|
191
202
|
console.error(chalk.red('❌ 获取当前配置失败:'), error.message);
|
|
192
203
|
process.exit(1);
|
|
@@ -198,7 +209,7 @@ program
|
|
|
198
209
|
.command('edit')
|
|
199
210
|
.argument('[provider]', '要编辑的供应商名称')
|
|
200
211
|
.description('编辑API密钥配置')
|
|
201
|
-
.action(async
|
|
212
|
+
.action(async provider => {
|
|
202
213
|
try {
|
|
203
214
|
await registry.executeCommand('edit', provider);
|
|
204
215
|
} catch (error) {
|
|
@@ -212,7 +223,9 @@ program
|
|
|
212
223
|
.command('export')
|
|
213
224
|
.argument('[file]', '导出文件路径 (默认: akm-config-{timestamp}.json)')
|
|
214
225
|
.description('导出配置到文件')
|
|
215
|
-
.option('--
|
|
226
|
+
.option('--include-secrets', '导出完整 Token(敏感文件,请妥善保管)')
|
|
227
|
+
.option('--mask', '兼容旧版本:不导出 Token(当前已是默认行为)')
|
|
228
|
+
.option('--dry-run', '只预览导出结果,不写入文件')
|
|
216
229
|
.action(async (file, options) => {
|
|
217
230
|
try {
|
|
218
231
|
await registry.executeCommand('export', file, options);
|
|
@@ -228,6 +241,7 @@ program
|
|
|
228
241
|
.argument('<file>', '要导入的配置文件路径')
|
|
229
242
|
.description('从文件导入配置')
|
|
230
243
|
.option('--overwrite', '覆盖已存在的供应商')
|
|
244
|
+
.option('--dry-run', '只校验并预览导入结果,不修改配置')
|
|
231
245
|
.action(async (file, options) => {
|
|
232
246
|
try {
|
|
233
247
|
await registry.executeCommand('import', file, options);
|
|
@@ -244,7 +258,7 @@ program
|
|
|
244
258
|
.option('-l, --list', '列出所有备份')
|
|
245
259
|
.option('-r, --restore <file>', '从备份恢复')
|
|
246
260
|
.option('-d, --dir <path>', '指定备份目录')
|
|
247
|
-
.action(async
|
|
261
|
+
.action(async options => {
|
|
248
262
|
try {
|
|
249
263
|
await registry.executeCommand('backup', options);
|
|
250
264
|
} catch (error) {
|
|
@@ -262,7 +276,7 @@ program
|
|
|
262
276
|
.option('--claude', '仅验证 Claude Code 供应商')
|
|
263
277
|
.action(async (provider, options) => {
|
|
264
278
|
try {
|
|
265
|
-
const filter = options.codex ? 'codex' :
|
|
279
|
+
const filter = options.codex ? 'codex' : options.claude ? 'claude' : null;
|
|
266
280
|
await registry.executeCommand('validate', provider, { filter });
|
|
267
281
|
} catch (error) {
|
|
268
282
|
console.error(chalk.red('❌ 验证失败:'), error.message);
|
|
@@ -275,7 +289,7 @@ program
|
|
|
275
289
|
.command('clone')
|
|
276
290
|
.argument('[source]', '要克隆的源供应商名称')
|
|
277
291
|
.description('克隆现有供应商配置')
|
|
278
|
-
.action(async
|
|
292
|
+
.action(async source => {
|
|
279
293
|
try {
|
|
280
294
|
await registry.executeCommand('clone', source);
|
|
281
295
|
} catch (error) {
|
|
@@ -296,7 +310,7 @@ program
|
|
|
296
310
|
.option('-l, --limit <number>', '推荐列表数量限制', '5')
|
|
297
311
|
.action(async (provider, options) => {
|
|
298
312
|
try {
|
|
299
|
-
const filter = options.codex ? 'codex' :
|
|
313
|
+
const filter = options.codex ? 'codex' : options.claude ? 'claude' : null;
|
|
300
314
|
const limit = parseInt(options.limit, 10);
|
|
301
315
|
await registry.executeCommand('stats', provider, {
|
|
302
316
|
filter,
|
|
@@ -317,13 +331,16 @@ program
|
|
|
317
331
|
.argument('[provider]', '要检查的供应商名称(不指定则检查全部)')
|
|
318
332
|
.option('--codex', '仅检查 Codex CLI 供应商')
|
|
319
333
|
.option('--claude', '仅检查 Claude Code 供应商')
|
|
320
|
-
.option('--
|
|
334
|
+
.option('--connectivity', '执行在线 API 检查(可能产生费用)')
|
|
335
|
+
.option('--no-connectivity', '兼容参数:跳过在线 API 检查')
|
|
336
|
+
.option('--json', '以 JSON 输出健康检查结果')
|
|
321
337
|
.action(async (provider, options) => {
|
|
322
338
|
try {
|
|
323
|
-
const filter = options.codex ? 'codex' :
|
|
339
|
+
const filter = options.codex ? 'codex' : options.claude ? 'claude' : null;
|
|
324
340
|
await registry.executeCommand('health', provider, {
|
|
325
341
|
filter,
|
|
326
|
-
connectivity: options.connectivity
|
|
342
|
+
connectivity: options.connectivity === true,
|
|
343
|
+
json: options.json
|
|
327
344
|
});
|
|
328
345
|
} catch (error) {
|
|
329
346
|
console.error(chalk.red('❌ 健康检查失败:'), error.message);
|
|
@@ -340,7 +357,7 @@ program
|
|
|
340
357
|
.option('--unused', '仅操作长期未使用的供应商 (90天以上)')
|
|
341
358
|
.action(async (operation, options) => {
|
|
342
359
|
try {
|
|
343
|
-
const filter = options.codex ? 'codex' :
|
|
360
|
+
const filter = options.codex ? 'codex' : options.claude ? 'claude' : null;
|
|
344
361
|
await registry.executeCommand('batch', operation, {
|
|
345
362
|
filter,
|
|
346
363
|
unused: options.unused
|
|
@@ -360,9 +377,9 @@ program
|
|
|
360
377
|
.option('-r, --rounds <number>', '每个供应商测试轮数', '3')
|
|
361
378
|
.option('-p, --parallel', '并行测试(更快但可能不准确)')
|
|
362
379
|
.option('--report [file]', '生成 Markdown 测试报告')
|
|
363
|
-
.action(async
|
|
380
|
+
.action(async options => {
|
|
364
381
|
try {
|
|
365
|
-
const filter = options.codex ? 'codex' :
|
|
382
|
+
const filter = options.codex ? 'codex' : options.claude ? 'claude' : null;
|
|
366
383
|
const rounds = parseInt(options.rounds, 10);
|
|
367
384
|
await registry.executeCommand('benchmark', {
|
|
368
385
|
filter,
|
|
@@ -381,7 +398,7 @@ program
|
|
|
381
398
|
.command('claude')
|
|
382
399
|
.argument('<subcommand>', '子命令: clean (清理) | analyze (分析)')
|
|
383
400
|
.description('Claude Code 配置管理 (clean/analyze)')
|
|
384
|
-
.action(async
|
|
401
|
+
.action(async subcommand => {
|
|
385
402
|
try {
|
|
386
403
|
if (subcommand !== 'clean' && subcommand !== 'analyze') {
|
|
387
404
|
console.error(chalk.red(`❌ 未知子命令: ${subcommand}`));
|
|
@@ -400,7 +417,7 @@ program
|
|
|
400
417
|
.command('mcp')
|
|
401
418
|
.argument('<subcommand>', '子命令: list | add | edit | remove')
|
|
402
419
|
.description('MCP 服务器管理 (list/add/edit/remove)')
|
|
403
|
-
.action(async
|
|
420
|
+
.action(async subcommand => {
|
|
404
421
|
try {
|
|
405
422
|
await registry.executeCommand('mcp', subcommand);
|
|
406
423
|
} catch (error) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pikecode/api-key-manager",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.1",
|
|
4
4
|
"description": "A CLI tool for managing and switching multiple API provider configurations",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"bin": {
|
|
@@ -16,14 +16,19 @@
|
|
|
16
16
|
"start": "node bin/akm.js",
|
|
17
17
|
"dev": "nodemon bin/akm.js",
|
|
18
18
|
"test": "jest",
|
|
19
|
-
"
|
|
20
|
-
"lint
|
|
19
|
+
"test:coverage": "jest --coverage",
|
|
20
|
+
"lint": "eslint src tests",
|
|
21
|
+
"lint:fix": "eslint src tests --fix",
|
|
21
22
|
"format": "prettier --write \"src/**/*.js\" \"tests/**/*.js\"",
|
|
22
23
|
"format:check": "prettier --check \"src/**/*.js\" \"tests/**/*.js\"",
|
|
23
24
|
"build": "echo 'No build needed'",
|
|
24
25
|
"prepare": "echo 'Preparing package'",
|
|
25
|
-
"
|
|
26
|
-
"
|
|
26
|
+
"verify": "npm run lint -- --max-warnings=0 && npm run test:coverage -- --runInBand",
|
|
27
|
+
"prepublishOnly": "npm run verify",
|
|
28
|
+
"release": "npm publish --access public",
|
|
29
|
+
"release:patch": "npm version patch && npm publish --access public",
|
|
30
|
+
"release:minor": "npm version minor && npm publish --access public",
|
|
31
|
+
"release:major": "npm version major && npm publish --access public"
|
|
27
32
|
},
|
|
28
33
|
"keywords": [
|
|
29
34
|
"api",
|
|
@@ -58,12 +63,12 @@
|
|
|
58
63
|
"homepage": "https://github.com/pikecode/api-key-manager#readme",
|
|
59
64
|
"dependencies": {
|
|
60
65
|
"@anthropic-ai/sdk": "0.71.2",
|
|
66
|
+
"ajv": "^8.18.0",
|
|
61
67
|
"chalk": "^4.1.2",
|
|
62
68
|
"commander": "14.0.2",
|
|
63
69
|
"cross-spawn": "^7.0.3",
|
|
64
70
|
"fs-extra": "^11.1.1",
|
|
65
|
-
"inquirer": "^8.2.6"
|
|
66
|
-
"supports-color": "^9.4.0"
|
|
71
|
+
"inquirer": "^8.2.6"
|
|
67
72
|
},
|
|
68
73
|
"devDependencies": {
|
|
69
74
|
"eslint": "^9.39.2",
|
|
@@ -73,7 +78,7 @@
|
|
|
73
78
|
"prettier": "^3.8.1"
|
|
74
79
|
},
|
|
75
80
|
"engines": {
|
|
76
|
-
"node": ">=
|
|
81
|
+
"node": ">=20.0.0"
|
|
77
82
|
},
|
|
78
83
|
"os": [
|
|
79
84
|
"win32",
|
package/src/CommandRegistry.js
CHANGED
|
@@ -67,7 +67,7 @@ registry.registerLazy('current', async () => {
|
|
|
67
67
|
});
|
|
68
68
|
|
|
69
69
|
registry.registerLazy('edit', async () => {
|
|
70
|
-
const { editCommand } = require('./commands/
|
|
70
|
+
const { editCommand } = require('./commands/switch');
|
|
71
71
|
return editCommand;
|
|
72
72
|
});
|
|
73
73
|
|
|
@@ -126,4 +126,4 @@ registry.registerLazy('mcp', async () => {
|
|
|
126
126
|
return mcpCommand;
|
|
127
127
|
});
|
|
128
128
|
|
|
129
|
-
module.exports = { CommandRegistry, registry };
|
|
129
|
+
module.exports = { CommandRegistry, registry };
|