@intentius/behold 0.29.48 → 0.29.49

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/dist/cli.js CHANGED
@@ -28581,7 +28581,7 @@ function joinTerragucci(read, nodes, roots) {
28581
28581
  if (!said4) continue;
28582
28582
  const id = blocks?.get(blockPath(c.address));
28583
28583
  if (!id) {
28584
- unmatchedChanges.push({ root: root.path, address: c.address });
28584
+ unmatchedChanges.push({ root: root.path, address: c.address, action: c.action, verdict: kind });
28585
28585
  continue;
28586
28586
  }
28587
28587
  const k = `${id}\0${c.action}`;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@intentius/behold",
3
- "version": "0.29.48",
3
+ "version": "0.29.49",
4
4
  "license": "Apache-2.0",
5
5
  "type": "module",
6
6
  "description": "behold — a live control plane on chant. See your whole estate (every substrate in one graph), coloured by drift; act through delegated, gated Ops.",
@@ -148,6 +148,32 @@ export function resourceCardId(answer, root, resourceId) {
148
148
  return `${r.member}/${r.name}/${rest}`;
149
149
  }
150
150
 
151
+ /**
152
+ * behold#796: the rows for a root's planned changes no card of the checkout
153
+ * is (`answer.unmatched.changes`): a resource the change adds is in the plan
154
+ * but not yet in the checkout's source, so the resources facet never lists
155
+ * it. One row a block, instance keys dropped; drift is not a plan.
156
+ */
157
+ function plannedOnly(answer, root, declared) {
158
+ const changes = answer && !answer.error && answer.unmatched && Array.isArray(answer.unmatched.changes) ? answer.unmatched.changes : [];
159
+ const r = Array.isArray(answer && answer.roots) ? answer.roots.find((x) => x.name === root || x.path === root) : null;
160
+ const path = r ? r.path : root;
161
+ const seen = new Set(declared.map((d) => d.address));
162
+ const byBlock = new Map();
163
+ for (const c of changes) {
164
+ if (c.root !== path || c.verdict === "drift") continue;
165
+ const address = c.address.replace(/\[(?:"(?:[^"\\]|\\.)*"|[^\]])*\]/g, "");
166
+ if (seen.has(address)) continue;
167
+ // A waiting wave's (the newest plan) before the pull request's plan, as planMark reads cards.
168
+ const had = byBlock.get(address);
169
+ if (!had || (c.verdict === "wave" && had.verdict !== "wave")) byBlock.set(address, c);
170
+ }
171
+ return [...byBlock].map(([address, c]) => ({ address, state: "change", words: PLANNED_WORDS[c.action] || WORDS.changes }));
172
+ }
173
+
174
+ /** behold#796: a row's words for a planned change the checkout has no card for. */
175
+ const PLANNED_WORDS = { create: "to create", delete: "to destroy", replace: "to replace" };
176
+
151
177
  /**
152
178
  * What the popover says about one root's card (Components): its
153
179
  * resources, each "changes", "no change" or "known after apply", and how
@@ -156,7 +182,7 @@ export function resourceCardId(answer, root, resourceId) {
156
182
  */
157
183
  export function rootPopover(answer, root, resources) {
158
184
  const list = Array.isArray(resources) ? resources : [];
159
- const rows = list.map((res) => {
185
+ const declared = list.map((res) => {
160
186
  const id = answer && !answer.error ? resourceCardId(answer, root, res.id) : null;
161
187
  const mark = id && answer.cards ? planMark(answer.cards[id]) : null;
162
188
  const address = res.id.startsWith(`${root}/`) ? res.id.slice(root.length + 1).split("/").join(".") : res.id;
@@ -164,6 +190,8 @@ export function rootPopover(answer, root, resources) {
164
190
  const unknown = (mark.values || []).some((v) => v.unknown);
165
191
  return { address, state: unknown ? "unknown" : "change", words: unknown ? WORDS.unknown2 : WORDS.changes };
166
192
  });
193
+ // behold#796: first, so "and N more" never hides them.
194
+ const rows = [...plannedOnly(answer, root, declared), ...declared];
167
195
  const changed = rows.filter((r) => r.state !== "same").length;
168
196
  const head = !rows.length ? WORDS.noResources : changed === 0 ? WORDS.noRootChange : `${changed} of ${rows.length} ${rows.length === 1 ? "resource changes" : "resources change"}.`;
169
197
  const shown = rows.slice(0, MAX_LINES + 2);
@@ -113,6 +113,38 @@ describe("what the popover says about a root, in Components (behold#571)", () =>
113
113
  expect(rootPopover(answer(), "other", [{ kind: "terraform_data", id: "other/terraform_data.backup_schedule" }]).head).toBe(WORDS.noRootChange);
114
114
  expect(rootPopover(answer(), "other", []).head).toBe(WORDS.noResources);
115
115
  });
116
+
117
+ it("lists a create the plan holds but the checkout does not declare yet, first, as a create (behold#796)", () => {
118
+ const resources = [
119
+ { kind: "terraform_remote_state", id: "cluster-a/data.terraform_remote_state.network" },
120
+ { kind: "aws_dynamodb_table", id: "cluster-a/aws_dynamodb_table.jobs" },
121
+ ];
122
+ const a = answer({
123
+ roots: [{ member: "repo", name: "cluster-a", path: "cluster-a", plan: { changes: 1 } }],
124
+ pull_request: { roots: ["cluster-a"] },
125
+ unmatched: {
126
+ roots: [],
127
+ changes: [
128
+ { root: "cluster-a", address: "aws_sqs_queue.events", action: "create", verdict: "plan" },
129
+ { root: "cluster-a", address: "aws_sqs_queue.events", action: "create", verdict: "wave" },
130
+ { root: "cluster-a", address: "aws_s3_bucket.logs", action: "delete", verdict: "drift" },
131
+ { root: "cluster-b", address: "aws_sqs_queue.other", action: "create", verdict: "plan" },
132
+ ],
133
+ },
134
+ });
135
+ const p = rootPopover(a, "cluster-a", resources);
136
+ expect(p.head).toBe("1 of 3 resources change.");
137
+ expect(p.changed).toBe(1);
138
+ expect(p.rows).toEqual([
139
+ { address: "aws_sqs_queue.events", state: "change", words: "to create" },
140
+ { address: "data.terraform_remote_state.network", state: "same", words: "no change" },
141
+ { address: "aws_dynamodb_table.jobs", state: "same", words: "no change" },
142
+ ]);
143
+ // An answer from before behold#796 carries no action: it still counts as a change.
144
+ const old = rootPopover(answer({ roots: a.roots, unmatched: { roots: [], changes: [{ root: "cluster-a", address: 'aws_sqs_queue.q["a"]' }] } }), "cluster-a", []);
145
+ expect(old.rows).toEqual([{ address: "aws_sqs_queue.q", state: "change", words: "changes" }]);
146
+ expect(old.head).toBe("1 of 1 resource changes.");
147
+ });
116
148
  });
117
149
 
118
150
  describe("when the popover shows (behold#571)", () => {
@@ -0,0 +1,79 @@
1
+ // behold#787: on /kiosk a visitor replays a step already past, or the failure, and goes back to live.
2
+ import { describe, expect, it } from "vitest";
3
+ import { BACK_WORDS, FAILURE_WORDS, REPLAY_IDLE_MS, askedLine, drawResult, replayOver, viewerReplay } from "./kiosk.js";
4
+ import { REPLAY_LAST_HOLD_MS } from "./kiosk-vendor.js";
5
+
6
+ const fakeDocument = () => {
7
+ const make = (tag) => {
8
+ const n = { tagName: tag, className: "", textContent: "", children: [], dataset: {}, style: {}, hidden: false, attrs: {}, on: {} };
9
+ n.appendChild = (c) => (n.children.push(c), c);
10
+ n.append = (...cs) => cs.forEach((c) => n.children.push(c));
11
+ n.replaceChildren = () => (n.children = []);
12
+ n.setAttribute = (k, v) => (n.attrs[k] = v);
13
+ n.addEventListener = (ev, fn) => (n.on[ev] = fn);
14
+ return n;
15
+ };
16
+ return { createElement: make };
17
+ };
18
+ const withDocument = (fn) => {
19
+ const was = globalThis.document;
20
+ globalThis.document = fakeDocument();
21
+ try {
22
+ return fn();
23
+ } finally {
24
+ globalThis.document = was;
25
+ }
26
+ };
27
+
28
+ const steps = [
29
+ { at: "2026-10-19T20:05:36Z", step: "pull-request" },
30
+ { at: "2026-10-19T20:06:47Z", step: "applying" },
31
+ { at: "2026-10-19T20:08:30Z", step: "failed" },
32
+ { at: "2026-10-19T20:12:12Z", step: "applied" },
33
+ { at: "2026-10-19T20:14:09Z", step: "reset" },
34
+ ];
35
+
36
+ describe("a replay the viewer asked for (behold#787)", () => {
37
+ it("is the one the live poll leaves alone; a tool page's own replay is not", () => {
38
+ expect(viewerReplay({ mode: "replay", replay: { asked: true } })).toBe(true);
39
+ expect(viewerReplay({ mode: "replay", replay: { asked: false } })).toBe(false);
40
+ expect(viewerReplay({ mode: "live", replay: null })).toBe(false);
41
+ expect(viewerReplay(null)).toBe(false);
42
+ });
43
+
44
+ it("ends at the cycle's end, or after a while with no input", () => {
45
+ const toApplied = Date.parse(steps[3].at) - Date.parse(steps[0].at);
46
+ const toReset = Date.parse(steps[4].at) - Date.parse(steps[0].at);
47
+ expect(replayOver(steps, toApplied, 0)).toBe(false);
48
+ expect(replayOver(steps, toReset, 0)).toBe(true);
49
+ expect(replayOver(steps, toReset + REPLAY_LAST_HOLD_MS - 1, 0)).toBe(true);
50
+ expect(replayOver(steps, 0, REPLAY_IDLE_MS)).toBe(false);
51
+ expect(replayOver(steps, 0, REPLAY_IDLE_MS + 1)).toBe(true);
52
+ expect(replayOver([], 0, 0)).toBe(true);
53
+ });
54
+
55
+ it("says it is a replay, with a button back to live", () =>
56
+ withDocument(() => {
57
+ let back = 0;
58
+ const p = askedLine({ replay: { banner: "Replay of the run at 20:05 UTC" }, backToLive: () => back++ });
59
+ expect(p.className).toBe("k-replay k-replay-asked");
60
+ expect(p.children.map((c) => c.textContent)).toEqual(["Replay of the run at 20:05 UTC", BACK_WORDS]);
61
+ p.children[1].on.click();
62
+ expect(back).toBe(1);
63
+ }));
64
+
65
+ it("puts a Replay the failure chip on the done card when the cycle failed", () =>
66
+ withDocument(() => {
67
+ const host = document.createElement("aside");
68
+ const model = { head: "Applied", counts: ["3 waves applied"], waves: [] };
69
+ let seek = null;
70
+ drawResult(host, model, { waveTraces: {}, failureAt: () => "2026-10-19T20:08:00Z", seekTo: (at) => (seek = at) });
71
+ const chip = host.children.find((c) => c.className === "k-result-replay");
72
+ expect(chip.textContent).toBe(FAILURE_WORDS);
73
+ host.on.click({ target: { closest: (sel) => (sel === ".k-result-replay" ? chip : null) } });
74
+ expect(seek).toBe("2026-10-19T20:08:00Z");
75
+ // A cycle with no failure: no chip.
76
+ drawResult(host, model, { waveTraces: {}, failureAt: () => null });
77
+ expect(host.children.some((c) => c.className === "k-result-replay")).toBe(false);
78
+ }));
79
+ });
@@ -102,7 +102,8 @@ export function cycleTrack(cycle) {
102
102
  last.ms += took;
103
103
  return;
104
104
  }
105
- chapter.segments.push({ label, steps: [s.step], ms: took, labelText: s.label || "" });
105
+ // behold#787: the segment's first step's time, where a replay of it starts.
106
+ chapter.segments.push({ label, steps: [s.step], ms: took, labelText: s.label || "", at: s.at });
106
107
  });
107
108
  const total = chapters.reduce((sum, c) => sum + c.segments.reduce((a, g) => a + g.ms, 0), 0) || 1;
108
109
  return { chapters, total, cycle: cycle.cycle, byStory };
@@ -127,9 +128,11 @@ export function chapterTitle(index, pull) {
127
128
  * this cycle has opened, in order; `since` when the current segment began
128
129
  * (ms); `waves` the apply's waves as the paced graph shows them
129
130
  * ([{ wave, state }]), for the applying segment's ticks; `jobs` the apply
130
- * jobs of this step's run that have started ({@link applyJobs}).
131
+ * jobs of this step's run that have started ({@link applyJobs}). behold#787:
132
+ * a segment already past (in a `replay`, any but the current one) carries
133
+ * `seek`, its first step's time, and a chapter carries its first segment's.
131
134
  */
132
- export function trackModel(track, { demo, pulls = [], since = null, now = Date.now(), waves = null, jobs = [] } = {}) {
135
+ export function trackModel(track, { demo, pulls = [], since = null, now = Date.now(), waves = null, jobs = [], replay = false } = {}) {
133
136
  if (!track || !demo) return null;
134
137
  // Where the cycle is: the step's own story chapter when told in them; else the chapter of the current pull request
135
138
  // (the reset, the last). Then the segment holding the step.
@@ -158,14 +161,42 @@ export function trackModel(track, { demo, pulls = [], since = null, now = Date.n
158
161
  state,
159
162
  tone,
160
163
  fill: state === "done" ? 1 : state === "current" ? fill : 0,
164
+ // The reset is the cycle's end: nothing to replay from there.
165
+ seek: (replay ? state !== "current" : state === "done") && g.label !== "reset" && typeof g.at === "string" ? g.at : null,
161
166
  ...(state === "current" && g.label === "applying" && Array.isArray(waves) && waves.length ? { ticks: waves.map((w) => ({ wave: w.wave, state: w.state })) } : {}),
162
167
  };
163
168
  }),
164
169
  }));
170
+ for (const c of chapters) c.seek = c.segments.length ? c.segments[0].seek : null;
165
171
  const nowLine = nowWords({ demo, segment: current, expected, elapsed, overrun, waves, jobs, now, fix: track.byStory ? pulls.indexOf(demo.pull) > 0 : at.chapter > 0 });
166
172
  return { chapters, at, elapsed, expected, overrun, now: nowLine, here: hereWords(chapters, at) };
167
173
  }
168
174
 
175
+ /** behold#787: how long before the failed step a replay of the failure starts: the apply's last stretch, where it breaks. */
176
+ export const FAILURE_LEAD_MS = 30_000;
177
+
178
+ /** behold#787: how far into the cycle a time is, in ms from its first step, for the replay's clock (kiosk-vendor.js replayAt). */
179
+ export function seekMs(cycle, at) {
180
+ const first = cycle && Array.isArray(cycle.steps) && cycle.steps[0] ? Date.parse(cycle.steps[0].at) : NaN;
181
+ const t = Date.parse(at || "");
182
+ return Number.isFinite(first) && Number.isFinite(t) ? Math.max(0, t - first) : 0;
183
+ }
184
+
185
+ /**
186
+ * behold#787: where a replay of the cycle's failure starts: FAILURE_LEAD_MS
187
+ * before its failed step, never before the step ahead of it (the apply that
188
+ * broke). Null for a cycle with no failure.
189
+ */
190
+ export function failureAt(cycle) {
191
+ const steps = cycle && Array.isArray(cycle.steps) ? cycle.steps : [];
192
+ const i = steps.findIndex((x) => x && x.step === "failed");
193
+ if (i < 0) return null;
194
+ const t = Date.parse(steps[i].at);
195
+ const before = i > 0 ? Date.parse(steps[i - 1].at) : t;
196
+ if (!Number.isFinite(t)) return null;
197
+ return new Date(Math.max(Number.isFinite(before) ? before : t, t - FAILURE_LEAD_MS)).toISOString();
198
+ }
199
+
169
200
  /**
170
201
  * behold#778: the current step by name, "Step: applying, in 3 The fix", for a
171
202
  * phone, whose segments are too narrow for their labels. Null when the cycle
@@ -283,6 +314,12 @@ body.k-watch #k-track { position: fixed; z-index: 7; left: 5px; right: 5px; }
283
314
  @keyframes kt-sheen { from { background-position: -60% 0; } to { background-position: 160% 0; } }
284
315
  }
285
316
  #k-track .kt-here { display: none; }
317
+ /* behold#787: a step already past is a button that replays it. */
318
+ #k-track button.kt-seek { font: inherit; margin: 0; cursor: pointer; background: transparent; color: inherit; text-align: inherit; }
319
+ #k-track button.kt-seg.kt-seek { padding: 0; }
320
+ #k-track button.kt-chapter-title.kt-seek { padding: 0; border: 0; color: var(--fg); text-decoration: underline dotted; text-underline-offset: 2px; }
321
+ #k-track button.kt-seg.kt-seek:hover { border-color: var(--pending); }
322
+ #k-track button.kt-seek:focus-visible { outline: 2px solid var(--pending); outline-offset: 1px; }
286
323
  /* behold#778: a phone's segments are too narrow for their labels, so a line names the current step, and the chapters wrap to a new line instead of running off the right edge. */
287
324
  @media (max-width: 600px) {
288
325
  body.k-watch #k-track { position: static; }
@@ -293,6 +330,10 @@ body.k-watch #k-track { position: fixed; z-index: 7; left: 5px; right: 5px; }
293
330
  #k-track .kt-seg { height: 0.8em; min-width: 0.6em !important; }
294
331
  #k-track .kt-here { display: block; margin: 0; color: var(--pending); font-size: 0.92em; }
295
332
  #k-track .kt-now { font-size: 0.92em; white-space: normal; }
333
+ /* behold#787: a phone's segments are too thin to press; a past chapter's title is the 44px target. */
334
+ #k-track button.kt-seg.kt-seek { pointer-events: none; }
335
+ #k-track button.kt-chapter-title.kt-seek { align-self: flex-start; max-width: 100%; min-height: 44px; padding: 0 0.8em; border: 1.5px solid color-mix(in srgb, var(--pending) 70%, transparent); border-radius: 999px; text-decoration: none; }
336
+ #k-track button.kt-chapter-title.kt-seek::after { content: " · replay"; color: var(--pending); font-weight: 500; }
296
337
  }
297
338
  `;
298
339
 
@@ -311,6 +352,25 @@ export function drawTrack(host, model, doc = typeof document !== "undefined" ? d
311
352
  if (text !== undefined && text !== null) n.textContent = text;
312
353
  return n;
313
354
  };
355
+ // behold#787: the track is rebuilt every second, so a press is read on the host: a tap whose button was
356
+ // rebuilt between its down and its up still seeks to where it went down, and a focused button keeps its focus.
357
+ host.ktSeek = model && model.onSeek ? model.onSeek : null;
358
+ if (!host.ktWired && host.addEventListener) {
359
+ host.ktWired = true;
360
+ let down = null;
361
+ const seekOf = (t) => (t && t.closest ? t.closest("[data-seek]") : null);
362
+ host.addEventListener("pointerdown", (e) => {
363
+ const b = seekOf(e.target);
364
+ down = b ? { seek: b.dataset.seek, at: Date.now() } : null;
365
+ });
366
+ host.addEventListener("click", (e) => {
367
+ const b = seekOf(e.target);
368
+ const seek = b ? b.dataset.seek : down && Date.now() - down.at < 1500 ? down.seek : null;
369
+ down = null;
370
+ if (seek && host.ktSeek) host.ktSeek(seek);
371
+ });
372
+ }
373
+ const focused = doc.activeElement && host.contains && host.contains(doc.activeElement) && doc.activeElement.dataset ? doc.activeElement.dataset.seek : null;
314
374
  host.replaceChildren();
315
375
  if (!model) {
316
376
  host.hidden = true;
@@ -324,14 +384,26 @@ export function drawTrack(host, model, doc = typeof document !== "undefined" ? d
324
384
  const ch = el("div", `kt-chapter kt-${c.state}`);
325
385
  // Grow factors summing to well over 1: below 1 a flex row leaves the rest of its width empty.
326
386
  ch.style.flex = `${Math.round(share * 1000)} 1 0`;
327
- ch.appendChild(el("div", "kt-chapter-title", c.title));
387
+ // behold#787: a step already past replays from its start on a press: the chapter's title (a phone's target) and each segment.
388
+ const seekable = (o) => !!(o.seek && model.onSeek);
389
+ const head = el(seekable(c) ? "button" : "div", `kt-chapter-title${seekable(c) ? " kt-seek" : ""}`, c.title);
390
+ if (seekable(c)) {
391
+ head.type = "button";
392
+ head.title = `Replay from ${c.title}`;
393
+ head.dataset.seek = c.seek;
394
+ }
395
+ ch.appendChild(head);
328
396
  const segs = el("div", "kt-segs");
329
397
  for (const g of c.segments) {
330
- const seg = el("div", `kt-seg kt-${g.state} kt-${g.tone}`);
398
+ const seg = el(seekable(g) ? "button" : "div", `kt-seg kt-${g.state} kt-${g.tone}${seekable(g) ? " kt-seek" : ""}`);
399
+ if (seekable(g)) {
400
+ seg.type = "button";
401
+ seg.dataset.seek = g.seek;
402
+ }
331
403
  seg.style.flex = `${Math.round(g.share * 1000)} 1 0`;
332
404
  // Never narrower than its short label, whole.
333
405
  seg.style.minWidth = `${(g.short.length * 0.62 + 1).toFixed(2)}em`;
334
- seg.title = g.label;
406
+ seg.title = seekable(g) ? `Replay from ${g.label}` : g.label;
335
407
  const fill = el("div", "kt-fill");
336
408
  fill.style.width = `${Math.round(g.fill * 1000) / 10}%`;
337
409
  seg.appendChild(fill);
@@ -359,4 +431,8 @@ export function drawTrack(host, model, doc = typeof document !== "undefined" ? d
359
431
  for (const lab of host.querySelectorAll ? host.querySelectorAll(".kt-label") : []) {
360
432
  if (lab.scrollWidth > lab.clientWidth + 1 && lab.dataset.short) lab.textContent = lab.dataset.short;
361
433
  }
434
+ if (focused && host.querySelector) {
435
+ const again = [...host.querySelectorAll("[data-seek]")].find((b) => b.dataset.seek === focused);
436
+ if (again && again.focus) again.focus();
437
+ }
362
438
  }
@@ -1,5 +1,5 @@
1
1
  import { describe, expect, it } from "vitest";
2
- import { FILL_CAP, applyJobs, cycleTrack, hereWords, trackModel, waitingSpec } from "./kiosk-track.js";
2
+ import { FAILURE_LEAD_MS, FILL_CAP, applyJobs, cycleTrack, failureAt, hereWords, seekMs, trackModel, waitingSpec } from "./kiosk-track.js";
3
3
 
4
4
  // behold#631: chant-fanout's last finished cycle as cycles/chant-fanout/latest.json had it (cycle 499):
5
5
  // fifteen steps, two pull requests, from the change's open to the reset.
@@ -191,3 +191,41 @@ describe("the apply's jobs end the wait (behold#774)", () => {
191
191
  expect(waitingSpec(at("applying", []), { quietMs: 5_000 }).what).toBe("the pipeline to start the apply");
192
192
  });
193
193
  });
194
+
195
+ describe("a past step replays from its start (behold#787)", () => {
196
+ const ch = (n, short) => ({ n, of: 4, headline: short, short });
197
+ const chapters = [ch(1, "The change goes out"), ch(2, "cluster-a breaks"), ch(3, "The fix"), ch(4, "Done")];
198
+ const of = (step, i) => (step === "failed" ? chapters[1] : ["applied", "reset"].includes(step) ? chapters[3] : i < 6 ? chapters[0] : chapters[2]);
199
+ const track = cycleTrack({ ...cycle, steps: cycle.steps.map((s, i) => ({ ...s, chapter: of(s.step, i) })) });
200
+ const now = Date.parse(T("40:00"));
201
+
202
+ it("gives each segment already past its first step's time, and each chapter its first segment's", () => {
203
+ const m = trackModel(track, { demo: { step: "planned", pull: 13, chapter: chapters[2] }, pulls: [12, 13], since: now, now });
204
+ expect(m.chapters[0].segments.map((g) => g.seek)).toEqual([T("18:49"), T("19:01"), T("19:14"), T("19:27"), T("19:30")]);
205
+ expect(m.chapters.map((c) => c.seek)).toEqual([T("18:49"), T("19:49"), T("20:10"), null]);
206
+ // The current step and those ahead have no seek in the live cycle.
207
+ expect(m.chapters[2].segments.map((g) => g.seek)).toEqual([T("20:10"), null, null, null, null]);
208
+ });
209
+
210
+ it("lets a replay seek to any step but the one it shows, and never to the reset", () => {
211
+ const m = trackModel(track, { demo: { step: "failed", pull: 12, chapter: chapters[1] }, pulls: [12], since: now, now, replay: true });
212
+ expect(m.chapters[1].segments[0]).toMatchObject({ state: "current", seek: null });
213
+ expect(m.chapters[2].segments[4]).toMatchObject({ state: "ahead", seek: T("20:37") });
214
+ expect(m.chapters[3].segments.map((g) => [g.label, g.seek])).toEqual([["done", T("20:56")], ["reset", null]]);
215
+ });
216
+
217
+ it("measures a seek from the cycle's first step", () => {
218
+ expect(seekMs(cycle, T("19:49"))).toBe(60_000);
219
+ expect(seekMs(cycle, "2026-10-18T17:00:00Z")).toBe(0);
220
+ expect(seekMs(null, T("19:49"))).toBe(0);
221
+ });
222
+
223
+ it("starts a replay of the failure in the apply's last stretch, never before the apply", () => {
224
+ // The apply took 19 s, under the lead: the replay starts with it.
225
+ expect(failureAt(cycle)).toBe(new Date(T("19:30")).toISOString());
226
+ const long = { ...cycle, steps: cycle.steps.map((s) => (s.step === "applying" && s.pull === 641 ? { ...s, at: "2026-10-18T18:17:00Z" } : s)) };
227
+ expect(Date.parse(failureAt(long))).toBe(Date.parse(T("19:49")) - FAILURE_LEAD_MS);
228
+ expect(failureAt({ ...cycle, steps: cycle.steps.filter((s) => s.step !== "failed") })).toBeNull();
229
+ expect(failureAt(null)).toBeNull();
230
+ });
231
+ });
package/web/kiosk.html CHANGED
@@ -616,6 +616,13 @@
616
616
  .k-wf-sw { display: inline-block; width: 1.2em; height: 0.55em; border-radius: 2px; }
617
617
  .k-result-head { margin: 0 0 0.2em; font: 700 1.5em var(--font-ui); color: var(--managed); }
618
618
  .k-result-counts { list-style: none; margin: 0 0 var(--s3); padding: 0; display: flex; flex-wrap: wrap; gap: var(--s1) var(--s2); }
619
+ /* 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. */
620
+ .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; }
621
+ .k-result-replay { margin-top: var(--s3); color: var(--degraded); border-color: var(--degraded); background: color-mix(in srgb, var(--degraded) 12%, transparent); }
622
+ .k-result-replay:focus-visible, .k-replay-back:focus-visible { outline: 2px solid var(--fg); outline-offset: 2px; }
623
+ .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); }
624
+ body.k-watch #bar > .k-replay-asked { flex: 1 1 100%; }
625
+ @media (pointer: coarse), (max-width: 600px) { .k-result-replay, .k-replay-back { min-height: 44px; padding: 0 var(--s5); } }
619
626
  .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
627
  .k-result-counts li:first-child { border-color: var(--managed); font-weight: 600; }
621
628
  .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); }
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";
@@ -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,6 +1069,35 @@ 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). */
@@ -1084,7 +1114,9 @@ function drawWatchHead(bar, s, now) {
1084
1114
  // behold#741: a terragucci repo's chapter-carrying scenario names terragucci, its engine and its forge.
1085
1115
  // behold#746: a tool's page leaves out the parts (and the tooltip's sentence) that name what it may not.
1086
1116
  // 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;
1117
+ // behold#787: and on a replay the viewer asked for.
1118
+ const asked = !!(s.replay && s.replay.asked);
1119
+ const hide = vendor || asked ? (t) => (!!vendor && namesOther(t, s.vendor)) || (s.mode === "replay" && /^live\b/.test(t)) : null;
1088
1120
  if (s.chantLoop) place.appendChild(whatLineEl(demo, s.chantForge ? s.chantForge() : null, null, hide, s.source === "chant-demo"));
1089
1121
  else place.appendChild(whatLineEl(demo, s.tgForge || null, { tools: s.tools || [] }, hide));
1090
1122
  } else {
@@ -1092,8 +1124,9 @@ function drawWatchHead(bar, s, now) {
1092
1124
  place.appendChild(el("span", "k-cycle", cycleWords(demo, now)));
1093
1125
  }
1094
1126
  // 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));
1127
+ 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
1128
  bar.appendChild(place);
1129
+ if (s.mode === "replay" && s.replay && s.replay.asked) bar.appendChild(askedLine(s));
1097
1130
  const intro = introFor(s);
1098
1131
  if (intro) bar.appendChild(el("p", "k-w-intro", intro));
1099
1132
  const strip = el("ol", "k-strip");
@@ -1328,6 +1361,24 @@ export function drawResult(host, model, s) {
1328
1361
  if (bars.size) wf.appendChild(phaseKey());
1329
1362
  host.appendChild(wf);
1330
1363
  }
1364
+ // behold#787: a visitor who missed the failure's few seconds replays them from here.
1365
+ // The card is rebuilt every second: the press is read on the card, so a tap across a rebuild still counts.
1366
+ if (s.failureAt && s.failureAt()) {
1367
+ const b = el("button", "k-result-replay", FAILURE_WORDS);
1368
+ b.type = "button";
1369
+ host.appendChild(b);
1370
+ if (!host.krWired && host.addEventListener) {
1371
+ host.krWired = true;
1372
+ let down = 0;
1373
+ const on = (e) => !!(e.target && e.target.closest && e.target.closest(".k-result-replay"));
1374
+ host.addEventListener("pointerdown", (e) => { down = on(e) ? Date.now() : 0; });
1375
+ host.addEventListener("click", (e) => {
1376
+ const hit = on(e) || (down && Date.now() - down < 1500 && e.target === host);
1377
+ down = 0;
1378
+ if (hit && s.seekTo && s.failureAt()) s.seekTo(s.failureAt());
1379
+ });
1380
+ }
1381
+ }
1331
1382
  }
1332
1383
 
1333
1384
  /** behold#571: a wave's trace as one bar of its phases, a button that opens the whole trace. */
@@ -1762,10 +1813,65 @@ export function startKiosk({ bar, frame, side, main, views, read = null, tools =
1762
1813
  if (s.mode !== "replay" || !s.replay) return;
1763
1814
  const steps = s.replay.cycle.steps;
1764
1815
  const r = replayAt(steps, now().getTime() - s.replay.start);
1816
+ // behold#787: a replay the viewer asked for ends at the cycle's end (its reset), or after a while with no input.
1817
+ if (s.replay.asked && replayOver(steps, now().getTime() - s.replay.start, now().getTime() - s.replay.input)) return leaveReplay();
1765
1818
  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) });
1819
+ s.replay.banner = replayBanner(s.replay.cycle, s.replay.asked ? null : liveEstimate(s.live && s.live.demo, s.replay.cycle, now()));
1820
+ setDemo({ source: "replay", read: steps[r.index].at, demo: vendor ? scrubDemo(steps[r.index], tool) : steps[r.index] });
1821
+ };
1822
+ /** 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. */
1823
+ const rewind = () => {
1824
+ if (s.resetStory) s.resetStory();
1825
+ Object.assign(trackState, { cycle: null, pulls: [], key: null, since: null });
1826
+ runMemo = null;
1827
+ watchHoldAt = null;
1828
+ s.watchHeld = null;
1829
+ drawerWave = null;
1830
+ drawerView = null;
1831
+ lastShot = null;
1768
1832
  };
1833
+ /**
1834
+ * behold#787: replay the track's cycle from `at` (a step's time): the replay a tool's page shows, the viewer's
1835
+ * this time. Within a replay it seeks; the live poll leaves it alone until it ends.
1836
+ */
1837
+ s.seekTo = (at) => {
1838
+ const cycle = s.mode === "replay" && s.replay ? s.replay.cycle : s.lastCycle();
1839
+ if (!cycle || !Array.isArray(cycle.steps) || !cycle.steps.length) return;
1840
+ const start = now().getTime() - seekMs(cycle, at);
1841
+ if (s.mode === "replay" && s.replay) s.replay.start = start;
1842
+ else {
1843
+ s.replay = { cycle, start, at: null, banner: null, runs: null, asked: true };
1844
+ s.mode = "replay";
1845
+ s.repo = cycle.repo || s.repo;
1846
+ }
1847
+ s.replay.input = now().getTime();
1848
+ rewind();
1849
+ draw();
1850
+ };
1851
+ /** behold#787: the cycle's failure, where the done card's chip replays it from; null for a cycle with none. */
1852
+ s.failureAt = () => failureAt(s.mode === "replay" && s.replay ? s.replay.cycle : s.lastCycle());
1853
+ const leaveReplay = () => {
1854
+ if (!s.replay || !s.replay.asked) return;
1855
+ s.replay = null;
1856
+ s.mode = "live";
1857
+ rewind();
1858
+ if (!vendor && s.live) {
1859
+ s.repo = s.live.demo ? s.live.demo.repo : s.repo;
1860
+ setDemo(s.live);
1861
+ }
1862
+ void demo();
1863
+ };
1864
+ s.backToLive = () => {
1865
+ leaveReplay();
1866
+ draw();
1867
+ };
1868
+ // behold#787: any input keeps the viewer's replay going.
1869
+ if (typeof document !== "undefined" && document.addEventListener) {
1870
+ const touched = () => {
1871
+ if (s.replay && s.replay.asked) s.replay.input = now().getTime();
1872
+ };
1873
+ for (const ev of ["pointerdown", "keydown", "wheel"]) document.addEventListener(ev, touched, { passive: true, capture: true });
1874
+ }
1769
1875
 
1770
1876
  const draw = () => {
1771
1877
  followRepo();
@@ -1994,8 +2100,10 @@ export function startKiosk({ bar, frame, side, main, views, read = null, tools =
1994
2100
  }
1995
2101
  // behold#774: the run's own jobs say the apply started before its run view does.
1996
2102
  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 });
2103
+ 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
2104
  s.trackModel = model;
2105
+ // behold#787: a past step's segment replays it.
2106
+ if (model) model.onSeek = s.seekTo;
1999
2107
  drawTrack(trackHost, model);
2000
2108
  // In the trail's place: over the caption.
2001
2109
  const cap = shownCaption().getBoundingClientRect();
@@ -2416,6 +2524,8 @@ export function startKiosk({ bar, frame, side, main, views, read = null, tools =
2416
2524
  s.strip = null;
2417
2525
  /** behold#631: the running tool's last finished cycle, when one is published. */
2418
2526
  s.lastCycle = () => {
2527
+ // behold#787: while it replays, the replayed cycle, though a newer one has ended since.
2528
+ if (s.mode === "replay" && s.replay && s.replay.cycle) return s.replay.cycle;
2419
2529
  const d = s.demo && s.demo.demo;
2420
2530
  const t = vendor ? tool : d && typeof d.tool === "string" ? d.tool : null;
2421
2531
  const r = t ? strips.get(t) : null;
@@ -2464,19 +2574,23 @@ export function startKiosk({ bar, frame, side, main, views, read = null, tools =
2464
2574
  };
2465
2575
  const replayRuns = async () => {
2466
2576
  const r = s.replay;
2577
+ // behold#787: a replay the viewer ended while this read was out.
2578
+ if (!r) return [];
2467
2579
  if (r.runs) return r.runs;
2468
2580
  const idx = await fetchJson(reads.runs);
2469
2581
  const listed = new Map((idx && idx.doc && Array.isArray(idx.doc.runs) ? idx.doc.runs : []).map((x) => [x.id, x]));
2470
2582
  const runs = [];
2471
- for (const id of r.cycle.runs) {
2583
+ for (const id of Array.isArray(r.cycle.runs) ? r.cycle.runs : []) {
2472
2584
  const e = listed.get(id) || (await runDoc(id));
2473
2585
  if (e) runs.push(e);
2474
2586
  }
2475
- r.runs = runs.filter((x) => keepRun(x, { tool, repo: r.cycle.repo }));
2587
+ // behold#787: /kiosk names no tool; the cycle does.
2588
+ r.runs = runs.filter((x) => keepRun(x, { tool: tool || r.cycle.tool, repo: r.cycle.repo }));
2476
2589
  return r.runs;
2477
2590
  };
2478
2591
  const runsSource = () => {
2479
- if (!vendor || s.mode === "live") return null;
2592
+ // behold#787: /kiosk replays too, when the viewer asks.
2593
+ if (s.mode === "live") return null;
2480
2594
  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
2595
  return {
2482
2596
  index: async () => replayIndex(await replayRuns(), shownNow().getTime()),
@@ -2575,6 +2689,8 @@ export function startKiosk({ bar, frame, side, main, views, read = null, tools =
2575
2689
  * up; the story never goes back within a cycle.
2576
2690
  */
2577
2691
  const story = { cycle: null, n: 0, chapter: null, step: null };
2692
+ // behold#787: a seek may go back within a cycle; the story starts from where it lands.
2693
+ s.resetStory = () => Object.assign(story, { cycle: null, n: 0, chapter: null, step: null });
2578
2694
  /** behold#631: the forge chant's pipeline runs on, from its loop as /api/chant/pr read it. */
2579
2695
  s.chantForge = () => (ap.chant && ap.chant.loop && ap.chant.loop.forge) || null;
2580
2696
  s.storyDemo = (d) => {
@@ -2944,6 +3060,8 @@ export function startKiosk({ bar, frame, side, main, views, read = null, tools =
2944
3060
  noteRead(link, "poll", !readFailed(live), now());
2945
3061
  paintLink();
2946
3062
  s.live = live;
3063
+ // behold#787: the poll leaves a replay the viewer asked for alone; its end takes the live step from here.
3064
+ if (viewerReplay(s)) return draw();
2947
3065
  if (!vendor) {
2948
3066
  s.repo = live && live.demo ? live.demo.repo : null;
2949
3067
  setDemo(live);