Skip to content

feat: add peer completion for bash, zsh, and fish - #16

Open
ayushsingh82 wants to merge 1 commit into
zkp2p:mainfrom
ayushsingh82:feat/shell-completion
Open

feat: add peer completion for bash, zsh, and fish#16
ayushsingh82 wants to merge 1 commit into
zkp2p:mainfrom
ayushsingh82:feat/shell-completion

Conversation

@ayushsingh82

@ayushsingh82 ayushsingh82 commented Aug 29, 2026

Copy link
Copy Markdown
Contributor

Running peer at a terminal today gives you nothing on tab — no command names, no flags. This adds peer completion <bash|zsh|fish> so you can wire up real completion:

source <(peer completion bash)
source <(peer completion zsh)
peer completion fish | source

The script isn't hand-written. It's generated from commandDefinitions and the program-level option list, so it can't drift from the actual command tree — add a command, rebuild, the completion follows.

How it's put together:

  • src/completion/index.ts walks the registry into a small tree (each node = its sub-commands + its long flags, with parent groups filled in from child paths), then renders per shell: a case "$path" lookup for bash, #compdef + _describe for zsh (keeps the command descriptions), and declarative complete -c peer lines behind a path-precise guard for fish.
  • src/commands/global-options.ts pulls the 15 global options out into a list. src/cli.ts now loops over that list instead of 15 literal program.option(...) calls, so the CLI and the completion generator are reading the same source.

It's a read-only command — passthrough: true so the raw script lands on stdout and stays source-able, errors still go out as the usual JSON envelope, and an unknown shell gets a VALIDATION_ERROR with exit 1. It's exposeInMcp: false for the same reason peer mcp is: a shell-script emitter doesn't belong in the MCP tool surface. MCP profile counts don't change.

Regenerated agents/tool-catalog.json and agents/runtime-manifest.json (CLI count 147 → 148). README gets a "Shell completion" section, plus updates to CHANGELOG.md, llms.txt, and AGENTS.md.

npm run check (247 tests, lint, typecheck, build) and npm run test:e2e (4/4) both pass; npm run audit is clean. tests/completion.test.ts covers the model builder, all three renderers, and the command including the error paths — the new files land at 100% coverage.

Adds `peer completion <bash|zsh|fish>`, a read-only generator that prints a
shell completion script built from the command registry, so it tracks the
live command tree without a hand-maintained second list.

- src/completion/index.ts folds commandDefinitions into a completion tree and
  renders a per-shell script (bash case lookup, zsh #compdef + _describe,
  fish declarative completes behind a path-precise guard)
- src/commands/global-options.ts extracts the program-level option list as
  data; src/cli.ts consumes it so the generator and the CLI describe one set
- the command is passthrough + exposeInMcp:false, keeping the script emitter
  out of the MCP tool surface, matching `peer mcp`
- regenerated agents/ catalogs; README, CHANGELOG, llms.txt, AGENTS.md updated
- tests/completion.test.ts covers the model, all three renderers, and the
  command; npm run check and npm run test:e2e pass
@ayushsingh82

ayushsingh82 commented Aug 29, 2026

Copy link
Copy Markdown
Contributor Author

Hey @ADWilkinson — heads up that I put this together on my own, it wasn't asked for, so genuinely no hard feelings if it's not something you want in the CLI.

The reason I did it: I kept reaching for tab completion while poking around with peer and there just isn't any yet. Rather than write completion scripts by hand and have them rot, I let them generate from the command registry so they stay honest as commands come and go. It's read-only and stays well away from anything protocol- or signing-related. I also tried to match how the repo already does things and moved the docs and generated catalogs along with it. Tests and the e2e run are passing.

If the approach isn't right, or you'd just rather not own this surface, tell me and I'll close it — no problem either way.

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