ai-agentmanager 1.60.0 → 1.62.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.
@@ -0,0 +1,274 @@
1
+ // Quality: what happened to the agents' pull requests after they merged, by day, week, month,
2
+ // quarter and year: the share that held up, the ones reverted, fixed afterwards or with failed
3
+ // checks, and from before the merge how often a reviewer asked for changes. A follow-up fix is a
4
+ // guess, so each pull request can be marked as not a problem, or as one.
5
+
6
+ import { expandButton, expandable } from './expand.js';
7
+ import { initStandards } from './standards.js';
8
+
9
+ const PERIODS = [
10
+ ['day', 'Day'],
11
+ ['week', 'Week'],
12
+ ['month', 'Month'],
13
+ ['quarter', 'Quarter'],
14
+ ['year', 'Year'],
15
+ ];
16
+ const SAVED = 'agentmgr.qualityPeriod';
17
+ const WORD = { reverted: 'Reverted', fixed: 'Fixed afterwards', broke: 'Checks failed', problem: 'A problem', clean: 'Held up', watching: 'Fine so far', unchecked: 'Not looked at' };
18
+ const BAD = new Set(['reverted', 'fixed', 'broke', 'problem']);
19
+
20
+ export function initQuality({ api, $, esc, toast, ago, openAgent }) {
21
+ const dialog = $('#quality-dialog');
22
+ const body = $('#quality-body');
23
+ let data = null;
24
+ let period = 'week';
25
+ let selected = null; // a period key; null is the current one
26
+ let only = false; // only the ones that did not hold up
27
+ let again = null;
28
+ let mode = 'after'; // or 'standards': what every change in a repository has to meet (standards.js)
29
+ const std = initStandards({
30
+ api,
31
+ esc,
32
+ toast,
33
+ rerender: (force) => {
34
+ if (force) document.activeElement?.blur();
35
+ render();
36
+ },
37
+ });
38
+ try {
39
+ period = localStorage.getItem(SAVED) || 'week';
40
+ } catch {}
41
+
42
+ async function load() {
43
+ try {
44
+ data = await api('GET', `/quality?period=${period}`);
45
+ } catch (e) {
46
+ toast?.(e.message, 5000);
47
+ }
48
+ render();
49
+ }
50
+
51
+ // A lower share of problems is the better direction, so the arrow's color follows the meaning.
52
+ function card(label, value, sub, delta, goodUp) {
53
+ const d = Number.isFinite(delta) && delta !== 0 ? `<div class="value-delta ${delta > 0 === goodUp ? 'up' : 'down'}">${delta > 0 ? '▲' : '▼'} ${Math.abs(delta)} points vs before</div>` : '';
54
+ return `<div class="value-card"><div class="hint">${esc(label)}</div><div class="value-big">${value}</div>${sub ? `<div class="hint">${sub}</div>` : ''}${d}</div>`;
55
+ }
56
+
57
+ const shortLabel = (p) => {
58
+ const d = new Date(p.start);
59
+ if (period === 'day') return d.toLocaleDateString(undefined, { weekday: 'narrow', day: 'numeric' });
60
+ if (period === 'week') return d.toLocaleDateString(undefined, { month: 'numeric', day: 'numeric' });
61
+ if (period === 'month') return d.toLocaleDateString(undefined, { month: 'short' });
62
+ return period === 'year' ? p.label : p.label.split(' ')[0];
63
+ };
64
+
65
+ function bars(periods) {
66
+ const max = Math.max(1, ...periods.map((p) => p.totals.prs));
67
+ return `<div class="value-bars" role="list">${[...periods]
68
+ .reverse()
69
+ .map((p) => {
70
+ const t = p.totals;
71
+ const on = (selected ?? periods[0].key) === p.key;
72
+ return `<button class="value-bar ${on ? 'on' : ''}" role="listitem" data-quality-pick="${esc(p.key)}" title="${esc(`${p.label}: ${t.prs} merged, ${t.problems} with a problem${t.heldPct == null ? '' : `, ${t.heldPct}% held up`}`)}">
73
+ <span class="stack"><span class="bad" style="height:${(t.problems / max) * 100}%"></span><span class="val" style="height:${((t.prs - t.problems) / max) * 100}%"></span></span>
74
+ <span class="lbl">${esc(shortLabel(p))}</span>
75
+ </button>`;
76
+ })
77
+ .join('')}</div>`;
78
+ }
79
+
80
+ const link = (x) => (x.url ? `<a href="${esc(x.url)}" target="_blank" rel="noopener">${esc(x.number ? `#${x.number} ` : '')}${esc(x.title)}</a>` : esc(x.title));
81
+
82
+ function why(it) {
83
+ const a = it.after;
84
+ if (it.mark) return `You said so${it.mark.note ? `: ${esc(it.mark.note)}` : ''}`;
85
+ if (it.verdict === 'reverted') return `Reverted by ${link(a.reverted)}`;
86
+ if (it.verdict === 'fixed') return a.fixes.map((f) => `${link(f)}${f.shared.length ? ` <span class="hint">same file${f.shared.length === 1 ? '' : 's'}: ${esc(f.shared.join(', '))}</span>` : ' <span class="hint">names it</span>'}`).join('<br>');
87
+ if (it.verdict === 'broke') return `Failed on the merged commit: ${esc(a.checks.failed.join(', '))}`;
88
+ if (it.verdict === 'unchecked') return it.error ? `GitHub: ${esc(it.error)}` : data.github ? 'Waiting its turn' : 'GitHub is not asked here';
89
+ if (it.verdict === 'watching') return `Nothing found; watched until ${esc(new Date(Date.parse(it.mergedAt) + data.settings.watchDays * 86_400_000).toLocaleDateString())}`;
90
+ return 'Nothing found';
91
+ }
92
+
93
+ function itemRow(it) {
94
+ const f = it.facts;
95
+ const hours = it.openedAt ? Math.round(((Date.parse(it.mergedAt) - Date.parse(it.openedAt)) / 3_600_000) * 10) / 10 : null;
96
+ return `<tr>
97
+ <td class="hint nowrap">${esc(new Date(it.mergedAt).toLocaleDateString())}</td>
98
+ <td><a href="${esc(it.url)}" target="_blank" rel="noopener">#${esc(it.number ?? '?')} ${esc(it.title)}</a><div class="hint">${esc([it.project, it.agentName].filter(Boolean).join(' · '))}</div></td>
99
+ <td><span class="quality-chip ${esc(it.verdict)}">${esc(WORD[it.verdict])}</span>${it.mark ? ' <span class="hint" title="Marked by you">✎</span>' : ''}</td>
100
+ <td>${why(it)}</td>
101
+ <td class="nowrap">${f ? `${f.changesRequested ? `${f.changesRequested} change request${f.changesRequested === 1 ? '' : 's'}` : 'no change requests'}<div class="hint">${f.lines} lines${hours != null ? ` · ${hours}h to merge` : ''}</div>` : '<span class="hint">—</span>'}</td>
102
+ <td class="nowrap">
103
+ ${it.mark ? `<button class="link" data-quality-mark="" data-url="${esc(it.url)}" title="Back to what was found">Undo</button>` : BAD.has(it.verdict) ? `<button class="link" data-quality-mark="clean" data-url="${esc(it.url)}" title="What was found is not about this pull request">Not a problem</button>` : `<button class="link" data-quality-mark="problem" data-url="${esc(it.url)}" title="It caused a problem that was not found here">It was a problem</button>`}
104
+ <div><button class="link" data-quality-check="${esc(it.url)}" ${data.github ? '' : 'disabled'} title="Look at GitHub again now${it.checkedAt ? `; last looked ${esc(ago(it.checkedAt))}` : ''}">Look again</button>${it.gone ? '' : ` · <button class="link" data-quality-agent="${esc(it.agentId)}">Agent</button>`}</div>
105
+ </td>
106
+ </tr>`;
107
+ }
108
+
109
+ function render() {
110
+ if (!dialog.open) return;
111
+ if (!data) {
112
+ body.innerHTML = '<p class="hint">Loading…</p>';
113
+ return;
114
+ }
115
+ if (body.contains(document.activeElement) && document.activeElement.matches('input, textarea, select')) return;
116
+ const n = std.proposed();
117
+ const modes = `<div class="chips" role="tablist" aria-label="Quality">
118
+ <button class="chip ${mode === 'after' ? 'active' : ''}" role="tab" aria-selected="${mode === 'after'}" data-quality-mode="after">After the merge</button>
119
+ <button class="chip ${mode === 'standards' ? 'active' : ''}" role="tab" aria-selected="${mode === 'standards'}" data-quality-mode="standards" title="What every change in a repository has to meet: lessons from what went wrong, high-risk paths, and the checks the app runs itself">Standards${n ? ` <span class="badge">${n}</span>` : ''}</button>
120
+ </div>`;
121
+ if (mode === 'standards') {
122
+ body.innerHTML = `
123
+ <div class="issues-head">
124
+ <h2>Quality</h2>
125
+ ${modes}
126
+ <span class="spacer"></span>
127
+ ${expandButton(dialog)}
128
+ <button class="small" data-quality="close" title="Close (Esc)">Close</button>
129
+ </div>
130
+ ${std.html()}`;
131
+ return;
132
+ }
133
+ const ps = data.periods;
134
+ const i = Math.max(0, ps.findIndex((p) => p.key === selected));
135
+ const p = ps[i];
136
+ const prev = ps[i + 1]?.totals.checked ? ps[i + 1].totals : null;
137
+ const t = p.totals;
138
+ const inside = data.items.filter((it) => p.items.includes(it.url));
139
+ const items = only ? inside.filter((it) => BAD.has(it.verdict)) : inside;
140
+ const pct = (n) => (n == null ? '—' : `${n}%`);
141
+ const s = data.settings;
142
+ body.innerHTML = `
143
+ <div class="issues-head">
144
+ <h2>Quality</h2>
145
+ ${modes}
146
+ <div class="chips" role="tablist">${PERIODS.map(([k, label]) => `<button class="chip ${k === period ? 'active' : ''}" role="tab" aria-selected="${k === period}" data-quality-period="${k}">${label}</button>`).join('')}</div>
147
+ <span class="spacer"></span>
148
+ <button class="small" data-quality="copy" title="Copy this period's report as Markdown">Copy report</button>
149
+ ${expandButton(dialog)}
150
+ <button class="small" data-quality="close" title="Close (Esc)">Close</button>
151
+ </div>
152
+ <p class="value-period"><b>${esc(p.label)}</b>${p.current ? ' <span class="hint">so far</span>' : ''} · ${t.prs} pull request${t.prs === 1 ? '' : 's'} from agents merged${t.unchecked ? ` · <span class="hint">${t.unchecked} not looked at yet</span>` : ''}</p>
153
+ ${data.github ? '' : '<p class="hint">GitHub is not asked on this computer, so merged pull requests are listed but not looked at.</p>'}
154
+ <div class="value-cards">
155
+ ${card('Held up', pct(t.heldPct), `${t.held} of ${t.checked} looked at${t.watching ? `; ${t.watching} still watched` : ''}`, prev && t.heldPct != null ? t.heldPct - prev.heldPct : null, true)}
156
+ ${card('Problems after the merge', String(t.problems), `${pct(t.failurePct)} of those looked at`, prev && t.failurePct != null ? t.failurePct - prev.failurePct : null, false)}
157
+ ${card('Reverted', String(t.reverted), 'taken back out', null)}
158
+ ${card('Fixed afterwards', String(t.fixed), `a fix to the same files within ${s.watchDays} days`, null)}
159
+ ${card('Checks failed', String(t.broke), 'on the commit it merged as', null)}
160
+ ${card('Changes requested', pct(t.changesPct), `by a reviewer, before the merge (${t.changesRequested})`, prev && t.changesPct != null && prev.changesPct != null ? t.changesPct - prev.changesPct : null, false)}
161
+ ${card('Opened to merged', t.hoursToMerge == null ? '—' : `${t.hoursToMerge}h`, 'median', null)}
162
+ </div>
163
+ ${bars(ps)}
164
+ <div class="value-legend hint"><span class="sw val"></span> held up <span class="sw bad"></span> a problem after the merge · pick a bar to see that ${esc(period)}
165
+ <span class="spacer"></span><label class="check"><input type="checkbox" data-quality-only ${only ? 'checked' : ''} /> Only the ones with a problem</label></div>
166
+ ${items.length
167
+ ? `<div class="issues-scroll"><table class="issues quality-items">
168
+ <thead><tr><th>Merged</th><th>Pull request</th><th>After the merge</th><th>Why</th><th>Before the merge</th><th></th></tr></thead>
169
+ <tbody>${items.map(itemRow).join('')}</tbody></table></div>`
170
+ : `<p class="hint issues-empty">${inside.length ? 'None of them had a problem.' : data.items.length ? `No pull request from an agent merged in ${esc(p.label)}.` : "No pull request from an agent has merged yet. Each one is looked at here once it has."}</p>`}
171
+ <details class="value-settings"><summary>Settings and how it is worked out</summary>
172
+ <form data-quality-settings>
173
+ <label class="check"><input type="checkbox" name="enabled" ${s.enabled ? 'checked' : ''} /> Look at merged pull requests on GitHub, for <input type="number" class="inline" name="watchDays" min="1" max="90" value="${s.watchDays}" /> days after each merge</label>
174
+ <p class="hint">Asked through the gh CLI as you, a few pull requests every two minutes and each again every six hours while it is watched. <b>Reverted</b>: a pull request titled Revert that names it, or a commit that reverts the one it merged as. <b>Fixed afterwards</b>: a later pull request whose title says it fixes something and that changes one of the same files, or names it; this one is a guess, so say <b>Not a problem</b> where it is wrong. <b>Checks failed</b>: a check on the merged commit failed or timed out. No model is called.</p>
175
+ <div class="actions"><span class="spacer"></span><button class="small primary">Save settings</button></div>
176
+ </form></details>`;
177
+ }
178
+
179
+ body.addEventListener('click', async (e) => {
180
+ const m = e.target.closest('[data-quality-mode]');
181
+ if (m) {
182
+ mode = m.dataset.qualityMode;
183
+ render();
184
+ return mode === 'standards' ? std.load() : load();
185
+ }
186
+ if (mode === 'standards' && std.click(e)) return;
187
+ const per = e.target.closest('[data-quality-period]');
188
+ if (per) {
189
+ period = per.dataset.qualityPeriod;
190
+ selected = null;
191
+ try {
192
+ localStorage.setItem(SAVED, period);
193
+ } catch {}
194
+ return load();
195
+ }
196
+ const pick = e.target.closest('[data-quality-pick]');
197
+ if (pick) {
198
+ selected = pick.dataset.qualityPick;
199
+ return render();
200
+ }
201
+ const mark = e.target.closest('[data-quality-mark]');
202
+ const check = e.target.closest('[data-quality-check]');
203
+ if (mark || check) {
204
+ try {
205
+ if (mark) await api('POST', '/quality/mark', { url: mark.dataset.url, verdict: mark.dataset.qualityMark || null });
206
+ else {
207
+ toast?.('Looking at GitHub…');
208
+ await api('POST', '/quality/check', { url: check.dataset.qualityCheck });
209
+ }
210
+ } catch (err) {
211
+ toast?.(err.message, 6000);
212
+ }
213
+ return load();
214
+ }
215
+ const agent = e.target.closest('[data-quality-agent]');
216
+ if (agent) {
217
+ dialog.close();
218
+ return openAgent(agent.dataset.qualityAgent);
219
+ }
220
+ const b = e.target.closest('[data-quality]')?.dataset.quality;
221
+ if (b === 'close') return dialog.close();
222
+ if (b === 'copy') {
223
+ const p = data?.periods.find((x) => x.key === selected) ?? data?.periods[0];
224
+ if (p && !p.current && p !== data.periods[1]) return toast?.('Reports are for the current period or the one just ended: pick one of those bars', 5000);
225
+ try {
226
+ const r = await api('GET', `/quality/report?kind=${period}${p?.current ? '&current=1' : ''}`);
227
+ await navigator.clipboard.writeText(r.markdown);
228
+ toast?.(`Copied the report for ${r.period.label}`);
229
+ } catch (err) {
230
+ toast?.(err.message, 6000);
231
+ }
232
+ }
233
+ });
234
+
235
+ body.addEventListener('change', (e) => {
236
+ if (mode === 'standards' && std.change(e)) return;
237
+ if (!e.target.matches('[data-quality-only]')) return;
238
+ only = e.target.checked;
239
+ e.target.blur();
240
+ render();
241
+ });
242
+
243
+ body.addEventListener('submit', async (e) => {
244
+ if (mode === 'standards' && std.submit(e)) return;
245
+ e.preventDefault();
246
+ const f = e.target;
247
+ try {
248
+ data = await api('PUT', `/quality?period=${period}`, { enabled: f.enabled.checked, watchDays: Number(f.watchDays.value) });
249
+ toast?.('Saved');
250
+ } catch (err) {
251
+ return toast?.(err.message, 6000);
252
+ }
253
+ document.activeElement?.blur();
254
+ render();
255
+ });
256
+
257
+ function open() {
258
+ if (dialog.open) return dialog.close();
259
+ dialog.showModal();
260
+ render();
261
+ load();
262
+ std.load();
263
+ }
264
+
265
+ /** The daemon says something changed: look again, while open. */
266
+ function changed() {
267
+ if (!dialog.open) return;
268
+ clearTimeout(again);
269
+ again = setTimeout(() => (load(), std.load()), 800);
270
+ }
271
+
272
+ expandable(dialog, render);
273
+ return { open, changed, isOpen: () => dialog.open };
274
+ }
@@ -70,6 +70,16 @@ export function scorecardHtml(doc, esc, { stale = false, actions = '' } = {}) {
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>`
71
71
  : '';
72
72
  const f = sc.facts;
73
+ // The repository's standards (Quality, Standards): the bar the app ran, its lessons, high-risk paths touched.
74
+ const barBad = (sc.bar?.results ?? []).filter((r) => !r.ok);
75
+ const bar = sc.bar
76
+ ? `<details class="sc-crit" ${barBad.length ? 'open' : ''}><summary>Quality bar, run by the app: ${sc.bar.results.length - barBad.length} of ${sc.bar.results.length} passed</summary><ul>${sc.bar.results.map((r) => `<li class="${r.ok ? 'met' : 'not_met'}">${r.ok ? '✅' : '❌'} ${esc(r.name)}${r.command ? ` <code>${esc(r.command)}</code>` : ''}${!r.ok && r.tail ? `<pre class="sc-tail">${esc(r.tail)}</pre>` : ''}</li>`).join('')}</ul></details>`
77
+ : '';
78
+ const lessonMark = { followed: '✅', broken: '❌', not_applicable: '➖', unverified: '❔' };
79
+ const lessons = sc.lessons?.length
80
+ ? `<details class="sc-crit" ${sc.lessons.some((l) => l.status === 'broken') ? 'open' : ''}><summary>Lessons of this repository: ${sc.lessons.filter((l) => l.status === 'broken').length} not followed, ${sc.lessons.filter((l) => l.status === 'followed').length} followed, of ${sc.lessons.length}</summary><ul>${sc.lessons.map((l) => `<li class="${l.status === 'broken' ? 'not_met' : l.status === 'followed' ? 'met' : ''}">${lessonMark[l.status] ?? '❔'} ${esc(l.text)}${l.evidence ? ` <span class="hint">${esc(l.evidence)}</span>` : ''}</li>`).join('')}</ul></details>`
81
+ : '';
82
+ const risk = f.risk?.length ? `<p class="sc-risk"><b>High-risk paths touched</b>: ${f.risk.map((p) => `<code>${esc(p)}</code>`).join(', ')} <span class="hint">yours to approve and merge</span></p>` : '';
73
83
  return `<div class="scorecard">
74
84
  <div class="sc-head">
75
85
  <span class="sc-overall ${recTone[sc.recommendation]}"><b>${sc.overall ?? '—'}</b><small>/100</small>${delta(doc)}</span>
@@ -78,7 +88,7 @@ export function scorecardHtml(doc, esc, { stale = false, actions = '' } = {}) {
78
88
  </div>
79
89
  ${stale ? '<p class="hint sc-stale"><b>The changes moved since this was scored.</b> Score again for the latest.</p>' : ''}
80
90
  <div class="sc-rows">${rows}</div>
81
- ${crit}${look}
91
+ ${risk}${bar}${lessons}${crit}${look}
82
92
  <div class="hint sc-facts">Measured: ${f.files} files (+${f.added} −${f.removed}) · ${f.testFiles} test files · CI ${esc(f.ci ?? 'n/a')} · checks ${f.checks.passed}✓ ${f.checks.failed}✗${f.plan ? ` · plan ${f.plan.done}/${f.plan.steps}` : ''}${doc.writer ? ` · scored by ${esc(doc.writer)}` : ''}</div>
83
93
  </div>`;
84
94
  }
@@ -0,0 +1,159 @@
1
+ // Standards, inside the Quality view: what every change in a repository has to meet. Lessons from
2
+ // what went wrong (proposed from the merged pull requests that had a problem, yours to word and
3
+ // accept), the paths that are high risk, and the checks the app runs itself before a change is scored.
4
+
5
+ const SAVED = 'agentmgr.standardsRepo';
6
+
7
+ export function initStandards({ api, esc, toast, rerender }) {
8
+ let data = null;
9
+ let repoKey = null;
10
+ let busy = null; // a lesson being worded by a model
11
+ try {
12
+ repoKey = localStorage.getItem(SAVED);
13
+ } catch {}
14
+
15
+ async function load() {
16
+ try {
17
+ data = await api('GET', '/standards');
18
+ // The one being looked at stays, whatever the order becomes (the ones with proposals come first).
19
+ if (!data.repos.some((r) => r.key === repoKey)) repoKey = data.repos[0]?.key ?? null;
20
+ } catch (e) {
21
+ toast?.(e.message, 5000);
22
+ }
23
+ rerender();
24
+ }
25
+
26
+ const repo = () => data?.repos.find((r) => r.key === repoKey) ?? data?.repos[0] ?? null;
27
+ const proposed = () => (data?.repos ?? []).reduce((n, r) => n + r.proposed.length, 0);
28
+
29
+ const source = (s) =>
30
+ s ? `<div class="hint">${s.url ? `<a href="${esc(s.url)}" target="_blank" rel="noopener">#${esc(s.number ?? '?')} ${esc(s.title ?? '')}</a>` : esc(s.title ?? '')}${s.detail ? ` · ${esc(s.detail)}` : ''}</div>` : '';
31
+
32
+ function lessonsHtml(r) {
33
+ const prop = r.proposed
34
+ .map(
35
+ (l) => `<li class="std-proposed" data-std-lesson="${esc(l.id)}">
36
+ ${source(l.source)}
37
+ <div class="std-line">
38
+ <input type="text" maxlength="300" value="${esc(l.text)}" placeholder="What should agents do differently here? One line." aria-label="The lesson" />
39
+ <button type="button" class="small" data-std="draft" ${busy === l.id ? 'disabled' : ''} title="Have a model word it from the pull request and what followed; yours to change">${busy === l.id ? 'Wording…' : 'Suggest wording'}</button>
40
+ <button type="button" class="small primary" data-std="accept" title="Every later agent in this repository is given it, and the scorecard checks it">Accept</button>
41
+ <button type="button" class="small ghost" data-std="dismiss" title="Nothing to learn from this one">Dismiss</button>
42
+ </div></li>`,
43
+ )
44
+ .join('');
45
+ const acc = r.lessons
46
+ .map((l) => `<li data-std-lesson="${esc(l.id)}"><div class="std-line"><span class="std-text">${esc(l.text)}</span><button type="button" class="link" data-std="remove" title="Agents are no longer given it">Remove</button></div>${source(l.source)}</li>`)
47
+ .join('');
48
+ return `<section class="std-section">
49
+ <h3>Lessons <span class="hint">${r.lessons.length} of ${data.limits.lessons}</span></h3>
50
+ <p class="hint">One line each. Every later agent in this repository is told to follow them, and the review scorecard checks each one against the changes: a lesson not followed means "Not ready".</p>
51
+ ${prop ? `<h4>Proposed, from pull requests that had a problem</h4><ul class="std-list">${prop}</ul>` : ''}
52
+ ${acc ? `<ul class="std-list">${acc}</ul>` : prop ? '' : '<p class="hint">No lessons yet. One is proposed here whenever a merged pull request is reverted, fixed afterwards, fails its checks or had changes requested.</p>'}
53
+ <form data-std-form="lesson" class="std-line"><input type="text" name="text" maxlength="300" required placeholder="Add a lesson: e.g. Every new endpoint checks the caller's permissions in a test" aria-label="A new lesson" /><button class="small">Add lesson</button></form>
54
+ </section>`;
55
+ }
56
+
57
+ function riskHtml(r) {
58
+ return `<section class="std-section">
59
+ <h3>High-risk paths <span class="hint">${r.risk.length}</span></h3>
60
+ <p class="hint">A change that touches one is never opened or merged by autopilot or on its Eval without you, is reviewed by another model, and cannot be scored "Ready to approve". Agents are told to say what they will change there before they do. <code>*</code> stays inside a folder, <code>**</code> crosses folders, a name without a slash fits at any depth.</p>
61
+ ${r.risk.length ? `<ul class="std-list">${r.risk.map((x) => `<li><div class="std-line"><code class="std-text">${esc(x.pattern)}</code><span class="hint">${esc(x.why)}</span><button type="button" class="link" data-std="unrisk" data-pattern="${esc(x.pattern)}">Remove</button></div></li>`).join('')}</ul>` : ''}
62
+ <form data-std-form="risk" class="std-line"><input type="text" name="pattern" maxlength="200" required placeholder="src/auth/** or **/migrations/** or *.sql" aria-label="A path pattern" /><input type="text" name="why" maxlength="200" placeholder="Why (optional)" aria-label="Why it is high risk" /><button class="small">Mark high risk</button></form>
63
+ </section>`;
64
+ }
65
+
66
+ function barHtml(r) {
67
+ const b = r.bar;
68
+ return `<section class="std-section">
69
+ <h3>Quality bar <span class="hint">${b.checks.length + (b.tests ? 1 : 0) + (b.secrets ? 1 : 0)} checks</span></h3>
70
+ <p class="hint">Run by the app on an agent's changes, in its folder, before they are scored. A failed check means "Not ready" whatever the agent says, and on autopilot the work goes back to the agent with the output. Each command gets ${Math.round(data.limits.checkSeconds / 60)} minutes.</p>
71
+ <label class="check"><input type="checkbox" data-std-bar="tests" ${b.tests ? 'checked' : ''} /> Code changes need a test file changed too</label>
72
+ <label class="check"><input type="checkbox" data-std-bar="secrets" ${b.secrets ? 'checked' : ''} /> No keys or tokens on the added lines</label>
73
+ ${b.checks.length ? `<ul class="std-list">${b.checks.map((c) => `<li><div class="std-line"><b>${esc(c.name)}</b><code class="std-text">${esc(c.command)}</code><button type="button" class="link" data-std="uncheck" data-name="${esc(c.name)}">Remove</button></div></li>`).join('')}</ul>` : ''}
74
+ ${r.suggested.length ? `<p class="hint">Found in this repository: ${r.suggested.map((c) => `<button type="button" class="chip" data-std="suggest" data-name="${esc(c.name)}" data-command="${esc(c.command)}" title="Add this check">+ ${esc(c.name)}: ${esc(c.command)}</button>`).join(' ')}</p>` : ''}
75
+ <form data-std-form="check" class="std-line"><input type="text" name="label" maxlength="60" placeholder="Name: Lint" aria-label="The check's name" class="std-short" /><input type="text" name="command" maxlength="500" required placeholder="Command: npm run lint" aria-label="The command" /><button class="small">Add check</button></form>
76
+ </section>`;
77
+ }
78
+
79
+ function html() {
80
+ if (!data) return '<p class="hint">Loading…</p>';
81
+ const r = repo();
82
+ if (!r) return '<p class="hint issues-empty">Standards are per repository. Start an agent in one, and it shows here.</p>';
83
+ return `<div class="std">
84
+ <p class="std-repo"><label>Repository <select data-std-repo aria-label="Repository">${data.repos.map((x) => `<option value="${esc(x.key)}" ${x.key === r.key ? 'selected' : ''}>${esc(x.name)}${x.proposed.length ? ` (${x.proposed.length} proposed)` : ''}</option>`).join('')}</select></label>
85
+ <span class="hint">${r.agents} agent${r.agents === 1 ? '' : 's'} here now · what is set applies to agents started from now on, and to every change scored from now on</span></p>
86
+ ${data.enabled ? '' : '<p class="hint"><b>Standards are turned off</b> in config.json ("standards": { "enabled": false }): nothing below is applied.</p>'}
87
+ ${lessonsHtml(r)}${riskHtml(r)}${barHtml(r)}
88
+ </div>`;
89
+ }
90
+
91
+ const save = async (fn, said) => {
92
+ try {
93
+ await fn();
94
+ if (said) toast?.(said);
95
+ } catch (e) {
96
+ toast?.(e.message, 6000);
97
+ }
98
+ document.activeElement?.blur();
99
+ return load();
100
+ };
101
+
102
+ /** A click inside the view; true when it was one of ours. */
103
+ function click(e) {
104
+ const b = e.target.closest('[data-std]');
105
+ const r = repo();
106
+ if (!b || !r) return false;
107
+ const act = b.dataset.std;
108
+ const li = b.closest('[data-std-lesson]');
109
+ const id = li?.dataset.stdLesson;
110
+ const text = li?.querySelector('input')?.value.trim();
111
+ if (act === 'accept') {
112
+ if (!text) return toast?.('Word the lesson first: one line', 4000), true;
113
+ save(() => api('PUT', `/standards/lessons/${id}`, { key: r.key, state: 'accepted', text }), 'Accepted: agents started from now on are given it');
114
+ } else if (act === 'dismiss' || act === 'remove') save(() => api('DELETE', `/standards/lessons/${id}?key=${encodeURIComponent(r.key)}`));
115
+ else if (act === 'draft') {
116
+ busy = id;
117
+ rerender(true);
118
+ save(() => api('POST', `/standards/lessons/${id}/draft`, { key: r.key })).finally(() => {
119
+ busy = null;
120
+ rerender(true);
121
+ });
122
+ } else if (act === 'unrisk') save(() => api('PUT', '/standards/repo', { key: r.key, risk: r.risk.filter((x) => x.pattern !== b.dataset.pattern) }));
123
+ else if (act === 'uncheck') save(() => api('PUT', '/standards/repo', { key: r.key, bar: { checks: r.bar.checks.filter((c) => c.name !== b.dataset.name) } }));
124
+ else if (act === 'suggest') save(() => api('PUT', '/standards/repo', { key: r.key, bar: { checks: [...r.bar.checks, { name: b.dataset.name, command: b.dataset.command }] } }), `Added: ${b.dataset.name}`);
125
+ return true;
126
+ }
127
+
128
+ function change(e) {
129
+ const r = repo();
130
+ if (e.target.matches('[data-std-repo]')) {
131
+ repoKey = e.target.value;
132
+ try {
133
+ localStorage.setItem(SAVED, repoKey);
134
+ } catch {}
135
+ e.target.blur();
136
+ rerender(true);
137
+ return true;
138
+ }
139
+ if (e.target.matches('[data-std-bar]') && r) {
140
+ save(() => api('PUT', '/standards/repo', { key: r.key, bar: { [e.target.dataset.stdBar]: e.target.checked } }));
141
+ return true;
142
+ }
143
+ return false;
144
+ }
145
+
146
+ function submit(e) {
147
+ const f = e.target.closest('[data-std-form]');
148
+ const r = repo();
149
+ if (!f || !r) return false;
150
+ e.preventDefault();
151
+ const kind = f.dataset.stdForm;
152
+ if (kind === 'lesson') save(() => api('POST', '/standards/lessons', { key: r.key, text: f.text.value }), 'Added: agents started from now on are given it');
153
+ else if (kind === 'risk') save(() => api('PUT', '/standards/repo', { key: r.key, risk: [...r.risk, { pattern: f.pattern.value, why: f.why.value }] }));
154
+ else if (kind === 'check') save(() => api('PUT', '/standards/repo', { key: r.key, bar: { checks: [...r.bar.checks, { name: f.label.value, command: f.command.value }] } }));
155
+ return true;
156
+ }
157
+
158
+ return { load, html, click, change, submit, proposed, loaded: () => Boolean(data) };
159
+ }
package/public/style.css CHANGED
@@ -1690,6 +1690,12 @@ table.os-table .num { text-align: right; font-variant-numeric: tabular-nums; whi
1690
1690
  .value-legend { margin: 6px 0 10px; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
1691
1691
  .value-legend .sw { display: inline-block; width: 10px; height: 10px; border-radius: 2px; }
1692
1692
  .value-legend .sw.val { background: var(--accent); }
1693
+ .value-bar .bad, .value-legend .sw.bad { background: var(--red); }
1694
+ .value-bar .bad { border-radius: 3px 3px 0 0; }
1695
+ .quality-chip { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 12px; white-space: nowrap; border: 1px solid var(--border); }
1696
+ .quality-chip.clean, .quality-chip.watching { color: var(--green); border-color: color-mix(in srgb, var(--green) 50%, transparent); }
1697
+ .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); }
1698
+ .quality-chip.unchecked { color: var(--muted); }
1693
1699
  .value-legend .sw.rev { background: color-mix(in srgb, var(--green) 70%, transparent); }
1694
1700
  table.value-items td.mine { color: var(--accent); font-weight: 600; }
1695
1701
  table.value-items tr.excluded td { opacity: 0.5; text-decoration: line-through; }
@@ -1698,6 +1704,23 @@ table.value-items tr.value-edit td { background: var(--panel-2); }
1698
1704
  .value-fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 8px; }
1699
1705
  .value-fields input::placeholder { color: var(--muted); opacity: 0.8; }
1700
1706
  .value-settings { margin-top: 14px; }
1707
+ .sc-risk { margin: 8px 0; color: var(--red); }
1708
+ .sc-risk code, .sc-risk .hint { color: var(--text, inherit); }
1709
+ .sc-tail { max-height: 180px; overflow: auto; font-size: 12px; white-space: pre-wrap; margin: 4px 0 0; }
1710
+ .std-repo { display: flex; flex-wrap: wrap; gap: 8px 14px; align-items: center; margin: 4px 0 6px; }
1711
+ .std-section { border-top: 1px solid var(--border); padding: 10px 0 12px; }
1712
+ .std-section h3 { margin: 0 0 4px; font-size: 15px; }
1713
+ .std-section h4 { margin: 10px 0 4px; font-size: 13px; }
1714
+ .std-section .check { display: flex; gap: 8px; align-items: center; margin: 4px 0; }
1715
+ .std-section .check input[type=checkbox] { width: auto; }
1716
+ .std-repo select { width: auto; max-width: 100%; }
1717
+ .std-list { list-style: none; margin: 6px 0; padding: 0; }
1718
+ .std-list li { padding: 6px 0; border-bottom: 1px dashed var(--border); }
1719
+ .std-proposed { background: color-mix(in srgb, var(--accent) 6%, transparent); padding: 8px !important; border-radius: 6px; margin-bottom: 6px; }
1720
+ .std-line { display: flex; flex-wrap: wrap; gap: 6px 8px; align-items: center; }
1721
+ .std-line input[type="text"] { flex: 1 1 220px; min-width: 0; max-width: 100%; box-sizing: border-box; margin: 0; }
1722
+ .std-line input.std-short { flex: 0 1 140px; }
1723
+ .std-line .std-text { flex: 1 1 220px; min-width: 0; overflow-wrap: anywhere; }
1701
1724
  .value-settings summary { cursor: pointer; font-weight: 600; }
1702
1725
  .value-report-kinds { display: flex; flex-wrap: wrap; gap: 4px 14px; align-items: center; }
1703
1726
  .value-report-kinds input[type="time"] { width: auto; }
@@ -1864,3 +1887,20 @@ table.eval-items tr.eval-na td { color: var(--muted); }
1864
1887
  .screen-tap { position: fixed; width: 28px; height: 28px; margin: -14px 0 0 -14px; border: 2px solid #4c8dff; border-radius: 50%; pointer-events: none; z-index: 5; animation: screen-tap 0.45s ease-out forwards; }
1865
1888
  @keyframes screen-tap { from { transform: scale(0.4); opacity: 1; } to { transform: scale(1.4); opacity: 0; } }
1866
1889
  @media (max-width: 800px) { .needs.inbox.one .need-actions button { padding: 10px 14px; font-size: 15px; } }
1890
+
1891
+ /* Claims check (claims.js): statements of fact and what backs them. */
1892
+ .cl-counts { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0; }
1893
+ .cl-chip { display: inline-block; padding: 1px 8px; border-radius: 10px; border: 1px solid var(--border); font-size: 12px; white-space: nowrap; }
1894
+ .cl-chip.cl-contradicted { border-color: var(--red); color: var(--red); font-weight: 600; }
1895
+ .cl-chip.cl-not_backed { border-color: var(--yellow); color: var(--yellow); font-weight: 600; }
1896
+ .cl-chip.cl-backed { border-color: var(--green); color: var(--green); }
1897
+ .cl-group { margin: 8px 0; }
1898
+ .cl-group summary { cursor: pointer; }
1899
+ .cl-list { list-style: none; margin: 6px 0 0; padding: 0; }
1900
+ .cl-claim { border-left: 3px solid var(--border); padding: 4px 0 4px 10px; margin: 6px 0; overflow-wrap: anywhere; }
1901
+ .cl-claim.cl-contradicted { border-left-color: var(--red); }
1902
+ .cl-claim.cl-not_backed { border-left-color: var(--yellow); }
1903
+ .cl-claim.cl-backed { border-left-color: var(--green); }
1904
+ .cl-quote { margin-top: 2px; }
1905
+ .cl-note { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin: 6px 0; }
1906
+ .cl-note.cl-doubt { border: 1px solid var(--yellow); border-radius: 8px; padding: 6px 10px; }
package/src/autopilot.js CHANGED
@@ -99,11 +99,18 @@ export class Autopilot {
99
99
  if (agent.preReview?.status === 'stalled') return this.hold(it, `The review rounds did not approve its changes (${agent.preReview.round} ${agent.preReview.round === 1 ? 'round' : 'rounds'}): see what is still open on the agent.`);
100
100
  if (pr?.state === 'CLOSED') return this.hold(it, 'Its pull request was closed without merging.');
101
101
  // Shipped in this round of review: see it through. Reopened since: the new work is scored and pushed to it.
102
- if (pr && ap.shipped === it.reviewAt) return level === 'merge' ? this.land(it, agent, pr) : undefined;
102
+ if (pr && ap.shipped === it.reviewAt) return level === 'merge' && !ap.risk ? this.land(it, agent, pr) : undefined;
103
103
 
104
104
  // Not shipped yet: the scorecard of the current changes decides (unless you said Ship it).
105
105
  const changes = await this.review.get(agent.id);
106
106
  if (!changes.files?.length) return this.hold(it, 'There are no changes to ship.');
107
+ // Under a path you marked high risk (standards.js): yours to approve, and never merged from here.
108
+ const risk = this.manager.standards?.riskIn(agent, changes.files) ?? [];
109
+ if (risk.length) {
110
+ if (ap.ship) return this.ship(it, agent, 'pr', { risk: true });
111
+ const paths = `${risk.slice(0, 3).map((r) => r.path).join(', ')}${risk.length > 3 ? ` and ${risk.length - 3} more` : ''}`;
112
+ return this.hold(it, `It changes high-risk paths (${paths}), so it is yours to approve. Ship it opens the pull request; merging it stays with you.`);
113
+ }
107
114
  if (ap.ship) return this.ship(it, agent, level);
108
115
  const card = agent.docs?.scorecard;
109
116
  if (card?.pending) return;
@@ -141,7 +148,7 @@ export class Autopilot {
141
148
  }
142
149
 
143
150
  /** Commit what's left, push and open the pull request; at "merge", landing takes it from there. */
144
- async ship(it, agent, level) {
151
+ async ship(it, agent, level, { risk = false } = {}) {
145
152
  this.note(it, { state: 'shipping', note: null });
146
153
  const title = it.title.split('\n')[0].slice(0, 100);
147
154
  try {
@@ -152,7 +159,7 @@ export class Autopilot {
152
159
  const { url } = await this.review.pr(agent.id, { title });
153
160
  if (!url) throw err(502, 'Pushed, but no pull request link came back.');
154
161
  this.log(`autopilot: opened ${url} for "${it.title}"`);
155
- this.note(it, { state: level === 'merge' ? 'landing' : 'pr', pr: url, shipped: it.reviewAt, ship: false });
162
+ this.note(it, { state: level === 'merge' ? 'landing' : 'pr', pr: url, shipped: it.reviewAt, ship: false, risk });
156
163
  await this.manager.refresh(agent.id, { withPrs: true }).catch(() => {});
157
164
  }
158
165