(b8aa66b) Evaluate ticket resolution in tiers, from four characters up, and bump to 0.4.0
resolve_ticket ORed the uuid prefix, title and filename predicates into one flat list, so an exact prefix match was reported as ambiguous against any title that merely mentioned that id. Reproduced: `show 641e3d5` on a board where another ticket's title quoted it failed with "Multiple tickets found", and told the user to use the displayed id, which was the id they had just used. The three tiers are now evaluated in order and the first non-empty one wins outright, which is what AGENTS.md always claimed. The ticket also asked for prefix matching to require eight characters, and that is not implemented. The guard it replaced read short_id.len() >= 8 where short_id was always the full uuid, so it was always true and any length already worked. Eight would have regressed that: ls prints seven characters, so the id the tool displays would drop out of the uuid tier and lose to any title quoting it, which is the very bug above. MIN_ID_SEARCH is four, so a short search is still text and `show 641` remains a title search. Docs corrected in four places that all stated the eight character rule: README, AGENTS.md, the opencode tool descriptions and the kanban skill. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5
parent
e20396ce6b
commit
5a7cfeb849
+42
-14
@@ -177,11 +177,28 @@ fn ambiguous(search: &str, matches: &[(String, String, String, String)]) -> anyh
|
||||
anyhow!(message)
|
||||
}
|
||||
|
||||
pub fn resolve_ticket(search: &str, worklane_dir: &Path) -> Result<(String, String, String)> {
|
||||
let statuses = status_dirs();
|
||||
let mut matches: Vec<(String, String, String, String)> = Vec::new();
|
||||
/// Shortest search tried as a UUID prefix. Below it the search is text, so a one or
|
||||
/// two character term is a title search rather than a prefix matching half the board.
|
||||
///
|
||||
/// Four, not eight. The guard this replaces read `short_id.len() >= 8`, and `short_id`
|
||||
/// there was always the full 36 character uuid, so it was always true and any length
|
||||
/// already worked. Requiring eight would have broken the id the tool prints itself:
|
||||
/// `ls` shows [`SHORT_ID_WIDTH`] characters, and pasting that back has to resolve.
|
||||
pub const MIN_ID_SEARCH: usize = 4;
|
||||
|
||||
for status in &statuses {
|
||||
pub fn resolve_ticket(search: &str, worklane_dir: &Path) -> Result<(String, String, String)> {
|
||||
let search_lower = search.to_lowercase();
|
||||
let long_enough_for_an_id = search.chars().count() >= MIN_ID_SEARCH;
|
||||
|
||||
// Three tiers, filled in one pass and consulted in order. A uuid prefix has to win
|
||||
// outright rather than join a flat list: ticket titles reference other tickets by
|
||||
// id, so an exact prefix match was reported as ambiguous against whichever title
|
||||
// happened to mention it.
|
||||
let mut by_id: Vec<(String, String, String, String)> = Vec::new();
|
||||
let mut by_title: Vec<(String, String, String, String)> = Vec::new();
|
||||
let mut by_filename: Vec<(String, String, String, String)> = Vec::new();
|
||||
|
||||
for status in status_dirs() {
|
||||
let status_path = worklane_dir.join(status);
|
||||
if !status_path.exists() {
|
||||
continue;
|
||||
@@ -206,23 +223,34 @@ pub fn resolve_ticket(search: &str, worklane_dir: &Path) -> Result<(String, Stri
|
||||
.file_stem()
|
||||
.map(|s| s.to_string_lossy().to_string())
|
||||
.unwrap_or_default();
|
||||
let short_id = filename.split('_').next().unwrap_or("");
|
||||
let uuid = filename.split('_').next().unwrap_or("");
|
||||
|
||||
let search_lower = search.to_lowercase();
|
||||
let title_lower = title.to_lowercase();
|
||||
let filename_lower = filename.to_lowercase();
|
||||
let by_prefix = long_enough_for_an_id && uuid.to_lowercase().starts_with(&search_lower);
|
||||
let in_title = title.to_lowercase().contains(&search_lower);
|
||||
// Still reaches the middle of a uuid, which the prefix tier cannot.
|
||||
let in_filename = filename.to_lowercase().contains(&search_lower);
|
||||
|
||||
let id_match =
|
||||
short_id.to_lowercase().starts_with(&search_lower) && short_id.len() >= 8;
|
||||
let title_match = title_lower.contains(&search_lower);
|
||||
let filename_match = filename_lower.contains(&search_lower);
|
||||
if !(by_prefix || in_title || in_filename) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if id_match || title_match || filename_match {
|
||||
matches.push((status.to_string(), title, content, short_id.to_string()));
|
||||
let found = (status.to_string(), title, content, uuid.to_string());
|
||||
if by_prefix {
|
||||
by_id.push(found);
|
||||
} else if in_title {
|
||||
by_title.push(found);
|
||||
} else {
|
||||
by_filename.push(found);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let mut matches = match (by_id.is_empty(), by_title.is_empty()) {
|
||||
(false, _) => by_id,
|
||||
(true, false) => by_title,
|
||||
(true, true) => by_filename,
|
||||
};
|
||||
|
||||
if matches.is_empty() {
|
||||
return Err(anyhow!("No ticket found matching '{}'", search));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user