@minniexcode/codex-switch 0.2.0 → 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.
Files changed (40) hide show
  1. package/README.AI.md +66 -94
  2. package/README.CN.md +84 -139
  3. package/README.md +91 -151
  4. package/dist/app/add-provider.js +6 -83
  5. package/dist/app/edit-provider.js +9 -29
  6. package/dist/app/get-status.js +1 -77
  7. package/dist/app/list-providers.js +0 -2
  8. package/dist/app/remove-provider.js +3 -5
  9. package/dist/app/run-doctor.js +2 -99
  10. package/dist/app/setup-codex.js +0 -2
  11. package/dist/app/switch-provider.js +1 -74
  12. package/dist/cli/output.js +3 -89
  13. package/dist/commands/handlers.js +20 -172
  14. package/dist/commands/help.js +1 -4
  15. package/dist/commands/registry.js +6 -74
  16. package/dist/domain/config.js +1 -3
  17. package/dist/domain/providers.js +4 -92
  18. package/dist/domain/runtime-state.js +0 -88
  19. package/dist/interaction/add-interactive.js +1 -55
  20. package/dist/interaction/interactive.js +1 -3
  21. package/dist/runtime/codex-probe.js +0 -12
  22. package/dist/storage/codex-paths.js +0 -2
  23. package/docs/Design/codex-switch-v0.2.1-design.md +77 -0
  24. package/docs/PRD/codex-switch-prd-v0.2.1.md +82 -0
  25. package/docs/Tests/testing.md +32 -34
  26. package/docs/cli-usage.md +67 -235
  27. package/docs/codex-switch-command-design.md +1 -1
  28. package/docs/codex-switch-product-overview.md +49 -96
  29. package/docs/codex-switch-technical-architecture.md +37 -52
  30. package/package.json +1 -1
  31. package/dist/app/bridge.js +0 -303
  32. package/dist/runtime/copilot-adapter.js +0 -617
  33. package/dist/runtime/copilot-bridge-worker.js +0 -69
  34. package/dist/runtime/copilot-bridge.js +0 -1351
  35. package/dist/runtime/copilot-cli.js +0 -164
  36. package/dist/runtime/copilot-http-bridge-worker.js +0 -228
  37. package/dist/runtime/copilot-installer.js +0 -231
  38. package/dist/runtime/copilot-sdk-loader.js +0 -62
  39. package/dist/runtime/copilot-token.js +0 -294
  40. package/dist/storage/runtime-state-repo.js +0 -121
package/README.AI.md CHANGED
@@ -1,24 +1,22 @@
1
- # AI README
1
+ # README.AI
2
2
 
3
- This file summarizes the current operational contract for AI agents, automation scripts, and contributors.
3
+ This file is the current AI-facing fact sheet for `@minniexcode/codex-switch`.
4
4
 
5
- ## Package Context
5
+ Current repository version: `0.2.1`
6
6
 
7
- - Package: `@minniexcode/codex-switch`
8
- - CLI name: `codexs`
9
- - Current repository version: `0.1.5`
10
- - Version status: development line
11
- - Runtime contract target: Codex `0.134.0+`
7
+ Current fact sources:
12
8
 
13
- ## Product Role
9
+ - `docs/PRD/codex-switch-prd-v0.2.1.md`
10
+ - `docs/Design/codex-switch-v0.2.1-design.md`
11
+ - `docs/cli-usage.md`
14
12
 
15
- `codex-switch` is a local-first TypeScript CLI that manages provider and model-provider routing state for Codex while keeping tool-managed state separate from the target Codex runtime.
13
+ ## Product Positioning
16
14
 
17
- The managed source of truth is the tool home. Runtime files under the target Codex directory are projected outputs, not the main registry.
15
+ `codex-switch` is a local-first provider/model-provider management CLI for Codex. It manages local provider records, projects Codex `model_provider` sections, writes the active top-level `model` / `model_provider` route, and maintains backups around mutating commands.
18
16
 
19
- ## Primary Workflows
17
+ Do not describe the current product as a direct-vs-Copilot dual path. In `0.2.1`, there is only the provider-management workflow for OpenAI-compatible provider endpoints.
20
18
 
