ai-agentmanager 1.62.0 → 1.64.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 +40 -0
- package/README.md +109 -0
- package/package.json +1 -1
- package/public/acceptance.js +194 -0
- package/public/app.js +84 -3
- package/public/attach.js +4 -0
- package/public/autonomy.js +144 -0
- package/public/boardcols.js +1 -0
- package/public/dropzone.js +203 -0
- package/public/groups.js +2 -0
- package/public/index.html +63 -0
- package/public/machine.js +2 -0
- package/public/menu.js +20 -0
- package/public/proof.js +114 -0
- package/public/scorecard.js +1 -1
- package/public/standup.js +1 -0
- package/public/style.css +61 -2
- package/src/acceptance.js +123 -0
- package/src/advisor.js +30 -8
- package/src/autonomy.js +684 -0
- package/src/autopilot.js +9 -1
- package/src/backlog.js +16 -3
- package/src/brief.js +24 -3
- package/src/bughunt.js +1 -0
- package/src/cli.js +171 -3
- package/src/config.js +5 -0
- package/src/decisions.js +5 -1
- package/src/engines/claude.js +4 -2
- package/src/groundrules.js +97 -0
- package/src/inbox.js +48 -0
- package/src/judge.js +1 -1
- package/src/manager.js +184 -7
- package/src/notify.js +16 -0
- package/src/prereview.js +7 -2
- package/src/proof.js +255 -0
- package/src/scorecard.js +40 -10
- package/src/server.js +66 -4
- package/src/service.js +24 -3
- package/src/standup.js +1 -0
package/public/scorecard.js
CHANGED
|
@@ -64,7 +64,7 @@ export function scorecardHtml(doc, esc, { stale = false, actions = '' } = {}) {
|
|
|
64
64
|
return `<div class="sc-row"><span class="sc-label">${label}</span><span class="sc-bar"><span class="${tone(d.score)}" style="width:${d.score}%"></span></span><span class="sc-n">${d.score}</span><span class="sc-why">${esc(d.why)}${d.notes.length ? ` <span class="sc-note">${esc(d.notes.join('; '))}</span>` : ''}</span></div>`;
|
|
65
65
|
}).join('');
|
|
66
66
|
const crit = sc.criteria.length
|
|
67
|
-
? `<details class="sc-crit" ${sc.criteria.some((c) => c.status !== 'met') ? 'open' : ''}><summary
|
|
67
|
+
? `<details class="sc-crit" ${sc.criteria.some((c) => c.status !== 'met') ? 'open' : ''}><summary>${sc.criteria.some((c) => c.agreed) ? 'What done means, as agreed' : 'Acceptance criteria'}: ${sc.criteria.filter((c) => c.status === 'met').length} of ${sc.criteria.length} met</summary><ul>${sc.criteria.map((c) => `<li class="${c.status}"><span class="sc-mark">${c.status === 'met' ? '✓' : c.status === 'not_met' ? '✗' : '?'}</span>${esc(c.criterion)}${c.evidence ? ` <span class="hint">${esc(c.evidence)}</span>` : ''}</li>`).join('')}</ul></details>`
|
|
68
68
|
: '';
|
|
69
69
|
const look = sc.look.length
|
|
70
70
|
? `<div class="sc-look"><b>Where to look</b><ol>${sc.look.map((l) => `<li><button type="button" class="link" data-sc-look="${esc(`${l.file}\t${l.head}`)}"><code>${esc(l.file)}</code></button> ${esc(l.reason)}</li>`).join('')}</ol></div>`
|
package/public/standup.js
CHANGED
|
@@ -165,6 +165,7 @@ export function initStandup({ api, $, esc, agents, needsFor, needCard, onNeed, t
|
|
|
165
165
|
}
|
|
166
166
|
if (need.kind === 'question') return { label: `answer “${t}”`, run: () => api('POST', `/agents/${a.id}/answer`, { question: need.q.id, text: t }) };
|
|
167
167
|
if (need.kind === 'waiting') return { label: `reply “${t}”`, run: () => api('POST', `/agents/${a.id}/waiting/answer`, { text: t }) };
|
|
168
|
+
if (need.kind === 'acceptance' && /\b(agree|agreed|approve|looks good|go ahead)\b/i.test(t)) return { label: 'agree on its points as written', run: () => api('POST', `/agents/${a.id}/acceptance/agree`, {}) };
|
|
168
169
|
if (need.kind === 'plan' && /\b(approve|looks good|go ahead|ship it)\b/i.test(t)) return { label: 'approve its plan', run: () => api('POST', `/agents/${a.id}/plan/approve`, {}) };
|
|
169
170
|
return { label: `tell it “${t}”`, run: () => api('POST', `/agents/${a.id}/tell`, { text: t }) };
|
|
170
171
|
}
|
package/public/style.css
CHANGED
|
@@ -444,7 +444,7 @@ body.term-max .term-agent, .term-wrap:fullscreen .term-agent { display: inline-b
|
|
|
444
444
|
.browser-frames { flex: 1; min-height: 0; position: relative; }
|
|
445
445
|
.browser-frame { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; background: #fff; }
|
|
446
446
|
/* Swipes scroll the terminal (handled in app.js), not the page. */
|
|
447
|
-
.terminal .xterm { touch-action: none; }
|
|
447
|
+
.terminal .xterm, .gterm .xterm { touch-action: none; }
|
|
448
448
|
.term-overlay {
|
|
449
449
|
position: absolute; inset: 36px 0 0; display: flex; flex-direction: column; align-items: center; justify-content: center;
|
|
450
450
|
gap: 8px; background: rgba(15, 17, 23, .78); color: #e5e8ef;
|
|
@@ -516,7 +516,7 @@ dialog::backdrop { background: rgba(0, 0, 0, .45); }
|
|
|
516
516
|
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
|
|
517
517
|
.row.three { grid-template-columns: 1fr 1fr 1fr; }
|
|
518
518
|
.team-gaps { max-height: 220px; overflow: auto; margin: 6px 0; font-size: 13px; }
|
|
519
|
-
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; }
|
|
519
|
+
.dialog-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; }
|
|
520
520
|
.error { color: var(--red); margin: 0; font-size: 13px; }
|
|
521
521
|
|
|
522
522
|
.update-dialog { width: min(520px, calc(100vw - 32px)); padding: 20px; }
|
|
@@ -676,6 +676,22 @@ pre.diff .meta { color: var(--muted); font-weight: 600; }
|
|
|
676
676
|
.doc-foot-actions { display: flex; gap: 8px; justify-content: flex-end; }
|
|
677
677
|
.plan-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin: 6px 0; }
|
|
678
678
|
.tag.plan-review { color: var(--accent); font-weight: 600; }
|
|
679
|
+
.tag.acc-review { color: var(--accent); font-weight: 600; }
|
|
680
|
+
.tag.acc-agreed { color: var(--green); }
|
|
681
|
+
.tag.acc-agreed.acc-bad { color: var(--red); font-weight: 600; }
|
|
682
|
+
.accept-dialog { width: min(620px, calc(100vw - 32px)); }
|
|
683
|
+
.acc-edit, .acc-list, .acc-need { margin: 8px 0; padding-left: 22px; }
|
|
684
|
+
.acc-need { font-size: 13px; }
|
|
685
|
+
.acc-edit li { margin: 6px 0; }
|
|
686
|
+
.acc-edit li::marker, .acc-list li::marker { color: var(--muted); }
|
|
687
|
+
.acc-edit textarea { width: calc(100% - 34px); vertical-align: top; font: inherit; font-size: 14px; padding: 6px 8px; resize: vertical; }
|
|
688
|
+
.acc-edit [data-acc-remove] { font-size: 18px; padding: 4px 8px; vertical-align: top; }
|
|
689
|
+
.acc-list li { margin: 8px 0; font-size: 13px; overflow-wrap: anywhere; }
|
|
690
|
+
.acc-chip.acc-met { border-color: var(--green); color: var(--green); }
|
|
691
|
+
.acc-chip.acc-not_met { border-color: var(--red); color: var(--red); font-weight: 600; }
|
|
692
|
+
.acc-chip.acc-unverified { border-color: var(--yellow); color: var(--yellow); }
|
|
693
|
+
.acc-evidence { margin-top: 2px; }
|
|
694
|
+
@media (max-width: 800px) { .acc-edit textarea { font-size: 16px; } }
|
|
679
695
|
.tag.plan-approved { color: #2f9e55; }
|
|
680
696
|
.tag.plan-changes { color: #c08a1e; }
|
|
681
697
|
.need-kind.plan { background: var(--accent); color: #fff; }
|
|
@@ -1904,3 +1920,46 @@ table.eval-items tr.eval-na td { color: var(--muted); }
|
|
|
1904
1920
|
.cl-quote { margin-top: 2px; }
|
|
1905
1921
|
.cl-note { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin: 6px 0; }
|
|
1906
1922
|
.cl-note.cl-doubt { border: 1px solid var(--yellow); border-radius: 8px; padding: 6px 10px; }
|
|
1923
|
+
|
|
1924
|
+
/* The agent's own confidence in what it built (Results). */
|
|
1925
|
+
.own-conf { margin: 6px 0; font-size: 13px; overflow-wrap: anywhere; }
|
|
1926
|
+
.own-conf .tag { font-weight: 600; margin-right: 4px; }
|
|
1927
|
+
|
|
1928
|
+
/* Without you (autonomy): the row in the brief card, the inbox card and the dialog. */
|
|
1929
|
+
.tag.auto-on { border-color: var(--accent, #4c8dff); color: var(--accent, #4c8dff); }
|
|
1930
|
+
.auto-answer { margin: 4px 0; font-size: 14px; overflow-wrap: anywhere; }
|
|
1931
|
+
.auto-hold { margin: 8px 0; font-size: 13px; }
|
|
1932
|
+
.auto-perm { margin: 4px 0 8px; }
|
|
1933
|
+
.auto-perm button { margin-left: 4px; }
|
|
1934
|
+
.not-done { margin: 6px 0; padding: 6px 10px; border-left: 3px solid var(--warn, #d9a441); font-size: 13px; overflow-wrap: anywhere; }
|
|
1935
|
+
.not-done ul { margin: 4px 0 0; padding-left: 18px; }
|
|
1936
|
+
.proof-row { margin: 6px 0; font-size: 13px; }
|
|
1937
|
+
.tag.proof-ok { color: var(--green); }
|
|
1938
|
+
.tag.proof-bad { color: var(--red); font-weight: 600; }
|
|
1939
|
+
.proof-list { list-style: none; margin: 8px 0; padding: 0; }
|
|
1940
|
+
.proof-list li { margin: 0 0 10px; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; font-size: 13px; overflow-wrap: anywhere; }
|
|
1941
|
+
.proof-title { font-weight: 600; margin-bottom: 4px; }
|
|
1942
|
+
.proof-cmd { display: inline-block; max-width: 100%; white-space: pre-wrap; overflow-wrap: anywhere; }
|
|
1943
|
+
.proof-out { margin: 6px 0 0; padding: 6px 8px; max-height: 180px; overflow: auto; font-size: 12px; white-space: pre-wrap; overflow-wrap: anywhere; background: var(--bg-2, rgba(127, 127, 127, 0.12)); border-radius: 6px; }
|
|
1944
|
+
.proof-out.bad { border: 1px solid var(--danger, #d9534f); }
|
|
1945
|
+
.auto-log { list-style: none; margin: 8px 0; padding: 0; }
|
|
1946
|
+
.auto-log li { margin: 0 0 10px; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; font-size: 13px; overflow-wrap: anywhere; }
|
|
1947
|
+
.auto-dialog select, #settings-autonomy select, #settings-autonomy input, #settings-ground textarea, #new-autonomy { width: 100%; font: inherit; font-size: 16px; }
|
|
1948
|
+
#settings-ground textarea { padding: 6px 8px; resize: vertical; }
|
|
1949
|
+
|
|
1950
|
+
/* Drop to start (dropzone.js): the box in the New agents form, and the frame over the page while dragging. */
|
|
1951
|
+
.drop-zone { display: flex; align-items: center; gap: 12px; margin: 0 0 10px; padding: 12px 14px; border: 2px dashed var(--border); border-radius: 12px; background: var(--panel-2); transition: border-color 0.12s, background 0.12s; }
|
|
1952
|
+
.drop-zone .drop-icon { font-size: 26px; line-height: 1; color: var(--muted); }
|
|
1953
|
+
.drop-zone .drop-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; font-size: 14px; }
|
|
1954
|
+
.drop-zone .hint { font-size: 12px; }
|
|
1955
|
+
.drop-zone .link { font-size: 12px; padding: 0; color: var(--accent); text-decoration: underline; }
|
|
1956
|
+
.drop-zone.over, form.dropping .drop-zone { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 10%, var(--panel-2)); }
|
|
1957
|
+
.drop-zone.over .drop-icon, form.dropping .drop-zone .drop-icon { color: var(--accent); }
|
|
1958
|
+
.drop-zone.filled { border-style: solid; border-color: var(--green); }
|
|
1959
|
+
.drop-added { font-size: 12px; color: var(--green); overflow-wrap: anywhere; }
|
|
1960
|
+
.drop-added:empty { display: none; }
|
|
1961
|
+
.drop-overlay { position: fixed; inset: 0; z-index: 1000; pointer-events: none; display: flex; padding: 16px; background: color-mix(in srgb, var(--accent) 14%, transparent); }
|
|
1962
|
+
.drop-overlay[hidden] { display: none; }
|
|
1963
|
+
.drop-frame { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; border: 3px dashed var(--accent); border-radius: 18px; background: color-mix(in srgb, var(--bg, #fff) 82%, transparent); text-align: center; padding: 20px; font-size: 15px; }
|
|
1964
|
+
.drop-frame b { font-size: 22px; }
|
|
1965
|
+
.drop-frame .drop-icon { font-size: 44px; color: var(--accent); }
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
// Acceptance: what "done" means for an agent's task, agreed with the person before the work is
|
|
2
|
+
// judged against it. The agent drafts a few checkable points in SPEC.md (it has read the code);
|
|
3
|
+
// the person edits them and agrees; from then on the points are kept by the app, not by the
|
|
4
|
+
// agent, and the review scorecard reports each one as met, not met or not verified.
|
|
5
|
+
//
|
|
6
|
+
// Everything here is pure: reading the points out of a spec, cleaning what the person sends,
|
|
7
|
+
// the messages to the agent, and matching the scorecard's answers back to the agreed points.
|
|
8
|
+
|
|
9
|
+
export const MAX_POINTS = 12;
|
|
10
|
+
export const MAX_POINT_CHARS = 300;
|
|
11
|
+
|
|
12
|
+
const tidy = (s) => String(s ?? '').replace(/\s+/g, ' ').trim();
|
|
13
|
+
const norm = (s) => tidy(s).toLowerCase().replace(/[^\p{L}\p{N} ]+/gu, '').replace(/\s+/g, ' ').trim();
|
|
14
|
+
|
|
15
|
+
/** The points under "## Acceptance criteria" in a spec: one per list item, wrapped lines joined. */
|
|
16
|
+
export function parseCriteria(spec) {
|
|
17
|
+
const block = /^##\s*Acceptance criteria\s*$([\s\S]*?)(?=^##\s|(?![\s\S]))/im.exec(String(spec ?? ''))?.[1] ?? '';
|
|
18
|
+
const out = [];
|
|
19
|
+
for (const line of block.split('\n')) {
|
|
20
|
+
const item = /^\s*(?:[-*+]|\d+[.)])\s+(?:\[[ xX~!]\]\s*)?(.*)$/.exec(line);
|
|
21
|
+
if (item) out.push(item[1]);
|
|
22
|
+
// A wrapped line of the item above (indented), not a new paragraph.
|
|
23
|
+
else if (out.length && /^\s+\S/.test(line)) out[out.length - 1] += ` ${line}`;
|
|
24
|
+
}
|
|
25
|
+
return out.map((t) => tidy(t).slice(0, MAX_POINT_CHARS)).filter((t) => /\p{L}|\p{N}/u.test(t)).slice(0, MAX_POINTS);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* The points the person sent (texts, or { text }), cleaned: no empty ones, no repeats, numbered
|
|
30
|
+
* A1.. in their order. `draft` is what the agent wrote: a point with its wording is "agent", any
|
|
31
|
+
* other is "you". Throws with a status when there is nothing to agree on, or too much.
|
|
32
|
+
*/
|
|
33
|
+
export function cleanPoints(list, draft = []) {
|
|
34
|
+
if (!Array.isArray(list)) throw Object.assign(new Error('points must be a list'), { status: 400 });
|
|
35
|
+
const drafted = new Set(draft.map(norm));
|
|
36
|
+
const seen = new Set();
|
|
37
|
+
const out = [];
|
|
38
|
+
for (const p of list) {
|
|
39
|
+
const text = tidy(typeof p === 'string' ? p : p?.text);
|
|
40
|
+
if (!text || seen.has(norm(text))) continue;
|
|
41
|
+
if (text.length > MAX_POINT_CHARS) throw Object.assign(new Error(`A point is at most ${MAX_POINT_CHARS} characters; split it`), { status: 400 });
|
|
42
|
+
seen.add(norm(text));
|
|
43
|
+
out.push({ id: `A${out.length + 1}`, text, from: drafted.has(norm(text)) ? 'agent' : 'you' });
|
|
44
|
+
}
|
|
45
|
+
if (!out.length) throw Object.assign(new Error('Give at least one point that says what done means'), { status: 400 });
|
|
46
|
+
if (out.length > MAX_POINTS) throw Object.assign(new Error(`At most ${MAX_POINTS} points: keep the ones you would check`), { status: 400 });
|
|
47
|
+
return out;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export const pointsBlock = (points) => points.map((p) => `${p.id}: ${p.text}`).join('\n');
|
|
51
|
+
|
|
52
|
+
/** The agent's instructions when the person agrees on the points before anything is changed. */
|
|
53
|
+
export const acceptancePrompt = (specFile, { planReview = false } = {}) =>
|
|
54
|
+
'The user agrees with you on what "done" means before you change anything. First investigate as much as you need ' +
|
|
55
|
+
`(reading code, docs and running read-only commands is fine), then write ${specFile} with three to six points under ` +
|
|
56
|
+
'"## Acceptance criteria": each one a single sentence a person can check without reading the code (a behavior they can see, ' +
|
|
57
|
+
'a command and its result, a test that passes), specific to this task, and none that only restates the request. ' +
|
|
58
|
+
'Then stop and wait. Until a message starting with "Acceptance agreed" or "Acceptance review skipped" arrives, do not edit, ' +
|
|
59
|
+
'create or delete files in the repository, commit, or run commands that change anything' +
|
|
60
|
+
(planReview ? ', and do not write your implementation plan yet: the plan comes after the points are agreed' : '') +
|
|
61
|
+
'. The agreed points may differ from yours: they are the ones the work is checked against.';
|
|
62
|
+
|
|
63
|
+
/** For a session started after the points were agreed (a restart, a resume). */
|
|
64
|
+
export const acceptanceAgreedPrompt = (points) =>
|
|
65
|
+
`The user agreed on what "done" means for this task. The work is checked against these points, as written:\n${pointsBlock(points)}\n` +
|
|
66
|
+
'Keep them under "## Acceptance criteria" in your spec as they are; you cannot change them. If one cannot be met, say so in the brief and why.';
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* What the agent is told when the points are agreed. `waiting`: it was stopped until now.
|
|
70
|
+
* `planNext`: its plan is reviewed too, and comes next. `changed`: they had been agreed before.
|
|
71
|
+
*/
|
|
72
|
+
export function agreedMessage(points, { waiting = false, planNext = false, changed = false } = {}) {
|
|
73
|
+
const head = waiting || !changed ? 'Acceptance agreed.' : 'Acceptance agreed again: the user changed the points.';
|
|
74
|
+
const next = waiting
|
|
75
|
+
? planNext
|
|
76
|
+
? 'Now write your implementation plan and wait for its approval, as instructed.'
|
|
77
|
+
: 'Go ahead with the work.'
|
|
78
|
+
: 'Check the work you have done against them and fix what does not meet them; say in the brief what you changed.';
|
|
79
|
+
return `${head} The work is done when all of these are true, and it is checked against them as written:\n${pointsBlock(points)}\n` +
|
|
80
|
+
`Replace the points under "## Acceptance criteria" in your spec with these, word for word. ${next}`;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export const SKIPPED_MESSAGE = 'Acceptance review skipped. Go ahead with the work, against the criteria in your own spec.';
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* The agreed points with what the scorecard found for each. `criteria` is the scorecard's list
|
|
87
|
+
* ({ id, criterion, status, evidence }); a point it has no answer for is "unchecked".
|
|
88
|
+
*/
|
|
89
|
+
export function results(points, criteria = null) {
|
|
90
|
+
const byId = new Map((criteria ?? []).filter((c) => c.id).map((c) => [String(c.id).toUpperCase(), c]));
|
|
91
|
+
const byText = new Map((criteria ?? []).map((c) => [norm(c.criterion), c]));
|
|
92
|
+
return points.map((p) => {
|
|
93
|
+
const c = byId.get(p.id) ?? byText.get(norm(p.text));
|
|
94
|
+
return { ...p, status: c ? c.status : 'unchecked', evidence: c?.evidence ?? '' };
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export const STATUS_LABEL = { met: 'Met', not_met: 'Not met', unverified: 'Not verified', unchecked: 'Not checked yet' };
|
|
99
|
+
|
|
100
|
+
export function counts(res) {
|
|
101
|
+
const n = (s) => res.filter((r) => r.status === s).length;
|
|
102
|
+
return { total: res.length, met: n('met'), notMet: n('not_met'), unverified: n('unverified'), unchecked: n('unchecked') };
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/** "3 of 5 met, 1 not met, 1 not verified", or what is left to do before there is a result. */
|
|
106
|
+
export function countsLine(c) {
|
|
107
|
+
if (!c.total) return 'no points';
|
|
108
|
+
if (c.unchecked === c.total) return `${c.total} point${c.total === 1 ? '' : 's'}, not checked yet`;
|
|
109
|
+
return [`${c.met} of ${c.total} met`, c.notMet ? `${c.notMet} not met` : '', c.unverified ? `${c.unverified} not verified` : '', c.unchecked ? `${c.unchecked} not checked yet` : ''].filter(Boolean).join(', ');
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
const MARK = { met: '✅', not_met: '❌', unverified: '❔', unchecked: '⏳' };
|
|
113
|
+
|
|
114
|
+
/** The acceptance of an agent as Markdown (the CLI prints it). `v` is what Manager.acceptanceOf returns. */
|
|
115
|
+
export function acceptanceMarkdown(v, name) {
|
|
116
|
+
const out = [`# What done means: ${name}`, ''];
|
|
117
|
+
if (v.status === 'none') return [...out, v.draft.length ? 'Not agreed. The agent wrote these in its spec:' : 'Not agreed, and the agent wrote no acceptance criteria.', '', ...v.draft.map((t, i) => `${i + 1}. ${t}`), ''].join('\n');
|
|
118
|
+
if (v.status === 'writing') return [...out, 'The agent is writing its points; it waits for you before changing anything.', ''].join('\n');
|
|
119
|
+
if (v.status === 'review') return [...out, 'Waiting for you. The agent wrote these and changes nothing until you agree:', '', ...v.draft.map((t, i) => `${i + 1}. ${t}`), ''].join('\n');
|
|
120
|
+
out.push(`Agreed ${v.agreedAt}: ${countsLine(v.counts)}${v.stale ? ' (the work changed or the points changed since the last check)' : ''}`, '');
|
|
121
|
+
for (const r of v.results) out.push(`- ${MARK[r.status]} **${r.id}** ${r.text}${r.from === 'you' ? ' _(yours)_' : ''}${r.evidence ? `\n ${STATUS_LABEL[r.status]}: ${r.evidence}` : ''}`);
|
|
122
|
+
return [...out, ''].join('\n');
|
|
123
|
+
}
|
package/src/advisor.js
CHANGED
|
@@ -57,7 +57,7 @@ const pastLines = (past) =>
|
|
|
57
57
|
const lessonLines = (lessons) => (lessons.length ? `What earlier decisions taught:\n${lessons.map((l) => `- ${clip(l, 200)}`).join('\n')}` : '');
|
|
58
58
|
|
|
59
59
|
/** The prompt for one thing waiting on the person: a plan to review, or an agent's question. */
|
|
60
|
-
export function briefPrompt(item, { standing = [], past = [], lessons = [], dates = '' } = {}) {
|
|
60
|
+
export function briefPrompt(item, { standing = [], past = [], lessons = [], dates = '', points = [], groundRules = [], repoLessons = [] } = {}) {
|
|
61
61
|
const head =
|
|
62
62
|
'You advise a senior engineer who supervises AI coding agents. Something waits for their decision. ' +
|
|
63
63
|
'Lay out the real options, recommend one, and say why in terms of this project. Be concrete and brief; do not flatter; when the evidence is thin, say so with a low confidence.';
|
|
@@ -73,6 +73,9 @@ export function briefPrompt(item, { standing = [], past = [], lessons = [], date
|
|
|
73
73
|
head,
|
|
74
74
|
`Project: ${item.project}.${dates ? ` ${dates}` : ''}`,
|
|
75
75
|
body,
|
|
76
|
+
points.length ? `What done means for this task, as agreed with the person (a recommendation must serve these):\n${points.map((p) => `- ${p.id ? `${p.id}: ` : ''}${clip(p.text ?? p, 300)}`).join('\n')}` : '',
|
|
77
|
+
groundRules.length ? `The person's ground rules for every agent (never recommend breaking one):\n${groundRules.map((r) => `- ${clip(r, 300)}`).join('\n')}` : '',
|
|
78
|
+
repoLessons.length ? `Lessons of this repository:\n${repoLessons.map((r) => `- ${clip(r, 240)}`).join('\n')}` : '',
|
|
76
79
|
standingLines(standing),
|
|
77
80
|
pastLines(past),
|
|
78
81
|
lessonLines(lessons),
|
|
@@ -257,8 +260,11 @@ export class Advisor {
|
|
|
257
260
|
* backlog, milestones, decisions, races: the other parts it reads and acts through;
|
|
258
261
|
* questions(agent): its questions; projectOf(agent): its project.
|
|
259
262
|
*/
|
|
260
|
-
constructor({ store, manager, backlog, milestones, decisions, races, questions, projectOf, bugs = () => 0, enabled = () => true, notify = null, onChange = () => {}, now = () => Date.now(), log = (m) => console.log(`[agentmgr] ${m}`), timer = true }) {
|
|
261
|
-
|
|
263
|
+
constructor({ store, manager, backlog, milestones, decisions, races, questions, projectOf, bugs = () => 0, enabled = () => true, notify = null, onChange = () => {}, now = () => Date.now(), log = (m) => console.log(`[agentmgr] ${m}`), timer = true, autonomous = () => false, guard = () => null, context = () => ({}), onAuto = null }) {
|
|
264
|
+
// autonomous(agentId): the agent runs without the person (autonomy.js), so "most" may be decided for it.
|
|
265
|
+
// guard(item): why an item is the person's whatever the recommendation (deleting, publishing, money...), or null.
|
|
266
|
+
// context(item): { points, groundRules, repoLessons } for its brief. onAuto(handled): told what was decided for the person.
|
|
267
|
+
Object.assign(this, { store, manager, backlog, milestones, decisions, races, questions, projectOf, bugs, enabled, notify, onChange, now, log, autonomous, guard, context, onAuto });
|
|
262
268
|
this.pending = new Set();
|
|
263
269
|
if (timer) {
|
|
264
270
|
this.timer = setInterval(() => this.tick().catch(() => {}), 20_000);
|
|
@@ -296,6 +302,17 @@ export class Advisor {
|
|
|
296
302
|
return this.state.autonomy[projectKey] ?? 'standing';
|
|
297
303
|
}
|
|
298
304
|
|
|
305
|
+
/** How much may be decided for one item: its project's level, or "most" when its agent runs without the person. */
|
|
306
|
+
levelOfItem(item) {
|
|
307
|
+
const p = this.levelFor(item.projectKey);
|
|
308
|
+
return this.autonomous(item.agentId) && LEVELS.indexOf(p) < LEVELS.indexOf('most') ? 'most' : p;
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
/** May this brief be carried out without asking? Never when the item is about what cannot be taken back. */
|
|
312
|
+
mayActOn(item, b) {
|
|
313
|
+
return mayAct(this.levelOfItem(item), b) && !this.guard(item);
|
|
314
|
+
}
|
|
315
|
+
|
|
299
316
|
setAutonomy(projectKey, level) {
|
|
300
317
|
if (!LEVELS.includes(level)) throw err(400, `level must be one of ${LEVELS.join(', ')}`);
|
|
301
318
|
if (!projectKey) throw err(400, 'Pick a project');
|
|
@@ -357,8 +374,9 @@ export class Advisor {
|
|
|
357
374
|
const jobs = [];
|
|
358
375
|
for (const item of items) {
|
|
359
376
|
const have = st.briefs[item.key];
|
|
360
|
-
|
|
361
|
-
|
|
377
|
+
// A brief written before its agent was set to run without the person is written again, on the models chosen for that.
|
|
378
|
+
if (have?.hash === item.hash && have.status !== 'stale' && !(have.status === 'open' && this.autonomous(item.agentId) && !have.own)) {
|
|
379
|
+
if (have.status === 'open' && this.mayActOn(item, have)) jobs.push(this.apply(item.key, have.recommend, { by: 'auto' }).catch((e) => this.log(`decide: ${e.message}`)));
|
|
362
380
|
continue;
|
|
363
381
|
}
|
|
364
382
|
if (this.pending.has(item.key)) continue;
|
|
@@ -372,17 +390,18 @@ export class Advisor {
|
|
|
372
390
|
async write(item) {
|
|
373
391
|
const standing = this.rulesFor(item);
|
|
374
392
|
const past = this.state.history.filter((h) => h.kind === item.kind).slice(-6);
|
|
375
|
-
const
|
|
393
|
+
const own = Boolean(this.autonomous(item.agentId));
|
|
394
|
+
const prompt = briefPrompt(item, { standing, past, lessons: this.state.lessons.slice(-5), dates: this.datesFor(item.projectKey).words, ...this.context(item) });
|
|
376
395
|
const agent = this.store.get(item.agentId) ?? null;
|
|
377
396
|
const d = normalizeBrief(await this.judge.ask(`advise:${item.key}:${item.hash}`, agent, prompt, (x) => Array.isArray(x.options)), item, standing);
|
|
378
397
|
const still = this.waiting().find((i) => i.key === item.key);
|
|
379
398
|
if (!still || still.hash !== item.hash) return;
|
|
380
|
-
const base = { key: item.key, kind: item.kind, agentId: item.agentId, agentName: item.agentName, project: item.project, projectKey: item.projectKey, title: clip(item.title, 300), qid: item.qid ?? null, hash: item.hash, at: this.iso(), status: 'open' };
|
|
399
|
+
const base = { key: item.key, kind: item.kind, agentId: item.agentId, agentName: item.agentName, project: item.project, projectKey: item.projectKey, title: clip(item.title, 300), qid: item.qid ?? null, hash: item.hash, at: this.iso(), status: 'open', ...(own ? { own: true } : {}) };
|
|
381
400
|
// No judge (off, over budget, or no usable reply): the card says so instead of guessing.
|
|
382
401
|
this.state.briefs[item.key] = d ? { ...base, ...d } : { ...base, options: [], recommend: null, why: '', evidence: [], risk: '', undo: 'easy', confidence: 0, standing: null, none: this.judge.enabled ? 'No recommendation could be written (the AI judge gave no usable answer, or is over its daily budget).' : 'The AI judge is off, so there is no recommendation.' };
|
|
383
402
|
this.save();
|
|
384
403
|
const b = this.state.briefs[item.key];
|
|
385
|
-
if (
|
|
404
|
+
if (this.mayActOn(item, b)) await this.apply(item.key, b.recommend, { by: 'auto' }).catch((e) => this.log(`decide: ${e.message}`));
|
|
386
405
|
}
|
|
387
406
|
|
|
388
407
|
/** Ask for the brief again (the judge was off, or you want a second look). */
|
|
@@ -413,6 +432,9 @@ export class Advisor {
|
|
|
413
432
|
this.state.handled.push({ at: b.decidedAt, key, kind: b.kind, agentId: b.agentId, agentName: b.agentName, project: b.project, projectKey: b.projectKey, title: b.title, did: opt.action === 'answer' ? `Answered: ${clip(say, 200)}` : opt.action === 'approve' ? 'Approved the plan' : `Sent the plan back: ${clip(say, 200)}`, why: b.why, standing: b.standing, standingWhen: rule?.when ?? null, confidence: b.confidence });
|
|
414
433
|
if (this.state.handled.length > 200) this.state.handled.splice(0, this.state.handled.length - 200);
|
|
415
434
|
if (rule) Object.assign(rule, { uses: (rule.uses ?? 0) + 1, lastUsedAt: b.decidedAt });
|
|
435
|
+
try {
|
|
436
|
+
this.onAuto?.({ ...this.state.handled.at(-1), qid: b.qid ?? null, action: opt.action, text: say });
|
|
437
|
+
} catch {}
|
|
416
438
|
this.notify?.(`Decided for you on *${b.project}*: ${clip(b.title, 120)} → ${this.state.handled.at(-1).did}`, `Decided for you on ${b.project}: ${clip(b.title, 120)}: ${this.state.handled.at(-1).did}`)?.catch?.(() => {});
|
|
417
439
|
}
|
|
418
440
|
this.log2decisions(b, { by, followed });
|