Skip to content

Commit 953e615

Browse files
authored
Merge pull request #384 from drivecore/feature/file-and-interactive-prompts
Add support for combining file input and interactive prompts
2 parents b03ae82 + 3cae6a2 commit 953e615

File tree

3 files changed

+50
-11
lines changed

3 files changed

+50
-11
lines changed

packages/cli/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ mycoder "Implement a React component that displays a list of items"
3333
# Run with a prompt from a file
3434
mycoder -f prompt.txt
3535

36+
# Combine file input with interactive prompts
37+
mycoder -f prompt.txt -i
38+
3639
# Disable user prompts for fully automated sessions
3740
mycoder --userPrompt false "Generate a basic Express.js server"
3841

packages/cli/src/commands/$default.ts

Lines changed: 44 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,12 @@ export async function executePrompt(
231231
);
232232
}
233233

234+
type PromptSource = {
235+
type: 'user' | 'file';
236+
source: string;
237+
content: string;
238+
};
239+
234240
export const command: CommandModule<SharedOptions, DefaultArgs> = {
235241
command: '* [prompt]',
236242
describe: 'Execute a prompt or start interactive mode',
@@ -244,21 +250,50 @@ export const command: CommandModule<SharedOptions, DefaultArgs> = {
244250
// Get configuration for model provider and name
245251
const argvConfig = getConfigFromArgv(argv);
246252
const config = await loadConfig(argvConfig);
247-
let prompt: string | undefined;
248253

254+
// Initialize prompt variable
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+
}
249265
// If promptFile is specified, read from file
250266
if (argv.file) {
251-
prompt = 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+
});
252272
}
253-
254273
// If interactive mode
255274
if (argv.interactive) {
256-
prompt = await userPrompt(
257-
"Type your request below or 'help' for usage information. Use Ctrl+C to exit.",
258-
);
259-
} else if (!prompt) {
260-
// Use command line prompt if provided
261-
prompt = argv.prompt;
275+
// If we already have file content, let the user know
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+
});
288+
}
289+
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+
}
262297
}
263298

264299
if (!prompt) {

packages/cli/src/options.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,14 @@ export const sharedOptions = {
5252
type: 'boolean',
5353
alias: 'i',
5454
description:
55-
'Run in interactive mode, asking for prompts and enabling corrections during execution (use Ctrl+M to send corrections)',
55+
'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.',
5656
default: false,
5757
} as const,
5858
file: {
5959
type: 'string',
6060
alias: 'f',
61-
description: 'Read prompt from a file',
61+
description:
62+
'Read prompt from a file (can be combined with -i/--interactive)',
6263
} as const,
6364
tokenUsage: {
6465
type: 'boolean',

0 commit comments

Comments
 (0)