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

3
.env
View File

@@ -1,3 +1,6 @@
; DO NOT MODIFY! this is an example environment file
; Create a copy called .env.local with the needed settings
GIT_HOST=
GIT_OWNER=
GIT_REPO=

8
package-lock.json generated
View File

@@ -9,7 +9,7 @@
"version": "0.0.0",
"license": "ISC",
"dependencies": {
"@ztimson/ai-utils": "0.2.3",
"@ztimson/ai-utils": "^0.2.4",
"@ztimson/node-utils": "^1.0.7",
"@ztimson/utils": "^0.28.3",
"dotenv": "^17.2.3"
@@ -288,9 +288,9 @@
}
},
"node_modules/@ztimson/ai-utils": {
"version": "0.2.3",
"resolved": "https://registry.npmjs.org/@ztimson/ai-utils/-/ai-utils-0.2.3.tgz",
"integrity": "sha512-3BnB7Xx4WaQbcYucaUNN9wCqZlhWZKyp/emEdHa4SBNUcyQAMl3VuVo6Ulle0vScsyOKXhPXN+5ij3sv1dk02w==",
"version": "0.2.4",
"resolved": "https://registry.npmjs.org/@ztimson/ai-utils/-/ai-utils-0.2.4.tgz",
"integrity": "sha512-dCkUCTXlKDztXRta4LrfOmgmhxYwegG/0dEr9jNXgbFb8j0M6bS5y9ZOn3m/tK6NDNdUzHKDBA/QDl17Vu7oyA==",
"license": "MIT",
"dependencies": {
"@anthropic-ai/sdk": "^0.67.0",

View File

@@ -9,7 +9,7 @@
"license": "ISC",
"description": "",
"dependencies": {
"@ztimson/ai-utils": "0.2.3",
"@ztimson/ai-utils": "^0.2.4",
"@ztimson/node-utils": "^1.0.7",
"@ztimson/utils": "^0.28.3",
"dotenv": "^17.2.3"

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);
})();