Skip to content

feat: add bash/zsh/fish shell completions - #46

Merged
aakashrajput merged 2 commits into
KlaatAI:mainfrom
Ayush7614:feat/shell-completions
Jul 20, 2026
Merged

feat: add bash/zsh/fish shell completions#46
aakashrajput merged 2 commits into
KlaatAI:mainfrom
Ayush7614:feat/shell-completions

Conversation

@Ayush7614

Copy link
Copy Markdown
Contributor

Summary

  • Adds klaatai completions <bash|zsh|fish> that prints static completion scripts (closes Shell completions for bash/zsh/fish #31).
  • Covers top-level commands (chat, run, login, logout, whoami, upgrade, serve, web, acp, completions) and their flags for both klaatai and klaatcode.
  • Reference scripts live under completions/; install hints added to the README.

Test plan

  • bun run typecheck
  • bun test (186 pass)
  • bun run bench:selfcheck
  • bun run build
  • bash -n / zsh -n on generated scripts
  • bash -c 'source … && complete -p klaatai klaatcode'
  • klaatai completions bogus exits 1 with usage
  • Manually: source <(klaatai completions bash) then tab-complete klaatai <TAB>

How tested

  • Unit tests assert both binary names + command/flag coverage for all three shells
  • bash -n and zsh -n syntax-checked the scripts (fish not installed on this machine)

Add klaatai completions <shell> to print static completion scripts
for both klaatai and klaatcode, covering top-level commands and
flags. Includes reference scripts under completions/ and README
install hints.
@Ayush7614

Copy link
Copy Markdown
Contributor Author

cc: @aakashrajput

@github-actions

Copy link
Copy Markdown
Contributor

🤖 KlaatAI Review Bot (powered by Klaatu, advisory only — a maintainer makes the real call)

Issue match
Fully addresses #31. Implements the klaatai completions <shell> command, provides static scripts for bash/zsh/fish covering both binaries and top-level commands, and adds README install hints.

Test coverage
src/commands/completions.test.ts covers happy paths well (shell recognition, script content, binary/command coverage). However, it lacks a unit test for the runCompletions("bogus") error path (verifying it exits with code 1 and writes to stderr). Additionally, the PR notes fish syntax was not verified in CI.

Correctness concerns

  1. In src/commands/completions.ts, runCompletions calls process.exit(1) on invalid input. While acceptable in a CLI, throwing an error and letting Commander handle it is cleaner and more testable.
  2. In completions/klaatai.zsh, the chat command suggests '1:directory:_files -/' for its first positional argument. Since chat takes a prompt or session ID (not a directory path), this should likely be '1:prompt:' to match the run command.

Verdict
Needs a specific fix first: correct the zsh chat argument completion and add a unit test for the invalid-shell error path before merging.

This is an automated review to help triage faster, not a gate. Nothing here blocks merging.

@aakashrajput

Copy link
Copy Markdown
Member

@Ayush7614 please take care of comments on your PR. Thanks

Extract resolveCompletions for unit-testing the unknown-shell error
path. Keep zsh chat directory completion — it matches chat [dir].
@Ayush7614

Copy link
Copy Markdown
Contributor Author

Addressed the review-bot notes in a follow-up commit:

  • Added resolveCompletions + unit coverage for the invalid-shell error path (bogus → usage error)
  • Left zsh chat directory completion as-is — the CLI’s chat [dir] argument is a project directory (_files -/ is correct, not a prompt)

@github-actions

Copy link
Copy Markdown
Contributor

🤖 KlaatAI Review Bot (powered by Klaatu, advisory only — a maintainer makes the real call)

Issue match
Fully addresses #31. Adds bash/zsh/fish completions, covers the requested top-level commands and flags, implements the klaatai completions <shell> subcommand, and adds README install hints.

Test coverage
src/commands/completions.test.ts covers shell validation, script content (both binary names, all commands, key flags), and error handling for invalid shells. Missing coverage: no automated test runs bash -n/zsh -n/fish -n to guarantee syntax validity on every CI run, and no integration test verifies the completions command registration in src/main.tsx.

Correctness concerns
The template literal escaping in src/commands/completions.ts (e.g., \${COMP_WORDS}) is correctly handled to prevent TypeScript interpolation. The zsh script correctly uses _files -/ for the chat directory argument. One minor note: runCompletions calls process.exit(1) on error, which bypasses Commander's standard error formatting, but this is acceptable for a simple print-and-exit utility. No blocking edge cases or unhandled error paths found.

Verdict
Flagging to human reviewer as ready to merge as-is.

This is an automated review to help triage faster, not a gate. Nothing here blocks merging.

@aakashrajput

Copy link
Copy Markdown
Member

@Ayush7614
Thanks a lot for your contribution! 🎉

Really appreciate you taking the time to improve KlaatCode. Your contribution helps make the project better for everyone.

If you haven't already, we'd love it if you could ⭐ star the repository and follow https://github.com/KlaatAI on GitHub to stay updated with new features and releases.

Feel free to keep using KlaatAI for your projects, and don't hesitate to open more issues, suggest ideas, or submit future PRs—we're always happy to have contributors like you in the community.

Looking forward to seeing your next contribution. Meantime please follow KlaatAI socials and if ok you can join discord too for suggestions on project, thanks Happy coding! 🚀

@aakashrajput
aakashrajput merged commit 285c2f1 into KlaatAI:main Jul 20, 2026
2 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.

Shell completions for bash/zsh/fish

2 participants