@popcorn245/cornfield 0.50.0 → 0.51.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.
Files changed (67) hide show
  1. package/explorer/camera-frame.js +82 -0
  2. package/explorer/camera.js +7 -73
  3. package/explorer/check-model.js +3 -44
  4. package/explorer/cloud-model.js +2 -101
  5. package/explorer/cloud-panel.js +107 -0
  6. package/explorer/css/review.css +2 -0
  7. package/explorer/engine/connection.js +4 -1
  8. package/explorer/engine/map-rect.js +97 -0
  9. package/explorer/engine/player.js +2 -1
  10. package/explorer/engine/proposal.js +28 -7
  11. package/explorer/engine/server-load.js +64 -0
  12. package/explorer/engine/sheets.js +4 -86
  13. package/explorer/engine/source-address.js +58 -0
  14. package/explorer/engine/source.js +16 -45
  15. package/explorer/engine/theme-sheet.js +23 -1
  16. package/explorer/engine/topology.js +1 -1
  17. package/explorer/focus-room.js +1 -7
  18. package/explorer/focusables.js +1 -1
  19. package/explorer/forge-panel.js +36 -2630
  20. package/explorer/index.html +15 -147
  21. package/explorer/instance-state.js +0 -7
  22. package/explorer/instance.js +19 -2
  23. package/explorer/layer-model.js +1 -1
  24. package/explorer/outage-model.js +6 -76
  25. package/explorer/outage-scenario.js +83 -0
  26. package/explorer/page-pieces.js +21 -2
  27. package/explorer/page.js +3 -3
  28. package/explorer/panels.js +1 -5
  29. package/explorer/pieces/layers.js +1 -0
  30. package/explorer/pieces/node-panel.js +19 -8
  31. package/explorer/pieces/proposal.js +9 -0
  32. package/explorer/pieces/review-source.js +84 -0
  33. package/explorer/pieces/review.js +145 -12
  34. package/explorer/pieces/scope.js +23 -54
  35. package/explorer/pieces/status.js +5 -1
  36. package/explorer/pieces/work-agent.js +211 -0
  37. package/explorer/pieces/work-common.js +88 -0
  38. package/explorer/pieces/work-confirm.js +169 -0
  39. package/explorer/pieces/work-data.js +178 -0
  40. package/explorer/pieces/work-deploys.js +104 -0
  41. package/explorer/pieces/work-events.js +285 -0
  42. package/explorer/pieces/work-issues.js +43 -0
  43. package/explorer/pieces/work-markup.js +155 -0
  44. package/explorer/pieces/work-notes.js +177 -0
  45. package/explorer/pieces/work-paint.js +312 -0
  46. package/explorer/pieces/work-prs.js +253 -0
  47. package/explorer/pieces/work-runs.js +387 -0
  48. package/explorer/pieces/work-specs.js +71 -0
  49. package/explorer/pieces/work-threads.js +309 -0
  50. package/explorer/pieces/work.js +285 -0
  51. package/explorer/proposal-marks.js +220 -0
  52. package/explorer/proposal-model.js +23 -211
  53. package/explorer/proposal.js +1 -2
  54. package/explorer/runs-map.js +108 -103
  55. package/explorer/runs-view.js +8 -6
  56. package/explorer/scenario.js +2 -1
  57. package/explorer/scene.js +2 -2
  58. package/explorer/selection-model.js +2 -42
  59. package/explorer/selection-view.js +1 -1
  60. package/explorer/selection-words.js +52 -0
  61. package/explorer/strings.js +1 -1
  62. package/explorer/verdict-paint.js +51 -0
  63. package/explorer/waiting-model.js +12 -12
  64. package/explorer/waiting-view.js +6 -6
  65. package/package.json +1 -1
  66. package/explorer/feedback.js +0 -15
  67. package/explorer/waiting-line.js +0 -14
