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.
@@ -27,6 +27,7 @@ import { pathToFileURL } from "node:url";
27
27
  import { pkgVersion } from "../lib/pkg-version.mjs";
28
28
  import { cachedUpdateNotice, checkForUpdate } from "../lib/update-check.mjs";
29
29
  import { LEADERBOARD_METRIC } from "../lib/constants.mjs";
30
+ import { readIntegrityCache, refreshIntegrityInBackground, renderIntegrityBlock, retryInMinutes } from "../lib/integrity.mjs";
30
31
 
31
32
  // Version read from the shared pkg-version helper (single source of truth —
32
33
  // matches cli.mjs; never hardcode, that's what caused the version drift).
@@ -35,6 +36,9 @@ const VERSION = pkgVersion();
35
36
  // "sigrank X available" text for the header; null unless runTui found a newer
36
37
  // release (cached result at launch, registry refresh in the background).
37
38
  let _updateNotice = null;
39
+ // Tokenpull Integrity status: last cached result (counts only), refreshed in a separate
40
+ // process at launch. Null until a result exists → the lines read "not checked".
41
+ let _integrityCache = null;
38
42
  const _updateVersion = () => (_updateNotice ? _updateNotice.split(" ")[1] : null);
39
43
 
40
44
  // Expensive platform readers that the Dashboard only runs on explicit user
@@ -1364,6 +1368,19 @@ function renderDashboard(data, status = "", scrollState = 0) {
1364
1368
  );
1365
1369
  }
1366
1370
 
1371
+ // Integrity block (checks × windows matrix) from the cached last result; never computed
1372
+ // here (a background process refreshes the cache). Falls back to one line, then nothing,
1373
+ // when there is no spare room. NO_COLOR / non-TTY: plain glyphs, no ANSI.
1374
+ {
1375
+ const spare = budget - used - 8;
1376
+ const useColor = !process.env.NO_COLOR && !!process.stdout.isTTY;
1377
+ const painters = useColor
1378
+ ? { ok: green, flag: (t) => paint(c.gold, t), off: dim, head: bold }
1379
+ : null;
1380
+ for (const line of renderIntegrityBlock(_integrityCache, { width: w, rows: spare, color: painters, retryIn: retryInMinutes() })) emit(` ${line}`);
1381
+ if (spare >= 1) emit();
1382
+ }
1383
+
1367
1384
  // (Υ Trend moved to the dedicated Trends tab [2] — every metric, with sub-views.)
1368
1385
 
1369
1386
  // ── Token Composition — lifetime per platform (owner 2026-10-15: "combine token
@@ -3386,6 +3403,14 @@ export async function runTui({
3386
3403
  })
3387
3404
  .catch(() => {});
3388
3405
 
3406
+ // Integrity status: show the cached last result at once, refresh in a separate process
3407
+ // when stale (never blocks the TUI; lines read "not checked" until a result exists).
3408
+ _integrityCache = readIntegrityCache();
3409
+ refreshIntegrityInBackground(() => {
3410
+ _integrityCache = readIntegrityCache();
3411
+ redraw().catch(() => {});
3412
+ });
3413
+
3389
3414
  // ── Initial data load
