@minniexcode/codex-switch 0.1.0 → 0.1.2

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.
Files changed (68) hide show
  1. package/README.AI.md +141 -110
  2. package/README.CN.md +215 -179
  3. package/README.md +224 -183
  4. package/dist/app/add-provider.js +16 -23
  5. package/dist/app/bridge.js +2 -1
  6. package/dist/app/edit-provider.js +30 -65
  7. package/dist/app/get-current-profile.js +15 -3
  8. package/dist/app/get-status.js +11 -8
  9. package/dist/app/list-config-profiles.js +3 -1
  10. package/dist/app/list-providers.js +10 -4
  11. package/dist/app/remove-provider.js +52 -19
  12. package/dist/app/run-doctor.js +26 -29
  13. package/dist/app/setup-codex.js +3 -3
  14. package/dist/app/show-config.js +3 -1
  15. package/dist/app/switch-provider.js +38 -6
  16. package/dist/cli/output.js +29 -19
  17. package/dist/commands/handlers.js +3 -2
  18. package/dist/commands/help.js +3 -3
  19. package/dist/commands/registry.js +29 -29
  20. package/dist/domain/config.js +293 -209
  21. package/dist/domain/providers.js +8 -0
  22. package/dist/domain/runtime-state.js +15 -15
  23. package/dist/domain/setup.js +3 -1
  24. package/dist/interaction/interactive.js +2 -2
  25. package/dist/runtime/codex-version.js +7 -0
  26. package/dist/runtime/copilot-adapter.js +326 -70
  27. package/dist/runtime/copilot-bridge-worker.js +27 -2
  28. package/dist/runtime/copilot-bridge.js +192 -10
  29. package/dist/runtime/copilot-cli.js +7 -0
  30. package/dist/runtime/copilot-installer.js +59 -1
  31. package/dist/runtime/copilot-sdk-loader.js +4 -1
  32. package/dist/storage/config-repo.js +6 -14
  33. package/docs/Design/codex-switch-v0.1.0-design.md +32 -152
  34. package/docs/Design/codex-switch-v0.1.1-design.md +22 -0
  35. package/docs/Design/codex-switch-v0.1.2-design.md +65 -0
  36. package/docs/PRD/codex-switch-prd-v0.1.0.md +65 -217
  37. package/docs/PRD/codex-switch-prd-v0.1.1.md +26 -0
  38. package/docs/PRD/codex-switch-prd-v0.1.2.md +41 -0
  39. package/docs/Reference/codex-config-reference.md +41 -0
  40. package/docs/Reference/codex-config-reference.zh-CN.md +41 -0
  41. package/docs/Tests/testing.md +1 -1
  42. package/docs/cli-usage.md +290 -223
  43. package/docs/codex-switch-command-design.md +2 -2
  44. package/docs/codex-switch-product-overview.md +18 -13
  45. package/docs/codex-switch-product-research.md +2 -2
  46. package/docs/codex-switch-technical-architecture.md +84 -1115
  47. package/package.json +2 -2
  48. package/docs/Design/codex-switch-copilot-integration-design.md +0 -517
  49. package/docs/Design/codex-switch-v0.0.10-design.md +0 -669
  50. package/docs/Design/codex-switch-v0.0.11-design.md +0 -824
  51. package/docs/Design/codex-switch-v0.0.12-design.md +0 -343
  52. package/docs/Design/codex-switch-v0.0.4-design.md +0 -874
  53. package/docs/Design/codex-switch-v0.0.5-design.md +0 -932
  54. package/docs/Design/codex-switch-v0.0.6-design.md +0 -708
  55. package/docs/Design/codex-switch-v0.0.7-design.md +0 -862
  56. package/docs/Design/codex-switch-v0.0.8-design.md +0 -132
  57. package/docs/Design/codex-switch-v0.0.9-design.md +0 -182
  58. package/docs/Design/codex-switch-v0.0.9-to-v0.0.12-roadmap.md +0 -413
  59. package/docs/PRD/codex-switch-prd-v0.0.10.md +0 -406
  60. package/docs/PRD/codex-switch-prd-v0.0.11.md +0 -577
  61. package/docs/PRD/codex-switch-prd-v0.0.12.md +0 -279
  62. package/docs/PRD/codex-switch-prd-v0.0.5-to-v0.1.0.md +0 -446
  63. package/docs/PRD/codex-switch-prd-v0.0.8.md +0 -62
  64. package/docs/PRD/codex-switch-prd-v0.0.9.md +0 -166
  65. package/docs/PRD/codex-switch-prd.md +0 -650
  66. package/docs/Tests/test-report-0.0.5.md +0 -163
  67. package/docs/Tests/test-report-0.0.7.md +0 -118
  68. package/docs/Tests/testing-bridge-v0.0.9.md +0 -367
