@minniexcode/codex-switch 0.0.2 → 0.0.4
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 +110 -0
- package/README.CN.md +160 -0
- package/README.md +159 -121
- package/dist/app/edit-provider.js +64 -0
- package/dist/app/import-providers.js +10 -1
- package/dist/app/list-backups.js +17 -0
- package/dist/app/rollback-backup.js +30 -0
- package/dist/app/setup-codex.js +138 -0
- package/dist/app/show-provider.js +22 -0
- package/dist/cli/add-interactive.js +108 -0
- package/dist/cli/args.js +42 -12
- package/dist/cli/help.js +278 -0
- package/dist/cli/interactive.js +173 -0
- package/dist/cli/output.js +34 -1
- package/dist/cli/prompt.js +110 -0
- package/dist/cli.js +229 -52
- package/dist/domain/backups.js +103 -0
- package/dist/domain/errors.js +3 -3
- package/dist/domain/providers.js +10 -0
- package/dist/domain/setup.js +30 -0
- package/dist/infra/backup-repo.js +65 -6
- package/dist/infra/codex-cli.js +62 -0
- package/dist/infra/codex-discovery.js +48 -0
- package/dist/infra/codex-paths.js +14 -1
- package/dist/infra/providers-repo.js +29 -0
- package/docs/PRD/codex-switch-prd-v0.1.0.md +393 -0
- package/docs/{codex-switch-prd.md → PRD/codex-switch-prd.md} +31 -8
- package/docs/cli-usage.md +580 -0
- package/docs/codex-switch-command-design.md +30 -5
- package/docs/codex-switch-product-overview.md +1 -1
- package/docs/codex-switch-product-research.md +2 -2
- package/docs/codex-switch-technical-architecture.md +79 -38
- package/docs/codex-switch-v0.0.4-design.md +874 -0
- package/package.json +4 -1
package/README.AI.md
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
# AI README
|
|
2
|
+
|
|
3
|
+
This file is for AI agents, automation scripts, and contributors who need a compact operational summary of the repository.
|
|
4
|
+
|
|
5
|
+
## Repository Purpose
|
|
6
|
+
|
|
7
|
+
`@minniexcode/codex-switch` is a local-first TypeScript CLI for managing provider/profile state for Codex under `~/.codex/`.
|
|
8
|
+
|
|
9
|
+
Primary goals:
|
|
10
|
+
|
|
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
|
|
16
|
+
|
|
17
|
+
## Main Command Surface
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
codexs setup
|
|
21
|
+
codexs list
|
|
22
|
+
codexs show <provider>
|
|
23
|
+
codexs current
|
|
24
|
+
codexs status
|
|
25
|
+
codexs edit <provider>
|
|
26
|
+
codexs switch <provider>
|
|
27
|
+
codexs import <file>
|
|
28
|
+
codexs export <file>
|
|
29
|
+
codexs add <provider>
|
|
30
|
+
codexs remove <provider>
|
|
31
|
+
codexs backups list
|
|
32
|
+
codexs doctor
|
|
33
|
+
codexs rollback [backup-id]
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
Shared flags:
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
--json
|
|
40
|
+
--codex-dir <path>
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## Important Runtime Files
|
|
44
|
+
|
|
45
|
+
```text
|
|
46
|
+
~/.codex/
|
|
47
|
+
config.toml
|
|
48
|
+
auth.json
|
|
49
|
+
providers.json
|
|
50
|
+
backups/
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
Operational model:
|
|
54
|
+
|
|
55
|
+
- `providers.json` is the management-state source of truth
|
|
56
|
+
- `config.toml` and `auth.json` are runtime mirrors
|
|
57
|
+
- `backups/latest.json` tracks the latest rollback state
|
|
58
|
+
- mutating commands should back up first and run under a lightweight file lock
|
|
59
|
+
|
|
60
|
+
## Project Structure
|
|
61
|
+
|
|
62
|
+
```text
|
|
63
|
+
src/
|
|
64
|
+
app/
|
|
65
|
+
cli/
|
|
66
|
+
domain/
|
|
67
|
+
infra/
|
|
68
|
+
tests/
|
|
69
|
+
docs/
|
|
70
|
+
dist/
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
Layer intent:
|
|
74
|
+
|
|
75
|
+
- `cli`: argument parsing, help, TTY flows, output shaping
|
|
76
|
+
- `app`: command orchestration and use-case logic
|
|
77
|
+
- `domain`: pure domain rules and shared models
|
|
78
|
+
- `infra`: filesystem, lock, backup, config, and Codex integration code
|
|
79
|
+
|
|
80
|
+
## Command Entry Point
|
|
81
|
+
|
|
82
|
+
Use `codexs` directly for runtime interaction:
|
|
83
|
+
|
|
84
|
+
```bash
|
|
85
|
+
codexs --help
|
|
86
|
+
codexs list --json
|
|
87
|
+
codexs status --json
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
## Current Version Context
|
|
91
|
+
|
|
92
|
+
Current package version in this repository:
|
|
93
|
+
|
|
94
|
+
```text
|
|
95
|
+
0.0.4
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
Recent version summary:
|
|
99
|
+
|
|
100
|
+
- `0.0.4`: setup/show/edit/backups list/specific rollback/import merge and clearer CLI semantics
|
|
101
|
+
- `0.0.3`: interactive TTY flows and improved help
|
|
102
|
+
- `0.0.2`: mutation orchestration, backups, rollback, locks, drift detection improvements
|
|
103
|
+
- `0.0.1`: initial TypeScript CLI and baseline docs
|
|
104
|
+
|
|
105
|
+
## Notes For Agents
|
|
106
|
+
|
|
107
|
+
- Prefer `--json` when invoking commands programmatically
|
|
108
|
+
- Treat `providers.json` as sensitive because it may contain API keys
|
|
109
|
+
- Do not assume silent write-back from runtime files into `providers.json`
|
|
110
|
+
- Use `docs/` for deeper product and architecture context
|
package/README.CN.md
ADDED
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
# @minniexcode/codex-switch
|
|
2
|
+
|
|
3
|
+
`@minniexcode/codex-switch` 是一个本地优先的 CLI,用来安全地管理和切换 Codex 的 provider/profile 配置。
|
|
4
|
+
|
|
5
|
+
它主要解决这样一个问题:如果你同时使用多个 Codex provider、API key 或 profile,不想再手动改 `~/.codex/` 里的文件,就可以用这个工具做统一管理和安全切换。
|
|
6
|
+
|
|
7
|
+
## 这个仓库是做什么的
|
|
8
|
+
|
|
9
|
+
这个仓库包含 `codex-switch` 的 CLI 实现、npm 包配置,以及相关产品和技术文档。
|
|
10
|
+
|
|
11
|
+
项目目标很明确:
|
|
12
|
+
|
|
13
|
+
- 在本地完成 Codex 配置切换
|
|
14
|
+
- 写入前先备份
|
|
15
|
+
- 出错时可回滚
|
|
16
|
+
- 同时兼顾终端用户和 AI/自动化调用
|
|
17
|
+
|
|
18
|
+
## 现在可以做什么
|
|
19
|
+
|
|
20
|
+
当前 MVP 命令如下:
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
codexs list
|
|
24
|
+
codexs current
|
|
25
|
+
codexs switch <provider>
|
|
26
|
+
codexs status
|
|
27
|
+
codexs import <file>
|
|
28
|
+
codexs export <file>
|
|
29
|
+
codexs add <provider>
|
|
30
|
+
codexs remove <provider>
|
|
31
|
+
codexs doctor
|
|
32
|
+
codexs rollback
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
对应能力包括:
|
|
36
|
+
|
|
37
|
+
- 查看本地已管理的 provider
|
|
38
|
+
- 查看当前激活的 profile
|
|
39
|
+
- 安全切换 provider
|
|
40
|
+
- 导入和导出 provider 映射
|
|
41
|
+
- 新增和删除 provider
|
|
42
|
+
- 检查配置漂移和常见本地问题
|
|
43
|
+
- 在变更前自动备份,并在失败时回滚
|
|
44
|
+
|
|
45
|
+
## 简单用法
|
|
46
|
+
|
|
47
|
+
全局安装:
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
npm install -g @minniexcode/codex-switch
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
或者直接执行:
|
|
54
|
+
|
|
55
|
+
```bash
|
|
56
|
+
npx @minniexcode/codex-switch --help
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
检查 CLI 是否可用:
|
|
60
|
+
|
|
61
|
+
```bash
|
|
62
|
+
codexs --help
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
典型使用方式:
|
|
66
|
+
|
|
67
|
+
```bash
|
|
68
|
+
codexs list
|
|
69
|
+
codexs current
|
|
70
|
+
codexs add my-provider --profile my-provider --api-key sk-xxx
|
|
71
|
+
codexs switch my-provider
|
|
72
|
+
codexs status
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
给脚本或 AI 使用时建议加上:
|
|
76
|
+
|
|
77
|
+
```bash
|
|
78
|
+
codexs list --json
|
|
79
|
+
codexs status --json
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
通用参数:
|
|
83
|
+
|
|
84
|
+
```bash
|
|
85
|
+
--json
|
|
86
|
+
--codex-dir <path>
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
## 交互式体验
|
|
90
|
+
|
|
91
|
+
这个 CLI 同时支持显式命令和交互式终端流程。
|
|
92
|
+
|
|
93
|
+
- `codexs add` 在 TTY 里会补问缺失的必填项
|
|
94
|
+
- `codexs switch` 在未传 provider 时可以弹出选择列表
|
|
95
|
+
- `codexs remove` 支持交互式选择和确认删除
|
|
96
|
+
- `import`、`export`、`rollback` 在交互模式下会要求确认
|
|
97
|
+
- `--json` 模式保持非交互,适合自动化
|
|
98
|
+
|
|
99
|
+
## 管理哪些文件
|
|
100
|
+
|
|
101
|
+
`codex-switch` 主要围绕 `~/.codex/` 下的这些文件工作:
|
|
102
|
+
|
|
103
|
+
```text
|
|
104
|
+
~/.codex/
|
|
105
|
+
config.toml
|
|
106
|
+
auth.json
|
|
107
|
+
providers.json
|
|
108
|
+
backups/
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
存储模型:
|
|
112
|
+
|
|
113
|
+
- `providers.json` 是管理态的单一事实来源
|
|
114
|
+
- `config.toml` 和 `auth.json` 是运行态文件
|
|
115
|
+
- `backups/latest.json` 记录最近一次可回滚窗口
|
|
116
|
+
|
|
117
|
+
注意:`providers.json` 可能包含 API key,应视为本地敏感文件。
|
|
118
|
+
|
|
119
|
+
## 相关文档
|
|
120
|
+
|
|
121
|
+
- [English README](./README.md)
|
|
122
|
+
- [AI README](./README.AI.md)
|
|
123
|
+
- [产品概览](./docs/codex-switch-product-overview.md)
|
|
124
|
+
- [产品调研](./docs/codex-switch-product-research.md)
|
|
125
|
+
- [PRD](./docs/codex-switch-prd.md)
|
|
126
|
+
- [技术架构](./docs/codex-switch-technical-architecture.md)
|
|
127
|
+
- [命令设计](./docs/codex-switch-command-design.md)
|
|
128
|
+
|
|
129
|
+
## 最近 3 个版本更新
|
|
130
|
+
|
|
131
|
+
### 0.0.3
|
|
132
|
+
|
|
133
|
+
- 为 `add`、`switch`、`remove`、`import`、`export`、`rollback` 增加了交互式 TTY 流程
|
|
134
|
+
- 改进了帮助信息和命令级使用说明
|
|
135
|
+
- 增强了交互行为和参数处理相关测试覆盖
|
|
136
|
+
|
|
137
|
+
### 0.0.2
|
|
138
|
+
|
|
139
|
+
- 增加了统一的变更编排能力,包括写前备份、失败回滚和单进程锁
|
|
140
|
+
- 改进了 `status` 和 `doctor`,更清晰地识别运行态漂移
|
|
141
|
+
- 加强了底层仓储层和领域层,使配置写入更安全
|
|
142
|
+
|
|
143
|
+
### 0.0.1
|
|
144
|
+
|
|
145
|
+
- 发布了第一版 TypeScript CLI 实现
|
|
146
|
+
- 落地了核心 MVP 命令和基于文件的 provider 管理模型
|
|
147
|
+
- 补齐了首批产品、架构和命令设计文档
|
|
148
|
+
|
|
149
|
+
## 本地开发
|
|
150
|
+
|
|
151
|
+
```bash
|
|
152
|
+
npm install
|
|
153
|
+
npm run build
|
|
154
|
+
npm test
|
|
155
|
+
node dist/cli.js --help
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
## License
|
|
159
|
+
|
|
160
|
+
MIT
|
package/README.md
CHANGED
|
@@ -1,193 +1,231 @@
|
|
|
1
1
|
# @minniexcode/codex-switch
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
`codex-switch` is a local-first CLI for managing and switching Codex provider/profile configuration safely.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
`codex-switch` 是一个本地优先的 CLI,用来安全地管理和切换 Codex 的 provider/profile 配置。
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
- local-first
|
|
9
|
-
- safe by default
|
|
10
|
-
- AI-friendly
|
|
7
|
+
It is designed for users who work with multiple Codex providers, API keys, or profiles and want a repeatable, backup-first workflow instead of manually editing files under `~/.codex/`.
|
|
11
8
|
|
|
12
|
-
|
|
9
|
+
它面向同时维护多个 Codex provider、API key 或 profile 的用户,目标是用可重复、先备份再写入的方式替代手动修改 `~/.codex/` 下的文件。
|
|
13
10
|
|
|
14
|
-
|
|
15
|
-
codexs
|
|
16
|
-
```
|
|
11
|
+
## Overview | 简介
|
|
17
12
|
|
|
18
|
-
|
|
13
|
+
What it does:
|
|
19
14
|
|
|
20
|
-
|
|
15
|
+
- Initialize `providers.json` from an existing Codex directory
|
|
16
|
+
- List, show, add, edit, and remove provider records
|
|
17
|
+
- Switch the active provider/profile safely
|
|
18
|
+
- Import and export provider definitions
|
|
19
|
+
- Run diagnostics and detect local drift
|
|
20
|
+
- List backups and rollback to a previous managed state
|
|
21
21
|
|
|
22
|
-
|
|
22
|
+
它可以完成的事情:
|
|
23
23
|
|
|
24
|
-
|
|
24
|
+
- 从现有 Codex 目录初始化 `providers.json`
|
|
25
|
+
- 查看、新增、编辑、删除 provider 记录
|
|
26
|
+
- 安全切换当前激活的 provider/profile
|
|
27
|
+
- 导入和导出 provider 配置
|
|
28
|
+
- 运行诊断并识别本地配置漂移
|
|
29
|
+
- 查看备份并回滚到之前的受管状态
|
|
25
30
|
|
|
26
|
-
|
|
31
|
+
Current version: `0.0.4`
|
|
27
32
|
|
|
28
|
-
|
|
29
|
-
- heavier account or desktop tools that solve a broader problem than local switching
|
|
33
|
+
当前版本:`0.0.4`
|
|
30
34
|
|
|
31
|
-
|
|
35
|
+
## Install | 安装
|
|
32
36
|
|
|
33
|
-
|
|
34
|
-
- listing locally configured providers
|
|
35
|
-
- switching providers safely
|
|
36
|
-
- backing up config before mutation
|
|
37
|
-
- rolling back on failure
|
|
38
|
-
- importing and exporting provider mappings
|
|
39
|
-
- returning structured output for automation and AI agents
|
|
37
|
+
Install globally:
|
|
40
38
|
|
|
41
|
-
|
|
39
|
+
```bash
|
|
40
|
+
npm install -g @minniexcode/codex-switch
|
|
41
|
+
```
|
|
42
42
|
|
|
43
|
-
|
|
43
|
+
Or run directly:
|
|
44
44
|
|
|
45
|
-
```
|
|
46
|
-
|
|
47
|
-
config.toml
|
|
48
|
-
auth.json
|
|
49
|
-
providers.json
|
|
50
|
-
backups/
|
|
45
|
+
```bash
|
|
46
|
+
npx @minniexcode/codex-switch --help
|
|
51
47
|
```
|
|
52
48
|
|
|
53
|
-
|
|
49
|
+
全局安装:
|
|
50
|
+
|
|
51
|
+
```bash
|
|
52
|
+
npm install -g @minniexcode/codex-switch
|
|
53
|
+
```
|
|
54
54
|
|
|
55
|
-
|
|
56
|
-
- `config.toml` and `auth.json` are runtime mirrors that codex-switch synchronizes safely
|
|
57
|
-
- `backups/latest.json` tracks rollback state for the latest managed mutation window
|
|
58
|
-
- all writes should be backed up first
|
|
59
|
-
- failures should trigger rollback
|
|
60
|
-
- write operations should execute under a lightweight single-process file lock
|
|
61
|
-
- CLI output should stay stable and machine-readable
|
|
55
|
+
或者直接运行:
|
|
62
56
|
|
|
63
|
-
|
|
57
|
+
```bash
|
|
58
|
+
npx @minniexcode/codex-switch --help
|
|
59
|
+
```
|
|
64
60
|
|
|
65
|
-
|
|
61
|
+
CLI entry:
|
|
66
62
|
|
|
67
63
|
```bash
|
|
68
|
-
codexs
|
|
69
|
-
codexs current
|
|
70
|
-
codexs switch <provider>
|
|
71
|
-
codexs status
|
|
72
|
-
codexs import <file>
|
|
73
|
-
codexs export <file>
|
|
74
|
-
codexs add <provider>
|
|
75
|
-
codexs remove <provider>
|
|
76
|
-
codexs doctor
|
|
77
|
-
codexs rollback
|
|
64
|
+
codexs --help
|
|
78
65
|
```
|
|
79
66
|
|
|
80
|
-
|
|
67
|
+
命令入口:
|
|
81
68
|
|
|
82
69
|
```bash
|
|
83
|
-
--
|
|
84
|
-
--codex-dir <path>
|
|
70
|
+
codexs --help
|
|
85
71
|
```
|
|
86
72
|
|
|
87
|
-
##
|
|
73
|
+
## Quick Start | 快速开始
|
|
88
74
|
|
|
89
|
-
|
|
75
|
+
Take over an existing Codex directory:
|
|
90
76
|
|
|
91
|
-
```
|
|
92
|
-
|
|
93
|
-
"providers": {
|
|
94
|
-
"packycode": {
|
|
95
|
-
"profile": "packycode",
|
|
96
|
-
"apiKey": "sk-xxx",
|
|
97
|
-
"baseUrl": "https://example.com/v1",
|
|
98
|
-
"note": "primary free model route",
|
|
99
|
-
"tags": ["free", "daily"]
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
}
|
|
77
|
+
```bash
|
|
78
|
+
codexs setup
|
|
103
79
|
```
|
|
104
80
|
|
|
105
|
-
|
|
81
|
+
接管当前已有的 Codex 目录:
|
|
106
82
|
|
|
107
|
-
|
|
83
|
+
```bash
|
|
84
|
+
codexs setup
|
|
85
|
+
```
|
|
108
86
|
|
|
109
|
-
|
|
87
|
+
Inspect managed providers:
|
|
110
88
|
|
|
111
89
|
```bash
|
|
112
|
-
|
|
90
|
+
codexs list
|
|
91
|
+
codexs show my-provider
|
|
113
92
|
```
|
|
114
93
|
|
|
115
|
-
|
|
94
|
+
查看已管理的 provider:
|
|
116
95
|
|
|
117
96
|
```bash
|
|
118
|
-
|
|
97
|
+
codexs list
|
|
98
|
+
codexs show my-provider
|
|
119
99
|
```
|
|
120
100
|
|
|
121
|
-
|
|
101
|
+
Add and switch:
|
|
122
102
|
|
|
123
103
|
```bash
|
|
124
|
-
codexs --
|
|
104
|
+
codexs add my-provider --profile my-provider --api-key sk-xxx
|
|
105
|
+
codexs switch my-provider
|
|
125
106
|
```
|
|
126
107
|
|
|
127
|
-
|
|
108
|
+
新增并切换:
|
|
109
|
+
|
|
110
|
+
```bash
|
|
111
|
+
codexs add my-provider --profile my-provider --api-key sk-xxx
|
|
112
|
+
codexs switch my-provider
|
|
113
|
+
```
|
|
128
114
|
|
|
129
|
-
|
|
115
|
+
Check runtime state:
|
|
130
116
|
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
117
|
+
```bash
|
|
118
|
+
codexs current
|
|
119
|
+
codexs status
|
|
120
|
+
codexs doctor
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
检查当前运行状态:
|
|
124
|
+
|
|
125
|
+
```bash
|
|
126
|
+
codexs current
|
|
127
|
+
codexs status
|
|
128
|
+
codexs doctor
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
## Common Commands | 常用命令
|
|
132
|
+
|
|
133
|
+
```bash
|
|
134
|
+
codexs setup
|
|
135
|
+
codexs list
|
|
136
|
+
codexs show <provider>
|
|
137
|
+
codexs current
|
|
138
|
+
codexs status
|
|
139
|
+
codexs add <provider> --profile <name> --api-key <key>
|
|
140
|
+
codexs edit <provider> [--profile <name>] [--api-key <key>]
|
|
141
|
+
codexs switch <provider>
|
|
142
|
+
codexs remove <provider>
|
|
143
|
+
codexs import <file> [--merge]
|
|
144
|
+
codexs export <file>
|
|
145
|
+
codexs backups list
|
|
146
|
+
codexs rollback [backup-id]
|
|
147
|
+
codexs doctor
|
|
148
|
+
```
|
|
136
149
|
|
|
137
|
-
|
|
150
|
+
Command help:
|
|
138
151
|
|
|
139
|
-
|
|
152
|
+
```bash
|
|
153
|
+
codexs help switch
|
|
154
|
+
codexs help setup
|
|
155
|
+
```
|
|
140
156
|
|
|
141
|
-
|
|
142
|
-
- repository-style infra modules for providers, config, backups, and write locks
|
|
143
|
-
- a shared mutation orchestration contract that wraps backup, rollback, and lock handling
|
|
144
|
-
- safe write flows with backup manifests under `backups/`
|
|
145
|
-
- rollback support for `config.toml` and optional `auth.json`
|
|
146
|
-
- `status` and `doctor` expose live-state drift so future backfill/edit/sync flows can reuse the same core model
|
|
147
|
-
- stable `--json` envelopes for automation
|
|
148
|
-
- test coverage in `tests/` using a custom serial runner (`tests/run-tests.js`) because the current environment hits `node --test` worker/spawn restrictions
|
|
157
|
+
命令帮助:
|
|
149
158
|
|
|
150
|
-
|
|
159
|
+
```bash
|
|
160
|
+
codexs help switch
|
|
161
|
+
codexs help setup
|
|
162
|
+
```
|
|
151
163
|
|
|
152
|
-
|
|
164
|
+
## How It Works | 工作方式
|
|
153
165
|
|
|
154
|
-
-
|
|
155
|
-
- runtime state: `config.toml` and `auth.json`
|
|
156
|
-
- rollback state: `backups/latest.json` and timestamped backup manifests
|
|
166
|
+
By default, `codex-switch` operates on `~/.codex/`, and you can override the target with `--codex-dir`.
|
|
157
167
|
|
|
158
|
-
|
|
168
|
+
`codex-switch` 默认围绕 `~/.codex/` 工作,也可以通过 `--codex-dir` 指向其他目录。
|
|
159
169
|
|
|
160
|
-
|
|
170
|
+
Managed files:
|
|
161
171
|
|
|
162
|
-
|
|
172
|
+
```text
|
|
173
|
+
~/.codex/
|
|
174
|
+
config.toml
|
|
175
|
+
auth.json
|
|
176
|
+
providers.json
|
|
177
|
+
backups/
|
|
178
|
+
```
|
|
163
179
|
|
|
164
|
-
|
|
165
|
-
- each mutation creates a backup first and rolls back on failure
|
|
166
|
-
- `status` and `doctor` detect when the active runtime profile in `config.toml` is no longer mapped in `providers.json`
|
|
180
|
+
说明:
|
|
167
181
|
|
|
168
|
-
|
|
182
|
+
- `providers.json` is the managed provider registry
|
|
183
|
+
- `config.toml` and `auth.json` represent runtime state
|
|
184
|
+
- mutating commands back up before writing
|
|
185
|
+
- rollback is available after failed or undesired changes
|
|
169
186
|
|
|
170
|
-
|
|
187
|
+
- `providers.json` 是受管理的 provider 注册表
|
|
188
|
+
- `config.toml` 和 `auth.json` 代表当前运行态
|
|
189
|
+
- 所有写操作都会先备份再写入
|
|
190
|
+
- 变更失败或结果不符合预期时可以回滚
|
|
171
191
|
|
|
172
|
-
|
|
192
|
+
## Automation | 自动化
|
|
173
193
|
|
|
174
|
-
|
|
175
|
-
- a background daemon
|
|
176
|
-
- a full account management platform
|
|
177
|
-
- a proxy/router layer
|
|
178
|
-
- a remote sync service
|
|
194
|
+
This CLI supports both human TTY use and non-interactive automation.
|
|
179
195
|
|
|
180
|
-
|
|
196
|
+
这个 CLI 同时支持人工交互和非交互自动化。
|
|
181
197
|
|
|
182
|
-
|
|
198
|
+
Recommended global flags:
|
|
183
199
|
|
|
184
200
|
```bash
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
201
|
+
--json
|
|
202
|
+
--codex-dir <path>
|
|
203
|
+
--help
|
|
204
|
+
--version
|
|
189
205
|
```
|
|
190
206
|
|
|
191
|
-
|
|
207
|
+
建议:
|
|
208
|
+
|
|
209
|
+
- use `--json` for stable machine-readable output
|
|
210
|
+
- pass all required arguments explicitly in scripts or CI
|
|
211
|
+
- use `--codex-dir <path>` for sandbox or test environments
|
|
212
|
+
|
|
213
|
+
- 在脚本或 CI 中使用 `--json` 获取稳定输出
|
|
214
|
+
- 在非交互环境中显式传入所有必需参数
|
|
215
|
+
- 在测试环境中优先配合 `--codex-dir <path>` 使用
|
|
216
|
+
|
|
217
|
+
## Documentation | 文档
|
|
218
|
+
|
|
219
|
+
- [Detailed CLI Usage](./docs/cli-usage.md)
|
|
220
|
+
- [详细 CLI 使用文档](./docs/cli-usage.md)
|
|
221
|
+
- [Changelog](./CHANGELOG.md)
|
|
222
|
+
- [更新日志](./CHANGELOG.md)
|
|
223
|
+
- [AI README](./README.AI.md)
|
|
224
|
+
- [中文 README(历史版)](./README.CN.md)
|
|
225
|
+
- [Product Overview](./docs/codex-switch-product-overview.md)
|
|
226
|
+
- [Technical Architecture](./docs/codex-switch-technical-architecture.md)
|
|
227
|
+
- [0.0.4 Design Doc](./docs/codex-switch-v0.0.4-design.md)
|
|
228
|
+
|
|
229
|
+
## License | 许可证
|
|
192
230
|
|
|
193
231
|
MIT
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.editProvider = editProvider;
|
|
4
|
+
const errors_1 = require("../domain/errors");
|
|
5
|
+
const providers_1 = require("../domain/providers");
|
|
6
|
+
const fs_utils_1 = require("../infra/fs-utils");
|
|
7
|
+
const providers_repo_1 = require("../infra/providers-repo");
|
|
8
|
+
const run_mutation_1 = require("./run-mutation");
|
|
9
|
+
/**
|
|
10
|
+
* Updates selected fields on a single managed provider.
|
|
11
|
+
*/
|
|
12
|
+
function editProvider(args) {
|
|
13
|
+
(0, fs_utils_1.ensureDir)(args.codexDir);
|
|
14
|
+
const providers = (0, providers_repo_1.readProvidersFile)(args.providersPath);
|
|
15
|
+
const current = providers.providers[args.providerName];
|
|
16
|
+
if (!current) {
|
|
17
|
+
throw (0, errors_1.cliError)("PROVIDER_NOT_FOUND", `Provider "${args.providerName}" was not found.`, {
|
|
18
|
+
provider: args.providerName,
|
|
19
|
+
file: args.providersPath,
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
const updatedFields = [];
|
|
23
|
+
const nextRecord = (0, providers_1.cleanProviderRecord)({
|
|
24
|
+
profile: args.profile ?? current.profile,
|
|
25
|
+
apiKey: args.apiKey ?? current.apiKey,
|
|
26
|
+
baseUrl: args.baseUrl === null ? undefined : args.baseUrl ?? current.baseUrl,
|
|
27
|
+
note: args.note === null ? undefined : args.note ?? current.note,
|
|
28
|
+
tags: args.tags ?? current.tags,
|
|
29
|
+
});
|
|
30
|
+
if (args.profile !== undefined && args.profile !== current.profile) {
|
|
31
|
+
updatedFields.push("profile");
|
|
32
|
+
}
|
|
33
|
+
if (args.apiKey !== undefined && args.apiKey !== current.apiKey) {
|
|
34
|
+
updatedFields.push("apiKey");
|
|
35
|
+
}
|
|
36
|
+
if (args.baseUrl !== undefined && (args.baseUrl ?? undefined) !== current.baseUrl) {
|
|
37
|
+
updatedFields.push("baseUrl");
|
|
38
|
+
}
|
|
39
|
+
if (args.note !== undefined && (args.note ?? undefined) !== current.note) {
|
|
40
|
+
updatedFields.push("note");
|
|
41
|
+
}
|
|
42
|
+
if (args.tags !== undefined) {
|
|
43
|
+
updatedFields.push("tags");
|
|
44
|
+
}
|
|
45
|
+
return (0, run_mutation_1.runMutation)({
|
|
46
|
+
codexDir: args.codexDir,
|
|
47
|
+
backupsDir: args.backupsDir,
|
|
48
|
+
latestBackupPath: args.latestBackupPath,
|
|
49
|
+
operation: "edit",
|
|
50
|
+
files: [{ absolutePath: args.providersPath, relativePath: "providers.json" }],
|
|
51
|
+
mutate: () => {
|
|
52
|
+
(0, providers_repo_1.writeProvidersFile)(args.providersPath, {
|
|
53
|
+
providers: {
|
|
54
|
+
...providers.providers,
|
|
55
|
+
[args.providerName]: nextRecord,
|
|
56
|
+
},
|
|
57
|
+
});
|
|
58
|
+
return {
|
|
59
|
+
provider: args.providerName,
|
|
60
|
+
updatedFields,
|
|
61
|
+
};
|
|
62
|
+
},
|
|
63
|
+
});
|
|
64
|
+
}
|