pi-mega-compact 0.18.1 → 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 (108) hide show
  1. package/assets/vector-cortex/encoder-v1/manifest.json +1 -0
  2. package/assets/vector-cortex/encoder-v1/model-card.json +1 -0
  3. package/assets/vector-cortex/encoder-v1/model.onnx +0 -0
  4. package/assets/vector-cortex/encoder-v1/tokenizer.json +1 -0
  5. package/dist/config/vector-cortex.js +19 -0
  6. package/dist/config.js +1 -1
  7. package/dist/extensions/dashboard-server/routes-rag-settings-helpers.js +2 -0
  8. package/dist/extensions/dashboard-server/routes-vector-cortex-eval.js +49 -0
  9. package/dist/extensions/dashboard-server/routes-vector-cortex-health.js +233 -0
  10. package/dist/extensions/dashboard-server/routes-vector-cortex-ledger.js +82 -0
  11. package/dist/extensions/dashboard-server/routes-vector-cortex-shared.js +46 -0
  12. package/dist/extensions/dashboard-server/routes-vector-cortex-topology.js +68 -0
  13. package/dist/extensions/dashboard-server/routes-vector-cortex.js +12 -285
  14. package/dist/extensions/dashboard-server/routes.js +1 -1
  15. package/dist/extensions/dashboard-server/server.js +3 -1
  16. package/dist/src/config/vector-cortex.js +19 -0
  17. package/dist/src/config.js +1 -1
  18. package/dist/src/vector-cortex/cortex/sqlite.js +393 -0
  19. package/dist/src/vector-cortex/cortex/store.js +139 -0
  20. package/dist/src/vector-cortex/cortex/types.js +44 -0
  21. package/dist/src/vector-cortex/encoder/calibrate.js +174 -0
  22. package/dist/src/vector-cortex/encoder/emit-vc2c.js +59 -0
  23. package/dist/src/vector-cortex/encoder/fallback.js +62 -0
  24. package/dist/src/vector-cortex/encoder/select.js +172 -0
  25. package/dist/src/vector-cortex/encoder/types.js +31 -0
  26. package/dist/vector-cortex/cortex/sqlite.js +393 -0
  27. package/dist/vector-cortex/cortex/store.js +139 -0
  28. package/dist/vector-cortex/cortex/types.js +44 -0
  29. package/dist/vector-cortex/encoder/calibrate.js +174 -0
  30. package/dist/vector-cortex/encoder/emit-vc2c.js +59 -0
  31. package/dist/vector-cortex/encoder/fallback.js +62 -0
  32. package/dist/vector-cortex/encoder/select.js +172 -0
  33. package/dist/vector-cortex/encoder/types.js +31 -0
  34. package/extensions/dashboard-client/dist/assets/{AreaChart-BQXFF7UI.js → AreaChart-B9KYKrUE.js} +2 -2
  35. package/extensions/dashboard-client/dist/assets/{AreaChart-BQXFF7UI.js.map → AreaChart-B9KYKrUE.js.map} +1 -1
  36. package/extensions/dashboard-client/dist/assets/{BarChart-BVtoz9Eg.js → BarChart-D1sWkR6j.js} +2 -2
  37. package/extensions/dashboard-client/dist/assets/{BarChart-BVtoz9Eg.js.map → BarChart-D1sWkR6j.js.map} +1 -1
  38. package/extensions/dashboard-client/dist/assets/{CacheTab-trI2TIGy.js → CacheTab-BR8MYcJq.js} +2 -2
  39. package/extensions/dashboard-client/dist/assets/{CacheTab-trI2TIGy.js.map → CacheTab-BR8MYcJq.js.map} +1 -1
  40. package/extensions/dashboard-client/dist/assets/{EventsTab-CNUbk9__.js → EventsTab-BRNpDMvP.js} +2 -2
  41. package/extensions/dashboard-client/dist/assets/{EventsTab-CNUbk9__.js.map → EventsTab-BRNpDMvP.js.map} +1 -1
  42. package/extensions/dashboard-client/dist/assets/{HealthTab-K-bd_CM-.js → HealthTab-rr5nXpjq.js} +2 -2
  43. package/extensions/dashboard-client/dist/assets/{HealthTab-K-bd_CM-.js.map → HealthTab-rr5nXpjq.js.map} +1 -1
  44. package/extensions/dashboard-client/dist/assets/{MaintenanceTab-CoEioKzx.js → MaintenanceTab-CtjPWnzN.js} +2 -2
  45. package/extensions/dashboard-client/dist/assets/{MaintenanceTab-CoEioKzx.js.map → MaintenanceTab-CtjPWnzN.js.map} +1 -1
  46. package/extensions/dashboard-client/dist/assets/{MemoryMapTab-CJo24ulv.js → MemoryMapTab-5SnFDIYc.js} +2 -2
  47. package/extensions/dashboard-client/dist/assets/{MemoryMapTab-CJo24ulv.js.map → MemoryMapTab-5SnFDIYc.js.map} +1 -1
  48. package/extensions/dashboard-client/dist/assets/{MetricsTab-DCNlQWWP.js → MetricsTab-4MZfwRhq.js} +2 -2
  49. package/extensions/dashboard-client/dist/assets/{MetricsTab-DCNlQWWP.js.map → MetricsTab-4MZfwRhq.js.map} +1 -1
  50. package/extensions/dashboard-client/dist/assets/{OverviewTab-CQQlyIQ6.js → OverviewTab-BAKENnbk.js} +2 -2
  51. package/extensions/dashboard-client/dist/assets/{OverviewTab-CQQlyIQ6.js.map → OverviewTab-BAKENnbk.js.map} +1 -1
  52. package/extensions/dashboard-client/dist/assets/{ReposTab-Cqm82_yn.js → ReposTab-7-z_OmZo.js} +2 -2
  53. package/extensions/dashboard-client/dist/assets/{ReposTab-Cqm82_yn.js.map → ReposTab-7-z_OmZo.js.map} +1 -1
  54. package/extensions/dashboard-client/dist/assets/{SessionsTab-A8xTAdET.js → SessionsTab-D_r2ki0y.js} +2 -2
  55. package/extensions/dashboard-client/dist/assets/{SessionsTab-A8xTAdET.js.map → SessionsTab-D_r2ki0y.js.map} +1 -1
  56. package/extensions/dashboard-client/dist/assets/{SetupTab-CqaSgaZl.js → SetupTab-DPujtYgv.js} +2 -2
  57. package/extensions/dashboard-client/dist/assets/{SetupTab-CqaSgaZl.js.map → SetupTab-DPujtYgv.js.map} +1 -1
  58. package/extensions/dashboard-client/dist/assets/{TimeSavedCard-C_f3q8GR.js → TimeSavedCard-CLHy30t6.js} +2 -2
  59. package/extensions/dashboard-client/dist/assets/{TimeSavedCard-C_f3q8GR.js.map → TimeSavedCard-CLHy30t6.js.map} +1 -1
  60. package/extensions/dashboard-client/dist/assets/{TurnsTab-BEsafACo.js → TurnsTab-Coul6CHc.js} +2 -2
  61. package/extensions/dashboard-client/dist/assets/{TurnsTab-BEsafACo.js.map → TurnsTab-Coul6CHc.js.map} +1 -1
  62. package/extensions/dashboard-client/dist/assets/VectorCortexTab-rqBpWc7A.js +2 -0
  63. package/extensions/dashboard-client/dist/assets/VectorCortexTab-rqBpWc7A.js.map +1 -0
  64. package/extensions/dashboard-client/dist/assets/{WikiTab-Bf01M2_Z.js → WikiTab-hryG5oyY.js} +2 -2
  65. package/extensions/dashboard-client/dist/assets/{WikiTab-Bf01M2_Z.js.map → WikiTab-hryG5oyY.js.map} +1 -1
  66. package/extensions/dashboard-client/dist/assets/{button-BEJPTk_E.js → button-Dxo95lRI.js} +2 -2
  67. package/extensions/dashboard-client/dist/assets/{button-BEJPTk_E.js.map → button-Dxo95lRI.js.map} +1 -1
  68. package/extensions/dashboard-client/dist/assets/{card-DK1V382s.js → card-FXwhLF_u.js} +2 -2
  69. package/extensions/dashboard-client/dist/assets/{card-DK1V382s.js.map → card-FXwhLF_u.js.map} +1 -1
  70. package/extensions/dashboard-client/dist/assets/{generateCategoricalChart-CRtaPphL.js → generateCategoricalChart-M-GeRM8U.js} +2 -2
  71. package/extensions/dashboard-client/dist/assets/{generateCategoricalChart-CRtaPphL.js.map → generateCategoricalChart-M-GeRM8U.js.map} +1 -1
  72. package/extensions/dashboard-client/dist/assets/{index-CB6BslE4.js → index-BIZZXvoy.js} +3 -3
  73. package/extensions/dashboard-client/dist/assets/{index-CB6BslE4.js.map → index-BIZZXvoy.js.map} +1 -1
  74. package/extensions/dashboard-client/dist/assets/index-CYpzq9Lm.css +1 -0
  75. package/extensions/dashboard-client/dist/assets/{switch-C4FV6B9k.js → switch-C-d4tkN1.js} +2 -2
  76. package/extensions/dashboard-client/dist/assets/{switch-C4FV6B9k.js.map → switch-C-d4tkN1.js.map} +1 -1
  77. package/extensions/dashboard-client/dist/assets/{toggle-GBmeENMd.js → toggle-Bfmucdcl.js} +2 -2
  78. package/extensions/dashboard-client/dist/assets/{toggle-GBmeENMd.js.map → toggle-Bfmucdcl.js.map} +1 -1
  79. package/extensions/dashboard-client/dist/assets/{useSSE-BOKZGSn1.js → useSSE-CxK_wdmk.js} +2 -2
  80. package/extensions/dashboard-client/dist/assets/{useSSE-BOKZGSn1.js.map → useSSE-CxK_wdmk.js.map} +1 -1
  81. package/extensions/dashboard-client/dist/index.html +2 -2
  82. package/extensions/dashboard-client/src/api/vector-cortex.ts +9 -0
  83. package/extensions/dashboard-client/src/tabs/VectorCortexTab.tsx +36 -0
  84. package/extensions/dashboard-client/src/types/vector-cortex.ts +26 -0
  85. package/extensions/dashboard-server/api-contracts/vector-cortex.ts +34 -0
  86. package/extensions/dashboard-server/routes-rag-settings-helpers.ts +12 -0
  87. package/extensions/dashboard-server/routes-vector-cortex-eval.ts +59 -0
  88. package/extensions/dashboard-server/routes-vector-cortex-health.ts +273 -0
  89. package/extensions/dashboard-server/routes-vector-cortex-ledger.ts +92 -0
  90. package/extensions/dashboard-server/routes-vector-cortex-shared.ts +53 -0
  91. package/extensions/dashboard-server/routes-vector-cortex-topology.ts +83 -0
  92. package/extensions/dashboard-server/routes-vector-cortex.ts +12 -324
  93. package/extensions/dashboard-server/routes.ts +1 -0
  94. package/extensions/dashboard-server/server.ts +2 -0
  95. package/package.json +2 -1
  96. package/src/config/vector-cortex.ts +21 -0
  97. package/src/config.ts +2 -0
  98. package/src/vector-cortex/cortex/sqlite.ts +489 -0
  99. package/src/vector-cortex/cortex/store.ts +202 -0
  100. package/src/vector-cortex/cortex/types.ts +194 -0
  101. package/src/vector-cortex/encoder/calibrate.ts +225 -0
  102. package/src/vector-cortex/encoder/emit-vc2c.ts +70 -0
  103. package/src/vector-cortex/encoder/fallback.ts +99 -0
  104. package/src/vector-cortex/encoder/select.ts +237 -0
  105. package/src/vector-cortex/encoder/types.ts +116 -0
  106. package/extensions/dashboard-client/dist/assets/VectorCortexTab-DD1CMK80.js +0 -2
  107. package/extensions/dashboard-client/dist/assets/VectorCortexTab-DD1CMK80.js.map +0 -1
  108. 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,332 +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 { VC0A_ENABLED, VC0C_ENABLED, VC1B_ENABLED } from "../../src/config.js";
