7 Commits

Author SHA1 Message Date
3daf5442d8 Merge remote-tracking branch 'origin/master'
All checks were successful
Publish Library / Build NPM Project (push) Successful in 7s
Publish Library / Tag Version (push) Successful in 6s
2025-12-30 15:44:14 -05:00
002e809ef6 Updated gitea comment retrieval 2025-12-30 15:43:55 -05:00
d1c0b7a872 Merge pull request 'Added ticket refinement bot' (#4) from refinement into master
All checks were successful
Publish Library / Build NPM Project (push) Successful in 8s
Publish Library / Tag Version (push) Successful in 5s
Reviewed-on: #4
2025-12-30 15:38:49 -05:00
1b026529fe Merge branch 'master' of git.zakscode.com:ztimson/ai-agents into refinement
All checks were successful
Publish Library / Build NPM Project (push) Successful in 4s
Publish Library / Tag Version (push) Successful in 16s
Code review / review (pull_request) Successful in 1m13s
# Conflicts:
#	src/review.mjs
2025-12-30 15:22:31 -05:00
af09bd0f53 Small issue refiner fixes
All checks were successful
Publish Library / Build NPM Project (push) Successful in 4s
Publish Library / Tag Version (push) Successful in 10s
Code review / review (pull_request) Successful in 1m1s
2025-12-30 15:18:02 -05:00
1f48b5a872 Fixed misc bugs
All checks were successful
Publish Library / Build NPM Project (push) Successful in 4s
Publish Library / Tag Version (push) Successful in 13s
Code review / review (pull_request) Successful in 1m0s
2025-12-30 14:15:40 -05:00
6bb78d0862 Added ticket refinement bot
All checks were successful
Publish Library / Build NPM Project (push) Successful in 4s
Publish Library / Tag Version (push) Successful in 6s
Code review / review (pull_request) Successful in 1m6s
2025-12-30 13:47:59 -05:00
7 changed files with 203 additions and 14 deletions

53
.github/issue_template/ai-refinement.md vendored Normal file
View File

@@ -0,0 +1,53 @@
---
name: "AI refinement"
about: "Use AI to refine ticket"
ref: "develop"
labels:
- Review/AI
---
# [Module] - [Add/Change/Fix/Refactor/Remove] [Feature/Component]
## Type: [Bug/DevOps/Enhancement/Refactor/Security]
| | Score |
|------------|----------|
| Size | 0-5 |
| Complexity | 0-5 |
| Unknowns | 0-5 |
| **Total** | **0-15** |
## Description
A clear explanation of the issue, feature, or change needed
## Current Behavior
For bugs: what's happening now
For refactors: what exists today
For enhancements: current state/gap
## Expected Behavior
What should happen instead
## Steps to Reproduce
1. First step
2. Second step
3. Third step
## Additional Context
Logs, screenshots, links, related issues
## Acceptance Criteria
- [ ] Todo requirement
- [X] Completed requirement
## Technical Notes
Implementation details, constraints, dependencies, design decisions

View File

@@ -1,4 +1,5 @@
name: Code review name: Code review
on: on:
pull_request: pull_request:
types: [opened, synchronize, reopened] types: [opened, synchronize, reopened]

26
.github/workflows/ticket-refinement.yml vendored Normal file
View File

@@ -0,0 +1,26 @@
name: Ticket refinement
on:
issues:
types: [opened, labeled]
jobs:
format:
runs-on: ubuntu-latest
container: node:22
steps:
- name: Fetch code
run: |
git clone "$(echo ${{github.server_url}}/${{github.repository}}.git | sed s%://%://${{github.token}}@% )" .
git checkout ${{ github.event.repository.default_branch }}
- name: Run AI Formatter
run: npx -y @ztimson/ai-agents@latest refine .github/issue_template/ai-refinement.md
env:
AI_HOST: anthropic
AI_MODEL: claude-sonnet-4-5
AI_TOKEN: ${{ secrets.ANTHROPIC_TOKEN }}
GIT_HOST: ${{ github.server_url }}
GIT_OWNER: ${{ github.repository_owner }}
GIT_REPO: ${{ github.event.repository.name }}
GIT_TOKEN: ${{ secrets.ASSISTANT_TOKEN }}
TICKET: ${{ github.event.issue.number }}

View File

@@ -9,7 +9,7 @@
### AI Agents ### AI Agents
<!-- Description --> <!-- Description -->
Automated AI-powered agents for automated reviews and code assistance AI-powered Gitea agents for automating reviews and administration
<!-- Repo badges --> <!-- Repo badges -->
[![Version](https://img.shields.io/badge/dynamic/json.svg?label=Version&style=for-the-badge&url=https://git.zakscode.com/api/v1/repos/ztimson/ai-agents/tags&query=$[0].name)](https://git.zakscode.com/ztimson/ai-agents/tags) [![Version](https://img.shields.io/badge/dynamic/json.svg?label=Version&style=for-the-badge&url=https://git.zakscode.com/api/v1/repos/ztimson/ai-agents/tags&query=$[0].name)](https://git.zakscode.com/ztimson/ai-agents/tags)
@@ -37,7 +37,9 @@ Automated AI-powered agents for automated reviews and code assistance
## About ## About
Automated code agents that uses AI to analyze git diffs and provide inline comments on pull requests. Supports Anthropic, OpenAI, and Ollama models with tool-based reviewing for precise feedback. Only supports Gitea
Use LLM models from Anthropic, OpenAI, or Ollama to automate ticket refinement, code reviews, and releases.
### Built With ### Built With
[![Docker](https://img.shields.io/badge/Docker-384d54?style=for-the-badge&logo=docker)](https://docker.com/) [![Docker](https://img.shields.io/badge/Docker-384d54?style=for-the-badge&logo=docker)](https://docker.com/)

View File

@@ -1,12 +1,13 @@
{ {
"name": "@ztimson/ai-agents", "name": "@ztimson/ai-agents",
"version": "0.0.3", "version": "0.0.4",
"description": "AI agents", "description": "AI agents",
"keywords": ["ai", "review"], "keywords": ["ai", "review"],
"author": "ztimson", "author": "ztimson",
"license": "ISC", "license": "ISC",
"type": "module", "type": "module",
"bin": { "bin": {
"refine": "./src/refine.mjs",
"review": "./src/review.mjs" "review": "./src/review.mjs"
}, },
"dependencies": { "dependencies": {

110
src/refine.mjs Normal file
View File

@@ -0,0 +1,110 @@
#!/usr/bin/env node
import {Ai} from '@ztimson/ai-utils';
import * as os from 'node:os';
import * as dotenv from 'dotenv';
import * as fs from 'node:fs';
import * as path from 'node:path';
dotenv.config({quiet: true});
dotenv.config({path: '.env.local', override: true, quiet: true});
(async () => {
let p = process.argv[process.argv.length - 1];
if(p === 'refine' || p.endsWith('refine.mjs')) p = null;
if(!/^(\/|[A-Z]:)/m.test(p)) p = path.join(process.cwd(), p);
if(!p || !fs.existsSync(p)) throw new Error('Please provide a template');
const git = process.env['GIT_HOST'],
owner = process.env['GIT_OWNER'],
repo = process.env['GIT_REPO'],
auth = process.env['GIT_TOKEN'],
ticket = process.env['TICKET'],
host = process.env['AI_HOST'],
model = process.env['AI_MODEL'],
token = process.env['AI_TOKEN'];
console.log(`Processing issue #${ticket}`);
// Fetch issue
const issueRes = await fetch(`${git}/api/v1/repos/${owner}/${repo}/issues/${ticket}`, {
headers: {'Authorization': `token ${auth}`}
});
if(!issueRes.ok) throw new Error(`${issueRes.status} ${await issueRes.text()}`);
const issueData = await issueRes.json();
if(!issueData.labels?.some(l => l.name === 'Review/AI')) {
console.log('Skipping');
return process.exit();
}
let readme = '', readmeP = path.join(process.cwd(), 'README.md');
if(fs.existsSync(readmeP)) readme = fs.readFileSync(readmeP, 'utf-8');
const template = fs.readFileSync(p, 'utf-8');
let options = {ollama: {model, host}};
if(host === 'anthropic') options = {anthropic: {model, token}};
else if(host === 'openai') options = {openAi: {model, token}};
const ai = new Ai({
...options,
model: [host, model],
path: process.env['path'] || os.tmpdir(),
system: `You are a ticket formatter. Transform raw issue descriptions into structured tickets.
**CRITICAL RULES:**
1. Identify the ticket type (Bug, DevOps, Enhancement, Refactor, Security)
2. Output MUST only contain the new ticket information in markdown, no extra fluff
3. Follow the template structure EXACTLY:
- Title format: [Module] - [Verb] [noun]
Example: Storage - Fix file uploads
- Fill in the identified ticket type
- Write a clear description
- For bugs: fill Steps to Reproduce with numbered list
- For enhancements/refactors: REMOVE the Steps to Reproduce section entirely
- Acceptance Criteria: convert requirements into checkboxes (- [ ])
- Weight scoring (0-5 each):
* Size: Number of modules, layers & files affected by change
* Complexity: Technical difficulty to implement
* Unknowns: Research/uncertainty in work estimation
* Calculate Total as sum of the three
- Remove sections that are not applicable based on ticket type
- Use proper markdown headers (##)
**README:**
\`\`\`markdown
${readme.trim() || 'No README available'}
\`\`\`
**TEMPLATE:**
\`\`\`markdown
${template.trim()}
\`\`\`
Output ONLY the formatted ticket, no explanation.`
})
const messages = await ai.language.ask(`Title: ${issueData.title}\n\nDescription:\n${issueData.body || 'No description provided'}`).catch(() => []);
const content = messages?.pop()?.content;
if(!content) {
console.log('Invalid response from AI');
return process.exit(1);
}
const title = /^# (.+)$/m.exec(content)?.[1] || issueData.title;
const typeMatch = /^## Type:\s*(.+)$/m.exec(content);
const type = typeMatch?.[1]?.split('/')[0]?.trim() || 'Unassigned';
const body = content.replace(/^# .+$/m, '').replace(/^## Type:.+$/m, '').trim();
const updateRes = await fetch(`${git}/api/v1/repos/${owner}/${repo}/issues/${ticket}`, {
method: 'PATCH',
headers: {
'Authorization': `token ${auth}`,
'Content-Type': 'application/json'
},
body: JSON.stringify({
title,
body,
labels: type?.length ? [`Kind/${type[0].toUpperCase() + type.slice(1).toLowerCase()}`] : []
})
});
if(!updateRes.ok) throw new Error(`${updateRes.status} ${await updateRes.text()}`);
console.log(body);
})();

View File

@@ -35,19 +35,15 @@ dotenv.config({path: '.env.local', override: true, quiet: true, debug: false});
return process.exit(); return process.exit();
} }
let existingComments = ''; let existingComments = 'Existing Comments:\n';
if(git && pr) { if(git && pr) {
const res = await fetch(`${git}/api/v1/repos/${owner}/${repo}/pulls/${pr}/reviews`, { const reviews = await fetch(`${git}/api/v1/repos/${owner}/${repo}/pulls/${pr}/reviews`, {
headers: {'Authorization': `token ${auth}`} headers: {'Authorization': `token ${auth}`}
}); }).then(resp => resp.ok ? resp.json() : []);
if(res.ok) { const comments = await Promise.all(reviews.map(r => fetch(`${git}/api/v1/repos/${owner}/${repo}/pulls/${pr}/reviews/${r.id}/comments`, {
const reviews = await res.json(); headers: {'Authorization': `token ${auth}`}
const allComments = reviews.flatMap(r => r.comments || []); }).then(resp => resp.ok ? resp.json() : [])));
if(allComments.length) { existingComments += comments.flatten().map(c => `${c.path}:${c.position}\n${c.body}`).join('\n\n');
existingComments = '\n\nExisting review comments (DO NOT repeat these):\n' +
allComments.map(c => `- ${c.path}:${c.line || c.position}: ${c.body}`).join('\n');
}
}
} }
let options = {ollama: {model, host}}; let options = {ollama: {model, host}};