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
@@ -91,6 +91,16 @@ export const VC2B_ENABLED = () => sprintFlag("MEGACOMPACT_VC2B");
91
91
  * the encoder-qualification emit seam and the calibrate/select seams.
92
92
  */
93
93
  export const VC2C_ENABLED = () => sprintFlag("MEGACOMPACT_VC2C");
94
+ /**
95
+ * VC3A — capability-gated cortex store (CortexReader/Writer/Admin, CortexRecordV1).
96
+ * Default ON. `MEGACOMPACT_VC3A=0` disables and is byte-identical to the
97
+ * predecessor (mode C: the derived cortex store is absent, mode B in-memory is
98
+ * not consulted, zero `vector_cortex_record_append_failed` /
99
+ * `vector_cortex_generation_rebuilt` emissions; the predecessor derived pointer
100
+ * and goldens are unchanged). The real consumers are the cortex append seam, the
101
+ * cortex rebuild/admin seam and the reader-only topology summary seam.
102
+ */
103
+ export const VC3A_ENABLED = () => sprintFlag("MEGACOMPACT_VC3A");
94
104
  // ---------------------------------------------------------------------------
95
105
  // Breaker state machine constants (TRIAD_RESILIENCE.md §breaker).
96
106
  // 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, 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, 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";
@@ -143,6 +143,7 @@ export const SETTINGS = [
143
143
  boolDirect("MEGACOMPACT_VC2A", "VC2A Offline Model Runtime", "ModelManifestV1 digest-before-load ONNX runtime (opset17/batch1/max512) + asset-free trigram demotion. Asset path assets/vector-cortex/encoder-v1 is immutable/digest-pinned. OFF = mode C, byte-identical to predecessor.", true),
144
144
  boolDirect("MEGACOMPACT_VC2B", "VC2B Multi-Head Encoder", "VectorSetV1 five L2-normalized heads (384/128/128/64/32) with head-calibration draft + asset-free trigram B (512d) and lexical C fallbacks, plus the per-head emit seam. OFF = mode C, no per-head vectors emitted, byte-identical predecessor.", true),
145
145
  boolDirect("MEGACOMPACT_VC2C", "VC2C Encoder Qualification + Calibration", "QualifiedEncoderV1/CalibrationV1: calibration fit on the calibration split only (held-out labels prohibited) + atomic selection across MODEL_ASSET and per-head EVALUATION thresholds (any field failure demotes all of A). OFF = mode C, no qualification/calibration selection, byte-identical predecessor.", true),
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),
146
147
  ],
147
148
  },
