ai-agentmanager 1.60.0 → 1.61.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,20 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.61.0 (2026-11-19)
4
+
5
+ - **Quality: what happened after the merge.** A new view (top bar, or `Q`) shows what became of the agents' pull requests once they merged: the share that held up, and the ones reverted, fixed afterwards, or with failed checks on the commit they merged as. From before the merge it shows how many had a reviewer ask for changes and the median time from opened to merged. By day, week, month, quarter and year, with the change against the period before.
6
+ - **How it knows.** Each merged pull request is watched for 14 days (1 to 90, in its settings). GitHub is asked through the `gh` CLI as you, a few pull requests every two minutes and each again every six hours. No model is called.
7
+ - **A guess you can overrule.** "Fixed afterwards" is a later pull request whose title says it fixes something and that changes one of the same files, or names it. **Not a problem** overrules it, **It was a problem** records one nothing here saw, **Undo** goes back.
8
+ - **Also:** `agentmgr quality` (`show`, `mark`, `report`, `set`), **Copy report** as Markdown, and **Only the ones with a problem**.
9
+ - **Standards: what every change in a repository has to meet.** A second tab in Quality, per repository, with three parts. `agentmgr standards` (`show`, `lesson`, `risk`, `bar`, `run`) does the same from a terminal. Only you set them: an agent's own calls are refused.
10
+ - **Lessons that stick.** A lesson is proposed whenever a merged pull request is reverted, fixed afterwards, fails its checks or had changes requested. You word it in one line (**Suggest wording** asks a model, from the pull request and what reviewers wrote) and accept or dismiss it; you can also add your own. Agents started in that repository from then on are told to follow the accepted ones, and the review scorecard checks each against the changes: one not followed means "Not ready", and Improve sends it back to the agent.
11
+ - **High-risk paths.** Mark paths such as `src/auth/**`, `**/migrations/**` or `*.sql`. A change that touches one cannot be scored "Ready to approve", is held by autopilot for you (Ship it opens the pull request; autopilot never merges it), is not merged on its Eval, and is reviewed by another model when the agent finishes, also with review rounds turned off. Agents are told which paths they are and to say what they will change there before they do.
12
+ - **A quality bar the app runs itself.** Per repository: your commands (lint, types, tests, a dependency scan), "code changes need a test file changed too", and "no keys or tokens on the added lines". They run in the agent's folder before its changes are scored, once per state of the changes. A failed check caps the Tests score at 30 and means "Not ready" whatever the agent says; its output goes back to the agent. Commands found in the repository (`npm run lint`, `go vet ./...` and the like) are offered with one click.
13
+ - **Changed for everyone:** the scan for keys and tokens is on for every repository unless you turn it off there, so a change that adds something that looks like one is now "Not ready".
14
+ - **Limits:** the scorecard's check of a lesson is a model's reading of the diff. The instruction to describe a high-risk change first is an instruction, not a gate; the gates are at shipping and merging. Coverage of changed lines is not measured unless one of your commands does it. The bar's commands run on this computer as you, not in a sandbox.
15
+ - **Tests:** a test that fails with a connection left open no longer keeps `npm test` running for ever; the run ends and shows the failure.
16
+ - **Tried:** in desktop Chrome with stand-ins for GitHub and the model. The lookups were tried read-only against this repository's own merged pull requests. Not yet with real agents, and not on a phone.
17
+
3
18
  ## 1.60.0 (2026-11-19)
4
19
 
5
20
  - **Value: pull requests merged.** Next to the value delivered, how many pull requests merged in the period and how many a day, with the change against the period before. Each counts in the period it merged in, so a second pull request on the same work is counted when it lands. It is on the page, in `agentmgr value`, in the report (Markdown and Slack) and as a `pull_requests` column at the end of `value.csv`.
package/README.md CHANGED
@@ -1197,6 +1197,64 @@ agentmgr value report --kind quarter --current # this quarter so far, as Markd
1197
1197
  agentmgr value set --rate 140 --reports weekly,monthly,quarterly --at 08:30 --drive on
