Skip to content

docs(plugins): align plugin API doc with host runtime - #2021

Merged
vastsa merged 2 commits into
vastsa:mainfrom
zszz3:docs/plugin-api-audit
Oct 31, 2026
Merged

vastsa merged 2 commits into
vastsa:mainfrom
zszz3:docs/plugin-api-audit

Conversation

@zszz3

@zszz3 zszz3 commented Oct 31, 2026

Copy link
Copy Markdown
Contributor

Related to #2000

P1 第 2 项:03-plugin-api.md 对照 PluginHostApi。只改文档,中英文成对。

检查的文档

  • docs/spec/07-plugins/03-plugin-api.md
  • docs/zh-CN/spec/07-plugins/03-plugin-api.md

对照的代码

  • SDK:PluginHostApi(issue 里写的 PluginApi 实际名为 PluginHostApi)
  • 运行时分发与错误:apps/desktop/electron/main/plugin-runtime.ts、plugin-host-process.mjs、plugin-websocket.ts
  • 事件发送方:plugin-runtime.ts broadcastEvent、services/plugin-services.ts、bootstrap/app-lifecycle.ts、runtime/sidecar.ts、ipc/session-ipc.ts、index.ts
  • 类型:packages/shared/src/types/plugins.ts PluginWorkspaceInfo

方法

用 TypeScript 编译器 API 从 PluginHostApi 抽出全部 104 个方法,与英文文档中出现的 pi.<ns>.<method> 逐一比对:两边完全一致,没有文档缺失或多余的方法。随后逐个比对签名代码块,并核对 §4 错误模型、§5 事件列表。

发现与修改

# 文档原文 代码实际 修改
1 §4 PluginApiError.code 写成 9 个值的封闭 union 运行时 apiError(code: string, …) 接受任意字符串;返回插件前用 pluginCallErrorCode 原样转发,无 code 时为 PLUGIN_API_FAILED;实际还会抛 INVALID_PARAMS(如 session.import、usage)、UNAVAILABLE(browser)、PLUGIN_UNLOADED(L2260)、CONFLICT(speech)、PROVIDER_ERROR(L1403)、WORKSPACE_CHANGED(L5009)、OPEN_FAILED / REVEAL_FAILED(L5933、L6030)、CONNECT_FAILED(plugin-websocket.ts) union 末尾加 `
2 §3 pi.workspace.get() 签名缺 remote PluginWorkspaceInfo 有 remote?: { path: string; readOnly: true },同一节正文也在描述它 签名补字段
3 §5 “Delivered today” 未列 websocket 事件 宿主向 socket 所属插件发送 net:websocket:${type},类型见 plugin-websocket.ts;§3 net 一节有描述,§5 清单漏了 补一条并指向 §3

其余已核对、与代码一致:104 个方法名;除上面第 2 条外的签名;§5 中 bus.message、workspace:changed、plugin:settingsChanged、appearance:changed、session:modelChanged、session:turnEnded、session:activated 均有对应发送方;未在白名单的 API 抛 UNSUPPORTED,与 §8 一致。

发现但未在本 PR 处理

  • zh 版缺英文版开头的 “Theme variables” 节和 pi.projects.list() 签名块,属于 P0“中文缺失章节”,不在本 PR 范围。
  • SDK 的 workspace.get 类型 只有 path / name / remote,缺运行时实际返回的 projectId / roots(PluginWorkspaceInfo)。这是 SDK 类型问题,不在文档范围,会单独开 issue。

验证

  • git diff --check 通过
  • 未改标题和锚点;新加的 “§3 net” 引用指向现有章节
  • 分支基于 upstream/main c85251b

The error model presented its code list as a closed union, so plugin
authors could switch exhaustively on it, while the desktop host also
throws INVALID_PARAMS, UNAVAILABLE, PLUGIN_UNLOADED and other codes and
falls back to PLUGIN_API_FAILED. The workspace.get signature also
omitted the remote field the host returns for SSH projects, and the
event list left out the net.websocket frames.

Describe the open code set, add the remote field, and list the
websocket events in both the English and zh-CN documents.

Related to vastsa#2000

@vastsa vastsa left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

已独立对照 PluginWorkspaceInfo、pluginCallErrorCode、plugin-host-process 错误传递及 deliverSocketEvent。remote 字段、开放的错误码集合与 PLUGIN_API_FAILED 回退、四种定向 websocket 事件均与实现相符,中英文一致,未发现阻塞问题。

最新 main:9eb371e276eb36b06b4ff169013c70156e96dda1;已验证的 GitHub 合并候选:ad9151e5156d402a5a9b73af8062f948f742e03d。diff --check、base ancestry、86 组中英配对、599 个文档页面、agent-policy sync、VitePress 生产构建及 GitHub Docs checks / Head contains latest base 全部通过。仅文档改动,应用 E2E 不适用。

@vastsa
vastsa merged commit e93d50e into vastsa:main Oct 31, 2026
2 checks passed
@Tioit-Wang

Copy link
Copy Markdown
Collaborator

Merged. Thanks!

Paired English/Chinese changes, every claim anchored to a code location, and the SDK-type discrepancy split into #2022 rather than papered over — exactly the standard #2000 set. Noting that you left the large missing-Chinese blocks (theme variables, projects.list()) explicitly out of scope was useful: it let #2029 fill them without overlap.

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.

3 participants