@@ -137,6 +137,12 @@ model_reasoning_effort = "high"
137
137
  approval_policy = "never"
138
138
  ```
139
139
 
140
+ Important `codex-switch` note:
141
+
142
+ - official Codex still supports profiles
143
+ - `codex-switch` `0.1.1` does not treat top-level `profile` as the recommended managed runtime selector
144
+ - in `codex-switch`, legacy `profile` and `[profiles.*]` are mainly inspect-and-adopt inputs for `migrate`, `doctor`, and `config` inspection flows
145
+
140
146
  ## 4. `config.toml` by topic
141
147
 
142
148
  ### 4.1 Model, reasoning, and response style
@@ -194,6 +200,8 @@ Core keys:
194
200
  - `model_providers.<id>.env_http_headers`
195
201
  - `model_providers.<id>.query_params`
196
202
  - `model_providers.<id>.request_max_retries`
203
+ - `model_providers.<id>.wire_api`
204
+ - `model_providers.<id>.requires_openai_auth`
197
205
 
198
206
  Authentication options for custom providers include:
199
207
 
@@ -214,6 +222,22 @@ Related Bedrock keys:
214
222
  - `model_providers.amazon-bedrock.aws.profile`
215
223
  - `model_providers.amazon-bedrock.aws.region`
216
224
 
225
+ #### `codex-switch` 0.1.1 managed projection
226
+
227
+ When `codex-switch` manages a direct OpenAI-compatible route for Codex `0.134.0+`, it intentionally projects a narrower runtime shape than the full official provider schema:
228
+
229
+ - top-level `model` is the active model selector
230
+ - top-level `model_provider` is the active route selector
231
+ - projected `[model_providers.<id>]` keeps `base_url`
232
+ - projected `[model_providers.<id>]` fixes `wire_api = "responses"`
233
+ - projected `[model_providers.<id>]` fixes `requires_openai_auth = true`
234
+ - projected runtime config does not keep `env_key`
235
+ - projected runtime config does not keep `env_key_instructions`
236
+
237
+ Authentication is projected through `auth.json` with `OPENAI_API_KEY`, not through `env_key` in the managed runtime config.
238
+
239
+ That is a `codex-switch` product decision, not a limitation of Codex itself. If you hand-write or independently manage Codex config, `env_key` remains a valid official mechanism.
240
+
217
241
  ### 4.3.1 `openai_base_url` vs custom providers
218
242
 
219
243
  If you only want to point the built-in OpenAI provider to a proxy, router, or residency-specific endpoint, use:
@@ -539,6 +563,23 @@ env_key = "OPENAI_API_KEY"
539
563
  http_headers = { "X-Team" = "platform" }
540
564
  ```
541
565
 
