@intentius/behold 0.30.0 → 0.30.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (57) hide show
  1. package/AGENTS.md +97 -33
  2. package/README.md +78 -56
  3. package/dist/cli.js +6913 -2448
  4. package/example-choudoufu-estate/chant.workspace.json +1 -1
  5. package/example-terraform-estate/README.md +1 -1
  6. package/example-terraform-estate/chant.workspace.json +1 -1
  7. package/example-terralith/README.md +1 -1
  8. package/example-three-cloud/package-lock.json +19 -19
  9. package/example-three-cloud/package.json +4 -4
  10. package/package.json +5 -5
  11. package/web/app.js +330 -19
  12. package/web/embed.js +2 -2
  13. package/web/event-help-modal.js +18 -12
  14. package/web/event-help-modal.test.js +28 -1
  15. package/web/index.html +18 -0
  16. package/web/kiosk-ask-layout.js +85 -0
  17. package/web/kiosk-ask-layout.test.js +83 -0
  18. package/web/kiosk-ask-tips.js +467 -0
  19. package/web/kiosk-ask-tips.test.js +359 -0
  20. package/web/kiosk-ask.js +774 -0
  21. package/web/kiosk-ask.test.js +593 -0
  22. package/web/kiosk-banner.js +108 -0
  23. package/web/kiosk-banner.test.js +72 -0
  24. package/web/kiosk-center-cards.test.js +110 -0
  25. package/web/kiosk-estate-scene.js +203 -0
  26. package/web/kiosk-estate-scene.test.js +21 -0
  27. package/web/kiosk-event-help.js +4 -1
  28. package/web/kiosk-graph-pane.js +63 -0
  29. package/web/kiosk-graph-pane.test.js +105 -0
  30. package/web/kiosk-light-frame.js +196 -0
  31. package/web/kiosk-light.js +509 -0
  32. package/web/kiosk-light.test.js +297 -0
  33. package/web/kiosk-metrics.js +7 -4
  34. package/web/kiosk-modal-sticky.test.js +2 -1
  35. package/web/kiosk-refit.test.js +81 -0
  36. package/web/kiosk-reset.js +49 -0
  37. package/web/kiosk-reset.test.js +11 -0
  38. package/web/kiosk-shot.js +40 -2
  39. package/web/kiosk-shot.test.js +23 -1
  40. package/web/kiosk-vendor.js +85 -7
  41. package/web/kiosk-vendor.test.js +9 -9
  42. package/web/kiosk-watch.js +8 -4
  43. package/web/kiosk.html +107 -1
  44. package/web/kiosk.js +149 -23
  45. package/web/kiosk.test.js +25 -1
  46. package/web/layout-store.js +3 -3
  47. package/web/small-stage.test.js +4 -0
  48. package/web/terragucci-change.js +30 -13
  49. package/web/tool-mark.js +4 -4
  50. package/web/tool-mark.test.js +1 -1
  51. package/web/vendors/atmos.svg +1 -0
  52. package/web/vendors/chant.svg +1 -0
  53. package/web/vendors/choudoufu.svg +1 -0
  54. package/web/vendors/terragrunt.svg +9 -0
  55. package/web/vendors/terragucci.svg +1 -0
  56. package/web/vendors/choudoufu-128.png +0 -0
  57. package/web/vendors/choudoufu-64.png +0 -0
