@intentius/behold 0.30.1 → 0.31.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (129) hide show
  1. package/AGENTS.md +475 -16
  2. package/README.md +25 -19
  3. package/demos.json +14 -9
  4. package/dist/cli.js +54900 -26771
  5. package/example-carve/README.md +19 -23
  6. package/example-carve/app/package.json +1 -1
  7. package/example-carve/app/src/carved.ts +3 -3
  8. package/example-carve/carve-report.json +1 -1
  9. package/example-carve/{legacy-tf → tf-root}/terraform.tfstate +1 -1
  10. package/example-choudoufu-estate/README.md +7 -0
  11. package/example-choudoufu-estate/chant.workspace.json +1 -1
  12. package/example-choudoufu-estate/scripts/choudoufu-down.sh +2 -1
  13. package/example-choudoufu-estate/scripts/choudoufu-up.sh +10 -3
  14. package/example-terraform-estate/README.md +32 -5
  15. package/example-terraform-estate/chant.workspace.json +1 -1
  16. package/example-terraform-estate/recorded/adoption/platform.json +72 -0
  17. package/example-terraform-estate/recorded/adoption/prod.json +224 -0
  18. package/example-terralith/README.md +1 -1
  19. package/example-three-cloud/README.md +111 -18
  20. package/example-three-cloud/aws/Pulumi.yaml +15 -0
  21. package/example-three-cloud/aws/index.ts +174 -0
  22. package/example-three-cloud/aws/package-lock.json +2725 -0
  23. package/example-three-cloud/aws/package.json +14 -0
  24. package/example-three-cloud/aws/tsconfig.json +17 -0
  25. package/example-three-cloud/azure/main.tf +48 -0
  26. package/example-three-cloud/azure/site.tf +104 -0
  27. package/example-three-cloud/chant.config.json +9 -0
  28. package/example-three-cloud/chant.workspace.json +30 -4
  29. package/example-three-cloud/dns/chant.config.ts +26 -1
  30. package/example-three-cloud/dns/src/records.component.ts +32 -6
  31. package/example-three-cloud/package-lock.json +48 -27
  32. package/example-three-cloud/package.json +8 -6
  33. package/example-three-cloud/scripts/emulators-up.sh +28 -1
  34. package/example-three-cloud/scripts/front-door.ts +679 -86
  35. package/package.json +13 -6
  36. package/web/adopt-pulumi.js +114 -0
  37. package/web/adopt-pulumi.test.js +28 -0
  38. package/web/adopt.js +203 -0
  39. package/web/adopt.test.js +27 -0
  40. package/web/app.js +614 -19
  41. package/web/carve-steps.js +1 -1
  42. package/web/carve-steps.test.js +2 -2
  43. package/web/change-set-overlay.js +12 -5
  44. package/web/change-set-overlay.test.js +22 -0
  45. package/web/drift-stream.js +241 -0
  46. package/web/drift-stream.test.js +146 -0
  47. package/web/edge-weight.d.ts +1 -1
  48. package/web/edge-weight.js +5 -1
  49. package/web/edge-weight.test.js +19 -0
  50. package/web/embed.js +2 -2
  51. package/web/event-help-modal.js +18 -12
  52. package/web/event-help-modal.test.js +28 -1
  53. package/web/graph-query.js +180 -0
  54. package/web/graph-query.test.js +49 -0
  55. package/web/graph.html +107 -0
  56. package/web/index-diff.js +109 -0
  57. package/web/index-diff.test.js +39 -0
  58. package/web/index.html +55 -0
  59. package/web/kiosk-ask-layout.js +85 -0
  60. package/web/kiosk-ask-layout.test.js +83 -0
  61. package/web/kiosk-ask-tips.js +477 -0
  62. package/web/kiosk-ask-tips.test.js +372 -0
  63. package/web/kiosk-ask.js +774 -0
  64. package/web/kiosk-ask.test.js +593 -0
  65. package/web/kiosk-banner.js +108 -0
  66. package/web/kiosk-banner.test.js +72 -0
  67. package/web/kiosk-center-cards.test.js +110 -0
  68. package/web/kiosk-estate-scene.js +267 -0
  69. package/web/kiosk-estate-scene.test.js +21 -0
  70. package/web/kiosk-event-help.js +4 -1
  71. package/web/kiosk-graph-pane.js +63 -0
  72. package/web/kiosk-graph-pane.test.js +105 -0
  73. package/web/kiosk-light-frame.js +197 -0
  74. package/web/kiosk-light.js +547 -0
  75. package/web/kiosk-light.test.js +297 -0
  76. package/web/kiosk-member-kind.test.js +140 -0
  77. package/web/kiosk-metrics.js +7 -4
  78. package/web/kiosk-modal-sticky.test.js +2 -1
  79. package/web/kiosk-popover.js +4 -1
  80. package/web/kiosk-refit.test.js +81 -0
  81. package/web/kiosk-reset.js +49 -0
  82. package/web/kiosk-reset.test.js +11 -0
  83. package/web/kiosk-shot.js +40 -2
  84. package/web/kiosk-shot.test.js +23 -1
  85. package/web/kiosk-side.js +296 -0
  86. package/web/kiosk-side.test.js +249 -0
  87. package/web/kiosk-vendor.js +85 -7
  88. package/web/kiosk-vendor.test.js +9 -9
  89. package/web/kiosk-watch.js +20 -4
  90. package/web/kiosk-watch.test.js +15 -1
  91. package/web/kiosk.html +153 -1
  92. package/web/kiosk.js +252 -27
  93. package/web/kiosk.test.js +25 -1
  94. package/web/member-kind.js +31 -0
  95. package/web/small-stage.test.js +4 -0
  96. package/web/template-apps.js +245 -0
  97. package/web/template-apps.test.js +252 -0
  98. package/web/templates.js +285 -0
  99. package/web/templates.test.js +155 -0
  100. package/web/terragucci-change.js +30 -13
  101. package/web/terragucci-lifecycle.js +112 -62
  102. package/web/terragucci-lifecycle.test.js +29 -1
  103. package/web/terragucci-timeline.js +39 -2
  104. package/web/terragucci-timeline.test.js +42 -1
  105. package/web/tool-mark.js +4 -4
  106. package/web/tool-mark.test.js +1 -1
  107. package/web/vendors/atmos.svg +1 -0
  108. package/web/vendors/chant.svg +1 -0
  109. package/web/vendors/choudoufu.svg +1 -0
  110. package/web/vendors/terragrunt.svg +9 -0
  111. package/web/vendors/terragucci.svg +1 -0
  112. package/example-three-cloud/aws/chant.config.ts +0 -8
  113. package/example-three-cloud/aws/site.component.ts +0 -13
  114. package/example-three-cloud/aws/src/site.ts +0 -27
  115. package/example-three-cloud/azure/chant.config.ts +0 -1
  116. package/example-three-cloud/azure/src/site.component.ts +0 -13
  117. package/example-three-cloud/azure/src/site.ts +0 -18
  118. package/web/vendors/choudoufu-128.png +0 -0
  119. package/web/vendors/choudoufu-64.png +0 -0
  120. /package/example-carve/{legacy-tf → tf-root}/cdn.tf +0 -0
  121. /package/example-carve/{legacy-tf → tf-root}/compute.tf +0 -0
  122. /package/example-carve/{legacy-tf → tf-root}/floci-override.tf.disabled +0 -0
  123. /package/example-carve/{legacy-tf → tf-root}/modules/cdn/main.tf +0 -0
  124. /package/example-carve/{legacy-tf → tf-root}/naming.tf +0 -0
  125. /package/example-carve/{legacy-tf → tf-root}/network.tf +0 -0
  126. /package/example-carve/{legacy-tf → tf-root}/observability.tf +0 -0
  127. /package/example-carve/{legacy-tf → tf-root}/outputs.tf +0 -0
  128. /package/example-carve/{legacy-tf → tf-root}/storage.tf +0 -0
  129. /package/example-carve/{legacy-tf → tf-root}/versions.tf +0 -0
