easymagic 0.5.0 → 0.5.2
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/AUDIT.md +14 -0
- package/BACKEND_INTEGRATION.md +20 -4
- package/README.md +10 -4
- package/RELEASING.md +35 -0
- package/dist/cli.js +248 -28
- package/package.json +2 -1
package/AUDIT.md
CHANGED
|
@@ -49,3 +49,17 @@
|
|
|
49
49
|
AI 模式明确通过 `ai` / `--ai` 选择,默认非阻塞、不打开浏览器。正常结果、帮助、版本、缺少子命令和错误均验证为 JSON;原来的 `--json` 保持兼容。
|
|
50
50
|
|
|
51
51
|
验证:166 项测试、1106 个断言通过,18 种 Agent 配置/备份/恢复流程通过;真实 PTY 验证 40/80/120 列、NO_COLOR、TERM=dumb、隐藏 PAT、取消不写入以及请求子进程回收。独立复核确认取消行为、完整确认信息及 10 种 AI 输出路径。新终端依赖的许可证随安装包提供,依赖审计未报告已知漏洞。
|
|
52
|
+
|
|
53
|
+
## 0.5.1 首页品牌与语言偏好
|
|
54
|
+
|
|
55
|
+
首页新增始终可识别的“中文 / English”菜单项,选择后立即刷新界面并将偏好保存到独立 `preferences.json`;不改账号元数据、PAT 或推理密钥。优先级为显式 `--lang`、`EASYMAGIC_LANG`、保存的界面偏好、系统语言。AI 模式不读取该偏好。
|
|
56
|
+
|
|
57
|
+
品牌区采用原 EasyMagic EM 标识的纯文本终端形式,配有本地双语介绍和完整官网地址;窄屏及 `TERM=dumb` 使用紧凑版本,不请求远程图片。172 项测试、1228 个断言、18 种客户端流程通过;真实 PTY 与独立复验覆盖语言切换、记忆、取消、NO_COLOR 和 40/80/120 列显示。
|
|
58
|
+
|
|
59
|
+
## 未发布修复:首次引导与登录诊断
|
|
60
|
+
|
|
61
|
+
首次手动启动固定先选择语言,再进入引导配置;用户可选择稍后配置,此后默认打开控制台,并可从“引导配置”重新进入。`onboardingCompleted` 只表示已经看过首次介绍,不代表登录或 Agent 配置成功。取消语言选择或尚未确认介绍时不写完成标记。
|
|
62
|
+
|
|
63
|
+
浏览器设备授权端点返回 404/405 时,CLI 返回 `DEVICE_LOGIN_UNSUPPORTED` 并说明站点尚未提供对应接口。手动界面可保留原站点及 profile,改用隐藏输入的 PAT 登录。403 权限拒绝及安全网关拦截不触发这种回退,不通过重复输入凭据绕过服务端限制。
|
|
64
|
+
|
|
65
|
+
现场只读检查确认官网设备授权端点返回 404,而公共站点状态接口可用。未在生产环境创建授权请求或写入配置,也未部署后端。发布工作流已经取消并禁用,另以 `NPM_PUBLISH_ENABLED` 开关保护后续自动发布;本次修复不发布 npm。
|
package/BACKEND_INTEGRATION.md
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
- 后端补丁基于提交 `4ee7497aa`,开发分支为 `feat/cli-device-login`。
|
|
6
6
|
- `backend/device-login.patch`:适用于以上基础提交的功能补丁。
|
|
7
7
|
- `backend/device-login.current-worktree.patch`:根据集成时的主站既有工作区生成,只追加本功能,保留原有 gzip、日志及其它改动。
|
|
8
|
-
- 已将 current-worktree
|
|
8
|
+
- 已将 current-worktree 补丁追加应用到当前主站源码,保留原有改动。网站发布状态见本文末尾。用于其他检出版本时,先在目标目录运行 `git apply --check <补丁路径>`;检查通过后才应用,不能把隔离工作区整体覆盖到主站。
|
|
9
9
|
|
|
10
10
|
## 端点和用户流程
|
|
11
11
|
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
|
|
29
29
|
复用已有 `auth_flows` 和 `user_access_tokens`,无新增表或列。设备秘密只保存 HMAC;配对码索引也只保存 HMAC。完整 PAT 仅在领取时从高熵设备秘密派生,在数据库保存指纹,不保存可用明文。领取和创建 PAT 在同一事务内完成;先锁定流程和用户,保证同一请求仅领取一次,并发请求不超过账户 PAT 数量上限。领取前重新验证原批准会话,撤销会话后不能继续领令牌。
|
|
30
30
|
|
|
31
|
-
10
|
|
31
|
+
10 分钟过期、限流、最小轮询间隔、拒绝、取消和单次领取都由服务端执行。轮询使用独立限流桶,不消耗登录/审批额度;重复审批、取消与领取使用一致锁顺序,防止死锁和已取消请求被误报批准。浏览器批准必须同时满足有效会话、可信 Origin 和使用独立 `cli.device.approve` scope、与本次配对码/权限/到期时间绑定的一次性安全证明。确认页使用 nonce CSP、`frame-ancestors 'none'`、`Referrer-Policy: no-referrer`、`Cache-Control: no-store`。页面使用 `textContent` 输出设备名;设备码、公开配对码及 PAT 不写入访问日志,安全审计只记录名称、权限、有效期与结果。
|
|
32
32
|
|
|
33
33
|
实现参考 OWASP Authentication、Session Management、OAuth2、CSRF Prevention Cheat Sheets 的传输、重验证、一次性令牌、同源验证和不记录秘密原则;不宣称安全认证。生产部署仍需配置 HTTPS 和可信浏览器来源,并沿用现有 cookie/代理设置。
|
|
34
34
|
|
|
@@ -52,7 +52,7 @@
|
|
|
52
52
|
|
|
53
53
|
配套改动已通过增量补丁应用到主站源码,保留了既有工作区修改。在后端源码目录执行 `GOTOOLCHAIN=go1.27.4 go test ./model ./controller ./router -run 'TestCLIDevice|TestAccessTokenRoute' -count=1`,三个包全部通过。
|
|
54
54
|
|
|
55
|
-
Playwright 在隔离的 `http://127.0.0.1:18891` 测试服务完成了真实页面加载、现有登录态恢复、密码再验证、确认授权,以及等待中的实际 CLI 领取并保存 PAT。桌面和 390px 手机视口截图保存在 `output/playwright/`(本地验收产物,不打进 npm
|
|
55
|
+
Playwright 在隔离的 `http://127.0.0.1:18891` 测试服务完成了真实页面加载、现有登录态恢复、密码再验证、确认授权,以及等待中的实际 CLI 领取并保存 PAT。桌面和 390px 手机视口截图保存在 `output/playwright/`(本地验收产物,不打进 npm 包)。测试服务和测试账户均非生产。生产站点须使用含这些端点的后端版本;网站发布状态见本文末尾。
|
|
56
56
|
|
|
57
57
|
## 0.4:可恢复的自动配置与首次协议确认
|
|
58
58
|
|
|
@@ -62,7 +62,7 @@ Playwright 在隔离的 `http://127.0.0.1:18891` 测试服务完成了真实页
|
|
|
62
62
|
|
|
63
63
|
新增的 `controller/cli_device_test.go` 覆盖页面安全响应头和实际内嵌脚本的同意状态:未勾选、只勾选一份、过期、版本变化、签署失败、已签署、拒绝以及更改配对码。测试与 HTML 已同步到主站源码,两份增量补丁同步更新,并通过各自工作区的 `git apply --reverse --check` 核对。
|
|
64
64
|
|
|
65
|
-
本次安全复核参考 [OWASP ASVS 5.0](https://github.com/OWASP/ASVS/tree/v5.0.
|
|
65
|
+
本次安全复核参考 [OWASP ASVS 5.0](https://github.com/OWASP/ASVS/tree/v5.0.0_release) 的 V3(浏览器安全)、V6(认证)、V7(会话管理)章节,以及 [Authentication](https://cheatsheetseries.owasp.org/cheatsheets/Authentication_Cheat_Sheet.html)、[Session Management](https://cheatsheetseries.owasp.org/cheatsheets/Session_Management_Cheat_Sheet.html)、[CSRF Prevention](https://cheatsheetseries.owasp.org/cheatsheets/Cross-Site_Request_Forgery_Prevention_Cheat_Sheet.html) 指引。验证范围是上述控制及回归用例,不代表获得安全认证。
|
|
66
66
|
|
|
67
67
|
0.4 CLI 已通过本地完整检查:136 项测试、743 个断言、独立安装包验证及 18 个客户端配置/备份/恢复流程。对应提交 `3fc6143` 的 [跨平台 CI](https://github.com/XzlmTech/easymagic-cli/actions/runs/46566200923) 全部 9 项通过,包含 Linux/macOS/Windows 的 Node 22/24 测试和三个系统上的 Claude Code/Codex 原生检查。新增状态与调用契约见 [AI_USAGE.md](AI_USAGE.md) 和 [CLI_CONTRACT.md](CLI_CONTRACT.md)。
|
|
68
68
|
|
|
@@ -77,3 +77,19 @@ python3 e2e/onboard-browser.py --backend-bin /path/to/test-backend \
|
|
|
77
77
|
--fixture-db /path/to/test-fixture.db --credential-file /private/test-login.json \
|
|
78
78
|
--playwright-wrapper /path/to/playwright_cli.sh --port 18894
|
|
79
79
|
```
|
|
80
|
+
|
|
81
|
+
## 2026-12-01 授权安全复核
|
|
82
|
+
|
|
83
|
+
补丁新增独立设备审批证明,不能混用普通 PAT 创建证明,也不能在同权限、同到期时间的两个设备请求间互换。已验证缺少/错误 Origin、缺少证明、无效会话、账号禁用、密码版本变化、撤销/过期会话、取消/过期请求、重复领取与并发 PAT 数量限制均不能签发令牌。
|
|
84
|
+
|
|
85
|
+
最终候选基于线上 `v20261130T112429+0800-72c6e0631a9a` 的冻结源码,仅追加 6 个文件、修改 9 个文件;数据库结构、依赖、既有管理后台与用户前端保持基线。已通过 SQLite 3.50.4、MySQL 8.4.13、PostgreSQL 18.6 的真实数据库回归、授权相关 Go 测试与 vet,以及真实浏览器协议确认 → CLI 恢复 → 单次创建密钥 → Claude Code 配置的完整验收。
|
|
86
|
+
|
|
87
|
+
适用控制参考 OWASP ASVS **5.0.0**:6.3.1(限流)、6.6.2(请求绑定)、7.2.1/7.2.3(服务端验证/随机性)、7.4.1/7.4.2(撤销/禁用)、10.4.9/10.4.11(撤销/最小权限)、10.7.1/10.7.2(明确同意),以及 Authentication、Session Management、CSRF、OAuth2 Cheat Sheets。设备码钓鱼无法仅靠协议完全消除:用户应只确认自己终端发起的代码;此页始终展示该警示。此复核仅覆盖本次功能,不是整站安全认证。
|
|
88
|
+
|
|
89
|
+
### 网站发布状态
|
|
90
|
+
|
|
91
|
+
2026-12-01 已部署到 `https://easymagic.ai`,后端版本 `v20261201T171639+0800-919955c75b35`。公网设备端点、授权页及尾斜杠路由、安全响应头和未授权拒绝验证通过;实际 CLI start/cancel 通过。线上及本机入口共 46 项检查通过,发布探针 2707 次、失败 0 次。经用户同意仅让一条旧空闲 WebSocket 重连一次完成交接。本次网站部署无需重新安装 npm 包即可获得服务端授权能力。CLI 发布流程见 [RELEASING.md](RELEASING.md)。
|
|
92
|
+
|
|
93
|
+
### 授权页呈现
|
|
94
|
+
|
|
95
|
+
授权页改为紧凑的品牌确认窗口。权限摘要、账户、设备与配对码保留,权限细项及两份协议全文默认折叠;未签署用户仍需分别主动勾选。单一验证方式不显示多余选择框,读取失败可原地重试,授权/取消后显示独立结果。仅精简呈现,原有服务端同源检查、一次性证明和权限范围不变。
|
package/README.md
CHANGED
|
@@ -13,7 +13,7 @@ npm install -g easymagic
|
|
|
13
13
|
easymagic --help
|
|
14
14
|
```
|
|
15
15
|
|
|
16
|
-
也可以不全局安装,直接执行 `npx --yes easymagic --help`。离线分发则使用安装包:`npm install -g ./easymagic-0.5.
|
|
16
|
+
也可以不全局安装,直接执行 `npx --yes easymagic --help`。离线分发则使用安装包:`npm install -g ./easymagic-0.5.2.tgz`。
|
|
17
17
|
|
|
18
18
|
源码构建需要 Bun:
|
|
19
19
|
|
|
@@ -35,7 +35,13 @@ easymagic
|
|
|
35
35
|
easymagic interactive
|
|
36
36
|
```
|
|
37
37
|
|
|
38
|
-
|
|
38
|
+
首次在终端运行时,先选择 **简体中文 / English**,然后进入配置引导:连接账户、选择 Agent、确认模型和写入目标。也可选择“稍后配置,进入控制台”;这表示已看过首次引导,不表示已经登录或配置成功。之后再直接运行 `easymagic` 就进入控制台,首页的 **引导配置 / Guided setup** 可随时重新打开向导。取消首次语言选择不会保存已完成状态。
|
|
39
|
+
|
|
40
|
+
手动控制台使用方向键选择、Enter 确认,按 Ctrl+C 取消当前操作或退出。`TERM=dumb` 的交互终端改用编号输入,输入 `q` 返回或退出;`NO_COLOR` 会关闭颜色。首页包含配置 Agent、引导配置、登录与切换账号、密钥管理、模型和用量、诊断、配置恢复及操作记录。打开语言选择和进入首页不发起网络请求,实际请求和变更在选择具体操作后执行。密码式 PAT 输入不回显,删除、恢复等变更需要确认;取消不会被当成确认。
|
|
41
|
+
|
|
42
|
+
从 0.5.1 起,首页的 **中文 / English** 可立即切换整套菜单语言,并记住选择。语言偏好与首次引导记录保存在 CLI 配置目录的 `preferences.json`,与登录凭据分开;取消选择不会更改偏好。启动时的优先级为 `--lang` > `EASYMAGIC_LANG` > 已保存的菜单语言 > 系统语言。比如 `easymagic --lang en` 可临时用英文打开,首页语言选项仍可随时切换。AI 模式不读取手动菜单的语言偏好。
|
|
43
|
+
|
|
44
|
+
首页同时显示 EasyMagic 终端品牌标识、简短介绍和官网 `https://easymagic.ai`;窄终端使用紧凑布局,品牌区不会代替账户状态或操作菜单。
|
|
39
45
|
|
|
40
46
|
AI 和脚本使用明确的另一种入口:
|
|
41
47
|
|
|
@@ -64,7 +70,7 @@ easymagic onboard codex
|
|
|
64
70
|
|
|
65
71
|
CLI 会复用当前有效登录;未登录时会打开本站授权页。用户登录网站、核对终端配对码并确认授权后,CLI 自动取得管理 PAT、创建客户端专用推理密钥、选择可用分组与模型并写入配置。需要签署 API 密钥使用协议时,由用户在浏览器中阅读并勾选。授权后无需手工复制密钥。
|
|
66
72
|
|
|
67
|
-
浏览器登录要求网站已部署配套 device-login 后端,见 [BACKEND_INTEGRATION.md](BACKEND_INTEGRATION.md)
|
|
73
|
+
浏览器登录要求网站已部署配套 device-login 后端,见 [BACKEND_INTEGRATION.md](BACKEND_INTEGRATION.md)。若设备授权接口返回 404/405,CLI 会明确提示 `DEVICE_LOGIN_UNSUPPORTED`,手动界面可当场改用 PAT 登录;已输入的站点和账户配置名会继续使用。EasyMagic 官网现已提供设备授权接口;其他尚未更新的站点可使用下面的 PAT 登录,然后运行 `onboard`,仍可自动建密钥与配置。
|
|
68
74
|
|
|
69
75
|
可显式指定分组、模型和协议:
|
|
70
76
|
|
|
@@ -204,4 +210,4 @@ bun run e2e
|
|
|
204
210
|
|
|
205
211
|
`check` 包含类型检查、单元/恢复流程测试、构建、安装包离线安装、18 个客户端的配置/备份/恢复检查。真实客户端验证范围见 Agent 文档。`e2e` 需独立 loopback 测试后端,使用 `EASYMAGIC_E2E_BASE_URL` 和 `EASYMAGIC_E2E_TOKEN_FILE`;禁止连接生产环境。
|
|
206
212
|
|
|
207
|
-
代码仓库:[XzlmTech/easymagic-cli](https://github.com/XzlmTech/easymagic-cli)
|
|
213
|
+
代码仓库:[XzlmTech/easymagic-cli](https://github.com/XzlmTech/easymagic-cli)。新版本推送到主分支并通过完整 CI 后,GitHub Actions 使用 npm 可信发布自动上线;已有版本自动跳过。维护者可通过发布开关暂停或恢复自动发布。维护者的一次性绑定和恢复方法见 [RELEASING.md](RELEASING.md)。
|
package/RELEASING.md
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# npm 自动发布
|
|
2
|
+
|
|
3
|
+
`.github/workflows/release.yml` 使用 GitHub Actions OIDC 可信发布,不保存长期 npm token。当前仓库保持私有;npm 不为私有源码生成 provenance,但支持这种可信发布方式。
|
|
4
|
+
|
|
5
|
+
自动发布由工作流启用状态和仓库变量 `NPM_PUBLISH_ENABLED` 共同控制。正常发布时启用 `release.yml`,并设为 `true`;需要暂停时禁用工作流并设为 `false`。恢复发布必须同时重新启用工作流并显式设为 `true`。
|
|
6
|
+
|
|
7
|
+
## 一次性绑定
|
|
8
|
+
|
|
9
|
+
包维护者需要在已启用双重验证的 npm 账号上执行:
|
|
10
|
+
|
|
11
|
+
```sh
|
|
12
|
+
npm trust github easymagic --repo XzlmTech/easymagic-cli \
|
|
13
|
+
--file release.yml --allow-publish --yes
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
这一步创建未来自动发布的信任关系,npm 会要求一次浏览器确认。授权范围固定为该仓库的 `release.yml`。不绑定 GitHub environment,避免引入每次部署的人工审核。拥有仓库写权限的人可以通过这个工作流发布,应按维护者权限管理仓库。
|
|
17
|
+
|
|
18
|
+
新信任配置应在创建后两天内完成首次可信发布;第一次需要使用尚未发布的新版本,不能覆盖已有版本。
|
|
19
|
+
|
|
20
|
+
## 以后如何发布
|
|
21
|
+
|
|
22
|
+
1. 完成改动,更新 `package.json` 中的稳定版本号。
|
|
23
|
+
2. 推送到 `main`,或将经过审阅的 PR 合并到 `main`。
|
|
24
|
+
3. `Test and package` 的全部 CI 通过后自动启动 npm 发布。
|
|
25
|
+
4. 工作流再次验证同一个提交,构建安装包,通过短期 OIDC 凭据发布,并检查公开包的完整性。
|
|
26
|
+
|
|
27
|
+
无需逐次网页授权、创建 npm token 或手动运行 `npm publish`。普通文档提交或没有升级版本号的提交,发现版本已存在就跳过。网络失败和认证错误会让流程失败,不能被当成“版本不存在”。排队中的旧版本不会覆盖更新的 `latest`。
|
|
28
|
+
|
|
29
|
+
工作流仅响应本仓库 `main` 的成功 push CI,PR 验证不会触发发布。也可在 GitHub Actions 中手动运行 `Publish npm package`,仅允许选择 `main`,同样先检查版本并运行验证。发布任务使用串行锁,避免同时提交重复版本。
|
|
30
|
+
|
|
31
|
+
## 失败恢复
|
|
32
|
+
|
|
33
|
+
先查看 Actions 中失败的步骤。npm 可能接受发布后异步处理数分钟,此时不要重复发布;先确认 `npm view easymagic@VERSION version`。已发布的版本不可覆盖,修改发布内容必须升级版本号。`scripts/npm-release-state.mjs --verify` 用于核对已构建安装包与公开包的完整性。
|
|
34
|
+
|
|
35
|
+
若可信配置被撤销、过期或绑定的仓库/工作流改名,重新配置该信任关系时才需要再次由维护者验证。`npm trust list easymagic --json` 可只读检查绑定。
|
package/dist/cli.js
CHANGED
|
@@ -2254,6 +2254,13 @@ function redactSecrets(value, secrets = []) {
|
|
|
2254
2254
|
}
|
|
2255
2255
|
|
|
2256
2256
|
// src/api.ts
|
|
2257
|
+
function edgeAccessMessage(status, body) {
|
|
2258
|
+
const value = body;
|
|
2259
|
+
if (status === 403 && (value?.cloudflare_error === true || value?.error_code === 1010 || value?.error_name === "browser_signature_banned")) {
|
|
2260
|
+
return "The site security gateway blocked this CLI request (HTTP 403). Ask the site administrator to allow the CLI API routes. Changing or re-entering your PAT will not fix this block.";
|
|
2261
|
+
}
|
|
2262
|
+
return;
|
|
2263
|
+
}
|
|
2257
2264
|
function requireCredentials() {
|
|
2258
2265
|
const credentials = resolveCredentials();
|
|
2259
2266
|
if (!credentials)
|
|
@@ -2292,6 +2299,9 @@ async function requestJSON(method, path, body, credentials = requireCredentials(
|
|
|
2292
2299
|
throw new ApiError(`Server returned non-JSON content (HTTP ${response.status}).${unknown ? " The write result is unknown; reconcile before retrying." : ""}`, unknown ? "WRITE_OUTCOME_UNKNOWN" : "INVALID_RESPONSE", response.status, unknown ? "unknown" : "failed");
|
|
2293
2300
|
}
|
|
2294
2301
|
const envelope = json;
|
|
2302
|
+
const edgeMessage = edgeAccessMessage(response.status, json);
|
|
2303
|
+
if (edgeMessage)
|
|
2304
|
+
throw new ApiError(edgeMessage, "SITE_ACCESS_BLOCKED", response.status, "failed");
|
|
2295
2305
|
if (!response.ok || envelope && envelope.success === false) {
|
|
2296
2306
|
let message = typeof envelope?.message === "string" && envelope.message || typeof envelope?.message_key === "string" && envelope.message_key || `HTTP ${response.status}`;
|
|
2297
2307
|
if (response.status === 401)
|
|
@@ -3093,15 +3103,22 @@ async function request2(baseURL, route, body) {
|
|
|
3093
3103
|
} catch {
|
|
3094
3104
|
throw new DeviceLoginError("Device login could not reach the site. The saved flow can be resumed.", "network_error");
|
|
3095
3105
|
}
|
|
3106
|
+
if ([404, 405].includes(response.status) && ["/api/cli/device/capabilities", "/api/cli/device/start"].includes(route)) {
|
|
3107
|
+
throw new DeviceLoginError("This site has not deployed compatible CLI browser authorization. Use a personal access token with login --token-stdin, or ask the site administrator to deploy the CLI device-login backend.", "DEVICE_LOGIN_UNSUPPORTED", response.status);
|
|
3108
|
+
}
|
|
3096
3109
|
let json;
|
|
3097
3110
|
try {
|
|
3098
3111
|
json = await response.json();
|
|
3099
3112
|
} catch {
|
|
3100
|
-
throw new DeviceLoginError(
|
|
3113
|
+
throw new DeviceLoginError(`The site returned an invalid CLI device-login response (HTTP ${response.status}). Use login --token-stdin or ask the site administrator to check the backend.`, "invalid_response", response.status);
|
|
3101
3114
|
}
|
|
3102
3115
|
if (!response.ok || json?.success !== true) {
|
|
3103
|
-
|
|
3104
|
-
|
|
3116
|
+
if (response.status === 403 && (json?.cloudflare_error === true || json?.error_code === 1010 || json?.error_name === "browser_signature_banned")) {
|
|
3117
|
+
throw new DeviceLoginError("Site security rules blocked CLI access (Cloudflare HTTP 403). Ask the site administrator to allow CLI API requests; changing login credentials will not resolve this block.", "SITE_ACCESS_BLOCKED", response.status);
|
|
3118
|
+
}
|
|
3119
|
+
const recognized = ["authorization_pending", "slow_down", "expired_token", "access_denied", "already_consumed", "authorization_revoked", "access_token_limit"];
|
|
3120
|
+
const code = typeof json?.code === "string" && recognized.includes(json.code) ? json.code : "DEVICE_LOGIN_FAILED";
|
|
3121
|
+
throw new DeviceLoginError(`Device login failed (HTTP ${response.status}${code === "DEVICE_LOGIN_FAILED" ? "" : `, ${code}`}).`, code, response.status);
|
|
3105
3122
|
}
|
|
3106
3123
|
if (!json.data || typeof json.data !== "object")
|
|
3107
3124
|
throw new DeviceLoginError("Invalid device login response.", "invalid_response");
|
|
@@ -3119,7 +3136,7 @@ async function startDeviceLogin(options = {}) {
|
|
|
3119
3136
|
throw new Error("Login timeout must be 1–600 seconds.");
|
|
3120
3137
|
const capability = await request2(baseURL, "/api/cli/device/capabilities");
|
|
3121
3138
|
if (!capability.supported)
|
|
3122
|
-
throw new
|
|
3139
|
+
throw new DeviceLoginError("This site has not enabled browser CLI login. Use --token-stdin.", "DEVICE_LOGIN_UNSUPPORTED");
|
|
3123
3140
|
const scopes = validateScopes(capability.scopes);
|
|
3124
3141
|
const response = await request2(baseURL, "/api/cli/device/start", { name: options.name || `EasyMagic CLI (${os3.hostname()})` });
|
|
3125
3142
|
if (typeof response.device_code !== "string" || !response.device_code || /\s/.test(response.device_code) || response.device_code.length > 512 || typeof response.user_code !== "string" || !/^[A-Z0-9-]{4,128}$/.test(response.user_code))
|
|
@@ -3298,10 +3315,10 @@ var init_device_login = __esm(() => {
|
|
|
3298
3315
|
init_config();
|
|
3299
3316
|
init_file_lock();
|
|
3300
3317
|
DEVICE_LOGIN_SCOPES = ["api_key:read", "api_key:reveal", "api_key:write", "profile:read", "usage:read"];
|
|
3301
|
-
DeviceLoginError = class DeviceLoginError extends
|
|
3318
|
+
DeviceLoginError = class DeviceLoginError extends ApiError {
|
|
3302
3319
|
code;
|
|
3303
|
-
constructor(message, code) {
|
|
3304
|
-
super(message);
|
|
3320
|
+
constructor(message, code, status) {
|
|
3321
|
+
super(message, code, status);
|
|
3305
3322
|
this.code = code;
|
|
3306
3323
|
this.name = "DeviceLoginError";
|
|
3307
3324
|
}
|
|
@@ -16573,7 +16590,7 @@ var package_default;
|
|
|
16573
16590
|
var init_package = __esm(() => {
|
|
16574
16591
|
package_default = {
|
|
16575
16592
|
name: "easymagic",
|
|
16576
|
-
version: "0.5.
|
|
16593
|
+
version: "0.5.2",
|
|
16577
16594
|
description: "Manage EasyMagic API keys, inspect usage, and configure coding clients",
|
|
16578
16595
|
type: "module",
|
|
16579
16596
|
bin: {
|
|
@@ -16625,6 +16642,7 @@ var init_package = __esm(() => {
|
|
|
16625
16642
|
"AI_USAGE.md",
|
|
16626
16643
|
"CLI_CONTRACT.md",
|
|
16627
16644
|
"AUDIT.md",
|
|
16645
|
+
"RELEASING.md",
|
|
16628
16646
|
"THIRD_PARTY_NOTICES.md"
|
|
16629
16647
|
],
|
|
16630
16648
|
repository: {
|
|
@@ -16749,6 +16767,79 @@ async function runCommand(args, options = {}) {
|
|
|
16749
16767
|
}
|
|
16750
16768
|
var init_runner = () => {};
|
|
16751
16769
|
|
|
16770
|
+
// src/interactive/preferences.ts
|
|
16771
|
+
import fs19 from "node:fs";
|
|
16772
|
+
import path18 from "node:path";
|
|
16773
|
+
import { randomUUID as randomUUID8 } from "node:crypto";
|
|
16774
|
+
function preferencesPath() {
|
|
16775
|
+
return path18.join(path18.dirname(configPath()), "preferences.json");
|
|
16776
|
+
}
|
|
16777
|
+
function loadUIPreferences() {
|
|
16778
|
+
try {
|
|
16779
|
+
const file = preferencesPath();
|
|
16780
|
+
const stat = fs19.lstatSync(file);
|
|
16781
|
+
if (!stat.isFile() || stat.isSymbolicLink() || stat.size > 4096)
|
|
16782
|
+
return {};
|
|
16783
|
+
const value = JSON.parse(fs19.readFileSync(file, "utf8"));
|
|
16784
|
+
if (value?.version !== 1)
|
|
16785
|
+
return {};
|
|
16786
|
+
return {
|
|
16787
|
+
...["zh", "en"].includes(value.language) ? { language: value.language } : {},
|
|
16788
|
+
...value.onboardingCompleted === true ? { onboardingCompleted: true } : {}
|
|
16789
|
+
};
|
|
16790
|
+
} catch {
|
|
16791
|
+
return {};
|
|
16792
|
+
}
|
|
16793
|
+
}
|
|
16794
|
+
function loadUILanguage() {
|
|
16795
|
+
return loadUIPreferences().language;
|
|
16796
|
+
}
|
|
16797
|
+
function resolveUILanguage(override) {
|
|
16798
|
+
if (override)
|
|
16799
|
+
return override;
|
|
16800
|
+
if (process.env.EASYMAGIC_LANG)
|
|
16801
|
+
return process.env.EASYMAGIC_LANG.toLowerCase().startsWith("zh") ? "zh" : "en";
|
|
16802
|
+
const saved = loadUILanguage();
|
|
16803
|
+
if (saved)
|
|
16804
|
+
return saved;
|
|
16805
|
+
return (process.env.LC_ALL || process.env.LANG || "en").toLowerCase().startsWith("zh") ? "zh" : "en";
|
|
16806
|
+
}
|
|
16807
|
+
function saveUILanguage(language) {
|
|
16808
|
+
if (language !== "zh" && language !== "en")
|
|
16809
|
+
throw new Error("Choose 简体中文 or English.");
|
|
16810
|
+
savePreferences({ language });
|
|
16811
|
+
}
|
|
16812
|
+
function saveFirstRunComplete() {
|
|
16813
|
+
savePreferences({ onboardingCompleted: true });
|
|
16814
|
+
}
|
|
16815
|
+
function savePreferences(change) {
|
|
16816
|
+
const file = preferencesPath();
|
|
16817
|
+
const directory = path18.dirname(file);
|
|
16818
|
+
fs19.mkdirSync(directory, { recursive: true, mode: 448 });
|
|
16819
|
+
const stat = fs19.lstatSync(directory);
|
|
16820
|
+
if (!stat.isDirectory() || stat.isSymbolicLink())
|
|
16821
|
+
throw new Error("UI preference directory must be a real directory.");
|
|
16822
|
+
const unlock = acquireFileLock(file + ".lock", "Another process is saving the interface language. Try again.");
|
|
16823
|
+
const temporary = `${file}.${randomUUID8()}.tmp`;
|
|
16824
|
+
try {
|
|
16825
|
+
if (fs19.existsSync(file)) {
|
|
16826
|
+
const existing = fs19.lstatSync(file);
|
|
16827
|
+
if (!existing.isFile() || existing.isSymbolicLink())
|
|
16828
|
+
throw new Error("UI preferences must be a regular file.");
|
|
16829
|
+
}
|
|
16830
|
+
fs19.writeFileSync(temporary, JSON.stringify({ version: 1, ...loadUIPreferences(), ...change }, null, 2) + `
|
|
16831
|
+
`, { flag: "wx", mode: 384 });
|
|
16832
|
+
fs19.renameSync(temporary, file);
|
|
16833
|
+
} finally {
|
|
16834
|
+
fs19.rmSync(temporary, { force: true });
|
|
16835
|
+
unlock();
|
|
16836
|
+
}
|
|
16837
|
+
}
|
|
16838
|
+
var init_preferences = __esm(() => {
|
|
16839
|
+
init_config();
|
|
16840
|
+
init_file_lock();
|
|
16841
|
+
});
|
|
16842
|
+
|
|
16752
16843
|
// node_modules/fast-string-truncated-width/dist/utils.js
|
|
16753
16844
|
var getCodePointsLength, isFullWidth = (x) => {
|
|
16754
16845
|
return x === 12288 || x >= 65281 && x <= 65376 || x >= 65504 && x <= 65510;
|
|
@@ -18118,6 +18209,20 @@ var init_string_width = __esm(() => {
|
|
|
18118
18209
|
emojiZwjSequenceRegex = /\u{200D}\p{Extended_Pictographic}/v;
|
|
18119
18210
|
});
|
|
18120
18211
|
|
|
18212
|
+
// src/interactive/brand.ts
|
|
18213
|
+
var TERMINAL_MARK, BRAND_WEBSITE = "https://easymagic.ai", BRAND_TAGLINE;
|
|
18214
|
+
var init_brand = __esm(() => {
|
|
18215
|
+
TERMINAL_MARK = [
|
|
18216
|
+
"┏━━╸ ╻╲ ╱╻",
|
|
18217
|
+
"┣━━╸ ┃ ╲╱ ┃",
|
|
18218
|
+
"┗━━╸ ╹ ╹"
|
|
18219
|
+
];
|
|
18220
|
+
BRAND_TAGLINE = {
|
|
18221
|
+
zh: "一个入口,连接你的 AI 工具",
|
|
18222
|
+
en: "One gateway for your AI tools"
|
|
18223
|
+
};
|
|
18224
|
+
});
|
|
18225
|
+
|
|
18121
18226
|
// src/interactive/ui.ts
|
|
18122
18227
|
import { createInterface } from "node:readline/promises";
|
|
18123
18228
|
import { emitKeypressEvents } from "node:readline";
|
|
@@ -18319,9 +18424,19 @@ function startTask(message) {
|
|
|
18319
18424
|
function banner(options) {
|
|
18320
18425
|
const style = color();
|
|
18321
18426
|
const width = terminalWidth() - 4;
|
|
18322
|
-
|
|
18323
|
-
|
|
18324
|
-
console.log("
|
|
18427
|
+
const version = `v${cleanText(options.version)}`;
|
|
18428
|
+
const tagline = BRAND_TAGLINE[language2];
|
|
18429
|
+
console.log("");
|
|
18430
|
+
if (width >= 68 && process.env.TERM !== "dumb") {
|
|
18431
|
+
console.log(" " + style.cyan(TERMINAL_MARK[0]) + " " + style.cyan.bold("EasyMagic") + " " + style.dim(version));
|
|
18432
|
+
console.log(" " + style.cyan(TERMINAL_MARK[1]) + " " + tagline);
|
|
18433
|
+
console.log(" " + style.cyan(TERMINAL_MARK[2]) + " " + style.underline(BRAND_WEBSITE));
|
|
18434
|
+
} else {
|
|
18435
|
+
console.log(" " + style.cyan.bold("EasyMagic") + " " + style.dim(version));
|
|
18436
|
+
for (const line of wrapText(tagline, width))
|
|
18437
|
+
console.log(" " + line);
|
|
18438
|
+
console.log(" " + style.underline(BRAND_WEBSITE));
|
|
18439
|
+
}
|
|
18325
18440
|
console.log(" " + style.dim("─".repeat(width)));
|
|
18326
18441
|
if (options.profile)
|
|
18327
18442
|
console.log(" " + style.dim(t2("账户配置 ", "Profile ")) + truncateText(options.profile, width - 10));
|
|
@@ -18377,6 +18492,7 @@ var init_ui = __esm(() => {
|
|
|
18377
18492
|
init_dist6();
|
|
18378
18493
|
init_source();
|
|
18379
18494
|
init_string_width();
|
|
18495
|
+
init_brand();
|
|
18380
18496
|
UserCancelled = class UserCancelled extends Error {
|
|
18381
18497
|
constructor() {
|
|
18382
18498
|
super("Interactive action cancelled.");
|
|
@@ -18397,7 +18513,7 @@ var init_ui = __esm(() => {
|
|
|
18397
18513
|
});
|
|
18398
18514
|
|
|
18399
18515
|
// src/interactive/main.ts
|
|
18400
|
-
import
|
|
18516
|
+
import path19 from "node:path";
|
|
18401
18517
|
async function execute2(ctx, args, message, input) {
|
|
18402
18518
|
const task = startTask(message);
|
|
18403
18519
|
try {
|
|
@@ -18409,7 +18525,7 @@ async function execute2(ctx, args, message, input) {
|
|
|
18409
18525
|
else
|
|
18410
18526
|
task.error(t3(ctx, "操作未完成", "Action needs attention"));
|
|
18411
18527
|
if (result.error)
|
|
18412
|
-
throw new Error(result.error.message);
|
|
18528
|
+
throw Object.assign(new Error(result.error.message), { code: result.error.code });
|
|
18413
18529
|
return result;
|
|
18414
18530
|
} catch (error) {
|
|
18415
18531
|
task.error(t3(ctx, "操作未完成", "Action needs attention"));
|
|
@@ -18479,15 +18595,35 @@ async function login(ctx) {
|
|
|
18479
18595
|
const oldProfile = ctx.profile;
|
|
18480
18596
|
ctx.profile = profile;
|
|
18481
18597
|
try {
|
|
18482
|
-
|
|
18598
|
+
const signInWithPAT = async () => {
|
|
18599
|
+
showNote(t3(ctx, "在网站个人设置中创建个人访问令牌(PAT),权限选择 profile:read、api_key:read、api_key:write、api_key:reveal、usage:read。将 nap_ 开头的令牌粘贴到下方;不要使用 sk- 推理密钥。", "Create a personal access token (PAT) in the website account settings with profile:read, api_key:read, api_key:write, api_key:reveal, and usage:read. Paste the nap_ token below; do not use an sk- inference key."), t3(ctx, "使用个人访问令牌登录", "Sign in with a personal access token"));
|
|
18483
18600
|
const token = await textInput(t3(ctx, "个人访问令牌(输入将隐藏)", "Personal access token (hidden)"), { secret: true, validate: (value) => /^nap_[a-zA-Z0-9_-]+$/.test(value.trim()) ? undefined : t3(ctx, "请输入 nap_ 开头的个人访问令牌", "Enter a personal access token beginning with nap_") });
|
|
18484
18601
|
const result = await execute2(ctx, [...args, "--token-stdin"], t3(ctx, "验证并保存登录", "Verifying and saving login"), token.trim());
|
|
18485
|
-
if (result.data?.status === "authenticated")
|
|
18602
|
+
if (result.data?.status === "authenticated") {
|
|
18603
|
+
ctx.profile = result.data.profile;
|
|
18486
18604
|
showSuccess(t3(ctx, "账户已连接", "Account connected"));
|
|
18605
|
+
}
|
|
18606
|
+
};
|
|
18607
|
+
if (method === "pat") {
|
|
18608
|
+
await signInWithPAT();
|
|
18487
18609
|
return;
|
|
18488
18610
|
}
|
|
18489
|
-
|
|
18490
|
-
|
|
18611
|
+
try {
|
|
18612
|
+
const result = await execute2(ctx, [...args, "--start", "--no-browser"], t3(ctx, "创建浏览器授权请求", "Starting browser authorization"));
|
|
18613
|
+
await finishLogin(ctx, result);
|
|
18614
|
+
} catch (error) {
|
|
18615
|
+
if (error.code !== "DEVICE_LOGIN_UNSUPPORTED")
|
|
18616
|
+
throw error;
|
|
18617
|
+
showWarning(t3(ctx, "该站点尚未提供 CLI 浏览器授权接口。可以先使用个人访问令牌登录,登录后仍能创建密钥并配置 Agent。", "This site does not provide CLI browser authorization yet. Sign in with a personal access token to create keys and configure agents."));
|
|
18618
|
+
const fallback = await selectChoice(t3(ctx, "选择登录方式", "Choose a sign-in method"), [
|
|
18619
|
+
{ value: "pat", label: t3(ctx, "改用个人访问令牌登录", "Use a personal access token") },
|
|
18620
|
+
back(ctx)
|
|
18621
|
+
]);
|
|
18622
|
+
if (fallback === "pat")
|
|
18623
|
+
await signInWithPAT();
|
|
18624
|
+
else
|
|
18625
|
+
ctx.profile = oldProfile;
|
|
18626
|
+
}
|
|
18491
18627
|
} catch (error) {
|
|
18492
18628
|
ctx.profile = oldProfile;
|
|
18493
18629
|
throw error;
|
|
@@ -18616,13 +18752,13 @@ async function configure(ctx) {
|
|
|
18616
18752
|
options.push("--context-window", context);
|
|
18617
18753
|
}
|
|
18618
18754
|
const directory = await textInput(t3(ctx, "配置目录(可修改)", "Configuration directory"), { initialValue: adapter.configDir(), validate: (value) => value.trim() ? undefined : t3(ctx, "请输入目录", "Enter a directory") });
|
|
18619
|
-
options.push("--config-dir",
|
|
18755
|
+
options.push("--config-dir", path19.resolve(directory));
|
|
18620
18756
|
displayPairs(t3(ctx, "确认配置", "Review configuration"), [
|
|
18621
18757
|
[t3(ctx, "Agent", "Agent"), adapter.label],
|
|
18622
18758
|
[t3(ctx, "账户", "Account"), ctx.profile],
|
|
18623
18759
|
[t3(ctx, "模型", "Model"), modelChoice === "__automatic" ? t3(ctx, "自动选择兼容模型", "Automatic compatible selection") : modelChoice],
|
|
18624
18760
|
[t3(ctx, "协议 / 分组", "Protocol / group"), `${protocol} / ${group}`],
|
|
18625
|
-
[t3(ctx, "目录", "Directory"),
|
|
18761
|
+
[t3(ctx, "目录", "Directory"), path19.resolve(directory)],
|
|
18626
18762
|
[t3(ctx, "密钥", "Key"), key ? `${text3(key.name)} #${key.id}` : t3(ctx, "新建专用密钥(不限额、不过期)", "New dedicated key (unlimited, no expiration)")]
|
|
18627
18763
|
]);
|
|
18628
18764
|
showInfo(t3(ctx, "已有配置会备份;本次不会发送计费推理请求。", "Existing configuration will be backed up. No billable inference request will be sent."));
|
|
@@ -18760,7 +18896,7 @@ async function keyMenu(ctx) {
|
|
|
18760
18896
|
if (choice === "manage")
|
|
18761
18897
|
await manageKey(ctx);
|
|
18762
18898
|
if (choice === "export") {
|
|
18763
|
-
const file = await textInput(t3(ctx, "导出文件路径(JSON 或 CSV)", "Export file path (JSON or CSV)"), { initialValue:
|
|
18899
|
+
const file = await textInput(t3(ctx, "导出文件路径(JSON 或 CSV)", "Export file path (JSON or CSV)"), { initialValue: path19.resolve("easymagic-keys.json"), validate: (value) => value.trim() ? undefined : t3(ctx, "请输入路径", "Enter a path") });
|
|
18764
18900
|
if (await confirmAction(t3(ctx, "导出全部密钥策略(不含完整密钥)?", "Export all key policies without full secrets?"))) {
|
|
18765
18901
|
const result = await execute2(ctx, ["keys", "export", "--all", "--file", file], t3(ctx, "导出策略", "Exporting policies"));
|
|
18766
18902
|
showSuccess(`${t3(ctx, "已导出", "Exported")}: ${text3(result.data?.file)}`);
|
|
@@ -18925,13 +19061,66 @@ async function recoverOperation2(ctx) {
|
|
|
18925
19061
|
const recovered = await execute2(ctx, ["operations", mode, id, ...mode === "reconcile" ? [] : ["--yes"]], t3(ctx, "恢复操作记录", "Recovering operation"));
|
|
18926
19062
|
displayTable([t3(ctx, "操作", "Action"), t3(ctx, "状态", "State"), t3(ctx, "说明", "Details")], (recovered.data?.entries || []).map((entry) => [text3(entry.action), text3(entry.state), text3(entry.error)]));
|
|
18927
19063
|
}
|
|
19064
|
+
async function chooseInterfaceLanguage(ctx, firstRun = false) {
|
|
19065
|
+
const selected = await selectChoice("选择语言 / Choose language", [
|
|
19066
|
+
{ value: "zh", label: "简体中文" },
|
|
19067
|
+
{ value: "en", label: "English" },
|
|
19068
|
+
...firstRun ? [] : [{ value: "back", label: "返回 / Back" }]
|
|
19069
|
+
]);
|
|
19070
|
+
if (selected === "back")
|
|
19071
|
+
return;
|
|
19072
|
+
saveUILanguage(selected);
|
|
19073
|
+
ctx.language = selected;
|
|
19074
|
+
setUILanguage(selected);
|
|
19075
|
+
if (!firstRun)
|
|
19076
|
+
showSuccess(t3(ctx, "已切换为简体中文,语言偏好已保存。", "Switched to English. Language preference saved."));
|
|
19077
|
+
}
|
|
19078
|
+
async function guidedSetup(ctx, firstRun = false) {
|
|
19079
|
+
showNote(t3(ctx, `1. 连接 EasyMagic 账户
|
|
19080
|
+
2. 选择 Agent、模型和配置目录
|
|
19081
|
+
3. 检查变更后,创建密钥并写入配置
|
|
19082
|
+
|
|
19083
|
+
已有配置会备份,默认不发送计费推理请求。`, `1. Connect your EasyMagic account
|
|
19084
|
+
2. Choose an agent, model, and configuration directory
|
|
19085
|
+
3. Review the changes, then create a key and write the configuration
|
|
19086
|
+
|
|
19087
|
+
Existing configuration is backed up. No billable inference request is sent by default.`), firstRun ? t3(ctx, "首次使用引导", "First-time setup") : t3(ctx, "引导配置", "Guided setup"));
|
|
19088
|
+
const action = await selectChoice(t3(ctx, "现在开始配置?", "Ready to configure?"), [
|
|
19089
|
+
{ value: "configure", label: t3(ctx, "开始引导配置", "Start guided setup") },
|
|
19090
|
+
{ value: "later", label: t3(ctx, "稍后配置,进入控制台", "Set up later; open console") }
|
|
19091
|
+
]);
|
|
19092
|
+
if (firstRun)
|
|
19093
|
+
saveFirstRunComplete();
|
|
19094
|
+
if (action === "configure")
|
|
19095
|
+
await configure(ctx);
|
|
19096
|
+
else
|
|
19097
|
+
showInfo(t3(ctx, "已进入控制台,可随时从“引导配置”重新开始。", "The console is ready. Choose Guided setup whenever you want to begin."));
|
|
19098
|
+
}
|
|
18928
19099
|
async function runInteractive(options = {}) {
|
|
18929
19100
|
let defaultProfile = "default";
|
|
18930
19101
|
try {
|
|
18931
19102
|
defaultProfile = listProfiles().active;
|
|
18932
19103
|
} catch {}
|
|
18933
|
-
const ctx = { profile: options.profile || defaultProfile, language: options.language
|
|
19104
|
+
const ctx = { profile: options.profile || defaultProfile, language: resolveUILanguage(options.language) };
|
|
18934
19105
|
setUILanguage(ctx.language);
|
|
19106
|
+
if (loadUIPreferences().onboardingCompleted !== true) {
|
|
19107
|
+
try {
|
|
19108
|
+
await chooseInterfaceLanguage(ctx, true);
|
|
19109
|
+
banner({ version: package_default.version, profile: ctx.profile, status: t3(ctx, "欢迎使用 EasyMagic", "Welcome to EasyMagic") });
|
|
19110
|
+
await guidedSetup(ctx, true);
|
|
19111
|
+
} catch (error) {
|
|
19112
|
+
if (error instanceof UserCancelled) {
|
|
19113
|
+
if (loadUIPreferences().onboardingCompleted !== true) {
|
|
19114
|
+
showInfo(t3(ctx, "已取消引导,可下次继续。", "Setup cancelled. You can continue next time."));
|
|
19115
|
+
return;
|
|
19116
|
+
}
|
|
19117
|
+
showInfo(t3(ctx, "已取消配置,返回控制台。", "Setup cancelled; opening the console."));
|
|
19118
|
+
} else {
|
|
19119
|
+
showError(error instanceof Error ? error.message : String(error));
|
|
19120
|
+
await pause(t3(ctx, "按 Enter 返回控制台", "Press Enter to open the console")).catch(() => {});
|
|
19121
|
+
}
|
|
19122
|
+
}
|
|
19123
|
+
}
|
|
18935
19124
|
let running = true;
|
|
18936
19125
|
while (running) {
|
|
18937
19126
|
let site;
|
|
@@ -18959,6 +19148,8 @@ async function runInteractive(options = {}) {
|
|
|
18959
19148
|
{ value: "doctor", label: t3(ctx, "诊断连接", "Diagnose connections") },
|
|
18960
19149
|
{ value: "recovery", label: t3(ctx, "恢复与操作记录", "Recovery and operation history") },
|
|
18961
19150
|
{ value: "ai", label: t3(ctx, "AI 调用方式", "Using the AI mode") },
|
|
19151
|
+
{ value: "guided", label: t3(ctx, "引导配置", "Guided setup"), hint: t3(ctx, "重新运行首次配置引导", "Run the setup guide again") },
|
|
19152
|
+
{ value: "language", label: "中文 / English", hint: t3(ctx, "界面语言:简体中文", "Interface language: English") },
|
|
18962
19153
|
{ value: "exit", label: t3(ctx, "退出", "Exit") }
|
|
18963
19154
|
]);
|
|
18964
19155
|
} catch (error) {
|
|
@@ -18979,6 +19170,8 @@ async function runInteractive(options = {}) {
|
|
|
18979
19170
|
await diagnose(ctx);
|
|
18980
19171
|
if (action === "recovery")
|
|
18981
19172
|
await recoveryMenu(ctx);
|
|
19173
|
+
if (action === "guided")
|
|
19174
|
+
await guidedSetup(ctx);
|
|
18982
19175
|
if (action === "ai") {
|
|
18983
19176
|
showNote(`easymagic ai
|
|
18984
19177
|
easymagic ai guide ai
|
|
@@ -18987,6 +19180,9 @@ easymagic ai onboard codex --start
|
|
|
18987
19180
|
easymagic ai onboard --resume <onboarding_id>`, t3(ctx, "AI 模式:结构化输出,无交互菜单", "AI mode: structured output, no interactive menus"));
|
|
18988
19181
|
await pause(t3(ctx, "按 Enter 返回主页", "Press Enter to return home"));
|
|
18989
19182
|
}
|
|
19183
|
+
if (action === "language") {
|
|
19184
|
+
await chooseInterfaceLanguage(ctx);
|
|
19185
|
+
}
|
|
18990
19186
|
if (action === "exit")
|
|
18991
19187
|
running = false;
|
|
18992
19188
|
} catch (error) {
|
|
@@ -19009,6 +19205,7 @@ var init_main3 = __esm(() => {
|
|
|
19009
19205
|
init_format();
|
|
19010
19206
|
init_package();
|
|
19011
19207
|
init_runner();
|
|
19208
|
+
init_preferences();
|
|
19012
19209
|
init_ui();
|
|
19013
19210
|
});
|
|
19014
19211
|
|
|
@@ -20930,6 +21127,9 @@ function chooseLanguage(args = process.argv.slice(2)) {
|
|
|
20930
21127
|
return language;
|
|
20931
21128
|
}
|
|
20932
21129
|
var messages = {
|
|
21130
|
+
"This site has not deployed compatible CLI browser authorization. Use a personal access token with login --token-stdin, or ask the site administrator to deploy the CLI device-login backend.": "该站点尚未部署兼容的 CLI 浏览器授权接口。请使用个人访问令牌(PAT)登录,或由站点管理员部署 CLI 设备授权后端。",
|
|
21131
|
+
"Site security rules blocked CLI access (Cloudflare HTTP 403). Ask the site administrator to allow CLI API requests; changing login credentials will not resolve this block.": "站点安全规则拦截了 CLI 请求(Cloudflare HTTP 403)。请站点管理员放行 CLI API;更换登录凭据不能解决此拦截。",
|
|
21132
|
+
"The site security gateway blocked this CLI request (HTTP 403). Ask the site administrator to allow the CLI API routes. Changing or re-entering your PAT will not fix this block.": "站点安全网关拦截了 CLI 请求(HTTP 403)。请站点管理员放行 CLI 所需 API 路径;更换或重新输入 PAT 无法解决此拦截。",
|
|
20933
21133
|
"Use AI mode: JSON output, no menus, no automatic browser launch": "AI 模式:输出 JSON,不进入菜单,不自动打开浏览器",
|
|
20934
21134
|
"Open the interactive terminal console": "打开手动交互控制台",
|
|
20935
21135
|
"Saved CLI configuration is invalid. Back up and repair config.json before changing profiles; existing profiles were preserved.": "CLI 配置无效。请先备份并修复 config.json;已有账号配置已保留。",
|
|
@@ -21105,7 +21305,7 @@ function translate(text) {
|
|
|
21105
21305
|
return text;
|
|
21106
21306
|
if (messages[text])
|
|
21107
21307
|
return messages[text];
|
|
21108
|
-
return text.replace(/^error: unknown command '(.+)'/, "未知命令:$1").replace(/^error: unknown option '(.+)'/, "未知选项:$1").replace(/^error: required option '(.+)' not specified/, "缺少必填选项:$1").replace(/^error: missing required argument '(.+)'/, "缺少必填参数:$1").replace(/^Logged in to (.+) as (.+)\.$/, "已登录 $1,账号:$2。").replace(/^Configured (.+) for (.+)$/, "已配置 $1,站点:$2").replace(/^Would configure (.+) for (.+)$/, "将配置 $1,站点:$2").replace(/^Configure (.+); use --dry-run to preview changes$/, "配置 $1;使用 --dry-run 预览").replace(/^Group (.+) is unavailable to this account\.$/, "当前账号无法使用分组 $1。").replace(/^Confirmation required to (.+): rerun with --yes, or preview with --dry-run$/, "操作需要确认($1)。添加 --yes 执行,或用 --dry-run 预览。").replace(/^ Backup: (.+)$/, " 备份:$1").replace(/^PASS /, "通过 ").replace(/^WARN /, "注意 ").replace(/^FAIL /, "失败 ").replace(/display help for command/g, "显示帮助").replace(/\(choices:/g, "(可选:").replace(/^Usage: /gm, "用法:").replace(/^Options:/gm, "选项:").replace(/^Commands:/gm, "命令:").replace(/^Arguments:/gm, "参数:");
|
|
21308
|
+
return text.replace(/^Device login failed \(HTTP (\d+)(?:, ([a-z_]+))?\)\.$/, (_match, status, code) => `设备授权失败(HTTP ${status}${code ? `,${code}` : ""})。`).replace(/^error: unknown command '(.+)'/, "未知命令:$1").replace(/^error: unknown option '(.+)'/, "未知选项:$1").replace(/^error: required option '(.+)' not specified/, "缺少必填选项:$1").replace(/^error: missing required argument '(.+)'/, "缺少必填参数:$1").replace(/^Logged in to (.+) as (.+)\.$/, "已登录 $1,账号:$2。").replace(/^Configured (.+) for (.+)$/, "已配置 $1,站点:$2").replace(/^Would configure (.+) for (.+)$/, "将配置 $1,站点:$2").replace(/^Configure (.+); use --dry-run to preview changes$/, "配置 $1;使用 --dry-run 预览").replace(/^Group (.+) is unavailable to this account\.$/, "当前账号无法使用分组 $1。").replace(/^Confirmation required to (.+): rerun with --yes, or preview with --dry-run$/, "操作需要确认($1)。添加 --yes 执行,或用 --dry-run 预览。").replace(/^ Backup: (.+)$/, " 备份:$1").replace(/^PASS /, "通过 ").replace(/^WARN /, "注意 ").replace(/^FAIL /, "失败 ").replace(/display help for command/g, "显示帮助").replace(/\(choices:/g, "(可选:").replace(/^Usage: /gm, "用法:").replace(/^Options:/gm, "选项:").replace(/^Commands:/gm, "命令:").replace(/^Arguments:/gm, "参数:");
|
|
21109
21309
|
}
|
|
21110
21310
|
function localizeCommands(command) {
|
|
21111
21311
|
if (language !== "zh")
|
|
@@ -21390,7 +21590,7 @@ npm install -g easymagic
|
|
|
21390
21590
|
easymagic --help
|
|
21391
21591
|
\`\`\`
|
|
21392
21592
|
|
|
21393
|
-
也可以不全局安装,直接执行 \`npx --yes easymagic --help\`。离线分发则使用安装包:\`npm install -g ./easymagic-0.5.
|
|
21593
|
+
也可以不全局安装,直接执行 \`npx --yes easymagic --help\`。离线分发则使用安装包:\`npm install -g ./easymagic-0.5.2.tgz\`。
|
|
21394
21594
|
|
|
21395
21595
|
源码构建需要 Bun:
|
|
21396
21596
|
|
|
@@ -21412,7 +21612,13 @@ easymagic
|
|
|
21412
21612
|
easymagic interactive
|
|
21413
21613
|
\`\`\`
|
|
21414
21614
|
|
|
21415
|
-
|
|
21615
|
+
首次在终端运行时,先选择 **简体中文 / English**,然后进入配置引导:连接账户、选择 Agent、确认模型和写入目标。也可选择“稍后配置,进入控制台”;这表示已看过首次引导,不表示已经登录或配置成功。之后再直接运行 \`easymagic\` 就进入控制台,首页的 **引导配置 / Guided setup** 可随时重新打开向导。取消首次语言选择不会保存已完成状态。
|
|
21616
|
+
|
|
21617
|
+
手动控制台使用方向键选择、Enter 确认,按 Ctrl+C 取消当前操作或退出。\`TERM=dumb\` 的交互终端改用编号输入,输入 \`q\` 返回或退出;\`NO_COLOR\` 会关闭颜色。首页包含配置 Agent、引导配置、登录与切换账号、密钥管理、模型和用量、诊断、配置恢复及操作记录。打开语言选择和进入首页不发起网络请求,实际请求和变更在选择具体操作后执行。密码式 PAT 输入不回显,删除、恢复等变更需要确认;取消不会被当成确认。
|
|
21618
|
+
|
|
21619
|
+
从 0.5.1 起,首页的 **中文 / English** 可立即切换整套菜单语言,并记住选择。语言偏好与首次引导记录保存在 CLI 配置目录的 \`preferences.json\`,与登录凭据分开;取消选择不会更改偏好。启动时的优先级为 \`--lang\` > \`EASYMAGIC_LANG\` > 已保存的菜单语言 > 系统语言。比如 \`easymagic --lang en\` 可临时用英文打开,首页语言选项仍可随时切换。AI 模式不读取手动菜单的语言偏好。
|
|
21620
|
+
|
|
21621
|
+
首页同时显示 EasyMagic 终端品牌标识、简短介绍和官网 \`https://easymagic.ai\`;窄终端使用紧凑布局,品牌区不会代替账户状态或操作菜单。
|
|
21416
21622
|
|
|
21417
21623
|
AI 和脚本使用明确的另一种入口:
|
|
21418
21624
|
|
|
@@ -21441,7 +21647,7 @@ easymagic onboard codex
|
|
|
21441
21647
|
|
|
21442
21648
|
CLI 会复用当前有效登录;未登录时会打开本站授权页。用户登录网站、核对终端配对码并确认授权后,CLI 自动取得管理 PAT、创建客户端专用推理密钥、选择可用分组与模型并写入配置。需要签署 API 密钥使用协议时,由用户在浏览器中阅读并勾选。授权后无需手工复制密钥。
|
|
21443
21649
|
|
|
21444
|
-
浏览器登录要求网站已部署配套 device-login 后端,见 [BACKEND_INTEGRATION.md](BACKEND_INTEGRATION.md)
|
|
21650
|
+
浏览器登录要求网站已部署配套 device-login 后端,见 [BACKEND_INTEGRATION.md](BACKEND_INTEGRATION.md)。若设备授权接口返回 404/405,CLI 会明确提示 \`DEVICE_LOGIN_UNSUPPORTED\`,手动界面可当场改用 PAT 登录;已输入的站点和账户配置名会继续使用。EasyMagic 官网现已提供设备授权接口;其他尚未更新的站点可使用下面的 PAT 登录,然后运行 \`onboard\`,仍可自动建密钥与配置。
|
|
21445
21651
|
|
|
21446
21652
|
可显式指定分组、模型和协议:
|
|
21447
21653
|
|
|
@@ -21581,7 +21787,7 @@ bun run e2e
|
|
|
21581
21787
|
|
|
21582
21788
|
\`check\` 包含类型检查、单元/恢复流程测试、构建、安装包离线安装、18 个客户端的配置/备份/恢复检查。真实客户端验证范围见 Agent 文档。\`e2e\` 需独立 loopback 测试后端,使用 \`EASYMAGIC_E2E_BASE_URL\` 和 \`EASYMAGIC_E2E_TOKEN_FILE\`;禁止连接生产环境。
|
|
21583
21789
|
|
|
21584
|
-
代码仓库:[XzlmTech/easymagic-cli](https://github.com/XzlmTech/easymagic-cli)
|
|
21790
|
+
代码仓库:[XzlmTech/easymagic-cli](https://github.com/XzlmTech/easymagic-cli)。新版本推送到主分支并通过完整 CI 后,GitHub Actions 使用 npm 可信发布自动上线;已有版本自动跳过。维护者可通过发布开关暂停或恢复自动发布。维护者的一次性绑定和恢复方法见 [RELEASING.md](RELEASING.md)。
|
|
21585
21791
|
`;
|
|
21586
21792
|
|
|
21587
21793
|
// AI_USAGE.md
|
|
@@ -21594,7 +21800,7 @@ var CLI_CONTRACT_default = '# EasyMagic CLI 机器交互契约\n\n本文面向
|
|
|
21594
21800
|
var AGENT_SUPPORT_default = "# Supported agent configuration\n\nThe registry covers all **18** application IDs in the original CC Switch `AppType::ALL` at commit [`0afb1f26de6383f43d304bf3e7ac77c4ffc6d15f`](https://github.com/farion1231/cc-switch/tree/0afb1f26de6383f43d304bf3e7ac77c4ffc6d15f). CC Switch CLI is also a reference for the shared seven applications. These are native configuration adapters; the CLI does not embed CC Switch's local proxy or route unsupported protocols through an implicit translator.\n\n| CLI target | Native files / directory | Protocols | Activation and notes |\n| --- | --- | --- | --- |\n| `claude-code` (`claude`, `cc`) | `.claude/settings.json` | Anthropic | Restart Claude; existing hooks/permissions retained |\n| `claude-desktop` | `Claude/` and `Claude-3p/configLibrary/` | Anthropic | Restart Desktop; requires Claude role model IDs, no invented mapping proxy |\n| `codex` | `.codex/config.toml`, `auth.json` | Responses | Restart; existing providers/MCP retained |\n| `gemini` (`gemini-cli`) | `.gemini/settings.json`, `.env` | Gemini native | Restart; managed auth policy is respected |\n| `grok-build` (`grok`, `grokbuild`) | `.grok/config.toml` | Chat, Responses, Anthropic | Model context window must be supplied if unknown |\n| `opencode` | `.config/opencode/opencode.json[c]` | Chat, Responses, Anthropic, Gemini | Existing v1/v2 detected; empty config uses installed major version, otherwise released v1; override with `--variant v1` or `v2` |\n| `openclaw` | `.openclaw/openclaw.json` | Chat, Responses, Anthropic, Gemini | JSON5 parsed safely; formatting/comments may be normalized |\n| `hermes` | `.hermes/config.yaml` (Windows: local app data) | Chat, Responses, Anthropic | Existing YAML comments and other providers retained |\n| `pi` | `.pi/agent/models.json`, `settings.json` | Chat, Responses, Anthropic, Gemini | Selects the managed provider/model |\n| `minimax-code` (`mcode`, `minimax`) | `.minimax/config.yaml` | Chat, Responses, Anthropic | Uses native `custom_provider`, retains official account |\n| `kimi-code` (`kimi`) | `.kimi-code/config.toml` | Chat, Responses, Anthropic, Gemini | Current TypeScript Kimi Code 2.x; context window required if unknown, not legacy Python Kimi CLI |\n| `deepseek-harness` (`dsh`) | `.dsh/profiles/{web,desktop,...}/cordis.patch.yml`, `.credentials.yaml` | Chat, Responses, Anthropic | Adds provider to native profiles; select it in the client; home-level shadowing is rejected |\n| `agy` (`antigravity`) | `.gemini/config/config.json` | Gemini native, Chat | Uses Enterprise Gateway settings; preserves other model entries |\n| `oh-my-pi` (`omp`) | `.omp/agent/models.yml`, `config.yml` | Chat, Responses, Anthropic, Gemini | Respects native profile directories and model roles |\n| `copilot` (`copilot-cli`) | `.copilot/providers.json`, `settings.json` | Chat, Responses, Anthropic | Uses native BYOK provider/model configuration |\n| `workbuddy` | `.workbuddy/models.json` | Chat | Select the added EasyMagic model in the client; official account retained |\n| `codebuddy` | `.codebuddy/models.json`, `settings.json` | Chat | Uses upstream model ID and native `openai-completions`; other unverified protocols deliberately excluded |\n| `zcode` | `.zcode/v2/provider_config.json` | Chat, Responses, Anthropic | Select EasyMagic in the client; encrypted active-provider state retained |\n\n`Chat` means OpenAI Chat Completions; `Responses` means OpenAI Responses. Protocol support depends on the selected site's groups and models too. A model using one protocol cannot be substituted into another client by changing a URL.\n\n## Commands\n\n```sh\neasymagic setup list\n\neasymagic setup opencode --key-id 123 --model your-model --dry-run\neasymagic setup opencode --key-id 123 --model your-model\n\n# Configure several already installed clients, or select explicit targets.\neasymagic setup all --clients claude-code,codex,opencode --key-id 123 --dry-run\neasymagic setup all --clients claude-code,codex,opencode --key-id 123 --yes\n\n# Real, provider-documented context limits; never guess these numbers.\neasymagic setup kimi-code --key-id 123 --model your-model --context-window YOUR_MODEL_CONTEXT\n\n# Restore a prior write. Later manual edits cause refusal unless --force is explicit.\neasymagic setup history\neasymagic setup restore RESTORE_ID --dry-run\neasymagic setup restore RESTORE_ID --yes\n\neasymagic doctor --client opencode --key-id 123\neasymagic doctor --client opencode --key-id 123 --check\n```\n\nA fresh `--config-dir` always isolates a client configuration. For Claude Desktop this is the **common parent** of `Claude` and `Claude-3p`, not an individual JSON file. `setup all` only chooses installed/configured clients unless `--clients` is explicit; it reports per-client results, and successful targets stay applied if another target fails. Each target receives its own restore ID.\n\nClaude Code and Codex use one active credential configuration in this CLI. Their `--provider` must remain `easymagic`; custom values are rejected before writes. Codex uses a global `auth.json` API key, so switching to another site requires configuring that site’s credential as well. Other providers’ entries are preserved, but this is not independent per-provider authentication.\n\nModel capacities are read from existing configuration or explicit `--context-window` / `--max-output-tokens` values. Unknown values are not fabricated. Kimi/Grok can require a capacity before writing. Use `--protocol` when a multi-protocol client should use a non-default protocol. `--provider` names stay under `easymagic` / `easymagic-*` so another provider cannot be overwritten accidentally.\n\n## Source references\n\n- [CC Switch native adapters](https://github.com/farion1231/cc-switch/tree/0afb1f26de6383f43d304bf3e7ac77c4ffc6d15f/src-tauri/src): app registry and native configuration contracts.\n- [CC Switch CLI](https://github.com/SaladDay/cc-switch-cli): terminal provider management, native settings and backup concepts.\n- [Gemini CLI](https://github.com/google-gemini/gemini-cli): `packages/core/src/core/contentGenerator.ts`, config/auth and environment handling.\n- [Kimi Code](https://github.com/MoonshotAI/kimi-code): `docs/en/configuration/config-files.md` and providers schema.\n- [OpenCode](https://github.com/anomalyco/opencode): released v1 configuration versus v2 development schema.\n- [Pi](https://github.com/badlogic/pi-mono): model registry, provider definitions and credential precedence.\n- [Grok Build](https://github.com/xai-org/grok-build), [MiniMax Code](https://github.com/MiniMax-AI/minimax-code): native custom provider and model schemas.\n\n## Verification scope\n\nAll 18 adapters have local configuration, preservation, protocol rejection, write/backup and restore checks. Native installed-client tests additionally cover Claude Code/Codex, Kimi Code 2.8.1, Gemini CLI 0.71.1, OpenCode and Pi where recorded by the test results. A local mock proves configuration is consumed and the expected protocol is emitted; it does not prove that every public model or every future client version works. Desktop-only applications have file-contract checks rather than a claimed desktop launch on a headless server.\n";
|
|
21595
21801
|
|
|
21596
21802
|
// BACKEND_INTEGRATION.md
|
|
21597
|
-
var BACKEND_INTEGRATION_default = "# 浏览器授权与多账户集成\n\n## 交付位置\n\n- 后端补丁基于提交 `4ee7497aa`,开发分支为 `feat/cli-device-login`。\n- `backend/device-login.patch`:适用于以上基础提交的功能补丁。\n- `backend/device-login.current-worktree.patch`:根据集成时的主站既有工作区生成,只追加本功能,保留原有 gzip、日志及其它改动。\n- 已将 current-worktree
|
|
21803
|
+
var BACKEND_INTEGRATION_default = "# 浏览器授权与多账户集成\n\n## 交付位置\n\n- 后端补丁基于提交 `4ee7497aa`,开发分支为 `feat/cli-device-login`。\n- `backend/device-login.patch`:适用于以上基础提交的功能补丁。\n- `backend/device-login.current-worktree.patch`:根据集成时的主站既有工作区生成,只追加本功能,保留原有 gzip、日志及其它改动。\n- 已将 current-worktree 补丁追加应用到当前主站源码,保留原有改动。网站发布状态见本文末尾。用于其他检出版本时,先在目标目录运行 `git apply --check <补丁路径>`;检查通过后才应用,不能把隔离工作区整体覆盖到主站。\n\n## 端点和用户流程\n\n| 端点 | 认证 | 用途 |\n| --- | --- | --- |\n| `GET /api/cli/device/capabilities` | 公开 | 检查服务端支持 |\n| `POST /api/cli/device/start` | 公开、限流 | 创建 10 分钟授权请求,返回设备秘密和公开配对码 |\n| `POST /api/cli/device/poll` | 请求体的设备秘密 | 5 秒最小间隔轮询,只返回一次 PAT |\n| `POST /api/cli/device/cancel` | 请求体的设备秘密 | 取消未完成请求 |\n| `GET /api/cli/device/info?user_code=...` | 已登录浏览器会话 | 查看请求名称和固定权限 |\n| `POST /api/cli/device/approve` | 浏览器会话、同源、一次性安全证明 | 批准请求 |\n| `POST /api/cli/device/deny` | 浏览器会话、同源 | 拒绝请求 |\n| `GET /cli/authorize` | 页面公开,操作需要浏览器会话 | 后端内置的授权确认页面 |\n\n`easymagic login` 默认发起浏览器授权,`--no-browser` 只打印链接和配对码;`--token-stdin` 保留为未部署新端点站点的登录方式。配对页面通过已有刷新 cookie 恢复短期浏览器 JWT;密码、TOTP 和 Passkey 使用现有安全验证端点,禁止将 PAT 当作浏览器会话批准。仅绑定第三方 OAuth 且没有上述验证方式的账户,页面会明确引导到原控制台创建 PAT,不降级认证要求。\n\n新增 PAT 固定授权为 `profile:read`、`api_key:read`、`api_key:write`、`api_key:reveal`、`usage:read`,有效期 30 天。授权页明确显示这些权限,用户主动确认,网页批准响应不含完整 PAT。\n\n## 安全控制\n\n复用已有 `auth_flows` 和 `user_access_tokens`,无新增表或列。设备秘密只保存 HMAC;配对码索引也只保存 HMAC。完整 PAT 仅在领取时从高熵设备秘密派生,在数据库保存指纹,不保存可用明文。领取和创建 PAT 在同一事务内完成;先锁定流程和用户,保证同一请求仅领取一次,并发请求不超过账户 PAT 数量上限。领取前重新验证原批准会话,撤销会话后不能继续领令牌。\n\n10 分钟过期、限流、最小轮询间隔、拒绝、取消和单次领取都由服务端执行。轮询使用独立限流桶,不消耗登录/审批额度;重复审批、取消与领取使用一致锁顺序,防止死锁和已取消请求被误报批准。浏览器批准必须同时满足有效会话、可信 Origin 和使用独立 `cli.device.approve` scope、与本次配对码/权限/到期时间绑定的一次性安全证明。确认页使用 nonce CSP、`frame-ancestors 'none'`、`Referrer-Policy: no-referrer`、`Cache-Control: no-store`。页面使用 `textContent` 输出设备名;设备码、公开配对码及 PAT 不写入访问日志,安全审计只记录名称、权限、有效期与结果。\n\n实现参考 OWASP Authentication、Session Management、OAuth2、CSRF Prevention Cheat Sheets 的传输、重验证、一次性令牌、同源验证和不记录秘密原则;不宣称安全认证。生产部署仍需配置 HTTPS 和可信浏览器来源,并沿用现有 cookie/代理设置。\n\n## Profile 与系统凭据\n\n`profile list/use/delete` 和全局 `--profile` / `EASYMAGIC_PROFILE` 支持多个站点账户。旧单账号文件按需迁移,列表不返回凭据。每个保存动作使用独立秘密引用,成功提交配置后才清理旧秘密。\n\n`--credential-store auto|file|keychain` 或 `EASYMAGIC_CREDENTIAL_STORE` 控制保存位置。auto 优先使用 macOS Keychain、Linux Secret Service(secret-tool)、Windows 当前用户 DPAPI;不可用时明确记录为 private file。keychain 模式失败不会静默降级。秘密经标准输入传递,不拼进 shell 或进程参数。文件保存仍为 POSIX 0600;Windows 采用目录 ACL 和当前用户 DPAPI。\n\n## 已执行验证\n\n- TypeScript 检查;`bun test test/auth-profiles.test.ts`:6 项通过,覆盖旧文件迁移、profile 隔离、环境令牌绕过锁定钥匙串、坏引用拒绝、写盘失败不删除旧秘密、浏览器设备轮询和跨域授权链接拒绝。\n- `go test ./model ./controller ./router -run 'TestCLIDevice|TestAccessTokenRoute' -count=1`:流程状态、控制器安全检查、路由权限声明。\n- 三数据库模型矩阵:SQLite **3.50.4**、MySQL **8.4.13**、PostgreSQL **18.6**,全部通过。每次创建独立临时库,结束后删除。两次 AutoMigrate 检查重复启动;覆盖过期、拒绝、取消、轮询节流、会话撤销、同一请求并发领取、两个设备竞争最后一个 PAT 名额、数据库无秘密明文。\n- 独立 HTTP 后端 + 实际 CLI:创建测试账户 → CLI 发起授权 → 浏览器身份进行安全验证并批准 → CLI 取得 PAT → 读取账户资料,全链路通过;确认页 CSP 和访问日志秘密检查通过。测试后端及账户与生产隔离。\n- macOS/Windows 原生凭据写入、读取、删除由仓库 CI 的 `scripts/keychain-smoke.ts` 执行;仅根据对应 CI 的实际结果判断是否通过。\n\n重跑数据库矩阵时,为**专用空测试库**设置 `CLI_TEST_MYSQL_DSN` 和 `CLI_TEST_POSTGRES_DSN`,执行 `go test ./model -run TestCLIDeviceDatabaseMatrix -count=1 -v`。没有设置 DSN 时对应数据库会跳过,不能将跳过算作通过。\n\n## 本次集成与浏览器验收\n\n配套改动已通过增量补丁应用到主站源码,保留了既有工作区修改。在后端源码目录执行 `GOTOOLCHAIN=go1.27.4 go test ./model ./controller ./router -run 'TestCLIDevice|TestAccessTokenRoute' -count=1`,三个包全部通过。\n\nPlaywright 在隔离的 `http://127.0.0.1:18891` 测试服务完成了真实页面加载、现有登录态恢复、密码再验证、确认授权,以及等待中的实际 CLI 领取并保存 PAT。桌面和 390px 手机视口截图保存在 `output/playwright/`(本地验收产物,不打进 npm 包)。测试服务和测试账户均非生产。生产站点须使用含这些端点的后端版本;网站发布状态见本文末尾。\n\n## 0.4:可恢复的自动配置与首次协议确认\n\n`onboard CLIENT` 把登录、创建客户端专用推理密钥和写入客户端配置连接起来。AI 使用 `onboard CLIENT --start --json` 获取授权链接与 `onboarding_id`,用户在浏览器确认后,调用 `onboard --resume ID --json` 继续。`login --start/--resume/--cancel` 也可独立使用。完成结果和恢复状态不返回 PAT 或完整推理 key;登录流程临时秘密仅保存在私有 `auth-flows/` 文件,完成后删除。\n\n首次创建 key 可能要求两份 API 密钥使用协议。授权页现在通过现有浏览器会话接口读取 `token-agreements` 状态,显示当前版本完整条款;只有用户分别勾选、挑战仍有效且签署成功,才继续身份再验证与设备授权。刷新或签署失败会清除勾选;拒绝授权不会签署协议。协议已经签署或站点未启用该要求时无需重复签署。仍由原服务端强制校验会话、挑战版本/期限、Origin 和安全证明,CLI 不代用户接受协议。\n\n新增的 `controller/cli_device_test.go` 覆盖页面安全响应头和实际内嵌脚本的同意状态:未勾选、只勾选一份、过期、版本变化、签署失败、已签署、拒绝以及更改配对码。测试与 HTML 已同步到主站源码,两份增量补丁同步更新,并通过各自工作区的 `git apply --reverse --check` 核对。\n\n本次安全复核参考 [OWASP ASVS 5.0](https://github.com/OWASP/ASVS/tree/v5.0.0_release) 的 V3(浏览器安全)、V6(认证)、V7(会话管理)章节,以及 [Authentication](https://cheatsheetseries.owasp.org/cheatsheets/Authentication_Cheat_Sheet.html)、[Session Management](https://cheatsheetseries.owasp.org/cheatsheets/Session_Management_Cheat_Sheet.html)、[CSRF Prevention](https://cheatsheetseries.owasp.org/cheatsheets/Cross-Site_Request_Forgery_Prevention_Cheat_Sheet.html) 指引。验证范围是上述控制及回归用例,不代表获得安全认证。\n\n0.4 CLI 已通过本地完整检查:136 项测试、743 个断言、独立安装包验证及 18 个客户端配置/备份/恢复流程。对应提交 `3fc6143` 的 [跨平台 CI](https://github.com/XzlmTech/easymagic-cli/actions/runs/46566200923) 全部 9 项通过,包含 Linux/macOS/Windows 的 Node 22/24 测试和三个系统上的 Claude Code/Codex 原生检查。新增状态与调用契约见 [AI_USAGE.md](AI_USAGE.md) 和 [CLI_CONTRACT.md](CLI_CONTRACT.md)。\n\n新的 Playwright 验收使用独立 SQLite 副本和 `127.0.0.1:18894`:测试账户尚未签署协议,两个勾选框默认关闭;只勾选一份仍无法授权;用户动作勾选两份并通过密码再验证后,实际 CLI `onboard --resume` 自动创建专用 key 并完成 Claude Code 配置。再次恢复同一编号返回相同的完成结果。整个验收使用测试账户和临时客户端目录;生产站点与用户真实 Agent 配置不受影响。\n\n数据库确认只新增一把密钥,两份协议签署时间均已写入;重复恢复后密钥数量不变。完成后私有授权流程文件已删除,服务日志未发现密码、PAT 或推理密钥。可复现脚本已实际运行并以 0 退出,测试后端、浏览器会话、临时数据库与凭据已清理。\n\n开发环境可用 `e2e/onboard-browser.py` 重现,需要 Python 3、已构建的 CLI/后端、Playwright CLI wrapper、测试 SQLite 与该测试账户的私有 JSON 凭据文件(`username` / `password`,0600)。脚本只启动数字 loopback 服务,将源 SQLite 只读复制到临时目录,并在结束时清理测试服务和临时状态:\n\n```sh\npython3 e2e/onboard-browser.py --backend-bin /path/to/test-backend \\\n --fixture-db /path/to/test-fixture.db --credential-file /private/test-login.json \\\n --playwright-wrapper /path/to/playwright_cli.sh --port 18894\n```\n\n## 2026-12-01 授权安全复核\n\n补丁新增独立设备审批证明,不能混用普通 PAT 创建证明,也不能在同权限、同到期时间的两个设备请求间互换。已验证缺少/错误 Origin、缺少证明、无效会话、账号禁用、密码版本变化、撤销/过期会话、取消/过期请求、重复领取与并发 PAT 数量限制均不能签发令牌。\n\n最终候选基于线上 `v20261130T112429+0800-72c6e0631a9a` 的冻结源码,仅追加 6 个文件、修改 9 个文件;数据库结构、依赖、既有管理后台与用户前端保持基线。已通过 SQLite 3.50.4、MySQL 8.4.13、PostgreSQL 18.6 的真实数据库回归、授权相关 Go 测试与 vet,以及真实浏览器协议确认 → CLI 恢复 → 单次创建密钥 → Claude Code 配置的完整验收。\n\n适用控制参考 OWASP ASVS **5.0.0**:6.3.1(限流)、6.6.2(请求绑定)、7.2.1/7.2.3(服务端验证/随机性)、7.4.1/7.4.2(撤销/禁用)、10.4.9/10.4.11(撤销/最小权限)、10.7.1/10.7.2(明确同意),以及 Authentication、Session Management、CSRF、OAuth2 Cheat Sheets。设备码钓鱼无法仅靠协议完全消除:用户应只确认自己终端发起的代码;此页始终展示该警示。此复核仅覆盖本次功能,不是整站安全认证。\n\n### 网站发布状态\n\n2026-12-01 已部署到 `https://easymagic.ai`,后端版本 `v20261201T171639+0800-919955c75b35`。公网设备端点、授权页及尾斜杠路由、安全响应头和未授权拒绝验证通过;实际 CLI start/cancel 通过。线上及本机入口共 46 项检查通过,发布探针 2707 次、失败 0 次。经用户同意仅让一条旧空闲 WebSocket 重连一次完成交接。本次网站部署无需重新安装 npm 包即可获得服务端授权能力。CLI 发布流程见 [RELEASING.md](RELEASING.md)。\n\n### 授权页呈现\n\n授权页改为紧凑的品牌确认窗口。权限摘要、账户、设备与配对码保留,权限细项及两份协议全文默认折叠;未签署用户仍需分别主动勾选。单一验证方式不显示多余选择框,读取失败可原地重试,授权/取消后显示独立结果。仅精简呈现,原有服务端同源检查、一次性证明和权限范围不变。\n";
|
|
21598
21804
|
|
|
21599
21805
|
// AUDIT.md
|
|
21600
21806
|
var AUDIT_default = `# 0.4.1 安全与流程复核
|
|
@@ -21648,6 +21854,20 @@ var AUDIT_default = `# 0.4.1 安全与流程复核
|
|
|
21648
21854
|
AI 模式明确通过 \`ai\` / \`--ai\` 选择,默认非阻塞、不打开浏览器。正常结果、帮助、版本、缺少子命令和错误均验证为 JSON;原来的 \`--json\` 保持兼容。
|
|
21649
21855
|
|
|
21650
21856
|
验证:166 项测试、1106 个断言通过,18 种 Agent 配置/备份/恢复流程通过;真实 PTY 验证 40/80/120 列、NO_COLOR、TERM=dumb、隐藏 PAT、取消不写入以及请求子进程回收。独立复核确认取消行为、完整确认信息及 10 种 AI 输出路径。新终端依赖的许可证随安装包提供,依赖审计未报告已知漏洞。
|
|
21857
|
+
|
|
21858
|
+
## 0.5.1 首页品牌与语言偏好
|
|
21859
|
+
|
|
21860
|
+
首页新增始终可识别的“中文 / English”菜单项,选择后立即刷新界面并将偏好保存到独立 \`preferences.json\`;不改账号元数据、PAT 或推理密钥。优先级为显式 \`--lang\`、\`EASYMAGIC_LANG\`、保存的界面偏好、系统语言。AI 模式不读取该偏好。
|
|
21861
|
+
|
|
21862
|
+
品牌区采用原 EasyMagic EM 标识的纯文本终端形式,配有本地双语介绍和完整官网地址;窄屏及 \`TERM=dumb\` 使用紧凑版本,不请求远程图片。172 项测试、1228 个断言、18 种客户端流程通过;真实 PTY 与独立复验覆盖语言切换、记忆、取消、NO_COLOR 和 40/80/120 列显示。
|
|
21863
|
+
|
|
21864
|
+
## 未发布修复:首次引导与登录诊断
|
|
21865
|
+
|
|
21866
|
+
首次手动启动固定先选择语言,再进入引导配置;用户可选择稍后配置,此后默认打开控制台,并可从“引导配置”重新进入。\`onboardingCompleted\` 只表示已经看过首次介绍,不代表登录或 Agent 配置成功。取消语言选择或尚未确认介绍时不写完成标记。
|
|
21867
|
+
|
|
21868
|
+
浏览器设备授权端点返回 404/405 时,CLI 返回 \`DEVICE_LOGIN_UNSUPPORTED\` 并说明站点尚未提供对应接口。手动界面可保留原站点及 profile,改用隐藏输入的 PAT 登录。403 权限拒绝及安全网关拦截不触发这种回退,不通过重复输入凭据绕过服务端限制。
|
|
21869
|
+
|
|
21870
|
+
现场只读检查确认官网设备授权端点返回 404,而公共站点状态接口可用。未在生产环境创建授权请求或写入配置,也未部署后端。发布工作流已经取消并禁用,另以 \`NPM_PUBLISH_ENABLED\` 开关保护后续自动发布;本次修复不发布 npm。
|
|
21651
21871
|
`;
|
|
21652
21872
|
|
|
21653
21873
|
// src/commands/guide.ts
|
|
@@ -21762,7 +21982,7 @@ async function openInteractive(command) {
|
|
|
21762
21982
|
throw new Error("Interactive mode requires a TTY. Open a terminal, or use easymagic ai for machine-readable commands.");
|
|
21763
21983
|
}
|
|
21764
21984
|
await Promise.resolve().then(() => init_main3());
|
|
21765
|
-
await runInteractive({ profile: command.optsWithGlobals().profile, language: language3 });
|
|
21985
|
+
await runInteractive({ profile: command.optsWithGlobals().profile, language: command.optsWithGlobals().lang ? language3 : undefined });
|
|
21766
21986
|
}
|
|
21767
21987
|
program2.action(async (_options, command) => {
|
|
21768
21988
|
if (invocation.ai) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "easymagic",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.2",
|
|
4
4
|
"description": "Manage EasyMagic API keys, inspect usage, and configure coding clients",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -52,6 +52,7 @@
|
|
|
52
52
|
"AI_USAGE.md",
|
|
53
53
|
"CLI_CONTRACT.md",
|
|
54
54
|
"AUDIT.md",
|
|
55
|
+
"RELEASING.md",
|
|
55
56
|
"THIRD_PARTY_NOTICES.md"
|
|
56
57
|
],
|
|
57
58
|
"repository": {
|