@giamme/forge 0.12.0 → 0.12.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,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
+ });
@@ -4,7 +4,7 @@
4
4
  apart, and while the agent runs a poll every few seconds that follows the end. Defines window.ForgeConvo.render(host, ctx).
5
5
  All API values enter the DOM as text.
6
6
  ctx = { run, spec: {task, exec}, brief (the Execution, when the run lists it), live (false in an export), fetchJSON(path),
7
- rerender(), closeHref, diffHash(spec) → hash } */
7
+ rerender(), closeHref, diffHash(spec) → hash, focus (the index of an event to open it at, or null) } */
8
8
  window.ForgeConvo = (() => {
9
9
  'use strict';
10
10
  const list = v => Array.isArray(v) ? v : [];
@@ -248,7 +248,10 @@ window.ForgeConvo = (() => {
248
248
  if (!errs.length) return;
249
249
  v.err = (v.err == null ? -1 : v.err) + 1;
250
250
  if (v.err >= errs.length) v.err = 0;
251
- const n = errs[v.err];
251
+ reveal(f, v, errs[v.err]);
252
+ }
253
+ // an event brought into view: shown whatever the filter, its folds open, focused and flashed
254
+ function reveal(f, v, n) {
252
255
  if (n.hidden) { v.query = ''; v.show = 'all'; f.search.value = ''; filter(f, v); }
253
256
  for (const d of n.querySelectorAll('details')) d.open = true;
254
257
  n.scrollIntoView({ block: 'center' }); n.focus({ preventScroll: true });
@@ -282,6 +285,12 @@ window.ForgeConvo = (() => {
282
285
  f.status.replaceChildren(...status);
283
286
  const grew = events(f, ctx, D, v);
284
287
  filter(f, v);
288
+ // opened at one event (a check, an environment problem): brought into view once, and the end is no longer followed
289
+ const at = Number.isInteger(ctx.focus) ? f.nodes[ctx.focus] : null;
290
+ if (at && f.focused !== ctx.focus) {
291
+ f.focused = ctx.focus; v.follow = false; f.follow.setAttribute('aria-pressed', 'false');
292
+ requestAnimationFrame(() => { if (at.isConnected) reveal(f, v, at); });
293
+ }
285
294
  if (running && v.follow && (grew || fresh)) requestAnimationFrame(() => end(f));
286
295
  // a log still being written: read it again shortly, while this view shows it
287
296
  if (running && !entry.timer) {
@@ -17,14 +17,15 @@
17
17
  const list = v => Array.isArray(v) ? v : [];
18
18
  const SEVERITIES = ['P0', 'P1', 'P2', 'P3'];
19
19
  const ORIGINS = ['tolerated', 'accepted', 'review', 'plausible'];
20
- const STATUSES = ['open', 'filed', 'fixed', 'dismissed'];
20
+ const STATUSES = ['open', 'filed', 'fixed', 'swept', 'dismissed'];
21
21
 
22
22
  /* ---------- pure ---------- */
23
- // open | filed (its issue is OPEN, or its state is not known yet) | fixed (CLOSED) | dismissed. A dismissal wins, so
24
- // that an Undismiss reaches every dismissed row.
23
+ // open | filed (its issue is OPEN, or its state is not known yet) | fixed (CLOSED) | swept (the run's finding sweep
24
+ // fixed it: nothing to file) | dismissed. A dismissal wins, so that an Undismiss reaches every dismissed row.
25
25
  function statusOf(f) {
26
26
  if (f && f.dismissed) return 'dismissed';
27
27
  if (f && f.filed) return String(f.filed.state || '').toUpperCase() === 'CLOSED' ? 'fixed' : 'filed';
28
+ if (f && f.swept) return 'swept';
28
29
  return 'open';
29
30
  }
30
31
  // filter = { status: 'open' (default) | 'all' | one of STATUSES, severity: 'all' | P0..P3, origin: 'all' | ORIGINS }
@@ -246,9 +247,10 @@
246
247
  };
247
248
  const statusCell = r => {
248
249
  const st = statusOf(r), box = el('span', undefined, 'fnd-status fnd-' + st);
249
- box.append(el('i', undefined, 'lamp ' + (st === 'filed' ? 'fnd-amber' : st === 'fixed' ? 'st-pass' : 'lamp-off')));
250
+ box.append(el('i', undefined, 'lamp ' + (st === 'filed' ? 'fnd-amber' : st === 'fixed' || st === 'swept' ? 'st-pass' : 'lamp-off')));
250
251
  if (st === 'dismissed') { box.title = r.dismissed.reason ? String(r.dismissed.reason) : 'dismissed'; box.append(el('span', 'dismissed')); return box; }
251
252
  if (st === 'open') { box.append(el('span', 'open')); return box; }
253
+ if (st === 'swept') { box.title = `fixed in the run by ${r.swept.task} (${r.swept.finding})`; box.append(el('span', 'swept')); return box; }
252
254
  const url = safeUrl(r.filed && r.filed.url), word = st === 'filed' ? 'filed' : 'fixed';
253
255
  if (url) { const a = el('a', word); a.href = url; a.target = '_blank'; a.rel = 'noopener noreferrer'; a.title = 'the GitHub issue (' + String(r.filed.state || 'state unknown').toLowerCase() + ')'; box.append(a); }
254
256
  else box.append(el('span', word));
@@ -26,6 +26,7 @@
26
26
  <script src="gantt.js" defer></script>
27
27
  <script src="controls.js" defer></script>
28
28
  <script src="verifyview.js" defer></script>
29
+ <script src="checksview.js" defer></script>
29
30
  <script src="panel.js" defer></script>
30
31
  <script src="diffview.js" defer></script>
31
32
  <script src="convo.js" defer></script>
@@ -5,6 +5,7 @@
5
5
  window.ForgePanel = (() => {
6
6
  'use strict';
7
7
  const RM = window.ForgeRunModel;
8
+ const C = window.ForgeChecks || null; // checksview.js: Now, checks, the scheduler
8
9
  const list = v => Array.isArray(v) ? v : [];
9
10
  const num = v => typeof v === 'number' && Number.isFinite(v) ? v : null;
10
11
  const display = v => v === null || v === undefined || v === '' ? '—' : typeof v === 'object' ? JSON.stringify(v, null, 2) : String(v);
@@ -220,6 +221,7 @@ window.ForgePanel = (() => {
220
221
  const s = section(host, 'Timeline');
221
222
  fields(s, [['Started', time(tr && tr.start)], ['Last activity', time(tr && tr.end)], ['Wall time', tr ? RM.fmtDur(tr.end - tr.start) : '—'],
222
223
  ['Concurrency limit', run.settings && run.settings.max_parallel != null ? run.settings.max_parallel : (run.kind === 'solo' ? '—' : '3 (default; not recorded)')]]);
224
+ if (C) C.schedulerFields(s, run, now);
223
225
  if (run.kind !== 'solo') {
224
226
  const cp = RM.criticalPath(run, { now });
225
227
  if (cp.ids.length) {
@@ -252,6 +254,14 @@ window.ForgePanel = (() => {
252
254
  ['Final review', finalValue]]);
253
255
  if (F.final.status === 'OUTDATED') muted(f, RM.reviewSinceLine(F.final));
254
256
  if (F.final.findings) findingCounts(f, F.final.findings);
257
+ const sweep = RM.sweepLine(run.sweep);
258
+ if (sweep) {
259
+ fields(f, [['Finding sweep', `${sweep} (${display(run.sweep.severity)} and worse)`]]);
260
+ const left = list(run.sweep.dropped);
261
+ if (left.length) details(f, `Left for forge issues by the sweep (${left.length})`,
262
+ left.map(d => `[${display(d.severity)}] ${display(d.location)} — ${display(d.summary)} (task ${display(d.task)}): ${display(d.reason)}${list(d.merged_since).length ? ' after ' + d.merged_since.join(', ') : ''}`).join('\n'),
263
+ 'sweep-left');
264
+ }
255
265
  }
256
266
  if (list(run.deferrals).length) details(host, `Deferred tasks (${run.deferrals.length})`, run.deferrals.join('\n'), 'deferrals');
257
267
  controlsSection(host, ctx);
@@ -259,6 +269,30 @@ window.ForgePanel = (() => {
259
269
  muted(host, 'Select a task, an attempt or a finish node on the map or in the table to see its prompts, models, timings and findings.');
260
270
  }
261
271
 
272
+ // A finding sweep's fix task: the findings it took and what its review said of each. A task whose findings a
273
+ // fix task took: which, and where that stands.
274
+ function sweepSection(host, ctx, task) {
275
+ const own = task.sweep && list(task.sweep.findings), took = list(task.swept);
276
+ if (!(own && own.length) && !took.length) return;
277
+ const s = section(host, own && own.length ? 'Finding sweep' : 'Taken by the finding sweep');
278
+ if (own && own.length) muted(s, `A fix task: the open findings of earlier tasks in ${display(task.sweep.file)}, with a narrow review of each.`);
279
+ const ul = el('ul', undefined, 'plain sweep-list');
280
+ for (const f of own && own.length ? own : took) {
281
+ const st = RM.sweepState(f.status), li = el('li', undefined, 'sweep-item');
282
+ const head = el('div', undefined, 'sweep-head');
283
+ head.append(el('i', undefined, 'lamp st-' + st.lamp), sevChip(f.severity || '—', f.severity), el('span', f.location || '—', 'mono sweep-where'));
284
+ li.append(head, el('p', f.summary || '', 'sweep-what'));
285
+ const meta = el('p', undefined, 'sweep-meta');
286
+ meta.append(document.createTextNode(`${f.id} · ${st.text}`));
287
+ const other = own && own.length ? f.task : f.by;
288
+ if (other) { meta.append(document.createTextNode(own && own.length ? ' · from ' : ' · by ')); meta.append(link(other, ctx.hash({ kind: 'task', id: other }), () => ctx.onSelect({ kind: 'task', id: other }))); }
289
+ if (f.note) meta.append(document.createTextNode(' — ' + f.note));
290
+ li.append(meta);
291
+ ul.append(li);
292
+ }
293
+ s.append(ul);
294
+ }
295
+
262
296
  function taskView(host, ctx, task) {
263
297
  const run = ctx.run, now = ctx.now, solo = run.kind === 'solo';
264
298
  const head = el('div', undefined, 'insp-head');
@@ -275,6 +309,8 @@ window.ForgePanel = (() => {
275
309
  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);
276
310
  host.append(head);
277
311
  if (!solo) fields(host, [['Difficulty', task.difficulty], ['Depends on', depLinks(task.deps, ctx)], ['Files', list(task.files).join('\n') || '—', true], ['Branch', task.branch, true]]);
312
+ if (C) C.nowSection(host, ctx, task);
313
+ sweepSection(host, ctx, task);
278
314
 
279
315
  // the models: who owned it, how it was routed, what it was escalated to
280
316
  const ms = section(host, 'Models');
@@ -298,6 +334,9 @@ window.ForgePanel = (() => {
298
334
  const as = section(host, 'Attempts');
299
335
  const tp = RM.taskParts(task), usedEscalations = new Set();
300
336
  if (!list(task.executions).length) muted(as, 'No executions recorded yet' + (task.status === 'PENDING' ? ': this task has not started.' : '.'));
337
+ // the checks each agent ran, read once for the whole task
338
+ const checks = C && list(task.executions).length ? C.taskChecks(ctx, task) : null;
339
+ if (checks) C.loadingLine(as, checks);
301
340
  for (const z of tp.zones) {
302
341
  const box = el('div', undefined, 'attempt');
303
342
  const row = list(task.attempts).filter(a => a.attempt === z.attempt).pop();
@@ -320,7 +359,9 @@ window.ForgePanel = (() => {
320
359
  if ((p.kind === 'qa' || p.kind === 'shadow') && p.exec && p.exec.id) { const a = diffLink(ctx, 'diff it read', { kind: 'task', task: task.id, source: p.exec.id }, 'diff-link small'); if (a) go.append(a); }
321
360
  if (go.childElementCount) line.append(go);
322
361
  box.append(line);
362
+ if (checks && (p.kind === 'dwarf' || p.kind === 'qa') && p.exec && p.exec.id) C.underExecution(box, ctx, task, checks, z.attempt, p.exec.id);
323
363
  }
364
+ if (checks) C.attemptCriteria(box, checks, z.attempt);
324
365
  for (const l of tp.links.filter(l => l.kind === 'escalation' && z.parts.includes(l.to))) {
325
366
  const line = el('p', `escalated: ${l.label} `, 'muted');
326
367
  const e = list(task.escalations).find(x => !usedEscalations.has(x) && `${x.from || '?'} → ${x.to || '?'}` === l.label); // the link carries only its label
@@ -418,6 +459,7 @@ window.ForgePanel = (() => {
418
459
  if (entry.data) findingsList(rs, entry.data.findings, `exec-${sel.exec}`); else loading(rs, entry, 'the findings');
419
460
  }
420
461
  }
462
+ if (C) C.execSection(host, ctx, task, sel, e);
421
463
  const ps = section(host, 'Prompt and output');
422
464
  if (loading(ps, entry, 'the prompt')) return;
423
465
  const d = entry.data;