pi-mega-compact 0.19.0 → 0.19.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 (89) hide show
  1. package/dist/config/vector-cortex.js +10 -0
  2. package/dist/config.js +1 -1
  3. package/dist/extensions/dashboard-server/routes-rag-settings-helpers.js +1 -0
  4. package/dist/extensions/dashboard-server/routes-vector-cortex-eval.js +49 -0
  5. package/dist/extensions/dashboard-server/routes-vector-cortex-health.js +233 -0
  6. package/dist/extensions/dashboard-server/routes-vector-cortex-ledger.js +82 -0
  7. package/dist/extensions/dashboard-server/routes-vector-cortex-shared.js +46 -0
  8. package/dist/extensions/dashboard-server/routes-vector-cortex-topology.js +68 -0
  9. package/dist/extensions/dashboard-server/routes-vector-cortex.js +12 -373
  10. package/dist/extensions/dashboard-server/routes.js +1 -1
  11. package/dist/extensions/dashboard-server/server.js +3 -1
  12. package/dist/src/config/vector-cortex.js +10 -0
  13. package/dist/src/config.js +1 -1
  14. package/dist/src/vector-cortex/cortex/sqlite.js +393 -0
  15. package/dist/src/vector-cortex/cortex/store.js +139 -0
  16. package/dist/src/vector-cortex/cortex/types.js +44 -0
  17. package/dist/vector-cortex/cortex/sqlite.js +393 -0
  18. package/dist/vector-cortex/cortex/store.js +139 -0
  19. package/dist/vector-cortex/cortex/types.js +44 -0
  20. package/extensions/dashboard-client/dist/assets/{AreaChart-DywU5SSt.js → AreaChart-B9KYKrUE.js} +2 -2
  21. package/extensions/dashboard-client/dist/assets/{AreaChart-DywU5SSt.js.map → AreaChart-B9KYKrUE.js.map} +1 -1
  22. package/extensions/dashboard-client/dist/assets/{BarChart-But7WN6K.js → BarChart-D1sWkR6j.js} +2 -2
  23. package/extensions/dashboard-client/dist/assets/{BarChart-But7WN6K.js.map → BarChart-D1sWkR6j.js.map} +1 -1
  24. package/extensions/dashboard-client/dist/assets/{CacheTab-7aZWa1DR.js → CacheTab-BR8MYcJq.js} +2 -2
  25. package/extensions/dashboard-client/dist/assets/{CacheTab-7aZWa1DR.js.map → CacheTab-BR8MYcJq.js.map} +1 -1
  26. package/extensions/dashboard-client/dist/assets/{EventsTab-Bf_boNG2.js → EventsTab-BRNpDMvP.js} +2 -2
  27. package/extensions/dashboard-client/dist/assets/{EventsTab-Bf_boNG2.js.map → EventsTab-BRNpDMvP.js.map} +1 -1
  28. package/extensions/dashboard-client/dist/assets/{HealthTab-AbGc1nXP.js → HealthTab-rr5nXpjq.js} +2 -2
  29. package/extensions/dashboard-client/dist/assets/{HealthTab-AbGc1nXP.js.map → HealthTab-rr5nXpjq.js.map} +1 -1
  30. package/extensions/dashboard-client/dist/assets/{MaintenanceTab-BfHHhn5F.js → MaintenanceTab-CtjPWnzN.js} +2 -2
  31. package/extensions/dashboard-client/dist/assets/{MaintenanceTab-BfHHhn5F.js.map → MaintenanceTab-CtjPWnzN.js.map} +1 -1
  32. package/extensions/dashboard-client/dist/assets/{MemoryMapTab-DrcWti0-.js → MemoryMapTab-5SnFDIYc.js} +2 -2
  33. package/extensions/dashboard-client/dist/assets/{MemoryMapTab-DrcWti0-.js.map → MemoryMapTab-5SnFDIYc.js.map} +1 -1
  34. package/extensions/dashboard-client/dist/assets/{MetricsTab-ALiglXQq.js → MetricsTab-4MZfwRhq.js} +2 -2
  35. package/extensions/dashboard-client/dist/assets/{MetricsTab-ALiglXQq.js.map → MetricsTab-4MZfwRhq.js.map} +1 -1
  36. package/extensions/dashboard-client/dist/assets/{OverviewTab-nnaJdNyR.js → OverviewTab-BAKENnbk.js} +2 -2
  37. package/extensions/dashboard-client/dist/assets/{OverviewTab-nnaJdNyR.js.map → OverviewTab-BAKENnbk.js.map} +1 -1
  38. package/extensions/dashboard-client/dist/assets/{ReposTab-BTK0nofM.js → ReposTab-7-z_OmZo.js} +2 -2
  39. package/extensions/dashboard-client/dist/assets/{ReposTab-BTK0nofM.js.map → ReposTab-7-z_OmZo.js.map} +1 -1
  40. package/extensions/dashboard-client/dist/assets/{SessionsTab-RXPNqO6x.js → SessionsTab-D_r2ki0y.js} +2 -2
  41. package/extensions/dashboard-client/dist/assets/{SessionsTab-RXPNqO6x.js.map → SessionsTab-D_r2ki0y.js.map} +1 -1
  42. package/extensions/dashboard-client/dist/assets/{SetupTab-Dab0AVfs.js → SetupTab-DPujtYgv.js} +2 -2
  43. package/extensions/dashboard-client/dist/assets/{SetupTab-Dab0AVfs.js.map → SetupTab-DPujtYgv.js.map} +1 -1
  44. package/extensions/dashboard-client/dist/assets/{TimeSavedCard-DIVG8hdt.js → TimeSavedCard-CLHy30t6.js} +2 -2
  45. package/extensions/dashboard-client/dist/assets/{TimeSavedCard-DIVG8hdt.js.map → TimeSavedCard-CLHy30t6.js.map} +1 -1
  46. package/extensions/dashboard-client/dist/assets/{TurnsTab-9uz2fBwx.js → TurnsTab-Coul6CHc.js} +2 -2
  47. package/extensions/dashboard-client/dist/assets/{TurnsTab-9uz2fBwx.js.map → TurnsTab-Coul6CHc.js.map} +1 -1
  48. package/extensions/dashboard-client/dist/assets/VectorCortexTab-rqBpWc7A.js +2 -0
  49. package/extensions/dashboard-client/dist/assets/VectorCortexTab-rqBpWc7A.js.map +1 -0
  50. package/extensions/dashboard-client/dist/assets/{WikiTab-CpcgaggS.js → WikiTab-hryG5oyY.js} +2 -2
  51. package/extensions/dashboard-client/dist/assets/{WikiTab-CpcgaggS.js.map → WikiTab-hryG5oyY.js.map} +1 -1
  52. package/extensions/dashboard-client/dist/assets/{button-B0Q2fuKY.js → button-Dxo95lRI.js} +2 -2
  53. package/extensions/dashboard-client/dist/assets/{button-B0Q2fuKY.js.map → button-Dxo95lRI.js.map} +1 -1
  54. package/extensions/dashboard-client/dist/assets/{card-Cnik3TFr.js → card-FXwhLF_u.js} +2 -2
  55. package/extensions/dashboard-client/dist/assets/{card-Cnik3TFr.js.map → card-FXwhLF_u.js.map} +1 -1
  56. package/extensions/dashboard-client/dist/assets/{generateCategoricalChart-DrSwgn1V.js → generateCategoricalChart-M-GeRM8U.js} +2 -2
  57. package/extensions/dashboard-client/dist/assets/{generateCategoricalChart-DrSwgn1V.js.map → generateCategoricalChart-M-GeRM8U.js.map} +1 -1
  58. package/extensions/dashboard-client/dist/assets/{index-DraytcOY.js → index-BIZZXvoy.js} +3 -3
  59. package/extensions/dashboard-client/dist/assets/{index-DraytcOY.js.map → index-BIZZXvoy.js.map} +1 -1
  60. package/extensions/dashboard-client/dist/assets/index-CYpzq9Lm.css +1 -0
  61. package/extensions/dashboard-client/dist/assets/{switch-DVQ1aB9b.js → switch-C-d4tkN1.js} +2 -2
  62. package/extensions/dashboard-client/dist/assets/{switch-DVQ1aB9b.js.map → switch-C-d4tkN1.js.map} +1 -1
  63. package/extensions/dashboard-client/dist/assets/{toggle-Dkppx-49.js → toggle-Bfmucdcl.js} +2 -2
  64. package/extensions/dashboard-client/dist/assets/{toggle-Dkppx-49.js.map → toggle-Bfmucdcl.js.map} +1 -1
  65. package/extensions/dashboard-client/dist/assets/{useSSE-CPkjU4Gx.js → useSSE-CxK_wdmk.js} +2 -2
  66. package/extensions/dashboard-client/dist/assets/{useSSE-CPkjU4Gx.js.map → useSSE-CxK_wdmk.js.map} +1 -1
  67. package/extensions/dashboard-client/dist/index.html +2 -2
  68. package/extensions/dashboard-client/src/api/vector-cortex.ts +9 -0
  69. package/extensions/dashboard-client/src/tabs/VectorCortexTab.tsx +34 -0
  70. package/extensions/dashboard-client/src/types/vector-cortex.ts +15 -0
  71. package/extensions/dashboard-server/api-contracts/vector-cortex.ts +23 -0
  72. package/extensions/dashboard-server/routes-rag-settings-helpers.ts +6 -0
  73. package/extensions/dashboard-server/routes-vector-cortex-eval.ts +59 -0
  74. package/extensions/dashboard-server/routes-vector-cortex-health.ts +273 -0
  75. package/extensions/dashboard-server/routes-vector-cortex-ledger.ts +92 -0
  76. package/extensions/dashboard-server/routes-vector-cortex-shared.ts +53 -0
  77. package/extensions/dashboard-server/routes-vector-cortex-topology.ts +83 -0
  78. package/extensions/dashboard-server/routes-vector-cortex.ts +12 -431
  79. package/extensions/dashboard-server/routes.ts +1 -0
  80. package/extensions/dashboard-server/server.ts +2 -0
  81. package/package.json +1 -1
  82. package/src/config/vector-cortex.ts +11 -0
  83. package/src/config.ts +1 -0
  84. package/src/vector-cortex/cortex/sqlite.ts +489 -0
  85. package/src/vector-cortex/cortex/store.ts +202 -0
  86. package/src/vector-cortex/cortex/types.ts +194 -0
  87. package/extensions/dashboard-client/dist/assets/VectorCortexTab-DnKY61EJ.js +0 -2
  88. package/extensions/dashboard-client/dist/assets/VectorCortexTab-DnKY61EJ.js.map +0 -1
  89. package/extensions/dashboard-client/dist/assets/index-CfvziyBi.css +0 -1
