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.

fix(agentic-ide): activate new chat panes before connect

rubenluetke10-beepf714406b2fb0
diff --git a/jarvis/ui/web/frontend/src/components/agentic/AgenticGrid.test.tsx b/jarvis/ui/web/frontend/src/components/agentic/AgenticGrid.test.tsx
index 36af928190..b4a35313df 100644
--- a/jarvis/ui/web/frontend/src/components/agentic/AgenticGrid.test.tsx
+++ b/jarvis/ui/web/frontend/src/components/agentic/AgenticGrid.test.tsx
@@ -24,7 +24,10 @@ if (typeof globalThis.ResizeObserver === "undefined") {
* Through `vi.hoisted` because `vi.mock` factories are lifted above ordinary
* module code and would otherwise reach a `const` that does not exist yet.
*/
-const { paneRenders } = vi.hoisted(() => ({ paneRenders: new Map<string, number>() }));
+const { paneRenders, paneActiveHistory } = vi.hoisted(() => ({
+ paneRenders: new Map<string, number>(),
+ paneActiveHistory: new Map<string, boolean[]>(),
+}));
const pushToast = vi.fn();
vi.mock("@/store/events", () => ({
@@ -129,6 +132,7 @@ vi.mock("./AgenticTerminal", () => ({
arranging,
layoutBusy,
fontSize,
+ active,
}: {
name: string;
maximized?: boolean;
@@ -146,8 +150,13 @@ vi.mock("./AgenticTerminal", () => ({
arranging?: boolean;
layoutBusy?: boolean;
fontSize?: number;
+ active?: boolean;
}) => {
paneRenders.set(name, (paneRenders.get(name) ?? 0) + 1);
+ paneActiveHistory.set(name, [
+ ...(paneActiveHistory.get(name) ?? []),
+ active ?? true,
+ ]);
return (
<div
data-testid={`pane-${name}`}
@@ -163,6 +172,7 @@ vi.mock("./AgenticTerminal", () => ({
// The real pane stops refitting its terminal while this is on. Read here
// because it is the grid's job to say WHEN the geometry is in motion.
data-layout-busy={layoutBusy ? "yes" : "no"}
+ data-active={active ? "yes" : "no"}
// The size the terminal text is drawn at. Read here because the point of
// remembering it is that the PANES come back at that size.
data-font-size={String(fontSize ?? "")}
@@ -287,6 +297,7 @@ beforeEach(() => {
// hand its sizes to the next one and the layout assertions would depend on
// the order the tests happen to run in.
window.localStorage.clear();
+ paneActiveHistory.clear();
window.localStorage.setItem("jarvis.agenticIde.composerHeight.v2", "176");
vi.mocked(api.addTerminal).mockResolvedValue(
sessionWith([
@@ -2655,6 +2666,29 @@ describe("chat view", () => {
expect(cellClass("Mika")).toContain("hidden");
});
+ it("activates an externally added pane on its first chat-stage render", () => {
+ const { rerender } = renderGrid(FOUR);
+ toChat();
+ paneActiveHistory.clear();
+
+ rerender({
+ session: sessionWith([
+ ["Mika", 0],
+ ["Nova", 1],
+ ["Aria", 2],
+ ["Kai", 3],
+ ["Fresh", 4],
+ ]),
+ });
+
+ // Connecting once while inactive gives the PTY the narrow hidden-grid
+ // geometry. The pane must own the full stage before its first effect runs.
+ expect(paneActiveHistory.get("Fresh")?.[0]).toBe(true);
+ expect(screen.getByTestId("pane-Fresh").getAttribute("data-active")).toBe(
+ "yes",
+ );
+ });
+
it("swaps two rail positions by dragging without moving or remounting the panes", async () => {
renderGrid(FOUR);
const paneBefore = screen.getByTestId("pane-Mika");
diff --git a/jarvis/ui/web/frontend/src/components/agentic/AgenticGrid.tsx b/jarvis/ui/web/frontend/src/components/agentic/AgenticGrid.tsx
index 8345447b90..679086ba19 100644
--- a/jarvis/ui/web/frontend/src/components/agentic/AgenticGrid.tsx
+++ b/jarvis/ui/web/frontend/src/components/agentic/AgenticGrid.tsx
@@ -791,6 +791,12 @@ export function AgenticGrid({
* effects, so a pane closed by another client simply falls back.
*/
const [chatPane, setChatPane] = useState<string | null>(null);
+ // Null until the first render has been seen: on mount every pane is "new",
+ // and announcing a restored workspace's eight panes would be a light show.
+ // Kept beside the stage selection because a newly arrived pane must be
+ // selected during render, before its terminal's connection effect measures
+ // the otherwise-hidden grid cell.
+ const knownPanes = useRef<Set<string> | null>(null);
const [chatOrder, setChatOrder] = useState<{
workspaceId: string;
keys: readonly string[];
@@ -1461,13 +1467,29 @@ export function AgenticGrid({
setChatOrder({ workspaceId: session.id, keys: stableChatKeys });
}, [chatOrder, session.id, stableChatKeys]);
- /** The pane on the chat stage: the chosen one while it lives, else a fallback. */
+ /*
+ * A pane can arrive through voice, the CLI, or another client. Effects run
+ * after child effects, which is too late to put that pane on the chat stage:
+ * its terminal would already have connected from a hidden, grid-sized cell
+ * and handed the PTY a tiny column count. Derive the arrival synchronously so
+ * the new terminal's first measurement is the full stage.
+ */
+ const knownBeforeRender = knownPanes.current;
+ const arrivingChatPane =
+ chatView && knownBeforeRender !== null
+ ? (session.terminals
+ .filter((term) => !knownBeforeRender.has(term.name))
+ .at(-1)?.name ?? null)
+ : null;
+
+ /** The pane on the chat stage: the newest arrival, chosen pane, then fallback. */
const chatSelected = useMemo(() => {
const names = session.terminals.map((term) => term.name);
+ if (arrivingChatPane && names.includes(arrivingChatPane)) return arrivingChatPane;
if (chatPane && names.includes(chatPane)) return chatPane;
if (target && names.includes(target)) return target;
return names[0] ?? null;
- }, [chatPane, target, session.terminals]);
+ }, [arrivingChatPane, chatPane, target, session.terminals]);
// The browser is the only layer that knows which pane fills the one-pane
// chat stage. Hand that fact to the backend so voice and chat can resolve
@@ -1672,9 +1694,6 @@ export function AgenticGrid({
* expires on its own — a permanent marker would become furniture.
*/
const [justOpened, setJustOpened] = useState<Set<string>>(() => new Set());
- // Null until the first render has been seen: on mount every pane is "new",
- // and announcing a restored workspace's eight panes would be a light show.
- const knownPanes = useRef<Set<string> | null>(null);
useEffect(() => {
const names = session.terminals.map((term) => term.name);
const known = knownPanes.current;