Skip to content

feat(plugins): 命令安装器支持下载固定地址的压缩包 - #2241

Merged
xiaoyumuxi merged 5 commits into
mainfrom
feat/command-installer-downloads
Nov 20, 2026
Merged

xiaoyumuxi merged 5 commits into
mainfrom
feat/command-installer-downloads

Conversation

@xiaoyumuxi

Copy link
Copy Markdown
Collaborator

关联 Issue / Linked issue

PR 类型 / Type

  • feat:新功能或用户可见的改进

改动说明 / What changes

背景 / Why

插件声明的 systemCommand 缺命令时,现有命令安装器(API-23,commandInstallers 0)只能调用插件指定的工具来安装,例如 go install。
有些调试适配器没有包管理器可用,上游只发布按平台打好的压缩包。CodeLLDB 就是这样,每个平台一个 .vsix。
这类命令过去只能把压缩包打进插件,会让插件变大,而且每个平台都要单独打包。

Core #133 给 commandInstallers 加了能力版本 1:插件可以为每个平台固定一个压缩包,写明地址、可选镜像、SHA-256、格式(zip / tar.gz)、要去掉的前缀,以及命令在包里的目录。
本 PR 是桌面端的实现。用户在插件能力卡片上点“安装”,确认对话框里列出版本、地址、镜像和摘要,确认后宿主下载、校验、解压到插件自己的托管目录,之后的 systemCommand 启动就能找到命令。
下载、镜像测速与回退、SHA-256 校验和安全解压,全部复用 managedRuntimes 已有的 pluginruntime.Manager,没有新写下载器。

改动 / Changes

Core 客户端(desktop/internal/core/command_installers.go)

  • CommandInstallerRequirements 和 PlanCommandInstaller 新增 platform 参数,Core 据此为当前平台选压缩包;没有当前平台压缩包的下载安装器不会出现在需求里。
  • CommandInstaller.Tool 改为可空;新增 Download(固定版本)。CommandInstallPlan 新增 Download,内容包括地址、镜像、SHA-256、格式、去前缀、缓存键和命令目录。
  • 新增 consistent() 校验:下载计划只能是 managed 目标,不能带工具、参数、环境变量或目录探测;工具计划仍然要求“托管安装才有命令目录”。不一致的结果作为解析错误拒绝。

插件宿主(desktop/internal/pluginhost/)

  • 声明 commandInstallers 支持 [0, 1]。
  • 新增三个一一对应的错误码:plugin.commandInstaller.downloadFailed(所有地址都没下到)、checksumMismatch(SHA-256 不符)、archiveInvalid(不是 zip/tar.gz,或条目不能安全解压)。CommandInstallError 增加 Err 和 Unwrap,诊断里带上底层原因。
  • commands/<安装器 ID>/ 的布局注释补上下载安装器的 <缓存键>/ 子目录。

托管运行时(desktop/internal/pluginruntime/、desktop/internal/pluginservice/)

  • 新增 pluginruntime.ErrDownload:所有候选地址都失败时,用它包住最后一个地址的错误。调用方由此能区分“没下到”和“下到了但摘要不符”。原先直接返回最后一个错误;相应测试改为同时断言两者。
  • 抽出 pluginservice.ArchivePlatform(),managedRuntimes 和命令安装器共用同一个平台值。

工作台(desktop/internal/workbench/command_installers.go)

  • Offer:下载安装器不解析工具,只返回版本、地址、镜像、摘要,目标只有 managed,没有命令行。这一步不发起任何网络请求(有测试覆盖)。
  • Install → download():用 pluginruntime.Manager{Root: 安装器托管目录}.Prepare 下载、校验和解压。校验器检查每个命令都在计划的命令目录里;检查通过后写入 commands.json,再删掉同一安装器其他缓存键的旧解压目录。
  • downloadFailure 把失败映射到上面三个错误码,并与已有的超时、取消区分开:用户取消不记录;传输卡住时,以安装自己的期限判定为超时。
  • Missing:下载安装器没有工具名,卡片上显示为下载安装。
  • 日志沿用已有的插件 attempt(StartPluginAttempt / EndAttempt)和 recordFailure,下载失败按阶段记一条终态,没有新增事件。