@@ -0,0 +1,83 @@
1
+ /**
2
+ * dashboard-server/routes-vector-cortex-topology.ts — VC3A vector-cortex topology
3
+ * dashboard route.
4
+ *
5
+ * Reader-only GET /api/vector-cortex/topology built ENTIRELY on the CortexReader
6
+ * capability: opens the isolated cortex DB for this repo's state dir and returns
7
+ * the topology summary (enabled, active generation identity, one root digest,
8
+ * derived frontier, record count, ordinal). It is query-only — never
9
+ * append/rebuild/switch. No writer or admin capability is reachable on this path
10
+ * (no writer/admin leakage). Non-fatal: a missing or corrupt cortex DB degrades
11
+ * to `enabled:false`.
12
+ *
13
+ * Guardrails: PREVENT-PI-004 (local filesystem read only), PREVENT-011 (no
14
+ * `any`), reader-only aggregate.
15
+ */
16
+
17
+ import type { IncomingMessage, ServerResponse } from "node:http";
18
+ import type { RouteContext } from "./routes-core.js";
19
+ import { VC3A_ENABLED } from "../../src/config.js";
20
+ import { createCortexStore } from "../../src/vector-cortex/cortex/store.js";
21
+ import { sendJson } from "./routes-vector-cortex-shared.js";
22
+ import type { VectorCortexTopologyView } from "./api-contracts/vector-cortex.js";
23
+
24
+ /**
25
+ * Reader-only GET /api/vector-cortex/topology (VC3A).
26
+ */
27
+ export function handleVectorCortexTopology(
28
+ req: IncomingMessage,
29
+ res: ServerResponse,
30
+ ctx: RouteContext,
31
+ ): boolean {
32
+ const url = req.url ?? "";
33
+ const path = url.split("?")[0] ?? url;
34
+ if (path !== "/api/vector-cortex/topology") return false;
35
+ if (req.method !== "GET") {
36
+ // Reader-only path: no mutation endpoint lives at /topology.
37
+ sendJson(res, 405, { error: "method_not_allowed" });
38
+ return true;
39
+ }
40
+
41
+ const enabled = VC3A_ENABLED();
42
+ let active = enabled;
43
+ let summary: {
44
+ generationId: string | null;
45
+ rootDigest: string | null;
46
+ sourceHighWater: string;
47
+ recordCount: number;
48
+ ordinal: string | null;
49
+ } = { generationId: null, rootDigest: null, sourceHighWater: "0", recordCount: 0, ordinal: null };
50
+
51
+ if (enabled) {
52
+ try {
53
+ const store = createCortexStore({ stateDir: ctx.stateDir });
54
+ try {
55
+ const s = store.reader().topologySummary();
56
+ summary = {
57
+ generationId: s.generationId,
58
+ rootDigest: s.rootDigest,
59
+ sourceHighWater: s.sourceHighWater,
60
+ recordCount: s.recordCount,
61
+ ordinal: s.ordinal,
62
+ };
63
+ } finally {
64
+ store.close();
65
+ }
66
+ } catch {
67
+ // Non-fatal: a missing/corrupt cortex DB degrades to `enabled:false`.
68
+ active = false;
69
+ }
70
+ }
71
+
72
+ const body: VectorCortexTopologyView = {
73
+ enabled: active,
74
+ generationId: summary.generationId,
75
+ rootDigest: summary.rootDigest,
76
+ sourceHighWater: summary.sourceHighWater,
77
+ recordCount: summary.recordCount,
78
+ ordinal: summary.ordinal,
79
+ updatedAt: new Date().toISOString(),
80
+ };
81
+ sendJson(res, 200, body);
82
+ return true;
83
+ }
@@ -1,439 +1,20 @@
1
1
  /**
2
2
  * dashboard-server/routes-vector-cortex.ts — vector-cortex dashboard routes.
3
3
  *
4
- * VC0A ships a single reader-only GET /api/vector-cortex/evaluation that
5
- * aggregates redacted evaluation rows (persisted JSONL under the state dir)
6
- * via the reader. No writable capability — no reset/mutation here; VC0C adds
7
- * breaker health + reset endpoints into this same file, keeping it additive
8
- * and within extension limits.
4
+ * Delegate shell: each VC feature owns a focused handler module below the
5
+ * extension line limit, and this file re-exports them unchanged so the existing
6
+ * registration (`routes.ts`, `server.ts`) keeps working without modification.
9
7
  *
10
- * VC0C (task 5) adds:
11
- * GET /api/vector-cortex/health reader-only aggregate health card
12
- * POST /api/vector-cortex/breakers/reset — explicit admin capability
8
+ * VC0A evaluation -> routes-vector-cortex-eval.ts (GET /evaluation)
9
+ * VC0C health/reset-> routes-vector-cortex-health.ts(GET /health, POST /breakers/reset)
10
+ * VC1B ledger -> routes-vector-cortex-ledger.ts (GET /ledger)
11
+ * VC3A topology -> routes-vector-cortex-topology.ts(GET /topology)
13
12
  *
14
13
  * Guardrails: PREVENT-PI-004 (local filesystem read only), PREVENT-011 (no
15
- * `any`), reader-only aggregate (never payloads/prompts/ledger — EVAL-REDACT-002).
14
+ * `any`), reader-only aggregates (never payloads/prompts/ledger text).
16
15
  */
