Skip to content

WIP: bind/read interactive faces — #2337 #2338 #2339 - #2364

Merged
caomengxuan666 merged 5 commits into
masterfrom
fix/r4-bind-read
Oct 31, 2026
Merged

caomengxuan666 merged 5 commits into
masterfrom
fix/r4-bind-read

Conversation

@caomengxuan666

@caomengxuan666 caomengxuan666 commented Oct 31, 2026 •

Copy link
Copy Markdown
Member

WIP — cluster R4: bind/read interactive faces. Refs #2337, #2338, #2339. One commit per issue; do not merge from here — the main session collects and closes with evidence. Local verification capped at cargo check per the compile-rationing directive; pin execution is CI + the main session's batch (rubash CI does not run most tests/*.rs targets).

9e4c1d5 — #2338 bind key-table content/lists diverge

GNU ground (bash 5.3 C source; oracle 5.3.20 dumps byte-checked):

  • builtins/bind.def:344-371 query_bindings answers from rl_invoking_keyseqs over the current keymap; -l is rl_list_funmap_names over lib/readline/funmap.c funmap[] + the rl_add_defun additions in bashline.c — 176 names, not the 57-name host subset the engine listed before.
  • lib/readline/bind.c rl_invoking_keyseqs_in_map collects sequences scanning key bytes 0..255 with submaps recursed in place ⇒ byte order of the translated sequence is the listing order (fixes backward-char answering "\e[D", "\C-b" and missing "\eOD").
  • rl_function_dumper/rl_print_keybinding: leading blank line, one line per funmap name, # name (not bound) (readable) / name is not bound to any keys (plain, no trailing period). -p is now 497 lines and -P 177, matching the oracle exactly.
  • Defaults captured from the oracle's own per-keymap dumps (emacs 403 rows, emacs-meta 109, emacs-ctlx 44, vi-insert 273, vi-movement 104; sources: lib/readline/emacs_keymap.c, vi_keymap.c, bind_arrow_keys_internal lib/readline/readline.c:1385-1444).
  • builtins/bind.def:274-276: -f failure is FILE: cannot read: + strerror(errno); the std (os error 2) suffix no longer leaks.
  • DEFAULT_FUNCTION_BINDINGS keeps name + type (recorded ledger symbol, niubash mirror follows the table); content is now GNU's emacs table.

Pins: tests/issue2338_bind_tables_regressions.rs + unit pins.

c33e1a9 — #2337 bind default keymap must be immutable

GNU's keymaps are single mutable maps; unbind_command (bind.def:375-388) and unbind_keyseq (bind.def:390-427) delete DEFAULT bindings too. rubash's overlay-only registry made -r/-u on defaults silent no-ops. The registry now records exact (sequence, keymap) removals, queries subtract them, rebinding clears a record, and hosts read them via Executor::bind_removed_keyseqs (pairs with bind_registry_snapshot + generation). Oracle-verified edges kept: naming a bare keymap prefix (bind -r "\C-x") removes nothing; any session binding kind shadows its exact sequence.

Pins: tests/issue2337_bind_unbind_regressions.rs + registry unit tests.

e062a74 — #2339 read -e not connected to line editing

read.def:321-328: -e AND -E set edit (the old in-tree "-E disables" comment was wrong). On a terminal, edit_line (read.def:685-710) replaces the raw scanner: -i pre-inserted via the startup hook, -n arms rl_num_chars_to_read, -d installs the eol delimiter, and the edited line flows through the same scanner afterwards. New src/readline_editor.rs (pure editor state machine: emacs motion/word/transpose/case ops, kill ring with consecutive-kill merging + yank-pop, history recall, CSI/SS3 parsing, unit-pinned) + a strict funnel gate mirroring read.def:489-497 (non-tty shapes fall through byte-identically). -s never repaints; -t slice-polls the armed deadline and assigns the partial buffer; Windows pumps RawConsole key events (Ctrl-C char aborts as 128+SIGINT). niubash hosts keep their own reedline — this editor engages only where the engine itself reads a real terminal.

Pins: unit tests in src/readline_editor.rs + a PTY probe script (cluster workdir probes/read_e_pty.py, 17/17 against the GNU oracle) for the batch to run against rubash.

Refs #2338

