@@ -163,6 +163,7 @@ import { useAtomQueryRunner } from "../state/use-atom-query-runner";
163163import { projectEnvironment } from "../state/projects" ;
164164import {
165165 claimWorkspaceBasenameLookup ,
166+ needsLiteralWorkspaceFileCheck ,
166167 normalizeWorkspaceLookupPath ,
167168 pickWorkspaceBasenameMatch ,
168169 WORKSPACE_BASENAME_LOOKUP_LIMIT ,
@@ -2209,6 +2210,9 @@ function useChatMarkdownState({
22092210 const searchProjectEntries = useAtomQueryRunner ( projectEnvironment . searchEntries , {
22102211 reportFailure : false ,
22112212 } ) ;
2213+ const readWorkspaceFile = useAtomQueryRunner ( projectEnvironment . readFile , {
2214+ reportFailure : false ,
2215+ } ) ;
22122216 const openPreview = useAtomCommand ( previewEnvironment . open , {
22132217 reportFailure : false ,
22142218 } ) ;
@@ -2437,6 +2441,20 @@ function useChatMarkdownState({
24372441 } ,
24382442 [ createAssetUrl , cwd , openPreview , preparedConnection , threadRef ] ,
24392443 ) ;
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 gitignored
2452+ // files still report present. Binary files fail the read and count as
2453+ // missing here; a stat RPC would close that gap.
2454+ return result . _tag === "Success" ;
2455+ } ,
2456+ [ cwd , environmentId , readWorkspaceFile ] ,
2457+ ) ;
24402458 const findWorkspaceBasenameMatch = useCallback (
24412459 async ( workspaceRelativePath : string ) => {
24422460 const lookupPath = normalizeWorkspaceLookupPath ( workspaceRelativePath ) ;
@@ -2452,11 +2470,19 @@ function useChatMarkdownState({
24522470 kind : "file" ,
24532471 } ,
24542472 } ) ;
2455- return result . _tag === "Success"
2456- ? pickWorkspaceBasenameMatch ( lookupPath , result . value . entries )
2457- : null ;
2473+ if ( result . _tag !== "Success" ) return null ;
2474+ const match = pickWorkspaceBasenameMatch ( lookupPath , result . value . entries ) ;
2475+ if (
2476+ needsLiteralWorkspaceFileCheck ( lookupPath , match ) &&
2477+ ( await literalWorkspaceFileExists ( lookupPath ) )
2478+ ) {
2479+ // The literal chip path names a real file, so keep it instead of the
2480+ // indexed twin. Callers fall back to the literal path on null.
2481+ return null ;
2482+ }
2483+ return match ;
24582484 } ,
2459- [ cwd , environmentId , searchProjectEntries ] ,
2485+ [ cwd , environmentId , literalWorkspaceFileExists , searchProjectEntries ] ,
24602486 ) ;
24612487 // Chip paths are relative to the agent's cwd, so every workspace open goes
24622488 // through the index first. Absolute host paths open as-is.
0 commit comments