3390
3415
  const loadAll = async () => {
3391
3416
  // A2 (2026-06-27): paint the frame + a clear "reading your cascade…" status IMMEDIATELY,
package/proxy.mjs CHANGED
@@ -45,13 +45,13 @@ export function parseProxyPort(value, { allowZero = false } = {}) {
45
45
 
46
46
  function routeFor(pathname) {
47
47
  if (pathname === "/v1/messages") {
48
- return { backend: "anthropic", endpoint: "messages" };
48
+ return { backend: "anthropic", endpoint: "messages", path: "/v1/messages" };
49
49
  }
50
50
  if (pathname === "/v1/chat/completions") {
51
- return { backend: "openai", endpoint: "chat-completions" };
51
+ return { backend: "openai", endpoint: "chat-completions", path: "/v1/chat/completions" };
52
52
  }
53
53
  if (pathname === "/v1/responses") {
54
- return { backend: "openai", endpoint: "responses" };
54
+ return { backend: "openai", endpoint: "responses", path: "/v1/responses" };
55
55
  }
56
56
  return null;
57
57
  }
@@ -376,7 +376,10 @@ export async function startProxy({
376
376
  return;
377
377
  }
378
378
 
379
- const upstreamUrl = new URL(parsedUrl.pathname + parsedUrl.search, upstreamBase);
379
+ // Build the upstream URL from the fixed route path, never from the raw
380
+ // request target, so the client can only choose the query string.
381
+ const upstreamUrl = new URL(route.path, upstreamBase);
382
+ upstreamUrl.search = parsedUrl.search;
380
383
  // Defense-in-depth: verify the constructed URL origin matches the intended
381
384
  // upstream. This prevents an absolute-form request target (e.g.
382
385
  // "http://attacker.example/v1/messages") from overriding upstreamBase via
package/submit/index.mjs CHANGED
@@ -187,6 +187,13 @@ export function buildPayload(
187
187
  if (opts.report && typeof opts.report === "object") {
188
188
  payload.report = opts.report;
189
189
  }
190
+
191
+ // Optional Tokenpull Integrity block (submit_verified integrity:true). Scores and
192
+ // counts only — built by lib/integrity.mjs integrityBlock(). Absent unless the
193
+ // caller passes it, so the payload (and its signed bytes) are unchanged when off.
194
+ if (opts.integrity && typeof opts.integrity === "object") {
195
+ payload.integrity = opts.integrity;
196
+ }
190
197
  payload.agent.snapshot_hash = snapshotHash(payload);
191
198
  return payload;
192
199
  }
@@ -515,3 +515,31 @@ export const SUGGEST_OUTPUT = {
515
515
  },
516
516
  },
517
517
  };
518
+
519
+ export const INTEGRITY_OUTPUT = {
520
+ type: "object",
521
+ properties: {
522
+ tool: { type: "string", description: "Integrity tool name" },
523
+ version: { type: "string", description: "Integrity tool version" },
524
+ hash: { type: "string", description: "Hash of the integrity tool code that ran" },
525
+ overall: { type: "string", description: "One-line summary across the windows checked" },
526
+ windows: {
527
+ type: "array",
528
+ description: "One entry per window checked",
529
+ items: {
530
+ type: "object",
531
+ properties: {
532
+ window: { type: "string", enum: ["7d", "30d", "90d", "all"] },
533
+ flags: { type: "number", description: "Total flags across every check; a flag means worth a look, not cheating" },
534
+ population: { type: "object", description: "Requests, finished requests and sessions checked" },
535
+ checks: {
536
+ type: "object",
537
+ description:
538
+ "Result per check, keyed by check name: flags, score, codes (counts per flag code), a few samples as transcript-file ordinal + line. A check that could not run carries a status instead.",
539
+ },
540
+ overall: { type: "string", description: "One-line summary for this window" },
541
+ },
542
+ },
543
+ },
544
+ },
545
+ };
@@ -0,0 +1,54 @@
1
+ /**
2
+ * tools/check-integrity.mjs — check_integrity tool.
3
+ *
4
+ * Read-only Tokenpull Integrity: runs the vendored checks over your LOCAL Claude Code
5
+ * transcripts and stored collector rows. Nothing is sent or signed.
6
+ */
7
+
8
+ import { INTEGRITY_OUTPUT, ANNOTATIONS } from "./_schemas.mjs";
9
+ import {
10
+ INTEGRITY_WINDOWS,
11
+ runIntegrity,
12
+ windowView,
13
+ flagCount,
14
+ overallLine,
15
+ } from "../lib/integrity.mjs";
16
+
17
+ export const TOOL_DEF = {
18
+ name: "check_integrity",
19
+ description:
20
+ "Run Tokenpull Integrity over your LOCAL data and report, per window (7d/30d/90d/all-time), each check's result: flags, score, flag codes, and a few samples as transcript-file ordinal + line number. Checks cover record integrity, agreement between transcripts and the live collector, cache pumping, and double counting. A flag means 'worth a look', not 'cheating'. Reads Claude Code session logs and stored collector rows on this machine; no text, paths or session ids are returned, and nothing is sent or signed. Returns the tool version and hash so a run can be reproduced. To attach a scores-and-counts summary to a signed submission, use submit_verified with integrity: true.",
21
+ annotations: { title: "Check integrity", ...ANNOTATIONS.readOnlyHint, ...ANNOTATIONS.openWorldHint },
22
+ inputSchema: {
23
+ type: "object",
24
+ properties: {
25
+ window: {
26
+ type: "string",
27
+ enum: ["7d", "30d", "90d", "all"],
28
+ description: "check only this window (default: all 4)",
29
+ },
30
+ },
31
+ },
32
+ outputSchema: INTEGRITY_OUTPUT,
33
+ };
34
+
35
+ export async function handleCheckIntegrity(args, ctx) {
36
+ const windows = args?.window !== undefined ? [args.window] : INTEGRITY_WINDOWS;
37
+ if (!INTEGRITY_WINDOWS.includes(windows[0])) {
38
+ return { status: "error", reason: "bad_window", detail: `window must be one of ${INTEGRITY_WINDOWS.join(", ")}.` };
39
+ }
40
+ const io = ctx?.opts?.integrity || {};
41
+ const res = await runIntegrity({ windows, roots: io.roots, dataDir: io.dataDir, now: ctx?.opts?.now ?? io.now });
42
+ const reps = windows.map((w) => res.reports[w]);
43
+ const total = reps.reduce((n, r) => n + flagCount(r), 0);
44
+ return {
45
+ tool: res.tool,
46
+ version: res.version,
47
+ hash: res.hash,
48
+ overall:
49
+ reps.length === 1
50
+ ? overallLine(reps[0])
51
+ : `${total} flag${total === 1 ? "" : "s"} across ${reps.length} windows · ${res.tool} v${res.version} (${res.hash}) · a flag means worth a look, not cheating · local only, nothing sent`,
52
+ windows: reps.map(windowView),
53
+ };
54
+ }
package/tools/index.mjs CHANGED
@@ -25,6 +25,7 @@ import { TOOL_DEF as tokenpullSubmitTool, handleTokenpullSubmit } from "./tokenp
25
25
  import { TOOL_DEF as rankWindowsTool, handleRankWindows } from "./rank-windows.mjs";
26
26
  import { TOOL_DEF as watchTokenpullTool, handleWatchTokenpull } from "./watch-tokenpull.mjs";
27
27
  import { TOOL_DEF as tokenpullCompareTool, handleTokenpullCompare } from "./tokenpull-compare.mjs";
28
+ import { TOOL_DEF as checkIntegrityTool, handleCheckIntegrity } from "./check-integrity.mjs";
28
29
  import { TOOL_DEF as enrollTool, handleEnroll } from "./enroll.mjs";
29
30
  import { TOOL_DEF as submitVerifiedTool, handleSubmitVerified } from "./submit-verified.mjs";
30
31
  import { TOOL_DEF as simulateChangeTool, handleSimulateChange } from "./simulate-change.mjs";
@@ -59,6 +60,7 @@ export const TOOLS = [
59
60
  rankWindowsTool,
60
61
  watchTokenpullTool,
61
62
  tokenpullCompareTool,
63
+ checkIntegrityTool,
62
64
  enrollTool,
63
65
  submitVerifiedTool,
64
66
  simulateChangeTool,
@@ -211,6 +213,8 @@ export async function callTool(name, args, opts = {}) {
211
213
  return handleWatchTokenpull(args, ctx);
212
214
  case "tokenpull_compare":
213
215
  return handleTokenpullCompare(args, ctx);
216
+ case "check_integrity":
217
+ return handleCheckIntegrity(args, ctx);
214
218
  case "enroll":
215
219
  return handleEnroll(args, ctx);
216
220
  case "submit_verified":
@@ -9,6 +9,7 @@ import { SUBMIT_OUTPUT, ANNOTATIONS } from "./_schemas.mjs";
9
9
  import { collectMultiPlatforms, multiAbortResult } from "./_multi.mjs";
10
10
  import { pullByPlatform, WINDOW_TYPE } from "./_helpers.mjs";
11
11
  import { _computeReportBlock } from "./_report.mjs";
12
+ import { runIntegrity, integrityBlock, INTEGRITY_SERVER_ACCEPTS } from "../lib/integrity.mjs";
12
13
  import { normalizeSource, OTEL_SOURCE_TAG } from "../adapters/otel.mjs";
13
14
  import {
14
15
  evaluatePublication,
@@ -21,7 +22,7 @@ import {
21
22
  export const TOOL_DEF = {
22
23
  name: "submit_verified",
23
24
  description:
24
- "Publish your LOCAL token runs to the SigRank board as a VERIFIED operator — the enrolled, signed path. Reads your pillars (tokenpull), builds the canonical Schema 1.0 snapshot per window, ed25519-signs it with your device key, and POSTs to /api/v1/snapshots. Requires `npx sigrank enroll` first (a bound device). Only signed submissions from a trusted device rank on the board. Token-only; the private key never leaves your machine. Publishing requires `confirm: true` (ask the user first); pass dry_run:true to inspect the exact signed payload without publishing and without confirm.",
25
+ "Publish your LOCAL token runs to the SigRank board as a VERIFIED operator — the enrolled, signed path. Reads your pillars (tokenpull), builds the canonical Schema 1.0 snapshot per window, ed25519-signs it with your device key, and POSTs to /api/v1/snapshots. Requires `npx sigrank enroll` first (a bound device). Only signed submissions from a trusted device rank on the board. Token-only; the private key never leaves your machine. Publishing requires `confirm: true` (ask the user first); pass dry_run:true to inspect the exact signed payload without publishing and without confirm. Optional `integrity: true` (default off) adds a Tokenpull Integrity block to the signed snapshot: per-check flag counts and scores plus the tool version and hash, no text, line numbers or session ids (Claude only; run check_integrity first to see the detail).",
25
26
  annotations: {
26
27
  title: "Submit verified score",
27
28
  ...ANNOTATIONS.destructiveHint,
@@ -53,6 +54,11 @@ export const TOOL_DEF = {
53
54
  description:
54
55
  "REQUIRED to publish: must be true, set only after the user has explicitly approved submitting. Not needed with dry_run:true.",
55
56
  },
57
+ integrity: {
58
+ type: "boolean",
59
+ description:
60
+ "default false. When true, add an `integrity` block (tool, version, hash, window, per-check flags/score/codes, flagCount) to each signed snapshot. Scores and counts only. Claude platform only. Use dry_run:true to see the block before publishing.",
61
+ },
56
62
  dry_run: {
57
63
  type: "boolean",
58
64
  description:
@@ -86,6 +92,37 @@ export async function handleSubmitVerified(args, ctx) {
86
92
  }
87
93
  const pullOpts = { ...ctx.opts, source };
88
94
 
95
+ // Optional integrity block (default off). Claude transcripts only: the checks read
96
+ // Claude Code logs, so a block on another platform or on the combined cascade would
97
+ // describe data the snapshot does not contain.
98
+ const wantIntegrity = args?.integrity === true;
99
+ if (wantIntegrity && platform !== "claude") {
100
+ return { status: "error", reason: "integrity_claude_only", detail: "integrity: true is available for platform: claude only.", windows: [] };
101
+ }
102
+ if (wantIntegrity && !args?.dry_run && !INTEGRITY_SERVER_ACCEPTS) {
103
+ return {
104
+ status: "error",
105
+ reason: "integrity_not_accepted_yet",
106
+ detail: "The board does not accept an integrity block yet (its snapshot schema is strict). Use dry_run: true to inspect the block, or publish without integrity.",
107
+ windows: [],
108
+ };
109
+ }
110
+ let integrityRun = null;
111
+ if (wantIntegrity) {
112
+ try {
113
+ integrityRun = await runIntegrity({
114
+ windows: args?.window ? [args.window] : undefined,
115
+ roots: ctx.opts.integrity?.roots,
116
+ dataDir: ctx.opts.integrity?.dataDir,
117
+ now: ctx.opts.now,
118
+ });
119
+ } catch (e) {
120
+ return { status: "error", reason: "integrity_failed", detail: `Integrity checks failed to run: ${e.message}. Nothing was sent; retry, or submit without integrity.`, windows: [] };
121
+ }
122
+ }
123
+ const integrityFor = (wk) =>
124
+ integrityRun?.reports?.[wk] ? { integrity: integrityBlock(integrityRun.reports[wk]) } : {};
125
+
89
126
  // MULTI: the combined cross-platform cascade. The dashboard already SUMS every
90
127
  // active platform's pillars (a "claude+codex" row) but never submitted it — this
91
128
  // is that missing submission. Aggregate every locally-detected platform's pillars
@@ -201,7 +238,14 @@ export async function handleSubmitVerified(args, ctx) {
201
238
  force: !!ctx.opts.force,
202
239
  report,
203
240
  ...measureWindow(w, local),
241
+ ...integrityFor(w.window),
204
242
  });
243
+ const sent = integrityFor(w.window);
244
+ if (sent.integrity && r.httpStatus >= 400 && r.httpStatus < 500) {
245
+ const why = r.detail || r.reason;
246
+ r.reason = "integrity_block_rejected";
247
+ r.detail = `The board rejected this snapshot with HTTP ${r.httpStatus} and it carried an integrity block (${why}). The integrity block may be the cause; retry without integrity: true.`;
248
+ }
205
249
  out.push({
206
250
  window: w.window,
207
251
  pillars: w.pillars,