Skip to content

feat: suggest commands for mistyped CLI input#322

Open
ompathak2004 wants to merge 5 commits into
resend:mainfrom
ompathak2004:feat/command-suggestions
Open

feat: suggest commands for mistyped CLI input#322
ompathak2004 wants to merge 5 commits into
resend:mainfrom
ompathak2004:feat/command-suggestions

Conversation

@ompathak2004

@ompathak2004 ompathak2004 commented Jun 7, 2026

Copy link
Copy Markdown

Summary

  • Suggest the closest valid command when users mistype a CLI command or subcommand (Git-style "Did you mean?")
  • Supports nested commands and aliases; skips hidden/internal commands
  • Handles global flags before parsing command tokens

Closes discussion #294

  • pnpm dev template → suggests resend templates
  • pnpm dev contact → suggests resend contacts
  • pnpm dev telemetri → no suggestion (hidden command)

Summary by cubic

Adds Git-style “Did you mean?” suggestions for mistyped CLI commands and subcommands. Installed via installCommandSuggestions(program) to guide users without revealing hidden commands.

  • New Features

    • Intercepts unknown-command errors via configureOutput and suggests candidates using a Damerau–Levenshtein score.
    • Skips global flags and their values before matching, suggests full command paths, prints canonical names, and preserves existing unknown option suggestions.
  • Bug Fixes

    • Treats empty optional option values (e.g., --profile "") as present so they’re consumed before matching commands.

Written for commit 10b4197. Summary will update on new commits.

Review in cubic

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

No issues found across 3 files

Auto-approved: This PR adds a CLI command suggestion feature with comprehensive tests; its impact is limited to user-facing error messages and does not affect core business logic or data integrity, making it safe to auto-approve.

Re-trigger cubic

@github-actions github-actions Bot added the linear-synced PR has been synced to Linear label Jun 7, 2026
Comment thread src/lib/command-suggestions.ts Outdated
@gabrielmfern

Copy link
Copy Markdown
Member

I don't think we need this cast

Comment thread src/lib/command-suggestions.ts Outdated
@gabrielmfern

Copy link
Copy Markdown
Member

we also don't need this type

@gabrielmfern

Copy link
Copy Markdown
Member

imo this function should also be inlined, otherwise it's harder to read

Comment thread src/lib/command-suggestions.ts Outdated
Comment thread src/lib/command-suggestions.ts Outdated
Comment thread src/lib/command-suggestions.ts Outdated
Comment thread src/lib/command-suggestions.ts Outdated
Comment thread src/lib/command-suggestions.ts Outdated
.map((match) => match.command);
}

function editDistance(a: string, b: string): number {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

can we use some library for this? otherwise we should have some very strong unit testing for this algorithm

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

1 issue found across 2 files (changes from recent commits).

Reply with feedback, questions, or to request a fix.

Fix all with cubic | Re-trigger cubic

Comment thread src/lib/command-suggestions.ts Outdated

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

0 issues found across 2 files (changes from recent commits).

Requires human review: This PR adds 306 lines of new library code implementing a 'did you mean' command suggestion system with Levenshtein distance matching, which, despite passing tests and having no detected issues, is a non-trivial feature in a CLI tool that could affect user interaction and debugging paths,...

Re-trigger cubic

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

linear-synced PR has been synced to Linear

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants