Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 @@ -59,6 +59,7 @@
- **Core(`rust/crates/plugin-web-content/src/lib.rs`)**:`plugins.web.open` 为一个已声明的 web 窗口登记页面,返回私有源 URL 和限额;`resource` 判断一个请求路径能不能读、读包里的哪几段路径(拒绝 `..`、空段、编码分隔符和保留的 `.lithe-host/`);`document` 在 HTML 文档最前面注入 CSP meta 和桥接脚本;`request` 校验页面发来的每条消息,要么直接给出拒绝回复,要么交回一个已规范化的动作;`reply` 和 `event` 把结果、进度和主题变化封装成发给页面的消息。调用 ID 不可复用、同时最多 16 个调用、一次只开一个对话框,这些计数也都在 Core 里。
- **`desktop/internal/pluginweb`**:一个 `Page` 对应一个页面。它按 Core 给出的路径段逐级 `Lstat` 读取包文件,不跟随任何符号链接,并且限制大小;把 Core 交回的动作交给 `Host` 执行(状态读写、后端调用和进度、文件对话框、在编辑器里打开文件),再把 Core 封装好的回复投递给页面。等待、读写文件和弹对话框都在窗口线程之外进行。页面关闭时取消它的全部调用,之后的结果不再投递。
- **`desktop/internal/workbench`**:插件工具窗口加进每个窗口自己的 chrome 目录,由 Core 统一排列。停用插件期间,保存的布局仍保留它的位置,重新启用后回到原处。网页窗口用 `app.WebHost` 打开 Web 视图,并用 `NativeView` 填满窗口正文。一帧没有声明某个页面,这个页面就在 `endPaint` 里关闭。所以隐藏或移动窗口、关闭项目、停用或更新插件,都走同一条关闭路径。
- **覆盖层与错误传递(2026-11-24)**:原生网页属于窗口的正文层。工作台自己的补全、悬停说明和导航弹层通过 `ui.Overlay` 明确放进 `LayerPaneChrome`(Viva 的面板覆盖层),由框架同时计算原生视图遮罩和点击区域;框架菜单、对话框仍使用更高层。后端函数失败经过 `pluginservice` 与 `pluginweb` 时保留原有 `code`、`message`、`pluginErrorCode`,桌面适配器只转换数据,不重新分配业务错误码。
- **状态(`pluginservice.SetPageState`)**:写到每用户插件根目录下的 `.state/<plugin>/pages/workspaces/<工作区键>/<窗口摘要>.json`,与插件后端的工作区状态放在一起,按窗口和工作区隔离,写入时先写临时文件再改名。它不在插件包或应用 bundle 里,所以不改变签名或增量更新的基线;`plugin-web-state` 仍然禁止跨工作树复用。

Viva 的 Web 视图目前有四处达不到契约,已记录为上游缺口,补齐前按下面的方式处理:
Expand All @@ -68,7 +69,7 @@ Viva 的 Web 视图目前有四处达不到契约,已记录为上游缺口,
- 数据存储是持久的,与契约“网页存储不持久”不符;状态仍然只走桥接。
- 包资源回调在窗口线程上同步执行,所以读包文件要有大小上限,Core 判断要设本地期限。

另外,本宿主不向页面提供构建系统(`build.*` 返回 `plugin.web.unknownMethod`),也还不支持摄像头、麦克风和插件声明的窗口图标(暂用通用工具窗口图标)。
另外,本宿主不向页面提供构建系统(`build.*` 返回 `plugin.web.unknownMethod`),也还不支持摄像头和麦克风。2026-11-24 起工具窗口读取声明的包内 SVG 图标:后台重载时复用 `pluginicons` 的只读加载和内存缓存,工具栏、隐藏入口列表和拖动预览在绘制时选择主题变体。缺失、被拒绝或当前绘制器不支持的资源记录一次降级,继续显示通用图标;PNG 仍不在当前矢量图标绘制器的支持范围内。

### 启动进程前的确认

Expand Down Expand Up @@ -109,6 +110,8 @@ Viva 的 Web 视图目前有四处达不到契约,已记录为上游缺口,
- `./scripts/desktop/verify/verify-runtime-bundle-immutability.sh`:确认没有新增写入 bundle 的路径。
- `./scripts/agent-notes/verify-agent-notes.sh`:Note 格式与路径。

