@minniexcode/codex-switch 0.0.10 → 0.0.12

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 (51) hide show
  1. package/README.AI.md +68 -73
  2. package/README.CN.md +108 -111
  3. package/README.md +87 -80
  4. package/dist/app/add-provider.js +29 -15
  5. package/dist/app/bridge.js +15 -14
  6. package/dist/app/edit-provider.js +1 -1
  7. package/dist/app/get-status.js +21 -9
  8. package/dist/app/import-providers.js +1 -1
  9. package/dist/app/init-codex.js +13 -14
  10. package/dist/app/list-providers.js +48 -1
  11. package/dist/app/remove-provider.js +1 -1
  12. package/dist/app/run-doctor.js +12 -5
  13. package/dist/app/run-mutation.js +3 -2
  14. package/dist/app/setup-codex.js +3 -1
  15. package/dist/app/switch-provider.js +11 -13
  16. package/dist/cli/output.js +145 -18
  17. package/dist/cli.js +34 -2
  18. package/dist/commands/args.js +2 -2
  19. package/dist/commands/dispatch.js +40 -0
  20. package/dist/commands/handlers.js +130 -161
  21. package/dist/commands/help.js +11 -5
  22. package/dist/commands/registry.js +42 -20
  23. package/dist/domain/backups.js +4 -4
  24. package/dist/domain/config.js +110 -5
  25. package/dist/domain/providers.js +12 -0
  26. package/dist/domain/runtime-state.js +111 -13
  27. package/dist/infra/config-repo.js +16 -206
  28. package/dist/interaction/interactive.js +16 -6
  29. package/dist/runtime/copilot-adapter.js +12 -12
  30. package/dist/runtime/copilot-bridge.js +394 -45
  31. package/dist/runtime/copilot-cli.js +84 -12
  32. package/dist/runtime/copilot-installer.js +10 -9
  33. package/dist/runtime/copilot-sdk-loader.js +5 -5
  34. package/dist/storage/backup-repo.js +4 -4
  35. package/dist/storage/codex-paths.js +34 -8
  36. package/dist/storage/config-repo.js +0 -23
  37. package/dist/storage/lock-repo.js +2 -4
  38. package/dist/storage/runtime-state-repo.js +14 -13
  39. package/dist/storage/tool-config-repo.js +111 -0
  40. package/docs/Design/codex-switch-v0.0.11-design.md +824 -0
  41. package/docs/Design/codex-switch-v0.0.12-design.md +343 -0
  42. package/docs/PRD/codex-switch-prd-v0.0.11.md +577 -0
  43. package/docs/PRD/codex-switch-prd-v0.0.12.md +279 -0
  44. package/docs/PRD/codex-switch-prd-v0.1.0.md +125 -237
  45. package/docs/Tests/testing.md +39 -112
  46. package/docs/cli-usage.md +135 -565
  47. package/docs/codex-switch-command-design.md +3 -0
  48. package/docs/codex-switch-product-overview.md +52 -207
  49. package/docs/codex-switch-technical-architecture.md +3 -0
  50. package/package.json +1 -1
  51. package/dist/app/rollback-latest.js +0 -26
package/README.AI.md CHANGED
@@ -1,115 +1,110 @@
1
1
  # AI README
2
2
 
3
- This file is for AI agents, automation scripts, and contributors who need a compact operational summary of the repository.
3
+ This file summarizes the current operational contract for AI agents, automation scripts, and contributors.
4
4
 
5
- ## Repository Purpose
5
+ ## Package Context
6
6
 
7
- `@minniexcode/codex-switch` is a local-first TypeScript CLI for managing provider/profile state for Codex under `~/.codex/`.
7
+ - Package: `@minniexcode/codex-switch`
8
+ - CLI name: `codexs`
9
+ - Current repository version: `0.0.12`
10
+ - Version status: development-version software, not a stable `0.1.0` release yet
8
11
 
9
- Primary goals:
12
+ ## Product Role
10
13
 
11
- - safe local profile switching
12
- - backup-before-write mutation flows
13
- - rollback on failure
14
- - stable machine-readable CLI output
15
- - support for both human TTY usage and agent automation
14
+ `codex-switch` is a local-first TypeScript CLI that manages provider and profile state for Codex while keeping tool-managed state separate from the target Codex runtime.
16
15
 