设置窗口(desktop/internal/settingswindow/)

  • 安装对话框新增下载卡片,依次是:首行“安装 <命令>(版本 x)”、校验说明、地址,以及“镜像”“SHA-256”标签行。标签用正文字体,地址和摘要用等宽字体。
  • 安装中显示下载进度(已下载/总大小)和解压阶段;失败时显示三个错误码各自的翻译。
  • CommandInstaller.Install 接口新增 progress 回调,可从任意 goroutine 调用。

界面文案

  • 新增 shared/i18n/features/command-installer-downloads.json,含 8 条中英词条:commandInstallDownloadPrompt、DownloadNetwork、Source、Mirror、Digest、DownloadFailed、ChecksumMismatch、ArchiveInvalid。生成结果已提交。

文档、Note 与矩阵

  • Agent Note 2026-11-15-plugin-command-installers.md 写入下载安装器的结论、做法、被否方案 6–9,以及后果和验证。被否方案 8 说明:命令下载会删旧缓存键,managedRuntimes 却保留旧目录,这是两边有意不同的取舍。
  • docs/ci-builds.md 写明 <插件根>/.state/<插件 ID>/commands/<安装器 ID>/<缓存键>/ 的归属、生命周期,以及不能跨工作树复制的原因。
  • docs/development/macos-plugin-api-plan.md 的 API-23 行补充 commandInstallers 1。
  • 功能矩阵 plugin-command-installers.json 更新能力、两端证据和验证动作。验证动作用通用的测试插件描述,不引用具体插件。

Core 固定版本

顺带修复:既有测试在 -race 下超时(main 上同样失败)

  • pluginservice/runtime_trust_test.go 的 TestManagedToolchainFactsFeedToolchainResolutionWithoutStartingBackend 把约 250 MB 的测试二进制用 Deflate 压进 zip 当运行时。-race 会给标准库 flate 也插桩,压缩加解压超过了 20 秒期限,表现为 managed runtime archive is not safe to extract: context deadline exceeded。
  • 我在 origin/main(9cd03eb)上复现了同样的失败。改为 zip.Store 后,-race 下从超过 20 秒降到 4.55 秒;不开 -race 时 1.6 秒。测试断言没有改。

不在本 PR 范围内 / Out of scope

  • 声明下载安装器的具体插件(Rust Support 的 CodeLLDB)在插件仓库另行提交,宿主不含任何插件专属逻辑。
  • Windows 真机验收、macOS 原生整机验收还没做,矩阵里两端验证状态保持 pending。
  • managedRuntimes 保留旧缓存键目录的行为不改:这是已有 Note 记录的有意取舍,见上面的被否方案 8。

类型专属:feat

多平台对齐

  • 两端都具备:实现全部在共享的 Viva Go 桌面端代码里,macOS 与 Windows 用同一份代码。Windows 的单元测试由 ready 后的完整 CI 覆盖,Windows 真机验收待做(见“验证”)。

范围检查 / Scope checks

功能矩阵 / Feature matrix

  • 已更新 shared/platform-feature-matrix/features/plugin-command-installers.json:能力、两端证据和验证动作已更新;没有运行的真机验证保持 pending
  • 已运行 ./scripts/platform-feature-matrix/verify-platform-feature-matrix.sh(218 validated)和 ./scripts/platform-feature-matrix/verify-platform-feature-matrix-change.sh origin/main HEAD(passed)
  • 没有提交 .artifacts/ 下生成的矩阵视图
  • [N/A] 没有更新矩阵的理由:已更新

插件归属 / Plugin ownership

  • 已在仓库根目录运行 develop-lithe 第三节的自查命令,结果为空
  • 新增或修改的测试只使用测试内联的合成插件(dev.lithe.test.*)和本地生成的压缩包,没有真实插件 ID,没有“缺少插件时跳过”的测试
  • 没有为具体插件提供的能力新建宿主矩阵条目;矩阵的验证动作写的是“声明下载安装器的测试插件”
  • 插件文案没有写进 shared/i18n/;插件的构建步骤和资源路径没有写进 docs/ci-builds.md、Note 或 Skill
  • 修改了通用扩展点:在 Go 插件仓库(Lithe-IDEA/lithe-plugin-go main 241c26c)用已发布的 go-support-1.3.1-darwin.zip,执行 node scripts/e2e-host.mjs --source <本仓库> --ref feat/command-installer-downloads,projectgen 5 项和 workbench 4 项(含 Delve 调试)全部通过

