Skip to content

fix(cli): completions exclude hidden/internal subcommands (v3.2.20)#63

Merged
kengio merged 6 commits into
mainfrom
fix/completions-hide
May 29, 2026
Merged

fix(cli): completions exclude hidden/internal subcommands (v3.2.20)#63
kengio merged 6 commits into
mainfrom
fix/completions-hide

Conversation

@kengio
Copy link
Copy Markdown
Contributor

@kengio kengio commented May 29, 2026

Summary

Follow-up bugfix to v3.2.19. onebrain completions <SHELL> listed hidden subcommands — unimplemented resource groups (avatar, daemon, bundle, serve, …), legacy aliases (session-init, orphan-scan, migrate, …), and hidden nested verbs (qmd setup, vault scan, …) — so onebrain <TAB> surfaced internal/deprecated commands.

Root cause

clap_complete's aot shell generators (the static generate() path we use) iterate cmd.get_subcommands() with no is_hide_set() filter#[command(hide = true)] only affects --help, not completion. Verified in clap_complete 4.6.5 source; 4.6.5 is the latest release. clap's Command has no remove-subcommand API, and the dynamic engine (which honors hide) is unstable + changes the install model.

Fix

New recursive visible_tree(&Command) -> Command (commands/completions.rs): rebuilds the command tree keeping only !is_hide_set() subcommands, then run generates completions from it. Since clap can't remove subcommands, each node is reconstructed via Command::new, copying the settings that affect completion: about, version, args (skipping the auto help/version to avoid duplicate-id panic), visible aliases, disable_help_subcommand, and propagate_version.

Adds the clap string feature (Str: From<String> is gated behind it; required for runtime-built commands).

Testing

  • Unit (visible_tree_*): top-level drop, nested-verb drop, deep-visible retention (synthetic tree).
  • Integration (real completions output): hidden top-level + legacy aliases + completions itself + help subcommand absent from the root candidate list; visible 11 commands present; nested — qmd keeps embed/status/reindex, drops setup/search/help.
  • Full suite: 589 passed, 1 ignored. All 5 shells generate valid, non-empty scripts (bash -n/zsh -n OK); stdout stays clean (0-byte stderr — brew-safe); binary name stays onebrain; arg value-lists (--harness (claude gemini), --output (text json yaml)) preserved.
  • Regression-checked: reverting the filter makes the hidden/help assertions fail.

3-round review (correctness / Rust-quality / adversarial) — the Rust-quality round caught a help-subcommand leak (dropped disable_help_subcommand), now fixed and guarded by tests.

🤖 Generated with Claude Code

@kengio kengio merged commit 523ce17 into main May 29, 2026
6 checks passed
@kengio kengio deleted the fix/completions-hide branch May 29, 2026 15:01
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