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.
Files changed (95) hide show
  1. package/dist/config/vector-cortex-early.js +89 -0
  2. package/dist/config/vector-cortex-flag.js +25 -0
  3. package/dist/config/vector-cortex.js +23 -83
  4. package/dist/config.js +1 -1
  5. package/dist/extensions/dashboard-server/api-contracts/vector-cortex-economics.js +20 -0
  6. package/dist/extensions/dashboard-server/route-dispatch.js +6 -0
  7. package/dist/extensions/dashboard-server/routes-rag-settings-vector-cortex.js +1 -0
  8. package/dist/extensions/dashboard-server/routes-vector-cortex-economics.js +59 -0
  9. package/dist/src/config/vector-cortex-early.js +89 -0
  10. package/dist/src/config/vector-cortex-flag.js +25 -0
  11. package/dist/src/config/vector-cortex.js +23 -83
  12. package/dist/src/config.js +1 -1
  13. package/dist/src/vector-cortex/cache/_economics-fixture.js +41 -0
  14. package/dist/src/vector-cortex/cache/compiler.js +201 -0
  15. package/dist/src/vector-cortex/cache/economics-emit.js +85 -0
  16. package/dist/src/vector-cortex/migrations/request-hash-v2.js +161 -0
  17. package/dist/src/vector-cortex/provider/economics-ids.js +29 -0
  18. package/dist/src/vector-cortex/provider/economics.js +176 -0
  19. package/dist/src/vector-cortex/provider/experiments.js +166 -0
  20. package/dist/vector-cortex/cache/_economics-fixture.js +41 -0
  21. package/dist/vector-cortex/cache/compiler.js +201 -0
  22. package/dist/vector-cortex/cache/economics-emit.js +85 -0
  23. package/dist/vector-cortex/migrations/request-hash-v2.js +161 -0
  24. package/dist/vector-cortex/provider/economics-ids.js +29 -0
  25. package/dist/vector-cortex/provider/economics.js +176 -0
  26. package/dist/vector-cortex/provider/experiments.js +166 -0
  27. package/extensions/dashboard-client/dist/assets/{AreaChart-CB-U7ViX.js → AreaChart-VUd_iOtO.js} +2 -2
  28. package/extensions/dashboard-client/dist/assets/{AreaChart-CB-U7ViX.js.map → AreaChart-VUd_iOtO.js.map} +1 -1
  29. package/extensions/dashboard-client/dist/assets/{BarChart-DnLw0fxA.js → BarChart-BoqeJ5mM.js} +2 -2
  30. package/extensions/dashboard-client/dist/assets/{BarChart-DnLw0fxA.js.map → BarChart-BoqeJ5mM.js.map} +1 -1
  31. package/extensions/dashboard-client/dist/assets/{CacheTab-CjyTVDiP.js → CacheTab-1ON7meDK.js} +2 -2
  32. package/extensions/dashboard-client/dist/assets/{CacheTab-CjyTVDiP.js.map → CacheTab-1ON7meDK.js.map} +1 -1
  33. package/extensions/dashboard-client/dist/assets/{EventsTab-Bz3QEWam.js → EventsTab-Dr9eqt1k.js} +2 -2
  34. package/extensions/dashboard-client/dist/assets/{EventsTab-Bz3QEWam.js.map → EventsTab-Dr9eqt1k.js.map} +1 -1
  35. package/extensions/dashboard-client/dist/assets/{HealthTab-CUylEvEY.js → HealthTab-Ciaigd4i.js} +2 -2
  36. package/extensions/dashboard-client/dist/assets/{HealthTab-CUylEvEY.js.map → HealthTab-Ciaigd4i.js.map} +1 -1
  37. package/extensions/dashboard-client/dist/assets/{MaintenanceTab-Cz_hj_E7.js → MaintenanceTab-DjZRr3Lf.js} +2 -2
  38. package/extensions/dashboard-client/dist/assets/{MaintenanceTab-Cz_hj_E7.js.map → MaintenanceTab-DjZRr3Lf.js.map} +1 -1
  39. package/extensions/dashboard-client/dist/assets/{MemoryMapTab-Dh8brIR1.js → MemoryMapTab-BpZXHA7j.js} +2 -2
  40. package/extensions/dashboard-client/dist/assets/{MemoryMapTab-Dh8brIR1.js.map → MemoryMapTab-BpZXHA7j.js.map} +1 -1
  41. package/extensions/dashboard-client/dist/assets/{MetricsTab-CkqSXc6e.js → MetricsTab-QemocY5k.js} +2 -2
  42. package/extensions/dashboard-client/dist/assets/{MetricsTab-CkqSXc6e.js.map → MetricsTab-QemocY5k.js.map} +1 -1
  43. package/extensions/dashboard-client/dist/assets/{OverviewTab-DGbJcx6d.js → OverviewTab-VtC1F-mO.js} +2 -2
  44. package/extensions/dashboard-client/dist/assets/{OverviewTab-DGbJcx6d.js.map → OverviewTab-VtC1F-mO.js.map} +1 -1
  45. package/extensions/dashboard-client/dist/assets/{ReposTab-BawS3nfF.js → ReposTab-CJD1cBxp.js} +2 -2
  46. package/extensions/dashboard-client/dist/assets/{ReposTab-BawS3nfF.js.map → ReposTab-CJD1cBxp.js.map} +1 -1
  47. package/extensions/dashboard-client/dist/assets/{SessionsTab-CUVnmYks.js → SessionsTab-Cj0erPR4.js} +2 -2
  48. package/extensions/dashboard-client/dist/assets/{SessionsTab-CUVnmYks.js.map → SessionsTab-Cj0erPR4.js.map} +1 -1
  49. package/extensions/dashboard-client/dist/assets/{SetupTab-cxTuyZNk.js → SetupTab-AOVROZ4G.js} +2 -2
  50. package/extensions/dashboard-client/dist/assets/{SetupTab-cxTuyZNk.js.map → SetupTab-AOVROZ4G.js.map} +1 -1
  51. package/extensions/dashboard-client/dist/assets/{TimeSavedCard-Cv5SENkE.js → TimeSavedCard-ZliVn8DH.js} +2 -2
  52. package/extensions/dashboard-client/dist/assets/{TimeSavedCard-Cv5SENkE.js.map → TimeSavedCard-ZliVn8DH.js.map} +1 -1
  53. package/extensions/dashboard-client/dist/assets/{TurnsTab-yl6BBG_F.js → TurnsTab-DsoTWeIh.js} +2 -2
  54. package/extensions/dashboard-client/dist/assets/{TurnsTab-yl6BBG_F.js.map → TurnsTab-DsoTWeIh.js.map} +1 -1
  55. package/extensions/dashboard-client/dist/assets/VectorCortexTab-BBa7rp6C.js +2 -0
  56. package/extensions/dashboard-client/dist/assets/VectorCortexTab-BBa7rp6C.js.map +1 -0
  57. package/extensions/dashboard-client/dist/assets/{WikiTab-DKv-0xCQ.js → WikiTab-CK8fcW1l.js} +2 -2
  58. package/extensions/dashboard-client/dist/assets/{WikiTab-DKv-0xCQ.js.map → WikiTab-CK8fcW1l.js.map} +1 -1
  59. package/extensions/dashboard-client/dist/assets/{button-CVPrO4UU.js → button-DdPcvex1.js} +2 -2
  60. package/extensions/dashboard-client/dist/assets/{button-CVPrO4UU.js.map → button-DdPcvex1.js.map} +1 -1
  61. package/extensions/dashboard-client/dist/assets/{card-BFLnQJEo.js → card-DXFuZph_.js} +2 -2
  62. package/extensions/dashboard-client/dist/assets/{card-BFLnQJEo.js.map → card-DXFuZph_.js.map} +1 -1
  63. package/extensions/dashboard-client/dist/assets/{generateCategoricalChart-B-IUoLd1.js → generateCategoricalChart-BagDVGWn.js} +2 -2
  64. package/extensions/dashboard-client/dist/assets/{generateCategoricalChart-B-IUoLd1.js.map → generateCategoricalChart-BagDVGWn.js.map} +1 -1
  65. package/extensions/dashboard-client/dist/assets/{index-Do749WlW.js → index-DVdDtRY4.js} +3 -3
  66. package/extensions/dashboard-client/dist/assets/{index-Do749WlW.js.map → index-DVdDtRY4.js.map} +1 -1
  67. package/extensions/dashboard-client/dist/assets/{switch-3uFnZmtq.js → switch-CtdtGyUR.js} +2 -2
  68. package/extensions/dashboard-client/dist/assets/{switch-3uFnZmtq.js.map → switch-CtdtGyUR.js.map} +1 -1
  69. package/extensions/dashboard-client/dist/assets/{toggle-C1rYLeXe.js → toggle-Cvvwlbye.js} +2 -2
  70. package/extensions/dashboard-client/dist/assets/{toggle-C1rYLeXe.js.map → toggle-Cvvwlbye.js.map} +1 -1
  71. package/extensions/dashboard-client/dist/assets/{useSSE-D1qzLzgR.js → useSSE-DvlceHjV.js} +2 -2
  72. package/extensions/dashboard-client/dist/assets/{useSSE-D1qzLzgR.js.map → useSSE-DvlceHjV.js.map} +1 -1
  73. package/extensions/dashboard-client/dist/index.html +1 -1
  74. package/extensions/dashboard-client/src/api/vector-cortex.ts +9 -0
  75. package/extensions/dashboard-client/src/tabs/VectorCortexEconomicsCard.tsx +41 -0
  76. package/extensions/dashboard-client/src/tabs/VectorCortexTab.tsx +8 -0
  77. package/extensions/dashboard-client/src/types/vector-cortex.ts +14 -0
  78. package/extensions/dashboard-server/api-contracts/vector-cortex-economics.ts +47 -0
  79. package/extensions/dashboard-server/route-dispatch.ts +5 -0
  80. package/extensions/dashboard-server/routes-rag-settings-vector-cortex.ts +6 -0
  81. package/extensions/dashboard-server/routes-vector-cortex-economics.ts +68 -0
  82. package/package.json +1 -1
  83. package/src/config/vector-cortex-early.ts +99 -0
  84. package/src/config/vector-cortex-flag.ts +24 -0
  85. package/src/config/vector-cortex.ts +34 -89
  86. package/src/config.ts +1 -0
  87. package/src/vector-cortex/cache/_economics-fixture.ts +128 -0
  88. package/src/vector-cortex/cache/compiler.ts +280 -0
  89. package/src/vector-cortex/cache/economics-emit.ts +116 -0
  90. package/src/vector-cortex/migrations/request-hash-v2.ts +228 -0
  91. package/src/vector-cortex/provider/economics-ids.ts +38 -0
  92. package/src/vector-cortex/provider/economics.ts +289 -0
  93. package/src/vector-cortex/provider/experiments.ts +248 -0
  94. package/extensions/dashboard-client/dist/assets/VectorCortexTab-94fqVjat.js +0 -2
  95. package/extensions/dashboard-client/dist/assets/VectorCortexTab-94fqVjat.js.map +0 -1
