@intentius/behold 0.29.43 → 0.29.44

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 (65) hide show
  1. package/AGENTS.md +77 -0
  2. package/dist/cli.js +3969 -1918
  3. package/package.json +1 -1
  4. package/web/app.js +1452 -73
  5. package/web/carve-narration.js +33 -1
  6. package/web/chant-live-pace.js +138 -0
  7. package/web/chant-live-pace.test.js +116 -0
  8. package/web/chant-pr-marks.js +417 -39
  9. package/web/chant-pr-marks.test.js +208 -4
  10. package/web/collision-marks.js +124 -0
  11. package/web/collision-marks.test.js +89 -0
  12. package/web/cone.js +269 -0
  13. package/web/cone.test.js +213 -0
  14. package/web/dots-live.test.js +151 -1
  15. package/web/dots-lod.js +20 -0
  16. package/web/dots-lod.test.js +19 -1
  17. package/web/dots-scene.js +110 -10
  18. package/web/dots.js +144 -31
  19. package/web/embed.js +1 -1
  20. package/web/event-help-modal.js +85 -3
  21. package/web/event-help-modal.test.js +85 -1
  22. package/web/feature-flags.js +143 -0
  23. package/web/feature-flags.test.js +96 -0
  24. package/web/index.html +33 -0
  25. package/web/kiosk-carve.js +59 -6
  26. package/web/kiosk-event-help-ui.js +150 -19
  27. package/web/kiosk-event-help.js +102 -15
  28. package/web/kiosk-event-help.test.js +58 -1
  29. package/web/kiosk-metrics.js +4 -3
  30. package/web/kiosk-runs.js +8 -5
  31. package/web/kiosk-shot.js +157 -3
  32. package/web/kiosk-shot.test.js +223 -1
  33. package/web/kiosk-source.js +43 -0
  34. package/web/kiosk-source.test.js +39 -0
  35. package/web/kiosk-story-gate.test.js +44 -0
  36. package/web/kiosk-track.js +312 -0
  37. package/web/kiosk-track.test.js +148 -0
  38. package/web/kiosk-unknown-step.test.js +58 -0
  39. package/web/kiosk-vendor.js +71 -4
  40. package/web/kiosk-vendor.test.js +103 -3
  41. package/web/kiosk-watch.js +154 -1
  42. package/web/kiosk-watch.test.js +53 -1
  43. package/web/kiosk.html +57 -22
  44. package/web/kiosk.js +566 -53
  45. package/web/kiosk.test.js +2 -1
  46. package/web/small-stage.test.js +150 -0
  47. package/web/terragucci-blocked.test.js +192 -0
  48. package/web/terragucci-change.js +197 -17
  49. package/web/terragucci-components-live.js +189 -13
  50. package/web/terragucci-live-pace.js +92 -0
  51. package/web/terragucci-wave-results.test.js +125 -0
  52. package/web/terralith.html +7 -7
  53. package/web/tg-outside.js +124 -0
  54. package/web/tg-outside.test.js +100 -0
  55. package/web/tg-read-pills.js +122 -0
  56. package/web/tg-read-pills.test.js +117 -0
  57. package/web/theme.js +13 -1
  58. package/web/theme.test.js +21 -1
  59. package/web/tooltip.js +19 -7
  60. package/web/tooltip.test.js +15 -0
  61. package/web/tours/terralith.json +4 -4
  62. package/web/trunk-lane.test.js +1 -1
  63. package/web/view-url.js +8 -2
  64. package/web/why.js +129 -1
  65. package/web/why.test.js +113 -1
package/web/app.js CHANGED
@@ -21,14 +21,18 @@ import { renderLane } from "./terragucci-lifecycle.js";
21
21
  import { renderReleases } from "./releases.js";
22
22
  import { renderTrunkLane } from "./trunk-lane.js";
23
23
  import { entriesFor as csEntriesFor, gapLines as csGapLines, inspectHeading as csInspectHeading, nodeMarks as csNodeMarks, offGraph as csOffGraph, overlayHeader as csHeader, overlayLegend as csLegend, PREVIEW_NOTE as CS_PREVIEW_NOTE } from "./change-set-overlay.js";
24
+ import { collisionFilter as coFilter, collisionHeader as coHeader, collisionMarks as coMarks, collisionsFor as coFor, COLLISION_NOTE as CO_NOTE, FILES_NOTE as CO_FILES_NOTE, FILTER_OFF as CO_FILTER_OFF, FILTER_ON as CO_FILTER_ON, gapLines as coGapLines, hideEdge as coHideEdge, itemRow as coItemRow, nodeRow as coNodeRow, sideLines as coSideLines } from "./collision-marks.js";
25
+ import { flagMarks as flFlagMarks, flagRow as flFlagRow, flagsFor as flFlagsFor, flagsHeader as flHeader, gapLines as flGapLines, NODES_NOTE as FL_NODES_NOTE, pickEnv as flPickEnv, STALE_COLOR as FL_STALE_COLOR, TURN_ON_NOTE as FL_TURN_ON_NOTE } from "./feature-flags.js";
24
26
  import { renderYodelLane } from "./sql-yodeler-lane.js";
25
27
  import { initTerragucciEstate } from "./terragucci-estate.js";
26
28
  import { chantComponentMarks } from "./chant-pr-marks.js";
29
+ import { createLivePacer } from "./chant-live-pace.js";
30
+ import { createProgressPacer } from "./terragucci-live-pace.js";
27
31
  import { noStateFill } from "./frame-fill.js";
28
32
  import { componentMarks as tgComponentMarks, runsCommit as tgRunsCommit, statusShort as tgStatusShort, waveOfKey as tgWaveOfKey } from "./terragucci-components-live.js";
29
33
  import { FORGES, MARK, componentsForge, forgeOfName, iconSvg, markLink, markTitle, waveJobUrl } from "./forge-mark.js";
30
34
  import { TOOLS, orderTools } from "./tool-mark.js";
31
- import { STATE_WORDS as tgStateWords, changeSection as tgChangeSection, readCardIds as tgReadCardIds, readEdges as tgReadEdges, readLabel as tgReadLabel, readLine as tgReadLine, readTag as tgReadTag, rootStates as tgRootStates, viewCaption as tgViewCaption, pinnedAnswer as tgPinnedAnswer, pinnedCaption as tgPinnedCaption, pinsCommit as tgPinsCommit } from "./terragucci-change.js";
35
+ import { STATE_WORDS as tgStateWords, changeSection as tgChangeSection, readCardIds as tgReadCardIds, readEdges as tgReadEdges, readLabel as tgReadLabel, readLine as tgReadLine, readTag as tgReadTag, rootStates as tgRootStates, viewCaption as tgViewCaption, pinnedAnswer as tgPinnedAnswer, pinnedCaption as tgPinnedCaption, pinsCommit as tgPinsCommit, pinWaits as tgPinWaits } from "./terragucci-change.js";
32
36
  import { auditLines as yrAuditLines, cornerText as yrCorner, datedWords as yrDated, environmentLines as yrEnvLines, joinMarks as yrJoin, legend as yrLegend, markLine as yrMarkLine } from "./yodel-report.js";
33
37
  import { cardProgress as tgCardProgress, progressLines as tgProgressLines, progressSection as tgProgressSection, stampProgress as tgStampProgress } from "./terragucci-progress.js";
34
38
  import { seconds, whyQuery, whyView } from "./why.js";
@@ -116,14 +120,18 @@ import { danglingFor, danglingRows, danglingHeading, DANGLING_EXPLAINED } from "
116
120
  import { comparisonRow, comparisonSummary } from "./cross-env.js";
117
121
  // The marker-vs-derived mark on a choudoufu card: how its identity was found.
118
122
  import { identityMark, tagGlyphSvg } from "./identity-mark.js";
119
- import { shotFromMessage, shotViewBox, tweenViewBox, unionBox, sameViewBox } from "./kiosk-shot.js"; // behold#571: Watch's camera
123
+ import { shotFromMessage, shotViewBox, tweenViewBox, unionBox, sameViewBox, heldFrame, heldInsets, heldTarget, holdsStage, medianWidth, smallStage } from "./kiosk-shot.js"; // behold#571: Watch's camera
120
124
  // #712, #715: the dots layer, the zoom past the cards. Mounted for a live
121
125
  // carve when the estate has choudoufu roots or estate rosters
122
126
  // (/api/terragucci/carve, liveCarveGate below), or when /api/graph's meta
123
127
  // carries `dots` (the local preview server, scripts/dots-preview.ts). With
124
128
  // neither it stays unmounted, and its hooks below are no-ops.
125
- import { mountDots, unmountDots, dotsCamera, dotsZoomOutFactor, dotsCarving, dotsMinViewWidth } from "./dots.js";
129
+ import { mountDots, unmountDots, dotsCamera, dotsZoomOutFactor, dotsCarving, dotsMinViewWidth, setDotsCone } from "./dots.js";
130
+ // Report minor 34: a cone plan's lights, on the cards and the dots (web/cone.js).
131
+ import { cardRoot as coneCardRoot, coneLights, coneOf, resourceLight as coneResourceLight, rootLight as coneRootLight, wrapWords } from "./cone.js";
126
132
  import { carveDrawable } from "./dots-live.js";
133
+ import { FLASH_MS as TG_FLASH_MS, createReadFlash, hotReads as tgHotReads, nearestOn as tgNearestOn, pillSpots as tgPillSpots, readKey as tgReadKey, readerStates as tgReaderStates } from "./tg-read-pills.js"; // behold#744
134
+ import { outsideCard as tgOutsideCard, outsideModel as tgOutsideModel, outsideSpots as tgOutsideSpots } from "./tg-outside.js"; // behold#743
127
135
  initTheme();
128
136
  // #476: framed in a host pane. The flag is a class on <html>, so the CSS that
129
137
  // folds the chrome away needs no JS, and the theme is the host's for this
@@ -694,7 +702,7 @@ function renderWhySection(panel, ask) {
694
702
  box.replaceChildren();
695
703
  const p = document.createElement("p");
696
704
  p.className = "queried";
697
- p.textContent = note || `The decisions that cover ${ask.node ? "this card" : `member ${memberName}`}, and the runs and commits behind it, from chant workspace graph --intent. Reading walks the repository's history; on a large one it takes a while.`;
705
+ p.textContent = note || `The decisions that cover ${ask.node ? "this card" : `member ${memberName}`}, the runs and commits behind it, and the chain from each commit's work item to its release, from chant workspace graph --intent. Reading walks the repository's history; on a large one it takes a while.`;
698
706
  box.append(p, button("Read why", "Ask chant now. Nothing is read until you click.", read));
699
707
  };
700
708
  const read = async () => {
@@ -795,6 +803,7 @@ function paintWhy(box, answer, again) {
795
803
  return li(lead, c.subject, c.meta);
796
804
  });
797
805
  for (const g of v.gaps) para(g, "why-gap");
806
+ if (v.chain) paintChain(box, v.chain, para);
798
807
  }
799
808
  if (v.footer) para(v.footer, "queried");
800
809
  const b = document.createElement("button");
@@ -806,6 +815,61 @@ function paintWhy(box, answer, again) {
806
815
  box.appendChild(b);
807
816
  }
808
817
 
818
+ /**
819
+ * #682: the chain under the why, one entry per commit chant walked, each link
820
+ * a row: what it is, chant's words for it, and the git line that opens its
821
+ * source record with a copy button. A missing link is drawn as missing, in
822
+ * the pending colour, with chant's reason.
823
+ */
824
+ function paintChain(box, chain, para) {
825
+ const t = document.createElement("div");
826
+ t.className = "why-head";
827
+ t.textContent = `chain, from work item to release${chain.more ? ` · ${chain.commits.length} of ${chain.commits.length + chain.more} commits` : ""}`;
828
+ box.appendChild(t);
829
+ for (const r of chain.reasons) para(r, "why-gap");
830
+ if (chain.note) {
831
+ para(chain.note, "why-gap");
832
+ return;
833
+ }
834
+ const ul = document.createElement("ul");
835
+ ul.className = "why-list why-chain";
836
+ for (const c of chain.commits) {
837
+ const li = document.createElement("li");
838
+ const top = document.createElement("div");
839
+ const sha = document.createElement("code");
840
+ sha.textContent = c.sha;
841
+ top.append(sha, c.subject ? ` ${c.subject}` : "");
842
+ li.appendChild(top);
843
+ for (const row of c.rows) {
844
+ const el = document.createElement("div");
845
+ el.className = row.missing ? "why-link why-missing" : "why-link";
846
+ const label = document.createElement("span");
847
+ label.className = "why-meta";
848
+ label.textContent = `${row.label} `;
849
+ el.append(label, row.text);
850
+ if (row.meta) {
851
+ const m = document.createElement("div");
852
+ m.className = "why-meta";
853
+ m.textContent = row.meta;
854
+ el.appendChild(m);
855
+ }
856
+ if (row.source) {
857
+ const src = document.createElement("div");
858
+ src.className = "why-source";
859
+ const line = document.createElement("code");
860
+ line.textContent = row.source.open;
861
+ line.title = row.source.title;
862
+ const copy = actButton("copy", () => copyToClipboard(row.source.open, copy), `Copy the line that opens this link's source record:\n${row.source.open}`);
863
+ src.append(line, copy);
864
+ el.appendChild(src);
865
+ }
866
+ li.appendChild(el);
867
+ }
868
+ ul.appendChild(li);
869
+ }
870
+ box.appendChild(ul);
871
+ }
872
+
809
873
  /** A member's box was picked: what the declaration says of it, and its why. */
