Skip to content

feat(plugin): 支持 GitHub Release 安装源并升级 Dashboard 插件市场一键安装体验 - #3978

Merged
deepcoldy merged 2 commits into
masterfrom
feat/plugin-github-release-market
Nov 28, 2026
Merged

deepcoldy merged 2 commits into
masterfrom
feat/plugin-github-release-market

Conversation

@deepcoldy

Copy link
Copy Markdown
Owner

改动背景与目标

支持插件直接通过 GitHub Release 分发安装(无需发 npm 即可经 CLI 和 Dashboard 插件市场安装),并升级 Dashboard 插件市场的官方标识、一键安装确认与安装后启用引导体验。

改动内容

1. 新增 GitHub Release 插件安装源(保留既有 npm / 本地安装)

  • CLI & 安装器(src/core/plugins/github-release.ts、src/core/plugins/tar-archive.ts、src/core/plugins/install.ts、src/core/plugins/init.ts、src/cli.ts):
    • botmux plugin install 支持 github:<owner>/<repo>(最新正式 Release,强制非 draft 且非 prerelease)与 github:<owner>/<repo>@<tag>(指定 tag,拒绝 draft);同时支持 install-verified 对已核验 GitHub Release tarball 落盘。
    • 统一校验 Release 资产中的单个 .tgz 与配套 .tgz.sha512(标准 SRI sha512-<base64>,兼容纯 SRI 行或带文件名尾缀,拒绝文件名不一致或缺失校验文件);若 GitHub Release API 资产自带 digest: "sha256:..." 则同步做辅助交叉核验。
    • 独立实现安全 tar 解包器(tar-archive.ts):限制解压体积上限(200 MiB 防解压炸弹)、校验 tar header checksum、支持 POSIX ustar / PAX / GNU LongLink、拒绝符号链接 / 硬链接 / 设备文件 / 路径穿越 / 越界 package/ / 重复 package/package.json。
    • 复用 src/core/release-download.ts 新增的单跳 requestReleaseHop(支持标准代理与 CONNECT 隧道、重定向拆连接)实现安全下载边界。
  • 元数据与清理兼容(src/core/plugins/types.ts、src/core/plugins/mutation-guard.ts、src/core/plugins/install.ts):
    • InstalledPluginRecord.source 扩展为联合类型,新增 { type: 'github-release', repo, tag, asset, integrity },兼容既有 npm / local 记录。
    • cleanupRetiredPluginHomes 同步识别 github-release 来源;PluginMutationGuard 新增可选 source 字段供 install-verified 精确记录来源。

2. Dashboard 插件市场后端扩展(src/dashboard/plugin-market.ts)

  • 向后兼容 schemaVersion: 1 的目录结构,扩展 entrySchema 支持可选 official?: boolean 及 distribution?: { type: 'npm' } | { type: 'github-release'; repo: string; assetPattern?: string }(缺省按 npm 处理)。
  • prepare() 遇到 distribution.type === 'github-release' 时调用 GitHub Releases API 拉取最新正式 Release(可选读取 GITHUB_TOKEN / GH_TOKEN / ~/.botmux/.env / gh auth token 做只读鉴权缓解匿名 60/h 限流),锁定 version、integrity(sha512-...)、downloadUrl、sourceType: 'github-release'、releaseRepo、releaseTag、releaseAsset 写入 PendingPlan。
  • install() 仅从 PendingPlan 锁定的 downloadUrl 下载(不再重复查询 Releases API),校验 sha512(及可选 sha256)与 package/package.json 后调用 botmux plugin install-verified,不削弱任何现有 CSRF、TOCTOU(expectedState / expectedRevision)、authorityDigest 与 assertPluginServiceStopped 门禁。