GNU ground (bash 5.3 C source, oracle-verified byte-for-byte):
- builtins/bind.def:344-371 query_bindings answers from
  rl_invoking_keyseqs over the current keymap; -l is
  rl_list_funmap_names over lib/readline/funmap.c funmap[] plus the
  rl_add_defun additions in bashline.c (176 names, not a 57-name
  host-subset).
- lib/readline/bind.c rl_invoking_keyseqs_in_map collects sequences
  scanning key bytes 0..255 with submaps recursed in place, so byte
  order of the translated sequence IS the listing order;
  rl_function_dumper/rl_print_keybinding print a leading blank line,
  one line per funmap name, "# name (not bound)" readable /
  "name is not bound to any keys" plain (no trailing period).
- Keymap defaults come from lib/readline/emacs_keymap.c,
  vi_keymap.c and bind_arrow_keys_internal (lib/readline/
  readline.c:1385-1444); the standalone emacs-meta and emacs-ctlx
  maps answer with unprefixed sequences.
- builtins/bind.def:274-276: the -f failure text is
  "FILE: cannot read: " + strerror(errno) — std's "(os error 2)"
  suffix must not leak (cannot_read_reason strips it).

The bind key tables are now captured from the oracle's own dumps
per keymap (emacs 403 rows, emacs-meta 109, emacs-ctlx 44,
vi-insert 273, vi-movement 104); BindRegistry::invoking_keyseqs
merges defaults with session overlay entries (overlay wins per
sequence) under scan order. DEFAULT_FUNCTION_BINDINGS keeps its
name and type — it is a recorded ledger symbol consumed by
niubash's mirror — with its content now GNU's emacs table.

Pins: tests/issue2338_bind_tables_regressions.rs (bd01/bd24/bd25/
bd27/bd28 shapes from hunt r35) plus unit pins for the scan-order
translator and the dump formatters.
Refs #2337

GNU ground (bash 5.3 C source): readline's keymaps are single
mutable maps and the unbind paths mutate them, defaults included —
builtins/bind.def:375-388 unbind_command calls
rl_unbind_function_in_map(function, rl_get_keymap());
builtins/bind.def:390-427 unbind_keyseq ends in
rl_bind_keyseq(seq, NULL) on the current map.

rubash split the world into static default tables plus a session
overlay, and the unbind paths only ever removed overlay entries —
so `bind -u backward-char` and `bind -r "\C-b"` silently left the
defaults in place and `bind -q` kept answering for them.

The registry now records removals: unbind_keyseq_for_keymap and
the new unbind_function_for_keymap record the exact
(sequence, keymap) pair alongside removing session entries, and
invoking_keyseqs subtracts the records. Registering a sequence
again clears its record (rl_generic_bind replaces the slot, so a
rebind revives it). Hosts read the records through
Executor::bind_removed_keyseqs, paired with bind_registry_snapshot
and the generation counter — a mirrored keymap must subtract them
from the default tables exactly like the engine does.

Oracle-verified edges kept: removals are exact-sequence only —
`bind -r "\C-x"` names a keymap prefix and deletes NOTHING in GNU
(unbind_keyseq acts only when the sequence resolves to a function;
\C-x\C-? survives), and any session binding kind (-x, macro,
function) shadows the default for its exact sequence.

Pins: tests/issue2337_bind_unbind_regressions.rs plus registry
unit tests for default removal, keymap scoping and revival.
Refs #2339

GNU ground (builtins/read.def): `case 'e'` sets edit = 1
(read.def:321-323) and `case 'E'` sets edit = use_bash_completion
= 1 (read.def:326-328) — the old in-tree comment claiming -E
disables readline was wrong. When the read descriptor is a
terminal, the raw scanner is replaced by edit_line (read.def:685-
710): the -i text is pre-inserted by the startup hook
(read.def:1282 set_itext -> rl_insert_text), -n arms
rl_num_chars_to_read (read.def:569-578), -d installs the
end-of-line delimiter (read.def:583 set_eol_delim), and the line
readline returns is consumed by the same scanner as raw input.
On a non-terminal descriptor, prompt/edit/silent/initial-text are
all cleared (read.def:476-497).

rubash parsed -e/-E and threw them away: on a terminal the bytes
went through the canonical tty line discipline, so only the
kernel's ERASE/WERASE worked and every readline command (C-a/C-e/
C-k/C-u/C-y/word ops/-i) was inert — the hunt r35 PTY batch found
15 divergences in 29 cases.

