@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,204 @@
|
|
|
1
|
+
import { COLLECTIONS, parseRole } from '@aigile/core';
|
|
2
|
+
import { AiBlockedError } from '../ai-service.js';
|
|
3
|
+
import { ConversationService } from '../conversations.js';
|
|
4
|
+
import { DataAccess } from '../data-access.js';
|
|
5
|
+
import { MilestoneService } from '../milestones.js';
|
|
6
|
+
import { QueueService } from '../queue.js';
|
|
7
|
+
import { QuestionService } from '../questions.js';
|
|
8
|
+
import { ProjectService } from '../services.js';
|
|
9
|
+
import { SpecResolver } from '../spec-resolver.js';
|
|
10
|
+
import { TrackService } from '../tracks.js';
|
|
11
|
+
import { SpecAnalyst } from './spec-analyst.js';
|
|
12
|
+
export const ORCHESTRATOR_KEY = 'orchestrator';
|
|
13
|
+
export const ORCHESTRATOR_ROLE = {
|
|
14
|
+
name: 'Orchestrator',
|
|
15
|
+
description: 'aigile’s Project Manager: the one agent people talk to. It keeps the tracker, routes what needs a person, and starts the other agents.',
|
|
16
|
+
appRole: 'maintainer',
|
|
17
|
+
kind: 'agent',
|
|
18
|
+
agentKey: ORCHESTRATOR_KEY,
|
|
19
|
+
};
|
|
20
|
+
export 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.
|
|
21
|
+
|
|
22
|
+
You 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.
|
|
23
|
+
|
|
24
|
+
Approvals 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.
|
|
25
|
+
|
|
26
|
+
Write 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.`;
|
|
27
|
+
export const ORCHESTRATOR_DEFAULT_BRIEF = `# Orchestrator brief
|
|
28
|
+
|
|
29
|
+
How 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).
|
|
30
|
+
|
|
31
|
+
## Routing
|
|
32
|
+
|
|
33
|
+
- A question nobody's spec decides goes to the highest-ranked author whose specs cover the area; say who has it.
|
|
34
|
+
- A build's approval goes to the project's highest-ranked author; say who has it.
|
|
35
|
+
|
|
36
|
+
## Tracks
|
|
37
|
+
|
|
38
|
+
- 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.
|
|
39
|
+
- Before starting a build, say which specs changed since the last one if you can tell.
|
|
40
|
+
|
|
41
|
+
## Tone
|
|
42
|
+
|
|
43
|
+
- One reply per message. Say what was done and what waits on whom; nothing else.
|
|
44
|
+
`;
|
|
45
|
+
const RECENT_MESSAGES = 30;
|
|
46
|
+
/**
|
|
47
|
+
* The one door (documentation/agents.md §2.1, §3.1): a person's message, the
|
|
48
|
+
* records as context, the tools that reach the other agents, one reply, all
|
|
49
|
+
* of it in their conversation. Events (items queued for them) arrive there
|
|
50
|
+
* too, from the queue.
|
|
51
|
+
*/
|
|
52
|
+
export class OrchestratorAgent {
|
|
53
|
+
store;
|
|
54
|
+
ai;
|
|
55
|
+
config;
|
|
56
|
+
queue;
|
|
57
|
+
actions;
|
|
58
|
+
data;
|
|
59
|
+
conversations;
|
|
60
|
+
tracks;
|
|
61
|
+
projects;
|
|
62
|
+
questions;
|
|
63
|
+
resolver;
|
|
64
|
+
milestones;
|
|
65
|
+
constructor(store, ai, config, queue, actions) {
|
|
66
|
+
this.store = store;
|
|
67
|
+
this.ai = ai;
|
|
68
|
+
this.config = config;
|
|
69
|
+
this.queue = queue;
|
|
70
|
+
this.actions = actions;
|
|
71
|
+
this.milestones = new MilestoneService(store);
|
|
72
|
+
this.data = new DataAccess(store);
|
|
73
|
+
this.conversations = new ConversationService(store);
|
|
74
|
+
this.tracks = new TrackService(store);
|
|
75
|
+
this.projects = new ProjectService(store);
|
|
76
|
+
this.questions = new QuestionService(store, queue);
|
|
77
|
+
this.resolver = new SpecResolver(this.data);
|
|
78
|
+
}
|
|
79
|
+
async role() {
|
|
80
|
+
const raw = await this.store.list(COLLECTIONS.roles);
|
|
81
|
+
return raw.map((r) => parseRole(r)).find((r) => r.agentKey === ORCHESTRATOR_KEY) ?? null;
|
|
82
|
+
}
|
|
83
|
+
/** A person's message: record it, answer it, record the answer; the conversation comes back. */
|
|
84
|
+
async chat(actor, text) {
|
|
85
|
+
const userId = actor.userId;
|
|
86
|
+
await this.conversations.append(userId, { role: 'user', body: text }, actor);
|
|
87
|
+
const role = await this.role();
|
|
88
|
+
const agentActor = { userId: `agent:${ORCHESTRATOR_KEY}`, author: { name: role?.name ?? 'Orchestrator', email: `${ORCHESTRATOR_KEY}@aigile.local` } };
|
|
89
|
+
const reply = async (body, actions = []) => this.conversations.append(userId, { role: 'orchestrator', body, actions }, agentActor);
|
|
90
|
+
if (!role)
|
|
91
|
+
return reply('The Orchestrator role is not installed; run `aigile install`.');
|
|
92
|
+
const brief = await this.resolver.resolveRole(role.id);
|
|
93
|
+
const system = [ORCHESTRATOR_CONTRACT, ...brief.map((b) => `\n\n---\n\n${b.content}`)].join('');
|
|
94
|
+
const context = await this.context(userId);
|
|
95
|
+
const history = (await this.conversations.get(userId)).messages.slice(-RECENT_MESSAGES);
|
|
96
|
+
const messages = history.map((m) => ({ role: m.role === 'user' ? 'user' : 'assistant', content: m.role === 'event' ? `[event] ${m.body}` : m.body }));
|
|
97
|
+
// The first message must be the person's; an event first is folded into their first message.
|
|
98
|
+
while (messages.length && messages[0].role !== 'user')
|
|
99
|
+
messages.shift();
|
|
100
|
+
if (messages.length === 0)
|
|
101
|
+
messages.push({ role: 'user', content: text });
|
|
102
|
+
messages[0] = { role: 'user', content: `${context}\n\n---\n\n${messages[0].content}` };
|
|
103
|
+
// Consecutive same-role turns are fine for the API; but the last must be the user's.
|
|
104
|
+
if (messages[messages.length - 1].role !== 'user')
|
|
105
|
+
messages.push({ role: 'user', content: text });
|
|
106
|
+
const actions = [];
|
|
107
|
+
const tools = this.tools(actor, actions);
|
|
108
|
+
try {
|
|
109
|
+
const result = await this.ai.runTools({ system, messages, tools: { custom: tools }, budgetTokens: 20_000, deadline: Date.now() + 5 * 60 * 1000 }, { roleId: role.id, agentKey: ORCHESTRATOR_KEY, purpose: `reply to ${userId}`, subject: null, briefRevisions: brief.map((b) => ({ specId: b.specId, revision: b.revision })) });
|
|
110
|
+
if (result.stopReason === 'refusal')
|
|
111
|
+
return reply(`I cannot answer that: ${result.refusal ?? 'the model declined'}.`, actions);
|
|
112
|
+
return reply(result.text.trim() || '(no reply)', actions);
|
|
113
|
+
}
|
|
114
|
+
catch (err) {
|
|
115
|
+
const detail = err instanceof AiBlockedError ? err.message : err instanceof Error ? err.message : String(err);
|
|
116
|
+
return reply(`I am blocked: ${detail}. I would have answered from the records and used my tools as needed.`, actions);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
/** What the person is looking at: their open items, the open tracks, the projects. */
|
|
120
|
+
async context(userId) {
|
|
121
|
+
const [items, tracks, projects, milestones] = await Promise.all([this.queue.openFor(userId), this.tracks.list(), this.projects.list(), this.milestones.recent(8)]);
|
|
122
|
+
const open = tracks.filter((t) => t.status !== 'closed');
|
|
123
|
+
return [
|
|
124
|
+
`## Context (the records now)`,
|
|
125
|
+
`Person: ${userId}.`,
|
|
126
|
+
`Projects: ${projects.map((p) => `${p.name} (${p.id}${p.gitUrl ? ', buildable' : ''})`).join('; ') || 'none'}.`,
|
|
127
|
+
`Open tracks: ${open.map((t) => `#${t.number} ${t.title} [${t.status}]`).join('; ') || 'none'}.`,
|
|
128
|
+
`Waiting on this person: ${items.map((i) => `${i.kind}: ${i.title}`).join('; ') || 'nothing'}.`,
|
|
129
|
+
`What the agents did lately: ${milestones.map((m) => `${m.agentKey ?? 'agent'} ${m.kind}: ${m.summary}`).join('; ') || 'nothing yet'}.`,
|
|
130
|
+
].join('\n');
|
|
131
|
+
}
|
|
132
|
+
tools(actor, actions) {
|
|
133
|
+
const note = (tool, summary) => actions.push({ tool, summary });
|
|
134
|
+
const json = (value) => ({ output: JSON.stringify(value, null, 1) });
|
|
135
|
+
return [
|
|
136
|
+
{
|
|
137
|
+
name: 'list_queue',
|
|
138
|
+
description: "The items waiting on this person: conflicts, approvals, questions, with what each is about.",
|
|
139
|
+
inputSchema: { properties: {}, additionalProperties: false },
|
|
140
|
+
run: async () => json((await this.queue.openFor(actor.userId)).map((i) => ({ id: i.id, kind: i.kind, title: i.title, summary: i.summary, about: i.ref }))),
|
|
141
|
+
},
|
|
142
|
+
{
|
|
143
|
+
name: 'list_tracks',
|
|
144
|
+
description: 'The tracks (the tracker), newest first: number, title, status, owner, claims, what blocks it.',
|
|
145
|
+
inputSchema: { properties: { includeClosed: { type: 'boolean' } }, additionalProperties: false },
|
|
146
|
+
run: async (input) => json((await this.tracks.list()).filter((t) => input.includeClosed === true || t.status !== 'closed').map((t) => ({ id: t.id, number: t.number, title: t.title, status: t.status, ownerUserId: t.ownerUserId, ownerRoleId: t.ownerRoleId, claims: t.claims, blockedBy: t.blockedBy, projectIds: t.projectIds }))),
|
|
147
|
+
},
|
|
148
|
+
{
|
|
149
|
+
name: 'list_milestones',
|
|
150
|
+
description: "What the agents reported lately: claimed, finished, blocked, findings, reviews, gate verdicts; newest first.",
|
|
151
|
+
inputSchema: { properties: { limit: { type: 'integer' } }, additionalProperties: false },
|
|
152
|
+
run: async (input) => json((await this.milestones.recent(typeof input.limit === 'number' ? input.limit : 20)).map((m) => ({ at: m.createdAt, agent: m.agentKey, kind: m.kind, summary: m.summary, detail: m.detail.slice(0, 300), about: m.about, needs: m.needs }))),
|
|
153
|
+
},
|
|
154
|
+
{
|
|
155
|
+
name: 'list_projects',
|
|
156
|
+
description: 'The projects: id, name, organization, whether it has a repository to build, and how many specs apply.',
|
|
157
|
+
inputSchema: { properties: {}, additionalProperties: false },
|
|
158
|
+
run: async () => {
|
|
159
|
+
const projects = await this.projects.list();
|
|
160
|
+
const out = [];
|
|
161
|
+
for (const p of projects)
|
|
162
|
+
out.push({ id: p.id, name: p.name, organizationId: p.organizationId, buildable: Boolean(p.gitUrl), specs: (await this.resolver.resolveProject(p.id)).resolved.length });
|
|
163
|
+
return json(out);
|
|
164
|
+
},
|
|
165
|
+
},
|
|
166
|
+
{
|
|
167
|
+
name: 'open_track',
|
|
168
|
+
description: 'Register a track in the tracker for a piece of work; returns its number.',
|
|
169
|
+
inputSchema: { properties: { title: { type: 'string' }, description: { type: 'string' }, projectIds: { type: 'array', items: { type: 'string' } } }, required: ['title'], additionalProperties: false },
|
|
170
|
+
run: async (input) => {
|
|
171
|
+
const track = await this.tracks.create({ title: String(input.title ?? ''), description: String(input.description ?? ''), projectIds: Array.isArray(input.projectIds) ? input.projectIds.map(String) : [] }, actor);
|
|
172
|
+
note('open_track', `Track ${track.number}: ${track.title}`);
|
|
173
|
+
await this.milestones.post({ kind: 'claimed', agentKey: ORCHESTRATOR_KEY, about: { kind: 'track', id: track.id }, projectIds: track.projectIds, summary: `Opened Track ${track.number}: ${track.title} for ${actor.userId}` }, actor);
|
|
174
|
+
return json({ id: track.id, number: track.number, status: track.status });
|
|
175
|
+
},
|
|
176
|
+
},
|
|
177
|
+
{
|
|
178
|
+
name: 'ask_analyst',
|
|
179
|
+
description: 'Ask the Spec Analyst what the specs say about something, for a project or the installation; returns the graded answer with citations. An undecided answer is queued for a person.',
|
|
180
|
+
inputSchema: { properties: { question: { type: 'string' }, projectId: { type: 'string' }, area: { type: 'string' } }, required: ['question'], additionalProperties: false },
|
|
181
|
+
run: async (input) => {
|
|
182
|
+
const asked = await this.questions.ask({ body: String(input.question ?? ''), projectId: typeof input.projectId === 'string' && input.projectId ? input.projectId : null, area: String(input.area ?? '') }, { kind: 'user', id: actor.userId }, actor);
|
|
183
|
+
const answered = await new SpecAnalyst(this.store, this.ai, this.queue).answer(asked.id);
|
|
184
|
+
note('ask_analyst', `${asked.body.slice(0, 60)} → ${answered.answer?.grade ?? 'no answer'}`);
|
|
185
|
+
return json({ questionId: answered.id, grade: answered.answer?.grade, answer: answered.answer?.body, citations: answered.answer?.citations, waitingOn: answered.assigneeUserId });
|
|
186
|
+
},
|
|
187
|
+
},
|
|
188
|
+
{
|
|
189
|
+
name: 'start_build',
|
|
190
|
+
description: "Start the Engineer on a project with a repository; the build runs on its own and ends as an approval for the project's approver. Returns the build id.",
|
|
191
|
+
inputSchema: { properties: { projectId: { type: 'string' } }, required: ['projectId'], additionalProperties: false },
|
|
192
|
+
run: async (input) => {
|
|
193
|
+
const project = await this.projects.get(String(input.projectId ?? ''));
|
|
194
|
+
if (!project.gitUrl)
|
|
195
|
+
return { output: `${project.name} has no repository to build`, isError: true };
|
|
196
|
+
const build = await this.actions.startBuild(project.id, actor);
|
|
197
|
+
note('start_build', `${project.name}: build ${build.id.slice(0, 8)} ${build.status}`);
|
|
198
|
+
return json(build);
|
|
199
|
+
},
|
|
200
|
+
},
|
|
201
|
+
];
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
//# sourceMappingURL=orchestrator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"orchestrator.js","sourceRoot":"","sources":["../../src/agents/orchestrator.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACtD,OAAO,EAAE,cAAc,EAAkB,MAAM,kBAAkB,CAAC;AAClE,OAAO,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAC1D,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC/C,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,EAAc,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAC5D,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEhD,MAAM,CAAC,MAAM,gBAAgB,GAAG,cAAc,CAAC;AAE/C,MAAM,CAAC,MAAM,iBAAiB,GAAG;IAC/B,IAAI,EAAE,cAAc;IACpB,WAAW,EAAE,wIAAwI;IACrJ,OAAO,EAAE,YAAqB;IAC9B,IAAI,EAAE,OAAgB;IACtB,QAAQ,EAAE,gBAAgB;CAC3B,CAAC;AAEF,MAAM,CAAC,MAAM,qBAAqB,GAAG;;;;;;iLAM4I,CAAC;AAElL,MAAM,CAAC,MAAM,0BAA0B,GAAG;;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,CAAC,cAAc,EAAE,CAAC,CAAC;gBACpL,CAAC;aACF;YACD;gBACE,IAAI,EAAE,aAAa;gBACnB,WAAW,EAAE,wJAAwJ;gBACrK,WAAW,EAAE,EAAE,UAAU,EAAE,EAAE,SAAS,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE,EAAE,QAAQ,EAAE,CAAC,WAAW,CAAC,EAAE,oBAAoB,EAAE,KAAK,EAAE;gBACpH,GAAG,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE;oBACnB,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,SAAS,IAAI,EAAE,CAAC,CAAC,CAAC;oBACvE,IAAI,CAAC,OAAO,CAAC,MAAM;wBAAE,OAAO,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,6BAA6B,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;oBACpG,MAAM,KAAK,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,OAAO,CAAC,EAAE,EAAE,KAAK,CAAC,CAAC;oBAC/D,IAAI,CAAC,aAAa,EAAE,GAAG,OAAO,CAAC,IAAI,WAAW,KAAK,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,KAAK,CAAC,MAAM,EAAE,CAAC,CAAC;oBACtF,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC;gBACrB,CAAC;aACF;SACF,CAAC;IACJ,CAAC;CACF"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import type { AppConfig, Build, DataStore, Release, Role } 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
|
+
import type { Monitor } from './monitor.js';
|
|
7
|
+
export declare const RELEASE_MANAGER_KEY = "release-manager";
|
|
8
|
+
export declare const RELEASE_MANAGER_ROLE: {
|
|
9
|
+
name: string;
|
|
10
|
+
description: string;
|
|
11
|
+
appRole: "maintainer";
|
|
12
|
+
kind: "agent";
|
|
13
|
+
agentKey: string;
|
|
14
|
+
};
|
|
15
|
+
export declare const RELEASE_MANAGER_CONTRACT = "You are the Release Manager of aigile, a system in which people write specs and agents turn them into work that is merged and released. A release is being cut: the merged builds since the last release are listed below, each with the Engineer's report and, when there is one, the pull request. Write the release notes a person sends to the people who use the software: what changed for them, grouped by what it means to them, not by build; a line per change; plain words; nothing that is not in the reports. Markdown, no heading above the groups, no preamble.";
|
|
16
|
+
export declare const RELEASE_MANAGER_DEFAULT_BRIEF = "# Release Manager brief\n\nHow the Release Manager writes this installation's release notes and runs its windows. Edit this spec to change its habits; add a spec mapped to the Release Manager and to an organization or project for rules that apply only there (who gets the gates, what a phase must wait for, the words to use).\n\n## Release notes\n\n- Written for the people who use the software: what they can do now, what changed, what was fixed.\n- One line per change; group by area; no build ids, no agent names.\n\n## Windows\n\n- A phase never starts without the go it needs; the person who gives it is recorded on the phase.\n- A failed verify is a stop: nothing proceeds to the next environment until a person decides (rollback, retry, skip).\n";
|
|
17
|
+
export interface ReleaseOptions {
|
|
18
|
+
installRoot: string;
|
|
19
|
+
actor: Actor;
|
|
20
|
+
/** The Monitor, for post-deploy audits when an environment asks for them. */
|
|
21
|
+
monitor?: Pick<Monitor, 'scheduleAudits'> | null;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* The Release Manager (documentation/agents.md §2.6): the one writer of the
|
|
25
|
+
* release and its runbook. `cut` gathers the merged builds, drafts the notes
|
|
26
|
+
* and opens the first gate; `go` runs a phase's deploy and verify through
|
|
27
|
+
* the runner, records every step live, and gates the next; `rollback`,
|
|
28
|
+
* `skip` and `abort` are the person's other answers. Nothing deploys on the
|
|
29
|
+
* clock; every phase waits for a person.
|
|
30
|
+
*/
|
|
31
|
+
export declare class ReleaseManager {
|
|
32
|
+
private readonly store;
|
|
33
|
+
private readonly ai;
|
|
34
|
+
private readonly config;
|
|
35
|
+
/** For tests: the runner to use instead of the configured one. */
|
|
36
|
+
private readonly runner?;
|
|
37
|
+
private readonly data;
|
|
38
|
+
private readonly builds;
|
|
39
|
+
private readonly projects;
|
|
40
|
+
private readonly resolver;
|
|
41
|
+
private readonly milestones;
|
|
42
|
+
private readonly queue;
|
|
43
|
+
constructor(store: DataStore, ai: AiService, config: AppConfig, queue?: QueueService,
|
|
44
|
+
/** For tests: the runner to use instead of the configured one. */
|
|
45
|
+
runner?: CommandRunner | undefined);
|
|
46
|
+
role(): Promise<Role | null>;
|
|
47
|
+
get(id: string): Promise<Release>;
|
|
48
|
+
/** Newest first. */
|
|
49
|
+
list(): Promise<Release[]>;
|
|
50
|
+
current(): Promise<Release | null>;
|
|
51
|
+
/** The merged builds no release carries yet. */
|
|
52
|
+
uncut(): Promise<Build[]>;
|
|
53
|
+
cut(options: ReleaseOptions, name?: string): Promise<Release | null>;
|
|
54
|
+
/** The go on a phase: deploy, then verify; the phase's state and steps live; the next gate, or done. */
|
|
55
|
+
go(releaseId: string, environment: string, options: ReleaseOptions): Promise<Release>;
|
|
56
|
+
private goLocked;
|
|
57
|
+
/** The rollback command for a deployed phase (failed or verified); the phase becomes rolled-back and waits for a go again. */
|
|
58
|
+
rollback(releaseId: string, environment: string, options: ReleaseOptions): Promise<Release>;
|
|
59
|
+
private rollbackLocked;
|
|
60
|
+
/** Skip a phase that waits (the person's call); the next one is gated. */
|
|
61
|
+
skip(releaseId: string, environment: string, actor: Actor): Promise<Release>;
|
|
62
|
+
private skipLocked;
|
|
63
|
+
abort(releaseId: string, actor: Actor): Promise<Release>;
|
|
64
|
+
private environment;
|
|
65
|
+
private allocate;
|
|
66
|
+
/** The notes from the model, or the list of builds when it cannot run. */
|
|
67
|
+
private notes;
|
|
68
|
+
private step;
|
|
69
|
+
private setPhase;
|
|
70
|
+
private update;
|
|
71
|
+
/** Gate the first phase that is still pending; done when none is left. */
|
|
72
|
+
private gateNext;
|
|
73
|
+
/** Open the gate item for a phase and mark it; who gets it: notifyUserId, else the requester, else the first user. */
|
|
74
|
+
private gateFor;
|
|
75
|
+
}
|
|
76
|
+
//# sourceMappingURL=release-manager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"release-manager.d.ts","sourceRoot":"","sources":["../../src/agents/release-manager.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE,SAAS,EAAE,OAAO,EAA6B,IAAI,EAAE,MAAM,cAAc,CAAC;AAE1G,OAAO,EAAkB,KAAK,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAGlE,OAAO,EAAE,KAAK,aAAa,EAAyB,MAAM,sBAAsB,CAAC;AAGjF,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAE,KAAK,KAAK,EAAgC,MAAM,gBAAgB,CAAC;AAE1E,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAE5C,eAAO,MAAM,mBAAmB,oBAAoB,CAAC;AAErD,eAAO,MAAM,oBAAoB;;;;;;CAMhC,CAAC;AAEF,eAAO,MAAM,wBAAwB,mjBAAmjB,CAAC;AAEzlB,eAAO,MAAM,6BAA6B,qvBAazC,CAAC;AAmBF,MAAM,WAAW,cAAc;IAC7B,WAAW,EAAE,MAAM,CAAC;IACpB,KAAK,EAAE,KAAK,CAAC;IACb,6EAA6E;IAC7E,OAAO,CAAC,EAAE,IAAI,CAAC,OAAO,EAAE,gBAAgB,CAAC,GAAG,IAAI,CAAC;CAClD;AAED;;;;;;;GAOG;AACH,qBAAa,cAAc;IASvB,OAAO,CAAC,QAAQ,CAAC,KAAK;IACtB,OAAO,CAAC,QAAQ,CAAC,EAAE;IACnB,OAAO,CAAC,QAAQ,CAAC,MAAM;IAEvB,kEAAkE;IAClE,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC;IAb1B,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AAO,CAAC,OAAO,CAAC;YAI9D,UAAU;IAaxB,KAAK,CAAC,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,GAAG,OAAO,CAAC,OAAO,CAAC;IASxD,OAAO,CAAC,WAAW;YAML,QAAQ;IAQtB,0EAA0E;YAC5D,KAAK;YAgBL,IAAI;IAUlB,OAAO,CAAC,QAAQ;YAIF,MAAM;IAUpB,0EAA0E;YAC5D,QAAQ;IAUtB,sHAAsH;YACxG,OAAO;CAWtB"}
|
|
@@ -0,0 +1,312 @@
|
|
|
1
|
+
import { join } from 'node:path';
|
|
2
|
+
import { COLLECTIONS, newId, nowIso, parseRole, RELEASE_COUNTER_ID, releaseSchema, trackCounterSchema } from '@aigile/core';
|
|
3
|
+
import { AiBlockedError } from '../ai-service.js';
|
|
4
|
+
import { redactSecrets } from '../tool-sandbox.js';
|
|
5
|
+
import { BuildService } from '../build-service.js';
|
|
6
|
+
import { HostRunner, runnerFor } from '../command-runner.js';
|
|
7
|
+
import { DataAccess } from '../data-access.js';
|
|
8
|
+
import { MilestoneService } from '../milestones.js';
|
|
9
|
+
import { QueueService } from '../queue.js';
|
|
10
|
+
import { ProjectService, ServiceError } from '../services.js';
|
|
11
|
+
import { SpecResolver } from '../spec-resolver.js';
|
|
12
|
+
export const RELEASE_MANAGER_KEY = 'release-manager';
|
|
13
|
+
export const RELEASE_MANAGER_ROLE = {
|
|
14
|
+
name: 'Release Manager',
|
|
15
|
+
description: 'aigile’s releasing agent: cuts a release from the merged builds, writes the runbook and the notes, and drives each environment with a person’s go per phase.',
|
|
16
|
+
appRole: 'maintainer',
|
|
17
|
+
kind: 'agent',
|
|
18
|
+
agentKey: RELEASE_MANAGER_KEY,
|
|
19
|
+
};
|
|
20
|
+
export const RELEASE_MANAGER_CONTRACT = `You are the Release Manager of aigile, a system in which people write specs and agents turn them into work that is merged and released. A release is being cut: the merged builds since the last release are listed below, each with the Engineer's report and, when there is one, the pull request. Write the release notes a person sends to the people who use the software: what changed for them, grouped by what it means to them, not by build; a line per change; plain words; nothing that is not in the reports. Markdown, no heading above the groups, no preamble.`;
|
|
21
|
+
export const RELEASE_MANAGER_DEFAULT_BRIEF = `# Release Manager brief
|
|
22
|
+
|
|
23
|
+
How the Release Manager writes this installation's release notes and runs its windows. Edit this spec to change its habits; add a spec mapped to the Release Manager and to an organization or project for rules that apply only there (who gets the gates, what a phase must wait for, the words to use).
|
|
24
|
+
|
|
25
|
+
## Release notes
|
|
26
|
+
|
|
27
|
+
- Written for the people who use the software: what they can do now, what changed, what was fixed.
|
|
28
|
+
- One line per change; group by area; no build ids, no agent names.
|
|
29
|
+
|
|
30
|
+
## Windows
|
|
31
|
+
|
|
32
|
+
- A phase never starts without the go it needs; the person who gives it is recorded on the phase.
|
|
33
|
+
- A failed verify is a stop: nothing proceeds to the next environment until a person decides (rollback, retry, skip).
|
|
34
|
+
`;
|
|
35
|
+
const TAIL = 4_000;
|
|
36
|
+
/** One decision at a time per release: a second go on the same phase waits, then finds it no longer awaiting. */
|
|
37
|
+
const locks = new Map();
|
|
38
|
+
async function withReleaseLock(id, fn) {
|
|
39
|
+
const previous = locks.get(id) ?? Promise.resolve();
|
|
40
|
+
const run = previous.catch(() => { }).then(fn);
|
|
41
|
+
locks.set(id, run);
|
|
42
|
+
try {
|
|
43
|
+
return await run;
|
|
44
|
+
}
|
|
45
|
+
finally {
|
|
46
|
+
if (locks.get(id) === run)
|
|
47
|
+
locks.delete(id);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
const LIVE = new Set(['drafted', 'in-progress']);
|
|
51
|
+
/**
|
|
52
|
+
* The Release Manager (documentation/agents.md §2.6): the one writer of the
|
|
53
|
+
* release and its runbook. `cut` gathers the merged builds, drafts the notes
|
|
54
|
+
* and opens the first gate; `go` runs a phase's deploy and verify through
|
|
55
|
+
* the runner, records every step live, and gates the next; `rollback`,
|
|
56
|
+
* `skip` and `abort` are the person's other answers. Nothing deploys on the
|
|
57
|
+
* clock; every phase waits for a person.
|
|
58
|
+
*/
|
|
59
|
+
export class ReleaseManager {
|
|
60
|
+
store;
|
|
61
|
+
ai;
|
|
62
|
+
config;
|
|
63
|
+
runner;
|
|
64
|
+
data;
|
|
65
|
+
builds;
|
|
66
|
+
projects;
|
|
67
|
+
resolver;
|
|
68
|
+
milestones;
|
|
69
|
+
queue;
|
|
70
|
+
constructor(store, ai, config, queue,
|
|
71
|
+
/** For tests: the runner to use instead of the configured one. */
|
|
72
|
+
runner) {
|
|
73
|
+
this.store = store;
|
|
74
|
+
this.ai = ai;
|
|
75
|
+
this.config = config;
|
|
76
|
+
this.runner = runner;
|
|
77
|
+
this.data = new DataAccess(store);
|
|
78
|
+
this.builds = new BuildService(this.data, store);
|
|
79
|
+
this.projects = new ProjectService(store);
|
|
80
|
+
this.resolver = new SpecResolver(this.data);
|
|
81
|
+
this.milestones = new MilestoneService(store);
|
|
82
|
+
this.queue = queue ?? new QueueService(store);
|
|
83
|
+
}
|
|
84
|
+
async role() {
|
|
85
|
+
const raw = await this.store.list(COLLECTIONS.roles);
|
|
86
|
+
return raw.map((r) => parseRole(r)).find((r) => r.agentKey === RELEASE_MANAGER_KEY) ?? null;
|
|
87
|
+
}
|
|
88
|
+
async get(id) {
|
|
89
|
+
const raw = await this.store.get(COLLECTIONS.releases, id);
|
|
90
|
+
if (raw === null)
|
|
91
|
+
throw new ServiceError(404, `release ${id} not found`);
|
|
92
|
+
return releaseSchema.parse(raw);
|
|
93
|
+
}
|
|
94
|
+
/** Newest first. */
|
|
95
|
+
async list() {
|
|
96
|
+
return (await this.data.releases()).sort((a, b) => b.number - a.number);
|
|
97
|
+
}
|
|
98
|
+
async current() {
|
|
99
|
+
return (await this.list()).find((r) => r.status === 'drafted' || r.status === 'in-progress') ?? null;
|
|
100
|
+
}
|
|
101
|
+
/** The merged builds no release carries yet. */
|
|
102
|
+
async uncut() {
|
|
103
|
+
const carried = new Set((await this.data.releases()).flatMap((r) => r.buildIds));
|
|
104
|
+
return (await this.builds.forProjectAll()).filter((b) => b.status === 'merged' && !carried.has(b.id)).sort((a, b) => a.updatedAt.localeCompare(b.updatedAt));
|
|
105
|
+
}
|
|
106
|
+
async cut(options, name) {
|
|
107
|
+
const environments = this.config.agents.release.environments;
|
|
108
|
+
if (environments.length === 0)
|
|
109
|
+
throw new ServiceError(400, 'no environments are configured (agents.release.environments)');
|
|
110
|
+
if (await this.current())
|
|
111
|
+
throw new ServiceError(409, 'a release is already in progress; finish or abort it first');
|
|
112
|
+
const builds = await this.uncut();
|
|
113
|
+
if (builds.length === 0)
|
|
114
|
+
return null;
|
|
115
|
+
const role = await this.role();
|
|
116
|
+
const agentActor = { userId: `agent:${RELEASE_MANAGER_KEY}`, author: { name: role?.name ?? 'Release Manager', email: `${RELEASE_MANAGER_KEY}@aigile.local` } };
|
|
117
|
+
const number = await this.allocate(agentActor);
|
|
118
|
+
const ts = nowIso();
|
|
119
|
+
const release = releaseSchema.parse({
|
|
120
|
+
id: newId(),
|
|
121
|
+
number,
|
|
122
|
+
name: name?.trim() || `Release ${number}`,
|
|
123
|
+
status: 'drafted',
|
|
124
|
+
buildIds: builds.map((b) => b.id),
|
|
125
|
+
cutAt: ts,
|
|
126
|
+
notes: await this.notes(role, builds),
|
|
127
|
+
phases: environments.map((e) => ({ environment: e.name, status: 'pending', requiresGo: e.requiresGo, steps: [], gateItemId: null, decidedBy: null })),
|
|
128
|
+
log: [{ at: ts, note: `cut with ${builds.length} build(s)` }],
|
|
129
|
+
requestedBy: options.actor.userId,
|
|
130
|
+
createdAt: ts,
|
|
131
|
+
updatedAt: ts,
|
|
132
|
+
});
|
|
133
|
+
await this.store.put(COLLECTIONS.releases, release.id, release, { message: `Release ${number} cut`, ...(agentActor.author ? { author: agentActor.author } : {}) });
|
|
134
|
+
await this.milestones.post({ kind: 'plan-ready', roleId: role?.id ?? null, agentKey: RELEASE_MANAGER_KEY, about: { kind: 'release', id: release.id }, projectIds: [...new Set(builds.map((b) => b.projectId))], summary: `${release.name} cut: ${builds.length} build(s), ${environments.length} phase(s)`, detail: release.notes, needs: `the go for ${environments[0].name}` }, agentActor);
|
|
135
|
+
return this.gateNext(release, agentActor);
|
|
136
|
+
}
|
|
137
|
+
/** The go on a phase: deploy, then verify; the phase's state and steps live; the next gate, or done. */
|
|
138
|
+
go(releaseId, environment, options) {
|
|
139
|
+
return withReleaseLock(releaseId, () => this.goLocked(releaseId, environment, options));
|
|
140
|
+
}
|
|
141
|
+
async goLocked(releaseId, environment, options) {
|
|
142
|
+
let release = await this.get(releaseId);
|
|
143
|
+
if (!LIVE.has(release.status))
|
|
144
|
+
throw new ServiceError(409, `the release is ${release.status}`);
|
|
145
|
+
const index = release.phases.findIndex((p) => p.environment === environment);
|
|
146
|
+
if (index === -1)
|
|
147
|
+
throw new ServiceError(404, `no phase for ${environment}`);
|
|
148
|
+
const phase = release.phases[index];
|
|
149
|
+
if (phase.status !== 'awaiting-go' && phase.status !== 'failed' && phase.status !== 'rolled-back')
|
|
150
|
+
throw new ServiceError(409, `${environment} is ${phase.status}, not awaiting a go`);
|
|
151
|
+
if (index > 0 && !['verified', 'skipped'].includes(release.phases[index - 1].status))
|
|
152
|
+
throw new ServiceError(409, `${release.phases[index - 1].environment} is not done`);
|
|
153
|
+
const env = this.environment(environment);
|
|
154
|
+
const role = await this.role();
|
|
155
|
+
const agentActor = { userId: `agent:${RELEASE_MANAGER_KEY}`, author: { name: role?.name ?? 'Release Manager', email: `${RELEASE_MANAGER_KEY}@aigile.local` } };
|
|
156
|
+
await this.queue.closeAbout({ kind: 'release', id: releaseId }, options.actor);
|
|
157
|
+
release = await this.update(release, { status: 'in-progress' }, (r) => this.setPhase(r, index, { status: 'running', decidedBy: options.actor.userId, gateItemId: null }), `${environment}: go by ${options.actor.userId}`);
|
|
158
|
+
const deploy = await this.step(release, index, 'deploy', env.deploy, options);
|
|
159
|
+
release = deploy.release;
|
|
160
|
+
if (!deploy.ok) {
|
|
161
|
+
release = await this.update(release, {}, (r) => this.setPhase(r, index, { status: 'failed' }), `${environment}: deploy failed`);
|
|
162
|
+
await this.milestones.post({ kind: 'blocked', roleId: role?.id ?? null, agentKey: RELEASE_MANAGER_KEY, about: { kind: 'release', id: releaseId }, summary: `${release.name}: the deploy to ${environment} failed`, detail: deploy.tail, needs: 'rollback, go again, or skip' }, agentActor);
|
|
163
|
+
return this.gateFor(release, index, agentActor, 'failed');
|
|
164
|
+
}
|
|
165
|
+
if (env.verify) {
|
|
166
|
+
const verify = await this.step(release, index, 'verify', env.verify, options);
|
|
167
|
+
release = verify.release;
|
|
168
|
+
if (!verify.ok) {
|
|
169
|
+
release = await this.update(release, {}, (r) => this.setPhase(r, index, { status: 'failed' }), `${environment}: verify failed`);
|
|
170
|
+
await this.milestones.post({ kind: 'gate-verdict', roleId: role?.id ?? null, agentKey: RELEASE_MANAGER_KEY, about: { kind: 'release', id: releaseId }, summary: `${release.name}: ${environment} failed its verify`, detail: verify.tail, needs: 'rollback, go again, or skip' }, agentActor);
|
|
171
|
+
return this.gateFor(release, index, agentActor, 'failed');
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
release = await this.update(release, {}, (r) => this.setPhase(r, index, { status: 'verified' }), `${environment}: verified`);
|
|
175
|
+
if (env.auditAfter && options.monitor)
|
|
176
|
+
for (const id of release.buildIds)
|
|
177
|
+
await options.monitor.scheduleAudits(id);
|
|
178
|
+
await this.milestones.post({ kind: 'gate-verdict', roleId: role?.id ?? null, agentKey: RELEASE_MANAGER_KEY, about: { kind: 'release', id: releaseId }, summary: `${release.name}: ${environment} deployed and verified` }, agentActor);
|
|
179
|
+
return this.gateNext(release, agentActor);
|
|
180
|
+
}
|
|
181
|
+
/** The rollback command for a deployed phase (failed or verified); the phase becomes rolled-back and waits for a go again. */
|
|
182
|
+
rollback(releaseId, environment, options) {
|
|
183
|
+
return withReleaseLock(releaseId, () => this.rollbackLocked(releaseId, environment, options));
|
|
184
|
+
}
|
|
185
|
+
async rollbackLocked(releaseId, environment, options) {
|
|
186
|
+
let release = await this.get(releaseId);
|
|
187
|
+
if (!LIVE.has(release.status))
|
|
188
|
+
throw new ServiceError(409, `the release is ${release.status}`);
|
|
189
|
+
const index = release.phases.findIndex((p) => p.environment === environment);
|
|
190
|
+
if (index === -1)
|
|
191
|
+
throw new ServiceError(404, `no phase for ${environment}`);
|
|
192
|
+
const phase = release.phases[index];
|
|
193
|
+
if (phase.status !== 'failed' && phase.status !== 'verified')
|
|
194
|
+
throw new ServiceError(409, `${environment} is ${phase.status}; only a deployed phase (failed or verified) can be rolled back`);
|
|
195
|
+
if (phase.status === 'verified' && release.phases.slice(index + 1).some((p) => p.status === 'verified' || p.status === 'running'))
|
|
196
|
+
throw new ServiceError(409, `a later environment has already deployed; roll that back first`);
|
|
197
|
+
const env = this.environment(environment);
|
|
198
|
+
if (!env.rollback)
|
|
199
|
+
throw new ServiceError(400, `${environment} has no rollback command`);
|
|
200
|
+
const role = await this.role();
|
|
201
|
+
const agentActor = { userId: `agent:${RELEASE_MANAGER_KEY}`, author: { name: role?.name ?? 'Release Manager', email: `${RELEASE_MANAGER_KEY}@aigile.local` } };
|
|
202
|
+
await this.queue.closeAbout({ kind: 'release', id: releaseId }, options.actor);
|
|
203
|
+
const r = await this.step(release, index, 'rollback', env.rollback, options);
|
|
204
|
+
release = await this.update(r.release, {}, (x) => this.setPhase(x, index, { status: r.ok ? 'rolled-back' : 'failed', decidedBy: options.actor.userId }), `${environment}: rollback ${r.ok ? 'done' : 'failed'}`);
|
|
205
|
+
await this.milestones.post({ kind: r.ok ? 'finished' : 'blocked', roleId: role?.id ?? null, agentKey: RELEASE_MANAGER_KEY, about: { kind: 'release', id: releaseId }, summary: `${release.name}: ${environment} ${r.ok ? 'rolled back' : 'rollback failed'}`, detail: r.tail }, agentActor);
|
|
206
|
+
return this.gateFor(release, index, agentActor, r.ok ? 'rolled-back' : 'failed');
|
|
207
|
+
}
|
|
208
|
+
/** Skip a phase that waits (the person's call); the next one is gated. */
|
|
209
|
+
skip(releaseId, environment, actor) {
|
|
210
|
+
return withReleaseLock(releaseId, () => this.skipLocked(releaseId, environment, actor));
|
|
211
|
+
}
|
|
212
|
+
async skipLocked(releaseId, environment, actor) {
|
|
213
|
+
let release = await this.get(releaseId);
|
|
214
|
+
if (!LIVE.has(release.status))
|
|
215
|
+
throw new ServiceError(409, `the release is ${release.status}`);
|
|
216
|
+
const index = release.phases.findIndex((p) => p.environment === environment);
|
|
217
|
+
if (index === -1)
|
|
218
|
+
throw new ServiceError(404, `no phase for ${environment}`);
|
|
219
|
+
const status = release.phases[index].status;
|
|
220
|
+
if (status !== 'awaiting-go' && status !== 'failed' && status !== 'rolled-back')
|
|
221
|
+
throw new ServiceError(409, `${environment} is ${status}; only a waiting phase can be skipped`);
|
|
222
|
+
await this.queue.closeAbout({ kind: 'release', id: releaseId }, actor);
|
|
223
|
+
release = await this.update(release, { status: 'in-progress' }, (r) => this.setPhase(r, index, { status: 'skipped', decidedBy: actor.userId, gateItemId: null }), `${environment}: skipped by ${actor.userId}`);
|
|
224
|
+
const role = await this.role();
|
|
225
|
+
return this.gateNext(release, { userId: `agent:${RELEASE_MANAGER_KEY}`, author: { name: role?.name ?? 'Release Manager', email: `${RELEASE_MANAGER_KEY}@aigile.local` } });
|
|
226
|
+
}
|
|
227
|
+
abort(releaseId, actor) {
|
|
228
|
+
return withReleaseLock(releaseId, async () => {
|
|
229
|
+
const release = await this.get(releaseId);
|
|
230
|
+
if (!LIVE.has(release.status))
|
|
231
|
+
throw new ServiceError(409, `the release is ${release.status}`);
|
|
232
|
+
await this.queue.closeAbout({ kind: 'release', id: releaseId }, actor);
|
|
233
|
+
return this.update(release, { status: 'aborted' }, (r) => r, `aborted by ${actor.userId}`);
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
environment(name) {
|
|
237
|
+
const env = this.config.agents.release.environments.find((e) => e.name === name);
|
|
238
|
+
if (!env)
|
|
239
|
+
throw new ServiceError(404, `environment ${name} is not configured`);
|
|
240
|
+
return env;
|
|
241
|
+
}
|
|
242
|
+
async allocate(actor) {
|
|
243
|
+
const raw = await this.store.get(COLLECTIONS.releases, RELEASE_COUNTER_ID);
|
|
244
|
+
const existing = (await this.data.releases()).reduce((max, r) => Math.max(max, r.number), 0);
|
|
245
|
+
const next = Math.max(raw ? trackCounterSchema.parse(raw).next : 1, existing + 1);
|
|
246
|
+
await this.store.put(COLLECTIONS.releases, RELEASE_COUNTER_ID, { next: next + 1 }, { message: `Release counter → ${next + 1}`, ...(actor.author ? { author: actor.author } : {}) });
|
|
247
|
+
return next;
|
|
248
|
+
}
|
|
249
|
+
/** The notes from the model, or the list of builds when it cannot run. */
|
|
250
|
+
async notes(role, builds) {
|
|
251
|
+
const projectName = new Map((await this.projects.list()).map((p) => [p.id, p.name]));
|
|
252
|
+
const fallback = builds.map((b) => `- ${projectName.get(b.projectId) ?? b.projectId}: ${b.report.split('\n').find((l) => l.trim() && !l.startsWith('#'))?.trim().slice(0, 120) ?? `build ${b.id.slice(0, 8)}`}${b.pullRequest ? ` (${b.pullRequest.url})` : ''}`).join('\n');
|
|
253
|
+
if (!role)
|
|
254
|
+
return fallback;
|
|
255
|
+
const brief = await this.resolver.resolveRole(role.id);
|
|
256
|
+
const system = [RELEASE_MANAGER_CONTRACT, ...brief.map((b) => `\n\n---\n\n${b.content}`)].join('');
|
|
257
|
+
const user = builds.map((b) => `## ${projectName.get(b.projectId) ?? b.projectId}, build ${b.id.slice(0, 8)}${b.pullRequest ? ` (${b.pullRequest.url})` : ''}\n\n${b.report.slice(0, 4000)}`).join('\n\n');
|
|
258
|
+
try {
|
|
259
|
+
const result = await this.ai.complete({ system, messages: [{ role: 'user', content: `${user}\n\nWrite the release notes.` }] }, { roleId: role.id, agentKey: RELEASE_MANAGER_KEY, purpose: `release notes for ${builds.length} build(s)`, subject: null, briefRevisions: brief.map((b) => ({ specId: b.specId, revision: b.revision })) });
|
|
260
|
+
return result.stopReason === 'refusal' ? fallback : result.text.trim() || fallback;
|
|
261
|
+
}
|
|
262
|
+
catch (err) {
|
|
263
|
+
if (!(err instanceof AiBlockedError))
|
|
264
|
+
console.warn(`[aigile] release notes: ${err instanceof Error ? err.message : String(err)}`);
|
|
265
|
+
return fallback;
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
async step(release, index, kind, command, options) {
|
|
269
|
+
const runner = this.runner ?? (this.config.agents.release.runtime === 'sandbox' ? runnerFor(this.config.agents.sandbox, [options.installRoot], 'release') : new HostRunner());
|
|
270
|
+
const at = Date.now();
|
|
271
|
+
const r = await runner.run(command, { cwd: options.installRoot, timeoutMs: this.config.agents.release.timeoutMs, maxOutput: 200_000 });
|
|
272
|
+
const ok = r.exitCode === 0 && !r.killed;
|
|
273
|
+
const step = { kind, command, at: new Date(at).toISOString(), exitCode: r.killed ? null : r.exitCode, durationMs: Date.now() - at, outputTail: redactSecrets(r.output).slice(-TAIL), by: options.actor.userId };
|
|
274
|
+
const next = await this.update(release, {}, (x) => this.setPhase(x, index, { steps: [...x.phases[index].steps, step] }), `${release.phases[index].environment}: ${kind} ${ok ? 'ok' : 'failed'}`);
|
|
275
|
+
return { release: next, ok, tail: step.outputTail };
|
|
276
|
+
}
|
|
277
|
+
setPhase(release, index, patch) {
|
|
278
|
+
return { ...release, phases: release.phases.map((p, i) => (i === index ? { ...p, ...patch } : p)) };
|
|
279
|
+
}
|
|
280
|
+
async update(release, patch, edit, note) {
|
|
281
|
+
const ts = nowIso();
|
|
282
|
+
// Edit what is stored now, not the copy in hand: an abort meanwhile stays an abort.
|
|
283
|
+
const stored = await this.get(release.id);
|
|
284
|
+
const base = stored.status === 'aborted' && patch.status !== 'aborted' ? { ...stored, ...patch, status: 'aborted' } : { ...stored, ...patch };
|
|
285
|
+
const next = { ...edit(base), updatedAt: ts, log: [...stored.log, { at: ts, note }] };
|
|
286
|
+
await this.store.put(COLLECTIONS.releases, release.id, next, { message: `Release ${release.number}: ${note}` });
|
|
287
|
+
return next;
|
|
288
|
+
}
|
|
289
|
+
/** Gate the first phase that is still pending; done when none is left. */
|
|
290
|
+
async gateNext(release, agentActor) {
|
|
291
|
+
const index = release.phases.findIndex((p) => p.status === 'pending');
|
|
292
|
+
if (index === -1) {
|
|
293
|
+
const done = await this.update(release, { status: 'done' }, (r) => r, 'done');
|
|
294
|
+
await this.milestones.post({ kind: 'finished', roleId: (await this.role())?.id ?? null, agentKey: RELEASE_MANAGER_KEY, about: { kind: 'release', id: release.id }, summary: `${release.name} is done` }, agentActor);
|
|
295
|
+
return done;
|
|
296
|
+
}
|
|
297
|
+
return this.gateFor(release, index, agentActor, 'awaiting-go');
|
|
298
|
+
}
|
|
299
|
+
/** Open the gate item for a phase and mark it; who gets it: notifyUserId, else the requester, else the first user. */
|
|
300
|
+
async gateFor(release, index, agentActor, status) {
|
|
301
|
+
const phase = release.phases[index];
|
|
302
|
+
const assignee = this.config.agents.release.notifyUserId ?? release.requestedBy ?? (await this.store.list(COLLECTIONS.users))[0]?.id ?? null;
|
|
303
|
+
let gateItemId = null;
|
|
304
|
+
if (assignee) {
|
|
305
|
+
const title = status === 'awaiting-go' ? `Go: ${release.name} to ${phase.environment}` : `${release.name}: ${phase.environment} ${status === 'failed' ? 'failed' : 'rolled back'}`;
|
|
306
|
+
const item = await this.queue.open({ kind: 'gate', assigneeUserId: assignee, title, summary: status === 'awaiting-go' ? `${release.buildIds.length} build(s); deploy then verify` : 'rollback, go again, or skip', ref: { kind: 'release', id: release.id }, waitingOnRoleId: (await this.role())?.id ?? null, projectIds: [] }, agentActor);
|
|
307
|
+
gateItemId = item.id;
|
|
308
|
+
}
|
|
309
|
+
return this.update(release, {}, (r) => this.setPhase(r, index, { status: status === 'awaiting-go' ? 'awaiting-go' : status, gateItemId }), `${phase.environment}: ${status === 'awaiting-go' ? 'awaiting the go' : `waiting after ${status}`}`);
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
//# sourceMappingURL=release-manager.js.map
|