@@ -189,8 +189,13 @@ export async function expertCommand(question: string | undefined, options: Exper
189189 } else {
190190 throw new Error ( `Preset not found: ${ options . preset } \nCreate it with: promptcode preset --create ${ options . preset } ` ) ;
191191 }
192+ } else if ( options . promptFile ) {
193+ // When using prompt-file without files/preset, don't scan any files by default
194+ // The user can specify files/preset if they want context
195+ patterns = [ ] ;
196+ console . log ( chalk . gray ( '💡 No files specified. Use -f or --preset to include code context.' ) ) ;
192197 } else {
193- // Default to all files
198+ // Default to all files only when not using prompt-file
194199 patterns = [ '**/*' ] ;
195200 }
196201
@@ -216,33 +221,45 @@ export async function expertCommand(question: string | undefined, options: Exper
216221 console . log ( chalk . green ( `✓ Saved file patterns to preset: ${ options . savePreset } ` ) ) ;
217222 }
218223
219- // Scan files
220- const files = await scanFiles ( {
221- cwd : projectPath ,
222- patterns,
223- respectGitignore : true ,
224- workspaceName : path . basename ( projectPath )
225- } ) ;
224+ // Scan files only if patterns exist
225+ let files : any [ ] = [ ] ;
226+ let result : any ;
226227
227- if ( files . length === 0 ) {
228- if ( spin ) {
229- spin . fail ( 'No files found matching patterns' ) ;
230- spin . stop ( ) ; // Ensure cleanup
228+ if ( patterns . length > 0 ) {
229+ files = await scanFiles ( {
230+ cwd : projectPath ,
231+ patterns,
232+ respectGitignore : true ,
233+ workspaceName : path . basename ( projectPath )
234+ } ) ;
235+
236+ if ( files . length === 0 ) {
237+ if ( spin ) {
238+ spin . fail ( 'No files found matching patterns' ) ;
239+ spin . stop ( ) ; // Ensure cleanup
240+ }
241+ console . error ( chalk . yellow ( '\nTips:' ) ) ;
242+ console . error ( chalk . gray ( ' - Check if the path exists: ' + patterns . join ( ', ' ) ) ) ;
243+ console . error ( chalk . gray ( ' - Try using absolute paths or glob patterns' ) ) ;
244+ console . error ( chalk . gray ( ' - Make sure .gitignore is not excluding your files' ) ) ;
245+ return ;
231246 }
232- console . error ( chalk . yellow ( '\nTips:' ) ) ;
233- console . error ( chalk . gray ( ' - Check if the path exists: ' + patterns . join ( ', ' ) ) ) ;
234- console . error ( chalk . gray ( ' - Try using absolute paths or glob patterns' ) ) ;
235- console . error ( chalk . gray ( ' - Make sure .gitignore is not excluding your files' ) ) ;
236- return ;
247+
248+ // Build context with files
249+ result = await buildPrompt ( files , '' , {
250+ includeFiles : true ,
251+ includeInstructions : false ,
252+ includeFileContents : true
253+ } ) ;
254+ } else {
255+ // No files to scan - create minimal result for prompt-only queries
256+ result = {
257+ prompt : '' ,
258+ tokenCount : 0 ,
259+ fileCount : 0
260+ } ;
237261 }
238262
239- // Build context
240- const result = await buildPrompt ( files , '' , {
241- includeFiles : true ,
242- includeInstructions : false ,
243- includeFileContents : true
244- } ) ;
245-
246263 // Model already validated earlier, just use it
247264
248265 /* ──────────────────────────────────────────────────────────
0 commit comments