Skip to content

feat(id): additive kitty browser encoder — #787 Slice C - #7348

Closed
dezren39 wants to merge 2 commits into
mainfrom
queue/12634-787-slice-c
Closed

dezren39 wants to merge 2 commits into
mainfrom
queue/12634-787-slice-c

Conversation

@dezren39

@dezren39 dezren39 commented Nov 8, 2026 •

Copy link
Copy Markdown
Member

Summary

Slice C of #787 (per doc/2026-11-01_design_id787.md §6 row C): adds kittyBytesForKey, an additive rich/kitty browser encoder, to pkgs/id/web/src/world-keyboard.ts. The legacy terminalBytesForKey is unchanged, and the new encoder is unused by the UI in this slice (inert, matching the design's phased plan; Slice F wires the opt-in).

The encoder is the browser counterpart of the Slice A Roc decoder Key.parse_events (kitty-disambiguate-v1):

  • Unmodified keys keep their legacy bytes (they already decode to the same events) — except Escape, sent as CSI-u ESC [ 27 u because a bare ESC is EventUnknown to the active decoder.
  • Modified keys carry explicit modifiers: CSI-u for Escape/Tab/Enter/Backspace (27/9/13/127 — so Tab vs Ctrl+i and Enter vs Ctrl+m are unambiguous), CSI 1 ; <mod> <letter> for arrows/Home/End, CSI <code> ; <mod> ~ for Delete/PageUp/PageDown, and CSI-u (not parameterised CSI Z, which the decoder rejects) for Shift+Tab.
  • Modified printable keys use CSI-u over the unshifted base scalar (lowercase letter / base digit-punctuation), mirroring a kitty terminal; AltGr (Ctrl+Alt composed non-letter, e.g. €) stays plain text. Meta/Dead/Process/Unidentified stay excluded.

Tests

  • New tests in world-keyboard.test.ts assert the shared rich fixtures — each expected byte string is an expect line from the Roc decoder in pkgs/id/examples/roc-world/Key.roc, so the encoder is checked against the Slice A decoder's expectations (Slice D will replace this mirroring with the compiled parity oracle).
  • Laptop: bunx vitest run src/world-keyboard.test.ts — 17/17 pass (10 legacy + 7 new); bun run typecheck (tsc --noEmit) passes.

Scope notes

Refs #787 · queue task 12634


Autofix with [code]smith
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

@dezren39
dezren39 requested a review from a team as a code owner November 8, 2026 06:21
@coderabbitai

coderabbitai Bot commented Nov 8, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 35 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 1f697b51-fe36-447c-84eb-2331d00e9328
Commits

Reviewing files that changed from the base of the PR and between 9615ae1 and d7dc062.

Files selected for processing: 2

  • pkgs/id/web/src/world-keyboard.test.ts
  • pkgs/id/web/src/world-keyboard.ts
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 8, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-08T14:51:36.300261Z d7dc062 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5a9c410f12

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread pkgs/id/web/src/world-keyboard.ts Outdated

/** The scalar a kitty terminal would name for this key event's key. */
function kittyBaseScalar(key: string, shiftKey: boolean): string {
if (/^[a-z]$/iu.test(key)) return key.toLowerCase();

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve Caps Lock case for modified letters

When Caps Lock produces a browser event such as {key: "A", ctrlKey: true, shiftKey: false}, unconditional lowercasing emits ESC[97;5u. The receiving Key.parse_events decoder only restores uppercase when Shift is present (Key.roc, parse_csi_u and normalize_shift), so this becomes lowercase a with Control rather than the reported uppercase scalar. Alt-modified uppercase letters have the same problem. Preserve the resulting case when selecting a base scalar so the new encoder maintains its decoded-event parity guarantee.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in d7dc062 (task 13060): kittyBaseScalar now lowercases a letter only when Shift is in the chord, so a Caps Lock / Alt-chord uppercase letter is sent as its reported scalar (ESC[65;5u for Ctrl+A-caps) and decodes back uppercase. Regression tests in world-keyboard.test.ts cover Ctrl/Alt uppercase without Shift and Caps+Shift lowercase; vitest 18/18 and tsc --noEmit pass on the laptop.

const base = kittyBaseScalar(key, event.shiftKey);
const code = base.codePointAt(0);
if (code === undefined || code < 32) return null;
return encode(`\x1b[${code};${modifierParameter(event)}u`);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Avoid remapping layout-resolved characters through US Shift

On layouts where Shift produces a digit, such as French AZERTY, a modified event can report {key: "1", ctrlKey: true, shiftKey: true}. The base-scalar helper leaves 1 unchanged, and this line emits ESC[49;6u; however, Key.roc's normalize_shift maps Shift plus scalar 49 to !, yielding the wrong logical key. Only retain Shift in this encoding when the decoder's normalization reconstructs the browser-reported scalar; otherwise encode the resulting scalar without triggering that transformation.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in d7dc062 (task 13060): the encoder now mirrors the decoder normalize_shift table (shiftNormalizedScalar) and only retains Shift when re-applying it reconstructs the browser-reported scalar exactly; otherwise it sends the reported scalar with Shift dropped from the modifier parameter — e.g. AZERTY Ctrl+Shift+1 now encodes ESC[49;5u (decodes to 1 with Control) instead of ESC[49;6u (which decoded to !). Tests cover the AZERTY digit cases plus the US-table cases that must stay unchanged (! and Ctrl+Shift+I) and unconsumed Shift (Space, ESC[32;6u).

Codex review on PR #7348 (findings 4505283127, 4505283130): the CSI-u encoder lowercased modified letters unconditionally, so a Caps Lock uppercase letter (no Shift in the chord) decoded back lowercase; and it trusted the decoder US-layout normalize_shift table for any Shift chord, so a layout-reported scalar such as AZERTY Shift+1 was remapped to the US shifted symbol.

kittyBaseScalar now lowercases only when Shift is in the chord, and a new shiftNormalizedScalar mirrors Key.roc normalize_shift: when re-applying Shift would not reconstruct the browser-reported scalar, the reported scalar is sent with Shift dropped from the modifier parameter. Tests cover Caps Lock case, Caps+Shift lowercase, AZERTY digits, and unconsumed Shift (Space). vitest 18/18, tsc --noEmit pass.
@dezren39

dezren39 commented Nov 8, 2026

Copy link
Copy Markdown
Member Author

Slice C follow-up from task 13060 (revival of task 12634): both Codex P2 findings are fixed in d7dc062 and dispositioned on their review threads — Caps Lock / no-Shift case is preserved, and Shift is only retained when the decoder's normalize_shift would reconstruct the reported scalar (AZERTY-style layout scalars are sent directly with Shift dropped). Laptop verification: bunx vitest run src/world-keyboard.test.ts 18/18 pass, bun run typecheck pass. This PR still does not close issue #787 (Slices D/E/F remain).

@dezren39

dezren39 commented Nov 8, 2026

Copy link
Copy Markdown
Member Author

agent-note:v1
event: done
task: 13060 (small_fix, repo-health-code-pilot; worker repo-worker-code; lane code-f)
by: repo-worker-code lane code-f
at: 2026-11-08T20:37Z

Closing PR #7348 as duplicate of PR #7734. The canonical PR #7734 (bound to task 13060) has now MERGED (merge commit 4cb8948). Per the salvage protocol, PR #7348 was diffed against the canonical PR before this close — salvage note: #7734 (comment) (nothing unique to salvage). Issue #787 stays open for Slices D/E/F.

@dezren39 dezren39 closed this Nov 8, 2026
@dezren39
dezren39 deleted the queue/12634-787-slice-c branch November 14, 2026 19:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant