fix(grep): report workspace-relative paths when the workspace path is not canonical

grep_files walks the canonicalized search root from ToolContext::resolve_path
but stripped matches against the raw context.workspace. Whenever the
workspace path runs through a symlink (macOS /var and /tmp, symlinked project
dirs) strip_prefix failed and every match came back as an absolute
/private/var/... path. #6393's grep pods expose this as its macOS-only
grep_pods_chart_matched_dirs_with_marks failure ("//private/var/.../net").
Strip against the canonical workspace as a fallback.

Evidence (macOS, this tree): a temporary, uncommitted grep check on a
tempdir workspace returned "net/server.rs" with the fix and
"/private/var/folders/.../net/server.rs" without it (1 failed). Existing
tools::search + tools::file_search: 41 passed, 0 failed. cargo fmt --check
clean. Full workspace suite left to hosted CI.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01NBKbhx19BRbZtvWK8rVKjz
This commit is contained in:
CodeWhale BotandClaude Opus 5.5 committed 2026-10-14 20:49:31 -07:00
1 parent 88b4c58dfb
commit c6bcf78c01
1 file changed
+7
+7
View File
@@ -192,6 +192,7 @@ impl ToolSpec for GrepFilesTool {
// can't pin the async runtime and leave the stop button unresponsive.
let result = run_blocking_grep(GREP_FILES_TIMEOUT, cancel_token.clone(), move || {
let cancel_token = cancel_token.as_ref();
let workspace_canonical = workspace.canonicalize().ok();
// Stream the walk: each file is searched as it is discovered and
// the traversal stops as soon as the match budget is exhausted.
@@ -230,6 +231,12 @@ impl ToolSpec for GrepFilesTool {
// Get relative path from workspace
let relative_path = file_path
.strip_prefix(&workspace)
.ok()
.or_else(|| {
workspace_canonical
.as_deref()
.and_then(|canonical| file_path.strip_prefix(canonical).ok())
})
.unwrap_or(file_path)
.to_string_lossy()
.to_string();