Repository navigation
feat(plugins): 会话事件、受控模型上下文和 Composer 多候选建议 - #2474
Merged
Merged
Conversation
…roups Expose durable user submissions without blocking the model, give plugins a bounded context contribution, and keep suggestion navigation and draft ownership in the native Composer. fixes #2470
Deploying pi-desktop with
|
| Latest commit: |
f9adbff
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://77713fa9.pi-desktop.pages.dev |
| Branch Preview URL: | https://feat-plugin-platform-2470.pi-desktop.pages.dev |
24 tasks
Move the shortcut and model-context checks into validation submodules, and give the new ADR the catalog H1 plus an index row.
The fixture loads agent-ipc through a closed import map, so the new provenance probe needs an explicit stub.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Goal
让插件在用户消息落盘时就动手,而不是等整轮回答结束;给普通插件一档「只追加有来源的参考文本」的权限,而不是只能申请替换整个请求;让原生 Composer 能展示一组后续建议,并由宿主守住按键、草稿和失效边界。
关联需求:#2470。
Current behaviour (before this change)
三处独立缺陷,均可在当前
main复现:session.appendMessage,再sidecar.call("agent.prompt"),但插件进程只收到session:turnEnded。首轮回答期间侧栏一直是占位标题;session:activated在回合登记时就发,此时消息还没写入,读了会得到空内容或上一轮内容。agent.extension,用受信任 Hook 的context替换整个请求消息列表;要么把内容拼进用户输入。没有「只追加一段标明来源、限长、按项目授权的文本」这一档。pi.composer.suggest只收一个text,连续调用互相覆盖;sessionId + turnId相同而用户切走又切回、或输入后又删空时,过期建议会重新出现。What changed
会话事件(插件进程)
session:turnStarted:正式回合登记后发出,含后台会话;文档与实现都明确它不代表用户消息已保存。session:userMessagePersisted:agent-ipc.ts取session.appendMessage的首次写入回执,写入成功后单独发出;通知异常只记日志,不影响后续模型请求。排队、失败、重试命中已存在行、导入回放、纯重新生成、宿主自发提示、运行中引导消息都不发。session.observe;plugin-services.ts按事件所属会话的项目过滤,只发给插件进程,不转给设置面板。载荷只有sessionId/turnId/messageId。plugin-runtime.ts的getCapabilities()仅在该插件实际持有session.observe时返回sessionUserMessagePersisted: true,未授权的插件据此回退到turnEnded,不会两边都触发。turnEnded的触发、载荷、授权、分发均未改动。模型上下文贡献
contributes.modelContext+agent.modelContext(清单校验要求二者同时出现),与受信任 Hook 分开:只接受{ text },不接触请求结构。runtime/plugin-model-context.ts每回合冻结一次贡献集合,发起请求前重新校验插件资格;撤权后该回合不再复用旧文本。agent-runtime/src/plugin-model-context.ts把文本以带source、trust="untrusted"的块追加到请求副本的最后一条用户消息上,并转义</>/&,会话记录与系统指令不变。Composer 候选组
composer-suggestion.ts新增目标探测与批量提交:目标是不透明 token,绑定插件、会话、回合和渲染层草稿修订;提交时再次校验归属、过期和当前修订。suggestion-bridge.ts维护整组候选与当前索引;ComposerInput.tsx在占位层显示位置与上下按钮。↑/↓ 循环、Tab 只填草稿、Esc 关闭整组;输入法组合、补全列表仍优先持有按键;单条候选不接管方向键。suggest({ text })路径保持可用。文档与 i18n
docs/spec/07-plugins/03-plugin-api.md、02-plugin-manifest-schema.md、13-plugin-permissions-matrix.md补充事件、贡献点、权限与示例。apps/desktop/src/features/plugins/model.ts标注风险等级。Design decisions
sessionId + turnId无法区分「切走再回来」和「输入后删空」Demo
候选切换的单文件原型(离线可开):
https://gist.github.com/Tioit-Wang/04095bd00a9abc8f9fb3dfcbbecf3734
Verification
node --test apps/desktop/test/composer-suggestion-state.test.mjs apps/desktop/test/composer-suggestion-relay.test.mjs apps/desktop/test/plugin-turn-observation-context.test.mjs apps/desktop/test/plugin-provider-catalog-ipc.test.mjs→ 35 pass(目标归属/过期、切换会话与附件失效、按钮与方向键、IME 与补全优先、可信渲染器回执、事件授权与项目范围、上下文冻结与撤权、超时取消)。ComposerInput与建议桥接:按钮切换、方向键环绕、输入法不抢键、Esc 关闭、Tab 只填不发 → 通过。tsc -p packages/plugin-sdk、packages/i18n、apps/desktop --noEmit→ 通过。cargo test -p host-core auto_title→ 3 pass;cargo test -p host-core model_context_contribution→ 1 pass;cargo fmt --check→ 通过。node scripts/check-pr-base-main.mjs→ 通过(head 含当前origin/main)。插件侧(独立仓库,不随本 PR 合入):
pi.official-enhancements提交9d8c04e8a9f061d7bde85acad5b829c231f107de。其测试覆盖即时标题、旧接口回退、纯路径命名、重复事件、关闭开关、无有效目标不花模型调用、批量去重;用本 PR 编译出的 DevKit 校验清单通过。Compatibility and risk
suggest({ text })与turnEnded不变。sessionUserMessagePersisted返回false,插件回退旧路径。80a1c02上全部通过(JS 构建/类型/测试、Docs、Rust 单测与 E2E、Trusted extensions Electron E2E、Cloudflare Pages、PR base)。Not covered
hooks.json兼容层。