ai-agentmanager 1.64.0 → 1.66.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/src/private.js ADDED
@@ -0,0 +1,52 @@
1
+ // Kept private: work that may be patentable is not published by the app until the person says so.
2
+ // Publishing before filing can cost the right to a patent, so once part of an agent's work is
3
+ // read as possibly new (the agent says so in its brief, Insights reads it as possibly patentable,
4
+ // or the person marks it), everything that sends it outside this computer is held: Google Drive,
5
+ // updates and Slack, comments on the pull request, and opening the pull request itself. Only the
6
+ // person lifts it (an agent's own call is refused in server.js). It is a guard on what the app
7
+ // sends, not on what the agent can do in its terminal: the agent is told as well.
8
+ import { parseKind } from '../public/valuelens.js';
9
+
10
+ const clip = (s, n) => {
11
+ const t = String(s ?? '').replace(/\s+/g, ' ').trim();
12
+ return t.length > n ? `${t.slice(0, n - 1)}…` : t;
13
+ };
14
+
15
+ /** Insights' "### Kind" section of an agent, parsed, or null. */
16
+ export function insightsKind(agent) {
17
+ const part = String(agent?.insights?.markdown ?? '').split(/^###\s+/m).find((p) => /^kind\b/i.test(p));
18
+ return part ? parseKind(part.split('\n').slice(1).join('\n')) : null;
19
+ }
20
+
21
+ /**
22
+ * Why an agent's work is kept private: { why, from: 'you' | 'agent' | 'insights' }, or null when
23
+ * it is not (nothing was read as new, or the person allowed sharing).
24
+ */
25
+ export function keptPrivate(agent) {
26
+ const st = agent?.idea ?? {};
27
+ if (st.allowed) return null;
28
+ if (st.private) return { from: 'you', why: st.note ? `You marked it private: ${clip(st.note, 200)}` : 'You marked it private' };
29
+ const fresh = agent?.brief?.options?.new;
30
+ if (fresh) return { from: 'agent', why: `The agent says part of its design may be new: ${clip(fresh, 200)}` };
31
+ const kind = insightsKind(agent);
32
+ if (kind?.kind === 'patent') return { from: 'insights', why: `Insights reads it as possibly patentable${kind.new ? `: ${clip(kind.new, 200)}` : ''}` };
33
+ return null;
34
+ }
35
+
36
+ /** Refuse a step that sends an agent's work outside this computer while it is kept private. */
37
+ export function mustBeShareable(agent, what) {
38
+ const kept = keptPrivate(agent);
39
+ if (kept) throw Object.assign(new Error(`${what} is held: this work is kept private. ${kept.why}. Publishing before filing can cost the right to a patent. To share it anyway: agentmgr private ${agent.id} --allow`), { status: 409, keptPrivate: true });
40
+ }
41
+
42
+ /** What the agent is told when its work is marked private from outside its session. */
43
+ export const PRIVATE_MESSAGE =
44
+ 'Part of this work may be new enough to protect, so it is kept private for now. Until I say otherwise: do not publish any of it outside this ' +
45
+ 'repository. No design doc or artifact published, no Google Doc, no public gist, post, issue or package, and do not open or update a pull request. ' +
46
+ 'Keep working locally and keep your documents as files.';
47
+
48
+ /** The person's own word: `private` true keeps it private, false allows sharing, null goes back to what was read. */
49
+ export function ideaPatch(agent, { private: keep = null, note = '' } = {}) {
50
+ if (keep === null) return { idea: agent?.idea?.toldAt ? { toldAt: agent.idea.toldAt } : null };
51
+ return { idea: keep ? { private: true, note: clip(note, 300), at: new Date().toISOString() } : { allowed: true, note: clip(note, 300), at: new Date().toISOString() } };
52
+ }
package/src/quality.js CHANGED
@@ -10,6 +10,7 @@ import { PERIODS } from './value.js';
10
10
  import { repoOf } from './landing.js';
11
11
  import { ghBin } from './tracker.js';
12
12
  import { run } from './git.js';
13
+ import { saidOf, trackRecord } from './record.js';
13
14
 
14
15
  const HOUR = 3_600_000;
15
16
  const DAY = 24 * HOUR;
@@ -265,9 +266,14 @@ export class Quality {
265
266
  mergedAt: new Date(p.mergedAt).toISOString(),
266
267
  };
267
268
  if (!cur) {
268
- st.items[p.url] = { ...fields, facts: null, after: null, addedAt: new Date(t).toISOString() };
269
+ // What is said about the work as it merges (record.js): compared later with what held.
270
+ st.items[p.url] = { ...fields, facts: null, after: null, said: saidOf(a), addedAt: new Date(t).toISOString() };
269
271
  added++;
270
- } else Object.assign(cur, fields);
272
+ } else {
273
+ Object.assign(cur, fields);
274
+ // One merged before this was kept: what is said now, marked as read late.
275
+ if (!cur.said) (cur.said = { ...saidOf(a), late: true }), added++;
276
+ }
271
277
  }
