ai-account-switch 1.8.1 → 1.11.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/.playwright-mcp/grid-view-before.png +0 -0
- package/.playwright-mcp/list-view.png +0 -0
- package/CLAUDE.md +338 -0
- package/README.md +42 -6
- package/README_EN.md +40 -6
- package/package.json +4 -4
- package/src/commands/account.js +124 -23
- package/src/commands/env.js +728 -0
- package/src/commands/helpers.js +32 -0
- package/src/commands/index.js +22 -1
- package/src/commands/mcp.js +71 -13
- package/src/config.js +290 -33
- package/src/index.js +90 -25
- package/src/ui-server.js +1093 -9
|
Binary file
|
|
Binary file
|
package/CLAUDE.md
ADDED
|
@@ -0,0 +1,338 @@
|
|
|
1
|
+
# CLAUDE.md
|
|
2
|
+
|
|
3
|
+
本文件为 Claude Code (claude.ai/code) 在此仓库中工作时提供指导。
|
|
4
|
+
|
|
5
|
+
## 项目概述
|
|
6
|
+
|
|
7
|
+
AI Account Switch (ais) 是一个跨平台的命令行工具,用于在项目级别管理和切换不同的 AI 服务账号(Claude、Codex、CCR、Droids)。它会自动为各种 AI 工具生成配置文件,并提供 CLI 和 Web UI 两种界面。
|
|
8
|
+
|
|
9
|
+
## 开发命令
|
|
10
|
+
|
|
11
|
+
### 测试
|
|
12
|
+
```bash
|
|
13
|
+
# 本地运行 CLI 工具
|
|
14
|
+
npm test
|
|
15
|
+
|
|
16
|
+
# 全局链接以便测试
|
|
17
|
+
npm link
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
### 安装
|
|
21
|
+
```bash
|
|
22
|
+
# 安装依赖
|
|
23
|
+
npm install
|
|
24
|
+
|
|
25
|
+
# 开发时全局链接
|
|
26
|
+
npm link
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## 架构设计
|
|
30
|
+
|
|
31
|
+
### 核心组件
|
|
32
|
+
|
|
33
|
+
**ConfigManager (`src/config.js`)**
|
|
34
|
+
- 中央配置管理类
|
|
35
|
+
- 处理全局配置 (`~/.ai-account-switch/config.json`) 和项目配置 (`.ais-project-config`)
|
|
36
|
+
- 实现智能目录检测(类似 git 向上搜索)
|
|
37
|
+
- 管理账号 ID、MCP 服务器和模型组
|
|
38
|
+
- 关键方法:
|
|
39
|
+
- `findProjectRoot()` - 向上搜索项目配置
|
|
40
|
+
- `readGlobalConfig()` / `saveGlobalConfig()` - 全局账号存储
|
|
41
|
+
- `readProjectConfig()` / `saveProjectConfig()` - 项目特定设置
|
|
42
|
+
- `generateClaudeConfig()` - 创建 `.claude/settings.local.json`
|
|
43
|
+
- `generateCodexProfile()` - 创建 Codex TOML profiles
|
|
44
|
+
- `generateCCRConfig()` - 更新 CCR router 配置
|
|
45
|
+
- `generateDroidsConfig()` - 创建 Droids JSON 配置
|
|
46
|
+
|
|
47
|
+
**命令模块 (`src/commands/`)**
|
|
48
|
+
- 模块化命令结构,单一职责
|
|
49
|
+
- `account.js` - 账号 CRUD 操作(添加、列表、使用、删除、导出)
|
|
50
|
+
- `model.js` - Claude 账号的模型组管理
|
|
51
|
+
- `mcp.js` - MCP (Model Context Protocol) 服务器管理
|
|
52
|
+
- `env.js` - 环境变量管理(列表、添加、设置、删除、显示、清空、编辑)
|
|
53
|
+
- `utility.js` - 诊断和辅助命令(doctor、paths)
|
|
54
|
+
- `helpers.js` - 共享工具函数(maskApiKey、验证)
|
|
55
|
+
- `index.js` - 统一导出接口
|
|
56
|
+
|
|
57
|
+
**Web UI 服务器 (`src/ui-server.js`)**
|
|
58
|
+
- 内嵌 HTML/CSS/JS 的 HTTP 服务器
|
|
59
|
+
- 提供账号管理的单页应用
|
|
60
|
+
- 账号、MCP 和环境变量操作的 REST API 端点
|
|
61
|
+
- 使用随机高位端口(49152-65535)避免冲突
|
|
62
|
+
- 支持双语界面(中文/英文)
|
|
63
|
+
|
|
64
|
+
**CLI 入口点 (`src/index.js`)**
|
|
65
|
+
- 基于 Commander.js 的 CLI 界面
|
|
66
|
+
- 定义所有命令和子命令
|
|
67
|
+
- 双语帮助文本(中文/英文)
|
|
68
|
+
|
|
69
|
+
### 生成的配置文件
|
|
70
|
+
|
|
71
|
+
**Claude Code 集成**
|
|
72
|
+
- `.claude/settings.local.json` - 项目级 Claude 配置
|
|
73
|
+
- 包含 `env.ANTHROPIC_AUTH_TOKEN` 和 `env.ANTHROPIC_BASE_URL`
|
|
74
|
+
- 包含账号配置中的自定义环境变量
|
|
75
|
+
- 自动添加到 `.gitignore`
|
|
76
|
+
|
|
77
|
+
**Codex 集成**
|
|
78
|
+
- `~/.codex/config.toml` - 全局 Codex profiles
|
|
79
|
+
- `.codex-profile` - 项目级 profile 引用
|
|
80
|
+
- 使用 OpenAI 兼容的 `wire_api = "chat"` 格式
|
|
81
|
+
- 支持三种 wire API 模式:chat、responses、env
|
|
82
|
+
- 自动为仅域名的 URL 添加 `/v1`
|
|
83
|
+
|
|
84
|
+
**CCR (Claude Code Router) 集成**
|
|
85
|
+
- `~/.claude-code-router/config.json` - CCR 配置
|
|
86
|
+
- 更新 Providers 和 Router 部分
|
|
87
|
+
- 配置更改后自动重启 CCR router
|
|
88
|
+
- 路由到本地 CCR 端点(默认端口 3456)
|
|
89
|
+
|
|
90
|
+
**Droids 集成**
|
|
91
|
+
- `.droids/config.json` - 项目级 Droids 配置
|
|
92
|
+
- 简单的模型配置结构
|
|
93
|
+
|
|
94
|
+
**MCP 集成**
|
|
95
|
+
- 在 `~/.ai-account-switch/config.json` 中全局管理
|
|
96
|
+
- 项目级启用状态在项目配置中跟踪
|
|
97
|
+
- 同步到 `.claude/settings.local.json` 的 `mcpServers` 键下
|
|
98
|
+
- 支持 stdio、sse 和 http 服务器类型
|
|
99
|
+
- 支持三种作用范围(scope):
|
|
100
|
+
- `local`(默认):仅当前项目可用,配置存储在全局,启用状态在项目配置中
|
|
101
|
+
- `project`:与项目成员共享,配置存储在项目配置的 `projectMcpServers` 中
|
|
102
|
+
- `user`:当前用户所有项目可用,配置存储在全局,自动在所有项目中启用
|
|
103
|
+
|
|
104
|
+
**环境变量管理 (env)**
|
|
105
|
+
- 项目级别:存储在 `.claude/settings.local.json` 的 `env` 属性中
|
|
106
|
+
- 用户级别:存储在 `~/.claude/settings.json` 的 `env` 属性中(跨平台兼容)
|
|
107
|
+
- 支持的命令:
|
|
108
|
+
- `ais env list` - 列出所有环境变量(项目和用户级别)
|
|
109
|
+
- `ais env add` - 交互式添加环境变量
|
|
110
|
+
- `ais env set <key> <value>` - 直接设置环境变量
|
|
111
|
+
- `ais env remove` / `ais env rm` - 交互式删除环境变量
|
|
112
|
+
- `ais env unset <key>` - 直接删除环境变量
|
|
113
|
+
- `ais env show <key>` - 显示特定环境变量的值
|
|
114
|
+
- `ais env clear` - 清空所有环境变量
|
|
115
|
+
- `ais env edit` - 交互式编辑环境变量
|
|
116
|
+
- 配置合并:更新环境变量时保留其他配置设置(permissions、statusLine、enabledPlugins)
|
|
117
|
+
- Web UI 支持:提供环境变量的可视化管理和编辑
|
|
118
|
+
|
|
119
|
+
### 账号类型及其行为
|
|
120
|
+
|
|
121
|
+
**Claude**
|
|
122
|
+
- 标准 Anthropic API 集成
|
|
123
|
+
- 支持包含多个模型配置的复杂模型组
|
|
124
|
+
- 环境变量传递给 Claude Code
|
|
125
|
+
|
|
126
|
+
**Codex**
|
|
127
|
+
- 在 `~/.codex/config.toml` 中生成 TOML profiles
|
|
128
|
+
- 创建项目级 `.codex-profile` 文件
|
|
129
|
+
- 处理重复 profile 清理
|
|
130
|
+
- 智能 URL 处理(需要时自动添加 `/v1`)
|
|
131
|
+
- 支持 wire_api 模式选择(chat/responses/env)
|
|
132
|
+
|
|
133
|
+
**CCR (Claude Code Router)**
|
|
134
|
+
- 同时更新 Provider 和 Router 配置
|
|
135
|
+
- 需要三种模型类型:default、background、think
|
|
136
|
+
- 在 Provider 配置中自动去重模型
|
|
137
|
+
- 通过 `ccr restart` 自动重启 CCR router
|
|
138
|
+
|
|
139
|
+
**Droids**
|
|
140
|
+
- 简单的配置结构
|
|
141
|
+
- 可选的模型规格
|
|
142
|
+
- 项目级 `.droids/config.json`
|
|
143
|
+
|
|
144
|
+
### 关键设计模式
|
|
145
|
+
|
|
146
|
+
**智能目录检测**
|
|
147
|
+
- 类似 git 的 `.git` 目录搜索
|
|
148
|
+
- `findProjectRoot()` 向上遍历目录树
|
|
149
|
+
- 允许命令在任何子目录中工作
|
|
150
|
+
- 如果未找到项目配置则回退到当前目录
|
|
151
|
+
|
|
152
|
+
**账号 ID 系统**
|
|
153
|
+
- 自动递增的数字 ID(从 1 开始)
|
|
154
|
+
- 允许通过 `ais use 1` 快速切换而不是完整名称
|
|
155
|
+
- 向后兼容现有账号
|
|
156
|
+
- 首次运行时在迁移期间分配 ID
|
|
157
|
+
|
|
158
|
+
**模型组**
|
|
159
|
+
- 每个 Claude 账号可以有多个模型组
|
|
160
|
+
- 活动模型组决定使用哪些模型
|
|
161
|
+
- 切换模型组会自动更新 Claude 配置
|
|
162
|
+
- 支持 DEFAULT_MODEL 作为未指定模型的回退
|
|
163
|
+
|
|
164
|
+
**MCP 服务器管理**
|
|
165
|
+
- 全局服务器定义,项目级启用
|
|
166
|
+
- 与 `.mcp.json` 双向同步(导入/导出)
|
|
167
|
+
- 通过 spawn/HTTP 请求进行连接测试
|
|
168
|
+
- 三种服务器类型,不同的配置模式
|
|
169
|
+
- 支持三种作用范围(scope):
|
|
170
|
+
- `local`:仅当前项目可用,服务器定义在全局配置,启用状态在项目配置中
|
|
171
|
+
- `project`:与项目成员共享,服务器定义存储在项目配置的 `projectMcpServers` 中
|
|
172
|
+
- `user`:当前用户所有项目可用,服务器定义在全局配置,自动在所有项目中启用
|
|
173
|
+
|
|
174
|
+
**配置隔离**
|
|
175
|
+
- 全局账号存储在用户主目录
|
|
176
|
+
- 项目配置从不包含敏感数据(仅账号引用)
|
|
177
|
+
- 自动更新 `.gitignore` 以保护敏感文件
|
|
178
|
+
- 通过 `os.homedir()` 和 `path.join()` 处理跨平台路径
|
|
179
|
+
|
|
180
|
+
## 重要实现细节
|
|
181
|
+
|
|
182
|
+
### Wire API 模式处理(Codex)
|
|
183
|
+
添加 Codex 账号时,工具支持三种 wire API 模式:
|
|
184
|
+
- `chat`(默认)- OpenAI 兼容的聊天格式
|
|
185
|
+
- `responses` - Anthropic responses 格式
|
|
186
|
+
- `env` - 使用环境变量进行身份验证
|
|
187
|
+
|
|
188
|
+
模式存储在账号配置中,并在生成 Codex profiles 时应用。
|
|
189
|
+
|
|
190
|
+
### URL 规范化(Codex)
|
|
191
|
+
工具智能处理 API URL:
|
|
192
|
+
- 仅域名的 URL(如 `https://api.example.com`)→ 自动添加 `/v1`
|
|
193
|
+
- 带路径的 URL(如 `https://api.example.com/v2`)→ 保持原样
|
|
194
|
+
- 这可以防止常见的 Cloudflare 400 错误
|
|
195
|
+
|
|
196
|
+
### CCR Router 集成
|
|
197
|
+
使用 CCR 账号时:
|
|
198
|
+
1. 使用 Provider 和 Router 配置更新 `~/.claude-code-router/config.json`
|
|
199
|
+
2. 从配置中动态读取 CCR 端口(默认 3456)
|
|
200
|
+
3. 生成指向 `http://127.0.0.1:{port}` 的 `.claude/settings.local.json`
|
|
201
|
+
4. 尝试通过 `ccr restart` 命令重启 CCR
|
|
202
|
+
5. 如果未找到 CCR CLI,提供清晰的后续步骤
|
|
203
|
+
|
|
204
|
+
### Doctor 命令
|
|
205
|
+
`ais doctor` 命令通过检查以下内容诊断配置问题:
|
|
206
|
+
- 当前目录和项目根目录
|
|
207
|
+
- AIS 项目配置是否存在
|
|
208
|
+
- Claude Code 配置(`.claude/settings.local.json`)
|
|
209
|
+
- 全局 Claude 配置(`~/.claude/settings.json`)
|
|
210
|
+
- 账号类型特定的配置(Codex TOML、CCR JSON、Droids JSON)
|
|
211
|
+
- 提供可操作的修复建议
|
|
212
|
+
|
|
213
|
+
### Web UI 架构
|
|
214
|
+
UI 服务器将所有 HTML/CSS/JS 嵌入单个文件:
|
|
215
|
+
- 无外部依赖或构建步骤
|
|
216
|
+
- 为根路径提供静态 HTML
|
|
217
|
+
- 数据操作的 REST API 端点
|
|
218
|
+
- 自动端口冲突解决
|
|
219
|
+
- 启动时自动打开浏览器
|
|
220
|
+
|
|
221
|
+
### 环境变量管理实现细节
|
|
222
|
+
**跨平台路径处理**
|
|
223
|
+
- 使用 `ConfigManager.getClaudeUserConfigPath()` 方法获取用户配置文件路径
|
|
224
|
+
- 优先级顺序:`~/.claude/settings.json` > 平台特定路径 > `~/.claude.json`(遗留)
|
|
225
|
+
- Windows 支持:`%APPDATA%\claude\settings.json`
|
|
226
|
+
- macOS/Linux 支持:`~/.config/claude/settings.json`
|
|
227
|
+
|
|
228
|
+
**配置合并策略**
|
|
229
|
+
- 读取现有配置文件,保留非 `env` 属性设置
|
|
230
|
+
- 仅更新 `env` 属性,不覆盖 `permissions`、`statusLine`、`enabledPlugins` 等
|
|
231
|
+
- 确保 `env` 属性存在,避免 `undefined` 错误
|
|
232
|
+
|
|
233
|
+
**命令模式**
|
|
234
|
+
- 交互式命令(add、remove、edit):使用 Inquirer.js 提供友好的用户界面
|
|
235
|
+
- 非交互式命令(set、unset、show):适合脚本和自动化
|
|
236
|
+
- 支持通过 `--level` 选项指定项目或用户级别
|
|
237
|
+
|
|
238
|
+
**安全性考虑**
|
|
239
|
+
- 显示环境变量时自动屏蔽包含 `KEY` 或 `TOKEN` 的变量值
|
|
240
|
+
- 支持在 Web UI 中安全地编辑敏感变量
|
|
241
|
+
|
|
242
|
+
## 测试注意事项
|
|
243
|
+
|
|
244
|
+
测试或修改时:
|
|
245
|
+
- 测试跨平台行为(macOS、Linux、Windows)
|
|
246
|
+
- 验证 `.gitignore` 更新正常工作
|
|
247
|
+
- 从各种子目录测试目录检测
|
|
248
|
+
- 确保账号 ID 迁移适用于现有配置
|
|
249
|
+
- 测试所有账号类型(Claude、Codex、CCR、Droids)
|
|
250
|
+
- 验证 MCP 服务器连接测试
|
|
251
|
+
- 在不同浏览器中测试 Web UI
|
|
252
|
+
- 测试环境变量命令的跨平台路径解析
|
|
253
|
+
- 验证环境变量配置合并不会丢失其他设置
|
|
254
|
+
- 测试环境变量在项目和用户级别的正确隔离
|
|
255
|
+
|
|
256
|
+
## 常见陷阱
|
|
257
|
+
|
|
258
|
+
**Codex Profile 重复**
|
|
259
|
+
- 写入新 profile 之前必须清理旧 profile
|
|
260
|
+
- 使用正则表达式匹配包括嵌套内容的整个 profile 部分
|
|
261
|
+
- 使用各种 TOML 结构进行测试
|
|
262
|
+
|
|
263
|
+
**CCR Router 重启**
|
|
264
|
+
- CCR CLI 必须已安装并在 PATH 中
|
|
265
|
+
- 优雅处理未找到 `ccr` 命令的情况
|
|
266
|
+
- 提供手动重启的清晰说明
|
|
267
|
+
|
|
268
|
+
**路径处理**
|
|
269
|
+
- 始终使用 `path.join()` 以实现跨平台兼容性
|
|
270
|
+
- 使用 `os.homedir()` 而不是 `~` 扩展
|
|
271
|
+
- 正确处理路径中的空格
|
|
272
|
+
|
|
273
|
+
**配置合并**
|
|
274
|
+
- 更新配置时,保留现有的非 AIS 设置
|
|
275
|
+
- 不要覆盖用户的自定义权限或其他设置
|
|
276
|
+
- 仅更新 AIS 管理的特定部分
|
|
277
|
+
|
|
278
|
+
**环境变量配置处理**
|
|
279
|
+
- 读取配置时确保 `env` 属性存在,避免 `undefined` 错误
|
|
280
|
+
- 写入配置时必须先读取现有配置,只合并 `env` 属性
|
|
281
|
+
- 使用跨平台兼容的路径方法 `ConfigManager.getClaudeUserConfigPath()`
|
|
282
|
+
- 不同操作系统的用户配置文件路径可能不同(Windows 使用 APPDATA,macOS/Linux 使用 .config)
|
|
283
|
+
|
|
284
|
+
**终端颜色使用规范**
|
|
285
|
+
⚠️ **重要:所有 CLI 输出必须严格遵守以下颜色规范**
|
|
286
|
+
|
|
287
|
+
| 颜色 | 用途 | 示例 |
|
|
288
|
+
|------|------|------|
|
|
289
|
+
| `chalk.green` | ✅ 成功操作、可用状态、完成标记 | `console.log(chalk.green('✓ Account added successfully!'))` |
|
|
290
|
+
| `chalk.red` | ❌ 错误、失败、不可用状态 | `console.error(chalk.red('✗ Error:'), error.message)` |
|
|
291
|
+
| `chalk.yellow` | ⚠️ 警告、取消操作、未配置、信息提示 | `console.log(chalk.yellow('⚠ No account set'))` |
|
|
292
|
+
| `chalk.cyan` | 📋 **标签**(如 "Path:", "Config:", "Level:")、信息标题、变量名 | `` `${chalk.cyan('Path:')} ${path}` `` |
|
|
293
|
+
| `chalk.yellow` | **变量值** | `` `${chalk.cyan(key)} = ${chalk.yellow(value)}` `` |
|
|
294
|
+
| `chalk.gray` | 辅助信息、次要内容、bullet 点 | `console.log(chalk.gray(' • Server name'))` |
|
|
295
|
+
| `chalk.bold` | 🔍 标题、章节标题 | `console.log(chalk.bold('COMMANDS:'))` |
|
|
296
|
+
| `chalk.green.bold` | 活动状态标记 | `console.log(chalk.green.bold('● Active'))` |
|
|
297
|
+
|
|
298
|
+
**格式规范:**
|
|
299
|
+
- **标签格式**:`` `${chalk.cyan('Label:')} value` ``(标签用 cyan,值用默认颜色)
|
|
300
|
+
- **错误格式**:`console.error(chalk.red('✗ Error:'), error.message)`
|
|
301
|
+
- **成功格式**:`console.log(chalk.green('✓ Success message'))`
|
|
302
|
+
- **警告格式**:`console.log(chalk.yellow('⚠ Warning message'))`
|
|
303
|
+
- **标题格式**:`console.log(chalk.bold('Section Title:'))`
|
|
304
|
+
|
|
305
|
+
**反面示例(禁止使用):**
|
|
306
|
+
```javascript
|
|
307
|
+
// ❌ 错误:标签不应该用 gray
|
|
308
|
+
console.log(chalk.gray(` Config: ${configPath}`));
|
|
309
|
+
|
|
310
|
+
// ❌ 错误:标签不应该用 bold
|
|
311
|
+
console.log(chalk.bold('Level:'), 'Project');
|
|
312
|
+
|
|
313
|
+
// ❌ 错误:不应该整行用一种颜色
|
|
314
|
+
console.log(chalk.cyan(` Config file: ${configPath}`));
|
|
315
|
+
```
|
|
316
|
+
|
|
317
|
+
**正确示例:**
|
|
318
|
+
```javascript
|
|
319
|
+
// ✅ 正确:标签用 cyan,值用默认颜色
|
|
320
|
+
console.log(` ${chalk.cyan('Config:')} ${configPath}`);
|
|
321
|
+
|
|
322
|
+
// ✅ 正确:标题用 cyan
|
|
323
|
+
console.log(chalk.cyan(`\n📋 Environment Variables\n`));
|
|
324
|
+
|
|
325
|
+
// ✅ 正确:变量名用 cyan,值用 yellow
|
|
326
|
+
console.log(` ${chalk.gray('•')} ${chalk.cyan(key)} = ${chalk.yellow(value)}`);
|
|
327
|
+
```
|
|
328
|
+
|
|
329
|
+
## 文件命名约定
|
|
330
|
+
|
|
331
|
+
- 全局配置:`~/.ai-account-switch/config.json`
|
|
332
|
+
- 项目配置:`.ais-project-config`
|
|
333
|
+
- Claude 配置:`.claude/settings.local.json`
|
|
334
|
+
- Claude 用户配置:`~/.claude/settings.json`(跨平台:Windows `%APPDATA%\claude\settings.json`,macOS/Linux `~/.config/claude/settings.json`)
|
|
335
|
+
- Codex profile:`.codex-profile`
|
|
336
|
+
- Codex 全局:`~/.codex/config.toml`
|
|
337
|
+
- CCR 配置:`~/.claude-code-router/config.json`
|
|
338
|
+
- Droids 配置:`.droids/config.json`
|
package/README.md
CHANGED
|
@@ -73,11 +73,11 @@ npm link
|
|
|
73
73
|
| 命令 | 别名 | 描述 |
|
|
74
74
|
|------|------|------|
|
|
75
75
|
| `ais add [name]` | - | 添加新的账户配置 |
|
|
76
|
-
| `ais list` | `ls` |
|
|
77
|
-
| `ais use [name]` | - | 为当前项目设置账户 |
|
|
76
|
+
| `ais list` | `ls` | 列出所有可用账户(含ID) |
|
|
77
|
+
| `ais use [name-or-id]` | - | 通过名称或ID为当前项目设置账户 |
|
|
78
78
|
| `ais info` | - | 显示当前项目的账户信息 |
|
|
79
79
|
| `ais current` | - | 显示当前账户名称 |
|
|
80
|
-
| `ais remove [name]` | `rm` | 删除账户 |
|
|
80
|
+
| `ais remove [name-or-id]` | `rm` | 通过名称或ID删除账户 |
|
|
81
81
|
| `ais model list` | `ls` | 列出当前账户的所有模型组 |
|
|
82
82
|
| `ais model add [name]` | - | 添加新的模型组 |
|
|
83
83
|
| `ais model use <name>` | - | 切换到不同的模型组 |
|
|
@@ -95,7 +95,7 @@ npm link
|
|
|
95
95
|
| `ais ui` | - | 启动 Web UI 管理界面 |
|
|
96
96
|
| `ais paths` | - | 显示配置文件路径 |
|
|
97
97
|
| `ais doctor` | - | 诊断 Claude Code 配置问题 |
|
|
98
|
-
| `ais export <name>` | - | 导出账户为 JSON 格式 |
|
|
98
|
+
| `ais export <name-or-id>` | - | 通过名称或ID导出账户为 JSON 格式 |
|
|
99
99
|
| `ais help` | - | 显示帮助信息 |
|
|
100
100
|
| `ais --version` | - | 显示版本号 |
|
|
101
101
|
|
|
@@ -128,7 +128,7 @@ ais add my-claude-account
|
|
|
128
128
|
|
|
129
129
|
#### 2. 列出所有账户
|
|
130
130
|
|
|
131
|
-
|
|
131
|
+
查看所有已配置的账户及其ID:
|
|
132
132
|
|
|
133
133
|
```bash
|
|
134
134
|
ais list
|
|
@@ -136,14 +136,33 @@ ais list
|
|
|
136
136
|
ais ls
|
|
137
137
|
```
|
|
138
138
|
|
|
139
|
+
输出示例:
|
|
140
|
+
```
|
|
141
|
+
📋 Available Accounts (可用账号):
|
|
142
|
+
|
|
143
|
+
● [1] my-claude-account
|
|
144
|
+
Type: Claude
|
|
145
|
+
API Key: sk-a****xyz
|
|
146
|
+
...
|
|
147
|
+
|
|
148
|
+
[2] work-codex
|
|
149
|
+
Type: Codex
|
|
150
|
+
API Key: sk-b****abc
|
|
151
|
+
...
|
|
152
|
+
```
|
|
153
|
+
|
|
139
154
|
当前项目激活的账户将用绿色圆点标记。
|
|
140
155
|
|
|
141
156
|
#### 3. 为当前项目切换账户
|
|
142
157
|
|
|
143
|
-
|
|
158
|
+
设置当前项目使用的账户(可以使用账户名或ID):
|
|
144
159
|
|
|
145
160
|
```bash
|
|
161
|
+
# 使用账户名
|
|
146
162
|
ais use my-claude-account
|
|
163
|
+
|
|
164
|
+
# 或使用ID(更快捷)
|
|
165
|
+
ais use 1
|
|
147
166
|
```
|
|
148
167
|
|
|
149
168
|
或交互式选择:
|
|
@@ -1005,6 +1024,23 @@ ais mcp remove filesystem
|
|
|
1005
1024
|
MIT License - 欢迎在你的项目中使用此工具!
|
|
1006
1025
|
|
|
1007
1026
|
## 更新日志
|
|
1027
|
+
### v1.9.1
|
|
1028
|
+
- **codex帐号添加env 配置方式**:
|
|
1029
|
+
- codex 支持env 临时export user-api-key 的方式认证.
|
|
1030
|
+
### v1.9.0
|
|
1031
|
+
- **账号ID功能**:
|
|
1032
|
+
- 为每个账号自动分配唯一数字ID(从1开始递增)
|
|
1033
|
+
- 支持通过ID快速切换账号:`ais use 1`
|
|
1034
|
+
- 支持通过ID删除账号:`ais remove 2`
|
|
1035
|
+
- 支持通过ID导出账号:`ais export 3`
|
|
1036
|
+
- 账号列表展示格式优化:`[ID] AccountName`
|
|
1037
|
+
- ID使用黄色高亮显示,更加清晰可见
|
|
1038
|
+
- 完全向后兼容:已有账号自动分配ID
|
|
1039
|
+
- 交互式选择账号时同时显示ID和名称
|
|
1040
|
+
- **文档更新**:
|
|
1041
|
+
- 更新所有命令说明,添加ID使用示例
|
|
1042
|
+
- 中英文README同步更新
|
|
1043
|
+
- Help命令输出优化
|
|
1008
1044
|
|
|
1009
1045
|
### v1.7.0
|
|
1010
1046
|
- **MCP Web UI 管理**:
|
package/README_EN.md
CHANGED
|
@@ -66,11 +66,11 @@ npm link
|
|
|
66
66
|
| Command | Alias | Description |
|
|
67
67
|
|---------|-------|-------------|
|
|
68
68
|
| `ais add [name]` | - | Add a new account configuration |
|
|
69
|
-
| `ais list` | `ls` | List all available accounts |
|
|
70
|
-
| `ais use [name]` | - | Set account for current project |
|
|
69
|
+
| `ais list` | `ls` | List all available accounts with IDs |
|
|
70
|
+
| `ais use [name-or-id]` | - | Set account for current project by name or ID |
|
|
71
71
|
| `ais info` | - | Show current project's account info |
|
|
72
72
|
| `ais current` | - | Show current account name |
|
|
73
|
-
| `ais remove [name]` | `rm` | Remove an account |
|
|
73
|
+
| `ais remove [name-or-id]` | `rm` | Remove an account by name or ID |
|
|
74
74
|
| `ais model list` | `ls` | List all model groups for current account |
|
|
75
75
|
| `ais model add [name]` | - | Add a new model group |
|
|
76
76
|
| `ais model use <name>` | - | Switch to a different model group |
|
|
@@ -88,7 +88,7 @@ npm link
|
|
|
88
88
|
| `ais ui` | - | Start web-based UI manager |
|
|
89
89
|
| `ais paths` | - | Show configuration file paths |
|
|
90
90
|
| `ais doctor` | - | Diagnose configuration issues |
|
|
91
|
-
| `ais export <name>` | - | Export account as JSON |
|
|
91
|
+
| `ais export <name-or-id>` | - | Export account as JSON by name or ID |
|
|
92
92
|
| `ais help` | - | Display help information |
|
|
93
93
|
| `ais --version` | - | Show version number |
|
|
94
94
|
|
|
@@ -122,7 +122,7 @@ You'll be prompted to enter:
|
|
|
122
122
|
|
|
123
123
|
#### 2. List All Accounts
|
|
124
124
|
|
|
125
|
-
View all your configured accounts:
|
|
125
|
+
View all your configured accounts with their IDs:
|
|
126
126
|
|
|
127
127
|
```bash
|
|
128
128
|
ais list
|
|
@@ -130,14 +130,33 @@ ais list
|
|
|
130
130
|
ais ls
|
|
131
131
|
```
|
|
132
132
|
|
|
133
|
+
Example output:
|
|
134
|
+
```
|
|
135
|
+
📋 Available Accounts:
|
|
136
|
+
|
|
137
|
+
● [1] my-claude-account
|
|
138
|
+
Type: Claude
|
|
139
|
+
API Key: sk-a****xyz
|
|
140
|
+
...
|
|
141
|
+
|
|
142
|
+
[2] work-codex
|
|
143
|
+
Type: Codex
|
|
144
|
+
API Key: sk-b****abc
|
|
145
|
+
...
|
|
146
|
+
```
|
|
147
|
+
|
|
133
148
|
The active account for the current project will be marked with a green dot.
|
|
134
149
|
|
|
135
150
|
#### 3. Switch Account for Current Project
|
|
136
151
|
|
|
137
|
-
Set which account to use in your current project:
|
|
152
|
+
Set which account to use in your current project (by name or ID):
|
|
138
153
|
|
|
139
154
|
```bash
|
|
155
|
+
# Use account by name
|
|
140
156
|
ais use my-claude-account
|
|
157
|
+
|
|
158
|
+
# Or use account by ID (faster)
|
|
159
|
+
ais use 1
|
|
141
160
|
```
|
|
142
161
|
|
|
143
162
|
Or select interactively:
|
|
@@ -997,6 +1016,21 @@ MIT License - feel free to use this tool in your projects!
|
|
|
997
1016
|
|
|
998
1017
|
## Changelog
|
|
999
1018
|
|
|
1019
|
+
### v1.9.0
|
|
1020
|
+
- **Account ID Feature**:
|
|
1021
|
+
- Automatically assign unique numeric ID to each account (starting from 1)
|
|
1022
|
+
- Quick account switching by ID: `ais use 1`
|
|
1023
|
+
- Remove account by ID: `ais remove 2`
|
|
1024
|
+
- Export account by ID: `ais export 3`
|
|
1025
|
+
- Optimized account list display format: `[ID] AccountName`
|
|
1026
|
+
- ID displayed in yellow color for better visibility
|
|
1027
|
+
- Fully backward compatible: existing accounts automatically assigned IDs
|
|
1028
|
+
- Interactive selection shows both ID and name
|
|
1029
|
+
- **Documentation Updates**:
|
|
1030
|
+
- Updated all command descriptions with ID usage examples
|
|
1031
|
+
- Synchronized Chinese and English README
|
|
1032
|
+
- Optimized help command output
|
|
1033
|
+
|
|
1000
1034
|
### v1.7.0
|
|
1001
1035
|
- **MCP Web UI Management**:
|
|
1002
1036
|
- Complete MCP server management through Web UI
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ai-account-switch",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.11.0",
|
|
4
4
|
"description": "A cross-platform CLI tool to manage and switch Claude/Codex/Droids account configurations",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"bin": {
|
|
@@ -37,10 +37,10 @@
|
|
|
37
37
|
},
|
|
38
38
|
"repository": {
|
|
39
39
|
"type": "git",
|
|
40
|
-
"url": "https://github.com/
|
|
40
|
+
"url": "https://github.com/DeanWanghewei/ai-agent-user-swith.git"
|
|
41
41
|
},
|
|
42
42
|
"bugs": {
|
|
43
|
-
"url": "https://github.com/
|
|
43
|
+
"url": "https://github.com/DeanWanghewei/ai-agent-user-swith/issues"
|
|
44
44
|
},
|
|
45
|
-
"homepage": "https://github.com/
|
|
45
|
+
"homepage": "https://github.com/DeanWanghewei/ai-agent-user-swith#readme"
|
|
46
46
|
}
|