UI 验证 / UI evidence

  • 已运行 Viva 无头视觉测试:LITHE_VISUAL_OUTPUT_DIR=… scripts/desktop/desktop-go.sh test -tags 'vivahead lithevisual' ./internal/settingswindow/ -run TestVisualCommandInstall -count=1。暗色为中文、亮色为英文,覆盖“确认下载”和“下载中”两个状态
  • 截图已提交到 docs/assets/command-installer-downloads/ 并嵌入下方
  • 这是新增状态,没有改动前的对照;明暗主题和中英文都已覆盖。macOS 原生窗口验收待做
状态 暗色 · 中文 亮色 · English
确认下载 download dialog dark download dialog light
下载中 download progress dark download progress light

统一日志系统 / Structured logging

  • 沿用已有的插件 attempt(core.StartPluginAttempt / EndAttempt)和 recordFailure("plugin_command_install", …),没有新增事件,也没有 print 或直接写 stderr
  • 一次安装只有一条终态,下载失败按阶段(resolve / decode / timeout)记录;用户取消不记录
  • 诊断只带错误码和底层错误,没有记录压缩包内容、环境变量或命令输出
  • [N/A] 旧日志校验脚本:本 PR 没有涉及

界面文案 / i18n

  • 宿主文案都走共享 i18n:新增 shared/i18n/features/command-installer-downloads.json(8 条中英词条),已运行生成脚本并提交 shared.generated.go
  • 插件文字没有写进 shared/i18n/
  • 已运行 node scripts/i18n/verify-app-language-localization.mjs 和 node scripts/i18n/generate-i18n.mjs --check,都通过

