Skip to content

feat(mcp): add shell completion command for bash, zsh, and fish - #400

Merged
JSONbored merged 3 commits into
JSONbored:mainfrom
glorydavid03023:feat/mcp-completion
Jun 5, 2026
Merged

feat(mcp): add shell completion command for bash, zsh, and fish#400
JSONbored merged 3 commits into
JSONbored:mainfrom
glorydavid03023:feat/mcp-completion

Conversation

@glorydavid03023

Copy link
Copy Markdown
Contributor

Summary

Adds gittensory-mcp completion <bash|zsh|fish> — a standard CLI feature that prints a tab-completion script for the user's shell:

# bash (~/.bashrc)
source <(gittensory-mcp completion bash)

# zsh (~/.zshrc or fpath)
source <(gittensory-mcp completion zsh)

# fish
gittensory-mcp completion fish > ~/.config/fish/completions/gittensory-mcp.fish

It completes the top-level commands and the subcommands of profile, cache, and agent. --json returns { "shell": "...", "script": "..." } for tooling. A missing or unsupported shell errors with the supported list.

Design

The scripts are generated from a single CLI_COMMAND_SPEC (top-level command → subcommands) so completion stays in sync with the CLI surface rather than drifting from a hand-maintained list.

Why no linked issue

Additive, self-contained CLI ergonomics. No public-behavior, auth/session, schema, deploy, or frontend-architecture change, so per CONTRIBUTING this does not require an issue first. Happy to file one if preferred.

Changes

  • packages/gittensory-mcp/bin/gittensory-mcp.jscompletion dispatch; completionCommand() + buildCompletionScript() and per-shell generators; CLI_COMMAND_SPEC/COMPLETION_SHELLS constants; help-text usage line.
  • test/unit/mcp-cli.test.ts — cover all three shells, the JSON form, and the missing/unsupported-shell errors.
  • packages/gittensory-mcp/README.md — document the command with install snippets.

Contract notes

No MCP tool or HTTP/OpenAPI contract changes. Local CLI command only; the --json payload is additive.

Validation

Run locally from the repo root (environment note: portable Node v20.18.1; CI runs Node 22):

  • npm run build:mcppass (exit 0)
  • npm run typecheck (tsc --noEmit) → pass (exit 0)
  • Focused test/unit/mcp-cli.test.ts → my new cases pass:
    • prints shell completion scripts for bash, zsh, and fish
    • emits completion as machine-readable json
    • rejects missing or unsupported completion shells
  • Smoke-tested each generated script (bash complete -F, zsh #compdef, fish complete -c) and the --json output.

Honest caveat (unrelated to this change): in a full mcp-cli.test.ts run, one pre-existing test (rejects unsafe server-provided packet markdown before non-json output, which does git init + subprocess work) times out at its 10s limit under the slow portable Node on Windows. It passes on CI (Linux/Node 22); my three cases and the other 36 tests pass locally. CI on this PR gives the authoritative full-gate result.

During development I caught and fixed a temporal-dead-zone bug (the command-spec constants are referenced by runCli, which is invoked at module load, so they must be declared before that call) before pushing.

Security / privacy

No auth, cookie, CORS, GitHub App output, identity, or contributor-evidence changes. The generated scripts contain only static command/subcommand names already shown in --help.

Add `gittensory-mcp completion <bash|zsh|fish>` to print a tab-completion
script for the user's shell. It completes the top-level commands and the
subcommands of `profile`, `cache`, and `agent`, driven by a single command
spec so it stays in sync with the CLI. `--json` returns
`{ shell, script }` for tooling; a missing or unsupported shell errors with
the supported list.

Tests cover all three shells, the JSON form, and the missing/unsupported
shell errors.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

@JSONbored JSONbored left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

@glorydavid03023 thanks, this is in good shape.

A few notes:

  • The completion command is scoped to the MCP CLI surface and the README coverage matches the user-facing behavior.
  • The tests cover the command path closely enough for this slice.
  • No code changes requested from me.

Validation expected:

  • Current green CI is enough for this change.

@dosubot dosubot Bot added the lgtm label Jun 5, 2026
@JSONbored
JSONbored merged commit 2973624 into JSONbored:main Jun 5, 2026
4 checks passed
@github-project-automation github-project-automation Bot moved this from Todo to Done in gittensory - v1 roadmap Jun 5, 2026
@github-actions github-actions Bot mentioned this pull request Jun 5, 2026
12 tasks
@JSONbored JSONbored added the gittensor:feature Gittensor-scored feature linked to a feature issue — scores a 0.25x multiplier. label Jun 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gittensor:feature Gittensor-scored feature linked to a feature issue — scores a 0.25x multiplier.

Projects

No open projects
Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants