Working AI
All checks were successful
Build and publish / Build Container (push) Successful in 1m1s

This commit is contained in:
2025-12-27 17:54:03 -05:00
parent 2b11979b66
commit c27802ca44
4 changed files with 18 additions and 14 deletions

View File

@@ -4,7 +4,6 @@ import * as os from 'node:os';
import * as path from 'node:path';
import * as fs from 'node:fs';
import * as dotenv from 'dotenv';
import {execSync} from 'node:child_process';
dotenv.config();
dotenv.config({path: '.env.local', override: true});
@@ -24,10 +23,12 @@ dotenv.config({path: '.env.local', override: true});
const comments = [];
const commit = await $`cd ${root} && git log -1 --pretty=format:%H`;
const remote = await $`cd ${root} && git symbolic-ref refs/remotes/origin/HEAD`;
const gitDiff = execSync(`git diff ${remote}...HEAD`, {cwd: root, encoding: 'utf-8'});
const target = await $`cd ${root} && git rev-parse HEAD`;
const dest = await $`cd ${root} && git symbolic-ref refs/remotes/origin/HEAD`;
const gitDiff = await $`git diff ${dest} ${target}`;
const markdown = !!git;
console.log(`Inspecting: ${root} (${commit})`);
console.log(`Inspecting: ${root} (${commit})\n`);
let options = {ollama: {model, host}};
if(host === 'anthropic') options = {anthropic: {model, token}};
@@ -36,7 +37,7 @@ dotenv.config({path: '.env.local', override: true});
...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 summary.',
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 summary using 100 words or less in ${markdown ? 'markdown' : 'unstyled text'}.`,
tools: [{
name: 'read_file',
description: 'Read contents of a file',
@@ -56,7 +57,7 @@ dotenv.config({path: '.env.local', override: true});
description: 'REQUIRED: Call this once for every bug, improvement, or concern identified in the review.',
args: {
file: {type: 'string', description: 'File path'},
line: {type: 'number', description: 'Line number in new file', optional: true},
line: {type: 'number', description: 'Line number in new file'},
comment: {type: 'string', description: 'Review comment explaining the issue'}
},
fn: (args) => {
@@ -75,7 +76,8 @@ dotenv.config({path: '.env.local', override: true});
return process.exit();
}
const summary = await ai.language.ask(gitDiff);
const messages = await ai.language.ask(gitDiff);
const summary = messages.pop().content;
if(git) {
const res = await fetch(`${git}/api/v1/repos/${owner}/${repo}/pulls/${pr}/reviews`, {
method: 'POST',
@@ -91,7 +93,6 @@ dotenv.config({path: '.env.local', override: true});
})
});
if(!res.ok) throw new Error(`${res.status} ${await res.text()}`);
} else {
console.log(comments.map(c => `${c.path}:${c.new_position}\n${c.body}`).join('\n\n') + '\n\n' + summary);
}
console.log(comments.map(c => `${c.path}${c.new_position ? `:${c.new_position}` : ''}\n${c.body}`).join('\n\n') + '\n\n' + summary);
})();