21
- import { readEvalRows } from "../../src/vector-cortex/eval/persist.js";
22
- import { summarizeEvalRows } from "../../src/vector-cortex/eval/reader.js";
23
- import { createVectorCortexSafety } from "../mega-runtime/vector-cortex-safety.js";
24
- import { createLedgerStore } from "../../src/vector-cortex/ledger/store.js";
25
- import type {
26
- VectorCortexEvaluationSummary,
27
- VectorCortexHealthCard,
28
- VectorCortexLedgerView,
29
- VectorCortexResetResult,
30
- } from "./api-contracts/vector-cortex.js";
31
-
32
- /** Admin capability: an actor-supplied subsystem selector for breaker reset. */
33
- function readJsonBody(
34
- req: IncomingMessage,
35
- cb: (
36
- result: { ok: true; value: Record<string, unknown> } | { ok: false; error: string },
37
- ) => void,
38
- ): void {
39
- let body = "";
40
- let tooBig = false;
41
- req.on("data", (chunk: Buffer) => {
42
- if (body.length > 65536) {
43
- tooBig = true;
44
- return;
45
- }
46
- body += chunk.toString();
47
- });
48
- req.on("end", () => {
49
- if (tooBig) return cb({ ok: false, error: "body_too_large" });
50
- try {
51
- const v = body ? JSON.parse(body) : {};
52
- if (typeof v !== "object" || v === null || Array.isArray(v)) {
53
- return cb({ ok: false, error: "invalid_object" });
54
- }
55
- cb({ ok: true, value: v as Record<string, unknown> });
56
- } catch {
57
- cb({ ok: false, error: "invalid_json" });
58
- }
59
- });
60
- }
61
-
62
- function sendJson(res: ServerResponse, status: number, body: unknown): void {
63
- // guardrails-allow PREVENT-PI-004: loopback dashboard response (local)
64
- res.writeHead(status, { "Content-Type": "application/json" });
65
- res.end(JSON.stringify(body));
66
- }
67
-
68
- /** Reader-only aggregate GET /api/vector-cortex/evaluation. */
69
- export function handleVectorCortexEvaluation(
70
- req: IncomingMessage,
71
- res: ServerResponse,
72
- ctx: RouteContext,
73
- ): boolean {
74
- const url = req.url ?? "";
75
- if (url !== "/api/vector-cortex/evaluation") return false;
76
- if (req.method !== "GET") {
77
- // Reader-only: no mutation endpoints exist on this path.
78
- // guardrails-allow PREVENT-PI-004: loopback dashboard response (local)
79
- res.writeHead(405, { "Content-Type": "application/json" });
80
- res.end(JSON.stringify({ error: "method_not_allowed" }));
81
- return true;
82
- }
83
-
84
- const enabled = VC0A_ENABLED();
85
- const rows = enabled ? readEvalRows(ctx.stateDir) : [];
86
- const summary = summarizeEvalRows(rows);
87
-
88
- const body: VectorCortexEvaluationSummary = {
89
- enabled,
90
- mode: enabled ? "A" : "C",
91
- samples: summary.samples,
92
- byMode: {
93
- A: summary.byMode.A,
94
- B: summary.byMode.B,
95
- C: summary.byMode.C,
96
- },
97
- histogram: {
98
- edges: [...summary.histogram.edges],
99
- cells: [...summary.histogram.cells],
100
- overflow: summary.histogram.overflow,
101
- total: summary.histogram.total,
102
- },
103
- rejects: [], // VC0C wires live breaker/reject telemetry here
104
- updatedAt: new Date().toISOString(),
105
- };
106
- sendJson(res, 200, body);
107
- return true;
108
- }
109
-
110
- /**
111
- * Reader-only GET /api/vector-cortex/health (VC0C).
112
- *
113
- * Aggregate health card: breaker state (window/probe/backoff), durable spool
114
- * frontier/authority/lag, and a worst-state aggregate. Constructs the safety
115
- * adapter over the state dir — durable spool state (frontier-frozen, lag) is
116
- * read from disk, so it reflects restart. Purely read: no mutation, never
117
- * payloads/prompts/ledger.
118
- */
119
- export function handleVectorCortexHealth(
120
- req: IncomingMessage,
121
- res: ServerResponse,
122
- ctx: RouteContext,
123
- ): boolean {
124
- const url = req.url ?? "";
125
- if (url !== "/api/vector-cortex/health") return false;
126
- if (req.method !== "GET") {
127
- // Reader-only path: no mutation endpoint lives at /health.
128
- sendJson(res, 405, { error: "method_not_allowed" });
129
- return true;
130
- }
131
-
132
- const enabled = VC0C_ENABLED();
133
- const safety = enabled ? createVectorCortexSafety({ stateDir: ctx.stateDir }) : null;
134
- const card = safety ? safety.health() : null;
135
-
136
- const fallback: VectorCortexHealthCard = {
137
- enabled: false,
138
- mode: "C",
139
- state: "CLOSED_A",
140
- subsystem: "provider",
141
- sinceMs: 0,
142
- windowMs: 0,
143
- probeCount: 0,
144
- backoffDelayMs: 0,
145
- frontierFrozen: false,
146
- authorityOutage: false,
147
- spoolLag: 0,
148
- attempts: 0,
149
- failures: 0,
150
- p95Ms: 0,
151
- failureRate: 0,
152
- updatedAt: new Date().toISOString(),
153
- aggregate: "CLOSED_A",
154
- stateSource: "ephemeral",
155
- };
156
- if (!card) {
157
- sendJson(res, 200, fallback);
158
- return true;
159
- }
160
-
161
- const mode: "A" | "B" | "C" =
162
- card.state === "CLOSED_A" ? "A" : card.state === "MANUAL_HALT" ? "C" : "B";
163
- const aggregate =
164
- card.state === "MANUAL_HALT"
165
- ? "MANUAL_HALT"
166
- : card.state === "OPEN_C"
167
- ? "OPEN_C"
168
- : card.state === "OPEN_B"
169
- ? "OPEN_B"
170
- : card.state === "PROBE_B" || card.state === "PROBE_A"
171
- ? "PROBE"
172
- : "CLOSED_A";
173
-
174
- const body: VectorCortexHealthCard = {
175
- enabled,
176
- mode,
177
- state: card.state,
178
- subsystem: card.subsystem,
179
- sinceMs: card.sinceMs,
180
- reason: card.reason,
181
- windowMs: card.windowMs,
182
- probeCount: card.probeCount,
183
- backoffDelayMs: card.backoffDelayMs,
184
- frontierFrozen: card.frontierFrozen,
185
- authorityOutage: card.authorityOutage,
186
- spoolLag: card.spoolLag,
187
- attempts: card.attempts,
188
- failures: card.failures,
189
- p95Ms: card.p95Ms,
190
- failureRate: card.failureRate,
191
- updatedAt: new Date().toISOString(),
192
- aggregate,
193
- stateSource: card.stateSource,
194
- };
195
- sendJson(res, 200, body);
196
- return true;
197
- }
198
-
199
- /**
200
- * Admin POST /api/vector-cortex/breakers/reset (VC0C).
201
- *
202
- * Explicit admin capability (separate from the reader GET). Clears a breaker's
203
- * cooldown — or unwires a MANUAL_HALT — but NEVER evidence (attempts/failures
204
- * are retained, per TRIAD_RESILIENCE). The subsystem is actor-supplied via the
205
- * JSON body `{ subsystem }`. Every reset is documented in the returned record
206
- * (state, retained evidence, updatedAt) — an auditable mutation surface; the
207
- * GET path can never mutate.
208
- */
209
- export function handleVectorCortexBreakersReset(
210
- req: IncomingMessage,
211
- res: ServerResponse,
212
- ctx: RouteContext,
213
- ): boolean {
214
- const url = req.url ?? "";
215
- if (url !== "/api/vector-cortex/breakers/reset") return false;
216
- if (req.method !== "POST") {
217
- sendJson(res, 405, { error: "method_not_allowed" });
218
- return true;
219
- }
220
- if (!VC0C_ENABLED()) {
221
- sendJson(res, 409, { error: "vco_c_disabled" });
222
- return true;
223
- }
224
-
225
- readJsonBody(req, (parsed) => {
226
- if (!parsed.ok) {
227
- sendJson(res, 400, { error: parsed.error });
228
- return;
229
- }
230
- const subsystem = parsed.value.subsystem;
231
- if (typeof subsystem !== "string" || subsystem.length === 0) {
232
- sendJson(res, 400, { error: "subsystem_required" });
233
- return;
234
- }
235
- try {
236
- const safety = createVectorCortexSafety({ stateDir: ctx.stateDir });
237
- const rec = safety.reset(subsystem);
238
- const body: VectorCortexResetResult = {
239
- subsystem: rec.subsystem,
240
- state: rec.state,
241
- cooldownCleared: true,
242
- attempts: rec.attempts,
243
- failures: rec.failures,
244
- probeCount: rec.probeCount,
245
- manualReason: rec.manualReason,
246
- updatedAt: rec.updatedAt,
247
- };
248
- sendJson(res, 200, body);
249
- } catch {
250
- sendJson(res, 500, { error: "reset_failed" });
251
- }
252
- });
253
- return true;
254
- }
255
-
256
- /**
257
- * Reader-only GET /api/vector-cortex/ledger (VC1B).
258
- *
259
- * Built on the LedgerReader capability: opens the occurrence-v2 ledger for this
260
- * repo's state dir and returns the session's occurrence IDENTITY rows
261
- * (seq/eventId/kind/digest/toolCallId) plus high-water/count. NEVER ships
262
- * sourceBytes or prompt text (reader-only no-ledger-text rule). Optional
263
- * `?session=<id>` query selects the session (default "default").
264
- */
265
- export function handleVectorCortexLedger(
266
- req: IncomingMessage,
267
- res: ServerResponse,
268
- ctx: RouteContext,
269
- ): boolean {
270
- const url = req.url ?? "";
271
- const path = url.split("?")[0] ?? url;
272
- if (path !== "/api/vector-cortex/ledger") return false;
273
- if (req.method !== "GET") {
274
- // Reader-only path: no mutation endpoint lives at /ledger.
275
- sendJson(res, 405, { error: "method_not_allowed" });
276
- return true;
277
- }
278
-
279
- // Parse the optional session query parameter.
280
- let session = "default";
281
- const qs = url.split("?")[1];
282
- if (qs !== undefined) {
283
- for (const pair of qs.split("&")) {
284
- const [k, v] = pair.split("=");
285
- if (k === "session" && v !== undefined && v.length > 0) {
286
- session = decodeURIComponent(v);
287
- }
288
- }
289
- }
290
-
291
- const enabled = VC1B_ENABLED();
292
- let active = enabled;
293
- let highWater = "0";
294
- let count = 0;
295
- let occurrences: VectorCortexLedgerView["occurrences"] = [];
296
-
297
- if (enabled) {
298
- try {
299
- const store = createLedgerStore({ stateDir: ctx.stateDir });
300
- try {
301
- const reader = store.reader();
302
- highWater = reader.highWater(session).toString();
303
- const rows = reader.readSession(session);
304
- count = rows.length;
305
- // Identity only: never sourceBytes or prompt text (reader-only rule).
306
- occurrences = rows.slice(-500).map((occ) => ({
307
- seq: occ.seq.toString(),
308
- eventId: occ.eventId,
309
- kind: occ.kind,
310
- digest: occ.digest,
311
- ...(occ.toolCallId !== undefined ? { toolCallId: occ.toolCallId } : {}),
312
- }));
313
- } finally {
314
- store.close();
315
- }
316
- } catch {
317
- // Non-fatal: a missing/corrupt ledger DB degrades to `enabled:false`.
318
- active = false;
319
- }
320
- }
321
-
322
- const body: VectorCortexLedgerView = {
323
- enabled: active,
324
- session,
325
- highWater,
326
- count,
327
- occurrences,
328
- updatedAt: new Date().toISOString(),
329
- };
330
- sendJson(res, 200, body);
331
- return true;
332
- }
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.18.1",
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",
@@ -27,6 +27,7 @@
27
27
  "extensions",
