2 Commits

Author SHA1 Message Date
c27802ca44 Working AI
All checks were successful
Build and publish / Build Container (push) Successful in 1m1s
2025-12-27 17:54:03 -05:00
2b11979b66 Update 2025-12-27 15:21:57 -05:00
5 changed files with 75 additions and 29 deletions

11
.env Normal file
View File

@@ -0,0 +1,11 @@
; 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=
GIT_TOKEN=
PULL_REQUEST=
AI_HOST=
AI_MODEL=
AI_TOKEN=

1
.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
.env.local

30
package-lock.json generated
View File

@@ -9,8 +9,10 @@
"version": "0.0.0",
"license": "ISC",
"dependencies": {
"@ztimson/ai-utils": "0.2.3",
"@ztimson/utils": "^0.28.3"
"@ztimson/ai-utils": "^0.2.4",
"@ztimson/node-utils": "^1.0.7",
"@ztimson/utils": "^0.28.3",
"dotenv": "^17.2.3"
}
},
"node_modules/@anthropic-ai/sdk": {
@@ -286,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",
@@ -311,9 +313,9 @@
}
},
"node_modules/@ztimson/node-utils": {
"version": "1.0.4",
"resolved": "https://registry.npmjs.org/@ztimson/node-utils/-/node-utils-1.0.4.tgz",
"integrity": "sha512-EVI0CQYvrzRV7f9pmy13piyFfF9htYS4Kf2W/dW4HzSBEPTO//mGPZthWyQXnxvMeG6p3e5hAPlQ4hAmrRDv6A==",
"version": "1.0.7",
"resolved": "https://registry.npmjs.org/@ztimson/node-utils/-/node-utils-1.0.7.tgz",
"integrity": "sha512-BqrEMfW3/FKyYnTnL1uzxHUZFUeg2FaRGjL9tWAFkw8M99HcN9HoStdrPL6JfLSudvCwDbGzUJSEP6GL0E8uoQ==",
"license": "MIT"
},
"node_modules/@ztimson/utils": {
@@ -682,6 +684,18 @@
"node": ">=8"
}
},
"node_modules/dotenv": {
"version": "17.2.3",
"resolved": "https://registry.npmjs.org/dotenv/-/dotenv-17.2.3.tgz",
"integrity": "sha512-JVUnt+DUIzu87TABbhPmNfVdBDt18BLOWjMUFJMSi/Qqg7NTYtabbvSNJGOJ7afbRuv9D/lngizHtP7QyLQ+9w==",
"license": "BSD-2-Clause",
"engines": {
"node": ">=12"
},
"funding": {
"url": "https://dotenvx.com"
}
},
"node_modules/dunder-proto": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/dunder-proto/-/dunder-proto-1.0.1.tgz",

View File

@@ -9,8 +9,9 @@
"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",
"@ztimson/node-utils": "^1.0.4"
"dotenv": "^17.2.3"
}
}

View File

@@ -3,6 +3,10 @@ import {$} from '@ztimson/node-utils';
import * as os from 'node:os';
import * as path from 'node:path';
import * as fs from 'node:fs';
import * as dotenv from 'dotenv';
dotenv.config();
dotenv.config({path: '.env.local', override: true});
(async () => {
const
@@ -16,9 +20,15 @@ import * as fs from 'node:fs';
model = process.env['AI_MODEL'],
token = process.env['AI_TOKEN'];
const comments = [];
const commit = (await $`git log -1 --pretty=format:%H`).trim();
const gitDiff = await $`git diff HEAD^..HEAD`;
const commit = await $`cd ${root} && git log -1 --pretty=format:%H`;
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})\n`);
let options = {ollama: {model, host}};
if(host === 'anthropic') options = {anthropic: {model, token}};
@@ -27,7 +37,7 @@ import * as fs from 'node:fs';
...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',
@@ -47,7 +57,7 @@ import * as fs from 'node:fs';
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) => {
@@ -61,7 +71,14 @@ import * as fs from 'node:fs';
}]
});
const summary = await ai.language.ask(gitDiff);
if(!gitDiff) {
console.warn('No diff found');
return process.exit();
}
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',
headers: {
@@ -76,4 +93,6 @@ import * as fs from 'node:fs';
})
});
if(!res.ok) throw new Error(`${res.status} ${await res.text()}`);
}
console.log(comments.map(c => `${c.path}${c.new_position ? `:${c.new_position}` : ''}\n${c.body}`).join('\n\n') + '\n\n' + summary);
})();