@giamme/forge 0.17.0 → 0.19.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 (110) hide show
  1. package/CHANGELOG.md +57 -0
  2. package/README.md +1 -0
  3. package/SKILL.md +32 -5
  4. package/VERSION +1 -1
  5. package/docs/artifacts.md +33 -1
  6. package/docs/commands.md +147 -16
  7. package/docs/dataset.md +5 -0
  8. package/docs/decomposed-runs.md +122 -1
  9. package/docs/development.md +2 -1
  10. package/docs/forge-ui.md +98 -8
  11. package/docs/memory.md +27 -4
  12. package/docs/models.md +8 -0
  13. package/docs/reviews.md +122 -0
  14. package/docs/safety.md +8 -0
  15. package/forge +44 -4
  16. package/package.json +2 -1
  17. package/references/dataset.md +39 -1
  18. package/references/decompose.md +737 -16
  19. package/references/harnesses.md +18 -3
  20. package/references/planning.md +43 -14
  21. package/references/solo.md +2 -1
  22. package/references/ui.md +56 -6
  23. package/registry.tsv +8 -3
  24. package/scripts/forge-artifact.sh +14 -0
  25. package/scripts/forge-brief.py +217 -0
  26. package/scripts/forge-compare.py +13 -2
  27. package/scripts/forge-config.py +176 -9
  28. package/scripts/forge-contract.py +246 -28
  29. package/scripts/forge-control.py +200 -15
  30. package/scripts/forge-dispatch.sh +48 -15
  31. package/scripts/forge-du.py +167 -0
  32. package/scripts/forge-group.py +496 -0
  33. package/scripts/forge-groups.py +89 -0
  34. package/scripts/forge-handoff.py +1128 -0
  35. package/scripts/forge-lib-adopt.sh +1 -0
  36. package/scripts/forge-lib-group.sh +641 -0
  37. package/scripts/forge-lib-plans.sh +343 -4
  38. package/scripts/forge-lib-review.sh +29 -1
  39. package/scripts/forge-lib-task.sh +197 -4
  40. package/scripts/forge-memory.sh +245 -3
  41. package/scripts/forge-metrics.sh +7 -3
  42. package/scripts/forge-parallel-options.sh +4 -0
  43. package/scripts/forge-parallel.sh +1216 -41
  44. package/scripts/forge-planner.py +104 -8
  45. package/scripts/forge-prompt.py +120 -0
  46. package/scripts/forge-retro.py +115 -0
  47. package/scripts/forge-route.py +190 -12
  48. package/scripts/forge-runs-compact.py +443 -0
  49. package/scripts/forge-runs-rm.py +2 -0
  50. package/scripts/forge-runs.py +27 -8
  51. package/scripts/forge-schedule.py +633 -49
  52. package/scripts/forge-shadow.py +7 -1
  53. package/scripts/forge-solo.sh +4 -0
  54. package/scripts/forge-summarize.py +698 -0
  55. package/scripts/forge-ui-options.sh +10 -0
  56. package/scripts/forge-worktrees.py +243 -0
  57. package/scripts/forge_brief/__init__.py +831 -0
  58. package/scripts/forge_brief/answers.py +506 -0
  59. package/scripts/forge_brief/proposals.py +1630 -0
  60. package/scripts/forge_dataset/__init__.py +10 -0
  61. package/scripts/forge_dataset/efforts.py +4 -3
  62. package/scripts/forge_dataset/export.py +36 -10
  63. package/scripts/forge_dataset/facts.py +8 -4
  64. package/scripts/forge_dataset/forecast.py +8 -18
  65. package/scripts/forge_dataset/harvest.py +241 -12
  66. package/scripts/forge_dataset/history.py +13 -6
  67. package/scripts/forge_dataset/importer.py +65 -1
  68. package/scripts/forge_dataset/names.py +66 -0
  69. package/scripts/forge_dataset/reviewers.py +5 -2
  70. package/scripts/forge_dataset/risk.py +6 -3
  71. package/scripts/forge_dataset/routing.py +6 -1
  72. package/scripts/forge_decide/__init__.py +11 -1
  73. package/scripts/forge_groups/__init__.py +308 -0
  74. package/scripts/forge_groups/attribute.py +289 -0
  75. package/scripts/forge_groups/review.py +286 -0
  76. package/scripts/forge_locations.py +366 -0
  77. package/scripts/forge_owner.py +152 -0
  78. package/scripts/forge_registry.py +19 -0
  79. package/scripts/forge_retro/__init__.py +417 -0
  80. package/scripts/forge_retro/issues.py +1193 -0
  81. package/scripts/forge_retro/report.py +671 -0
  82. package/scripts/forge_side/__init__.py +482 -0
  83. package/scripts/forge_storage.py +515 -0
  84. package/ui/README.md +68 -8
  85. package/ui/docs/api.md +375 -31
  86. package/ui/forge_ui/control.py +451 -11
  87. package/ui/forge_ui/executions.py +8 -1
  88. package/ui/forge_ui/export.py +53 -7
  89. package/ui/forge_ui/groups.py +264 -0
  90. package/ui/forge_ui/links.py +337 -0
  91. package/ui/forge_ui/models.py +125 -10
  92. package/ui/forge_ui/projects.py +4 -1
  93. package/ui/forge_ui/reader.py +919 -45
  94. package/ui/forge_ui/server.py +4 -0
  95. package/ui/forge_ui/static/app.js +173 -11
  96. package/ui/forge_ui/static/briefview.js +605 -0
  97. package/ui/forge_ui/static/checksview.js +6 -2
  98. package/ui/forge_ui/static/controls.js +5 -0
  99. package/ui/forge_ui/static/diffview.js +86 -1
  100. package/ui/forge_ui/static/groupsview.js +332 -0
  101. package/ui/forge_ui/static/index.html +4 -0
  102. package/ui/forge_ui/static/panel.js +394 -8
  103. package/ui/forge_ui/static/projectsview.js +189 -10
  104. package/ui/forge_ui/static/runmodel.js +27 -4
  105. package/ui/forge_ui/static/storageview.js +352 -0
  106. package/ui/forge_ui/static/style.css +176 -6
  107. package/ui/forge_ui/static/worktreesview.js +235 -14
  108. package/ui/forge_ui/storage.py +150 -0
  109. package/ui/forge_ui/transcripts.py +35 -10
  110. package/ui/forge_ui/worktrees.py +154 -13
