Documentation
¶
Overview ¶
Package suggest provides the shared "did you mean" primitives: a rune-aware Levenshtein edit distance and a prefix-weighted Closest ranker. It is the single home for these so cmd, cmd/event, and internal/cmdpolicy stop each carrying their own copy.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Closest ¶
Closest returns up to maxN of candidates that plausibly match typed, ranked by shared-prefix length (desc) then edit distance (asc), keeping only reasonably-close ones.
Shared prefix is weighted first on purpose: hallucinated names are often semantically close but lexically far (e.g. "+cells-find" vs "+cells-search", "--with-styles" vs nothing close), where the common prefix is the strongest signal of intent that raw edit distance misses.
A hallucinated name is also often a compound welded from real names ("sql-file" from "sql" + "file"). Prefix and edit distance both miss the trailing half: "file" shares no prefix with "sql-file" and sits 4 edits away, past the budget, so the one candidate naming what the caller actually wanted got dropped while the leading half survived on prefix alone. Segment-exact candidates are therefore always plausible, however far the whole string drifted.
func Levenshtein ¶
Levenshtein computes the classic edit distance between two strings. It is rune-aware, so it is correct for multi-byte input.
Types ¶
This section is empty.