@@ -0,0 +1,105 @@
1
+ import { describe, expect, it } from "vitest";
2
+ import { graphFolds, graphPending } from "./kiosk-graph-pane.js";
3
+
4
+ const base = { vendor: { id: "terragucci" }, ok: false, askOn: false, seen: false, pending: false };
5
+
6
+ describe("when the graph pane folds away", () => {
7
+ it("folds for a tool with no graph, once the reads are in", () => {
8
+ expect(graphFolds(base)).toBe(true);
9
+ });
10
+ it("never folds while the graph is there", () => {
11
+ expect(graphFolds({ ...base, ok: true })).toBe(false);
12
+ });
13
+ it("not before the page has read the project and the answer (the moment after a reload)", () => {
14
+ expect(graphFolds({ ...base, pending: true })).toBe(false);
15
+ });
16
+ it("not in ask mode: the graph is half of the story", () => {
17
+ expect(graphFolds({ ...base, askOn: true })).toBe(false);
18
+ });
19
+ it("not after the graph has been shown on this page (a stale or failed read keeps it)", () => {
20
+ expect(graphFolds({ ...base, seen: true })).toBe(false);
21
+ });
22
+ it("a page with no tool folds nothing", () => {
23
+ expect(graphFolds({ ...base, vendor: null })).toBe(false);
24
+ });
25
+ });
26
+
27
+ describe("whether a read is still to come", () => {
28
+ it("until /api/project has answered", () => {
29
+ expect(graphPending({ own: false, single: null, answer: { a: 1 } })).toBe(true);
30
+ });
31
+ it("until the terragucci answer is in, for a tool that reads it", () => {
32
+ expect(graphPending({ own: false, single: true, answer: null })).toBe(true);
33
+ expect(graphPending({ own: false, single: true, answer: { error: "x" } })).toBe(false);
34
+ });
35
+ it("a tool with its own reads waits for the project only", () => {
36
+ expect(graphPending({ own: true, single: false, answer: null })).toBe(false);
37
+ });
38
+ });
39
+
40
+ import { graphMayShow, keepsSceneInAsk, mayTellDrawn } from "./kiosk-graph-pane.js";
41
+
42
+ describe("graphMayShow: ask mode never paints the plain resource graph", () => {
43
+ const ask = { askOn: true, components: false, sceneUp: false, answerSettled: false, answerHasScene: false };
44
+ it("Inspect (not ask mode) always shows the graph", () => {
45
+ expect(graphMayShow({ ...ask, askOn: false })).toBe(true);
46
+ });
47
+ it("the components view always shows", () => {
48
+ expect(graphMayShow({ ...ask, components: true })).toBe(true);
49
+ });
50
+ it("holds before the reports are in", () => {
51
+ expect(graphMayShow(ask)).toBe(false);
52
+ });
53
+ it("holds while the reports have a scene the pin hides for now", () => {
54
+ expect(graphMayShow({ ...ask, answerSettled: true, answerHasScene: true })).toBe(false);
55
+ });
56
+ it("holds on a failed read", () => {
57
+ expect(graphMayShow({ ...ask, answerSettled: false })).toBe(false);
58
+ });
59
+ it("shows once the scene is drawn, and keeps showing when the reads go missing", () => {
60
+ expect(graphMayShow({ ...ask, sceneUp: true })).toBe(true);
61
+ });
62
+ it("a repo whose reports hold no scene shows its own graph", () => {
63
+ expect(graphMayShow({ ...ask, answerSettled: true, answerHasScene: false })).toBe(true);
64
+ });
65
+ });
66
+
67
+ describe("keepsSceneInAsk", () => {
68
+ it("keeps a drawn scene in ask mode, never outside it", () => {
69
+ expect(keepsSceneInAsk({ askOn: true, sceneUp: true })).toBe(true);
70
+ expect(keepsSceneInAsk({ askOn: true, sceneUp: false })).toBe(false);
71
+ expect(keepsSceneInAsk({ askOn: false, sceneUp: true })).toBe(false);
72
+ });
73
+ });
74
+
75
+ describe("mayTellDrawn", () => {
76
+ it("waits for the kiosk's word on ask mode, for a while", () => {
77
+ expect(mayTellDrawn({ askHeard: false, waitedMs: 500, askOn: false, mayShow: true })).toBe(false);
78
+ expect(mayTellDrawn({ askHeard: false, waitedMs: 3500, askOn: false, mayShow: true })).toBe(true);
79
+ });
80
+ it("in ask mode, not until the graph may show", () => {
81
+ expect(mayTellDrawn({ askHeard: true, waitedMs: 9000, askOn: true, mayShow: false })).toBe(false);
82
+ expect(mayTellDrawn({ askHeard: true, waitedMs: 9000, askOn: true, mayShow: true })).toBe(true);
83
+ });
84
+ it("outside ask mode, as before", () => {
85
+ expect(mayTellDrawn({ askHeard: true, waitedMs: 0, askOn: false, mayShow: false })).toBe(true);
86
+ });
87
+ });
88
+
89
+ import { refusalHoldsScene } from "./kiosk-graph-pane.js";
90
+
91
+ describe("refusalHoldsScene: a composed run's scene needs no graph", () => {
92
+ const refusal = { code: "lint", error: "dependencies not installed" };
93
+ const scene = { estateScene: { roots: [{ path: "network", resources: [{ address: "aws_subnet.b" }] }] } };
94
+ it("draws the scene in a frame whose graph refused the checkout, once the reports hold one", () => {
95
+ expect(refusalHoldsScene({ refusal, bare: true, answer: scene })).toBe(true);
96
+ });
97
+ it("keeps the refusal's card without a scene, outside a frame, or with no refusal", () => {
98
+ expect(refusalHoldsScene({ refusal, bare: true, answer: { roots: [] } })).toBe(false);
99
+ expect(refusalHoldsScene({ refusal, bare: true, answer: { estateScene: { roots: [{ path: "a", resources: [] }] } } })).toBe(false);
100
+ expect(refusalHoldsScene({ refusal, bare: true, answer: { error: "x", ...scene } })).toBe(false);
101
+ expect(refusalHoldsScene({ refusal, bare: true, answer: null })).toBe(false);
102
+ expect(refusalHoldsScene({ refusal, bare: false, answer: scene })).toBe(false);
103
+ expect(refusalHoldsScene({ refusal: null, bare: true, answer: scene })).toBe(false);
104
+ });
105
+ });
@@ -0,0 +1,196 @@
1
+ // behold#937: the graph frame's half of a step's lighting (web/kiosk-light.js decides).
2
+ // Draws, over the terragucci marks the frame already has:
3
+ // - lit and dimmed cards, the edges between lit cards at full weight (the `q`
4
+ // view's look, #913, under its own `data-kl` marks so a query's repaint
5
+ // never clears them), and a one-time pulse on what lit;
6
+ // - each root's state file and its "written" mark, in one of three looks
7
+ // (applied, partly applied, not applied);
8
+ // - at most two attribute lines on a card: a value read from another estate ("known after apply", dashed amber,
9
+ // until its producer applied, then the real value in green), or a known value that changed; no other attribute;
10
+ // - the ghosted "plan again, approve again" approval, struck through;
11
+ // - the resource's name first on its card, its type second.
12
+ // All of it is removed and drawn again on each call, so a redraw of the marks is harmless.
13
+
14
+ import { cardLines, cardTitle, lineState, planOf, rootsOf, stateMarks, stateWords } from "./kiosk-light.js";
15
+
16
+ const NS = "http://www.w3.org/2000/svg";
17
+ const make = (tag, attrs, text) => {
18
+ const n = document.createElementNS(NS, tag);
19
+ for (const [k, v] of Object.entries(attrs || {})) n.setAttribute(k, String(v));
20
+ if (text !== undefined) n.textContent = text;
21
+ return n;
22
+ };
23
+
24
+ /** Take back what the last call drew or changed. */
25
+ export function clearLight(svg) {
26
+ if (!svg) return;
27
+ for (const el of svg.querySelectorAll("[data-kl-layer]")) el.remove();
28
+ for (const el of svg.querySelectorAll("[data-kl]")) el.removeAttribute("data-kl");
29
+ for (const el of svg.querySelectorAll("[data-kl-pulse]")) el.removeAttribute("data-kl-pulse");
30
+ }
31
+
32
+ /**
33
+ * Draw a step's lighting. `msg` is the last `behold:light` message (or null),
34
+ * `answer` and `progress` the frame's reads (the paced run view), and `h` the
35
+ * frame's helpers: `{ cardsOf(root), rootBox(root), compMode, pulsed }`.
36
+ * `pulsed` is a `{ token }` box kept between calls so a beat pulses once.
37
+ */
38
+ export function drawLight(svg, msg, answer, progress, h) {
39
+ clearLight(svg);
40
+ if (!svg || !msg || !answer || answer.error || !Array.isArray(answer.roots)) return;
41
+ const plan = planOf(answer, progress);
42
+ const layer = make("g", { "data-kl-layer": "1", "pointer-events": "none" });
43
+ svg.appendChild(layer);
44
+
45
+ // Cards lead with the resource's name, its type second.
46
+ if (!h.compMode) nameFirst(svg, plan);
47
+
48
+ // Lit and dimmed.
49
+ if (msg.lit) {
50
+ const lit = new Set(msg.ids);
51
+ const litRoots = new Set(msg.roots);
52
+ const cards = [...svg.querySelectorAll("[data-node-id]")];
53
+ const isLit = (g) => (h.compMode ? litRoots.has(rootOfCard(answer, g.getAttribute("data-node-id"), h)) : lit.has(g.getAttribute("data-node-id")));
54
+ const fresh = h.pulsed && h.pulsed.token !== msg.token;
55
+ for (const g of cards) {
56
+ const on = isLit(g);
57
+ g.setAttribute("data-kl", on ? "lit" : "dim");
58
+ if (on && fresh) g.setAttribute("data-kl-pulse", "1");
59
+ }
60
+ if (h.pulsed) h.pulsed.token = msg.token;
61
+ const state = new Map(cards.map((g) => [g.getAttribute("data-node-id"), g.getAttribute("data-kl")]));
62
+ for (const e of svg.querySelectorAll("g[data-edge-from]")) {
63
+ e.setAttribute("data-kl", state.get(e.getAttribute("data-edge-from")) === "lit" && state.get(e.getAttribute("data-edge-to")) === "lit" ? "path" : "dim");
64
+ }
65
+ // The reads between roots: at full weight between two lit roots, dim otherwise.
66
+ for (const l of svg.querySelectorAll("line[data-tg-read-from]")) {
67
+ l.setAttribute("data-kl", litRoots.has(l.getAttribute("data-tg-read-from")) && litRoots.has(l.getAttribute("data-tg-read-to")) ? "path" : "dim");
68
+ }
69
+ } else if (h.pulsed) h.pulsed.token = msg.token;
70
+
71
+ if (msg.labels) {
72
+ drawStates(layer, answer, progress, h);
73
+ if (!h.compMode) drawSlots(layer, svg, plan, answer, progress, h, msg);
74
+ }
75
+ if (msg.ghost) drawGhost(layer, h);
76
+ }
77
+
78
+ function rootOfCard(answer, id, h) {
79
+ const r = (answer.roots || []).find((x) => h.cardsOf(x.path).some((g) => g.getAttribute("data-node-id") === id));
80
+ return r ? r.path : null;
81
+ }
82
+
83
+ function nameFirst(svg, plan) {
84
+ const byCard = new Map([...plan.resources.values()].filter((r) => r.cardId).map((r) => [r.cardId, r]));
85
+ for (const g of svg.querySelectorAll("[data-node-id]")) {
86
+ const res = byCard.get(g.getAttribute("data-node-id"));
87
+ if (!res || !res.type) continue;
88
+ const texts = [...g.querySelectorAll(":scope > text")];
89
+ const title = texts.find((t) => t.getAttribute("visibility") !== "hidden" && (t.textContent || "").trim());
90
+ if (!title) continue;
91
+ const { name, type } = cardTitle(res.address);
92
+ title.textContent = name;
93
+ // The kind line the kiosk hides ("terraform_data · terraform") becomes the type, second.
94
+ const kind = texts.find((t) => t.hasAttribute("data-kiosk-quiet") && / · /.test(t.textContent || ""));
95
+ if (kind) {
96
+ kind.textContent = type;
97
+ kind.removeAttribute("visibility");
98
+ kind.setAttribute("data-kl", "type");
99
+ }
100
+ }
101
+ }
102
+
103
+ /** Each root's state file label, with its written mark and its look. */
104
+ function drawStates(layer, answer, progress, h) {
105
+ const marks = stateMarks(answer, progress);
106
+ for (const r of rootsOf(answer)) {
107
+ const m = marks[r.path];
108
+ // behold#940: a label rides inside its box's own group when the graph has one, so it moves, grows and reflows with the box.
109
+ const host = h.boxHost ? h.boxHost(r.path) : null;
110
+ const box = host || h.rootBox(r.path);
111
+ if (!m || !box) continue;
112
+ // behold#939: a prompt-driven step draws the roots' resources, which fill their boxes: the label goes under the box, off the cards.
113
+ const y = h.below ? box.y2 + 26 : box.y2 - 12;
114
+ const g = make("g", { "data-kl-state": r.path, "data-kl-look": m.look || "none", "pointer-events": "none" });
115
+ if (host) g.setAttribute("data-kl-layer", "1");
116
+ const words = stateWords(m);
117
+ const w = Math.max(120, words.length * 7.4 + 20);
118
+ const x = box.x + 14;
119
+ const rect = make("rect", { x, y: y - 17, width: w, height: 22, rx: 4, fill: "var(--panel, var(--bg))", stroke: "var(--frame-neutral, var(--neutral))", "stroke-width": 1.5 });
120
+ // Three looks, by shape as well as colour: solid is applied, half filled with a dashed edge is partly applied, hollow dotted is not applied.
121
+ let ink = "var(--fg)";
122
+ if (m.look === "applied") {
123
+ rect.setAttribute("fill", "var(--frame-managed, var(--managed))");
124
+ rect.setAttribute("stroke", "var(--frame-managed, var(--managed))");
125
+ ink = "var(--bg)";
126
+ g.appendChild(rect);
127
+ } else if (m.look === "partial") {
128
+ rect.setAttribute("stroke", "var(--frame-pending, var(--pending))");
129
+ rect.setAttribute("stroke-dasharray", "6 3");
130
+ g.appendChild(rect);
131
+ g.appendChild(make("rect", { x, y: y - 17, width: w / 2, height: 22, rx: 4, fill: "var(--frame-pending, var(--pending))", opacity: 0.45 }));
132
+ } else if (m.look === "not-applied") {
133
+ rect.setAttribute("stroke-dasharray", "2 3");
134
+ rect.setAttribute("fill", "none");
135
+ g.appendChild(rect);
136
+ ink = "var(--muted)";
137
+ } else g.appendChild(rect);
138
+ g.appendChild(make("text", { x: x + 10, y: y - 1.5, "font-size": 13, "font-weight": 700, fill: ink }, words));
139
+ g.appendChild(make("title", {}, m.estate ? `${r.path} is an estate: it keeps records, not a state file${m.written ? "; the apply wrote them" : ""}` : `${r.path}'s state file is ${m.file}${m.from === "path" ? " (named from the root's path)" : ""}${m.written ? "; the apply wrote it" : ""}`));
140
+ (host ? host.parent : layer).appendChild(g);
141
+ }
142
+ }
143
+
144
+ /** A card's attribute lines (web/kiosk-light.js cardLines): unknown dashed amber, applied or changed solid. */
145
+ function drawSlots(layer, svg, plan, answer, progress, h, msg) {
146
+ const byCard = new Map();
147
+ for (const s of cardLines(plan, msg && msg.light)) {
148
+ if (!byCard.has(s.cardId)) byCard.set(s.cardId, []);
149
+ byCard.get(s.cardId).push(s);
150
+ }
151
+ for (const [id, slots] of byCard) {
152
+ const card = svg.querySelector(`[data-node-id="${CSS.escape(id)}"]`);
153
+ const rect = card && card.querySelector(":scope > rect");
154
+ if (!rect) continue;
155
+ const b = rect.getBBox();
156
+ slots.forEach((s, i) => {
157
+ const st = lineState(s, answer, progress);
158
+ const words = st.text;
159
+ // behold#940: a card the scene drew (data-kl-synth) has room under it for its lines, in bigger type; a graph card's hang over its foot.
160
+ const synth = card.hasAttribute("data-kl-synth");
161
+ const size = synth ? 14 : 11.5;
162
+ // One line, inside the card: a long value ends in an ellipsis.
163
+ const fit = Math.max(8, Math.floor((b.width - 28) / (size * 0.6)));
164
+ // A filled line's payoff is its end (the id the producer made): cut from the middle, and drop the attribute's name before the end.
165
+ const shown = words.length <= fit ? words : fit - 9 >= 14 ? `${words.slice(0, 6)}...${words.slice(words.length - (fit - 9))}` : `...${words.slice(words.length - (fit - 3))}`;
166
+ const w = synth ? b.width - 12 : Math.min(b.width - 12, Math.max(90, shown.length * 6.8 + 16));
167
+ const rowH = synth ? 22 : 18;
168
+ const y = synth ? b.y + b.height + 6 + rowH + i * 26 : b.y + b.height - 3 + i * 22;
169
+ const ink = st.state === "applied" ? "var(--frame-managed, var(--managed))" : "var(--frame-pending, var(--pending))";
170
+ const g = make("g", { "data-kl-slot": id, "data-kl-filled": st.state === "applied" ? "1" : "0", "data-kl-line": st.state });
171
+ g.setAttribute("transform", card.getAttribute("transform") || "");
172
+ // Unknown: a dashed amber outline with a hollow inside. Applied: solid green, tinted. A changed value: solid amber.
173
+ g.appendChild(make("rect", { x: b.x + 6, y: y - rowH, width: w, height: rowH, rx: 3, fill: st.state === "unknown" ? "var(--bg)" : ink, "fill-opacity": st.state === "unknown" ? 1 : 0.25, stroke: ink, "stroke-width": 1.5, "stroke-dasharray": st.state === "unknown" ? "4 3" : "none" }));
174
+ g.appendChild(make("text", { x: b.x + 12, y: y - (synth ? 6 : 5), "font-size": size, "font-weight": 600, fill: "var(--fg)" }, shown));
175
+ layer.appendChild(g);
176
+ });
177
+ }
178
+ }
179
+
180
+ /** The approval the change does not need: faded, between network and app, then struck through. */
181
+ function drawGhost(layer, h) {
182
+ const a = h.rootBox("network");
183
+ const b = h.rootBox("app");
184
+ if (!a || !b) return;
185
+ const cx = (a.x + a.x2 + b.x + b.x2) / 4;
186
+ const cy = (a.y + a.y2 + b.y + b.y2) / 4;
187
+ const words = "plan again, approve again";
188
+ const w = words.length * 8.6 + 28;
189
+ const g = make("g", { "data-kl-ghost": "1", opacity: 0.55 });
190
+ g.appendChild(make("rect", { x: cx - w / 2, y: cy - 16, width: w, height: 32, rx: 6, fill: "var(--panel, var(--bg))", stroke: "var(--frame-foreign, var(--foreign))", "stroke-width": 2, "stroke-dasharray": "6 4" }));
191
+ g.appendChild(make("text", { x: cx, y: cy + 5, "text-anchor": "middle", "font-size": 15, "font-weight": 600, fill: "var(--fg)" }, words));
192
+ // The strike draws itself after the approval has been on screen a moment.
193
+ const strike = make("line", { x1: cx - w / 2 + 6, y1: cy, x2: cx + w / 2 - 6, y2: cy, stroke: "var(--frame-degraded, var(--degraded))", "stroke-width": 3, class: "kl-strike", pathLength: 1 });
194
+ g.appendChild(strike);
195
+ layer.appendChild(g);
196
+ }