cornfield 0.63.0 → 0.64.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/explorer/inbox-model.js +180 -0
- package/explorer/pieces/inbox.js +201 -0
- package/explorer/work-view.css +51 -0
- package/explorer/work-view.js +70 -3
- package/package.json +1 -1
- package/server/work-graph.js +60 -3
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module explorer/inbox-model
|
|
3
|
+
*
|
|
4
|
+
* The Work inbox's rules, the pure half (spec 0016 D2 to D4): no DOM, no `window`, no clock of its own. From the server's work graph
|
|
5
|
+
* (server/work-graph.js: `{ nodes, edges }`) it works out which group each piece of work is in, why (in words), its one action, the order, and
|
|
6
|
+
* a waiting run folded into the spec it asks about. The page draws it (explorer/pieces/inbox.js).
|
|
7
|
+
*
|
|
8
|
+
* inboxOf(graph, { now }) -> { groups: { waiting, move, unclaimed, motion, done }, rows, drafts, count, rowsWaiting }
|
|
9
|
+
*
|
|
10
|
+
* A row: `{ id, item, group, why, bad, action, counted, also }`. `action` is `{ key, label }`, the key one of ACTIONS (what the node panel already does);
|
|
11
|
+
* `counted` is spec 0010 D1's rule (`item.waiting`), so `count` is the number the Work button shows; `also` is the row of a waiting run folded into it (D4).
|
|
12
|
+
* Nothing here files, archives or hides a row by hand (D7): a row moves only when the graph says its state moved.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import { tagOf } from './work-model.js';
|
|
16
|
+
|
|
17
|
+
/** The groups, in the queue's order (D2), with their words, and whether each starts open */
|
|
18
|
+
export const GROUPS = Object.freeze([
|
|
19
|
+
{ key: 'waiting', title: 'Waiting on you', hint: '', open: true },
|
|
20
|
+
{ key: 'move', title: 'Your move', hint: 'not counted', open: true },
|
|
21
|
+
{ key: 'unclaimed', title: 'Nobody on it', hint: 'not counted', open: true },
|
|
22
|
+
{ key: 'motion', title: 'In motion', hint: '', open: false },
|
|
23
|
+
{ key: 'done', title: 'Done lately', hint: '', open: false },
|
|
24
|
+
]);
|
|
25
|
+
export const GROUP_KEYS = Object.freeze(GROUPS.map((g) => g.key));
|
|
26
|
+
|
|
27
|
+
/** The actions a row offers: each is one the node panel already has (spec 0012 D5), with its confirm step and server checks */
|
|
28
|
+
export const ACTIONS = Object.freeze({
|
|
29
|
+
review: 'Review',
|
|
30
|
+
'review-change': 'Review the change',
|
|
31
|
+
answer: 'Answer',
|
|
32
|
+
land: 'Land it',
|
|
33
|
+
rerun: 'Re-run failed',
|
|
34
|
+
retry: 'Start again',
|
|
35
|
+
agent: 'Start an agent',
|
|
36
|
+
reply: 'Reply',
|
|
37
|
+
logs: 'Logs',
|
|
38
|
+
});
|
|
39
|
+
const act = (key, label = ACTIONS[key]) => ({ key, label });
|
|
40
|
+
|
|
41
|
+
const text = (v) => (typeof v === 'string' ? v : '');
|
|
42
|
+
const cap = (s) => text(s).replace(/-/g, ' ').replace(/^./, (c) => c.toUpperCase());
|
|
43
|
+
const plural = (n, one, many = `${one}s`) => `${n} ${n === 1 ? one : many}`;
|
|
44
|
+
|
|
45
|
+
/** "lint failed · test running · 1 passed", from a pull request's `checks` (server/work-graph.js `checkCounts`); '' with none */
|
|
46
|
+
export function checkWords(checks) {
|
|
47
|
+
if (!checks) return '';
|
|
48
|
+
const names = (list, n) => (list && list.length ? list.join(', ') + (n > list.length ? ` and ${n - list.length} more` : '') : plural(n, 'check'));
|
|
49
|
+
return [
|
|
50
|
+
checks.failed ? `${names(checks.failedNames, checks.failed)} failed` : '',
|
|
51
|
+
checks.running ? `${names(checks.runningNames, checks.running)} running` : '',
|
|
52
|
+
checks.passed ? `${checks.passed} passed` : '',
|
|
53
|
+
].filter(Boolean).join(' · ');
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* A thread folded into a spec (spec 0015 D2): every line of it is `discusses` or `became` to a proposal. Such a thread is not a row.
|
|
58
|
+
* @param {string} id
|
|
59
|
+
* @param {{ from: string, to: string, rel: string }[]} edges
|
|
60
|
+
* @param {Map<string, any>} byId
|
|
61
|
+
*/
|
|
62
|
+
export function isFoldedThread(id, edges, byId) {
|
|
63
|
+
const mine = edges.filter((e) => e.from === id || e.to === id);
|
|
64
|
+
if (!mine.length) return false;
|
|
65
|
+
return mine.every((e) => e.from === id && (e.rel === 'discusses' || e.rel === 'became') && byId.has(e.to) && byId.get(e.to).kind === 'proposal');
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Where a piece of work goes, and why (D2). Null: it is not a row (a folded thread, a local draft: drafts are a count).
|
|
70
|
+
* @param {any} item a node of the server's graph
|
|
71
|
+
* @param {{ edges: any[], byId: Map<string, any> }} ctx
|
|
72
|
+
* @returns {{ group: string, why: string, bad?: boolean, action: { key: string, label: string } | null } | null}
|
|
73
|
+
*/
|
|
74
|
+
export function placeOf(item, { edges, byId }) {
|
|
75
|
+
switch (item.kind) {
|
|
76
|
+
case 'proposal':
|
|
77
|
+
if (item.state === 'local') return null;
|
|
78
|
+
if (item.waiting && item.state === 'changed') return { group: 'waiting', why: 'Changed since you approved it', action: act('review-change') };
|
|
79
|
+
if (item.waiting) return { group: 'waiting', why: 'Ready for your decision', action: act('review') };
|
|
80
|
+
if (!item.open) return { group: 'done', why: cap(item.state), action: null };
|
|
81
|
+
if (item.state === 'approved') return { group: 'move', why: 'Approved: landing it merges the spec', action: act('land') };
|
|
82
|
+
if (item.state === 'sent-back') return { group: 'motion', why: 'Sent back: with the agent until it pushes', action: null };
|
|
83
|
+
if (item.state === 'draft-pr') return { group: 'motion', why: 'A draft pull request: the agent is still writing it', action: null };
|
|
84
|
+
return { group: 'motion', why: cap(item.state), action: null };
|
|
85
|
+
case 'run': {
|
|
86
|
+
if (item.waiting) return { group: 'waiting', why: text(item.note) || 'Waiting on your answer', action: act('answer') };
|
|
87
|
+
if (item.state === 'failed') return { group: 'move', why: `Failed${item.note ? `: ${item.note}` : ''}`, bad: true, action: act('retry') };
|
|
88
|
+
if (item.state === 'done' && item.pull && item.pull.state === 'open') return { group: 'move', why: `Done: PR #${item.pull.number} is open${item.note ? `. ${item.note}` : ''}`, action: act('land', `Land PR #${item.pull.number}`) };
|
|
89
|
+
if (item.open) return { group: 'motion', why: `${cap(item.state)}${item.note ? `: ${item.note}` : ''}`, action: null };
|
|
90
|
+
return { group: 'done', why: text(item.note) || cap(item.state), action: null };
|
|
91
|
+
}
|
|
92
|
+
case 'pull': {
|
|
93
|
+
if (!item.open) return { group: 'done', why: cap(item.state), action: null };
|
|
94
|
+
const words = checkWords(item.checks);
|
|
95
|
+
if (item.checks && item.checks.failed) return { group: 'move', why: words, bad: true, action: act('rerun') };
|
|
96
|
+
return { group: 'motion', why: words || (item.draft ? 'Draft' : 'Open'), action: null };
|
|
97
|
+
}
|
|
98
|
+
case 'issue': {
|
|
99
|
+
if (!item.open) return { group: 'done', why: 'Closed', action: null };
|
|
100
|
+
const live = edges.filter((e) => e.from === item.id && e.rel === 'agent-on').map((e) => byId.get(e.to)).filter((r) => r && r.open);
|
|
101
|
+
if (live.length) return { group: 'motion', why: `${plural(live.length, 'agent run')} on it`, action: null };
|
|
102
|
+
return { group: 'unclaimed', why: 'Nobody is on it', action: act('agent') };
|
|
103
|
+
}
|
|
104
|
+
case 'thread': {
|
|
105
|
+
if (isFoldedThread(item.id, edges, byId)) return null;
|
|
106
|
+
if (!item.open) return { group: 'done', why: 'Closed', action: null };
|
|
107
|
+
const spec = edges.some((e) => e.from === item.id && (e.rel === 'became' || e.rel === 'discusses'));
|
|
108
|
+
if (spec) return { group: 'motion', why: 'A spec is being written from it', action: null };
|
|
109
|
+
return { group: 'unclaimed', why: 'No spec yet', action: act('reply') };
|
|
110
|
+
}
|
|
111
|
+
case 'deploy':
|
|
112
|
+
if (item.state === 'running' || item.state === 'queued') return { group: 'motion', why: cap(item.state), action: act('logs') };
|
|
113
|
+
return { group: 'done', why: item.state === 'failure' ? 'Failed' : cap(item.state), bad: item.state === 'failure', action: null };
|
|
114
|
+
default: return null;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
const time = (iso) => { const t = Date.parse(text(iso)); return Number.isFinite(t) ? t : 0; };
|
|
119
|
+
/** Oldest first, so what has waited longest is on top (D2); Done lately newest first; then by id, so the order is the same for the same graph */
|
|
120
|
+
const oldest = (a, b) => time(a.item.updated) - time(b.item.updated) || (a.id < b.id ? -1 : a.id > b.id ? 1 : 0);
|
|
121
|
+
const newest = (a, b) => time(b.item.updated) - time(a.item.updated) || (a.id < b.id ? -1 : a.id > b.id ? 1 : 0);
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* The inbox of a work graph (D2 to D4).
|
|
125
|
+
* @param {{ nodes?: any[], edges?: any[] } | null} graph the server's answer
|
|
126
|
+
*/
|
|
127
|
+
export function inboxOf(graph) {
|
|
128
|
+
const nodes = (graph && Array.isArray(graph.nodes) ? graph.nodes : []).filter((n) => n && n.kind !== 'code' && typeof n.id === 'string');
|
|
129
|
+
const edges = graph && Array.isArray(graph.edges) ? graph.edges : [];
|
|
130
|
+
const byId = new Map(nodes.map((n) => [n.id, n]));
|
|
131
|
+
const rows = [];
|
|
132
|
+
let drafts = 0;
|
|
133
|
+
for (const item of nodes) {
|
|
134
|
+
if (item.kind === 'proposal' && item.state === 'local') { drafts += 1; continue; }
|
|
135
|
+
const place = placeOf(item, { edges, byId });
|
|
136
|
+
if (!place) continue;
|
|
137
|
+
rows.push({ id: item.id, item, tag: tagOf(item), group: place.group, why: place.why, bad: place.bad === true, action: place.action, counted: item.waiting === true, also: null, folded: false });
|
|
138
|
+
}
|
|
139
|
+
// D4: a waiting run about a spec that also waits rides in the spec's row
|
|
140
|
+
for (const r of rows) {
|
|
141
|
+
const slug = r.item.kind === 'run' && r.group === 'waiting' ? edges.find((e) => e.to === r.id && e.rel === 'agent-on' && byId.has(e.from) && byId.get(e.from).kind === 'proposal') : null;
|
|
142
|
+
if (!slug) continue;
|
|
143
|
+
const host = rows.find((x) => x.id === slug.from && x.group === 'waiting' && !x.also);
|
|
144
|
+
if (host) { host.also = r; r.folded = true; }
|
|
145
|
+
}
|
|
146
|
+
const groups = Object.fromEntries(GROUP_KEYS.map((k) => [k, rows.filter((r) => r.group === k && !r.folded).sort(k === 'done' ? newest : oldest)]));
|
|
147
|
+
const count = rows.filter((r) => r.counted).length;
|
|
148
|
+
return { groups, rows, drafts, count, rowsWaiting: groups.waiting.length };
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/** The queue's heading: "4 waiting on you in 3 rows", "1 waiting on you", "Nothing waits on you" */
|
|
152
|
+
export function headingOf({ count, rowsWaiting }) {
|
|
153
|
+
if (!count) return 'Nothing waits on you';
|
|
154
|
+
return `${count} waiting on you${rowsWaiting !== count ? ` in ${plural(rowsWaiting, 'row')}` : ''}`;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/** What a screen reader hears when the Inbox opens (D6): "Inbox: 4 waiting on you in 3 rows, 4 your move, 1 nobody on it." */
|
|
158
|
+
export function openedWords(inbox) {
|
|
159
|
+
const parts = [headingOf(inbox).replace(/^Nothing waits on you$/, 'nothing waits on you')];
|
|
160
|
+
if (inbox.groups.move.length) parts.push(`${inbox.groups.move.length} your move`);
|
|
161
|
+
if (inbox.groups.unclaimed.length) parts.push(`${inbox.groups.unclaimed.length} nobody on it`);
|
|
162
|
+
return `Inbox: ${parts.join(', ')}.`;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/** The ids in the order J and K move through them: the open groups' rows, top to bottom (D6) */
|
|
166
|
+
export function orderOf(inbox, open = new Set(GROUPS.filter((g) => g.open).map((g) => g.key))) {
|
|
167
|
+
return GROUP_KEYS.filter((k) => open.has(k)).flatMap((k) => inbox.groups[k].map((r) => r.id));
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/** The row after an action: the next one in the order, else the one before, else none (D6) */
|
|
171
|
+
export function nextAfter(order, id) {
|
|
172
|
+
const i = order.indexOf(id);
|
|
173
|
+
if (i < 0) return order[0] ?? null;
|
|
174
|
+
return order[i + 1] ?? order[i - 1] ?? null;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/** A row read out: its tag, title, why and how long ago (D6) */
|
|
178
|
+
export function rowWords(row, ago) {
|
|
179
|
+
return `${row.tag}, ${text(row.item.title)}. ${row.why}${row.also ? `, and ${row.also.tag} waits on your answer` : ''}. ${ago}.`;
|
|
180
|
+
}
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module explorer/pieces/inbox
|
|
3
|
+
*
|
|
4
|
+
* The Work inbox in cornfield's page (spec 0016 D1, D2, D5 to D8): the queue of what needs you, over the Work view's stage, beside the node panel. Its rules are
|
|
5
|
+
* inbox-model.js (pure); work-view.js owns the read of the graph and the Inbox · Graph toggle, and mounts this once.
|
|
6
|
+
*
|
|
7
|
+
* mount(stage, { pick, act, announce, refresh, colorOf, now }) -> { paint(graph, { on, selected }), focus(), destroy() }
|
|
8
|
+
*
|
|
9
|
+
* `pick(id)` selects a piece of work (the node panel opens on it, with its actions: spec 0015's action bar); `act(id)` selects it and does its primary action, the
|
|
10
|
+
* node panel's own button, with its confirm step. Every word from the forge is set as text, never as HTML. J and K (and the arrows) move through the open groups,
|
|
11
|
+
* Enter acts, a group's header folds it. Nothing is filed by hand (D7): a row moves when the graph says its state moved.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import { GROUPS, inboxOf, headingOf, openedWords, orderOf, rowWords } from '../inbox-model.js';
|
|
15
|
+
import { relativeTime } from '../review-model.js';
|
|
16
|
+
|
|
17
|
+
const SHAPE = { thread: 'circle', issue: 'circle', proposal: 'diamond', run: 'hexagon', pull: 'rounded', deploy: 'square' };
|
|
18
|
+
|
|
19
|
+
/** A small mark of the kind, drawn by its shape (the kind is said in words too: the row's tag) */
|
|
20
|
+
function glyph(kind, color) {
|
|
21
|
+
const ns = 'http://www.w3.org/2000/svg';
|
|
22
|
+
const svg = document.createElementNS(ns, 'svg');
|
|
23
|
+
svg.setAttribute('viewBox', '0 0 16 16');
|
|
24
|
+
svg.setAttribute('width', '16');
|
|
25
|
+
svg.setAttribute('height', '16');
|
|
26
|
+
svg.setAttribute('aria-hidden', 'true');
|
|
27
|
+
svg.setAttribute('class', `hx-inbox-glyph is-${kind}`);
|
|
28
|
+
if (color) svg.style.setProperty('--hx-glyph', color);
|
|
29
|
+
const shape = SHAPE[kind] || 'circle';
|
|
30
|
+
let el;
|
|
31
|
+
if (shape === 'circle') { el = document.createElementNS(ns, 'circle'); el.setAttribute('cx', '8'); el.setAttribute('cy', '8'); el.setAttribute('r', '6'); }
|
|
32
|
+
else if (shape === 'diamond') { el = document.createElementNS(ns, 'rect'); el.setAttribute('x', '3.5'); el.setAttribute('y', '3.5'); el.setAttribute('width', '9'); el.setAttribute('height', '9'); el.setAttribute('transform', 'rotate(45 8 8)'); }
|
|
33
|
+
else if (shape === 'hexagon') { el = document.createElementNS(ns, 'polygon'); el.setAttribute('points', '8,1.5 13.6,4.75 13.6,11.25 8,14.5 2.4,11.25 2.4,4.75'); }
|
|
34
|
+
else { el = document.createElementNS(ns, 'rect'); el.setAttribute('x', '2'); el.setAttribute('y', '2'); el.setAttribute('width', '12'); el.setAttribute('height', '12'); el.setAttribute('rx', shape === 'rounded' ? '3.5' : '1.5'); }
|
|
35
|
+
svg.append(el);
|
|
36
|
+
return svg;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** A number as data, and a kind's tag: the page's own `count` and `tag` hooks (docs/theming.md) */
|
|
40
|
+
const counted = (n) => { const el = make('span', 'hx-inbox-count', String(n)); el.dataset.corn = 'count'; el.setAttribute('part', 'count'); return el; };
|
|
41
|
+
const tagged = (words) => { const el = make('span', 'hx-inbox-tag', words); el.dataset.corn = 'tag'; el.setAttribute('part', 'tag'); return el; };
|
|
42
|
+
const make = (tag, cls, words) => { const el = document.createElement(tag); if (cls) el.className = cls; if (words != null) el.textContent = words; return el; };
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* @param {HTMLElement} stage the Work view's stage (the map's box)
|
|
46
|
+
* @param {{ pick: (id: string) => boolean, act: (id: string) => void, announce: (words: string) => void, now?: () => number, refresh: () => void, colorOf?: (kind: string) => string }} hooks
|
|
47
|
+
*/
|
|
48
|
+
export function mount(stage, hooks) {
|
|
49
|
+
const now = hooks.now || (() => Date.now());
|
|
50
|
+
const color = (kind) => (hooks.colorOf ? hooks.colorOf(kind) : '');
|
|
51
|
+
const root = make('section', 'hx-inbox');
|
|
52
|
+
root.dataset.corn = 'inbox';
|
|
53
|
+
root.setAttribute('part', 'inbox');
|
|
54
|
+
root.setAttribute('aria-label', 'Inbox');
|
|
55
|
+
root.hidden = true;
|
|
56
|
+
const queue = make('div', 'hx-inbox-queue');
|
|
57
|
+
const head = make('div', 'hx-inbox-head');
|
|
58
|
+
const title = make('h2', 'hx-inbox-title', 'Inbox');
|
|
59
|
+
const sub = make('span', 'hx-inbox-sub');
|
|
60
|
+
head.append(title, sub);
|
|
61
|
+
const list = make('div', 'hx-inbox-groups');
|
|
62
|
+
queue.append(head, list);
|
|
63
|
+
const aside = make('p', 'hx-inbox-pick', 'Pick a row: what it needs opens beside the queue.');
|
|
64
|
+
aside.dataset.corn = 'hint';
|
|
65
|
+
aside.setAttribute('part', 'hint');
|
|
66
|
+
root.append(queue, aside);
|
|
67
|
+
stage.append(root);
|
|
68
|
+
|
|
69
|
+
/** which groups are open: the ones GROUPS starts open, then as the viewer folds them (kept while the page is open) */
|
|
70
|
+
const open = new Set(GROUPS.filter((g) => g.open).map((g) => g.key));
|
|
71
|
+
let inbox = inboxOf(null);
|
|
72
|
+
let selected = null;
|
|
73
|
+
let was = false;
|
|
74
|
+
|
|
75
|
+
function paint(graph, { on, selected: sel = null } = {}) {
|
|
76
|
+
root.hidden = !on;
|
|
77
|
+
if (!on) { was = false; return; }
|
|
78
|
+
inbox = inboxOf(graph);
|
|
79
|
+
selected = sel;
|
|
80
|
+
sub.textContent = headingOf(inbox);
|
|
81
|
+
list.textContent = '';
|
|
82
|
+
if (!inbox.count) {
|
|
83
|
+
const empty = make('p', 'hx-inbox-empty');
|
|
84
|
+
empty.dataset.corn = 'empty';
|
|
85
|
+
empty.setAttribute('part', 'empty');
|
|
86
|
+
empty.append(make('strong', '', 'Nothing waits on you.'), document.createTextNode(' What is still yours to pick up is below.'));
|
|
87
|
+
list.append(empty);
|
|
88
|
+
}
|
|
89
|
+
for (const g of GROUPS) {
|
|
90
|
+
const rows = inbox.groups[g.key];
|
|
91
|
+
if (!rows.length) continue;
|
|
92
|
+
const isOpen = open.has(g.key);
|
|
93
|
+
const group = make('div', `hx-inbox-group is-${g.key}`);
|
|
94
|
+
group.dataset.corn = 'section';
|
|
95
|
+
group.setAttribute('part', 'section');
|
|
96
|
+
group.dataset.group = g.key;
|
|
97
|
+
const btn = make('button', 'hx-inbox-group-head');
|
|
98
|
+
btn.type = 'button';
|
|
99
|
+
btn.dataset.inboxGroup = g.key;
|
|
100
|
+
btn.setAttribute('aria-expanded', String(isOpen));
|
|
101
|
+
btn.append(make('span', 'hx-inbox-group-title', g.title), counted(rows.length));
|
|
102
|
+
if (g.hint) btn.append(make('span', 'hx-inbox-hint', g.hint));
|
|
103
|
+
group.append(btn);
|
|
104
|
+
if (isOpen) {
|
|
105
|
+
const ul = make('ul', 'hx-inbox-rows');
|
|
106
|
+
ul.setAttribute('aria-label', g.title);
|
|
107
|
+
for (const r of rows) ul.append(rowEl(r, g.key));
|
|
108
|
+
group.append(ul);
|
|
109
|
+
}
|
|
110
|
+
list.append(group);
|
|
111
|
+
}
|
|
112
|
+
if (inbox.drafts) {
|
|
113
|
+
const d = make('p', 'hx-inbox-drafts');
|
|
114
|
+
d.append(make('span', 'hx-inbox-group-title', 'Drafts in the checkout'), counted(inbox.drafts), make('span', 'hx-inbox-hint', 'nobody has been asked to decide them'));
|
|
115
|
+
list.append(d);
|
|
116
|
+
}
|
|
117
|
+
aside.hidden = !!selected;
|
|
118
|
+
if (!was) { hooks.announce(openedWords(inbox)); was = true; }
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
function rowEl(r, group) {
|
|
122
|
+
const li = make('li', `hx-inbox-row${r.id === selected || (r.also && r.also.id === selected) ? ' is-selected' : ''}`);
|
|
123
|
+
li.dataset.corn = 'row';
|
|
124
|
+
li.setAttribute('part', 'row');
|
|
125
|
+
li.dataset.id = r.id;
|
|
126
|
+
const ago = relativeTime(r.item.updated, now());
|
|
127
|
+
// The row is a list item holding two buttons (a row that is an option cannot hold a button): its line, which selects it and covers the row, and its action
|
|
128
|
+
const top = make('button', 'hx-inbox-line');
|
|
129
|
+
top.type = 'button';
|
|
130
|
+
top.dataset.inboxOpen = r.id;
|
|
131
|
+
top.setAttribute('aria-label', rowWords(r, ago));
|
|
132
|
+
if (r.id === selected) top.setAttribute('aria-current', 'true');
|
|
133
|
+
top.tabIndex = r.id === selected || (!selected && r.id === order()[0]) ? 0 : -1;
|
|
134
|
+
top.append(tagged(r.tag), make('span', 'hx-inbox-row-title', String(r.item.title || '')));
|
|
135
|
+
const why = make('span', `hx-inbox-why${r.bad ? ' is-bad' : ''}`, r.why);
|
|
136
|
+
li.append(glyph(r.item.kind, color(r.item.kind)), top, make('span', 'hx-inbox-age', ago), why);
|
|
137
|
+
if (r.action) {
|
|
138
|
+
const go = make('button', `hx-inbox-act${group === 'waiting' ? ' is-primary' : ''}`, r.action.label);
|
|
139
|
+
go.type = 'button';
|
|
140
|
+
go.tabIndex = -1;
|
|
141
|
+
go.dataset.inboxAct = r.id;
|
|
142
|
+
li.append(go);
|
|
143
|
+
}
|
|
144
|
+
if (r.also) {
|
|
145
|
+
const also = make('span', 'hx-inbox-also');
|
|
146
|
+
also.append(glyph('run', color('run')), document.createTextNode(` and ${r.also.tag} waits on your answer`));
|
|
147
|
+
li.append(also);
|
|
148
|
+
}
|
|
149
|
+
return li;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
const order = () => orderOf(inbox, open);
|
|
153
|
+
const rowOf = (id) => list.querySelector(`.hx-inbox-row[data-id="${CSS.escape(id)}"]`);
|
|
154
|
+
|
|
155
|
+
function choose(id, { focus = true } = {}) {
|
|
156
|
+
if (!id) return;
|
|
157
|
+
hooks.pick(id);
|
|
158
|
+
const el = rowOf(id);
|
|
159
|
+
if (el && focus) el.querySelector('[data-inbox-open]').focus();
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
function onClick(e) {
|
|
163
|
+
const t = e.target && e.target.closest ? e.target : null;
|
|
164
|
+
if (!t || !root.contains(t)) return;
|
|
165
|
+
const fold = t.closest('[data-inbox-group]');
|
|
166
|
+
if (fold) { const k = fold.dataset.inboxGroup; if (open.has(k)) open.delete(k); else open.add(k); hooks.refresh(); return; }
|
|
167
|
+
const go = t.closest('[data-inbox-act]');
|
|
168
|
+
if (go) { e.stopPropagation(); hooks.act(go.dataset.inboxAct); return; }
|
|
169
|
+
const row = t.closest('.hx-inbox-row');
|
|
170
|
+
if (row) choose(row.dataset.id, { focus: false });
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
function onKey(e) {
|
|
174
|
+
if (root.hidden || e.ctrlKey || e.metaKey || e.altKey) return;
|
|
175
|
+
const t = e.target;
|
|
176
|
+
if (!t || !root.contains(t) || (t.closest && t.closest('input, textarea, select'))) return;
|
|
177
|
+
const ids = order();
|
|
178
|
+
const cur = t.closest('.hx-inbox-row') ? t.closest('.hx-inbox-row').dataset.id : selected;
|
|
179
|
+
const i = ids.indexOf(cur);
|
|
180
|
+
let to = null;
|
|
181
|
+
if (e.key === 'j' || e.key === 'J' || e.key === 'ArrowDown') to = ids[Math.min(ids.length - 1, i + 1)] ?? ids[0];
|
|
182
|
+
else if (e.key === 'k' || e.key === 'K' || e.key === 'ArrowUp') to = ids[Math.max(0, i - 1)] ?? ids[0];
|
|
183
|
+
else if (e.key === 'Enter' && cur && t.closest('.hx-inbox-row')) { e.preventDefault(); hooks.act(cur); return; }
|
|
184
|
+
else return;
|
|
185
|
+
e.preventDefault();
|
|
186
|
+
if (to) choose(to);
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
root.addEventListener('click', onClick);
|
|
190
|
+
root.addEventListener('keydown', onKey);
|
|
191
|
+
|
|
192
|
+
return {
|
|
193
|
+
paint,
|
|
194
|
+
/** The focus on the selected row, else the first */
|
|
195
|
+
focus() { const el = (selected && rowOf(selected)) || list.querySelector('.hx-inbox-row'); if (el) el.querySelector('[data-inbox-open]').focus(); },
|
|
196
|
+
/** The row of the selection and the next one in the order (the selection moves there after an action: D6) */
|
|
197
|
+
order,
|
|
198
|
+
destroy() { root.removeEventListener('click', onClick); root.removeEventListener('keydown', onKey); root.remove(); },
|
|
199
|
+
el: root,
|
|
200
|
+
};
|
|
201
|
+
}
|
package/explorer/work-view.css
CHANGED
|
@@ -51,3 +51,54 @@ body:has(.hx-stage.is-work) .hx-layers :is([data-corn="legend-key"], [data-corn=
|
|
|
51
51
|
.hx-work-badges[hidden] { display: none; }
|
|
52
52
|
.hx-work-badge { position: absolute; box-sizing: border-box; display: inline-block; max-width: 14rem; padding: 0 var(--corn-space-1); border: var(--corn-border-strong) solid var(--hx-badge, var(--corn-line)); border-radius: var(--corn-radius-pill); background: color-mix(in srgb, var(--corn-surface-1) 92%, transparent); color: var(--corn-text); font-weight: 600; line-height: 1.3; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; transform: translateX(-50%); }
|
|
53
53
|
.hx-work-badge.is-waiting { border-width: calc(var(--corn-border-strong) + var(--corn-border)); }
|
|
54
|
+
/* The Work inbox (explorer/pieces/inbox.js, spec 0016): the queue over the stage, on the page's own ground, beside the node panel (which stays over it, as over the map).
|
|
55
|
+
The kind is said by its tag in words; the mark beside it is its shape in the kind's colour (`--hx-glyph`, set from `--corn-work-<kind>` as the badges' is). */
|
|
56
|
+
.hx-work-as { display: inline-flex; gap: 0; }
|
|
57
|
+
.hx-work-as .hx-view-control:first-child { border-top-right-radius: 0; border-bottom-right-radius: 0; }
|
|
58
|
+
.hx-work-as .hx-view-control:last-child { border-top-left-radius: 0; border-bottom-left-radius: 0; border-left-width: 0; }
|
|
59
|
+
.hx-inbox { position: absolute; inset: 0; z-index: 4; display: grid; grid-template-columns: minmax(20rem, 28rem) 1fr; background: var(--corn-ground); color: var(--corn-text); }
|
|
60
|
+
.hx-inbox[hidden] { display: none; }
|
|
61
|
+
.hx-stage.is-inbox .hx-work-badges, .hx-stage.is-inbox .hx-work-lanes { display: none; }
|
|
62
|
+
.hx-inbox-queue { overflow-y: auto; min-height: 0; padding: var(--corn-space-2) 0 var(--corn-space-8); border-right: var(--corn-border) solid var(--corn-line); background: var(--corn-surface-1); }
|
|
63
|
+
.hx-inbox-head { display: flex; align-items: baseline; gap: var(--corn-space-2); padding: var(--corn-space-3) var(--corn-space-4) var(--corn-space-1); }
|
|
64
|
+
.hx-inbox-title { margin: 0; font-size: var(--corn-text-md); font-weight: 600; }
|
|
65
|
+
.hx-inbox-sub { color: var(--corn-text-3); font-size: var(--corn-text-sm); }
|
|
66
|
+
.hx-inbox-empty { margin: var(--corn-space-3) var(--corn-space-4); color: var(--corn-text-2); font-size: var(--corn-text-sm); }
|
|
67
|
+
.hx-inbox-empty strong { display: block; color: var(--corn-text); font-size: var(--corn-text-md); margin-bottom: var(--corn-space-1); }
|
|
68
|
+
.hx-inbox-group { margin-top: var(--corn-space-2); }
|
|
69
|
+
.hx-inbox-group-head, .hx-inbox-drafts { display: flex; align-items: center; gap: var(--corn-space-2); width: 100%; margin: 0; padding: var(--corn-space-2) var(--corn-space-4); border: 0; background: none; color: var(--corn-text-3); font-size: var(--corn-text-xs); font-weight: 600; letter-spacing: 0.05em; text-transform: uppercase; text-align: left; cursor: pointer; }
|
|
70
|
+
.hx-inbox-drafts { cursor: default; }
|
|
71
|
+
.hx-inbox-group-head::after { content: '▾'; margin-left: auto; }
|
|
72
|
+
.hx-inbox-group-head[aria-expanded="false"]::after { content: '▸'; }
|
|
73
|
+
.hx-inbox-group.is-waiting .hx-inbox-group-head { color: var(--corn-warn, var(--corn-text-2)); }
|
|
74
|
+
.hx-inbox-count { font-variant-numeric: tabular-nums; }
|
|
75
|
+
.hx-inbox-hint { font-weight: 400; letter-spacing: 0; text-transform: none; }
|
|
76
|
+
.hx-inbox-rows { list-style: none; margin: 0; padding: 0 var(--corn-space-2); display: grid; gap: calc(var(--corn-space-1) / 2); }
|
|
77
|
+
.hx-inbox-row { position: relative; display: grid; grid-template-columns: 1.25rem minmax(0, 1fr) auto; gap: calc(var(--corn-space-1) / 2) var(--corn-space-3); align-items: start; padding: var(--corn-space-2) var(--corn-space-3); border: var(--corn-border) solid transparent; border-radius: var(--corn-radius); cursor: pointer; }
|
|
78
|
+
.hx-inbox-row:hover { background: var(--corn-surface-2); }
|
|
79
|
+
.hx-inbox-row.is-selected { background: var(--corn-accent-soft, var(--corn-surface-3)); border-color: var(--corn-accent); }
|
|
80
|
+
.hx-inbox-glyph { grid-row: span 2; margin-top: calc(var(--corn-space-1) / 2); }
|
|
81
|
+
.hx-inbox-glyph > * { fill: var(--hx-glyph, var(--corn-text-3)); }
|
|
82
|
+
.hx-inbox-line { min-width: 0; margin: 0; padding: 0; border: 0; background: none; color: inherit; font: inherit; text-align: left; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: var(--corn-text-sm); font-weight: 500; cursor: pointer; }
|
|
83
|
+
/* The line is the row's button: it covers the row (its action stays over it), and its focus ring is the row's */
|
|
84
|
+
.hx-inbox-line::after { content: ''; position: absolute; inset: 0; border-radius: var(--corn-radius); }
|
|
85
|
+
.hx-inbox-line:focus-visible { outline: none; }
|
|
86
|
+
.hx-inbox-row:has(.hx-inbox-line:focus-visible) { outline: var(--corn-focus-width) solid var(--corn-focus); outline-offset: calc(0px - var(--corn-focus-width)); }
|
|
87
|
+
.hx-inbox-tag { margin-right: var(--corn-space-1); color: var(--corn-text-3); font-weight: 400; font-variant-numeric: tabular-nums; }
|
|
88
|
+
.hx-inbox-age { color: var(--corn-text-3); font-size: var(--corn-text-xs); white-space: nowrap; font-variant-numeric: tabular-nums; }
|
|
89
|
+
.hx-inbox-why { grid-column: 2; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--corn-text-2); font-size: var(--corn-text-xs); }
|
|
90
|
+
.hx-inbox-why.is-bad { color: var(--corn-bad); }
|
|
91
|
+
.hx-inbox-act { grid-column: 3; grid-row: 2; height: 1.6rem; padding: 0 var(--corn-space-3); border-radius: var(--corn-radius-sm); border: var(--corn-border) solid var(--corn-line); background: var(--corn-surface-2); color: var(--corn-text); font-size: var(--corn-text-xs); white-space: nowrap; cursor: pointer; opacity: 0; position: relative; z-index: 1; }
|
|
92
|
+
.hx-inbox-act.is-primary { background: var(--corn-accent); border-color: var(--corn-accent); color: var(--corn-text-on-accent); font-weight: 600; }
|
|
93
|
+
.hx-inbox-row:hover .hx-inbox-act, .hx-inbox-row.is-selected .hx-inbox-act, .hx-inbox-row:focus-within .hx-inbox-act { opacity: 1; }
|
|
94
|
+
@media (hover: none) { .hx-inbox-act { opacity: 1; } }
|
|
95
|
+
.hx-inbox-also { grid-column: 2 / 4; display: flex; align-items: center; gap: var(--corn-space-1); color: var(--corn-warn, var(--corn-text-2)); font-size: var(--corn-text-xs); }
|
|
96
|
+
.hx-inbox-also .hx-inbox-glyph { grid-row: auto; margin: 0; width: 12px; height: 12px; }
|
|
97
|
+
.hx-inbox-pick { align-self: center; justify-self: center; max-width: 24rem; margin: 0; color: var(--corn-text-3); font-size: var(--corn-text-sm); text-align: center; }
|
|
98
|
+
.hx-inbox-pick[hidden] { display: none; }
|
|
99
|
+
@container corn-box (max-width: 767px) {
|
|
100
|
+
/* The Layers chip and the view's controls float on the map's top two rows here (layers.css, header.css): the queue starts under them */
|
|
101
|
+
.hx-inbox { grid-template-columns: 1fr; padding-top: calc(2 * var(--hx-control-h) + 2 * var(--corn-space-4)); }
|
|
102
|
+
.hx-inbox-queue { border-right: 0; border-top: var(--corn-border) solid var(--corn-line); }
|
|
103
|
+
.hx-inbox-pick { display: none; }
|
|
104
|
+
}
|
package/explorer/work-view.js
CHANGED
|
@@ -46,6 +46,7 @@ import { workButtonName } from './waiting-model.js';
|
|
|
46
46
|
import { stepFrom } from './keyboard-model.js';
|
|
47
47
|
import { RUNS_POLL_MS } from './pieces/work-common.js';
|
|
48
48
|
import { showWorkRef, openForge, closeForge } from './forge-panel.js';
|
|
49
|
+
import { mount as mountInbox } from './pieces/inbox.js';
|
|
49
50
|
import {
|
|
50
51
|
CODE_LAYER, DRAFT_LAYER, KIND_WORDS, addressOf, applyFilters, areaFor, arrowTarget, drawnEdges, landingWords, applyWorkLayout, codePanelHtml, layerRowsOf, newWorkState, nodeForAddress, openedWords, panelOf, setOpenArea, setWorkGraph, showWork, touchedBy, workAddress, workPanelHtml,
|
|
51
52
|
} from './work-model.js';
|
|
@@ -62,11 +63,20 @@ let offPaint = null;
|
|
|
62
63
|
let badges = null; // the Work layer's pills over the map (work-badges.js)
|
|
63
64
|
let badgeWas = false; // whether the layer wanted the graph at the last look: it asks for it when it comes on
|
|
64
65
|
let card = null; // the map's own card (pieces/status.js)
|
|
66
|
+
let inbox = null; // the Work inbox over the stage (pieces/inbox.js, spec 0016)
|
|
65
67
|
let timer = 0;
|
|
66
68
|
let seq = 0; // the answer that is waited for: an older one is dropped
|
|
67
69
|
let wasOn = false;
|
|
68
70
|
|
|
69
71
|
const inst = () => pageInstance();
|
|
72
|
+
|
|
73
|
+
/** Inbox or Graph (spec 0016 D1): the Work view opens on the Inbox; the choice is remembered like a layer */
|
|
74
|
+
const AS_KEY = 'cornfield.work.as';
|
|
75
|
+
function rememberedAs() {
|
|
76
|
+
try { return localStorage.getItem(AS_KEY) === 'graph' ? 'graph' : 'inbox'; } catch { return 'inbox'; }
|
|
77
|
+
}
|
|
78
|
+
const asOf = () => { const w = work(); if (w.as !== 'inbox' && w.as !== 'graph') w.as = rememberedAs(); return w.as; };
|
|
79
|
+
const inInbox = () => on() && asOf() === 'inbox';
|
|
70
80
|
const work = () => state.work || (state.work = newWorkState());
|
|
71
81
|
const on = () => state.view === 'work';
|
|
72
82
|
|
|
@@ -148,7 +158,8 @@ function mount() {
|
|
|
148
158
|
if (!stage || (els && els.stage === stage && els.bar.isConnected && stage.contains(els.lanes))) return;
|
|
149
159
|
const bar = controlsSlot(stage);
|
|
150
160
|
bar.hidden = true;
|
|
151
|
-
bar.innerHTML = '<button type="button" class="hx-view-control" data-corn="work-chip" data-corn-kind="secondary" data-work-
|
|
161
|
+
bar.innerHTML = '<span class="hx-work-as" role="group" aria-label="Show the work as"><button type="button" class="hx-view-control" data-corn="work-chip" data-corn-kind="secondary" data-work-as="inbox" aria-pressed="true" title="What needs you, in a queue (G switches)">Inbox</button><button type="button" class="hx-view-control" data-corn="work-chip" data-corn-kind="secondary" data-work-as="graph" aria-pressed="false" title="The lanes of work and the code they touch (G switches)">Graph</button></span>'
|
|
162
|
+
+ '<button type="button" class="hx-view-control" data-corn="work-chip" data-corn-kind="secondary" data-work-toggle="waiting" aria-pressed="false" title="Show only what waits on you; the rest is dimmed">Waiting on you</button>'
|
|
152
163
|
+ '<button type="button" class="hx-view-control" data-corn="work-chip" data-corn-kind="secondary" data-action="toggle-forge" aria-expanded="false" aria-controls="forge-panel" aria-label="Work list" title="The lists of issues, pull requests, proposals, threads, runs and deploys" hidden>List</button>'
|
|
153
164
|
+ '<span class="hx-work-busy" hidden>Updating…</span>';
|
|
154
165
|
const note = document.createElement('p');
|
|
@@ -169,7 +180,15 @@ function mount() {
|
|
|
169
180
|
loading.innerHTML = `<div class="hx-work-skeleton" aria-hidden="true">${['Talk', 'Decide', 'Build', 'Ship', 'Code it touches'].map((name) => `<div class="hx-work-skel-lane"><span class="hx-work-lane-title">${name}</span><i></i><i></i><i></i><i></i></div>`).join('')}</div>`
|
|
170
181
|
+ '<p class="hx-work-loading-text" role="status">Reading the work from the forge. A big repository can take several seconds the first time; the page works meanwhile.</p>';
|
|
171
182
|
stage.append(lanes, loading, note);
|
|
172
|
-
els = { stage, bar,
|
|
183
|
+
els = { stage, bar, as: bar.children[0], waiting: bar.children[1], list: bar.children[2], busy: bar.children[3], note, lanes, loading };
|
|
184
|
+
if (inbox) inbox.destroy();
|
|
185
|
+
inbox = mountInbox(stage, {
|
|
186
|
+
pick: (id) => pick(id, { frame: false, source: 'link' }),
|
|
187
|
+
act: (id) => actOn(id),
|
|
188
|
+
announce: (words) => announce(inst(), words),
|
|
189
|
+
colorOf: (kind) => badgeColor(kind),
|
|
190
|
+
refresh: () => paintInbox(),
|
|
191
|
+
});
|
|
173
192
|
paintList(!!inst().ask('work:on')); // the List toggle is there while the Work piece is on: a signed-in maintainer of a forge
|
|
174
193
|
if (offPaint) offPaint();
|
|
175
194
|
if (badges) badges.destroy();
|
|
@@ -205,7 +224,7 @@ function watchSize(stage) {
|
|
|
205
224
|
function paintLanes(scene, camera) {
|
|
206
225
|
if (!els) return;
|
|
207
226
|
const w = work();
|
|
208
|
-
const show = on() && w.status === 'ok' && w.lanes.length > 0;
|
|
227
|
+
const show = on() && !inInbox() && w.status === 'ok' && w.lanes.length > 0;
|
|
209
228
|
els.lanes.hidden = !show;
|
|
210
229
|
if (!show) return;
|
|
211
230
|
if (laneKey !== w.lanes) {
|
|
@@ -258,11 +277,48 @@ function paintBar() {
|
|
|
258
277
|
const w = work();
|
|
259
278
|
els.bar.hidden = !on();
|
|
260
279
|
els.waiting.setAttribute('aria-pressed', String(!!w.waiting)); // the Work button's badge says how many; the toggle says only that it is on
|
|
280
|
+
els.waiting.hidden = inInbox(); // the Inbox is what waits on you, in a queue: dimming is the Graph's
|
|
281
|
+
for (const b of els.as.querySelectorAll('[data-work-as]')) b.setAttribute('aria-pressed', String(b.dataset.workAs === asOf()));
|
|
282
|
+
if (els.stage) els.stage.classList.toggle('is-inbox', inInbox());
|
|
261
283
|
els.busy.hidden = !(on() && w.status === 'ok' && w.updating);
|
|
262
284
|
els.loading.hidden = !(on() && w.status === 'loading');
|
|
263
285
|
const lines = [...(w.stale ? [w.stale] : []), ...(w.lastError ? [w.lastError] : []), ...w.problems.map((p) => p.text)];
|
|
264
286
|
els.note.hidden = !on() || !lines.length;
|
|
265
287
|
els.note.textContent = lines.length ? lines.slice(0, 2).join(' ') + (lines.length > 2 ? ` and ${lines.length - 2} more.` : '') : '';
|
|
288
|
+
paintInbox();
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
/** The Inbox drawn from the last answer, the selection marked (spec 0016); hidden in the Graph and off the Work view */
|
|
292
|
+
function paintInbox() {
|
|
293
|
+
if (!inbox) return;
|
|
294
|
+
const w = work();
|
|
295
|
+
inbox.paint(w.graph, { on: inInbox() && w.status === 'ok', selected: state.selectedNode ? state.selectedNode.id : null });
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
/** Inbox or Graph (spec 0016 D1), remembered; the Graph is fitted again as it comes back */
|
|
299
|
+
function setAs(as) {
|
|
300
|
+
const w = work();
|
|
301
|
+
if (asOf() === as) return;
|
|
302
|
+
w.as = as;
|
|
303
|
+
try { localStorage.setItem(AS_KEY, as); } catch { /* remembering is a convenience */ }
|
|
304
|
+
paintBar();
|
|
305
|
+
if (on() && w.status === 'ok' && as === 'graph') { applyWorkLayout(state, { phone: isPhone() }); inst().touchScene(); fitGraphToViewport(fitPadding()); render(); }
|
|
306
|
+
if (as === 'inbox' && inbox) inbox.focus();
|
|
307
|
+
announce(inst(), as === 'inbox' ? 'Inbox.' : 'Graph: the lanes of work.');
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
/** A row's action (spec 0016 D5, D6): its piece of work is selected and the node panel's own primary action is pressed, with the confirm step it has there */
|
|
311
|
+
function actOn(id) {
|
|
312
|
+
if (!pick(id, { frame: false, source: 'link' })) return;
|
|
313
|
+
const t0 = Date.now();
|
|
314
|
+
const press = () => {
|
|
315
|
+
const bar = document.querySelector('[data-corn="node-panel"] [data-corn="actions"]');
|
|
316
|
+
const btn = bar ? bar.querySelector('button:not([disabled]), a[href]') : null;
|
|
317
|
+
if (btn) { btn.click(); return; }
|
|
318
|
+
if (Date.now() - t0 < 2000) setTimeout(press, 60); // the Work piece draws a piece of work's actions once what it needs is read
|
|
319
|
+
else announce(inst(), 'Its actions are in the panel.');
|
|
320
|
+
};
|
|
321
|
+
setTimeout(press, 0);
|
|
266
322
|
}
|
|
267
323
|
|
|
268
324
|
/** The view opened or closed: the button, the bar, the stage; the map's own layers are back when it closed (work-model.js `leaveWork`) */
|
|
@@ -569,6 +625,7 @@ let opened = null;
|
|
|
569
625
|
*/
|
|
570
626
|
function onSelection({ node: picked }) {
|
|
571
627
|
if (!on() || work().status !== 'ok') return;
|
|
628
|
+
paintInbox();
|
|
572
629
|
if (!picked) { openArea(null); return; }
|
|
573
630
|
const node = work().nodes.find((n) => n.id === picked.id); // the view's own node (a tap names the scene's)
|
|
574
631
|
if (!node) return;
|
|
@@ -638,6 +695,11 @@ function pickRef(ref) {
|
|
|
638
695
|
// Keys (the map's own are for the other views: Shift and an arrow still pan, the rest are the map's)
|
|
639
696
|
// ---------------------------------------------------------------------------
|
|
640
697
|
function onKey(e) {
|
|
698
|
+
if (on() && !e.defaultPrevented && !e.ctrlKey && !e.metaKey && !e.altKey && (e.key === 'g' || e.key === 'G') && !(e.target && e.target.closest && e.target.closest('input, textarea, select, [contenteditable="true"]'))) {
|
|
699
|
+
e.preventDefault();
|
|
700
|
+
setAs(asOf() === 'inbox' ? 'graph' : 'inbox');
|
|
701
|
+
return;
|
|
702
|
+
}
|
|
641
703
|
if (!on() || e.defaultPrevented || e.ctrlKey || e.metaKey || e.altKey || !state.canvas || e.target !== state.canvas) return;
|
|
642
704
|
const shown = shownInOrder();
|
|
643
705
|
if (!shown.length) return;
|
|
@@ -663,6 +725,8 @@ function onClick(e) {
|
|
|
663
725
|
if (t_.closest('[data-action="preset-work"]')) { if (on()) closeWork(); else openWork(); return; }
|
|
664
726
|
if (t_.closest('[data-action="refresh-forge"]') && on()) { load({ again: true }); return; }
|
|
665
727
|
if (t_.closest('[data-work-toggle="waiting"]') && on()) { setWaiting(!work().waiting); return; }
|
|
728
|
+
const as = t_.closest('[data-work-as]');
|
|
729
|
+
if (as && on()) { setAs(as.dataset.workAs); return; }
|
|
666
730
|
const act = t_.closest('[data-work-action]');
|
|
667
731
|
if (!act) return;
|
|
668
732
|
if (act.dataset.workAction === 'open-item') { // a node panel's "Open work" link: the Work view opens on that piece of work (a new tab, by the link's own address, is left alone)
|
|
@@ -702,6 +766,7 @@ export async function followWorkAddress(search = location.search) {
|
|
|
702
766
|
if (!ask) return false;
|
|
703
767
|
if (!offered) { announce(inst(), 'The map of work needs a forge in the config.'); return false; }
|
|
704
768
|
spend();
|
|
769
|
+
try { const as = new URLSearchParams(search).get('as'); if (as === 'graph' || as === 'inbox') work().as = as; } catch { /* the address is a convenience */ }
|
|
705
770
|
return openWork({ ask: ask.kind ? ask : null });
|
|
706
771
|
}
|
|
707
772
|
|
|
@@ -733,6 +798,8 @@ export function resetWorkViewForTests() {
|
|
|
733
798
|
offered = false;
|
|
734
799
|
els = null;
|
|
735
800
|
card = null;
|
|
801
|
+
if (inbox) inbox.destroy();
|
|
802
|
+
inbox = null;
|
|
736
803
|
seq++;
|
|
737
804
|
wasOn = false;
|
|
738
805
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cornfield",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.64.0",
|
|
4
4
|
"description": "A self-hostable dev dashboard with the topology map at its centre: proposals on the map, scenarios, outages and what-if edits, for any repo.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "popcorn245 (https://github.com/popcorn245)",
|
package/server/work-graph.js
CHANGED
|
@@ -15,7 +15,8 @@
|
|
|
15
15
|
* deploy deploy:<id> ship a workflow run the config says is a deploy (server/deploys.js)
|
|
16
16
|
*
|
|
17
17
|
* Every node: `{ id, kind, stage, title, state, open, waiting, url, updated, ...}` and its number (`number`), slug (`slug`), run id (`runId`) or
|
|
18
|
-
* deploy id (`deployId`). `
|
|
18
|
+
* deploy id (`deployId`). A run also carries `note` (its report's last word, the question when it waits), `brief` and `pull` (`{ number, state }` of the pull
|
|
19
|
+
* request it opened); an open pull request `checks` (`checkCounts`: failed, running, passed, green and the names), or null when they could not be read (spec 0016 D9). `waiting` is spec 0010 D1's rule, worked out by the same functions the page's number uses (explorer/waiting-model.js
|
|
19
20
|
* `specStateOf`, explorer/runs-model.js `canAnswer`): a spec to decide, a run waiting on an answer; nothing else asks the maintainer a question.
|
|
20
21
|
* The code a proposal adds, and the map does not hold yet, comes as `{ id, kind: 'code', planned: true, label, type, parent }`; the code that exists is
|
|
21
22
|
* on the map the page already has, and is only named by edges.
|
|
@@ -51,7 +52,7 @@
|
|
|
51
52
|
*/
|
|
52
53
|
|
|
53
54
|
import fs from 'node:fs';
|
|
54
|
-
import { DEFAULT_LIMIT, ForgeError } from './forge.js';
|
|
55
|
+
import { DEFAULT_LIMIT, ForgeError, isGreen, RERUN_STATES } from './forge.js';
|
|
55
56
|
import { filesAt, forgeWords, pullProposals, readPullProposal, reviewStates } from './proposal-pulls.js';
|
|
56
57
|
import { listProposalFiles } from './files.js';
|
|
57
58
|
import { deploysOf } from './deploys.js';
|
|
@@ -152,6 +153,48 @@ async function each(items, fn) {
|
|
|
152
153
|
return out;
|
|
153
154
|
}
|
|
154
155
|
|
|
156
|
+
/** The longest a run's note or brief is carried, in characters */
|
|
157
|
+
export const NOTE_CUT = 300;
|
|
158
|
+
const clip = (s, n) => (s.length > n ? `${s.slice(0, n - 1)}…` : s);
|
|
159
|
+
/** The states a check is still on its way in */
|
|
160
|
+
const GOING = new Set(['queued', 'running', 'pending', 'in_progress', 'waiting']);
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* A commit's checks as counts (spec 0016 D9): failed (failed or cancelled), running (queued or running), passed, and `green` as landing reads it
|
|
164
|
+
* (server/forge.js `isGreen`). The inbox says "lint failed · test running" from the names of the failed and running ones (`failedNames`, `runningNames`, at most five each).
|
|
165
|
+
* @param {{ name: string, state: string }[]} checks
|
|
166
|
+
*/
|
|
167
|
+
export function checkCounts(checks) {
|
|
168
|
+
const list = Array.isArray(checks) ? checks : [];
|
|
169
|
+
const failed = list.filter((c) => RERUN_STATES.includes(c.state));
|
|
170
|
+
const going = list.filter((c) => GOING.has(c.state));
|
|
171
|
+
return {
|
|
172
|
+
failed: failed.length, running: going.length, passed: list.filter((c) => c.state === 'success').length, green: isGreen(list),
|
|
173
|
+
failedNames: failed.slice(0, 5).map((c) => text(c.name)), runningNames: going.slice(0, 5).map((c) => text(c.name)),
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/** How long a head's checks are kept: while one runs, a minute (the page asks every minute); once all are over, ten (a re-run starts them again) */
|
|
178
|
+
export const CHECKS_KEEP_RUNNING_MS = 60_000;
|
|
179
|
+
export const CHECKS_KEEP_DONE_MS = 10 * 60_000;
|
|
180
|
+
const CHECKS_KEPT_MAX = 500;
|
|
181
|
+
/** where -> sha -> { at, keep, counts } */
|
|
182
|
+
const checkCaches = new WeakMap();
|
|
183
|
+
|
|
184
|
+
/** The checks at a head sha as counts, kept per `where` (CHECKS_KEEP_*); a failed read is never kept */
|
|
185
|
+
async function checksAt(forge, where, sha, nowMs) {
|
|
186
|
+
const key = where && typeof where === 'object' ? where : checkCaches;
|
|
187
|
+
let kept = checkCaches.get(key);
|
|
188
|
+
if (!kept) checkCaches.set(key, (kept = new Map()));
|
|
189
|
+
const got = kept.get(sha);
|
|
190
|
+
if (got && nowMs - got.at < got.keep) return got.counts;
|
|
191
|
+
const counts = checkCounts(await forge.checks(sha));
|
|
192
|
+
kept.delete(sha);
|
|
193
|
+
kept.set(sha, { at: nowMs, keep: counts.running ? CHECKS_KEEP_RUNNING_MS : CHECKS_KEEP_DONE_MS, counts });
|
|
194
|
+
while (kept.size > CHECKS_KEPT_MAX) kept.delete(kept.keys().next().value);
|
|
195
|
+
return counts;
|
|
196
|
+
}
|
|
197
|
+
|
|
155
198
|
/** An id of the work graph's own: a map node with one would be two things */
|
|
156
199
|
const WORK_ID = /^(?:thread|issue|proposal|run|pull|deploy):/;
|
|
157
200
|
/** A link the page may open: http(s) only; anything else (a runner's report saying `javascript:`) is no link */
|
|
@@ -338,10 +381,21 @@ export async function workGraph(forge, config, map, { where = config, runs = nul
|
|
|
338
381
|
}
|
|
339
382
|
}
|
|
340
383
|
|
|
384
|
+
// The checks on each open pull request's head, as counts (spec 0016 D9): asked each time, since a head's checks move while it stays
|
|
385
|
+
const checkable = pulls.filter((p) => !specEntries.has(p.number) && p.state === 'open' && p.head && p.head.sha);
|
|
386
|
+
const gotChecks = await each(checkable, (pull) => attempt(() => checksAt(forge, where, pull.head.sha, nowMs)));
|
|
387
|
+
const checksOf = new Map();
|
|
388
|
+
const noChecks = [];
|
|
389
|
+
for (const [i, pull] of checkable.entries()) {
|
|
390
|
+
if (gotChecks[i].err) noChecks.push(pull.number);
|
|
391
|
+
else checksOf.set(pull.number, gotChecks[i].value);
|
|
392
|
+
}
|
|
393
|
+
if (noChecks.length) say('pulls', `The checks of ${noChecks.length === 1 ? 'pull request' : 'pull requests'} ${numbers(noChecks)} could not be read, so they are not said.`);
|
|
394
|
+
|
|
341
395
|
for (const pull of pulls) {
|
|
342
396
|
if (specEntries.has(pull.number)) continue;
|
|
343
397
|
const id = `pull:${pull.number}`;
|
|
344
|
-
put({ id, kind: 'pull', title: pull.title, state: pull.state, open: pull.state === 'open', number: pull.number, url: webUrl(pull.url), updated: pull.updatedAt, draft: pull.draft, author: pull.author ? pull.author.login : null });
|
|
398
|
+
put({ id, kind: 'pull', title: pull.title, state: pull.state, open: pull.state === 'open', number: pull.number, url: webUrl(pull.url), updated: pull.updatedAt, draft: pull.draft, author: pull.author ? pull.author.login : null, checks: checksOf.get(pull.number) ?? null });
|
|
345
399
|
byPull.set(pull.number, [id]);
|
|
346
400
|
if (filesOf.has(pull.number)) for (const to of nodesOfFiles(filesOf.get(pull.number), mapNodes)) edge(id, to, 'changes');
|
|
347
401
|
}
|
|
@@ -459,6 +513,9 @@ export async function workGraph(forge, config, map, { where = config, runs = nul
|
|
|
459
513
|
put({
|
|
460
514
|
id, kind: 'run', title: runName(run), state: run.status, open: run.open === true, waiting: canAnswer(run), runId: run.runId, number: null, url: webUrl(run.report && run.report.url) || webUrl(run.comment && run.comment.url) || webUrl(run.pull && run.pull.url),
|
|
461
515
|
updated: ended, requestedBy: run.requestedBy ?? null,
|
|
516
|
+
// what the inbox says of it (spec 0016 D9): its question or last word, what it was asked to do, and the pull request it opened
|
|
517
|
+
note: clip(text(run.report && run.report.note), NOTE_CUT) || null, brief: clip(text(run.brief), NOTE_CUT) || null,
|
|
518
|
+
pull: run.pull && Number.isInteger(run.pull.number) ? { number: run.pull.number, state: text(run.pull.state) || null } : null,
|
|
462
519
|
});
|
|
463
520
|
const about = [run.refs && run.refs.issue, run.refs && run.refs.thread].filter((n) => n != null).map(talkNode).filter(Boolean);
|
|
464
521
|
for (const from of new Set(about)) edge(from, id, 'agent-on');
|