Change:
- New src/readline_editor.rs: a pure character-fed editor state
  machine implementing the emacs keymap's editing semantics
  (text.c/kill.c: point motion, word ops on the rl_alphabetic
  class, transpose, case ops, kill ring with consecutive-kill
  merging and yank/yank-pop, history recall from the session
  snapshot — read lines themselves are never added), a CSI/SS3
  sequence parser for the initialized arrow/Home/End/Delete keys,
  and a termios guard (canonical/echo off, ISIG kept so ^C stays
  the executor's SIGINT path, TCSANOW so pre-typed input is never
  flushed). Scope limits are documented in the module: TAB
  completion, C-r isearch and undo are inert.
- The funnel (read_input_for_command_inner) consults the editor
  only behind a strict gate mirroring read.def:489-497: -e/-E
  armed (getopt-faithful scan — an option argument's text can
  never arm it), no staged heredoc/herestring body, and the read
  descriptor is the process's own terminal (fd 0 unbound-away, or
  a -u dup of inherited stdin). Every other shape falls through
  to the existing transports byte-identically. The edited line
  returns through the same funnel, so IFS splitting, -a, -n/-N
  trimming and backslash handling are shared with the raw path,
  matching GNU's rlbuf-through-the-scanner model.
- -s suppresses every repaint (no typed-text leak); -t polls in
  50ms slices against the armed deadline and assigns the partial
  buffer on expiry, the raw loops' own discipline; stream EOF
  returns the partial buffer as the unterminated record
  (read.def:949); ^D on an empty buffer is EOF.
- Windows: the pump runs on console_readline::RawConsole key
  events; Ctrl-C arrives as a char there and aborts the read as
  128+SIGINT. Inside niubash the host's reedline owns editing —
  this editor engages only where the engine itself reads a real
  terminal, so hosts grow no second editor path.
- The kill ring lives in BindRegistry (readline's process-global
  kill state) so it is shared across read invocations.

Pins: unit tests in readline_editor.rs for every hunt key shape,
plus probes/read_e_pty.py (in the cluster workdir) replicating
the r35 PTY cases — 17/17 against the GNU oracle; the batch runs
it against rubash. Local verification capped at cargo check per
the compile-rationing directive.
The pin asserted history-incremental-search-backward is a known
readline function. It is not a GNU name at all (it is a zsh/zle
widget name): lib/readline/funmap.c carries only the
non-incremental-* family (funmap.c:114-117), GNU's incremental
search is reverse-search-history (funmap.c:131), a tree-wide grep
finds zero hits for history-incremental, and the 5.3.20 oracle's
own bind -q history-incremental-search-backward answers
'unknown function name' (rc 1).

The product table stands: oracle bind -l lists 176 names and
READLINE_FUNCTIONS is identical to it, name for name, in order.
is_known_function gates the registry surfaces (bind -l/-p/-P
iteration, -q/-u unknown-name rejection per bind.def:351), so the
contract is GNU funmap membership, which the table already meets.

Swap the pin to reverse-search-history and pin the zsh name as
NOT known, with the citations inline, so it is not re-added by
symmetry with history-search-backward /
history-substring-search-backward. Test-only change.

Verified: cargo check --lib clean; cargo test --lib
builtins::bind::tests = 19 passed / 0 failed.

Refs #2338
@caomengxuan666
caomengxuan666 marked this pull request as ready for review October 31, 2026 16:52
@caomengxuan666
caomengxuan666 merged commit f22531b into master Oct 31, 2026
caomengxuan666 added a commit that referenced this pull request Nov 1, 2026
Test-only; no product changes. #2339 (read -e) landed in
PR #2364 without a named integration regression file. This
ports the 17 shapes from the hunt probe
(fix-r4-bind-read/probes/read_e_pty.py, r35 rs01-rs29 shapes)
into a Rust PTY harness (openpty, 0.35s termios settle, keys,
read-to-exit with deadline) with the probe's GNU expectations.

Verdicts recorded against master before this port: GNU bash
5.3.20 17/17, rubash 16/17. The one divergence, rs24 (C-d on
an empty buffer), keeps its GNU expectation (<> rc=1) under
an #[ignore] marker naming the residual — the read -e editor
(src/readline_editor.rs) does not return EOF for C-d on an
empty buffer; fixing that is a product cluster's job, not
this test-debt item's.

Refs #2389
Refs #2339
@caomengxuan666
caomengxuan666 deleted the fix/r4-bind-read branch November 2, 2026 01:10
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