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:
parent
7652e62d47
commit
4bccbcc9ee
3 changed files with 37 additions and 13 deletions
24
src/index.ts
24
src/index.ts
|
|
@ -1,4 +1,5 @@
|
|||
#!/usr/bin/env node
|
||||
import fs from "node:fs/promises";
|
||||
import consumers from "node:stream/consumers";
|
||||
import util from "node:util";
|
||||
import { createOpenAICompatible } from "@ai-sdk/openai-compatible";
|
||||
|
|
@ -7,7 +8,7 @@ import { streamText } from "ai";
|
|||
import { initConfig, loadConfig } from "./config";
|
||||
import { Conversation } from "./conversation";
|
||||
import { handleTopLevel } from "./errors";
|
||||
import { Prompts } from "./prompts";
|
||||
import { commitDiff, file, reviewDiff, reviewFile } from "./prompts";
|
||||
import Renderer from "./render";
|
||||
|
||||
async function main() {
|
||||
|
|
@ -29,6 +30,8 @@ async function main() {
|
|||
g: { type: "boolean" },
|
||||
review: { type: "boolean" },
|
||||
r: { type: "boolean" },
|
||||
file: { type: "string" },
|
||||
f: { type: "string" },
|
||||
},
|
||||
strict: true,
|
||||
allowPositionals: true,
|
||||
|
|
@ -42,6 +45,7 @@ async function main() {
|
|||
const configFlag = args.config ?? args.c;
|
||||
const messageFlag = args["git-message"] ?? args.g;
|
||||
const reviewFlag = args.review ?? args.r;
|
||||
const fileFlag = args.file ?? args.f;
|
||||
|
||||
if (versionFlag) {
|
||||
console.log("0.0.0");
|
||||
|
|
@ -76,10 +80,20 @@ async function main() {
|
|||
let input = positionals.join(" ").trim();
|
||||
if (input === "-") input = await consumers.text(process.stdin);
|
||||
|
||||
let prompt = "Introduce yourself.";
|
||||
if (messageFlag) prompt = Prompts.commit(input);
|
||||
else if (reviewFlag) prompt = Prompts.review(input);
|
||||
else if (input) prompt = input;
|
||||
let prompt = input;
|
||||
if (messageFlag) {
|
||||
prompt = commitDiff(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 });
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue