Repository navigation
fix(scope): apply activation scope to desktop.control session reads - #2390
Conversation
Setting a plugin's activation scope to specific projects only filtered
its UI surface. `desktop.invoke("session/list")` still returned every
project's sessions, and targeted session reads (`session/get`,
`session/listMessages`, `session/listRevisions`) reached sessions in
projects the scope excludes — the same class of gap vastsa#1754 fixed on the
`session:activated` event channel (vastsa#2377).
- desktop.invoke now holds the scope line on session reads:
`session/list` results are filtered to sessions whose projectPath the
caller's activation scope covers, and targeted reads are refused with
PERMISSION_DENIED when the target session's project is out of scope
(pre-checked against the live session-project map when available).
- The runtime gains an optional `pluginActiveInProject` service wired
from the same scope records the view IPCs use, so background services
making the same desktop.control calls through their plugin process are
gated identically.
- Spec 13 documents session reads as scope-filtered, matching
07-plugins/01 D192 (scope applies to every extension).
vastsa
left a comment
There was a problem hiding this comment.
原有 8 个 desktop-control 测试均通过;追加真实 PluginRuntime → 插件子进程冷会话用例后,8/9 通过,新增用例失败。
阻碍合入:生产 getWorkspacePathForSession 是 sessionProjects.get(sessionId) ?? null,该表由 runtime launch 填充。应用重启后尚未启动 runtime 的持久化会话,即使属于允许项目也返回 null;isActiveInProject 对指定项目 scope + null 返回 false。session/list 可以列出允许项目的会话,紧接着 session/get 却返回 PERMISSION_DENIED。仅绕过 undefined 的分支无法覆盖生产返回值。
请从权威持久化 session/project 元数据解析冷会话项目,再做范围判断;未知时保持安全拒绝,不要简单放行 null。补充重启/未启动 runtime 的允许项目读取成功、其他项目拒绝,以及 list→get/listRevisions 回归。现有测试只提供热会话映射。本次未合入。
…esktop into fix/issue-2377-activation-scope
vastsa
left a comment
There was a problem hiding this comment.
已复核最新修订,前次复现的 cold durable session 在 scope 内却被拒绝的问题已修正:Main 接入持久化 session.get 元数据解析,不再依赖仅在 runtime 启动后填充的内存映射。未知/缺失项目继续按 null 交给现有 activation scope 判断,没有放宽项目权限。
本地在隔离 worktree 对当前 head 执行 desktop-control + session-access:17/17 通过(真实 PluginRuntime 和插件子进程,controller/Host 边界受控);额外直接执行生产 resolver 的 8 个缺失/非法元数据、Host 缺失/异常及读取期间 Host 切换拒绝用例,全部通过。当前 origin/main 27ec1a4 为 head 祖先,GitHub 实际 merge ref tree 与测试 head 一致(1a5cef746b710444a49fc3564899660f1b4bf5f7),diff check 通过。六项当前 CI 均 SUCCESS,包含 typecheck/build/architecture/test、Rust 与 Windows Host E2E、可信扩展 Electron E2E。没有声称本地全应用 bootstrap 或真实 Host 冷会话端到端测试;本地覆盖的是插件进程链与生产解析器边界,远端集成套件提供邻接覆盖。
修复范围聚焦会话读取 scope 与持久化项目解析,可以合入。
根因 (Root cause)
插件的 activation scope 只在用户可见的 UI 表面(命令/视图/agent 工具/
session:activated事件 #1754)被强制执行。desktop.control的会话读取完全绕过它:desktop.invoke("session/list")返回全部项目的会话,session/get/session/listMessages/session/listRevisions可读取任意项目的会话;后台服务经插件进程走同一条desktop.invoke通道,同样不受限(#2377,与 #1754 同类缺口)。修复 (Fix)
plugin-runtime.ts的desktop.invoke现在对会话读取强制执行 scope:session/list:结果按会话projectPath过滤,只返回调用插件 activation scope 覆盖的项目内会话(有过滤时审计scope: "filtered");session/get等):目标会话项目超出 scope 时直接PERMISSION_DENIED,请求不再到达控制器(优先用运行中的 session→project 映射预检,避免先读后拒);pluginActiveInProject服务,来自 Main 中与视图 IPC 相同的 scope 记录(plugin-services.ts接线),因此后台服务发起的同通道调用被一致约束。desktop.control行补充"session reads 按 activation scope 过滤",与 07-plugins/01 D192(scope 适用于每个扩展)对齐。说明:后台服务的常驻运行本身(计时器触发)仍随插件进程全局存在;本 PR 收紧的是其可触达的会话数据读取面。若需要按 scope 完全停启服务,需要引入项目级服务生命周期,建议另行评审。
验证 (Verification)
plugin-desktop-control.test.mjs新增 3 个用例(全过):scoped 插件session/list被过滤、scoped 插件定向读取越界会话被拒(且不触达控制器)、未设 scope 的插件行为不变。apps/desktop全量 typecheck 通过。Fixes #2377