@@ -64,6 +64,10 @@ import { handleVectorCortexRepair } from "./routes-vector-cortex-repair.js";
64
64
  // stays independent of the heal/repair handlers and every file stays well under
65
65
  // the 400-line extension limit.
66
66
  import { handleVectorCortexCrystals } from "./routes-vector-cortex-crystals.js";
67
+ // VC7B cache economics likewise get their own module so the economics seam stays
68
+ // independent of the crystals handler and every file stays well under the
69
+ // 400-line extension soft limit.
70
+ import { handleVectorCortexEconomics } from "./routes-vector-cortex-economics.js";
67
71
 
68
72
  /**
69
73
  * Dispatch a request through every registered route handler.
@@ -119,5 +123,6 @@ export function dispatchRoutes(
119
123
  if (handleVectorCortexRestore(req, res, ctx)) return true;
120
124
  if (handleVectorCortexRepair(req, res, ctx)) return true;
121
125
  if (handleVectorCortexCrystals(req, res, ctx)) return true;
126
+ if (handleVectorCortexEconomics(req, res, ctx)) return true;
122
127
  return false;
123
128
  }
@@ -162,5 +162,11 @@ export const VECTOR_CORTEX_SETTINGS: SettingGroup = {
162
162
  "Frozen range crystals: caches a rendered prompt under an IMMUTABLE key built from the source ranges it covers, the digest of those covered bytes, the validated durable dependency high-water, and the renderer + provider profile — and deliberately NOT the global ledger frontier, so an unrelated append leaves the key unchanged instead of invalidating every crystal on every turn. Any covered-byte, dependency, renderer, or profile change invalidates 100%. Ranges are sorted by source start and overlapping ranges are rejected (CRY_RANGE_OVERLAP) rather than merged. The store is content-addressed and write-once: identical bytes re-written are idempotent, but a same-key/different-bytes write returns CRY_KEY_COLLISION and never overwrites, surfacing renderer non-determinism instead of hiding it. A store hit is mode A, a miss/collision forces a fresh deterministic render (mode B), and an unavailable store bypasses the cache entirely (mode C). OFF = byte-identical predecessor (VC6C); the crystal/store arithmetic still runs, only the reporter + dashboard seam is suppressed.",
163
163
  true,
164
164
  ),
165
+ boolDirect(
166
+ "MEGACOMPACT_VC7B",
167
+ "VC7B Provider Cache Economics",
168
+ "Provider cache economics: extends the VC5B provider registry with cache economics (read/write price, TTL, minimum prefix, and a mandatory exclusion fixture id). Answers whether reusing a frozen crystal is actually worth it — a cache WRITE typically costs more than an uncached token, so a cache only pays off once a written prefix is re-read enough times before TTL expiry. Net savings are reported (never clamped at zero, so a losing cache stays visible) and every exclusion MUST name a proving conformance fixture or it is rejected (ECON_EXCLUSION_UNPROVEN). A compiled crystal boundary still reuses the VC7A key unchanged, and a randomized session-level experiment assigns arms by a stable hash so a lost assignment journal re-derives the same arm. OFF = byte-identical predecessor (VC7A); the economics/compiler/experiment arithmetic still runs, only the reporter + dashboard seam is suppressed.",
169
+ true,
170
+ ),
165
171
  ],
166
172
  };
@@ -0,0 +1,68 @@
1
+ /**
2
+ * dashboard-server/routes-vector-cortex-economics.ts — VC7B cache-economics
3
+ * dashboard route.
4
+ *
5
+ * Reader-only GET /api/vector-cortex/cache-economics returning the cache-
6
+ * economics aggregate diagnostics: whether the VC7B flag is enabled, the runtime
7
+ * triad mode, how many provider profiles carry economics, how many exclusions
8
+ * are proven vs unproven, and the last ECON_* failure code.
9
+ *
10
+ * COUNTS + CODES ONLY. Cache economics price a FROZEN RENDERED PROMPT's reuse,
11
+ * so a careless payload field would leak the frozen bytes, the covered ranges,
12
+ * the span/covered digests, the request digests, or session ids that identify
13
+ * the framed conversation. This route NEVER exposes frozen bytes, ranges,
14
+ * digests, session ids, or request digests — only aggregate counts and the
15
+ * observable ECON_* outcome code (reader-only, SECURITY_PRIVACY). There is no
16
+ * mutation seam: economics are computed by the render path, never by a dashboard
17
+ * request. Non-GET is rejected outright.
18
+ *
19
+ * Split into its own file (rather than grown into routes-vector-cortex-crystals.ts)
20
+ * to keep every extensions/ file well under the 400-line soft-as-hard limit.
21
+ *
22
+ * Guardrails: PREVENT-PI-004 (local in-process state only), PREVENT-011 (no
23
+ * `any`), reader-only aggregate (counts + codes only).
24
+ */
25
+
26
+ import type { IncomingMessage, ServerResponse } from "node:http";
27
+ import type { RouteContext } from "./routes-core.js";
28
+ import { VC7B_ENABLED } from "../../src/config.js";
29
+ import { sendJson } from "./routes-vector-cortex-shared.js";
30
+ import type { VectorCortexEconomicsView } from "./api-contracts/vector-cortex-economics.js";
31
+
32
+ /**
33
+ * Reader-only GET /api/vector-cortex/cache-economics (VC7B).
34
+ *
35
+ * Counts, profile tallies, and ECON_* codes only — a static reader-only
36
+ * aggregate seam with the same shape as the VC7A crystals handler.
37
+ */
38
+ export function handleVectorCortexEconomics(
39
+ req: IncomingMessage,
40
+ res: ServerResponse,
41
+ _ctx: RouteContext,
42
+ ): boolean {
43
+ const url = req.url ?? "";
44
+ const path = url.split("?")[0] ?? url;
45
+ if (path !== "/api/vector-cortex/cache-economics") return false;
46
+ if (req.method !== "GET") {
47
+ sendJson(res, 405, { error: "method_not_allowed" });
48
+ return true;
49
+ }
50
+
51
+ const enabled = VC7B_ENABLED();
52
+ // Flag-off routes to mode C: with VC7B off no cache economics are served, which
53
+ // is exactly the spec's "economics bypass" outcome. Reporting A (cached render
54
+ // priced) or B (fresh render priced) would imply an economics path that is not
55
+ // wired at all. Mirrors how VC6C/VC7A OFF views report the mode they take.
56
+ const mode: "A" | "B" | "C" = enabled ? "A" : "C";
57
+ const body: VectorCortexEconomicsView = {
58
+ enabled,
59
+ mode,
60
+ profileCount: 0,
61
+ provenExclusions: 0,
62
+ unprovenExclusions: 0,
63
+ lastFailure: null,
64
+ updatedAt: new Date().toISOString(),
65
+ };
66
+ sendJson(res, 200, body);
67
+ return true;
68
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-mega-compact",
3
- "version": "0.20.13",
3
+ "version": "0.20.14",
4
4
  "description": "Layered, local, vector-backed context compressor for pi — supersede/collapse/cluster compaction with deduped inline recall.",
5
5
  "type": "module",
6
6
  "license": "BSD-3-Clause",
@@ -0,0 +1,99 @@
1
+ /**
2
+ * config/vector-cortex-early.ts — VC0/VC1/VC2 phase sprint flags.
3
+ *
4
+ * Extracted from vector-cortex.ts to keep that file under the 300-line soft
5
+ * limit (soft-as-hard gate), exactly as vector-cortex-breakers.ts was. These are
6
+ * the FOUNDATION-phase flags (observability, ledger, conformance, encoder); the
7
+ * VC3+ derived-state and prompt-path flags stay in vector-cortex.ts alongside
8
+ * the shared `sprintFlag` reader they are documented against.
9
+ *
10
+ * The split is purely mechanical: every flag below is byte-identical in name,
11
+ * semantics, and default to its previous definition, and vector-cortex.ts
12
+ * re-exports all of them so no consumer import path changes.
13
+ *
14
+ * Pi-agnostic, dependency-free (PREVENT-PI-004 / PREVENT-011).
15
+ */
16
+
17
+ import { sprintFlag } from "./vector-cortex-flag.js";
18
+
19
+ /** VC0A — baseline observability (MetricEventV1 / AnnotationV1). Default ON. */
20
+ export const VC0A_ENABLED = (): boolean => sprintFlag("MEGACOMPACT_VC0A");
21
+
22
+ /**
23
+ * VC0B — replay correctness (ReplayCutV2 / ReplayReportV2, M3 effective-cut-v2).
24
+ * Default ON. `MEGACOMPACT_VC0B=0` disables and is byte-identical to the
25
+ * predecessor (legacy capped-replay behavior preserved; the v2 cut/replay is
26
+ * only consulted on the vector-cortex path).
27
+ */
28
+ export const VC0B_ENABLED = (): boolean => sprintFlag("MEGACOMPACT_VC0B");
29
+
30
+ /**
31
+ * VC1A — canonical byte events (EventV2 / EventCodec).
32
+ * Default ON. `MEGACOMPACT_VC1A=0` disables and is byte-identical to the
33
+ * predecessor (mode C: ledger absent, current transcript codec unchanged).
34
+ * The single real consumer is the ledger emit seam (`ledger/emit.ts`): flag OFF
35
+ * gates zero observability writes.
36
+ */
37
+ export const VC1A_ENABLED = (): boolean => sprintFlag("MEGACOMPACT_VC1A");
38
+
39
+ /**
40
+ * VC1B — occurrence ledger + tool identity + compat journal (LedgerReader/
41
+ * Writer/Admin, CompatJournalV1, M2 occurrence-v2 migration).
42
+ * Default ON. `MEGACOMPACT_VC1B=0` disables and is byte-identical to the
43
+ * predecessor (mode C: the neutral occurrence ledger is not written, no
44
+ * journal rows, zero `vector_cortex_occurrence_appended` emissions). The real
45
+ * consumers are the ledger write integration seam and the compat-journal
46
+ * switch seam.
47
+ */
48
+ export const VC1B_ENABLED = (): boolean => sprintFlag("MEGACOMPACT_VC1B");
49
+
50
+ /**
51
+ * VC0C — live safety envelope (TriadResult / Breaker / KillDecision + durable
52
+ * spool). Default ON. `MEGACOMPACT_VC0C=0` disables and is byte-identical to
53
+ * the predecessor (mode C: selected before provider invocation, unchanged host
54
+ * transcript, breaker/spool idle and emitting nothing). The single real
55
+ * consumer is the resilience emit seam + the safety adapter's triad selection.
56
+ */
57
+ export const VC0C_ENABLED = (): boolean => sprintFlag("MEGACOMPACT_VC0C");
58
+
59
+ /**
60
+ * VC1C — cross-language conformance v2 (FixtureManifestV2 / DowngradeReport /
61
+ * MinHashV2 + M4 minhash-v2 migration).
62
+ * Default ON. `MEGACOMPACT_VC1C=0` disables and is byte-identical to the
63
+ * predecessor (mode C: a v2 conformance runner that accepts authority fixtures
64
+ * and the manifest validator idle; the sync dedup scan stays on the v1 path;
65
+ * zero `vector_cortex_*` VC1C emissions). The real consumers are the conformance
66
+ * emit seam, the minhash-v2 backfill seam and the downgrade-export seam.
67
+ */
68
+ export const VC1C_ENABLED = (): boolean => sprintFlag("MEGACOMPACT_VC1C");
69
+
70
+ /**
71
+ * VC2A — offline model runtime and asset decision (ModelManifestV1 /
72
+ * EncoderRuntime).
73
+ * Default ON. `MEGACOMPACT_VC2A=0` disables and is byte-identical to the
74
+ * predecessor (mode C: no asset manifest is read/verified, the encoder runtime
75
+ * idles in mode C, zero `vector_cortex_encoder_*` emissions; the trigram/lexical
76
+ * paths are unchanged). The real consumers are the encoder emit seam and the
77
+ * encoder runtime's A/B/C selection.
78
+ */
79
+ export const VC2A_ENABLED = (): boolean => sprintFlag("MEGACOMPACT_VC2A");
80
+
81
+ /**
82
+ * VC2B — multi-head encoder (VectorSetV1 / HeadCalibrationDraft).
83
+ * Default ON. `MEGACOMPACT_VC2B=0` disables and is byte-identical to the
84
+ * predecessor (the encoder emits no per-head vectors and no fallback-selected
85
+ * event; the trigram/lexical paths themselves are unchanged and are the
86
+ * predecessor's mode-B/C producers). The real consumers are the encoder-heads
87
+ * emit seam and the multi-head encoder producers (heads/trigram/lexical).
88
+ */
89
+ export const VC2B_ENABLED = (): boolean => sprintFlag("MEGACOMPACT_VC2B");
90
+
91
+ /**
92
+ * VC2C — encoder qualification + calibration (QualifiedEncoderV1 / CalibrationV1).
93
+ * Default ON. `MEGACOMPACT_VC2C=0` disables and is byte-identical to the
94
+ * predecessor (mode C: no qualification manifest is read or selected, the
95
+ * calibrate/select/fallback seams are idle, zero `vector_cortex_encoder_qualification_*`
96
+ * emissions; the trigram/lexical paths are unchanged). The real consumers are
97
+ * the encoder-qualification emit seam and the calibrate/select seams.
98
+ */
99
+ export const VC2C_ENABLED = (): boolean => sprintFlag("MEGACOMPACT_VC2C");
@@ -0,0 +1,24 @@
1
+ /**
2
+ * config/vector-cortex-flag.ts — the single positive sprint-flag reader.
3
+ *
4
+ * Extracted from vector-cortex.ts so the flag groups split across
5
+ * vector-cortex.ts and vector-cortex-early.ts share ONE definition of what
6
+ * "enabled" means. Duplicating this three-line function into each group would
7
+ * be the classic way a sprint flag silently acquires different off-semantics in
8
+ * different files; there is exactly one implementation and both groups import it.
9
+ *
10
+ * Semantics (unchanged, byte-identical to the original in-place definition):
11
+ * every sprint flag is POSITIVE and defaults ON. `MEGACOMPACT_<SPRINT>=0` or
12
+ * `=false` disables it, as does `MEGACOMPACT_<SPRINT>_DISABLED=true`/`=1`.
13
+ *
14
+ * Pi-agnostic, dependency-free (PREVENT-PI-004 / PREVENT-011).
15
+ */
16
+
17
+ /** Positive sprint flag: `=0` or `_DISABLED=true` disables (default ON). */
18
+ export function sprintFlag(name: string): boolean {
19
+ const v = process.env[name];
20
+ if (v === "0" || v === "false") return false;
21
+ const disabled = process.env[name + "_DISABLED"];
22
+ if (disabled === "true" || disabled === "1") return false;
23
+ return true;
24
+ }
@@ -9,96 +9,22 @@
9
9
  * them without re-declaring the ownership boundary. Pi-agnostic, dependency-free.
10
10
  */
11
11
 
12
- /** Positive sprint flag: `=0` or `_DISABLED=true` disables (default ON). */
13
- function sprintFlag(name: string): boolean {
14
- const v = process.env[name];
15
- if (v === "0" || v === "false") return false;
16
- const disabled = process.env[name + "_DISABLED"];
17
- if (disabled === "true" || disabled === "1") return false;
18
- return true;
19
- }
12
+ import { sprintFlag } from "./vector-cortex-flag.js";
20
13
 
21
- /** VC0A baseline observability (MetricEventV1 / AnnotationV1). Default ON. */
22
- export const VC0A_ENABLED = (): boolean => sprintFlag("MEGACOMPACT_VC0A");
23
-
24
- /**
25
- * VC0B — replay correctness (ReplayCutV2 / ReplayReportV2, M3 effective-cut-v2).
26
- * Default ON. `MEGACOMPACT_VC0B=0` disables and is byte-identical to the
27
- * predecessor (legacy capped-replay behavior preserved; the v2 cut/replay is
28
- * only consulted on the vector-cortex path).
29
- */
30
- export const VC0B_ENABLED = (): boolean => sprintFlag("MEGACOMPACT_VC0B");
31
-
32
- /**
33
- * VC1A — canonical byte events (EventV2 / EventCodec).
34
- * Default ON. `MEGACOMPACT_VC1A=0` disables and is byte-identical to the
35
- * predecessor (mode C: ledger absent, current transcript codec unchanged).
36
- * The single real consumer is the ledger emit seam (`ledger/emit.ts`): flag OFF
37
- * gates zero observability writes.
38
- */
39
- export const VC1A_ENABLED = (): boolean => sprintFlag("MEGACOMPACT_VC1A");
40
-
41
- /**
42
- * VC1B — occurrence ledger + tool identity + compat journal (LedgerReader/
43
- * Writer/Admin, CompatJournalV1, M2 occurrence-v2 migration).
44
- * Default ON. `MEGACOMPACT_VC1B=0` disables and is byte-identical to the
45
- * predecessor (mode C: the neutral occurrence ledger is not written, no
46
- * journal rows, zero `vector_cortex_occurrence_appended` emissions). The real
47
- * consumers are the ledger write integration seam and the compat-journal
48
- * switch seam.
49
- */
50
- export const VC1B_ENABLED = (): boolean => sprintFlag("MEGACOMPACT_VC1B");
51
-
52
- /**
53
- * VC0C — live safety envelope (TriadResult / Breaker / KillDecision + durable
54
- * spool). Default ON. `MEGACOMPACT_VC0C=0` disables and is byte-identical to
55
- * the predecessor (mode C: selected before provider invocation, unchanged host
56
- * transcript, breaker/spool idle and emitting nothing). The single real
57
- * consumer is the resilience emit seam + the safety adapter's triad selection.
58
- */
59
- export const VC0C_ENABLED = (): boolean => sprintFlag("MEGACOMPACT_VC0C");
60
-
61
- /**
62
- * VC1C — cross-language conformance v2 (FixtureManifestV2 / DowngradeReport /
63
- * MinHashV2 + M4 minhash-v2 migration).
64
- * Default ON. `MEGACOMPACT_VC1C=0` disables and is byte-identical to the
65
- * predecessor (mode C: a v2 conformance runner that accepts authority fixtures
66
- * and the manifest validator idle; the sync dedup scan stays on the v1 path;
67
- * zero `vector_cortex_*` VC1C emissions). The real consumers are the conformance
68
- * emit seam, the minhash-v2 backfill seam and the downgrade-export seam.
69
- */
70
- export const VC1C_ENABLED = (): boolean => sprintFlag("MEGACOMPACT_VC1C");
71
-
72
- /**
73
- * VC2A — offline model runtime and asset decision (ModelManifestV1 /
74
- * EncoderRuntime).
75
- * Default ON. `MEGACOMPACT_VC2A=0` disables and is byte-identical to the
76
- * predecessor (mode C: no asset manifest is read/verified, the encoder runtime
77
- * idles in mode C, zero `vector_cortex_encoder_*` emissions; the trigram/lexical
78
- * paths are unchanged). The real consumers are the encoder emit seam and the
79
- * encoder runtime's A/B/C selection.
80
- */
81
- export const VC2A_ENABLED = (): boolean => sprintFlag("MEGACOMPACT_VC2A");
82
-
83
- /**
84
- * VC2B — multi-head encoder (VectorSetV1 / HeadCalibrationDraft).
85
- * Default ON. `MEGACOMPACT_VC2B=0` disables and is byte-identical to the
86
- * predecessor (the encoder emits no per-head vectors and no fallback-selected
87
- * event; the trigram/lexical paths themselves are unchanged and are the
88
- * predecessor's mode-B/C producers). The real consumers are the encoder-heads
89
- * emit seam and the multi-head encoder producers (heads/trigram/lexical).
90
- */
91
- export const VC2B_ENABLED = (): boolean => sprintFlag("MEGACOMPACT_VC2B");
92
-
93
- /**
94
- * VC2C — encoder qualification + calibration (QualifiedEncoderV1 / CalibrationV1).
95
- * Default ON. `MEGACOMPACT_VC2C=0` disables and is byte-identical to the
96
- * predecessor (mode C: no qualification manifest is read or selected, the
97
- * calibrate/select/fallback seams are idle, zero `vector_cortex_encoder_qualification_*`
98
- * emissions; the trigram/lexical paths are unchanged). The real consumers are
99
- * the encoder-qualification emit seam and the calibrate/select seams.
100
- */
101
- export const VC2C_ENABLED = (): boolean => sprintFlag("MEGACOMPACT_VC2C");
14
+ // VC0/VC1/VC2 foundation-phase flags extracted to vector-cortex-early.ts to keep
15
+ // this file under the 300-line soft limit. Re-exported here so every existing
16
+ // `from "./config/vector-cortex.js"` import keeps resolving unchanged.
17
+ export {
18
+ VC0A_ENABLED,
19
+ VC0B_ENABLED,
20
+ VC0C_ENABLED,
21
+ VC1A_ENABLED,
22
+ VC1B_ENABLED,
23
+ VC1C_ENABLED,
24
+ VC2A_ENABLED,
25
+ VC2B_ENABLED,
26
+ VC2C_ENABLED,
27
+ } from "./vector-cortex-early.js";
102
28
 
103
29
  /**
104
30
  * VC3A — capability-gated cortex store (CortexReader/Writer/Admin, CortexRecordV1).
@@ -273,6 +199,25 @@ export const VC6C_ENABLED = (): boolean => sprintFlag("MEGACOMPACT_VC6C");
273
199
  */
274
200
  export const VC7A_ENABLED = (): boolean => sprintFlag("MEGACOMPACT_VC7A");
275
201
 
202
+ /**
203
+ * VC7B — provider cache economics + crystal compiler. Default ON.
204
+ * `MEGACOMPACT_VC7B=0` disables and is byte-identical to the predecessor
205
+ * (VC7A): `computeEconomics`, `compileCrystalBoundaries` and `assignExperiment`
206
+ * STILL RUN (they are PURE — exact integer/rational arithmetic and a SHA-256
207
+ * session bucket, with no clock, storage, or network), so a session keeps its
208
+ * SAME experiment arm and the compiler keeps producing the SAME boundaries with
209
+ * the flag off. Crucially the compiler never changes request identity in either
210
+ * state, so the outbound canonical request — and therefore the VC7A crystal key
211
+ * and the predecessor golden bytes — are unaffected by this flag.
212
+ *
213
+ * The flag gates ONLY the `vector_cortex_cache_experiment_assigned` /
214
+ * `vector_cortex_cache_economics_estimated` events and the cache-economics
215
+ * dashboard seam, which reports `enabled:false` + mode C when off. This flag
216
+ * MUST also be a dashboard SETTINGS toggle (visible in config UI, never in
217
+ * EXCLUDED_SETTINGS), mirroring VC4A..VC7A.
218
+ */
219
+ export const VC7B_ENABLED = (): boolean => sprintFlag("MEGACOMPACT_VC7B");
220
+
276
221
  // Breaker state machine constants (TRIAD_RESILIENCE.md §breaker) extracted to
277
222
  // vector-cortex-breakers.ts to keep this file under the 300-line soft limit.
278
223
  export {
package/src/config.ts CHANGED
@@ -173,6 +173,7 @@ export {
173
173
  VC6B_ENABLED,
174
174
  VC6C_ENABLED,
175
175
  VC7A_ENABLED,
176
+ VC7B_ENABLED,
176
177
  BREAKER_WINDOW_MS,
177
178
  BREAKER_MIN_ATTEMPTS,
178
179
  BREAKER_PERF_FAILURES,
@@ -0,0 +1,128 @@
1
+ /**
2
+ * cache/_economics-fixture.ts — conformance fixture I/O for VC7B economics rows.
3
+ *
4
+ * Sibling of `./_crystal-fixture.ts`, same job for a different corpus: turn
5
+ * canonical JSON back into the REAL production types the economics / compiler /
6
+ * experiments modules consume. Fixtures cannot express bigints, so token counts
7
+ * stored as numbers are converted here — if that conversion were lossy the
8
+ * computed digests would diverge and the acceptance rows would fail loudly.
9
+ *
10
+ * No mocks, no stubs, no parallel "test shape": the decoded objects ARE
11
+ * `ProviderEconomicsV1` / `CacheUsageV1` / `CacheExperimentV1` and are fed
12
+ * verbatim into `validateProfileEconomics`, `computeEconomics`, `compileCrystalBoundaries`,
13
+ * and `assignExperiment`.
14
+ */
15
+
16
+ import { readFileSync } from "node:fs";
17
+ import { join } from "node:path";
18
+ import assert from "node:assert/strict";
19
+
20
+ import { V2, readManifest } from "../heal/_acceptance-fixture.js";
21
+
22
+ /** A `ProviderProfileExclusion` as it appears in JSON. */
23
+ export interface EconFxExclusion {
24
+ pointer: string;
25
+ fixtureId: string;
26
+ proofDigest: string;
27
+ }
28
+
29
+ /** A `ProviderProfileV1` as it appears in JSON (exclusions flattened). */
30
+ export interface EconFxProfile {
31
+ profileId: string;
32
+ profileVersion: string;
33
+ exclusionFixtureId: string | null;
34
+ exclusions: readonly EconFxExclusion[];
35
+ }
36
+
37
+ /** A `CacheUsageV1` as it appears in JSON (matches `CacheUsageV1` exactly). */
38
+ export interface EconFxUsage {
39
+ cachedTokens: number;
40
+ writeCount: number;
41
+ hitCount: number;
42
+ }
43
+
44
+ /** A compiler input range as it appears in JSON (matches `DagSpan` minus seq). */
45
+ export interface EconFxCompilerRange {
46
+ sessionId: string;
47
+ startSeq: number;
48
+ endSeq: number;
49
+ startByte: number;
50
+ endByte: number;
51
+ digest: string;
52
+ }
53
+
54
+ export interface EconFxExperiment {
55
+ experimentId: string;
56
+ sessionId: string;
57
+ arm: "A" | "B" | "C";
58
+ source: "randomized" | "forced" | "shadow";
59
+ }
60
+
61
+ export interface EconFxInput {
62
+ scenario: "economics" | "exclusion" | "compile" | "experiment" | "eligibility";
63
+ mode: string;
64
+ economics?: ProviderEconomicsV1Lite;
65
+ profile?: EconFxProfile;
66
+ exclusion?: EconFxExclusion;
67
+ usage?: EconFxUsage;
68
+ prefixTokens?: number;
69
+ ageMs?: number;
70
+ ranges?: readonly EconFxCompilerRange[];
71
+ experiment?: EconFxExperiment;
72
+ repeatAssignments?: number;
73
+ loseJournalAfterFirst?: boolean;
74
+ }
75
+
76
+ export interface ProviderEconomicsV1Lite {
77
+ profileId: string;
78
+ profileVersion: string;
79
+ basePrice: number;
80
+ readPrice: number;
81
+ writePrice: number;
82
+ ttlMs: number;
83
+ minPrefix: number;
84
+ exclusionFixtureId: string | null;
85
+ }
86
+
87
+ export interface EconFxExpected {
88
+ ok: boolean;
89
+ code?: string;
90
+ netSavings?: number;
91
+ tokenSavings?: number;
92
+ breakEvenHits?: number | null;
93
+ eligible?: boolean;
94
+ identityPreserved?: boolean;
95
+ repeatArm?: "A" | "B" | "C";
96
+ }
97
+
98
+ export interface EconFx {
99
+ id: string;
100
+ schema: string;
101
+ producer: string;
102
+ assertion: string;
103
+ kind: string;
104
+ input: EconFxInput;
105
+ expected: EconFxExpected;
106
+ }
107
+
108
+ /** Read one registered cache-economics fixture (asserting it IS registered). */
109
+ export function economicsFixture(id: string): EconFx {
110
+ const m = readManifest();
111
+ const row = m.fixtures.find((f) => f.id === id && f.path.startsWith("cache-economics/"));
112
+ assert.ok(row, `fixture ${id} registered under cache-economics/ in manifest`);
113
+ return JSON.parse(readFileSync(join(V2, row!.path), "utf8")) as EconFx;
114
+ }
115
+
116
+ /** Flag-pinned wrapper: VC7B gated by MEGACOMPACT_VC7B (defaults ON). */
117
+ export function withVc7bFlag(value: string, fn: () => void): () => void {
118
+ return (): void => {
119
+ const saved = process.env.MEGACOMPACT_VC7B;
120
+ process.env.MEGACOMPACT_VC7B = value;
121
+ try {
122
+ fn();
123
+ } finally {
124
+ if (saved === undefined) delete process.env.MEGACOMPACT_VC7B;
125
+ else process.env.MEGACOMPACT_VC7B = saved;
126
+ }
127
+ };
128
+ }