@minniexcode/codex-switch 0.1.0 → 0.1.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/docs/cli-usage.md CHANGED
@@ -1,223 +1,282 @@
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 CLI contract for `@minniexcode/codex-switch` at version `0.1.1`.
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.1`.
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
+
55
+ ## 3. Runtime Route Contract
56
+
57
+ For Codex `0.134.0+`, the active runtime route is selected through top-level `model` and `model_provider` in `config.toml`.
58
+
59
+ `codex-switch` writes that route as its primary runtime projection:
60
+
61
+ - top-level `model`
62
+ - top-level `model_provider`
63
+ - `[model_providers.<id>]`
64
+ - `auth.json` when direct auth projection is required
65
+
66
+ Managed provider projection intentionally avoids these legacy fields:
67
+
68
+ - `model_providers.<id>.env_key`
69
+ - `model_providers.<id>.env_key_instructions`
70
+
71
+ Managed provider projection fixes these fields for OpenAI-compatible direct routes:
72
+
73
+ - `wire_api = "responses"`
74
+ - `requires_openai_auth = true`
75
+
76
+ Compatibility notes:
77
+
78
+ - `--profile` is accepted as an alias for the managed `model_provider` id.
79
+ - legacy top-level `profile` and `[profiles.*]` may still appear in existing runtime state
80
+ - `migrate`, `config show`, `config list-profiles`, and `doctor` can still inspect those legacy structures
81
+ - new managed runtime projection should be described as route-first, not profile-first
82
+
83
+ Example managed direct-provider projection:
84
+
85
+ ```toml
86
+ model = "gpt-5.5"
87
+ model_provider = "proxy"
88
+
89
+ [model_providers.proxy]
90
+ name = "proxy"
91
+ base_url = "https://proxy.example.com/v1"
92
+ wire_api = "responses"
93
+ requires_openai_auth = true
94
+ ```
95
+
96
+ Authentication projection for the direct path remains:
97
+
98
+ ```json
99
+ {
100
+ "OPENAI_API_KEY": "sk-xxx"
101
+ }
102
+ ```
103
+
104
+ ## 4. Advanced Adopt Workflow
105
+
106
+ Use `migrate` only when you already have Codex runtime state that should be adopted into managed `providers.json` state.
107
+
108
+ ```bash
109
+ codexs init
110
+ codexs migrate
111
+ ```
112
+
113
+ `migrate` is an advanced adopt helper. It is not the default first step for fresh installs.
114
+
115
+ Current behavior:
116
+
117
+ - It can inspect legacy runtime `profile` and `[profiles.*]` state from the target Codex runtime.
118
+ - It can collect missing provider details in TTY mode.
119
+ - It can merge into or overwrite existing managed provider state.
120
+ - It still fails fast in non-TTY and `--json` runs when interactive input would be required.
121
+
122
+ ## 5. Deprecated Entry
123
+
124
+ ```bash
125
+ codexs setup
126
+ ```
127
+
128
+ `setup` is deprecated. It is kept only to direct callers toward `init` or `migrate`, and it no longer performs initialization or migration work.
129
+
130
+ ## 6. Global Contract
131
+
132
+ ### 6.1 Global Flags
133
+
134
+ ```bash
135
+ --json
136
+ --codex-dir <path>
137
+ --help
138
+ --version
139
+ ```
140
+
141
+ ### 6.2 Environment Variables
142
+
143
+ ```bash
144
+ CODEXS_HOME
145
+ CODEXS_CODEX_DIR
146
+ ```
147
+
148
+ ### 6.3 Runtime Model
149
+
150
+ Tool home:
151
+
152
+ ```text
153
+ ~/.config/codex-switch/
154
+ codex-switch.json
155
+ providers.json
156
+ backups/
157
+ runtime/
158
+ runtimes/
159
+ ```
160
+
161
+ Target Codex runtime:
162
+
163
+ ```text
164
+ ~/.codex/
165
+ config.toml
166
+ auth.json
167
+ ```
168
+
169
+ Meaning:
170
+
171
+ - `providers.json` is the managed provider registry.
172
+ - `codex-switch.json` stores tool-level metadata such as `defaultCodexDir`.
173
+ - `config.toml` remains the active runtime routing file.
174
+ - `auth.json` remains the active auth projection file.
175
+
176
+ ## 7. Command Categories
177
+
178
+ Read commands:
179
+
180
+ ```bash
181
+ codexs list
182
+ codexs show <provider>
183
+ codexs current
184
+ codexs status
185
+ codexs config show [profile]
186
+ codexs config list-profiles
187
+ codexs bridge status [provider]
188
+ codexs backups list
189
+ codexs doctor
190
+ ```
191
+
192
+ Change commands:
193
+
194
+ ```bash
195
+ codexs init
196
+ codexs login copilot
197
+ codexs migrate
198
+ codexs add <provider>
199
+ codexs edit <provider>
200
+ codexs switch <provider>
201
+ codexs remove <provider>
202
+ codexs import <file>
203
+ codexs export <file>
204
+ codexs bridge start [provider]
205
+ codexs bridge stop [provider]
206
+ codexs rollback [backup-id]
207
+ ```
208
+
209
+ ## 8. Selected Command Semantics
210
+
211
+ ### `init`
212
+
213
+ - Creates `codex-switch.json` and `providers.json` under the tool home when they do not exist yet.
214
+ - Does not create or validate `config.toml`, `auth.json`, or the target Codex directory.
215
+ - When `--codex-dir` is passed explicitly during first-time initialization, it can persist `defaultCodexDir`.
216
+
217
+ ### `login copilot`
218
+
219
+ - Supports `copilot` and `github-copilot` as the current upstream name.
220
+ - Installs the local Copilot SDK under the tool home when needed.
221
+ - Invokes the official Copilot CLI for login when readiness is not already present.
222
+ - Requires a real TTY and does not support `--json`.
223
+
224
+ ### `status`
225
+
226
+ - Reports the target Codex runtime and the tool-home root.
227
+ - Reports the active model and active `model_provider` route.
228
+ - Can still surface legacy profile-derived observations when inspecting older runtime state.
229
+ - Adds bridge, Copilot SDK, and upstream auth signals when the active provider uses a local runtime bridge.
230
+ - Does not mutate any files.
231
+
232
+ ### `list`
233
+
234
+ - Lists managed providers together with their linked route identity.
235
+ - Distinguishes provider type using the public values `direct` and `copilot`.
236
+ - Marks the current provider only when the active runtime can be mapped back to one unique managed provider.
237
+ - When the active route is shared by multiple providers, it does not invent a single current provider and should instead surface the ambiguity.
238
+ - TTY provider pickers used by commands such as `switch` and `show` follow the same visibility rules for route, provider type, and current-state hints.
239
+
240
+ ### `doctor`
241
+
242
+ - Checks expected config files, managed-provider consistency, and Codex CLI availability.
243
+ - Inspects both route-first runtime state and legacy profile state when needed.
244
+ - Adds bridge and Copilot dependency diagnostics for Copilot-backed providers.
245
+ - Returns repair-oriented issues intended for both human users and AI agents.
246
+
247
+ ### `switch`
248
+
249
+ - Projects direct providers by rewriting top-level `model`, top-level `model_provider`, the managed `[model_providers.<id>]` block, and `auth.json`.
250
+ - Cleans legacy projected `env_key` and `env_key_instructions` fields before writing the managed provider route.
251
+ - Copilot bridge providers also project the local bridge secret into the runtime while managing bridge routing.
252
+ - Managed writes are backed up and rolled back on failure.
253
+ - 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`.
254
+
255
+ ### `add` and `edit`
256
+
257
+ - Create or update managed provider records rather than editing runtime files directly.
258
+ - Treat `--profile` only as an alias for the managed `model_provider` id.
259
+ - Clean old `env_key` and `env_key_instructions` fields from managed projection during subsequent switching.
260
+
261
+ ### `migrate`
262
+
263
+ - Adopts unmanaged runtime route or legacy profile state into managed `providers.json` state.
264
+ - Still relies on interactive route/profile selection and provider-detail collection in this release.
265
+ - Should be treated as an advanced adopt tool, not as the normal onboarding path.
266
+
267
+ ## 9. Automation Boundaries
268
+
269
+ - Progressive prompts run only in a real TTY and never under `--json`.
270
+ - Human write commands may prompt for missing inputs or dangerous-action confirmation.
271
+ - Automation should pass explicit arguments and prefer `--json`.
272
+ - `login copilot` is TTY-only.
273
+ - `migrate` is not yet a complete non-interactive workflow.
274
+
275
+ ## 10. Related Docs
276
+
277
+ - [README](../README.md)
278
+ - [Chinese README](../README.CN.md)
279
+ - [AI README](../README.AI.md)
280
+ - [Product Overview](./codex-switch-product-overview.md)
281
+ - [Release PRD 0.1.1](./PRD/codex-switch-prd-v0.1.1.md)
282
+ - [Release Design 0.1.1](./Design/codex-switch-v0.1.1-design.md)
@@ -1,7 +1,7 @@
1
1
  # codex-switch 命令设计说明