17
- ## Main Command Surface
16
+ The managed source of truth is the tool home. Runtime files under the target Codex directory are projected outputs, not the main registry.
17
+
18
+ ## Primary Workflows
19
+
20
+ Direct provider workflow:
18
21
 
19
22
  ```bash
20
23
  codexs init
21
- codexs migrate
22
- codexs list
23
- codexs show <provider>
24
- codexs current
24
+ codexs add <provider> --profile <name> --api-key <key>
25
+ codexs switch <provider>
25
26
  codexs status
26
- codexs edit <provider>
27
+ codexs doctor
28
+ ```
29
+
30
+ GitHub Copilot workflow:
31
+
32
+ ```bash
33
+ codexs init
34
+ codexs login copilot
35
+ codexs add <provider> --copilot --profile <name>
27
36
  codexs switch <provider>
28
- codexs import <file>
29
- codexs export <file>
30
- codexs add <provider>
31
- codexs remove <provider>
32
- codexs backups list
37
+ codexs status
33
38
  codexs doctor
34
- codexs rollback [backup-id]
35
39
  ```
36
40
 
37
- Shared flags:
41
+ Advanced adopt workflow:
38
42
 
39
43
  ```bash
40
- --json
41
- --codex-dir <path>
44
+ codexs init
45
+ codexs migrate
42
46
  ```
43
47
 
44
- ## Important Runtime Files
48
+ `migrate` is not a fresh-install default. It is an advanced adopt helper for existing runtime state.
49
+
50
+ ## Important Paths
51
+
52
+ Tool home:
45
53
 
46
54
  ```text
47
- ~/.codex/
48
- config.toml
49
- auth.json
55
+ ~/.config/codex-switch/
56
+ codex-switch.json
50
57
  providers.json
51
58
  backups/
59
+ runtime/
60
+ runtimes/
52
61
  ```
53
62
 
54
- Operational model:
55
-
56
- - `providers.json` is the management-state source of truth
57
- - `config.toml` is the managed runtime-routing file
58
- - `auth.json` is the active auth projection file for direct providers and is also inspected by status/doctor
59
- - `backups/latest.json` tracks the latest rollback state
60
- - mutating commands should back up first and run under a lightweight file lock
61
-
62
- ## Project Structure
63
+ Target Codex runtime:
63
64
 
64
65
  ```text
65
- src/
66
- app/
67
- cli/
68
- domain/
69
- infra/
70
- tests/
71
- docs/
72
- dist/
66
+ ~/.codex/
67
+ config.toml
68
+ auth.json
73
69
  ```
74
70
 
75
- Layer intent:
71
+ Operational meaning:
76
72
 
77
- - `cli`: argument parsing, help, TTY flows, output shaping
78
- - `app`: command orchestration and use-case logic
79
- - `domain`: pure domain rules and shared models
80
- - `infra`: filesystem, lock, backup, config, and Codex integration code
73
+ - `providers.json` is the managed provider registry.
74
+ - `codex-switch.json` stores tool-level metadata such as the default target Codex directory.
75
+ - `config.toml` is the active runtime routing file.
76
+ - `auth.json` is the active auth projection file.
81
77
 
82
- ## Command Entry Point
78
+ ## Command Notes
83
79
 
84
- Use `codexs` directly for runtime interaction:
80
+ Shared flags:
85
81
 
86
82
  ```bash
87
- codexs --help
88
- codexs list --json
89
- codexs status --json
83
+ --json
84
+ --codex-dir <path>
85
+ --help
86
+ --version
90
87
  ```
91
88
 
92
- ## Current Version Context
93
-
94
- Current package version in this repository:
89
+ Relevant environment variables:
95
90
 
96
- ```text
97
- 0.0.10
91
+ ```bash
92
+ CODEXS_HOME
93
+ CODEXS_CODEX_DIR
98
94
  ```
99
95
 
100
- Recent version summary:
96
+ Important behavioral constraints:
101
97
 
102
- - `0.0.10`: `init` / `migrate` command split finalized, `setup` deprecated, and the managed provider model reduced to static profile plus `base_url` configuration
103
- - `0.0.7`: command-surface refactor, env_key/auth-mirror model corrections, and the initial `setup` split toward `init` plus `migrate`
104
- - `0.0.4`: setup/show/edit/backups list/specific rollback/import merge and clearer CLI semantics
105
- - `0.0.3`: interactive TTY flows and improved help
106
- - `0.0.2`: mutation orchestration, backups, rollback, locks, drift detection improvements
107
- - `0.0.1`: initial TypeScript CLI and baseline docs
98
+ - Prefer `--json` for programmatic invocation whenever the command supports it.
99
+ - `login copilot` requires a real TTY and does not support `--json`.
100
+ - `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.
101
+ - `add --copilot` assumes SDK install and upstream Copilot auth are already ready.
102
+ - `migrate` still depends on interactive profile selection and provider-detail collection in this release.
103
+ - `status` is the main dual-path summary command.
104
+ - `doctor` is the deeper repair-oriented diagnostic command.
108
105
 
