@intentius/behold 0.29.48 → 0.29.50

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/web/kiosk.html CHANGED
@@ -115,6 +115,7 @@
115
115
  .r-head-title .r-icon { margin: 0; }
116
116
  .r-head-sub { color: var(--fg); font-size: 0.88em; margin-top: 0.15em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
117
117
  .r-head-meta { color: var(--muted); font-size: 0.82em; }
118
+ .r-head-meta .r-origin { color: inherit; }
118
119
  /* behold#725: a section heading (Jobs, Features, Steps) keeps a line of its own: the pane is a flex column, and nothing in it but the steps may shrink. */
119
120
  .r-label { display: block; flex: none; position: static; font: 600 0.8em/1.3 var(--font-ui); color: var(--muted); padding: var(--s3) var(--s4) var(--s1); }
120
121
  #runs-main > :not(.r-steps) { flex: none; }
@@ -488,7 +489,22 @@
488
489
  .k-modes { height: auto; }
489
490
  .k-theme-arrow { min-width: 44px; }
490
491
  .k-w-held { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s2) var(--s3); flex: 1 1 100%; }
491
- .k-w-held button.k-w-resume { min-height: 44px; padding: 0 var(--s5); border: 2px solid var(--pending); border-radius: 999px; background: color-mix(in srgb, var(--pending) 18%, transparent); text-decoration: none; font-weight: 600; }
492
+ .k-w-held button.k-w-resume, #k-held-over button.k-w-resume { min-height: 44px; padding: 0 var(--s5); border: 2px solid var(--pending); border-radius: 999px; background: color-mix(in srgb, var(--pending) 18%, transparent); text-decoration: none; font-weight: 600; }
493
+ body.k-watch #k-held-over:not([hidden]) { position: fixed; bottom: calc(12px + env(safe-area-inset-bottom, 0px)); left: 12px; right: 12px; z-index: 40; display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--s2) var(--s3); padding: var(--s2) var(--s3); border: 2px solid var(--pending); border-radius: 10px; background: color-mix(in srgb, var(--panel) 94%, transparent); box-shadow: 0 2px 10px rgb(0 0 0 / 0.25); color: var(--fg); font-weight: 600; }
494
+ }
495
+ #k-held-over { display: none; }
496
+ .k-w-point { display: none; }
497
+ /* A phone's Watch says what it shows first and once: the point, the step track, one "Now:" line, the graph.
498
+ The intro, the waiting box and the caption's copy of the point repeat it; the facts under the graph fold. */
499
+ @media (max-width: 600px) {
500
+ body.k-watch .k-w-point { display: block; margin: 0.2em 0 0.1em; font: 700 1.2em/1.25 var(--font-ui); color: var(--fg); }
501
+ body.k-watch .k-w-intro, body.k-watch .k-cap-point, body.k-watch .k-cap-next, body.k-watch .k-cap-step { display: none; }
502
+ body.k-watch .eh-modal-wrap:has(> .eh-modal-waiting) { display: none; }
503
+ body.k-watch #k-change > .k-change-label, body.k-watch #k-waves > .k-wl-head { cursor: pointer; min-height: 44px; display: flex; align-items: center; gap: var(--s3); }
504
+ body.k-watch #k-change:not(.k-open) > :not(.k-change-label), body.k-watch #k-waves:not(.k-open) > :not(.k-wl-head) { display: none; }
505
+ body.k-watch #k-change .k-change-label::after, body.k-watch #k-waves .k-wl-title::after { content: " · show"; color: var(--pending); font-weight: 500; }
506
+ body.k-watch #k-change.k-open .k-change-label::after, body.k-watch #k-waves.k-open .k-wl-title::after { content: " · hide"; }
507
+ body.k-watch #k-waves:not(.k-open) .k-wl-hint { display: none; }
492
508
  }
493
509
  /* The caption: the title, what changes, the step. One of the two beats leads. */
494
510
  #k-caption { position: absolute; left: 5px; right: 5px; bottom: 5px; display: grid; grid-template-rows: auto calc(2 * 1.25em * 1.3) calc(2 * 1.25em * 1.3); gap: 0.25em; padding: var(--s3) 1.4em var(--s4);
@@ -616,6 +632,13 @@
616
632
  .k-wf-sw { display: inline-block; width: 1.2em; height: 0.55em; border-radius: 2px; }
617
633
  .k-result-head { margin: 0 0 0.2em; font: 700 1.5em var(--font-ui); color: var(--managed); }
618
634
  .k-result-counts { list-style: none; margin: 0 0 var(--s3); padding: 0; display: flex; flex-wrap: wrap; gap: var(--s1) var(--s2); }
635
+ /* behold#787: the done card's chip that replays the failure, and the banner of a replay the viewer asked for with its way back. */
636
+ .k-result-replay, .k-replay-back { font: 600 0.95em var(--font-ui); color: var(--pending); background: color-mix(in srgb, var(--pending) 16%, transparent); border: 2px solid var(--pending); border-radius: 999px; padding: 0.25em var(--s4); cursor: pointer; }
637
+ .k-result-replay { margin-top: var(--s3); color: var(--degraded); border-color: var(--degraded); background: color-mix(in srgb, var(--degraded) 12%, transparent); }
638
+ .k-result-replay:focus-visible, .k-replay-back:focus-visible { outline: 2px solid var(--fg); outline-offset: 2px; }
639
+ .k-replay.k-replay-asked { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s2) var(--s4); padding-right: var(--s3); white-space: normal; border-left-color: var(--pending); }
640
+ body.k-watch #bar > .k-replay-asked { flex: 1 1 100%; }
641
+ @media (pointer: coarse), (max-width: 600px) { .k-result-replay, .k-replay-back { min-height: 44px; padding: 0 var(--s5); } }
619
642
  .k-result-counts li { padding: 0.15em var(--s3); border-radius: 999px; background: var(--surface-box); border: 1px solid var(--rule); font-size: 0.95em; font-variant-numeric: tabular-nums; }
