Local-first AI coding agent desktop: Electron + Rust host core + pi Agent Harness + user-installable plugins
TypeScript ai-agentcoding-agentdesktop-appelectronglobali18nlocal-firstmcppipi-agentpi-desktoppluginsreactrusttypescript
docs(plugins): align plugin API doc with host runtime
zszz34403ca2173ac
diff --git a/docs/spec/07-plugins/03-plugin-api.md b/docs/spec/07-plugins/03-plugin-api.mdindex a304529cc..5d8a29245 100644--- a/docs/spec/07-plugins/03-plugin-api.md+++ b/docs/spec/07-plugins/03-plugin-api.md@@ -346,6 +346,7 @@ pi.workspace.get(): Promise<{name: string;projectId?: string;roots?: Array<{ path: string; name: string; primary: boolean }>;+ remote?: { path: string; readOnly: true }; // SSH projects only, see below} | null>pi.fs.readText(pathFromRoot: string): Promise<string>@@ -1368,11 +1369,22 @@ type PluginApiError = {| "RATE_LIMITED" // a rolling window is exhausted (e.g. bus publishes)| "CONFIRMATION_REQUIRED" // a dangerous desktop operation without confirm: true| "INTERNAL"+ | string // see belowmessage: string}```-All API failures throw an error carrying a `code`.+All API failures throw an error carrying a `code`. The list above is the common+set, not a closed enum: the host forwards whatever code the failing layer set,+and an error without one reaches the plugin as `PLUGIN_API_FAILED`. Other codes+the desktop host currently throws include `INVALID_PARAMS` (input validation of+the session, usage, project, and desktop APIs, alongside `INVALID_ARGUMENT`+elsewhere), `UNAVAILABLE` (a host service such as the browser is missing),+`PLUGIN_UNLOADED` (the plugin was unloaded or reloaded while the call ran),+`CONFLICT` (a speech protocol already in use), `PROVIDER_ERROR` (a speech+adapter returned empty output), `WORKSPACE_CHANGED`, `OPEN_FAILED`,+`REVEAL_FAILED`, and `CONNECT_FAILED`. Branch on the codes you handle and treat+the rest as a generic failure.## 5. Events (host -> plugin)@@ -1430,6 +1442,10 @@ Delivered today:`pi.session.getActive()` call. Needs no permission, and the selected session'sturn id is the same identity `session:turnEnded` reports.+- `net:websocket:open` / `net:websocket:message` / `net:websocket:close` /+ `net:websocket:error` — sent only to the plugin that owns the socket; see+ `net.websocket` under §3 `net`.+A throwing handler is logged and does not affect other listeners or the plugin.Planned events: none.diff --git a/docs/zh-CN/spec/07-plugins/03-plugin-api.md b/docs/zh-CN/spec/07-plugins/03-plugin-api.mdindex 200acd82a..e64ac8ca4 100644--- a/docs/zh-CN/spec/07-plugins/03-plugin-api.md+++ b/docs/zh-CN/spec/07-plugins/03-plugin-api.md@@ -292,6 +292,7 @@ pi.workspace.get(): Promise<{name: string;projectId?: string;roots?: Array<{ path: string; name: string; primary: boolean }>;+ remote?: { path: string; readOnly: true }; // 仅 SSH 项目,见下文} | null>pi.fs.readText(pathFromRoot: string): Promise<string>@@ -1078,11 +1079,18 @@ type PluginApiError = {| "RATE_LIMITED" // a rolling window is exhausted (e.g. bus publishes)| "CONFIRMATION_REQUIRED" // a dangerous desktop operation without confirm: true| "INTERNAL"+ | string // 见下文message: string}```-所有 API 失败都会引发携带 `code` 的错误。+所有 API 失败都会引发携带 `code` 的错误。上面列出的是常见取值,不是封闭枚举:宿主+会原样转发出错层设置的 code,没有 code 的错误到达插件时为 `PLUGIN_API_FAILED`。+桌面宿主目前还会抛出 `INVALID_PARAMS`(session、usage、project、desktop API 的+输入校验;其他 API 用 `INVALID_ARGUMENT`)、`UNAVAILABLE`(浏览器等宿主服务缺失)、+`PLUGIN_UNLOADED`(调用期间插件被卸载或重载)、`CONFLICT`(speech 协议已被占用)、+`PROVIDER_ERROR`(speech 适配器返回空结果)、`WORKSPACE_CHANGED`、`OPEN_FAILED`、+`REVEAL_FAILED` 和 `CONNECT_FAILED`。只对自己处理的 code 分支,其余按通用失败处理。## 5. 事件(主机 -> 插件)@@ -1125,6 +1133,10 @@ pi.events.off(event, handler)一次 `pi.session.getActive()` 补齐。不需要权限,且其中回合 id 与`session:turnEnded` 报告的身份一致。+- `net:websocket:open` / `net:websocket:message` / `net:websocket:close` /+ `net:websocket:error` —— 只发给持有该 socket 的插件;见 §3 `net` 下的+ `net.websocket`。+抛出的处理程序会被记录下来,并且不会影响其他侦听器或插件。计划活动:无。