pi-mega-compact 0.20.13 → 0.20.14
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-early.js +89 -0
- package/dist/config/vector-cortex-flag.js +25 -0
- package/dist/config/vector-cortex.js +23 -83
- package/dist/config.js +1 -1
- package/dist/extensions/dashboard-server/api-contracts/vector-cortex-economics.js +20 -0
- package/dist/extensions/dashboard-server/route-dispatch.js +6 -0
- package/dist/extensions/dashboard-server/routes-rag-settings-vector-cortex.js +1 -0
- package/dist/extensions/dashboard-server/routes-vector-cortex-economics.js +59 -0
- package/dist/src/config/vector-cortex-early.js +89 -0
- package/dist/src/config/vector-cortex-flag.js +25 -0
- package/dist/src/config/vector-cortex.js +23 -83
- package/dist/src/config.js +1 -1
- package/dist/src/vector-cortex/cache/_economics-fixture.js +41 -0
- package/dist/src/vector-cortex/cache/compiler.js +201 -0
- package/dist/src/vector-cortex/cache/economics-emit.js +85 -0
- package/dist/src/vector-cortex/migrations/request-hash-v2.js +161 -0
- package/dist/src/vector-cortex/provider/economics-ids.js +29 -0
- package/dist/src/vector-cortex/provider/economics.js +176 -0
- package/dist/src/vector-cortex/provider/experiments.js +166 -0
- package/dist/vector-cortex/cache/_economics-fixture.js +41 -0
- package/dist/vector-cortex/cache/compiler.js +201 -0
- package/dist/vector-cortex/cache/economics-emit.js +85 -0
- package/dist/vector-cortex/migrations/request-hash-v2.js +161 -0
- package/dist/vector-cortex/provider/economics-ids.js +29 -0
- package/dist/vector-cortex/provider/economics.js +176 -0
- package/dist/vector-cortex/provider/experiments.js +166 -0
- package/extensions/dashboard-client/dist/assets/{AreaChart-CB-U7ViX.js → AreaChart-VUd_iOtO.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{AreaChart-CB-U7ViX.js.map → AreaChart-VUd_iOtO.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{BarChart-DnLw0fxA.js → BarChart-BoqeJ5mM.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{BarChart-DnLw0fxA.js.map → BarChart-BoqeJ5mM.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{CacheTab-CjyTVDiP.js → CacheTab-1ON7meDK.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{CacheTab-CjyTVDiP.js.map → CacheTab-1ON7meDK.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{EventsTab-Bz3QEWam.js → EventsTab-Dr9eqt1k.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{EventsTab-Bz3QEWam.js.map → EventsTab-Dr9eqt1k.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{HealthTab-CUylEvEY.js → HealthTab-Ciaigd4i.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{HealthTab-CUylEvEY.js.map → HealthTab-Ciaigd4i.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{MaintenanceTab-Cz_hj_E7.js → MaintenanceTab-DjZRr3Lf.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{MaintenanceTab-Cz_hj_E7.js.map → MaintenanceTab-DjZRr3Lf.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{MemoryMapTab-Dh8brIR1.js → MemoryMapTab-BpZXHA7j.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{MemoryMapTab-Dh8brIR1.js.map → MemoryMapTab-BpZXHA7j.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{MetricsTab-CkqSXc6e.js → MetricsTab-QemocY5k.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{MetricsTab-CkqSXc6e.js.map → MetricsTab-QemocY5k.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{OverviewTab-DGbJcx6d.js → OverviewTab-VtC1F-mO.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{OverviewTab-DGbJcx6d.js.map → OverviewTab-VtC1F-mO.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{ReposTab-BawS3nfF.js → ReposTab-CJD1cBxp.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{ReposTab-BawS3nfF.js.map → ReposTab-CJD1cBxp.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{SessionsTab-CUVnmYks.js → SessionsTab-Cj0erPR4.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{SessionsTab-CUVnmYks.js.map → SessionsTab-Cj0erPR4.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{SetupTab-cxTuyZNk.js → SetupTab-AOVROZ4G.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{SetupTab-cxTuyZNk.js.map → SetupTab-AOVROZ4G.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{TimeSavedCard-Cv5SENkE.js → TimeSavedCard-ZliVn8DH.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{TimeSavedCard-Cv5SENkE.js.map → TimeSavedCard-ZliVn8DH.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{TurnsTab-yl6BBG_F.js → TurnsTab-DsoTWeIh.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{TurnsTab-yl6BBG_F.js.map → TurnsTab-DsoTWeIh.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/VectorCortexTab-BBa7rp6C.js +2 -0
- package/extensions/dashboard-client/dist/assets/VectorCortexTab-BBa7rp6C.js.map +1 -0
- package/extensions/dashboard-client/dist/assets/{WikiTab-DKv-0xCQ.js → WikiTab-CK8fcW1l.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{WikiTab-DKv-0xCQ.js.map → WikiTab-CK8fcW1l.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{button-CVPrO4UU.js → button-DdPcvex1.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{button-CVPrO4UU.js.map → button-DdPcvex1.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{card-BFLnQJEo.js → card-DXFuZph_.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{card-BFLnQJEo.js.map → card-DXFuZph_.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{generateCategoricalChart-B-IUoLd1.js → generateCategoricalChart-BagDVGWn.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{generateCategoricalChart-B-IUoLd1.js.map → generateCategoricalChart-BagDVGWn.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{index-Do749WlW.js → index-DVdDtRY4.js} +3 -3
- package/extensions/dashboard-client/dist/assets/{index-Do749WlW.js.map → index-DVdDtRY4.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{switch-3uFnZmtq.js → switch-CtdtGyUR.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{switch-3uFnZmtq.js.map → switch-CtdtGyUR.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{toggle-C1rYLeXe.js → toggle-Cvvwlbye.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{toggle-C1rYLeXe.js.map → toggle-Cvvwlbye.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{useSSE-D1qzLzgR.js → useSSE-DvlceHjV.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{useSSE-D1qzLzgR.js.map → useSSE-DvlceHjV.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/VectorCortexEconomicsCard.tsx +41 -0
- package/extensions/dashboard-client/src/tabs/VectorCortexTab.tsx +8 -0
- package/extensions/dashboard-client/src/types/vector-cortex.ts +14 -0
- package/extensions/dashboard-server/api-contracts/vector-cortex-economics.ts +47 -0
- package/extensions/dashboard-server/route-dispatch.ts +5 -0
- package/extensions/dashboard-server/routes-rag-settings-vector-cortex.ts +6 -0
- package/extensions/dashboard-server/routes-vector-cortex-economics.ts +68 -0
- package/package.json +1 -1
- package/src/config/vector-cortex-early.ts +99 -0
- package/src/config/vector-cortex-flag.ts +24 -0
- package/src/config/vector-cortex.ts +34 -89
- package/src/config.ts +1 -0
- package/src/vector-cortex/cache/_economics-fixture.ts +128 -0
- package/src/vector-cortex/cache/compiler.ts +280 -0
- package/src/vector-cortex/cache/economics-emit.ts +116 -0
- package/src/vector-cortex/migrations/request-hash-v2.ts +228 -0
- package/src/vector-cortex/provider/economics-ids.ts +38 -0
- package/src/vector-cortex/provider/economics.ts +289 -0
- package/src/vector-cortex/provider/experiments.ts +248 -0
- package/extensions/dashboard-client/dist/assets/VectorCortexTab-94fqVjat.js +0 -2
- package/extensions/dashboard-client/dist/assets/VectorCortexTab-94fqVjat.js.map +0 -1
|
@@ -0,0 +1,280 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* vector-cortex/cache/compiler.ts — VC7B provider-safe crystal boundary compiler.
|
|
3
|
+
*
|
|
4
|
+
* A provider caches a PREFIX of the request. So where you cut the prompt into
|
|
5
|
+
* cacheable segments determines whether anything is reusable at all: cut too
|
|
6
|
+
* finely and every segment falls under the provider's `minPrefix` and nothing is
|
|
7
|
+
* cacheable; cut in the wrong place and a segment that changes every turn sits
|
|
8
|
+
* in front of one that never changes, invalidating everything behind it. This
|
|
9
|
+
* file turns validated source ranges plus a profile's limits into boundaries
|
|
10
|
+
* that the provider can actually cache.
|
|
11
|
+
*
|
|
12
|
+
* THE ONE INVARIANT THAT OUTRANKS EVERYTHING: THE COMPILER NEVER CHANGES
|
|
13
|
+
* REQUEST IDENTITY. It selects where boundaries FALL; it never reorders, never
|
|
14
|
+
* merges across a session, never drops a range, never rewrites bytes. The
|
|
15
|
+
* concatenation of the compiled boundaries covers exactly the same ranges, in
|
|
16
|
+
* exactly the same canonical order, as the input — so the VC5B canonical request
|
|
17
|
+
* digest and the VC7A crystal key are byte-identical before and after
|
|
18
|
+
* compilation. `boundariesPreserveIdentity()` states this as an executable
|
|
19
|
+
* check, and the acceptance suite runs it on every compiled row. If compilation
|
|
20
|
+
* could alter identity it would be a cache-poisoning engine rather than an
|
|
21
|
+
* optimizer: two different conversations could compile to one cache key.
|
|
22
|
+
*
|
|
23
|
+
* WHY MERGE FORWARD, AND ONLY WITHIN A SESSION. Ranges below `minPrefix` are not
|
|
24
|
+
* independently cacheable, so the compiler merges each undersized range into the
|
|
25
|
+
* one that FOLLOWS it in canonical order — forward, so the merged segment keeps
|
|
26
|
+
* the earlier range's start and the prefix relationship is preserved. Merging is
|
|
27
|
+
* confined to a single session because ranges from different sessions cover
|
|
28
|
+
* disjoint byte streams; a cross-session segment would claim a contiguity that
|
|
29
|
+
* does not exist. A trailing undersized run with nothing to merge into is
|
|
30
|
+
* emitted as its own boundary marked `cacheable: false` — reported honestly as
|
|
31
|
+
* uncacheable rather than padded, dropped, or silently attached backwards.
|
|
32
|
+
*
|
|
33
|
+
* BOUNDED. `maxSegments` caps the output so a caller-shaped range list cannot be
|
|
34
|
+
* turned into an unbounded segmentation (`COMP_SEGMENT_LIMIT`).
|
|
35
|
+
*
|
|
36
|
+
* PURE. No clock, no storage, no console, no network (PREVENT-PI-004 /
|
|
37
|
+
* PREVENT-011). Runs identically with `MEGACOMPACT_VC7B` on or off — the flag
|
|
38
|
+
* gates only the reporter/dashboard seam in `./economics-emit.ts`.
|
|
39
|
+
*/
|
|
40
|
+
|
|
41
|
+
import { createHash } from "node:crypto";
|
|
42
|
+
|
|
43
|
+
import { compareSpans, sortSpans, validateRanges } from "./crystal.js";
|
|
44
|
+
import type { CrystalKeyV1, DagSpan } from "./types.js";
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* One compiled, provider-safe cache boundary: a contiguous run of covered ranges
|
|
48
|
+
* within a SINGLE session that the provider may treat as one cacheable segment.
|
|
49
|
+
*/
|
|
50
|
+
export interface CrystalBoundaryV1 {
|
|
51
|
+
readonly schema: "crystal-boundary-v1";
|
|
52
|
+
/** The session these ranges belong to (a boundary never spans sessions). */
|
|
53
|
+
readonly sessionId: string;
|
|
54
|
+
/** The covered ranges in this segment, in canonical order. */
|
|
55
|
+
readonly ranges: readonly DagSpan[];
|
|
56
|
+
/** Total covered bytes in the segment. */
|
|
57
|
+
readonly byteCount: number;
|
|
58
|
+
/** Approximate token count used against `minPrefix` (see `tokensForBytes`). */
|
|
59
|
+
readonly tokenCount: number;
|
|
60
|
+
/**
|
|
61
|
+
* Whether the provider can actually cache this segment: it meets `minPrefix`.
|
|
62
|
+
* A `false` segment is still emitted and still rendered — it is simply priced
|
|
63
|
+
* as uncached rather than pretended to be a hit.
|
|
64
|
+
*/
|
|
65
|
+
readonly cacheable: boolean;
|
|
66
|
+
/** `sha256:` digest over the segment's ranges — a segment-level content pin. */
|
|
67
|
+
readonly digest: string;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** Profile-derived limits the compiler must respect. */
|
|
71
|
+
export interface CompilerLimits {
|
|
72
|
+
/** Minimum cacheable prefix in tokens (`ProviderEconomicsV1.minPrefix`). */
|
|
73
|
+
readonly minPrefix: number;
|
|
74
|
+
/** Maximum number of compiled segments. Bounds the output. */
|
|
75
|
+
readonly maxSegments: number;
|
|
76
|
+
/** Bytes per token used for the token estimate. Must be >= 1. */
|
|
77
|
+
readonly bytesPerToken: number;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/** Conventional default limits (4 bytes/token is the usual English estimate). */
|
|
81
|
+
export const DEFAULT_COMPILER_LIMITS: CompilerLimits = {
|
|
82
|
+
minPrefix: 1024,
|
|
83
|
+
maxSegments: 64,
|
|
84
|
+
bytesPerToken: 4,
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
/** VC7B compiler failure codes. */
|
|
88
|
+
export type CompilerFailureCode =
|
|
89
|
+
/** The input ranges failed VC7A validation (empty/malformed/overlapping). */
|
|
90
|
+
| "COMP_RANGE_INVALID"
|
|
91
|
+
/** Compilation would exceed `maxSegments`. */
|
|
92
|
+
| "COMP_SEGMENT_LIMIT"
|
|
93
|
+
/** A limit is negative, fractional, or otherwise unusable. */
|
|
94
|
+
| "COMP_LIMIT_INVALID"
|
|
95
|
+
/** The compiled boundaries did not re-cover the input exactly (never expected). */
|
|
96
|
+
| "COMP_IDENTITY_DRIFT";
|
|
97
|
+
|
|
98
|
+
/** The verdict of a compilation. */
|
|
99
|
+
export type CompileResult =
|
|
100
|
+
| {
|
|
101
|
+
readonly ok: true;
|
|
102
|
+
readonly boundaries: readonly CrystalBoundaryV1[];
|
|
103
|
+
/** Segments the provider can actually cache (`cacheable: true`). */
|
|
104
|
+
readonly cacheableCount: number;
|
|
105
|
+
/** Covered tokens sitting in cacheable segments. */
|
|
106
|
+
readonly cacheableTokens: number;
|
|
107
|
+
}
|
|
108
|
+
| { readonly ok: false; readonly codes: readonly CompilerFailureCode[] };
|
|
109
|
+
|
|
110
|
+
/** Covered bytes of one range. */
|
|
111
|
+
function spanBytes(s: DagSpan): number {
|
|
112
|
+
return s.endByte - s.startByte;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Byte→token estimate. Deliberately a floor: under-estimating tokens can only
|
|
117
|
+
* make the compiler MORE conservative about calling a segment cacheable, which
|
|
118
|
+
* fails safe (a wrongly-cacheable segment would be priced as a hit it never got).
|
|
119
|
+
*/
|
|
120
|
+
export function tokensForBytes(bytes: number, bytesPerToken: number): number {
|
|
121
|
+
return Math.floor(bytes / bytesPerToken);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/** `sha256:` digest over a segment's ranges — length-prefixed, so injective. */
|
|
125
|
+
function boundaryDigest(ranges: readonly DagSpan[]): string {
|
|
126
|
+
const h = createHash("sha256");
|
|
127
|
+
for (const s of ranges) {
|
|
128
|
+
const parts = [
|
|
129
|
+
s.sessionId,
|
|
130
|
+
s.startSeq.toString(),
|
|
131
|
+
s.endSeq.toString(),
|
|
132
|
+
String(s.startByte),
|
|
133
|
+
String(s.endByte),
|
|
134
|
+
s.digest,
|
|
135
|
+
];
|
|
136
|
+
for (const p of parts) h.update(`${Buffer.byteLength(p, "utf8")}:${p}`, "utf8");
|
|
137
|
+
}
|
|
138
|
+
return `sha256:${h.digest("hex")}`;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/** Build one boundary from a contiguous same-session run of ranges. */
|
|
142
|
+
function makeBoundary(
|
|
143
|
+
ranges: readonly DagSpan[],
|
|
144
|
+
limits: CompilerLimits,
|
|
145
|
+
): CrystalBoundaryV1 {
|
|
146
|
+
const byteCount = ranges.reduce((n, s) => n + spanBytes(s), 0);
|
|
147
|
+
const tokenCount = tokensForBytes(byteCount, limits.bytesPerToken);
|
|
148
|
+
const first = ranges[0];
|
|
149
|
+
return {
|
|
150
|
+
schema: "crystal-boundary-v1",
|
|
151
|
+
sessionId: first === undefined ? "" : first.sessionId,
|
|
152
|
+
ranges,
|
|
153
|
+
byteCount,
|
|
154
|
+
tokenCount,
|
|
155
|
+
cacheable: tokenCount >= limits.minPrefix,
|
|
156
|
+
digest: boundaryDigest(ranges),
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
function validLimits(l: CompilerLimits): boolean {
|
|
161
|
+
return (
|
|
162
|
+
Number.isSafeInteger(l.minPrefix) &&
|
|
163
|
+
l.minPrefix >= 0 &&
|
|
164
|
+
Number.isSafeInteger(l.maxSegments) &&
|
|
165
|
+
l.maxSegments > 0 &&
|
|
166
|
+
Number.isSafeInteger(l.bytesPerToken) &&
|
|
167
|
+
l.bytesPerToken >= 1
|
|
168
|
+
);
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* Compile validated ranges into provider-safe cache boundaries.
|
|
173
|
+
*
|
|
174
|
+
* Ranges are first put in canonical order (the SAME `sortSpans` order the VC7A
|
|
175
|
+
* key encoder uses — sharing the comparator is what keeps the two subsystems
|
|
176
|
+
* from disagreeing about what "canonical" means). They are then grouped by
|
|
177
|
+
* session, and within each session an undersized run is merged FORWARD until it
|
|
178
|
+
* meets `minPrefix`.
|
|
179
|
+
*
|
|
180
|
+
* Identity is verified before returning: the flattened output must equal the
|
|
181
|
+
* canonical input exactly. That check should never fire — it is a guard against
|
|
182
|
+
* a future edit to the merge loop quietly reordering or dropping a range.
|
|
183
|
+
*/
|
|
184
|
+
export function compileCrystalBoundaries(
|
|
185
|
+
ranges: readonly DagSpan[],
|
|
186
|
+
limits: CompilerLimits = DEFAULT_COMPILER_LIMITS,
|
|
187
|
+
): CompileResult {
|
|
188
|
+
if (!validLimits(limits)) return { ok: false, codes: ["COMP_LIMIT_INVALID"] };
|
|
189
|
+
|
|
190
|
+
// Reuse VC7A's validator verbatim: the compiler must never accept a range set
|
|
191
|
+
// the crystal key would reject, or the two would disagree about what is legal.
|
|
192
|
+
const rangeCodes = validateRanges(ranges);
|
|
193
|
+
if (rangeCodes.length > 0) return { ok: false, codes: ["COMP_RANGE_INVALID"] };
|
|
194
|
+
|
|
195
|
+
const sorted = sortSpans(ranges);
|
|
196
|
+
const boundaries: CrystalBoundaryV1[] = [];
|
|
197
|
+
|
|
198
|
+
let run: DagSpan[] = [];
|
|
199
|
+
const flushRun = (): void => {
|
|
200
|
+
if (run.length > 0) {
|
|
201
|
+
boundaries.push(makeBoundary(run, limits));
|
|
202
|
+
run = [];
|
|
203
|
+
}
|
|
204
|
+
};
|
|
205
|
+
|
|
206
|
+
for (const span of sorted) {
|
|
207
|
+
const head = run[0];
|
|
208
|
+
// A session change always closes the run: a boundary never spans sessions,
|
|
209
|
+
// because two sessions' byte streams are not contiguous with each other.
|
|
210
|
+
if (head !== undefined && head.sessionId !== span.sessionId) flushRun();
|
|
211
|
+
run.push(span);
|
|
212
|
+
const bytes = run.reduce((n, s) => n + spanBytes(s), 0);
|
|
213
|
+
// Close as soon as the run is independently cacheable; anything smaller keeps
|
|
214
|
+
// absorbing the next range (merge-forward).
|
|
215
|
+
if (tokensForBytes(bytes, limits.bytesPerToken) >= limits.minPrefix) flushRun();
|
|
216
|
+
}
|
|
217
|
+
// A trailing undersized run has nothing left to merge into: emit it honestly
|
|
218
|
+
// as a non-cacheable boundary rather than padding or dropping it.
|
|
219
|
+
flushRun();
|
|
220
|
+
|
|
221
|
+
if (boundaries.length > limits.maxSegments) {
|
|
222
|
+
return { ok: false, codes: ["COMP_SEGMENT_LIMIT"] };
|
|
223
|
+
}
|
|
224
|
+
if (!boundariesPreserveIdentity(sorted, boundaries)) {
|
|
225
|
+
return { ok: false, codes: ["COMP_IDENTITY_DRIFT"] };
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
let cacheableCount = 0;
|
|
229
|
+
let cacheableTokens = 0;
|
|
230
|
+
for (const b of boundaries) {
|
|
231
|
+
if (b.cacheable) {
|
|
232
|
+
cacheableCount += 1;
|
|
233
|
+
cacheableTokens += b.tokenCount;
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
return { ok: true, boundaries, cacheableCount, cacheableTokens };
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
/**
|
|
240
|
+
* The executable form of the sprint's headline invariant: flattening the
|
|
241
|
+
* compiled boundaries must reproduce the canonical input ranges EXACTLY — same
|
|
242
|
+
* ranges, same order, same pinned digests.
|
|
243
|
+
*
|
|
244
|
+
* Comparison is field-by-field on identity (session, seq bounds, byte bounds,
|
|
245
|
+
* digest), never by count or by digest alone: a compiler bug that swapped two
|
|
246
|
+
* equal-length ranges would keep the count and the byte total identical while
|
|
247
|
+
* changing what the request means.
|
|
248
|
+
*/
|
|
249
|
+
export function boundariesPreserveIdentity(
|
|
250
|
+
input: readonly DagSpan[],
|
|
251
|
+
boundaries: readonly CrystalBoundaryV1[],
|
|
252
|
+
): boolean {
|
|
253
|
+
const flat: DagSpan[] = [];
|
|
254
|
+
for (const b of boundaries) flat.push(...b.ranges);
|
|
255
|
+
const canonical = sortSpans(input);
|
|
256
|
+
if (flat.length !== canonical.length) return false;
|
|
257
|
+
for (let i = 0; i < flat.length; i += 1) {
|
|
258
|
+
const a = flat[i];
|
|
259
|
+
const b = canonical[i];
|
|
260
|
+
if (a === undefined || b === undefined) return false;
|
|
261
|
+
if (compareSpans(a, b) !== 0) return false;
|
|
262
|
+
// compareSpans intentionally ignores the pinned digest (it orders by source
|
|
263
|
+
// position). Identity includes the covered bytes, so check it explicitly.
|
|
264
|
+
if (a.digest !== b.digest) return false;
|
|
265
|
+
}
|
|
266
|
+
return true;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
/**
|
|
270
|
+
* Compile the ranges of an existing crystal key. Returns the boundaries plus the
|
|
271
|
+
* UNCHANGED key: compilation is an optimization of how the render is segmented,
|
|
272
|
+
* never a re-keying. Returning the same key object makes that explicit at the
|
|
273
|
+
* call site — a caller cannot accidentally pick up a "compiled key" that differs.
|
|
274
|
+
*/
|
|
275
|
+
export function compileForKey(
|
|
276
|
+
key: CrystalKeyV1,
|
|
277
|
+
limits: CompilerLimits = DEFAULT_COMPILER_LIMITS,
|
|
278
|
+
): { readonly key: CrystalKeyV1; readonly compiled: CompileResult } {
|
|
279
|
+
return { key, compiled: compileCrystalBoundaries(key.sourceRanges, limits) };
|
|
280
|
+
}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* vector-cortex/cache/economics-emit.ts — VC7B event reporter seam.
|
|
3
|
+
*
|
|
4
|
+
* Mirrors `./crystal-emit.ts`: a thin `safe()` wrapper around an optional
|
|
5
|
+
* injected `emit` (unit tests pass `undefined` and stay pure), and the two event
|
|
6
|
+
* names the sprint spec requires verbatim:
|
|
7
|
+
* - `vector_cortex_cache_experiment_assigned` — a session entered an arm.
|
|
8
|
+
* - `vector_cortex_cache_economics_estimated` — net savings were computed.
|
|
9
|
+
*
|
|
10
|
+
* FLAG SEMANTICS. `computeEconomics`, `compileCrystalBoundaries` and
|
|
11
|
+
* `assignExperiment` are PURE and run REGARDLESS of `MEGACOMPACT_VC7B`. The flag
|
|
12
|
+
* gates ONLY this reporting + dashboard seam: with the flag off a session still
|
|
13
|
+
* hashes to the SAME arm, the compiler still produces the SAME boundaries, and
|
|
14
|
+
* the same net savings are still computed — we just do not announce them under
|
|
15
|
+
* the VC7B event namespace, and the dashboard reports `enabled:false` + mode C.
|
|
16
|
+
* That is what makes flag-off byte-identical to VC7A: the arithmetic is never
|
|
17
|
+
* skipped, only the emission.
|
|
18
|
+
*
|
|
19
|
+
* PAYLOAD DISCIPLINE. These events carry the ARM, the BUCKET, integer money
|
|
20
|
+
* AGGREGATES, and the evidence label — never a session id, never covered ranges,
|
|
21
|
+
* never frozen bytes, never a request or covered digest. A session id here would
|
|
22
|
+
* re-identify a user's conversation in a log file, and the bucket already carries
|
|
23
|
+
* everything needed to audit the split (SECURITY_PRIVACY — the exact ledger is
|
|
24
|
+
* not diagnostic data). The `evidence` label travels WITH every economics event
|
|
25
|
+
* so a downstream aggregator can never mistake a shadow estimate for a measured,
|
|
26
|
+
* randomized result.
|
|
27
|
+
*
|
|
28
|
+
* No console, no storage, no network (PREVENT-PI-004 / PREVENT-011). Every line
|
|
29
|
+
* is a structured JSON event with `ts` + `event`.
|
|
30
|
+
*/
|
|
31
|
+
|
|
32
|
+
import { VC7B_ENABLED } from "../../config/vector-cortex.js";
|
|
33
|
+
import type { EconomicsEvidence } from "../provider/economics.js";
|
|
34
|
+
import type { AssignmentSource, ExperimentArm } from "../provider/experiments.js";
|
|
35
|
+
|
|
36
|
+
/** The two structured events the VC7B reporter emits. */
|
|
37
|
+
export type EconomicsEventName =
|
|
38
|
+
| "vector_cortex_cache_experiment_assigned"
|
|
39
|
+
| "vector_cortex_cache_economics_estimated";
|
|
40
|
+
|
|
41
|
+
/** Optional emit fn injected by the runtime; tests pass `undefined`. */
|
|
42
|
+
export type EconomicsEmit = (name: string, payload: unknown) => void;
|
|
43
|
+
|
|
44
|
+
/** Run `fn` only when an emit exists; a reporting failure is never fatal. */
|
|
45
|
+
function safe(emit: EconomicsEmit | undefined, fn: (emit: EconomicsEmit) => void): void {
|
|
46
|
+
if (emit === undefined) return;
|
|
47
|
+
try {
|
|
48
|
+
fn(emit);
|
|
49
|
+
} catch {
|
|
50
|
+
// Non-fatal: a reporting failure must never break the agent loop.
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** The event names VC7B emits, exported for the dashboard seam and tests. */
|
|
55
|
+
export const ECONOMICS_EVENT_NAMES: readonly EconomicsEventName[] = [
|
|
56
|
+
"vector_cortex_cache_experiment_assigned",
|
|
57
|
+
"vector_cortex_cache_economics_estimated",
|
|
58
|
+
] as const;
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Report a session's experiment assignment.
|
|
62
|
+
*
|
|
63
|
+
* Arm + bucket + source only. The bucket is sufficient to audit that the split
|
|
64
|
+
* is being honored; the SESSION ID is deliberately absent so the event log
|
|
65
|
+
* cannot be used to reconstruct who was in which arm.
|
|
66
|
+
*/
|
|
67
|
+
export function reportCacheExperimentAssigned(
|
|
68
|
+
emit: EconomicsEmit | undefined,
|
|
69
|
+
payload: {
|
|
70
|
+
readonly experimentId: string;
|
|
71
|
+
readonly arm: ExperimentArm;
|
|
72
|
+
readonly bucket: number;
|
|
73
|
+
readonly source: AssignmentSource;
|
|
74
|
+
},
|
|
75
|
+
): void {
|
|
76
|
+
if (!VC7B_ENABLED()) return;
|
|
77
|
+
safe(emit, (e) =>
|
|
78
|
+
e("vector_cortex_cache_experiment_assigned", {
|
|
79
|
+
ts: undefined,
|
|
80
|
+
event: "vector_cortex_cache_experiment_assigned",
|
|
81
|
+
experimentId: payload.experimentId,
|
|
82
|
+
arm: payload.arm,
|
|
83
|
+
bucket: payload.bucket,
|
|
84
|
+
source: payload.source,
|
|
85
|
+
}),
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Report computed cache economics.
|
|
91
|
+
*
|
|
92
|
+
* Integer micro-unit aggregates plus the evidence label. `netSavings` may be
|
|
93
|
+
* NEGATIVE and is reported as such — a cache that lost money is the outcome this
|
|
94
|
+
* telemetry exists to surface, so it is never clamped on the way out.
|
|
95
|
+
*/
|
|
96
|
+
export function reportCacheEconomicsEstimated(
|
|
97
|
+
emit: EconomicsEmit | undefined,
|
|
98
|
+
payload: {
|
|
99
|
+
readonly profileId: string;
|
|
100
|
+
readonly netSavings: number;
|
|
101
|
+
readonly tokenSavings: number;
|
|
102
|
+
readonly evidence: EconomicsEvidence;
|
|
103
|
+
},
|
|
104
|
+
): void {
|
|
105
|
+
if (!VC7B_ENABLED()) return;
|
|
106
|
+
safe(emit, (e) =>
|
|
107
|
+
e("vector_cortex_cache_economics_estimated", {
|
|
108
|
+
ts: undefined,
|
|
109
|
+
event: "vector_cortex_cache_economics_estimated",
|
|
110
|
+
profileId: payload.profileId,
|
|
111
|
+
netSavings: payload.netSavings,
|
|
112
|
+
tokenSavings: payload.tokenSavings,
|
|
113
|
+
evidence: payload.evidence,
|
|
114
|
+
}),
|
|
115
|
+
);
|
|
116
|
+
}
|
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* vector-cortex/migrations/request-hash-v2.ts — M5 request-hash-v2, COPY +
|
|
3
|
+
* VALIDATE ONLY (VC7B). The switch lands in VC7C.
|
|
4
|
+
*
|
|
5
|
+
* M5 versions the canonical request hash: the predecessor hashed the outbound
|
|
6
|
+
* request under the v1 scheme; v2 folds in the provider profile's ECONOMICS
|
|
7
|
+
* version so a pricing/TTL/exclusion change cannot silently reuse a cache
|
|
8
|
+
* identity minted under different economics. Like M4/M6 it follows the
|
|
9
|
+
* copy/validate/switch contract — but VC7B deliberately stops after validate:
|
|
10
|
+
*
|
|
11
|
+
* - copy: resumable per (profile, request) — an interrupted run resumes
|
|
12
|
+
* without duplicate rows or active-pointer drift.
|
|
13
|
+
* - validate: every v1 row has exactly one v2 row, every v2 digest re-hashes
|
|
14
|
+
* from its own declared fields, and — the M5-specific invariant —
|
|
15
|
+
* the migration is IDENTITY-PRESERVING: a v2 row must carry the
|
|
16
|
+
* same `requestDigest` as the v1 row it came from. v2 changes how
|
|
17
|
+
* a CACHE KEY is derived, never what the request IS. A row whose
|
|
18
|
+
* request digest drifted is rejected (`M5_IDENTITY_DRIFT`).
|
|
19
|
+
* - switch: NOT IMPLEMENTED IN VC7B. `m5Switch` exists so the shape of the
|
|
20
|
+
* lifecycle is reviewable, but it always refuses with
|
|
21
|
+
* `M5_SWITCH_DEFERRED` and leaves the active pointer on v1.
|
|
22
|
+
*
|
|
23
|
+
* WHY THE SWITCH IS WITHHELD. Flipping the request-hash version invalidates
|
|
24
|
+
* every crystal minted under v1 in one step. VC7C first runs the shadow
|
|
25
|
+
* comparison (v1 vs v2 digests over live traffic) so the blast radius is
|
|
26
|
+
* measured before it is taken. Shipping the switch here would mean flipping it
|
|
27
|
+
* on evidence that does not exist yet — so the function is present, refuses, and
|
|
28
|
+
* says why, rather than being a TODO comment someone later mistakes for done.
|
|
29
|
+
* Old-binary protocol: a reader that predates v2 keeps reading v1 rows, which
|
|
30
|
+
* remain untouched and authoritative for the whole of VC7B.
|
|
31
|
+
*
|
|
32
|
+
* Pure logic over an injected M5Host (deterministic + testable; no console).
|
|
33
|
+
* PREVENT-002/011/PI-004 honored.
|
|
34
|
+
*/
|
|
35
|
+
|
|
36
|
+
import { createHash } from "node:crypto";
|
|
37
|
+
|
|
38
|
+
/** The active-version value the v2 pointer will be switched to — in VC7C. */
|
|
39
|
+
export const REQUEST_HASH_V2_VERSION = 2;
|
|
40
|
+
/** The legacy (predecessor) active version; VC7B never leaves this. */
|
|
41
|
+
export const REQUEST_HASH_LEGACY_VERSION = 1;
|
|
42
|
+
|
|
43
|
+
/** M5 failure codes. */
|
|
44
|
+
export const M5_FAIL = {
|
|
45
|
+
COPY_PARTIAL: "M5_COPY_PARTIAL",
|
|
46
|
+
COUNT_MISMATCH: "M5_COUNT_MISMATCH",
|
|
47
|
+
DIGEST_MISMATCH: "M5_DIGEST_MISMATCH",
|
|
48
|
+
IDENTITY_DRIFT: "M5_IDENTITY_DRIFT",
|
|
49
|
+
SWITCH_DEFERRED: "M5_SWITCH_DEFERRED",
|
|
50
|
+
} as const;
|
|
51
|
+
export type M5MigrationCode = (typeof M5_FAIL)[keyof typeof M5_FAIL];
|
|
52
|
+
|
|
53
|
+
/** A predecessor (v1) request-hash row. */
|
|
54
|
+
export interface RequestHashV1Row {
|
|
55
|
+
readonly profileId: string;
|
|
56
|
+
/** BARE lowercase hex canonical request digest (VC5B convention). */
|
|
57
|
+
readonly requestDigest: string;
|
|
58
|
+
/** The v1 cache-identity hash derived from the request. */
|
|
59
|
+
readonly hash: string;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* A v2 request-hash row. Identity is `(profileId, requestDigest)` — unchanged
|
|
64
|
+
* from v1, which is the point: only `hash` is re-derived, now folding in the
|
|
65
|
+
* economics version.
|
|
66
|
+
*/
|
|
67
|
+
export interface RequestHashV2Row {
|
|
68
|
+
readonly profileId: string;
|
|
69
|
+
readonly requestDigest: string;
|
|
70
|
+
/** Economics version folded into the v2 hash (absent in v1). */
|
|
71
|
+
readonly economicsVersion: string;
|
|
72
|
+
/** The v2 cache-identity hash. */
|
|
73
|
+
readonly hash: string;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** The host the migration reads from / writes to (capability-shaped). */
|
|
77
|
+
export interface M5Host {
|
|
78
|
+
/** Every predecessor row being migrated. */
|
|
79
|
+
readonly v1Rows: () => readonly RequestHashV1Row[];
|
|
80
|
+
/** The economics version to fold in, per profile. */
|
|
81
|
+
readonly economicsVersionOf: (profileId: string) => string;
|
|
82
|
+
/** Persisted v2 rows already written (for resume). */
|
|
83
|
+
readonly existingV2: () => readonly RequestHashV2Row[];
|
|
84
|
+
/** Idempotent write of v2 rows (never mutates v1 rows). */
|
|
85
|
+
readonly putV2: (rows: readonly RequestHashV2Row[]) => void;
|
|
86
|
+
/** The currently ACTIVE version (1 = legacy; VC7B never changes it). */
|
|
87
|
+
readonly activeVersion: () => number;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/** An M5 validation result. */
|
|
91
|
+
export interface M5ValidateResult {
|
|
92
|
+
readonly ok: boolean;
|
|
93
|
+
readonly codes: readonly M5MigrationCode[];
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/** Length-prefixed framing so the folded fields cannot alias. */
|
|
97
|
+
function field(value: string): string {
|
|
98
|
+
return `${Buffer.byteLength(value, "utf8")}:${value}`;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* The authoritative v2 hash: SHA-256 over the version tag, profile, request
|
|
103
|
+
* digest, and economics version. Length-prefixed for injectivity, exactly as the
|
|
104
|
+
* crystal key encoder frames its fields.
|
|
105
|
+
*/
|
|
106
|
+
export function deriveRequestHashV2(
|
|
107
|
+
profileId: string,
|
|
108
|
+
requestDigest: string,
|
|
109
|
+
economicsVersion: string,
|
|
110
|
+
): string {
|
|
111
|
+
return createHash("sha256")
|
|
112
|
+
.update(
|
|
113
|
+
field("request-hash-v2") + field(profileId) + field(requestDigest) + field(economicsVersion),
|
|
114
|
+
"utf8",
|
|
115
|
+
)
|
|
116
|
+
.digest("hex");
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/** Derive the v2 row for one v1 row. */
|
|
120
|
+
export function deriveRequestHashRow(host: M5Host, v1: RequestHashV1Row): RequestHashV2Row {
|
|
121
|
+
const economicsVersion = host.economicsVersionOf(v1.profileId);
|
|
122
|
+
return {
|
|
123
|
+
profileId: v1.profileId,
|
|
124
|
+
// IDENTITY-PRESERVING: carried through verbatim, never re-derived.
|
|
125
|
+
requestDigest: v1.requestDigest,
|
|
126
|
+
economicsVersion,
|
|
127
|
+
hash: deriveRequestHashV2(v1.profileId, v1.requestDigest, economicsVersion),
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
const identity = (profileId: string, requestDigest: string): string =>
|
|
132
|
+
`${profileId}::${requestDigest}`;
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Copy every v1 row into a v2 row BESIDE it (resumable, idempotent). Rows already
|
|
136
|
+
* persisted with a matching derivation are left untouched; absent or stale rows
|
|
137
|
+
* are (re)written from the authoritative derivation. The active pointer is never
|
|
138
|
+
* touched — v1 remains authoritative throughout VC7B.
|
|
139
|
+
*/
|
|
140
|
+
export function m5Copy(host: M5Host): {
|
|
141
|
+
readonly written: readonly RequestHashV2Row[];
|
|
142
|
+
readonly all: readonly RequestHashV2Row[];
|
|
143
|
+
} {
|
|
144
|
+
const existing = new Map(host.existingV2().map((r) => [identity(r.profileId, r.requestDigest), r]));
|
|
145
|
+
const wanted: RequestHashV2Row[] = [];
|
|
146
|
+
for (const v1 of host.v1Rows()) {
|
|
147
|
+
const fresh = deriveRequestHashRow(host, v1);
|
|
148
|
+
const stored = existing.get(identity(v1.profileId, v1.requestDigest));
|
|
149
|
+
if (
|
|
150
|
+
stored !== undefined &&
|
|
151
|
+
stored.hash === fresh.hash &&
|
|
152
|
+
stored.economicsVersion === fresh.economicsVersion
|
|
153
|
+
) {
|
|
154
|
+
continue; // healthy, already copied
|
|
155
|
+
}
|
|
156
|
+
wanted.push(fresh);
|
|
157
|
+
}
|
|
158
|
+
if (wanted.length > 0) host.putV2(wanted);
|
|
159
|
+
return { written: wanted, all: [...host.existingV2()] };
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* Validate the copied set: exactly one v2 row per v1 row, every v2 hash
|
|
164
|
+
* re-derives from its own declared fields, no orphan v2 rows, and every v2 row's
|
|
165
|
+
* request digest equals its v1 source's (identity preservation). Never mutates.
|
|
166
|
+
*/
|
|
167
|
+
export function m5Verify(host: M5Host): M5ValidateResult {
|
|
168
|
+
const codes: M5MigrationCode[] = [];
|
|
169
|
+
const stored = host.existingV2();
|
|
170
|
+
const v1Rows = host.v1Rows();
|
|
171
|
+
|
|
172
|
+
const counts = new Map<string, number>();
|
|
173
|
+
for (const r of stored) {
|
|
174
|
+
const id = identity(r.profileId, r.requestDigest);
|
|
175
|
+
counts.set(id, (counts.get(id) ?? 0) + 1);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
const expected = new Set<string>();
|
|
179
|
+
for (const v1 of v1Rows) {
|
|
180
|
+
const id = identity(v1.profileId, v1.requestDigest);
|
|
181
|
+
expected.add(id);
|
|
182
|
+
const n = counts.get(id) ?? 0;
|
|
183
|
+
if (n === 0) codes.push(M5_FAIL.COPY_PARTIAL);
|
|
184
|
+
if (n > 1) codes.push(M5_FAIL.COUNT_MISMATCH);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
// Every v1 request digest that must survive the migration unchanged.
|
|
188
|
+
const v1Digests = new Set(v1Rows.map((r) => identity(r.profileId, r.requestDigest)));
|
|
189
|
+
for (const r of stored) {
|
|
190
|
+
const fresh = deriveRequestHashV2(r.profileId, r.requestDigest, r.economicsVersion);
|
|
191
|
+
if (r.hash !== fresh) codes.push(M5_FAIL.DIGEST_MISMATCH);
|
|
192
|
+
const id = identity(r.profileId, r.requestDigest);
|
|
193
|
+
// A v2 row whose identity has no v1 source either drifted or is an orphan.
|
|
194
|
+
if (!v1Digests.has(id)) {
|
|
195
|
+
codes.push(expected.size > 0 ? M5_FAIL.IDENTITY_DRIFT : M5_FAIL.COUNT_MISMATCH);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
return { ok: codes.length === 0, codes: dedupe(codes) };
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* The switch — DEFERRED TO VC7C BY DESIGN.
|
|
204
|
+
*
|
|
205
|
+
* Always refuses and always leaves the active pointer on v1. It exists so the
|
|
206
|
+
* lifecycle is complete and reviewable, and so a caller that tries to switch
|
|
207
|
+
* early gets an explicit `M5_SWITCH_DEFERRED` instead of silence.
|
|
208
|
+
*/
|
|
209
|
+
export function m5Switch(host: M5Host): M5ValidateResult {
|
|
210
|
+
void host;
|
|
211
|
+
return { ok: false, codes: [M5_FAIL.SWITCH_DEFERRED] };
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
* The VC7B M5 lifecycle: copy -> verify. NO SWITCH. Returns the verify result;
|
|
216
|
+
* the active version pointer is guaranteed to still be
|
|
217
|
+
* `REQUEST_HASH_LEGACY_VERSION` on return.
|
|
218
|
+
*/
|
|
219
|
+
export function migrateRequestHashV2CopyValidate(host: M5Host): M5ValidateResult {
|
|
220
|
+
m5Copy(host);
|
|
221
|
+
return m5Verify(host);
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
function dedupe(codes: readonly M5MigrationCode[]): M5MigrationCode[] {
|
|
225
|
+
const out: M5MigrationCode[] = [];
|
|
226
|
+
for (const c of codes) if (!out.includes(c)) out.push(c);
|
|
227
|
+
return out;
|
|
228
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* vector-cortex/provider/economics-ids.ts — VC7B conformance ID registrations.
|
|
3
|
+
*
|
|
4
|
+
* Extracted from economics.ts to keep that file under the 300-line soft limit
|
|
5
|
+
* (soft-as-hard gate). The ID ranges and named rows are pure data — splitting
|
|
6
|
+
* them out mirrors how vector-cortex-breakers.ts was extracted from
|
|
7
|
+
* vector-cortex.ts. economics.ts re-exports them so no consumer import path
|
|
8
|
+
* changes.
|
|
9
|
+
*
|
|
10
|
+
* Pi-agnostic, dependency-free (PREVENT-PI-004 / PREVENT-011).
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Registered VC7B cache-economics conformance ID range (CACHE-001..015). The
|
|
15
|
+
* acceptance aggregator reads these rows from the v2 manifest and asserts each
|
|
16
|
+
* returns its manifest `ok`/`code`.
|
|
17
|
+
*/
|
|
18
|
+
export const CACHE_IDS: readonly string[] = Array.from(
|
|
19
|
+
{ length: 15 },
|
|
20
|
+
(_v, i) => `CACHE-${String(i + 1).padStart(3, "0")}`,
|
|
21
|
+
);
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Registered VC7B provider-economics conformance rows (PRO-024..030), continuing
|
|
25
|
+
* VC7A's PRO-016..023. These pin the ECONOMICS half of a provider profile:
|
|
26
|
+
* pricing validity, the exclusion-proof rule, and TTL/min-prefix eligibility.
|
|
27
|
+
*/
|
|
28
|
+
export const ECONOMICS_PROVIDER_IDS: readonly string[] = Array.from(
|
|
29
|
+
{ length: 7 },
|
|
30
|
+
(_v, i) => `PRO-${String(i + 24).padStart(3, "0")}`,
|
|
31
|
+
);
|
|
32
|
+
|
|
33
|
+
/** Named VC7B conformance assertions (the sprint's headline rows). */
|
|
34
|
+
export const ECONOMICS_NAMED_IDS = [
|
|
35
|
+
"CACHE-COST-001",
|
|
36
|
+
"CACHE-EXCLUDE-002",
|
|
37
|
+
"CACHE-RANDOM-003",
|
|
38
|
+
] as const;
|