Repository navigation
feat(completion): carapace-bin as the third-party completion source (spike + implementation) - #243
Merged
Merged
Conversation
…commands Wire carapace-bin (MIT, ~1200 community specs, niubash#187 description menu) in behind the existing completion chain: - CarapaceCompletionPlugin: NIU_CARAPACE / PATH / bundle discovery, fish-format parsing (value<TAB>Description), 300ms hard timeout, silent degradation, per-session cache keyed by (command, preceding words, word shape, cwd) with 5-minute TTL — a warm call costs 104-146ms, so ordinary words fetch the full list once with an empty query word and are prefix-filtered locally per keystroke. - Coverage gate: winuxcmd applet TOMLs, bundle definitions and user completion files always win; the carapace source only serves commands without a local definition. - Tests: fish-format parsing, ERR/_ meta-line skipping, query-word shaping, prefix filtering with descriptions, coverage stand-down, discovery off-switch/explicit path, plus live end-to-end probes that skip when no carapace binary is installed. Bundle decision deferred: 87MB exe (17MB packed) — adding it to scripts/release/preinstall.json needs a separate owner call.
caomengxuan666
force-pushed
the
feat/carapace-completions
branch
from
October 10, 2026 04:45
472b507 to
f2a8f0e
Compare
caomengxuan666
added a commit
that referenced
this pull request
Oct 10, 2026
…notes draft (#254) - Version 1.3.4 -> 1.4.0 (workspace root + crates/niubash-runtime; Cargo.lock synced; internal niubash-runtime dep requirement aligned 1.2.5 -> 1.4.0). The rubash engine requirement stays 1.3.4: it is semver-open (^1.3.4 admits the engine's 1.4.0), and the committed [patch] resolves it to the local ../rubash worktree, whose Cargo.toml still says 1.3.4 until the engine cuts its own release. - CHANGELOG: the Unreleased section becomes [1.4.0] - 2026-10-10. Also repairs the committed merge damage from #243 (stray conflict marker and the #241 doctor-advice entry glued onto the carapace entry) and folds in the merged cycle: #235 #239 #246 #247 #250 #251 #252 #253 plus a compact rubash 1.4.0 engine summary. #240's P2-batch content stays under [1.3.4] where the file already records it (no dup). - docs/release-notes-1.4.0-draft.md: zh+en draft release notes (Added / Fixed / Performance), winuxcmd #1151/#1154-#1157 marked as in-flight for the coordinator, plus the local verification log: release build PASS (niu.exe 10.6 MB), MSIX packed unsigned with a placeholder identity (5.1 MB), wpm-source main carries all four preinstall packages, and cargo publish --dry-run chain findings (rubash -> niubash-runtime -> niubash, blocked on the engine's crates.io release). No tag, no release workflow trigger, no in-flight PRs merged.
caomengxuan666
added a commit
that referenced
this pull request
Oct 12, 2026
… integrate through the rc data layer Architecture correction before 1.4.0 (owner ruling 2026-10-12): no shell hardcodes a third-party completion provider into its source. #243 compiled CarapaceCompletionPlugin (NIU_CARAPACE discovery, Go-binary output parsing, 300 ms timeout, 5-min TTL session cache, winuxcmd-TOML yield logic) into the completion core; the provider belongs in the rc DATA layer, integrating through the protocol the shell already speaks. Removed: crates/niubash-runtime/src/completion/carapace.rs and every hook (mod declaration, CarapaceCoverage plumbing in completer.rs, the live registration test). NIU_CARAPACE never shipped in a tag, so zero compatibility debt. The protocol layer is unchanged — the three native surfaces still stand: `complete` compspecs (rubash engine), NIU_COMPDEFS compdef functions, and winuxcmd applet TOMLs / completion definition files. Put back at the data layer, per the standard bash-completion practice: - niu setup grows an opt-in question (default OFF) that appends the standard guarded carapace-bin rc snippet — the same block a bash user writes by hand, with the install requirement commented; niu ships and installs no provider. - New docs page "External Completion Providers" (SUMMARY-linked): the protocol surfaces, priority rules, carapace-bin as one example, and an honest status note — complete -F/-C hook functions resolve in-script (compgen -F) but their interactive Tab resolution remains a rubash engine follow-up; function providers speak the compdef protocol today. - Binary-level tests pin the rc route: `complete -W` wordlists and compdef hooks sourced from ~/.niubashrc serve Tab candidates through the real startup sequence, and a standard .bash completion script serves flag candidates through the bash-import channel. The --completion-probe now mirrors the REPL startup (loads compdefs, installs the completion bridge), which is what makes those probes faithful. - CHANGELOG 1.4.0 records #243 as the architecture correction it was. cargo test --no-fail-fast failure set is identical to the origin/master baseline run on the same machine (environment-bound interactive/ConPTY failures only); cargo fmt --check clean.
caomengxuan666
added a commit
that referenced
this pull request
Oct 13, 2026
… integrate through the rc data layer (#278) * refactor(completion): retire the in-core carapace provider; providers integrate through the rc data layer Architecture correction before 1.4.0 (owner ruling 2026-10-12): no shell hardcodes a third-party completion provider into its source. #243 compiled CarapaceCompletionPlugin (NIU_CARAPACE discovery, Go-binary output parsing, 300 ms timeout, 5-min TTL session cache, winuxcmd-TOML yield logic) into the completion core; the provider belongs in the rc DATA layer, integrating through the protocol the shell already speaks. Removed: crates/niubash-runtime/src/completion/carapace.rs and every hook (mod declaration, CarapaceCoverage plumbing in completer.rs, the live registration test). NIU_CARAPACE never shipped in a tag, so zero compatibility debt. The protocol layer is unchanged — the three native surfaces still stand: `complete` compspecs (rubash engine), NIU_COMPDEFS compdef functions, and winuxcmd applet TOMLs / completion definition files. Put back at the data layer, per the standard bash-completion practice: - niu setup grows an opt-in question (default OFF) that appends the standard guarded carapace-bin rc snippet — the same block a bash user writes by hand, with the install requirement commented; niu ships and installs no provider. - New docs page "External Completion Providers" (SUMMARY-linked): the protocol surfaces, priority rules, carapace-bin as one example, and an honest status note — complete -F/-C hook functions resolve in-script (compgen -F) but their interactive Tab resolution remains a rubash engine follow-up; function providers speak the compdef protocol today. - Binary-level tests pin the rc route: `complete -W` wordlists and compdef hooks sourced from ~/.niubashrc serve Tab candidates through the real startup sequence, and a standard .bash completion script serves flag candidates through the bash-import channel. The --completion-probe now mirrors the REPL startup (loads compdefs, installs the completion bridge), which is what makes those probes faithful. - CHANGELOG 1.4.0 records #243 as the architecture correction it was. cargo test --no-fail-fast failure set is identical to the origin/master baseline run on the same machine (environment-bound interactive/ConPTY failures only); cargo fmt --check clean. * feat(history): expose Shell::flush_session_history for explicit session-end writes Public API retention after the #281 ruling: the rc-0 one-shot exits return from main normally, so the provider's Drop flush carries the session-end history write on every standard path and the funnel never calls this — the method exists for embedding hosts that terminate through std::process::exit on paths the funnel does not own (a hard exit skips Drop, so the write must be made explicitly). Best-effort like every history-file write: never fails, never reaches stderr.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #187 (interaction checklist item "补全描述", A 路线). Follow-up spike on top of the 80% completion infra:
ExternalCompletionPluginalready serves the 180 winuxcmd applet TOMLs +NIU_COMPDEFS; this adds carapace-bin as the spec source for everything else (git / curl / gh / docker / …, ~1200 community specs).Spike findings (carapace-bin v1.8.0)
carapace.exe87 MB unpacked, 17.5 MB packed (windows_amd64 zip).carapace <command> fish <words...>— completer name first, then the shell, then the words after the command (last word = word under cursor, empty string right after a space). Stdout is one candidate per line in fish formatvalue\tDescription, already prefix-filtered. Stderr unused; unknown command → exit 0, no output. Meta lines to skip:ERR\t…(dynamic-spec failure channel) and a bare_placeholder. Note the bridge scripts also exportCOMP_LINE/COMP_POINT, but nested parsing works through the plain args — no env needed.git commit <TAB>returns top-level candidates;git stash push <TAB>in a non-repo emitsERR\tfatal: not a git repository), and git's top-level flag query (-) returns nothing. Static specs are solid (cargo flags, gh subcommands, docker levels). Recorded as known limitation / follow-up.Implementation
crates/niubash-runtime/src/completion/carapace.rs:CarapaceCompletionPluginregistered behind the existing chain.NIU_CARAPACE(explicit path;off/0/falsedisables), thencarapace[.exe]onPATH, then bundle locations (<exe_dir>\carapace.exe,<exe_dir>\opt\carapace\carapace.exe).(command, preceding words, word shape, cwd), 5-minute TTL. Ordinary words query with an empty last word (full list fetched once) and are prefix-filtered locally, sogit ch→git chekeystrokes hit the same cache entry — one spawn per (command, args) shape, not per keystroke. Flag-shaped words query with-and filter locally. Cache cleared oncdbecause dynamic specs (git branch lists…) are cwd-sensitive.try_wait), silent spawn/parse errors, stderr discarded — a missing/broken carapace is zero user-visible error.CompletionStaterecords every command that has a local definition; the carapace source stands down for them. Winuxcmd applet TOMLs, bundle definitions and user completion files always win; carapace covers the long tail (verified:ls --aoutput identical with and without carapace).CompletionResult::with_descriptions→ reedline suggestions, i.e. straight into the [feature] 交互体验对照三大 shell 的缺失清单:abbr/瞬态提示/描述菜单/fzf 式搜索/补全描述——逐项补齐 #187 description menu.CHANGELOG.mdentry under Unreleased.Layered delivery
Landed: discovery, fish-format integration, caching, timeout/degradation, priority gate, tests, changelog.
Deferred / follow-up:
scripts/release/preinstall.json— data above (87 MB / 17 MB, MIT). Recommendation: ship via wpm on x64 only, or expose awinuxcmd wpm install carapacehint instead of preinstalling, given the size.live_invocation_*) skip automatically when no carapace binary is installed, so CI without the spike stays green.Verification
git ch<TAB>vianiu --completion-probe "git ch"withNIU_CARAPACEset →check-attr / check-ignore / … / cherry-pick(carapace candidates); without carapace → unchanged legacy behavior (path completer).cargo test -p niubash-runtime --lib completion→ 52/52 green (11 new carapace unit tests + live registration test).host_contract::closed_stdout_pipe_does_not_print_broken_pipe_errorand 3plugins::distrosoffline tests, all verified failing on cleanorigin/master(pre-existing, unrelated).cargo fmt --checkclean.