@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,66 @@
|
|
|
1
|
+
import type { AppConfig, Audit, DataStore, ProbeResult, Role, Sweep } from '@aigile/core';
|
|
2
|
+
import { type AiService } from '../ai-service.js';
|
|
3
|
+
import { type CommandRunner } from '../command-runner.js';
|
|
4
|
+
import { QueueService } from '../queue.js';
|
|
5
|
+
import { type Actor } from '../services.js';
|
|
6
|
+
export declare const MONITOR_KEY = "monitor";
|
|
7
|
+
export declare const MONITOR_ROLE: {
|
|
8
|
+
name: string;
|
|
9
|
+
description: string;
|
|
10
|
+
appRole: "viewer";
|
|
11
|
+
kind: "agent";
|
|
12
|
+
agentKey: string;
|
|
13
|
+
};
|
|
14
|
+
export declare const MONITOR_CONTRACT = "You are the Monitor of aigile, a system in which people write specs and agents turn them into work that is then merged and deployed. You watch what shipped. You are read-only everywhere: you change no alarm, no threshold, no system; a change you want is a finding for a person.\n\nA sweep ran the installation's probes (commands people configured: a health check, a log tail, a count). Some failed. For each failing probe, say what it is: \"real\" (a problem in the live system, with the evidence from the output you cite and the first action a person should take), \"noise\" (a known or harmless signature: say why), or \"watching\" (not enough evidence yet). A finding is real only with evidence you cite; otherwise it is watching. A probe that failed because it could not run (a missing command, a timeout) is watching, not real. Then give the sweep's verdict: \"clean\" when nothing is real or watching, \"watch\" when something is watching, \"regression\" when something is real, and a one-paragraph summary a person reads first. When this sweep audits a merge, say whether the merge looks implicated.\n\nAnswer in the JSON format requested, nothing else.";
|
|
15
|
+
export declare const MONITOR_DEFAULT_BRIEF = "# Monitor brief\n\nHow the Monitor reads this installation's probes. Edit this spec to change its judgement; add a spec mapped to the Monitor and to an organization or project for signatures that apply only there.\n\n## Known noise\n\n- (none yet: when a signature is noise, write it here with the date it was last confirmed harmless)\n\n## What makes a finding real\n\n- The probe's own output shows the problem (an error, a wrong count, a missing response), not only a non-zero exit.\n- The same probe passed in the previous sweep, or a merge under audit touches the area.\n\n## The first action\n\n- Name the one thing a person does first: look at X, roll back Y, page Z.\n";
|
|
16
|
+
export interface SweepOptions {
|
|
17
|
+
installRoot: string;
|
|
18
|
+
reason: Sweep['reason'];
|
|
19
|
+
/** The merged build an audit sweep is about. */
|
|
20
|
+
buildId?: string | null;
|
|
21
|
+
actor?: Actor;
|
|
22
|
+
/** The sweep's time (the clock's, when it ticks on one). */
|
|
23
|
+
at?: string;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* The Monitor (documentation/agents.md §2.7): the installation's probes run
|
|
27
|
+
* on the cadence, after each merge, or by hand; a model verdict only when a
|
|
28
|
+
* probe failed; an incident only for a real finding with evidence; the watch
|
|
29
|
+
* page in the installation rewritten each sweep. Writes nothing but its own
|
|
30
|
+
* records and page.
|
|
31
|
+
*/
|
|
32
|
+
export declare class Monitor {
|
|
33
|
+
private readonly store;
|
|
34
|
+
private readonly ai;
|
|
35
|
+
private readonly config;
|
|
36
|
+
/** For tests: the runner to use instead of the configured one. */
|
|
37
|
+
private readonly runner?;
|
|
38
|
+
private readonly data;
|
|
39
|
+
private readonly builds;
|
|
40
|
+
private readonly projects;
|
|
41
|
+
private readonly resolver;
|
|
42
|
+
private readonly milestones;
|
|
43
|
+
private readonly queue;
|
|
44
|
+
constructor(store: DataStore, ai: AiService, config: AppConfig, queue?: QueueService,
|
|
45
|
+
/** For tests: the runner to use instead of the configured one. */
|
|
46
|
+
runner?: CommandRunner | undefined);
|
|
47
|
+
role(): Promise<Role | null>;
|
|
48
|
+
get(id: string): Promise<Sweep>;
|
|
49
|
+
/** Sweeps, newest first. */
|
|
50
|
+
recent(limit?: number): Promise<Sweep[]>;
|
|
51
|
+
lastSweep(): Promise<Sweep | null>;
|
|
52
|
+
sweep(options: SweepOptions): Promise<Sweep>;
|
|
53
|
+
/** The probes, in order, each through the runner; a failure does not stop the rest. */
|
|
54
|
+
runProbes(installRoot: string): Promise<ProbeResult[]>;
|
|
55
|
+
private verdict;
|
|
56
|
+
/** The project's highest-ranked spec author, else agents.monitor.notifyUserId, else the first admin-ish user. */
|
|
57
|
+
private assigneeFor;
|
|
58
|
+
/** Audits owed after a merge, one per configured delay. */
|
|
59
|
+
scheduleAudits(buildId: string, mergedAt?: number): Promise<Audit[]>;
|
|
60
|
+
/** Run the audits that are due; returns the sweeps. */
|
|
61
|
+
runDueAudits(installRoot: string, now?: number): Promise<Sweep[]>;
|
|
62
|
+
pendingAudits(): Promise<Audit[]>;
|
|
63
|
+
/** The watch page (documentation/agents.md §2.7): what people read, in the installation. */
|
|
64
|
+
private writeWatchPage;
|
|
65
|
+
}
|
|
66
|
+
//# sourceMappingURL=monitor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"monitor.d.ts","sourceRoot":"","sources":["../../src/agents/monitor.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE,SAAS,EAAE,WAAW,EAAE,IAAI,EAAE,KAAK,EAAgB,MAAM,cAAc,CAAC;AAGxG,OAAO,EAAkB,KAAK,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAElE,OAAO,EAA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AAC,IAAI,GAAG,IAAI,CAAC;IAK5B,GAAG,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,KAAK,CAAC;IAMrC,4BAA4B;IACtB,MAAM,CAAC,KAAK,SAAK,GAAG,OAAO,CAAC,KAAK,EAAE,CAAC;IAIpC,SAAS,IAAI,OAAO,CAAC,KAAK,GAAG,IAAI,CAAC;IAIlC,KAAK,CAAC,OAAO,EAAE,YAAY,GAAG,OAAO,CAAC,KAAK,CAAC;IAmDlD,uFAAuF;IACjF,SAAS,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,EAAE,CAAC;YAY9C,OAAO;IAsCrB,iHAAiH;YACnG,WAAW;IAWzB,2DAA2D;IACrD,cAAc,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,SAAa,GAAG,OAAO,CAAC,KAAK,EAAE,CAAC;IAW9E,uDAAuD;IACjD,YAAY,CAAC,WAAW,EAAE,MAAM,EAAE,GAAG,SAAa,GAAG,OAAO,CAAC,KAAK,EAAE,CAAC;IAWrE,aAAa,IAAI,OAAO,CAAC,KAAK,EAAE,CAAC;IAIvC,4FAA4F;YAC9E,cAAc;CA6B7B"}
|
|
@@ -0,0 +1,281 @@
|
|
|
1
|
+
import { mkdir, writeFile } from 'node:fs/promises';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import { auditSchema, COLLECTIONS, newId, nowIso, parseRole, sweepSchema } from '@aigile/core';
|
|
4
|
+
import { z } from 'zod';
|
|
5
|
+
import { AiBlockedError } from '../ai-service.js';
|
|
6
|
+
import { BuildService } from '../build-service.js';
|
|
7
|
+
import { HostRunner, runnerFor } from '../command-runner.js';
|
|
8
|
+
import { DataAccess } from '../data-access.js';
|
|
9
|
+
import { MilestoneService } from '../milestones.js';
|
|
10
|
+
import { QueueService } from '../queue.js';
|
|
11
|
+
import { ProjectService, ServiceError } from '../services.js';
|
|
12
|
+
import { SpecResolver } from '../spec-resolver.js';
|
|
13
|
+
export const MONITOR_KEY = 'monitor';
|
|
14
|
+
export const MONITOR_ROLE = {
|
|
15
|
+
name: 'Monitor',
|
|
16
|
+
description: 'aigile’s watching agent: sweeps the installation’s probes on a cadence and after each merge, and raises an incident only with evidence it cites. Read-only everywhere.',
|
|
17
|
+
appRole: 'viewer',
|
|
18
|
+
kind: 'agent',
|
|
19
|
+
agentKey: MONITOR_KEY,
|
|
20
|
+
};
|
|
21
|
+
export const MONITOR_CONTRACT = `You are the Monitor of aigile, a system in which people write specs and agents turn them into work that is then merged and deployed. You watch what shipped. You are read-only everywhere: you change no alarm, no threshold, no system; a change you want is a finding for a person.
|
|
22
|
+
|
|
23
|
+
A sweep ran the installation's probes (commands people configured: a health check, a log tail, a count). Some failed. For each failing probe, say what it is: "real" (a problem in the live system, with the evidence from the output you cite and the first action a person should take), "noise" (a known or harmless signature: say why), or "watching" (not enough evidence yet). A finding is real only with evidence you cite; otherwise it is watching. A probe that failed because it could not run (a missing command, a timeout) is watching, not real. Then give the sweep's verdict: "clean" when nothing is real or watching, "watch" when something is watching, "regression" when something is real, and a one-paragraph summary a person reads first. When this sweep audits a merge, say whether the merge looks implicated.
|
|
24
|
+
|
|
25
|
+
Answer in the JSON format requested, nothing else.`;
|
|
26
|
+
export const MONITOR_DEFAULT_BRIEF = `# Monitor brief
|
|
27
|
+
|
|
28
|
+
How the Monitor reads this installation's probes. Edit this spec to change its judgement; add a spec mapped to the Monitor and to an organization or project for signatures that apply only there.
|
|
29
|
+
|
|
30
|
+
## Known noise
|
|
31
|
+
|
|
32
|
+
- (none yet: when a signature is noise, write it here with the date it was last confirmed harmless)
|
|
33
|
+
|
|
34
|
+
## What makes a finding real
|
|
35
|
+
|
|
36
|
+
- The probe's own output shows the problem (an error, a wrong count, a missing response), not only a non-zero exit.
|
|
37
|
+
- The same probe passed in the previous sweep, or a merge under audit touches the area.
|
|
38
|
+
|
|
39
|
+
## The first action
|
|
40
|
+
|
|
41
|
+
- Name the one thing a person does first: look at X, roll back Y, page Z.
|
|
42
|
+
`;
|
|
43
|
+
const verdictSchema = z.object({
|
|
44
|
+
findings: z.array(z.object({ probe: z.string().min(1), grade: z.enum(['real', 'noise', 'watching']), evidence: z.string().default(''), firstAction: z.string().default('') })).default([]),
|
|
45
|
+
verdict: z.enum(['clean', 'watch', 'regression']),
|
|
46
|
+
summary: z.string().default(''),
|
|
47
|
+
});
|
|
48
|
+
const VERDICT_JSON_SCHEMA = {
|
|
49
|
+
type: 'object',
|
|
50
|
+
properties: {
|
|
51
|
+
findings: {
|
|
52
|
+
type: 'array',
|
|
53
|
+
items: {
|
|
54
|
+
type: 'object',
|
|
55
|
+
properties: { probe: { type: 'string' }, grade: { type: 'string', enum: ['real', 'noise', 'watching'] }, evidence: { type: 'string' }, firstAction: { type: 'string' } },
|
|
56
|
+
required: ['probe', 'grade', 'evidence', 'firstAction'],
|
|
57
|
+
additionalProperties: false,
|
|
58
|
+
},
|
|
59
|
+
},
|
|
60
|
+
verdict: { type: 'string', enum: ['clean', 'watch', 'regression'] },
|
|
61
|
+
summary: { type: 'string' },
|
|
62
|
+
},
|
|
63
|
+
required: ['findings', 'verdict', 'summary'],
|
|
64
|
+
additionalProperties: false,
|
|
65
|
+
};
|
|
66
|
+
const TAIL = 3_000;
|
|
67
|
+
/**
|
|
68
|
+
* The Monitor (documentation/agents.md §2.7): the installation's probes run
|
|
69
|
+
* on the cadence, after each merge, or by hand; a model verdict only when a
|
|
70
|
+
* probe failed; an incident only for a real finding with evidence; the watch
|
|
71
|
+
* page in the installation rewritten each sweep. Writes nothing but its own
|
|
72
|
+
* records and page.
|
|
73
|
+
*/
|
|
74
|
+
export class Monitor {
|
|
75
|
+
store;
|
|
76
|
+
ai;
|
|
77
|
+
config;
|
|
78
|
+
runner;
|
|
79
|
+
data;
|
|
80
|
+
builds;
|
|
81
|
+
projects;
|
|
82
|
+
resolver;
|
|
83
|
+
milestones;
|
|
84
|
+
queue;
|
|
85
|
+
constructor(store, ai, config, queue,
|
|
86
|
+
/** For tests: the runner to use instead of the configured one. */
|
|
87
|
+
runner) {
|
|
88
|
+
this.store = store;
|
|
89
|
+
this.ai = ai;
|
|
90
|
+
this.config = config;
|
|
91
|
+
this.runner = runner;
|
|
92
|
+
this.data = new DataAccess(store);
|
|
93
|
+
this.builds = new BuildService(this.data, store);
|
|
94
|
+
this.projects = new ProjectService(store);
|
|
95
|
+
this.resolver = new SpecResolver(this.data);
|
|
96
|
+
this.milestones = new MilestoneService(store);
|
|
97
|
+
this.queue = queue ?? new QueueService(store);
|
|
98
|
+
}
|
|
99
|
+
async role() {
|
|
100
|
+
const raw = await this.store.list(COLLECTIONS.roles);
|
|
101
|
+
return raw.map((r) => parseRole(r)).find((r) => r.agentKey === MONITOR_KEY) ?? null;
|
|
102
|
+
}
|
|
103
|
+
async get(id) {
|
|
104
|
+
const raw = await this.store.get(COLLECTIONS.sweeps, id);
|
|
105
|
+
if (raw === null)
|
|
106
|
+
throw new ServiceError(404, `sweep ${id} not found`);
|
|
107
|
+
return sweepSchema.parse(raw);
|
|
108
|
+
}
|
|
109
|
+
/** Sweeps, newest first. */
|
|
110
|
+
async recent(limit = 20) {
|
|
111
|
+
return (await this.data.sweeps()).sort((a, b) => b.at.localeCompare(a.at)).slice(0, limit);
|
|
112
|
+
}
|
|
113
|
+
async lastSweep() {
|
|
114
|
+
return (await this.recent(1))[0] ?? null;
|
|
115
|
+
}
|
|
116
|
+
async sweep(options) {
|
|
117
|
+
const role = await this.role();
|
|
118
|
+
const actor = options.actor ?? { userId: `agent:${MONITOR_KEY}`, author: { name: role?.name ?? 'Monitor', email: `${MONITOR_KEY}@aigile.local` } };
|
|
119
|
+
const at = options.at ?? nowIso();
|
|
120
|
+
const probes = await this.runProbes(options.installRoot);
|
|
121
|
+
const failing = probes.filter((p) => !p.ok);
|
|
122
|
+
const base = { at, reason: options.reason, buildId: options.buildId ?? null, probes, incidentItemIds: [], costUsd: null };
|
|
123
|
+
let verdict = 'clean';
|
|
124
|
+
let summary = failing.length === 0 ? `${probes.length} probe(s) passed.` : '';
|
|
125
|
+
let findings = [];
|
|
126
|
+
if (failing.length > 0 || options.reason === 'audit') {
|
|
127
|
+
if (!role) {
|
|
128
|
+
verdict = 'blocked';
|
|
129
|
+
summary = 'the Monitor role is not installed; run `aigile install`';
|
|
130
|
+
}
|
|
131
|
+
else {
|
|
132
|
+
const r = await this.verdict(role, probes, options);
|
|
133
|
+
verdict = r.verdict;
|
|
134
|
+
summary = r.summary;
|
|
135
|
+
findings = r.findings;
|
|
136
|
+
base.costUsd = r.costUsd;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
if (probes.length === 0)
|
|
140
|
+
summary = 'no probes are configured (agents.monitor.probes); nothing to sweep';
|
|
141
|
+
const sweep = sweepSchema.parse({ ...base, id: newId(), verdict, summary, findings, createdAt: at, updatedAt: at });
|
|
142
|
+
// Incidents for real findings, to the probe's project approver, else notifyUserId, else nobody (a finding on the sweep).
|
|
143
|
+
for (const f of findings.filter((x) => x.grade === 'real')) {
|
|
144
|
+
const probe = probes.find((p) => p.name === f.probe);
|
|
145
|
+
const assignee = await this.assigneeFor(probe?.projectId ?? null);
|
|
146
|
+
if (!assignee)
|
|
147
|
+
continue;
|
|
148
|
+
const item = await this.queue.open({ kind: 'incident', assigneeUserId: assignee, title: `Incident: ${f.probe}`, summary: f.firstAction || f.evidence.slice(0, 120), ref: { kind: 'sweep', id: sweep.id }, waitingOnRoleId: role?.id ?? null, projectIds: probe?.projectId ? [probe.projectId] : [] }, actor);
|
|
149
|
+
sweep.incidentItemIds.push(item.id);
|
|
150
|
+
}
|
|
151
|
+
await this.store.put(COLLECTIONS.sweeps, sweep.id, sweep, { message: `Sweep (${sweep.reason}): ${sweep.verdict}`, ...(actor.author ? { author: actor.author } : {}) });
|
|
152
|
+
if (probes.length > 0 || options.reason === 'audit') {
|
|
153
|
+
const kind = sweep.verdict === 'regression' ? 'incident' : options.reason === 'audit' ? 'gate-verdict' : sweep.verdict === 'watch' ? 'finding' : null;
|
|
154
|
+
if (kind) {
|
|
155
|
+
await this.milestones.post({ kind, roleId: role?.id ?? null, agentKey: MONITOR_KEY, about: { kind: 'sweep', id: sweep.id }, projectIds: [...new Set(probes.map((p) => p.projectId).filter((x) => !!x))], summary: `${options.reason === 'audit' ? 'Audit' : 'Sweep'}: ${sweep.verdict}${sweep.buildId ? ` for build ${sweep.buildId.slice(0, 8)}` : ''}`, detail: sweep.summary, needs: sweep.verdict === 'regression' ? 'look at the incident' : null }, actor);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
await this.writeWatchPage(options.installRoot, sweep).catch(() => { });
|
|
159
|
+
return sweep;
|
|
160
|
+
}
|
|
161
|
+
/** The probes, in order, each through the runner; a failure does not stop the rest. */
|
|
162
|
+
async runProbes(installRoot) {
|
|
163
|
+
const monitor = this.config.agents.monitor;
|
|
164
|
+
const runner = this.runner ?? (monitor.runtime === 'sandbox' ? runnerFor(this.config.agents.sandbox, [installRoot], 'monitor') : new HostRunner());
|
|
165
|
+
const results = [];
|
|
166
|
+
for (const probe of monitor.probes) {
|
|
167
|
+
const at = Date.now();
|
|
168
|
+
const r = await runner.run(probe.command, { cwd: installRoot, timeoutMs: monitor.timeoutMs, maxOutput: 100_000 });
|
|
169
|
+
results.push({ name: probe.name, command: probe.command, projectId: probe.projectId, ok: r.exitCode === 0 && !r.killed, exitCode: r.killed ? null : r.exitCode, durationMs: Date.now() - at, outputTail: r.output.slice(-TAIL) });
|
|
170
|
+
}
|
|
171
|
+
return results;
|
|
172
|
+
}
|
|
173
|
+
async verdict(role, probes, options) {
|
|
174
|
+
const brief = await this.resolver.resolveRole(role.id);
|
|
175
|
+
const system = [MONITOR_CONTRACT, ...brief.map((b) => `\n\n---\n\n${b.content}`)].join('');
|
|
176
|
+
const previous = await this.lastSweep();
|
|
177
|
+
const build = options.buildId ? await this.builds.get(options.buildId).catch(() => null) : null;
|
|
178
|
+
const project = build ? await this.projects.get(build.projectId).catch(() => null) : null;
|
|
179
|
+
const lines = probes.map((p) => `### Probe ${p.name}${p.projectId ? ` (project ${p.projectId})` : ''}: ${p.ok ? 'passed' : `FAILED (${p.exitCode === null ? 'timed out' : `exit ${p.exitCode}`})`}\n\`${p.command}\`\n\`\`\`\n${p.outputTail.trim() || '(no output)'}\n\`\`\``);
|
|
180
|
+
const user = [
|
|
181
|
+
`## This sweep (${options.reason})`,
|
|
182
|
+
build ? `An audit of the merge of build ${build.id.slice(0, 8)} of ${project?.name ?? build.projectId} (${build.pullRequest?.url ?? 'pushed'}), merged ${build.updatedAt}; its report:\n\n${build.report.slice(0, 2000)}` : '',
|
|
183
|
+
'',
|
|
184
|
+
...lines,
|
|
185
|
+
'',
|
|
186
|
+
previous ? `## The previous sweep (${previous.at}): ${previous.verdict}\n\n${previous.summary}\n${previous.probes.map((p) => `- ${p.name}: ${p.ok ? 'passed' : 'failed'}`).join('\n')}` : '## No previous sweep.',
|
|
187
|
+
'',
|
|
188
|
+
'## Your task',
|
|
189
|
+
'',
|
|
190
|
+
'Grade each failing probe, give the verdict and the summary, as JSON.',
|
|
191
|
+
].join('\n');
|
|
192
|
+
try {
|
|
193
|
+
const result = await this.ai.complete({ system, messages: [{ role: 'user', content: user }], format: { name: 'sweep_verdict', schema: VERDICT_JSON_SCHEMA } }, { roleId: role.id, agentKey: MONITOR_KEY, purpose: `sweep (${options.reason})`, subject: null, briefRevisions: brief.map((b) => ({ specId: b.specId, revision: b.revision })) });
|
|
194
|
+
if (result.stopReason === 'refusal')
|
|
195
|
+
return { verdict: 'blocked', summary: `The model declined: ${result.refusal ?? ''}`, findings: [], costUsd: result.costUsd };
|
|
196
|
+
const parsed = verdictSchema.safeParse(result.json);
|
|
197
|
+
if (!parsed.success)
|
|
198
|
+
return { verdict: 'blocked', summary: `The Monitor's verdict was not readable: ${result.text.slice(0, 200)}`, findings: [], costUsd: result.costUsd };
|
|
199
|
+
const known = new Set(probes.map((p) => p.name));
|
|
200
|
+
const findings = parsed.data.findings.filter((f) => known.has(f.probe));
|
|
201
|
+
// A real finding needs evidence; without it, it is watching.
|
|
202
|
+
for (const f of findings)
|
|
203
|
+
if (f.grade === 'real' && !f.evidence.trim())
|
|
204
|
+
f.grade = 'watching';
|
|
205
|
+
const verdict = findings.some((f) => f.grade === 'real') ? 'regression' : findings.some((f) => f.grade === 'watching') ? 'watch' : 'clean';
|
|
206
|
+
return { verdict, summary: parsed.data.summary, findings, costUsd: result.costUsd };
|
|
207
|
+
}
|
|
208
|
+
catch (err) {
|
|
209
|
+
return { verdict: 'blocked', summary: err instanceof AiBlockedError ? `blocked: ${err.message}` : err instanceof Error ? err.message : String(err), findings: [], costUsd: null };
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
/** The project's highest-ranked spec author, else agents.monitor.notifyUserId, else the first admin-ish user. */
|
|
213
|
+
async assigneeFor(projectId) {
|
|
214
|
+
if (projectId) {
|
|
215
|
+
const resolution = await this.resolver.resolveProject(projectId);
|
|
216
|
+
const ranked = resolution.resolved.filter((r) => r.ranking !== null && !r.authorUserId.startsWith('agent:') && r.authorUserId !== 'aigile');
|
|
217
|
+
if (ranked[0])
|
|
218
|
+
return ranked[0].authorUserId;
|
|
219
|
+
}
|
|
220
|
+
if (this.config.agents.monitor.notifyUserId)
|
|
221
|
+
return this.config.agents.monitor.notifyUserId;
|
|
222
|
+
const users = await this.store.list(COLLECTIONS.users);
|
|
223
|
+
return users.find((u) => !u.disabled)?.id ?? null;
|
|
224
|
+
}
|
|
225
|
+
/** Audits owed after a merge, one per configured delay. */
|
|
226
|
+
async scheduleAudits(buildId, mergedAt = Date.now()) {
|
|
227
|
+
const out = [];
|
|
228
|
+
for (const minutes of this.config.agents.monitor.auditDelaysMinutes) {
|
|
229
|
+
const ts = nowIso();
|
|
230
|
+
const audit = auditSchema.parse({ id: newId(), buildId, dueAt: new Date(mergedAt + minutes * 60_000).toISOString(), done: false, sweepId: null, createdAt: ts, updatedAt: ts });
|
|
231
|
+
await this.store.put(COLLECTIONS.audits, audit.id, audit, { message: `Audit of build ${buildId.slice(0, 8)} due ${audit.dueAt}` });
|
|
232
|
+
out.push(audit);
|
|
233
|
+
}
|
|
234
|
+
return out;
|
|
235
|
+
}
|
|
236
|
+
/** Run the audits that are due; returns the sweeps. */
|
|
237
|
+
async runDueAudits(installRoot, now = Date.now()) {
|
|
238
|
+
const due = (await this.data.audits()).filter((a) => !a.done && Date.parse(a.dueAt) <= now);
|
|
239
|
+
const sweeps = [];
|
|
240
|
+
for (const audit of due) {
|
|
241
|
+
const sweep = await this.sweep({ installRoot, reason: 'audit', buildId: audit.buildId, at: new Date(now).toISOString() });
|
|
242
|
+
await this.store.put(COLLECTIONS.audits, audit.id, { ...audit, done: true, sweepId: sweep.id, updatedAt: nowIso() }, { message: `Audit of build ${audit.buildId.slice(0, 8)} done: ${sweep.verdict}` });
|
|
243
|
+
sweeps.push(sweep);
|
|
244
|
+
}
|
|
245
|
+
return sweeps;
|
|
246
|
+
}
|
|
247
|
+
async pendingAudits() {
|
|
248
|
+
return (await this.data.audits()).filter((a) => !a.done).sort((a, b) => a.dueAt.localeCompare(b.dueAt));
|
|
249
|
+
}
|
|
250
|
+
/** The watch page (documentation/agents.md §2.7): what people read, in the installation. */
|
|
251
|
+
async writeWatchPage(installRoot, sweep) {
|
|
252
|
+
const dir = join(installRoot, 'agents', 'monitor');
|
|
253
|
+
await mkdir(dir, { recursive: true });
|
|
254
|
+
const pending = await this.pendingAudits();
|
|
255
|
+
const lines = [
|
|
256
|
+
'# Watch',
|
|
257
|
+
'',
|
|
258
|
+
`_Written by aigile's Monitor at ${sweep.at}._`,
|
|
259
|
+
'',
|
|
260
|
+
`## Last sweep: ${sweep.verdict} (${sweep.reason}${sweep.buildId ? `, build ${sweep.buildId.slice(0, 8)}` : ''})`,
|
|
261
|
+
'',
|
|
262
|
+
sweep.summary,
|
|
263
|
+
'',
|
|
264
|
+
'| Probe | Result | Time |',
|
|
265
|
+
'|---|---|---|',
|
|
266
|
+
...sweep.probes.map((p) => `| ${p.name} | ${p.ok ? 'passed' : `failed (${p.exitCode === null ? 'timed out' : `exit ${p.exitCode}`})`} | ${Math.round(p.durationMs / 1000)} s |`),
|
|
267
|
+
'',
|
|
268
|
+
'## Open items',
|
|
269
|
+
'',
|
|
270
|
+
...(sweep.findings.length ? sweep.findings.map((f) => `- **${f.grade}** ${f.probe}: ${f.evidence}${f.firstAction ? ` → ${f.firstAction}` : ''}`) : ['- none']),
|
|
271
|
+
'',
|
|
272
|
+
'## Next',
|
|
273
|
+
'',
|
|
274
|
+
`- The cadence: every ${this.config.agents.monitor.cadenceMinutes} min.`,
|
|
275
|
+
...pending.map((a) => `- Audit of build ${a.buildId.slice(0, 8)} at ${a.dueAt}.`),
|
|
276
|
+
'',
|
|
277
|
+
];
|
|
278
|
+
await writeFile(join(dir, 'watch.md'), lines.join('\n'), 'utf8');
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
//# sourceMappingURL=monitor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"monitor.js","sourceRoot":"","sources":["../../src/agents/monitor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC/F,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,EAAsB,UAAU,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACjF,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC/C,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,EAAE,YAAY,E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AG,CAAC,KAAK,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,OAAO,CAAC,CAAC,KAAK,MAAM,CAAC,CAAC,KAAK,KAAK,CAAC,CAAC,QAAQ,GAAG,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC;YAC9J,EAAE;YACF,SAAS;YACT,EAAE;YACF,wBAAwB,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,cAAc,OAAO;YACxE,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,oBAAoB,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC,KAAK,GAAG,CAAC;YACjF,EAAE;SACH,CAAC;QACF,MAAM,SAAS,CAAC,IAAI,CAAC,GAAG,EAAE,UAAU,CAAC,EAAE,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC,CAAC;IACnE,CAAC;CACF"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { AppConfig, Conversation, DataStore, Role } from '@aigile/core';
|
|
2
|
+
import { type AiService } from '../ai-service.js';
|
|
3
|
+
import { QueueService } from '../queue.js';
|
|
4
|
+
import { type Actor } from '../services.js';
|
|
5
|
+
export declare const ORCHESTRATOR_KEY = "orchestrator";
|
|
6
|
+
export declare const ORCHESTRATOR_ROLE: {
|
|
7
|
+
name: string;
|
|
8
|
+
description: string;
|
|
9
|
+
appRole: "maintainer";
|
|
10
|
+
kind: "agent";
|
|
11
|
+
agentKey: string;
|
|
12
|
+
};
|
|
13
|
+
export declare const ORCHESTRATOR_CONTRACT = "You are the Orchestrator of aigile, its Project Manager, and the only agent the people of this installation talk to. aigile turns specs (statements of intent in Markdown, mapped to organizations and projects) into work: the Spec Analyst reads them (conflicts, questions), the Engineer builds them on a branch a person approves, and you keep the tracker, route what needs a person, and answer from the records.\n\nYou do none of the work yourself. You have tools: read the person's queue, the tracks, the projects; open a track; ask the Spec Analyst a question (it answers from the specs with a grade: documented, inferred, undecided); start a build (the Engineer works; the result comes back as an approval for a person). Use a tool when the answer is in the records or the job belongs to an agent; answer directly when you already know. Never invent a record, a status or a spec. Everything you start is visible to the person at once (a track in the board, a question with its answer, a build waiting for approval), so act when asked and say what you did.\n\nApprovals belong to people: you never approve a build, resolve a conflict or decide a question for them; you point them at it. If something is blocked (no provider, a cap, a missing role), say so plainly with what you would have done.\n\nWrite short, plain replies in the person's terms: the answer first, then what you did, then what waits on them, if anything. No preamble, no lists of options you will not take.";
|
|
14
|
+
export declare const ORCHESTRATOR_DEFAULT_BRIEF = "# Orchestrator brief\n\nHow the Orchestrator runs this installation. Edit this spec to change its habits; add a spec mapped to the Orchestrator and to an organization or project for rules that apply only there (who approves what, how tracks are named, what to ask before starting a build).\n\n## Routing\n\n- A question nobody's spec decides goes to the highest-ranked author whose specs cover the area; say who has it.\n- A build's approval goes to the project's highest-ranked author; say who has it.\n\n## Tracks\n\n- Open a track for any piece of work that will take more than one build or involves more than one project; name it by outcome, not by activity.\n- Before starting a build, say which specs changed since the last one if you can tell.\n\n## Tone\n\n- One reply per message. Say what was done and what waits on whom; nothing else.\n";
|
|
15
|
+
export interface OrchestratorActions {
|
|
16
|
+
/** Start the Engineer on a project; resolves with the Build's id and status (the build runs behind). */
|
|
17
|
+
startBuild: (projectId: string, actor: Actor) => Promise<{
|
|
18
|
+
id: string;
|
|
19
|
+
status: string;
|
|
20
|
+
}>;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* The one door (documentation/agents.md §2.1, §3.1): a person's message, the
|
|
24
|
+
* records as context, the tools that reach the other agents, one reply, all
|
|
25
|
+
* of it in their conversation. Events (items queued for them) arrive there
|
|
26
|
+
* too, from the queue.
|
|
27
|
+
*/
|
|
28
|
+
export declare class OrchestratorAgent {
|
|
29
|
+
private readonly store;
|
|
30
|
+
private readonly ai;
|
|
31
|
+
private readonly config;
|
|
32
|
+
private readonly queue;
|
|
33
|
+
private readonly actions;
|
|
34
|
+
private readonly data;
|
|
35
|
+
private readonly conversations;
|
|
36
|
+
private readonly tracks;
|
|
37
|
+
private readonly projects;
|
|
38
|
+
private readonly questions;
|
|
39
|
+
private readonly resolver;
|
|
40
|
+
private readonly milestones;
|
|
41
|
+
constructor(store: DataStore, ai: AiService, config: AppConfig, queue: QueueService, actions: OrchestratorActions);
|
|
42
|
+
role(): Promise<Role | null>;
|
|
43
|
+
/** A person's message: record it, answer it, record the answer; the conversation comes back. */
|
|
44
|
+
chat(actor: Actor, text: string): Promise<Conversation>;
|
|
45
|
+
/** What the person is looking at: their open items, the open tracks, the projects. */
|
|
46
|
+
private context;
|
|
47
|
+
private tools;
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=orchestrator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"orchestrator.d.ts","sourceRoot":"","sources":["../../src/agents/orchestrator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAgB,SAAS,EAAE,YAAY,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AAE3F,OAAO,EAAkB,KAAK,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAIlE,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAE3C,OAAO,EAAE,KAAK,KAAK,EAAkB,MAAM,gBAAgB,CAAC;AAK5D,eAAO,MAAM,gBAAgB,iBAAiB,CAAC;AAE/C,eAAO,MAAM,iBAAiB;;;;;;CAM7B,CAAC;AAEF,eAAO,MAAM,qBAAqB,u8CAM+I,CAAC;AAElL,eAAO,MAAM,0BAA0B,o1BAiBtC,CAAC;AAEF,MAAM,WAAW,mB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