fix(agent): match Windows drive-letter paths in extract_image_refs - #61571
fix(agent): match Windows drive-letter paths in extract_image_refs#61571lEWFkRAD wants to merge 1 commit into
Conversation
_LOCAL_IMAGE_PATH_RE only anchored on ~/ or / with forward-slash separators, so Windows absolute paths (C:\Users\...\shot.png) never matched and kanban task-body image enrichment silently attached nothing on native Windows. The gateway's extract_local_files() pattern — which this regex documents itself as mirroring — was already extended for drive-letter paths in NousResearch#34632; this applies the same shape here. Also normalize the expanded path (os.path.normpath) so mixed-separator mentions of the same file dedupe to one attachment, and fix the tilde test to set USERPROFILE alongside HOME (ntpath.expanduser ignores HOME). Fixes NousResearch#61568 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Duplicate of #34374 (earliest open fix PR for the same |
|
Thanks for the focused Windows parity fix. Current The existing member triage note identifies open PR #34374 as an earlier implementation of the same fix; choosing the canonical contribution is maintainer triage rather than a correctness concern with this patch. Automated hermes-sweeper review. |
What does this PR do?
Fixes a native-Windows product bug in
agent/image_routing.py::extract_image_refs: the local-path regex (_LOCAL_IMAGE_PATH_RE) only anchored on~/or/with forward-slash separators, so Windows absolute paths (C:\Users\...\shot.png,C:/...) could never match. User-visible effect: kanban task-body image enrichment (cli.py) silently attached nothing on native Windows — pasting a screenshot path into a task body worked on POSIX and was a no-op on Windows. 12 tests fail on native Windows because of this (7 intests/agent/test_image_routing.py::TestExtractImageRefs, 5 intests/hermes_cli/test_kanban_worker_image_extraction.py).The regex documents itself as matching "the same shape gateway's extract_local_files() uses" — but the gateway pattern was extended for Windows drive-letter paths in #34632 and this one was missed. This PR applies the exact same shape:
(?:~/|/|[A-Za-z]:[/\])anchor with[/\]segment separators.Two adjacent fixes ride along:
os.path.normpathafterexpanduser) so the same file cited asC:\x\a.pngandC:/x/a.pngdedupes to one attachment, and tilde expansion on Windows doesn't leave a foreign/in the result. On POSIX this is lexical-identity for the shapes the regex emits — behavior unchanged.test_finds_home_relative_pathmonkeypatched onlyHOME, whichntpath.expanduserignores (Python ≥3.8 usesUSERPROFILE). It now sets both — same idiom astests/tools/test_vision_tools.py.Related Issue
Fixes #61568
Continues the native-Windows series: #57016, #57181 (fixes #57145), #57182 (fixes #57147), #57885 (fixes #57883). Windows-path parity with #34632.
Type of Change
Changes Made
agent/image_routing.py:_LOCAL_IMAGE_PATH_REgains the Bug: MEDIA directive silently fails on Windows #34632 drive-letter alternation and[/\]separators; expanded paths arenormpath-normalized before theisfilecheck and dedupe; docstring/comments updatedtests/agent/test_image_routing.py:test_finds_home_relative_pathsetsUSERPROFILEalongsideHOMEtest_mixed_separator_duplicates_collapse(native-separator + forward-slash spellings of one file → one attachment)TestLocalImagePathRegexWindowsShapes— pattern-level coverage that runs on every platform (backslash drive path, forward-slash drive path, lowercase drive, drive-root file, relative path andC:file.pngnon-matches, Unix shapes still match, URL path-portion still rejected via the lookbehind) — same approach astests/gateway/test_run_tool_media_re.pyHow to Test
python -m pytest tests/agent/test_image_routing.py tests/hermes_cli/test_kanban_worker_image_extraction.py -q→ 12 failed (assert [] == ['C:\...\real.jpg'])normpathis identity for the matched shapes)Checklist
Code
fix(scope):,feat(scope):, etc.)pytest tests/ -qand all tests pass (both affected files green natively on Windows; note below on pre-existing unrelated flakes)Documentation & Housekeeping
docs/, docstrings) — docstring + regex comments updated in placecli-config.yaml.exampleif I added/changed config keys — N/ACONTRIBUTING.mdorAGENTS.mdif I changed architecture or workflows — N/AScreenshots / Logs
Before (main @ daedf4f, native Windows):
After:
Note: when
test_image_routing.pyruns together with the other vision-routing test files,TestDecideImageInputMode/TestLookupSupportsVisionOverrideshow order-dependent flaky failures on clean main as well (verified A/B, varying membership run to run) — pre-existing and unrelated to this change; flagged in #61568 and I'll file separately once isolated.