Skip to content

feat(plugins): commandInstallers 让宿主安装 systemCommand 启动缺的命令 - #53

Merged
xiaoyumuxi merged 2 commits into
mainfrom
feat/command-installers
Nov 15, 2026
Merged

xiaoyumuxi merged 2 commits into
mainfrom
feat/command-installers

Conversation

@xiaoyumuxi

Copy link
Copy Markdown
Contributor

背景

Go 插件的 Delve 调试适配器和 gopls 语言服务器都是 systemCommand 启动,只写裸命令名 dlv、gopls。机器上没装时,插件管理的能力卡片只报 none of the plan's commands is available,用户得自己开终端跑 go install,还要保证 $(go env GOPATH)/bin 在 PATH 里。

这个 PR 给契约加上「安装缺失的命令」:插件声明怎样用它已经依赖的工具(requiresTools)安装这些命令,宿主在卡片上显示「未找到」和安装按钮,用户确认命令行、是否联网和安装位置后才运行。安装位置由用户选:装进 Lithe 管理的目录(managed),或者装到工具默认位置(toolDefault)。归入 API-23(工具链)。

改动

清单与校验(rust/crates/plugin-manifest/src/command_installers.rs,新文件)

  • 顶层 commandInstallers[](最多 16 个),字段 id、commands(1–8 个裸命令)、tool、minimumVersion?、字面量 arguments、mayUseNetwork(必填)、timeoutSeconds?(1–3600,默认 600)、targets。
  • targets.managed:arguments?(替换安装的参数)和 environment 可以用唯一的模板变量 ${installDirectory},而且两者加起来至少要用一次;commandDirectory? 是安装目录下命令所在的相对路径。
  • targets.toolDefault:值全是字面量;directory 最多 4 个探针,每个有非空 arguments,可选 pathList(取路径列表第一项)和 append(拼接相对路径)。
  • 校验规则:
    • 每个命令必须出现在本清单某个 systemCommand 启动里(语言服务器、构建提供者、VCS 提供者、调试适配器、后端)。
    • 一个命令只能归一个安装,安装 ID 不重复。
    • tool 必须在 requiresTools 里,否则返回 plugin.runtime.undeclared。
    • 环境变量名只能是大写字母、数字和 _。
    • 相对路径不能越出所在目录。
    • 每项长度和个数都有上限。
  • 能力 commandInstallers 0 写进 plugin-model/src/capabilities.rs,并接入 used_capabilities:用了要声明,没用不能声明。
  • 权限 commands.install:有安装就必须声明这个权限;没有安装时声明它会被拒绝。
  • 每个安装都是安装审查里的程序(kind: "commandInstaller"),改了要运行的内容需要重新批准。

宿主命令(core/src/protocol/command.rs、runtime/dispatcher/plugins.rs)

命令 输入 输出
plugins.commandInstallers.requirements { manifest } 每个 systemCommand 启动(kind、id)的命令以及提供它的安装(没有时为 null);所有安装的摘要
plugins.commandInstallers.plan { manifest, installerID, target, installDirectory? } 展开后的 tool、arguments、environment、timeoutMilliseconds、commandDirectory、directoryProbes
plugins.commandInstallers.defaultDirectory { manifest, installerID, outputs } 第一个输出绝对目录的探针决定的默认目录,没有时为 null
  • 路径按 Core 所在平台处理:managed 要求 installDirectory 是本平台的绝对路径,commandDirectory 用本平台的分隔符拼接;探针输出先去掉首尾空白,pathList 按本平台的路径列表分隔符切分。
  • 新的 Core 错误码一码一义:
    • plugin.commandInstaller.unknown
    • plugin.commandInstaller.targetUndeclared
    • plugin.commandInstaller.directoryInvalid
    • plugin.commandInstaller.probeOutputsInvalid
  • 契约里同时写明了将由宿主报告的四个错误码:
    • plugin.command.missing
    • plugin.commandInstaller.failed
    • plugin.commandInstaller.timedOut
    • plugin.commandInstaller.commandsMissing
  • 请求格式不对(例如 target 不是两个目标之一、缺 outputs)时,命令直接失败,不返回拒绝。

平台与重构

  • lithe-platform 的 paths.rs 新增三个函数,判断 Windows 绝对路径时不把 C:、C:go 和 \go 算作绝对路径:
    • path_list_separator
    • is_absolute_path:只看文本判断是否绝对路径,Windows 认盘符加分隔符和 UNC 路径。
    • join_native
  • 原来 build 和 project-generators 各有一份 is_environment_name,现在收到 plugin-model::names 一处。行为不变。