21
- Direct provider workflow:
19
+ ## Primary Workflow
22
20
 
23
21
  ```bash
24
22
  codexs init
@@ -28,70 +26,47 @@ codexs status
28
26
  codexs doctor
29
27
  ```
30
28
 
31
- GitHub Copilot workflow:
29
+ `--profile` means managed `model_provider` id alias. It is not the legacy Codex top-level `profile` selector.
32
30
 
33
- ```bash
34
- codexs init
35
- codexs login copilot
36
- codexs add <provider> --copilot --profile <model-provider-id> --model <model>
37
- codexs switch <provider>
38
- codexs status
39
- codexs doctor
40
- ```
41
-
42
- Advanced adopt workflow:
43
-
44
- ```bash
45
- codexs init
46
- codexs migrate
47
- ```
48
-
49
- `migrate` is not a fresh-install default. It is an advanced adopt helper for existing runtime state.
50
-
51
- ## Runtime Route Contract
52
-
53
- For Codex `0.134.0+`, the live route is selected by:
31
+ ## Current Command Surface
54
32
 
55
- - top-level `model`
56
- - top-level `model_provider`
57
-
58
- Important implications for automation:
59
-
60
- - treat `model_provider` as the active provider selector
61
- - treat `--profile` as an alias for a managed `model_provider` id
62
- - do not describe top-level `profile` or `[profiles.*]` as the primary runtime path
63
- - managed direct-provider projection does not keep `env_key` or `env_key_instructions`
64
- - managed provider projection fixes `wire_api = "responses"` and `requires_openai_auth = true`
33
+ Document only these current commands:
65
34
 
66
- Expected managed direct-provider projection:
67
-
68
- ```toml
69
- model = "gpt-5.5"
70
- model_provider = "proxy"
71
-
72
- [model_providers.proxy]
73
- name = "proxy"
74
- base_url = "https://proxy.example.com/v1"
75
- wire_api = "responses"
76
- requires_openai_auth = true
35
+ ```text
36
+ init
37
+ migrate
38
+ list
39
+ show
40
+ current
41
+ status
42
+ config show
43
+ config list-profiles
44
+ add
45
+ edit
46
+ switch
47
+ remove
48
+ import
49
+ export
50
+ backups list
51
+ rollback
52
+ doctor
53
+ setup
77
54
  ```
78
55
 
79
- Authentication remains projected through `auth.json` with `OPENAI_API_KEY`.
56
+ `setup` is deprecated and only points callers to `init` or `migrate`.
80
57
 
81
- ## Important Paths
58
+ ## State Model
82
59
 
83
60
  Tool home:
84
61
 
85
62
  ```text
86
- ~/.config/codex-switch/
63
+ ~/.codex-switch/
87
64
  codex-switch.json
88
65
  providers.json
89
66
  backups/
90
- runtime/
91
- runtimes/
92
67
  ```
93
68
 
94
- Target Codex runtime:
69
+ Target Codex directory:
95
70
 
96
71
  ```text
97
72
  ~/.codex/
@@ -99,45 +74,42 @@ Target Codex runtime:
99
74
  auth.json
