pi-mega-compact 0.19.3 → 0.20.1

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.
Files changed (114) hide show
  1. package/dist/config/vector-cortex.js +24 -0
  2. package/dist/config.js +1 -1
  3. package/dist/extensions/dashboard-server/routes-cache.test/_helpers.js +2 -0
  4. package/dist/extensions/dashboard-server/routes-rag-settings-helpers.js +2 -0
  5. package/dist/extensions/dashboard-server/routes-vector-cortex-helpers.js +100 -0
  6. package/dist/extensions/dashboard-server/routes-vector-cortex-residual.js +51 -0
  7. package/dist/extensions/dashboard-server/routes-vector-cortex-shards.js +48 -0
  8. package/dist/extensions/dashboard-server/routes-vector-cortex.js +2 -0
  9. package/dist/extensions/dashboard-server/routes.js +1 -1
  10. package/dist/extensions/dashboard-server/server.js +41 -16
  11. package/dist/extensions/dashboard-server/tailscale.js +32 -0
  12. package/dist/src/config/vector-cortex.js +24 -0
  13. package/dist/src/config.js +1 -1
  14. package/dist/src/vector-cortex/residual/codec.js +224 -0
  15. package/dist/src/vector-cortex/residual/dct.js +158 -0
  16. package/dist/src/vector-cortex/residual/fixture-payload.js +77 -0
  17. package/dist/src/vector-cortex/residual/gf256.js +182 -0
  18. package/dist/src/vector-cortex/residual/parity.js +245 -0
  19. package/dist/src/vector-cortex/residual/quantize.js +200 -0
  20. package/dist/src/vector-cortex/residual/stream.js +124 -0
  21. package/dist/src/vector-cortex/residual/types.js +55 -0
  22. package/dist/src/vector-cortex/shards/exact.js +134 -0
  23. package/dist/src/vector-cortex/shards/manifest.js +237 -0
  24. package/dist/src/vector-cortex/shards/semantic.js +137 -0
  25. package/dist/src/vector-cortex/shards/types.js +51 -0
  26. package/dist/vector-cortex/residual/codec.js +224 -0
  27. package/dist/vector-cortex/residual/dct.js +158 -0
  28. package/dist/vector-cortex/residual/fixture-payload.js +77 -0
  29. package/dist/vector-cortex/residual/gf256.js +182 -0
  30. package/dist/vector-cortex/residual/parity.js +245 -0
  31. package/dist/vector-cortex/residual/quantize.js +200 -0
  32. package/dist/vector-cortex/residual/stream.js +124 -0
  33. package/dist/vector-cortex/residual/types.js +55 -0
  34. package/dist/vector-cortex/shards/exact.js +134 -0
  35. package/dist/vector-cortex/shards/manifest.js +237 -0
  36. package/dist/vector-cortex/shards/semantic.js +137 -0
  37. package/dist/vector-cortex/shards/types.js +51 -0
  38. package/extensions/dashboard-client/dist/assets/{AreaChart-DqiFSnDx.js → AreaChart-n4z5w9Ox.js} +2 -2
  39. package/extensions/dashboard-client/dist/assets/{AreaChart-DqiFSnDx.js.map → AreaChart-n4z5w9Ox.js.map} +1 -1
  40. package/extensions/dashboard-client/dist/assets/{BarChart-Cqg-PQMK.js → BarChart-BLGjWWBr.js} +2 -2
  41. package/extensions/dashboard-client/dist/assets/{BarChart-Cqg-PQMK.js.map → BarChart-BLGjWWBr.js.map} +1 -1
  42. package/extensions/dashboard-client/dist/assets/{CacheTab-BPNs0xIF.js → CacheTab-CAnrKKVK.js} +2 -2
  43. package/extensions/dashboard-client/dist/assets/{CacheTab-BPNs0xIF.js.map → CacheTab-CAnrKKVK.js.map} +1 -1
  44. package/extensions/dashboard-client/dist/assets/{EventsTab-BQf7OGkf.js → EventsTab-D-GL7Ngq.js} +2 -2
  45. package/extensions/dashboard-client/dist/assets/{EventsTab-BQf7OGkf.js.map → EventsTab-D-GL7Ngq.js.map} +1 -1
  46. package/extensions/dashboard-client/dist/assets/{HealthTab-B14TaSPN.js → HealthTab-C4x5qQ8s.js} +2 -2
  47. package/extensions/dashboard-client/dist/assets/{HealthTab-B14TaSPN.js.map → HealthTab-C4x5qQ8s.js.map} +1 -1
  48. package/extensions/dashboard-client/dist/assets/{MaintenanceTab-D8lkRoa1.js → MaintenanceTab-BSPs0eq5.js} +2 -2
  49. package/extensions/dashboard-client/dist/assets/{MaintenanceTab-D8lkRoa1.js.map → MaintenanceTab-BSPs0eq5.js.map} +1 -1
  50. package/extensions/dashboard-client/dist/assets/{MemoryMapTab-BOWtGfpx.js → MemoryMapTab-BWEUtTSu.js} +2 -2
  51. package/extensions/dashboard-client/dist/assets/{MemoryMapTab-BOWtGfpx.js.map → MemoryMapTab-BWEUtTSu.js.map} +1 -1
  52. package/extensions/dashboard-client/dist/assets/{MetricsTab-7XI9cWaX.js → MetricsTab-Dhm1c3Cx.js} +2 -2
  53. package/extensions/dashboard-client/dist/assets/{MetricsTab-7XI9cWaX.js.map → MetricsTab-Dhm1c3Cx.js.map} +1 -1
  54. package/extensions/dashboard-client/dist/assets/{OverviewTab-C9KaGYvh.js → OverviewTab-Cm6cySiQ.js} +2 -2
  55. package/extensions/dashboard-client/dist/assets/{OverviewTab-C9KaGYvh.js.map → OverviewTab-Cm6cySiQ.js.map} +1 -1
  56. package/extensions/dashboard-client/dist/assets/{ReposTab-BwESNhox.js → ReposTab-DxLN1N4K.js} +2 -2
  57. package/extensions/dashboard-client/dist/assets/{ReposTab-BwESNhox.js.map → ReposTab-DxLN1N4K.js.map} +1 -1
  58. package/extensions/dashboard-client/dist/assets/{SessionsTab-DKH55Rda.js → SessionsTab-CZuI4ISW.js} +2 -2
  59. package/extensions/dashboard-client/dist/assets/{SessionsTab-DKH55Rda.js.map → SessionsTab-CZuI4ISW.js.map} +1 -1
  60. package/extensions/dashboard-client/dist/assets/{SetupTab-zDxf-nJd.js → SetupTab-C_0VOomm.js} +2 -2
  61. package/extensions/dashboard-client/dist/assets/{SetupTab-zDxf-nJd.js.map → SetupTab-C_0VOomm.js.map} +1 -1
  62. package/extensions/dashboard-client/dist/assets/{TimeSavedCard-C9isog4L.js → TimeSavedCard-BhbaRLmi.js} +2 -2
  63. package/extensions/dashboard-client/dist/assets/{TimeSavedCard-C9isog4L.js.map → TimeSavedCard-BhbaRLmi.js.map} +1 -1
  64. package/extensions/dashboard-client/dist/assets/{TurnsTab-ciI6ydvj.js → TurnsTab-CXJmbjje.js} +2 -2
  65. package/extensions/dashboard-client/dist/assets/{TurnsTab-ciI6ydvj.js.map → TurnsTab-CXJmbjje.js.map} +1 -1
  66. package/extensions/dashboard-client/dist/assets/VectorCortexTab-BGe9hu3r.js +2 -0
  67. package/extensions/dashboard-client/dist/assets/VectorCortexTab-BGe9hu3r.js.map +1 -0
  68. package/extensions/dashboard-client/dist/assets/{WikiTab-DcYHc734.js → WikiTab-C5uvMCzp.js} +2 -2
  69. package/extensions/dashboard-client/dist/assets/{WikiTab-DcYHc734.js.map → WikiTab-C5uvMCzp.js.map} +1 -1
  70. package/extensions/dashboard-client/dist/assets/{button-DF8lx4bt.js → button-Cl_fxJcg.js} +2 -2
  71. package/extensions/dashboard-client/dist/assets/{button-DF8lx4bt.js.map → button-Cl_fxJcg.js.map} +1 -1
  72. package/extensions/dashboard-client/dist/assets/{card-DIoDheSZ.js → card-BH8Le5YM.js} +2 -2
  73. package/extensions/dashboard-client/dist/assets/{card-DIoDheSZ.js.map → card-BH8Le5YM.js.map} +1 -1
  74. package/extensions/dashboard-client/dist/assets/{generateCategoricalChart-BFRzeYX3.js → generateCategoricalChart-sZ6ZNtBi.js} +2 -2
  75. package/extensions/dashboard-client/dist/assets/{generateCategoricalChart-BFRzeYX3.js.map → generateCategoricalChart-sZ6ZNtBi.js.map} +1 -1
  76. package/extensions/dashboard-client/dist/assets/{index-DSZON0Yi.js → index-CX9zv8cJ.js} +3 -3
  77. package/extensions/dashboard-client/dist/assets/{index-DSZON0Yi.js.map → index-CX9zv8cJ.js.map} +1 -1
  78. package/extensions/dashboard-client/dist/assets/{switch-l4qo22mU.js → switch-CXJhcjhM.js} +2 -2
  79. package/extensions/dashboard-client/dist/assets/{switch-l4qo22mU.js.map → switch-CXJhcjhM.js.map} +1 -1
  80. package/extensions/dashboard-client/dist/assets/{toggle-DPn6td1_.js → toggle-CoLtIc6y.js} +2 -2
  81. package/extensions/dashboard-client/dist/assets/{toggle-DPn6td1_.js.map → toggle-CoLtIc6y.js.map} +1 -1
  82. package/extensions/dashboard-client/dist/assets/{useSSE-BLmolqTJ.js → useSSE-fSXho606.js} +2 -2
  83. package/extensions/dashboard-client/dist/assets/{useSSE-BLmolqTJ.js.map → useSSE-fSXho606.js.map} +1 -1
  84. package/extensions/dashboard-client/dist/index.html +1 -1
  85. package/extensions/dashboard-client/src/api/vector-cortex.ts +9 -0
  86. package/extensions/dashboard-client/src/tabs/VectorCortexTab.tsx +35 -0
  87. package/extensions/dashboard-client/src/types/vector-cortex.ts +13 -0
  88. package/extensions/dashboard-server/api-contracts/vector-cortex.ts +53 -0
  89. package/extensions/dashboard-server/routes-cache.test/_helpers.ts +2 -0
  90. package/extensions/dashboard-server/routes-rag-settings-helpers.ts +12 -0
  91. package/extensions/dashboard-server/routes-vector-cortex-helpers.ts +110 -0
  92. package/extensions/dashboard-server/routes-vector-cortex-residual.ts +60 -0
  93. package/extensions/dashboard-server/routes-vector-cortex-shards.ts +57 -0
  94. package/extensions/dashboard-server/routes-vector-cortex.ts +2 -0
  95. package/extensions/dashboard-server/routes.ts +2 -0
  96. package/extensions/dashboard-server/server.ts +46 -17
  97. package/extensions/dashboard-server/tailscale.ts +32 -0
  98. package/package.json +1 -1
  99. package/src/config/vector-cortex.ts +26 -0
  100. package/src/config.ts +2 -0
  101. package/src/vector-cortex/residual/codec.ts +292 -0
  102. package/src/vector-cortex/residual/dct.ts +166 -0
  103. package/src/vector-cortex/residual/fixture-payload.ts +90 -0
  104. package/src/vector-cortex/residual/gf256.ts +196 -0
  105. package/src/vector-cortex/residual/parity.ts +283 -0
  106. package/src/vector-cortex/residual/quantize.ts +230 -0
  107. package/src/vector-cortex/residual/stream.ts +135 -0
  108. package/src/vector-cortex/residual/types.ts +236 -0
  109. package/src/vector-cortex/shards/exact.ts +141 -0
  110. package/src/vector-cortex/shards/manifest.ts +276 -0
  111. package/src/vector-cortex/shards/semantic.ts +156 -0
  112. package/src/vector-cortex/shards/types.ts +212 -0
  113. package/extensions/dashboard-client/dist/assets/VectorCortexTab-qTZ7NWng.js +0 -2
  114. package/extensions/dashboard-client/dist/assets/VectorCortexTab-qTZ7NWng.js.map +0 -1
