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 Shift+Enter break the line instead of sending
Ruben Lütke24e64715e880
diff --git a/jarvis/ui/web/frontend/src/components/agentic/AgenticTerminal.offscreen.test.tsx b/jarvis/ui/web/frontend/src/components/agentic/AgenticTerminal.offscreen.test.tsxindex efcffbad85..721b34d291 100644--- a/jarvis/ui/web/frontend/src/components/agentic/AgenticTerminal.offscreen.test.tsx+++ b/jarvis/ui/web/frontend/src/components/agentic/AgenticTerminal.offscreen.test.tsx@@ -41,6 +41,11 @@ vi.mock("@xterm/xterm", () => ({open() {}focus() {}paste() {}+ // The pane claims keystrokes on mount (paste, and the newline chord in+ // ./terminalNewline) — a stand-in without these is a terminal xterm never+ // shipped either.+ attachCustomKeyEventHandler() {}+ input() {}getSelection() {return "";}diff --git a/jarvis/ui/web/frontend/src/components/agentic/AgenticTerminal.test.tsx b/jarvis/ui/web/frontend/src/components/agentic/AgenticTerminal.test.tsxindex db9a2c0761..33a75e1264 100644--- a/jarvis/ui/web/frontend/src/components/agentic/AgenticTerminal.test.tsx+++ b/jarvis/ui/web/frontend/src/components/agentic/AgenticTerminal.test.tsx@@ -11,6 +11,10 @@ const terminalHarness = vi.hoisted(() => ({send: vi.fn<(payload: unknown) => boolean>(() => true),/** The live socket's handlers, so a test can play a reconnect. */handlers: { current: null as Record<string, (...args: never[]) => void> | null },+ /** Everything the pane types into the terminal on the user's behalf. */+ input: vi.fn<(data: string) => void>(),+ /** xterm's single custom key handler, so a test can press a key. */+ keys: { current: null as ((event: KeyboardEvent) => boolean) | null },}));vi.mock("@xterm/xterm", () => ({@@ -36,6 +40,12 @@ vi.mock("@xterm/xterm", () => ({}focus() {}paste() {}+ attachCustomKeyEventHandler(handler: (event: KeyboardEvent) => boolean) {+ terminalHarness.keys.current = handler;+ }+ input(data: string) {+ terminalHarness.input(data);+ }getSelection() {return "";}@@ -129,6 +139,61 @@ describe("AgenticTerminal layout", () => {});});+describe("pane keyboard", () => {+ beforeEach(() => {+ terminalHarness.input.mockClear();+ terminalHarness.keys.current = null;+ globalThis.ResizeObserver = ResizeObserverHarness;+ });++ afterEach(() => {+ vi.restoreAllMocks();+ });++ /**+ * The reported bug: Shift+Enter sent the half-written instruction, because+ * every modifier combination of Enter reaches a terminal as the same+ * carriage return. See ./terminalNewline for the sequence.+ */+ it("breaks the line on Shift+Enter instead of sending the instruction", () => {+ render(+ <AgenticTerminal+ name="Dana"+ displayName="Claude Code"+ appearance="dark"+ fontSize={13}+ />,+ );++ const press = terminalHarness.keys.current;+ expect(press).not.toBeNull();+ const claimed = press?.(+ new KeyboardEvent("keydown", { key: "Enter", shiftKey: true }),+ );++ expect(claimed).toBe(false);+ expect(terminalHarness.input).toHaveBeenCalledWith("\x1b\r");+ });++ it("leaves a plain Enter to xterm, so Enter still sends", () => {+ render(+ <AgenticTerminal+ name="Dana"+ displayName="Claude Code"+ appearance="dark"+ fontSize={13}+ />,+ );++ const claimed = terminalHarness.keys.current?.(+ new KeyboardEvent("keydown", { key: "Enter" }),+ );++ expect(claimed).toBe(true);+ expect(terminalHarness.input).not.toHaveBeenCalled();+ });+});+describe("pane header recap", () => {beforeEach(() => {globalThis.ResizeObserver = ResizeObserverHarness;diff --git a/jarvis/ui/web/frontend/src/components/agentic/AgenticTerminal.tsx b/jarvis/ui/web/frontend/src/components/agentic/AgenticTerminal.tsxindex 024e2f5fef..d91b5e7b18 100644--- a/jarvis/ui/web/frontend/src/components/agentic/AgenticTerminal.tsx+++ b/jarvis/ui/web/frontend/src/components/agentic/AgenticTerminal.tsx@@ -75,6 +75,8 @@ import { attachToTerminal } from "@/lib/agenticIdeApi";import { attachTerminalBridge } from "@/lib/editActions";import { robustPaste } from "@/lib/clipboard";import { installPasteBridge } from "./terminalPaste";+import { createKeyEventChain } from "./terminalKeyChain";+import { installNewlineBridge } from "./terminalNewline";import { OffscreenBuffer } from "./offscreenBuffer";import { installQuerySuppression } from "./terminalQueries";import { PaneScrollbar } from "./PaneScrollbar";@@ -305,16 +307,30 @@ export function AgenticTerminal({paste: (text) => term.paste(text),focus: () => term.focus(),});+ // Both keyboard bridges below claim keystrokes, and xterm holds exactly ONE+ // custom key handler — attaching them directly would leave only the last+ // one working, silently. See ./terminalKeyChain.+ const keys = createKeyEventChain(term);// Make Ctrl+V / Cmd+V paste. Left to itself xterm reads the chord as the// terminal control code ^V and CANCELS the keystroke, so the browser never// runs its own paste and nothing arrives at all — see ./terminalPaste.- const disposePasteBridge = installPasteBridge(term, container, {- readClipboard: robustPaste,- isMac: /mac|iphone|ipad/i.test(navigator.userAgent),- onUnavailable: () =>- onAttachErrorRef.current?.(- "Could not read the clipboard on this machine.",- ),+ const disposePasteBridge = installPasteBridge(+ { attachCustomKeyEventHandler: keys.add, paste: (text) => term.paste(text) },+ container,+ {+ readClipboard: robustPaste,+ isMac: /mac|iphone|ipad/i.test(navigator.userAgent),+ onUnavailable: () =>+ onAttachErrorRef.current?.(+ "Could not read the clipboard on this machine.",+ ),+ },+ );+ // Make Shift+Enter (and Option/Cmd+Enter) break the line instead of sending+ // the half-written instruction — see ./terminalNewline.+ const disposeNewlineBridge = installNewlineBridge({+ attachCustomKeyEventHandler: keys.add,+ input: (data) => term.input(data),});try {fit.fit();@@ -552,6 +568,7 @@ export function AgenticTerminal({ro.disconnect();io?.disconnect();disposePasteBridge();+ disposeNewlineBridge();disposeQuerySuppression();try {socket?.close();diff --git a/jarvis/ui/web/frontend/src/components/agentic/terminalKeyChain.test.ts b/jarvis/ui/web/frontend/src/components/agentic/terminalKeyChain.test.tsnew file mode 100644index 0000000000..e1c6110ed6--- /dev/null+++ b/jarvis/ui/web/frontend/src/components/agentic/terminalKeyChain.test.ts@@ -0,0 +1,86 @@+import { describe, expect, it, vi } from "vitest";++import { createKeyEventChain } from "./terminalKeyChain";++/** Stand-in for xterm's single-handler slot. */+function fakeHost(): {+ attachCustomKeyEventHandler: (h: (e: KeyboardEvent) => boolean) => void;+ press: () => boolean;+ attachCount: number;+} {+ const host = {+ handler: ((() => true) as (e: KeyboardEvent) => boolean),+ attachCount: 0,+ attachCustomKeyEventHandler(h: (e: KeyboardEvent) => boolean) {+ host.handler = h;+ host.attachCount += 1;+ },+ press: () => host.handler(new KeyboardEvent("keydown", { key: "a" })),+ };+ return host;+}++describe("sharing xterm's one custom key handler", () => {+ /**+ * The regression guard for what the chain exists to prevent: xterm's+ * `attachCustomKeyEventHandler` is a setter, so wiring two bridges directly+ * would leave only the last one working.+ */+ it("claims the single slot once, however many members are added", () => {+ const host = fakeHost();+ const chain = createKeyEventChain(host);+ chain.add(() => true);+ chain.add(() => true);++ expect(host.attachCount).toBe(1);+ });++ it("offers a key to every member while none of them claims it", () => {+ const host = fakeHost();+ const chain = createKeyEventChain(host);+ const first = vi.fn(() => true);+ const second = vi.fn(() => true);+ chain.add(first);+ chain.add(second);++ expect(host.press()).toBe(true);+ expect(first).toHaveBeenCalledOnce();+ expect(second).toHaveBeenCalledOnce();+ });++ it("stops at the member that claims the key", () => {+ const host = fakeHost();+ const chain = createKeyEventChain(host);+ const later = vi.fn(() => true);+ chain.add(() => false);+ chain.add(later);++ expect(host.press()).toBe(false);+ expect(later).not.toHaveBeenCalled();+ });++ it("forgets a removed member", () => {+ const host = fakeHost();+ const chain = createKeyEventChain(host);+ const remove = chain.add(() => false);++ remove();++ expect(host.press()).toBe(true);+ });++ it("survives a member that removes itself while running", () => {+ const host = fakeHost();+ const chain = createKeyEventChain(host);+ const second = vi.fn(() => true);+ let remove = () => undefined as void;+ remove = chain.add(() => {+ remove();+ return true;+ });+ chain.add(second);++ expect(host.press()).toBe(true);+ expect(second).toHaveBeenCalledOnce();+ });+});diff --git a/jarvis/ui/web/frontend/src/components/agentic/terminalKeyChain.ts b/jarvis/ui/web/frontend/src/components/agentic/terminalKeyChain.tsnew file mode 100644index 0000000000..2923deb49d--- /dev/null+++ b/jarvis/ui/web/frontend/src/components/agentic/terminalKeyChain.ts@@ -0,0 +1,50 @@+/**+ * Sharing xterm's ONE custom key handler between several bridges.+ *+ * `attachCustomKeyEventHandler` reads like a subscription but is a setter:+ * xterm keeps a single handler, and a second call silently replaces the first.+ * Two features in a terminal pane need to claim keystrokes — pasting+ * (./terminalPaste) and the newline chord (./terminalNewline) — so whichever+ * was wired last would have switched the other one off, with no error and+ * nothing in the console to notice it by.+ *+ * The chain registers one real handler and offers the event to its members in+ * the order they were added, stopping at the first that claims it. "Claims" is+ * xterm's own convention: returning `false` means "xterm, keep your hands off+ * this one", and a handler that says so must also be the last to see the key —+ * otherwise two bridges would act on the same keystroke.+ */++/** The slice of an xterm terminal this chain drives. */+export interface KeyHandlerHost {+ attachCustomKeyEventHandler(handler: (event: KeyboardEvent) => boolean): void;+}++/** `true` lets the key through to xterm, `false` claims it. */+export type KeyEventHandler = (event: KeyboardEvent) => boolean;++export interface KeyEventChain {+ /** Add a handler, returning a function that removes it again. */+ add(handler: KeyEventHandler): () => void;+}++export function createKeyEventChain(host: KeyHandlerHost): KeyEventChain {+ const handlers: KeyEventHandler[] = [];++ host.attachCustomKeyEventHandler((event) =>+ // A copy, because a handler is allowed to remove itself while running.+ // `every` short-circuits, which is exactly the contract above: once one has+ // claimed the keystroke, the ones behind it must not see it as well.+ handlers.slice().every((handler) => handler(event)),+ );++ return {+ add(handler) {+ handlers.push(handler);+ return () => {+ const at = handlers.indexOf(handler);+ if (at >= 0) handlers.splice(at, 1);+ };+ },+ };+}diff --git a/jarvis/ui/web/frontend/src/components/agentic/terminalNewline.test.ts b/jarvis/ui/web/frontend/src/components/agentic/terminalNewline.test.tsnew file mode 100644index 0000000000..3f0558cb8a--- /dev/null+++ b/jarvis/ui/web/frontend/src/components/agentic/terminalNewline.test.ts@@ -0,0 +1,162 @@+import { describe, expect, it } from "vitest";++import {+ NEWLINE_SEQUENCE,+ installNewlineBridge,+ isNewlineChord,+} from "./terminalNewline";++/** Stand-in for the xterm terminal, recording what the bridge does to it. */+function fakeTerminal(): {+ attachCustomKeyEventHandler: (h: (e: KeyboardEvent) => boolean) => void;+ input: (data: string) => void;+ press: (init: KeyboardEventInit, type?: string) => boolean;+ sent: string[];+} {+ let handler: (event: KeyboardEvent) => boolean = () => true;+ const sent: string[] = [];+ return {+ attachCustomKeyEventHandler: (h) => {+ handler = h;+ },+ input: (data: string) => {+ sent.push(data);+ },+ press: (init: KeyboardEventInit, type = "keydown") =>+ handler(new KeyboardEvent(type, { cancelable: true, ...init })),+ sent,+ };+}++describe("recognising the newline chord", () => {+ it("takes Shift+Enter — the reported bug", () => {+ expect(+ isNewlineChord(new KeyboardEvent("keydown", { key: "Enter", shiftKey: true })),+ ).toBe(true);+ });++ it("takes Option/Alt+Enter and Cmd+Enter", () => {+ expect(+ isNewlineChord(new KeyboardEvent("keydown", { key: "Enter", altKey: true })),+ ).toBe(true);+ expect(+ isNewlineChord(new KeyboardEvent("keydown", { key: "Enter", metaKey: true })),+ ).toBe(true);+ });++ it("leaves a plain Enter alone — that is still 'send'", () => {+ expect(isNewlineChord(new KeyboardEvent("keydown", { key: "Enter" }))).toBe(+ false,+ );+ });++ it("leaves Ctrl+Enter alone, and with it AltGr+Enter", () => {+ expect(+ isNewlineChord(new KeyboardEvent("keydown", { key: "Enter", ctrlKey: true })),+ ).toBe(false);+ expect(+ isNewlineChord(+ new KeyboardEvent("keydown", {+ key: "Enter",+ ctrlKey: true,+ altKey: true,+ }),+ ),+ ).toBe(false);+ });++ it("leaves other keys alone", () => {+ expect(+ isNewlineChord(new KeyboardEvent("keydown", { key: "a", shiftKey: true })),+ ).toBe(false);+ });++ /**+ * While an IME is composing, Enter confirms the candidate word. Turning that+ * into a line break would make the pane unusable in Japanese, Chinese and+ * Korean.+ */+ it("stays out of the way while an IME is composing", () => {+ const event = new KeyboardEvent("keydown", { key: "Enter", shiftKey: true });+ Object.defineProperty(event, "isComposing", { value: true });+ expect(isNewlineChord(event)).toBe(false);+ });+});++describe("writing a new line into a terminal pane", () => {+ it("sends ESC+CR instead of the carriage return that submits", () => {+ const term = fakeTerminal();+ installNewlineBridge(term);++ expect(term.press({ key: "Enter", shiftKey: true })).toBe(false);+ expect(term.sent).toEqual([NEWLINE_SEQUENCE]);+ });++ /**+ * Both bytes in ONE write: a parser tells "ESC as a modifier" from "Escape,+ * then Return" by whether they arrive together, and the split version cancels+ * the agent's prompt rather than extending it.+ */+ it("sends the escape and the return together", () => {+ const term = fakeTerminal();+ installNewlineBridge(term);++ term.press({ key: "Enter", altKey: true });++ expect(term.sent).toHaveLength(1);+ expect(term.sent[0]).toBe("\x1b\r");+ });++ it("leaves a plain Enter to xterm, so Enter still sends", () => {+ const term = fakeTerminal();+ installNewlineBridge(term);++ expect(term.press({ key: "Enter" })).toBe(true);+ expect(term.sent).toEqual([]);+ });++ /**+ * Without `preventDefault` the browser runs its default action, xterm's+ * separate keypress path sees a plain Enter, and the carriage return this+ * bridge exists to prevent goes out after all.+ */+ it("stops the browser from acting on the key as well", () => {+ let handler: (event: KeyboardEvent) => boolean = () => true;+ installNewlineBridge({+ attachCustomKeyEventHandler: (h) => {+ handler = h;+ },+ input: () => undefined,+ });++ const event = new KeyboardEvent("keydown", {+ key: "Enter",+ shiftKey: true,+ cancelable: true,+ });+ handler(event);++ expect(event.defaultPrevented).toBe(true);+ });++ it("writes one line per press, not one per keydown/keypress/keyup", () => {+ const term = fakeTerminal();+ installNewlineBridge(term);++ expect(term.press({ key: "Enter", shiftKey: true }, "keydown")).toBe(false);+ expect(term.press({ key: "Enter", shiftKey: true }, "keypress")).toBe(false);+ expect(term.press({ key: "Enter", shiftKey: true }, "keyup")).toBe(false);++ expect(term.sent).toEqual([NEWLINE_SEQUENCE]);+ });++ it("hands the chord back once the pane is gone", () => {+ const term = fakeTerminal();+ const dispose = installNewlineBridge(term);++ dispose();++ expect(term.press({ key: "Enter", shiftKey: true })).toBe(true);+ expect(term.sent).toEqual([]);+ });+});diff --git a/jarvis/ui/web/frontend/src/components/agentic/terminalNewline.ts b/jarvis/ui/web/frontend/src/components/agentic/terminalNewline.tsnew file mode 100644index 0000000000..7a824a2656--- /dev/null+++ b/jarvis/ui/web/frontend/src/components/agentic/terminalNewline.ts@@ -0,0 +1,93 @@+/**+ * Shift+Enter writes a new line instead of sending the message.+ *+ * ## Why this file has to exist+ *+ * A terminal has no concept of "insert a line break without submitting": Enter+ * is one byte, carriage return, and every modifier combination xterm knows+ * sends that same byte. So a long instruction typed into a coding agent's+ * prompt box could not be broken into paragraphs at all — Shift+Enter sent it+ * half-written (reported 2026-07-27), which is worse than doing nothing,+ * because the agent immediately starts working on the fragment.+ *+ * Native terminals solve this by being configured for it: on macOS the+ * convention is Option+Enter, and Claude Code's own `/terminal-setup` writes a+ * Shift+Enter mapping into iTerm2 and VS Code. A pane inside this app has no+ * such settings file for anyone to edit, so the mapping belongs here.+ *+ * ## What is actually sent, and why that sequence+ *+ * `ESC` followed by carriage return — what any terminal sends for+ * Alt/Option+Enter, and the reason it is the right choice is that it is not a+ * private convention:+ *+ * * **Coding agents** built on Ink (Claude Code, Gemini CLI) parse a leading+ * ESC as the meta modifier, so this arrives as the meta+Enter their prompt+ * box already treats as a line break — the same keystroke their macOS users+ * press.+ * * **A plain shell pane** is served too: PSReadLine, the default on Windows,+ * binds Alt+Enter to inserting a line.+ * * **Nothing submits on it.** Where a program does not know the sequence it+ * ignores it, which is the honest failure here — a stray line break costs a+ * keystroke, a stray submit costs a half-written instruction.+ *+ * Both bytes go out in ONE write on purpose. Readline-style parsers decide+ * "ESC as a modifier" versus "the Escape key, then a separate Return" by+ * whether the bytes arrive together, so splitting them would cancel the+ * agent's prompt instead of extending it.+ *+ * ## Which chords count+ *+ * Shift, Alt/Option and Cmd — every "Enter, but not really" a user might+ * reach for. Ctrl+Enter is deliberately left alone: Ctrl+<key> is a control+ * code in a terminal, and people who use Ctrl+Enter to send would lose that.+ * Ctrl also rules out AltGr, which European layouts deliver as Ctrl+Alt.+ */++/** ESC + CR — Alt/Option+Enter, as a real terminal would send it. */+export const NEWLINE_SEQUENCE = "\x1b\r";++/** The slice of an xterm terminal this bridge drives. */+export interface NewlineCapableTerminal {+ attachCustomKeyEventHandler(handler: (event: KeyboardEvent) => boolean): void;+ /** Send data as if the user had typed it (fires xterm's `onData`). */+ input(data: string, wasUserInput?: boolean): void;+}++/** Is this the keystroke the user means as "new line, do not send"? */+export function isNewlineChord(event: KeyboardEvent): boolean {+ if (event.key !== "Enter") return false;+ // Mid-composition (Japanese, Chinese, Korean input) Enter confirms the+ // candidate word and never reaches the terminal as a keystroke at all.+ if (event.isComposing) return false;+ if (event.ctrlKey) return false;+ return event.shiftKey || event.altKey || event.metaKey;+}++/**+ * Wire the newline chord into `term`, returning a cleanup function.+ *+ * `preventDefault` matters as much as the return value: without it the browser+ * still runs its default action for the key, xterm's separate keypress path+ * sees a plain Enter, and the carriage return this exists to prevent goes out+ * after all.+ */+export function installNewlineBridge(term: NewlineCapableTerminal): () => void {+ let live = true;++ term.attachCustomKeyEventHandler((event) => {+ if (!live) return true;+ if (!isNewlineChord(event)) return true;+ // keydown carries the keystroke; the keypress and keyup that follow are the+ // same press and must be swallowed rather than acted on twice.+ if (event.type === "keydown") {+ event.preventDefault();+ term.input(NEWLINE_SEQUENCE);+ }+ return false;+ });++ return () => {+ live = false;+ };+}diff --git a/jarvis/ui/web/frontend/src/components/workspace/WorkspaceTerminal.tsx b/jarvis/ui/web/frontend/src/components/workspace/WorkspaceTerminal.tsxindex 778fe4406d..771b01655c 100644--- a/jarvis/ui/web/frontend/src/components/workspace/WorkspaceTerminal.tsx+++ b/jarvis/ui/web/frontend/src/components/workspace/WorkspaceTerminal.tsx@@ -13,6 +13,7 @@ import { FitAddon } from "@xterm/addon-fit";import { WebLinksAddon } from "@xterm/addon-web-links";import "@xterm/xterm/css/xterm.css";import { Terminal as TerminalIcon, AlertCircle } from "lucide-react";+import { installNewlineBridge } from "../agentic/terminalNewline";type Status = "connecting" | "live" | "exited" | "error";@@ -67,6 +68,11 @@ export function WorkspaceTerminal({term.loadAddon(fit);term.loadAddon(new WebLinksAddon());term.open(container);+ // Shift+Enter breaks the line instead of sending a half-written+ // instruction — the same binding the Agentic IDE panes have, because it is+ // the same kind of agent prompt on the other end (see+ // ../agentic/terminalNewline).+ const disposeNewlineBridge = installNewlineBridge(term);try {fit.fit();} catch {@@ -163,6 +169,7 @@ export function WorkspaceTerminal({disposed = true;window.removeEventListener("resize", sendResize);ro.disconnect();+ disposeNewlineBridge();try {ws?.close();} catch {