100
75
  ```
101
76
 
102
- Operational meaning:
77
+ Managed projection for current Codex versions is route-first:
103
78
 
104
- - `providers.json` is the managed provider registry.
105
- - `codex-switch.json` stores tool-level metadata such as the default target Codex directory.
106
- - `config.toml` is the active runtime routing file.
107
- - `auth.json` is the active auth projection file.
79
+ - top-level `model`
80
+ - top-level `model_provider`
81
+ - matching `[model_providers.<id>]`
82
+ - API-key auth projection in `auth.json`
108
83
 
109
- ## Command Notes
84
+ Do not present top-level `profile` or `[profiles.*]` as the current managed runtime path. They may be inspected for adoption or legacy diagnostics only.
110
85
 
111
- Shared flags:
86
+ ## Current Non-Goals
112
87
 
113
- ```bash
114
- --json
115
- --codex-dir <path>
116
- --help
117
- --version
118
- ```
88
+ `0.2.1` does not include:
119
89
 
120
- Relevant environment variables:
90
+ - Copilot SDK integration.
91
+ - GitHub device-flow login.
92
+ - `login copilot`.
93
+ - `add --copilot`.
94
+ - `bridge start`, `bridge status`, or `bridge stop`.
95
+ - HTTP proxy bridge or local bridge worker runtime.
96
+ - `runtime/` or `runtimes/` managed service directories.
97
+ - Bridge logs or bridge runtime state.
98
+ - Built-in third-party router packaging.
99
+ - Automatic migration of old Copilot or bridge state.
121
100
 
122
- ```bash
123
- CODEXS_HOME
124
- CODEXS_CODEX_DIR
125
- ```
101
+ A future release may integrate a third-party router-like capability. Do not write current commands, schema, or runtime paths for that in `0.2.1` docs or code.
126
102
 
127
- Important behavioral constraints:
103
+ ## Development-Version Policy
128
104
 
129
- - Prefer `--json` for programmatic invocation whenever the command supports it.
130
- - `login copilot` requires a real TTY and does not support `--json`.
131
- - `login copilot` currently installs the local Copilot SDK when needed, tries the bundled runtime CLI first, falls back to `PATH` when necessary, and rechecks auth readiness before reporting success.
132
- - `add --copilot` assumes SDK install and upstream Copilot auth are already ready.
133
- - Non-interactive automation should pass `--profile` explicitly. In TTY mode, `add` and `edit` can prompt for missing required fields.
134
- - `migrate` remains interactive when provider adoption requires human input.
135
- - `status` is the main dual-path summary command.
136
- - `doctor` is the deeper repair-oriented diagnostic command.
137
- - The current `0.1.5` line focuses on Copilot Bridge process visibility, Responses commentary/reasoning stream events, defensive SDK-event normalization, and unknown-event redaction hardening rather than command-surface expansion.
105
+ Treat `0.2.1` as development-version software unless the user explicitly declares a real release. Do not add automatic migration shims, dual-read/dual-write behavior, or compatibility preservation for old experimental local state unless asked in the current task.
138
106
 
139
- ## Safety Notes
107
+ ## Verification Commands
140
108
 
141
- - Treat `providers.json` as sensitive because it may contain API keys.
142
- - Human-readable output may mask secrets, but JSON output can expose full provider payloads.
143
- - Managed write operations rely on backup and rollback flow; do not describe manual file edits as the primary workflow.
109
+ ```bash
110
+ npx tsc --noEmit
111
+ npm test
112
+ node dist/cli.js --help
113
+ node dist/cli.js --version
114
+ npm pack --dry-run
115
+ ```
package/README.CN.md CHANGED
@@ -1,153 +1,108 @@
1
- # @minniexcode/codex-switch
1
+ # codex-switch
2
2
 
3
- `@minniexcode/codex-switch` 是一个本地优先的 CLI,用来安全地管理和切换 Codex providermodel-provider 路由配置。
3
+ `@minniexcode/codex-switch` 是一个本地优先的 Codex provider/model-provider 管理 CLI。
4
4
 
5
- 它把 `codex-switch` 自己的工具状态和目标 Codex runtime 明确分开,让 provider 管理、备份与 runtime 投影有一套受管流程,而不是依赖手工改文件。
5
+ 它把 `codex-switch` 自己的工具状态和目标 Codex 目录分开,让 provider 管理、备份和 `model_provider` 投影通过明确命令完成,而不是手工编辑文件。
6
6
 
7
- ## 版本定位
7
+ 当前包版本:`0.2.1`
8
8
 
9
- 当前包版本:`0.1.5`
10
-
11
- 这是当前仓库开发线。`0.1.5` 是 Copilot Bridge 过程可见性补丁,聚焦于 commentary/reasoning 流式信号、SDK 事件防御性归一化,以及未知运行态事件的更安全脱敏,同时不扩展 provider 命令面。
9
+ `0.2.1` 是当前仓库开发线,也是 provider-management-only 收敛版本:只管理本地 OpenAI-compatible provider 记录,并把它们投影到 Codex `config.toml` / `auth.json`。本版本不包含之前实验过的账号登录、本地 bridge 或后台 runtime 能力。
12
10
 
13
11
  ## 安装
14
12
 
15
13
  ```bash
16
14
  npm install -g @minniexcode/codex-switch