@@ -122,6 +122,30 @@ export const VC3B_ENABLED = () => sprintFlag("MEGACOMPACT_VC3B");
122
122
  * dashboard topology query diagnostic view.
123
123
  */
124
124
  export const VC3C_ENABLED = () => sprintFlag("MEGACOMPACT_VC3C");
125
+ /**
126
+ * VC4A — dual-tier shard contract (SemanticShardV1 / ExactShardV1 /
127
+ * ShardManifestV1).
128
+ * Default ON. `MEGACOMPACT_VC4A=0` disables and is byte-identical to the
129
+ * predecessor (mode C: exact anchors/current transcript only, no semantic or
130
+ * exact shard manifest is assembled or emitted, zero
131
+ * `vector_cortex_shard_manifest_built` / `vector_cortex_protected_span_rejected`
132
+ * emissions; the predecessor derived pointer and goldens are unchanged). The
133
+ * real consumers are the shard assembly seam (manifest.ts) and the reader-only
134
+ * dashboard shards aggregate view.
135
+ */
136
+ export const VC4A_ENABLED = () => sprintFlag("MEGACOMPACT_VC4A");
137
+ /**
138
+ * VC4B — residual codec and numeric parity (ResidualCodecV1 / ParityShardV1).
139
+ * Default ON. `MEGACOMPACT_VC4B=0` disables and is byte-identical to the
140
+ * predecessor (mode C: no residual artifact is admitted, the exact compressed
141
+ * payload / ledger bytes remain the only representation, zero
142
+ * `vector_cortex_residual_admitted` / `vector_cortex_parity_recovery_failed`
143
+ * emissions; the VC4A shard manifest and its goldens are unchanged). The real
144
+ * consumers are the codec admission seam (codec.ts) and the reader-only
145
+ * dashboard residual aggregate view. The codec math itself is PURE — flag OFF
146
+ * gates the reporter/admission seam, never the arithmetic.
147
+ */
148
+ export const VC4B_ENABLED = () => sprintFlag("MEGACOMPACT_VC4B");
125
149
  // ---------------------------------------------------------------------------
