@huui/cdx-switcher 1.8.7

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 bjesuiter
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/NOTICE ADDED
@@ -0,0 +1,18 @@
1
+ cdx — community-maintained, modified fork
2
+
3
+ This repository is derived from codex-switcher:
4
+ https://github.com/bjesuiter/codex-switcher
5
+
6
+ Original work:
7
+ Copyright (c) 2025 bjesuiter
8
+ Licensed under the MIT License. See LICENSE.
9
+
10
+ Modifications:
11
+ Copyright (c) 2026 LittleHuui and contributors
12
+ Licensed under the MIT License. See LICENSE.
13
+
14
+ This is an independent community project. It is not affiliated with,
15
+ endorsed by, or sponsored by the original author or OpenAI.
16
+
17
+ OpenAI and Codex are referenced only to describe compatibility. Do not use
18
+ OpenAI branding or imply an official relationship with OpenAI.
package/README.md ADDED
@@ -0,0 +1,226 @@
1
+ # cdx
2
+
3
+ `cdx` 是一个社区维护的命令行工具,用于在本机保存的多个账号凭据之间切换,并将当前账号凭据写入兼容的开发工具配置中。
4
+
5
+ > 非官方项目:本仓库基于 [bjesuiter/codex-switcher](https://github.com/bjesuiter/codex-switcher) 二次开发,遵循 MIT 许可证。原作者署名、许可证和本分叉声明见 [NOTICE](./NOTICE) 与 [LICENSE](./LICENSE)。本项目与原作者及 OpenAI 均不存在隶属、赞助或认可关系。
6
+
7
+ ## 当前版本
8
+
9
+ ### 1.8.7
10
+
11
+ - 修复 Windows 上 OAuth 登录链接被 `cmd` 截断的问题,改用 Windows 系统 URL 协议处理器打开浏览器。
12
+ - 更新 OAuth 请求的 scope、state 与 originator 兼容处理,并按当前 Codex CLI 的格式写入 `auth.json`。
13
+ - 增加分叉来源说明、第三方依赖声明与发布前元数据检查。
14
+ - 移除仅用于 PKCE 的第三方 OAuth 依赖,改用 Node 内置加密实现。
15
+
16
+ 完整变更记录见 [CHANGELOG.md](./CHANGELOG.md)。
17
+
18
+ ## 使用范围与安全边界
19
+
20
+ - 仅使用你本人拥有或已获授权使用的账号;不要借此规避订阅、地区、用量、访问控制或服务条款限制。
21
+ - 登录后,本工具会在系统凭据库中保存令牌,并向目标工具写入本地认证文件。令牌等同于账号访问凭据,请不要提交、截图或分享这些文件。
22
+ - 本仓库不含 OpenAI 徽标或官方视觉素材。文档中出现 OpenAI、Codex、OpenCode、Pi 等名称仅用于说明兼容对象,不表示官方关系。
23
+
24
+ ## 支持的目标与系统
25
+
26
+ | 目标 | 写入位置 |
27
+ | --- | --- |
28
+ | Codex CLI | `~/.codex/auth.json`;Windows 为 `%USERPROFILE%\\.codex\\auth.json` |
29
+ | OpenCode | `~/.local/share/opencode/auth.json`;Windows 为 `%LOCALAPPDATA%\\opencode\\auth.json` |
30
+ | Pi Agent | `~/.pi/agent/auth.json`;Windows 为 `%USERPROFILE%\\.pi\\agent\\auth.json` |
31
+
32
+ | 系统 | 凭据存储 | 状态 |
33
+ | --- | --- | --- |
34
+ | macOS | Keychain | 已支持 |
35
+ | Windows | Windows Credential Manager | Beta,已针对 OAuth 浏览器启动修复 |
36
+ | Linux | Secret Service/keyring | Beta,需要可用的 keyring 服务 |
37
+
38
+ 运行环境需要 [Bun](https://bun.sh)。Linux 推荐先安装并启动 GNOME Keyring 或兼容的 Secret Service 服务。
39
+
40
+ ## 安装
41
+
42
+ 安装本工具需要先安装 [Bun](https://bun.sh)。
43
+
44
+ ### 安装已发布版本
45
+
46
+ 本项目发布到 npm 后,使用以下命令安装:
47
+
48
+ ```bash
49
+ bun install -g @huui/cdx-switcher
50
+ ```
51
+
52
+ 安装后验证:
53
+
54
+ ```bash
55
+ cdx --version
56
+ cdx --help
57
+ ```
58
+
59
+ ### 从当前源码使用
60
+
61
+ 在 npm 版本发布前,或希望直接使用当前源码时:
62
+
63
+ ```bash
64
+ git clone https://github.com/LittleHuui/codex-switcher.git
65
+ cd codex-switcher
66
+ bun install --frozen-lockfile
67
+ ```
68
+
69
+ 之后通过 Bun 执行命令,不会注册全局 `cdx`:
70
+
71
+ ```bash
72
+ bun cdx.ts status
73
+ bun cdx.ts login
74
+ ```
75
+
76
+ ## 快速操作流程
77
+
78
+ ### 1. 添加第一个账号
79
+
80
+ ```bash
81
+ cdx login
82
+ ```
83
+
84
+ 保持终端窗口开启。命令会启动本地回调地址 `http://localhost:1455/auth/callback` 并尝试打开浏览器;在浏览器完成授权后,浏览器会跳回该本地地址,终端将保存账号。
85
+
86
+ Windows 若没有打开浏览器、错误打开文件夹,或自动页仍报认证参数错误:
87
+
88
+ 1. 先确认运行的是本仓库发布的 1.8.7 或更高版本:`cdx --version`。
89
+ 2. 不要关闭运行 `cdx login` 的终端。
90
+ 3. 复制终端打印的**完整**授权链接,在正常浏览器地址栏重新打开;不要手动删改 `originator`、`state`、`scope`、`code_challenge` 等参数。
91
+ 4. 完成登录后,浏览器必须回跳到 `http://localhost:1455/auth/callback`,终端才会完成保存。
92
+
93
+ ### 2. 查看账号状态
94
+
95
+ ```bash
96
+ cdx status
97
+ ```
98
+
99
+ ### 3. 切换当前账号
100
+
101
+ 交互选择账号:
102
+
103
+ ```bash
104
+ cdx switch
105
+ ```
106
+
107
+ 切换到下一个账号:
108
+
109
+ ```bash
110
+ cdx switch --next
111
+ ```
112
+
113
+ 按账号 ID 或标签切换:
114
+
115
+ ```bash
116
+ cdx switch <账号-ID-或标签>
117
+ ```
118
+
119
+ 切换后,重新打开对应的 Codex CLI、OpenCode 或 Pi 会话,使其读取新的本地认证文件。
120
+
121
+ ### 4. 给账号设置标签
122
+
123
+ ```bash
124
+ cdx label
125
+ cdx label <账号-ID-或旧标签> <新标签>
126
+ ```
127
+
128
+ ### 5. 重新登录已有账号
129
+
130
+ ```bash
131
+ cdx relogin
132
+ cdx relogin <账号-ID-或标签>
133
+ ```
134
+
135
+ ## 常用命令
136
+
137
+ | 命令 | 用途 |
138
+ | --- | --- |
139
+ | `cdx` | 进入交互模式 |
140
+ | `cdx login` | 通过浏览器 OAuth 添加账号 |
141
+ | `cdx login --device-flow` | 使用设备授权流程;某些 VPS/IP 可能被 Cloudflare 拦截 |
142
+ | `cdx relogin [账号]` | 重新授权指定账号;不带账号时交互选择 |
143
+ | `cdx switch [账号]` | 切换账号;`--next` 切到下一个 |
144
+ | `cdx label [账号] [标签]` | 查看或修改账号标签 |
145
+ | `cdx status` | 查看账号、令牌过期时间与用量状态 |
146
+ | `cdx usage [账号]` | 查看所有或指定账号的用量 |
147
+ | `cdx doctor` | 显示认证文件位置、状态与运行环境能力 |
148
+ | `cdx keyring check` | 检查 Linux keyring 依赖和安全存储能力 |
149
+ | `cdx keyring install` | 在 Debian/Ubuntu/Mint 安装 Linux keyring 依赖 |
150
+ | `cdx migrate-secrets` | 将 macOS 旧 Keychain 条目迁移到默认后端 |
151
+ | `cdx complete <shell>` | 生成 `zsh`、`bash`、`fish` 或 `powershell` 补全脚本 |
152
+ | `cdx update-self` | 更新已发布的全局包;仅在你自己的 npm 包发布后使用 |
153
+
154
+ 所有命令和选项以 `cdx --help`、`cdx help <命令>` 为准。
155
+
156
+ ## 凭据与配置位置
157
+
158
+ 账号列表不包含明文令牌;令牌存入系统凭据库:
159
+
160
+ | 系统 | 账号列表 | 凭据库 |
161
+ | --- | --- | --- |
162
+ | macOS / Linux | `~/.config/cdx/accounts.json`,或 `$XDG_CONFIG_HOME/cdx/accounts.json` | macOS Keychain / Linux Secret Service |
163
+ | Windows | `%APPDATA%\\cdx\\accounts.json` | Windows Credential Manager |
164
+
165
+ 默认凭据后端为 `auto`。macOS 需要兼容旧条目时,可临时指定:
166
+
167
+ ```bash
168
+ cdx --secret-store legacy-keychain status
169
+ ```
170
+
171
+ 若某个平台只能使用降级安全存储,工具会要求明确确认。只有在理解风险时才可设置非交互覆盖:
172
+
173
+ ```bash
174
+ CDX_ALLOW_SECURE_STORE_FALLBACK=1
175
+ ```
176
+
177
+ Windows PowerShell 等价写法:
178
+
179
+ ```powershell
180
+ $env:CDX_ALLOW_SECURE_STORE_FALLBACK = "1"
181
+ ```
182
+
183
+ ## Shell 补全
184
+
185
+ ```bash
186
+ # zsh
187
+ source <(cdx complete zsh)
188
+
189
+ # bash
190
+ source <(cdx complete bash)
191
+ ```
192
+
193
+ Fish 和 PowerShell 请使用 `cdx complete fish`、`cdx complete powershell` 生成相应脚本后,按各自 shell 的配置方式加载。
194
+
195
+ ## 排错
196
+
197
+ ### OAuth 页面显示“缺少必填参数”
198
+
199
+ - 确认没有使用旧的全局 `cdx`、缓存链接或原项目构建产物。
200
+ - 使用 `cdx --version` 确认版本;重新安装自己的发布包后再重试。
201
+ - 通过终端输出的完整授权 URL 打开浏览器。该 URL 与本次运行的本地回调、state 和 PKCE verifier 绑定,不能复用旧链接。
202
+ - 若手动打开能成功而自动打开失败,请保留终端输出和 `cdx doctor` 结果后提交 Issue;不要公开令牌、回调 `code` 或完整授权 URL。
203
+
204
+ ### Linux 无法保存凭据
205
+
206
+ 先执行:
207
+
208
+ ```bash
209
+ cdx keyring check
210
+ ```
211
+
212
+ 在 Debian、Ubuntu 或 Mint 上可执行:
213
+
214
+ ```bash
215
+ cdx keyring install
216
+ ```
217
+
218
+ ### 远程 SSH / VPS 登录
219
+
220
+ 优先使用普通 `cdx login` 并按终端提示完成手动回调。设备授权模式可能遇到 Cloudflare 验证,不能作为可靠替代方案。
221
+
222
+ ## 许可证与署名
223
+
224
+ 本仓库保留了上游 MIT 许可证和原作者署名,并通过 `NOTICE` 明确列出二次开发关系。MIT 允许修改和再发布,但要求在副本或实质部分中保留版权和许可声明。对第三方依赖,见 [THIRD_PARTY_NOTICES.md](./THIRD_PARTY_NOTICES.md)。
225
+
226
+ 这份说明是工程层面的合规措施,不构成法律意见;若计划商业化、使用品牌进行宣传,或将工具提供给组织用户,建议让具备资质的律师按你的实际发布地区、服务条款和使用方式复核。
@@ -0,0 +1,21 @@
1
+ # Third-party notices
2
+
3
+ `cdx.mjs` keeps its runtime dependencies external. They are declared in the
4
+ published `package.json` and installed by the package manager rather than being
5
+ copied into this project's bundle.
6
+
7
+ The direct runtime dependencies and their declared SPDX licenses at the time of
8
+ this release are:
9
+
10
+ | Package | Version range | License |
11
+ | --- | --- | --- |
12
+ | `@bjesuiter/cross-keychain` | `1.1.0-jb.0` | MIT |
13
+ | `@bomb.sh/tab` | `^0.0.14` | MIT |
14
+ | `@clack/prompts` | `^1.1.0` | MIT |
15
+ | `age-encryption` | `^0.3.0` | BSD-3-Clause |
16
+ | `commander` | `^14.0.3` | MIT |
17
+
18
+ Each dependency remains subject to its own license. Before changing or adding
19
+ dependencies, maintainers must review the exact version's package metadata and
20
+ license text, and update this file when the set of distributed dependencies
21
+ changes.