feat(cli): add --file flag for file review and refactor prompt generation

- Inject current date into review prompts to improve LLM context accuracy
- Remove unused `module` field from package.json
This commit is contained in:
mitchell 2026-06-17 22:48:54 -04:00
parent 7652e62d47
commit 4bccbcc9ee
3 changed files with 37 additions and 13 deletions

View file

@ -1,6 +1,5 @@
{ {
"name": "lmc", "name": "lmc",
"module": "src/index.ts",
"type": "module", "type": "module",
"private": true, "private": true,
"bin": { "bin": {

View file

@ -1,4 +1,5 @@
#!/usr/bin/env node #!/usr/bin/env node
import fs from "node:fs/promises";
import consumers from "node:stream/consumers"; import consumers from "node:stream/consumers";
import util from "node:util"; import util from "node:util";
import { createOpenAICompatible } from "@ai-sdk/openai-compatible"; import { createOpenAICompatible } from "@ai-sdk/openai-compatible";
@ -7,7 +8,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 { commitDiff, file, reviewDiff, reviewFile } from "./prompts";
import Renderer from "./render"; import Renderer from "./render";
async function main() { async function main() {
@ -29,6 +30,8 @@ async function main() {
g: { type: "boolean" }, g: { type: "boolean" },
review: { type: "boolean" }, review: { type: "boolean" },
r: { type: "boolean" }, r: { type: "boolean" },
file: { type: "string" },
f: { type: "string" },
}, },
strict: true, strict: true,
allowPositionals: true, allowPositionals: true,
@ -42,6 +45,7 @@ async function main() {
const configFlag = args.config ?? args.c; const configFlag = args.config ?? args.c;
const messageFlag = args["git-message"] ?? args.g; const messageFlag = args["git-message"] ?? args.g;
const reviewFlag = args.review ?? args.r; const reviewFlag = args.review ?? args.r;
const fileFlag = args.file ?? args.f;
if (versionFlag) { if (versionFlag) {
console.log("0.0.0"); console.log("0.0.0");
@ -76,10 +80,20 @@ async function main() {
let input = positionals.join(" ").trim(); let input = positionals.join(" ").trim();
if (input === "-") input = await consumers.text(process.stdin); if (input === "-") input = await consumers.text(process.stdin);
let prompt = "Introduce yourself."; let prompt = input;
if (messageFlag) prompt = Prompts.commit(input); if (messageFlag) {
else if (reviewFlag) prompt = Prompts.review(input); prompt = commitDiff(input);
else if (input) prompt = input; } else if (reviewFlag && fileFlag) {
const content = await fs.readFile(fileFlag, "utf8");
prompt = reviewFile(file(fileFlag, content));
} else if (fileFlag) {
const content = await fs.readFile(fileFlag, "utf8");
prompt = `${file(fileFlag, content)}\n\n${input}`;
} else if (reviewFlag) {
prompt = reviewDiff(input);
}
if (!prompt) throw new Error("No prompt given.");
convo.messages.push({ role: "user", content: prompt }); convo.messages.push({ role: "user", content: prompt });

View file

@ -1,15 +1,26 @@
export const Prompts = { export const file = (name: string, input: string) => `${name}:
default: "Introduce yourself.", \`\`\`
${input}
\`\`\``;
commit: (input: string) => `\`\`\`diff export const commitDiff = (input: string) => `\`\`\`diff
${input} ${input}
\`\`\` \`\`\`
Generate a conventional commit message for this diff. If you are unable to generate a reasonable option, ask for more context.`, 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 export const reviewFile = (input: string) => `${input}
Todays date is ${new Date().toISOString()}, your version info is likely out-of-date.
Review the included file for any potential bugs, best practices, performance issues, or security flaws.
Let me know if you need any more context to complete your review.`;
export const reviewDiff = (input: string) => `\`\`\`diff
${input} ${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.`, Todays date is ${new Date().toISOString()}, your version info is likely out-of-date.
};
Review the included 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.`;