Repository navigation
fix(repl): terminate the gather on a stray close inside an open group - #484
Conversation
… (niubash#482)
`{ echo c` opens a brace group; the next line `)` closes nothing — GNU
reports `syntax error near unexpected token `)'' at that line, abandons
the whole group, rc 2, and the session returns to PS1. Niubash's input
completeness scanner had no such terminal condition: the open `{` kept
the buffer "incomplete" forever, so the REPL (reedline, --noediting and
piped `-i` alike) wedged in PS2 with no diagnostic. The niubash#431
stray-close guard only audits COMPLETE groups, which this input never
became.
- scan_repl_input now emits `;;`/`;&`/`;;;&` as single operators (they
are case-clause terminators, not two `;`).
- is_repl_input_complete tracks an open `case` by phase (operand / in /
pattern / body): `)` and `;;`-family that cannot close anything are
judged complete so the armed engine parse reports GNU's diagnostic
instead of gathering forever; `a)`/`(a|b)`/`;;` inside case stay
legal so real multi-line cases still gather.
- Foreign keyword closers (`fi`/`done`/`esac`/`}`) mismatched under a
keyword opener end the gather the same way — GNU's read-time verdict;
under `(`/case frames they remain legal words (arithmetic, patterns).
- Engine side (unixwin/rubash#955): the group gather stops at the stray
token and the unclosed-`{`/`(` EOF paths report the mismatched closer
at its line instead of `unexpected end of file`.
GNU 5.2.37 script-file probes (WSL forbidden by task): `niu -i`, stdin,
`-s` and `-c` transcripts all byte-match GNU for the ticket family.
Tests: tests/issue482_stray_close_gather.rs — 8 cases covering the
ticket repro, PS1 recovery + rc=2, mid-command/case-body strays and a
normal-group battery; `cargo test -p niubash-runtime --lib repl::` 68/68.
Generated with [Devin](https://devin.ai)
Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Review verdict: hold — CI red on a one-line lockfile defect; semantics verified green locally (read-only review, left for author re-push)The blocker is mechanical and precisely root-caused. All 8 failed jobs die at Everything else was verified green locally (PR tree +
Merge order note: engine half landed first as unixwin/rubash#955 ( |
… parallel batch) (#485) ## 终审:通过,合并 Cargo.lock hunk 去除后的返工验收四项全过(head `273841c7`): 1. **diff 只剩 logo.rs** — `master...head` 仅 `crates/niubash-runtime/src/logo.rs`(6 处 `chunks_exact(N)` → `as_chunks::<N>().0.iter()`,机械改写、余量丢弃语义与 `chunks_exact` 一致);返工 commit 本身单文件。`Cargo.lock` 与 master(`8dd8407`)`cmp` 逐字节一致。 2. **chunks_exact_to_as_chunks = 0** — `cargo clippy -p niubash-runtime --all-targets`,rustc/clippy 1.99.0(与口径一致):该 lint 0 报。 3. **其余类别零变化** — 与 master 同命令全类别 tally 逐行 diff,唯一差异即 `chunks_exact_to_as_chunks` 1→0;`needless_borrow`(exact)0、`cloned_ref_to_slice_refs` 0 保持。 4. **runtime 测试绿** — `cargo test -p niubash-runtime --lib --locked`:567 passed / 0 failed。 CI:`build-and-test` 红点为 `console_window_gate` 已知 flake(`detached_builtin_only_session_allocates_zero_conhosts`,tests/console_window_gate.rs:382),其余单测面在该 job 内全 ok;cross-check ×2、cross-target ×4、smoke 全 pass —— 按容忍口径放行。另注:base 落后 master(#484 已并),但本 PR diff 与之零交集,MERGEABLE。
* docs(skill): refresh agent skill bundle for the 1.4.3 surface The corpus transcript predated the GNU invocation face and the verbatim handoff, and the prose still described the retired oh-my-niu stack (niubash#145) and the managed-block rc era (niubash#359). - corpus: recapture `niu --help` (GNU long/short option face, verbatim handoff spellings --encoded-command/-EncodedCommand/--ec + v1:, --cwd-state, --install-wt-shortcuts, plugin migrate-rc, skill install|status, portal lines, primary-only rc wording) - SKILL.md: 83/83 suite ledger (2026-10-12 re-run), argv[0] hardlink faces, generated-loader startup (before rc, NIU_PLUGIN_LOADER=off, migrate-rc), NIU_SHELL+SHELL exports, behavior notes for the gather wedge / bare-drive / negative-cache / unset-inherited / marker-zone / dolbrace / ordered-fd / CJK-readline fixes, verbatim handoff for hosts that cannot quote - references: prompt-plugins.md rewritten for the spec+lockfile+loader model; paths.md gains bare drive designators; wpm.md notes same-session visibility of fresh installs; quickref.md gains the host-level verbs - generate-skill.py: capability snapshot names `config`, the verbatim handoff, and `migrate-rc` - check-rename-clean.baseline regenerated: drops the retired winuxshrc- migration help line, absorbs docs/src residue already on master, and records the intentional WINUXSH_SHELL mention in SKILL.md Refs niubash#474 #477 #481 #482 #483 #484 #490 #943 #948 #952 niubash#359 Refs rubash#940 #947 #951 #952 #953 #955 #957 #976 #977 #979 Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com> * docs(skill): correct SHELL export claim — filled only when unset NIU_SHELL is exported unconditionally, but SHELL is backfilled with the niu.exe path only when the host left it unset (shell.rs shell_was_missing gate); a parent-supplied SHELL passes through. Aligns the NIU_SHELL paragraph with the actual behavior per review on #498. Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com> --------- Co-authored-by: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Summary
Fixes #482. A stray
)inside an OPEN multi-line grouped command made the input gather unbounded:is_repl_input_completekept waiting for the unclosed{so the REPL (reedline,--noediting, piped-i, stdin gather) sat in PS2 forever with no diagnostic. GNU abandons the group at the token:syntax error near unexpected token ')', rc 2, back to PS1. The #431 stray-close guard only audits COMPLETE groups — this input never became one.Host half:
scan_repl_inputemits;;/;&/;;;&as single operators.is_repl_input_completetracks an opencaseby phase (operand →in→ pattern → body):)and;;-family that can close nothing are judged complete so the armed engine parse prints GNU's diagnostic rather than PS2-wedging;a)/(a|b)/;;inside case remain legal so real multi-line cases gather.fi/done/esac/}) mismatched under a keyword opener end the gather the same way; under(/case frames they stay legal words (arithmetic text, patterns).Engine half: unixwin/rubash#955 (lands first — the group gather stops at the stray token and unclosed
{/(EOF paths report the mismatched closer at its line). LocalCargo.tomlpatch pointed at the fixed checkout for verification; lockfile refreshed.Refs #431, #368, #367.
Test plan
tests/issue482_stray_close_gather.rs: 8 cases — ticket repro via stdin/-s/-i/-c(GNU-verbatimline 2: syntax error near unexpected token ')'+ echo, rc 2), interactive PS1 recovery (rc=2-recoveredruns), mid-command and case-body strays, 10-form normal-group battery — all greencargo test --test issue431_stray_close_paren8/8,cargo test -p niubash-runtime --lib repl::68/68-i, stdin,-s,-c(WSL forbidden by task discipline)cargo fmt --checkclean; no full suite run (task scope: targeted only)Dependency note
Merge order: unixwin/rubash#955 first; this PR's
Cargo.lockthen pins the merged rubash commit. Left open for human review per task discipline.