126
150
  // Breaker state machine constants (TRIAD_RESILIENCE.md §breaker).
127
151
  // Rolled numbers for one 60s window; VC0C consumes these at its breaker seam.
package/dist/config.js CHANGED
@@ -114,4 +114,4 @@ export const NEW_UI = () => ragEnabled("MEGACOMPACT_NEW_UI");
114
114
  // default ON, `=0`/`_DISABLED` off. Re-exported from src/config/vector-cortex.ts
115
115
  // so root consumers share one source of truth.
116
116
  // ---------------------------------------------------------------------------
117
- export { VC0A_ENABLED, VC0B_ENABLED, VC1A_ENABLED, VC0C_ENABLED, VC1B_ENABLED, VC1C_ENABLED, VC2A_ENABLED, VC2B_ENABLED, VC2C_ENABLED, VC3A_ENABLED, VC3B_ENABLED, VC3C_ENABLED, BREAKER_WINDOW_MS, BREAKER_MIN_ATTEMPTS, BREAKER_PERF_FAILURES, BREAKER_PERF_FAILURE_RATE, BREAKER_CORRECTNESS_FAILURES, BREAKER_COOLDOWN_MS, BREAKER_PROBE_COUNT, BREAKER_RETRY_BASE_MS, BREAKER_RETRY_CAP_MS, BREAKER_RETRY_JITTER, BREAKER_HYSTERESIS_FAILURE_RATE, BREAKER_HYSTERESIS_BUDGET_P95_MS, BREAKER_MIN_HEALTHY_RESIDENCE_MS, } from "./config/vector-cortex.js";
117
+ export { VC0A_ENABLED, VC0B_ENABLED, VC1A_ENABLED, VC0C_ENABLED, VC1B_ENABLED, VC1C_ENABLED, VC2A_ENABLED, VC2B_ENABLED, VC2C_ENABLED, VC3A_ENABLED, VC3B_ENABLED, VC3C_ENABLED, VC4A_ENABLED, VC4B_ENABLED, BREAKER_WINDOW_MS, BREAKER_MIN_ATTEMPTS, BREAKER_PERF_FAILURES, BREAKER_PERF_FAILURE_RATE, BREAKER_CORRECTNESS_FAILURES, BREAKER_COOLDOWN_MS, BREAKER_PROBE_COUNT, BREAKER_RETRY_BASE_MS, BREAKER_RETRY_CAP_MS, BREAKER_RETRY_JITTER, BREAKER_HYSTERESIS_FAILURE_RATE, BREAKER_HYSTERESIS_BUDGET_P95_MS, BREAKER_MIN_HEALTHY_RESIDENCE_MS, } from "./config/vector-cortex.js";
@@ -25,6 +25,7 @@ export function freshDir(prefix) {
25
25
  }