3. Dashboard 官方插件市场前端升级(src/dashboard/web/plugin-page.tsx、src/dashboard/web/plugin-market.css)

  • 将「发现」Tab 升级为「插件市场」(同时兼容 #/plugins?view=discover 与 #/plugins?view=market 路由)。
  • 官方标识:entry.official === true 或 entry.package.startsWith('@botmux-ai/') 展示「官方」徽标;详情与确认弹窗明确区分「Botmux 官方插件」与「社区插件目录(非安全认证)」,并展示分发来源(npm / GitHub Release)。
  • 卡片直接一键安装:未安装卡片底部提供主按钮「安装」与「详情」,点击「安装」直接触发 prepare() 弹出确认框展示版本号、安装来源与 SHA-512 摘要;已安装卡片展示「已安装」状态并提供「详情 / 管理 / 检查更新」入口。
  • 来源筛选与安装后引导:已安装列表来源筛选新增 GitHub Release(保留既有 本地安装 / npm 安装);安装成功后在提示条中提供「前往启用 / 管理」(跳转已安装视图并直接打开管理弹窗)与「打开配置」(有 Dashboard 页面时)。
┌──────────────────────────────────────────────────────────────────────┐
│ 插件                                              [已安装 N] [插件市场 M] │
│ [搜索插件                  ]  [全部来源 / 本地安装 / npm 安装 / GitHub Release] │
├──────────────────────────────────────────────────────────────────────┤
│ ▏已安装 GitHub (v0.1.0),默认未启用,可前往插件卡片启用或配置。                 │
│ ▏                                        [前往启用 / 管理]  [打开配置]   │
├──────────────────────────────────┬───────────────────────────────────┤
│ GitHub  [官方]                    │ Weather                           │
│ @botmux-ai/plugin-github         │ botmux-plugin-weather             │
│ 官方 GitHub 插件                  │ 社区天气插件                        │
│ [vcs]                            │ [tools]                           │
│ GitHub Release    [详情] [ 安装 ] │ npm               [详情] [ 安装 ]  │
└──────────────────────────────────┴───────────────────────────────────┘

安全边界与影响面评估

  • 下载白名单与重定向:仅允许 https: + 443 端口 + 无 URL 内嵌凭据,主机名严格白名单(api.github.com、github.com、objects.githubusercontent.com、release-assets.githubusercontent.com),每跳重定向均重新校验并限制最多 5 跳。
  • 凭据隔离:可选 GitHub 只读 Token 仅发往 api.github.com,重定向至 github.com / CDN 时剥离 Authorization 头;401 时自动匿名重试一次;Token 不写入日志、错误文案、前端响应或 PendingPlan。
  • 完整性与原子性:强制校验 .tgz.sha512(绝不裸装无校验 tarball)、体积上限 50 MiB(兼顾 Content-Length 与实际流式字节数)、超时中断与失败清理临时目录;落盘沿用 withPluginServiceLockSync + 清理前后双重 assertPluginMutationGuard + assertExistingPluginServiceStopped + 失败回滚。
  • 影响面:涉及插件安装器(core/plugins/*)、共享下载辅助函数(core/release-download.ts 新增 requestReleaseHop,既有 getReleaseStream 签名和行为不变)、CLI plugin install 与 Dashboard 插件市场页面;不影响任何 CLI 适配器、会话后端或现有已安装插件记录。

验证结果

构建与类型检查

  • bun run build:通过(含 audit:domains、tsc、typecheck、dashboard:bundle、audit-dist、audit-embedded-assets)
  • bun run typecheck:通过

自动化测试(Vitest + Bun 双腿全绿)

  • Vitest(13 个测试文件,271/271 通过):
    • npx vitest run --project unit test/plugin-github-release.test.ts test/dashboard-plugin-market.test.ts test/dashboard-plugin-market-github.test.ts test/dashboard-plugin-page-market.test.ts test/plugin-integrated-management.test.ts test/plugin-dashboard-service-fetch.test.ts test/plugin-mutation-guard.test.ts test/plugin-retired-cleanup-adversarial.test.ts test/plugin-market-final-verification.test.ts test/plugin-manifest-store.test.ts test/plugin-init.test.ts test/update-check-proxy.test.ts test/test-hygiene.test.ts
  • Bun(7 个双腿测试文件,113/113 通过):
    • bun test test/plugin-github-release.test.ts test/dashboard-plugin-market.test.ts test/dashboard-plugin-market-github.test.ts test/dashboard-plugin-page-market.test.ts test/plugin-integrated-management.test.ts test/plugin-dashboard-service-fetch.test.ts test/plugin-manifest-store.test.ts

关键安全守卫变异复验(经 bun scripts/fenced-run.ts 围栏执行,8/8 均咬红)

  1. 重定向目标域名白名单校验(assertAllowedGithubReleaseUrl)— KILLED
  2. Authorization 请求头仅限 api.github.com — KILLED
  3. installGithubReleaseArchive 的 sha512 完整性校验 — KILLED
  4. tar-archive 拒绝符号链接(typeflag === '2')— KILLED
  5. cleanupRetiredPluginHomes 兼容 github-release 来源 — KILLED
  6. installGithubReleaseArchive 清理后二次 assertPluginMutationGuard 复核 — KILLED
  7. 市场 prepare() 对 downloadUrl 的域名白名单校验 — KILLED
  8. 市场 install() 对下载产物的 verifyPluginArchive 校验 — KILLED

🤖 Generated with Claude Code

- 新增 GitHub Release 插件安装源(`github:<owner>/<repo>` 与 `github:<owner>/<repo>@<tag>` 及 `install-verified` 复用),强制校验 `.tgz` + `.tgz.sha512` 完整性摘要、HTTPS 白名单域名、安全重定向、50 MiB 上限与超时控制,并复核 `package/package.json` 及 `PluginMutationGuard` 原子安装与回滚
- 扩展 `InstalledPluginRecord.source` 支持 `{ type: 'github-release', repo, tag, asset, integrity }`,兼容既有 `npm` / `local` 记录与 `cleanupRetiredPluginHomes`
- 扩展 Dashboard 插件市场后端向后兼容 `official` 与 `distribution`(`npm` / `github-release`),在 `prepare()` 锁死版本、来源、下载地址与完整性摘要,在 `install()` 严格按锁定地址下载校验后经 `plugin install-verified` 落盘
- 升级 Dashboard「插件市场」Tab:官方徽标与详情归属区分、卡片一键「安装」触发确认弹窗、已安装来源筛选支持 GitHub Release、安装后反馈提示支持快捷跳转启用/配置

Co-Authored-By: Claude Code <[email protected]>

@deepcoldy deepcoldy left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

复审结论:暂缓合入

发现 1 个需要修复的“官方”标识可信性问题,另有 3 个非阻断边界问题。以下 4 条均已用临时探针通过真实 React 组件、真实 token 缓存/子进程或自定义下载流复现;探针已删除,未修改 PR 代码。

1. 需要修复:本地/被替换的插件会误显示“官方”徽标

src/dashboard/web/plugin-page.tsx:802 的 PluginCard:

  • marketEntry 在上游仅按 entry.id === plugin.id 匹配,未核对 entry.package === plugin.packageName;
  • 没有目录条目时,又仅凭本地记录中的 packageName.startsWith('@botmux-ai/') 判定官方。

因此本地安装或被替换的插件,只要复用目录中的官方 ID,或自行声明 @botmux-ai/fake,管理卡片就会显示“官方”。这会把本地供应的 manifest/code 误标为官方来源。

探针结果:本地 id=github, packageName=local-github 与未列入目录的 @botmux-ai/fake 均渲染出了 data-official-badge。

建议:已安装卡片只在目录条目存在且 package 与安装记录一致时继承该条目的官方属性;不要对未列入目录或本地安装记录仅凭包名前缀显示官方。

2. 非阻断:gh auth 的未认证结果被缓存 10 分钟

src/core/plugins/github-release.ts:286 将 token: null 也写入 cachedGhToken。首次匿名/未认证调用后,用户按限流提示完成 gh auth login 并立即重试,仍会读取缓存的 null,直到 TTL 到期才再次执行 gh auth token。

探针结果:真实 execFile('gh') 路径连续三次结果为 [null, null, 'gho_new'],第二次认证已可用但仍被缓存 miss 遮住。

建议:不要缓存 null,或在认证/限流失败后使 miss 缓存失效。

3. 非阻断:目标文件打开失败时未清理响应流和超时定时器

src/core/plugins/github-release.ts:543 的 await open(destPath, ...) 位于 try/finally 之前。响应头已返回后,如果打开目标文件因 EACCES / ENOSPC / ENOENT 失败,函数会直接 reject,而不会执行 drainAndDestroy(stream) 或 cleanup();默认 120 秒定时器仍存活。

探针结果:以不存在的父目录触发 ENOENT 后,destroy 调用次数为 0、signal 初始未 abort,随后只能由测试设置的短超时触发 abort。

建议:把目标文件 open 纳入受保护的清理路径,在失败时销毁响应并清理 timer;文件句柄按是否成功打开做条件关闭。

4. 非阻断:安装成功但列表刷新失败时仍展示失效的管理快捷入口

src/dashboard/web/plugin-page.tsx:1266 中 load() 刷新失败会返回 null,但代码仍无条件把 pluginId 写入成功通知。此时旧 payload 中没有新插件,“前往启用 / 管理”仍会显示;点击后没有对应卡片或管理弹窗。

探针结果:安装接口成功、随后 /api/plugins 返回 500 时,快捷按钮仍出现;点击后 data-plugin-card=github 和对应启用开关均不存在。

建议:仅在刷新后的记录确实存在时展示这些快捷动作,或重试/合并已确认的安装结果后再展示。

验证

  • GitHub head:69d5f12182c72d3a3fa5885bb3637c30793f2e57;本地 rebase 树 846e874b5316f1c5cd0063fc565eb985b33e4d63 与其 patch-id 完全一致。
  • bun run build:通过。
  • PR 清单中的 13 个 Vitest 文件:271/271 通过;7 个 Bun 双腿文件逐文件运行:113/113 通过。
  • 额外补跑的插件生命周期、Dashboard、命令及共享下载相邻测试均通过;git diff --check 通过。
  • 上述 4 条临时复现探针:4/4 复现,随后已删除。
  • 直接以 bun test 运行仓库已标记 deferred 的 plugin-retired-cleanup-adversarial / plugin-mutation-guard 时,分别因既有 Bun shim 不支持 vi.mock 工厂回调 / vi.hoisted 而报错;两者的 Vitest 版本通过,正式 Bun runner 会排除,不属于本 PR 回归。

- 已安装卡片与计划弹窗只信任 id/package 双匹配的目录条目\n- 空 gh token 不再缓存,目标文件打开失败时清理响应与定时器\n- 安装后刷新失败时隐藏无效的管理快捷入口\n- 补充官方标识、token 缓存、下载清理与刷新失败回归测试\n\nCo-Authored-By: Claude Code <[email protected]>
@deepcoldy
deepcoldy merged commit b0300b5 into master Nov 28, 2026
19 checks passed
@github-actions

Copy link
Copy Markdown

@deepcoldy 合入 master 后的 Midscene E2E 失败:Feishu live Midscene 失败。

这次运行覆盖 b0300b5…cbeb67d12(4 个提交),同批合入的还有 #3977 #3982 #3981,失败不一定由本 PR 引起。

用例 跑道 状态 失败信息
Antigravity basic bot flow feishu-core-clis failed openThreadForMessage: couldn't find topic entry containing "e2e-antigravity-1795902111520" within 30000ms
Claude DM thread mode gives each message its own topic and session feishu-core-dm-modes-claude failed Node "feishu.runScenario" timed out after 1800000ms.
Codex DM chat mode replies inline and keeps one session feishu-core-dm-modes-codex failed Node "feishu.runScenario" timed out after 1800000ms.
Claude group reply mode new-topic starts a session per topic feishu-core-group-modes failed Node "feishu.runScenario" timed out after 1800000ms.
Claude group @ mode always ignores messages without an @ feishu-core-group-modes failed Reply "ACK-e2e-gm-always-claude-2-1795910134297 RECALL ACK-" appeared 0 time(s) within 240000ms, expected 1 (clicked 直接开启会话 0×; re-opened 1×; repo card buttons 0 visible / 0 total, anchor matches 3, …
Claude group @ mode never answers without an @ feishu-core-group-modes failed Reply "ACK-e2e-gm-never-claude-1-1795910977602 RECALL ACK-" appeared 0 time(s) within 240000ms, expected 1 (clicked 直接开启会话 0×; re-opened 1×; repo card buttons 0 visible / 0 total, anchor matches 3, n…
Claude group @ mode ambient answers without an @ but yields to others feishu-core-group-modes failed Reply "ACK-e2e-gm-ambient-claude-1-1795911803177 RECALL ACK-" appeared 0 time(s) within 240000ms, expected 1 (clicked 直接开启会话 0×; re-opened 1×; repo card buttons 0 visible / 0 total, anchor matches 3,…
Consecutive message queue feishu-core-queue failed Node "feishu.runScenario" timed out after 1800000ms.
Sandbox hides home and harness secrets feishu-core-sandbox failed openThreadForMessage: couldn't find topic entry containing "e2e-sbx-1795907974699" within 30000ms

@github-actions

Copy link
Copy Markdown

🚀 Released in v3.59.38

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant