ai-agentmanager 1.64.0 → 1.65.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/public/style.css CHANGED
@@ -362,7 +362,34 @@ body.term-max .term-agent, .term-wrap:fullscreen .term-agent { display: inline-b
362
362
  .insight h4 { margin: 0 0 6px; font-size: 13px; color: var(--text); }
363
363
  .insight .md ul { margin: 0; padding-left: 16px; }
364
364
  .insight .md li { margin: 0 0 4px; }
365
+ .insight-wide { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) minmax(0, 2fr); margin-top: 10px; }
366
+ .insight.value { border-top-color: #f08c00; }
367
+ .insight.kind { border-top-color: #0c8599; }
368
+ .insight.paths { border-top-color: #6741d9; }
369
+ .vl-row { margin: 0 0 8px; font-size: 13px; }
370
+ .vl-row b { display: inline-block; min-width: 40px; }
371
+ .vl-word { font-weight: 600; }
372
+ .vl-meter { display: inline-flex; gap: 2px; vertical-align: middle; }
373
+ .vl-meter i { width: 10px; height: 8px; border-radius: 2px; background: var(--border); }
374
+ .vl-high i, .vl-medium i:nth-child(-n+2), .vl-low i:first-child { background: var(--accent); }
375
+ .vl-line { margin: 0 0 6px; font-size: 13px; overflow-wrap: anywhere; }
376
+ .vl-kind-task { color: var(--muted); }
377
+ .vl-kind-paper { color: #0c8599; font-weight: 600; }
378
+ .vl-kind-patent { color: #e8590c; font-weight: 600; }
379
+ .vl-paths { margin: 0 0 6px; padding-left: 20px; font-size: 13px; }
380
+ .vl-paths li { margin: 0 0 8px; overflow-wrap: anywhere; }
381
+ .vl-paths li.vl-first { font-size: 14px; }
382
+ .tag.vl-pick { color: var(--green); font-weight: 600; }
383
+ .vl-chips { display: flex; flex-wrap: wrap; gap: 4px; margin: 3px 0; }
384
+ .vl-chip { padding: 0 7px; border: 1px solid var(--border); border-radius: 999px; font-size: 12px; white-space: nowrap; }
385
+ .vl-chip.vl-good { color: var(--green); border-color: color-mix(in srgb, var(--green) 50%, transparent); }
386
+ .vl-chip.vl-poor { color: var(--red); border-color: color-mix(in srgb, var(--red) 50%, transparent); }
387
+ .vl-options .vl-paths { margin-top: 6px; }
388
+ .kept-private { margin: 6px 0 10px; padding: 8px 10px; border: 1px solid #e8590c; border-radius: 8px; font-size: 13px; overflow-wrap: anywhere; }
389
+ .kept-private p { margin: 4px 0 6px; }
390
+ .kept-private-off { margin: 4px 0; }
365
391
  @media (max-width: 1000px) { .insight-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
392
+ @media (max-width: 1000px) { .insight-wide { grid-template-columns: minmax(0, 1fr); } }
366
393
  @media (max-width: 560px) { .insight-grid { grid-template-columns: minmax(0, 1fr); } }
367
394
  .explain { margin: 0 0 12px; padding: 10px 12px; border-radius: 8px; background: var(--panel-2); border-left: 3px solid var(--accent); }
368
395
  .explain .md h3 { font-size: 13px; text-transform: none; letter-spacing: 0; color: var(--text); margin: 8px 0 2px; display: block; }
@@ -1712,6 +1739,10 @@ table.os-table .num { text-align: right; font-variant-numeric: tabular-nums; whi
1712
1739
  .quality-chip.clean, .quality-chip.watching { color: var(--green); border-color: color-mix(in srgb, var(--green) 50%, transparent); }
1713
1740
  .quality-chip.reverted, .quality-chip.fixed, .quality-chip.broke, .quality-chip.problem { color: var(--red); border-color: color-mix(in srgb, var(--red) 50%, transparent); }
1714
1741
  .quality-chip.unchecked { color: var(--muted); }
1742
+ .rec-head { margin: 16px 0 2px; font-size: 14px; }
1743
+ .rec-table td.num, .rec-table th.num { text-align: right; white-space: nowrap; }
1744
+ .rec-ok { color: var(--green); }
1745
+ .rec-bad { color: var(--red); font-weight: 600; }
1715
1746
  .value-legend .sw.rev { background: color-mix(in srgb, var(--green) 70%, transparent); }
1716
1747
  table.value-items td.mine { color: var(--accent); font-weight: 600; }
1717
1748
  table.value-items tr.excluded td { opacity: 0.5; text-decoration: line-through; }
@@ -1936,12 +1967,21 @@ table.eval-items tr.eval-na td { color: var(--muted); }
1936
1967
  .proof-row { margin: 6px 0; font-size: 13px; }
1937
1968
  .tag.proof-ok { color: var(--green); }
1938
1969
  .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; }
1970
+ .proof-list, .breaks-list { list-style: none; margin: 8px 0; padding: 0; }
1971
+ .proof-list li, .breaks-list li { margin: 0 0 10px; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; font-size: 13px; overflow-wrap: anywhere; }
1941
1972
  .proof-title { font-weight: 600; margin-bottom: 4px; }
1942
1973
  .proof-cmd { display: inline-block; max-width: 100%; white-space: pre-wrap; overflow-wrap: anywhere; }
1943
1974
  .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
1975
  .proof-out.bad { border: 1px solid var(--danger, #d9534f); }
1976
+ .breaks-head { margin: 18px 0 4px; padding-top: 12px; border-top: 1px solid var(--border); font-size: 15px; }
1977
+ .breaks-cmd { display: block; margin: 8px 0 2px; font-size: 13px; }
1978
+ .breaks-cmd input { display: block; width: 100%; margin-top: 4px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; }
1979
+ .breaks-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
1980
+ .proof-warn { color: var(--red); font-weight: 600; }
1981
+ .risks, .vl-options { margin: 6px 0; font-size: 13px; }
1982
+ .risks summary, .vl-options summary { cursor: pointer; }
1983
+ .risks ul { list-style: none; margin: 6px 0 0; padding: 0; }
1984
+ .risks li { margin: 0 0 4px; overflow-wrap: anywhere; }
1945
1985
  .auto-log { list-style: none; margin: 8px 0; padding: 0; }
1946
1986
  .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
1987
  .auto-dialog select, #settings-autonomy select, #settings-autonomy input, #settings-ground textarea, #new-autonomy { width: 100%; font: inherit; font-size: 16px; }
@@ -0,0 +1,114 @@
1
+ // Value and paths: the part of a design that is a decision. Three things are read from Markdown
2
+ // the same way wherever they are written (the Insights call, or the agent's own brief):
3
+ // Value - what the work is worth now against what it is worth later, and what waiting costs.
4
+ // Kind - whether it is just a task, worth writing up (a white paper), or possibly patentable.
5
+ // Paths - the ways to do it, preferred first, each with its value now and later, cost and risk.
6
+ // Shared by the page and the daemon (brief.js reads an agent's "## Options" with it).
7
+
8
+ const LEVELS = ['high', 'medium', 'low'];
9
+ const COSTS = ['small', 'medium', 'large'];
10
+ export const KINDS = { task: 'Just a task', paper: 'Worth a white paper', patent: 'Possibly patentable' };
11
+
12
+ const level = (s, set = LEVELS) => set.find((l) => new RegExp(`^\\W*${l}\\b`, 'i').test(String(s ?? ''))) ?? null;
13
+ const clean = (s) => String(s ?? '').replace(/\*\*/g, '').trim();
14
+ /** "high - support stops doing this by hand" -> { level: 'high', why: 'support stops…' } */
15
+ const rated = (s, set = LEVELS) => {
16
+ const t = clean(s);
17
+ const l = level(t, set);
18
+ return { level: l, why: (l ? t.replace(new RegExp(`^\\W*${l}\\b`, 'i'), '') : t).replace(/^\s*[-–—:,;.()]+\s*/, '').trim() };
19
+ };
20
+ const field = (md, name) => new RegExp(`^\\s*[-*]\\s+\\**\\s*${name}\\s*\\**\\s*:\\s*\\**\\s*(.+)$`, 'im').exec(String(md ?? ''))?.[1]?.trim() ?? '';
21
+
22
+ /** "### Value": { now, later: { level, why }, waiting, weighs: { side: now|later|both, why } } or null. */
23
+ export function parseValue(md) {
24
+ const now = field(md, 'now');
25
+ const later = field(md, 'later');
26
+ if (!now && !later) return null;
27
+ const w = clean(field(md, 'weighs'));
28
+ const side = /^\W*(now|later|both)\b/i.exec(w)?.[1].toLowerCase() ?? null;
29
+ return { now: rated(now), later: rated(later), waiting: clean(field(md, 'waiting')), weighs: { side, why: (side ? w.replace(/^\W*(now|later|both)\b/i, '') : w).replace(/^\s*[-–—:,;.]+\s*/, '').trim() } };
30
+ }
31
+
32
+ /** "### Kind": { kind: task|paper|patent, new, next } or null. */
33
+ export function parseKind(md) {
34
+ const k = clean(field(md, 'kind')).toLowerCase();
35
+ if (!k) return null;
36
+ const kind = /patent/.test(k) ? 'patent' : /paper|write-?up|publish/.test(k) ? 'paper' : 'task';
37
+ return { kind, new: clean(field(md, 'new')), next: clean(field(md, 'next')) };
38
+ }
39
+
40
+ /**
41
+ * One path: "1. Name: what it is | now: high | later: low | cost: small | risk: low | when: …"
42
+ * -> { rank, name, what, now, later, cost, risk, when }, or null when the line is not one.
43
+ */
44
+ export function parsePathLine(line) {
45
+ const m = /^\s*(\d+)[.)]\s+(.+)$/.exec(String(line ?? ''));
46
+ if (!m) return null;
47
+ const [head, ...rest] = m[2].split('|').map((s) => s.trim());
48
+ const [name, ...what] = clean(head).split(/:\s+/);
49
+ const get = (key) => rest.map((r) => new RegExp(`^\\**${key}\\**\\s*:\\s*(.+)$`, 'i').exec(r)?.[1]).find(Boolean) ?? '';
50
+ if (!name) return null;
51
+ return { rank: Number(m[1]), name: name.trim().slice(0, 120), what: what.join(': ').trim().slice(0, 300), now: level(get('now')), later: level(get('later')), cost: level(get('cost'), COSTS), risk: level(get('risk')), when: clean(get('when') || get('pick when')).slice(0, 300) };
52
+ }
53
+
54
+ /** "### Paths" (or a brief's "## Options"): { paths (by rank), preferred (why the first wins), new }. */
55
+ export function parsePaths(md) {
56
+ const paths = String(md ?? '').split('\n').map(parsePathLine).filter(Boolean).slice(0, 6).sort((a, b) => a.rank - b.rank);
57
+ return { paths, preferred: clean(field(md, 'preferred')).replace(/^\d+\s*[,:]?\s*(because\s+)?/i, '').slice(0, 400), new: clean(field(md, 'new')).slice(0, 300) };
58
+ }
59
+
60
+ const WORD = { high: 'High', medium: 'Medium', low: 'Low', small: 'Small', large: 'Large' };
61
+ const meter = (l) => `<span class="vl-meter vl-${l ?? 'none'}" aria-hidden="true"><i></i><i></i><i></i></span>`;
62
+
63
+ export function valueHtml(v, esc) {
64
+ if (!v) return '';
65
+ const row = (label, r) => `<div class="vl-row"><b>${label}</b> ${meter(r.level)} <span class="vl-word">${WORD[r.level] ?? 'Unclear'}</span><div class="hint">${esc(r.why)}</div></div>`;
66
+ const weighs = { now: 'Design for now', later: 'Design for later', both: 'Both count' }[v.weighs.side];
67
+ return `${row('Now', v.now)}${row('Later', v.later)}
68
+ ${v.waiting ? `<p class="vl-line"><b>Waiting costs</b> ${esc(v.waiting)}</p>` : ''}
69
+ ${weighs || v.weighs.why ? `<p class="vl-line"><b>${weighs ?? 'Weighs'}</b> ${esc(v.weighs.why)}</p>` : ''}`;
70
+ }
71
+
72
+ export function kindHtml(k, esc) {
73
+ if (!k) return '';
74
+ return `<p class="vl-line"><span class="tag vl-kind vl-kind-${k.kind}">${KINDS[k.kind]}</span></p>
75
+ ${k.new ? `<p class="vl-line"><b>New</b> ${esc(k.new)}</p>` : ''}
76
+ ${k.next ? `<p class="vl-line"><b>Next</b> ${esc(k.next)}</p>` : ''}
77
+ ${k.kind === 'patent' ? '<p class="hint">A first read, not legal advice. Publishing before filing can cost the right to a patent: keep it private until you have talked to a patent attorney.</p>' : ''}`;
78
+ }
79
+
80
+ export function pathsHtml(p, esc) {
81
+ if (!p?.paths.length) return '';
82
+ const chip = (label, l, good) => (l ? `<span class="vl-chip ${good.includes(l) ? 'vl-good' : l === 'medium' ? '' : 'vl-poor'}">${label} ${l}</span>` : '');
83
+ return `<ol class="vl-paths">${p.paths
84
+ .map(
85
+ (x, i) => `<li class="${i === 0 ? 'vl-first' : ''}">
86
+ <div class="vl-name">${i === 0 ? '<span class="tag vl-pick">Preferred</span> ' : ''}<b>${esc(x.name)}</b>${x.what ? ` <span class="hint">${esc(x.what)}</span>` : ''}</div>
87
+ <div class="vl-chips">${chip('now', x.now, ['high'])}${chip('later', x.later, ['high'])}${chip('cost', x.cost, ['small'])}${chip('risk', x.risk, ['low'])}</div>
88
+ ${x.when ? `<div class="hint">Pick when: ${esc(x.when)}</div>` : ''}
89
+ </li>`,
90
+ )
91
+ .join('')}</ol>
92
+ ${p.preferred ? `<p class="vl-line"><b>Why the first</b> ${esc(p.preferred)}</p>` : ''}`;
93
+ }
94
+
95
+ /** In the agent's Results: the ways it weighed before building, preferred first. */
96
+ export function optionsRows(a, esc) {
97
+ const o = a.brief?.options;
98
+ if (!o?.paths?.length && !o?.new) return '';
99
+ return `<details class="vl-options"${o.new ? ' open' : ''}><summary><b>Paths it weighed</b> <span class="hint">${o.paths.length ? `${o.paths.length}, preferred first${o.paths[0] ? `: ${esc(o.paths[0].name)}` : ''}` : ''}</span></summary>
100
+ ${pathsHtml(o, esc)}
101
+ ${o.new ? `<p class="vl-line"><span class="tag vl-kind vl-kind-paper">Possibly new</span> ${esc(o.new)} <span class="hint">Kept inside the repository; whether it is worth a paper or a patent is yours to decide.</span></p>` : ''}
102
+ </details>`;
103
+ }
104
+
105
+ /** In the agent's Results: that its work is kept private, why, and the way to allow sharing; or the way to keep it private. */
106
+ export function privateRow(a, esc) {
107
+ const k = a.keptPrivate;
108
+ if (k)
109
+ return `<div class="kept-private"><b>🔒 Kept private</b> <span>${esc(k.why)}.</span>
110
+ <p class="hint">The app does not publish or send it: no Google Drive, update, Slack, comment on the pull request or new pull request. Publishing before filing can cost the right to a patent; talk to a patent attorney first.</p>
111
+ <button class="small" data-act="idea-allow" title="You decide it can be shared: the holds are lifted">Allow sharing</button></div>`;
112
+ if (a.idea?.allowed) return `<p class="hint kept-private-off">Sharing allowed by you. <button class="link" data-act="idea-reset">Undo</button></p>`;
113
+ return '';
114
+ }
package/src/autonomy.js CHANGED
@@ -22,6 +22,7 @@ import crypto from 'node:crypto';
22
22
  import fs from 'node:fs';
23
23
  import { parseJsonReply, specPath } from './brief.js';
24
24
  import { FREE_CHOICE } from './inbox.js';
25
+ import { keptPrivate } from './private.js';
25
26
  import { memoryKey, memoryText } from './memory.js';
26
27
  import { landState } from './tracker.js';
27
28
 
@@ -74,6 +75,8 @@ export function autonomySettings(config = {}) {
74
75
  const d = AUTONOMY_DEFAULTS;
75
76
  return {
76
77
  level: parseLevel(c.level) ?? d.level,
78
+ // A level for the new agents of one project, by its name; the others get `level`.
79
+ projects: Object.fromEntries(Object.entries(c.projects ?? {}).map(([k, v]) => [k, parseLevel(v)]).filter(([k, v]) => k && v)),
77
80
  models: models.length ? models : d.models,
78
81
  answers: c.answers !== false,
79
82
  nudges: c.nudges !== false,
@@ -259,6 +262,8 @@ export function menuOf(view) {
259
262
 
260
263
  /** Why a merge is the person's: the agent says it left something out, or its proof did not hold when run again. */
261
264
  export function leftOut(agent, view) {
265
+ const kept = keptPrivate(agent);
266
+ if (kept) return `It is kept private: ${kept.why}.`;
262
267
  const nd = view?.results?.notDone ?? [];
263
268
  if (nd.length) return `The agent lists as not done: ${clip(nd.join('; '), 240)}.`;
264
269
  const rerun = agent.proof && agent.proof.proofAt === (agent.proofDoc?.updatedAt ?? null) ? agent.proof.results.filter((r) => r.status === 'differs') : [];
@@ -363,9 +368,15 @@ export class Autonomy {
363
368
  change(b = {}) {
364
369
  const next = { ...this.config.autonomy };
365
370
  if ('level' in b) {
366
- const level = parseLevel(b.level);
367
- if (!level) throw err(400, `level is one of ${LEVELS.join(', ')}`);
368
- next.level = level;
371
+ // "default" with a project: back to the level every other project gets.
372
+ const level = b.project && /^default$/i.test(String(b.level).trim()) ? null : parseLevel(b.level);
373
+ if (!level && !(b.project && /^default$/i.test(String(b.level).trim()))) throw err(400, `level is one of ${LEVELS.join(', ')}`);
374
+ const project = String(b.project ?? '').trim();
375
+ if (project) {
376
+ next.projects = { ...next.projects };
377
+ if (level) next.projects[project] = level;
378
+ else delete next.projects[project];
379
+ } else next.level = level;
369
380
  }
370
381
  if ('models' in b) {
371
382
  const models = cleanModels(b.models);
package/src/brief.js CHANGED
@@ -1,5 +1,6 @@
1
1
  // The agent's living brief: Problem, Solution, Diagram and Checks, written by
2
2
  // Claude to a Markdown file outside the repository and shown in the UI.
3
+ import { parsePaths } from '../public/valuelens.js';
3
4
  import fs from 'node:fs';
4
5
  import path from 'node:path';
5
6
  import { paths } from './config.js';
@@ -48,6 +49,8 @@ const SECTION_ALIASES = {
48
49
  checks: ['checks', 'verification', 'tests', 'testing', 'validation'],
49
50
  references: ['references', 'links', 'documents', 'docs', 'specs', 'prd / tech spec', 'prd/tech spec'],
50
51
  results: ['results', 'result', 'outcome', 'status and results', 'results and status'],
52
+ risks: ['risks', 'what could go wrong', 'pre-mortem', 'premortem', 'risks named before starting'],
53
+ options: ['options', 'paths', 'alternatives', 'options considered', 'options weighed'],
51
54
  };
52
55
 
53
56
  // "- **PRD**: [Title](https://...) — highlight", tolerating ":" / "-" / "–" separators and bare URLs.
@@ -74,6 +77,36 @@ function sectionKey(heading) {
74
77
  }
75
78
 
76
79
  const CHECK_STATES = { ' ': 'pending', '~': 'running', x: 'passed', X: 'passed', '!': 'failed' };
80
+ const RISK_STATES = { ' ': 'open', '~': 'open', x: 'avoided', X: 'avoided', '!': 'happened' };
81
+
82
+ /**
83
+ * The pre-mortem: before it changes anything the agent names how the task could go wrong, and at
84
+ * the end says for each whether it did. The list tells a reviewer where to look.
85
+ */
86
+ export const RISKS_PROMPT =
87
+ 'Before you change anything, add a section "## Risks" to the brief: the 3 to 5 most likely ways this task could go wrong or be done ' +
88
+ 'wrongly, each on one line as "- [ ] <the risk>". Be specific to this task (a part of the request that can be read two ways, an input ' +
89
+ 'that breaks it, something else that depends on what you change, a step that is easy to skip), not general ("bugs", "bad tests"). ' +
90
+ 'Do not remove or reword a risk later. When you finish, mark each one: "- [x] <the risk>: avoided, <how you know: the test or command>", ' +
91
+ '"- [!] <the risk>: happened, <what, and what you did about it>", or leave "- [ ]" when you did not check it.';
92
+
93
+ /**
94
+ * Value and paths: a design is a decision when there is more than one way. The agent lists the
95
+ * ways, preferred first, with what each is worth now and later; and says when something looks new.
96
+ */
97
+ export const OPTIONS_PROMPT =
98
+ 'When there is more than one reasonable way to solve this, add a section "## Options" to the brief before you build: 2 to 4 ways, ' +
99
+ 'preferred first, one line each as\n' +
100
+ '"1. <name>: <what it is> | now: high/medium/low | later: high/medium/low | cost: small/medium/large | risk: low/medium/high | when: <when this one is the right pick>"\n' +
101
+ '"now" is what the user gains as soon as it ships; "later" is what it makes possible, saves or avoids over time, counted lower the less sure it is. ' +
102
+ 'Then one line "- Preferred: <why the first wins>". How to rank: the most value for its cost first; between close ones, the one that is easier ' +
103
+ 'to undo; a way worth more later than now comes first only when waiting costs little or the cheaper way would close that door. ' +
104
+ 'Build the first unless the user says otherwise. When there is only one reasonable way, leave the section out: most work is just a task. ' +
105
+ 'If part of your design seems new beyond common practice, add a line "- New: <what is new>" there and do not publish it outside this ' +
106
+ 'repository: no public gist, post or package, no pull request, and write the design doc as a file without publishing it. Whether it is worth a paper or a patent is for the user to decide.';
107
+
108
+ /** Counts of a brief's risks: { total, avoided, happened, open }. */
109
+ export const riskCounts = (risks = []) => ({ total: risks.length, avoided: risks.filter((r) => r.state === 'avoided').length, happened: risks.filter((r) => r.state === 'happened').length, open: risks.filter((r) => r.state === 'open').length });
77
110
 
78
111
  /** Parse the brief Markdown into its four sections. Unknown sections are ignored. */
79
112
  const CONFIDENCE_LINE = /^\s*(?:[-*]\s+)?\**\s*confidence\s*\**\s*:\s*\**\s*(\d{1,3})\s*%?\s*\**\s*(?:[-–—:,;.]\s*)?(.*)$/i;
@@ -90,7 +123,7 @@ export function parseConfidence(body) {
90
123
  }
91
124
 
92
125
  export function parseBrief(markdown) {
93
- const out = { status: null, problem: '', solution: '', diagram: null, diagramNotes: '', checks: [], references: [], results: null };
126
+ const out = { status: null, problem: '', solution: '', diagram: null, diagramNotes: '', checks: [], references: [], results: null, risks: [], options: null };
94
127
  const st = markdown.split(/^##\s/m)[0].match(/^\s*\**status\**\s*:\s*\**\s*(planning|working|blocked|done)\b/im);
95
128
  if (st) out.status = st[1].toLowerCase();
96
129
  const parts = markdown.split(/^##\s+(.+?)\s*#*\s*$/m);
@@ -127,6 +160,16 @@ export function parseBrief(markdown) {
127
160
  const ref = parseReference(line);
128
161
  if (ref) out.references.push(ref);
129
162
  }
163
+ } else if (key === 'options') {
164
+ // The ways it weighed (OPTIONS_PROMPT): preferred first, each with its value now and later, cost and risk.
165
+ const o = parsePaths(body);
166
+ out.options = o.paths.length || o.new ? o : null;
167
+ } else if (key === 'risks') {
168
+ // The pre-mortem (RISKS_PROMPT): "- [ ] risk" as named before starting; "[x]" avoided, "[!]" happened.
169
+ for (const line of body.split('\n')) {
170
+ const m = line.match(/^\s*[-*]\s+\[([ xX!~])\]\s+(.+?)\s*$/);
171
+ if (m && out.risks.length < 12) out.risks.push({ state: RISK_STATES[m[1]], text: m[2].slice(0, 400) });
172
+ }
130
173
  } else if (key === 'checks') {
131
174
  for (const line of body.split('\n')) {
132
175
  const m = line.match(/^\s*[-*]\s+\[([ xX!~])\]\s+(.+?)\s*$/);
@@ -240,8 +283,8 @@ export function explainPrompt({ intent, status, digest, repo, briefMarkdown }) {
240
283
  /** Prompt for "Insights": Why / What / How / Now, three tidy points each. */
241
284
  export function insightsPrompt({ intent, status, digest, repo, briefMarkdown }) {
242
285
  return [
243
- "Give a human the four insights that matter about an AI coding agent's work, from its ask and live",
244
- 'context below. Write Markdown with exactly these four sections, in this order:',
286
+ "Give a human the insights that matter about an AI coding agent's work, from its ask and live",
287
+ 'context below. Write Markdown with exactly these seven sections, in this order:',
245
288
  '### Why',
246
289
  'Why this work matters: the motivation, the user or business need, or the root cause of the problem.',
247
290
  '### What',
@@ -250,12 +293,33 @@ export function insightsPrompt({ intent, status, digest, repo, briefMarkdown })
250
293
  'How it is being done: the approach, the key mechanism or the main changes.',
251
294
  '### Now',
252
295
  'Where it stands now and the next step, including anything waiting on the user.',
296
+ '### Value',
297
+ 'What the work is worth now against later. Exactly these four bullets:',
298
+ '- Now: high, medium or low - who gains what as soon as it ships',
299
+ '- Later: high, medium or low - what it makes possible, saves or avoids over time; lower the less sure it is',
300
+ '- Waiting: what is lost each week it is not done, or "little"',
301
+ '- Weighs: now, later or both - which of the two should drive the design, and why',
302
+ '### Kind',
303
+ 'What kind of idea this is. Exactly these three bullets:',
304
+ '- Kind: task, white paper or patentable idea. "task" for ordinary work done in a known way (most work). "white paper" when the approach or',
305
+ ' the result would teach others something and is worth writing up. "patentable idea" only when there is a specific technical mechanism',
306
+ ' that seems new, not an obvious step for someone skilled in the field, and useful; an idea, a goal or a business rule alone is not.',
307
+ '- New: what, concretely, is new beyond common practice, or "nothing new"',
308
+ '- Next: what to do about it: build it; write it up (and for whom); or keep it unpublished and talk to a patent attorney before sharing',
309
+ '### Paths',
310
+ 'The 2 to 4 real ways to go from here, preferred first, one numbered line each, exactly in this form:',
311
+ '1. <name>: <what it is> | now: high/medium/low | later: high/medium/low | cost: small/medium/large | risk: low/medium/high | when: <when this is the right pick>',
312
+ 'Then one bullet "- Preferred: <why the first wins>". Rank by the most value for the cost; between close ones, the one easier to undo;',
313
+ 'a way worth more later than now comes first only when waiting costs little or the cheaper way would close that door.',
314
+ 'Include the way the agent is taking. If there is truly one way, give it alone and say so in Preferred.',
253
315
  '',
254
316
  'Style rules, strictly:',
255
- '- Each section has 1 to 3 bullets, never more. Fewer is better when it is enough.',
256
- '- Each bullet is one short, concrete line of at most 12 words: easy to remember and repeat.',
317
+ '- Why, What, How and Now have 1 to 3 bullets each, never more. Fewer is better when it is enough.',
318
+ '- In those four, each bullet is one short, concrete line of at most 12 words: easy to remember and repeat.',
319
+ '- In Value, Kind and Paths, keep each line under 25 words and keep the labels exactly as given.',
257
320
  '- Lead with the key word; no filler, no hedging, no nested bullets, no preamble or closing text.',
258
321
  '- Use only the context. If something is not known yet, write "Unclear yet" as the bullet.',
322
+ '- Kind is a first read, not legal advice, and you have not searched for prior art: when unsure between two kinds, give the lower one.',
259
323
  '',
260
324
  '<agent_status>',
261
325
  status,
package/src/cli.js CHANGED
@@ -610,6 +610,52 @@ export async function main(argv) {
610
610
  if (v.rerun && !v.rerun.stale && v.rerun.differs) process.exitCode = 1;
611
611
  });
612
612
 
613
+ program
614
+ .command('test-tests')
615
+ .description("Test an agent's tests: break the lines it changed one at a time (=== becomes !==, && becomes ||, a number goes up by one), run the tests on each, and put the line back. A break the tests still pass on is a line nothing checks. Without --run it shows the last run (exit 1 when a break went unnoticed).")
616
+ .argument('<agent>')
617
+ .option('--run', "break the changed lines and run the tests now, in the agent's folder")
618
+ .option('-c, --command <command>', 'the command that runs the tests (default: the passing commands the agent recorded in its proof)')
619
+ .option('--max <n>', 'how many lines to break (default 8)')
620
+ .option('--send', 'tell the agent which breaks its tests did not notice')
621
+ .option('--json', 'print it as JSON')
622
+ .action(async (ref, opts) => {
623
+ await daemon();
624
+ const a = await resolveAgent(ref);
625
+ let v = await api('GET', `/agents/${a.id}/breaks`);
626
+ if (opts.run) {
627
+ const cmds = opts.command ? [opts.command] : v.commands;
628
+ if (cmds.length) process.stderr.write(dim(`Breaking up to ${opts.max ?? v.max} changed lines in ${a.workdir ?? 'its folder'}, one at a time, and running: ${cmds.join(' && ')}\nEach line is put back after its run…\n`));
629
+ v = await api('POST', `/agents/${a.id}/breaks/run`, { command: opts.command, max: opts.max ? Number(opts.max) : undefined });
630
+ }
631
+ if (opts.send) v = await api('POST', `/agents/${a.id}/breaks/send`);
632
+ if (opts.json) console.log(JSON.stringify(v, null, 2));
633
+ else {
634
+ console.log((await api('GET', `/agents/${a.id}/breaks?format=md`)).markdown);
635
+ if (!v.last) console.log(dim(v.commands.length ? `\nRun it: agentmgr test-tests ${a.id} --run (tests: ${v.commands.join(' && ')})` : `\nThe agent recorded no passing test command. Run it with yours: agentmgr test-tests ${a.id} --run -c "npm test"`));
636
+ else if (opts.send) console.log(green('\nSent to the agent.'));
637
+ else if (v.last.missed && !v.last.stale) console.log(dim(`\nTell the agent: agentmgr test-tests ${a.id} --send`));
638
+ }
639
+ if (v.last && !v.last.stale && (v.last.missed || !v.last.baseline.ok)) process.exitCode = 1;
640
+ });
641
+
642
+ program
643
+ .command('private')
644
+ .description("Keep an agent's work private, or allow sharing it. Work that may be patentable (the agent says part of its design is new, or Insights reads it so) is kept private by itself: publishing to Google Drive, updates, Slack, comments on the pull request and opening the pull request are held until you allow it. Publishing before filing can cost the right to a patent.")
645
+ .argument('<agent>')
646
+ .option('--keep', 'keep it private')
647
+ .option('--allow', 'allow sharing it')
648
+ .option('--reset', 'back to what the agent and Insights say')
649
+ .option('--note <text>', 'why, in a line')
650
+ .action(async (ref, o) => {
651
+ await daemon();
652
+ const a = await resolveAgent(ref);
653
+ if ([o.keep, o.allow, o.reset].filter(Boolean).length > 1) throw new Error('Give one of --keep, --allow or --reset');
654
+ const v = o.keep || o.allow || o.reset ? await api('POST', `/agents/${a.id}/private`, { private: o.keep ? true : o.allow ? false : null, note: o.note ?? '' }) : a;
655
+ if (v.keptPrivate) console.log(`${bold('Kept private.')} ${v.keptPrivate.why}\n${dim(`Nothing of it is published or sent by the app. Allow sharing: agentmgr private ${a.id} --allow`)}`);
656
+ else console.log(v.idea?.allowed ? `${green('✓')} Sharing is allowed (you said so).` : `Not kept private: nothing in it was read as new. ${dim(`Keep it private anyway: agentmgr private ${a.id} --keep`)}`);
657
+ });
658
+
613
659
  program
614
660
  .command('acceptance')
615
661
  .description('What done means for an agent: the points its work is checked against. The agent drafts them in its spec; you edit and agree; the review scorecard then reports each one as met, not met or not verified')
@@ -667,7 +713,7 @@ export async function main(argv) {
667
713
 
668
714
  program
669
715
  .command('insights')
670
- .description('Why / What / How / Now for an agent, three tidy points each (one-off Claude call)')
716
+ .description('Insights for an agent: Why / What / How / Now in three tidy points each, then what the work is worth now against later, what kind of idea it is (a task, worth a white paper, possibly patentable) and the ways to go, preferred first (one-off Claude call)')
671
717
  .argument('<agent>')
672
718
  .action(async (ref) => {
673
719
  await daemon();
@@ -1516,6 +1562,17 @@ export async function main(argv) {
1516
1562
  for (const it of items) console.log(` ${truncate(`#${it.number ?? '?'} ${it.title}`, 54).padEnd(54)} ${(['clean', 'watching'].includes(it.verdict) ? green : it.verdict === 'unchecked' ? dim : yellow)(word[it.verdict].padEnd(17))} ${dim(it.url)}`);
1517
1563
  if (!v.github) console.log(dim('\nGitHub is not asked here, so nothing is looked at.'));
1518
1564
  });
1565
+ qualityCmd
1566
+ .command('record')
1567
+ .description("The track record: what was said when each pull request merged (the agent's own confidence, the scorecard, whether its tests were tested, the model, how far it ran without you) against what held up; and the level of \"Without you\" each project's record supports")
1568
+ .option('--json', 'print JSON')
1569
+ .action(async (opts) => {
1570
+ await daemon();
1571
+ if (opts.json) return console.log(JSON.stringify(await api('GET', '/quality/record'), null, 2));
1572
+ const r = await api('GET', '/quality/record');
1573
+ console.log((await api('GET', '/quality/record?format=md')).markdown);
1574
+ for (const p of r.projects.filter((x) => x.suggestion)) console.log(dim(`\nSet it: agentmgr autonomy --project "${p.label}" --default ${p.suggestion.level}`));
1575
+ });
1519
1576
  qualityCmd
1520
1577
  .command('mark <pr-url>')
1521
1578
  .description('Say what a merged pull request was: not a problem, a problem, or back to what was found')
@@ -1793,6 +1850,7 @@ export async function main(argv) {
1793
1850
  .argument('[agent]')
1794
1851
  .argument('[level]', 'ask, run, pr or merge: set it for this agent')
1795
1852
  .option('--default <level>', 'the level new agents get when none is named')
1853
+ .option('--project <name>', 'with --default: the level for the new agents of this project only ("default" takes it away again)')
1796
1854
  .option('--models <list>', 'the models its calls run on, best first; the next one is used when a call fails (default: fable,opus,sonnet)')
1797
1855
  .option('--ok <entry>', 'you have seen an answer given for you (its id from the list; "hold" for a held merge)')
1798
1856
  .option('--change <entry=answer>', 'your own answer to a question that was answered for you; the agent is told to apply it')
@@ -1801,10 +1859,12 @@ export async function main(argv) {
1801
1859
  await daemon();
1802
1860
  const { LEVEL_LABEL, logLine } = await import('./autonomy.js');
1803
1861
  if (!ref) {
1804
- const patch = { ...(o.default ? { level: o.default } : {}), ...(o.models ? { models: o.models } : {}) };
1862
+ if (o.project && !o.default) throw new Error('--project goes with --default <level>');
1863
+ const patch = { ...(o.default ? { level: o.default, ...(o.project ? { project: o.project } : {}) } : {}), ...(o.models ? { models: o.models } : {}) };
1805
1864
  const s = Object.keys(patch).length ? await api('PUT', '/autonomy', patch) : await api('GET', '/autonomy');
1806
1865
  if (o.json) return console.log(JSON.stringify(s, null, 2));
1807
1866
  console.log(`${bold('New agents:')} ${LEVEL_LABEL[s.level]} ${dim(`(${s.level})`)}`);
1867
+ for (const [name, l] of Object.entries(s.projects ?? {})) console.log(`${bold(`New agents in ${name}:`)} ${LEVEL_LABEL[l]} ${dim(`(${l})`)}`);
1808
1868
  console.log(`${bold('Models, best first:')} ${s.models.map((m) => (typeof m === 'string' ? m : `${m.engine ?? 'claude'}:${m.model}`)).join(' → ')}`);
1809
1869
  console.log(dim(`${s.agents} agent${s.agents === 1 ? '' : 's'} running without you · ${s.calls} of ${s.dailyCalls} calls today${s.lastModel ? ` · last answered by ${s.lastModel}` : ''}`));
1810
1870
  if (s.lastError) console.log(dim(`Last failure ${s.lastError.at}: ${s.lastError.message}`));
package/src/config.js CHANGED
@@ -53,6 +53,12 @@ const DEFAULTS = {
53
53
  brief: true,
54
54
  // With the brief: ask for the proof of its checks (PROOF.md: command, exit code, output) and what it did not do.
55
55
  proof: true,
56
+ // With the brief: ask for a pre-mortem (## Risks: how the task could go wrong, named before starting and marked at the end).
57
+ premortem: true,
58
+ // With the brief: when there is more than one way, ask for the options ranked by value now and later (## Options).
59
+ valueLens: true,
60
+ // Test the tests (mutate.js): how many changed lines are broken in one run, the longest the tests may take, and one run in all.
61
+ testTheTests: { max: 8, timeoutMs: 300_000, budgetMs: 900_000 },
56
62
  // Backlog: items worked on at once per project (overridable per project), and overall.
57
63
  backlogParallel: 2,
58
64
  backlogMaxActive: 4,
@@ -107,6 +107,9 @@ export default {
107
107
  attention: [
108
108
  [/trustthisfolder/i, 'Folder trust prompt'],
109
109
  [/Doyouwantto(proceed|make|create|allow|run|overwrite)/i, 'Permission prompt'],
110
+ // The same prompt when a redraw dropped letters of its question ("Do you want to pro eed?"): its
111
+ // choices and footer, Yes first, No last, then "Esc to cancel" (a question menu ends "Enter to select").
112
+ [/(?:^|[^a-z0-9])1\.?Yes.{0,300}\d\.?No.{0,60}(?<!Entertoselect.{0,40})Esctocancel/i, 'Permission prompt'],
110
113
  // The agent's own question, as a menu: a message typed now would pick the highlighted option.
111
114
  [/Entertoselect.{0,40}Esctocancel/i, 'Question'],
112
115
  ],
package/src/inbox.js CHANGED
@@ -119,7 +119,10 @@ export function questionMenu(screen) {
119
119
  export function promptChoices(screen) {
120
120
  const text = String(screen ?? '')
121
121
  .replace(/\x1b\[(\d*)C/g, (_, n) => ' '.repeat(Math.min(Number(n || 1), 8)))
122
- .replace(/\x1b\[[0-9;]*[ABDGHJKfm]/g, '\n')
122
+ // A jump along the line is a gap, not a new line. Claude Code redraws only the cells that
123
+ // changed, so a prompt can arrive as "pro" + jump + "eed?" and "❯ 1" + jump + "Yes".
124
+ .replace(/\x1b\[\d*G/g, ' ')
125
+ .replace(/\x1b\[[0-9;]*[ABDHJKfm]/g, '\n')
123
126
  .replace(/\x1b\[[0-9;?<>=]*[ -\/]*[@-~]|\x1b\][^\x07\x1b]*(\x07|\x1b\\)/g, '')
124
127
  .replace(/\r/g, '\n');
125
128
  const lines = text.split('\n').map((l) => l.replace(/\s+/g, ' ').trim());
@@ -127,9 +130,11 @@ export function promptChoices(screen) {
127
130
  const choices = new Map();
128
131
  let question = '';
129
132
  for (let i = lines.length - 1; i >= 0; i--) {
130
- const m = /^(?:[❯>›]\s*)?(\d)[.)]\s+(.{1,80})$/.exec(lines[i]);
133
+ // The highlighted choice can lose its dot to a redraw ("❯ 1 Yes"): the pointer marks it as one.
134
+ const m = /^(?:[❯>›]\s*(\d)[.)]?|(\d)[.)])\s+(.{1,80})$/.exec(lines[i]);
131
135
  if (m) {
132
- if (!choices.has(m[1])) choices.set(m[1], m[2].trim());
136
+ const key = m[1] ?? m[2];
137
+ if (!choices.has(key)) choices.set(key, m[3].replace(/\s*·.*$/, '').trim());
133
138
  } else if (choices.size && lines[i]) {
134
139
  question = lines[i].slice(0, 200);
135
140
  break;
@@ -139,13 +144,14 @@ export function promptChoices(screen) {
139
144
  // and switch to auto mode 3. No Esc to cancel"): read the flattened screen after the last question.
140
145
  if (!choices.size) {
141
146
  const flat = lines.join(' ').replace(/\s+/g, ' ');
142
- const at = flat.search(/\?\s*(?:[❯>›]\s*)?1[.)]\s*\S[^?]*$/);
147
+ const at = flat.search(/\?\s*(?:[❯>›]\s*1[.)]?|1[.)])\s*\S[^?]*$/);
143
148
  if (at >= 0) {
144
149
  const head = flat.slice(0, at + 1);
145
150
  // Drop what's left of the box around it (╌ ─ │ and stray letters before them).
146
151
  question = (/([^.?!│]*\?)$/.exec(head)?.[1] ?? '').replace(/^.*[╌─│━]+\s*/, '').trim().slice(-200);
147
- for (const m of flat.slice(at + 1).matchAll(/(?:[❯>›]\s*)?\b(\d)[.)]\s*(.+?)(?=\s+(?:[❯>›]\s*)?\d[.)]\s|\s+Esc to cancel|\s+Enter to|$)/g)) {
148
- if (!choices.has(m[1])) choices.set(m[1], m[2].replace(/\s*·.*$/, '').trim().slice(0, 80));
152
+ for (const m of flat.slice(at + 1).matchAll(/(?:[❯>›]\s*(\d)[.)]?|\b(\d)[.)])\s*(.+?)(?=\s+(?:[❯>›]\s*)?\d[.)]\s|\s+Esc to cancel|\s+Enter to|$)/g)) {
153
+ const key = m[1] ?? m[2];
154
+ if (!choices.has(key)) choices.set(key, m[3].replace(/\s*·.*$/, '').trim().slice(0, 80));
149
155
  }
150
156
  }
151
157
  }