Skip to content

feat(cli): grok-style clap completions with tiny rc hook - #37

Merged
Blankeos merged 3 commits into
mainfrom
feat/clap-completion-install
Sep 2, 2026
Merged

feat(cli): grok-style clap completions with tiny rc hook#37
Blankeos merged 3 commits into
mainfrom
feat/clap-completion-install

Conversation

@Blankeos

@Blankeos Blankeos commented Aug 29, 2026

Copy link
Copy Markdown
Owner

Summary

Grok-style crabcode completion <shell> on clap. Tiny rc hook; clap_complete Tab UX.

What

  • crabcode completion zsh / bash / fish / elvish / powershell — prints the script
  • --install writes the autoload file + a marked rc block appended at the end
  • Zsh: fpath + autoload + compdef (script is not sourced at startup; parsed on first Tab). Never nests inside grok installer
  • Empty Tab is clap _arguments (shared - prefix then flags, same as grok)
  • Install-time scan of .zshrc for alias foo=crabcode into #compdef (no runtime loop, no hardcoded cc)
  • clap#6282 workaround: drop the unused [PROMPT] slot so nested commands complete

Install

crabcode completion zsh --install
exec zsh

Then crabcode completion <tab> → shells; crabcode completion zsh <tab>- then flags.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Aug 29, 2026

Copy link
Copy Markdown

Deploying crabcode with  Cloudflare Pages  Cloudflare Pages

Latest commit: f843b93
Status: ✅  Deploy successful!
Preview URL: https://bf1ae921.crabcode.pages.dev
Branch Preview URL: https://feat-clap-completion-install.crabcode.pages.dev

View logs

@Blankeos
Blankeos force-pushed the feat/clap-completion-install branch 3 times, most recently from 56b69cc to 646827f Compare August 29, 2026 21:14
`crabcode completion <shell>` prints a clap_complete script.
`--install` writes it to the autoload path and a marked rc block
appended after other installers. Zsh uses fpath + autoload +
compdef so the script is not sourced at startup (parsed on first
Tab). `#compdef` includes aliases discovered from `.zshrc` at
install time. clap#6282: drop the unused prompt slot.
…HOME dotsources, strip old inline dumps

- Default shell from `$SHELL` env var (zsh/fish/elvish/pwsh, else bash)
- Script paths use `$XDG_DATA_HOME` / `$XDG_CONFIG_HOME` when set
- Bash falls back to `.bash_profile` when `.bashrc` is absent
- PowerShell hooks dotsource `"$HOME/..."` instead of bare `~`
- Strip old inline completion dumps from rc before installing marked block
- Add CI workflow for rustfmt + completion tests on PRs
- Add PR review doc
- Update README and npm/README with XDG, $SHELL default, and re-run note
- 19 completion tests pass

chore(ci): drop PR Actions workflow

Too expensive, and cargo test hits build.rs requiring remote-client assets.
Keep local completion tests; merge confidence stays 4.5/5.
clap_complete zsh scripts end with `compdef _crabcode` inside if/else/fi.
The stripper treated `compdef` as the dump end and left a stray `fi` in
.zshrc (`parse error near 'fi'`). Eat that closer (and following blanks).

Drop the in-branch PR review doc. Tests now assert no leftover `fi` and
`zsh -n` on a real clap dump.
@Blankeos
Blankeos force-pushed the feat/clap-completion-install branch from 646827f to f843b93 Compare September 1, 2026 19:42
@Blankeos

Blankeos commented Sep 1, 2026

Copy link
Copy Markdown
Owner Author

PR Review — #37 feat(cli): grok-style clap completions with tiny rc hook

Branch: feat/clap-completion-installmain
PR: #37
HEAD: f843b93 (3 commits, rebased onto main)
Merge confidence: 4.85 / 5


Body (GitHub comment)

Grok-style crabcode completion [shell] [--install]. Clap prints the script; --install writes the autoload file and a marked rc block (zsh: fpath + autoload + compdef, no startup source). Fish is file-only. Zsh #compdef picks up alias foo=crabcode from .zshrc at install time. clap#6282 workaround drops the unused [PROMPT] slot so nested commands complete on $line[1].

