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): keep copy shortcut out of codex pty

Ruben Lütke4e291134cda0
diff --git a/jarvis/ui/web/frontend/src/components/agentic/AgenticTerminal.test.tsx b/jarvis/ui/web/frontend/src/components/agentic/AgenticTerminal.test.tsx
index 5dd2a664f4..65d7b4d264 100644
--- a/jarvis/ui/web/frontend/src/components/agentic/AgenticTerminal.test.tsx
+++ b/jarvis/ui/web/frontend/src/components/agentic/AgenticTerminal.test.tsx
@@ -345,6 +345,23 @@ describe("pane keyboard", () => {
expect(claimed).toBe(true);
expect(terminalHarness.input).not.toHaveBeenCalled();
});
+
+ it("keeps Ctrl+C out of the PTY even when nothing is selected", () => {
+ render(
+ <AgenticTerminal
+ name="Dana"
+ displayName="Codex"
+ appearance="dark"
+ fontSize={13}
+ />,
+ );
+
+ const claimed = terminalHarness.keys.current?.(
+ new KeyboardEvent("keydown", { key: "c", ctrlKey: true }),
+ );
+
+ expect(claimed).toBe(false);
+ });
});
describe("pane header recap", () => {
diff --git a/jarvis/ui/web/frontend/src/components/agentic/AgenticTerminal.tsx b/jarvis/ui/web/frontend/src/components/agentic/AgenticTerminal.tsx
index f6f94ce60e..ad12b89357 100644
--- a/jarvis/ui/web/frontend/src/components/agentic/AgenticTerminal.tsx
+++ b/jarvis/ui/web/frontend/src/components/agentic/AgenticTerminal.tsx
@@ -91,7 +91,7 @@ import { PaneRecap } from "./PaneRecap";
import { attachToTerminal } from "@/lib/agenticIdeApi";
import type { RecapReason, RecapSource } from "@/lib/agenticIdeApi";
import { attachTerminalBridge } from "@/lib/editActions";
-import { robustPaste } from "@/lib/clipboard";
+import { robustCopy, robustPaste } from "@/lib/clipboard";
import {
TERMINAL_FONT_STACK,
alignTerminalCells,
@@ -102,6 +102,7 @@ import {
TERMINAL_OSC_LINK_HANDLER,
} from "@/lib/terminalLinks";
import { installPasteBridge } from "./terminalPaste";
+import { installCopyBridge } from "./terminalCopy";
import { createKeyEventChain } from "./terminalKeyChain";
import { installNewlineBridge } from "./terminalNewline";
import { cancelPaneReflow, queuePaneReflow } from "./paneReflowQueue";
@@ -510,10 +511,29 @@ export function AgenticTerminal({
paste: (text) => term.paste(text),
focus: () => term.focus(),
});
- // Both keyboard bridges below claim keystrokes, and xterm holds exactly ONE
+ // The 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);
+ const isMac = /mac|iphone|ipad/i.test(navigator.userAgent);
+ // The desktop IDE reserves its platform copy chord for copying. In
+ // particular, an unselected Ctrl+C on Windows/Linux must not reach Codex
+ // as `^C`, where it cancels the current turn or exits the pane.
+ const disposeCopyBridge = installCopyBridge(
+ {
+ attachCustomKeyEventHandler: keys.add,
+ getSelection: () => term.getSelection(),
+ focus: () => term.focus(),
+ },
+ {
+ copy: robustCopy,
+ isMac,
+ onUnavailable: () =>
+ onAttachErrorRef.current?.(
+ "Could not copy the terminal selection on this machine.",
+ ),
+ },
+ );
// 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.
@@ -525,7 +545,7 @@ export function AgenticTerminal({
container,
{
readClipboard: robustPaste,
- isMac: /mac|iphone|ipad/i.test(navigator.userAgent),
+ isMac,
onUnavailable: () =>
onAttachErrorRef.current?.(
"Could not read the clipboard on this machine.",
@@ -1063,6 +1083,7 @@ export function AgenticTerminal({
ro.disconnect();
io?.disconnect();
disposeFontSync();
+ disposeCopyBridge();
disposePasteBridge();
disposeNewlineBridge();
disposeQuerySuppression();
diff --git a/jarvis/ui/web/frontend/src/components/agentic/terminalCopy.test.ts b/jarvis/ui/web/frontend/src/components/agentic/terminalCopy.test.ts
new file mode 100644
index 0000000000..6618cc4100
--- /dev/null
+++ b/jarvis/ui/web/frontend/src/components/agentic/terminalCopy.test.ts
@@ -0,0 +1,139 @@
+import { describe, expect, it, vi } from "vitest";
+
+import { installCopyBridge, isCopyChord } from "./terminalCopy";
+
+function fakeTerminal(selection = "") {
+ let handler: (event: KeyboardEvent) => boolean = () => true;
+ const dispose = vi.fn();
+ return {
+ term: {
+ attachCustomKeyEventHandler: (next: (event: KeyboardEvent) => boolean) => {
+ handler = next;
+ return dispose;
+ },
+ getSelection: () => selection,
+ focus: vi.fn(),
+ },
+ press: (init: KeyboardEventInit) =>
+ handler(new KeyboardEvent("keydown", { cancelable: true, ...init })),
+ dispose,
+ };
+}
+
+describe("recognising the copy chord", () => {
+ it("uses Ctrl+C on Windows and Linux", () => {
+ expect(
+ isCopyChord(
+ new KeyboardEvent("keydown", { key: "c", ctrlKey: true }),
+ false,
+ ),
+ ).toBe(true);
+ });
+
+ it("uses Cmd+C on macOS and leaves Ctrl+C there as terminal interrupt", () => {
+ expect(
+ isCopyChord(
+ new KeyboardEvent("keydown", { key: "c", metaKey: true }),
+ true,
+ ),
+ ).toBe(true);
+ expect(
+ isCopyChord(
+ new KeyboardEvent("keydown", { key: "c", ctrlKey: true }),
+ true,
+ ),
+ ).toBe(false);
+ });
+
+ it("accepts the traditional shifted copy chord and ignores AltGr", () => {
+ expect(
+ isCopyChord(
+ new KeyboardEvent("keydown", {
+ key: "C",
+ ctrlKey: true,
+ shiftKey: true,
+ }),
+ false,
+ ),
+ ).toBe(true);
+ expect(
+ isCopyChord(
+ new KeyboardEvent("keydown", {
+ key: "c",
+ ctrlKey: true,
+ altKey: true,
+ }),
+ false,
+ ),
+ ).toBe(false);
+ });
+});
+
+describe("copying from a terminal pane", () => {
+ it("copies xterm's canvas selection and keeps the pane focused", async () => {
+ const copy = vi.fn(async () => true);
+ const { term, press } = fakeTerminal("selected output");
+ installCopyBridge(term, { copy, isMac: false });
+
+ expect(press({ key: "c", ctrlKey: true })).toBe(false);
+ await vi.waitFor(() => expect(copy).toHaveBeenCalledWith("selected output"));
+ await vi.waitFor(() => expect(term.focus).toHaveBeenCalledOnce());
+ });
+
+ it("swallows Ctrl+C without a selection so it cannot cancel Codex", () => {
+ const copy = vi.fn(async () => true);
+ const { term, press } = fakeTerminal();
+ installCopyBridge(term, { copy, isMac: false });
+
+ expect(press({ key: "c", ctrlKey: true })).toBe(false);
+ expect(copy).not.toHaveBeenCalled();
+ });
+
+ it("leaves unrelated terminal control chords alone", () => {
+ const copy = vi.fn(async () => true);
+ const { term, press } = fakeTerminal("selected output");
+ installCopyBridge(term, { copy, isMac: false });
+
+ expect(press({ key: "z", ctrlKey: true })).toBe(true);
+ expect(copy).not.toHaveBeenCalled();
+ });
+
+ it("reports clipboard failure and unregisters cleanly", async () => {
+ const onUnavailable = vi.fn();
+ const { term, press, dispose } = fakeTerminal("selected output");
+ const cleanup = installCopyBridge(term, {
+ copy: async () => false,
+ isMac: false,
+ onUnavailable,
+ });
+
+ press({ key: "c", ctrlKey: true });
+ await vi.waitFor(() => expect(onUnavailable).toHaveBeenCalledOnce());
+ cleanup();
+ expect(dispose).toHaveBeenCalledOnce();
+ });
+
+ it("does not focus or report after the pane was disposed", async () => {
+ let finishCopy: ((copied: boolean) => void) | undefined;
+ const copy = () =>
+ new Promise<boolean>((resolve) => {
+ finishCopy = resolve;
+ });
+ const onUnavailable = vi.fn();
+ const { term, press } = fakeTerminal("selected output");
+ const cleanup = installCopyBridge(term, {
+ copy,
+ isMac: false,
+ onUnavailable,
+ });
+
+ press({ key: "c", ctrlKey: true });
+ cleanup();
+ finishCopy?.(false);
+ await Promise.resolve();
+ await Promise.resolve();
+
+ expect(onUnavailable).not.toHaveBeenCalled();
+ expect(term.focus).not.toHaveBeenCalled();
+ });
+});
diff --git a/jarvis/ui/web/frontend/src/components/agentic/terminalCopy.ts b/jarvis/ui/web/frontend/src/components/agentic/terminalCopy.ts
new file mode 100644
index 0000000000..a69ef72c03
--- /dev/null
+++ b/jarvis/ui/web/frontend/src/components/agentic/terminalCopy.ts
@@ -0,0 +1,73 @@
+/**
+ * Desktop-style copy shortcuts for an xterm pane.
+ *
+ * xterm normally turns Ctrl+C into the terminal control code `^C`. That is a
+ * useful shell convention, but it is a dangerous surprise inside Jarvis's
+ * desktop IDE: every other surface treats Ctrl+C as Copy, while a Codex pane
+ * interprets it as "cancel the current turn" (and a second press may exit).
+ *
+ * The pane therefore owns the platform copy chord. With a selection it copies
+ * xterm's canvas-backed text; without one it deliberately does nothing. In
+ * both cases the chord stays out of the PTY, so an attempted copy can never
+ * stop the agent.
+ */
+
+export interface CopyCapableTerminal {
+ attachCustomKeyEventHandler(
+ handler: (event: KeyboardEvent) => boolean,
+ ): void | (() => void);
+ getSelection(): string;
+ focus(): void;
+}
+
+export interface CopyBridgeOptions {
+ copy: (text: string) => Promise<boolean>;
+ /** True on macOS, where the desktop copy chord is Cmd+C. */
+ isMac: boolean;
+ onUnavailable?: () => void;
+}
+
+/** Match the platform copy chord without stealing AltGr input. */
+export function isCopyChord(event: KeyboardEvent, isMac: boolean): boolean {
+ if (event.altKey) return false;
+ if ((event.key || "").toLowerCase() !== "c") return false;
+ return isMac
+ ? event.metaKey && !event.ctrlKey
+ : event.ctrlKey && !event.metaKey;
+}
+
+/** Install the copy shortcut and return a cleanup function. */
+export function installCopyBridge(
+ term: CopyCapableTerminal,
+ options: CopyBridgeOptions,
+): () => void {
+ let disposed = false;
+ const disposeKeyHandler = term.attachCustomKeyEventHandler((event) => {
+ if (event.type !== "keydown") return true;
+ if (!isCopyChord(event, options.isMac)) return true;
+
+ // Claim the chord even when there is no selection. Letting that one case
+ // fall through is precisely how an innocent Copy attempt cancelled Codex.
+ event.preventDefault();
+ const selected = term.getSelection();
+ if (selected) {
+ void options
+ .copy(selected)
+ .then((copied) => {
+ if (!copied && !disposed) options.onUnavailable?.();
+ })
+ .catch(() => {
+ if (!disposed) options.onUnavailable?.();
+ })
+ .finally(() => {
+ if (!disposed) term.focus();
+ });
+ }
+ return false;
+ });
+
+ return () => {
+ disposed = true;
+ if (typeof disposeKeyHandler === "function") disposeKeyHandler();
+ };
+}