Skip to content

A local-first multi-agent app development platform, built on PenguinHarness

fix(web): the terminal panel closes when something takes its place (#377)

Myriad-Dreamin5a57c7374a7b
diff --git a/changelog/unreleased/2026-08-20-terminal-panel-swap.md b/changelog/unreleased/2026-08-20-terminal-panel-swap.md
new file mode 100644
index 00000000..2a3f23c1
--- /dev/null
+++ b/changelog/unreleased/2026-08-20-terminal-panel-swap.md
@@ -0,0 +1,29 @@
+# The terminal panel closes when something takes its place
+
+- **Date:** 2026-08-20
+- **Type:** fix
+- **Scope:** `web`
+
+[中文版](2026-08-20-terminal-panel-swap.zh.md)
+
+Two ways the terminal stayed on screen after the user had, as far as they could tell,
+closed it.
+
+## Opening a chat panel closes a side pane, not parks it
+
+A left or right terminal pane and the Agents/Workspace panel share one slot, and opening
+the panel used to displace the pane behind it — so closing the panel again brought the
+terminal back, unasked. From where the user sits, opening the panel is what closed the
+terminal; closing the panel should leave the slot empty.
+
+It closes now. The arrangement survives, so reopening the dock returns it to the edge it
+was on with its screen intact — what does not survive is the showing of it. A top or
+bottom pane is unaffected: it costs height, not width, and never competed for that slot.
+
+## The dock stays with its conversation
+
+A terminal opened in a conversation followed the user into Agents, Skills and user
+management — pages with no conversation of their own, where a shell has nothing to do with
+what is on screen. Those pages scope the dock to a placeholder that holds no arrangement,
+so it is simply not there; returning to the conversation restores it, screen and all. The
+shell keeps running throughout, as it does whenever the panel is closed.
diff --git a/changelog/unreleased/2026-08-20-terminal-panel-swap.zh.md b/changelog/unreleased/2026-08-20-terminal-panel-swap.zh.md
new file mode 100644
index 00000000..b015656c
--- /dev/null
+++ b/changelog/unreleased/2026-08-20-terminal-panel-swap.zh.md
@@ -0,0 +1,19 @@
+# 终端面板在被别的东西顶替时会真正关闭
+
+- **Date:** 2026-08-20
+- **Type:** fix
+- **Scope:** `web`
+
+[English](2026-08-20-terminal-panel-swap.md)
+
+有两种情况下,终端在用户看来已经被关掉了,却仍然留在屏幕上。
+
+## 打开聊天面板是关闭侧边窗格,而不是把它停在后面
+
+左侧或右侧的终端窗格与 Agents / 工作区面板共用同一块位置,而此前打开面板只是把窗格挤到它后面——于是再关掉面板,终端就自己回来了,没人要求它回来。从用户的视角看,打开面板正是关掉终端的那个动作;关掉面板之后,那块位置应该是空的。
+
+现在它是真的关闭。布局仍然保留,所以重新打开终端会回到它原来那条边、屏幕内容完好——不保留的只是「正在显示」这件事。上下窗格不受影响:它们占的是高度而不是宽度,从来就不争这块位置。
+
+## 终端跟着它所属的对话
+
+在某个对话里打开的终端,会跟着用户进入 Agents、技能库、用户管理——那些页面没有自己的对话,一个 shell 摆在那儿与屏幕上的内容毫无关系。这些页面把终端面板归到一个不持有任何布局的占位作用域,于是它根本不在那里;回到对话则原样恢复,包括屏幕内容。整个过程中 shell 一直在运行,就像任何一次关闭面板那样。
diff --git a/packages/web/e2e/terminal-dock.spec.mjs b/packages/web/e2e/terminal-dock.spec.mjs
index 92911a9c..7d324f05 100644
--- a/packages/web/e2e/terminal-dock.spec.mjs
+++ b/packages/web/e2e/terminal-dock.spec.mjs
@@ -996,10 +996,9 @@ test("a side pane and the Workspace panel take turns: whichever was asked for la
await workspace.click();
await expect(workspace).toHaveAttribute("aria-expanded", "true");
await expect(dock(page)).toBeHidden();
- // Collapsed, not unmounted — that is what lets the width animate rather than pop, and it
- // is why the shell's view survives the swap. (Raw selector: the collapsed pane is inert,
- // which the dock() helper deliberately filters out.)
- await expect(page.locator('[data-testid="terminal-dock"]')).toHaveCount(1);
+ // The pane closes rather than parking behind the panel; it lingers just long enough to
+ // collapse (useLingeringSlot) and then unmounts, so there is no steady state to assert
+ // here beyond its absence — the shell it was showing is checked below.
// Same slot, same width: the panel opens exactly as wide as the pane it displaced
// (use-panel-width.ts is one value for all three side surfaces). Polled — the open is
@@ -1026,9 +1025,15 @@ test("a side pane and the Workspace panel take turns: whichever was asked for la
const { terminals } = await (await page.request.get(`${BASE}/api/terminals`)).json();
expect(terminals.filter((t) => t.alive)).toHaveLength(1);
- // Closing it gives the pane back, on the same edge, with its screen intact.
+ // Closing the panel leaves the slot EMPTY. Opening the panel is what the user saw close
+ // the terminal, so closing the panel must not conjure it back.
await workspace.click();
await expect(workspace).toHaveAttribute("aria-expanded", "false");
+ await expect(dock(page)).toBeHidden();
+
+ // Asking for it again brings it back on the edge it was on, with its screen intact — the
+ // arrangement survived, only the showing of it did not.
+ await page.keyboard.press("Control+Backquote");
await expect(dock(page)).toBeVisible({ timeout: 10000 });
await expect(dock(page)).toHaveAttribute("data-position", "right");
await expect(page.locator('[data-testid="terminal-dock"][data-status="ready"]')).toBeVisible({
@@ -1036,10 +1041,42 @@ test("a side pane and the Workspace panel take turns: whichever was asked for la
});
await expect.poll(() => dockScreenText(page), { timeout: 15000 }).toContain("SIDE_SWAP_MARKER");
- // And the other direction: asking for the terminal retracts the panel.
+ // And the other direction: asking for the terminal retracts an open panel.
await workspace.click();
await expect(dock(page)).toBeHidden();
await page.keyboard.press("Control+Backquote");
await expect(dock(page)).toBeVisible({ timeout: 10000 });
await expect(workspace).toHaveAttribute("aria-expanded", "false");
});
+
+test("the dock stays with its conversation, not with the user's browsing", async ({ page }) => {
+ await provisionAndLogin(page.request, U, P);
+ const projectId = await configureProjectModel(page.request);
+ await killAllTerminals(page.request);
+ const sessionId = await createSession(page.request, projectId);
+
+ await page.goto(`${BASE}/chat/${sessionId}`);
+ await expect(page.locator('[data-testid="panels-toolbar"]')).toBeVisible({ timeout: 20000 });
+ await page.keyboard.press("Control+Backquote");
+ await expect(dock(page)).toBeVisible({ timeout: 10000 });
+ await waitForDockShell(page, "AWAY_SHELL_UP");
+ await runInDock(page, "echo AWAY_MARKER");
+ await expect.poll(() => dockScreenText(page), { timeout: 15000 }).toContain("AWAY_MARKER");
+
+ // A page with no conversation of its own: a shell has no business beside it. The shell
+ // keeps running — this is about where it is shown, not whether it lives.
+ await page.locator('aside a[href="/agents"]').first().click();
+ await expect(page).toHaveURL(/\/agents$/);
+ await expect(dock(page)).toBeHidden();
+ const { terminals } = await (await page.request.get(`${BASE}/api/terminals`)).json();
+ expect(terminals.filter((t) => t.alive)).toHaveLength(1);
+
+ // Back on the conversation, it is there again with its screen intact.
+ await page.goBack();
+ await expect(page).toHaveURL(new RegExp(`/chat/${sessionId}$`));
+ await expect(dock(page)).toBeVisible({ timeout: 10000 });
+ await expect(page.locator('[data-testid="terminal-dock"][data-status="ready"]')).toBeVisible({
+ timeout: 20000,
+ });
+ await expect.poll(() => dockScreenText(page), { timeout: 15000 }).toContain("AWAY_MARKER");
+});
diff --git a/packages/web/src/components/layout/app-layout.tsx b/packages/web/src/components/layout/app-layout.tsx
index bc82df0c..bed4ce0e 100644
--- a/packages/web/src/components/layout/app-layout.tsx
+++ b/packages/web/src/components/layout/app-layout.tsx
@@ -216,7 +216,11 @@ export function AppLayout() {
// dock flashes on the incoming one.
const dockScope = useMatch("/chat/:sessionId")?.params.sessionId ?? null;
useLayoutEffect(() => {
- if (dockScope !== null) setDockScope(dockScope);
+ // null off a conversation, which is a scope with no arrangement — so the dock is not on
+ // screen there. A terminal belongs to the conversation it was opened in; carrying it
+ // into Agents or user management puts a shell beside a page that has nothing to do with
+ // it. Coming back to the conversation restores it, because only the scope changed.
+ setDockScope(dockScope);
}, [dockScope]);
// Any dock-state change (panes opening/closing/moving) re-renders the slots below.
useSyncExternalStore(subscribeTerminalDock, dockStateVersion);
diff --git a/packages/web/src/features/terminal/terminal-dock-state.ts b/packages/web/src/features/terminal/terminal-dock-state.ts
index 6d2d976e..b962f710 100644
--- a/packages/web/src/features/terminal/terminal-dock-state.ts
+++ b/packages/web/src/features/terminal/terminal-dock-state.ts
@@ -10,10 +10,11 @@
* switches the whole dock with it — a Session that never opened a terminal shows none, and
* coming back restores the panes and tabs that were there. The shells themselves are
* per-user and keep running regardless; a scope only decides which of them are on screen
- * here. Pages with no Session of their own (settings, Agents, …) keep the last one's dock
- * rather than blanking it, since navigating to a settings page is not leaving the
- * conversation; and a dock opened before any conversation was chosen is handed to the
- * first one that is (see setDockScope).
+ * here. Pages with no Session of their own (settings, Agents, …) scope to a placeholder
+ * that holds no arrangement, so the dock is not on screen there — a terminal belongs to a
+ * conversation, not beside a settings page — and returning to the conversation restores it.
+ * A dock opened while on that placeholder is handed to the first conversation chosen
+ * afterwards (see setDockScope).
*
* A side pane and the chat's Agents/Workspace panel both want the horizontal half of the
* content area, so only one of them is on screen: whichever the user opened last. That is
@@ -308,21 +309,32 @@ export function openPanes(): DockPosition[] {
}
/**
- * A chat side panel (Agents / Workspace) is on screen, displacing this dock's left and
- * right panes. Not persisted: it mirrors panel state that is itself per-visit, and a reload
- * with no panel open should show the panes again.
+ * A chat side panel (Agents / Workspace) holds the side. Not persisted: it mirrors panel
+ * state that is itself per-visit.
+ *
+ * Taking the side CLOSES a side pane rather than parking it behind the panel. The pane
+ * stays in the arrangement, so reopening the dock brings it back on the edge it was on —
+ * but closing the panel leaves the slot empty, because from where the user sits, opening
+ * the panel is what closed the terminal, and closing the panel should not conjure it back.
*/
-let sidePanelDisplacing = false;
+let sidePanelHoldsTheSide = false;
/** Whether a chat side panel currently holds the side. */
export function chatSidePanelOpen(): boolean {
- return sidePanelDisplacing;
+ return sidePanelHoldsTheSide;
}
export function setChatSidePanelOpen(open: boolean): void {
- if (open) cancelHandover(); // the panel is back: nothing left to hand over
- if (sidePanelDisplacing === open) return;
- sidePanelDisplacing = open;
+ if (open) {
+ cancelHandover(); // the panel is back: nothing left to hand over
+ // Only a side pane competes for this space; a top/bottom one costs height and stays.
+ if (visible && panes.some((p) => !isHorizontal(p))) {
+ visible = false;
+ persist();
+ }
+ }
+ if (sidePanelHoldsTheSide === open) return;
+ sidePanelHoldsTheSide = open;
notify();
}
@@ -358,8 +370,8 @@ function cancelHandover(): void {
* expanding into a slot that is still occupied.
*/
function terminalTakesTheSide(): void {
- if (!sidePanelDisplacing) return;
- sidePanelDisplacing = false; // the chat page reads this and retracts its panels
+ if (!sidePanelHoldsTheSide) return;
+ sidePanelHoldsTheSide = false; // the chat page reads this and retracts its panels
handingOver = true;
if (handoverTimer !== null) clearTimeout(handoverTimer);
handoverTimer = setTimeout(() => {
@@ -371,9 +383,13 @@ function terminalTakesTheSide(): void {
let visibleSnapshot: DockPosition[] = [];
-/** Panes to actually render: the arrangement minus what a chat side panel is displacing. */
+/**
+ * Panes to actually render: the arrangement, minus a side pane still waiting out an
+ * outgoing panel's retraction (see handingOver). Nothing else is ever filtered — a panel
+ * taking the side closes the pane outright rather than parking it.
+ */
export function visiblePanes(): DockPosition[] {
- const next = sidePanelDisplacing || handingOver ? panes.filter(isHorizontal) : panes;
+ const next = handingOver ? panes.filter(isHorizontal) : panes;
if (next.length === panes.length) return panes; // nothing displaced: keep the stable ref
if (next.length !== visibleSnapshot.length || next.some((p, i) => p !== visibleSnapshot[i])) {
visibleSnapshot = next;
diff --git a/packages/web/test/terminal-dock-scope.test.ts b/packages/web/test/terminal-dock-scope.test.ts
index eacc6d1a..2a381706 100644
--- a/packages/web/test/terminal-dock-scope.test.ts
+++ b/packages/web/test/terminal-dock-scope.test.ts
@@ -135,18 +135,22 @@ describe("the scope-less dock", () => {
});
describe("the side, shared with the chat panels", () => {
- it("displaces left and right panes while a panel holds it, and gives them back", () => {
+ it("closes a side pane when a panel takes the side, and closing the panel leaves it closed", () => {
dock.setDockScope("session-side");
dock.assignTerminalToPane("term-right", "right");
- expect(dock.visiblePanes()).toEqual(["right"]);
+ expect(dock.isTerminalDockOpen()).toBe(true);
dock.setChatSidePanelOpen(true);
- expect(dock.visiblePanes()).toEqual([]);
- // Displaced, not closed: the arrangement still holds it, which is what lets it return.
+ expect(dock.isTerminalDockOpen()).toBe(false);
+ // Closed, not parked behind the panel: closing the panel must not conjure it back,
+ // because opening the panel is what the user saw close the terminal.
+ dock.setChatSidePanelOpen(false);
+ expect(dock.isTerminalDockOpen()).toBe(false);
+
+ // The arrangement survives, so reopening returns it to the edge it was on.
expect(dock.openPanes()).toEqual(["right"]);
expect(dock.paneOfTerminal("term-right")).toBe("right");
-
- dock.setChatSidePanelOpen(false);
+ dock.setTerminalDockOpen(true);
expect(dock.visiblePanes()).toEqual(["right"]);
});
@@ -154,9 +158,29 @@ describe("the side, shared with the chat panels", () => {
dock.setDockScope("session-bottom");
dock.assignTerminalToPane("term-bottom", "bottom");
dock.setChatSidePanelOpen(true);
+ expect(dock.isTerminalDockOpen()).toBe(true);
expect(dock.visiblePanes()).toEqual(["bottom"]);
});
+ it("is not on screen away from a conversation, and comes back on return", () => {
+ dock.setChatSidePanelOpen(false); // no panel holding the side, so no handover to wait out
+ dock.setDockScope("session-away");
+ dock.assignTerminalToPane("term-away", "right");
+ expect(dock.isTerminalDockOpen()).toBe(true);
+
+ // Agents, user management, settings: no Session, so the placeholder scope. Asserted on
+ // this conversation's pane rather than on the dock as a whole — the placeholder can hold
+ // an arrangement of its own (a terminal opened while on one of those pages), and what
+ // matters is that the conversation's does not follow the user there.
+ dock.setDockScope(null);
+ expect(dock.paneOfTerminal("term-away")).toBeNull();
+ expect(dock.openPanes()).not.toContain("right");
+
+ dock.setDockScope("session-away");
+ expect(dock.isTerminalDockOpen()).toBe(true);
+ expect(dock.paneOfTerminal("term-away")).toBe("right");
+ });
+
it("hands the side back the moment a terminal is put on screen", async () => {
vi.useFakeTimers();
try {
@@ -190,8 +214,9 @@ describe("the side, shared with the chat panels", () => {
dock.setChatSidePanelOpen(true); // …and the user reopens the panel mid-retraction
vi.advanceTimersByTime(200);
- // The handover's timer must not fire the pane back on: the panel holds the side now.
- expect(dock.visiblePanes()).toEqual([]);
+ // The handover's timer must not fire the pane back on: the panel holds the side now,
+ // which closed the pane again on its way in.
+ expect(dock.isTerminalDockOpen()).toBe(false);
expect(dock.chatSidePanelOpen()).toBe(true);
} finally {
vi.useRealTimers();