diff --git a/docs/keybindings.md b/docs/keybindings.md index 7c40edd4b..0c5ac2563 100644 --- a/docs/keybindings.md +++ b/docs/keybindings.md @@ -43,7 +43,7 @@ app.history.search: [] | `app.clipboard.pasteImage` | `Ctrl+V` (`Alt+V` fallback on Windows) | Paste from the clipboard (image preferred, text fallback) | | `app.stt.toggle` | Unbound (hold `Space`) | Toggle speech-to-text. By default there is no key chord — hold the space bar to record (push-to-talk) and release to transcribe; bind a chord here for a press-to-toggle alternative | -On Windows Terminal, `Ctrl+V` may be handled by the terminal paste command before `omp` sees it; use the `Alt+V` fallback when clipboard image paste appears to do nothing. When the clipboard holds no image, `app.clipboard.pasteImage` pastes the clipboard text instead, so hosts that deliver only this chord (VS Code's integrated terminal when configured to forward `Ctrl+V`, Windows clipboard history via `Win+V`) work for both payload kinds. Windows Terminal also swallows `Ctrl+Enter`, so the follow-up shortcut also binds `Ctrl+Q` — the same chord GitHub Copilot CLI uses. If your existing `keybindings.yml` already assigns `Ctrl+Q` to another action, that user remap wins and follow-up keeps `Ctrl+Enter` unless you explicitly bind `app.message.followUp`. +On Windows Terminal, `Ctrl+V` may be handled by the terminal paste command before `omp` sees it; use the `Alt+V` fallback when clipboard image paste appears to do nothing. When the clipboard holds no image, `app.clipboard.pasteImage` pastes the clipboard text instead, so hosts that deliver only this chord (VS Code's integrated terminal when configured to forward `Ctrl+V`, Windows clipboard history via `Win+V`) work for both payload kinds. Windows Terminal also swallows `Ctrl+Enter`, so the `app.message.followUp` chord also binds `Ctrl+Q` — the same chord GitHub Copilot CLI uses — and the same chord submits the agent dashboard's new-agent description and hook-editor prompts. If your existing `keybindings.yml` already assigns `Ctrl+Q` to another action, that user remap wins and follow-up keeps `Ctrl+Enter` unless you explicitly bind `app.message.followUp`. Terminals that implement OSC 5522 enhanced paste can send clipboard MIME data directly to `omp`; image pastes are attached as `[Image #N]`, while text/plain paste events keep normal paste behavior. When OSC 5522 is unavailable, bracketed paste still handles text, and a pasted single image-file path is loaded as an image when the file is readable from the `omp` host. diff --git a/docs/skills/authoring-hooks.md b/docs/skills/authoring-hooks.md index 666c44ccd..7054bb3aa 100644 --- a/docs/skills/authoring-hooks.md +++ b/docs/skills/authoring-hooks.md @@ -255,7 +255,7 @@ export default function contextFilter(omp: HookAPI): void { | `custom(factory)` | Render a custom TUI component | | `theme` | Current theme object | -Pass `{ promptStyle: true }` as the fourth argument when Enter should submit and Shift+Enter should insert a newline. The default hook editor behavior keeps Enter as newline and Ctrl+Enter as submit. +Pass `{ promptStyle: true }` as the fourth argument when Enter should submit and Shift+Enter should insert a newline. The default hook editor behavior keeps Enter as newline and submits on the `app.message.followUp` chord (`Ctrl+Q` or `Ctrl+Enter`). `ctx.hasUI` is `false` in headless/print/subagent mode — always guard interactive calls. diff --git a/packages/coding-agent/CHANGELOG.md b/packages/coding-agent/CHANGELOG.md index 467263d15..3da20ebf2 100644 --- a/packages/coding-agent/CHANGELOG.md +++ b/packages/coding-agent/CHANGELOG.md @@ -1476,6 +1476,9 @@ - Fixed plan-mode subagents preserving read-only specialty tools such as `report_finding` while still stripping mutating tools ([#1998](https://github.com/can1357/oh-my-pi/issues/1998)). - Removed unreachable standalone Exa tool-suite exports and stale tool-count barrel exposure while keeping the live Exa `web_search` provider helpers ([#2093](https://github.com/can1357/oh-my-pi/issues/2093)). - Fixed `omp commit` split plans accepting hunk selectors that resolve to no parsed hunks, which crashed the apply step after the index reset and left the working tree fully unstaged ([#2098](https://github.com/can1357/oh-my-pi/issues/2098)). +### Fixed + +- Fixed the agent dashboard new-agent description and the hook editor (default hook-style mode) treating Ctrl+Q as plain text on Windows Terminal, leaving Windows users unable to submit because the terminal cannot deliver a distinct Ctrl+Enter event. Both forms now submit on the shared `app.message.followUp` chord (Ctrl+Q or Ctrl+Enter), matching the main prompt editor and any user remap of `app.message.followUp` ([#2118](https://github.com/can1357/oh-my-pi/issues/2118)). ## [15.10.5] - 2026-06-08 diff --git a/packages/coding-agent/src/modes/components/agent-dashboard.ts b/packages/coding-agent/src/modes/components/agent-dashboard.ts index 87837ddcd..4890a995e 100644 --- a/packages/coding-agent/src/modes/components/agent-dashboard.ts +++ b/packages/coding-agent/src/modes/components/agent-dashboard.ts @@ -52,7 +52,12 @@ import { discoverAgents } from "../../task/discovery"; import type { AgentDefinition, AgentSource } from "../../task/types"; import { shortenPath } from "../../tools/render-utils"; import { getEditorTheme, theme } from "../theme/theme"; -import { matchesAppInterrupt, matchesSelectDown, matchesSelectUp } from "../utils/keybinding-matchers"; +import { + matchesAppFollowUp, + matchesAppInterrupt, + matchesSelectDown, + matchesSelectUp, +} from "../utils/keybinding-matchers"; import { DynamicBorder } from "./dynamic-border"; type SourceTabId = "all" | AgentSource; @@ -652,11 +657,6 @@ export class AgentDashboard extends Container { this.#buildLayout(); } - #shouldSubmitCreateDescription(data: string): boolean { - if (matchesKey(data, "ctrl+enter")) return true; - return process.platform === "win32" && data === "\n" && this.#createDescription.trim().length > 0; - } - async #generateAgentFromDescription(rawDescription: string): Promise { const description = rawDescription.trim(); this.#createDescription = description; @@ -911,7 +911,7 @@ export class AgentDashboard extends Container { this.addChild(new Spacer(1)); const hints = this.#createGenerating ? " Generating..." - : " Ctrl+Enter: generate Enter: newline Tab: toggle scope Esc: cancel"; + : " Ctrl+Q/Ctrl+Enter: generate Enter: newline Tab: toggle scope Esc: cancel"; this.addChild(new Text(theme.fg("dim", hints), 0, 0)); } @@ -1102,7 +1102,7 @@ export class AgentDashboard extends Container { } return; } - if (!this.#createGenerating && this.#shouldSubmitCreateDescription(data)) { + if (!this.#createGenerating && matchesAppFollowUp(data)) { this.#submitCreateDescription(); return; } diff --git a/packages/coding-agent/src/modes/components/hook-editor.ts b/packages/coding-agent/src/modes/components/hook-editor.ts index 6fe845fd9..ab00709c9 100644 --- a/packages/coding-agent/src/modes/components/hook-editor.ts +++ b/packages/coding-agent/src/modes/components/hook-editor.ts @@ -3,12 +3,17 @@ * Supports Ctrl+G for external editor. * * Two modes: - * - Default (hook): Enter inserts newline, Ctrl+Enter submits, bordered popup + * - Default (hook): Enter inserts newline, the `app.message.followUp` chord + * (Ctrl+Q / Ctrl+Enter) submits, bordered popup * - Prompt-style (ask): Enter submits, Shift+Enter inserts newline, legacy ask chrome */ import { Container, Editor, matchesKey, Spacer, Text, type TUI } from "@oh-my-pi/pi-tui"; import { getEditorTheme, theme } from "../../modes/theme/theme"; -import { matchesAppExternalEditor, matchesAppInterrupt } from "../../modes/utils/keybinding-matchers"; +import { + matchesAppExternalEditor, + matchesAppFollowUp, + matchesAppInterrupt, +} from "../../modes/utils/keybinding-matchers"; import { getEditorCommand, openInEditor } from "../../utils/external-editor"; import { DynamicBorder } from "./dynamic-border"; @@ -17,10 +22,6 @@ export interface HookEditorOptions { promptStyle?: boolean; } -function isCtrlEnterSubmit(keyData: string): boolean { - return matchesKey(keyData, "ctrl+enter") || (keyData.charCodeAt(0) === 10 && keyData.length > 1); -} - export class HookEditorComponent extends Container { #editor: Editor; #onSubmitCallback: (value: string) => void; @@ -67,7 +68,7 @@ export class HookEditorComponent extends Container { // Hint const hint = this.#promptStyle ? "enter submit esc cancel ctrl+g external editor" - : "ctrl+enter submit esc cancel ctrl+g external editor"; + : "ctrl+q/ctrl+enter submit esc cancel ctrl+g external editor"; this.addChild(new Text(theme.fg("dim", hint), 1, 0)); this.addChild(new Spacer(1)); @@ -118,10 +119,12 @@ export class HookEditorComponent extends Container { this.#editor.handleInput(keyData); } - /** Hook-style: Enter=newline, Ctrl+Enter=submit (original behavior) */ + /** Hook-style: Enter=newline, app.message.followUp chord (Ctrl+Q/Ctrl+Enter) submits. */ #handleHookStyleInput(keyData: string): void { - // Ctrl+Enter to submit. Use key matching so lock-key and keypad Enter variants work. - if (isCtrlEnterSubmit(keyData)) { + // Submit on the follow-up chord. Uses the shared keybinding so Ctrl+Q works + // on Windows Terminal (#1903) and any user remap of `app.message.followUp` + // applies here too. + if (matchesAppFollowUp(keyData)) { this.#submitCurrentText(); return; } diff --git a/packages/coding-agent/src/modes/utils/keybinding-matchers.ts b/packages/coding-agent/src/modes/utils/keybinding-matchers.ts index 289fd1938..4befdee2c 100644 --- a/packages/coding-agent/src/modes/utils/keybinding-matchers.ts +++ b/packages/coding-agent/src/modes/utils/keybinding-matchers.ts @@ -1,4 +1,4 @@ -import { getKeybindings, matchesKey } from "@oh-my-pi/pi-tui"; +import { getKeybindings, type KeyId, matchesKey } from "@oh-my-pi/pi-tui"; /** * Match the coding-agent interrupt key. @@ -49,3 +49,38 @@ export function matchesAppExternalEditor(data: string): boolean { } return matchesKey(data, "ctrl+g"); } + +function matchesEffectiveKey(data: string, key: KeyId): boolean { + if ((key === "ctrl+enter" || key === "ctrl+return") && data.charCodeAt(0) === 10 && data.length > 1) { + return true; + } + return matchesKey(data, key); +} + +function matchesEffectiveKeys(data: string, keys: readonly KeyId[]): boolean { + for (const key of keys) { + if (matchesEffectiveKey(data, key)) return true; + } + return false; +} + +/** + * Match the "submit multi-line text input" keybinding (`app.message.followUp`). + * + * Used by forms where plain Enter inserts a newline and a modified-Enter chord + * submits — the main editor's follow-up handler, the agent dashboard's new-agent + * description, and the hook editor's hook-style mode. The keybinding defaults to + * `["ctrl+q", "ctrl+enter"]` so Windows Terminal (which can't deliver a distinct + * Ctrl+Enter event; #1903) still has a working chord without user remapping. + * + * Also recognizes modifier-tagged LF as Ctrl+Enter only when Ctrl+Enter is an + * effective follow-up binding. + */ +export function matchesAppFollowUp(data: string): boolean { + const keybindings = getKeybindings(); + const keys = keybindings.getKeys("app.message.followUp"); + if (keys.length > 0) { + return matchesEffectiveKeys(data, keys); + } + return matchesEffectiveKeys(data, ["ctrl+enter", "ctrl+q"]); +} diff --git a/packages/coding-agent/test/agent-dashboard-create-editor.test.ts b/packages/coding-agent/test/agent-dashboard-create-editor.test.ts index 429b982fa..8569492c8 100644 --- a/packages/coding-agent/test/agent-dashboard-create-editor.test.ts +++ b/packages/coding-agent/test/agent-dashboard-create-editor.test.ts @@ -71,7 +71,7 @@ describe("AgentDashboard create editor", () => { expect(rendered).toContain("> first line"); expect(rendered).toContain(" second line"); - expect(rendered).toContain("Ctrl+Enter: generate"); + expect(rendered).toContain("Ctrl+Q/Ctrl+Enter: generate"); expect(rendered).toContain("Enter: newline"); expect(rendered).not.toContain("Description is required."); }); @@ -105,11 +105,52 @@ describe("AgentDashboard create editor", () => { expect(rendered).toContain("> first line"); expect(rendered).toContain(" second line"); - expect(rendered).toContain("Ctrl+Enter: generate"); + expect(rendered).toContain("Ctrl+Q/Ctrl+Enter: generate"); expect(rendered).toContain("Enter: newline"); expect(rendered).not.toContain("Model registry unavailable in current session."); expect(rendered).not.toContain("Description is required."); }); + + test("submits new-agent descriptions on Ctrl+Q (Windows Terminal fallback for #2118)", async () => { + await initTheme(false); + const dashboard = await AgentDashboard.create(await makeTempCwd(), settingsStub, 24, {}); + + dashboard.handleInput("n"); + typeText(dashboard, "first line"); + dashboard.handleInput("\r"); + typeText(dashboard, "second line"); + // Ctrl+Q raw byte (0x11). Windows Terminal can't deliver a distinct + // Ctrl+Enter event, so the app.message.followUp keybinding doubles as a + // portable submit chord and must apply to the create form too. + dashboard.handleInput("\x11"); + await Bun.sleep(0); + const rendered = dashboard.render(80).join("\n").replace(ANSI_PATTERN, ""); + + expect(rendered).toContain("Model registry unavailable in current session."); + expect(rendered).not.toContain("Description is required."); + }); + + test("Ctrl+Q still works after pressing Enter for a newline (Windows Terminal)", async () => { + await initTheme(false); + const dashboard = await AgentDashboard.create(await makeTempCwd(), settingsStub, 24, {}); + + dashboard.handleInput("n"); + typeText(dashboard, "line one"); + // Windows Terminal sends bare `\r` for both Enter and Ctrl+Enter; the + // dashboard must treat `\r` as a newline so the user can keep typing. + dashboard.handleInput("\r"); + typeText(dashboard, "line two"); + const beforeSubmit = dashboard.render(80).join("\n").replace(ANSI_PATTERN, ""); + expect(beforeSubmit).toContain("> line one"); + expect(beforeSubmit).toContain(" line two"); + expect(beforeSubmit).not.toContain("Model registry unavailable in current session."); + + dashboard.handleInput("\x11"); + await Bun.sleep(0); + const afterSubmit = dashboard.render(80).join("\n").replace(ANSI_PATTERN, ""); + + expect(afterSubmit).toContain("Model registry unavailable in current session."); + }); }); describe("AgentDashboard layout", () => { diff --git a/packages/coding-agent/test/hook-editor.test.ts b/packages/coding-agent/test/hook-editor.test.ts index e2ea463f0..96c638c15 100644 --- a/packages/coding-agent/test/hook-editor.test.ts +++ b/packages/coding-agent/test/hook-editor.test.ts @@ -141,6 +141,41 @@ describe("HookEditorComponent default (hook) mode", () => { expect(onSubmit).toHaveBeenCalledWith("draft"); expect(onCancel).not.toHaveBeenCalled(); }); + it("submits the current text on Ctrl+Q (Windows Terminal fallback for #2118)", () => { + const onSubmit = vi.fn(); + const onCancel = vi.fn(); + const component = new HookEditorComponent(createTui(), "Prompt", "line 1\nline 2", onSubmit, onCancel); + + // Ctrl+Q raw byte (0x11). Windows Terminal cannot deliver a distinct + // Ctrl+Enter, so app.message.followUp also binds Ctrl+Q (#1903), and the + // hook editor must honor it for the same reason. + component.handleInput("\x11"); + + expect(onSubmit).toHaveBeenCalledTimes(1); + expect(onSubmit).toHaveBeenCalledWith("line 1\nline 2"); + expect(onCancel).not.toHaveBeenCalled(); + }); + + it("keeps Ctrl+Q working after Enter inserts a newline (Windows Terminal)", () => { + const onSubmit = vi.fn(); + const onCancel = vi.fn(); + const component = new HookEditorComponent(createTui(), "Prompt", undefined, onSubmit, onCancel); + + component.handleInput("a"); + component.handleInput("b"); + // Windows Terminal sends bare `\r` for both Enter and Ctrl+Enter; the + // hook editor must treat `\r` as a newline and reserve Ctrl+Q for submit. + component.handleInput("\r"); + component.handleInput("c"); + component.handleInput("d"); + expect(onSubmit).not.toHaveBeenCalled(); + + component.handleInput("\x11"); + + expect(onSubmit).toHaveBeenCalledTimes(1); + expect(onSubmit).toHaveBeenCalledWith("ab\ncd"); + expect(onCancel).not.toHaveBeenCalled(); + }); it("expands large paste markers when submitting on Ctrl+Enter", () => { const onSubmit = vi.fn(); diff --git a/packages/coding-agent/test/keybindings-migration.test.ts b/packages/coding-agent/test/keybindings-migration.test.ts index 53c8727d1..dbcafef51 100644 --- a/packages/coding-agent/test/keybindings-migration.test.ts +++ b/packages/coding-agent/test/keybindings-migration.test.ts @@ -3,9 +3,13 @@ import * as fs from "node:fs/promises"; import * as os from "node:os"; import * as path from "node:path"; import { KeybindingsManager } from "@oh-my-pi/pi-coding-agent/config/keybindings"; +import { matchesAppFollowUp } from "@oh-my-pi/pi-coding-agent/modes/utils/keybinding-matchers"; import { setKeybindings } from "@oh-my-pi/pi-tui"; import { YAML } from "bun"; +function ctrl(key: string): string { + return String.fromCharCode(key.toLowerCase().charCodeAt(0) & 31); +} describe("KeybindingsManager.create", () => { beforeEach(() => { setKeybindings(KeybindingsManager.inMemory()); @@ -188,11 +192,14 @@ describe("KeybindingsManager.create", () => { const manager = KeybindingsManager.inMemory({ "app.plan.toggle": "ctrl+q", }); + setKeybindings(manager); expect(manager.getKeys("app.plan.toggle")).toEqual(["ctrl+q"]); expect(manager.getKeys("app.message.followUp")).toEqual(["ctrl+enter"]); expect(manager.getDisplayString("app.message.followUp")).toBe("Ctrl+Enter"); expect(manager.getEffectiveConfig()["app.message.followUp"]).toBe("ctrl+enter"); + expect(matchesAppFollowUp(ctrl("q"))).toBe(false); + expect(matchesAppFollowUp("\x1b[13;5u")).toBe(true); }); it("keeps the Ctrl+Q follow-up default when only an unknown config key claims it (#1903)", () => {