Skip to content

feat(cli): suggest the nearest command on engine-intercepted unknowns - #104

Merged
jpage-godaddy merged 4 commits into
mainfrom
feat/unknown-command-suggestions
Aug 25, 2026
Merged

feat(cli): suggest the nearest command on engine-intercepted unknowns#104
jpage-godaddy merged 4 commits into
mainfrom
feat/unknown-command-suggestions

Conversation

@qcai-godaddy

@qcai-godaddy qcai-godaddy commented Aug 25, 2026

Copy link
Copy Markdown
Collaborator

Summary

cli-engine intercepts unknown group commands before clap parses, to emit structured unknown command "X" for "Y" errors. That early return bypasses clap's suggestion machinery — stock cli-engine gives no hint (e.g. gddy domian → unknown command "domian" for "gddy").

This change adds nearest-match hints on that path for top-level and nested typos, same plain message for humans and agents. In an interactive TTY, an optional Did you mean domain? (Y/n) prompt re-dispatches on accept. Agents, pipes, and non-TTY runs never prompt — they get the hint in the error and exit non-zero.

Mistyped commands now point at the closest real command instead of just failing:

$ gddy domian
unknown command "domian" for "gddy" — did you mean "domain"?

$ gddy domain lst
unknown command "lst" for "gddy domain" — did you mean "list"?

Testing

cli-engine local:

  • cargo fmt --check
  • cargo clippy --all-targets -- -D warnings (zero warnings)
  • cargo test (foundation 290 + unit/integration suites)
  • cargo doc -D warnings
  • New unit + integration tests for edit distance, nearest match, alias/hidden
    handling, -- operands, and interactive decline paths

Integration against gddy:

  • domaon / domian → suggest domain; dm → no hint
  • two typos: domian lstdid you mean "gddy domain list"?
  • leaf typo + operand domain avaliable example.com"gddy domain available example.com"
  • domain lst → suggest list; domain xyzzy → no hint
  • domain -- lst → clap error, no hint (operand after --)
  • Interactive (pty): y auto-runs gddy domain (exit 0); n → error (exit 1)

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR improves cli-engine’s early “unknown command” interception path by adding nearest-match suggestions (and an optional interactive correction prompt) so typos in top-level and nested command tokens produce actionable hints instead of bypassing clap’s suggestion machinery entirely.

Changes:

  • Add nearest-subcommand suggestion logic (edit distance + visibility/alias handling) to the group-router unknown-command path.
  • Add an interactive Did you mean ...? confirmation prompt that can rewrite args and re-dispatch in interactive sessions.
  • Extend foundation/unit tests to cover suggested hints, non-hints, and -- operand handling.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.

File Description
cli-engine/tests/foundation.rs Adds integration-style tests asserting suggested hints (and no hints) for unknown commands, including -- operand behavior.
cli-engine/src/prompt.rs Introduces the command-correction prompt API and tests for non-interactive behavior.
cli-engine/src/cli.rs Replaces the prior unknown-group-command message path with structured detection + nearest-match suggestion and optional interactive correction/arg rewrite.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread cli-engine/src/prompt.rs Outdated
Comment thread cli-engine/src/prompt.rs Outdated
Comment thread cli-engine/src/prompt.rs
Comment thread cli-engine/src/cli.rs

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.

Comment thread cli-engine/src/cli.rs Outdated

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 4 out of 5 changed files in this pull request and generated 1 comment.

Comment thread cli-engine/src/cli.rs Outdated

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 4 out of 5 changed files in this pull request and generated no new comments.

@jpage-godaddy
jpage-godaddy merged commit 0bfe701 into main Aug 25, 2026
3 checks passed
@jpage-godaddy
jpage-godaddy deleted the feat/unknown-command-suggestions branch August 25, 2026 23:09
@github-actions github-actions Bot mentioned this pull request Aug 25, 2026
jpage-godaddy pushed a commit that referenced this pull request Aug 25, 2026
🤖 I have created a release *beep* *boop*
---


<details><summary>cli-engine: 0.9.1</summary>

##
[0.9.1](cli-engine-v0.9.0...cli-engine-v0.9.1)
(2026-08-25)


### Features

* **cli:** suggest the nearest command on engine-intercepted unknowns
([#104](#104))
([0bfe701](0bfe701))
</details>

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
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.

3 participants