@popcorn245/cornfield 0.49.0 → 0.50.1
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/explorer/css/review.css +49 -0
- package/explorer/decision-model.js +6 -0
- package/explorer/engine/layout.js +8 -3
- package/explorer/engine/sheets.js +40 -7
- package/explorer/engine/topology.js +126 -0
- package/explorer/focus-room.js +1 -7
- package/explorer/focusables.js +1 -1
- package/explorer/forge-panel.js +36 -2630
- package/explorer/index.html +15 -147
- package/explorer/instance-state.js +0 -7
- package/explorer/instance.js +21 -2
- package/explorer/page-pieces.js +21 -2
- package/explorer/page.js +3 -3
- package/explorer/panels.js +1 -5
- package/explorer/pieces/changes.js +2 -9
- package/explorer/pieces/decision.js +10 -3
- package/explorer/pieces/layers.js +1 -0
- package/explorer/pieces/map.js +4 -23
- package/explorer/pieces/node-panel.js +15 -5
- package/explorer/pieces/proposal.js +9 -0
- package/explorer/pieces/review.js +280 -0
- package/explorer/pieces/work-agent.js +211 -0
- package/explorer/pieces/work-common.js +88 -0
- package/explorer/pieces/work-confirm.js +169 -0
- package/explorer/pieces/work-data.js +178 -0
- package/explorer/pieces/work-deploys.js +104 -0
- package/explorer/pieces/work-events.js +285 -0
- package/explorer/pieces/work-issues.js +43 -0
- package/explorer/pieces/work-markup.js +155 -0
- package/explorer/pieces/work-notes.js +177 -0
- package/explorer/pieces/work-paint.js +312 -0
- package/explorer/pieces/work-prs.js +253 -0
- package/explorer/pieces/work-runs.js +387 -0
- package/explorer/pieces/work-specs.js +71 -0
- package/explorer/pieces/work-threads.js +309 -0
- package/explorer/pieces/work.js +285 -0
- package/explorer/proposal.js +1 -2
- package/explorer/runs-map.js +108 -103
- package/explorer/runs-view.js +8 -6
- package/explorer/strings.js +1 -1
- package/explorer/view.js +6 -59
- package/explorer/waiting-model.js +12 -12
- package/explorer/waiting-view.js +6 -6
- package/package.json +1 -1
- package/explorer/feedback.js +0 -15
- package/explorer/waiting-line.js +0 -14
|
@@ -0,0 +1,280 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module explorer/pieces/review
|
|
3
|
+
*
|
|
4
|
+
* The review as one piece (spec 0011 D3, D4, D8): the engine half of the coming `<corn-review>`. It lays out, in ONE root and on ONE instance, what a
|
|
5
|
+
* review needs, and mounts the pieces of the explorer into it through their own `mount(root, inst, { slots })`: the map (pieces/map.js), the proposal's
|
|
6
|
+
* bar (pieces/proposal.js, without the what-if editor's buttons: the editor is not converted), the change list with the scenario player
|
|
7
|
+
* (pieces/changes.js), the decision's foot (pieces/decision.js, in the column's foot) and the node panel (pieces/node-panel.js). It is not cornfield's
|
|
8
|
+
* page: no header, Work panel, search, Layers chip, account menu or hint, and cornfield's page does not use it (it keeps its own layout).
|
|
9
|
+
*
|
|
10
|
+
* const review = mount(root, inst, options) -> { update, destroy, ... }
|
|
11
|
+
*
|
|
12
|
+
* root the host's element (or shadow root): the piece makes ONE box in it (`[data-corn="review"]`), and everything it makes is inside that box
|
|
13
|
+
* inst the instance; null makes one over the box, which `destroy()` then ends too. One instance for every piece inside: the lookups by id that
|
|
14
|
+
* still cross pieces (the dock, the bar, the review column, the node panel, the player's place) find their elements because there is one root
|
|
15
|
+
*
|
|
16
|
+
* Options, all optional; `update(next)` takes the same keys and applies what is present:
|
|
17
|
+
* topology {nodes, edges}: the map. The piece does not load it: it takes what it is given (engine/topology.js `setTopology`, which the map piece calls too)
|
|
18
|
+
* proposal a slug (fetched through `inst.fetch`, so a `base` applies; `source` names the copy), or the proposal object (nothing is fetched: `slug`,
|
|
19
|
+
* `source` and `sha256` may name it, which a decision needs; with no `base` and no `fetch` they are ignored, so nothing is sent anywhere), or null: closes it. Held until a topology is there
|
|
20
|
+
* source where the server found the proposal ('checkout', 'pull/24', a worktree)
|
|
21
|
+
* view 'before' | 'diff' | 'after': the proposal's view; or 'map' | 'dataflow': the map's. The two sets of words do not meet
|
|
22
|
+
* node the selected node's id (null clears it)
|
|
23
|
+
* config { theme, layers }: the repo's client config as /cornfield/config.json carries it, which this piece takes and does not fetch: `theme` starts the
|
|
24
|
+
* theme's map icons (they are fetched without the session, with CORS), `layers` are the project's layers
|
|
25
|
+
* strings the host's own words (core/strings.js keys): the instance speaks in them
|
|
26
|
+
* theme 'light' | 'dark' | 'auto' (the map's ground), checker (a plugin's checker for the scenarios), now (the decision's clock)
|
|
27
|
+
* base, fetch, tokens, renderer, onSelect, onReady as pieces/map.js; `renderer` is read at mount only (a canvas that is replaced loses the edge picking)
|
|
28
|
+
* label the box's accessible name (a region; 'Proposal review' by default), read at mount
|
|
29
|
+
*
|
|
30
|
+
* What a host hears is on the instance already (instance.js): `selection`, `proposal`, `decision`, `auth`, `scenario:player`. This piece adds nothing.
|
|
31
|
+
*
|
|
32
|
+
* Where it lives. The box declares itself the query container its stylesheets ask (`container: corn-box corn-page / size`, css/review.css) and is the
|
|
33
|
+
* containing block of its own `position: fixed` descendants (`contain: layout`), so it needs a host that gives it a height (it fills 100% of it and is never
|
|
34
|
+
* under 24rem). Under 768px by the box's own width, not the window's, it is the page's phone layout with its sheets (engine/sheets.js `setPhoneBox`).
|
|
35
|
+
* The stylesheets to load, in order, after the default tokens and before a theme: `STYLESHEETS` below (explorer/css/).
|
|
36
|
+
*
|
|
37
|
+
* Nothing leaves the box: no listener on `document` or `window`, nothing appended outside it, no id looked up outside it, keys act only with the focus
|
|
38
|
+
* inside, no `location`, no `history`; the wheel is the page's until the map has the focus or Ctrl or Cmd is held (input.js).
|
|
39
|
+
*
|
|
40
|
+
* Not in it: the what-if editor, the mockups, the Work panel, search, the Layers menu, the Proposals menu (its markup is kept in a spare, hidden place: the
|
|
41
|
+
* proposal piece makes it), signing in (the decision says `auth`).
|
|
42
|
+
*
|
|
43
|
+
* @param {Element|ShadowRoot} root
|
|
44
|
+
* @param {ReturnType<typeof import('../instance.js').createInstance>|null} inst
|
|
45
|
+
* @param {object} [options]
|
|
46
|
+
*/
|
|
47
|
+
|
|
48
|
+
import { createInstance } from '../instance.js';
|
|
49
|
+
import { mount as mountMap } from './map.js';
|
|
50
|
+
import { mount as mountNodePanel } from './node-panel.js';
|
|
51
|
+
import { mount as mountProposal } from './proposal.js';
|
|
52
|
+
import { mount as mountChanges } from './changes.js';
|
|
53
|
+
import { mount as mountDecision } from './decision.js';
|
|
54
|
+
import { setTopology, layoutMap, setMap } from '../engine/topology.js';
|
|
55
|
+
import { closeProposal, rebuildProposalMap } from '../engine/proposal.js';
|
|
56
|
+
import { measureCovered, setPhoneBox } from '../engine/sheets.js';
|
|
57
|
+
import { setProjectLayers } from '../engine/layers.js';
|
|
58
|
+
import { applyStrings, setStrings } from '../engine/strings.js';
|
|
59
|
+
import { withParts } from '../engine/piece.js';
|
|
60
|
+
import { PROPOSAL_VIEWS } from '../proposal-model.js';
|
|
61
|
+
import { NOTHING_TO_DECIDE } from '../decision-model.js';
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* The files of explorer/css/ the review needs, in the order to load them (the cascade's): after the default tokens (explorer/tokens.css, or the
|
|
65
|
+
* generated sheet `tokens` hands the map) and before a theme. Never page.css, which is cornfield's own page. The shell reads this list.
|
|
66
|
+
*/
|
|
67
|
+
export const STYLESHEETS = ['base.css', 'map.css', 'node-panel.css', 'proposal.css', 'changes.css', 'decision.css', 'sheets.css', 'review.css'];
|
|
68
|
+
|
|
69
|
+
/** The keys of the map in the review: the page's, without Freeform (the review has none) */
|
|
70
|
+
export const KEYS_HELP = "Arrow keys pan, plus and minus zoom, 0 fits the map. N and P select the next and the previous node, Home and End the first and the last. F frames the selected node and what it lights. Enter goes to the selected node's panel, Escape closes it.";
|
|
71
|
+
|
|
72
|
+
const MAP_VIEWS = ['map', 'orbit', 'dataflow'];
|
|
73
|
+
|
|
74
|
+
/** What the box says over a map with no nodes */
|
|
75
|
+
export const EMPTY_WORDS = 'There is no map to show: the topology has no nodes.';
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* The layout: a stage (the map, and over it the dock, which holds the bar, the review column and the node panel, and the tap-away behind the panel on a
|
|
79
|
+
* phone), as cornfield's page has, with each piece's place marked by a comment where its elements go before. The Proposals menu has a spare place of its own.
|
|
80
|
+
*/
|
|
81
|
+
const LAYOUT = '<div class="hx-stage" data-corn="stage">'
|
|
82
|
+
+ '<!--corn-piece:map/stage-->'
|
|
83
|
+
+ '<div id="sheet-dock" class="hx-dock" data-corn="dock">'
|
|
84
|
+
+ '<!--corn-piece:proposal/bar-->'
|
|
85
|
+
+ '<!--corn-piece:changes/column-->'
|
|
86
|
+
+ '<!--corn-piece:node-panel/drawer-->'
|
|
87
|
+
+ '</div>'
|
|
88
|
+
+ '<!--corn-piece:node-panel/backdrop-->'
|
|
89
|
+
+ '<p class="hx-review-empty" data-corn="empty" role="status" hidden></p>'
|
|
90
|
+
+ '</div>'
|
|
91
|
+
+ '<div class="hx-review-spare" hidden><!--corn-piece:proposal/menu--></div>';
|
|
92
|
+
|
|
93
|
+
/** The marker comments under `el`, by `name/slot` */
|
|
94
|
+
function markersIn(doc, el) {
|
|
95
|
+
const found = {};
|
|
96
|
+
const walker = doc.createTreeWalker(el, 128 /* NodeFilter.SHOW_COMMENT */);
|
|
97
|
+
for (let node = walker.nextNode(); node; node = walker.nextNode()) {
|
|
98
|
+
if (node.data.startsWith('corn-piece:')) found[node.data.slice('corn-piece:'.length)] = node;
|
|
99
|
+
}
|
|
100
|
+
return found;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export function mount(root, inst, options = {}) {
|
|
104
|
+
const doc = root.ownerDocument || root;
|
|
105
|
+
// -- the box: ONE root for everything the review makes ---------------------------------------------------------------------------------
|
|
106
|
+
const box = doc.createElement('div');
|
|
107
|
+
box.setAttribute('data-corn', 'review');
|
|
108
|
+
box.setAttribute('part', 'review');
|
|
109
|
+
// A named region: a screen reader finds the review as one place in the host's page (its headings start at h2: the proposal's title and the node's)
|
|
110
|
+
box.setAttribute('role', 'region');
|
|
111
|
+
box.setAttribute('aria-label', typeof options.label === 'string' && options.label.trim() ? options.label.trim() : 'Proposal review');
|
|
112
|
+
box.innerHTML = withParts(LAYOUT);
|
|
113
|
+
root.append(box);
|
|
114
|
+
|
|
115
|
+
const ownsInstance = !inst;
|
|
116
|
+
if (ownsInstance) inst = createInstance({ root: box, base: options.base || '', fetch: options.fetch, strings: options.strings });
|
|
117
|
+
else if (options.strings !== undefined) setStrings(inst, options.strings);
|
|
118
|
+
const { state } = inst;
|
|
119
|
+
setPhoneBox(inst, box); // a phone is a narrow box, whatever the window is (engine/sheets.js)
|
|
120
|
+
applyStrings(inst, box);
|
|
121
|
+
let ended = false;
|
|
122
|
+
|
|
123
|
+
// -- the pieces, in the order the page mounts them: the map first, the node panel, the bar, the column, the decision in the column's foot -----
|
|
124
|
+
const at = markersIn(doc, box);
|
|
125
|
+
const mapPiece = mountMap(box, inst, {
|
|
126
|
+
slots: { stage: at['map/stage'] },
|
|
127
|
+
measureCovered: () => measureCovered(inst),
|
|
128
|
+
keysHelp: KEYS_HELP,
|
|
129
|
+
renderer: options.renderer,
|
|
130
|
+
theme: options.theme,
|
|
131
|
+
tokens: options.tokens,
|
|
132
|
+
onSelect: options.onSelect,
|
|
133
|
+
onReady: options.onReady,
|
|
134
|
+
});
|
|
135
|
+
const nodePanel = mountNodePanel(box, inst, { slots: { drawer: at['node-panel/drawer'], backdrop: at['node-panel/backdrop'] } });
|
|
136
|
+
const proposalPiece = mountProposal(box, inst, { slots: { bar: at['proposal/bar'], menu: at['proposal/menu'] }, edit: false });
|
|
137
|
+
const changesPiece = mountChanges(box, inst, { slots: { column: at['changes/column'] }, checker: options.checker });
|
|
138
|
+
const foot = markersIn(doc, box)['decision/foot']; // the column keeps a place for it
|
|
139
|
+
const decisionPiece = mountDecision(box, inst, { slots: { foot }, now: options.now, unnamed: NOTHING_TO_DECIDE }); // handed an object with no server, it says so
|
|
140
|
+
|
|
141
|
+
// The review lays the map out from what the engine hands over (a proposal's nodes and edges are the base with marks): nodes that were there keep their place
|
|
142
|
+
const stopAsking = inst.on('map:set', ({ nodes, edges }) => { setMap(inst, nodes, edges); return true; });
|
|
143
|
+
|
|
144
|
+
// -- what the host asked for ---------------------------------------------------------------------------------------------------------------
|
|
145
|
+
/** What has been handed in, so an `update` that repeats a value changes nothing */
|
|
146
|
+
const serverless = !options.base && !options.fetch;
|
|
147
|
+
const current = { topology: undefined, proposal: null, source: null, slug: null, sha256: null, proposalView: null, shown: null, hasTopology: false, held: false };
|
|
148
|
+
|
|
149
|
+
const redraw = () => { proposalPiece.update(); changesPiece.update(); decisionPiece.update(); nodePanel.update(); };
|
|
150
|
+
|
|
151
|
+
/** The proposal asked for, opened (or closed) once there is a map to open it on */
|
|
152
|
+
function applyProposal() {
|
|
153
|
+
if (ended) return undefined;
|
|
154
|
+
const wanted = current.proposal;
|
|
155
|
+
if (wanted === null || wanted === undefined || wanted === '') {
|
|
156
|
+
current.held = false;
|
|
157
|
+
current.shown = null;
|
|
158
|
+
if (state.proposal) closeProposal(inst);
|
|
159
|
+
return undefined;
|
|
160
|
+
}
|
|
161
|
+
if (!current.hasTopology) { current.held = true; return undefined; } // a proposal is laid over a map: it opens when there is one
|
|
162
|
+
current.held = false;
|
|
163
|
+
const view = current.proposalView;
|
|
164
|
+
if (typeof wanted === 'string') {
|
|
165
|
+
const key = `${wanted}\u0000${current.source || ''}`;
|
|
166
|
+
if (current.shown === key && state.proposal) return undefined; // already open (the piece answers true too)
|
|
167
|
+
current.shown = key;
|
|
168
|
+
return proposalPiece.update({ proposal: wanted, source: current.source, view });
|
|
169
|
+
}
|
|
170
|
+
if (current.shown === wanted && state.proposal) return undefined;
|
|
171
|
+
current.shown = wanted;
|
|
172
|
+
// With no server to ask (no `base`, no `fetch`) the object is all there is: its name and source would only send the pieces to the host's own origin for a PR's checks and reviews
|
|
173
|
+
const named = serverless ? {} : { source: current.source, slug: current.slug, sha256: current.sha256 };
|
|
174
|
+
proposalPiece.update({ proposal: wanted, ...named, view });
|
|
175
|
+
return undefined;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/** The topology changed: the base map is the host's new one, laid out and fitted; an open proposal is laid over it again */
|
|
179
|
+
function applyTopology(topology) {
|
|
180
|
+
current.hasTopology = setTopology(inst, topology);
|
|
181
|
+
// A topology with nothing on it says so in words, never a blank box (no word before a topology is handed in: the host may still be loading it)
|
|
182
|
+
const empty = box.querySelector('.hx-review-empty');
|
|
183
|
+
empty.textContent = current.hasTopology ? '' : EMPTY_WORDS;
|
|
184
|
+
empty.hidden = current.hasTopology;
|
|
185
|
+
if (!current.hasTopology) { inst.map.render(); return; }
|
|
186
|
+
layoutMap(inst);
|
|
187
|
+
if (state.proposal) rebuildProposalMap(inst, undefined, { fit: true });
|
|
188
|
+
else mapPiece.fit();
|
|
189
|
+
inst.map.render();
|
|
190
|
+
inst.map.ensureFlowLoop();
|
|
191
|
+
if (current.held) applyProposal();
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/** The map's view (whole map or the data-flow lanes): laid out again, the camera fitted, a playing scenario ended (as the page's switch does) */
|
|
195
|
+
function setMapView(view) {
|
|
196
|
+
const next = view === 'dataflow' ? 'dataflow' : 'orbit';
|
|
197
|
+
if (state.view === next) return;
|
|
198
|
+
state.view = next;
|
|
199
|
+
inst.emit('scenario:clear');
|
|
200
|
+
inst.touchScene();
|
|
201
|
+
if (state.nodes.length) {
|
|
202
|
+
setMap(inst, state.mapNodes, state.mapEdges);
|
|
203
|
+
mapPiece.fit();
|
|
204
|
+
inst.map.ensureFlowLoop();
|
|
205
|
+
}
|
|
206
|
+
inst.emit('view', state.view);
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
/** The words of `view`: the proposal's (before, diff, after) or the map's (map, dataflow); the two sets do not meet */
|
|
210
|
+
function applyView(view) {
|
|
211
|
+
if (PROPOSAL_VIEWS.includes(view)) {
|
|
212
|
+
current.proposalView = view;
|
|
213
|
+
if (state.proposal) proposalPiece.update({ view });
|
|
214
|
+
} else if (MAP_VIEWS.includes(view)) setMapView(view);
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
function applyConfig(config) {
|
|
218
|
+
if (!config || typeof config !== 'object') return;
|
|
219
|
+
if ('layers' in config) setProjectLayers(inst, config.layers);
|
|
220
|
+
if (config.theme) mapPiece.applyTheme(config.theme);
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
/**
|
|
224
|
+
* Applies what changed in `next` (the options above). Only the keys present are looked at.
|
|
225
|
+
* @returns {Promise<boolean>|undefined} when a proposal is fetched: whether it opened
|
|
226
|
+
*/
|
|
227
|
+
function update(next = {}) {
|
|
228
|
+
if (ended) return undefined;
|
|
229
|
+
let again = false;
|
|
230
|
+
if ('strings' in next) { setStrings(inst, next.strings); applyStrings(inst, box); again = true; }
|
|
231
|
+
if ('config' in next) applyConfig(next.config);
|
|
232
|
+
if ('theme' in next) mapPiece.update({ theme: next.theme });
|
|
233
|
+
if ('checker' in next) changesPiece.update({ checker: next.checker });
|
|
234
|
+
if ('topology' in next && next.topology !== current.topology) { current.topology = next.topology; applyTopology(next.topology); }
|
|
235
|
+
let result;
|
|
236
|
+
const asked = ['proposal', 'source', 'slug', 'sha256'].some((k) => k in next);
|
|
237
|
+
if (asked) {
|
|
238
|
+
if ('source' in next) current.source = next.source || null;
|
|
239
|
+
if ('slug' in next) current.slug = next.slug || null;
|
|
240
|
+
if ('sha256' in next) current.sha256 = next.sha256 || null;
|
|
241
|
+
if ('proposal' in next) { current.proposal = next.proposal; current.shown = null; }
|
|
242
|
+
if ('view' in next && PROPOSAL_VIEWS.includes(next.view)) current.proposalView = next.view;
|
|
243
|
+
result = applyProposal();
|
|
244
|
+
}
|
|
245
|
+
if ('view' in next && !(asked && PROPOSAL_VIEWS.includes(next.view))) applyView(next.view);
|
|
246
|
+
if ('node' in next) mapPiece.update({ node: next.node });
|
|
247
|
+
if (again) redraw();
|
|
248
|
+
return result;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
/** Ends the piece: every piece in it, the box, and the instance if the piece made it. Safe to call twice. */
|
|
252
|
+
function destroy() {
|
|
253
|
+
if (ended) return;
|
|
254
|
+
ended = true;
|
|
255
|
+
stopAsking();
|
|
256
|
+
for (const piece of [decisionPiece, changesPiece, proposalPiece, nodePanel, mapPiece]) piece.destroy();
|
|
257
|
+
setPhoneBox(inst, null);
|
|
258
|
+
box.remove();
|
|
259
|
+
if (ownsInstance) inst.destroy();
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
// What was handed in at mount is applied as an update, in the order update() keeps (strings, theme and the checker were taken above)
|
|
263
|
+
const first = {};
|
|
264
|
+
for (const key of ['config', 'topology', 'proposal', 'source', 'slug', 'sha256', 'view', 'node']) if (options[key] !== undefined) first[key] = options[key];
|
|
265
|
+
update(first);
|
|
266
|
+
|
|
267
|
+
return {
|
|
268
|
+
inst,
|
|
269
|
+
elements: [box],
|
|
270
|
+
map: mapPiece,
|
|
271
|
+
proposal: proposalPiece,
|
|
272
|
+
changes: changesPiece,
|
|
273
|
+
decision: decisionPiece,
|
|
274
|
+
nodePanel,
|
|
275
|
+
update,
|
|
276
|
+
destroy,
|
|
277
|
+
/** The whole map in view */
|
|
278
|
+
fit: () => mapPiece.fit(),
|
|
279
|
+
};
|
|
280
|
+
}
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module explorer/pieces/work-agent
|
|
3
|
+
*
|
|
4
|
+
* The Start an agent dialog (a modal dialog over a scrim). Part of the Work piece (pieces/work.js): `install(ctx)` makes this part's functions for one mount, and hands the ones other parts call
|
|
5
|
+
* to `ctx.fn`; nothing is shared between two mounts.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { RUNS_URL, canRetry, retryRefs, retryWords, limitsFromFields, defaultLimits, LIMIT_KEYS, briefUrl, KINDS, aboutWords, startBody, startWords, confirmStartWords } from '../runs-model.js';
|
|
9
|
+
import { trapTab } from '../focusables.js';
|
|
10
|
+
import { option } from './work-common.js';
|
|
11
|
+
|
|
12
|
+
export function install(ctx) {
|
|
13
|
+
const { inst, ui, m, fn, root, $ } = ctx;
|
|
14
|
+
const { announce, t, trapFocus } = ctx.h;
|
|
15
|
+
|
|
16
|
+
const agentEl = () => $('agent-start');
|
|
17
|
+
|
|
18
|
+
/** While the dialog is open the focus cannot leave it */
|
|
19
|
+
function keepFocusInAgent(e) {
|
|
20
|
+
const el = agentEl();
|
|
21
|
+
if (ui.agent && el && !el.contains(inst.active())) $('agent-kind').focus(); // (the focus in the root's own tree: outside it, none)
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Opens the Start an agent dialog for `issue:<n>` or `proposal:<slug>`; the focus goes to the first field. The limit fields hold what the request
|
|
26
|
+
* starts from (the config's, for the profile). With `again` (a run that failed or was stopped) it is **Start again**: the same kind, refs,
|
|
27
|
+
* profile, brief and limits filled in, all editable, and the request will carry `retryOf`. `brief` is that run's whole brief when the list's was cut
|
|
28
|
+
*/
|
|
29
|
+
async function openAgent(ref, opener, again = null, brief = null) {
|
|
30
|
+
if (!agentEl() || ui.agent || ui.confirm) return; // one dialog at a time
|
|
31
|
+
const at = ref.indexOf(':');
|
|
32
|
+
const type = ref.slice(0, at);
|
|
33
|
+
const value = ref.slice(at + 1);
|
|
34
|
+
const refs = again ? retryRefs(again) : type === 'proposal' ? { proposal: value } : { issue: Number(value) };
|
|
35
|
+
ui.agent = { opener, refs, posting: false, retryOf: again ? again.runId : null };
|
|
36
|
+
// The profiles the config lists come with the runs: asked for if the Agents tab has not been opened yet
|
|
37
|
+
if (!ui.runs) { await fn.loadRuns(false); if (ui.kind === 'work') fn.paint(); }
|
|
38
|
+
if (!ui.agent) return;
|
|
39
|
+
const profiles = (ui.runs && ui.runs.data && ui.runs.data.profiles) || [];
|
|
40
|
+
$('agent-start-about').textContent = `About ${aboutWords(refs)}`;
|
|
41
|
+
fn.paintRunner('agent-start-runner', ui.runs && ui.runs.data);
|
|
42
|
+
const kind = again ? again.kind : 'code';
|
|
43
|
+
// The old run's profile stays on offer even if the config no longer lists it: the server then says so, in its words
|
|
44
|
+
const shown = again && again.profile && !profiles.includes(again.profile) ? [...profiles, again.profile] : profiles;
|
|
45
|
+
$('agent-kind').innerHTML = KINDS.map(([v, l]) => option(v, l, v === kind)).join('');
|
|
46
|
+
$('agent-profile').innerHTML = option('', 'No profile', !(again && again.profile)) + shown.map((p) => option(p, p, !!again && p === again.profile)).join('');
|
|
47
|
+
$('agent-profile-field').hidden = !shown.length;
|
|
48
|
+
$('agent-profile').value = again && again.profile ? again.profile : ''; // as well as `selected`, which not every DOM honours
|
|
49
|
+
$('agent-start-title').textContent = again ? t('startAgain') : t('startAgent');
|
|
50
|
+
const note = $('agent-retry-note');
|
|
51
|
+
note.hidden = !again;
|
|
52
|
+
note.textContent = again ? retryWords(again) : '';
|
|
53
|
+
fillLimits(again ? again.limits || {} : limitDefaultsNow());
|
|
54
|
+
$('agent-brief').value = brief ?? (again && typeof again.brief === 'string' ? again.brief : '');
|
|
55
|
+
$('agent-force').checked = false;
|
|
56
|
+
$('agent-force-field').hidden = true;
|
|
57
|
+
$('agent-start-msg').hidden = true;
|
|
58
|
+
$('agent-start-msg').textContent = '';
|
|
59
|
+
$('agent-start-words').textContent = confirmStartWords(refs, fn.forgeName());
|
|
60
|
+
const go = $('agent-start-go');
|
|
61
|
+
go.disabled = false;
|
|
62
|
+
go.removeAttribute('aria-busy');
|
|
63
|
+
go.textContent = fn.askRunnerWords();
|
|
64
|
+
m.agentTrap = trapFocus(keepFocusInAgent);
|
|
65
|
+
agentEl().hidden = false;
|
|
66
|
+
$('agent-kind').focus();
|
|
67
|
+
announce(`${again ? t('startAgain') : t('startAgent')} on ${aboutWords(refs)}. ${confirmStartWords(refs, fn.forgeName())}`);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** "Start again" on a run that failed or was stopped. A brief the list shows cut is read whole first: the dialog never starts from part of one */
|
|
71
|
+
async function startAgain(runId) {
|
|
72
|
+
const run = ui.runs && ui.runs.data ? ui.runs.data.runs.find((r) => r.runId === runId) : null;
|
|
73
|
+
if (!run || !canRetry(run) || ui.agent || ui.retrying) return;
|
|
74
|
+
let brief = null;
|
|
75
|
+
if (run.briefCut) {
|
|
76
|
+
ui.retrying = true;
|
|
77
|
+
const res = await fn.request(briefUrl(runId), false);
|
|
78
|
+
ui.retrying = false;
|
|
79
|
+
if (!res.ok || typeof res.body.brief !== 'string') {
|
|
80
|
+
ui.runNote = { text: `The brief of ${runId} could not be read, so Start again did not open: ${fn.failWords(res)}`, ok: false };
|
|
81
|
+
fn.paint();
|
|
82
|
+
announce(ui.runNote.text);
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
brief = res.body.brief;
|
|
86
|
+
}
|
|
87
|
+
const about = run.refs.proposal != null ? `proposal:${run.refs.proposal}` : `issue:${run.refs.issue ?? run.refs.thread}`;
|
|
88
|
+
openAgent(about, `[data-forge-retry="${runId}"]`, run, brief);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/** The limits the config gives a request under the chosen profile */
|
|
92
|
+
const limitDefaultsNow = () => defaultLimits(ui.runs && ui.runs.data && ui.runs.data.limits, $('agent-profile-field').hidden ? '' : $('agent-profile').value);
|
|
93
|
+
|
|
94
|
+
/** What the four limit fields hold, as text */
|
|
95
|
+
const limitFields = () => Object.fromEntries(LIMIT_KEYS.map((k) => [k, $(`agent-limit-${k}`).value]));
|
|
96
|
+
|
|
97
|
+
/** Fills the four limit fields (blank where `limits` has none) and remembers what was filled */
|
|
98
|
+
function fillLimits(limits) {
|
|
99
|
+
for (const k of LIMIT_KEYS) {
|
|
100
|
+
const field = $(`agent-limit-${k}`);
|
|
101
|
+
field.value = limits && limits[k] != null ? String(limits[k]) : '';
|
|
102
|
+
field.removeAttribute('aria-invalid');
|
|
103
|
+
field.removeAttribute('aria-describedby');
|
|
104
|
+
}
|
|
105
|
+
if (ui.agent) ui.agent.filled = JSON.stringify(limitFields());
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/** Another profile: its limits fill the fields, unless the person has typed in them */
|
|
109
|
+
function onAgentProfile() {
|
|
110
|
+
if (ui.agent && ui.agent.filled === JSON.stringify(limitFields())) fillLimits(limitDefaultsNow());
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/** Closes the dialog; the focus goes back to the button that opened it unless told not to */
|
|
114
|
+
function closeAgent({ restoreFocus = true } = {}) {
|
|
115
|
+
const el = agentEl();
|
|
116
|
+
if (!el || !ui.agent) return;
|
|
117
|
+
const { opener } = ui.agent;
|
|
118
|
+
ui.agent = null;
|
|
119
|
+
el.hidden = true;
|
|
120
|
+
if (m.agentTrap) { m.agentTrap(); m.agentTrap = null; }
|
|
121
|
+
if (!restoreFocus) return;
|
|
122
|
+
const back = root.querySelector(opener) || $('forge-title'); // the node panel's Start a run is an opener too
|
|
123
|
+
if (back && !back.disabled) back.focus();
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/** The one write: posts the choices once; a refusal stays in the dialog, in the server's words */
|
|
127
|
+
async function submitAgent(e) {
|
|
128
|
+
e.preventDefault();
|
|
129
|
+
if (!ui.agent || ui.agent.posting) return;
|
|
130
|
+
ui.agent.posting = true;
|
|
131
|
+
const go = $('agent-start-go');
|
|
132
|
+
go.disabled = true;
|
|
133
|
+
go.setAttribute('aria-busy', 'true');
|
|
134
|
+
go.textContent = 'Asking …';
|
|
135
|
+
$('agent-start-msg').hidden = true;
|
|
136
|
+
const again = ui.agent.retryOf;
|
|
137
|
+
const fields = limitFields();
|
|
138
|
+
const limits = limitsFromFields(fields);
|
|
139
|
+
// Each field that is not a number above zero is marked, and the first has the focus; the message says why
|
|
140
|
+
const wrong = LIMIT_KEYS.filter((k) => limitsFromFields({ [k]: fields[k] }) === null);
|
|
141
|
+
for (const k of LIMIT_KEYS) {
|
|
142
|
+
const field = $(`agent-limit-${k}`);
|
|
143
|
+
if (wrong.includes(k)) { field.setAttribute('aria-invalid', 'true'); field.setAttribute('aria-describedby', 'agent-start-msg'); } else { field.removeAttribute('aria-invalid'); field.removeAttribute('aria-describedby'); }
|
|
144
|
+
}
|
|
145
|
+
if (limits === null) {
|
|
146
|
+
ui.agent.posting = false;
|
|
147
|
+
go.disabled = false;
|
|
148
|
+
go.removeAttribute('aria-busy');
|
|
149
|
+
go.textContent = fn.askRunnerWords();
|
|
150
|
+
const bad = $('agent-start-msg');
|
|
151
|
+
bad.textContent = `A limit is a number above zero, or blank for the config's (${wrong.join(', ')}).`;
|
|
152
|
+
bad.hidden = false;
|
|
153
|
+
$(`agent-limit-${wrong[0]}`).focus();
|
|
154
|
+
announce(bad.textContent);
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
const res = await fn.post(RUNS_URL, startBody({
|
|
158
|
+
kind: $('agent-kind').value, profile: $('agent-profile-field').hidden ? '' : $('agent-profile').value, brief: $('agent-brief').value, refs: ui.agent.refs, force: $('agent-force').checked,
|
|
159
|
+
limits, ...(again ? { retryOf: again } : {}),
|
|
160
|
+
}));
|
|
161
|
+
if (!ui.agent) return;
|
|
162
|
+
ui.agent.posting = false;
|
|
163
|
+
const text = startWords(res.status, res.body);
|
|
164
|
+
if (res.ok) {
|
|
165
|
+
closeAgent();
|
|
166
|
+
ui.runNote = { text, ok: true };
|
|
167
|
+
announce(text);
|
|
168
|
+
await fn.loadRuns(false);
|
|
169
|
+
fn.paint();
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
go.disabled = false;
|
|
173
|
+
go.removeAttribute('aria-busy');
|
|
174
|
+
go.textContent = fn.askRunnerWords();
|
|
175
|
+
const msg = $('agent-start-msg');
|
|
176
|
+
msg.textContent = text;
|
|
177
|
+
msg.hidden = false;
|
|
178
|
+
// The one-per-issue rule can be set aside on purpose; the cap cannot
|
|
179
|
+
if (res.body && res.body.code === 'run-open') $('agent-force-field').hidden = false;
|
|
180
|
+
announce(text);
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/** Keys inside the dialog: Escape cancels, Tab stays inside, nothing reaches the map behind it */
|
|
184
|
+
function onAgentKey(e) {
|
|
185
|
+
e.stopPropagation();
|
|
186
|
+
if (e.key === 'Escape') {
|
|
187
|
+
e.preventDefault();
|
|
188
|
+
if (!ui.agent || !ui.agent.posting) closeAgent();
|
|
189
|
+
return;
|
|
190
|
+
}
|
|
191
|
+
trapTab(e, agentEl());
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
function onAgentClick(e) {
|
|
195
|
+
const t = e.target;
|
|
196
|
+
if (t === agentEl()) { if (ui.agent && !ui.agent.posting) closeAgent(); return; } // the scrim
|
|
197
|
+
if (t.closest && t.closest('[data-action="agent-start-cancel"]') && ui.agent && !ui.agent.posting) closeAgent();
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/** `?proposal=<slug>&start=1`: the Start dialog on that proposal (the proposal itself is opened by proposal.js) */
|
|
201
|
+
async function openProposalStart(slug, opener = '#forge-title') {
|
|
202
|
+
if (!ui.config || !agentEl()) return false;
|
|
203
|
+
await openAgent(`proposal:${slug}`, opener);
|
|
204
|
+
return !!ui.agent;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
/** Whether the Start dialog can open now: the server runs agents and the page has the dialog (the node panel's "Start a run" asks) */
|
|
208
|
+
const canStartAgent = () => !!(ui.config && ui.config.agents && agentEl());
|
|
209
|
+
|
|
210
|
+
Object.assign(fn, { agentEl, keepFocusInAgent, openAgent, startAgain, limitDefaultsNow, limitFields, fillLimits, onAgentProfile, closeAgent, submitAgent, onAgentKey, onAgentClick, openProposalStart, canStartAgent });
|
|
211
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module explorer/pieces/work-common
|
|
3
|
+
*
|
|
4
|
+
* What the parts of the Work piece (pieces/work.js and work-*.js) share and that holds nothing of one mount: words, small pure helpers, and the
|
|
5
|
+
* shape of the two forms' state. No instance, no page.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { escapeHtml as escHtml } from '../../core/text.js';
|
|
9
|
+
import { defaultFilters } from '../forge-panel-model.js';
|
|
10
|
+
import { withParts } from '../engine/piece.js';
|
|
11
|
+
|
|
12
|
+
export const FORGE_NAMES = { github: 'GitHub', forgejo: 'Forgejo' };
|
|
13
|
+
export const SEARCH_ANNOUNCE_MS = 500;
|
|
14
|
+
/** How often the runs are read again while one is open */
|
|
15
|
+
export const RUNS_POLL_MS = 60_000;
|
|
16
|
+
/** How often the specs are read again for the number while the page is open (spec 0010 D2: at most every 5 minutes; the server keeps what it read by PR head) */
|
|
17
|
+
export const SPECS_POLL_MS = 5 * 60_000;
|
|
18
|
+
/** The tabs, in the order of the loop */
|
|
19
|
+
export const TABS = ['specs', 'pulls', 'issues', 'threads', 'work', 'deploys'];
|
|
20
|
+
/** A node id that reads back as one mention: no brackets or line breaks, as core/mentions.js parses them */
|
|
21
|
+
export const MENTIONABLE = /^[^[\]\r\n]{1,200}$/;
|
|
22
|
+
|
|
23
|
+
export const plural = (n, word, more = `${word}s`) => `${n} ${n === 1 ? word : more}`;
|
|
24
|
+
/** A link only if it is the forge's web address: a forge's JSON is data, not trusted markup */
|
|
25
|
+
export const safeUrl = (u) => (typeof u === 'string' && /^https?:\/\//i.test(u) ? u : null);
|
|
26
|
+
export const option = (value, label, on) => `<option value="${escHtml(value)}"${on ? ' selected' : ''}>${escHtml(label)}</option>`;
|
|
27
|
+
/** The back control of a detail: an arrow and the name of the list it returns to ("All pull requests") */
|
|
28
|
+
export const backHtml = (action, words) => withParts(`<button data-corn="back" type="button" class="hx-forge-back" data-action="${action}"><svg width="14" height="14" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.6" aria-hidden="true"><path d="M10 3L5 8l5 5"/></svg><span class="hx-forge-back-text">${escHtml(words)}</span></button>`);
|
|
29
|
+
/** The thread a successful answer holds, or null (a failure, or an answer without one) */
|
|
30
|
+
export const threadOf = (res) => (res && res.ok && res.body && res.body.thread && typeof res.body.thread === 'object' && Array.isArray(res.body.thread.messages) ? res.body.thread : null);
|
|
31
|
+
|
|
32
|
+
/** The Release notes view: the draft loaded for a tag, and where the confirm step is */
|
|
33
|
+
export function freshNotes() {
|
|
34
|
+
return { since: '', data: null, loading: false, error: '', confirm: false, posting: false, message: '', bad: false, link: null };
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** The New idea form: whether it is open, one send in flight, and what the last send came to */
|
|
38
|
+
export function freshIdea() {
|
|
39
|
+
// `opener` is the id of the node whose panel button that opened the form ('' when the bar's own button did), `node` the node it was about
|
|
40
|
+
return { open: false, busy: false, message: '', bad: false, link: null, opener: '', node: null };
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** What is shown: the lists loaded, the filters, the selected pull request with its files and checks */
|
|
44
|
+
export function freshUi() {
|
|
45
|
+
return {
|
|
46
|
+
config: null,
|
|
47
|
+
open: false,
|
|
48
|
+
kind: 'specs', // the tab: specs | pulls | issues | threads | work (Runs) | deploys; 'notes' is the Release notes view, reached from the PRs list
|
|
49
|
+
filtersOpen: false, // the Filter chip's box
|
|
50
|
+
filters: defaultFilters(),
|
|
51
|
+
lists: {}, // `${kind}|${server state}` -> { items, at, rate, stale }
|
|
52
|
+
work: null, // { grouped, problem, at, rate, stale } of the Agents tab
|
|
53
|
+
specQuery: '', // the Specs tab's search (spec 0010 D5)
|
|
54
|
+
draftsOpen: null, // the Drafts group opened (true) or folded (false) by hand; null: as the model has it (folded past 10 rows)
|
|
55
|
+
workFilters: { agentsOnly: false, finished: false },
|
|
56
|
+
loading: false,
|
|
57
|
+
error: '',
|
|
58
|
+
selected: null, // the pull request's number
|
|
59
|
+
selectedOn: '', // the tab it was selected on ('pulls' or 'work')
|
|
60
|
+
detail: null, // { pull, files, checks, at, rate, stale } of the selected one
|
|
61
|
+
landing: null, // what waits to land on its approval for the selected pull request ({ slug, by, since }), or null
|
|
62
|
+
detailError: '',
|
|
63
|
+
lit: null, // litFor(detail, nodes)
|
|
64
|
+
thread: null, // the selected thread's number (Threads tab)
|
|
65
|
+
threadDetail: null, // { thread, at, rate, stale } of the selected one: its messages, as written
|
|
66
|
+
threadError: '',
|
|
67
|
+
litThread: null, // litForThread(thread, nodes)
|
|
68
|
+
idea: freshIdea(), // the New idea form
|
|
69
|
+
deploy: null, // the selected deploy's id; the deploy itself is `deployItem`
|
|
70
|
+
deployItem: null,
|
|
71
|
+
litDeploy: null, // litForDeploy(deployItem, nodes)
|
|
72
|
+
nodesSeen: null, // the `state.nodes` the lights were worked out for
|
|
73
|
+
busy: '', // the action in flight ('merge', or 'rerun:<check id>'), so a second click does nothing
|
|
74
|
+
note: null, // { text, ok }: what the last action came to, for the selected pull request
|
|
75
|
+
confirm: null, // { opener: selector, kind: 'merge' | 'spec' | 'build', plan?, n?, slug? } while the confirm dialog is open
|
|
76
|
+
actNote: null, // { text, ok, url }: what the last pipeline step came to
|
|
77
|
+
notes: freshNotes(), // the Release notes view
|
|
78
|
+
runs: null, // { data, error } of the Agents tab's runs: what /api/agent-runs answered
|
|
79
|
+
runNote: null, // { text, ok }: what the last Stop came to
|
|
80
|
+
runSel: null, // the run lit on the map (Light on the map), by id
|
|
81
|
+
runnerSaid: null, // the runner state last shown ('online', 'offline', 'none'; null off the pull transport), so a change is said once
|
|
82
|
+
runTimelines: new Set(), // the runs whose timeline is open
|
|
83
|
+
runReplies: new Map(), // the reply typed so far for each waiting run, so a repaint (the runs are looked at again) keeps it
|
|
84
|
+
agent: null, // { opener, refs, posting, retryOf, filled } while the Start an agent dialog is open
|
|
85
|
+
threadsOn: true, // `threads: false` in the config turns the Threads tab off
|
|
86
|
+
retrying: false, // a Start again reading its run's whole brief, so a second click does nothing
|
|
87
|
+
};
|
|
88
|
+
}
|