Follow-up f843b93 fixes the dump stripper: clap zsh scripts close compdef _crabcode inside if/else/fi; --install now eats that fi so a prior crabcode completion >> ~/.zshrc does not leave parse error near 'fi'. Review doc dropped. Rebased onto main. No DB/config migrations.

Ready to merge. Remaining 0.15 is live Tab dogfood in an interactive zsh (not blocking).


Diff summary

File Change
src/completion.rs generate / install / rc upsert / alias scan / clap#6282 patch; XDG; bash .bashrc else .bash_profile; pwsh "$HOME/..."; stripper consumes trailing fi; zsh -n on a real clap dump
src/main.rs Completion { shell: Option<Shell>, install }; default from $SHELL; drop is_completion_help root-help hack
README.md / npm/README.md --install docs, XDG, $SHELL default, re-run note for old dumps. npm copy also pulls in Upgrade + PERF.md (just sync_readme)

.github/workflows/pr.yml and PR_REVIEW_20260830_043010.md were added then removed on the branch.


Regressions?

No remaining CLI break. Previously completion was a flag-less subcommand that printed from $SHELL (zsh vs bash only). Now shell is optional, still defaults from $SHELL (zsh/fish/elvish/pwsh, else bash), and --install writes autoload + a marked rc block.

Fixed since last review:

  • --install against a real clap zsh dump no longer leaves a stray fi in .zshrc. Isolated fake-$HOME run: dump stripped, grok block preserved, crabcode hook appended, zsh -n exit 0, second --install idempotent.

Remaining (non-blocking):

  1. Old inline dumps are only stripped on --install (documented). Re-run if you used >> ~/.zshrc.
  2. Zsh hook skips compdef if compinit has not run ((( $+functions[compdef] ))). Deliberate; block is at EOF.
  3. PowerShell completions path is XDG-ish, not the usual pwsh profile completions dir. Hook dotsources "$HOME/..." (tested).
  4. crabcode completion --help now prints subcommand help, not root help. Correct clap UX.
  5. No --uninstall. CHANGELOG is git-cliff at tag time.

TUI / agent / persistence paths are untouched. Branch is 0 behind main.


Migrations?

No.

  • No SQLite / prefs schema change
  • No auth.json format change
  • No crabcode.json(c) contract change

--install mutates shell rc + autoload files (user-config install, not app state). Idempotent via markers. Stripper is the one-shot migration for old >> ~/.zshrc dumps.


Checks run (non-mutating)

Check Result
cargo fmt --check clean
cargo test --bin crabcode -- completion 20 passed (includes real clap dump + zsh -n)
rebase onto main clean, 0 behind
crabcode completion (no shell) prints zsh ($SHELL)
crabcode completion zsh #compdef crabcode; $line[1]; no ::prompt
crabcode completion --help subcommand help ([SHELL], --install)
zsh -n on generated _crabcode OK
--install under fake $HOME + unset XDG_*, real clap dump OK: no stray fi, grok-after, alias cc, idempotent
same isolation: bash / fish / pwsh / elvish writes only under fake $HOME
GitHub Actions PR CI Release plan success; no rust test job (dropped on purpose)

Checklist before merge

  • Fix strip_inline_usage_completion to consume the trailing fi
  • Assert no leftover fi / zsh -n-clean on a real clap dump
  • Drop PR_REVIEW_20260830_043010.md
  • Rebase onto main
  • Isolated --install (HOME + unset XDG_*) zsh/bash/fish/pwsh/elvish
  • cargo fmt --check
  • 20 completion-filter tests pass
  • CHANGELOG: git-cliff on next just tag — no Unreleased section
  • Live zsh Tab dogfood (crabcode completion <tab> → shells; nested commands)
  • No migration / prefs / auth follow-up

Confidence bumps

Now 4.85 / 5 (was 3.0 before f843b93).

If you do this New score
Live zsh Tab dogfood (crabcode completion <tab> → shells; crabcode completion zsh <tab>- then flags; nested commands) 5.0

Merge is fine at 4.85. The leftover 0.15 is interactive Tab UX, already unit-smoked (zsh_tab_smoke_lists_completion_and_parses).

@Blankeos
Blankeos merged commit 4b41a3e into main Sep 2, 2026
7 checks passed
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