@giamme/forge 0.13.0 → 0.14.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.
Files changed (60) hide show
  1. package/CHANGELOG.md +40 -0
  2. package/SKILL.md +17 -11
  3. package/VERSION +1 -1
  4. package/docs/artifacts.md +1 -0
  5. package/docs/commands.md +121 -7
  6. package/docs/development.md +3 -0
  7. package/docs/forge-ui.md +7 -1
  8. package/docs/reviews.md +2 -0
  9. package/docs/troubleshooting.md +5 -1
  10. package/forge +28 -1
  11. package/package.json +1 -1
  12. package/references/dataset.md +3 -1
  13. package/references/decision-models.md +5 -1
  14. package/references/decompose.md +199 -61
  15. package/references/runtime.md +29 -0
  16. package/references/ui.md +10 -0
  17. package/scripts/forge-compare.py +491 -0
  18. package/scripts/forge-config.py +3 -3
  19. package/scripts/forge-contract.py +34 -8
  20. package/scripts/forge-control.py +105 -13
  21. package/scripts/forge-dispatch.sh +9 -5
  22. package/scripts/forge-jev-options.sh +17 -4
  23. package/scripts/forge-ledger.py +387 -0
  24. package/scripts/forge-lib-plans.sh +16 -2
  25. package/scripts/forge-lib-task.sh +390 -28
  26. package/scripts/forge-parallel-options.sh +20 -4
  27. package/scripts/forge-parallel.sh +118 -12
  28. package/scripts/forge-plan-check.py +68 -3
  29. package/scripts/forge-pr.py +276 -0
  30. package/scripts/forge-route.py +350 -34
  31. package/scripts/forge-runs.py +18 -1
  32. package/scripts/forge-runtime.py +23 -7
  33. package/scripts/forge-schedule.py +303 -46
  34. package/scripts/forge-solo.sh +1 -0
  35. package/scripts/forge-ui-options.sh +25 -0
  36. package/scripts/forge-verify-failed.py +111 -0
  37. package/scripts/forge-watch.py +372 -0
  38. package/scripts/forge_dataset/export.py +87 -41
  39. package/scripts/forge_dataset/harvest.py +3 -1
  40. package/scripts/forge_decide/budget.py +39 -8
  41. package/scripts/forge_decide/doctor.py +49 -0
  42. package/scripts/forge_fractal/cli.py +23 -6
  43. package/scripts/forge_infra.py +274 -0
  44. package/scripts/forge_jev/client.py +13 -9
  45. package/ui/docs/api.md +83 -15
  46. package/ui/forge_ui/control.py +11 -3
  47. package/ui/forge_ui/export.py +6 -2
  48. package/ui/forge_ui/models.py +16 -16
  49. package/ui/forge_ui/reader.py +217 -13
  50. package/ui/forge_ui/repos.py +428 -0
  51. package/ui/forge_ui/static/app.js +24 -5
  52. package/ui/forge_ui/static/checksview.js +20 -7
  53. package/ui/forge_ui/static/cloudmodel.js +8 -5
  54. package/ui/forge_ui/static/controls.js +6 -3
  55. package/ui/forge_ui/static/modelstats.js +12 -8
  56. package/ui/forge_ui/static/panel.js +69 -4
  57. package/ui/forge_ui/static/runmodel.js +55 -10
  58. package/ui/forge_ui/static/scene3d.js +3 -2
  59. package/ui/forge_ui/static/settings.js +147 -29
  60. package/ui/forge_ui/static/style.css +49 -7
@@ -59,15 +59,17 @@
59
59
  function inPeriod(created, f, now) {
60
60
  return !f.days || num(now) === null || (num(created) !== null && created >= now - f.days * DAY);
61
61
  }
62
- // a run's own facts (repo, kind, created): from its task rows, else from the run summaries
62
+ // a run's own facts (repo, repo_root, kind, created): from its task rows, else from the run summaries
63
63
  function runIndex(data, runs) {
64
64
  const by = new Map();
65
- for (const t of list(data.tasks)) if (obj(t) && t.run && !by.has(t.run)) by.set(t.run, { repo: t.repo || null, kind: t.kind || null, created: num(t.created) });
66
- for (const r of list(runs)) if (obj(r) && r.key && !by.has(r.key)) by.set(r.key, { repo: r.repo || null, kind: r.kind || null, created: num(r.created) });
65
+ for (const t of list(data.tasks)) if (obj(t) && t.run && !by.has(t.run)) by.set(t.run, { repo: t.repo || null, repo_root: t.repo_root || null, kind: t.kind || null, created: num(t.created) });
66
+ for (const r of list(runs)) if (obj(r) && r.key && !by.has(r.key)) by.set(r.key, { repo: r.repo || null, repo_root: r.repo_root || null, kind: r.kind || null, created: num(r.created) });
67
67
  return by;
68
68
  }
69
+ // a project is a repository root; a saved project that names the checkout a row started in still matches that row
70
+ const inProject = (row, project) => !project || RM.repoKey(row) === project || row.repo === project;
69
71
  function taskMatch(t, f, now) {
70
- if (f.project && t.repo !== f.project) return false;
72
+ if (!inProject(t, f.project)) return false;
71
73
  if (f.difficulty && diffOf(t) !== f.difficulty) return false;
72
74
  if (f.kind && t.kind !== f.kind) return false;
73
75
  if (!inPeriod(t.created, f, now)) return false;
@@ -81,8 +83,9 @@
81
83
  if (t) return taskMatch(t, f, now);
82
84
  }
83
85
  if (f.difficulty || f.exploratoryOnly) return false;
84
- const r = runs.get(v.run) || {};
85
- if (f.project && r.repo !== f.project) return false;
86
+ // no run summary loaded yet: the review row's own repo_root (reviews carry no repo) still names the project
87
+ const r = runs.get(v.run) || { repo_root: v.repo_root || null };
88
+ if (!inProject(r, f.project)) return false;
86
89
  if (f.kind && r.kind !== f.kind) return false;
87
90
  return inPeriod(r.created, f, now);
88
91
  }
@@ -101,7 +104,8 @@
101
104
  const repos = new Map(), diff = {}, kinds = {}, aliases = new Set();