272
278
  }
273
279
  if (added) this.store.save();
@@ -358,6 +364,14 @@ export class Quality {
358
364
  return { settings: s, period, periods: aggregate(all, s, { period, t }), items: all.map((it) => this.itemView(it, t)), github: !process.env.AGENTMGR_NO_GH };
359
365
  }
360
366
 
367
+ /** The track record (record.js): what was said at the merge against what held, and the level each project's record supports. */
368
+ record(t = Date.now()) {
369
+ this.scan(t);
370
+ const s = this.settings;
371
+ const au = this.config.autonomy ?? {};
372
+ return trackRecord(Object.values(this.state.items), (it) => verdictOf(it, s, t), { levels: { default: au.level ?? 'ask', projects: au.projects ?? {} } });
373
+ }
374
+
361
375
  /** A period's report: the latest complete one of a kind, or the current one so far. */
362
376
  async report(kind = 'week', { current = false, t = Date.now() } = {}) {
363
377
  if (!PERIODS[kind]) throw err(400, `kind is one of ${Object.keys(PERIODS).join(', ')}`);
package/src/record.js ADDED
@@ -0,0 +1,147 @@
1
+ // Track record: was the confidence right? Quality (quality.js) knows what happened to each merged
2
+ // pull request: held up, or reverted, fixed afterwards, failed checks. This keeps, for each one,
3
+ // what was said about it when it merged (the agent's own confidence, the review scorecard, whether
4
+ // its tests were tested, the model, how far it ran without the person) and compares the two:
5
+ // "said 85% on average, 6 of 10 held up". Per project it also says what level of "Without you"
6
+ // the record supports. The level stays the person's to set; this only suggests. No model is called.
7
+
8
+ export const MIN_TO_SAY = 5; // fewer settled pull requests than this say nothing
9
+ const LEVELS = ['ask', 'run', 'pr', 'merge'];
10
+ const LEVEL_LABEL = { ask: 'Ask me', run: 'Agree, then run', pr: 'Run to pull request', merge: 'Run to merge' };
11
+ const PROBLEMS = new Set(['reverted', 'fixed', 'broke', 'problem']);
12
+ const round = (n) => (Number.isFinite(n) ? Math.round(n) : null);
13
+
14
+ /** What is said about an agent's work now, kept when its pull request merges. */
15
+ export function saidOf(agent, { engine = null } = {}) {
16
+ const sc = agent.docs?.scorecard?.data;
17
+ const b = agent.breaks?.baseline?.ok ? agent.breaks.breaks ?? [] : null;
18
+ const n = (st) => b.filter((x) => x.status === st).length;
19
+ const pct = agent.brief?.results?.confidence?.percent;
20
+ return {
21
+ confidence: Number.isFinite(pct) ? pct : null,
22
+ score: Number.isFinite(sc?.overall) ? sc.overall : null,
23
+ recommendation: sc?.recommendation ?? null,
24
+ breaks: b && n('caught') + n('missed') ? { caught: n('caught'), tried: n('caught') + n('missed') } : null,
25
+ notDone: agent.brief?.results?.notDone?.length ?? 0,
26
+ engine: engine ?? agent.engine ?? 'claude',
27
+ model: agent.model ?? null,
28
+ level: LEVELS.includes(agent.autonomy?.level) ? agent.autonomy.level : 'ask',
29
+ };
30
+ }
31
+
32
+ const BANDS = [
33
+ ['90', '90 to 100%', (c) => c >= 90],
34
+ ['70', '70 to 89%', (c) => c >= 70 && c < 90],
35
+ ['50', '50 to 69%', (c) => c >= 50 && c < 70],
36
+ ['0', 'under 50%', (c) => c < 50],
37
+ ];
38
+ const RECOMMENDATION = { ready: 'Ready to approve', look: 'Look at these first', not_ready: 'Not ready' };
39
+
40
+ /** How what was said compares with what held: a few words, or that there are too few to say. */
41
+ export function readOf(row) {
42
+ if (row.n < MIN_TO_SAY) return 'too few to say';
43
+ if (row.said == null) return '';
44
+ if (row.said - row.heldPct >= 15) return 'said more than held up';
45
+ if (row.heldPct - row.said >= 15) return 'held up better than said';
46
+ return 'about right';
47
+ }
48
+
49
+ function rowsOf(settled, groups) {
50
+ return groups
51
+ .map(([key, label, test]) => {
52
+ const list = settled.filter((it) => test(it));
53
+ const held = list.filter((it) => it.held).length;
54
+ const conf = list.map((it) => it.said?.confidence).filter(Number.isFinite);
55
+ const row = { key, label, n: list.length, held, heldPct: list.length ? round((held / list.length) * 100) : null, said: conf.length ? round(conf.reduce((a, c) => a + c, 0) / conf.length) : null };
56
+ return { ...row, read: readOf(row) };
57
+ })
58
+ .filter((r) => r.n);
59
+ }
60
+
61
+ /**
62
+ * The level of "Without you" a project's record supports: { level, why } when it differs from the
63
+ * one it has, else null. One step at a time; down after a recent problem, up only on a clean run.
64
+ * `settled`: the project's settled pull requests, newest first.
65
+ */
66
+ export function suggestLevel(settled, current = 'ask') {
67
+ const i = LEVELS.indexOf(current);
68
+ const last = (n) => settled.slice(0, n);
69
+ const bad3 = last(3).filter((it) => !it.held).length;
70
+ if (bad3 && i > 0) return { level: LEVELS[i - 1], direction: 'down', why: `${bad3} of its last ${last(3).length} merged pull request${last(3).length === 1 ? '' : 's'} did not hold up` };
71
+ const held = settled.filter((it) => it.held).length;
72
+ const pct = settled.length ? (held / settled.length) * 100 : 0;
73
+ if (current === 'pr') {
74
+ if (settled.length >= 10 && pct >= 95 && last(10).every((it) => it.held)) return { level: 'merge', direction: 'up', why: `${held} of ${settled.length} held up, and all of the last 10` };
75
+ return null;
76
+ }
77
+ if (i < LEVELS.indexOf('pr') && settled.length >= MIN_TO_SAY && pct >= 90 && last(5).every((it) => it.held)) return { level: LEVELS[i + 1], direction: 'up', why: `${held} of ${settled.length} held up, and all of the last 5` };
78
+ return null;
79
+ }
80
+
81
+ /**
82
+ * The record from Quality's items. `verdict(it)` is quality.js's verdictOf; a pull request counts
83
+ * once it is settled: held up after the watch days, or a problem. `levels`: { default, projects }.
84
+ */
85
+ export function trackRecord(items, verdict, { levels = {} } = {}) {
86
+ const all = items.map((it) => ({ ...it, verdict: verdict(it) }));
87
+ const settled = all
88
+ .filter((it) => it.verdict === 'clean' || PROBLEMS.has(it.verdict))
89
+ .map((it) => ({ ...it, held: it.verdict === 'clean' }))
90
+ .sort((a, b) => b.mergedAt.localeCompare(a.mergedAt));
91
+ const held = settled.filter((it) => it.held).length;
92
+ const withConf = settled.filter((it) => Number.isFinite(it.said?.confidence));
93
+ const uniq = (f) => [...new Set(settled.map(f))];
94
+ const overall = rowsOf(withConf, [['all', 'all with a confidence', () => true]])[0] ?? null;
95
+ const projects = uniq((it) => it.project ?? 'No project').map((name) => {
96
+ const list = settled.filter((it) => (it.project ?? 'No project') === name);
97
+ const row = rowsOf(list, [[name, name, () => true]])[0];
98
+ const level = levels.projects?.[name] ?? null;
99
+ const current = level ?? levels.default ?? 'ask';
100
+ return { ...row, level, current, suggestion: name === 'No project' ? null : suggestLevel(list, current) };
101
+ });
102
+ return {
103
+ settled: settled.length,
104
+ open: all.length - settled.length,
105
+ held,
106
+ heldPct: settled.length ? round((held / settled.length) * 100) : null,
107
+ // The agent's own confidence against what held: overall, then by what it said.
108
+ confidence: overall,
109
+ bands: rowsOf(withConf, BANDS.map(([k, label, test]) => [k, label, (it) => test(it.said.confidence)])),
110
+ noConfidence: settled.length - withConf.length,
111
+ scorecard: rowsOf(settled, [...Object.entries(RECOMMENDATION).map(([k, label]) => [k, label, (it) => it.said?.recommendation === k]), ['none', 'No scorecard', (it) => !it.said?.recommendation]]),
112
+ tests: rowsOf(settled, [
113
+ ['all', 'Tests tested: every break caught', (it) => it.said?.breaks && it.said.breaks.caught === it.said.breaks.tried],
114
+ ['some', 'Tests tested: a break not noticed', (it) => it.said?.breaks && it.said.breaks.caught < it.said.breaks.tried],
115
+ ['none', 'Tests not tested', (it) => !it.said?.breaks],
116
+ ]),
117
+ models: rowsOf(settled, uniq((it) => `${it.said?.engine ?? 'unknown'}${it.said?.model ? ` · ${it.said.model}` : ''}`).map((k) => [k, k, (it) => `${it.said?.engine ?? 'unknown'}${it.said?.model ? ` · ${it.said.model}` : ''}` === k])),
118
+ levels: rowsOf(settled, LEVELS.map((l) => [l, LEVEL_LABEL[l], (it) => (it.said?.level ?? 'ask') === l])),
119
+ projects: projects.sort((a, b) => b.n - a.n),
120
+ defaultLevel: levels.default ?? 'ask',
121
+ };
122
+ }
123
+
124
+ const line = (r) => `${r.label}: ${r.held} of ${r.n} held up${r.heldPct == null ? '' : ` (${r.heldPct}%)`}${r.said != null ? `, said ${r.said}% on average` : ''}${r.read ? `: ${r.read}` : ''}`;
125
+
126
+ export function recordMarkdown(r) {
127
+ const out = ['# Track record', ''];
128
+ if (!r.settled) return [...out, `No merged pull request is settled yet${r.open ? ` (${r.open} still watched or not looked at)` : ''}. One counts once it held up for the watch days, or was reverted, fixed afterwards or failed its checks.`].join('\n');
129
+ out.push(`${r.held} of ${r.settled} merged pull requests held up (${r.heldPct}%).${r.open ? ` ${r.open} more are still watched or not looked at.` : ''}`, '');
130
+ const part = (title, rows, note = '') => {
131
+ if (!rows.length) return;
132
+ out.push(`## ${title}`, '', ...rows.map((x) => `- ${line(x)}`), ...(note ? ['', note] : []), '');
133
+ };
134
+ part("The agent's own confidence", [...(r.confidence ? [r.confidence] : []), ...r.bands], r.noConfidence ? `${r.noConfidence} had no confidence written.` : '');
135
+ part('The review scorecard', r.scorecard);
136
+ part('Tests tested', r.tests);
137
+ part('Model', r.models);
138
+ part('Without you', r.levels);
139
+ if (r.projects.length) {
140
+ out.push('## Projects', '');
141
+ for (const p of r.projects) {
142
+ out.push(`- ${line(p)}. New agents: ${LEVEL_LABEL[p.current]}${p.level ? '' : ' (the default)'}.${p.suggestion ? ` The record supports **${LEVEL_LABEL[p.suggestion.level]}**: ${p.suggestion.why}.` : ''}`);
143
+ }
144
+ out.push('');
145
+ }
146
+ return out.join('\n').trimEnd();
147
+ }
package/src/scorecard.js CHANGED
@@ -5,6 +5,7 @@
5
5
  // so a confident-sounding model can't talk a change into "ready".
6
6
 
7
7
  import { proofFacts } from './proof.js';
8
+ import { breakCounts, breakFacts } from './mutate.js';
8
9
 
9
10
  export const DIMENSIONS = [
10
11
  ['intent', 'Intent', 'Does it do what was asked?'],
@@ -18,7 +19,7 @@ const WEIGHTS = { intent: 25, spec: 20, tests: 20, safety: 15, scope: 10, plan:
18
19
  const TEST_FILE = /(^|\/)(tests?|__tests__|spec|specs)\/|[._-](test|spec)\.[a-z]+$|_test\.go$|Test\.java$/i;
19
20
 
20
21
  /** Facts the app knows without a model: CI, test files touched, the agent's checks, plan and spec progress. */
21
- export function facts({ files = [], prs = [], brief = null, plan = '', spec = '', standards = null, agreed = null, proof = null }) {
22
+ export function facts({ files = [], prs = [], brief = null, plan = '', spec = '', standards = null, agreed = null, proof = null, breaks = null }) {
22
23
  const paths = files.map((f) => f.path);
23
24
  const tests = paths.filter((p) => TEST_FILE.test(p));
24
25
  const code = paths.filter((p) => !TEST_FILE.test(p) && !/\.(md|txt|rst|adoc)$/i.test(p) && !/(^|\/)docs?\//i.test(p));
@@ -42,6 +43,10 @@ export function facts({ files = [], prs = [], brief = null, plan = '', spec = ''
42
43
  // Its proof (proof.js): what it recorded, what the app ran again, and what it says it left out.
43
44
  proof: proof ? { doc: proof.doc, rerun: proof.rerun ?? null } : null,
44
45
  notDone: brief?.results?.notDone ?? [],
46
+ // Its pre-mortem (brief.js): the risks it named before starting, and how each ended.
47
+ risks: brief?.risks ?? [],
48
+ // Its tests tested (mutate.js): changed lines broken one at a time, and whether the tests noticed.
49
+ breaks: breaks && !breaks.stale ? breaks : null,
45
50
  // What done means, agreed with the person (acceptance.js): these are checked, whatever the spec says now.
46
51
  agreed: agreed?.length ? agreed.map((p) => ({ id: p.id, text: p.text })) : null,
47
52
  // The repository's standards (standards.js): high-risk files touched, and the bar the app ran.
@@ -61,6 +66,14 @@ export const factLines = (f) =>
61
66
  ...(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(', ')})` : ''}`] : []),
62
67
  ...(f.risk?.length ? [`files under paths the person marked high risk: ${f.risk.join(', ')}`] : []),
63
68
  ...(f.proof ? proofFacts(f.proof.doc, f.proof.rerun) : []),
69
+ ...breakFacts(f.breaks),
70
+ ...(f.risks?.length
71
+ ? [
72
+ `risks the agent named before starting: ${f.risks.length}; it marks ${f.risks.filter((r) => r.state === 'avoided').length} avoided, ${f.risks.filter((r) => r.state === 'happened').length} happened, ${f.risks.filter((r) => r.state === 'open').length} not checked` +
73
+ (f.risks.some((r) => r.state !== 'avoided') ? ` (${f.risks.filter((r) => r.state !== 'avoided').map((r) => `${r.state === 'happened' ? 'happened' : 'not checked'}: ${r.text.slice(0, 120)}`).join('; ')})` : '') +
74
+ '. Check the ones not marked avoided against the changes.',
75
+ ]
76
+ : []),
64
77
  ...(f.notDone?.length ? [`the agent lists as not done: ${f.notDone.join('; ')}`] : []),
65
78
  ].join('\n');
66
79
 
@@ -149,6 +162,18 @@ export function combine(reply, f, hunks, { lessons = [], bar = null } = {}) {
149
162
  // Its recorded commands, run again by the app at the person's request: one that now gives another result is not verified.
150
163
  const differs = f.proof?.rerun && !f.proof.rerun.stale ? f.proof.rerun.results.filter((r) => r.status === 'differs') : [];
151
164
  if (differs.length) cap('tests', 40, `${differs.length} of its recorded commands gave a different result when run again (${differs.map((r) => r.title).join('; ').slice(0, 200)})`);
165
+ // Its tests tested by the app: breaks the tests did not notice are lines nothing verifies.
166
+ if (f.breaks?.baseline?.ok) {
167
+ const c = breakCounts(f.breaks.breaks);
168
+ if (c.tried >= 3 && !c.caught) cap('tests', 35, `none of ${c.tried} breaks made in the changed code was noticed by the tests`);
169
+ else if (c.tried >= 3 && c.missed * 2 > c.tried) cap('tests', 55, `${c.missed} of ${c.tried} breaks made in the changed code were not noticed by the tests`);
170
+ else if (c.missed && out.tests) out.tests.notes.push(`${c.missed} of ${c.tried} breaks made in the changed code ${c.missed === 1 ? 'was' : 'were'} not noticed by the tests`);
171
+ } else if (f.breaks?.baseline) cap('tests', 40, 'the tests failed when the app ran them');
172
+ // Its own pre-mortem: a risk it named and did not check is a place nobody looked.
173
+ const unchecked = (f.risks ?? []).filter((r) => r.state === 'open');
174
+ const happened = (f.risks ?? []).filter((r) => r.state === 'happened');
175
+ if (unchecked.length && out.tests) out.tests.notes.push(`${unchecked.length} of the ${f.risks.length} risks it named before starting ${unchecked.length === 1 ? 'was' : 'were'} not checked`);
176
+ if (happened.length && out.safety) out.safety.notes.push(`${happened.length} of the risks it named happened: ${happened.map((r) => r.text.slice(0, 100)).join('; ')}`);
152
177
  if (f.notDone?.length && out.intent) out.intent.notes.push(`the agent lists ${f.notDone.length} thing${f.notDone.length === 1 ? '' : 's'} as not done`);
153
178
  // Plan: bounded by the steps ticked.
154
179
  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`);
package/src/server.js CHANGED
@@ -57,8 +57,11 @@ import { Builder } from './builder.js';
57
57
  import { Standup } from './standup.js';
58
58
  import { Value, valueSlack } from './value.js';
59
59
  import { Quality } from './quality.js';
60
+ import { recordMarkdown } from './record.js';
61
+ import { PRIVATE_MESSAGE, keptPrivate, mustBeShareable } from './private.js';
60
62
  import { Standards, runCheck } from './standards.js';
61
63
  import { Proof, proofMarkdown } from './proof.js';
64
+ import { Mutate, breaksMarkdown } from './mutate.js';
62
65
  import { News } from './news.js';
63
66
  import { System } from './system.js';
64
67
  import { Advisor } from './advisor.js';
@@ -219,6 +222,7 @@ export async function startServer({ port = PORT, host = HOST, evalTimer = true }
219
222
  /** Commit what's left, push and open the agent's pull request, titled after the issue or request. */
220
223
  const shipAgent = async (ref, { title = '', body = '' } = {}) => {
221
224
  const a = manager.mustGet(ref);
225
+ mustBeShareable(a, 'Opening the pull request');
222
226
  const key = leadingJiraKey(a.intent);
223
227
  const words = a.synopsis?.text ?? a.brief?.title ?? String(a.intent ?? '').replace(/^<?https?:\/\/\S+>?\s*/, '').split('\n')[0];
224
228
  title = String(title ?? '').trim() || `${key ? `${key}: ` : ''}${words || a.name}`.slice(0, 100);
@@ -247,6 +251,14 @@ export async function startServer({ port = PORT, host = HOST, evalTimer = true }
247
251
  // nudges and follow-ups sent, and at "merge" the pull request merged when everything says ready.
248
252
  const autonomy = new Autonomy({ manager, store, config, review, landing, backlog });
249
253
  manager.proof = new Proof({ manager, store, run: runCheck, log: (m) => console.log(`[agentmgr] ${m}`) });
254
+ manager.mutate = new Mutate({ manager, store, run: runCheck, changes: (id) => review.get(id), config: config.testTheTests ?? {}, log: (m) => console.log(`[agentmgr] ${m}`) });
255
+ manager.mutate.recover();
256
+ // Read as possibly patentable by Insights: the agent is told once to keep it inside the repository (private.js).
257
+ manager.on('change', (v) => {
258
+ if (v.keptPrivate?.from !== 'insights' || v.idea?.toldAt || !manager.runtimes.get(v.id)?.pty) return;
259
+ manager.patch(v.id, { idea: { ...v.idea, toldAt: new Date().toISOString() } });
260
+ manager.tell(v.id, PRIVATE_MESSAGE);
261
+ });
250
262
  manager.inboxSources.push(() => autonomy.inbox());
251
263
  // How far an agent goes without the person is the person's to set: never an agent's own call.
252
264
  const yourLevel = (req) => {
@@ -621,6 +633,13 @@ export async function startServer({ port = PORT, host = HOST, evalTimer = true }
621
633
  const bg = (req) => req.query.background === '1' || req.body?.background === true;
622
634
  api.post('/agents/:id/explain', wrap((req) => (bg(req) ? manager.summarizeInBackground(req.params.id, ['explain']) : manager.explain(req.params.id))));
623
635
  api.post('/agents/:id/insights', wrap((req) => (bg(req) ? manager.summarizeInBackground(req.params.id, ['insights']) : manager.insights(req.params.id))));
636
+ // Kept private (private.js): yours to set and to lift, never the agent's.
637
+ api.post('/agents/:id/private', wrap((req) => {
638
+ if (req.headers['x-agentmgr-agent']) throw fail(403, 'Whether work is kept private is decided by the person, not by an agent');
639
+ const b = req.body ?? {};
640
+ if (![true, false, null].includes(b.private ?? null)) throw fail(400, 'private is true (keep it private), false (allow sharing) or null (what was read)');
641
+ return manager.setPrivate(req.params.id, { private: b.private ?? null, note: b.note ?? '' });
642
+ }));
624
643
  const DOC_LIST = ['analysis', 'design', 'flow', 'proposal', 'humanai', 'estimate', 'documentation'];
625
644
  api.post('/agents/:id/humanai/answers', wrap((req) => manager.humanAiAnswers(req.params.id, req.body?.answers, { send: req.body?.send === true })));
626
645
  api.post(
@@ -656,6 +675,7 @@ export async function startServer({ port = PORT, host = HOST, evalTimer = true }
656
675
  api.put('/agents/:id/announce', wrap((req) => manager.updateState(req.params.id, req.body ?? {})));
657
676
  api.post('/agents/:id/announce/publish', wrap((req) => manager.publishUpdate(req.params.id)));
658
677
  api.post('/agents/:id/announce/slack', wrap(async (req) => {
678
+ mustBeShareable(manager.mustGet(req.params.id), 'Posting the update to Slack');
659
679
  const to = announceSlack();
660
680
  if (!to) throw fail(409, 'Slack is not set up: give a webhook for updates (agentmgr announce --webhook <url>), or set up Slack alerts');
661
681
  const text = manager.updateSlackText(req.params.id, req.body?.text ?? null);
@@ -676,7 +696,7 @@ export async function startServer({ port = PORT, host = HOST, evalTimer = true }
676
696
  });
677
697
  // All of an agent's documents to Google Drive (through the Claude account's Google Drive connector).
678
698
  api.post('/agents/:id/drive', wrap((req) => manager.publishToDrive(req.params.id)));
679
- api.post('/agents/:id/scorecard/post', wrap((req) => review.postScorecard(req.params.id)));
699
+ api.post('/agents/:id/scorecard/post', wrap((req) => (mustBeShareable(manager.mustGet(req.params.id), 'Posting the scorecard on the pull request'), review.postScorecard(req.params.id))));
680
700
  // Improve: its scorecard goes back to the agent; a backlog item in review is reopened with it.
681
701
  api.post(
682
702
  '/agents/:id/scorecard/improve',
@@ -708,6 +728,20 @@ export async function startServer({ port = PORT, host = HOST, evalTimer = true }
708
728
  if (req.headers['x-agentmgr-agent']) throw fail(403, 'Running the proof again is asked by the person, not by an agent');
709
729
  return manager.proof.rerun(req.params.id);
710
730
  }));
731
+ // Test the tests (mutate.js): changed lines broken one at a time, the tests run on each. The
732
+ // person's call only: it runs commands here and changes the agent's files for a moment.
733
+ api.get('/agents/:id/breaks', wrap(async (req) => {
734
+ const v = await manager.mutate.view(req.params.id);
735
+ return req.query.format === 'md' ? { markdown: breaksMarkdown(v) } : v;
736
+ }));
737
+ api.post('/agents/:id/breaks/run', wrap((req) => {
738
+ if (req.headers['x-agentmgr-agent']) throw fail(403, 'Testing the tests is asked by the person, not by an agent');
739
+ return manager.mutate.start(req.params.id, { command: req.body?.command, max: req.body?.max });
740
+ }));
741
+ api.post('/agents/:id/breaks/send', wrap((req) => {
742
+ if (req.headers['x-agentmgr-agent']) throw fail(403, 'Testing the tests is asked by the person, not by an agent');
743
+ return manager.mutate.send(req.params.id);
744
+ }));
711
745
  // Autonomy (autonomy.js): the default level and the models its calls run on; one agent's level;
712
746
  // and what was done for the person: seen ("ack"), or an answer changed to their own ("correct").
713
747
  api.get('/autonomy', wrap(() => autonomy.status()));
@@ -1345,6 +1379,11 @@ export async function startServer({ port = PORT, host = HOST, evalTimer = true }
1345
1379
  return quality.view({ period: String(req.query.period ?? 'week') });
1346
1380
  }));
1347
1381
  // A pull request is named by its link, so it travels in the body.
1382
+ // Track record (record.js): what was said at the merge against what held, and the level each project's record supports.
1383
+ api.get('/quality/record', wrap((req) => {
1384
+ const r = quality.record();
1385
+ return req.query.format === 'md' ? { markdown: recordMarkdown(r) } : r;
1386
+ }));
1348
1387
  api.post('/quality/mark', wrap((req) => quality.mark(String(req.body?.url ?? ''), { verdict: req.body?.verdict ?? null, note: req.body?.note ?? '' })));
1349
1388
  api.post('/quality/check', wrap((req) => quality.check(String(req.body?.url ?? ''), { fresh: true })));
1350
1389
  // Standards are the person's to set: an agent's own calls can read them, not change them.