15
+ codexs --help
17
16
  ```
18
17
 
19
- 不全局安装时也可以直接运行:
18
+ 本地开发:
20
19
 
21
20
  ```bash
22
- npx @minniexcode/codex-switch --help
21
+ npm install
22
+ npm run build
23
+ node dist/cli.js --help
23
24
  ```
24
25
 
25
- CLI 命令名:
26
-
27
- ```bash
28
- codexs --help
29
- ```
26
+ 需要 Node.js `>=18`。
30
27
 
31
28
  ## 主工作流
32
29
 
33
- Direct provider 主路径:
34
-
35
- ```bash
36
- codexs init
37
- codexs add my-provider --profile my-provider --model gpt-5.5 --base-url https://gateway.example.com/v1 --api-key sk-xxx
38
- codexs switch my-provider
39
- codexs status
40
- codexs doctor
41
- ```
42
-
43
- GitHub Copilot 主路径:
44
-
45
30
  ```bash
46
31
  codexs init
47
- codexs login copilot
48
- codexs add copilot-main --copilot --profile copilot-main --model gpt-4.1
49
- codexs switch copilot-main
32
+ codexs add packycode --profile packycode --model gpt-5 --api-key sk-xxx --base-url https://api.example/v1
33
+ codexs switch packycode
50
34
  codexs status
51
35
  codexs doctor
52
36
  ```
53
37
 
54
- 说明:
55
-
56
- - `init` 负责初始化 `codex-switch` tool home 与受管状态文件。
57
- - `login copilot` 负责上游 Copilot onboarding 和登录可用性检查。
58
- - `add --copilot` 不负责替你登录,它假设上游 Copilot 已经 ready。
59
- - 非交互调用请显式传入 `--profile`;在 TTY 模式下,`add` 和 `edit` 可以补问缺失的必填项。
60
- - `switch` 会把选中的 provider 投影到目标 Codex runtime 的顶层 `model` 与 `model_provider`。
61
- - `status` 是切换后的主读取命令。
62
- - `doctor` 是主诊断命令,用于解释问题和下一步修复动作。
63
-
64
- ## Runtime 路由模型
65
-
66
- 对于 Codex `0.134.0+`,活动 runtime route 由 `config.toml` 顶层的 `model` 和 `model_provider` 决定。
67
-
68
- `codex-switch` 按这套 contract 管理运行态:
69
-
70
- - 顶层 `model` 表示当前活动模型
71
- - 顶层 `model_provider` 表示当前活动 provider route
72
- - 受管的 `[model_providers.<id>]` 是 runtime provider 定义投影
73
- - `--profile` 只作为受管 `model_provider` id 的 alias,不再是主 runtime selector
74
-
75
- Direct provider 的运行态投影会写入:
76
-
77
- - 顶层 `model`
78
- - 顶层 `model_provider`
79
- - `[model_providers.<id>]`
80
- - 带 `OPENAI_API_KEY` 的 `auth.json`
81
-
82
- 受管 direct provider 投影不会再保留 `env_key` 或 `env_key_instructions`。`switch`、`add` 和 `edit` 会在写入活动路由前清理这些旧字段。
83
-
84
- 对受管的 OpenAI-compatible route,投影后的 provider 结构固定为:
85
-
86
- ```toml
87
- model = "gpt-5.5"
88
- model_provider = "my-provider"
89
-
90
- [model_providers.my-provider]
91
- name = "my-provider"
92
- base_url = "https://gateway.example.com/v1"
93
- wire_api = "responses"
94
- requires_openai_auth = true
95
- ```
96
-
97
- ## Advanced Adopt 路径
98
-
99
- 如果你已经有现成的 Codex runtime 状态,希望把它 adopt 到受管 `providers.json`,再使用:
100
-
101
- ```bash
102
- codexs init
103
- codexs migrate
104
- ```
38
+ - `init` 创建 `codex-switch` 工具状态文件。
39
+ - `add` 在 `providers.json` 中保存受管 provider,并创建或更新对应 `[model_providers.<id>]`。
40
+ - `switch` 写入目标 Codex 配置的顶层 `model` / `model_provider`,并把 `OPENAI_API_KEY` 投影到 `auth.json`。
41
+ - `status` 汇总当前映射、认证投影和漂移状态。
42
+ - `doctor` 输出问题优先的诊断结果。
105
43
 
106
- `migrate` 是高级 adopt helper,不是 fresh install 的默认第一步。
44
+ `--profile` 是受管 Codex `model_provider` id CLI alias,不是旧 Codex 顶层 `profile` selector。
107
45
 
108
46
  ## 命令面
109
47
 
110
- ```bash
48
+ `0.2.1` 当前命令:
49
+
50
+ ```text
111
51
  codexs init
112
- codexs login copilot
113
52
  codexs migrate
114
53
  codexs list
115
54
  codexs show <provider>
116
55
  codexs current
117
56
  codexs status
118
- codexs config show [profile]
57
+ codexs config show
119
58
  codexs config list-profiles
120
59
  codexs add <provider> --profile <model-provider-id> --model <model> --api-key <key> [--base-url <url>]
121
- codexs add <provider> --copilot --profile <model-provider-id> --model <model>
122
- codexs edit <provider>
60
+ codexs edit <provider> [options]
123
61
  codexs switch <provider>
124
- codexs remove <provider> [--force] [--switch-to <provider>]
62
+ codexs remove <provider> --force
125
63
  codexs import <file>
126
- codexs export <file> [--force]
127
- codexs bridge start [provider]
128
- codexs bridge status [provider]
129
- codexs bridge stop [provider]
64
+ codexs export <file>
130
65
  codexs backups list
131
66
  codexs rollback [backup-id]
132
67
  codexs doctor
68
+ codexs setup
69
+ ```
70
+
71
+ `setup` 已废弃,只保留为指向 `init` 或 `migrate` 的兼容入口。
72
+
73
+ ## Runtime 投影
74
+
75
+ Codex `0.134.0+` 的活动路由由 `config.toml` 顶层 `model` 和 `model_provider` 决定。
76
+
77
+ 受管 provider 的投影形态:
78
+
79
+ ```toml
80
+ model = "gpt-5"
81
+ model_provider = "packycode"
82
+
83
+ [model_providers.packycode]
84
+ name = "packycode"
85
+ base_url = "https://api.example/v1"
86
+ wire_api = "responses"
87
+ requires_openai_auth = true
133
88
  ```