@@ -1,6 +1,8 @@
1
1
  /* forge-ui inspector: what a selected node is, which model owned it, what prompt launched it, how long it
2
2
  took and what its reviewer found. Defines window.ForgePanel.render(host, ctx). All API values enter the
3
3
  DOM as text. Large texts (prompts, reports) come from the lazy endpoints and are fetched once per node.
4
+ A task opens on its header (title, goal, links, and the prompt, approach and acceptance criteria) and
5
+ its attempt trail, then its summary (#133 B), then its brief questions (#135) when it has them, and the chips and the rest.
4
6
  The run's and a task's write controls are controls.js's (ForgeControls); this file only says where they stand. */
5
7
  window.ForgePanel = (() => {
6
8
  'use strict';
@@ -10,8 +12,9 @@ window.ForgePanel = (() => {
10
12
  const num = v => typeof v === 'number' && Number.isFinite(v) ? v : null;
11
13
  const display = v => v === null || v === undefined || v === '' ? '—' : typeof v === 'object' ? JSON.stringify(v, null, 2) : String(v);
12
14
  const STATUSES = new Set(['merged', 'pass', 'running', 'pending', 'fail', 'error', 'infra', 'timeout', 'unknown', 'invalidated', 'blocked',
13
- 'interrupted', 'nochanges', 'conflict', 'accepted', 'none', 'outdated', 'needs_input', 'needs_decision', 'waiting']);
15
+ 'interrupted', 'nochanges', 'conflict', 'accepted', 'none', 'outdated', 'needs_input', 'needs_decision', 'waiting', 'implemented']);
14
16
  const cache = new Map(); // path → {data, error, at}
17
+ const shownText = new Map(); // task id → which header text is open (prompt, approach, criteria)
15
18
  function el(tag, text, className) {
16
19
  const node = document.createElement(tag);
17
20
  if (text !== undefined) node.textContent = display(text);
@@ -86,8 +89,9 @@ window.ForgePanel = (() => {
86
89
  const s = section(host, 'Controls');
87
90
  muted(s, 'Read-only: this page cannot change the run.');
88
91
  }
89
- // A task that stopped NEEDS_INPUT: the question it asked, and the command that answers it. forge-ui shows the
90
- // command and never runs it; only the user's answer, passed to retry, resumes the task.
92
+ // A task that stopped NEEDS_INPUT: the question it asked, and the command that answers it. The copy stays in
93
+ // every mode. When controls are on, a plan (not a solo run) can send the answer from here: that post is not
94
+ // destructive, so it needs no confirm. A solo run still shows only the question.
91
95
  const shellWord = s => /^[\w@%+=:,./-]+$/.test(s) ? s : "'" + String(s).replace(/'/g, "'\\''") + "'";
92
96
  // An INFRA task: why its dispatch stopped (the cause, the stage, the model it ran on), when its limit resets, and
93
97
  // whether the user must act: the reader's answer from forge's cause table (after the run too), else a live
@@ -115,6 +119,94 @@ window.ForgePanel = (() => {
115
119
  const line = el('div', undefined, 'waiting-cmd');
116
120
  line.append(el('pre', text, 'cmd'), copy);
117
121
  s.append(line);
122
+ const U = window.ForgeUI;
123
+ if (!U || !U.controlsEnabled) return;
124
+ // In the tree before controlsEnabled answers, with data-hold. A poll rebuilds this inspector
125
+ // through controls.js hold(), which only puts back a [data-hold][data-editing] node that the
126
+ // new tree already contains. Appending the box from the promise leaves the draft behind.
127
+ const box = answerField(ctx, task, U);
128
+ s.append(box);
129
+ U.controlsEnabled().then(on => {
130
+ if (!s.isConnected || on) return;
131
+ dropHold(s, 'answer:');
132
+ });
133
+ }
134
+ // The draft of one waiting task. data-editing is set while the field is in use, so hold() keeps
135
+ // this node (its text and its focus) instead of the empty one the next draw builds.
136
+ function answerField(ctx, task, U) {
137
+ const run = ctx.run || {};
138
+ const box = el('div', undefined, 'waiting-cmd');
139
+ box.dataset.hold = 'answer:' + run.key + ':' + task.id;
140
+ const field = el('textarea');
141
+ field.setAttribute('aria-label', 'Answer');
142
+ field.rows = 3;
143
+ field.maxLength = 8000;
144
+ field.autocomplete = 'off';
145
+ const send = el('button', 'Send answer'); send.type = 'button';
146
+ const msgs = el('div');
147
+ const mark = () => { box.dataset.editing = '1'; };
148
+ field.addEventListener('focus', mark);
149
+ field.addEventListener('input', mark);
150
+ field.addEventListener('blur', () => {
151
+ if (box.dataset.busy) return;
152
+ if (!String(field.value || '').trim()) delete box.dataset.editing;
153
+ });
154
+ send.addEventListener('click', () => { sendWaitingAnswer(box, field, send, msgs, ctx, task, U); });
155
+ box.append(field, send, msgs);
156
+ return box;
157
+ }
158
+ function dropHold(root, prefix) {
159
+ const pending = [root];
160
+ while (pending.length) {
161
+ const node = pending.pop();
162
+ for (const child of [...(node.children || [])]) {
163
+ if (child.dataset && String(child.dataset.hold || '').startsWith(prefix)) child.remove();
164
+ else pending.push(child);
165
+ }
166
+ }
167
+ }
168
+ // What the answer endpoint means for the page. `live` is the scheduler's word; anything else is the error
169
+ // sentence outcomeText already uses for every other write.
170
+ function answerLive(answer) {
171
+ if (!answer || typeof answer !== 'object' || answer.ok === false) return null;
172
+ const data = answer.data && typeof answer.data === 'object' ? answer.data : answer;
173
+ if (data.live === true) return true;
174
+ if (data.live === false) return false;
175
+ return null;
176
+ }
177
+ function answerOutcome(answer) {
178
+ const live = answerLive(answer);
179
+ if (live === true) return 'Queued: the running scheduler resumes the task';
180
+ if (live === false) return 'Prepared: the next run dispatches the task';
181
+ const say = window.ForgeUI && window.ForgeUI.outcomeText;
182
+ if (typeof say === 'function') return say(answer).text;
183
+ const r = answer || {};
184
+ return r.detail || r.error || 'failed';
185
+ }
186
+ async function sendWaitingAnswer(box, field, send, msgs, ctx, task, U) {
187
+ if (box.dataset.busy) return;
188
+ const text = String(field.value || '').trim();
189
+ if (!text) {
190
+ if (U && U.outcome) U.outcome(msgs, { ok: false, status: 400, error: 'invalid', detail: 'the answer is empty' });
191
+ return;
192
+ }
193
+ box.dataset.editing = '1';
194
+ box.dataset.busy = '1';
195
+ send.disabled = true;
196
+ const run = ctx.run || {};
197
+ const path = '/api/runs/' + encodeURIComponent(run.key) + '/tasks/' + encodeURIComponent(task.id) + '/answer';
198
+ let res = { ok: false, error: 'unavailable', detail: 'this page cannot send' };
199
+ try {
200
+ if (U && U.post) res = await U.post(path, { text });
201
+ } catch (_) {
202
+ res = { ok: false, error: 'failed', detail: 'could not send' };
203
+ }
204
+ if (!box.isConnected) return;
205
+ delete box.dataset.busy;
206
+ send.disabled = false;
207
+ if (!U || !U.outcome) return;
208
+ if (res && res.ok) U.outcome(msgs, res, answerOutcome(res));
209
+ else U.outcome(msgs, res);
118
210
  }
119
211
  // A task that stopped NEEDS_DECISION: why the retry policy stopped it, its attempts against the cap, the ledger of its
120
212
  // reviews, and the decision text, which holds the commands to run. forge-ui shows the commands and never runs them.
@@ -336,6 +428,15 @@ window.ForgePanel = (() => {
336
428
  const line = window.ForgeSettings && window.ForgeSettings.profileRowText && window.ForgeSettings.profileRowText(profile);
337
429
  return line || undefined;
338
430
  }
431
+ // the Retro section (retro mode only): the report's counts on one line, then the report, collapsed like the other long texts.
432
+ // The report is plain text: forge-ui has no Markdown renderer, and run data never goes in as HTML.
433
+ function retroSection(host, run) {
434
+ const line = RM.retroSummary(run.retro);
435
+ if (!line) return;
436
+ const s = section(host, 'Retro');
437
+ muted(s, line);
438
+ if (run.retro.text != null) details(s, 'Report', run.retro.text, 'run-retro');
439
+ }
339
440
  // the run's record: what it was asked, how it was set up, and what verification printed (the header names and counts it)
340
441
  function runRecord(host, ctx) {
341
442
  const run = ctx.run, solo = run.kind === 'solo';
@@ -348,9 +449,30 @@ window.ForgePanel = (() => {
348
449
  ['Verification', chip((run.verification && run.verification.status) || run.verification_status)],
349
450
  ['Command', run.verification && run.verification.command, true]]);
350
451
  details(host, 'Request', display(run.request), 'run-request');
452
+ retroSection(host, run);
351
453
  if (!solo) details(host, 'Waves', list(run.waves).map((ids, i) => `${i + 1}: ${list(ids).join(', ')}`).join('\n') || '—', 'waves');
352
454
  if (run.verification && run.verification.log_tail != null) details(host, 'Verification output', run.verification.log_tail, 'verification-output');
353
455
  }
456
+ // `after` is the predecessor; `followed_by` the plans that name this run. Run ids read as the
457
+ // other ids on the page (mono). The hash is the other run's page, the same shape app.js uses.
458
+ function chainRows(run) {
459
+ const rows = [];
460
+ const prev = run.after;
461
+ if (prev && typeof prev === 'object') {
462
+ const label = prev.run_id || prev.key;
463
+ if (label) rows.push(['After', link(label, '#/runs/' + encodeURIComponent(prev.key)), true]);
464
+ }
465
+ const next = list(run.followed_by).filter(item => item && (item.run_id || item.key));
466
+ if (next.length) {
467
+ const span = el('span');
468
+ next.forEach((item, i) => {
469
+ if (i) span.append(document.createTextNode(', '));
470
+ span.append(link(item.run_id || item.key, '#/runs/' + encodeURIComponent(item.key)));
471
+ });
472
+ rows.push(['Followed by', span, true]);
473
+ }
474
+ return rows;
475
+ }
354
476
  function runView(host, ctx) {
355
477
  const run = ctx.run, now = ctx.now;
356
478
  const tr = RM.timeRange(run, now);
@@ -372,10 +494,13 @@ window.ForgePanel = (() => {
372
494
  }
373
495
  const f = section(host, 'Finish');
374
496
  const F = RM.finishState(run);
497
+ // A chained plan: the one it starts from, and the ones that start from it. Each links to that
498
+ // run's page. A run in neither chain keeps this block as it was.
499
+ const chain = chainRows(run);
375
500
  if (run.kind === 'solo') {
376
501
  const soloTask = list(run.tasks)[0];
377
502
  const verdict = soloTask ? RM.taskVerdict(soloTask) : { text: null, status: 'unknown' };
378
- fields(f, [['Verdict', chip(verdict.text, verdict.status)]]);
503
+ fields(f, [['Verdict', chip(verdict.text, verdict.status)], ...chain]);
379
504
  }
380
505
  else {
381
506
  const finalSel = { kind: 'final' }, openFinal = () => ctx.onSelect(finalSel);
@@ -387,7 +512,7 @@ window.ForgePanel = (() => {
387
512
  } else finalValue = link(F.final.status === 'NONE' ? 'not requested' : F.final.status, ctx.hash(finalSel), openFinal);
388
513
  fields(f, [['Integration', link(`${F.integration.merged}/${F.integration.total} merged`, ctx.hash({ kind: 'integration' }), () => ctx.onSelect({ kind: 'integration' }))],
389
514
  ['Verification', link(F.verification.status, ctx.hash({ kind: 'verification' }), () => ctx.onSelect({ kind: 'verification' }))],
390
- ['Final review', finalValue]]);
515
+ ['Final review', finalValue], ...chain]);
391
516
  const attribution = RM.attributionLine(run.attribution);
392
517
  if (attribution) f.append(el('p', attribution, 'warn'));
393
518
  if (F.final.status === 'OUTDATED') muted(f, RM.reviewSinceLine(F.final));
@@ -431,17 +556,277 @@ window.ForgePanel = (() => {
431
556
  s.append(ul);
432
557
  }
433
558
 
559
+ // Why an attempt ran, in the words the trail shows. Anything else reads as unrecorded.
560
+ const TRAIL_REASONS = {
561
+ first: 'first attempt', review: 'after review findings', prereview: 'after failing tests before review',
562
+ bounce: 'after unaddressed findings', message: 'after an unfinished message', answer: 'after your answer',
563
+ escalation: 'escalated to a stronger model', manual: 'manual retry', unknown: 'reason not recorded',
564
+ };
565
+ function reasonText(reason) {
566
+ return Object.prototype.hasOwnProperty.call(TRAIL_REASONS, reason) ? TRAIL_REASONS[reason] : TRAIL_REASONS.unknown;
567
+ }
568
+ function findingsText(item) {
569
+ const findings = item && item.findings;
570
+ const has = !!findings && typeof findings === 'object' && !Array.isArray(findings);
571
+ const count = has ? (num(findings.confirmed) === null ? 0 : num(findings.confirmed)) : null;
572
+ const worst = item && item.worst ? String(item.worst) : '';
573
+ if (count === null && !worst) return 'no findings';
574
+ const n = count === null ? 0 : count;
575
+ const noun = n === 1 ? 'finding' : 'findings';
576
+ return worst ? `${n} ${noun} (worst ${worst})` : `${n} ${noun}`;
577
+ }
578
+ // `#2 grok:xhigh · FAIL · 3 findings (worst P1) · after review findings`
579
+ function trailLine(item) {
580
+ const row = item || {};
581
+ const attempt = row.attempt == null || row.attempt === '' ? '—' : row.attempt;
582
+ const dwarf = row.dwarf ? String(row.dwarf) : '—';
583
+ const verdict = row.verdict ? String(row.verdict) : '—';
584
+ return `#${attempt} ${dwarf} · ${verdict} · ${findingsText(row)} · ${reasonText(row.reason)}`;
585
+ }
586
+ // A header link: `#123` or `PR #45` when it has a number, the url itself otherwise.
587
+ // Only an http(s) url is opened; anything else is shown as text.
588
+ function linkModel(link) {
589
+ if (!link || typeof link !== 'object') return { label: 'link', href: null };
590
+ const href = typeof link.url === 'string' && /^https?:\/\//i.test(link.url) ? link.url : null;
591
+ let label = 'link';
592
+ if (link.kind === 'pr' && link.number != null) label = `PR #${link.number}`;
593
+ else if (link.number != null) label = `#${link.number}`;
594
+ else if (href) label = href;
595
+ return { label, href };
596
+ }
597
+ function linkChip(item) {
598
+ const model = linkModel(item);
599
+ if (!model.href) return el('span', model.label, 'task-link-text');
600
+ const a = el('a', model.label, 'chip');
601
+ a.href = model.href; a.target = '_blank'; a.rel = 'noopener noreferrer';
602
+ return a;
603
+ }
604
+ const textMissing = v => v == null || v === '';
605
+ // Prompt and approach come from the lazy task detail once it has landed, and from the task until then.
606
+ // Acceptance criteria is header.criteria, already on the task. A missing text disables its button.
607
+ function knownTexts(task, detail) {
608
+ if (detail && detail.data) {
609
+ const t = detail.data.texts || {};
610
+ return { prompt: t.prompt ?? null, approach: t.approach ?? null, settled: true };
611
+ }
612
+ return { prompt: task.prompt ?? null, approach: task.approach ?? null, settled: false };
613
+ }
614
+ function headerActions(header, texts) {
615
+ const h = header || {}, t = texts || {};
616
+ return [
617
+ { key: 'prompt', label: 'Prompt', disabled: textMissing(t.prompt), text: t.prompt ?? null },
618
+ { key: 'approach', label: 'Approach', disabled: textMissing(t.approach), text: t.approach ?? null },
619
+ { key: 'criteria', label: 'Acceptance criteria', disabled: textMissing(h.criteria), text: h.criteria ?? null },
620
+ ];
621
+ }
622
+ function revealBody(key, detail, action) {
623
+ if (key === 'criteria') return action && action.text != null ? String(action.text) : '';
624
+ if (detail && detail.error) {
625
+ const err = detail.error;
626
+ return err.status === 404 ? 'This text is not available from this server.' : `Could not load it: ${err.message || 'error'}`;
627
+ }
628
+ if (!detail || !detail.data) return 'Loading…';
629
+ return action && action.text != null ? String(action.text) : '';
630
+ }
631
+ function taskHeader(host, ctx, task, detail) {
632
+ const header = task.header || {};
633
+ const texts = knownTexts(task, detail);
634
+ const actions = headerActions(header, texts);
635
+ let open = shownText.get(task.id) || null;
636
+ if (open && actions.some(a => a.key === open && a.disabled && texts.settled)) { shownText.delete(task.id); open = null; }
637
+ const box = el('div', undefined, 'task-header');
638
+ const top = el('div', undefined, 'task-header-top');
639
+ top.append(el('h2', header.title || task.title || 'Untitled task'));
640
+ if (header.goal) top.append(el('p', header.goal, 'task-goal'));
641
+ box.append(top);
642
+ const links = list(header.links);
643
+ if (links.length) {
644
+ const row = el('div', undefined, 'chips task-links');
645
+ for (const item of links) row.append(linkChip(item));
646
+ box.append(row);
647
+ }
648
+ const bank = el('div', undefined, 'seg task-texts');
649
+ bank.setAttribute('role', 'group'); bank.setAttribute('aria-label', 'Task text');
650
+ for (const action of actions) {
651
+ const button = el('button', action.label);
652
+ button.type = 'button'; button.dataset.text = action.key; button.disabled = action.disabled;
653
+ button.setAttribute('aria-pressed', open === action.key ? 'true' : 'false');
654
+ button.addEventListener('click', () => {
655
+ shownText.set(task.id, shownText.get(task.id) === action.key ? null : action.key);
656
+ ctx.rerender();
657
+ });
658
+ bank.append(button);
659
+ }
660
+ box.append(bank);
661
+ if (open) {
662
+ const action = actions.find(a => a.key === open);
663
+ const pre = el('pre', revealBody(open, detail, action), 'task-reveal');
664
+ pre.dataset.scroll = `task-${task.id}-header-text`;
665
+ box.append(pre);
666
+ }
667
+ host.append(box);
668
+ }
669
+ // The links to an attempt's executions, one per execution, labelled by role. The trail and a summary's sources share them.
670
+ function executionLinks(ctx, task, ids) {
671
+ const nav = el('span', undefined, 'trail-nav');
672
+ for (const id of list(ids)) {
673
+ const role = String(id).split('-')[0].toLowerCase();
674
+ const target = { kind: 'execution', task: task.id, id: task.id, exec: id, shadow: false };
675
+ nav.append(link(role, ctx.hash(target), () => ctx.onSelect(target)));
676
+ }
677
+ return nav;
678
+ }
679
+ // One line per attempt. Its executions open the same way the Attempts section opens them.
680
+ function attemptTrail(host, ctx, task) {
681
+ const items = list(task.trail);
682
+ if (!items.length) return;
683
+ const ol = el('ol', undefined, 'attempt-trail');
684
+ for (const item of items) {
685
+ const li = el('li', undefined, 'trail-line');
686
+ li.append(el('span', trailLine(item), 'trail-summary'));
687
+ const nav = executionLinks(ctx, task, item && item.executions);
688
+ if (nav.childElementCount) li.append(nav);
689
+ ol.append(li);
690
+ }
691
+ host.append(ol);
692
+ }
693
+
694
+ /* ---------- summaries (#133 B): a task's generated summary, and the switches that turn summaries on or off ---------- */
695
+ // A switch's question, answer and request body are controls.js's (prepare, savedText); the confirm strip and the POST
696
+ // are uikit's. An answer stays on the page for a few seconds, so a poll that draws the section again keeps it in view.
697
+ const ANSWER_MS = 9000;
698
+ const answers = new Map(); // a section's hold key → {res, text, at}
699
+ const ago = (at, now) => window.ForgeControls ? window.ForgeControls.agoText(at, now) : time(at);
700
+ const findingsId = taskId => `task-${taskId}-findings`;
701
+ // A bank of push keys: the value in force is pressed, and pressing the pressed key does nothing.
702
+ function summaryBank(options, current, pick, label) {
703
+ const seg = el('div', undefined, 'seg sum-bank');
704
+ seg.setAttribute('role', 'group'); seg.setAttribute('aria-label', label);
705
+ for (const [value, text] of options) {
706
+ const b = el('button', text); b.type = 'button'; b.dataset.value = value;
707
+ b.setAttribute('aria-pressed', String(value === current));
708
+ b.addEventListener('click', () => { if (b.getAttribute('aria-pressed') !== 'true') pick(value); });
709
+ seg.append(b);
710
+ }
711
+ return seg;
712
+ }
713
+ // Asks, sends and answers one change to a summaries switch (`forge control set summaries`). `slot` takes the question
714
+ // and the answer. `held` is the section that holds a task's switch (null for the run's): it is kept as it is while the
715
+ // question is open or the answer pends, the way controls.js keeps its own sections.
716
+ function changeSummaries(slot, held, runKey, change, done) {
717
+ const C = window.ForgeControls, U = window.ForgeUI, node = held || slot;
718
+ const plan = C.prepare({ kind: 'set', key: 'summaries', input: change.input, task: change.task });
719
+ if (!plan.ok) { U.outcome(slot, { ok: false, status: 400, error: 'invalid', detail: plan.error }); return; }
720
+ if (node.dataset.busy) return;
721
+ node.dataset.editing = '1';
722
+ U.confirmInline(slot, plan.confirm).then(async yes => {
723
+ if (!yes) { if (!slot.querySelector('.ui-confirm')) delete node.dataset.editing; return; } // a newer question took the strip
724
+ node.dataset.busy = '1';
725
+ if (held) held.setAttribute('aria-busy', 'true');
726
+ const res = await U.post(`/api/runs/${encodeURIComponent(runKey)}/controls`, plan.body);
727
+ delete node.dataset.busy; delete node.dataset.editing;
728
+ if (held) held.removeAttribute('aria-busy');
729
+ const text = C.savedText(res.data);
730
+ if (held) answers.set(held.dataset.hold, { res, text, at: Date.now() });
731
+ U.outcome(slot, res, text);
732
+ if (done) done(res);
733
+ });
734
+ }
735
+ // The summary's text as plain text, its model and when it was made, whether the task changed since, the error of a
736
+ // failed try, and where it came from.
737
+ function summaryText(s, ctx, task, sum) {
738
+ s.append(el('p', sum.text, 'sum-text'));
739
+ const by = el('p', undefined, 'muted sum-by');
740
+ by.title = time(sum.generated_at);
741
+ by.append(document.createTextNode('Generated by '), sum.model ? plate(sum.model) : el('span', 'an unrecorded model'),
742
+ document.createTextNode(`, ${ago(sum.generated_at, ctx.now)}`));
743
+ if (sum.stale) by.append(document.createTextNode(' '), chip('Out of date', 'outdated'));
744
+ s.append(by);
745
+ if (sum.error) s.append(el('p', `The last try failed: ${String(sum.error).trim()}`, 'warn sum-error'));
746
+ if (list(sum.sources).length) s.append(sourceList(ctx, task, sum.sources));
747
+ }
748
+ // Where a summary came from: an attempt's executions, as the trail links them; a finding, linked to the review findings
749
+ // section. A source the task no longer has is named, not linked.
750
+ function sourceList(ctx, task, sources) {
751
+ const ul = el('ul', undefined, 'sum-sources');
752
+ for (const src of sources) {
753
+ const li = el('li'), ref = String(src.ref || '');
754
+ if (src.kind === 'attempt') {
755
+ li.append(el('span', `attempt ${ref}`));
756
+ const item = list(task.trail).find(t => t && String(t.attempt) === ref);
757
+ const nav = executionLinks(ctx, task, item && item.executions);
758
+ if (nav.childElementCount) li.append(nav);
759
+ } else {
760
+ const cut = ref.indexOf(':'), attempt = cut > 0 ? ref.slice(0, cut) : null, title = cut > 0 ? ref.slice(cut + 1) : ref;
761
+ const a = el('a', title || 'finding'); a.href = '#' + findingsId(task.id);
762
+ a.addEventListener('click', e => {
763
+ e.preventDefault();
764
+ const node = document.getElementById(findingsId(task.id));
765
+ if (node) node.scrollIntoView({ block: 'nearest' });
766
+ });
767
+ li.append(el('span', 'finding: ', 'muted'), a);
768
+ if (attempt) li.append(el('span', `attempt ${attempt}`, 'muted'));
769
+ }
770
+ ul.append(li);
771
+ }
772
+ return ul;
773
+ }
774
+ // The task's own switch: inherit the run's, or on or off for this task (`forge control set summaries --task`).
775
+ function summaryOverride(s, ctx, task) {
776
+ const key = s.dataset.hold, run = ctx.run, own = task.summaries_override;
777
+ const current = own === 'on' || own === 'off' ? own : 'inherit';
778
+ const runOn = !!run.summaries && run.summaries.mode === 'on';
779
+ // A data-row inside the section's data-hold: controls.js's hold() puts the keyboard back on this key after a redraw.
780
+ const row = el('div', undefined, 'sum-switch'), msgs = el('div', undefined, 'sum-msgs');
781
+ row.dataset.row = 'summary-override';
782
+ const pick = value => changeSummaries(msgs, s, run.key, { input: value, task: task.id }, () => ctx.refresh && ctx.refresh());
783
+ const bank = summaryBank([['inherit', 'Inherit'], ['on', 'On'], ['off', 'Off']], current, pick, 'Summaries for this task');
784
+ row.append(el('p', 'Summaries for this task', 'sum-label'), bank,
785
+ el('p', current === 'inherit' ? `Follows the run: ${runOn ? 'on' : 'off'}.` : `${current === 'on' ? 'On' : 'Off'} for this task, whatever the run sets.`, 'muted sum-note'),
786
+ msgs);
787
+ const answer = answers.get(key);
788
+ if (answer && Date.now() - answer.at < ANSWER_MS && window.ForgeUI) window.ForgeUI.outcome(msgs, answer.res, answer.text, { silent: true });
789
+ return row;
790
+ }
791
+ // The task's summary, after its attempt trail: its text, what it came from, and the switch where this page can change
792
+ // the run. A solo run has none. A task with no summary shows only its switch; where the page cannot write, nothing.
793
+ function summarySection(host, ctx, task) {
794
+ const run = ctx.run, sum = task.summary || null, U = window.ForgeUI;
795
+ if (run.kind === 'solo') return;
796
+ const s = section(host, 'Summary');
797
+ s.classList.add('sum-section');
798
+ s.dataset.hold = `summary:${run.key}:${task.id}`;
799
+ if (sum) summaryText(s, ctx, task, sum); else muted(s, 'No summary yet.');
800
+ const row = summaryOverride(s, ctx, task);
801
+ s.append(row);
802
+ const writable = U && U.controlsEnabled && window.ForgeControls ? U.controlsEnabled() : Promise.resolve(false);
803
+ writable.then(on => { if (!on) { row.remove(); if (!sum) s.remove(); } });
804
+ }
805
+
434
806
  function taskView(host, ctx, task) {
435
807
  const run = ctx.run, now = ctx.now, solo = run.kind === 'solo';
808
+ const detail = lazy(ctx, `/api/runs/${encodeURIComponent(run.key)}/tasks/${encodeURIComponent(task.id)}`, run.updated);
809
+ taskHeader(host, ctx, task, detail);
810
+ attemptTrail(host, ctx, task);
811
+ summarySection(host, ctx, task);
812
+ if (window.ForgeBrief) window.ForgeBrief.taskSection(host, ctx, task);
436
813
  const head = el('div', undefined, 'insp-head');
437
814
  head.append(el('h2', solo ? (task.title || 'Solo run') : `${task.id} · ${task.title || 'Untitled task'}`), el('div', solo ? 'solo task' : `task · wave ${display(task.wave)}`, 'insp-kind'));
438
815
  const chips = el('div', undefined, 'chips');
439
816
  if (RM.taskStatus(task) === 'ACCEPTED') chips.append(acceptedChip(task));
440
817
  else {
441
- chips.append(RM.taskStatus(task) === 'INFRA' ? chip(RM.statusText(task), 'infra') : chip(RM.taskStatus(task)));
818
+ chips.append(chip(RM.statusText(task), String(RM.taskStatus(task)).toLowerCase()));
442
819
  if (task.accepted === true) chips.append(acceptedChip(task));
443
820
  else if (task.verdict) chips.append(chip('review ' + task.verdict, task.verdict.toLowerCase()));
444
821
  }
822
+ if (task.group && window.ForgeGroups) {
823
+ const group = window.ForgeGroups.taskChip(task.group, ctx.hash({ kind: 'group', id: task.group }));
824
+ if (group) chips.append(group);
825
+ }
826
+ if (window.ForgeBrief && window.ForgeBrief.affectedBadge) {
827
+ const affected = window.ForgeBrief.affectedBadge(task);
828
+ if (affected) chips.append(affected);
829
+ }
445
830
  if (task.explored) chips.append(el('span', '* explored', 'tag'));
446
831
  head.append(chips);
447
832
  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);
@@ -521,11 +906,11 @@ window.ForgePanel = (() => {
521
906
 
522
907
  // reviews and their findings
523
908
  const rs = section(host, 'Review findings');
909
+ rs.id = findingsId(task.id); // a summary's finding links here
524
910
  gateLine(rs, task.gate);
525
911
  findingCounts(rs, task.findings);
526
912
  failFirst(rs, task.fail_first);
527
913
  preReview(rs, task.pre_review);
528
- const detail = lazy(ctx, `/api/runs/${encodeURIComponent(run.key)}/tasks/${encodeURIComponent(task.id)}`, run.updated);
529
914
  if (!loading(rs, detail, 'the full findings')) {
530
915
  const reviews = list(detail.data.reviews);
531
916
  if (!reviews.length) muted(rs, 'No review has run yet.');
@@ -858,5 +1243,6 @@ window.ForgePanel = (() => {
858
1243
  if (sel.kind === 'fractal') return fractalNodeView(host, ctx, sel);
859
1244
  return runView(host, ctx);
860
1245
  }
861
- return { render, cache };
1246
+ return { render, cache, trailLine, reasonText, linkModel, headerActions, summaryBank, changeSummaries, answerOutcome };
862
1247
  })();
1248
+ if (typeof module === 'object' && module.exports) module.exports = window.ForgePanel;