@giamme/forge 0.18.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.
- package/CHANGELOG.md +33 -0
- package/README.md +1 -0
- package/SKILL.md +16 -2
- package/VERSION +1 -1
- package/docs/artifacts.md +25 -1
- package/docs/commands.md +81 -14
- package/docs/decomposed-runs.md +114 -1
- package/docs/development.md +2 -1
- package/docs/forge-ui.md +84 -15
- package/docs/memory.md +25 -4
- package/docs/models.md +8 -0
- package/docs/reviews.md +122 -0
- package/forge +20 -3
- package/package.json +2 -1
- package/references/dataset.md +20 -1
- package/references/decompose.md +621 -33
- package/references/harnesses.md +18 -3
- package/references/planning.md +43 -14
- package/references/ui.md +53 -6
- package/registry.tsv +8 -3
- package/scripts/forge-brief.py +88 -3
- package/scripts/forge-compare.py +4 -3
- package/scripts/forge-contract.py +202 -27
- package/scripts/forge-control.py +117 -5
- package/scripts/forge-dispatch.sh +34 -5
- package/scripts/forge-group.py +496 -0
- package/scripts/forge-groups.py +89 -0
- package/scripts/forge-handoff.py +1128 -0
- package/scripts/forge-lib-group.sh +641 -0
- package/scripts/forge-lib-plans.sh +339 -3
- package/scripts/forge-lib-task.sh +197 -4
- package/scripts/forge-memory.sh +245 -3
- package/scripts/forge-parallel.sh +715 -34
- package/scripts/forge-planner.py +104 -8
- package/scripts/forge-route.py +190 -12
- package/scripts/forge-runs.py +9 -5
- package/scripts/forge-schedule.py +354 -45
- package/scripts/forge-solo.sh +2 -0
- package/scripts/forge-worktrees.py +243 -0
- package/scripts/forge_brief/__init__.py +294 -50
- package/scripts/forge_brief/answers.py +58 -11
- package/scripts/forge_brief/proposals.py +1630 -0
- package/scripts/forge_dataset/efforts.py +4 -3
- package/scripts/forge_dataset/export.py +24 -12
- package/scripts/forge_dataset/facts.py +5 -3
- package/scripts/forge_dataset/forecast.py +8 -18
- package/scripts/forge_dataset/harvest.py +204 -9
- package/scripts/forge_dataset/history.py +11 -6
- package/scripts/forge_dataset/importer.py +65 -1
- package/scripts/forge_dataset/names.py +66 -0
- package/scripts/forge_dataset/reviewers.py +5 -2
- package/scripts/forge_dataset/risk.py +6 -3
- package/scripts/forge_dataset/routing.py +6 -1
- package/scripts/forge_groups/__init__.py +308 -0
- package/scripts/forge_groups/attribute.py +289 -0
- package/scripts/forge_groups/review.py +286 -0
- package/scripts/forge_owner.py +152 -0
- package/scripts/forge_side/__init__.py +12 -7
- package/ui/docs/api.md +173 -17
- package/ui/forge_ui/control.py +361 -2
- package/ui/forge_ui/executions.py +8 -1
- package/ui/forge_ui/export.py +31 -4
- package/ui/forge_ui/groups.py +264 -0
- package/ui/forge_ui/models.py +70 -8
- package/ui/forge_ui/reader.py +262 -19
- package/ui/forge_ui/server.py +4 -0
- package/ui/forge_ui/static/app.js +93 -13
- package/ui/forge_ui/static/briefview.js +350 -47
- package/ui/forge_ui/static/diffview.js +86 -1
- package/ui/forge_ui/static/groupsview.js +332 -0
- package/ui/forge_ui/static/index.html +1 -0
- package/ui/forge_ui/static/panel.js +127 -7
- package/ui/forge_ui/static/projectsview.js +189 -10
- package/ui/forge_ui/static/runmodel.js +14 -3
- package/ui/forge_ui/static/storageview.js +91 -10
- package/ui/forge_ui/static/style.css +79 -5
- package/ui/forge_ui/static/worktreesview.js +233 -12
- package/ui/forge_ui/storage.py +14 -0
|
@@ -47,6 +47,66 @@
|
|
|
47
47
|
return list(rows).filter(r => (cat === 'all' || r.category === cat) && (st === 'all' || stateFor(r, source).state === st)
|
|
48
48
|
&& (!text || String(r.text || '').toLowerCase().includes(text)));
|
|
49
49
|
}
|
|
50
|
+
// The forget wire key is the learning's own category and key, joined once. A row missing either is not selectable.
|
|
51
|
+
function learningKey(row) {
|
|
52
|
+
if (!row || row.category == null || row.key == null) return '';
|
|
53
|
+
const category = String(row.category), key = String(row.key);
|
|
54
|
+
return category && key ? category + ':' + key : '';
|
|
55
|
+
}
|
|
56
|
+
// Keys to forget, in learning order. `selected` is a Set or array of learning rows or of "category:key" strings.
|
|
57
|
+
function forgetKeys(learnings, selected) {
|
|
58
|
+
const want = selected instanceof Set ? selected : new Set(list(selected));
|
|
59
|
+
const out = [], seen = new Set();
|
|
60
|
+
for (const row of list(learnings)) {
|
|
61
|
+
const key = learningKey(row);
|
|
62
|
+
if (!key || seen.has(key) || (!want.has(row) && !want.has(key))) continue;
|
|
63
|
+
seen.add(key);
|
|
64
|
+
out.push(key);
|
|
65
|
+
}
|
|
66
|
+
return out;
|
|
67
|
+
}
|
|
68
|
+
function forgetData(res) {
|
|
69
|
+
const body = res && res.data && res.data.checkouts ? res.data : res;
|
|
70
|
+
return body && body.checkouts ? body : null;
|
|
71
|
+
}
|
|
72
|
+
// The confirm sentence: the chosen learnings, then the memory.md lines the dry run says go. All of it is text.
|
|
73
|
+
function forgetConfirmText(learnings, keys, res) {
|
|
74
|
+
const byKey = new Map();
|
|
75
|
+
for (const row of list(learnings)) { const key = learningKey(row); if (key && !byKey.has(key)) byKey.set(key, row); }
|
|
76
|
+
const lines = ['Forget these learnings?'];
|
|
77
|
+
for (const key of keys) {
|
|
78
|
+
const row = byKey.get(key), text = row && row.text != null ? String(row.text) : '';
|
|
79
|
+
lines.push(text ? key + ' — ' + text : key);
|
|
80
|
+
}
|
|
81
|
+
const removed = [];
|
|
82
|
+
for (const checkout of list(forgetData(res) && forgetData(res).checkouts)) {
|
|
83
|
+
for (const line of list(checkout && checkout.result && checkout.result.memory_lines_removed)) {
|
|
84
|
+
if (line != null && String(line) !== '') removed.push(String(line));
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
lines.push(removed.length ? 'memory.md lines that go:' : 'No memory.md line goes.');
|
|
88
|
+
return lines.concat(removed).join('\n');
|
|
89
|
+
}
|
|
90
|
+
// One line per key after the real call: how many ledger rows went, or that the key was not found.
|
|
91
|
+
function forgetResultLines(res) {
|
|
92
|
+
const lines = [];
|
|
93
|
+
for (const checkout of list(forgetData(res) && forgetData(res).checkouts)) {
|
|
94
|
+
const result = checkout && checkout.result;
|
|
95
|
+
if (!result) {
|
|
96
|
+
const err = checkout && checkout.error;
|
|
97
|
+
const why = typeof err === 'string' ? err : err && (err.detail || err.error);
|
|
98
|
+
lines.push(why || 'Could not forget in this checkout');
|
|
99
|
+
continue;
|
|
100
|
+
}
|
|
101
|
+
for (const item of list(result.keys)) {
|
|
102
|
+
if (!item || item.key == null) continue;
|
|
103
|
+
if (!item.found) { lines.push(String(item.key) + ': not found'); continue; }
|
|
104
|
+
const rows = typeof item.rows === 'number' && Number.isFinite(item.rows) ? item.rows : 0;
|
|
105
|
+
lines.push(String(item.key) + ': ' + rows + (rows === 1 ? ' row' : ' rows') + ' removed');
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
return lines;
|
|
109
|
+
}
|
|
50
110
|
// what the Memories tab says when there is nothing to show
|
|
51
111
|
function memoryEmpty(data) {
|
|
52
112
|
if (!data) return null;
|
|
@@ -74,7 +134,8 @@
|
|
|
74
134
|
const guard = (region, draw) => { if (UI.guard) UI.guard(region, draw); else draw(); };
|
|
75
135
|
const s = { id: ctx.id || null, tab: TABS.includes(ctx.tab) ? ctx.tab : 'runs', list: null, detail: null, findings: null, memories: null,
|
|
76
136
|
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
|
|
137
|
+
mfilter: { category: 'all', state: 'all', text: '' }, source: null, checkout: '', error: null, seq: 0, timer: null,
|
|
138
|
+
writes: false, picked: new Set(), forgetNote: null, forgetting: false, forgetEpoch: 0, forgetHost: null };
|
|
78
139
|
const tablePrefs = id => ctx.tablePrefs ? ctx.tablePrefs(id) : null, savePrefs = id => p => ctx.saveTablePrefs && ctx.saveTablePrefs(id, p);
|
|
79
140
|
|
|
80
141
|
function table(parent, id, label, columns, rows, extra) {
|
|
@@ -85,11 +146,35 @@
|
|
|
85
146
|
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
147
|
b.addEventListener('click', onClick); return b;
|
|
87
148
|
}
|
|
149
|
+
// confirmInline settles only when its own host answers. A redraw drops that host (another checkout,
|
|
150
|
+
// Read again, leaving the tab), the await never finishes, and `forgetting` stays true, so every later
|
|
151
|
+
// checkbox and the Forget button are drawn disabled. Cancel the strip now and retire the attempt.
|
|
152
|
+
function press(node) {
|
|
153
|
+
if (node && typeof node.click === 'function') node.click();
|
|
154
|
+
}
|
|
155
|
+
function dismissConfirm(host) {
|
|
156
|
+
if (!host) return;
|
|
157
|
+
for (const child of [...(host.children || [])]) {
|
|
158
|
+
if (!child.classList || !child.classList.contains('ui-confirm')) continue;
|
|
159
|
+
for (const button of child.children || []) {
|
|
160
|
+
if (button.tagName === 'BUTTON' && button.textContent === 'Cancel') { press(button); return; }
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
function abandonForget() {
|
|
165
|
+
if (!s.forgetting) return;
|
|
166
|
+
const host = s.forgetHost;
|
|
167
|
+
s.forgetting = false;
|
|
168
|
+
s.forgetEpoch += 1;
|
|
169
|
+
s.forgetHost = null;
|
|
170
|
+
dismissConfirm(host);
|
|
171
|
+
}
|
|
88
172
|
const notes = n => el('div', undefined, 'prj-notes muted');
|
|
89
173
|
function fill(node, items) { node.replaceChildren(...list(items).map(t => el('p', String(t)))); }
|
|
90
174
|
|
|
91
175
|
/* the list */
|
|
92
176
|
function drawList() {
|
|
177
|
+
abandonForget();
|
|
93
178
|
const head = el('div', undefined, 'prj-head'), body = el('div', undefined, 'prj-body');
|
|
94
179
|
head.append(el('h1', 'Projects', 'module-title'));
|
|
95
180
|
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);
|
|
@@ -117,6 +202,7 @@
|
|
|
117
202
|
|
|
118
203
|
/* one project */
|
|
119
204
|
function drawProject() {
|
|
205
|
+
abandonForget();
|
|
120
206
|
const head = el('div', undefined, 'prj-head'), tabs = el('nav', undefined, 'seg prj-tabs'), body = el('div', undefined, 'prj-body');
|
|
121
207
|
tabs.setAttribute('aria-label', 'Project tabs');
|
|
122
208
|
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); }
|
|
@@ -139,7 +225,7 @@
|
|
|
139
225
|
return draw;
|
|
140
226
|
}
|
|
141
227
|
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; }
|
|
228
|
+
if (!s.detail) { abandonForget(); body.replaceChildren(el('p', s.error ? `Could not read this project (${s.error}).` : 'Reading the project…', s.error ? 'warn' : 'muted')); return; }
|
|
143
229
|
if (s.tab === 'runs') return drawRuns(body, note);
|
|
144
230
|
if (s.tab === 'findings') return drawFindings(body, note);
|
|
145
231
|
return drawMemories(body, note);
|
|
@@ -147,6 +233,7 @@
|
|
|
147
233
|
|
|
148
234
|
/* Runs */
|
|
149
235
|
function drawRuns(body, note) {
|
|
236
|
+
abandonForget();
|
|
150
237
|
fill(note, []);
|
|
151
238
|
const runs = list(s.detail.runs), checkouts = list(s.detail.checkouts);
|
|
152
239
|
const bar = el('div', undefined, 'prj-filters');
|
|
@@ -175,6 +262,7 @@
|
|
|
175
262
|
|
|
176
263
|
/* Findings */
|
|
177
264
|
function drawFindings(body, note) {
|
|
265
|
+
abandonForget();
|
|
178
266
|
const d = s.findings;
|
|
179
267
|
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
268
|
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.`] : []));
|
|
@@ -257,6 +345,7 @@
|
|
|
257
345
|
|
|
258
346
|
/* Memories */
|
|
259
347
|
function drawMemories(body, note) {
|
|
348
|
+
abandonForget();
|
|
260
349
|
const d = s.memories;
|
|
261
350
|
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
351
|
fill(note, d.notes);
|
|
@@ -266,7 +355,7 @@
|
|
|
266
355
|
if (sources.length > 1) {
|
|
267
356
|
const l = el('label', undefined, 'fnd-field'), sel = el('select'); sel.dataset.filter = 'source';
|
|
268
357
|
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); });
|
|
358
|
+
sel.value = s.source || ''; sel.addEventListener('change', () => { s.source = sel.value; s.picked = new Set(); s.forgetNote = null; drawMemories(body, note); });
|
|
270
359
|
l.append(el('span', 'Checkout', 'plate'), sel); bar.append(l);
|
|
271
360
|
}
|
|
272
361
|
bar.append(readAgain(() => loadTab(true)));
|
|
@@ -295,15 +384,93 @@
|
|
|
295
384
|
lsel('state', 'State', [['all', 'all']].concat(Object.entries(STATES).map(([k, v]) => [k, v])));
|
|
296
385
|
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
386
|
tx.addEventListener('input', () => { s.mfilter.text = tx.value; drawLearnings(); }); tl.append(el('span', 'Text', 'plate'), tx); lbar.append(tl);
|
|
387
|
+
let allBox = null, forget = null;
|
|
388
|
+
const faction = el('div'), noteHost = el('div'); faction.append(noteHost);
|
|
389
|
+
s.forgetHost = faction;
|
|
390
|
+
if (s.writes) {
|
|
391
|
+
const lab = el('label', undefined, 'fnd-toggle');
|
|
392
|
+
allBox = el('input'); allBox.type = 'checkbox'; allBox.setAttribute('aria-label', 'Select all shown learnings');
|
|
393
|
+
lab.append(allBox, el('span', 'Select all'));
|
|
394
|
+
forget = el('button', 'Forget selected (0)', 'ui-danger'); forget.type = 'button';
|
|
395
|
+
forget.addEventListener('click', () => { forgetSelected(); });
|
|
396
|
+
allBox.addEventListener('change', () => {
|
|
397
|
+
const shown = filterLearnings(learnings, s.mfilter, s.source);
|
|
398
|
+
for (const row of shown) {
|
|
399
|
+
const key = learningKey(row);
|
|
400
|
+
if (!key) continue;
|
|
401
|
+
if (allBox.checked) s.picked.add(key); else s.picked.delete(key);
|
|
402
|
+
}
|
|
403
|
+
drawLearnings();
|
|
404
|
+
});
|
|
405
|
+
lbar.append(lab, forget);
|
|
406
|
+
}
|
|
298
407
|
const lcount = el('p', '', 'muted prj-count'), lhost = el('div', undefined, 'prj-table');
|
|
299
|
-
all.append(lbar, lcount, lhost); parts.push(all);
|
|
408
|
+
all.append(lbar, faction, lcount, lhost); parts.push(all);
|
|
300
409
|
body.replaceChildren(...parts);
|
|
301
410
|
const learnings = list(d.learnings);
|
|
411
|
+
const shownNow = () => filterLearnings(learnings, s.mfilter, s.source);
|
|
412
|
+
function syncForget() {
|
|
413
|
+
if (!forget) return;
|
|
414
|
+
const keys = forgetKeys(shownNow(), s.picked);
|
|
415
|
+
forget.textContent = `Forget selected (${keys.length})`;
|
|
416
|
+
forget.disabled = s.forgetting || keys.length === 0;
|
|
417
|
+
if (allBox) {
|
|
418
|
+
const selectable = shownNow().map(learningKey).filter(Boolean);
|
|
419
|
+
allBox.checked = selectable.length > 0 && selectable.every(key => s.picked.has(key));
|
|
420
|
+
allBox.disabled = s.forgetting || selectable.length === 0;
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
function paintNote() {
|
|
424
|
+
noteHost.replaceChildren(...list(s.forgetNote).map(line => el('p', line, 'muted')));
|
|
425
|
+
}
|
|
426
|
+
async function forgetSelected() {
|
|
427
|
+
if (s.forgetting) return;
|
|
428
|
+
const keys = forgetKeys(shownNow(), s.picked);
|
|
429
|
+
if (!keys.length) return;
|
|
430
|
+
const epoch = s.forgetEpoch;
|
|
431
|
+
const host = faction;
|
|
432
|
+
const current = () => epoch === s.forgetEpoch && host.isConnected;
|
|
433
|
+
s.forgetting = true; s.forgetNote = null; syncForget(); paintNote();
|
|
434
|
+
for (const child of [...host.children]) if (child !== noteHost) child.remove();
|
|
435
|
+
const path = '/api/projects/' + encodeURIComponent(s.id) + '/memories/forget';
|
|
436
|
+
const base = { keys }; if (s.source) base.path = s.source;
|
|
437
|
+
try {
|
|
438
|
+
// Dry run first. Nothing is forgotten until the confirm, and a cancel sends nothing more.
|
|
439
|
+
const preview = await UI.post(path, { ...base, dry_run: true });
|
|
440
|
+
if (!current()) return;
|
|
441
|
+
if (!preview || !preview.ok || (preview.data && preview.data.ok === false)) {
|
|
442
|
+
UI.outcome(host, preview && preview.ok ? { ok: false, status: preview.status || 500, error: 'failed', detail: 'Could not preview what would be forgotten' } : preview);
|
|
443
|
+
return;
|
|
444
|
+
}
|
|
445
|
+
const yes = await UI.confirmInline(host, forgetConfirmText(learnings, keys, preview), { danger: true });
|
|
446
|
+
if (!current() || !yes) return;
|
|
447
|
+
const res = await UI.post(path, { ...base, dry_run: false });
|
|
448
|
+
// Once sent, the forget happened whatever the screen did meanwhile (Read again, another checkout,
|
|
449
|
+
// another tab): its result line is kept for the next draw rather than dropped with this strip.
|
|
450
|
+
if (!current()) {
|
|
451
|
+
s.forgetNote = res && res.ok ? forgetResultLines(res)
|
|
452
|
+
: ['Could not forget: ' + ((res && (res.detail || res.error)) || 'no answer')];
|
|
453
|
+
if (res && res.ok) for (const key of keys) s.picked.delete(key);
|
|
454
|
+
if (s.tab === 'memories') await loadTab(true);
|
|
455
|
+
return;
|
|
456
|
+
}
|
|
457
|
+
if (!res || !res.ok) { UI.outcome(host, res); return; }
|
|
458
|
+
s.forgetNote = forgetResultLines(res);
|
|
459
|
+
for (const key of keys) s.picked.delete(key);
|
|
460
|
+
s.forgetting = false;
|
|
461
|
+
await loadTab(true);
|
|
462
|
+
} finally {
|
|
463
|
+
if (epoch !== s.forgetEpoch) return;
|
|
464
|
+
s.forgetting = false;
|
|
465
|
+
if (host.isConnected) syncForget();
|
|
466
|
+
}
|
|
467
|
+
}
|
|
302
468
|
function drawLearnings() {
|
|
303
|
-
const shown =
|
|
469
|
+
const shown = shownNow();
|
|
304
470
|
lcount.textContent = `${shown.length} of ${learnings.length} learnings`;
|
|
471
|
+
paintNote(); syncForget();
|
|
305
472
|
if (!shown.length) { lhost.replaceChildren(el('p', 'No learnings match these filters.', 'muted')); return; }
|
|
306
|
-
|
|
473
|
+
const columns = [
|
|
307
474
|
{ id: 'category', label: 'Category', value: r => r.category, cell: r => r.category },
|
|
308
475
|
{ id: 'text', label: 'Learning', value: r => r.text, cell: r => el('span', r.text, 'prj-learning') },
|
|
309
476
|
{ 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; } },
|
|
@@ -314,7 +481,14 @@
|
|
|
314
481
|
{ id: 'model', label: 'Model', value: r => (list(r.rows).slice(-1)[0] || {}).model, cell: r => (list(r.rows).slice(-1)[0] || {}).model || '—' },
|
|
315
482
|
{ 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
483
|
{ id: 'last', label: 'Last seen', value: r => r.last, cell: r => r.last || '—' },
|
|
317
|
-
]
|
|
484
|
+
];
|
|
485
|
+
if (s.writes) columns.unshift({ id: 'pick', label: '', title: 'Select', sortable: false, hideable: false, cell: r => {
|
|
486
|
+
const key = learningKey(r), box = el('input'); box.type = 'checkbox'; box.checked = !!(key && s.picked.has(key));
|
|
487
|
+
box.disabled = s.forgetting || !key; box.setAttribute('aria-label', 'Select ' + (key || 'learning'));
|
|
488
|
+
box.addEventListener('change', () => { if (!key) return; if (box.checked) s.picked.add(key); else s.picked.delete(key); syncForget(); });
|
|
489
|
+
return box;
|
|
490
|
+
} });
|
|
491
|
+
table(lhost, 'project-learnings', 'Learnings', columns, shown);
|
|
318
492
|
}
|
|
319
493
|
drawLearnings();
|
|
320
494
|
}
|
|
@@ -346,7 +520,12 @@
|
|
|
346
520
|
if (s.id) { redraw = drawProject(); redraw(); loadDetail().then(() => { if (s.tab !== 'runs') loadTab(false); }); }
|
|
347
521
|
else { redraw = drawList(); redraw(); loadList(); }
|
|
348
522
|
}
|
|
349
|
-
UI.controlsEnabled().then(on => {
|
|
523
|
+
UI.controlsEnabled().then(on => {
|
|
524
|
+
const next = !!on;
|
|
525
|
+
if (s.writes === next) return;
|
|
526
|
+
s.writes = next;
|
|
527
|
+
if ((s.tab === 'findings' && s.findings) || (s.tab === 'memories' && s.memories)) redraw();
|
|
528
|
+
});
|
|
350
529
|
open();
|
|
351
530
|
return {
|
|
352
531
|
go(id, tab) {
|
|
@@ -354,7 +533,7 @@
|
|
|
354
533
|
if (id === s.id && t === s.tab) return; // the page's own refresh: nothing changed here
|
|
355
534
|
const same = id === s.id;
|
|
356
535
|
s.id = id || null; s.tab = t;
|
|
357
|
-
if (!same) { s.detail = s.findings = s.memories = null; s.source = null; s.checkout = ''; }
|
|
536
|
+
if (!same) { s.detail = s.findings = s.memories = null; s.source = null; s.checkout = ''; s.picked = new Set(); s.forgetNote = null; }
|
|
358
537
|
if (same && s.id) { redraw = drawProject(); redraw(); if (t === 'runs') loadDetail(); else if (!(t === 'findings' ? s.findings : s.memories)) loadTab(false); }
|
|
359
538
|
else open();
|
|
360
539
|
},
|
|
@@ -368,5 +547,5 @@
|
|
|
368
547
|
};
|
|
369
548
|
}
|
|
370
549
|
|
|
371
|
-
return { render, cleanSummary, filterFindings, filterLearnings, stateFor, memoryEmpty, routeOf, STATUSES, STATES };
|
|
550
|
+
return { render, cleanSummary, filterFindings, filterLearnings, stateFor, memoryEmpty, routeOf, forgetKeys, STATUSES, STATES };
|
|
372
551
|
});
|
|
@@ -236,10 +236,21 @@
|
|
|
236
236
|
const CAUSE_LABELS = { capacity: 'at capacity', rate_limit: 'rate limited', usage_limit: 'usage limit', budget: 'out of budget',
|
|
237
237
|
auth: 'login needed', network: 'network down', provider_down: 'provider down', empty: 'empty answer', cancelled: 'cancelled' };
|
|
238
238
|
const causeLabel = cause => cause ? (Object.prototype.hasOwnProperty.call(CAUSE_LABELS, cause) ? CAUSE_LABELS[cause] : String(cause)) : null;
|
|
239
|
+
// Words the page shows in place of a status word. IMPLEMENTED is a member whose work is in and whose group has not reviewed it.
|
|
240
|
+
const STATUS_LABELS = { IMPLEMENTED: 'awaiting group review' };
|
|
241
|
+
function statusLabel(status) {
|
|
242
|
+
const word = status == null ? '' : String(status);
|
|
243
|
+
return Object.prototype.hasOwnProperty.call(STATUS_LABELS, word) ? STATUS_LABELS[word] : word;
|
|
244
|
+
}
|
|
239
245
|
// The status word, with an INFRA task's cause after it (`INFRA · usage limit`); plain `INFRA` when no cause was recorded.
|
|
246
|
+
// IMPLEMENTED reads as its label. The word itself stays the lamp class (taskStatus).
|
|
240
247
|
function statusText(t) {
|
|
241
|
-
const status = taskStatus(t)
|
|
242
|
-
|
|
248
|
+
const status = taskStatus(t);
|
|
249
|
+
if (status === 'INFRA') {
|
|
250
|
+
const label = causeLabel(t.infra && t.infra.cause);
|
|
251
|
+
return label ? `INFRA · ${label}` : status;
|
|
252
|
+
}
|
|
253
|
+
return statusLabel(status);
|
|
243
254
|
}
|
|
244
255
|
const DAY_NAMES = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];
|
|
245
256
|
const MONTH_NAMES = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
|
|
@@ -951,7 +962,7 @@
|
|
|
951
962
|
}
|
|
952
963
|
|
|
953
964
|
return { liveNow, runState, execStatus, matchRun, filterOptions, atlasModel, repoKey, repoLabel, compareRepo, columns, planModel, finishState,
|
|
954
|
-
finalStatus, runReviewStatus, reviewSinceLine, reviewAt, taskStatus, statusText, causeLabel, resetText, taskVerdict, attemptStatus, attemptNote, attemptFailed, isWaiting,
|
|
965
|
+
finalStatus, runReviewStatus, reviewSinceLine, reviewAt, taskStatus, statusText, statusLabel, causeLabel, resetText, taskVerdict, attemptStatus, attemptNote, attemptFailed, isWaiting,
|
|
955
966
|
attributionLine, taskParts,
|
|
956
967
|
taskTimes, metricValue, overlap, projectSchedule, execModel, verifyLeds, criticalPath, concurrency, stateAt, timeRange, events, lineage, structureKey, innerKey,
|
|
957
968
|
fmtDur, alias, basename, weight, searchIndex, searchRank, statusEvents, fractalTree, sweepLine, sweepState, retroSummary };
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
/* forge-ui Disk screen (#139): what forge takes on disk in every repository it has runs for (run dirs, worktrees,
|
|
2
2
|
its data home) and the command that takes each part back (window.ForgeStorage, and a CommonJS module under
|
|
3
3
|
node:test). Route #/disk. The same report as `forge du --all`, from the same rules (scripts/forge_storage.py).
|
|
4
|
-
The commands come from the server
|
|
5
|
-
|
|
4
|
+
The commands come from the server. Under --read-only they are only ever copied. When controls are on, a
|
|
5
|
+
reclaimable run (and every reclaimable run at once) can be compacted from here, after a dry run and a
|
|
6
|
+
confirmation. Measuring visits every file, so it runs once in the background when the screen opens and
|
|
6
7
|
again on "Measure again"; the page polls only while a measurement runs.
|
|
7
8
|
The pure helpers are tested in ui/tests/js/storageview.test.js.
|
|
8
|
-
ctx = { runHref(
|
|
9
|
+
ctx = { runHref(key) -> href (a run row's key is null when the run list does not show it), tablePrefs?(id), saveTablePrefs?(id, prefs) }. */
|
|
9
10
|
(function (root, factory) {
|
|
10
11
|
'use strict';
|
|
11
12
|
const api = factory(root);
|
|
@@ -25,6 +26,35 @@
|
|
|
25
26
|
while (v >= 1024 && i < units.length - 1) { v /= 1024; i += 1; }
|
|
26
27
|
return (i === 0 ? String(v) : v.toFixed(v < 10 ? 1 : 0)) + ' ' + units[i];
|
|
27
28
|
}
|
|
29
|
+
// A copied command is a compact only when it is `forge runs compact`. `--all` is the whole disk; anything
|
|
30
|
+
// else names one run. `forge du --all` and `forge runs rm` are not compacts.
|
|
31
|
+
function compactKind(command) {
|
|
32
|
+
if (typeof command !== 'string' || !command.includes('forge runs compact')) return null;
|
|
33
|
+
return /(?:^|\s)--all(?:\s|$)/.test(command) ? 'all' : 'run';
|
|
34
|
+
}
|
|
35
|
+
// The compact POST body, without dry_run (the caller adds it). `all` compacts every reclaimable run;
|
|
36
|
+
// a string or {run}|{key} compacts that run.
|
|
37
|
+
function compactBody(target) {
|
|
38
|
+
if (target === 'all' || (target && typeof target === 'object' && target.all === true)) return { all: true };
|
|
39
|
+
if (typeof target === 'string') return { run: target };
|
|
40
|
+
const raw = target && typeof target === 'object' ? (target.run != null ? target.run : target.key) : null;
|
|
41
|
+
return { run: raw == null ? '' : String(raw) };
|
|
42
|
+
}
|
|
43
|
+
function compactPayload(answer) {
|
|
44
|
+
const data = answer && answer.data;
|
|
45
|
+
if (data && typeof data === 'object' && !Array.isArray(data)
|
|
46
|
+
&& ('bytes_freed' in data || 'runs' in data || 'dry_run' in data)) return data;
|
|
47
|
+
return answer && typeof answer === 'object' ? answer : {};
|
|
48
|
+
}
|
|
49
|
+
// What the confirm and the result say: the bytes `forge runs compact --json` would free, and how many runs.
|
|
50
|
+
function compactSummary(answer) {
|
|
51
|
+
const body = compactPayload(answer);
|
|
52
|
+
const bytes = typeof body.bytes_freed === 'number' && Number.isFinite(body.bytes_freed) ? body.bytes_freed : 0;
|
|
53
|
+
const n = Array.isArray(body.runs) ? body.runs.length : 0;
|
|
54
|
+
const runs = n === 1 ? '1 run' : n + ' runs';
|
|
55
|
+
return (body.dry_run ? 'Would free ' : 'Freed ') + humanBytes(bytes) + ' across ' + runs;
|
|
56
|
+
}
|
|
57
|
+
const ACTIVE_RUN = 'this run is active: compact it after it ends';
|
|
28
58
|
// One line on the whole: what forge takes and what can go without losing a run.
|
|
29
59
|
function summary(data) {
|
|
30
60
|
const t = (data && data.totals) || {};
|
|
@@ -83,7 +113,7 @@
|
|
|
83
113
|
function render(host, ctx) {
|
|
84
114
|
const UI = root.ForgeUI;
|
|
85
115
|
const el = (tag, text, cls) => UI.el(tag, text, cls);
|
|
86
|
-
const s = { answer: null, error: null, timer: null, seq: 0 };
|
|
116
|
+
const s = { answer: null, error: null, timer: null, seq: 0, writes: false, compacting: false };
|
|
87
117
|
|
|
88
118
|
const head = el('div', undefined, 'wt-head');
|
|
89
119
|
const again = el('button', 'Measure again'); again.type = 'button';
|
|
@@ -91,15 +121,18 @@
|
|
|
91
121
|
again.addEventListener('click', () => load(true));
|
|
92
122
|
const stamp = el('span', '', 'muted wt-stamp');
|
|
93
123
|
head.append(el('h1', 'Disk', 'module-title'), again, stamp);
|
|
94
|
-
const
|
|
124
|
+
const LEDE_OFF = 'What forge takes on disk in every repository it has runs for, and the command that takes each part back. Review snapshots and log copies can go without losing a run: every run stays viewable here and in the dataset. Commands are only copied: this page runs nothing.';
|
|
125
|
+
const LEDE_ON = 'What forge takes on disk in every repository it has runs for, and the command that takes each part back. Review snapshots and log copies can go without losing a run: every run stays viewable here and in the dataset. Copy a command, or compact from here after a dry run and a confirmation.';
|
|
126
|
+
const lede = el('p', LEDE_OFF, 'muted wt-lede');
|
|
95
127
|
const status = el('p', undefined, 'wt-totals'); status.setAttribute('role', 'status');
|
|
96
128
|
const cmds = el('div', undefined, 'disk-commands');
|
|
129
|
+
const action = el('div');
|
|
97
130
|
const chart = el('section', undefined, 'disk-chart');
|
|
98
131
|
chart.setAttribute('aria-label', 'Where the space goes');
|
|
99
132
|
const tip = el('div', undefined, 'disk-tip'); tip.hidden = true; tip.setAttribute('role', 'tooltip');
|
|
100
133
|
const tableHost = el('div', undefined, 'wt-table');
|
|
101
134
|
const extra = el('section', undefined, 'disk-extra');
|
|
102
|
-
host.replaceChildren(head, lede, status, chart, cmds, tableHost, extra, tip);
|
|
135
|
+
host.replaceChildren(head, lede, status, chart, cmds, action, tableHost, extra, tip);
|
|
103
136
|
|
|
104
137
|
// one tooltip for every segment: what it is, its size and its share, beside the pointer or the focused segment
|
|
105
138
|
function showTip(seg, x, y) {
|
|
@@ -164,17 +197,58 @@
|
|
|
164
197
|
});
|
|
165
198
|
return b;
|
|
166
199
|
}
|
|
167
|
-
function commandBox(c) {
|
|
200
|
+
function commandBox(c, key) {
|
|
168
201
|
const box = el('div', undefined, 'wt-cmd');
|
|
169
202
|
const code = el('code', c.command, 'mono'); code.tabIndex = 0; code.title = c.label;
|
|
170
203
|
box.append(code, copyButton(c.command));
|
|
204
|
+
const kind = compactKind(c && c.command);
|
|
205
|
+
if (s.writes && kind === 'all') box.append(compactButton('Compact all', { all: true }));
|
|
206
|
+
else if (s.writes && kind === 'run' && key) box.append(compactButton('Compact', { run: key }));
|
|
171
207
|
return box;
|
|
172
208
|
}
|
|
209
|
+
function compactButton(text, target) {
|
|
210
|
+
const b = el('button', text, 'wt-copy ui-danger'); b.type = 'button';
|
|
211
|
+
b.addEventListener('click', () => { runCompact(target); });
|
|
212
|
+
return b;
|
|
213
|
+
}
|
|
214
|
+
function refusedActive(res) { return !!(res && res.status === 409 && res.error !== 'busy'); }
|
|
215
|
+
async function runCompact(target) {
|
|
216
|
+
if (s.compacting) return;
|
|
217
|
+
s.compacting = true;
|
|
218
|
+
for (const child of [...action.children]) child.remove();
|
|
219
|
+
const path = '/api/storage/compact';
|
|
220
|
+
const base = compactBody(target);
|
|
221
|
+
try {
|
|
222
|
+
const preview = await UI.post(path, { ...base, dry_run: true });
|
|
223
|
+
if (!action.isConnected) return;
|
|
224
|
+
if (refusedActive(preview)) {
|
|
225
|
+
UI.outcome(action, { ok: false, status: 409, error: preview.error || 'refused', detail: ACTIVE_RUN });
|
|
226
|
+
return;
|
|
227
|
+
}
|
|
228
|
+
if (!preview || !preview.ok || (preview.data && preview.data.ok === false)) {
|
|
229
|
+
UI.outcome(action, preview && preview.ok ? { ok: false, status: preview.status || 500, error: 'failed', detail: 'Could not preview what compact would free' } : preview);
|
|
230
|
+
return;
|
|
231
|
+
}
|
|
232
|
+
const yes = await UI.confirmInline(action, compactSummary(preview), { danger: true });
|
|
233
|
+
if (!action.isConnected || !yes) return;
|
|
234
|
+
const res = await UI.post(path, { ...base, dry_run: false });
|
|
235
|
+
if (!action.isConnected) return;
|
|
236
|
+
if (refusedActive(res)) {
|
|
237
|
+
UI.outcome(action, { ok: false, status: 409, error: res.error || 'refused', detail: ACTIVE_RUN });
|
|
238
|
+
return;
|
|
239
|
+
}
|
|
240
|
+
if (!res || !res.ok) { UI.outcome(action, res); return; }
|
|
241
|
+
UI.outcome(action, res, compactSummary(res));
|
|
242
|
+
await load(true);
|
|
243
|
+
} finally {
|
|
244
|
+
s.compacting = false;
|
|
245
|
+
}
|
|
246
|
+
}
|
|
173
247
|
const when = t => Number.isFinite(t) ? new Date(t * 1000).toLocaleString() : '—';
|
|
174
248
|
const bytesCell = n => Number.isFinite(n) && n > 0 ? humanBytes(n) : '—';
|
|
175
249
|
const columns = [
|
|
176
250
|
{ id: 'run', label: 'Run', value: r => r.run_id, cell: r => {
|
|
177
|
-
const href = ctx.runHref ? ctx.runHref(r.
|
|
251
|
+
const href = r.key && ctx.runHref ? ctx.runHref(r.key) : null;
|
|
178
252
|
const n = el(href ? 'a' : 'span', r.run_id, 'mono'); if (href) n.href = href; n.title = r.path; return n; } },
|
|
179
253
|
{ id: 'repo', label: 'Repository', value: r => repoName(r.repo), cell: r => { const n = el('span', repoName(r.repo)); if (r.repo) n.title = r.repo; return n; } },
|
|
180
254
|
{ id: 'total', label: 'Total', value: r => r.total, cell: r => humanBytes(r.total) },
|
|
@@ -182,7 +256,7 @@
|
|
|
182
256
|
{ id: 'logs', label: 'Logs', value: r => r.logs + r.gz, cell: r => bytesCell(r.logs + r.gz) },
|
|
183
257
|
{ id: 'strays', label: "Not forge's", title: 'a dependency install or a .git found inside the run dir: forge never removes these', value: r => r.strays, cell: r => bytesCell(r.strays) },
|
|
184
258
|
{ id: 'reclaimable', label: 'Can go', title: 'what forge runs compact --logs would take back (logs estimated)', value: r => r.reclaimable, cell: r => bytesCell(r.reclaimable) },
|
|
185
|
-
{ id: 'command', label: 'Command', sortable: false, cls: 'wt-command-col', cell: r => { const box = el('div', undefined, 'wt-cmds'); for (const c of list(r.commands)) box.append(commandBox(c)); return box; } },
|
|
259
|
+
{ id: 'command', label: 'Command', sortable: false, cls: 'wt-command-col', cell: r => { const box = el('div', undefined, 'wt-cmds'); for (const c of list(r.commands)) box.append(commandBox(c, r.key)); return box; } },
|
|
186
260
|
{ id: 'updated', label: 'Changed', value: r => r.updated, cell: r => when(r.updated) },
|
|
187
261
|
{ id: 'path', label: 'Path', value: r => r.path, cell: r => el('span', r.path, 'mono'), hidden: true },
|
|
188
262
|
];
|
|
@@ -219,6 +293,7 @@
|
|
|
219
293
|
extra.replaceChildren(...out);
|
|
220
294
|
}
|
|
221
295
|
function drawNow() {
|
|
296
|
+
lede.textContent = s.writes ? LEDE_ON : LEDE_OFF;
|
|
222
297
|
const a = s.answer, d = a && a.data;
|
|
223
298
|
if (s.error) status.replaceChildren(el('span', `Could not read the disk report (${s.error}).`, 'warn'));
|
|
224
299
|
else if (!a) status.replaceChildren(el('span', 'Asking…', 'muted'));
|
|
@@ -249,6 +324,12 @@
|
|
|
249
324
|
}
|
|
250
325
|
// A redraw never pulls a command out from under someone selecting or copying it (#115).
|
|
251
326
|
const draw = () => { if (UI.guard) UI.guard(host, drawNow); else drawNow(); };
|
|
327
|
+
UI.controlsEnabled().then(on => {
|
|
328
|
+
const next = !!on;
|
|
329
|
+
if (s.writes === next) return;
|
|
330
|
+
s.writes = next;
|
|
331
|
+
draw();
|
|
332
|
+
});
|
|
252
333
|
|
|
253
334
|
async function load(refresh) {
|
|
254
335
|
const mine = ++s.seq;
|
|
@@ -267,5 +348,5 @@
|
|
|
267
348
|
return { reload: () => load(true) };
|
|
268
349
|
}
|
|
269
350
|
|
|
270
|
-
return { render, humanBytes, summary, homeParts, repoName, HOME_LABEL, PARTS, breakdown, byRepo, pct };
|
|
351
|
+
return { render, humanBytes, summary, homeParts, repoName, HOME_LABEL, PARTS, breakdown, byRepo, pct, compactBody, compactSummary };
|
|
271
352
|
});
|