Skip to content

fix(input): read the raw key sequence without the Ink patch (#1505) - #1670

Merged
akramcodez merged 2 commits into
Nano-Collective:mainfrom
addyCooks:fix/backspace-without-ink-patch-1505
Oct 13, 2026
Merged

akramcodez merged 2 commits into
Nano-Collective:mainfrom
addyCooks:fix/backspace-without-ink-patch-1505

Conversation

@addyCooks

@addyCooks addyCooks commented Oct 9, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes #1505

Backspace was told apart from forward Delete by key.raw, a field that only exists through a pnpm patch to Ink. pnpm patches apply inside this repo alone; the published package depends on plain Ink, so npm installs lost key.raw and Backspace fell through to forward Delete. The xterm Shift/Alt+Enter newline chords and the MCP wizard's Backspace used the same field and broke the same way.

Add useRawInput, which reads the sequence from the stdin event emitter Ink already exposes through useStdin, and use it in TextInput, UserInput and the MCP wizard. isNewlineKey now takes the sequence as an argument.

Add a guard test that fails if key.raw is read again.

Description

Fixes Backspace acting as forward Delete on npm installs of v1.31.0 (nothing happens at the end of the line, and the character to the right of the cursor is deleted mid-line).

The cause is packaging, not input handling. patches/ink@6.8.0.patch adds key.raw, and the Backspace check from bbae037 depends on it. The patch is a pnpm patchedDependencies entry, so it only applies in this repo. Dev runs and the test suite use the patched Ink, which is why this never reproduced for us.

Changes:

  • useRawInput (in text-input.tsx) reads the raw sequence from useStdin().internal_eventEmitter. The listener is prepended, so it runs before any useInput handler.
  • TextInput, UserInput and the MCP wizard use it instead of key.raw.
  • isNewlineKey(input, key, raw) takes the sequence as a third argument.
  • A guard test in text-input-keys.spec.tsx fails if key.raw is read again, because the keyboard specs pass on patched Ink either way.

Type of Change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation update

Changeset

  • Added a changeset (pnpm changeset) describing this change for the changelog

Testing

Automated Tests

  • New features include passing tests in .spec.ts/tsx files
  • All existing tests pass (pnpm test:all completes successfully)
  • Tests cover both success and error scenarios

Manual Testing

  • Tested with Ollama
  • Tested with OpenRouter
  • Tested with OpenAI-compatible API
  • Tested MCP integration (if applicable)

Checklist

  • If this was for an open issue, I was assigned to it
  • Code follows project style guidelines
  • Self-review completed
  • Documentation updated (if needed)
  • No breaking changes (or clearly documented)
  • Appropriate logging added using structured logging (see CONTRIBUTING.md)

…lective#1505)

Backspace was told apart from forward Delete by key.raw, a field that only
exists through a pnpm patch to Ink. pnpm patches apply inside this repo
alone; the published package depends on plain Ink, so npm installs lost
key.raw and Backspace fell through to forward Delete. The xterm
Shift/Alt+Enter newline chords and the MCP wizard's Backspace used the
same field and broke the same way.

Add useRawInput, which reads the sequence from the stdin event emitter Ink
already exposes through useStdin, and use it in TextInput, UserInput and
the MCP wizard. isNewlineKey now takes the sequence as an argument.

Add a guard test that fails if key.raw is read again.
@github-actions github-actions Bot added the area:tui Terminal UI label Oct 9, 2026
@github-actions

github-actions Bot commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

nc-review: comments — 2 nits

@addyCooks — a few things worth a look, none blocking.

The PR correctly removes the dependency on the pnpm-patched Ink key.raw field by introducing a useRawInput hook that reads the raw sequence directly from Ink's internal_eventEmitter, and applies it to all three call sites that previously read key.raw (TextInput, UserInput, McpStep). The change is well-scoped, matches the project's architecture, comes with a changeset, and is covered by both updated unit tests and a new filesystem guard test that fails if key.raw is read again. The fix resolves issue #1505.

⚪ nit · design · source/components/text-input.tsx:28

The useRawInput hook depends on [emitter] for its useEffect. Ink's useStdin returns a stable internal_eventEmitter reference, so [] would also work and avoid the (small) churn of remove/re-subscribe on every parent re-render where emitter identity changes. Behaviour is correct either way.

⚪ nit · tests · source/components/text-input-keys.spec.tsx:437

The guard test scans source files for the substring key.raw without word boundaries (/key\.raw/). It will also match coincidental occurrences inside longer identifiers (e.g. key.rawSequence) and inside string literals or comments that mention the field by name. Tightening to /\bkey\.raw\b/ would make the assertion tighter without losing the regression coverage it is meant to provide.


🔴 blocking · 🟠 a reviewer would ask for a change · ⚪ optional

Automated code review — correctness, security, design, tests, plus duplicates and scope. A human still decides; this is not a substitute for review and is not exhaustive. The required status checks separately cover lint, formatting, types, unused dependencies, the test suite and the build. This bot never merges. Maintainers can rerun with /re-review.

@github-actions github-actions Bot added the agent:comments nc-review left non-blocking findings label Oct 9, 2026
The regex in the guard test carried literal backspace characters instead
of \b, so it could never match and the test passed vacuously. Use real
word boundaries, and confirm it fails when a source file reads key.raw.
@addyCooks

Copy link
Copy Markdown
Collaborator Author

Hey @akramcodez,
can you pls review this one : )

@akramcodez
akramcodez merged commit 7866fdd into Nano-Collective:main Oct 13, 2026
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agent:comments nc-review left non-blocking findings area:tui Terminal UI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] (v1.31.0) (Windows/Linux) Backspace behaves as Delete in the input field (worked fine in v1.30.0)

2 participants