@@ -24,7 +24,8 @@ import {
2424 getImportLogger , getCurrentLogPath ,
2525} from "./logger" ;
2626import { isDomainTrusted , promptForTrust , addTrustedDomain , extractDomain } from "./trust" ;
27- import { dirname , resolve } from "path" ;
27+ import { dirname , resolve , join } from "path" ;
28+ import { homedir } from "os" ;
2829import { input } from "@inquirer/prompts" ;
2930import { exceedsLimit , StdinSizeLimitError } from "./limits" ;
3031import { countTokens } from "./tokenizer" ;
@@ -90,6 +91,48 @@ export class CliRunner {
9091 if ( logPath ) this . writeStderr ( ` Detailed logs: ${ logPath } ` ) ;
9192 }
9293
94+ /**
95+ * Resolve file path by checking multiple locations in order:
96+ * 1. As-is (absolute path or relative to cwd)
97+ * 2. Project agents: ./.mdflow/<filename>
98+ * 3. User agents: ~/.mdflow/<filename>
99+ * 4. PATH directories (for files without path separators)
100+ */
101+ private async resolveFilePath ( filePath : string ) : Promise < string > {
102+ // 1. Try as-is (could be absolute or relative from cwd)
103+ if ( await this . env . fs . exists ( filePath ) ) {
104+ return filePath ;
105+ }
106+
107+ // Only search directories for simple filenames (no path separators)
108+ if ( ! filePath . includes ( "/" ) ) {
109+ // 2. Try ./.mdflow/
110+ const projectPath = join ( this . cwd , ".mdflow" , filePath ) ;
111+ if ( await this . env . fs . exists ( projectPath ) ) {
112+ return projectPath ;
113+ }
114+
115+ // 3. Try ~/.mdflow/
116+ const userPath = join ( homedir ( ) , ".mdflow" , filePath ) ;
117+ if ( await this . env . fs . exists ( userPath ) ) {
118+ return userPath ;
119+ }
120+
121+ // 4. Try $PATH directories
122+ const pathDirs = ( this . processEnv . PATH || "" ) . split ( ":" ) ;
123+ for ( const dir of pathDirs ) {
124+ if ( ! dir ) continue ;
125+ const pathFilePath = join ( dir , filePath ) ;
126+ if ( await this . env . fs . exists ( pathFilePath ) ) {
127+ return pathFilePath ;
128+ }
129+ }
130+ }
131+
132+ // Not found anywhere - return original for error message
133+ return filePath ;
134+ }
135+
93136 async run ( argv : string [ ] ) : Promise < CliRunResult > {
94137 let logPath : string | null = null ;
95138 try {
@@ -182,6 +225,9 @@ export class CliRunner {
182225 }
183226 localFilePath = remoteResult . localPath ! ;
184227 isRemote = true ;
228+ } else {
229+ // Resolve local file path by checking multiple directories
230+ localFilePath = await this . resolveFilePath ( filePath ) ;
185231 }
186232
187233 // Signal handling
0 commit comments