Skip to content

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

feat(work-panel): add tab context menu actions (#1904)

Lan5aa253883c4e
diff --git a/apps/desktop/src/components/ContextMenu.tsx b/apps/desktop/src/components/ContextMenu.tsx
index 525308405..fe69cef89 100644
--- a/apps/desktop/src/components/ContextMenu.tsx
+++ b/apps/desktop/src/components/ContextMenu.tsx
@@ -315,6 +315,8 @@ export function ContextMenu({
// Keyboard users land on the first item; Enter then runs it instead of
// re-opening the menu.
+ // This viewport-fixed portal dismisses on page scroll, so focusing it must
+ // not scroll the underlying work surface.
useEffect(() => {
if (!state || !placement) return;
const frame = requestAnimationFrame(() => {
@@ -322,7 +324,7 @@ export function ContextMenu({
?.querySelector<HTMLButtonElement>(
'[role="menuitem"]:not(:disabled)',
)
- ?.focus();
+ ?.focus({ preventScroll: true });
});
return () => cancelAnimationFrame(frame);
}, [placement, state]);
@@ -400,7 +402,7 @@ export function ContextMenu({
?.querySelector<HTMLButtonElement>(
'[data-context-menu-submenu-item]:not(:disabled)',
)
- ?.focus();
+ ?.focus({ preventScroll: true });
});
}}
onClick={() => {
diff --git a/apps/desktop/src/components/workpanel/WorkPanel.tsx b/apps/desktop/src/components/workpanel/WorkPanel.tsx
index 8d4280773..8a3ca69fd 100644
--- a/apps/desktop/src/components/workpanel/WorkPanel.tsx
+++ b/apps/desktop/src/components/workpanel/WorkPanel.tsx
@@ -29,6 +29,11 @@ import { pluginViewIcon, pluginViewInitial } from "../../lib/plugin-view-icons";
import { useAppStore } from "../../stores/app-store";
import type { WorkPanelTab } from "../../stores/app-store";
import { cx } from "../ui";
+import {
+ ContextMenu,
+ useContextMenu,
+ type ContextMenuItem,
+} from "../ContextMenu";
import { TooltipButton } from "../ui";
import type { IconProps } from "../icons";
import {
@@ -206,6 +211,11 @@ function LocalWorkPanel({
}) {
const { t } = useTranslation();
const blockingOverlayActive = useBlockingOverlayActive();
+ const {
+ contextMenu: tabContextMenu,
+ openContextMenu: openTabContextMenu,
+ closeContextMenu: closeTabContextMenu,
+ } = useContextMenu();
const rawTabs = useAppStore((s) => s.workPanelTabs);
const tabs = rawTabs.filter(isKnownWorkPanelTab);
const activeTabId = useAppStore((s) => s.activeWorkPanelTabId);
@@ -217,6 +227,8 @@ function LocalWorkPanel({
const reorderTabs = useAppStore((s) => s.reorderWorkPanelTabs);
const closeTab = useAppStore((s) => s.closeWorkPanelTab);
const openWorkPanelTab = useAppStore((s) => s.openWorkPanelTab);
+ const closeOtherTabs = useAppStore((s) => s.closeOtherWorkPanelTabs);
+ const closeAllTabs = useAppStore((s) => s.closeAllWorkPanelTabs);
const openNewWorkPanelTab = useAppStore((s) => s.openNewWorkPanelTab);
const replaceWorkPanelTab = useAppStore((s) => s.replaceWorkPanelTab);
const setWidth = useAppStore((s) => s.setWorkPanelWidth);
@@ -225,6 +237,7 @@ function LocalWorkPanel({
const tabSignature = JSON.stringify(
tabs.map(({ id, kind, resource, location }) => [id, kind, resource, location]),
);
+
// Subagent tabs may share an agent name; repeats gain a 1-based `#n`
// suffix in strip order so the row stays unambiguous. The base label
// already falls back to panel.tabs.subagent when no name was captured.
@@ -644,6 +657,17 @@ function LocalWorkPanel({
},
[closeTab, tabs],
);
+ const closeOtherTabsAndFocus = useCallback(
+ (tabId: string) => {
+ closeOtherTabs(tabId);
+ requestAnimationFrame(() => tabButtonRefs.current[tabId]?.focus());
+ },
+ [closeOtherTabs],
+ );
+ const closeAllTabsAndFocus = useCallback(() => {
+ closeAllTabs();
+ requestAnimationFrame(() => newTabButtonRef.current?.focus());
+ }, [closeAllTabs]);
const onTabKeyDown = useCallback(
(event: ReactKeyboardEvent<HTMLButtonElement>, tabId: string) => {
const index = tabs.findIndex((tab) => tab.id === tabId);
@@ -912,6 +936,31 @@ function LocalWorkPanel({
// revealing opacity is not enough when the control sits
// outside the strip, so bring the whole box in first.
onPointerEnter={() => revealTab(tab.id)}
+ onContextMenu={(event) => {
+ const items: ContextMenuItem[] = [
+ {
+ id: "close-tab",
+ label: t("panel.closeTab", { name: label }),
+ onSelect: () => closeTabAndFocus(tab.id),
+ },
+ {
+ id: "close-other-tabs",
+ label: t("panel.closeOtherTabs"),
+ disabled: tabs.length <= 1,
+ separatorBefore: true,
+ onSelect: () => closeOtherTabsAndFocus(tab.id),
+ },
+ {
+ id: "close-all-tabs",
+ label: t("panel.closeAllTabs"),
+ onSelect: closeAllTabsAndFocus,
+ },
+ ];
+ openTabContextMenu(event, {
+ label: t("panel.tabsLabel"),
+ items,
+ });
+ }}
key={tab.id}
>
<button
@@ -1088,6 +1137,7 @@ function LocalWorkPanel({
)}
</div>
</div>
+ <ContextMenu state={tabContextMenu} onClose={closeTabContextMenu} />
</aside>
);
}
diff --git a/apps/desktop/src/lib/work-panel-tabs.ts b/apps/desktop/src/lib/work-panel-tabs.ts
index dac6dfc60..5a89f4d82 100644
--- a/apps/desktop/src/lib/work-panel-tabs.ts
+++ b/apps/desktop/src/lib/work-panel-tabs.ts
@@ -409,6 +409,24 @@ export function closeWorkPanelTabState(
};
}
+export function closeOtherWorkPanelTabsState(
+ state: WorkPanelTabsState,
+ tabId: string,
+): WorkPanelTabsState {
+ const tab = state.tabs.find((item) => item.id === tabId);
+ if (!tab) return state;
+ if (state.tabs.length === 1 && state.activeTabId === tabId) return state;
+ return { tabs: [tab], activeTabId: tab.id };
+}
+
+export function closeAllWorkPanelTabsState(
+ state: WorkPanelTabsState,
+): WorkPanelTabsState {
+ return state.tabs.length === 0 && state.activeTabId === null
+ ? state
+ : { tabs: [], activeTabId: null };
+}
+
/**
* Display labels for the subagent tabs in strip order.
*
diff --git a/apps/desktop/src/stores/app-state.ts b/apps/desktop/src/stores/app-state.ts
index faa36c6d2..47df28c31 100644
--- a/apps/desktop/src/stores/app-state.ts
+++ b/apps/desktop/src/stores/app-state.ts
@@ -427,6 +427,8 @@ export type AppState = {
insertAfter: boolean,
) => void;
closeWorkPanelTab: (tabId: string) => void;
+ closeOtherWorkPanelTabs: (tabId: string) => void;
+ closeAllWorkPanelTabs: () => void;
collapseWorkPanel: () => void;
/** Hide the visible panel while retaining its session-owned context. */
resetWorkPanelContext: () => void;
diff --git a/apps/desktop/src/stores/slices/work-panel-slice.ts b/apps/desktop/src/stores/slices/work-panel-slice.ts
index 90af311e5..3da354efb 100644
--- a/apps/desktop/src/stores/slices/work-panel-slice.ts
+++ b/apps/desktop/src/stores/slices/work-panel-slice.ts
@@ -4,6 +4,8 @@ import {
activateWorkPanelTabState,
browserPluginTab,
browserTabLabel,
+ closeAllWorkPanelTabsState,
+ closeOtherWorkPanelTabsState,
closeWorkPanelTabState,
createWorkPanelFileRequest,
emptyWorkPanelContext,
@@ -111,6 +113,8 @@ export function createWorkPanelSlice({
| "activateWorkPanelTab"
| "reorderWorkPanelTabs"
| "closeWorkPanelTab"
+ | "closeOtherWorkPanelTabs"
+ | "closeAllWorkPanelTabs"
| "collapseWorkPanel"
| "resetWorkPanelContext"
| "setWorkPanelWidth"
@@ -125,6 +129,10 @@ export function createWorkPanelSlice({
if (!tab || tab.kind !== "file" || !tab.resource) return null;
return createWorkPanelFileRequest(tab, ++workPanelFileRequestSeq);
};
+ const closeBrowserWorkPanelTab = (sessionId: string, tabId: string) => {
+ void api.pluginViewClose("pi.browser", "browser", { sessionId, tabId })
+ .catch((error) => get().showToast(String(error), { variant: "error" }));
+ };
return {
openSubagentTab: (delegationId, agentName) => {
@@ -300,9 +308,11 @@ export function createWorkPanelSlice({
},
closeWorkPanelTab: (tabId) => {
const current = get();
- if (current.activeSessionId && current.workPanelTabs.some((tab) => tab.id === tabId && tab.resource === "pi.browser/browser")) {
- void api.pluginViewClose("pi.browser", "browser", { sessionId: current.activeSessionId, tabId })
- .catch((error) => get().showToast(String(error), { variant: "error" }));
+ const browserTab = current.workPanelTabs.find(
+ (tab) => tab.id === tabId && tab.resource === "pi.browser/browser",
+ );
+ if (current.activeSessionId && browserTab) {
+ closeBrowserWorkPanelTab(current.activeSessionId, browserTab.id);
}
set((state) => {
const sessionId = state.activeSessionId;
@@ -336,6 +346,70 @@ export function createWorkPanelSlice({
};
});
},
+ closeOtherWorkPanelTabs: (tabId) => {
+ const current = get();
+ const sessionId = current.activeSessionId;
+ if (!sessionId) return;
+ const state = {
+ tabs: current.workPanelTabs,
+ activeTabId: current.activeWorkPanelTabId,
+ };
+ const next = closeOtherWorkPanelTabsState(state, tabId);
+ if (next === state) return;
+ for (const tab of state.tabs) {
+ if (tab.id !== tabId && tab.resource === "pi.browser/browser") {
+ closeBrowserWorkPanelTab(sessionId, tab.id);
+ }
+ }
+ const activeTab = next.tabs.find((tab) => tab.id === next.activeTabId);
+ const fileRequest = nextFileRequest(activeTab) ?? current.workPanelFileRequest;
+ const nextContext: WorkPanelContext = {
+ open: current.workPanelOpen,
+ tabs: next.tabs,
+ activeTabId: next.activeTabId,
+ fileRequest,
+ };
+ set({
+ workPanelTabs: next.tabs,
+ activeWorkPanelTabId: next.activeTabId,
+ workPanelFileRequest: fileRequest,
+ workPanelContexts: {
+ ...current.workPanelContexts,
+ [sessionId]: nextContext,
+ },
+ });
+ },
+ closeAllWorkPanelTabs: () => {
+ const current = get();
+ const sessionId = current.activeSessionId;
+ if (!sessionId) return;
+ const state = {
+ tabs: current.workPanelTabs,
+ activeTabId: current.activeWorkPanelTabId,
+ };
+ const next = closeAllWorkPanelTabsState(state);
+ if (next === state) return;
+ for (const tab of state.tabs) {
+ if (tab.resource === "pi.browser/browser") {
+ closeBrowserWorkPanelTab(sessionId, tab.id);
+ }
+ }
+ const nextContext: WorkPanelContext = {
+ open: current.workPanelOpen,
+ tabs: next.tabs,
+ activeTabId: next.activeTabId,
+ fileRequest: null,
+ };
+ set({
+ workPanelTabs: next.tabs,
+ activeWorkPanelTabId: next.activeTabId,
+ workPanelFileRequest: null,
+ workPanelContexts: {
+ ...current.workPanelContexts,
+ [sessionId]: nextContext,
+ },
+ });
+ },
collapseWorkPanel: () => {
const state = get();
const sessionId = state.activeSessionId;
diff --git a/apps/desktop/test/browser-tab-restore.test.mjs b/apps/desktop/test/browser-tab-restore.test.mjs
index 5b01f04ab..79363e2d1 100644
--- a/apps/desktop/test/browser-tab-restore.test.mjs
+++ b/apps/desktop/test/browser-tab-restore.test.mjs
@@ -8,8 +8,15 @@ import * as workPanelTabs from "../src/lib/work-panel-tabs.ts";
const { outputText } = ts.transpileModule(readFileSync(new URL("../src/stores/slices/work-panel-slice.ts", import.meta.url), "utf8"), {
compilerOptions: { module: ts.ModuleKind.CommonJS, target: ts.ScriptTarget.ES2022 },
});
+const closedBrowserTabs = [];
const imports = {
- "../../lib/api": { api: { pluginViewClose: async () => {} } },
+ "../../lib/api": {
+ api: {
+ pluginViewClose: async (_pluginId, _viewId, options) => {
+ closedBrowserTabs.push(options);
+ },
+ },
+ },
"../../lib/remote-session-safety": { isRemoteSession: () => false },
"../../lib/work-panel-tabs": workPanelTabs,
"../../lib/work-panel-resize": workPanelResize,
@@ -66,3 +73,45 @@ test("renderer recovery does not duplicate tabs or replace a user-selected resou
get().closeWorkPanelTab("a");
assert.deepEqual(get().workPanelTabs.map((tab) => tab.id), ["review"]);
});
+
+test("bulk tab closing retains the target and releases Browser resources", () => {
+ closedBrowserTabs.length = 0;
+ const { get, set } = store();
+ const browserA = workPanelTabs.browserPluginTab("https://a.example");
+ const browserB = workPanelTabs.browserPluginTab("https://b.example");
+ const review = workPanelTabs.toolWorkPanelTab("review");
+ const file = workPanelTabs.fileWorkPanelTab("src/App.tsx");
+ set({
+ workPanelOpen: true,
+ workPanelTabs: [browserA, review, browserB, file],
+ activeWorkPanelTabId: file.id,
+ });
+
+ get().closeOtherWorkPanelTabs(review.id);
+
+ assert.deepEqual(get().workPanelTabs, [review]);
+ assert.equal(get().activeWorkPanelTabId, review.id);
+ assert.equal(get().workPanelContexts.A.open, true);
+ assert.deepEqual(get().workPanelContexts.A.tabs, [review]);
+ assert.deepEqual(closedBrowserTabs, [
+ { sessionId: "A", tabId: browserA.id },
+ { sessionId: "A", tabId: browserB.id },
+ ]);
+
+ const remainingBrowser = workPanelTabs.browserPluginTab("https://remaining.example");
+ set({
+ workPanelTabs: [review, remainingBrowser],
+ activeWorkPanelTabId: remainingBrowser.id,
+ });
+ get().closeAllWorkPanelTabs();
+
+ assert.deepEqual(get().workPanelTabs, []);
+ assert.equal(get().activeWorkPanelTabId, null);
+ assert.equal(get().workPanelOpen, true);
+ assert.equal(get().workPanelFileRequest, null);
+ assert.deepEqual(get().workPanelContexts.A.tabs, []);
+ assert.deepEqual(closedBrowserTabs[2], {
+ sessionId: "A",
+ tabId: remainingBrowser.id,
+ });
+});
diff --git a/apps/desktop/test/work-panel-tabs.test.mjs b/apps/desktop/test/work-panel-tabs.test.mjs
index 9683aef2a..e5b05903a 100644
--- a/apps/desktop/test/work-panel-tabs.test.mjs
+++ b/apps/desktop/test/work-panel-tabs.test.mjs
@@ -7,6 +7,8 @@ const {
browserPluginTab,
browserPluginTabForReveal,
closeWorkPanelTabState,
+ closeAllWorkPanelTabsState,
+ closeOtherWorkPanelTabsState,
createWorkPanelFileRequest,
emptyWorkPanelContext,
fileWorkPanelTab,
@@ -140,6 +142,25 @@ test("closing an inactive tab preserves selection and the last close empties sta
assert.deepEqual(empty, { tabs: [], activeTabId: null });
});
+test("closing other tabs retains and activates the requested tab", () => {
+ const review = toolWorkPanelTab("review");
+ const file = fileWorkPanelTab("src/App.tsx");
+ const browser = browserPluginTab("https://example.com");
+ const state = { tabs: [review, file, browser], activeTabId: review.id };
+
+ const retained = closeOtherWorkPanelTabsState(state, browser.id);
+ assert.deepEqual(retained, { tabs: [browser], activeTabId: browser.id });
+ assert.equal(closeOtherWorkPanelTabsState(state, "missing"), state);
+});
+
+test("closing all tabs clears selection and is idempotent", () => {
+ const state = { tabs: [toolWorkPanelTab("review")], activeTabId: "review" };
+ const empty = closeAllWorkPanelTabsState(state);
+
+ assert.deepEqual(empty, { tabs: [], activeTabId: null });
+ assert.equal(closeAllWorkPanelTabsState(empty), empty);
+});
+
test("activation ignores stale tab ids", () => {
const state = { tabs: [toolWorkPanelTab("review")], activeTabId: "review" };
assert.equal(activateWorkPanelTabState(state, "missing"), state);
diff --git a/apps/desktop/test/work-panel.test.mjs b/apps/desktop/test/work-panel.test.mjs
index 9f8719ae9..5d2d31036 100644
--- a/apps/desktop/test/work-panel.test.mjs
+++ b/apps/desktop/test/work-panel.test.mjs
@@ -316,7 +316,13 @@ test("work panel header exposes a scrollable tab strip and direct new-page actio
);
assert.doesNotMatch(pluginSurface, /isResizing/);
assert.doesNotMatch(panelSource, /createPortal|newTabMenuRef|menuOpen/);
- assert.doesNotMatch(panelSource, /onContextMenu|work-panel-context-menu/);
+ assert.match(panelSource, /onContextMenu=\{\(event\) =>/);
+ assert.match(panelSource, /id: "close-tab"/);
+ assert.match(panelSource, /id: "close-other-tabs"[\s\S]*?closeOtherTabsAndFocus\(tab\.id\)/);
+ assert.match(panelSource, /disabled: tabs\.length <= 1/);
+ assert.match(panelSource, /id: "close-all-tabs"[\s\S]*?closeAllTabsAndFocus/);
+ assert.match(panelSource, /<ContextMenu state=\{tabContextMenu\}/);
+ assert.doesNotMatch(panelSource, /work-panel-context-menu/);
assert.doesNotMatch(globalStyles, /work-panel-new-menu|work-panel-menu-item|work-panel-open-dot/);
assert.match(globalStyles, /\.work-panel-tab-strip \{[^}]*overflow-x:\s*auto;/s);
assert.match(globalStyles, /\.work-panel-tab-strip \{[^}]*gap:\s*6px;/s);
@@ -556,8 +562,8 @@ test("file preview request ids stay unique across session contexts", () => {
/const nextFileRequest = \(tab\?: WorkPanelTab\)[\s\S]*?createWorkPanelFileRequest\(tab, \+\+workPanelFileRequestSeq\)/,
);
assert.ok(
- storeSource.match(/nextFileRequest\((?:tab|activeTab)\)/g)?.length === 4,
- "open, replace, activation, and close paths must share the position-preserving request",
+ storeSource.match(/nextFileRequest\((?:tab|activeTab)\)/g)?.length === 5,
+ "open, replace, activation, close, and close-other paths must share the position-preserving request",
);
assert.doesNotMatch(storeSource, /seq:\s*\([^)]*fileRequest\?\.seq[^)]*\) \+ 1/);
});
diff --git a/docs/spec/04-ux/08-component-spec.md b/docs/spec/04-ux/08-component-spec.md
index 758ce9909..188f8ebb9 100644
--- a/docs/spec/04-ux/08-component-spec.md
+++ b/docs/spec/04-ux/08-component-spec.md
@@ -1297,6 +1297,11 @@ entirely inside the plugin's isolated page:
the strip toward off-screen tabs. `Alt+ArrowLeft`/`Alt+ArrowRight` reorders
the focused tab without changing its active state. The `+` trigger remains
fixed beside the strip and creates a new launcher tab.
+- Tab context menu: right-clicking a tab or invoking its context-menu key while
+ focused opens a localized menu with Close Tab, Close Other Tabs, and Close All
+ Tabs. Close Other Tabs keeps and activates the pointed-to tab and is disabled
+ when it is the only tab. Close All Tabs releases Browser pages, empties the
+ strip, and leaves the panel open on the New launcher.
- New launcher: each `+` click creates a unique, active New tab. Its body uses
the Review-plus-plugin tool list as buttons. Selecting a row replaces the
launcher tab with that destination or activates its existing singleton.
@@ -1359,6 +1364,8 @@ entirely inside the plugin's isolated page:
`aria-controls`, roving `tabIndex`, and localized close buttons.
ArrowLeft/ArrowRight/Home/End move through tabs; Delete/Backspace and
middle-click close the focused tab. The `+` button is a direct action with a
+ Right-click, Shift+F10, or the context-menu key on a focused tab opens a
+ localized `role="menu"` with the shared arrow/Enter/Escape navigation.
localized label and no popup state. A New tab's body is a labelled
`role="tabpanel"` containing a labelled `role="group"` of ordinary buttons;
the legacy no-tab reveal remains a plain labelled group. Each resource body
diff --git a/docs/spec/04-ux/09-interaction-patterns.md b/docs/spec/04-ux/09-interaction-patterns.md
index 1ffd8965f..56d24b67d 100644
--- a/docs/spec/04-ux/09-interaction-patterns.md
+++ b/docs/spec/04-ux/09-interaction-patterns.md
@@ -570,6 +570,10 @@ may be retained while exactly one workspace supplies the visible shell context.
then the left. Selecting a launcher row replaces that New tab with the
destination or activates its existing singleton. Shortcut labels appear only
for bindings that actually exist.
+- Right-clicking a tab or invoking the context-menu key on the focused tab opens
+ Close Tab, Close Other Tabs, and Close All Tabs. Close Other Tabs activates the
+ targeted tab and closes every other tab; it is disabled for a single tab.
+ Close All Tabs closes Browser resources and leaves the panel open on New.
- Activating a tool that is already open activates its existing resource instead
of replacing it, so Browser keeps its URL and Files its selection (D173).
- Every resource can be closed from its tab. Closing the active resource selects
diff --git a/docs/spec/06-delivery/04-e2e-test-plan.md b/docs/spec/06-delivery/04-e2e-test-plan.md
index 1fbf608e9..0b6ed5423 100644
--- a/docs/spec/06-delivery/04-e2e-test-plan.md
+++ b/docs/spec/06-delivery/04-e2e-test-plan.md
@@ -4779,13 +4779,16 @@ window; opening a normal panel afterward must still work.
context. 2) Open two distinct file artifacts, the same first file again,
a URL preview, and a completed Bash row. 3) Verify the header is a tablist:
open enough tabs to overflow it, confirm only the strip scrolls and the `+`
- trigger stays visible, activate the scrolled-away tab, and close tabs with
- hover/focus `×` and middle-click. Drag a tab across another tab and verify
- the before/after drop indicator, resulting order, and unchanged active tab;
- hold a drag at each strip edge until hidden tabs scroll into view, then verify
- the indicator follows the newly visible targets. Repeat with
- `Alt+ArrowLeft`/`Alt+ArrowRight`. With only one or two tabs, drag unused
- header space to move the native window; tab and action clicks must still
+ trigger stays visible, and activate the scrolled-away tab. Right-click an
+ inactive tab and choose Close Other Tabs; verify the pointed-to tab remains
+ and becomes active, and that the action is disabled with one tab. Reopen
+ multiple artifacts, then right-click and choose Close All Tabs; confirm the
+ panel remains open on the New launcher. Reopen resources before checking
+ hover/focus `×`, middle-click, drag reorder, insertion indicators, and edge
+ auto-scroll. Open a tab menu with Shift+F10, navigate its items with arrows,
+ 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;
@@ -4830,17 +4833,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. 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.
- Closing the last tab leaves the panel open on New. Collapse
+ 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
previews its current/minimum/maximum values through the panel separator. The
@@ -4872,7 +4880,9 @@ window; opening a normal panel afterward must still work.
- **Milestone**: M5
- **Status**: Unit-covered (`work-panel-resize.test.mjs`,
`work-panel-window.test.mjs`, `work-panel-presentation.test.mjs`,
- `work-panel.test.mjs`); full UI scenario Draft
+ `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
#### E2E-057: Message-owned review history survives commits and rolls back safely
diff --git a/packages/i18n/src/locales/de/index.ts b/packages/i18n/src/locales/de/index.ts
index 63e702617..d4673ecfc 100644
--- a/packages/i18n/src/locales/de/index.ts
+++ b/packages/i18n/src/locales/de/index.ts
@@ -2084,6 +2084,8 @@ sklm: {
"open": "Neu"
},
"closeTab": "Schließen {{name}}",
+ "closeOtherTabs": "Andere Tabs schließen",
+ "closeAllTabs": "Alle Tabs schließen",
"tabs": {
"review": "Überprüfen",
"browser": "Browser",
diff --git a/packages/i18n/src/locales/en/index.ts b/packages/i18n/src/locales/en/index.ts
index 8b93bb542..8f81407d0 100644
--- a/packages/i18n/src/locales/en/index.ts
+++ b/packages/i18n/src/locales/en/index.ts
@@ -2104,6 +2104,8 @@ sklm: {
open: "New",
},
closeTab: "Close {{name}}",
+ closeOtherTabs: "Close other tabs",
+ closeAllTabs: "Close all tabs",
tabs: {
review: "Review",
browser: "Browser",
diff --git a/packages/i18n/src/locales/es/index.ts b/packages/i18n/src/locales/es/index.ts
index eca25feba..0b2d870b3 100644
--- a/packages/i18n/src/locales/es/index.ts
+++ b/packages/i18n/src/locales/es/index.ts
@@ -2084,6 +2084,8 @@ sklm: {
"open": "Nuevo"
},
"closeTab": "Cerrar {{name}}",
+ "closeOtherTabs": "Cerrar las demás pestañas",
+ "closeAllTabs": "Cerrar todas las pestañas",
"tabs": {
"review": "Revisar",
"browser": "Navegador",
diff --git a/packages/i18n/src/locales/fr/index.ts b/packages/i18n/src/locales/fr/index.ts
index a40b57527..e4c1ed23c 100644
--- a/packages/i18n/src/locales/fr/index.ts
+++ b/packages/i18n/src/locales/fr/index.ts
@@ -2084,6 +2084,8 @@ sklm: {
"open": "Nouveau"
},
"closeTab": "Fermer {{name}}",
+ "closeOtherTabs": "Fermer les autres onglets",
+ "closeAllTabs": "Fermer tous les onglets",
"tabs": {
"review": "Réviser",
"browser": "Navigateur",
diff --git a/packages/i18n/src/locales/ko/index.ts b/packages/i18n/src/locales/ko/index.ts
index eedbbf607..df9576c0b 100644
--- a/packages/i18n/src/locales/ko/index.ts
+++ b/packages/i18n/src/locales/ko/index.ts
@@ -2100,6 +2100,8 @@ sklm: {
open: "새로 만들기",
},
closeTab: "{{name}} 닫기",
+ closeOtherTabs: "다른 탭 닫기",
+ closeAllTabs: "모든 탭 닫기",
tabs: {
review: "검토",
browser: "브라우저",
diff --git a/packages/i18n/src/locales/pt-BR/index.ts b/packages/i18n/src/locales/pt-BR/index.ts
index a83bd2b0d..ccef8e9a3 100644
--- a/packages/i18n/src/locales/pt-BR/index.ts
+++ b/packages/i18n/src/locales/pt-BR/index.ts
@@ -2050,6 +2050,8 @@ export const ptBR = {
open: "Novo"
},
closeTab: "Fechar {{name}}",
+ closeOtherTabs: "Fechar outras abas",
+ closeAllTabs: "Fechar todas as abas",
tabs: {
review: "Revisar",
browser: "Navegador",
diff --git a/packages/i18n/src/locales/tr/index.ts b/packages/i18n/src/locales/tr/index.ts
index 3e84b7327..88726748a 100644
--- a/packages/i18n/src/locales/tr/index.ts
+++ b/packages/i18n/src/locales/tr/index.ts
@@ -2094,6 +2094,8 @@ sklm: {
open: "Yeni",
},
closeTab: "{{name}} öğesini kapat",
+ closeOtherTabs: "Diğer sekmeleri kapat",
+ closeAllTabs: "Tüm sekmeleri kapat",
tabs: {
review: "İnceleme",
browser: "Tarayıcı",
diff --git a/packages/i18n/src/locales/zh-CN/index.ts b/packages/i18n/src/locales/zh-CN/index.ts
index a403f3a85..551cc80ff 100644
--- a/packages/i18n/src/locales/zh-CN/index.ts
+++ b/packages/i18n/src/locales/zh-CN/index.ts
@@ -2079,6 +2079,8 @@ sklm: {
open: "新建",
},
closeTab: "关闭{{name}}",
+ closeOtherTabs: "关闭其他标签页",
+ closeAllTabs: "关闭所有标签页",
tabs: {
review: "审阅",
browser: "浏览器",
diff --git a/packages/i18n/src/locales/zh-TW/index.ts b/packages/i18n/src/locales/zh-TW/index.ts
index 94e14a621..6e962a278 100644
--- a/packages/i18n/src/locales/zh-TW/index.ts
+++ b/packages/i18n/src/locales/zh-TW/index.ts
@@ -2079,6 +2079,8 @@ sklm: {
open: "新增",
},
closeTab: "關閉{{name}}",
+ closeOtherTabs: "關閉其他標籤頁",
+ closeAllTabs: "關閉所有標籤頁",
tabs: {
review: "審閱",
browser: "瀏覽器",
diff --git a/scripts/e2e-work-panel-tab-close.mjs b/scripts/e2e-work-panel-tab-close.mjs
index 6f55c71d3..9a2f390fd 100644
--- a/scripts/e2e-work-panel-tab-close.mjs
+++ b/scripts/e2e-work-panel-tab-close.mjs
@@ -28,7 +28,7 @@ const temp = await mkdtemp(join(tmpdir(), "pi-tab-close-"));
try {
const styles = await Promise.all(
- ["tokens", "base", "chat-shell", "work-panel"].map((name) =>
+ ["tokens", "base", "chat-shell", "ui-kit", "work-panel"].map((name) =>
readFile(join(root, `apps/desktop/src/styles/${name}.css`), "utf8"),
),
);
@@ -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"]) {
+ for (const stage of ["narrow-active", "resize-same-tab", "hover-inactive", "context-menu-user-path"]) {
const result = await win.webContents.executeJavaScript(
"window.tabCloseProbe(" + JSON.stringify(stage) + ")");
console.log("TAB_CLOSE " + JSON.stringify(result));
@@ -99,9 +99,16 @@ 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, 3, "expected three probe stages");
+ assert.equal(results.length, 4, "expected three geometry stages and one context-menu user path");
for (const result of results) {
+ if (result.stage === "context-menu-user-path") {
+ assert.equal(result.passed, true, "tab context-menu user path failed");
+ assert.equal(result.remainingTabs, 0, "Close All Tabs did not empty the strip");
+ assert.equal(result.activeTabId, null, "Close All Tabs retained an active tab");
+ console.log("context menu user path: 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 87608b27d..f47d07563 100644
--- a/scripts/e2e/work-panel-tab-close.tsx
+++ b/scripts/e2e/work-panel-tab-close.tsx
@@ -29,8 +29,15 @@ type CloseGeometry = {
hitIsClose: boolean;
hitIsDescendant: boolean;
};
+
+type TabContextMenuPathResult = {
+ stage: "context-menu-user-path";
+ passed: true;
+ remainingTabs: number;
+ activeTabId: string | null;
+};
declare global {
- var tabCloseProbe: (stage: string) => Promise<CloseGeometry>;
+ var tabCloseProbe: (stage: string) => Promise<CloseGeometry | TabContextMenuPathResult>;
}
const assert = (condition: unknown, message: string) => {
@@ -131,8 +138,115 @@ function measure(stage: string): CloseGeometry {
};
}
+async function runTabContextMenuUserPath(): Promise<TabContextMenuPathResult> {
+ useAppStore.setState({
+ workPanelOpen: true,
+ workPanelTabs: [],
+ activeWorkPanelTabId: null,
+ workPanelFileRequest: null,
+ workPanelContexts: {},
+ });
+ renderPanel(1000);
+ openManyLongTabs(3);
+ await rendered();
+
+ const tabIds = () =>
+ [...host.querySelectorAll<HTMLElement>(".work-panel-tab")].map(
+ (tab) => tab.dataset.workPanelTabId,
+ );
+ const initialIds = tabIds();
+ assert(initialIds.length === 3, "fixture did not create three tabs");
+ const firstId = initialIds[0];
+ const secondId = initialIds[1];
+ if (!firstId || !secondId) throw new Error("fixture tab ids are missing");
+
+ const openTabMenu = async (tabId: string, keyboard = false) => {
+ const wrapper = host.querySelector<HTMLElement>(
+ `[data-work-panel-tab-id="${CSS.escape(tabId)}"]`,
+ );
+ assert(wrapper, "target tab wrapper is missing");
+ const tabButton = wrapper!.querySelector<HTMLElement>("[role=tab]");
+ assert(tabButton, "target tab button is missing");
+ window.getSelection()?.removeAllRanges();
+ if (keyboard) tabButton!.focus({ preventScroll: true });
+ const event = new MouseEvent("contextmenu", {
+ bubbles: true,
+ cancelable: true,
+ clientX: keyboard ? 0 : 24,
+ clientY: keyboard ? 0 : 24,
+ });
+ flushSync(() => wrapper!.dispatchEvent(event));
+ assert(event.defaultPrevented, "tab context menu did not prevent the platform menu");
+ await rendered();
+ const menu = document.body.querySelector<HTMLElement>('[role="menu"]');
+ assert(
+ menu,
+ `tab context menu did not open (menus=${document.body.querySelectorAll("[role=menu]").length}; tabs=${host.querySelectorAll(".work-panel-tab").length})`,
+ );
+ assert(
+ menu!.getAttribute("aria-label") === "Side panel tabs",
+ "tab context menu label was not localized",
+ );
+ return menu!;
+ };
+ const menuItem = (menu: HTMLElement, id: string) => {
+ const item = menu.querySelector<HTMLButtonElement>(
+ `[data-context-menu-item="${id}"]`,
+ );
+ assert(item, "missing context-menu item " + id);
+ return item!;
+ };
+
+ let menu = await openTabMenu(firstId, true);
+ document.activeElement?.dispatchEvent(
+ new KeyboardEvent("keydown", { key: "ArrowDown", bubbles: true, cancelable: true }),
+ );
+ await rendered();
+ assert(
+ (document.activeElement as HTMLElement | null)?.dataset.contextMenuItem ===
+ "close-other-tabs",
+ "ArrowDown did not move focus through the tab menu",
+ );
+ document.activeElement?.dispatchEvent(
+ new KeyboardEvent("keydown", { key: "Escape", bubbles: true, cancelable: true }),
+ );
+ await rendered();
+ assert(!document.body.querySelector('[role="menu"]'), "Escape did not close the tab menu");
+
+ menu = await openTabMenu(firstId);
+ flushSync(() => menuItem(menu, "close-tab").click());
+ await rendered();
+ assert(!tabIds().includes(firstId), "Close Tab left the target tab open");
+
+ menu = await openTabMenu(secondId);
+ flushSync(() => menuItem(menu, "close-other-tabs").click());
+ await rendered();
+ assert(tabIds().length === 1 && tabIds()[0] === secondId, "Close Other Tabs did not retain its target");
+ assert(activeTabId() === secondId, "Close Other Tabs did not activate its target");
+
+ menu = await openTabMenu(secondId);
+ assert(menuItem(menu, "close-other-tabs").disabled, "Close Other Tabs must be disabled for one tab");
+ flushSync(() => menuItem(menu, "close-all-tabs").click());
+ await rendered();
+ assert(tabIds().length === 0, "Close All Tabs left resources open");
+ assert(useAppStore.getState().activeWorkPanelTabId === null, "Close All Tabs retained an active tab");
+ assert(useAppStore.getState().workPanelOpen, "Close All Tabs collapsed the work panel");
+ assert(host.querySelector('[data-testid="work-panel-empty"]'), "Close All Tabs did not show the New launcher");
+
+ return {
+ stage: "context-menu-user-path",
+ passed: true,
+ remainingTabs: tabIds().length,
+ activeTabId: useAppStore.getState().activeWorkPanelTabId,
+ };
+}
+
globalThis.tabCloseProbe = async (stage) => {
await ready;
+ if (stage === "context-menu-user-path") {
+ await ready;
+ return runTabContextMenuUserPath();
+ }
if (stage === "narrow-active") {
renderPanel(900);