@@ -0,0 +1,104 @@
1
+ /**
2
+ * @module explorer/pieces/work-deploys
3
+ *
4
+ * The Deploys tab: the list and a deploy's detail, lit on the map. 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 { withParts } from '../engine/piece.js';
9
+ import { litForDeploy, nodesForRestarts, deployWords, deployMeta } from '../forge-panel-model.js';
10
+ import { cornStateAttr, markStateAttr, stateIconHtml } from '../corn-state.js';
11
+ import { layerOn } from '../layer-model.js';
12
+ import { LAYER_DEFS } from '../engine/layers.js';
13
+ import { escapeHtml as escHtml } from '../../core/text.js';
14
+ import { plural, safeUrl, backHtml } from './work-common.js';
15
+
16
+ export function install(ctx) {
17
+ const { ui, m, fn, state, $ } = ctx;
18
+ const { announce, render, touchScene, isNodeVisible, toggleLayer } = ctx.h;
19
+
20
+ /** Selects a deploy: nothing to ask (the list holds what it restarted), so its nodes light at once */
21
+ function selectDeploy(id) {
22
+ const found = ui.lists.deploys && ui.lists.deploys.items.find((d) => d.id === id);
23
+ if (!found) return;
24
+ m.pullToken++;
25
+ fn.dropThread();
26
+ ui.selected = null;
27
+ ui.detail = null;
28
+ ui.detailError = '';
29
+ ui.lit = null;
30
+ ui.deploy = id;
31
+ ui.deployItem = found;
32
+ // A container, a stack or a machine is on a layer that starts off: the layers the deploy's nodes are on come on, or nothing would light
33
+ const turnedOn = [];
34
+ for (const n of litForDeploy(found, state.nodes).nodes) {
35
+ const layer = LAYER_DEFS.find((l) => l.key === n.type);
36
+ if (layer && !layerOn(state, layer.key)) { toggleLayer(layer.key); turnedOn.push(layer.label); }
37
+ }
38
+ fn.relight();
39
+ $('forge-panel').querySelector('.hx-forge-body').scrollTop = 0; // the deploy's nodes are what was asked for, not the row that was tapped
40
+ announce(deploySelectionWords(turnedOn));
41
+ }
42
+
43
+ /** Lets go of the selected deploy: nothing is lit any more */
44
+ function clearDeploy() {
45
+ const had = ui.deployItem;
46
+ ui.deploy = null;
47
+ ui.deployItem = null;
48
+ ui.litDeploy = null;
49
+ state.forgeLit = null;
50
+ touchScene();
51
+ render();
52
+ fn.paint();
53
+ if (had) announce(`Deploy ${had.name} cleared`);
54
+ }
55
+
56
+ /** What a deploy lights, said short, for its row: how many nodes, or that it is not mapped */
57
+ function lightsWords(deploy) {
58
+ if (!deploy.restarts.length) return 'Not mapped to a node';
59
+ const { nodes } = nodesForRestarts(deploy.restarts, state.nodes);
60
+ return nodes.length ? `Lights ${plural(nodes.length, 'node')}` : 'Names nodes not on the map';
61
+ }
62
+
63
+ function deployHtml(d) {
64
+ const link = safeUrl(d.url);
65
+ const out = link ? `<a data-corn="out-link" class="hx-forge-out" href="${escHtml(link)}" target="_blank" rel="noreferrer" aria-label="Open deploy ${escHtml(d.name)} on ${escHtml(fn.forgeName())} (new tab)">↗</a>` : '';
66
+ return `<li class="hx-forge-item"><button type="button" class="hx-forge-row" data-forge-deploy="${escHtml(d.id)}" aria-pressed="${ui.deploy === d.id}" data-corn="row">
67
+ <span class="hx-forge-title">${escHtml(d.name)}${d.title && d.title !== d.name ? `<span class="hx-faint"> · ${escHtml(d.title)}</span>` : ''}</span>
68
+ <span class="hx-forge-meta"><span class="hx-forge-state hx-forge-state--${escHtml(d.state)}" data-corn="state-pill"${cornStateAttr(d.state)}>${stateIconHtml(d.state)}${escHtml(deployWords(d))}</span> ${escHtml(deployMeta(d, m.now()))}</span>
69
+ <span class="hx-forge-labels"><span class="hx-forge-label" data-corn="tag">${escHtml(lightsWords(d))}</span></span></button>${out}</li>`;
70
+ }
71
+
72
+ /** The selected deploy: what it was, and the nodes it restarted (each a button that selects it on the map) */
73
+ function deployDetailHtml() {
74
+ const d = ui.deployItem;
75
+ const lit = ui.litDeploy;
76
+ const url = safeUrl(d.url);
77
+ const head = `${backHtml('clear-forge-deploy', 'All deploys')}<h3 class="hx-forge-detail-title" data-corn="detail-title">${escHtml(d.name)}</h3>
78
+ <p class="hx-forge-meta"><span class="hx-forge-state hx-forge-state--${escHtml(d.state)}" data-corn="state-pill"${cornStateAttr(d.state)}>${stateIconHtml(d.state)}${escHtml(deployWords(d))}</span> ${escHtml(deployMeta(d, m.now()))}${url ? ` · <a data-corn="text-link" class="hx-link" href="${escHtml(url)}" target="_blank" rel="noreferrer">Open on ${escHtml(fn.forgeName())} ↗</a>` : ''}</p>`;
79
+ const stale = ui.lists.deploys && ui.lists.deploys.stale;
80
+ let body;
81
+ if (!d.restarts.length) {
82
+ body = '<p class="hx-forge-notice" data-corn="notice">No node is mapped to this deploy, so nothing is lit. Say what it restarts under <code class="hx-code">deploys.restarts</code> in cornfield.config.js (docs/deploys.md).</p>';
83
+ } else {
84
+ const rows = lit.nodes.map((n) => `<li class="hx-forge-file" data-corn="file"><button data-corn="node-chip" type="button" class="hx-forge-node" data-forge-node="${escHtml(n.id)}" aria-label="Show ${escHtml(n.label)} on the map${isNodeVisible(n) ? '' : ' (its layer is off)'}">${escHtml(n.label)}${isNodeVisible(n) ? '' : ' · layer off'}</button> <span class="hx-faint">${escHtml(n.type)}</span></li>`).join('');
85
+ const missing = lit.missing.length ? `<p class="hx-forge-notice" data-corn="notice">${escHtml(lit.missing.join(', '))} ${lit.missing.length === 1 ? 'is' : 'are'} named in the config but not on the map.</p>` : '';
86
+ const key = lit.nodes.length ? `<p class="hx-forge-key hx-faint"><span class="hx-mark-dot hx-mark-dot--${d.state === 'failure' ? 'removed' : 'changed'}" data-corn="mark-dot"${markStateAttr(d.state === 'failure' ? 'removed' : 'changed')} aria-hidden="true"></span>${d.state === 'failure' ? 'restarted by a deploy that failed' : 'restarted by this deploy'}</p>` : '';
87
+ body = `<h4 class="hx-forge-sub">${escHtml(`Restarted: ${plural(lit.nodes.length, 'node')} on the map`)}</h4>${key}${rows ? `<ul class="hx-forge-files">${rows}</ul>` : ''}${missing}`;
88
+ }
89
+ return `${head}${stale ? `<p class="hx-forge-notice" data-corn="notice">${escHtml(`This is an older answer. ${stale}`)}</p>` : ''}${body}`;
90
+ }
91
+
92
+ /** What a screen reader hears when a deploy is selected */
93
+ function deploySelectionWords(turnedOn = []) {
94
+ const { name, branch } = ui.deployItem;
95
+ const lit = ui.litDeploy;
96
+ const head = `Deploy ${name}${branch ? ` of ${branch}` : ''}, ${deployWords(ui.deployItem).toLowerCase()}`;
97
+ if (!ui.deployItem.restarts.length) return `${head}. No node is mapped to it, so nothing is lit.`;
98
+ const layers = turnedOn.length ? ` Turned on the ${turnedOn.join(' and ')} ${turnedOn.length === 1 ? 'layer' : 'layers'}.` : '';
99
+ return `${head}: ${plural(lit.nodes.length, 'node')} restarted and lit${lit.missing.length ? `, ${lit.missing.length} named that ${lit.missing.length === 1 ? 'is' : 'are'} not on the map` : ''}.${layers}`;
100
+ }
101
+
102
+ // what other parts put in the panel gets its parts (a hook is a part of the same name)
103
+ Object.assign(fn, { selectDeploy, clearDeploy, lightsWords, deployHtml: (...a) => withParts(deployHtml(...a)), deployDetailHtml: (...a) => withParts(deployDetailHtml(...a)), deploySelectionWords });
104
+ }
@@ -0,0 +1,285 @@
1
+ /**
2
+ * @module explorer/pieces/work-events
3
+ *
4
+ * Opening and closing the panel, and what a click, a change, an input and a key in it do. 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 { workStatus } from '../agents-model.js';
9
+ import { defaultFilters, filterItems } from '../forge-panel-model.js';
10
+ import { waiting, specGroups } from '../waiting-model.js';
11
+ import { plural, TABS, SEARCH_ANNOUNCE_MS } from './work-common.js';
12
+
13
+ export function install(ctx) {
14
+ const { inst, ui, m, fn, state, $ } = ctx;
15
+ const { announce, t, isPhone, expandSheet, collapseSheet, showSheet, nodeById, selectNode, clearResult, resultOf, showResultIn, setT, clearT } = ctx.h;
16
+
17
+ const isForgeOpen = () => ui.open;
18
+
19
+ /**
20
+ * Opens the panel with the focus on its title; the first time, loads what its tab shows (the proposals, to start with).
21
+ * `tab` opens it on that tab ('specs', 'pulls', 'issues', 'threads', 'work' for Runs, 'deploys'), whichever was shown last otherwise.
22
+ */
23
+ function openForge({ load = true, tab } = {}) {
24
+ const panel = $('forge-panel');
25
+ if (!panel || panel.hidden) return;
26
+ if (tab && tab !== (ui.kind === 'notes' ? 'pulls' : ui.kind) && TABS.includes(tab)) { // the Release notes are one level down on PRs
27
+ ui.kind = tab;
28
+ ui.filters = defaultFilters(tab);
29
+ ui.actNote = null;
30
+ } else if (!tab && load && !ui.open) {
31
+ // Opened by a toggle: on the tab with the oldest thing waiting on you, else the tab used last (spec 0010 D2)
32
+ const oldest = fn.waitingNow().oldest;
33
+ if (oldest && oldest !== ui.kind) {
34
+ ui.kind = oldest;
35
+ ui.filters = defaultFilters(oldest);
36
+ ui.actNote = null;
37
+ fn.paintFilters();
38
+ }
39
+ }
40
+ ui.open = true;
41
+ panel.inert = false;
42
+ panel.classList.add('forge-open');
43
+ if (isPhone()) { showSheet('forge'); if (tab) expandSheet('forge'); } // a peek; only a link that names a tab (a deep link, "Open the Specs list") opens it expanded
44
+ fn.paintButton();
45
+ const title = $('forge-title');
46
+ title.focus();
47
+ announce('Work');
48
+ if (!load) return; // a deep link loads the list it wants itself (openTab)
49
+ if (!tab) fn.primeCounts(); // opened by a toggle, not for a tab: the other tabs' counts are read quietly
50
+ if (ui.kind === 'notes') { if (!ui.notes.data && !ui.notes.loading) fn.loadNotes(); else fn.paint(); return; }
51
+ if (ui.kind === 'specs' || !fn.current()) { fn.paintFilters(); fn.loadList(); } else fn.paint();
52
+ }
53
+
54
+ /** Shows `tab` in the panel, opened (and, on a phone, expanded), with its list read; resolves when the list is in */
55
+ async function openTab(tab) {
56
+ ui.kind = tab;
57
+ ui.filters = defaultFilters(tab); // a filter left from before must not hide what the link names
58
+ ui.actNote = null;
59
+ fn.paintFilters();
60
+ if (!ui.open) openForge({ load: false });
61
+ if (isPhone()) expandSheet('forge');
62
+ if (fn.current()) fn.paint(); else await fn.loadList();
63
+ }
64
+
65
+ /** What a link names is not there: a line in the panel, said through the live region */
66
+ function linkMissing(words) {
67
+ ui.actNote = { ok: false, text: words };
68
+ fn.paint();
69
+ announce(words);
70
+ return false;
71
+ }
72
+
73
+ /** Moves the focus to `el` (made focusable if it is a row) and brings it into view */
74
+ function bringIntoView(el) {
75
+ if (!el) return;
76
+ if (!el.matches('button, a, input, select, textarea')) el.setAttribute('tabindex', '-1');
77
+ el.focus();
78
+ if (typeof el.scrollIntoView === 'function') el.scrollIntoView({ block: 'nearest' });
79
+ }
80
+
81
+ /** Closes the panel. What a selected pull request lit stays lit (the button says which); Clear lets go of it. */
82
+ function closeForge({ restoreFocus = true } = {}) {
83
+ const panel = $('forge-panel');
84
+ if (!panel || !ui.open) return;
85
+ const hadFocus = panel.contains(inst.active());
86
+ ui.open = false;
87
+ panel.classList.remove('forge-open');
88
+ panel.inert = true;
89
+ collapseSheet('forge');
90
+ fn.paintButton();
91
+ const back = m.openerEl && m.openerEl.isConnected ? m.openerEl : $('forge-btn');
92
+ if (restoreFocus && hadFocus && back) back.focus();
93
+ announce('Work closed');
94
+ }
95
+
96
+ const toggleForge = () => (ui.open ? closeForge() : openForge());
97
+
98
+ /** After a filter changes: the list again, and how many it holds */
99
+ function filtersChanged(announceNow = true) {
100
+ fn.paint();
101
+ const list = fn.current();
102
+ if (announceNow && list && ui.kind === 'work') announce(workStatus(fn.groupsShown(), '', m.now()));
103
+ else if (announceNow && list) announce(`${filterItems(list.items, ui.kind, ui.filters).length} of ${plural(list.items.length, fn.kindWords())} shown`);
104
+ }
105
+
106
+ function onClick(e) {
107
+ const t = e.target;
108
+ if (!t.closest) return;
109
+ const kind = t.closest('[data-forge-kind]');
110
+ if (kind) {
111
+ if (kind.dataset.forgeKind === ui.kind) return;
112
+ ui.kind = kind.dataset.forgeKind;
113
+ ui.actNote = null;
114
+ ui.filters = defaultFilters(ui.kind);
115
+ fn.paintFilters();
116
+ // The proposals are asked for again each time (worktrees come and go); the other lists keep what they have
117
+ if (ui.kind === 'specs') { fn.paint(); fn.loadList(false, true); announce(fn.current() ? `${plural(fn.current().items.length, 'spec')} shown` : 'Looking for proposals'); } else if (fn.current()) filtersChanged(); else { fn.paint(); fn.loadList(); }
118
+ return;
119
+ }
120
+ const fold = t.closest('[data-spec-group-toggle]');
121
+ if (fold) {
122
+ // Drafts folded behind their header, opened by hand and folded again; the focus stays on the header (findAgain)
123
+ const drafts = specGroups(fn.specsList() ? fn.specsList().items : [], { query: ui.specQuery }).find((g) => g.key === 'drafts');
124
+ const folded = ui.draftsOpen === null ? !!(drafts && drafts.collapsed) : !ui.draftsOpen;
125
+ ui.draftsOpen = folded;
126
+ fn.paint();
127
+ return;
128
+ }
129
+ const pr = t.closest('[data-forge-pr]');
130
+ if (pr) {
131
+ const n = Number(pr.dataset.forgePr);
132
+ m.returnTo = fn.findAgain(pr); // the row to give the focus back to when the selection is let go of
133
+ if (ui.selected === n) fn.clearPull(); else fn.selectPull(n);
134
+ return;
135
+ }
136
+ const thr = t.closest('[data-forge-thread]');
137
+ if (thr) {
138
+ const n = Number(thr.dataset.forgeThread);
139
+ m.returnTo = fn.findAgain(thr);
140
+ if (ui.thread === n) fn.clearThread(); else fn.selectThread(n);
141
+ return;
142
+ }
143
+ const dep = t.closest('[data-forge-deploy]');
144
+ if (dep) {
145
+ m.returnTo = fn.findAgain(dep);
146
+ if (ui.deploy === dep.dataset.forgeDeploy) fn.clearDeploy(); else fn.selectDeploy(dep.dataset.forgeDeploy);
147
+ return;
148
+ }
149
+ const nodeBtn = t.closest('[data-forge-node]');
150
+ if (nodeBtn) {
151
+ const node = nodeById(nodeBtn.dataset.forgeNode);
152
+ if (!node) return;
153
+ selectNode(node, { frame: true });
154
+ if (isPhone()) collapseSheet('forge'); // the map and the node's sheet are what is wanted now
155
+ announce(`${node.label}, ${node.type}`);
156
+ return;
157
+ }
158
+ const agent = t.closest('[data-forge-agent]');
159
+ if (agent) { fn.openAgent(agent.dataset.forgeAgent, `[data-forge-agent="${agent.dataset.forgeAgent}"]`); return; }
160
+ const stop = t.closest('[data-forge-stop]');
161
+ if (stop) { fn.stopRun(stop.dataset.forgeStop); return; }
162
+ const retry = t.closest('[data-forge-retry]');
163
+ if (retry) { fn.startAgain(retry.dataset.forgeRetry); return; }
164
+ const goto = t.closest('[data-run-goto]');
165
+ if (goto) { fn.goToRun(goto.dataset.runGoto); return; }
166
+ const answer = t.closest('[data-run-answer]');
167
+ if (answer) { fn.answerRun(answer.dataset.runId, answer.dataset.runAnswer); return; }
168
+ const discard = t.closest('[data-run-discard]');
169
+ if (discard) { fn.discardReply(discard.dataset.runDiscard); return; }
170
+ const pick = t.closest('[data-run-select]');
171
+ if (pick) { fn.selectRun(pick.dataset.runSelect); return; }
172
+ const timeline = t.closest('[data-run-timeline]');
173
+ if (timeline) { fn.toggleTimeline(timeline.dataset.runTimeline); return; }
174
+ const unland = t.closest('[data-forge-landing-cancel]');
175
+ if (unland) { fn.cancelLanding(Number(unland.dataset.forgeLandingCancel)); return; }
176
+ const merge = t.closest('[data-forge-merge]');
177
+ if (merge) { fn.openConfirm('[data-forge-merge]'); return; }
178
+ const spec = t.closest('[data-forge-spec]');
179
+ if (spec) { fn.askPlan('spec', Number(spec.dataset.forgeSpec), null, `[data-forge-spec="${spec.dataset.forgeSpec}"]`); return; }
180
+ const build = t.closest('[data-forge-build]');
181
+ if (build && ui.selected !== null) { fn.askPlan('build', ui.selected, build.dataset.forgeBuild, `[data-forge-build="${build.dataset.forgeBuild}"]`); return; }
182
+ const rerun = t.closest('[data-forge-rerun]');
183
+ if (rerun) { fn.rerunCheck(rerun.dataset.forgeRerun); return; }
184
+ const action = t.closest('[data-action]');
185
+ if (!action) return;
186
+ if (action.dataset.action === 'close-forge') closeForge();
187
+ else if (action.dataset.action === 'refresh-forge' || action.dataset.action === 'retry-forge') fn.refreshForge();
188
+ else if (action.dataset.action === 'clear-specs-search') {
189
+ ui.specQuery = '';
190
+ const box = $('specs-search');
191
+ if (box) { box.value = ''; }
192
+ fn.paint();
193
+ announce(fn.specsShownWords());
194
+ if (box) box.focus();
195
+ }
196
+ else if (action.dataset.action === 'copy-notes') fn.copyNotes();
197
+ else if (action.dataset.action === 'post-notes') { if (ui.notes.confirm) fn.closeNotesConfirm(); else fn.openNotesConfirm(); }
198
+ else if (action.dataset.action === 'confirm-notes') fn.postDraft();
199
+ else if (action.dataset.action === 'cancel-notes') { fn.closeNotesConfirm(); announce('Cancelled. Nothing was posted.'); }
200
+ else if (action.dataset.action === 'clear-forge-pr') fn.clearPull();
201
+ else if (action.dataset.action === 'clear-forge-deploy') fn.clearDeploy();
202
+ else if (action.dataset.action === 'clear-forge-thread') fn.clearThread();
203
+ else if (action.dataset.action === 'toggle-filters') { ui.filtersOpen = !ui.filtersOpen; fn.paintChip(); }
204
+ else if (action.dataset.action === 'open-notes') fn.openNotes();
205
+ else if (action.dataset.action === 'close-notes') fn.closeNotes();
206
+ else if (action.dataset.action === 'open-proposal' && isPhone()) collapseSheet('forge'); // the proposal's own bar and the map are what is wanted now
207
+ else if (action.dataset.action === 'idea-open') fn.toggleIdea(!ui.idea.open);
208
+ else if (action.dataset.action === 'idea-send') {
209
+ // Nothing of it may escape as an unhandled rejection: what went wrong is said, and the form is usable again
210
+ fn.sendIdea().catch((err) => {
211
+ ui.idea.busy = false;
212
+ ui.idea.message = `Something went wrong in the page: ${err instanceof Error ? err.message : err}`;
213
+ ui.idea.bad = true;
214
+ fn.paintIdea();
215
+ announce(ui.idea.message);
216
+ });
217
+ }
218
+ else if (action.dataset.action === 'idea-cancel') { fn.toggleIdea(false); announce('Cancelled. Nothing was opened.'); }
219
+ }
220
+
221
+ function onChange(e) {
222
+ const id = e.target.id;
223
+ if (id === 'notes-since') {
224
+ ui.notes.since = e.target.value;
225
+ ui.notes.message = '';
226
+ fn.loadNotes();
227
+ } else if (id === 'forge-state') {
228
+ ui.filters.state = e.target.value;
229
+ fn.paintFilters();
230
+ if (fn.current()) filtersChanged(); else { fn.paint(); fn.loadList(); }
231
+ } else if (id === 'forge-work-agents' || id === 'forge-work-finished') {
232
+ if (id === 'forge-work-agents') ui.workFilters.agentsOnly = e.target.checked;
233
+ else ui.workFilters.finished = e.target.checked;
234
+ fn.paint();
235
+ announce(workStatus(fn.groupsShown(), '', m.now()));
236
+ } else if (id === 'forge-label') {
237
+ ui.filters.label = e.target.value;
238
+ filtersChanged();
239
+ } else if (id === 'forge-author') {
240
+ ui.filters.author = e.target.value;
241
+ filtersChanged();
242
+ }
243
+ }
244
+
245
+ function onInput(e) {
246
+ if (e.target.dataset && e.target.dataset.runReply) {
247
+ const id = e.target.dataset.runReply;
248
+ ui.runReplies.set(id, e.target.value);
249
+ // "Write a reply first" goes once something is written: a refusal does not outlive what it was about
250
+ const said = resultOf(id);
251
+ if (said && !said.ok && e.target.value.trim()) { clearResult(id); showResultIn(e.target.closest('[data-run]') && e.target.closest('[data-run]').querySelector(`[data-run-result="${id}"]`), id); }
252
+ return;
253
+ }
254
+ if (e.target.id === 'specs-search') {
255
+ ui.specQuery = e.target.value;
256
+ fn.paint();
257
+ clearT(m.searchTimer);
258
+ m.searchTimer = setT(() => announce(fn.specsShownWords()), SEARCH_ANNOUNCE_MS);
259
+ return;
260
+ }
261
+ if (e.target.id !== 'forge-text') return;
262
+ ui.filters.text = e.target.value;
263
+ filtersChanged(false);
264
+ clearT(m.searchTimer);
265
+ m.searchTimer = setT(() => filtersChanged(), SEARCH_ANNOUNCE_MS);
266
+ }
267
+
268
+ /** Escape anywhere in the panel closes it, and the button has the focus again (a field's own Escape comes first) */
269
+ function onKey(e) {
270
+ if (e.key === 'Enter' && e.target.dataset && e.target.dataset.runReply && !e.defaultPrevented) { e.preventDefault(); fn.answerRun(e.target.dataset.runReply, 'reply'); return; }
271
+ if (e.key === 'Enter' && e.target.id === 'notes-tag' && !e.defaultPrevented) { e.preventDefault(); fn.postDraft(); return; }
272
+ if (e.key === 'Escape' && !e.defaultPrevented && ui.notes.confirm && e.target.closest && e.target.closest('#notes-confirm')) {
273
+ e.preventDefault();
274
+ fn.closeNotesConfirm();
275
+ announce('Cancelled. Nothing was posted.');
276
+ return;
277
+ }
278
+ if (e.key !== 'Escape' || e.defaultPrevented) return;
279
+ if (e.target.closest && e.target.closest('select, input, textarea')) return;
280
+ e.preventDefault();
281
+ closeForge();
282
+ }
283
+
284
+ Object.assign(fn, { isForgeOpen, openForge, openTab, linkMissing, bringIntoView, closeForge, toggleForge, filtersChanged, onClick, onChange, onInput, onKey });
285
+ }
@@ -0,0 +1,43 @@
1
+ /**
2
+ * @module explorer/pieces/work-issues
3
+ *
4
+ * The Issues tab and the deep link to an issue (its rows are drawn with the PRs' in work-prs.js). 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 { issueUrl } from '../forge-panel-model.js';
9
+
10
+ export function install(ctx) {
11
+ const { ui, fn, $ } = ctx;
12
+ const { announce } = ctx.h;
13
+
14
+ /** An issue the open list does not hold: asked for once, directly, so a closed one is called closed and a missing one missing */
15
+ async function issueNotListed(n) {
16
+ const res = await fn.request(issueUrl(n));
17
+ if (res.ok && res.body.issue) {
18
+ const { issue } = res.body;
19
+ ui.actNote = { ok: false, text: issue.state === 'closed' ? `Issue ${n} is closed: ${issue.title}` : `Issue ${n} is open, but not in the list shown here: ${issue.title}`, url: issue.url };
20
+ fn.paint();
21
+ announce(ui.actNote.text);
22
+ return false;
23
+ }
24
+ return fn.linkMissing(res.status === 404 ? `There is no issue ${n}.` : fn.failWords(res, `issue ${n}`));
25
+ }
26
+
27
+ /** `?issue=<n>`: the Issues tab with that issue's Start an agent button in view and focused, ready to press */
28
+ async function openIssueLink(n) {
29
+ if (!ui.config) return false;
30
+ await fn.openTab('issues');
31
+ const list = fn.current();
32
+ if (!list) return fn.linkMissing(ui.error || 'The issues could not be read.');
33
+ const item = list.items.find((i) => i.number === n);
34
+ if (!item) return issueNotListed(n);
35
+ fn.paint();
36
+ const start = $('forge-list').querySelector(`[data-forge-agent="issue:${n}"]`);
37
+ fn.bringIntoView(start);
38
+ announce(`Issue ${n}: ${item.title}. Start an agent is ready`);
39
+ return true;
40
+ }
41
+
42
+ Object.assign(fn, { issueNotListed, openIssueLink });
43
+ }
@@ -0,0 +1,155 @@
1
+ /**
2
+ * @module explorer/pieces/work-markup
3
+ *
4
+ * The Work piece's markup (spec 0011 D3), moved out of explorer/index.html unchanged: the Work button (its stand-in stays in the header, held equal to
5
+ * this by test/explorer/page-pieces.test.js), the panel, and the two dialogs it opens (the confirm step and Start an agent), which sit
6
+ * at the end of the page, over a scrim. Every `data-corn` element also gets its `part` when the piece places it (engine/piece.js).
7
+ */
8
+
9
+ import { withParts } from '../engine/piece.js';
10
+
11
+ /** The markup, each hook with its part of the same name (engine/piece.js `place` would give it too) */
12
+ export const markup = () => Object.fromEntries(Object.entries(markupOf()).map(([slot, html]) => [slot, withParts(html)]));
13
+
14
+ const markupOf = () => ({
15
+ /** The Work toggle: opens the panel; hidden until the config names a forge and somebody is signed in */
16
+ button: `<button type="button" id="forge-btn" class="hx-work" data-action="toggle-forge" aria-expanded="false" aria-controls="forge-panel" aria-label="Work" data-corn-string-aria-label="issuesAndPrs" title="Issues, pull requests and deploys: a pull request lights the nodes it changes, a deploy the nodes it restarted" hidden data-corn="forge-button">
17
+ <span data-corn-string="issuesAndPrs">Work</span>
18
+ <span id="forge-btn-lit" class="hx-forge-lit" data-corn="count" hidden></span>
19
+ <span id="forge-btn-dot" class="hx-runner-dot" aria-hidden="true" title="No runner online" hidden></span>
20
+ <span id="forge-btn-waiting" class="hx-waiting-badge" data-corn="waiting-badge" aria-hidden="true" hidden></span>
21
+ </button>`,
22
+ /** Specs, PRs, Issues, Threads, Runs and Deploys, in the order of the loop: a slide-over from the left on desktop, a bottom sheet on a phone; hidden and inert until the config names a forge. `forge-panel` on the inner box is the old name of the hook, kept for one release (docs/theming.md) */
23
+ panel: `<aside id="forge-panel" class="hx-forge glass" aria-label="Work" inert hidden data-corn="work-panel">
24
+ <div class="hx-forge-body" data-corn="forge-panel">
25
+ <div class="hx-forge-top" data-corn="work-top">
26
+ <div class="hx-forge-head" data-corn="work-head">
27
+ <h2 id="forge-title" class="hx-drawer-title" data-corn="work-title" tabindex="-1">Work</h2>
28
+ <button type="button" class="hx-btn hx-btn--quiet" data-action="refresh-forge" title="Ask the forge again" data-corn-kind="quiet">Refresh</button>
29
+ <button type="button" class="hx-close" data-action="close-forge" aria-label="Close" data-corn-kind="icon">✕</button>
30
+ </div>
31
+ <div class="hx-forge-tabs" role="group" aria-label="Show" data-corn="tabs">
32
+ <button type="button" class="hx-forge-tab" data-forge-kind="specs" aria-pressed="true" title="The proposals: what a change would add, change and remove" data-corn="tab"><span data-corn-string="tabSpecs">Specs</span><span class="hx-forge-count" data-corn="count"></span></button>
33
+ <button type="button" class="hx-forge-tab" data-forge-kind="pulls" aria-pressed="false" title="Pull requests" data-corn="tab"><span data-corn-string="tabPulls">PRs</span><span class="hx-forge-count" data-corn="count"></span></button>
34
+ <button type="button" class="hx-forge-tab" data-forge-kind="issues" aria-pressed="false" data-corn="tab"><span data-corn-string="tabIssues">Issues</span><span class="hx-forge-count" data-corn="count"></span></button>
35
+ <button type="button" class="hx-forge-tab" data-forge-kind="threads" aria-pressed="false" title="Ideas and spec conversations, with the nodes they mention" data-corn="tab"><span data-corn-string="tabThreads">Threads</span><span class="hx-forge-count" data-corn="count"></span></button>
36
+ <button type="button" class="hx-forge-tab" data-forge-kind="work" aria-pressed="false" title="Agent runs, and the work grouped by issue and proposal with agent-made work marked" data-corn="tab"><span data-corn-string="tabRuns">Runs</span><span class="hx-forge-count" data-corn="count"></span></button>
37
+ <button type="button" class="hx-forge-tab" data-forge-kind="deploys" aria-pressed="false" data-corn="tab"><span data-corn-string="tabDeploys">Deploys</span><span class="hx-forge-count" data-corn="count" hidden></span></button>
38
+ </div>
39
+ </div>
40
+ <div id="forge-bar" class="hx-forge-bar">
41
+ <p id="forge-status" class="hx-forge-status hx-faint"></p>
42
+ <button data-corn="filter-chip" type="button" id="forge-filter-chip" class="hx-forge-chip" data-action="toggle-filters" aria-expanded="false" aria-controls="forge-filter-box" hidden>Filter<span class="hx-forge-count" data-corn="count" hidden></span></button>
43
+ </div>
44
+ <div id="forge-specs-search" class="hx-forge-specsearch" data-corn="specs-search" hidden>
45
+ <label class="hx-forge-field hx-forge-field--text" data-corn="field">Find a spec<input data-corn="control" type="search" id="specs-search" class="hx-forge-input" placeholder="Title, name, summary" autocomplete="off" /></label>
46
+ </div>
47
+ <div id="forge-filter-box" class="hx-forge-controls" data-corn="filters" hidden>
48
+ <div id="forge-work-filters" class="hx-forge-work-filters" hidden>
49
+ <label class="hx-forge-toggle" data-corn="check-field"><input data-corn="control" type="checkbox" id="forge-work-agents" /> Agent-made only</label>
50
+ <label class="hx-forge-toggle" data-corn="check-field"><input data-corn="control" type="checkbox" id="forge-work-finished" /> Include merged and closed</label>
51
+ </div>
52
+ <div id="forge-filters" class="hx-forge-filters">
53
+ <label class="hx-forge-field" data-corn="field">State<select data-corn="control" id="forge-state" class="hx-forge-select"></select></label>
54
+ <label class="hx-forge-field" data-corn="field">Label<select data-corn="control" id="forge-label" class="hx-forge-select"></select></label>
55
+ <label class="hx-forge-field" data-corn="field">Author<select data-corn="control" id="forge-author" class="hx-forge-select"></select></label>
56
+ <label class="hx-forge-field hx-forge-field--text" data-corn="field">Search<input data-corn="control" type="search" id="forge-text" class="hx-forge-input" placeholder="Title, number, label" autocomplete="off" /></label>
57
+ </div>
58
+ </div>
59
+ <p id="forge-notice" class="hx-forge-notice" hidden data-corn="notice"></p>
60
+ <p id="forge-act-note" class="hx-forge-notice" hidden data-corn="notice"></p>
61
+ <section id="forge-notes" class="hx-forge-notes" aria-label="Release notes" hidden>
62
+ <button data-corn="back" type="button" class="hx-forge-back" data-action="close-notes"><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">All pull requests</span></button>
63
+ <h3 id="notes-title" class="hx-forge-notes-title" data-corn="detail-title" tabindex="-1">Release notes</h3>
64
+ <label class="hx-forge-field" data-corn="field">Since tag<select data-corn="control" id="notes-since" class="hx-forge-select"></select></label>
65
+ <label class="hx-forge-field" data-corn="field">Draft, in Markdown<textarea data-corn="control" id="notes-preview" class="hx-forge-preview" rows="14" readonly spellcheck="false"></textarea></label>
66
+ <div class="hx-forge-actions">
67
+ <button data-corn-kind="secondary" type="button" id="notes-copy" class="hx-btn" data-action="copy-notes">Copy</button>
68
+ <button type="button" id="notes-post" class="hx-btn hx-btn--approve" data-action="post-notes" aria-expanded="false" aria-controls="notes-confirm" data-corn-kind="approve">Post as draft …</button>
69
+ </div>
70
+ <p id="notes-message" class="hx-forge-msg" hidden data-corn="message"></p>
71
+ <div id="notes-confirm" class="hx-forge-confirm" data-corn="confirm-form" role="group" aria-labelledby="notes-confirm-title" hidden>
72
+ <h3 id="notes-confirm-title" class="hx-forge-confirm-title">Post as a draft release</h3>
73
+ <p id="notes-confirm-words"></p>
74
+ <label class="hx-forge-field" data-corn="field">Tag for the draft<input data-corn="control" type="text" id="notes-tag" class="hx-forge-input" autocomplete="off" spellcheck="false" /></label>
75
+ <div class="hx-forge-actions">
76
+ <button type="button" id="notes-confirm-yes" class="hx-btn hx-btn--approve" data-action="confirm-notes" data-corn-kind="approve">Create the draft</button>
77
+ <button type="button" class="hx-btn hx-btn--quiet" data-action="cancel-notes" data-corn-kind="quiet">Cancel</button>
78
+ </div>
79
+ </div>
80
+ </section>
81
+ <section id="forge-runs" class="hx-forge-runs" aria-labelledby="forge-runs-title" hidden>
82
+ <h3 id="forge-runs-title" class="hx-forge-runs-title">Agent runs</h3>
83
+ <p id="forge-runs-runner" class="hx-forge-meta" hidden></p>
84
+ <p id="forge-runs-status" class="hx-forge-meta hx-faint"></p>
85
+ <p id="forge-runs-note" class="hx-forge-notice" hidden data-corn="notice"></p>
86
+ <p id="forge-runs-trigger" class="hx-forge-notice" hidden data-corn="notice"></p>
87
+ <div id="forge-runs-totals" data-corn="run-totals" role="group" aria-label="Tokens and cost the runners reported" hidden></div>
88
+ <ul id="forge-runs-hand" class="hx-forge-meta" aria-label="Requests written by hand that started nothing" hidden></ul>
89
+ <ul id="forge-runs-list" class="hx-forge-files" aria-label="Runs"></ul>
90
+ </section>
91
+ <section id="forge-detail" class="hx-forge-detail" aria-label="Selected pull request" hidden></section>
92
+ <ul id="forge-list" class="hx-forge-list" aria-label="Results"></ul>
93
+ <div id="forge-foot" class="hx-forge-foot" data-corn="work-foot">
94
+ <button data-corn-kind="secondary" type="button" id="notes-open" class="hx-btn" data-action="open-notes" hidden>Release notes …</button>
95
+ <section id="forge-idea" class="hx-forge-notes" aria-label="New idea" data-corn-string-aria-label="newIdea" hidden>
96
+ <div class="hx-forge-actions">
97
+ <button type="button" id="idea-open" class="hx-btn hx-btn--approve" data-action="idea-open" aria-expanded="false" aria-controls="idea-form" data-corn-kind="approve"><span data-corn-string="newIdea">New idea</span> …</button>
98
+ </div>
99
+ <p id="idea-message" class="hx-forge-msg" role="status" hidden data-corn="message"></p>
100
+ <div id="idea-form" data-corn="confirm-form" class="hx-forge-confirm" role="group" aria-labelledby="idea-form-title" hidden>
101
+ <h3 id="idea-form-title" class="hx-forge-confirm-title" data-corn-string="newIdea">New idea</h3>
102
+ <p id="idea-words"></p>
103
+ <label class="hx-forge-field" data-corn="field">Title<input data-corn="control" type="text" id="idea-title" class="hx-forge-input" maxlength="256" autocomplete="off" /></label>
104
+ <label class="hx-forge-field" data-corn="field">What is the idea?<textarea data-corn="control" id="idea-body" class="hx-forge-preview hx-thread-compose" rows="6" maxlength="20000" spellcheck="true"></textarea></label>
105
+ <div class="hx-forge-actions">
106
+ <button type="button" id="idea-send" class="hx-btn hx-btn--approve" data-action="idea-send" data-corn-kind="approve">Open the idea</button>
107
+ <button type="button" class="hx-btn hx-btn--quiet" data-action="idea-cancel" data-corn-kind="quiet">Cancel</button>
108
+ </div>
109
+ </div>
110
+ </section>
111
+ </div>
112
+ <p id="forge-rate" class="hx-forge-rate hx-faint"></p>
113
+ </div>
114
+ </aside>`,
115
+ /** The nodes agent runs are changing, marked over the map: a picture; the Runs view says the same in words */
116
+ overlay: `<div id="run-overlay" class="hx-run-overlay" aria-hidden="true" hidden data-corn="run-overlay"></div>`,
117
+ /** The confirm step of landing a pull request, starting a spec and opening a build issue, and Start an agent: modal dialogs over a scrim; the focus stays in them while one is open */
118
+ dialogs: `<div id="forge-confirm" class="hx-confirm-scrim" hidden data-corn="dialog-scrim">
119
+ <div class="hx-confirm glass" role="dialog" aria-modal="true" aria-labelledby="forge-confirm-title" aria-describedby="forge-confirm-body" data-corn="confirm-dialog">
120
+ <h2 id="forge-confirm-title" class="hx-confirm-title" data-corn="dialog-title"></h2>
121
+ <div id="forge-confirm-body"></div>
122
+ <div class="hx-confirm-actions">
123
+ <button data-corn-kind="secondary" type="button" class="hx-btn" data-action="forge-confirm-cancel">Cancel</button>
124
+ <button type="button" class="hx-btn hx-btn--approve" data-action="forge-confirm-go" data-corn-kind="approve" data-corn-string="landIt">Land it</button>
125
+ </div>
126
+ </div>
127
+ </div>
128
+
129
+ <div id="agent-start" class="hx-confirm-scrim" hidden data-corn="dialog-scrim">
130
+ <div class="hx-confirm glass" role="dialog" aria-modal="true" aria-labelledby="agent-start-title" aria-describedby="agent-start-words" data-corn="agent-dialog">
131
+ <h2 id="agent-start-title" class="hx-confirm-title" data-corn="dialog-title" data-corn-string="startAgent">Start an agent</h2>
132
+ <p id="agent-start-about" class="hx-forge-meta"></p>
133
+ <p id="agent-start-runner" class="hx-forge-meta" hidden></p>
134
+ <p id="agent-retry-note" class="hx-forge-meta" hidden></p>
135
+ <form id="agent-start-form" class="hx-forge-confirm" data-corn="confirm-form" novalidate>
136
+ <label class="hx-forge-field" data-corn="field">Kind of run<select data-corn="control" id="agent-kind" class="hx-forge-select"></select></label>
137
+ <label id="agent-profile-field" class="hx-forge-field" hidden data-corn="field">Profile<select data-corn="control" id="agent-profile" class="hx-forge-select"></select></label>
138
+ <fieldset id="agent-limits-edit" class="hx-forge-field hx-forge-limits" data-corn="field"><legend>Limits, hints for the runner (one left blank takes the config's, if any)</legend>
139
+ <label class="hx-forge-field" data-corn="field">Minutes<input data-corn="control" type="number" id="agent-limit-minutes" class="hx-forge-input" min="0" step="any" inputmode="decimal" /></label>
140
+ <label class="hx-forge-field" data-corn="field">Turns<input data-corn="control" type="number" id="agent-limit-turns" class="hx-forge-input" min="0" step="1" inputmode="numeric" /></label>
141
+ <label class="hx-forge-field" data-corn="field">Cost<input data-corn="control" type="number" id="agent-limit-cost" class="hx-forge-input" min="0" step="any" inputmode="decimal" /></label>
142
+ <label class="hx-forge-field" data-corn="field">Tokens<input data-corn="control" type="number" id="agent-limit-tokens" class="hx-forge-input" min="0" step="1" inputmode="numeric" /></label>
143
+ </fieldset>
144
+ <label class="hx-forge-field" data-corn="field">Brief for the runner<textarea data-corn="control" id="agent-brief" class="hx-forge-preview" rows="6" maxlength="20000" spellcheck="true"></textarea></label>
145
+ <label id="agent-force-field" class="hx-forge-toggle" data-corn="check-field" hidden><input data-corn="control" type="checkbox" id="agent-force" /> Ask for another run on purpose</label>
146
+ <p id="agent-start-words" class="hx-confirm-note"></p>
147
+ <p id="agent-start-msg" class="hx-forge-msg hx-forge-msg--bad" role="alert" hidden data-corn="message" data-corn-state="failure"></p>
148
+ <div class="hx-confirm-actions">
149
+ <button data-corn-kind="secondary" type="button" class="hx-btn" data-action="agent-start-cancel">Cancel</button>
150
+ <button type="submit" class="hx-btn hx-btn--approve" id="agent-start-go" data-corn-kind="approve" data-corn-string="askRunner">Ask the runner</button>
151
+ </div>
152
+ </form>
153
+ </div>
154
+ </div>`,
155
+ });