Skip to content

feat(plugins): add sidebar plugin pages and view scope - #2650

Merged
Tioit-Wang merged 8 commits into
vastsa:mainfrom
zszz3:feat/plugin-view-scope
Dec 1, 2026
Merged

Tioit-Wang merged 8 commits into
vastsa:mainfrom
zszz3:feat/plugin-view-scope

Conversation

@zszz3

@zszz3 zszz3 commented Nov 29, 2026

Copy link
Copy Markdown
Contributor

概要

Closes #2472

按 #2472 里的方案,让插件可以在左栏加入口、在中心区域渲染页面;另外按群里的讨论加了视图作用域(global / project / session):在同一个项目里切换会话时,项目级的右栏视图不切换,也不刷新。

插件在 manifest 里这样声明:

"views": [
  { "id": "board", "title": "Board", "entry": "views/board.html", "placement": "sidebar" },
  { "id": "notes", "title": "Notes", "entry": "views/notes.html", "scope": "project" }
]
  • placement:"workPanel"(默认,行为和现在一样)或 "sidebar"。
  • scope:"global"(默认,行为和现在一样)、"project" 或 "session"。页面 URL 会带上 piViewScope / piProjectPath / piSessionId,插件能知道当前页面属于哪个项目或会话。
  • 两个字段都是可选的,现有插件不受影响;也不新增权限,仍然只需要 ui.view。

左栏页面

  • 入口排在系统入口之后,按视图声明的顺序排列;tooltip 显示「标题 · 插件名」;入口多了在自己的区域里滚动,不会挤占会话和项目列表。
  • 打开后在中心区域显示,工作面板收起;再点一次入口会回到原来的会话,草稿和右栏都还在,也不会新建会话。
  • 历史记录里会带上视图,前进/后退能回到插件页。插件被禁用或视图消失时会回到会话,这一页也会从历史里删掉。
  • 打开设置等浮层时,原生页面会先隐藏,关掉浮层再显示;页面加载失败时显示重试按钮。
  • 左栏视图不能接收对话文本选区,不接受 location,也不能用 revealView 打开;revealView 只处理工作面板视图,原有行为不变。

作用域

  • 项目级:每个项目一页。同一项目里切换会话时,右栏仍停在这个视图上,页面不会重新加载;切到别的项目时显示那个项目自己的页面。
  • 会话级:每个会话一页,删除会话时会释放它的页面。
  • 左栏页面也支持 scope: "project",会跟着当前项目切换。

提交拆分

按 issue 里的建议拆成 5 个提交:

  1. refactor(desktop):抽出 usePluginViewSurface,行为不变
  2. feat(plugin-sdk):placement / scope 字段,SDK 和 host-core 的校验,shared 类型,以及 workPanelViews / sidebarViews 两个分流函数
  3. feat(desktop):主进程按作用域区分页面,兼容 revealView,删除会话或移除项目时释放对应页面
  4. feat(desktop):插件页路由、左栏入口、失效处理、重试、i18n,以及同一项目内切换会话时保留项目级视图;示例插件和 E2E 也在这个提交里
  5. docs:ADR、spec、插件开发文档(中英文)、E2E 场景、changelog

ADR 文件名用的是 docs/adr/plugin-view-placement-and-scope.md:最近的 ADR 都不带编号,而且内容也包括作用域。它是对 ADR 0104 的扩展。

示例

下面的截图是基于这套能力写的示例插件 pi-context。它在单独的仓库里,不包含在这个 PR 中,包括两个视图:

  • 全局的左栏页面「上下文总览」
  • 会话级的右栏视图「上下文」

左栏页面:上下文总览

左栏「上下文总览」:placement: "sidebar",点击后在中心区域打开。

会话级右栏视图:上下文

右栏「上下文」:scope: "session",每个会话一页。

仓库里的 examples/plugins/view-scope 是最小示例,E2E 也用它。

