@minniexcode/codex-switch 0.0.10 → 0.0.11
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 +52 -15
- package/README.CN.md +81 -48
- package/README.md +75 -34
- package/dist/app/add-provider.js +29 -15
- package/dist/app/bridge.js +15 -14
- package/dist/app/edit-provider.js +1 -1
- package/dist/app/get-status.js +13 -6
- package/dist/app/import-providers.js +1 -1
- package/dist/app/init-codex.js +13 -14
- package/dist/app/remove-provider.js +1 -1
- package/dist/app/run-doctor.js +12 -5
- package/dist/app/run-mutation.js +3 -2
- package/dist/app/setup-codex.js +3 -1
- package/dist/app/switch-provider.js +11 -13
- package/dist/cli.js +34 -2
- package/dist/commands/args.js +2 -2
- package/dist/commands/dispatch.js +40 -0
- package/dist/commands/handlers.js +121 -156
- package/dist/commands/help.js +2 -0
- package/dist/commands/registry.js +28 -9
- package/dist/domain/backups.js +4 -4
- package/dist/domain/config.js +110 -5
- package/dist/domain/providers.js +12 -0
- package/dist/domain/runtime-state.js +81 -5
- package/dist/runtime/copilot-adapter.js +12 -12
- package/dist/runtime/copilot-bridge.js +392 -44
- package/dist/runtime/copilot-cli.js +84 -12
- package/dist/runtime/copilot-installer.js +10 -9
- package/dist/runtime/copilot-sdk-loader.js +5 -5
- package/dist/storage/backup-repo.js +4 -4
- package/dist/storage/codex-paths.js +34 -8
- package/dist/storage/lock-repo.js +2 -4
- package/dist/storage/runtime-state-repo.js +14 -13
- package/dist/storage/tool-config-repo.js +111 -0
- package/docs/Design/codex-switch-v0.0.11-design.md +824 -0
- package/docs/PRD/codex-switch-prd-v0.0.11.md +577 -0
- package/docs/cli-usage.md +166 -295
- package/package.json +1 -1
package/README.AI.md
CHANGED
|
@@ -4,7 +4,7 @@ This file is for AI agents, automation scripts, and contributors who need a comp
|
|
|
4
4
|
|
|
5
5
|
## Repository Purpose
|
|
6
6
|
|
|
7
|
-
`@minniexcode/codex-switch` is a local-first TypeScript CLI for managing provider/profile state for Codex
|
|
7
|
+
`@minniexcode/codex-switch` is a local-first TypeScript CLI for managing provider/profile state for Codex while keeping codex-switch tool state separate from the target Codex runtime.
|
|
8
8
|
|
|
9
9
|
Primary goals:
|
|
10
10
|
|
|
@@ -13,22 +13,29 @@ Primary goals:
|
|
|
13
13
|
- rollback on failure
|
|
14
14
|
- stable machine-readable CLI output
|
|
15
15
|
- support for both human TTY usage and agent automation
|
|
16
|
+
- explicit onboarding for interactive upstreams such as GitHub Copilot
|
|
16
17
|
|
|
17
18
|
## Main Command Surface
|
|
18
19
|
|
|
19
20
|
```bash
|
|
20
21
|
codexs init
|
|
22
|
+
codexs login copilot
|
|
21
23
|
codexs migrate
|
|
22
24
|
codexs list
|
|
23
25
|
codexs show <provider>
|
|
24
26
|
codexs current
|
|
25
27
|
codexs status
|
|
28
|
+
codexs config show [profile]
|
|
29
|
+
codexs config list-profiles
|
|
26
30
|
codexs edit <provider>
|
|
27
31
|
codexs switch <provider>
|
|
28
32
|
codexs import <file>
|
|
29
33
|
codexs export <file>
|
|
30
34
|
codexs add <provider>
|
|
31
35
|
codexs remove <provider>
|
|
36
|
+
codexs bridge start [provider]
|
|
37
|
+
codexs bridge status [provider]
|
|
38
|
+
codexs bridge stop [provider]
|
|
32
39
|
codexs backups list
|
|
33
40
|
codexs doctor
|
|
34
41
|
codexs rollback [backup-id]
|
|
@@ -41,23 +48,43 @@ Shared flags:
|
|
|
41
48
|
--codex-dir <path>
|
|
42
49
|
```
|
|
43
50
|
|
|
44
|
-
|
|
51
|
+
Relevant environment variables:
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
CODEXS_HOME
|
|
55
|
+
CODEXS_CODEX_DIR
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## Important Files
|
|
59
|
+
|
|
60
|
+
Tool home:
|
|
61
|
+
|
|
62
|
+
```text
|
|
63
|
+
~/.config/codex-switch/
|
|
64
|
+
codex-switch.json
|
|
65
|
+
providers.json
|
|
66
|
+
backups/
|
|
67
|
+
runtime/
|
|
68
|
+
runtimes/
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
Target Codex runtime:
|
|
45
72
|
|
|
46
73
|
```text
|
|
47
74
|
~/.codex/
|
|
48
75
|
config.toml
|
|
49
76
|
auth.json
|
|
50
|
-
providers.json
|
|
51
|
-
backups/
|
|
52
77
|
```
|
|
53
78
|
|
|
54
79
|
Operational model:
|
|
55
80
|
|
|
56
81
|
- `providers.json` is the management-state source of truth
|
|
57
|
-
- `
|
|
58
|
-
- `
|
|
59
|
-
- `
|
|
60
|
-
-
|
|
82
|
+
- `codex-switch.json` stores tool-level metadata such as `defaultCodexDir`
|
|
83
|
+
- `config.toml` remains the managed runtime-routing file in the target Codex directory
|
|
84
|
+
- `auth.json` remains the active auth projection file
|
|
85
|
+
- `runtime/` stores managed bridge runtime state
|
|
86
|
+
- `runtimes/` stores optional local runtimes such as the Copilot SDK install
|
|
87
|
+
- mutating commands back up first and run under a lightweight file lock in the tool home
|
|
61
88
|
|
|
62
89
|
## Project Structure
|
|
63
90
|
|
|
@@ -65,8 +92,11 @@ Operational model:
|
|
|
65
92
|
src/
|
|
66
93
|
app/
|
|
67
94
|
cli/
|
|
95
|
+
commands/
|
|
68
96
|
domain/
|
|
69
|
-
|
|
97
|
+
interaction/
|
|
98
|
+
runtime/
|
|
99
|
+
storage/
|
|
70
100
|
tests/
|
|
71
101
|
docs/
|
|
72
102
|
dist/
|
|
@@ -74,10 +104,13 @@ dist/
|
|
|
74
104
|
|
|
75
105
|
Layer intent:
|
|
76
106
|
|
|
77
|
-
- `cli`:
|
|
107
|
+
- `cli`: output shaping and thin CLI-facing utilities
|
|
108
|
+
- `commands`: argument parsing, help rendering, and command dispatch
|
|
78
109
|
- `app`: command orchestration and use-case logic
|
|
79
110
|
- `domain`: pure domain rules and shared models
|
|
80
|
-
- `
|
|
111
|
+
- `interaction`: TTY-only prompt flows
|
|
112
|
+
- `runtime`: Codex/Copilot runtime probing and local bridge management
|
|
113
|
+
- `storage`: filesystem-backed repositories and path resolution
|
|
81
114
|
|
|
82
115
|
## Command Entry Point
|
|
83
116
|
|
|
@@ -87,6 +120,7 @@ Use `codexs` directly for runtime interaction:
|
|
|
87
120
|
codexs --help
|
|
88
121
|
codexs list --json
|
|
89
122
|
codexs status --json
|
|
123
|
+
codexs config list-profiles --json
|
|
90
124
|
```
|
|
91
125
|
|
|
92
126
|
## Current Version Context
|
|
@@ -94,13 +128,14 @@ codexs status --json
|
|
|
94
128
|
Current package version in this repository:
|
|
95
129
|
|
|
96
130
|
```text
|
|
97
|
-
0.0.
|
|
131
|
+
0.0.11
|
|
98
132
|
```
|
|
99
133
|
|
|
100
134
|
Recent version summary:
|
|
101
135
|
|
|
102
|
-
- `0.0.
|
|
103
|
-
- `0.0.
|
|
136
|
+
- `0.0.11`: tool-home split, `login copilot`, managed bridge commands, and config inspection commands
|
|
137
|
+
- `0.0.10`: `init` / `migrate` command split finalized and `setup` deprecated
|
|
138
|
+
- `0.0.7`: command-surface refactor and setup split groundwork
|
|
104
139
|
- `0.0.4`: setup/show/edit/backups list/specific rollback/import merge and clearer CLI semantics
|
|
105
140
|
- `0.0.3`: interactive TTY flows and improved help
|
|
106
141
|
- `0.0.2`: mutation orchestration, backups, rollback, locks, drift detection improvements
|
|
@@ -111,5 +146,7 @@ Recent version summary:
|
|
|
111
146
|
- Prefer `--json` when invoking commands programmatically
|
|
112
147
|
- Treat `providers.json` as sensitive because it may contain API keys
|
|
113
148
|
- Do not assume silent write-back from runtime files into `providers.json`
|
|
114
|
-
- Prefer `init` for repeatable
|
|
149
|
+
- Prefer `init` for repeatable tool-home setup and `migrate` for human-led adopt flows
|
|
150
|
+
- `login copilot` requires a real TTY and should not be used under `--json`
|
|
151
|
+
- `add --copilot` assumes SDK install and upstream auth readiness are already satisfied
|
|
115
152
|
- Use `docs/` for deeper product and architecture context
|
package/README.CN.md
CHANGED
|
@@ -2,55 +2,58 @@
|
|
|
2
2
|
|
|
3
3
|
`@minniexcode/codex-switch` 是一个本地优先的 CLI,用来安全地管理和切换 Codex 的 provider/profile 配置。
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
从 `0.0.11` 开始,它不再把整个管理态都塞进 `~/.codex/`,而是把工具自己的状态拆到独立的 tool home 里,同时继续对目标 Codex runtime 做受控写入。
|
|
6
6
|
|
|
7
7
|
## 这个仓库是做什么的
|
|
8
8
|
|
|
9
9
|
这个仓库包含 `codex-switch` 的 CLI 实现、npm 包配置,以及相关产品和技术文档。
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
项目目标:
|
|
12
12
|
|
|
13
|
-
- 在本地完成
|
|
13
|
+
- 在本地完成 provider/profile 管理与切换
|
|
14
14
|
- 写入前先备份
|
|
15
15
|
- 出错时可回滚
|
|
16
16
|
- 同时兼顾终端用户和 AI/自动化调用
|
|
17
|
+
- 为 GitHub Copilot 这类交互式上游登录提供独立入口
|
|
17
18
|
|
|
18
19
|
## 现在可以做什么
|
|
19
20
|
|
|
20
|
-
|
|
21
|
+
当前公开命令面如下:
|
|
21
22
|
|
|
22
23
|
```bash
|
|
23
24
|
codexs init
|
|
25
|
+
codexs login copilot
|
|
24
26
|
codexs migrate
|
|
25
27
|
codexs list
|
|
26
28
|
codexs show <provider>
|
|
27
29
|
codexs current
|
|
28
30
|
codexs status
|
|
31
|
+
codexs config show [profile]
|
|
32
|
+
codexs config list-profiles
|
|
29
33
|
codexs edit <provider>
|
|
30
34
|
codexs switch <provider>
|
|
31
35
|
codexs import <file>
|
|
32
36
|
codexs export <file>
|
|
33
37
|
codexs add <provider>
|
|
34
38
|
codexs remove <provider>
|
|
39
|
+
codexs bridge start [provider]
|
|
40
|
+
codexs bridge status [provider]
|
|
41
|
+
codexs bridge stop [provider]
|
|
35
42
|
codexs backups list
|
|
36
43
|
codexs doctor
|
|
37
|
-
codexs rollback
|
|
44
|
+
codexs rollback [backup-id]
|
|
38
45
|
codexs setup
|
|
39
46
|
```
|
|
40
47
|
|
|
41
48
|
对应能力包括:
|
|
42
49
|
|
|
43
|
-
-
|
|
50
|
+
- 初始化独立的 tool home 与空的受管 `providers.json`
|
|
44
51
|
- 从已有 `config.toml` adopt 可管理的 runtime profile
|
|
45
|
-
-
|
|
46
|
-
-
|
|
47
|
-
-
|
|
48
|
-
-
|
|
49
|
-
-
|
|
50
|
-
- 安全切换 provider
|
|
51
|
-
- 导入和导出 provider 映射
|
|
52
|
-
- 新增和删除 provider
|
|
53
|
-
- 查看备份列表
|
|
52
|
+
- 查看本地已管理 provider
|
|
53
|
+
- 查看结构化 config profile 视图
|
|
54
|
+
- 编辑、切换、导入、导出、删除 provider
|
|
55
|
+
- 为 GitHub Copilot 完成上游 SDK 安装与登录检查
|
|
56
|
+
- 显式启动、查看和停止本地 Copilot bridge
|
|
54
57
|
- 检查配置漂移和常见本地问题
|
|
55
58
|
- 在变更前自动备份,并在失败时回滚
|
|
56
59
|
- 保留 `setup` 作为弃用入口,并引导到 `init` / `migrate`
|
|
@@ -81,17 +84,26 @@ codexs --help
|
|
|
81
84
|
codexs init
|
|
82
85
|
codexs migrate
|
|
83
86
|
codexs list
|
|
84
|
-
codexs
|
|
87
|
+
codexs config show
|
|
85
88
|
codexs add my-provider --profile my-provider --api-key sk-xxx
|
|
86
89
|
codexs switch my-provider
|
|
87
90
|
codexs status
|
|
88
91
|
```
|
|
89
92
|
|
|
93
|
+
GitHub Copilot 路径:
|
|
94
|
+
|
|
95
|
+
```bash
|
|
96
|
+
codexs login copilot
|
|
97
|
+
codexs add copilot-main --copilot --profile copilot-main
|
|
98
|
+
codexs bridge start copilot-main
|
|
99
|
+
```
|
|
100
|
+
|
|
90
101
|
给脚本或 AI 使用时建议加上:
|
|
91
102
|
|
|
92
103
|
```bash
|
|
93
104
|
codexs list --json
|
|
94
105
|
codexs status --json
|
|
106
|
+
codexs config list-profiles --json
|
|
95
107
|
```
|
|
96
108
|
|
|
97
109
|
通用参数:
|
|
@@ -101,6 +113,13 @@ codexs status --json
|
|
|
101
113
|
--codex-dir <path>
|
|
102
114
|
```
|
|
103
115
|
|
|
116
|
+
环境变量:
|
|
117
|
+
|
|
118
|
+
```bash
|
|
119
|
+
CODEXS_HOME
|
|
120
|
+
CODEXS_CODEX_DIR
|
|
121
|
+
```
|
|
122
|
+
|
|
104
123
|
## 交互式体验
|
|
105
124
|
|
|
106
125
|
这个 CLI 同时支持显式命令和交互式终端流程。
|
|
@@ -109,64 +128,77 @@ codexs status --json
|
|
|
109
128
|
- `codexs switch` 在未传 provider 时可以弹出选择列表
|
|
110
129
|
- `codexs remove` 支持交互式选择和确认删除
|
|
111
130
|
- `import`、`export`、`rollback` 在交互模式下会要求确认
|
|
131
|
+
- `login copilot` 必须在真实 TTY 中执行
|
|
132
|
+
- `migrate` 当前仍保留交互式 adopt 语义
|
|
112
133
|
- `--json` 模式保持非交互,适合自动化
|
|
113
134
|
|
|
114
135
|
## 管理哪些文件
|
|
115
136
|
|
|
116
|
-
`codex-switch`
|
|
137
|
+
从 `0.0.11` 开始,`codex-switch` 使用双路径模型。
|
|
138
|
+
|
|
139
|
+
tool home:
|
|
140
|
+
|
|
141
|
+
```text
|
|
142
|
+
~/.config/codex-switch/
|
|
143
|
+
codex-switch.json
|
|
144
|
+
providers.json
|
|
145
|
+
backups/
|
|
146
|
+
runtime/
|
|
147
|
+
runtimes/
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
目标 Codex runtime:
|
|
117
151
|
|
|
118
152
|
```text
|
|
119
153
|
~/.codex/
|
|
120
154
|
config.toml
|
|
121
155
|
auth.json
|
|
122
|
-
providers.json
|
|
123
|
-
backups/
|
|
124
156
|
```
|
|
125
157
|
|
|
126
158
|
存储模型:
|
|
127
159
|
|
|
128
|
-
- `providers.json`
|
|
129
|
-
- `
|
|
130
|
-
- `
|
|
160
|
+
- `providers.json` 是管理态的单一事实来源,位于 tool home
|
|
161
|
+
- `codex-switch.json` 存放工具级配置,例如 `defaultCodexDir`
|
|
162
|
+
- `config.toml` 是目标 Codex runtime 的受管路由文件
|
|
163
|
+
- `auth.json` 是当前认证投影文件
|
|
131
164
|
- `backups/latest.json` 记录最近一次可回滚窗口
|
|
165
|
+
- `runtime/` 保存受管 bridge runtime state
|
|
166
|
+
- `runtimes/` 用于存放可选本地 runtime,例如 Copilot SDK
|
|
132
167
|
|
|
133
|
-
注意:`providers.json` 可能包含 API key
|
|
168
|
+
注意:`providers.json` 可能包含 API key,本地使用时应视为敏感文件。
|
|
134
169
|
|
|
135
|
-
##
|
|
170
|
+
## 最近版本更新
|
|
136
171
|
|
|
137
|
-
|
|
138
|
-
- [AI README](./README.AI.md)
|
|
139
|
-
- [产品概览](./docs/codex-switch-product-overview.md)
|
|
140
|
-
- [产品调研](./docs/codex-switch-product-research.md)
|
|
141
|
-
- [PRD](./docs/codex-switch-prd.md)
|
|
142
|
-
- [技术架构](./docs/codex-switch-technical-architecture.md)
|
|
143
|
-
- [命令设计](./docs/codex-switch-command-design.md)
|
|
172
|
+
### 0.0.11
|
|
144
173
|
|
|
145
|
-
|
|
174
|
+
- 引入独立 tool home,正式把管理态从 `~/.codex` 中拆出
|
|
175
|
+
- 新增 `login copilot`,把 GitHub Copilot 上游登录从 `add --copilot` 中解耦
|
|
176
|
+
- 新增 `bridge start/status/stop` 与 `config show/list-profiles`
|
|
177
|
+
- README、CLI usage 和发布元数据统一按新命令契约更新
|
|
146
178
|
|
|
147
179
|
### 0.0.10
|
|
148
180
|
|
|
149
181
|
- 正式拆分 `setup`:新增 `init` 和 `migrate`,`setup` 变为弃用命令
|
|
150
|
-
-
|
|
151
|
-
- 清理 provider/runtime 管理语义,CLI
|
|
182
|
+
- 收紧迁移、诊断、回滚和发布正确性边界
|
|
183
|
+
- 清理 provider/runtime 管理语义,CLI 聚焦静态 profile 与 `base_url` 层配置
|
|
152
184
|
|
|
153
|
-
### 0.0.
|
|
185
|
+
### 0.0.7
|
|
154
186
|
|
|
155
|
-
-
|
|
156
|
-
-
|
|
157
|
-
-
|
|
187
|
+
- 完成 command-surface 重构
|
|
188
|
+
- 校正 env key / auth mirror 相关模型
|
|
189
|
+
- 推进 `setup` 向 `init` + `migrate` 的拆分
|
|
158
190
|
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
- 增加了统一的变更编排能力,包括写前备份、失败回滚和单进程锁
|
|
162
|
-
- 改进了 `status` 和 `doctor`,更清晰地识别运行态漂移
|
|
163
|
-
- 加强了底层仓储层和领域层,使配置写入更安全
|
|
164
|
-
|
|
165
|
-
### 0.0.1
|
|
191
|
+
## 相关文档
|
|
166
192
|
|
|
167
|
-
-
|
|
168
|
-
-
|
|
169
|
-
-
|
|
193
|
+
- [English README](./README.md)
|
|
194
|
+
- [AI README](./README.AI.md)
|
|
195
|
+
- [详细 CLI 文档](./docs/cli-usage.md)
|
|
196
|
+
- [产品概览](./docs/codex-switch-product-overview.md)
|
|
197
|
+
- [产品调研](./docs/codex-switch-product-research.md)
|
|
198
|
+
- [PRD 0.0.11](./docs/PRD/codex-switch-prd-v0.0.11.md)
|
|
199
|
+
- [技术架构](./docs/codex-switch-technical-architecture.md)
|
|
200
|
+
- [0.0.11 设计文档](./docs/Design/codex-switch-v0.0.11-design.md)
|
|
201
|
+
- [测试说明](./docs/Tests/testing.md)
|
|
170
202
|
|
|
171
203
|
## 本地开发
|
|
172
204
|
|
|
@@ -174,6 +206,7 @@ codexs status --json
|
|
|
174
206
|
npm install
|
|
175
207
|
npm run build
|
|
176
208
|
npm test
|
|
209
|
+
npx tsc --noEmit
|
|
177
210
|
node dist/cli.js --help
|
|
178
211
|
```
|
|
179
212
|
|
package/README.md
CHANGED
|
@@ -8,17 +8,20 @@ It is designed for users who work with multiple Codex providers, API keys, or pr
|
|
|
8
8
|
|
|
9
9
|
## Overview
|
|
10
10
|
|
|
11
|
-
What it does
|
|
11
|
+
What it does in `0.0.11`:
|
|
12
12
|
|
|
13
|
-
-
|
|
14
|
-
-
|
|
15
|
-
-
|
|
16
|
-
-
|
|
17
|
-
-
|
|
18
|
-
-
|
|
19
|
-
-
|
|
13
|
+
- Initializes a dedicated `codex-switch` tool home
|
|
14
|
+
- Adopts unmanaged runtime profiles from an existing Codex directory
|
|
15
|
+
- Lists, shows, adds, edits, and removes provider records
|
|
16
|
+
- Switches the active provider/profile safely
|
|
17
|
+
- Supports explicit GitHub Copilot upstream onboarding
|
|
18
|
+
- Manages the local Copilot bridge runtime explicitly
|
|
19
|
+
- Imports and exports provider definitions
|
|
20
|
+
- Runs diagnostics and detects local drift
|
|
21
|
+
- Lists backups and rolls back to a previous managed state
|
|
22
|
+
- Inspects `config.toml` profiles through structured read commands
|
|
20
23
|
|
|
21
|
-
Current version: `0.0.
|
|
24
|
+
Current version: `0.0.11`
|
|
22
25
|
|
|
23
26
|
## Install
|
|
24
27
|
|
|
@@ -42,27 +45,36 @@ codexs --help
|
|
|
42
45
|
|
|
43
46
|
## Quick Start
|
|
44
47
|
|
|
45
|
-
|
|
48
|
+
Initialize tool state and adopt an existing Codex runtime:
|
|
46
49
|
|
|
47
50
|
```bash
|
|
48
51
|
codexs init
|
|
49
52
|
codexs migrate
|
|
50
53
|
```
|
|
51
54
|
|
|
52
|
-
Inspect managed providers:
|
|
55
|
+
Inspect managed providers and config:
|
|
53
56
|
|
|
54
57
|
```bash
|
|
55
58
|
codexs list
|
|
56
59
|
codexs show my-provider
|
|
60
|
+
codexs config show
|
|
57
61
|
```
|
|
58
62
|
|
|
59
|
-
Add and switch:
|
|
63
|
+
Add and switch a direct provider:
|
|
60
64
|
|
|
61
65
|
```bash
|
|
62
66
|
codexs add my-provider --profile my-provider --api-key sk-xxx
|
|
63
67
|
codexs switch my-provider
|
|
64
68
|
```
|
|
65
69
|
|
|
70
|
+
Prepare GitHub Copilot and manage its bridge:
|
|
71
|
+
|
|
72
|
+
```bash
|
|
73
|
+
codexs login copilot
|
|
74
|
+
codexs add copilot-main --copilot --profile copilot-main
|
|
75
|
+
codexs bridge start copilot-main
|
|
76
|
+
```
|
|
77
|
+
|
|
66
78
|
Check runtime state:
|
|
67
79
|
|
|
68
80
|
```bash
|
|
@@ -75,17 +87,24 @@ codexs doctor
|
|
|
75
87
|
|
|
76
88
|
```bash
|
|
77
89
|
codexs init
|
|
90
|
+
codexs login copilot
|
|
78
91
|
codexs migrate
|
|
79
92
|
codexs list
|
|
80
93
|
codexs show <provider>
|
|
81
94
|
codexs current
|
|
82
95
|
codexs status
|
|
96
|
+
codexs config show [profile]
|
|
97
|
+
codexs config list-profiles
|
|
83
98
|
codexs add <provider> --profile <name> --api-key <key>
|
|
84
|
-
codexs
|
|
99
|
+
codexs add <provider> --copilot --profile <name>
|
|
100
|
+
codexs edit <provider>
|
|
85
101
|
codexs switch <provider>
|
|
86
|
-
codexs
|
|
102
|
+
codexs bridge start [provider]
|
|
103
|
+
codexs bridge status [provider]
|
|
104
|
+
codexs bridge stop [provider]
|
|
105
|
+
codexs remove <provider> [--force] [--switch-to <profile>]
|
|
87
106
|
codexs import <file> [--merge]
|
|
88
|
-
codexs export <file>
|
|
107
|
+
codexs export <file> [--force]
|
|
89
108
|
codexs backups list
|
|
90
109
|
codexs rollback [backup-id]
|
|
91
110
|
codexs doctor
|
|
@@ -94,41 +113,61 @@ codexs doctor
|
|
|
94
113
|
Command help:
|
|
95
114
|
|
|
96
115
|
```bash
|
|
97
|
-
codexs help switch
|
|
98
116
|
codexs help init
|
|
117
|
+
codexs help login
|
|
118
|
+
codexs help add
|
|
119
|
+
codexs help bridge
|
|
120
|
+
codexs help config
|
|
99
121
|
codexs help migrate
|
|
100
|
-
codexs help setup
|
|
101
122
|
```
|
|
102
123
|
|
|
103
124
|
## How It Works
|
|
104
125
|
|
|
105
|
-
|
|
126
|
+
Starting in `0.0.11`, `codex-switch` uses a dual-path model.
|
|
106
127
|
|
|
107
|
-
|
|
128
|
+
Tool home:
|
|
129
|
+
|
|
130
|
+
```text
|
|
131
|
+
~/.config/codex-switch/
|
|
132
|
+
codex-switch.json
|
|
133
|
+
providers.json
|
|
134
|
+
backups/
|
|
135
|
+
runtime/
|
|
136
|
+
runtimes/
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
Target Codex runtime:
|
|
108
140
|
|
|
109
141
|
```text
|
|
110
142
|
~/.codex/
|
|
111
143
|
config.toml
|
|
112
144
|
auth.json
|
|
113
|
-
providers.json
|
|
114
|
-
backups/
|
|
115
145
|
```
|
|
116
146
|
|
|
117
147
|
Notes:
|
|
118
148
|
|
|
119
|
-
- `providers.json` is the managed provider registry
|
|
120
|
-
- `
|
|
121
|
-
- `
|
|
122
|
-
-
|
|
123
|
-
-
|
|
149
|
+
- `providers.json` is the managed provider registry and now lives under the tool home
|
|
150
|
+
- `codex-switch.json` stores tool-level metadata such as `defaultCodexDir`
|
|
151
|
+
- `config.toml` is still the active runtime-routing file in the target Codex directory
|
|
152
|
+
- `auth.json` is the active auth projection file
|
|
153
|
+
- direct-provider switches rewrite `OPENAI_API_KEY`
|
|
154
|
+
- Copilot bridge providers keep upstream login in the official Copilot runtime while `codex-switch` manages the local bridge secret, bridge state, and routing
|
|
155
|
+
- mutating commands back up before writing and rollback stays available after failed or undesired changes
|
|
156
|
+
|
|
157
|
+
Path overrides and resolution:
|
|
158
|
+
|
|
159
|
+
- `--codex-dir <path>` explicitly targets a Codex runtime directory
|
|
160
|
+
- `CODEXS_CODEX_DIR` sets the default target when `--codex-dir` is not passed
|
|
161
|
+
- `CODEXS_HOME` overrides the tool home location
|
|
124
162
|
|
|
125
163
|
## Automation
|
|
126
164
|
|
|
127
165
|
This CLI supports both human TTY use and non-interactive automation.
|
|
128
166
|
|
|
129
167
|
Current exceptions:
|
|
130
|
-
|
|
131
|
-
- `
|
|
168
|
+
|
|
169
|
+
- `login copilot` requires a real TTY and does not support `--json`
|
|
170
|
+
- `migrate` remains intentionally interactive for adopt profile selection and provider detail collection
|
|
132
171
|
|
|
133
172
|
Recommended global flags:
|
|
134
173
|
|
|
@@ -144,6 +183,7 @@ Recommendations:
|
|
|
144
183
|
- use `--json` for stable machine-readable output
|
|
145
184
|
- pass all required arguments explicitly in scripts or CI
|
|
146
185
|
- use `--codex-dir <path>` for sandbox or test environments
|
|
186
|
+
- use `CODEXS_HOME` when you want tool state isolated from your default workstation setup
|
|
147
187
|
|
|
148
188
|
## Testing
|
|
149
189
|
|
|
@@ -152,24 +192,25 @@ Build and test locally:
|
|
|
152
192
|
```bash
|
|
153
193
|
npm run build
|
|
154
194
|
npm test
|
|
195
|
+
npx tsc --noEmit
|
|
155
196
|
```
|
|
156
197
|
|
|
157
198
|
The repository includes a development fixture under `dev-codex/local-sandbox` plus dedicated test docs:
|
|
158
199
|
|
|
159
|
-
- [Testing Guide](./docs/testing.md)
|
|
160
|
-
- [
|
|
200
|
+
- [Testing Guide](./docs/Tests/testing.md)
|
|
201
|
+
- [Bridge Testing Notes](./docs/Tests/testing-bridge-v0.0.9.md)
|
|
202
|
+
- [Test Report for 0.0.7](./docs/Tests/test-report-0.0.7.md)
|
|
161
203
|
|
|
162
204
|
## Documentation
|
|
163
205
|
|
|
164
206
|
- [Chinese README](./README.CN.md)
|
|
165
207
|
- [AI README](./README.AI.md)
|
|
166
208
|
- [Detailed CLI Usage](./docs/cli-usage.md)
|
|
167
|
-
- [Testing Guide](./docs/testing.md)
|
|
168
|
-
- [Test Report for 0.0.5](./docs/test-report-0.0.5.md)
|
|
209
|
+
- [Testing Guide](./docs/Tests/testing.md)
|
|
169
210
|
- [Product Overview](./docs/codex-switch-product-overview.md)
|
|
170
211
|
- [Technical Architecture](./docs/codex-switch-technical-architecture.md)
|
|
171
|
-
- [
|
|
172
|
-
- [Design Doc 0.0.
|
|
212
|
+
- [PRD 0.0.11](./docs/PRD/codex-switch-prd-v0.0.11.md)
|
|
213
|
+
- [Design Doc 0.0.11](./docs/Design/codex-switch-v0.0.11-design.md)
|
|
173
214
|
|
|
174
215
|
## License
|
|
175
216
|
|
package/dist/app/add-provider.js
CHANGED
|
@@ -41,12 +41,13 @@ const errors_1 = require("../domain/errors");
|
|
|
41
41
|
const config_repo_1 = require("../storage/config-repo");
|
|
42
42
|
const fs_utils_1 = require("../storage/fs-utils");
|
|
43
43
|
const providers_repo_1 = require("../storage/providers-repo");
|
|
44
|
+
const copilot_adapter_1 = require("../runtime/copilot-adapter");
|
|
44
45
|
const copilot_installer_1 = require("../runtime/copilot-installer");
|
|
45
46
|
const run_mutation_1 = require("./run-mutation");
|
|
46
47
|
/**
|
|
47
48
|
* Adds a new provider record to the managed providers registry.
|
|
48
49
|
*/
|
|
49
|
-
function addProvider(args) {
|
|
50
|
+
async function addProvider(args) {
|
|
50
51
|
(0, fs_utils_1.ensureDir)(args.codexDir);
|
|
51
52
|
const providers = (0, providers_repo_1.readProvidersFileIfExists)(args.providersPath);
|
|
52
53
|
if (providers.providers[args.providerName]) {
|
|
@@ -67,17 +68,26 @@ function addProvider(args) {
|
|
|
67
68
|
}
|
|
68
69
|
: undefined;
|
|
69
70
|
if (args.copilot) {
|
|
70
|
-
const installStatus = (0, copilot_installer_1.probeCopilotSdkInstall)();
|
|
71
|
+
const installStatus = (0, copilot_installer_1.probeCopilotSdkInstall)(args.runtimesDir);
|
|
71
72
|
if (!installStatus.installed) {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
73
|
+
throw (0, errors_1.cliError)("COPILOT_SDK_MISSING", "The optional Copilot SDK runtime is not installed. Run `codexs login copilot` first.", {
|
|
74
|
+
installDir: installStatus.installDir,
|
|
75
|
+
packageName: installStatus.packageName,
|
|
76
|
+
suggestion: "Run `codexs login copilot` to install the Copilot SDK and complete login.",
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
try {
|
|
80
|
+
await (0, copilot_adapter_1.readCopilotAuthState)(args.runtimesDir);
|
|
81
|
+
}
|
|
82
|
+
catch (error) {
|
|
83
|
+
const normalized = (0, errors_1.normalizeError)(error);
|
|
84
|
+
if (normalized.code === "COPILOT_AUTH_REQUIRED") {
|
|
85
|
+
throw (0, errors_1.cliError)("COPILOT_AUTH_REQUIRED", "Copilot authentication is required before a Copilot provider can be added.", {
|
|
86
|
+
...(normalized.details ?? {}),
|
|
87
|
+
suggestion: "Run `codexs login copilot` to complete GitHub Copilot login.",
|
|
78
88
|
});
|
|
79
89
|
}
|
|
80
|
-
|
|
90
|
+
throw error;
|
|
81
91
|
}
|
|
82
92
|
}
|
|
83
93
|
const document = (0, config_repo_1.readStructuredConfig)(args.configPath);
|
|
@@ -97,13 +107,17 @@ function addProvider(args) {
|
|
|
97
107
|
}),
|
|
98
108
|
}
|
|
99
109
|
: undefined;
|
|
100
|
-
const upsertModelProviders =
|
|
110
|
+
const upsertModelProviders = args.copilot
|
|
101
111
|
? {
|
|
102
|
-
[args.profile]:
|
|
103
|
-
baseUrl: args.copilot ? (0, providers_1.buildCopilotBridgeBaseUrl)(runtime) : args.baseUrl ?? undefined,
|
|
104
|
-
},
|
|
112
|
+
[args.profile]: (0, providers_1.buildCopilotModelProviderProjection)(runtime),
|
|
105
113
|
}
|
|
106
|
-
:
|
|
114
|
+
: !existingModelProvider && args.createProfile
|
|
115
|
+
? {
|
|
116
|
+
[args.profile]: {
|
|
117
|
+
baseUrl: args.baseUrl ?? undefined,
|
|
118
|
+
},
|
|
119
|
+
}
|
|
120
|
+
: undefined;
|
|
107
121
|
if (existingProfile) {
|
|
108
122
|
(0, config_repo_1.requireManagedProfileRuntime)(document, providers, args.profile);
|
|
109
123
|
}
|
|
@@ -123,7 +137,7 @@ function addProvider(args) {
|
|
|
123
137
|
},
|
|
124
138
|
};
|
|
125
139
|
return (0, run_mutation_1.runMutation)({
|
|
126
|
-
|
|
140
|
+
lockPath: args.lockPath,
|
|
127
141
|
backupsDir: args.backupsDir,
|
|
128
142
|
latestBackupPath: args.latestBackupPath,
|
|
129
143
|
operation: "add",
|