@minniexcode/codex-switch 0.0.1 → 0.0.3
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 +105 -0
- package/README.CN.md +160 -0
- package/README.md +102 -111
- package/dist/app/add-provider.js +45 -0
- package/dist/app/export-providers.js +62 -0
- package/dist/app/get-current-profile.js +14 -0
- package/dist/app/get-status.js +75 -0
- package/dist/app/import-providers.js +74 -0
- package/dist/app/list-providers.js +23 -0
- package/dist/app/remove-provider.js +31 -0
- package/dist/app/rollback-latest.js +26 -0
- package/dist/app/run-doctor.js +130 -0
- package/dist/app/run-mutation.js +63 -0
- package/dist/app/switch-provider.js +43 -0
- package/dist/app/types.js +2 -0
- package/dist/cli/add-interactive.js +114 -0
- package/dist/cli/args.js +125 -0
- package/dist/cli/help.js +220 -0
- package/dist/cli/interactive.js +114 -0
- package/dist/cli/output.js +156 -0
- package/dist/cli/prompt.js +93 -0
- package/dist/cli.js +215 -26
- package/dist/domain/backup.js +2 -0
- package/dist/domain/config.js +106 -0
- package/dist/domain/errors.js +36 -0
- package/dist/domain/providers.js +92 -0
- package/dist/domain/runtime-state.js +56 -0
- package/dist/infra/backup-repo.js +151 -0
- package/dist/infra/codex-cli.js +53 -0
- package/dist/infra/codex-paths.js +58 -0
- package/dist/infra/config-repo.js +56 -0
- package/dist/infra/fs-utils.js +97 -0
- package/dist/infra/lock-repo.js +99 -0
- package/dist/infra/providers-repo.js +69 -0
- package/docs/codex-switch-command-design.md +646 -0
- package/docs/codex-switch-prd.md +24 -3
- package/docs/codex-switch-product-overview.md +2 -0
- package/docs/codex-switch-technical-architecture.md +1042 -0
- package/package.json +7 -4
package/README.AI.md
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
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 list
|
|
21
|
+
codexs current
|
|
22
|
+
codexs switch <provider>
|
|
23
|
+
codexs status
|
|
24
|
+
codexs import <file>
|
|
25
|
+
codexs export <file>
|
|
26
|
+
codexs add <provider>
|
|
27
|
+
codexs remove <provider>
|
|
28
|
+
codexs doctor
|
|
29
|
+
codexs rollback
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
Shared flags:
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
--json
|
|
36
|
+
--codex-dir <path>
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## Important Runtime Files
|
|
40
|
+
|
|
41
|
+
```text
|
|
42
|
+
~/.codex/
|
|
43
|
+
config.toml
|
|
44
|
+
auth.json
|
|
45
|
+
providers.json
|
|
46
|
+
backups/
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
Operational model:
|
|
50
|
+
|
|
51
|
+
- `providers.json` is the management-state source of truth
|
|
52
|
+
- `config.toml` and `auth.json` are runtime mirrors
|
|
53
|
+
- `backups/latest.json` tracks the latest rollback state
|
|
54
|
+
- mutating commands should back up first and run under a lightweight file lock
|
|
55
|
+
|
|
56
|
+
## Project Structure
|
|
57
|
+
|
|
58
|
+
```text
|
|
59
|
+
src/
|
|
60
|
+
app/
|
|
61
|
+
cli/
|
|
62
|
+
domain/
|
|
63
|
+
infra/
|
|
64
|
+
tests/
|
|
65
|
+
docs/
|
|
66
|
+
dist/
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
Layer intent:
|
|
70
|
+
|
|
71
|
+
- `cli`: argument parsing, help, TTY flows, output shaping
|
|
72
|
+
- `app`: command orchestration and use-case logic
|
|
73
|
+
- `domain`: pure domain rules and shared models
|
|
74
|
+
- `infra`: filesystem, lock, backup, config, and Codex integration code
|
|
75
|
+
|
|
76
|
+
## Command Entry Point
|
|
77
|
+
|
|
78
|
+
Use `codexs` directly for runtime interaction:
|
|
79
|
+
|
|
80
|
+
```bash
|
|
81
|
+
codexs --help
|
|
82
|
+
codexs list --json
|
|
83
|
+
codexs status --json
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
## Current Version Context
|
|
87
|
+
|
|
88
|
+
Current package version in this repository:
|
|
89
|
+
|
|
90
|
+
```text
|
|
91
|
+
0.0.3
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
Recent version summary:
|
|
95
|
+
|
|
96
|
+
- `0.0.3`: interactive TTY flows and improved help
|
|
97
|
+
- `0.0.2`: mutation orchestration, backups, rollback, locks, drift detection improvements
|
|
98
|
+
- `0.0.1`: initial TypeScript CLI and baseline docs
|
|
99
|
+
|
|
100
|
+
## Notes For Agents
|
|
101
|
+
|
|
102
|
+
- Prefer `--json` when invoking commands programmatically
|
|
103
|
+
- Treat `providers.json` as sensitive because it may contain API keys
|
|
104
|
+
- Do not assume silent write-back from runtime files into `providers.json`
|
|
105
|
+
- 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
|
@@ -2,169 +2,160 @@
|
|
|
2
2
|
|
|
3
3
|
`@minniexcode/codex-switch` is a local-first CLI for managing and switching Codex provider/profile configuration safely.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
It is built for people who use multiple Codex providers, API keys, or profiles and want a repeatable way to switch between them without manually editing files under `~/.codex/`.
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
- local-first
|
|
9
|
-
- safe by default
|
|
10
|
-
- AI-friendly
|
|
7
|
+
## What This Repository Is For
|
|
11
8
|
|
|
12
|
-
|
|
9
|
+
This repository contains the CLI implementation, package metadata, and product documents for `codex-switch`.
|
|
13
10
|
|
|
14
|
-
|
|
15
|
-
codexs
|
|
16
|
-
```
|
|
11
|
+
The project focuses on a simple idea:
|
|
17
12
|
|
|
18
|
-
|
|
13
|
+
- keep Codex profile switching local
|
|
14
|
+
- back up config before writes
|
|
15
|
+
- roll back on failure
|
|
16
|
+
- support both humans in a terminal and AI/automation workflows
|
|
19
17
|
|
|
20
|
-
|
|
18
|
+
## What It Can Do
|
|
21
19
|
|
|
22
|
-
|
|
20
|
+
Current MVP command set:
|
|
23
21
|
|
|
24
|
-
|
|
25
|
-
|
|
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
|
+
```
|
|
26
34
|
|
|
27
|
-
|
|
35
|
+
What that means in practice:
|
|
28
36
|
|
|
29
|
-
|
|
37
|
+
- list locally managed providers
|
|
38
|
+
- show the current active profile
|
|
39
|
+
- switch to another provider safely
|
|
40
|
+
- import and export provider mappings
|
|
41
|
+
- add or remove provider records
|
|
42
|
+
- detect config drift and common local issues
|
|
43
|
+
- back up managed files before mutation and roll back when needed
|
|
30
44
|
|
|
31
|
-
|
|
32
|
-
- heavier account or desktop tools that solve a broader problem than local switching
|
|
45
|
+
## Quick Start
|
|
33
46
|
|
|
34
|
-
|
|
47
|
+
### For Humans
|
|
35
48
|
|
|
36
|
-
|
|
37
|
-
- listing locally configured providers
|
|
38
|
-
- switching providers safely
|
|
39
|
-
- backing up config before mutation
|
|
40
|
-
- rolling back on failure
|
|
41
|
-
- importing and exporting provider mappings
|
|
42
|
-
- returning structured output for automation and AI agents
|
|
49
|
+
Install globally:
|
|
43
50
|
|
|
44
|
-
|
|
51
|
+
```text
|
|
52
|
+
npm install -g @minniexcode/codex-switch
|
|
53
|
+
```
|
|
45
54
|
|
|
46
|
-
|
|
55
|
+
Or run without installing globally:
|
|
47
56
|
|
|
48
57
|
```text
|
|
49
|
-
|
|
50
|
-
config.toml
|
|
51
|
-
auth.json
|
|
52
|
-
providers.json
|
|
53
|
-
backups/
|
|
58
|
+
npx @minniexcode/codex-switch --help
|
|
54
59
|
```
|
|
55
60
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
- `config.toml` remains the source of the active top-level `profile`
|
|
59
|
-
- `providers.json` stores provider-to-profile and provider-to-key mappings
|
|
60
|
-
- all writes should be backed up first
|
|
61
|
-
- failures should trigger rollback
|
|
62
|
-
- CLI output should stay stable and machine-readable
|
|
61
|
+
Check the CLI:
|
|
63
62
|
|
|
64
|
-
|
|
63
|
+
```text
|
|
64
|
+
codexs --help
|
|
65
|
+
```
|
|
65
66
|
|
|
66
|
-
|
|
67
|
+
Typical usage:
|
|
67
68
|
|
|
68
|
-
```
|
|
69
|
+
```text
|
|
69
70
|
codexs list
|
|
70
71
|
codexs current
|
|
71
|
-
codexs
|
|
72
|
+
codexs add my-provider --profile my-provider --api-key sk-xxx
|
|
73
|
+
codexs switch my-provider
|
|
72
74
|
codexs status
|
|
73
|
-
codexs import <file>
|
|
74
|
-
codexs export <file>
|
|
75
|
-
codexs add <provider>
|
|
76
|
-
codexs remove <provider>
|
|
77
|
-
codexs doctor
|
|
78
|
-
codexs rollback
|
|
79
75
|
```
|
|
80
76
|
|
|
81
|
-
|
|
77
|
+
### For LLM Agents
|
|
82
78
|
|
|
83
|
-
|
|
84
|
-
--json
|
|
85
|
-
--codex-dir <path>
|
|
86
|
-
```
|
|
79
|
+
Read this first:
|
|
87
80
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
Planned `providers.json` shape:
|
|
91
|
-
|
|
92
|
-
```json
|
|
93
|
-
{
|
|
94
|
-
"providers": {
|
|
95
|
-
"packycode": {
|
|
96
|
-
"profile": "packycode",
|
|
97
|
-
"apiKey": "sk-xxx",
|
|
98
|
-
"baseUrl": "https://example.com/v1",
|
|
99
|
-
"note": "primary free model route",
|
|
100
|
-
"tags": ["free", "daily"]
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
}
|
|
81
|
+
```text
|
|
82
|
+
./README.AI.md
|
|
104
83
|
```
|
|
105
84
|
|
|
106
|
-
|
|
85
|
+
Then install and use the project by following the agent-specific instructions in that file.
|
|
107
86
|
|
|
108
|
-
|
|
87
|
+
Reference:
|
|
109
88
|
|
|
110
|
-
|
|
89
|
+
- [AI README](./README.AI.md)
|
|
111
90
|
|
|
112
|
-
|
|
113
|
-
|
|
91
|
+
Shared flags:
|
|
92
|
+
|
|
93
|
+
```text
|
|
94
|
+
--json
|
|
95
|
+
--codex-dir <path>
|
|
114
96
|
```
|
|
115
97
|
|
|
116
|
-
|
|
98
|
+
## Interactive Use
|
|
117
99
|
|
|
118
|
-
|
|
119
|
-
npx @minniexcode/codex-switch
|
|
120
|
-
```
|
|
100
|
+
The CLI supports both explicit commands and guided terminal flows.
|
|
121
101
|
|
|
122
|
-
|
|
102
|
+
- `codexs add` prompts for missing required values in a real TTY
|
|
103
|
+
- `codexs switch` can show a provider selector when no provider is passed
|
|
104
|
+
- `codexs remove` supports interactive selection and confirmation
|
|
105
|
+
- `import`, `export`, and `rollback` ask for confirmation in interactive mode
|
|
106
|
+
- `--json` remains non-interactive for scripts and agents
|
|
123
107
|
|
|
124
|
-
|
|
125
|
-
|
|
108
|
+
## Files It Manages
|
|
109
|
+
|
|
110
|
+
`codex-switch` is designed around files under `~/.codex/`:
|
|
111
|
+
|
|
112
|
+
```text
|
|
113
|
+
~/.codex/
|
|
114
|
+
config.toml
|
|
115
|
+
auth.json
|
|
116
|
+
providers.json
|
|
117
|
+
backups/
|
|
126
118
|
```
|
|
127
119
|
|
|
128
|
-
|
|
120
|
+
Storage model:
|
|
129
121
|
|
|
130
|
-
|
|
122
|
+
- `providers.json` is the management source of truth
|
|
123
|
+
- `config.toml` and `auth.json` are runtime state
|
|
124
|
+
- `backups/latest.json` tracks the latest rollback window
|
|
131
125
|
|
|
132
|
-
|
|
133
|
-
- [Product Research](./docs/codex-switch-product-research.md)
|
|
134
|
-
- [PRD](./docs/codex-switch-prd.md)
|
|
126
|
+
`providers.json` may contain API keys, so it should be treated as a local secret.
|
|
135
127
|
|
|
136
|
-
##
|
|
128
|
+
## Documentation
|
|
137
129
|
|
|
138
|
-
|
|
130
|
+
User-oriented project docs:
|
|
139
131
|
|
|
140
|
-
-
|
|
141
|
-
-
|
|
142
|
-
-
|
|
143
|
-
-
|
|
144
|
-
-
|
|
145
|
-
-
|
|
132
|
+
- [Chinese README](./README.CN.md)
|
|
133
|
+
- [AI README](./README.AI.md)
|
|
134
|
+
- [Product Overview](./docs/codex-switch-product-overview.md)
|
|
135
|
+
- [Product Research](./docs/codex-switch-product-research.md)
|
|
136
|
+
- [PRD](./docs/codex-switch-prd.md)
|
|
137
|
+
- [Technical Architecture](./docs/codex-switch-technical-architecture.md)
|
|
138
|
+
- [Command Design](./docs/codex-switch-command-design.md)
|
|
146
139
|
|
|
147
|
-
##
|
|
140
|
+
## Latest 3 Versions
|
|
148
141
|
|
|
149
|
-
|
|
142
|
+
### 0.0.3
|
|
150
143
|
|
|
151
|
-
-
|
|
152
|
-
-
|
|
153
|
-
-
|
|
154
|
-
- a proxy/router layer
|
|
155
|
-
- a remote sync service
|
|
144
|
+
- Added interactive TTY flows for high-frequency commands such as `add`, `switch`, `remove`, `import`, `export`, and `rollback`
|
|
145
|
+
- Improved help output and command-specific guidance
|
|
146
|
+
- Expanded CLI test coverage for interactive and argument handling behavior
|
|
156
147
|
|
|
157
|
-
|
|
148
|
+
### 0.0.2
|
|
158
149
|
|
|
159
|
-
|
|
150
|
+
- Added mutation orchestration with backup-first writes, rollback handling, and single-process locking
|
|
151
|
+
- Improved `status` and `doctor` so they can detect runtime drift more clearly
|
|
152
|
+
- Strengthened repository and domain layers for safer config operations
|
|
160
153
|
|
|
161
|
-
|
|
154
|
+
### 0.0.1
|
|
162
155
|
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
node dist/cli.js --help
|
|
167
|
-
```
|
|
156
|
+
- Shipped the initial TypeScript CLI implementation
|
|
157
|
+
- Added the core MVP commands and file-based provider management model
|
|
158
|
+
- Added the first full set of product, architecture, and command design docs
|
|
168
159
|
|
|
169
160
|
## License
|
|
170
161
|
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.addProvider = addProvider;
|
|
4
|
+
const providers_1 = require("../domain/providers");
|
|
5
|
+
const errors_1 = require("../domain/errors");
|
|
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
|
+
* Adds a new provider record to the managed providers registry.
|
|
11
|
+
*/
|
|
12
|
+
function addProvider(args) {
|
|
13
|
+
(0, fs_utils_1.ensureDir)(args.codexDir);
|
|
14
|
+
const providers = (0, providers_repo_1.readProvidersFileIfExists)(args.providersPath);
|
|
15
|
+
if (providers.providers[args.providerName]) {
|
|
16
|
+
throw (0, errors_1.cliError)("INVALID_IMPORT_FILE", `Provider "${args.providerName}" already exists.`);
|
|
17
|
+
}
|
|
18
|
+
const next = {
|
|
19
|
+
providers: {
|
|
20
|
+
...providers.providers,
|
|
21
|
+
[args.providerName]: (0, providers_1.cleanProviderRecord)({
|
|
22
|
+
profile: args.profile,
|
|
23
|
+
apiKey: args.apiKey,
|
|
24
|
+
baseUrl: args.baseUrl ?? undefined,
|
|
25
|
+
note: args.note ?? undefined,
|
|
26
|
+
tags: args.tags,
|
|
27
|
+
}),
|
|
28
|
+
},
|
|
29
|
+
};
|
|
30
|
+
return (0, run_mutation_1.runMutation)({
|
|
31
|
+
codexDir: args.codexDir,
|
|
32
|
+
backupsDir: args.backupsDir,
|
|
33
|
+
latestBackupPath: args.latestBackupPath,
|
|
34
|
+
operation: "add",
|
|
35
|
+
files: [{ absolutePath: args.providersPath, relativePath: "providers.json" }],
|
|
36
|
+
mutate: () => {
|
|
37
|
+
// Persist only the normalized provider payload so later reads are deterministic.
|
|
38
|
+
(0, providers_repo_1.writeProvidersFile)(args.providersPath, next);
|
|
39
|
+
return {
|
|
40
|
+
provider: args.providerName,
|
|
41
|
+
profile: args.profile,
|
|
42
|
+
};
|
|
43
|
+
},
|
|
44
|
+
});
|
|
45
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.exportProviders = exportProviders;
|
|
37
|
+
const fs = __importStar(require("node:fs"));
|
|
38
|
+
const path = __importStar(require("node:path"));
|
|
39
|
+
const errors_1 = require("../domain/errors");
|
|
40
|
+
const fs_utils_1 = require("../infra/fs-utils");
|
|
41
|
+
const providers_repo_1 = require("../infra/providers-repo");
|
|
42
|
+
/**
|
|
43
|
+
* Exports the current providers registry to a user-specified file.
|
|
44
|
+
*/
|
|
45
|
+
function exportProviders(args) {
|
|
46
|
+
const absoluteTarget = path.resolve(args.targetFile);
|
|
47
|
+
if (fs.existsSync(absoluteTarget) && !args.force) {
|
|
48
|
+
throw (0, errors_1.cliError)("INVALID_IMPORT_FILE", "Export target already exists. Re-run with --force to overwrite.", {
|
|
49
|
+
file: absoluteTarget,
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
const providers = (0, providers_repo_1.readProvidersFile)(args.providersPath);
|
|
53
|
+
// Create the target directory first so exports work for nested paths.
|
|
54
|
+
(0, fs_utils_1.ensureDir)(path.dirname(absoluteTarget));
|
|
55
|
+
(0, providers_repo_1.writeProvidersFile)(absoluteTarget, providers);
|
|
56
|
+
return {
|
|
57
|
+
data: {
|
|
58
|
+
exportedTo: absoluteTarget,
|
|
59
|
+
count: Object.keys(providers.providers).length,
|
|
60
|
+
},
|
|
61
|
+
};
|
|
62
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getCurrentProfile = getCurrentProfile;
|
|
4
|
+
const config_repo_1 = require("../infra/config-repo");
|
|
5
|
+
/**
|
|
6
|
+
* Returns the currently active top-level Codex profile.
|
|
7
|
+
*/
|
|
8
|
+
function getCurrentProfile(configPath) {
|
|
9
|
+
return {
|
|
10
|
+
data: {
|
|
11
|
+
profile: (0, config_repo_1.readCurrentProfile)(configPath),
|
|
12
|
+
},
|
|
13
|
+
};
|
|
14
|
+
}
|