@aigile/engine 0.0.0-stage → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/agents/code-reviewer.d.ts +37 -0
- package/dist/agents/code-reviewer.d.ts.map +1 -0
- package/dist/agents/code-reviewer.js +192 -0
- package/dist/agents/code-reviewer.js.map +1 -0
- package/dist/agents/engineer.d.ts +118 -0
- package/dist/agents/engineer.d.ts.map +1 -0
- package/dist/agents/engineer.js +528 -0
- package/dist/agents/engineer.js.map +1 -0
- package/dist/agents/monitor.d.ts +66 -0
- package/dist/agents/monitor.d.ts.map +1 -0
- package/dist/agents/monitor.js +281 -0
- package/dist/agents/monitor.js.map +1 -0
- package/dist/agents/orchestrator.d.ts +49 -0
- package/dist/agents/orchestrator.d.ts.map +1 -0
- package/dist/agents/orchestrator.js +204 -0
- package/dist/agents/orchestrator.js.map +1 -0
- package/dist/agents/release-manager.d.ts +76 -0
- package/dist/agents/release-manager.d.ts.map +1 -0
- package/dist/agents/release-manager.js +312 -0
- package/dist/agents/release-manager.js.map +1 -0
- package/dist/agents/spec-analyst.d.ts +102 -0
- package/dist/agents/spec-analyst.d.ts.map +1 -0
- package/dist/agents/spec-analyst.js +406 -0
- package/dist/agents/spec-analyst.js.map +1 -0
- package/dist/agents/verifier.d.ts +41 -0
- package/dist/agents/verifier.d.ts.map +1 -0
- package/dist/agents/verifier.js +173 -0
- package/dist/agents/verifier.js.map +1 -0
- package/dist/ai-service.d.ts +52 -0
- package/dist/ai-service.d.ts.map +1 -0
- package/dist/ai-service.js +164 -0
- package/dist/ai-service.js.map +1 -0
- package/dist/build-service.d.ts +65 -0
- package/dist/build-service.d.ts.map +1 -0
- package/dist/build-service.js +140 -0
- package/dist/build-service.js.map +1 -0
- package/dist/checkout.d.ts +57 -0
- package/dist/checkout.d.ts.map +1 -0
- package/dist/checkout.js +187 -0
- package/dist/checkout.js.map +1 -0
- package/dist/command-runner.d.ts +67 -0
- package/dist/command-runner.d.ts.map +1 -0
- package/dist/command-runner.js +149 -0
- package/dist/command-runner.js.map +1 -0
- package/dist/conversations.d.ts +18 -0
- package/dist/conversations.d.ts.map +1 -0
- package/dist/conversations.js +34 -0
- package/dist/conversations.js.map +1 -0
- package/dist/data-access.d.ts +34 -0
- package/dist/data-access.d.ts.map +1 -0
- package/dist/data-access.js +85 -0
- package/dist/data-access.js.map +1 -0
- package/dist/git-host.d.ts +43 -0
- package/dist/git-host.d.ts.map +1 -0
- package/dist/git-host.js +83 -0
- package/dist/git-host.js.map +1 -0
- package/dist/in-memory-store.d.ts +25 -0
- package/dist/in-memory-store.d.ts.map +1 -0
- package/dist/in-memory-store.js +52 -0
- package/dist/in-memory-store.js.map +1 -0
- package/dist/index.d.ts +28 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +28 -0
- package/dist/index.js.map +1 -0
- package/dist/milestones.d.ts +36 -0
- package/dist/milestones.d.ts.map +1 -0
- package/dist/milestones.js +50 -0
- package/dist/milestones.js.map +1 -0
- package/dist/pull-request-sync.d.ts +29 -0
- package/dist/pull-request-sync.d.ts.map +1 -0
- package/dist/pull-request-sync.js +79 -0
- package/dist/pull-request-sync.js.map +1 -0
- package/dist/questions.d.ts +37 -0
- package/dist/questions.d.ts.map +1 -0
- package/dist/questions.js +79 -0
- package/dist/questions.js.map +1 -0
- package/dist/queue.d.ts +51 -0
- package/dist/queue.d.ts.map +1 -0
- package/dist/queue.js +108 -0
- package/dist/queue.js.map +1 -0
- package/dist/reviews.d.ts +17 -0
- package/dist/reviews.d.ts.map +1 -0
- package/dist/reviews.js +42 -0
- package/dist/reviews.js.map +1 -0
- package/dist/router.d.ts +13 -0
- package/dist/router.d.ts.map +1 -0
- package/dist/router.js +22 -0
- package/dist/router.js.map +1 -0
- package/dist/scheduler.d.ts +57 -0
- package/dist/scheduler.d.ts.map +1 -0
- package/dist/scheduler.js +134 -0
- package/dist/scheduler.js.map +1 -0
- package/dist/services.d.ts +359 -0
- package/dist/services.d.ts.map +1 -0
- package/dist/services.js +674 -0
- package/dist/services.js.map +1 -0
- package/dist/spec-resolver.d.ts +69 -0
- package/dist/spec-resolver.d.ts.map +1 -0
- package/dist/spec-resolver.js +200 -0
- package/dist/spec-resolver.js.map +1 -0
- package/dist/text-diff.d.ts +16 -0
- package/dist/text-diff.d.ts.map +1 -0
- package/dist/text-diff.js +51 -0
- package/dist/text-diff.js.map +1 -0
- package/dist/tool-sandbox.d.ts +47 -0
- package/dist/tool-sandbox.d.ts.map +1 -0
- package/dist/tool-sandbox.js +245 -0
- package/dist/tool-sandbox.js.map +1 -0
- package/dist/tracks.d.ts +58 -0
- package/dist/tracks.d.ts.map +1 -0
- package/dist/tracks.js +149 -0
- package/dist/tracks.js.map +1 -0
- package/dist/verifier.d.ts +27 -0
- package/dist/verifier.d.ts.map +1 -0
- package/dist/verifier.js +99 -0
- package/dist/verifier.js.map +1 -0
- package/package.json +31 -4
- package/README.md +0 -3
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { AppConfig, DataStore, Review, Role } from '@aigile/core';
|
|
2
|
+
import { type AiService } from '../ai-service.js';
|
|
3
|
+
import { type Actor } from '../services.js';
|
|
4
|
+
export declare const CODE_REVIEWER_KEY = "code-reviewer";
|
|
5
|
+
export declare const CODE_REVIEWER_ROLE: {
|
|
6
|
+
name: string;
|
|
7
|
+
description: string;
|
|
8
|
+
appRole: "viewer";
|
|
9
|
+
kind: "agent";
|
|
10
|
+
agentKey: string;
|
|
11
|
+
};
|
|
12
|
+
export declare const CODE_REVIEWER_CONTRACT = "You are the Code Reviewer of aigile, a system in which people write specs (statements of intent in Markdown) and agents turn them into work. The Engineer has made a change on a branch to satisfy the specs; a person will decide whether it goes in. You read the change before they do, in a detached checkout of the branch, and you change nothing: your tools view files and run checks (tests, lint, build, read-only git); they refuse writes.\n\nReview the change against the specs it was built from and the repository's own conventions. Report only what the author should act on in this change: a spec requirement missed or misread, a defect, a regression, a test that no longer proves what it claims, a convention broken where the repository is consistent. Keep pre-existing problems apart and mention one only when it blocks what the change set out to do. A finding that rests on an assumption names it. A green check never downgrades a finding you have seen. \"None found\" is a valid conclusion. Run the checks the repository has and report their result; if one cannot run here, say so.\n\nAnswer with your report in Markdown, the conclusion first, then the findings, then what you ran; and end with exactly one fenced block tagged json of this shape, nothing after it:\n```json\n{\"verdict\": \"clean\" | \"findings\", \"worst\": \"none\" | \"low\" | \"medium\" | \"high\" | \"critical\", \"summary\": \"one or two sentences, the conclusion\", \"findings\": [{\"severity\": \"...\", \"title\": \"...\", \"detail\": \"...\", \"file\": \"path or null\", \"preexisting\": false}], \"assumptions\": [\"...\"], \"checks\": \"what you ran and the result\"}\n```";
|
|
13
|
+
export declare const CODE_REVIEWER_DEFAULT_BRIEF = "# Code Reviewer brief\n\nHow the Code Reviewer reads this installation's changes. Edit this spec to change its judgement; add a spec mapped to the Code Reviewer and to an organization or project for rules that apply only there (the checks to run, the conventions that matter, what is never a finding).\n\n## What is a finding\n\n- The change does not do what a spec asks, or does something no spec asks for.\n- A defect a test would catch, or a test that was weakened to pass.\n- A convention the repository keeps everywhere, broken here.\n\n## What is not\n\n- Style the linter does not enforce.\n- A problem that was already there, unless the change cannot meet its objective because of it.\n- A different design the reviewer would have chosen.\n\n## Severity\n\n- critical: data loss, security, or the spec's purpose defeated \u00B7 high: wrong behaviour the approver would notice \u00B7 medium: a defect in an edge \u00B7 low: a nit worth a line.\n";
|
|
14
|
+
/**
|
|
15
|
+
* The Code Reviewer (documentation/agents.md §2.4): a detached worktree of
|
|
16
|
+
* the build's branch, the read-only sandbox, the specs and the Engineer's
|
|
17
|
+
* report as the brief, and a Review record with the conclusion first. The
|
|
18
|
+
* approver reads it before the Engineer's own report; it informs, it does
|
|
19
|
+
* not gate.
|
|
20
|
+
*/
|
|
21
|
+
export declare class CodeReviewerAgent {
|
|
22
|
+
private readonly store;
|
|
23
|
+
private readonly ai;
|
|
24
|
+
private readonly config;
|
|
25
|
+
private readonly data;
|
|
26
|
+
private readonly builds;
|
|
27
|
+
private readonly reviews;
|
|
28
|
+
private readonly projects;
|
|
29
|
+
private readonly resolver;
|
|
30
|
+
constructor(store: DataStore, ai: AiService, config: AppConfig);
|
|
31
|
+
role(): Promise<Role | null>;
|
|
32
|
+
/** Review a proposed build; a previous reported review of it is superseded. Every outcome is a Review. */
|
|
33
|
+
review(buildId: string, installRoot: string, actor: Actor): Promise<Review>;
|
|
34
|
+
private record;
|
|
35
|
+
private prompt;
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=code-reviewer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"code-reviewer.d.ts","sourceRoot":"","sources":["../../src/agents/code-reviewer.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAS,SAAS,EAAW,MAAM,EAAE,IAAI,EAAY,MAAM,cAAc,CAAC;AAGjG,OAAO,EAAkB,KAAK,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAMlE,OAAO,EAAE,KAAK,KAAK,EAAkB,MAAM,gBAAgB,CAAC;AAM5D,eAAO,MAAM,iBAAiB,kBAAkB,CAAC;AAEjD,eAAO,MAAM,kBAAkB;;;;;;CAM9B,CAAC;AAEF,eAAO,MAAM,sBAAsB,8nDAO5B,CAAC;AAER,eAAO,MAAM,2BAA2B,67BAmBvC,CAAC;AAgBF;;;;;;GAMG;AACH,qBAAa,iBAAiB;IAQ1B,OAAO,CAAC,QAAQ,CAAC,KAAK;IACtB,OAAO,CAAC,QAAQ,CAAC,EAAE;IACnB,OAAO,CAAC,QAAQ,CAAC,MAAM;IATzB,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAa;IAClC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAe;IACtC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAgB;IACxC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAiB;IAC1C,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAe;gBAGrB,KAAK,EAAE,SAAS,EAChB,EAAE,EAAE,SAAS,EACb,MAAM,EAAE,SAAS;IAS9B,IAAI,IAAI,OAAO,CAAC,IAAI,GAAG,IAAI,CAAC;IAKlC,0GAA0G;IACpG,MAAM,CAAC,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,GAAG,OAAO,CAAC,MAAM,CAAC;YA+CnE,MAAM;YAkBN,MAAM;CAerB"}
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
import { join } from 'node:path';
|
|
2
|
+
import { COLLECTIONS, parseRole, SEVERITIES } from '@aigile/core';
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
import { AiBlockedError } from '../ai-service.js';
|
|
5
|
+
import { BuildService } from '../build-service.js';
|
|
6
|
+
import { Checkout } from '../checkout.js';
|
|
7
|
+
import { DataAccess } from '../data-access.js';
|
|
8
|
+
import { MilestoneService } from '../milestones.js';
|
|
9
|
+
import { ReviewService } from '../reviews.js';
|
|
10
|
+
import { ProjectService } from '../services.js';
|
|
11
|
+
import { SpecResolver } from '../spec-resolver.js';
|
|
12
|
+
import { formatUnifiedDiff } from '../text-diff.js';
|
|
13
|
+
import { runnerFor } from '../command-runner.js';
|
|
14
|
+
import { ToolSandbox } from '../tool-sandbox.js';
|
|
15
|
+
export const CODE_REVIEWER_KEY = 'code-reviewer';
|
|
16
|
+
export const CODE_REVIEWER_ROLE = {
|
|
17
|
+
name: 'Code Reviewer',
|
|
18
|
+
description: 'aigile’s reviewing agent: reads a proposed build in a checkout of its own, runs the checks, and reports for the approver. Changes nothing.',
|
|
19
|
+
appRole: 'viewer',
|
|
20
|
+
kind: 'agent',
|
|
21
|
+
agentKey: CODE_REVIEWER_KEY,
|
|
22
|
+
};
|
|
23
|
+
export const CODE_REVIEWER_CONTRACT = `You are the Code Reviewer of aigile, a system in which people write specs (statements of intent in Markdown) and agents turn them into work. The Engineer has made a change on a branch to satisfy the specs; a person will decide whether it goes in. You read the change before they do, in a detached checkout of the branch, and you change nothing: your tools view files and run checks (tests, lint, build, read-only git); they refuse writes.
|
|
24
|
+
|
|
25
|
+
Review the change against the specs it was built from and the repository's own conventions. Report only what the author should act on in this change: a spec requirement missed or misread, a defect, a regression, a test that no longer proves what it claims, a convention broken where the repository is consistent. Keep pre-existing problems apart and mention one only when it blocks what the change set out to do. A finding that rests on an assumption names it. A green check never downgrades a finding you have seen. "None found" is a valid conclusion. Run the checks the repository has and report their result; if one cannot run here, say so.
|
|
26
|
+
|
|
27
|
+
Answer with your report in Markdown, the conclusion first, then the findings, then what you ran; and end with exactly one fenced block tagged json of this shape, nothing after it:
|
|
28
|
+
\`\`\`json
|
|
29
|
+
{"verdict": "clean" | "findings", "worst": "none" | "low" | "medium" | "high" | "critical", "summary": "one or two sentences, the conclusion", "findings": [{"severity": "...", "title": "...", "detail": "...", "file": "path or null", "preexisting": false}], "assumptions": ["..."], "checks": "what you ran and the result"}
|
|
30
|
+
\`\`\``;
|
|
31
|
+
export const CODE_REVIEWER_DEFAULT_BRIEF = `# Code Reviewer brief
|
|
32
|
+
|
|
33
|
+
How the Code Reviewer reads this installation's changes. Edit this spec to change its judgement; add a spec mapped to the Code Reviewer and to an organization or project for rules that apply only there (the checks to run, the conventions that matter, what is never a finding).
|
|
34
|
+
|
|
35
|
+
## What is a finding
|
|
36
|
+
|
|
37
|
+
- The change does not do what a spec asks, or does something no spec asks for.
|
|
38
|
+
- A defect a test would catch, or a test that was weakened to pass.
|
|
39
|
+
- A convention the repository keeps everywhere, broken here.
|
|
40
|
+
|
|
41
|
+
## What is not
|
|
42
|
+
|
|
43
|
+
- Style the linter does not enforce.
|
|
44
|
+
- A problem that was already there, unless the change cannot meet its objective because of it.
|
|
45
|
+
- A different design the reviewer would have chosen.
|
|
46
|
+
|
|
47
|
+
## Severity
|
|
48
|
+
|
|
49
|
+
- critical: data loss, security, or the spec's purpose defeated · high: wrong behaviour the approver would notice · medium: a defect in an edge · low: a nit worth a line.
|
|
50
|
+
`;
|
|
51
|
+
const reportSchema = z.object({
|
|
52
|
+
verdict: z.enum(['clean', 'findings']),
|
|
53
|
+
worst: z.enum(SEVERITIES).default('none'),
|
|
54
|
+
summary: z.string().default(''),
|
|
55
|
+
findings: z
|
|
56
|
+
.array(z.object({ severity: z.enum(SEVERITIES), title: z.string().min(1), detail: z.string().default(''), file: z.string().nullable().default(null), preexisting: z.boolean().default(false) }))
|
|
57
|
+
.default([]),
|
|
58
|
+
assumptions: z.array(z.string()).default([]),
|
|
59
|
+
checks: z.string().default(''),
|
|
60
|
+
});
|
|
61
|
+
const MAX_PATCH_CHARS = 200_000;
|
|
62
|
+
const MAX_SPECS_CHARS = 200_000;
|
|
63
|
+
/**
|
|
64
|
+
* The Code Reviewer (documentation/agents.md §2.4): a detached worktree of
|
|
65
|
+
* the build's branch, the read-only sandbox, the specs and the Engineer's
|
|
66
|
+
* report as the brief, and a Review record with the conclusion first. The
|
|
67
|
+
* approver reads it before the Engineer's own report; it informs, it does
|
|
68
|
+
* not gate.
|
|
69
|
+
*/
|
|
70
|
+
export class CodeReviewerAgent {
|
|
71
|
+
store;
|
|
72
|
+
ai;
|
|
73
|
+
config;
|
|
74
|
+
data;
|
|
75
|
+
builds;
|
|
76
|
+
reviews;
|
|
77
|
+
projects;
|
|
78
|
+
resolver;
|
|
79
|
+
constructor(store, ai, config) {
|
|
80
|
+
this.store = store;
|
|
81
|
+
this.ai = ai;
|
|
82
|
+
this.config = config;
|
|
83
|
+
this.data = new DataAccess(store);
|
|
84
|
+
this.builds = new BuildService(this.data, store);
|
|
85
|
+
this.reviews = new ReviewService(store);
|
|
86
|
+
this.projects = new ProjectService(store);
|
|
87
|
+
this.resolver = new SpecResolver(this.data);
|
|
88
|
+
}
|
|
89
|
+
async role() {
|
|
90
|
+
const raw = await this.store.list(COLLECTIONS.roles);
|
|
91
|
+
return raw.map((r) => parseRole(r)).find((r) => r.agentKey === CODE_REVIEWER_KEY) ?? null;
|
|
92
|
+
}
|
|
93
|
+
/** Review a proposed build; a previous reported review of it is superseded. Every outcome is a Review. */
|
|
94
|
+
async review(buildId, installRoot, actor) {
|
|
95
|
+
const build = await this.builds.get(buildId);
|
|
96
|
+
const project = await this.projects.get(build.projectId);
|
|
97
|
+
const role = await this.role();
|
|
98
|
+
const agentActor = { userId: `agent:${CODE_REVIEWER_KEY}`, author: { name: role?.name ?? 'Code Reviewer', email: `${CODE_REVIEWER_KEY}@aigile.local` } };
|
|
99
|
+
const base = { buildId, projectId: project.id, reviewerRoleId: role?.id ?? null, toolLog: [], costUsd: null, commit: build.commit };
|
|
100
|
+
const blocked = async (summary) => this.record(build, { ...base, verdict: 'blocked', worst: 'none', summary, findings: [], assumptions: [], checks: '' }, agentActor);
|
|
101
|
+
if (!role)
|
|
102
|
+
return blocked('The Code Reviewer role is not installed; run `aigile install`.');
|
|
103
|
+
if ((build.status !== 'proposed' && build.status !== 'checking') || !build.branch || !project.gitUrl)
|
|
104
|
+
return blocked(`Build ${buildId.slice(0, 8)} is ${build.status}; only a built branch is reviewed.`);
|
|
105
|
+
await this.reviews.settleForBuild(buildId, 'superseded', actor);
|
|
106
|
+
const checkout = new Checkout(join(installRoot, '.aigile', 'work', project.id), project.gitUrl, project.gitBranch);
|
|
107
|
+
const dir = join(installRoot, '.aigile', 'work', `${project.id}-review-${build.id.slice(0, 8)}`);
|
|
108
|
+
try {
|
|
109
|
+
await checkout.addWorktree(build.branch, dir);
|
|
110
|
+
}
|
|
111
|
+
catch (err) {
|
|
112
|
+
return blocked(`could not check out ${build.branch} for review: ${err instanceof Error ? err.message : String(err)}`);
|
|
113
|
+
}
|
|
114
|
+
let sandbox;
|
|
115
|
+
try {
|
|
116
|
+
sandbox = new ToolSandbox(dir, this.config.agents.engineer, true, runnerFor(this.config.agents.sandbox, [checkout.dir, dir], project.id));
|
|
117
|
+
}
|
|
118
|
+
catch (err) {
|
|
119
|
+
await checkout.removeWorktree(dir);
|
|
120
|
+
return blocked(err instanceof Error ? err.message : String(err));
|
|
121
|
+
}
|
|
122
|
+
try {
|
|
123
|
+
const brief = await this.resolver.resolveRole(role.id, project.id);
|
|
124
|
+
const system = [CODE_REVIEWER_CONTRACT, ...brief.map((b) => `\n\n---\n\n${b.content}`)].join('');
|
|
125
|
+
const user = await this.prompt(build, project.name, checkout);
|
|
126
|
+
const engineer = this.config.agents.engineer;
|
|
127
|
+
const result = await this.ai.runTools({ system, messages: [{ role: 'user', content: user }], tools: sandbox.handlers(), budgetTokens: engineer.budgetTokens, deadline: Date.now() + engineer.buildTimeoutMs }, { roleId: role.id, agentKey: CODE_REVIEWER_KEY, purpose: `review build of ${project.name}`, subject: null, briefRevisions: brief.map((b) => ({ specId: b.specId, revision: b.revision })) });
|
|
128
|
+
base.toolLog = sandbox.log;
|
|
129
|
+
base.costUsd = result.costUsd;
|
|
130
|
+
if (result.stopReason === 'refusal')
|
|
131
|
+
return blocked(`The model declined: ${result.refusal ?? ''}`);
|
|
132
|
+
const parsed = parseReport(result.text);
|
|
133
|
+
return this.record(build, { ...base, ...parsed }, agentActor);
|
|
134
|
+
}
|
|
135
|
+
catch (err) {
|
|
136
|
+
base.toolLog = sandbox.log;
|
|
137
|
+
return blocked(err instanceof AiBlockedError ? `blocked: ${err.message}` : err instanceof Error ? err.message : String(err));
|
|
138
|
+
}
|
|
139
|
+
finally {
|
|
140
|
+
await checkout.removeWorktree(dir);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
async record(build, input, actor) {
|
|
144
|
+
const review = await this.reviews.create(input, actor);
|
|
145
|
+
await this.builds.update(build.id, { reviewId: review.id }, `Build ${build.id.slice(0, 8)} reviewed: ${review.verdict}`);
|
|
146
|
+
await new MilestoneService(this.store).post({
|
|
147
|
+
kind: review.verdict === 'blocked' ? 'blocked' : 'report-ready',
|
|
148
|
+
roleId: review.reviewerRoleId,
|
|
149
|
+
agentKey: CODE_REVIEWER_KEY,
|
|
150
|
+
about: { kind: 'build', id: build.id },
|
|
151
|
+
projectIds: [build.projectId],
|
|
152
|
+
summary: review.verdict === 'blocked' ? `Could not review build ${build.id.slice(0, 8)}` : `Reviewed build ${build.id.slice(0, 8)}: ${review.verdict}${review.worst !== 'none' ? `, worst ${review.worst}` : ''}`,
|
|
153
|
+
detail: review.summary,
|
|
154
|
+
}, actor);
|
|
155
|
+
return review;
|
|
156
|
+
}
|
|
157
|
+
async prompt(build, projectName, checkout) {
|
|
158
|
+
const resolution = await this.resolver.resolveProject(build.projectId);
|
|
159
|
+
let budget = MAX_SPECS_CHARS;
|
|
160
|
+
const specs = resolution.resolved
|
|
161
|
+
.filter((r) => {
|
|
162
|
+
budget -= r.content.length;
|
|
163
|
+
return budget >= 0;
|
|
164
|
+
})
|
|
165
|
+
.map((r, i) => `### ${i + 1}. ${r.title} (ranking ${r.ranking ?? 'none'})\n\n${r.content}`)
|
|
166
|
+
.join('\n\n');
|
|
167
|
+
const changes = (await this.builds.changesOf(build)).map((c) => `### Spec ${c.specId} (${c.kind})\n\`\`\`diff\n${formatUnifiedDiff(c.diff)}\n\`\`\``).join('\n\n');
|
|
168
|
+
const { stat, patch } = await checkout.diff(build.branch);
|
|
169
|
+
const shownPatch = patch.length > MAX_PATCH_CHARS ? `${patch.slice(0, MAX_PATCH_CHARS)}\n[patch truncated; read the files in the checkout]` : patch;
|
|
170
|
+
return `## The project\n\n${projectName}; you are in a detached checkout of ${build.branch} at your working directory.\n\n## The specs that apply, strongest first (${resolution.resolved.length})\n\n${specs}\n\n## The spec changes the build worked from\n\n${changes || '(first build: every spec is new)'}\n\n## The Engineer's report\n\n${build.report}\n\n## The change\n\n\`\`\`\n${stat.trim()}\n\`\`\`\n\n\`\`\`diff\n${shownPatch}\n\`\`\`\n\n## Your task\n\nReview it against the specs and the repository's conventions, run its checks, and report as instructed.`;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
/** The JSON block at the end of the reply, or the reply itself as a findings-grade summary. */
|
|
174
|
+
function parseReport(text) {
|
|
175
|
+
const match = [...text.matchAll(/```json\s*([\s\S]*?)```/g)].at(-1);
|
|
176
|
+
if (match) {
|
|
177
|
+
try {
|
|
178
|
+
const parsed = reportSchema.safeParse(JSON.parse(match[1]));
|
|
179
|
+
if (parsed.success) {
|
|
180
|
+
const findings = parsed.data.findings;
|
|
181
|
+
const acting = findings.filter((f) => !f.preexisting);
|
|
182
|
+
const worst = acting.reduce((w, f) => (SEVERITIES.indexOf(f.severity) > SEVERITIES.indexOf(w) ? f.severity : w), 'none');
|
|
183
|
+
return { verdict: acting.length ? 'findings' : parsed.data.verdict, worst: acting.length ? worst : 'none', summary: parsed.data.summary, findings, assumptions: parsed.data.assumptions, checks: parsed.data.checks };
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
catch {
|
|
187
|
+
// Not JSON; the text stands.
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
return { verdict: 'findings', worst: 'low', summary: text.trim().slice(0, 2000) || '(the Reviewer gave no report)', findings: [], assumptions: ['the report was not in the expected shape; read it as prose'], checks: '' };
|
|
191
|
+
}
|
|
192
|
+
//# sourceMappingURL=code-reviewer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"code-reviewer.js","sourceRoot":"","sources":["../../src/agents/code-reviewer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAClE,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,cAAc,EAAkB,MAAM,kBAAkB,CAAC;AAClE,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC/C,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,EAAE,aAAa,EAAE,MAAM,eA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AI,CAAC,WAAW,EAAE,MAAM,EAAE,MAAM,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC;YACxN,CAAC;QACH,CAAC;QAAC,MAAM,CAAC;YACP,6BAA6B;QAC/B,CAAC;IACH,CAAC;IACD,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,IAAI,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,EAAE,IAAI,CAAC,IAAI,+BAA+B,EAAE,QAAQ,EAAE,EAAE,EAAE,WAAW,EAAE,CAAC,4DAA4D,CAAC,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC;AAC9N,CAAC"}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import type { AppConfig, Build, DataStore, Project, Review, Role, Verification } from '@aigile/core';
|
|
2
|
+
import { type AiService } from '../ai-service.js';
|
|
3
|
+
import { Checkout } from '../checkout.js';
|
|
4
|
+
import { QueueService } from '../queue.js';
|
|
5
|
+
import { type Actor } from '../services.js';
|
|
6
|
+
export declare const ENGINEER_KEY = "engineer";
|
|
7
|
+
export declare const ENGINEER_ROLE: {
|
|
8
|
+
name: string;
|
|
9
|
+
description: string;
|
|
10
|
+
appRole: "contributor";
|
|
11
|
+
kind: "agent";
|
|
12
|
+
agentKey: string;
|
|
13
|
+
};
|
|
14
|
+
/** The part of the Engineer's instructions that ships with the package (documentation/agents.md §2.3). */
|
|
15
|
+
export declare const ENGINEER_CONTRACT = "You are the Engineer of aigile, a system in which people write specs (statements of intent in Markdown) and agents turn them into work. You are working in a checkout of one project's repository, on a branch made for this build. You have two tools: bash, which runs in the checkout with a short allowlist of commands (build, test, lint, read-only git; nothing that leaves the checkout, and never a push), and a text editor for viewing, creating and editing files under it.\n\nYour job: make the repository satisfy the specs below, with the smallest correct change. Read before you write: look at the layout, the existing conventions and the tests. Change what the specs require and nothing else; do not refactor, reformat or \"improve\" what they do not mention. Run the project's checks (tests, lint, build) when it has them and make them pass; if a check cannot run here, say so. Do not commit or push: aigile commits your working tree when you finish, and a person approves it before anything leaves this machine. Do not create files outside the checkout. If a spec is ambiguous, choose the reading that changes the least and name the question in your report. If a spec cannot be satisfied (it needs something the repository does not have, or contradicts what you find), stop and say so instead of guessing.\n\nWhen you are done, answer with your report and nothing else, in Markdown with exactly these headings:\n## Summary\nOne paragraph: what the specs asked for and what you did.\n## Changes\nA bullet per file, what and why.\n## Checks\nWhat you ran and the result; what you could not run.\n## Open questions\nAnything the approver should decide, or \"None\".";
|
|
16
|
+
/** The instructions for the plan, before any change (documentation/agents.md §2.3, the plan gate). */
|
|
17
|
+
export declare const ENGINEER_PLAN_CONTRACT = "You are the Engineer of aigile, planning before you build. You are in a checkout of the project's repository on its mainline, with tools that only read: view files and run read-only commands (ls, cat, grep, git log, the test runner if you want to see what exists). Nothing you do here changes the repository; a person approves your plan, and then you build in a later run with this plan in front of you.\n\nRead the repository enough to plan well: its layout, its conventions, its tests, where the specs' requirements live. Then answer with your plan and nothing else, in Markdown with exactly these headings:\n## Summary\nOne paragraph: what the specs ask for and what you will do.\n## Files\nA bullet per file you will create or change, with what and why.\n## Steps\nNumbered, in the order you will work.\n## Checks\nWhat you will run to prove it.\n## Risks\nWhat could go wrong, what you are unsure of, and what you will do about it.\n## Open questions\nAnything the approver should decide before you start, or \"None\".";
|
|
18
|
+
export declare const ENGINEER_DEFAULT_BRIEF = "# Engineer brief\n\nHow the Engineer works on this installation's repositories. Edit this spec to change its habits; add a spec mapped to the Engineer and to an organization or project for rules that apply only there (the commands to run, the conventions to follow, the files never to touch).\n\n## Working\n\n- Match the repository's conventions: language, formatting, test style, commit granularity.\n- Prefer the existing tooling (its package scripts, its test runner) over anything new.\n- Keep the change reviewable: one concern, no drive-by edits.\n\n## Checks\n\n- Run the fastest relevant check first (a focused test), the full suite before finishing.\n- Never weaken or delete a test to make it pass; report the failure instead.\n\n## Reporting\n\n- The approver reads your report before the diff: say what changed and why in their words, not in the code's.\n";
|
|
19
|
+
export interface BuildRunOptions {
|
|
20
|
+
/** The installation's root: where `.aigile/work/<projectId>` and `agents/engineer/` live. */
|
|
21
|
+
installRoot: string;
|
|
22
|
+
/** Review a proposed build before its approval is queued (the Code Reviewer); null when there is none. */
|
|
23
|
+
reviewer?: ((build: Build) => Promise<Review | null>) | null;
|
|
24
|
+
/** Run the project's checks on a proposed build before its approval is queued (the Verifier); null when there is none. */
|
|
25
|
+
verifier?: ((build: Build) => Promise<Verification | null>) | null;
|
|
26
|
+
/** Add the tests that prove the change, before the review and the checks (the Verifier agent); null when there is none. */
|
|
27
|
+
testWriter?: ((build: Build) => Promise<{
|
|
28
|
+
build: Build;
|
|
29
|
+
status: string;
|
|
30
|
+
detail: string;
|
|
31
|
+
} | null>) | null;
|
|
32
|
+
/** Who asked (the queue item falls back to them). */
|
|
33
|
+
actor: Actor;
|
|
34
|
+
/** A previous build this one re-does, with the reason it was rejected. */
|
|
35
|
+
retry?: {
|
|
36
|
+
build: Build;
|
|
37
|
+
reason: string;
|
|
38
|
+
};
|
|
39
|
+
/** Build without the plan gate (the CLI's --no-plan; an approved plan). */
|
|
40
|
+
skipPlan?: boolean;
|
|
41
|
+
}
|
|
42
|
+
export declare function withProjectLock<T>(projectId: string, fn: () => Promise<T>): Promise<T>;
|
|
43
|
+
/**
|
|
44
|
+
* The Engineer's build (documentation/agents.md §2.3, the Build step): a Build
|
|
45
|
+
* from the resolved specs, a clean branch in the project's checkout, the
|
|
46
|
+
* model at work with the sandboxed tools, a commit of what it changed, and
|
|
47
|
+
* an approval queued for the project's highest-ranked author. Every outcome
|
|
48
|
+
* lands on the Build record; the caller only ever gets a Build back.
|
|
49
|
+
*/
|
|
50
|
+
export declare class EngineerAgent {
|
|
51
|
+
private readonly store;
|
|
52
|
+
private readonly ai;
|
|
53
|
+
private readonly config;
|
|
54
|
+
private readonly data;
|
|
55
|
+
private readonly builds;
|
|
56
|
+
private readonly resolver;
|
|
57
|
+
private readonly projects;
|
|
58
|
+
private readonly queue;
|
|
59
|
+
private readonly reviews;
|
|
60
|
+
private readonly milestones;
|
|
61
|
+
constructor(store: DataStore, ai: AiService, config: AppConfig, queue?: QueueService);
|
|
62
|
+
role(): Promise<Role | null>;
|
|
63
|
+
static branchFor(build: Build): string;
|
|
64
|
+
checkoutFor(project: Project, installRoot: string): Checkout;
|
|
65
|
+
/**
|
|
66
|
+
* A build: with the plan gate on (the default), the Engineer plans first
|
|
67
|
+
* and the Build waits (`plan-ready`) for a person's go; with it off, or
|
|
68
|
+
* `skipPlan`, it builds at once. The returned Build says where it is.
|
|
69
|
+
*/
|
|
70
|
+
build(projectId: string, options: BuildRunOptions): Promise<Build>;
|
|
71
|
+
/** The plan: read the checkout on the mainline, write the plan, queue the person's go. */
|
|
72
|
+
plan(build: Build, project: Project, options: BuildRunOptions): Promise<Build>;
|
|
73
|
+
/** The person's go on the plan: the build runs now, with the plan in its brief. */
|
|
74
|
+
approvePlan(buildId: string, actor: Actor, options: Omit<BuildRunOptions, 'actor' | 'retry' | 'skipPlan'>): Promise<Build>;
|
|
75
|
+
/** The decision itself: the plan is accepted and the build is building (409 when it is not plan-ready). The work is runApproved. */
|
|
76
|
+
acceptPlan(buildId: string, actor: Actor): Promise<{
|
|
77
|
+
build: Build;
|
|
78
|
+
project: Project;
|
|
79
|
+
}>;
|
|
80
|
+
/** The work after an accepted plan, one build at a time per project. */
|
|
81
|
+
runApproved(build: Build, project: Project, options: Omit<BuildRunOptions, 'retry' | 'skipPlan'>): Promise<Build>;
|
|
82
|
+
/** The person's no on the plan, with a reason: one more plan with the reason, then discard. */
|
|
83
|
+
rejectPlan(buildId: string, reason: string, actor: Actor, installRoot: string): Promise<{
|
|
84
|
+
rejected: Build;
|
|
85
|
+
retry: Build | null;
|
|
86
|
+
}>;
|
|
87
|
+
/** The decision itself (409 when the build is not plan-ready); `retryable` says whether one more plan is owed. */
|
|
88
|
+
markPlanRejected(buildId: string, reason: string, actor: Actor): Promise<{
|
|
89
|
+
rejected: Build;
|
|
90
|
+
retryable: boolean;
|
|
91
|
+
}>;
|
|
92
|
+
/** The one retry a rejection earns: a new build on the project with the reason. */
|
|
93
|
+
retry(rejected: Build, reason: string, options: Omit<BuildRunOptions, 'retry' | 'skipPlan'>): Promise<Build>;
|
|
94
|
+
/** The work on an already planned Build (the web API plans, answers, then runs). */
|
|
95
|
+
run(build: Build, project: Project, options: BuildRunOptions): Promise<Build>;
|
|
96
|
+
/** The approver's yes: push the branch (never the mainline), open the pull request, close the queue items. */
|
|
97
|
+
approve(buildId: string, actor: Actor, installRoot: string, env?: Record<string, string | undefined>): Promise<Build>;
|
|
98
|
+
private afterPush;
|
|
99
|
+
/** Open the pull request for a pushed branch, or say why there is none; never throws. */
|
|
100
|
+
private pullRequestFor;
|
|
101
|
+
/** The approver's no, with a reason: the branch goes, and the Engineer tries once more with the reason. */
|
|
102
|
+
reject(buildId: string, reason: string, actor: Actor, installRoot: string, reviewer?: BuildRunOptions['reviewer'], verifier?: BuildRunOptions['verifier'], testWriter?: BuildRunOptions['testWriter']): Promise<{
|
|
103
|
+
rejected: Build;
|
|
104
|
+
retry: Build | null;
|
|
105
|
+
}>;
|
|
106
|
+
/** The decision itself: the branch is dropped and the build rejected (409 when it is not proposed); `retryable` says whether one more build is owed. */
|
|
107
|
+
markRejected(buildId: string, reason: string, actor: Actor, installRoot: string): Promise<{
|
|
108
|
+
rejected: Build;
|
|
109
|
+
retryable: boolean;
|
|
110
|
+
}>;
|
|
111
|
+
/** Drop a proposed build and its branch without a retry. */
|
|
112
|
+
discard(buildId: string, actor: Actor, installRoot: string): Promise<Build>;
|
|
113
|
+
private verificationLines;
|
|
114
|
+
/** The project's highest-ranked spec author (documentation/agents.md §3.7); the requester when nobody ranks. */
|
|
115
|
+
private approverFor;
|
|
116
|
+
private prompt;
|
|
117
|
+
}
|
|
118
|
+
//# sourceMappingURL=engineer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"engineer.d.ts","sourceRoot":"","sources":["../../src/agents/engine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