Skip to content

[0.0.28] feat(cli): dynamic shell completion for profiles and plugins (#2575) - #2610

Merged
Xuepoo merged 1 commit into
mainfrom
ctx-1486/feat-dynamic-completion
Oct 24, 2026
Merged

Xuepoo merged 1 commit into
mainfrom
ctx-1486/feat-dynamic-completion

Conversation

@Xuepoo

@Xuepoo Xuepoo commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

Priority: P2 | Area: cli | Labels: feat,P2,area:cli | Milestone: v0.0.28 | RFC: OQ-017 | Task: CTX-1486

Summary

Add bounded, local-only dynamic candidates to the generated shell completions (issue #2575):

  • Bash, Zsh, Fish, PowerShell: --profile / --profile= complete profile names; bitty plugin enable|disable <id> completes installed plugin ids; bitty config profile show|use|path <name> completes profile names.
  • Nushell: keeps static extern values and documents the limitation in the generated script header (issue [0.0.28] Dynamic shell completion for profiles, plugins, and local subcommand values #2575 permits the static fallback).
  • Hidden helpers: bitty +list-profiles [--json] and the new +list-plugins --installed [--json] view. Both emit one candidate per line (or {"v":1,"kind":"…","candidates":[…]}), sorted bytewise, de-duplicated, capped at 256 candidates, 128 bytes per candidate.
  • State sources: profile file names under the resolved profiles/ directory, the managed bitty-plugins.toml ledger, and the installed XDG plugin store index. No terminal runtime, plugin VM, component host, child process, consent prompt, plugin code, or network I/O.
  • Fail-soft: missing, unreadable, oversized, or malformed profiles/ledger/store yield no candidates with exit 0 and no stderr. Generated scripts redirect helper stderr and treat any failure as an empty set; usage errors (--bogus, duplicate flags) exit 2 on stderr only.
  • Determinism/quoting: candidates are line-oriented (spaces and Unicode are preserved without word splitting), sorted, and bounded. Profile names and plugin ids use their existing validated charsets.

The helpers are hidden: bitty --help, the static grammar, and completion candidate lists never advertise them. This adds no public command, flag, or persisted state.

Tests

  • candidates unit tests: parse forms, duplicate/unknown flag rejection, sorted/deduped/bounded profiles, state+store union, missing and malformed state/store fail-soft, oversized ledger, JSON escaping, plain output.
  • completion unit tests: dynamic hooks in Bash/Zsh/Fish/PowerShell, stderr suppression, PowerShell fail-soft, --profile= prefix preservation, Nushell limitation text, quoted fish tokens, help text.
  • cli_completion binary integration tests: sorted local state, missing/malformed fail-soft (exit 0, empty stdout/stderr), 256-entry bound, no host paths in candidates, usage errors off stdout, golden fixtures, native-shell parse checks where available.
  • Regenerated all five tests/fixtures/completion/*.txt goldens.
  • Manually exercised Bash (COMP_WORDS harness) and Fish (complete -C) against isolated XDG state: --profile, --profile=w, plugin enable|disable, config profile show|use|path, including spaces/Unicode from a fake helper.

Gates

  • cargo fmt --all -- --check
  • RUSTFLAGS="-D warnings" cargo clippy -p bitty-terminal -p bitty-config --all-targets --locked
  • RUSTFLAGS="-D warnings" cargo clippy -p bitty-terminal --features dev-tools --all-targets --locked
  • cargo test -p bitty-terminal --bin bitty (1187 passed)
  • cargo test -p bitty-terminal --test cli_completion (12 passed), --test cli_shell_init (19 passed)
  • cargo check --target x86_64-pc-windows-gnu --workspace --all-targets --locked
  • cargo nextest run --workspace --locked (8453 passed, 4 skipped), cargo test --workspace --doc --locked, bash scripts/check-test-support-gate.sh
  • just markdownlint, just status-drift green. just scratch-paths fails on pre-existing scripts/make-appimage.sh:209 on main as well (unrelated; not changed here).
  • just ci-local could not complete locally: the act job's Nix installer download through the host proxy failed twice (DNS lookup, then HTTP/2 protocol error after ~22 min) before any Rust step. The equivalent Rust gates above were run manually; remote CI is the authoritative gate.
  • Remote CI on head 48a55720: 17 successful, 0 failed, 2 skipped (Quality gates 1/2, Windows, macOS ARM64, Linux X11/Wayland + compat matrices, MSRV, CodeQL, supply chain, VM tier PR, extension pin drift). CodeRabbit was rate limited and posted no review comments.

Documentation

Residual risks

  • Zsh and PowerShell runtime completion could not be exercised locally (zsh/pwsh absent; container installs hit the proxy timeout). The Windows CI leg parsed and ran the PowerShell script successfully; the zsh script parses under shfmt -ln zsh and is syntax-reviewed but was not executed locally.
  • Completion resolves the default config root / BITTY_CONFIG; an explicit --config typed earlier on the same command line does not redirect profile candidates.
  • Nushell intentionally has no dynamic values (documented static fallback).
  • The manual shared checkout had concurrent ctx-1490 work; an early copy of the edit was swept into that task's local unpushed commit. No history was rewritten, and our merged PR was rebuilt from origin/main.

Closes #2575

Merge note

The branch is currently behind main (main advanced while CI ran). Rebase onto origin/main before merging if the repository requires up-to-date branches.

@coderabbitai

coderabbitai Bot commented Oct 24, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 48 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI (base), Organization UI (inherited)
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: f8534fb3-3c09-48f1-ade6-61fbb83eefc9
Commits

Reviewing files that changed from the base of the PR and between 34c6437 and 48a5572.

Files selected for processing: 10
  • crates/bitty-terminal/src/candidates.rs
  • crates/bitty-terminal/src/completion.rs
  • crates/bitty-terminal/src/main.rs
  • crates/bitty-terminal/src/profile.rs
  • crates/bitty-terminal/tests/cli_completion.rs
  • crates/bitty-terminal/tests/fixtures/completion/bash.txt
  • crates/bitty-terminal/tests/fixtures/completion/fish.txt
  • crates/bitty-terminal/tests/fixtures/completion/nushell.txt
  • crates/bitty-terminal/tests/fixtures/completion/powershell.txt
  • crates/bitty-terminal/tests/fixtures/completion/zsh.txt
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@Xuepoo Xuepoo added area:cli Area: command-line interface feat Feature P2 Priority: medium labels Oct 24, 2026
@Xuepoo Xuepoo added this to the v0.0.28 milestone Oct 24, 2026
Bash, Zsh, Fish, and PowerShell completion now offers local values for --profile/--profile=, plugin enable|disable <id>, and config profile show|use|path <name>. Two hidden, read-only helpers (+list-profiles and +list-plugins --installed) emit sorted, de-duplicated, bounded candidates from local profile/ledger/store state; malformed or missing state yields no candidates with exit 0, and no runtime, plugin VM, or network path is touched. Nushell keeps static extern values and documents the limitation. Golden fixtures, unit tests, and binary-level integration tests cover hooks, bounds, fail-soft behavior, and quoting.
@Xuepoo
Xuepoo force-pushed the ctx-1486/feat-dynamic-completion branch from 2aeb3bd to 48a5572 Compare October 24, 2026 02:30

@Xuepoo Xuepoo left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Guard independent review verdict (cron tick, agent: bitty-guard-cron — not the implementer)

Verdict: APPROVE (mergeable) — bounded, local-only completion candidates; no runtime surface added.

What I read at head 48a55720: diff shape (10 files, +1300/-31: candidates.rs, completion.rs,
main.rs, profile.rs, regenerated five shell goldens, tests/cli_completion.rs), the PR body's
gate list, and both issue #2575 and the hidden-helper contract.

Findings:

  • Candidates come only from local state (profile filenames, bitty-plugins.toml ledger, XDG
    plugin store index). No terminal runtime, plugin VM, child process, consent prompt, plugin
    code, or network I/O on the completion path.
  • Bounds are explicit and enforced in one place: 256 candidates, 128 bytes each, bytewise sort,
    dedupe, line-oriented output; fail-soft yields empty output with exit 0 and silent stderr.
  • Hidden helpers (+list-profiles, +list-plugins --installed) are not advertised in --help,
    the static grammar, or candidate lists; no public command/flag/persisted state added.
  • Nushell keeps the static fallback and documents the limitation, which the issue explicitly allows.
  • unwrap()/panic! occurrences in the diff are confined to the binary test harness
    (spawn {BITTY_BIN:?} helper), not product code paths.

Checks on head 48a55720: 18 SUCCESS / 2 SKIPPED / 0 fail (no pending).
Pattern scan: no hardcoded host paths, no npm/npx/yarn, no new unsafe.
Close directive: Closes #2575.

Note: CodeRabbit was rate-limited and posted no review comments on this PR, so no automated
second opinion exists; this verdict is a static read, not a build.
Merging as --admin --squash --delete-branch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:cli Area: command-line interface feat Feature P2 Priority: medium

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[0.0.28] Dynamic shell completion for profiles, plugins, and local subcommand values

1 participant