From eec90209d24cd1e9377b75b9051244a8038e3dba Mon Sep 17 00:00:00 2001 From: mitchell Date: Wed, 17 Jun 2026 01:25:27 -0400 Subject: [PATCH] refactor(prompts): extract prompt templates to dedicated module --- src/index.ts | 18 ++++-------------- src/prompts.ts | 15 +++++++++++++++ 2 files changed, 19 insertions(+), 14 deletions(-) create mode 100644 src/prompts.ts diff --git a/src/index.ts b/src/index.ts index a99fe41..4f7b4b4 100644 --- a/src/index.ts +++ b/src/index.ts @@ -6,6 +6,7 @@ import { streamText } from "ai"; import { initConfig, loadConfig } from "./config"; import { Conversation } from "./conversation"; import { handleTopLevel } from "./errors"; +import { Prompts } from "./prompts"; import Renderer from "./render"; async function main() { @@ -73,21 +74,10 @@ async function main() { let prompt = "Introduce yourself."; const input = positionals.join(" ").trim(); - if (messageFlag) { - prompt = `\`\`\`diff -${input} -\`\`\` + if (messageFlag) prompt = Prompts.commit(input); + else if (reviewFlag) prompt = Prompts.review(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 }); const { fullStream, text, totalUsage } = streamText({ diff --git a/src/prompts.ts b/src/prompts.ts new file mode 100644 index 0000000..94969d4 --- /dev/null +++ b/src/prompts.ts @@ -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.`, +};