566
+ This is an official Codex-style custom provider example.
567
+
568
+ If you are using `codex-switch` managed direct-provider projection instead, the runtime projection is intentionally narrower:
569
+
570
+ ```toml
571
+ model = "gpt-5.4"
572
+ model_provider = "proxy"
573
+
574
+ [model_providers.proxy]
575
+ name = "proxy"
576
+ base_url = "https://proxy.example.com/v1"
577
+ wire_api = "responses"
578
+ requires_openai_auth = true
579
+ ```
580
+
581
+ In that managed projection, `OPENAI_API_KEY` is expected in `auth.json` rather than through `env_key` in `config.toml`.
582
+
542
583
  ### 6.4 Locked-down shell environment
543
584
 
544
585
  ```toml
@@ -149,6 +149,12 @@ model_reasoning_effort = "high"
149
149
  approval_policy = "never"
150
150
  ```
151
151
 
152
+ 对 `codex-switch` 0.1.1 的补充说明:
153
+
154
+ - 官方 Codex 仍然支持 profiles
155
+ - `codex-switch` 不再把顶层 `profile` 视为推荐的受管 runtime selector
156
+ - 在 `codex-switch` 里,legacy `profile` 和 `[profiles.*]` 主要用于 `migrate`、`doctor` 和 `config` 检视的 adopt / inspect 场景
157
+
152
158
  ## 4. `config.toml` 主题整理
153
159
 
154
160
  ### 4.1 模型、推理强度与输出风格
@@ -206,6 +212,8 @@ Codex 把“当前使用哪个 provider”和“provider 怎么定义”拆开
206
212
  - `model_providers.<id>.env_http_headers`
207
213
  - `model_providers.<id>.query_params`
208
214
  - `model_providers.<id>.request_max_retries`
215
+ - `model_providers.<id>.wire_api`
216
+ - `model_providers.<id>.requires_openai_auth`
209
217
 
210
218
  自定义 provider 的认证方式包括:
211
219
 
@@ -229,6 +237,22 @@ Bedrock 相关 key:
229
237
  - `model_providers.amazon-bedrock.aws.profile`
230
238
  - `model_providers.amazon-bedrock.aws.region`
231
239
 
240
+ #### `codex-switch` 0.1.1 的受管投影
241
+
242
+ 当 `codex-switch` 为 Codex `0.134.0+` 管理一个 direct OpenAI-compatible route 时,它会有意把运行态投影限制在一组更窄的字段上:
243
+
244
+ - 顶层 `model` 是活动模型选择器
245
+ - 顶层 `model_provider` 是活动路由选择器
246
+ - 投影后的 `[model_providers.<id>]` 保留 `base_url`
247
+ - 投影后的 `[model_providers.<id>]` 固定写 `wire_api = "responses"`
248
+ - 投影后的 `[model_providers.<id>]` 固定写 `requires_openai_auth = true`
249
+ - 受管运行态投影不会保留 `env_key`
250
+ - 受管运行态投影不会保留 `env_key_instructions`
251
+
252
+ 认证信息会通过 `auth.json` 里的 `OPENAI_API_KEY` 投影,而不是通过运行态 `config.toml` 中的 `env_key`。
253
+
254
+ 这属于 `codex-switch` 的产品约束,不是 Codex 官方能力限制。如果你是手工维护或独立维护 Codex config,`env_key` 仍然是官方支持的方式。
255
+
232
256
  ### 4.3.1 `openai_base_url` 和自定义 provider 的区别
233
257
 
234
258
  如果你只是想把内置 `openai` provider 指向公司网关、路由层或者某个数据驻留 endpoint,官方建议直接用:
@@ -568,6 +592,23 @@ env_key = "OPENAI_API_KEY"
568
592
  http_headers = { "X-Team" = "platform" }