契约与文档

  • contract/v1/README.md:
    • 新增 ## Command installers 一节,包括示例(Go 安装 dlv)、字段表、两个目标、限额、宿主的五步流程和不覆盖的范围(invocation.executables)。
    • 同时补上 Manifest 字段、Capabilities、commands.install 权限和错误码表的对应行。
  • plugin-manifest.schema.json:
    • 新增 commandInstallers 属性和 requires.commandInstallers。
    • 权限枚举加 commands.install。
    • 新增条件:有 commandInstallers 时必须声明这个能力和权限。
    • 新增定义:$defs/commandInstaller、commandInstallerArguments、commandInstallerEnvironment、commandInstallerRelativePath。
  • fixture:
    • 新增 fixtures/command-installers/command-installer.plugin.json,含两个安装:sample-ls 两种目标都有、用环境变量传目录;sample-dap 只有 managed、替换参数并指定 bin。
    • 新增 command-installer-plans.json,共 16 个期望结果,与平台有关的用例分别给出 unix 和 windows 的结果。
    • invalid-manifests.json 增加 20 个拒绝用例。
  • rust/contracts/rust-core-api.md:命令表加三行,Declarative plugins 一节加一段说明。
  • reference/protocol-changelog.md:首次出现表加一行 commandInstallers 0,2026-11-15 时间线加一行。
  • reference/capabilities-and-versions.md:中英表格各加一行,桌面端标为「未声明」。
  • reference/api-catalog.md:API-23 中英两行补上 commandInstallers,并写明桌面端尚未声明。
  • reference/domains/toolchains.md:中英文各新增「安装缺失的命令」一节,并补上桌面端状态、契约章节和示例行。

模块注释引用的 Agent Note .agents/notes/implemented/architecture/2026-11-15-plugin-command-installers.md 写在 Lithe-IDEA 主仓库,随桌面端 PR 提交。这和其他 Core 模块引用 Note 的方式一致。

不新增 lithe/host/* 方法或宿主通知,所以 API 总表和更新记录里没有宿主方法行。

原计划编号 方法 用途
API-23 — 清单声明 commandInstallers;宿主命令 plugins.commandInstallers.requirements / plan / defaultDirectory,不是插件可调用的宿主方法

验证

命令 平台 结果
cargo test -p lithe-core -p lithe-plugin-manifest -p lithe-platform -p lithe-build -p lithe-project-generators -p lithe-plugin-model -p lithe-plugin-marketplace -p lithe-protocol macOS arm64 915 个通过,0 个失败
其中 lithe-plugin-manifest 的 command_installers 单元测试 macOS arm64 每个 golden 用例都按 Unix 和 Windows 两个平台各跑一遍
其中 lithe-core 的 declarative_plugins macOS arm64 新增 3 个测试:本机平台的 golden 用例、安装审查程序、请求严格解码;20 个拒绝用例通过
cargo clippy(同上 8 个 crate)--all-targets -- -D warnings macOS arm64 无警告
cargo fmt --all -- --check macOS arm64 通过
node shared/plugins/scripts/verify-docs.mjs macOS arm64 通过

没做的验证:

  • Windows 上的 lithe-core 测试(本机平台那一组)没有在 Windows 上跑,等 CI 跑。不过 Windows 路径规则已经在 lithe-plugin-manifest 里按两个平台测过。
  • 本机没有 JSON Schema 校验器,新增的 schema 是人工对照 Rust 校验规则写的。

合入后

  • 桌面端(Lithe-IDEA):
    • 把 PINNED_CORE_REVISION 升到合入提交,并声明 commandInstallers: [0]。
    • 能力卡片检测缺失命令,显示安装按钮和确认弹窗(选择 Lithe 目录或默认位置),运行时显示输出、可以取消、超时停止。
    • 启动时也查找受管目录和记录下来的默认目录。
  • Go 插件(Lithe-IDEA/lithe-plugin-go):为 dlv 和 gopls 声明 go install 安装。

插件清单新增顶层 commandInstallers[](能力 commandInstallers 0、权限
commands.install),声明怎样用插件已依赖的工具安装 systemCommand 启动用到的
裸命令,例如用 go install 装 dlv。目标有两个:managed 装进宿主为插件管理的
目录(唯一模板变量 ${installDirectory}),toolDefault 装到工具默认位置,并
用探针读出目录。

新增宿主命令 plugins.commandInstallers.requirements、plan、defaultDirectory,
Core 错误码 plugin.commandInstaller.unknown、targetUndeclared、
directoryInvalid、probeOutputsInvalid;安装声明进入安装审查。
lithe-platform 增加 path_list_separator、is_absolute_path、join_native;
is_environment_name 收到 plugin-model::names 一处。

契约 README、schema、fixture、rust-core-api.md、协议更新记录、能力版本、
API 总表和工具链领域页同步更新。
宿主每次执行用户确认的安装,用 diagnostics.recordPluginOperation 记一条
commandInstaller/install(命令执行生命周期):计划、找工具、启动、超时、
非零退出各有阶段,正常退出但命令不在目录里记 decode。用户取消不记录。

CONTRIBUTIONS 加一行,契约 README、rust-core-api.md、日志 README 的贡献表
和协议更新记录同步更新;不新增事件、通道或错误码。
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