109
- ## Notes For Agents
106
+ ## Safety Notes
110
107
 
111
- - Prefer `--json` when invoking commands programmatically
112
- - Treat `providers.json` as sensitive because it may contain API keys
113
- - Do not assume silent write-back from runtime files into `providers.json`
114
- - Prefer `init` for repeatable machine setup and `migrate` for human-led adopt flows
115
- - Use `docs/` for deeper product and architecture context
108
+ - Treat `providers.json` as sensitive because it may contain API keys.
109
+ - Human-readable output may mask secrets, but JSON output can expose full provider payloads.
110
+ - Managed write operations rely on backup and rollback flow; do not describe manual file edits as the primary workflow.
package/README.CN.md CHANGED
@@ -1,182 +1,179 @@
1
1
  # @minniexcode/codex-switch
2
2
 
3
- `@minniexcode/codex-switch` 是一个本地优先的 CLI,用来安全地管理和切换 Codex 的 provider/profile 配置。
3
+ `@minniexcode/codex-switch` 是一个本地优先的 CLI,用来安全地管理和切换 Codex 的 providerprofile 配置。
4
4
 
5
- 它主要解决这样一个问题:如果你同时使用多个 Codex provider、API key profile,不想再手动改 `~/.codex/` 里的文件,就可以用这个工具做统一管理和安全切换。
5
+ 它把 `codex-switch` 自己的工具状态和目标 Codex runtime 明确分开,让 provider 管理、备份与 runtime 投影有一套受管流程,而不是依赖手工改文件。
6
6
 
7
- ## 这个仓库是做什么的
7
+ ## 版本定位
8
8
 
9
- 这个仓库包含 `codex-switch` 的 CLI 实现、npm 包配置,以及相关产品和技术文档。
9
+ 当前包版本:`0.0.12`
10
10
 
11
- 项目目标很明确:
11
+ 当前仍处于开发版本阶段。这个版本的重点不是继续扩命令面,而是把主工作流、帮助文案和实际行为统一到同一套契约上。
12
12
 
13
- - 在本地完成 Codex 配置切换
14
- - 写入前先备份
15
- - 出错时可回滚
16
- - 同时兼顾终端用户和 AI/自动化调用
17
-
18
- ## 现在可以做什么
19
-
20
- 当前命令面如下:
21
-
22
- ```bash
23
- codexs init
24
- codexs migrate
25
- codexs list
26
- codexs show <provider>
27
- codexs current
28
- codexs status
29
- codexs edit <provider>
30
- codexs switch <provider>
31
- codexs import <file>
32
- codexs export <file>
33
- codexs add <provider>
34
- codexs remove <provider>
35
- codexs backups list
36
- codexs doctor
37
- codexs rollback
38
- codexs setup
39
- ```
40
-
41
- 对应能力包括:
42
-
43
- - 初始化空的受管 `providers.json`
44
- - 从已有 `config.toml` adopt 可管理的 runtime profile
45
- - 查看本地已管理的 provider
46
- - 查看单个 provider 详情
47
- - 查看当前激活的 profile
48
- - 查看本地运行态摘要
49
- - 编辑已有 provider
50
- - 安全切换 provider
51
- - 导入和导出 provider 映射
52
- - 新增和删除 provider
53
- - 查看备份列表
54
- - 检查配置漂移和常见本地问题
55
- - 在变更前自动备份,并在失败时回滚
56
- - 保留 `setup` 作为弃用入口,并引导到 `init` / `migrate`
57
-
58
- ## 简单用法
59
-
60
- 全局安装:
13
+ ## 安装
61
14
 
62
15
  ```bash
63
16
  npm install -g @minniexcode/codex-switch
64
17
  ```
