@intentius/behold 0.29.40 → 0.29.42
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/AGENTS.md +180 -10
- package/README.md +6 -2
- package/dist/cli.js +16121 -13141
- package/example-writes/README.md +1 -1
- package/example-writes/chant.config.ts +0 -6
- package/package.json +5 -2
- package/web/app.js +327 -21
- package/web/carve-export.js +142 -0
- package/web/carve-narration.js +294 -0
- package/web/carve-narration.test.js +48 -0
- package/web/change-set-overlay.js +147 -0
- package/web/change-set-overlay.test.js +83 -0
- package/web/dots-border.js +66 -0
- package/web/dots-border.test.js +27 -0
- package/web/dots-kiosk.js +279 -0
- package/web/dots-kiosk.test.js +60 -0
- package/web/dots-layout.d.ts +10 -0
- package/web/dots-layout.js +201 -0
- package/web/dots-live.js +316 -0
- package/web/dots-live.test.js +220 -0
- package/web/dots-lod.js +122 -0
- package/web/dots-lod.test.js +78 -0
- package/web/dots-recording.d.ts +7 -0
- package/web/dots-recording.js +247 -0
- package/web/dots-recording.test.js +71 -0
- package/web/dots-scene.js +294 -0
- package/web/dots-scene.test.js +118 -0
- package/web/dots-timeline.js +128 -0
- package/web/dots-timeline.test.js +83 -0
- package/web/dots-tour.js +153 -0
- package/web/dots.js +2124 -0
- package/web/dots.test.js +15 -0
- package/web/event-help-modal.js +1 -1
- package/web/index.html +215 -121
- package/web/kiosk-carve.js +225 -0
- package/web/kiosk-carve.test.js +26 -0
- package/web/kiosk-event-help-ui.js +7 -1
- package/web/kiosk-link.js +68 -0
- package/web/kiosk-link.test.js +69 -0
- package/web/kiosk-metrics.js +2 -2
- package/web/kiosk-trace.js +1 -1
- package/web/kiosk.html +186 -135
- package/web/kiosk.js +65 -7
- package/web/motion.js +42 -0
- package/web/motion.test.js +64 -0
- package/web/operator.js +1 -1
- package/web/run-playhead.js +102 -19
- package/web/run-playhead.test.js +81 -11
- package/web/terralith.html +2 -2
- package/web/theme.js +99 -26
- package/web/theme.test.js +70 -6
- package/web/tooltip.js +212 -0
- package/web/tooltip.test.js +193 -0
- package/web/tour-player.js +204 -0
- package/web/tour-player.test.js +115 -0
- package/web/tours/behold.tour.v1.schema.json +182 -0
- package/web/tours/terralith.json +330 -0
- package/web/trunk-lane.js +406 -0
- package/web/trunk-lane.test.js +224 -0
- package/web/workspace-gates.js +29 -4
- package/web/workspace-gates.test.js +23 -2
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { readFileSync } from "node:fs";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { describe, expect, it } from "vitest";
|
|
4
|
+
import { overlayFrom } from "../src/change-set-overlay.ts";
|
|
5
|
+
import { gatesFromStatus } from "../src/workspace-gates.ts";
|
|
6
|
+
import { actionWords, attributeWords, BUCKETS, entriesFor, gapLines, nodeMarks, offGraph, overlayHeader, overlayLegend, valueWords } from "./change-set-overlay.js";
|
|
7
|
+
|
|
8
|
+
// #681: the overlay drawn from the stored change set chant printed for the
|
|
9
|
+
// fixture workspace (src/__fixtures__/change-set-overlay), as the route
|
|
10
|
+
// answers it: the release gate waiting in prod and its change set.
|
|
11
|
+
const FIX = join(import.meta.dirname, "..", "src", "__fixtures__", "change-set-overlay");
|
|
12
|
+
const fixture = (name) => JSON.parse(readFileSync(join(FIX, name), "utf8"));
|
|
13
|
+
const gates = gatesFromStatus(fixture("status-prod.json"), "/ws");
|
|
14
|
+
const { dir: _dir, ...gate } = gates.gates[0];
|
|
15
|
+
const answer = { workspace: true, chant: "0.124.28", ...overlayFrom(gate, fixture("change-set-show.json"), new Date("2026-10-16T00:00:00Z")) };
|
|
16
|
+
|
|
17
|
+
describe("the overlay's colours (#681)", () => {
|
|
18
|
+
it("draws create, change and delete in the drift legend's tokens", () => {
|
|
19
|
+
expect(BUCKETS.map((b) => [b.bucket, b.color])).toEqual([
|
|
20
|
+
["create", "var(--managed)"],
|
|
21
|
+
["change", "var(--foreign)"],
|
|
22
|
+
["delete", "var(--degraded)"],
|
|
23
|
+
]);
|
|
24
|
+
});
|
|
25
|
+
it("gives a legend row per bucket with its count, and counts what changes nothing", () => {
|
|
26
|
+
expect(overlayLegend(answer).map((r) => [r.label, r.count])).toEqual([
|
|
27
|
+
["create", 1],
|
|
28
|
+
["update or replace", 2],
|
|
29
|
+
["delete or forget", 1],
|
|
30
|
+
["no change (not drawn)", 1],
|
|
31
|
+
]);
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
describe("the overlay on the graph (#681)", () => {
|
|
36
|
+
it("marks each node the change set touches, with its colour and its actions", () => {
|
|
37
|
+
const marks = nodeMarks(answer);
|
|
38
|
+
expect(Object.keys(marks).sort()).toEqual(["web/AppBucket", "web/AppFunction", "web/AppQueue"]);
|
|
39
|
+
expect(marks["web/AppQueue"]).toMatchObject({ bucket: "create", color: "var(--managed)", tag: "create" });
|
|
40
|
+
expect(marks["web/AppFunction"]).toMatchObject({ bucket: "change", color: "var(--foreign)", tag: "replace" });
|
|
41
|
+
expect(marks["web/AppBucket"].title).toBe("change set 9cf74a6fee02 (preview, not applied):\nupdate AppBucket");
|
|
42
|
+
});
|
|
43
|
+
it("names the commit, gate and release it belongs to", () => {
|
|
44
|
+
expect(overlayHeader(answer)).toMatchObject({
|
|
45
|
+
lines: ["change set 9cf74a6fee02 · gate web/release/promote in prod", "commit a14610e · run run-9 · release 1a23268fa8b1 planned for prod"],
|
|
46
|
+
tone: "quiet",
|
|
47
|
+
});
|
|
48
|
+
expect(overlayHeader(answer).title).toContain("chant approve release promote --env prod");
|
|
49
|
+
});
|
|
50
|
+
it("says why when the change set wasn't read", () => {
|
|
51
|
+
const refusal = { error: "Change set needs chant 0.124.28 or newer. This project has chant 0.124.24.", code: "chant-too-old", remedy: "Upgrade" };
|
|
52
|
+
expect(overlayHeader({ workspace: true, refusal })).toEqual({ lines: [`change set not read: ${refusal.error}`], tone: "refusal", title: "Upgrade" });
|
|
53
|
+
expect(nodeMarks({ refusal })).toEqual({});
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
describe("a node's entries (#681)", () => {
|
|
58
|
+
it("lists address, action and fields when a node is clicked", () => {
|
|
59
|
+
expect(entriesFor(answer, "web/AppFunction")).toEqual([
|
|
60
|
+
{
|
|
61
|
+
head: "replace AppFunction",
|
|
62
|
+
bucket: "change",
|
|
63
|
+
color: "var(--foreign)",
|
|
64
|
+
facts: "AWS::Lambda::Function · disruption replace",
|
|
65
|
+
fields: ['FunctionName: before "cart-v1", after "cart-v2" (forces replacement)', "Environment: sensitive, not shown"],
|
|
66
|
+
},
|
|
67
|
+
]);
|
|
68
|
+
expect(entriesFor(answer, "web/AppBucket")[0].fields).toEqual(['VersioningConfiguration: before {"Status":"Suspended"}, after {"Status":"Enabled"}', 'Tags: before [{"Key":"team","Value":"cart"}], after: known after apply']);
|
|
69
|
+
expect(entriesFor(answer, "web/AppRole")).toEqual([]);
|
|
70
|
+
});
|
|
71
|
+
it("keeps the entries with no node in the side list, and those this view does not draw", () => {
|
|
72
|
+
const off = offGraph(answer, new Set(["web/AppQueue", "web/AppBucket"]));
|
|
73
|
+
expect(off.noNode.map((e) => e.head)).toEqual(["delete LegacyTopic"]);
|
|
74
|
+
expect(off.noNode[0].color).toBe("var(--degraded)");
|
|
75
|
+
expect(off.notDrawn.map((e) => [e.head, e.node])).toEqual([["replace AppFunction", "web/AppFunction"]]);
|
|
76
|
+
});
|
|
77
|
+
it("words the small things plainly", () => {
|
|
78
|
+
expect(actionWords({ create: 2, delete: 1 })).toBe("2 create, delete");
|
|
79
|
+
expect(attributeWords({ path: "a", after: 1 })).toBe("a: after 1");
|
|
80
|
+
expect(valueWords("x".repeat(200))).toHaveLength(80);
|
|
81
|
+
expect(gapLines({ ...answer, gaps: [{ member: "api", status: "failed", error: "no credentials", holes: [] }] })).toEqual([{ text: "api did not plan: no credentials, so its changes are not drawn", title: "" }]);
|
|
82
|
+
});
|
|
83
|
+
});
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
// Points along an estate box's border, for the lights that run around it
|
|
2
|
+
// (#712): the draw-in head, the running light, the landing ripple and a
|
|
3
|
+
// failure's red segment. A box is {x, y, w, h}; a position on the border is
|
|
4
|
+
// its distance `s` clockwise from the top-left corner. Pure.
|
|
5
|
+
|
|
6
|
+
export function perimeter(b) {
|
|
7
|
+
return 2 * (Math.max(0, b.w) + Math.max(0, b.h));
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/** The point at distance s (wrapped) clockwise from the top-left corner. */
|
|
11
|
+
export function pointAt(b, s) {
|
|
12
|
+
const P = perimeter(b);
|
|
13
|
+
if (!(P > 0)) return { x: b.x, y: b.y };
|
|
14
|
+
let d = ((s % P) + P) % P;
|
|
15
|
+
if (d <= b.w) return { x: b.x + d, y: b.y };
|
|
16
|
+
d -= b.w;
|
|
17
|
+
if (d <= b.h) return { x: b.x + b.w, y: b.y + d };
|
|
18
|
+
d -= b.h;
|
|
19
|
+
if (d <= b.w) return { x: b.x + b.w - d, y: b.y + b.h };
|
|
20
|
+
d -= b.w;
|
|
21
|
+
return { x: b.x, y: b.y + b.h - d };
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** The distance along the border of the border point nearest p. */
|
|
25
|
+
export function nearestS(b, p) {
|
|
26
|
+
const cx = Math.max(b.x, Math.min(b.x + b.w, p.x));
|
|
27
|
+
const cy = Math.max(b.y, Math.min(b.y + b.h, p.y));
|
|
28
|
+
const dl = Math.abs(cx - b.x);
|
|
29
|
+
const dr = Math.abs(b.x + b.w - cx);
|
|
30
|
+
const dt = Math.abs(cy - b.y);
|
|
31
|
+
const db = Math.abs(b.y + b.h - cy);
|
|
32
|
+
// Inside the box, project onto the nearest side; outside, the clamp is already on it.
|
|
33
|
+
const inside = p.x > b.x && p.x < b.x + b.w && p.y > b.y && p.y < b.y + b.h;
|
|
34
|
+
const m = inside ? Math.min(dl, dr, dt, db) : -1;
|
|
35
|
+
if ((inside && m === dt) || (!inside && cy === b.y)) return cx - b.x;
|
|
36
|
+
if ((inside && m === dr) || (!inside && cx === b.x + b.w)) return b.w + (cy - b.y);
|
|
37
|
+
if ((inside && m === db) || (!inside && cy === b.y + b.h)) return b.w + b.h + (b.x + b.w - cx);
|
|
38
|
+
return 2 * b.w + b.h + (b.y + b.h - cy);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* A polyline along the border from s0 for `len` (negative runs anticlockwise),
|
|
43
|
+
* with a vertex at every corner it passes, so it bends where the box does.
|
|
44
|
+
*/
|
|
45
|
+
export function segment(b, s0, len) {
|
|
46
|
+
const P = perimeter(b);
|
|
47
|
+
if (!(P > 0) || !len) return [];
|
|
48
|
+
const L = Math.max(-P, Math.min(P, len));
|
|
49
|
+
const corners = [0, b.w, b.w + b.h, 2 * b.w + b.h];
|
|
50
|
+
const pts = [pointAt(b, s0)];
|
|
51
|
+
const dir = Math.sign(L);
|
|
52
|
+
const a = s0;
|
|
53
|
+
const z = s0 + L;
|
|
54
|
+
// Every corner strictly between a and z, in travel order.
|
|
55
|
+
const between = [];
|
|
56
|
+
for (let k = Math.floor(Math.min(a, z) / P) - 1; k <= Math.ceil(Math.max(a, z) / P) + 1; k++) {
|
|
57
|
+
for (const c of corners) {
|
|
58
|
+
const s = c + k * P;
|
|
59
|
+
if ((dir > 0 && s > a && s < z) || (dir < 0 && s < a && s > z)) between.push(s);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
between.sort((p, q) => (dir > 0 ? p - q : q - p));
|
|
63
|
+
for (const s of between) pts.push(pointAt(b, s));
|
|
64
|
+
pts.push(pointAt(b, z));
|
|
65
|
+
return pts;
|
|
66
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { describe, it, expect } from "vitest";
|
|
2
|
+
import { perimeter, pointAt, nearestS, segment } from "./dots-border.js";
|
|
3
|
+
|
|
4
|
+
const b = { x: 0, y: 0, w: 10, h: 4 };
|
|
5
|
+
describe("estate box borders (#712)", () => {
|
|
6
|
+
it("walks the border clockwise from the top-left corner", () => {
|
|
7
|
+
expect(perimeter(b)).toBe(28);
|
|
8
|
+
expect(pointAt(b, 0)).toEqual({ x: 0, y: 0 });
|
|
9
|
+
expect(pointAt(b, 10)).toEqual({ x: 10, y: 0 });
|
|
10
|
+
expect(pointAt(b, 12)).toEqual({ x: 10, y: 2 });
|
|
11
|
+
expect(pointAt(b, 19)).toEqual({ x: 5, y: 4 });
|
|
12
|
+
expect(pointAt(b, 26)).toEqual({ x: 0, y: 2 });
|
|
13
|
+
expect(pointAt(b, 28 + 12)).toEqual({ x: 10, y: 2 });
|
|
14
|
+
expect(pointAt(b, -2)).toEqual({ x: 0, y: 2 });
|
|
15
|
+
});
|
|
16
|
+
it("finds the nearest border point, inside or outside", () => {
|
|
17
|
+
expect(nearestS(b, { x: 5, y: -3 })).toBe(5);
|
|
18
|
+
expect(nearestS(b, { x: 9.5, y: 2 })).toBe(12);
|
|
19
|
+
expect(pointAt(b, nearestS(b, { x: 5, y: 3.8 }))).toEqual({ x: 5, y: 4 });
|
|
20
|
+
expect(pointAt(b, nearestS(b, { x: 0.2, y: 2 }))).toEqual({ x: 0, y: 2 });
|
|
21
|
+
});
|
|
22
|
+
it("bends a segment round the corners it passes, either way", () => {
|
|
23
|
+
expect(segment(b, 8, 4)).toEqual([{ x: 8, y: 0 }, { x: 10, y: 0 }, { x: 10, y: 2 }]);
|
|
24
|
+
expect(segment(b, 2, -4)).toEqual([{ x: 2, y: 0 }, { x: 0, y: 0 }, { x: 0, y: 2 }]);
|
|
25
|
+
expect(segment(b, 3, 0)).toEqual([]);
|
|
26
|
+
});
|
|
27
|
+
});
|
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
// The dots layer in the kiosk (#712, #715): what Watch says and frames as a carve
|
|
2
|
+
// replays. Every beat is read off the scene, which is the recording's moves
|
|
3
|
+
// flown by unit (web/dots-scene.js): who moved where, which landed, which
|
|
4
|
+
// were refused. Pure: scene and time in, words and a focus out.
|
|
5
|
+
|
|
6
|
+
/** The kiosk's loop: the replay plays, holds on its result, then starts again. */
|
|
7
|
+
export const LOOP = { holdMs: 10_000 };
|
|
8
|
+
/** How long a Tips bubble stays up, and the least time between two. */
|
|
9
|
+
export const TIP = { showMs: 4_200, gapMs: 1_200, staleMs: 9_000 };
|
|
10
|
+
/** The director changes what it frames at most this often. */
|
|
11
|
+
export const DIRECTOR = { holdMs: 2_600 };
|
|
12
|
+
|
|
13
|
+
const fmt = (n) => Number(n).toLocaleString("en-US");
|
|
14
|
+
|
|
15
|
+
export function shortName(e, source) {
|
|
16
|
+
return e !== source && e.startsWith(`${source}-`) ? e.slice(source.length + 1) : e;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/** The carve's facts, once per scene. */
|
|
20
|
+
export function carveStory(scene) {
|
|
21
|
+
const moves = scene.flights.filter((f) => !f.parent);
|
|
22
|
+
const landing = scene.flights.filter((f) => f.ok);
|
|
23
|
+
const refusals = moves.filter((f) => !f.ok);
|
|
24
|
+
const firstLanding = new Map();
|
|
25
|
+
for (const f of landing) if (!firstLanding.has(f.to) || f.end < firstLanding.get(f.to).end) firstLanding.set(f.to, f);
|
|
26
|
+
const dests = [...firstLanding.keys()].sort();
|
|
27
|
+
return {
|
|
28
|
+
source: scene.source,
|
|
29
|
+
moves,
|
|
30
|
+
dests,
|
|
31
|
+
firstLanding,
|
|
32
|
+
firstRefusal: refusals.reduce((a, f) => (!a || f.end < a.end ? f : a), null),
|
|
33
|
+
start: moves.length ? Math.min(...moves.map((f) => f.start)) : 0,
|
|
34
|
+
end: scene.flights.length ? Math.max(...scene.flights.map((f) => f.end)) : 0,
|
|
35
|
+
refused: refusals.length,
|
|
36
|
+
resourcesMoved: landing.length,
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** Each estate's count at t, a dot counted where it is until it lands. */
|
|
41
|
+
export function countsNow(scene, t) {
|
|
42
|
+
const owners = new Map(scene.show.owners0);
|
|
43
|
+
for (const f of scene.landing) if (f.end <= t) owners.set(f.address, f.to);
|
|
44
|
+
const c = new Map();
|
|
45
|
+
for (const e of owners.values()) c.set(e, (c.get(e) ?? 0) + 1);
|
|
46
|
+
return c;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** The move flying most recently at t (not a child), or null. */
|
|
50
|
+
export function currentMove(story, t) {
|
|
51
|
+
let at = null;
|
|
52
|
+
for (const f of story.moves) if (f.start <= t && (!at || f.start > at.start)) at = f;
|
|
53
|
+
return at;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* What Watch says at replay time t: the title, the line under it, how many
|
|
58
|
+
* moves are left, and what the director frames.
|
|
59
|
+
*/
|
|
60
|
+
export function beatAt(story, scene, t) {
|
|
61
|
+
const src = story.source;
|
|
62
|
+
const n = story.dests.length;
|
|
63
|
+
const counts = countsNow(scene, t);
|
|
64
|
+
const left = story.moves.filter((f) => f.end > t).length;
|
|
65
|
+
const total = story.moves.length;
|
|
66
|
+
const next = { text: left ? `${fmt(left)} move${left === 1 ? "" : "s"} left` : "carve done", fraction: total ? (total - left) / total : 1 };
|
|
67
|
+
if (t < story.start) {
|
|
68
|
+
return {
|
|
69
|
+
phase: "start",
|
|
70
|
+
title: `Carving ${src} into ${n} team estates`,
|
|
71
|
+
line: { label: "now", text: `${fmt(counts.get(src) ?? 0)} resources in one estate, about to move by tag writes alone`, tone: "busy" },
|
|
72
|
+
next,
|
|
73
|
+
focus: { kind: "source" },
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
if (t >= story.end) {
|
|
77
|
+
const kept = counts.get(src) ?? 0;
|
|
78
|
+
return {
|
|
79
|
+
phase: "settled",
|
|
80
|
+
title: `Carved: ${n} estate${n === 1 ? "" : "s"}`,
|
|
81
|
+
line: {
|
|
82
|
+
label: "done",
|
|
83
|
+
text: `${fmt(story.resourcesMoved)} resources moved, nothing recreated` + (story.refused ? `; ${story.refused} moves refused, so ${fmt(kept)} stay in ${src}` : ""),
|
|
84
|
+
tone: "ok",
|
|
85
|
+
},
|
|
86
|
+
next,
|
|
87
|
+
focus: { kind: "all" },
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
const f = currentMove(story, t);
|
|
91
|
+
const refusedSoFar = story.moves.filter((m) => !m.ok && m.end <= t).length;
|
|
92
|
+
if (f && !f.ok) {
|
|
93
|
+
return {
|
|
94
|
+
phase: "carve",
|
|
95
|
+
title: `Carving ${src} into ${n} team estates`,
|
|
96
|
+
line: { label: "refused", text: `${f.address}: ${refusedSoFar > 1 ? `${refusedSoFar} moves refused` : "the move is refused"}; ${refusedSoFar > 1 ? "they stay" : "it stays"} in ${src}`, tone: "bad" },
|
|
97
|
+
next,
|
|
98
|
+
focus: { kind: "estate", estate: src },
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
const to = f ? f.to : src;
|
|
102
|
+
return {
|
|
103
|
+
phase: "carve",
|
|
104
|
+
title: `Carving ${src} into ${n} team estates`,
|
|
105
|
+
line: { label: "moving", text: `${shortName(to, src)}: ${fmt(counts.get(to) ?? 0)} resources moved, nothing recreated`, tone: "busy" },
|
|
106
|
+
next,
|
|
107
|
+
focus: { kind: "estate", estate: to },
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* The Tips bubbles that fire in (from, to]: each estate's first landing, the
|
|
113
|
+
* first refusal, and the end. Each has a key, so a loop shows it once.
|
|
114
|
+
*/
|
|
115
|
+
export function tipsBetween(story, from, to) {
|
|
116
|
+
const src = story.source;
|
|
117
|
+
const out = [];
|
|
118
|
+
const inWin = (t) => t > from && t <= to;
|
|
119
|
+
for (const e of story.dests) {
|
|
120
|
+
const f = story.firstLanding.get(e);
|
|
121
|
+
if (f && inWin(f.end)) out.push({ key: `land:${e}`, at: f.end, recordedAt: f.at, estate: e, tone: "ok", title: `${shortName(e, src)}: the first landing`, text: `${shortName(e, src)}: its first resource lands. live-mv rewrote the ownership tags; nothing was recreated.` });
|
|
122
|
+
}
|
|
123
|
+
const r = story.firstRefusal;
|
|
124
|
+
if (r && inWin(r.end)) {
|
|
125
|
+
const why = r.refusalSummary ? r.refusalSummary.replace(/\.$/, "").toLowerCase() : r.refusal || "refused";
|
|
126
|
+
out.push({ key: "refused", at: r.end, recordedAt: r.at, estate: src, address: r.address, tone: "bad", title: "A move is refused", text: `${r.address} is refused: ${why}. Nothing was written, so it stays in ${src}.` });
|
|
127
|
+
}
|
|
128
|
+
if (inWin(story.end)) out.push({ key: "end", at: story.end, recordedAt: story.moves.reduce((m, f) => Math.max(m, f.at || 0), 0) || null, estate: null, tone: "ok", title: "Carved", text: `Carved into ${story.dests.length} estate${story.dests.length === 1 ? "" : "s"} by tag writes alone: ${fmt(story.resourcesMoved)} resources moved, none recreated.` });
|
|
129
|
+
return out.sort((a, b) => a.at - b.at);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/** What the director frames: a focus held at least DIRECTOR.holdMs before it changes. */
|
|
133
|
+
export function directorFocus(prev, want, wall) {
|
|
134
|
+
const same = prev && prev.focus.kind === want.kind && prev.focus.estate === want.estate;
|
|
135
|
+
if (same) return prev;
|
|
136
|
+
// The start and the end always take over; a move to another estate waits its turn.
|
|
137
|
+
if (prev && want.kind === "estate" && prev.focus.kind === "estate" && wall - prev.since < DIRECTOR.holdMs) return prev;
|
|
138
|
+
return { focus: want, since: wall };
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
// --- the live carve (#715) -------------------------------------------------------
|
|
142
|
+
// The same beats over a carve that is being written: the title and the next
|
|
143
|
+
// line come from demo.json while a migration runs ("carve: 36 of 79 moved"),
|
|
144
|
+
// the line under the title from the newest progress line, and the end is the
|
|
145
|
+
// migration's own finish, not the last flight.
|
|
146
|
+
|
|
147
|
+
/** After a live carve ends, Watch holds on the result this long before handing the camera back. */
|
|
148
|
+
export const LIVE_HOLD_MS = 12_000;
|
|
149
|
+
|
|
150
|
+
const lineWords = {
|
|
151
|
+
moved: "moving",
|
|
152
|
+
stamped: "adopting",
|
|
153
|
+
refused: "refused",
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
/** The newest event of the show that has started by replay time t: a write's flight, or an adoption. */
|
|
157
|
+
export function latestEvent(scene, t) {
|
|
158
|
+
let at = null;
|
|
159
|
+
for (const f of scene.flights) if (!f.parent && f.start <= t && (!at || f.start >= at.start)) at = { ...f, kind: f.ok ? "moved" : "refused" };
|
|
160
|
+
const t0 = scene.show.t0;
|
|
161
|
+
for (const e of scene.show.events) {
|
|
162
|
+
if (e.kind !== "adopt" || e.before) continue;
|
|
163
|
+
const s = e.start - t0;
|
|
164
|
+
if (s <= t && (!at || s >= at.start)) at = { kind: "stamped", address: e.address, start: s, to: null, from: null };
|
|
165
|
+
}
|
|
166
|
+
return at;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* What Watch says over a live carve at replay time t. `ctx`: { demo, migration }
|
|
171
|
+
* from the route's answer (demo.json's fields, and the migration in view).
|
|
172
|
+
*/
|
|
173
|
+
export function liveBeat(scene, t, ctx = {}) {
|
|
174
|
+
const src = scene.source;
|
|
175
|
+
const story = carveStory(scene);
|
|
176
|
+
const counts = countsNow(scene, t);
|
|
177
|
+
const m = ctx.migration || null;
|
|
178
|
+
const demo = ctx.demo || null;
|
|
179
|
+
// The counts as played (web/dots-live.js playedCounts): the caption and the next line say the same numbers.
|
|
180
|
+
const shown = ctx.shown || null;
|
|
181
|
+
const c = m ? (shown ? shown.counts : m.counts) : null;
|
|
182
|
+
const total = c ? c.moved + c.stamped + c.refused + c.skipped + (c.left ?? 0) : story.moves.length;
|
|
183
|
+
const doneN = c ? c.moved + c.stamped + c.refused + c.skipped : story.moves.filter((f) => f.end <= t).length;
|
|
184
|
+
// demo.json's next line names the migration with the driver's count, read when it last looked; the page's own count replaces it.
|
|
185
|
+
const named = demo && demo.next ? /^\s*([^:\s]+):\s+\d+\s+of\s+\d+\s+(?:moved|stamped)\b/.exec(demo.next) : null;
|
|
186
|
+
const ours = !!(shown && m && (!demo || !demo.next || (named && named[1] === m.name)));
|
|
187
|
+
const nextText = ours
|
|
188
|
+
? `${m.name}: ${fmt(doneN)} of ${fmt(total)} ${c.stamped && !c.moved ? "stamped" : "moved"}`
|
|
189
|
+
: demo && demo.next
|
|
190
|
+
? demo.next
|
|
191
|
+
: m
|
|
192
|
+
? `${m.name}: ${fmt(c.moved + c.stamped)} of ${fmt(total)} ${c.stamped && !c.moved ? "stamped" : "moved"}`
|
|
193
|
+
: "no migration running";
|
|
194
|
+
const next = { text: nextText, fraction: total ? Math.min(1, doneN / total) : 0 };
|
|
195
|
+
const title = demo && demo.title ? demo.title : m ? `Carving ${src}: ${m.name}` : src;
|
|
196
|
+
const ev = latestEvent(scene, t);
|
|
197
|
+
const running = !!(m && (m.running || (shown && shown.playing)));
|
|
198
|
+
if (!ev) {
|
|
199
|
+
return {
|
|
200
|
+
phase: running ? "start" : "stock",
|
|
201
|
+
title,
|
|
202
|
+
line: { label: "now", text: `${fmt(counts.get(src) ?? 0)} resources in ${src}${running ? ", the migration is starting" : ""}`, tone: running ? "busy" : "idle" },
|
|
203
|
+
next,
|
|
204
|
+
focus: { kind: "source" },
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
if (!running && m) {
|
|
208
|
+
const kept = counts.get(src) ?? 0;
|
|
209
|
+
const r = resourceCounts(m);
|
|
210
|
+
const n = [...counts.entries()].filter(([e, v]) => v > 0 && e !== src).length;
|
|
211
|
+
return {
|
|
212
|
+
phase: "settled",
|
|
213
|
+
title,
|
|
214
|
+
line: {
|
|
215
|
+
label: "done",
|
|
216
|
+
text: `${m.name}: ${fmt(r.moved)} resources moved, ${fmt(r.stamped)} stamped, nothing recreated` + (r.refused ? `; ${r.refused} refused, so ${fmt(kept)} stay in ${src}` : "") + (n ? ` · ${n} estate${n === 1 ? "" : "s"} beside ${src}` : ""),
|
|
217
|
+
tone: r.refused ? "bad" : "ok",
|
|
218
|
+
},
|
|
219
|
+
next: { ...next, fraction: 1 },
|
|
220
|
+
focus: { kind: "all" },
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
if (ev.kind === "refused") {
|
|
224
|
+
return { phase: "carve", title, line: { label: "refused", text: `${ev.address}: ${ev.refusalSummary || "the move is refused"}; it stays in ${shortName(ev.from || src, src)}`, tone: "bad" }, next, focus: { kind: "estate", estate: ev.from || src } };
|
|
225
|
+
}
|
|
226
|
+
if (ev.kind === "stamped") {
|
|
227
|
+
return { phase: "carve", title, line: { label: lineWords.stamped, text: `${ev.address} wears its estate's tags now; nothing was recreated`, tone: "busy" }, next, focus: { kind: "source" } };
|
|
228
|
+
}
|
|
229
|
+
return { phase: "carve", title, line: { label: lineWords.moved, text: `${shortName(ev.to, src)}: ${fmt(counts.get(ev.to) ?? 0)} resources, moved by tag writes, nothing recreated`, tone: "busy" }, next, focus: { kind: "estate", estate: ev.to } };
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
/**
|
|
233
|
+
* The live carve's Tips that fire in (from, to]: each estate's first landing
|
|
234
|
+
* and the first refusal, from the flights. The end is told by the caller when
|
|
235
|
+
* the migration finishes ({@link liveEndTip}). Keys are stable across reads, so
|
|
236
|
+
* a bubble shows once however often the scene is rebuilt.
|
|
237
|
+
*/
|
|
238
|
+
export function liveTipsBetween(scene, from, to) {
|
|
239
|
+
const story = carveStory(scene);
|
|
240
|
+
const src = story.source;
|
|
241
|
+
const out = [];
|
|
242
|
+
const inWin = (t) => t > from && t <= to;
|
|
243
|
+
for (const e of story.dests) {
|
|
244
|
+
const f = story.firstLanding.get(e);
|
|
245
|
+
if (f && inWin(f.end)) out.push({ key: `land:${e}`, at: f.end, recordedAt: f.at, estate: e, tone: "ok", title: `${shortName(e, src)}: the first landing`, text: `${shortName(e, src)}: its first resource lands. The migration rewrote the ownership tags; nothing was recreated.` });
|
|
246
|
+
}
|
|
247
|
+
const r = story.firstRefusal;
|
|
248
|
+
if (r && inWin(r.end)) {
|
|
249
|
+
const why = r.refusalSummary ? r.refusalSummary.replace(/\.$/, "") : r.refusal || "refused";
|
|
250
|
+
out.push({ key: "refused", at: r.end, recordedAt: r.at, estate: r.from || src, address: r.address, tone: "bad", title: "A move is refused", text: `${r.address} is refused: ${why}. Nothing was written, so it stays in ${shortName(r.from || src, src)}.` });
|
|
251
|
+
}
|
|
252
|
+
return out.sort((a, b) => a.at - b.at);
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
/**
|
|
256
|
+
* A migration's counts in resources, not lines: a follower of two parents has
|
|
257
|
+
* a moved line under each (terragucci#1146), so the record's line counts can
|
|
258
|
+
* say 45 where 39 resources moved. With no lines, the record's own counts.
|
|
259
|
+
*/
|
|
260
|
+
export function resourceCounts(migration) {
|
|
261
|
+
const lines = (migration && migration.lines) || [];
|
|
262
|
+
if (!lines.length) return migration ? migration.counts : null;
|
|
263
|
+
const n = (o) => new Set(lines.filter((l) => l.outcome === o).map((l) => l.live_id || l.address)).size;
|
|
264
|
+
return { ...migration.counts, moved: n("moved"), stamped: n("stamped"), refused: n("refused"), skipped: n("skipped") };
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
/** The Tip for a migration that has just finished. */
|
|
268
|
+
export function liveEndTip(migration, t) {
|
|
269
|
+
const c = resourceCounts(migration);
|
|
270
|
+
return {
|
|
271
|
+
key: `end:${migration.name}`,
|
|
272
|
+
at: t,
|
|
273
|
+
recordedAt: null,
|
|
274
|
+
estate: null,
|
|
275
|
+
tone: c.refused ? "bad" : "ok",
|
|
276
|
+
title: `${migration.name}: done`,
|
|
277
|
+
text: `${migration.name} is done: ${fmt(c.moved)} resources moved and ${fmt(c.stamped)} stamped by tag writes alone, none recreated${c.refused ? `; ${c.refused} refused, left where they were` : ""}.`,
|
|
278
|
+
};
|
|
279
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { describe, it, expect } from "vitest";
|
|
2
|
+
import { readFileSync } from "node:fs";
|
|
3
|
+
import { gunzipSync } from "node:zlib";
|
|
4
|
+
import { fileURLToPath } from "node:url";
|
|
5
|
+
import { readCarve, carveShow } from "./dots-recording.js";
|
|
6
|
+
import { parentsOf } from "./dots-layout.js";
|
|
7
|
+
import { buildScene } from "./dots-scene.js";
|
|
8
|
+
import { carveStory, beatAt, tipsBetween, directorFocus, DIRECTOR, shortName } from "./dots-kiosk.js";
|
|
9
|
+
|
|
10
|
+
const text = gunzipSync(readFileSync(fileURLToPath(new URL("../scripts/dot-bench/carve-terralith-14.jsonl.gz", import.meta.url)))).toString("utf8");
|
|
11
|
+
const rec = readCarve(text);
|
|
12
|
+
const scene = buildScene(carveShow(rec, parentsOf(rec.roster)));
|
|
13
|
+
const story = carveStory(scene);
|
|
14
|
+
const src = "behold-terralith-14";
|
|
15
|
+
|
|
16
|
+
describe("the kiosk's carve beats (#712)", () => {
|
|
17
|
+
it("reads the carve's facts off the recording", () => {
|
|
18
|
+
expect(story.moves).toHaveLength(463);
|
|
19
|
+
expect(story.refused).toBe(14);
|
|
20
|
+
expect(story.dests).toHaveLength(8);
|
|
21
|
+
expect(story.firstRefusal.ok).toBe(false);
|
|
22
|
+
});
|
|
23
|
+
it("starts on one estate, says what moves, and ends carved", () => {
|
|
24
|
+
const start = beatAt(story, scene, 0);
|
|
25
|
+
expect(start.phase).toBe("start");
|
|
26
|
+
expect(start.title).toBe(`Carving ${src} into 8 team estates`);
|
|
27
|
+
expect(start.next.text).toBe("463 moves left");
|
|
28
|
+
expect(start.focus).toEqual({ kind: "source" });
|
|
29
|
+
const mid = beatAt(story, scene, (story.start + story.end) / 2);
|
|
30
|
+
expect(mid.phase).toBe("carve");
|
|
31
|
+
expect(mid.line.text).toMatch(/^(\w+: \d+ resources moved, nothing recreated|.+refused.+)$/);
|
|
32
|
+
const end = beatAt(story, scene, story.end);
|
|
33
|
+
expect(end.title).toBe("Carved: 8 estates");
|
|
34
|
+
expect(end.line.text).toMatch(/14 moves refused, so \d+ stay in behold-terralith-14/);
|
|
35
|
+
expect(end.next.fraction).toBe(1);
|
|
36
|
+
expect(end.focus).toEqual({ kind: "all" });
|
|
37
|
+
});
|
|
38
|
+
it("names a refusal while it is the latest move", () => {
|
|
39
|
+
const r = story.firstRefusal;
|
|
40
|
+
const b = beatAt(story, scene, r.start + 1);
|
|
41
|
+
expect(b.line.tone).toBe("bad");
|
|
42
|
+
expect(b.line.text).toContain(r.address);
|
|
43
|
+
});
|
|
44
|
+
it("tips each estate's first landing, the first refusal and the end, once each", () => {
|
|
45
|
+
const all = tipsBetween(story, -1, story.end);
|
|
46
|
+
expect(all.filter((t) => t.key.startsWith("land:"))).toHaveLength(8);
|
|
47
|
+
expect(all.filter((t) => t.key === "refused")).toHaveLength(1);
|
|
48
|
+
expect(all.at(-1).key).toBe("end");
|
|
49
|
+
const halves = [...tipsBetween(story, -1, story.end / 2), ...tipsBetween(story, story.end / 2, story.end)];
|
|
50
|
+
expect(halves.map((t) => t.key).sort()).toEqual(all.map((t) => t.key).sort());
|
|
51
|
+
expect(all.find((t) => t.key === "refused").text).toMatch(/Nothing was written/);
|
|
52
|
+
});
|
|
53
|
+
it("holds a framing before moving to another estate, but not at the start or end", () => {
|
|
54
|
+
const a = directorFocus(null, { kind: "estate", estate: "x" }, 0);
|
|
55
|
+
expect(directorFocus(a, { kind: "estate", estate: "y" }, DIRECTOR.holdMs - 1)).toBe(a);
|
|
56
|
+
expect(directorFocus(a, { kind: "estate", estate: "y" }, DIRECTOR.holdMs + 1).focus.estate).toBe("y");
|
|
57
|
+
expect(directorFocus(a, { kind: "all" }, 10).focus.kind).toBe("all");
|
|
58
|
+
expect(shortName(`${src}-billing`, src)).toBe("billing");
|
|
59
|
+
});
|
|
60
|
+
});
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// Types for src/dots-preview.ts, which orders the cards with the page's own layout (#712).
|
|
2
|
+
export function parseAddress(address: string): { module: string; type: string; name: string; index: string };
|
|
3
|
+
export function unitOf(address: string, type?: string): string;
|
|
4
|
+
export function unitsOf(roster: Array<{ address: string; type: string; taggable: boolean }>): any[];
|
|
5
|
+
export function parentsOf(roster: Array<{ address: string; type: string; taggable: boolean }>): Map<string, string>;
|
|
6
|
+
export function ringsOf(n: number, start?: number): Array<{ r: number; n: number }>;
|
|
7
|
+
export function unitCell(u: any): { rings: Array<{ r: number; n: number }>; shift: number; cell: number };
|
|
8
|
+
export function blockWidth(units: any[], aspect?: number): number;
|
|
9
|
+
export function packBlock(units: any[], opts?: { width?: number; fromEnd?: boolean }): any;
|
|
10
|
+
export function shelfPack(boxes: Array<{ key: string; w: number; h: number }>, opts: { width: number; gap?: number }): Map<string, { x: number; y: number }>;
|