@giamme/forge 0.12.0 → 0.13.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 (117) hide show
  1. package/CHANGELOG.md +77 -0
  2. package/README.md +1 -1
  3. package/SKILL.md +31 -12
  4. package/VERSION +1 -1
  5. package/docs/add-ons.md +11 -6
  6. package/docs/artifacts.md +18 -6
  7. package/docs/commands.md +189 -17
  8. package/docs/decomposed-runs.md +13 -5
  9. package/docs/forge-ui.md +34 -4
  10. package/docs/memory.md +2 -1
  11. package/docs/models.md +4 -2
  12. package/docs/reviews.md +81 -19
  13. package/docs/troubleshooting.md +3 -1
  14. package/forge +17 -1
  15. package/package.json +1 -1
  16. package/references/dataset.md +40 -14
  17. package/references/decision-models.md +759 -0
  18. package/references/decompose.md +197 -28
  19. package/references/harnesses.md +10 -3
  20. package/references/planning.md +8 -0
  21. package/references/solo.md +13 -3
  22. package/references/ui.md +11 -0
  23. package/scripts/forge-artifact.sh +30 -4
  24. package/scripts/forge-config.py +238 -29
  25. package/scripts/forge-contract.py +127 -58
  26. package/scripts/forge-control.py +40 -9
  27. package/scripts/forge-decide.py +6 -0
  28. package/scripts/forge-dispatch.sh +47 -15
  29. package/scripts/forge-fail-first.py +2 -2
  30. package/scripts/forge-gate-addressed.sh +40 -0
  31. package/scripts/forge-gate-message.sh +64 -0
  32. package/scripts/forge-issues.py +368 -36
  33. package/scripts/forge-jev-options.sh +269 -42
  34. package/scripts/forge-lib-attribute.sh +447 -0
  35. package/scripts/forge-lib-gates.sh +32 -0
  36. package/scripts/forge-lib-plans.sh +17 -6
  37. package/scripts/forge-lib-review.sh +24 -19
  38. package/scripts/forge-lib-task.sh +219 -39
  39. package/scripts/forge-lib-verify.sh +45 -8
  40. package/scripts/forge-memory.sh +3 -3
  41. package/scripts/forge-parallel-options.sh +44 -5
  42. package/scripts/forge-parallel.sh +503 -304
  43. package/scripts/forge-plan-check.py +35 -1
  44. package/scripts/forge-pre-review.py +437 -0
  45. package/scripts/forge-prompt.py +25 -5
  46. package/scripts/forge-route.py +2 -2
  47. package/scripts/forge-runtime.py +55 -1
  48. package/scripts/forge-schedule.py +70 -9
  49. package/scripts/forge-shadow.py +2 -2
  50. package/scripts/forge-solo.sh +41 -10
  51. package/scripts/forge-submodules.py +389 -0
  52. package/scripts/forge-sweep.py +542 -0
  53. package/scripts/forge_dataset/cli.py +12 -6
  54. package/scripts/forge_dataset/export.py +55 -45
  55. package/scripts/forge_dataset/forecast.py +4 -1
  56. package/scripts/forge_dataset/harvest.py +33 -5
  57. package/scripts/{forge_jev/outcome.py → forge_dataset/states.py} +21 -7
  58. package/scripts/forge_decide/__init__.py +141 -0
  59. package/scripts/forge_decide/budget.py +149 -0
  60. package/scripts/forge_decide/cache.py +66 -0
  61. package/scripts/forge_decide/cli.py +953 -0
  62. package/scripts/forge_decide/doctor.py +221 -0
  63. package/scripts/forge_decide/label_addressed.py +75 -0
  64. package/scripts/forge_decide/label_attribution.py +62 -0
  65. package/scripts/forge_decide/label_coverage.py +81 -0
  66. package/scripts/forge_decide/label_message.py +38 -0
  67. package/scripts/forge_decide/label_prompt.py +139 -0
  68. package/scripts/forge_decide/labels.py +328 -0
  69. package/scripts/forge_decide/metrics.py +125 -0
  70. package/scripts/forge_decide/migrate.py +226 -0
  71. package/scripts/forge_decide/providers.py +292 -0
  72. package/scripts/forge_decide/replay.py +350 -0
  73. package/scripts/forge_decide/report.py +382 -0
  74. package/scripts/forge_decide/resolve.py +397 -0
  75. package/scripts/forge_decide/sites.py +377 -0
  76. package/scripts/forge_jev/__init__.py +202 -104
  77. package/scripts/forge_jev/addressed.py +171 -0
  78. package/scripts/forge_jev/attribution.py +198 -0
  79. package/scripts/forge_jev/cli.py +460 -382
  80. package/scripts/forge_jev/client.py +155 -77
  81. package/scripts/forge_jev/coupling.py +19 -87
  82. package/scripts/forge_jev/coverage.py +303 -0
  83. package/scripts/forge_jev/findings.py +219 -0
  84. package/scripts/forge_jev/gates.py +225 -27
  85. package/scripts/forge_jev/memory.py +65 -4
  86. package/scripts/forge_jev/message.py +134 -0
  87. package/scripts/forge_jev/plan_gates.py +294 -0
  88. package/scripts/forge_jev/questions.py +173 -313
  89. package/scripts/forge_jev/verify.py +130 -104
  90. package/ui/README.md +41 -10
  91. package/ui/docs/api.md +212 -44
  92. package/ui/forge_ui/checks.py +331 -0
  93. package/ui/forge_ui/control.py +60 -11
  94. package/ui/forge_ui/export.py +8 -3
  95. package/ui/forge_ui/models.py +1 -0
  96. package/ui/forge_ui/reader.py +436 -26
  97. package/ui/forge_ui/server.py +13 -0
  98. package/ui/forge_ui/static/app.js +15 -8
  99. package/ui/forge_ui/static/checksview.js +449 -0
  100. package/ui/forge_ui/static/controls.js +20 -13
  101. package/ui/forge_ui/static/convo.js +11 -2
  102. package/ui/forge_ui/static/findingsview.js +6 -4
  103. package/ui/forge_ui/static/index.html +1 -0
  104. package/ui/forge_ui/static/panel.js +105 -17
  105. package/ui/forge_ui/static/runmodel.js +40 -2
  106. package/ui/forge_ui/static/scene3d.js +2 -15
  107. package/ui/forge_ui/static/settings.js +336 -41
  108. package/ui/forge_ui/static/style.css +72 -7
  109. package/ui/forge_ui/transcripts.py +225 -54
  110. package/references/jev.md +0 -865
  111. package/scripts/forge_jev/backtest.py +0 -322
  112. package/scripts/forge_jev/corpus.py +0 -156
  113. package/scripts/forge_jev/features.py +0 -24
  114. package/scripts/forge_jev/predict.py +0 -204
  115. package/scripts/forge_jev/review.py +0 -73
  116. package/scripts/forge_jev/routing.py +0 -271
  117. package/scripts/forge_jev/subset.py +0 -123
