@giamme/forge 0.15.0 → 0.17.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 (80) hide show
  1. package/CHANGELOG.md +48 -0
  2. package/VERSION +1 -1
  3. package/docs/artifacts.md +1 -1
  4. package/docs/commands.md +14 -3
  5. package/docs/dataset.md +8 -0
  6. package/docs/forge-ui.md +14 -0
  7. package/docs/memory.md +22 -0
  8. package/docs/reviews.md +22 -1
  9. package/forge +11 -0
  10. package/package.json +1 -1
  11. package/references/dataset.md +129 -7
  12. package/references/decision-models.md +15 -2
  13. package/references/decompose.md +95 -13
  14. package/references/harnesses.md +4 -1
  15. package/references/planning.md +3 -2
  16. package/references/solo.md +5 -1
  17. package/references/ui.md +10 -1
  18. package/scripts/forge-artifact.sh +53 -0
  19. package/scripts/forge-contract.py +107 -9
  20. package/scripts/forge-control.py +0 -2
  21. package/scripts/forge-dispatch.sh +28 -12
  22. package/scripts/forge-fail-first.py +3 -1
  23. package/scripts/forge-guard.py +247 -8
  24. package/scripts/forge-issues.py +16 -3
  25. package/scripts/forge-ledger.py +3 -1
  26. package/scripts/forge-lib-adopt.sh +266 -0
  27. package/scripts/forge-lib-attribute.sh +10 -2
  28. package/scripts/forge-lib-plans.sh +16 -4
  29. package/scripts/forge-lib-review.sh +8 -2
  30. package/scripts/forge-lib-task.sh +19 -5
  31. package/scripts/forge-memory.sh +41 -4
  32. package/scripts/forge-metrics.sh +29 -0
  33. package/scripts/forge-parallel.sh +99 -14
  34. package/scripts/forge-plan-check.py +25 -2
  35. package/scripts/forge-planner.py +20 -6
  36. package/scripts/forge-route.py +16 -2
  37. package/scripts/forge-runs-rm.py +23 -7
  38. package/scripts/forge-runtime.py +25 -2
  39. package/scripts/forge-schedule.py +5 -2
  40. package/scripts/forge-shadow.py +30 -9
  41. package/scripts/forge-solo.sh +6 -0
  42. package/scripts/forge-sweep.py +25 -10
  43. package/scripts/forge_dataset/cli.py +99 -0
  44. package/scripts/forge_dataset/export.py +1 -0
  45. package/scripts/forge_dataset/facts.py +278 -0
  46. package/scripts/forge_dataset/harvest.py +27 -3
  47. package/scripts/forge_dataset/history.py +126 -0
  48. package/scripts/forge_dataset/outcomes.py +206 -58
  49. package/scripts/forge_dataset/pairs.py +174 -0
  50. package/scripts/forge_dataset/risk.py +108 -0
  51. package/scripts/forge_dataset/tiers.py +427 -0
  52. package/scripts/forge_dataset/worktrees.py +95 -0
  53. package/scripts/forge_decide/cli.py +23 -2
  54. package/scripts/forge_decide/labels.py +30 -6
  55. package/scripts/forge_decide/replay.py +10 -4
  56. package/scripts/forge_memory_list.py +153 -0
  57. package/scripts/forge_worktrees.py +88 -0
  58. package/ui/README.md +31 -0
  59. package/ui/docs/api.md +92 -6
  60. package/ui/forge_ui/__init__.py +14 -1
  61. package/ui/forge_ui/__main__.py +1 -1
  62. package/ui/forge_ui/control.py +77 -0
  63. package/ui/forge_ui/export.py +9 -2
  64. package/ui/forge_ui/findings.py +11 -2
  65. package/ui/forge_ui/projects.py +571 -0
  66. package/ui/forge_ui/reader.py +96 -9
  67. package/ui/forge_ui/server.py +8 -0
  68. package/ui/forge_ui/static/app.js +105 -22
  69. package/ui/forge_ui/static/cloudui.js +6 -2
  70. package/ui/forge_ui/static/convo.js +1 -1
  71. package/ui/forge_ui/static/diffview.js +9 -5
  72. package/ui/forge_ui/static/files.js +1 -1
  73. package/ui/forge_ui/static/index.html +5 -1
  74. package/ui/forge_ui/static/panel.js +69 -2
  75. package/ui/forge_ui/static/projectsview.js +372 -0
  76. package/ui/forge_ui/static/settings.js +136 -4
  77. package/ui/forge_ui/static/style.css +94 -3
  78. package/ui/forge_ui/static/uikit.js +94 -1
  79. package/ui/forge_ui/static/worktreesview.js +250 -0
  80. package/ui/forge_ui/worktrees.py +570 -0
@@ -743,7 +743,7 @@
743
743
  else if (rows.length - fold <= 4) s.append(items(rows));
744
744
  else {
745
745
  if (fold) s.append(items(rows.slice(0, fold)));
746
- const det = el('details', undefined, 'fm-more');
746
+ const det = el('details', undefined, 'fm-more'); det.dataset.keep = `fm-more-${title}`;
747
747
  det.append(el('summary', `${fmt(rows.length - fold)} ${more}`), items(rows.slice(fold)));
748
748
  s.append(det);
749
749
  }
@@ -35,6 +35,8 @@
35
35
  <script src="cloudui.js" defer></script>
36
36
  <script src="leaderboard.js" defer></script>
37
37
  <script src="findingsview.js" defer></script>
38
+ <script src="worktreesview.js" defer></script>
39
+ <script src="projectsview.js" defer></script>
38
40
  <script src="rundelete.js" defer></script>
39
41
  <script src="settings.js" defer></script>
40
42
  <script src="search.js" defer></script>
@@ -44,11 +46,13 @@
44
46
  <body data-shell="immersive" data-runs="open" data-insp="open" data-tasks="open">
45
47
  <script src="shell.js"></script>
46
48
  <header class="topbar">
47
- <a class="brand" href="#/" title="forge-ui · local run viewer"><span class="brand-plate">forge</span><span class="brand-sub">ui</span></a>
49
+ <a class="brand" href="#/" title="forge-ui · local run viewer"><span class="brand-plate">forge</span><span class="brand-sub">ui</span><span class="brand-version" id="brand-version" hidden></span></a>
48
50
  <nav class="desk-nav" aria-label="Views">