620
643
  .k-result-counts li:first-child { border-color: var(--managed); font-weight: 600; }
621
644
  .k-result-waves { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 0.2em var(--s4); margin: 0; padding-top: var(--s2); border-top: 1px solid var(--rule); }
@@ -734,6 +757,8 @@
734
757
  <div id="views" hidden></div>
735
758
  <section id="k-read" aria-label="How to read this" hidden></section>
736
759
  <iframe id="view" title="behold's view of the change"></iframe>
760
+ <!-- A paused Watch says so at the foot of the screen: on a phone the header that also says it is scrolled away. -->
761
+ <div id="k-held-over" role="status" hidden></div>
737
762
  </section>
738
763
  <!-- behold#571: Watch mode's overlays, over the graph; web/kiosk-watch.js says what each holds and where it goes. -->
739
764
  <div id="k-watch">
@@ -758,9 +783,14 @@
758
783
  <div id="eh-modals"></div>
759
784
  <script type="module">
760
785
  import { initTheme, KIOSK_THEME, getThemeName, onThemeChange, stepTheme } from "/theme.js";
786
+ // A phone's facts under the graph fold to their heads; a tap on a head opens or folds them (the class outlives a redraw).
787
+ document.addEventListener("click", (e) => {
788
+ const head = e.target.closest && e.target.closest("#k-change > .k-change-label, #k-waves > .k-wl-head");
789
+ if (head) head.parentElement.classList.toggle("k-open");
790
+ });
761
791
  import { startKiosk } from "/kiosk.js";
762
792
  import { pageTool } from "/kiosk-vendor.js";
763
- import { pageSource, readsFor } from "/kiosk-source.js";
793
+ import { pageRuns, pageSource, readsFor } from "/kiosk-source.js";
764
794
  import { installMotion } from "/motion.js";
765
795
  initTheme(KIOSK_THEME);
766
796
  // behold#725: every looping animation holds while the tab is hidden.
@@ -781,7 +811,7 @@
781
811
  eh: { switchHost: document.getElementById("k-tools"), trailHost: document.getElementById("eh-trail"), tipsHost: document.getElementById("eh-tips"), modalHost: document.getElementById("eh-modals") },
782
812
  watch: { layer: document.getElementById("k-watch"), caption: document.getElementById("k-caption"), change: document.getElementById("k-change"), waves: document.getElementById("k-waves"), callout: document.getElementById("k-callout"), drawer: document.getElementById("k-drawer"), badges: document.getElementById("k-badges"), result: document.getElementById("k-result") },
783
813
  },
784
- { tool: pageTool(document), source: pageSource(document) },
814
+ { tool: pageTool(document), source: pageSource(document), runs: pageRuns(document) },
785
815
  );
786
816
  // behold#571: the repo's numbers from Prometheus, a pane of its own in Inspect (web/kiosk-metrics.js), and Watch's badges and delivery line.
787
817
  import("/kiosk-metrics.js").then((m) => m.startMetrics(document.getElementById("k-metrics"), { tool: pageTool(document), reads: readsFor(pageSource(document)), onModel: (model) => kiosk.setMetrics(model) }));
package/web/kiosk.js CHANGED
@@ -16,7 +16,7 @@
16
16
  import { linkState, linkWords, noteBack, noteRead, readFailed, shareLink } from "./kiosk-link.js";
17
17
  import { CHANT_PANEL_STEPS, chantApprovalModel, chantResultModel } from "./chant-pr-marks.js";
18
18
  import { createLivePacer } from "./chant-live-pace.js";
19
- import { applyJobs, cycleTrack, drawTrack, trackModel, waitingSpec } from "./kiosk-track.js";
19
+ import { applyJobs, cycleTrack, drawTrack, failureAt, seekMs, trackModel, waitingSpec } from "./kiosk-track.js";
20
20
  import { FORGES, iconSvg } from "./forge-mark.js";
21
21
  import { TOOLS } from "./tool-mark.js";
22
22
  import { graphWaves } from "./chant-pr-marks.js";
