Skip to content

fix(cli): map NumLock/CapsLock modifier-bit variants under kitty protocol - #90291

Closed
grahfmusic wants to merge 1 commit into
NousResearch:mainfrom
grahfmusic:fix/kitty-lock-bit-aliases
Closed

fix(cli): map NumLock/CapsLock modifier-bit variants under kitty protocol#90291
grahfmusic wants to merge 1 commit into
NousResearch:mainfrom
grahfmusic:fix/kitty-lock-bit-aliases

Conversation

@grahfmusic

Copy link
Copy Markdown
Contributor

Problem

With the kitty keyboard protocol push active (CSI >1u disambiguate, restored in #87511 / 03bf85d), kitty encodes lock-key state into the CSI modifier field of function keys. A plain Down with NumLock on arrives as:

  • ESC[1;129B — NumLock (bit 128)
  • ESC[1;65B — CapsLock (bit 64)
  • ESC[1;193B — both

…instead of the legacy ESC[B. Stock prompt_toolkit maps none of these, so the VT100 parser fires Escape and inserts the remainder ([1;129B) as literal text in the input line. Letters are unaffected (kitty sends those as plain text), which is why only arrow/nav keys break — and why it looks like "escape codes" appear when pressing Up/Down.

Root cause

03bf85d ("restore Kitty keyboard protocol push and complete the extended-key alias table") restored the disambiguate push and mapped the modifier families 2/3/4/5/6/7/8, but left the lock-bit modifiers (129/65/193) unmapped. Those are exactly what the disambiguate flag makes kitty emit for a plain keypress whenever NumLock/CapsLock is engaged — the most common desktop state.

Fix

Extend install_modify_other_keys_aliases() with the lock-bit modifier family:

  • plain: 129 (NumLock), 65 (CapsLock), 193 (both) → the unmodified key
  • +shift: 130/66/194 → the Shift* variant

Covered keys: arrows, Home/End, Insert/Delete/PageUp/PageDown, and the CSI-u forms of Enter/Tab/Backspace/Space (which under disambiguate also carry the lock bit).

Verification

  • \x1b[1;129BKeys.Down, \x1b[1;129AKeys.Up, \x1b[1;65B/\x1b[1;193BKeys.Down, \x1b[1;130BKeys.ShiftDown, etc. — 893 aliases install cleanly.
  • Confirmed against kitty's own encode_key_for_tty: plain Down with Hermes' pushed flags → ESC[B; same key with NumLock → ESC[1;129B.
  • Tested live: arrows, Home/End, PageUp/PageDown, Enter, Tab, Backspace, Space all work in the Hermes CLI with NumLock on in kitty.

Refs #87511, #86866.

…ocol

With the kitty keyboard protocol push active (CSI >1u disambiguate), kitty
encodes lock-key state into the CSI modifier field of function keys: a
plain Down with NumLock on arrives as ESC[1;129B (NumLock), ESC[1;65B
(CapsLock), or ESC[1;193B (both) instead of the legacy ESC[B. Stock
prompt_toolkit maps none of these, so the parser fires Escape and
inserts the remainder as literal text in the input line.

03bf85d restored the kitty push and completed the extended-key alias
table but left these lock-bit variants unmapped, so kitty + NumLock
still leaks [1;129A/B for arrow/nav keys.

Map modifier 129/65/193 (plain) and 130/66/194 (+shift) for arrows,
Home/End, Insert/Delete/PageUp/PageDown, and CSI-u Enter/Tab/Backspace/
Space to their plain keys.
@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists comp/cli CLI entry point, hermes_cli/, setup wizard needs-decision Awaiting maintainer decision before any implementation labels Aug 19, 2026
kshitijk4poor added a commit to kshitijk4poor/hermes-agent that referenced this pull request Aug 20, 2026
…s, and PUA functional keys

Follow-up to the salvaged NousResearch#89676 + NousResearch#90291 lock-bit fixes: extract a shared _lock_variants() helper and cover the sites both PRs missed - install_shift_enter_alias / install_ctrl_enter_alias / install_cmd_backspace_alias CSI-u spellings, legacy CSI-letter and CSI-tilde navigation twins derived from the existing table for ALL modifiers 1-16 (not just plain/shift), plain F1-F4 SS3 fallback, unmodified CSI-u keys (Tab/Enter/Space/Backspace), and kitty PUA functional keys (keypad, F13-F24, Ignore range) under lock bits. 8 new tests.
kshitijk4poor added a commit that referenced this pull request Aug 20, 2026
…s, and PUA functional keys

Follow-up to the salvaged #89676 + #90291 lock-bit fixes: extract a shared _lock_variants() helper and cover the sites both PRs missed - install_shift_enter_alias / install_ctrl_enter_alias / install_cmd_backspace_alias CSI-u spellings, legacy CSI-letter and CSI-tilde navigation twins derived from the existing table for ALL modifiers 1-16 (not just plain/shift), plain F1-F4 SS3 fallback, unmodified CSI-u keys (Tab/Enter/Space/Backspace), and kitty PUA functional keys (keypad, F13-F24, Ignore range) under lock bits. 8 new tests.
@kshitijk4poor

Copy link
Copy Markdown
Collaborator

Merged via #90561 with your commit cherry-picked onto current main — your authorship is preserved in the git history (git log shows your commit under your name on main). Your PR contributed the legacy CSI-letter/CSI-tilde navigation slice (ESC[1;129B arrows, ESC[3;129~ Delete, …) that every CSI-u-focused fix in this cluster missed — we combined it with #89676's CSI-u lock twins and widened it further to derive the nav twins for all modifiers 1–16 from the existing table (plus F1–F4 SS3 fallback).

Thanks for catching the slice nobody else did!

lisajlau pushed a commit to lisajlau/hermes-agent that referenced this pull request Aug 20, 2026
…s, and PUA functional keys

Follow-up to the salvaged NousResearch#89676 + NousResearch#90291 lock-bit fixes: extract a shared _lock_variants() helper and cover the sites both PRs missed - install_shift_enter_alias / install_ctrl_enter_alias / install_cmd_backspace_alias CSI-u spellings, legacy CSI-letter and CSI-tilde navigation twins derived from the existing table for ALL modifiers 1-16 (not just plain/shift), plain F1-F4 SS3 fallback, unmodified CSI-u keys (Tab/Enter/Space/Backspace), and kitty PUA functional keys (keypad, F13-F24, Ignore range) under lock bits. 8 new tests.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/cli CLI entry point, hermes_cli/, setup wizard needs-decision Awaiting maintainer decision before any implementation P2 Medium — degraded but workaround exists type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants