Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
3396ae6
feat(i18n): declare managed runtime preparation messages
lithe-support[bot] Nov 18, 2026
ceb5653
feat(i18n): merge strict feature catalogs at build time
lithe-support[bot] Nov 18, 2026
301c9bd
fix(i18n): validate lookups against the merged contract
lithe-support[bot] Nov 18, 2026
02aec73
test(i18n): cover feature ownership and strict validation
lithe-support[bot] Nov 18, 2026
aa8b6d1
docs(i18n): describe feature catalog sources
lithe-support[bot] Nov 18, 2026
fac1b53
chore(i18n): generate managed runtime preparation copy
lithe-support[bot] Nov 18, 2026
46ca846
feat(plugins): add reviewed managed runtime support (1/7)
lithe-support[bot] Nov 18, 2026
4a8dad9
feat(plugins): add reviewed managed runtime support (2/7)
lithe-support[bot] Nov 18, 2026
18ebb87
feat(plugins): add reviewed managed runtime support (3/7)
lithe-support[bot] Nov 18, 2026
21f5466
feat(plugins): add reviewed managed runtime support (4/7)
lithe-support[bot] Nov 18, 2026
07c7c00
feat(plugins): add reviewed managed runtime support (5/7)
lithe-support[bot] Nov 18, 2026
e0afb29
feat(plugins): add reviewed managed runtime support (6/7)
lithe-support[bot] Nov 18, 2026
d00678c
feat(plugins): add reviewed managed runtime support (7/7)
lithe-support[bot] Nov 18, 2026
3d9e9b1
fix(plugins): bind only validated external runtime identities
lithe-support[bot] Nov 18, 2026
1b0cafe
fix(toolchains): exclude open workspace code from runtime probes
lithe-support[bot] Nov 18, 2026
d7f5d66
fix(plugins): preserve runtime and workspace lifecycle ownership
lithe-support[bot] Nov 18, 2026
a6ab6e5
fix(workbench): bind queued startup to its captured workspace
lithe-support[bot] Nov 18, 2026
2670237
fix(plugins): retain workspace identity for shared build launches
lithe-support[bot] Nov 18, 2026
3a1ddef
test(plugins): align host tests with managed runtimes and workspace i…
1lck Nov 18, 2026
38691ad
Merge remote-tracking branch 'origin/main' into lithe-support/managed…
1lck Nov 18, 2026
35c9286
build(core): pin the merged managed runtimes contract (Lithe-core-rus…
1lck Nov 18, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@

## 先说结论

带语言服务器(Language Server,通过 LSP 提供补全、诊断和跳转能力的进程)的插件,必须在构建阶段固定语言服务器的来源和校验值,下载并校验后放入插件包,插件包完成签名后再分发。运行时只从已安装插件中发现入口,不能把下载物、解压物或插件状态写入应用安装目录,也不能写入跨工作树共享的缓存。插件卸载、重装和回滚时,必须能连同自己的语言服务器一起清理或替换。
带语言服务器(Language Server,通过 LSP 提供补全、诊断和跳转能力的进程)的插件,默认在构建阶段固定语言服务器的来源和校验值,下载并校验后放入插件包,插件包完成签名后再分发。运行时不能把下载物、解压物或插件状态写入应用安装目录,也不能写入跨工作树共享的缓存。插件卸载、重装和回滚时,必须能按声明管理自己的语言服务器。

下文的包内入口和随版本替换规则适用于默认的 bundled 模式。显式声明 `requires.managedRuntimes: 0`
及对应安装权限的插件可以采用[受管插件运行时](2026-11-18-managed-plugin-runtimes.md):来源与校验值仍在插件清单中固定,
经审批后先检查已有安装,只为缺失项下载,并保存到该插件独立、跨版本的状态目录。
这个受控模式没有恢复宿主自行识别语言、选择版本或维护跨插件共享工具目录的旧路径。

语言服务器的声明位于插件的 `plugin.json` 的 `languageServers` 中;Lithe 负责插件包验证、启停、运行时发现、进程生命周期和现有 LSP 会话编排。插件包是声明式的,不含宿主加载的代码,见 [声明式语言插件](2026-10-12-declarative-language-plugins.md)。

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
# Agent 笔记:插件声明的运行时按依赖身份安装并跨插件版本复用

状态:已实现

## 先说结论

插件可以显式声明安装自己所需的运行时,用户批准该插件的程序与下载权限后,宿主先让插件检查已有安装,只下载缺失项。完成校验的依赖放在该插件的跨版本状态目录,因此普通插件升级不必重复下载大型运行时。Core 决定声明是否合法、当前平台选哪个归档以及回复是否完整;插件判断实际安装是否合用,宿主负责下载、文件安全和进程生命周期。默认随插件打包资源的方式仍然有效,不声明新能力的插件保留原有流程。

## 问题

把大型运行时随每个插件版本打包,更新少量插件代码也要重新传输依赖;完全依赖用户安装,又容易因工具缺失、版本或目录不兼容而启动失败。简单地在语言服务器启动时下载也有问题:包已显示安装成功,实际依赖却可能尚未可用;下载中断和插件更新重叠时,旧进程还可能读到正在覆盖的文件。

已有插件状态目录可以提供写入位置,但目录本身不回答依赖版本、平台、来源、校验值和兼容性问题。需要把这些内容纳入正式清单和审批,同时保持应用安装包只读,且不能把某种语言的下载规则搬回宿主。

## 决策

### 1. 新能力必须显式声明并进入程序审批

`managedRuntimes` 是版本为 0 的可选能力,同时要求 `runtimes.install` 权限。插件清单固定每个依赖的版本、平台归档、HTTPS 来源、SHA-256 和相对目录布局,并声明一个检查函数。这些内容进入既有程序审批摘要,插件改变下载来源或可执行文件布局时必须重新走审批。

检查函数由插件自带的后端运行;这个后端必须能够独立启动,不能先依赖尚待准备的工具。宿主在审批后、插件版本提交前运行检查,因此检查失败或下载失败不会替换已安装的可用版本。检查进程不加入正常插件函数转发,不获得工作区和其他宿主服务授权;宿主仍可直接调用它,并接收能力查询和日志。

### 2. Core、插件与宿主分别回答不同问题

Core 校验清单、按平台选择唯一归档、计算稳定缓存键,并校验检查结果覆盖全部依赖且没有未知或重复项。插件检查显式配置、宿主提供的候选目录和外部工具事实,决定哪些目录合用、哪些依赖缺失;无效的显式选择应报告错误,不能悄悄换成下载。宿主只执行通过 Core 校验的计划,不推断语言版本,也不维护特定工具的下载地址。

安装检查使用全局设置;启动前修复使用随后启动所用的有效设置快照,避免忽略项目覆盖。选中的运行时目录只读传给该次语言服务器启动;声明绑定的工具也只覆盖这一次启动,不写全局工具目录、项目配置或用户选择。

全局选择模式不抹除已打开项目的路径边界。工作区上下文按真实 Open、Close、CloseAll 生命周期登记根目录,跨窗口和标签页按引用计数维护;一次准备捕获同一份根快照,供原生探针执行前检查和 Core 工具路径分类使用。检查函数返回的工具目录仍以固定 Home 走 Core 校验,确认实际可执行文件是同一文件后,向后续启动传递已验证的规范路径与 Home,避免重新使用项目内可变的符号链接。这个过程只读,不写工具目录或信任授权。

上下文由界面在打开项目时同步建立。后台激活、语言服务启动和共享构建服务只消费捕获的 ContextRef,不代替已关闭项目重新 Open;关闭后即使重新打开同一路径,旧身份也不能借用新项目。准备结束及原生启动边界再次核对身份,失效时沿用取消与销毁流程。这使共享根引用严格对应仍打开的项目,迟到后台任务不会留下永久根记录。

正确做法:插件检查函数确认一个外部安装完整可用后返回该目录;若另一个声明依赖缺失,宿主只下载后者。
不要这样做:宿主通过插件名称猜测所需工具版本,或者发现项目工具不合适时直接修改项目默认工具。

### 3. 按依赖身份保留完整文件,不按插件版本覆盖

受管文件位于 `<plugin-root>/.state/<plugin-id>/runtimes/<cache-key>/`。缓存键包含选定依赖的版本、平台、下载内容身份和布局,不包含插件版本;同一依赖跨插件升级可直接复用。不同插件不共享这个目录,外部安装也不转为宿主拥有的文件。

下载归档经过 SHA-256 校验后保存。解压先写私有目录,核对路径、链接、数量和字节预算,再调用插件检查;检查通过且输入文件没有被改写,才原子发布完成记录。每次发布使用新的完整目录,不原地替换旧进程正在读取的文件。归档损坏时重新下载;展开文件损坏而归档仍有效时可离线重建。旧的完整目录保留到插件状态被删除,为仍运行的进程和旧插件版本提供稳定路径。

安装与升级完整核对缓存文件哈希;正常启动先核对文件清单和元数据,再由插件作有界兼容性检查。启动发现缺失或损坏时复用同一准备流程。缓存布局、限制与清理规则见 [CI 构建与资源归属](../../../../docs/ci-builds.md),它不是可以跨工作树复制的构建缓存。

### 4. 取消、禁用和卸载必须等待准备工作结束

宿主跟踪准备任务及其检查进程。取消后清理未发布文件;禁用、替换或卸载先阻止新任务,取消并等待已有任务和语言服务器退出,再进行后续操作。停止失败保留包和状态供重试,避免后台任务在删除后重新创建目录。外部安装不在删除范围内;禁用也不删除已下载完成的依赖。

应用包、插件包和受管完成目录都是只读输入。索引、日志和进程的可写配置仍使用各自状态目录;这沿用[运行时保持发布程序包不变](../bug-fix/2026-09-25-runtime-bundle-immutability-and-update-delta.md)的边界。默认打包资源的规则见 [LSP 插件构建与分发](2026-09-30-lsp-plugin-build-and-distribution.md)。

### 5. 准备进度使用共享词条和原有生成器

检查、下载、解压、验证、修复和取消都显示当前准备阶段;失败说明保留旧插件版本与已校验下载物,用户可以重试。宿主新增文案仍由共享 i18n 生成,具体插件的诊断由插件自己翻译。

这组声明和双语译文放在 `shared/i18n/features/plugin-managed-runtimes.json`。既有注册表已经超过提交接口的单次内容上限,而旧下载与权限文案的语义不适用于运行依赖,因此采用构建时的小文件输入,不重排大词库,也不换用含义不同的提示。原生成器合并后继续执行同一套声明、平台、别名、参数和完整翻译校验;片段不能重复或覆盖别处的词条。运行时只读取既有生成字典,没有额外加载路径。格式与操作见[共享翻译](../../../../shared/i18n/README.md)。

## 考虑过的备选方案

- 每个插件版本都内含完整运行时:适合需要完全离线分发的插件,也继续受支持,但会重复传输不变的大文件。
- 宿主按语言名称管理共享工具目录:目录少,但兼容规则、下载地址和清理责任会重新落回宿主,多个插件还可能互相影响版本。
- 只在第一次语言服务器启动时补装:接入简单,却无法在安装提交前发现问题,用户看到安装成功后仍要等待或排查失败。
- 插件更新时覆盖同一路径:节省旧目录空间,但无法保证旧进程继续读取完整文件,Windows 上运行中的可执行文件也可能无法替换。

## 后果

插件更新可以复用未变化的依赖,已具备合用外部安装的用户不必重复下载;缺失和损坏都经过相同的检查、校验与错误通道。新增语言的规则留在插件仓库,宿主和 Core 只新增一次通用能力。

代价是首次安装可能需要较大下载,插件必须提供独立可运行的检查后端并维护固定校验值。保留归档和旧的完整目录会占用更多磁盘;当前按整个插件状态清理,不在升级时猜测哪些旧进程已经不再使用目录。没有匹配平台归档、无法联网且没有合用缓存、或显式配置无效时,准备会明确失败,不提交半完成的插件版本。

## 验证

- `cd desktop && ../scripts/desktop/desktop-go.sh test -race ./internal/core/ ./internal/pluginruntime/ ./internal/pluginbackend/ ./internal/pluginservice/`:共享 Core 契约、外部复用、跨版本不重复下载、缓存损坏修复、失败保留旧目录、并发与取消、安全解压及准备进程隔离。
- `cd desktop && ../scripts/desktop/desktop-go.sh test -tags vivahead ./internal/workbench/ ./internal/settingswindow/`:安装前准备、进度与取消、启动等待以及关闭项目后的旧结果保护。macOS 与 Windows 原生窗口流程另行验收,功能矩阵不以无头测试替代实机结果。
- `./scripts/desktop/verify/verify-runtime-bundle-immutability.sh`
- `./scripts/platform-feature-matrix/verify-platform-feature-matrix.sh`
- `./scripts/agent-notes/verify-agent-notes.sh`

## 适用范围

- `desktop/internal/core/managed_runtimes.go`
- `desktop/internal/pluginruntime/`
- `desktop/internal/pluginservice/runtimes.go`
- `desktop/internal/pluginservice/runtime_lifecycle.go`
- `desktop/internal/pluginbackend/pluginbackend.go`
- `desktop/internal/settingswindow/plugin_install.go`
- `desktop/internal/workbench/runtime_preparation_test.go`
- `shared/i18n/features/plugin-managed-runtimes.json`
- `docs/ci-builds.md`
- `shared/platform-feature-matrix/features/plugin-managed-runtimes.json`
- `https://github.com/Lithe-IDEA/Lithe-core-rust/blob/main/shared/plugins/contract/v1/README.md`
101 changes: 101 additions & 0 deletions desktop/internal/core/managed_runtimes.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
package core

import (
"context"
"encoding/json"
)

// ManagedRuntimePlatform uses plugin contract platform tokens, independent of Go names.
type ManagedRuntimePlatform struct {
OS string `json:"os"`
Arch string `json:"arch"`
}

// ManagedRuntimeResolver is the packaged backend function that verifies a dependency set.
type ManagedRuntimeResolver struct {
Function string `json:"function"`
TimeoutMilliseconds int `json:"timeoutMilliseconds"`
}

// ManagedRuntimeDependency is Core's platform-selected, content-addressed download plan.
// Home is relative to the extracted root after StripPrefix; Executable is relative to Home.
type ManagedRuntimeDependency struct {
ID string `json:"id"`
Version string `json:"version"`
Tool string `json:"tool,omitempty"`
OS string `json:"os"`
Arch string `json:"arch"`
URL string `json:"url"`
SHA256 string `json:"sha256"`
Archive string `json:"archive"`
StripPrefix string `json:"stripPrefix"`
Home string `json:"home"`
Executable string `json:"executable"`
CacheKey string `json:"cacheKey"`
}

// ManagedRuntimePlan describes downloads and the plugin-owned compatibility check.
type ManagedRuntimePlan struct {
Resolve *ManagedRuntimeResolver `json:"resolve,omitempty"`
Dependencies []ManagedRuntimeDependency `json:"dependencies"`
}

// ManagedRuntimeInstallation is a validated read-only home, managed or external.
type ManagedRuntimeInstallation struct {
ID string `json:"id"`
Home string `json:"home"`
Version string `json:"version"`
}

// ManagedRuntimeResolution partitions every declared dependency into usable or missing.
type ManagedRuntimeResolution struct {
Runtimes []ManagedRuntimeInstallation `json:"runtimes"`
Missing []string `json:"missing"`
}

// PlanManagedRuntimes validates the manifest and chooses immutable artifacts for a platform.
func (c *Client) PlanManagedRuntimes(ctx context.Context, manifest json.RawMessage, platform ManagedRuntimePlatform) (ManagedRuntimePlan, error) {
const command = "plugins.managedRuntimes.plan"
var result struct {
Status string `json:"status"`
Error *MarketplaceRejection `json:"error"`
Plan *ManagedRuntimePlan `json:"plan"`
}
if err := c.Execute(ctx, command, struct {
Manifest json.RawMessage `json:"manifest"`
Platform ManagedRuntimePlatform `json:"platform"`
}{manifest, platform}, &result); err != nil {
return ManagedRuntimePlan{}, err
}
if result.Status == "rejected" && result.Error != nil {
return ManagedRuntimePlan{}, result.Error
}
if result.Status != "ok" || result.Plan == nil {
return ManagedRuntimePlan{}, newParseError(command, "runtime plan returned an invalid outcome", "")
}
return *result.Plan, nil
}

// DecodeManagedRuntimeResolution checks the plugin's answer before native paths are consumed.
func (c *Client) DecodeManagedRuntimeResolution(ctx context.Context, manifest json.RawMessage, platform ManagedRuntimePlatform, answer json.RawMessage) (ManagedRuntimeResolution, error) {
const command = "plugins.managedRuntimes.decodeResolution"
var result struct {
Status string `json:"status"`
Error *MarketplaceRejection `json:"error"`
Resolution *ManagedRuntimeResolution `json:"resolution"`
}
if err := c.Execute(ctx, command, struct {
Manifest json.RawMessage `json:"manifest"`
Platform ManagedRuntimePlatform `json:"platform"`
Result json.RawMessage `json:"result"`
}{manifest, platform, answer}, &result); err != nil {
return ManagedRuntimeResolution{}, err
}
if result.Status == "rejected" && result.Error != nil {
return ManagedRuntimeResolution{}, result.Error
}
if result.Status != "ok" || result.Resolution == nil {
return ManagedRuntimeResolution{}, newParseError(command, "runtime resolution returned an invalid outcome", "")
}
return *result.Resolution, nil
}
54 changes: 54 additions & 0 deletions desktop/internal/core/managed_runtimes_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package core

import (
"context"
"encoding/json"
"os"
"testing"
"time"

"github.com/1lck/Lithe-IDEA/desktop/internal/contractfixture"
)

func TestManagedRuntimesBridgeUsesSharedContract(t *testing.T) {
data, err := os.ReadFile(contractfixture.CoreFixture("plugins/managed-runtimes.json"))
if err != nil {
t.Fatal(err)
}
var fixture struct {
Manifest json.RawMessage `json:"manifest"`
Resolution json.RawMessage `json:"resolution"`
WindowsResolution json.RawMessage `json:"windowsResolution"`
}
if err := json.Unmarshal(data, &fixture); err != nil {
t.Fatal(err)
}
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
client := NewClient()
for _, os := range []string{"linux", "windows"} {
t.Run(os, func(t *testing.T) {
platform := ManagedRuntimePlatform{OS: os, Arch: "x86_64"}
plan, err := client.PlanManagedRuntimes(ctx, fixture.Manifest, platform)
if err != nil || plan.Resolve == nil || len(plan.Dependencies) != 2 {
t.Fatalf("plan=%+v error=%v", plan, err)
}
for _, dependency := range plan.Dependencies {
if dependency.OS != os || len(dependency.CacheKey) != 64 || dependency.SHA256 == "" {
t.Fatalf("incomplete native download plan: %+v", dependency)
}
}
answer := fixture.Resolution
if os == "windows" {
answer = fixture.WindowsResolution
}
resolution, err := client.DecodeManagedRuntimeResolution(ctx, fixture.Manifest, platform, answer)
if err != nil || len(resolution.Runtimes) != 1 || len(resolution.Missing) != 1 || resolution.Missing[0] != "server" {
t.Fatalf("resolution=%+v error=%v", resolution, err)
}
if _, err := client.DecodeManagedRuntimeResolution(ctx, fixture.Manifest, platform, json.RawMessage(`{"runtimes":[],"missing":[]}`)); err == nil {
t.Fatal("an incomplete answer crossed the native boundary")
}
})
}
}
3 changes: 3 additions & 0 deletions desktop/internal/core/plugin_session.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ type PluginBackendStart struct {
RootURI any `json:"rootUri"`
WorkingDirectory string `json:"workingDirectory"`
HostServices []string `json:"hostServices,omitempty"`
// FunctionRelayEnabled isolates preparation sessions from both incoming and
// outgoing cross-plugin calls. Omitted preserves ordinary backend behavior.
FunctionRelayEnabled *bool `json:"functionRelayEnabled,omitempty"`
// HostOptions are the options of the granted services, which Core reports to the
// backend through lithe/host/getCapabilities.
HostOptions *PluginHostOptions `json:"hostOptions,omitempty"`
Expand Down
Loading
Loading