@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
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
/* forge-ui brief questions (#135): a task's questions in the inspector,
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
/* forge-ui brief questions (#135) and proposals (#136): a task's questions in the inspector, the run's
|
|
2
|
+
open questions, and the proposals waiting on an answer. window.ForgeBrief, and a CommonJS module
|
|
3
|
+
under node:test. The pure helpers (openQuestions, orderQuestions, startLine, groupQuestions,
|
|
4
|
+
canPropose, affectedLabel) are tested in ui/tests/js/briefview.test.js. Question text, answers,
|
|
5
|
+
reasons and diffs are untrusted: they only ever enter the page as text.
|
|
5
6
|
Ordering is flagged (must answer) first, then by the projected start from projectSchedule. A task with no
|
|
6
7
|
finite start is last. Wave numbers are a preview and are never a sort key. */
|
|
7
8
|
(function (root, factory) {
|
|
@@ -14,10 +15,24 @@
|
|
|
14
15
|
|
|
15
16
|
const list = v => Array.isArray(v) ? v : [];
|
|
16
17
|
const num = v => typeof v === 'number' && Number.isFinite(v) ? v : null;
|
|
18
|
+
// A question with no group, drawn only when it shares the list with a group or with Plan.
|
|
19
|
+
// An all-loose list stays flat, so this title is not a heading there.
|
|
20
|
+
const LOOSE_TITLE = 'No group';
|
|
17
21
|
const notices = new Map(); // run\ntask\nqid → the late answer's stdout
|
|
22
|
+
const proposalNotices = new Map(); // run\npid → the apply/reject/propose stdout
|
|
23
|
+
|
|
24
|
+
function page() {
|
|
25
|
+
if (root && root.document) return root;
|
|
26
|
+
return globalThis;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function forgeUI() {
|
|
30
|
+
if (root && root.ForgeUI) return root.ForgeUI;
|
|
31
|
+
return globalThis.ForgeUI;
|
|
32
|
+
}
|
|
18
33
|
|
|
19
34
|
function el(tag, text, className) {
|
|
20
|
-
const node =
|
|
35
|
+
const node = page().document.createElement(tag);
|
|
21
36
|
if (text !== undefined) node.textContent = text === null || text === undefined ? '' : String(text);
|
|
22
37
|
if (className) node.className = className;
|
|
23
38
|
return node;
|
|
@@ -27,6 +42,10 @@
|
|
|
27
42
|
return String(run && run.key) + '\n' + String(task && task.id) + '\n' + String(question && question.id);
|
|
28
43
|
}
|
|
29
44
|
|
|
45
|
+
function proposalKey(runKey, pid) {
|
|
46
|
+
return String(runKey) + '\n' + String(pid);
|
|
47
|
+
}
|
|
48
|
+
|
|
30
49
|
// Open task questions, in task order. Parked questions are wider than the task and are not listed here.
|
|
31
50
|
function openQuestions(run) {
|
|
32
51
|
const items = [];
|
|
@@ -111,6 +130,90 @@
|
|
|
111
130
|
});
|
|
112
131
|
}
|
|
113
132
|
|
|
133
|
+
// Where one question sits. A plan question is under "Plan". A wave question uses only its own group
|
|
134
|
+
// (an empty one stays loose, not the task's group). Anything else uses the question's group, then the task's.
|
|
135
|
+
function bucketOf(item) {
|
|
136
|
+
const question = item && item.question;
|
|
137
|
+
const task = item && item.task;
|
|
138
|
+
const scope = question && question.scope;
|
|
139
|
+
if (scope === 'plan') return { kind: 'plan' };
|
|
140
|
+
if (scope === 'wave') {
|
|
141
|
+
const id = question && typeof question.group === 'string' ? question.group : '';
|
|
142
|
+
return id ? { kind: 'group', id } : { kind: 'loose' };
|
|
143
|
+
}
|
|
144
|
+
const fromQuestion = question && typeof question.group === 'string' && question.group ? question.group : '';
|
|
145
|
+
const fromTask = task && typeof task.group === 'string' && task.group ? task.group : '';
|
|
146
|
+
const id = fromQuestion || fromTask;
|
|
147
|
+
return id ? { kind: 'group', id } : { kind: 'loose' };
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
// Sections in run.groups order, then unknown group ids in the order they appear, then Plan, then loose.
|
|
151
|
+
// A group with no question in `items` is skipped. Order inside a section is the order of `items`.
|
|
152
|
+
// Loose questions (no group of their own, and not plan-scoped) carry LOOSE_TITLE so a mixed list
|
|
153
|
+
// does not file them under the previous group or under Plan.
|
|
154
|
+
function groupQuestions(items, groups) {
|
|
155
|
+
const catalog = new Map();
|
|
156
|
+
for (const group of list(groups)) {
|
|
157
|
+
if (group && typeof group.id === 'string' && group.id && !catalog.has(group.id)) catalog.set(group.id, group);
|
|
158
|
+
}
|
|
159
|
+
const byGroup = new Map();
|
|
160
|
+
const unknown = [];
|
|
161
|
+
const plan = [];
|
|
162
|
+
const loose = [];
|
|
163
|
+
for (const item of list(items)) {
|
|
164
|
+
const where = bucketOf(item);
|
|
165
|
+
if (where.kind === 'plan') { plan.push(item); continue; }
|
|
166
|
+
if (where.kind === 'loose') { loose.push(item); continue; }
|
|
167
|
+
if (!byGroup.has(where.id)) {
|
|
168
|
+
byGroup.set(where.id, []);
|
|
169
|
+
if (!catalog.has(where.id)) unknown.push(where.id);
|
|
170
|
+
}
|
|
171
|
+
byGroup.get(where.id).push(item);
|
|
172
|
+
}
|
|
173
|
+
const sections = [];
|
|
174
|
+
for (const group of list(groups)) {
|
|
175
|
+
if (!group || typeof group.id !== 'string' || !group.id) continue;
|
|
176
|
+
const rows = byGroup.get(group.id);
|
|
177
|
+
if (!rows || !rows.length) continue;
|
|
178
|
+
const title = typeof group.title === 'string' && group.title ? group.title : group.id;
|
|
179
|
+
const goal = typeof group.goal === 'string' ? group.goal : '';
|
|
180
|
+
sections.push({ kind: 'group', id: group.id, title, goal, items: rows });
|
|
181
|
+
byGroup.delete(group.id);
|
|
182
|
+
}
|
|
183
|
+
for (const id of unknown) {
|
|
184
|
+
const rows = byGroup.get(id);
|
|
185
|
+
if (rows && rows.length) sections.push({ kind: 'group', id, title: id, goal: '', items: rows });
|
|
186
|
+
}
|
|
187
|
+
if (plan.length) sections.push({ kind: 'plan', id: null, title: 'Plan', goal: '', items: plan });
|
|
188
|
+
if (loose.length) sections.push({ kind: 'loose', id: null, title: LOOSE_TITLE, goal: '', items: loose });
|
|
189
|
+
return sections;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
// The propose button is only on an answered wave or plan question. A task question has no scope.
|
|
193
|
+
function canPropose(question) {
|
|
194
|
+
if (!question || typeof question !== 'object') return false;
|
|
195
|
+
if (question.scope !== 'wave' && question.scope !== 'plan') return false;
|
|
196
|
+
return typeof question.answer === 'string' && question.answer.length > 0;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
// "affected by p3", or "flagged: already started" when the task had already started. Otherwise null.
|
|
200
|
+
function affectedLabel(task) {
|
|
201
|
+
const mark = task && task.affected;
|
|
202
|
+
if (!mark || typeof mark !== 'object') return null;
|
|
203
|
+
if (mark.flag_only === true) return 'flagged: already started';
|
|
204
|
+
if (typeof mark.pid === 'string' && mark.pid) return 'affected by ' + mark.pid;
|
|
205
|
+
return null;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
function affectedBadge(task) {
|
|
209
|
+
const label = affectedLabel(task);
|
|
210
|
+
if (!label) return null;
|
|
211
|
+
const node = el('span', label, 'tag brief-affected');
|
|
212
|
+
const reason = task.affected && typeof task.affected.reason === 'string' ? task.affected.reason : '';
|
|
213
|
+
if (reason) node.title = reason;
|
|
214
|
+
return node;
|
|
215
|
+
}
|
|
216
|
+
|
|
114
217
|
function flags(question) {
|
|
115
218
|
const row = el('div', undefined, 'brief-flags');
|
|
116
219
|
if (question && question.must_answer === true) row.append(el('span', 'must answer', 'tag'));
|
|
@@ -138,6 +241,35 @@
|
|
|
138
241
|
if (old) old.remove();
|
|
139
242
|
}
|
|
140
243
|
|
|
244
|
+
function setBusy(node, on) {
|
|
245
|
+
if (!node) return;
|
|
246
|
+
if (on) {
|
|
247
|
+
node.dataset.busy = '1';
|
|
248
|
+
node.setAttribute('aria-busy', 'true');
|
|
249
|
+
} else {
|
|
250
|
+
delete node.dataset.busy;
|
|
251
|
+
node.removeAttribute('aria-busy');
|
|
252
|
+
}
|
|
253
|
+
if (!node.querySelectorAll) return;
|
|
254
|
+
for (const item of node.querySelectorAll('button, textarea, input')) item.disabled = !!on;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
function outputOf(res) {
|
|
258
|
+
const data = res && res.data;
|
|
259
|
+
return data && typeof data.output === 'string' ? data.output : '';
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
async function postJson(path, body) {
|
|
263
|
+
const ui = forgeUI();
|
|
264
|
+
let res = { ok: false, error: 'unavailable', detail: 'this page cannot send' };
|
|
265
|
+
try {
|
|
266
|
+
if (ui && ui.post) res = await ui.post(path, body);
|
|
267
|
+
} catch (_) {
|
|
268
|
+
res = { ok: false, error: 'failed', detail: 'could not send' };
|
|
269
|
+
}
|
|
270
|
+
return res;
|
|
271
|
+
}
|
|
272
|
+
|
|
141
273
|
function answerBox(ctx, task, question) {
|
|
142
274
|
const run = ctx.run || {};
|
|
143
275
|
const box = el('div', undefined, 'brief-box');
|
|
@@ -165,7 +297,7 @@
|
|
|
165
297
|
async function sendAnswer(box, field, send, msgs, ctx, task, question) {
|
|
166
298
|
if (box.dataset.busy) return;
|
|
167
299
|
const answer = field.value.trim();
|
|
168
|
-
const ui =
|
|
300
|
+
const ui = forgeUI();
|
|
169
301
|
if (!answer) {
|
|
170
302
|
if (ui) ui.outcome(msgs, { ok: false, status: 400, error: 'invalid', detail: 'the answer is empty' });
|
|
171
303
|
return;
|
|
@@ -204,6 +336,38 @@
|
|
|
204
336
|
if (ui && ui.outcome) ui.outcome(msgs, res);
|
|
205
337
|
}
|
|
206
338
|
|
|
339
|
+
async function sendPropose(actions, ctx, task, question) {
|
|
340
|
+
if (actions.dataset.busy) return;
|
|
341
|
+
const run = (ctx && ctx.run) || {};
|
|
342
|
+
setBusy(actions, true);
|
|
343
|
+
const path = '/api/runs/' + encodeURIComponent(run.key) + '/proposals';
|
|
344
|
+
const res = await postJson(path, { task: task.id, qid: question.id });
|
|
345
|
+
if (!actions.isConnected) return;
|
|
346
|
+
const output = outputOf(res);
|
|
347
|
+
// Exit 0 stored a proposal. Exit 3 is also 409 when the run lock is busy, and when the CLI
|
|
348
|
+
// refuses without storing anything (a wave question with no group, a plan question the scope
|
|
349
|
+
// cannot act on, brief off): stdout is empty then. A refused proposal that was stored prints
|
|
350
|
+
// its pid. Only that, and exit 0, are a write the page should redraw. Anything else is an error.
|
|
351
|
+
const pid = /^p[0-9]{1,6}\b/.exec(String(output).trim());
|
|
352
|
+
const wrote = !!(res && (res.ok || (res.status === 409 && pid)));
|
|
353
|
+
if (pid) proposalNotices.set(proposalKey(run.key, pid[0]), output);
|
|
354
|
+
if (wrote && ctx && ctx.refresh) { ctx.refresh(); return; }
|
|
355
|
+
setBusy(actions, false);
|
|
356
|
+
const ui = forgeUI();
|
|
357
|
+
const msgs = actions.querySelector('.brief-msgs');
|
|
358
|
+
if (!wrote && ui && ui.outcome && msgs) ui.outcome(msgs, res);
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
function proposeActions(ctx, task, question) {
|
|
362
|
+
const actions = el('div', undefined, 'brief-actions');
|
|
363
|
+
const send = el('button', 'Propose a change', 'brief-propose');
|
|
364
|
+
send.type = 'button';
|
|
365
|
+
const msgs = el('div', undefined, 'brief-msgs');
|
|
366
|
+
send.addEventListener('click', () => sendPropose(actions, ctx, task, question));
|
|
367
|
+
actions.append(send, msgs);
|
|
368
|
+
return actions;
|
|
369
|
+
}
|
|
370
|
+
|
|
207
371
|
function questionCard(question, ctx, task, parked) {
|
|
208
372
|
const li = el('li', undefined, 'brief-q');
|
|
209
373
|
if (question.id) li.dataset.qid = String(question.id);
|
|
@@ -214,23 +378,48 @@
|
|
|
214
378
|
if (typeof question.default === 'string' && question.default) li.append(el('p', 'if unanswered: ' + question.default, 'brief-default muted'));
|
|
215
379
|
const marks = flags(question);
|
|
216
380
|
if (marks) li.append(marks);
|
|
217
|
-
if (
|
|
381
|
+
if (typeof question.answer === 'string' && question.answer) li.append(el('p', 'Answer: ' + question.answer, 'brief-got'));
|
|
218
382
|
if (parked && typeof question.scope === 'string' && question.scope) li.append(el('p', 'scope: ' + question.scope, 'brief-scope muted'));
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
}
|
|
383
|
+
const note = notices.get(noticeKey(ctx && ctx.run, task, question));
|
|
384
|
+
const box = answerBox(ctx, task, question);
|
|
385
|
+
if (note) li.append(noticeNode(note));
|
|
386
|
+
li.append(box);
|
|
387
|
+
if (canPropose(question)) li.append(proposeActions(ctx, task, question));
|
|
225
388
|
return li;
|
|
226
389
|
}
|
|
227
390
|
|
|
228
|
-
|
|
391
|
+
function sectionHead(section) {
|
|
392
|
+
const title = section && typeof section.title === 'string' ? section.title : '';
|
|
393
|
+
if (!title) return null;
|
|
394
|
+
const block = el('div', undefined, 'brief-group');
|
|
395
|
+
block.append(el('h4', title, 'brief-group-title'));
|
|
396
|
+
if (section.goal) block.append(el('p', section.goal, 'brief-goal'));
|
|
397
|
+
return block;
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
function questionList(items, ctx, task, parked) {
|
|
401
|
+
const ul = el('ul', undefined, 'brief-questions');
|
|
402
|
+
for (const item of items) ul.append(questionCard(item.question, ctx, task, parked));
|
|
403
|
+
return ul;
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
function appendQuestions(parent, questions, ctx, task, parked) {
|
|
407
|
+
const sections = groupQuestions(questions.map(question => ({ task, question })), (ctx.run || {}).groups);
|
|
408
|
+
const flat = sections.length === 1 && sections[0].kind === 'loose';
|
|
409
|
+
if (flat) { parent.append(questionList(sections[0].items, ctx, task, parked)); return; }
|
|
410
|
+
for (const section of sections) {
|
|
411
|
+
const heading = sectionHead(section);
|
|
412
|
+
if (heading) parent.append(heading);
|
|
413
|
+
parent.append(questionList(section.items, ctx, task, parked));
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
// Drop the answer boxes and the write buttons once the page knows it cannot write.
|
|
229
418
|
function settleControls(section) {
|
|
230
|
-
const ui =
|
|
419
|
+
const ui = forgeUI();
|
|
231
420
|
const drop = () => {
|
|
232
421
|
if (!section.isConnected) return;
|
|
233
|
-
for (const box of section.querySelectorAll('.brief-box')) box.remove();
|
|
422
|
+
for (const box of section.querySelectorAll('.brief-box, .brief-actions')) box.remove();
|
|
234
423
|
section.dataset.controls = 'off';
|
|
235
424
|
};
|
|
236
425
|
if (!ui || !ui.controlsEnabled) { drop(); return; }
|
|
@@ -241,7 +430,8 @@
|
|
|
241
430
|
});
|
|
242
431
|
}
|
|
243
432
|
|
|
244
|
-
// The inspector section. Nothing when this task has no brief. Parked questions stay collapsed
|
|
433
|
+
// The inspector section. Nothing when this task has no brief. Parked questions stay collapsed.
|
|
434
|
+
// An unanswered parked question still has an answer box, so it can be answered and then proposed.
|
|
245
435
|
function taskSection(host, ctx, task) {
|
|
246
436
|
const brief = task && task.brief;
|
|
247
437
|
if (!host || !brief || typeof brief !== 'object') return null;
|
|
@@ -250,17 +440,12 @@
|
|
|
250
440
|
const questions = list(brief.questions).filter(item => item && typeof item === 'object');
|
|
251
441
|
const parked = list(brief.parked).filter(item => item && typeof item === 'object');
|
|
252
442
|
if (!questions.length && !parked.length) section.append(el('p', 'No questions.', 'muted'));
|
|
253
|
-
if (questions.length)
|
|
254
|
-
const ul = el('ul', undefined, 'brief-questions');
|
|
255
|
-
for (const question of questions) ul.append(questionCard(question, ctx, task, false));
|
|
256
|
-
section.append(ul);
|
|
257
|
-
}
|
|
443
|
+
if (questions.length) appendQuestions(section, questions, ctx, task, false);
|
|
258
444
|
if (parked.length) {
|
|
259
445
|
const details = el('details', undefined, 'brief-parked');
|
|
260
446
|
details.dataset.keep = 'brief-parked:' + task.id;
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
details.append(el('summary', 'Parked (wider scope)'), ul);
|
|
447
|
+
details.append(el('summary', 'Parked (wider scope)'));
|
|
448
|
+
appendQuestions(details, parked, ctx, task, true);
|
|
264
449
|
section.append(details);
|
|
265
450
|
}
|
|
266
451
|
host.append(section);
|
|
@@ -268,35 +453,153 @@
|
|
|
268
453
|
return section;
|
|
269
454
|
}
|
|
270
455
|
|
|
271
|
-
|
|
456
|
+
function openItem(item, spec) {
|
|
457
|
+
const run = spec.run;
|
|
458
|
+
const task = item.task, question = item.question;
|
|
459
|
+
const li = el('li');
|
|
460
|
+
const link = el('a', undefined, 'brief-open');
|
|
461
|
+
link.href = typeof spec.href === 'function' ? spec.href(task.id) : '#';
|
|
462
|
+
const top = el('span', undefined, 'brief-open-top');
|
|
463
|
+
top.append(el('span', task.id, 'mono brief-open-task'), el('span', typeof question.text === 'string' && question.text ? question.text : '—', 'brief-open-text'));
|
|
464
|
+
link.append(top);
|
|
465
|
+
const marks = flags(question);
|
|
466
|
+
if (marks) link.append(marks);
|
|
467
|
+
const when = startLine({ deps: waitingDeps(task, run && run.tasks), start: projectionStart(spec.projections, task), now: spec.now, status: task.status });
|
|
468
|
+
if (when) link.append(el('span', when, 'brief-when'));
|
|
469
|
+
li.append(link);
|
|
470
|
+
return li;
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
function drawDiff(proposal) {
|
|
474
|
+
const box = el('div', undefined, 'brief-patch');
|
|
475
|
+
const Diff = (typeof globalThis !== 'undefined' && globalThis.ForgeDiff) || (root && root.ForgeDiff);
|
|
476
|
+
const text = typeof proposal.diff === 'string' ? proposal.diff : '';
|
|
477
|
+
const opts = { truncated: proposal.truncated === true };
|
|
478
|
+
if (Diff && typeof Diff.renderPatch === 'function') Diff.renderPatch(box, text, opts);
|
|
479
|
+
else {
|
|
480
|
+
box.append(el('pre', text, 'mono brief-diff'));
|
|
481
|
+
if (opts.truncated) box.append(el('p', 'This diff was cut short.', 'warn'));
|
|
482
|
+
}
|
|
483
|
+
return box;
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
async function sendDecision(card, spec, proposal, kind, reasonField) {
|
|
487
|
+
if (card.dataset.busy) return;
|
|
488
|
+
const run = (spec && spec.run) || {};
|
|
489
|
+
const base = '/api/runs/' + encodeURIComponent(run.key) + '/proposals/' + encodeURIComponent(proposal.pid) + '/';
|
|
490
|
+
let path, body;
|
|
491
|
+
if (kind === 'apply') {
|
|
492
|
+
path = base + 'apply';
|
|
493
|
+
body = { hash: proposal.hash };
|
|
494
|
+
} else {
|
|
495
|
+
path = base + 'reject';
|
|
496
|
+
const reason = reasonField && typeof reasonField.value === 'string' ? reasonField.value.trim() : '';
|
|
497
|
+
body = reason ? { reason } : {};
|
|
498
|
+
}
|
|
499
|
+
setBusy(card, true);
|
|
500
|
+
const res = await postJson(path, body);
|
|
501
|
+
if (!card.isConnected) return;
|
|
502
|
+
const output = outputOf(res);
|
|
503
|
+
if (output) proposalNotices.set(proposalKey(run.key, proposal.pid), output);
|
|
504
|
+
if (res && res.ok && spec && spec.refresh) { spec.refresh(); return; }
|
|
505
|
+
setBusy(card, false);
|
|
506
|
+
const ui = forgeUI();
|
|
507
|
+
const msgs = card.querySelector('.brief-msgs');
|
|
508
|
+
if (!(res && res.ok) && ui && ui.outcome && msgs) ui.outcome(msgs, res);
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
function proposalActions(card, spec, proposal) {
|
|
512
|
+
const actions = el('div', undefined, 'brief-actions');
|
|
513
|
+
const msgs = el('div', undefined, 'brief-msgs');
|
|
514
|
+
if (typeof proposal.hash === 'string' && proposal.hash) {
|
|
515
|
+
const approve = el('button', 'Approve', 'brief-approve');
|
|
516
|
+
approve.type = 'button';
|
|
517
|
+
approve.addEventListener('click', () => sendDecision(card, spec, proposal, 'apply'));
|
|
518
|
+
actions.append(approve);
|
|
519
|
+
}
|
|
520
|
+
const reject = el('button', 'Reject', 'brief-reject');
|
|
521
|
+
reject.type = 'button';
|
|
522
|
+
const reason = el('input');
|
|
523
|
+
reason.type = 'text';
|
|
524
|
+
reason.maxLength = 500;
|
|
525
|
+
reason.setAttribute('aria-label', 'Reject reason');
|
|
526
|
+
reason.placeholder = 'Reason (optional)';
|
|
527
|
+
reject.addEventListener('click', () => sendDecision(card, spec, proposal, 'reject', reason));
|
|
528
|
+
actions.append(reject, reason, msgs);
|
|
529
|
+
return actions;
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
function proposalCard(proposal, spec) {
|
|
533
|
+
const card = el('article', undefined, 'brief-proposal');
|
|
534
|
+
if (proposal.pid) card.dataset.pid = String(proposal.pid);
|
|
535
|
+
const top = el('div', undefined, 'brief-proposal-top');
|
|
536
|
+
top.append(el('span', typeof proposal.state === 'string' && proposal.state ? proposal.state : '—', 'tag brief-state'));
|
|
537
|
+
top.append(el('span', typeof proposal.scope === 'string' && proposal.scope ? proposal.scope : '—', 'tag'));
|
|
538
|
+
const group = typeof proposal.group === 'string' && proposal.group ? proposal.group : '—';
|
|
539
|
+
top.append(el('span', group, 'brief-proposal-group'));
|
|
540
|
+
card.append(top);
|
|
541
|
+
card.append(el('p', typeof proposal.summary === 'string' && proposal.summary ? proposal.summary : '—', 'brief-summary'));
|
|
542
|
+
if (proposal.state === 'refused' && typeof proposal.reason === 'string' && proposal.reason) card.append(el('p', proposal.reason, 'brief-reason'));
|
|
543
|
+
if (typeof proposal.hash === 'string' && proposal.hash) card.append(el('code', proposal.hash, 'mono brief-hash'));
|
|
544
|
+
card.append(drawDiff(proposal));
|
|
545
|
+
const run = spec && spec.run;
|
|
546
|
+
const stored = proposalNotices.get(proposalKey(run && run.key, proposal.pid));
|
|
547
|
+
if (stored) card.append(noticeNode(stored));
|
|
548
|
+
if (proposal.state === 'proposed') card.append(proposalActions(card, spec, proposal));
|
|
549
|
+
return card;
|
|
550
|
+
}
|
|
551
|
+
|
|
552
|
+
function proposalsBlock(proposals, spec) {
|
|
553
|
+
const wrap = el('div', undefined, 'brief-proposals');
|
|
554
|
+
const head = el('p', undefined, 'brief-list-head');
|
|
555
|
+
head.append(el('span', 'Proposals', 'plate'), el('span', String(proposals.length), 'module-count'));
|
|
556
|
+
wrap.append(head);
|
|
557
|
+
for (const proposal of proposals) wrap.append(proposalCard(proposal, spec));
|
|
558
|
+
return wrap;
|
|
559
|
+
}
|
|
560
|
+
|
|
561
|
+
// The run's open questions, grouped when a group or a plan section exists, and its proposals.
|
|
562
|
+
// All-loose questions stay the flat list the run page had. Beside another section they sit under
|
|
563
|
+
// "No group", not under the previous heading. `href(taskId)` opens that task's inspector.
|
|
272
564
|
function renderList(host, spec) {
|
|
273
565
|
spec = spec || {};
|
|
274
566
|
if (!host) return;
|
|
275
567
|
host.replaceChildren();
|
|
568
|
+
if (host.dataset) delete host.dataset.proposals;
|
|
276
569
|
const run = spec.run;
|
|
277
570
|
const open = orderQuestions(openQuestions(run), spec.projections);
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
const
|
|
285
|
-
|
|
286
|
-
const
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
571
|
+
const proposals = list(run && run.proposals).filter(item => item && typeof item === 'object');
|
|
572
|
+
if (!open.length && !proposals.length) return;
|
|
573
|
+
if (proposals.length && host.dataset) host.dataset.proposals = '1';
|
|
574
|
+
if (open.length) {
|
|
575
|
+
const head = el('p', undefined, 'brief-list-head');
|
|
576
|
+
head.append(el('span', 'Questions', 'plate'), el('span', String(open.length), 'module-count'));
|
|
577
|
+
const ul = el('ul', undefined, 'brief-list');
|
|
578
|
+
ul.dataset.scroll = 'brief-list';
|
|
579
|
+
const sections = groupQuestions(open, run && run.groups);
|
|
580
|
+
const flat = sections.length === 1 && sections[0].kind === 'loose';
|
|
581
|
+
if (flat) {
|
|
582
|
+
for (const item of sections[0].items) ul.append(openItem(item, spec));
|
|
583
|
+
} else {
|
|
584
|
+
for (const section of sections) {
|
|
585
|
+
const li = el('li');
|
|
586
|
+
const heading = sectionHead(section);
|
|
587
|
+
if (heading) li.append(heading);
|
|
588
|
+
if (li.childElementCount) ul.append(li);
|
|
589
|
+
for (const item of section.items) ul.append(openItem(item, spec));
|
|
590
|
+
}
|
|
591
|
+
}
|
|
592
|
+
host.append(head, ul);
|
|
593
|
+
}
|
|
594
|
+
if (proposals.length) {
|
|
595
|
+
const block = proposalsBlock(proposals, spec);
|
|
596
|
+
host.append(block);
|
|
597
|
+
settleControls(block);
|
|
297
598
|
}
|
|
298
|
-
host.append(head, ul);
|
|
299
599
|
}
|
|
300
600
|
|
|
301
|
-
return {
|
|
601
|
+
return {
|
|
602
|
+
openQuestions, orderQuestions, startLine, renderList, taskSection,
|
|
603
|
+
groupQuestions, canPropose, affectedLabel, affectedBadge,
|
|
604
|
+
};
|
|
302
605
|
});
|
|
@@ -235,5 +235,90 @@ window.ForgeDiff = (() => {
|
|
|
235
235
|
if (target && host.dataset.scrolledTo !== url + '\n' + spec.file) { host.dataset.scrolledTo = url + '\n' + spec.file; requestAnimationFrame(() => target.scrollIntoView({ block: 'start' })); }
|
|
236
236
|
}
|
|
237
237
|
}
|
|
238
|
-
|
|
238
|
+
|
|
239
|
+
// A proposal's unified diff (difflib, or diff --git). Same line table as a file hunk, text only.
|
|
240
|
+
function parsePatch(text) {
|
|
241
|
+
const files = [];
|
|
242
|
+
let file = null, hunk = null, sawMinus = false;
|
|
243
|
+
function startFile(name) {
|
|
244
|
+
file = { name: name || 'diff', hunks: [] };
|
|
245
|
+
files.push(file);
|
|
246
|
+
hunk = null;
|
|
247
|
+
}
|
|
248
|
+
for (let raw of String(text || '').split('\n')) {
|
|
249
|
+
if (raw.endsWith('\r')) raw = raw.slice(0, -1);
|
|
250
|
+
if (raw.startsWith('diff --git ')) {
|
|
251
|
+
const parts = raw.slice('diff --git '.length).trim().split(/\s+/);
|
|
252
|
+
const name = (parts[1] || parts[0] || 'diff').replace(/^b\//, '');
|
|
253
|
+
startFile(name);
|
|
254
|
+
sawMinus = false;
|
|
255
|
+
continue;
|
|
256
|
+
}
|
|
257
|
+
if (raw.startsWith('--- ')) {
|
|
258
|
+
const name = raw.slice(4).trim().replace(/^a\//, '');
|
|
259
|
+
startFile(name === '/dev/null' ? 'diff' : name);
|
|
260
|
+
sawMinus = true;
|
|
261
|
+
continue;
|
|
262
|
+
}
|
|
263
|
+
if (raw.startsWith('+++ ') && sawMinus) {
|
|
264
|
+
const name = raw.slice(4).trim().replace(/^b\//, '');
|
|
265
|
+
if (file && name && name !== '/dev/null') file.name = name;
|
|
266
|
+
sawMinus = false;
|
|
267
|
+
continue;
|
|
268
|
+
}
|
|
269
|
+
sawMinus = false;
|
|
270
|
+
const head = /^@@ -(\d+)(?:,(\d+))? \+(\d+)(?:,(\d+))? @@(.*)$/.exec(raw);
|
|
271
|
+
if (head) {
|
|
272
|
+
if (!file) startFile('diff');
|
|
273
|
+
hunk = {
|
|
274
|
+
old_start: Number(head[1]), old_lines: head[2] == null ? 1 : Number(head[2]),
|
|
275
|
+
new_start: Number(head[3]), new_lines: head[4] == null ? 1 : Number(head[4]),
|
|
276
|
+
section: head[5].trim(), lines: [],
|
|
277
|
+
};
|
|
278
|
+
file.hunks.push(hunk);
|
|
279
|
+
continue;
|
|
280
|
+
}
|
|
281
|
+
if (hunk && (raw.startsWith('+') || raw.startsWith('-') || raw.startsWith(' ') || raw.startsWith('\\'))) hunk.lines.push(raw);
|
|
282
|
+
}
|
|
283
|
+
return files.filter(item => item.hunks.length);
|
|
284
|
+
}
|
|
285
|
+
function patchTable(file) {
|
|
286
|
+
const sec = el('section', undefined, 'diff-file');
|
|
287
|
+
if (file.name) sec.append(el('p', file.name, 'mono diff-path'));
|
|
288
|
+
const table = el('table', undefined, 'diff-table');
|
|
289
|
+
table.setAttribute('role', 'presentation');
|
|
290
|
+
const body = el('tbody');
|
|
291
|
+
for (const h of file.hunks) {
|
|
292
|
+
const hr = el('tr', undefined, 'diff-hunk');
|
|
293
|
+
const label = `@@ -${h.old_start},${h.old_lines} +${h.new_start},${h.new_lines} @@${h.section ? ' ' + h.section : ''}`;
|
|
294
|
+
const hc = el('td', label);
|
|
295
|
+
hc.colSpan = 4;
|
|
296
|
+
hr.append(hc);
|
|
297
|
+
body.append(hr);
|
|
298
|
+
let o = h.old_start, n = h.new_start;
|
|
299
|
+
for (const ln of h.lines) {
|
|
300
|
+
const m = ln[0];
|
|
301
|
+
const tr = el('tr', undefined, 'diff-line ' + (m === '+' ? 'add' : m === '-' ? 'del' : m === '\\' ? 'meta' : 'ctx'));
|
|
302
|
+
const on = m === '+' || m === '\\' ? '' : String(o++);
|
|
303
|
+
const nn = m === '-' || m === '\\' ? '' : String(n++);
|
|
304
|
+
tr.append(el('td', on, 'ln'), el('td', nn, 'ln'), el('td', m === '\\' ? '' : m, 'mk'), el('td', m === '\\' ? ln.slice(1).trim() : ln.slice(1), 'code'));
|
|
305
|
+
body.append(tr);
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
table.append(body);
|
|
309
|
+
const scroll = el('div', undefined, 'diff-scroll');
|
|
310
|
+
scroll.append(table);
|
|
311
|
+
sec.append(scroll);
|
|
312
|
+
return sec;
|
|
313
|
+
}
|
|
314
|
+
function renderPatch(host, text, opts) {
|
|
315
|
+
if (!host) return;
|
|
316
|
+
host.replaceChildren();
|
|
317
|
+
opts = opts || {};
|
|
318
|
+
const files = parsePatch(text);
|
|
319
|
+
if (!files.length) host.append(el('pre', typeof text === 'string' ? text : '', 'mono brief-diff'));
|
|
320
|
+
else for (const file of files) host.append(patchTable(file));
|
|
321
|
+
if (opts.truncated) host.append(el('p', 'This diff was cut short.', 'warn'));
|
|
322
|
+
}
|
|
323
|
+
return { render, urlFor, cache, renderPatch };
|
|
239
324
|
})();
|