2
2
 
3
3
  > 状态说明:这份文档是历史跨版本参考,不是当前 release contract。
4
- > 当前事实源请改看 [`docs/cli-usage.md`](./cli-usage.md)、[`docs/PRD/codex-switch-prd-v0.1.0.md`](./PRD/codex-switch-prd-v0.1.0.md)、[`docs/Design/codex-switch-v0.1.0-design.md`](./Design/codex-switch-v0.1.0-design.md)。
4
+ > 当前事实源请改看 [`docs/cli-usage.md`](./cli-usage.md)、[`docs/PRD/codex-switch-prd-v0.1.1.md`](./PRD/codex-switch-prd-v0.1.1.md)、[`docs/Design/codex-switch-v0.1.1-design.md`](./Design/codex-switch-v0.1.1-design.md)。
5
5
 
6
6
  ## 文档信息
7
7
 
@@ -4,15 +4,15 @@
4
4
 
5
5
  这份文档介绍当前活跃产品事实源下的 `codex-switch` 产品定位。
6
6
 
7
- 当前 release contract 以这些文档为准:
7
+ 当前 release contract 以这些文档为准:
8
8
 
9
9
  - [`cli-usage.md`](./cli-usage.md)
10
- - [`PRD/codex-switch-prd-v0.1.0.md`](./PRD/codex-switch-prd-v0.1.0.md)
11
- - [`Design/codex-switch-v0.1.0-design.md`](./Design/codex-switch-v0.1.0-design.md)
10
+ - [`PRD/codex-switch-prd-v0.1.1.md`](./PRD/codex-switch-prd-v0.1.1.md)
11
+ - [`Design/codex-switch-v0.1.1-design.md`](./Design/codex-switch-v0.1.1-design.md)
12
12
 
