Registry Mirror
Skip to content

Conversation

@silvioprog

@silvioprog silvioprog commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Hunk's CLI has grown a broad surface (session, daemon, extension, markup, and their subcommands), but it ships no shell completions, so users have to remember command names, flags, and option values or keep checking --help.

Demo

Screen.Recording.2026-10-11.at.7.23.00.PM.mp4

Fix

  • Add hunk completion <bash|zsh>, which prints a static completion script.
  • Generate both scripts from the existing CLI metadata (CLI_REFERENCE_COMMANDS, COMMON_REVIEW_OPTIONS, WATCH_OPTION, and SESSION_AGENT_COMMAND_LIST), so completions stay in sync with the commands and the generated docs. Hidden options are excluded.
  • Complete commands, aliases (ext, mcp), nested subcommands, and per-command flags. A new optional values field on option metadata completes --mode, --cursor-line, and --method from their existing value constants (LAYOUT_MODE_VALUES and CURSOR_LINE_VALUES added in commandInputs.ts, UPDATE_METHOD_VALUES).
  • Bash: _hunk uses compgen -W and registers with complete -o default, so file completion still works for paths. Load it with eval "$(hunk completion bash)", which also works with macOS's default bash 3.2 (source <(...) silently loads nothing there).
  • Zsh: uses _describe with descriptions and falls back to _files. It works when loaded with source <(hunk completion zsh) after compinit, or when saved as _hunk in fpath.
  • The command is printed through the existing help output path, so main.tsx and startup.ts are unchanged. completion is reserved in BUILT_IN_CLI_COMMAND_NAMES and listed in top-level help.
  • Regenerate the CLI reference docs and add a minor changeset.

Why core

Completions need the built-in command and flag metadata, which lives in the core CLI, and the script has to stay in sync with it. An extension could not see or track that surface.

Verification

  • bun test packages/hunk/src/app/shellCompletion.test.ts packages/hunk/src/app/cli.test.ts: 174 pass. Covers a metadata drift guard, hidden flags, enum values, real bash COMPREPLY checks, bash -n/zsh -n syntax checks (skipped on Windows or when the shell is missing), and CLI parsing for completion bash|zsh, --help, and invalid shells.
  • bun run typecheck, bun run lint, bun run deps:check, bun run format:check, bun run ./scripts/generate/generate-docs.ts --check: all clean.
  • Manual smoke test on macOS with zsh and /bin/bash 3.2 (video below): top-level commands, session subcommands, review flags, --mode/--cursor-line/--method values, and file fallback for hunk diff <TAB>.

Platforms

Tested on macOS (zsh, bash 3.2). Not manually tested on Linux or Windows.

Limitations and follow-ups

  • Extension-provided commands are not completed, since the script is static.
  • --flag=value forms do not complete values; the space-separated form does.
  • Out of scope: fish/PowerShell and git ref completion.

Closes #1123

@vercel

vercel Bot commented Oct 11, 2026

Copy link
Copy Markdown

@silvioprog is attempting to deploy a commit to the Modem Team on Vercel.

A member of the Team first needs to authorize it.

@greptile-apps

greptile-apps Bot commented Oct 11, 2026

Copy link
Copy Markdown
Contributor

PR author is not in the allowed authors list.

@silvioprog
silvioprog force-pushed the feat-shell-completions branch from 4ae12de to 1cb4665 Compare October 11, 2026 22:46
@benvinegar

Copy link
Copy Markdown
Member

Pushed a follow-up fix in 999914b, keeping the metadata-driven static completion approach:

  • Skip option arguments when recognizing commands, so hunk --extension session diff --mo<TAB> correctly offers --mode.
  • Respect --: stop offering options and enum values after the pathspec separator, and delegate to file completion.
  • Include -h/--help, top-level version flags, and supported leading host flags.
  • Add Bash behavioral regressions and Zsh dispatch tests for both sourced and autoloaded scripts. The Zsh tests stub _describe/_files to verify delegation; they do not simulate interactive ZLE completion.
  • Add a patch Changeset.

Verified on Linux:

  • bun test packages/hunk/src/app/shellCompletion.test.ts packages/hunk/src/app/cli.test.ts — 178 passed.
  • bun run test — 4,775 passed, 13 skipped, 0 failed across both shards.
  • bun run typecheck, bun run lint, bun run deps:check, bun run format:check, bun run check:docs, and git diff --check passed.
  • Source and rebuilt binary emit scripts accepted by bash -n and zsh -n.

macOS/Bash 3.2 and Windows were not tested for this follow-up. Fish/PowerShell, dynamic extension/ref completion, and --flag=value value completion remain outside this change.

This comment was generated by Pi using gpt-6.1-sol

@benvinegar

Copy link
Copy Markdown
Member

Pushed another follow-up in 13c3503. This keeps static, metadata-driven completion and adds no runtime dependency.

  • Bash uses _get_comp_words_by_ref -n =: when available, with a standalone fallback compatible with Bash 3.2. The fallback preserves argument boundaries around =, :, repeated separator fragments, empty next arguments, and Unicode cursor offsets.
  • Recognize the command boundary in session reload ... -- <review-command> separately from a nested pathspec separator.
  • Complete implicit diff flags/values after --fast, while preserving explicit command selection.
  • Generate native Zsh _arguments specifications for option parsing and value completion, preserving quoted argument boundaries and sourced/autoloaded loading.
  • Add real Bash Readline/Zsh ZLE Tab integration coverage, compatibility-test instructions, a Changeset, and the Zsh compinit setup note.

Verification on Linux:

  • bun run test — 4,777 passed, 13 skipped, 0 failed.
  • bun run test:integration — 221 passed, 1 skipped, 0 failed.
  • bun run typecheck, bun run lint, bun run deps:check, bun run format:check, bun run check:docs, and git diff --check passed.
  • Built GNU Bash 3.2 locally and ran the generator/unit tests plus the standalone real-Readline suite against it — 15 passed. Current Bash was 5.3.15 and Zsh was 5.9.2.
  • Source and rebuilt binary completion output passed Bash 3.2/Bash/Zsh syntax checks.
  • Independent subagent review found and helped verify the Unicode/separator edge fixes; the final focused review found no remaining issue within that scope.

The @bomb.sh/tab experiment remains isolated and is not included in this PR. macOS and Windows were not runtime-tested for this follow-up. Bash inline-value completion, dynamic refs/extensions, and Fish/PowerShell remain outside this change; native Zsh may provide additional inline-value behavior through _arguments.

This comment was generated by Pi using gpt-6.1-sol

@benvinegar
benvinegar enabled auto-merge (squash) October 12, 2026 17:09
@benvinegar
benvinegar merged commit 74596a0 into modem-dev:main Oct 12, 2026
13 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.

Add Bash/Zsh shell completions

2 participants