Skip to content

fix(coding-agent): prevent input corruption in external editors - #878

Open
andrewneilson wants to merge 1 commit into
PrimeIntellect-ai:mainfrom
andrewneilson:vim811
Open

fix(coding-agent): prevent input corruption in external editors#878
andrewneilson wants to merge 1 commit into
PrimeIntellect-ai:mainfrom
andrewneilson:vim811

Conversation

@andrewneilson

@andrewneilson andrewneilson commented Aug 7, 2026

Copy link
Copy Markdown

Problem

(premise of #811) Opening an external editor (vim) from the fullscreen TUI could leak terminal keyboard events into the child process. In Ghostty with Vim, this appeared as corrupted input such as w becoming ww, : becoming :;, and :q becoming :;qq.

Root cause

Kitty keyboard protocol state is scoped to the active terminal screen. The TUI could leave the alternate screen before popping its keyboard protocol state, causing cleanup to target the primary screen instead. Delayed negotiation responses or the modifyOtherKeys fallback could also reactivate a protocol while input was being drained.

Fix

  • Pop active keyboard protocols before releasing the current screen and restore them after switching screens.
  • Cancel keyboard protocol negotiation and disable active protocols while draining terminal input.
  • Share the external-editor lifecycle across the main and extension editor paths:
    write, drain, stop, spawn, clean up, restart, and render.
  • Preserve the current draft when the editor exits unsuccessfully and surface asynchronous editor failures.
  • Add focused regression coverage for protocol ordering, delayed responses, fallback cancellation, and editor lifecycle cleanup.

Scope

This does not change the external-editor keybinding, editor command selection, or daemon protocol.

Validation

  • npm run check
  • packages/coding-agent/test/external-editor.test.ts: 3 tests passed
  • packages/tui/test/terminal.test.ts: 10 tests passed
  • packages/tui/test/fullscreen.test.ts: 37 tests passed
  • Deterministic terminal check confirmed Kitty mode is popped before leaving the
    alternate screen.
  • Source Vim smoke confirmed exact :q, a single w, clean :q!, and TUI
    restoration.

Fixes #811

Note

Fix duplicate/corrupted key presses when opening external editors from the composer

  • Introduces runExternalEditor, a centralized utility that drains pending terminal input, stops the TUI, synchronously spawns the configured editor, then restarts the TUI — preventing buffered keystrokes from corrupting input after the editor exits.
  • Refactors ExtensionEditorComponent and InteractiveMode.openExternalEditor to use this shared utility; editor content is only applied on a zero exit status, and errors are surfaced via the TUI rather than propagating synchronously.
  • Fixes Kitty keyboard protocol state across alt-screen transitions in terminal.ts by introducing pushKittyProtocol/popKittyProtocol helpers that rebind the protocol to the active screen when toggling fullscreen.
  • drainInput now disables keyboard protocols before draining and re-enables them after, preventing new escape sequences from being generated mid-drain.

Macroscope summarized b780cfc.

Pop screen-local keyboard protocols before leaving the alternate screen, drain pending input before editor handoff, and share the lifecycle across both external-editor entry points.

Add regressions for protocol negotiation ordering, delayed responses, fallback cancellation, and editor cleanup.

fixes PrimeIntellect-ai#811
zhengr pushed a commit to zhengr/prime-agent that referenced this pull request Aug 8, 2026
…tellect-ai#878)

* feat(tui): add Alt+Delete as hotkey for delete word forwards

* docs(coding-agent): update keybindings table with Alt+Delete
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.

Duplicate key presses in vim composer

1 participant