diff --git a/packages/cli/README.md b/packages/cli/README.md index 40217c8..2ade744 100644 --- a/packages/cli/README.md +++ b/packages/cli/README.md @@ -33,6 +33,9 @@ mycoder "Implement a React component that displays a list of items" # Run with a prompt from a file mycoder -f prompt.txt +# Combine file input with interactive prompts +mycoder -f prompt.txt -i + # Disable user prompts for fully automated sessions mycoder --userPrompt false "Generate a basic Express.js server" diff --git a/packages/cli/src/commands/$default.ts b/packages/cli/src/commands/$default.ts index 2b9cfe0..5ecaadb 100644 --- a/packages/cli/src/commands/$default.ts +++ b/packages/cli/src/commands/$default.ts @@ -231,6 +231,12 @@ export async function executePrompt( ); } +type PromptSource = { + type: 'user' | 'file'; + source: string; + content: string; +}; + export const command: CommandModule = { command: '* [prompt]', describe: 'Execute a prompt or start interactive mode', @@ -244,21 +250,50 @@ export const command: CommandModule = { // Get configuration for model provider and name const argvConfig = getConfigFromArgv(argv); const config = await loadConfig(argvConfig); - let prompt: string | undefined; + // Initialize prompt variable + const prompts: PromptSource[] = []; + + // If prompt is specified, use it as inline prompt + if (argv.prompt) { + prompts.push({ + type: 'user', + source: 'command line', + content: argv.prompt, + }); + } // If promptFile is specified, read from file if (argv.file) { - prompt = await fs.readFile(argv.file, 'utf-8'); + prompts.push({ + type: 'file', + source: argv.file, + content: await fs.readFile(argv.file, 'utf-8'), + }); } - // If interactive mode if (argv.interactive) { - prompt = await userPrompt( - "Type your request below or 'help' for usage information. Use Ctrl+C to exit.", - ); - } else if (!prompt) { - // Use command line prompt if provided - prompt = argv.prompt; + // If we already have file content, let the user know + const promptMessage = + (prompts.length > 0 + ? 'Add additional instructions' + : 'Enter your request') + + " below or 'help' for usage information. Use Ctrl+C to exit."; + const interactiveContent = await userPrompt(promptMessage); + + prompts.push({ + type: 'user', + source: 'interactive', + content: interactiveContent, + }); + } + + let prompt = ''; + for (const promptSource of prompts) { + if (promptSource.type === 'user') { + prompt += `--- ${promptSource.source} ---\n\n${promptSource.content}\n\n`; + } else if (promptSource.type === 'file') { + prompt += `--- contents of ${promptSource.source} ---\n\n${promptSource.content}\n\n`; + } } if (!prompt) { diff --git a/packages/cli/src/options.ts b/packages/cli/src/options.ts index e0627c4..11b1a8c 100644 --- a/packages/cli/src/options.ts +++ b/packages/cli/src/options.ts @@ -52,13 +52,14 @@ export const sharedOptions = { type: 'boolean', alias: 'i', description: - 'Run in interactive mode, asking for prompts and enabling corrections during execution (use Ctrl+M to send corrections)', + 'Run in interactive mode, asking for prompts and enabling corrections during execution (use Ctrl+M to send corrections). Can be combined with -f/--file to append interactive input to file content.', default: false, } as const, file: { type: 'string', alias: 'f', - description: 'Read prompt from a file', + description: + 'Read prompt from a file (can be combined with -i/--interactive)', } as const, tokenUsage: { type: 'boolean',