@@ -34,7 +34,7 @@ import { creditLines, filterIndex, keepRun, kioskVendorOf, liveEstimate, liveFor
34
34
  import { repoParam, repoUrl, stepCheckout } from "./kiosk-repo.js";
35
35
  import { startKioskCarve } from "./kiosk-carve.js";
36
36
  import { drawWaveList, waveListKey } from "./kiosk-wave-list.js";
37
- import { readsFor } from "./kiosk-source.js";
37
+ import { readsFor, runsReadsFor } from "./kiosk-source.js";
38
38
  import { STATE_WORDS, changingRoots, costLine, pinsCommit, planFitsPin, pullPin, readEdges, rootsCount, totalsLine, waveRows, blastRows } from "./terragucci-change.js";
39
39
 
40
40
  /** The scenarios terragucci#1014 numbers. An id not here is shown by the title demo.json carries. */
@@ -912,7 +912,8 @@ function drawBar(bar, s, now) {
912
912
  const head = scenarioHead(demo, { vendor: s.vendor || null });
913
913
 
914
914
  // behold#571: a tool's page says plainly when it replays an earlier run, and when it can't draw the repo's graph.
915
- if (s.replay && s.replay.banner) bar.appendChild(el("p", "k-replay", s.replay.banner));
915
+ if (s.replay && s.replay.asked) bar.appendChild(askedLine(s));
916
+ else if (s.replay && s.replay.banner) bar.appendChild(el("p", "k-replay", s.replay.banner));
916
917
  if (vendor && s.noReports && (s.mode === "live" || s.mode === "replay")) bar.appendChild(el("p", "k-nograph-note", NO_GRAPH_WORDS));
917
918
  const intro = introText(demo);
918
919
 
@@ -1068,11 +1069,55 @@ export function touchScreen() {
1068
1069
  export function heldWords(secs, touch = false) {
1069
1070
  return touch ? `Paused where you tapped · the steps go on in ${secs} s` : `Held where you left it · the steps lead again in ${secs} s`;
1070
1071
  }
1072
+ /** behold#787: the button that ends a replay the viewer asked for. */
1073
+ export const BACK_WORDS = "Back to live";
1074
+ /** behold#787: the done card's chip that replays the cycle's failure. */
1075
+ export const FAILURE_WORDS = "Replay the failure";
1076
+ /** behold#787: how long a replay the viewer asked for runs with no input before the kiosk is live again. */
1077
+ export const REPLAY_IDLE_MS = 180_000;
1078
+
1079
+ /** behold#787: whether the replay is one the viewer asked for, which the live poll leaves alone. */
1080
+ export function viewerReplay(s) {
1081
+ return !!s && s.mode === "replay" && !!s.replay && !!s.replay.asked;
1082
+ }
1083
+
1084
+ /** behold#787: whether a replay the viewer asked for is over: it reached the cycle's last step (the reset), or `idle` ms went by with no input. */
1085
+ export function replayOver(steps, elapsed, idle) {
1086
+ if (!Array.isArray(steps) || !steps.length) return true;
1087
+ return replayAt(steps, elapsed).index === steps.length - 1 || idle > REPLAY_IDLE_MS;
1088
+ }
1089
+
1090
+ /** behold#787: the banner of a replay the viewer asked for, with its way back to live. */
1091
+ export function askedLine(s) {
1092
+ const p = el("p", "k-replay k-replay-asked", null);
1093
+ p.setAttribute("role", "status");
1094
+ p.appendChild(el("span", "k-replay-words", s.replay.banner || "Replay of the latest run"));
1095
+ const b = el("button", "k-replay-back", BACK_WORDS);
1096
+ b.type = "button";
1097
+ b.addEventListener("click", () => s.backToLive && s.backToLive());
1098
+ p.appendChild(b);
1099
+ return p;
1100
+ }
1071
1101
  export const FOLLOW_WORDS = "Follow the steps";
1072
1102
  export const RESUME_WORDS = "Resume now";
1073
1103
  /** behold#779: how long a tap on a touch screen holds Watch's shot (a click holds it PICK_HOLD_MS). */
1074
1104
  export const TAP_HOLD_MS = 20_000;
1075
1105
 
1106
+ /**
1107
+ * A paused Watch, said at the foot of the screen with its resume (kiosk.html shows it on a touch screen only): on a
1108
+ * phone the header that also says it is scrolled away by the time a tap on the graph paused it.
1109
+ */
1110
+ function drawHeldOver(doc, s) {
1111
+ const over = doc && doc.getElementById ? doc.getElementById("k-held-over") : null;
1112
+ if (!over) return;
1113
+ over.hidden = !s.watchHeld;
1114
+ if (!s.watchHeld) return void over.replaceChildren();
1115
+ const b = el("button", "k-w-resume", RESUME_WORDS);
1116
+ b.type = "button";
1117
+ b.addEventListener("click", () => s.followSteps && s.followSteps());
1118
+ over.replaceChildren(el("span", "k-held-words", heldWords(s.watchHeld.secs, true)), b);
1119
+ }
1120
+
1076
1121
  /** Watch's header: the scenario's place and the strip on the left, the delivery numbers on the right. */
1077
1122
  function drawWatchHead(bar, s, now) {
1078
1123
  const demo = s.demo.demo;
@@ -1084,7 +1129,9 @@ function drawWatchHead(bar, s, now) {
1084
1129
  // behold#741: a terragucci repo's chapter-carrying scenario names terragucci, its engine and its forge.
1085
1130
  // behold#746: a tool's page leaves out the parts (and the tooltip's sentence) that name what it may not.
1086
1131
  // On its replay the line's "live demo" goes; the replay's banner follows the line instead.
1087
- const hide = vendor ? (t) => namesOther(t, s.vendor) || (s.mode === "replay" && /^live\b/.test(t)) : null;
1132
+ // behold#787: and on a replay the viewer asked for.
1133
+ const asked = !!(s.replay && s.replay.asked);
1134
+ const hide = vendor || asked ? (t) => (!!vendor && namesOther(t, s.vendor)) || (s.mode === "replay" && /^live\b/.test(t)) : null;
1088
1135
  if (s.chantLoop) place.appendChild(whatLineEl(demo, s.chantForge ? s.chantForge() : null, null, hide, s.source === "chant-demo"));
1089
1136
  else place.appendChild(whatLineEl(demo, s.tgForge || null, { tools: s.tools || [] }, hide));
1090
1137
  } else {
@@ -1092,10 +1139,13 @@ function drawWatchHead(bar, s, now) {
1092
1139
  place.appendChild(el("span", "k-cycle", cycleWords(demo, now)));
1093
1140
  }
1094
1141
  // behold#746: a tool's page says in Watch too that it replays an earlier run.
1095
- if (vendor && s.mode === "replay" && s.replay && s.replay.banner) place.appendChild(el("span", "k-cycle k-w-replay", s.replay.banner));
1142
+ if (vendor && s.mode === "replay" && s.replay && s.replay.banner && !s.replay.asked) place.appendChild(el("span", "k-cycle k-w-replay", s.replay.banner));
1096
1143
  bar.appendChild(place);
1144
+ if (s.mode === "replay" && s.replay && s.replay.asked) bar.appendChild(askedLine(s));
1097
1145
  const intro = introFor(s);
1098
1146
  if (intro) bar.appendChild(el("p", "k-w-intro", intro));
1147
+ // A phone leads with what the demo shows (kiosk.html shows it there only); the caption's copy of it goes.
1148
+ if (demo && demo.title) bar.appendChild(el("p", "k-w-point", demo.title));
1099
1149
  const strip = el("ol", "k-strip");
1100
1150
  // behold#631: a chant pull request's wait for its approval comes before its merge. Without a stop of its own on the
1101
1151
  // strip it shows as "planned", for the fix's pull request as for the first.
@@ -1111,6 +1161,7 @@ function drawWatchHead(bar, s, now) {
1111
1161
  p.appendChild(b);
1112
1162
  bar.appendChild(p);
1113
1163
  }
1164
+ drawHeldOver(bar.ownerDocument, s);
1114
1165
  const dora = doraLine(s.metrics);
1115
1166
  if (dora) {
1116
1167
  const p = el("p", "k-w-dora", dora);
@@ -1328,6 +1379,24 @@ export function drawResult(host, model, s) {
1328
1379
  if (bars.size) wf.appendChild(phaseKey());
1329
1380
  host.appendChild(wf);
1330
1381
  }
1382
+ // behold#787: a visitor who missed the failure's few seconds replays them from here.
1383
+ // The card is rebuilt every second: the press is read on the card, so a tap across a rebuild still counts.
1384
+ if (s.failureAt && s.failureAt()) {
1385
+ const b = el("button", "k-result-replay", FAILURE_WORDS);
1386
+ b.type = "button";
1387
+ host.appendChild(b);
1388
+ if (!host.krWired && host.addEventListener) {
1389
+ host.krWired = true;
1390
+ let down = 0;
1391
+ const on = (e) => !!(e.target && e.target.closest && e.target.closest(".k-result-replay"));
1392
+ host.addEventListener("pointerdown", (e) => { down = on(e) ? Date.now() : 0; });
1393
+ host.addEventListener("click", (e) => {
1394
+ const hit = on(e) || (down && Date.now() - down < 1500 && e.target === host);
1395
+ down = 0;
1396
+ if (hit && s.seekTo && s.failureAt()) s.seekTo(s.failureAt());
1397
+ });
1398
+ }
1399
+ }
1331
1400
  }
1332
1401
 
1333
1402
  /** behold#571: a wave's trace as one bar of its phases, a button that opens the whole trace. */
@@ -1549,9 +1618,11 @@ export const CHANT_SIDE_ROOM = 520;
1549
1618
  * countdown. When the roots the step is about change, move the framed view
1550
1619
  * with a `behold:view` message; the frame takes them only from this origin.
1551
1620
  */
1552
- export function startKiosk({ bar, frame, side, main, views, read = null, tools = null, watch = null, eh = null }, { fetchJson = defaultFetch, now = () => new Date(), origin = location.origin, tool = null, source = null } = {}) {
1621
+ export function startKiosk({ bar, frame, side, main, views, read = null, tools = null, watch = null, eh = null }, { fetchJson = defaultFetch, now = () => new Date(), origin = location.origin, tool = null, source = null, runs = null } = {}) {
1553
1622
  // behold#752: terragucci's loop, or chant's fan-out demo from its own records (web/kiosk-source.js).
1554
1623
  const reads = readsFor(source);
1624
+ // behold#815: the runs pane's own reads, chant's run index when serve has --ci-report-url.
1625
+ const runsReads = runsReadsFor(runs, reads);
1555
1626
  const s = { source: reads.source, demo: null, answer: null, progress: null, components: false, pick: null, view: "resources", roots: [], waves: [], light: false, hover: null, frameHover: null, held: null };
1556
1627
  // behold#571: Watch or Inspect, the viewer's pick kept in their browser; Watch until they pick Inspect.
1557
1628
  const shelf = typeof localStorage !== "undefined" ? (() => { try { return localStorage; } catch { return null; } })() : null;
@@ -1762,10 +1833,65 @@ export function startKiosk({ bar, frame, side, main, views, read = null, tools =
1762
1833
  if (s.mode !== "replay" || !s.replay) return;
1763
1834
  const steps = s.replay.cycle.steps;
1764
1835
  const r = replayAt(steps, now().getTime() - s.replay.start);
1836
+ // behold#787: a replay the viewer asked for ends at the cycle's end (its reset), or after a while with no input.
1837
+ if (s.replay.asked && replayOver(steps, now().getTime() - s.replay.start, now().getTime() - s.replay.input)) return leaveReplay();
1765
1838
  s.replay.at = r.at;
1766
- s.replay.banner = replayBanner(s.replay.cycle, liveEstimate(s.live && s.live.demo, s.replay.cycle, now()));
1767
- setDemo({ source: "replay", read: steps[r.index].at, demo: scrubDemo(steps[r.index], tool) });
1839
+ s.replay.banner = replayBanner(s.replay.cycle, s.replay.asked ? null : liveEstimate(s.live && s.live.demo, s.replay.cycle, now()));
1840
+ setDemo({ source: "replay", read: steps[r.index].at, demo: vendor ? scrubDemo(steps[r.index], tool) : steps[r.index] });
1841
+ };
1842
+ /** behold#787: what a seek or the end of a replay leaves behind: the story's place, the track's, the run view's memo and Watch's hold. */
1843
+ const rewind = () => {
1844
+ if (s.resetStory) s.resetStory();
1845
+ Object.assign(trackState, { cycle: null, pulls: [], key: null, since: null });
1846
+ runMemo = null;
1847
+ watchHoldAt = null;
1848
+ s.watchHeld = null;
1849
+ drawerWave = null;
1850
+ drawerView = null;
1851
+ lastShot = null;
1852
+ };
1853
+ /**
1854
+ * behold#787: replay the track's cycle from `at` (a step's time): the replay a tool's page shows, the viewer's
1855
+ * this time. Within a replay it seeks; the live poll leaves it alone until it ends.
1856
+ */
1857
+ s.seekTo = (at) => {
1858
+ const cycle = s.mode === "replay" && s.replay ? s.replay.cycle : s.lastCycle();
1859
+ if (!cycle || !Array.isArray(cycle.steps) || !cycle.steps.length) return;
1860
+ const start = now().getTime() - seekMs(cycle, at);
1861
+ if (s.mode === "replay" && s.replay) s.replay.start = start;
1862
+ else {
1863
+ s.replay = { cycle, start, at: null, banner: null, runs: null, asked: true };
1864
+ s.mode = "replay";
1865
+ s.repo = cycle.repo || s.repo;
1866
+ }
1867
+ s.replay.input = now().getTime();
1868
+ rewind();
1869
+ draw();
1768
1870
  };
1871
+ /** behold#787: the cycle's failure, where the done card's chip replays it from; null for a cycle with none. */
1872
+ s.failureAt = () => failureAt(s.mode === "replay" && s.replay ? s.replay.cycle : s.lastCycle());
1873
+ const leaveReplay = () => {
1874
+ if (!s.replay || !s.replay.asked) return;
1875
+ s.replay = null;
1876
+ s.mode = "live";
1877
+ rewind();
1878
+ if (!vendor && s.live) {
1879
+ s.repo = s.live.demo ? s.live.demo.repo : s.repo;
1880
+ setDemo(s.live);
1881
+ }
1882
+ void demo();
1883
+ };
1884
+ s.backToLive = () => {
1885
+ leaveReplay();
1886
+ draw();
1887
+ };
1888
+ // behold#787: any input keeps the viewer's replay going.
1889
+ if (typeof document !== "undefined" && document.addEventListener) {
1890
+ const touched = () => {
1891
+ if (s.replay && s.replay.asked) s.replay.input = now().getTime();
1892
+ };
1893
+ for (const ev of ["pointerdown", "keydown", "wheel"]) document.addEventListener(ev, touched, { passive: true, capture: true });
1894
+ }
1769
1895
 
1770
1896
  const draw = () => {
1771
1897
  followRepo();
@@ -1994,8 +2120,10 @@ export function startKiosk({ bar, frame, side, main, views, read = null, tools =
1994
2120
  }
1995
2121
  // behold#774: the run's own jobs say the apply started before its run view does.
1996
2122
  const jobs = applyJobs(runsApi && runsApi.run ? runsApi.run.doc : null, d);
1997
- const model = trackModel(track, { demo: d, pulls: trackState.pulls, since: trackState.since, now: t, waves: live ? live.waves : null, jobs });
2123
+ const model = trackModel(track, { demo: d, pulls: trackState.pulls, since: trackState.since, now: t, waves: live ? live.waves : null, jobs, replay: s.mode === "replay" });
1998
2124
  s.trackModel = model;
2125
+ // behold#787: a past step's segment replays it.
2126
+ if (model) model.onSeek = s.seekTo;
1999
2127
  drawTrack(trackHost, model);
2000
2128
  // In the trail's place: over the caption.
2001
2129
  const cap = shownCaption().getBoundingClientRect();
@@ -2416,6 +2544,8 @@ export function startKiosk({ bar, frame, side, main, views, read = null, tools =
2416
2544
  s.strip = null;
2417
2545
  /** behold#631: the running tool's last finished cycle, when one is published. */
2418
2546
  s.lastCycle = () => {
2547
+ // behold#787: while it replays, the replayed cycle, though a newer one has ended since.
2548
+ if (s.mode === "replay" && s.replay && s.replay.cycle) return s.replay.cycle;
2419
2549
  const d = s.demo && s.demo.demo;
2420
2550
  const t = vendor ? tool : d && typeof d.tool === "string" ? d.tool : null;
2421
2551
  const r = t ? strips.get(t) : null;
@@ -2464,19 +2594,23 @@ export function startKiosk({ bar, frame, side, main, views, read = null, tools =
2464
2594
  };
2465
2595
  const replayRuns = async () => {
2466
2596
  const r = s.replay;
2597
+ // behold#787: a replay the viewer ended while this read was out.
2598
+ if (!r) return [];
2467
2599
  if (r.runs) return r.runs;
2468
2600
  const idx = await fetchJson(reads.runs);
2469
2601
  const listed = new Map((idx && idx.doc && Array.isArray(idx.doc.runs) ? idx.doc.runs : []).map((x) => [x.id, x]));
2470
2602
  const runs = [];
2471
- for (const id of r.cycle.runs) {
2603
+ for (const id of Array.isArray(r.cycle.runs) ? r.cycle.runs : []) {
2472
2604
  const e = listed.get(id) || (await runDoc(id));
2473
2605
  if (e) runs.push(e);
2474
2606
  }
2475
- r.runs = runs.filter((x) => keepRun(x, { tool, repo: r.cycle.repo }));
2607
+ // behold#787: /kiosk names no tool; the cycle does.
2608
+ r.runs = runs.filter((x) => keepRun(x, { tool: tool || r.cycle.tool, repo: r.cycle.repo }));
2476
2609
  return r.runs;
2477
2610
  };
2478
2611
  const runsSource = () => {
2479
- if (!vendor || s.mode === "live") return null;
2612
+ // behold#787: /kiosk replays too, when the viewer asks.
2613
+ if (s.mode === "live") return null;
2480
2614
  if (s.mode !== "replay" || !s.replay) return { index: async () => ({ doc: { schema: "demo.runs/v1", runs: [] } }), run: async () => ({ doc: null, absent: "No run to show yet." }) };
2481
2615
  return {
2482
2616
  index: async () => replayIndex(await replayRuns(), shownNow().getTime()),
@@ -2575,6 +2709,8 @@ export function startKiosk({ bar, frame, side, main, views, read = null, tools =
2575
2709
  * up; the story never goes back within a cycle.
2576
2710
  */
2577
2711
  const story = { cycle: null, n: 0, chapter: null, step: null };
2712
+ // behold#787: a seek may go back within a cycle; the story starts from where it lands.
2713
+ s.resetStory = () => Object.assign(story, { cycle: null, n: 0, chapter: null, step: null });
2578
2714
  /** behold#631: the forge chant's pipeline runs on, from its loop as /api/chant/pr read it. */
2579
2715
  s.chantForge = () => (ap.chant && ap.chant.loop && ap.chant.loop.forge) || null;
2580
2716
  s.storyDemo = (d) => {
@@ -2697,11 +2833,13 @@ export function startKiosk({ bar, frame, side, main, views, read = null, tools =
2697
2833
  tools: () => s.tools || [],
2698
2834
  rootTools: () => s.rootTools || {},
2699
2835
  light: () => s.light,
2700
- source: runsSource,
2701
- filter: vendor ? (index) => filterIndex(index, { tool, repo: s.repo }) : (index) => index,
2702
- replay: () => s.mode === "replay",
2836
+ // behold#815: chant's run index is the served repo's runs alone and their history, so the pane reads it whole,
2837
+ // on a tool's page and in a replay alike.
2838
+ source: runsReads.from ? () => null : runsSource,
2839
+ filter: vendor && !runsReads.from ? (index) => filterIndex(index, { tool, repo: s.repo }) : (index) => index,
2840
+ replay: () => !runsReads.from && s.mode === "replay",
2703
2841
  hideLine: vendor ? (line) => namesOther(line, tool) : null,
2704
- urls: { runs: reads.runs, run: reads.run },
2842
+ urls: runsReads,
2705
2843
  },
2706
2844
  );
2707
2845
  }
@@ -2944,6 +3082,8 @@ export function startKiosk({ bar, frame, side, main, views, read = null, tools =
2944
3082
  noteRead(link, "poll", !readFailed(live), now());
2945
3083
  paintLink();
2946
3084
  s.live = live;
3085
+ // behold#787: the poll leaves a replay the viewer asked for alone; its end takes the live step from here.
3086
+ if (viewerReplay(s)) return draw();
2947
3087
  if (!vendor) {
2948
3088
  s.repo = live && live.demo ? live.demo.repo : null;
2949
3089
  setDemo(live);
@@ -0,0 +1,276 @@
1
+ // behold#685: "Run this job locally". behold starts `chant ci run plan
2
+ // --local --events-json` at a commit (POST /api/chant/ci/local), and draws the
3
+ // run from its run-event/v1 lines in the runs pane's run view
4
+ // (web/kiosk-runs.js renderRun), next to CI's run of the same job at the same
5
+ // commit from chant's run index when serve has --ci-report-url. Plan only:
6
+ // apply is never offered here (src/ci-local-run.ts APPLY_REFUSAL). The tab is
7
+ // never drawn in a public view, an embed, a static export or a guarded repo.
8
+
9
+ import { renderRun, STATUS_WORDS } from "./kiosk-runs.js";
10
+
11
+ /** The tab's first line. */
12
+ export const LOCAL_LEGEND =
13
+ "Runs a CI job on this machine with chant ci run --local: a fresh worktree of the commit, no push, no commit status, nothing under the report URL. chant keeps the run's record on the local chant/lifecycle.";
14
+
15
+ const sha8 = (s) => (s ? String(s).slice(0, 8) : "");
16
+
17
+ /** What the tab offers, from GET /api/chant/ci/local's `offer`. */
18
+ export function offerView(answer) {
19
+ const offer = (answer && answer.offer) || null;
20
+ if (!offer) return { can: false, refusal: answer && answer.error ? answer.error : "behold did not say what it offers here", remedy: "", apply: null, env: "", members: [], ciIndex: false };
21
+ return {
22
+ can: (offer.jobs || []).includes("plan"),
23
+ refusal: offer.refusal ? offer.refusal.error : null,
24
+ remedy: offer.refusal && offer.refusal.remedy ? offer.refusal.remedy : "",
25
+ apply: offer.apply || null,
26
+ env: offer.env || "",
27
+ members: offer.members || [],
28
+ ciIndex: !!offer.ciIndex,
29
+ };
30
+ }
31
+
32
+ /** CI's plan jobs from chant's run index (GET /api/chant/ci/runs), each a job a local run can repeat. */
33
+ export function ciPlanRows(index) {
34
+ const runs = index && index.doc && Array.isArray(index.doc.runs) ? index.doc.runs : [];
35
+ return runs
36
+ .filter((r) => r.job === "plan" && r.pull !== null && r.pull !== undefined)
37
+ .map((r) => ({
38
+ id: r.id,
39
+ commit: r.commit,
40
+ pr: r.pull,
41
+ member: r.member || null,
42
+ text: `plan of #${r.pull} at ${sha8(r.commit)}${r.member ? ` · ${r.member}` : ""} · ${STATUS_WORDS[r.status] || r.status}`,
43
+ }));
44
+ }
45
+
46
+ /** The body POST /api/chant/ci/local takes, from the form's values; null with the reason when one is missing. */
47
+ export function askBody({ commit, pr, env, base, member, forge }) {
48
+ const c = String(commit || "").trim();
49
+ const p = String(pr || "").trim();
50
+ if (!/^[0-9a-f]{7,64}$/.test(c)) return { error: "a commit's sha, 7 hex digits or more" };
51
+ if (!/^[1-9][0-9]*$/.test(p)) return { error: "the pull request's number: chant's plan job reads it" };
52
+ const body = { job: "plan", commit: c, pr: Number(p) };
53
+ if (String(env || "").trim()) body.env = String(env).trim();
54
+ if (String(base || "").trim()) body.base = String(base).trim();
55
+ if (member) body.member = member;
56
+ if (forge) body.forge = forge;
57
+ return { body };
58
+ }
59
+
60
+ /** The two halves' headings: where each run ran. */
61
+ export function compareHeads(answer) {
62
+ const doc = answer && answer.doc;
63
+ const local = doc ? `This machine · chant ci run plan --local · base ${sha8(doc.base)} · ${doc.env}${doc.where && doc.where.forge && doc.where.forge !== "local" ? ` · chant said it ran on ${doc.where.forge}` : ""}` : "This machine";
64
+ return { local, ci: "CI · from chant's run index" };
65
+ }
66
+
67
+ const el = (tag, cls, text) => {
68
+ const n = document.createElement(tag);
69
+ if (cls) n.className = cls;
70
+ if (text !== undefined) n.textContent = text;
71
+ return n;
72
+ };
73
+
74
+ /**
75
+ * Draw the tab into `host`. `s` holds `offer` (GET /api/chant/ci/local),
76
+ * `index` (GET /api/chant/ci/runs, or null), `answer` (GET
77
+ * /api/chant/ci/local/:id) and the form's values; `ui.start(body)` posts,
78
+ * `ui.pick(id)` opens a run, `ui.redraw()` draws again.
79
+ */
80
+ export function renderLocalRuns(host, s, ui) {
81
+ host.replaceChildren();
82
+ const v = offerView(s.offer);
83
+ host.appendChild(el("div", "tg-legend", LOCAL_LEGEND));
84
+ if (v.refusal) {
85
+ const r = el("div", "tg-refusal", v.refusal);
86
+ if (v.remedy) r.title = v.remedy;
87
+ host.appendChild(r);
88
+ }
89
+ if (v.apply) host.appendChild(el("div", "tg-legend", v.apply));
90
+
91
+ // The form: a commit and its pull request, and what CI ran it with.
92
+ const form = el("div", "lr-form");
93
+ const field = (name, label, value, placeholder) => {
94
+ const l = el("label", "lr-field", label);
95
+ const i = el("input");
96
+ i.name = name;
97
+ i.value = value || "";
98
+ if (placeholder) i.placeholder = placeholder;
99
+ i.spellcheck = false;
100
+ i.addEventListener("input", () => (s.form[name] = i.value));
101
+ l.appendChild(i);
102
+ form.appendChild(l);
103
+ };
104
+ s.form = s.form || {};
105
+ if (s.form.env === undefined) s.form.env = v.env;
106
+ field("commit", "commit", s.form.commit, "sha");
107
+ field("pr", "pull request", s.form.pr, "#");
108
+ field("env", "env", s.form.env, "the pipeline's env");
109
+ field("base", "base", s.form.base, "where it leaves the trunk");
110
+ const pick = (name, label, options) => {
111
+ const l = el("label", "lr-field", label);
112
+ const sel = el("select");
113
+ sel.name = name;
114
+ for (const [value, text] of options) {
115
+ const o = el("option", null, text);
116
+ o.value = value;
117
+ if ((s.form[name] || "") === value) o.selected = true;
118
+ sel.appendChild(o);
119
+ }
120
+ sel.addEventListener("change", () => (s.form[name] = sel.value));
121
+ l.appendChild(sel);
122
+ form.appendChild(l);
123
+ };
124
+ pick("member", "member", [["", "the workspace"], ...v.members.map((m) => [m, m])]);
125
+ pick("forge", "forge", [["", "detect"], ["github", "github"], ["gitlab", "gitlab"], ["forgejo", "forgejo"]]);
126
+ const go = el("button", "lr-go", "Run plan locally");
127
+ go.type = "button";
128
+ go.disabled = !v.can || !!s.starting;
129
+ go.title = v.can ? "Start chant ci run plan --local at this commit." : v.refusal || "";
130
+ go.addEventListener("click", () => {
131
+ const a = askBody(s.form);
132
+ if (a.error) {
133
+ s.formError = a.error;
134
+ ui.redraw();
135
+ return;
136
+ }
137
+ ui.start(a.body);
138
+ });
139
+ form.appendChild(go);
140
+ host.appendChild(form);
141
+ if (s.formError) host.appendChild(el("div", "tg-refusal", s.formError));
142
+
143
+ // CI's plan jobs, each one click from running here.
144
+ if (v.ciIndex) {
145
+ host.appendChild(el("h3", null, "CI's plan jobs"));
146
+ const rows = ciPlanRows(s.index);
147
+ if (!s.index) host.appendChild(el("div", "tg-legend", "reading chant's run index"));
148
+ else if (s.index.error || s.index.absent) host.appendChild(el("div", "tg-legend", s.index.error || s.index.absent));
149
+ else if (!rows.length) host.appendChild(el("div", "tg-legend", "chant's run index lists no plan job of a pull request"));
150
+ for (const r of rows) {
151
+ const row = el("div", "lr-ci-row");
152
+ row.appendChild(el("span", "lr-ci-text", r.text));
153
+ const b = el("button", "lr-again", "Run this job locally");
154
+ b.type = "button";
155
+ b.disabled = !v.can || !!s.starting;
156
+ b.title = v.can ? `chant ci run plan --local --commit ${r.commit} --pr ${r.pr}${r.member ? ` in ${r.member}` : ""}` : v.refusal || "";
157
+ b.addEventListener("click", () => {
158
+ Object.assign(s.form, { commit: r.commit, pr: String(r.pr), member: r.member || "", base: "" });
159
+ const a = askBody(s.form);
160
+ if (a.body) ui.start(a.body);
161
+ });
162
+ row.appendChild(b);
163
+ host.appendChild(row);
164
+ }
165
+ }
166
+
167
+ // The runs behold started, newest first.
168
+ const runs = (s.offer && s.offer.runs) || [];
169
+ if (runs.length) {
170
+ host.appendChild(el("h3", null, "run on this machine"));
171
+ for (const r of runs) {
172
+ const row = el("div", `lr-run${s.selected === r.id ? " lr-selected" : ""}`, `${sha8(r.commit)} · #${r.pull}${r.member ? ` · ${r.member}` : ""} · ${STATUS_WORDS[r.status] || r.status}`);
173
+ row.title = r.title;
174
+ row.tabIndex = 0;
175
+ row.addEventListener("click", () => ui.pick(r.id));
176
+ host.appendChild(row);
177
+ }
178
+ }
179
+ if (!s.selected) return;
180
+
181
+ // The run beside CI's run of the same job at the same commit.
182
+ const heads = compareHeads(s.answer);
183
+ const box = el("div", "lr-compare");
184
+ const half = (title, answer, side) => {
185
+ const col = el("div", "lr-half");
186
+ col.appendChild(el("div", "lr-half-head", title));
187
+ const pane = el("div", "lr-run-view");
188
+ s.ui = s.ui || {};
189
+ const u = (s.ui[side] = s.ui[side] || { job: null, open: null, setup: null });
190
+ renderRun(pane, answer, u, {
191
+ pickJob: (name) => {
192
+ u.job = name;
193
+ u.open = null;
194
+ ui.redraw();
195
+ },
196
+ toggleStep: (job, i) => {
197
+ u.job = job;
198
+ u.open = i;
199
+ ui.redraw();
200
+ },
201
+ toggleSetup: (key) => {
202
+ u.setup = u.setup === key ? null : key;
203
+ ui.redraw();
204
+ },
205
+ });
206
+ col.appendChild(pane);
207
+ box.appendChild(col);
208
+ };
209
+ half(heads.local, s.answer ? { doc: s.answer.doc, error: s.answer.error, absent: s.answer.absent } : null, "local");
210
+ half(heads.ci, s.answer ? s.answer.ci || { absent: "no CI run to show" } : null, "ci");
211
+ host.appendChild(box);
212
+ }
213
+
214
+ /**
215
+ * Mount the tab's reads: the offer and the runs on open, chant's run index
216
+ * when serve names one, and the selected run again whenever behold says it
217
+ * moved (the SSE `local-run` event). `fetchJson(url, init)` answers parsed JSON.
218
+ */
219
+ export function startLocalRuns(host, { fetchJson, events, toast = () => {} }) {
220
+ const s = { offer: null, index: null, answer: null, selected: null, form: {}, starting: false };
221
+ const redraw = () => renderLocalRuns(host, s, ui);
222
+ const readOffer = async () => {
223
+ s.offer = await fetchJson("/api/chant/ci/local").catch((e) => ({ error: String(e) }));
224
+ if (s.offer && s.offer.offer && s.offer.offer.ciIndex && !s.index) s.index = await fetchJson("/api/chant/ci/runs").catch((e) => ({ error: String(e) }));
225
+ redraw();
226
+ };
227
+ const readRun = async () => {
228
+ if (!s.selected) return;
229
+ const id = s.selected;
230
+ const a = await fetchJson(`/api/chant/ci/local/${encodeURIComponent(id)}`).catch((e) => ({ error: String(e) }));
231
+ if (s.selected !== id) return;
232
+ s.answer = a;
233
+ redraw();
234
+ };
235
+ const ui = {
236
+ redraw,
237
+ pick: (id) => {
238
+ s.selected = id;
239
+ s.answer = null;
240
+ s.ui = {};
241
+ redraw();
242
+ readRun();
243
+ },
244
+ start: async (body) => {
245
+ s.starting = true;
246
+ s.formError = null;
247
+ redraw();
248
+ const r = await fetchJson("/api/chant/ci/local", { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify(body) }).catch((e) => ({ error: String(e) }));
249
+ s.starting = false;
250
+ if (r.error) {
251
+ s.formError = r.error;
252
+ toast(`✗ run locally: ${r.error}`, false);
253
+ redraw();
254
+ return;
255
+ }
256
+ toast(`▶ ${r.command}`, true);
257
+ await readOffer();
258
+ ui.pick(r.id);
259
+ },
260
+ };
261
+ // One read per burst of lines.
262
+ let pending = null;
263
+ if (events) {
264
+ events.addEventListener("local-run", (e) => {
265
+ if (e.data !== s.selected || pending) return;
266
+ pending = setTimeout(async () => {
267
+ pending = null;
268
+ await readRun();
269
+ const a = s.answer && s.answer.doc;
270
+ if (a && a.status !== "running" && a.status !== "queued") readOffer();
271
+ }, 250);
272
+ });
273
+ }
274
+ readOffer();
275
+ return { reload: readOffer };
276
+ }