1198
1198
  ```
1199
1199
 
1200
+ ## Quality: what happened after the merge
1201
+
1202
+ **Quality** in the top bar (or `Q`) shows what became of the agents' pull requests once they merged, by **Day**, **Week**, **Month**, **Quarter** or **Year**. Merging more is only good news if it holds up, so this sits next to the pull request count in Value.
1203
+
1204
+ | Figure | What it is |
1205
+ |---|---|
1206
+ | Held up | The share of the merged pull requests looked at that had no problem after the merge |
1207
+ | Reverted | A later pull request titled Revert that names it, or a commit that reverts the commit it merged as |
1208
+ | Fixed afterwards | A later pull request, within the days watched, whose title says it fixes something and that changes one of the same files or names it |
1209
+ | Checks failed | A check failed or timed out on the commit it merged as (a cancelled run is not a failure) |
1210
+ | Changes requested | How many had a reviewer ask for changes before the merge |
1211
+ | Opened to merged | Median hours from opening the pull request to merging it |
1212
+
1213
+ Each pull request is watched for 14 days after it merges (set it from 1 to 90). GitHub is asked through the `gh` CLI as you: a few pull requests every two minutes, and each again every six hours while it is watched. No model is called.
1214
+
1215
+ **Fixed afterwards is a guess**, from titles and files: a fix in the same file may be about something else. **Not a problem** on a pull request overrules what was found, **It was a problem** records one nothing here saw, and **Undo** goes back; yours are marked. **Look again** asks GitHub now. **Only the ones with a problem** narrows the list, and **Copy report** gives the period as Markdown.
1216
+
1217
+ It covers pull requests of agents here, from about 100 days before you first opened it. A problem that never showed on GitHub (an incident fixed elsewhere, a bug nobody linked) is not seen unless you mark it.
1218
+
1219
+ ```bash
1220
+ agentmgr quality --period month # the share that held up, by month
1221
+ agentmgr quality mark https://github.com/acme/shop/pull/77 --clean --note "the fix was about another bug"
1222
+ agentmgr quality report --kind month # last month, as Markdown
1223
+ agentmgr quality set --days 30 # watch each merge for 30 days
1224
+ ```
1225
+
1226
+ ## Standards: what every change in a repository has to meet
1227
+
1228
+ The **Standards** tab in Quality (or `agentmgr standards`) holds, per repository, the rules that turn what went wrong before into how agents work next. Only you set them; an agent's own calls to change them are refused.
1229
+
1230
+ **Lessons.** Whenever a merged pull request is reverted, fixed afterwards, fails its checks or had changes requested by a reviewer, a lesson is proposed for its repository. Word it in one line, or use **Suggest wording** to have a model draft it from the pull request and what reviewers wrote, then **Accept** or **Dismiss**. You can add your own too. Accepted lessons (at most 40 per repository) are given to every agent started there from then on, and the review scorecard checks each one against the changes: a lesson not followed means "Not ready", and Improve sends it back to the agent.
1231
+
1232
+ **High-risk paths.** Mark the parts where a mistake is expensive: `src/auth/**`, `**/migrations/**`, `*.sql`. `*` stays inside a folder, `**` crosses folders, and a name without a slash fits at any depth. A change that touches one:
1233
+
1234
+ - cannot be scored "Ready to approve"; the scorecard says which paths it touched
1235
+ - is held by autopilot for you. **Ship it** opens the pull request, and autopilot never merges it
1236
+ - is not merged on its Eval ("merge when sure")
1237
+ - is reviewed by another model when the agent finishes, also with review rounds turned off; the pull request is then yours to open
1238
+
1239
+ Agents are told which paths are high risk and to say in their brief what they will change there before they do.
1240
+
1241
+ **The quality bar.** Checks the app runs itself, in the agent's folder, before its changes are scored:
1242
+
1243
+ - your commands, each with a name: lint, a type check, the tests, a dependency scan. Commands found in the repository are offered with one click
1244
+ - code changes need a test file changed too (off by default)
1245
+ - no keys or tokens on the added lines (on by default, for every repository)
1246
+
1247
+ A failed check caps the Tests score at 30 and means "Not ready" whatever the agent says, and on autopilot the work goes back to the agent with the check's output. The bar runs once per state of the changes; `agentmgr standards run <agent>` runs it now. Each command gets 10 minutes (`"standards": { "checkTimeoutMs": 600000 }` in `config.json`), and runs on this computer as you. `"standards": { "enabled": false }` turns all of it off.
1248
+
1249
+ ```sh
1250
+ agentmgr standards # every repository: lessons, high-risk paths, the bar
1251
+ agentmgr standards lesson shop "Exports are paged, never loaded whole"
1252
+ agentmgr standards lesson shop --accept 3fa2c1d0 "Rotate tokens behind a flag"
1253
+ agentmgr standards risk shop "src/auth/**" "**/migrations/**" --why "sign-in and data"
1254
+ agentmgr standards bar shop --add "Lint=npm run lint" --add "Types=npx tsc --noEmit" --tests
1255
+ agentmgr standards run my-agent # run the bar on its changes now
1256
+ ```
1257
+
1200
1258
  ## Results and spend
1201
1259
 
1202
1260
  **Results** in the top bar shows how agents did over the last 7, 30 or 90 days (or all time): how many started and how many opened a pull request, PRs merged and closed, the merge rate, the median time from starting an agent to its first PR and to merge, and the cost per merged PR. The same by engine and model (which one gets merged more, for less), by where agents came from (you, the assistant, triggers, the backlog, teams, races) and by project. `agentmgr stats --days 30`.
@@ -68,4 +68,4 @@ Design notes: [distributed.md](distributed.md) (hub) and [engines.md](engines.md
68
68
 
69
69
  ## Tests
70
70
 
71
- `test/e2e.test.js` starts a real daemon on a temporary home and port, with fake engines that print what the real CLIs print. `test/unit.test.js` covers parsers and pure functions. CI runs both on macOS and Linux, Node 20 and 22.
71
+ `test/e2e.test.js` starts a real daemon on a temporary home and port, with fake engines that print what the real CLIs print. `test/unit.test.js` covers parsers and pure functions. CI runs them on macOS and Linux, Node 20 and 22, on every push to `main` and nightly. A pull request runs the basic set (the whole suite once, on Linux with Node 22, and the package check); the label `full-ci` on it, for a big change or a release, runs all four.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ai-agentmanager",
3
- "version": "1.60.0",
3
+ "version": "1.61.0",
4
4
  "description": "Run background coding agents (Claude Code, Codex) per intent, and keep track of them from a web UI, your phone or the CLI",
5
5
  "keywords": [
6
6
  "claude",
package/public/app.js CHANGED
@@ -40,6 +40,7 @@ import { initReviews } from '/reviews.js';
40
40
  import { initBugHunt } from '/bughunt.js';
41
41
  import { drawDiagram } from '/diagram.js';
42
42
  import { initValue } from '/value.js';
43
+ import { initQuality } from '/quality.js';
43
44
  import { initNews } from '/news.js';
44
45
  import { initPlan } from '/plan.js';
45
46
  import { initSystem } from '/system.js';
@@ -78,6 +79,7 @@ const watchOnLoad = hashId === 'watch';
78
79
  const standupOnLoad = hashId === 'standup';
79
80
  const mapOnLoad = hashId === 'map';
80
81
  const valueOnLoad = hashId === 'value';
82
+ const qualityOnLoad = hashId === 'quality';
81
83
  const newsOnLoad = hashId === 'news';
82
84
  // "#plan" or "#plan/<dates|decisions|debt>".
83
85
  const planOnLoad = hashId === 'plan';
@@ -89,7 +91,7 @@ const reviewsOnLoad = hashId === 'reviews';
89
91
  // "#mcp" or "#mcp/<agent>": the MCP window on its own.
90
92
  const mcpOnLoad = hashId === 'mcp';
91
93
  let watchShown = false;
92
- let selectedId = (watchOnLoad || standupOnLoad || mapOnLoad || valueOnLoad || newsOnLoad || planOnLoad || osOnLoad || boardOnLoad || decideOnLoad || reviewsOnLoad || mcpOnLoad ? null : hashId) || null;
94
+ let selectedId = (watchOnLoad || standupOnLoad || mapOnLoad || valueOnLoad || qualityOnLoad || newsOnLoad || planOnLoad || osOnLoad || boardOnLoad || decideOnLoad || reviewsOnLoad || mcpOnLoad ? null : hashId) || null;
93
95
  let openTermOnLoad = hashView === 'term' || hashView === 'code' || isShell(hashView) || isBrowser(hashView);
94
96
  let filterText = '';
95
97
  // Only agents whose session is open (the "running" count above the list, clicked).
@@ -325,6 +327,9 @@ $('#bugs-btn').onclick = () => bugsUi.open();
325
327
  // Value: what the delivered work is worth, for you and for management.
326
328
  const valueUi = initValue({ api, $, esc, toast: (m, ms) => toast(m, ms), openAgent: (id) => (showTab('agents'), select(id)) });
327
329
  $('#value-btn').onclick = () => valueUi.open();
330
+ // Quality: what happened to the agents' pull requests after they merged.
331
+ const qualityUi = initQuality({ api, $, esc, toast: (m, ms) => toast(m, ms), ago: (t) => ago(t), openAgent: (id) => (showTab('agents'), select(id)) });
332
+ $('#quality-btn').onclick = () => qualityUi.open();
328
333
  // AI News: the frontier labs' latest releases, summarized.
329
334
  const newsUi = initNews({ api, $, esc, ago, toast: (m, ms) => toast(m, ms) });
330
335
  $('#news-btn').onclick = () => newsUi.open();
@@ -434,6 +439,7 @@ function shortcut(act) {
434
439
  if (act === 'reviews') return reviewsUi.open();
435
440
  if (act === 'bugs') return bugsUi.open();
436
441
  if (act === 'value') return valueUi.open();
442
+ if (act === 'quality') return qualityUi.open();
437
443
  if (act === 'news') return newsUi.open();
438
444
  if (act === 'plan') return planUi.open();
439
445
  if (act === 'os') return osUi.open();
@@ -4695,6 +4701,11 @@ function handleEvent(msg) {
4695
4701
  history.replaceState(null, '', '#');
4696
4702
  valueUi.open();
4697
4703
  }
4704
+ if (qualityOnLoad && !watchShown) {
4705
+ watchShown = true;
4706
+ history.replaceState(null, '', '#');
4707
+ qualityUi.open();
4708
+ }
4698
4709
  if (planOnLoad && !watchShown) {
4699
4710
  watchShown = true;
4700
4711
  history.replaceState(null, '', '#');
@@ -4769,6 +4780,8 @@ function handleEvent(msg) {
4769
4780
  teams.delete(msg.id);
4770
4781
  } else if (msg.t === 'value') {
4771
4782
  valueUi.changed();
4783
+ } else if (msg.t === 'quality') {
4784
+ qualityUi.changed();
4772
4785
  } else if (msg.t === 'news') {
4773
4786
  newsUi.changed();
4774
4787
  } else if (msg.t === 'usage') {
package/public/index.html CHANGED
@@ -42,6 +42,7 @@
42
42
  <button id="bugs-btn" title="Bugs: background hunts in a project or folder, and what they found, checked and worst first">Bugs <span id="bugs-count" class="badge"></span></button>
43
43
  <button id="reviews-btn" title="Reviews: pull requests you review. Reviewer agents ask the critical questions and find what blocks approval; you post what you pick">Reviews <span id="reviews-count" class="badge ready"></span></button>
44
44
  <button id="value-btn" title="Value: what the delivered work is worth, and the pull requests merged, by day, week, month, quarter and year, against the AI cost and your time; reports for management">Value</button>
45
+ <button id="quality-btn" title="Quality: what happened to the agents' pull requests after they merged: reverted, fixed afterwards, failed checks, or held up; and how often a reviewer asked for changes">Quality</button>
45
46
  <button id="decide-btn" title="Decide: what waits for you with its options and a recommendation, your standing decisions and what was decided for you, the backlog by impact, dates at risk as choices, and a look back at past decisions">Decide <span id="decide-count" class="badge"></span></button>
46
47
  <button id="plan-btn" title="Plan: a project's dates (code complete, RC, GA) with their checklists and reminders, the decision log, and the tech debt radar">Plan <span id="plan-count" class="badge"></span></button>
47
48
  <button id="news-btn" title="AI News: the frontier labs' latest releases (Anthropic, OpenAI, Google and the other top labs), each summarized, with links">AI News <span id="news-count" class="badge ready"></span></button>
@@ -430,6 +431,9 @@
430
431
  <dialog id="value-dialog" class="issues-dialog value-dialog" aria-label="Value">
431
432
  <div id="value-body"></div>
432
433
  </dialog>
434
+ <dialog id="quality-dialog" class="issues-dialog value-dialog" aria-label="Quality">
435
+ <div id="quality-body"></div>
436
+ </dialog>
433
437
  <dialog id="plan-dialog" class="issues-dialog plan-dialog" aria-label="Plan">
434
438
  <div id="plan-body"></div>
435
439
  </dialog>
package/public/keys.js CHANGED
@@ -28,6 +28,7 @@ export const SHORTCUTS = [
28
28
  [['d'], 'Designs: agents\' design docs', 'designs'],
29
29
  [['g'], 'Reviews: pull requests you review', 'reviews'],
30
30
  [['v'], 'Value: what the work is worth', 'value'],
31
+ [['Q'], 'Quality: what happened to pull requests after they merged', 'quality'],
31
32
  [['l'], 'AI News: the latest frontier releases', 'news'],
32
33
  [['c'], 'Plan: project dates, decisions and tech debt', 'plan'],
33
34
  [['u'], 'OS: this computer and its load', 'os'],
@@ -79,11 +80,11 @@ export const SHORTCUTS = [
79
80
  // A single key, as an event names it, to its action.
80
81
  export const SINGLE = {
81
82
  j: 'next', k: 'prev', Enter: 'terminal', t: 'terminal',
82
- r: 'changes', s: 'start', X: 'stop', e: 'edit', n: 'new', a: 'ask', '/': 'filter', w: 'watch', p: 'standup', m: 'map', i: 'issues', o: 'actions', h: 'assistant', ',': 'settings', d: 'designs', g: 'reviews', v: 'value', l: 'news', c: 'plan', u: 'os', B: 'board', q: 'decide', z: 'usage', y: 'today', b: 'bugs', S: 'screen', T: 'machine', '?': 'help',
83
+ r: 'changes', s: 'start', X: 'stop', e: 'edit', n: 'new', a: 'ask', '/': 'filter', w: 'watch', p: 'standup', m: 'map', i: 'issues', o: 'actions', h: 'assistant', ',': 'settings', d: 'designs', g: 'reviews', v: 'value', Q: 'quality', l: 'news', c: 'plan', u: 'os', B: 'board', q: 'decide', z: 'usage', y: 'today', b: 'bugs', S: 'screen', T: 'machine', '?': 'help',
83
84
  1: 'tab:agents', 2: 'tab:inbox', 3: 'tab:backlog', 4: 'tab:land', 5: 'tab:built',
84
85
  };
85
86
  // While Watch is open: only what makes sense there.
86
- const ON_WATCH = new Set(['today', 'new', 'ask', 'watch', 'standup', 'map', 'issues', 'actions', 'assistant', 'settings', 'designs', 'reviews', 'value', 'news', 'plan', 'os', 'board', 'decide', 'usage', 'bugs', 'screen', 'machine', 'help']);
87
+ const ON_WATCH = new Set(['today', 'new', 'ask', 'watch', 'standup', 'map', 'issues', 'actions', 'assistant', 'settings', 'designs', 'reviews', 'value', 'quality', 'news', 'plan', 'os', 'board', 'decide', 'usage', 'bugs', 'screen', 'machine', 'help']);
87
88
 
88
89
  /** Typing somewhere: a field, an editor or a terminal (xterm types through a textarea). */
89
90
  const typing = (el) => Boolean(el?.closest?.('input, textarea, select, [contenteditable=""], [contenteditable="true"], .xterm, .cm-editor'));
@@ -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
  }