Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions packages/cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
53 changes: 44 additions & 9 deletions packages/cli/src/commands/$default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,12 @@ export async function executePrompt(
);
}

type PromptSource = {
type: 'user' | 'file';
source: string;
content: string;
};

export const command: CommandModule<SharedOptions, DefaultArgs> = {
command: '* [prompt]',
describe: 'Execute a prompt or start interactive mode',
Expand All @@ -244,21 +250,50 @@ export const command: CommandModule<SharedOptions, DefaultArgs> = {
// 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) {
Expand Down
5 changes: 3 additions & 2 deletions packages/cli/src/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
Loading