17
16
 
18
- import type { IncomingMessage, ServerResponse } from "node:http";
19
- import type { RouteContext } from "./routes-core.js";
20
- import { createHash } from "node:crypto";
21
- import { readFileSync, statSync } from "node:fs";
22
- import { join, dirname } from "node:path";
23
- import { fileURLToPath } from "node:url";
24
- import { VC0A_ENABLED, VC0C_ENABLED, VC1B_ENABLED, VC2C_ENABLED } from "../../src/config.js";
25
- import { readEvalRows } from "../../src/vector-cortex/eval/persist.js";
26
- import { summarizeEvalRows } from "../../src/vector-cortex/eval/reader.js";
27
- import { createVectorCortexSafety } from "../mega-runtime/vector-cortex-safety.js";
28
- import { createLedgerStore } from "../../src/vector-cortex/ledger/store.js";
29
- import { readEncoderManifest, verifyEncoderAsset, detectPlatform } from "../../src/vector-cortex/encoder/asset.js";
30
- import type {
31
- VectorCortexEvaluationSummary,
32
- VectorCortexHealthCard,
33
- VectorCortexLedgerView,
34
- VectorCortexResetResult,
35
- } from "./api-contracts/vector-cortex.js";
36
-
37
- /** Admin capability: an actor-supplied subsystem selector for breaker reset. */
38
- function readJsonBody(
39
- req: IncomingMessage,
40
- cb: (
41
- result: { ok: true; value: Record<string, unknown> } | { ok: false; error: string },
42
- ) => void,
43
- ): void {
44
- let body = "";
45
- let tooBig = false;
46
- req.on("data", (chunk: Buffer) => {
47
- if (body.length > 65536) {
48
- tooBig = true;
49
- return;
50
- }
51
- body += chunk.toString();
52
- });
53
- req.on("end", () => {
54
- if (tooBig) return cb({ ok: false, error: "body_too_large" });
55
- try {
56
- const v = body ? JSON.parse(body) : {};
57
- if (typeof v !== "object" || v === null || Array.isArray(v)) {
58
- return cb({ ok: false, error: "invalid_object" });
59
- }
60
- cb({ ok: true, value: v as Record<string, unknown> });
61
- } catch {
62
- cb({ ok: false, error: "invalid_json" });
63
- }
64
- });
65
- }
66
-
67
- function sendJson(res: ServerResponse, status: number, body: unknown): void {
68
- // guardrails-allow PREVENT-PI-004: loopback dashboard response (local)
69
- res.writeHead(status, { "Content-Type": "application/json" });
70
- res.end(JSON.stringify(body));
71
- }
72
-
73
- /** Resolve the committed encoder-v1 asset dir by walking up to the repo root. */
74
- function encoderAssetDir(): string | null {
75
- let dir = dirname(fileURLToPath(import.meta.url));
76
- const rel = join("assets", "vector-cortex", "encoder-v1");
77
- for (let i = 0; i < 8; i++) {
78
- const candidate = join(dir, rel);
79
- try {
80
- // guardrails-allow PREVENT-PI-004: local asset filesystem read (loopback)
81
- readFileSync(join(candidate, "manifest.json"));
82
- return candidate;
83
- } catch {
84
- /* keep walking */
85
- }
86
- const next = dirname(dir);
87
- if (next === dir) break;
88
- dir = next;
89
- }
90
- return null;
91
- }
92
-
93
- /**
94
- * VC2C encoder health facts (task 5): the SHA-256 of the committed qualified
95
- * manifest (asset digest) and the encoder triad mode. Reader-only aggregate
96
- * (digest prefix, no bytes). Gated on MEGACOMPACT_VC2C: when the flag is OFF
97
- * (rollback), the card reports mode C with an absent digest — consistent with
98
- * the rest of the card, whose enabled/mode fields reflect active (flag-gated)
99
- * state. When ON: "A" when the committed asset verifies on this host, "B" when
100
- * present but not verified (demotion), "C" when absent.
101
- *
102
- * The verification hashes the full ONNX + tokenizer bytes, which is expensive
103
- * on a periodically-polled endpoint as the shipped asset grows. The result is
104
- * memoized against a cheap key (manifest bytes + file sizes/mtimes + platform);
105
- * any on-disk mutation invalidates the key, so the cache never goes stale while
106
- * avoiding the repeated large-file hashing. A failed digest read returns null
107
- * (an absent digest), never a misleading zero-sentinel.
108
- */
109
- type EncoderHealthFacts = { assetDigest: string | null; mode: "A" | "B" | "C" };
110
-
111
- interface HealthFactCache {
112
- key: string;
113
- facts: EncoderHealthFacts;
114
- }
115
-
116
- let healthCache: HealthFactCache | null = null;
117
-
118
- /** Stable cache key: manifest bytes + (size,mtime) of the asset files + platform. */
119
- function healthFactCacheKey(dir: string, manifestPath: string): string | null {
120
- const platform = detectPlatform();
121
- if (!platform) return null;
122
- const parts: string[] = [platform];
123
- try {
124
- for (const p of [manifestPath, join(dir, "model.onnx"), join(dir, "tokenizer.json")]) {
125
- const s = statSync(p);
126
- parts.push(`${s.size}:${s.mtimeMs}`);
127
- }
128
- // guardrails-allow PREVENT-PI-004: local manifest filesystem read (loopback)
129
- parts.push(createHash("sha256").update(readFileSync(manifestPath)).digest("hex"));
130
- } catch {
131
- return null;
132
- }
133
- return parts.join("|");
134
- }
135
-
136
- function computeEncoderHealthFacts(dir: string): EncoderHealthFacts | null {
137
- const manifest = readEncoderManifest(dir);
138
- if (manifest === null) return { assetDigest: null, mode: "C" };
139
- const manifestPath = join(dir, "manifest.json");
140
- const key = healthFactCacheKey(dir, manifestPath);
141
- if (key === null) return null;
142
- if (healthCache !== null && healthCache.key === key) return healthCache.facts;
143
- let digest: string;
144
- try {
145
- // guardrails-allow PREVENT-PI-004: local manifest filesystem read (loopback)
146
- digest = createHash("sha256").update(readFileSync(manifestPath)).digest("hex");
147
- } catch {
148
- return { assetDigest: null, mode: "B" };
149
- }
150
- const verify = verifyEncoderAsset(dir, manifest, detectPlatform());
151
- const facts: EncoderHealthFacts = { assetDigest: digest, mode: verify.ok ? "A" : "B" };
152
- healthCache = { key, facts };
153
- return facts;
154
- }
155
-
156
- function encoderHealthFacts(): EncoderHealthFacts {
157
- if (!VC2C_ENABLED()) {
158
- // Rollback: MEGACOMPACT_VC2C=0 selects C — report the inactive (flag-gated)
159
- // mode with no asset digest rather than an on-disk-computed A/B.
160
- return { assetDigest: null, mode: "C" };
161
- }
162
- const dir = encoderAssetDir();
163
- if (dir === null) return { assetDigest: null, mode: "C" };
164
- const facts = computeEncoderHealthFacts(dir);
165
- if (facts === null) return { assetDigest: null, mode: "C" };
166
- return facts;
167
- }
168
-
169
- /** Reader-only aggregate GET /api/vector-cortex/evaluation. */
170
- export function handleVectorCortexEvaluation(
171
- req: IncomingMessage,
172
- res: ServerResponse,
173
- ctx: RouteContext,
174
- ): boolean {
175
- const url = req.url ?? "";
176
- if (url !== "/api/vector-cortex/evaluation") return false;
177
- if (req.method !== "GET") {
178
- // Reader-only: no mutation endpoints exist on this path.
179
- // guardrails-allow PREVENT-PI-004: loopback dashboard response (local)
180
- res.writeHead(405, { "Content-Type": "application/json" });
181
- res.end(JSON.stringify({ error: "method_not_allowed" }));
182
- return true;
183
- }
184
-
185
- const enabled = VC0A_ENABLED();
186
- const rows = enabled ? readEvalRows(ctx.stateDir) : [];
187
- const summary = summarizeEvalRows(rows);
188
-
189
- const body: VectorCortexEvaluationSummary = {
190
- enabled,
191
- mode: enabled ? "A" : "C",
192
- samples: summary.samples,
193
- byMode: {
194
- A: summary.byMode.A,
195
- B: summary.byMode.B,
196
- C: summary.byMode.C,
197
- },
198
- histogram: {
199
- edges: [...summary.histogram.edges],
200
- cells: [...summary.histogram.cells],
201
- overflow: summary.histogram.overflow,
202
- total: summary.histogram.total,
203
- },
204
- rejects: [], // VC0C wires live breaker/reject telemetry here
205
- updatedAt: new Date().toISOString(),
206
- };
207
- sendJson(res, 200, body);
208
- return true;
209
- }
210
-
211
- /**
212
- * Reader-only GET /api/vector-cortex/health (VC0C).
213
- *
214
- * Aggregate health card: breaker state (window/probe/backoff), durable spool
215
- * frontier/authority/lag, and a worst-state aggregate. Constructs the safety
216
- * adapter over the state dir — durable spool state (frontier-frozen, lag) is
217
- * read from disk, so it reflects restart. Purely read: no mutation, never
218
- * payloads/prompts/ledger.
219
- */
220
- export function handleVectorCortexHealth(
221
- req: IncomingMessage,
222
- res: ServerResponse,
223
- ctx: RouteContext,
224
- ): boolean {
225
- const url = req.url ?? "";
226
- if (url !== "/api/vector-cortex/health") return false;
227
- if (req.method !== "GET") {
228
- // Reader-only path: no mutation endpoint lives at /health.
229
- sendJson(res, 405, { error: "method_not_allowed" });
230
- return true;
231
- }
232
-
233
- const enabled = VC0C_ENABLED();
234
- const safety = enabled ? createVectorCortexSafety({ stateDir: ctx.stateDir }) : null;
235
- const card = safety ? safety.health() : null;
236
-
237
- const enc = encoderHealthFacts();
238
-
239
- const fallback: VectorCortexHealthCard = {
240
- enabled: false,
241
- mode: "C",
242
- state: "CLOSED_A",
243
- subsystem: "provider",
244
- sinceMs: 0,
245
- windowMs: 0,
246
- probeCount: 0,
247
- backoffDelayMs: 0,
248
- frontierFrozen: false,
249
- authorityOutage: false,
250
- spoolLag: 0,
251
- attempts: 0,
252
- failures: 0,
253
- p95Ms: 0,
254
- failureRate: 0,
255
- updatedAt: new Date().toISOString(),
256
- aggregate: "CLOSED_A",
257
- stateSource: "ephemeral",
258
- encoderAssetDigest: enc.assetDigest,
259
- encoderMode: enc.mode,
260
- };
261
- if (!card) {
262
- sendJson(res, 200, fallback);
263
- return true;
264
- }
265
-
266
- const mode: "A" | "B" | "C" =
267
- card.state === "CLOSED_A" ? "A" : card.state === "MANUAL_HALT" ? "C" : "B";
268
- const aggregate =
269
- card.state === "MANUAL_HALT"
270
- ? "MANUAL_HALT"
271
- : card.state === "OPEN_C"
272
- ? "OPEN_C"
273
- : card.state === "OPEN_B"
274
- ? "OPEN_B"
275
- : card.state === "PROBE_B" || card.state === "PROBE_A"
276
- ? "PROBE"
277
- : "CLOSED_A";
278
-
279
- const body: VectorCortexHealthCard = {
280
- enabled,
281
- mode,
282
- state: card.state,
283
- subsystem: card.subsystem,
284
- sinceMs: card.sinceMs,
285
- reason: card.reason,
286
- windowMs: card.windowMs,
287
- probeCount: card.probeCount,
288
- backoffDelayMs: card.backoffDelayMs,
289
- frontierFrozen: card.frontierFrozen,
290
- authorityOutage: card.authorityOutage,
291
- spoolLag: card.spoolLag,
292
- attempts: card.attempts,
293
- failures: card.failures,
294
- p95Ms: card.p95Ms,
295
- failureRate: card.failureRate,
296
- updatedAt: new Date().toISOString(),
297
- aggregate,
298
- stateSource: card.stateSource,
299
- encoderAssetDigest: enc.assetDigest,
300
- encoderMode: enc.mode,
301
- };
302
- sendJson(res, 200, body);
303
- return true;
304
- }
305
-
306
- /**
307
- * Admin POST /api/vector-cortex/breakers/reset (VC0C).
308
- *
309
- * Explicit admin capability (separate from the reader GET). Clears a breaker's
310
- * cooldown — or unwires a MANUAL_HALT — but NEVER evidence (attempts/failures
311
- * are retained, per TRIAD_RESILIENCE). The subsystem is actor-supplied via the
312
- * JSON body `{ subsystem }`. Every reset is documented in the returned record
313
- * (state, retained evidence, updatedAt) — an auditable mutation surface; the
314
- * GET path can never mutate.
315
- */
316
- export function handleVectorCortexBreakersReset(
317
- req: IncomingMessage,
318
- res: ServerResponse,
319
- ctx: RouteContext,
320
- ): boolean {
321
- const url = req.url ?? "";
322
- if (url !== "/api/vector-cortex/breakers/reset") return false;
323
- if (req.method !== "POST") {
324
- sendJson(res, 405, { error: "method_not_allowed" });
325
- return true;
326
- }
327
- if (!VC0C_ENABLED()) {
328
- sendJson(res, 409, { error: "vco_c_disabled" });
329
- return true;
330
- }
331
-
332
- readJsonBody(req, (parsed) => {
333
- if (!parsed.ok) {
334
- sendJson(res, 400, { error: parsed.error });
335
- return;
336
- }
337
- const subsystem = parsed.value.subsystem;
338
- if (typeof subsystem !== "string" || subsystem.length === 0) {
339
- sendJson(res, 400, { error: "subsystem_required" });
340
- return;
341
- }
342
- try {
343
- const safety = createVectorCortexSafety({ stateDir: ctx.stateDir });
344
- const rec = safety.reset(subsystem);
345
- const body: VectorCortexResetResult = {
346
- subsystem: rec.subsystem,
347
- state: rec.state,
348
- cooldownCleared: true,
349
- attempts: rec.attempts,
350
- failures: rec.failures,
351
- probeCount: rec.probeCount,
352
- manualReason: rec.manualReason,
353
- updatedAt: rec.updatedAt,
354
- };
355
- sendJson(res, 200, body);
356
- } catch {
357
- sendJson(res, 500, { error: "reset_failed" });
358
- }
359
- });
360
- return true;
361
- }
362
-
363
- /**
364
- * Reader-only GET /api/vector-cortex/ledger (VC1B).
365
- *
366
- * Built on the LedgerReader capability: opens the occurrence-v2 ledger for this
367
- * repo's state dir and returns the session's occurrence IDENTITY rows
368
- * (seq/eventId/kind/digest/toolCallId) plus high-water/count. NEVER ships
369
- * sourceBytes or prompt text (reader-only no-ledger-text rule). Optional
370
- * `?session=<id>` query selects the session (default "default").
371
- */
372
- export function handleVectorCortexLedger(
373
- req: IncomingMessage,
374
- res: ServerResponse,
375
- ctx: RouteContext,
376
- ): boolean {
377
- const url = req.url ?? "";
378
- const path = url.split("?")[0] ?? url;
379
- if (path !== "/api/vector-cortex/ledger") return false;
380
- if (req.method !== "GET") {
381
- // Reader-only path: no mutation endpoint lives at /ledger.
382
- sendJson(res, 405, { error: "method_not_allowed" });
383
- return true;
384
- }
385
-
386
- // Parse the optional session query parameter.
387
- let session = "default";
388
- const qs = url.split("?")[1];
389
- if (qs !== undefined) {
390
- for (const pair of qs.split("&")) {
391
- const [k, v] = pair.split("=");
392
- if (k === "session" && v !== undefined && v.length > 0) {
393
- session = decodeURIComponent(v);
394
- }
395
- }
396
- }
397
-
398
- const enabled = VC1B_ENABLED();
399
- let active = enabled;
400
- let highWater = "0";
401
- let count = 0;
402
- let occurrences: VectorCortexLedgerView["occurrences"] = [];
403
-
404
- if (enabled) {
405
- try {
406
- const store = createLedgerStore({ stateDir: ctx.stateDir });
407
- try {
408
- const reader = store.reader();
409
- highWater = reader.highWater(session).toString();
410
- const rows = reader.readSession(session);
411
- count = rows.length;
412
- // Identity only: never sourceBytes or prompt text (reader-only rule).
413
- occurrences = rows.slice(-500).map((occ) => ({
414
- seq: occ.seq.toString(),
415
- eventId: occ.eventId,
416
- kind: occ.kind,
417
- digest: occ.digest,
418
- ...(occ.toolCallId !== undefined ? { toolCallId: occ.toolCallId } : {}),
419
- }));
420
- } finally {
421
- store.close();
422
- }
423
- } catch {
424
- // Non-fatal: a missing/corrupt ledger DB degrades to `enabled:false`.
425
- active = false;
426
- }
427
- }
428
-
429
- const body: VectorCortexLedgerView = {
430
- enabled: active,
431
- session,
432
- highWater,
433
- count,
434
- occurrences,
435
- updatedAt: new Date().toISOString(),
436
- };
437
- sendJson(res, 200, body);
438
- return true;
439
- }
17
+ export { handleVectorCortexEvaluation } from "./routes-vector-cortex-eval.js";
18
+ export { handleVectorCortexHealth, handleVectorCortexBreakersReset } from "./routes-vector-cortex-health.js";
19
+ export { handleVectorCortexLedger } from "./routes-vector-cortex-ledger.js";
20
+ export { handleVectorCortexTopology } from "./routes-vector-cortex-topology.js";
@@ -45,4 +45,5 @@ export {
45
45
  handleVectorCortexHealth,
46
46
  handleVectorCortexBreakersReset,
47
47
  handleVectorCortexLedger,
48
+ handleVectorCortexTopology,
48
49
  } from "./routes-vector-cortex.js";
