Skip to content

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

fix(work-panel): keep tab menu above native views

vastsabe519a4c97ed
diff --git a/apps/desktop/src/components/workpanel/WorkPanel.tsx b/apps/desktop/src/components/workpanel/WorkPanel.tsx
index 8a3ca69fd..845acdd92 100644
--- a/apps/desktop/src/components/workpanel/WorkPanel.tsx
+++ b/apps/desktop/src/components/workpanel/WorkPanel.tsx
@@ -1089,7 +1089,7 @@ function LocalWorkPanel({
location={activeTab.location}
tabId={activeTab.id}
// Native WebContentsViews composite above renderer content.
- blocked={exiting || panelBlocked || blockingOverlayActive}
+ blocked={exiting || panelBlocked || blockingOverlayActive || tabContextMenu !== null}
/>
</div>
);
diff --git a/apps/desktop/test/plugin-work-panel-views.test.mjs b/apps/desktop/test/plugin-work-panel-views.test.mjs
index c7ed51eaa..5a733caa7 100644
--- a/apps/desktop/test/plugin-work-panel-views.test.mjs
+++ b/apps/desktop/test/plugin-work-panel-views.test.mjs
@@ -96,8 +96,11 @@ test("plugin views reach the panel body and the empty state", () => {
assert.doesNotMatch(panelSource, /openPluginView\(view\)/);
});
-test("the native surface keeps its full and current bounds while the launcher is active", () => {
- assert.match(panelSource, /blocked=\{\s*exiting \|\| panelBlocked \|\| blockingOverlayActive\s*\}/s);
+test("the native surface hides behind the work-panel menu and keeps its full bounds", () => {
+ assert.match(
+ panelSource,
+ /blocked=\{\s*exiting \|\| panelBlocked \|\| blockingOverlayActive \|\| tabContextMenu !== null\s*\}/s,
+ );
assert.doesNotMatch(panelSource, /avoid: pluginSurface/);
assert.doesNotMatch(panelSource, /menuOpen|work-panel-new-menu|placeWorkPanelMenu/);
assert.doesNotMatch(viewTabSource, /occludedById/);
diff --git a/apps/desktop/test/work-panel.test.mjs b/apps/desktop/test/work-panel.test.mjs
index 5d2d31036..8a9ab7f05 100644
--- a/apps/desktop/test/work-panel.test.mjs
+++ b/apps/desktop/test/work-panel.test.mjs
@@ -234,7 +234,7 @@ test("work panel uses the fixed-window internal dock", () => {
// guest clamped to the plugin view is gone before the dock CSS animation.
assert.match(
panelSource,
- /blocked=\{\s*exiting \|\| panelBlocked \|\| blockingOverlayActive\s*\}/,
+ /blocked=\{\s*exiting \|\| panelBlocked \|\| blockingOverlayActive \|\| tabContextMenu !== null\s*\}/s,
);
assert.match(panelSource, /nativeSurfaceReadyForExit/);
assert.match(panelSource, /is-exit-pending/);
@@ -312,7 +312,7 @@ test("work panel header exposes a scrollable tab strip and direct new-page actio
const pluginSurface = panelSource.slice(pluginSurfaceStart, pluginSurfaceEnd);
assert.match(
pluginSurface,
- /blocked=\{\s*exiting \|\| panelBlocked \|\| blockingOverlayActive\s*\}/s,
+ /blocked=\{\s*exiting \|\| panelBlocked \|\| blockingOverlayActive \|\| tabContextMenu !== null\s*\}/s,
);
assert.doesNotMatch(pluginSurface, /isResizing/);
assert.doesNotMatch(panelSource, /createPortal|newTabMenuRef|menuOpen/);
diff --git a/docs/spec/04-ux/08-component-spec.md b/docs/spec/04-ux/08-component-spec.md
index 188f8ebb9..6cc65c5c9 100644
--- a/docs/spec/04-ux/08-component-spec.md
+++ b/docs/spec/04-ux/08-component-spec.md
@@ -1242,7 +1242,7 @@ entirely inside the plugin's isolated page:
| Open with no resource | `Cmd/Ctrl + J` reveals the panel without creating a tab, so the body renders the New launcher. Clicking `+` creates an explicit, closable New tab with the same launcher rows. Activating a row from that tab replaces it with or selects the singleton view. Closing the final tab leaves the panel open in the no-resource state. |
| Constrained work area | The panel is capped by the shared three-column budget inside the existing client area; MainChat never drops below its 450px floor and the expanded sidebar yields at the threshold |
| New launcher active | The body hosts concise Review and plugin-view buttons. Each row replaces the launcher tab with its destination or activates the existing singleton; the page is independently closeable. |
-| Plugin view active | The body hosts the plugin's own isolated page as a native `WebContentsView`, positioned from the measured surface rect. It remains visible at its full rect while the divider is being resized or a New launcher tab is created; creating a page never pushes the plugin body down or changes its bounds. Embedded plugin documents start with zero root/body margin and border and a transparent background, so the host panel and plugin theme own the visible surface edge. It is hidden whenever the tab is inactive, the panel is animating, or a panel-wide blocking overlay is open — the same rule the Browser preview follows, since both composite above renderer content. A view whose plugin is disabled, uninstalled, reloaded, or crashed is destroyed; the tab stays and re-opens the page on the next lifecycle event (ADR 0104) |
+| Plugin view active | The body hosts the plugin's own isolated page as a native `WebContentsView`, positioned from the measured surface rect. It remains visible at its full rect while the divider is being resized or a New launcher tab is created; creating a page never pushes the plugin body down or changes its bounds. Embedded plugin documents start with zero root/body margin and border and a transparent background, so the host panel and plugin theme own the visible surface edge. It is hidden whenever the tab is inactive, the panel is animating, a panel-wide blocking overlay is open, or the tab context menu is open — the same rule the Browser preview follows, since both composite above renderer content. Closing the menu restores the view without changing its bounds. A view whose plugin is disabled, uninstalled, reloaded, or crashed is destroyed; the tab stays and re-opens the page on the next lifecycle event (ADR 0104) |
| Plugin out of scope | A view contributed by a plugin that is not active in the current project disappears from the New launcher when the project changes. Unlike contributed themes, which are one global setting and stay unfiltered, a view is scoped work |
### 5.4 Interactions
diff --git a/docs/spec/06-delivery/04-e2e-test-plan.md b/docs/spec/06-delivery/04-e2e-test-plan.md
index 0b6ed5423..d81b3c1a3 100644
--- a/docs/spec/06-delivery/04-e2e-test-plan.md
+++ b/docs/spec/06-delivery/04-e2e-test-plan.md
@@ -4789,20 +4789,17 @@ window; opening a normal panel afterward must still work.
and press Escape to leave the tabs unchanged. With only one or two tabs, drag
unused header space to move the native window; tab and action clicks must
still work without moving it.
- work without moving it. 4) Click `+` twice and verify each click
- creates and activates a separate New launcher tab. Confirm the launcher body
- contains Review plus each in-scope plugin view exactly once as clickable rows;
- there is no work-panel dropdown or popup. Click Browser from one New tab and
- confirm that tab opens the native plugin surface without changing its bounds.
- 5) Close
- active middle and edge tabs and verify neighbor selection. Close the final
- tab and confirm the panel remains open on the New launcher. 6) Use the
- viewport-fixed work-panel toggle and trigger another artifact. 7) In session A,
- leave the panel open with multiple
- tabs and a Browser resource; switch to session B, create a different tab set,
- then switch repeatedly between A and B and select a project without an active
- conversation. Generate a background artifact in the non-visible session.
- 7) Drag the inner left-edge handle left and right across its bounds; verify
+ 4) Click `+` twice and verify each creates and activates a separate New
+ launcher tab. Confirm its body lists Review and each in-scope plugin view
+ exactly once. Open Browser and confirm its native surface opens at unchanged
+ bounds. Open that tab's context menu and verify it appears above Browser
+ chrome while the native view is hidden; Escape closes the menu and restores
+ the view without changing bounds. 5) Close active middle and edge tabs,
+ verify neighbor selection, then close the final tab and confirm New remains.
+ 6) Collapse/reopen the panel and trigger another artifact. In session A, leave
+ Browser open; switch to B and create another tab set, then switch repeatedly
+ between sessions and select a project without a conversation. Generate a
+ background artifact in the non-visible session. 7) Drag the inner divider
pointer-down does not jump the divider or resize the native window, cancel one
gesture with Escape, then focus the handle and exercise Arrow/Shift+Arrow/Home/End.
Commit a different panel width with Browser active, double-click the divider and
@@ -4833,24 +4830,22 @@ window; opening a normal panel afterward must still work.
opacity/slide, so MainChat reflows continuously without a pre-animation jump.
Opening the panel, collapsing it, or committing a divider resize updates the
presentation without a native-window jump. The header is a horizontally
- Opening the panel, collapsing it, or committing a divider resize updates the
- presentation without a native-window jump. The header is a horizontally
scrollable tablist with stable `92px–180px` tabs, visible spacing, and a
fixed `+`; labels stay readable instead of shrinking into one cluster, the
strip alone scrolls, active tabs scroll into view, and close selects the
right neighbor then left. A localized, keyboard-navigable tab context menu
offers Close Tab, Close Other Tabs, and Close All Tabs. Close Other Tabs
retains and activates its target and is disabled for one tab; Close All Tabs
- closes Browser resources and leaves the panel open on New. New launcher tabs
- expose Review and in-scope plugin views as body buttons, with no popup to
- overlap or shift the panel. Dragging a tab shows a before/after insertion
- indicator, edge-holding scrolls the strip toward hidden tabs, and reorders
- only the tab array; the active resource stays active. `Alt+ArrowLeft`/
- `Alt+ArrowRight` provides the same reorder path from the focused tab. Clicking
- a launcher row replaces that New tab with the destination or activates its
- existing singleton.
- retains runtime tabs but hides the panel until another artifact reopens it.
- Width follows the shared three-column budget with no fixed pixel cap and
+ closes Browser resources and leaves the panel open on New. The Browser tab's
+ native view is hidden while its context menu is open, placing the menu above
+ Browser chrome; closing the menu restores the view without changing bounds.
+ New launcher tabs expose Review and plugin views as body buttons, with no
+ overlapping popup. Dragging a tab shows a before/after insertion indicator;
+ edge-holding scrolls toward hidden tabs, and reordering leaves the active
+ resource unchanged. `Alt+ArrowLeft`/`Alt+ArrowRight` provides keyboard
+ reordering. Selecting a launcher row replaces New or activates its singleton.
+ Collapse retains runtime tabs while hiding the panel. Width follows the shared
+ three-column budget without a fixed pixel cap and
previews its current/minimum/maximum values through the panel separator. The
inner divider exposes the panel width to assistive technology and supports
the documented keyboard steps. Pointer-down preserves the starting width,
@@ -4878,11 +4873,11 @@ window; opening a normal panel afterward must still work.
D357
- **Acceptance**: F (persistence), Quality
- **Milestone**: M5
-- **Status**: Unit-covered (`work-panel-resize.test.mjs`,
`work-panel-window.test.mjs`, `work-panel-presentation.test.mjs`,
`work-panel-tabs.test.mjs`, `browser-tab-restore.test.mjs`,
- `work-panel.test.mjs`); isolated Electron context-menu user path and close
- geometry in `scripts/e2e-work-panel-tab-close.mjs`; full UI scenario Draft
+ `work-panel.test.mjs`, `plugin-work-panel-views.test.mjs`); isolated Electron
+ tab-menu, Browser visibility, and close-geometry path in
+ `scripts/e2e-work-panel-tab-close.mjs`; full UI scenario Draft
#### E2E-057: Message-owned review history survives commits and rolls back safely
diff --git a/scripts/e2e-work-panel-tab-close.mjs b/scripts/e2e-work-panel-tab-close.mjs
index 9a2f390fd..b4c38e9c4 100644
--- a/scripts/e2e-work-panel-tab-close.mjs
+++ b/scripts/e2e-work-panel-tab-close.mjs
@@ -71,7 +71,7 @@ app.whenReady().then(async () => {
win.webContents.on("console-message", (event) => console.error(event.message));
try {
await win.loadFile(path.join(__dirname, "index.html"));
- for (const stage of ["narrow-active", "resize-same-tab", "hover-inactive", "context-menu-user-path"]) {
+ for (const stage of ["narrow-active", "resize-same-tab", "hover-inactive", "context-menu-user-path", "plugin-view-menu-layer"]) {
const result = await win.webContents.executeJavaScript(
"window.tabCloseProbe(" + JSON.stringify(stage) + ")");
console.log("TAB_CLOSE " + JSON.stringify(result));
@@ -99,7 +99,7 @@ app.whenReady().then(async () => {
.split("\n")
.filter((line) => line.startsWith("TAB_CLOSE "))
.map((line) => JSON.parse(line.slice("TAB_CLOSE ".length)));
- assert.equal(results.length, 4, "expected three geometry stages and one context-menu user path");
+ assert.equal(results.length, 5, "expected geometry, tab-menu, and plugin-layer stages");
for (const result of results) {
if (result.stage === "context-menu-user-path") {
@@ -109,6 +109,12 @@ app.whenReady().then(async () => {
console.log("context menu user path: PASS");
continue;
}
+ if (result.stage === "plugin-view-menu-layer") {
+ assert.equal(result.hiddenWhileMenuOpen, true, "native Browser view was not hidden behind the menu");
+ assert.equal(result.restoredAfterMenuClose, true, "native Browser view was not restored after closing the menu");
+ console.log("plugin view menu layer: PASS");
+ continue;
+ }
console.log(
`${result.stage}: strip [${result.stripLeft.toFixed(1)}, ${result.stripRight.toFixed(1)}] ` +
`clientWidth=${result.stripClientWidth} ` +
diff --git a/scripts/e2e/work-panel-tab-close.tsx b/scripts/e2e/work-panel-tab-close.tsx
index f47d07563..5a142599c 100644
--- a/scripts/e2e/work-panel-tab-close.tsx
+++ b/scripts/e2e/work-panel-tab-close.tsx
@@ -4,6 +4,8 @@ import { createInstance } from "i18next";
import { I18nextProvider } from "react-i18next";
import { catalogs } from "@pi-desktop/i18n";
import { WorkPanel } from "../../apps/desktop/src/components/workpanel/WorkPanel";
+import { IPC } from "@pi-desktop/shared";
+import { pluginWorkPanelTab } from "../../apps/desktop/src/lib/work-panel-tabs";
import { useAppStore } from "../../apps/desktop/src/stores/app-store";
/*
@@ -36,8 +38,14 @@ type TabContextMenuPathResult = {
remainingTabs: number;
activeTabId: string | null;
};
+
+type PluginViewMenuLayerResult = {
+ stage: "plugin-view-menu-layer";
+ hiddenWhileMenuOpen: boolean;
+ restoredAfterMenuClose: boolean;
+};
declare global {
- var tabCloseProbe: (stage: string) => Promise<CloseGeometry | TabContextMenuPathResult>;
+ var tabCloseProbe: (stage: string) => Promise<CloseGeometry | TabContextMenuPathResult | PluginViewMenuLayerResult>;
}
const assert = (condition: unknown, message: string) => {
@@ -54,6 +62,19 @@ const ready = i18n.init({
resources: { en: { translation: catalogs.en } },
interpolation: { escapeValue: false },
});
+const pluginViewVisibility: boolean[] = [];
+window.piDesktop = {
+ channels: IPC,
+ platform: "darwin",
+ invoke: async (channel, ...args) => {
+ if (channel === IPC.invoke.pluginViewSetVisible) {
+ const payload = args[0] as { visible?: boolean } | undefined;
+ if (typeof payload?.visible === "boolean") pluginViewVisibility.push(payload.visible);
+ }
+ return { ok: true, data: undefined };
+ },
+ on: () => () => undefined,
+};
function element(selector: string): HTMLElement {
const found = host.querySelector<HTMLElement>(selector);
@@ -241,12 +262,79 @@ async function runTabContextMenuUserPath(): Promise<TabContextMenuPathResult> {
};
}
+async function runPluginViewMenuLayerPath(): Promise<PluginViewMenuLayerResult> {
+ const tab = pluginWorkPanelTab("pi.browser", "browser");
+ pluginViewVisibility.length = 0;
+ host.style.width = "1000px";
+ flushSync(() => {
+ useAppStore.setState({
+ activeSessionId: "tab-close-plugin",
+ workPanelOpen: true,
+ workPanelTabs: [tab],
+ activeWorkPanelTabId: tab.id,
+ workPanelFileRequest: null,
+ workPanelContexts: {},
+ pluginViews: [{
+ pluginId: "pi.browser",
+ viewId: "browser",
+ ref: "pi.browser/browser",
+ title: "Browser",
+ pluginName: "PI-Desktop",
+ order: 0,
+ }],
+ });
+ root.render(
+ <I18nextProvider i18n={i18n}>
+ <WorkPanel containerWidth={1000} sidebarCollapsed />
+ </I18nextProvider>,
+ );
+ });
+ await rendered();
+ assert(pluginViewVisibility.at(-1) === true, "Browser view did not become visible");
+
+ const tabWrapper = host.querySelector<HTMLElement>(
+ `[data-work-panel-tab-id="${CSS.escape(tab.id)}"]`,
+ );
+ assert(tabWrapper, "Browser tab wrapper is missing");
+ const event = new MouseEvent("contextmenu", {
+ bubbles: true,
+ cancelable: true,
+ clientX: 32,
+ clientY: 32,
+ });
+ flushSync(() => tabWrapper!.dispatchEvent(event));
+ assert(event.defaultPrevented, "Browser tab menu did not open");
+ await rendered();
+ assert(document.body.querySelector('[role="menu"]'), "Browser tab menu is missing");
+ const hiddenWhileMenuOpen = pluginViewVisibility.at(-1) === false;
+ assert(hiddenWhileMenuOpen, "native Browser view remained above the tab menu");
+
+ window.dispatchEvent(new KeyboardEvent("keydown", {
+ key: "Escape",
+ bubbles: true,
+ cancelable: true,
+ }));
+ await rendered();
+ assert(!document.body.querySelector('[role="menu"]'), "Escape did not close the Browser tab menu");
+ const restoredAfterMenuClose = pluginViewVisibility.at(-1) === true;
+ assert(restoredAfterMenuClose, "native Browser view did not return after menu close");
+
+ return {
+ stage: "plugin-view-menu-layer",
+ hiddenWhileMenuOpen,
+ restoredAfterMenuClose,
+ };
+}
+
globalThis.tabCloseProbe = async (stage) => {
await ready;
if (stage === "context-menu-user-path") {
await ready;
return runTabContextMenuUserPath();
}
+ if (stage === "plugin-view-menu-layer") {
+ return runPluginViewMenuLayerPath();
+ }
if (stage === "narrow-active") {
renderPanel(900);