Local-first AI coding agent desktop: Electron + Rust host core + pi Agent Harness + user-installable plugins
TypeScript ai-agentcoding-agentdesktop-appelectronglobali18nlocal-firstmcppipi-agentpi-desktoppluginsreactrusttypescript
fix(plugins): check file line registration when invoked
Linuxdazhaoa1b9212b98e8
diff --git a/apps/desktop/electron/main/file-line-reference.ts b/apps/desktop/electron/main/file-line-reference.tsindex ce6822360..547e98618 100644--- a/apps/desktop/electron/main/file-line-reference.ts+++ b/apps/desktop/electron/main/file-line-reference.ts@@ -16,17 +16,6 @@ export function canUseFileLineView(loaded: LoadedPlugin | undefined): loaded isloaded.permissions.has("fs.read") && loaded.permissions.has("ui.view");}-export async function isRegisteredFileLineView(- host: Pick<HostProcess, "call"> | null,- pluginId: string,- version: string,-): Promise<boolean> {- const registry = await host?.call<{- plugins: Array<{ id: string; enabled: boolean; version: string }>;- }>("plugins.list");- return registry?.plugins.some(item => item.id === pluginId && item.enabled && item.version === version) ?? false;-}-type FileLineBridge = {plugins: Pick<PluginRuntime, "getLoaded">;pluginViews: Pick<PluginViewHost, "isVisibleViewSender">;@@ -63,7 +52,15 @@ export async function addFileLinesFromView(}const host = bridge.getHost();- if (!await isRegisteredFileLineView(host, pluginId, target.loaded.manifest.version)) {+ if (!host) {+ throw Object.assign(new Error("HOST_UNAVAILABLE: The Host is unavailable. Try adding the selection again when it reconnects."), {+ code: "HOST_UNAVAILABLE",+ });+ }+ const registry = await host.call<{+ plugins: Array<{ id: string; enabled: boolean; version: string }>;+ }>("plugins.list", undefined, 5_000);+ if (!registry?.plugins.some(item => item.id === pluginId && item.enabled && item.version === target.loaded.manifest.version)) {throw new Error("The File Manager is not enabled in the Host registry.");}const current = currentTarget();diff --git a/apps/desktop/electron/main/ipc/plugin-ui-ipc.ts b/apps/desktop/electron/main/ipc/plugin-ui-ipc.tsindex fcc228b11..421ce740a 100644--- a/apps/desktop/electron/main/ipc/plugin-ui-ipc.ts+++ b/apps/desktop/electron/main/ipc/plugin-ui-ipc.ts@@ -18,12 +18,10 @@ import {type PluginComposerSuggestionRefusal,} from "@pi-desktop/plugin-sdk";import type { ComposerSuggestionAnswer } from "../services/composer-suggestion";-import { canUseFileLineView, FILE_LINES_VIEW_KEY, isRegisteredFileLineView } from "../file-line-reference";-import type { HostProcess } from "../host-process";+import { canUseFileLineView, FILE_LINES_VIEW_KEY } from "../file-line-reference";export type PluginUiIpcDependencies = {registrar: IpcRegistrar;- getHost: () => HostProcess | null;plugins: PluginRuntime;browserHost: BrowserHost;pluginViews: PluginViewHost;@@ -47,7 +45,6 @@ export type PluginUiIpcDependencies = {/** Register plugin panels, work-panel views, themes and services. */export function registerPluginUiIpc({registrar,- getHost,plugins,browserHost,pluginViews,@@ -322,23 +319,13 @@ export function registerPluginUiIpc({if (isBrowserView && sessionId) {browserHost.setChromeSession(sessionId, typeof payload.tabId === "string" ? payload.tabId : undefined, location);}- let composerFileLines = false;- if (pluginViewKey(pluginId, viewId) === FILE_LINES_VIEW_KEY && canUseFileLineView(loaded)) {- const host = getHost();- composerFileLines = await isRegisteredFileLineView(host, pluginId, loaded.manifest.version).catch(() => false);- if (plugins.getLoaded(pluginId) !== loaded || loaded.disposing ||- !loaded.permissions.has("ui.view") || !pluginActiveInProject(pluginId, currentWorkspacePath())) {- throw new Error("plugin is no longer active in this project");- }- composerFileLines = composerFileLines && getHost() === host && canUseFileLineView(loaded);- }pluginViews.open({pluginId,viewId,locale: getUpdaterLocale(),theme: getPluginPanelTheme(),htmlPath,- composerFileLines,+ composerFileLines: pluginViewKey(pluginId, viewId) === FILE_LINES_VIEW_KEY && canUseFileLineView(loaded),netDomains: loaded.manifest.net?.domains?.map((domain) => String(domain)),netAnyHost: loaded.permissions.has("net.anyHost"),// The browser view owns an address bar and its own history, so itsdiff --git a/apps/desktop/electron/main/ipc/register.ts b/apps/desktop/electron/main/ipc/register.tsindex ae57d68a4..46ac96974 100644--- a/apps/desktop/electron/main/ipc/register.ts+++ b/apps/desktop/electron/main/ipc/register.ts@@ -515,7 +515,6 @@ export function registerIpcHandlers(dependencies: RegisterIpcDependencies) {registerPluginUiIpc({registrar,- getHost,plugins,browserHost,pluginViews,diff --git a/apps/desktop/test/file-line-bridge.test.mjs b/apps/desktop/test/file-line-bridge.test.mjsindex e5196c9ca..3eb28b919 100644--- a/apps/desktop/test/file-line-bridge.test.mjs+++ b/apps/desktop/test/file-line-bridge.test.mjs@@ -25,21 +25,32 @@ test("an installed File Manager can add lines only to the session that authorizepluginSession.setActiveSession(session);const deliveries = [];const record = { id: pluginId, version: "0.9.0", enabled: true, source: "marketplace" };+ let registryFailure = false;const host = {- async call(method) {+ async call(method, params, timeoutMs) {assert.equal(method, "plugins.list");+ assert.equal(params, undefined);+ assert.equal(timeoutMs, 5_000);+ if (registryFailure) throw new Error("Host restarting");return { plugins: [record] };},};+ let activeHost = host;const bridge = {plugins: { getLoaded: (id) => id === pluginId ? loaded : undefined },pluginViews: { isVisibleViewSender: (id, key) => id === 123 && key === "pi.file-manager/manager" },pluginSession,pluginActiveInProject: (id, projectPath) => id === pluginId && projectPath === workspace,- getHost: () => host,+ getHost: () => activeHost,getWorkspacePath: () => workspace,publish: (delivery) => deliveries.push(delivery),};+ activeHost = null;+ await assert.rejects(addFileLinesFromView(pluginId, 123, payload, bridge), { code: "HOST_UNAVAILABLE" });+ activeHost = host;+ registryFailure = true;+ await assert.rejects(addFileLinesFromView(pluginId, 123, payload, bridge), /Host restarting/);+ registryFailure = false;assert.deepEqual(await addFileLinesFromView(pluginId, 123, payload, bridge), { ok: true });assert.deepEqual(deliveries, [{ sessionId: "selected", reference: payload }]);@@ -50,6 +61,9 @@ test("an installed File Manager can add lines only to the session that authorizerecord.enabled = false;await assert.rejects(addFileLinesFromView(pluginId, 123, payload, bridge), /not enabled in the Host registry/);record.enabled = true;+ record.version = "0.8.0";+ await assert.rejects(addFileLinesFromView(pluginId, 123, payload, bridge), /not enabled in the Host registry/);+ record.version = "0.9.0";const pending = addFileLinesFromView(pluginId, 123, payload, bridge);pluginSession.setActiveSession({ ...session, sessionId: "different" });diff --git a/apps/desktop/test/plugin-provider-catalog-ipc.test.mjs b/apps/desktop/test/plugin-provider-catalog-ipc.test.mjsindex 61f65716f..11bb04522 100644--- a/apps/desktop/test/plugin-provider-catalog-ipc.test.mjs+++ b/apps/desktop/test/plugin-provider-catalog-ipc.test.mjs@@ -50,7 +50,7 @@ function loadPluginUiIpc({ gateFactory = () => () => ({ ignored: false }) } = {}return module.exports.registerPluginUiIpc;}-test("only the enabled, registered File Manager with both grants advertises Composer line references", async () => {+test("File Manager view capabilities survive Host unavailability without a registry query on open", async () => {const handlers = new Map();const views = [];const loaded = {@@ -60,8 +60,8 @@ test("only the enabled, registered File Manager with both grants advertises Comppath: "/plugins/file-manager",manifest: { version: "0.9.0", contributes: { views: [{ id: "manager", entry: "index.html" }] } },};- const record = { id: "pi.file-manager", enabled: true, version: "0.9.0" };- const host = { call: async () => ({ plugins: [record] }) };+ let hostQueries = 0;+ const host = { call: async () => { hostQueries++; throw new Error("Host restarting"); } };loadPluginUiIpc()({registrar: { handle: (channel, handler) => handlers.set(channel, handler) },plugins: { getLoaded: () => loaded },@@ -81,14 +81,10 @@ test("only the enabled, registered File Manager with both grants advertises Comploaded.development = true;assert.equal(await open(), false);loaded.development = false;- record.enabled = false;- assert.equal(await open(), false);- record.enabled = true;- record.version = "0.8.0";- assert.equal(await open(), false);- record.version = "0.9.0";+ assert.equal(await open(), true);loaded.permissions.delete("fs.read");assert.equal(await open(), false);+ assert.equal(hostQueries, 0);});test("the plugin Add Service IPC returns declared categories through the Host handler", async () => {diff --git a/docs/adr/file-manager-line-references.md b/docs/adr/file-manager-line-references.mdindex 0baedfd89..f42f9567c 100644--- a/docs/adr/file-manager-line-references.md+++ b/docs/adr/file-manager-line-references.md@@ -18,6 +18,11 @@ project, and the selected session. The registered File Manager can be bundledor installed. Both paths create the same draft reference. Composer eventsconfer no file permission.+The view capability advertises bridge support from the loaded instance and+its grants. Registration is authorized on invocation, with a bounded Host+query, so a Host restart cannot delay opening the view or freeze a transient+registry failure into its preload capability.+The selected text is never used as the model payload for a reference. Mainvalidates the reference path against the Session project folders. At promptexecution, the Agent runtime invokes the existing Read tool with the inclusivediff --git a/docs/spec/06-delivery/04-e2e-test-plan.md b/docs/spec/06-delivery/04-e2e-test-plan.mdindex b7ecf416e..e0f35fcca 100644--- a/docs/spec/06-delivery/04-e2e-test-plan.md+++ b/docs/spec/06-delivery/04-e2e-test-plan.md@@ -20116,6 +20116,11 @@ excluded. A one-line selection displays one line number.Open the same view from a development-loaded File Manager and verify thatthe host does not advertise `composerFileLines`.+With the Host unavailable, open an eligible installed File Manager view.+Verify opening completes immediately and `composerFileLines` remains true.+**Add to chat** reports Host unavailability. Reconnect the Host and retry+from the same view. The selection is added after registration is checked.+Insert an unsaved line before the range. Copying still pastes the originaltext and the selection menu has no **Add to chat** action. Save the file andverify that both actions use the new saved line numbers.diff --git a/docs/spec/07-plugins/12-plugin-ipc-and-host-services.md b/docs/spec/07-plugins/12-plugin-ipc-and-host-services.mdindex 895593b89..61689b2e5 100644--- a/docs/spec/07-plugins/12-plugin-ipc-and-host-services.md+++ b/docs/spec/07-plugins/12-plugin-ipc-and-host-services.md@@ -145,9 +145,13 @@ Panel bridge fixed channels also include `app.setTheme`, `themes.upsert`,no file or session access.The docked File Manager (`pi.file-manager/manager`) receives-`pluginBridge.capabilities.composerFileLines` when its loaded version matches-an enabled Host registry entry and holds both `ui.view` and `fs.read`.-Development-loaded views do not advertise the capability. An eligible view can invoke+`pluginBridge.capabilities.composerFileLines` when its loaded instance holds+both `ui.view` and `fs.read` and is not development-loaded or disposing.+This flag describes bridge support. Opening a view requires no Host registry+query. Each invocation checks the enabled registry entry and loaded version+with a five-second RPC timeout. An unavailable Host returns `HOST_UNAVAILABLE`;+a later invocation can retry after reconnection in the same view.+An eligible view can invoke`composer.addFileLines` with `{ workspace, path, start, end }`, where paths areabsolute and lines are one-based and inclusive. The host requires the visibleview of an enabled, registered File Manager with `ui.view` and `fs.read`, a