@@ -60,6 +60,7 @@ import {
60
60
  handleVectorCortexHealth,
61
61
  handleVectorCortexBreakersReset,
62
62
  handleVectorCortexLedger,
63
+ handleVectorCortexTopology,
63
64
  handleStatic,
64
65
  } from "./routes.js";
65
66
 
@@ -283,6 +284,7 @@ export async function launchDashboardServer(
283
284
  if (handleVectorCortexHealth(req, res, ctx)) return;
284
285
  if (handleVectorCortexBreakersReset(req, res, ctx)) return;
285
286
  if (handleVectorCortexLedger(req, res, ctx)) return;
287
+ if (handleVectorCortexTopology(req, res, ctx)) return;
286
288
  handleStatic(req, res, ctx);
287
289
  });
288
290
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-mega-compact",
3
- "version": "0.19.0",
3
+ "version": "0.19.1",
4
4
  "description": "Layered, local, vector-backed context compressor for pi — supersede/collapse/cluster compaction with deduped inline recall.",
5
5
  "type": "module",
6
6
  "license": "BSD-3-Clause",
@@ -100,6 +100,17 @@ export const VC2B_ENABLED = (): boolean => sprintFlag("MEGACOMPACT_VC2B");
100
100
  */
101
101
  export const VC2C_ENABLED = (): boolean => sprintFlag("MEGACOMPACT_VC2C");
