@giamme/forge 0.18.0 → 0.20.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 +49 -0
- package/README.md +1 -0
- package/SKILL.md +19 -2
- package/VERSION +1 -1
- package/docs/artifacts.md +25 -1
- package/docs/commands.md +217 -18
- package/docs/decomposed-runs.md +114 -1
- package/docs/development.md +2 -1
- package/docs/forge-ui.md +138 -18
- package/docs/memory.md +25 -4
- package/docs/models.md +8 -0
- package/docs/reviews.md +122 -0
- package/forge +26 -3
- package/package.json +2 -1
- package/references/dataset.md +20 -1
- package/references/decompose.md +641 -41
- package/references/harnesses.md +18 -3
- package/references/memory.md +30 -5
- 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-findings.py +675 -0
- package/scripts/forge-group.py +496 -0
- package/scripts/forge-groups.py +89 -0
- package/scripts/forge-handoff.py +1128 -0
- package/scripts/forge-issues.py +228 -97
- 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 +711 -17
- package/scripts/forge-parallel.sh +721 -38
- 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 +417 -52
- package/scripts/forge-solo.sh +2 -0
- package/scripts/forge-sweep.py +199 -44
- 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_findings/__init__.py +17 -0
- package/scripts/forge_findings/apply.py +441 -0
- package/scripts/forge_findings/status.py +43 -0
- package/scripts/forge_findings/store.py +583 -0
- package/scripts/forge_findings/tags.py +53 -0
- package/scripts/forge_findings/triage.py +603 -0
- 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_identity.py +327 -0
- package/scripts/forge_memory_list.py +7 -3
- package/scripts/forge_owner.py +152 -0
- package/scripts/forge_side/__init__.py +228 -38
- package/ui/docs/api.md +303 -29
- package/ui/forge_ui/control.py +1018 -6
- 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/projects.py +209 -22
- 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/findingsactions.js +201 -0
- package/ui/forge_ui/static/groupsview.js +332 -0
- package/ui/forge_ui/static/index.html +3 -0
- package/ui/forge_ui/static/panel.js +127 -7
- package/ui/forge_ui/static/projectsview.js +764 -30
- 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 +138 -5
- package/ui/forge_ui/static/triageview.js +423 -0
- package/ui/forge_ui/static/worktreesview.js +233 -12
- package/ui/forge_ui/storage.py +14 -0
|
@@ -3,7 +3,9 @@
|
|
|
3
3
|
Routes: #/projects (the list) and #/projects/<id>[/runs|/findings|/memories]. The id is the run cloud's.
|
|
4
4
|
Each tab reads its own endpoint when it opens, never on the page's poll; "Read again" asks the server to read
|
|
5
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.
|
|
6
|
+
and only ever enter the page as text. With writes on, Memories can edit or add a learning (confirm first);
|
|
7
|
+
read-only, the row shows the forge memory command to copy. The pure helpers are tested in
|
|
8
|
+
ui/tests/js/projectsview.test.js and ui/tests/js/memoriesedit.test.js.
|
|
7
9
|
ctx = { id?, tab?, runs() (the page's run list), runHref(key), tablePrefs?(id), saveTablePrefs?(id, prefs) }. */
|
|
8
10
|
(function (root, factory) {
|
|
9
11
|
'use strict';
|
|
@@ -14,22 +16,29 @@
|
|
|
14
16
|
'use strict';
|
|
15
17
|
|
|
16
18
|
const list = v => Array.isArray(v) ? v : [];
|
|
19
|
+
const A = root.ForgeFindingsActions || (typeof require === 'function' ? require('./findingsactions.js') : null);
|
|
20
|
+
const T = root.ForgeTriage || (typeof require === 'function' ? require('./triageview.js') : null);
|
|
17
21
|
const SEVERITIES = ['P0', 'P1', 'P2', 'P3'];
|
|
18
|
-
const STATUSES = ['open', 'filed', 'fixed', 'swept', 'dismissed', 'superseded'];
|
|
22
|
+
const STATUSES = ['open', 'to-file', 'filed', 'fixed', 'swept', 'dismissed', 'duplicate', 'shadow', 'unlabelled', 'superseded'];
|
|
23
|
+
const LAMPS = { open: 'lamp-off', 'to-file': 'lamp-route', filed: 'fnd-amber', fixed: 'st-pass', swept: 'st-pass', dismissed: 'lamp-off', duplicate: 'lamp-off',
|
|
24
|
+
shadow: 'st-outdated', unlabelled: 'st-unknown', superseded: 'st-outdated' };
|
|
25
|
+
const OPEN = ['open', 'to-file']; // the filter `open` shows both: a finding marked to file is still open work
|
|
19
26
|
const STATES = { in_memory: 'in memory', waiting: 'waiting for a second run', stale: 'dropped: stale', capped: 'dropped: trimmed by the cap',
|
|
20
27
|
muted: 'not injected (curated out)', dropped: 'dropped', gone: 'from a checkout that is gone' };
|
|
21
28
|
const TABS = ['runs', 'findings', 'memories'];
|
|
22
29
|
const ROLES_NOTE = 'planner and dwarf get Verify, Known traps and Recurring QA findings; QA gets the last two';
|
|
23
30
|
|
|
24
31
|
/* ---------- pure ---------- */
|
|
25
|
-
// filter = { severity: 'all' | P0..P3, status: 'all' | 'open' (default) | STATUSES,
|
|
26
|
-
// since: 0 (days, 0 = any), shadow: false }
|
|
32
|
+
// filter = { severity: 'all' | P0..P3, status: 'all' | 'open' (default: open and to-file) | STATUSES, tag: '' | a tag, run: '' | run id,
|
|
33
|
+
// reviewer: '', path: '' (substring), since: 0 (days, 0 = any), shadow: false, fp: '' (one finding, by its record key; set by a triage card) }
|
|
27
34
|
function filterFindings(rows, filter, now) {
|
|
28
35
|
const f = filter || {}, sev = f.severity || 'all', status = f.status || 'open', path = String(f.path || '').toLowerCase();
|
|
29
36
|
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)
|
|
32
|
-
&& (
|
|
37
|
+
return list(rows).filter(r => (f.shadow || r.kind !== 'shadow' || status === 'shadow')
|
|
38
|
+
&& (sev === 'all' || r.severity === sev)
|
|
39
|
+
&& (status === 'all' || (status === 'open' ? OPEN.includes(r.status) : r.status === status))
|
|
40
|
+
&& (!f.tag || list(r.tags).includes(f.tag))
|
|
41
|
+
&& (!f.run || r.run_id === f.run) && (!f.reviewer || r.reviewer === f.reviewer) && (!f.fp || r.record_fp === f.fp)
|
|
33
42
|
&& (!path || String(r.location || '').toLowerCase().includes(path))
|
|
34
43
|
&& (since === null || (Number.isFinite(r.at) && r.at >= since)));
|
|
35
44
|
}
|
|
@@ -47,6 +56,66 @@
|
|
|
47
56
|
return list(rows).filter(r => (cat === 'all' || r.category === cat) && (st === 'all' || stateFor(r, source).state === st)
|
|
48
57
|
&& (!text || String(r.text || '').toLowerCase().includes(text)));
|
|
49
58
|
}
|
|
59
|
+
// The forget wire key is the learning's own category and key, joined once. A row missing either is not selectable.
|
|
60
|
+
function learningKey(row) {
|
|
61
|
+
if (!row || row.category == null || row.key == null) return '';
|
|
62
|
+
const category = String(row.category), key = String(row.key);
|
|
63
|
+
return category && key ? category + ':' + key : '';
|
|
64
|
+
}
|
|
65
|
+
// Keys to forget, in learning order. `selected` is a Set or array of learning rows or of "category:key" strings.
|
|
66
|
+
function forgetKeys(learnings, selected) {
|
|
67
|
+
const want = selected instanceof Set ? selected : new Set(list(selected));
|
|
68
|
+
const out = [], seen = new Set();
|
|
69
|
+
for (const row of list(learnings)) {
|
|
70
|
+
const key = learningKey(row);
|
|
71
|
+
if (!key || seen.has(key) || (!want.has(row) && !want.has(key))) continue;
|
|
72
|
+
seen.add(key);
|
|
73
|
+
out.push(key);
|
|
74
|
+
}
|
|
75
|
+
return out;
|
|
76
|
+
}
|
|
77
|
+
function forgetData(res) {
|
|
78
|
+
const body = res && res.data && res.data.checkouts ? res.data : res;
|
|
79
|
+
return body && body.checkouts ? body : null;
|
|
80
|
+
}
|
|
81
|
+
// The confirm sentence: the chosen learnings, then the memory.md lines the dry run says go. All of it is text.
|
|
82
|
+
function forgetConfirmText(learnings, keys, res) {
|
|
83
|
+
const byKey = new Map();
|
|
84
|
+
for (const row of list(learnings)) { const key = learningKey(row); if (key && !byKey.has(key)) byKey.set(key, row); }
|
|
85
|
+
const lines = ['Forget these learnings?'];
|
|
86
|
+
for (const key of keys) {
|
|
87
|
+
const row = byKey.get(key), text = row && row.text != null ? String(row.text) : '';
|
|
88
|
+
lines.push(text ? key + ' — ' + text : key);
|
|
89
|
+
}
|
|
90
|
+
const removed = [];
|
|
91
|
+
for (const checkout of list(forgetData(res) && forgetData(res).checkouts)) {
|
|
92
|
+
for (const line of list(checkout && checkout.result && checkout.result.memory_lines_removed)) {
|
|
93
|
+
if (line != null && String(line) !== '') removed.push(String(line));
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
lines.push(removed.length ? 'memory.md lines that go:' : 'No memory.md line goes.');
|
|
97
|
+
return lines.concat(removed).join('\n');
|
|
98
|
+
}
|
|
99
|
+
// One line per key after the real call: how many ledger rows went, or that the key was not found.
|
|
100
|
+
function forgetResultLines(res) {
|
|
101
|
+
const lines = [];
|
|
102
|
+
for (const checkout of list(forgetData(res) && forgetData(res).checkouts)) {
|
|
103
|
+
const result = checkout && checkout.result;
|
|
104
|
+
if (!result) {
|
|
105
|
+
const err = checkout && checkout.error;
|
|
106
|
+
const why = typeof err === 'string' ? err : err && (err.detail || err.error);
|
|
107
|
+
lines.push(why || 'Could not forget in this checkout');
|
|
108
|
+
continue;
|
|
109
|
+
}
|
|
110
|
+
for (const item of list(result.keys)) {
|
|
111
|
+
if (!item || item.key == null) continue;
|
|
112
|
+
if (!item.found) { lines.push(String(item.key) + ': not found'); continue; }
|
|
113
|
+
const rows = typeof item.rows === 'number' && Number.isFinite(item.rows) ? item.rows : 0;
|
|
114
|
+
lines.push(String(item.key) + ': ' + rows + (rows === 1 ? ' row' : ' rows') + ' removed');
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
return lines;
|
|
118
|
+
}
|
|
50
119
|
// what the Memories tab says when there is nothing to show
|
|
51
120
|
function memoryEmpty(data) {
|
|
52
121
|
if (!data) return null;
|
|
@@ -54,6 +123,88 @@
|
|
|
54
123
|
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
124
|
return null;
|
|
56
125
|
}
|
|
126
|
+
const MEMORY_CATEGORIES = ['verify', 'trap', 'finding'];
|
|
127
|
+
const MEMORY_TEXT_MAX = 300;
|
|
128
|
+
const MEMORY_PATH_MAX = 300;
|
|
129
|
+
const MEMORY_PATHS_MAX = 20;
|
|
130
|
+
const MEMORY_KEY_MAX = 256;
|
|
131
|
+
const MEMORY_KEY_RE = /^[^:\s-][^:]*:.+$/;
|
|
132
|
+
const MEMORY_CONTROL_RE = /[\u0000-\u001f\u007f]/;
|
|
133
|
+
function memoryTextError(text) {
|
|
134
|
+
if (typeof text !== 'string' || MEMORY_CONTROL_RE.test(text) || text.length < 1 || text.length > MEMORY_TEXT_MAX)
|
|
135
|
+
return 'text must be one line of 1 to 300 characters';
|
|
136
|
+
return '';
|
|
137
|
+
}
|
|
138
|
+
function memoryPathError(path) {
|
|
139
|
+
if (typeof path !== 'string' || !path || path.length > MEMORY_PATH_MAX) return 'a path is at most 300 characters';
|
|
140
|
+
if (MEMORY_CONTROL_RE.test(path) || /[,[\]]/.test(path)) return 'a path must not contain a comma, a bracket or a control character';
|
|
141
|
+
if (path.startsWith('/') || path.startsWith('\\')) return 'a path must be relative';
|
|
142
|
+
if (path.split(/[\\/]/).includes('..')) return 'a path must not contain ..';
|
|
143
|
+
return '';
|
|
144
|
+
}
|
|
145
|
+
// `value` is a list or a comma-separated line. Empty means no paths.
|
|
146
|
+
function memoryPaths(value) {
|
|
147
|
+
if (value == null || value === '') return { paths: [] };
|
|
148
|
+
let items = value;
|
|
149
|
+
if (typeof value === 'string') items = value.split(',').map(part => part.trim()).filter(Boolean);
|
|
150
|
+
if (!Array.isArray(items)) return { error: 'paths must be a list of relative paths' };
|
|
151
|
+
if (items.length > MEMORY_PATHS_MAX) return { error: 'at most 20 paths' };
|
|
152
|
+
const paths = [];
|
|
153
|
+
for (const item of items) {
|
|
154
|
+
const path = typeof item === 'string' ? item.trim() : item;
|
|
155
|
+
const error = memoryPathError(path);
|
|
156
|
+
if (error) return { error };
|
|
157
|
+
if (!paths.includes(path)) paths.push(path);
|
|
158
|
+
}
|
|
159
|
+
return { paths };
|
|
160
|
+
}
|
|
161
|
+
// The POST body for memories/add: {body} or {error}. `input` is {category, text, paths?, path?}.
|
|
162
|
+
function memoryAddBody(input) {
|
|
163
|
+
const o = input || {};
|
|
164
|
+
const category = typeof o.category === 'string' ? o.category : '';
|
|
165
|
+
if (!MEMORY_CATEGORIES.includes(category)) return { error: 'category must be verify, trap or finding' };
|
|
166
|
+
const textError = memoryTextError(o.text);
|
|
167
|
+
if (textError) return { error: textError };
|
|
168
|
+
const parsed = memoryPaths(o.paths);
|
|
169
|
+
if (parsed.error) return { error: parsed.error };
|
|
170
|
+
const body = { category, text: o.text };
|
|
171
|
+
if (parsed.paths.length) body.paths = parsed.paths;
|
|
172
|
+
if (typeof o.path === 'string' && o.path) body.path = o.path;
|
|
173
|
+
return { body };
|
|
174
|
+
}
|
|
175
|
+
// The POST body for memories/edit: {body} or {error}. The checkout path, when there is one, is added by the page.
|
|
176
|
+
function memoryEditBody(key, text) {
|
|
177
|
+
if (typeof key !== 'string' || !key || key.length > MEMORY_KEY_MAX || MEMORY_CONTROL_RE.test(key) || !MEMORY_KEY_RE.test(key))
|
|
178
|
+
return { error: 'key must be category:key' };
|
|
179
|
+
const textError = memoryTextError(text);
|
|
180
|
+
if (textError) return { error: textError };
|
|
181
|
+
return { body: { key, text } };
|
|
182
|
+
}
|
|
183
|
+
// One argument for a POSIX shell. A safe word stays bare; quotes and `$` stay literal inside single quotes.
|
|
184
|
+
function shellQuote(value) {
|
|
185
|
+
const text = value == null ? '' : String(value);
|
|
186
|
+
if (text !== '' && /^[A-Za-z0-9_@%+=:,./-]+$/.test(text) && !text.startsWith('-')) return text;
|
|
187
|
+
return "'" + text.replace(/'/g, "'\\''") + "'";
|
|
188
|
+
}
|
|
189
|
+
// `forge memory add|edit <checkout> …`, shell-quoted, for a person to copy. Not the argv the server runs.
|
|
190
|
+
function memoryCommand(op, checkout, input) {
|
|
191
|
+
const o = input || {};
|
|
192
|
+
const head = ['forge memory', op, shellQuote(checkout == null ? '' : checkout)];
|
|
193
|
+
if (op === 'edit') {
|
|
194
|
+
head.push(shellQuote(o.key == null ? 'category:key' : o.key), '--text', shellQuote(o.text == null ? 'TEXT' : o.text));
|
|
195
|
+
} else {
|
|
196
|
+
head.push('--category', shellQuote(o.category || 'verify'), '--text', shellQuote(o.text == null ? 'TEXT' : o.text));
|
|
197
|
+
for (const path of list(o.paths)) head.push('--path', shellQuote(path));
|
|
198
|
+
}
|
|
199
|
+
return head.join(' ');
|
|
200
|
+
}
|
|
201
|
+
// `manual` is set when a person wrote a row. The projects answer keeps each row's role and may omit the flag;
|
|
202
|
+
// forge sets the flag for exactly the role `person`.
|
|
203
|
+
function learningManual(row) {
|
|
204
|
+
if (!row) return false;
|
|
205
|
+
if (row.manual === true) return true;
|
|
206
|
+
return list(row.rows).some(item => item && item.role === 'person');
|
|
207
|
+
}
|
|
57
208
|
// A summary without what its own columns show: the bullet, the [P1][CONFIRMED] tags and a leading location.
|
|
58
209
|
function cleanSummary(text, location) {
|
|
59
210
|
let s = String(text || '').replace(/^\s*(?:[-*+•]|\d+[.)])\s*/, '').replace(/\*\*/g, '');
|
|
@@ -73,8 +224,10 @@
|
|
|
73
224
|
const when = t => Number.isFinite(t) ? new Date(t * 1000).toLocaleString() : '—';
|
|
74
225
|
const guard = (region, draw) => { if (UI.guard) UI.guard(region, draw); else draw(); };
|
|
75
226
|
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
|
|
227
|
+
ffilter: { severity: 'all', status: 'open', tag: '', run: '', reviewer: '', path: '', since: 0, shadow: false },
|
|
228
|
+
mfilter: { category: 'all', state: 'all', text: '' }, source: null, checkout: '', error: null, seq: 0, timer: null,
|
|
229
|
+
writes: false, picked: new Set(), forgetNote: null, forgetting: false, forgetEpoch: 0, forgetHost: null,
|
|
230
|
+
fsel: new Set(), acting: false, actEpoch: 0, actHost: null, actResult: null, triage: {}, triagePanel: null };
|
|
78
231
|
const tablePrefs = id => ctx.tablePrefs ? ctx.tablePrefs(id) : null, savePrefs = id => p => ctx.saveTablePrefs && ctx.saveTablePrefs(id, p);
|
|
79
232
|
|
|
80
233
|
function table(parent, id, label, columns, rows, extra) {
|
|
@@ -85,11 +238,52 @@
|
|
|
85
238
|
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
239
|
b.addEventListener('click', onClick); return b;
|
|
87
240
|
}
|
|
241
|
+
// confirmInline settles only when its own host answers. A redraw drops that host (another checkout,
|
|
242
|
+
// Read again, leaving the tab), the await never finishes, and `forgetting` stays true, so every later
|
|
243
|
+
// checkbox and the Forget button are drawn disabled. Cancel the strip now and retire the attempt.
|
|
244
|
+
function press(node) {
|
|
245
|
+
if (node && typeof node.click === 'function') node.click();
|
|
246
|
+
}
|
|
247
|
+
function dismissConfirm(host) {
|
|
248
|
+
if (!host) return;
|
|
249
|
+
for (const child of [...(host.children || [])]) {
|
|
250
|
+
if (!child.classList || !child.classList.contains('ui-confirm')) continue;
|
|
251
|
+
for (const button of child.children || []) {
|
|
252
|
+
if (button.tagName === 'BUTTON' && button.textContent === 'Cancel') { press(button); return; }
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
// The same for a finding action (a confirm, or the drafts being made for File selected).
|
|
257
|
+
function abandonAct() {
|
|
258
|
+
if (!s.acting) return;
|
|
259
|
+
const host = s.actHost;
|
|
260
|
+
s.acting = false;
|
|
261
|
+
s.actEpoch += 1;
|
|
262
|
+
s.actHost = null;
|
|
263
|
+
dismissConfirm(host);
|
|
264
|
+
}
|
|
265
|
+
// The triage panel's polling and its confirm end with the draw that made it.
|
|
266
|
+
function abandonTriage() {
|
|
267
|
+
const panel = s.triagePanel;
|
|
268
|
+
s.triagePanel = null;
|
|
269
|
+
if (panel) panel.stop();
|
|
270
|
+
}
|
|
271
|
+
function abandonForget() {
|
|
272
|
+
abandonTriage();
|
|
273
|
+
abandonAct();
|
|
274
|
+
if (!s.forgetting) return;
|
|
275
|
+
const host = s.forgetHost;
|
|
276
|
+
s.forgetting = false;
|
|
277
|
+
s.forgetEpoch += 1;
|
|
278
|
+
s.forgetHost = null;
|
|
279
|
+
dismissConfirm(host);
|
|
280
|
+
}
|
|
88
281
|
const notes = n => el('div', undefined, 'prj-notes muted');
|
|
89
282
|
function fill(node, items) { node.replaceChildren(...list(items).map(t => el('p', String(t)))); }
|
|
90
283
|
|
|
91
284
|
/* the list */
|
|
92
285
|
function drawList() {
|
|
286
|
+
abandonForget();
|
|
93
287
|
const head = el('div', undefined, 'prj-head'), body = el('div', undefined, 'prj-body');
|
|
94
288
|
head.append(el('h1', 'Projects', 'module-title'));
|
|
95
289
|
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 +311,7 @@
|
|
|
117
311
|
|
|
118
312
|
/* one project */
|
|
119
313
|
function drawProject() {
|
|
314
|
+
abandonForget();
|
|
120
315
|
const head = el('div', undefined, 'prj-head'), tabs = el('nav', undefined, 'seg prj-tabs'), body = el('div', undefined, 'prj-body');
|
|
121
316
|
tabs.setAttribute('aria-label', 'Project tabs');
|
|
122
317
|
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 +334,7 @@
|
|
|
139
334
|
return draw;
|
|
140
335
|
}
|
|
141
336
|
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; }
|
|
337
|
+
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
338
|
if (s.tab === 'runs') return drawRuns(body, note);
|
|
144
339
|
if (s.tab === 'findings') return drawFindings(body, note);
|
|
145
340
|
return drawMemories(body, note);
|
|
@@ -147,6 +342,7 @@
|
|
|
147
342
|
|
|
148
343
|
/* Runs */
|
|
149
344
|
function drawRuns(body, note) {
|
|
345
|
+
abandonForget();
|
|
150
346
|
fill(note, []);
|
|
151
347
|
const runs = list(s.detail.runs), checkouts = list(s.detail.checkouts);
|
|
152
348
|
const bar = el('div', undefined, 'prj-filters');
|
|
@@ -174,11 +370,27 @@
|
|
|
174
370
|
}
|
|
175
371
|
|
|
176
372
|
/* Findings */
|
|
373
|
+
function copyButton(command) {
|
|
374
|
+
const b = el('button', 'Copy', 'fnd-copy'); b.type = 'button'; b.setAttribute('aria-label', 'Copy: ' + command);
|
|
375
|
+
b.addEventListener('click', async () => {
|
|
376
|
+
try { await navigator.clipboard.writeText(command); b.textContent = 'Copied'; } catch (_) { b.textContent = 'Copy failed: select it'; }
|
|
377
|
+
setTimeout(() => { b.textContent = 'Copy'; }, 2500);
|
|
378
|
+
});
|
|
379
|
+
return b;
|
|
380
|
+
}
|
|
177
381
|
function drawFindings(body, note) {
|
|
382
|
+
abandonForget();
|
|
178
383
|
const d = s.findings;
|
|
179
384
|
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
|
-
|
|
385
|
+
const lines = 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.`] : []);
|
|
386
|
+
if (d.issues_online && Number.isFinite(d.issues_read_at)) lines.push(`issue states read from GitHub at ${when(d.issues_read_at)}`);
|
|
387
|
+
else if (!d.issues_online && !lines.some(n => /GitHub/.test(String(n)))) lines.push('issue states were not read from GitHub (offline): filed findings may show as open');
|
|
388
|
+
fill(note, lines);
|
|
181
389
|
const rows = list(d.rows);
|
|
390
|
+
const have = new Set(rows.map(r => r.record_fp));
|
|
391
|
+
for (const fp of [...s.fsel]) if (!have.has(fp)) s.fsel.delete(fp);
|
|
392
|
+
const tags = A.tagsIn(rows);
|
|
393
|
+
if (s.ffilter.tag && !tags.includes(s.ffilter.tag)) s.ffilter.tag = '';
|
|
182
394
|
const bar = el('div', undefined, 'prj-filters');
|
|
183
395
|
const select = (name, text, options) => {
|
|
184
396
|
const l = el('label', undefined, 'fnd-field'), sel = el('select'); sel.dataset.filter = name;
|
|
@@ -188,7 +400,9 @@
|
|
|
188
400
|
l.append(el('span', text, 'plate'), sel); bar.append(l);
|
|
189
401
|
};
|
|
190
402
|
const counts = {}; for (const r of rows) counts[r.status] = (counts[r.status] || 0) + 1;
|
|
191
|
-
|
|
403
|
+
const countOf = x => x === 'open' ? OPEN.reduce((n, k) => n + (counts[k] || 0), 0) : counts[x] || 0;
|
|
404
|
+
select('status', 'Status', [['all', 'all']].concat(STATUSES.map(x => [x, `${x} (${countOf(x)})`])));
|
|
405
|
+
select('tag', 'Tag', [['', 'all']].concat(tags.map(t => [t, t])));
|
|
192
406
|
select('severity', 'Severity', [['all', 'all']].concat(SEVERITIES.map(x => [x, x])));
|
|
193
407
|
select('run', 'Run', [['', 'all']].concat(Array.from(new Set(rows.map(r => r.run_id).filter(Boolean))).sort().map(x => [x, x])));
|
|
194
408
|
select('reviewer', 'Reviewer', [['', 'all']].concat(Array.from(new Set(rows.map(r => r.reviewer).filter(Boolean))).sort().map(x => [x, x])));
|
|
@@ -202,34 +416,278 @@
|
|
|
202
416
|
const again = readAgain(() => loadTab(true));
|
|
203
417
|
bar.append(again);
|
|
204
418
|
const count = el('p', '', 'muted prj-count'), tableHost = el('div', undefined, 'prj-table');
|
|
205
|
-
|
|
419
|
+
const formHost = el('div', undefined, 'fnd-form'), actHost = el('div', undefined, 'fnd-confirm'), noteHost = el('div', undefined, 'fnd-result');
|
|
420
|
+
s.actHost = actHost;
|
|
421
|
+
const triageHost = el('div', undefined, 'triage-host');
|
|
422
|
+
if (T) {
|
|
423
|
+
s.triagePanel = T.render(triageHost, {
|
|
424
|
+
id: s.id, root: s.detail && s.detail.root, writes: s.writes, store: s.triage, reload: () => { if (s.tab === 'findings') loadTab(true); },
|
|
425
|
+
openCount: () => rows.filter(r => OPEN.includes(r.status) && r.kind !== 'shadow').length,
|
|
426
|
+
rows: () => rows,
|
|
427
|
+
show: fp => { s.ffilter = { severity: 'all', status: 'all', tag: '', run: '', reviewer: '', path: '', since: 0, shadow: true, fp }; drawFindings(body, note); },
|
|
428
|
+
});
|
|
429
|
+
}
|
|
430
|
+
if (s.actResult) { UI.outcome(noteHost, s.actResult.res, s.actResult.text, { silent: true }); s.actResult = null; } // shown once
|
|
431
|
+
const shownNow = () => filterFindings(rows, s.ffilter);
|
|
432
|
+
const selectedNow = () => A.selectedRows(shownNow(), s.fsel);
|
|
433
|
+
|
|
434
|
+
/* the write controls */
|
|
435
|
+
let allBox = null, picked = null;
|
|
436
|
+
const opButtons = {};
|
|
437
|
+
function syncBar() {
|
|
438
|
+
if (!picked) return;
|
|
439
|
+
const sel = selectedNow(), ok = A.allowed(sel);
|
|
440
|
+
picked.textContent = ok.why || `${ok.count} selected`;
|
|
441
|
+
for (const [op, b] of Object.entries(opButtons)) b.disabled = s.acting || !ok[op];
|
|
442
|
+
const shown = shownNow().filter(A.selectable);
|
|
443
|
+
allBox.checked = shown.length > 0 && shown.every(r => s.fsel.has(r.record_fp));
|
|
444
|
+
allBox.disabled = !shown.length;
|
|
445
|
+
}
|
|
446
|
+
const closeForm = () => formHost.replaceChildren();
|
|
447
|
+
// Confirm, post, and show what the route said. Copies forgetSelected's guard: a redraw (Read again, another tab)
|
|
448
|
+
// drops this strip, so its epoch is retired, the controls are usable again, and a request already sent keeps its result.
|
|
449
|
+
async function perform(op, fps, request) {
|
|
450
|
+
if (s.acting) { UI.outcome(noteHost, { ok: false, status: 409, error: 'busy', detail: 'another action is waiting for its confirm' }); return; }
|
|
451
|
+
const epoch = s.actEpoch, host = actHost, current = () => epoch === s.actEpoch && host.isConnected;
|
|
452
|
+
s.acting = true; s.actResult = null; s.actHost = host; syncBar();
|
|
453
|
+
noteHost.replaceChildren();
|
|
454
|
+
for (const child of [...host.children]) child.remove();
|
|
455
|
+
try {
|
|
456
|
+
const yes = await UI.confirmInline(host, A.confirmText(op, fps.length, request), {});
|
|
457
|
+
if (!current() || !yes) return;
|
|
458
|
+
const res = await UI.post(A.pathOf(s.id, op), request);
|
|
459
|
+
s.actResult = { res, text: `${fps.length} finding${fps.length === 1 ? '' : 's'} ${A.PAST[op]}` };
|
|
460
|
+
if (res && res.ok) for (const fp of fps) s.fsel.delete(fp);
|
|
461
|
+
if (!current()) { if (s.tab === 'findings') await loadTab(true); return; }
|
|
462
|
+
if (!res || !res.ok) { s.actResult = null; UI.outcome(noteHost, res); return; } // shown here, not again on a redraw
|
|
463
|
+
closeForm();
|
|
464
|
+
s.acting = false;
|
|
465
|
+
await loadTab(true);
|
|
466
|
+
} finally {
|
|
467
|
+
if (epoch === s.actEpoch) { s.acting = false; if (host.isConnected) syncBar(); }
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
const textInput = (ph, max) => { const i = el('input'); i.type = 'text'; i.placeholder = ph; if (max) i.maxLength = max; return i; };
|
|
471
|
+
const field = (label, input) => { const l = el('label', undefined, 'fnd-field'); l.append(el('span', label, 'plate'), input); return l; };
|
|
472
|
+
function openForm(op, row) {
|
|
473
|
+
const fpsNow = () => row ? [row.record_fp] : A.fpsOf(selectedNow());
|
|
474
|
+
if (op === 'reopen') { const fps = fpsNow(), built = A.bodyFor(op, fps, {}); if (built.error) UI.outcome(noteHost, { ok: false, error: built.error }); else perform(op, fps, built.body); return; }
|
|
475
|
+
closeForm();
|
|
476
|
+
let collect = () => ({}), first = null;
|
|
477
|
+
const parts = [], heading = el('p', undefined, 'fnd-form-title');
|
|
478
|
+
if (op === 'fix') {
|
|
479
|
+
const c = textInput('7 to 40 hex characters'), r = textInput('why (optional with a commit)', 500); first = c;
|
|
480
|
+
parts.push(field('Commit', c), field('Reason', r)); collect = () => ({ commit: c.value, reason: r.value });
|
|
481
|
+
heading.textContent = 'Mark fixed: give a commit, a reason, or both';
|
|
482
|
+
} else if (op === 'dismiss') {
|
|
483
|
+
const r = textInput('why it needs no work', 500); first = r;
|
|
484
|
+
parts.push(field('Reason (required)', r)); collect = () => ({ reason: r.value });
|
|
485
|
+
heading.textContent = 'Dismiss: say why';
|
|
486
|
+
} else if (op === 'to-file') {
|
|
487
|
+
const t = textInput('issue title (optional)', 200); first = t;
|
|
488
|
+
parts.push(field('Title', t)); collect = () => ({ title: t.value });
|
|
489
|
+
heading.textContent = 'Mark to file: keep a draft issue for these findings';
|
|
490
|
+
} else if (op === 'dup') {
|
|
491
|
+
const sel = el('select'); first = sel;
|
|
492
|
+
const mine = fpsNow()[0];
|
|
493
|
+
for (const r of shownNow().filter(x => A.selectable(x) && x.record_fp !== mine)) {
|
|
494
|
+
const o = el('option', `${r.severity || '—'} ${cleanSummary(r.summary, r.location).slice(0, 90)} · ${r.record_fp}`); o.value = r.record_fp; sel.append(o);
|
|
495
|
+
}
|
|
496
|
+
if (!sel.children.length) parts.push(el('p', 'No other finding is shown: widen the filters to pick the original.', 'muted'));
|
|
497
|
+
else { parts.push(field('Duplicate of', sel)); collect = () => ({ of: sel.value }); }
|
|
498
|
+
heading.textContent = 'Mark duplicate: pick the finding it repeats';
|
|
499
|
+
} else if (op === 'tag') {
|
|
500
|
+
const t = textInput('tags, comma separated'), m = el('select'); first = t;
|
|
501
|
+
for (const [v, x] of [['add', 'Add'], ['remove', 'Remove']]) { const o = el('option', x); o.value = v; m.append(o); }
|
|
502
|
+
parts.push(field('Tags', t), field('Action', m)); collect = () => ({ tags: t.value, remove: m.value === 'remove' });
|
|
503
|
+
heading.textContent = 'Tags: lowercase, digits and dashes, at most 8';
|
|
504
|
+
} else if (op === 'note') {
|
|
505
|
+
const t = el('textarea'); t.rows = 3; t.maxLength = 2000; t.placeholder = 'a note (empty clears it)'; t.value = row && row.record && row.record.note || ''; first = t;
|
|
506
|
+
parts.push(field('Note', t)); collect = () => ({ text: t.value });
|
|
507
|
+
heading.textContent = 'Note on ' + (row ? cleanSummary(row.summary, row.location).slice(0, 80) : 'the finding');
|
|
508
|
+
} else if (op === 'edit') {
|
|
509
|
+
const sv = el('select'), t = el('textarea'); first = sv; t.rows = 4; t.maxLength = 4000;
|
|
510
|
+
const was = row && row.record && row.record.edit && row.record.edit.text || (row && (row.text || row.summary)) || '';
|
|
511
|
+
t.value = was;
|
|
512
|
+
for (const v of [''].concat(SEVERITIES)) { const o = el('option', v || 'keep'); o.value = v; sv.append(o); }
|
|
513
|
+
sv.value = '';
|
|
514
|
+
parts.push(field('Severity', sv), field('Text', t));
|
|
515
|
+
collect = () => ({ severity: sv.value, text: t.value === was ? undefined : t.value });
|
|
516
|
+
heading.textContent = 'Edit ' + (row ? cleanSummary(row.summary, row.location).slice(0, 80) : 'the finding') + (row && row.severity ? ` (now ${row.severity})` : '');
|
|
517
|
+
}
|
|
518
|
+
const msg = el('p', undefined, 'warn fnd-form-msg');
|
|
519
|
+
const apply = () => {
|
|
520
|
+
const fps = fpsNow(), built = A.bodyFor(op, fps, collect());
|
|
521
|
+
if (built.error) { msg.textContent = built.error; return; }
|
|
522
|
+
msg.textContent = '';
|
|
523
|
+
perform(op, fps, built.body);
|
|
524
|
+
};
|
|
525
|
+
const go = el('button', 'Apply', 'primary'); go.type = 'button'; go.addEventListener('click', apply);
|
|
526
|
+
const cancel = el('button', 'Cancel'); cancel.type = 'button'; cancel.addEventListener('click', closeForm);
|
|
527
|
+
const wrap = el('div', undefined, 'fnd-form-body');
|
|
528
|
+
wrap.append(...parts, go, cancel);
|
|
529
|
+
wrap.addEventListener('keydown', e => {
|
|
530
|
+
if (e.key === 'Escape') { e.preventDefault(); e.stopPropagation(); closeForm(); }
|
|
531
|
+
else if (e.key === 'Enter' && e.target && e.target.tagName === 'INPUT') { e.preventDefault(); apply(); }
|
|
532
|
+
});
|
|
533
|
+
formHost.append(heading, wrap, msg);
|
|
534
|
+
if (first && first.focus) first.focus();
|
|
535
|
+
}
|
|
536
|
+
// File selected: drafts for exactly the chosen findings, a dialog, and the POST only after its confirm.
|
|
537
|
+
async function fileSelected() {
|
|
538
|
+
const FF = root.ForgeFindings;
|
|
539
|
+
if (s.acting || !FF) return;
|
|
540
|
+
const sel = selectedNow(), fps = A.fileableFps(sel), key = A.fileRun(sel);
|
|
541
|
+
if (!fps.length || !key) return;
|
|
542
|
+
const epoch = s.actEpoch;
|
|
543
|
+
s.acting = true; s.actResult = null; s.actHost = actHost; noteHost.replaceChildren(); syncBar();
|
|
544
|
+
let res;
|
|
545
|
+
try { res = await UI.get(FF.issuesUrl(key, { scope: 'repo', offline: false, plausible: true, only: fps })); }
|
|
546
|
+
finally { if (epoch === s.actEpoch) { s.acting = false; if (actHost.isConnected) syncBar(); } }
|
|
547
|
+
if (!res || !res.ok) {
|
|
548
|
+
if (epoch === s.actEpoch && actHost.isConnected) UI.outcome(noteHost, res); else s.actResult = { res };
|
|
549
|
+
return;
|
|
550
|
+
}
|
|
551
|
+
fileDialog(FF, key, fps, list(res.data && res.data.drafts));
|
|
552
|
+
}
|
|
553
|
+
function fileDialog(FF, key, fps, drafts) {
|
|
554
|
+
const dlg = el('dialog', undefined, 'fnd-dialog'); dlg.setAttribute('aria-label', 'File issues on GitHub');
|
|
555
|
+
document.body.append(dlg);
|
|
556
|
+
let posting = false;
|
|
557
|
+
const cleanup = () => { dlg.remove(); };
|
|
558
|
+
const shut = () => { if (typeof dlg.close === 'function') dlg.close(); else cleanup(); };
|
|
559
|
+
dlg.addEventListener('close', cleanup);
|
|
560
|
+
dlg.addEventListener('click', e => { if (e.target === dlg && !posting) shut(); });
|
|
561
|
+
dlg.addEventListener('cancel', e => { if (posting) e.preventDefault(); });
|
|
562
|
+
dlg.append(el('h2', 'File issues on GitHub'));
|
|
563
|
+
const warn = el('p', undefined, 'fnd-warn');
|
|
564
|
+
warn.append(el('i', undefined, 'lamp st-running'), el('span', `This creates ${drafts.length} issue${drafts.length === 1 ? '' : 's'} on this repository's GitHub project, from your gh login, and cannot be undone from here.`));
|
|
565
|
+
dlg.append(warn);
|
|
566
|
+
if (!drafts.length) dlg.append(el('p', 'forge has no draft for this selection (its findings may be filed already).', 'muted'));
|
|
567
|
+
for (const dr of drafts) {
|
|
568
|
+
const art = el('article', undefined, 'fnd-draft'), h = el('h3', undefined, 'fnd-draft-title');
|
|
569
|
+
h.append(el('span', dr.severity || '—', 'chip sev-chip sev-' + (SEVERITIES.includes(dr.severity) ? dr.severity : 'none')), el('span', dr.title || 'untitled'));
|
|
570
|
+
art.append(h);
|
|
571
|
+
if (dr.same_title) {
|
|
572
|
+
const url = FF.safeUrl(dr.same_title), p = el('p', undefined, 'fnd-same');
|
|
573
|
+
p.append(el('i', undefined, 'lamp fnd-amber'), el('span', 'An open issue with this title exists already: '));
|
|
574
|
+
if (url) { const a = el('a', url); a.href = url; a.target = '_blank'; a.rel = 'noopener noreferrer'; p.append(a); } else p.append(el('span', String(dr.same_title)));
|
|
575
|
+
p.append(el('span', '. forge skips it.')); art.append(p);
|
|
576
|
+
}
|
|
577
|
+
art.append(el('pre', dr.body || '', 'fnd-body')); dlg.append(art);
|
|
578
|
+
}
|
|
579
|
+
const labels = el('input'); labels.type = 'text'; labels.placeholder = 'bug, forge (optional, comma separated)';
|
|
580
|
+
const labelNote = el('p', undefined, 'warn fnd-label-note'); labelNote.hidden = true;
|
|
581
|
+
const results = el('div', undefined, 'fnd-results');
|
|
582
|
+
const go = el('button', 'File on GitHub', 'primary'), cancel = el('button', 'Cancel'); go.type = 'button'; cancel.type = 'button';
|
|
583
|
+
go.disabled = !drafts.length;
|
|
584
|
+
cancel.addEventListener('click', shut);
|
|
585
|
+
go.addEventListener('click', async () => {
|
|
586
|
+
const parsed = FF.parseLabels(labels.value);
|
|
587
|
+
labelNote.hidden = !parsed.error; labelNote.textContent = parsed.error || '';
|
|
588
|
+
if (parsed.error) return;
|
|
589
|
+
go.disabled = true; cancel.disabled = true; labels.disabled = true; results.replaceChildren(); posting = true;
|
|
590
|
+
const res = await UI.post(FF.issuesPath(key), FF.fileBody('repo', fps, true, parsed.labels));
|
|
591
|
+
posting = false;
|
|
592
|
+
if (!res || !res.ok) { go.disabled = false; cancel.disabled = false; labels.disabled = false; UI.outcome(results, res); return; }
|
|
593
|
+
const made = FF.resultLines(res.data.created), ul = el('ul', undefined, 'fnd-created');
|
|
594
|
+
for (const ln of made) {
|
|
595
|
+
const li = el('li', undefined, 'fnd-created-' + ln.kind), url = FF.safeUrl(ln.url);
|
|
596
|
+
li.append(el('i', undefined, 'lamp ' + (ln.kind === 'created' ? 'st-pass' : 'fnd-amber')));
|
|
597
|
+
if (url) { const a = el('a', ln.text); a.href = url; a.target = '_blank'; a.rel = 'noopener noreferrer'; li.append(a); } else li.append(el('span', ln.text));
|
|
598
|
+
ul.append(li);
|
|
599
|
+
}
|
|
600
|
+
results.replaceChildren(el('p', `${made.filter(l => l.kind === 'created').length} created`, 'fnd-done'), ul);
|
|
601
|
+
for (const n of FF.emptyNotes(res.data.created, res.data.notes)) results.append(el('p', n, 'muted fnd-result-note'));
|
|
602
|
+
go.remove(); cancel.textContent = 'Close'; cancel.disabled = false;
|
|
603
|
+
for (const r of list(s.findings && s.findings.rows)) if (fps.includes(r.record_fp)) s.fsel.delete(r.record_fp);
|
|
604
|
+
if (s.tab === 'findings') loadTab(true);
|
|
605
|
+
});
|
|
606
|
+
const actions = el('div', undefined, 'fnd-dialog-actions'); actions.append(cancel, go);
|
|
607
|
+
const labelField = el('label', undefined, 'fnd-field'); labelField.append(el('span', 'Labels', 'plate'), labels);
|
|
608
|
+
dlg.append(labelField, labelNote, results, actions);
|
|
609
|
+
if (typeof dlg.showModal === 'function') dlg.showModal(); else dlg.setAttribute('open', '');
|
|
610
|
+
(drafts.length ? go : cancel).focus();
|
|
611
|
+
}
|
|
612
|
+
|
|
613
|
+
if (s.writes) {
|
|
614
|
+
const abar = el('div', undefined, 'fnd-actions prj-actions');
|
|
615
|
+
const lab = el('label', undefined, 'fnd-toggle');
|
|
616
|
+
allBox = el('input'); allBox.type = 'checkbox'; allBox.setAttribute('aria-label', 'Select all shown findings');
|
|
617
|
+
lab.append(allBox, el('span', 'Select all'));
|
|
618
|
+
picked = el('span', '0 selected', 'muted fnd-picked');
|
|
619
|
+
allBox.addEventListener('change', () => {
|
|
620
|
+
for (const r of shownNow()) { if (!A.selectable(r)) continue; if (allBox.checked) s.fsel.add(r.record_fp); else s.fsel.delete(r.record_fp); }
|
|
621
|
+
drawTable();
|
|
622
|
+
});
|
|
623
|
+
abar.append(lab, picked);
|
|
624
|
+
for (const [op, text] of [['fix', 'Mark fixed'], ['dismiss', 'Dismiss'], ['reopen', 'Reopen'], ['to-file', 'Mark to file'], ['dup', 'Duplicate of…'], ['tag', 'Tags…']]) {
|
|
625
|
+
const b = el('button', text); b.type = 'button'; b.dataset.op = op; b.disabled = true;
|
|
626
|
+
b.addEventListener('click', () => openForm(op)); opButtons[op] = b; abar.append(b);
|
|
627
|
+
}
|
|
628
|
+
const fileKey = el('button', 'File selected', 'primary'); fileKey.type = 'button'; fileKey.dataset.op = 'file'; fileKey.disabled = true;
|
|
629
|
+
fileKey.title = 'creates GitHub issues for the selected findings that forge issues can file (at most ' + A.MAX_FILE + ')';
|
|
630
|
+
fileKey.addEventListener('click', () => { fileSelected(); }); opButtons.file = fileKey; abar.append(fileKey);
|
|
631
|
+
body.replaceChildren(triageHost, bar, abar, formHost, actHost, noteHost, count, tableHost);
|
|
632
|
+
} else body.replaceChildren(triageHost, bar, count, tableHost);
|
|
633
|
+
|
|
634
|
+
/* the table */
|
|
206
635
|
const summaryCell = r => {
|
|
207
636
|
const wrap = el('div', undefined, 'fnd-summary'), line = el('div', undefined, 'fnd-summary-line');
|
|
208
637
|
const more = el('button', undefined, 'fnd-more'); more.type = 'button'; more.setAttribute('aria-expanded', 'false'); more.setAttribute('aria-label', 'Show the full text');
|
|
209
638
|
more.append(el('span', '▸', 'fnd-caret'));
|
|
210
639
|
const detail = el('div', undefined, 'fnd-detail'); detail.hidden = true;
|
|
211
640
|
detail.append(el('pre', r.text || r.summary || '', 'fnd-text'));
|
|
641
|
+
const rec = r.record || {};
|
|
642
|
+
for (const [k, label] of [['reason', 'reason'], ['commit', 'fixed by'], ['duplicate_of', 'duplicate of'], ['issue', 'issue'], ['note', 'note']]) {
|
|
643
|
+
if (rec[k] != null && String(rec[k]) !== '') detail.append(el('p', `${label}: ${rec[k]}`, 'fnd-rec'));
|
|
644
|
+
}
|
|
212
645
|
if (list(r.occurrences).length > 1) {
|
|
213
646
|
const ul = el('ul', undefined, 'prj-occ');
|
|
214
647
|
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
648
|
detail.append(el('p', `Seen ${r.count} times, the newest first in the row:`, 'muted'), ul);
|
|
216
649
|
}
|
|
650
|
+
if (!s.writes) {
|
|
651
|
+
const cmds = A.commandsFor(s.detail && s.detail.root, r), cbox = el('div', undefined, 'fnd-cmds');
|
|
652
|
+
if (!cmds.length) cbox.append(el('p', 'This finding has no record key, so forge cannot change it.', 'muted'));
|
|
653
|
+
else {
|
|
654
|
+
cbox.append(el('p', 'This page is read-only. Change this finding from a terminal:', 'muted'));
|
|
655
|
+
for (const c of cmds) { const rowEl = el('div', undefined, 'fnd-cmd'), code = el('code', c.command, 'mono'); code.tabIndex = 0; code.title = c.label; rowEl.append(code, copyButton(c.command)); cbox.append(rowEl); }
|
|
656
|
+
}
|
|
657
|
+
detail.append(cbox);
|
|
658
|
+
}
|
|
217
659
|
more.addEventListener('click', () => { const open = detail.hidden; detail.hidden = !open; more.setAttribute('aria-expanded', String(open)); more.firstChild.textContent = open ? '▾' : '▸'; });
|
|
218
660
|
line.append(more, el('span', cleanSummary(r.summary, r.location) || '—', 'prj-summary'));
|
|
219
661
|
if (r.count > 1) line.append(el('span', `×${r.count}`, 'chip prj-count-chip'));
|
|
220
|
-
wrap.append(line
|
|
662
|
+
wrap.append(line);
|
|
663
|
+
if (list(r.tags).length) {
|
|
664
|
+
const chips = el('div', undefined, 'fnd-tags'), derived = A.derivedTags(r);
|
|
665
|
+
for (const t of r.tags) {
|
|
666
|
+
const c = el('span', t, 'fnd-tag' + (derived ? ' fnd-tag-derived' : '')); if (derived) c.title = 'derived from the path';
|
|
667
|
+
chips.append(c);
|
|
668
|
+
}
|
|
669
|
+
wrap.append(chips);
|
|
670
|
+
}
|
|
671
|
+
wrap.append(detail); return wrap;
|
|
221
672
|
};
|
|
222
673
|
const statusCell = r => {
|
|
223
674
|
const b = el('span', undefined, 'fnd-status fnd-' + r.status);
|
|
224
|
-
b.append(el('i', undefined, 'lamp
|
|
675
|
+
b.append(el('i', undefined, 'lamp fnd-lamp-' + r.status + ' ' + (LAMPS[r.status] || 'lamp-off')), el('span', r.status));
|
|
225
676
|
if (r.status === 'superseded') b.title = 'a later review of the same task passed; that does not say this finding was fixed';
|
|
677
|
+
else if (r.status === 'to-file') b.title = 'marked to file as a GitHub issue: still open work';
|
|
678
|
+
else if (r.status === 'unlabelled') b.title = 'the finding has no usable label, so forge cannot say what it is';
|
|
226
679
|
return b;
|
|
227
680
|
};
|
|
228
681
|
const whereCell = r => {
|
|
229
682
|
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
683
|
const box = el('span', undefined, 'prj-where');
|
|
231
684
|
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 (
|
|
685
|
+
if (s.writes && A.selectable(r)) {
|
|
686
|
+
for (const op of ['note', 'edit']) {
|
|
687
|
+
const b = el('button', op === 'note' ? 'Note' : 'Edit', 'fnd-rowbtn'); b.type = 'button'; b.dataset.op = op; b.title = op === 'note' ? 'add or change a note' : 'change the severity or the text';
|
|
688
|
+
b.addEventListener('click', () => openForm(op, r)); box.append(document.createTextNode(' '), b);
|
|
689
|
+
}
|
|
690
|
+
}
|
|
233
691
|
return box;
|
|
234
692
|
};
|
|
235
693
|
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; };
|
|
@@ -246,9 +704,21 @@
|
|
|
246
704
|
{ id: 'status', label: 'Status', value: r => STATUSES.indexOf(r.status), cell: statusCell },
|
|
247
705
|
{ id: 'open', label: 'Open', sortable: false, cell: whereCell },
|
|
248
706
|
];
|
|
707
|
+
if (s.writes) columns.unshift({ id: 'pick', label: '', title: 'Select', sortable: false, hideable: false, cell: r => {
|
|
708
|
+
if (!A.selectable(r)) { const n = el('span', '—', 'muted'); n.title = 'this finding has no record key: forge cannot change it'; return n; }
|
|
709
|
+
const cb = el('input'); cb.type = 'checkbox'; cb.checked = s.fsel.has(r.record_fp); cb.setAttribute('aria-label', 'Select finding ' + r.record_fp);
|
|
710
|
+
cb.addEventListener('change', () => { if (cb.checked) s.fsel.add(r.record_fp); else s.fsel.delete(r.record_fp); syncBar(); });
|
|
711
|
+
return cb;
|
|
712
|
+
} });
|
|
249
713
|
function drawTable() {
|
|
250
|
-
const shown =
|
|
714
|
+
const shown = shownNow();
|
|
251
715
|
count.textContent = `${shown.length} of ${rows.length} findings`;
|
|
716
|
+
if (s.ffilter.fp) {
|
|
717
|
+
const all = el('button', 'Show all findings'); all.type = 'button'; all.dataset.op = 'clear-fp';
|
|
718
|
+
all.addEventListener('click', () => { s.ffilter = { severity: 'all', status: 'open', tag: '', run: '', reviewer: '', path: '', since: 0, shadow: false, fp: '' }; drawFindings(body, note); });
|
|
719
|
+
count.append(document.createTextNode(` · only ${s.ffilter.fp} `), all);
|
|
720
|
+
}
|
|
721
|
+
syncBar();
|
|
252
722
|
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
723
|
table(tableHost, 'project-findings', 'Findings', columns, shown, { className: 'fnd-grid prj-findings' });
|
|
254
724
|
}
|
|
@@ -257,6 +727,7 @@
|
|
|
257
727
|
|
|
258
728
|
/* Memories */
|
|
259
729
|
function drawMemories(body, note) {
|
|
730
|
+
abandonForget();
|
|
260
731
|
const d = s.memories;
|
|
261
732
|
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
733
|
fill(note, d.notes);
|
|
@@ -266,13 +737,198 @@
|
|
|
266
737
|
if (sources.length > 1) {
|
|
267
738
|
const l = el('label', undefined, 'fnd-field'), sel = el('select'); sel.dataset.filter = 'source';
|
|
268
739
|
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); });
|
|
740
|
+
sel.value = s.source || ''; sel.addEventListener('change', () => { s.source = sel.value; s.picked = new Set(); s.forgetNote = null; drawMemories(body, note); });
|
|
270
741
|
l.append(el('span', 'Checkout', 'plate'), sel); bar.append(l);
|
|
271
742
|
}
|
|
272
743
|
bar.append(readAgain(() => loadTab(true)));
|
|
273
744
|
const parts = [bar];
|
|
745
|
+
const learnings = list(d.learnings);
|
|
746
|
+
const shownNow = () => filterLearnings(learnings, s.mfilter, s.source);
|
|
747
|
+
let allBox = null, forget = null, addButton = null, saveEdit = null, editButtons = [];
|
|
748
|
+
const faction = el('div'), noteHost = el('div'); faction.append(noteHost);
|
|
749
|
+
s.forgetHost = faction;
|
|
750
|
+
const editHost = el('div', undefined, 'prj-edit');
|
|
751
|
+
const lcount = el('p', '', 'muted prj-count'), lhost = el('div', undefined, 'prj-table');
|
|
752
|
+
const checkoutOf = () => s.source || (s.detail && s.detail.root) || '';
|
|
753
|
+
const writeCheckouts = () => s.source ? [s.source] : list(d.sources).map(item => item && item.path).filter(Boolean);
|
|
754
|
+
const whereText = targets => targets.length ? targets.join(', ') : 'every checkout of this project';
|
|
755
|
+
function commandLine(command) {
|
|
756
|
+
const rowEl = el('div', undefined, 'fnd-cmd'), code = el('code', command, 'mono');
|
|
757
|
+
code.tabIndex = 0; rowEl.append(code, copyButton(command)); return rowEl;
|
|
758
|
+
}
|
|
759
|
+
function terminalBox(intro, commands) {
|
|
760
|
+
const box = el('div', undefined, 'fnd-cmds');
|
|
761
|
+
box.append(el('p', intro, 'muted'));
|
|
762
|
+
for (const command of commands) box.append(commandLine(command));
|
|
763
|
+
return box;
|
|
764
|
+
}
|
|
765
|
+
function paintNote() { noteHost.replaceChildren(...list(s.forgetNote).map(line => el('p', line, 'muted'))); }
|
|
766
|
+
// Forget, Edit and Add share s.forgetting, so one confirm is the only write in flight.
|
|
767
|
+
function syncForget() {
|
|
768
|
+
const busy = s.forgetting;
|
|
769
|
+
if (forget) {
|
|
770
|
+
const keys = forgetKeys(shownNow(), s.picked);
|
|
771
|
+
forget.textContent = `Forget selected (${keys.length})`;
|
|
772
|
+
forget.disabled = busy || keys.length === 0;
|
|
773
|
+
if (allBox) {
|
|
774
|
+
const selectable = shownNow().map(learningKey).filter(Boolean);
|
|
775
|
+
allBox.checked = selectable.length > 0 && selectable.every(key => s.picked.has(key));
|
|
776
|
+
allBox.disabled = busy || selectable.length === 0;
|
|
777
|
+
}
|
|
778
|
+
}
|
|
779
|
+
if (addButton) addButton.disabled = busy;
|
|
780
|
+
if (saveEdit) saveEdit.disabled = busy;
|
|
781
|
+
for (const b of editButtons) b.disabled = busy || !b.dataset.key;
|
|
782
|
+
}
|
|
783
|
+
function memoryResultLines(op, res) {
|
|
784
|
+
const data = forgetData(res), verb = op === 'add' ? 'added' : 'edited';
|
|
785
|
+
if (!data) return [verb];
|
|
786
|
+
const lines = [];
|
|
787
|
+
for (const checkout of list(data.checkouts)) {
|
|
788
|
+
const where = checkout && checkout.path ? String(checkout.path) : 'checkout';
|
|
789
|
+
const result = checkout && checkout.result;
|
|
790
|
+
if (!result || result.ok === false) {
|
|
791
|
+
const err = checkout && checkout.error;
|
|
792
|
+
const why = typeof err === 'string' ? err : err && (err.detail || err.error);
|
|
793
|
+
lines.push(where + ': ' + (why || 'failed'));
|
|
794
|
+
continue;
|
|
795
|
+
}
|
|
796
|
+
lines.push(where + ': ' + verb + (result.key ? ' ' + result.key : ''));
|
|
797
|
+
}
|
|
798
|
+
return lines.length ? lines : [verb];
|
|
799
|
+
}
|
|
800
|
+
function memoryFailLine(op, res) {
|
|
801
|
+
return (op === 'add' ? 'Could not add: ' : 'Could not edit: ') + ((res && (res.detail || res.error)) || 'no answer');
|
|
802
|
+
}
|
|
803
|
+
// Same epoch guard as forgetSelected: a redraw retires this attempt, the new controls stay usable,
|
|
804
|
+
// and a request already sent keeps its result line.
|
|
805
|
+
async function commitMemory(op, request, sentence) {
|
|
806
|
+
if (s.forgetting) return;
|
|
807
|
+
const epoch = s.forgetEpoch, host = faction;
|
|
808
|
+
const current = () => epoch === s.forgetEpoch && host.isConnected;
|
|
809
|
+
s.forgetting = true; s.forgetNote = null; syncForget(); paintNote();
|
|
810
|
+
for (const child of [...host.children]) if (child !== noteHost) child.remove();
|
|
811
|
+
try {
|
|
812
|
+
const yes = await UI.confirmInline(host, sentence, {});
|
|
813
|
+
if (!current() || !yes) return;
|
|
814
|
+
const res = await UI.post('/api/projects/' + encodeURIComponent(s.id) + '/memories/' + op, request);
|
|
815
|
+
if (!current()) {
|
|
816
|
+
s.forgetNote = res && res.ok ? memoryResultLines(op, res) : [memoryFailLine(op, res)];
|
|
817
|
+
if (s.tab === 'memories') await loadTab(true);
|
|
818
|
+
return;
|
|
819
|
+
}
|
|
820
|
+
if (!res || !res.ok) { UI.outcome(host, res); return; }
|
|
821
|
+
s.forgetNote = memoryResultLines(op, res);
|
|
822
|
+
s.forgetting = false;
|
|
823
|
+
await loadTab(true);
|
|
824
|
+
} finally {
|
|
825
|
+
if (epoch !== s.forgetEpoch) return;
|
|
826
|
+
s.forgetting = false;
|
|
827
|
+
if (host.isConnected) syncForget();
|
|
828
|
+
}
|
|
829
|
+
}
|
|
830
|
+
function countedField(label, value, field) {
|
|
831
|
+
const input = el('input'); input.type = 'text'; input.value = value || ''; input.dataset.field = field;
|
|
832
|
+
input.setAttribute('aria-label', label);
|
|
833
|
+
const count = el('span', '', 'muted'); count.dataset.field = field + '-count';
|
|
834
|
+
const sync = () => {
|
|
835
|
+
const n = String(input.value || '').length;
|
|
836
|
+
count.textContent = n + '/300';
|
|
837
|
+
count.className = n > MEMORY_TEXT_MAX ? 'warn' : 'muted';
|
|
838
|
+
};
|
|
839
|
+
input.addEventListener('input', sync); sync();
|
|
840
|
+
const wrap = el('label', undefined, 'fnd-field');
|
|
841
|
+
wrap.append(el('span', label, 'plate'), input, count);
|
|
842
|
+
return { wrap, input };
|
|
843
|
+
}
|
|
844
|
+
function addConfirm(body, targets) {
|
|
845
|
+
const lines = ['Add this learning to ' + whereText(targets) + '?', body.category + ': ' + body.text];
|
|
846
|
+
if (body.paths && body.paths.length) lines.push('paths: ' + body.paths.join(', '));
|
|
847
|
+
return lines.join('\n');
|
|
848
|
+
}
|
|
849
|
+
function editConfirm(key, before, after, targets) {
|
|
850
|
+
return 'Change ' + key + ' in ' + whereText(targets) + '?\n' + before + ' → ' + after;
|
|
851
|
+
}
|
|
852
|
+
function buildAddForm() {
|
|
853
|
+
const form = el('div', undefined, 'prj-add');
|
|
854
|
+
form.append(el('h3', 'Add learning'));
|
|
855
|
+
const cat = el('select'); cat.dataset.field = 'add-category'; cat.setAttribute('aria-label', 'Category');
|
|
856
|
+
for (const name of MEMORY_CATEGORIES) { const o = el('option', name); o.value = name; cat.append(o); }
|
|
857
|
+
cat.value = 'verify';
|
|
858
|
+
const catLabel = el('label', undefined, 'fnd-field'); catLabel.append(el('span', 'Category', 'plate'), cat);
|
|
859
|
+
const text = countedField('Text', '', 'add-text');
|
|
860
|
+
const paths = el('input'); paths.type = 'text'; paths.placeholder = 'optional paths, comma separated';
|
|
861
|
+
paths.dataset.field = 'add-paths'; paths.setAttribute('aria-label', 'Paths');
|
|
862
|
+
const pathsLabel = el('label', undefined, 'fnd-field'); pathsLabel.append(el('span', 'Paths', 'plate'), paths);
|
|
863
|
+
const msg = el('p', '', 'warn');
|
|
864
|
+
addButton = el('button', 'Add learning', 'primary'); addButton.type = 'button';
|
|
865
|
+
const submit = () => {
|
|
866
|
+
if (s.forgetting) return;
|
|
867
|
+
const built = memoryAddBody({ category: cat.value, text: text.input.value, paths: paths.value, path: s.source || undefined });
|
|
868
|
+
if (built.error) { msg.textContent = built.error; return; }
|
|
869
|
+
msg.textContent = '';
|
|
870
|
+
commitMemory('add', built.body, addConfirm(built.body, writeCheckouts()));
|
|
871
|
+
};
|
|
872
|
+
addButton.addEventListener('click', submit);
|
|
873
|
+
const onEnter = e => { if (e.key === 'Enter') { e.preventDefault(); submit(); } };
|
|
874
|
+
text.input.addEventListener('keydown', onEnter);
|
|
875
|
+
paths.addEventListener('keydown', onEnter);
|
|
876
|
+
form.append(catLabel, text.wrap, pathsLabel, addButton, msg);
|
|
877
|
+
return form;
|
|
878
|
+
}
|
|
879
|
+
function openEdit(row) {
|
|
880
|
+
if (s.forgetting) return;
|
|
881
|
+
const key = learningKey(row);
|
|
882
|
+
if (!key) return;
|
|
883
|
+
const before = row.text == null ? '' : String(row.text);
|
|
884
|
+
editHost.replaceChildren();
|
|
885
|
+
const text = countedField('Text', before, 'edit-text');
|
|
886
|
+
const msg = el('p', '', 'warn');
|
|
887
|
+
saveEdit = el('button', 'Save', 'primary'); saveEdit.type = 'button';
|
|
888
|
+
const cancel = el('button', 'Cancel'); cancel.type = 'button'; cancel.setAttribute('aria-label', 'Cancel edit');
|
|
889
|
+
const close = () => { saveEdit = null; editHost.replaceChildren(); };
|
|
890
|
+
cancel.addEventListener('click', close);
|
|
891
|
+
const apply = () => {
|
|
892
|
+
if (s.forgetting) return;
|
|
893
|
+
const built = memoryEditBody(key, text.input.value);
|
|
894
|
+
if (built.error) { msg.textContent = built.error; return; }
|
|
895
|
+
if (s.source) built.body.path = s.source;
|
|
896
|
+
msg.textContent = '';
|
|
897
|
+
commitMemory('edit', built.body, editConfirm(key, before, built.body.text, writeCheckouts()));
|
|
898
|
+
};
|
|
899
|
+
saveEdit.addEventListener('click', apply);
|
|
900
|
+
text.input.addEventListener('keydown', e => {
|
|
901
|
+
if (e.key === 'Enter') { e.preventDefault(); apply(); }
|
|
902
|
+
else if (e.key === 'Escape') { e.preventDefault(); close(); }
|
|
903
|
+
});
|
|
904
|
+
editHost.append(el('p', 'Edit ' + key), text.wrap, saveEdit, cancel, msg);
|
|
905
|
+
if (text.input.focus) text.input.focus();
|
|
906
|
+
}
|
|
907
|
+
function rowCommands(r) {
|
|
908
|
+
const checkout = checkoutOf(), text = r.text == null ? '' : String(r.text), commands = [];
|
|
909
|
+
const key = learningKey(r);
|
|
910
|
+
if (key) commands.push(memoryCommand('edit', checkout, { key, text }));
|
|
911
|
+
if (MEMORY_CATEGORIES.includes(r.category)) commands.push(memoryCommand('add', checkout, { category: r.category, text }));
|
|
912
|
+
return commands.length ? terminalBox('This page is read-only. From a terminal:', commands) : null;
|
|
913
|
+
}
|
|
914
|
+
function learningCell(r) {
|
|
915
|
+
const box = el('div', undefined, 'prj-learning'), line = el('div');
|
|
916
|
+
line.append(el('span', r.text == null ? '' : String(r.text)));
|
|
917
|
+
if (learningManual(r)) { line.append(document.createTextNode(' '), el('span', 'added by a person', 'chip prj-manual')); }
|
|
918
|
+
box.append(line);
|
|
919
|
+
if (!s.writes) { const commands = rowCommands(r); if (commands) box.append(commands); }
|
|
920
|
+
return box;
|
|
921
|
+
}
|
|
274
922
|
const empty = memoryEmpty(d);
|
|
275
|
-
if (empty) {
|
|
923
|
+
if (empty) {
|
|
924
|
+
parts.push(el('p', empty, 'muted prj-empty'));
|
|
925
|
+
paintNote();
|
|
926
|
+
if (s.writes) parts.push(buildAddForm());
|
|
927
|
+
else parts.push(terminalBox('This page is read-only. Add a learning from a terminal:', [memoryCommand('add', checkoutOf(), {})]));
|
|
928
|
+
parts.push(faction);
|
|
929
|
+
body.replaceChildren(...parts);
|
|
930
|
+
return;
|
|
931
|
+
}
|
|
276
932
|
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
933
|
const src = sources.find(x => x.path === s.source);
|
|
278
934
|
const given = el('section', undefined, 'prj-given');
|
|
@@ -295,17 +951,77 @@
|
|
|
295
951
|
lsel('state', 'State', [['all', 'all']].concat(Object.entries(STATES).map(([k, v]) => [k, v])));
|
|
296
952
|
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
953
|
tx.addEventListener('input', () => { s.mfilter.text = tx.value; drawLearnings(); }); tl.append(el('span', 'Text', 'plate'), tx); lbar.append(tl);
|
|
298
|
-
|
|
299
|
-
|
|
954
|
+
if (s.writes) {
|
|
955
|
+
const lab = el('label', undefined, 'fnd-toggle');
|
|
956
|
+
allBox = el('input'); allBox.type = 'checkbox'; allBox.setAttribute('aria-label', 'Select all shown learnings');
|
|
957
|
+
lab.append(allBox, el('span', 'Select all'));
|
|
958
|
+
forget = el('button', 'Forget selected (0)', 'ui-danger'); forget.type = 'button';
|
|
959
|
+
forget.addEventListener('click', () => { forgetSelected(); });
|
|
960
|
+
allBox.addEventListener('change', () => {
|
|
961
|
+
const shown = shownNow();
|
|
962
|
+
for (const row of shown) {
|
|
963
|
+
const key = learningKey(row);
|
|
964
|
+
if (!key) continue;
|
|
965
|
+
if (allBox.checked) s.picked.add(key); else s.picked.delete(key);
|
|
966
|
+
}
|
|
967
|
+
drawLearnings();
|
|
968
|
+
});
|
|
969
|
+
lbar.append(lab, forget);
|
|
970
|
+
all.append(lbar, buildAddForm(), editHost, faction, lcount, lhost);
|
|
971
|
+
} else all.append(lbar, faction, lcount, lhost);
|
|
972
|
+
parts.push(all);
|
|
300
973
|
body.replaceChildren(...parts);
|
|
301
|
-
|
|
974
|
+
async function forgetSelected() {
|
|
975
|
+
if (s.forgetting) return;
|
|
976
|
+
const keys = forgetKeys(shownNow(), s.picked);
|
|
977
|
+
if (!keys.length) return;
|
|
978
|
+
const epoch = s.forgetEpoch;
|
|
979
|
+
const host = faction;
|
|
980
|
+
const current = () => epoch === s.forgetEpoch && host.isConnected;
|
|
981
|
+
s.forgetting = true; s.forgetNote = null; syncForget(); paintNote();
|
|
982
|
+
for (const child of [...host.children]) if (child !== noteHost) child.remove();
|
|
983
|
+
const path = '/api/projects/' + encodeURIComponent(s.id) + '/memories/forget';
|
|
984
|
+
const base = { keys }; if (s.source) base.path = s.source;
|
|
985
|
+
try {
|
|
986
|
+
// Dry run first. Nothing is forgotten until the confirm, and a cancel sends nothing more.
|
|
987
|
+
const preview = await UI.post(path, { ...base, dry_run: true });
|
|
988
|
+
if (!current()) return;
|
|
989
|
+
if (!preview || !preview.ok || (preview.data && preview.data.ok === false)) {
|
|
990
|
+
UI.outcome(host, preview && preview.ok ? { ok: false, status: preview.status || 500, error: 'failed', detail: 'Could not preview what would be forgotten' } : preview);
|
|
991
|
+
return;
|
|
992
|
+
}
|
|
993
|
+
const yes = await UI.confirmInline(host, forgetConfirmText(learnings, keys, preview), { danger: true });
|
|
994
|
+
if (!current() || !yes) return;
|
|
995
|
+
const res = await UI.post(path, { ...base, dry_run: false });
|
|
996
|
+
// Once sent, the forget happened whatever the screen did meanwhile (Read again, another checkout,
|
|
997
|
+
// another tab): its result line is kept for the next draw rather than dropped with this strip.
|
|
998
|
+
if (!current()) {
|
|
999
|
+
s.forgetNote = res && res.ok ? forgetResultLines(res)
|
|
1000
|
+
: ['Could not forget: ' + ((res && (res.detail || res.error)) || 'no answer')];
|
|
1001
|
+
if (res && res.ok) for (const key of keys) s.picked.delete(key);
|
|
1002
|
+
if (s.tab === 'memories') await loadTab(true);
|
|
1003
|
+
return;
|
|
1004
|
+
}
|
|
1005
|
+
if (!res || !res.ok) { UI.outcome(host, res); return; }
|
|
1006
|
+
s.forgetNote = forgetResultLines(res);
|
|
1007
|
+
for (const key of keys) s.picked.delete(key);
|
|
1008
|
+
s.forgetting = false;
|
|
1009
|
+
await loadTab(true);
|
|
1010
|
+
} finally {
|
|
1011
|
+
if (epoch !== s.forgetEpoch) return;
|
|
1012
|
+
s.forgetting = false;
|
|
1013
|
+
if (host.isConnected) syncForget();
|
|
1014
|
+
}
|
|
1015
|
+
}
|
|
302
1016
|
function drawLearnings() {
|
|
303
|
-
const shown =
|
|
1017
|
+
const shown = shownNow();
|
|
304
1018
|
lcount.textContent = `${shown.length} of ${learnings.length} learnings`;
|
|
305
|
-
|
|
306
|
-
|
|
1019
|
+
paintNote();
|
|
1020
|
+
editButtons = [];
|
|
1021
|
+
if (!shown.length) { lhost.replaceChildren(el('p', 'No learnings match these filters.', 'muted')); syncForget(); return; }
|
|
1022
|
+
const columns = [
|
|
307
1023
|
{ id: 'category', label: 'Category', value: r => r.category, cell: r => r.category },
|
|
308
|
-
{ id: 'text', label: 'Learning', value: r => r.text, cell: r =>
|
|
1024
|
+
{ id: 'text', label: 'Learning', value: r => r.text, cell: r => learningCell(r) },
|
|
309
1025
|
{ 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
1026
|
{ id: 'count', label: 'Runs', title: 'distinct runs that emitted it', value: r => r.count, cell: r => String(r.count || '—') },
|
|
311
1027
|
{ 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 || '—' },
|
|
@@ -314,7 +1030,20 @@
|
|
|
314
1030
|
{ id: 'model', label: 'Model', value: r => (list(r.rows).slice(-1)[0] || {}).model, cell: r => (list(r.rows).slice(-1)[0] || {}).model || '—' },
|
|
315
1031
|
{ 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
1032
|
{ id: 'last', label: 'Last seen', value: r => r.last, cell: r => r.last || '—' },
|
|
317
|
-
]
|
|
1033
|
+
];
|
|
1034
|
+
if (s.writes) columns.unshift({ id: 'pick', label: '', title: 'Select', sortable: false, hideable: false, cell: r => {
|
|
1035
|
+
const key = learningKey(r), box = el('input'); box.type = 'checkbox'; box.checked = !!(key && s.picked.has(key));
|
|
1036
|
+
box.disabled = s.forgetting || !key; box.setAttribute('aria-label', 'Select ' + (key || 'learning'));
|
|
1037
|
+
box.addEventListener('change', () => { if (!key) return; if (box.checked) s.picked.add(key); else s.picked.delete(key); syncForget(); });
|
|
1038
|
+
return box;
|
|
1039
|
+
} });
|
|
1040
|
+
if (s.writes) columns.push({ id: 'edit', label: '', title: 'Edit', sortable: false, hideable: false, cell: r => {
|
|
1041
|
+
const key = learningKey(r), b = el('button', 'Edit'); b.type = 'button'; b.dataset.key = key;
|
|
1042
|
+
b.disabled = s.forgetting || !key; b.setAttribute('aria-label', 'Edit ' + (key || 'learning'));
|
|
1043
|
+
b.addEventListener('click', () => openEdit(r)); editButtons.push(b); return b;
|
|
1044
|
+
} });
|
|
1045
|
+
table(lhost, 'project-learnings', 'Learnings', columns, shown);
|
|
1046
|
+
syncForget();
|
|
318
1047
|
}
|
|
319
1048
|
drawLearnings();
|
|
320
1049
|
}
|
|
@@ -346,7 +1075,12 @@
|
|
|
346
1075
|
if (s.id) { redraw = drawProject(); redraw(); loadDetail().then(() => { if (s.tab !== 'runs') loadTab(false); }); }
|
|
347
1076
|
else { redraw = drawList(); redraw(); loadList(); }
|
|
348
1077
|
}
|
|
349
|
-
UI.controlsEnabled().then(on => {
|
|
1078
|
+
UI.controlsEnabled().then(on => {
|
|
1079
|
+
const next = !!on;
|
|
1080
|
+
if (s.writes === next) return;
|
|
1081
|
+
s.writes = next;
|
|
1082
|
+
if ((s.tab === 'findings' && s.findings) || (s.tab === 'memories' && s.memories)) redraw();
|
|
1083
|
+
});
|
|
350
1084
|
open();
|
|
351
1085
|
return {
|
|
352
1086
|
go(id, tab) {
|
|
@@ -354,7 +1088,7 @@
|
|
|
354
1088
|
if (id === s.id && t === s.tab) return; // the page's own refresh: nothing changed here
|
|
355
1089
|
const same = id === s.id;
|
|
356
1090
|
s.id = id || null; s.tab = t;
|
|
357
|
-
if (!same) { s.detail = s.findings = s.memories = null; s.source = null; s.checkout = ''; }
|
|
1091
|
+
if (!same) { s.detail = s.findings = s.memories = null; s.source = null; s.checkout = ''; s.picked = new Set(); s.forgetNote = null; s.fsel = new Set(); s.actResult = null; abandonTriage(); s.triage = {}; }
|
|
358
1092
|
if (same && s.id) { redraw = drawProject(); redraw(); if (t === 'runs') loadDetail(); else if (!(t === 'findings' ? s.findings : s.memories)) loadTab(false); }
|
|
359
1093
|
else open();
|
|
360
1094
|
},
|
|
@@ -368,5 +1102,5 @@
|
|
|
368
1102
|
};
|
|
369
1103
|
}
|
|
370
1104
|
|
|
371
|
-
return { render, cleanSummary, filterFindings, filterLearnings, stateFor, memoryEmpty, routeOf, STATUSES, STATES };
|
|
1105
|
+
return { render, cleanSummary, filterFindings, filterLearnings, stateFor, memoryEmpty, routeOf, forgetKeys, memoryAddBody, memoryEditBody, memoryCommand, STATUSES, STATES };
|
|
372
1106
|
});
|