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
feat(chat): the chat stage follows an answer that grows past the window
rubenluetke10-beep6581dc7178ac
diff --git a/jarvis/ui/web/frontend/src/components/home/ChatStage.test.tsx b/jarvis/ui/web/frontend/src/components/home/ChatStage.test.tsxindex 0af0fad2d9..890dc88d32 100644--- a/jarvis/ui/web/frontend/src/components/home/ChatStage.test.tsx+++ b/jarvis/ui/web/frontend/src/components/home/ChatStage.test.tsx@@ -112,6 +112,55 @@ function ev(kind: string, payload: Record<string, unknown>): AgentChatEvent {return { seq, ts_ms: 1_000 + seq, kind, payload };}+/**+ * jsdom has no ResizeObserver, and the stage only follows a growing answer+ * where the platform has one. This one records every observer's callback+ * and is fired by hand — "the column just grew" — from the test.+ */+class FakeResizeObserver {+ static callbacks: ResizeObserverCallback[] = [];+ constructor(callback: ResizeObserverCallback) {+ FakeResizeObserver.callbacks.push(callback);+ }+ observe() {}+ unobserve() {}+ disconnect() {}+ static fire() {+ for (const callback of FakeResizeObserver.callbacks) {+ callback([], this as unknown as ResizeObserver);+ }+ }+}+function withResizeObserver() {+ FakeResizeObserver.callbacks = [];+ vi.stubGlobal("ResizeObserver", FakeResizeObserver);+}++/** jsdom lays nothing out, so the scroller is told how tall it "is". */+function measure(el: HTMLElement, scrollTop: number, scrollHeight: number, clientHeight: number) {+ Object.defineProperty(el, "scrollHeight", { value: scrollHeight, configurable: true });+ Object.defineProperty(el, "clientHeight", { value: clientHeight, configurable: true });+ el.scrollTop = scrollTop;+}++/** The Radix viewport the stage scrolls — the element the follow rule listens on. */+function stageViewport(): HTMLElement {+ const viewport = screen+ .getByTestId("chat-stage")+ .querySelector<HTMLElement>("[data-radix-scroll-area-viewport]");+ if (!viewport) throw new Error("the chat stage rendered no scroll viewport");+ return viewport;+}++/** A turn that is under way: the person asked, the agent is answering. */+function runningTurn() {+ return reduceEvents(EMPTY_TIMELINE, [+ ev("user_message", { text: "run the tests" }),+ ev("turn_started", { turn_id: "t1", provider: "claude-api", model: "claude-opus-5", effort: "high", runner: "claude-cli" }),+ ev("assistant_text", { turn_id: "t1", message_id: "m1", text: "Running them now." }),+ ]);+}+describe("ChatStage (agent chat)", () => {let scrollTo: ReturnType<typeof vi.fn>;@@ -134,6 +183,7 @@ describe("ChatStage (agent chat)", () => {});afterEach(() => {cleanup();+ vi.unstubAllGlobals();});it("shows the greeting and the composer with the four picks when there is nothing yet", () => {@@ -176,6 +226,27 @@ describe("ChatStage (agent chat)", () => {expect(screen.getByTestId("chat-folder-headline").textContent).toContain("work");});+ it("keeps the folder chip out of the Jarvis chat and leaves it in the IDE's", () => {+ // The chip belongs to the IDE: a coding agent is pointed at a checkout and+ // has to be movable. On the front page it only showed the leaf of the+ // default path — on Windows the account name, which read like a setting+ // nobody chose (maintainer, 2026-08-25). The folder itself did not go+ // away; a CLI seat still starts in one. It is just no longer a control.+ const { unmount } = render(<ChatStage />);+ expect(screen.getByTestId("composer-surface").getAttribute("data-surface")).toBe("jarvis");+ expect(screen.queryByTestId("composer-folder")).toBeNull();+ unmount();++ useAgentSessionStore.setState(seedState());+ render(+ <AgentChatStoreProvider store={useAgentSessionStore}>+ <ChatStage />+ </AgentChatStoreProvider>,+ );+ expect(screen.getByTestId("composer-surface").getAttribute("data-surface")).toBe("agent");+ expect(screen.getByTestId("composer-folder")).toBeTruthy();+ });+it("bylines a turn with the assistant on the front page and with the coding agent in the IDE", () => {const timeline = reduceEvents(EMPTY_TIMELINE, [ev("user_message", { text: "list the files" }),@@ -392,8 +463,78 @@ describe("ChatStage (agent chat)", () => {fireEvent.click(within(tool).getByRole("button"));expect(tool.textContent).toContain("a.py");expect(within(turn).getByTestId("agent-text").querySelector("strong")?.textContent).toBe("a.py");- // The person's message was pinned to the top of the scroll area.- expect(scrollTo).toHaveBeenCalled();+ });++ it("pins the person's message to the top when it is the newest thing, and keeps it there while the answer fits", () => {+ withResizeObserver();+ useAgentChatStore.setState({+ activeSessionId: "s1",+ timeline: reduceEvents(EMPTY_TIMELINE, [ev("user_message", { text: "run the tests" })]),+ });+ render(<ChatStage />);+ // Sent: the message is brought to the top of the scroll area.+ expect(scrollTo).toHaveBeenCalledWith(expect.objectContaining({ top: 0 }));++ const viewport = stageViewport();+ measure(viewport, 950, 1000, 100);+ act(() => {+ fireEvent.scroll(viewport);+ });+ // The answer starts under it but still fits the window: the spacer gives+ // way (100 px window − 24 px breath = 76 px left) and the view does not+ // move — the message stays on its line.+ act(() => {+ FakeResizeObserver.fire();+ });+ expect(screen.getByTestId("chat-bottom-spacer").style.minHeight).toBe("76px");+ expect(viewport.scrollTop).toBe(950);+ expect(screen.queryByTestId("chat-scroll-end")).toBeNull();+ });++ it("follows an answer that grows past the window while the view is at the end", () => {+ withResizeObserver();+ useAgentChatStore.setState({ activeSessionId: "s1", timeline: runningTurn() });+ render(<ChatStage />);+ const viewport = stageViewport();+ measure(viewport, 950, 1000, 50);+ act(() => {+ fireEvent.scroll(viewport);+ });++ // The reasoning trace grows without a new item — the column gets taller.+ measure(viewport, 950, 2000, 50);+ act(() => {+ FakeResizeObserver.fire();+ });+ expect(viewport.scrollTop).toBe(2000);+ expect(screen.queryByTestId("chat-scroll-end")).toBeNull();+ });++ it("leaves a reader who scrolled up where they are, and offers the way back over the composer", () => {+ withResizeObserver();+ useAgentChatStore.setState({ activeSessionId: "s1", timeline: runningTurn() });+ render(<ChatStage />);+ const viewport = stageViewport();+ measure(viewport, 100, 1000, 50);+ act(() => {+ fireEvent.scroll(viewport);+ });+ expect(screen.getByTestId("chat-scroll-end")).toBeTruthy();++ // The answer keeps growing below; the reader's place is not touched.+ measure(viewport, 100, 2000, 50);+ act(() => {+ FakeResizeObserver.fire();+ });+ expect(viewport.scrollTop).toBe(100);++ // Taking the way back goes to the end and retires the button.+ scrollTo.mockClear();+ act(() => {+ fireEvent.click(screen.getByTestId("chat-scroll-end"));+ });+ expect(scrollTo).toHaveBeenCalledWith(expect.objectContaining({ top: 2000 }));+ expect(screen.queryByTestId("chat-scroll-end")).toBeNull();});it("shows the approval card while the runner waits and routes the click to the store", () => {@@ -415,7 +556,7 @@ describe("ChatStage (agent chat)", () => {expect(screen.getByTestId("composer-stop")).toBeTruthy();});- it("always shows that the turn is alive: glyph, a word, the clock and the tokens", () => {+ it("always shows that the turn is alive: the core, a word, the clock and the tokens", () => {vi.useFakeTimers();try {const started = Date.now();@@ -428,21 +569,24 @@ describe("ChatStage (agent chat)", () => {useAgentChatStore.setState({ activeSessionId: "s1", timeline });render(<ChatStage />);- // The redacted thought is a row of its own — thinking you cannot read- // is still thinking you can see.- const reasoning = screen.getByTestId("agent-reasoning");- expect(reasoning.getAttribute("data-live")).toBe("true");+ // A thought still running draws NO row of its own: the live line below+ // already says the turn is thinking, and two lines saying it at once is+ // the duplication the maintainer objected to (2026-08-25).+ expect(screen.queryByTestId("agent-reasoning")).toBeNull();const live = screen.getByTestId("agent-turn-live");- expect(within(live).getByTestId("agent-glyph")).toBeTruthy();+ expect(within(live).getByTestId("live-core")).toBeTruthy();expect(live.textContent).toMatch(/4\.8k/);+ // Output only: the input side of a CLI re-counts the whole conversation+ // on every step, so it reads as an absurd number for one question.+ expect(live.textContent).not.toMatch(/\b12\b/);// The clock moves on its own.act(() => {vi.advanceTimersByTime(12_000);});expect(live.textContent).toMatch(/1[0-9]s|12s/);- // The rail marks the whole block as running.- expect(screen.getByTestId("agent-turn-rail").className).toContain("agent-rail-live");+ // No hairline rail runs down the turn any more.+ expect(screen.queryByTestId("agent-turn-rail")).toBeNull();// A running turn shows no receipt yet.expect(screen.queryByTestId("agent-turn-footer")).toBeNull();} finally {@@ -450,6 +594,87 @@ describe("ChatStage (agent chat)", () => {}});+ it("reads each stretch of thinking where it happened, with its words in view", () => {+ // The complaint this guards (maintainer, 2026-08-25): the model's+ // intermediate steps had stopped showing — every thought was merged+ // into one folded row on top of the turn. Each stretch now sits before+ // the step it explains; the scratchpad itself is covered in+ // agentchat/AgentTimeline.test.tsx.+ const timeline = reduceEvents(EMPTY_TIMELINE, [+ ev("user_message", { text: "look into it" }),+ ev("turn_started", { turn_id: "t4", provider: "claude-api", model: "claude-opus-5", effort: "high", runner: "claude-cli" }),+ ev("reasoning", { turn_id: "t4", text: "First the port.", duration_ms: 1000 }),+ ev("tool_call", { turn_id: "t4", call_id: "c1", name: "PowerShell", input: { command: "Get-NetTCPConnection" } }),+ ev("tool_result", { turn_id: "t4", call_id: "c1", output: "ok", is_error: false }),+ ev("reasoning", { turn_id: "t4", text: "It is listening.", duration_ms: 4000 }),+ ev("assistant_text", { turn_id: "t4", message_id: "m1", text: "Running." }),+ ev("turn_finished", { turn_id: "t4", status: "done", duration_ms: 6000, usage: {} }),+ ]);+ useAgentChatStore.setState({ activeSessionId: "s4", timeline });+ render(<ChatStage />);++ const rows = screen.getAllByTestId("agent-reasoning");+ expect(rows).toHaveLength(2);+ // Each thought keeps its own time and shows its words without a click.+ expect(rows[0].textContent).toMatch(/1s/);+ expect(rows[0].textContent).toContain("First the port.");+ expect(rows[1].textContent).toMatch(/4s/);+ expect(rows[1].textContent).toContain("It is listening.");+ // Thought, command, thought — the order they happened in.+ const order = Array.from(+ document.querySelectorAll("[data-testid='agent-reasoning'],[data-testid='agent-tool']"),+ ).map((el) => el.getAttribute("data-testid"));+ expect(order).toEqual(["agent-reasoning", "agent-tool", "agent-reasoning"]);+ });++ it("says how a turn ended — including one that answered nothing at all", () => {+ // The complaint this guards (maintainer, 2026-08-25): a turn whose only+ // step was a denied command simply stopped drawing, and there was no way+ // to tell a finished turn from one still thinking.+ const timeline = reduceEvents(EMPTY_TIMELINE, [+ ev("user_message", { text: "what is on my list?" }),+ ev("turn_started", { turn_id: "t4", provider: "google", model: "gemini-3-flash", effort: "medium", runner: "agy" }),+ ev("tool_call", { turn_id: "t4", call_id: "c1", name: "run_command", input: { CommandLine: "gws tasks list" } }),+ ev("tool_result", { turn_id: "t4", call_id: "c1", output: "permission check failed for command\nuser denied permission", is_error: true }),+ ev("turn_finished", { turn_id: "t4", status: "done", duration_ms: 28_000, usage: { input_tokens: 35_400, output_tokens: 448 } }),+ ]);+ useAgentChatStore.setState({ activeSessionId: "s4", timeline });+ render(<ChatStage />);++ const outcome = screen.getByTestId("agent-turn-footer");+ expect(outcome.getAttribute("data-outcome")).toBe("no-answer");+ expect(outcome.textContent).toContain("448");+ // Only the output side reaches the receipt.+ expect(outcome.textContent).not.toContain("35.4k");+ // The failure reads on the row itself, without opening anything.+ expect(screen.getByTestId("agent-tool-gist").textContent).toContain("permission check failed");+ // Nothing claims to still be working.+ expect(screen.queryByTestId("agent-turn-live")).toBeNull();+ });++ it("does not print a tool's input twice when the row already says it", () => {+ const timeline = reduceEvents(EMPTY_TIMELINE, [+ ev("turn_started", { turn_id: "t5", provider: "claude-api", model: "claude-opus-5", effort: "high", runner: "claude-cli" }),+ ev("tool_call", { turn_id: "t5", call_id: "c1", name: "Bash", input: { command: "ls -la" } }),+ ev("tool_result", { turn_id: "t5", call_id: "c1", output: "a.py", is_error: false }),+ ev("tool_call", { turn_id: "t5", call_id: "c2", name: "Grep", input: { pattern: "TODO", path: "src", "-n": true } }),+ ev("tool_result", { turn_id: "t5", call_id: "c2", output: "src/a.py:3", is_error: false }),+ ev("turn_finished", { turn_id: "t5", status: "done", duration_ms: 900, usage: {} }),+ ]);+ useAgentChatStore.setState({ activeSessionId: "s5", timeline });+ render(<ChatStage />);++ const [shell, grep] = screen.getAllByTestId("agent-tool");+ fireEvent.click(within(shell).getByRole("button"));+ // One field, and the row's summary already carries it — no INPUT block.+ expect(within(shell).queryByText("Input")).toBeNull();+ expect(shell.textContent).toContain("a.py");++ fireEvent.click(within(grep).getByRole("button"));+ // More than the summary could say, so the whole input is worth printing.+ expect(within(grep).getByText("Input")).toBeTruthy();+ });+it("names tools the way the agent's log does and closes with time and tokens", () => {const timeline = reduceEvents(EMPTY_TIMELINE, [ev("user_message", { text: "check the repo" }),diff --git a/jarvis/ui/web/frontend/src/components/home/ChatStage.tsx b/jarvis/ui/web/frontend/src/components/home/ChatStage.tsxindex 13ab501b3e..10d2381f77 100644--- a/jarvis/ui/web/frontend/src/components/home/ChatStage.tsx+++ b/jarvis/ui/web/frontend/src/components/home/ChatStage.tsx@@ -3,6 +3,8 @@ import { useCallback, useEffect, useLayoutEffect, useMemo, useRef } from "react"import { useEventStore } from "@/store/events";import { useAgentChat } from "@/components/agentchat/AgentChatStoreContext";import { ScrollArea } from "@/components/ui/scroll-area";+import { ScrollToEndButton } from "@/components/ui/scroll-to-end-button";+import { scrollViewportOf, useStickToBottom } from "@/hooks/useStickToBottom";import { AgentComposer } from "@/components/agentchat/AgentComposer";import { AgentTimeline } from "@/components/agentchat/AgentTimeline";import { Greeting } from "@/components/home/Greeting";@@ -39,8 +41,14 @@ import { FolderCode } from "lucide-react";* is brought to the TOP of the scroll area and the answer grows below it —* the eye stays where the new turn begins instead of chasing the bottom.* A spacer under the last turn makes that possible even when the turn is- * short; it shrinks as the answer fills the viewport. Nothing jumps on- * assistant output.+ * short; it shrinks as the answer fills the viewport. While the answer fits,+ * nothing moves. Once it grows PAST the bottom edge — a long reasoning+ * trace, a coding agent's run of tool calls — the view follows it down,+ * through the rule every conversation surface here shares+ * (hooks/useStickToBottom): new output pulls the view along ONLY while the+ * view is already at the end. Scrolled up to read something, you keep your+ * place while the answer goes on below, and a button over the composer takes+ * you back. Nothing yanks the page out from under someone mid-sentence.*/export function ChatStage() {const t = useT();@@ -73,6 +81,19 @@ export function ChatStage() {const rootRef = useRef<HTMLDivElement | null>(null);const columnRef = useRef<HTMLDivElement | null>(null);const spacerRef = useRef<HTMLDivElement | null>(null);+ // Whether the view is at the end — and so whether growth pulls it along —+ // is the hook's to answer; it listens on the same viewport this stage+ // scrolls. The column is NOT handed over as its content: the spacer must+ // be sized before any follow, so the resize observer below does both, in+ // that order, instead of two observers racing for the same frame.+ const { rootRef: stickRootRef, atEnd, jumpToEnd, follow } = useStickToBottom();+ const setRoot = useCallback(+ (node: HTMLDivElement | null) => {+ rootRef.current = node;+ stickRootRef(node);+ },+ [stickRootRef],+ );// The user message pinned to the top of the scroll area for the current// turn. Null until the person sends in this mounted column — opening an// old conversation lands at its end like before, with no spacer.@@ -83,18 +104,25 @@ export function ChatStage() {// Refs, not state, on purpose: the spacer must be sized BEFORE the scroll// that relies on it, in the same layout pass — a state round-trip would// scroll first and grow the page afterwards, clamping the scroll short.- const applySpacer = () => {- const viewport = viewportOf(rootRef.current);+ //+ // Answers whether the pinned turn still has room under it. While it has,+ // the answer grows into the spacer and the page does not get any taller —+ // there is nothing to follow, and following anyway would nudge the pinned+ // message off its line. Once the room is gone the answer is growing past+ // the bottom edge, and that is what the view follows.+ const applySpacer = (): boolean => {+ const viewport = scrollViewportOf(rootRef.current);const spacer = spacerRef.current;- if (!viewport || !spacer) return;+ if (!viewport || !spacer) return false;const anchor = anchorIdRef.current ? messageElement(viewport, anchorIdRef.current) : null;if (!anchor) {spacer.style.minHeight = "0px";- return;+ return false;}const turnHeight = spacer.getBoundingClientRect().top - anchor.getBoundingClientRect().top;const room = viewport.clientHeight - turnHeight - TURN_BOTTOM_PAD_PX;spacer.style.minHeight = `${Math.max(0, Math.round(room))}px`;+ return room > 0;};const lastItem = items[items.length - 1];@@ -107,7 +135,7 @@ export function ChatStage() {anchorIdRef.current = null;lastItemIdRef.current = null;}- const viewport = viewportOf(rootRef.current);+ const viewport = scrollViewportOf(rootRef.current);const isNew = lastItemId !== lastItemIdRef.current;lastItemIdRef.current = lastItemId;if (!viewport || !lastItemId) return;@@ -117,24 +145,33 @@ export function ChatStage() {scrollMessageToTop(viewport, lastItemId);return;}- applySpacer();- if (isNew && anchorIdRef.current === null) scrollToEnd(viewport);+ // A new item under a turn that has outgrown its window — or an opened+ // conversation landing at its end, or a coding agent's next tool call+ // arriving under a pane that was already full: the end, if the view was+ // there. A reader who scrolled up is left where they are.+ const roomLeft = applySpacer();+ if (isNew && !roomLeft) follow();// `applySpacer` reads refs only and is recreated per render by design.// eslint-disable-next-line react-hooks/exhaustive-deps- }, [lastItemId, lastItemIsUser, activeSessionId, items.length]);+ }, [lastItemId, lastItemIsUser, activeSessionId, items.length, follow]);- // The live blocks grow without a new item; the spacer follows the- // column's size where the platform has ResizeObserver.+ // The live blocks grow without a new item — a reasoning trace, a streamed+ // answer — so no render-driven effect fires for it; the column's own size+ // is the honest signal. Spacer first, then the follow that depends on it.+ // The viewport is watched too: a window that shrinks under a view at the+ // end keeps it at the end.useEffect(() => {const column = columnRef.current;- const viewport = viewportOf(rootRef.current);+ const viewport = scrollViewportOf(rootRef.current);if (!column || !viewport || typeof ResizeObserver === "undefined") return;- const ro = new ResizeObserver(() => applySpacer());+ const ro = new ResizeObserver(() => {+ if (!applySpacer()) follow();+ });ro.observe(column);ro.observe(viewport);return () => ro.disconnect();// eslint-disable-next-line react-hooks/exhaustive-deps- }, [hasContent]);+ }, [hasContent, follow]);// The two surfaces open with different words because they are different// things to be doing: here Jarvis reads with your memory and tools, there a@@ -168,7 +205,7 @@ export function ChatStage() {return (<div className="flex min-h-0 flex-1 flex-col items-center" data-testid="chat-stage" data-empty="false">- <ScrollArea ref={rootRef} className="min-h-0 w-full flex-1">+ <ScrollArea ref={setRoot} className="min-h-0 w-full flex-1"><divref={columnRef}className="relative mx-auto flex w-full max-w-[760px] flex-col gap-5 px-6 pb-6 pt-8"@@ -182,7 +219,8 @@ export function ChatStage() {<div ref={spacerRef} aria-hidden data-testid="chat-bottom-spacer" className="shrink-0" /></div></ScrollArea>- <div className="w-full max-w-[760px] px-6 pb-5 pt-2">+ <div className="relative w-full max-w-[760px] px-6 pb-5 pt-2">+ {!atEnd && <ScrollToEndButton onClick={jumpToEnd} testId="chat-scroll-end" />}<AgentComposer /></div></div>@@ -213,12 +251,6 @@ function FolderHeadline({ folder, subtitle }: { folder: string; subtitle: string/** Room kept under the turn so the composer's shadow never kisses the text. */const TURN_BOTTOM_PAD_PX = 24;-/** Radix renders the scrolling element as the viewport inside our ScrollArea root. */-function viewportOf(root: HTMLElement | null): HTMLElement | null {- if (!root) return null;- return (root.querySelector("[data-radix-scroll-area-viewport]") as HTMLElement | null) ?? root;-}-function messageElement(viewport: HTMLElement, id: string): HTMLElement | null {// Attribute compare instead of a selector: ids carry characters a CSS// selector would need escaping for.@@ -248,7 +280,3 @@ function scrollMessageToTop(viewport: HTMLElement, id: string) {el.getBoundingClientRect().top - viewport.getBoundingClientRect().top + viewport.scrollTop - 12;scrollViewport(viewport, Math.max(0, top));}--function scrollToEnd(viewport: HTMLElement) {- scrollViewport(viewport, viewport.scrollHeight);-}