28
28
  "extensions/dashboard-client/dist",
29
29
  "src",
30
+ "assets/vector-cortex/encoder-v1",
30
31
  "README.md",
31
32
  "LICENSE",
32
33
  "!dist/**/*.test.js",
@@ -90,6 +90,27 @@ export const VC2A_ENABLED = (): boolean => sprintFlag("MEGACOMPACT_VC2A");
90
90
  */
91
91
  export const VC2B_ENABLED = (): boolean => sprintFlag("MEGACOMPACT_VC2B");
92
92
 
93
+ /**
94
+ * VC2C — encoder qualification + calibration (QualifiedEncoderV1 / CalibrationV1).
95
+ * Default ON. `MEGACOMPACT_VC2C=0` disables and is byte-identical to the
96
+ * predecessor (mode C: no qualification manifest is read or selected, the
97
+ * calibrate/select/fallback seams are idle, zero `vector_cortex_encoder_qualification_*`
98
+ * emissions; the trigram/lexical paths are unchanged). The real consumers are
99
+ * the encoder-qualification emit seam and the calibrate/select seams.
100
+ */
101
+ export const VC2C_ENABLED = (): boolean => sprintFlag("MEGACOMPACT_VC2C");
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
+
93
114
  // ---------------------------------------------------------------------------
94
115
  // Breaker state machine constants (TRIAD_RESILIENCE.md §breaker).
95
116
  // Rolled numbers for one 60s window; VC0C consumes these at its breaker seam.
package/src/config.ts CHANGED
@@ -159,6 +159,8 @@ export {
159
159
  VC1C_ENABLED,
160
160
  VC2A_ENABLED,
161
161
  VC2B_ENABLED,
162
+ VC2C_ENABLED,
163
+ VC3A_ENABLED,
162
164
  BREAKER_WINDOW_MS,
163
165
  BREAKER_MIN_ATTEMPTS,
164
166
  BREAKER_PERF_FAILURES,