65
18
 
66
- 或者直接执行:
19
+ 不全局安装时也可以直接运行:
67
20
 
68
21
  ```bash
69
22
  npx @minniexcode/codex-switch --help
70
23
  ```
71
24
 
72
- 检查 CLI 是否可用:
25
+ CLI 命令名:
73
26
 
74
27
  ```bash
75
28
  codexs --help
76
29
  ```
77
30
 
78
- 典型使用方式:
31
+ ## 主工作流
32
+
33
+ Direct provider 主路径:
79
34
 
80
35
  ```bash
81
36
  codexs init
82
- codexs migrate
83
- codexs list
84
- codexs current
85
37
  codexs add my-provider --profile my-provider --api-key sk-xxx
86
38
  codexs switch my-provider
87
39
  codexs status
40
+ codexs doctor
88
41
  ```
89
42
 
90
- 给脚本或 AI 使用时建议加上:
43
+ GitHub Copilot 主路径:
91
44
 
92
45
  ```bash
93
- codexs list --json
94
- codexs status --json
46
+ codexs init
47
+ codexs login copilot
48
+ codexs add copilot-main --copilot --profile copilot-main
49
+ codexs switch copilot-main
50
+ codexs status
51
+ codexs doctor
95
52
  ```
96
53
 
97
- 通用参数:
54
+ 说明:
55
+
56
+ - `init` 负责初始化 `codex-switch` 的 tool home 与受管状态文件。
57
+ - `login copilot` 负责上游 Copilot onboarding 和登录可用性检查。
58
+ - `add --copilot` 不负责替你登录,它假设上游 Copilot 已经 ready。
59
+ - `status` 是切换后的主读取命令。
60
+ - `doctor` 是主诊断命令,用于解释问题和下一步修复动作。
61
+
62
+ ## Advanced Adopt 路径
63
+
64
+ 如果你已经有现成的 Codex runtime 状态,希望把它 adopt 到受管 `providers.json`,再使用:
98
65
 
99
66
  ```bash
100
- --json
101
- --codex-dir <path>
67
+ codexs init
68
+ codexs migrate
102
69
  ```
103
70
 
104
- ## 交互式体验
71
+ `migrate` 是高级 adopt helper,不是 fresh install 的默认第一步。
105
72
 
106
- 这个 CLI 同时支持显式命令和交互式终端流程。
73
+ ## 命令面
107
74
 
108
- - `codexs add` 在 TTY 里会补问缺失的必填项
109
- - `codexs switch` 在未传 provider 时可以弹出选择列表
110
- - `codexs remove` 支持交互式选择和确认删除
111
- - `import`、`export`、`rollback` 在交互模式下会要求确认
112
- - `--json` 模式保持非交互,适合自动化
75
+ ```bash
76
+ codexs init
77
+ codexs login copilot
78
+ codexs migrate
79
+ codexs list
80
+ codexs show <provider>
81
+ codexs current
82
+ codexs status
83
+ codexs config show [profile]
84
+ codexs config list-profiles
85
+ codexs add <provider> --profile <name> --api-key <key>
86
+ codexs add <provider> --copilot --profile <name>
87
+ codexs edit <provider>
88
+ codexs switch <provider>
89
+ codexs remove <provider> [--force] [--switch-to <profile>]
90
+ codexs import <file>
91
+ codexs export <file> [--force]
92
+ codexs bridge start [provider]
93
+ codexs bridge status [provider]
94
+ codexs bridge stop [provider]
95
+ codexs backups list
96
+ codexs rollback [backup-id]
97
+ codexs doctor
98
+ ```
99
+
100
+ `setup` 仍然存在,但只作为已弃用兼容入口,用来提示调用方改用 `init` 或 `migrate`。
113
101
 
114
- ## 管理哪些文件
102
+ ## 双路径模型
115
103
 
116
- `codex-switch` 主要围绕 `~/.codex/` 下的这些文件工作:
104
+ tool home:
117
105
 
118
106
  ```text
119
- ~/.codex/
120
- config.toml
121
- auth.json
107
+ ~/.config/codex-switch/
108
+ codex-switch.json
122
109
  providers.json
123
110
  backups/
111
+ runtime/
112
+ runtimes/
124
113
  ```
125
114
 
