@giamme/forge 0.17.0 → 0.19.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +57 -0
- package/README.md +1 -0
- package/SKILL.md +32 -5
- package/VERSION +1 -1
- package/docs/artifacts.md +33 -1
- package/docs/commands.md +147 -16
- package/docs/dataset.md +5 -0
- package/docs/decomposed-runs.md +122 -1
- package/docs/development.md +2 -1
- package/docs/forge-ui.md +98 -8
- package/docs/memory.md +27 -4
- package/docs/models.md +8 -0
- package/docs/reviews.md +122 -0
- package/docs/safety.md +8 -0
- package/forge +44 -4
- package/package.json +2 -1
- package/references/dataset.md +39 -1
- package/references/decompose.md +737 -16
- package/references/harnesses.md +18 -3
- package/references/planning.md +43 -14
- package/references/solo.md +2 -1
- package/references/ui.md +56 -6
- package/registry.tsv +8 -3
- package/scripts/forge-artifact.sh +14 -0
- package/scripts/forge-brief.py +217 -0
- package/scripts/forge-compare.py +13 -2
- package/scripts/forge-config.py +176 -9
- package/scripts/forge-contract.py +246 -28
- package/scripts/forge-control.py +200 -15
- package/scripts/forge-dispatch.sh +48 -15
- package/scripts/forge-du.py +167 -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-lib-adopt.sh +1 -0
- package/scripts/forge-lib-group.sh +641 -0
- package/scripts/forge-lib-plans.sh +343 -4
- package/scripts/forge-lib-review.sh +29 -1
- package/scripts/forge-lib-task.sh +197 -4
- package/scripts/forge-memory.sh +245 -3
- package/scripts/forge-metrics.sh +7 -3
- package/scripts/forge-parallel-options.sh +4 -0
- package/scripts/forge-parallel.sh +1216 -41
- package/scripts/forge-planner.py +104 -8
- package/scripts/forge-prompt.py +120 -0
- package/scripts/forge-retro.py +115 -0
- package/scripts/forge-route.py +190 -12
- package/scripts/forge-runs-compact.py +443 -0
- package/scripts/forge-runs-rm.py +2 -0
- package/scripts/forge-runs.py +27 -8
- package/scripts/forge-schedule.py +633 -49
- package/scripts/forge-shadow.py +7 -1
- package/scripts/forge-solo.sh +4 -0
- package/scripts/forge-summarize.py +698 -0
- package/scripts/forge-ui-options.sh +10 -0
- package/scripts/forge-worktrees.py +243 -0
- package/scripts/forge_brief/__init__.py +831 -0
- package/scripts/forge_brief/answers.py +506 -0
- package/scripts/forge_brief/proposals.py +1630 -0
- package/scripts/forge_dataset/__init__.py +10 -0
- package/scripts/forge_dataset/efforts.py +4 -3
- package/scripts/forge_dataset/export.py +36 -10
- package/scripts/forge_dataset/facts.py +8 -4
- package/scripts/forge_dataset/forecast.py +8 -18
- package/scripts/forge_dataset/harvest.py +241 -12
- package/scripts/forge_dataset/history.py +13 -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_decide/__init__.py +11 -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_locations.py +366 -0
- package/scripts/forge_owner.py +152 -0
- package/scripts/forge_registry.py +19 -0
- package/scripts/forge_retro/__init__.py +417 -0
- package/scripts/forge_retro/issues.py +1193 -0
- package/scripts/forge_retro/report.py +671 -0
- package/scripts/forge_side/__init__.py +482 -0
- package/scripts/forge_storage.py +515 -0
- package/ui/README.md +68 -8
- package/ui/docs/api.md +375 -31
- package/ui/forge_ui/control.py +451 -11
- package/ui/forge_ui/executions.py +8 -1
- package/ui/forge_ui/export.py +53 -7
- package/ui/forge_ui/groups.py +264 -0
- package/ui/forge_ui/links.py +337 -0
- package/ui/forge_ui/models.py +125 -10
- package/ui/forge_ui/projects.py +4 -1
- package/ui/forge_ui/reader.py +919 -45
- package/ui/forge_ui/server.py +4 -0
- package/ui/forge_ui/static/app.js +173 -11
- package/ui/forge_ui/static/briefview.js +605 -0
- package/ui/forge_ui/static/checksview.js +6 -2
- package/ui/forge_ui/static/controls.js +5 -0
- 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 +4 -0
- package/ui/forge_ui/static/panel.js +394 -8
- package/ui/forge_ui/static/projectsview.js +189 -10
- package/ui/forge_ui/static/runmodel.js +27 -4
- package/ui/forge_ui/static/storageview.js +352 -0
- package/ui/forge_ui/static/style.css +176 -6
- package/ui/forge_ui/static/worktreesview.js +235 -14
- package/ui/forge_ui/storage.py +150 -0
- package/ui/forge_ui/transcripts.py +35 -10
- package/ui/forge_ui/worktrees.py +154 -13
|
@@ -0,0 +1,605 @@
|
|
|
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.
|
|
6
|
+
Ordering is flagged (must answer) first, then by the projected start from projectSchedule. A task with no
|
|
7
|
+
finite start is last. Wave numbers are a preview and are never a sort key. */
|
|
8
|
+
(function (root, factory) {
|
|
9
|
+
'use strict';
|
|
10
|
+
const api = factory(root);
|
|
11
|
+
if (typeof module === 'object' && module.exports) module.exports = api;
|
|
12
|
+
else root.ForgeBrief = api;
|
|
13
|
+
})(typeof self !== 'undefined' ? self : this, function (root) {
|
|
14
|
+
'use strict';
|
|
15
|
+
|
|
16
|
+
const list = v => Array.isArray(v) ? v : [];
|
|
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';
|
|
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
|
+
}
|
|
33
|
+
|
|
34
|
+
function el(tag, text, className) {
|
|
35
|
+
const node = page().document.createElement(tag);
|
|
36
|
+
if (text !== undefined) node.textContent = text === null || text === undefined ? '' : String(text);
|
|
37
|
+
if (className) node.className = className;
|
|
38
|
+
return node;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function noticeKey(run, task, question) {
|
|
42
|
+
return String(run && run.key) + '\n' + String(task && task.id) + '\n' + String(question && question.id);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function proposalKey(runKey, pid) {
|
|
46
|
+
return String(runKey) + '\n' + String(pid);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// Open task questions, in task order. Parked questions are wider than the task and are not listed here.
|
|
50
|
+
function openQuestions(run) {
|
|
51
|
+
const items = [];
|
|
52
|
+
for (const task of list(run && run.tasks)) {
|
|
53
|
+
const brief = task && task.brief;
|
|
54
|
+
if (!brief || typeof brief !== 'object') continue;
|
|
55
|
+
for (const question of list(brief.questions)) {
|
|
56
|
+
if (!question || typeof question !== 'object' || question.state !== 'open') continue;
|
|
57
|
+
items.push({ task, question });
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return items;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function projectionStart(projections, task) {
|
|
64
|
+
if (!projections || !task) return null;
|
|
65
|
+
const row = projections[task.id];
|
|
66
|
+
if (!row || typeof row !== 'object') return null;
|
|
67
|
+
return num(row.start);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// Flagged first, then the earliest finite projected start. No start (missing, or not a finite number) sorts
|
|
71
|
+
// last inside its group. The original index breaks ties, so equal starts keep the order they were given.
|
|
72
|
+
function orderQuestions(items, projections) {
|
|
73
|
+
const rows = list(items).map((item, index) => ({ item, index }));
|
|
74
|
+
rows.sort((a, b) => {
|
|
75
|
+
const fa = a.item && a.item.question && a.item.question.must_answer === true ? 0 : 1;
|
|
76
|
+
const fb = b.item && b.item.question && b.item.question.must_answer === true ? 0 : 1;
|
|
77
|
+
if (fa !== fb) return fa - fb;
|
|
78
|
+
const sa = projectionStart(projections, a.item && a.item.task);
|
|
79
|
+
const sb = projectionStart(projections, b.item && b.item.task);
|
|
80
|
+
if (sa === null && sb !== null) return 1;
|
|
81
|
+
if (sa !== null && sb === null) return -1;
|
|
82
|
+
if (sa !== null && sb !== null && sa !== sb) return sa - sb;
|
|
83
|
+
return a.index - b.index;
|
|
84
|
+
});
|
|
85
|
+
return rows.map(row => row.item);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// A wait, rounded to a phrase. Under 45s is "about now"; otherwise the nearest minute, then hours.
|
|
89
|
+
function aboutText(seconds) {
|
|
90
|
+
const s = Math.max(0, num(seconds) === null ? 0 : seconds);
|
|
91
|
+
if (s < 45) return 'about now';
|
|
92
|
+
const minutes = Math.round(s / 60);
|
|
93
|
+
if (minutes <= 1) return 'about 1 min';
|
|
94
|
+
if (minutes < 60) return 'about ' + minutes + ' min';
|
|
95
|
+
const hours = Math.floor(minutes / 60), rest = minutes % 60;
|
|
96
|
+
return rest ? 'about ' + hours + ' h ' + rest + ' min' : 'about ' + hours + ' h';
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function namesPhrase(deps) {
|
|
100
|
+
const names = list(deps).map(id => String(id));
|
|
101
|
+
if (names.length <= 1) return names[0] || '';
|
|
102
|
+
if (names.length === 2) return names[0] + ' and ' + names[1];
|
|
103
|
+
return names.slice(0, -1).join(', ') + ' and ' + names[names.length - 1];
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// "starts after A and B merge, about 40 min". No finite start → null. No clock → the wait is about now.
|
|
107
|
+
// A task that has started (any status but PENDING or BLOCKED) says so instead: its projected start is in
|
|
108
|
+
// the past, and an answer now is a late one.
|
|
109
|
+
function startLine(spec) {
|
|
110
|
+
spec = spec || {};
|
|
111
|
+
const status = typeof spec.status === 'string' ? spec.status : '';
|
|
112
|
+
if (status === 'RUNNING') return 'running now';
|
|
113
|
+
if (status && status !== 'PENDING' && status !== 'BLOCKED') return 'already started';
|
|
114
|
+
const start = num(spec.start);
|
|
115
|
+
if (start === null) return null;
|
|
116
|
+
const clock = num(spec.now);
|
|
117
|
+
const about = aboutText(clock === null ? 0 : start - clock);
|
|
118
|
+
const deps = list(spec.deps);
|
|
119
|
+
if (!deps.length) return about === 'about now' ? 'starts about now' : 'starts in ' + about;
|
|
120
|
+
const verb = deps.length === 1 ? 'merges' : 'merge';
|
|
121
|
+
return 'starts after ' + namesPhrase(deps) + ' ' + verb + ', ' + about;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// Deps that have not merged yet, including an id the run does not know. PASS is still ahead of the merge.
|
|
125
|
+
function waitingDeps(task, tasks) {
|
|
126
|
+
const byId = new Map(list(tasks).map(item => [item && item.id, item]));
|
|
127
|
+
return list(task && task.deps).filter(id => {
|
|
128
|
+
const dep = byId.get(id);
|
|
129
|
+
return !dep || dep.status !== 'MERGED';
|
|
130
|
+
});
|
|
131
|
+
}
|
|
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
|
+
|
|
217
|
+
function flags(question) {
|
|
218
|
+
const row = el('div', undefined, 'brief-flags');
|
|
219
|
+
if (question && question.must_answer === true) row.append(el('span', 'must answer', 'tag'));
|
|
220
|
+
if (question && question.possibly_stale === true) row.append(el('span', 'possibly stale', 'tag'));
|
|
221
|
+
return row.childElementCount ? row : null;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
function noticeNode(text) {
|
|
225
|
+
const pre = el('pre', text, 'brief-notice');
|
|
226
|
+
pre.setAttribute('role', 'status');
|
|
227
|
+
return pre;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
function paintNotice(box, text) {
|
|
231
|
+
const card = box && box.parentElement;
|
|
232
|
+
if (!card) return;
|
|
233
|
+
const node = noticeNode(text);
|
|
234
|
+
const old = card.querySelector(':scope > .brief-notice');
|
|
235
|
+
if (old) old.replaceWith(node);
|
|
236
|
+
else card.insertBefore(node, box);
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
function clearNotice(box) {
|
|
240
|
+
const old = box && box.parentElement && box.parentElement.querySelector(':scope > .brief-notice');
|
|
241
|
+
if (old) old.remove();
|
|
242
|
+
}
|
|
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
|
+
|
|
273
|
+
function answerBox(ctx, task, question) {
|
|
274
|
+
const run = ctx.run || {};
|
|
275
|
+
const box = el('div', undefined, 'brief-box');
|
|
276
|
+
box.dataset.hold = 'brief:' + run.key + ':' + task.id + ':' + question.id;
|
|
277
|
+
const field = el('textarea');
|
|
278
|
+
field.setAttribute('aria-label', 'Answer');
|
|
279
|
+
field.maxLength = 4096;
|
|
280
|
+
field.rows = 3;
|
|
281
|
+
field.autocomplete = 'off';
|
|
282
|
+
const send = el('button', 'Send', 'brief-send');
|
|
283
|
+
send.type = 'button';
|
|
284
|
+
const msgs = el('div', undefined, 'brief-msgs');
|
|
285
|
+
const mark = () => { box.dataset.editing = '1'; };
|
|
286
|
+
field.addEventListener('focus', mark);
|
|
287
|
+
field.addEventListener('input', mark);
|
|
288
|
+
field.addEventListener('blur', () => {
|
|
289
|
+
if (box.dataset.busy) return;
|
|
290
|
+
if (!field.value.trim()) delete box.dataset.editing;
|
|
291
|
+
});
|
|
292
|
+
send.addEventListener('click', () => sendAnswer(box, field, send, msgs, ctx, task, question));
|
|
293
|
+
box.append(field, send, msgs);
|
|
294
|
+
return box;
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
async function sendAnswer(box, field, send, msgs, ctx, task, question) {
|
|
298
|
+
if (box.dataset.busy) return;
|
|
299
|
+
const answer = field.value.trim();
|
|
300
|
+
const ui = forgeUI();
|
|
301
|
+
if (!answer) {
|
|
302
|
+
if (ui) ui.outcome(msgs, { ok: false, status: 400, error: 'invalid', detail: 'the answer is empty' });
|
|
303
|
+
return;
|
|
304
|
+
}
|
|
305
|
+
box.dataset.editing = '1';
|
|
306
|
+
box.dataset.busy = '1';
|
|
307
|
+
box.setAttribute('aria-busy', 'true');
|
|
308
|
+
send.disabled = true;
|
|
309
|
+
const run = ctx.run || {};
|
|
310
|
+
const path = '/api/runs/' + encodeURIComponent(run.key) + '/tasks/' + encodeURIComponent(task.id) + '/brief/' + encodeURIComponent(question.id);
|
|
311
|
+
let res = { ok: false, error: 'unavailable', detail: 'this page cannot send' };
|
|
312
|
+
try {
|
|
313
|
+
if (ui && ui.post) res = await ui.post(path, { answer });
|
|
314
|
+
} catch (_) {
|
|
315
|
+
res = { ok: false, error: 'failed', detail: 'could not send the answer' };
|
|
316
|
+
}
|
|
317
|
+
if (!box.isConnected) return;
|
|
318
|
+
delete box.dataset.busy;
|
|
319
|
+
box.removeAttribute('aria-busy');
|
|
320
|
+
send.disabled = false;
|
|
321
|
+
const data = res && res.data;
|
|
322
|
+
const output = data && typeof data.output === 'string' ? data.output : '';
|
|
323
|
+
if (res && res.ok && data && data.exit === 0) {
|
|
324
|
+
const key = noticeKey(run, task, question);
|
|
325
|
+
if (output.includes('forge control add')) {
|
|
326
|
+
notices.set(key, output);
|
|
327
|
+
paintNotice(box, output);
|
|
328
|
+
} else {
|
|
329
|
+
notices.delete(key);
|
|
330
|
+
clearNotice(box);
|
|
331
|
+
}
|
|
332
|
+
delete box.dataset.editing; // the redraw shows the recorded answer, not this draft
|
|
333
|
+
if (ctx.refresh) ctx.refresh();
|
|
334
|
+
return;
|
|
335
|
+
}
|
|
336
|
+
if (ui && ui.outcome) ui.outcome(msgs, res);
|
|
337
|
+
}
|
|
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
|
+
|
|
371
|
+
function questionCard(question, ctx, task, parked) {
|
|
372
|
+
const li = el('li', undefined, 'brief-q');
|
|
373
|
+
if (question.id) li.dataset.qid = String(question.id);
|
|
374
|
+
li.append(el('p', typeof question.text === 'string' && question.text ? question.text : '—', 'brief-text'));
|
|
375
|
+
if (typeof question.why === 'string' && question.why) li.append(el('p', question.why, 'brief-why muted'));
|
|
376
|
+
const options = list(question.options).filter(item => typeof item === 'string' && item);
|
|
377
|
+
if (options.length) li.append(el('p', options.join(' · '), 'brief-options'));
|
|
378
|
+
if (typeof question.default === 'string' && question.default) li.append(el('p', 'if unanswered: ' + question.default, 'brief-default muted'));
|
|
379
|
+
const marks = flags(question);
|
|
380
|
+
if (marks) li.append(marks);
|
|
381
|
+
if (typeof question.answer === 'string' && question.answer) li.append(el('p', 'Answer: ' + question.answer, 'brief-got'));
|
|
382
|
+
if (parked && typeof question.scope === 'string' && question.scope) li.append(el('p', 'scope: ' + question.scope, 'brief-scope muted'));
|
|
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));
|
|
388
|
+
return li;
|
|
389
|
+
}
|
|
390
|
+
|
|
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.
|
|
418
|
+
function settleControls(section) {
|
|
419
|
+
const ui = forgeUI();
|
|
420
|
+
const drop = () => {
|
|
421
|
+
if (!section.isConnected) return;
|
|
422
|
+
for (const box of section.querySelectorAll('.brief-box, .brief-actions')) box.remove();
|
|
423
|
+
section.dataset.controls = 'off';
|
|
424
|
+
};
|
|
425
|
+
if (!ui || !ui.controlsEnabled) { drop(); return; }
|
|
426
|
+
ui.controlsEnabled().then(on => {
|
|
427
|
+
if (!section.isConnected) return;
|
|
428
|
+
if (!on) drop();
|
|
429
|
+
else section.dataset.controls = 'on';
|
|
430
|
+
});
|
|
431
|
+
}
|
|
432
|
+
|
|
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.
|
|
435
|
+
function taskSection(host, ctx, task) {
|
|
436
|
+
const brief = task && task.brief;
|
|
437
|
+
if (!host || !brief || typeof brief !== 'object') return null;
|
|
438
|
+
const section = el('section', undefined, 'insp-section brief-section');
|
|
439
|
+
section.append(el('h3', 'Questions'));
|
|
440
|
+
const questions = list(brief.questions).filter(item => item && typeof item === 'object');
|
|
441
|
+
const parked = list(brief.parked).filter(item => item && typeof item === 'object');
|
|
442
|
+
if (!questions.length && !parked.length) section.append(el('p', 'No questions.', 'muted'));
|
|
443
|
+
if (questions.length) appendQuestions(section, questions, ctx, task, false);
|
|
444
|
+
if (parked.length) {
|
|
445
|
+
const details = el('details', undefined, 'brief-parked');
|
|
446
|
+
details.dataset.keep = 'brief-parked:' + task.id;
|
|
447
|
+
details.append(el('summary', 'Parked (wider scope)'));
|
|
448
|
+
appendQuestions(details, parked, ctx, task, true);
|
|
449
|
+
section.append(details);
|
|
450
|
+
}
|
|
451
|
+
host.append(section);
|
|
452
|
+
settleControls(section);
|
|
453
|
+
return section;
|
|
454
|
+
}
|
|
455
|
+
|
|
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.
|
|
564
|
+
function renderList(host, spec) {
|
|
565
|
+
spec = spec || {};
|
|
566
|
+
if (!host) return;
|
|
567
|
+
host.replaceChildren();
|
|
568
|
+
if (host.dataset) delete host.dataset.proposals;
|
|
569
|
+
const run = spec.run;
|
|
570
|
+
const open = orderQuestions(openQuestions(run), spec.projections);
|
|
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);
|
|
598
|
+
}
|
|
599
|
+
}
|
|
600
|
+
|
|
601
|
+
return {
|
|
602
|
+
openQuestions, orderQuestions, startLine, renderList, taskSection,
|
|
603
|
+
groupQuestions, canPropose, affectedLabel, affectedBadge,
|
|
604
|
+
};
|
|
605
|
+
});
|
|
@@ -83,6 +83,10 @@
|
|
|
83
83
|
if (w.kind === 'slot') return { ...out, text: `no free slot: ${num(w.running) ?? '?'} of ${num(w.max_parallel) ?? '?'} running` };
|
|
84
84
|
if (w.kind === 'drained') return { ...out, text: 'drained: nothing new starts until the run resumes' };
|
|
85
85
|
if (w.kind === 'stopping') return { ...out, text: w.mode === 'now' ? 'the run is stopping now' : 'the run stops once its running tasks end' };
|
|
86
|
+
if (w.kind === 'brief') {
|
|
87
|
+
const asked = ids(w.questions);
|
|
88
|
+
return { ...out, text: asked.length ? `waits for your answer to ${asked.join(', ')}` : 'waits for its brief questions to be written' };
|
|
89
|
+
}
|
|
86
90
|
if (w.kind === 'next') return { ...out, text: "starts at the scheduler's next turn" };
|
|
87
91
|
if (w.kind === 'infra') {
|
|
88
92
|
const cause = RM.causeLabel(w.class);
|
|
@@ -98,7 +102,7 @@
|
|
|
98
102
|
return null;
|
|
99
103
|
}
|
|
100
104
|
// The Now column's order: running, then what starts soonest, then what waits on others, then what is held
|
|
101
|
-
const RANK = { running: 0, next: 1, slot: 2, overlap: 2, deps: 3, infra: 4, drained: 5, stopping: 5, escalation: 6 };
|
|
105
|
+
const RANK = { running: 0, next: 1, slot: 2, overlap: 2, brief: 2, deps: 3, infra: 4, drained: 5, stopping: 5, escalation: 6 };
|
|
102
106
|
function nowRank(task) {
|
|
103
107
|
if (task && task.now) return RANK.running;
|
|
104
108
|
const w = task && task.waiting;
|
|
@@ -142,7 +146,7 @@
|
|
|
142
146
|
if (!s || s.live !== true) return null;
|
|
143
147
|
const tasks = list(run.tasks), count = kind => tasks.filter(t => t.waiting && t.waiting.kind === kind).length;
|
|
144
148
|
const state = s.stopping ? (s.stopping === 'now' ? 'stopping now' : 'stopping once its running tasks end') : s.drained ? 'drained: nothing new starts' : 'dispatching';
|
|
145
|
-
const waiting = [['deps', 'on dependencies'], ['overlap', 'on shared files'], ['slot', 'for a free slot'], ['infra', 'paused'],
|
|
149
|
+
const waiting = [['deps', 'on dependencies'], ['overlap', 'on shared files'], ['slot', 'for a free slot'], ['brief', 'for your answer'], ['infra', 'paused'],
|
|
146
150
|
['next', 'next'], ['escalation', 'stopped by the retry policy']]
|
|
147
151
|
.map(([kind, label]) => [count(kind), label]).filter(([n]) => n).map(([n, label]) => `${n} ${label}`);
|
|
148
152
|
const rows = [['Scheduler', state], ['Running', String(tasks.filter(t => t.status === 'RUNNING').length) + (num(s.max_parallel) !== null ? ` of ${s.max_parallel} slots` : '')]];
|
|
@@ -29,6 +29,7 @@
|
|
|
29
29
|
'max-parallel': { label: 'Max parallel', run: 'at the next dispatch', planOnly: true, live: true },
|
|
30
30
|
'infra-backoff': { label: 'Infra backoff', run: 'at the next infrastructure wait', planOnly: true },
|
|
31
31
|
'escalate-effort': { label: 'Effort step', run: 'at the next retry decision', planOnly: true },
|
|
32
|
+
'summaries': { label: 'Summaries', run: "at each task's next change", task: 'at its next change' },
|
|
32
33
|
};
|
|
33
34
|
const BACKOFF_FORMS = 'exp:<base>[,<cap>], linear:<start>,<step>[,<cap>] or list:<a>,<b>,… (seconds)';
|
|
34
35
|
// A task status after which "Retry now" applies (or the policy stopped it).
|
|
@@ -94,6 +95,10 @@
|
|
|
94
95
|
if (key === 'max-parallel') {
|
|
95
96
|
return /^[0-9]{1,2}$/.test(text) && Number(text) >= 1 && Number(text) <= 64 ? { ok: true, value: String(Number(text)) } : bad('a whole number, 1 to 64');
|
|
96
97
|
}
|
|
98
|
+
if (key === 'summaries') {
|
|
99
|
+
return text === 'on' || text === 'off' || (task && text === 'inherit') ? { ok: true, value: text }
|
|
100
|
+
: bad(task ? 'on, off or inherit' : 'on or off');
|
|
101
|
+
}
|
|
97
102
|
if (key === 'escalate-effort') return text === 'on' || text === 'off' ? { ok: true, value: text } : bad('on or off');
|
|
98
103
|
if (key === 'infra-backoff') {
|
|
99
104
|
// The shape itself is the CLI's to check; here only what can never be one. "default" drops the setting.
|