Skip to content

Commit 7750ec9

Browse files
committed
feat: add support for combining file input and interactive prompts
1 parent df7c1ed commit 7750ec9

File tree

3 files changed

+30
-8
lines changed

3 files changed

+30
-8
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: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -246,18 +246,36 @@ export const command: CommandModule<SharedOptions, DefaultArgs> = {
246246
const config = await loadConfig(argvConfig);
247247
let prompt: string | undefined;
248248

249+
// Initialize prompt variable
250+
let fileContent: string | undefined;
251+
let interactiveContent: string | undefined;
252+
249253
// If promptFile is specified, read from file
250254
if (argv.file) {
251-
prompt = await fs.readFile(argv.file, 'utf-8');
255+
fileContent = await fs.readFile(argv.file, 'utf-8');
252256
}
253257

254258
// If interactive mode
255259
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
260+
// 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);
266+
}
267+
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
261279
prompt = argv.prompt;
262280
}
263281

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)