134
89
 
135
- `setup` 仍然存在,但只作为已弃用兼容入口,用来提示调用方改用 `init` `migrate`。
90
+ `codex-switch` 不为新受管 provider 写入旧 `[profiles.*]`,并会在写入受管投影时清理旧 `env_key` / `env_key_instructions` 字段。
136
91
 
137
- ## 双路径模型
92
+ 认证会投影到目标 Codex `auth.json`,使用 API-key 模式和 `OPENAI_API_KEY`。不要提交真实 API key、`auth.json` 或私有 provider 导出。
138
93
 
139
- tool home:
94
+ ## 状态位置
95
+
96
+ 工具 home:
140
97
 
141
98
  ```text
142
- ~/.config/codex-switch/
99
+ ~/.codex-switch/
143
100
  codex-switch.json
144
101
  providers.json
145
102
  backups/
146
- runtime/
147
- runtimes/
148
103
  ```
149
104
 
150
- 目标 Codex runtime:
105
+ 目标 Codex 目录:
151
106
 
152
107
  ```text
153
108
  ~/.codex/
@@ -155,64 +110,54 @@ tool home:
155
110
  auth.json
156
111
  ```
157
112
 
158
- 关键边界:
113
+ 环境变量:
159
114
 
160
- - `providers.json` 是受管 provider 注册表,位于 tool home。
161
- - `codex-switch.json` 保存工具级元数据,例如 `defaultCodexDir`。
162
- - `config.toml` 仍然是目标 runtime 里的活动路由文件。
163
- - `auth.json` 仍然是目标 runtime 里的活动认证投影文件。
164
- - Direct provider 切换会改写活动 runtime 中的 `OPENAI_API_KEY`。
165
- - Copilot provider 保持上游 GitHub 登录留在官方 Copilot runtime 中,`codex-switch` 只管理本地 bridge 状态与路由。
115
+ - `CODEXS_HOME` 覆盖 `codex-switch` 工具 home。
116
+ - `CODEXS_CODEX_DIR` 在未传 `--codex-dir` 时提供默认目标 Codex 目录。
117
+ - 开发环境下,`NODE_ENV=development` 且没有显式覆盖时默认使用 `./dev-codex/local-sandbox`。
166
118
 
