Skip to content

feat(id): kitty keyboard slices E+F — SSH negotiation/framing and browser opt-in (#787) - #13267

Open
dezren39 wants to merge 2 commits into
mainfrom
felix/787-kitty-slice-e-f
Open

dezren39 wants to merge 2 commits into
mainfrom
felix/787-kitty-slice-e-f

Conversation

@dezren39

@dezren39 dezren39 commented Nov 23, 2026 •

Copy link
Copy Markdown
Member

Implements the two remaining slices of #787 per doc/2026-11-01_design_id787.md §6. Slices A–D were already on main (Roc decoder #4438, assembler, browser encoder #7734, parity oracle #12926), and the F13.4 startup probe already records kitty_keyboard support in the SSH adapter — this PR wires activation to that evidence. This PR does not close #787: the issue's final acceptance also wants one supported-terminal smoke session (and the unsupported fallback) recorded against a real terminal, which a remote test run cannot supply.

Slice E — opt-in SSH lifecycle integration (world_ssh)

  • New SshServeOptions { kitty_keyboard } (default off); serve() delegates to serve_with_options(). The serve command maps env ID_WORLD_SSH_KITTY_KEYBOARD=1 to it, following the existing ID_WORLD_* env pattern, with a status line when enabled.
  • On a raw session (never command/explorer/exec), after the F13.4 probe closes with uncontradicted kitty support, the session writes the profile push CSI > 1 u + flags query CSI ? u and verifies before admitting any key: tokens assembled during verification are held; a flags report carrying the disambiguation bit activates framing, one without it — or a 500 ms timeout — pops the owned push and falls back to legacy chunk input with held bytes untouched. One attempt per connection (no renegotiation loop).
  • While active, input runs through the Slice B assembler: one complete key token per durable Input event, exact bytes preserved, split/CSI/UTF-8 safe. Verification replies are consumed by an outstanding-query-only filter — never journaled. Framing errors, incomplete token at EOF/deadline, and input-queue loss past the activation baseline are fatal to the session (no unsafe resync).
  • Teardown pops exactly the owned push on every exit path (normal, refused, error, cancellation) before the alternate screen is left. Form answers route through the same engaged stream so the assembler cannot desync around them.
  • The assembler module moves from the id facade into id-worlds (the adapter's crate); the facade re-exports it, so id::input_framing is unchanged.

Slice F — browser opt-in (web)

  • world.ts selects richTerminalBytesForKey per connection when the page is opened with ?keyboard=kitty; legacy stays the default. Paste, the manual input form, and Meta/Dead/Process exclusions are unchanged in both modes.

Tests

  • world_ssh::kitty unit tests: flags-report grammar, outstanding-only consumption, verify flip/refusal, coalesced key order, fallback byte fidelity, split tokens.
  • world_ssh integration tests (real russh client + world event subscription): negotiate → verify → split CSI-u framed as one event, Escape vs Alt+x as distinct events, no reply bytes journaled, exactly one pop at teardown; verification-refused fallback (held key delivered, legacy resumes, no second push); no negotiation without the opt-in; no push when the terminal reports no support.
  • Web: new world-keyboard-optin.test.ts — DOM → WebSocket in both modes (legacy bare Escape 1b vs kitty CSI 27 u, Ctrl+i vs Tab, Alt+x), paste + shortcut exclusions under the opt-in.

Verification state (read this before merging)

Remote dispatches were queued while runner surfaces were exhausted; all three were still queued (no surface) when this PR was opened. Handles (branch head 00520a8a3):

  • Rust tests (cargo test -p id-worlds --features ssh world_ssh + input_framing): fp_250be4a8258466cd46be42840fee197b
  • Web tests + typecheck: fp_b7b9a7f0f820ca7eb716a93e47b95c1a
  • Clippy (id-worlds, id-cli, id, all targets/features): fp_ac36488f6ba6798b5a8af6a3cba2b93e

The jobs are recorded in the fleet queue and run when a surface frees; results land under fleet queue session result <handle>. Local verification was rustfmt only (remote-builds-only rule). No new dependencies.

Residuals named in the design

  • Queue-loss fatality is observed on the recv path against the activation baseline; a drop claimed by the send path's viewer notice in the same instant could in principle race it — the window is one loop iteration and the failure mode degrades to today's legacy notice behavior.
  • Disambiguation only, per the design: no event-type/all-keys/alternate-key flags, no keyup path.

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

felix added 2 commits November 23, 2026 12:34
…r opt-in (#787)

Slice E: on an opted-in server (SshServeOptions::kitty_keyboard; serve
command env ID_WORLD_SSH_KITTY_KEYBOARD), a raw SSH session whose F13.4
probe reported kitty keyboard support pushes kitty-disambiguate-v1,
verifies the flags report before admitting keys, frames input with the
Slice B assembler (one complete key token per durable Input event), and
pops exactly its own push on fallback and on every teardown path.
Verification failure or timeout pops and falls back to legacy chunk
input with held bytes untouched. Command, explorer and exec sessions
never negotiate; defaults are legacy everywhere.

The assembler moves from the id facade into id-worlds (the SSH adapter's
crate); the facade re-exports it, so id::input_framing is unchanged.

Slice F: the web world page selects the Slice C rich encoder per
connection via ?keyboard=kitty; legacy remains the default, paste and
the manual input form keep their existing paths.

Tests: kitty.rs unit tests (filter, verification, fallback byte
fidelity, split tokens); world_ssh integration tests (negotiate +
split-input framing + Escape/Alt distinction + teardown pop, verify
fallback, no-opt-in, unsupported terminal); web opt-in contract tests
(DOM to WebSocket, both modes, paste/shortcut exclusions).
@coderabbitai

coderabbitai Bot commented Nov 23, 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 59 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: c2457369-0024-4e78-bce5-f056e9c6f37f
Commits

Reviewing files that changed from the base of the PR and between 795b240 and 00520a8.

Files selected for processing: 11

  • doc/2026-11-02T_reference_kitty_disambiguate_v1.md
  • pkgs/id/crates/id-cli/src/commands/serve.rs
  • pkgs/id/crates/id-worlds/src/input_framing.rs
  • pkgs/id/crates/id-worlds/src/lib.rs
  • pkgs/id/crates/id-worlds/src/world_ssh.rs
  • pkgs/id/crates/id-worlds/src/world_ssh/form_io.rs
  • pkgs/id/crates/id-worlds/src/world_ssh/kitty.rs
  • pkgs/id/src/lib.rs
  • pkgs/id/web/src/world-keyboard-optin.test.ts
  • pkgs/id/web/src/world-keyboard.ts
  • pkgs/id/web/src/world.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 23, 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-23T12:46:16.140456Z 00520a8 PR opened
ℹ️ 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: 00520a8a3e

ℹ️ 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 on lines +1464 to +1468
None => {
let held = self.close_terminal_probe();
if !held.is_empty() {
return Inbound::Text(raw_frame(&SshInputFrame::Bytes(held)));
}

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 Start negotiation when the probe closes without held input

On an opted-in connection whose terminal answers the startup probe without any accompanying keystrokes, closing the probe normally returns no held bytes. This branch then continues the inner legacy receive loop without revisiting maybe_begin_kitty(), which is called only before that loop. In a quiet world, negotiation therefore stalls until another keystroke or unrelated world event arrives, and that first keystroke is forwarded with legacy chunk semantics. Recheck activation immediately after closing the probe and draining any held input.

Useful? React with 👍 / 👎.

Comment on lines +1287 to +1288
if let Some(token) = self.kitty.take_token() {
return KittyRead::Token(token);

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 Hold queued keys until verification completes

If a key arrives before the post-push flags reply, feed() queues its token while the keyboard remains in Verifying, but this unconditional dequeue immediately returns it as application input. Consequently, keys can affect the world and enter its journal before the push has been verified, including when verification subsequently fails. Only release queued tokens after entering Active or completing the fallback to legacy input.

Useful? React with 👍 / 👎.

/// the caller writes the pop. Returns whether a pop is owed.
pub fn fallback(&mut self) -> bool {
self.phase = KittyPhase::Inactive;
self.assembler = InputAssembler::new(Limits::default());

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 pending token bytes when falling back

If verification times out while a transport-split key is incomplete, replacing the assembler silently discards the received prefix. For example, receiving ESC [ 97 ; before the timeout and 5u afterward causes only 5u to reach the legacy path, turning part of a control-key sequence into ordinary application text. Preserve pending bytes in arrival order during fallback, or close the session if they cannot be safely forwarded, rather than continuing with a truncated stream.

Useful? React with 👍 / 👎.

// saw leave a gap no resynchronisation can repair (design
// §4.2). The counter is shared with the russh handler, so only
// growth past the activation baseline is this stream's loss.
if self.dropped_input.load(Ordering::Relaxed) > self.kitty_drop_baseline {

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 Track fatal queue loss independently of the notice counter

When the active SSH input queue overflows by at least 1,024 bytes, an outbound world event can erase the loss evidence before this check runs: SshIo::send() calls claim_dropped_input_notice(), which subtracts the observed count from dropped_input. The session loop selects outbound events against io.recv(), so this ordering is possible during normal operation. This counter is therefore not monotonic, and comparing it with the activation baseline can miss a fatal gap and continue journaling a truncated key stream. Use a monotonic loss counter or sticky failure flag that displaying the notice cannot clear.

Useful? React with 👍 / 👎.

This branch has not been deployed

No deployments
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.

id: Phase 13 F13.5 kitty keyboard protocol on the raw input path

1 participant