102
102
 
103
+ /**
104
+ * VC3A — capability-gated cortex store (CortexReader/Writer/Admin, CortexRecordV1).
105
+ * Default ON. `MEGACOMPACT_VC3A=0` disables and is byte-identical to the
106
+ * predecessor (mode C: the derived cortex store is absent, mode B in-memory is
107
+ * not consulted, zero `vector_cortex_record_append_failed` /
108
+ * `vector_cortex_generation_rebuilt` emissions; the predecessor derived pointer
109
+ * and goldens are unchanged). The real consumers are the cortex append seam, the
110
+ * cortex rebuild/admin seam and the reader-only topology summary seam.
111
+ */
112
+ export const VC3A_ENABLED = (): boolean => sprintFlag("MEGACOMPACT_VC3A");
113
+
103
114
  // ---------------------------------------------------------------------------
104
115
  // Breaker state machine constants (TRIAD_RESILIENCE.md §breaker).
105
116
  // Rolled numbers for one 60s window; VC0C consumes these at its breaker seam.
package/src/config.ts CHANGED
@@ -160,6 +160,7 @@ export {
160
160
  VC2A_ENABLED,
161
161
  VC2B_ENABLED,
162
162
  VC2C_ENABLED,
163
+ VC3A_ENABLED,
163
164
  BREAKER_WINDOW_MS,
164
165
  BREAKER_MIN_ATTEMPTS,
165
166
  BREAKER_PERF_FAILURES,