148
149
  {
@@ -0,0 +1,49 @@
1
+ /**
2
+ * dashboard-server/routes-vector-cortex-eval.ts — VC0A vector-cortex evaluation
3
+ * dashboard route.
4
+ *
5
+ * A single reader-only GET /api/vector-cortex/evaluation that aggregates redacted
6
+ * evaluation rows (persisted JSONL under the state dir) via the reader. No
7
+ * writable capability — no reset/mutation here.
8
+ *
9
+ * Guardrails: PREVENT-PI-004 (local filesystem read only), PREVENT-011 (no
10
+ * `any`), reader-only aggregate (never payloads/prompts/ledger — EVAL-REDACT-002).
11
+ */
12
+ import { VC0A_ENABLED } from "../../src/config.js";
13
+ import { readEvalRows } from "../../src/vector-cortex/eval/persist.js";
14
+ import { summarizeEvalRows } from "../../src/vector-cortex/eval/reader.js";
15
+ import { sendJson } from "./routes-vector-cortex-shared.js";
16
+ /** Reader-only aggregate GET /api/vector-cortex/evaluation. */
17
+ export function handleVectorCortexEvaluation(req, res, ctx) {
18
+ const url = req.url ?? "";
19
+ if (url !== "/api/vector-cortex/evaluation")
20
+ return false;
21
+ if (req.method !== "GET") {
22
+ // Reader-only: no mutation endpoints exist on this path.
23
+ sendJson(res, 405, { error: "method_not_allowed" });
24
+ return true;
25
+ }
26
+ const enabled = VC0A_ENABLED();
27
+ const rows = enabled ? readEvalRows(ctx.stateDir) : [];
28
+ const summary = summarizeEvalRows(rows);
29
+ const body = {
30
+ enabled,
31
+ mode: enabled ? "A" : "C",
32
+ samples: summary.samples,
33
+ byMode: {
34
+ A: summary.byMode.A,
35
+ B: summary.byMode.B,
36
+ C: summary.byMode.C,
37
+ },
38
+ histogram: {
39
+ edges: [...summary.histogram.edges],
40
+ cells: [...summary.histogram.cells],
41
+ overflow: summary.histogram.overflow,
42
+ total: summary.histogram.total,
43
+ },
44
+ rejects: [], // VC0C wires live breaker/reject telemetry here
45
+ updatedAt: new Date().toISOString(),
46
+ };
47
+ sendJson(res, 200, body);
48
+ return true;
49
+ }
@@ -0,0 +1,233 @@
1
+ /**
2
+ * dashboard-server/routes-vector-cortex-health.ts — VC0C vector-cortex breaker
3
+ * health + reset routes (plus the VC2C encoder-health facts they surface).
4
+ *
5
+ * GET /api/vector-cortex/health — reader-only aggregate health card
6
+ * POST /api/vector-cortex/breakers/reset — explicit admin capability
7
+ *
8
+ * Guardrails: PREVENT-PI-004 (local filesystem read only), PREVENT-011 (no
9
+ * `any`), reader-only aggregate (never payloads/prompts/ledger — EVAL-REDACT-002).
10
+ */
11
+ import { createHash } from "node:crypto";
12
+ import { readFileSync, statSync } from "node:fs";
13
+ import { join, dirname } from "node:path";
14
+ import { fileURLToPath } from "node:url";
15
+ import { VC0C_ENABLED, VC2C_ENABLED } from "../../src/config.js";
16
+ import { createVectorCortexSafety } from "../mega-runtime/vector-cortex-safety.js";
17
+ import { readEncoderManifest, verifyEncoderAsset, detectPlatform } from "../../src/vector-cortex/encoder/asset.js";
18
+ import { sendJson, readJsonBody } from "./routes-vector-cortex-shared.js";
19
+ /** Resolve the committed encoder-v1 asset dir by walking up to the repo root. */
20
+ function encoderAssetDir() {
21
+ let dir = dirname(fileURLToPath(import.meta.url));
22
+ const rel = join("assets", "vector-cortex", "encoder-v1");
23
+ for (let i = 0; i < 8; i++) {
24
+ const candidate = join(dir, rel);
25
+ try {
26
+ // guardrails-allow PREVENT-PI-004: local asset filesystem read (loopback)
27
+ readFileSync(join(candidate, "manifest.json"));
28
+ return candidate;
29
+ }
30
+ catch {
31
+ /* keep walking */
32
+ }
33
+ const next = dirname(dir);
34
+ if (next === dir)
35
+ break;
36
+ dir = next;
37
+ }
38
+ return null;
39
+ }
40
+ let healthCache = null;
41
+ /** Stable cache key: manifest bytes + (size,mtime) of the asset files + platform. */
42
+ function healthFactCacheKey(dir, manifestPath) {
43
+ const platform = detectPlatform();
44
+ if (!platform)
45
+ return null;
46
+ const parts = [platform];
47
+ try {
48
+ for (const p of [manifestPath, join(dir, "model.onnx"), join(dir, "tokenizer.json")]) {
49
+ const s = statSync(p);
50
+ parts.push(`${s.size}:${s.mtimeMs}`);
51
+ }
52
+ // guardrails-allow PREVENT-PI-004: local manifest filesystem read (loopback)
53
+ parts.push(createHash("sha256").update(readFileSync(manifestPath)).digest("hex"));
54
+ }
55
+ catch {
56
+ return null;
57
+ }
58
+ return parts.join("|");
59
+ }
60
+ function computeEncoderHealthFacts(dir) {
61
+ const manifest = readEncoderManifest(dir);
62
+ if (manifest === null)
63
+ return { assetDigest: null, mode: "C" };
64
+ const manifestPath = join(dir, "manifest.json");
65
+ const key = healthFactCacheKey(dir, manifestPath);
66
+ if (key === null)
67
+ return null;
68
+ if (healthCache !== null && healthCache.key === key)
69
+ return healthCache.facts;
70
+ let digest;
71
+ try {
72
+ // guardrails-allow PREVENT-PI-004: local manifest filesystem read (loopback)
73
+ digest = createHash("sha256").update(readFileSync(manifestPath)).digest("hex");
74
+ }
75
+ catch {
76
+ return { assetDigest: null, mode: "B" };
77
+ }
78
+ const verify = verifyEncoderAsset(dir, manifest, detectPlatform());
79
+ const facts = { assetDigest: digest, mode: verify.ok ? "A" : "B" };
80
+ healthCache = { key, facts };
81
+ return facts;
82
+ }
83
+ function encoderHealthFacts() {
84
+ if (!VC2C_ENABLED()) {
85
+ // Rollback: MEGACOMPACT_VC2C=0 selects C — report the inactive (flag-gated)
86
+ // mode with no asset digest rather than an on-disk-computed A/B.
87
+ return { assetDigest: null, mode: "C" };
88
+ }
89
+ const dir = encoderAssetDir();
90
+ if (dir === null)
91
+ return { assetDigest: null, mode: "C" };
92
+ const facts = computeEncoderHealthFacts(dir);
93
+ if (facts === null)
94
+ return { assetDigest: null, mode: "C" };
95
+ return facts;
96
+ }
97
+ /**
98
+ * Reader-only GET /api/vector-cortex/health (VC0C).
99
+ *
100
+ * Aggregate health card: breaker state (window/probe/backoff), durable spool
101
+ * frontier/authority/lag, and a worst-state aggregate. Constructs the safety
102
+ * adapter over the state dir — durable spool state (frontier-frozen, lag) is
103
+ * read from disk, so it reflects restart. Purely read: no mutation, never
104
+ * payloads/prompts/ledger.
105
+ */
106
+ export function handleVectorCortexHealth(req, res, ctx) {
107
+ const url = req.url ?? "";
108
+ if (url !== "/api/vector-cortex/health")
109
+ return false;
110
+ if (req.method !== "GET") {
111
+ // Reader-only path: no mutation endpoint lives at /health.
112
+ sendJson(res, 405, { error: "method_not_allowed" });
113
+ return true;
114
+ }
115
+ const enabled = VC0C_ENABLED();
116
+ const safety = enabled ? createVectorCortexSafety({ stateDir: ctx.stateDir }) : null;
117
+ const card = safety ? safety.health() : null;
118
+ const enc = encoderHealthFacts();
119
+ const fallback = {
120
+ enabled: false,
121
+ mode: "C",
122
+ state: "CLOSED_A",
123
+ subsystem: "provider",
124
+ sinceMs: 0,
125
+ windowMs: 0,
126
+ probeCount: 0,
127
+ backoffDelayMs: 0,
128
+ frontierFrozen: false,
129
+ authorityOutage: false,
130
+ spoolLag: 0,
131
+ attempts: 0,
132
+ failures: 0,
133
+ p95Ms: 0,
134
+ failureRate: 0,
135
+ updatedAt: new Date().toISOString(),
136
+ aggregate: "CLOSED_A",
137
+ stateSource: "ephemeral",
138
+ encoderAssetDigest: enc.assetDigest,
139
+ encoderMode: enc.mode,
140
+ };
141
+ if (!card) {
142
+ sendJson(res, 200, fallback);
143
+ return true;
144
+ }
145
+ const mode = card.state === "CLOSED_A" ? "A" : card.state === "MANUAL_HALT" ? "C" : "B";
146
+ const aggregate = card.state === "MANUAL_HALT"
147
+ ? "MANUAL_HALT"
148
+ : card.state === "OPEN_C"
149
+ ? "OPEN_C"
150
+ : card.state === "OPEN_B"
151
+ ? "OPEN_B"
152
+ : card.state === "PROBE_B" || card.state === "PROBE_A"
153
+ ? "PROBE"
154
+ : "CLOSED_A";
155
+ const body = {
156
+ enabled,
157
+ mode,
158
+ state: card.state,
159
+ subsystem: card.subsystem,
160
+ sinceMs: card.sinceMs,
161
+ reason: card.reason,
162
+ windowMs: card.windowMs,
163
+ probeCount: card.probeCount,
164
+ backoffDelayMs: card.backoffDelayMs,
165
+ frontierFrozen: card.frontierFrozen,
166
+ authorityOutage: card.authorityOutage,
167
+ spoolLag: card.spoolLag,
168
+ attempts: card.attempts,
169
+ failures: card.failures,
170
+ p95Ms: card.p95Ms,
171
+ failureRate: card.failureRate,
172
+ updatedAt: new Date().toISOString(),
173
+ aggregate,
174
+ stateSource: card.stateSource,
175
+ encoderAssetDigest: enc.assetDigest,
176
+ encoderMode: enc.mode,
177
+ };
178
+ sendJson(res, 200, body);
179
+ return true;
180
+ }
181
+ /**
182
+ * Admin POST /api/vector-cortex/breakers/reset (VC0C).
183
+ *
184
+ * Explicit admin capability (separate from the reader GET). Clears a breaker's
185
+ * cooldown — or unwires a MANUAL_HALT — but NEVER evidence (attempts/failures
186
+ * are retained, per TRIAD_RESILIENCE). The subsystem is actor-supplied via the
187
+ * JSON body `{ subsystem }`. Every reset is documented in the returned record
188
+ * (state, retained evidence, updatedAt) — an auditable mutation surface; the
189
+ * GET path can never mutate.
190
+ */
191
+ export function handleVectorCortexBreakersReset(req, res, ctx) {
192
+ const url = req.url ?? "";
193
+ if (url !== "/api/vector-cortex/breakers/reset")
194
+ return false;
195
+ if (req.method !== "POST") {
196
+ sendJson(res, 405, { error: "method_not_allowed" });
197
+ return true;
198
+ }
199
+ if (!VC0C_ENABLED()) {
200
+ sendJson(res, 409, { error: "vco_c_disabled" });
201
+ return true;
202
+ }
203
+ readJsonBody(req, (parsed) => {
204
+ if (!parsed.ok) {
205
+ sendJson(res, 400, { error: parsed.error });
206
+ return;
207
+ }
208
+ const subsystem = parsed.value.subsystem;
209
+ if (typeof subsystem !== "string" || subsystem.length === 0) {
210
+ sendJson(res, 400, { error: "subsystem_required" });
211
+ return;
212
+ }
213
+ try {
214
+ const safety = createVectorCortexSafety({ stateDir: ctx.stateDir });
215
+ const rec = safety.reset(subsystem);
216
+ const body = {
217
+ subsystem: rec.subsystem,
218
+ state: rec.state,
219
+ cooldownCleared: true,
220
+ attempts: rec.attempts,
221
+ failures: rec.failures,
222
+ probeCount: rec.probeCount,
223
+ manualReason: rec.manualReason,
224
+ updatedAt: rec.updatedAt,
225
+ };
226
+ sendJson(res, 200, body);
227
+ }
228
+ catch {
229
+ sendJson(res, 500, { error: "reset_failed" });
230
+ }
231
+ });
232
+ return true;
233
+ }
@@ -0,0 +1,82 @@
1
+ /**
2
+ * dashboard-server/routes-vector-cortex-ledger.ts — VC1B vector-cortex ledger
3
+ * dashboard route.
4
+ *
5
+ * Reader-only GET /api/vector-cortex/ledger built on the LedgerReader capability:
6
+ * opens the occurrence-v2 ledger for this repo's state dir and returns the
7
+ * session's occurrence IDENTITY rows (seq/eventId/kind/digest/toolCallId) plus
8
+ * high-water/count. NEVER ships sourceBytes or prompt text (reader-only
9
+ * no-ledger-text rule). Optional `?session=<id>` query selects the session.
10
+ *
11
+ * Guardrails: PREVENT-PI-004 (local filesystem read only), PREVENT-011 (no
12
+ * `any`), reader-only aggregate/identity only.
13
+ */
14
+ import { VC1B_ENABLED } from "../../src/config.js";
15
+ import { createLedgerStore } from "../../src/vector-cortex/ledger/store.js";
16
+ import { sendJson } from "./routes-vector-cortex-shared.js";
17
+ /**
18
+ * Reader-only GET /api/vector-cortex/ledger (VC1B).
19
+ */
20
+ export function handleVectorCortexLedger(req, res, ctx) {
21
+ const url = req.url ?? "";
22
+ const path = url.split("?")[0] ?? url;
23
+ if (path !== "/api/vector-cortex/ledger")
24
+ return false;
25
+ if (req.method !== "GET") {
26
+ // Reader-only path: no mutation endpoint lives at /ledger.
27
+ sendJson(res, 405, { error: "method_not_allowed" });
28
+ return true;
29
+ }
30
+ // Parse the optional session query parameter.
31
+ let session = "default";
32
+ const qs = url.split("?")[1];
33
+ if (qs !== undefined) {
34
+ for (const pair of qs.split("&")) {
35
+ const [k, v] = pair.split("=");
36
+ if (k === "session" && v !== undefined && v.length > 0) {
37
+ session = decodeURIComponent(v);
38
+ }
39
+ }
40
+ }
41
+ const enabled = VC1B_ENABLED();
42
+ let active = enabled;
43
+ let highWater = "0";
44
+ let count = 0;
45
+ let occurrences = [];
46
+ if (enabled) {
47
+ try {
48
+ const store = createLedgerStore({ stateDir: ctx.stateDir });
49
+ try {
50
+ const reader = store.reader();
51
+ highWater = reader.highWater(session).toString();
52
+ const rows = reader.readSession(session);
53
+ count = rows.length;
54
+ // Identity only: never sourceBytes or prompt text (reader-only rule).
55
+ occurrences = rows.slice(-500).map((occ) => ({
56
+ seq: occ.seq.toString(),
57
+ eventId: occ.eventId,
58
+ kind: occ.kind,
59
+ digest: occ.digest,
60
+ ...(occ.toolCallId !== undefined ? { toolCallId: occ.toolCallId } : {}),
61
+ }));
62
+ }
63
+ finally {
64
+ store.close();
65
+ }
66
+ }
67
+ catch {
68
+ // Non-fatal: a missing/corrupt ledger DB degrades to `enabled:false`.
69
+ active = false;
70
+ }
71
+ }
72
+ const body = {
73
+ enabled: active,
74
+ session,
75
+ highWater,
76
+ count,
77
+ occurrences,
78
+ updatedAt: new Date().toISOString(),
79
+ };
80
+ sendJson(res, 200, body);
81
+ return true;
82
+ }
@@ -0,0 +1,46 @@
1
+ /**
2
+ * dashboard-server/routes-vector-cortex-shared.ts — shared HTTP helpers for the
3
+ * per-feature vector-cortex route modules.
4
+ *
5
+ * Homes the small request/response helpers used across the VC0A/VC0C/VC1B/VC3A
6
+ * handler modules (`sendJson`, `readJsonBody`) so the feature modules stay small
7
+ * and within extension line limits.
8
+ *
9
+ * Guardrails: PREVENT-PI-004 (loopback dashboard response only), PREVENT-011 (no
10
+ * `any`), PREVENT-001 (JSON.parse guarded by an object/shape check).
11
+ */
12
+ export function sendJson(res, status, body) {
13
+ // guardrails-allow PREVENT-PI-004: loopback dashboard response (local)
14
+ res.writeHead(status, { "Content-Type": "application/json" });
15
+ res.end(JSON.stringify(body));
16
+ }
17
+ /**
18
+ * Parse a JSON request body with a size cap. `cb` receives either a validated
19
+ * plain object or an error reason. PREVENT-001: JSON.parse is guarded by a
20
+ * shape check (rejects null / arrays / non-objects).
21
+ */
22
+ export function readJsonBody(req, cb) {
23
+ let body = "";
24
+ let tooBig = false;
25
+ req.on("data", (chunk) => {
26
+ if (body.length > 65536) {
27
+ tooBig = true;
28
+ return;
29
+ }
30
+ body += chunk.toString();
31
+ });
32
+ req.on("end", () => {
33
+ if (tooBig)
34
+ return cb({ ok: false, error: "body_too_large" });
35
+ try {
36
+ const v = body ? JSON.parse(body) : {};
37
+ if (typeof v !== "object" || v === null || Array.isArray(v)) {
38
+ return cb({ ok: false, error: "invalid_object" });
39
+ }
40
+ cb({ ok: true, value: v });
41
+ }
42
+ catch {
43
+ cb({ ok: false, error: "invalid_json" });
44
+ }
45
+ });
46
+ }
@@ -0,0 +1,68 @@
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
+ import { VC3A_ENABLED } from "../../src/config.js";
17
+ import { createCortexStore } from "../../src/vector-cortex/cortex/store.js";
18
+ import { sendJson } from "./routes-vector-cortex-shared.js";
19
+ /**
20
+ * Reader-only GET /api/vector-cortex/topology (VC3A).
21
+ */
22
+ export function handleVectorCortexTopology(req, res, ctx) {
23
+ const url = req.url ?? "";
24
+ const path = url.split("?")[0] ?? url;
25
+ if (path !== "/api/vector-cortex/topology")
26
+ return false;
27
+ if (req.method !== "GET") {
28
+ // Reader-only path: no mutation endpoint lives at /topology.
29
+ sendJson(res, 405, { error: "method_not_allowed" });
30
+ return true;
31
+ }
32
+ const enabled = VC3A_ENABLED();
33
+ let active = enabled;
34
+ let summary = { generationId: null, rootDigest: null, sourceHighWater: "0", recordCount: 0, ordinal: null };
35
+ if (enabled) {
36
+ try {
37
+ const store = createCortexStore({ stateDir: ctx.stateDir });
38
+ try {
39
+ const s = store.reader().topologySummary();
40
+ summary = {
41
+ generationId: s.generationId,
42
+ rootDigest: s.rootDigest,
43
+ sourceHighWater: s.sourceHighWater,
44
+ recordCount: s.recordCount,
45
+ ordinal: s.ordinal,
46
+ };
47
+ }
48
+ finally {
49
+ store.close();
50
+ }
51
+ }
52
+ catch {
53
+ // Non-fatal: a missing/corrupt cortex DB degrades to `enabled:false`.
54
+ active = false;
55
+ }
56
+ }
57
+ const body = {
58
+ enabled: active,
59
+ generationId: summary.generationId,
60
+ rootDigest: summary.rootDigest,
61
+ sourceHighWater: summary.sourceHighWater,
62
+ recordCount: summary.recordCount,
63
+ ordinal: summary.ordinal,
64
+ updatedAt: new Date().toISOString(),
65
+ };
66
+ sendJson(res, 200, body);
67
+ return true;
68
+ }