Skip to content

Dodaios is an open-source agent OS for your desktop: it runs your coding agents, browser and apps by voice or chat, on your own machine. Formerly Personal Jarvis.

feat(agentic-ide): a workspace bar to switch between open folders

Ruben Lütke7e3dce654c1c
diff --git a/jarvis/ui/web/frontend/src/components/agentic/AgenticGrid.tsx b/jarvis/ui/web/frontend/src/components/agentic/AgenticGrid.tsx
index 91bf2116a7..7f44ef13a0 100644
--- a/jarvis/ui/web/frontend/src/components/agentic/AgenticGrid.tsx
+++ b/jarvis/ui/web/frontend/src/components/agentic/AgenticGrid.tsx
@@ -527,6 +527,7 @@ export function AgenticGrid({
>
<AgenticTerminal
name={term.name}
+ workspaceId={session.id}
displayName={term.display_name}
appearance={appearance}
fontSize={fontSize}
diff --git a/jarvis/ui/web/frontend/src/components/agentic/WorkspaceBar.tsx b/jarvis/ui/web/frontend/src/components/agentic/WorkspaceBar.tsx
new file mode 100644
index 0000000000..085b55cd0f
--- /dev/null
+++ b/jarvis/ui/web/frontend/src/components/agentic/WorkspaceBar.tsx
@@ -0,0 +1,221 @@
+/**
+ * The row of open workspaces above the Agentic IDE, and the button that adds
+ * another one.
+ *
+ * A workspace is a folder with its own running coding agents. Several can be
+ * open at once, and switching between them costs nothing: the agents in the one
+ * you leave keep working, and the one you come back to reconnects to the
+ * processes that were running the whole time.
+ *
+ * Two things the tabs have to say out loud, because the alternative is a user
+ * guessing:
+ *
+ * * **how many agents are alive in there.** A workspace you are not looking at
+ * is still working (and still spending), so the count is the thing that keeps
+ * "it runs until you close it" honest rather than hidden.
+ * * **which one is on screen.** With the panes of only one workspace visible at
+ * a time, an unmarked bar would make the grid look like it belongs to
+ * whichever tab the eye landed on.
+ *
+ * Closing is deliberately a two-step: the X reveals a confirm, because it is the
+ * one control in this bar that stops work — every other one is reversible.
+ */
+import { useState } from "react";
+import { FolderGit2, Plus, X } from "lucide-react";
+import { cn } from "@/lib/utils";
+import type { WorkspaceCard } from "@/lib/agenticIdeApi";
+
+interface WorkspaceBarProps {
+ workspaces: WorkspaceCard[];
+ /** Id of the workspace on screen, or null while the wizard is showing. */
+ activeId: string | null;
+ /** True while the wizard is open for an ADDITIONAL workspace. */
+ addingNew: boolean;
+ maxWorkspaces: number;
+ onSelect: (id: string) => void;
+ onAdd: () => void;
+ onClose: (id: string) => void;
+ /** Disable every control while a switch or a close is in flight. */
+ busy?: boolean;
+}
+
+export function WorkspaceBar({
+ workspaces,
+ activeId,
+ addingNew,
+ maxWorkspaces,
+ onSelect,
+ onAdd,
+ onClose,
+ busy = false,
+}: WorkspaceBarProps) {
+ // Which tab has its close button armed. One at a time, and cleared on every
+ // other interaction, so an armed X can never be clicked by accident later.
+ const [confirming, setConfirming] = useState<string | null>(null);
+ const full = workspaces.length >= maxWorkspaces;
+
+ // Nothing open and nothing to add to: the wizard IS the screen, and an empty
+ // bar above it would be furniture.
+ if (workspaces.length === 0) return null;
+
+ return (
+ <div
+ data-testid="workspace-bar"
+ className="flex items-center gap-1 overflow-x-auto border-b border-border px-3 py-1.5 scrollbar-jarvis"
+ role="tablist"
+ aria-label="Open workspaces"
+ >
+ {workspaces.map((workspace) => {
+ const selected = !addingNew && workspace.id === activeId;
+ const armed = confirming === workspace.id;
+ return (
+ <div
+ key={workspace.id}
+ className={cn(
+ "group/tab flex shrink-0 items-center gap-2 rounded-lg border px-3 py-1.5 transition-colors",
+ selected
+ ? "border-primary/50 bg-primary/10"
+ : "border-transparent hover:border-border hover:bg-muted/40",
+ )}
+ >
+ <button
+ type="button"
+ role="tab"
+ aria-selected={selected}
+ disabled={busy}
+ data-testid={`workspace-tab-${workspace.id}`}
+ title={workspace.folder}
+ onClick={() => {
+ setConfirming(null);
+ if (!selected) onSelect(workspace.id);
+ }}
+ className="flex min-w-0 items-center gap-2 text-left disabled:cursor-not-allowed disabled:opacity-60"
+ >
+ <FolderGit2
+ className={cn(
+ "h-3.5 w-3.5 shrink-0",
+ selected ? "text-primary" : "text-muted-foreground",
+ )}
+ />
+ <span
+ className={cn(
+ "max-w-[14rem] truncate text-sm font-medium",
+ selected ? "text-primary" : "text-foreground",
+ )}
+ >
+ {workspace.name}
+ </span>
+ <PaneCount workspace={workspace} selected={selected} />
+ </button>
+
+ {armed ? (
+ <span className="flex items-center gap-1">
+ <button
+ type="button"
+ disabled={busy}
+ data-testid={`workspace-close-confirm-${workspace.id}`}
+ onClick={() => {
+ setConfirming(null);
+ onClose(workspace.id);
+ }}
+ className="rounded bg-destructive/20 px-2 py-0.5 text-[11px] font-medium text-destructive transition-colors hover:bg-destructive/30 disabled:opacity-50"
+ >
+ Stop {workspace.live_terminals || workspace.terminals}
+ </button>
+ <button
+ type="button"
+ aria-label="Keep this workspace open"
+ onClick={() => setConfirming(null)}
+ className="rounded px-1.5 py-0.5 text-[11px] text-muted-foreground hover:text-foreground"
+ >
+ Keep
+ </button>
+ </span>
+ ) : (
+ <button
+ type="button"
+ aria-label={`Close ${workspace.name}`}
+ title={`Close ${workspace.name} and stop its agents`}
+ disabled={busy}
+ data-testid={`workspace-close-${workspace.id}`}
+ onClick={() => setConfirming(workspace.id)}
+ className={cn(
+ "flex h-5 w-5 items-center justify-center rounded text-muted-foreground transition-opacity hover:bg-destructive/20 hover:text-destructive",
+ selected
+ ? "opacity-100"
+ : "opacity-0 focus-visible:opacity-100 group-hover/tab:opacity-100",
+ )}
+ >
+ <X className="h-3 w-3" />
+ </button>
+ )}
+ </div>
+ );
+ })}
+
+ <button
+ type="button"
+ role="tab"
+ aria-selected={addingNew}
+ disabled={busy || full}
+ data-testid="workspace-add"
+ title={
+ full
+ ? `${maxWorkspaces} workspaces are already open — close one first.`
+ : "Open another folder in its own workspace"
+ }
+ onClick={() => {
+ setConfirming(null);
+ onAdd();
+ }}
+ className={cn(
+ "flex shrink-0 items-center gap-1.5 rounded-lg border px-3 py-1.5 text-sm transition-colors disabled:cursor-not-allowed disabled:opacity-40",
+ addingNew
+ ? "border-primary/50 bg-primary/10 text-primary"
+ : "border-dashed border-border text-muted-foreground hover:border-primary/40 hover:text-foreground",
+ )}
+ >
+ <Plus className="h-3.5 w-3.5" />
+ New workspace
+ </button>
+ </div>
+ );
+}
+
+/**
+ * "3" when every pane is running, "1/3" when they are not.
+ *
+ * The split form only appears when it carries information. A tab that always
+ * read "3/3" would train the eye to skip the number, and the number is the
+ * whole point on a workspace nobody is watching.
+ */
+function PaneCount({
+ workspace,
+ selected,
+}: {
+ workspace: WorkspaceCard;
+ selected: boolean;
+}) {
+ const allLive = workspace.live_terminals === workspace.terminals;
+ const label = allLive
+ ? String(workspace.terminals)
+ : `${workspace.live_terminals}/${workspace.terminals}`;
+ return (
+ <span
+ data-testid={`workspace-panes-${workspace.id}`}
+ title={
+ allLive
+ ? `${workspace.terminals} agent${workspace.terminals === 1 ? "" : "s"} running`
+ : `${workspace.live_terminals} of ${workspace.terminals} agents running`
+ }
+ className={cn(
+ "shrink-0 rounded px-1.5 py-0.5 font-mono text-[10px]",
+ selected
+ ? "bg-primary/20 text-primary"
+ : "bg-muted text-muted-foreground",
+ )}
+ >
+ {label}
+ </span>
+ );
+}
diff --git a/jarvis/ui/web/frontend/src/lib/agenticIdeApi.ts b/jarvis/ui/web/frontend/src/lib/agenticIdeApi.ts
index 471e9af5bf..af51e83855 100644
--- a/jarvis/ui/web/frontend/src/lib/agenticIdeApi.ts
+++ b/jarvis/ui/web/frontend/src/lib/agenticIdeApi.ts
@@ -106,10 +106,37 @@ export interface SessionState {
terminals: TerminalState[];
}
+/**
+ * One open workspace, as the workspace bar shows it.
+ *
+ * Deliberately not a whole `SessionState`: the bar renders a name and a couple
+ * of numbers, and carrying six full project profiles plus every pane's
+ * transcript statistics to do that would make every poll expensive.
+ */
+export interface WorkspaceCard {
+ id: string;
+ folder: string;
+ /** Project name — what the tab is labelled with. */
+ name: string;
+ branch: string | null;
+ terminals: number;
+ /** Panes whose agent is running right now — a background tab's honest count. */
+ live_terminals: number;
+ focus_mode: boolean;
+ created_at: number;
+ last_active_at: number;
+ active: boolean;
+}
+
export interface IdeState {
active: boolean;
session: SessionState | null;
max_terminals: number;
+ /** Every open workspace, in tab order. */
+ workspaces: WorkspaceCard[];
+ /** The one on screen, or null while the wizard is showing. */
+ active_id: string | null;
+ max_workspaces: number;
}
/** One pane of the workspace being offered back after a close or a restart. */
@@ -203,6 +230,46 @@ export async function forgetRecent(path: string): Promise<void> {
if (!res.ok) throw new Error(await detail(res));
}
+export interface NativePickerSupport {
+ available: boolean;
+ backend?: string | null;
+ reason?: string | null;
+}
+
+export interface NativePickResult {
+ path?: string | null;
+ cancelled?: boolean;
+ error?: string | null;
+}
+
+/**
+ * Whether this machine can show the operating system's own folder window.
+ *
+ * Asked before the button is offered rather than after it is pressed: the
+ * window opens where the SERVER runs, so from a phone or another laptop it
+ * would appear on a screen nobody is watching. A `false` here always comes with
+ * a `reason` worth showing.
+ */
+export function fetchNativePickerSupport(): Promise<NativePickerSupport> {
+ return getJson<NativePickerSupport>("/api/agentic-ide/folders/native");
+}
+
+/**
+ * Open the system folder window and wait for an answer.
+ *
+ * The request stays open for as long as the window does — that is the point,
+ * not a hang. Cancelling comes back as `cancelled`, never as an error.
+ */
+export async function openNativePicker(start?: string | null): Promise<NativePickResult> {
+ const res = await fetch("/api/agentic-ide/folders/native", {
+ method: "POST",
+ headers: { "Content-Type": "application/json" },
+ body: JSON.stringify({ start: start ?? null }),
+ });
+ if (!res.ok) throw new Error(await detail(res));
+ return (await res.json()) as NativePickResult;
+}
+
/**
* Turn a drag-and-drop payload into a folder path.
*
@@ -224,25 +291,90 @@ export async function resolveDroppedFolder(payload: {
return (await res.json()) as ResolveResponse;
}
+/**
+ * Open `folder` as another workspace and return the state that results.
+ *
+ * The whole state, not just the new session: opening ADDS a workspace, so the
+ * bar changes too, and answering with both means the view never has to re-read
+ * to find out what it just did. A second fetch would also be a race — it can
+ * return a snapshot from before the open and blank the workspace that was just
+ * created.
+ */
export async function startIdeSession(
folder: string,
terminals: TerminalPlan[],
-): Promise<SessionState> {
+): Promise<IdeState> {
const res = await fetch("/api/agentic-ide/session", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ folder, terminals }),
});
if (!res.ok) throw new Error(await detail(res));
- const body = (await res.json()) as { session: SessionState };
- return body.session;
-}
+ const body = (await res.json()) as { session: SessionState; state: IdeState };
+ // `state` is authoritative; `session` alone is kept as the fallback for a
+ // backend that predates the workspace bar.
+ return body.state ?? { ...EMPTY_IDE_STATE, active: true, session: body.session };
+}
+
+/** Shape a pre-workspace-bar backend does not send. */
+const EMPTY_IDE_STATE: IdeState = {
+ active: false,
+ session: null,
+ max_terminals: 12,
+ workspaces: [],
+ active_id: null,
+ max_workspaces: 6,
+};
export async function endIdeSession(): Promise<void> {
const res = await fetch("/api/agentic-ide/session", { method: "DELETE" });
if (!res.ok) throw new Error(await detail(res));
}
+export interface WorkspacesResponse {
+ workspaces: WorkspaceCard[];
+ active_id: string | null;
+ max_workspaces: number;
+}
+
+/** Every open workspace, in tab order, with the front one marked. */
+export function fetchWorkspaces(): Promise<WorkspacesResponse> {
+ return getJson<WorkspacesResponse>("/api/agentic-ide/workspaces");
+}
+
+/**
+ * Bring one workspace to the front, or clear the front entirely.
+ *
+ * Nothing starts, stops or restarts — the agents in every open workspace keep
+ * working and the one that comes forward reconnects to the processes that were
+ * running all along.
+ *
+ * `null` means "show no workspace": the state the view is in while the wizard
+ * opens an ADDITIONAL one. It has to be sent BEFORE the outgoing panes unmount,
+ * which is why it is awaited rather than fired off — see AgenticIdeView.
+ */
+export async function activateWorkspace(id: string | null): Promise<IdeState> {
+ const res = await fetch("/api/agentic-ide/workspaces/active", {
+ method: "PUT",
+ headers: { "Content-Type": "application/json" },
+ body: JSON.stringify({ id }),
+ });
+ if (!res.ok) throw new Error(await detail(res));
+ const body = (await res.json()) as { state: IdeState };
+ return body.state;
+}
+
+/** Close ONE workspace and stop every agent in it. Returns the state that is left. */
+export async function closeWorkspace(id: string): Promise<IdeState> {
+ const res = await fetch(
+ `/api/agentic-ide/workspaces/${encodeURIComponent(id)}`,
+ { method: "DELETE" },
+ );
+ if (!res.ok) throw new Error(await detail(res));
+ const body = (await res.json()) as { state: IdeState };
+ return body.state;
+}
+
/** What reopening the last workspace would bring back, checked against this machine. */
export function fetchResumeOffer(): Promise<ResumeOffer> {
return getJson<ResumeOffer>("/api/agentic-ide/resume");
diff --git a/jarvis/ui/web/frontend/src/views/AgenticIdeView.test.tsx b/jarvis/ui/web/frontend/src/views/AgenticIdeView.test.tsx
index 3ef7a6bc77..865fa7633d 100644
--- a/jarvis/ui/web/frontend/src/views/AgenticIdeView.test.tsx
+++ b/jarvis/ui/web/frontend/src/views/AgenticIdeView.test.tsx
@@ -57,6 +57,11 @@ vi.mock("@/lib/agenticIdeApi", () => ({
fetchResumeOffer: vi.fn(),
resumeWorkspace: vi.fn(),
forgetResumeOffer: vi.fn(),
+ fetchWorkspaces: vi.fn(),
+ activateWorkspace: vi.fn(),
+ closeWorkspace: vi.fn(),
+ fetchNativePickerSupport: vi.fn(),
+ openNativePicker: vi.fn(),
}));
import { AgenticIdeView } from "./AgenticIdeView";
@@ -84,7 +89,45 @@ const AGENTS: api.AgentsResponse = {
],
};
-const EMPTY_STATE: api.IdeState = { active: false, session: null, max_terminals: 12 };
+const EMPTY_STATE: api.IdeState = {
+ active: false,
+ session: null,
+ max_terminals: 12,
+ workspaces: [],
+ active_id: null,
+ max_workspaces: 6,
+};
+
+/**
+ * The state the backend returns with one workspace open.
+ *
+ * Derives the workspace bar from the session rather than letting a test spell
+ * both out, so a fixture can never describe a front workspace that is not in
+ * the bar — a shape the backend cannot produce and a test should not either.
+ */
+function stateWith(session: api.SessionState): api.IdeState {
+ return {
+ active: true,
+ session,
+ max_terminals: 12,
+ workspaces: [
+ {
+ id: session.id,
+ folder: session.folder,
+ name: session.project.name,
+ branch: session.project.branch,
+ terminals: session.terminals.length,
+ live_terminals: session.terminals.filter((t) => t.status === "live").length,
+ focus_mode: session.focus_mode,
+ created_at: session.created_at,
+ last_active_at: session.created_at,
+ active: true,
+ },
+ ],
+ active_id: session.id,
+ max_workspaces: 6,
+ };
+}
const NO_OFFER: api.ResumeOffer = {
available: false,
@@ -194,6 +237,11 @@ beforeEach(() => {
});
// Nothing to resume by default; the resume tests override this.
vi.mocked(api.fetchResumeOffer).mockResolvedValue(NO_OFFER);
+ // No system folder window in jsdom — the picker falls back to browsing.
+ vi.mocked(api.fetchNativePickerSupport).mockResolvedValue({
+ available: false,
+ reason: "not available under test",
+ });
});
afterEach(() => {
@@ -214,7 +262,7 @@ describe("Agentic IDE wizard", () => {
});
it("walks folder → count → agents → start and opens the workspace", async () => {
- vi.mocked(api.startIdeSession).mockResolvedValue(sessionWith(["Mika", "Nova"]));
+ vi.mocked(api.startIdeSession).mockResolvedValue(stateWith(sessionWith(["Mika", "Nova"])));
render(<AgenticIdeView />);
await waitFor(() => expect(api.fetchIdeAgents).toHaveBeenCalled());
@@ -364,22 +412,14 @@ describe("Agentic IDE wizard", () => {
describe("Agentic IDE running workspace", () => {
it("renders the open session instead of the wizard", async () => {
- vi.mocked(api.fetchIdeState).mockResolvedValue({
- active: true,
- session: sessionWith(["Mika"]),
- max_terminals: 12,
- });
+ vi.mocked(api.fetchIdeState).mockResolvedValue(stateWith(sessionWith(["Mika"])));
render(<AgenticIdeView />);
expect(await screen.findByTestId("pane-Mika")).toBeTruthy();
expect(screen.queryByRole("button", { name: /next/i })).toBeNull();
});
it("toggles focus mode through the API, not just locally", async () => {
- vi.mocked(api.fetchIdeState).mockResolvedValue({
- active: true,
- session: sessionWith(["Mika"]),
- max_terminals: 12,
- });
+ vi.mocked(api.fetchIdeState).mockResolvedValue(stateWith(sessionWith(["Mika"])));
vi.mocked(api.setFocusMode).mockResolvedValue(true);
render(<AgenticIdeView />);
@@ -399,11 +439,7 @@ describe("Agentic IDE running workspace", () => {
});
it("sends a prompt to the selected terminal through the same endpoint voice uses", async () => {
- vi.mocked(api.fetchIdeState).mockResolvedValue({
- active: true,
- session: sessionWith(["Mika", "Nova"]),
- max_terminals: 12,
- });
+ vi.mocked(api.fetchIdeState).mockResolvedValue(stateWith(sessionWith(["Mika", "Nova"])));
vi.mocked(api.promptTerminal).mockResolvedValue({
terminal: "Mika",
sent: "run the tests",
@@ -424,11 +460,7 @@ describe("Agentic IDE running workspace", () => {
});
it("reports a refused prompt instead of pretending it landed", async () => {
- vi.mocked(api.fetchIdeState).mockResolvedValue({
- active: true,
- session: sessionWith(["Mika"]),
- max_terminals: 12,
- });
+ vi.mocked(api.fetchIdeState).mockResolvedValue(stateWith(sessionWith(["Mika"])));
vi.mocked(api.promptTerminal).mockRejectedValue(
new Error("Mika is not running right now"),
);
@@ -451,22 +483,14 @@ describe("Agentic IDE running workspace", () => {
* the listener existed, the agents were running and the user saw the old grid
* — the feature looked broken while working perfectly.
*/
- vi.mocked(api.fetchIdeState).mockResolvedValue({
- active: true,
- session: sessionWith(["Mika", "Nova"]),
- max_terminals: 12,
- });
+ vi.mocked(api.fetchIdeState).mockResolvedValue(stateWith(sessionWith(["Mika", "Nova"])));
render(<AgenticIdeView />);
await screen.findByTestId("pane-Mika");
expect(screen.queryByTestId("pane-Aria")).toBeNull();
// Voice opened a third pane; the WebSocket layer turns the bus event into
// this window event.
- vi.mocked(api.fetchIdeState).mockResolvedValue({
- active: true,
- session: sessionWith(["Mika", "Nova", "Aria"]),
- max_terminals: 12,
- });
+ vi.mocked(api.fetchIdeState).mockResolvedValue(stateWith(sessionWith(["Mika", "Nova", "Aria"])));
window.dispatchEvent(
new CustomEvent("jarvis:agentic-ide-changed", {
detail: { names: ["Aria"], agent: "claude" },
@@ -498,11 +522,7 @@ describe("AgenticIdeView — resuming the last workspace", () => {
});
it("does not offer a resume while a workspace is open", async () => {
- vi.mocked(api.fetchIdeState).mockResolvedValue({
- active: true,
- session: sessionWith(["Mika"]),
- max_terminals: 12,
- });
+ vi.mocked(api.fetchIdeState).mockResolvedValue(stateWith(sessionWith(["Mika"])));
vi.mocked(api.fetchResumeOffer).mockResolvedValue(PREVIOUS_WORKSPACE);
render(<AgenticIdeView />);
@@ -543,3 +563,122 @@ describe("AgenticIdeView — resuming the last workspace", () => {
expect(screen.queryByTestId("resume-card")).toBeNull();
});
});
+
+/*
+ * The workspace bar.
+ *
+ * What these defend is the promise the bar makes by existing: several
+ * workspaces are open at once, and moving between them costs nothing. The
+ * ordering assertions are the important ones — the backend has to be told the
+ * front workspace changed BEFORE the outgoing panes unmount, because a pane
+ * that disappears while its workspace is still the front one is indistinguishable
+ * from a close.
+ */
+function twoWorkspaces(): api.IdeState {
+ const front = sessionWith(["Mika"]);
+ const base = stateWith(front);
+ return {
+ ...base,
+ workspaces: [
+ {
+ id: "ide_other",
+ folder: "/work/api",
+ name: "api",
+ branch: "main",
+ terminals: 3,
+ live_terminals: 2,
+ focus_mode: false,
+ created_at: 0,
+ last_active_at: 0,
+ active: false,
+ },
+ ...base.workspaces,
+ ],
+ };
+}
+
+describe("AgenticIdeView — the workspace bar", () => {
+ it("lists every open workspace and marks the one on screen", async () => {
+ vi.mocked(api.fetchIdeState).mockResolvedValue(twoWorkspaces());
+ render(<AgenticIdeView />);
+
+ await screen.findByTestId("workspace-bar");
+ const other = screen.getByTestId("workspace-tab-ide_other");
+ const front = screen.getByTestId("workspace-tab-ide_test");
+ expect(other.getAttribute("aria-selected")).toBe("false");
+ expect(front.getAttribute("aria-selected")).toBe("true");
+ // A background workspace says how many of its agents are still running —
+ // that is what keeps "it runs until you close it" honest.
+ expect(screen.getByTestId("workspace-panes-ide_other").textContent).toBe("2/3");
+ });
+
+ it("stays hidden while nothing is open", async () => {
+ render(<AgenticIdeView />);
+ await screen.findByText("Folder");
+ expect(screen.queryByTestId("workspace-bar")).toBeNull();
+ });
+
+ it("switches to another workspace through the API", async () => {
+ vi.mocked(api.fetchIdeState).mockResolvedValue(twoWorkspaces());
+ const other = sessionWith(["Kai"]);
+ other.id = "ide_other";
+ vi.mocked(api.activateWorkspace).mockResolvedValue(stateWith(other));
+ render(<AgenticIdeView />);
+
+ fireEvent.click(await screen.findByTestId("workspace-tab-ide_other"));
+
+ await waitFor(() => expect(api.activateWorkspace).toHaveBeenCalledWith("ide_other"));
+ await screen.findByTestId("pane-Kai");
+ // Switching is not closing: nothing was ended.
+ expect(api.endIdeSession).not.toHaveBeenCalled();
+ expect(api.closeWorkspace).not.toHaveBeenCalled();
+ });
+
+ it("clears the front workspace before showing the wizard for a new one", async () => {
+ vi.mocked(api.fetchIdeState).mockResolvedValue(twoWorkspaces());
+ vi.mocked(api.activateWorkspace).mockResolvedValue({
+ ...twoWorkspaces(),
+ session: null,
+ active_id: null,
+ active: false,
+ });
+ render(<AgenticIdeView />);
+
+ fireEvent.click(await screen.findByTestId("workspace-add"));
+
+ // null, not a close: the workspaces stay open with their agents running.
+ await waitFor(() => expect(api.activateWorkspace).toHaveBeenCalledWith(null));
+ expect(api.closeWorkspace).not.toHaveBeenCalled();
+ expect(api.endIdeSession).not.toHaveBeenCalled();
+ // The wizard is showing, and the bar still lists both workspaces.
+ await screen.findByText("Folder");
+ expect(screen.getByTestId("workspace-tab-ide_other")).toBeTruthy();
+ expect(screen.getByTestId("workspace-tab-ide_test")).toBeTruthy();
+ });
+
+ it("asks before closing a workspace, then closes only that one", async () => {
+ vi.mocked(api.fetchIdeState).mockResolvedValue(twoWorkspaces());
+ const left = stateWith(sessionWith(["Mika"]));
+ vi.mocked(api.closeWorkspace).mockResolvedValue(left);
+ render(<AgenticIdeView />);
+
+ fireEvent.click(await screen.findByTestId("workspace-close-ide_other"));
+ // One click arms it; the workspace is still open at this point.
+ expect(api.closeWorkspace).not.toHaveBeenCalled();
+
+ fireEvent.click(screen.getByTestId("workspace-close-confirm-ide_other"));
+ await waitFor(() => expect(api.closeWorkspace).toHaveBeenCalledWith("ide_other"));
+ await waitFor(() =>
+ expect(screen.queryByTestId("workspace-tab-ide_other")).toBeNull(),
+ );
+ });
+
+ it("refuses to add one past the cap", async () => {
+ const full = twoWorkspaces();
+ vi.mocked(api.fetchIdeState).mockResolvedValue({ ...full, max_workspaces: 2 });
+ render(<AgenticIdeView />);
+
+ const add = (await screen.findByTestId("workspace-add")) as HTMLButtonElement;
+ expect(add.disabled).toBe(true);
+ });
+});
diff --git a/jarvis/ui/web/frontend/src/views/AgenticIdeView.tsx b/jarvis/ui/web/frontend/src/views/AgenticIdeView.tsx
index 916a0571fe..19485b6a63 100644
--- a/jarvis/ui/web/frontend/src/views/AgenticIdeView.tsx
+++ b/jarvis/ui/web/frontend/src/views/AgenticIdeView.tsx
@@ -43,7 +43,10 @@ import {
} from "@/components/agentic/layout";
import { FolderPicker } from "@/components/agentic/FolderPicker";
import { ResumeCard } from "@/components/agentic/ResumeCard";
+import { WorkspaceBar } from "@/components/agentic/WorkspaceBar";
import {
+ activateWorkspace,
+ closeWorkspace,
endIdeSession,
fetchIdeAgents,
fetchIdeState,
@@ -54,8 +57,10 @@ import {
startIdeSession,
type AgentStatus,
type AgentsResponse,
+ type IdeState,
type ResumeOffer,
type SessionState,
+ type WorkspaceCard,
} from "@/lib/agenticIdeApi";
type Step = 0 | 1 | 2 | 3;
@@ -105,6 +110,22 @@ export function AgenticIdeView() {
const [focusMode, setFocus] = useState(false);
const [busy, setBusy] = useState(false);
+ // Every open workspace, for the bar above. The one on screen is `session`;
+ // these are the others, still running, one click away.
+ const [workspaces, setWorkspaces] = useState<WorkspaceCard[]>([]);
+ const [maxWorkspaces, setMaxWorkspaces] = useState(6);
+ /*
+ * The wizard is showing for an ADDITIONAL workspace.
+ *
+ * Kept as its own flag rather than inferred from `session === null`, because
+ * the two mean different things once several workspaces exist: no session can
+ * also be "everything was closed", and the bar has to know whether the +
+ * button is the selected tab. Pressing + clears the front on the BACKEND too
+ * (see `startAdding`), which is what stops the outgoing panes from being read
+ * as a close.
+ */
+ const [addingNew, setAddingNew] = useState(false);
+
const [step, setStep] = useState<Step>(0);
const [folder, setFolder] = useState<string | null>(null);
const [count, setCount] = useState(2);
@@ -120,11 +141,18 @@ export function AgenticIdeView() {
const [state, agents] = await Promise.all([fetchIdeState(), fetchIdeAgents()]);
setMeta(agents);
setSession(state.session);
+ setWorkspaces(state.workspaces ?? []);
+ setMaxWorkspaces(state.max_workspaces ?? 6);
setFocus(Boolean(state.session?.focus_mode));
- // Only worth asking about when there is no workspace on screen. With one
- // open, the panes reconnect and continue by themselves — the offer is for
- // the case where the workspace itself did not survive.
- if (state.session === null) {
+ // The backend is the authority on whether a workspace is on screen. It
+ // says so by carrying one in `session`, so a fetch that finds one ends
+ // the "adding" state — otherwise a workspace opened in another tab (or
+ // by voice) would come up behind a wizard nobody asked for.
+ if (state.session !== null) setAddingNew(false);
+ // Only worth asking about when NOTHING is open. With a workspace around,
+ // its panes reconnect and continue by themselves — the offer is for the
+ // case where the workspaces themselves did not survive.
+ if ((state.workspaces ?? []).length === 0) {
try {
const previous = await fetchResumeOffer();
setOffer(previous.terminals.length > 0 ? previous : null);
@@ -141,6 +169,14 @@ export function AgenticIdeView() {
}
}, []);
+ /** Apply a state the backend just handed back, without a second round-trip. */
+ const applyState = useCallback((state: IdeState) => {
+ setSession(state.session);
+ setWorkspaces(state.workspaces ?? []);
+ setMaxWorkspaces(state.max_workspaces ?? 6);
+ setFocus(Boolean(state.session?.focus_mode));
+ }, []);
+
useEffect(() => {
void refresh();
}, [refresh]);
@@ -299,13 +335,17 @@ export function AgenticIdeView() {
if (!folder) return;
setBusy(true);
try {
- const created = await startIdeSession(folder, planned);
- setSession(created);
- setFocus(created.focus_mode);
- pushToast(
- "success",
- `Workspace open — ${created.terminals.map((x) => x.name).join(", ")}`,
- );
+ // The open answers with the whole state — the new workspace AND the bar.
+ // Re-fetching instead would be a race that can blank what was just opened.
+ const next = await startIdeSession(folder, planned);
+ applyState(next);
+ setAddingNew(false);
+ // The wizard is reusable — someone who opens a third workspace should not
+ // land on the leftovers of the second one's plan.
+ setStep(0);
+ setFolder(null);
+ const names = next.session?.terminals.map((x) => x.name).join(", ") ?? "";
+ pushToast("success", `Workspace open — ${names}`);
} catch (e) {
pushToast("error", (e as Error).message);
} finally {
@@ -317,12 +357,61 @@ export function AgenticIdeView() {
setBusy(true);
try {
await endIdeSession();
- setSession(null);
setFocus(false);
setStep(0);
// Closing on purpose withdraws the offer, so the wizard comes back clean
// rather than immediately proposing the workspace just shut down.
setOffer(null);
+ // Whatever is still open takes the front; only a full refresh knows what
+ // that is, so the view asks rather than guessing it is now empty.
+ await refresh();
+ } catch (e) {
+ pushToast("error", (e as Error).message);
+ } finally {
+ setBusy(false);
+ }
+ };
+
+ /*
+ * ------------------------------------------------------------ workspace bar
+ *
+ * All three actions share one rule, and it is the whole reason they are
+ * awaited rather than fired off: **the backend has to know the front workspace
+ * changed BEFORE the outgoing panes come down.**
+ *
+ * A pane that disappears releases its viewer, and the backend decides what
+ * that means from which workspace the pane belongs to. Ordering the state
+ * change after the round-trip keeps that decision correct; doing it the other
+ * way round would tear down panes while their workspace was still the front
+ * one, which is the difference between "switched tab" and "closed".
+ */
+ const switchTo = async (id: string) => {
+ if (busy || (id === session?.id && !addingNew)) return;
+ setBusy(true);
+ try {
+ applyState(await activateWorkspace(id));
+ setAddingNew(false);
+ setOffer(null);
+ } catch (e) {
+ pushToast("error", (e as Error).message);
+ // The tab may have been closed elsewhere — re-read rather than leave a
+ // bar showing a workspace that is not there.
+ void refresh();
+ } finally {
+ setBusy(false);
+ }
+ };
+
+ const startAdding = async () => {
+ if (busy) return;
+ setBusy(true);
+ try {
+ applyState(await activateWorkspace(null));
+ setAddingNew(true);
+ // A fresh plan, not the previous workspace's.
+ setStep(0);
+ setFolder(null);
+ setOffer(null);
} catch (e) {
pushToast("error", (e as Error).message);
} finally {
@@ -330,6 +419,27 @@ export function AgenticIdeView() {
}
};
+ const closeOne = async (id: string) => {
+ if (busy) return;
+ setBusy(true);
+ try {
+ const next = await closeWorkspace(id);
+ applyState(next);
+ if (next.session === null && (next.workspaces ?? []).length === 0) {
+ // Nothing left — the wizard is the screen again, and the offer for the
+ // workspace just shut down has been withdrawn with it.
+ setAddingNew(false);
+ setStep(0);
+ setOffer(null);
+ }
+ } catch (e) {
+ pushToast("error", (e as Error).message);
+ void refresh();
+ } finally {
+ setBusy(false);
+ }
+ };
+
const resumeAll = async () => {
setBusy(true);
try {
@@ -376,20 +486,52 @@ export function AgenticIdeView() {
}
};
+ /*
+ * The workspace bar sits above BOTH states, always in the same place.
+ *
+ * It is the one part of this view that is not about the workspace you are in
+ * — it is about which one you are in — so it stays put whether the grid or
+ * the wizard is below it. A bar that moved (or vanished while adding one)
+ * would leave the user without a way back to the workspaces still running.
+ */
+ const bar = (
+ <WorkspaceBar
+ workspaces={workspaces}
+ activeId={session?.id ?? null}
+ addingNew={addingNew}
+ maxWorkspaces={maxWorkspaces}
+ onSelect={(id) => void switchTo(id)}
+ onAdd={() => void startAdding()}
+ onClose={(id) => void closeOne(id)}
+ busy={busy}
+ />
+ );
+
// ------------------------------------------------------------ running mode
- if (session) {
+ if (session && !addingNew) {
return (
- <>
- <AgenticGrid
- session={session}
- focusMode={focusMode}
- onToggleFocus={(v) => void toggleFocus(v)}
- onClose={() => void close()}
- busy={busy}
- maxTerminals={maxTerminals}
- agents={splitChoices}
- onSessionChanged={setSession}
- />
+ <div className="flex h-full flex-col">
+ {bar}
+ <div className="min-h-0 flex-1">
+ {/*
+ Keyed by workspace, so switching tabs REPLACES the grid instead of
+ re-using it. That is deliberate: each pane's terminal is wired to
+ one call-sign for its whole life, and re-using the component across
+ workspaces would leave xterm instances pointed at the panes of the
+ workspace that just left.
+ */}
+ <AgenticGrid
+ key={session.id}
+ session={session}
+ focusMode={focusMode}
+ onToggleFocus={(v) => void toggleFocus(v)}
+ onClose={() => void close()}
+ busy={busy}
+ maxTerminals={maxTerminals}
+ agents={splitChoices}
+ onSessionChanged={setSession}
+ />
+ </div>
{modeIntroFor === session.id && (
<CodingModeIntro
terminals={session.terminals.map((x) => x.name)}
@@ -400,7 +542,7 @@ export function AgenticIdeView() {
}}
/>
)}
- </>
+ </div>
);
}
@@ -412,10 +554,15 @@ export function AgenticIdeView() {
return (
<div className="flex h-full flex-col" ref={shellRef}>
+ {bar}
<ViewHeader
icon={<Sparkles className="h-4 w-4 text-primary" />}
title={t("nav.agentic_ide") === "nav.agentic_ide" ? "Agentic IDE" : t("nav.agentic_ide")}
- subtitle="Open a folder, run coding agents in named terminals, and talk to them."
+ subtitle={
+ addingNew
+ ? "Open another folder — the workspaces you already have keep running."
+ : "Open a folder, run coding agents in named terminals, and talk to them."
+ }
/>
<div className="flex-1 overflow-y-auto scrollbar-jarvis">