26
26
  export async function withServer(port, dir, fn) {
27
27
  process.env.MEGACOMPACT_DASHBOARD_PORT = port;
28
+ process.env.MEGACOMPACT_DASHBOARD_HOST = "127.0.0.1";
28
29
  const child = spawn(process.execPath, [SERVER_ENTRY, dir], { stdio: "ignore" });
29
30
  try {
30
31
  await waitFor(async () => {
@@ -43,6 +44,7 @@ export async function withServer(port, dir, fn) {
43
44
  finally {
44
45
  child.kill("SIGTERM");
45
46
  delete process.env.MEGACOMPACT_DASHBOARD_PORT;
47
+ delete process.env.MEGACOMPACT_DASHBOARD_HOST;
46
48
  rmSync(dir, { recursive: true, force: true });
47
49
  }
48
50
  }
@@ -146,6 +146,8 @@ export const SETTINGS = [
146
146
  boolDirect("MEGACOMPACT_VC3A", "VC3A Cortex Store", "Capability-gated derived cortex store (CortexReader/Writer/Admin + CortexRecordV1): additive, keyed (sourceHighWater, algorithmVersion, id), immutable records, deterministic generation rebuild + one root digest. OFF = mode C, no cortex records written, byte-identical predecessor.", true),
147
147
  boolDirect("MEGACOMPACT_VC3B", "VC3B Deterministic Topology", "Deterministic cortical topology (TopologyV1/EdgeV1): per-(source,head) top-k=16/head calibrated-threshold edges, stable score-desc/then-target-ID sort, dependency directed + contradiction symmetric paired records, one stable generation digest. OFF = mode C, no topology graph built/emitted, predecessor-precise topology view, byte-identical predecessor.", true),
148
148
  boolDirect("MEGACOMPACT_VC3C", "VC3C Topology Query + Router Invalidation", "TopologyQueryV1/RouterKeyV2 structured keys (length-delimited, unsigned-byte order, no prefix ambiguity), exact (session,generation) invalidation, stale-generation rejection (TOP_GENERATION_STALE), and the M6 router-generation-v2 copy/validate/switch migration. OFF = mode C, no structured router key / generation invalidation, byte-identical predecessor.", true),
149
+ boolDirect("MEGACOMPACT_VC4A", "VC4A Dual-Tier Shards", "SemanticShardV1/ExactShardV1/ShardManifestV1: partition a session ONLY at complete EventV2 boundaries; exact shards preserve every tool call/result pair, anchor and invalid UTF-8 event as original bytes (pairs never split across exact shards); manifest enforces disjoint sorted ranges + complete protected-span coverage. OFF = mode C, exact anchors/current transcript only, byte-identical predecessor.", true),
150
+ boolDirect("MEGACOMPACT_VC4B", "VC4B Residual Basis Parity", "Residual codec: orthonormal DCT-II basis + int16 block quantization + block-scoped exact correction stream + (9,6) Reed-Solomon parity shards with SHA-256 corruption detection; admission gates on encodedSize <= 95% of exact-compressed size. OFF = mode C, no residual artifact produced, byte-identical predecessor.", true),
149
151
  ],
150
152
  },
151
153
  {
@@ -0,0 +1,100 @@
1
+ /**
2
+ * routes-vector-cortex-helpers.ts — shared spawn-and-fetch harness for the
3
+ * /api/vector-cortex/* route test files.
4
+ *
5
+ * The dashboard-server.js main block fires when the entry argv includes
6
+ * "dashboard-server", so tests under dist/extensions/dashboard-server/ MUST
7
+ * spawn the server as a child process rather than import launchDashboardServer.
8
+ * Extracted from routes-vector-cortex.test.ts so per-sprint route test files
9
+ * can share the harness without each re-implementing it.
10
+ *
11
+ * Reader-only: no payload bytes are ever returned by the routes under test.
12
+ */
13
+ import { createHash } from "node:crypto";
14
+ import { rmSync, readFileSync, existsSync } from "node:fs";
15
+ import { dirname, join } from "node:path";
16
+ import { fileURLToPath } from "node:url";
17
+ import { spawn } from "node:child_process";
18
+ /** Locate the repo root (the directory holding `conformance/vector-cortex`). */
19
+ const HERE = dirname(fileURLToPath(import.meta.url));
20
+ export function repoRoot(from = HERE) {
21
+ let dir = from;
22
+ for (let i = 0; i < 8; i++) {
23
+ if (existsSync(join(dir, "conformance", "vector-cortex")))
24
+ return dir;
25
+ const next = dirname(dir);
26
+ if (next === dir)
27
+ break;
28
+ dir = next;
29
+ }
30
+ throw new Error("conformance corpus not found above " + from);
31
+ }
32
+ const REPO_ROOT = repoRoot();
33
+ /** SHA-256 of the REAL committed ModelManifestV1 — the health card's digest. */
34
+ export function realManifestDigest() {
35
+ // guardrails-allow PREVENT-PI-004: local committed asset filesystem read (loopback)
36
+ return createHash("sha256")
37
+ .update(readFileSync(join(REPO_ROOT, "assets", "vector-cortex", "encoder-v1", "manifest.json")))
38
+ .digest("hex");
39
+ }
40
+ export const SERVER_ENTRY = new URL("./server.js", import.meta.url).pathname;
41
+ export function waitFor(cond, timeoutMs = 6000) {
42
+ const start = Date.now();
43
+ return new Promise((resolve, reject) => {
44
+ const tick = async () => {
45
+ if (await cond())
46
+ return resolve();
47
+ if (Date.now() - start > timeoutMs)
48
+ return reject(new Error("timeout"));
49
+ setTimeout(tick, 50);
50
+ };
51
+ tick();
52
+ });
53
+ }
54
+ export async function withServer(port, dir, fn) {
55
+ process.env.MEGACOMPACT_DASHBOARD_PORT = port;
56
+ // Pin loopback so the spawn-and-fetch harness stays hermetic even on a
57
+ // machine with tailscale0 (the production auto-bind would otherwise grab the
58
+ // tailnet IP and the localhost probe would connection-refuse). Tests that
59
+ // need a different host can set MEGACOMPACT_DASHBOARD_HOST before calling.
60
+ process.env.MEGACOMPACT_DASHBOARD_HOST = "127.0.0.1";
61
+ const child = spawn(process.execPath, [SERVER_ENTRY, dir], {
62
+ stdio: "ignore",
63
+ env: {
64
+ ...process.env,
65
+ MEGACOMPACT_INDEX_DIR: dir,
66
+ },
67
+ });
68
+ try {
69
+ await waitFor(async () => {
70
+ try {
71
+ const raw = JSON.parse(readFileSync(join(dir, "port.pid"), "utf-8"));
72
+ const res = await fetch(`http://localhost:${raw.port}/api/version`);
73
+ return res.ok;
74
+ }
75
+ catch {
76
+ return false;
77
+ }
78
+ });
79
+ const raw = JSON.parse(readFileSync(join(dir, "port.pid"), "utf-8"));
80
+ return await fn(raw.port);
81
+ }
82
+ finally {
83
+ child.kill("SIGTERM");
84
+ delete process.env.MEGACOMPACT_DASHBOARD_PORT;
85
+ delete process.env.MEGACOMPACT_DASHBOARD_HOST;
86
+ rmSync(dir, { recursive: true, force: true });
87
+ }
88
+ }
89
+ /** Seed redacted metric rows directly on disk so the server's reader sees them. */
90
+ export async function seedEval(dir) {
91
+ const { appendEvalRow } = await import("../../src/vector-cortex/eval/persist.js");
92
+ // Buckets (inclusive): 1,5,10,25,50,100,250. 1ms→cell0, 12ms→cell3
93
+ // (<=25), 250ms→cell6, 300ms→overflow.
94
+ appendEvalRow(dir, [
95
+ { session: "s1", seq: 1, event: "encode", value: 1, unit: "ms", mode: "A" },
96
+ { session: "s1", seq: 2, event: "encode", value: 250, unit: "ms", mode: "A" },
97
+ { session: "s1", seq: 3, event: "encode", value: 300, unit: "ms", mode: "A" },
98
+ { session: "s1", seq: 4, event: "encode", value: 12, unit: "ms", mode: "A" },
99
+ ]);
100
+ }
@@ -0,0 +1,51 @@
1
+ /**
2
+ * dashboard-server/routes-vector-cortex-residual.ts — VC4B residual basis parity
3
+ * dashboard route.
4
+ *
5
+ * Reader-only GET /api/vector-cortex/residual returning a COUNT/BYTE aggregate
6
+ * (encode attempts, admitted/rejected counts, recovery failures, encoded/exact
7
+ * byte totals) — never residual payloads, correction streams, shard bytes, or
8
+ * original source bytes. Flag-gated on MEGACOMPACT_VC4B: `enabled:false` when off
9
+ * (byte-identical to the pre-VC4B predecessor).
10
+ *
11
+ * The VC4B residual codec is PURE IN-MEMORY logic in this sprint (it has no
12
+ * durable metrics store yet), so the aggregate reports the current status
13
+ * truthfully: `enabled` reflects the flag, and the count/byte fields are zero
14
+ * until a future sprint persists a metrics store. This route is the seam that
15
+ * sprint will populate. Non-fatal: a missing state dir degrades to
16
+ * `enabled:false`.
17
+ *
18
+ * Guardrails: PREVENT-PI-004 (local filesystem read only / in-process state),
19
+ * PREVENT-011 (no `any`), reader-only aggregate (counts/bytes only).
20
+ */
21
+ import { VC4B_ENABLED } from "../../src/config.js";
22
+ import { sendJson } from "./routes-vector-cortex-shared.js";
23
+ /**
24
+ * Reader-only GET /api/vector-cortex/residual (VC4B).
25
+ */
26
+ export function handleVectorCortexResidual(req, res, _ctx) {
27
+ const url = req.url ?? "";
28
+ const path = url.split("?")[0] ?? url;
29
+ if (path !== "/api/vector-cortex/residual")
30
+ return false;
31
+ if (req.method !== "GET") {
32
+ // Reader-only path: cannot be "off" without a GET; it is genuinely read-only.
33
+ sendJson(res, 405, { error: "method_not_allowed" });
34
+ return true;
35
+ }
36
+ const enabled = VC4B_ENABLED();
37
+ const body = {
38
+ enabled,
39
+ // No durable residual metrics store is staged yet in this sprint (pure
40
+ // in-memory encode), so the aggregates are truthfully zero.
41
+ encodeAttempts: 0,
42
+ admittedCount: 0,
43
+ rejectedCount: 0,
44
+ recoveryFailures: 0,
45
+ encodedByteTotal: 0,
46
+ exactByteTotal: 0,
47
+ updatedAt: new Date().toISOString(),
48
+ };
49
+ sendJson(res, 200, body);
50
+ return true;
51
+ }
@@ -0,0 +1,48 @@
1
+ /**
2
+ * dashboard-server/routes-vector-cortex-shards.ts — VC4A dual-tier shard
3
+ * dashboard route.
4
+ *
5
+ * Reader-only GET /api/vector-cortex/shards returning a COUNT/BYTE aggregate
6
+ * (semantic shards, exact shards, protected byte total) — never shard payloads,
7
+ * verbatim exact bytes, or prompt text. Flag-gated on MEGACOMPACT_VC4A:
8
+ * `enabled:false` when off (byte-identical to the pre-VC4A predecessor).
9
+ *
10
+ * The VC4A shard partition is PURE IN-MEMORY logic in this sprint (it has no
11
+ * durable manifest store yet), so the aggregate reports the current status
12
+ * truthfully: `enabled` reflects the flag, and the count/byte fields are zero
13
+ * until a future sprint persists a staged manifest. This route is the seam that
14
+ * sprint will populate. Non-fatal: a missing state dir degrades to
15
+ * `enabled:false`.
16
+ *
17
+ * Guardrails: PREVENT-PI-004 (local filesystem read only / in-process state),
18
+ * PREVENT-011 (no `any`), reader-only aggregate (counts/bytes only).
19
+ */
20
+ import { VC4A_ENABLED } from "../../src/config.js";
21
+ import { sendJson } from "./routes-vector-cortex-shared.js";
22
+ /**
23
+ * Reader-only GET /api/vector-cortex/shards (VC4A).
24
+ */
25
+ export function handleVectorCortexShards(req, res, _ctx) {
26
+ const url = req.url ?? "";
27
+ const path = url.split("?")[0] ?? url;
28
+ if (path !== "/api/vector-cortex/shards")
29
+ return false;
30
+ if (req.method !== "GET") {
31
+ // Reader-only path: cannot be "off" without a GET; it is genuinely read-only.
32
+ sendJson(res, 405, { error: "method_not_allowed" });
33
+ return true;
34
+ }
35
+ const enabled = VC4A_ENABLED();
36
+ const body = {
37
+ enabled,
38
+ // No durable shard manifest is staged yet in this sprint (pure in-memory
39
+ // partition), so the aggregates are truthfully zero.
40
+ semanticCount: 0,
41
+ exactCount: 0,
42
+ byteTotal: 0,
43
+ protectedByteTotal: 0,
44
+ updatedAt: new Date().toISOString(),
45
+ };
46
+ sendJson(res, 200, body);
47
+ return true;
48
+ }
@@ -18,3 +18,5 @@ export { handleVectorCortexHealth, handleVectorCortexBreakersReset } from "./rou
18
18
  export { handleVectorCortexLedger } from "./routes-vector-cortex-ledger.js";
19
19
  export { handleVectorCortexTopology } from "./routes-vector-cortex-topology.js";
20
20
  export { handleVectorCortexQuery } from "./routes-vector-cortex-query.js";
21
+ export { handleVectorCortexShards } from "./routes-vector-cortex-shards.js";
22
+ export { handleVectorCortexResidual } from "./routes-vector-cortex-residual.js";
@@ -23,4 +23,4 @@ export { handleRagSettings } from "./routes-rag-settings.js";
23
23
  export { handleRagMetrics } from "./routes-rag-metrics.js";
24
24
  export { handleModelThresholds } from "./routes-model-thresholds.js";
25
25
  export { handleWiki } from "./routes-wiki.js";
26
- export { handleVectorCortexEvaluation, handleVectorCortexHealth, handleVectorCortexBreakersReset, handleVectorCortexLedger, handleVectorCortexTopology, handleVectorCortexQuery, } from "./routes-vector-cortex.js";
26
+ export { handleVectorCortexEvaluation, handleVectorCortexHealth, handleVectorCortexBreakersReset, handleVectorCortexLedger, handleVectorCortexTopology, handleVectorCortexQuery, handleVectorCortexShards, handleVectorCortexResidual, } from "./routes-vector-cortex.js";
@@ -13,7 +13,8 @@ import { fileURLToPath } from "node:url";
13
13
  import { createRequire } from "node:module";
14
14
  import { NEW_UI } from "../../src/config.js";
15
15
  import { log, setLogPath, setDashboardServerVersion } from "./state.js";
16
- import { buildRouteContext, handleIndex, handleRepoIndex, handleEvents, handleGameState, handleGameScores, handlePerf, handlePerfSamples, handleAchievements, handleSessions, handleTopics, handleTurns, handleMaintenance, handleProviderCache, handleCacheStripes, handleMemoryStatus, handleSetupStatus, handleSetupDetect, handleSetupConfigure, handleMemoryMap, handleRaptorTree, handleRaptorBuildHistory, handleContextHealth, handleCachePoison, handleHealthSettings, handleEmbedderHealth, handleRagSettings, handleRagMetrics, handleModelThresholds, handleWiki, handleVectorCortexEvaluation, handleVectorCortexHealth, handleVectorCortexBreakersReset, handleVectorCortexLedger, handleVectorCortexTopology, handleVectorCortexQuery, handleStatic, } from "./routes.js";
16
+ import { detectTailscaleIP } from "./tailscale.js";
17
+ import { buildRouteContext, handleIndex, handleRepoIndex, handleEvents, handleGameState, handleGameScores, handlePerf, handlePerfSamples, handleAchievements, handleSessions, handleTopics, handleTurns, handleMaintenance, handleProviderCache, handleCacheStripes, handleMemoryStatus, handleSetupStatus, handleSetupDetect, handleSetupConfigure, handleMemoryMap, handleRaptorTree, handleRaptorBuildHistory, handleContextHealth, handleCachePoison, handleHealthSettings, handleEmbedderHealth, handleRagSettings, handleRagMetrics, handleModelThresholds, handleWiki, handleVectorCortexEvaluation, handleVectorCortexHealth, handleVectorCortexBreakersReset, handleVectorCortexLedger, handleVectorCortexTopology, handleVectorCortexQuery, handleVectorCortexShards, handleVectorCortexResidual, handleStatic, } from "./routes.js";
17
18
  export async function launchDashboardServer(stateDir) {
18
19
  // Our own package version — exposed at /api/version so the launcher can
19
20
  // detect a stale server (started by an older build) and replace it on
@@ -166,13 +167,26 @@ export async function launchDashboardServer(stateDir) {
166
167
  serveClientAsset,
167
168
  detectCrossRepoDrift,
168
169
  });
170
+ // Bind host resolution: explicit MEGACOMPACT_DASHBOARD_HOST override wins;
171
+ // otherwise auto-bind to the Tailscale interface (tailnet access); fall back
172
+ // to loopback when Tailscale is absent. 0.0.0.0 means "all interfaces" and
173
+ // opts into permissive CORS below.
174
+ const host = process.env.MEGACOMPACT_DASHBOARD_HOST ??
175
+ detectTailscaleIP() ??
176
+ "127.0.0.1";
177
+ const allInterfaces = host === "0.0.0.0";
178
+ // guardrails-allow PREVENT-PI-004: optional, user-triggered /dashboard server (tailnet-local via Tailscale mesh or loopback); no remote outbound calls.
169
179
  const server = createServer((req, res) => {
170
- // guardrails-allow PREVENT-PI-004: optional, user-triggered /dashboard localhost server (loopback-only) CORS restricted to same-origin localhost browsers.
171
- // CORS for local access — restricted to loopback origins (the dashboard server only binds to localhost).
180
+ // CORS for local access — restricted to loopback/same-origin tailnet
181
+ // origins (the dashboard server binds to localhost or the tailscale IP).
182
+ // With MEGACOMPACT_DASHBOARD_HOST=0.0.0.0 the user opted into
183
+ // all-interfaces binding, so we allow any origin.
172
184
  const origin = req.headers.origin;
173
- if (typeof origin === "string" &&
174
- /^http:\/\/(localhost|127\.0\.0\.1)(:\d+)?$/.test(origin)) {
175
- res.setHeader("Access-Control-Allow-Origin", origin);
185
+ const originAllowed = allInterfaces ||
186
+ (typeof origin === "string" &&
187
+ new RegExp(`^http://(localhost|127\\.0\\.0\\.1|::1|${host.replace(/\./g, "\\.")})(:\\d+)?$`).test(origin));
188
+ if (originAllowed) {
189
+ res.setHeader("Access-Control-Allow-Origin", origin ?? "*");
176
190
  res.setHeader("Vary", "Origin");
177
191
  }
178
192
  res.setHeader("Access-Control-Allow-Methods", "GET, POST, PUT, OPTIONS");
@@ -253,6 +267,10 @@ export async function launchDashboardServer(stateDir) {
253
267
  return;
254
268
  if (handleVectorCortexQuery(req, res, ctx))
255
269
  return;
270
+ if (handleVectorCortexShards(req, res, ctx))
271
+ return;
272
+ if (handleVectorCortexResidual(req, res, ctx))
273
+ return;
256
274
  handleStatic(req, res, ctx);
257
275
  });
258
276
  // Bind base + range are env-configurable so tests can use a private,
@@ -274,26 +292,33 @@ export async function launchDashboardServer(stateDir) {
274
292
  reject(err);
275
293
  }
276
294
  });
277
- server.listen(port, "127.0.0.1", () => {
278
- const url = `http://localhost:${port}`; // guardrails-allow PREVENT-PI-004: localhost dashboard URL (loopback-only)
279
- log("server running", { url });
295
+ server.listen(port, host, () => {
296
+ // When bound to the loopback, keep the legacy localhost URL so the
297
+ // user's browser (which resolves localhost ::1 or 127.0.0.1) works.
298
+ // When bound to a tailnet/tailscale IP, surface that address instead.
299
+ const url = host === "127.0.0.1"
300
+ ? `http://localhost:${port}`
301
+ : `http://${host}:${port}`; // guardrails-allow PREVENT-PI-004: dashboard URL (tailnet-local via Tailscale mesh or loopback)
302
+ log("server running", { url, host });
280
303
  // eslint-disable-next-line no-console
281
304
  console.log(`[mega-compact] dashboard server running: ${url}`);
282
- // v0.8.2: also bind the IPv6 loopback (::1). On many systems `localhost`
283
- // resolves to ::1 first (see /etc/hosts), so an IPv4-only bind makes the
284
- // browser hit ::1:port and get connection refused. PREVENT-PI-004
285
- // (loopback-only) means BOTH 127.0.0.1 and ::1. Non-fatal: IPv4-only
286
- // hosts or a ::1 already in use just skip the mirror.
305
+ // v0.8.2: also bind the IPv6 loopback (::1) when bound to the IPv4
306
+ // loopback. On many systems `localhost` resolves to ::1 first (see
307
+ // /etc/hosts), so an IPv4-only bind makes the browser hit ::1:port and
308
+ // get connection refused. PREVENT-PI-004 (loopback-only) means BOTH
309
+ // 127.0.0.1 and ::1. When bound to a tailscale/0.0.0.0 host, we do NOT
310
+ // bind ::1 — the tailnet address is what the user reaches. Non-fatal:
311
+ // IPv4-only hosts or a ::1 already in use just skip the mirror.
287
312
  let v6;
288
313
  const v4Handler = server.listeners("request")[0];
289
- if (v4Handler) {
314
+ if (host === "127.0.0.1" && v4Handler) {
290
315
  v6 = createServer((r, s) => v4Handler.call(server, r, s));
291
316
  v6.on("error", (e) => log("ipv6 loopback bind skipped", {
292
317
  port,
293
318
  code: e.code,
294
319
  message: e.message,
295
320
  }));
296
- v6.listen(port, "::1", () => log("ipv6 loopback bound", { port })); // guardrails-allow PREVENT-PI-004: IPv6 loopback (::1) mirror of the localhost dashboard server
321
+ v6.listen(port, "::1", () => log("ipv6 loopback bound", { port })); // guardrails-allow PREVENT-PI-004: IPv6 loopback (::1) mirror of the dashboard server
297
322
  }
298
323
  // Write port.pid
299
324
  try {
@@ -1,3 +1,4 @@
1
+ import { networkInterfaces } from "node:os";
1
2
  export function setupTailscaleServe(port = 3000, httpsPort = 443) {
2
3
  // Tailscale serve: exposes localhost dashboard securely.
3
4
  // Only activates when TAILSCALE_ENABLED=1 is set.
@@ -6,3 +7,34 @@ export function setupTailscaleServe(port = 3000, httpsPort = 443) {
6
7
  console.log(`[tailscale] Serve enabled on port ${port} (https:${httpsPort})`);
7
8
  return true;
8
9
  }
10
+ // CGNAT block used by Tailscale for client addresses (100.64.0.0/10).
11
+ const TAILSCALE_CGNAT_PREFIX = "100.";
12
+ /**
13
+ * Detect the IPv4 address Tailscale has assigned to this host, so the dashboard
14
+ * server can auto-bind to the tailnet interface and be reachable from other
15
+ * devices on the tailnet. Returns null when Tailscale is not present.
16
+ *
17
+ * The default Tailscale interface name is `tailscale0` on Linux and `Tailscale`
18
+ * on macOS/Windows. We prefer an address inside Tailscale's CGNAT range
19
+ * (100.64.0.0/10) when one exists; otherwise we return the first IPv4 address
20
+ * found on the interface.
21
+ */
22
+ export function detectTailscaleIP() {
23
+ const ifaces = networkInterfaces();
24
+ const candidates = [];
25
+ for (const [name, addrs] of Object.entries(ifaces)) {
26
+ if (name !== "tailscale0" && name !== "Tailscale")
27
+ continue;
28
+ if (!addrs)
29
+ continue;
30
+ for (const addr of addrs) {
31
+ if (addr.family === "IPv4") {
32
+ candidates.push(addr.address);
33
+ }
34
+ }
35
+ }
36
+ if (candidates.length === 0)
37
+ return null;
38
+ const cgnat = candidates.find((ip) => ip.startsWith(TAILSCALE_CGNAT_PREFIX));
39
+ return cgnat ?? candidates[0];
40
+ }
@@ -122,6 +122,30 @@ export const VC3B_ENABLED = () => sprintFlag("MEGACOMPACT_VC3B");
122
122
  * dashboard topology query diagnostic view.
123
123
  */
124
124
  export const VC3C_ENABLED = () => sprintFlag("MEGACOMPACT_VC3C");
125
+ /**
126
+ * VC4A — dual-tier shard contract (SemanticShardV1 / ExactShardV1 /
127
+ * ShardManifestV1).
128
+ * Default ON. `MEGACOMPACT_VC4A=0` disables and is byte-identical to the
129
+ * predecessor (mode C: exact anchors/current transcript only, no semantic or
130
+ * exact shard manifest is assembled or emitted, zero
131
+ * `vector_cortex_shard_manifest_built` / `vector_cortex_protected_span_rejected`
132
+ * emissions; the predecessor derived pointer and goldens are unchanged). The
133
+ * real consumers are the shard assembly seam (manifest.ts) and the reader-only
134
+ * dashboard shards aggregate view.
135
+ */
136
+ export const VC4A_ENABLED = () => sprintFlag("MEGACOMPACT_VC4A");
137
+ /**
138
+ * VC4B — residual codec and numeric parity (ResidualCodecV1 / ParityShardV1).
139
+ * Default ON. `MEGACOMPACT_VC4B=0` disables and is byte-identical to the
140
+ * predecessor (mode C: no residual artifact is admitted, the exact compressed
141
+ * payload / ledger bytes remain the only representation, zero
142
+ * `vector_cortex_residual_admitted` / `vector_cortex_parity_recovery_failed`
143
+ * emissions; the VC4A shard manifest and its goldens are unchanged). The real
144
+ * consumers are the codec admission seam (codec.ts) and the reader-only
145
+ * dashboard residual aggregate view. The codec math itself is PURE — flag OFF
146
+ * gates the reporter/admission seam, never the arithmetic.
147
+ */
148
+ export const VC4B_ENABLED = () => sprintFlag("MEGACOMPACT_VC4B");
125
149
  // ---------------------------------------------------------------------------
126
150
  // Breaker state machine constants (TRIAD_RESILIENCE.md §breaker).
127
151
  // Rolled numbers for one 60s window; VC0C consumes these at its breaker seam.
@@ -114,4 +114,4 @@ export const NEW_UI = () => ragEnabled("MEGACOMPACT_NEW_UI");
114
114
  // default ON, `=0`/`_DISABLED` off. Re-exported from src/config/vector-cortex.ts
115
115
  // so root consumers share one source of truth.
116
116
  // ---------------------------------------------------------------------------
117
- export { VC0A_ENABLED, VC0B_ENABLED, VC1A_ENABLED, VC0C_ENABLED, VC1B_ENABLED, VC1C_ENABLED, VC2A_ENABLED, VC2B_ENABLED, VC2C_ENABLED, VC3A_ENABLED, VC3B_ENABLED, VC3C_ENABLED, BREAKER_WINDOW_MS, BREAKER_MIN_ATTEMPTS, BREAKER_PERF_FAILURES, BREAKER_PERF_FAILURE_RATE, BREAKER_CORRECTNESS_FAILURES, BREAKER_COOLDOWN_MS, BREAKER_PROBE_COUNT, BREAKER_RETRY_BASE_MS, BREAKER_RETRY_CAP_MS, BREAKER_RETRY_JITTER, BREAKER_HYSTERESIS_FAILURE_RATE, BREAKER_HYSTERESIS_BUDGET_P95_MS, BREAKER_MIN_HEALTHY_RESIDENCE_MS, } from "./config/vector-cortex.js";
117
+ export { VC0A_ENABLED, VC0B_ENABLED, VC1A_ENABLED, VC0C_ENABLED, VC1B_ENABLED, VC1C_ENABLED, VC2A_ENABLED, VC2B_ENABLED, VC2C_ENABLED, VC3A_ENABLED, VC3B_ENABLED, VC3C_ENABLED, VC4A_ENABLED, VC4B_ENABLED, BREAKER_WINDOW_MS, BREAKER_MIN_ATTEMPTS, BREAKER_PERF_FAILURES, BREAKER_PERF_FAILURE_RATE, BREAKER_CORRECTNESS_FAILURES, BREAKER_COOLDOWN_MS, BREAKER_PROBE_COUNT, BREAKER_RETRY_BASE_MS, BREAKER_RETRY_CAP_MS, BREAKER_RETRY_JITTER, BREAKER_HYSTERESIS_FAILURE_RATE, BREAKER_HYSTERESIS_BUDGET_P95_MS, BREAKER_MIN_HEALTHY_RESIDENCE_MS, } from "./config/vector-cortex.js";