测试

  • E2E:pnpm test:e2e:plugin-view-scope,启动真实的桌面应用,32 项检查全部通过:
    • 项目级视图:同一项目内切换会话时页面不重新加载(加载时间和已输入的内容都还在);别的项目使用自己的页面
    • 会话级视图:每个会话一页;删除会话后它的页面被释放,项目页保留
    • 左栏入口的顺序和 tooltip;左栏视图不出现在工作面板的启动器里
    • 打开插件页:在中心区域显示,工作面板收起;打开设置时页面隐藏,关闭设置后恢复
    • 再点一次入口回到原会话,草稿和右栏不变;前进/后退正常
    • 项目级左栏页面跟着当前项目切换
    • 快速切换后没有残留的页面;禁用插件后回到会话,前进/后退也打不开这一页
  • 单元测试和组件测试:
    • 路由:在真实的 interaction slice 上测入口点击、前进/后退和清理失效页面
    • 在隔离的 Electron 里跑真实的 PluginPage:加载失败后重试、浮层遮挡、视图消失
    • 主进程的作用域解析、revealView 兼容、view open 的约束
    • SDK、host-core 的校验和 shared 分流函数
  • typecheck、lint、architecture、docs:check、cargo fmt、host-core plugins 测试都通过;分支基于最新的 main。

需求关联

The work panel tab owned the whole native view lifecycle: opening and
re-opening the view on plugin changes, tracking its bounds, and driving
its visibility. Sidebar plugin pages (vastsa#2472) need the same lifecycle on
a different placeholder, so it moves into usePluginViewSurface and the
tab keeps only the placeholder and its empty state.

No behavior change: the hook runs the same effects with the same
dependencies.
Plugins can now say where a view lives and how many live instances it
has. `placement: "sidebar"` asks for a left sidebar entry that opens a
center page (vastsa#2472); `scope` picks one page for the app, per project, or
per conversation. Both are optional and default to today's behavior
(work panel, global), so existing manifests keep working unchanged.

The SDK and host-core validate the same rules, including that a sidebar
view cannot accept transcript selection, because a center page is never
a target of the selection menu. Shared carries placement and scope on
PluginViewMeta, and workPanelViews / sidebarViews split the list so
consumers do not filter placement inline.
The main process now addresses one page per declared scope: a project
view is keyed by its project path and a session view by its
conversation, and the page URL names that context so the plugin knows
which one it serves. Pages are released when their conversation is
deleted or their project removed. Global views keep the single page and
the URL they had before.

Sidebar pages stay out of the work panel contracts: revealView resolves
only work panel views, and opening a sidebar view with a location is
rejected, so plugins that use those calls today see no change.
Sidebar views get entries after the built-in destinations and open as
a center page route. History carries the view, so back and forward
return to it; a second click on the entry goes back to the
conversation as it was; and a page whose view goes away falls back to
the conversation and is dropped from history. Host overlays detach the
native page, and a page that fails to load offers a retry.

In the work panel, a project-scoped view stays on screen without
reloading when switching between conversations of the same project,
the case asked for alongside vastsa#2472. The view-scope example plugin and
an Electron E2E (pnpm test:e2e:plugin-view-scope) cover both paths.

closes vastsa#2472
Record the decision in an ADR that extends ADR 0104, and describe
placement, scope and the sidebar page route rules in the plugin API,
manifest and permission specs and in both plugin development guides,
so plugin authors and reviewers have one consistent description.

Add the two E2E scenarios with their coverage and the user-facing
changelog highlight.
Bring in the session context card and the collaboration sidebar so the
pull request merges cleanly. The only textual conflict was the import
list of the plugin UI IPC module, where both sides added a line.

The session-active channel now asserts the shell's top frame, so the
view scope IPC test uses the shared shell registrar like its neighbours.
Bring in the session context card polish, whose plugin view host now
prewarms built-in views and attaches a view only once it has loaded.

Scoped pages keep their own live-view key through the new entry path,
so a project or conversation page is still created, shown after load
and closed under its instance. Hiding still names the view rather than
the page, and now also drops a pending show of any page of that view.
Bring in queued worker completion reports so the pull request stays
current with main. It merges without conflicts; the only shared file is
the plugin API spec, where the two changes touch separate sections.
@Tioit-Wang
Tioit-Wang merged commit 7ca0643 into vastsa:main Dec 1, 2026
6 checks passed
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.

[Feature] 允许插件在左栏添加同级入口并渲染中心页

2 participants