逻辑归属 / Logic placement

  • 下载安装器的声明校验、平台选择、缓存键和命令目录都在 Rust Core(功能建议:设置支持日志相关操作 #133),并配有契约 fixture;桌面端只负责下载、解压(原生 I/O)和呈现
  • [N/A] 平台层已有的可共享逻辑:本 PR 没有新增平台层判定逻辑
  • 宿主和 Core 没有按工具名或插件名加分支

性能与内存 / Performance and memory

  • 只在用户确认安装后才下载;没有新增空闲轮询;进度回调只更新最后一个阶段;缓存键变化时删掉旧解压目录,不会持续占用磁盘
  • 下载、校验和解压都在安装的 goroutine 上,不在主线程
  • [N/A] 性能基线:本 PR 不涉及启动、打开项目、输入、滚动、大文件、长输出或搜索

设置 / Settings

  • [N/A] 没有新增设置项或设置页,只是在已有的插件能力卡片安装对话框里新增一种安装方式

插件契约 / Plugin contract

原计划编号 方法 用途
— 无新增宿主方法 API-23 的 commandInstallers[].download 是清单字段;Core API plugins.commandInstallers.requirements / plan 新增 platform 参数,由宿主内部调用,不对插件开放

发行包与资源 / Bundle and resources

  • 下载和解压只写到 <插件根>/.state/<插件 ID>/commands/<安装器 ID>/<缓存键>/,即平台存储里的插件状态目录,不写 app bundle 或安装目录;已运行 ./scripts/desktop/verify/verify-runtime-bundle-immutability.sh,通过
  • 已在 docs/ci-builds.md“独立工作树的本地编译”一节写明路径、归属、生命周期,以及不能跨工作树复制的原因

无用代码与重构 / Dead code and refactoring

  • 本次改动没有让任何代码变成无用代码
  • [N/A] 既有可重构之处:managedRuntimes 保留旧缓存键是已记录的有意取舍,不算债务;顺带修的 -race 超时只改了一行夹具,已在上面“改动”里单独说明

验证 / Verification

命令或操作 平台 结果
scripts/desktop/desktop-go.sh test ./...(固定到 f9af83e 时) macOS arm64 通过
固定版本换到 72036de 后:desktop-go.sh test -count=1 ./internal/core/ ./internal/pluginhost/ ./internal/pluginruntime/ ./internal/pluginservice/ ./internal/settingswindow/,以及 ./internal/workbench/ -run 'Command(Download|Install)' macOS arm64 通过
desktop-go.sh test -race -count=1 core / pluginruntime / pluginhost / pluginservice / settingswindow / workbench macOS arm64 修复夹具前只有 pluginservice 那一项超时(main 上同样失败);修复后 pluginservice 整包 -race 通过,其余包通过,没有 DATA RACE
.agents/skills/write-stable-tests/scripts/test-stability-macos.sh --package ./internal/pluginservice -- --filter TestManagedToolchainFacts… macOS arm64 通过,1630 ms
.agents/skills/write-stable-tests/scripts/verify-test-stability.sh macOS 通过
gofmt -l / desktop-go.sh vet macOS 干净
视觉测试 TestVisualCommandInstall(vivahead lithevisual) macOS 无头 通过,截图见上
node scripts/i18n/generate-i18n.mjs --check、node scripts/i18n/verify-app-language-localization.mjs — 通过
./scripts/desktop/verify/verify-runtime-bundle-immutability.sh macOS 通过
./scripts/agent-notes/verify-agent-notes.sh — ok 190
verify-platform-feature-matrix.sh / verify-platform-feature-matrix-change.sh origin/main HEAD — 218 validated / passed
develop-lithe 第三节插件归属自查 — 结果为空
Go 插件 e2e(已发布的 1.3.1 包,--ref feat/command-installer-downloads) macOS arm64 9 项全部通过
下载真实 CodeLLDB v1.12.3 codelldb-darwin-arm64.vsix,用 zipinfo 检查 macOS SHA-256 与插件将要声明的值一致;extension/adapter/codelldb 为 0755,解压会保留可执行位

未能执行的检查和原因:

  • Windows:没有在本机虚拟机做真机验收。Windows 单元测试等 ready 后由完整 CI 运行;矩阵里 Windows 验证保持 pending。
  • macOS 原生窗口整机验收(装一个声明下载安装器的测试插件,点安装,再启动)还没做;矩阵里 macOS 验证保持 pending。

提交前确认 / Final checks

  • 分支从最新的 main 创建,期间合入过一次 origin/main(9cd03eb);目标分支 main
  • 以 Draft 提交,本地验证通过后才标记 ready
  • 没有无关改动(-race 夹具修复已单独说明),没有提交产物、凭据或个人路径
  • 本次测试没有启动 Lithe 应用;e2e 和视觉测试的子进程都已随测试结束,没有残留。本机正在运行的 /Applications/Lithe Desktop.app 是用户自己的,没有动

插件可以在 commandInstallers 里声明下载安装器(commandInstallers 1,
Lithe-core-rust#133):为每个平台固定压缩包地址、镜像和 SHA-256。
命令缺失时,用户在对话框里看到地址和校验值,确认后宿主下载、校验、
解压到插件的受管命令目录并记录,之后的 systemCommand 启动能找到命令。

- 下载、镜像选择、校验和安全解压复用 pluginruntime.Manager.Prepare,
  发布前检查命令是否在压缩包的命令目录里
- 下载失败、校验值不符、压缩包无效、命令不在压缩包里、超时分别报告,
  取消不写失败日志
- 记录新缓存键后删除同一安装器的旧版本目录
- 对话框显示下载地址、镜像、SHA-256 和下载进度
- 宿主声明 commandInstallers [0, 1],Core 固定到 f9af83e
-race 下压缩和解压约 250 MB 的测试二进制超过了 20 秒期限,main 上同样失败。
@ghfind-review ghfind-review Bot added the review: high ghfind author score; see https://ghfind.com label Nov 20, 2026
@xiaoyumuxi
xiaoyumuxi marked this pull request as ready for review November 20, 2026 14:34
@xiaoyumuxi
xiaoyumuxi merged commit 035f3c5 into main Nov 20, 2026
6 of 10 checks passed
@xiaoyumuxi xiaoyumuxi mentioned this pull request Nov 20, 2026
15 of 18 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

review: high ghfind author score; see https://ghfind.com

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant