@intentius/behold 0.29.21 → 0.29.22

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
@@ -20716,10 +20716,10 @@ function latestResolutionForPlan(records, gate, sinceIso, planDigest) {
20716
20716
  for (const r of records) {
20717
20717
  if (r.gate !== gate) continue;
20718
20718
  if (new Date(r.timestamp).getTime() < since) continue;
20719
- const newest2 = (best) => !best || new Date(r.timestamp).getTime() >= new Date(best.timestamp).getTime();
20719
+ const newest3 = (best) => !best || new Date(r.timestamp).getTime() >= new Date(best.timestamp).getTime();
20720
20720
  if (samePlanDigest(r.planDigest, planDigest)) {
20721
- if (newest2(matched)) matched = r;
20722
- } else if (newest2(mismatched)) {
20721
+ if (newest3(matched)) matched = r;
20722
+ } else if (newest3(mismatched)) {
20723
20723
  mismatched = r;
20724
20724
  }
20725
20725
  }
@@ -20956,13 +20956,13 @@ function overrideCommand(subject, rules, sealed = false) {
20956
20956
  }
20957
20957
  var time = (iso) => new Date(iso).getTime();
20958
20958
  function recordedDenials(pending) {
20959
- const newest2 = /* @__PURE__ */ new Map();
20959
+ const newest3 = /* @__PURE__ */ new Map();
20960
20960
  for (const p of pending) {
20961
20961
  if (p.op !== OVERRIDE_OP || !p.planDigest) continue;
20962
- const before = newest2.get(p.gate);
20963
- if (!before || time(p.timestamp) >= time(before.timestamp)) newest2.set(p.gate, p);
20962
+ const before = newest3.get(p.gate);
20963
+ if (!before || time(p.timestamp) >= time(before.timestamp)) newest3.set(p.gate, p);
20964
20964
  }
20965
- return [...newest2.values()].map((p) => {
20965
+ return [...newest3.values()].map((p) => {
20966
20966
  const r = p;
20967
20967
  return { ...p, plan: typeof r.plan === "string" ? r.plan : "", rules: Array.isArray(r.rules) ? sortedRules(r.rules.filter((x) => typeof x === "string")) : [] };
20968
20968
  }).sort((a, b) => a.gate < b.gate ? -1 : a.gate > b.gate ? 1 : 0);
@@ -23321,9 +23321,11 @@ async function readTerragucci(source2, opts = {}) {
23321
23321
  if (prRow && prDoc) pullRequest = pullRequestPlan(prDoc, under(prRow.path, "report.html"));
23322
23322
  const estateDoc = await readDoc(source2, "estate.json", "estate", v);
23323
23323
  const estateProject = estateDoc?.projects.find((p) => p.project === project);
23324
+ const behind = !!estateProject && rows.length > 0 && (Date.parse(rows[0].finished) || 0) > (Date.parse(estateDoc.generated) || 0);
23325
+ const fromEstate = !!estateProject && !behind;
23324
23326
  const waiting = [];
23325
23327
  const waitingRows = [];
23326
- if (estateProject) {
23328
+ if (fromEstate) {
23327
23329
  for (const w of estateProject.waiting) {
23328
23330
  const row = rows.find((r) => r.stage === "tf-apply" && r.commit === w.commit && r.wave === w.wave);
23329
23331
  if (row) waitingRows.push({ row, since: w.since });
@@ -23352,7 +23354,7 @@ async function readTerragucci(source2, opts = {}) {
23352
23354
  report: under(row.path, "report.html"),
23353
23355
  ...row.job_url ? { job_url: row.job_url } : {},
23354
23356
  command: terragucciApproveCommand(row.wave, digest),
23355
- from: estateProject ? "estate" : "index"
23357
+ from: fromEstate ? "estate" : "index"
23356
23358
  });
23357
23359
  }
23358
23360
  return {
@@ -23372,7 +23374,8 @@ async function readTerragucci(source2, opts = {}) {
23372
23374
  drifted: estateProject.drifted,
23373
23375
  failed: estateProject.failed,
23374
23376
  waiting: estateProject.waiting.length,
23375
- status: estateProject.status
23377
+ status: estateProject.status,
23378
+ ...behind ? { behind: true } : {}
23376
23379
  }
23377
23380
  } : {}
23378
23381
  };
@@ -24702,7 +24705,8 @@ function demoOf(d) {
24702
24705
  scenarios: positive(d.scenarios),
24703
24706
  index: positive(d.index),
24704
24707
  tool: text(d.tool),
24705
- repo: text(d.repo)
24708
+ repo: text(d.repo),
24709
+ delivery: text(d.delivery)
24706
24710
  };
24707
24711
  }
24708
24712
  function terragucciDemoRoute(app, source2, opts = {}) {
@@ -25079,6 +25083,8 @@ function terragucciRoutes(app, opts, dirs) {
25079
25083
  var METRICS_TTL_MS = 3e4;
25080
25084
  var RUN_WINDOW = "3h";
25081
25085
  var DORA_WINDOW = "7d";
25086
+ var DORA_STEP = "1m";
25087
+ var newest2 = (selector) => `last_over_time((max by (project) (${selector}))[${DORA_WINDOW}:${DORA_STEP}])`;
25082
25088
  var QUERIES = {
25083
25089
  waveSeconds: `max by (project, commit, run, wave) (last_over_time(terragucci_stage_duration_seconds{stage="tf-apply"}[${RUN_WINDOW}]))`,
25084
25090
  rootInit: `max by (project, commit, run, wave, root) (last_over_time(terragucci_root_init_seconds{stage="tf-apply"}[${RUN_WINDOW}]))`,
@@ -25090,10 +25096,11 @@ var QUERIES = {
25090
25096
  changes: `max by (project, commit, run, wave, action) (last_over_time(terragucci_wave_changes[${RUN_WINDOW}]))`,
25091
25097
  settled: `max by (project, commit, run, wave) (last_over_time(terragucci_wave_settled_seconds[${RUN_WINDOW}]))`,
25092
25098
  waiting: `max by (project, commit, run, wave) (last_over_time(terragucci_wave_waiting_since_seconds[${RUN_WINDOW}]))`,
25093
- deployments: `max by (project) (last_over_time(terragucci_dora_deployments_per_week[${DORA_WINDOW}]))`,
25094
- leadTime: `max by (project) (last_over_time(terragucci_dora_lead_time_seconds{segment="total"}[${DORA_WINDOW}]))`,
25095
- failureRate: `max by (project) (last_over_time(terragucci_dora_change_failure_ratio[${DORA_WINDOW}]))`,
25096
- restore: `max by (project) (last_over_time(terragucci_dora_restore_seconds[${DORA_WINDOW}]))`
25099
+ // behold#571: the newest gauge, never the largest over the window, so a rate that fell reads as it is now.
25100
+ deployments: newest2("terragucci_dora_deployments_per_week"),
25101
+ leadTime: newest2(`terragucci_dora_lead_time_seconds{segment="total"}`),
25102
+ failureRate: newest2("terragucci_dora_change_failure_ratio"),
25103
+ restore: newest2("terragucci_dora_restore_seconds")
25097
25104
  };
25098
25105
  var REPO = /^(?:[A-Za-z0-9][A-Za-z0-9._-]{0,99}\/)?[A-Za-z0-9._-]{1,100}$/;
25099
25106
  var COMMIT = /^[0-9a-f]{7,64}$/;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@intentius/behold",
3
- "version": "0.29.21",
3
+ "version": "0.29.22",
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.",
package/web/app.js CHANGED
@@ -4415,7 +4415,7 @@ function renderTerragucciPanel() {
4415
4415
  head.textContent = lg.text;
4416
4416
  head.title = lg.title;
4417
4417
  host.appendChild(head);
4418
- const est = estateLine(a);
4418
+ const est = estateLine(a, now);
4419
4419
  if (est) {
4420
4420
  const line = document.createElement("div");
4421
4421
  line.className = "tg-estate";
@@ -9,6 +9,10 @@
9
9
  //
10
10
  // The pane reads on its own: demo.json for the repo and commit the kiosk is
11
11
  // on (on a tool's page, that tool's repo), then the metrics. All GET.
12
+ //
13
+ // The delivery numbers on the demo are the loop's own (terragucci's
14
+ // stack/demo.sh runs terragucci estate after each cycle's audit): demo.json's
15
+ // `delivery` line says so over them, and the section shows no line without one.
12
16
 
13
17
  /** The localStorage key of the viewer's fold. */
14
18
  export const METRICS_STORE = "behold.kiosk.metrics";
@@ -67,9 +71,10 @@ export function clockWords(unix) {
67
71
 
68
72
  /**
69
73
  * What the pane shows, from one /api/metrics answer, or null for no pane:
70
- * `{ count, run: { label, waves: [{ head, rows: [[label, value, root?]] }] } | null, dora: [[label, value]] | null }`.
74
+ * `{ count, run: { label, waves: [{ head, rows: [[label, value, root?]] }] } | null, dora: [[label, value]] | null, note? }`.
75
+ * `note` is the line over the delivery numbers, demo.json's `delivery`, when there are numbers and a line.
71
76
  */
72
- export function metricsModel(answer) {
77
+ export function metricsModel(answer, delivery = null) {
73
78
  if (!answer || answer.error) return null;
74
79
  let run = null;
75
80
  if (answer.run && Array.isArray(answer.run.waves)) {
@@ -113,7 +118,8 @@ export function metricsModel(answer) {
113
118
  if (!run && !dora) return null;
114
119
  const n = run ? run.waves.length : 0;
115
120
  const count = [n ? `${n} ${n === 1 ? "wave" : "waves"}` : null, dora ? `${dora.length} delivery` : null].filter(Boolean).join(" · ");
116
- return { count, run, dora };
121
+ const note = dora && typeof delivery === "string" && delivery.trim() ? delivery.trim() : null;
122
+ return { count, run, dora, ...(note ? { note } : {}) };
117
123
  }
118
124
 
119
125
  /** The viewer's fold: true open, false folded, null when they never chose. */
@@ -168,6 +174,7 @@ body.k-has-metrics.k-notyet #view-pane { grid-row: 1; }
168
174
  .k-metrics-rows dt.k-metrics-root { font-family: var(--font-mono); color: var(--fg); }
169
175
  .k-metrics-rows dd { margin: 0; color: var(--fg); font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
170
176
  .k-metrics-dora { background: var(--surface-box); border-radius: 6px; padding: 0.3em 0.6em 0.35em; }
177
+ .k-metrics-note { margin: 0 0 0.3em; color: var(--muted); font-size: 0.92em; line-height: 1.35; }
171
178
  @media (max-width: 900px) and (min-width: 601px) { body.k-has-metrics #runs-main, body.k-has-metrics #view-pane { grid-row: auto; } body.k-has-metrics #k-metrics { grid-row: auto; grid-column: auto; } body.k-has-metrics #stage { grid-template-rows: none; } }
172
179
  @media (max-width: 600px) { #k-metrics, body.k-has-metrics #k-metrics { order: 2; margin: 0.6em 16px 0; max-height: none; } }
173
180
  `;
@@ -227,6 +234,7 @@ export function renderMetrics(host, model, { open = true, onToggle = () => {}, d
227
234
  }
228
235
  if (model.dora) {
229
236
  body.appendChild(el(doc, "h3", "k-metrics-label", "Delivery (DORA)"));
237
+ if (model.note) body.appendChild(el(doc, "p", "k-metrics-note", model.note));
230
238
  const box = el(doc, "div", "k-metrics-dora");
231
239
  box.appendChild(rowsEl(doc, model.dora));
232
240
  body.appendChild(box);
@@ -282,7 +290,7 @@ export function startMetrics(host, { tool = null, fetchJson = defaultFetch, stor
282
290
  const demo = await fetchJson("/api/terragucci/demo");
283
291
  const cycle = tool && !(demo && demo.demo && demo.demo.tool === tool) ? await fetchJson(`/api/terragucci/cycles/${tool}`) : null;
284
292
  const target = metricsTarget(demo, cycle, tool);
285
- const next = target ? metricsModel(await fetchJson(metricsUrl(target))) : null;
293
+ const next = target ? metricsModel(await fetchJson(metricsUrl(target)), demo && demo.demo ? demo.demo.delivery : null) : null;
286
294
  if (JSON.stringify(next) !== JSON.stringify(model)) {
287
295
  model = next;
288
296
  draw();
@@ -70,6 +70,16 @@ describe("kiosk metrics: what the pane shows", () => {
70
70
  const onlyDora = metricsModel({ run: null, dora: { from: "dora.json", restore_seconds: 600 } });
71
71
  expect(onlyDora).toEqual({ count: "1 delivery", run: null, dora: [["Time to restore", "10 min"]] });
72
72
  });
73
+
74
+ it("puts demo.json's delivery line over the delivery numbers, and only when there are numbers (behold#571)", () => {
75
+ const line = "Counted from this demo loop's own runs, where the failure scenario fails on purpose each cycle.";
76
+ expect(metricsModel(answer(), ` ${line}`).note).toBe(line);
77
+ expect(metricsModel(answer(), null).note).toBeUndefined();
78
+ expect(metricsModel(answer(), " ").note).toBeUndefined();
79
+ const noDora = { ...answer(), dora: null };
80
+ expect(metricsModel(noDora, line).note).toBeUndefined();
81
+ expect(metricsModel(noDora, line).dora).toBeNull();
82
+ });
73
83
  });
74
84
 
75
85
  describe("kiosk metrics: which repo, and the fold", () => {
package/web/terragucci.js CHANGED
@@ -127,12 +127,13 @@ export function waveCards(answer, now = new Date()) {
127
127
  }));
128
128
  }
129
129
 
130
- /** terragucci's own counts, as its estate page shows them, with the page's link. */
131
- export function estateLine(answer) {
130
+ /** terragucci's own counts, as its estate page shows them, with the page's link. A page older than the newest run says when it was written. */
131
+ export function estateLine(answer, now = new Date()) {
132
132
  if (!answer.estate) return null;
133
133
  const e = answer.estate;
134
+ const when = e.behind ? `, written ${ago(e.generated, now)}, before the newest run` : "";
134
135
  return {
135
- text: `terragucci's estate page: ${e.drifted} root${e.drifted === 1 ? "" : "s"} drifted · ${e.failed} failed · ${e.waiting} wave${e.waiting === 1 ? "" : "s"} waiting`,
136
+ text: `terragucci's estate page${when}: ${e.drifted} root${e.drifted === 1 ? "" : "s"} drifted · ${e.failed} failed · ${e.waiting} wave${e.waiting === 1 ? "" : "s"} waiting`,
136
137
  href: hrefOf(answer, e.html),
137
138
  };
138
139
  }
@@ -93,4 +93,11 @@ describe("a waiting wave is a gate card with a line to copy, never a button (#49
93
93
  });
94
94
  expect(estateLine({})).toBeNull();
95
95
  });
96
+
97
+ it("says when a page older than the newest run was written (behold#571)", () => {
98
+ const now = new Date("2026-10-16T08:30:00Z");
99
+ expect(estateLine({ files: "../../", estate: { drifted: 0, failed: 0, waiting: 0, html: "estate.html", generated: "2026-10-16T08:24:00Z", behind: true } }, now).text).toBe(
100
+ "terragucci's estate page, written 6m ago, before the newest run: 0 roots drifted · 0 failed · 0 waves waiting",
101
+ );
102
+ });
96
103
  });