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.
Python agent-orchestrationai-agentai-coding-assistantclaude-codecoding-agentcomputer-usedesktop-applocal-firstmcppersonal-jarvisvoice-assistantvoice-coding
fix(agentic-ide): make the wizard preview show the layout it will really open
Ruben Lütkeac4cea18b110
diff --git a/jarvis/ui/web/frontend/src/views/AgenticIdeView.test.tsx b/jarvis/ui/web/frontend/src/views/AgenticIdeView.test.tsxindex 70184f7056..f778ea2c67 100644--- a/jarvis/ui/web/frontend/src/views/AgenticIdeView.test.tsx+++ b/jarvis/ui/web/frontend/src/views/AgenticIdeView.test.tsx@@ -192,6 +192,106 @@ describe("Agentic IDE wizard", () => {expect(await screen.findByTestId("pane-Mika")).toBeTruthy();});+ /**+ * Drive the wizard to the count step with a workspace of ``width`` pixels,+ * choose ``n`` through a preset or Custom Terminals, and return its dot grid.+ */+ async function countTile(width: number, n: string): Promise<HTMLElement> {+ const previous = globalThis.ResizeObserver;+ class WidthObserver {+ constructor(private readonly callback: ResizeObserverCallback) {}+ observe(): void {+ this.callback(+ [{ contentRect: { width } } as ResizeObserverEntry],+ this as unknown as ResizeObserver,+ );+ }+ unobserve(): void {}+ disconnect(): void {}+ }+ globalThis.ResizeObserver = WidthObserver as unknown as typeof ResizeObserver;+ try {+ render(<AgenticIdeView />);+ await waitFor(() => expect(api.fetchIdeAgents).toHaveBeenCalled());+ fireEvent.click(await screen.findByRole("button", { name: /project/i }));+ fireEvent.click(screen.getByRole("button", { name: /next/i }));+ const preset = screen.queryByRole("button", { name: n });+ if (preset) return preset.querySelector("div") as HTMLElement;++ fireEvent.click(screen.getByRole("button", { name: /custom terminals/i }));+ fireEvent.change(screen.getByRole("spinbutton", { name: /custom terminal count/i }), {+ target: { value: n },+ });+ return screen.getByTestId("custom-terminal-preview");+ } finally {+ globalThis.ResizeObserver = previous;+ }+ }++ /** The number of columns promised by a preview dot grid. */+ const dotsOf = (grid: HTMLElement) => grid.style.gridTemplateColumns;++ it("keeps uncommon counts in Custom Terminals instead of fixed cards", async () => {+ await countTile(2328, "10");++ expect(screen.queryByRole("button", { name: "10" })).toBeNull();+ expect(screen.queryByRole("button", { name: "12" })).toBeNull();+ expect(screen.getByRole("button", { name: /custom terminals/i })).toBeTruthy();+ expect(+ (screen.getByRole("spinbutton", {+ name: /custom terminal count/i,+ }) as HTMLInputElement).value,+ ).toBe("10");+ });++ it("builds the requested number of custom terminal plans", async () => {+ render(<AgenticIdeView />);+ await waitFor(() => expect(api.fetchIdeAgents).toHaveBeenCalled());+ fireEvent.click(await screen.findByRole("button", { name: /project/i }));+ fireEvent.click(screen.getByRole("button", { name: /next/i }));+ fireEvent.click(screen.getByRole("button", { name: /custom terminals/i }));+ fireEvent.change(screen.getByRole("spinbutton", { name: /custom terminal count/i }), {+ target: { value: "10" },+ });+ fireEvent.click(screen.getByRole("button", { name: /next/i }));++ expect(screen.getByLabelText("Call-sign for terminal 10")).toBeTruthy();+ });++ it("caps custom terminal counts at the backend limit", async () => {+ await countTile(2328, "99");++ expect(+ (screen.getByRole("spinbutton", {+ name: /custom terminal count/i,+ }) as HTMLInputElement).value,+ ).toBe("12");+ expect(+ (screen.getByRole("button", { name: /use one more terminal/i }) as HTMLButtonElement)+ .disabled,+ ).toBe(true);+ });++ it("previews 12 terminals as 6 and 6 when the window is wide enough", async () => {+ // 2328 px of workspace minus the grid's padding fits six 380 px panes, so+ // the twelve wrap into two even bands — the arrangement the user asked for.+ const tile = await countTile(2328, "12");+ expect(dotsOf(tile)).toBe("repeat(6, minmax(0, 1fr))");+ });++ it("previews the narrower arrangement a narrow window will really produce", async () => {+ // The same twelve in a 1314 px workspace: only three panes stay readable+ // per line, so the grid makes 3 × 4. The preview promised 6 + 6 here once,+ // which is the drift this test exists to catch.+ const tile = await countTile(1314, "12");+ expect(dotsOf(tile)).toBe("repeat(3, minmax(0, 1fr))");+ });++ it("keeps a small workspace on one line at any usable width", async () => {+ const tile = await countTile(1314, "3");+ expect(dotsOf(tile)).toBe("repeat(3, minmax(0, 1fr))");+ });+it("says so plainly when the machine has no terminal backend", async () => {vi.mocked(api.fetchIdeAgents).mockResolvedValue({...AGENTS,@@ -294,4 +394,38 @@ describe("Agentic IDE running workspace", () => {expect(pushToast).toHaveBeenCalledWith("error", "Mika is not running right now"),);});+ it("shows panes that voice opened, without a reload", async () => {+ /*+ * The regression this guards: a spoken "spawn three more terminals" adds the+ * panes in the backend, but this view fetches its state once on mount. Before+ * 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,+ });+ 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,+ });+ window.dispatchEvent(+ new CustomEvent("jarvis:agentic-ide-changed", {+ detail: { names: ["Aria"], agent: "claude" },+ }),+ );++ await screen.findByTestId("pane-Aria");+ // The panes that were already mounted stay mounted: re-parenting one would+ // tear down its WebSocket and kill the agent behind it.+ expect(screen.getByTestId("pane-Mika")).toBeTruthy();+ });});diff --git a/jarvis/ui/web/frontend/src/views/AgenticIdeView.tsx b/jarvis/ui/web/frontend/src/views/AgenticIdeView.tsxindex df8c3cb7e6..15508d03b2 100644--- a/jarvis/ui/web/frontend/src/views/AgenticIdeView.tsx+++ b/jarvis/ui/web/frontend/src/views/AgenticIdeView.tsx@@ -26,6 +26,8 @@ import {FolderOpen,Loader2,Mic,+ Minus,+ Plus,Rocket,Sparkles,Terminal,@@ -35,7 +37,7 @@ import { useEventStore } from "@/store/events";import { cn } from "@/lib/utils";import { useT } from "@/i18n";import { AgenticGrid } from "@/components/agentic/AgenticGrid";-import { paneColumns } from "@/components/agentic/layout";+import { bandCapacityFor, paneColumns } from "@/components/agentic/layout";import { FolderPicker } from "@/components/agentic/FolderPicker";import {endIdeSession,@@ -55,9 +57,12 @@ interface PlannedTerminal {name: string;}-// Offered up to the backend's cap, so the busiest workspace the app supports is-// one click away rather than eleven splits.-const COUNT_CHOICES = [1, 2, 3, 4, 6, 8, 10, 12] as const;+// Common layouts stay one click away. Less common counts belong in the custom+// selector instead of widening this row with a card for every possible value.+const COUNT_CHOICES = [1, 2, 3, 4, 6, 8] as const;++/** The grid's own horizontal padding (`p-3`), which the preview must discount. */+const GRID_PADDING_PX = 24;/*** Terminal plan for ``count`` panes, preserving whatever the user already chose@@ -98,6 +103,7 @@ export function AgenticIdeView() {const [step, setStep] = useState<Step>(0);const [folder, setFolder] = useState<string | null>(null);const [count, setCount] = useState(2);+ const [customCountSelected, setCustomCountSelected] = useState(false);const [planned, setPlanned] = useState<PlannedTerminal[]>([]);const refresh = useCallback(async () => {@@ -117,6 +123,22 @@ export function AgenticIdeView() {void refresh();}, [refresh]);+ /*+ * Panes can appear without this view asking for them.+ *+ * Saying "spawn five more Claude Code terminals" adds them in the backend; the+ * grid below renders whatever the last fetch returned, so without this listener+ * the panes exist, their agents are told to start — and the user sees nothing.+ * The event carries the new call-signs, but they are deliberately ignored here:+ * re-fetching keeps ONE source of truth for the layout instead of patching the+ * session object from a payload that could be a step behind.+ */+ useEffect(() => {+ const onChanged = () => void refresh();+ window.addEventListener("jarvis:agentic-ide-changed", onChanged);+ return () => window.removeEventListener("jarvis:agentic-ide-changed", onChanged);+ }, [refresh]);+/** Being in this section IS the coding mode.*@@ -134,6 +156,39 @@ export function AgenticIdeView() {const optedOutRef = useRef(false);const [modeIntroFor, setModeIntroFor] = useState<string | null>(null);+ /*+ * How wide the workspace will be — measured here, in the wizard, because the+ * preview dots must promise the arrangement the grid will actually produce.+ *+ * The grid decides its band width from its own width (a pane below+ * MIN_PANE_WIDTH_PX is unreadable), so a preview computing columns from the+ * count alone drifts apart from it the moment the window is narrow: it drew+ * "12 → 6 above, 6 below" while the grid, in the same window, produced three+ * columns and four rows. The wizard shell sits in the same slot the grid will+ * occupy, so measuring it here answers the same question.+ */+ const shellRef = useRef<HTMLDivElement | null>(null);+ const [shellWidth, setShellWidth] = useState(0);+ useEffect(() => {+ const node = shellRef.current;+ if (!node || typeof ResizeObserver === "undefined") return;+ setShellWidth(node.clientWidth);+ const observer = new ResizeObserver((entries) => {+ const width = entries[0]?.contentRect.width ?? node.clientWidth;+ // Same 16 px step the grid rounds to, so both sides flip at one width.+ setShellWidth(Math.round(width / 16) * 16);+ });+ observer.observe(node);+ return () => observer.disconnect();+ }, [session]);++ // The grid pads itself by 12 px on each side; without that the preview would+ // promise one column more than fits at the boundary.+ const previewPerBand = useMemo(+ () => bandCapacityFor(Math.max(0, shellWidth - GRID_PADDING_PX)),+ [shellWidth],+ );+useEffect(() => {if (!session || session.focus_mode || optedOutRef.current) return;let cancelled = false;@@ -160,6 +215,7 @@ export function AgenticIdeView() {const suggested = useMemo(() => meta?.suggested_names ?? [], [meta]);const installed = useMemo(() => agents.filter((a) => a.installed), [agents]);const defaultAgent = installed[0]?.name ?? "claude";+ const maxTerminals = meta?.max_terminals ?? 12;// What the grid's split menus offer. Uninstalled CLIs stay in the list but// disabled, so their absence is visible rather than silently missing.@@ -173,9 +229,11 @@ export function AgenticIdeView() {[agents],);- const chooseCount = (n: number) => {- setCount(n);- setPlanned((prev) => buildPlan(n, prev, defaultAgent, suggested));+ const chooseCount = (n: number, custom = false) => {+ const next = Math.max(1, Math.min(maxTerminals, Math.trunc(n)));+ setCustomCountSelected(custom);+ setCount(next);+ setPlanned((prev) => buildPlan(next, prev, defaultAgent, suggested));};const replayRecent = (recent: {@@ -183,8 +241,9 @@ export function AgenticIdeView() {terminals: number;agents: Record<string, number>;}) => {- const total = Math.max(1, Math.min(recent.terminals, meta?.max_terminals ?? 12));+ const total = Math.max(1, Math.min(recent.terminals, maxTerminals));setCount(total);+ setCustomCountSelected(!COUNT_CHOICES.some((choice) => choice === total));const entries = Object.entries(recent.agents ?? {}).filter(([, n]) => n > 0);if (entries.length === 0) {setPlanned(buildPlan(total, [], defaultAgent, suggested));@@ -267,7 +326,7 @@ export function AgenticIdeView() {onToggleFocus={(v) => void toggleFocus(v)}onClose={() => void close()}busy={busy}- maxTerminals={meta?.max_terminals ?? 12}+ maxTerminals={maxTerminals}agents={splitChoices}onSessionChanged={setSession}/>@@ -292,7 +351,7 @@ export function AgenticIdeView() {(step === 2 && planned.every((p) => p.name.trim() && p.agent));return (- <div className="flex h-full flex-col">+ <div className="flex h-full flex-col" ref={shellRef}><ViewHeadericon={<Sparkles className="h-4 w-4 text-primary" />}title={t("nav.agentic_ide") === "nav.agentic_ide" ? "Agentic IDE" : t("nav.agentic_ide")}@@ -352,25 +411,31 @@ export function AgenticIdeView() {title="How many terminals?"hint="Each terminal runs its own agent. The dots show how they will sit — side by side, wrapping onto a second line once there are too many to stay readable.">- <div className="grid grid-cols-4 gap-3 sm:grid-cols-8">- {COUNT_CHOICES.filter((n) => n <= (meta?.max_terminals ?? 12)).map((n) => (+ <div className="grid grid-cols-3 gap-3 sm:grid-cols-6">+ {COUNT_CHOICES.filter((n) => n <= maxTerminals).map((n) => (<buttonkey={n}type="button"- aria-pressed={count === n}+ aria-pressed={!customCountSelected && count === n}onClick={() => chooseCount(n)}className={cn("flex aspect-square flex-col items-center justify-center gap-2 rounded-xl border p-3 transition-colors",- count === n+ !customCountSelected && count === n? "border-primary/50 bg-primary/5": "border-border bg-card/60 hover:border-primary/30",)}>- <DotGrid n={n} active={count === n} />+ <DotGrid+ n={n}+ perBand={previewPerBand}+ active={!customCountSelected && count === n}+ /><spanclassName={cn("text-sm font-semibold",- count === n ? "text-primary" : "text-foreground",+ !customCountSelected && count === n+ ? "text-primary"+ : "text-foreground",)}>{n}@@ -378,6 +443,75 @@ export function AgenticIdeView() {</button>))}</div>++ <div+ className={cn(+ "flex flex-wrap items-center gap-4 rounded-xl border bg-card/60 p-4 transition-colors",+ customCountSelected+ ? "border-primary/50 bg-primary/5"+ : "border-border hover:border-primary/30",+ )}+ >+ <button+ type="button"+ aria-pressed={customCountSelected}+ onClick={() => chooseCount(count, true)}+ className="flex min-w-0 flex-1 items-center gap-3 text-left"+ >+ <span className="flex h-10 w-10 shrink-0 items-center justify-center rounded-lg border border-border bg-background/60">+ <DotGrid+ n={count}+ perBand={previewPerBand}+ active={customCountSelected}+ testId="custom-terminal-preview"+ />+ </span>+ <span className="min-w-0">+ <span className="block text-sm font-semibold">Custom Terminals</span>+ <span className="block text-xs text-muted-foreground">+ Choose any number from 1 to {maxTerminals}.+ </span>+ </span>+ </button>++ <div className="flex shrink-0 items-center gap-1 rounded-lg border border-border bg-background/60 p-1">+ <button+ type="button"+ aria-label="Use one fewer terminal"+ disabled={count <= 1}+ onClick={() => chooseCount(count - 1, true)}+ className="flex h-8 w-8 items-center justify-center rounded-md text-muted-foreground hover:bg-muted hover:text-foreground disabled:cursor-not-allowed disabled:opacity-40"+ >+ <Minus className="h-4 w-4" />+ </button>+ <input+ type="number"+ min={1}+ max={maxTerminals}+ value={count}+ aria-label="Custom terminal count"+ onFocus={() => chooseCount(count, true)}+ onChange={(event) =>+ chooseCount(+ Number.isFinite(event.currentTarget.valueAsNumber)+ ? event.currentTarget.valueAsNumber+ : 1,+ true,+ )+ }+ className="h-8 w-14 rounded-md border border-border bg-background text-center font-mono text-sm font-semibold outline-none focus:border-primary/60"+ />+ <button+ type="button"+ aria-label="Use one more terminal"+ disabled={count >= maxTerminals}+ onClick={() => chooseCount(count + 1, true)}+ className="flex h-8 w-8 items-center justify-center rounded-md text-muted-foreground hover:bg-muted hover:text-foreground disabled:cursor-not-allowed disabled:opacity-40"+ >+ <Plus className="h-4 w-4" />+ </button>+ </div>+ </div></Section>)}@@ -697,16 +831,30 @@ function AgentChoice({/*** The arrangement ``n`` terminals will actually open in.*- * The column count comes from the same function the running grid lays itself- * out with — it used to have its own (three per line), so choosing 4 previewed- * 3 above and 1 below and then opened 4 side by side. A preview is only worth- * showing while it cannot disagree with the real thing.+ * Both numbers behind this come from the grid itself: `perBand` is what fits in+ * the measured width, and `paneColumns` is the function the grid lays itself out+ * with. The preview used to have its own formula (three per line), so choosing 4+ * previewed 3 above and 1 below and then opened 4 side by side; then it dropped+ * the width and promised 6 + 6 where a narrow window gave three columns and four+ * rows. A preview is only worth showing while it cannot disagree with the real+ * thing, and that means sharing every input, not just the function.*/-function DotGrid({ n, active }: { n: number; active: boolean }) {- const cols = Math.max(1, paneColumns(n));+function DotGrid({+ n,+ perBand,+ active,+ testId,+}: {+ n: number;+ perBand: number;+ active: boolean;+ testId?: string;+}) {+ const cols = Math.max(1, paneColumns(n, perBand));const tight = cols > 6;return (<div+ data-testid={testId}className={cn("grid", tight ? "gap-0.5" : "gap-1")}style={{ gridTemplateColumns: `repeat(${cols}, minmax(0, 1fr))` }}>