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,285 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module explorer/pieces/work
|
|
3
|
+
*
|
|
4
|
+
* The Work panel as a piece on the instance (spec 0011 D2 and D3; CF-07, CF-42, spec 0001 section 4, spec 0010): the Work button with its badge, the
|
|
5
|
+
* panel with its tabs (Specs, PRs, Issues, Threads, Runs, Deploys, and Release notes one level down on PRs), the two dialogs it opens (the confirm
|
|
6
|
+
* step and Start an agent) and the layer over the map that marks the nodes an open run is changing. What the panel shows, asks and does is the
|
|
7
|
+
* parts' (work-*.js, one module each); this file makes them for one mount, wires them to the instance, and ends them.
|
|
8
|
+
*
|
|
9
|
+
* mount(root, inst, { slots, config, clock }) -> { update, destroy, elements, ... }
|
|
10
|
+
* slots where cornfield's page leaves the places (`<!--corn-piece:work/button-->`, `work/panel`, `work/overlay`, `work/dialogs`); a host
|
|
11
|
+
* that gives none gets the four at the end of `root`
|
|
12
|
+
* config what `/cornfield/config.json` said: with no `forge`, or nobody signed in (`signIn`), the button and the panel stay hidden
|
|
13
|
+
* clock `() => ms`, for the times shown (tests)
|
|
14
|
+
* update({ config, clock }) the config arrived (or changed): the panel starts, or does not. `isOn()` says which.
|
|
15
|
+
* destroy() every listener, timer and poll ends, the elements go, an answer still on its way is not heard
|
|
16
|
+
*
|
|
17
|
+
* What it asks of the server (all through `credentialed(inst)`, served paths only; server/embed.js `ROUTES` and docs/embedding.md say which a listed origin
|
|
18
|
+
* may reach: of these only GET /proposals, GET /api/forge/pulls/<n> and POST /api/forge/pulls/<n>/landing/cancel, which the proposal bar uses too):
|
|
19
|
+
* GET /api/forge/{pulls,issues,threads}?state=<open|closed|all>&limit=100 GET /api/forge/deploys?limit=100 GET /api/forge/work
|
|
20
|
+
* GET /api/forge/pulls/<n> GET /api/forge/pulls/<n>/landing (approveLands) POST /api/forge/pulls/<n>/landing/cancel {}
|
|
21
|
+
* POST /api/forge/pulls/<n>/merge {sha, ...} POST /api/forge/pulls/<n>/rerun {sha, check} GET /api/forge/pulls/<n>/build?slug=<slug> POST /api/forge/pulls/<n>/build {digest, ...}
|
|
22
|
+
* GET /api/forge/issues/<n> GET /api/forge/issues/<n>/spec POST /api/forge/issues/<n>/spec {digest, ...}
|
|
23
|
+
* GET /api/forge/threads/<n> POST /api/forge/threads {title, body}
|
|
24
|
+
* GET /api/forge/release-notes[?since=<tag>] POST /api/forge/release-drafts {tag, since?}
|
|
25
|
+
* GET /api/agent-runs[?follow=1] POST /api/agent-runs {kind, refs, brief, profile?, limits?, force?, retryOf?} GET /api/agent-runs/<id>/brief
|
|
26
|
+
* POST /api/agent-runs/<id>/stop {} POST /api/agent-runs/<id>/answer {action: 'continue'|'stop'|'reply', text?}
|
|
27
|
+
* (and GET /proposals, which the engine reads for the Specs tab: engine/proposal.js)
|
|
28
|
+
*
|
|
29
|
+
* Events and asks (instance.js lists them): hears `work:open-specs` (ask, answers true), `forge:can-start` (ask) and `forge:start`, `thread:open`,
|
|
30
|
+
* `thread:start`, `threads:ensure`, `threads:index` (ask), `proposal:bar`, `decision`, `work:answer`, `work:on` (ask), `scene`; says `work:waiting {total}`,
|
|
31
|
+
* `work:available {on}`, `proposal:waiting`, `proposal:waiting-reset`, `runs:map {active}`, `threads:changed`, `announce`.
|
|
32
|
+
*/
|
|
33
|
+
|
|
34
|
+
import { place, scopeOf } from '../engine/piece.js';
|
|
35
|
+
import { markup } from './work-markup.js';
|
|
36
|
+
import { freshUi, RUNS_POLL_MS, SPECS_POLL_MS } from './work-common.js';
|
|
37
|
+
import { announce } from '../engine/keyboard.js';
|
|
38
|
+
import { t } from '../engine/strings.js';
|
|
39
|
+
import { isPhone, registerSheet, unregisterSheet, expandSheet, collapseSheet, showSheet, refreshStubs } from '../engine/sheets.js';
|
|
40
|
+
import { sayResult, clearResult, resultOf, showResultIn } from '../engine/feedback.js';
|
|
41
|
+
import { selectNode } from '../engine/selection.js';
|
|
42
|
+
import { toggleLayer } from '../engine/layers.js';
|
|
43
|
+
import { notSentWords } from '../engine/connection.js';
|
|
44
|
+
import * as P from '../engine/proposal.js';
|
|
45
|
+
import { isNodeVisible } from '../scene.js';
|
|
46
|
+
import { revealInStrip } from '../focus-room.js';
|
|
47
|
+
import { createRunsMap } from '../runs-map.js';
|
|
48
|
+
import { workButtonName } from '../waiting-model.js';
|
|
49
|
+
import { install as installData } from './work-data.js';
|
|
50
|
+
import { install as installSpecs } from './work-specs.js';
|
|
51
|
+
import { install as installPrs } from './work-prs.js';
|
|
52
|
+
import { install as installIssues } from './work-issues.js';
|
|
53
|
+
import { install as installThreads } from './work-threads.js';
|
|
54
|
+
import { install as installRuns } from './work-runs.js';
|
|
55
|
+
import { install as installDeploys } from './work-deploys.js';
|
|
56
|
+
import { install as installNotes } from './work-notes.js';
|
|
57
|
+
import { install as installConfirm } from './work-confirm.js';
|
|
58
|
+
import { install as installAgent } from './work-agent.js';
|
|
59
|
+
import { install as installPaint } from './work-paint.js';
|
|
60
|
+
import { install as installEvents } from './work-events.js';
|
|
61
|
+
|
|
62
|
+
export { markup, RUNS_POLL_MS, SPECS_POLL_MS };
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* @param {ParentNode} root where the elements go when the host names no place
|
|
66
|
+
* @param {ReturnType<typeof import('../instance.js').createInstance>} inst
|
|
67
|
+
* @param {{ slots?: Record<string, Node | null>, config?: object | null, clock?: () => number }} [options]
|
|
68
|
+
*/
|
|
69
|
+
export function mount(root, inst, options = {}) {
|
|
70
|
+
const scope = scopeOf(inst);
|
|
71
|
+
const mk = markup();
|
|
72
|
+
const slots = options.slots || {};
|
|
73
|
+
const made = [
|
|
74
|
+
...place(inst, root, mk.button, slots, 'button'),
|
|
75
|
+
...place(inst, root, mk.panel, slots, 'panel'),
|
|
76
|
+
...place(inst, root, mk.overlay, slots, 'overlay'),
|
|
77
|
+
...place(inst, root, mk.dialogs, slots, 'dialogs'),
|
|
78
|
+
];
|
|
79
|
+
const panelEl = made.find((el) => el.id === 'forge-panel');
|
|
80
|
+
scope.keepParts(...made);
|
|
81
|
+
|
|
82
|
+
// -- what the parts share: the state of this one panel, and the few things that are not functions ---------------------------------------
|
|
83
|
+
/** @type {Record<string, any>} */
|
|
84
|
+
const m = {
|
|
85
|
+
runsTimer: 0, threadToken: 0, indexToken: 0, indexLoading: false, indexCache: null, listToken: 0, pullToken: 0, notesToken: 0,
|
|
86
|
+
searchTimer: null, now: options.clock || (() => Date.now()), pageAway: false, specsTimer: 0, specsReading: false, primed: new Set(),
|
|
87
|
+
shownKey: '', shownKind: '', returnTo: null, openerEl: null, merged: { entries: null, items: [] }, redrawRuns: new Set(), agentTrap: null, confirmTrap: null,
|
|
88
|
+
};
|
|
89
|
+
const timers = new Set();
|
|
90
|
+
/** Timers that end with the piece, and do nothing once it has */
|
|
91
|
+
const setT = (f, ms) => { const id = setTimeout(() => { timers.delete(id); if (!ctx.dead) f(); }, ms); timers.add(id); return id; };
|
|
92
|
+
const clearT = (id) => { clearTimeout(id); timers.delete(id); };
|
|
93
|
+
scope.own(() => { for (const id of timers) clearTimeout(id); timers.clear(); });
|
|
94
|
+
const runsMap = createRunsMap(inst);
|
|
95
|
+
|
|
96
|
+
/** Each of the instance's modules, bound to this instance: the parts call these and never reach a page */
|
|
97
|
+
const h = {
|
|
98
|
+
announce: (text) => announce(inst, text),
|
|
99
|
+
t: (key) => t(inst, key),
|
|
100
|
+
isPhone: () => isPhone(inst),
|
|
101
|
+
registerSheet: (id, el, opts) => registerSheet(inst, id, el, opts),
|
|
102
|
+
expandSheet: (id) => expandSheet(inst, id),
|
|
103
|
+
collapseSheet: (id) => collapseSheet(inst, id),
|
|
104
|
+
showSheet: (id) => showSheet(inst, id),
|
|
105
|
+
refreshStubs: () => refreshStubs(inst),
|
|
106
|
+
render: () => { if (inst.map) inst.map.render(); },
|
|
107
|
+
touchScene: () => inst.touchScene(),
|
|
108
|
+
nodeById: (id) => inst.state.nodes.find((n) => n.id === id),
|
|
109
|
+
isNodeVisible: (node) => (inst.map ? inst.map.isNodeVisible(node) : isNodeVisible(inst.state, node)),
|
|
110
|
+
selectNode: (node, opts) => selectNode(inst, node, opts),
|
|
111
|
+
repaintThreads: () => inst.emit('threads:changed'),
|
|
112
|
+
toggleLayer: (key) => toggleLayer(inst, key),
|
|
113
|
+
sayResult: (key, text, ok) => sayResult(inst, key, text, ok),
|
|
114
|
+
clearResult: (key) => clearResult(inst, key),
|
|
115
|
+
resultOf: (key) => resultOf(inst, key),
|
|
116
|
+
showResultIn: (el, key) => showResultIn(inst, el, key),
|
|
117
|
+
isOffline: () => inst.offline(),
|
|
118
|
+
notSentWords: (what) => notSentWords(inst, what),
|
|
119
|
+
proposalListing: () => P.proposalListing(inst),
|
|
120
|
+
onProposalListing: (f) => P.onProposalListing(inst, f),
|
|
121
|
+
loadProposalList: () => P.loadProposalList(inst),
|
|
122
|
+
paintWaitingLine: (run, key) => inst.emit('proposal:waiting', { run, key }),
|
|
123
|
+
setRunsOnMap: (runs) => runsMap.set(runs),
|
|
124
|
+
clearRunsOnMap: () => runsMap.clear(),
|
|
125
|
+
setT,
|
|
126
|
+
clearT,
|
|
127
|
+
/**
|
|
128
|
+
* Keeps the focus in an open dialog: `keep` hears every focus that lands inside the instance's root, and, when the root is not the document
|
|
129
|
+
* (an element or a shadow root in a host's page), every focus that lands outside the root too, which the root never hears, unless it landed in
|
|
130
|
+
* another open modal dialog (a second instance's: two traps never pull the focus between them). Returns how to stop.
|
|
131
|
+
*/
|
|
132
|
+
trapFocus: (keep) => {
|
|
133
|
+
const offs = [scope.listen(ctx.root, 'focusin', keep)];
|
|
134
|
+
const inModal = (e) => (e.composedPath ? e.composedPath() : [e.target]).some((n) => n && n.nodeType === 1 && n.getAttribute('aria-modal') === 'true');
|
|
135
|
+
if (ctx.root !== inst.doc) offs.push(scope.own(inst.onPageFocus((e) => { if (!inst.active() && !inModal(e)) keep(e); })));
|
|
136
|
+
return () => offs.forEach((off) => off());
|
|
137
|
+
},
|
|
138
|
+
};
|
|
139
|
+
const ctx = { inst, ui: freshUi(), m, fn: {}, state: inst.state, root: inst.root || root, $: (id) => inst.el(id), scope, h, dead: false };
|
|
140
|
+
const { ui, fn } = ctx;
|
|
141
|
+
for (const install of [installData, installSpecs, installPrs, installIssues, installThreads, installRuns, installDeploys, installNotes, installConfirm, installAgent, installPaint, installEvents]) install(ctx);
|
|
142
|
+
|
|
143
|
+
// -- the panel starts once the config says there is a forge and somebody is signed in ---------------------------------------------------
|
|
144
|
+
let on = false;
|
|
145
|
+
// A piece mounted after the panel started asks rather than waits for `work:available` (the proposal piece hides its Proposals entry)
|
|
146
|
+
scope.on('work:on', () => on);
|
|
147
|
+
|
|
148
|
+
/** Starts the panel for `config`; with no forge in it, or nobody signed in, the button and the panel stay hidden. Returns whether it is on. */
|
|
149
|
+
function start(config) {
|
|
150
|
+
const panel = ctx.$('forge-panel');
|
|
151
|
+
if (!config || !config.forge || !config.signIn || !panel) return false;
|
|
152
|
+
ui.config = config;
|
|
153
|
+
const first = !on;
|
|
154
|
+
on = true;
|
|
155
|
+
for (const toggle of ctx.root.querySelectorAll('[data-action="toggle-forge"]')) toggle.hidden = false;
|
|
156
|
+
panel.hidden = false;
|
|
157
|
+
inst.emit('work:available', { on: true });
|
|
158
|
+
// `threads: false` in the config turns the tab off; a server that does not say has threads
|
|
159
|
+
const threadsOn = config.threads !== false;
|
|
160
|
+
const tab = panel.querySelector('[data-forge-kind="threads"]');
|
|
161
|
+
if (tab) tab.hidden = !threadsOn;
|
|
162
|
+
ui.threadsOn = threadsOn;
|
|
163
|
+
// On a phone Work is a sheet: it opens as a peek and displaces the node panel; folded to a stub it says its title and what waits on you (spec 0010 D7)
|
|
164
|
+
registerSheet(inst, 'forge', panel, {
|
|
165
|
+
stub: () => { const n = fn.waitingNow().total; return { title: h.t('issuesAndPrs'), badge: n ? String(n) : '', label: workButtonName(h.t('issuesAndPrs'), n, h.t) }; },
|
|
166
|
+
away: () => fn.closeForge({ restoreFocus: false }),
|
|
167
|
+
});
|
|
168
|
+
fn.paintFilters();
|
|
169
|
+
fn.paint();
|
|
170
|
+
// The map shows the open runs whether or not the panel is open: read them once now, and again now and then while any is open
|
|
171
|
+
if (config.agents && config.agents.runs) fn.loadRuns(false).then(() => { if (ui.kind === 'work') fn.paint(); }, () => {});
|
|
172
|
+
fn.readSpecsQuiet();
|
|
173
|
+
fn.syncSpecsPoll();
|
|
174
|
+
if (first) wire(panel);
|
|
175
|
+
return true;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/** The listeners, once: they end with the piece */
|
|
179
|
+
function wire(panel) {
|
|
180
|
+
// The specs part of what waits on you is read after a review is sent; the proposal bar says so when a run waits on the proposal it shows
|
|
181
|
+
scope.on('decision', ({ open }) => { if (open !== false) fn.readSpecsQuiet(); });
|
|
182
|
+
scope.on('proposal:bar', ({ open }) => fn.paintBarLine(open));
|
|
183
|
+
scope.on('work:answer', ({ run }) => { fn.answerFromBar(run); });
|
|
184
|
+
// A bad link's way on, and the node panel's "Start a run"
|
|
185
|
+
scope.on('work:open-specs', () => { fn.openForge({ tab: 'specs' }); return true; });
|
|
186
|
+
scope.on('forge:can-start', () => fn.canStartAgent());
|
|
187
|
+
scope.on('forge:start', ({ slug, returnTo }) => { fn.openProposalStart(slug, returnTo); });
|
|
188
|
+
// A node's panel lists the threads that mention it; a click there shows one in this panel
|
|
189
|
+
scope.on('threads:index', (nodeId) => (ui.config && ui.threadsOn ? { threads: fn.threadsFor(nodeId), forge: fn.forgeName(), start: true } : undefined));
|
|
190
|
+
scope.on('threads:ensure', () => { if (ui.config && ui.threadsOn) fn.ensureThreadsList(); });
|
|
191
|
+
scope.on('thread:open', ({ number }) => { if (ui.threadsOn) fn.openThread(number); });
|
|
192
|
+
scope.on('thread:start', ({ node }) => { if (ui.threadsOn && node) fn.startThread(node); });
|
|
193
|
+
// The map or the proposal changed the nodes: the lights follow them. The header's Proposals menu reads the same list: the Specs tab and its count follow
|
|
194
|
+
scope.on('scene', fn.onNodesChange);
|
|
195
|
+
scope.own(P.onProposalListing(inst, () => { fn.paintWaiting(); if (ui.open) fn.paint(); }));
|
|
196
|
+
scope.own(inst.onNetwork((offline) => { if (!offline) fn.readOnline(); })); // ends with the piece, not only with the instance
|
|
197
|
+
scope.own(inst.onPageHide(() => fn.onPageHide()));
|
|
198
|
+
scope.own(inst.onPageShow(() => fn.onPageShow()));
|
|
199
|
+
// Any `data-action="toggle-forge"` opens and closes the panel
|
|
200
|
+
scope.listen(ctx.root, 'click', (e) => {
|
|
201
|
+
const el = e.target.closest && e.target.closest('[data-action="toggle-forge"]');
|
|
202
|
+
if (!el) return;
|
|
203
|
+
m.openerEl = el;
|
|
204
|
+
fn.toggleForge();
|
|
205
|
+
});
|
|
206
|
+
// A control tabbed to inside the strip of tabs is brought fully into view, ring and all (focus-room.js)
|
|
207
|
+
scope.listen(ctx.root, 'focusin', (e) => { revealInStrip(e.target); });
|
|
208
|
+
const tabs = panel.querySelector('.hx-forge-tabs');
|
|
209
|
+
if (tabs) scope.listen(tabs, 'scroll', fn.paintTabsMore, { passive: true });
|
|
210
|
+
scope.own(inst.onResize(() => fn.paintTabsMore()));
|
|
211
|
+
// The strip's fade and the top's height follow their own size too: a phone's sheet expanding shows the tabs (they were not laid out in the
|
|
212
|
+
// peek), and a host's box resizes without the window doing so (F42)
|
|
213
|
+
const Observer = inst.win && inst.win.ResizeObserver;
|
|
214
|
+
const top = panel.querySelector('.hx-forge-top');
|
|
215
|
+
if (Observer && top && tabs) {
|
|
216
|
+
const seen = new Observer(() => { if (!ctx.dead) fn.paintTabsMore(); });
|
|
217
|
+
seen.observe(top);
|
|
218
|
+
seen.observe(tabs);
|
|
219
|
+
scope.own(() => seen.disconnect());
|
|
220
|
+
}
|
|
221
|
+
scope.listen(panel, 'click', fn.onClick);
|
|
222
|
+
scope.listen(panel, 'change', fn.onChange);
|
|
223
|
+
scope.listen(panel, 'input', fn.onInput);
|
|
224
|
+
scope.listen(panel, 'keydown', fn.onKey);
|
|
225
|
+
const agent = fn.agentEl();
|
|
226
|
+
if (agent) {
|
|
227
|
+
scope.listen(agent, 'click', fn.onAgentClick);
|
|
228
|
+
scope.listen(agent, 'keydown', fn.onAgentKey);
|
|
229
|
+
scope.listen(agent.querySelector('form'), 'submit', fn.submitAgent);
|
|
230
|
+
scope.listen(ctx.$('agent-profile'), 'change', fn.onAgentProfile);
|
|
231
|
+
}
|
|
232
|
+
const confirm = fn.confirmEl();
|
|
233
|
+
if (confirm) {
|
|
234
|
+
scope.listen(confirm, 'click', fn.onConfirmClick);
|
|
235
|
+
scope.listen(confirm, 'keydown', fn.onConfirmKey);
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
/** What the page tells the piece after it is mounted: the config (the panel starts), a clock */
|
|
240
|
+
function update(patch = {}) {
|
|
241
|
+
if (ctx.dead) return;
|
|
242
|
+
if (patch.clock) m.now = patch.clock;
|
|
243
|
+
if (patch.config !== undefined) start(patch.config);
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
function destroy() {
|
|
247
|
+
if (ctx.dead) return;
|
|
248
|
+
ctx.dead = true;
|
|
249
|
+
if (ui.confirm) fn.closeConfirm({ restoreFocus: false });
|
|
250
|
+
if (ui.agent) fn.closeAgent({ restoreFocus: false });
|
|
251
|
+
// What this panel lit and said goes with it
|
|
252
|
+
if (inst.state.forgeLit) inst.state.forgeLit = null;
|
|
253
|
+
runsMap.destroy();
|
|
254
|
+
inst.emit('proposal:waiting-reset');
|
|
255
|
+
inst.emit('work:waiting', { total: 0 });
|
|
256
|
+
if (on) inst.emit('work:available', { on: false }); // the account menu's Proposals entry is the way to the proposals again
|
|
257
|
+
try { unregisterSheet(inst, 'forge', false); } catch { /* it was never registered */ }
|
|
258
|
+
scope.destroy();
|
|
259
|
+
for (const el of made) el.remove();
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
if (options.config) update({ config: options.config });
|
|
263
|
+
|
|
264
|
+
return {
|
|
265
|
+
elements: made,
|
|
266
|
+
update,
|
|
267
|
+
destroy,
|
|
268
|
+
isOn: () => on,
|
|
269
|
+
isForgeOpen: () => ui.open,
|
|
270
|
+
openForge: (opts) => fn.openForge(opts),
|
|
271
|
+
closeForge: (opts) => fn.closeForge(opts),
|
|
272
|
+
toggleForge: () => fn.toggleForge(),
|
|
273
|
+
refreshForge: (opts) => fn.refreshForge(opts),
|
|
274
|
+
clearPull: () => fn.clearPull(),
|
|
275
|
+
clearDeploy: () => fn.clearDeploy(),
|
|
276
|
+
clearThread: () => fn.clearThread(),
|
|
277
|
+
selectDeploy: (id) => fn.selectDeploy(id),
|
|
278
|
+
openRunLink: (id) => fn.openRunLink(id),
|
|
279
|
+
openIssueLink: (n) => fn.openIssueLink(n),
|
|
280
|
+
openProposalStart: (slug, opener) => fn.openProposalStart(slug, opener),
|
|
281
|
+
canStartAgent: () => fn.canStartAgent(),
|
|
282
|
+
/** For tests: force reduced motion on or off for the runs' marks (null: follow the viewer's setting) */
|
|
283
|
+
setReducedMotion: (v) => runsMap.setReducedMotion(v),
|
|
284
|
+
};
|
|
285
|
+
}
|
package/explorer/proposal.js
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
* as a listener of the instance (one registration per hook: assigning again takes the last one back), so a chain that wraps `hooks.bar` still works:
|
|
10
10
|
*
|
|
11
11
|
* hooks.effective -> ask proposal:effective hooks.mark -> event proposal:mark hooks.beforeClose -> ask proposal:before-close
|
|
12
|
-
* hooks.closed -> event proposal {closed} hooks.bar -> event proposal:bar
|
|
12
|
+
* hooks.closed -> event proposal {closed} hooks.bar -> event proposal:bar
|
|
13
13
|
* hooks.reviewed -> event decision
|
|
14
14
|
*/
|
|
15
15
|
|
|
@@ -30,7 +30,6 @@ const ADAPT = {
|
|
|
30
30
|
beforeClose: (fn) => ['proposal:before-close', () => fn()],
|
|
31
31
|
closed: (fn) => ['proposal', ({ change }) => { if (change === 'closed') fn(); }],
|
|
32
32
|
bar: (fn) => ['proposal:bar', ({ open }) => { fn(open); }],
|
|
33
|
-
openSpecs: (fn) => ['work:open-specs', () => { fn(); return true; }],
|
|
34
33
|
reviewed: (fn) => ['decision', ({ open }) => { if (open !== false) fn(); }], // as before: not when another proposal was opened while it was sent
|
|
35
34
|
};
|
|
36
35
|
const kept = {};
|
package/explorer/runs-map.js
CHANGED
|
@@ -13,11 +13,8 @@
|
|
|
13
13
|
* state or a collision changes. The positions come from the scene the map just drew, so they follow every view, zoom and pan.
|
|
14
14
|
*/
|
|
15
15
|
|
|
16
|
-
import { state } from './state.js';
|
|
17
16
|
import { layerOn } from './layer-model.js';
|
|
18
|
-
import { render, onPaint } from './render.js';
|
|
19
17
|
import { overlayOf } from './runs-model.js';
|
|
20
|
-
import { flowReduceMotion } from './flows.js';
|
|
21
18
|
|
|
22
19
|
/** The most marks drawn at once: past this the Runs view still lists them all */
|
|
23
20
|
export const MAX_MARKS = 80;
|
|
@@ -25,113 +22,121 @@ export const MAX_MARKS = 80;
|
|
|
25
22
|
/** The key of the layer in the Layers menu and `state.activeLayers` */
|
|
26
23
|
export const RUNS_LAYER = 'runs';
|
|
27
24
|
|
|
28
|
-
/** @type {Map<string, HTMLElement>} the marks on the page by `<kind>:<node id>`, kept so a pulse is not restarted by every pan */
|
|
29
|
-
const marks = new Map();
|
|
30
|
-
let wired = false;
|
|
31
|
-
/** What the marks were last placed for: a paint with the same scene, camera, runs, layer and motion moves nothing (packet frames) */
|
|
32
|
-
let placed = '';
|
|
33
|
-
let placedFor = null;
|
|
34
|
-
let placedScene = null;
|
|
35
|
-
let placedLayer = null;
|
|
36
|
-
let reduce = null;
|
|
37
|
-
|
|
38
|
-
/** Whether motion is reduced: the page's setting, or a test's */
|
|
39
|
-
const reducedMotion = () => (reduce === null ? flowReduceMotion : reduce);
|
|
40
|
-
/** For tests: force reduced motion on or off (null: follow the page's setting) */
|
|
41
|
-
export function setReducedMotionForTests(on) { reduce = on; }
|
|
42
|
-
|
|
43
|
-
/** Whether the layer is on */
|
|
44
|
-
export const runsLayerOn = () => layerOn(state, RUNS_LAYER); // the viewer's layer, or the review's (layer-model.js)
|
|
45
|
-
|
|
46
|
-
/** Hands the map the runs the API listed: what pulses and what collides is worked out here, and the map is drawn again */
|
|
47
|
-
export function setRunsOnMap(runs) {
|
|
48
|
-
state.runsMap = Array.isArray(runs) && runs.length ? { ...overlayOf(runs), runs } : null;
|
|
49
|
-
wire();
|
|
50
|
-
paintLegend();
|
|
51
|
-
render();
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
/** Takes the marks off (the panel is reset, or there is no forge) */
|
|
55
|
-
export function clearRunsOnMap() {
|
|
56
|
-
state.runsMap = null;
|
|
57
|
-
clearMarks();
|
|
58
|
-
paintLegend();
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
function wire() {
|
|
62
|
-
if (wired) return;
|
|
63
|
-
wired = true;
|
|
64
|
-
onPaint((scene, camera) => syncRunOverlay(scene, camera));
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
function clearMarks() {
|
|
68
|
-
for (const el of marks.values()) el.remove();
|
|
69
|
-
marks.clear();
|
|
70
|
-
placed = '';
|
|
71
|
-
}
|
|
72
|
-
|
|
73
25
|
/** The words on a collision mark */
|
|
74
26
|
export const collisionTag = (n) => `Collision · ${n} runs`;
|
|
75
27
|
|
|
76
28
|
/**
|
|
77
|
-
*
|
|
78
|
-
*
|
|
79
|
-
* @param {{ nodes: { id: string, x: number, y: number, r: number, alpha: number }[] }} scene
|
|
80
|
-
* @param {{ x: number, y: number, zoom: number }} camera
|
|
29
|
+
* The runs' marks for one instance (spec 0011 D3): what the Work piece hands the map. Nothing here is shared with another instance.
|
|
30
|
+
* @param {ReturnType<import('./instance.js').createInstance>} inst
|
|
81
31
|
*/
|
|
82
|
-
export function
|
|
83
|
-
const
|
|
84
|
-
|
|
85
|
-
const
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
const
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
32
|
+
export function createRunsMap(inst) {
|
|
33
|
+
const { state } = inst;
|
|
34
|
+
/** @type {Map<string, HTMLElement>} the marks by `<kind>:<node id>`, kept so a pulse is not restarted by every pan */
|
|
35
|
+
const marks = new Map();
|
|
36
|
+
/** What the marks were last placed for: a paint with the same scene, camera, runs, layer and motion moves nothing (packet frames) */
|
|
37
|
+
let placed = '';
|
|
38
|
+
let placedFor = null;
|
|
39
|
+
let placedScene = null;
|
|
40
|
+
let placedLayer = null;
|
|
41
|
+
let reduce = null;
|
|
42
|
+
/** The map's paint hook while the marks follow it */
|
|
43
|
+
let offPaint = null;
|
|
44
|
+
|
|
45
|
+
/** Whether motion is reduced: the viewer's setting, or a test's */
|
|
46
|
+
const reducedMotion = () => (reduce === null ? inst.reducedMotion : reduce);
|
|
47
|
+
/** Whether the layer is on: the viewer's layer, or the review's (layer-model.js) */
|
|
48
|
+
const runsLayerOn = () => layerOn(state, RUNS_LAYER);
|
|
49
|
+
|
|
50
|
+
function clearMarks() {
|
|
51
|
+
for (const el of marks.values()) el.remove();
|
|
52
|
+
marks.clear();
|
|
53
|
+
placed = '';
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** Says whether any run is on the map: the Layers menu shows its legend while there is */
|
|
57
|
+
function paintLegend() {
|
|
58
|
+
inst.emit('runs:map', { active: !!(state.runsMap && (state.runsMap.flight.size || state.runsMap.collide.size)) });
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Puts the marks on the nodes the scene drew, at the camera. Marks are kept between frames (only their place changes), so a pan does not
|
|
63
|
+
* restart the pulse.
|
|
64
|
+
* @param {{ nodes: { id: string, x: number, y: number, r: number, alpha: number }[], version?: number }} scene
|
|
65
|
+
* @param {{ x: number, y: number, zoom: number }} camera
|
|
66
|
+
*/
|
|
67
|
+
function sync(scene, camera) {
|
|
68
|
+
const layer = inst.el('run-overlay');
|
|
69
|
+
if (!layer) return;
|
|
70
|
+
const map = state.runsMap;
|
|
71
|
+
if (!map || !runsLayerOn() || (!map.flight.size && !map.collide.size)) { if (marks.size) clearMarks(); layer.hidden = true; placed = ''; return; }
|
|
72
|
+
// The map paints every frame while packets move; the marks only move with the scene or the camera
|
|
73
|
+
const key = `${scene.version}|${camera.x}|${camera.y}|${camera.zoom}|${reducedMotion()}`;
|
|
74
|
+
if (key === placed && placedFor === map && placedScene === scene && placedLayer === layer) return;
|
|
75
|
+
placed = key;
|
|
76
|
+
placedLayer = layer;
|
|
77
|
+
placedFor = map;
|
|
78
|
+
placedScene = scene;
|
|
79
|
+
layer.hidden = false;
|
|
80
|
+
layer.classList.toggle('is-static', reducedMotion());
|
|
81
|
+
const seen = new Set();
|
|
82
|
+
let n = 0;
|
|
83
|
+
for (const node of scene.nodes) {
|
|
84
|
+
if (n >= MAX_MARKS) break;
|
|
85
|
+
const runs = map.collide.get(node.id) || map.flight.get(node.id);
|
|
86
|
+
if (!runs || !(node.alpha > 0.2)) continue;
|
|
87
|
+
const kind = map.collide.has(node.id) ? 'collision' : 'flight';
|
|
88
|
+
const key = `${kind}:${node.id}`;
|
|
89
|
+
n += 1;
|
|
90
|
+
seen.add(key);
|
|
91
|
+
let el = marks.get(key);
|
|
92
|
+
if (!el) {
|
|
93
|
+
el = inst.doc.createElement('span');
|
|
94
|
+
el.className = `hx-run-mark hx-run-mark--${kind}`;
|
|
95
|
+
el.dataset.node = node.id;
|
|
96
|
+
el.dataset.kind = kind;
|
|
97
|
+
el.dataset.corn = 'run-mark';
|
|
98
|
+
el.setAttribute('part', 'run-mark');
|
|
99
|
+
el.innerHTML = `<span class="hx-run-ring"></span>${kind === 'collision' ? `<span class="hx-run-tag"><span class="hx-run-sign">⚠</span> ${collisionTag(runs.length)}</span>` : ''}`;
|
|
100
|
+
layer.append(el);
|
|
101
|
+
marks.set(key, el);
|
|
102
|
+
}
|
|
103
|
+
const r = Math.max(10, (node.r + 9) * camera.zoom);
|
|
104
|
+
el.style.left = `${(node.x * camera.zoom + camera.x).toFixed(1)}px`;
|
|
105
|
+
el.style.top = `${(node.y * camera.zoom + camera.y).toFixed(1)}px`;
|
|
106
|
+
el.style.setProperty('--r', `${r.toFixed(1)}px`);
|
|
116
107
|
}
|
|
117
|
-
const
|
|
118
|
-
el.style.left = `${(node.x * camera.zoom + camera.x).toFixed(1)}px`;
|
|
119
|
-
el.style.top = `${(node.y * camera.zoom + camera.y).toFixed(1)}px`;
|
|
120
|
-
el.style.setProperty('--r', `${r.toFixed(1)}px`);
|
|
108
|
+
for (const [key, el] of marks) if (!seen.has(key)) { el.remove(); marks.delete(key); }
|
|
121
109
|
}
|
|
122
|
-
for (const [key, el] of marks) if (!seen.has(key)) { el.remove(); marks.delete(key); }
|
|
123
|
-
}
|
|
124
110
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
111
|
+
function clear() {
|
|
112
|
+
state.runsMap = null;
|
|
113
|
+
clearMarks();
|
|
114
|
+
paintLegend();
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/** Follows the map's paints: once, while the instance has a map (a bare root has none, and no marks) */
|
|
118
|
+
function wire() {
|
|
119
|
+
if (offPaint || !inst.map) return;
|
|
120
|
+
offPaint = inst.own(inst.map.onPaint((scene, camera) => sync(scene, camera)));
|
|
121
|
+
}
|
|
131
122
|
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
123
|
+
return {
|
|
124
|
+
/** Hands the map the runs the API listed: what pulses and what collides is worked out here, and the map is drawn again */
|
|
125
|
+
set(runs) {
|
|
126
|
+
state.runsMap = Array.isArray(runs) && runs.length ? { ...overlayOf(runs), runs } : null;
|
|
127
|
+
wire();
|
|
128
|
+
paintLegend();
|
|
129
|
+
if (inst.map) inst.map.render();
|
|
130
|
+
},
|
|
131
|
+
/** Takes the marks off (the panel ends, or there is no forge) */
|
|
132
|
+
clear,
|
|
133
|
+
/** Takes the marks off and stops following the map's paints: the piece that made this ends before the instance (a second one may follow) */
|
|
134
|
+
destroy() {
|
|
135
|
+
if (offPaint) { offPaint(); inst.release(offPaint); offPaint = null; }
|
|
136
|
+
clear();
|
|
137
|
+
},
|
|
138
|
+
sync,
|
|
139
|
+
/** For tests: force reduced motion on or off (null: follow the viewer's setting) */
|
|
140
|
+
setReducedMotion(on) { reduce = on; },
|
|
141
|
+
};
|
|
137
142
|
}
|
package/explorer/runs-view.js
CHANGED
|
@@ -92,15 +92,16 @@ function resultHtml(ctx, run) {
|
|
|
92
92
|
|
|
93
93
|
/** A waiting run: what was asked (the note and link are shown above) and the three answers, plain buttons and a reply field */
|
|
94
94
|
function answerHtml(ctx, run) {
|
|
95
|
+
const say = ctx.t || t; // the words of the instance that draws it (the Work piece hands its own), else the page's
|
|
95
96
|
const id = ctx.esc(run.runId);
|
|
96
97
|
const name = ctx.esc(runName(run, ctx.now));
|
|
97
98
|
const off = ctx.busy ? ' disabled' : '';
|
|
98
99
|
const reply = ctx.replies && ctx.replies.get(run.runId) || '';
|
|
99
100
|
return `${run.answer ? answeredHtml(ctx, run) : ''}<div class="hx-run-actions" data-corn="run-actions" role="group" aria-label="Answer: ${name}">
|
|
100
|
-
<button data-corn-kind="secondary" type="button" class="hx-btn hx-forge-act" data-run-answer="continue" data-run-id="${id}" aria-label="${ctx.esc(
|
|
101
|
-
<button type="button" class="hx-btn hx-forge-act" data-run-answer="stop" data-run-id="${id}" aria-label="${ctx.esc(
|
|
101
|
+
<button data-corn-kind="secondary" type="button" class="hx-btn hx-forge-act" data-run-answer="continue" data-run-id="${id}" aria-label="${ctx.esc(say('continueRun'))}: ${name}"${off}>${ctx.esc(say('continueRun'))}</button>
|
|
102
|
+
<button type="button" class="hx-btn hx-forge-act" data-run-answer="stop" data-run-id="${id}" aria-label="${ctx.esc(say('stop'))}: ${name}"${off} data-corn-kind="danger">${ctx.esc(say('stop'))}</button></div>
|
|
102
103
|
<label class="hx-forge-field" data-corn="field">Reply to ${ctx.esc(`${run.kind} on ${aboutWords(run.refs)}`)}<input data-corn="control" type="text" class="hx-forge-input" data-run-reply="${id}" value="${ctx.esc(reply)}" maxlength="4000" autocomplete="off" /></label>
|
|
103
|
-
<div class="hx-run-actions" data-corn="run-actions"><button data-corn-kind="secondary" type="button" class="hx-btn hx-forge-act" data-run-answer="reply" data-run-id="${id}" aria-label="${ctx.esc(
|
|
104
|
+
<div class="hx-run-actions" data-corn="run-actions"><button data-corn-kind="secondary" type="button" class="hx-btn hx-forge-act" data-run-answer="reply" data-run-id="${id}" aria-label="${ctx.esc(say('reply'))}: ${name}"${off}>${ctx.esc(say('reply'))}</button></div>`;
|
|
104
105
|
}
|
|
105
106
|
|
|
106
107
|
/**
|
|
@@ -141,6 +142,7 @@ export function loadingLinesHtml(n = 1) {
|
|
|
141
142
|
|
|
142
143
|
/** One run */
|
|
143
144
|
export function runHtml(ctx, run, all) {
|
|
145
|
+
const say = ctx.t || t;
|
|
144
146
|
const lit = ctx.selected === run.runId;
|
|
145
147
|
const open = ctx.timelines.has(run.runId);
|
|
146
148
|
const why = statusWhy(run);
|
|
@@ -148,8 +150,8 @@ export function runHtml(ctx, run, all) {
|
|
|
148
150
|
const note = run.report && run.report.note ? `<p class="hx-forge-meta">Runner: ${ctx.esc(run.report.note)}</p>` : '';
|
|
149
151
|
const answering = canAnswer(run);
|
|
150
152
|
const off = ctx.busy ? ' disabled' : '';
|
|
151
|
-
const retry = canRetry(run) ? `<button data-corn-kind="secondary" type="button" class="hx-btn hx-forge-act" data-forge-retry="${ctx.esc(run.runId)}" aria-label="${ctx.esc(
|
|
152
|
-
const stop = canStop(run) && !answering ? `<button type="button" class="hx-btn hx-forge-act" data-forge-stop="${ctx.esc(run.runId)}" aria-label="${ctx.esc(
|
|
153
|
+
const retry = canRetry(run) ? `<button data-corn-kind="secondary" type="button" class="hx-btn hx-forge-act" data-forge-retry="${ctx.esc(run.runId)}" aria-label="${ctx.esc(say('startAgain'))}: ${name}"${off}>${ctx.esc(say('startAgain'))}</button>` : '';
|
|
154
|
+
const stop = canStop(run) && !answering ? `<button type="button" class="hx-btn hx-forge-act" data-forge-stop="${ctx.esc(run.runId)}" aria-label="${ctx.esc(say('stop'))}: ${name}"${off} data-corn-kind="danger">${ctx.esc(say('stop'))}</button>` : '';
|
|
153
155
|
const names = nodeLabels(run.nodes, ctx.nodes);
|
|
154
156
|
const collision = collisionWords(run, all, ctx.nodes);
|
|
155
157
|
const limits = limitRows(run);
|
|
@@ -182,7 +184,7 @@ export function runHtml(ctx, run, all) {
|
|
|
182
184
|
* @param {object[]} runs
|
|
183
185
|
*/
|
|
184
186
|
export function runsHtml(ctx, runs) {
|
|
185
|
-
return runGroups(runs).map((group) => runGroupHeadingHtml(group) + group.items.map((g) => {
|
|
187
|
+
return runGroups(runs).map((group) => runGroupHeadingHtml(group, ctx.t) + group.items.map((g) => {
|
|
186
188
|
if (g.kind === 'run') return runHtml(ctx, g.run, runs);
|
|
187
189
|
const id = `cmp-${g.runs[0].runId}`;
|
|
188
190
|
return `<li class="hx-run-group" data-key="${ctx.esc(id)}"><section class="hx-run-compare" aria-labelledby="${ctx.esc(id)}">
|
package/explorer/strings.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* A bridge (spec 0011 D2, step 4): the words now live on the instance (`inst.strings`, read with `t(inst, key)` from engine/strings.js).
|
|
5
5
|
* This file keeps the old names for the modules that are not yet on an instance, bound to the page's voice: `pageStrings`, the object the page
|
|
6
6
|
* instance's `strings` is (state.js hands it over), so the two are one. It imports nothing of the page's state, because pure models read the words
|
|
7
|
-
* through it (waiting-model.js) and the converted modules import those. It goes when the last caller (
|
|
7
|
+
* through it (waiting-model.js) and the converted modules import those. It goes when the last caller (proposal.js, review.js,
|
|
8
8
|
* review-column.js, whatif.js, scenario-ui.js, runs-view.js, waiting-*.js, plugins.js) is converted.
|
|
9
9
|
*/
|
|
10
10
|
import * as S from './engine/strings.js';
|