@@ -21,7 +21,7 @@ export const CARVE_STEPS = [
21
21
  {
22
22
  id: "advise",
23
23
  label: "Advise",
24
- blurb: "chant scored every resource in the Terraform half. Green carves cheaply; grey stays where it is.",
24
+ blurb: "chant scored every resource in the Terraform root. Green hands over cheaply; grey stays in Terraform.",
25
25
  },
26
26
  {
27
27
  id: "pick",
@@ -301,14 +301,14 @@ const CARVE_STATE = {
301
301
  stage: "emitted",
302
302
  graduated: false,
303
303
  note: "emitted — typed chant source exists, and the surviving Terraform still reads the resource directly. `carve bridge` is next.",
304
- applyCommand: "chant carve apply --from legacy-tf --output app/carveout --env <env> --stack <stack> --write-source",
304
+ applyCommand: "chant carve apply --from tf-root --output app/carveout --env <env> --stack <stack> --write-source",
305
305
  },
306
306
  {
307
307
  target: "aws_s3_bucket.assets",
308
308
  stage: "applied",
309
309
  graduated: true,
310
310
  note: "graduated — `carve apply` recorded the ownership marker (stack assets, env prod). chant owns it.",
311
- applyCommand: "chant carve apply --from legacy-tf --output app/carveout --env prod --stack assets --write-source",
311
+ applyCommand: "chant carve apply --from tf-root --output app/carveout --env prod --stack assets --write-source",
312
312
  },
313
313
  ],
314
314
  apply: { human: true, note: "behold has no apply endpoint and no apply button, by design." },
@@ -64,12 +64,17 @@ export function actionWords(actions) {
64
64
  return order.filter((k) => actions && actions[k]).map((k) => (actions[k] === 1 ? k : `${actions[k]} ${k}`)).join(", ");
65
65
  }
66
66
 
67
- /** The marks to draw: per node id, its colour, its tag and its tooltip. */
67
+ /** The entries on one card: its own, and on a counted block its instances' (#996). */
68
+ const onCard = (a, id) => a.entries.filter((e) => e.node === id || e.block === id);
69
+
70
+ /** The marks to draw: per node id, its colour, its tag and its tooltip. A
71
+ * counted block's mark is the rollup of its instances' (#996), and each
72
+ * instance card has its own. */
68
73
  export function nodeMarks(a) {
69
74
  const out = {};
70
75
  if (!a || a.error || a.refusal || !a.nodes) return out;
71
76
  for (const [id, n] of Object.entries(a.nodes)) {
72
- const entries = a.entries.filter((e) => e.node === id);
77
+ const entries = onCard(a, id);
73
78
  out[id] = {
74
79
  bucket: n.bucket,
75
80
  color: bucketColor(n.bucket),
@@ -116,19 +121,21 @@ export function entryLines(e) {
116
121
  /** The entries on one card, for the inspect pane. */
117
122
  export function entriesFor(a, id) {
118
123
  if (!a || a.error || a.refusal || !a.entries) return [];
119
- return a.entries.filter((e) => e.node === id).map(entryLines);
124
+ return onCard(a, id).map(entryLines);
120
125
  }
121
126
 
122
127
  /**
123
128
  * The entries a reader would not see on the graph: those chant mapped to no
124
129
  * node, and those whose node this view does not draw (another lens, or a
125
- * member not on screen). `drawn` is the set of node ids on the canvas.
130
+ * member not on screen). `drawn` is the set of node ids on the canvas. An
131
+ * instance whose card is not drawn is on the graph all the same when its
132
+ * block card is: the block's rollup outline carries it (#996).
126
133
  */
127
134
  export function offGraph(a, drawn) {
128
135
  if (!a || a.error || a.refusal || !a.entries) return { noNode: [], notDrawn: [] };
129
136
  return {
130
137
  noNode: a.entries.filter((e) => !e.node).map(entryLines),
131
- notDrawn: a.entries.filter((e) => e.node && drawn && !drawn.has(e.node)).map((e) => ({ ...entryLines(e), node: e.node })),
138
+ notDrawn: a.entries.filter((e) => e.node && drawn && !drawn.has(e.node) && !(e.block && drawn.has(e.block))).map((e) => ({ ...entryLines(e), node: e.node })),
132
139
  };
133
140
  }
134
141
 
@@ -81,3 +81,25 @@ describe("a node's entries (#681)", () => {
81
81
  expect(gapLines({ ...answer, gaps: [{ member: "api", status: "failed", error: "no credentials", holes: [] }] })).toEqual([{ text: "api did not plan: no credentials, so its changes are not drawn", title: "" }]);
82
82
  });
83
83
  });
84
+
85
+ // #996: a `count = 3` block's change set. Each instance's entry outlines its
86
+ // own card, `<blockNode>[k]`, and the block card carries the rollup. The
87
+ // entries name the block node, as chant maps them before INTENTIUS/chant#4454
88
+ // (src/instance-cards.test.ts shows the instance-node mapping gives the same).
89
+ describe("instance cards (#996)", () => {
90
+ const entry = (i, action) => ({ member: "tf", planner: "terraform", address: `aws_s3_bucket.logs[${i}]`, type: "aws_s3_bucket", action, attributes: [], node: "tf/app/aws_s3_bucket.logs" });
91
+ const doc = { changeSet: { digest: "jcs1-sha256:00", entries: [entry(0, "no-op"), entry(1, "update"), entry(2, "create")], members: [], graph: { member: "tf", at: null } } };
92
+ const counted = overlayFrom(gate, doc, new Date(0));
93
+ it("puts each instance's entry on its own card and all of them on the block", () => {
94
+ const marks = nodeMarks(counted);
95
+ expect(marks["tf/app/aws_s3_bucket.logs[1]"].tag).toBe("update");
96
+ expect(marks["tf/app/aws_s3_bucket.logs[2]"].tag).toBe("create");
97
+ expect(marks["tf/app/aws_s3_bucket.logs"].tag).toBe("create, update");
98
+ expect(entriesFor(counted, "tf/app/aws_s3_bucket.logs[2]").map((e) => e.head)).toEqual(["create aws_s3_bucket.logs[2]"]);
99
+ expect(entriesFor(counted, "tf/app/aws_s3_bucket.logs")).toHaveLength(2);
100
+ });
101
+ it("counts an instance whose card is not drawn as on the graph when its block is", () => {
102
+ expect(offGraph(counted, new Set(["tf/app/aws_s3_bucket.logs"])).notDrawn).toEqual([]);
103
+ expect(offGraph(counted, new Set()).notDrawn).toHaveLength(2);
104
+ });
105
+ });
@@ -0,0 +1,241 @@
1
+ // behold#998: streamed drift, the page's half.
2
+ //
3
+ // The server narrates one run of chant's drift stream as `drift` frames on
4
+ // /api/events (src/drift-stream.ts): begin, start (the addresses a read
5
+ // expects), one record per instance as it arrives, settle (with a
6
+ // not-reached record already sent for every expected address no record
7
+ // answered), failed, end. This module folds a frame into the graph IR on
8
+ // screen, the same way web/pending.js folds a `member` frame: in place, the
9
+ // node set never changes, and it returns the ids that moved so the caller
10
+ // repaints only those.
11
+ //
12
+ // Reading is not a status. A card a started read has not reported yet keeps
13
+ // its `_status` and gains `_driftReading`, which the page draws dimmed and
14
+ // dashed, never filled. Only a record changes `_status`.
15
+
16
+ /**
17
+ * The addresses of a member's cards, for the start request. A stack card
18
+ * (`attrs._stackOf`, src/stack-lens.ts, an estate's default zoom) is titled
19
+ * `<kind> ×<n>`, which is no address: the cards it holds are asked about
20
+ * instead, each by its id inside the member.
21
+ */
22
+ export function memberAddresses(ir, member) {
23
+ const prefix = member + "/";
24
+ const out = [];
25
+ const add = (a) => {
26
+ if (a && !out.includes(a)) out.push(a);
27
+ };
28
+ for (const n of (ir && ir.nodes) || []) {
29
+ if (!n.id || !n.id.startsWith(prefix)) continue;
30
+ const held = n.attrs && n.attrs._stackOf;
31
+ if (Array.isArray(held)) {
32
+ for (const m of held) {
33
+ const id = typeof m === "string" ? m : m && typeof m.id === "string" ? m.id : "";
34
+ if (id.startsWith(prefix)) add(id.slice(prefix.length));
35
+ }
36
+ continue;
37
+ }
38
+ add(n.attrs && typeof n.attrs.address === "string" ? n.attrs.address : n.id.slice(prefix.length));
39
+ }
40
+ return out;
41
+ }
42
+
43
+ /** The id of one `_stackOf` entry: a string, or an object's `id`. */
44
+ const heldId = (m) => (typeof m === "string" ? m : m && typeof m.id === "string" ? m.id : "");
45
+
46
+ /**
47
+ * behold#1021: the card a stack holds that a record or an expected address
48
+ * names, by the same match as a card of its own (its id, `<member>/<address>`
49
+ * or the record's node), or undefined. A held card's `address` is not carried
50
+ * on `_stackOf`, which is why memberAddresses asks about each by its id.
51
+ */
52
+ function heldMatch(n, prefix, address, node) {
53
+ const held = n.attrs && n.attrs._stackOf;
54
+ if (!Array.isArray(held)) return undefined;
55
+ for (const m of held) {
56
+ const id = heldId(m);
57
+ if (!id.startsWith(prefix)) continue;
58
+ if ((node && (id === node || id === prefix + node)) || id === prefix + address) return id;
59
+ }
60
+ return undefined;
61
+ }
62
+
63
+ /**
64
+ * The cards a record or an expected address lands on: the record's graph
65
+ * node when chant mapped one, else the card whose id or `address` is the
66
+ * address, inside the member. behold#1021: a stack card (`_stackOf`) that
67
+ * holds such a card is one too, so the default stacked view colours.
68
+ */
69
+ export function cardsFor(ir, member, address, node) {
70
+ const prefix = member + "/";
71
+ const ids = [];
72
+ for (const n of (ir && ir.nodes) || []) {
73
+ if (!n.id || !n.id.startsWith(prefix)) continue;
74
+ const own = n.attrs && n.attrs.address;
75
+ // chant's workspace drift composes `node` with the member in front (`<member>/<root>/<path>`), as workspace graph does; a bare one is prefixed.
76
+ if ((node && (n.id === node || n.id === prefix + node)) || n.id === prefix + address || own === address || heldMatch(n, prefix, address, node)) ids.push(n.id);
77
+ }
78
+ return ids;
79
+ }
80
+
81
+ /**
82
+ * behold#1021: the tones a record paints (src/drift-tone.ts `CardTone`),
83
+ * worst first. A stack card takes the worst of its cards' records: one drifted
84
+ * card in a stack of ten makes the stack drifted. `neutral` (not observed, or
85
+ * a record behold does not know) ranks above `runtime` and `good`, so a stack
86
+ * is never green while a card in it went unseen.
87
+ */
88
+ export const TONES_WORST_FIRST = ["warn", "accent", "neutral", "runtime", "good"];
89
+
90
+ /** The worst of `tones`, by {@link TONES_WORST_FIRST}; a tone outside it ranks as neutral. */
91
+ export function worstTone(tones) {
92
+ let best = -1;
93
+ for (const t of tones) {
94
+ const i = TONES_WORST_FIRST.indexOf(t);
95
+ const rank = i < 0 ? TONES_WORST_FIRST.indexOf("neutral") : i;
96
+ if (best < 0 || rank < best) best = rank;
97
+ }
98
+ return best < 0 ? undefined : TONES_WORST_FIRST[best];
99
+ }
100
+
101
+ /** A record frame as the `_drift` a card keeps. */
102
+ function driftOf(frame) {
103
+ return {
104
+ status: frame.status,
105
+ read: frame.read,
106
+ label: frame.label,
107
+ run: frame.run,
108
+ ...(frame.reason ? { reason: frame.reason } : {}),
109
+ ...(frame.notReached ? { notReached: true } : {}),
110
+ ...(frame.unknown ? { unknown: true } : {}),
111
+ };
112
+ }
113
+
114
+ /**
115
+ * behold#1021: a stack card's state for one run, `attrs._driftHeld`: the
116
+ * cards a start expected and the record each has had, by held id. A new run
117
+ * starts it afresh.
118
+ */
119
+ function heldState(a, run) {
120
+ if (!a._driftHeld || a._driftHeld.run !== run) a._driftHeld = { run, expected: [], records: {} };
121
+ return a._driftHeld;
122
+ }
123
+
124
+ /**
125
+ * Paint a stack card from its held records: `_status` the worst tone, `_drift`
126
+ * that record's with the count in its label, each `_stackOf` entry's status
127
+ * the tone its record painted (the inspect pane lists them), and reading
128
+ * while a held card a start expected has not reported. The worst tone so far
129
+ * only gets worse as records arrive, so a warn, accent or neutral one paints
130
+ * at once; a good or runtime one waits for the last expected card, so a
131
+ * stack is never green while a card in it is still being read.
132
+ */
133
+ function paintStack(a, state) {
134
+ const records = Object.values(state.records);
135
+ const worst = worstTone(records.map((r) => r.tone));
136
+ const atWorst = records.filter((r) => worstTone([r.tone]) === worst);
137
+ const held = Array.isArray(a._stackOf) ? a._stackOf : [];
138
+ const pending = state.expected.some((id) => !state.records[id]);
139
+ if (atWorst.length && (!pending || TONES_WORST_FIRST.indexOf(worst) <= TONES_WORST_FIRST.indexOf("neutral"))) {
140
+ const top = atWorst[0].drift;
141
+ const of = held.length || records.length;
142
+ a._status = worst;
143
+ a._drift = { ...top, label: `${top.label}: ${atWorst.length} of ${of} card${of === 1 ? "" : "s"}${records.length < of ? `, ${records.length} reported` : ""}` };
144
+ if (records.every((r) => r.drift.status === "not-observed")) a._unobserved = { reason: top.reason || "read-failed" };
145
+ else delete a._unobserved;
146
+ }
147
+ for (const m of held) if (m && typeof m === "object" && state.records[m.id]) m.status = state.records[m.id].tone;
148
+ if (pending) a._driftReading = state.run;
149
+ else delete a._driftReading;
150
+ }
151
+
152
+ function nodeById(ir) {
153
+ return new Map(((ir && ir.nodes) || []).map((n) => [n.id, n]));
154
+ }
155
+
156
+ /**
157
+ * Fold one `drift` frame into `ir`. Returns `{ moved, reading }`: the ids
158
+ * whose paint changed, and how many cards of this run are still reading.
159
+ */
160
+ export function applyDriftFrame(ir, frame) {
161
+ const moved = [];
162
+ if (!ir || !frame || !frame.kind || !frame.member) return { moved, reading: 0 };
163
+ const byId = nodeById(ir);
164
+ const attrsOf = (id) => {
165
+ const n = byId.get(id);
166
+ return n ? n.attrs || (n.attrs = {}) : null;
167
+ };
168
+ if (frame.kind === "start") {
169
+ const prefix = frame.member + "/";
170
+ for (const address of frame.expected || []) {
171
+ for (const id of cardsFor(ir, frame.member, address, null)) {
172
+ const a = attrsOf(id);
173
+ if (!a) continue;
174
+ const held = heldMatch(byId.get(id), prefix, address, null);
175
+ if (held) {
176
+ const state = heldState(a, frame.run);
177
+ if (!state.expected.includes(held)) state.expected.push(held);
178
+ }
179
+ if (a._driftReading === frame.run) continue;
180
+ a._driftReading = frame.run;
181
+ moved.push(id);
182
+ }
183
+ }
184
+ } else if (frame.kind === "record") {
185
+ const prefix = frame.member + "/";
186
+ for (const id of cardsFor(ir, frame.member, frame.address, frame.node)) {
187
+ const a = attrsOf(id);
188
+ if (!a) continue;
189
+ // behold#1021: a stack card keeps each held card's record and paints the worst.
190
+ const held = heldMatch(byId.get(id), prefix, frame.address, frame.node);
191
+ if (held) {
192
+ const state = heldState(a, frame.run);
193
+ state.records[held] = { tone: frame.tone, drift: driftOf(frame) };
194
+ paintStack(a, state);
195
+ moved.push(id);
196
+ continue;
197
+ }
198
+ delete a._driftReading;
199
+ a._status = frame.tone;
200
+ a._drift = driftOf(frame);
201
+ if (frame.status === "not-observed") a._unobserved = { reason: frame.reason || "read-failed" };
202
+ else delete a._unobserved;
203
+ moved.push(id);
204
+ }
205
+ } else if (frame.kind === "failed" || frame.kind === "end") {
206
+ // Nothing more is coming for these cards: they stop reading and keep the
207
+ // colour they had. A settle has already resolved every card it expected.
208
+ for (const n of (ir && ir.nodes) || []) {
209
+ if (n.attrs && n.attrs._driftReading === frame.run && n.id.startsWith(frame.member + "/")) {
210
+ delete n.attrs._driftReading;
211
+ moved.push(n.id);
212
+ }
213
+ }
214
+ }
215
+ let reading = 0;
216
+ for (const n of (ir && ir.nodes) || []) if (n.attrs && n.attrs._driftReading === frame.run) reading++;
217
+ return { moved, reading };
218
+ }
219
+
220
+ /** The now-line for a frame, or null when the frame says nothing a person needs. */
221
+ export function driftLine(frame, reading) {
222
+ if (!frame) return null;
223
+ switch (frame.kind) {
224
+ case "begin":
225
+ return frame.plan === "per-resource"
226
+ ? `↻ streaming drift for ${frame.member}, one resource at a time (${frame.resources.length})`
227
+ : `↻ streaming drift for ${frame.member}`;
228
+ case "start":
229
+ return `↻ ${frame.member}: reading ${frame.resource || "the member"} (${reading} card${reading === 1 ? "" : "s"} reading)`;
230
+ case "settle":
231
+ return frame.notReached && frame.notReached.length
232
+ ? `↻ ${frame.member}: ${frame.resource || "the read"} settled, ${frame.notReached.length} not reached`
233
+ : null;
234
+ case "failed":
235
+ return `✗ ${frame.member}${frame.resource ? ` ${frame.resource}` : ""}: ${frame.error}`;
236
+ case "end":
237
+ return `■ drift stream for ${frame.member} done`;
238
+ default:
239
+ return null;
240
+ }
241
+ }
@@ -0,0 +1,146 @@
1
+ import { describe, expect, it } from "vitest";
2
+ import { applyDriftFrame, cardsFor, memberAddresses, worstTone } from "./drift-stream.js";
3
+
4
+ // behold#998/#1014: the addresses the page sends to POST /api/workspace/drift/stream.
5
+ describe("memberAddresses", () => {
6
+ it("names each card of the member by its address, once", () => {
7
+ const ir = {
8
+ nodes: [
9
+ { id: "monolith/aws_iam_role.team_a", attrs: { address: "aws_iam_role.team_a" } },
10
+ { id: "monolith/aws_iam_policy.team_a", attrs: {} },
11
+ { id: "team-a/aws_iam_role.team_a", attrs: { address: "aws_iam_role.team_a" } },
12
+ { id: "monolith/aws_iam_role.team_a", attrs: { address: "aws_iam_role.team_a" } },
13
+ ],
14
+ };
15
+ expect(memberAddresses(ir, "monolith")).toEqual(["aws_iam_role.team_a", "aws_iam_policy.team_a"]);
16
+ });
17
+
18
+ it("asks about the cards a stack holds, never the stack's `<kind> ×<n>` title", () => {
19
+ // An estate's default zoom stacks alike cards (src/stack-lens.ts); the
20
+ // stack's address is its title, which the server's resourceBlocks drops,
21
+ // so before this the start named no resource and ended at once.
22
+ const ir = {
23
+ nodes: [
24
+ {
25
+ id: "monolith/aws_iam_policy ×3",
26
+ attrs: {
27
+ address: "aws_iam_policy ×3",
28
+ _stackOf: [{ id: "monolith/aws_iam_policy.team_a" }, { id: "monolith/aws_iam_policy.team_b", status: "ok" }, "monolith/aws_iam_policy.team_c"],
29
+ },
30
+ },
31
+ { id: "monolith/aws_iam_role.team_a", attrs: { address: "aws_iam_role.team_a" } },
32
+ { id: "team-b/aws_iam_policy ×3", attrs: { _stackOf: [{ id: "team-b/aws_iam_policy.x" }] } },
33
+ ],
34
+ };
35
+ expect(memberAddresses(ir, "monolith")).toEqual([
36
+ "aws_iam_policy.team_a",
37
+ "aws_iam_policy.team_b",
38
+ "aws_iam_policy.team_c",
39
+ "aws_iam_role.team_a",
40
+ ]);
41
+ });
42
+ });
43
+
44
+ // behold#1021: in the default stacked view a record colours the stack card that holds its card, worst tone wins.
45
+ describe("streamed drift on a stack card", () => {
46
+ const stacked = () => ({
47
+ nodes: [
48
+ {
49
+ id: "monolith/aws_iam_policy ×3",
50
+ attrs: {
51
+ address: "aws_iam_policy ×3",
52
+ _status: "neutral",
53
+ _stackOf: [{ id: "monolith/aws_iam_policy.team_a" }, { id: "monolith/aws_iam_policy.team_b" }, "monolith/aws_iam_policy.team_c"],
54
+ },
55
+ },
56
+ { id: "monolith/aws_iam_role.team_a", attrs: { address: "aws_iam_role.team_a" } },
57
+ { id: "team-a/aws_iam_policy ×3", attrs: { _stackOf: [{ id: "team-a/aws_iam_policy.team_a" }] } },
58
+ ],
59
+ });
60
+ const ADDRS = ["aws_iam_policy.team_a", "aws_iam_policy.team_b", "aws_iam_policy.team_c", "aws_iam_role.team_a"];
61
+ const start = (ir) => applyDriftFrame(ir, { run: 7, kind: "start", member: "monolith", expected: ADDRS });
62
+ const record = (ir, address, tone, status, extra = {}) =>
63
+ applyDriftFrame(ir, { run: 7, kind: "record", member: "monolith", address, node: null, status, read: "ownership", tone, label: status, ...extra });
64
+
65
+ it("cardsFor finds the stack card that holds the address, in its own member only", () => {
66
+ const ir = stacked();
67
+ expect(cardsFor(ir, "monolith", "aws_iam_policy.team_c", null)).toEqual(["monolith/aws_iam_policy ×3"]);
68
+ expect(cardsFor(ir, "monolith", "x", "monolith/aws_iam_policy.team_b")).toEqual(["monolith/aws_iam_policy ×3"]);
69
+ expect(cardsFor(ir, "monolith", "x", "aws_iam_policy.team_a")).toEqual(["monolith/aws_iam_policy ×3"]);
70
+ expect(cardsFor(ir, "monolith", "aws_iam_role.team_a", null)).toEqual(["monolith/aws_iam_role.team_a"]);
71
+ expect(cardsFor(ir, "team-a", "aws_iam_policy.team_b", null)).toEqual([]);
72
+ });
73
+
74
+ it("a start marks the stack reading; it reads until every held card reported", () => {
75
+ const ir = stacked();
76
+ expect(start(ir).reading).toBe(2);
77
+ const stack = ir.nodes[0].attrs;
78
+ expect(stack._driftReading).toBe(7);
79
+ record(ir, "aws_iam_policy.team_a", "good", "in-sync");
80
+ record(ir, "aws_iam_policy.team_b", "good", "in-sync");
81
+ expect(stack._driftReading).toBe(7);
82
+ // A green so far is no claim while a card is unread: the stack keeps its colour.
83
+ expect(stack._status).toBe("neutral");
84
+ expect(stack._drift).toBeUndefined();
85
+ const { moved } = record(ir, "aws_iam_policy.team_c", "good", "in-sync");
86
+ expect(moved).toEqual(["monolith/aws_iam_policy ×3"]);
87
+ expect(stack._driftReading).toBeUndefined();
88
+ expect(stack._status).toBe("good");
89
+ expect(stack._drift.label).toBe("in-sync: 3 of 3 cards");
90
+ });
91
+
92
+ it("worst tone wins, and paints as soon as it arrives", () => {
93
+ const ir = stacked();
94
+ start(ir);
95
+ const stack = ir.nodes[0].attrs;
96
+ record(ir, "aws_iam_policy.team_a", "good", "in-sync");
97
+ record(ir, "aws_iam_policy.team_b", "warn", "drifted");
98
+ expect(stack._status).toBe("warn");
99
+ expect(stack._drift.status).toBe("drifted");
100
+ expect(stack._drift.label).toBe("drifted: 1 of 3 cards, 2 reported");
101
+ expect(stack._driftReading).toBe(7);
102
+ record(ir, "aws_iam_policy.team_c", "accent", "pending");
103
+ expect(stack._status).toBe("warn");
104
+ expect(stack._driftReading).toBeUndefined();
105
+ // The pane's list carries each held card's tone; a bare-string entry stays a string.
106
+ expect(stack._stackOf).toEqual([
107
+ { id: "monolith/aws_iam_policy.team_a", status: "good" },
108
+ { id: "monolith/aws_iam_policy.team_b", status: "warn" },
109
+ "monolith/aws_iam_policy.team_c",
110
+ ]);
111
+ // The lone card is untouched by the stack's records.
112
+ expect(ir.nodes[1].attrs._status).toBeUndefined();
113
+ });
114
+
115
+ it("an unobserved card keeps a stack from green; all unobserved marks the stack unobserved", () => {
116
+ const ir = stacked();
117
+ start(ir);
118
+ const stack = ir.nodes[0].attrs;
119
+ record(ir, "aws_iam_policy.team_a", "good", "in-sync");
120
+ record(ir, "aws_iam_policy.team_b", "neutral", "not-observed", { reason: "read-failed", notReached: true });
121
+ record(ir, "aws_iam_policy.team_c", "good", "in-sync");
122
+ expect(stack._status).toBe("neutral");
123
+ expect(stack._unobserved).toBeUndefined();
124
+ const all = stacked();
125
+ start(all);
126
+ for (const a of ADDRS.slice(0, 3)) record(all, a, "neutral", "not-observed", { reason: "not-reached", notReached: true });
127
+ expect(all.nodes[0].attrs._unobserved).toEqual({ reason: "not-reached" });
128
+ });
129
+
130
+ it("a new run starts the stack afresh", () => {
131
+ const ir = stacked();
132
+ start(ir);
133
+ for (const a of ADDRS.slice(0, 3)) record(ir, a, "warn", "drifted");
134
+ applyDriftFrame(ir, { run: 8, kind: "start", member: "monolith", expected: ADDRS });
135
+ for (const a of ADDRS.slice(0, 3)) applyDriftFrame(ir, { run: 8, kind: "record", member: "monolith", address: a, node: null, status: "in-sync", read: "ownership", tone: "good", label: "in-sync" });
136
+ expect(ir.nodes[0].attrs._status).toBe("good");
137
+ });
138
+
139
+ it("worstTone ranks warn, accent, neutral, runtime, good; an unknown tone as neutral", () => {
140
+ expect(worstTone(["good", "runtime"])).toBe("runtime");
141
+ expect(worstTone(["good", "neutral", "accent"])).toBe("accent");
142
+ expect(worstTone(["good", "bogus"])).toBe("neutral");
143
+ expect(worstTone([])).toBeUndefined();
144
+ });
145
+ });
146
+
@@ -1,5 +1,5 @@
1
1
  // Types for src/stack-lens.ts, which keeps the traffic path's lines when a card carries a count instead (#877).
2
2
  export const WEIGHTS: Record<string, string>;
3
3
  export function isWired(e: { viaAttr?: string }): boolean;
4
- export function edgeWeights(edges?: Array<{ from: string; to: string; kind?: string; viaAttr?: string; inferred?: boolean }>, kindOf?: Map<string, string | undefined>): Map<string, string>;
4
+ export function edgeWeights(edges?: Array<{ from: string; to: string; kind?: string; viaAttr?: string; inferred?: boolean; origin?: string }>, kindOf?: Map<string, string | undefined>): Map<string, string>;
5
5
  export function weightLegend(weights: Map<string, string>): Array<{ weight: string; label: string; title: string; count: number }>;
@@ -9,6 +9,10 @@
9
9
  // put together. Plumbing that more than two cards share (one role for half
10
10
  // the estate) says nothing at all, so it draws no edge.
11
11
  //
12
+ // An edge chant derived (`origin: "derived"` with the `rule` that drew it,
13
+ // chant#4522/#4523, behold#1030) is a match chant made, not a declaration, so
14
+ // it weighs as an inferred one does.
15
+ //
12
16
  // Only references are weighed: a CI edge (needs, calls, triggers, …) keeps its
13
17
  // own kind's style (./edge-kind.js).
14
18
 
@@ -52,7 +56,7 @@ export function edgeWeights(edges = [], kindOf = new Map()) {
52
56
  if (plumbing(e)) {
53
57
  const hub = PLUMBING_KIND.test(kindOf.get(e.to) || "") ? e.to : e.from;
54
58
  w = (sharers.get(hub)?.size ?? 0) > 2 ? "hidden" : "plumbing";
55
- } else if (e.inferred) w = "inferred";
59
+ } else if (e.inferred || e.origin === "derived") w = "inferred";
56
60
  else if (isWired(e)) w = "wired";
57
61
  else w = "reference";
58
62
  out.set(`${e.from}→${e.to}`, w);
@@ -47,3 +47,22 @@ describe("edgeWeights (#878)", () => {
47
47
  expect(weightLegend(new Map([["x→y", "reference"]]))).toEqual([]);
48
48
  });
49
49
  });
50
+
51
+ describe("edgeWeights over chant's derived edges (behold#1030)", () => {
52
+ it("weighs an edge chant derived as inferred, as the matcher's were", () => {
53
+ const kindOf = new Map([
54
+ ["db", "AWS::RDS::DBInstance"],
55
+ ["group", "AWS::RDS::DBSubnetGroup"],
56
+ ]);
57
+ const w = edgeWeights(
58
+ [{ from: "db", to: "group", kind: "ref", viaAttr: "DBSubnetGroupName", origin: "derived", rule: "aws:AWS::RDS::DBInstance:DBSubnetGroupName" }],
59
+ kindOf,
60
+ );
61
+ expect(w.get("db→group")).toBe("inferred");
62
+ });
63
+
64
+ it("keeps a declared edge a reference", () => {
65
+ const w = edgeWeights([{ from: "db", to: "group", kind: "ref", viaAttr: "DBSubnetGroupName", origin: "declared" }], new Map());
66
+ expect(w.get("db→group")).toBe("reference");
67
+ });
68
+ });
package/web/embed.js CHANGED
@@ -60,8 +60,8 @@ export function viewFromMessage(event, host) {
60
60
  for (const k of VIEW_KEYS) {
61
61
  if (!(k in d)) continue;
62
62
  const v = d[k];
63
- if (k === "radial" || k === "plan") {
64
- // plan (behold#922): true is the plan read, false the declared source again.
63
+ if (k === "radial" || k === "plan" || k === "alike") {
64
+ // plan (behold#922): true is the plan read, false the declared source again. alike (behold#939): false draws every card, true stacks them.
65
65
  if (typeof v === "boolean") want[k] = v;
66
66
  continue;
67
67
  }
@@ -76,6 +76,8 @@ export function modeLine(mode, kind, { at = null, now = 0, resolved = false, out
76
76
  if (kind === "waiting") return null;
77
77
  // behold#757: a highlight's kicker says what it is, in a replay as live: the replay's banner says which run it is.
78
78
  if (kind === "highlight") return HIGHLIGHT_KICKER;
79
+ // The prompt demo's tip cards (web/kiosk-ask-tips.js): the highlight's card, with a kicker of their own.
80
+ if (kind === "tip") return "Tip";
79
81
  if (mode === "replay") return `Replay of the run at ${utc(Number.isFinite(replayAt) ? replayAt : now)} UTC`;
80
82
  if (mode !== "narrated") return null;
81
83
  if (resolved) return outcome ? `Live · ${outcome}` : "Live";
@@ -121,10 +123,10 @@ export const MODAL_STYLE = `
121
123
  border: 2px solid var(--bar, var(--focus)); box-shadow: 0 16px 48px color-mix(in srgb, var(--shadow) 80%, transparent); font-size: 1.05em; }
122
124
  .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)); }
123
125
  /* behold#757: a step's highlight: the runtime bar's tone (no state's), a kicker in it, and its body set to be read. */
124
- .eh-modal-highlight { --bar: var(--bar-runtime, var(--runtime, var(--focus))); background: linear-gradient(color-mix(in srgb, var(--bar) 9%, transparent), transparent 5em), var(--surface-pane-b, var(--panel)); box-shadow: inset 5px 0 0 var(--bar), 0 16px 48px color-mix(in srgb, var(--shadow) 80%, transparent); }
125
- .eh-modal-highlight .eh-modal-mode { text-transform: uppercase; letter-spacing: 0.08em; }
126
- .eh-modal-highlight .eh-modal-mode::before { content: "\\2605"; margin-right: 0.45em; }
127
- .eh-modal-highlight .eh-modal-line { color: var(--fg); line-height: 1.45; }
126
+ .eh-modal-highlight, .eh-modal-tip { --bar: var(--bar-runtime, var(--runtime, var(--focus))); background: linear-gradient(color-mix(in srgb, var(--bar) 9%, transparent), transparent 5em), var(--surface-pane-b, var(--panel)); box-shadow: inset 5px 0 0 var(--bar), 0 16px 48px color-mix(in srgb, var(--shadow) 80%, transparent); }
127
+ .eh-modal-highlight .eh-modal-mode, .eh-modal-tip .eh-modal-mode { text-transform: uppercase; letter-spacing: 0.08em; }
128
+ .eh-modal-highlight .eh-modal-mode::before, .eh-modal-tip .eh-modal-mode::before { content: "\\2605"; margin-right: 0.45em; }
129
+ .eh-modal-highlight .eh-modal-line, .eh-modal-tip .eh-modal-line { color: var(--fg); line-height: 1.45; }
128
130
  .eh-modal-close { position: absolute; top: 0.4em; right: 0.5em; font-size: 1.3em; background: transparent; border: 0; color: var(--muted); cursor: pointer; }
129
131
  .eh-modal-mode { margin: 0 2em 0.3em 0; font: 600 0.8em var(--font-ui); font-variant-numeric: tabular-nums; color: var(--bar, var(--muted)); }
130
132
  .eh-modal-title { margin: 0 0 0.5em; font-size: 1.35em; }
@@ -260,18 +262,20 @@ export function openEventModal(host, { mode, kind, data = {}, actions = {}, doc
260
262
  if (st.closeAt !== null) st.closeAt = Math.max(st.closeAt, now() + 2_000);
261
263
  });
262
264
 
265
+ // One close button for the modal's whole life, never detached: render() runs every 250 ms, and taking the button out of
266
+ // the page (or replacing it) between a press and its release (a click lasts 80-150 ms) drops the click, so it never closed.
267
+ const x = el("button", "eh-modal-close", "×");
268
+ x.type = "button";
269
+ x.setAttribute("aria-label", "Close");
270
+ x.addEventListener("click", () => close("viewer"));
271
+ box.appendChild(x);
263
272
  const render = () => {
264
273
  if (st.closed) return;
265
274
  const t = now();
266
- box.replaceChildren();
267
- const x = el("button", "eh-modal-close", "×");
268
- x.type = "button";
269
- x.setAttribute("aria-label", "Close");
270
- x.addEventListener("click", () => close("viewer"));
271
- box.appendChild(x);
275
+ for (const c of [...box.children]) if (c !== x) c.remove();
272
276
  const line = modeLine(mode, kind, { at: data.at, now: t, resolved: st.resolved, outcome: st.outcome, replayAt: data.replayAt, action: data.action, fix: !!data.fix });
273
277
  if (line) box.appendChild(el("p", `eh-modal-mode eh-modal-${mode}`, line));
274
- box.appendChild(el("h2", "eh-modal-title", data.title || ""));
278
+ if (data.title || kind !== "tip") box.appendChild(el("h2", "eh-modal-title", data.title || ""));
275
279
  for (const l of data.lines || []) {
276
280
  const p = el("p", `eh-modal-line${l.lit ? " eh-lit" : ""}`, l.text);
277
281
  if (l.title) p.title = l.title;
@@ -288,7 +292,7 @@ export function openEventModal(host, { mode, kind, data = {}, actions = {}, doc
288
292
  if (data.progress.words) box.appendChild(el("p", "eh-modal-note", data.progress.words));
289
293
  }
290
294
  // behold#757: a highlight is words to read: no command, no button.
291
- if (kind === "waiting" || kind === "highlight") return;
295
+ if (kind === "waiting" || kind === "highlight" || kind === "tip") return;
292
296
  const routed = mode === "live" && approveRoute(data.gate);
293
297
  // The panel, when there is one, already carries the command.
294
298
  if (data.command && !routed && !(data.panel && mode !== "live")) {
@@ -417,6 +421,8 @@ export function openEventModal(host, { mode, kind, data = {}, actions = {}, doc
417
421
  render();
418
422
  },
419
423
  close: () => close(),
424
+ /** The viewer closed it (a click outside, say): onClose sees `closedBy` "viewer". */
425
+ dismiss: () => close("viewer"),
420
426
  };
421
427
  return api;
422
428
  }