@@ -231,6 +231,12 @@ export async function executePrompt(
231
231
) ;
232
232
}
233
233
234
+ type PromptSource = {
235
+ type : 'user' | 'file' ;
236
+ source : string ;
237
+ content : string ;
238
+ } ;
239
+
234
240
export const command : CommandModule < SharedOptions , DefaultArgs > = {
235
241
command : '* [prompt]' ,
236
242
describe : 'Execute a prompt or start interactive mode' ,
@@ -244,39 +250,50 @@ export const command: CommandModule<SharedOptions, DefaultArgs> = {
244
250
// Get configuration for model provider and name
245
251
const argvConfig = getConfigFromArgv ( argv ) ;
246
252
const config = await loadConfig ( argvConfig ) ;
247
- let prompt : string | undefined ;
248
253
249
254
// Initialize prompt variable
250
- let fileContent : string | undefined ;
251
- let interactiveContent : string | undefined ;
252
-
255
+ const prompts : PromptSource [ ] = [ ] ;
256
+
257
+ // If prompt is specified, use it as inline prompt
258
+ if ( argv . prompt ) {
259
+ prompts . push ( {
260
+ type : 'user' ,
261
+ source : 'command line' ,
262
+ content : argv . prompt ,
263
+ } ) ;
264
+ }
253
265
// If promptFile is specified, read from file
254
266
if ( argv . file ) {
255
- fileContent = await fs . readFile ( argv . file , 'utf-8' ) ;
267
+ prompts . push ( {
268
+ type : 'file' ,
269
+ source : argv . file ,
270
+ content : await fs . readFile ( argv . file , 'utf-8' ) ,
271
+ } ) ;
256
272
}
257
-
258
273
// If interactive mode
259
274
if ( argv . interactive ) {
260
275
// If we already have file content, let the user know
261
- const promptMessage = fileContent
262
- ? "File content loaded. Add additional instructions below or 'help' for usage information. Use Ctrl+C to exit."
263
- : "Type your request below or 'help' for usage information. Use Ctrl+C to exit." ;
264
-
265
- interactiveContent = await userPrompt ( promptMessage ) ;
276
+ const promptMessage =
277
+ ( prompts . length > 0
278
+ ? 'Add additional instructions'
279
+ : 'Enter your request' ) +
280
+ " below or 'help' for usage information. Use Ctrl+C to exit." ;
281
+ const interactiveContent = await userPrompt ( promptMessage ) ;
282
+
283
+ prompts . push ( {
284
+ type : 'user' ,
285
+ source : 'interactive' ,
286
+ content : interactiveContent ,
287
+ } ) ;
266
288
}
267
289
268
- // Combine inputs or use individual ones
269
- if ( fileContent && interactiveContent ) {
270
- // Combine both inputs with a separator
271
- prompt = `${ fileContent } \n\n--- Additional instructions ---\n\n${ interactiveContent } ` ;
272
- console . log ( 'Combined file content with interactive input.' ) ;
273
- } else if ( fileContent ) {
274
- prompt = fileContent ;
275
- } else if ( interactiveContent ) {
276
- prompt = interactiveContent ;
277
- } else if ( argv . prompt ) {
278
- // Use command line prompt if provided and no other input method was used
279
- prompt = argv . prompt ;
290
+ let prompt = '' ;
291
+ for ( const promptSource of prompts ) {
292
+ if ( promptSource . type === 'user' ) {
293
+ prompt += `--- ${ promptSource . source } ---\n\n${ promptSource . content } \n\n` ;
294
+ } else if ( promptSource . type === 'file' ) {
295
+ prompt += `--- contents of ${ promptSource . source } ---\n\n${ promptSource . content } \n\n` ;
296
+ }
280
297
}
281
298
282
299
if ( ! prompt ) {
0 commit comments