13
13
  ## 产品概述
14
14
 
15
- `codex-switch` 是一个本地 provider 管理 CLI,用于管理和切换目标 Codex runtime 的 provider/profile 配置,同时把工具自己的管理态保存在独立 tool home 下。
15
+ `codex-switch` 是一个本地 provider 管理 CLI,用于管理和切换目标 Codex runtime 的 provider/model-provider 路由配置,同时把工具自己的管理态保存在独立 tool home 下。
16
16
 
17
17
  它不是旧 `setup` 小工具,也不是围绕单目录 `~/.codex` 组织全部状态的脚本集合。
18
18
 
@@ -48,11 +48,11 @@ target Codex runtime:
48
48
 
49
49
  ## 核心使用流程
50
50
 
51
- Direct 主路径:
51
+ Direct 主路径:
52
52
 
53
53
  ```bash
54
54
  codexs init
55
- codexs add <provider> --profile <name> --api-key <key>
55
+ codexs add <provider> --model <model> --api-key <key> [--base-url <url>]
56
56
  codexs switch <provider>
57
57
  codexs status
58
58
  codexs doctor
@@ -63,7 +63,7 @@ Copilot 主路径:
63
63
  ```bash
64
64
  codexs init
65
65
  codexs login copilot
66
- codexs add <provider> --copilot --profile <name>
66
+ codexs add <provider> --copilot --model <model>
67
67
  codexs switch <provider>
68
68
  codexs status
69
69
  codexs doctor
@@ -78,9 +78,10 @@ codexs migrate
78
78
 
79
79
  ## 当前产品判断
80
80
 
81
- `0.1.0` 的重点不是再加新命令,而是让用户在 README、help 和输出第一屏就能理解:
81
+ `0.1.1` 的重点不是再加新命令,而是让用户在 README、help 和输出第一屏就能理解:
82
82
 
83
- - fresh install 应先走什么
84
- - Copilot 路径和 direct 路径有什么区别
85
- - `migrate` 何时才该使用
86
- - `status` / `doctor` 如何帮助定位下一步
83
+ - fresh install 应先走什么
84
+ - Copilot 路径和 direct 路径有什么区别
85
+ - `migrate` 何时才该使用
86
+ - `status` / `doctor` 如何帮助定位下一步
87
+ - 当前运行态是用顶层 `model` 与 `model_provider` 选择活动路由
@@ -1,7 +1,7 @@
1
1
  # codex-switch 技术架构设计
2
2
 
3
3
  > 状态说明:这份文档是历史跨版本参考,不是当前 release contract。
4
- > 当前事实源请改看 [`docs/cli-usage.md`](./cli-usage.md)、[`docs/PRD/codex-switch-prd-v0.1.0.md`](./PRD/codex-switch-prd-v0.1.0.md)、[`docs/Design/codex-switch-v0.1.0-design.md`](./Design/codex-switch-v0.1.0-design.md)。
4
+ > 当前事实源请改看 [`docs/cli-usage.md`](./cli-usage.md)、[`docs/PRD/codex-switch-prd-v0.1.1.md`](./PRD/codex-switch-prd-v0.1.1.md)、[`docs/Design/codex-switch-v0.1.1-design.md`](./Design/codex-switch-v0.1.1-design.md)。
5
5
 
6
6
  ## 文档信息
7
7
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@minniexcode/codex-switch",
3
- "version": "0.1.0",
4
- "description": "Local-first CLI for managing and switching Codex provider/profile configuration.",
3
+ "version": "0.1.1",
4
+ "description": "Local-first CLI for managing and switching Codex provider/model-provider routing.",
5
5
  "license": "MIT",
6
6
  "type": "commonjs",
7
7
  "bin": {