102
105
  let first = null, last = null, explored = 0;
103
106
  for (const t of tasks) {
104
- if (t.repo) repos.set(t.repo, (repos.get(t.repo) || 0) + 1);
107
+ const key = RM.repoKey(t);
108
+ if (key) repos.set(key, (repos.get(key) || 0) + 1);
105
109
  const d = diffOf(t); diff[d] = (diff[d] || 0) + 1;
106
110
  if (t.kind) kinds[t.kind] = (kinds[t.kind] || 0) + 1;
107
111
  const c = num(t.created);
@@ -114,7 +118,7 @@
114
118
  for (const v of list(data.reviews)) {
115
119
  if (!obj(v)) continue;
116
120
  const x = aliasOf(v); if (x) aliases.add(x);
117
- const r = idx.get(v.run); if (r && r.repo && !repos.has(r.repo)) repos.set(r.repo, 0);
121
+ const key = RM.repoKey(idx.get(v.run) || v); if (key && !repos.has(key)) repos.set(key, 0);
118
122
  }
119
123
  return {
120
124
  projects: projectNames(repos),
@@ -10,7 +10,7 @@ window.ForgePanel = (() => {
10
10
  const num = v => typeof v === 'number' && Number.isFinite(v) ? v : null;
11
11
  const display = v => v === null || v === undefined || v === '' ? '—' : typeof v === 'object' ? JSON.stringify(v, null, 2) : String(v);
12
12
  const STATUSES = new Set(['merged', 'pass', 'running', 'pending', 'fail', 'error', 'infra', 'timeout', 'unknown', 'invalidated', 'blocked',
13
- 'interrupted', 'nochanges', 'conflict', 'accepted', 'none', 'outdated', 'needs_input', 'waiting']);
13
+ 'interrupted', 'nochanges', 'conflict', 'accepted', 'none', 'outdated', 'needs_input', 'needs_decision', 'waiting']);
14
14
  const cache = new Map(); // path → {data, error, at}
15
15
  function el(tag, text, className) {
16
16
  const node = document.createElement(tag);
@@ -89,6 +89,17 @@ window.ForgePanel = (() => {
89
89
  // A task that stopped NEEDS_INPUT: the question it asked, and the command that answers it. forge-ui shows the
90
90
  // command and never runs it; only the user's answer, passed to retry, resumes the task.
91
91
  const shellWord = s => /^[\w@%+=:,./-]+$/.test(s) ? s : "'" + String(s).replace(/'/g, "'\\''") + "'";
92
+ // An INFRA task: why its dispatch stopped (the cause, the stage, the model it ran on), when its limit resets, and
93
+ // whether the user must act: the reader's answer from forge's cause table (after the run too), else a live
94
+ // scope pause that names the task in its `tasks`
95
+ function infraSection(host, ctx, task) {
96
+ const s = section(host, 'Stopped on infrastructure'), inf = task.infra || {};
97
+ fields(s, [['Cause', RM.causeLabel(inf.cause)], ['Stage', inf.stage], ['Harness', inf.harness, true], ['Model', inf.model, true],
98
+ ['Reset', RM.resetText(inf.reset_at, ctx.now) || undefined]]);
99
+ const pause = list(ctx.run.scheduler && ctx.run.scheduler.pauses).find(p => list(p.tasks).includes(task.id)) || {};
100
+ const hint = inf.hint || pause.hint;
101
+ if (inf.needs_you === true || pause.needs_you === true) s.append(el('p', 'needs you' + (hint ? `: ${hint}` : ''), 'warn'));
102
+ }
92
103
  function waitingSection(host, ctx, task) {
93
104
  const s = section(host, 'Waiting for you');
94
105
  muted(s, 'This task stopped for an answer only you can give. Nothing retries it until you answer.');
@@ -105,6 +116,53 @@ window.ForgePanel = (() => {
105
116
  line.append(el('pre', text, 'cmd'), copy);
106
117
  s.append(line);
107
118
  }
119
+ // A task that stopped NEEDS_DECISION: why the retry policy stopped it, its attempts against the cap, the ledger of its
120
+ // reviews, and the decision text, which holds the commands to run. forge-ui shows the commands and never runs them.
121
+ const REASON_WORDS = { converging: 'reviews are not converging', split: 'no stronger model left', cap: 'attempt cap reached' };
122
+ // `attempts 9 of 8 allowed`, or `attempts 9` with no cap; null for a task that has made no attempt
123
+ function attemptsText(task) {
124
+ const n = num(task.attempts_total), cap = num(task.attempt_cap);
125
+ if (!n) return null;
126
+ return cap === null ? `attempts ${n}` : `attempts ${n} of ${cap} allowed`;
127
+ }
128
+ function decisionSection(host, ctx, task) {
129
+ const d = task.decision || {};
130
+ const reasons = list(d.reasons).map(r => Object.prototype.hasOwnProperty.call(REASON_WORDS, r) ? REASON_WORDS[r] : r);
131
+ const s = el('section', undefined, 'insp-section');
132
+ s.append(el('h3', reasons.length ? reasons.join(', ') : 'waiting for a decision', 'decision-reasons'));
133
+ host.append(s);
134
+ muted(s, 'This task stopped for a decision only you can make. Nothing retries it until you run one of the commands below.');
135
+ const attempts = attemptsText(task);
136
+ if (attempts) s.append(el('p', attempts));
137
+ ledgerTable(s, list(task.ledger));
138
+ s.append(el('pre', d.text != null ? d.text : `The decision is not recorded: tasks/${task.id}/decision.md is missing.`));
139
+ }
140
+ // The review ledger as a small table, one row per review. A FAIL verdict or a `fail` gate reads as failed: a gate fail
141
+ // over a PASS verdict keeps the reviewer's word and turns the chip red, with the gate's decision on hover.
142
+ function ledgerTable(parent, rows) {
143
+ if (!rows.length) { muted(parent, 'No review is recorded for this task yet.'); return; }
144
+ const word = v => String(v || '').toLowerCase();
145
+ const wrap = el('div', undefined, 'ledger-wrap'), table = el('table', undefined, 'ledger');
146
+ const findings = el('th', 'Findings'); findings.title = 'confirmed findings';
147
+ const thead = el('thead'), head = el('tr');
148
+ head.append(el('th', 'Attempt'), el('th', 'Verdict'), findings, el('th', 'New'), el('th', 'Worst'));
149
+ thead.append(head);
150
+ const tbody = el('tbody');
151
+ for (const r of rows) {
152
+ const failed = word(r.verdict) === 'fail' || word(r.gate) === 'fail';
153
+ const verdict = el('td'), worst = el('td');
154
+ const v = chip(r.verdict, failed ? 'fail' : word(r.verdict) === 'pass' ? 'pass' : 'unknown');
155
+ if (word(r.gate) === 'fail' && word(r.verdict) !== 'fail') v.title = 'forge gate: FAIL' + (r.verdict ? ` (reviewer said ${r.verdict})` : '');
156
+ verdict.append(v);
157
+ worst.append(r.worst ? sevChip(r.worst, r.worst) : document.createTextNode('—'));
158
+ const tr = el('tr', undefined, failed ? 'failed' : undefined);
159
+ tr.append(el('td', r.attempt, 'num'), verdict, el('td', r.confirmed, 'num'), el('td', r.new, 'num'), worst);
160
+ tbody.append(tr);
161
+ }
162
+ table.append(thead, tbody);
163
+ wrap.append(table);
164
+ parent.append(wrap);
165
+ }
108
166
  // An attempt's chip. A failed attempt is red whatever its words; a send-back says what forge did in its title.
109
167
  function attemptChip(word) {
110
168
  const c = chip(word, RM.attemptFailed(word) ? 'fail' : undefined), note = RM.attemptNote(word);
@@ -355,7 +413,7 @@ window.ForgePanel = (() => {
355
413
  const chips = el('div', undefined, 'chips');
356
414
  if (RM.taskStatus(task) === 'ACCEPTED') chips.append(acceptedChip(task));
357
415
  else {
358
- chips.append(chip(RM.taskStatus(task)));
416
+ chips.append(RM.taskStatus(task) === 'INFRA' ? chip(RM.statusText(task), 'infra') : chip(RM.taskStatus(task)));
359
417
  if (task.accepted === true) chips.append(acceptedChip(task));
360
418
  else if (task.verdict) chips.append(chip('review ' + task.verdict, task.verdict.toLowerCase()));
361
419
  }
@@ -363,20 +421,27 @@ window.ForgePanel = (() => {
363
421
  head.append(chips);
364
422
  const dl = diffLink(ctx, solo ? 'View the diff →' : 'View its diff, findings pinned to their lines →', { kind: 'task', task: task.id, source: 'current' }); if (dl) head.append(dl);
365
423
  host.append(head);
366
- if (RM.isWaiting(task.status)) waitingSection(host, ctx, task);
424
+ if (task.status === 'NEEDS_DECISION') decisionSection(host, ctx, task);
425
+ else if (RM.isWaiting(task.status)) waitingSection(host, ctx, task);
426
+ if (RM.taskStatus(task) === 'INFRA') infraSection(host, ctx, task);
367
427
  if (!solo) fields(host, [['Difficulty', task.difficulty], ['Depends on', depLinks(task.deps, ctx)], ['Files', list(task.files).join('\n') || '—', true], ['Branch', task.branch, true]]);
368
428
  if (C) C.nowSection(host, ctx, task);
369
429
  sweepSection(host, ctx, task);
370
430
 
371
431
  // the models: who owned it, how it was routed, what it was escalated to
372
432
  const ms = section(host, 'Models');
373
- fields(ms, [['Dwarf', plate(task.dwarf)], ['Reviewer', plate(task.qa)], ['Attempt', task.attempt]]);
433
+ const attempts = attemptsText(task);
434
+ fields(ms, [['Dwarf', plate(task.dwarf)], ['Reviewer', plate(task.qa)], attempts ? ['Attempts', attempts] : ['Attempt', task.attempt]]);
374
435
  const route = list(task.route).slice(-1)[0];
375
436
  if (route) fields(ms, [['Routed', `${display(route.chosen)} from ${list(route.candidates).join(', ') || '—'}${route.explored ? ` (exploratory, p=${display(route.propensity)})` : ''}`, true], ['Tier · ε', `${display(route.tier)} · ${display(route.epsilon)}`]]);
376
437
  for (const e of list(task.escalations)) {
377
438
  const line = el('p', `Escalated after attempt ${display(e.attempt)}: ${display(e.from)} → ${display(e.to)} at ${time(e.at)} `, 'muted');
378
439
  line.append(sourcePlate(e.source)); ms.append(line);
379
440
  }
441
+ for (const m of list(task.lateral)) {
442
+ const cause = RM.causeLabel(m.cause);
443
+ ms.append(el('p', `moved sideways: ${display(m.role)} ${display(m.from)} → ${display(m.to)}${cause ? ` (${cause})` : ''} · attempt ${display(m.attempt)} · ${time(m.at)}`, 'muted'));
444
+ }
380
445
  controlsSection(host, ctx, task);
381
446
 
382
447
  // timings
@@ -15,13 +15,29 @@
15
15
  const clamp = (v, a, b) => Math.max(a, Math.min(b, v));
16
16
  const DONE = new Set(['MERGED', 'PASS', 'NOCHANGES']);
17
17
  const BAD = new Set(['FAIL', 'ERROR', 'CONFLICT', 'INFRA', 'TIMEOUT', 'INVALIDATED', 'INTERRUPTED', 'UNKNOWN', 'BLOCKED']);
18
- // NEEDS_INPUT: stopped for an answer only the user can give. Neither DONE nor BAD, so never a failure.
19
- const WAITING = new Set(['NEEDS_INPUT']);
18
+ // NEEDS_INPUT (an answer) and NEEDS_DECISION (a choice): stopped for the user. Neither DONE nor BAD, so never a failure.
19
+ const WAITING = new Set(['NEEDS_INPUT', 'NEEDS_DECISION']);
20
20
  const isWaiting = status => WAITING.has(status);
21
21
  const WEIGHT = { low: 1, medium: 2, high: 3 };
22
22
  const weight = t => WEIGHT[String(t && t.difficulty || '').toLowerCase()] || 2;
23
23
  const alias = spec => spec ? String(spec).split(':')[0] : null;
24
24
  const basename = p => p ? String(p).split(/[\\/]/).filter(Boolean).pop() || String(p) : '—';
25
+ // What a run (or a models row) is grouped under: its repository root, else the checkout it started in (an older server).
26
+ const repoKey = run => (run && (run.repo_root || run.repo)) || null;
27
+ // The run list's "by repo" order: the name of each run's repository root.
28
+ const compareRepo = (a, b) => basename(repoKey(a)).localeCompare(basename(repoKey(b)));
29
+ // What a run shows where its repository is named. `name` is the root's basename. `worktree` is the
30
+ // checkout it started in when that is not the root — "forge-c2 (fix/milestone-c2)", or the basename
31
+ // alone when the branch is unknown — and null for the main checkout. A summary that lacks
32
+ // repo_root, repo_worktree and repo_branch (an older server or export) keeps basename(repo).
33
+ const repoLabel = run => {
34
+ const name = basename(run && (run.repo_root || run.repo));
35
+ const path = run && typeof run.repo_worktree === 'string' ? run.repo_worktree : '';
36
+ if (!path) return { name, worktree: null };
37
+ const branch = typeof run.repo_branch === 'string' ? run.repo_branch.trim() : '';
38
+ const leaf = basename(path);
39
+ return { name, worktree: branch ? `${leaf} (${branch})` : leaf };
40
+ };
25
41
  function fmtDur(s) {
26
42
  s = num(s); if (s === null) return '—';
27
43
  s = Math.max(0, Math.round(s));
@@ -112,7 +128,8 @@
112
128
  const text = String(f.text || '').trim().toLowerCase();
113
129
  if (text && ![run.goal, run.repo, run.run_id, run.path, ...list(run.models)].some(v => String(v || '').toLowerCase().includes(text))) return false;
114
130
  if (f.state && runState(run) !== f.state) return false;
115
- if (f.repo && run.repo !== f.repo) return false;
131
+ // a saved filter may name the checkout a run started in (a worktree) rather than its root: it still matches that run
132
+ if (f.repo && repoKey(run) !== f.repo && run.repo !== f.repo) return false;
116
133
  if (f.kind && run.kind !== f.kind) return false;
117
134
  if (f.model && !list(run.models).some(m => alias(m) === f.model)) return false;
118
135
  if (f.ageDays && num(now) !== null && !(num(run.updated) !== null && run.updated >= now - f.ageDays * 86400)) return false;
@@ -127,7 +144,8 @@
127
144
  function filterOptions(runs) {
128
145
  const repos = new Map(), models = new Set();
129
146
  for (const r of list(runs)) {
130
- if (r.repo && !repos.has(r.repo)) repos.set(r.repo, basename(r.repo));
147
+ const key = repoKey(r);
148
+ if (key && !repos.has(key)) repos.set(key, basename(key));
131
149
  for (const m of list(r.models)) if (alias(m)) models.add(alias(m));
132
150
  }
133
151
  return { repos: [...repos].map(([path, name]) => ({ path, name })), models: [...models].sort() };
@@ -145,11 +163,12 @@
145
163
  shown = (recent.length >= Math.min(floor, sorted.length) ? recent : sorted.slice(0, floor)).slice(0, limit);
146
164
  }
147
165
  const layers = [], seen = new Set();
166
+ const layerOf = r => 'repo:' + (repoKey(r) || '?');
148
167
  for (const r of shown) {
149
- const id = 'repo:' + (r.repo || '?');
150
- if (!seen.has(id)) { seen.add(id); layers.push({ id, name: basename(r.repo), repo: r.repo || null }); }
168
+ const id = layerOf(r), key = repoKey(r);
169
+ if (!seen.has(id)) { seen.add(id); layers.push({ id, name: basename(key), repo: key }); }
151
170
  }
152
- const modules = shown.map(r => ({ id: r.key, layer: 'repo:' + (r.repo || '?'), run: r, state: runState(r),
171
+ const modules = shown.map(r => ({ id: r.key, layer: layerOf(r), run: r, state: runState(r),
153
172
  tasks: list(r.task_statuses).length ? list(r.task_statuses) : Object.entries(r.counts || {}).flatMap(([s, n]) => Array.from({ length: Math.min(n, 60) }, (_, i) => ({ id: s + i, status: s }))),
154
173
  match: matchRun(r, f, now) }));
155
174
  const p = plate({ modules, layers }, atlasSize);
@@ -184,7 +203,7 @@
184
203
  if (statuses.some(s => s === 'RUNNING')) return 'RUNNING';
185
204
  if (statuses.every(s => s === 'MERGED')) return 'MERGED';
186
205
  if (statuses.some(s => s === 'PENDING' || s === 'PASS')) return 'PENDING';
187
- // only answers are missing: the integration waits for the user, not for a fix
206
+ // only the user is missing (an answer or a decision): the integration waits, not for a fix
188
207
  if (statuses.some(isWaiting) && statuses.every(s => s === 'MERGED' || isWaiting(s))) return 'WAITING';
189
208
  return 'BLOCKED';
190
209
  }
@@ -212,6 +231,31 @@
212
231
  if (t.status === 'MERGED' && t.accepted === true) return 'ACCEPTED';
213
232
  return t.status || 'PENDING';
214
233
  }
234
+ // An infrastructure stop's cause as a short label, shared by the task table, the panel and the checks view.
235
+ // A cause the page does not know (an older run's `quota`) is shown as it was written; no cause is null.
236
+ const CAUSE_LABELS = { capacity: 'at capacity', rate_limit: 'rate limited', usage_limit: 'usage limit', budget: 'out of budget',
237
+ auth: 'login needed', network: 'network down', provider_down: 'provider down', empty: 'empty answer', cancelled: 'cancelled' };
238
+ const causeLabel = cause => cause ? (Object.prototype.hasOwnProperty.call(CAUSE_LABELS, cause) ? CAUSE_LABELS[cause] : String(cause)) : null;
239
+ // The status word, with an INFRA task's cause after it (`INFRA · usage limit`); plain `INFRA` when no cause was recorded.
240
+ function statusText(t) {
241
+ const status = taskStatus(t), label = status === 'INFRA' ? causeLabel(t.infra && t.infra.cause) : null;
242
+ return label ? `INFRA · ${label}` : status;
243
+ }
244
+ const DAY_NAMES = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];
245
+ const MONTH_NAMES = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
246
+ // When a limit resets, in local time: `resets 14:05` today, `resets Fri 09:00` within the next six days, else
247
+ // `resets Nov 3 09:00`. Null without a reset (epoch seconds, or null) or without now to compare it with.
248
+ function resetText(epoch, now) {
249
+ const at = num(epoch), t = num(now);
250
+ if (at === null || t === null) return null;
251
+ const when = new Date(at * 1000), today = new Date(t * 1000);
252
+ if (Number.isNaN(when.getTime()) || Number.isNaN(today.getTime())) return null;
253
+ const clock = `${String(when.getHours()).padStart(2, '0')}:${String(when.getMinutes()).padStart(2, '0')}`;
254
+ const days = Math.round((new Date(when.getFullYear(), when.getMonth(), when.getDate()) - new Date(today.getFullYear(), today.getMonth(), today.getDate())) / 86400000);
255
+ if (days === 0) return `resets ${clock}`;
256
+ if (days > 0 && days < 7) return `resets ${DAY_NAMES[when.getDay()]} ${clock}`;
257
+ return `resets ${MONTH_NAMES[when.getMonth()]} ${when.getDate()} ${clock}`;
258
+ }
215
259
  // Verdict column and the 2D graph's tick or cross. text is the words, status the lamp class,
216
260
  // mark the cross (FAIL) or tick (PASS). An acceptance names FAIL or UNKNOWN and never invents a FAIL,
217
261
  // and it draws no mark: the graph must not put a red cross on a task a human accepted.
@@ -831,6 +875,7 @@
831
875
  }
832
876
 
833
877
  /* ---------- notifications: what changed between two polls of the run list ---------- */
878
+ // Waiting statuses are absent: a task that stops for the user (NEEDS_INPUT, NEEDS_DECISION) is not a failure.
834
879
  const FAILING = new Set(['FAIL', 'ERROR', 'CONFLICT', 'TIMEOUT', 'INVALIDATED', 'INTERRUPTED', 'BLOCKED']);
835
880
  // prev, next: RunSummary lists (prev null on the first poll, which is only a baseline). A run that has not
836
881
  // changed for two hours (stale: its process died) never fires.
@@ -893,8 +938,8 @@
893
938
  return { pos, edges, cols, rows: next };
894
939
  }
895
940
 
896
- return { liveNow, runState, execStatus, matchRun, filterOptions, atlasModel, columns, planModel, finishState,
897
- finalStatus, runReviewStatus, reviewSinceLine, reviewAt, taskStatus, taskVerdict, attemptStatus, attemptNote, attemptFailed, isWaiting,
941
+ return { liveNow, runState, execStatus, matchRun, filterOptions, atlasModel, repoKey, repoLabel, compareRepo, columns, planModel, finishState,
942
+ finalStatus, runReviewStatus, reviewSinceLine, reviewAt, taskStatus, statusText, causeLabel, resetText, taskVerdict, attemptStatus, attemptNote, attemptFailed, isWaiting,
898
943
  attributionLine, taskParts,
899
944
  taskTimes, metricValue, overlap, projectSchedule, execModel, verifyLeds, criticalPath, concurrency, stateAt, timeRange, events, lineage, structureKey, innerKey,
900
945
  fmtDur, alias, basename, weight, searchIndex, searchRank, statusEvents, fractalTree, sweepLine, sweepState };
@@ -167,7 +167,8 @@ export async function createStage(host, cb = {}) {
167
167
  const parts = [r.kind === 'solo' ? (Object.keys(c)[0] || 'solo') : `${merged}/${total} done`];
168
168
  if (running) parts.push(`${running} running`);
169
169
  if (bad) parts.push(`${bad} failed`);
170
- if (c.NEEDS_INPUT) parts.push(`${c.NEEDS_INPUT} waiting for you`); // not in the failed count: it waits for an answer
170
+ const waiting = (c.NEEDS_INPUT || 0) + (c.NEEDS_DECISION || 0);
171
+ if (waiting) parts.push(`${waiting} waiting for you`); // not in the failed count: each waits for the user
171
172
  const reviewStatus = RM.runReviewStatus(r);
172
173
  if (reviewStatus) parts.push(`review ${reviewStatus}`);
173
174
  else if (r.verification_status) parts.push(`verify ${r.verification_status}`);
@@ -1248,7 +1249,7 @@ export async function createStage(host, cb = {}) {
1248
1249
  const lamps = { title: 'Lamps', rows: [
1249
1250
  { sw: { lamp: 'st-merged' }, label: 'merged · passed · accepted' }, { sw: { lamp: 'st-running' }, label: 'running · interrupted' },
1250
1251
  { sw: { lamp: 'st-fail' }, label: 'failed · conflict · infra · timeout' }, { sw: { lamp: 'st-pending' }, label: 'pending, not started' },
1251
- { sw: { lamp: 'st-outdated' }, label: 'outdated review' }, { sw: { lamp: 'st-needs_input' }, label: 'waiting for you' },
1252
+ { sw: { lamp: 'st-outdated' }, label: 'outdated review' }, { sw: { lamp: 'st-needs_input' }, label: 'waiting for you' }, // NEEDS_INPUT and NEEDS_DECISION share this lamp
1252
1253
  { sw: { route: true }, label: st.view === 'atlas' ? 'chosen run' : 'chosen task' + (L.route ? ' and its route' : '') }] };
1253
1254
  if (st.view === 'atlas') {
1254
1255
  out.push({ title: 'Map', rows: [], note: 'Each block is a run, each district a repository. The lamps on a block are its tasks; the block stands taller the more tasks it has.' }, lamps);
@@ -10,10 +10,11 @@
10
10
  with controls on. */
11
11
  (function (root, factory) {
12
12
  'use strict';
13
- const api = factory(root);
13
+ const RM = typeof module === 'object' && module.exports ? require('./runmodel.js') : root.ForgeRunModel;
14
+ const api = factory(root, RM);
14
15
  if (typeof module === 'object' && module.exports) module.exports = api;
15
16
  else root.ForgeSettings = api;
16
- })(typeof self !== 'undefined' ? self : this, function (root) {
17
+ })(typeof self !== 'undefined' ? self : this, function (root, RM) {
17
18
  'use strict';
18
19
 
19
20
  const FILES = ['verify', 'setup', 'verify-subset'];
@@ -172,7 +173,7 @@
172
173
  }
173
174
 
174
175
  // The runs a repository can be taken from (those that name one), newest first.
175
- const withRepo = runs => list(runs).filter(r => r && r.key != null && typeof r.repo === 'string' && r.repo);
176
+ const withRepo = runs => list(runs).filter(r => r && r.key != null && typeof RM.repoKey(r) === 'string');
176
177
  const newestFirst = (a, b) => (Number(b.updated) || 0) - (Number(a.updated) || 0);
177
178
  // The run whose repository the page opens on: the current run when it is in the list, else the most recent one.
178
179
  function pickDefault(runs, current) {
@@ -181,19 +182,37 @@
181
182
  const latest = usable.slice().sort(newestFirst)[0];
182
183
  return latest ? latest.key : null;
183
184
  }
184
- // The choices grouped by repository: [{repo, name, runs}], the repository of the newest run first.
185
+ // The choices grouped by repository root: [{repo, name, runs}], the repository of the newest run first.
185
186
  function groupRuns(runs) {
186
187
  const groups = new Map();
187
188
  for (const r of withRepo(runs).sort(newestFirst)) {
188
- if (!groups.has(r.repo)) groups.set(r.repo, { repo: r.repo, name: basename(r.repo), runs: [] });
189
- groups.get(r.repo).runs.push(r);
189
+ const repo = RM.repoKey(r);
190
+ if (!groups.has(repo)) groups.set(repo, { repo, name: basename(repo), runs: [] });
191
+ groups.get(repo).runs.push(r);
190
192
  }
191
193
  return [...groups.values()];
192
194
  }
195
+ // The run inside its repository's group. The worktree it started in belongs to the run too, and the picker shows it
196
+ // beside this label as secondary text; the group names the repository.
193
197
  const optionLabel = r => {
194
198
  const goal = text(r.goal).split('\n')[0].trim();
195
- return [r.run_id || r.key, goal.length > 60 ? goal.slice(0, 59) + '…' : goal].filter(Boolean).join(' · ');
199
+ const short = goal.length > 60 ? goal.slice(0, 59) + '…' : goal;
200
+ return [r.run_id || r.key, short].filter(Boolean).join(' · ');
196
201
  };
202
+ // The option the picker's type-ahead lands on: the first label that starts with `query`, ignoring case, searching on from
203
+ // the active one `from` and wrapping round; -1 when none does. One letter typed again and again steps through the labels
204
+ // that start with it, so the search starts after the active label; a longer query starts at it, which stays put.
205
+ function typeAhead(labels, from, query) {
206
+ const all = list(labels), q = text(query).toLowerCase();
207
+ if (!q || !all.length) return -1;
208
+ const repeat = [...q].every(ch => ch === q[0]);
209
+ const want = repeat ? q[0] : q, start = repeat ? from + 1 : Math.max(from, 0);
210
+ for (let i = 0; i < all.length; i++) {
211
+ const at = (start + i) % all.length;
212
+ if (text(all[at]).toLowerCase().startsWith(want)) return at;
213
+ }
214
+ return -1;
215
+ }
197
216
 
198
217
  // An editor's unsaved text. `base` is the file as last read, `draft` the textarea (null: untouched). The CLI ends a saved
199
218
  // file with a newline, so trailing newlines do not count as an edit.
@@ -226,7 +245,7 @@
226
245
  function render(host, ctx) {
227
246
  const UI = root.ForgeUI, c = ctx || {};
228
247
  const el = (tag, t, cls) => UI.el(tag, t, cls);
229
- const s = { run: null, data: null, dataText: null, error: null, writes: false, loading: true, editors: {}, moved: {}, models: {}, modelMoved: {}, hold: 0, redraw: false, seq: 0, gen: 0, runsSig: null, ready: false, loadedAt: 0, repo: null, gone: false, asking: 0, asks: 0, pickerLate: false };
248
+ const s = { run: null, data: null, dataText: null, error: null, writes: false, loading: true, editors: {}, moved: {}, models: {}, modelMoved: {}, hold: 0, redraw: false, seq: 0, gen: 0, runsSig: null, ready: false, loadedAt: 0, repo: null, gone: false, asking: 0, asks: 0, pickerLate: false, listOpen: false };
230
249
  const key_ = (label, cls, onclick) => { const b = el('button', label, cls); b.type = 'button'; if (onclick) b.addEventListener('click', onclick); return b; };
231
250
 
232
251
  const head = el('header', undefined, 'set-head');
@@ -243,10 +262,26 @@
243
262
  host.replaceChildren(head, picker, note, stale, body);
244
263
  const staleNote = msg => { stale.hidden = !msg; stale.textContent = msg ? `The last read of the configuration failed: ${msg}. This shows the read before it; the next refresh tries again.` : ''; };
245
264
 
246
- /* the repository picker */
265
+ /* the repository picker: a button and a listbox rather than a native select, whose options hold plain text only, so
266
+ that each run can show the worktree it started in as secondary text. */
267
+ // The repository the configuration was read from, as the server answered; until then the run's root.
268
+ const repoPath = () => text(object(object(s.data).repo).path) || s.repo || '';
269
+ // A run as the picker shows it: its label, then its worktree as secondary text, with the full path and branch in its title.
270
+ function runFace(r) {
271
+ const face = [el('span', optionLabel(r), 'set-run-label')];
272
+ const worktree = RM.repoLabel(r).worktree;
273
+ if (worktree) {
274
+ const wt = el('span', worktree, 'muted repo-wt');
275
+ const branch = typeof r.repo_branch === 'string' ? r.repo_branch.trim() : '';
276
+ wt.title = r.repo_worktree + (branch ? `\nbranch ${branch}` : '');
277
+ face.push(wt);
278
+ }
279
+ return face;
280
+ }
247
281
  function drawPicker() {
248
- // The switch confirm lives in the picker: while it is open the rebuild waits, and runs when it is answered.
249
- if (s.asking) { s.pickerLate = true; return; }
282
+ // The switch confirm lives in the picker, and the open list is part of it: while either is open the rebuild waits,
283
+ // and runs when the confirm is answered or the list closes.
284
+ if (s.asking || s.listOpen) { s.pickerLate = true; return; }
250
285
  const runs = c.runs ? c.runs() : [];
251
286
  const groups = groupRuns(runs);
252
287
  const before = s.run, usable = withRepo(runs);
@@ -255,48 +290,130 @@
255
290
  if (s.run != null && !usable.some(r => r.key === s.run)) {
256
291
  // The run left the list. Another run of the same repository carries on with the editors as they are; with unsaved
257
292
  // text and no such run the page stays on it, flagged, rather than throwing the text away.
258
- const sibling = usable.slice().sort(newestFirst).find(r => r.repo === s.repo);
293
+ const sibling = usable.slice().sort(newestFirst).find(r => RM.repoKey(r) === s.repo);
259
294
  if (sibling) { s.run = sibling.key; kept = true; }
260
295
  else if (FILES.some(n => isDirty(s.editors[n]))) s.gone = true;
261
296
  else s.run = null;
262
297
  }
263
298
  if (s.run == null) s.run = pickDefault(runs, c.key);
264
299
  const now = usable.find(r => r.key === s.run);
265
- if (now) s.repo = now.repo;
300
+ if (now) s.repo = RM.repoKey(now);
266
301
  if (s.run !== before) {
267
302
  if (!kept) resetRun();
268
303
  if (s.ready) { if (!kept) drawBody(); load(); } // the default arrived, or the run went away
269
304
  }
270
- const sig = JSON.stringify([s.run, s.gone, groups.map(g => [g.repo, g.runs.map(r => [r.key, optionLabel(r)])])]);
305
+ const sig = JSON.stringify([s.run, s.gone, repoPath(), groups.map(g => [g.repo, g.runs.map(r => [r.key, optionLabel(r), r.repo_worktree || null, r.repo_branch || null])])]);
271
306
  if (sig === s.runsSig) return;
272
307
  s.runsSig = sig;
273
308
  if (!groups.length) { picker.replaceChildren(el('p', 'No run names a repository yet, so there is nothing to configure.', 'muted')); return; }
274
- const sel = el('select'); sel.id = 'set-run';
275
- if (s.gone) { const o = el('option', 'This run is no longer listed'); o.value = ''; o.selected = true; o.disabled = true; sel.append(o); }
276
- for (const g of groups) {
277
- const og = el('optgroup'); og.label = g.name + ' · ' + g.repo;
278
- for (const r of g.runs) { const o = el('option', optionLabel(r)); o.value = r.key; o.selected = r.key === s.run; og.append(o); }
279
- sel.append(og);
309
+ const refocus = document.activeElement && document.activeElement.id === 'set-run';
310
+ const current = s.gone ? null : usable.find(r => r.key === s.run);
311
+
312
+ const btn = el('button', undefined, 'set-run'); btn.type = 'button'; btn.id = 'set-run';
313
+ btn.dataset.run = current ? current.key : '';
314
+ btn.setAttribute('aria-haspopup', 'listbox'); btn.setAttribute('aria-expanded', 'false');
315
+ btn.setAttribute('aria-controls', 'set-run-list'); btn.setAttribute('aria-labelledby', 'set-run-cap set-run');
316
+ if (current) btn.append(...runFace(current));
317
+ else btn.append(el('span', 'This run is no longer listed', 'set-run-label'));
318
+ const pop = el('div', undefined, 'set-run-pop popover'); pop.popover = 'auto'; pop.id = 'set-run-pop';
319
+ const box = el('div', undefined, 'set-run-list'); box.id = 'set-run-list'; box.tabIndex = -1;
320
+ box.setAttribute('role', 'listbox'); box.setAttribute('aria-labelledby', 'set-run-cap');
321
+ const options = [];
322
+ groups.forEach((g, i) => {
323
+ const group = el('div', undefined, 'set-run-group'); group.setAttribute('role', 'group');
324
+ const name = el('div', undefined, 'set-run-group-name'); name.id = 'set-run-g' + i;
325
+ name.append(el('span', g.name, 'plate'), el('span', g.repo, 'muted mono'));
326
+ group.setAttribute('aria-labelledby', name.id); group.append(name);
327
+ for (const r of g.runs) {
328
+ const o = el('div', undefined, 'set-run-opt'); o.id = 'set-run-o-' + r.key; o.dataset.run = r.key;
329
+ o.setAttribute('role', 'option'); o.setAttribute('aria-selected', String(r.key === btn.dataset.run));
330
+ o.append(...runFace(r)); group.append(o); options.push(o);
331
+ }
332
+ box.append(group);
333
+ });
334
+ pop.append(box);
335
+
336
+ let active = -1, query = '', queryAt = 0; // the type-ahead's letters, and when the last came
337
+ const typing = () => query !== '' && Date.now() - queryAt < 700;
338
+ function activate(i) {
339
+ active = i;
340
+ options.forEach((o, j) => o.classList.toggle('is-active', j === i));
341
+ if (i < 0) { box.removeAttribute('aria-activedescendant'); return; }
342
+ box.setAttribute('aria-activedescendant', options[i].id);
343
+ options[i].scrollIntoView({ block: 'nearest' });
280
344
  }
281
- sel.addEventListener('change', async () => {
345
+ const isOpen = () => pop.matches(':popover-open');
346
+ const close = () => { s.listOpen = false; btn.setAttribute('aria-expanded', 'false'); if (isOpen()) pop.hidePopover(); };
347
+ btn.popoverTargetElement = pop; // a click toggles the list; Escape or a click elsewhere closes it
348
+ btn.addEventListener('keydown', e => {
349
+ if (e.key !== 'ArrowDown' && e.key !== 'ArrowUp') return;
350
+ e.preventDefault();
351
+ if (!isOpen()) pop.showPopover();
352
+ });
353
+ // The open state as the list starts to open or close (beforetoggle runs at once); where it sits and the focus once it has
354
+ // (toggle runs after).
355
+ pop.addEventListener('beforetoggle', e => {
356
+ s.listOpen = e.newState === 'open'; btn.setAttribute('aria-expanded', String(s.listOpen));
357
+ });
358
+ pop.addEventListener('toggle', e => {
359
+ if (e.newState === 'open') {
360
+ // under the button, or above it when the button sits low on the screen
361
+ const r = btn.getBoundingClientRect();
362
+ pop.style.minWidth = Math.round(r.width) + 'px';
363
+ const h = pop.offsetHeight, below = window.innerHeight - r.bottom > h + 16;
364
+ pop.style.left = Math.round(Math.max(8, Math.min(window.innerWidth - pop.offsetWidth - 8, r.left))) + 'px';
365
+ pop.style.top = Math.round(below ? r.bottom + 4 : Math.max(8, r.top - h - 4)) + 'px';
366
+ query = '';
367
+ activate(Math.max(0, options.findIndex(o => o.dataset.run === btn.dataset.run)));
368
+ box.focus({ preventScroll: true });
369
+ return;
370
+ }
371
+ // Focus left with the list goes back to the button, the one on the page now (a choice may have rebuilt it).
372
+ const at = document.activeElement;
373
+ if (!at || at === document.body || pop.contains(at)) { const b = document.getElementById('set-run'); if (b) b.focus({ preventScroll: true }); }
374
+ if (s.pickerLate && !s.asking) { s.pickerLate = false; drawPicker(); }
375
+ });
376
+ box.addEventListener('keydown', e => {
377
+ const k = e.key, last = options.length - 1;
378
+ if (k === 'ArrowDown') activate(Math.min(last, active + 1));
379
+ else if (k === 'ArrowUp') activate(Math.max(0, active - 1));
380
+ else if (k === 'Home') activate(0);
381
+ else if (k === 'End') activate(last);
382
+ else if (k === 'Enter' || (k === ' ' && !typing())) { if (active >= 0) choose(options[active].dataset.run); }
383
+ else if (k === 'Tab') { close(); return; }
384
+ else if (k.length === 1 && !e.altKey && !e.ctrlKey && !e.metaKey) {
385
+ query = (typing() ? query : '') + k; queryAt = Date.now();
386
+ const at = typeAhead(options.map(o => o.firstChild.textContent), active, query);
387
+ if (at >= 0) activate(at);
388
+ } else return;
389
+ e.preventDefault();
390
+ });
391
+ box.addEventListener('mousemove', e => { const o = e.target.closest('[role=option]'); if (o && options.indexOf(o) !== active) activate(options.indexOf(o)); });
392
+ box.addEventListener('click', e => { const o = e.target.closest('[role=option]'); if (o) choose(o.dataset.run); });
393
+ async function choose(key) {
394
+ close();
395
+ if (key === btn.dataset.run) return; // the run already shown
282
396
  const unsaved = FILES.filter(n => s.editors[n] && isDirty(s.editors[n]));
283
397
  if (unsaved.length) {
284
398
  const ask = s.asking = ++s.asks;
285
399
  const yes = await UI.confirmInline(picker, `Switch repository and discard the unsaved edits to ${unsaved.map(n => '.forge/' + n).join(', ')}?`, { danger: true });
286
- if (s.asking !== ask) return; // a later change asked again, and that confirm decides
400
+ if (s.asking !== ask) return; // a later choice asked again, and that confirm decides
287
401
  const late = s.pickerLate;
288
402
  s.asking = 0; s.pickerLate = false;
289
- if (!yes) { sel.value = s.gone ? '' : s.run; if (late) drawPicker(); return; }
403
+ if (!yes) { if (late) drawPicker(); return; }
290
404
  }
291
- pick(sel.value);
292
- });
405
+ pick(key);
406
+ }
407
+
293
408
  const lab = el('label', undefined, 'set-field'); lab.htmlFor = 'set-run';
294
- lab.append(el('span', 'Repository of run', 'plate'));
409
+ const cap = el('span', 'Repository of run', 'plate'); cap.id = 'set-run-cap';
410
+ lab.append(cap);
295
411
  const path = el('p', undefined, 'set-repo-path');
296
- path.append(el('i', undefined, 'lamp lamp-route'), el('span', s.repo || '', 'mono'));
297
- const row = el('div', undefined, 'set-picker-row'); row.append(lab, sel);
412
+ path.append(el('i', undefined, 'lamp lamp-route'), el('span', repoPath(), 'mono'));
413
+ const row = el('div', undefined, 'set-picker-row'); row.append(lab, btn, pop);
298
414
  picker.replaceChildren(row, path);
299
415
  if (s.gone) picker.append(el('p', 'The run is gone from the list. Your unsaved edits are kept; pick another run to continue, which discards them.', 'warn set-problem'));
416
+ if (refocus) btn.focus({ preventScroll: true });
300
417
  }
301
418
  // A new run: nothing of the old one stays, and confirms of the old body (now detached) no longer hold a redraw.
302
419
  function resetRun() {
@@ -340,6 +457,7 @@
340
457
  const t = JSON.stringify(res.data);
341
458
  if (t === s.dataText && !s.redraw) return;
342
459
  s.data = res.data; s.dataText = t;
460
+ drawPicker(); // its path line names the repository this read came from
343
461
  if (s.hold > 0) { s.redraw = true; return; } // a confirm or a write is open: draw after it
344
462
  drawBody();
345
463
  }
@@ -725,6 +843,6 @@
725
843
  }
726
844
 
727
845
  return { render, configBody, repoKey, gateKey, targetPath, subsetOk, valueProblem, decideTextProblem, describeDecide, gateTags, replayDate,
728
- pickDefault, groupRuns, optionLabel, editorOf, isDirty, dirtyState, edited, typed, shown, readFailure,
846
+ pickDefault, groupRuns, optionLabel, typeAhead, editorOf, isDirty, dirtyState, edited, typed, shown, readFailure,
729
847
  FILES, GATES, MODES, VALUE_MAX, DECIDE_VALUE_MAX, ADD_COMMAND };
730
848
  });