pi-mega-compact 0.19.1 → 0.19.3
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 +21 -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-query.js +46 -0
- package/dist/extensions/dashboard-server/routes-vector-cortex-topology.js +145 -5
- package/dist/extensions/dashboard-server/routes-vector-cortex.js +1 -0
- 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 +21 -0
- package/dist/src/config.js +1 -1
- package/dist/src/tieredRouter.js +8 -0
- package/dist/src/vector-cortex/migrations/router-generation-v2.js +252 -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/query.js +342 -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/migrations/router-generation-v2.js +252 -0
- package/dist/vector-cortex/topology/build.js +232 -0
- package/dist/vector-cortex/topology/index.js +113 -0
- package/dist/vector-cortex/topology/query.js +342 -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-B9KYKrUE.js → AreaChart-DqiFSnDx.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{AreaChart-B9KYKrUE.js.map → AreaChart-DqiFSnDx.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{BarChart-D1sWkR6j.js → BarChart-Cqg-PQMK.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{BarChart-D1sWkR6j.js.map → BarChart-Cqg-PQMK.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{CacheTab-BR8MYcJq.js → CacheTab-BPNs0xIF.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{CacheTab-BR8MYcJq.js.map → CacheTab-BPNs0xIF.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{EventsTab-BRNpDMvP.js → EventsTab-BQf7OGkf.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{EventsTab-BRNpDMvP.js.map → EventsTab-BQf7OGkf.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{HealthTab-rr5nXpjq.js → HealthTab-B14TaSPN.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{HealthTab-rr5nXpjq.js.map → HealthTab-B14TaSPN.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{MaintenanceTab-CtjPWnzN.js → MaintenanceTab-D8lkRoa1.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{MaintenanceTab-CtjPWnzN.js.map → MaintenanceTab-D8lkRoa1.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{MemoryMapTab-5SnFDIYc.js → MemoryMapTab-BOWtGfpx.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{MemoryMapTab-5SnFDIYc.js.map → MemoryMapTab-BOWtGfpx.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{MetricsTab-4MZfwRhq.js → MetricsTab-7XI9cWaX.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{MetricsTab-4MZfwRhq.js.map → MetricsTab-7XI9cWaX.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{OverviewTab-BAKENnbk.js → OverviewTab-C9KaGYvh.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{OverviewTab-BAKENnbk.js.map → OverviewTab-C9KaGYvh.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{ReposTab-7-z_OmZo.js → ReposTab-BwESNhox.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{ReposTab-7-z_OmZo.js.map → ReposTab-BwESNhox.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{SessionsTab-D_r2ki0y.js → SessionsTab-DKH55Rda.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{SessionsTab-D_r2ki0y.js.map → SessionsTab-DKH55Rda.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{SetupTab-DPujtYgv.js → SetupTab-zDxf-nJd.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{SetupTab-DPujtYgv.js.map → SetupTab-zDxf-nJd.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{TimeSavedCard-CLHy30t6.js → TimeSavedCard-C9isog4L.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{TimeSavedCard-CLHy30t6.js.map → TimeSavedCard-C9isog4L.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{TurnsTab-Coul6CHc.js → TurnsTab-ciI6ydvj.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{TurnsTab-Coul6CHc.js.map → TurnsTab-ciI6ydvj.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/VectorCortexTab-qTZ7NWng.js +2 -0
- package/extensions/dashboard-client/dist/assets/VectorCortexTab-qTZ7NWng.js.map +1 -0
- package/extensions/dashboard-client/dist/assets/{WikiTab-hryG5oyY.js → WikiTab-DcYHc734.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{WikiTab-hryG5oyY.js.map → WikiTab-DcYHc734.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{button-Dxo95lRI.js → button-DF8lx4bt.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{button-Dxo95lRI.js.map → button-DF8lx4bt.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{card-FXwhLF_u.js → card-DIoDheSZ.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{card-FXwhLF_u.js.map → card-DIoDheSZ.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{generateCategoricalChart-M-GeRM8U.js → generateCategoricalChart-BFRzeYX3.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{generateCategoricalChart-M-GeRM8U.js.map → generateCategoricalChart-BFRzeYX3.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{index-BIZZXvoy.js → index-DSZON0Yi.js} +3 -3
- package/extensions/dashboard-client/dist/assets/{index-BIZZXvoy.js.map → index-DSZON0Yi.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{switch-C-d4tkN1.js → switch-l4qo22mU.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{switch-C-d4tkN1.js.map → switch-l4qo22mU.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{toggle-Bfmucdcl.js → toggle-DPn6td1_.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{toggle-Bfmucdcl.js.map → toggle-DPn6td1_.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{useSSE-CxK_wdmk.js → useSSE-BLmolqTJ.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{useSSE-CxK_wdmk.js.map → useSSE-BLmolqTJ.js.map} +1 -1
- package/extensions/dashboard-client/dist/index.html +1 -1
- package/extensions/dashboard-client/src/api/vector-cortex.ts +9 -0
- package/extensions/dashboard-client/src/tabs/VectorCortexTab.tsx +82 -0
- package/extensions/dashboard-client/src/types/vector-cortex.ts +25 -0
- package/extensions/dashboard-server/api-contracts/vector-cortex.ts +35 -0
- package/extensions/dashboard-server/routes-rag-settings-helpers.ts +12 -0
- package/extensions/dashboard-server/routes-vector-cortex-query.ts +54 -0
- package/extensions/dashboard-server/routes-vector-cortex-topology.ts +166 -5
- package/extensions/dashboard-server/routes-vector-cortex.ts +1 -0
- 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 +23 -0
- package/src/config.ts +2 -0
- package/src/tieredRouter.ts +9 -0
- package/src/vector-cortex/migrations/router-generation-v2.ts +317 -0
- package/src/vector-cortex/topology/build.ts +259 -0
- package/src/vector-cortex/topology/index.ts +143 -0
- package/src/vector-cortex/topology/query.ts +485 -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-rqBpWc7A.js +0 -2
- package/extensions/dashboard-client/dist/assets/VectorCortexTab-rqBpWc7A.js.map +0 -1
|
@@ -138,6 +138,41 @@ export interface VectorCortexTopologyView {
|
|
|
138
138
|
readonly recordCount: number;
|
|
139
139
|
/** Monotonic rebuild ordinal, or null. */
|
|
140
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
|
+
|
|
163
|
+
/**
|
|
164
|
+
* Reader-only query-layer diagnostics view for GET /api/vector-cortex/query
|
|
165
|
+
* (VC3C). Purely a flag-status + structural diagnostic — reports whether the
|
|
166
|
+
* VC3C flag is enabled and the router-generation v2 version constant. The VC3C
|
|
167
|
+
* query index is in-memory (not durable), so no payloads, prompts, or index
|
|
168
|
+
* contents are ever exposed. Non-fatal: a missing state dir or internal error
|
|
169
|
+
* degrades to `enabled:false`.
|
|
170
|
+
*/
|
|
171
|
+
export interface VectorCortexQueryView {
|
|
172
|
+
/** Whether the VC3C query-layer flag is enabled in this process. */
|
|
173
|
+
readonly enabled: boolean;
|
|
174
|
+
/** Router-generation v2 key version constant (query index format). */
|
|
175
|
+
readonly routerVersion: number;
|
|
141
176
|
/** ISO timestamp of the snapshot. */
|
|
142
177
|
readonly updatedAt: string;
|
|
143
178
|
}
|
|
@@ -337,6 +337,18 @@ export const SETTINGS: ReadonlyArray<{
|
|
|
337
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
338
|
true,
|
|
339
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
|
+
),
|
|
346
|
+
boolDirect(
|
|
347
|
+
"MEGACOMPACT_VC3C",
|
|
348
|
+
"VC3C Topology Query + Router Invalidation",
|
|
349
|
+
"TopologyQueryV1/RouterKeyV2 structured keys (length-delimited, unsigned-byte order, no prefix ambiguity), exact (session,generation) invalidation, stale-generation rejection (TOP_GENERATION_STALE), and the M6 router-generation-v2 copy/validate/switch migration. OFF = mode C, no structured router key / generation invalidation, byte-identical predecessor.",
|
|
350
|
+
true,
|
|
351
|
+
),
|
|
340
352
|
],
|
|
341
353
|
},
|
|
342
354
|
{
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* dashboard-server/routes-vector-cortex-query.ts — VC3C vector-cortex query-layer
|
|
3
|
+
* diagnostics dashboard route.
|
|
4
|
+
*
|
|
5
|
+
* Reader-only GET /api/vector-cortex/query. Purely a flag-status + structural
|
|
6
|
+
* diagnostic: the VC3C query index is in-memory (not durable), so this route
|
|
7
|
+
* reports whether the VC3C flag is enabled, the router-generation v2 version
|
|
8
|
+
* constant, and a snapshot timestamp. It NEVER exposes payloads or prompts.
|
|
9
|
+
* Non-fatal: a missing state dir (or any internal error) degrades to
|
|
10
|
+
* `enabled:false`.
|
|
11
|
+
*
|
|
12
|
+
* Guardrails: PREVENT-PI-004 (local flag/config read only, no network),
|
|
13
|
+
* PREVENT-011 (no `any`), reader-only aggregate (never payloads/prompts).
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
import type { IncomingMessage, ServerResponse } from "node:http";
|
|
17
|
+
import type { RouteContext } from "./routes-core.js";
|
|
18
|
+
import { VC3C_ENABLED } from "../../src/config.js";
|
|
19
|
+
import { ROUTER_KEY_VERSION } from "../../src/vector-cortex/topology/query.js";
|
|
20
|
+
import { sendJson } from "./routes-vector-cortex-shared.js";
|
|
21
|
+
import type { VectorCortexQueryView } from "./api-contracts/vector-cortex.js";
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Reader-only GET /api/vector-cortex/query (VC3C query-layer diagnostics).
|
|
25
|
+
*/
|
|
26
|
+
export function handleVectorCortexQuery(
|
|
27
|
+
req: IncomingMessage,
|
|
28
|
+
res: ServerResponse,
|
|
29
|
+
_ctx: RouteContext,
|
|
30
|
+
): boolean {
|
|
31
|
+
const url = req.url ?? "";
|
|
32
|
+
const path = url.split("?")[0] ?? url;
|
|
33
|
+
if (path !== "/api/vector-cortex/query") return false;
|
|
34
|
+
if (req.method !== "GET") {
|
|
35
|
+
// Reader-only path: no mutation endpoint lives at /query.
|
|
36
|
+
sendJson(res, 405, { error: "method_not_allowed" });
|
|
37
|
+
return true;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
let enabled = false;
|
|
41
|
+
try {
|
|
42
|
+
enabled = VC3C_ENABLED();
|
|
43
|
+
} catch {
|
|
44
|
+
// Non-fatal: a missing/unavailable flag degrades to `enabled:false`.
|
|
45
|
+
enabled = false;
|
|
46
|
+
}
|
|
47
|
+
const body: VectorCortexQueryView = {
|
|
48
|
+
enabled,
|
|
49
|
+
routerVersion: ROUTER_KEY_VERSION,
|
|
50
|
+
updatedAt: new Date().toISOString(),
|
|
51
|
+
};
|
|
52
|
+
sendJson(res, 200, body);
|
|
53
|
+
return true;
|
|
54
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* dashboard-server/routes-vector-cortex-topology.ts — VC3A vector-cortex
|
|
3
|
-
* dashboard route.
|
|
2
|
+
* dashboard-server/routes-vector-cortex-topology.ts — VC3A/VC3B vector-cortex
|
|
3
|
+
* topology dashboard route.
|
|
4
4
|
*
|
|
5
5
|
* Reader-only GET /api/vector-cortex/topology built ENTIRELY on the CortexReader
|
|
6
6
|
* capability: opens the isolated cortex DB for this repo's state dir and returns
|
|
@@ -10,19 +10,34 @@
|
|
|
10
10
|
* (no writer/admin leakage). Non-fatal: a missing or corrupt cortex DB degrades
|
|
11
11
|
* to `enabled:false`.
|
|
12
12
|
*
|
|
13
|
+
* VC3B adds the deterministic node/edge shapes (TopologyV1) when both VC3A and
|
|
14
|
+
* VC3B are enabled: the accepted derived records of kind "topology" that carry a
|
|
15
|
+
* canonical TopologyCandidate JSON payload are fed through the deterministic
|
|
16
|
+
* build (buildTopologyGraph), whose stable generation digest + sorted node/edge
|
|
17
|
+
* arrays are returned. Bad/unparseable records are skipped (PREVENT-001), and
|
|
18
|
+
* with VC3B off the node/edge fields are omitted entirely — byte-identical to
|
|
19
|
+
* the VC3A predecessor view.
|
|
20
|
+
*
|
|
13
21
|
* Guardrails: PREVENT-PI-004 (local filesystem read only), PREVENT-011 (no
|
|
14
22
|
* `any`), reader-only aggregate.
|
|
15
23
|
*/
|
|
16
24
|
|
|
17
25
|
import type { IncomingMessage, ServerResponse } from "node:http";
|
|
18
26
|
import type { RouteContext } from "./routes-core.js";
|
|
19
|
-
import { VC3A_ENABLED } from "../../src/config.js";
|
|
27
|
+
import { VC3A_ENABLED, VC3B_ENABLED } from "../../src/config.js";
|
|
28
|
+
import { Logger } from "../../src/log.js";
|
|
20
29
|
import { createCortexStore } from "../../src/vector-cortex/cortex/store.js";
|
|
30
|
+
import { buildTopologyGraph } from "../../src/vector-cortex/topology/index.js";
|
|
31
|
+
import type { TopologyCandidate, TopologyEmit } from "../../src/vector-cortex/topology/index.js";
|
|
32
|
+
import type { CortexRecordV1 } from "../../src/vector-cortex/cortex/types.js";
|
|
21
33
|
import { sendJson } from "./routes-vector-cortex-shared.js";
|
|
22
34
|
import type { VectorCortexTopologyView } from "./api-contracts/vector-cortex.js";
|
|
23
35
|
|
|
36
|
+
/** Well-known cortex record kind that carries a canonical candidate payload. */
|
|
37
|
+
const TOPOLOGY_RECORD_KIND = "topology";
|
|
38
|
+
|
|
24
39
|
/**
|
|
25
|
-
* Reader-only GET /api/vector-cortex/topology (VC3A).
|
|
40
|
+
* Reader-only GET /api/vector-cortex/topology (VC3A + VC3B node/edge shapes).
|
|
26
41
|
*/
|
|
27
42
|
export function handleVectorCortexTopology(
|
|
28
43
|
req: IncomingMessage,
|
|
@@ -39,6 +54,7 @@ export function handleVectorCortexTopology(
|
|
|
39
54
|
}
|
|
40
55
|
|
|
41
56
|
const enabled = VC3A_ENABLED();
|
|
57
|
+
const topologyEnabled = VC3B_ENABLED();
|
|
42
58
|
let active = enabled;
|
|
43
59
|
let summary: {
|
|
44
60
|
generationId: string | null;
|
|
@@ -47,12 +63,22 @@ export function handleVectorCortexTopology(
|
|
|
47
63
|
recordCount: number;
|
|
48
64
|
ordinal: string | null;
|
|
49
65
|
} = { generationId: null, rootDigest: null, sourceHighWater: "0", recordCount: 0, ordinal: null };
|
|
66
|
+
let nodes: { id: string; kind: string }[] | undefined;
|
|
67
|
+
let edges: {
|
|
68
|
+
source: string;
|
|
69
|
+
target: string;
|
|
70
|
+
head: string;
|
|
71
|
+
score: number;
|
|
72
|
+
direction: string;
|
|
73
|
+
}[] | undefined;
|
|
74
|
+
let generationDigest: string | null | undefined;
|
|
50
75
|
|
|
51
76
|
if (enabled) {
|
|
52
77
|
try {
|
|
53
78
|
const store = createCortexStore({ stateDir: ctx.stateDir });
|
|
54
79
|
try {
|
|
55
|
-
const
|
|
80
|
+
const reader = store.reader();
|
|
81
|
+
const s = reader.topologySummary();
|
|
56
82
|
summary = {
|
|
57
83
|
generationId: s.generationId,
|
|
58
84
|
rootDigest: s.rootDigest,
|
|
@@ -60,6 +86,12 @@ export function handleVectorCortexTopology(
|
|
|
60
86
|
recordCount: s.recordCount,
|
|
61
87
|
ordinal: s.ordinal,
|
|
62
88
|
};
|
|
89
|
+
if (topologyEnabled) {
|
|
90
|
+
const built = buildFromRecords(reader.readRecords());
|
|
91
|
+
nodes = built.nodes;
|
|
92
|
+
edges = built.edges;
|
|
93
|
+
generationDigest = built.generationDigest;
|
|
94
|
+
}
|
|
63
95
|
} finally {
|
|
64
96
|
store.close();
|
|
65
97
|
}
|
|
@@ -76,8 +108,137 @@ export function handleVectorCortexTopology(
|
|
|
76
108
|
sourceHighWater: summary.sourceHighWater,
|
|
77
109
|
recordCount: summary.recordCount,
|
|
78
110
|
ordinal: summary.ordinal,
|
|
111
|
+
...(topologyEnabled
|
|
112
|
+
? { nodes, edges, generationDigest }
|
|
113
|
+
: {}),
|
|
79
114
|
updatedAt: new Date().toISOString(),
|
|
80
115
|
};
|
|
81
116
|
sendJson(res, 200, body);
|
|
82
117
|
return true;
|
|
83
118
|
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Reconstruct the deterministic topology graph from the accepted derived records
|
|
122
|
+
* (reader-only, best-effort). Only records of kind "topology" whose payload is a
|
|
123
|
+
* canonical TopologyCandidate JSON are consumed; everything else is ignored.
|
|
124
|
+
* Returns empty arrays + null digest when no valid candidates are stored.
|
|
125
|
+
*
|
|
126
|
+
* The build seam is invoked with a logger-derived emit so the VC3B observability
|
|
127
|
+
* events (`vector_cortex_topology_built` / `vector_cortex_topology_edge_rejected`)
|
|
128
|
+
* fire on this production path — not just under unit tests. Best-effort and
|
|
129
|
+
* non-fatal: a failing emitter never breaks the agent loop.
|
|
130
|
+
*
|
|
131
|
+
* Q04 — DIVERGENCE RISK (documented, currently latent): the build is invoked
|
|
132
|
+
* with a hardcoded `threshold: 0` (plus `sessionId: "dashboard"` and
|
|
133
|
+
* `sourceHighWater: 0n`). This reflects the VC3B state where no production
|
|
134
|
+
* writer emits calibrated-threshold candidates yet, so retaining ALL stored
|
|
135
|
+
* "topology" records is correct for now. Once a real calibrated-threshold
|
|
136
|
+
* producer lands (VC3C), this dashboard digest will NOT derive from the
|
|
137
|
+
* authoritative threshold and can diverge from the canonical build for the same
|
|
138
|
+
* stored candidate set. The calibrated threshold must then be threaded through
|
|
139
|
+
* (e.g. sourced from the authority/config, not zero) before this route is treated
|
|
140
|
+
* as authoritative. Until then the route is explicitly best-effort display only.
|
|
141
|
+
*/
|
|
142
|
+
function buildFromRecords(records: readonly CortexRecordV1[]): {
|
|
143
|
+
nodes: { id: string; kind: string }[];
|
|
144
|
+
edges: { source: string; target: string; head: string; score: number; direction: string }[];
|
|
145
|
+
generationDigest: string | null;
|
|
146
|
+
} {
|
|
147
|
+
const candidates: TopologyCandidate[] = [];
|
|
148
|
+
for (const r of records) {
|
|
149
|
+
if (r.kind !== TOPOLOGY_RECORD_KIND) continue;
|
|
150
|
+
const parsed = parseCandidatePayload(r);
|
|
151
|
+
if (parsed) candidates.push(parsed);
|
|
152
|
+
}
|
|
153
|
+
const result = buildTopologyGraph(
|
|
154
|
+
{ sessionId: "dashboard", sourceHighWater: 0n, threshold: 0, candidates },
|
|
155
|
+
topologyEmit,
|
|
156
|
+
);
|
|
157
|
+
if (!result.ok) return { nodes: [], edges: [], generationDigest: null };
|
|
158
|
+
return {
|
|
159
|
+
nodes: result.topology.nodes.map((n) => ({ id: n.id, kind: n.kind })),
|
|
160
|
+
edges: result.topology.edges.map((e) => ({
|
|
161
|
+
source: e.source,
|
|
162
|
+
target: e.target,
|
|
163
|
+
head: e.head,
|
|
164
|
+
score: e.score,
|
|
165
|
+
direction: e.direction,
|
|
166
|
+
})),
|
|
167
|
+
generationDigest: result.topology.generationDigest,
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* Logger-derived default emitter for the VC3B topology events. Mirrors the
|
|
173
|
+
* cortex store's `defaultEmitFor()` convention: a REAL structured-log producer so
|
|
174
|
+
* a caller that invokes the build seam without injecting an emitter still yields
|
|
175
|
+
* telemetry (best-effort, non-fatal). This is the production invoke point that
|
|
176
|
+
* makes the task-5 emission capable live (not dead under unit tests only).
|
|
177
|
+
*/
|
|
178
|
+
const topologyEmit: TopologyEmit = (event, fields) => {
|
|
179
|
+
new Logger().info(event, fields);
|
|
180
|
+
};
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* PREVENT-001: parse + shape-check a candidate payload before use. Returns
|
|
184
|
+
* undefined on any malformed/non-object input (best-effort, non-fatal).
|
|
185
|
+
*
|
|
186
|
+
* Q04 — FRAMING HARDENING: the canonical digest serialization in index.ts uses
|
|
187
|
+
* `|` (FIELD_SEP) and `~` (RECORD_SEP) as unambiguous delimiters between node
|
|
188
|
+
* ids/kinds and edge fields. That framing is collision-free only while id values
|
|
189
|
+
* (source/target/head) contain neither byte. Today ids are project-controlled, so
|
|
190
|
+
* this is latent, but a stored topology record could in principle carry a
|
|
191
|
+
* content-derived id containing those bytes, making the digest ambiguous
|
|
192
|
+
* (distinct graphs could collide) or the serialization injection-prone. To keep
|
|
193
|
+
* the digest well-defined for ANY input, reject candidates whose source/target/
|
|
194
|
+
* head contain the field/record separators; such a record is skipped (non-fatal)
|
|
195
|
+
* rather than fed into the digest.
|
|
196
|
+
*/
|
|
197
|
+
function parseCandidatePayload(r: CortexRecordV1): TopologyCandidate | undefined {
|
|
198
|
+
let text: string;
|
|
199
|
+
try {
|
|
200
|
+
text = new TextDecoder().decode(r.payloadBytes);
|
|
201
|
+
} catch {
|
|
202
|
+
return undefined;
|
|
203
|
+
}
|
|
204
|
+
try {
|
|
205
|
+
const v: unknown = JSON.parse(text);
|
|
206
|
+
if (
|
|
207
|
+
v === null ||
|
|
208
|
+
typeof v !== "object" ||
|
|
209
|
+
Array.isArray(v)
|
|
210
|
+
) {
|
|
211
|
+
return undefined;
|
|
212
|
+
}
|
|
213
|
+
const o = v as Record<string, unknown>;
|
|
214
|
+
if (
|
|
215
|
+
typeof o.source !== "string" ||
|
|
216
|
+
typeof o.target !== "string" ||
|
|
217
|
+
typeof o.head !== "string" ||
|
|
218
|
+
typeof o.score !== "number" ||
|
|
219
|
+
(o.kind !== "dependency" && o.kind !== "contradiction")
|
|
220
|
+
) {
|
|
221
|
+
return undefined;
|
|
222
|
+
}
|
|
223
|
+
// Q04: reject any id that would corrupt the `|`/`~` digest framing.
|
|
224
|
+
if (
|
|
225
|
+
FRAMING_SEP.test(o.source) ||
|
|
226
|
+
FRAMING_SEP.test(o.target) ||
|
|
227
|
+
FRAMING_SEP.test(o.head)
|
|
228
|
+
) {
|
|
229
|
+
return undefined;
|
|
230
|
+
}
|
|
231
|
+
return {
|
|
232
|
+
source: o.source,
|
|
233
|
+
target: o.target,
|
|
234
|
+
head: o.head,
|
|
235
|
+
score: o.score,
|
|
236
|
+
kind: o.kind,
|
|
237
|
+
};
|
|
238
|
+
} catch {
|
|
239
|
+
return undefined;
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
/** Field (`|`) and record (`~`) separators used by the canonical digest framing. */
|
|
244
|
+
const FRAMING_SEP = /[|~]/;
|
|
@@ -18,3 +18,4 @@ export { handleVectorCortexEvaluation } from "./routes-vector-cortex-eval.js";
|
|
|
18
18
|
export { handleVectorCortexHealth, handleVectorCortexBreakersReset } from "./routes-vector-cortex-health.js";
|
|
19
19
|
export { handleVectorCortexLedger } from "./routes-vector-cortex-ledger.js";
|
|
20
20
|
export { handleVectorCortexTopology } from "./routes-vector-cortex-topology.js";
|
|
21
|
+
export { handleVectorCortexQuery } from "./routes-vector-cortex-query.js";
|
|
@@ -61,6 +61,7 @@ import {
|
|
|
61
61
|
handleVectorCortexBreakersReset,
|
|
62
62
|
handleVectorCortexLedger,
|
|
63
63
|
handleVectorCortexTopology,
|
|
64
|
+
handleVectorCortexQuery,
|
|
64
65
|
handleStatic,
|
|
65
66
|
} from "./routes.js";
|
|
66
67
|
|
|
@@ -285,6 +286,7 @@ export async function launchDashboardServer(
|
|
|
285
286
|
if (handleVectorCortexBreakersReset(req, res, ctx)) return;
|
|
286
287
|
if (handleVectorCortexLedger(req, res, ctx)) return;
|
|
287
288
|
if (handleVectorCortexTopology(req, res, ctx)) return;
|
|
289
|
+
if (handleVectorCortexQuery(req, res, ctx)) return;
|
|
288
290
|
handleStatic(req, res, ctx);
|
|
289
291
|
});
|
|
290
292
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-mega-compact",
|
|
3
|
-
"version": "0.19.
|
|
3
|
+
"version": "0.19.3",
|
|
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",
|
|
@@ -111,6 +111,29 @@ export const VC2C_ENABLED = (): boolean => sprintFlag("MEGACOMPACT_VC2C");
|
|
|
111
111
|
*/
|
|
112
112
|
export const VC3A_ENABLED = (): boolean => sprintFlag("MEGACOMPACT_VC3A");
|
|
113
113
|
|
|
114
|
+
/**
|
|
115
|
+
* VC3B — deterministic cortical topology (TopologyV1 / EdgeV1).
|
|
116
|
+
* Default ON. `MEGACOMPACT_VC3B=0` disables and is byte-identical to the
|
|
117
|
+
* predecessor (mode C: no topology graph is built or emitted, the dashboard
|
|
118
|
+
* topology view returns the VC3A-precise aggregation shape with no node/edge
|
|
119
|
+
* arrays, zero `vector_cortex_topology_*` emissions). The real consumers are
|
|
120
|
+
* the topology build seam (build.ts) and the dashboard topology node/edge view.
|
|
121
|
+
*/
|
|
122
|
+
export const VC3B_ENABLED = (): boolean => sprintFlag("MEGACOMPACT_VC3B");
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* VC3C — topology query + router invalidation (TopologyQueryV1 / RouterKeyV2,
|
|
126
|
+
* M6 router-generation-v2 migration).
|
|
127
|
+
* Default ON. `MEGACOMPACT_VC3C=0` disables and is byte-identical to the
|
|
128
|
+
* predecessor (mode C: no length-delimited router key, no generation
|
|
129
|
+
* invalidation, zero `vector_cortex_router_generation_invalidated` /
|
|
130
|
+
* `vector_cortex_topology_query_demoted` emissions; the predecessor tiered
|
|
131
|
+
* router keying is unchanged). The real consumers are the topology query seam
|
|
132
|
+
* (query.ts), the M6 router-generation-v2 migration seam, and the reader-only
|
|
133
|
+
* dashboard topology query diagnostic view.
|
|
134
|
+
*/
|
|
135
|
+
export const VC3C_ENABLED = (): boolean => sprintFlag("MEGACOMPACT_VC3C");
|
|
136
|
+
|
|
114
137
|
// ---------------------------------------------------------------------------
|
|
115
138
|
// Breaker state machine constants (TRIAD_RESILIENCE.md §breaker).
|
|
116
139
|
// Rolled numbers for one 60s window; VC0C consumes these at its breaker seam.
|
package/src/config.ts
CHANGED
package/src/tieredRouter.ts
CHANGED
|
@@ -16,6 +16,9 @@
|
|
|
16
16
|
import { createHash } from "node:crypto";
|
|
17
17
|
import { appendFileSync, existsSync, mkdirSync, readFileSync } from "node:fs";
|
|
18
18
|
import { dirname, join } from "node:path";
|
|
19
|
+
import { VC3C_ENABLED } from "./config.js";
|
|
20
|
+
import { Logger } from "./log.js";
|
|
21
|
+
import { routerGenerationInvalidationSeam, type RouterKeyV2 } from "./vector-cortex/topology/query.js";
|
|
19
22
|
import { openStore } from "./store/sqlite/utils.js";
|
|
20
23
|
import { fts5SearchScoped } from "./store/sqlite/fts5-search.js";
|
|
21
24
|
import { listCheckpoints } from "./store/sqlite.js";
|
|
@@ -343,6 +346,12 @@ export class TieredRouter {
|
|
|
343
346
|
this.embeddingCache.clear();
|
|
344
347
|
}
|
|
345
348
|
|
|
349
|
+
/** VC3C narrow delegate: exact (session,generation) RouterKeyV2 invalidation.
|
|
350
|
+
* No routing rewrite; `MEGACOMPACT_VC3C=0` is a strict no-op, byte-identical. */
|
|
351
|
+
invalidateGeneration(key: RouterKeyV2): void {
|
|
352
|
+
routerGenerationInvalidationSeam(key, VC3C_ENABLED(), (e, f) => new Logger().info(e, f));
|
|
353
|
+
}
|
|
354
|
+
|
|
346
355
|
/** Snapshot of current metrics for dashboard / logging. */
|
|
347
356
|
getMetrics(): TieredRouterMetrics {
|
|
348
357
|
const q = Math.max(this.totalQueries, 1);
|