167
- 路径控制:
119
+ ## 迁移与采用
168
120
 
169
- - `--codex-dir <path>` 显式指定目标 Codex runtime 目录。
170
- - `CODEXS_CODEX_DIR` 在未传 `--codex-dir` 时提供默认目标目录。
171
- - `CODEXS_HOME` 用于覆盖 tool home 位置。
121
+ 只有当你已经有 Codex 配置,并希望把它 adopt 到受管 `providers.json` 时才使用 `migrate`。新安装默认使用 `init`。
172
122
 
173
- ## 自动化说明
123
+ ```bash
124
+ codexs migrate
125
+ codexs migrate --overwrite --codex-dir ~/.codex
126
+ ```
174
127
 
175
- 这个 CLI 同时支持人类终端使用和非交互自动化。
128
+ 本仓库按开发版本处理,包括 `0.2.1`。旧实验状态不会自动迁移;从旧本地实验切换过来时,请手动清理或重新添加 provider。
176
129
 
177
- 全局参数:
130
+ ## 当前非目标
178
131
 
179
- ```bash
180
- --json
181
- --codex-dir <path>
182
- --help
183
- --version
184
- ```
132
+ `0.2.1` 不实现也不预留以下 runtime 代码路径:
185
133
 
186
- 当前实现边界:
134
+ - GitHub Copilot SDK 集成。
135
+ - GitHub device-flow 登录。
136
+ - `login copilot`。
137
+ - `add --copilot`。
138
+ - HTTP proxy bridge 或本地 bridge worker 命令。
139
+ - 后台 runtime service、bridge log 或 bridge runtime state。
140
+ - 内置第三方 router 封装。
141
+ - 账号系统或云同步。
142
+ - 旧 Copilot / bridge 状态的自动迁移。
187
143
 
188
- - `login copilot` 必须运行在真实 TTY 下,不支持 `--json`。
189
- - `migrate` 在需要人工补齐 adopt 信息时仍然保持交互式语义。
190
- - 自动化调用应尽量显式传参,并优先使用 `--json`。
144
+ 未来版本可能接入类似第三方 router 的能力,但 `0.2.1` 不承诺工作流、schema runtime 行为。
191
145
 
192
- ## 本地开发
146
+ ## 开发
193
147
 
194
148
  ```bash
195
149
  npm run build
196
- npm test
197
150
  npx tsc --noEmit
151
+ npm test
198
152
  node dist/cli.js --help
153
+ node dist/cli.js --version
199
154
  npm pack --dry-run
200
155
  ```
201
156
 
202
- ## 相关文档
203
-
204
- - [English README](./README.md)
205
- - [AI README](./README.AI.md)
206
- - [详细 CLI 文档](./docs/cli-usage.md)
207
- - [产品概览](./docs/codex-switch-product-overview.md)
208
- - [测试说明](./docs/Tests/testing.md)
209
- - [PRD 0.1.1](./docs/PRD/codex-switch-prd-v0.1.1.md)
210
- - [Design 0.1.1](./docs/Design/codex-switch-v0.1.1-design.md)
211
- - [PRD 0.1.2](./docs/PRD/codex-switch-prd-v0.1.2.md)
212
- - [Design 0.1.2](./docs/Design/codex-switch-v0.1.2-design.md)
213
- - [PRD 0.1.5](./docs/PRD/codex-switch-prd-v0.1.5.md)
214
- - [Design 0.1.5](./docs/Design/codex-switch-v0.1.5-design.md)
157
+ ## 当前事实源
215
158
 
216
- ## License
159
+ - [PRD 0.2.1](./docs/PRD/codex-switch-prd-v0.2.1.md)
160
+ - [Design 0.2.1](./docs/Design/codex-switch-v0.2.1-design.md)
161
+ - [CLI usage](./docs/cli-usage.md)
217
162
 
218
- MIT
163
+ 旧 `0.1.x` / `0.2.0` 文档保留为历史记录。