sigrank 1.0.53 → 1.0.54

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/CHANGELOG.md CHANGED
@@ -12,7 +12,13 @@
12
12
  * "Update available" notice (header in the TUI, one line in plain CLI output). Non-blocking, 1.5s cap, silent offline, cached ~24h in `~/.sigrank-mcp/update-check.json`. Opt out with `SIGRANK_NO_UPDATE_CHECK=1` (also `NO_UPDATE_NOTIFIER`, `CI`).
13
13
  * Dashboard: the Your Cascade table scrolls reliably (↑/↓, j/k, PgUp/PgDn, Home/End). Combined rows are part of the scrollable table, the ▲/▼ hints are exact, and the view stays on the same row while platforms load in.
14
14
 
15
- ## Unreleased
15
+ ## 1.0.54 (2026-12-04)
16
+
17
+ ### Integrity
18
+
19
+ * New read-only MCP tool `check_integrity`: runs Tokenpull Integrity (record integrity, source agreement, cache pumping, double counting) over your local Claude Code logs and returns per-window flags, scores, codes, and a few samples as file ordinal + line. A flag means worth a look, not cheating. Nothing is sent or signed.
20
+ * `submit_verified` takes an optional `integrity: true` (default off). When on, the signed snapshot carries an `integrity` block of per-check flag counts and scores plus tool version and hash. No text, line numbers or session ids. `dry_run` shows it. With the flag off the payload is byte-identical. The board accepts the block (sigrank-app #521).
21
+ * TUI Dashboard: an integrity matrix (checks by windows; tick when clean, amber count when flagged, dash when not run) from a cached last result, refreshed by one detached background process at a time, with a 30-minute backoff after a failed run (`SIGRANK_NO_INTEGRITY=1` to opt out). Falls back to one line on small terminals and shows "not checked" until a result exists.
16
22
 
17
23
  ### TUI
18
24
 
package/README.md CHANGED
@@ -86,7 +86,7 @@ The entry point automatically runs an MCP stdio server when launched without a t
86
86
 
87
87
  | Task | Tools |
88
88
  | --- | --- |
89
- | Inspect local usage | `tokenpull`, `rank_windows`, `tokenpull_compare` |
89
+ | Inspect local usage | `tokenpull`, `rank_windows`, `tokenpull_compare`, `check_integrity` |
90
90
  | Calculate from supplied counts | `rank_paste`, `get_sigrank_standard_record` |
91
91
  | Read public results | `get_leaderboard`, `get_operator`, `discover_peers` |
92
92
  | Explore possible changes | `diagnose_cascade`, `simulate_change`, `suggest_improvements` |
@@ -0,0 +1,42 @@
1
+ // lib/integrity-worker.mjs — background runner for the TUI integrity status.
2
+ // Spawned detached by the TUI so the (seconds-long) transcript scan never shares its
3
+ // event loop. Runs the checks, writes ~/.sigrank-mcp/integrity-last.json (counts only,
4
+ // dir 0700, file 0600, same as the update-check cache), exits. No network.
5
+ import { chmodSync, mkdirSync, writeFileSync, renameSync } from "node:fs";
6
+ import { dirname } from "node:path";
7
+ import { runIntegrity, cacheEntry, integrityCachePath, acquireIntegrityLock, releaseIntegrityLock, writeIntegrityAttempt } from "./integrity.mjs";
8
+
9
+ const done = (code) => {
10
+ writeIntegrityAttempt(undefined, code === 0);
11
+ releaseIntegrityLock();
12
+ process.exit(code);
13
+ };
14
+ // One worker at a time; exit quietly if another is live.
15
+ if (!acquireIntegrityLock()) process.exit(0);
16
+ // Spawned detached so quitting the TUI does not kill a mid-scan worker; a hard time limit
17
+ // keeps a hung scan from lingering.
18
+ setTimeout(() => done(1), 10 * 60 * 1000).unref();
19
+ process.on("SIGTERM", () => done(1));
20
+ process.on("SIGINT", () => done(1));
21
+
22
+ async function main() {
23
+ const res = await runIntegrity();
24
+ const windows = {};
25
+ for (const [w, rep] of Object.entries(res.reports)) windows[w] = cacheEntry(rep);
26
+ const file = integrityCachePath();
27
+ const dir = dirname(file);
28
+ mkdirSync(dir, { recursive: true, mode: 0o700 });
29
+ const tmp = `${file}.${process.pid}.tmp`;
30
+ writeFileSync(tmp, JSON.stringify({ at: Date.now(), windows }), { mode: 0o600 });
31
+ try {
32
+ chmodSync(tmp, 0o600);
33
+ } catch {
34
+ /* best effort */
35
+ }
36
+ renameSync(tmp, file);
37
+ }
38
+
39
+ main().then(
40
+ () => done(0),
41
+ () => done(1),
42
+ );
@@ -0,0 +1,402 @@
1
+ // lib/integrity.mjs — Tokenpull Integrity wrapper for sigrank-mcp (check_integrity,
2
+ // submit_verified's optional integrity block, and the TUI status line).
3
+ //
4
+ // Vendored, not forked: ./vendor/tokenpull-integrity/ holds byte-identical copies of
5
+ // source repo : _7_labs/tokenpull-integrity (integrity/), commit 69360a7
6
+ // integrity.mjs sha256 13fbbc5111ceee707f300999c41af17e335993122cca77e7e7dfcae6608ba713
7
+ // humanlike.mjs sha256 fc86829f1d506d778d1c9a3b5a85da0061783afa95f8cda23a36cd38e5e954c6
8
+ // model/human-v1.json sha256 cb6492329bb5719e6b746bdf7e3b16795627ae863679a383e3bf6215a5006c0e
9
+ // (original filenames and layout kept: humanlike.mjs imports ./integrity.mjs and reads
10
+ // model/ next to itself). crossadapter.mjs and model/human-v1.lab.json (lab-only adversary
11
+ // results) are not vendored and must not ship. A test pins
12
+ // the sha256s. To upgrade, re-copy the files and update the pins here and in the test.
13
+ // The logic lives only in the vendored files. This module adds nothing to it: it iterates
14
+ // `report.checks` and never lists check names, so checks added later flow through.
15
+ //
16
+ // Local-only. Nothing here touches the network or writes outside the cache helpers below.
17
+
18
+ import { readFileSync, existsSync, writeFileSync, mkdirSync, unlinkSync } from "node:fs";
19
+ import { spawn } from "node:child_process";
20
+ import { homedir } from "node:os";
21
+ import { join, dirname } from "node:path";
22
+ import { fileURLToPath } from "node:url";
23
+ import {
24
+ listTranscripts,
25
+ readTranscripts,
26
+ otelFiles,
27
+ readOtel,
28
+ evaluate,
29
+ toolHash,
30
+ WINDOWS,
31
+ TOOL,
32
+ VERSION,
33
+ } from "./vendor/tokenpull-integrity/integrity.mjs";
34
+ import { MIN_PROMPTS, scoreSessions } from "./vendor/tokenpull-integrity/humanlike.mjs";
35
+
36
+ export const VENDORED_SHA256 = {
37
+ "integrity.mjs": "13fbbc5111ceee707f300999c41af17e335993122cca77e7e7dfcae6608ba713",
38
+ "humanlike.mjs": "fc86829f1d506d778d1c9a3b5a85da0061783afa95f8cda23a36cd38e5e954c6",
39
+ "model/human-v1.json": "cb6492329bb5719e6b746bdf7e3b16795627ae863679a383e3bf6215a5006c0e",
40
+ };
41
+ export const VENDORED_COMMIT = "69360a7";
42
+ export const INTEGRITY_WINDOWS = Object.keys(WINDOWS); // 7d, 30d, 90d, all
43
+ export { TOOL as INTEGRITY_TOOL, VERSION as INTEGRITY_VERSION };
44
+
45
+ /**
46
+ * The board's snapshot schema is strict (unknown fields are rejected). sigrank-app #521
47
+ * accepts the optional signed `integrity` block, so a real publish with integrity:true
48
+ * is allowed. Set false to refuse client-side again (dry_run always shows the block).
49
+ */
50
+ export const INTEGRITY_SERVER_ACCEPTS = true;
51
+
52
+ const here = dirname(fileURLToPath(import.meta.url));
53
+ const VENDOR_DIR = join(here, "vendor", "tokenpull-integrity");
54
+ const MODEL_FILE = join(VENDOR_DIR, "model", "human-v1.json");
55
+ // Same convention as the tool itself: first 16 hex of the sha256 of the file.
56
+ // The vendored toolHash(): sha256[:16] over integrity.mjs + humanlike.mjs + model/human-v1.json.
57
+ export const INTEGRITY_HASH = toolHash(VENDOR_DIR);
58
+
59
+ const SAMPLE_LIMIT = 5;
60
+
61
+ function defaultDataDir() {
62
+ try {
63
+ const c = JSON.parse(
64
+ readFileSync(join(homedir(), ".config", "sigrank-otel", "config.json"), "utf8"),
65
+ );
66
+ if (c && typeof c.dataDir === "string" && c.dataDir) {
67
+ return c.dataDir.replace(/^~(?=\/|$)/, homedir());
68
+ }
69
+ } catch {
70
+ /* no collector config */
71
+ }
72
+ return join(homedir(), ".local", "share", "sigrank-otel");
73
+ }
74
+
75
+ /**
76
+ * Run the checks. Reads transcripts + stored OTel rows once, evaluates each requested
77
+ * window. opts: { windows?: string[], roots?: string[], dataDir?: string, now?: number }.
78
+ * Returns { tool, version, hash, reports: { <window>: report } } with the vendored
79
+ * report objects untouched (the vendored evaluate() sets `hash` from toolHash()).
80
+ */
81
+ export async function runIntegrity(opts = {}) {
82
+ const windows = (opts.windows && opts.windows.length ? opts.windows : INTEGRITY_WINDOWS).filter(
83
+ (w) => w in WINDOWS,
84
+ );
85
+ const roots = opts.roots || [join(homedir(), ".claude", "projects")];
86
+ const now = opts.now ?? Date.now();
87
+ const files = listTranscripts(roots);
88
+ const tx = await readTranscripts(files, { now });
89
+ const op = otelFiles(opts.dataDir || defaultDataDir());
90
+ const otel = op.length ? await readOtel(op) : null;
91
+ // Check 3 (human likelihood), mirroring integrity.mjs main(): session scores carry the
92
+ // transcript ordinal; the path is dropped.
93
+ let human = null;
94
+ if (existsSync(MODEL_FILE)) {
95
+ const model = JSON.parse(readFileSync(MODEL_FILE, "utf8"));
96
+ const ord = new Map(files.map(([p], i) => [p, i]));
97
+ const sessions = (await scoreSessions(roots, model)).map((x) => ({ ...x, ordinal: ord.get(x.path) ?? null, path: undefined }));
98
+ human = { model, minPrompts: MIN_PROMPTS, sessions };
99
+ }
100
+ const reports = {};
101
+ for (const w of windows) {
102
+ const rep = evaluate({ tx, otel, windowName: w, now, human });
103
+ reports[w] = rep;
104
+ }
105
+ return { tool: TOOL, version: VERSION, hash: INTEGRITY_HASH, reports };
106
+ }
107
+
108
+ /** Total flags across every check in a report (checks without a flag count add 0). */
109
+ export function flagCount(report) {
110
+ let n = 0;
111
+ for (const c of Object.values(report?.checks || {})) {
112
+ if (c && Number.isFinite(c.flags)) n += c.flags;
113
+ }
114
+ return n;
115
+ }
116
+
117
+ /** One-line overall summary for a window. */
118
+ export function overallLine(report) {
119
+ const checks = Object.entries(report?.checks || {});
120
+ const ran = checks.filter(([, c]) => c && Number.isFinite(c.flags));
121
+ const skipped = checks.length - ran.length;
122
+ const n = flagCount(report);
123
+ return (
124
+ `${report.window}: ${n} flag${n === 1 ? "" : "s"} across ${ran.length} check${ran.length === 1 ? "" : "s"}` +
125
+ (skipped ? ` (${skipped} not run)` : "") +
126
+ ` · ${report.tool} v${report.version} (${report.hash}) · a flag means worth a look, not cheating · local only, nothing sent`
127
+ );
128
+ }
129
+
130
+ /** Per-check view for check_integrity: flags, score, codes, a few samples (ordinal + line). */
131
+ export function checkView(check) {
132
+ const c = check || {};
133
+ if (!Number.isFinite(c.flags)) {
134
+ return { status: c.status || "not_run", ...(c.reason ? { reason: c.reason } : {}) };
135
+ }
136
+ return {
137
+ flags: c.flags,
138
+ score: c.score ?? null,
139
+ codes: { ...(c.codes || {}) },
140
+ // e.g. human_likelihood: "calibrated on one operator ..." so a flag is not read as an accusation
141
+ ...(typeof c.calibration?.note === "string" ? { note: c.calibration.note } : {}),
142
+ sample: (c.sample || []).slice(0, SAMPLE_LIMIT).map((s) => ({
143
+ code: s.code,
144
+ file: s.file, // ordinal in the sorted transcript list, not a path
145
+ line: s.line,
146
+ })),
147
+ };
148
+ }
149
+
150
+ /** check_integrity result for one window. */
151
+ export function windowView(report) {
152
+ const checks = {};
153
+ for (const [name, c] of Object.entries(report.checks || {})) checks[name] = checkView(c);
154
+ return {
155
+ window: report.window,
156
+ from: report.from,
157
+ to: report.to,
158
+ population: report.population,
159
+ flags: flagCount(report),
160
+ checks,
161
+ overall: overallLine(report),
162
+ };
163
+ }
164
+
165
+ /**
166
+ * The block added to a signed snapshot when integrity is on. Scores and counts only:
167
+ * no samples, file ordinals, line numbers, text, paths or session ids. Check names and
168
+ * code names are the vendored tool's own fixed vocabulary; a check that did not run
169
+ * carries flags: null.
170
+ */
171
+ export function integrityBlock(report) {
172
+ const checks = {};
173
+ for (const [name, c] of Object.entries(report.checks || {})) {
174
+ const ran = c && Number.isFinite(c.flags);
175
+ const codes = {};
176
+ if (ran) {
177
+ for (const [k, v] of Object.entries(c.codes || {})) {
178
+ if (Number.isFinite(v)) codes[k] = v;
179
+ }
180
+ }
181
+ checks[name] = {
182
+ flags: ran ? c.flags : null,
183
+ score: ran && Number.isFinite(c.score) ? c.score : null,
184
+ codes,
185
+ };
186
+ }
187
+ return {
188
+ tool: report.tool,
189
+ version: report.version,
190
+ hash: report.hash,
191
+ window: report.window,
192
+ checks,
193
+ flagCount: flagCount(report),
194
+ };
195
+ }
196
+
197
+ // ── TUI cache: last result per window, written by a background worker ───────────
198
+ export const CACHE_TTL_MS = 6 * 60 * 60 * 1000;
199
+ export const integrityCachePath = (dir = process.env.SIGRANK_INTEGRITY_DIR || join(homedir(), ".sigrank-mcp")) =>
200
+ join(dir, "integrity-last.json");
201
+
202
+ /** Compact cache shape: counts only. */
203
+ export function cacheEntry(report) {
204
+ // checks: name -> flag count, or null when that check did not run (generic: no name list).
205
+ const checks = {};
206
+ for (const [name, c] of Object.entries(report.checks || {})) checks[name] = c && Number.isFinite(c.flags) ? c.flags : null;
207
+ return { flags: flagCount(report), version: report.version, hash: report.hash, checks };
208
+ }
209
+
210
+ /** Read the cache synchronously. Returns { at, windows: { <w>: {flags,version,hash} } } or null. */
211
+ export function readIntegrityCache(dir) {
212
+ try {
213
+ const c = JSON.parse(readFileSync(integrityCachePath(dir), "utf8"));
214
+ if (c && typeof c.at === "number" && c.windows && typeof c.windows === "object") return c;
215
+ } catch {
216
+ /* none yet */
217
+ }
218
+ return null;
219
+ }
220
+
221
+ /** One status line for a window; "not checked" until a cached result exists. */
222
+ export function statusLine(cache, window) {
223
+ const e = cache?.windows?.[window];
224
+ if (!e || !Number.isFinite(e.flags)) return `integrity: not checked · ${window}`;
225
+ return `integrity: ${e.flags} flag${e.flags === 1 ? "" : "s"} · checked ${window} · v${e.version}`;
226
+ }
227
+
228
+ // ── Single-worker lock: integrity-worker.lock = { pid, at }. A lock is live while its pid
229
+ // runs and it is younger than LOCK_MAX_AGE_MS; otherwise it is stale and is taken over.
230
+ export const LOCK_MAX_AGE_MS = 15 * 60 * 1000;
231
+ export const integrityLockPath = (dir) => join(dir || process.env.SIGRANK_INTEGRITY_DIR || join(homedir(), ".sigrank-mcp"), "integrity-worker.lock");
232
+ const pidAlive = (pid) => {
233
+ try {
234
+ process.kill(pid, 0);
235
+ return true;
236
+ } catch (e) {
237
+ return e.code === "EPERM";
238
+ }
239
+ };
240
+ /** True when another worker holds a live lock. */
241
+ export function integrityLockHeld(dir, { now = Date.now(), alive = pidAlive } = {}) {
242
+ try {
243
+ const l = JSON.parse(readFileSync(integrityLockPath(dir), "utf8"));
244
+ return Number.isInteger(l.pid) && now - l.at < LOCK_MAX_AGE_MS && alive(l.pid);
245
+ } catch {
246
+ return false;
247
+ }
248
+ }
249
+ /** Take the lock; false if a live one exists. Atomic create. A stale lock is removed only
250
+ * if its content is still what we read (two takeovers cannot both succeed: whoever loses the
251
+ * re-check, or the following exclusive create, backs off). */
252
+ export function acquireIntegrityLock(dir, { now = Date.now(), pid = process.pid, alive = pidAlive } = {}) {
253
+ const file = integrityLockPath(dir);
254
+ mkdirSync(dirname(file), { recursive: true, mode: 0o700 });
255
+ for (let i = 0; i < 3; i++) {
256
+ try {
257
+ writeFileSync(file, JSON.stringify({ pid, at: now }), { flag: "wx", mode: 0o600 });
258
+ return true;
259
+ } catch (e) {
260
+ if (e.code !== "EEXIST") return false;
261
+ let seen;
262
+ try { seen = readFileSync(file, "utf8"); } catch { continue; } // vanished: retry the create
263
+ if (integrityLockHeld(dir, { now, alive })) return false;
264
+ try {
265
+ if (readFileSync(file, "utf8") === seen) unlinkSync(file); // still the stale one we judged
266
+ } catch { /* someone else took it over */ }
267
+ }
268
+ }
269
+ return false;
270
+ }
271
+ export function releaseIntegrityLock(dir, pid = process.pid) {
272
+ try {
273
+ const l = JSON.parse(readFileSync(integrityLockPath(dir), "utf8"));
274
+ if (l.pid === pid) unlinkSync(integrityLockPath(dir));
275
+ } catch { /* gone */ }
276
+ }
277
+
278
+ // ── Attempt marker: integrity-attempt.json = { at, ok }. A failed or unfinished attempt blocks
279
+ // respawning for RETRY_MS, so a broken worker cannot be restarted on every TUI launch.
280
+ export const RETRY_MS = 30 * 60 * 1000;
281
+ export const integrityAttemptPath = (dir) => join(dir || process.env.SIGRANK_INTEGRITY_DIR || join(homedir(), ".sigrank-mcp"), "integrity-attempt.json");
282
+ export function writeIntegrityAttempt(dir, ok, now = Date.now()) {
283
+ try {
284
+ const f = integrityAttemptPath(dir);
285
+ mkdirSync(dirname(f), { recursive: true, mode: 0o700 });
286
+ writeFileSync(f, JSON.stringify({ at: now, ok }), { mode: 0o600 });
287
+ } catch { /* best effort */ }
288
+ }
289
+ export function readIntegrityAttempt(dir) {
290
+ try {
291
+ const a = JSON.parse(readFileSync(integrityAttemptPath(dir), "utf8"));
292
+ return a && typeof a.at === "number" ? a : null;
293
+ } catch { return null; }
294
+ }
295
+ /** Minutes until a retry is allowed after a failed/unfinished attempt, else 0. */
296
+ export function retryInMinutes(dir, now = Date.now()) {
297
+ const a = readIntegrityAttempt(dir);
298
+ if (!a || a.ok === true) return 0;
299
+ const left = RETRY_MS - (now - a.at);
300
+ return left > 0 ? Math.ceil(left / 60000) : 0;
301
+ }
302
+
303
+ const truthy = (v) => v != null && v !== "" && v !== "0" && v !== "false";
304
+
305
+ /** Opt out of the TUI's background check: SIGRANK_NO_INTEGRITY=1 (also set in CI). */
306
+ export function integrityBackgroundDisabled(env = process.env) {
307
+ return truthy(env.SIGRANK_NO_INTEGRITY) || truthy(env.CI);
308
+ }
309
+
310
+ /**
311
+ * Refresh the cache in a separate process when it is missing or older than CACHE_TTL_MS.
312
+ * Never blocks and never throws: returns null when nothing was started, else the child
313
+ * (unref'd, stdio ignored). onDone fires when the worker exits, so the caller can re-read
314
+ * the cache and redraw. opts: { dir, env, now, spawnFn }.
315
+ */
316
+ export function refreshIntegrityInBackground(onDone, opts = {}) {
317
+ try {
318
+ if (integrityBackgroundDisabled(opts.env)) return null;
319
+ const cache = readIntegrityCache(opts.dir);
320
+ const now = opts.now ?? Date.now();
321
+ if (cache && now - cache.at < CACHE_TTL_MS) return null;
322
+ if (retryInMinutes(opts.dir, now) > 0) return null; // backing off after a failed attempt
323
+ if (integrityLockHeld(opts.dir, { now, ...(opts.alive ? { alive: opts.alive } : {}) })) return null; // one worker at a time
324
+ writeIntegrityAttempt(opts.dir, null, now); // unfinished until the worker reports ok
325
+ const child = (opts.spawnFn || spawn)(
326
+ process.execPath,
327
+ [join(here, "integrity-worker.mjs")],
328
+ { stdio: "ignore", detached: true, windowsHide: true, env: { ...process.env, ...(opts.dir ? { SIGRANK_INTEGRITY_DIR: opts.dir } : {}) } },
329
+ );
330
+ child.on?.("exit", () => {
331
+ try {
332
+ onDone?.();
333
+ } catch {
334
+ /* ignore */
335
+ }
336
+ });
337
+ child.on?.("error", () => {});
338
+ child.unref?.();
339
+ return child;
340
+ } catch {
341
+ return null;
342
+ }
343
+ }
344
+
345
+ // ── TUI block: checks × windows matrix (same design as the site's matrix) ──────────
346
+ // ✓ clean (green) · N flags (amber, never red: a flag is "worth a look") · – not run (dim).
347
+ const SHORT = {
348
+ record_integrity: "records",
349
+ source_agreement: "sources",
350
+ cache_pumping: "cache",
351
+ human_likelihood: "human",
352
+ double_counting: "double",
353
+ cross_adapter: "adapters",
354
+ };
355
+ /** Short row label; an unknown check falls back to its key, shortened. */
356
+ export const checkLabel = (name) => SHORT[name] || String(name).replace(/_/g, " ").slice(0, 8);
357
+
358
+ export function ageLabel(ms) {
359
+ if (!Number.isFinite(ms) || ms < 0) return "just now";
360
+ const m = Math.floor(ms / 60000);
361
+ if (m < 1) return "just now";
362
+ if (m < 60) return `${m}m ago`;
363
+ const h = Math.floor(m / 60);
364
+ return h < 48 ? `${h}h ago` : `${Math.floor(h / 24)}d ago`;
365
+ }
366
+
367
+ const PLAIN = { ok: (s) => s, flag: (s) => s, off: (s) => s, head: (s) => s };
368
+ const MATRIX_MIN_WIDTH = 44;
369
+
370
+ /**
371
+ * Lines for the Dashboard (no leading indent). opts: { width, rows (spare lines),
372
+ * color: {ok, flag, off, head} painters or null for plain, now }.
373
+ * Matrix when it fits; else one line (statusLine for 7d); "not checked" until a cache exists.
374
+ */
375
+ export function renderIntegrityBlock(cache, { width = 80, rows = 99, color = null, now = Date.now(), retryIn = 0 } = {}) {
376
+ const P = color || PLAIN;
377
+ if (!cache || !cache.windows) {
378
+ if (rows < 1) return [];
379
+ return [`${P.head("INTEGRITY")} ${P.off(retryIn > 0 ? `integrity: check failed · retry in ${retryIn}m` : "not checked")}`];
380
+ }
381
+ const wins = INTEGRITY_WINDOWS.filter((w) => cache.windows[w]);
382
+ const names = [];
383
+ for (const w of wins) for (const n of Object.keys(cache.windows[w].checks || {})) if (!names.includes(n)) names.push(n);
384
+ const first = cache.windows[wins[0]] || {};
385
+ const need = 2 + names.length;
386
+ if (!names.length || rows < need || width < MATRIX_MIN_WIDTH) {
387
+ return rows >= 1 ? [P.off(statusLine(cache, "7d"))] : [];
388
+ }
389
+ const LW = Math.max(7, ...names.map((n) => checkLabel(n).length)) + 2, CW = 6;
390
+ const cell = (v) => {
391
+ if (v == null) return P.off("–".padStart(Math.ceil((CW + 1) / 2)).padEnd(CW));
392
+ if (v === 0) return P.ok("✓".padStart(Math.ceil((CW + 1) / 2)).padEnd(CW));
393
+ const t = v > 99 ? "99+" : String(v);
394
+ return P.flag(t.padStart(Math.ceil((CW + t.length) / 2)).padEnd(CW));
395
+ };
396
+ const out = [`${P.head("INTEGRITY")} ${P.off(`v${first.version} · ${String(first.hash || "").slice(0, 8)} · checked ${ageLabel(now - cache.at)}`)}`];
397
+ out.push(" ".repeat(LW) + wins.map((w) => P.off(w.padStart(Math.ceil((CW + w.length) / 2)).padEnd(CW))).join(""));
398
+ for (const n of names) {
399
+ out.push(checkLabel(n).padEnd(LW) + wins.map((w) => cell(cache.windows[w].checks?.[n])).join(""));
400
+ }
401
+ return out;
402
+ }