diff --git a/packages/opencode/src/cli/cmd/run/runtime.boot.ts b/packages/opencode/src/cli/cmd/run/runtime.boot.ts index b1f62178460e..282c50a6b2fb 100644 --- a/packages/opencode/src/cli/cmd/run/runtime.boot.ts +++ b/packages/opencode/src/cli/cmd/run/runtime.boot.ts @@ -82,6 +82,7 @@ function runTuiConfig(config: Config | undefined): RunTuiConfig { keybinds: config.keybinds, leader_timeout: config.leader_timeout, diff_style: config.diff_style ?? "auto", + kitty_keyboard: config.kitty_keyboard, } } diff --git a/packages/opencode/src/cli/cmd/run/runtime.lifecycle.ts b/packages/opencode/src/cli/cmd/run/runtime.lifecycle.ts index 4644d3d036fa..622024e6957f 100644 --- a/packages/opencode/src/cli/cmd/run/runtime.lifecycle.ts +++ b/packages/opencode/src/cli/cmd/run/runtime.lifecycle.ts @@ -186,7 +186,7 @@ export async function createRuntimeLifecycle(input: LifecycleInput): Promise[0] export type QuestionReject = Parameters[0] -export type RunTuiConfig = Pick +export type RunTuiConfig = Pick // Lifecycle phase of a scrollback entry. "start" opens the entry, "progress" // appends content (coalesced in the footer queue), "final" closes it. diff --git a/packages/tui/src/app.tsx b/packages/tui/src/app.tsx index 57f372ef709a..34b2083bf66b 100644 --- a/packages/tui/src/app.tsx +++ b/packages/tui/src/app.tsx @@ -196,7 +196,7 @@ export const run = Effect.fn("Tui.run")(function* (input: TuiInput) { targetFps: 60, gatherStats: false, exitOnCtrlC: false, - useKittyKeyboard: {}, + useKittyKeyboard: { events: input.config.kitty_keyboard.events }, autoFocus: false, openConsoleOnError: false, useMouse: !Flag.OPENCODE_DISABLE_MOUSE && input.config.mouse, diff --git a/packages/tui/src/config/index.tsx b/packages/tui/src/config/index.tsx index bde0bfb0718a..1d3eb9469197 100644 --- a/packages/tui/src/config/index.tsx +++ b/packages/tui/src/config/index.tsx @@ -39,6 +39,12 @@ export const Cursor = Schema.Struct({ }), }).annotate({ description: "Terminal cursor settings" }) +export const KittyKeyboard = Schema.Struct({ + events: Schema.optional(Schema.Boolean).annotate({ + description: "Request Kitty keyboard press, repeat, and release events. Enable only in terminals that support it.", + }), +}).annotate({ description: "Kitty keyboard protocol settings" }) + export const AttentionSounds = Schema.Record(AttentionSoundName, Schema.optionalKey(Schema.String)) export type AttentionSoundPaths = Schema.Schema.Type export const Attention = Schema.Struct({ @@ -72,10 +78,14 @@ export const Info = Schema.Struct({ diff_style: Schema.optional(DiffStyle), cursor: Schema.optional(Cursor), mouse: Schema.optional(Schema.Boolean).annotate({ description: "Enable or disable mouse capture (default: true)" }), + kitty_keyboard: Schema.optional(KittyKeyboard), }) export type Info = Schema.Schema.Type -export type Resolved = Omit & { +export type Resolved = Omit< + Info, + "attention" | "keybinds" | "leader_timeout" | "mouse" | "cursor" | "kitty_keyboard" +> & { attention: { enabled: boolean notifications: boolean @@ -91,6 +101,9 @@ export type Resolved = Omit { scroll_speed: 0.001, diff_style: "stacked", cursor: { blinking: false }, + kitty_keyboard: { events: true }, plugin: ["example-plugin"], }), ).toMatchObject({ @@ -39,6 +40,7 @@ test("validates config constraints", () => { attention: { volume: 1 }, diff_style: "stacked", cursor: { blinking: false }, + kitty_keyboard: { events: true }, }) expect(() => decodeInfo({ leader_timeout: 0 })).toThrow() expect(() => decodeInfo({ attention: { volume: 1.1 } })).toThrow() @@ -64,6 +66,7 @@ test("resolves host-neutral defaults", () => { expect(config.keybinds.has("terminal.suspend")).toBe(true) expect(config.keybinds.has("session.list")).toBe(true) expect(config.cursor).toBeUndefined() + expect(config.kitty_keyboard).toEqual({ events: false }) }) test("resolves overrides without mutating input", () => { @@ -81,6 +84,7 @@ test("resolves overrides without mutating input", () => { }, keybinds: { session_list: "ctrl+l" }, cursor: { blinking: false }, + kitty_keyboard: { events: true }, } const config = resolve(input, { terminalSuspend: true }) @@ -90,6 +94,7 @@ test("resolves overrides without mutating input", () => { leader_timeout: 750, attention: input.attention, cursor: { style: "block", blinking: false }, + kitty_keyboard: { events: true }, }) expect(config.keybinds.get("session.list")).toHaveLength(1) expect(input.keybinds).toEqual({ session_list: "ctrl+l" }) diff --git a/packages/web/src/content/docs/config.mdx b/packages/web/src/content/docs/config.mdx index 318f013b4119..089573e9dbe4 100644 --- a/packages/web/src/content/docs/config.mdx +++ b/packages/web/src/content/docs/config.mdx @@ -291,6 +291,8 @@ Use `OPENCODE_TUI_CONFIG` to point to a custom TUI config file. When `cursor.style` is `"default"`, the terminal default cursor is restored, so `cursor.blinking` has no effect. +Set `kitty_keyboard.events` to `true` only when your terminal reliably supports the Kitty keyboard protocol. It enables press, repeat, and release events; some xterm.js-based terminals report releases incorrectly. + Set `attention.enabled` to turn on TUI desktop notifications and sounds. See [TUI attention](/docs/tui#attention). Legacy `theme`, `keybinds`, and `tui` keys in `opencode.json` are deprecated and automatically migrated when possible. diff --git a/packages/web/src/content/docs/tui.mdx b/packages/web/src/content/docs/tui.mdx index 856ef392c748..4469405c4024 100644 --- a/packages/web/src/content/docs/tui.mdx +++ b/packages/web/src/content/docs/tui.mdx @@ -401,10 +401,25 @@ This is separate from `opencode.json`, which configures server/runtime behavior. - `diff_style` - Controls diff rendering. `"auto"` adapts to terminal width, `"stacked"` always shows a single-column layout. - `cursor` - Controls the terminal cursor in TUI input fields. `style` defaults to `"block"`, can be `"underline"`, `"line"`, or `"default"`; `blinking` defaults to `true`. When `style` is `"default"`, the terminal default cursor is restored, so `blinking` has no effect. - `mouse` - Enable or disable mouse capture in the TUI (default: `true`). When disabled, the terminal's native mouse selection/scrolling behavior is preserved. +- `kitty_keyboard.events` - Request Kitty keyboard press, repeat, and release events. Disabled by default. Enable it only in terminals with reliable Kitty keyboard support; some xterm.js-based terminals report release events incorrectly. - `attention` - Configures TUI desktop notifications and sounds. Disabled by default. Use `OPENCODE_TUI_CONFIG` to load a custom TUI config path. +### Kitty keyboard events + +To receive Kitty keyboard press, repeat, and release events, add this opt-in setting: + +```json title="tui.json" +{ + "kitty_keyboard": { + "events": true + } +} +``` + +Enable it only in terminals with reliable Kitty keyboard support. Some xterm.js-based terminals report release events incorrectly. + ### Attention The TUI can request attention for questions, permissions, session errors, and completed sessions. Enable it with `attention.enabled`; built-in events play sounds when triggered, and non-subagent events request desktop notifications only when the terminal is blurred.