810
874
  function inspectMember(name) {
811
875
  const m = declaredMember(name);
@@ -969,6 +1033,32 @@ function inspect(node) {
969
1033
  panel.appendChild(h);
970
1034
  for (const e of csEntries) panel.appendChild(csEntryEl(e));
971
1035
  }
1036
+ // #683: the feature flags of this card's member, in the environment the Flags tab draws.
1037
+ const flRows = flAnswer && flOn ? flFlagsFor(flAnswer, nodeMember(node.id), flEnv) : [];
1038
+ if (flRows.length) {
1039
+ const h = document.createElement("h3");
1040
+ h.textContent = "feature flags";
1041
+ h.title = FL_NODES_NOTE;
1042
+ panel.appendChild(h);
1043
+ for (const r of flRows) {
1044
+ const row = panelDotRow(r.color, r.text, "");
1045
+ row.title = r.title;
1046
+ panel.appendChild(row);
1047
+ }
1048
+ }
1049
+ // #684: the in-flight work items colliding on this card.
1050
+ const coRows = coAnswer && coOn ? coFor(coAnswer, node.id) : [];
1051
+ if (coRows.length) {
1052
+ const h = document.createElement("h3");
1053
+ h.textContent = "colliding work";
1054
+ h.title = CO_NOTE;
1055
+ panel.appendChild(h);
1056
+ for (const r of coRows) {
1057
+ const row = panelDotRow(r.color, r.text, "");
1058
+ row.title = r.title;
1059
+ panel.appendChild(row);
1060
+ }
1061
+ }
972
1062
  // #526: SQL Yodeler's drift on this card, each dated by its file.
973
1063
  const yrMarks = yrJoined && yrJoined.cards[node.id];
974
1064
  if (yrMarks && yrMarks.length) {
@@ -2539,6 +2629,7 @@ function applyWantedView(want) {
2539
2629
  if ("gates" in apply) view.gates = apply.gates;
2540
2630
  if ("focus" in apply) view.focus = apply.focus; // #569: drawn by drawTgReads, no new read
2541
2631
  if ("run" in apply) view.run = apply.run; // #569: which run the view draws; read in the message handler
2632
+ if ("pull" in apply) view.pull = apply.pull; // the cycle's pull request: a commit's run never draws another's plan
2542
2633
  if (want.member === null) {
2543
2634
  view.member = null;
2544
2635
  selectedNodeId = null;
@@ -2564,10 +2655,14 @@ window.addEventListener("message", (e) => {
2564
2655
  const gatesBefore = view.gates;
2565
2656
  const focusBefore = view.focus;
2566
2657
  const runBefore = view.run;
2658
+ const pullBefore = view.pull;
2567
2659
  const moved = applyWantedView(want);
2568
- if (view.run !== runBefore) {
2569
- void loadTgProgress({ fresh: true }); // #569: the run the narration is about
2660
+ if (view.run !== runBefore || view.pull !== pullBefore) {
2661
+ if (tgServed) void loadTgProgress({ fresh: true }); // #569: the run the narration is about
2570
2662
  if (chantFacets) void loadChantPr(); // behold#631
2663
+ // The reports too, read fresh now, and again every few seconds while the pin's plan or run isn't written yet:
2664
+ // the reports a frame read a step ago don't hold this cycle's pull request.
2665
+ if (tgAnswer && embedOpts.bare) void refreshTgAnswer();
2571
2666
  }
2572
2667
  else if (view.focus !== focusBefore && !moved) drawTgReads(); // #569
2573
2668
  // #477: the host's env for the gate strip moved. Read it now, not on the
@@ -3458,10 +3553,13 @@ let tgAnswer = null;
3458
3553
  let tgHost = null;
3459
3554
  let tgTimeline = null; // #506: /api/terragucci/timeline, the audit record's lane
3460
3555
  let tgHistory = null; // #522: /api/lifecycle/history, the gate ledgers' history
3556
+ /** behold#752: whether serve reads terragucci's reports; without them a pin's run view is never asked (chant's demo has none). */
3557
+ let tgServed = false;
3461
3558
  async function initTerragucci() {
3462
3559
  const project = await apiFetch("/api/project").then((r) => r.json()).catch(() => ({}));
3463
3560
  kioskRoots = project.terragucciRoots || null; // behold#571
3464
3561
  if (!project.terragucciReports) return;
3562
+ tgServed = true;
3465
3563
  // #715: the live carve's gate, asked beside the reports; closed, nothing below changes.
3466
3564
  if (!staticMode) void liveCarveGate();
3467
3565
  await loadTerragucci();
@@ -3507,6 +3605,8 @@ function mountLiveCarve(g, svgEl) {
3507
3605
  vbInit: vbInit.slice(),
3508
3606
  getVB: () => vb,
3509
3607
  setVB: (a) => {
3608
+ // A held small stage in Watch keeps its one framing: only the carve's director moves the camera then.
3609
+ if (kioskHeld && kioskShot && !dotsCarving()) return;
3510
3610
  vb = a.slice();
3511
3611
  vbAtFit = false;
3512
3612
  applyVB();
@@ -3575,6 +3675,38 @@ async function loadTerragucci({ fresh = false } = {}) {
3575
3675
  renderTerragucciPanel();
3576
3676
  markTerragucciCards();
3577
3677
  if (!staticMode) await loadTgProgress({ fresh });
3678
+ tgRefreshSoon();
3679
+ }
3680
+ /**
3681
+ * The kiosk's frame is pinned to one step's run (#569) and swapped for the next step's, so it reads again soon while
3682
+ * what its pin names isn't written yet: the pull request's plan (the plan job is still running), or the merge's run
3683
+ * view (the waves have not started). The plan then lights from planned on, and the waves' own states take over as
3684
+ * soon as their run view is there, without waiting for the reports poll.
3685
+ */
3686
+ var tgSoon = null;
3687
+ var TG_SOON_MS = 5_000;
3688
+ /** The reports alone, read fresh and drawn at once: the timeline and the gate ledgers' history (slow reads) wait for the next full read. */
3689
+ async function refreshTgAnswer() {
3690
+ const answer = await apiFetch("/api/terragucci?fresh=1")
3691
+ .then((r) => r.json())
3692
+ .catch((e) => ({ error: String(e), code: "terragucci-report", remedy: "" }));
3693
+ if (!answer.error || !tgAnswer) tgAnswer = answer;
3694
+ renderTerragucciPanel();
3695
+ markTerragucciCards();
3696
+ drawTgReads();
3697
+ tgRefreshSoon();
3698
+ }
3699
+ function tgRefreshSoon() {
3700
+ if (!embedOpts.bare || staticMode || tgSoon) return;
3701
+ const waits = tgPinWaits(tgAnswer, tgProgress, view.run, view.pull || null);
3702
+ if (!waits.plan && !waits.run) return;
3703
+ tgSoon = setTimeout(() => {
3704
+ tgSoon = null;
3705
+ // Asked again now: the pin may have moved while the timer ran.
3706
+ const now = tgPinWaits(tgAnswer, tgProgress, view.run, view.pull || null);
3707
+ if (now.plan) void refreshTgAnswer();
3708
+ else if (now.run) void loadTgProgress({ fresh: true }).then(tgRefreshSoon);
3709
+ }, TG_SOON_MS);
3578
3710
  }
3579
3711
  // #511: /api/terragucci/progress, the newest apply's run view on the cards.
3580
3712
  let tgProgress = null;
@@ -3606,7 +3738,7 @@ function tgPushFits(answer) {
3606
3738
  }
3607
3739
  /** #569: the reports as the view draws them: at `run=base` no pull request, at `run=pull-<n>` only that one's plan. */
3608
3740
  function tgAnswerDrawn() {
3609
- return tgPinnedAnswer(tgAnswer, view.run);
3741
+ return tgPinnedAnswer(tgAnswer, view.run, view.pull || null);
3610
3742
  }
3611
3743
  function paintTgProgress() {
3612
3744
  tgStampProgress(document.querySelector("#graph svg"), tgProgress, new Date());
@@ -3636,6 +3768,7 @@ function drawTgReads() {
3636
3768
  if (!svg) return;
3637
3769
  drawPipelineMarks(svg); // behold#571: the forge and tool marks, before the wave boxes' status finds room around them
3638
3770
  for (const old of svg.querySelectorAll("[data-tg-reads]")) old.remove();
3771
+ tgReadEdgesNow = []; // behold#744
3639
3772
  for (const old of svg.querySelectorAll("[data-tg-root]")) old.remove();
3640
3773
  for (const r of svg.querySelectorAll("rect[data-tg-stroke0]")) {
3641
3774
  r.setAttribute("stroke", r.getAttribute("data-tg-stroke0"));
@@ -3643,6 +3776,11 @@ function drawTgReads() {
3643
3776
  r.removeAttribute("data-tg-stroke0");
3644
3777
  r.removeAttribute("data-tg-width0");
3645
3778
  }
3779
+ // A card grown to hold a cone's lines goes back to its own height (drawTgComponentMarks).
3780
+ for (const r of svg.querySelectorAll("rect[data-tg-h0]")) {
3781
+ r.setAttribute("height", r.getAttribute("data-tg-h0"));
3782
+ r.removeAttribute("data-tg-h0");
3783
+ }
3646
3784
  for (const r of svg.querySelectorAll("[data-tg-fill0]")) {
3647
3785
  r.setAttribute("fill", r.getAttribute("data-tg-fill0"));
3648
3786
  r.removeAttribute("data-tg-fill0");
@@ -3657,6 +3795,8 @@ function drawTgReads() {
3657
3795
  }
3658
3796
  // behold#631: a chant repo's pull-request loop marks its components from chant's records, not terragucci's reports.
3659
3797
  const chantMode = chantPrDrawn();
3798
+ // Report minor 34: last draw's cone lights go; drawConeLights sets this draw's.
3799
+ if (chantMode || !tgAnswer || tgAnswer.error || !tgAnswer.roots) drawConeLights(svg, { stage: null });
3660
3800
  if (!chantMode && (!tgAnswer || tgAnswer.error || !tgAnswer.roots)) return;
3661
3801
  const toSvg = svg.getScreenCTM && svg.getScreenCTM();
3662
3802
  if (!toSvg) return;
@@ -3710,14 +3850,25 @@ function drawTgReads() {
3710
3850
  return n;
3711
3851
  };
3712
3852
  if (chantMode) {
3713
- drawTgComponentMarks(svg, { marks: chantComponentMarks(chantPrAnswer, chantFacets), focus: null, boxOf, make, edgePoints: chantEdgePoints(svg) });
3853
+ // behold#631: a kiosk passer-by can't place a card's type glyph (it reads as a checkbox): a chant repo's kiosk hides it.
3854
+ if (embedOpts.bare) kioskCardGlyphs(svg);
3855
+ const chantMarks = chantComponentMarks(chantPaced(), chantFacets, { kiosk: !!embedOpts.bare });
3856
+ if (embedOpts.bare) chantKioskWaves(svg, boxOf, chantMarks.waveFont || 18);
3857
+ drawTgComponentMarks(svg, { marks: chantMarks, focus: null, boxOf, make, edgePoints: chantEdgePoints(svg) });
3858
+ drawReach(svg, chantMarks.reach || null, boxOf, chantMarks.waveFont || 18);
3859
+ tipComponentEdges(svg); // behold#744
3714
3860
  return;
3715
3861
  }
3716
3862
  const layer = make("g", { "data-tg-reads": "1", "pointer-events": "none" });
3717
3863
  svg.appendChild(layer); // over the boxes and cards: the lines end at the borders, and the labels carry a background
3864
+ // behold#744: the read lines' pointer targets, under the cards (a line crossing a card leaves the card its pointer) and over the edges.
3865
+ const hits = make("g", { "data-tg-reads": "hits" });
3866
+ let under = svg.querySelector("[data-node-id]");
3867
+ while (under && under.parentNode !== svg) under = under.parentNode;
3868
+ svg.insertBefore(hits, under || layer);
3718
3869
  // A pill of text with a background, centred on (cx, cy); measured once it is in the svg.
3719
- const pill = (parent, cx, cy, text, { stroke, fill = "var(--panel)", color = "var(--fg)", size = 13, weight = 600, anchor = "middle", cls = "" } = {}) => {
3720
- const g = make("g", cls ? { class: cls } : {});
3870
+ const pill = (parent, cx, cy, text, { stroke, fill = "var(--panel)", color = "var(--fg)", size = 13, weight = 600, anchor = "middle", cls = "", attrs = {} } = {}) => {
3871
+ const g = make("g", { ...(cls ? { class: cls } : {}), ...attrs }); // behold#744: a read's pill is hidden from its first style, never faded out
3721
3872
  const rect = make("rect", { rx: 6, fill, stroke: stroke || "var(--rule)", "stroke-width": 1.5 });
3722
3873
  const t = make("text", { x: cx, y: cy, "text-anchor": anchor, "dominant-baseline": "central", "font-size": size, "font-weight": weight, fill: color }, text);
3723
3874
  g.append(rect, t);
@@ -3825,11 +3976,26 @@ function drawTgReads() {
3825
3976
  }
3826
3977
  }
3827
3978
 
3979
+ // Report minor 34: a cone plan lights what it planned and dims the rest, never hiding it (web/cone.js).
3980
+ drawConeLights(svg, { stage: states.stage, drawnAnswer, compMode, componentsOfRoot, rootOf });
3981
+
3828
3982
  // #571: the components zoom's own marks; its wave boxes are the boxes the caption and the labels keep clear of.
3829
3983
  const edgePoints = compMode ? chantEdgePoints(svg) : [];
3984
+ let readMarks = null; // behold#744: the cards' and waves' states (a story's paced) that a read's pill flashes on
3830
3985
  if (compMode) {
3831
3986
  boxes.length = 0;
3832
- boxes.push(...drawTgComponentMarks(svg, { drawnAnswer, focus, boxOf, make, edgePoints }));
3987
+ // behold#741: a kiosk telling a chapter-carrying scenario looks as chant's loop does: no type glyph, the waves
3988
+ // read bottom to top, the bigger words, and the reach wedge. Without a chapter, today's marks alone.
3989
+ const story = tgStoryMarks();
3990
+ if (story) kioskCardGlyphs(svg);
3991
+ const marks = story ? tgComponentMarks(drawnAnswer, tgPacedProgress(), tgComponentFacets, { runs: tgRuns, pin: view.run || null, story }) : null;
3992
+ if (marks) {
3993
+ readMarks = marks;
3994
+ tgStoryRemember(marks);
3995
+ chantKioskWaves(svg, boxOf, marks.waveFont || 18);
3996
+ }
3997
+ boxes.push(...drawTgComponentMarks(svg, { drawnAnswer, focus, boxOf, make, edgePoints, ...(marks ? { marks } : {}) }));
3998
+ if (marks) drawReach(svg, marks.reach || null, boxOf, marks.waveFont || 18, marks.needs || {});
3833
3999
  }
3834
4000
 
3835
4001
  // The reads. #569 review: no line or label crosses text. Each line is the
@@ -3838,6 +4004,7 @@ function drawTgReads() {
3838
4004
  // there are; each label then sits beside its line where it covers no text
3839
4005
  // and crosses no line.
3840
4006
  const edges = tgReadEdges(drawnAnswer, tgProgress);
4007
+ if (compMode) tipComponentEdges(svg, edges); // behold#744
3841
4008
  const centre = (b) => ({ x: (b.x + b.x2) / 2, y: (b.y + b.y2) / 2 });
3842
4009
  const grow = (b, d) => ({ x: b.x - d, y: b.y - d, x2: b.x2 + d, y2: b.y2 + d });
3843
4010
  // Whether the segment p-q passes through the box (Liang-Barsky).
@@ -3943,70 +4110,88 @@ function drawTgReads() {
3943
4110
  }
3944
4111
  if (!best) continue;
3945
4112
  const { p0, p1 } = best;
3946
- const line = make("line", { x1: p0.x, y1: p0.y, x2: p1.x, y2: p1.y, stroke: color, "stroke-width": 3, "stroke-dasharray": e.outputs === "planned" ? "9 6" : "none", "marker-end": `url(#tg-arrow-${kind})`, "data-tg-read-from": e.from, "data-tg-read-to": e.to });
3947
- line.appendChild(make("title", {}, tgReadLine(e)));
4113
+ const key = tgReadKey(e);
4114
+ const line = make("line", { x1: p0.x, y1: p0.y, x2: p1.x, y2: p1.y, stroke: color, "stroke-width": 3, "stroke-dasharray": e.outputs === "planned" ? "9 6" : "none", "marker-end": `url(#tg-arrow-${kind})`, "data-tg-read-from": e.from, "data-tg-read-to": e.to, "data-tg-read": key });
3948
4115
  if (focus && !(focus.has(e.from) || focus.has(e.to))) line.style.opacity = "0.5";
3949
4116
  layer.appendChild(line);
4117
+ // behold#744: a wide clear stroke along the line takes the pointer (the drawn layer lets it through): pointing at it shows the
4118
+ // read's pill; outside a kiosk frame the shared tooltip adds the whole sentence (data-tip, no <title>: no second, native one).
4119
+ hits.appendChild(make("line", { x1: p0.x, y1: p0.y, x2: p1.x, y2: p1.y, stroke: "transparent", "stroke-width": 16, "pointer-events": "stroke", "data-tg-read-hit": key, ...(embedOpts.bare ? {} : { "data-tip": tgReadLine(e) }) }));
3950
4120
  drawn.push({ p0, p1 });
3951
- labels.push({ e, p0, p1, color, kind });
4121
+ labels.push({ e, p0, p1, color, kind, key, fromBox });
3952
4122
  }
3953
4123
  // behold#571: the marks step aside from the read lines, and a box lifts its marks off an arrowhead (its box then reaches higher).
3954
4124
  for (const [rect] of clearMarksOfReads(svg, drawn)) {
3955
4125
  const now = boxOf(rect);
3956
4126
  for (const b of boxes) if (now && Math.abs(b.x - now.x) < 0.5 && Math.abs(b.x2 - now.x2) < 0.5 && Math.abs(b.y2 - now.y2) < 0.5) b.y = now.y;
3957
4127
  }
3958
- // Each read's words beside its line: covering no text, crossing no line,
3959
- // over as few cards and box headers as can be.
4128
+ // behold#744: each read's words in a pill at the reader's end of its line, beside the reader's card and joined to it by a
4129
+ // short leader in the line's colour: covering no text where it can, never out in open ground. Drawn hidden; the pointer
4130
+ // (on the reader, the root it reads or the line), a kiosk's flash or an Inspect focus shows it (tgReadShow).
3960
4131
  const cardBoxes = cardEls.map((g) => cardBoxOf.get(g)).filter(Boolean);
3961
4132
  const headers = boxes.map((b) => ({ x: b.x, y: b.y - 14, x2: b.x2, y2: b.y + 36 }));
3962
4133
  const placed = [];
4134
+ const pillsBy = []; // behold#743: each pill's rect and its reader, shown or not
3963
4135
  const overlap = (r, b) => Math.max(0, Math.min(r.x2, b.x2) - Math.max(r.x, b.x)) * Math.max(0, Math.min(r.y2, b.y2) - Math.max(r.y, b.y));
3964
4136
  const sum = (r, list, k) => list.reduce((a, b) => a + k * overlap(r, b), 0);
3965
- for (const l of labels) {
4137
+ const span = union(boxes);
4138
+ // A kiosk with no chapters flashes on the marks drawTgComponentMarks drew from the same reads (wave jobs' status included).
4139
+ if (embedOpts.bare && compMode && !readMarks) readMarks = tgComponentMarks(drawnAnswer, tgProgress, tgComponentFacets, { runs: tgRuns, pin: view.run || null });
4140
+ const flash = embedOpts.bare ? new Map(tgReadFlash.live(edges, tgReaderStates(readMarks, states.roots)).map((f) => [f.key, f.age])) : new Map();
4141
+ // The flashing pills first: they show together, so each keeps clear of the others; a hidden one only shows with its own root's.
4142
+ const lit = [];
4143
+ for (const l of [...labels].sort((a, b) => Number(flash.has(b.key)) - Number(flash.has(a.key)))) {
3966
4144
  const words = `${l.e.from} ${tgReadLabel(l.e)}`;
3967
- const size = 13;
3968
- const w = words.length * size * 0.56 + 16;
3969
- const h = size + 10;
3970
- const dx = l.p1.x - l.p0.x;
3971
- const dy = l.p1.y - l.p0.y;
3972
- let best = null;
3973
- // behold#571: the label's own line may run under it; every other read line may not.
4145
+ const size = embedOpts.bare ? 15 : 13; // a kiosk's card words are bigger too
4146
+ const p = pill(layer, 0, 0, words, { stroke: l.color, fill: "var(--bg)", color: "var(--fg)", size, weight: 600, attrs: { "data-tg-read-pill": "1", "data-tg-read": l.key } });
4147
+ const { w, h } = p;
4148
+ // The pill's own line may run under it; every other read line costs, though only a few pills show at once.
3974
4149
  const others = drawn.filter((d) => !(d.p0 === l.p0 && d.p1 === l.p1));
3975
- for (const t of [0.5, 0.35, 0.65, 0.2, 0.8, 0.1, 0.9]) {
3976
- const m = { x: l.p0.x + dx * t, y: l.p0.y + dy * t };
3977
- // On the line itself, slid along its width; then beside the line, then farther off it into open ground: the boxes sit close.
3978
- const spots = [-0.35, -0.2, 0, 0.2, 0.35].map((f) => ({ x: m.x + f * w, y: m.y, off: 1 + Math.abs(f) * 4 }));
3979
- for (let k = 0; k < 6; k++) {
3980
- const off = k * (h + 6);
3981
- spots.push(
3982
- { x: m.x + w / 2 + 12 + off, y: m.y, off },
3983
- { x: m.x - w / 2 - 12 - off, y: m.y, off },
3984
- { x: m.x, y: m.y - h / 2 - 10 - off, off },
3985
- { x: m.x, y: m.y + h / 2 + 10 + off, off },
3986
- );
3987
- }
3988
- for (const c of spots) {
3989
- const r = { x: c.x - w / 2, y: c.y - h / 2, x2: c.x + w / 2, y2: c.y + h / 2 };
3990
- const lineHits = others.filter((d) => crosses(d.p0, d.p1, r)).length;
3991
- // Outside the boxes' own span the label may leave the drawing when the view is fitted: keep it in.
3992
- // behold#571: never above the top box, where the caption says which run the marks are from.
3993
- const span = union(boxes);
3994
- const out = span ? (r.x2 - r.x) * (r.y2 - r.y) - overlap(r, { x: span.x - 40, y: span.y, x2: span.x2 + 40, y2: span.y2 + 40 }) : 0;
3995
- // behold#571: a card or a box's title row under the words costs as much as text does, so a label sits on open ground between boxes.
3996
- // A dependency line under a label costs less than a card or text does, and far less than another read's line.
3997
- const score = out * 80 + lineHits * 1e6 + edgeIn(r) * 30 + Math.hypot(c.x - m.x, c.y - m.y) * 2 + sum(r, textBoxes, 50) + sum(r, placed, 50) + sum(r, cardBoxes, 50) + sum(r, headers, 40) + sum(r, boxes, 0.15) + Math.abs(t - 0.5) * 300 + c.off * 4;
3998
- if (!best || score < best.score) best = { c, r, score };
3999
- }
4150
+ let best = null;
4151
+ // A kiosk frame's popover opens to the right of a pointed card (placePopover): the pill keeps out from under it.
4152
+ const fb = l.fromBox;
4153
+ const popRoom = embedOpts.bare ? [{ x: fb.x2, y: fb.y, x2: fb.x2 + 3 * (fb.x2 - fb.x), y2: fb.y + 3 * (fb.y2 - fb.y) }] : [];
4154
+ // A kiosk's camera (Watch's shot) frames part of the graph: a pill stays inside what it shows.
4155
+ const vb = embedOpts.bare && svg.viewBox && svg.viewBox.baseVal && svg.viewBox.baseVal.width ? svg.viewBox.baseVal : null;
4156
+ const seen = vb ? { x: vb.x + 8, y: vb.y + 8, x2: vb.x + vb.width - 8, y2: vb.y + vb.height - 8 } : null;
4157
+ for (const s of tgPillSpots(fb, l.p0, w, h)) {
4158
+ const r = s.r;
4159
+ const lineHits = others.filter((d) => crosses(d.p0, d.p1, r)).length;
4160
+ // Outside the boxes' own span the pill may leave the drawing when the view is fitted: keep it in, and never above the
4161
+ // top box, where the caption says which run the marks are from (behold#571).
4162
+ const out = span ? (r.x2 - r.x) * (r.y2 - r.y) - overlap(r, { x: span.x - 40, y: span.y, x2: span.x2 + 40, y2: span.y2 + 40 }) : 0;
4163
+ const unseen = seen ? (r.x2 - r.x) * (r.y2 - r.y) - overlap(r, seen) : 0;
4164
+ const score = out * 80 + unseen * 80 + lineHits * 2000 + edgeIn(r) * 30 + sum(r, textBoxes, 50) + sum(r, lit, 200) + sum(r, placed, 50) + sum(r, cardBoxes, 50) + sum(r, headers, 20) + sum(r, popRoom, 4) + s.far * 12 + s.gap * 3 + s.round * 150;
4165
+ if (!best || score < best.score) best = { s, score };
4166
+ }
4167
+ if (!best) {
4168
+ p.g.remove();
4169
+ continue;
4000
4170
  }
4001
- placed.push(best.r);
4002
- const p = pill(layer, best.c.x, best.c.y, words, { stroke: l.color, fill: "var(--bg)", color: "var(--fg)", size, weight: 600 });
4003
- if (focus && !(focus.has(l.e.from) || focus.has(l.e.to))) p.g.style.opacity = "0.5";
4171
+ const { c, r } = best.s;
4172
+ (flash.has(l.key) ? lit : placed).push(r);
4173
+ pillsBy.push({ from: l.e.from, r, lit: flash.has(l.key) });
4174
+ p.g.setAttribute("transform", `translate(${c.x} ${c.y})`);
4175
+ // The leader: from the line's start on the card's border to the pill's nearest edge, with a dot where it leaves the card.
4176
+ const q = tgNearestOn(r, l.p0);
4177
+ p.g.insertBefore(make("line", { x1: l.p0.x - c.x, y1: l.p0.y - c.y, x2: q.x - c.x, y2: q.y - c.y, stroke: l.color, "stroke-width": 2.5 }), p.g.firstChild);
4178
+ p.g.insertBefore(make("circle", { cx: l.p0.x - c.x, cy: l.p0.y - c.y, r: 4, fill: l.color }), p.g.firstChild);
4179
+ if (flash.has(l.key)) {
4180
+ // A kiosk's flash: TG_FLASH_MS from when its reader came into the state, so a redraw midway carries on where it was.
4181
+ p.g.classList.add("tg-flash");
4182
+ p.g.style.animationDuration = `${TG_FLASH_MS}ms`;
4183
+ p.g.style.animationDelay = `-${Math.round(flash.get(l.key))}ms`;
4184
+ }
4185
+ // Inspect's focus keeps the focused roots' reads in words, as every read was before.
4186
+ if (!embedOpts.bare && focus && (focus.has(l.e.from) || focus.has(l.e.to))) p.g.classList.add("tg-shown");
4004
4187
  }
4188
+ tgReadEdgesNow = edges;
4189
+ tgReadShow(svg);
4005
4190
 
4006
4191
  // Which run the marks come from, above the boxes.
4007
4192
  // #569: a pin that holds the view off every plan says why in its own words.
4008
- const shown = tgViewCaption(drawnAnswer, tgProgress, new Date());
4009
- const caption = tgPinnedCaption(tgAnswer, view.run) || (shown ? `Showing ${shown}` : null);
4193
+ const shown = tgViewCaption(drawnAnswer, tgProgress, new Date(), { merged: tgPinsCommit(view.run) });
4194
+ const caption = tgPinnedCaption(tgAnswer, view.run, view.pull || null, tgProgress) || (shown ? `Showing ${shown}` : null);
4010
4195
  const all = union(boxes);
4011
4196
  if (caption && all) {
4012
4197
  const line = make("text", { "data-tg-reads": "caption", x: all.x, y: all.y - 22, "font-size": 16, "font-weight": 600, fill: "var(--muted)" }, caption);
@@ -4025,9 +4210,311 @@ function drawTgReads() {
4025
4210
  layer.appendChild(make("text", { "data-tg-reads": "caption", x: all.x, y: all.y - 22, "font-size": 16, "font-weight": 600, fill: "var(--muted)" }, caption.slice(cut + 2)));
4026
4211
  }
4027
4212
  }
4213
+ // behold#743: an apply made outside the pipeline, on its estate's card, clear of the reads' pills and the caption.
4214
+ if (compMode && readMarks) {
4215
+ const captions = [...layer.querySelectorAll("text[data-tg-reads=caption]")].map(boxOf).filter(Boolean).map((b) => grow(b, 4));
4216
+ drawTgOutside(svg, { layer, make, boxOf, marks: readMarks, roots: states.roots, cardBoxOf, avoid: { pills: pillsBy, texts: textBoxes, captions, headers }, edgeIn, crosses });
4217
+ }
4218
+ }
4219
+
4220
+ /**
4221
+ * behold#743: demo.json's `outside` (an operator's apply to app-01's estate while the pipeline's wave 3 applies it),
4222
+ * drawn as a mark joined to the estate's card: dashed, tagged "outside the pipeline", with who ran it, the command, its
4223
+ * state and its resources, and what the pipeline does to the same estate meanwhile; once both land, both changes. Only
4224
+ * a kiosk frame telling a chapter-carrying story draws it, and only while the step carries one: other scenarios, and
4225
+ * steps without it, draw nothing new. The mark is a child of the reads' layer, so the kiosk's modals and callouts keep
4226
+ * clear of it as of the pills (kioskTellBoxes' `labels`).
4227
+ */
4228
+ function drawTgOutside(svg, { layer, make, boxOf, marks, roots, cardBoxOf, avoid, edgeIn, crosses }) {
4229
+ const outside = tgStoryOn() && tgStory.outside ? tgStory.outside : null;
4230
+ if (!outside || !marks || !marks.cards) return;
4231
+ const cards = marks.cards;
4232
+ const id = tgOutsideCard(outside.estate, [...Object.keys(cards), ...Object.values(cards).map((c) => c && c.root)]);
4233
+ const cid = id && (cards[id] ? id : Object.keys(cards).find((k) => cards[k] && cards[k].root === id));
4234
+ const el = cid ? svg.querySelector(`[data-node-id="${CSS.escape(cid)}"]`) : null;
4235
+ const cardBox = el ? cardBoxOf.get(el) || boxOf(el) : null;
4236
+ if (!cardBox) return;
4237
+ const m = cards[cid];
4238
+ // The pipeline's own state for the card, as the reads' flash reads it: a card whose wave's job runs now is applying.
4239
+ const pipeline = tgReaderStates(marks, roots)[m.root] || m.state;
4240
+ const plans = (m.facts || []).find((f) => /^plans /.test(f));
4241
+ const model = tgOutsideModel(outside, { pipeline, card: cid, change: plans ? plans.slice(6) : null, wave: Number.isInteger(m.wave) ? m.wave : null });
4242
+ if (!model) return;
4243
+ const tone = TG_TONE[model.tone] || TG_TONE.idle;
4244
+ const g = make("g", { "data-tg-outside": cid, "pointer-events": "none" });
4245
+ layer.appendChild(g);
4246
+ // The card's own ring, dashed in the mark's tone: the estate the outside apply is on.
4247
+ const ring = make("rect", { x: cardBox.x - 6, y: cardBox.y - 6, width: cardBox.x2 - cardBox.x + 12, height: cardBox.y2 - cardBox.y + 12, rx: 10, fill: "none", stroke: tone, "stroke-width": 2.5, "stroke-dasharray": "7 5" });
4248
+ g.appendChild(ring);
4249
+ // The words, measured where they are drawn; the box is sized to them.
4250
+ const size = embedOpts.bare ? 15 : 13;
4251
+ const mono = "ui-monospace, SFMono-Regular, Menlo, Consolas, monospace";
4252
+ const style = {
4253
+ who: { size, weight: 700, fill: tone },
4254
+ landed: { size, weight: 700, fill: tone },
4255
+ command: { size: size - 2, weight: 500, fill: "var(--fg)", family: mono },
4256
+ resources: { size: size - 1, weight: 600, fill: "var(--fg)", family: mono },
4257
+ pipeline: { size: size - 1, weight: 600, fill: "var(--muted)" },
4258
+ };
4259
+ const body = make("g", {});
4260
+ g.appendChild(body);
4261
+ const texts = model.lines.map((l) => {
4262
+ const s = style[l.kind] || style.pipeline;
4263
+ const t = make("text", { "font-size": s.size, "font-weight": s.weight, fill: s.fill, ...(s.family ? { "font-family": s.family } : {}) }, l.text);
4264
+ if (l.kind === "who" && model.pulse) t.setAttribute("class", "pin-pulse");
4265
+ body.appendChild(t);
4266
+ let w = l.text.length * s.size * 0.6;
4267
+ try {
4268
+ w = t.getComputedTextLength() || w;
4269
+ } catch {
4270
+ /* not laid out: the estimate stands */
4271
+ }
4272
+ return { t, w, s };
4273
+ });
4274
+ const tagSize = size - 3;
4275
+ const tag = make("text", { "font-size": tagSize, "font-weight": 800, fill: "var(--bg)", "letter-spacing": "0.04em" }, model.tag.toUpperCase());
4276
+ let tagW = model.tag.length * tagSize * 0.72;
4277
+ g.appendChild(tag);
4278
+ try {
4279
+ tagW = tag.getComputedTextLength() || tagW;
4280
+ } catch {
4281
+ /* not laid out */
4282
+ }
4283
+ const padX = 14;
4284
+ const lineGap = 7;
4285
+ const top = 18; // under the tag, which sits across the top border
4286
+ const w = Math.max(tagW + 24, ...texts.map((x) => x.w)) + 2 * padX;
4287
+ const h = top + texts.reduce((a, x) => a + x.s.size + lineGap, 0) + 6;
4288
+ // Where it goes: beside the card, clear of the other cards, the card's read pills (behold#744), the caption and the
4289
+ // text around, and inside what Watch's camera shows.
4290
+ const vbb = embedOpts.bare && svg.viewBox && svg.viewBox.baseVal && svg.viewBox.baseVal.width ? svg.viewBox.baseVal : null;
4291
+ const seen = vbb ? { x: vbb.x + 8, y: vbb.y + 8, x2: vbb.x + vbb.width - 8, y2: vbb.y + vbb.height - 8 } : null;
4292
+ const overlap = (r, b) => Math.max(0, Math.min(r.x2, b.x2) - Math.max(r.x, b.x)) * Math.max(0, Math.min(r.y2, b.y2) - Math.max(r.y, b.y));
4293
+ const sum = (r, list, k) => list.reduce((a, b) => a + k * overlap(r, b), 0);
4294
+ const others = [...cardBoxOf.values()].filter((b) => b && b !== cardBox);
4295
+ const ringBox = { x: cardBox.x - 8, y: cardBox.y - 8, x2: cardBox.x2 + 8, y2: cardBox.y2 + 8 };
4296
+ // The card's own read pills (behold#744) and the ones flashing now must stay clear; the others show only on a pointer.
4297
+ const ownPills = avoid.pills.filter((x) => x.lit || x.from === m.root || x.from === cid).map((x) => x.r);
4298
+ const restPills = avoid.pills.filter((x) => !(x.lit || x.from === m.root || x.from === cid)).map((x) => x.r);
4299
+ // The leader: from the box's nearest edge to the card's ring, which it meets with a dot.
4300
+ const inner = { x: ringBox.x + 2, y: ringBox.y + 2, x2: ringBox.x2 - 2, y2: ringBox.y2 - 2 };
4301
+ const leaderOf = (r) => {
4302
+ const q = tgNearestOn(r, { x: (cardBox.x + cardBox.x2) / 2, y: (cardBox.y + cardBox.y2) / 2 });
4303
+ return { p: tgNearestOn(inner, q), q };
4304
+ };
4305
+ let best = null;
4306
+ // Slid further along a side than a pill is: the mark is wide, and a caption may sit over the card's box.
4307
+ for (const s of tgOutsideSpots(ringBox, w, h + 12, { gaps: [12, 28, 48, 72, 100, 140, 180], slides: [0, -0.25, 0.25, -0.5, 0.5, 0.75, 1, 1.25, 1.5, 1.75, -0.75, -1, -1.25] })) {
4308
+ const r = { ...s.r, y: s.r.y + 12 }; // the tag reaches 12 above the box
4309
+ const hit = { ...r, y: r.y - 12 };
4310
+ const unseen = seen ? (hit.x2 - hit.x) * (hit.y2 - hit.y) - overlap(hit, seen) : 0;
4311
+ const { p, q } = leaderOf(r);
4312
+ const across = [...avoid.texts, ...avoid.captions, ...ownPills, ...others].filter((t) => crosses(p, q, t)).length;
4313
+ const score = sum(hit, [ringBox], 400) + sum(hit, others, 200) + sum(hit, ownPills, 300) + sum(hit, restPills, 10) + sum(hit, avoid.captions, 300) + sum(hit, avoid.texts, 60) + sum(hit, avoid.headers, 15) + unseen * 120 + edgeIn(hit) * 4 + across * 4000 + s.far * 6;
4314
+ if (!best || score < best.score) best = { r, score };
4315
+ }
4316
+ if (!best) return g.remove();
4317
+ const r = best.r;
4318
+ body.prepend(make("rect", { x: r.x, y: r.y, width: w, height: h, rx: 9, fill: "var(--bg)", stroke: tone, "stroke-width": 2.5, "stroke-dasharray": "9 5" }));
4319
+ // The tag across the top border, filled, so it reads as a label of the box and not as one of the pipeline's states.
4320
+ g.insertBefore(make("rect", { x: r.x + padX - 8, y: r.y - 12, width: tagW + 16, height: 24, rx: 12, fill: tone }), tag);
4321
+ tag.setAttribute("x", String(r.x + padX));
4322
+ tag.setAttribute("y", String(r.y));
4323
+ tag.setAttribute("dominant-baseline", "central");
4324
+ let y = r.y + top;
4325
+ for (const x of texts) {
4326
+ y += x.s.size;
4327
+ x.t.setAttribute("x", String(r.x + padX));
4328
+ x.t.setAttribute("y", String(y));
4329
+ y += lineGap;
4330
+ }
4331
+ const { p, q } = leaderOf(r);
4332
+ if (Math.hypot(q.x - p.x, q.y - p.y) > 3) {
4333
+ g.insertBefore(make("line", { x1: p.x, y1: p.y, x2: q.x, y2: q.y, stroke: tone, "stroke-width": 2.5, "stroke-dasharray": "6 4" }), body);
4334
+ g.insertBefore(make("circle", { cx: p.x, cy: p.y, r: 4.5, fill: tone }), body);
4335
+ }
4336
+ g.appendChild(make("title", {}, [`${model.tag}: ${outside.who} ran ${outside.command} on ${outside.estate}`, `${outside.state}${(outside.resources || []).length ? ` · ${outside.resources.join(", ")}` : ""}`, ...(outside.log || []).slice(-3)].join("\n") + "\n(from the demo's narration, demo.json)"));
4337
+ }
4338
+ /**
4339
+ * Report minor 34: while the view draws a pull request's plan that has a cone
4340
+ * view, each card of a root it names takes `data-cone`: `changed` and `lit`
4341
+ * (planned: outlined in the plan's colour), or `dim` (not planned: faded,
4342
+ * still drawn). A components card, one per root, lights as its root does.
4343
+ * The dots layer is told the same lights. Any other plan sets nothing.
4344
+ */
4345
+ function drawConeLights(svg, { stage, drawnAnswer, compMode, componentsOfRoot, rootOf }) {
4346
+ for (const g of svg.querySelectorAll("[data-cone]")) g.removeAttribute("data-cone");
4347
+ for (const g of svg.querySelectorAll("[data-cone-dim]")) {
4348
+ g.removeAttribute("data-cone-dim");
4349
+ g.style.opacity = g.getAttribute("data-tg-dim") ? "0.5" : "";
4350
+ }
4351
+ const lights = stage === "pull-request" ? coneLights(coneOf(drawnAnswer && drawnAnswer.pull_request)) : null;
4352
+ setDotsCone(lights);
4353
+ if (!lights) return;
4354
+ const outline = (g, width) => {
4355
+ const r = g.querySelector(":scope > rect");
4356
+ if (!r) return;
4357
+ if (!r.hasAttribute("data-tg-stroke0")) {
4358
+ r.setAttribute("data-tg-stroke0", r.getAttribute("stroke") || "");
4359
+ r.setAttribute("data-tg-width0", r.getAttribute("stroke-width") || "1.2");
4360
+ }
4361
+ r.setAttribute("stroke", TG_TONE.plan);
4362
+ r.setAttribute("stroke-width", width);
4363
+ };
4364
+ const dim = (g) => {
4365
+ g.setAttribute("data-cone-dim", "1");
4366
+ g.style.opacity = "0.35";
4367
+ };
4368
+ const mark = (g, light) => {
4369
+ if (!light) return;
4370
+ g.setAttribute("data-cone", light);
4371
+ if (light === "dim") dim(g);
4372
+ // A components card is outlined by its root's state already (drawTgComponentMarks), which keeps the original stroke to put back.
4373
+ else if (!compMode) outline(g, light === "changed" ? "4" : "2.5");
4374
+ };
4375
+ if (compMode) {
4376
+ // Each components card by the root its job names (terragucci.components.json), else by the answer's root.
4377
+ const named = (tgComponentFacets && tgComponentFacets.roots) || {};
4378
+ const done = new Set();
4379
+ for (const g of svg.querySelectorAll("[data-node-id]")) {
4380
+ const id = g.getAttribute("data-node-id");
4381
+ const path = [named[id], id].find((p) => p && lights.roots.has(p));
4382
+ if (path) {
4383
+ mark(g, coneRootLight(lights, path));
4384
+ done.add(g);
4385
+ }
4386
+ }
4387
+ for (const path of lights.roots.keys()) {
4388
+ const r = rootOf(path);
4389
+ if (!r) continue;
4390
+ for (const c of componentsOfRoot(r)) {
4391
+ const g = svg.querySelector(`[data-node-id="${CSS.escape(c)}"]`);
4392
+ if (g && !done.has(g)) mark(g, coneRootLight(lights, path));
4393
+ }
4394
+ }
4395
+ return;
4396
+ }
4397
+ for (const g of svg.querySelectorAll("[data-node-id]")) {
4398
+ const at = coneCardRoot(g.getAttribute("data-node-id"), lights, (tgAnswer && tgAnswer.roots) || []);
4399
+ if (at) mark(g, coneResourceLight(lights, at.root, at.address));
4400
+ }
4401
+ // Each root's box says how the plan took it (the badge's words, web/terragucci-change.js rootStates).
4402
+ for (const m of svg.querySelectorAll("g[data-tg-root]")) {
4403
+ const light = coneRootLight(lights, m.getAttribute("data-tg-root"));
4404
+ if (light) m.setAttribute("data-cone", light);
4405
+ }
4406
+ }
4407
+ /**
4408
+ * How far a card (`b`, svg units) may grow down: to the next card under it, or the bottom of the box that holds it,
4409
+ * with a gap; nothing when no box holds it, so a grown card never changes what the graph spans.
4410
+ */
4411
+ function roomUnder(b, svg, boxOf, own, need = 0) {
4412
+ // The innermost box that holds the card.
4413
+ let box = null;
4414
+ let boxB = null;
4415
+ for (const r of svg.querySelectorAll("rect[data-group-id]")) {
4416
+ const g = boxOf(r);
4417
+ if (g && b.x >= g.x - 0.5 && b.x2 <= g.x2 + 0.5 && b.y >= g.y - 0.5 && b.y2 <= g.y2 + 0.5 && (!boxB || g.y2 - g.y < boxB.y2 - boxB.y)) {
4418
+ box = r;
4419
+ boxB = g;
4420
+ }
4421
+ }
4422
+ if (!box) return 0;
4423
+ let cardRoom = Infinity;
4424
+ for (const c of svg.querySelectorAll("[data-node-id]")) {
4425
+ if (c === own) continue;
4426
+ const o = boxOf(c);
4427
+ if (o && o.x < b.x2 && o.x2 > b.x && o.y >= b.y2 - 0.5) cardRoom = Math.min(cardRoom, o.y - b.y2 - 8);
4428
+ }
4429
+ let room = boxB.y2 - b.y2 - 10;
4430
+ // Not enough in the box, and no card under this one in it: the box grows too, when nothing lies under the box.
4431
+ if (need > room && cardRoom === Infinity) {
4432
+ const extra = need - room;
4433
+ const below = [...svg.querySelectorAll("rect[data-group-id], [data-node-id]")].some((n) => {
4434
+ if (n === box || n === own || box.contains(n)) return false;
4435
+ const o = boxOf(n);
4436
+ return o && o.x < boxB.x2 && o.x2 > boxB.x && o.y >= boxB.y2 - 0.5 && o.y < boxB.y2 + extra + 12;
4437
+ });
4438
+ if (!below) {
4439
+ const h0 = Number(box.getAttribute("height"));
4440
+ if (!box.hasAttribute("data-tg-h0")) box.setAttribute("data-tg-h0", String(h0));
4441
+ box.setAttribute("height", String(h0 + extra));
4442
+ room = need;
4443
+ }
4444
+ }
4445
+ return Math.max(0, Math.min(room, cardRoom));
4028
4446
  }
4029
4447
  const sameBox = (a, b) => !!a && !!b && Math.abs(a.x - b.x) < 0.5 && Math.abs(a.y - b.y) < 0.5 && Math.abs(a.x2 - b.x2) < 0.5 && Math.abs(a.y2 - b.y2) < 0.5;
4030
4448
 
4449
+ /**
4450
+ * behold#744: on the components zoom an edge says what it means, not only "app-01 → cluster-a": the one depends on the
4451
+ * other, which applies first, and what it reads of it. In its <title>, which the shared tooltip shows (a kiosk frame's too).
4452
+ */
4453
+ function tipComponentEdges(svg, edges = []) {
4454
+ for (const g of svg.querySelectorAll("g[data-edge-from]")) {
4455
+ const from = g.getAttribute("data-edge-from");
4456
+ const to = g.getAttribute("data-edge-to");
4457
+ const title = [...g.children].find((c) => c.localName === "title");
4458
+ if (!from || !to || !title) continue;
4459
+ const read = edges.find((e) => (e.from === from || e.from.endsWith(`/${from}`)) && (e.to === to || e.to.endsWith(`/${to}`)));
4460
+ title.textContent = `${from} → ${to}\n${from} depends on ${to}, so ${to} applies first${read ? `\n${tgReadLine(read)}` : ""}`;
4461
+ }
4462
+ }
4463
+
4464
+ // behold#744: the reads' pills show while they matter (web/tg-read-pills.js): the pointer's, a kiosk's flash, Inspect's focus.
4465
+ const tgReadFlash = createReadFlash();
4466
+ let tgReadEdgesNow = [];
4467
+ let tgReadHot = [];
4468
+ /** The reads the pointer (or the focus) on `target` lights: a read's line, or a card or box of a root that reads or is read. */
4469
+ function tgReadHotOf(target) {
4470
+ if (!target || !target.closest || !target.closest("#graph svg") || !tgReadEdgesNow.length) return [];
4471
+ const hit = target.closest("[data-tg-read-hit]");
4472
+ if (hit) return tgHotReads(tgReadEdgesNow, { key: hit.getAttribute("data-tg-read-hit") });
4473
+ const h = kioskHoverOf(target);
4474
+ return h && h.root ? tgHotReads(tgReadEdgesNow, { root: h.root }) : [];
4475
+ }
4476
+ function tgReadSetHot(keys) {
4477
+ if (keys.length === tgReadHot.length && keys.every((k, i) => k === tgReadHot[i])) return;
4478
+ tgReadHot = keys;
4479
+ const svg = document.querySelector("#graph svg");
4480
+ if (svg) tgReadShow(svg);
4481
+ }
4482
+ /** Light the hot reads' pills and lines, the lit pills last in their layer so they sit over the rest. */
4483
+ function tgReadShow(svg) {
4484
+ ensureTgReadStyle();
4485
+ const hot = new Set(tgReadHot);
4486
+ for (const el of svg.querySelectorAll("[data-tg-read]")) el.classList.toggle("tg-hot", hot.has(el.getAttribute("data-tg-read")));
4487
+ for (const g of svg.querySelectorAll("g[data-tg-read-pill].tg-hot")) g.parentNode.appendChild(g);
4488
+ }
4489
+ let tgReadWired = false;
4490
+ function wireTgReadHover() {
4491
+ if (tgReadWired || typeof document === "undefined") return;
4492
+ tgReadWired = true;
4493
+ document.addEventListener("pointerover", (e) => tgReadSetHot(tgReadHotOf(e.target)));
4494
+ document.addEventListener("pointerout", (e) => !e.relatedTarget && tgReadSetHot([]));
4495
+ document.addEventListener("focusin", (e) => tgReadSetHot(tgReadHotOf(e.target)));
4496
+ document.addEventListener("focusout", (e) => !e.relatedTarget && tgReadSetHot([]));
4497
+ }
4498
+ /** The pills' looks, once per document: hidden until lit; a flash shows and fades; no fade under prefers-reduced-motion. */
4499
+ function ensureTgReadStyle() {
4500
+ wireTgReadHover();
4501
+ if (document.getElementById("tg-read-style")) return;
4502
+ const st = document.createElement("style");
4503
+ st.id = "tg-read-style";
4504
+ st.textContent = `#graph g[data-tg-read-pill] { opacity: 0; }
4505
+ #graph g[data-tg-read-pill].tg-hot, #graph g[data-tg-read-pill].tg-shown { opacity: 1 !important; }
4506
+ #graph g[data-tg-read-pill].tg-hot { transition: opacity .15s ease; }
4507
+ #graph g[data-tg-read-pill].tg-flash { animation: tg-read-flash 6s linear both; }
4508
+ #graph line[data-tg-read].tg-hot { stroke-width: 5; filter: drop-shadow(0 0 3px var(--bg)); }
4509
+ @keyframes tg-read-flash { 0% { opacity: 0; } 4%, 80% { opacity: 1; } 100% { opacity: 0; } }
4510
+ @keyframes tg-read-flash-step { 0%, 99.9% { opacity: 1; } 100% { opacity: 0; } }
4511
+ @media (prefers-reduced-motion: reduce) {
4512
+ #graph g[data-tg-read-pill].tg-hot { transition: none; }
4513
+ #graph g[data-tg-read-pill].tg-flash { animation-name: tg-read-flash-step; animation-timing-function: step-end; }
4514
+ }`;
4515
+ document.head.appendChild(st);
4516
+ }
4517
+
4031
4518
  /** #571: points along the components graph's own edges, in the svg's coordinates, every few units. */
4032
4519
  function chantEdgePoints(svg) {
4033
4520
  const toSvg = svg.getScreenCTM && svg.getScreenCTM();
@@ -4084,6 +4571,330 @@ function watchTgRuns() {
4084
4571
  * spot that is clear, in the words that fit, else only in the tooltip.
4085
4572
  * Returns the wave boxes, in the svg's coordinates.
4086
4573
  */
4574
+ /** behold#631: a kiosk passer-by can't place a card's type glyph (it reads as a checkbox): hide it, once per card. */
4575
+ function kioskCardGlyphs(svg) {
4576
+ for (const card of svg.querySelectorAll("[data-node-id]")) {
4577
+ const icon = card.querySelector(":scope > g[transform]");
4578
+ if (!icon || card.hasAttribute("data-kiosk-glyph")) continue;
4579
+ icon.setAttribute("visibility", "hidden");
4580
+ // The name and the state line take the glyph's room, so the bigger state words fit.
4581
+ card.setAttribute("data-kiosk-glyph", "1");
4582
+ for (const t of card.querySelectorAll(":scope > text")) t.setAttribute("x", String(Number(t.getAttribute("x")) - 30));
4583
+ }
4584
+ }
4585
+ /** The convex hull of points (monotone chain), counter-clockwise. */
4586
+ function hullOf(points) {
4587
+ const p = [...points].sort((a, b) => a.x - b.x || a.y - b.y);
4588
+ if (p.length < 3) return p;
4589
+ const cross = (o, a, b) => (a.x - o.x) * (b.y - o.y) - (a.y - o.y) * (b.x - o.x);
4590
+ const lower = [];
4591
+ for (const q of p) {
4592
+ while (lower.length >= 2 && cross(lower[lower.length - 2], lower[lower.length - 1], q) <= 0) lower.pop();
4593
+ lower.push(q);
4594
+ }
4595
+ const upper = [];
4596
+ for (const q of [...p].reverse()) {
4597
+ while (upper.length >= 2 && cross(upper[upper.length - 2], upper[upper.length - 1], q) <= 0) upper.pop();
4598
+ upper.push(q);
4599
+ }
4600
+ return [...lower.slice(0, -1), ...upper.slice(0, -1)];
4601
+ }
4602
+ /** A closed path through a hull, each corner rounded by at most `r`, the `sharp` point (the apex) left a point. */
4603
+ function smoothPath(h, sharp = null, r = 28) {
4604
+ if (h.length < 3) return "";
4605
+ const f = (n) => Math.round(n * 10) / 10;
4606
+ const toward = (p, q, d) => {
4607
+ const len = Math.hypot(q.x - p.x, q.y - p.y) || 1;
4608
+ return { x: p.x + ((q.x - p.x) / len) * d, y: p.y + ((q.y - p.y) / len) * d };
4609
+ };
4610
+ let d = "";
4611
+ h.forEach((p, i) => {
4612
+ const prev = h[(i - 1 + h.length) % h.length];
4613
+ const next = h[(i + 1) % h.length];
4614
+ if (sharp && p.x === sharp.x && p.y === sharp.y) {
4615
+ d += `${i ? "L" : "M"}${f(p.x)},${f(p.y)} `;
4616
+ return;
4617
+ }
4618
+ const k = Math.min(r, Math.hypot(prev.x - p.x, prev.y - p.y) / 2, Math.hypot(next.x - p.x, next.y - p.y) / 2);
4619
+ const a = toward(p, prev, k);
4620
+ const b = toward(p, next, k);
4621
+ d += `${i ? "L" : "M"}${f(a.x)},${f(a.y)} Q${f(p.x)},${f(p.y)} ${f(b.x)},${f(b.y)} `;
4622
+ });
4623
+ return `${d}Z`;
4624
+ }
4625
+ const REACH_TONE = { plan: "var(--frame-pending, var(--pending))", bad: "var(--frame-degraded, var(--degraded))" };
4626
+ /**
4627
+ * behold#631: what a change reaches, drawn on a chant repo's components graph:
4628
+ * a soft wedge per root, from the root card's top centre up over the cards
4629
+ * downstream of it, padded, behind the cards and in front of the wave boxes.
4630
+ * It grows from the root outward over about 1.2 s (none under reduced motion)
4631
+ * and then rests faint, with its words at its upper edge. A new reach
4632
+ * crossfades the old one out; the same one redrawn only follows the cards.
4633
+ */
4634
+ function drawReach(svg, reach, boxOf, size = 18, needs = null) {
4635
+ // Its words inside it, beside its apex: just right of the root card, in the open space between the root's wave box and the one above.
4636
+ const labelAt = (shapes) => {
4637
+ const at = shapes[0];
4638
+ const waveBoxes = [...svg.querySelectorAll("rect[data-group-id]")].map((r) => boxOf(r)).filter(Boolean);
4639
+ const inBox = waveBoxes.find((b) => at.root.x >= b.x && at.root.x2 <= b.x2 && at.root.y >= b.y && at.root.y2 <= b.y2) || null;
4640
+ const above = inBox ? waveBoxes.filter((b) => b.y2 <= inBox.y + 1).sort((a, b) => b.y2 - a.y2)[0] : null;
4641
+ return { x: at.root.x2 + 14, y: inBox && above ? (inBox.y + above.y2) / 2 : at.root.y - 24 };
4642
+ };
4643
+ const NS = "http://www.w3.org/2000/svg";
4644
+ const old = svg.querySelector("g[data-reach]");
4645
+ const key = reach ? reach.key : null;
4646
+ const fadeOut = (g) => {
4647
+ if (!g) return;
4648
+ // Its words, drawn on top in their own group, go with it.
4649
+ const words = svg.querySelector(`g[data-reach-words="${CSS.escape(g.getAttribute("data-reach") || "")}"]`);
4650
+ if (words) {
4651
+ words.removeAttribute("data-reach-words");
4652
+ words.style.transition = "opacity 0.5s ease-out";
4653
+ words.style.opacity = "0";
4654
+ setTimeout(() => words.remove(), 600);
4655
+ }
4656
+ g.removeAttribute("data-reach");
4657
+ g.setAttribute("data-reach-old", "1");
4658
+ g.style.transition = "opacity 0.5s ease-out";
4659
+ g.style.opacity = "0";
4660
+ setTimeout(() => g.remove(), 600);
4661
+ };
4662
+ if (!reach) return fadeOut(old);
4663
+ const card = (id) => svg.querySelector(`[data-node-id="${CSS.escape(id)}"]`);
4664
+ const box = (id) => {
4665
+ const g = card(id);
4666
+ return g ? boxOf(g) : null;
4667
+ };
4668
+ const pad = 16;
4669
+ const shapes = [];
4670
+ const covered = new Set(reach.covered);
4671
+ // behold#741: a terragucci repo's marks carry their own edges (the plan report's reads, the run view's).
4672
+ const needsOf = needs || (chantFacets && chantFacets.needs) || {};
4673
+ for (const root of reach.roots) {
4674
+ const rb = box(root);
4675
+ if (!rb) continue;
4676
+ // This root's own reach: the covered cards downstream of it.
4677
+ const mine = [...covered].filter((c) => c !== root && (reach.roots.length === 1 || reachesFrom(root, c, needsOf)));
4678
+ const boxes = mine.map(box).filter(Boolean);
4679
+ if (!boxes.length) continue;
4680
+ // The apex just below the root card's bottom centre; the root card itself inside, so the shape comes out of it.
4681
+ const apex = { x: (rb.x + rb.x2) / 2, y: rb.y2 + pad + 10 };
4682
+ const pts = [apex];
4683
+ for (const b of [rb, ...boxes]) pts.push({ x: b.x - pad, y: b.y - pad }, { x: b.x2 + pad, y: b.y - pad }, { x: b.x - pad, y: b.y2 + pad }, { x: b.x2 + pad, y: b.y2 + pad });
4684
+ const top = Math.min(...boxes.map((b) => b.y)) - pad;
4685
+ shapes.push({ d: smoothPath(hullOf(pts), apex), apex, root: rb, top, cx: (Math.min(...boxes.map((b) => b.x)) + Math.max(...boxes.map((b) => b.x2))) / 2, reachR: Math.max(...pts.map((p) => Math.hypot(p.x - apex.x, p.y - apex.y))) });
4686
+ }
4687
+ if (!shapes.length) return fadeOut(old);
4688
+ const tone = REACH_TONE[reach.tone] || REACH_TONE.plan;
4689
+ if (old && old.getAttribute("data-reach") === key) {
4690
+ // The same reach: follow the cards, no new growth, and never left part-grown (a frame drawn while hidden pauses its animation).
4691
+ old.querySelectorAll("path[data-reach-shape], path[data-reach-edge]").forEach((p) => {
4692
+ const i = Number(p.getAttribute("data-reach-i"));
4693
+ if (shapes[i]) p.setAttribute("d", shapes[i].d);
4694
+ });
4695
+ reachFinal(old, shapes, labelAt(shapes));
4696
+ return;
4697
+ }
4698
+ fadeOut(old);
4699
+ const g = document.createElementNS(NS, "g");
4700
+ g.setAttribute("data-reach", key);
4701
+ g.setAttribute("pointer-events", "none");
4702
+ const reduce = typeof matchMedia === "function" && matchMedia("(prefers-reduced-motion: reduce)").matches;
4703
+ const id = `reach-${Date.now().toString(36)}`;
4704
+ // The growth: each wedge revealed by a circle from its apex, widening out and up as if along the edges.
4705
+ const defs = document.createElementNS(NS, "defs");
4706
+ const clip = document.createElementNS(NS, "clipPath");
4707
+ clip.setAttribute("id", id);
4708
+ for (const sh of shapes) {
4709
+ const c = document.createElementNS(NS, "circle");
4710
+ c.setAttribute("cx", String(sh.apex.x));
4711
+ c.setAttribute("cy", String(sh.apex.y));
4712
+ c.setAttribute("r", reduce ? String(sh.reachR) : "0");
4713
+ if (!reduce) {
4714
+ const a = document.createElementNS(NS, "animate");
4715
+ for (const [k, v] of Object.entries({ attributeName: "r", from: "0", to: String(sh.reachR), dur: "1.2s", fill: "freeze", calcMode: "spline", keyTimes: "0;1", keySplines: "0.16 1 0.3 1" })) a.setAttribute(k, v);
4716
+ c.appendChild(a);
4717
+ }
4718
+ clip.appendChild(c);
4719
+ }
4720
+ defs.appendChild(clip);
4721
+ g.appendChild(defs);
4722
+ // One fill for all the wedges, so where two roots' wedges meet they merge rather than darken.
4723
+ const fill = document.createElementNS(NS, "g");
4724
+ fill.setAttribute("clip-path", `url(#${id})`);
4725
+ fill.setAttribute("opacity", "0.13");
4726
+ const edge = document.createElementNS(NS, "g");
4727
+ edge.setAttribute("clip-path", `url(#${id})`);
4728
+ for (const sh of shapes) {
4729
+ const p = document.createElementNS(NS, "path");
4730
+ p.setAttribute("d", sh.d);
4731
+ p.setAttribute("fill", tone);
4732
+ p.setAttribute("data-reach-shape", "1");
4733
+ p.setAttribute("data-reach-i", String(shapes.indexOf(sh)));
4734
+ fill.appendChild(p);
4735
+ const e = document.createElementNS(NS, "path");
4736
+ e.setAttribute("d", sh.d);
4737
+ e.setAttribute("fill", "none");
4738
+ e.setAttribute("stroke", tone);
4739
+ e.setAttribute("stroke-opacity", "0.55");
4740
+ e.setAttribute("stroke-width", "1.5");
4741
+ e.setAttribute("data-reach-edge", "1");
4742
+ e.setAttribute("data-reach-i", String(shapes.indexOf(sh)));
4743
+ edge.appendChild(e);
4744
+ }
4745
+ g.append(fill, edge);
4746
+ const where = labelAt(shapes);
4747
+ const label = document.createElementNS(NS, "text");
4748
+ for (const [k, v] of Object.entries({ x: String(where.x), y: String(where.y), "text-anchor": "start", "dominant-baseline": "central", "font-size": String(size), "font-weight": "700", fill: tone, stroke: "var(--bg)", "stroke-width": "5", "paint-order": "stroke", "stroke-linejoin": "round", "data-reach-label": "1" })) label.setAttribute(k, v);
4749
+ label.textContent = reach.label;
4750
+ if (!reduce) {
4751
+ label.style.opacity = "0";
4752
+ label.style.transition = "opacity 0.4s ease-out 1s";
4753
+ requestAnimationFrame(() => (label.style.opacity = "1"));
4754
+ }
4755
+ // The shape lies under everything, a shadow on the stage floor: before the wave boxes, the edges and the cards.
4756
+ // Its words sit on top, in their own group, so they stay readable.
4757
+ const words = document.createElementNS(NS, "g");
4758
+ words.setAttribute("data-reach-words", key);
4759
+ words.setAttribute("pointer-events", "none");
4760
+ words.appendChild(label);
4761
+ // Above the stage's own backdrop (pinhole's gradient and dot pattern), under all else.
4762
+ const backdrop = (n) => n.tagName.toLowerCase() === "rect" && !n.hasAttribute("data-group-id") && /^url\(#pin-/.test(n.getAttribute("fill") || "");
4763
+ const floor = [...svg.children].find((n) => !["defs", "style", "title"].includes(n.tagName.toLowerCase()) && !backdrop(n) && !n.hasAttribute("data-reach-old"));
4764
+ if (floor) svg.insertBefore(g, floor);
4765
+ else svg.appendChild(g);
4766
+ svg.appendChild(words);
4767
+ // Whatever the animation did (a hidden frame pauses it), the reach ends whole, its words up.
4768
+ setTimeout(() => g.isConnected && reachFinal(g, shapes, labelAt(shapes)), reduce ? 0 : 1_400);
4769
+ }
4770
+ /**
4771
+ * behold#631: a chant kiosk reads its waves bottom to top. Each wave box's
4772
+ * title says "wave N" at the header's size in a readable tone, each edge
4773
+ * carries an arrowhead at its dependent's end (so up reads as "then"), and
4774
+ * the bottom box says once that the waves apply from the bottom up.
4775
+ */
4776
+ function chantKioskWaves(svg, boxOf, size) {
4777
+ const NS = "http://www.w3.org/2000/svg";
4778
+ let relabelled = false;
4779
+ for (const rect of svg.querySelectorAll("rect[data-group-id]")) {
4780
+ const n = tgWaveOfKey(rect.getAttribute("data-group-id"));
4781
+ if (n === null) continue;
4782
+ let title = null;
4783
+ for (let el = rect.nextElementSibling; el; el = el.nextElementSibling) {
4784
+ if (el.tagName.toLowerCase() === "text") {
4785
+ title = el;
4786
+ break;
4787
+ }
4788
+ if (el.tagName.toLowerCase() === "rect") break;
4789
+ }
4790
+ // The reach lies under the boxes: on a chant kiosk their fill lets it show through faintly; the border stays.
4791
+ if (!rect.hasAttribute("data-kiosk-fill")) {
4792
+ rect.setAttribute("data-kiosk-fill", rect.getAttribute("fill-opacity") || "");
4793
+ rect.setAttribute("fill-opacity", "0.3");
4794
+ }
4795
+ if (!title || title.hasAttribute("data-kiosk-wave")) continue;
4796
+ title.setAttribute("data-kiosk-wave", "1");
4797
+ title.textContent = `wave ${n}`;
4798
+ title.setAttribute("font-size", String(size));
4799
+ title.dataset.pinFont = String(size);
4800
+ title.setAttribute("fill", "var(--fg)");
4801
+ relabelled = true;
4802
+ }
4803
+ // scaleBoxLabels indexed the titles at pinhole's size: index them again at this one.
4804
+ if (relabelled) {
4805
+ boxLabelCache = { svg: null, labels: [] };
4806
+ boxLabelScale = null;
4807
+ }
4808
+ // Arrowheads: one marker, at the end of each edge that meets its dependent (the edge's `from`, consumer -> producer).
4809
+ if (!svg.querySelector("#k-then-arrow")) {
4810
+ const defs = svg.querySelector("defs") || svg.insertBefore(document.createElementNS(NS, "defs"), svg.firstChild);
4811
+ const m = document.createElementNS(NS, "marker");
4812
+ for (const [k, v] of Object.entries({ id: "k-then-arrow", viewBox: "0 0 10 10", refX: "9", refY: "5", markerWidth: "7", markerHeight: "7", markerUnits: "userSpaceOnUse", orient: "auto-start-reverse" })) m.setAttribute(k, v);
4813
+ const p = document.createElementNS(NS, "path");
4814
+ p.setAttribute("d", "M0,0 L10,5 L0,10 z");
4815
+ p.setAttribute("fill", "var(--muted)");
4816
+ m.appendChild(p);
4817
+ defs.appendChild(m);
4818
+ }
4819
+ for (const g of svg.querySelectorAll("g[data-edge-from]")) {
4820
+ const path = g.querySelector("path.pin-edge-line") || g.querySelector("path");
4821
+ if (!path || path.hasAttribute("data-kiosk-then")) continue;
4822
+ path.setAttribute("data-kiosk-then", "1");
4823
+ const from = svg.querySelector(`[data-node-id="${CSS.escape(g.getAttribute("data-edge-from"))}"]`);
4824
+ const fb = from ? boxOf(from) : null;
4825
+ let start = null;
4826
+ let end = null;
4827
+ try {
4828
+ const len = path.getTotalLength();
4829
+ start = path.getPointAtLength(0);
4830
+ end = path.getPointAtLength(len);
4831
+ } catch {
4832
+ continue;
4833
+ }
4834
+ if (!fb || !start || !end) continue;
4835
+ const near = (p) => Math.hypot(p.x - (fb.x + fb.x2) / 2, p.y - (fb.y + fb.y2) / 2);
4836
+ // The arrow points into the dependent: at whichever end of the path meets it.
4837
+ if (near(start) < near(end)) path.setAttribute("marker-start", "url(#k-then-arrow)");
4838
+ else path.setAttribute("marker-end", "url(#k-then-arrow)");
4839
+ }
4840
+ // The bottom box says which way the waves go, once.
4841
+ if (!svg.querySelector("text[data-kiosk-upward]")) {
4842
+ const boxes = [...svg.querySelectorAll("rect[data-group-id]")].filter((r) => tgWaveOfKey(r.getAttribute("data-group-id")) !== null);
4843
+ const low = boxes.map((r) => ({ r, b: boxOf(r) })).filter((x) => x.b).sort((a, b) => b.b.y2 - a.b.y2)[0];
4844
+ if (low) {
4845
+ const t = document.createElementNS(NS, "text");
4846
+ for (const [k, v] of Object.entries({ x: String(low.b.x + 18), y: String(low.b.y2 - 12), "font-size": "13", "font-weight": "600", fill: "var(--muted)", "data-kiosk-upward": "1" })) t.setAttribute(k, v);
4847
+ t.textContent = "the waves apply from the bottom up";
4848
+ svg.appendChild(t);
4849
+ }
4850
+ }
4851
+ }
4852
+ /** A reach at its end state: each clip circle at full radius on its apex, no animation left, its words shown where they go. */
4853
+ function reachFinal(g, shapes, where) {
4854
+ const svgEl = g.ownerSVGElement || g.parentNode;
4855
+ g.querySelectorAll("clipPath circle").forEach((c, i) => {
4856
+ for (const a of c.querySelectorAll("animate")) a.remove();
4857
+ const sh = shapes[i];
4858
+ if (!sh) return;
4859
+ c.setAttribute("cx", String(sh.apex.x));
4860
+ c.setAttribute("cy", String(sh.apex.y));
4861
+ c.setAttribute("r", String(sh.reachR));
4862
+ });
4863
+ const key = g.getAttribute("data-reach") || "";
4864
+ const words = svgEl && svgEl.querySelector ? svgEl.querySelector(`g[data-reach-words="${CSS.escape(key)}"]`) : null;
4865
+ const label = (words && words.querySelector("text[data-reach-label]")) || g.querySelector("text[data-reach-label]");
4866
+ if (label) {
4867
+ label.setAttribute("x", String(where.x));
4868
+ label.setAttribute("y", String(where.y));
4869
+ label.style.transition = "";
4870
+ label.style.opacity = "1";
4871
+ }
4872
+ }
4873
+ /** Whether `c` is downstream of `root` along `needs`. */
4874
+ function reachesFrom(root, c, needs) {
4875
+ const seen = new Set();
4876
+ const up = (n) => {
4877
+ for (const d of needs[n] || []) {
4878
+ if (d === root) return true;
4879
+ if (seen.has(d)) continue;
4880
+ seen.add(d);
4881
+ if (up(d)) return true;
4882
+ }
4883
+ return false;
4884
+ };
4885
+ return up(c);
4886
+ }
4887
+ /** behold#631: the "working" outline pulse, once per document; no motion under prefers-reduced-motion. */
4888
+ function ensureWorkingStyle() {
4889
+ if (document.getElementById("k-working-style")) return;
4890
+ const st = document.createElement("style");
4891
+ st.id = "k-working-style";
4892
+ st.textContent = `@media (prefers-reduced-motion: no-preference) {
4893
+ rect.k-working { animation: k-working 1.6s ease-in-out infinite; stroke: var(--frame-runtime, var(--runtime)); }
4894
+ @keyframes k-working { 0%, 100% { stroke-opacity: 0.35; stroke-width: 1.5; } 50% { stroke-opacity: 1; stroke-width: 3; } }
4895
+ }`;
4896
+ document.head.appendChild(st);
4897
+ }
4087
4898
  function drawTgComponentMarks(svg, { drawnAnswer, focus, boxOf, make, edgePoints, marks: given = null }) {
4088
4899
  const marks = given || tgComponentMarks(drawnAnswer, tgProgress, tgComponentFacets, { runs: tgRuns, pin: view.run || null });
4089
4900
  // behold#631: where the marks came from, said in each tooltip.
@@ -4099,6 +4910,8 @@ function drawTgComponentMarks(svg, { drawnAnswer, focus, boxOf, make, edgePoints
4099
4910
  .map(boxOf)
4100
4911
  .filter(Boolean);
4101
4912
  const cardEls = [...svg.querySelectorAll("[data-node-id]")];
4913
+ // behold#631: last draw's "working" pulse goes; this draw's marks say which cards still have it.
4914
+ for (const r of svg.querySelectorAll("rect.k-working")) r.setAttribute("class", (r.getAttribute("class") || "").replace(/\bk-working\b/g, "").trim());
4102
4915
  const cardBoxes = cardEls.map(boxOf).filter(Boolean);
4103
4916
  const edgeHit = (r) => edgePoints.some((p) => p.x >= r.x - 4 && p.x <= r.x2 + 4 && p.y >= r.y - 4 && p.y <= r.y2 + 4);
4104
4917
  const probe = make("text", { "font-size": 12, "font-weight": 700 });
@@ -4124,7 +4937,7 @@ function drawTgComponentMarks(svg, { drawnAnswer, focus, boxOf, make, edgePoints
4124
4937
  const rects = [...g.querySelectorAll(":scope > rect")];
4125
4938
  const body = rects.reduce((a, r) => (!a || Number(r.getAttribute("width")) * Number(r.getAttribute("height")) > Number(a.getAttribute("width")) * Number(a.getAttribute("height")) ? r : a), null);
4126
4939
  const bar = rects.find((r) => r !== body && Number(r.getAttribute("width")) <= 6);
4127
- const quiet = m.state === "outside" || m.state === "unchanged" || m.state === "not-started";
4940
+ const quiet = m.state === "outside" || m.state === "unchanged" || m.state === "not-started" || m.state === "reading";
4128
4941
  const inFocus = !focus || focus.has(m.root) || focus.has(id);
4129
4942
  if (body) {
4130
4943
  body.setAttribute("data-tg-stroke0", body.getAttribute("stroke") || "");
@@ -4138,20 +4951,67 @@ function drawTgComponentMarks(svg, { drawnAnswer, focus, boxOf, make, edgePoints
4138
4951
  bar.setAttribute("data-tg-fill0", bar.getAttribute("fill") || "");
4139
4952
  bar.setAttribute("fill", tone(m.tone));
4140
4953
  }
4954
+ // behold#631: a card the pipeline is about to work on, between events, pulses its outline (none under reduced motion).
4955
+ if (body) {
4956
+ if (m.working) body.setAttribute("class", `${body.getAttribute("class") || ""} k-working`.trim());
4957
+ else if ((body.getAttribute("class") || "").includes("k-working")) body.setAttribute("class", (body.getAttribute("class") || "").replace(/\bk-working\b/g, "").trim());
4958
+ if (m.working) ensureWorkingStyle();
4959
+ }
4960
+ if (!m.words && m.working) continue;
4141
4961
  const texts = [...g.querySelectorAll(":scope > text")];
4142
4962
  const sub = texts.find((t) => /^Component\b/.test((t.textContent || "").trim())) || texts[1];
4143
4963
  if (!sub || !body) continue;
4144
4964
  const x = Number(sub.getAttribute("x"));
4145
4965
  const y = Number(sub.getAttribute("y"));
4146
4966
  const room = Number(body.getAttribute("x")) + Number(body.getAttribute("width")) - 10 - x;
4147
- const words = width(m.words, 12, 700) <= room ? m.words : m.short;
4967
+ // behold#631: a middle form (a failure's first words, a blocker's name) before the one-word short.
4968
+ // behold#631: a chant kiosk says a card's state at the size of its name, readable from a few feet.
4969
+ const cardFont = marks.cardFont || 12;
4970
+ // A cone root's words that don't fit: the state on this line, the cone's size wrapped under it (never cut).
4971
+ const coneCard = m.cone === "cone" || m.cone === "full";
4972
+ // behold#736: a fallback's line breaks after "planned in full", its kind under it ("empty cone").
4973
+ const coneCut = coneCard ? m.words.indexOf(m.cone === "full" ? ": " : " · ") : -1;
4974
+ const words = width(m.words, cardFont, 700) <= room ? m.words : coneCut > 0 ? m.words.slice(0, coneCut) : m.mid && width(m.mid, cardFont, 700) <= room ? m.mid : m.short;
4148
4975
  sub.setAttribute("visibility", "hidden");
4149
4976
  sub.setAttribute("data-tg-hid", "1");
4150
- const t = make("text", { "data-tg-root": "card", x, y, "font-size": 12, "font-weight": 700, fill: quiet ? "var(--frame-card-muted, var(--muted))" : TG_CARD_TONE[m.tone] || TG_CARD_TONE.idle }, words);
4977
+ const t = make("text", { "data-tg-root": "card", x, y: marks.cardFont ? y + 4 : y, "font-size": cardFont, "font-weight": 700, fill: quiet ? "var(--frame-card-muted, var(--muted))" : TG_CARD_TONE[m.tone] || TG_CARD_TONE.idle }, words);
4151
4978
  if (m.state === "applying") t.setAttribute("class", "pin-pulse");
4152
4979
  if (!inFocus) t.style.opacity = "0.6";
4153
- t.appendChild(make("title", {}, [`wave ${m.wave} · ${m.words}`, ...m.facts].join("\n") + "\n" + cardSource));
4154
- g.appendChild(t);
4980
+ // The tooltip (with where the marks come from) beside the words, in a group of their own, so the card's text is its words alone.
4981
+ const tip = make("g", { "data-tg-root": "card-tip" });
4982
+ tip.append(make("title", {}, [`wave ${m.wave} · ${m.words}`, ...m.facts].join("\n") + "\n" + cardSource), t);
4983
+ g.appendChild(tip);
4984
+ // Report minor 34: under the state, what didn't fit of its words (the cone's size), then the cone's resources, a
4985
+ // line each, each wrapped to the card's width (web/cone.js wrapWords) so it reads in full. The card's body grows
4986
+ // to hold them when the gap under it has room; no box round them.
4987
+ const rest = words !== m.words && coneCut > 0 ? [m.words.slice(words.length).replace(/^(?: · |: )/, "")] : [];
4988
+ // behold#736: a story's cards say their state at its bigger size (cardFont); the lines under it follow, a size smaller.
4989
+ const lineFont = marks.cardFont ? cardFont - 2 : 11.5;
4990
+ const y0 = marks.cardFont ? y + 4 : y;
4991
+ const said = [...rest, ...(m.lines || [])].flatMap((line) => wrapWords(line, room, (txt) => width(txt, lineFont, 600)));
4992
+ if (said.length) {
4993
+ const LH = lineFont + 3.5;
4994
+ const top = Number(body.getAttribute("y"));
4995
+ const h0 = Number(body.getAttribute("height"));
4996
+ const need = y0 + LH * said.length + 8 - top;
4997
+ if (need > h0) {
4998
+ // Grow into the gap under the card, never onto another card; its box grows with it when nothing lies under the box.
4999
+ const b = boxOf(body);
5000
+ const gap = b ? roomUnder(b, svg, boxOf, g, need - h0) : 0;
5001
+ const grow = Math.max(0, Math.min(need - h0, gap));
5002
+ if (grow > 0) {
5003
+ body.setAttribute("data-tg-h0", String(h0));
5004
+ body.setAttribute("height", String(h0 + grow));
5005
+ }
5006
+ }
5007
+ const floor = top + Number(body.getAttribute("height")) - 6;
5008
+ said.forEach((line, k) => {
5009
+ const ly = y0 + LH * (k + 1);
5010
+ if (ly > floor) return;
5011
+ const last = k === said.length - 1 || y0 + LH * (k + 2) <= floor ? line : `${line} …`;
5012
+ g.appendChild(make("text", { "data-tg-root": "cone-line", x, y: ly, "font-size": lineFont, "font-weight": 600, fill: "var(--frame-card-muted, var(--muted))" }, last));
5013
+ });
5014
+ }
4155
5015
  }
4156
5016
 
4157
5017
  // The wave boxes.
@@ -4181,10 +5041,13 @@ function drawTgComponentMarks(svg, { drawnAnswer, focus, boxOf, make, edgePoints
4181
5041
  if (rb) placed.push(rb);
4182
5042
  // The job's status: after the title on its line, else at the right of that line.
4183
5043
  if (w.status && tb) {
4184
- const size = 12;
5044
+ // behold#631: a chant kiosk's wave words half again as big.
5045
+ const size = marks.waveFont || 12;
4185
5046
  const cy = (tb.y + tb.y2) / 2;
4186
5047
  // Right after the title, as "apply-wave-2 · held at the gate"; else alone at the right of the title's line.
4187
5048
  const spots = [{ words: `· ${w.status.words}`, at: () => tb.x2 + 6 }, { words: w.status.words, at: (wd) => b.x2 - 16 - wd }];
5049
+ // behold#631: a chant kiosk's box titles grow with the fit (scaleBoxLabels), which would run into words set just after them: the right of the line first.
5050
+ if (marks.statusRight) spots.reverse();
4188
5051
  // behold#693: a narrow box whose full words would cross an edge says the short form.
4189
5052
  const short = tgStatusShort(w.status);
4190
5053
  if (short && short !== w.status.words) spots.push({ words: `· ${short}`, at: () => tb.x2 + 6 }, { words: short, at: (wd) => b.x2 - 16 - wd });
@@ -4209,7 +5072,8 @@ function drawTgComponentMarks(svg, { drawnAnswer, focus, boxOf, make, edgePoints
4209
5072
  if (fact) {
4210
5073
  const size = 12.5;
4211
5074
  const digest = /^approve plan (\S+)/.exec(fact);
4212
- const say = digest ? [fact, `plan ${digest[1]}`, `plan ${digest[1].slice(0, 8)}`, digest[1].slice(0, 8)] : [fact];
5075
+ // behold#631: a fact may carry shorter forms of itself (a failure's reason, cut), tried in turn.
5076
+ const say = digest ? [fact, `plan ${digest[1]}`, `plan ${digest[1].slice(0, 8)}`, digest[1].slice(0, 8)] : [fact, ...(Array.isArray(w.factShort) ? w.factShort : [])];
4213
5077
  const fill = w.state === "waiting" ? tone(w.tone) : "var(--muted)";
4214
5078
  let done = false;
4215
5079
  for (const words of say) {
@@ -4514,7 +5378,8 @@ function kioskShotTarget(svg, shot) {
4514
5378
  const boxes = [];
4515
5379
  if (shot.whole) {
4516
5380
  // The whole graph is what is drawn: the boxes, the cards and the reads, not pinhole's margins round them.
4517
- for (const n of svg.querySelectorAll("rect[data-group-id], [data-node-id], [data-tg-reads] > g, line[data-tg-read-from], text[data-tg-reads='caption']")) boxes.push(userBoxOf(svg, n));
5381
+ // behold#744: not the reads' pills, which show and go while the shot stays.
5382
+ for (const n of svg.querySelectorAll("rect[data-group-id], [data-node-id], [data-tg-reads] > g:not([data-tg-read-pill]), line[data-tg-read-from], text[data-tg-reads='caption']")) boxes.push(userBoxOf(svg, n));
4518
5383
  return unionBox(boxes) || { x: vbInit[0], y: vbInit[1], x2: vbInit[0] + vbInit[2], y2: vbInit[1] + vbInit[3] };
4519
5384
  }
4520
5385
  const named = (tgComponentFacets && tgComponentFacets.roots) || {};
@@ -4546,15 +5411,86 @@ function kioskShotBox() {
4546
5411
  const host = document.getElementById("graph");
4547
5412
  if (!svg || !host || !kioskShot) return null;
4548
5413
  const pane = host.getBoundingClientRect();
4549
- const i = kioskShot.insets;
4550
- const insets = {
4551
- top: Math.max(0, i.top - pane.top),
4552
- left: Math.max(0, i.left - pane.left),
4553
- bottom: Math.max(0, i.bottom - (window.innerHeight - pane.bottom)),
4554
- right: Math.max(0, i.right - (window.innerWidth - pane.right)),
5414
+ const insets = kioskPaneInsets(kioskShot);
5415
+ // One framing on a small stage (web/kiosk-shot.js): when the whole graph fits with its cards readable, every step's
5416
+ // shot is the whole graph, and the viewBox holds from step to step and cycle to cycle while the repo, the view and
5417
+ // the pane stay. Judged with the room the held framing keeps, so a caption's height never flips the rule.
5418
+ // heldInsets: the run's caption's room at the top and the caption under the stage; nothing a step shows sits at the side.
5419
+ const docked = heldInsets(insets, kioskShot.room || 0);
5420
+ const rects = [...svg.querySelectorAll("[data-node-id] > rect")];
5421
+ const graph = `${new URLSearchParams(location.search).get("repo") || ""}|${view.components ? "components" : "resources"}`;
5422
+ // The graph itself, its boxes and cards: the marks, the reads' labels and the caption on it change from step to step.
5423
+ // Only the boxes' and the cards' own rects: a card's group also spans its hidden text and tooltips, and anything
5424
+ // else on the page (the reads' labels, the caption, the marks) is drawn over the graph, not part of what it spans.
5425
+ // A card or box grown to hold a cone's lines counts at its own height: the lines grow into the room under the
5426
+ // graph that the framing keeps, so they come and go with no move.
5427
+ const own = (r) => {
5428
+ const b = userBoxOf(svg, r);
5429
+ const h0 = Number(r.getAttribute("data-tg-h0"));
5430
+ const h = Number(r.getAttribute("height"));
5431
+ return b && h0 > 0 && h > 0 ? { ...b, y2: b.y + ((b.y2 - b.y) * h0) / h } : b;
5432
+ };
5433
+ // Only what is drawn: a rect hidden, or with no size on screen, is not part of the graph.
5434
+ const drawn = (r) => {
5435
+ const c = r.getBoundingClientRect();
5436
+ return c.width > 0 && c.height > 0 && !r.closest("[visibility='hidden'], [display='none']") && getComputedStyle(r).visibility !== "hidden";
4555
5437
  };
5438
+ const whole = heldTarget([...svg.querySelectorAll("rect[data-group-id]")].filter(drawn).map(own), rects.filter(drawn).map(own));
5439
+ const cardW = medianWidth(rects.map((r) => {
5440
+ const b = userBoxOf(svg, r);
5441
+ return b ? b.x2 - b.x : 0;
5442
+ }));
5443
+ // A frame the kiosk swapped in (a new pin each step) takes up the framing the last one held.
5444
+ if (!kioskHeld) kioskHeld = readHeld();
5445
+ const held = kioskHeld && kioskHeld.key === graph ? kioskHeld : null;
5446
+ // Only an estate on choudoufu's live backend (the cone scenario's) is held; every other keeps a shot per step, as on main.
5447
+ // behold#736: a story's stage (fan-out-choudoufu, a chapter-carrying scenario, behold#741) is never held: it keeps
5448
+ // the story's own look, its result card, #745's pills and #748's outside mark.
5449
+ if (whole && !tgStoryOn() && holdsStage(tgAnswer && !tgAnswer.error ? tgAnswer.binaries : null) && smallStage(whole, pane, held ? held.insets : docked, cardW)) {
5450
+ kioskHeld = heldFrame(kioskHeld, { key: graph, pane, insets: docked, target: whole });
5451
+ writeHeld(kioskHeld);
5452
+ document.documentElement.classList.add("kiosk-held");
5453
+ // What the framing was made of, for a check from outside: the inputs, and why it last framed again.
5454
+ window.__kioskHeld = () => ({ ...kioskHeld, inputs: { pane: { width: pane.width, height: pane.height }, insets: docked, shot: kioskShot.insets, room: kioskShot.room || 0, cards: rects.length, cardW, target: whole } });
5455
+ return kioskHeld.vb;
5456
+ }
5457
+ kioskHeld = null;
5458
+ document.documentElement.classList.remove("kiosk-held");
4556
5459
  return shotViewBox(kioskShotTarget(svg, kioskShot), pane, insets);
4557
5460
  }
5461
+ /** The whole-graph framing Watch holds on a small stage while the graph and the pane stay (web/kiosk-shot.js heldFrame); null on a bigger one. */
5462
+ var kioskHeld = null;
5463
+ /** Where the held framing is kept for the frame the kiosk swaps in next: this tab's session, same origin as every frame. */
5464
+ var HELD_STORE = "behold.kiosk.held.v3";
5465
+ function readHeld() {
5466
+ try {
5467
+ const h = JSON.parse(sessionStorage.getItem(HELD_STORE) || "null");
5468
+ return h && typeof h.key === "string" && Array.isArray(h.vb) && h.pane && h.insets && h.target ? h : null;
5469
+ } catch {
5470
+ return null;
5471
+ }
5472
+ }
5473
+ function writeHeld(h) {
5474
+ try {
5475
+ sessionStorage.setItem(HELD_STORE, JSON.stringify(h));
5476
+ } catch {
5477
+ /* no storage: this frame still holds its own framing */
5478
+ }
5479
+ }
5480
+
5481
+ /** A shot's insets (the frame's window px) as the graph pane's own: the pane's offset in the window comes off them. */
5482
+ function kioskPaneInsets(shot) {
5483
+ const host = document.getElementById("graph");
5484
+ const i = (shot && shot.insets) || {};
5485
+ if (!host) return { top: 0, right: 0, bottom: 0, left: 0 };
5486
+ const pane = host.getBoundingClientRect();
5487
+ return {
5488
+ top: Math.max(0, (i.top || 0) - pane.top),
5489
+ left: Math.max(0, (i.left || 0) - pane.left),
5490
+ bottom: Math.max(0, (i.bottom || 0) - (window.innerHeight - pane.bottom)),
5491
+ right: Math.max(0, (i.right || 0) - (window.innerWidth - pane.right)),
5492
+ };
5493
+ }
4558
5494
 
4559
5495
  /** Move to the shot: a pan and zoom over its time, or at once (a re-render, a resize, reduced motion). */
4560
5496
  function applyKioskShot(animate) {
@@ -4567,9 +5503,11 @@ function applyKioskShot(animate) {
4567
5503
  return;
4568
5504
  }
4569
5505
  if (sameViewBox(vb, to)) return kioskTellBoxes();
5506
+ // A held small stage lands on its one framing at once: a frame the kiosk swapped in never moves into it on screen.
5507
+ const landing = !!kioskHeld && vbAtFit;
4570
5508
  vbAtFit = false;
4571
5509
  const ms = kioskShot.ms;
4572
- if (!animate || reducedMotion() || !(ms > 0)) {
5510
+ if (!animate || landing || reducedMotion() || !(ms > 0)) {
4573
5511
  if (shotAnim) cancelAnimationFrame(shotAnim.raf);
4574
5512
  shotAnim = null;
4575
5513
  vb = to;
@@ -4635,11 +5573,13 @@ function kioskTellBoxes() {
4635
5573
  }
4636
5574
  }
4637
5575
  // The reads' labels too, which the kiosk's callouts keep clear of.
4638
- const labels = [...svg.querySelectorAll("[data-tg-reads] > g")].map((g) => rect(g.getBoundingClientRect())).filter((r) => r.w > 0);
5576
+ // behold#744: a read's pill only while it shows.
5577
+ const labels = [...svg.querySelectorAll("[data-tg-reads] > g:not([data-tg-read-pill]), [data-tg-reads] > g.tg-flash, [data-tg-reads] > g.tg-hot, [data-tg-reads] > g.tg-shown")].map((g) => rect(g.getBoundingClientRect())).filter((r) => r.w > 0);
4639
5578
  const host = document.getElementById("graph");
4640
5579
  const pane = host ? rect(host.getBoundingClientRect()) : null;
4641
5580
  try {
4642
- window.parent.postMessage({ type: "behold:boxes", waves, roots, labels, pane, moving: !!shotAnim }, embedOpts.host);
5581
+ // held: one framing holds the small stage.
5582
+ window.parent.postMessage({ type: "behold:boxes", waves, roots, labels, pane, moving: !!shotAnim, held: !!kioskHeld }, embedOpts.host);
4643
5583
  } catch {
4644
5584
  /* the parent went away */
4645
5585
  }
@@ -4660,6 +5600,8 @@ function kioskTellDrawn() {
4660
5600
  if (!failed && !(svg && svg.querySelector("[data-node-id]"))) return;
4661
5601
  // The marks: terragucci's reports answered (or refused), or chant's loop has its own.
4662
5602
  if (!failed && terragucciComponentsRepo && !tgAnswer && !chantPrDrawn()) return;
5603
+ // behold#631: a chant repo's loop: its first read of /api/chant/pr, answered or not.
5604
+ if (!failed && !terragucciComponentsRepo && view.components && chantFacets && !staticMode && !chantPrRead) return;
4663
5605
  drawnTold = true;
4664
5606
  try {
4665
5607
  window.parent.postMessage({ type: "behold:drawn", failed }, embedOpts.host);
@@ -4678,6 +5620,7 @@ window.addEventListener("message", (e) => {
4678
5620
  if (shotAnim) cancelAnimationFrame(shotAnim.raf);
4679
5621
  shotAnim = null;
4680
5622
  kioskShot = null;
5623
+ document.documentElement.classList.remove("kiosk-held"); // Inspect: the zoom rail is the viewer's again
4681
5624
  fitGraph();
4682
5625
  return;
4683
5626
  }
@@ -4750,6 +5693,19 @@ function wireKioskFrame() {
4750
5693
  if (e.data && e.data.type === "behold:unpin") return kioskPopEvent({ type: "outside" });
4751
5694
  // behold#571: the kiosk's theme picker moved; follow it here without a reload.
4752
5695
  if (e.data && e.data.type === "behold:theme" && typeof e.data.name === "string") return void setTheme(e.data.name, { persist: false });
5696
+ // behold#741: the scenario carries chapters (or stopped carrying them): the kiosk's look, and the wave blocks, follow.
5697
+ if (e.data && e.data.type === "behold:story") {
5698
+ const on = e.data.on === true;
5699
+ const cycle = Number.isInteger(e.data.cycle) ? e.data.cycle : null;
5700
+ const was = tgStoryOn();
5701
+ // behold#743: the step's apply made outside the pipeline, or null; a change redraws the marks.
5702
+ const outside = e.data.outside && typeof e.data.outside === "object" && typeof e.data.outside.estate === "string" ? e.data.outside : null;
5703
+ const outsideMoved = JSON.stringify(outside) !== JSON.stringify((tgStory && tgStory.outside) || null);
5704
+ tgStory = { on, cycle, outside };
5705
+ if (tgStoryOn() !== was && view.components && terragucciComponentsRepo) load({ quiet: true });
5706
+ else if (outsideMoved && tgStoryOn()) drawTgReads();
5707
+ return;
5708
+ }
4753
5709
  const h = hoverFromMessage(e.data);
4754
5710
  if (h === undefined) return;
4755
5711
  kioskHostHover = h;
@@ -4971,6 +5927,320 @@ function approveFromLane(key, env, btn) {
4971
5927
  }
4972
5928
  initTrunkLane();
4973
5929
 
5930
+ // --- #683: feature flags, on or off per environment ---------------------------
5931
+ // The Flags tab reads /api/workspace/flags when it is opened: each flag of the
5932
+ // workspace with its owner, work item and value per environment, a flip
5933
+ // waiting at a gate as the link that opens that gate's change set (#681), and
5934
+ // otherwise the lines a person runs to turn it on. behold changes no flag. The
5935
+ // tab picks an environment, and every card of a flagged member gets a tag under
5936
+ // it, since chant names no node that reads a build parameter.
5937
+ let flAnswer = null;
5938
+ let flOn = true;
5939
+ let flEnv = null;
5940
+ let flHost = null;
5941
+ let flRead = false;
5942
+ async function initFlags() {
5943
+ if (staticMode || publicMode) return; // /api/workspace/* is refused in a public view
5944
+ const project = await apiFetch("/api/project").then((r) => r.json()).catch(() => ({}));
5945
+ if (!project.workspace) return;
5946
+ flHost = addPanelTab("flags", "Flags", "The workspace's feature flags, on or off per environment, with their owner and work item. Read from chant when you open the tab.");
5947
+ if (!flHost) return;
5948
+ flHost.id = "tab-flags";
5949
+ const tab = document.querySelector('#panel-tabs button[data-tab="flags"]');
5950
+ if (tab) tab.addEventListener("click", () => flRead || loadFlags());
5951
+ if (flHost.classList.contains("active")) loadFlags();
5952
+ }
5953
+ async function loadFlags() {
5954
+ flRead = true;
5955
+ const reading = document.createElement("div");
5956
+ reading.className = "tg-legend";
5957
+ reading.textContent = "reading the flags from chant";
5958
+ flHost.replaceChildren(reading);
5959
+ flAnswer = await apiFetch("/api/workspace/flags")
5960
+ .then((r) => r.json())
5961
+ .catch((e) => ({ error: String(e) }));
5962
+ flEnv = flPickEnv(flAnswer, flEnv || view.env);
5963
+ markFlagCards();
5964
+ }
5965
+ function markFlagCards() {
5966
+ const svg = document.querySelector("#graph svg");
5967
+ if (svg) {
5968
+ for (const old of svg.querySelectorAll("[data-fl-mark]")) old.remove();
5969
+ if (flAnswer && flOn) {
5970
+ const ids = [...svg.querySelectorAll("[data-node-id]")].map((g) => g.getAttribute("data-node-id"));
5971
+ for (const [id, m] of Object.entries(flFlagMarks(flAnswer, flEnv, ids, nodeMember))) {
5972
+ const g = svg.querySelector('[data-node-id="' + CSS.escape(id) + '"]');
5973
+ if (!g) continue;
5974
+ const rect = g.querySelector("rect");
5975
+ const box = rect && rect.getBBox ? rect.getBBox() : { x: 0, y: 0, width: 150, height: 60 };
5976
+ const tag = document.createElementNS("http://www.w3.org/2000/svg", "text");
5977
+ tag.setAttribute("data-fl-mark", "tag");
5978
+ tag.setAttribute("x", String(box.x));
5979
+ tag.setAttribute("y", String(box.y + box.height + 13));
5980
+ tag.setAttribute("font-size", "11");
5981
+ tag.setAttribute("font-weight", "700");
5982
+ tag.setAttribute("fill", m.stale ? FL_STALE_COLOR : m.color);
5983
+ tag.textContent = m.tag;
5984
+ const title = document.createElementNS("http://www.w3.org/2000/svg", "title");
5985
+ title.setAttribute("data-fl-mark", "title");
5986
+ title.textContent = m.title;
5987
+ tag.appendChild(title);
5988
+ g.append(tag);
5989
+ }
5990
+ }
5991
+ }
5992
+ renderFlagsTab();
5993
+ }
5994
+ function renderFlagsTab() {
5995
+ if (!flHost) return;
5996
+ flHost.replaceChildren();
5997
+ const line = (cls, text, title, host = flHost) => {
5998
+ const d = document.createElement("div");
5999
+ d.className = cls;
6000
+ d.textContent = text;
6001
+ if (title) d.title = title;
6002
+ host.appendChild(d);
6003
+ return d;
6004
+ };
6005
+ const h = flHeader(flAnswer);
6006
+ line(h.tone === "refusal" ? "tg-refusal" : "fl-title", h.text, h.title);
6007
+ const refused = !flAnswer || flAnswer.error || flAnswer.refusal;
6008
+ if (refused && flAnswer && flAnswer.degraded) line("tg-legend", `Without it, ${flAnswer.degraded}.`);
6009
+ if (!refused) {
6010
+ line("tg-legend", FL_NODES_NOTE);
6011
+ if (flAnswer.environments.length) {
6012
+ const pick = document.createElement("div");
6013
+ pick.className = "fl-envs";
6014
+ const label = document.createElement("span");
6015
+ label.textContent = "on the graph in";
6016
+ pick.appendChild(label);
6017
+ for (const env of flAnswer.environments) {
6018
+ const b = button(env, env === flEnv ? "fl-env on" : "fl-env", () => {
6019
+ flEnv = env;
6020
+ markFlagCards();
6021
+ });
6022
+ b.setAttribute("aria-pressed", String(env === flEnv));
6023
+ b.title = `Mark each flagged card with its flags' values in ${env}.`;
6024
+ pick.appendChild(b);
6025
+ }
6026
+ flHost.appendChild(pick);
6027
+ }
6028
+ for (const g of flGapLines(flAnswer)) line("tg-refusal", g.text, g.title);
6029
+ const toggle = button(flOn ? "Turn off the marks" : "Turn on the marks", "", () => {
6030
+ flOn = !flOn;
6031
+ markFlagCards();
6032
+ });
6033
+ toggle.title = flOn ? "Remove the flag marks from the graph. The tab keeps the flags." : "Mark the flagged cards on the graph again.";
6034
+ flHost.appendChild(toggle);
6035
+ if (!flAnswer.flags.length) line("tg-legend", "no member has a feature flag");
6036
+ for (const f of flAnswer.flags) {
6037
+ const r = flFlagRow(f, flEnv);
6038
+ const box = document.createElement("div");
6039
+ box.className = "fl-flag";
6040
+ const title = line("fl-flag-title", r.title, r.path, box);
6041
+ if (r.stale) {
6042
+ const s = document.createElement("span");
6043
+ s.className = "fl-stale";
6044
+ s.textContent = ` · ${r.stale.text}`;
6045
+ s.title = r.stale.title;
6046
+ title.appendChild(s);
6047
+ }
6048
+ line("fl-facts", r.facts, "", box);
6049
+ const values = document.createElement("div");
6050
+ values.className = "fl-values";
6051
+ for (const v of r.values) {
6052
+ const span = document.createElement("span");
6053
+ span.className = v.current ? "fl-value current" : "fl-value";
6054
+ span.style.setProperty("--dot", v.color);
6055
+ span.textContent = v.text;
6056
+ values.appendChild(span);
6057
+ }
6058
+ box.appendChild(values);
6059
+ for (const w of r.waiting) {
6060
+ const d = line("fl-waiting", `${w.text} · `, "", box);
6061
+ const a = document.createElement("a");
6062
+ a.href = "#";
6063
+ a.className = "lane-change-set";
6064
+ a.textContent = w.link;
6065
+ a.title = w.title;
6066
+ a.addEventListener("click", (ev) => {
6067
+ ev.preventDefault();
6068
+ openChangeSet(w.gate, w.env);
6069
+ });
6070
+ d.appendChild(a);
6071
+ }
6072
+ for (const t of r.turnOn) {
6073
+ line("fl-turn-on", t.head, FL_TURN_ON_NOTE, box);
6074
+ const pre = document.createElement("pre");
6075
+ pre.className = "fl-lines";
6076
+ pre.textContent = t.lines.join("\n");
6077
+ pre.title = FL_TURN_ON_NOTE;
6078
+ box.appendChild(pre);
6079
+ }
6080
+ flHost.appendChild(box);
6081
+ }
6082
+ if (flAnswer.flags.some((f) => f.turnOn.length)) line("tg-legend", FL_TURN_ON_NOTE);
6083
+ }
6084
+ if (!staticMode) {
6085
+ const again = button("Read again", "", () => loadFlags());
6086
+ again.title = "Read the flags and every environment's gates from chant again.";
6087
+ flHost.appendChild(again);
6088
+ }
6089
+ }
6090
+ initFlags();
6091
+
6092
+ // --- #684: collision marks, nodes touched by two in-flight work items --------
6093
+ // The Collisions tab reads /api/workspace/collisions when it is opened: the
6094
+ // in-flight work items chant reports (workspace status overlap, chant#4025),
6095
+ // the nodes two of them reach through a waiting gate's change set (a ring and
6096
+ // a tag on each card), and on the side the files they both changed, which
6097
+ // have no node. The filter keeps only colliding work: the other cards and the
6098
+ // edges that touch them are hidden. behold records and locks nothing.
6099
+ let coAnswer = null;
6100
+ let coOn = true;
6101
+ let coOnly = false;
6102
+ let coHost = null;
6103
+ let coRead = false;
6104
+ async function initCollisions() {
6105
+ if (staticMode || publicMode) return; // /api/workspace/* is refused in a public view
6106
+ const project = await apiFetch("/api/project").then((r) => r.json()).catch(() => ({}));
6107
+ if (!project.workspace) return;
6108
+ coHost = addPanelTab("collisions", "Collisions", "In-flight work items that touch the same resource, marked on the graph. Read from chant when you open the tab.");
6109
+ if (!coHost) return;
6110
+ coHost.id = "tab-collisions";
6111
+ const tab = document.querySelector('#panel-tabs button[data-tab="collisions"]');
6112
+ if (tab) tab.addEventListener("click", () => coRead || loadCollisions());
6113
+ if (coHost.classList.contains("active")) loadCollisions();
6114
+ }
6115
+ async function loadCollisions() {
6116
+ coRead = true;
6117
+ const reading = document.createElement("div");
6118
+ reading.className = "tg-legend";
6119
+ reading.textContent = "reading the work overlap from chant";
6120
+ coHost.replaceChildren(reading);
6121
+ coAnswer = await apiFetch("/api/workspace/collisions")
6122
+ .then((r) => r.json())
6123
+ .catch((e) => ({ error: String(e) }));
6124
+ markCollisionCards();
6125
+ }
6126
+ function markCollisionCards() {
6127
+ const svg = document.querySelector("#graph svg");
6128
+ if (svg) {
6129
+ for (const old of svg.querySelectorAll("[data-co-mark]")) old.remove();
6130
+ for (const h of svg.querySelectorAll("[data-co-hidden]")) {
6131
+ h.removeAttribute("data-co-hidden");
6132
+ h.style.display = "";
6133
+ }
6134
+ if (coAnswer && coOn) {
6135
+ const ids = [...svg.querySelectorAll("[data-node-id]")].map((g) => g.getAttribute("data-node-id"));
6136
+ for (const [id, m] of Object.entries(coMarks(coAnswer, ids))) {
6137
+ const g = svg.querySelector('[data-node-id="' + CSS.escape(id) + '"]');
6138
+ if (!g) continue;
6139
+ const rect = g.querySelector("rect");
6140
+ const box = rect && rect.getBBox ? rect.getBBox() : { x: 0, y: 0, width: 150, height: 60 };
6141
+ const ring = document.createElementNS("http://www.w3.org/2000/svg", "rect");
6142
+ ring.setAttribute("data-co-mark", "ring");
6143
+ ring.setAttribute("x", String(box.x - 3));
6144
+ ring.setAttribute("y", String(box.y - 3));
6145
+ ring.setAttribute("width", String(box.width + 6));
6146
+ ring.setAttribute("height", String(box.height + 6));
6147
+ ring.setAttribute("rx", "8");
6148
+ ring.setAttribute("fill", "none");
6149
+ ring.setAttribute("stroke", m.color);
6150
+ ring.setAttribute("stroke-width", "2");
6151
+ ring.setAttribute("stroke-dasharray", "5 3");
6152
+ ring.setAttribute("pointer-events", "none");
6153
+ const tag = document.createElementNS("http://www.w3.org/2000/svg", "text");
6154
+ tag.setAttribute("data-co-mark", "tag");
6155
+ tag.setAttribute("x", String(box.x));
6156
+ tag.setAttribute("y", String(box.y + box.height + 26));
6157
+ tag.setAttribute("font-size", "11");
6158
+ tag.setAttribute("font-weight", "700");
6159
+ tag.setAttribute("fill", m.color);
6160
+ tag.textContent = m.tag;
6161
+ const title = document.createElementNS("http://www.w3.org/2000/svg", "title");
6162
+ title.setAttribute("data-co-mark", "title");
6163
+ title.textContent = m.title;
6164
+ tag.appendChild(title);
6165
+ g.append(ring, tag);
6166
+ }
6167
+ if (coOnly) {
6168
+ for (const id of coFilter(coAnswer, ids, true).hide) {
6169
+ const g = svg.querySelector('[data-node-id="' + CSS.escape(id) + '"]');
6170
+ if (g) {
6171
+ g.setAttribute("data-co-hidden", "true");
6172
+ g.style.display = "none";
6173
+ }
6174
+ }
6175
+ for (const e of svg.querySelectorAll("g[data-edge-from]")) {
6176
+ if (!coHideEdge(coAnswer, e.getAttribute("data-edge-from"), e.getAttribute("data-edge-to"), true)) continue;
6177
+ e.setAttribute("data-co-hidden", "true");
6178
+ e.style.display = "none";
6179
+ }
6180
+ }
6181
+ }
6182
+ }
6183
+ renderCollisionsTab();
6184
+ }
6185
+ function renderCollisionsTab() {
6186
+ if (!coHost) return;
6187
+ coHost.replaceChildren();
6188
+ const line = (cls, text, title, host = coHost) => {
6189
+ const d = document.createElement("div");
6190
+ d.className = cls;
6191
+ d.textContent = text;
6192
+ if (title) d.title = title;
6193
+ host.appendChild(d);
6194
+ return d;
6195
+ };
6196
+ const h = coHeader(coAnswer);
6197
+ line(h.tone === "refusal" ? "tg-refusal" : "fl-title", h.text, h.title);
6198
+ const refused = !coAnswer || coAnswer.error || coAnswer.refusal;
6199
+ if (refused && coAnswer && coAnswer.degraded) line("tg-legend", `Without it, ${coAnswer.degraded}.`);
6200
+ if (!refused) {
6201
+ for (const g of coGapLines(coAnswer)) line("tg-legend", g.text, g.title);
6202
+ const filter = button(coOnly ? CO_FILTER_ON : CO_FILTER_OFF, "", () => {
6203
+ coOnly = !coOnly;
6204
+ markCollisionCards();
6205
+ });
6206
+ filter.setAttribute("aria-pressed", String(coOnly));
6207
+ filter.title = coOnly ? "Draw every card and every work item again." : "Hide the cards that no two work items touch, and the work items that collide with none.";
6208
+ coHost.appendChild(filter);
6209
+ const toggle = button(coOn ? "Turn off the marks" : "Turn on the marks", "", () => {
6210
+ coOn = !coOn;
6211
+ markCollisionCards();
6212
+ });
6213
+ toggle.title = coOn ? "Remove the collision marks from the graph. The tab keeps the work items." : "Mark the colliding cards on the graph again.";
6214
+ coHost.appendChild(toggle);
6215
+ const ids = [...document.querySelectorAll("#graph svg [data-node-id]")].map((g) => g.getAttribute("data-node-id"));
6216
+ const shown = coFilter(coAnswer, ids, coOnly);
6217
+ if (shown.nodes.length) {
6218
+ line("fl-title", "nodes touched by two or more work items", CO_NOTE);
6219
+ for (const n of shown.nodes.map(coNodeRow)) line("fl-facts", n.text, n.title);
6220
+ }
6221
+ const side = coSideLines(coAnswer);
6222
+ if (side.length) {
6223
+ line("fl-title", "no graph node", CO_FILES_NOTE);
6224
+ for (const s of side) line("fl-facts", s.text, s.title);
6225
+ }
6226
+ if (!shown.items.length) line("tg-legend", coOnly ? "no work item collides with another" : "no in-flight work item has a linked commit");
6227
+ for (const i of shown.items.map(coItemRow)) {
6228
+ const box = document.createElement("div");
6229
+ box.className = "fl-flag";
6230
+ line("fl-flag-title", i.title, "", box);
6231
+ line("fl-facts", i.facts, "", box);
6232
+ line(i.colliding ? "fl-stale" : "fl-facts", i.with, "", box);
6233
+ coHost.appendChild(box);
6234
+ }
6235
+ }
6236
+ if (!staticMode) {
6237
+ const again = button("Read again", "", () => loadCollisions());
6238
+ again.title = "Read the work overlap from chant again.";
6239
+ coHost.appendChild(again);
6240
+ }
6241
+ }
6242
+ initCollisions();
6243
+
4974
6244
  // --- #681: a waiting gate's change set, on the graph -------------------------
4975
6245
  // Opened from a gate card's "change set" link in the Trunk tab. The server
4976
6246
  // reads the gate from status and the stored change set from chant change-set
@@ -5418,23 +6688,117 @@ let ciForge = null; // the forge the pipeline was generated for (#164) — heads
5418
6688
  // (`meta.terragucciComponents`, see takeTerragucciFacets), which a public view
5419
6689
  // can read, so the two facet fetches below are skipped.
5420
6690
  let terragucciComponentsRepo = false;
6691
+ /**
6692
+ * behold#741: the kiosk's word that the scenario it shows carries chapters (demo.json's step `chapter`), with the
6693
+ * cycle: `{ on, cycle }` from a `behold:story` message, null until one comes. Only a kiosk frame (bare) of a
6694
+ * terragucci repo's components zoom acts on it; b-waves, failure and tg-planned-outputs send `on: false`.
6695
+ * behold#743: `outside` too, the step's apply made outside the pipeline (demo.json's), or null.
6696
+ */
6697
+ let tgStory = null;
6698
+ function tgStoryOn() {
6699
+ return !!(embedOpts.bare && tgStory && tgStory.on && terragucciComponentsRepo);
6700
+ }
6701
+ // behold#741: what landed in this cycle's earlier apply, and what its failure left, for the next pull request's cards.
6702
+ let tgStoryEarlier = { cycle: null, earlier: new Set(), lastStates: {} };
6703
+ function tgStoryMarks() {
6704
+ if (!tgStoryOn() || !view.components) return null;
6705
+ if (tgStoryEarlier.cycle !== tgStory.cycle || view.run === "base") tgStoryEarlier = { cycle: tgStory.cycle, earlier: new Set(), lastStates: {} };
6706
+ return { kiosk: true, earlier: tgStoryEarlier.earlier, lastStates: tgStoryEarlier.lastStates };
6707
+ }
6708
+ /** Keep what an apply's cards say: applied roots land in `earlier`; a failed or blocked one keeps that state until it applies. */
6709
+ function tgStoryRemember(marks) {
6710
+ if (!marks || marks.stage !== "apply") return;
6711
+ for (const c of Object.values(marks.cards)) {
6712
+ if (c.state === "applied") {
6713
+ tgStoryEarlier.earlier.add(c.root);
6714
+ delete tgStoryEarlier.lastStates[c.root];
6715
+ } else if (c.state === "failed" || c.state === "blocked") tgStoryEarlier.lastStates[c.root] = { state: c.state, words: c.words, ...(c.blockedBy ? { blockedBy: c.blockedBy } : {}) };
6716
+ }
6717
+ }
6718
+ // behold#741: the run view's waves at the pace chant's are played (web/terragucci-live-pace.js), while the story is on.
6719
+ const tgPacer = createProgressPacer();
6720
+ let tgPaceTimer = null;
6721
+ function tgPacedProgress() {
6722
+ const p = tgPacer.progress(tgProgress);
6723
+ if (tgPacer.pending && !tgPaceTimer) {
6724
+ let was = JSON.stringify(p && p.states);
6725
+ tgPaceTimer = setInterval(() => {
6726
+ const next = tgPacer.progress(tgProgress);
6727
+ const now = JSON.stringify(next && next.states);
6728
+ if (now !== was) {
6729
+ was = now;
6730
+ drawTgReads();
6731
+ }
6732
+ if (!tgPacer.pending) {
6733
+ clearInterval(tgPaceTimer);
6734
+ tgPaceTimer = null;
6735
+ }
6736
+ }, 400);
6737
+ }
6738
+ return p;
6739
+ }
5421
6740
  // #571: the components graph's facets (jobs, component -> root), for the live marks drawTgReads puts on it.
5422
6741
  let tgComponentFacets = null;
5423
6742
  // behold#631: a chant repo's pull-request loop: the graph's `meta.chantPr` and /api/chant/pr's answer at the view's run pin.
5424
6743
  let chantFacets = null;
5425
6744
  let chantPrAnswer = null;
5426
6745
  let chantPrTimer = null;
6746
+ /** Whether /api/chant/pr has answered (or failed) once since the components view drew, so a kiosk frame swaps in with its marks on. */
6747
+ let chantPrRead = false;
6748
+ // behold#631: a fast apply played at a pace a viewer can follow (web/chant-live-pace.js).
6749
+ const chantPacer = createLivePacer();
6750
+ let chantPaceTimer = null;
6751
+ let chantPacedWas = null;
6752
+ /** The answer as the pacer shows it now; while it is behind the stream, redraw as it plays. */
6753
+ function chantPaced() {
6754
+ const a = chantPacer.answer(chantPrAnswer);
6755
+ chantPacedWas = JSON.stringify(a && a.live ? a.live.apply : null);
6756
+ if (chantPacer.pending && !chantPaceTimer) {
6757
+ chantPaceTimer = setInterval(() => {
6758
+ const next = chantPacer.answer(chantPrAnswer);
6759
+ const was = chantPacedWas;
6760
+ if (JSON.stringify(next && next.live ? next.live.apply : null) !== was) drawTgReads();
6761
+ if (!chantPacer.pending) {
6762
+ clearInterval(chantPaceTimer);
6763
+ chantPaceTimer = null;
6764
+ }
6765
+ }, 400);
6766
+ }
6767
+ return a;
6768
+ }
5427
6769
  function chantPrDrawn() {
5428
6770
  return !!(view.components && chantFacets && !terragucciComponentsRepo && chantPrAnswer && !chantPrAnswer.error && chantPrAnswer.loop);
5429
6771
  }
5430
6772
  async function loadChantPr() {
5431
6773
  const pin = view.run || "";
5432
6774
  const was = JSON.stringify(chantPrAnswer);
5433
- const answer = await apiFetch(`/api/chant/pr${pin ? `?pin=${encodeURIComponent(pin)}` : ""}`)
6775
+ let answer = await apiFetch(`/api/chant/pr${pin ? `?pin=${encodeURIComponent(pin)}` : ""}`)
5434
6776
  .then((r) => (r.ok ? r.json() : null))
5435
6777
  .catch(() => null);
5436
6778
  if ((view.run || "") !== pin) return; // the pin moved while this read ran
6779
+ // behold#631: at the merge, before the apply's run is listed, the merge commit names no pull request yet and the
6780
+ // answer comes back empty: the cards keep the plan they had until the apply's own records replace it.
6781
+ const nothing = (a) => a && !a.error && !a.plan && !a.apply && !a.running && !(a.live && (a.live.apply || a.live.plan));
6782
+ if (nothing(answer) && chantPrAnswer && chantPrAnswer.plan && pin && pin !== "base" && pin !== "none" && !/^pull/.test(pin)) answer = { ...answer, pull: chantPrAnswer.pull, plan: chantPrAnswer.plan, gate: chantPrAnswer.gate, ...(chantPrAnswer.live ? { live: { ...chantPrAnswer.live, apply: null, plan: null } } : {}), carried: true };
6783
+ // behold#631: a new pull request of the cycle (the fix) that has no plan yet: its cards keep what they were.
6784
+ // What landed reads applied earlier; a failed or blocked card keeps that state until the fix's plan says otherwise.
6785
+ const noPlanYet = (a) => a && !a.error && !a.plan && !a.apply && !(a.live && (a.live.apply || a.live.plan));
6786
+ if (noPlanYet(answer) && /^pull/.test(pin) && chantPrAnswer && chantFacets) {
6787
+ const prev = chantPrAnswer;
6788
+ let lastStates = prev.lastStates && prev.pull === answer.pull ? prev.lastStates : null;
6789
+ let landed = new Set(prev.live && prev.live.earlier ? prev.live.earlier.applied : []);
6790
+ if (!lastStates && (prev.plan || (prev.live && prev.live.apply)) && prev.pull !== answer.pull) {
6791
+ const cards = chantComponentMarks(chantPacer.answer(prev), chantFacets).cards;
6792
+ lastStates = {};
6793
+ for (const [c, m] of Object.entries(cards)) {
6794
+ if (m.state === "failed" || m.state === "blocked") lastStates[c] = m.state;
6795
+ else if (m.state === "applied" || m.state === "already-applied" || m.state === "applied-earlier") landed.add(c);
6796
+ }
6797
+ }
6798
+ if (lastStates) answer = { ...answer, lastStates, live: { ...(answer.live || { reportUrl: null, via: "pipeline" }), plan: null, apply: null, earlier: { runs: (answer.live && answer.live.earlier && answer.live.earlier.runs) || [], applied: [...new Set([...landed, ...((answer.live && answer.live.earlier && answer.live.earlier.applied) || [])])] } } };
6799
+ }
5437
6800
  chantPrAnswer = answer;
6801
+ chantPrRead = true;
5438
6802
  if (JSON.stringify(answer) !== was) drawTgReads();
5439
6803
  }
5440
6804
  /** Read the loop every few seconds while a chant repo's components view is on screen. */
@@ -6146,7 +7510,8 @@ function wireEdgeHighlight(svgEl, ir) {
6146
7510
  title.textContent = edgeTitle(from, to, { kind, via, cross });
6147
7511
  g.insertBefore(title, g.firstChild);
6148
7512
  }
6149
- const raise = (g) => g.parentNode && g.parentNode.appendChild(g);
7513
+ // behold#744: raised under the terragucci reads' layer, whose lines and pills stay over every edge.
7514
+ const raise = (g) => g.parentNode && g.parentNode.insertBefore(g, g.parentNode.querySelector(":scope > [data-tg-reads]"));
6150
7515
  // Delegated: raise whichever edge the pointer is over (its hit-path catches it).
6151
7516
  svgEl.addEventListener("mouseover", (e) => {
6152
7517
  const g = e.target.closest && e.target.closest("g[data-edge-from]");
@@ -6587,10 +7952,16 @@ function drawPipelineMarks(svgEl) {
6587
7952
  const light = kioskLight();
6588
7953
  const pin = view.run || null;
6589
7954
  const commit = tgRunsCommit(pin, tgProgress);
7955
+ // behold#631: on a kiosk, a chant repo's forge and tool are named once, with their logos, in the kiosk's title line:
7956
+ // the wave boxes carry no marks of their own there. Inspect keeps them.
7957
+ const chantKiosk = !!(embedOpts.bare && view.components && chantFacets && !terragucciComponentsRepo);
7958
+ if (chantKiosk) return;
7959
+ const onlyWave = null;
6590
7960
  for (const rect of svgEl.querySelectorAll("rect[data-group-id]")) {
6591
7961
  const key = rect.getAttribute("data-group-id");
6592
7962
  const n = tgWaveOfKey(key);
6593
7963
  if (n === null) continue;
7964
+ if (onlyWave !== null && n !== onlyWave) continue;
6594
7965
  const what = pipelineMarksFor(n);
6595
7966
  if (!what) continue;
6596
7967
  const forge = what.forge && FORGES[what.forge] ? what.forge : null;
@@ -6799,6 +8170,8 @@ function render(ir, svg, m) {
6799
8170
  markTerragucciCards(); // #490: and what terragucci's reports found, dated
6800
8171
  markYodelCards(); // #526: and SQL Yodeler's drift, dated
6801
8172
  if (csAnswer) markChangeSetCards(); // #681: and the change set a gate binds, as a preview
8173
+ if (flAnswer) markFlagCards(); // #683: and the feature flags of each flagged member
8174
+ if (coAnswer) markCollisionCards(); // #684: and the nodes two in-flight work items touch
6802
8175
  applyLayout(); // #228: last, so the hand-placed deltas ride on top of every other pass
6803
8176
  drawTgReads(); // #568: after the layout, so the reads lines meet the cards where they now sit
6804
8177
  renderDial();
@@ -7894,6 +9267,12 @@ async function loadOnce(opts = {}, isCurrent = () => true) {
7894
9267
  // cross-substrate entity overlay, which components never use.
7895
9268
  q.set("components", "1");
7896
9269
  if (view.env) q.set("env", view.env);
9270
+ // behold#741: a chapter-carrying scenario's fan-out wave as one block per parent, as chant's loop lays it out.
9271
+ if (tgStoryOn()) q.set("blocks", "1");
9272
+ // The kiosk's frame of a choudoufu estate (the held small stage): its waves in a row, wave 1 on the left, so
9273
+ // the graph's shape is the stage's and the held framing can zoom in as far as the width allows. A story's
9274
+ // fan-out (fan-out-choudoufu) keeps its blocks.
9275
+ else if (embedOpts.bare && projectInfo && projectInfo.terragucciChoudoufu) q.set("waves", "row");
7897
9276
  } else if (view.stacks) {
7898
9277
  // The apply-order lens (#426): chant's cross-stack ordering, built fresh
7899
9278
  // for the same reason the ops lens is — it reads none of the entity