diff --git a/src/args.ts b/src/args.ts index 9eb8df76c..0769850ae 100644 --- a/src/args.ts +++ b/src/args.ts @@ -1,9 +1,10 @@ -import * as path from "path"; import * as os from "os"; +import * as path from "path"; export interface CommandLineArgs { isHeadless: boolean; assistantPath: string; + prompt?: string; // Optional prompt argument } /** @@ -12,11 +13,11 @@ export interface CommandLineArgs { */ export function parseArgs(): CommandLineArgs { const args = process.argv.slice(2); - + // Default values const result: CommandLineArgs = { isHeadless: false, - assistantPath: path.join(os.homedir(), ".continue", "config.yaml") + assistantPath: path.join(os.homedir(), ".continue", "config.yaml"), }; // Parse flags @@ -24,11 +25,28 @@ export function parseArgs(): CommandLineArgs { result.isHeadless = true; } - // Get assistant path or slug (first non-flag argument) - const nonFlagArgs = args.filter(arg => !arg.startsWith("--")); + // Get assistant path from --assistant flag + const assistantIndex = args.indexOf("--assistant"); + if (assistantIndex !== -1 && assistantIndex + 1 < args.length) { + result.assistantPath = args[assistantIndex + 1]; + } + + // Find the last argument that's not a flag or a flag value + const nonFlagArgs = args.filter((arg, index) => { + // Skip flags (starting with --) + if (arg.startsWith("--")) return false; + + // Skip flag values + const prevArg = index > 0 ? args[index - 1] : ""; + if (prevArg === "--assistant") return false; + + return true; + }); + + // If there are any non-flag arguments, use the last one as the prompt if (nonFlagArgs.length > 0) { - result.assistantPath = nonFlagArgs[0]; + result.prompt = nonFlagArgs[nonFlagArgs.length - 1]; } return result; -} \ No newline at end of file +} diff --git a/src/index.ts b/src/index.ts index deaf5844e..4f67dbbfc 100644 --- a/src/index.ts +++ b/src/index.ts @@ -57,9 +57,20 @@ async function chat() { chatHistory.push({ role: "system", content: systemMessage }); } + let isFirstMessage = true; while (true) { + // When in headless mode, don't ask for user input + if (!isFirstMessage && args.prompt && args.isHeadless) { + break; + } + // Get user input - let userInput = readlineSync.question(`\n${chalk.bold.green("You:")} `); + let userInput = + isFirstMessage && args.prompt + ? args.prompt + : readlineSync.question(`\n${chalk.bold.green("You:")} `); + + isFirstMessage = false; // Handle slash commands const commandResult = handleSlashCommands(userInput, assistant); @@ -81,7 +92,9 @@ async function chat() { chatHistory.push({ role: "user", content: userInput }); // Get AI response with potential tool usage - console.log(`\n${chalk.bold.blue("Assistant:")}`); + if (!args.isHeadless) { + console.log(`\n${chalk.bold.blue("Assistant:")}`); + } try { await streamChatResponse(chatHistory, assistant); @@ -90,6 +103,7 @@ async function chat() { console.log( chalk.dim(`Chat history:\n${JSON.stringify(chatHistory, null, 2)}`) ); + } finally { } } }