fix(forge): suggest the nearest name when a filter value misses

The third bullet of the issue's ask, dropped in the first pass and caught
in review: a filter value that does not resolve is a near-miss far more
often than an invention, and an error that only lists all 18 available
names makes the reader do the diff by eye -- on the one occasion they
already know they mistyped something.

Thresholded rather than always suggesting the minimum-distance
candidate: a wrong suggestion is worse than none, because it invites a
second failed attempt at a name that was never there. The bound scales
with the needle (a third of its length, capped at 3), so a short name
does not match half the repo and a long one still tolerates a typo or
two, and an unrelated word falls back to the full list.

Tie-break is on length then alphabetical, so the suggestion does not
depend on the order the forge happened to return its labels in.
This commit is contained in:
atlas 2026-08-05 22:13:45 +02:00
commit 6e64489050
3 changed files with 101 additions and 2 deletions

View file

@ -145,7 +145,7 @@ pub(crate) fn resolve_ids(all: &[Label], names: &[String]) -> Result<Vec<i64>> {
let available: Vec<&str> = all.iter().filter_map(|l| l.name.as_deref()).collect();
bail!(
"unresolved label name(s): {} — available labels: {}",
unresolved.join(", "),
crate::verbs::with_suggestions(&unresolved, &available),
if available.is_empty() {
"(none)".to_owned()
} else {