@intentius/behold 0.29.32 → 0.29.34
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/package.json +1 -1
- package/web/app.js +93 -2
- package/web/event-help-modal.js +280 -0
- package/web/event-help-modal.test.js +180 -0
- package/web/event-help-store.js +23 -0
- package/web/index.html +4 -1
- package/web/kiosk-event-help-ui.js +397 -0
- package/web/kiosk-event-help.js +255 -0
- package/web/kiosk-event-help.test.js +162 -0
- package/web/kiosk-runs.js +18 -1
- package/web/kiosk-trace.js +72 -13
- package/web/kiosk-trace.test.js +14 -0
- package/web/kiosk-watch.js +43 -3
- package/web/kiosk-watch.test.js +31 -1
- package/web/kiosk-wave-traces.js +104 -0
- package/web/kiosk-wave-traces.test.js +53 -0
- package/web/kiosk.html +33 -0
- package/web/kiosk.js +317 -25
- package/web/kiosk.test.js +18 -0
|
@@ -0,0 +1,397 @@
|
|
|
1
|
+
// behold#571: event-help in the kiosk, the "Tips". The events come from
|
|
2
|
+
// web/kiosk-event-help.js; this draws them:
|
|
3
|
+
//
|
|
4
|
+
// - a tip, one short line, pops from the thing on screen an event is about (a
|
|
5
|
+
// card or a wave box in the graph, a job row, the approval panel, a metrics
|
|
6
|
+
// badge), for TIP_MS, two at once at most, then shrinks toward the trail;
|
|
7
|
+
// - the event's subjects light together across the panes for that time, as
|
|
8
|
+
// a hover lights them (`light`), and the thing the tip points at glows;
|
|
9
|
+
// - the story trail: the cycle's beats as chips, quiet, under the header in
|
|
10
|
+
// Inspect and by the caption in Watch; a chip, pointed at or clicked,
|
|
11
|
+
// shows its tip and its lights again;
|
|
12
|
+
// - a critical event (a wave held, a wave failed, the cycle applied) opens
|
|
13
|
+
// web/event-help-modal.js, narrated (or replayed on a tool's page).
|
|
14
|
+
//
|
|
15
|
+
// The Tips switch, on by default and kept per viewer, turns the tips, the
|
|
16
|
+
// lights, the glows and the modals off; the trail stays, since it is the
|
|
17
|
+
// record.
|
|
18
|
+
|
|
19
|
+
import { EH_STORE, LATE_ORDER, TIP_MS, cycleFacts, ehSnapshot, ehStore, ehStored, modalQueue, newEvents, storyTrail, tipsQueue } from "./kiosk-event-help.js";
|
|
20
|
+
|
|
21
|
+
/** How long after the page opens (or the cycle turns) what arrives is the story so far, not news: the reads land one by one. */
|
|
22
|
+
export const SETTLE_MS = 8_000;
|
|
23
|
+
import { modalStyle, openEventModal } from "./event-help-modal.js";
|
|
24
|
+
|
|
25
|
+
/** The switch's label, and its title. */
|
|
26
|
+
export const TIPS_WORDS = "Tips";
|
|
27
|
+
export const TIPS_TITLE = "Short notes on what just happened, beside the things they are about";
|
|
28
|
+
/** The trail's label. */
|
|
29
|
+
export const TRAIL_WORDS = "This cycle";
|
|
30
|
+
|
|
31
|
+
const STYLE = `
|
|
32
|
+
#eh-trail { display: flex; flex-wrap: nowrap; align-items: center; gap: 0.35em; overflow-x: auto; scrollbar-width: none; contain: inline-size; min-width: 0; padding: 0.15em 0.9em 0.3em; font-size: 0.78em; color: var(--muted); min-height: 1.9em; }
|
|
33
|
+
#eh-trail::-webkit-scrollbar { display: none; }
|
|
34
|
+
#eh-trail[hidden] { display: none; }
|
|
35
|
+
.eh-trail-label { font: 600 0.85em var(--font-mono); text-transform: uppercase; letter-spacing: 0.06em; margin-right: 0.3em; white-space: nowrap; }
|
|
36
|
+
.eh-chip { flex: none; white-space: nowrap; padding: 0.05em 0.6em; border-radius: 999px; border: 1px solid color-mix(in srgb, var(--rule) 80%, transparent); background: transparent; color: var(--muted); font: inherit; cursor: pointer; box-shadow: inset 3px 0 0 var(--bar, var(--bar-neutral, var(--muted))); }
|
|
37
|
+
.eh-chip:hover, .eh-chip:focus-visible { color: var(--fg); border-color: var(--focus); }
|
|
38
|
+
.eh-chip:last-of-type { color: var(--fg); }
|
|
39
|
+
.eh-sep { flex: none; opacity: 0.5; }
|
|
40
|
+
.eh-chip[data-eh-tone="ok"] { --bar: var(--bar-managed, var(--managed)); }
|
|
41
|
+
.eh-chip[data-eh-tone="wait"] { --bar: var(--bar-foreign, var(--foreign)); }
|
|
42
|
+
.eh-chip[data-eh-tone="bad"] { --bar: var(--bar-degraded, var(--degraded)); }
|
|
43
|
+
.eh-chip[data-eh-tone="busy"] { --bar: var(--bar-pending, var(--pending)); }
|
|
44
|
+
body.k-watch #eh-trail { position: fixed; z-index: 7; left: 5px; right: 5px; padding: 0.3em 1.4em; background: var(--surface-pane-b); border-top: 1px solid color-mix(in srgb, var(--rule) 60%, transparent); border-radius: 8px 8px 0 0; }
|
|
45
|
+
#eh-tips { position: fixed; inset: 0; pointer-events: none; z-index: 40; }
|
|
46
|
+
#eh-modals { position: fixed; z-index: 50; }
|
|
47
|
+
.eh-tip { position: fixed; left: 0; top: 0; max-width: 24em; padding: 0.35em 0.75em; border-radius: 9px; background: var(--surface-box, var(--panel)); color: var(--fg); border: 1px solid var(--bar, var(--focus)); font-size: 0.92em; line-height: 1.3;
|
|
48
|
+
box-shadow: 0 6px 22px color-mix(in srgb, var(--shadow) 70%, transparent); transform-origin: 50% 100%; }
|
|
49
|
+
.eh-tip.eh-tip-go { pointer-events: auto; cursor: pointer; }
|
|
50
|
+
.eh-tip.eh-tip-go:hover { background: var(--active); }
|
|
51
|
+
.eh-tip::after { content: ""; position: absolute; left: calc(50% - 6px); bottom: -7px; width: 12px; height: 12px; background: inherit; border: inherit; border-top: 0; border-left: 0; transform: rotate(45deg); }
|
|
52
|
+
.eh-tip.eh-below::after { bottom: auto; top: -7px; transform: rotate(-135deg); }
|
|
53
|
+
.eh-tip[data-eh-tone="ok"] { --bar: var(--bar-managed, var(--managed)); }
|
|
54
|
+
.eh-tip[data-eh-tone="wait"] { --bar: var(--bar-foreign, var(--foreign)); }
|
|
55
|
+
.eh-tip[data-eh-tone="bad"] { --bar: var(--bar-degraded, var(--degraded)); }
|
|
56
|
+
.eh-tip[data-eh-tone="busy"] { --bar: var(--bar-pending, var(--pending)); }
|
|
57
|
+
.eh-glow { outline: 2px solid var(--eh-glow, var(--focus)); outline-offset: 2px; border-radius: 6px; }
|
|
58
|
+
@media (prefers-reduced-motion: no-preference) {
|
|
59
|
+
.eh-tip { animation: eh-pop 0.28s ease-out; }
|
|
60
|
+
.eh-tip.eh-out { transition: transform 0.6s ease-in, opacity 0.6s ease-in; opacity: 0; }
|
|
61
|
+
.eh-glow { animation: eh-pulse 1.4s ease-in-out 2; }
|
|
62
|
+
}
|
|
63
|
+
@media (prefers-reduced-motion: reduce) { .eh-tip.eh-out { opacity: 0; } }
|
|
64
|
+
@keyframes eh-pop { from { opacity: 0; transform: var(--eh-at) translateY(6px) scale(0.92); } to { opacity: 1; transform: var(--eh-at); } }
|
|
65
|
+
@keyframes eh-pulse { 0%, 100% { outline-color: color-mix(in srgb, var(--eh-glow, var(--focus)) 35%, transparent); } 50% { outline-color: var(--eh-glow, var(--focus)); } }
|
|
66
|
+
@media (max-width: 600px) { #eh-trail { padding: 0.2em 16px; } body.k-watch #eh-trail { position: static; background: transparent; border: 0; } .eh-tip { max-width: 18em; } }
|
|
67
|
+
`;
|
|
68
|
+
|
|
69
|
+
/** A fact's tone, for its chip, its tip and its modal: the state colours the bars use. */
|
|
70
|
+
export function toneOf(kind) {
|
|
71
|
+
if (kind === "held") return "wait";
|
|
72
|
+
if (kind === "failed" || kind === "refused") return "bad";
|
|
73
|
+
if (kind === "applied" || kind === "applied-wave" || kind === "approved" || kind === "known") return "ok";
|
|
74
|
+
return "busy";
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Start Tips. `get()` answers what the kiosk holds now; `light(subjects)`
|
|
79
|
+
* lights them across the panes as a hover does (null puts them out);
|
|
80
|
+
* `panel(kind)` builds the real panel the modal shows (the approval panel).
|
|
81
|
+
*/
|
|
82
|
+
export function startEventHelp({ doc = document, store = null, switchHost = null, trailHost, tipsHost, modalHost, get, light = () => {}, panel = () => null, openTrace = () => {}, now = () => Date.now(), shown = now, reduced = () => typeof matchMedia === "function" && matchMedia("(prefers-reduced-motion: reduce)").matches }) {
|
|
83
|
+
if (doc.head && !doc.getElementById("eh-style")) {
|
|
84
|
+
const style = doc.createElement("style");
|
|
85
|
+
style.id = "eh-style";
|
|
86
|
+
style.textContent = STYLE;
|
|
87
|
+
doc.head.appendChild(style);
|
|
88
|
+
}
|
|
89
|
+
modalStyle(doc);
|
|
90
|
+
const st = { bootAt: now(), maxOrder: -Infinity, appliedAt: new Map(), on: ehStored(store), cycle: null, seen: null, trail: new Map(), failed: new Set(), tips: null, modals: null, modal: null, lastInput: -Infinity, lit: null, litUntil: 0, nodes: new Map(), glows: [] };
|
|
91
|
+
const el = (tag, cls, text) => {
|
|
92
|
+
const n = doc.createElement(tag);
|
|
93
|
+
if (cls) n.className = cls;
|
|
94
|
+
if (text !== undefined && text !== null) n.textContent = text;
|
|
95
|
+
return n;
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
// The switch, by the theme picker and "What is this?".
|
|
99
|
+
if (switchHost) {
|
|
100
|
+
const label = el("label", "eh-switch");
|
|
101
|
+
label.title = TIPS_TITLE;
|
|
102
|
+
const box = el("input");
|
|
103
|
+
box.type = "checkbox";
|
|
104
|
+
box.checked = st.on;
|
|
105
|
+
box.addEventListener("change", () => {
|
|
106
|
+
st.on = box.checked;
|
|
107
|
+
ehStore(store, st.on);
|
|
108
|
+
if (!st.on) quiet();
|
|
109
|
+
});
|
|
110
|
+
label.append(box, TIPS_WORDS);
|
|
111
|
+
switchHost.prepend(label);
|
|
112
|
+
}
|
|
113
|
+
// A viewer at the page: no modal opens over what they are doing.
|
|
114
|
+
for (const ev of ["pointerdown", "keydown", "wheel"]) doc.addEventListener(ev, () => (st.lastInput = now()), { passive: true });
|
|
115
|
+
doc.addEventListener("pointermove", (e) => {
|
|
116
|
+
if (e.pointerType !== "touch") st.lastInput = now();
|
|
117
|
+
}, { passive: true });
|
|
118
|
+
|
|
119
|
+
/** Everything Tips put up, put away: the tips, the lights, the glows, any modal. */
|
|
120
|
+
const quiet = () => {
|
|
121
|
+
for (const n of st.nodes.values()) n.remove();
|
|
122
|
+
st.nodes.clear();
|
|
123
|
+
st.tips = null;
|
|
124
|
+
st.modals = null;
|
|
125
|
+
for (const g of st.glows) g.el.classList.remove("eh-glow");
|
|
126
|
+
st.glows = [];
|
|
127
|
+
if (st.lit) light(null);
|
|
128
|
+
st.lit = null;
|
|
129
|
+
if (st.modal) st.modal.api.close();
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
// ---- where an event's things are on screen -----------------------------
|
|
133
|
+
const frameRect = (h) => {
|
|
134
|
+
const f = h.frame;
|
|
135
|
+
if (!f || !f.getBoundingClientRect) return null;
|
|
136
|
+
const F = f.getBoundingClientRect();
|
|
137
|
+
return F.width ? F : null;
|
|
138
|
+
};
|
|
139
|
+
const visible = (r) => r && r.width > 0 && r.height > 0 && r.bottom > 0 && r.right > 0 && r.top < (doc.defaultView ? doc.defaultView.innerHeight : 1e9);
|
|
140
|
+
const fromFrame = (h, b) => {
|
|
141
|
+
const F = frameRect(h);
|
|
142
|
+
if (!F || !b || !(b.w > 0)) return null;
|
|
143
|
+
const r = { left: F.left + b.x, top: F.top + b.y, width: b.w, height: b.h };
|
|
144
|
+
// Only the part inside the frame: a box panned out of view is no anchor.
|
|
145
|
+
const top = Math.max(r.top, F.top);
|
|
146
|
+
const bottom = Math.min(r.top + r.height, F.bottom);
|
|
147
|
+
const left = Math.max(r.left, F.left);
|
|
148
|
+
const right = Math.min(r.left + r.width, F.right);
|
|
149
|
+
return bottom - top > 8 && right - left > 8 ? { left, top, width: right - left, height: bottom - top, right, bottom } : null;
|
|
150
|
+
};
|
|
151
|
+
const q = (sel) => [...doc.querySelectorAll(sel)].find((n) => visible(n.getBoundingClientRect()) && !n.closest("[hidden]"));
|
|
152
|
+
/** The things an event is about, the one its tip points at first. */
|
|
153
|
+
const anchorsOf = (ev, h) => {
|
|
154
|
+
const s = ev.subjects;
|
|
155
|
+
const out = [];
|
|
156
|
+
const graph = () => {
|
|
157
|
+
const boxes = (h.boxes && h.boxes.waves) || {};
|
|
158
|
+
const roots = (h.boxes && h.boxes.roots) || {};
|
|
159
|
+
const card = s.roots.map((r) => fromFrame(h, roots[r])).find(Boolean);
|
|
160
|
+
const wave = Number.isInteger(s.wave) ? fromFrame(h, boxes[s.wave]) : null;
|
|
161
|
+
// A read's value, a plan: the card; a wave's news: its box.
|
|
162
|
+
return ev.kind === "known" || ev.kind === "planned" || ev.kind === "pull-request" ? card || wave : wave || card;
|
|
163
|
+
};
|
|
164
|
+
const approvalEl = () => q("#k-callout:not([hidden])") || q(".k-box-hold.k-hold");
|
|
165
|
+
const jobEl = () => (Number.isInteger(s.wave) ? q(`.r-job[data-k-wave="${s.wave}"]`) : null) || (s.job ? q("#k-drawer:not([hidden]) .k-drawer-head") : null);
|
|
166
|
+
const badgeEl = () => (Number.isInteger(s.wave) ? q(`.k-badge.k-placed[data-k-wave="${s.wave}"]`) || q(`#k-metrics .k-metrics-wave[data-k-wave="${s.wave}"]`) : null);
|
|
167
|
+
const add = (x) => {
|
|
168
|
+
if (!x) return;
|
|
169
|
+
if (x.getBoundingClientRect) out.push({ el: x, rect: x.getBoundingClientRect() });
|
|
170
|
+
else out.push({ el: null, rect: x });
|
|
171
|
+
};
|
|
172
|
+
if (["held", "approved", "resumed"].includes(ev.kind)) add(approvalEl());
|
|
173
|
+
if (ev.kind === "metrics") add(badgeEl());
|
|
174
|
+
// A job's own news (it started, failed, ran again, has a trace) points at its job row first.
|
|
175
|
+
if (["trace", "started", "failed", "refused", "rerun"].includes(ev.kind)) add(jobEl());
|
|
176
|
+
add(graph());
|
|
177
|
+
add(jobEl());
|
|
178
|
+
if (ev.kind !== "metrics") add(badgeEl());
|
|
179
|
+
// The first that is on screen leads; the same element twice counts once.
|
|
180
|
+
return out.filter((a, i) => visible(a.rect) && (!a.el || out.findIndex((b) => b.el === a.el) === i));
|
|
181
|
+
};
|
|
182
|
+
|
|
183
|
+
// ---- tips ----------------------------------------------------------------
|
|
184
|
+
const place = (node, rect) => {
|
|
185
|
+
const W = doc.defaultView ? doc.defaultView.innerWidth : 1600;
|
|
186
|
+
const w = node.offsetWidth || 200;
|
|
187
|
+
const hgt = node.offsetHeight || 30;
|
|
188
|
+
let x = rect.left + rect.width / 2 - w / 2;
|
|
189
|
+
x = Math.max(8, Math.min(x, W - w - 8));
|
|
190
|
+
let y = rect.top - hgt - 12;
|
|
191
|
+
const below = y < 8;
|
|
192
|
+
if (below) y = rect.top + rect.height + 12;
|
|
193
|
+
node.classList.toggle("eh-below", below);
|
|
194
|
+
const at = `translate(${Math.round(x)}px, ${Math.round(y)}px)`;
|
|
195
|
+
node.style.setProperty("--eh-at", at);
|
|
196
|
+
node.style.transform = at;
|
|
197
|
+
};
|
|
198
|
+
const trailChip = (id) => trailHost && trailHost.querySelector(`.eh-chip[data-eh-id="${CSS.escape(id)}"]`);
|
|
199
|
+
const showTips = (h) => {
|
|
200
|
+
const t = now();
|
|
201
|
+
const prev = st.tips;
|
|
202
|
+
st.tips = tipsQueue(st.tips, { now: t });
|
|
203
|
+
const up = new Set(st.tips.shown.map((x) => x.event.id));
|
|
204
|
+
// Each tip whose time is up shrinks toward its chip on the trail, then goes.
|
|
205
|
+
for (const [id, node] of st.nodes) {
|
|
206
|
+
if (up.has(id)) continue;
|
|
207
|
+
st.nodes.delete(id);
|
|
208
|
+
const chip = trailChip(id) || (trailHost && trailHost.querySelector(".eh-chip:last-of-type"));
|
|
209
|
+
if (chip && !reduced()) {
|
|
210
|
+
const c = chip.getBoundingClientRect();
|
|
211
|
+
const r = node.getBoundingClientRect();
|
|
212
|
+
node.style.transform = `translate(${Math.round(c.left + c.width / 2 - r.width / 2)}px, ${Math.round(c.top - r.height / 2)}px) scale(0.2)`;
|
|
213
|
+
}
|
|
214
|
+
node.classList.add("eh-out");
|
|
215
|
+
setTimeout(() => node.remove(), reduced() ? 250 : 650);
|
|
216
|
+
}
|
|
217
|
+
for (const { event } of st.tips.shown) {
|
|
218
|
+
const anchors = anchorsOf(event, h);
|
|
219
|
+
let node = st.nodes.get(event.id);
|
|
220
|
+
if (!anchors.length) {
|
|
221
|
+
if (node) node.style.visibility = "hidden";
|
|
222
|
+
continue;
|
|
223
|
+
}
|
|
224
|
+
const isNew = !node;
|
|
225
|
+
if (isNew) {
|
|
226
|
+
node = el("div", "eh-tip", event.text);
|
|
227
|
+
node.dataset.ehTone = toneOf(event.kind);
|
|
228
|
+
node.setAttribute("role", "status");
|
|
229
|
+
// A trace's tip opens the trace.
|
|
230
|
+
if (event.kind === "trace" && Number.isInteger(event.subjects.wave)) {
|
|
231
|
+
node.classList.add("eh-tip-go");
|
|
232
|
+
node.title = "Open this wave's trace";
|
|
233
|
+
const w = event.subjects.wave;
|
|
234
|
+
node.addEventListener("click", () => openTrace(w));
|
|
235
|
+
}
|
|
236
|
+
tipsHost.appendChild(node);
|
|
237
|
+
st.nodes.set(event.id, node);
|
|
238
|
+
}
|
|
239
|
+
node.style.visibility = "";
|
|
240
|
+
place(node, anchors[0].rect);
|
|
241
|
+
if (isNew) {
|
|
242
|
+
// The things it is about glow while it is up, and light together across the panes.
|
|
243
|
+
for (const a of anchors) if (a.el) glowOn(a.el, toneOf(event.kind));
|
|
244
|
+
lightFor(event);
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
if (prev && !st.tips.shown.length && st.lit && now() > st.litUntil) {
|
|
248
|
+
light(null);
|
|
249
|
+
st.lit = null;
|
|
250
|
+
}
|
|
251
|
+
};
|
|
252
|
+
const glowOn = (node, tone) => {
|
|
253
|
+
node.style.setProperty("--eh-glow", `var(--bar-${tone === "ok" ? "managed" : tone === "wait" ? "foreign" : tone === "bad" ? "degraded" : "pending"}, var(--focus))`);
|
|
254
|
+
node.classList.add("eh-glow");
|
|
255
|
+
const until = now() + TIP_MS;
|
|
256
|
+
st.glows.push({ el: node, until });
|
|
257
|
+
};
|
|
258
|
+
const lightFor = (event) => {
|
|
259
|
+
const s = event.subjects;
|
|
260
|
+
st.lit = Number.isInteger(s.wave) ? { wave: s.wave } : s.roots.length ? { root: s.roots[0] } : null;
|
|
261
|
+
st.litUntil = now() + TIP_MS;
|
|
262
|
+
if (st.lit) light(st.lit);
|
|
263
|
+
};
|
|
264
|
+
const ageGlows = () => {
|
|
265
|
+
const t = now();
|
|
266
|
+
st.glows = st.glows.filter((g) => {
|
|
267
|
+
if (g.until > t) return true;
|
|
268
|
+
g.el.classList.remove("eh-glow");
|
|
269
|
+
return false;
|
|
270
|
+
});
|
|
271
|
+
if (st.lit && t > st.litUntil) {
|
|
272
|
+
st.lit = null;
|
|
273
|
+
light(null);
|
|
274
|
+
}
|
|
275
|
+
};
|
|
276
|
+
|
|
277
|
+
// ---- the trail -----------------------------------------------------------
|
|
278
|
+
let trailKey = "";
|
|
279
|
+
const drawTrail = (h) => {
|
|
280
|
+
if (!trailHost) return;
|
|
281
|
+
const facts = [...st.trail.values()].sort((a, b) => a.order - b.order);
|
|
282
|
+
const key = facts.map((f) => `${f.id}=${f.text}`).join(",");
|
|
283
|
+
trailHost.hidden = !facts.length;
|
|
284
|
+
if (h.watch && h.caption && trailHost.style) {
|
|
285
|
+
const c = h.caption.getBoundingClientRect();
|
|
286
|
+
trailHost.style.bottom = c.height ? `${Math.round((doc.defaultView ? doc.defaultView.innerHeight : 0) - c.top)}px` : "";
|
|
287
|
+
} else if (trailHost.style) trailHost.style.bottom = "";
|
|
288
|
+
if (key === trailKey) return;
|
|
289
|
+
trailKey = key;
|
|
290
|
+
trailHost.replaceChildren(el("span", "eh-trail-label", TRAIL_WORDS));
|
|
291
|
+
facts.forEach((f, i) => {
|
|
292
|
+
if (i) trailHost.appendChild(el("span", "eh-sep", "›"));
|
|
293
|
+
const chip = el("button", "eh-chip", f.text);
|
|
294
|
+
chip.type = "button";
|
|
295
|
+
chip.dataset.ehId = f.id;
|
|
296
|
+
chip.dataset.ehTone = toneOf(f.kind);
|
|
297
|
+
// A chip asked for shows its tip again: on a hover while Tips are on, on a click always.
|
|
298
|
+
chip.addEventListener("pointerenter", () => st.on && replay(f));
|
|
299
|
+
chip.addEventListener("click", () => replay(f));
|
|
300
|
+
trailHost.appendChild(chip);
|
|
301
|
+
});
|
|
302
|
+
// The newest beat stays in view.
|
|
303
|
+
trailHost.scrollLeft = trailHost.scrollWidth;
|
|
304
|
+
};
|
|
305
|
+
// A chip asked for takes the stage: the tips up now step aside for it.
|
|
306
|
+
const replay = (f) => {
|
|
307
|
+
for (const n of st.nodes.values()) n.remove();
|
|
308
|
+
st.nodes.clear();
|
|
309
|
+
st.tips = { shown: [], waiting: [f] };
|
|
310
|
+
showTips(get());
|
|
311
|
+
};
|
|
312
|
+
|
|
313
|
+
// ---- modals --------------------------------------------------------------
|
|
314
|
+
const openModal = (event, h) => {
|
|
315
|
+
const d = h.demo;
|
|
316
|
+
const nextAt = d && d.next && d.next.at ? Date.parse(d.next.at) : null;
|
|
317
|
+
const mode = h.replay ? "replay" : "narrated";
|
|
318
|
+
const t = shown();
|
|
319
|
+
let data;
|
|
320
|
+
if (event.kind === "held") {
|
|
321
|
+
data = { title: Number.isInteger(event.subjects.wave) ? `Wave ${event.subjects.wave} waits for an approval` : "The plan waits for an approval", lines: [{ text: event.text }], panel: panel("held"), command: h.approveLine || null, at: d && d.step === "waiting" && /approve/.test((d.next && d.next.action) || "") ? nextAt : null, from: t, replayAt: t };
|
|
322
|
+
} else if (event.kind === "failed" || event.kind === "refused") {
|
|
323
|
+
data = { title: `Wave ${event.subjects.wave} failed`, lines: [{ text: event.text, lit: true }, ...(h.label ? [{ text: h.label }] : [])], action: d && d.next ? d.next.action : null, at: nextAt, from: t, replayAt: t };
|
|
324
|
+
} else {
|
|
325
|
+
const r = h.result;
|
|
326
|
+
data = { title: "Applied", lines: [...(h.label ? [{ text: h.label }] : []), ...(r ? r.counts.map((c) => ({ text: c })) : [])], replayAt: t };
|
|
327
|
+
}
|
|
328
|
+
const kind = event.kind === "refused" ? "failed" : event.kind;
|
|
329
|
+
const api = openEventModal(modalHost, { mode, kind, data, doc, now: shown, reduced: reduced(), onClose: () => (st.modal = null) });
|
|
330
|
+
st.modal = { api, event, kind, step: d ? d.step : null, cycle: d ? d.cycle : null };
|
|
331
|
+
};
|
|
332
|
+
/** The modal's real event: the approval landed, the waves ran again, the cycle moved on. */
|
|
333
|
+
const settleModal = (h, facts) => {
|
|
334
|
+
const m = st.modal;
|
|
335
|
+
if (!m || m.api.state.resolved) return;
|
|
336
|
+
const d = h.demo;
|
|
337
|
+
if (m.kind === "held") {
|
|
338
|
+
const ok = facts.find((f) => f.kind === "approved" && (f.subjects.wave === m.event.subjects.wave || !Number.isInteger(m.event.subjects.wave)));
|
|
339
|
+
if (ok) m.api.resolve(ok.text);
|
|
340
|
+
else if (d && (d.cycle !== m.cycle || !["waiting", "approved"].includes(d.step))) m.api.resolve(d.cycle === m.cycle ? "approved; the waves run again" : null);
|
|
341
|
+
} else if (m.kind === "failed") {
|
|
342
|
+
if (d && (d.cycle !== m.cycle || ["resumed", "applying", "waiting", "applied"].includes(d.step))) m.api.resolve(d.cycle === m.cycle ? "the waves run again" : null);
|
|
343
|
+
}
|
|
344
|
+
};
|
|
345
|
+
|
|
346
|
+
/** Read what the kiosk holds, find the news, and draw it. Called on every kiosk redraw. */
|
|
347
|
+
const tick = () => {
|
|
348
|
+
const h = get();
|
|
349
|
+
if (!h || !h.demo) return;
|
|
350
|
+
// behold#571 (#631): the story is told in the tool's own step order; until that is read, nothing is said in another's.
|
|
351
|
+
if (h.stripReady === false) return;
|
|
352
|
+
const stripKey = JSON.stringify((h.strip || []).map((x) => x.id));
|
|
353
|
+
if (stripKey !== st.stripKey) {
|
|
354
|
+
// Another tool's order: the trail is told again in it.
|
|
355
|
+
st.stripKey = stripKey;
|
|
356
|
+
st.trail.clear();
|
|
357
|
+
}
|
|
358
|
+
const facts = cycleFacts(ehSnapshot({ demo: h.demo, answer: h.answer, progress: h.progress, runDoc: h.runDoc, runDocs: h.runDocs || [], approval: h.approval, metrics: h.metrics, waveTraces: h.waveTraces || {}, strip: h.strip || null, waves: h.waves || [], failed: [...st.failed] }));
|
|
359
|
+
if (h.demo.cycle !== st.cycle) {
|
|
360
|
+
// A new cycle: a new story. Its first look is the trail so far, not news.
|
|
361
|
+
// The first look at a page sees a cycle already under way: no news. A cycle that turns while the page is open is all news.
|
|
362
|
+
if (st.cycle !== null) st.seen = new Set();
|
|
363
|
+
else st.seen = null;
|
|
364
|
+
st.cycle = h.demo.cycle;
|
|
365
|
+
st.maxOrder = -Infinity;
|
|
366
|
+
st.trail.clear();
|
|
367
|
+
st.failed.clear();
|
|
368
|
+
}
|
|
369
|
+
for (const f of facts) if ((f.kind === "failed" || f.kind === "refused") && Number.isInteger(f.subjects.wave)) st.failed.add(f.subjects.wave);
|
|
370
|
+
// While the page settles, everything is the story so far.
|
|
371
|
+
const settling = now() - st.bootAt < SETTLE_MS;
|
|
372
|
+
let news = settling ? [] : newEvents(st.seen, facts, { after: st.maxOrder - LATE_ORDER });
|
|
373
|
+
st.seen = new Set([...(st.seen || []), ...facts.map((f) => f.id)]);
|
|
374
|
+
for (const f of facts) if (f.kind !== "metrics" && f.kind !== "trace") st.maxOrder = Math.max(st.maxOrder, f.order);
|
|
375
|
+
// A wave's numbers right after its own "applied" tip say little new: they wait for the badge.
|
|
376
|
+
for (const f of news) if (f.kind === "applied-wave") st.appliedAt.set(f.subjects.wave, now());
|
|
377
|
+
news = news.filter((f) => !(f.kind === "metrics" && now() - (st.appliedAt.get(f.subjects.wave) || -Infinity) < 30_000));
|
|
378
|
+
// A beat keeps its place, and its words follow what the newest read says of it.
|
|
379
|
+
for (const f of storyTrail(facts)) st.trail.set(f.id, f);
|
|
380
|
+
drawTrail(h);
|
|
381
|
+
settleModal(h, facts);
|
|
382
|
+
if (!st.on) return;
|
|
383
|
+
if (news.length) st.tips = tipsQueue(st.tips, { add: news, now: now() });
|
|
384
|
+
// While a modal is up, the tips wait their turn behind it.
|
|
385
|
+
if (!st.modal) showTips(h);
|
|
386
|
+
ageGlows();
|
|
387
|
+
st.modals = modalQueue(st.modals, { add: news, now: now(), lastInput: st.lastInput, open: !!st.modal });
|
|
388
|
+
// A modal opens only while its event is still the step's: one that waited out a viewer at the page and went by is history.
|
|
389
|
+
if (st.modals.next && stillNow(st.modals.next, h.demo)) openModal(st.modals.next, h);
|
|
390
|
+
};
|
|
391
|
+
const stillNow = (e, d) => (e.kind === "held" ? d.step === "waiting" : e.kind === "failed" || e.kind === "refused" ? d.step === "failed" : e.kind === "applied" ? d.step === "applied" : false);
|
|
392
|
+
/** Keep the tips on their things while the graph moves (a shot, a pan). */
|
|
393
|
+
const follow = () => {
|
|
394
|
+
if (st.on && st.tips && st.tips.shown.length) showTips(get());
|
|
395
|
+
};
|
|
396
|
+
return { tick, follow, state: st, store: EH_STORE };
|
|
397
|
+
}
|
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
// behold#571: event-help, the kiosk's "Tips". What happens in a cycle, as
|
|
2
|
+
// events: each a short line of context about what just happened, and the
|
|
3
|
+
// things on screen it is about (its roots, its wave, its job and its run), so
|
|
4
|
+
// the kiosk can place a tip on them, light them together across the panes,
|
|
5
|
+
// and keep them in order on the cycle's story trail.
|
|
6
|
+
//
|
|
7
|
+
// Pure, no DOM, no reads of its own. The kiosk hands it what it already reads
|
|
8
|
+
// (demo.json, the pull request's plan, the run view, the pipeline's run, the
|
|
9
|
+
// approval panel's rows, the metrics, which jobs have a trace), as one
|
|
10
|
+
// snapshot. `cycleFacts(snapshot)` says everything the snapshot shows has
|
|
11
|
+
// happened in the cycle so far, in the cycle's order: that is the trail, and
|
|
12
|
+
// a viewer who arrives mid-cycle gets it whole. `newEvents(seen, facts)` is
|
|
13
|
+
// what happened since the last snapshot: those pop as tips.
|
|
14
|
+
|
|
15
|
+
import { STRIP, matchingPull, matchingRun } from "./kiosk.js";
|
|
16
|
+
import { defaultStep } from "./kiosk-runs.js";
|
|
17
|
+
import { traceReadyWords } from "./kiosk-wave-traces.js";
|
|
18
|
+
|
|
19
|
+
export { EH_STORE, ehStore, ehStored } from "./event-help-store.js";
|
|
20
|
+
|
|
21
|
+
/** How long a tip stays up before it shrinks toward the trail, and how many show at once. */
|
|
22
|
+
export const TIP_MS = 5_000;
|
|
23
|
+
export const TIPS_AT_ONCE = 2;
|
|
24
|
+
|
|
25
|
+
const ACTIONS = { create: "created", update: "updated", replace: "replaced", delete: "deleted", forget: "forgotten", import: "imported", move: "moved" };
|
|
26
|
+
const changedWords = (totals) => {
|
|
27
|
+
const parts = Object.entries(ACTIONS)
|
|
28
|
+
.filter(([a]) => totals && typeof totals[a] === "number" && totals[a] > 0)
|
|
29
|
+
.map(([a, w]) => `${totals[a]} ${w}`);
|
|
30
|
+
return parts.length ? parts.join(", ") : null;
|
|
31
|
+
};
|
|
32
|
+
/** "the plan creates 5 and updates 1", from a plan's totals. */
|
|
33
|
+
export function planWords(totals) {
|
|
34
|
+
const verbs = { create: "creates", update: "updates", replace: "replaces", delete: "deletes", forget: "forgets", import: "imports" };
|
|
35
|
+
const parts = Object.entries(verbs).filter(([a]) => totals && totals[a] > 0).map(([a, v]) => `${v} ${totals[a]}`);
|
|
36
|
+
return parts.length ? `the plan ${list(parts)}` : "the plan changes nothing";
|
|
37
|
+
}
|
|
38
|
+
const list = (xs) => (xs.length <= 1 ? xs.join("") : `${xs.slice(0, -1).join(", ")} and ${xs[xs.length - 1]}`);
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* SQL Yodeler's refusal in a failed job's log, as one short line, or null:
|
|
42
|
+
* "SQL Yodeler refused: an email shared by more than one row".
|
|
43
|
+
*/
|
|
44
|
+
export function yodelRefusal(lines) {
|
|
45
|
+
const text = (lines || []).filter((l) => typeof l === "string");
|
|
46
|
+
if (!text.some((l) => /yodel apply: refused/.test(l))) return null;
|
|
47
|
+
for (const l of text) {
|
|
48
|
+
const m = /would fail: (\d+) values? of \(([^)]+)\) held by more than one row/.exec(l);
|
|
49
|
+
if (m) {
|
|
50
|
+
const n = Number(m[1]);
|
|
51
|
+
const what = n === 1 ? `${/^[aeiou]/i.test(m[2]) ? "an" : "a"} ${m[2]} is` : `${n} ${m[2]} values are`;
|
|
52
|
+
return `SQL Yodeler refused, since ${what} shared by more than one row`;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return "SQL Yodeler refused the migration before its first statement";
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** Every log line of a job, its steps in order. */
|
|
59
|
+
const jobLines = (job) => (job && Array.isArray(job.steps) ? job.steps.flatMap((s) => (Array.isArray(s.log) ? s.log : [])) : []);
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* One snapshot of what the kiosk holds, reduced to what events are made of.
|
|
63
|
+
* `waves` is the declared waves (`{ job, wave, roots }`), so a job names its
|
|
64
|
+
* wave and a wave its roots.
|
|
65
|
+
*/
|
|
66
|
+
export function ehSnapshot({ demo = null, answer = null, progress = null, runDoc = null, runDocs = [], approval = null, metrics = null, waveTraces = {}, waves = [], failed = [], strip = null } = {}) {
|
|
67
|
+
if (!demo) return null;
|
|
68
|
+
const pr = matchingPull(answer, demo) || (answer && !answer.error && answer.pull_request && demo.pull !== null && String(answer.pull_request.run && answer.pull_request.run.pull_request) === String(demo.pull) ? answer.pull_request : null);
|
|
69
|
+
const run = matchingRun(progress, demo);
|
|
70
|
+
const jobs = runDoc && Array.isArray(runDoc.jobs) && (!demo.cycle || runDoc.cycle === undefined || runDoc.cycle === demo.cycle) ? runDoc.jobs : [];
|
|
71
|
+
return {
|
|
72
|
+
cycle: demo.cycle,
|
|
73
|
+
step: demo.step,
|
|
74
|
+
pull: demo.pull,
|
|
75
|
+
label: demo.label || "",
|
|
76
|
+
plan: pr ? { totals: pr.totals || null, roots: pr.roots || [], reads: pr.reads || [] } : null,
|
|
77
|
+
states: run ? progress.states || [] : [],
|
|
78
|
+
run: runDoc ? { id: runDoc.id, jobs: jobs.map((j) => ({ name: j.name, status: j.status, wave: waveOfJob(j.name, waves), refusal: j.status === "failure" ? yodelRefusal(jobLines(j)) : null, step: j.steps ? defaultStep(j.steps) : -1 })) } : null,
|
|
79
|
+
approval: approval && Array.isArray(approval.rows) ? { wave: approval.wave, rows: approval.rows.filter((r) => r.state === "lit").map((r) => ({ id: r.id, at: r.at || null, actor: r.id === "approved" ? actorOf(r.text) : null, signed: !!(r.seal && /^signed/.test(r.seal.text || "")) })) } : null,
|
|
80
|
+
// The numbers of this cycle's merge only: from the merge on, and only for its commit.
|
|
81
|
+
metrics: metrics && metrics.run && metrics.run.current && stepRank(demo.step, strip) >= stepRank("merged", strip) && (!demo.commit || String(metrics.run.label || "").includes(String(demo.commit).slice(0, 8))) ? metrics.run.waves.map((w) => ({ wave: w.wave, words: [w.seconds, w.held ? `held ${w.held}` : null, w.changed].filter(Boolean).join(" · ") })).filter((w) => w.words) : [],
|
|
82
|
+
// Each wave's trace, once Tempo has it (web/kiosk-wave-traces.js): `{ wave, run, job, words }`.
|
|
83
|
+
traces: Object.keys(waveTraces || {}).map(Number).sort((a, b) => a - b).map((w) => ({ wave: w, run: waveTraces[w].run, job: waveTraces[w].job, words: traceReadyWords(w, waveTraces[w].trace) })).filter((t) => t.words),
|
|
84
|
+
waves,
|
|
85
|
+
// The scenario's own step order (kiosk.js stripFromSteps), so the story keeps the order the steps had: chant gates before its merge.
|
|
86
|
+
strip: Array.isArray(strip) && strip.length ? strip : STRIP,
|
|
87
|
+
// The waves this cycle saw fail, kept by the kiosk: a re-run is news only against a failure seen before it.
|
|
88
|
+
failed: [...new Set(failed)],
|
|
89
|
+
// The cycle's earlier runs' failures (the approval panel reads them): a viewer who arrives after the re-run still gets the refusal.
|
|
90
|
+
pastFailures: (runDocs || [])
|
|
91
|
+
.filter((d) => d && d.id !== (runDoc && runDoc.id) && (!demo.cycle || d.cycle === undefined || d.cycle === demo.cycle) && Array.isArray(d.jobs))
|
|
92
|
+
.flatMap((d) => d.jobs.filter((j) => j.status === "failure" && waveOfJob(j.name, waves) !== null).map((j) => ({ wave: waveOfJob(j.name, waves), job: j.name, run: d.id, refusal: yodelRefusal(jobLines(j)) }))),
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
const waveOfJob = (name, waves) => {
|
|
97
|
+
const w = (waves || []).find((x) => x.job === name);
|
|
98
|
+
return w ? w.wave : null;
|
|
99
|
+
};
|
|
100
|
+
const rootsOfWave = (n, waves, states) => {
|
|
101
|
+
const s = (states || []).find((x) => x.number === n);
|
|
102
|
+
if (s && Array.isArray(s.changed) && s.changed.length) return s.changed;
|
|
103
|
+
const w = (waves || []).find((x) => x.wave === n);
|
|
104
|
+
return w ? w.roots || [] : s ? s.roots || [] : [];
|
|
105
|
+
};
|
|
106
|
+
/** "demo-reviewer approved exactly this plan." → "demo-reviewer". */
|
|
107
|
+
const actorOf = (text) => {
|
|
108
|
+
const m = /^(.+?) approved\b/.exec(text || "");
|
|
109
|
+
return m && m[1] !== "A reviewer" ? m[1] : null;
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
/** The strip's order of a step: 0 for the pull request, up to 5 for the reset; -1 for one the strip doesn't know. */
|
|
113
|
+
const stepRank = (step, strip = STRIP) => (strip || STRIP).findIndex((s) => s.steps.includes(step));
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Everything the snapshot says has happened in its cycle, as facts in the
|
|
117
|
+
* cycle's order. A fact is `{ id, kind, text, subjects: { roots, wave, job, run }, order, trail, critical }`:
|
|
118
|
+
* `id` is stable for the cycle, so a fact seen once is never news again;
|
|
119
|
+
* `trail` says whether the story trail keeps it (a wave starting or a trace
|
|
120
|
+
* landing pops a tip but is not a beat of the story); `critical` is a wave
|
|
121
|
+
* held for an approval, a wave that failed, and the cycle applied.
|
|
122
|
+
*/
|
|
123
|
+
export function cycleFacts(snap) {
|
|
124
|
+
if (!snap) return [];
|
|
125
|
+
const out = [];
|
|
126
|
+
const add = (f) => out.push({ subjects: { roots: [], wave: null, job: null, run: null }, trail: true, critical: false, ...f, subjects: { roots: [], wave: null, job: null, run: null, ...(f.subjects || {}) } });
|
|
127
|
+
const strip = snap.strip || STRIP;
|
|
128
|
+
const at = stepRank(snap.step, strip);
|
|
129
|
+
const rank = (step) => stepRank(step, strip);
|
|
130
|
+
const c = snap.cycle;
|
|
131
|
+
const runId = snap.run ? snap.run.id : null;
|
|
132
|
+
// The pull request and its plan.
|
|
133
|
+
if (snap.pull !== null && snap.pull !== undefined && at >= 0) add({ id: `${c}|pr`, kind: "pull-request", text: `pull request #${snap.pull} opened`, order: 0, subjects: { roots: snap.plan ? snap.plan.roots : [] } });
|
|
134
|
+
if (snap.plan && snap.plan.totals && at >= rank("planned")) {
|
|
135
|
+
add({ id: `${c}|plan`, kind: "planned", text: planWords(snap.plan.totals), order: 1, subjects: { roots: snap.plan.roots } });
|
|
136
|
+
}
|
|
137
|
+
if (at >= rank("merged") && snap.pull !== null && snap.pull !== undefined) add({ id: `${c}|merged`, kind: "merged", text: `pull request #${snap.pull} merged`, order: 2 });
|
|
138
|
+
// Each wave, from the run view; a wave's job, from the pipeline's run.
|
|
139
|
+
const jobOf = (n) => (snap.run ? snap.run.jobs.find((j) => j.wave === n) : null);
|
|
140
|
+
const approved = snap.approval ? snap.approval.rows.find((r) => r.id === "approved") : null;
|
|
141
|
+
const states = [...snap.states].sort((a, b) => a.number - b.number);
|
|
142
|
+
const failedBefore = new Set([...(snap.failed || []), ...(snap.pastFailures || []).map((f) => f.wave)]);
|
|
143
|
+
for (const s of states) {
|
|
144
|
+
const n = s.number;
|
|
145
|
+
const roots = rootsOfWave(n, snap.waves, states);
|
|
146
|
+
const job = jobOf(n);
|
|
147
|
+
const subjects = { roots, wave: n, job: job ? job.name : null, run: runId };
|
|
148
|
+
const base = 10 + n * 10;
|
|
149
|
+
if (["applying", "waiting", "applied", "failed", "refused"].includes(s.state)) add({ id: `${c}|w${n}|start`, kind: "started", text: `wave ${n} started`, order: base, subjects, trail: false });
|
|
150
|
+
// A failure the run view no longer shows (the re-run moved on) is still the pipeline's run's.
|
|
151
|
+
const failedJob = job && job.status === "failure" ? job : null;
|
|
152
|
+
const past = (snap.pastFailures || []).find((f) => f.wave === n);
|
|
153
|
+
if (s.state === "failed" || s.state === "refused" || failedJob || past) {
|
|
154
|
+
failedBefore.add(n);
|
|
155
|
+
const refusal = (failedJob && failedJob.refusal) || (past && past.refusal);
|
|
156
|
+
add({ id: `${c}|w${n}|failed`, kind: refusal ? "refused" : "failed", text: refusal || `wave ${n} failed`, order: base + 1, subjects: past && !failedJob ? { ...subjects, job: past.job, run: past.run } : subjects, critical: true });
|
|
157
|
+
}
|
|
158
|
+
// The read that holds a wave: a root of it reading a value its upstream only now has.
|
|
159
|
+
const read = snap.plan ? snap.plan.reads.find((r) => roots.includes(r.root) && r.unknown && r.unknown.length) : null;
|
|
160
|
+
const heldText = read ? `wave ${n} held, since ${read.root}'s plan uses ${list(read.unknown)}` : `wave ${n} held for an approval`;
|
|
161
|
+
if (s.state === "waiting") add({ id: `${c}|w${n}|held`, kind: "held", text: heldText, order: base + 3, subjects, critical: true });
|
|
162
|
+
if (snap.approval && snap.approval.wave === n) {
|
|
163
|
+
for (const r of snap.approval.rows) {
|
|
164
|
+
if (r.id === "requested" && s.state !== "waiting") add({ id: `${c}|w${n}|held`, kind: "held", text: heldText, order: base + 3, subjects, critical: true });
|
|
165
|
+
if (r.id === "approved") add({ id: `${c}|w${n}|approved`, kind: "approved", text: r.actor ? `approved by ${r.actor}${r.signed ? ", signed" : ""}` : "approved, signed", order: base + 4, subjects });
|
|
166
|
+
if (r.id === "resumed") add({ id: `${c}|w${n}|resumed`, kind: "resumed", text: "/terragucci apply ran the waves again", order: base + 5, subjects });
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
if (failedBefore.has(n) && (s.state === "applying" || s.state === "applied") && !failedJob) add({ id: `${c}|w${n}|rerun`, kind: "rerun", text: `wave ${n} runs again`, order: base + 6, subjects });
|
|
170
|
+
if (s.state === "applied") {
|
|
171
|
+
const changed = changedWords(s.totals);
|
|
172
|
+
const under = approved && snap.approval.wave === n && approved.actor ? ` under ${approved.actor}'s approval` : "";
|
|
173
|
+
add({ id: `${c}|w${n}|applied`, kind: "applied-wave", text: `wave ${n} applied${under || (changed ? `: ${changed}` : "")}`, order: base + 7, subjects });
|
|
174
|
+
// The values a read waited on are known once their upstream applies.
|
|
175
|
+
for (const r of snap.plan ? snap.plan.reads : []) {
|
|
176
|
+
if (!r.unknown || !r.unknown.length || !roots.includes(r.upstream)) continue;
|
|
177
|
+
add({ id: `${c}|known|${r.root}|${r.upstream}`, kind: "known", text: `${list(r.unknown)} now known`, order: base + 8, subjects: { roots: [r.upstream, r.root], wave: n, job: subjects.job, run: runId } });
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
// The numbers and the traces, when they land.
|
|
182
|
+
for (const m of snap.metrics) add({ id: `${c}|metrics|${m.wave}`, kind: "metrics", text: `wave ${m.wave}: ${m.words}`, order: 10 + m.wave * 10 + 9, subjects: { roots: rootsOfWave(m.wave, snap.waves, states), wave: m.wave, run: runId }, trail: false });
|
|
183
|
+
// A wave's trace, once Tempo has it: a beat of the story, and a tip that opens it.
|
|
184
|
+
for (const t of snap.traces) add({ id: `${c}|trace|w${t.wave}`, kind: "trace", text: t.words, order: 10 + t.wave * 10 + 9, subjects: { roots: rootsOfWave(t.wave, snap.waves, states), wave: t.wave, job: t.job, run: t.run } });
|
|
185
|
+
// A gate on the whole change (chant's pull-request loop): its approval, no wave named.
|
|
186
|
+
if (snap.approval && !Number.isInteger(snap.approval.wave)) {
|
|
187
|
+
if (snap.approval.rows.some((r) => r.id === "requested" || r.id === "approved")) add({ id: `${c}|held`, kind: "held", text: "the plan waits for an approval", order: 9, critical: true });
|
|
188
|
+
const ok = snap.approval.rows.find((r) => r.id === "approved");
|
|
189
|
+
if (ok) add({ id: `${c}|approved`, kind: "approved", text: ok.actor ? `approved by ${ok.actor}${ok.signed ? ", signed" : ""}` : "approved, signed", order: 9.5 });
|
|
190
|
+
}
|
|
191
|
+
// A gate on the whole change (chant's pull-request loop): the plan waits, no wave named.
|
|
192
|
+
// A repo with declared waves names its held wave once the run view has it; this is for a repo without them.
|
|
193
|
+
if (snap.step === "waiting" && !(snap.waves || []).length && !out.some((f) => f.kind === "held")) add({ id: `${c}|held`, kind: "held", text: "the plan waits for an approval", order: 9, critical: true });
|
|
194
|
+
// The step says the run applied: every wave the run view names, even one a read has not caught up on.
|
|
195
|
+
if (snap.step === "applied") add({ id: `${c}|applied`, kind: "applied", text: !states.length ? "the change applied" : states.length === 1 ? "the wave applied" : `all ${states.length} waves applied`, order: 990, critical: true });
|
|
196
|
+
if (snap.step === "reset") add({ id: `${c}|reset`, kind: "reset", text: "states back on the base", order: 995 });
|
|
197
|
+
// One fact per id (a wave's hold is said by the run view and the approval rows alike).
|
|
198
|
+
const byId = new Map();
|
|
199
|
+
for (const f of out) if (!byId.has(f.id)) byId.set(f.id, f);
|
|
200
|
+
// behold#571 (#631): in the order the scenario's steps went: each fact at its stop of the strip, then in its order within it.
|
|
201
|
+
// An approval before the merge (chant's gate) is its own stop; after it, part of the waves.
|
|
202
|
+
const stopIndex = (id) => {
|
|
203
|
+
const i = strip.findIndex((x) => x.id === id);
|
|
204
|
+
return i >= 0 ? i : strip.findIndex((x) => x.id === "waves");
|
|
205
|
+
};
|
|
206
|
+
const gateStop = strip.some((x) => x.id === "approval") ? "approval" : "waves";
|
|
207
|
+
const stopOf = (f) => (["pull-request", "planned", "merged", "applied", "reset"].includes(f.kind) ? f.kind : f.kind === "pull-request" ? "pull-request" : ["held", "approved", "resumed"].includes(f.kind) && !Number.isInteger(f.subjects.wave) ? gateStop : "waves");
|
|
208
|
+
return [...byId.values()].map((f) => ({ ...f, stop: stopOf(f), order: Math.max(0, stopIndex(stopOf(f))) * 1000 + f.order })).sort((a, b) => a.order - b.order);
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
/** The story trail: the cycle's facts that are beats of its story. */
|
|
212
|
+
export function storyTrail(facts) {
|
|
213
|
+
return facts.filter((f) => f.trail);
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* What is news: the facts not seen before, in order. The first snapshot of a
|
|
218
|
+
* page (`seen` null) is no news at all: it is the trail so far.
|
|
219
|
+
*/
|
|
220
|
+
export function newEvents(seen, facts, { after = -Infinity } = {}) {
|
|
221
|
+
if (!seen) return [];
|
|
222
|
+
// A fact that turns up late, behind the story already told (a plan read after the waves began), joins the trail but is no news.
|
|
223
|
+
// A trace and a wave's numbers always land after the wave's next beats: they are news whenever they land.
|
|
224
|
+
const fresh = facts.filter((f) => !seen.has(f.id) && (f.order >= after || f.kind === "trace" || f.kind === "metrics"));
|
|
225
|
+
// A wave's start said alone is news; beside its own next beat, the beat says it.
|
|
226
|
+
return fresh.filter((f) => !(f.kind === "started" && fresh.some((g) => g !== f && g.subjects.wave === f.subjects.wave && g.kind !== "metrics" && g.kind !== "trace")));
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
/** How far behind the newest beat told a late fact may sit and still be news. */
|
|
230
|
+
export const LATE_ORDER = 10;
|
|
231
|
+
|
|
232
|
+
/**
|
|
233
|
+
* The tips queue: at most TIPS_AT_ONCE up, the rest waiting their turn, each
|
|
234
|
+
* up TIP_MS. Pure: `{ shown: [{ event, until }], waiting: [event] }`.
|
|
235
|
+
*/
|
|
236
|
+
export function tipsQueue(state, { add = [], now = 0, max = TIPS_AT_ONCE, ms = TIP_MS } = {}) {
|
|
237
|
+
const shown = (state ? state.shown : []).filter((s) => s.until > now);
|
|
238
|
+
const waiting = [...(state ? state.waiting : []), ...add].filter((e, i, all) => all.findIndex((x) => x.id === e.id) === i && !shown.some((s) => s.event.id === e.id));
|
|
239
|
+
while (shown.length < max && waiting.length) shown.push({ event: waiting.shift(), until: now + ms });
|
|
240
|
+
return { shown, waiting };
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
/**
|
|
244
|
+
* The critical modals' queue: one at a time, never while a viewer is at the
|
|
245
|
+
* page (a pointer or a key within `quietMs`), and only the newest of each
|
|
246
|
+
* kind, since an old one is already history.
|
|
247
|
+
*/
|
|
248
|
+
export function modalQueue(state, { add = [], now = 0, lastInput = -Infinity, quietMs = 6_000, open = false } = {}) {
|
|
249
|
+
const waiting = [...(state ? state.waiting : []), ...add.filter((e) => e.critical)];
|
|
250
|
+
const newest = new Map();
|
|
251
|
+
for (const e of waiting) newest.set(e.kind === "refused" ? "failed" : e.kind, e);
|
|
252
|
+
const queue = [...newest.values()];
|
|
253
|
+
if (open || !queue.length || now - lastInput < quietMs) return { next: null, waiting: queue };
|
|
254
|
+
return { next: queue[0], waiting: queue.slice(1) };
|
|
255
|
+
}
|