126
- 存储模型:
127
-
128
- - `providers.json` 是管理态的单一事实来源
129
- - `config.toml` 是受管的运行时路由文件
130
- - `auth.json` 是独立的 Codex 认证状态文件,`status` / `doctor` 只读检查它
131
- - `backups/latest.json` 记录最近一次可回滚窗口
115
+ 目标 Codex runtime:
132
116
 
133
- 注意:`providers.json` 可能包含 API key,应视为本地敏感文件。
134
-
135
- ## 相关文档
117
+ ```text
118
+ ~/.codex/
119
+ config.toml
120
+ auth.json
121
+ ```
136
122
 
137
- - [English README](./README.md)
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)
123
+ 关键边界:
144
124
 
145
- ## 最近 3 个版本更新
125
+ - `providers.json` 是受管 provider 注册表,位于 tool home。
126
+ - `codex-switch.json` 保存工具级元数据,例如 `defaultCodexDir`。
127
+ - `config.toml` 仍然是目标 runtime 里的活动路由文件。
128
+ - `auth.json` 仍然是目标 runtime 里的活动认证投影文件。
129
+ - Direct provider 切换会改写活动 runtime 中的 `OPENAI_API_KEY`。
130
+ - Copilot provider 保持上游 GitHub 登录留在官方 Copilot runtime 中,`codex-switch` 只管理本地 bridge 状态与路由。
146
131
 
147
- ### 0.0.10
132
+ 路径控制:
148
133
 
149
- - 正式拆分 `setup`:新增 `init` `migrate`,`setup` 变为弃用命令
150
- - 增加 `show`、`edit`、`backups list` 等对当前命令面的整理
151
- - 清理 provider/runtime 管理语义,CLI 只负责静态 profile 与 `base_url` 层配置
134
+ - `--codex-dir <path>` 显式指定目标 Codex runtime 目录。
135
+ - `CODEXS_CODEX_DIR` 在未传 `--codex-dir` 时提供默认目标目录。
136
+ - `CODEXS_HOME` 用于覆盖 tool home 位置。
152
137
 
153
- ### 0.0.3
138
+ ## 自动化说明
154
139
 
155
- - `add`、`switch`、`remove`、`import`、`export`、`rollback` 增加了交互式 TTY 流程
156
- - 改进了帮助信息和命令级使用说明
157
- - 增强了交互行为和参数处理相关测试覆盖
140
+ 这个 CLI 同时支持人类终端使用和非交互自动化。
158
141
 
159
- ### 0.0.2
142
+ 全局参数:
160
143
 
161
- - 增加了统一的变更编排能力,包括写前备份、失败回滚和单进程锁
162
- - 改进了 `status` 和 `doctor`,更清晰地识别运行态漂移
163
- - 加强了底层仓储层和领域层,使配置写入更安全
144
+ ```bash
145
+ --json
146
+ --codex-dir <path>
147
+ --help
148
+ --version
149
+ ```
164
150
 
165
- ### 0.0.1
151
+ 当前实现边界:
166
152
 
167
- - 发布了第一版 TypeScript CLI 实现
168
- - 落地了核心 MVP 命令和基于文件的 provider 管理模型
169
- - 补齐了首批产品、架构和命令设计文档
153
+ - `login copilot` 必须运行在真实 TTY 下,不支持 `--json`。
154
+ - `migrate` 在当前版本仍然依赖交互式 profile 选择和 provider 细节补全。
155
+ - 自动化调用应尽量显式传参,并优先使用 `--json`。
170
156
 
171
157
  ## 本地开发
172
158
 
173
159
  ```bash
174
- npm install
175
160
  npm run build
176
161
  npm test
162
+ npx tsc --noEmit
177
163
  node dist/cli.js --help
164
+ npm pack --dry-run
178
165
  ```
179
166
 
167
+ ## 相关文档
168
+
169
+ - [English README](./README.md)
170
+ - [AI README](./README.AI.md)
171
+ - [详细 CLI 文档](./docs/cli-usage.md)
172
+ - [产品概览](./docs/codex-switch-product-overview.md)
173
+ - [测试说明](./docs/Tests/testing.md)
174
+ - [PRD 0.0.12](./docs/PRD/codex-switch-prd-v0.0.12.md)
175
+ - [Release Gate PRD 0.1.0](./docs/PRD/codex-switch-prd-v0.1.0.md)
176
+
180
177
  ## License
181
178
 
182
179
  MIT