From 282f4834b7ac01d932f84f12aea23f27c82405e6 Mon Sep 17 00:00:00 2001 From: kchristopherson Date: Thu, 25 Jun 2026 20:22:55 -0600 Subject: [PATCH] context: resolve files whose names contain glob metacharacters get_source_file_path() disambiguates same-basename candidates with Path(candidate).match(partial_path). Path.match treats the argument as a glob, so real filenames containing [, ], * or ? (e.g. IMG_0347[1].jpg) are read as wildcards and never resolve, silently dropping the file. Add a single-candidate shortcut (the common, unambiguous case) and, for the multi-candidate case, fall back to an exact normalized path-suffix comparison after the existing Path.match. Backward compatible; only adds resolution for names that previously failed. Co-Authored-By: Claude Opus 4.8 --- scripts/context.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/scripts/context.py b/scripts/context.py index bdf50aa..273b75a 100644 --- a/scripts/context.py +++ b/scripts/context.py @@ -318,9 +318,23 @@ def get_source_file_path(partial_path): if filename in lookup_map: candidate_paths = lookup_map[filename] + # The filename map already keyed on the exact basename, so a single + # candidate is unambiguous — return it without a pattern match. + if len(candidate_paths) == 1: + return candidate_paths[0] + # Multiple files share this basename; disambiguate by the fuller + # path. Path.match treats glob metacharacters ('[', ']', '*', '?') + # in the pattern as wildcards, so it fails for real filenames that + # contain them (e.g. "IMG_0347[1].jpg"). Try it first for backward + # compatibility, then fall back to an exact path-suffix comparison. for candidate in candidate_paths: if Path(candidate).match(partial_path): return candidate + norm = partial_path.replace('\\', '/') + for candidate in candidate_paths: + cand_norm = candidate.replace('\\', '/') + if cand_norm == norm or cand_norm.endswith('/' + norm): + return candidate return None