569
593
  ```
570
594
 
595
+ 这段是官方 Codex 风格的自定义 provider 示例。
596
+
597
+ 如果你走的是 `codex-switch` 的受管 direct-provider 投影,运行态会被有意收窄为:
598
+
599
+ ```toml
600
+ model = "gpt-5.4"
601
+ model_provider = "proxy"
602
+
603
+ [model_providers.proxy]
604
+ name = "proxy"
605
+ base_url = "https://proxy.example.com/v1"
606
+ wire_api = "responses"
607
+ requires_openai_auth = true
608
+ ```
609
+
610
+ 在这种受管投影下,`OPENAI_API_KEY` 预期写在 `auth.json`,而不是通过 `config.toml` 里的 `env_key` 暴露。
611
+
571
612
  ### 6.4 最小暴露的 shell 环境策略
572
613
 
573
614
  ```toml
@@ -1,6 +1,6 @@
1
1
  # codex-switch Testing Guide
2
2
 
3
- This guide records the release gate for `0.1.0`.
3
+ This guide records the current `0.1.x` verification contract for release and review work.
4
4
 
5
5
  ## Required checks
6
6
 
package/docs/cli-usage.md CHANGED
@@ -1,223 +1,290 @@
1
- # codex-switch CLI Usage
2
-
3
- This document describes the current CLI contract for `@minniexcode/codex-switch` at version `0.1.0`.
4
-
5
- Executable command name:
6
-
7
- ```bash
8
- codexs
9
- ```
10
-
11
- ## 1. Version Context
12
-
13
- The current package version in this repository is `0.1.0`.
14
-
15
- This is the first stable release line. The command surface already exists, and this version focuses on keeping workflow guidance, help text, and implementation behavior aligned.
16
-
17
- ## 2. Primary Workflows
18
-
19
- ### 2.1 Direct Providers
20
-
21
- ```bash
22
- codexs init
23
- codexs add <provider> --profile <name> --api-key <key>
24
- codexs switch <provider>
25
- codexs status
26
- codexs doctor
27
- ```
28
-
29
- Intent:
30
-
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.
36
-
37
- ### 2.2 GitHub Copilot
38
-
39
- ```bash
40
- codexs init
41
- codexs login copilot
42
- codexs add <provider> --copilot --profile <name>
43
- codexs switch <provider>
44
- codexs status
45
- codexs doctor
46
- ```
47
-
48
- Important notes:
49
-
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.
54
-
55
- ## 3. Advanced Adopt Workflow
56
-
57
- Use `migrate` only when you already have Codex runtime state that should be adopted into managed `providers.json` state.
58
-
59
- ```bash
60
- codexs init
61
- codexs migrate
62
- ```
63
-
64
- `migrate` is an advanced adopt helper. It is not the default first step for fresh installs.
65
-
66
- Current behavior:
67
-
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.
72
-
73
- ## 4. Deprecated Entry
74
-
75
- ```bash
76
- codexs setup
77
- ```
78
-
79
- `setup` is deprecated. It is kept only to direct callers toward `init` or `migrate`, and it no longer performs initialization or migration work.
80
-
81
- ## 5. Global Contract
82
-
83
- ### 5.1 Global Flags
84
-
85
- ```bash
86
- --json
87
- --codex-dir <path>
88
- --help
89
- --version
90
- ```
91
-
92
- ### 5.2 Environment Variables
93
-
94
- ```bash
95
- CODEXS_HOME
96
- CODEXS_CODEX_DIR
97
- ```
98
-
99
- ### 5.3 Runtime Model
100
-
101
- Tool home:
102
-
103
- ```text
104
- ~/.config/codex-switch/
105
- codex-switch.json
106
- providers.json
107
- backups/
108
- runtime/
109
- runtimes/
110
- ```
111
-
112
- Target Codex runtime:
113
-
114
- ```text
115
- ~/.codex/
116
- config.toml
117
- auth.json
118
- ```
119
-
120
- Meaning:
121
-
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.
126
-
127
- ## 6. Command Categories
128
-
129
- Read commands:
130
-
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
140
- codexs doctor
141
- ```
142
-
143
- Change commands:
144
-
145
- ```bash
146
- codexs init
147
- codexs login copilot
148
- codexs migrate
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]
158
- ```
159
-
160
- ## 7. Selected Command Semantics
161
-
162
- ### `init`
163
-
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`.
167
-
168
- ### `login copilot`
169
-
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`.
174
-
175
- ### `status`
176
-
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.
181
-
182
- ### `list`
183
-
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.
189
-
190
- ### `doctor`
191
-
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.
195
-
196
- ### `switch`
197
-
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`.
202
-
203
- ### `migrate`
204
-
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.
208
-
209
- ## 8. Automation Boundaries
210
-
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.
216
-
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
- - [Release PRD 0.1.0](./PRD/codex-switch-prd-v0.1.0.md)
1
+ # codex-switch CLI Usage
2
+
3
+ This document describes the current `0.1.2` CLI contract for `@minniexcode/codex-switch`, including the Copilot runtime repair boundary.
4
+
5
+ Executable command name:
6
+
7
+ ```bash
8
+ codexs
9
+ ```
10
+
11
+ ## 1. Version Context
12
+
13
+ The current package version in this repository is `0.1.2`.
14
+
15
+ This release line targets Codex `0.134.0+`. The public contract assumes runtime routing is selected by top-level `model` plus `model_provider`, while legacy `profile` and `[profiles.*]` remain inspect-and-adopt inputs instead of the recommended runtime path.
16
+
17
+ ## 2. Primary Workflows
18
+
19
+ ### 2.1 Direct Providers
20
+
21
+ ```bash
22
+ codexs init
23
+ codexs add <provider> --model <model> --api-key <key> [--base-url <url>]
24
+ codexs switch <provider>
25
+ codexs status
26
+ codexs doctor
27
+ ```
28
+
29
+ Intent:
30
+
31
+ - `init` prepares the `codex-switch` tool home.
32
+ - `add` creates a managed provider record with a target model and provider route identity.
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.
36
+
37
+ ### 2.2 GitHub Copilot
38
+
39
+ ```bash
40
+ codexs init
41
+ codexs login copilot
42
+ codexs add <provider> --copilot --model <model>
43
+ codexs switch <provider>
44
+ codexs status
45
+ codexs doctor
46
+ ```
47
+
48
+ Important notes:
49
+
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.
54
+ - Copilot runtime paths require Node.js `>=20`; direct providers remain supported on Node.js `>=18`.
55
+ - The Copilot bridge is experimental and targets simple text-oriented turns through the local OpenAI-compatible bridge.
56
+
57
+ ## 3. Runtime Route Contract
58
+
59
+ For Codex `0.134.0+`, the active runtime route is selected through top-level `model` and `model_provider` in `config.toml`.
60
+
61
+ `codex-switch` writes that route as its primary runtime projection:
62
+
63
+ - top-level `model`
64
+ - top-level `model_provider`
65
+ - `[model_providers.<id>]`
66
+ - `auth.json` when direct auth projection is required
67
+
68
+ Managed provider projection intentionally avoids these legacy fields:
69
+
70
+ - `model_providers.<id>.env_key`
71
+ - `model_providers.<id>.env_key_instructions`
72
+
73
+ Managed provider projection fixes these fields for OpenAI-compatible direct routes:
74
+
75
+ - `wire_api = "responses"`
76
+ - `requires_openai_auth = true`
77
+
78
+ Copilot bridge projection also writes:
79
+
80
+ - `stream_idle_timeout_ms = 300000`
81
+
82
+ Compatibility notes:
83
+
84
+ - `--profile` is accepted as an alias for the managed `model_provider` id.
85
+ - legacy top-level `profile` and `[profiles.*]` may still appear in existing runtime state
86
+ - `migrate`, `config show`, `config list-profiles`, and `doctor` can still inspect those legacy structures
87
+ - new managed runtime projection should be described as route-first, not profile-first
88
+
89
+ Example managed direct-provider projection:
90
+
91
+ ```toml
92
+ model = "gpt-5.5"
93
+ model_provider = "proxy"
94
+
95
+ [model_providers.proxy]
96
+ name = "proxy"
97
+ base_url = "https://proxy.example.com/v1"
98
+ wire_api = "responses"
99
+ requires_openai_auth = true
100
+ ```
101
+
102
+ Authentication projection for the direct path remains:
103
+
104
+ ```json
105
+ {
106
+ "OPENAI_API_KEY": "sk-xxx"
107
+ }
108
+ ```
109
+
110
+ ## 4. Advanced Adopt Workflow
111
+
112
+ Use `migrate` only when you already have Codex runtime state that should be adopted into managed `providers.json` state.
113
+
114
+ ```bash
115
+ codexs init
116
+ codexs migrate
117
+ ```
118
+
119
+ `migrate` is an advanced adopt helper. It is not the default first step for fresh installs.
120
+
121
+ Current behavior:
122
+
123
+ - It can inspect legacy runtime `profile` and `[profiles.*]` state from the target Codex runtime.
124
+ - It can collect missing provider details in TTY mode.
125
+ - It can merge into or overwrite existing managed provider state.
126
+ - It still fails fast in non-TTY and `--json` runs when interactive input would be required.
127
+
128
+ ## 5. Deprecated Entry
129
+
130
+ ```bash
131
+ codexs setup
132
+ ```
133
+
134
+ `setup` is deprecated. It is kept only to direct callers toward `init` or `migrate`, and it no longer performs initialization or migration work.
135
+
136
+ ## 6. Global Contract
137
+
138
+ ### 6.1 Global Flags
139
+
140
+ ```bash
141
+ --json
142
+ --codex-dir <path>
143
+ --help
144
+ --version
145
+ ```
146
+
147
+ ### 6.2 Environment Variables
148
+
149
+ ```bash
150
+ CODEXS_HOME
151
+ CODEXS_CODEX_DIR
152
+ ```
153
+
154
+ ### 6.3 Runtime Model
155
+
156
+ Tool home:
157
+
158
+ ```text
159
+ ~/.config/codex-switch/
160
+ codex-switch.json
161
+ providers.json
162
+ backups/
163
+ runtime/
164
+ runtimes/
165
+ ```
166
+
167
+ Target Codex runtime:
168
+
169
+ ```text
170
+ ~/.codex/
171
+ config.toml
172
+ auth.json
173
+ ```
174
+
175
+ Meaning:
176
+
177
+ - `providers.json` is the managed provider registry.
178
+ - `codex-switch.json` stores tool-level metadata such as `defaultCodexDir`.
179
+ - `config.toml` remains the active runtime routing file.
180
+ - `auth.json` remains the active auth projection file.
181
+
182
+ ## 7. Command Categories
183
+
184
+ Read commands:
185
+
186
+ ```bash
187
+ codexs list
188
+ codexs show <provider>
189
+ codexs current
190
+ codexs status
191
+ codexs config show [profile]
192
+ codexs config list-profiles
193
+ codexs bridge status [provider]
194
+ codexs backups list
195
+ codexs doctor
196
+ ```
197
+
198
+ Change commands:
199
+
200
+ ```bash
201
+ codexs init
202
+ codexs login copilot
203
+ codexs migrate
204
+ codexs add <provider>
205
+ codexs edit <provider>
206
+ codexs switch <provider>
207
+ codexs remove <provider>
208
+ codexs import <file>
209
+ codexs export <file>
210
+ codexs bridge start [provider]
211
+ codexs bridge stop [provider]
212
+ codexs rollback [backup-id]
213
+ ```
214
+
215
+ ## 8. Selected Command Semantics
216
+
217
+ ### `init`
218
+
219
+ - Creates `codex-switch.json` and `providers.json` under the tool home when they do not exist yet.
220
+ - Does not create or validate `config.toml`, `auth.json`, or the target Codex directory.
221
+ - When `--codex-dir` is passed explicitly during first-time initialization, it can persist `defaultCodexDir`.
222
+
223
+ ### `login copilot`
224
+
225
+ - Supports `copilot` and `github-copilot` as the current upstream name.
226
+ - Installs the local Copilot SDK under the tool home when needed.
227
+ - Invokes the official Copilot CLI for login when readiness is not already present.
228
+ - Requires a real TTY and does not support `--json`.
229
+
230
+ ### `status`
231
+
232
+ - Reports the target Codex runtime and the tool-home root.
233
+ - Reports the active model and active `model_provider` route.
234
+ - Can still surface legacy profile-derived observations when inspecting older runtime state.
235
+ - Adds bridge, Copilot SDK, and upstream auth signals when the active provider uses a local runtime bridge.
236
+ - Does not mutate any files.
237
+
238
+ ### `list`
239
+
240
+ - Lists managed providers together with their linked route identity.
241
+ - Distinguishes provider type using the public values `direct` and `copilot`.
242
+ - Marks the current provider only when the active runtime can be mapped back to one unique managed provider.
243
+ - When the active route is shared by multiple providers, it does not invent a single current provider and should instead surface the ambiguity.
244
+ - TTY provider pickers used by commands such as `switch` and `show` follow the same visibility rules for route, provider type, and current-state hints.
245
+
246
+ ### `doctor`
247
+
248
+ - Checks expected config files, managed-provider consistency, and Codex CLI availability.
249
+ - Inspects both route-first runtime state and legacy profile state when needed.
250
+ - Adds bridge and Copilot dependency diagnostics for Copilot-backed providers.
251
+ - Returns repair-oriented issues intended for both human users and AI agents.
252
+
253
+ ### `switch`
254
+
255
+ - Projects direct providers by rewriting top-level `model`, top-level `model_provider`, the managed `[model_providers.<id>]` block, and `auth.json`.
256
+ - Cleans legacy projected `env_key` and `env_key_instructions` fields before writing the managed provider route.
257
+ - Copilot bridge providers also project the local bridge secret into the runtime while managing bridge routing.
258
+ - Managed writes are backed up and rolled back on failure.
259
+ - When `<provider>` is omitted in a TTY, the interactive provider selector should show route, provider type, and current-state hints using the same rules as `list`.
260
+
261
+ ### `add` and `edit`
262
+
263
+ - Create or update managed provider records rather than editing runtime files directly.
264
+ - Treat `--profile` only as an alias for the managed `model_provider` id.
265
+ - Clean old `env_key` and `env_key_instructions` fields from managed projection during subsequent switching.
266
+
267
+ ### `migrate`
268
+
269
+ - Adopts unmanaged runtime route or legacy profile state into managed `providers.json` state.
270
+ - Still relies on interactive route/profile selection and provider-detail collection in this release.
271
+ - Should be treated as an advanced adopt tool, not as the normal onboarding path.
272
+
273
+ ## 9. Automation Boundaries
274
+
275
+ - Progressive prompts run only in a real TTY and never under `--json`.
276
+ - Human write commands may prompt for missing inputs or dangerous-action confirmation.
277
+ - Automation should pass explicit arguments and prefer `--json`.
278
+ - `login copilot` is TTY-only.
279
+ - `migrate` is not yet a complete non-interactive workflow.
280
+
281
+ ## 10. Related Docs
282
+
283
+ - [README](../README.md)
284
+ - [Chinese README](../README.CN.md)
285
+ - [AI README](../README.AI.md)
286
+ - [Product Overview](./codex-switch-product-overview.md)
287
+ - [PRD 0.1.0](./PRD/codex-switch-prd-v0.1.0.md)
288
+ - [PRD 0.1.1](./PRD/codex-switch-prd-v0.1.1.md)
289
+ - [PRD 0.1.2](./PRD/codex-switch-prd-v0.1.2.md)
290
+ - [Design 0.1.2](./Design/codex-switch-v0.1.2-design.md)