pi-mega-compact 0.20.5 → 0.20.7
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 +12 -0
- package/dist/config.js +1 -1
- package/dist/extensions/dashboard-server/routes-rag-settings-helpers.js +3 -31
- package/dist/extensions/dashboard-server/routes-rag-settings-types.js +11 -0
- package/dist/extensions/dashboard-server/routes-rag-settings-vector-cortex.js +43 -0
- package/dist/extensions/dashboard-server/routes-vector-cortex-rollout.js +43 -0
- 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/extensions/mega-runtime/vector-cortex-live.js +105 -0
- package/dist/src/config/dedup.js +1 -0
- package/dist/src/config/vector-cortex.js +12 -0
- package/dist/src/config.js +1 -1
- package/dist/src/dedup-audit.test-helpers.js +43 -0
- package/dist/src/monitoring.js +9 -0
- package/dist/src/vector-cortex/rollout/_acceptance-fixture.js +55 -0
- package/dist/src/vector-cortex/rollout/_acceptance-helpers.js +8 -0
- package/dist/src/vector-cortex/rollout/_acceptance-scenario.js +70 -0
- package/dist/src/vector-cortex/rollout/assign.js +56 -0
- package/dist/src/vector-cortex/rollout/emit.js +50 -0
- package/dist/src/vector-cortex/rollout/gate.js +75 -0
- package/dist/src/vector-cortex/rollout/types.js +39 -0
- package/dist/src/vectorStore/add-l0.js +108 -0
- package/dist/src/vectorStore/add-l1.js +35 -0
- package/dist/src/vectorStore/add.js +229 -0
- package/dist/src/vectorStore/class.js +15 -291
- package/dist/src/vectorStore/dedup-audit.js +104 -0
- package/dist/src/vectorStore.js +1 -0
- package/dist/vector-cortex/rollout/_acceptance-fixture.js +55 -0
- package/dist/vector-cortex/rollout/_acceptance-helpers.js +8 -0
- package/dist/vector-cortex/rollout/_acceptance-scenario.js +70 -0
- package/dist/vector-cortex/rollout/assign.js +56 -0
- package/dist/vector-cortex/rollout/emit.js +50 -0
- package/dist/vector-cortex/rollout/gate.js +75 -0
- package/dist/vector-cortex/rollout/types.js +39 -0
- package/extensions/dashboard-client/dist/assets/{AreaChart-CGL29Tcl.js → AreaChart-DqTbaSRA.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{AreaChart-CGL29Tcl.js.map → AreaChart-DqTbaSRA.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{BarChart-OxhalIZa.js → BarChart-BfNBeOvF.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{BarChart-OxhalIZa.js.map → BarChart-BfNBeOvF.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{CacheTab-VcMFwL-6.js → CacheTab-C9SOMYB5.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{CacheTab-VcMFwL-6.js.map → CacheTab-C9SOMYB5.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{EventsTab-DePofXDM.js → EventsTab-GsMKP10_.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{EventsTab-DePofXDM.js.map → EventsTab-GsMKP10_.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{HealthTab-nQd1tjSF.js → HealthTab-DAOCXwRP.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{HealthTab-nQd1tjSF.js.map → HealthTab-DAOCXwRP.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{MaintenanceTab-CzvA8-F6.js → MaintenanceTab-BtBeMkB5.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{MaintenanceTab-CzvA8-F6.js.map → MaintenanceTab-BtBeMkB5.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{MemoryMapTab-3lxgWBvU.js → MemoryMapTab-DzndtgkZ.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{MemoryMapTab-3lxgWBvU.js.map → MemoryMapTab-DzndtgkZ.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{MetricsTab-D_FcA6kN.js → MetricsTab-DyxJ4eb8.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{MetricsTab-D_FcA6kN.js.map → MetricsTab-DyxJ4eb8.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{OverviewTab-BU6R4aEs.js → OverviewTab-DCiEdVWR.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{OverviewTab-BU6R4aEs.js.map → OverviewTab-DCiEdVWR.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{ReposTab-DFjy1isz.js → ReposTab-B5SIqVHA.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{ReposTab-DFjy1isz.js.map → ReposTab-B5SIqVHA.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{SessionsTab-UGIzIH25.js → SessionsTab-DLWFJ9xI.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{SessionsTab-UGIzIH25.js.map → SessionsTab-DLWFJ9xI.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{SetupTab-CECrgMKI.js → SetupTab-CvGXZyej.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{SetupTab-CECrgMKI.js.map → SetupTab-CvGXZyej.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{TimeSavedCard-Dyy4SCDk.js → TimeSavedCard-wZuQGxLS.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{TimeSavedCard-Dyy4SCDk.js.map → TimeSavedCard-wZuQGxLS.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{TurnsTab-B0LPcVs1.js → TurnsTab-B7aOejch.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{TurnsTab-B0LPcVs1.js.map → TurnsTab-B7aOejch.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/VectorCortexTab-eHVt9yDx.js +2 -0
- package/extensions/dashboard-client/dist/assets/VectorCortexTab-eHVt9yDx.js.map +1 -0
- package/extensions/dashboard-client/dist/assets/{WikiTab-DWk9Qvut.js → WikiTab-DhWHjAtt.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{WikiTab-DWk9Qvut.js.map → WikiTab-DhWHjAtt.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{button-O59wPr5H.js → button-BrC-W87h.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{button-O59wPr5H.js.map → button-BrC-W87h.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{card-C-DxXv1-.js → card-0rgfRgr3.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{card-C-DxXv1-.js.map → card-0rgfRgr3.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{generateCategoricalChart-Dw5YnE5s.js → generateCategoricalChart-DRresOQF.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{generateCategoricalChart-Dw5YnE5s.js.map → generateCategoricalChart-DRresOQF.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{index-i9oaPE0a.js → index-DohmtZWL.js} +3 -3
- package/extensions/dashboard-client/dist/assets/{index-i9oaPE0a.js.map → index-DohmtZWL.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{switch-B69QY3IM.js → switch-Bs8g_zB5.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{switch-B69QY3IM.js.map → switch-Bs8g_zB5.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{toggle-BJ4Kwggu.js → toggle-DVVauIo8.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{toggle-BJ4Kwggu.js.map → toggle-DVVauIo8.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{useSSE-BpuA8sPd.js → useSSE-DxH1PTAR.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{useSSE-BpuA8sPd.js.map → useSSE-DxH1PTAR.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/VectorCortexRolloutCard.tsx +44 -0
- package/extensions/dashboard-client/src/tabs/VectorCortexTab.tsx +8 -0
- package/extensions/dashboard-client/src/types/vector-cortex.ts +17 -0
- package/extensions/dashboard-server/api-contracts/vector-cortex.ts +32 -1
- package/extensions/dashboard-server/routes-rag-settings-helpers.ts +11 -129
- package/extensions/dashboard-server/routes-rag-settings-types.ts +34 -0
- package/extensions/dashboard-server/routes-rag-settings-vector-cortex.ts +142 -0
- package/extensions/dashboard-server/routes-vector-cortex-rollout.ts +52 -0
- 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/extensions/mega-runtime/vector-cortex-live.ts +165 -0
- package/package.json +1 -1
- package/src/config/dedup.ts +9 -0
- package/src/config/vector-cortex.ts +13 -0
- package/src/config.ts +1 -0
- package/src/dedup-audit.test-helpers.ts +49 -0
- package/src/monitoring.ts +10 -0
- package/src/vector-cortex/rollout/_acceptance-fixture.ts +94 -0
- package/src/vector-cortex/rollout/_acceptance-helpers.ts +24 -0
- package/src/vector-cortex/rollout/_acceptance-scenario.ts +96 -0
- package/src/vector-cortex/rollout/assign.ts +67 -0
- package/src/vector-cortex/rollout/emit.ts +81 -0
- package/src/vector-cortex/rollout/gate.ts +119 -0
- package/src/vector-cortex/rollout/types.ts +111 -0
- package/src/vectorStore/add-l0.ts +152 -0
- package/src/vectorStore/add-l1.ts +57 -0
- package/src/vectorStore/add.ts +269 -0
- package/src/vectorStore/class.ts +17 -327
- package/src/vectorStore/dedup-audit.ts +199 -0
- package/src/vectorStore.ts +1 -0
- package/extensions/dashboard-client/dist/assets/VectorCortexTab-BWi3u_gp.js +0 -2
- package/extensions/dashboard-client/dist/assets/VectorCortexTab-BWi3u_gp.js.map +0 -1
package/src/vectorStore/class.ts
CHANGED
|
@@ -7,9 +7,8 @@
|
|
|
7
7
|
* Backed by the gzipped on-disk checkpoint files (store.ts). Similarity is a
|
|
8
8
|
* linear cosine scan — checkpoint counts are small, so no ANN index is needed.
|
|
9
9
|
*/
|
|
10
|
-
import { createHash } from "node:crypto";
|
|
11
10
|
import type { Embedder } from "../embedder.js";
|
|
12
|
-
import {
|
|
11
|
+
import { defaultEmbedder } from "../embedder.js";
|
|
13
12
|
import {
|
|
14
13
|
loadDedupConfig,
|
|
15
14
|
type DedupConfigShape,
|
|
@@ -17,47 +16,28 @@ import {
|
|
|
17
16
|
} from "../config/dedup.js";
|
|
18
17
|
import { logDecision } from "../monitoring.js";
|
|
19
18
|
import { repoKey } from "../store/repoKey.js";
|
|
20
|
-
import
|
|
21
|
-
import { getStateDir, normalizeSessionId, compressSmart } from "../store.js";
|
|
22
|
-
import { computeContentDigest } from "../dedup/digest.js";
|
|
19
|
+
import { getStateDir } from "../store.js";
|
|
23
20
|
import type { RaptorTree } from "../dedup/raptor/tree.js";
|
|
24
|
-
import {
|
|
25
|
-
minhashSignature,
|
|
26
|
-
SIGNATURE_VERSION,
|
|
27
|
-
NUM_HASHES,
|
|
28
|
-
} from "../dedup/l1-minhash.js";
|
|
29
|
-
import { lshBands } from "../dedup/l1-lsh.js";
|
|
30
|
-
import { isNearDuplicate } from "../dedup/l1-verify.js";
|
|
31
|
-
import { openBloom, saveBloom } from "../store/bloom.js";
|
|
32
|
-
import {
|
|
33
|
-
listCheckpoints,
|
|
34
|
-
nextCheckpointId,
|
|
35
|
-
upsertCheckpoint,
|
|
36
|
-
loadSessionState,
|
|
37
|
-
saveSessionState,
|
|
38
|
-
upsertMinhashSignature,
|
|
39
|
-
insertLshBuckets,
|
|
40
|
-
lshCandidateChunks,
|
|
41
|
-
addTokensSaved,
|
|
42
|
-
bumpDedupStats,
|
|
43
|
-
} from "../store/sqlite.js";
|
|
21
|
+
import { openBloom } from "../store/bloom.js";
|
|
44
22
|
import { migrateJsonToSqlite } from "../store/migrate.js";
|
|
45
|
-
import {
|
|
23
|
+
import { addCheckpoint } from "./add.js";
|
|
46
24
|
import type { AddInput, AddResult } from "./types.js";
|
|
47
25
|
|
|
48
26
|
export class VectorStore {
|
|
49
27
|
// These fields are `readonly` (set once in the constructor) but NOT private:
|
|
50
|
-
// the read/search/dedup helpers split into
|
|
51
|
-
// and vector-dedup.ts access them directly. Marking them
|
|
52
|
-
// ugly `as unknown as` casts in those modules; keeping
|
|
53
|
-
// makes VectorStore a thin barrel whose helpers live in
|
|
28
|
+
// the add/read/search/dedup helpers split into add.ts, vector-read.ts,
|
|
29
|
+
// vector-search.ts, and vector-dedup.ts access them directly. Marking them
|
|
30
|
+
// private would force ugly `as unknown as` casts in those modules; keeping
|
|
31
|
+
// them package-public makes VectorStore a thin barrel whose helpers live in
|
|
32
|
+
// sibling files.
|
|
54
33
|
readonly embedder: Embedder;
|
|
55
34
|
readonly stateDir: string;
|
|
56
|
-
|
|
35
|
+
/** L2 semantic firing point (cfg.L2_COSINE, or a direct test override). */
|
|
36
|
+
readonly l2Threshold: number;
|
|
57
37
|
/** Single source of truth for tier flags + thresholds (Sprint 14). */
|
|
58
38
|
readonly cfg: DedupConfigShape;
|
|
59
39
|
/** Optional monitoring target (Sprint 14). Undefined → no monitoring. */
|
|
60
|
-
|
|
40
|
+
readonly eventsPath?: string;
|
|
61
41
|
/**
|
|
62
42
|
* Repo key for the async PGlite vector index (Slice 2). We use the stateDir
|
|
63
43
|
* itself as the repo id — it is already unique per repo and available here
|
|
@@ -132,302 +112,12 @@ export class VectorStore {
|
|
|
132
112
|
}
|
|
133
113
|
|
|
134
114
|
/**
|
|
135
|
-
* Add a checkpoint
|
|
136
|
-
*
|
|
137
|
-
*
|
|
138
|
-
*
|
|
139
|
-
* 4. If none match → create new checkpoint
|
|
115
|
+
* Add a checkpoint, deduping it against the session's existing checkpoints.
|
|
116
|
+
*
|
|
117
|
+
* The cascade itself lives in ./add.ts (sibling-helper pattern) so this class
|
|
118
|
+
* stays a thin shell over the fields its helpers read.
|
|
140
119
|
*/
|
|
141
120
|
add(input: AddInput): AddResult {
|
|
142
|
-
|
|
143
|
-
const sessionId = normalizeSessionId(input.sessionId);
|
|
144
|
-
const regionHash = computeRegionHash(input.regionText);
|
|
145
|
-
const all = listCheckpoints(sessionId, this.stateDir);
|
|
146
|
-
// Honest "tokens saved" base for this region. For a deduped add the whole
|
|
147
|
-
// original region is discarded (nothing new stored); for a new checkpoint
|
|
148
|
-
// we persist (orig − stored). Falls back to stored when orig is unknown.
|
|
149
|
-
const origTokens = input.originalTokenEstimate ?? input.tokenEstimate ?? 0;
|
|
150
|
-
const cfg = this.cfg;
|
|
151
|
-
// Live per-tier progress hook (Phase 1). Sync + optional; fired at each tier
|
|
152
|
-
// so the UI can paint "L0 ✓ → L1 ✓ → L2 0.91 → stored" during a compaction.
|
|
153
|
-
const onTier = input.onTier;
|
|
154
|
-
// Tracks whether a tier matched while in MARK_ONLY (record-but-don't-collapse),
|
|
155
|
-
// and which tier.
|
|
156
|
-
let markOnly: DedupTier | null = null;
|
|
157
|
-
|
|
158
|
-
// 0. L0 content-hash dedup (Sprint 9) — catches identical content arriving
|
|
159
|
-
// under different regionText. Normalization handles case/whitespace/ANSI so
|
|
160
|
-
// variants collapse to one row. Dual-hash guards a single-hash collision.
|
|
161
|
-
// Sprint 10: bloom is the accelerator — a miss means "definitely new" and
|
|
162
|
-
// skips the scan; a hit is only a candidate, confirmed against `all` below.
|
|
163
|
-
// Gated by L0_ENABLED (Sprint 14). MARK_ONLY_L0 records the decision but
|
|
164
|
-
// does not collapse — the new region is still stored.
|
|
165
|
-
onTier?.({ tier: "L0", status: "scanning" });
|
|
166
|
-
const digest = computeContentDigest(input.regionText);
|
|
167
|
-
const bloom = openBloom(this.stateDir);
|
|
168
|
-
if (cfg.L0_ENABLED && bloom.maybeHas(digest.contentHash)) {
|
|
169
|
-
const contentMatch = all.find(
|
|
170
|
-
(cp) =>
|
|
171
|
-
cp.contentHash === digest.contentHash &&
|
|
172
|
-
cp.contentHash2 === digest.contentHash2,
|
|
173
|
-
);
|
|
174
|
-
if (contentMatch) {
|
|
175
|
-
if (cfg.MARK_ONLY_L0) {
|
|
176
|
-
markOnly = "L0"; // Record-but-don't-collapse: fall through.
|
|
177
|
-
} else {
|
|
178
|
-
contentMatch.timestamp = input.timestamp;
|
|
179
|
-
upsertCheckpoint(contentMatch, this.stateDir);
|
|
180
|
-
bumpDedupStats(true, this.stateDir);
|
|
181
|
-
// Deduped: whole original region discarded, nothing new stored.
|
|
182
|
-
addTokensSaved(origTokens, this.stateDir);
|
|
183
|
-
const r = {
|
|
184
|
-
checkpoint: contentMatch,
|
|
185
|
-
deduped: true,
|
|
186
|
-
reason: "contentHash",
|
|
187
|
-
};
|
|
188
|
-
this.record("L0", "deduped", "contentHash", Date.now() - t0, 1, contentMatch.checkpointId);
|
|
189
|
-
onTier?.({ tier: "L0", status: "deduped", detail: "contentHash" });
|
|
190
|
-
return r;
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
// 1. Legacy regionHash dedup (backward-compat) — part of L0 tier gating.
|
|
196
|
-
if (cfg.L0_ENABLED) {
|
|
197
|
-
const regionMatch = all.find((cp) => cp.regionHash === regionHash);
|
|
198
|
-
if (regionMatch) {
|
|
199
|
-
if (cfg.MARK_ONLY_L0) {
|
|
200
|
-
markOnly = "L0"; // fall through
|
|
201
|
-
} else {
|
|
202
|
-
bumpDedupStats(true, this.stateDir);
|
|
203
|
-
// Deduped: whole original region discarded, nothing new stored.
|
|
204
|
-
addTokensSaved(origTokens, this.stateDir);
|
|
205
|
-
const r = {
|
|
206
|
-
checkpoint: regionMatch,
|
|
207
|
-
deduped: true,
|
|
208
|
-
reason: "regionHash",
|
|
209
|
-
};
|
|
210
|
-
this.record("L0", "deduped", "regionHash", Date.now() - t0, 1, regionMatch.checkpointId);
|
|
211
|
-
onTier?.({ tier: "L0", status: "deduped", detail: "regionHash" });
|
|
212
|
-
return r;
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
// 2. SummaryHash dedup — catches same-topic incremental compactions.
|
|
218
|
-
// Full 64-hex SHA-256 (was 16-hex in Sprint 8 — collision-prone).
|
|
219
|
-
const summaryHash = input.topicSummary
|
|
220
|
-
? createHash("sha256").update(input.topicSummary).digest("hex")
|
|
221
|
-
: undefined;
|
|
222
|
-
if (summaryHash && cfg.L0_ENABLED) {
|
|
223
|
-
const summaryMatch = all.find((cp) => cp.summaryHash === summaryHash);
|
|
224
|
-
if (summaryMatch) {
|
|
225
|
-
if (cfg.MARK_ONLY_L0) {
|
|
226
|
-
markOnly = "L0"; // fall through
|
|
227
|
-
} else {
|
|
228
|
-
summaryMatch.timestamp = input.timestamp;
|
|
229
|
-
upsertCheckpoint(summaryMatch, this.stateDir);
|
|
230
|
-
bumpDedupStats(true, this.stateDir);
|
|
231
|
-
// Deduped: whole original region discarded, nothing new stored.
|
|
232
|
-
addTokensSaved(origTokens, this.stateDir);
|
|
233
|
-
const r = {
|
|
234
|
-
checkpoint: summaryMatch,
|
|
235
|
-
deduped: true,
|
|
236
|
-
reason: "summaryHash",
|
|
237
|
-
};
|
|
238
|
-
this.record("L0", "deduped", "summaryHash", Date.now() - t0, 1, summaryMatch.checkpointId);
|
|
239
|
-
onTier?.({ tier: "L0", status: "deduped", detail: "summaryHash" });
|
|
240
|
-
return r;
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
// L0 did not collapse this region.
|
|
245
|
-
onTier?.({ tier: "L0", status: "passed" });
|
|
246
|
-
|
|
247
|
-
// 2b. L1 MinHash/LSH near-duplicate dedup (Sprint 11) — catches one-word
|
|
248
|
-
// edits / rewordings that L0's exact hash misses. Cheap LSH bucket
|
|
249
|
-
// retrieval → trigram verification (pg_trgm-equivalent) as the final gate.
|
|
250
|
-
// Gated by L1_ENABLED (Sprint 14); MARK_ONLY_L1 records but doesn't collapse.
|
|
251
|
-
onTier?.({ tier: "L1", status: "scanning" });
|
|
252
|
-
if (cfg.L1_ENABLED) {
|
|
253
|
-
const l1 = this.findL1Duplicate(sessionId, input.regionText, all);
|
|
254
|
-
if (l1 && !cfg.MARK_ONLY_L1) {
|
|
255
|
-
l1.timestamp = input.timestamp;
|
|
256
|
-
upsertCheckpoint(l1, this.stateDir);
|
|
257
|
-
bumpDedupStats(true, this.stateDir);
|
|
258
|
-
const r = { checkpoint: l1, deduped: true, reason: "l1MinHash" };
|
|
259
|
-
this.record("L1", "deduped", "l1MinHash", Date.now() - t0, 1, l1.checkpointId);
|
|
260
|
-
onTier?.({ tier: "L1", status: "deduped", detail: "l1MinHash" });
|
|
261
|
-
return r;
|
|
262
|
-
}
|
|
263
|
-
if (l1 && cfg.MARK_ONLY_L1) markOnly = "L1";
|
|
264
|
-
}
|
|
265
|
-
onTier?.({ tier: "L1", status: "passed" });
|
|
266
|
-
|
|
267
|
-
// 3. L2 semantic dedup — catches near-identical / semantically-similar regions
|
|
268
|
-
// via cosine over the embedding. topicSummary is used for summaryHash dedup
|
|
269
|
-
// (tier 2); the vector index is keyed on the original region for backward-
|
|
270
|
-
// compat search semantics. Threshold from cfg (L2_COSINE trigram honest
|
|
271
|
-
// firing point). QA #13 timeout guard: if the O(n) scan exceeds the budget,
|
|
272
|
-
// degrade to "store without dedup this pass" so we never lose a checkpoint.
|
|
273
|
-
// Gated by L2_ENABLED (Sprint 14); MARK_ONLY_L2 records but doesn't collapse.
|
|
274
|
-
const SIMILARITY_BUDGET_MS = cfg.SIMILARITY_BUDGET_MS;
|
|
275
|
-
const simThreshold = this.l2Threshold; // from cfg.L2_COSINE (default 0.85 trigram)
|
|
276
|
-
const embedding = this.embedder.embed(input.regionText);
|
|
277
|
-
onTier?.({ tier: "L2", status: "scanning" });
|
|
278
|
-
if (cfg.L2_ENABLED && all.length > 0) {
|
|
279
|
-
const start = Date.now();
|
|
280
|
-
let timedOut = false;
|
|
281
|
-
const nearest = all.reduce(
|
|
282
|
-
(best, cp) => {
|
|
283
|
-
if (!timedOut && Date.now() - start > SIMILARITY_BUDGET_MS)
|
|
284
|
-
timedOut = true;
|
|
285
|
-
if (timedOut) return best;
|
|
286
|
-
const sim = cosineSimilarity(embedding, cp.embedding);
|
|
287
|
-
return sim > best.sim ? { checkpoint: cp, sim } : best;
|
|
288
|
-
},
|
|
289
|
-
{ checkpoint: all[0], sim: -1 },
|
|
290
|
-
);
|
|
291
|
-
if (!timedOut && nearest.sim >= simThreshold) {
|
|
292
|
-
if (!cfg.MARK_ONLY_L2) {
|
|
293
|
-
// Near-identical — update timestamp on existing checkpoint
|
|
294
|
-
nearest.checkpoint.timestamp = input.timestamp;
|
|
295
|
-
upsertCheckpoint(nearest.checkpoint, this.stateDir);
|
|
296
|
-
bumpDedupStats(true, this.stateDir);
|
|
297
|
-
// Deduped: whole original region discarded, nothing new stored.
|
|
298
|
-
addTokensSaved(origTokens, this.stateDir);
|
|
299
|
-
const r = {
|
|
300
|
-
checkpoint: nearest.checkpoint,
|
|
301
|
-
deduped: true,
|
|
302
|
-
reason: "contentSimilarity",
|
|
303
|
-
};
|
|
304
|
-
this.record("L2", "deduped", "contentSimilarity", Date.now() - t0, nearest.sim, nearest.checkpoint.checkpointId);
|
|
305
|
-
onTier?.({
|
|
306
|
-
tier: "L2",
|
|
307
|
-
status: "deduped",
|
|
308
|
-
detail: nearest.sim.toFixed(2),
|
|
309
|
-
});
|
|
310
|
-
return r;
|
|
311
|
-
}
|
|
312
|
-
markOnly = "L2";
|
|
313
|
-
}
|
|
314
|
-
onTier?.({
|
|
315
|
-
tier: "L2",
|
|
316
|
-
status: "passed",
|
|
317
|
-
detail: `best ${nearest.sim.toFixed(2)}`,
|
|
318
|
-
});
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
// 4. Genuinely new — create checkpoint
|
|
322
|
-
const checkpointId = nextCheckpointId(sessionId, this.stateDir);
|
|
323
|
-
const checkpoint: StoredCheckpoint = {
|
|
324
|
-
checkpointId,
|
|
325
|
-
sessionId,
|
|
326
|
-
repoId: this.repoId,
|
|
327
|
-
summary: input.summary,
|
|
328
|
-
topicSummary: input.topicSummary,
|
|
329
|
-
summaryHash,
|
|
330
|
-
keyDecisions: input.keyDecisions ?? [],
|
|
331
|
-
nextSteps: input.nextSteps ?? [],
|
|
332
|
-
filesModified: input.filesModified ?? [],
|
|
333
|
-
tokenEstimate: input.tokenEstimate ?? 0,
|
|
334
|
-
originalTokenEstimate: input.originalTokenEstimate,
|
|
335
|
-
regionHash,
|
|
336
|
-
contentHash: digest.contentHash,
|
|
337
|
-
contentHash2: digest.contentHash2,
|
|
338
|
-
contentHashVersion: digest.contentHashVersion,
|
|
339
|
-
normalizedText: digest.normalizedText,
|
|
340
|
-
compressedOriginal: compressSmart(
|
|
341
|
-
Buffer.from(input.regionText, "utf-8"),
|
|
342
|
-
input.compressionPressure,
|
|
343
|
-
),
|
|
344
|
-
embedding,
|
|
345
|
-
timestamp: input.timestamp,
|
|
346
|
-
};
|
|
347
|
-
// Persistence is SQLite (store/sqlite.ts). upsertCheckpoint keeps the
|
|
348
|
-
// idempotent-by-id semantics the old JSON append implied.
|
|
349
|
-
upsertCheckpoint(checkpoint, this.stateDir);
|
|
350
|
-
// Cumulative "tokens saved" counter (per-repo SQLite meta). For a NEW
|
|
351
|
-
// checkpoint the saved amount is (original − stored); for a deduped add the
|
|
352
|
-
// whole original region is discarded (handled in the deduped return paths
|
|
353
|
-
// below). Survives sessions and travels with the repo.
|
|
354
|
-
const stored = input.tokenEstimate ?? 0;
|
|
355
|
-
addTokensSaved(Math.max(0, origTokens - stored), this.stateDir);
|
|
356
|
-
// L1: persist this checkpoint's MinHash signature + LSH buckets so future
|
|
357
|
-
// near-duplicate inserts can find it. Deterministic given the seed.
|
|
358
|
-
const sig = minhashSignature(input.regionText);
|
|
359
|
-
upsertMinhashSignature(
|
|
360
|
-
checkpointId,
|
|
361
|
-
sessionId,
|
|
362
|
-
SIGNATURE_VERSION,
|
|
363
|
-
sig,
|
|
364
|
-
this.stateDir,
|
|
365
|
-
);
|
|
366
|
-
insertLshBuckets(
|
|
367
|
-
checkpointId,
|
|
368
|
-
sessionId,
|
|
369
|
-
SIGNATURE_VERSION,
|
|
370
|
-
lshBands(sig, sessionId, SIGNATURE_VERSION),
|
|
371
|
-
this.stateDir,
|
|
372
|
-
);
|
|
373
|
-
// Bloom accelerator: record the new content_hash so a future add() can short-
|
|
374
|
-
// circuit the scan on a hit (still confirmed by the SELECT-based `all` above).
|
|
375
|
-
bloom.add(digest.contentHash);
|
|
376
|
-
saveBloom(this.stateDir);
|
|
377
|
-
|
|
378
|
-
// Track the region hash in session state for fast sentinel checks.
|
|
379
|
-
const state = loadSessionState(sessionId, this.stateDir);
|
|
380
|
-
if (!state.storedRegionHashes.includes(regionHash)) {
|
|
381
|
-
state.storedRegionHashes.push(regionHash);
|
|
382
|
-
saveSessionState(sessionId, state, this.stateDir);
|
|
383
|
-
}
|
|
384
|
-
// A new checkpoint. If a tier matched while MARK_ONLY, record that (the
|
|
385
|
-
// decision fired but we intentionally did not collapse).
|
|
386
|
-
if (markOnly) {
|
|
387
|
-
this.record(markOnly, "mark_only", "mark_only", Date.now() - t0);
|
|
388
|
-
} else {
|
|
389
|
-
this.record("L0", "new", undefined, Date.now() - t0);
|
|
390
|
-
}
|
|
391
|
-
// Cumulative store-wide dedup accounting (attempt, not collapsed).
|
|
392
|
-
bumpDedupStats(false, this.stateDir);
|
|
393
|
-
onTier?.({ tier: "new", status: "stored" });
|
|
394
|
-
return { checkpoint, deduped: false };
|
|
395
|
-
}
|
|
396
|
-
|
|
397
|
-
/**
|
|
398
|
-
* L1 near-duplicate lookup: MinHash → LSH candidate retrieval → trigram verify.
|
|
399
|
-
* Returns the matching checkpoint or undefined. Bounded by a 100-candidate cap
|
|
400
|
-
* and a 20ms verify budget (QA #7/#15) so it never hangs a large session.
|
|
401
|
-
*/
|
|
402
|
-
private findL1Duplicate(
|
|
403
|
-
sessionId: string,
|
|
404
|
-
regionText: string,
|
|
405
|
-
all: StoredCheckpoint[],
|
|
406
|
-
): StoredCheckpoint | undefined {
|
|
407
|
-
if (all.length === 0) return undefined;
|
|
408
|
-
const sig = minhashSignature(regionText);
|
|
409
|
-
if (sig.length !== NUM_HASHES) return undefined;
|
|
410
|
-
const bands = lshBands(sig, sessionId, SIGNATURE_VERSION);
|
|
411
|
-
// Cheap candidate retrieval (single query, capped). Exclude nothing yet —
|
|
412
|
-
// the new checkpoint has no id, so pass a sentinel that never matches.
|
|
413
|
-
const candidateIds = lshCandidateChunks(
|
|
414
|
-
bands,
|
|
415
|
-
sessionId,
|
|
416
|
-
"__new__",
|
|
417
|
-
this.stateDir,
|
|
418
|
-
100,
|
|
419
|
-
);
|
|
420
|
-
if (candidateIds.length === 0) return undefined;
|
|
421
|
-
const byId = new Map(all.map((cp) => [cp.checkpointId, cp]));
|
|
422
|
-
const VERIFY_BUDGET_MS = 20;
|
|
423
|
-
const start = Date.now();
|
|
424
|
-
for (const id of candidateIds) {
|
|
425
|
-
if (Date.now() - start > VERIFY_BUDGET_MS) break; // QA #15: abort → "not dup"
|
|
426
|
-
const cand = byId.get(id);
|
|
427
|
-
if (!cand) continue;
|
|
428
|
-
const candText = cand.normalizedText ?? cand.summary ?? "";
|
|
429
|
-
if (isNearDuplicate(regionText, candText)) return cand;
|
|
430
|
-
}
|
|
431
|
-
return undefined;
|
|
121
|
+
return addCheckpoint(this, input);
|
|
432
122
|
}
|
|
433
123
|
}
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* dedup-audit.ts — durable audit trail for dedup tier decisions
|
|
3
|
+
* (external-audit item #2).
|
|
4
|
+
*
|
|
5
|
+
* Before this module a tier decision existed only as the in-process `onTier`
|
|
6
|
+
* callback that paints the live UI; nothing survived the process, so an
|
|
7
|
+
* operator could not answer "which layer collapsed this region, onto what, at
|
|
8
|
+
* what similarity?" — the inputs needed to tune the thresholds in
|
|
9
|
+
* config/dedup.ts. Here each decision is appended to the repo's events.log as
|
|
10
|
+
* one structured JSON line (see `DedupAuditEvent` below).
|
|
11
|
+
*
|
|
12
|
+
* The event type and its append helper live HERE rather than in monitoring.ts:
|
|
13
|
+
* monitoring.ts already owns three concerns (decision events, the dashboard.json
|
|
14
|
+
* metrics snapshot, FP alerting) and sits close to its 300-line soft limit, so
|
|
15
|
+
* co-locating the shape with the only recorder that produces it keeps both files
|
|
16
|
+
* under the headroom gate. monitoring.ts re-exports both for callers (and the
|
|
17
|
+
* dashboard SSE tail) that treat it as the events.log barrel.
|
|
18
|
+
*
|
|
19
|
+
* Design constraints:
|
|
20
|
+
* - PURE INSTRUMENTATION. Nothing in this file may influence a dedup outcome.
|
|
21
|
+
* - Best-effort/non-fatal: `logDedupAudit` swallows IO errors, and the emitter
|
|
22
|
+
* itself is wrapped so a malformed field can never break add().
|
|
23
|
+
* - Honest fields only: a value is emitted only where the caller actually
|
|
24
|
+
* computed it. L0/L1 are hash/verify tiers and pass no `similarity`.
|
|
25
|
+
* - Signal, not chatter: callers emit on DECISIONS (a match, a scored
|
|
26
|
+
* candidate, the final outcome), never on every "scanning" transition.
|
|
27
|
+
* - Flag-gated by cfg.DEDUP_AUDIT (default ON; OFF writes nothing at all).
|
|
28
|
+
*
|
|
29
|
+
* PREVENT-PI-004: local filesystem append only, no network.
|
|
30
|
+
*/
|
|
31
|
+
|
|
32
|
+
import { appendFileSync, mkdirSync } from "node:fs";
|
|
33
|
+
import { dirname } from "node:path";
|
|
34
|
+
import { defaultEventsPath } from "../monitoring.js";
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* One dedup decision, as persisted to events.log.
|
|
38
|
+
*
|
|
39
|
+
* `ts` is an ISO-8601 string (not the epoch millis DedupDecisionEvent uses):
|
|
40
|
+
* the dashboard SSE tail only forwards lines carrying a `type` discriminator,
|
|
41
|
+
* and its consumers parse the timestamp as a date. Optional fields are omitted
|
|
42
|
+
* rather than nulled — a missing `similarity` means the tier computed no score,
|
|
43
|
+
* which is itself the honest signal (L0/L1 are hash/verify tiers).
|
|
44
|
+
*/
|
|
45
|
+
export interface DedupAuditEvent {
|
|
46
|
+
/** SSE discriminator — the dashboard streams only typed lines. */
|
|
47
|
+
type: "dedup_audit";
|
|
48
|
+
/** ISO-8601 decision timestamp. */
|
|
49
|
+
ts: string;
|
|
50
|
+
/** Normalized session the region belongs to. */
|
|
51
|
+
sessionId: string;
|
|
52
|
+
/** Which layer produced the decision ("new" = nothing collapsed). */
|
|
53
|
+
tier: "L0" | "L1" | "L2" | "new";
|
|
54
|
+
/** What the layer decided. */
|
|
55
|
+
status: "deduped" | "passed" | "stored";
|
|
56
|
+
/** Checkpoint the region collapsed onto, or the nearest one scored. */
|
|
57
|
+
matchedEntry?: string;
|
|
58
|
+
/** Checkpoint created, when the outcome was a new write. */
|
|
59
|
+
storedEntry?: string;
|
|
60
|
+
/** Cosine similarity — present only where a tier actually scored. */
|
|
61
|
+
similarity?: number;
|
|
62
|
+
/** Why the decision went the way it did (e.g. "contentHash", "mark_only"). */
|
|
63
|
+
dedupReason?: string;
|
|
64
|
+
/** Tokens the original region occupied before compaction. */
|
|
65
|
+
originalTokenEstimate?: number;
|
|
66
|
+
/** Tokens the stored summary occupies. */
|
|
67
|
+
tokenEstimate?: number;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Append one audit event to events.log (best-effort, never throws).
|
|
72
|
+
*
|
|
73
|
+
* Same append-one-JSON-line contract as monitoring.ts's logDecision — an
|
|
74
|
+
* unwritable path is swallowed so instrumentation can never break add().
|
|
75
|
+
*/
|
|
76
|
+
export function logDedupAudit(path: string, ev: DedupAuditEvent): void {
|
|
77
|
+
try {
|
|
78
|
+
mkdirSync(dirname(path), { recursive: true });
|
|
79
|
+
appendFileSync(path, `${JSON.stringify(ev)}\n`, "utf-8");
|
|
80
|
+
} catch {
|
|
81
|
+
/* best-effort — never break the extension on a log failure */
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/** The slice of VectorStore the audit emitter reads. */
|
|
86
|
+
export interface DedupAuditContext {
|
|
87
|
+
/** Per-repo state dir — resolves the events.log the dashboard tails. */
|
|
88
|
+
readonly stateDir: string;
|
|
89
|
+
/** Explicit events.log override (tests / the Sprint-14 monitoring opt-in). */
|
|
90
|
+
readonly eventsPath?: string;
|
|
91
|
+
/** Whether the audit trail is enabled (cfg.DEDUP_AUDIT). */
|
|
92
|
+
readonly auditEnabled: boolean;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/** The decision payload a call site supplies; ts/type are filled in here. */
|
|
96
|
+
export type DedupAuditInput = Omit<DedupAuditEvent, "type" | "ts">;
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* The per-add() facts every decision in one cascade shares: which session, and
|
|
100
|
+
* the token accounting already computed by the caller.
|
|
101
|
+
*/
|
|
102
|
+
export interface DedupAuditScope {
|
|
103
|
+
sessionId: string;
|
|
104
|
+
/** Tokens the original region occupied (VectorStore.add's `origTokens`). */
|
|
105
|
+
originalTokenEstimate?: number;
|
|
106
|
+
/** Tokens the stored summary occupies (AddInput.tokenEstimate). */
|
|
107
|
+
tokenEstimate?: number;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* A decision recorder bound to one add() cascade.
|
|
112
|
+
*
|
|
113
|
+
* `deduped` / `passed` / `stored` are the three shapes the cascade actually
|
|
114
|
+
* produces; binding them here keeps VectorStore.add's call sites to one line
|
|
115
|
+
* each (delegate-shell pattern) and keeps the field-honesty rules — which tier
|
|
116
|
+
* may carry a similarity, matched vs. created id — in a single place.
|
|
117
|
+
*/
|
|
118
|
+
export interface DedupAuditRecorder {
|
|
119
|
+
/** A tier collapsed the region onto `matchedEntry`. */
|
|
120
|
+
deduped(
|
|
121
|
+
tier: "L0" | "L1" | "L2",
|
|
122
|
+
matchedEntry: string,
|
|
123
|
+
dedupReason: string,
|
|
124
|
+
similarity?: number,
|
|
125
|
+
): void;
|
|
126
|
+
/** A tier scored a candidate but did not collapse (threshold near-miss). */
|
|
127
|
+
passed(
|
|
128
|
+
tier: "L0" | "L1" | "L2",
|
|
129
|
+
matchedEntry: string,
|
|
130
|
+
similarity: number,
|
|
131
|
+
): void;
|
|
132
|
+
/** Final outcome: nothing collapsed, a new checkpoint was written. */
|
|
133
|
+
stored(storedEntry: string, dedupReason: string, tokenEstimate: number): void;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/** Build a recorder bound to one add() cascade. */
|
|
137
|
+
export function dedupAuditRecorder(
|
|
138
|
+
ctx: DedupAuditContext,
|
|
139
|
+
scope: DedupAuditScope,
|
|
140
|
+
): DedupAuditRecorder {
|
|
141
|
+
const base = {
|
|
142
|
+
sessionId: scope.sessionId,
|
|
143
|
+
originalTokenEstimate: scope.originalTokenEstimate,
|
|
144
|
+
tokenEstimate: scope.tokenEstimate,
|
|
145
|
+
};
|
|
146
|
+
return {
|
|
147
|
+
deduped: (tier, matchedEntry, dedupReason, similarity) =>
|
|
148
|
+
emitDedupAudit(ctx, {
|
|
149
|
+
...base,
|
|
150
|
+
tier,
|
|
151
|
+
status: "deduped",
|
|
152
|
+
matchedEntry,
|
|
153
|
+
dedupReason,
|
|
154
|
+
...(similarity === undefined ? {} : { similarity }),
|
|
155
|
+
}),
|
|
156
|
+
passed: (tier, matchedEntry, similarity) =>
|
|
157
|
+
emitDedupAudit(ctx, {
|
|
158
|
+
...base,
|
|
159
|
+
tier,
|
|
160
|
+
status: "passed",
|
|
161
|
+
matchedEntry,
|
|
162
|
+
similarity,
|
|
163
|
+
}),
|
|
164
|
+
stored: (storedEntry, dedupReason, tokenEstimate) =>
|
|
165
|
+
emitDedupAudit(ctx, {
|
|
166
|
+
...base,
|
|
167
|
+
tier: "new",
|
|
168
|
+
status: "stored",
|
|
169
|
+
storedEntry,
|
|
170
|
+
dedupReason,
|
|
171
|
+
tokenEstimate,
|
|
172
|
+
}),
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* Append one dedup decision to events.log.
|
|
178
|
+
*
|
|
179
|
+
* Resolves the target path from the explicit `eventsPath` when a caller opted
|
|
180
|
+
* in (Sprint 14 monitoring / tests), otherwise from the store's own per-repo
|
|
181
|
+
* state dir — production never passes `eventsPath`, so defaulting is what makes
|
|
182
|
+
* the audit trail actually exist on a real device.
|
|
183
|
+
*/
|
|
184
|
+
export function emitDedupAudit(
|
|
185
|
+
ctx: DedupAuditContext,
|
|
186
|
+
input: DedupAuditInput,
|
|
187
|
+
): void {
|
|
188
|
+
if (!ctx.auditEnabled) return;
|
|
189
|
+
try {
|
|
190
|
+
const path = ctx.eventsPath ?? defaultEventsPath(ctx.stateDir);
|
|
191
|
+
logDedupAudit(path, {
|
|
192
|
+
type: "dedup_audit",
|
|
193
|
+
ts: new Date().toISOString(),
|
|
194
|
+
...input,
|
|
195
|
+
});
|
|
196
|
+
} catch {
|
|
197
|
+
/* instrumentation must never break the add() path */
|
|
198
|
+
}
|
|
199
|
+
}
|
package/src/vectorStore.ts
CHANGED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import{j as e,B as a,r as c}from"./index-i9oaPE0a.js";import{C as d,a as i,b as x,c as h}from"./card-C-DxXv1-.js";async function L(){const s=await fetch("/api/vector-cortex/evaluation");if(!s.ok)throw new Error(`vector-cortex evaluation: ${s.status}`);return s.json()}async function w(){const s=await fetch("/api/vector-cortex/health");if(!s.ok)throw new Error(`vector-cortex health: ${s.status}`);return s.json()}async function H(){const s=await fetch("/api/vector-cortex/topology");if(!s.ok)throw new Error(`vector-cortex topology: ${s.status}`);return s.json()}async function q(){const s=await fetch("/api/vector-cortex/query");if(!s.ok)throw new Error(`vector-cortex query: ${s.status}`);return s.json()}async function G(){const s=await fetch("/api/vector-cortex/shards");if(!s.ok)throw new Error(`vector-cortex shards: ${s.status}`);return s.json()}async function Q(){const s=await fetch("/api/vector-cortex/reconstruct");if(!s.ok)throw new Error(`vector-cortex reconstruct: ${s.status}`);return s.json()}async function W(){const s=await fetch("/api/vector-cortex/plans");if(!s.ok)throw new Error(`vector-cortex plans: ${s.status}`);return s.json()}async function z(){const s=await fetch("/api/vector-cortex/render");if(!s.ok)throw new Error(`vector-cortex render: ${s.status}`);return s.json()}async function J(s="default"){const o=await fetch(`/api/vector-cortex/ledger?session=${encodeURIComponent(s)}`);if(!o.ok)throw new Error(`vector-cortex ledger: ${o.status}`);return o.json()}async function K(s){const o=await fetch("/api/vector-cortex/breakers/reset",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({subsystem:s})});if(!o.ok)throw new Error(`vector-cortex reset: ${o.status}`);return o.json()}function t({label:s,value:o}){return e.jsxs("div",{children:[e.jsx("div",{className:"text-xs text-muted-foreground",children:s}),e.jsx("div",{className:"font-mono text-sm",children:o})]})}function U({view:s}){return e.jsxs(d,{children:[e.jsx(i,{children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(x,{children:"Validated Prompt Renderer (VC5B)"}),s?.enabled?e.jsx(a,{variant:"success",children:"ACTIVE"}):e.jsx(a,{variant:"danger",children:"OFF"})]})}),e.jsx(h,{children:s?.enabled?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid grid-cols-2 gap-4 md:grid-cols-4",children:[e.jsx(t,{label:"Render fixtures",value:String(s.renderCount)}),e.jsx(t,{label:"Provider profiles",value:String(s.providerCount)}),e.jsx(t,{label:"Known profiles",value:String(s.knownProfiles.length)})]}),e.jsx("div",{className:"mt-3 text-xs text-muted-foreground",children:"Reader-only render conformance route — no prompt text or session payloads exposed."})]}):e.jsx("div",{className:"vc-empty",children:"Renderer disabled (VC5B off)."})})]})}function Z({view:s}){return e.jsxs(d,{children:[e.jsx(i,{children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(x,{children:"Plan Manifests (VC5A)"}),s?.enabled?e.jsx(a,{variant:"success",children:"ACTIVE"}):e.jsx(a,{variant:"danger",children:"OFF"})]})}),e.jsx(h,{children:s?.enabled?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid grid-cols-2 gap-4 md:grid-cols-4",children:[e.jsx(t,{label:"DAG fixtures",value:String(s.dagCount)}),e.jsx(t,{label:"Plan fixtures",value:String(s.plannerCount)}),e.jsx(t,{label:"Plans exposed",value:String(s.plans.length)})]}),e.jsx("div",{className:"mt-3 text-xs text-muted-foreground",children:"Reader-only plan manifests only — no session payloads or prompt text. Per-run plan outputs are staged in-memory this sprint."})]}):e.jsx("div",{className:"vc-empty",children:"PromptDagV1 + budgeted planner disabled (VC5A off)."})})]})}function p({mode:s,count:o}){return e.jsxs("div",{className:"flex items-center justify-between border-b border-border/50 py-1 text-sm",children:[e.jsxs("span",{className:"text-muted-foreground",children:["Mode ",s]}),e.jsx("span",{className:"font-mono",children:o})]})}function _(){const[s,o]=c.useState(null),[b,V]=c.useState(null),[E,F]=c.useState(!0),[n,y]=c.useState(null),[N,C]=c.useState(null),[m,R]=c.useState(null),[l,$]=c.useState(null),[v,k]=c.useState(null),[j,A]=c.useState(null),[u,T]=c.useState(null),[I,M]=c.useState(null),[B,D]=c.useState(null),f=c.useCallback(()=>{L().then(o).catch(r=>V(r instanceof Error?r.message:String(r))).finally(()=>F(!1)),w().then(y).catch(()=>{}),J().then(R).catch(()=>{}),H().then($).catch(()=>{}),q().then(k).catch(()=>{}),G().then(A).catch(()=>{}),Q().then(T).catch(()=>{}),W().then(M).catch(()=>{}),z().then(D).catch(()=>{})},[]);c.useEffect(()=>{f();const r=setInterval(f,5e3);return()=>clearInterval(r)},[f]);const O=()=>{K("provider").then(r=>(C(`Breaker "${r.subsystem}" ${r.state}; evidence retained: ${r.failures} failures / ${r.attempts} attempts`),w())).then(y).catch(r=>C(r instanceof Error?r.message:String(r)))};if(E&&!s)return e.jsx("div",{className:"vc-loading",children:"Loading vector-cortex evaluation…"});if(b&&!s)return e.jsxs("div",{className:"vc-error",children:["Error: ",b]});if(!s)return e.jsx("div",{className:"vc-empty",children:"No evaluation data available."});const S=Math.max(1,...s.histogram.cells,s.histogram.overflow);return e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("h2",{className:"text-lg font-semibold",children:"Vector Cortex Evaluation"}),s.enabled?e.jsx(a,{variant:"warning",children:"OBSERVER PENDING (A)"}):e.jsx(a,{variant:"danger",children:"MODE C (OFF)"})]}),e.jsxs("div",{className:"grid grid-cols-1 gap-4 md:grid-cols-3",children:[e.jsxs(d,{children:[e.jsx(i,{children:e.jsx(x,{children:"Samples"})}),e.jsxs(h,{children:[e.jsx("div",{className:"text-3xl font-bold",children:s.samples}),e.jsxs("div",{className:"mt-2 flex flex-col",children:[e.jsx(p,{mode:"A",count:s.byMode.A}),e.jsx(p,{mode:"B",count:s.byMode.B}),e.jsx(p,{mode:"C",count:s.byMode.C})]})]})]}),e.jsxs(d,{className:"md:col-span-2",children:[e.jsx(i,{children:e.jsx(x,{children:"Latency Histogram (ms, inclusive edges)"})}),e.jsxs(h,{children:[e.jsxs("div",{className:"flex items-end gap-2",style:{height:160},children:[s.histogram.edges.map((r,g)=>{const P=s.histogram.cells[g]/S*140;return e.jsxs("div",{className:"flex flex-1 flex-col items-center gap-1",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:s.histogram.cells[g]}),e.jsx("div",{className:"w-full rounded-t",style:{height:Math.max(2,P),background:"#6366f1"}}),e.jsxs("span",{className:"text-[10px] text-muted-foreground",children:["≤",r]})]},r)}),e.jsxs("div",{className:"flex flex-1 flex-col items-center gap-1",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:s.histogram.overflow}),e.jsx("div",{className:"w-full rounded-t",style:{height:Math.max(2,s.histogram.overflow/S*140),background:"#f87171"}}),e.jsx("span",{className:"text-[10px] text-muted-foreground",children:">250"})]})]}),e.jsxs("div",{className:"mt-1 text-xs text-muted-foreground",children:["Total: ",s.histogram.total," · Rejects: ",s.rejects.length]})]})]})]}),e.jsxs(d,{children:[e.jsx(i,{children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(x,{children:"Live Safety Envelope (VC0C)"}),e.jsxs("div",{className:"flex items-center gap-2",children:[n?.stateSource==="ephemeral"&&e.jsx(a,{variant:"outline",children:"EPHEMERAL (non-live)"}),e.jsx("button",{onClick:O,disabled:!n?.enabled,className:"rounded border border-border px-2 py-1 text-xs disabled:opacity-50",children:"Reset Cooldown"})]})]})}),e.jsxs(h,{children:[N&&e.jsx("div",{className:"mb-2 text-xs text-muted-foreground",children:N}),n?e.jsxs("div",{className:"grid grid-cols-2 gap-4 md:grid-cols-4",children:[e.jsx(t,{label:"State",value:n.state}),e.jsx(t,{label:"Mode",value:n.mode}),e.jsx(t,{label:"Window",value:`${n.windowMs}ms`}),e.jsx(t,{label:"Probes",value:String(n.probeCount)}),e.jsx(t,{label:"Backoff",value:`${n.backoffDelayMs}ms`}),e.jsx(t,{label:"Failures",value:`${n.failures}/${n.attempts}`}),e.jsx(t,{label:"Frontier",value:n.stateSource==="ephemeral"?"non-live":n.frontierFrozen?"FROZEN":"LIVE"}),e.jsx(t,{label:"Spool lag",value:String(n.spoolLag)}),e.jsx(t,{label:"Encoder mode",value:n.encoderMode}),e.jsx(t,{label:"Encoder asset",value:n.encoderAssetDigest?n.encoderAssetDigest.slice(0,12):"none"})]}):e.jsx("div",{className:"vc-empty",children:"Health unavailable (VC0C off)."})]})]}),e.jsxs(d,{children:[e.jsx(i,{children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(x,{children:"Derived Cortex Store (VC3A)"}),l?.enabled?e.jsx(a,{variant:"success",children:"ACTIVE"}):e.jsx(a,{variant:"danger",children:"OFF"})]})}),e.jsx(h,{children:l?.enabled?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid grid-cols-2 gap-4 md:grid-cols-3",children:[e.jsx(t,{label:"Generation",value:l.generationId??"—"}),e.jsx(t,{label:"Ordinal",value:l.ordinal??"—"}),e.jsx(t,{label:"Records",value:String(l.recordCount)}),e.jsx(t,{label:"Frontier (HW)",value:l.sourceHighWater}),e.jsx(t,{label:"Root digest",value:l.rootDigest?l.rootDigest.slice(0,16):"—"}),l.nodes!==void 0&&e.jsxs(e.Fragment,{children:[e.jsx(t,{label:"Nodes",value:String(l.nodes?.length??0)}),e.jsx(t,{label:"Edges",value:String(l.edges?.length??0)}),e.jsx(t,{label:"Graph digest",value:l.generationDigest?l.generationDigest.slice(0,16):"—"})]})]}),l.nodes!==void 0&&(l.edges?.length??0)>0&&e.jsxs("div",{className:"mt-4 max-h-56 overflow-y-auto",children:[e.jsx("div",{className:"mb-1 text-xs font-medium text-muted-foreground",children:"Topology edges (VC3B)"}),e.jsxs("table",{className:"w-full text-left text-xs",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"border-b border-border/50 text-muted-foreground",children:[e.jsx("th",{className:"py-1 pr-2",children:"source"}),e.jsx("th",{className:"py-1 pr-2",children:"target"}),e.jsx("th",{className:"py-1 pr-2",children:"head"}),e.jsx("th",{className:"py-1 pr-2",children:"dir"}),e.jsx("th",{className:"py-1",children:"score"})]})}),e.jsx("tbody",{children:l.edges?.map((r,g)=>e.jsxs("tr",{className:"border-b border-border/30",children:[e.jsx("td",{className:"py-1 pr-2 font-mono",children:r.source}),e.jsx("td",{className:"py-1 pr-2 font-mono",children:r.target}),e.jsx("td",{className:"py-1 pr-2 font-mono",children:r.head}),e.jsx("td",{className:"py-1 pr-2",children:r.direction}),e.jsx("td",{className:"py-1 font-mono",children:r.score})]},`${r.source}-${r.target}-${r.head}-${g}`))})]})]})]}):e.jsx("div",{className:"vc-empty",children:"Cortex store disabled (VC3A off)."})})]}),e.jsxs(d,{children:[e.jsx(i,{children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(x,{children:"Topology Query Diagnostics (VC3C)"}),v?.enabled?e.jsx(a,{variant:"success",children:"ACTIVE"}):e.jsx(a,{variant:"danger",children:"OFF"})]})}),e.jsx(h,{children:v?.enabled?e.jsx("div",{className:"grid grid-cols-2 gap-4 md:grid-cols-3",children:e.jsx(t,{label:"Router version",value:String(v.routerVersion)})}):e.jsx("div",{className:"vc-empty",children:"Query diagnostics unavailable (VC3C off)."})})]}),e.jsxs(d,{children:[e.jsx(i,{children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(x,{children:"Dual-Tier Shards (VC4A)"}),j?.enabled?e.jsx(a,{variant:"success",children:"ACTIVE"}):e.jsx(a,{variant:"danger",children:"OFF"})]})}),e.jsx(h,{children:j?.enabled?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid grid-cols-2 gap-4 md:grid-cols-4",children:[e.jsx(t,{label:"Semantic shards",value:String(j.semanticCount)}),e.jsx(t,{label:"Exact shards",value:String(j.exactCount)}),e.jsx(t,{label:"Byte total",value:String(j.byteTotal)}),e.jsx(t,{label:"Protected bytes",value:String(j.protectedByteTotal)})]}),e.jsx("div",{className:"mt-3 text-xs text-muted-foreground",children:"Reader-only count/byte aggregate; staged in-memory this sprint."})]}):e.jsx("div",{className:"vc-empty",children:"Dual-tier shards disabled (VC4A off)."})})]}),e.jsxs(d,{children:[e.jsx(i,{children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(x,{children:"Reconstruction Fidelity (VC4C)"}),u?.enabled?e.jsx(a,{variant:"success",children:"ACTIVE"}):e.jsx(a,{variant:"danger",children:"OFF"})]})}),e.jsx(h,{children:u?.enabled?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid grid-cols-2 gap-4 md:grid-cols-4",children:[e.jsx(t,{label:"Closure attempts",value:String(u.closureAttempts)}),e.jsx(t,{label:"Closure rejections",value:String(u.closureRejections)}),e.jsx(t,{label:"Validated",value:String(u.validatedCount)}),e.jsx(t,{label:"Invalidated",value:String(u.invalidatedCount)}),e.jsx(t,{label:"Span total",value:String(u.spanTotal)}),e.jsx(t,{label:"Byte total",value:String(u.byteTotal)})]}),e.jsx("div",{className:"mt-3 text-xs text-muted-foreground",children:"Reader-only closure/validation aggregate; staged in-memory this sprint."})]}):e.jsx("div",{className:"vc-empty",children:"Reconstruction fidelity disabled (VC4C off)."})})]}),e.jsx(Z,{view:I}),e.jsx(U,{view:B}),e.jsxs(d,{children:[e.jsx(i,{children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(x,{children:"Occurrence Ledger (VC1B)"}),m?.enabled?e.jsx(a,{variant:"success",children:"ACTIVE"}):e.jsx(a,{variant:"danger",children:"OFF"})]})}),e.jsx(h,{children:m?.enabled?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"mb-3 grid grid-cols-2 gap-4 md:grid-cols-3",children:[e.jsx(t,{label:"Session",value:m.session}),e.jsx(t,{label:"High-water",value:m.highWater}),e.jsx(t,{label:"Occurrences",value:String(m.count)})]}),m.occurrences.length===0?e.jsx("div",{className:"vc-empty",children:"No occurrences recorded."}):e.jsx("div",{className:"max-h-64 overflow-y-auto",children:e.jsxs("table",{className:"w-full text-left text-xs",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"border-b border-border/50 text-muted-foreground",children:[e.jsx("th",{className:"py-1 pr-2",children:"seq"}),e.jsx("th",{className:"py-1 pr-2",children:"eventId"}),e.jsx("th",{className:"py-1 pr-2",children:"kind"}),e.jsx("th",{className:"py-1 pr-2",children:"toolCall"}),e.jsx("th",{className:"py-1",children:"digest"})]})}),e.jsx("tbody",{children:m.occurrences.map(r=>e.jsxs("tr",{className:"border-b border-border/30",children:[e.jsx("td",{className:"py-1 pr-2 font-mono",children:r.seq}),e.jsx("td",{className:"py-1 pr-2 font-mono",children:r.eventId}),e.jsx("td",{className:"py-1 pr-2",children:r.kind}),e.jsx("td",{className:"py-1 pr-2 font-mono",children:r.toolCallId??"—"}),e.jsx("td",{className:"max-w-[180px] truncate font-mono text-muted-foreground",children:r.digest})]},`${r.seq}-${r.eventId}`))})]})})]}):e.jsx("div",{className:"vc-empty",children:"Ledger disabled (VC1B off)."})})]})]})}export{_ as default};
|
|
2
|
-
//# sourceMappingURL=VectorCortexTab-BWi3u_gp.js.map
|