Skip to content

feat(build): macOS 宿主启动构建 Provider 并发送 lithe/build/* 请求 (#1351) - #1356

Merged
xiaoyumuxi merged 2 commits into
previewfrom
feat/1351-macos-build-provider
Oct 20, 2026
Merged

xiaoyumuxi merged 2 commits into
previewfrom
feat/1351-macos-build-provider

Conversation

@xiaoyumuxi

Copy link
Copy Markdown
Collaborator

关联 #1351(PR 1:macOS 宿主启动构建 Provider 并发送 lithe/build/model / lithe/build/dependencies)。

改了什么

Rust Core

  • lsp/interface/build_provider.rs(新):initialize 时在 capabilities.experimental.litheBuild 下发送 {"versions": [1]},Provider 回 {"version": 1} 才算协商成功;版本 1 只接受 lithe/build/model、lithe/build/dependencies。
  • 新命令 lsp.buildRequest {sessionId, method, params, timeoutMilliseconds}(protocol/command.rs、runtime/dispatcher.rs、engine.rs):未协商的会话或不在版本内的方法直接失败,不写入进程;结果经 requestCompleted 返回。shared/contracts/rust-core-api.md 同步。

macOS

  • Provider 进程管理 Platform/MacOS/Build/MacBuildProviderSessions.swift(新,实现 BuildProviderRequesting):
    • 进程按「插件 ID + 构建系统 ID + 工作区」一一对应,插件之间永不共享;每个进程只通过自己的 stdio 与宿主说 JSON-RPC 2.0,宿主不在进程间转发。
    • 只在用户加载模型/依赖时启动;进程退出后下次请求重启;同一目标并发请求共用一次启动。
    • 可执行文件:包内文件直接启动;command / runtime 复用 MacBuildToolResolver(与构建命令同一套运行时、PATH、最低版本检查)。
    • 会话复用 LanguageServerRuntimeSession,登记进程账本,模块 ID 为该插件的构建系统扩展。
  • 启动计划 MacPluginLanguageServerLaunchResolver.resolveBuildProvider:按 buildSystemID 取 Core 启动计划,只用该插件自己的设置;可写状态放 <插件状态目录>/build-systems/<buildSystemID>,不写 app bundle / 插件包。
  • 共享写法隔离:LanguageToolingSessionManager.requestBuildProvider 发送前核对语言运行时的来源插件 ID,只允许复用同一插件的语言服务器会话。
  • 会话层:LanguageServerSession.buildRequest(就绪检查、取消时 cancelLanguageServerOperation);RustCoreBridge.lspBuildRequest / RustLanguageServerRuntimeAdapter.requestBuildProvider。
  • 契约 BuildSystemContracts.swift:BuildOutputPlan.provider(BuildProviderRequest)(带 params、optionFingerprint、两个标志)、BuildCommandOutput.providerResult、BuildProviderTarget、BuildProviderRequesting 端口、BuildSystemInstance.loadsModelOnRequest。
  • 编排 BuildSystemService:provider 计划发给 Provider,回复作为 result 交给 build.decodeModel / build.decodeDependencies;Build Output 显示 ▶ 标题 → method;reset(含退出应用)停止全部 Provider,pluginsChanged 停止已停用或已更新(包目录变化)插件的 Provider。
  • 工具窗口 BuildSystemToolWindowView:provider 来源与 command 一样显示「加载模型」/重新加载。
  • 组合 MacServiceContainer 构造 MacBuildProviderSessions 并注入;AppServices.connectBuildProviderLanguageSessions 让 AppModel 接上语言会话管理器(语言模块未激活时共享写法提示先打开该语言文件)。
  • 能力声明 PluginTypes.hostCapabilities 新增 buildProviders: [1],gradle-provider / mix-provider 现在可通过 macOS 安装审查。
  • RustDeclarativePluginOperations:启动计划解码 executable、buildProvider,新增 buildProviderLaunchPlan。

文档

  • 契约 README「Build providers」新增宿主隔离规则(每插件/构建系统/工作区一个进程、共享写法仅限同插件、启动与停止时机、可写位置)。
  • Agent Note 构建系统插件契约第 9、10、13 节、后果、备选方案(为什么不换更轻的协议或共用代理进程)和验证;提案 Note 同步已完成部分。
  • 功能矩阵 build-system-plugins 更新 macOS 描述和证据路径。

没有做(后续)

  • Windows 宿主的 Provider 接入。
  • lithe/build/execute(Provider 自己执行任务并流式汇报)。
  • 操作系统级沙盒:当前隔离到进程和通信通道层面,Provider 仍以用户权限运行。

验证

  • cargo test -p lithe-core --lib:1019 通过;verify-rust-core.sh、verify-rust-core-comments.sh、verify-rust-core-swift-bridge.sh 通过。
  • 新增 Swift 用例(BuildSystemServiceTests):providerModelSendsThePlannedRequestAndDecodesItsReply、providerDependenciesDecodeTheProvidersReply、workspaceSwitchAndDisabledPluginStopTheirProviders、providerModelFailsWithoutAProviderHost、failedProviderRequestReportsItsMessage;PluginMarketplaceServiceTests.buildProvidersAreAcceptedByTheMacOSHost 取代原先的“拒绝”用例。
  • 全量 macOS 测试 2387 项:除 PluginUIIconTests.renderedTemplateAndBrandIconsAdaptToThemesAndHostSize(图标像素颜色断言)和 RunEntryPointTests.runWithExistingConfigurationLaunchesOnlyAfterTheSnapshotArrives(超出本地耗时预算 1.5s)外全部通过;两者不在本 PR 改动范围,单独重跑仍复现,尚未在 preview 基线上对照。
  • verify-shared-contracts.sh、verify-service-boundaries.sh、verify-module-boundaries.sh、verify-runtime-bundle-immutability.sh、verify-test-stability.sh、verify-agent-notes.sh、verify-platform-feature-matrix.sh、verify-platform-feature-matrix-change.sh origin/preview HEAD 通过。
  • 未做:真实 Gradle/Mix Provider 的端到端手动验证(仓库目前没有可运行的 Provider 插件包)。

- Rust Core:initialize 在 capabilities.experimental.litheBuild 下协商
  Provider 协议版本;新增 lsp.buildRequest,只把协商版本内的
  lithe/build/model、lithe/build/dependencies 写给已协商的会话。
- macOS:MacBuildProviderSessions 按“插件 + 构建系统 + 工作区”各启动一个
  独立 Provider 进程(JSON-RPC over stdio),用户加载模型/依赖时才启动,
  切换工作区、停用或更新插件、退出应用时停止;状态写入插件构建系统状态目录。
- 共享写法只复用同一插件的语言服务器会话,跨插件时拒绝。
- BuildSystemService 把 provider 计划发给 Provider,回复作为 providerResult
  交给 Core 解码;工具窗口对 provider 来源显示“加载模型”。
- 宿主声明 buildProviders: [1],gradle-provider / mix-provider 可通过安装审查。
- 更新契约 README、rust-core-api、Agent Note、提案与功能矩阵,补充测试。
@ghfind-review ghfind-review Bot added the review: medium ghfind author score; see https://ghfind.com label Oct 20, 2026
@xiaoyumuxi
xiaoyumuxi marked this pull request as ready for review October 20, 2026 02:06
@lithe-code-review

lithe-code-review Bot commented Oct 20, 2026 •

Copy link
Copy Markdown

Lithe Review

结论: ❓ 审查未完成

审查失败:codex exited with code 1。可以重新评论 @lithe review 召唤。

@xiaoyumuxi xiaoyumuxi left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

整体设计方向合理:Rust Core 对 litheBuild 的协议版本和方法白名单有明确校验;独立 Provider 的进程/工作区隔离、与共享语言服务器的来源插件检查也值得保留。

这次 review 有 1 项 P1 和 2 项 P2(详见行内评论),建议在合并前处理 Provider 的更新回收、设置变更和可执行入口校验。当前新增的 BuildSystemServiceTests 主要使用 FakeBuildProviders,建议补充真实 MacBuildProviderSessions 的生命周期测试:并发请求只启动一次、初始化失败后重试、插件更新/同版本重装/卸载、设置变更后重启进程、无效包内入口拒绝以及工作区切换时取消未完成的请求。

基于 PR head 370642b5 的源码静态审查;GitHub CI 已通过,但尚未做真实 Gradle/Mix Provider 的端到端验证。

处理 PR #1356 评审意见:

- [P1] 插件安装/同版本重装/回滚/卸载前,MacPluginManager 的
  beforePackageReplacement 钩子直接按插件 ID 停止该插件全部 Provider
  (MacBuildProviderSessions.stopProviders(ofPlugin:)),不再依赖
  BuildSystemService 启动时的插件快照比较。
- [P2] 每个 Provider 进程记录启动时展开的插件设置值;下一次请求发现
  设置不同(如 providerHeapMB)就停止旧进程并按新参数重启。
- [P2] 安装时对声明了 provider 的构建系统展开启动计划,要求包内路径
  存在、不越界、不经过符号链接,包内可执行文件和打包运行时为普通
  可执行文件,否则拒绝安装(buildProviderLaunchMissing);启动时
  resolveBuildProvider 同样检查 regular file + executable。
- DeclarativeBuildSystem 新增 declaresProvider(解码 provider 字段是否存在)。
- 新增 MacBuildProviderSessionsTests(真实会话表 + 脚本化 Core)和
  PluginPackageStoreTests 的 Provider 入口校验用例;同步契约 README 与 Agent Note。
@xiaoyumuxi
xiaoyumuxi merged commit 86e48ce into preview Oct 20, 2026
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant