generated from ztimson/template
Use npx instead
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
import {Ai} from '@ztimson/ai-utils';
|
||||
import {$} from '@ztimson/node-utils';
|
||||
import * as os from 'node:os';
|
||||
@@ -5,12 +7,14 @@ import * as path from 'node:path';
|
||||
import * as fs from 'node:fs';
|
||||
import * as dotenv from 'dotenv';
|
||||
|
||||
dotenv.config({debug: false});
|
||||
dotenv.config({path: '.env.local', override: true, debug: false});
|
||||
dotenv.config({quiet: true, debug: false});
|
||||
dotenv.config({path: '.env.local', override: true, quiet: true, debug: false});
|
||||
|
||||
(async () => {
|
||||
const root = process.argv[2] || process.cwd(),
|
||||
branch = process.env['GIT_BRANCH'] || await $`cd ${root} && git symbolic-ref refs/remotes/origin/HEAD`,
|
||||
let p = process.argv[process.argv.length - 1];
|
||||
if(p === 'review' || p.endsWith('review.mjs')) p = null;
|
||||
|
||||
const root = p || process.cwd(),
|
||||
git = process.env['GIT_HOST'],
|
||||
owner = process.env['GIT_OWNER'],
|
||||
repo = process.env['GIT_REPO'],
|
||||
@@ -21,11 +25,11 @@ dotenv.config({path: '.env.local', override: true, debug: false});
|
||||
token = process.env['AI_TOKEN'];
|
||||
|
||||
console.log(`Reviewing: ${root}\n`);
|
||||
const branch = process.env['GIT_BRANCH'] || await $`cd ${root} && git symbolic-ref refs/remotes/origin/HEAD`;
|
||||
const comments = [];
|
||||
const commit = await $`cd ${root} && git log -1 --pretty=format:%H`;
|
||||
const gitDiff = await $`cd ${root} && git diff ${branch}`;
|
||||
|
||||
|
||||
let options = {ollama: {model, host}};
|
||||
if(host === 'anthropic') options = {anthropic: {model, token}};
|
||||
else if(host === 'openai') options = {openAi: {model, token}};
|
||||
@@ -33,7 +37,7 @@ dotenv.config({path: '.env.local', override: true, debug: false});
|
||||
...options,
|
||||
model: [host, model],
|
||||
path: process.env['path'] || os.tmpdir(),
|
||||
system: `You are a code reviewer. Analyze the git diff and use the \`recommend\` tool for EACH issue you find. You must call \`recommend\` exactly once for every bug or improvement opportunity. After making all recommendations, provide a brief bullet point summary in markdown.`,
|
||||
system: `You are a code reviewer. Analyze the git diff and use the \`recommend\` tool for EACH issue you find. You must call \`recommend\` exactly once for every bug or improvement opportunity directly related to changes. Ignore formatting recommendations. After making all recommendations, provide one brief bullet-point summary.`,
|
||||
tools: [{
|
||||
name: 'read_file',
|
||||
description: 'Read contents of a file',
|
||||
|
||||
Reference in New Issue
Block a user