@minniexcode/codex-switch 0.1.5 → 0.2.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.
- package/README.AI.md +66 -94
- package/README.CN.md +84 -139
- package/README.md +91 -151
- package/dist/app/add-provider.js +6 -89
- package/dist/app/edit-provider.js +9 -29
- package/dist/app/get-status.js +1 -74
- package/dist/app/list-providers.js +0 -2
- package/dist/app/remove-provider.js +3 -5
- package/dist/app/run-doctor.js +2 -100
- package/dist/app/setup-codex.js +0 -2
- package/dist/app/switch-provider.js +1 -79
- package/dist/cli/output.js +3 -89
- package/dist/commands/handlers.js +20 -209
- package/dist/commands/help.js +1 -4
- package/dist/commands/registry.js +6 -74
- package/dist/domain/config.js +1 -3
- package/dist/domain/providers.js +4 -92
- package/dist/domain/runtime-state.js +0 -88
- package/dist/interaction/add-interactive.js +1 -55
- package/dist/interaction/interactive.js +1 -3
- package/dist/runtime/codex-probe.js +0 -12
- package/dist/storage/codex-paths.js +0 -2
- package/docs/Design/codex-switch-v0.2.0-design.md +56 -0
- package/docs/Design/codex-switch-v0.2.1-design.md +77 -0
- package/docs/PRD/codex-switch-prd-v0.2.1.md +82 -0
- package/docs/Tests/testing.md +32 -34
- package/docs/cli-usage.md +67 -235
- package/docs/codex-switch-command-design.md +1 -1
- package/docs/codex-switch-product-overview.md +49 -96
- package/docs/codex-switch-technical-architecture.md +37 -52
- package/package.json +1 -1
- package/dist/app/bridge.js +0 -308
- package/dist/runtime/copilot-adapter.js +0 -612
- package/dist/runtime/copilot-bridge-worker.js +0 -69
- package/dist/runtime/copilot-bridge.js +0 -1318
- package/dist/runtime/copilot-cli.js +0 -164
- package/dist/runtime/copilot-installer.js +0 -231
- package/dist/runtime/copilot-sdk-loader.js +0 -62
- package/dist/storage/runtime-state-repo.js +0 -121
package/docs/cli-usage.md
CHANGED
|
@@ -1,298 +1,130 @@
|
|
|
1
|
-
#
|
|
1
|
+
# CLI Usage
|
|
2
2
|
|
|
3
|
-
This document describes the current `0.1
|
|
3
|
+
This document describes the current `0.2.1` repository development-line CLI contract for `@minniexcode/codex-switch`.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
`codex-switch` is a local-first provider/model-provider management CLI for Codex. It manages local provider records and projects the active Codex route into `config.toml` and `auth.json`.
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
codexs
|
|
9
|
-
```
|
|
10
|
-
|
|
11
|
-
## 1. Version Context
|
|
12
|
-
|
|
13
|
-
The current package version in this repository is `0.1.5`.
|
|
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. The current `0.1.5` development line adds Copilot Bridge process visibility, defensive SDK-event normalization, and unknown-event redaction hardening without expanding the provider command surface.
|
|
16
|
-
|
|
17
|
-
## 2. Primary Workflows
|
|
18
|
-
|
|
19
|
-
### 2.1 Direct Providers
|
|
20
|
-
|
|
21
|
-
```bash
|
|
22
|
-
codexs init
|
|
23
|
-
codexs add <provider> --profile <model-provider-id> --model <model> --api-key <key> [--base-url <url>]
|
|
24
|
-
codexs switch <provider>
|
|
25
|
-
codexs status
|
|
26
|
-
codexs doctor
|
|
27
|
-
```
|
|
7
|
+
## Version
|
|
28
8
|
|
|
29
|
-
|
|
9
|
+
Current package version: `0.2.1`
|
|
30
10
|
|
|
31
|
-
- `
|
|
32
|
-
- `add` creates a managed provider record with a target model and provider route identity.
|
|
33
|
-
- Non-interactive runs should pass `--profile` explicitly; TTY mode can prompt for missing required fields.
|
|
34
|
-
- `switch` projects the selected provider into the target Codex runtime.
|
|
35
|
-
- `status` summarizes tool-home, runtime, provider, and health state.
|
|
36
|
-
- `doctor` gives deeper repair-oriented diagnostics.
|
|
11
|
+
This line targets Codex `0.134.0+`, where the active route is selected by top-level `model` plus `model_provider`. Legacy top-level `profile` and `[profiles.*]` sections may still be inspected for migration/adoption, but they are not the recommended managed route.
|
|
37
12
|
|
|
38
|
-
|
|
13
|
+
## Primary Workflow
|
|
39
14
|
|
|
40
15
|
```bash
|
|
41
16
|
codexs init
|
|
42
|
-
codexs
|
|
43
|
-
codexs
|
|
44
|
-
codexs switch <provider>
|
|
17
|
+
codexs add packycode --profile packycode --model gpt-5 --api-key sk-xxx --base-url https://api.example/v1
|
|
18
|
+
codexs switch packycode
|
|
45
19
|
codexs status
|
|
46
20
|
codexs doctor
|
|
47
21
|
```
|
|
48
22
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
- `login copilot` is the upstream onboarding command.
|
|
52
|
-
- The current implementation prefers the bundled Copilot CLI from the managed runtime and falls back to `PATH` when needed.
|
|
53
|
-
- `login copilot` succeeds only after auth readiness is rechecked.
|
|
54
|
-
- `add --copilot` does not install or log in to Copilot for you.
|
|
55
|
-
- Non-interactive Copilot adds should also pass `--profile` explicitly; TTY mode can still collect missing required fields.
|
|
56
|
-
- Copilot runtime paths require Node.js `>=20`; direct providers remain supported on Node.js `>=18`.
|
|
57
|
-
- The Copilot bridge is experimental and targets simple text-oriented turns through the local OpenAI-compatible bridge.
|
|
58
|
-
|
|
59
|
-
## 3. Runtime Route Contract
|
|
60
|
-
|
|
61
|
-
For Codex `0.134.0+`, the active runtime route is selected through top-level `model` and `model_provider` in `config.toml`.
|
|
23
|
+
`--profile` is a CLI alias for the managed `model_provider` id.
|
|
62
24
|
|
|
63
|
-
|
|
25
|
+
## Commands
|
|
64
26
|
|
|
65
|
-
|
|
66
|
-
- top-level `model_provider`
|
|
67
|
-
- `[model_providers.<id>]`
|
|
68
|
-
- `auth.json` when direct auth projection is required
|
|
69
|
-
|
|
70
|
-
Managed provider projection intentionally avoids these legacy fields:
|
|
71
|
-
|
|
72
|
-
- `model_providers.<id>.env_key`
|
|
73
|
-
- `model_providers.<id>.env_key_instructions`
|
|
74
|
-
|
|
75
|
-
Managed provider projection fixes these fields for OpenAI-compatible direct routes:
|
|
76
|
-
|
|
77
|
-
- `wire_api = "responses"`
|
|
78
|
-
- `requires_openai_auth = true`
|
|
79
|
-
|
|
80
|
-
Copilot bridge projection also writes:
|
|
81
|
-
|
|
82
|
-
- `stream_idle_timeout_ms = 300000`
|
|
83
|
-
|
|
84
|
-
Compatibility notes:
|
|
85
|
-
|
|
86
|
-
- `--profile` is accepted as an alias for the managed `model_provider` id.
|
|
87
|
-
- automation should still pass `--profile` explicitly instead of relying on prompts
|
|
88
|
-
- legacy top-level `profile` and `[profiles.*]` may still appear in existing runtime state
|
|
89
|
-
- `migrate`, `config show`, `config list-profiles`, and `doctor` can still inspect those legacy structures
|
|
90
|
-
- new managed runtime projection should be described as route-first, not profile-first
|
|
91
|
-
|
|
92
|
-
Example managed direct-provider projection:
|
|
27
|
+
### `init`
|
|
93
28
|
|
|
94
|
-
|
|
95
|
-
model = "gpt-5.5"
|
|
96
|
-
model_provider = "proxy"
|
|
29
|
+
Initializes the `codex-switch` tool home. It creates `codex-switch.json` and `providers.json` when missing. It does not require a target Codex `config.toml`.
|
|
97
30
|
|
|
98
|
-
|
|
99
|
-
name = "proxy"
|
|
100
|
-
base_url = "https://proxy.example.com/v1"
|
|
101
|
-
wire_api = "responses"
|
|
102
|
-
requires_openai_auth = true
|
|
103
|
-
```
|
|
31
|
+
### `migrate`
|
|
104
32
|
|
|
105
|
-
|
|
33
|
+
Advanced adopt helper for existing Codex config. Use it only when existing route/profile state should be copied into managed `providers.json`.
|
|
106
34
|
|
|
107
|
-
|
|
108
|
-
{
|
|
109
|
-
"OPENAI_API_KEY": "sk-xxx"
|
|
110
|
-
}
|
|
111
|
-
```
|
|
112
|
-
|
|
113
|
-
## 4. Advanced Adopt Workflow
|
|
35
|
+
### `list`
|
|
114
36
|
|
|
115
|
-
|
|
37
|
+
Lists managed providers with their model-provider ids, model hints, tags, notes, and current-state mapping. Human output does not expose a provider-type column because `0.2.1` has only the provider-management path.
|
|
116
38
|
|
|
117
|
-
|
|
118
|
-
codexs init
|
|
119
|
-
codexs migrate
|
|
120
|
-
```
|
|
39
|
+
### `show <provider>`
|
|
121
40
|
|
|
122
|
-
|
|
41
|
+
Shows one provider record. Human output masks the API key; JSON output returns the local provider payload.
|
|
123
42
|
|
|
124
|
-
|
|
43
|
+
### `current`
|
|
125
44
|
|
|
126
|
-
|
|
127
|
-
- It can collect missing provider details in TTY mode.
|
|
128
|
-
- It can merge into or overwrite existing managed provider state.
|
|
129
|
-
- It still fails fast in non-TTY and `--json` runs when interactive input would be required.
|
|
45
|
+
Reads the current top-level `model` and `model_provider` from `config.toml` and maps it back to a managed provider when possible.
|
|
130
46
|
|
|
131
|
-
|
|
47
|
+
### `status`
|
|
132
48
|
|
|
133
|
-
|
|
134
|
-
codexs setup
|
|
135
|
-
```
|
|
49
|
+
Reports target Codex directory, tool-home root, current model route, mapping state, auth projection state, warnings, and next step. It does not report bridge runtime health.
|
|
136
50
|
|
|
137
|
-
|
|
51
|
+
### `config show`
|
|
138
52
|
|
|
139
|
-
|
|
53
|
+
Shows the current route summary and recognizable legacy profile view.
|
|
140
54
|
|
|
141
|
-
###
|
|
55
|
+
### `config list-profiles`
|
|
142
56
|
|
|
143
|
-
|
|
144
|
-
--json
|
|
145
|
-
--codex-dir <path>
|
|
146
|
-
--help
|
|
147
|
-
--version
|
|
148
|
-
```
|
|
57
|
+
Lists recognizable legacy config profiles with managed-state hints for adoption and diagnostics.
|
|
149
58
|
|
|
150
|
-
###
|
|
59
|
+
### `add`
|
|
151
60
|
|
|
152
61
|
```bash
|
|
153
|
-
|
|
154
|
-
CODEXS_CODEX_DIR
|
|
62
|
+
codexs add <provider> --profile <model-provider-id> --model <model> --api-key <key> [--base-url <url>] [--note <text>] [--tag <tag> ...]
|
|
155
63
|
```
|
|
156
64
|
|
|
157
|
-
|
|
65
|
+
Adds a provider to `providers.json`, creates or updates the matching `[model_providers.<id>]` section, and backs up managed files before writing.
|
|
158
66
|
|
|
159
|
-
|
|
67
|
+
### `edit`
|
|
160
68
|
|
|
161
|
-
|
|
162
|
-
~/.config/codex-switch/
|
|
163
|
-
codex-switch.json
|
|
164
|
-
providers.json
|
|
165
|
-
backups/
|
|
166
|
-
runtime/
|
|
167
|
-
runtimes/
|
|
168
|
-
```
|
|
69
|
+
Updates selected fields on a provider record and repairs the matching model-provider projection when needed.
|
|
169
70
|
|
|
170
|
-
|
|
71
|
+
### `switch`
|
|
171
72
|
|
|
172
|
-
|
|
173
|
-
~/.codex/
|
|
174
|
-
config.toml
|
|
175
|
-
auth.json
|
|
176
|
-
```
|
|
73
|
+
Switches the active Codex route to a managed provider by writing top-level `model` and `model_provider`, updating the matching model-provider section, and projecting API-key auth.
|
|
177
74
|
|
|
178
|
-
|
|
75
|
+
### `remove`
|
|
179
76
|
|
|
180
|
-
|
|
181
|
-
- `codex-switch.json` stores tool-level metadata such as `defaultCodexDir`.
|
|
182
|
-
- `config.toml` remains the active runtime routing file.
|
|
183
|
-
- `auth.json` remains the active auth projection file.
|
|
77
|
+
Removes a provider from `providers.json`. Non-interactive and JSON runs require `--force`. Removing a provider that owns the active route may require `--switch-to` first.
|
|
184
78
|
|
|
185
|
-
|
|
79
|
+
### `import`
|
|
186
80
|
|
|
187
|
-
|
|
81
|
+
Replaces or merges `providers.json` from an explicit JSON file under backup flow.
|
|
188
82
|
|
|
189
|
-
|
|
190
|
-
codexs list
|
|
191
|
-
codexs show <provider>
|
|
192
|
-
codexs current
|
|
193
|
-
codexs status
|
|
194
|
-
codexs config show [profile]
|
|
195
|
-
codexs config list-profiles
|
|
196
|
-
codexs bridge status [provider]
|
|
197
|
-
codexs backups list
|
|
198
|
-
codexs doctor
|
|
199
|
-
```
|
|
83
|
+
### `export`
|
|
200
84
|
|
|
201
|
-
|
|
85
|
+
Exports current `providers.json` to an explicit file. Use `--force` to overwrite in automation.
|
|
202
86
|
|
|
203
|
-
|
|
204
|
-
codexs init
|
|
205
|
-
codexs login copilot
|
|
206
|
-
codexs migrate
|
|
207
|
-
codexs add <provider>
|
|
208
|
-
codexs edit <provider>
|
|
209
|
-
codexs switch <provider>
|
|
210
|
-
codexs remove <provider>
|
|
211
|
-
codexs import <file>
|
|
212
|
-
codexs export <file>
|
|
213
|
-
codexs bridge start [provider]
|
|
214
|
-
codexs bridge stop [provider]
|
|
215
|
-
codexs rollback [backup-id]
|
|
216
|
-
```
|
|
87
|
+
### `backups list`
|
|
217
88
|
|
|
218
|
-
|
|
89
|
+
Lists managed backup manifests newest first.
|
|
219
90
|
|
|
220
|
-
### `
|
|
91
|
+
### `rollback`
|
|
221
92
|
|
|
222
|
-
|
|
223
|
-
- Does not create or validate `config.toml`, `auth.json`, or the target Codex directory.
|
|
224
|
-
- When `--codex-dir` is passed explicitly during first-time initialization, it can persist `defaultCodexDir`.
|
|
93
|
+
Restores the latest managed backup or a specific backup id.
|
|
225
94
|
|
|
226
|
-
### `
|
|
95
|
+
### `doctor`
|
|
227
96
|
|
|
228
|
-
-
|
|
229
|
-
- Installs the local Copilot SDK under the tool home when needed.
|
|
230
|
-
- Invokes the official Copilot CLI for login when readiness is not already present.
|
|
231
|
-
- Requires a real TTY and does not support `--json`.
|
|
97
|
+
Runs issue-first diagnostics across config, providers, auth projection, route drift, and Codex CLI availability.
|
|
232
98
|
|
|
233
|
-
### `
|
|
99
|
+
### `setup`
|
|
234
100
|
|
|
235
|
-
|
|
236
|
-
- Reports the active model and active `model_provider` route.
|
|
237
|
-
- Can still surface legacy profile-derived observations when inspecting older runtime state.
|
|
238
|
-
- Adds bridge, Copilot SDK, and upstream auth signals when the active provider uses a local runtime bridge.
|
|
239
|
-
- Does not mutate any files.
|
|
101
|
+
Deprecated. It exists only to point users to `init` for fresh state or `migrate` for adoption.
|
|
240
102
|
|
|
241
|
-
|
|
103
|
+
## Current Non-Goals
|
|
242
104
|
|
|
243
|
-
-
|
|
244
|
-
- Distinguishes provider type using the public values `direct` and `copilot`.
|
|
245
|
-
- Marks the current provider only when the active runtime can be mapped back to one unique managed provider.
|
|
246
|
-
- When the active route is shared by multiple providers, it does not invent a single current provider and should instead surface the ambiguity.
|
|
247
|
-
- TTY provider pickers used by commands such as `switch` and `show` follow the same visibility rules for route, provider type, and current-state hints.
|
|
105
|
+
`0.2.1` does not provide `login copilot`, `add --copilot`, `bridge start`, `bridge status`, `bridge stop`, Copilot SDK integration, GitHub device-flow login, HTTP proxy bridge, local bridge workers, background runtime services, bridge logs, or automatic migration of old bridge state.
|
|
248
106
|
|
|
249
|
-
|
|
107
|
+
## JSON Contract
|
|
250
108
|
|
|
251
|
-
|
|
252
|
-
- Inspects both route-first runtime state and legacy profile state when needed.
|
|
253
|
-
- Adds bridge and Copilot dependency diagnostics for Copilot-backed providers.
|
|
254
|
-
- Returns repair-oriented issues intended for both human users and AI agents.
|
|
109
|
+
`--json` renders the standard envelope:
|
|
255
110
|
|
|
256
|
-
|
|
111
|
+
```json
|
|
112
|
+
{
|
|
113
|
+
"ok": true,
|
|
114
|
+
"command": "status",
|
|
115
|
+
"data": {},
|
|
116
|
+
"warnings": [],
|
|
117
|
+
"error": null
|
|
118
|
+
}
|
|
119
|
+
```
|
|
257
120
|
|
|
258
|
-
|
|
259
|
-
- Cleans legacy projected `env_key` and `env_key_instructions` fields before writing the managed provider route.
|
|
260
|
-
- Copilot bridge providers also project the local bridge secret into the runtime while managing bridge routing.
|
|
261
|
-
- Managed writes are backed up and rolled back on failure.
|
|
262
|
-
- 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`.
|
|
121
|
+
Failures render the same envelope to stderr with `ok: false` and a structured error.
|
|
263
122
|
|
|
264
|
-
|
|
123
|
+
## Fact Sources
|
|
265
124
|
|
|
266
|
-
|
|
267
|
-
- Treat `--profile` only as an alias for the managed `model_provider` id.
|
|
268
|
-
- Require explicit `--profile` in non-interactive usage; allow TTY prompts to fill it when omitted.
|
|
269
|
-
- Clean old `env_key` and `env_key_instructions` fields from managed projection during subsequent switching.
|
|
125
|
+
Current:
|
|
270
126
|
|
|
271
|
-
|
|
127
|
+
- [PRD 0.2.1](./PRD/codex-switch-prd-v0.2.1.md)
|
|
128
|
+
- [Design 0.2.1](./Design/codex-switch-v0.2.1-design.md)
|
|
272
129
|
|
|
273
|
-
|
|
274
|
-
- Still relies on interactive route/profile selection and provider-detail collection in this release.
|
|
275
|
-
- Should be treated as an advanced adopt tool, not as the normal onboarding path.
|
|
276
|
-
|
|
277
|
-
## 9. Automation Boundaries
|
|
278
|
-
|
|
279
|
-
- Progressive prompts run only in a real TTY and never under `--json`.
|
|
280
|
-
- Human write commands may prompt for missing inputs or dangerous-action confirmation.
|
|
281
|
-
- Automation should pass explicit arguments and prefer `--json`.
|
|
282
|
-
- `login copilot` is TTY-only.
|
|
283
|
-
- `migrate` is not yet a complete non-interactive workflow.
|
|
284
|
-
|
|
285
|
-
## 10. Related Docs
|
|
286
|
-
|
|
287
|
-
- [README](../README.md)
|
|
288
|
-
- [Chinese README](../README.CN.md)
|
|
289
|
-
- [AI README](../README.AI.md)
|
|
290
|
-
- [Product Overview](./codex-switch-product-overview.md)
|
|
291
|
-
- [PRD 0.1.0](./PRD/codex-switch-prd-v0.1.0.md)
|
|
292
|
-
- [PRD 0.1.1](./PRD/codex-switch-prd-v0.1.1.md)
|
|
293
|
-
- [PRD 0.1.2](./PRD/codex-switch-prd-v0.1.2.md)
|
|
294
|
-
- [PRD 0.1.3](./PRD/codex-switch-prd-v0.1.3.md)
|
|
295
|
-
- [PRD 0.1.5](./PRD/codex-switch-prd-v0.1.5.md)
|
|
296
|
-
- [Design 0.1.2](./Design/codex-switch-v0.1.2-design.md)
|
|
297
|
-
- [Design 0.1.3](./Design/codex-switch-v0.1.3-design.md)
|
|
298
|
-
- [Design 0.1.5](./Design/codex-switch-v0.1.5-design.md)
|
|
130
|
+
Historical `0.1.x` and `0.2.0` docs remain archived for context only.
|
|
@@ -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.
|
|
4
|
+
> 当前事实源请改看 [`docs/cli-usage.md`](./cli-usage.md)、[`docs/PRD/codex-switch-prd-v0.2.1.md`](./PRD/codex-switch-prd-v0.2.1.md)、[`docs/Design/codex-switch-v0.2.1-design.md`](./Design/codex-switch-v0.2.1-design.md)。
|
|
5
5
|
|
|
6
6
|
## 文档信息
|
|
7
7
|
|
|
@@ -1,96 +1,49 @@
|
|
|
1
|
-
# codex-switch
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
- [`cli-usage.md`](./cli-usage.md)
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
- `providers.json` 不位于 `~/.codex`
|
|
51
|
-
- `backups/` 不位于 `~/.codex`
|
|
52
|
-
- tool home 承担管理态 SSOT
|
|
53
|
-
- target runtime 承担受管运行态投影
|
|
54
|
-
|
|
55
|
-
## 核心使用流程
|
|
56
|
-
|
|
57
|
-
Direct 主路径:
|
|
58
|
-
|
|
59
|
-
```bash
|
|
60
|
-
codexs init
|
|
61
|
-
codexs add <provider> --profile <model-provider-id> --model <model> --api-key <key> [--base-url <url>]
|
|
62
|
-
codexs switch <provider>
|
|
63
|
-
codexs status
|
|
64
|
-
codexs doctor
|
|
65
|
-
```
|
|
66
|
-
|
|
67
|
-
Copilot 主路径:
|
|
68
|
-
|
|
69
|
-
```bash
|
|
70
|
-
codexs init
|
|
71
|
-
codexs login copilot
|
|
72
|
-
codexs add <provider> --copilot --profile <model-provider-id> --model <model>
|
|
73
|
-
codexs switch <provider>
|
|
74
|
-
codexs status
|
|
75
|
-
codexs doctor
|
|
76
|
-
```
|
|
77
|
-
|
|
78
|
-
Advanced adopt helper:
|
|
79
|
-
|
|
80
|
-
```bash
|
|
81
|
-
codexs init
|
|
82
|
-
codexs migrate
|
|
83
|
-
```
|
|
84
|
-
|
|
85
|
-
## 当前产品判断
|
|
86
|
-
|
|
87
|
-
`0.1.1` 的重点不是再加新命令,而是让用户在 README、help 和输出第一屏就能理解:
|
|
88
|
-
|
|
89
|
-
- fresh install 应先走什么
|
|
90
|
-
- Copilot 路径和 direct 路径有什么区别
|
|
91
|
-
- 非交互命令为什么应显式传 `--profile`,以及 TTY 模式下哪些缺失项可以补问
|
|
92
|
-
- `migrate` 何时才该使用
|
|
93
|
-
- `status` / `doctor` 如何帮助定位下一步
|
|
94
|
-
- 当前运行态是用顶层 `model` 与 `model_provider` 选择活动路由
|
|
95
|
-
|
|
96
|
-
`0.1.5` 是当前仓库开发线,重点不是扩展 provider 面,而是让已有 Copilot bridge 实验路径具备过程可见性:SDK 事件被归一化为稳定运行态事件,Responses 流可以显示 commentary/reasoning 信号,未知事件摘要会被脱敏和截断。当前实现边界仍然是:Copilot 路径要求 Node.js `>=20`,受管安装默认固定到 `@github/copilot-sdk@1.0.2`,本地 bridge 仍然只是面向 simple text-oriented turns 的 experimental bridge;Direct provider 路径继续支持 Node.js `>=18`。
|
|
1
|
+
# codex-switch Product Overview
|
|
2
|
+
|
|
3
|
+
Current version: `0.2.1`
|
|
4
|
+
|
|
5
|
+
Current fact sources:
|
|
6
|
+
|
|
7
|
+
- [`PRD/codex-switch-prd-v0.2.1.md`](./PRD/codex-switch-prd-v0.2.1.md)
|
|
8
|
+
- [`Design/codex-switch-v0.2.1-design.md`](./Design/codex-switch-v0.2.1-design.md)
|
|
9
|
+
- [`cli-usage.md`](./cli-usage.md)
|
|
10
|
+
|
|
11
|
+
## Product
|
|
12
|
+
|
|
13
|
+
`codex-switch` is a local-first provider/model-provider management CLI for Codex. It is for users who switch between OpenAI-compatible provider endpoints and want the switch to be explicit, backed up, and inspectable.
|
|
14
|
+
|
|
15
|
+
The product owns three jobs:
|
|
16
|
+
|
|
17
|
+
- Maintain managed provider records in `providers.json`.
|
|
18
|
+
- Project Codex `model_provider` entries plus active top-level `model` / `model_provider` route.
|
|
19
|
+
- Provide diagnostics, import/export, backups, and rollback for local state.
|
|
20
|
+
|
|
21
|
+
## Current Workflow
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
codexs init
|
|
25
|
+
codexs add <provider> --profile <model-provider-id> --model <model> --api-key <key> --base-url <url>
|
|
26
|
+
codexs switch <provider>
|
|
27
|
+
codexs status
|
|
28
|
+
codexs doctor
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
`migrate` is an advanced adopt helper for existing Codex config, not the fresh-install default.
|
|
32
|
+
|
|
33
|
+
## Current Boundary
|
|
34
|
+
|
|
35
|
+
`0.2.1` deliberately narrows the product to provider management. It does not include account onboarding, hosted services, local proxy bridges, or background runtime orchestration. A future third-party-router integration may be considered separately, but no workflow or runtime code path is part of `0.2.1`.
|
|
36
|
+
|
|
37
|
+
## Users
|
|
38
|
+
|
|
39
|
+
- Developers who maintain several Codex-compatible provider endpoints.
|
|
40
|
+
- AI agents that need a stable JSON command envelope and deterministic local state.
|
|
41
|
+
- Operators who want backups and diagnostics before changing Codex config.
|
|
42
|
+
|
|
43
|
+
## Non-Goals
|
|
44
|
+
|
|
45
|
+
- Copilot SDK or GitHub login flows.
|
|
46
|
+
- `login copilot`, `add --copilot`, or `bridge *` commands.
|
|
47
|
+
- HTTP proxy bridge or local bridge worker runtime.
|
|
48
|
+
- Account systems, cloud sync, or background services.
|
|
49
|
+
- Automatic migration of old experimental runtime state.
|
|
@@ -1,35 +1,30 @@
|
|
|
1
1
|
# codex-switch Technical Architecture
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Current version: `0.2.1`
|
|
4
4
|
|
|
5
|
+
Current fact sources:
|
|
6
|
+
|
|
7
|
+
- [`PRD/codex-switch-prd-v0.2.1.md`](./PRD/codex-switch-prd-v0.2.1.md)
|
|
8
|
+
- [`Design/codex-switch-v0.2.1-design.md`](./Design/codex-switch-v0.2.1-design.md)
|
|
5
9
|
- [`cli-usage.md`](./cli-usage.md)
|
|
6
|
-
- [`PRD/codex-switch-prd-v0.1.0.md`](./PRD/codex-switch-prd-v0.1.0.md)
|
|
7
|
-
- [`PRD/codex-switch-prd-v0.1.1.md`](./PRD/codex-switch-prd-v0.1.1.md)
|
|
8
|
-
- [`PRD/codex-switch-prd-v0.1.2.md`](./PRD/codex-switch-prd-v0.1.2.md)
|
|
9
|
-
- [`PRD/codex-switch-prd-v0.1.3.md`](./PRD/codex-switch-prd-v0.1.3.md)
|
|
10
|
-
- [`PRD/codex-switch-prd-v0.1.5.md`](./PRD/codex-switch-prd-v0.1.5.md)
|
|
11
|
-
- [`Design/codex-switch-v0.1.0-design.md`](./Design/codex-switch-v0.1.0-design.md)
|
|
12
|
-
- [`Design/codex-switch-v0.1.1-design.md`](./Design/codex-switch-v0.1.1-design.md)
|
|
13
|
-
- [`Design/codex-switch-v0.1.2-design.md`](./Design/codex-switch-v0.1.2-design.md)
|
|
14
|
-
- [`Design/codex-switch-v0.1.3-design.md`](./Design/codex-switch-v0.1.3-design.md)
|
|
15
|
-
- [`Design/codex-switch-v0.1.5-design.md`](./Design/codex-switch-v0.1.5-design.md)
|
|
16
10
|
|
|
17
11
|
## Layers
|
|
18
12
|
|
|
19
13
|
```text
|
|
20
|
-
src/
|
|
21
|
-
src/
|
|
22
|
-
src/
|
|
23
|
-
src/
|
|
24
|
-
src/
|
|
25
|
-
src/
|
|
26
|
-
src/
|
|
27
|
-
src/
|
|
14
|
+
src/cli.ts process entrypoint
|
|
15
|
+
src/commands/ argument parsing, command registry, help, dispatch
|
|
16
|
+
src/cli/ output rendering and CLI helpers
|
|
17
|
+
src/interaction/ prompt collection for TTY workflows
|
|
18
|
+
src/app/ command use cases
|
|
19
|
+
src/domain/ provider/config/backup types and pure rules
|
|
20
|
+
src/storage/ filesystem repositories and TOML/auth helpers
|
|
21
|
+
src/runtime/ Codex CLI probing and invocation helpers
|
|
22
|
+
src/infra/ compatibility facades for storage/runtime helpers
|
|
28
23
|
```
|
|
29
24
|
|
|
30
|
-
|
|
25
|
+
`dist/` is generated by `npm run build`.
|
|
31
26
|
|
|
32
|
-
## State
|
|
27
|
+
## State Boundary
|
|
33
28
|
|
|
34
29
|
Tool home stores managed state:
|
|
35
30
|
|
|
@@ -37,52 +32,42 @@ Tool home stores managed state:
|
|
|
37
32
|
codex-switch.json
|
|
38
33
|
providers.json
|
|
39
34
|
backups/
|
|
40
|
-
runtime/
|
|
41
|
-
runtimes/
|
|
42
35
|
```
|
|
43
36
|
|
|
44
|
-
Target Codex
|
|
37
|
+
Target Codex directory stores active Codex runtime files:
|
|
45
38
|
|
|
46
39
|
```text
|
|
47
40
|
config.toml
|
|
48
41
|
auth.json
|
|
49
42
|
```
|
|
50
43
|
|
|
51
|
-
|
|
44
|
+
The app layer should pass explicit paths into storage functions and avoid hidden global filesystem access beyond path resolution.
|
|
52
45
|
|
|
53
|
-
##
|
|
46
|
+
## Provider Model
|
|
54
47
|
|
|
55
|
-
`
|
|
48
|
+
`providers.json` stores provider records keyed by local provider name. Each provider points to a managed Codex `model_provider` id through its `profile` field. In current docs and UI, `--profile` is explained as this model-provider id alias.
|
|
56
49
|
|
|
57
|
-
|
|
58
|
-
2. Resolve the target provider and model.
|
|
59
|
-
3. For Copilot providers, verify SDK install, Node runtime, upstream auth, and bridge health.
|
|
60
|
-
4. Create a mutation backup.
|
|
61
|
-
5. Project `model`, `model_provider`, and `[model_providers.<id>]`.
|
|
62
|
-
6. Write `auth.json` with the Codex-facing bearer secret.
|
|
63
|
-
7. Roll back touched files if a mutation step fails.
|
|
50
|
+
Managed projection writes:
|
|
64
51
|
|
|
65
|
-
|
|
52
|
+
- top-level `model`
|
|
53
|
+
- top-level `model_provider`
|
|
54
|
+
- `[model_providers.<id>]` with `name`, `base_url`, `wire_api = "responses"`, and `requires_openai_auth = true`
|
|
55
|
+
- `auth.json` API-key projection
|
|
66
56
|
|
|
67
|
-
|
|
57
|
+
New managed writes do not create legacy `[profiles.*]` sections.
|
|
68
58
|
|
|
69
|
-
|
|
59
|
+
## Mutations And Backups
|
|
70
60
|
|
|
71
|
-
|
|
72
|
-
- The managed installer defaults to `@github/copilot-sdk@1.0.2`.
|
|
73
|
-
- Copilot paths require Node.js `>=20`; direct providers continue to support Node.js `>=18`.
|
|
74
|
-
- Runtime validation separately rejects older or prerelease SDK installs, and SDK API shape is validated when creating the client or session.
|
|
75
|
-
- The bridge exposes a minimal OpenAI-compatible `/v1/chat/completions` and `/v1/responses` surface for simple text-oriented turns.
|
|
76
|
-
- The worker keeps one long-lived `CopilotClient`, creates one session per request, serializes requests, requires `abort()`, and treats `disconnect()` as best-effort cleanup rather than a compatibility gate.
|
|
77
|
-
- Responses streaming emits initial SSE events before upstream completion and uses heartbeat comments while waiting.
|
|
61
|
+
Mutating app services run through `runMutation`, acquire the lock, create backups for affected files, perform writes, and roll back when the mutation fails.
|
|
78
62
|
|
|
79
|
-
|
|
63
|
+
Commands that mutate local state include `init`, `migrate`, `add`, `edit`, `switch`, `remove`, `import`, `export`, and `rollback`.
|
|
80
64
|
|
|
81
|
-
|
|
65
|
+
## Diagnostics
|
|
82
66
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
67
|
+
`status` is a lightweight current-state view. `doctor` is issue-first and checks config existence, providers existence, model-provider consistency, auth projection validity, route drift, and Codex CLI availability.
|
|
68
|
+
|
|
69
|
+
Optional bridge or account-runtime checks are not part of `0.2.1` diagnostics.
|
|
70
|
+
|
|
71
|
+
## Removed Runtime Experiments
|
|
72
|
+
|
|
73
|
+
`0.2.1` removes current runtime code paths for Copilot SDK integration, GitHub device-flow login, HTTP proxy bridge, local bridge workers, bridge logs, and bridge runtime state. Historical docs describe those experiments, but current architecture does not expose them.
|