@minniexcode/codex-switch 0.0.10 → 0.0.12
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.AI.md +68 -73
- package/README.CN.md +108 -111
- package/README.md +87 -80
- package/dist/app/add-provider.js +29 -15
- package/dist/app/bridge.js +15 -14
- package/dist/app/edit-provider.js +1 -1
- package/dist/app/get-status.js +21 -9
- package/dist/app/import-providers.js +1 -1
- package/dist/app/init-codex.js +13 -14
- package/dist/app/list-providers.js +48 -1
- package/dist/app/remove-provider.js +1 -1
- package/dist/app/run-doctor.js +12 -5
- package/dist/app/run-mutation.js +3 -2
- package/dist/app/setup-codex.js +3 -1
- package/dist/app/switch-provider.js +11 -13
- package/dist/cli/output.js +145 -18
- package/dist/cli.js +34 -2
- package/dist/commands/args.js +2 -2
- package/dist/commands/dispatch.js +40 -0
- package/dist/commands/handlers.js +130 -161
- package/dist/commands/help.js +11 -5
- package/dist/commands/registry.js +42 -20
- package/dist/domain/backups.js +4 -4
- package/dist/domain/config.js +110 -5
- package/dist/domain/providers.js +12 -0
- package/dist/domain/runtime-state.js +111 -13
- package/dist/infra/config-repo.js +16 -206
- package/dist/interaction/interactive.js +16 -6
- package/dist/runtime/copilot-adapter.js +12 -12
- package/dist/runtime/copilot-bridge.js +394 -45
- package/dist/runtime/copilot-cli.js +84 -12
- package/dist/runtime/copilot-installer.js +10 -9
- package/dist/runtime/copilot-sdk-loader.js +5 -5
- package/dist/storage/backup-repo.js +4 -4
- package/dist/storage/codex-paths.js +34 -8
- package/dist/storage/config-repo.js +0 -23
- package/dist/storage/lock-repo.js +2 -4
- package/dist/storage/runtime-state-repo.js +14 -13
- package/dist/storage/tool-config-repo.js +111 -0
- package/docs/Design/codex-switch-v0.0.11-design.md +824 -0
- package/docs/Design/codex-switch-v0.0.12-design.md +343 -0
- package/docs/PRD/codex-switch-prd-v0.0.11.md +577 -0
- package/docs/PRD/codex-switch-prd-v0.0.12.md +279 -0
- package/docs/PRD/codex-switch-prd-v0.1.0.md +125 -237
- package/docs/Tests/testing.md +39 -112
- package/docs/cli-usage.md +135 -565
- package/docs/codex-switch-command-design.md +3 -0
- package/docs/codex-switch-product-overview.md +52 -207
- package/docs/codex-switch-technical-architecture.md +3 -0
- package/package.json +1 -1
- package/dist/app/rollback-latest.js +0 -26
package/docs/cli-usage.md
CHANGED
|
@@ -1,653 +1,223 @@
|
|
|
1
1
|
# codex-switch CLI Usage
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
This document describes the current CLI contract for `@minniexcode/codex-switch` at version `0.0.12`.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
Executable command name:
|
|
6
6
|
|
|
7
7
|
```bash
|
|
8
8
|
codexs
|
|
9
9
|
```
|
|
10
10
|
|
|
11
|
-
## 1.
|
|
11
|
+
## 1. Version Context
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
The current package version in this repository is `0.0.12`.
|
|
14
14
|
|
|
15
|
-
|
|
15
|
+
This is still a development-version release. The command surface already exists, but this version mainly focuses on keeping workflow guidance, help text, and implementation behavior aligned.
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
2. 写入前先备份,异常时支持回滚
|
|
19
|
-
3. 同时兼容人类终端使用和脚本/Agent 自动化调用
|
|
17
|
+
## 2. Primary Workflows
|
|
20
18
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
```text
|
|
24
|
-
~/.codex/
|
|
25
|
-
config.toml
|
|
26
|
-
auth.json
|
|
27
|
-
providers.json
|
|
28
|
-
backups/
|
|
29
|
-
```
|
|
30
|
-
|
|
31
|
-
## 2. 安装与入口
|
|
32
|
-
|
|
33
|
-
全局安装:
|
|
34
|
-
|
|
35
|
-
```bash
|
|
36
|
-
npm install -g @minniexcode/codex-switch
|
|
37
|
-
```
|
|
38
|
-
|
|
39
|
-
临时执行:
|
|
40
|
-
|
|
41
|
-
```bash
|
|
42
|
-
npx @minniexcode/codex-switch --help
|
|
43
|
-
```
|
|
44
|
-
|
|
45
|
-
查看总帮助:
|
|
46
|
-
|
|
47
|
-
```bash
|
|
48
|
-
codexs --help
|
|
49
|
-
```
|
|
50
|
-
|
|
51
|
-
查看版本:
|
|
52
|
-
|
|
53
|
-
```bash
|
|
54
|
-
codexs --version
|
|
55
|
-
```
|
|
56
|
-
|
|
57
|
-
## 3. 全局规则
|
|
58
|
-
|
|
59
|
-
### 3.1 全局参数
|
|
60
|
-
|
|
61
|
-
所有命令都支持以下全局参数:
|
|
62
|
-
|
|
63
|
-
```bash
|
|
64
|
-
--json
|
|
65
|
-
--codex-dir <path>
|
|
66
|
-
--help
|
|
67
|
-
--version
|
|
68
|
-
```
|
|
69
|
-
|
|
70
|
-
说明:
|
|
71
|
-
|
|
72
|
-
- `--json`:输出标准 JSON 结果,并禁用所有交互 prompt
|
|
73
|
-
- `--codex-dir <path>`:将目标目录从默认 `~/.codex` 改成指定路径
|
|
74
|
-
- `--help`:查看命令帮助
|
|
75
|
-
- `--version`:输出当前 CLI 版本
|
|
76
|
-
|
|
77
|
-
### 3.2 交互规则
|
|
78
|
-
|
|
79
|
-
CLI 的交互行为遵循以下规则:
|
|
80
|
-
|
|
81
|
-
- 只有在真实 TTY 终端下才会出现 prompt
|
|
82
|
-
- 只要传入 `--json`,就绝不会出现 prompt
|
|
83
|
-
- 面向脚本或 CI 的调用应显式传参,并优先使用 `--json`
|
|
84
|
-
- 某些危险操作在交互模式下会确认,在非交互模式下则要求显式参数
|
|
85
|
-
|
|
86
|
-
### 3.3 备份与回滚
|
|
87
|
-
|
|
88
|
-
所有受管理的写操作都会先备份相关文件,再执行写入。
|
|
89
|
-
|
|
90
|
-
典型受影响命令包括:
|
|
91
|
-
|
|
92
|
-
- `migrate`
|
|
93
|
-
- `add`
|
|
94
|
-
- `edit`
|
|
95
|
-
- `switch`
|
|
96
|
-
- `remove`
|
|
97
|
-
- `import`
|
|
98
|
-
|
|
99
|
-
如果操作失败,命令内部会尽量自动回滚。你也可以稍后手动执行:
|
|
100
|
-
|
|
101
|
-
```bash
|
|
102
|
-
codexs rollback
|
|
103
|
-
codexs rollback <backup-id>
|
|
104
|
-
```
|
|
105
|
-
|
|
106
|
-
## 4. 读取类命令
|
|
107
|
-
|
|
108
|
-
### 4.1 `list`
|
|
109
|
-
|
|
110
|
-
列出 `providers.json` 中的全部 provider。
|
|
111
|
-
|
|
112
|
-
```bash
|
|
113
|
-
codexs list [--json] [--codex-dir <path>]
|
|
114
|
-
```
|
|
115
|
-
|
|
116
|
-
示例:
|
|
117
|
-
|
|
118
|
-
```bash
|
|
119
|
-
codexs list
|
|
120
|
-
codexs list --json
|
|
121
|
-
```
|
|
122
|
-
|
|
123
|
-
适用场景:
|
|
124
|
-
|
|
125
|
-
- 查看当前已管理 provider 列表
|
|
126
|
-
- 给后续 `switch`、`show`、`edit`、`remove` 提供候选名称
|
|
127
|
-
|
|
128
|
-
### 4.2 `show`
|
|
129
|
-
|
|
130
|
-
查看单个 provider 的完整记录。
|
|
131
|
-
|
|
132
|
-
```bash
|
|
133
|
-
codexs show <provider> [--json] [--codex-dir <path>]
|
|
134
|
-
```
|
|
135
|
-
|
|
136
|
-
示例:
|
|
137
|
-
|
|
138
|
-
```bash
|
|
139
|
-
codexs show packycode
|
|
140
|
-
codexs show packycode --json
|
|
141
|
-
```
|
|
142
|
-
|
|
143
|
-
说明:
|
|
144
|
-
|
|
145
|
-
- 普通文本输出会默认隐藏 `apiKey`
|
|
146
|
-
- `--json` 模式会输出完整 provider 数据,适合本地自动化
|
|
147
|
-
|
|
148
|
-
### 4.3 `current`
|
|
149
|
-
|
|
150
|
-
查看 `config.toml` 当前激活的顶层 profile。
|
|
151
|
-
|
|
152
|
-
```bash
|
|
153
|
-
codexs current [--json] [--codex-dir <path>]
|
|
154
|
-
```
|
|
155
|
-
|
|
156
|
-
示例:
|
|
157
|
-
|
|
158
|
-
```bash
|
|
159
|
-
codexs current
|
|
160
|
-
codexs current --json
|
|
161
|
-
```
|
|
162
|
-
|
|
163
|
-
说明:
|
|
164
|
-
|
|
165
|
-
- 如果缺少 `config.toml`,或配置中没有顶层 profile,会直接报错
|
|
166
|
-
|
|
167
|
-
### 4.4 `status`
|
|
168
|
-
|
|
169
|
-
输出本地 Codex 目录的快速状态摘要。
|
|
170
|
-
|
|
171
|
-
```bash
|
|
172
|
-
codexs status [--json] [--codex-dir <path>]
|
|
173
|
-
```
|
|
174
|
-
|
|
175
|
-
示例:
|
|
19
|
+
### 2.1 Direct Providers
|
|
176
20
|
|
|
177
21
|
```bash
|
|
22
|
+
codexs init
|
|
23
|
+
codexs add <provider> --profile <name> --api-key <key>
|
|
24
|
+
codexs switch <provider>
|
|
178
25
|
codexs status
|
|
179
|
-
codexs
|
|
180
|
-
```
|
|
181
|
-
|
|
182
|
-
通常会覆盖这些信息:
|
|
183
|
-
|
|
184
|
-
- 关键文件是否存在
|
|
185
|
-
- 当前激活 profile 是什么
|
|
186
|
-
- 当前运行态是否能在受管理的 provider 映射中找到
|
|
187
|
-
|
|
188
|
-
### 4.5 `backups list`
|
|
189
|
-
|
|
190
|
-
查看历史备份清单。
|
|
191
|
-
|
|
192
|
-
```bash
|
|
193
|
-
codexs backups list [--json] [--codex-dir <path>]
|
|
194
|
-
```
|
|
195
|
-
|
|
196
|
-
示例:
|
|
197
|
-
|
|
198
|
-
```bash
|
|
199
|
-
codexs backups list
|
|
200
|
-
codexs backups list --json
|
|
26
|
+
codexs doctor
|
|
201
27
|
```
|
|
202
28
|
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
- 返回结果按 `createdAt` 倒序排列
|
|
206
|
-
- 损坏的备份 manifest 会被跳过,并给出 warning,不会导致整个命令失败
|
|
207
|
-
|
|
208
|
-
## 5. 变更类命令
|
|
29
|
+
Intent:
|
|
209
30
|
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
codexs init [--json] [--codex-dir <path>]
|
|
216
|
-
```
|
|
31
|
+
- `init` prepares the `codex-switch` tool home.
|
|
32
|
+
- `add` creates a managed provider record.
|
|
33
|
+
- `switch` projects the selected provider into the target Codex runtime.
|
|
34
|
+
- `status` summarizes tool-home, runtime, provider, and health state.
|
|
35
|
+
- `doctor` gives deeper repair-oriented diagnostics.
|
|
217
36
|
|
|
218
|
-
|
|
37
|
+
### 2.2 GitHub Copilot
|
|
219
38
|
|
|
220
39
|
```bash
|
|
221
40
|
codexs init
|
|
222
|
-
codexs
|
|
223
|
-
codexs
|
|
41
|
+
codexs login copilot
|
|
42
|
+
codexs add <provider> --copilot --profile <name>
|
|
43
|
+
codexs switch <provider>
|
|
44
|
+
codexs status
|
|
45
|
+
codexs doctor
|
|
224
46
|
```
|
|
225
47
|
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
- 不依赖 `codex` 可执行文件
|
|
229
|
-
- 不要求 `config.toml` 或 `auth.json` 已存在
|
|
230
|
-
- `providers.json` 不存在时创建空 registry:`{ "providers": {} }`
|
|
231
|
-
- `providers.json` 已存在时返回成功 no-op,不改写文件,也不会创建备份
|
|
232
|
-
- 成功 JSON 结果固定包含:`codexDir`、`createdCodexDir`、`createdProvidersFile`、`providersAlreadyExisted`、`configExists`、`authExists`
|
|
233
|
-
|
|
234
|
-
交互模式:
|
|
48
|
+
Important notes:
|
|
235
49
|
|
|
236
|
-
-
|
|
237
|
-
-
|
|
50
|
+
- `login copilot` is the upstream onboarding command.
|
|
51
|
+
- The current implementation prefers the bundled Copilot CLI from the managed runtime and falls back to `PATH` when needed.
|
|
52
|
+
- `login copilot` succeeds only after auth readiness is rechecked.
|
|
53
|
+
- `add --copilot` does not install or log in to Copilot for you.
|
|
238
54
|
|
|
239
|
-
|
|
55
|
+
## 3. Advanced Adopt Workflow
|
|
240
56
|
|
|
241
|
-
|
|
242
|
-
- 目标目录不存在时直接返回结构化错误
|
|
243
|
-
|
|
244
|
-
### 5.2 `migrate`
|
|
245
|
-
|
|
246
|
-
从现有 `config.toml` adopt unmanaged profiles,并写入受管理的 `providers.json`。
|
|
247
|
-
|
|
248
|
-
```bash
|
|
249
|
-
codexs migrate [--json] [--codex-dir <path>] [--merge|--overwrite]
|
|
250
|
-
```
|
|
251
|
-
|
|
252
|
-
示例:
|
|
57
|
+
Use `migrate` only when you already have Codex runtime state that should be adopted into managed `providers.json` state.
|
|
253
58
|
|
|
254
59
|
```bash
|
|
60
|
+
codexs init
|
|
255
61
|
codexs migrate
|
|
256
|
-
codexs migrate --overwrite --json
|
|
257
|
-
codexs migrate --merge --codex-dir ./.tmp-codex
|
|
258
62
|
```
|
|
259
63
|
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
- 读取 `config.toml` 中已有 profile
|
|
263
|
-
- 仅 adopt 已具备 `model`、`model_provider` 且能解析到匹配 `model_providers.*.base_url` 的 unmanaged profile
|
|
264
|
-
- 收集每个 profile 对应的 provider 记录
|
|
265
|
-
- 保持现有受管备份、锁和 post-run `doctor` 流程,不重写 `auth.json`
|
|
64
|
+
`migrate` is an advanced adopt helper. It is not the default first step for fresh installs.
|
|
266
65
|
|
|
267
|
-
|
|
66
|
+
Current behavior:
|
|
268
67
|
|
|
269
|
-
-
|
|
270
|
-
-
|
|
68
|
+
- It reads `config.toml` profiles from the target Codex runtime.
|
|
69
|
+
- It can collect missing provider details in TTY mode.
|
|
70
|
+
- It can merge into or overwrite existing managed provider state.
|
|
71
|
+
- It still fails fast in non-TTY and `--json` runs when interactive input would be required.
|
|
271
72
|
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
- `providers.json` 已存在时,必须显式传入 `--merge` 或 `--overwrite`
|
|
275
|
-
- `--json` 模式下不会进入任何引导式输入
|
|
276
|
-
- 由于 adopt profile 选择和 provider secret 收集仍然是交互契约,当前版本会直接失败
|
|
277
|
-
|
|
278
|
-
### 5.3 `setup`
|
|
279
|
-
|
|
280
|
-
`setup` 已弃用,不再执行实际初始化或迁移工作。
|
|
73
|
+
## 4. Deprecated Entry
|
|
281
74
|
|
|
282
75
|
```bash
|
|
283
76
|
codexs setup
|
|
284
77
|
```
|
|
285
78
|
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
- 该命令现在返回 `COMMAND_DEPRECATED`
|
|
289
|
-
- 错误详情中包含 `replacements: ["init", "migrate"]`
|
|
290
|
-
- 应改用 `codexs init` 或 `codexs migrate`
|
|
291
|
-
|
|
292
|
-
### 5.4 `add`
|
|
293
|
-
|
|
294
|
-
新增一个 provider。`add` 当前同时支持 direct provider 和 Copilot bridge provider 两条路径。
|
|
295
|
-
|
|
296
|
-
```bash
|
|
297
|
-
codexs add <provider> --profile <name> --api-key <key> [--base-url <url>] [--note <text>] [--tag <tag> ...]
|
|
298
|
-
codexs add <provider> --copilot --profile <name> [--bridge-host <host>] [--bridge-port <port>] [--bridge-api-key <secret>] [--install-copilot-sdk]
|
|
299
|
-
codexs add
|
|
300
|
-
```
|
|
301
|
-
|
|
302
|
-
direct provider 示例:
|
|
79
|
+
`setup` is deprecated. It is kept only to direct callers toward `init` or `migrate`, and it no longer performs initialization or migration work.
|
|
303
80
|
|
|
304
|
-
|
|
305
|
-
codexs add packycode --profile packycode --api-key sk-xxx
|
|
306
|
-
codexs add packycode --profile packycode --api-key sk-xxx --tag paid --tag daily
|
|
307
|
-
codexs add
|
|
308
|
-
```
|
|
81
|
+
## 5. Global Contract
|
|
309
82
|
|
|
310
|
-
|
|
83
|
+
### 5.1 Global Flags
|
|
311
84
|
|
|
312
85
|
```bash
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
direct provider 字段说明:
|
|
318
|
-
|
|
319
|
-
- `provider`:provider 名称,也是后续 `switch/show/edit/remove` 的标识
|
|
320
|
-
- `--profile`:写入到 `config.toml` 的 profile 名称
|
|
321
|
-
- `--api-key`:provider API key
|
|
322
|
-
- `--base-url`:可选的 provider 元数据,不会写回 `[profiles.*]`
|
|
323
|
-
- `--note`:备注
|
|
324
|
-
- `--tag`:标签,可重复传多次
|
|
325
|
-
|
|
326
|
-
Copilot provider 字段说明:
|
|
327
|
-
|
|
328
|
-
- `--copilot`:切换到 Copilot provider 模式
|
|
329
|
-
- `--profile`:必填
|
|
330
|
-
- `--api-key`:在 `--copilot` 下禁止使用;Copilot 不接收 direct provider API key
|
|
331
|
-
- `--bridge-host`:本地 bridge host,默认 `127.0.0.1`
|
|
332
|
-
- `--bridge-port`:本地 bridge port,默认 `41415`
|
|
333
|
-
- `--bridge-api-key`:本地 bridge shared secret;留空时自动生成
|
|
334
|
-
- `--install-copilot-sdk`:允许在首次接入时安装可选 Copilot SDK runtime
|
|
335
|
-
|
|
336
|
-
交互模式:
|
|
337
|
-
|
|
338
|
-
- direct provider 缺少 `provider`、`profile`、`apiKey` 时,会在 TTY 中补问
|
|
339
|
-
- direct provider 的 API key 隐藏输入会做二次确认
|
|
340
|
-
- Copilot provider 会先做固定 preflight:检查 SDK、必要时立即安装、检查 GitHub Copilot 登录态、必要时执行官方 `copilot login`,全部通过后才进入专用输入流
|
|
341
|
-
- Copilot provider 的专用输入流只采集 provider/profile/model、note/tags 和 bridge 参数
|
|
342
|
-
- Copilot provider 不会提示 `API key`、`Confirm API key` 或输出 `API key is required.`
|
|
343
|
-
- 若官方 `copilot login` 无法启动,会回退为人工提示:运行 `copilot login`,完成 GitHub 官方 device/browser 流程后执行一次明确 recheck
|
|
344
|
-
- `add --copilot --json` 永远不会启动登录流程;若 auth 未就绪,直接返回 `COPILOT_AUTH_REQUIRED`,并提示手动运行 `copilot login`
|
|
345
|
-
|
|
346
|
-
非交互模式:
|
|
347
|
-
|
|
348
|
-
- direct provider 必须显式传入所有必填字段
|
|
349
|
-
- `add --copilot` 必须显式传入 `<provider>` 和 `--profile`
|
|
350
|
-
- `add --copilot --json` 不会进入任何 prompt;若 SDK 缺失且未传 `--install-copilot-sdk`,直接失败;若 auth 未就绪,也直接返回 `COPILOT_AUTH_REQUIRED`
|
|
351
|
-
|
|
352
|
-
### 5.5 `edit`
|
|
353
|
-
|
|
354
|
-
编辑单个 provider 的字段。
|
|
355
|
-
|
|
356
|
-
```bash
|
|
357
|
-
codexs edit <provider> [--profile <name>] [--api-key <key>] [--base-url <url>] [--note <text>] [--tag <tag> ...] [--json] [--codex-dir <path>]
|
|
358
|
-
```
|
|
359
|
-
|
|
360
|
-
示例:
|
|
361
|
-
|
|
362
|
-
```bash
|
|
363
|
-
codexs edit packycode --note primary
|
|
364
|
-
codexs edit packycode --api-key sk-new --base-url https://example.com/v1
|
|
365
|
-
codexs edit packycode --tag daily --tag paid
|
|
366
|
-
```
|
|
367
|
-
|
|
368
|
-
行为说明:
|
|
369
|
-
|
|
370
|
-
- 只会更新你显式传入的字段
|
|
371
|
-
- 未传入的字段保持不变
|
|
372
|
-
- `--tag` 会替换整组标签,而不是追加单个 tag
|
|
373
|
-
- 写入前会备份 `providers.json`
|
|
374
|
-
|
|
375
|
-
交互模式:
|
|
376
|
-
|
|
377
|
-
- 如果没有传任何可编辑字段,TTY 下会进入交互编辑
|
|
378
|
-
|
|
379
|
-
非交互模式:
|
|
380
|
-
|
|
381
|
-
- 至少要提供一个需要修改的字段
|
|
382
|
-
|
|
383
|
-
### 5.6 `switch`
|
|
384
|
-
|
|
385
|
-
切换当前使用的 provider/profile。
|
|
386
|
-
|
|
387
|
-
```bash
|
|
388
|
-
codexs switch <provider> [--json] [--codex-dir <path>]
|
|
389
|
-
```
|
|
390
|
-
|
|
391
|
-
示例:
|
|
392
|
-
|
|
393
|
-
```bash
|
|
394
|
-
codexs switch freemodel
|
|
395
|
-
codexs switch freemodel --json
|
|
396
|
-
codexs switch
|
|
397
|
-
```
|
|
398
|
-
|
|
399
|
-
行为说明:
|
|
400
|
-
|
|
401
|
-
- 根据 `providers.json` 找到目标 provider
|
|
402
|
-
- 更新相关运行态配置
|
|
403
|
-
- direct provider 会切换当前 active profile,并将 `auth.json` 重写为 `auth_mode = "apikey"` 和 `OPENAI_API_KEY = <provider.apiKey>`
|
|
404
|
-
- Copilot bridge provider 不写 `OPENAI_API_KEY`,而是维护本地 bridge 路由
|
|
405
|
-
- 备份 `config.toml`,并在 direct provider 切换时一并备份 `auth.json`
|
|
406
|
-
|
|
407
|
-
交互模式:
|
|
408
|
-
|
|
409
|
-
- 如果没有传 `<provider>`,TTY 下会弹出 provider 选择器
|
|
410
|
-
- 如果已经传了 `<provider>`,则直接执行,不再额外确认
|
|
411
|
-
|
|
412
|
-
### 5.7 `remove`
|
|
413
|
-
|
|
414
|
-
删除一个 provider 记录。
|
|
415
|
-
|
|
416
|
-
```bash
|
|
417
|
-
codexs remove <provider> [--force] [--json] [--codex-dir <path>]
|
|
418
|
-
```
|
|
419
|
-
|
|
420
|
-
示例:
|
|
421
|
-
|
|
422
|
-
```bash
|
|
423
|
-
codexs remove freemodel
|
|
424
|
-
codexs remove freemodel --force --json
|
|
425
|
-
```
|
|
426
|
-
|
|
427
|
-
行为说明:
|
|
428
|
-
|
|
429
|
-
- 删除的是 `providers.json` 中的记录
|
|
430
|
-
- 删除前会备份 `providers.json`
|
|
431
|
-
|
|
432
|
-
交互模式:
|
|
433
|
-
|
|
434
|
-
- 如果没传 provider,可以在 TTY 中选择
|
|
435
|
-
- 无论是否显式传入 provider,交互模式下都会要求确认删除
|
|
436
|
-
|
|
437
|
-
非交互模式:
|
|
438
|
-
|
|
439
|
-
- 必须同时传入 `<provider>` 和 `--force`
|
|
440
|
-
|
|
441
|
-
### 5.8 `import`
|
|
442
|
-
|
|
443
|
-
从外部 JSON 文件导入 provider 配置。
|
|
444
|
-
|
|
445
|
-
```bash
|
|
446
|
-
codexs import <file> [--merge] [--json] [--codex-dir <path>]
|
|
86
|
+
--json
|
|
87
|
+
--codex-dir <path>
|
|
88
|
+
--help
|
|
89
|
+
--version
|
|
447
90
|
```
|
|
448
91
|
|
|
449
|
-
|
|
92
|
+
### 5.2 Environment Variables
|
|
450
93
|
|
|
451
94
|
```bash
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
codexs import ./providers.json --merge --json
|
|
95
|
+
CODEXS_HOME
|
|
96
|
+
CODEXS_CODEX_DIR
|
|
455
97
|
```
|
|
456
98
|
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
- 默认会用导入文件替换当前 `providers.json`
|
|
460
|
-
- 加上 `--merge` 后,会按 provider 名称做浅合并
|
|
461
|
-
- 冲突时,以导入文件中的 provider 记录为准
|
|
462
|
-
|
|
463
|
-
交互模式:
|
|
464
|
-
|
|
465
|
-
- 会在写入前确认是替换还是合并结果
|
|
99
|
+
### 5.3 Runtime Model
|
|
466
100
|
|
|
467
|
-
|
|
101
|
+
Tool home:
|
|
468
102
|
|
|
469
|
-
|
|
470
|
-
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
```bash
|
|
477
|
-
codexs export <file> [--force] [--json] [--codex-dir <path>]
|
|
103
|
+
```text
|
|
104
|
+
~/.config/codex-switch/
|
|
105
|
+
codex-switch.json
|
|
106
|
+
providers.json
|
|
107
|
+
backups/
|
|
108
|
+
runtime/
|
|
109
|
+
runtimes/
|
|
478
110
|
```
|
|
479
111
|
|
|
480
|
-
|
|
112
|
+
Target Codex runtime:
|
|
481
113
|
|
|
482
|
-
```
|
|
483
|
-
|
|
484
|
-
|
|
114
|
+
```text
|
|
115
|
+
~/.codex/
|
|
116
|
+
config.toml
|
|
117
|
+
auth.json
|
|
485
118
|
```
|
|
486
119
|
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
- 将当前受管理 provider 注册表导出为外部 JSON 文件
|
|
120
|
+
Meaning:
|
|
490
121
|
|
|
491
|
-
|
|
122
|
+
- `providers.json` is the managed provider registry.
|
|
123
|
+
- `codex-switch.json` stores tool-level metadata such as `defaultCodexDir`.
|
|
124
|
+
- `config.toml` remains the active runtime routing file.
|
|
125
|
+
- `auth.json` remains the active auth projection file.
|
|
492
126
|
|
|
493
|
-
|
|
494
|
-
- 如果目标文件已存在,交互模式下会询问是否覆盖
|
|
495
|
-
- 非交互模式下必须显式传 `--force`
|
|
127
|
+
## 6. Command Categories
|
|
496
128
|
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
### 6.1 `doctor`
|
|
500
|
-
|
|
501
|
-
运行本地配置与环境诊断。
|
|
502
|
-
|
|
503
|
-
```bash
|
|
504
|
-
codexs doctor [--json] [--codex-dir <path>]
|
|
505
|
-
```
|
|
506
|
-
|
|
507
|
-
示例:
|
|
129
|
+
Read commands:
|
|
508
130
|
|
|
509
131
|
```bash
|
|
132
|
+
codexs list
|
|
133
|
+
codexs show <provider>
|
|
134
|
+
codexs current
|
|
135
|
+
codexs status
|
|
136
|
+
codexs config show [profile]
|
|
137
|
+
codexs config list-profiles
|
|
138
|
+
codexs bridge status [provider]
|
|
139
|
+
codexs backups list
|
|
510
140
|
codexs doctor
|
|
511
|
-
codexs doctor --json
|
|
512
|
-
```
|
|
513
|
-
|
|
514
|
-
通常会检查:
|
|
515
|
-
|
|
516
|
-
- 必要文件是否存在
|
|
517
|
-
- provider/profile 映射是否一致
|
|
518
|
-
- 当前运行态是否有漂移
|
|
519
|
-
- Codex CLI 是否可用
|
|
520
|
-
|
|
521
|
-
### 6.2 `rollback`
|
|
522
|
-
|
|
523
|
-
回滚到最近一次备份,或者指定备份 ID。
|
|
524
|
-
|
|
525
|
-
```bash
|
|
526
|
-
codexs rollback [<backup-id>] [--json] [--codex-dir <path>]
|
|
527
|
-
```
|
|
528
|
-
|
|
529
|
-
示例:
|
|
530
|
-
|
|
531
|
-
```bash
|
|
532
|
-
codexs rollback
|
|
533
|
-
codexs rollback 20260511-221457-switch
|
|
534
|
-
codexs rollback 20260511-221457-switch --json
|
|
535
|
-
```
|
|
536
|
-
|
|
537
|
-
行为说明:
|
|
538
|
-
|
|
539
|
-
- 不带参数时,默认回滚最近一次受管备份
|
|
540
|
-
- 传入 `<backup-id>` 时,回滚到指定备份
|
|
541
|
-
|
|
542
|
-
交互模式:
|
|
543
|
-
|
|
544
|
-
- 会先展示目标备份和受影响文件,再要求确认
|
|
545
|
-
|
|
546
|
-
非交互模式:
|
|
547
|
-
|
|
548
|
-
- 直接执行,不会二次确认
|
|
549
|
-
|
|
550
|
-
## 7. JSON 输出与自动化建议
|
|
551
|
-
|
|
552
|
-
如果你是在脚本、CI 或 Agent 环境中调用,建议遵循以下约束:
|
|
553
|
-
|
|
554
|
-
```bash
|
|
555
|
-
codexs <command> --json
|
|
556
141
|
```
|
|
557
142
|
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
- 始终显式传入必需参数,不依赖交互输入
|
|
561
|
-
- 使用 `--json` 获取稳定输出
|
|
562
|
-
- 对危险命令显式传入控制参数,例如 `--force`、`--merge`、`--overwrite`
|
|
563
|
-
- 对多环境调试使用 `--codex-dir <path>`,避免误改默认 `~/.codex`
|
|
564
|
-
|
|
565
|
-
适合自动化的例子:
|
|
566
|
-
|
|
567
|
-
```bash
|
|
568
|
-
codexs list --json
|
|
569
|
-
codexs show packycode --json
|
|
570
|
-
codexs switch packycode --json
|
|
571
|
-
codexs export ./providers.snapshot.json --force --json
|
|
572
|
-
codexs rollback 20260511-221457-switch --json
|
|
573
|
-
```
|
|
574
|
-
|
|
575
|
-
## 8. 典型使用流程
|
|
576
|
-
|
|
577
|
-
### 8.1 第一次接管现有 Codex 配置
|
|
143
|
+
Change commands:
|
|
578
144
|
|
|
579
145
|
```bash
|
|
580
146
|
codexs init
|
|
147
|
+
codexs login copilot
|
|
581
148
|
codexs migrate
|
|
582
|
-
codexs
|
|
583
|
-
codexs
|
|
149
|
+
codexs add <provider>
|
|
150
|
+
codexs edit <provider>
|
|
151
|
+
codexs switch <provider>
|
|
152
|
+
codexs remove <provider>
|
|
153
|
+
codexs import <file>
|
|
154
|
+
codexs export <file>
|
|
155
|
+
codexs bridge start [provider]
|
|
156
|
+
codexs bridge stop [provider]
|
|
157
|
+
codexs rollback [backup-id]
|
|
584
158
|
```
|
|
585
159
|
|
|
586
|
-
|
|
160
|
+
## 7. Selected Command Semantics
|
|
587
161
|
|
|
588
|
-
|
|
589
|
-
codexs add my-provider --profile my-provider --api-key sk-xxx
|
|
590
|
-
codexs switch my-provider
|
|
591
|
-
codexs current
|
|
592
|
-
```
|
|
162
|
+
### `init`
|
|
593
163
|
|
|
594
|
-
|
|
164
|
+
- Creates `codex-switch.json` and `providers.json` under the tool home when they do not exist yet.
|
|
165
|
+
- Does not create or validate `config.toml`, `auth.json`, or the target Codex directory.
|
|
166
|
+
- When `--codex-dir` is passed explicitly during first-time initialization, it can persist `defaultCodexDir`.
|
|
595
167
|
|
|
596
|
-
|
|
597
|
-
codexs export ./providers.backup.json
|
|
598
|
-
codexs import ./team.providers.json --merge
|
|
599
|
-
codexs doctor
|
|
600
|
-
```
|
|
168
|
+
### `login copilot`
|
|
601
169
|
|
|
602
|
-
|
|
170
|
+
- Supports `copilot` and `github-copilot` as the current upstream name.
|
|
171
|
+
- Installs the local Copilot SDK under the tool home when needed.
|
|
172
|
+
- Invokes the official Copilot CLI for login when readiness is not already present.
|
|
173
|
+
- Requires a real TTY and does not support `--json`.
|
|
603
174
|
|
|
604
|
-
|
|
605
|
-
codexs backups list
|
|
606
|
-
codexs rollback
|
|
607
|
-
```
|
|
175
|
+
### `status`
|
|
608
176
|
|
|
609
|
-
|
|
177
|
+
- Reports the target Codex runtime and the tool-home root.
|
|
178
|
+
- Reports the current profile and whether it maps to a managed provider.
|
|
179
|
+
- Adds bridge, Copilot SDK, and upstream auth signals when the active provider uses a local runtime bridge.
|
|
180
|
+
- Does not mutate any files.
|
|
610
181
|
|
|
611
|
-
|
|
612
|
-
codexs rollback <backup-id>
|
|
613
|
-
```
|
|
182
|
+
### `list`
|
|
614
183
|
|
|
615
|
-
|
|
184
|
+
- Lists managed providers together with their linked profile.
|
|
185
|
+
- Distinguishes provider type using the public values `direct` and `copilot`.
|
|
186
|
+
- Marks the current provider only when the active runtime can be mapped back to one unique managed provider.
|
|
187
|
+
- When the active profile is shared by multiple providers, it does not invent a single current provider and should instead surface the ambiguity.
|
|
188
|
+
- TTY provider pickers used by commands such as `switch` and `show` follow the same visibility rules for profile, provider type, and current-state hints.
|
|
616
189
|
|
|
617
|
-
|
|
190
|
+
### `doctor`
|
|
618
191
|
|
|
619
|
-
-
|
|
620
|
-
-
|
|
621
|
-
-
|
|
622
|
-
- `edit`
|
|
623
|
-
- `switch`
|
|
624
|
-
- `remove`
|
|
625
|
-
- `import`
|
|
626
|
-
- `export`(目标文件已存在时)
|
|
627
|
-
- `rollback`
|
|
192
|
+
- Checks expected config files, provider/profile consistency, and Codex CLI availability.
|
|
193
|
+
- Adds bridge and Copilot dependency diagnostics for Copilot-backed providers.
|
|
194
|
+
- Returns repair-oriented issues intended for both human users and AI agents.
|
|
628
195
|
|
|
629
|
-
|
|
196
|
+
### `switch`
|
|
630
197
|
|
|
631
|
-
-
|
|
632
|
-
-
|
|
633
|
-
-
|
|
198
|
+
- Direct providers rewrite `auth.json` as an API-key projection and update the active runtime profile.
|
|
199
|
+
- Copilot bridge providers also project the local bridge secret into the runtime while managing bridge routing.
|
|
200
|
+
- Managed writes are backed up and rolled back on failure.
|
|
201
|
+
- When `<provider>` is omitted in a TTY, the interactive provider selector should show profile, provider type, and current-state hints using the same rules as `list`.
|
|
634
202
|
|
|
635
|
-
|
|
203
|
+
### `migrate`
|
|
636
204
|
|
|
637
|
-
|
|
205
|
+
- Adopts unmanaged runtime profiles into managed `providers.json` state.
|
|
206
|
+
- Still relies on interactive profile selection and provider-detail collection in this release.
|
|
207
|
+
- Should be treated as an advanced adopt tool, not as the normal onboarding path.
|
|
638
208
|
|
|
639
|
-
|
|
640
|
-
codexs --help
|
|
641
|
-
```
|
|
209
|
+
## 8. Automation Boundaries
|
|
642
210
|
|
|
643
|
-
|
|
211
|
+
- Progressive prompts run only in a real TTY and never under `--json`.
|
|
212
|
+
- Human write commands may prompt for missing inputs or dangerous-action confirmation.
|
|
213
|
+
- Automation should pass explicit arguments and prefer `--json`.
|
|
214
|
+
- `login copilot` is TTY-only.
|
|
215
|
+
- `migrate` is not yet a complete non-interactive workflow.
|
|
644
216
|
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
codexs help rollback
|
|
653
|
-
```
|
|
217
|
+
## 9. Related Docs
|
|
218
|
+
|
|
219
|
+
- [README](../README.md)
|
|
220
|
+
- [Chinese README](../README.CN.md)
|
|
221
|
+
- [AI README](../README.AI.md)
|
|
222
|
+
- [Product Overview](./codex-switch-product-overview.md)
|
|
223
|
+
- [PRD 0.0.12](./PRD/codex-switch-prd-v0.0.12.md)
|