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(agent-chat): a sent message is on screen at once, and the composer grows with the text

rubenluetke10-beepfccb3319975d
diff --git a/jarvis/ui/web/frontend/src/components/ChatInput.tsx b/jarvis/ui/web/frontend/src/components/ChatInput.tsx
index 3e348af607..ffe8a26443 100644
--- a/jarvis/ui/web/frontend/src/components/ChatInput.tsx
+++ b/jarvis/ui/web/frontend/src/components/ChatInput.tsx
@@ -2,6 +2,7 @@ import { useEffect, useRef, useState, type KeyboardEvent } from "react";
import { ArrowUp, Mic, Square } from "lucide-react";
import { getWSClient } from "@/hooks/useWebSocket";
import { useVoiceEngineDisplay } from "@/hooks/useVoiceEngineDisplay";
+import { useAutoGrowTextarea } from "@/hooks/useAutoGrowTextarea";
import { useEventStore } from "@/store/events";
import { cn } from "@/lib/utils";
import { useT } from "@/i18n";
@@ -22,6 +23,7 @@ const THINKING_TIMEOUT_MS = 60_000;
export function ChatInput() {
const t = useT();
const [value, setValue] = useState("");
+ const textareaRef = useAutoGrowTextarea(value);
const connected = useEventStore((s) => s.connected);
const setActiveSection = useEventStore((s) => s.setActiveSection);
// What will answer: the classic brain, or the realtime engine when voice
@@ -188,6 +190,7 @@ export function ChatInput() {
// it hands a transcript to a component that may be unmounted — see
// lib/dictationTarget.ts.
data-jarvis-chat-input=""
+ ref={textareaRef}
value={value}
onChange={(e) => setValue(e.target.value)}
onKeyDown={onKeyDown}
@@ -200,7 +203,9 @@ export function ChatInput() {
}
disabled={!connected}
rows={2}
- className="max-h-48 w-full resize-none bg-transparent px-1 py-1 text-[15px] leading-relaxed text-foreground placeholder:text-muted-foreground focus-visible:outline-none disabled:opacity-50"
+ // Grows with the text up to half the window (useAutoGrowTextarea);
+ // past the cap the box scrolls rather than pushing Send out of reach.
+ className="max-h-[50vh] w-full resize-none bg-transparent px-1 py-1 text-[15px] leading-relaxed text-foreground scrollbar-jarvis placeholder:text-muted-foreground focus-visible:outline-none disabled:opacity-50"
/>
<div className="flex items-center gap-1.5">
<button
diff --git a/jarvis/ui/web/frontend/src/components/agentchat/AgentComposer.tsx b/jarvis/ui/web/frontend/src/components/agentchat/AgentComposer.tsx
index 6aae52663b..6988e25db4 100644
--- a/jarvis/ui/web/frontend/src/components/agentchat/AgentComposer.tsx
+++ b/jarvis/ui/web/frontend/src/components/agentchat/AgentComposer.tsx
@@ -27,6 +27,7 @@ import { useComposerDictation } from "@/components/agentchat/useComposerDictatio
import { useChatAttachments } from "@/components/agentchat/useChatAttachments";
import { usePasteRescue } from "@/components/agentchat/usePasteRescue";
import { ChatAttachmentStrip } from "@/components/agentchat/ChatAttachmentStrip";
+import { useAutoGrowTextarea } from "@/hooks/useAutoGrowTextarea";
import { fill, useT } from "@/i18n";
import { cn } from "@/lib/utils";
@@ -74,6 +75,7 @@ import { cn } from "@/lib/utils";
export function AgentComposer({ autoFocus = false }: { autoFocus?: boolean }) {
const t = useT();
const [value, setValueState] = useState("");
+ const textareaRef = useAutoGrowTextarea(value);
const setValue = useCallback(
(next: string | ((current: string) => string)) => setValueState(next),
[],
@@ -414,6 +416,7 @@ export function AgentComposer({ autoFocus = false }: { autoFocus?: boolean }) {
onRemove={files.remove}
/>
<textarea
+ ref={textareaRef}
data-jarvis-chat-input=""
autoFocus={autoFocus}
value={value}
@@ -426,7 +429,10 @@ export function AgentComposer({ autoFocus = false }: { autoFocus?: boolean }) {
placeholder={placeholder}
disabled={!connected}
rows={2}
- className="max-h-48 w-full resize-none bg-transparent px-1 py-1 text-[15px] leading-relaxed text-foreground placeholder:text-muted-foreground focus-visible:outline-none disabled:opacity-50"
+ // Grows with the text up to half the window (useAutoGrowTextarea), so
+ // a message is read whole while it is written; past the cap the box
+ // scrolls rather than pushing the picks and Send out of reach.
+ className="max-h-[50vh] w-full resize-none bg-transparent px-1 py-1 text-[15px] leading-relaxed text-foreground scrollbar-jarvis placeholder:text-muted-foreground focus-visible:outline-none disabled:opacity-50"
/>
<div className="flex flex-wrap items-center gap-1">
{/*
diff --git a/jarvis/ui/web/frontend/src/hooks/useAutoGrowTextarea.ts b/jarvis/ui/web/frontend/src/hooks/useAutoGrowTextarea.ts
new file mode 100644
index 0000000000..e0a42446dd
--- /dev/null
+++ b/jarvis/ui/web/frontend/src/hooks/useAutoGrowTextarea.ts
@@ -0,0 +1,30 @@
+import { useLayoutEffect, useRef, type RefObject } from "react";
+
+/**
+ * A textarea that grows with what is typed into it.
+ *
+ * A textarea keeps the height its `rows` give it and scrolls inside that box,
+ * so a message four lines long is read three lines at a time, with its own
+ * opening out of sight (maintainer, 2026-08-27: "I want to see the whole
+ * text, not scroll up"). This sets the element's height to its content after
+ * every change, from the `rows` minimum up to whatever `max-height` the
+ * element's own styling names — past that cap the box scrolls again, so a
+ * pasted file cannot push the composer off the screen.
+ *
+ * Layout-phase, so the box is already the right size when the frame paints.
+ * Where the platform reports no content height (a test DOM), the box keeps
+ * its `rows` height and nothing else happens.
+ */
+export function useAutoGrowTextarea(value: string): RefObject<HTMLTextAreaElement> {
+ const ref = useRef<HTMLTextAreaElement>(null);
+ useLayoutEffect(() => {
+ const el = ref.current;
+ if (!el) return;
+ // Let it shrink first: a height set from the last, longer value would
+ // keep `scrollHeight` from reporting the shorter content.
+ el.style.height = "auto";
+ const content = el.scrollHeight;
+ if (content > 0) el.style.height = `${content}px`;
+ }, [value]);
+ return ref;
+}
diff --git a/jarvis/ui/web/frontend/src/store/paneChat.test.ts b/jarvis/ui/web/frontend/src/store/paneChat.test.ts
index 77bf5695ff..5ffc298ed7 100644
--- a/jarvis/ui/web/frontend/src/store/paneChat.test.ts
+++ b/jarvis/ui/web/frontend/src/store/paneChat.test.ts
@@ -230,9 +230,120 @@ describe("createPaneChatStore", () => {
detail: "still in the input box",
});
const store = makeStore();
+ store.getState().start();
+ await flush();
await store.getState().send("hi");
+ store.getState().stop();
const toasts = useEventStore.getState().toasts;
expect(toasts.at(-1)?.message).toContain("T7 did not take the message: still in the input box");
+ // The sentence sits in the pane's input box, not in its conversation —
+ // so the echo drawn at Send is taken back, and only the record remains.
+ const texts = store.getState().timeline.items.map((it) => (it.type === "user" ? it.text : it.type));
+ expect(texts).toEqual(["Fix the login bug", "turn"]);
+ });
+
+ it("draws the sentence the moment Send is pressed, and hands it to the record once that holds it", async () => {
+ vi.mocked(api.fetchTerminalTimeline).mockResolvedValue(answer());
+ let deliver!: (result: Awaited<ReturnType<typeof api.promptTerminal>>) => void;
+ vi.mocked(api.promptTerminal).mockReturnValue(
+ new Promise((resolve) => {
+ deliver = resolve;
+ }),
+ );
+ const store = makeStore();
+ store.getState().start();
+ await flush();
+ expect(store.getState().timeline.items).toHaveLength(2);
+
+ // Not awaited: the pane has not even typed the sentence yet.
+ const sending = store.getState().send("Now the tests");
+ const drawn = store.getState().timeline.items;
+ expect(drawn).toHaveLength(4);
+ expect(drawn[2]).toMatchObject({ type: "user", text: "Now the tests" });
+ expect(drawn[3]).toMatchObject({ type: "turn", status: "running", provider: CLAUDE_CLI.id });
+ expect(drawn[3].id).toMatch(/^echo-/);
+ expect(store.getState().timeline.lastSeq).toBe(8); // an echo never moves the cursor
+
+ // The pane took it; the record has not caught up: the echo stays.
+ deliver({ terminal: "T7", sent: "Now the tests", composed_by: "raw", files: [], submitted: true });
+ await sending;
+ await flush();
+ expect(store.getState().timeline.items).toHaveLength(4);
+ expect(store.getState().timeline.items[3].id).toMatch(/^echo-/);
+
+ // The record holds a message newer than before the send: its copy takes
+ // over, the echo goes, and nothing is shown twice.
+ vi.mocked(api.fetchTerminalTimeline).mockResolvedValue(
+ answer({
+ live: true,
+ activity: "working",
+ events: [
+ ...EXCHANGE,
+ ev(9, "user_message", { text: "Now the tests" }, 20_000),
+ ev(10, "turn_started", { turn_id: "turn-2", provider: "claude", model: "claude-opus-5", effort: "xhigh", runner: "cli" }, 20_000),
+ ],
+ }),
+ );
+ store.getState().reload();
+ await flush();
+ store.getState().stop();
+ const items = store.getState().timeline.items;
+ expect(items).toHaveLength(4);
+ expect(items.filter((it) => it.type === "user" && it.text === "Now the tests")).toHaveLength(1);
+ expect(items[2].id).toBe("u-9");
+ expect(items[3].id).toBe("turn-2");
+ expect(store.getState().timeline.lastSeq).toBe(10);
+ });
+
+ it("two messages sent back to back settle one at a time, oldest first", async () => {
+ vi.mocked(api.fetchTerminalTimeline).mockResolvedValue(answer());
+ vi.mocked(api.promptTerminal).mockResolvedValue({
+ terminal: "T7",
+ sent: "",
+ composed_by: "raw",
+ files: [],
+ submitted: true,
+ });
+ const store = makeStore();
+ store.getState().start();
+ await flush();
+ await store.getState().send("First");
+ await store.getState().send("Second");
+ await flush();
+ const userTexts = () =>
+ store.getState().timeline.items.flatMap((it) => (it.type === "user" ? [it.text] : []));
+ expect(userTexts()).toEqual(["Fix the login bug", "First", "Second"]);
+
+ // The record has the first message and its turn; the second is still an echo.
+ vi.mocked(api.fetchTerminalTimeline).mockResolvedValue(
+ answer({
+ events: [
+ ...EXCHANGE,
+ ev(9, "user_message", { text: "First" }, 20_000),
+ ev(10, "turn_started", { turn_id: "turn-2", provider: "claude", model: "", effort: "", runner: "cli" }, 20_000),
+ ev(11, "turn_finished", { turn_id: "turn-2", status: "done", duration_ms: 10, usage: null, error: null, cost_usd: null }, 21_000),
+ ],
+ }),
+ );
+ store.getState().reload();
+ await flush();
+ store.getState().stop();
+ expect(userTexts()).toEqual(["Fix the login bug", "First", "Second"]);
+ const items = store.getState().timeline.items;
+ expect(items.filter((it) => it.id.startsWith("echo-"))).toHaveLength(1);
+ expect(items.filter((it) => it.type === "user" && it.id === "u-9")).toHaveLength(1);
+ });
+
+ it("withdraws the echo when the send itself fails", async () => {
+ vi.mocked(api.fetchTerminalTimeline).mockResolvedValue(answer());
+ vi.mocked(api.promptTerminal).mockRejectedValue(new Error("pane is gone"));
+ const store = makeStore();
+ store.getState().start();
+ await flush();
+ await store.getState().send("hello?");
+ store.getState().stop();
+ expect(store.getState().lastError).toBe("pane is gone");
+ expect(store.getState().timeline.items).toHaveLength(2);
});
it("Stop presses Escape in the pane", async () => {
diff --git a/jarvis/ui/web/frontend/src/store/paneChat.ts b/jarvis/ui/web/frontend/src/store/paneChat.ts
index f07c1266d7..08332d63d3 100644
--- a/jarvis/ui/web/frontend/src/store/paneChat.ts
+++ b/jarvis/ui/web/frontend/src/store/paneChat.ts
@@ -119,6 +119,79 @@ function withProvider(timeline: Timeline, providerId: string): Timeline {
return { ...timeline, items };
}
+/**
+ * A message typed here that the CLI's record does not hold yet.
+ *
+ * The record is the CLI's own transcript, read by polling: the sentence shows
+ * up there only once the CLI has taken it, and the next read follows seconds
+ * later. The front page's chat hears its own message back over the socket at
+ * once; a pane gets the same immediacy from this — the sentence is drawn the
+ * moment Send is pressed, exactly as the record will draw it (the message,
+ * then an open turn, which is what `agent_transcript` itself writes for an
+ * unanswered question on a working pane), and it stays drawn until the record
+ * holds a newer message than it did before the send. Then the record's copy
+ * takes over and the echo is dropped, so nothing is shown twice.
+ */
+export interface PendingEcho {
+ text: string;
+ attachments: ChatAttachment[];
+ /** When Send was pressed — the echo's timestamp and its turn's start. */
+ atMs: number;
+ /** The newest user message the record held before the send; the echo settles once that grows. */
+ lastUserTsBefore: number;
+}
+
+/** The timestamp of the newest user message in a read, 0 when it holds none. */
+export function lastUserMessageTs(events: readonly AgentChatEvent[]): number {
+ for (let i = events.length - 1; i >= 0; i -= 1) {
+ if (events[i].kind === "user_message") return events[i].ts_ms;
+ }
+ return 0;
+}
+
+/** How many user messages a read holds that are newer than `ts`. */
+export function countUserMessagesAfter(events: readonly AgentChatEvent[], ts: number): number {
+ let n = 0;
+ for (const ev of events) if (ev.kind === "user_message" && ev.ts_ms > ts) n += 1;
+ return n;
+}
+
+/** The two events a pending echo folds through the chat's reducer as. */
+export function echoEvents(
+ echo: PendingEcho,
+ turn: { provider: string; model: string; effort: string },
+): AgentChatEvent[] {
+ // `seq` 0: an echo never advances the timeline's cursor — the record's own
+ // sequence does that once it holds the message.
+ return [
+ {
+ seq: 0,
+ ts_ms: echo.atMs,
+ kind: "user_message",
+ payload: {
+ text: echo.text,
+ attachments: echo.attachments.map((a) => ({
+ name: a.name,
+ kind: a.kind,
+ described_by: a.described_by,
+ })),
+ },
+ },
+ {
+ seq: 0,
+ ts_ms: echo.atMs,
+ kind: "turn_started",
+ payload: {
+ turn_id: `echo-${echo.atMs}`,
+ provider: turn.provider,
+ model: turn.model,
+ effort: turn.effort,
+ runner: "cli",
+ },
+ },
+ ];
+}
+
export interface PaneChatStoreOptions {
terminal: string;
workspaceId: string;
@@ -202,10 +275,26 @@ export function createPaneChatStore(options: PaneChatStoreOptions) {
...patch,
});
+ /** The record as the last read returned it — what the timeline is rebuilt from. */
+ let lastEvents: AgentChatEvent[] = [];
+ /** Messages typed here that the record does not hold yet, oldest first. */
+ let echoes: PendingEcho[] = [];
+
const store = create<PaneChatState>((set, get) => {
const providerId = () =>
providerForAgent(options.agent, agentStore.getState().providerOptions())?.id ?? "";
+ /** The record's timeline, with every pending echo drawn after it. */
+ const rebuild = (pid: string): Timeline => {
+ const { model, effort } = get().draft;
+ const recorded = reduceEvents(EMPTY_TIMELINE, lastEvents);
+ const echoed = echoes.reduce(
+ (tl, echo) => reduceEvents(tl, echoEvents(echo, { provider: pid, model, effort })),
+ recorded,
+ );
+ return withProvider(echoed, pid);
+ };
+
const apply = (res: TerminalTimelineResponse) => {
const pid = providerId();
// A model picked here is typed into the pane and shows up in the record
@@ -243,7 +332,20 @@ export function createPaneChatStore(options: PaneChatStoreOptions) {
const sig = eventsSignature(res.events, res.live);
if (sig !== signature) {
signature = sig;
- next.timeline = withProvider(reduceEvents(EMPTY_TIMELINE, res.events), pid);
+ lastEvents = res.events;
+ // The record has caught up with a send when it holds a user message
+ // newer than the one it held before that send: the oldest echo is now
+ // the record's, and the record draws it from here on. By timestamp,
+ // not by count — the read keeps only the last N turns, so a count
+ // stands still exactly when the conversation is long.
+ // Every pending echo was sent against the same read (the read only
+ // moves here), so one base serves them all: each message the record
+ // gained past it settles one echo, oldest first.
+ if (echoes.length > 0) {
+ const gained = countUserMessagesAfter(res.events, echoes[0].lastUserTsBefore);
+ echoes = echoes.slice(Math.min(gained, echoes.length));
+ }
+ next.timeline = rebuild(pid);
}
set(next);
return pollIntervalFor(res.live, res.activity);
@@ -380,7 +482,22 @@ export function createPaneChatStore(options: PaneChatStoreOptions) {
send: async (text: string, attachments: ChatAttachment[] = []) => {
if (get().busy) return;
- set({ busy: true, lastError: null });
+ // Drawn before anything is sent: the person just pressed Send and the
+ // sentence is theirs to see now, not after the pane has typed it, the
+ // CLI has taken it, written it down, and a poll has read it back
+ // (measured at five seconds, 2026-08-27). See `PendingEcho`.
+ const echo: PendingEcho = {
+ text,
+ attachments,
+ atMs: Date.now(),
+ lastUserTsBefore: lastUserMessageTs(lastEvents),
+ };
+ echoes = [...echoes, echo];
+ set({ busy: true, lastError: null, timeline: rebuild(providerId()) });
+ const withdraw = () => {
+ echoes = echoes.filter((e) => e !== echo);
+ set({ timeline: rebuild(providerId()) });
+ };
try {
// Verbatim: `compose` off. A brief written FOR the person belongs to
// the voice path; here the person is talking to the agent themselves.
@@ -389,6 +506,9 @@ export function createPaneChatStore(options: PaneChatStoreOptions) {
attachments,
});
if (result.submitted === false) {
+ // The text sits in the pane's input box, not in its conversation;
+ // a bubble saying otherwise would be the lie the toast corrects.
+ withdraw();
toast(
"warning",
translate("agentic_grid.pane_chat.not_taken")
@@ -400,6 +520,7 @@ export function createPaneChatStore(options: PaneChatStoreOptions) {
// starts at once so the answer is seen forming.
get().reload();
} catch (reason: unknown) {
+ withdraw();
set({ lastError: reason instanceof Error ? reason.message : String(reason) });
} finally {
set({ busy: false });