ai-agentmanager 1.62.0 → 1.63.0
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/CHANGELOG.md +21 -0
- package/README.md +92 -0
- package/package.json +1 -1
- package/public/acceptance.js +194 -0
- package/public/app.js +61 -2
- package/public/attach.js +4 -0
- package/public/autonomy.js +140 -0
- package/public/boardcols.js +1 -0
- package/public/dropzone.js +203 -0
- package/public/index.html +56 -0
- package/public/menu.js +20 -0
- package/public/scorecard.js +1 -1
- package/public/standup.js +1 -0
- package/public/style.css +47 -1
- package/src/acceptance.js +123 -0
- package/src/advisor.js +30 -8
- package/src/autonomy.js +624 -0
- package/src/autopilot.js +7 -1
- package/src/backlog.js +16 -3
- package/src/brief.js +21 -3
- package/src/bughunt.js +1 -0
- package/src/cli.js +132 -0
- package/src/config.js +3 -0
- package/src/decisions.js +5 -1
- package/src/groundrules.js +97 -0
- package/src/judge.js +1 -1
- package/src/manager.js +174 -5
- package/src/notify.js +16 -0
- package/src/prereview.js +7 -2
- package/src/scorecard.js +26 -9
- package/src/server.js +53 -3
- package/src/standup.js +1 -0
package/src/autonomy.js
ADDED
|
@@ -0,0 +1,624 @@
|
|
|
1
|
+
// Autonomy: how far an agent goes without the person. One level per agent:
|
|
2
|
+
// ask - today's flow: questions, stuck findings and follow-ups wait in the inbox.
|
|
3
|
+
// run - "agree, then run": the person agrees on what done means (acceptance.js), and the middle
|
|
4
|
+
// is handled for them. A question in QUESTIONS.md or a plan waiting for review is decided
|
|
5
|
+
// by Decide (advisor.js) at its "most things" level, whatever the project's level is; a
|
|
6
|
+
// question the agent stopped on in its terminal is answered here from what is already
|
|
7
|
+
// decided (the request, the agreed points, the ground rules, the repository's lessons,
|
|
8
|
+
// earlier answers); a nudge the judge is sure of is sent; a quiet, unfinished agent is
|
|
9
|
+
// told to carry on. Each is recorded, and an answer shows in the inbox as "Answered for
|
|
10
|
+
// you", where the person can change it.
|
|
11
|
+
// pr - and its pull request is opened when the work is ready (review rounds for an agent,
|
|
12
|
+
// autopilot for a backlog item), also when that is turned off in general.
|
|
13
|
+
// merge - and the pull request is merged when its checks pass, the review found it ready and it
|
|
14
|
+
// touches no high-risk path.
|
|
15
|
+
// What never happens here: a permission prompt is never answered by a model, a question about
|
|
16
|
+
// deleting, publishing, money, credentials or scope is left for the person, and an agent cannot
|
|
17
|
+
// raise its own level (server.js refuses its calls).
|
|
18
|
+
//
|
|
19
|
+
// The model calls made here run on a list of models, best first ("fable", "opus", "sonnet" by
|
|
20
|
+
// default): the first one that answers is used, and one that fails is skipped for a while.
|
|
21
|
+
import crypto from 'node:crypto';
|
|
22
|
+
import fs from 'node:fs';
|
|
23
|
+
import { parseJsonReply, specPath } from './brief.js';
|
|
24
|
+
import { memoryKey, memoryText } from './memory.js';
|
|
25
|
+
import { landState } from './tracker.js';
|
|
26
|
+
|
|
27
|
+
export const LEVELS = ['ask', 'run', 'pr', 'merge'];
|
|
28
|
+
export const LEVEL_LABEL = { ask: 'Ask me', run: 'Agree, then run', pr: 'Run to pull request', merge: 'Run to merge' };
|
|
29
|
+
export const AUTONOMY_DEFAULTS = {
|
|
30
|
+
level: 'ask', // for new agents that name none
|
|
31
|
+
models: ['fable', 'opus', 'sonnet'], // best first; the next one when a call fails
|
|
32
|
+
answers: true,
|
|
33
|
+
nudges: true,
|
|
34
|
+
followUps: true,
|
|
35
|
+
minConfidence: 0.7, // of the model, to act on its answer or its nudge
|
|
36
|
+
minBuildConfidence: 70, // of the agent in its own work (its brief), to merge without the person
|
|
37
|
+
maxAnswers: 12, // per agent
|
|
38
|
+
maxNudges: 3,
|
|
39
|
+
maxFollowUps: 2,
|
|
40
|
+
dailyCalls: 80,
|
|
41
|
+
retryMin: 15, // a model that failed is skipped this long
|
|
42
|
+
};
|
|
43
|
+
const LOG_KEEP = 40;
|
|
44
|
+
const SEEN_KEEP = 200;
|
|
45
|
+
|
|
46
|
+
const now = () => new Date().toISOString();
|
|
47
|
+
const today = () => new Date().toISOString().slice(0, 10);
|
|
48
|
+
const err = (status, message) => Object.assign(new Error(message), { status });
|
|
49
|
+
const hash = (s) => crypto.createHash('sha1').update(String(s)).digest('hex').slice(0, 10);
|
|
50
|
+
const clip = (s, n) => {
|
|
51
|
+
const t = String(s ?? '').replace(/\s+/g, ' ').trim();
|
|
52
|
+
return t.length > n ? `${t.slice(0, n - 1)}…` : t;
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
/** A level by its name ("pr", "Run to pull request", "off"); null when it is none of them. */
|
|
56
|
+
export function parseLevel(v) {
|
|
57
|
+
const t = String(v ?? '').trim().toLowerCase();
|
|
58
|
+
if (!t) return null;
|
|
59
|
+
if (LEVELS.includes(t)) return t;
|
|
60
|
+
if (['off', 'none', 'no', 'false'].includes(t)) return 'ask';
|
|
61
|
+
if (['on', 'true', 'yes'].includes(t)) return 'run';
|
|
62
|
+
return LEVELS.find((l) => LEVEL_LABEL[l].toLowerCase() === t) ?? null;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export const levelOf = (agent) => (LEVELS.includes(agent?.autonomy?.level) ? agent.autonomy.level : 'ask');
|
|
66
|
+
export const atLeast = (level, min) => LEVELS.indexOf(level) >= LEVELS.indexOf(min);
|
|
67
|
+
|
|
68
|
+
/** Settings from config.json's "autonomy", with defaults. `models`: names, or { engine, model }. */
|
|
69
|
+
export function autonomySettings(config = {}) {
|
|
70
|
+
const c = config.autonomy ?? {};
|
|
71
|
+
const n = (v, d, lo, hi) => (Number.isFinite(Number(v)) && v !== null && v !== '' ? Math.max(lo, Math.min(hi, Number(v))) : d);
|
|
72
|
+
const models = cleanModels(c.models);
|
|
73
|
+
const d = AUTONOMY_DEFAULTS;
|
|
74
|
+
return {
|
|
75
|
+
level: parseLevel(c.level) ?? d.level,
|
|
76
|
+
models: models.length ? models : d.models,
|
|
77
|
+
answers: c.answers !== false,
|
|
78
|
+
nudges: c.nudges !== false,
|
|
79
|
+
followUps: c.followUps !== false,
|
|
80
|
+
minConfidence: n(c.minConfidence, d.minConfidence, 0.5, 1),
|
|
81
|
+
minBuildConfidence: n(c.minBuildConfidence, d.minBuildConfidence, 0, 100),
|
|
82
|
+
maxAnswers: n(c.maxAnswers, d.maxAnswers, 0, 100),
|
|
83
|
+
maxNudges: n(c.maxNudges, d.maxNudges, 0, 20),
|
|
84
|
+
maxFollowUps: n(c.maxFollowUps, d.maxFollowUps, 0, 20),
|
|
85
|
+
dailyCalls: n(c.dailyCalls, d.dailyCalls, 0, 2000),
|
|
86
|
+
retryMin: n(c.retryMin, d.retryMin, 1, 1440),
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/** A list of models as given ("fable, opus", ["fable", { engine, model }]), cleaned: no empty ones, no repeats, six at most. */
|
|
91
|
+
export function cleanModels(input) {
|
|
92
|
+
const list = typeof input === 'string' ? input.split(/[,\s>]+/) : Array.isArray(input) ? input : [];
|
|
93
|
+
const out = [];
|
|
94
|
+
const seen = new Set();
|
|
95
|
+
for (const m of list) {
|
|
96
|
+
const item = typeof m === 'string' ? m.trim() : m && typeof m.model === 'string' ? { ...(m.engine ? { engine: String(m.engine) } : {}), model: m.model.trim() } : null;
|
|
97
|
+
const name = typeof item === 'string' ? item : item?.model;
|
|
98
|
+
if (!name || !/^[\w.:\/\[\]-]{1,80}$/.test(name)) continue;
|
|
99
|
+
const key = typeof item === 'string' ? item : `${item.engine ?? ''}/${item.model}`;
|
|
100
|
+
if (seen.has(key)) continue;
|
|
101
|
+
seen.add(key);
|
|
102
|
+
out.push(item);
|
|
103
|
+
}
|
|
104
|
+
return out.slice(0, 6);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export const modelName = (m) => (typeof m === 'string' ? m : m?.model ? `${m.engine?.label ?? m.engine ?? ''}${m.engine ? ' ' : ''}${m.model}`.trim() : m?.engine?.label ?? 'the default model');
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Run `call(model)` on the first model that answers, best first. A model that failed within
|
|
111
|
+
* `retryMs` is tried only after the others. `down` (model name -> when it failed) is kept by the
|
|
112
|
+
* caller between calls. Resolves to { text, model, tried: [{ model, error }] }; rejects when none answered.
|
|
113
|
+
*/
|
|
114
|
+
export async function callLadder(models, call, { down = new Map(), retryMs = 15 * 60_000, t = Date.now() } = {}) {
|
|
115
|
+
const isDown = (m) => t - (down.get(modelName(m)) ?? -Infinity) < retryMs;
|
|
116
|
+
const order = [...models.filter((m) => !isDown(m)), ...models.filter(isDown)];
|
|
117
|
+
const tried = [];
|
|
118
|
+
for (const model of order) {
|
|
119
|
+
try {
|
|
120
|
+
const text = await call(model);
|
|
121
|
+
down.delete(modelName(model));
|
|
122
|
+
return { text, model, tried };
|
|
123
|
+
} catch (e) {
|
|
124
|
+
down.set(modelName(model), Date.now());
|
|
125
|
+
tried.push({ model: modelName(model), error: String(e?.message ?? e).slice(0, 200) });
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
throw Object.assign(new Error(`No model answered (${tried.map((x) => x.model).join(', ') || 'none configured'})${tried.length ? `: ${tried.at(-1).error}` : ''}`), { tried });
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
// Questions that are the person's whatever the sources say: the words that go with what cannot be
|
|
132
|
+
// taken back, costs money, or reaches outside the repository.
|
|
133
|
+
const SENSITIVE = [
|
|
134
|
+
[/\b(delet\w*|drop(?:ping)?\s+(?:the\s+)?(?:table|database|column|index)|truncat\w*|wip\w+|eras\w+|rm\s+-rf|overwrit\w+)\b/i, 'deleting or overwriting'],
|
|
135
|
+
[/\b(force[- ]?push\w*|rewrit\w+\s+(?:the\s+)?history|reset\s+--hard|rebase\s+(?:onto\s+)?(?:main|master))\b/i, 'rewriting history'],
|
|
136
|
+
[/\b(deploy\w*|publish\w*|releas\w+|ship\s+to|go\s+live|production|prod\b|merge\s+(?:it|this|the\s+(?:pull\s+request|pr|branch))|npm\s+publish)\b/i, 'publishing, deploying or merging'],
|
|
137
|
+
[/\b(password|credential\w*|secret\w*|api[- ]?keys?|private\s+keys?|access\s+tokens?|auth\s+tokens?)\b/i, 'credentials'],
|
|
138
|
+
[/\b(pay(?:ment|ing)?|purchas\w+|billing|invoice\w*|subscription|pricing|paid\s+plan|cost\s+money|licen[cs]e\w*|legal)\b/i, 'money, licences or legal matters'],
|
|
139
|
+
[/\b(personal\s+data|pii|customer\s+data|user\s+data|gdpr|privacy)\b/i, 'personal data'],
|
|
140
|
+
[/\b(send\s+(?:an?\s+)?(?:email|message)|email\s+(?:the|to)|post\s+(?:to|in|on)\s+(?:slack|the\s+channel)|notify\s+(?:the\s+)?(?:customer|client|team))\b/i, 'sending something to other people'],
|
|
141
|
+
[/\b(scope|out\s+of\s+scope|drop\s+(?:the\s+)?(?:feature|requirement)|skip\s+(?:the\s+)?(?:tests?|requirement|acceptance))\b/i, 'the scope of the task'],
|
|
142
|
+
];
|
|
143
|
+
|
|
144
|
+
/** Why a question is the person's to answer (a short phrase), or null when a model may look at it. */
|
|
145
|
+
export function sensitive(text) {
|
|
146
|
+
const t = String(text ?? '');
|
|
147
|
+
return SENSITIVE.find(([re]) => re.test(t))?.[1] ?? null;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
const block = (tag, body) => (String(body ?? '').trim() ? [`<${tag}>`, String(body).trim(), `</${tag}>`] : []);
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* The call that stands in for the person on one question. `ctx`: { question, options, default,
|
|
154
|
+
* context, intent, spec, points, groundRules, lessons, memory, answers: [{ question, answer }],
|
|
155
|
+
* past: [{ question, answer, outcome }] }.
|
|
156
|
+
*/
|
|
157
|
+
export function answerPrompt(ctx) {
|
|
158
|
+
return [
|
|
159
|
+
'You stand in for a person who is away, for ONE question an AI coding agent asked while working on their task.',
|
|
160
|
+
'Answer it only when one of these holds:',
|
|
161
|
+
'- the answer is already decided by what the person wrote or agreed: the request, the agreed points for what done means, their ground rules, the lessons of the repository, or an earlier answer of theirs;',
|
|
162
|
+
'- it is a routine implementation detail the request leaves to the implementer and that is cheap to change later (a name, where a file goes, which existing helper to use, a default the agent itself proposes).',
|
|
163
|
+
'Leave it for the person ("ask": true) when it changes what is built or how much; when it trades off cost, security, privacy, data or compatibility;',
|
|
164
|
+
'when it would delete, overwrite, publish, deploy, merge, spend money, touch credentials or reach outside the repository; when the sources disagree or do not cover it; or when you are not sure.',
|
|
165
|
+
'Never invent a preference the person has not shown. When nothing decides it and the choice is cheap to change, the agent\'s own stated default is the answer.',
|
|
166
|
+
'Reply with one JSON object only, no prose around it. confidence is a number from 0 to 1.',
|
|
167
|
+
'Shape: {"ask": true|false, "answer": "what to tell the agent, one to three sentences, or empty", "basis": "the source that decides it, quoted briefly, or: routine detail, cheap to change", "confidence": 0.0}',
|
|
168
|
+
'',
|
|
169
|
+
'<question>',
|
|
170
|
+
ctx.question,
|
|
171
|
+
ctx.options?.length ? `Options: ${ctx.options.join(' | ')}` : '',
|
|
172
|
+
ctx.default ? `The agent's default until answered: ${ctx.default}` : '',
|
|
173
|
+
ctx.context ? `Context from the agent: ${ctx.context}` : '',
|
|
174
|
+
'</question>',
|
|
175
|
+
...block('request', clip(ctx.intent, 3000)),
|
|
176
|
+
...block('agreed_points_for_done', (ctx.points ?? []).map((p) => `${p.id}: ${p.text}`).join('\n')),
|
|
177
|
+
...block('ground_rules', (ctx.groundRules ?? []).map((r) => `- ${r}`).join('\n')),
|
|
178
|
+
...block('lessons_of_the_repository', (ctx.lessons ?? []).map((l) => `- ${l}`).join('\n')),
|
|
179
|
+
...block('earlier_answers_from_the_person', (ctx.answers ?? []).map((a) => `- Q: ${clip(a.question, 200)}\n A: ${clip(a.answer, 300)}`).join('\n')),
|
|
180
|
+
...block('spec_written_by_the_agent', String(ctx.spec ?? '').slice(0, 5000)),
|
|
181
|
+
...block('repository_memory', String(ctx.memory ?? '').slice(0, 2500)),
|
|
182
|
+
...(ctx.past?.length
|
|
183
|
+
? ['<how_the_person_took_earlier_answers_given_for_them>', ...ctx.past.map((p) => `- Q: ${clip(p.question, 160)} → answered: ${clip(p.answer, 160)}; the person ${p.outcome}`), '</how_the_person_took_earlier_answers_given_for_them>', 'Calibrate to these: where they changed an answer, be slower to answer that kind of question.']
|
|
184
|
+
: []),
|
|
185
|
+
]
|
|
186
|
+
.filter((l) => l !== '')
|
|
187
|
+
.join('\n');
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/** The model's reply as { ask, answer, basis, confidence }, or null when it is unusable. */
|
|
191
|
+
export function parseAnswer(text) {
|
|
192
|
+
let d;
|
|
193
|
+
try {
|
|
194
|
+
d = parseJsonReply(text);
|
|
195
|
+
} catch {
|
|
196
|
+
return null;
|
|
197
|
+
}
|
|
198
|
+
if (!d || typeof d !== 'object' || typeof d.ask !== 'boolean') return null;
|
|
199
|
+
const answer = clip(d.answer, 600);
|
|
200
|
+
return { ask: d.ask || !answer, answer, basis: clip(d.basis, 300), confidence: Math.max(0, Math.min(1, Number(d.confidence) || 0)) };
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
/** What the agent is told: the answer, and that it was given for the person, not by them. */
|
|
204
|
+
export const autoAnswerMessage = (question, e) =>
|
|
205
|
+
`Answer to your question "${question}": ${e.answer}\n(Given for the user by AI Agent Manager while they are away, from what is already decided${e.basis ? `: ${e.basis}` : ''}. The user sees it and may change it; record it in your brief as an assumption.)`;
|
|
206
|
+
|
|
207
|
+
export const correctionMessage = (e, text) => `Correction from the user: your question "${e.question}" was answered for them with "${e.answer}". Their own answer is: ${text}\nApply it, and undo what you did on the earlier answer where it differs.`;
|
|
208
|
+
|
|
209
|
+
export const nudgeNote = '\n(Sent by AI Agent Manager while the user is away. If this does not help, set your brief to blocked and say what you need.)';
|
|
210
|
+
|
|
211
|
+
export const followUpMessage = (v) =>
|
|
212
|
+
`You have been quiet for a while and the task is not finished${v?.detail ? ` (${v.detail})` : ''}. Carry on from where you stopped: check your brief and plan, do the next step, and keep the brief current. ` +
|
|
213
|
+
'If you are waiting for something only the user can give, set the brief to blocked and say exactly what you need.';
|
|
214
|
+
|
|
215
|
+
/** "2 answered, 1 nudge, 1 left for you", from an agent's log. */
|
|
216
|
+
export function logLine(log = []) {
|
|
217
|
+
const n = (k) => log.filter((e) => e.kind === k).length;
|
|
218
|
+
const parts = [
|
|
219
|
+
n('answer') ? `${n('answer')} answered` : '',
|
|
220
|
+
n('nudge') ? `${n('nudge')} nudge${n('nudge') === 1 ? '' : 's'}` : '',
|
|
221
|
+
n('followup') ? `${n('followup')} follow-up${n('followup') === 1 ? '' : 's'}` : '',
|
|
222
|
+
n('plan') ? 'plan decided' : '',
|
|
223
|
+
n('merge') ? 'merged' : '',
|
|
224
|
+
n('left') ? `${n('left')} left for you` : '',
|
|
225
|
+
].filter(Boolean);
|
|
226
|
+
return parts.join(', ');
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
/** An agent this can work for: a task with changes of its own, not a team member, reviewer, hunter or builder. */
|
|
230
|
+
export const eligible = (agent) => agent?.kind === 'task' && !agent.team && !agent.builds && !agent.reviewing && !agent.hunting && !agent.fixing && !agent.raceId;
|
|
231
|
+
|
|
232
|
+
export class Autonomy {
|
|
233
|
+
/**
|
|
234
|
+
* `review.get(id)` gives an agent's changes ({ files, diffHash }); `landing` merges; `backlog`
|
|
235
|
+
* says which agents are a backlog item's (autopilot ships those).
|
|
236
|
+
*/
|
|
237
|
+
constructor({ manager, store, config = {}, review = null, landing = null, backlog = null, log = (m) => console.log(`[agentmgr] ${m}`) }) {
|
|
238
|
+
Object.assign(this, { manager, store, config, review, landing, backlog, log });
|
|
239
|
+
this.working = new Set(); // agent ids with a step in progress
|
|
240
|
+
this.queued = null;
|
|
241
|
+
this.kick = () => this.schedule();
|
|
242
|
+
manager.autonomy = this;
|
|
243
|
+
manager.on('change', this.kick);
|
|
244
|
+
manager.on('prs', this.kick);
|
|
245
|
+
this.timer = setInterval(this.kick, 30_000);
|
|
246
|
+
this.timer.unref?.();
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
close() {
|
|
250
|
+
clearInterval(this.timer);
|
|
251
|
+
clearTimeout(this.queued);
|
|
252
|
+
this.manager.off('change', this.kick);
|
|
253
|
+
this.manager.off('prs', this.kick);
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
get settings() {
|
|
257
|
+
return autonomySettings(this.config);
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
schedule() {
|
|
261
|
+
if (this.queued) return;
|
|
262
|
+
this.queued = setTimeout(() => {
|
|
263
|
+
this.queued = null;
|
|
264
|
+
this.tick();
|
|
265
|
+
}, 500);
|
|
266
|
+
this.queued.unref?.();
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
/** One look at every agent that runs without the person. Steps of different agents run side by side. */
|
|
270
|
+
tick() {
|
|
271
|
+
const runs = [];
|
|
272
|
+
for (const agent of this.store.list()) {
|
|
273
|
+
const level = levelOf(agent);
|
|
274
|
+
if (level === 'ask' || !eligible(agent) || this.working.has(agent.id)) continue;
|
|
275
|
+
this.working.add(agent.id);
|
|
276
|
+
runs.push(
|
|
277
|
+
this.step(agent.id, level)
|
|
278
|
+
.catch((e) => this.log(`autonomy: ${agent.name}: ${e.message}`))
|
|
279
|
+
.finally(() => this.working.delete(agent.id)),
|
|
280
|
+
);
|
|
281
|
+
}
|
|
282
|
+
return Promise.all(runs);
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
// ------------------------------------------------------------ the record
|
|
286
|
+
|
|
287
|
+
state(agent) {
|
|
288
|
+
return { log: [], seen: {}, ...agent.autonomy };
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
/** Change an agent's record, from the stored one (a step can take a while). */
|
|
292
|
+
put(id, fn) {
|
|
293
|
+
const agent = this.store.get(id);
|
|
294
|
+
if (!agent?.autonomy) return null;
|
|
295
|
+
const st = this.state(agent);
|
|
296
|
+
fn(st);
|
|
297
|
+
if (st.log.length > LOG_KEEP) st.log = st.log.slice(-LOG_KEEP);
|
|
298
|
+
// What was looked at, newest kept: a question or finding seen long ago does not come back.
|
|
299
|
+
const seen = Object.entries(st.seen);
|
|
300
|
+
if (seen.length > SEEN_KEEP) st.seen = Object.fromEntries(seen.sort((a, b) => String(a[1]).localeCompare(String(b[1]))).slice(-SEEN_KEEP));
|
|
301
|
+
return this.manager.patch(id, { autonomy: st });
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
record(id, entry) {
|
|
305
|
+
const e = { id: crypto.randomBytes(4).toString('hex'), at: now(), ...entry };
|
|
306
|
+
this.put(id, (st) => st.log.push(e));
|
|
307
|
+
return e;
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
usage() {
|
|
311
|
+
const u = (this.store.data.autonomy ??= {});
|
|
312
|
+
if (u.day !== today()) Object.assign(u, { day: today(), calls: 0 });
|
|
313
|
+
return u;
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
status() {
|
|
317
|
+
const s = this.settings;
|
|
318
|
+
const u = this.usage();
|
|
319
|
+
const agents = this.store.list().filter((a) => levelOf(a) !== 'ask');
|
|
320
|
+
return { ...s, labels: LEVEL_LABEL, levels: LEVELS, calls: u.calls, lastModel: u.lastModel ?? null, lastError: u.lastError ?? null, agents: agents.length };
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
/** Changes from the API: `level` (for new agents), `models` (best first), the switches and the limits. */
|
|
324
|
+
change(b = {}) {
|
|
325
|
+
const next = { ...this.config.autonomy };
|
|
326
|
+
if ('level' in b) {
|
|
327
|
+
const level = parseLevel(b.level);
|
|
328
|
+
if (!level) throw err(400, `level is one of ${LEVELS.join(', ')}`);
|
|
329
|
+
next.level = level;
|
|
330
|
+
}
|
|
331
|
+
if ('models' in b) {
|
|
332
|
+
const models = cleanModels(b.models);
|
|
333
|
+
if (!models.length) throw err(400, 'Name at least one model, best first: fable, opus, sonnet');
|
|
334
|
+
next.models = models;
|
|
335
|
+
}
|
|
336
|
+
for (const k of ['answers', 'nudges', 'followUps']) if (k in b) next[k] = b[k] === true || b[k] === 'on';
|
|
337
|
+
for (const k of ['minConfidence', 'minBuildConfidence', 'maxAnswers', 'maxNudges', 'maxFollowUps', 'dailyCalls']) {
|
|
338
|
+
if (!(k in b)) continue;
|
|
339
|
+
if (!Number.isFinite(Number(b[k])) || Number(b[k]) < 0) throw err(400, `${k} must be a number`);
|
|
340
|
+
next[k] = Number(b[k]);
|
|
341
|
+
}
|
|
342
|
+
this.config.autonomy = next;
|
|
343
|
+
return next;
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
// ------------------------------------------------------------ one agent
|
|
347
|
+
|
|
348
|
+
/** Set an agent's level. Its record (what was answered and sent for you) is kept. */
|
|
349
|
+
setLevel(ref, value) {
|
|
350
|
+
const agent = this.manager.mustGet(ref);
|
|
351
|
+
const level = parseLevel(value);
|
|
352
|
+
if (!level) throw err(400, `autonomy is one of ${LEVELS.join(', ')}`);
|
|
353
|
+
if (level !== 'ask' && !eligible(agent)) throw err(400, 'Only a task agent with changes of its own can run without you (not a team member, a reviewer, a bug hunt or a general session)');
|
|
354
|
+
if (level === levelOf(agent)) return this.manager.view(agent);
|
|
355
|
+
const st = this.state(agent);
|
|
356
|
+
const next = level === 'ask' && !st.log.length ? null : { ...st, level, hold: null };
|
|
357
|
+
const v = this.manager.view(this.manager.patch(agent.id, { autonomy: next }));
|
|
358
|
+
this.schedule();
|
|
359
|
+
return v;
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
async step(id, level) {
|
|
363
|
+
const agent = this.store.get(id);
|
|
364
|
+
if (!agent || agent.status === 'preparing' || agent.desktop) return;
|
|
365
|
+
const s = this.settings;
|
|
366
|
+
const v = this.manager.view(agent);
|
|
367
|
+
const st = this.state(agent);
|
|
368
|
+
const count = (k) => st.log.filter((e) => e.kind === k).length;
|
|
369
|
+
|
|
370
|
+
if (s.answers) {
|
|
371
|
+
// Questions in QUESTIONS.md and plans are Decide's (advisor.js); the one it stopped on in its terminal is ours.
|
|
372
|
+
const w = v.runtime?.waiting;
|
|
373
|
+
const asked = w?.state === 'question' ? w.question || w.summary : null;
|
|
374
|
+
if (asked && !st.seen[`w:${hash(asked)}`]) return this.answer(agent, { key: `w:${hash(asked)}`, question: asked, options: w.choices ?? [] });
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
if (s.nudges) {
|
|
378
|
+
for (const f of v.stuck ?? []) {
|
|
379
|
+
const key = `s:${f.key}:${f.since}`;
|
|
380
|
+
if (st.seen[key] || f.ai?.verdict !== 'stuck' || !(f.ai.confidence >= s.minConfidence) || !f.nudge) continue;
|
|
381
|
+
if (count('nudge') >= s.maxNudges) {
|
|
382
|
+
this.put(id, (x) => (x.seen[key] = now()));
|
|
383
|
+
continue; // it stays in the inbox, for the person
|
|
384
|
+
}
|
|
385
|
+
this.put(id, (x) => (x.seen[key] = now()));
|
|
386
|
+
this.manager.tell(id, `${f.nudge}${nudgeNote}`, { source: 'autonomy' });
|
|
387
|
+
this.manager.dismissStuck(id, f.key, { feedback: null });
|
|
388
|
+
this.record(id, { kind: 'nudge', title: f.title, text: f.nudge, confidence: f.ai.confidence, model: f.ai.by ?? null });
|
|
389
|
+
this.log(`autonomy: nudged ${agent.name}: ${f.title}`);
|
|
390
|
+
return;
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
const fu = v.followUp;
|
|
395
|
+
if (s.followUps && fu?.kind === 'followup' && !st.seen[`f:${fu.since}`]) {
|
|
396
|
+
const waitsOnPerson = this.manager.acceptanceWaits(agent) || (agent.planReview && agent.planReview.status !== 'approved') || v.results?.outcome === 'blocked';
|
|
397
|
+
if (!waitsOnPerson) {
|
|
398
|
+
this.put(id, (x) => (x.seen[`f:${fu.since}`] = now()));
|
|
399
|
+
if (count('followup') < s.maxFollowUps) {
|
|
400
|
+
this.manager.tell(id, followUpMessage(fu), { source: 'autonomy' });
|
|
401
|
+
this.record(id, { kind: 'followup', title: fu.title, text: fu.detail ?? '' });
|
|
402
|
+
this.log(`autonomy: told ${agent.name} to carry on (${fu.title})`);
|
|
403
|
+
return;
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
if (level === 'merge' && this.landing && !this.backlogItem(id)) await this.land(agent, v);
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
/** The backlog item an agent works on, if any: autopilot ships those (autopilot.js). */
|
|
412
|
+
backlogItem(id) {
|
|
413
|
+
return this.backlog?.items().find((it) => it.agentId === id) ?? null;
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
// -------------------------------------------------------------- answers
|
|
417
|
+
|
|
418
|
+
context(agent) {
|
|
419
|
+
let spec = '';
|
|
420
|
+
try {
|
|
421
|
+
spec = fs.readFileSync(specPath(agent.id), 'utf8');
|
|
422
|
+
} catch {}
|
|
423
|
+
const questions = new Map((this.manager.questionsView(agent) ?? []).map((q) => [q.id, q.question]));
|
|
424
|
+
const answers = Object.entries(agent.answers ?? {})
|
|
425
|
+
.filter(([, a]) => a.by !== 'autonomy')
|
|
426
|
+
.map(([qid, a]) => ({ question: questions.get(qid) ?? '(an earlier question)', answer: a.text }))
|
|
427
|
+
.slice(-8);
|
|
428
|
+
const past = [];
|
|
429
|
+
for (const a of this.store.list()) {
|
|
430
|
+
for (const e of a.autonomy?.log ?? []) if (e.kind === 'answer' && (e.ack || e.corrected)) past.push({ at: e.at, question: e.question, answer: e.answer, outcome: e.corrected ? `changed it to: ${clip(e.corrected, 160)}` : 'kept it' });
|
|
431
|
+
}
|
|
432
|
+
past.sort((x, y) => x.at.localeCompare(y.at));
|
|
433
|
+
return {
|
|
434
|
+
intent: agent.intent,
|
|
435
|
+
spec,
|
|
436
|
+
points: agent.acceptance?.status === 'agreed' ? agent.acceptance.points : [],
|
|
437
|
+
groundRules: this.manager.groundRules?.list() ?? [],
|
|
438
|
+
lessons: (this.manager.standards?.forAgent(agent).lessons ?? []).map((l) => l.text).filter(Boolean),
|
|
439
|
+
memory: this.config.memory === false ? '' : memoryText(memoryKey(agent)),
|
|
440
|
+
answers,
|
|
441
|
+
past: past.slice(-8),
|
|
442
|
+
};
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
/** One question: leave it for the person, or answer it from what is already decided. */
|
|
446
|
+
async answer(agent, q) {
|
|
447
|
+
const id = agent.id;
|
|
448
|
+
const s = this.settings;
|
|
449
|
+
const st = this.state(agent);
|
|
450
|
+
const left = (why) => {
|
|
451
|
+
this.put(id, (x) => (x.seen[q.key] = now()));
|
|
452
|
+
this.record(id, { kind: 'left', key: q.key, question: clip(q.question, 300), why });
|
|
453
|
+
};
|
|
454
|
+
const touchy = sensitive([q.question, ...(q.options ?? []), q.default, q.context].filter(Boolean).join('\n'));
|
|
455
|
+
if (touchy) return left(`It is about ${touchy}: yours to answer.`);
|
|
456
|
+
if (st.log.filter((e) => e.kind === 'answer').length >= s.maxAnswers) return left(`${s.maxAnswers} questions were already answered for you on this agent.`);
|
|
457
|
+
const u = this.usage();
|
|
458
|
+
if (u.calls >= s.dailyCalls) return left("Today's calls for answering are used up.");
|
|
459
|
+
u.calls++;
|
|
460
|
+
// Seen before the call: a second look while it runs must not ask again.
|
|
461
|
+
this.put(id, (x) => (x.seen[q.key] = now()));
|
|
462
|
+
let r;
|
|
463
|
+
try {
|
|
464
|
+
r = await this.manager.ladderShot(agent, answerPrompt({ ...q, ...this.context(agent) }), { timeoutMs: 120_000 });
|
|
465
|
+
} catch (e) {
|
|
466
|
+
u.lastError = { at: now(), message: String(e.message).slice(0, 300) };
|
|
467
|
+
this.store.save();
|
|
468
|
+
this.record(id, { kind: 'left', key: q.key, question: clip(q.question, 300), why: 'No model could be reached to look at it.' });
|
|
469
|
+
return;
|
|
470
|
+
}
|
|
471
|
+
u.lastModel = r.by;
|
|
472
|
+
this.store.save();
|
|
473
|
+
const d = parseAnswer(r.text);
|
|
474
|
+
if (!d || d.ask || d.confidence < s.minConfidence) {
|
|
475
|
+
this.record(id, { kind: 'left', key: q.key, question: clip(q.question, 300), why: d ? (d.ask ? d.basis || 'Nothing already decided covers it.' : `Not sure enough (${Math.round(d.confidence * 100)}%).`) : 'The reply could not be read.', model: r.by });
|
|
476
|
+
return;
|
|
477
|
+
}
|
|
478
|
+
// The person may have answered while the model was thinking: theirs stands.
|
|
479
|
+
const cur = this.store.get(id);
|
|
480
|
+
if (!cur || levelOf(cur) === 'ask') return;
|
|
481
|
+
if (q.qid) {
|
|
482
|
+
if (cur.answers?.[q.qid]) return;
|
|
483
|
+
this.manager.patch(id, { answers: { ...cur.answers, [q.qid]: { text: d.answer, at: now(), by: 'autonomy', model: r.by, basis: d.basis } } });
|
|
484
|
+
} else {
|
|
485
|
+
const rt = this.manager.runtimes.get(id);
|
|
486
|
+
const w = rt?.waiting;
|
|
487
|
+
if (!w || (w.question || w.summary) !== q.question) return;
|
|
488
|
+
rt.waiting = null;
|
|
489
|
+
}
|
|
490
|
+
const e = this.record(id, { kind: 'answer', key: q.key, qid: q.qid ?? null, question: clip(q.question, 300), answer: d.answer, basis: d.basis, confidence: d.confidence, model: r.by, ack: false });
|
|
491
|
+
this.manager.tell(id, autoAnswerMessage(q.question, e), { source: 'autonomy' });
|
|
492
|
+
this.log(`autonomy: answered for ${agent.name} (${r.by}): ${clip(q.question, 80)}`);
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
// ---------------------------------------------- with Decide (advisor.js)
|
|
496
|
+
|
|
497
|
+
/** For Decide: does this agent run without the person? */
|
|
498
|
+
autonomous(agentId) {
|
|
499
|
+
const agent = this.store.get(agentId);
|
|
500
|
+
return Boolean(agent) && eligible(agent) && levelOf(agent) !== 'ask' && this.settings.answers;
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
/** For Decide: why an item is the person's whatever is recommended, or null. */
|
|
504
|
+
guard(item) {
|
|
505
|
+
return sensitive([item.question, ...(item.options ?? []), item.default, item.context].filter(Boolean).join('\n'));
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
/** For Decide: what its recommendation should know of this agent's task. */
|
|
509
|
+
briefContext(item) {
|
|
510
|
+
const agent = this.store.get(item.agentId);
|
|
511
|
+
if (!agent) return {};
|
|
512
|
+
const c = this.context(agent);
|
|
513
|
+
return { points: c.points, groundRules: c.groundRules, repoLessons: c.lessons };
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
/** Decide carried something out for an agent that runs without the person: it goes on that agent's record. */
|
|
517
|
+
decided(h) {
|
|
518
|
+
const agent = this.store.get(h.agentId);
|
|
519
|
+
if (!agent?.autonomy || levelOf(agent) === 'ask') return;
|
|
520
|
+
if (h.action === 'answer') this.record(agent.id, { kind: 'answer', via: 'decide', qid: h.qid ?? null, question: clip(h.title, 300), answer: clip(h.text, 600), basis: clip(h.why, 300), confidence: h.confidence ?? null, model: null, ack: false });
|
|
521
|
+
else this.record(agent.id, { kind: 'plan', via: 'decide', title: h.did, text: clip(h.why, 300) });
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
entry(agent, entryId) {
|
|
525
|
+
const e = (agent.autonomy?.log ?? []).find((x) => x.id === entryId);
|
|
526
|
+
if (!e) throw err(404, 'No such entry');
|
|
527
|
+
return e;
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
/** "OK": the person has seen what was done for them (an answer, a held merge). */
|
|
531
|
+
ack(ref, entryId) {
|
|
532
|
+
const agent = this.manager.mustGet(ref);
|
|
533
|
+
if (entryId === 'hold') return this.manager.view(this.put(agent.id, (st) => st.hold && (st.hold.ack = true)) ?? agent);
|
|
534
|
+
this.entry(agent, entryId);
|
|
535
|
+
return this.manager.view(this.put(agent.id, (st) => (st.log.find((x) => x.id === entryId).ack = true)));
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
/** The person's own answer to a question that was answered for them: the agent is told to apply it. */
|
|
539
|
+
correct(ref, entryId, text) {
|
|
540
|
+
const agent = this.manager.mustGet(ref);
|
|
541
|
+
const e = this.entry(agent, entryId);
|
|
542
|
+
if (e.kind !== 'answer') throw err(400, 'Only an answer can be changed');
|
|
543
|
+
text = String(text ?? '').trim();
|
|
544
|
+
if (!text) throw err(400, 'Your answer is empty');
|
|
545
|
+
if (e.qid) this.manager.patch(agent.id, { answers: { ...agent.answers, [e.qid]: { text, at: now() } } });
|
|
546
|
+
this.put(agent.id, (st) => Object.assign(st.log.find((x) => x.id === entryId), { ack: true, corrected: clip(text, 600) }));
|
|
547
|
+
return this.manager.tell(agent.id, correctionMessage(e, text), { source: 'answer' });
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
// ---------------------------------------------------------------- merge
|
|
551
|
+
|
|
552
|
+
/** Stop and wait for the person on this state of the pull request; shown once in the inbox. */
|
|
553
|
+
hold(id, key, note) {
|
|
554
|
+
const cur = this.store.get(id)?.autonomy?.hold;
|
|
555
|
+
if (cur?.key === key && cur.note === note) return;
|
|
556
|
+
this.log(`autonomy: holding ${this.store.get(id)?.name}: ${note}`);
|
|
557
|
+
this.put(id, (st) => (st.hold = { key, note: clip(note, 500), at: now(), ack: false }));
|
|
558
|
+
}
|
|
559
|
+
|
|
560
|
+
/** "Run to merge" for an agent that is not a backlog item: merge its pull request when everything says ready. */
|
|
561
|
+
async land(agent, v) {
|
|
562
|
+
const id = agent.id;
|
|
563
|
+
const s = this.settings;
|
|
564
|
+
for (const pr of this.landing.openPrs(agent)) {
|
|
565
|
+
const state = landState(pr);
|
|
566
|
+
const key = `${pr.url}@${pr.head ?? ''}`;
|
|
567
|
+
const st = this.state(this.store.get(id) ?? agent);
|
|
568
|
+
if (st.hold?.key === key || st.merged === key) continue;
|
|
569
|
+
if (state === 'behind' && st.updated !== key) {
|
|
570
|
+
this.put(id, (x) => (x.updated = key));
|
|
571
|
+
await this.landing.updateBranch(id).catch((e) => this.hold(id, key, `Its branch is behind and could not be updated: ${e.message}`));
|
|
572
|
+
return;
|
|
573
|
+
}
|
|
574
|
+
if (state === 'draft') return this.hold(id, key, 'Its pull request is a draft.');
|
|
575
|
+
if (state !== 'ready') continue; // waiting for checks; failing ones go back to the agent through Landing
|
|
576
|
+
if (v.runtime?.busy) return;
|
|
577
|
+
// Reviewed in rounds: only what the critics approved is merged.
|
|
578
|
+
const pre = agent.preReview;
|
|
579
|
+
if (['reviewing', 'fixing'].includes(pre?.status)) return;
|
|
580
|
+
if (pre && pre.status !== 'approved') return this.hold(id, key, pre.status === 'stalled' ? `The review rounds did not approve its changes (${pre.round} ${pre.round === 1 ? 'round' : 'rounds'}).` : 'Its changes were not approved by the review rounds.');
|
|
581
|
+
if (this.manager.acceptanceWaits(agent)) return this.hold(id, key, 'What done means is not agreed yet.');
|
|
582
|
+
const own = v.results?.confidence;
|
|
583
|
+
if (own && own.percent < s.minBuildConfidence) return this.hold(id, key, `The agent's own confidence in this is ${own.percent}%${own.why ? `: ${own.why}` : ''}.`);
|
|
584
|
+
const changes = this.review ? await this.review.get(id) : null;
|
|
585
|
+
const risk = changes ? this.manager.standards?.riskIn(agent, changes.files ?? []) ?? [] : [];
|
|
586
|
+
if (risk.length) return this.hold(id, key, `It changes high-risk paths (${risk.slice(0, 3).map((r) => r.path).join(', ')}${risk.length > 3 ? ` and ${risk.length - 3} more` : ''}): yours to merge.`);
|
|
587
|
+
const card = this.store.get(id)?.docs?.scorecard;
|
|
588
|
+
if (card?.pending) return;
|
|
589
|
+
if (!card?.data || (changes?.diffHash && card.diffHash !== changes.diffHash)) {
|
|
590
|
+
if (st.scored === key) return this.hold(id, key, card?.error ? `Couldn't score the changes: ${card.error}` : "Couldn't score the changes.");
|
|
591
|
+
this.put(id, (x) => (x.scored = key));
|
|
592
|
+
await this.manager.summarize(id, 'scorecard').catch(() => {});
|
|
593
|
+
return this.schedule();
|
|
594
|
+
}
|
|
595
|
+
const sc = card.data;
|
|
596
|
+
if (sc.recommendation !== 'ready') return this.hold(id, key, `The review scorecard says ${sc.recommendation === 'look' ? 'to look first' : 'it is not ready'} (${sc.overall ?? '?'}/100)${sc.reasons?.length ? `: ${sc.reasons.join('; ')}` : ''}.`);
|
|
597
|
+
this.put(id, (x) => (x.merged = key));
|
|
598
|
+
try {
|
|
599
|
+
await this.landing.merge(id, { url: pr.url });
|
|
600
|
+
} catch (e) {
|
|
601
|
+
this.put(id, (x) => (x.merged = null));
|
|
602
|
+
return this.hold(id, key, `The merge failed: ${e.message}`);
|
|
603
|
+
}
|
|
604
|
+
this.record(id, { kind: 'merge', title: `Merged ${pr.url}`, text: `Checks passed, the scorecard said ready (${sc.overall ?? '?'}/100)${own ? `, its own confidence ${own.percent}%` : ''}.`, url: pr.url });
|
|
605
|
+
this.log(`autonomy: merged ${pr.url}`);
|
|
606
|
+
return;
|
|
607
|
+
}
|
|
608
|
+
}
|
|
609
|
+
|
|
610
|
+
// ---------------------------------------------------------------- inbox
|
|
611
|
+
|
|
612
|
+
/** What was decided for the person and they have not seen: answers given, a merge held. */
|
|
613
|
+
inbox() {
|
|
614
|
+
const items = [];
|
|
615
|
+
for (const agent of this.store.list()) {
|
|
616
|
+
const st = agent.autonomy;
|
|
617
|
+
if (!st) continue;
|
|
618
|
+
const base = { kind: 'auto', agentId: agent.id, agentName: agent.name, priority: agent.priority ?? 2 };
|
|
619
|
+
for (const e of st.log ?? []) if (e.kind === 'answer' && !e.ack) items.push({ ...base, key: `auto:${agent.id}:${e.id}`, title: `Answered for you: ${e.question}`, entry: e, at: e.at });
|
|
620
|
+
if (st.hold && !st.hold.ack && levelOf(agent) === 'merge') items.push({ ...base, key: `auto:${agent.id}:hold`, title: `Not merged: ${st.hold.note}`, entry: { id: 'hold', kind: 'hold', ...st.hold }, at: st.hold.at });
|
|
621
|
+
}
|
|
622
|
+
return items;
|
|
623
|
+
}
|
|
624
|
+
}
|
package/src/autopilot.js
CHANGED
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
// and stops early once a round no longer raises the score. Anything else ("look at these first"
|
|
11
11
|
// without a target, a failed step, a closed pull request) waits for you in the inbox, with Ship it to
|
|
12
12
|
// go ahead anyway. An item whose pull request merges is done.
|
|
13
|
+
import { autonomySettings } from './autonomy.js';
|
|
13
14
|
import { landState } from './tracker.js';
|
|
14
15
|
|
|
15
16
|
export const AUTOPILOT_LEVELS = ['off', 'pr', 'merge'];
|
|
@@ -90,7 +91,8 @@ export class Autopilot {
|
|
|
90
91
|
this.backlog.accept(it.id);
|
|
91
92
|
return;
|
|
92
93
|
}
|
|
93
|
-
|
|
94
|
+
// Its own autonomy level when that says "pr" or "merge" (autonomy.js), else its project's.
|
|
95
|
+
const level = ['pr', 'merge'].includes(it.autonomy) ? it.autonomy : this.backlog.autopilotFor(it.projectKey);
|
|
94
96
|
if (level === 'off' && !ap.ship) return;
|
|
95
97
|
if (ap.state === 'held' && ap.round === it.reviewAt) return;
|
|
96
98
|
if (this.manager.view(agent).runtime.busy) return;
|
|
@@ -167,6 +169,10 @@ export class Autopilot {
|
|
|
167
169
|
async land(it, agent, pr) {
|
|
168
170
|
const state = landState(pr);
|
|
169
171
|
if (state === 'ready') {
|
|
172
|
+
// The agent's own confidence in what it built (its brief): a low one is yours to merge.
|
|
173
|
+
const own = this.manager.view(agent).results?.confidence;
|
|
174
|
+
const min = autonomySettings(this.config).minBuildConfidence;
|
|
175
|
+
if (own && own.percent < min) return this.hold(it, `The agent's own confidence in this is ${own.percent}%${own.why ? `: ${own.why}` : ''}. Its pull request is open; merging it is yours.`);
|
|
170
176
|
this.note(it, { state: 'merging' });
|
|
171
177
|
await this.landing.merge(agent.id, { url: pr.url });
|
|
172
178
|
this.log(`autopilot: merged ${pr.url}`);
|