Skip to content

feat: Add help and shell completion support to CLI - #594

Merged
razor-x merged 9 commits into
mainfrom
claude/shell-completion-generation-ka6fba
Aug 4, 2026
Merged

feat: Add help and shell completion support to CLI#594
razor-x merged 9 commits into
mainfrom
claude/shell-completion-generation-ka6fba

Conversation

@razor-x

@razor-x razor-x commented Jul 29, 2026

Copy link
Copy Markdown
Member

This PR adds comprehensive help documentation and shell completion scripts to the Seam CLI, making it more user-friendly and discoverable.

Summary

The CLI now generates help guides and completion scripts dynamically from the API blueprint. Users can run seam --help to see available commands, seam <command> --help for command details, and install completion scripts for bash, fish, and zsh shells.

Key Changes

  • Command Specification System (src/lib/command-spec.ts): Created a new module that derives a structured command specification from the API blueprint, including:

    • Converting API endpoints to command definitions with flags
    • Organizing commands into hierarchical groups
    • Defining global flags available to all commands
    • Utility functions for finding commands and groups by path
  • Help Rendering (src/lib/render-help.ts): Implemented dynamic help guide generation that:

    • Renders help for the root command, command groups, and individual commands
    • Documents flags with their descriptions, required status, and known values
    • Uses the command-line-usage library for consistent formatting
  • Shell Completion Scripts: Added renderers for three shells:

    • Bash (src/lib/completion/render-bash.ts): Case-based completion with flag value support
    • Zsh (src/lib/completion/render-zsh.ts): Descriptive completion with inline help text
    • Fish (src/lib/completion/render-fish.ts): Guard-based completion with helper functions
    • Completion Index (src/lib/completion/index.ts): Unified interface for rendering completions
  • Completion Utilities (src/lib/completion/describe.ts): Helper to safely format descriptions for shell scripts by removing special characters and truncating to fit completion menus

  • CLI Integration (src/bin/cli.ts): Updated the main CLI to:

    • Use the new help system instead of hardcoded help text
    • Support seam completion <shell> commands
    • Handle --help flag with command path awareness
  • Build Process (prepack.ts): Extended to generate and package completion scripts in a completions/ directory during build

  • Documentation (README.md): Added sections explaining help usage and shell completion installation

  • Testing: Added comprehensive test suites for command spec derivation, help rendering, and completion generation with a test blueprint fixture

Notable Implementation Details

  • The command specification system intelligently handles both API-defined endpoints and CLI-specific commands (login, logout, completion, etc.)
  • Help text is derived from markdown descriptions in the API blueprint and reduced to plain text
  • Completion scripts are generated from the bundled API definitions, ensuring they work offline and without authentication
  • The system deduplicates commands and sorts them consistently for predictable output
  • Shell-safe descriptions drop problematic characters (quotes, colons, etc.) that would break completion menus

https://claude.ai/code/session_016eYkGybhEJJE3FkaqXdwLv

claude added 7 commits July 29, 2026 03:07
Add 'seam completion <bash|fish|zsh>', which prints a completion script
derived from the API definitions bundled with the CLI. The script completes
command paths, per-command flags, and flag values for enum and boolean
parameters.

Write the same scripts to completions/ on prepack and publish them, so a
system package can install them without running the CLI.

Completions are always generated from the bundled definitions so that they
work offline and without logging in. They may lag the definitions served by
Seam when config use-remote-api-defs is enabled.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016eYkGybhEJJE3FkaqXdwLv
Help was one static page listing four examples and a single option, no
matter which command it followed. Render it from the same command spec that
drives completions instead, so it answers the command it is passed with:

  seam --help                 every top level command
  seam devices --help         the commands under seam devices
  seam devices list --help    the options seam devices list accepts

Command help documents every parameter of the endpoint, marking the required
ones and naming the values of enum and boolean parameters. An unrecognized
command path reports itself rather than printing the root guide.

Move the command spec out of lib/completion, since completions are now one of
its two consumers, and keep shell quoting in the completion renderers so help
can carry the full text of a description.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016eYkGybhEJJE3FkaqXdwLv
Adapt shell completions and help to the cached blueprint:

- prepack generates completions from the latest published API definitions
  using a temporary cache, since the blueprint is no longer bundled.
- seam completion and seam --help use the cached definitions and accept
  --update to refresh them first.
- Add the wizard command and the --update flag to the command spec, so
  they complete and appear in help.
- Attach the completion scripts to GitHub releases and install them for
  bash, fish, and zsh in the seam-bin AUR package.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016eYkGybhEJJE3FkaqXdwLv
The root guide listed every top level name in one table, burying login,
wizard, and the other commands of the CLI itself among the API routes.
Split it: a Commands section for the CLI's own commands first, then an
API Commands section for the commands that call the Seam API, then the
options and examples.

health counts as an API command, since it calls the Seam API. Deeper
guides keep a single Commands section: a group holds commands of one
kind, so the split adds nothing there.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016eYkGybhEJJE3FkaqXdwLv
Replace the packaged completion scripts with loaders that run
'seam completion' the first time the shell completes a seam command.
Installed completions now always match the CLI's current Seam API
definitions instead of the definitions packaged at release time, and
never go stale between package updates. Each shell loads its completion
file on demand, so the CLI runs once per shell session at first
completion, never at shell startup, and the loaders degrade to no
completions when the seam command is missing or cannot produce a script.

Search the whole funcstack in the zsh dispatch, since eval pushes
'(eval)' onto funcstack: the top entry is not _seam when the loader
evaluates the script, and the previous check deferred the completion
menu to the second tab.

Packing no longer needs the API definitions: the loaders are static
text, so prepack is offline again.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016eYkGybhEJJE3FkaqXdwLv
Enum values were already allowlisted and descriptions sanitized, but
command path words and flag names were embedded in single-quoted shell
strings unvalidated. Drop endpoints and flags whose names a shell could
read as syntax, so nothing from the API definitions can escape its
quoting in a generated completion script.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016eYkGybhEJJE3FkaqXdwLv
Adapt help and completions:

- Root help gains the Output section, the new -i, -y, and --json flags,
  and the piping examples, all rendered from the command spec.
- The help and completion paths write through the output so stdout
  stays clean, and report unknown commands on stderr.
- The static help block from main is dropped: renderHelp covers it.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016eYkGybhEJJE3FkaqXdwLv
@razor-x razor-x changed the title Add help and shell completion support to CLI feat: Add help and shell completion support to CLI Aug 4, 2026
claude added 2 commits August 4, 2026 04:26
Command help listed the request parameters and the CLI's own flags in
one Options table, putting --device-id next to --version. Document the
command's parameters under a Parameters section and keep Options for
the flags every seam command takes.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016eYkGybhEJJE3FkaqXdwLv
@razor-x
razor-x marked this pull request as ready for review August 4, 2026 04:29
@razor-x
razor-x merged commit d20064f into main Aug 4, 2026
12 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.

2 participants