Skip to content
Merged
Changes from 1 commit
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
45 changes: 39 additions & 6 deletions src/commands/run.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -304,8 +304,10 @@ export async function runRun(context: Context) {
alias: {
model: 'm',
help: 'h',
quiet: 'q',
yes: 'y',
},
boolean: ['help'],
boolean: ['help', 'quiet', 'yes'],
string: ['model'],
});

Expand All @@ -315,6 +317,7 @@ export async function runRun(context: Context) {
}

const model = argv.model || context.config.smallModel || context.config.model;
const quiet = argv.quiet || argv.yes || context.config.quiet;

// Initialize NodeBridge for AI queries
const nodeBridge = new NodeBridge({
Expand All @@ -331,15 +334,37 @@ export async function runRun(context: Context) {
messageBus.setTransport(clientTransport);
nodeBridge.messageBus.setTransport(nodeTransport);

// Create readline interface
// Track current working directory
let cwd = context.cwd;

// Initial prompt from CLI arguments if any
// Note: argv._[0] is 'run', so the prompt is from index 1 onwards
let firstPrompt: string | undefined = argv._.slice(1).join(' ') || undefined;

if (quiet) {
if (!firstPrompt) {
console.error('Error: Prompt is required in quiet mode');
process.exit(1);
}

// Single-shot execution in quiet mode
if (!isNaturalLanguage(firstPrompt)) {
await executeCommand(firstPrompt, cwd);
} else {
const result = await generateCommand(messageBus, firstPrompt, cwd, model);
if (result) {
await executeCommand(result.command, cwd);
}
}
process.exit(0);
}

// Create readline interface for interactive mode
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
});

// Track current working directory
let cwd = context.cwd;

// Handle Ctrl+D to exit
rl.on('close', () => {
console.log('\nBye!');
Expand All @@ -348,7 +373,13 @@ export async function runRun(context: Context) {

// Main loop
while (true) {
const userInput = await askPrompt(rl, cwd);
let userInput: string;
if (firstPrompt) {
userInput = firstPrompt;
firstPrompt = undefined; // Only use once
} else {
userInput = await askPrompt(rl, cwd);
}

if (userInput === '') {
// Empty input, just continue to next prompt
Expand Down Expand Up @@ -382,6 +413,8 @@ export async function runRun(context: Context) {
const confirmed = await confirmCommand(rl, result.command);
if (!confirmed) continue;

process.stdout.write('\n'); // Add newline after confirmation input
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't add this, no newline after confirm is by design.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't add this, no newline after confirm is by design.

fixed


// Check if generated command is cd
const cdNewCwd = tryChangeDirectory(result.command, cwd);
if (cdNewCwd !== null) {
Expand Down