fix(web): resolve slashed file-chip paths through the workspace index #8254
Closedcbangera2(GitHub profile, opens in a new tab)wants to merge 15 commits into
main fromrefs/pull/8254/headopened View on GitHubgithub-actions[bot](GitHub profile, opens in a new tab) added labelssize:S
github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched
- apps/web/src/workspaceBasenameLookup.ts lines 35 to 35OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -23,13 +23,13 @@2323 return separatorIndex >= 0 ? path.slice(separatorIndex + 1) : path;2424 }252526-export function needsWorkspaceBasenameLookup(relativePath: string): boolean {27- const trimmed = relativePath.trim();28- return trimmed.length > 0 && !trimmed.includes("/") && !trimmed.includes("\\");26+/** `a/b/c` matches `c` and `b/c` at a segment boundary, but not `abc`. */27+function hasSegmentSuffix(path: string, suffix: string): boolean {28+ return path === suffix || path.endsWith(`/${suffix}`);2929 }30303131 export function pickWorkspaceBasenameMatch(3232 basename: string,3333 entries: ReadonlyArray<WorkspaceEntryCandidate>,3434 ): string | null {35- const target = basename.trim();35+ const target = basename.trim().replaceAll("\\", "/");apps/web/src/workspaceBasenameLookup.ts lines 66 to 66Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -27,11 +26,18 @@27- const trimmed = relativePath.trim();28- return trimmed.length > 0 && !trimmed.includes("/") && !trimmed.includes("\\");26+/** `a/b/c` matches `c` and `b/c` at a segment boundary, but not `abc`. */27+function hasSegmentSuffix(path: string, suffix: string): boolean {28+ return path === suffix || path.endsWith(`/${suffix}`);2929 }30303131 export function pickWorkspaceBasenameMatch(3232 basename: string,3333 entries: ReadonlyArray<WorkspaceEntryCandidate>,3434 ): string | null {35- const target = basename.trim();35+ const target = basename.trim().replaceAll("\\", "/");3636 if (!target) return null;3737 const files = entries.filter((entry) => entry.kind === "file");38+ const exactPath = files.find((entry) => entry.path === target);39+ if (exactPath) return exactPath.path;40+ // Agents reference files relative to their own cwd, which is not always the41+ // workspace root, so a `docs/plan.md` chip has to match wherever that suffix42+ // actually lives. Index order (frecency) breaks ties.43+ const suffixMatches = files.filter((entry) => hasSegmentSuffix(entry.path, target));
- apps/web/src/workspaceBasenameLookup.ts line 44OutdatedResolvedby cbangera2(GitHub profile, opens in a new tab)@@ -28,10 +26,19 @@28- return trimmed.length > 0 && !trimmed.includes("/") && !trimmed.includes("\\");26+/** `a/b/c` matches `c` and `b/c` at a segment boundary, but not `abc`. */27+function hasSegmentSuffix(path: string, suffix: string): boolean {28+ return path === suffix || path.endsWith(`/${suffix}`);2929 }30303131 export function pickWorkspaceBasenameMatch(3232 basename: string,3333 entries: ReadonlyArray<WorkspaceEntryCandidate>,3434 ): string | null {35- const target = basename.trim();35+ const target = basename.trim().replaceAll("\\", "/");3636 if (!target) return null;3737 const files = entries.filter((entry) => entry.kind === "file");38+ const exactPath = files.find((entry) => entry.path === target);39+ if (exactPath) return exactPath.path;40+ // Agents reference files relative to their own cwd, which is not always the41+ // workspace root, so a `docs/plan.md` chip has to match wherever that suffix42+ // actually lives. Index order (frecency) breaks ties.43+ const suffixMatches = files.filter((entry) => hasSegmentSuffix(entry.path, target));44+ if (suffixMatches.length > 0) return suffixMatches[0]?.path ?? null;
github-actions[bot](GitHub profile, opens in a new tab) removed labelssize:S
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:M
- apps/web/src/components/ChatMarkdown.tsx line 1866OutdatedResolvedby cbangera2(GitHub profile, opens in a new tab)@@ -1864 +1866 @@18641866 const isLatestLookup = claimWorkspaceBasenameLookup();
- apps/web/src/workspaceBasenameLookup.ts lines 54 to 58OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -29,9 +39,20 @@39+/** `a/b/c` matches `c` and `b/c` at a segment boundary, but not `abc`. */40+function hasSegmentSuffix(path: string, suffix: string): boolean {41+ const posix = posixPath(path);42+ return posix === suffix || posix.endsWith(`/${suffix}`);2943 }30443145 export function pickWorkspaceBasenameMatch(3246 basename: string,3347 entries: ReadonlyArray<WorkspaceEntryCandidate>,3448 ): string | null {35- const target = basename.trim();49+ const target = normalizeWorkspaceLookupPath(basename);3650 if (!target) return null;3751 const files = entries.filter((entry) => entry.kind === "file");52+ const exactPath = files.find((entry) => posixPath(entry.path) === target);53+ if (exactPath) return exactPath.path;54+ // Agents reference files relative to their own cwd, which is not always the55+ // workspace root, so a `docs/plan.md` chip has to match wherever that suffix56+ // actually lives. Index order (frecency) breaks ties.57+ const suffixMatches = files.filter((entry) => hasSegmentSuffix(entry.path, target));58+ if (suffixMatches.length > 0) return suffixMatches[0]?.path ?? null;
- apps/web/src/workspaceBasenameLookup.ts lines 73 to 75Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -29,9 +41,20 @@2941 }30423143 export function pickWorkspaceBasenameMatch(3244 basename: string,3345 entries: ReadonlyArray<WorkspaceEntryCandidate>,3446 ): string | null {35- const target = basename.trim();47+ const target = normalizeWorkspaceLookupPath(basename);3648 if (!target) return null;3749 const files = entries.filter((entry) => entry.kind === "file");50+ const exactPath = files.find((entry) => posixPath(entry.path) === target);51+ if (exactPath) return exactPath.path;52+ // Chip paths are relative to the agent's cwd, so match the suffix wherever it lives.53+ const suffixMatches = files.filter((entry) => hasSegmentSuffix(entry.path, target));54+ if (suffixMatches.length === 1) return suffixMatches[0]?.path ?? null;55+ if (suffixMatches.length > 1) return null;56+ const foldedTarget = target.toLowerCase();57+ const foldedSuffixMatches = files.filter((entry) =>58+ hasSegmentSuffix(posixPath(entry.path).toLowerCase(), foldedTarget),59+ );60+ if (foldedSuffixMatches.length === 1) return foldedSuffixMatches[0]?.path ?? null;
- apps/web/src/components/ChatMarkdown.tsx lines 1859 to 1859OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -1841,18 +1843,17 @@18411843 }18421844 const result = await searchProjectEntries({18431845 environmentId,18441846 input: {18451847 cwd,1846- query: workspaceRelativePath,1848+ query: lookupPath,18471849 limit: WORKSPACE_BASENAME_LOOKUP_LIMIT,18481850 kind: "file",18491851 },18501852 });18511853 return result._tag === "Success"1852- ? pickWorkspaceBasenameMatch(workspaceRelativePath, result.value.entries)1854+ ? pickWorkspaceBasenameMatch(lookupPath, result.value.entries)18531855 : null;18541856 },18551857 [cwd, environmentId, searchProjectEntries],18561858 );1857- // A bare filename resolves to the workspace root, which is rarely where the1858- // file is, so ask the index before opening.1859+ // Chip paths are relative to the agent's cwd, so every open goes through the index first.apps/web/src/workspaceBasenameLookup.ts lines 74 to 74Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -30,8 +42,20 @@30423143 export function pickWorkspaceBasenameMatch(3244 basename: string,3345 entries: ReadonlyArray<WorkspaceEntryCandidate>,3446 ): string | null {35- const target = basename.trim();47+ const target = normalizeWorkspaceLookupPath(basename);3648 if (!target) return null;3749 const files = entries.filter((entry) => entry.kind === "file");50+ const exactPath = files.find((entry) => posixPath(entry.path) === target);51+ if (exactPath) return exactPath.path;52+ // Chip paths are relative to the agent's cwd, so match the suffix wherever it lives.53+ const suffixMatches = files.filter((entry) => hasSegmentSuffix(entry.path, target));54+ if (suffixMatches.length === 1) return suffixMatches[0]?.path ?? null;55+ if (suffixMatches.length > 1) {56+ return target.includes("/") ? null : (suffixMatches[0]?.path ?? null);57+ }58+ const foldedTarget = target.toLowerCase();59+ const foldedSuffixMatches = files.filter((entry) =>60+ hasSegmentSuffix(posixPath(entry.path).toLowerCase(), foldedTarget),61+ );
- apps/web/src/workspaceBasenameLookup.ts lines 64 to 70OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -38,8 +52,19 @@52+ // Chip paths are relative to the agent's cwd, so match the suffix wherever it lives.53+ const suffixMatches = files.filter((entry) => hasSegmentSuffix(entry.path, target));54+ if (suffixMatches.length === 1) return suffixMatches[0]?.path ?? null;55+ if (suffixMatches.length > 1) {56+ return target.includes("/") ? null : (suffixMatches[0]?.path ?? null);57+ }58+ const foldedTarget = target.toLowerCase();59+ const foldedSuffixMatches = files.filter((entry) =>60+ hasSegmentSuffix(posixPath(entry.path).toLowerCase(), foldedTarget),61+ );62+ if (foldedSuffixMatches.length === 1) return foldedSuffixMatches[0]?.path ?? null;63+ if (foldedSuffixMatches.length > 1) return null;3864 const exact = files.find((entry) => basenameOfPath(entry.path) === target);3965 if (exact) return exact.path;4066 // Folded matching covers casing that drifted from disk, but `FOO.ts` against4167 // both `Foo.ts` and `foo.ts` has no right answer, so it resolves to nothing4268 // rather than opening whichever the index ranked first.43- const folded = target.toLowerCase();4469 const foldedMatches = files.filter(45- (entry) => basenameOfPath(entry.path).toLowerCase() === folded,70+ (entry) => basenameOfPath(entry.path).toLowerCase() === foldedTarget,
- apps/web/src/components/ChatMarkdown.tsx lines 2718 to 2718Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -1921,4 +1938,4 @@19211938 copyMarkdown={copyMarkdown}19221939 theme={resolvedTheme}19231940 threadRef={threadRef}1924- {...(canUseShellActions ? { onOpen: openInPreferredEditor } : {})}1941+ {...(canUseShellActions ? { onOpen: () => openMarkdownFileInEditor(fileLinkMeta) } : {})}
github-actions[bot](GitHub profile, opens in a new tab) removed labelssize:M
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:L
- apps/web/src/components/ChatMarkdown.tsx line 2456OutdatedResolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -2438,17 +2439,18 @@24382439 );24392440 const findWorkspaceBasenameMatch = useCallback(24402441 async (workspaceRelativePath: string) => {2441- if (!cwd || environmentId === null || !needsWorkspaceBasenameLookup(workspaceRelativePath)) {2442+ const lookupPath = normalizeWorkspaceLookupPath(workspaceRelativePath);2443+ if (!cwd || environmentId === null || !lookupPath) {24422444 return null;24432445 }24442446 const result = await searchProjectEntries({24452447 environmentId,24462448 input: {24472449 cwd,2448- query: workspaceRelativePath,2450+ query: lookupPath,24492451 limit: WORKSPACE_BASENAME_LOOKUP_LIMIT,24502452 kind: "file",24512453 },24522454 });24532455 return result._tag === "Success"2454- ? pickWorkspaceBasenameMatch(workspaceRelativePath, result.value.entries)2456+ ? pickWorkspaceBasenameMatch(lookupPath, result.value.entries)
juliusmarminge added labelsmacroscope-review
- apps/web/src/components/ChatMarkdown.tsx line 2593Resolvedby cbangera2(GitHub profile, opens in a new tab)@@ -2436,6 +2441,20 @@24362441 },24372442 [createAssetUrl, cwd, openPreview, preparedConnection, threadRef],24382443 );2444+ const literalWorkspaceFileExists = useCallback(2445+ async (workspaceRelativePath: string) => {2446+ if (!cwd || environmentId === null) return false;2447+ const result = await readWorkspaceFile({2448+ environmentId,2449+ input: { cwd, relativePath: workspaceRelativePath },2450+ });2451+ // readFile reads from disk rather than the search index, so gitignored2452+ // files still report present. Binary files fail the read and count as2453+ // missing here; a stat RPC would close that gap.2454+ return result._tag === "Success";2455+ },2456+ [cwd, environmentId, readWorkspaceFile],2457+ );24392458 const findWorkspaceBasenameMatch = useCallback(24402459 async (workspaceRelativePath: string) => {2441- if (!cwd || environmentId === null || !needsWorkspaceBasenameLookup(workspaceRelativePath)) {2460+ const lookupPath = normalizeWorkspaceLookupPath(workspaceRelativePath);apps/web/src/components/ChatMarkdown.tsx line 2454OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -2436,3 +2441,14 @@24362441 },24372442 [createAssetUrl, cwd, openPreview, preparedConnection, threadRef],24382443 );2444+ const literalWorkspaceFileExists = useCallback(2445+ async (workspaceRelativePath: string) => {2446+ if (!cwd || environmentId === null) return false;2447+ const result = await readWorkspaceFile({2448+ environmentId,2449+ input: { cwd, relativePath: workspaceRelativePath },2450+ });2451+ // readFile reads from disk rather than the search index, so gitignored2452+ // files still report present. Binary files fail the read and count as2453+ // missing here; a stat RPC would close that gap.2454+ return result._tag === "Success";
- apps/web/src/components/ChatMarkdown.tsx lines 2330 to 2333Resolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -2321,3 +2327,6 @@23212327 const searchProjectEntries = useAtomQueryRunner(projectEnvironment.searchEntries, {23222328 reportFailure: false,23232329 });2330+ const readWorkspaceFile = useAtomQueryRunner(projectEnvironment.readFile, {2331+ reportFailure: false,2332+ });
macroscopeapp[bot](GitHub profile, opens in a new tab) approved these changes
maria-rcks closed this
Sign in to join this conversation.


Navigate logical layers of code changes, visualize relationships, and explore their blast radius.
No actionable comments were generated in the recent review. 🎉
ℹ️ Recent review info
⚙️ Run configuration
Configuration used: Repository: pingdotgg/t3code/.coderabbit.yaml
Review profile: CHILL
Plan: Advanced
Run ID:
9a99c795-478d-4d22-8ddc-4b48b37262ba📥 Commits
Reviewing files that changed from the base of the PR and between 1263353278d9a5867c241cdec0770415260543d5 and 81c533c743ef07f0321cea7f0004fd6ae272c435.
📒 Files selected for processing (1)
apps/web/src/components/ChatMarkdown.tsx🚧 Files skipped from review as they are similar to previous changes (1)
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.
📝 Walkthrough
Walkthrough#
Workspace-relative file links now use normalized path matching against indexed files. File-panel lookup checks divergent literal paths against disk and scopes lookup claims by thread. Editor and browser actions use resolved paths when available.
Changes#
Workspace file resolution
apps/web/src/workspaceBasenameLookup.ts,apps/web/src/workspaceBasenameLookup.test.tsapps/web/src/components/ChatMarkdown.tsxapps/web/src/components/ChatMarkdown.tsxPriority: ⬇️ Low
Estimated code review effort: 3 (Moderate) | ~20 minutes
Change: Bug fix · Severity of issue fixed: Low
Merge Risk: ⚪ Minimal · up to
81c53Workspace file actions preserve existing literal paths while resolving indexed alternatives. No actionable merge-blocking risk remains in the inspected changes; merge after normal checks.
Security Architecture Review#
Security architecture risk: 🔵 Low · up to
12633Existing permissions and workspace checks remain in place. No new cross-environment access was demonstrated, but behavior during interrupted actions or workspace changes is not fully established.
Retained concerns No architecture-level concerns identified.
Security review details
Security Blast Radius
Trust Boundaries and Controls
Resilience and Maintainability Implications
Hardening Proposals
🚥 Pre-merge checks | ✅ 4 | ❌ 1
❌ Failed checks (1 warning)#
✅ Passed checks (4 passed)
#8251requiresapps/webfile chips to open a file relative to the agent working directory.ChatMarkdown.tsxresolves non-absolute chip paths through the workspace index and falls back to the…#8251. They update web file-chip path resolution and add supporting tests. The editor, browser, reveal, and panel updates keep file-chip actions consistent. No unrelate…✨ Finishing Touches
🧪 Generate unit tests (beta)
Comment `@coderabbitai help` to get the list of available commands.