refactor(prompts): extract prompt templates to dedicated module

This commit is contained in:
mitchell 2026-06-17 01:25:27 -04:00
parent 3c3dab1525
commit eec90209d2
2 changed files with 19 additions and 14 deletions

View file

@ -6,6 +6,7 @@ import { streamText } from "ai";
import { initConfig, loadConfig } from "./config"; import { initConfig, loadConfig } from "./config";
import { Conversation } from "./conversation"; import { Conversation } from "./conversation";
import { handleTopLevel } from "./errors"; import { handleTopLevel } from "./errors";
import { Prompts } from "./prompts";
import Renderer from "./render"; import Renderer from "./render";
async function main() { async function main() {
@ -73,21 +74,10 @@ async function main() {
let prompt = "Introduce yourself."; let prompt = "Introduce yourself.";
const input = positionals.join(" ").trim(); const input = positionals.join(" ").trim();
if (messageFlag) { if (messageFlag) prompt = Prompts.commit(input);
prompt = `\`\`\`diff else if (reviewFlag) prompt = Prompts.review(input);
${input} else if (input) prompt = input;
\`\`\`
Generate a conventional commit message for this diff. If you are unable to generate a reasonable option, ask for more context.`;
} else if (reviewFlag) {
prompt = `\`\`\`diff
${input}
\`\`\`
Review the above diff for any potential bugs, best practices, performance issues, or security flaws. Let me know if you need any more context to compelete your review.`;
} else if (input) {
prompt = input;
}
convo.messages.push({ role: "user", content: prompt }); convo.messages.push({ role: "user", content: prompt });
const { fullStream, text, totalUsage } = streamText({ const { fullStream, text, totalUsage } = streamText({

15
src/prompts.ts Normal file
View file

@ -0,0 +1,15 @@
export const Prompts = {
default: "Introduce yourself.",
commit: (input: string) => `\`\`\`diff
${input}
\`\`\`
Generate a conventional commit message for this diff. If you are unable to generate a reasonable option, ask for more context.`,
review: (input: string) => `\`\`\`diff
${input}
\`\`\`
Review the above diff for any potential bugs, best practices, performance issues, or security flaws. Let me know if you need any more context to complete your review.`,
};