Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions pkg/cmd/suggest.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ func jaroWinkler(a, b string) float64 {
// suggestCommand takes a list of commands and a provided string to suggest a
// command name
func suggestCommand(commands []*cli.Command, provided string) string {
const minSuggestionDistance = 0.75

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Handle single-edit typos for short commands

For the real run subcommand declared with suggestions enabled in pkg/cmd/finetuningalphagrader.go:17-20, omitting the middle character produces jaroWinkler("run", "rn") == 0.611, so this fixed threshold returns no suggestion even though the input is only one deletion away. The new filter therefore suppresses a close typo that the change is intended to preserve; the cutoff should account for short command lengths or use an edit-distance fallback.

Useful? React with 👍 / 👎.


distance := 0.0
var lineage []*cli.Command
for _, command := range commands {
Expand All @@ -112,6 +114,9 @@ func suggestCommand(commands []*cli.Command, provided string) string {
}
}
}
if distance < minSuggestionDistance || len(lineage) == 0 {
return ""
Comment on lines +117 to +118

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Reject unrelated short inputs before suggesting

With the actual root command list, an unrelated invocation such as openai bar still passes this check because jaroWinkler("beta:threads", "bar") == 0.775: the short input's three characters match widely separated characters in the longer command, and the common b prefix boosts the score over the cutoff. As a result, the CLI still suggests beta:threads for clearly unrelated input, so the new regression test's two-command fixture does not establish that the production command set avoids the original false-positive behavior.

Useful? React with 👍 / 👎.

}

var parts []string
for _, command := range lineage {
Expand Down
29 changes: 29 additions & 0 deletions pkg/cmd/suggest_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package cmd

import (
"testing"

"github.com/urfave/cli/v3"
)

func TestSuggestCommandSkipsUnrelatedInput(t *testing.T) {
commands := []*cli.Command{
{Name: "completions"},
{Name: "responses"},
}

if got := suggestCommand(commands, "totallybogus"); got != "" {
t.Fatalf("expected no suggestion for unrelated input, got %q", got)
}
}

func TestSuggestCommandKeepsCloseMatches(t *testing.T) {
commands := []*cli.Command{
{Name: "create"},
{Name: "delete"},
}

if got := suggestCommand(commands, "creat"); got != "Did you mean 'create'?" {
t.Fatalf("expected create suggestion, got %q", got)
}
}