Skip to content

fix(open): Hold the injected rename until the input box is empty - #105

Merged
4ndreello merged 5 commits into
mainfrom
fix/rename-input-gate
Sep 23, 2026
Merged

4ndreello merged 5 commits into
mainfrom
fix/rename-input-gate

Conversation

@4ndreello

@4ndreello 4ndreello commented Sep 23, 2026 •

Copy link
Copy Markdown
Owner

codedeck open types /rename <name> + Enter into the pty as soon as the title hook writes its sidecar. The title comes from a Haiku call that takes a few seconds, so it usually lands while the user is typing the second message. Claude Code appends it to the half-typed line and the Enter submits both: Bora tamb/rename XPto xyz went out as one prompt.

The wrapper already sees every keystroke, so startPtySession now routes them through createInputGate (src/open/pty.ts). The rename is typed only when the box is clean (nothing typed since the last Enter, or since the session started) and there has been no key for 300 ms. If the user is mid-line, the name is held and typed after their next submit plus 300 ms of quiet, and it then runs as a queued slash command, as docs/harness-behaviour.md describes.

A \r does not count as a submit when it is inside a bracketed paste, after \ (line continuation), or after ESC (Alt/Option+Enter). An Enter that follows an unrecognised escape sequence (arrows, CSI-u keys) or an unknown control byte does not count either: measured on Claude Code 2.1.280, Down then Enter accepts an @ suggestion without submitting, while Enter with the menu open and no navigation submits the prompt as typed.

Chunks that are only terminal replies (DCS, OSC, CSI replies with a ? or > prefix) are ignored like focus reports. Claude queries the terminal at startup, and without this the replies armed the escape guard and pushed the rename to the second prompt.

The rename is typed at most once, and a held name is dropped on dispose. Every uncertain case (Ctrl+C, a lone Esc, arrow navigation) keeps the name held, so the worst case is a rename that lands one prompt later.

Spec: .specs/features/pty-session-rename/spec.md, Block B.

Not covered: measurements were taken in tmux only, not through the real codedeck open path (scripts/rename-gate.sh was not rerun), and other terminals' startup replies were not captured. A terminal that answers with a reply this pattern does not know falls on the escape guard, which only delays the rename.

Tests

  • npx vitest run tests/open-pty.test.ts: 65 passed
  • npx vitest run tests/open-: 8 files, 302 passed (at 59b7b46)
  • npx tsc --noEmit -p .: clean
  • npm run build && scripts/pty-gate.sh: pty path ok: tty, 137x41, /rename corrigir-auth-do-login typed, keys still flowing (run on the first commit)
  • Mutation probes, all killed: injecting regardless of dirty state, counting \r inside a paste as submit, releasing on submit without the quiet window, typing the rename twice, dropping the \ continuation check, dropping the ESC (Alt+Enter) check, removing the terminal reply skip (7 tests fail), not guarding Enter after an unknown escape (Down+Enter test fails), restoring the lazy DCS body (mixed-chunk test fails).

4ndreello and others added 5 commits September 22, 2026 22:38
Queue the sidecar name while the input line is dirty, then type it after
Enter and 300 ms of quiet. Cover the input gate, TUI wiring, and safety cases.

Co-Authored-By: Codex <noreply@openai.com>
Alt+Enter arrives as ESC CR and inserts a newline in Claude Code, so it must not release a held rename. A lone ESC before a bracketed paste no longer hides the paste start. Tighten the dispose and wiring tests so each proves its rule.
Track the current token so mention acceptance keeps the input dirty,
then let a later submit release the held rename. Handle backspaces and
uncertain edits conservatively while preserving the existing submit rules.

Co-Authored-By: Codex <noreply@openai.com>
Claude Code queries the terminal at startup and the DCS, DA1 and DECRPM replies came through the gate as unknown escapes, so the rename waited for the second prompt. Whole-chunk terminal replies are now ignored like focus reports.

Measured on Claude Code 2.1.280: Enter with the @ menu open submits, and only arrow navigation plus Enter accepts a suggestion without submitting. The escape guard covers that path, so the token tracking is gone.
A lazy DCS or OSC body could run past the reply terminator and swallow a chunk that also held typed text. Bodies now stop at ESC or BEL, and a test pins that mixed chunks still dirty the box. The pattern needs control characters, so the Sonar control character rule is silenced on that line.
@sonarqubecloud

Copy link
Copy Markdown

@4ndreello
4ndreello merged commit a6aeb43 into main Sep 23, 2026
4 checks passed
@4ndreello
4ndreello deleted the fix/rename-input-gate branch September 23, 2026 03:04
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