11import type { AvailableCommand } from "@agentclientprotocol/sdk" ;
22import { CODE_COMMANDS } from "@features/message-editor/commands" ;
33import { getAvailableCommandsForTask } from "@features/sessions/stores/sessionStore" ;
4- import { fetchRepoFiles , searchFiles } from "@hooks/useRepoFiles" ;
4+ import {
5+ fetchRepoFiles ,
6+ pathToFileItem ,
7+ searchFiles ,
8+ } from "@hooks/useRepoFiles" ;
9+ import { trpcClient } from "@renderer/trpc/client" ;
10+ import { isAbsolutePath } from "@utils/path" ;
511import Fuse , { type IFuseOptions } from "fuse.js" ;
612import { useDraftStore } from "../stores/draftStore" ;
713import type { CommandSuggestionItem , FileSuggestionItem } from "../types" ;
@@ -39,20 +45,44 @@ function searchCommands(
3945 return results . map ( ( result ) => result . item ) ;
4046}
4147
48+ async function getAbsolutePathSuggestion (
49+ query : string ,
50+ ) : Promise < FileSuggestionItem | null > {
51+ if ( ! isAbsolutePath ( query ) ) return null ;
52+
53+ try {
54+ const exists = await trpcClient . fs . fileExists . query ( { filePath : query } ) ;
55+ if ( ! exists ) return null ;
56+ } catch {
57+ return null ;
58+ }
59+
60+ const fileItem = pathToFileItem ( query ) ;
61+ return {
62+ id : query ,
63+ label : fileItem . name ,
64+ description : fileItem . dir || undefined ,
65+ filename : fileItem . name ,
66+ path : query ,
67+ } ;
68+ }
69+
4270export async function getFileSuggestions (
4371 sessionId : string ,
4472 query : string ,
4573) : Promise < FileSuggestionItem [ ] > {
4674 const repoPath = useDraftStore . getState ( ) . contexts [ sessionId ] ?. repoPath ;
75+ const absolutePathSuggestion = getAbsolutePathSuggestion ( query ) ;
4776
4877 if ( ! repoPath ) {
49- return [ ] ;
78+ const resolved = await absolutePathSuggestion ;
79+ return resolved ? [ resolved ] : [ ] ;
5080 }
5181
5282 const { files, fzf } = await fetchRepoFiles ( repoPath ) ;
5383 const matched = searchFiles ( fzf , files , query ) ;
5484
55- return matched . map ( ( file ) => {
85+ const results : FileSuggestionItem [ ] = matched . map ( ( file ) => {
5686 const parentDir = file . dir ? file . dir . split ( "/" ) . pop ( ) : undefined ;
5787 const label = parentDir ? `${ parentDir } /${ file . name } ` : file . name ;
5888
@@ -64,6 +94,13 @@ export async function getFileSuggestions(
6494 path : file . path ,
6595 } ;
6696 } ) ;
97+
98+ const resolved = await absolutePathSuggestion ;
99+ if ( resolved && ! results . some ( ( r ) => r . id === resolved . id ) ) {
100+ results . unshift ( resolved ) ;
101+ }
102+
103+ return results ;
67104}
68105
69106export function getCommandSuggestions (
0 commit comments