Skip to content

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

fix(composer): isolate task dock tab content

vastsa28d5d07de18f
diff --git a/apps/desktop/src/components/TaskDock.tsx b/apps/desktop/src/components/TaskDock.tsx
index ce5265928..c83f81028 100644
--- a/apps/desktop/src/components/TaskDock.tsx
+++ b/apps/desktop/src/components/TaskDock.tsx
@@ -181,14 +181,14 @@ export function TaskDock({ sessionId }: { sessionId: string }) {
{t(`backgroundTasks.${error === "remove" ? "removeFailed" : `${error}Failed`}`)}
</p>
) : null}
- {hasTodo ? (
+ {hasTodo && tab === "todo" ? (
<TodoPanel
todos={todos}
listId={`${panelId}-todo`}
interactive={!collapsed && tab === "todo"}
/>
) : null}
- {hasTasks ? (
+ {hasTasks && tab === "tasks" ? (
<TaskPanel
listId={`${panelId}-tasks`}
tasks={tasks}
diff --git a/apps/desktop/test/background-tasks-dock-render.test.mjs b/apps/desktop/test/background-tasks-dock-render.test.mjs
index bbeaf5976..99c414044 100644
--- a/apps/desktop/test/background-tasks-dock-render.test.mjs
+++ b/apps/desktop/test/background-tasks-dock-render.test.mjs
@@ -149,3 +149,27 @@ test("a checklist keeps the container without inventing an empty task panel", as
);
});
});
+
+for (const activeTab of ["todo", "tasks"]) {
+ test(`the selected ${activeTab} tab renders only its own panel`, async () => {
+ await withDockRender(({ render }) => {
+ const running = task("t-running", "running");
+ const html = render({
+ tasks: [running],
+ sessionTasks: [running],
+ activeTab,
+ collapsed: false,
+ todos: [{ content: "finish the checklist", status: "completed", priority: "high" }],
+ });
+ assert.match(html, /role="tablist"/);
+ assert.match(html, /1 running/, "the shared header still reports live work");
+ if (activeTab === "todo") {
+ assert.match(html, /class="todo-dock-list"/);
+ assert.doesNotMatch(html, /class="task-list"/, "tasks must not leak into Todo");
+ } else {
+ assert.match(html, /class="task-list"/);
+ assert.doesNotMatch(html, /class="todo-dock-list"/, "todos must not leak into Tasks");
+ }
+ });
+ });
+}
diff --git a/apps/desktop/test/helpers/background-tasks-hook.stub.ts b/apps/desktop/test/helpers/background-tasks-hook.stub.ts
index 4761b9b03..16d749009 100644
--- a/apps/desktop/test/helpers/background-tasks-hook.stub.ts
+++ b/apps/desktop/test/helpers/background-tasks-hook.stub.ts
@@ -15,6 +15,7 @@ export type DockFixture = {
tasks: BackgroundTaskSummary[];
sessionTasks: BackgroundTaskSummary[];
collapsed?: boolean;
+ activeTab?: "todo" | "tasks";
};
declare global {
@@ -27,7 +28,7 @@ export function useBackgroundTasks() {
return {
tasks: fixture.tasks,
sessionTasks: fixture.sessionTasks,
- activeTab: "tasks" as const,
+ activeTab: fixture.activeTab ?? "tasks",
openTasksTab() {},
openTodoTab() {},
collapsed: fixture.collapsed ?? true,
diff --git a/docs/spec/03-runtime/03-tools-and-permissions.md b/docs/spec/03-runtime/03-tools-and-permissions.md
index 146865327..fb938830c 100644
--- a/docs/spec/03-runtime/03-tools-and-permissions.md
+++ b/docs/spec/03-runtime/03-tools-and-permissions.md
@@ -625,7 +625,10 @@ Host execution baseline:
Plan/Ask decision surfaces and the input. The container has a single header
carrying the todo progress summary, the running-task count, the tab list, and
the disclosure control; collapsing hides only the panels, so the tabs stay
- reachable while collapsed. Tabs appear only when both sides have content: with
+ reachable while collapsed. Only the selected tab renders its panel; Todo never
+ includes background-task rows or logs, and Background tasks never includes the
+ checklist. Switching tabs does not stop processes or clear an open log.
+ Tabs appear only when both sides have content: with
one side populated, that panel renders on its own and the tab list is not
rendered at all, and a container with nothing to show renders nothing. The
panel scrolls within `min(200px, 24vh)` so additional rows do not displace the
diff --git a/docs/spec/06-delivery/04-e2e-test-plan.md b/docs/spec/06-delivery/04-e2e-test-plan.md
index 236d21dd2..925b9d92c 100644
--- a/docs/spec/06-delivery/04-e2e-test-plan.md
+++ b/docs/spec/06-delivery/04-e2e-test-plan.md
@@ -1,5 +1,20 @@
# 04. E2E Test Plan
+## E2E-TASK-DOCK-tab-content-isolation
+
+- **Preconditions:** Isolated Electron renderer with synthetic todos and a running
+ task; production TaskDock, hook and store, with only host IPC stubbed.
+- **Steps:** Expand the dock, select Todo, select Background tasks, open its log,
+ switch to Todo and back. Repeat with completed todos.
+- **Expected:** Only the selected panel appears. Todo contains no task rows,
+ Stop control or log; Background tasks contains no checklist. The shared live
+ count remains visible, switching never sends Stop, and the open log survives.
+- **Entry:** `node scripts/e2e-task-dock-tabs.mjs`.
+- **Specs:** `03-runtime/03-tools-and-permissions.md`, shared task container.
+- **Acceptance:** Both switch directions preserve task state and log selection.
+- **Milestone:** Maintenance. **Status:** Automated renderer interaction test.
+
+
## E2E-PROJECT-case-alias-upgrade-and-delete
- Entry: `python scripts/e2e-project-path-case.py <candidate-host>` on native
diff --git a/scripts/e2e-task-dock-tabs.mjs b/scripts/e2e-task-dock-tabs.mjs
new file mode 100644
index 000000000..07b2b86b6
--- /dev/null
+++ b/scripts/e2e-task-dock-tabs.mjs
@@ -0,0 +1,60 @@
+#!/usr/bin/env node
+import assert from "node:assert/strict";
+import { spawn } from "node:child_process";
+import { createRequire } from "node:module";
+import { mkdtemp, readFile, rm, writeFile } from "node:fs/promises";
+import { tmpdir } from "node:os";
+import { join } from "node:path";
+import { repositoryRoot, resolveElectronBinary } from "./e2e/boot.mjs";
+
+const root = repositoryRoot();
+const { build } = createRequire(join(root, "packages/agent-runtime/package.json"))("esbuild");
+const temp = await mkdtemp(join(process.env.PI_SCRATCH_DIR || tmpdir(), "task-dock-tabs-"));
+try {
+ await build({ entryPoints: [join(root, "scripts/e2e/task-dock-tabs.tsx")],
+ outfile: join(temp, "renderer.js"), bundle: true, platform: "browser", format: "iife", jsx: "automatic",
+ define: { "process.env.NODE_ENV": '"production"', "import.meta.env.DEV": "false" },
+ alias: { "@pi-desktop/i18n": join(root, "packages/i18n/src/index.ts"),
+ "@pi-desktop/shared": join(root, "packages/shared/src/index.ts"),
+ react: join(root, "apps/desktop/node_modules/react"),
+ "react-dom": join(root, "apps/desktop/node_modules/react-dom") },
+ nodePaths: [join(root, "apps/desktop/node_modules")],
+ });
+ const styles = await Promise.all(["tokens.css", "composer.css"].map((name) =>
+ readFile(join(root, "apps/desktop/src/styles", name), "utf8")));
+ await writeFile(join(temp, "styles.css"), styles.join("\n"));
+ await writeFile(join(temp, "index.html"), `<!doctype html><html><head><meta charset="utf-8"><meta http-equiv="Content-Security-Policy" content="default-src 'self'; style-src 'self' 'unsafe-inline'"><link rel="stylesheet" href="styles.css"></head><body><div id="root"></div><script src="renderer.js"></script></body></html>`);
+ await writeFile(join(temp, "main.cjs"), `
+const { app, BrowserWindow } = require("electron");
+const { join } = require("node:path");
+app.setPath("userData", join(__dirname, "profile"));
+app.disableHardwareAcceleration();
+app.whenReady().then(async () => {
+ const win = new BrowserWindow({ show: false, webPreferences: {
+ sandbox: true, contextIsolation: true, nodeIntegration: false, backgroundThrottling: false } });
+ try {
+ await win.loadFile(join(__dirname, "index.html"));
+ const result = await win.webContents.executeJavaScript("globalThis.taskDockTabsProbe()");
+ console.log("TASK_DOCK_TABS " + JSON.stringify(result));
+ app.exit(result.ok ? 0 : 1);
+ } catch (error) { console.error(error); app.exit(1); }
+}).catch(error => { console.error(error); app.exit(1); });
+`);
+ const env = { ...process.env };
+ delete env.ELECTRON_RUN_AS_NODE;
+ const { electronBinary } = resolveElectronBinary(root);
+ const child = spawn(electronBinary, [join(temp, "main.cjs")], { env, stdio: ["ignore", "pipe", "pipe"] });
+ let output = "";
+ for (const stream of [child.stdout, child.stderr]) stream.on("data", (chunk) => { output += chunk; });
+ const timer = setTimeout(() => child.kill("SIGKILL"), 30000);
+ let code;
+ try {
+ code = await new Promise((resolve, reject) => {
+ child.once("error", reject);
+ child.once("close", resolve);
+ });
+ } finally { clearTimeout(timer); }
+ assert.equal(code, 0, output);
+ assert.match(output, /TASK_DOCK_TABS .*"ok":true/);
+ console.log(output.trim());
+} finally { await rm(temp, { recursive: true, force: true }); }
diff --git a/scripts/e2e/task-dock-tabs.tsx b/scripts/e2e/task-dock-tabs.tsx
new file mode 100644
index 000000000..9153bfb25
--- /dev/null
+++ b/scripts/e2e/task-dock-tabs.tsx
@@ -0,0 +1,83 @@
+import { createRoot } from "react-dom/client";
+import { flushSync } from "react-dom";
+import i18n from "i18next";
+import { I18nextProvider } from "react-i18next";
+import { en } from "@pi-desktop/i18n";
+import { IPC } from "@pi-desktop/shared";
+import { TaskDock } from "../../apps/desktop/src/components/TaskDock";
+import { useAppStore } from "../../apps/desktop/src/stores/app-store";
+
+function assert(value: unknown, message: string): asserts value {
+ if (!value) throw new Error(message);
+}
+async function until(predicate: () => boolean, message: string) {
+ const deadline = performance.now() + 5000;
+ while (!predicate()) {
+ assert(performance.now() < deadline, message);
+ await new Promise<void>((resolve) => requestAnimationFrame(() => resolve()));
+ }
+}
+let stops = 0;
+Object.defineProperty(window, "piDesktop", { value: {
+ invoke: async (channel: string) => {
+ let data: unknown;
+ if (channel === IPC.invoke.backgroundTasksList) {
+ data = { tasks: [{ id: "task-1", sessionId: "fixture", command: "fixture-dev-server",
+ commandShellId: "bash", state: "running", elapsedMs: 1000 }], version: 1 };
+ } else if (channel === IPC.invoke.backgroundTasksOutput) {
+ data = { id: "task-1", state: "running", stdout: "fixture log output", stderr: "", truncated: false };
+ } else if (channel === IPC.invoke.todosGet) {
+ data = useAppStore.getState().sessionTodos.fixture;
+ } else if (channel === IPC.invoke.backgroundTasksStop) {
+ stops++;
+ data = { ok: true, found: true };
+ } else throw new Error(`Unexpected fixture IPC: ${channel}`);
+ return { ok: true, data };
+ },
+ on: () => () => {},
+} });
+function select(label: string) {
+ const button = [...document.querySelectorAll<HTMLButtonElement>('[role="tab"]')]
+ .find((element) => element.textContent?.startsWith(label));
+ assert(button, `Missing tab ${label}`);
+ flushSync(() => button.click());
+ assert(button.getAttribute("aria-selected") === "true", `Tab ${label} must be selected`);
+}
+function assertPanel(todo: boolean) {
+ assert(!!document.querySelector(".todo-dock-list") === todo, "Todo panel visibility mismatch");
+ assert(!!document.querySelector(".task-list") === !todo, "Task panel visibility mismatch");
+ assert(!!document.querySelector(".task-action.is-stop") === !todo, "Stop belongs only to Tasks");
+ assert(document.querySelector(".dock-live")?.textContent === "1 running", "Live count must remain");
+}
+async function probe() {
+ await i18n.init({ lng: "en", resources: { en: { translation: en } } });
+ const root = createRoot(document.getElementById("root")!);
+ try {
+ for (const status of ["in_progress", "completed"] as const) {
+ flushSync(() => useAppStore.setState({ sessionTodos: { fixture: {
+ sessionId: "fixture", revision: 1, updatedAt: 1,
+ todos: [{ content: "fixture checklist item", status, priority: "high" }],
+ } } }));
+ flushSync(() => root.render(<I18nextProvider i18n={i18n}><TaskDock sessionId="fixture" /></I18nextProvider>));
+ await until(() => document.querySelectorAll('[role="tab"]').length === 2, "Task tabs must load");
+ select("Todo");
+ assertPanel(true);
+ assert(!document.querySelector(".task-output"), "Todo must not show a log");
+ select("Background tasks");
+ assertPanel(false);
+ const row = document.querySelector<HTMLElement>(".task-main");
+ assert(row, "Task row missing");
+ if (row.getAttribute("aria-expanded") !== "true") flushSync(() => row.click());
+ await until(() => !!document.querySelector("pre")?.textContent?.includes("fixture log output"), "Log must load");
+ select("Todo");
+ assertPanel(true);
+ assert(!document.querySelector("pre"), "Task log must not leak into Todo");
+ select("Background tasks");
+ assertPanel(false);
+ assert(document.querySelector("pre")?.textContent?.includes("fixture log output"), "Open log must survive switching");
+ }
+ assert(stops === 0, "Switching tabs must never stop a task");
+ return { ok: true, scenarios: 2 };
+ } finally { flushSync(() => root.unmount()); }
+}
+Object.assign(globalThis, { taskDockTabsProbe: probe });