49
51
  <a class="top-link" href="#/">Map</a>
50
52
  <a class="top-link" href="#/cloud">Cloud</a>
53
+ <a class="top-link" href="#/projects">Projects</a>
51
54
  <a class="top-link" href="#/models">Models</a>
55
+ <a class="top-link" href="#/worktrees">Worktrees</a>
52
56
  <a class="top-link" href="#/settings">Settings</a>
53
57
  </nav>
54
58
  <button class="top-search" type="button" data-jump title="Jump to a run, task, project, model or command (/)"><span class="top-search-label"><span>Search</span></span> <kbd>Ctrl K</kbd></button>
@@ -163,6 +163,14 @@ window.ForgePanel = (() => {
163
163
  wrap.append(table);
164
164
  parent.append(wrap);
165
165
  }
166
+ // What a reviewer said about its own tests (FORGE_TESTS). A review that could not run them stands out: its verdict
167
+ // rests on reading alone. A reply that says nothing shows nothing.
168
+ const TESTS_WORDS = { ran: 'Reviewer ran tests', not_needed: 'Reviewer needed no tests', could_not_run: 'Reviewer could not run tests', unclear: 'Reviewer\'s word on its tests is unclear' };
169
+ function testsLine(parent, tests) {
170
+ if (!tests || !TESTS_WORDS[tests.status]) return;
171
+ const text = TESTS_WORDS[tests.status] + (tests.reason ? `: ${tests.reason}` : '');
172
+ parent.append(el('p', text, tests.status === 'could_not_run' ? 'warn tests-line' : 'muted tests-line'));
173
+ }
166
174
  // An attempt's chip. A failed attempt is red whatever its words; a send-back says what forge did in its title.
167
175
  function attemptChip(word) {
168
176
  const c = chip(word, RM.attemptFailed(word) ? 'fail' : undefined), note = RM.attemptNote(word);
@@ -527,7 +535,7 @@ window.ForgePanel = (() => {
527
535
  h.append(el('strong', `${r.kind} review · attempt ${display(r.attempt)}`), plate(r.spec), chip(r.verdict || r.state || 'unknown'));
528
536
  box.append(h);
529
537
  if (r.state === 'running') muted(box, 'Still reviewing; findings appear when it finishes.');
530
- else findingsList(box, r.findings, `task-${task.id}-r${i}`);
538
+ else { testsLine(box, r.tests); findingsList(box, r.findings, `task-${task.id}-r${i}`); }
531
539
  rs.append(box);
532
540
  });
533
541
  }
@@ -670,11 +678,69 @@ window.ForgePanel = (() => {
670
678
  if (n.last == null && n.planning_last == null) muted(ps, 'No output yet.');
671
679
  }
672
680
 
681
+ // Commits made outside forge that `adopt` brought in, each reviewed alone: a person's work, so no task row claims them.
682
+ // Each opens its review, its findings and the range's diff (#131).
683
+ function adoptionsList(host, run, ctx) {
684
+ const rows = list(run.adoptions);
685
+ if (!rows.length) return;
686
+ const s = section(host, `Adopted commits (${rows.length})`);
687
+ const ul = el('ul', undefined, 'adoptions');
688
+ for (const a of rows) {
689
+ const li = el('li'), failed = String(a.verdict).toUpperCase() !== 'PASS';
690
+ li.append(el('code', `${String(a.base).slice(0, 12)}..${String(a.tip).slice(0, 12)}`, 'mono'), document.createTextNode(' '),
691
+ chip(a.verdict, failed ? 'fail' : 'pass'));
692
+ if (a.approved) li.append(el('span', 'approved over the review', 'tag'));
693
+ if (a.findings && a.findings.worst) li.append(document.createTextNode(' '), sevChip(`${a.findings.worst}×${a.findings[a.findings.worst]}`, a.findings.worst));
694
+ if (a.reason) li.append(el('p', a.reason, 'muted'));
695
+ if (ctx && a.findings !== undefined && (a.findings !== null || a.diff)) {
696
+ const links = el('p', undefined, 'adoption-links'), sel = { kind: 'adoption', name: a.review };
697
+ links.append(link('Its review and findings →', ctx.hash(sel), () => ctx.onSelect(sel)));
698
+ const d = a.diff && diffLink(ctx, 'The range, findings pinned →', { kind: 'adoption', name: a.review });
699
+ if (d) links.append(document.createTextNode(' '), d);
700
+ li.append(links);
701
+ }
702
+ ul.append(li);
703
+ }
704
+ s.append(ul);
705
+ }
706
+
707
+ function adoptionView(host, ctx, sel) {
708
+ const run = ctx.run, a = list(run.adoptions).find(x => x.review === sel.name);
709
+ const head = el('div', undefined, 'insp-head');
710
+ head.append(el('h2', 'Adopted range'), el('div', 'finish · made outside forge, reviewed alone', 'insp-kind'));
711
+ host.append(head);
712
+ const back = { kind: 'final' };
713
+ if (!a) { muted(host, `This run adopted nothing under ${sel.name}.`); host.append(link('← Final review', ctx.hash(back), () => ctx.onSelect(back))); return; }
714
+ const chips = el('div', undefined, 'chips');
715
+ chips.append(chip(a.verdict, String(a.verdict).toUpperCase() === 'PASS' ? 'pass' : 'fail'));
716
+ if (a.approved) chips.append(el('span', 'approved over the review', 'tag'));
717
+ head.append(chips);
718
+ if (a.reason) host.append(el('p', a.reason));
719
+ fields(host, [['Reviewer', plate(a.spec)], ['Range', `${String(a.base).slice(0, 12)}..${String(a.tip).slice(0, 12)}`, true], ['Adopted', time(a.at)]]);
720
+ const d0 = a.diff && diffLink(ctx, 'The range, findings pinned →', { kind: 'adoption', name: a.review });
721
+ if (d0) host.append(d0);
722
+ const fs = section(host, 'Findings');
723
+ findingCounts(fs, a.findings);
724
+ const entry = lazy(ctx, `/api/runs/${encodeURIComponent(run.key)}/adoptions/${encodeURIComponent(a.review)}`, 'adoption:' + a.review);
725
+ if (!loading(fs, entry, 'the review')) {
726
+ const d = entry.data;
727
+ gateLine(fs, d.gate);
728
+ testsLine(fs, d.tests);
729
+ findingsList(fs, d.findings, `adoption-${a.review}`);
730
+ const ps = section(host, 'Report and prompt');
731
+ if (d.known_issues) details(ps, a.approved ? 'Findings kept (known_issues.md)' : 'Known issues', d.known_issues, `adoption-${a.review}-known`);
732
+ details(ps, 'Reviewer report (qa.last)', d.qa_last, `adoption-${a.review}-last`);
733
+ details(ps, 'Prompt (qa.input)', d.qa_input, `adoption-${a.review}-input`);
734
+ }
735
+ host.append(el('p'), link('← Final review', ctx.hash(back), () => ctx.onSelect(back)));
736
+ }
737
+
673
738
  function finalView(host, ctx, sel) {
674
739
  const run = ctx.run, reviews = list(run.final_reviews);
675
740
  const head = el('div', undefined, 'insp-head');
676
741
  head.append(el('h2', 'Final review'), el('div', 'finish · whole-run review', 'insp-kind'));
677
742
  host.append(head);
743
+ adoptionsList(host, run, ctx);
678
744
  const pick = sel.name ? reviews.find(r => r.name === sel.name) : reviews[0];
679
745
  if (!pick) {
680
746
  head.append(chip(run.settings && run.settings.final_qa ? 'pending' : 'not requested', 'none'));
@@ -700,7 +766,7 @@ window.ForgePanel = (() => {
700
766
  const entry = lazy(ctx, `/api/runs/${encodeURIComponent(run.key)}/final-reviews/${encodeURIComponent(pick.name)}`, pick.state === 'done' ? 'done:' + pick.verdict : run.updated);
701
767
  if (!loading(fs, entry, 'the review')) {
702
768
  const d = entry.data;
703
- if (pick.state !== 'running') findingsList(fs, d.findings, `final-${pick.name}`);
769
+ if (pick.state !== 'running') { testsLine(fs, d.tests); findingsList(fs, d.findings, `final-${pick.name}`); }
704
770
  const ps = section(host, 'Report and prompt');
705
771
  details(ps, 'Reviewer report (qa.last)', d.qa_last, `final-${pick.name}-last`);
706
772
  details(ps, 'Prompt (qa.input)', d.qa_input, `final-${pick.name}-input`);
@@ -786,6 +852,7 @@ window.ForgePanel = (() => {
786
852
  }
787
853
  if (sel.kind === 'execution') return execView(host, ctx, task, sel);
788
854
  if (sel.kind === 'final') return finalView(host, ctx, sel);
855
+ if (sel.kind === 'adoption') return adoptionView(host, ctx, sel);
789
856
  if (sel.kind === 'verification') return verificationView(host, ctx);
790
857
  if (sel.kind === 'integration') return integrationView(host, ctx);
791
858
  if (sel.kind === 'fractal') return fractalNodeView(host, ctx, sel);
@@ -0,0 +1,372 @@
1
+ /* forge-ui Projects screen (#126): one page per repository with its runs, every finding forge wrote about it and
2
+ every memory forge wrote for it (window.ForgeProjects, and a CommonJS module under node:test).
3
+ Routes: #/projects (the list) and #/projects/<id>[/runs|/findings|/memories]. The id is the run cloud's.
4
+ Each tab reads its own endpoint when it opens, never on the page's poll; "Read again" asks the server to read
5
+ everything again. A redraw keeps filters, scroll and a selection (#115). Finding and memory texts are untrusted
6
+ and only ever enter the page as text. The pure helpers are tested in ui/tests/js/projectsview.test.js.
7
+ ctx = { id?, tab?, runs() (the page's run list), runHref(key), tablePrefs?(id), saveTablePrefs?(id, prefs) }. */
8
+ (function (root, factory) {
9
+ 'use strict';
10
+ const api = factory(root);
11
+ if (typeof module === 'object' && module.exports) module.exports = api;
12
+ else root.ForgeProjects = api;
13
+ })(typeof self !== 'undefined' ? self : this, function (root) {
14
+ 'use strict';
15
+
16
+ const list = v => Array.isArray(v) ? v : [];
17
+ const SEVERITIES = ['P0', 'P1', 'P2', 'P3'];
18
+ const STATUSES = ['open', 'filed', 'fixed', 'swept', 'dismissed', 'superseded'];
19
+ const STATES = { in_memory: 'in memory', waiting: 'waiting for a second run', stale: 'dropped: stale', capped: 'dropped: trimmed by the cap',
20
+ muted: 'not injected (curated out)', dropped: 'dropped', gone: 'from a checkout that is gone' };
21
+ const TABS = ['runs', 'findings', 'memories'];
22
+ const ROLES_NOTE = 'planner and dwarf get Verify, Known traps and Recurring QA findings; QA gets the last two';
23
+
24
+ /* ---------- pure ---------- */
25
+ // filter = { severity: 'all' | P0..P3, status: 'all' | 'open' (default) | STATUSES, run: '' | run id, reviewer: '', path: '' (substring),
26
+ // since: 0 (days, 0 = any), shadow: false }
27
+ function filterFindings(rows, filter, now) {
28
+ const f = filter || {}, sev = f.severity || 'all', status = f.status || 'open', path = String(f.path || '').toLowerCase();
29
+ const since = Number(f.since) > 0 ? (now || Date.now() / 1000) - Number(f.since) * 86400 : null;
30
+ return list(rows).filter(r => (f.shadow || r.kind !== 'shadow')
31
+ && (sev === 'all' || r.severity === sev) && (status === 'all' || r.status === status)
32
+ && (!f.run || r.run_id === f.run) && (!f.reviewer || r.reviewer === f.reviewer)
33
+ && (!path || String(r.location || '').toLowerCase().includes(path))
34
+ && (since === null || (Number.isFinite(r.at) && r.at >= since)));
35
+ }
36
+ // A learning's state as the picked checkout's forge-memory.sh decides it: its own ledger's state, else the first
37
+ // other checkout's (with that checkout named), else `gone` for one only the dataset still has.
38
+ function stateFor(learning, source) {
39
+ const states = learning && learning.states || {};
40
+ if (source && states[source]) return { state: states[source], from: null };
41
+ const other = Object.keys(states)[0];
42
+ if (other) return { state: states[other], from: other };
43
+ return { state: 'gone', from: 'dataset' };
44
+ }
45
+ function filterLearnings(rows, filter, source) {
46
+ const f = filter || {}, cat = f.category || 'all', st = f.state || 'all', text = String(f.text || '').toLowerCase();
47
+ return list(rows).filter(r => (cat === 'all' || r.category === cat) && (st === 'all' || stateFor(r, source).state === st)
48
+ && (!text || String(r.text || '').toLowerCase().includes(text)));
49
+ }
50
+ // what the Memories tab says when there is nothing to show
51
+ function memoryEmpty(data) {
52
+ if (!data) return null;
53
+ if (data.runs > 0 && data.memory_off_runs === data.runs) return 'Every run of this repository ran with memory turned off (--no-memory), so forge recorded no learnings.';
54
+ if (!list(data.learnings).length && !list(data.sources).some(s => s.memory)) return 'No memories yet: forge has recorded no learning for this repository.';
55
+ return null;
56
+ }
57
+ // A summary without what its own columns show: the bullet, the [P1][CONFIRMED] tags and a leading location.
58
+ function cleanSummary(text, location) {
59
+ let s = String(text || '').replace(/^\s*(?:[-*+•]|\d+[.)])\s*/, '').replace(/\*\*/g, '');
60
+ s = s.replace(/^(?:\s*(?:\[[^\]\n]*\]|\((?:P[0-3]|CONFIRMED|PLAUSIBLE|UNSTATED)\)|P[0-3]:?|CONFIRMED|PLAUSIBLE))+\s*/, '');
61
+ if (location) {
62
+ const at = s.indexOf(location);
63
+ if (at >= 0 && at < 4) s = s.slice(at + location.length).replace(/^[`'"*]*\s*(?:\([^)]*\))?\s*(?:[—–:-]+\s*)?/, '');
64
+ }
65
+ return s.trim() || String(text || '').trim();
66
+ }
67
+ const basename = p => typeof p === 'string' && p ? p.replace(/\/+$/, '').split('/').pop() : '—';
68
+ const routeOf = (id, tab) => '#/projects/' + encodeURIComponent(id) + (tab && tab !== 'runs' ? '/' + tab : '');
69
+
70
+ /* ---------- DOM ---------- */
71
+ function render(host, ctx) {
72
+ const UI = root.ForgeUI, el = (tag, text, cls) => UI.el(tag, text, cls);
73
+ const when = t => Number.isFinite(t) ? new Date(t * 1000).toLocaleString() : '—';
74
+ const guard = (region, draw) => { if (UI.guard) UI.guard(region, draw); else draw(); };
75
+ const s = { id: ctx.id || null, tab: TABS.includes(ctx.tab) ? ctx.tab : 'runs', list: null, detail: null, findings: null, memories: null,
76
+ ffilter: { severity: 'all', status: 'open', run: '', reviewer: '', path: '', since: 0, shadow: false },
77
+ mfilter: { category: 'all', state: 'all', text: '' }, source: null, checkout: '', error: null, seq: 0, timer: null };
78
+ const tablePrefs = id => ctx.tablePrefs ? ctx.tablePrefs(id) : null, savePrefs = id => p => ctx.saveTablePrefs && ctx.saveTablePrefs(id, p);
79
+
80
+ function table(parent, id, label, columns, rows, extra) {
81
+ parent.replaceChildren();
82
+ root.ForgeTable.render(parent, Object.assign({ id, label, columns, rows, prefs: tablePrefs(id), savePrefs: savePrefs(id) }, extra || {}));
83
+ }
84
+ function readAgain(onClick) {
85
+ const b = el('button', 'Read again'); b.type = 'button'; b.title = 'Read the run dirs, forge issues, the ledgers and the dataset again now';
86
+ b.addEventListener('click', onClick); return b;
87
+ }
88
+ const notes = n => el('div', undefined, 'prj-notes muted');
89
+ function fill(node, items) { node.replaceChildren(...list(items).map(t => el('p', String(t)))); }
90
+
91
+ /* the list */
92
+ function drawList() {
93
+ const head = el('div', undefined, 'prj-head'), body = el('div', undefined, 'prj-body');
94
+ head.append(el('h1', 'Projects', 'module-title'));
95
+ host.replaceChildren(head, el('p', 'Each repository forge has run in: its runs, every finding its reviews wrote and every memory forge keeps for it, whichever checkout a run started in.', 'muted prj-lede'), body);
96
+ const draw = () => guard(body, () => {
97
+ if (!s.list) { body.replaceChildren(el('p', s.error ? `Could not read the projects (${s.error}).` : 'Reading the projects…', s.error ? 'warn' : 'muted')); return; }
98
+ const rows = list(s.list.projects);
99
+ if (!rows.length) { body.replaceChildren(el('p', 'No projects yet: forge-ui lists no run.', 'muted')); return; }
100
+ table(body, 'projects', 'Projects', [
101
+ { id: 'name', label: 'Project', value: p => p.name, cell: p => {
102
+ const box = el('span', undefined, 'prj-name'), a = el('a', p.name); a.href = routeOf(p.id); box.append(a);
103
+ if (!p.exists) box.append(el('span', 'folder gone', 'chip st-unknown'));
104
+ if (p.path_only) { const c = el('span', 'tied by path', 'chip st-pending'); c.title = `${p.path_only} run(s) were tied to this repository only by their path: it may not be a separate repository`; box.append(c); }
105
+ return box; } },
106
+ { id: 'root', label: 'Root', value: p => p.root, mono: true, cls: 'prj-cut', cell: p => { const n = el('span', p.root); n.title = p.root; return n; } },
107
+ { id: 'runs', label: 'Runs', value: p => p.runs, cell: p => String(p.runs) },
108
+ { id: 'live', label: 'Live now', value: p => p.live, cell: p => p.live ? String(p.live) : '—' },
109
+ { id: 'last', label: 'Last activity', value: p => p.last, cell: p => when(p.last) },
110
+ { id: 'open', label: 'Findings open', title: 'findings no later passing review superseded; dismissals and filed issues show on the Findings tab', value: p => p.open_findings, cell: p => p.open_findings == null ? '—' : String(p.open_findings) },
111
+ { id: 'memory', label: 'Memory lines', value: p => p.memory_lines, cell: p => p.memory_lines == null ? '—' : String(p.memory_lines) },
112
+ { id: 'checkouts', label: 'Checkouts', value: p => p.checkouts, cell: p => String(p.checkouts), hidden: true },
113
+ ], rows);
114
+ });
115
+ return draw;
116
+ }
117
+
118
+ /* one project */
119
+ function drawProject() {
120
+ const head = el('div', undefined, 'prj-head'), tabs = el('nav', undefined, 'seg prj-tabs'), body = el('div', undefined, 'prj-body');
121
+ tabs.setAttribute('aria-label', 'Project tabs');
122
+ for (const t of TABS) { const a = el('a', t[0].toUpperCase() + t.slice(1)); a.href = routeOf(s.id, t); a.dataset.tab = t; if (t === s.tab) a.setAttribute('aria-current', 'page'); tabs.append(a); }
123
+ const title = el('h1', '…', 'module-title'), where = el('p', '', 'muted mono prj-root');
124
+ const links = el('div', undefined, 'prj-links');
125
+ const back = el('a', 'All projects'); back.href = '#/projects';
126
+ const cloud = el('a', 'In the run cloud'); cloud.href = '#/cloud/projects/' + encodeURIComponent(s.id);
127
+ const wts = el('a', 'Worktrees'); wts.href = '#/worktrees';
128
+ links.append(back, cloud, wts);
129
+ head.append(title, links);
130
+ const note = notes();
131
+ host.replaceChildren(head, where, tabs, note, body);
132
+ const syncHead = () => {
133
+ const d = s.detail;
134
+ title.textContent = d ? d.name : s.error ? 'Unknown project' : '…';
135
+ where.textContent = d ? d.root + (d.exists ? '' : ' (this folder is gone)') : '';
136
+ if (d) wts.href = '#/worktrees/repo/' + encodeURIComponent(d.root);
137
+ };
138
+ const draw = () => { syncHead(); guard(body, () => drawTab(body, note)); };
139
+ return draw;
140
+ }
141
+ function drawTab(body, note) {
142
+ if (!s.detail) { body.replaceChildren(el('p', s.error ? `Could not read this project (${s.error}).` : 'Reading the project…', s.error ? 'warn' : 'muted')); return; }
143
+ if (s.tab === 'runs') return drawRuns(body, note);
144
+ if (s.tab === 'findings') return drawFindings(body, note);
145
+ return drawMemories(body, note);
146
+ }
147
+
148
+ /* Runs */
149
+ function drawRuns(body, note) {
150
+ fill(note, []);
151
+ const runs = list(s.detail.runs), checkouts = list(s.detail.checkouts);
152
+ const bar = el('div', undefined, 'prj-filters');
153
+ if (checkouts.length > 1) {
154
+ const l = el('label', undefined, 'fnd-field'), sel = el('select'); sel.dataset.filter = 'checkout';
155
+ for (const [v, t] of [['', 'all']].concat(checkouts.map(c => [c.path, basename(c.path) + (c.branch ? ` (${c.branch})` : '') + (c.exists ? '' : ' · gone')]))) { const o = el('option', t); o.value = v; sel.append(o); }
156
+ sel.value = s.checkout; sel.addEventListener('change', () => { s.checkout = sel.value; drawRuns(body, note); });
157
+ l.append(el('span', 'Checkout', 'plate'), sel); bar.append(l);
158
+ }
159
+ const shown = runs.filter(r => !s.checkout || (r.repo_worktree || s.detail.root) === s.checkout);
160
+ const tableHost = el('div', undefined, 'prj-table');
161
+ body.replaceChildren(bar, tableHost);
162
+ if (!shown.length) { tableHost.append(el('p', 'No runs.', 'muted')); return; }
163
+ const RM = root.ForgeRunModel;
164
+ table(tableHost, 'project-runs', 'Runs', [
165
+ { id: 'state', label: 'State', value: r => RM ? RM.runState(r) : null, cell: r => { const b = el('span', undefined, 'fnd-status'); const st = RM ? RM.runState(r) : 'pending'; b.append(el('i', undefined, 'lamp st-' + ({ live: 'running', failed: 'fail', done: 'merged', pending: 'pending' })[st]), el('span', st)); return b; } },
166
+ { id: 'goal', label: 'Goal', value: r => r.goal, cell: r => { const a = el('a', String(r.goal || 'Untitled run').split('\n')[0]); a.href = ctx.runHref(r.key); return a; } },
167
+ { id: 'run', label: 'Run', value: r => r.run_id, mono: true, cell: r => r.run_id || '—' },
168
+ { id: 'checkout', label: 'Checkout', value: r => r.repo_worktree || '', cell: r => r.repo_worktree ? basename(r.repo_worktree) + (r.repo_branch ? ` (${r.repo_branch})` : '') : 'root' },
169
+ { id: 'tasks', label: 'Tasks', value: r => r.task_count, cell: r => Object.entries(r.counts || {}).map(([k, n]) => `${k} ${n}`).join(' · ') || '—' },
170
+ { id: 'verification', label: 'Verification', value: r => r.verification_status, cell: r => r.verification_status || '—' },
171
+ { id: 'review', label: 'Final review', value: r => r.final_review, cell: r => r.final_review ? r.final_review + (r.final_review_outdated ? ' (outdated)' : '') : '—' },
172
+ { id: 'updated', label: 'Updated', value: r => r.updated, cell: r => when(r.updated) },
173
+ ], shown);
174
+ }
175
+
176
+ /* Findings */
177
+ function drawFindings(body, note) {
178
+ const d = s.findings;
179
+ if (!d) { fill(note, []); body.replaceChildren(el('p', s.ferror ? `Could not read the findings (${s.ferror}).` : 'Reading every review of every run… the first read parses each reply, so it can take a few seconds.', s.ferror ? 'warn' : 'muted')); return; }
180
+ fill(note, list(d.notes).concat(d.dataset_runs ? [`${d.dataset_runs} run(s) whose directory is gone are read from the dataset: their findings link to no run page or diff.`] : []));
181
+ const rows = list(d.rows);
182
+ const bar = el('div', undefined, 'prj-filters');
183
+ const select = (name, text, options) => {
184
+ const l = el('label', undefined, 'fnd-field'), sel = el('select'); sel.dataset.filter = name;
185
+ for (const [v, t] of options) { const o = el('option', t); o.value = String(v); sel.append(o); }
186
+ sel.value = String(s.ffilter[name]);
187
+ sel.addEventListener('change', () => { s.ffilter[name] = name === 'since' ? Number(sel.value) : sel.value; drawTable(); });
188
+ l.append(el('span', text, 'plate'), sel); bar.append(l);
189
+ };
190
+ const counts = {}; for (const r of rows) counts[r.status] = (counts[r.status] || 0) + 1;
191
+ select('status', 'Status', [['all', 'all']].concat(STATUSES.map(x => [x, `${x} (${counts[x] || 0})`])));
192
+ select('severity', 'Severity', [['all', 'all']].concat(SEVERITIES.map(x => [x, x])));
193
+ select('run', 'Run', [['', 'all']].concat(Array.from(new Set(rows.map(r => r.run_id).filter(Boolean))).sort().map(x => [x, x])));
194
+ select('reviewer', 'Reviewer', [['', 'all']].concat(Array.from(new Set(rows.map(r => r.reviewer).filter(Boolean))).sort().map(x => [x, x])));
195
+ select('since', 'Date', [[0, 'any time'], [1, 'last day'], [7, 'last week'], [30, 'last month']]);
196
+ const pl = el('label', undefined, 'fnd-field'), path = el('input'); path.type = 'search'; path.placeholder = 'path contains…'; path.value = s.ffilter.path; path.dataset.filter = 'path';
197
+ path.addEventListener('input', () => { s.ffilter.path = path.value; drawTable(); });
198
+ pl.append(el('span', 'Path', 'plate'), path); bar.append(pl);
199
+ const sh = el('label', undefined, 'fnd-toggle'), box = el('input'); box.type = 'checkbox'; box.checked = s.ffilter.shadow; box.dataset.filter = 'shadow';
200
+ box.addEventListener('change', () => { s.ffilter.shadow = box.checked; drawTable(); });
201
+ sh.append(box, el('span', 'Shadow reviews')); bar.append(sh);
202
+ const again = readAgain(() => loadTab(true));
203
+ bar.append(again);
204
+ const count = el('p', '', 'muted prj-count'), tableHost = el('div', undefined, 'prj-table');
205
+ body.replaceChildren(bar, count, tableHost);
206
+ const summaryCell = r => {
207
+ const wrap = el('div', undefined, 'fnd-summary'), line = el('div', undefined, 'fnd-summary-line');
208
+ const more = el('button', undefined, 'fnd-more'); more.type = 'button'; more.setAttribute('aria-expanded', 'false'); more.setAttribute('aria-label', 'Show the full text');
209
+ more.append(el('span', '▸', 'fnd-caret'));
210
+ const detail = el('div', undefined, 'fnd-detail'); detail.hidden = true;
211
+ detail.append(el('pre', r.text || r.summary || '', 'fnd-text'));
212
+ if (list(r.occurrences).length > 1) {
213
+ const ul = el('ul', undefined, 'prj-occ');
214
+ for (const o of r.occurrences) { const li = el('li'); const t = `${o.run_id || '—'} · ${o.task || 'final review'} · attempt ${o.attempt == null ? '—' : o.attempt} · ${o.reviewer || '—'} · ${when(o.at)}`; if (o.href) { const a = el('a', t); a.href = o.href; li.append(a); } else li.append(el('span', t)); ul.append(li); }
215
+ detail.append(el('p', `Seen ${r.count} times, the newest first in the row:`, 'muted'), ul);
216
+ }
217
+ more.addEventListener('click', () => { const open = detail.hidden; detail.hidden = !open; more.setAttribute('aria-expanded', String(open)); more.firstChild.textContent = open ? '▾' : '▸'; });
218
+ line.append(more, el('span', cleanSummary(r.summary, r.location) || '—', 'prj-summary'));
219
+ if (r.count > 1) line.append(el('span', `×${r.count}`, 'chip prj-count-chip'));
220
+ wrap.append(line, detail); return wrap;
221
+ };
222
+ const statusCell = r => {
223
+ const b = el('span', undefined, 'fnd-status fnd-' + r.status);
224
+ b.append(el('i', undefined, 'lamp ' + (r.status === 'open' ? 'lamp-off' : r.status === 'filed' ? 'fnd-amber' : r.status === 'superseded' ? 'st-outdated' : r.status === 'dismissed' ? 'lamp-off' : 'st-pass')), el('span', r.status));
225
+ if (r.status === 'superseded') b.title = 'a later review of the same task passed; that does not say this finding was fixed';
226
+ return b;
227
+ };
228
+ const whereCell = r => {
229
+ if (r.source === 'dataset') { const x = el('span', 'from the dataset', 'chip st-unknown'); x.title = 'its run directory is gone: no run page or diff to open'; return x; }
230
+ const box = el('span', undefined, 'prj-where');
231
+ if (r.href) { const a = el('a', 'diff'); a.href = r.href; a.title = 'open the diff at this finding'; box.append(a); }
232
+ if (r.fileable && s.writes) { const f = el('a', 'file or dismiss'); f.href = '#/runs/' + encodeURIComponent(r.run) + '/findings'; f.title = 'on the run\'s Open findings page, through forge issues'; box.append(document.createTextNode(' · '), f); }
233
+ return box;
234
+ };
235
+ const runCell = r => { if (!r.run) return r.run_id || '—'; const a = el('a', r.run_id || r.run, 'mono'); a.href = ctx.runHref(r.run); return a; };
236
+ const columns = [
237
+ { id: 'severity', label: 'Severity', value: r => SEVERITIES.indexOf(r.severity), cell: r => el('span', r.severity || '—', 'chip sev-chip sev-' + (SEVERITIES.includes(r.severity) ? r.severity : 'none')) },
238
+ { id: 'confidence', label: 'Confidence', value: r => r.confidence, cell: r => r.confidence || '—' },
239
+ { id: 'summary', label: 'Summary', value: r => r.summary, cls: 'prj-wide', cell: summaryCell },
240
+ { id: 'location', label: 'Location', value: r => r.location, mono: true, cls: 'prj-cut', cell: r => { const n = el('span', r.location || '—'); if (r.location) n.title = r.location; return n; } },
241
+ { id: 'run', label: 'Run', value: r => r.run_id, cell: runCell },
242
+ { id: 'task', label: 'Task', value: r => r.task, mono: true, cell: r => r.task || (r.final_review ? 'final review' : '—') },
243
+ { id: 'attempt', label: 'Attempt', value: r => r.attempt, cell: r => r.attempt == null ? '—' : String(r.attempt) },
244
+ { id: 'reviewer', label: 'Reviewer', value: r => r.reviewer, cell: r => (r.reviewer || '—') + (r.kind === 'shadow' ? ' (shadow)' : '') },
245
+ { id: 'date', label: 'Date', value: r => r.at, cls: 'prj-nowrap', cell: r => { const n = el('span', Number.isFinite(r.at) ? new Date(r.at * 1000).toLocaleDateString() : '—'); n.title = when(r.at); return n; } },
246
+ { id: 'status', label: 'Status', value: r => STATUSES.indexOf(r.status), cell: statusCell },
247
+ { id: 'open', label: 'Open', sortable: false, cell: whereCell },
248
+ ];
249
+ function drawTable() {
250
+ const shown = filterFindings(rows, s.ffilter);
251
+ count.textContent = `${shown.length} of ${rows.length} findings`;
252
+ if (!shown.length) { tableHost.replaceChildren(el('p', rows.length ? 'No findings match these filters.' : 'No review of this repository wrote a finding.', 'muted')); return; }
253
+ table(tableHost, 'project-findings', 'Findings', columns, shown, { className: 'fnd-grid prj-findings' });
254
+ }
255
+ drawTable();
256
+ }
257
+
258
+ /* Memories */
259
+ function drawMemories(body, note) {
260
+ const d = s.memories;
261
+ if (!d) { fill(note, []); body.replaceChildren(el('p', s.merror ? `Could not read the memories (${s.merror}).` : 'Reading each checkout\'s ledger…', s.merror ? 'warn' : 'muted')); return; }
262
+ fill(note, d.notes);
263
+ const sources = list(d.sources);
264
+ if (!s.source || !sources.some(x => x.path === s.source)) s.source = (sources.find(x => x.root) || sources[0] || {}).path || null;
265
+ const bar = el('div', undefined, 'prj-filters');
266
+ if (sources.length > 1) {
267
+ const l = el('label', undefined, 'fnd-field'), sel = el('select'); sel.dataset.filter = 'source';
268
+ for (const x of sources) { const o = el('option', basename(x.path) + (x.root ? ' (root)' : x.branch ? ` (${x.branch})` : '')); o.value = x.path; sel.append(o); }
269
+ sel.value = s.source || ''; sel.addEventListener('change', () => { s.source = sel.value; drawMemories(body, note); });
270
+ l.append(el('span', 'Checkout', 'plate'), sel); bar.append(l);
271
+ }
272
+ bar.append(readAgain(() => loadTab(true)));
273
+ const parts = [bar];
274
+ const empty = memoryEmpty(d);
275
+ if (empty) { parts.push(el('p', empty, 'muted prj-empty')); body.replaceChildren(...parts); return; }
276
+ if (d.differs) parts.push(el('p', 'The checkouts\' memory.md files differ: pick a checkout to see what its runs are told.', 'warn prj-differs'));
277
+ const src = sources.find(x => x.path === s.source);
278
+ const given = el('section', undefined, 'prj-given');
279
+ given.append(el('h2', 'Given to models'), el('p', ROLES_NOTE + '. At most ' + ((src && src.max_lines) || 40) + ' lines.', 'muted'));
280
+ if (src && src.rebuilt_differs) given.append(el('p', 'This memory.md is not what forge would rebuild now: an older forge wrote it, or a prune asked Jev to drop facts. The states below are what the next rebuild does.', 'muted'));
281
+ if (!src || !src.memory || !list(src.memory).length) given.append(el('p', 'This checkout has no memory.md yet.', 'muted'));
282
+ for (const sec of list(src && src.memory)) {
283
+ const block = el('div', undefined, 'prj-section');
284
+ const h = el('h3', sec.title); const roles = el('span', ' · ' + list(sec.roles).join(', '), 'muted'); h.append(roles);
285
+ const ul = el('ul', undefined, 'prj-lines');
286
+ for (const line of list(sec.lines)) ul.append(el('li', (line.count ? line.count + 'x: ' : '') + line.text));
287
+ block.append(h, ul); given.append(block);
288
+ }
289
+ parts.push(given);
290
+ const all = el('section', undefined, 'prj-learnings');
291
+ all.append(el('h2', 'All learnings'));
292
+ const lbar = el('div', undefined, 'prj-filters');
293
+ const lsel = (name, text, options) => { const l = el('label', undefined, 'fnd-field'), sel = el('select'); sel.dataset.filter = 'm-' + name; for (const [v, t] of options) { const o = el('option', t); o.value = v; sel.append(o); } sel.value = s.mfilter[name]; sel.addEventListener('change', () => { s.mfilter[name] = sel.value; drawLearnings(); }); l.append(el('span', text, 'plate'), sel); lbar.append(l); };
294
+ lsel('category', 'Category', [['all', 'all'], ['verify', 'verify'], ['trap', 'trap'], ['finding', 'finding']]);
295
+ lsel('state', 'State', [['all', 'all']].concat(Object.entries(STATES).map(([k, v]) => [k, v])));
296
+ const tl = el('label', undefined, 'fnd-field'), tx = el('input'); tx.type = 'search'; tx.placeholder = 'text contains…'; tx.value = s.mfilter.text; tx.dataset.filter = 'm-text';
297
+ tx.addEventListener('input', () => { s.mfilter.text = tx.value; drawLearnings(); }); tl.append(el('span', 'Text', 'plate'), tx); lbar.append(tl);
298
+ const lcount = el('p', '', 'muted prj-count'), lhost = el('div', undefined, 'prj-table');
299
+ all.append(lbar, lcount, lhost); parts.push(all);
300
+ body.replaceChildren(...parts);
301
+ const learnings = list(d.learnings);
302
+ function drawLearnings() {
303
+ const shown = filterLearnings(learnings, s.mfilter, s.source);
304
+ lcount.textContent = `${shown.length} of ${learnings.length} learnings`;
305
+ if (!shown.length) { lhost.replaceChildren(el('p', 'No learnings match these filters.', 'muted')); return; }
306
+ table(lhost, 'project-learnings', 'Learnings', [
307
+ { id: 'category', label: 'Category', value: r => r.category, cell: r => r.category },
308
+ { id: 'text', label: 'Learning', value: r => r.text, cell: r => el('span', r.text, 'prj-learning') },
309
+ { id: 'state', label: 'State', value: r => stateFor(r, s.source).state, cell: r => { const st = stateFor(r, s.source), b = el('span', STATES[st.state] || st.state); if (st.from && st.from !== 'dataset') b.title = 'from ' + st.from + ', not this checkout\'s ledger'; return b; } },
310
+ { id: 'count', label: 'Runs', title: 'distinct runs that emitted it', value: r => r.count, cell: r => String(r.count || '—') },
311
+ { id: 'run', label: 'Last run', value: r => (list(r.rows).slice(-1)[0] || {}).run_id, mono: true, cell: r => (list(r.rows).slice(-1)[0] || {}).run_id || '—' },
312
+ { id: 'task', label: 'Task', value: r => (list(r.rows).slice(-1)[0] || {}).task, mono: true, cell: r => (list(r.rows).slice(-1)[0] || {}).task || '—' },
313
+ { id: 'role', label: 'Role', value: r => (list(r.rows).slice(-1)[0] || {}).role, cell: r => (list(r.rows).slice(-1)[0] || {}).role || '—' },
314
+ { id: 'model', label: 'Model', value: r => (list(r.rows).slice(-1)[0] || {}).model, cell: r => (list(r.rows).slice(-1)[0] || {}).model || '—' },
315
+ { id: 'from', label: 'From', value: r => r.dataset_only ? 'dataset' : '', cell: r => r.dataset_only ? 'dataset' : Array.from(new Set(list(r.rows).flatMap(x => list(x.from)))).map(basename).join(', ') },
316
+ { id: 'last', label: 'Last seen', value: r => r.last, cell: r => r.last || '—' },
317
+ ], shown);
318
+ }
319
+ drawLearnings();
320
+ }
321
+
322
+ /* loading */
323
+ async function loadList() {
324
+ const res = await UI.get('/api/projects');
325
+ if (res.ok) { s.list = res.data; s.error = null; } else s.error = res.detail || res.error || 'no answer';
326
+ redraw();
327
+ }
328
+ async function loadDetail() {
329
+ const res = await UI.get('/api/projects/' + encodeURIComponent(s.id));
330
+ if (res.ok) { s.detail = res.data; s.error = null; } else s.error = res.status === 404 ? 'no project has this id' : res.detail || res.error || 'no answer';
331
+ redraw();
332
+ }
333
+ async function loadTab(refresh) {
334
+ const tab = s.tab, mine = ++s.seq;
335
+ if (tab === 'runs') { await loadDetail(); return; }
336
+ const q = refresh ? '?refresh=1' : '';
337
+ const res = await UI.get(`/api/projects/${encodeURIComponent(s.id)}/${tab}${q}`);
338
+ if (mine !== s.seq) return;
339
+ if (tab === 'findings') { if (res.ok) { s.findings = res.data; s.ferror = null; } else s.ferror = res.detail || res.error || 'no answer'; }
340
+ else { if (res.ok) { s.memories = res.data; s.merror = null; } else s.merror = res.detail || res.error || 'no answer'; }
341
+ redraw();
342
+ }
343
+ let redraw = () => {};
344
+ function open() {
345
+ clearTimeout(s.timer);
346
+ if (s.id) { redraw = drawProject(); redraw(); loadDetail().then(() => { if (s.tab !== 'runs') loadTab(false); }); }
347
+ else { redraw = drawList(); redraw(); loadList(); }
348
+ }
349
+ UI.controlsEnabled().then(on => { s.writes = !!on; if (s.tab === 'findings' && s.findings) redraw(); });
350
+ open();
351
+ return {
352
+ go(id, tab) {
353
+ const t = TABS.includes(tab) ? tab : 'runs';
354
+ if (id === s.id && t === s.tab) return; // the page's own refresh: nothing changed here
355
+ const same = id === s.id;
356
+ s.id = id || null; s.tab = t;
357
+ if (!same) { s.detail = s.findings = s.memories = null; s.source = null; s.checkout = ''; }
358
+ if (same && s.id) { redraw = drawProject(); redraw(); if (t === 'runs') loadDetail(); else if (!(t === 'findings' ? s.findings : s.memories)) loadTab(false); }
359
+ else open();
360
+ },
361
+ // the list and the runs follow the page at most every 30 s; findings and memories wait for Read again
362
+ poll() {
363
+ const now = Date.now();
364
+ if (s.polled && now - s.polled < 30000) return;
365
+ s.polled = now;
366
+ if (!s.id) loadList(); else if (s.tab === 'runs') loadDetail();
367
+ },
368
+ };
369
+ }
370
+
371
+ return { render, cleanSummary, filterFindings, filterLearnings, stateFor, memoryEmpty, routeOf, STATUSES, STATES };
372
+ });