diff --git a/index.ts b/index.ts index 45cdd57..35c5ec7 100644 --- a/index.ts +++ b/index.ts @@ -17,9 +17,14 @@ const { values: args, positionals } = util.parseArgs({ config: { type: "boolean" }, c: { type: "boolean" }, plain: { type: "boolean" }, - plainOut: { type: "boolean" }, - plainErr: { type: "boolean" }, + "plain-out": { type: "boolean" }, + "plain-err": { type: "boolean" }, + version: { type: "boolean" }, v: { type: "boolean" }, + "git-message": { type: "boolean" }, + g: { type: "boolean" }, + review: { type: "boolean" }, + r: { type: "boolean" }, }, strict: true, allowPositionals: true, @@ -27,12 +32,15 @@ const { values: args, positionals } = util.parseArgs({ async function main() { const newConvo = args.new ?? args.n; - const plainOut = args.plainOut ?? args.plain ?? !process.stdout.isTTY; - const plainErr = args.plainErr ?? args.plain ?? !process.stderr.isTTY; + const plainOut = args["plain-out"] ?? args.plain ?? !process.stdout.isTTY; + const plainErr = args["plain-err"] ?? args.plain ?? !process.stderr.isTTY; const modelFlag = args.model ?? args.m; + const versionFlag = args.version ?? args.v; const configFlag = args.config ?? args.c; + const messageFlag = args["git-message"] ?? args.g; + const reviewFlag = args.review ?? args.r; - if (args.v) { + if (versionFlag) { console.log("0.0.0"); return; } @@ -62,7 +70,23 @@ async function main() { if (modelFlag) convo.model = modelFlag; } - const prompt = positionals.join(" ") || "Introduce yourself."; + let prompt = "Introduce yourself."; + const input = positionals.join(" ").trim(); + if (messageFlag) { + prompt = `\`\`\`diff +${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({