ai-agentmanager 1.61.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 +30 -0
- package/README.md +124 -0
- package/package.json +1 -1
- package/public/acceptance.js +194 -0
- package/public/announce.js +9 -1
- package/public/app.js +82 -10
- package/public/attach.js +4 -0
- package/public/autonomy.js +140 -0
- package/public/boardcols.js +1 -0
- package/public/claims.js +65 -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 +64 -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/claims.js +239 -0
- package/src/cli.js +164 -2
- 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 +257 -6
- package/src/notify.js +16 -0
- package/src/prereview.js +7 -2
- package/src/scorecard.js +27 -10
- package/src/server.js +67 -4
- package/src/standup.js +1 -0
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
// Ground rules: the person's own rules for every agent, in every repository and on every engine,
|
|
2
|
+
// given with each session's instructions next to (not instead of) the repository's memory and
|
|
3
|
+
// standards. Memory is what agents learned; standards are per repository; these are how this
|
|
4
|
+
// person wants agents to work anywhere ("ask before adding a dependency", "never force-push").
|
|
5
|
+
// One Markdown file, ~/.agentmanager/ground-rules.md, one rule per line. Only the person sets
|
|
6
|
+
// them: an agent's own calls to change them are refused (server.js).
|
|
7
|
+
import fs from 'node:fs';
|
|
8
|
+
import path from 'node:path';
|
|
9
|
+
import { paths } from './config.js';
|
|
10
|
+
|
|
11
|
+
export const MAX_RULES = 40;
|
|
12
|
+
export const MAX_RULE_CHARS = 400;
|
|
13
|
+
const err = (status, message) => Object.assign(new Error(message), { status });
|
|
14
|
+
|
|
15
|
+
export const groundRulesFile = () => path.join(paths.home, 'ground-rules.md');
|
|
16
|
+
|
|
17
|
+
/** The rules in a text: one per line, list marks and numbers dropped, no empty lines, no repeats. */
|
|
18
|
+
export function parseRules(text) {
|
|
19
|
+
const out = [];
|
|
20
|
+
const seen = new Set();
|
|
21
|
+
for (const raw of String(text ?? '').split('\n')) {
|
|
22
|
+
const line = raw.replace(/\s+/g, ' ').replace(/^\s*(?:[-*+]|\d+[.)])\s+/, '').trim();
|
|
23
|
+
if (!line || /^#/.test(line) || seen.has(line.toLowerCase())) continue;
|
|
24
|
+
seen.add(line.toLowerCase());
|
|
25
|
+
out.push(line);
|
|
26
|
+
}
|
|
27
|
+
return out;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** The rules the person sent, checked: a text or a list. Throws with a status when one is too long or there are too many. */
|
|
31
|
+
export function cleanRules(input) {
|
|
32
|
+
const rules = parseRules(Array.isArray(input) ? input.join('\n') : input);
|
|
33
|
+
const long = rules.find((r) => r.length > MAX_RULE_CHARS);
|
|
34
|
+
if (long) throw err(400, `A ground rule is one short line (${MAX_RULE_CHARS} characters at most): "${long.slice(0, 60)}…"`);
|
|
35
|
+
if (rules.length > MAX_RULES) throw err(400, `At most ${MAX_RULES} ground rules: a long list is not followed, keep the ones that matter`);
|
|
36
|
+
return rules;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** What every session is told, or '' when there are none. */
|
|
40
|
+
export function groundRulesPrompt(rules) {
|
|
41
|
+
if (!rules?.length) return '';
|
|
42
|
+
return [
|
|
43
|
+
'Ground rules from the user, for everything you do in this session. They come before your own preferences and before what the repository\'s memory suggests. ' +
|
|
44
|
+
'If the task cannot be done without breaking one, stop and say which and why (in the brief, or as a question) instead of working around it:',
|
|
45
|
+
...rules.map((r) => `- ${r}`),
|
|
46
|
+
].join('\n');
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** For a session that is already running when the rules change. */
|
|
50
|
+
export const groundRulesMessage = (rules) =>
|
|
51
|
+
rules.length
|
|
52
|
+
? `The user changed their ground rules. From now on, these apply to everything you do in this session (they replace any ground rules you were given before):\n${rules.map((r) => `- ${r}`).join('\n')}`
|
|
53
|
+
: 'The user removed their ground rules: the ones you were given at the start no longer apply.';
|
|
54
|
+
|
|
55
|
+
export class GroundRules {
|
|
56
|
+
constructor({ file = groundRulesFile() } = {}) {
|
|
57
|
+
this.file = file;
|
|
58
|
+
this.cache = null; // { mtimeMs, rules }
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** The rules now (read again when the file changed: it can be edited by hand). */
|
|
62
|
+
list() {
|
|
63
|
+
try {
|
|
64
|
+
const { mtimeMs } = fs.statSync(this.file);
|
|
65
|
+
if (this.cache?.mtimeMs !== mtimeMs) this.cache = { mtimeMs, rules: parseRules(fs.readFileSync(this.file, 'utf8')).slice(0, MAX_RULES) };
|
|
66
|
+
return this.cache.rules;
|
|
67
|
+
} catch {
|
|
68
|
+
this.cache = null;
|
|
69
|
+
return [];
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
view() {
|
|
74
|
+
const rules = this.list();
|
|
75
|
+
let updatedAt = null;
|
|
76
|
+
try {
|
|
77
|
+
updatedAt = fs.statSync(this.file).mtime.toISOString();
|
|
78
|
+
} catch {}
|
|
79
|
+
return { rules, text: rules.join('\n'), file: this.file, max: MAX_RULES, maxChars: MAX_RULE_CHARS, updatedAt };
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/** Replace the rules. Returns { changed, ...view }. */
|
|
83
|
+
set(input) {
|
|
84
|
+
const rules = cleanRules(input);
|
|
85
|
+
const changed = JSON.stringify(rules) !== JSON.stringify(this.list());
|
|
86
|
+
if (changed) {
|
|
87
|
+
fs.mkdirSync(path.dirname(this.file), { recursive: true });
|
|
88
|
+
fs.writeFileSync(this.file, rules.length ? `${rules.map((r) => `- ${r}`).join('\n')}\n` : '');
|
|
89
|
+
this.cache = null;
|
|
90
|
+
}
|
|
91
|
+
return { changed, ...this.view() };
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
prompt() {
|
|
95
|
+
return groundRulesPrompt(this.list());
|
|
96
|
+
}
|
|
97
|
+
}
|
package/src/judge.js
CHANGED
|
@@ -259,7 +259,7 @@ export class Judge {
|
|
|
259
259
|
const u = this.usage();
|
|
260
260
|
if (u.calls >= u.cap) return null;
|
|
261
261
|
this.state.calls++;
|
|
262
|
-
const data = parseJsonReply(await this.call(agent, prompt, { timeoutMs: this.settings.timeoutSec * 1000 }));
|
|
262
|
+
const data = parseJsonReply(await this.call(agent, prompt, { timeoutMs: this.settings.timeoutSec * 1000, kind: key.split(':')[0] }));
|
|
263
263
|
if (!validate(data)) throw new Error('reply did not have the expected shape');
|
|
264
264
|
data.confidence = Math.max(0, Math.min(1, Number(data.confidence) || 0));
|
|
265
265
|
return data;
|
package/src/manager.js
CHANGED
|
@@ -68,6 +68,7 @@ const SUMMARIES = {
|
|
|
68
68
|
walkthrough: { doc: 'walkthrough', run: 'runWalkthrough' },
|
|
69
69
|
scorecard: { doc: 'scorecard', run: 'runScorecard' },
|
|
70
70
|
update: { doc: 'update', run: 'runUpdate' },
|
|
71
|
+
claims: { doc: 'claims', run: 'runClaims' },
|
|
71
72
|
};
|
|
72
73
|
/** Read / write where a summary of `kind` is kept on the agent record. */
|
|
73
74
|
const getSummary = (agent, kind) => (SUMMARIES[kind].doc ? agent.docs?.[kind] : agent[SUMMARIES[kind].field]);
|
|
@@ -129,10 +130,14 @@ import { preReviewPrompt } from './prereview.js';
|
|
|
129
130
|
import { reviewPath, reviewerPrompt } from './reviews.js';
|
|
130
131
|
import { findingsPath, fixPath, fixerPrompt, hunterPrompt } from './bughunt.js';
|
|
131
132
|
import { reminderFor, reminderSettings } from './reminders.js';
|
|
132
|
-
import { combine, facts as scoreFacts, improveMessage, scorecardMarkdown, scorecardPrompt } from './scorecard.js';
|
|
133
|
+
import { combine, factLines, facts as scoreFacts, improveMessage, scorecardMarkdown, scorecardPrompt } from './scorecard.js';
|
|
134
|
+
import { acceptanceAgreedPrompt, acceptancePrompt, agreedMessage, cleanPoints, counts as acceptanceCounts, parseCriteria, results as acceptanceResults, SKIPPED_MESSAGE } from './acceptance.js';
|
|
135
|
+
import { CLAIM_TEXTS, claimsMarkdown, claimsPrompt, combineClaims, parseClaims, totals as claimTotals } from './claims.js';
|
|
133
136
|
import { CONTAINER_ENGINES, claudeToken, containerName, containerRunning, engineMounts, gitCommonDir, removeContainer, runArgs, stopContainer } from './container.js';
|
|
134
137
|
import { conflictMessage, findConflicts, related, repoKey, summarize as summarizeConflicts } from './conflicts.js';
|
|
135
138
|
import { answerMessage, loadQuestions, questionsPath, questionsPrompt } from './inbox.js';
|
|
139
|
+
import { GroundRules, groundRulesMessage } from './groundrules.js';
|
|
140
|
+
import { autonomySettings, callLadder, eligible as autonomyEligible, levelOf, modelName, parseLevel } from './autonomy.js';
|
|
136
141
|
import { STUCK_DEFAULTS, detectStuck } from './stuck.js';
|
|
137
142
|
import { Judge, clashPrompt, finishMessage, hash, reviewPrompt, screenPrompt, stripChrome, stuckPrompt } from './judge.js';
|
|
138
143
|
import { findLocalUrls, findSignInLinks, parseCallback, parseUrl } from './preview.js';
|
|
@@ -323,7 +328,16 @@ export class AgentManager extends EventEmitter {
|
|
|
323
328
|
// The AI judge: rules decide when to look, a model decides what is going on (see judge.js).
|
|
324
329
|
this.rules = new Rules({ suggestAfter: config.rules?.suggestAfter, readOnly: config.rules?.readOnly });
|
|
325
330
|
this.inboxSources = [];
|
|
326
|
-
this.
|
|
331
|
+
this.groundRules = new GroundRules(); // the person's own rules for every session (groundrules.js)
|
|
332
|
+
// For an agent that runs without the person (autonomy.js), what is decided in their place (is it
|
|
333
|
+
// stuck and what nudge, what to answer or approve) is judged on the autonomy models, best first:
|
|
334
|
+
// what comes out is acted on without anyone reading it first.
|
|
335
|
+
this.judge = new Judge({
|
|
336
|
+
config,
|
|
337
|
+
call: (agent, prompt, { timeoutMs, kind }) =>
|
|
338
|
+
['stuck', 'advise'].includes(kind) && agent && levelOf(agent) !== 'ask' ? this.ladderShot(agent, prompt, { timeoutMs }).then((r) => r.text) : this.oneShot(agent, prompt, { ...this.judgeModel(agent), timeoutMs }),
|
|
339
|
+
});
|
|
340
|
+
this.modelsDown = new Map(); // model name -> when a call on it last failed (autonomy's list of models)
|
|
327
341
|
this.stuckVerdicts = new Map(); // agent id -> Map(finding key -> { at, since, data })
|
|
328
342
|
this.signIns = new Map(); // agent id -> { url, port, callback, terminal, at, finished } from a CLI's sign-in link
|
|
329
343
|
this.seenLinks = new Map(); // agent id -> Set of sign-in links already raised
|
|
@@ -468,7 +482,7 @@ export class AgentManager extends EventEmitter {
|
|
|
468
482
|
else if (agent.brief?.status || rt?.pty || agent.status === 'preparing') outcome = 'in progress';
|
|
469
483
|
}
|
|
470
484
|
if (!outcome && !delivered.length && !blockers.length) return null;
|
|
471
|
-
return { outcome: outcome ?? 'in progress', delivered, blockers, notes: r?.notes ?? '', fromAgent: Boolean(r) };
|
|
485
|
+
return { outcome: outcome ?? 'in progress', delivered, blockers, notes: r?.notes ?? '', confidence: r?.confidence ?? null, fromAgent: Boolean(r) };
|
|
472
486
|
}
|
|
473
487
|
|
|
474
488
|
changed(agent) {
|
|
@@ -634,6 +648,8 @@ export class AgentManager extends EventEmitter {
|
|
|
634
648
|
start = true,
|
|
635
649
|
plan = false,
|
|
636
650
|
planReview,
|
|
651
|
+
acceptance,
|
|
652
|
+
autonomy,
|
|
637
653
|
designDoc,
|
|
638
654
|
demoPage,
|
|
639
655
|
benchmarks,
|
|
@@ -700,6 +716,11 @@ export class AgentManager extends EventEmitter {
|
|
|
700
716
|
// Attached files (a screenshot, a log) go in the agent's own uploads folder, listed in its request.
|
|
701
717
|
if (staged.length) intent = [intent, attachmentNote(copyAttachments(staged, id))].filter(Boolean).join('\n\n');
|
|
702
718
|
|
|
719
|
+
// How far it goes without you (autonomy.js): "ask" (as before) unless a level is named or set as the default.
|
|
720
|
+
const plainTask = !general && !team && !builds && !reviewing && !hunting && !fixing && !race;
|
|
721
|
+
const asked = autonomy === undefined || autonomy === null || autonomy === '' ? null : parseLevel(autonomy);
|
|
722
|
+
if (autonomy && !asked) throw Object.assign(new Error('autonomy is one of ask, run, pr, merge'), { status: 400 });
|
|
723
|
+
const level = plainTask ? asked ?? autonomySettings(this.config).level : 'ask';
|
|
703
724
|
const agent = {
|
|
704
725
|
id,
|
|
705
726
|
kind: general ? kind : 'task',
|
|
@@ -734,6 +755,10 @@ export class AgentManager extends EventEmitter {
|
|
|
734
755
|
// Review the implementation plan before the agent implements it: null = no review.
|
|
735
756
|
// Team members get their review from the team instead.
|
|
736
757
|
planReview: !general && !team && !builds && !reviewing && !hunting && (planReview ?? this.config.planReview ?? false) ? { status: 'writing' } : null,
|
|
758
|
+
// Agree on what done means first (acceptance.js): the agent drafts the points and waits. null = not asked.
|
|
759
|
+
acceptance: !general && !team && !builds && !reviewing && !hunting && (acceptance ?? (level !== 'ask' ? true : this.config.acceptance) ?? false) ? { status: 'writing', wait: true, points: [] } : null,
|
|
760
|
+
// Runs without you past that point: { level, log, seen } (autonomy.js). null = asks, as before.
|
|
761
|
+
autonomy: level !== 'ask' ? { level, log: [], seen: {} } : null,
|
|
737
762
|
// Write and publish a design doc (Google Doc + Artifact) after the plan, updated at the end.
|
|
738
763
|
designDoc: !general && !team && !builds && !reviewing && !hunting && Boolean(designDoc ?? this.config.designDoc ?? true),
|
|
739
764
|
demoPage: !general && !team && !builds && !reviewing && !hunting && Boolean(demoPage ?? this.config.demoPage ?? false),
|
|
@@ -1377,7 +1402,15 @@ export class AgentManager extends EventEmitter {
|
|
|
1377
1402
|
fs.mkdirSync(briefDir(agent.id), { recursive: true });
|
|
1378
1403
|
const dir = fs.realpathSync(briefDir(agent.id));
|
|
1379
1404
|
writableDir ??= dir;
|
|
1380
|
-
prompts.push(specPrompt(path.join(dir, path.basename(specPath(agent.id))), path.join(dir, path.basename(planPath(agent.id))), { withPlan: !agent.planReview }));
|
|
1405
|
+
prompts.push(specPrompt(path.join(dir, path.basename(specPath(agent.id))), path.join(dir, path.basename(planPath(agent.id))), { withPlan: !agent.planReview, wait: this.acceptanceWaits(agent) }));
|
|
1406
|
+
}
|
|
1407
|
+
// What done means: drafted and waiting for the person, or agreed (then the points are the app's, as written).
|
|
1408
|
+
if (agent.acceptance && task) {
|
|
1409
|
+
fs.mkdirSync(briefDir(agent.id), { recursive: true });
|
|
1410
|
+
const file = path.join(fs.realpathSync(briefDir(agent.id)), path.basename(specPath(agent.id)));
|
|
1411
|
+
writableDir ??= path.dirname(file);
|
|
1412
|
+
if (agent.acceptance.status === 'agreed') prompts.push(acceptanceAgreedPrompt(agent.acceptance.points));
|
|
1413
|
+
else if (this.acceptanceWaits(agent)) prompts.push(acceptancePrompt(file, { planReview: Boolean(agent.planReview) && agent.planReview.status !== 'approved' }));
|
|
1381
1414
|
}
|
|
1382
1415
|
// Its changes are reviewed in rounds before a pull request (prereview.js): it leaves opening one to that.
|
|
1383
1416
|
if (withBrief && !planning && this.preReview?.instructs(agent)) prompts.push(preReviewPrompt());
|
|
@@ -1437,6 +1470,9 @@ export class AgentManager extends EventEmitter {
|
|
|
1437
1470
|
// The repository's standards (standards.js): lessons to follow and the parts marked high risk.
|
|
1438
1471
|
const standards = task ? this.standards?.prompt(agent) : '';
|
|
1439
1472
|
if (standards) prompts.push(standards);
|
|
1473
|
+
// The person's own ground rules, for every session in every repository (groundrules.js).
|
|
1474
|
+
const ground = this.groundRules.prompt();
|
|
1475
|
+
if (ground) prompts.push(ground);
|
|
1440
1476
|
// Commands you chose to always allow in this repo.
|
|
1441
1477
|
const ruled = agent.workdir ? this.rules.allowed(memoryKey(agent)) : [];
|
|
1442
1478
|
if (ruled.length) allowedTools = [...(allowedTools ?? []), ...ruled];
|
|
@@ -1929,6 +1965,14 @@ export class AgentManager extends EventEmitter {
|
|
|
1929
1965
|
allowed.model = String(fields.model ?? '').trim() || null;
|
|
1930
1966
|
if (engineOf(agent).checkModel) allowed.model = engineOf(agent).checkModel(allowed.model, this.config);
|
|
1931
1967
|
}
|
|
1968
|
+
// How far it goes without you (autonomy.js); what was done for you so far is kept.
|
|
1969
|
+
if ('autonomy' in fields) {
|
|
1970
|
+
const level = parseLevel(fields.autonomy);
|
|
1971
|
+
if (!level) throw bad('autonomy is one of ask, run, pr, merge');
|
|
1972
|
+
if (level !== 'ask' && !autonomyEligible(agent)) throw bad('Only a task agent with changes of its own can run without you');
|
|
1973
|
+
const cur = agent.autonomy;
|
|
1974
|
+
if (level !== levelOf(agent)) allowed.autonomy = level === 'ask' && !cur?.log?.length ? null : { log: [], seen: {}, ...cur, level, hold: null };
|
|
1975
|
+
}
|
|
1932
1976
|
// Keep: clean up never closes or deletes it.
|
|
1933
1977
|
if ('keep' in fields) allowed.keep = Boolean(fields.keep);
|
|
1934
1978
|
if ('budgetUsd' in fields) {
|
|
@@ -2506,7 +2550,21 @@ export class AgentManager extends EventEmitter {
|
|
|
2506
2550
|
if (finished && !rounds && !NO_REPO.has(agent.kind) && this.changesSource) this.standards?.finished(agent).catch((e) => this.log?.(`standards: ${e.message}`));
|
|
2507
2551
|
if (finished && this.judge.enabled && !rounds) this.requestReview(id, { trigger: 'brief' }).catch(() => {});
|
|
2508
2552
|
// ...and score it for the reviewer ("scorecard": { "auto": false } in config.json turns this off).
|
|
2509
|
-
|
|
2553
|
+
// The points were agreed (or changed) after the last score: the brief saying done again is checked against them.
|
|
2554
|
+
const reagreed = brief.status === 'done' && agent.acceptance?.status === 'agreed' && agent.docs?.scorecard?.data && agent.docs.scorecard.acceptanceAt !== agent.acceptance.agreedAt;
|
|
2555
|
+
if ((improved || reagreed || (finished && this.config.scorecard?.auto !== false && !rounds)) && !NO_REPO.has(agent.kind) && this.changesSource) this.summarize(id, 'scorecard').catch(() => {});
|
|
2556
|
+
}
|
|
2557
|
+
// Its points for what done means, written or revised in the spec: they wait for the person.
|
|
2558
|
+
if (this.acceptanceWaits(agent)) {
|
|
2559
|
+
let at = null;
|
|
2560
|
+
try {
|
|
2561
|
+
at = fs.statSync(specPath(id)).mtime.toISOString();
|
|
2562
|
+
} catch {}
|
|
2563
|
+
if (at && at !== agent.acceptance.specAt) {
|
|
2564
|
+
const points = parseCriteria(readSpecDoc(id, 'spec')?.markdown);
|
|
2565
|
+
const cur = this.store.get(id).acceptance;
|
|
2566
|
+
this.patch(id, { acceptance: { ...cur, specAt: at, ...(points.length ? { status: 'review', points: points.map((text, i) => ({ id: `A${i + 1}`, text, from: 'agent' })), updatedAt: at } : {}) } });
|
|
2567
|
+
}
|
|
2510
2568
|
}
|
|
2511
2569
|
if (agent.planReview) {
|
|
2512
2570
|
const file = loadPlanFile(id, agent.planReview);
|
|
@@ -2558,6 +2616,97 @@ export class AgentManager extends EventEmitter {
|
|
|
2558
2616
|
return this.tell(agent.id, `Plan changes requested. Revise the plan file and wait for approval again:\n${note.trim()}`);
|
|
2559
2617
|
}
|
|
2560
2618
|
|
|
2619
|
+
// ------------------------------------------------------------ ground rules
|
|
2620
|
+
|
|
2621
|
+
/**
|
|
2622
|
+
* Replace the person's ground rules. Sessions started from now on get them with their
|
|
2623
|
+
* instructions; with `tell`, the ones running now are told too. Returns the rules and how many
|
|
2624
|
+
* sessions were told.
|
|
2625
|
+
*/
|
|
2626
|
+
setGroundRules(input, { tell = false } = {}) {
|
|
2627
|
+
const r = this.groundRules.set(input);
|
|
2628
|
+
let told = 0;
|
|
2629
|
+
if (tell && r.changed) {
|
|
2630
|
+
for (const [id, rt] of this.runtimes) {
|
|
2631
|
+
const agent = this.store.get(id);
|
|
2632
|
+
if (!rt.pty || !agent) continue;
|
|
2633
|
+
try {
|
|
2634
|
+
this.tell(id, groundRulesMessage(r.rules), { source: 'ground-rules' });
|
|
2635
|
+
told++;
|
|
2636
|
+
} catch {}
|
|
2637
|
+
}
|
|
2638
|
+
}
|
|
2639
|
+
return { ...r, told };
|
|
2640
|
+
}
|
|
2641
|
+
|
|
2642
|
+
// -------------------------------------------------------------- acceptance
|
|
2643
|
+
|
|
2644
|
+
/** Whether the agent is stopped until the person agrees on what done means. */
|
|
2645
|
+
acceptanceWaits(agent) {
|
|
2646
|
+
return Boolean(agent.acceptance?.wait) && ['writing', 'review'].includes(agent.acceptance.status);
|
|
2647
|
+
}
|
|
2648
|
+
|
|
2649
|
+
/**
|
|
2650
|
+
* What done means for an agent: the agreed points with what the last scorecard found for each,
|
|
2651
|
+
* or (not agreed) the points its spec has now. `stale`: agreed or changed since they were checked.
|
|
2652
|
+
*/
|
|
2653
|
+
acceptanceOf(ref) {
|
|
2654
|
+
const agent = this.mustGet(ref);
|
|
2655
|
+
const acc = agent.acceptance;
|
|
2656
|
+
const draft = acc?.status === 'agreed' ? [] : parseCriteria(readSpecDoc(agent.id, 'spec')?.markdown);
|
|
2657
|
+
if (acc?.status !== 'agreed') {
|
|
2658
|
+
const status = !acc ? 'none' : draft.length ? 'review' : 'writing';
|
|
2659
|
+
return { id: agent.id, name: agent.name, status, wait: this.acceptanceWaits(agent), draft, points: [], results: [], counts: acceptanceCounts([]), agreedAt: null, checkedAt: null, stale: false };
|
|
2660
|
+
}
|
|
2661
|
+
const sc = agent.docs?.scorecard;
|
|
2662
|
+
const current = Boolean(sc?.data) && sc.acceptanceAt === acc.agreedAt;
|
|
2663
|
+
const res = acceptanceResults(acc.points, current ? sc.data.criteria : null);
|
|
2664
|
+
return {
|
|
2665
|
+
id: agent.id,
|
|
2666
|
+
name: agent.name,
|
|
2667
|
+
status: 'agreed',
|
|
2668
|
+
wait: false,
|
|
2669
|
+
draft: [],
|
|
2670
|
+
points: acc.points,
|
|
2671
|
+
results: res,
|
|
2672
|
+
counts: acceptanceCounts(res),
|
|
2673
|
+
agreedAt: acc.agreedAt,
|
|
2674
|
+
checkedAt: current ? sc.at : null,
|
|
2675
|
+
// Checked against other points, or the brief moved on since: the result is not of the work as it is.
|
|
2676
|
+
stale: Boolean(sc?.data) && (!current || (sc.briefUpdatedAt ?? null) !== (agent.brief?.updatedAt ?? null)),
|
|
2677
|
+
scoring: Boolean(sc?.pending),
|
|
2678
|
+
};
|
|
2679
|
+
}
|
|
2680
|
+
|
|
2681
|
+
/**
|
|
2682
|
+
* Agree on the points (as the agent wrote them, or as the person edited them). From here they
|
|
2683
|
+
* are kept by the app; an agent that is running is told them, one that was waiting goes ahead.
|
|
2684
|
+
*/
|
|
2685
|
+
agreeAcceptance(ref, list) {
|
|
2686
|
+
const agent = this.mustGet(ref);
|
|
2687
|
+
if (NO_REPO.has(agent.kind)) throw Object.assign(new Error('Acceptance is for agents that work on a task'), { status: 400 });
|
|
2688
|
+
const prev = agent.acceptance;
|
|
2689
|
+
const draft = prev?.status === 'agreed' ? prev.points.filter((p) => p.from === 'agent').map((p) => p.text) : parseCriteria(readSpecDoc(agent.id, 'spec')?.markdown);
|
|
2690
|
+
const points = cleanPoints(list ?? draft, draft);
|
|
2691
|
+
const waiting = this.acceptanceWaits(agent);
|
|
2692
|
+
const changed = prev?.status === 'agreed';
|
|
2693
|
+
if (changed && prev.points.length === points.length && prev.points.every((p, i) => p.text === points[i].text)) return this.view(agent);
|
|
2694
|
+
this.patch(agent.id, { acceptance: { status: 'agreed', wait: false, points, agreedAt: now(), rounds: (prev?.rounds ?? 0) + 1, yours: points.filter((p) => p.from === 'you').length } });
|
|
2695
|
+
// A session at work hears now; one that isn't running reads them when it next starts (its work is scored against them either way).
|
|
2696
|
+
if (waiting || this.runtimes.get(agent.id)?.pty) return this.tell(agent.id, agreedMessage(points, { waiting, changed, planNext: Boolean(agent.planReview) && agent.planReview.status !== 'approved' }));
|
|
2697
|
+
// Already scored against other criteria: score it against these.
|
|
2698
|
+
if (agent.docs?.scorecard?.data && this.changesSource) this.summarize(agent.id, 'scorecard').catch(() => {});
|
|
2699
|
+
return this.view(this.store.get(agent.id));
|
|
2700
|
+
}
|
|
2701
|
+
|
|
2702
|
+
/** Stop waiting for the person: the agent goes ahead with the criteria in its own spec. */
|
|
2703
|
+
skipAcceptance(ref) {
|
|
2704
|
+
const agent = this.mustGet(ref);
|
|
2705
|
+
if (!this.acceptanceWaits(agent)) throw Object.assign(new Error('The agent is not waiting for the acceptance points'), { status: 409 });
|
|
2706
|
+
this.patch(agent.id, { acceptance: null });
|
|
2707
|
+
return this.tell(agent.id, SKIPPED_MESSAGE);
|
|
2708
|
+
}
|
|
2709
|
+
|
|
2561
2710
|
/** Turn plan review on (before the agent has implemented anything) or off (no longer waits). */
|
|
2562
2711
|
setPlanReview(ref, on) {
|
|
2563
2712
|
const agent = this.mustGet(ref);
|
|
@@ -2809,7 +2958,7 @@ export class AgentManager extends EventEmitter {
|
|
|
2809
2958
|
const doc = (n) => readSpecDoc(agent.id, n)?.markdown ?? '';
|
|
2810
2959
|
// The repository's standards: its bar is run here, by the app, before the model is asked.
|
|
2811
2960
|
const standards = (await this.standards?.assess(agent.id, data)) ?? null;
|
|
2812
|
-
const f = scoreFacts({ files: data.files, prs: Object.values(cur0.prs ?? {}), brief: cur0.brief, plan: doc('plan'), spec: doc('spec'), standards });
|
|
2961
|
+
const f = scoreFacts({ files: data.files, prs: Object.values(cur0.prs ?? {}), brief: cur0.brief, plan: doc('plan'), spec: doc('spec'), standards, agreed: cur0.acceptance?.status === 'agreed' ? cur0.acceptance.points : null });
|
|
2813
2962
|
const writer = this.writerFor(agent);
|
|
2814
2963
|
const prompt = scorecardPrompt({ ...ctx, briefMarkdown: this.briefFile(agent.id).markdown ?? '', intentDoc: doc('intent'), specDoc: doc('spec'), planDoc: doc('plan'), hunks, facts: f, lessons: standards?.lessons ?? [] });
|
|
2815
2964
|
const sc = combine(parseJsonReply(await this.oneShot(agent, prompt, writer)), f, hunks, { lessons: standards?.lessons ?? [], bar: standards?.bar ?? null });
|
|
@@ -2828,6 +2977,8 @@ export class AgentManager extends EventEmitter {
|
|
|
2828
2977
|
improvedFrom: cur.improving ? cur.improving.from : null,
|
|
2829
2978
|
at: now(),
|
|
2830
2979
|
briefUpdatedAt: cur.brief?.updatedAt ?? null,
|
|
2980
|
+
// The agreed points it was checked against (acceptance.js); null when none were agreed then.
|
|
2981
|
+
acceptanceAt: f.agreed ? cur0.acceptance.agreedAt : null,
|
|
2831
2982
|
pending: false,
|
|
2832
2983
|
error: null,
|
|
2833
2984
|
}),
|
|
@@ -2836,6 +2987,86 @@ export class AgentManager extends EventEmitter {
|
|
|
2836
2987
|
);
|
|
2837
2988
|
}
|
|
2838
2989
|
|
|
2990
|
+
/** The texts of an agent whose statements can be checked: its brief, and what was written about its work. */
|
|
2991
|
+
claimTexts(agent) {
|
|
2992
|
+
const brief = this.briefFile(agent.id).markdown ?? '';
|
|
2993
|
+
const u = agent.docs?.update;
|
|
2994
|
+
const of = {
|
|
2995
|
+
brief: { text: brief, at: agent.brief?.updatedAt ?? null },
|
|
2996
|
+
update: { text: u?.markdown ? [`Slack:\n${u.parts?.slack ?? ''}`, `Email: ${u.parts?.subject ?? ''}\n${u.parts?.email ?? ''}`, u.markdown].join('\n\n') : '', at: u?.at ?? null },
|
|
2997
|
+
explain: { text: agent.explanation?.markdown ?? '', at: agent.explanation?.at ?? null },
|
|
2998
|
+
insights: { text: agent.insights?.markdown ?? '', at: agent.insights?.at ?? null },
|
|
2999
|
+
};
|
|
3000
|
+
return Object.entries(CLAIM_TEXTS)
|
|
3001
|
+
.map(([key, label]) => ({ key, label, ...(of[key] ?? { text: agent.docs?.[key]?.markdown ?? '', at: agent.docs?.[key]?.at ?? null }) }))
|
|
3002
|
+
.filter((t) => t.text.trim());
|
|
3003
|
+
}
|
|
3004
|
+
|
|
3005
|
+
/**
|
|
3006
|
+
* The claims check (see claims.js): each statement of fact in the agent's brief and in what was
|
|
3007
|
+
* written about its work, traced to a source by another model than the writer, and the app
|
|
3008
|
+
* checking the model: the statement is in the text, the quote in the source, the particulars exist.
|
|
3009
|
+
*/
|
|
3010
|
+
async runClaims(agent, ctx) {
|
|
3011
|
+
const cur0 = this.store.get(agent.id) ?? agent;
|
|
3012
|
+
const texts = this.claimTexts(cur0);
|
|
3013
|
+
if (!texts.length) throw Object.assign(new Error('Nothing to check yet: no brief, update or explanation is written'), { status: 400 });
|
|
3014
|
+
const doc = (n) => readSpecDoc(agent.id, n)?.markdown ?? '';
|
|
3015
|
+
const cut = (s, max) => (s.length > max ? `${s.slice(0, max)}\n… (the rest was cut)` : s);
|
|
3016
|
+
const data = this.changesSource && !NO_REPO.has(agent.kind) && agent.workdir ? await this.changesSource(agent.id).catch(() => null) : null;
|
|
3017
|
+
const bar = cur0.standards?.bar?.results ?? [];
|
|
3018
|
+
const measured = [
|
|
3019
|
+
ctx.status,
|
|
3020
|
+
// Not the agent's own checks: those are its account, in its brief.
|
|
3021
|
+
data ? factLines(scoreFacts({ files: data.files, prs: Object.values(cur0.prs ?? {}), brief: null, plan: doc('plan'), spec: doc('spec'), standards: cur0.standards ?? null })).split('\n').filter((l) => !l.startsWith("the agent's own checks")).join('\n') : '',
|
|
3022
|
+
data?.files?.length ? `files changed:\n${data.files.map((f) => `${f.path} (+${f.added ?? 0} -${f.removed ?? 0})`).join('\n')}` : '',
|
|
3023
|
+
...bar.map((r) => `quality bar check "${r.name}": ${r.ok ? 'passed' : 'failed'}`),
|
|
3024
|
+
];
|
|
3025
|
+
const briefText = texts.find((t) => t.key === 'brief')?.text ?? '';
|
|
3026
|
+
const sources = [
|
|
3027
|
+
{ name: 'What the app measured', text: measured.filter(Boolean).join('\n') },
|
|
3028
|
+
{ name: 'The repository: commits and changed files', text: ctx.repo },
|
|
3029
|
+
{ name: 'The changes themselves (the diff)', text: cut(data?.diff ?? '', 60_000) },
|
|
3030
|
+
{ name: 'What was asked', text: [ctx.intent, doc('intent')].filter(Boolean).join('\n\n') },
|
|
3031
|
+
{ name: 'The conversation with the agent', text: cut(ctx.digest ?? '', 30_000), own: true },
|
|
3032
|
+
{ name: "The agent's spec and plan", text: cut([doc('spec'), doc('plan')].filter(Boolean).join('\n\n'), 20_000), own: true },
|
|
3033
|
+
{ name: "The agent's brief", text: cut(briefText, 20_000), own: true, brief: true },
|
|
3034
|
+
]
|
|
3035
|
+
.filter((s) => s.text?.trim())
|
|
3036
|
+
.map((s, i) => ({ ...s, id: `S${i + 1}`, own: Boolean(s.own) }));
|
|
3037
|
+
const checker = this.criticFor(this.writerFor(agent));
|
|
3038
|
+
const done = [];
|
|
3039
|
+
for (const t of texts) {
|
|
3040
|
+
// The brief is not a source for itself.
|
|
3041
|
+
const from = t.key === 'brief' ? sources.filter((s) => !s.brief) : sources;
|
|
3042
|
+
const text = cut(t.text, 20_000);
|
|
3043
|
+
try {
|
|
3044
|
+
const reply = parseClaims(await this.oneShot(agent, claimsPrompt({ label: t.label, text, sources: from }), { ...checker, timeoutMs: 300_000 }));
|
|
3045
|
+
done.push({ key: t.key, label: t.label, at: t.at, ...combineClaims(reply, { text, sources: from }) });
|
|
3046
|
+
} catch (e) {
|
|
3047
|
+
done.push({ key: t.key, label: t.label, at: t.at, error: e.message.slice(0, 200) });
|
|
3048
|
+
}
|
|
3049
|
+
}
|
|
3050
|
+
if (done.every((t) => t.error)) throw new Error(done[0].error);
|
|
3051
|
+
const result = { texts: done, ...claimTotals(done), sources: sources.map((s) => ({ id: s.id, name: s.name, own: s.own })) };
|
|
3052
|
+
const cur = this.store.get(agent.id);
|
|
3053
|
+
if (!cur) return null;
|
|
3054
|
+
return this.view(
|
|
3055
|
+
this.patch(
|
|
3056
|
+
agent.id,
|
|
3057
|
+
summaryPatch(cur, 'claims', {
|
|
3058
|
+
data: result,
|
|
3059
|
+
markdown: claimsMarkdown(result, cur.name),
|
|
3060
|
+
writer: `${checker.engine.label}${checker.model ? ` (${checker.model})` : ''}`,
|
|
3061
|
+
at: now(),
|
|
3062
|
+
briefUpdatedAt: cur.brief?.updatedAt ?? null,
|
|
3063
|
+
pending: false,
|
|
3064
|
+
error: null,
|
|
3065
|
+
}),
|
|
3066
|
+
),
|
|
3067
|
+
);
|
|
3068
|
+
}
|
|
3069
|
+
|
|
2839
3070
|
/**
|
|
2840
3071
|
* Improve before review: the agent gets its scorecard's low scores, unmet criteria and where a
|
|
2841
3072
|
* reviewer would look, and its changes are scored again when it next updates its brief as done.
|
|
@@ -3453,6 +3684,26 @@ export class AgentManager extends EventEmitter {
|
|
|
3453
3684
|
return this.writerFor(agent);
|
|
3454
3685
|
}
|
|
3455
3686
|
|
|
3687
|
+
/** The models autonomy's own calls run on, best first: config `autonomy.models` on Claude Code, else the summary writer. */
|
|
3688
|
+
ladderModels(agent) {
|
|
3689
|
+
const usable = (e) => e?.supports.oneShot && installed(e, this.config);
|
|
3690
|
+
const out = [];
|
|
3691
|
+
for (const m of autonomySettings(this.config).models) {
|
|
3692
|
+
const engine = ENGINES[typeof m === 'string' ? DEFAULT_ENGINE : m.engine ?? DEFAULT_ENGINE];
|
|
3693
|
+
if (usable(engine)) out.push({ engine, model: typeof m === 'string' ? m : m.model });
|
|
3694
|
+
}
|
|
3695
|
+
return out.length ? out : [this.writerFor(agent)];
|
|
3696
|
+
}
|
|
3697
|
+
|
|
3698
|
+
/**
|
|
3699
|
+
* One call for an agent that runs without the person: on the first of the models that answers.
|
|
3700
|
+
* Resolves to { text, by } (`by`: the model that answered); rejects when none did.
|
|
3701
|
+
*/
|
|
3702
|
+
async ladderShot(agent, prompt, { timeoutMs = 120_000 } = {}) {
|
|
3703
|
+
const r = await callLadder(this.ladderModels(agent), (m) => this.oneShot(agent, prompt, { ...m, timeoutMs }), { down: this.modelsDown, retryMs: autonomySettings(this.config).retryMin * 60_000 });
|
|
3704
|
+
return { text: r.text, by: modelName(r.model), tried: r.tried };
|
|
3705
|
+
}
|
|
3706
|
+
|
|
3456
3707
|
/** The end of the terminal screen as text: cursor moves become spaces or line breaks. */
|
|
3457
3708
|
screenText(rt) {
|
|
3458
3709
|
return rt.tail
|
package/src/notify.js
CHANGED
|
@@ -252,7 +252,23 @@ export class Notifier {
|
|
|
252
252
|
this.send('question', a, `asks: ${q.question}`);
|
|
253
253
|
}
|
|
254
254
|
}
|
|
255
|
+
for (const e of a.autonomy?.log ?? []) {
|
|
256
|
+
const k = `auto:${e.id}`;
|
|
257
|
+
// A question it stopped on, answered for you (autonomy.js); what Decide handled is alerted by Decide.
|
|
258
|
+
if (e.kind === 'answer' && e.via !== 'decide' && !e.ack && !s.sent.has(k)) {
|
|
259
|
+
s.sent.add(k);
|
|
260
|
+
this.send('decided', a, `asked: ${e.question} It was answered for you: ${e.answer}`);
|
|
261
|
+
}
|
|
262
|
+
}
|
|
255
263
|
// A plan waiting for review is an inbox decision too (same switch as questions).
|
|
264
|
+
// So are its points for what done means, when it waits for them to be agreed.
|
|
265
|
+
if (a.acceptance?.status === 'review' && a.acceptance.wait) {
|
|
266
|
+
const k = `acceptance:${a.acceptance.updatedAt}`;
|
|
267
|
+
if (!s.sent.has(k)) {
|
|
268
|
+
s.sent.add(k);
|
|
269
|
+
this.send('question', a, `wrote what done means (${a.acceptance.points.length} point${a.acceptance.points.length === 1 ? '' : 's'}); agree on it before it starts`);
|
|
270
|
+
}
|
|
271
|
+
}
|
|
256
272
|
if (a.planReview?.status === 'review') {
|
|
257
273
|
const k = `plan:${a.planReview.updatedAt}`;
|
|
258
274
|
if (!s.sent.has(k)) {
|
package/src/prereview.js
CHANGED
|
@@ -261,9 +261,14 @@ export class PreReview {
|
|
|
261
261
|
return Boolean(agent.kind === 'task' && agent.workdir && !agent.hunting && !agent.fixing && !agent.reviewing && !agent.team && !agent.builds && !agent.raceId && !this.skip(agent) && this.candidates(agent).length);
|
|
262
262
|
}
|
|
263
263
|
|
|
264
|
+
/** Is its pull request opened on approval? The setting, or its own autonomy level saying so (autonomy.js). */
|
|
265
|
+
opensPr(agent) {
|
|
266
|
+
return this.settings.openPr || ['pr', 'merge'].includes(agent?.autonomy?.level);
|
|
267
|
+
}
|
|
268
|
+
|
|
264
269
|
/** Told at launch that the pull request waits for the review? */
|
|
265
270
|
instructs(agent) {
|
|
266
|
-
return this.applies(agent) && this.
|
|
271
|
+
return this.applies(agent) && this.opensPr(agent) && !this.managed(agent.id);
|
|
267
272
|
}
|
|
268
273
|
|
|
269
274
|
/**
|
|
@@ -402,7 +407,7 @@ export class PreReview {
|
|
|
402
407
|
this.manager.patch(id, { preReview: state });
|
|
403
408
|
this.log(`review rounds: ${this.manager.store.get(id)?.name ?? id} ${state.status === 'approved' ? 'approved' : 'not approved'} in round ${state.round} of ${state.max}`);
|
|
404
409
|
await this.after(id);
|
|
405
|
-
if (state.status === 'approved' && this.
|
|
410
|
+
if (state.status === 'approved' && this.opensPr(this.manager.store.get(id)) && !state.forced && !this.managed(id)) await this.open(id).catch(() => {});
|
|
406
411
|
}
|
|
407
412
|
|
|
408
413
|
/** What waited for the rounds: the AI review, and the score (which goes in the pull request's description). */
|
package/src/scorecard.js
CHANGED
|
@@ -16,7 +16,7 @@ const WEIGHTS = { intent: 25, spec: 20, tests: 20, safety: 15, scope: 10, plan:
|
|
|
16
16
|
const TEST_FILE = /(^|\/)(tests?|__tests__|spec|specs)\/|[._-](test|spec)\.[a-z]+$|_test\.go$|Test\.java$/i;
|
|
17
17
|
|
|
18
18
|
/** Facts the app knows without a model: CI, test files touched, the agent's checks, plan and spec progress. */
|
|
19
|
-
export function facts({ files = [], prs = [], brief = null, plan = '', spec = '', standards = null }) {
|
|
19
|
+
export function facts({ files = [], prs = [], brief = null, plan = '', spec = '', standards = null, agreed = null }) {
|
|
20
20
|
const paths = files.map((f) => f.path);
|
|
21
21
|
const tests = paths.filter((p) => TEST_FILE.test(p));
|
|
22
22
|
const code = paths.filter((p) => !TEST_FILE.test(p) && !/\.(md|txt|rst|adoc)$/i.test(p) && !/(^|\/)docs?\//i.test(p));
|
|
@@ -37,19 +37,22 @@ export function facts({ files = [], prs = [], brief = null, plan = '', spec = ''
|
|
|
37
37
|
plan: steps.length ? { steps: steps.length, done: steps.filter((s) => s === 'x').length } : null,
|
|
38
38
|
criteria: criteriaBlock.split('\n').filter((l) => /^\s*[-*\d]/.test(l) && /\w/.test(l)).length,
|
|
39
39
|
hasSpec: Boolean(String(spec).trim()),
|
|
40
|
+
// What done means, agreed with the person (acceptance.js): these are checked, whatever the spec says now.
|
|
41
|
+
agreed: agreed?.length ? agreed.map((p) => ({ id: p.id, text: p.text })) : null,
|
|
40
42
|
// The repository's standards (standards.js): high-risk files touched, and the bar the app ran.
|
|
41
43
|
risk: (standards?.risk ?? []).map((r) => r.path),
|
|
42
44
|
bar: standards?.bar ? { passed: standards.bar.results.filter((r) => r.ok).length, failed: standards.bar.results.filter((r) => !r.ok).map((r) => r.name) } : null,
|
|
43
45
|
};
|
|
44
46
|
}
|
|
45
47
|
|
|
46
|
-
const factLines = (f) =>
|
|
48
|
+
export const factLines = (f) =>
|
|
47
49
|
[
|
|
48
50
|
`files changed: ${f.files} (+${f.added} -${f.removed}); code files: ${f.codeFiles}; test files: ${f.testFiles}`,
|
|
49
51
|
`CI on the pull request: ${f.ci ?? 'no pull request or no checks yet'}${f.ciFailed.length ? ` (failing: ${f.ciFailed.join(', ')})` : ''}`,
|
|
50
52
|
`the agent's own checks (from its brief): ${f.checks.passed} passed, ${f.checks.failed} failed, ${f.checks.pending} pending`,
|
|
51
53
|
`plan: ${f.plan ? `${f.plan.done} of ${f.plan.steps} steps ticked` : 'no plan written'}`,
|
|
52
54
|
`spec: ${f.hasSpec ? `${f.criteria} acceptance criteria` : 'no spec written'}`,
|
|
55
|
+
...(f.agreed ? [`acceptance agreed with the person: ${f.agreed.length} point${f.agreed.length === 1 ? '' : 's'}`] : []),
|
|
53
56
|
...(f.bar ? [`the repository's quality bar, run by the app: ${f.bar.passed} passed, ${f.bar.failed.length} failed${f.bar.failed.length ? ` (${f.bar.failed.join(', ')})` : ''}`] : []),
|
|
54
57
|
...(f.risk?.length ? [`files under paths the person marked high risk: ${f.risk.join(', ')}`] : []),
|
|
55
58
|
].join('\n');
|
|
@@ -62,7 +65,9 @@ export function scorecardPrompt({ intent, status, digest, briefMarkdown, intentD
|
|
|
62
65
|
'Reply with one JSON object only:',
|
|
63
66
|
'{"summary": "<two sentences: what the change does and how sure you are>",',
|
|
64
67
|
' "scores": {"intent": {"score": 0-100, "why": "<one sentence>"}, "scope": {...}, "plan": {...}, "tests": {...}, "safety": {...}},',
|
|
65
|
-
|
|
68
|
+
f.agreed
|
|
69
|
+
? ' "criteria": [{"id": "A1", "criterion": "<the point, as written>", "status": "met|not_met|unverified", "evidence": "<where: file, test, check>"}],'
|
|
70
|
+
: ' "criteria": [{"criterion": "<an acceptance criterion from the spec>", "status": "met|not_met|unverified", "evidence": "<where: file, test, check>"}],',
|
|
66
71
|
` "look": [{"id": "H3", "reason": "<why a person should read this hunk>"}]${lessons.length ? ',' : '}'}`,
|
|
67
72
|
...(lessons.length ? [' "lessons": [{"id": "L1", "status": "followed|broken|not_applicable", "evidence": "<where in the diff>"}]}'] : []),
|
|
68
73
|
'',
|
|
@@ -72,7 +77,9 @@ export function scorecardPrompt({ intent, status, digest, briefMarkdown, intentD
|
|
|
72
77
|
'- plan: how closely the change follows PLAN (steps done, departures explained). Without a plan, judge whether the work is coherent.',
|
|
73
78
|
'- tests: whether the changed behavior is verified: tests added or updated for it, CI, checks the agent ran. Code changes with no tests and no passing checks score low.',
|
|
74
79
|
'- safety: 100 when nothing risky is touched or risks are handled; lower for security, auth, data loss, migrations, concurrency, money, new dependencies or public API changes without care.',
|
|
75
|
-
|
|
80
|
+
f.agreed
|
|
81
|
+
? '- criteria: one entry per point in AGREED_ACCEPTANCE, with its id, in its order. The person agreed on these with the agent, so judge the work against them as written, not against the criteria in SPEC. "met" only when the diff, a test or a check shows it; "not_met" when the change does not do it or goes against it; otherwise "unverified".'
|
|
82
|
+
: '- criteria: one entry per acceptance criterion in SPEC, in its order; leave the list empty if there is no spec.',
|
|
76
83
|
'- look: at most 5 hunks a person must read (the risky, subtle or unverified ones), most important first. Not the obvious ones.',
|
|
77
84
|
...(lessons.length ? ['- lessons: one entry per lesson in LESSONS. "broken" only when the diff shows the change going against it; "not_applicable" when the change has nothing to do with it.'] : []),
|
|
78
85
|
'',
|
|
@@ -85,6 +92,7 @@ export function scorecardPrompt({ intent, status, digest, briefMarkdown, intentD
|
|
|
85
92
|
'<spec>',
|
|
86
93
|
specDoc || '(no spec written)',
|
|
87
94
|
'</spec>',
|
|
95
|
+
...(f.agreed ? ['<agreed_acceptance>', ...f.agreed.map((p) => `${p.id}: ${p.text}`), '</agreed_acceptance>'] : []),
|
|
88
96
|
'<plan>',
|
|
89
97
|
planDoc || '(no plan written)',
|
|
90
98
|
'</plan>',
|
|
@@ -105,6 +113,8 @@ export function scorecardPrompt({ intent, status, digest, briefMarkdown, intentD
|
|
|
105
113
|
}
|
|
106
114
|
|
|
107
115
|
const clamp = (n) => Math.max(0, Math.min(100, Math.round(Number(n) || 0)));
|
|
116
|
+
const plain = (s) => String(s ?? '').toLowerCase().replace(/[^\p{L}\p{N}]+/gu, ' ').trim();
|
|
117
|
+
const sameText = (a, b) => plain(a) === plain(b);
|
|
108
118
|
|
|
109
119
|
/**
|
|
110
120
|
* The scorecard from the model's reply and the facts: scores capped by what was measured, the spec
|
|
@@ -131,16 +141,23 @@ export function combine(reply, f, hunks, { lessons = [], bar = null } = {}) {
|
|
|
131
141
|
if (f.plan && out.plan) cap('plan', Math.round(40 + (60 * f.plan.done) / f.plan.steps), `${f.plan.done} of ${f.plan.steps} plan steps ticked`);
|
|
132
142
|
if (!f.plan && out.plan) out.plan.notes.push('no plan written');
|
|
133
143
|
// Spec: computed from the criteria (met 1, unverified ½, not met 0); none without a spec.
|
|
134
|
-
const
|
|
135
|
-
.filter((c) => c?.criterion)
|
|
144
|
+
const told = (Array.isArray(reply?.criteria) ? reply.criteria : [])
|
|
145
|
+
.filter((c) => c?.criterion || c?.id)
|
|
136
146
|
.slice(0, 20)
|
|
137
|
-
.map((c) => ({ criterion: String(c.criterion).slice(0, 300), status: ['met', 'not_met', 'unverified'].includes(c.status) ? c.status : 'unverified', evidence: String(c.evidence ?? '').slice(0, 300) }));
|
|
147
|
+
.map((c) => ({ id: String(c.id ?? '').trim().toUpperCase(), criterion: String(c.criterion ?? '').slice(0, 300), status: ['met', 'not_met', 'unverified'].includes(c.status) ? c.status : 'unverified', evidence: String(c.evidence ?? '').slice(0, 300) }));
|
|
148
|
+
// Points agreed with the person: exactly those, in their words; one the model skipped is unverified.
|
|
149
|
+
const criteria = f.agreed
|
|
150
|
+
? f.agreed.map((p) => {
|
|
151
|
+
const c = told.find((t) => t.id === p.id) ?? told.find((t) => !t.id && sameText(t.criterion, p.text));
|
|
152
|
+
return { id: p.id, criterion: p.text, status: c?.status ?? 'unverified', evidence: c?.evidence ?? '', agreed: true };
|
|
153
|
+
})
|
|
154
|
+
: told.filter((c) => c.criterion).map(({ id, ...c }) => c);
|
|
138
155
|
// A spec with criteria the model didn't assess: they count as unverified, not as passed.
|
|
139
|
-
if (f.hasSpec && f.criteria && !criteria.length) out.spec = { score: 50, why: `${f.criteria} acceptance criteri${f.criteria === 1 ? 'on' : 'a'} not assessed`, notes: ['treated as unverified'] };
|
|
140
|
-
if (f.hasSpec && criteria.length) {
|
|
156
|
+
if (!f.agreed && f.hasSpec && f.criteria && !criteria.length) out.spec = { score: 50, why: `${f.criteria} acceptance criteri${f.criteria === 1 ? 'on' : 'a'} not assessed`, notes: ['treated as unverified'] };
|
|
157
|
+
if ((f.hasSpec || f.agreed) && criteria.length) {
|
|
141
158
|
const pts = criteria.reduce((n, c) => n + (c.status === 'met' ? 1 : c.status === 'unverified' ? 0.5 : 0), 0);
|
|
142
159
|
const met = criteria.filter((c) => c.status === 'met').length;
|
|
143
|
-
out.spec = { score: clamp((100 * pts) / criteria.length), why: `${met} of ${criteria.length} acceptance criteri${criteria.length === 1 ? 'on' : 'a'} met${criteria.some((c) => c.status === 'not_met') ? ', some not met' : ''}`, notes: [] };
|
|
160
|
+
out.spec = { score: clamp((100 * pts) / criteria.length), why: `${met} of ${criteria.length} acceptance criteri${criteria.length === 1 ? 'on' : 'a'} met${criteria.some((c) => c.status === 'not_met') ? ', some not met' : ''}`, notes: f.agreed ? ['the points agreed with the person'] : [] };
|
|
144
161
|
}
|
|
145
162
|
// Overall: weighted over the scores there are.
|
|
146
163
|
const have = Object.entries(WEIGHTS).filter(([k]) => out[k]);
|