pi-mega-compact 0.19.0 → 0.19.2
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.
- package/dist/config/vector-cortex.js +19 -0
- package/dist/config.js +1 -1
- package/dist/extensions/dashboard-server/routes-rag-settings-helpers.js +2 -0
- package/dist/extensions/dashboard-server/routes-vector-cortex-eval.js +49 -0
- package/dist/extensions/dashboard-server/routes-vector-cortex-health.js +233 -0
- package/dist/extensions/dashboard-server/routes-vector-cortex-ledger.js +82 -0
- package/dist/extensions/dashboard-server/routes-vector-cortex-shared.js +46 -0
- package/dist/extensions/dashboard-server/routes-vector-cortex-topology.js +208 -0
- package/dist/extensions/dashboard-server/routes-vector-cortex.js +12 -373
- package/dist/extensions/dashboard-server/routes.js +1 -1
- package/dist/extensions/dashboard-server/server.js +3 -1
- package/dist/src/config/vector-cortex.js +19 -0
- package/dist/src/config.js +1 -1
- package/dist/src/vector-cortex/cortex/sqlite.js +393 -0
- package/dist/src/vector-cortex/cortex/store.js +139 -0
- package/dist/src/vector-cortex/cortex/types.js +44 -0
- package/dist/src/vector-cortex/topology/build.js +232 -0
- package/dist/src/vector-cortex/topology/index.js +113 -0
- package/dist/src/vector-cortex/topology/types.js +54 -0
- package/dist/src/vector-cortex/vc3b-support.js +125 -0
- package/dist/vector-cortex/cortex/sqlite.js +393 -0
- package/dist/vector-cortex/cortex/store.js +139 -0
- package/dist/vector-cortex/cortex/types.js +44 -0
- package/dist/vector-cortex/topology/build.js +232 -0
- package/dist/vector-cortex/topology/index.js +113 -0
- package/dist/vector-cortex/topology/types.js +54 -0
- package/dist/vector-cortex/vc3b-support.js +125 -0
- package/extensions/dashboard-client/dist/assets/{AreaChart-DywU5SSt.js → AreaChart-CSaJZXru.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{AreaChart-DywU5SSt.js.map → AreaChart-CSaJZXru.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{BarChart-But7WN6K.js → BarChart-CQouNj1g.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{BarChart-But7WN6K.js.map → BarChart-CQouNj1g.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{CacheTab-7aZWa1DR.js → CacheTab-m_eiCYoL.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{CacheTab-7aZWa1DR.js.map → CacheTab-m_eiCYoL.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{EventsTab-Bf_boNG2.js → EventsTab-DRyOwjYN.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{EventsTab-Bf_boNG2.js.map → EventsTab-DRyOwjYN.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{HealthTab-AbGc1nXP.js → HealthTab-Dj9k40TJ.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{HealthTab-AbGc1nXP.js.map → HealthTab-Dj9k40TJ.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{MaintenanceTab-BfHHhn5F.js → MaintenanceTab-Bk9mhYfD.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{MaintenanceTab-BfHHhn5F.js.map → MaintenanceTab-Bk9mhYfD.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{MemoryMapTab-DrcWti0-.js → MemoryMapTab-C7ve49VG.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{MemoryMapTab-DrcWti0-.js.map → MemoryMapTab-C7ve49VG.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{MetricsTab-ALiglXQq.js → MetricsTab-DzjhqZA9.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{MetricsTab-ALiglXQq.js.map → MetricsTab-DzjhqZA9.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{OverviewTab-nnaJdNyR.js → OverviewTab-CFQdfIm_.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{OverviewTab-nnaJdNyR.js.map → OverviewTab-CFQdfIm_.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{ReposTab-BTK0nofM.js → ReposTab-DyjwEFUr.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{ReposTab-BTK0nofM.js.map → ReposTab-DyjwEFUr.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{SessionsTab-RXPNqO6x.js → SessionsTab-njLIy7ab.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{SessionsTab-RXPNqO6x.js.map → SessionsTab-njLIy7ab.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{SetupTab-Dab0AVfs.js → SetupTab-UHIs8-Lh.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{SetupTab-Dab0AVfs.js.map → SetupTab-UHIs8-Lh.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{TimeSavedCard-DIVG8hdt.js → TimeSavedCard-inWHjCxg.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{TimeSavedCard-DIVG8hdt.js.map → TimeSavedCard-inWHjCxg.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{TurnsTab-9uz2fBwx.js → TurnsTab-CXJYugBu.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{TurnsTab-9uz2fBwx.js.map → TurnsTab-CXJYugBu.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/VectorCortexTab-DkS0Azx9.js +2 -0
- package/extensions/dashboard-client/dist/assets/VectorCortexTab-DkS0Azx9.js.map +1 -0
- package/extensions/dashboard-client/dist/assets/{WikiTab-CpcgaggS.js → WikiTab-BJ4A2oi9.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{WikiTab-CpcgaggS.js.map → WikiTab-BJ4A2oi9.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{button-B0Q2fuKY.js → button-BWl-moyn.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{button-B0Q2fuKY.js.map → button-BWl-moyn.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{card-Cnik3TFr.js → card-C58RVPOk.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{card-Cnik3TFr.js.map → card-C58RVPOk.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{generateCategoricalChart-DrSwgn1V.js → generateCategoricalChart-vgeOQU3L.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{generateCategoricalChart-DrSwgn1V.js.map → generateCategoricalChart-vgeOQU3L.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/index-CYpzq9Lm.css +1 -0
- package/extensions/dashboard-client/dist/assets/{index-DraytcOY.js → index-lVrWQjpu.js} +3 -3
- package/extensions/dashboard-client/dist/assets/{index-DraytcOY.js.map → index-lVrWQjpu.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{switch-DVQ1aB9b.js → switch-CSeplFQT.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{switch-DVQ1aB9b.js.map → switch-CSeplFQT.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{toggle-Dkppx-49.js → toggle-CQRxgVRi.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{toggle-Dkppx-49.js.map → toggle-CQRxgVRi.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{useSSE-CPkjU4Gx.js → useSSE-BUz6IOI-.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{useSSE-CPkjU4Gx.js.map → useSSE-BUz6IOI-.js.map} +1 -1
- package/extensions/dashboard-client/dist/index.html +2 -2
- package/extensions/dashboard-client/src/api/vector-cortex.ts +9 -0
- package/extensions/dashboard-client/src/tabs/VectorCortexTab.tsx +89 -0
- package/extensions/dashboard-client/src/types/vector-cortex.ts +28 -0
- package/extensions/dashboard-server/api-contracts/vector-cortex.ts +41 -0
- package/extensions/dashboard-server/routes-rag-settings-helpers.ts +12 -0
- package/extensions/dashboard-server/routes-vector-cortex-eval.ts +59 -0
- package/extensions/dashboard-server/routes-vector-cortex-health.ts +273 -0
- package/extensions/dashboard-server/routes-vector-cortex-ledger.ts +92 -0
- package/extensions/dashboard-server/routes-vector-cortex-shared.ts +53 -0
- package/extensions/dashboard-server/routes-vector-cortex-topology.ts +244 -0
- package/extensions/dashboard-server/routes-vector-cortex.ts +12 -431
- package/extensions/dashboard-server/routes.ts +1 -0
- package/extensions/dashboard-server/server.ts +2 -0
- package/package.json +1 -1
- package/src/config/vector-cortex.ts +21 -0
- package/src/config.ts +2 -0
- package/src/vector-cortex/cortex/sqlite.ts +489 -0
- package/src/vector-cortex/cortex/store.ts +202 -0
- package/src/vector-cortex/cortex/types.ts +194 -0
- package/src/vector-cortex/topology/build.ts +259 -0
- package/src/vector-cortex/topology/index.ts +143 -0
- package/src/vector-cortex/topology/types.ts +156 -0
- package/src/vector-cortex/vc3b-support.ts +142 -0
- package/extensions/dashboard-client/dist/assets/VectorCortexTab-DnKY61EJ.js +0 -2
- package/extensions/dashboard-client/dist/assets/VectorCortexTab-DnKY61EJ.js.map +0 -1
- package/extensions/dashboard-client/dist/assets/index-CfvziyBi.css +0 -1
|
@@ -119,6 +119,47 @@ export interface VectorCortexResetResult {
|
|
|
119
119
|
readonly updatedAt: string;
|
|
120
120
|
}
|
|
121
121
|
|
|
122
|
+
/**
|
|
123
|
+
* Reader-only cortex topology view for GET /api/vector-cortex/topology (VC3A).
|
|
124
|
+
* Built on the CortexReader capability surface ONLY — it exposes the flagged
|
|
125
|
+
* enabled state, active generation identity, one root digest, derived frontier
|
|
126
|
+
* and record count, and NEVER append/rebuild capability or raw record payloads.
|
|
127
|
+
*/
|
|
128
|
+
export interface VectorCortexTopologyView {
|
|
129
|
+
/** Whether the VC3A cortex-store flag is enabled in this process. */
|
|
130
|
+
readonly enabled: boolean;
|
|
131
|
+
/** Active generation id, or null when none rebuilt yet. */
|
|
132
|
+
readonly generationId: string | null;
|
|
133
|
+
/** Active generation root digest, or null. */
|
|
134
|
+
readonly rootDigest: string | null;
|
|
135
|
+
/** Derived frontier (active generation sourceHighWater, else "0"). */
|
|
136
|
+
readonly sourceHighWater: string;
|
|
137
|
+
/** Accepted derived record count. */
|
|
138
|
+
readonly recordCount: number;
|
|
139
|
+
/** Monotonic rebuild ordinal, or null. */
|
|
140
|
+
readonly ordinal: string | null;
|
|
141
|
+
/**
|
|
142
|
+
* VC3B deterministic topology node/edge shapes — present ONLY when the VC3B
|
|
143
|
+
* flag is enabled (flag-off omits them, byte-identical to the VC3A
|
|
144
|
+
* predecessor view). Built reader-only from the accepted derived records and
|
|
145
|
+
* best-effort: an unavailable or un-stored graph degrades to empty arrays,
|
|
146
|
+
* never an error. The exact node (`id`/`kind`) and edge
|
|
147
|
+
* (`source`/`target`/`head`/`score`/`direction`) shapes match TopologyV1.
|
|
148
|
+
*/
|
|
149
|
+
readonly nodes?: readonly { id: string; kind: string }[];
|
|
150
|
+
readonly edges?: readonly {
|
|
151
|
+
source: string;
|
|
152
|
+
target: string;
|
|
153
|
+
head: string;
|
|
154
|
+
score: number;
|
|
155
|
+
direction: string;
|
|
156
|
+
}[];
|
|
157
|
+
/** Stable graph generation digest (VC3B), when the graph was built. */
|
|
158
|
+
readonly generationDigest?: string | null;
|
|
159
|
+
/** ISO timestamp of the snapshot. */
|
|
160
|
+
readonly updatedAt: string;
|
|
161
|
+
}
|
|
162
|
+
|
|
122
163
|
/**
|
|
123
164
|
* Reader-only occurrence-ledger view for GET /api/vector-cortex/ledger (VC1B).
|
|
124
165
|
* Built on the LedgerReader capability surface. Exposes occurrence IDENTITY
|
|
@@ -331,6 +331,18 @@ export const SETTINGS: ReadonlyArray<{
|
|
|
331
331
|
"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.",
|
|
332
332
|
true,
|
|
333
333
|
),
|
|
334
|
+
boolDirect(
|
|
335
|
+
"MEGACOMPACT_VC3A",
|
|
336
|
+
"VC3A Cortex Store",
|
|
337
|
+
"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.",
|
|
338
|
+
true,
|
|
339
|
+
),
|
|
340
|
+
boolDirect(
|
|
341
|
+
"MEGACOMPACT_VC3B",
|
|
342
|
+
"VC3B Deterministic Topology",
|
|
343
|
+
"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.",
|
|
344
|
+
true,
|
|
345
|
+
),
|
|
334
346
|
],
|
|
335
347
|
},
|
|
336
348
|
{
|
|
@@ -0,0 +1,59 @@
|
|
|
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
|
+
|
|
13
|
+
import type { IncomingMessage, ServerResponse } from "node:http";
|
|
14
|
+
import type { RouteContext } from "./routes-core.js";
|
|
15
|
+
import { VC0A_ENABLED } from "../../src/config.js";
|
|
16
|
+
import { readEvalRows } from "../../src/vector-cortex/eval/persist.js";
|
|
17
|
+
import { summarizeEvalRows } from "../../src/vector-cortex/eval/reader.js";
|
|
18
|
+
import { sendJson } from "./routes-vector-cortex-shared.js";
|
|
19
|
+
import type { VectorCortexEvaluationSummary } from "./api-contracts/vector-cortex.js";
|
|
20
|
+
|
|
21
|
+
/** Reader-only aggregate GET /api/vector-cortex/evaluation. */
|
|
22
|
+
export function handleVectorCortexEvaluation(
|
|
23
|
+
req: IncomingMessage,
|
|
24
|
+
res: ServerResponse,
|
|
25
|
+
ctx: RouteContext,
|
|
26
|
+
): boolean {
|
|
27
|
+
const url = req.url ?? "";
|
|
28
|
+
if (url !== "/api/vector-cortex/evaluation") return false;
|
|
29
|
+
if (req.method !== "GET") {
|
|
30
|
+
// Reader-only: no mutation endpoints exist on this path.
|
|
31
|
+
sendJson(res, 405, { error: "method_not_allowed" });
|
|
32
|
+
return true;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const enabled = VC0A_ENABLED();
|
|
36
|
+
const rows = enabled ? readEvalRows(ctx.stateDir) : [];
|
|
37
|
+
const summary = summarizeEvalRows(rows);
|
|
38
|
+
|
|
39
|
+
const body: VectorCortexEvaluationSummary = {
|
|
40
|
+
enabled,
|
|
41
|
+
mode: enabled ? "A" : "C",
|
|
42
|
+
samples: summary.samples,
|
|
43
|
+
byMode: {
|
|
44
|
+
A: summary.byMode.A,
|
|
45
|
+
B: summary.byMode.B,
|
|
46
|
+
C: summary.byMode.C,
|
|
47
|
+
},
|
|
48
|
+
histogram: {
|
|
49
|
+
edges: [...summary.histogram.edges],
|
|
50
|
+
cells: [...summary.histogram.cells],
|
|
51
|
+
overflow: summary.histogram.overflow,
|
|
52
|
+
total: summary.histogram.total,
|
|
53
|
+
},
|
|
54
|
+
rejects: [], // VC0C wires live breaker/reject telemetry here
|
|
55
|
+
updatedAt: new Date().toISOString(),
|
|
56
|
+
};
|
|
57
|
+
sendJson(res, 200, body);
|
|
58
|
+
return true;
|
|
59
|
+
}
|
|
@@ -0,0 +1,273 @@
|
|
|
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
|
+
|
|
12
|
+
import type { IncomingMessage, ServerResponse } from "node:http";
|
|
13
|
+
import { createHash } from "node:crypto";
|
|
14
|
+
import { readFileSync, statSync } from "node:fs";
|
|
15
|
+
import { join, dirname } from "node:path";
|
|
16
|
+
import { fileURLToPath } from "node:url";
|
|
17
|
+
import type { RouteContext } from "./routes-core.js";
|
|
18
|
+
import { VC0C_ENABLED, VC2C_ENABLED } from "../../src/config.js";
|
|
19
|
+
import { createVectorCortexSafety } from "../mega-runtime/vector-cortex-safety.js";
|
|
20
|
+
import { readEncoderManifest, verifyEncoderAsset, detectPlatform } from "../../src/vector-cortex/encoder/asset.js";
|
|
21
|
+
import { sendJson, readJsonBody } from "./routes-vector-cortex-shared.js";
|
|
22
|
+
import type {
|
|
23
|
+
VectorCortexHealthCard,
|
|
24
|
+
VectorCortexResetResult,
|
|
25
|
+
} from "./api-contracts/vector-cortex.js";
|
|
26
|
+
|
|
27
|
+
/** Resolve the committed encoder-v1 asset dir by walking up to the repo root. */
|
|
28
|
+
function encoderAssetDir(): string | null {
|
|
29
|
+
let dir = dirname(fileURLToPath(import.meta.url));
|
|
30
|
+
const rel = join("assets", "vector-cortex", "encoder-v1");
|
|
31
|
+
for (let i = 0; i < 8; i++) {
|
|
32
|
+
const candidate = join(dir, rel);
|
|
33
|
+
try {
|
|
34
|
+
// guardrails-allow PREVENT-PI-004: local asset filesystem read (loopback)
|
|
35
|
+
readFileSync(join(candidate, "manifest.json"));
|
|
36
|
+
return candidate;
|
|
37
|
+
} catch {
|
|
38
|
+
/* keep walking */
|
|
39
|
+
}
|
|
40
|
+
const next = dirname(dir);
|
|
41
|
+
if (next === dir) break;
|
|
42
|
+
dir = next;
|
|
43
|
+
}
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* VC2C encoder health facts (task 5): the SHA-256 of the committed qualified
|
|
49
|
+
* manifest (asset digest) and the encoder triad mode. Reader-only aggregate
|
|
50
|
+
* (digest prefix, no bytes). Gated on MEGACOMPACT_VC2C: when the flag is OFF
|
|
51
|
+
* (rollback), the card reports mode C with an absent digest — consistent with
|
|
52
|
+
* the rest of the card, whose enabled/mode fields reflect active (flag-gated)
|
|
53
|
+
* state. When ON: "A" when the committed asset verifies on this host, "B" when
|
|
54
|
+
* present but not verified (demotion), "C" when absent.
|
|
55
|
+
*
|
|
56
|
+
* The verification hashes the full ONNX + tokenizer bytes, which is expensive
|
|
57
|
+
* on a periodically-polled endpoint as the shipped asset grows. The result is
|
|
58
|
+
* memoized against a cheap key (manifest bytes + file sizes/mtimes + platform);
|
|
59
|
+
* any on-disk mutation invalidates the key, so the cache never goes stale while
|
|
60
|
+
* avoiding the repeated large-file hashing. A failed digest read returns null
|
|
61
|
+
* (an absent digest), never a misleading zero-sentinel.
|
|
62
|
+
*/
|
|
63
|
+
type EncoderHealthFacts = { assetDigest: string | null; mode: "A" | "B" | "C" };
|
|
64
|
+
|
|
65
|
+
interface HealthFactCache {
|
|
66
|
+
key: string;
|
|
67
|
+
facts: EncoderHealthFacts;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
let healthCache: HealthFactCache | null = null;
|
|
71
|
+
|
|
72
|
+
/** Stable cache key: manifest bytes + (size,mtime) of the asset files + platform. */
|
|
73
|
+
function healthFactCacheKey(dir: string, manifestPath: string): string | null {
|
|
74
|
+
const platform = detectPlatform();
|
|
75
|
+
if (!platform) return null;
|
|
76
|
+
const parts: string[] = [platform];
|
|
77
|
+
try {
|
|
78
|
+
for (const p of [manifestPath, join(dir, "model.onnx"), join(dir, "tokenizer.json")]) {
|
|
79
|
+
const s = statSync(p);
|
|
80
|
+
parts.push(`${s.size}:${s.mtimeMs}`);
|
|
81
|
+
}
|
|
82
|
+
// guardrails-allow PREVENT-PI-004: local manifest filesystem read (loopback)
|
|
83
|
+
parts.push(createHash("sha256").update(readFileSync(manifestPath)).digest("hex"));
|
|
84
|
+
} catch {
|
|
85
|
+
return null;
|
|
86
|
+
}
|
|
87
|
+
return parts.join("|");
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function computeEncoderHealthFacts(dir: string): EncoderHealthFacts | null {
|
|
91
|
+
const manifest = readEncoderManifest(dir);
|
|
92
|
+
if (manifest === null) return { assetDigest: null, mode: "C" };
|
|
93
|
+
const manifestPath = join(dir, "manifest.json");
|
|
94
|
+
const key = healthFactCacheKey(dir, manifestPath);
|
|
95
|
+
if (key === null) return null;
|
|
96
|
+
if (healthCache !== null && healthCache.key === key) return healthCache.facts;
|
|
97
|
+
let digest: string;
|
|
98
|
+
try {
|
|
99
|
+
// guardrails-allow PREVENT-PI-004: local manifest filesystem read (loopback)
|
|
100
|
+
digest = createHash("sha256").update(readFileSync(manifestPath)).digest("hex");
|
|
101
|
+
} catch {
|
|
102
|
+
return { assetDigest: null, mode: "B" };
|
|
103
|
+
}
|
|
104
|
+
const verify = verifyEncoderAsset(dir, manifest, detectPlatform());
|
|
105
|
+
const facts: EncoderHealthFacts = { assetDigest: digest, mode: verify.ok ? "A" : "B" };
|
|
106
|
+
healthCache = { key, facts };
|
|
107
|
+
return facts;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
function encoderHealthFacts(): EncoderHealthFacts {
|
|
111
|
+
if (!VC2C_ENABLED()) {
|
|
112
|
+
// Rollback: MEGACOMPACT_VC2C=0 selects C — report the inactive (flag-gated)
|
|
113
|
+
// mode with no asset digest rather than an on-disk-computed A/B.
|
|
114
|
+
return { assetDigest: null, mode: "C" };
|
|
115
|
+
}
|
|
116
|
+
const dir = encoderAssetDir();
|
|
117
|
+
if (dir === null) return { assetDigest: null, mode: "C" };
|
|
118
|
+
const facts = computeEncoderHealthFacts(dir);
|
|
119
|
+
if (facts === null) return { assetDigest: null, mode: "C" };
|
|
120
|
+
return facts;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Reader-only GET /api/vector-cortex/health (VC0C).
|
|
125
|
+
*
|
|
126
|
+
* Aggregate health card: breaker state (window/probe/backoff), durable spool
|
|
127
|
+
* frontier/authority/lag, and a worst-state aggregate. Constructs the safety
|
|
128
|
+
* adapter over the state dir — durable spool state (frontier-frozen, lag) is
|
|
129
|
+
* read from disk, so it reflects restart. Purely read: no mutation, never
|
|
130
|
+
* payloads/prompts/ledger.
|
|
131
|
+
*/
|
|
132
|
+
export function handleVectorCortexHealth(
|
|
133
|
+
req: IncomingMessage,
|
|
134
|
+
res: ServerResponse,
|
|
135
|
+
ctx: RouteContext,
|
|
136
|
+
): boolean {
|
|
137
|
+
const url = req.url ?? "";
|
|
138
|
+
if (url !== "/api/vector-cortex/health") return false;
|
|
139
|
+
if (req.method !== "GET") {
|
|
140
|
+
// Reader-only path: no mutation endpoint lives at /health.
|
|
141
|
+
sendJson(res, 405, { error: "method_not_allowed" });
|
|
142
|
+
return true;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
const enabled = VC0C_ENABLED();
|
|
146
|
+
const safety = enabled ? createVectorCortexSafety({ stateDir: ctx.stateDir }) : null;
|
|
147
|
+
const card = safety ? safety.health() : null;
|
|
148
|
+
|
|
149
|
+
const enc = encoderHealthFacts();
|
|
150
|
+
|
|
151
|
+
const fallback: VectorCortexHealthCard = {
|
|
152
|
+
enabled: false,
|
|
153
|
+
mode: "C",
|
|
154
|
+
state: "CLOSED_A",
|
|
155
|
+
subsystem: "provider",
|
|
156
|
+
sinceMs: 0,
|
|
157
|
+
windowMs: 0,
|
|
158
|
+
probeCount: 0,
|
|
159
|
+
backoffDelayMs: 0,
|
|
160
|
+
frontierFrozen: false,
|
|
161
|
+
authorityOutage: false,
|
|
162
|
+
spoolLag: 0,
|
|
163
|
+
attempts: 0,
|
|
164
|
+
failures: 0,
|
|
165
|
+
p95Ms: 0,
|
|
166
|
+
failureRate: 0,
|
|
167
|
+
updatedAt: new Date().toISOString(),
|
|
168
|
+
aggregate: "CLOSED_A",
|
|
169
|
+
stateSource: "ephemeral",
|
|
170
|
+
encoderAssetDigest: enc.assetDigest,
|
|
171
|
+
encoderMode: enc.mode,
|
|
172
|
+
};
|
|
173
|
+
if (!card) {
|
|
174
|
+
sendJson(res, 200, fallback);
|
|
175
|
+
return true;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
const mode: "A" | "B" | "C" =
|
|
179
|
+
card.state === "CLOSED_A" ? "A" : card.state === "MANUAL_HALT" ? "C" : "B";
|
|
180
|
+
const aggregate =
|
|
181
|
+
card.state === "MANUAL_HALT"
|
|
182
|
+
? "MANUAL_HALT"
|
|
183
|
+
: card.state === "OPEN_C"
|
|
184
|
+
? "OPEN_C"
|
|
185
|
+
: card.state === "OPEN_B"
|
|
186
|
+
? "OPEN_B"
|
|
187
|
+
: card.state === "PROBE_B" || card.state === "PROBE_A"
|
|
188
|
+
? "PROBE"
|
|
189
|
+
: "CLOSED_A";
|
|
190
|
+
|
|
191
|
+
const body: VectorCortexHealthCard = {
|
|
192
|
+
enabled,
|
|
193
|
+
mode,
|
|
194
|
+
state: card.state,
|
|
195
|
+
subsystem: card.subsystem,
|
|
196
|
+
sinceMs: card.sinceMs,
|
|
197
|
+
reason: card.reason,
|
|
198
|
+
windowMs: card.windowMs,
|
|
199
|
+
probeCount: card.probeCount,
|
|
200
|
+
backoffDelayMs: card.backoffDelayMs,
|
|
201
|
+
frontierFrozen: card.frontierFrozen,
|
|
202
|
+
authorityOutage: card.authorityOutage,
|
|
203
|
+
spoolLag: card.spoolLag,
|
|
204
|
+
attempts: card.attempts,
|
|
205
|
+
failures: card.failures,
|
|
206
|
+
p95Ms: card.p95Ms,
|
|
207
|
+
failureRate: card.failureRate,
|
|
208
|
+
updatedAt: new Date().toISOString(),
|
|
209
|
+
aggregate,
|
|
210
|
+
stateSource: card.stateSource,
|
|
211
|
+
encoderAssetDigest: enc.assetDigest,
|
|
212
|
+
encoderMode: enc.mode,
|
|
213
|
+
};
|
|
214
|
+
sendJson(res, 200, body);
|
|
215
|
+
return true;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
/**
|
|
219
|
+
* Admin POST /api/vector-cortex/breakers/reset (VC0C).
|
|
220
|
+
*
|
|
221
|
+
* Explicit admin capability (separate from the reader GET). Clears a breaker's
|
|
222
|
+
* cooldown — or unwires a MANUAL_HALT — but NEVER evidence (attempts/failures
|
|
223
|
+
* are retained, per TRIAD_RESILIENCE). The subsystem is actor-supplied via the
|
|
224
|
+
* JSON body `{ subsystem }`. Every reset is documented in the returned record
|
|
225
|
+
* (state, retained evidence, updatedAt) — an auditable mutation surface; the
|
|
226
|
+
* GET path can never mutate.
|
|
227
|
+
*/
|
|
228
|
+
export function handleVectorCortexBreakersReset(
|
|
229
|
+
req: IncomingMessage,
|
|
230
|
+
res: ServerResponse,
|
|
231
|
+
ctx: RouteContext,
|
|
232
|
+
): boolean {
|
|
233
|
+
const url = req.url ?? "";
|
|
234
|
+
if (url !== "/api/vector-cortex/breakers/reset") return false;
|
|
235
|
+
if (req.method !== "POST") {
|
|
236
|
+
sendJson(res, 405, { error: "method_not_allowed" });
|
|
237
|
+
return true;
|
|
238
|
+
}
|
|
239
|
+
if (!VC0C_ENABLED()) {
|
|
240
|
+
sendJson(res, 409, { error: "vco_c_disabled" });
|
|
241
|
+
return true;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
readJsonBody(req, (parsed) => {
|
|
245
|
+
if (!parsed.ok) {
|
|
246
|
+
sendJson(res, 400, { error: parsed.error });
|
|
247
|
+
return;
|
|
248
|
+
}
|
|
249
|
+
const subsystem = parsed.value.subsystem;
|
|
250
|
+
if (typeof subsystem !== "string" || subsystem.length === 0) {
|
|
251
|
+
sendJson(res, 400, { error: "subsystem_required" });
|
|
252
|
+
return;
|
|
253
|
+
}
|
|
254
|
+
try {
|
|
255
|
+
const safety = createVectorCortexSafety({ stateDir: ctx.stateDir });
|
|
256
|
+
const rec = safety.reset(subsystem);
|
|
257
|
+
const body: VectorCortexResetResult = {
|
|
258
|
+
subsystem: rec.subsystem,
|
|
259
|
+
state: rec.state,
|
|
260
|
+
cooldownCleared: true,
|
|
261
|
+
attempts: rec.attempts,
|
|
262
|
+
failures: rec.failures,
|
|
263
|
+
probeCount: rec.probeCount,
|
|
264
|
+
manualReason: rec.manualReason,
|
|
265
|
+
updatedAt: rec.updatedAt,
|
|
266
|
+
};
|
|
267
|
+
sendJson(res, 200, body);
|
|
268
|
+
} catch {
|
|
269
|
+
sendJson(res, 500, { error: "reset_failed" });
|
|
270
|
+
}
|
|
271
|
+
});
|
|
272
|
+
return true;
|
|
273
|
+
}
|
|
@@ -0,0 +1,92 @@
|
|
|
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
|
+
|
|
15
|
+
import type { IncomingMessage, ServerResponse } from "node:http";
|
|
16
|
+
import type { RouteContext } from "./routes-core.js";
|
|
17
|
+
import { VC1B_ENABLED } from "../../src/config.js";
|
|
18
|
+
import { createLedgerStore } from "../../src/vector-cortex/ledger/store.js";
|
|
19
|
+
import { sendJson } from "./routes-vector-cortex-shared.js";
|
|
20
|
+
import type { VectorCortexLedgerView } from "./api-contracts/vector-cortex.js";
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Reader-only GET /api/vector-cortex/ledger (VC1B).
|
|
24
|
+
*/
|
|
25
|
+
export function handleVectorCortexLedger(
|
|
26
|
+
req: IncomingMessage,
|
|
27
|
+
res: ServerResponse,
|
|
28
|
+
ctx: RouteContext,
|
|
29
|
+
): boolean {
|
|
30
|
+
const url = req.url ?? "";
|
|
31
|
+
const path = url.split("?")[0] ?? url;
|
|
32
|
+
if (path !== "/api/vector-cortex/ledger") return false;
|
|
33
|
+
if (req.method !== "GET") {
|
|
34
|
+
// Reader-only path: no mutation endpoint lives at /ledger.
|
|
35
|
+
sendJson(res, 405, { error: "method_not_allowed" });
|
|
36
|
+
return true;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// Parse the optional session query parameter.
|
|
40
|
+
let session = "default";
|
|
41
|
+
const qs = url.split("?")[1];
|
|
42
|
+
if (qs !== undefined) {
|
|
43
|
+
for (const pair of qs.split("&")) {
|
|
44
|
+
const [k, v] = pair.split("=");
|
|
45
|
+
if (k === "session" && v !== undefined && v.length > 0) {
|
|
46
|
+
session = decodeURIComponent(v);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const enabled = VC1B_ENABLED();
|
|
52
|
+
let active = enabled;
|
|
53
|
+
let highWater = "0";
|
|
54
|
+
let count = 0;
|
|
55
|
+
let occurrences: VectorCortexLedgerView["occurrences"] = [];
|
|
56
|
+
|
|
57
|
+
if (enabled) {
|
|
58
|
+
try {
|
|
59
|
+
const store = createLedgerStore({ stateDir: ctx.stateDir });
|
|
60
|
+
try {
|
|
61
|
+
const reader = store.reader();
|
|
62
|
+
highWater = reader.highWater(session).toString();
|
|
63
|
+
const rows = reader.readSession(session);
|
|
64
|
+
count = rows.length;
|
|
65
|
+
// Identity only: never sourceBytes or prompt text (reader-only rule).
|
|
66
|
+
occurrences = rows.slice(-500).map((occ) => ({
|
|
67
|
+
seq: occ.seq.toString(),
|
|
68
|
+
eventId: occ.eventId,
|
|
69
|
+
kind: occ.kind,
|
|
70
|
+
digest: occ.digest,
|
|
71
|
+
...(occ.toolCallId !== undefined ? { toolCallId: occ.toolCallId } : {}),
|
|
72
|
+
}));
|
|
73
|
+
} finally {
|
|
74
|
+
store.close();
|
|
75
|
+
}
|
|
76
|
+
} catch {
|
|
77
|
+
// Non-fatal: a missing/corrupt ledger DB degrades to `enabled:false`.
|
|
78
|
+
active = false;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const body: VectorCortexLedgerView = {
|
|
83
|
+
enabled: active,
|
|
84
|
+
session,
|
|
85
|
+
highWater,
|
|
86
|
+
count,
|
|
87
|
+
occurrences,
|
|
88
|
+
updatedAt: new Date().toISOString(),
|
|
89
|
+
};
|
|
90
|
+
sendJson(res, 200, body);
|
|
91
|
+
return true;
|
|
92
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
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
|
+
|
|
13
|
+
import type { IncomingMessage, ServerResponse } from "node:http";
|
|
14
|
+
|
|
15
|
+
export function sendJson(res: ServerResponse, status: number, body: unknown): void {
|
|
16
|
+
// guardrails-allow PREVENT-PI-004: loopback dashboard response (local)
|
|
17
|
+
res.writeHead(status, { "Content-Type": "application/json" });
|
|
18
|
+
res.end(JSON.stringify(body));
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Parse a JSON request body with a size cap. `cb` receives either a validated
|
|
23
|
+
* plain object or an error reason. PREVENT-001: JSON.parse is guarded by a
|
|
24
|
+
* shape check (rejects null / arrays / non-objects).
|
|
25
|
+
*/
|
|
26
|
+
export function readJsonBody(
|
|
27
|
+
req: IncomingMessage,
|
|
28
|
+
cb: (
|
|
29
|
+
result: { ok: true; value: Record<string, unknown> } | { ok: false; error: string },
|
|
30
|
+
) => void,
|
|
31
|
+
): void {
|
|
32
|
+
let body = "";
|
|
33
|
+
let tooBig = false;
|
|
34
|
+
req.on("data", (chunk: Buffer) => {
|
|
35
|
+
if (body.length > 65536) {
|
|
36
|
+
tooBig = true;
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
body += chunk.toString();
|
|
40
|
+
});
|
|
41
|
+
req.on("end", () => {
|
|
42
|
+
if (tooBig) return cb({ ok: false, error: "body_too_large" });
|
|
43
|
+
try {
|
|
44
|
+
const v = body ? JSON.parse(body) : {};
|
|
45
|
+
if (typeof v !== "object" || v === null || Array.isArray(v)) {
|
|
46
|
+
return cb({ ok: false, error: "invalid_object" });
|
|
47
|
+
}
|
|
48
|
+
cb({ ok: true, value: v as Record<string, unknown> });
|
|
49
|
+
} catch {
|
|
50
|
+
cb({ ok: false, error: "invalid_json" });
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
}
|