2026-11-24 的层级修复在用户停止验证前已运行定向回归:修复前悬停弹层与正文同为 0 层,修复后层级断言通过;`TestVisualPointerHover` 生成浅色、深色和中英文的悬停与导航截图。网页错误回归 `TestPagePreservesBackendFunctionFailure` 在修复前丢失 `pluginErrorCode`,修复后保留三个结构化字段。组件结果不代替原生 WebView 遮挡验收。用户随后要求自行验收,此后的图标接线、矩阵、Note 和提交收尾没有再运行验证,原生 macOS 与 Windows 状态仍为 pending。图标用例 `TestInstalledToolWindowKeepsPackageIconDeclaration` 与 `TestPluginToolWindowUsesPackageIconAcrossThemes` 已编写,尚未执行。

## 适用范围

- `https://github.com/Lithe-IDEA/Lithe-core-rust/blob/main/shared/plugins/contract/v1/`
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# Agent 笔记:插件网页浮层、失败传递与窗口图标

状态:已实现

## 先说结论

工作台的悬停说明、补全和导航必须显式声明在 Viva 的面板覆盖层,单靠把绘制调用放到正文之后无法盖住原生网页。后端函数失败经过网页适配器时,要保留 Core 已给出的错误码和插件业务错误码。工具窗口还必须读取已声明的包内图标,不能只识别内置图标名。这些修复都在宿主的通用呈现与数据转换边界,不依赖具体插件,也不新增协议。

## 问题

