Skip to content

Local-first AI coding agent desktop: Electron + Rust host core + pi Agent Harness + user-installable plugins

fix(plugins): require the session scope check and update the wiring contracts

liuzixiangce8ffae8acaf
diff --git a/apps/desktop/electron/main/ipc/plugin-ui-ipc.ts b/apps/desktop/electron/main/ipc/plugin-ui-ipc.ts
index 7847075d8..1d4f2860f 100644
--- a/apps/desktop/electron/main/ipc/plugin-ui-ipc.ts
+++ b/apps/desktop/electron/main/ipc/plugin-ui-ipc.ts
@@ -51,7 +51,9 @@ export function registerPluginUiIpc({
let activeSessionSeq = 0;
/** The renderer load the high-water mark belongs to. A reload restarts the
* renderer's counter from one, so a changed boot id resets the mark and
- * pushes keep flowing afterwards (#1753). */
+ * pushes keep flowing afterwards (#1753). The boot id is per renderer
+ * load, so with two windows open the out-of-order guarantee is per window
+ * — only one window's session is on screen at a time. */
let activeSessionBootId: string | null = null;
/**
* The session on screen, as the shell sees it.
diff --git a/apps/desktop/electron/main/services/plugin-services.ts b/apps/desktop/electron/main/services/plugin-services.ts
index 5d1ffb6b3..a989584f2 100644
--- a/apps/desktop/electron/main/services/plugin-services.ts
+++ b/apps/desktop/electron/main/services/plugin-services.ts
@@ -90,7 +90,7 @@ export type PluginServicesDependencies = {
* fan-out can hold the same line `session.getActive` does for sessions
* that are not the window's own selection (#1754).
*/
- pluginActiveInProject?: (pluginId: string, projectPath: string | null | undefined) => boolean;
+ pluginActiveInProject: (pluginId: string, projectPath: string | null | undefined) => boolean;
};
/**
@@ -587,14 +587,13 @@ export function createPluginServices({
// ui.revealView) already enforces: a project-scoped plugin does not
// receive a session its scope excludes (#1754). Sessions without a
// project fall back to the workspace-relative check.
- const scopeFilter =
- SESSION_SCOPED_EVENTS.has(event) && pluginActiveInProject
- ? (pluginId: string) =>
- pluginActiveInProject(
- pluginId,
- (sessionId && sessionProjects.get(sessionId)) ?? null,
- )
- : undefined;
+ const scopeFilter = SESSION_SCOPED_EVENTS.has(event)
+ ? (pluginId: string) =>
+ pluginActiveInProject(
+ pluginId,
+ (sessionId && sessionProjects.get(sessionId)) ?? null,
+ )
+ : undefined;
try {
plugins.broadcastEvent(event, [payload], scopeFilter);
} catch (error) {
diff --git a/apps/desktop/test/main-wiring-contract.test.mjs b/apps/desktop/test/main-wiring-contract.test.mjs
index f29da9c74..32991d669 100644
--- a/apps/desktop/test/main-wiring-contract.test.mjs
+++ b/apps/desktop/test/main-wiring-contract.test.mjs
@@ -204,9 +204,9 @@ test("a finished turn is announced to every plugin surface", () => {
services,
services.indexOf("{", services.indexOf("const broadcastSessionEvent")),
);
- assert.match(fanOut, /plugins\.broadcastEvent\(event, \[payload\]\)/);
+ assert.match(fanOut, /plugins\.broadcastEvent\(event, \[payload\](?:, scopeFilter)?\)/);
assert.match(fanOut, /pluginPanels\.broadcast\(event, payload\)/);
- assert.match(fanOut, /pluginViews\.broadcast\(event, payload\)/);
+ assert.match(fanOut, /pluginViews\.broadcast\(event, payload(?:, scopeFilter)?\)/);
// Each surface owns its failure: one unreachable plugin process, panel or
// view must not suppress the other two.
assert.equal(
@@ -228,9 +228,9 @@ test("the selected session is announced to every plugin surface", () => {
// The snapshot is announced from the one module that owns it, and reaches the
// same three surfaces as a finished turn.
assert.match(context, /announce\("session:activated", next\)/);
- assert.match(services, /plugins\.broadcastEvent\(event, \[payload\]\)/);
+ assert.match(services, /plugins\.broadcastEvent\(event, \[payload\](?:, scopeFilter)?\)/);
assert.match(services, /pluginPanels\.broadcast\(event, payload\)/);
- assert.match(services, /pluginViews\.broadcast\(event, payload\)/);
+ assert.match(services, /pluginViews\.broadcast\(event, payload(?:, scopeFilter)?\)/);
// Turn identity and start time come from the host, never from the renderer.
assert.match(
services,