Skip to content

Commit 3cae6a2

Browse files
committed
chore: improve start-up sequence
1 parent 7750ec9 commit 3cae6a2

File tree

1 file changed

+40
-23
lines changed

1 file changed

+40
-23
lines changed

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

Lines changed: 40 additions & 23 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,39 +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

249254
// Initialize prompt variable
250-
let fileContent: string | undefined;
251-
let interactiveContent: string | undefined;
252-
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+
}
253265
// If promptFile is specified, read from file
254266
if (argv.file) {
255-
fileContent = 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+
});
256272
}
257-
258273
// If interactive mode
259274
if (argv.interactive) {
260275
// 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);
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+
});
266288
}
267289

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
279-
prompt = argv.prompt;
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+
}
280297
}
281298

282299
if (!prompt) {

0 commit comments

Comments
 (0)