迁移到 Viva 的提交 `0faecba49`(#1799)在正文之后直接声明工作台浮层,但它们仍然属于正文的 0 层。原生 WebView 是系统视图,画布上同层的悬停面板可能被它遮住;菜单和对话框的声明顺序不能代替明确层级。

同一迁移中的网页回复只识别 `pluginweb.Failure`。后端函数返回的 `pluginservice.FunctionError` 及嵌入它的事件失败会进入兜底路径,被改写成 `plugin.web.invalidRequest`;页面失去 `pluginErrorCode`,只能显示笼统提示。

同一提交的工具窗口声明只解码 `icon.host`,包内图标路径被丢弃,因此合法的自定义图标仍显示通用工具窗口图标。宿主已有 `pluginicons` 负责包内 SVG 的只读加载,无需再做一份解码器。

## 决策

- 在 `workbench.root` 把工作台浮层放入 `ui.Overlay` 的 `LayerPaneChrome`,即 Viva 用于正文上方控件的覆盖层。框架据此同时处理原生视图遮罩、命中区域和绘制;框架菜单、对话框仍使用自己的更高层。
- `FunctionError` 提供结构化转换,`Page.answer` 通过接口获取原有 `code`、`message`、`pluginErrorCode`,再交给 Core 包装回复。桌面端不解释插件业务错误,不分配新码,也不另记一条相同失败日志。
- 工具窗口保留包内图标声明,在插件重载的后台工作中读入共享图标缓存。工具栏、隐藏入口列表和拖动预览按当前主题读取缓存,模板图标沿用控件着色,原色图标保留填充色。资源缺失或不受支持时复用现有 `plugin_icon` 降级日志,每个资源只记一次;不在绘制时读文件,不写磁盘缓存。
- 正确做法:新增悬停或导航内容继续使用工作台统一浮层入口;插件根据自己收到的业务错误选择本地提示。
- 不要这样做:给某个网页单独加窗口置底代码、用 CSS 层级操作窗口外的原生视图,或根据插件 ID 在宿主转换错误。

## 考虑过的备选方案

仅调整正文与浮层声明顺序不能改变原生视图的层级。修改 Viva 原生窗口排序会重复框架已有遮罩能力,也会影响其他原生视图,因此本次只修正调用方的覆盖层声明。

把后端错误文本拼进通用错误消息虽然能看到一部分原因,却仍然丢失机器可读的分类;让网页或宿主按文本匹配又会依赖翻译。保留契约现有字段即可,不需要新 API。

把某个品牌图标写入宿主会让插件失去独立维护能力;另建 SVG 绘制器又会重复现有包路径与资源预算保护。因此只接线既有声明和图标适配器,不扩大格式支持。

## 后果

宿主中的网页内容遵守与其他正文相同的浮层关系,插件无需配合;页面也能继续使用后端提供的受控业务提示。代价是无头画布只能证明层级声明与错误回复,不能证明系统 WebView 的真实遮挡、指针与焦点行为,仍需要目标平台验收。

## 验证

用户要求停止验证之前,定向回归已执行:`TestPointerHoverPaintsAboveTheNativeContentLayer` 在修复前报告悬停层 0 不高于正文层 0,修复后通过;`TestPagePreservesBackendFunctionFailure` 修复前丢失插件业务码,修复后通过。`TestVisualPointerHover` 采集了浅色、深色、中英文的悬停和导航画面,但无头环境没有原生网页引擎。

用户随后明确要求自行验收,此后的图标接线、文档、矩阵和提交收尾没有重新运行测试或检查。图标声明保留与明暗主题、模板着色用例已编写,尚未执行。macOS 原生 WebView 叠层与 Windows 验收均保持 pending。后续入口为 `scripts/desktop/desktop-go.sh test -race -count=1 ./internal/pluginweb -run TestPagePreservesBackendFunctionFailure`、工作台同名层级回归,以及 `./internal/pluginservice -run TestInstalledToolWindowKeepsPackageIconDeclaration`、`./internal/workbench -run TestPluginToolWindowUsesPackageIconAcrossThemes`;原生验收步骤见功能矩阵。

## 适用范围

- `desktop/internal/workbench/root.go`
- `desktop/internal/workbench/pluginsemantics_hover_test.go`
- `desktop/internal/workbench/pluginsemantics_hover_visual_test.go`
- `desktop/internal/pluginservice/backendhost.go`
- `desktop/internal/pluginservice/toolwindows.go`
- `desktop/internal/pluginservice/installed_snapshot_test.go`
- `desktop/internal/pluginweb/page.go`
- `desktop/internal/pluginweb/page_test.go`
- `desktop/internal/workbench/plugintools.go`
- `desktop/internal/workbench/plugintools_test.go`
- `desktop/internal/workbench/plugins.go`
- `desktop/internal/workbench/chrome_view.go`
- `desktop/internal/workbench/drag.go`
- [插件网页界面的边界](../architecture/2026-10-18-plugin-web-content-in-host-windows.md)
6 changes: 6 additions & 0 deletions desktop/internal/pluginservice/backendhost.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ type FunctionError struct {

func (e *FunctionError) Error() string { return e.Code + ": " + e.Message }

// PluginWebError preserves the structured failure when a backend call crosses
// the desktop page adapter. Embedded event failures inherit this conversion.
func (e *FunctionError) PluginWebError() core.PluginWebError {
return core.PluginWebError{Code: e.Code, Message: e.Message, PluginErrorCode: e.PluginCode}
}

// BackendHost keeps at most one backend process per plugin and starts it on
// demand: when a workspace opens for a plugin that asks for it, when its
// language server needs a launch answer, or when another plugin calls it.
Expand Down
16 changes: 16 additions & 0 deletions desktop/internal/pluginservice/installed_snapshot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"testing"

"github.com/1lck/Lithe-IDEA/desktop/internal/core"
"github.com/1lck/Lithe-IDEA/desktop/internal/pluginicons"
"github.com/1lck/Lithe-IDEA/desktop/internal/pluginmanager"
"github.com/1lck/Lithe-IDEA/desktop/internal/pluginpkg"
)
Expand Down Expand Up @@ -57,6 +58,21 @@ const snapshotManifest = `{
"outputLinkMatchers":[{"id":"snapshot-link","pattern":"snapshot"}]
}`

func TestInstalledToolWindowKeepsPackageIconDeclaration(t *testing.T) {
manifest := strings.Replace(snapshotManifest, `"title":"Before","text":"Snapshot"`,
`"title":"Before","text":"Snapshot","icon":{"path":"icons/light.svg","darkPath":"icons/dark.svg","mode":"original"}`, 1)
entry := snapshotEntry(t, "dev.lithe.test.snapshot", "1.0.0", manifest)
service := &Service{kernel: &fakeKernel{}}
windows, err := service.ToolWindows(context.Background(), []pluginmanager.Entry{entry})
want := pluginicons.Declaration{Path: "icons/light.svg", DarkPath: "icons/dark.svg", Mode: "original"}
if err != nil || len(windows) != 1 {
t.Fatalf("tool windows = %+v, %v", windows, err)
}
if windows[0].Icon != want || windows[0].IconHost != "" || windows[0].Package != entry.Installed.Path {
t.Fatalf("package icon declaration = %+v, want %+v in its installed package", windows[0], want)
}
}

func TestInstalledSnapshotKeepsOneManifestAcrossConsumers(t *testing.T) {
ctx := context.Background()
kernel := &snapshotKernel{fakeKernel: &fakeKernel{}}
Expand Down
13 changes: 10 additions & 3 deletions desktop/internal/pluginservice/toolwindows.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"fmt"
"sort"

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

Expand Down Expand Up @@ -34,9 +35,9 @@ type ToolWindow struct {
// View is the backend view function that draws the window's body for each view event
// (pluginview); empty for the other kinds.
View string
// IconHost is the declared host icon ID ("database", "git", ...), empty when the window
// declares none. Package resources are not read as icons.
// IconHost names a host icon; Icon instead names read-only package resources.
IconHost string
Icon pluginicons.Declaration
}

// ToolWindows reads the tool windows of every enabled plugin, ordered by
Expand Down Expand Up @@ -73,7 +74,10 @@ func (snapshot InstalledSnapshot) ToolWindows() ([]ToolWindow, error) {
Entry string `json:"entry"`
} `json:"web"`
Icon *struct {
Host string `json:"host"`
Host string `json:"host"`
Path string `json:"path"`
DarkPath string `json:"darkPath"`
Mode string `json:"mode"`
} `json:"icon"`
} `json:"toolWindows"`
} `json:"ui"`
Expand All @@ -97,6 +101,9 @@ func (snapshot InstalledSnapshot) ToolWindows() ([]ToolWindow, error) {
}
if window.Icon != nil {
declaredWindow.IconHost = window.Icon.Host
declaredWindow.Icon = pluginicons.Declaration{
Path: window.Icon.Path, DarkPath: window.Icon.DarkPath, Mode: window.Icon.Mode,
}
}
if window.View != nil {
declaredWindow.View = window.View.Function
Expand Down
7 changes: 6 additions & 1 deletion desktop/internal/pluginweb/page.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,12 @@ func (p *Page) answer(action core.PluginWebAction, call string, result any, fail
reply := core.PluginWebReply{Page: p.info.Page, ID: action.ID, Method: action.Method, Call: call}
if failure != nil {
var coded *Failure
if !errors.As(failure, &coded) {
var backend interface{ PluginWebError() core.PluginWebError }
switch {
case errors.As(failure, &coded):
case errors.As(failure, &backend):
coded = &Failure{backend.PluginWebError()}
default:
coded = Fail("plugin.web.invalidRequest", failure.Error())
}
reply.Error = &coded.PluginWebError
Expand Down
15 changes: 15 additions & 0 deletions desktop/internal/pluginweb/page_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (

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

// waitLimit bounds every wait for an answer the page is posted.
Expand Down Expand Up @@ -72,10 +73,24 @@ func (h *fakeHost) CallBackend(ctx context.Context, _, function string, params j
close(h.started)
<-ctx.Done()
return nil, ctx.Err()
case "failure":
return nil, &pluginservice.FunctionError{Code: "plugin.function.failed", Message: "Choose a resource first.", PluginCode: "fixture.resourceRequired"}
}
return nil, Fail("plugin.function.unknown", "no such function")
}

func TestPagePreservesBackendFunctionFailure(t *testing.T) {
f := openFixture(t)
reply := f.request(t, 1, "functions.invoke", map[string]any{"function": "failure"})
var failure core.PluginWebError
if err := json.Unmarshal(reply["error"], &failure); err != nil {
t.Fatal(err)
}
if failure.Code != "plugin.function.failed" || failure.Message != "Choose a resource first." || failure.PluginErrorCode != "fixture.resourceRequired" {
t.Fatalf("backend failure lost its structured fields: %+v", failure)
}
}

func (h *fakeHost) ChooseFile(string, FileRequest) (string, error) {
h.mu.Lock()
defer h.mu.Unlock()
Expand Down
8 changes: 4 additions & 4 deletions desktop/internal/workbench/chrome_view.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func (a *App) chromeGlyph(c ui.C, i int, layout glyphLayout, rest, hover gfx.Col
box := a.chromeBox(ui.Row(k).Size(layout.side, layout.side).Shrink(0).Center(), ui.ID(k), i, open, "", true).
TooltipOn(layout.tooltip)
box.Children(func() {
ui.Icon(c, *a.chrome.catalog[i].icon).Size(layout.icon, layout.icon).Color(rest).
ui.Icon(c, *a.chromeItemIcon(i)).Size(layout.icon, layout.icon).Color(rest).
StateFrom(box).Hover(ui.Look{}.Color(hover))
})
return box, box.Clicked()
Expand Down Expand Up @@ -412,7 +412,7 @@ func (a *App) hiddenToolWindowsButton(c ui.C, i int, z zone, layout glyphLayout)
button = button.Background(a.colors.Active).Hover(ui.Look{}.Background(a.colors.Active))
}
button.Children(func() {
ui.Icon(c, *a.chrome.catalog[i].icon).Size(layout.icon, layout.icon).Color(rest).
ui.Icon(c, *a.chromeItemIcon(i)).Size(layout.icon, layout.icon).Color(rest).
StateFrom(button).Hover(ui.Look{}.Color(hover))
})
clicked := button.Clicked()
Expand Down Expand Up @@ -493,8 +493,8 @@ func (a *App) hiddenToolWindowRow(c ui.C, i int) (ui.Box, bool) {
row = a.chromeHover(row)
}
row.Children(func() {
if it.icon != nil {
ui.Icon(c, *it.icon).Size(chromeIconSize, chromeIconSize).Shrink(0).Color(a.colors.Subtle)
if icon := a.chromeItemIcon(i); icon != nil {
ui.Icon(c, *icon).Size(chromeIconSize, chromeIconSize).Shrink(0).Color(a.colors.Subtle)
}
ui.Text(c, label).Grow(1).Color(a.colors.Text).LineHeight(chromeLineHeight).Ellipsis()
if it.panel {
Expand Down
6 changes: 3 additions & 3 deletions desktop/internal/workbench/drag.go
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ func (a *App) paintSnappedToolGhost(canvas *gfx.Canvas, d *dragState) {
gfx.Rect{Width: d.viewport.Width, Height: d.viewport.Height},
)
canvas.RoundedBorder(ghost, dragGhostRadius, dragGhostBorderWidth, a.colors.Accent, a.colors.Ground)
if icon := a.chrome.catalog[d.item].icon; icon != nil {
if icon := a.chromeItemIcon(d.item); icon != nil {
canvas.DrawIcon(*icon, ghost.Inset(gfx.All(dragSnappedGhostIconInset)), a.colors.Text)
}
}
Expand All @@ -366,7 +366,7 @@ func (a *App) paintDetachedToolGhost(canvas *gfx.Canvas, d *dragState) {
}
color = color.WithAlpha(dragFloatingGhostOpacity)
canvas.RoundedBorder(ghost, dragFloatingGhostRadius, dragFloatingGhostBorderWidth, color, color)
if icon := a.chrome.catalog[d.item].icon; icon != nil {
if icon := a.chromeItemIcon(d.item); icon != nil {
canvas.DrawIcon(*icon, ghost.Inset(gfx.All(dragFloatingGhostIconInset)), a.colors.Text.WithAlpha(dragFloatingGhostOpacity))
}
}
Expand Down Expand Up @@ -407,7 +407,7 @@ func (a *App) paintDetachedDropPreview(canvas *gfx.Canvas, target dragTarget) {
// because those bars do not detach into the workbench. A title bar button that may also sit
// on the stripes takes it while the pointer is over the title bar.
func (a *App) paintLegacyDragGhost(canvas *gfx.Canvas, d *dragState) {
icon := a.chrome.catalog[d.item].icon
icon := a.chromeItemIcon(d.item)
text := a.dragGhostText(d.item)
ghost := gfx.Rect{X: d.x + dragGhostOffset, Y: d.y + dragGhostOffset, Width: dragGhostSize, Height: dragGhostSize}
if text != "" {
Expand Down
11 changes: 11 additions & 0 deletions desktop/internal/workbench/plugins.go
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,17 @@ func (a *App) reloadPluginLanguages() {
return nil
}
windows, windowsErr := snapshot.ToolWindows()
for _, window := range windows {
if ctx.Err() != nil || a.pluginReloadGeneration.Load() != generation {
return nil
}
if window.Icon.Path == "" {
continue
}
if err := a.pluginIcons.Read(window.PluginID, window.Package, window.Icon); err != nil {
a.backgroundFailedIn(ctx, "plugin_icon", fmt.Errorf("%s: %w", window.PluginID, err))
}
}
commands, commandsErr := snapshot.ToolCommands()
vcsPlugins, vcsErr := snapshot.VcsPlugins()
a.pluginReloadMu.Lock()
Expand Down
Loading
Loading