@intentius/behold 0.29.32 → 0.29.33
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 +389 -0
- package/web/kiosk-event-help.js +237 -0
- package/web/kiosk-event-help.test.js +144 -0
- package/web/kiosk-runs.js +18 -1
- package/web/kiosk-trace.js +8 -3
- package/web/kiosk-wave-traces.js +104 -0
- package/web/kiosk-wave-traces.test.js +53 -0
- package/web/kiosk.html +30 -0
- package/web/kiosk.js +218 -16
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@intentius/behold",
|
|
3
|
-
"version": "0.29.
|
|
3
|
+
"version": "0.29.33",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"description": "behold — a live control plane on chant. See your whole estate (every substrate in one graph), coloured by drift; act through delegated, gated Ops.",
|
package/web/app.js
CHANGED
|
@@ -102,7 +102,9 @@ import { hasPlayhead, renderPlayhead, waitingFor } from "./run-playhead.js";
|
|
|
102
102
|
// the lease, the pending gate count) and the converge gate card, whose Approve
|
|
103
103
|
// records a fact for the next tick rather than releasing anything. Same split as
|
|
104
104
|
// the playhead — the decisions are pure in there, the fetches stay here.
|
|
105
|
-
import { hasOperator, renderOperator, APPROVED_SEMANTICS } from "./operator.js";
|
|
105
|
+
import { hasOperator, renderOperator, renderConvergeGateCard, APPROVED_SEMANTICS } from "./operator.js";
|
|
106
|
+
import { modalStyle, openEventModal } from "./event-help-modal.js";
|
|
107
|
+
import { ehStore, ehStored } from "./event-help-store.js";
|
|
106
108
|
// #165: the recorded release on a component — which run put it here, from
|
|
107
109
|
// which commit, approved by whom — and, when the ledger's run id cannot be
|
|
108
110
|
// followed, the reason in words rather than a guessed link.
|
|
@@ -4541,12 +4543,24 @@ function kioskTellBoxes() {
|
|
|
4541
4543
|
const n = tgWaveOfKey(r.getAttribute("data-group-id"));
|
|
4542
4544
|
if (n !== null) waves[n] = rect(r.getBoundingClientRect());
|
|
4543
4545
|
}
|
|
4546
|
+
// behold#571 event-help: each root's cards, where the kiosk's tips about a root point.
|
|
4547
|
+
const roots = {};
|
|
4548
|
+
const named = (tgComponentFacets && tgComponentFacets.roots) || {};
|
|
4549
|
+
for (const g of svg.querySelectorAll("[data-node-id]")) {
|
|
4550
|
+
const id = g.getAttribute("data-node-id");
|
|
4551
|
+
const r = g.getBoundingClientRect();
|
|
4552
|
+
if (!r.width) continue;
|
|
4553
|
+
for (const root of new Set([id, named[id]].filter(Boolean))) {
|
|
4554
|
+
const had = roots[root];
|
|
4555
|
+
roots[root] = had ? { x: Math.min(had.x, Math.round(r.left)), y: Math.min(had.y, Math.round(r.top)), w: Math.round(Math.max(had.x + had.w, r.right) - Math.min(had.x, r.left)), h: Math.round(Math.max(had.y + had.h, r.bottom) - Math.min(had.y, r.top)) } : rect(r);
|
|
4556
|
+
}
|
|
4557
|
+
}
|
|
4544
4558
|
// The reads' labels too, which the kiosk's callouts keep clear of.
|
|
4545
4559
|
const labels = [...svg.querySelectorAll("[data-tg-reads] > g")].map((g) => rect(g.getBoundingClientRect())).filter((r) => r.w > 0);
|
|
4546
4560
|
const host = document.getElementById("graph");
|
|
4547
4561
|
const pane = host ? rect(host.getBoundingClientRect()) : null;
|
|
4548
4562
|
try {
|
|
4549
|
-
window.parent.postMessage({ type: "behold:boxes", waves, labels, pane, moving: !!shotAnim }, embedOpts.host);
|
|
4563
|
+
window.parent.postMessage({ type: "behold:boxes", waves, roots, labels, pane, moving: !!shotAnim }, embedOpts.host);
|
|
4550
4564
|
} catch {
|
|
4551
4565
|
/* the parent went away */
|
|
4552
4566
|
}
|
|
@@ -4619,6 +4633,27 @@ function wireKioskFrame() {
|
|
|
4619
4633
|
else kioskPopEvent({ type: "outside" });
|
|
4620
4634
|
// behold#571: a click on the graph holds the kiosk's shot where the viewer is reading.
|
|
4621
4635
|
if (card && kioskShot) kioskViewerMoved();
|
|
4636
|
+
// behold#571: a click on a wave's box (not a card in it) asks the kiosk for that wave's trace, or its log.
|
|
4637
|
+
if (!card && !panMoved && embedOpts.host && window.parent !== window) {
|
|
4638
|
+
const box = e.target.closest && (e.target.closest("rect[data-group-id]") || e.target.closest("[data-group-id]"));
|
|
4639
|
+
let n = box ? tgWaveOfKey(box.getAttribute("data-group-id")) : null;
|
|
4640
|
+
if (n === null) {
|
|
4641
|
+
// A box's title or marks sit over it: find the box the click is inside.
|
|
4642
|
+
const svg = currentSvg();
|
|
4643
|
+
for (const r of svg ? svg.querySelectorAll("rect[data-group-id]") : []) {
|
|
4644
|
+
const b = r.getBoundingClientRect();
|
|
4645
|
+
const w = tgWaveOfKey(r.getAttribute("data-group-id"));
|
|
4646
|
+
if (w !== null && e.clientX >= b.left && e.clientX <= b.right && e.clientY >= b.top && e.clientY <= b.bottom) n = w;
|
|
4647
|
+
}
|
|
4648
|
+
}
|
|
4649
|
+
if (n !== null) {
|
|
4650
|
+
try {
|
|
4651
|
+
window.parent.postMessage({ type: "behold:wave", wave: n }, embedOpts.host);
|
|
4652
|
+
} catch {
|
|
4653
|
+
/* the parent went away */
|
|
4654
|
+
}
|
|
4655
|
+
}
|
|
4656
|
+
}
|
|
4622
4657
|
},
|
|
4623
4658
|
true,
|
|
4624
4659
|
);
|
|
@@ -5331,7 +5366,63 @@ function dialArrow() {
|
|
|
5331
5366
|
return s;
|
|
5332
5367
|
}
|
|
5333
5368
|
|
|
5369
|
+
// --- behold#571: event-help in the full app ---------------------------------
|
|
5370
|
+
// A converge gate that waits for a person opens event-help's modal in live
|
|
5371
|
+
// mode (web/event-help-modal.js): what the gate covers, behold's own gate
|
|
5372
|
+
// card, and an Approve button that calls the route the card's button calls
|
|
5373
|
+
// (approveConvergeGate). It waits for the person, and closes when they
|
|
5374
|
+
// dismiss it or when the gate leaves the pending list. Only where behold may
|
|
5375
|
+
// approve: never framed, in a snapshot, in a preview or in a public view.
|
|
5376
|
+
// The Tips switch, the kiosk's too, turns it off.
|
|
5377
|
+
const ehApp = { seen: new Set(), modal: null };
|
|
5378
|
+
const ehShelf = (() => {
|
|
5379
|
+
try {
|
|
5380
|
+
return localStorage;
|
|
5381
|
+
} catch {
|
|
5382
|
+
return null;
|
|
5383
|
+
}
|
|
5384
|
+
})();
|
|
5385
|
+
(function wireTips() {
|
|
5386
|
+
modalStyle(document);
|
|
5387
|
+
const label = document.getElementById("panel-tips");
|
|
5388
|
+
const box = label && label.querySelector("input");
|
|
5389
|
+
if (!box) return;
|
|
5390
|
+
box.checked = ehStored(ehShelf);
|
|
5391
|
+
box.addEventListener("change", () => {
|
|
5392
|
+
ehStore(ehShelf, box.checked);
|
|
5393
|
+
if (!box.checked && ehApp.modal) ehApp.modal.api.close();
|
|
5394
|
+
});
|
|
5395
|
+
})();
|
|
5396
|
+
const ehGateKey = (g) => `${g.op}|${g.gate}|${g.since || ""}`;
|
|
5397
|
+
function ehAppGates() {
|
|
5398
|
+
if (embedOpts.embed || staticMode || previewMode || publicMode) return;
|
|
5399
|
+
const gates = (operatorState && operatorState.gates) || [];
|
|
5400
|
+
// The event resolved: the gate left the pending list.
|
|
5401
|
+
if (ehApp.modal && !gates.some((g) => ehGateKey(g) === ehApp.modal.key)) ehApp.modal.api.resolve(APPROVED_SEMANTICS);
|
|
5402
|
+
if (!ehStored(ehShelf)) return;
|
|
5403
|
+
for (const g of gates) {
|
|
5404
|
+
const key = ehGateKey(g);
|
|
5405
|
+
if (ehApp.seen.has(key)) continue;
|
|
5406
|
+
ehApp.seen.add(key);
|
|
5407
|
+
if (ehApp.modal) continue;
|
|
5408
|
+
// behold's own card, without its button: the modal's Approve is the same act.
|
|
5409
|
+
const card = renderConvergeGateCard(g, { approve: () => {} });
|
|
5410
|
+
for (const b of card.querySelectorAll("button")) b.remove();
|
|
5411
|
+
const host = document.getElementById("eh-modals") || document.body;
|
|
5412
|
+
const api = openEventModal(host, {
|
|
5413
|
+
mode: "live",
|
|
5414
|
+
kind: "held",
|
|
5415
|
+
data: { title: `${g.gate} waits for an approval`, lines: [{ text: `${g.op} wants a person's approval before the converge loop applies its change.` }], panel: card, gate: { kind: "converge", op: g.op, gate: g.gate, approve: g.approve }, verbs: { verb: "Record approval", ing: "Recording…", past: "Recorded" } },
|
|
5416
|
+
actions: { approve: () => approveConvergeGate(g.op, g.gate) },
|
|
5417
|
+
reduced: typeof matchMedia === "function" && matchMedia("(prefers-reduced-motion: reduce)").matches,
|
|
5418
|
+
onClose: () => (ehApp.modal = null),
|
|
5419
|
+
});
|
|
5420
|
+
ehApp.modal = { key, api };
|
|
5421
|
+
}
|
|
5422
|
+
}
|
|
5423
|
+
|
|
5334
5424
|
function renderDial() {
|
|
5425
|
+
ehAppGates();
|
|
5335
5426
|
const host = document.getElementById("dial");
|
|
5336
5427
|
if (!view.env) {
|
|
5337
5428
|
// The dial used to vanish entirely here, with nothing saying why — someone
|
|
@@ -0,0 +1,280 @@
|
|
|
1
|
+
// behold#571: event-help's modal for a critical event: a wave held for an
|
|
2
|
+
// approval, a wave that failed, a cycle applied. One component for the full
|
|
3
|
+
// app and the kiosk, with the mode an explicit parameter:
|
|
4
|
+
//
|
|
5
|
+
// - `live` (the full app, any serve that isn't public or a preview): it opens
|
|
6
|
+
// on the event and waits for the person. It closes when they dismiss it or
|
|
7
|
+
// when the event resolves. It acts only through behold's existing approval
|
|
8
|
+
// paths: an Op's gate through the route the app already calls
|
|
9
|
+
// (`actions.approve`, which the app hands in), and a terragucci or chant
|
|
10
|
+
// gate, which behold holds no identity to clear, by showing the signed
|
|
11
|
+
// `chant approve` command to copy and watching the ledger (`actions.watch`,
|
|
12
|
+
// a read) until the approval lands.
|
|
13
|
+
// - `narrated` (the live kiosk): the event is live and so is the data. The
|
|
14
|
+
// button the driver is about to press counts down to the driver's real
|
|
15
|
+
// action (demo.json's `next.at`): "Approve · 12". At zero it says
|
|
16
|
+
// "Approving…", and it shows pressed and resolved only when the real record
|
|
17
|
+
// or step arrives (`resolve`), never before. Every button is inert.
|
|
18
|
+
// - `replay` (a tool's page replaying a recorded cycle): the same, counting to
|
|
19
|
+
// the recorded event's time, marked as a replay.
|
|
20
|
+
//
|
|
21
|
+
// Nothing here writes on its own: the only write is `actions.approve` in live
|
|
22
|
+
// mode, and only on a click.
|
|
23
|
+
|
|
24
|
+
/** The three modes. */
|
|
25
|
+
export const MODAL_MODES = ["live", "narrated", "replay"];
|
|
26
|
+
|
|
27
|
+
/** How long a narrated or replayed modal stays up once its event resolved, and how long a live one shows the outcome. */
|
|
28
|
+
export const MODAL_CLOSE_MS = 6_000;
|
|
29
|
+
export const LIVE_OUTCOME_MS = 2_500;
|
|
30
|
+
/** How often live mode reads the ledger for a signed approval. */
|
|
31
|
+
export const LEDGER_WATCH_MS = 4_000;
|
|
32
|
+
|
|
33
|
+
/** The verb each kind's button says, before, during and after. */
|
|
34
|
+
export const VERBS = {
|
|
35
|
+
held: { verb: "Approve", ing: "Approving…", past: "Approved" },
|
|
36
|
+
failed: { verb: "Run again", ing: "Running again…", past: "Running again" },
|
|
37
|
+
applied: { verb: "Close", ing: "Close", past: "Close" },
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
/** Whole seconds until `at` (ms), never below 0; null without a time. */
|
|
41
|
+
export function secondsLeft(at, now) {
|
|
42
|
+
if (!Number.isFinite(at)) return null;
|
|
43
|
+
return Math.max(0, Math.ceil((at - now) / 1000));
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* The button's state: `{ label, pressed, progress }`. Counting down to the
|
|
48
|
+
* real action ("Approve · 12"), then "Approving…" at zero, and pressed only
|
|
49
|
+
* once the real event resolved it. `progress` (0..1) fills a ring as the time
|
|
50
|
+
* runs out; null under reduced motion, or without a time.
|
|
51
|
+
*/
|
|
52
|
+
export function buttonState(kind, { at = null, from = null, now = 0, resolved = false, reduced = false, verbs = null } = {}) {
|
|
53
|
+
const v = verbs || VERBS[kind] || VERBS.held;
|
|
54
|
+
if (resolved) return { label: v.past, pressed: true, progress: null };
|
|
55
|
+
const left = secondsLeft(at, now);
|
|
56
|
+
if (left === null) return { label: v.verb, pressed: false, progress: null };
|
|
57
|
+
if (left === 0) return { label: v.ing, pressed: false, progress: reduced ? null : 1 };
|
|
58
|
+
const span = Number.isFinite(from) && at > from ? at - from : null;
|
|
59
|
+
return { label: `${v.verb} · ${left}`, pressed: false, progress: reduced || !span ? null : Math.min(1, Math.max(0, (now - from) / span)) };
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** "04:08", UTC. */
|
|
63
|
+
const utc = (ms) => new Date(ms).toISOString().slice(11, 16);
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* The line that says which mode this is. Narrated says what the driver does
|
|
67
|
+
* and when; replay says which run it replays; live says nothing extra.
|
|
68
|
+
*/
|
|
69
|
+
export function modeLine(mode, kind, { at = null, now = 0, resolved = false, outcome = null, replayAt = null, action = null } = {}) {
|
|
70
|
+
if (mode === "replay") return `Replay of the run at ${utc(Number.isFinite(replayAt) ? replayAt : now)} UTC`;
|
|
71
|
+
if (mode !== "narrated") return null;
|
|
72
|
+
if (resolved) return outcome ? `Live · ${outcome}` : "Live";
|
|
73
|
+
const left = secondsLeft(at, now);
|
|
74
|
+
if (kind === "held") return left === null ? "Live · the driver plays the reviewer" : left > 0 ? `Live · the driver plays the reviewer and approves in ${left} s` : "Live · the driver plays the reviewer and approves now";
|
|
75
|
+
if (kind === "failed") return left === null ? "Live · the driver fixes it and runs it again" : left > 0 ? `Live · the driver fixes it and runs it again in ${left} s` : "Live · the driver fixes it and runs it again now";
|
|
76
|
+
return "Live";
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/** Which gates live mode can clear through behold's own routes: an Op's run gate and a converge gate. */
|
|
80
|
+
export const ROUTED_GATES = ["run", "converge"];
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* The route the app already calls to clear an Op's gate, as `{ method, path }`;
|
|
84
|
+
* null for a gate behold holds no identity for (terragucci's, chant's).
|
|
85
|
+
*/
|
|
86
|
+
export function approveRoute(gate) {
|
|
87
|
+
if (!gate) return null;
|
|
88
|
+
const e = encodeURIComponent;
|
|
89
|
+
if (gate.kind === "converge") return { method: "POST", path: (gate.approve && gate.approve.path) || `/api/operator/approve/${e(gate.op)}/${e(gate.gate)}` };
|
|
90
|
+
if (gate.kind === "run") return { method: "POST", path: `/api/ops/${e(gate.op)}/signal/${e(gate.gate)}` };
|
|
91
|
+
return null;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
const ESC = "Escape";
|
|
95
|
+
|
|
96
|
+
/** The modal's look (and the Tips switch's), for the kiosk and the full app alike; the state colours are the bars' (theme.js barInks). */
|
|
97
|
+
export const MODAL_STYLE = `
|
|
98
|
+
.eh-switch { display: inline-flex; align-items: center; gap: 0.35em; color: var(--muted); cursor: pointer; user-select: none; }
|
|
99
|
+
.eh-switch input { margin: 0; accent-color: var(--pending); }
|
|
100
|
+
.eh-switch:hover { color: var(--fg); }
|
|
101
|
+
.eh-modal-wrap { position: fixed; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center; background: color-mix(in srgb, var(--bg) 35%, transparent); }
|
|
102
|
+
.eh-modal { position: relative; width: min(36em, calc(100vw - 32px)); max-height: calc(100vh - 48px); overflow-y: auto; padding: 1em 1.2em 1.1em; border-radius: 12px; background: var(--surface-pane-b, var(--panel)); color: var(--fg);
|
|
103
|
+
border: 2px solid var(--bar, var(--focus)); box-shadow: 0 16px 48px color-mix(in srgb, var(--shadow) 80%, transparent); font-size: 1.05em; }
|
|
104
|
+
.eh-modal-held { --bar: var(--bar-foreign, var(--foreign)); } .eh-modal-failed { --bar: var(--bar-degraded, var(--degraded)); } .eh-modal-applied { --bar: var(--bar-managed, var(--managed)); }
|
|
105
|
+
.eh-modal-close { position: absolute; top: 0.4em; right: 0.5em; font-size: 1.3em; background: transparent; border: 0; color: var(--muted); cursor: pointer; }
|
|
106
|
+
.eh-modal-mode { margin: 0 2em 0.3em 0; font: 600 0.78em var(--font-mono); text-transform: uppercase; letter-spacing: 0.05em; color: var(--bar, var(--muted)); }
|
|
107
|
+
.eh-modal-title { margin: 0 0 0.5em; font-size: 1.35em; }
|
|
108
|
+
.eh-modal-line { margin: 0.2em 0; color: color-mix(in srgb, var(--fg) 82%, var(--muted)); }
|
|
109
|
+
.eh-modal-line.eh-lit { color: var(--fg); font-family: var(--font-mono); font-size: 0.9em; padding: 0.35em 0.6em; border-radius: 6px; background: color-mix(in srgb, var(--bar, var(--focus)) 14%, var(--well, transparent)); box-shadow: inset 3px 0 0 var(--bar, var(--focus)); }
|
|
110
|
+
.eh-modal-command { display: flex; gap: 0.5em; align-items: center; margin: 0.6em 0; }
|
|
111
|
+
.eh-modal-command code { flex: 1; padding: 0.45em 0.7em; background: var(--well); border-radius: 6px; font: 0.88em var(--font-mono); overflow-wrap: anywhere; }
|
|
112
|
+
.eh-modal-copy { font: inherit; padding: 0.3em 0.8em; border-radius: 6px; border: 1px solid var(--rule); background: transparent; color: var(--fg); cursor: pointer; }
|
|
113
|
+
.eh-modal-note, .eh-modal-outcome { margin: 0.4em 0; color: var(--muted); }
|
|
114
|
+
.eh-modal-outcome { color: var(--fg); font-weight: 600; }
|
|
115
|
+
.eh-modal-act { --eh-progress: 0; margin-top: 0.7em; font: 600 1.05em var(--font-ui); padding: 0.5em 1.4em; border-radius: 8px; border: 2px solid var(--bar, var(--pending)); color: var(--fg); cursor: default;
|
|
116
|
+
background: linear-gradient(90deg, color-mix(in srgb, var(--bar, var(--pending)) 35%, transparent) calc(var(--eh-progress) * 100%), transparent 0); }
|
|
117
|
+
.eh-modal-act.eh-pressed { background: var(--bar, var(--pending)); color: var(--bg); transform: translateY(1px); }
|
|
118
|
+
.eh-mode-live .eh-modal-act:not(.eh-pressed) { cursor: pointer; }
|
|
119
|
+
.eh-modal .k-ap { margin-top: 0.4em; }
|
|
120
|
+
`;
|
|
121
|
+
|
|
122
|
+
/** Put the modal's style in `doc` once. */
|
|
123
|
+
export function modalStyle(doc) {
|
|
124
|
+
if (!doc || !doc.head || !doc.getElementById || doc.getElementById("eh-modal-style")) return;
|
|
125
|
+
const style = doc.createElement("style");
|
|
126
|
+
style.id = "eh-modal-style";
|
|
127
|
+
style.textContent = MODAL_STYLE;
|
|
128
|
+
doc.head.appendChild(style);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Open the modal in `host` (a document's body, or any element). Returns
|
|
133
|
+
* `{ resolve(outcome), update(data), close(), state }`.
|
|
134
|
+
*
|
|
135
|
+
* `data`: `{ title, lines: [{ text, lit? }], panel?: Node, command?, at?, from?, action?, replayAt?, verbs?, gate?: { kind, op, gate, approve? } }`.
|
|
136
|
+
* `actions` (live only): `approve()` the app's own approve call, and
|
|
137
|
+
* `watch()` a read that answers an outcome once the ledger has the approval.
|
|
138
|
+
*/
|
|
139
|
+
export function openEventModal(host, { mode, kind, data = {}, actions = {}, doc = typeof document !== "undefined" ? document : null, now = () => Date.now(), reduced = false, onClose = () => {}, setTimer = setInterval, clearTimer = clearInterval } = {}) {
|
|
140
|
+
if (!MODAL_MODES.includes(mode)) throw new Error(`event-help modal: no mode ${JSON.stringify(mode)}`);
|
|
141
|
+
modalStyle(doc);
|
|
142
|
+
const st = { mode, kind, data, resolved: false, outcome: null, closed: false, hovered: false, closeAt: null, pressing: false };
|
|
143
|
+
const el = (tag, cls, text) => {
|
|
144
|
+
const n = doc.createElement(tag);
|
|
145
|
+
if (cls) n.className = cls;
|
|
146
|
+
if (text !== undefined && text !== null) n.textContent = String(text);
|
|
147
|
+
return n;
|
|
148
|
+
};
|
|
149
|
+
const wrap = el("div", "eh-modal-wrap");
|
|
150
|
+
const box = el("div", `eh-modal eh-modal-${kind} eh-mode-${mode}`);
|
|
151
|
+
box.setAttribute("role", "dialog");
|
|
152
|
+
box.setAttribute("aria-modal", "false");
|
|
153
|
+
box.setAttribute("aria-label", data.title || kind);
|
|
154
|
+
wrap.appendChild(box);
|
|
155
|
+
host.appendChild(wrap);
|
|
156
|
+
|
|
157
|
+
const close = () => {
|
|
158
|
+
if (st.closed) return;
|
|
159
|
+
st.closed = true;
|
|
160
|
+
clearTimer(timer);
|
|
161
|
+
if (watchTimer) clearTimer(watchTimer);
|
|
162
|
+
if (doc.removeEventListener) doc.removeEventListener("keydown", onKey);
|
|
163
|
+
if (wrap.remove) wrap.remove();
|
|
164
|
+
else if (host.removeChild) host.removeChild(wrap);
|
|
165
|
+
onClose(st);
|
|
166
|
+
};
|
|
167
|
+
const onKey = (e) => {
|
|
168
|
+
if (e && e.key === ESC) close();
|
|
169
|
+
};
|
|
170
|
+
if (doc.addEventListener) doc.addEventListener("keydown", onKey);
|
|
171
|
+
wrap.addEventListener("click", (e) => {
|
|
172
|
+
if (e && e.target === wrap) close();
|
|
173
|
+
});
|
|
174
|
+
// Hovered, it holds: its time to close starts again when the pointer leaves.
|
|
175
|
+
box.addEventListener("pointerenter", () => (st.hovered = true));
|
|
176
|
+
box.addEventListener("pointerleave", () => {
|
|
177
|
+
st.hovered = false;
|
|
178
|
+
if (st.closeAt !== null) st.closeAt = Math.max(st.closeAt, now() + 2_000);
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
const render = () => {
|
|
182
|
+
if (st.closed) return;
|
|
183
|
+
const t = now();
|
|
184
|
+
box.replaceChildren();
|
|
185
|
+
const x = el("button", "eh-modal-close", "×");
|
|
186
|
+
x.type = "button";
|
|
187
|
+
x.setAttribute("aria-label", "Close");
|
|
188
|
+
x.addEventListener("click", close);
|
|
189
|
+
box.appendChild(x);
|
|
190
|
+
const line = modeLine(mode, kind, { at: data.at, now: t, resolved: st.resolved, outcome: st.outcome, replayAt: data.replayAt, action: data.action });
|
|
191
|
+
if (line) box.appendChild(el("p", `eh-modal-mode eh-modal-${mode}`, line));
|
|
192
|
+
box.appendChild(el("h2", "eh-modal-title", data.title || ""));
|
|
193
|
+
for (const l of data.lines || []) box.appendChild(el("p", `eh-modal-line${l.lit ? " eh-lit" : ""}`, l.text));
|
|
194
|
+
if (data.panel) box.appendChild(data.panel);
|
|
195
|
+
const routed = mode === "live" && approveRoute(data.gate);
|
|
196
|
+
// The panel, when there is one, already carries the command.
|
|
197
|
+
if (data.command && !routed && !(data.panel && mode !== "live")) {
|
|
198
|
+
const row = el("div", "eh-modal-command");
|
|
199
|
+
row.appendChild(el("code", null, data.command));
|
|
200
|
+
if (mode === "live") {
|
|
201
|
+
// Copying is no write: it puts the command where the person can run it with their own key.
|
|
202
|
+
const copy = el("button", "eh-modal-copy", "Copy");
|
|
203
|
+
copy.type = "button";
|
|
204
|
+
copy.addEventListener("click", () => {
|
|
205
|
+
try {
|
|
206
|
+
const c = typeof navigator !== "undefined" && navigator.clipboard;
|
|
207
|
+
if (c) void c.writeText(data.command);
|
|
208
|
+
} catch {
|
|
209
|
+
/* no clipboard: the command stays on screen */
|
|
210
|
+
}
|
|
211
|
+
});
|
|
212
|
+
row.appendChild(copy);
|
|
213
|
+
}
|
|
214
|
+
box.appendChild(row);
|
|
215
|
+
if (mode === "live" && kind === "held" && !st.resolved) box.appendChild(el("p", "eh-modal-note", "Watching the ledger for the approval."));
|
|
216
|
+
}
|
|
217
|
+
if (st.resolved && st.outcome) box.appendChild(el("p", "eh-modal-outcome", st.outcome));
|
|
218
|
+
if (kind === "applied" && !routed) return;
|
|
219
|
+
if (mode === "live" && !routed) return; // a gate behold can't clear: the command is the action
|
|
220
|
+
const b = buttonState(kind, { at: mode === "live" ? null : data.at, from: data.from, now: t, resolved: st.resolved || st.pressing, reduced, verbs: data.verbs || null });
|
|
221
|
+
const btn = el("button", `eh-modal-act${b.pressed ? " eh-pressed" : ""}`, b.label);
|
|
222
|
+
btn.type = "button";
|
|
223
|
+
if (b.progress !== null && btn.style) btn.style.setProperty("--eh-progress", String(b.progress));
|
|
224
|
+
if (mode === "live" && routed && !st.resolved && !st.pressing) {
|
|
225
|
+
btn.addEventListener("click", () => {
|
|
226
|
+
st.pressing = true;
|
|
227
|
+
render();
|
|
228
|
+
Promise.resolve(actions.approve ? actions.approve() : null).catch(() => {
|
|
229
|
+
st.pressing = false;
|
|
230
|
+
render();
|
|
231
|
+
});
|
|
232
|
+
});
|
|
233
|
+
} else {
|
|
234
|
+
// Narrated and replayed buttons show what the driver does; they do nothing.
|
|
235
|
+
btn.setAttribute("aria-disabled", "true");
|
|
236
|
+
btn.tabIndex = -1;
|
|
237
|
+
}
|
|
238
|
+
box.appendChild(btn);
|
|
239
|
+
};
|
|
240
|
+
|
|
241
|
+
// Live, a terragucci or chant gate: read the ledger until the approval lands.
|
|
242
|
+
let watchTimer = null;
|
|
243
|
+
if (mode === "live" && kind === "held" && !approveRoute(data.gate) && actions.watch) {
|
|
244
|
+
const look = async () => {
|
|
245
|
+
if (st.closed || st.resolved) return;
|
|
246
|
+
const outcome = await actions.watch();
|
|
247
|
+
if (outcome) api.resolve(outcome);
|
|
248
|
+
};
|
|
249
|
+
watchTimer = setTimer(() => void look(), LEDGER_WATCH_MS);
|
|
250
|
+
void look();
|
|
251
|
+
}
|
|
252
|
+
const tick = () => {
|
|
253
|
+
if (st.closed) return;
|
|
254
|
+
if (st.closeAt !== null && !st.hovered && now() >= st.closeAt) return close();
|
|
255
|
+
render();
|
|
256
|
+
};
|
|
257
|
+
const timer = setTimer(tick, 250);
|
|
258
|
+
// The result needs no event to wait for: it closes on its own after its time.
|
|
259
|
+
if (kind === "applied" && mode !== "live") st.closeAt = now() + MODAL_CLOSE_MS;
|
|
260
|
+
render();
|
|
261
|
+
|
|
262
|
+
const api = {
|
|
263
|
+
state: st,
|
|
264
|
+
/** The real event arrived: show it pressed and resolved, and close after a while (live: shortly after the outcome). */
|
|
265
|
+
resolve(outcome = null) {
|
|
266
|
+
if (st.closed || st.resolved) return;
|
|
267
|
+
st.resolved = true;
|
|
268
|
+
st.pressing = false;
|
|
269
|
+
st.outcome = outcome;
|
|
270
|
+
st.closeAt = now() + (mode === "live" ? LIVE_OUTCOME_MS : MODAL_CLOSE_MS);
|
|
271
|
+
render();
|
|
272
|
+
},
|
|
273
|
+
update(next) {
|
|
274
|
+
Object.assign(data, next);
|
|
275
|
+
render();
|
|
276
|
+
},
|
|
277
|
+
close,
|
|
278
|
+
};
|
|
279
|
+
return api;
|
|
280
|
+
}
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
// behold#571: event-help's modal, one component in three modes. The countdown
|
|
2
|
+
// follows the driver's real action time, the button is pressed only once the
|
|
3
|
+
// real event arrives, narrated and replayed modals never write, and live mode
|
|
4
|
+
// writes only through the app's existing approve route, or waits on the ledger.
|
|
5
|
+
import { describe, expect, it, vi } from "vitest";
|
|
6
|
+
import { approveRoute, buttonState, modeLine, openEventModal, secondsLeft } from "./event-help-modal.js";
|
|
7
|
+
|
|
8
|
+
/** Just enough of a DOM for the modal: elements with children, text, attributes and listeners. */
|
|
9
|
+
function fakeDoc() {
|
|
10
|
+
const listeners = {};
|
|
11
|
+
const make = (tag) => {
|
|
12
|
+
const n = {
|
|
13
|
+
tagName: tag.toUpperCase(),
|
|
14
|
+
children: [],
|
|
15
|
+
attrs: {},
|
|
16
|
+
handlers: {},
|
|
17
|
+
textContent: "",
|
|
18
|
+
className: "",
|
|
19
|
+
style: { setProperty() {} },
|
|
20
|
+
appendChild(c) {
|
|
21
|
+
c.parent = n;
|
|
22
|
+
n.children.push(c);
|
|
23
|
+
return c;
|
|
24
|
+
},
|
|
25
|
+
replaceChildren() {
|
|
26
|
+
n.children = [];
|
|
27
|
+
},
|
|
28
|
+
setAttribute(k, v) {
|
|
29
|
+
n.attrs[k] = String(v);
|
|
30
|
+
},
|
|
31
|
+
addEventListener(ev, fn) {
|
|
32
|
+
(n.handlers[ev] ||= []).push(fn);
|
|
33
|
+
},
|
|
34
|
+
remove() {
|
|
35
|
+
if (n.parent) n.parent.children = n.parent.children.filter((x) => x !== n);
|
|
36
|
+
},
|
|
37
|
+
};
|
|
38
|
+
return n;
|
|
39
|
+
};
|
|
40
|
+
return {
|
|
41
|
+
createElement: make,
|
|
42
|
+
addEventListener: (ev, fn) => ((listeners[ev] ||= []).push(fn)),
|
|
43
|
+
removeEventListener() {},
|
|
44
|
+
fire: (ev, e) => (listeners[ev] || []).forEach((fn) => fn(e)),
|
|
45
|
+
body: make("body"),
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
const all = (n) => [n, ...n.children.flatMap(all)];
|
|
49
|
+
const find = (root, cls) => all(root).find((n) => n.className && n.className.split(" ").includes(cls));
|
|
50
|
+
const click = (n) => (n.handlers.click || []).forEach((fn) => fn({ target: n }));
|
|
51
|
+
|
|
52
|
+
/** A clock and a timer the test drives. */
|
|
53
|
+
function clock(start = 1_000_000) {
|
|
54
|
+
let t = start;
|
|
55
|
+
const timers = [];
|
|
56
|
+
return {
|
|
57
|
+
now: () => t,
|
|
58
|
+
setTimer: (fn) => (timers.push(fn), timers.length),
|
|
59
|
+
clearTimer() {},
|
|
60
|
+
advance(ms) {
|
|
61
|
+
t += ms;
|
|
62
|
+
timers.forEach((fn) => fn());
|
|
63
|
+
},
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
describe("event-help modal: the countdown", () => {
|
|
68
|
+
it("counts to the real action's time, says Approving… at zero, and is pressed only once resolved", () => {
|
|
69
|
+
const at = 1_000_000 + 12_000;
|
|
70
|
+
expect(buttonState("held", { at, now: 1_000_000 }).label).toBe("Approve · 12");
|
|
71
|
+
expect(buttonState("held", { at, now: at - 1 }).label).toBe("Approve · 1");
|
|
72
|
+
expect(buttonState("held", { at, now: at })).toMatchObject({ label: "Approving…", pressed: false });
|
|
73
|
+
expect(buttonState("held", { at, now: at + 30_000 })).toMatchObject({ label: "Approving…", pressed: false });
|
|
74
|
+
expect(buttonState("held", { at, now: at + 30_000, resolved: true })).toMatchObject({ label: "Approved", pressed: true });
|
|
75
|
+
expect(buttonState("failed", { at, now: 1_000_000 }).label).toBe("Run again · 12");
|
|
76
|
+
expect(secondsLeft(null, 0)).toBeNull();
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
it("fills a ring as the time runs out, and shows the number alone under reduced motion", () => {
|
|
80
|
+
expect(buttonState("held", { at: 20_000, from: 0, now: 5_000 }).progress).toBeCloseTo(0.25);
|
|
81
|
+
expect(buttonState("held", { at: 20_000, from: 0, now: 5_000, reduced: true }).progress).toBeNull();
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
it("says plainly what narrated and replayed modals are", () => {
|
|
85
|
+
expect(modeLine("narrated", "held", { at: 12_000, now: 0 })).toBe("Live · the driver plays the reviewer and approves in 12 s");
|
|
86
|
+
expect(modeLine("narrated", "held", { at: 12_000, now: 0, resolved: true, outcome: "approved by demo-reviewer" })).toBe("Live · approved by demo-reviewer");
|
|
87
|
+
expect(modeLine("replay", "held", { replayAt: Date.parse("2026-10-16T04:08:00Z") })).toBe("Replay of the run at 04:08 UTC");
|
|
88
|
+
expect(modeLine("live", "held", {})).toBeNull();
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
describe("event-help modal: narrated and replayed modals never write", () => {
|
|
93
|
+
for (const mode of ["narrated", "replay"]) {
|
|
94
|
+
it(`${mode}: a click on every button calls no fetch, and the button presses only on the real event`, () => {
|
|
95
|
+
const fetchSpy = vi.fn();
|
|
96
|
+
vi.stubGlobal("fetch", fetchSpy);
|
|
97
|
+
const doc = fakeDoc();
|
|
98
|
+
const c = clock();
|
|
99
|
+
const approve = vi.fn();
|
|
100
|
+
const m = openEventModal(doc.body, { mode, kind: "held", data: { title: "Wave 2 waits for an approval", at: c.now() + 3_000, command: "chant approve tf-apply wave-2 --actor <reviewer> --sign <reviewer key>", gate: { kind: "converge", op: "a", gate: "b" } }, actions: { approve }, doc, ...c });
|
|
101
|
+
const act = () => find(doc.body, "eh-modal-act");
|
|
102
|
+
expect(act().textContent).toBe("Approve · 3");
|
|
103
|
+
click(act());
|
|
104
|
+
c.advance(10_000); // the driver's time passes; no record has landed
|
|
105
|
+
expect(act().textContent).toBe("Approving…");
|
|
106
|
+
expect(act().className).not.toContain("eh-pressed");
|
|
107
|
+
for (const b of all(doc.body).filter((n) => n.tagName === "BUTTON" && n.className !== "eh-modal-close")) click(b);
|
|
108
|
+
m.resolve("approved by demo-reviewer");
|
|
109
|
+
expect(act().className).toContain("eh-pressed");
|
|
110
|
+
expect(approve).not.toHaveBeenCalled();
|
|
111
|
+
expect(fetchSpy).not.toHaveBeenCalled();
|
|
112
|
+
vi.unstubAllGlobals();
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
it("narrated closes a while after its event resolved, later while hovered, and at once on Escape", () => {
|
|
117
|
+
const doc = fakeDoc();
|
|
118
|
+
const c = clock();
|
|
119
|
+
const closed = vi.fn();
|
|
120
|
+
const m = openEventModal(doc.body, { mode: "narrated", kind: "held", data: { title: "t", at: c.now() + 1_000 }, doc, onClose: closed, ...c });
|
|
121
|
+
m.resolve("approved");
|
|
122
|
+
c.advance(5_000);
|
|
123
|
+
expect(closed).not.toHaveBeenCalled();
|
|
124
|
+
c.advance(1_500);
|
|
125
|
+
expect(closed).toHaveBeenCalledTimes(1);
|
|
126
|
+
const m2 = openEventModal(doc.body, { mode: "narrated", kind: "held", data: { title: "t" }, doc, onClose: closed, ...c });
|
|
127
|
+
doc.fire("keydown", { key: "Escape" });
|
|
128
|
+
expect(m2.state.closed).toBe(true);
|
|
129
|
+
});
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
describe("event-help modal: live mode", () => {
|
|
133
|
+
it("clears an Op's gate only through the route the app already calls", async () => {
|
|
134
|
+
expect(approveRoute({ kind: "converge", op: "fountain-apply", gate: "rollout-gate", approve: { path: "/api/operator/approve/fountain-apply/rollout-gate" } })).toEqual({ method: "POST", path: "/api/operator/approve/fountain-apply/rollout-gate" });
|
|
135
|
+
expect(approveRoute({ kind: "run", op: "apply prod", gate: "approve" })).toEqual({ method: "POST", path: "/api/ops/apply%20prod/signal/approve" });
|
|
136
|
+
expect(approveRoute({ kind: "terragucci", gate: "wave-2" })).toBeNull();
|
|
137
|
+
const doc = fakeDoc();
|
|
138
|
+
const c = clock();
|
|
139
|
+
const calls = [];
|
|
140
|
+
const approve = vi.fn(async () => calls.push(approveRoute({ kind: "converge", op: "fountain-apply", gate: "rollout-gate" })));
|
|
141
|
+
const m = openEventModal(doc.body, { mode: "live", kind: "held", data: { title: "rollout-gate waits", gate: { kind: "converge", op: "fountain-apply", gate: "rollout-gate" } }, actions: { approve }, doc, ...c });
|
|
142
|
+
// It waits for the person: no countdown, no closing on its own.
|
|
143
|
+
expect(find(doc.body, "eh-modal-act").textContent).toBe("Approve");
|
|
144
|
+
c.advance(60_000);
|
|
145
|
+
expect(m.state.closed).toBe(false);
|
|
146
|
+
click(find(doc.body, "eh-modal-act"));
|
|
147
|
+
await Promise.resolve();
|
|
148
|
+
expect(approve).toHaveBeenCalledTimes(1);
|
|
149
|
+
expect(calls).toEqual([{ method: "POST", path: "/api/operator/approve/fountain-apply/rollout-gate" }]);
|
|
150
|
+
// The gate cleared: the app resolves it, and it closes after showing so.
|
|
151
|
+
m.resolve("the gate cleared");
|
|
152
|
+
c.advance(3_000);
|
|
153
|
+
expect(m.state.closed).toBe(true);
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
it("for a terragucci or chant gate, offers the signed command and waits for the ledger, never writing", async () => {
|
|
157
|
+
const fetchSpy = vi.fn();
|
|
158
|
+
vi.stubGlobal("fetch", fetchSpy);
|
|
159
|
+
const doc = fakeDoc();
|
|
160
|
+
const c = clock();
|
|
161
|
+
let landed = null;
|
|
162
|
+
const watch = vi.fn(async () => landed);
|
|
163
|
+
const m = openEventModal(doc.body, { mode: "live", kind: "held", data: { title: "wave 2 waits", command: "chant approve tf-apply wave-2 --plan jcs1-sha256:… --sign <your key>", gate: { kind: "terragucci", gate: "wave-2" } }, actions: { watch }, doc, ...c });
|
|
164
|
+
expect(find(doc.body, "eh-modal-act")).toBeUndefined();
|
|
165
|
+
expect(find(doc.body, "eh-modal-copy").textContent).toBe("Copy");
|
|
166
|
+
await Promise.resolve();
|
|
167
|
+
expect(watch).toHaveBeenCalledTimes(1);
|
|
168
|
+
c.advance(4_000);
|
|
169
|
+
await Promise.resolve();
|
|
170
|
+
expect(m.state.resolved).toBe(false);
|
|
171
|
+
landed = "approved by demo-reviewer, signed";
|
|
172
|
+
c.advance(4_000);
|
|
173
|
+
await Promise.resolve();
|
|
174
|
+
await Promise.resolve();
|
|
175
|
+
expect(m.state.resolved).toBe(true);
|
|
176
|
+
expect(m.state.outcome).toBe("approved by demo-reviewer, signed");
|
|
177
|
+
expect(fetchSpy).not.toHaveBeenCalled();
|
|
178
|
+
vi.unstubAllGlobals();
|
|
179
|
+
});
|
|
180
|
+
});
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// behold#571: the event-help ("Tips") switch, shared by the kiosk and the full
|
|
2
|
+
// app: on unless a viewer turned it off, kept in their own browser.
|
|
3
|
+
|
|
4
|
+
/** Where a viewer's Tips switch is kept. */
|
|
5
|
+
export const EH_STORE = "behold.eventHelp";
|
|
6
|
+
|
|
7
|
+
/** Tips, on unless the viewer turned them off; on when storage refuses. */
|
|
8
|
+
export function ehStored(store) {
|
|
9
|
+
try {
|
|
10
|
+
return !(store && store.getItem(EH_STORE) === "off");
|
|
11
|
+
} catch {
|
|
12
|
+
return true;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/** Keep the viewer's Tips switch; quiet where storage refuses (a private window). */
|
|
17
|
+
export function ehStore(store, on) {
|
|
18
|
+
try {
|
|
19
|
+
if (store) store.setItem(EH_STORE, on ? "on" : "off");
|
|
20
|
+
} catch {
|
|
21
|
+
/* the switch lasts this visit */
|
|
22
|
+
}
|
|
23
|
+
}
|
package/web/index.html
CHANGED
|
@@ -409,7 +409,7 @@
|
|
|
409
409
|
/* #476: framed in a host pane. Deploying and the theme are the host's
|
|
410
410
|
business; the panel and the inspect pane start folded (app.js). */
|
|
411
411
|
.embed #panel-tabs button[data-tab="deploy"], .embed #panel-body section[data-tab="deploy"],
|
|
412
|
-
.embed #panel-body section[data-tab="view"] > h3:has(+ #panel-theme), .embed #panel-theme { display: none !important; }
|
|
412
|
+
.embed #panel-body section[data-tab="view"] > h3:has(+ #panel-theme), .embed #panel-theme, .embed #panel-tips { display: none !important; }
|
|
413
413
|
/* Folded in a frame, the panel is a small pill (⌘K and the expand
|
|
414
414
|
chevron) in the corner, so the graph has the pane to itself. */
|
|
415
415
|
.embed #panel.collapsed #panel-tabs button[data-tab] { display: none; }
|
|
@@ -823,6 +823,9 @@
|
|
|
823
823
|
<div id="panel-viewtools"></div>
|
|
824
824
|
<h3>theme</h3>
|
|
825
825
|
<div id="panel-theme"></div>
|
|
826
|
+
<!-- behold#571: event-help, the "Tips" switch the kiosk has too. -->
|
|
827
|
+
<label id="panel-tips" class="eh-switch" title="A window opens when a gate waits for you, and shows how to approve it"><input type="checkbox" /> Tips</label>
|
|
828
|
+
<div id="eh-modals"></div>
|
|
826
829
|
</section>
|
|
827
830
|
<section data-tab="scope" id="tab-scope"></section>
|
|
828
831
|
<section data-tab="substrates"><div id="substrates"></div></section>
|