@@ -64,8 +64,8 @@ window.ForgeApp = (() => {
64
64
  if (spec.kind === 'fractal') return `${base}/tasks/${e(spec.task)}/fractal/${e(spec.node)}/diff${file}`;
65
65
  return `${base}/tasks/${e(spec.task)}/diff${spec.source && spec.source !== 'current' ? '/' + e(spec.source) : ''}${file}`;
66
66
  }
67
- // an execution's conversation, in the stage's place like a diff
68
- const convoHash = (key, sel) => hashFor(key, sel) + '/conversation';
67
+ // an execution's conversation, in the stage's place like a diff; opened at one of its events when given
68
+ const convoHash = (key, sel, event) => hashFor(key, sel) + '/conversation' + (Number.isInteger(event) && event >= 0 ? '/event/' + event : '');
69
69
  function cloudHash(sel, focus) {
70
70
  if (sel) return '#/cloud/runs/' + encodeURIComponent(sel);
71
71
  return focus ? '#/cloud/projects/' + encodeURIComponent(focus) : '#/cloud';
@@ -83,11 +83,11 @@ window.ForgeApp = (() => {
83
83
  if ((r = rest.match(/^\/tasks\/([^/]+)\/diff(?:\/(?!file\/|finding\/)([^/]+))?(?:\/finding\/([^/]+))?(?:\/file\/(.+?))?\/?$/))) return { key: d(m[1]), sel: { kind: 'task', id: d(r[1]) }, diff: { kind: 'task', task: d(r[1]), source: r[2] ? d(r[2]) : 'current', finding: r[3] ? d(r[3]) : null, file: r[4] ? d(r[4]) : null } };
84
84
  if ((r = rest.match(/^\/tasks\/([^/]+)\/fractal\/([^/]+)\/diff(?:\/file\/(.+?))?\/?$/))) return { key: d(m[1]), sel: { kind: 'task', id: d(r[1]) }, diff: { kind: 'fractal', task: d(r[1]), node: d(r[2]), file: r[3] ? d(r[3]) : null } };
85
85
  if ((r = rest.match(/^\/final-review\/([^/]+)\/diff(?:\/finding\/([^/]+))?(?:\/file\/(.+?))?\/?$/))) return { key: d(m[1]), sel: { kind: 'final', name: d(r[1]) }, diff: { kind: 'final', name: d(r[1]), finding: r[2] ? d(r[2]) : null, file: r[3] ? d(r[3]) : null } };
86
- if ((r = rest.match(/^\/(?:tasks\/([^/]+)\/)?executions\/([^/]+)\/conversation\/?$/))) {
86
+ if ((r = rest.match(/^\/(?:tasks\/([^/]+)\/)?executions\/([^/]+)\/conversation(?:\/event\/(\d{1,7}))?\/?$/))) {
87
87
  const s = r[1] ? { kind: 'execution', task: d(r[1]), id: d(r[1]), exec: d(r[2]) } : { kind: 'execution', task: null, exec: d(r[2]) };
88
88
  const run = s.task && state.cache.get(d(m[1]))?.data, t = run && list(run.tasks).find(x => x.id === s.task);
89
89
  if (t && list(t.shadow).some(x => x.execution === s.exec)) s.shadow = true;
90
- return { key: d(m[1]), sel: s, convo: { task: s.task, exec: s.exec } };
90
+ return { key: d(m[1]), sel: s, convo: { task: s.task, exec: s.exec, event: r[3] ? Number(r[3]) : null } };
91
91
  }
92
92
  if ((r = rest.match(/^\/tasks\/([^/]+)\/executions\/([^/]+)\/?$/))) sel = { kind: 'execution', task: d(r[1]), id: d(r[1]), exec: d(r[2]) };
93
93
  if (sel && sel.kind === 'execution' && sel.task) {
@@ -106,7 +106,7 @@ window.ForgeApp = (() => {
106
106
  function link(text, key, sel) { const a = el('a', text); a.href = hashFor(key, sel); return a; }
107
107
 
108
108
  const statuses = new Set(['merged', 'pass', 'running', 'pending', 'fail', 'error', 'infra',
109
- 'timeout', 'unknown', 'invalidated', 'blocked', 'interrupted', 'nochanges', 'conflict', 'accepted', 'outdated']);
109
+ 'timeout', 'unknown', 'invalidated', 'blocked', 'interrupted', 'nochanges', 'conflict', 'accepted', 'outdated', 'needs_input']);
110
110
  function chip(value, cls) {
111
111
  const status = String(cls || value || 'unknown').toLowerCase();
112
112
  return el('span', value || '—', 'chip st-' + (statuses.has(status) ? status : 'unknown'));
@@ -593,7 +593,7 @@ window.ForgeApp = (() => {
593
593
  ['labels', 'Readouts', 'The status line on the front of each block'], ['beacons', 'Findings', 'A mark over the block per review finding, shaped by its severity'],
594
594
  ['finish', 'Finish line', 'Integration, verification and the final review'], ['districts', 'Districts', 'The wave and repository names on the plate'],
595
595
  ['halos', 'Halos', 'The glow under running and chosen blocks'], ['route', 'Route', 'A chosen task keeps its route lit: what it waits on and what waits on it (I)']], 'layer');
596
- bankOf('Marks', [['critical', 'Critical path', 'The chain of dependencies that bounded the wall time'], ['arcs', 'Review marks', 'Shadow disagreements and Clef rings'],
596
+ bankOf('Marks', [['critical', 'Critical path', 'The chain of dependencies that bounded the wall time'], ['arcs', 'Review marks', 'Shadow disagreements'],
597
597
  ['ghosts', 'Projected', 'Where the tasks that have not started would run, by forge-schedule\'s rules']], 'ov');
598
598
  ov.addEventListener('click', e => {
599
599
  const b = e.target.closest('.layer-key'); if (!b) return;
@@ -740,6 +740,10 @@ window.ForgeApp = (() => {
740
740
  if (run.updated != null) { upd.dataset.epoch = run.updated; upd.dataset.short = ''; }
741
741
  desc.append(upd);
742
742
  row.append(lamp, title, where, desc); head.append(row);
743
+ // an environment problem several tasks met, read lazily
744
+ if (window.ForgeChecks && !solo) window.ForgeChecks.banner(head, { run, fetchJSON: path => fetchJSON(path).then(r => r.data),
745
+ rerender: () => { const cur = state.cache.get(state.key)?.data; if (cur && cur.key === run.key) renderHeader(cur); },
746
+ hash: s => hashFor(run.key, s), convoHash: (s, event) => convoHash(run.key, s, event) });
743
747
  if (list(run.warnings).length) details(head, `Reader warnings (${run.warnings.length})`, run.warnings.join('\n'), 'warnings');
744
748
  if (list(run.truncated).length) details(head, 'Truncated fields', run.truncated.join('\n'), 'truncated');
745
749
  scoped(head, run.key + ':');
@@ -756,6 +760,8 @@ window.ForgeApp = (() => {
756
760
  { id: 'difficulty', label: 'Difficulty', value: t => DIFF_RANK[t.difficulty] ?? null, cell: t => display(t.difficulty) },
757
761
  { id: 'wave', label: 'Wave', value: t => Number.isFinite(Number(t.wave)) && t.wave !== null && t.wave !== '' ? Number(t.wave) : null, cell: t => display(t.wave) },
758
762
  { id: 'status', label: 'Status', value: t => RM.taskStatus(t), cell: t => chip(RM.taskStatus(t)) },
763
+ ...(window.ForgeChecks ? [{ id: 'now', label: 'Now', title: 'What a running task is doing, or why one that is not running waits',
764
+ value: t => window.ForgeChecks.nowRank(t), cell: t => window.ForgeChecks.cell(t, now(), { hash: s => hashFor(run.key, s) }) }] : []),
759
765
  { id: 'dwarf', label: 'Dwarf', value: t => t.dwarf, cell: t => window.ForgeIcons.modelPlate(t.dwarf) },
760
766
  { id: 'qa', label: 'QA', value: t => t.qa, cell: t => window.ForgeIcons.modelPlate(t.qa) },
761
767
  { id: 'attempt', label: 'Attempt', value: t => Number(t.attempt) || null, cell: t => display(t.attempt) },
@@ -802,7 +808,7 @@ window.ForgeApp = (() => {
802
808
  fetchJSON: path => fetchJSON(path).then(r => r.data),
803
809
  rerender: () => { const r = state.cache.get(state.key)?.data; if (r) renderInspector(r); },
804
810
  hash: s => hashFor(run.key, s), onSelect: s => select(s), diffHash: spec => diffHash(run.key, spec),
805
- convoHash: s => convoHash(run.key, s),
811
+ convoHash: (s, event) => convoHash(run.key, s, event),
806
812
  onFractal: (id, data) => { if (state.stage && state.stage.setFractal) state.stage.setFractal(id, data); },
807
813
  });
808
814
  scoped(host, run.key + ':');
@@ -874,7 +880,7 @@ window.ForgeApp = (() => {
874
880
  if (kind === 'convo') {
875
881
  const sel = state.sel, task = sel.task ? list(run.tasks).find(t => t.id === sel.task) : run.kind === 'solo' ? list(run.tasks)[0] : null;
876
882
  const brief = list(task && task.executions).find(e => e.id === state.convo.exec) || null;
877
- window.ForgeConvo.render(host, { run, spec: { task: task ? task.id : null, exec: state.convo.exec }, brief, live: !SNAP,
883
+ window.ForgeConvo.render(host, { run, spec: { task: task ? task.id : null, exec: state.convo.exec }, brief, live: !SNAP, focus: state.convo.event,
878
884
  fetchJSON: path => fetchJSON(path).then(r => r.data), rerender, diffHash: spec => diffHash(run.key, spec), closeHref: hashFor(run.key, state.sel) });
879
885
  return;
880
886
  }
@@ -1076,6 +1082,7 @@ window.ForgeApp = (() => {
1076
1082
  if (state.models) loadModels();
1077
1083
  if (state.settings) state.settingsView?.poll();
1078
1084
  for (const node of document.querySelectorAll('[data-epoch]')) { const t = relative(node.dataset.epoch); node.textContent = node.dataset.short !== undefined ? t.replace(/^updated /, '') : t; }
1085
+ if (window.ForgeChecks) window.ForgeChecks.tick(document, now());
1079
1086
  }
1080
1087
  // Poll faster while something runs, slower otherwise; never with refresh off, and a hidden tab only to notify.
1081
1088
  function schedule() {
@@ -0,0 +1,449 @@
1
+ /* forge-ui checks and where each task stands (window.ForgeChecks, and a CommonJS module under node:test).
2
+ - Now: what a running task does (the agent at work, the call it is making and since when, how long its log has been
3
+ quiet), or why a task that is not running waits (RunDetail task.now, task.waiting and run.scheduler in
4
+ ui/docs/api.md): a cell of the task table, a section of the task inspector, the run inspector's scheduler fields.
5
+ - Checks: the tests, type checks, lints and builds each dwarf and reviewer ran, attempt by attempt, against the
6
+ commands the brief's acceptance criteria name (/tasks/<id>/checks, /executions/<name>/checks).
7
+ - Environment: a banner in the run header for each environment problem (Docker, a sandbox's EPERM, a port in use…)
8
+ that several tasks met (/environment).
9
+ Times that move between polls (an elapsed time, a countdown, a quiet log) are elements with data-since, data-until
10
+ or data-quiet; tick(root, now) brings them up to date, and app.js calls it on every refresh.
11
+ The pure helpers are tested in ui/tests/js/checksview.test.js. Commands, output lines and task ids are untrusted:
12
+ they only ever enter the page as text.
13
+ ctx = { run, now (epoch seconds), fetchJSON(path), rerender(), hash(sel), onSelect(sel), convoHash(sel, event) } */
14
+ (function (root, factory) {
15
+ 'use strict';
16
+ const api = factory(root);
17
+ if (typeof module === 'object' && module.exports) module.exports = api;
18
+ else root.ForgeChecks = api;
19
+ })(typeof self !== 'undefined' ? self : this, function (root) {
20
+ 'use strict';
21
+
22
+ const QUIET_WARN_S = 300; // a log quiet past this is flagged, as the verification view flags its own
23
+ const ENV_EVERY_S = 15; // a running run's environment problems are read again at most this often
24
+ const list = v => Array.isArray(v) ? v : [];
25
+ const num = v => typeof v === 'number' && Number.isFinite(v) ? v : null;
26
+ const ROLE = { dwarf: 'dwarf', qa: 'reviewer', task: 'task', solo: 'run' };
27
+ const KIND = { test: 'tests', typecheck: 'type check', lint: 'lint', build: 'build' };
28
+ const plural = (n, word) => `${n} ${word}${n === 1 ? '' : 's'}`;
29
+
30
+ /* ---------- pure ---------- */
31
+ function dur(s) {
32
+ s = num(s); if (s === null) return '—';
33
+ s = Math.max(0, Math.round(s));
34
+ if (s < 60) return s + 's';
35
+ if (s < 3600) return Math.floor(s / 60) + 'm' + String(s % 60).padStart(2, '0') + 's';
36
+ return Math.floor(s / 3600) + 'h' + String(Math.floor(s % 3600 / 60)).padStart(2, '0') + 'm';
37
+ }
38
+ const since = (start, now) => num(start) !== null && num(now) !== null ? Math.max(0, now - start) : null;
39
+ const firstLine = text => (String(text || '').split('\n').find(line => line.trim()) || '').trim();
40
+ // "quiet 12 min" once a log has said nothing for over five minutes, else null
41
+ function quietText(lastOutput, now) {
42
+ const q = since(lastOutput, now);
43
+ return q !== null && q > QUIET_WARN_S ? `quiet ${Math.floor(q / 60)} min` : null;
44
+ }
45
+ // "resumes in 2m10s", "resuming" once its time has come, or null without a time
46
+ function untilText(until, now) {
47
+ if (num(until) === null || num(now) === null) return null;
48
+ return until > now ? 'resumes in ' + dur(until - now) : 'resuming';
49
+ }
50
+ // What a running task does now: {who, role, execution, attempt, phase, phaseSince, call, quietSince}; call is
51
+ // {text (its first line, or the tool), command, check, since} or null while the agent thinks or writes.
52
+ function nowModel(task) {
53
+ const n = task && task.now;
54
+ if (!n || typeof n !== 'object') return null;
55
+ const call = n.call && typeof n.call === 'object' ? n.call : null;
56
+ return {
57
+ who: ROLE[n.role] || String(n.role || 'task'), role: n.role || null, execution: n.execution || null, attempt: num(n.attempt),
58
+ phase: n.phase || null, phaseSince: num(n.phase_started),
59
+ call: call ? { text: firstLine(call.command) || call.tool || call.kind || 'a call', command: call.command || null,
60
+ tool: call.tool || null, check: call.check || null, since: num(call.started) } : null,
61
+ quietSince: num(n.last_output_at),
62
+ };
63
+ }
64
+ function scopeText(w) {
65
+ const scope = String(w.scope || '');
66
+ if (scope === 'all') return 'every model';
67
+ if (scope.startsWith('model:')) return `model ${w.model || scope.slice(6)}${w.harness ? ' on ' + w.harness : ''}`;
68
+ if (scope.startsWith('harness:')) return `harness ${w.harness || scope.slice(8)}`;
69
+ return scope || 'its model';
70
+ }
71
+ // Why a task waits: {kind, text, tasks: [{id, stopped}], until, exhausted, split}, or null
72
+ function waitingModel(w) {
73
+ if (!w || typeof w !== 'object') return null;
74
+ const ids = v => list(v).map(String);
75
+ const out = { kind: w.kind, tasks: [], until: null, exhausted: false, split: null };
76
+ if (w.kind === 'deps') {
77
+ const stopped = new Set(ids(w.stopped));
78
+ return { ...out, text: 'waits on', tasks: ids(w.on).map(id => ({ id, stopped: stopped.has(id) })) };
79
+ }
80
+ if (w.kind === 'overlap') return { ...out, text: 'shares files with', tasks: ids(w.on).map(id => ({ id, stopped: false })) };
81
+ if (w.kind === 'slot') return { ...out, text: `no free slot: ${num(w.running) ?? '?'} of ${num(w.max_parallel) ?? '?'} running` };
82
+ if (w.kind === 'drained') return { ...out, text: 'drained: nothing new starts until the run resumes' };
83
+ if (w.kind === 'stopping') return { ...out, text: w.mode === 'now' ? 'the run is stopping now' : 'the run stops once its running tasks end' };
84
+ if (w.kind === 'next') return { ...out, text: "starts at the scheduler's next turn" };
85
+ if (w.kind === 'infra') {
86
+ return { ...out, text: `paused: ${scopeText(w)}${w.class ? ' · ' + String(w.class).replace(/_/g, ' ') : ''}`,
87
+ until: w.exhausted === true ? null : num(w.until), exhausted: w.exhausted === true };
88
+ }
89
+ if (w.kind === 'escalation') {
90
+ return { ...out, text: `stopped by the retry policy${num(w.attempts) !== null ? ` after ${plural(w.attempts, 'attempt')}` : ''}${w.model ? ' on ' + w.model : ''}`,
91
+ split: w.split || null };
92
+ }
93
+ return null;
94
+ }
95
+ // The Now column's order: running, then what starts soonest, then what waits on others, then what is held
96
+ const RANK = { running: 0, next: 1, slot: 2, overlap: 2, deps: 3, infra: 4, drained: 5, stopping: 5, escalation: 6 };
97
+ function nowRank(task) {
98
+ if (task && task.now) return RANK.running;
99
+ const w = task && task.waiting;
100
+ return w && RANK[w.kind] !== undefined ? RANK[w.kind] : null;
101
+ }
102
+ function countsText(c) {
103
+ if (!c || typeof c !== 'object') return null;
104
+ if ('errors' in c || 'warnings' in c) {
105
+ const parts = [plural(num(c.errors) || 0, 'error')];
106
+ if (num(c.warnings)) parts.push(plural(c.warnings, 'warning'));
107
+ return parts.join(' · ');
108
+ }
109
+ const parts = [`${num(c.passed) || 0} passed`];
110
+ if (num(c.failed)) parts.push(`${c.failed} failed`);
111
+ if (num(c.skipped)) parts.push(`${c.skipped} skipped`);
112
+ return parts.join(' · ');
113
+ }
114
+ // One check as a row: {index, state (pass, fail, running, unknown), kind, command, full, exit, time, since, counts, tail}
115
+ function checkRow(c, now) {
116
+ const running = c.running === true;
117
+ const state = running ? 'running' : c.failed === true ? 'fail' : c.exit === 0 ? 'pass' : num(c.exit) !== null ? 'fail' : 'unknown';
118
+ const took = running ? since(c.started, now) : num(c.duration_s);
119
+ return { index: num(c.index), state, kind: KIND[c.kind] || String(c.kind || 'check'), command: firstLine(c.command),
120
+ full: String(c.command || ''), exit: !running && num(c.exit) !== null ? 'exit ' + c.exit : null,
121
+ time: took === null ? null : dur(took), since: running ? num(c.started) : null, counts: countsText(c.counts), tail: c.tail || null };
122
+ }
123
+ // Which acceptance-criteria checks an attempt's agents ran: {total, ran, similar: [cmd], missing: [cmd], text}, or null
124
+ function coverageModel(criteria) {
125
+ const items = list(criteria).filter(c => c && typeof c === 'object');
126
+ if (!items.length) return null;
127
+ const of = status => items.filter(c => c.status === status).map(c => String(c.command));
128
+ const ran = of('ran').length;
129
+ return { total: items.length, ran, similar: of('similar'), missing: of('missing'),
130
+ text: `${ran} of ${items.length} acceptance-criteria check${items.length === 1 ? '' : 's'} ran as written` };
131
+ }
132
+ // The environment problems that several tasks met, for the run header's banner
133
+ const bannerProblems = (env, least = 2) => list(env && env.problems).filter(p => p && list(p.tasks).length >= least);
134
+ // The run inspector's scheduler fields: [[label, text]], or null when no scheduler runs the plan
135
+ function schedulerModel(run) {
136
+ const s = run && run.scheduler;
137
+ if (!s || s.live !== true) return null;
138
+ const tasks = list(run.tasks), count = kind => tasks.filter(t => t.waiting && t.waiting.kind === kind).length;
139
+ const state = s.stopping ? (s.stopping === 'now' ? 'stopping now' : 'stopping once its running tasks end') : s.drained ? 'drained: nothing new starts' : 'dispatching';
140
+ const waiting = [['deps', 'on dependencies'], ['overlap', 'on shared files'], ['slot', 'for a free slot'], ['infra', 'paused'],
141
+ ['next', 'next'], ['escalation', 'stopped by the retry policy']]
142
+ .map(([kind, label]) => [count(kind), label]).filter(([n]) => n).map(([n, label]) => `${n} ${label}`);
143
+ const rows = [['Scheduler', state], ['Running', String(tasks.filter(t => t.status === 'RUNNING').length) + (num(s.max_parallel) !== null ? ` of ${s.max_parallel} slots` : '')]];
144
+ if (waiting.length) rows.push(['Waiting', waiting.join(' · ')]);
145
+ return rows;
146
+ }
147
+
148
+ /* ---------- DOM ---------- */
149
+ const cache = new Map(); // path → { data, error, pending, fresh, at }
150
+ function el(tag, text, className) {
151
+ const node = document.createElement(tag);
152
+ if (text !== undefined && text !== null) node.textContent = String(text);
153
+ if (className) node.className = className;
154
+ return node;
155
+ }
156
+ function section(parent, title, cls) {
157
+ const s = el('section', undefined, 'insp-section' + (cls ? ' ' + cls : ''));
158
+ s.append(el('h3', title)); parent.append(s); return s;
159
+ }
160
+ function load(ctx, path, fresh) {
161
+ const c = cache.get(path);
162
+ if (c && (c.fresh === fresh || c.pending)) return c;
163
+ const entry = { pending: true, fresh, data: c ? c.data : null, error: null, at: Date.now() };
164
+ cache.set(path, entry);
165
+ for (const old of cache.keys()) if (cache.size > 40 && old !== path) cache.delete(old);
166
+ ctx.fetchJSON(path).then(data => { entry.data = data; entry.error = null; }, err => { entry.error = err; })
167
+ .finally(() => { entry.pending = false; ctx.rerender(); });
168
+ return entry;
169
+ }
170
+ const enc = encodeURIComponent;
171
+ const taskPath = (run, id) => `/api/runs/${enc(run.key)}/tasks/${enc(id)}/checks`;
172
+ const execPath = (run, name) => `/api/runs/${enc(run.key)}/executions/${enc(name)}/checks`;
173
+ // a finished task's checks never change; a running one's are read again when the run moved
174
+ const freshness = (run, task) => task && task.status === 'RUNNING' ? 'live:' + run.updated : `done:${task && task.status}:${task && task.attempt}`;
175
+ function timeNode(start, now, cls) {
176
+ const n = el('span', dur(since(start, now)), 'vfy-num ' + (cls || 'now-time'));
177
+ if (num(start) !== null) n.dataset.since = String(start);
178
+ return n;
179
+ }
180
+ function quietNode(lastOutput, now) {
181
+ const t = quietText(lastOutput, now), n = el('span', t || '', 'warn now-quiet');
182
+ n.hidden = !t;
183
+ if (num(lastOutput) !== null) n.dataset.quiet = String(lastOutput);
184
+ return n;
185
+ }
186
+ function untilNode(until, now) {
187
+ const n = el('span', untilText(until, now), 'vfy-num now-until');
188
+ n.dataset.until = String(until);
189
+ return n;
190
+ }
191
+ function taskLinks(parent, ctx, tasks) {
192
+ tasks.forEach((t, i) => {
193
+ if (i) parent.append(document.createTextNode(', '));
194
+ const a = el('a', t.id, 'mono'); a.href = ctx.hash({ kind: 'task', id: t.id });
195
+ parent.append(a);
196
+ if (t.stopped) parent.append(el('span', ' (stopped)', 'warn'));
197
+ });
198
+ }
199
+ // Brings the times under `root` up to `now` (epoch seconds) between redraws.
200
+ function tick(rootNode, now) {
201
+ if (!rootNode || !rootNode.querySelectorAll || num(now) === null) return;
202
+ for (const n of rootNode.querySelectorAll('[data-since]')) n.textContent = dur(since(Number(n.dataset.since), now));
203
+ for (const n of rootNode.querySelectorAll('[data-until]')) n.textContent = untilText(Number(n.dataset.until), now) || '';
204
+ for (const n of rootNode.querySelectorAll('[data-quiet]')) { const t = quietText(Number(n.dataset.quiet), now); n.textContent = t || ''; n.hidden = !t; }
205
+ }
206
+
207
+ // The task table's Now cell
208
+ function cell(task, now, ctx) {
209
+ const box = el('span', undefined, 'now-cell');
210
+ const m = nowModel(task);
211
+ if (m) {
212
+ if (m.call) {
213
+ const code = el('code', m.call.text, 'now-call'); code.title = m.call.command || m.call.text;
214
+ box.append(code, timeNode(m.call.since, now));
215
+ } else box.append(el('span', `${m.who}${m.phase ? ' · ' + m.phase : ''}`, 'now-who'), timeNode(m.phaseSince, now));
216
+ box.append(quietNode(m.quietSince, now));
217
+ return box;
218
+ }
219
+ const w = waitingModel(task && task.waiting);
220
+ if (!w) { box.append(el('span', '—', 'muted')); return box; }
221
+ box.classList.add('now-waiting');
222
+ box.append(el('span', w.text + (w.tasks.length ? ' ' : ''), 'now-why'));
223
+ taskLinks(box, ctx, w.tasks);
224
+ if (w.until !== null) box.append(untilNode(w.until, now));
225
+ if (w.exhausted) box.append(el('span', 'waits used up', 'warn'));
226
+ return box;
227
+ }
228
+
229
+ // The task inspector's Now section: what it does, or why it waits
230
+ function nowSection(host, ctx, task) {
231
+ const m = nowModel(task), w = m ? null : waitingModel(task.waiting);
232
+ if (!m && !w) return;
233
+ const s = section(host, 'Now', 'now-section');
234
+ const box = el('div', undefined, 'vfy-live now-live');
235
+ if (m) {
236
+ const exec = list(task.executions).find(e => e.id === m.execution);
237
+ const who = el('p', undefined, 'vfy-now');
238
+ who.append(el('span', m.who, 'now-role'));
239
+ const spec = exec && exec.model && exec.model.spec;
240
+ if (spec && root.ForgeIcons) who.append(document.createTextNode(' '), root.ForgeIcons.modelPlate(spec));
241
+ if (m.attempt !== null) who.append(el('span', ` · attempt ${m.attempt}`, 'muted'));
242
+ if (m.phase) who.append(el('span', ` · ${m.phase} for `, 'muted'), timeNode(m.phaseSince, ctx.now));
243
+ box.append(who);
244
+ const call = el('p', undefined, 'vfy-now now-doing');
245
+ if (m.call) {
246
+ call.append(el('span', m.call.command ? 'runs ' : 'calls ', 'muted'));
247
+ const code = el('code', m.call.text, 'now-call'); code.title = m.call.command || m.call.text;
248
+ call.append(code);
249
+ if (m.call.check) call.append(el('span', KIND[m.call.check] || m.call.check, 'tag'));
250
+ call.append(el('span', ' for ', 'muted'), timeNode(m.call.since, ctx.now));
251
+ } else if (m.role === 'dwarf' || m.role === 'qa') call.append(el('span', 'no call running: the model is thinking or writing', 'muted'));
252
+ if (call.childNodes.length) box.append(call);
253
+ if (m.quietSince !== null) {
254
+ const last = el('p', undefined, 'vfy-now muted');
255
+ last.append(document.createTextNode('last output '), timeNode(m.quietSince, ctx.now), document.createTextNode(' ago'));
256
+ box.append(last);
257
+ }
258
+ const quiet = quietNode(m.quietSince, ctx.now); quiet.classList.add('vfy-idle');
259
+ box.append(quiet);
260
+ if (m.execution && (m.role === 'dwarf' || m.role === 'qa') && ctx.convoHash) {
261
+ const a = el('a', 'Follow it in its conversation →', 'diff-link small');
262
+ a.href = ctx.convoHash({ kind: 'execution', task: task.id === 'solo' ? null : task.id, id: task.id, exec: m.execution });
263
+ box.append(a);
264
+ }
265
+ } else {
266
+ const p = el('p', undefined, 'vfy-now');
267
+ p.append(el('span', w.text + (w.tasks.length ? ' ' : '')));
268
+ taskLinks(p, ctx, w.tasks);
269
+ if (w.until !== null) p.append(document.createTextNode(' · '), untilNode(w.until, ctx.now));
270
+ if (w.exhausted) p.append(el('span', ' · its waits are used up', 'warn'));
271
+ box.append(p);
272
+ if (w.split) {
273
+ const d = el('details', undefined, 'now-split'); d.dataset.keep = `now-split-${task.id}`;
274
+ d.append(el('summary', 'The split it suggests'), el('pre', w.split));
275
+ box.append(d);
276
+ }
277
+ }
278
+ s.append(box);
279
+ }
280
+
281
+ // One execution's checks, its environment problems and, while it runs, its call
282
+ function execChecks(parent, ctx, task, data) {
283
+ const rows = list(data && data.checks).map(c => checkRow(c, ctx.now));
284
+ const target = { kind: 'execution', task: task && task.id !== 'solo' ? task.id : null, id: task ? task.id : null, exec: data.execution };
285
+ if (rows.length) {
286
+ const ul = el('ul', undefined, 'plain checks');
287
+ for (const r of rows) {
288
+ const li = el('li', undefined, 'check check-' + r.state);
289
+ const head = el('div', undefined, 'check-head');
290
+ head.append(el('i', undefined, 'lamp st-' + (r.state === 'unknown' ? 'unknown' : r.state)), el('span', r.kind, 'tag'));
291
+ const cmd = r.index !== null && ctx.convoHash ? el('a', r.command, 'mono check-cmd') : el('span', r.command, 'mono check-cmd');
292
+ if (cmd.tagName === 'A') cmd.href = ctx.convoHash(target, r.index);
293
+ cmd.title = r.full;
294
+ head.append(cmd);
295
+ const meta = el('span', undefined, 'check-meta vfy-num');
296
+ if (r.exit) meta.append(el('span', r.exit, r.state === 'fail' ? 'check-exit warn' : 'check-exit'));
297
+ if (r.since !== null) meta.append(timeNode(r.since, ctx.now));
298
+ else if (r.time) meta.append(el('span', r.time));
299
+ if (r.counts) meta.append(el('span', r.counts, 'check-counts'));
300
+ if (meta.childNodes.length) head.append(meta);
301
+ li.append(head);
302
+ if (r.tail) {
303
+ const d = el('details', undefined, 'check-tail'); d.dataset.keep = `check-${data.execution}-${r.index}`;
304
+ d.append(el('summary', 'last lines'), el('pre', r.tail));
305
+ li.append(d);
306
+ }
307
+ ul.append(li);
308
+ }
309
+ parent.append(ul);
310
+ } else if (data.state === 'done') parent.append(el('p', 'ran no tests, type checks or lints', 'muted checks-none'));
311
+ for (const hit of list(data.environment)) {
312
+ const p = el('p', undefined, 'check-env');
313
+ p.append(el('span', hit.label || hit.problem, 'check-env-what'));
314
+ const cmd = ctx.convoHash ? el('a', firstLine(hit.command), 'mono') : el('span', firstLine(hit.command), 'mono');
315
+ if (ctx.convoHash) cmd.href = ctx.convoHash(target, hit.index);
316
+ p.append(cmd);
317
+ if (hit.line) p.title = hit.line;
318
+ parent.append(p);
319
+ }
320
+ }
321
+
322
+ function coverageBlock(parent, cov, running) {
323
+ if (!cov) return;
324
+ const box = el('div', undefined, 'checks-criteria');
325
+ box.append(el('p', cov.text, cov.missing.length && !running ? 'warn checks-cov' : 'muted checks-cov'));
326
+ const items = [...cov.missing.map(c => [c, running ? 'not run yet' : 'not run']), ...cov.similar.map(c => [c, 'run another way'])];
327
+ if (items.length) {
328
+ const ul = el('ul', undefined, 'plain checks-missing');
329
+ for (const [command, why] of items) {
330
+ const li = el('li');
331
+ li.append(el('span', why + ': ', why === 'not run' ? 'warn' : 'muted'), el('code', command, 'mono'));
332
+ ul.append(li);
333
+ }
334
+ box.append(ul);
335
+ }
336
+ parent.append(box);
337
+ }
338
+
339
+ // The task inspector's attempts get their checks: one lazy read for the whole task.
340
+ function taskChecks(ctx, task) {
341
+ if (!ctx.fetchJSON || !task) return null;
342
+ return load(ctx, taskPath(ctx.run, task.id), freshness(ctx.run, task));
343
+ }
344
+ // under an attempt's dwarf or reviewer line
345
+ function underExecution(parent, ctx, task, entry, attempt, exec) {
346
+ const a = entry && entry.data && list(entry.data.attempts).find(x => x.attempt === attempt);
347
+ const data = a && list(a.executions).find(x => x.execution === exec);
348
+ if (!data) return;
349
+ const box = el('div', undefined, 'checks-of');
350
+ execChecks(box, ctx, task, data);
351
+ if (box.childNodes.length) parent.append(box);
352
+ }
353
+ // at the foot of an attempt's box
354
+ function attemptCriteria(parent, entry, attempt) {
355
+ const a = entry && entry.data && list(entry.data.attempts).find(x => x.attempt === attempt);
356
+ if (a) coverageBlock(parent, coverageModel(a.criteria), a.running === true);
357
+ }
358
+ function loadingLine(parent, entry) {
359
+ if (!entry) return;
360
+ if (entry.error && !entry.data) {
361
+ parent.append(el('p', entry.error.snapshot ? 'The checks are not in this export: it was made without prompts and texts.'
362
+ : `Could not read the checks${entry.error.status === 404 ? ': this server predates them (forge ui open restarts it)' : ''}.`, 'muted'));
363
+ } else if (!entry.data) parent.append(el('p', 'Reading the checks each agent ran…', 'muted'));
364
+ }
365
+
366
+ // The execution inspector's Checks section
367
+ function execSection(host, ctx, task, sel, brief) {
368
+ const role = brief ? brief.role : String(sel.exec).split('-')[0];
369
+ if (role !== 'dwarf' && role !== 'qa') return;
370
+ const s = section(host, 'Checks', 'checks-section');
371
+ const fresh = brief && brief.state === 'done' ? 'done' : 'live:' + ctx.run.updated;
372
+ const entry = load(ctx, execPath(ctx.run, sel.exec), fresh);
373
+ loadingLine(s, entry);
374
+ const d = entry.data;
375
+ if (!d) return;
376
+ if (d.call && d.state === 'running') {
377
+ const p = el('p', undefined, 'vfy-now now-doing');
378
+ p.append(el('span', d.call.command ? 'runs ' : 'calls ', 'muted'), el('code', firstLine(d.call.command) || d.call.tool || 'a call', 'now-call'),
379
+ el('span', ' for ', 'muted'), timeNode(d.call.started, ctx.now));
380
+ s.append(p);
381
+ }
382
+ execChecks(s, ctx, task, d);
383
+ coverageBlock(s, coverageModel(d.criteria), d.state === 'running');
384
+ }
385
+
386
+ // The run inspector's scheduler fields, under its timeline
387
+ function schedulerFields(parent, run, now) {
388
+ const rows = schedulerModel(run);
389
+ if (!rows) return;
390
+ const dl = el('dl', undefined, 'fields');
391
+ for (const [label, value] of rows) { dl.append(el('dt', label), el('dd', value)); }
392
+ for (const p of list(run.scheduler.pauses)) {
393
+ const w = waitingModel({ ...p, kind: 'infra' });
394
+ const dd = el('dd', w.text);
395
+ if (w.until !== null) dd.append(document.createTextNode(' · '), untilNode(w.until, now));
396
+ if (w.exhausted) dd.append(el('span', ' · its waits are used up', 'warn'));
397
+ dl.append(el('dt', 'Paused'), dd);
398
+ }
399
+ parent.append(dl);
400
+ }
401
+
402
+ // The run header's banner: environment problems more than one task met
403
+ const banners = new Map(); // run key → { entry, updated, at }
404
+ function banner(head, ctx) {
405
+ const run = ctx.run, path = `/api/runs/${enc(run.key)}/environment`;
406
+ const running = list(run.tasks).some(t => t.status === 'RUNNING');
407
+ const c = cache.get(path);
408
+ // once per change of the run, and while it runs at most every fifteen seconds
409
+ const due = !c || (c.fresh !== run.updated && (!running || Date.now() - c.at > ENV_EVERY_S * 1000));
410
+ const entry = due ? load(ctx, path, run.updated) : c;
411
+ const problems = bannerProblems(entry && entry.data);
412
+ if (!problems.length) return;
413
+ const box = el('div', undefined, 'env-banner'); box.setAttribute('role', 'note');
414
+ box.append(el('span', 'Environment', 'plate'));
415
+ const ul = el('ul', undefined, 'plain env-list');
416
+ for (const p of problems) {
417
+ const li = el('li', undefined, 'env-problem');
418
+ const head2 = el('span', undefined, 'env-head');
419
+ head2.append(el('strong', p.label || p.problem), el('span', ` in ${plural(list(p.tasks).length, 'task')}: `, 'muted'));
420
+ list(p.tasks).forEach((id, i) => {
421
+ if (i) head2.append(document.createTextNode(', '));
422
+ const a = el('a', id, 'mono'); a.href = ctx.hash({ kind: 'task', id });
423
+ head2.append(a);
424
+ });
425
+ li.append(head2);
426
+ const d = el('details', undefined, 'env-hits'); d.dataset.keep = `env-${p.problem}`;
427
+ d.append(el('summary', `${plural(num(p.count) || list(p.hits).length, 'failed command')}, what they said`));
428
+ const hits = el('ul', undefined, 'plain env-hit-list');
429
+ for (const h of list(p.hits)) {
430
+ const item = el('li');
431
+ const where = el('span', `${h.task} · attempt ${h.attempt ?? '?'} · ${ROLE[h.role] || h.role}: `, 'muted');
432
+ const cmd = ctx.convoHash ? el('a', firstLine(h.command), 'mono') : el('span', firstLine(h.command), 'mono');
433
+ if (ctx.convoHash) cmd.href = ctx.convoHash({ kind: 'execution', task: h.task === 'solo' ? null : h.task, id: h.task, exec: h.execution }, h.index);
434
+ item.append(where, cmd);
435
+ if (h.line) item.append(el('div', h.line, 'mono env-line'));
436
+ hits.append(item);
437
+ }
438
+ d.append(hits);
439
+ li.append(d);
440
+ ul.append(li);
441
+ }
442
+ box.append(ul);
443
+ head.append(box);
444
+ }
445
+
446
+ return { dur, quietText, untilText, nowModel, waitingModel, nowRank, countsText, checkRow, coverageModel, bannerProblems,
447
+ schedulerModel, tick, cell, nowSection, taskChecks, underExecution, attemptCriteria, loadingLine, execSection,
448
+ schedulerFields, banner, QUIET_WARN_S, cache };
449
+ });