pi-mega-compact 0.20.19 → 0.20.21

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 (100) hide show
  1. package/dist/config/vector-cortex-vc8c.js +31 -0
  2. package/dist/config/vector-cortex.js +5 -0
  3. package/dist/config.js +1 -1
  4. package/dist/extensions/dashboard-server/api-contracts/vector-cortex-platform.js +12 -0
  5. package/dist/extensions/dashboard-server/route-dispatch.js +6 -0
  6. package/dist/extensions/dashboard-server/routes-rag-settings-vector-cortex.js +2 -1
  7. package/dist/extensions/dashboard-server/routes-vector-cortex-platform.js +42 -0
  8. package/dist/src/config/vector-cortex-vc8c.js +31 -0
  9. package/dist/src/config/vector-cortex.js +5 -0
  10. package/dist/src/config.js +1 -1
  11. package/dist/src/vector-cortex/cache/_diagnostics-fixture.js +79 -5
  12. package/dist/src/vector-cortex/cache/diagnostics.js +17 -8
  13. package/dist/src/vector-cortex/controller/_adaptive-fixture.js +126 -0
  14. package/dist/src/vector-cortex/controller/policy.js +1 -1
  15. package/dist/src/vector-cortex/migrations/request-hash-v2-ops.js +23 -7
  16. package/dist/src/vector-cortex/platform/cross-read.js +98 -0
  17. package/dist/src/vector-cortex/platform/emit.js +54 -0
  18. package/dist/src/vector-cortex/platform/select.js +104 -0
  19. package/dist/src/vector-cortex/platform/types.js +57 -0
  20. package/dist/vector-cortex/cache/_diagnostics-fixture.js +79 -5
  21. package/dist/vector-cortex/cache/diagnostics.js +17 -8
  22. package/dist/vector-cortex/controller/_adaptive-fixture.js +126 -0
  23. package/dist/vector-cortex/controller/policy.js +1 -1
  24. package/dist/vector-cortex/migrations/request-hash-v2-ops.js +23 -7
  25. package/dist/vector-cortex/platform/cross-read.js +98 -0
  26. package/dist/vector-cortex/platform/emit.js +54 -0
  27. package/dist/vector-cortex/platform/select.js +104 -0
  28. package/dist/vector-cortex/platform/types.js +57 -0
  29. package/extensions/dashboard-client/dist/assets/{AreaChart-ujtGh2ez.js → AreaChart-BkfB-LSQ.js} +2 -2
  30. package/extensions/dashboard-client/dist/assets/{AreaChart-ujtGh2ez.js.map → AreaChart-BkfB-LSQ.js.map} +1 -1
  31. package/extensions/dashboard-client/dist/assets/{BarChart-DNZqvtqh.js → BarChart-Cs1kogko.js} +2 -2
  32. package/extensions/dashboard-client/dist/assets/{BarChart-DNZqvtqh.js.map → BarChart-Cs1kogko.js.map} +1 -1
  33. package/extensions/dashboard-client/dist/assets/{CacheTab-CeCIW1rD.js → CacheTab-BZgaguGr.js} +2 -2
  34. package/extensions/dashboard-client/dist/assets/{CacheTab-CeCIW1rD.js.map → CacheTab-BZgaguGr.js.map} +1 -1
  35. package/extensions/dashboard-client/dist/assets/{EventsTab-ChohmqJI.js → EventsTab-BFbkI_MO.js} +2 -2
  36. package/extensions/dashboard-client/dist/assets/{EventsTab-ChohmqJI.js.map → EventsTab-BFbkI_MO.js.map} +1 -1
  37. package/extensions/dashboard-client/dist/assets/{HealthTab-CKfAooiV.js → HealthTab-CvlOENCX.js} +2 -2
  38. package/extensions/dashboard-client/dist/assets/{HealthTab-CKfAooiV.js.map → HealthTab-CvlOENCX.js.map} +1 -1
  39. package/extensions/dashboard-client/dist/assets/{MaintenanceTab-D3DxHgM2.js → MaintenanceTab-CtBuz2qL.js} +2 -2
  40. package/extensions/dashboard-client/dist/assets/{MaintenanceTab-D3DxHgM2.js.map → MaintenanceTab-CtBuz2qL.js.map} +1 -1
  41. package/extensions/dashboard-client/dist/assets/{MemoryMapTab--c-0PBka.js → MemoryMapTab-K4775S4d.js} +2 -2
  42. package/extensions/dashboard-client/dist/assets/{MemoryMapTab--c-0PBka.js.map → MemoryMapTab-K4775S4d.js.map} +1 -1
  43. package/extensions/dashboard-client/dist/assets/{MetricsTab-9UaEB69R.js → MetricsTab-DVGcFInz.js} +2 -2
  44. package/extensions/dashboard-client/dist/assets/{MetricsTab-9UaEB69R.js.map → MetricsTab-DVGcFInz.js.map} +1 -1
  45. package/extensions/dashboard-client/dist/assets/{OverviewTab-89zNl1qx.js → OverviewTab-4LmW5ZCl.js} +2 -2
  46. package/extensions/dashboard-client/dist/assets/{OverviewTab-89zNl1qx.js.map → OverviewTab-4LmW5ZCl.js.map} +1 -1
  47. package/extensions/dashboard-client/dist/assets/{ReposTab-CkfNrdxF.js → ReposTab-StebchgQ.js} +2 -2
  48. package/extensions/dashboard-client/dist/assets/{ReposTab-CkfNrdxF.js.map → ReposTab-StebchgQ.js.map} +1 -1
  49. package/extensions/dashboard-client/dist/assets/{SessionsTab-DA7wqI05.js → SessionsTab-C3D_XAkX.js} +2 -2
  50. package/extensions/dashboard-client/dist/assets/{SessionsTab-DA7wqI05.js.map → SessionsTab-C3D_XAkX.js.map} +1 -1
  51. package/extensions/dashboard-client/dist/assets/{SetupTab-pG4xMI3P.js → SetupTab-BTBGyppF.js} +2 -2
  52. package/extensions/dashboard-client/dist/assets/{SetupTab-pG4xMI3P.js.map → SetupTab-BTBGyppF.js.map} +1 -1
  53. package/extensions/dashboard-client/dist/assets/{TimeSavedCard-DeQnzSkb.js → TimeSavedCard-CTPi_AAW.js} +2 -2
  54. package/extensions/dashboard-client/dist/assets/{TimeSavedCard-DeQnzSkb.js.map → TimeSavedCard-CTPi_AAW.js.map} +1 -1
  55. package/extensions/dashboard-client/dist/assets/{TurnsTab-B6ifHMbg.js → TurnsTab-DSOGcY5Q.js} +2 -2
  56. package/extensions/dashboard-client/dist/assets/{TurnsTab-B6ifHMbg.js.map → TurnsTab-DSOGcY5Q.js.map} +1 -1
  57. package/extensions/dashboard-client/dist/assets/VectorCortexTab-OMW8_RFf.js +2 -0
  58. package/extensions/dashboard-client/dist/assets/VectorCortexTab-OMW8_RFf.js.map +1 -0
  59. package/extensions/dashboard-client/dist/assets/{WikiTab-awMsQNBY.js → WikiTab-Db-qFDdg.js} +2 -2
  60. package/extensions/dashboard-client/dist/assets/{WikiTab-awMsQNBY.js.map → WikiTab-Db-qFDdg.js.map} +1 -1
  61. package/extensions/dashboard-client/dist/assets/{button-DCDwPy_j.js → button-BF4UgBAD.js} +2 -2
  62. package/extensions/dashboard-client/dist/assets/{button-DCDwPy_j.js.map → button-BF4UgBAD.js.map} +1 -1
  63. package/extensions/dashboard-client/dist/assets/{card-D3KAYtck.js → card-XmXoYQqB.js} +2 -2
  64. package/extensions/dashboard-client/dist/assets/{card-D3KAYtck.js.map → card-XmXoYQqB.js.map} +1 -1
  65. package/extensions/dashboard-client/dist/assets/{generateCategoricalChart-D_FHNog-.js → generateCategoricalChart-Be8hM1aU.js} +2 -2
  66. package/extensions/dashboard-client/dist/assets/{generateCategoricalChart-D_FHNog-.js.map → generateCategoricalChart-Be8hM1aU.js.map} +1 -1
  67. package/extensions/dashboard-client/dist/assets/{index-4MkLsevY.js → index-NXDgILxv.js} +3 -3
  68. package/extensions/dashboard-client/dist/assets/{index-4MkLsevY.js.map → index-NXDgILxv.js.map} +1 -1
  69. package/extensions/dashboard-client/dist/assets/{switch-Cc05xGtg.js → switch-kUZCrbia.js} +2 -2
  70. package/extensions/dashboard-client/dist/assets/{switch-Cc05xGtg.js.map → switch-kUZCrbia.js.map} +1 -1
  71. package/extensions/dashboard-client/dist/assets/{toggle--QUzWk-Y.js → toggle-DEe5mCwF.js} +2 -2
  72. package/extensions/dashboard-client/dist/assets/{toggle--QUzWk-Y.js.map → toggle-DEe5mCwF.js.map} +1 -1
  73. package/extensions/dashboard-client/dist/assets/{useSSE-DcAeX67m.js → useSSE-BlCyLqge.js} +2 -2
  74. package/extensions/dashboard-client/dist/assets/{useSSE-DcAeX67m.js.map → useSSE-BlCyLqge.js.map} +1 -1
  75. package/extensions/dashboard-client/dist/index.html +1 -1
  76. package/extensions/dashboard-client/src/api/vector-cortex.ts +9 -0
  77. package/extensions/dashboard-client/src/tabs/VectorCortexPlatformCard.tsx +42 -0
  78. package/extensions/dashboard-client/src/tabs/VectorCortexTab.tsx +2 -0
  79. package/extensions/dashboard-client/src/tabs/useVectorCortexPoll.ts +5 -0
  80. package/extensions/dashboard-client/src/types/vector-cortex-vc8.ts +19 -3
  81. package/extensions/dashboard-client/src/types/vector-cortex.ts +1 -1
  82. package/extensions/dashboard-server/api-contracts/vector-cortex-platform.ts +34 -0
  83. package/extensions/dashboard-server/route-dispatch.ts +6 -0
  84. package/extensions/dashboard-server/routes-rag-settings-vector-cortex.ts +7 -1
  85. package/extensions/dashboard-server/routes-vector-cortex-platform.ts +52 -0
  86. package/package.json +1 -1
  87. package/src/config/vector-cortex-vc8c.ts +33 -0
  88. package/src/config/vector-cortex.ts +6 -0
  89. package/src/config.ts +1 -0
  90. package/src/vector-cortex/cache/_diagnostics-fixture.ts +163 -5
  91. package/src/vector-cortex/cache/diagnostics.ts +18 -9
  92. package/src/vector-cortex/controller/_adaptive-fixture.ts +230 -0
  93. package/src/vector-cortex/controller/policy.ts +1 -1
  94. package/src/vector-cortex/migrations/request-hash-v2-ops.ts +21 -6
  95. package/src/vector-cortex/platform/cross-read.ts +122 -0
  96. package/src/vector-cortex/platform/emit.ts +77 -0
  97. package/src/vector-cortex/platform/select.ts +131 -0
  98. package/src/vector-cortex/platform/types.ts +169 -0
  99. package/extensions/dashboard-client/dist/assets/VectorCortexTab-DSz16qtM.js +0 -2
  100. package/extensions/dashboard-client/dist/assets/VectorCortexTab-DSz16qtM.js.map +0 -1
@@ -0,0 +1,34 @@
1
+ /**
2
+ * api-contracts/vector-cortex-platform.ts — VC8C engine parity/selection API contract.
3
+ *
4
+ * PREVENT-PI-004: type definitions only, no network code.
5
+ * PREVENT-011: no `any` type.
6
+ *
7
+ * Reader-only GET /api/vector-cortex/platform diagnostics view (VC8C).
8
+ * COUNTS + CODES ONLY. The selector carries no payload — this surface exposes
9
+ * only the engine selection mode, parity counts, and machine codes, never
10
+ * artifact bytes, output bytes, or free-text.
11
+ */
12
+
13
+ /** Runtime triad mode implied by the VC8C flag state. */
14
+ export type VectorCortexPlatformMode = "A" | "B" | "C";
15
+
16
+ /** Reader-only engine parity/selection aggregate view for GET /api/vector-cortex/platform. */
17
+ export interface VectorCortexPlatformView {
18
+ /** Whether the VC8C platform flag is enabled. */
19
+ readonly enabled: boolean;
20
+ /** Runtime triad mode: A=qualified external Rust, B=TS reference, C=legacy path. */
21
+ readonly mode: VectorCortexPlatformMode;
22
+ /** Total fixtures in the parity matrix (count only). */
23
+ readonly fixtureCount: number;
24
+ /** Fixtures that passed byte-equal comparison (count only). */
25
+ readonly passed: number;
26
+ /** Fixtures that mismatched (count only). */
27
+ readonly failed: number;
28
+ /** Whether an external Rust runner is configured (boolean, no path). */
29
+ readonly externalRunnerConfigured: boolean;
30
+ /** Last RUST_ failure code, or null if none. */
31
+ readonly lastFailure: string | null;
32
+ /** ISO timestamp of the snapshot. */
33
+ readonly updatedAt: string;
34
+ }
@@ -82,6 +82,11 @@ import { handleVectorCortexOutcomes } from "./routes-vector-cortex-outcomes.js";
82
82
  // 400-line extension soft limit.
83
83
  import { handleVectorCortexPolicy } from "./routes-vector-cortex-policy.js";
84
84
 
85
+ // VC8C canary selection + external Rust parity gets its own module so the
86
+ // platform/selection seam stays independent and every file stays well under
87
+ // the 400-line extension soft limit.
88
+ import { handleVectorCortexPlatform } from "./routes-vector-cortex-platform.js";
89
+
85
90
  /**
86
91
  * Dispatch a request through every registered route handler.
87
92
  * Returns true if a handler claimed the request (ended the response).
@@ -140,5 +145,6 @@ export function dispatchRoutes(
140
145
  if (handleVectorCortexDiagnostics(req, res, ctx)) return true;
141
146
  if (handleVectorCortexOutcomes(req, res, ctx)) return true;
142
147
  if (handleVectorCortexPolicy(req, res, ctx)) return true;
148
+ if (handleVectorCortexPlatform(req, res, ctx)) return true;
143
149
  return false;
144
150
  }
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * dashboard-server/routes-rag-settings-vector-cortex.ts — Vector Cortex SETTINGS.
3
3
  *
4
- * The VC0A..VC5C chain flag inventory, split out of routes-rag-settings-helpers.ts
4
+ * The VC0A..VC8C chain flag inventory, split out of routes-rag-settings-helpers.ts
5
5
  * to keep that file under the 400-line extensions/ soft limit. Every VC flag is a
6
6
  * user-visible dashboard toggle (never in EXCLUDED_SETTINGS) per the chain spec,
7
7
  * and each carries the long description the Setup panel renders as help text.
@@ -186,5 +186,11 @@ export const VECTOR_CORTEX_SETTINGS: SettingGroup = {
186
186
  "Bounded shadow adaptive policy + M7 pressure-v2 migration. Policy actions are from a finite set (admit/dampen/defer/escalate/reject) chosen deterministically by the canonical pressure level; token budgets are clamped into a configured window after the pressure factor. Unknown pressure labels are rejected as POL_PRESSURE_UNKNOWN, never coerced to a neighbour. The shadow engine is structurally incapable of affecting the live path: inputs are deep-copied, the canonical prompt digest is pinned before and after to prove non-mutation, and liveMutations is always zero. M7 migrates legacy pressure labels to the v2 canonical five by copy/validate/switch; an unknown label blocks the switch and keeps the legacy pointer (M7_PRESSURE_UNKNOWN). A shadow decision is mode A, static calibrated policy is mode B (forced by invalid A), and fixed legacy thresholds is mode C (forced by M7 or B failure). OFF = byte-identical predecessor (VC8A); the policy/shadow/migration arithmetic still runs, only the reporter + dashboard seam is suppressed.",
187
187
  true,
188
188
  ),
189
+ boolDirect(
190
+ "MEGACOMPACT_VC8C",
191
+ "VC8C Canary Platform + Rust Parity",
192
+ "Canary selection and external Rust parity. The selector admits a qualified external Rust artifact only when ABI version, URL metadata, commit, Cargo.lock digest, and platform all match evidence; a Cargo.lock digest mismatch rejects the artifact (RUST_CARGO_DIGEST_MISMATCH). The cross-conformance runner exchanges length-framed neutral records over a local stdin/stdout channel — a subprocess, never a URL (PREVENT-PI-004). A parity mismatch selects TS mode B. A qualified external artifact is mode A, TS reference is mode B, legacy path is mode C. OFF = byte-identical predecessor (VC8B); the selector and cross-conformance arithmetic still run, only the reporter + dashboard seam is suppressed.",
193
+ true,
194
+ ),
189
195
  ],
190
196
  };
@@ -0,0 +1,52 @@
1
+ /**
2
+ * dashboard-server/routes-vector-cortex-platform.ts — VC8C platform dashboard route.
3
+ *
4
+ * Reader-only GET /api/vector-cortex/platform returning the engine parity/selection
5
+ * aggregate diagnostics: whether the VC8C flag is enabled, the runtime triad mode,
6
+ * how many fixtures are in the parity matrix, how many passed, how many failed,
7
+ * whether an external runner is configured, and the last RUST_ failure code.
8
+ *
9
+ * COUNTS + CODES ONLY. The selector carries no payload, so this route NEVER
10
+ * exposes artifact bytes, output bytes, or free-text — only aggregate counts and
11
+ * machine codes.
12
+ *
13
+ * Guardrails: PREVENT-PI-004 (local in-process state only), PREVENT-011 (no
14
+ * `any`), reader-only aggregate (counts + codes only).
15
+ */
16
+
17
+ import type { IncomingMessage, ServerResponse } from "node:http";
18
+ import type { RouteContext } from "./routes-core.js";
19
+ import { VC8C_ENABLED } from "../../src/config.js";
20
+ import { sendJson } from "./routes-vector-cortex-shared.js";
21
+ import type { VectorCortexPlatformView } from "./api-contracts/vector-cortex-platform.js";
22
+
23
+ /** GET /api/vector-cortex/platform — reader-only engine parity/selection aggregate (VC8C). */
24
+ export function handleVectorCortexPlatform(
25
+ req: IncomingMessage,
26
+ res: ServerResponse,
27
+ _ctx: RouteContext,
28
+ ): boolean {
29
+ const url = req.url ?? "";
30
+ const path = url.split("?")[0] ?? url;
31
+
32
+ if (path !== "/api/vector-cortex/platform") return false;
33
+ if (req.method !== "GET") {
34
+ sendJson(res, 405, { error: "method_not_allowed" });
35
+ return true;
36
+ }
37
+
38
+ const enabled = VC8C_ENABLED();
39
+ const mode: VectorCortexPlatformView["mode"] = enabled ? "A" : "C";
40
+ const body: VectorCortexPlatformView = {
41
+ enabled,
42
+ mode,
43
+ fixtureCount: 0,
44
+ passed: 0,
45
+ failed: 0,
46
+ externalRunnerConfigured: process.env.MEGACOMPACT_RUST_RUNNER !== undefined,
47
+ lastFailure: null,
48
+ updatedAt: new Date().toISOString(),
49
+ };
50
+ sendJson(res, 200, body);
51
+ return true;
52
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-mega-compact",
3
- "version": "0.20.19",
3
+ "version": "0.20.21",
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,33 @@
1
+ /**
2
+ * config/vector-cortex-vc8c.ts — VC8C canary-selection sprint flag.
3
+ *
4
+ * Extracted from vector-cortex.ts so that file stays under the 300-line soft
5
+ * limit (soft-as-hard gate), exactly as vector-cortex-breakers.ts and
6
+ * vector-cortex-early.ts were. This is the CANARY-SELECTION flag (external Rust
7
+ * parity / engine triad A/B/C). vector-cortex.ts re-exports it below so no
8
+ * consumer import path changes.
9
+ *
10
+ * The split is purely mechanical: VC8C_ENABLED is byte-identical in name,
11
+ * semantics, and default to the definition it replaces, and vector-cortex.ts
12
+ * re-exports it so every existing `from "./config/vector-cortex.js"` import
13
+ * keeps resolving unchanged.
14
+ *
15
+ * Pi-agnostic, dependency-free (PREVENT-PI-004 / PREVENT-011).
16
+ */
17
+
18
+ import { sprintFlag } from "./vector-cortex-flag.js";
19
+
20
+ /**
21
+ * VC8C — canary selection + external Rust parity (EngineAbiV1 / ParityReportV1).
22
+ * Default ON. `MEGACOMPACT_VC8C=0` disables and is byte-identical to the
23
+ * predecessor (VC8B): the engine selector and the cross-conformance runner
24
+ * STILL RUN (they are PURE — ABI/evidence matching plus neutral length-framed
25
+ * byte comparison, with no clock, storage, or network), so a qualified external
26
+ * artifact is still accepted and a parity mismatch still demotes to mode B with
27
+ * the flag off. The flag gates ONLY the
28
+ * `vector_cortex_engine_parity_checked` / `vector_cortex_engine_selection_demoted`
29
+ * events and the engine parity/selection dashboard seam, which reports
30
+ * `enabled:false` + mode C when off. This flag MUST also be a dashboard SETTINGS
31
+ * toggle (visible in config UI, never in EXCLUDED_SETTINGS), mirroring VC4A..VC8B.
32
+ */
33
+ export const VC8C_ENABLED = (): boolean => sprintFlag("MEGACOMPACT_VC8C");
@@ -269,6 +269,12 @@ export const VC8A_ENABLED = (): boolean => sprintFlag("MEGACOMPACT_VC8A");
269
269
  */
270
270
  export const VC8B_ENABLED = (): boolean => sprintFlag("MEGACOMPACT_VC8B");
271
271
 
272
+ // VC8C (canary selection + external Rust parity) extracted to
273
+ // vector-cortex-vc8c.ts to keep this file under the 300-line soft limit.
274
+ // Re-exported here so every existing `from "./config/vector-cortex.js"`
275
+ // import keeps resolving unchanged.
276
+ export { VC8C_ENABLED } from "./vector-cortex-vc8c.js";
277
+
272
278
  // Breaker state machine constants (TRIAD_RESILIENCE.md §breaker) extracted to
273
279
  // vector-cortex-breakers.ts to keep this file under the 300-line soft limit.
274
280
  export {
package/src/config.ts CHANGED
@@ -177,6 +177,7 @@ export {
177
177
  VC7C_ENABLED,
178
178
  VC8A_ENABLED,
179
179
  VC8B_ENABLED,
180
+ VC8C_ENABLED,
180
181
  BREAKER_WINDOW_MS,
181
182
  BREAKER_MIN_ATTEMPTS,
182
183
  BREAKER_PERF_FAILURES,
@@ -1,16 +1,42 @@
1
1
  /**
2
- * cache/_diagnostics-fixture.ts — VC7C acceptance-test fixture helpers.
2
+ * cache/_diagnostics-fixture.ts — VC7C conformance fixture I/O + host builders.
3
3
  *
4
- * Reads conformance fixtures from the v2 `cache-diagnostics/` domain and provides
5
- * a flag-toggling wrapper for VC7C parity tests. Mirrors `_economics-fixture.ts`.
4
+ * Reads conformance fixtures from the v2 `cache-diagnostics/` domain, decodes
5
+ * them into the REAL production types (`MissObservation`, `M5Host`) and feeds
6
+ * them verbatim into `classifyMiss` / `migrateRequestHashV2`. Fixtures store
7
+ * bigints as JSON numbers — converted here (lossy conversion would break
8
+ * digests and the acceptance rows would fail loudly).
9
+ *
10
+ * No mocks, no stubs, no parallel "test shape": the decoded objects ARE
11
+ * `MissObservation` / `M5Host` and drive the production functions directly.
12
+ * Mirrors `_economics-fixture.ts`.
6
13
  */
7
14
 
8
- import { readFileSync } from "node:fs";
15
+ import { readFileSync, existsSync } from "node:fs";
9
16
  import { join, dirname } from "node:path";
10
17
  import { fileURLToPath } from "node:url";
11
18
 
19
+ import type { MissObservation } from "./diagnostics-types.js";
20
+ import type {
21
+ M5Host,
22
+ RequestHashV1Row,
23
+ RequestHashV2Row,
24
+ } from "../migrations/request-hash-v2-types.js";
25
+
12
26
  const here = dirname(fileURLToPath(import.meta.url));
13
- const V2 = join(here, "..", "..", "..", "conformance", "vector-cortex", "v2");
27
+
28
+ function repoRoot(from: string): string {
29
+ let dir = from;
30
+ for (let i = 0; i < 8; i++) {
31
+ if (existsSync(join(dir, "conformance", "vector-cortex"))) return dir;
32
+ const next = dirname(dir);
33
+ if (next === dir) break;
34
+ dir = next;
35
+ }
36
+ throw new Error("conformance corpus not found above " + from);
37
+ }
38
+
39
+ const V2 = join(repoRoot(here), "conformance", "vector-cortex", "v2");
14
40
  const DIR = join(V2, "cache-diagnostics");
15
41
 
16
42
  /** Read + parse one conformance fixture by ID. */
@@ -30,3 +56,135 @@ export function withVc7cFlag<T>(value: string, fn: () => T): T {
30
56
  else process.env.MEGACOMPACT_VC7C = prior;
31
57
  }
32
58
  }
59
+
60
+ // ── Cache-diagnostic fixture types (CACHE-016..030 + named) ──────────────────
61
+
62
+ interface CacheFxInput {
63
+ scenario: string;
64
+ observe: {
65
+ requestProfileId: string;
66
+ requestProfileVersion: string;
67
+ cachedProfileId: string | null;
68
+ cachedProfileVersion: string | null;
69
+ requestCoveredDigest: string;
70
+ cachedCoveredDigest: string | null;
71
+ requestedRangeCount: number;
72
+ cachedRangeCount: number | null;
73
+ requestDigest: string;
74
+ cachedRequestDigest: string | null;
75
+ requestDependencyHighWater: number;
76
+ cachedDependencyHighWater: number | null;
77
+ generationInvalidated: boolean;
78
+ };
79
+ }
80
+
81
+ interface CacheFxExpected {
82
+ ok: boolean;
83
+ missClass: string;
84
+ evidence: {
85
+ profileMismatch: boolean;
86
+ rangeMismatch: boolean;
87
+ dependencyAdvanced: boolean;
88
+ requestMismatch: boolean;
89
+ generationInvalidated: boolean;
90
+ requestedRangeCount: number;
91
+ cachedRangeCount: number;
92
+ dependencyDelta: number;
93
+ absent: boolean;
94
+ };
95
+ }
96
+
97
+ export interface CacheFx {
98
+ id: string;
99
+ assertion: string;
100
+ input: CacheFxInput;
101
+ expected: CacheFxExpected;
102
+ }
103
+
104
+ /** Read a cache-diagnostic fixture as a typed CacheFx. */
105
+ export function cacheFx(id: string): CacheFx {
106
+ return diagnosticsFixture(id) as unknown as CacheFx;
107
+ }
108
+
109
+ /** Decode the fixture's JSON observe into the production MissObservation. */
110
+ export function toObservation(fx: CacheFx): MissObservation {
111
+ const o = fx.input.observe;
112
+ return {
113
+ requestProfileId: o.requestProfileId,
114
+ requestProfileVersion: o.requestProfileVersion,
115
+ cachedProfileId: o.cachedProfileId,
116
+ cachedProfileVersion: o.cachedProfileVersion,
117
+ requestCoveredDigest: o.requestCoveredDigest,
118
+ cachedCoveredDigest: o.cachedCoveredDigest,
119
+ requestedRangeCount: o.requestedRangeCount,
120
+ cachedRangeCount: o.cachedRangeCount,
121
+ requestDigest: o.requestDigest,
122
+ cachedRequestDigest: o.cachedRequestDigest,
123
+ requestDependencyHighWater: BigInt(o.requestDependencyHighWater),
124
+ cachedDependencyHighWater:
125
+ o.cachedDependencyHighWater === null
126
+ ? null
127
+ : BigInt(o.cachedDependencyHighWater),
128
+ generationInvalidated: o.generationInvalidated,
129
+ };
130
+ }
131
+
132
+ // ── M5 fixture types (M5-001..020 + M5-COLLIDE-002) ─────────────────────────
133
+
134
+ interface M5FxInput {
135
+ scenario: string;
136
+ v1Rows: readonly { profileId: string; requestDigest: string; hash: string }[];
137
+ econVersionOf: Record<string, string>;
138
+ activeVersion: number;
139
+ sessionOf: Record<string, string>;
140
+ liveGenerationOf: Record<string, number>;
141
+ }
142
+
143
+ interface M5FxExpected {
144
+ ok: boolean;
145
+ codes: string[];
146
+ activeVersionAfter: number;
147
+ }
148
+
149
+ export interface M5Fx {
150
+ id: string;
151
+ assertion: string;
152
+ input: M5FxInput;
153
+ expected: M5FxExpected;
154
+ }
155
+
156
+ /** Read an M5 fixture as a typed M5Fx. */
157
+ export function m5Fx(id: string): M5Fx {
158
+ return diagnosticsFixture(id) as unknown as M5Fx;
159
+ }
160
+
161
+ /** Build an in-memory M5Host from the fixture input. */
162
+ export function toM5Host(
163
+ fx: M5Fx,
164
+ ): M5Host & { activeVersionAfter: number } {
165
+ const v1Rows: RequestHashV1Row[] = fx.input.v1Rows.map((r) => ({
166
+ profileId: r.profileId,
167
+ requestDigest: r.requestDigest,
168
+ hash: r.hash,
169
+ }));
170
+ const v2Rows: RequestHashV2Row[] = [];
171
+ let activeVersion = fx.input.activeVersion;
172
+
173
+ const host: M5Host & { activeVersionAfter: number } = {
174
+ v1Rows: () => v1Rows,
175
+ economicsVersionOf: (p) => fx.input.econVersionOf[p] ?? "econ-1",
176
+ sessionOf: (p) => fx.input.sessionOf[p] ?? "s1",
177
+ liveGenerationOf: (s) =>
178
+ BigInt(fx.input.liveGenerationOf[s] ?? 0),
179
+ existingV2: () => v2Rows,
180
+ putV2: (rows) => v2Rows.push(...rows),
181
+ activeVersion: () => activeVersion,
182
+ switchToV2: () => {
183
+ activeVersion = 2;
184
+ },
185
+ get activeVersionAfter() {
186
+ return activeVersion;
187
+ },
188
+ };
189
+ return host;
190
+ }
@@ -45,17 +45,32 @@ function advanceDelta(
45
45
 
46
46
  /** Collect the payload-free evidence from one observation. */
47
47
  export function collectEvidence(o: MissObservation): MissEvidence {
48
+ // Absence is computed first: "absence is not a mismatch" means a cold key
49
+ // (null cached fields) classifies `unknown`, never `profile`/`range`/etc.
50
+ // The cachedRangeCount on a cold key is 0 by convention (not a real count),
51
+ // so it must not trigger a range mismatch even though isPresent(0) is true.
52
+ const absent =
53
+ !isPresent(o.cachedProfileId) &&
54
+ !isPresent(o.cachedCoveredDigest) &&
55
+ !isPresent(o.cachedRequestDigest) &&
56
+ !isPresent(o.cachedDependencyHighWater);
57
+
48
58
  const profileMismatch =
49
59
  isPresent(o.cachedProfileId) &&
50
60
  isPresent(o.cachedProfileVersion) &&
51
61
  (o.cachedProfileId !== o.requestProfileId ||
52
62
  o.cachedProfileVersion !== o.requestProfileVersion);
53
63
 
64
+ // Guard with !absent: a cold key's cachedRangeCount is 0 by convention (not
65
+ // a real count), so it must not fire a range mismatch even though
66
+ // isPresent(0) is true. The covered-digest arm is already null-safe but
67
+ // the rangeCount arm is not — !absent covers both uniformly.
54
68
  const rangeMismatch =
55
- (isPresent(o.cachedCoveredDigest) &&
69
+ !absent &&
70
+ ((isPresent(o.cachedCoveredDigest) &&
56
71
  o.cachedCoveredDigest !== o.requestCoveredDigest) ||
57
- (isPresent(o.cachedRangeCount) &&
58
- o.cachedRangeCount !== o.requestedRangeCount);
72
+ (isPresent(o.cachedRangeCount) &&
73
+ o.cachedRangeCount !== o.requestedRangeCount));
59
74
 
60
75
  const dep = advanceDelta(
61
76
  o.requestDependencyHighWater,
@@ -66,12 +81,6 @@ export function collectEvidence(o: MissObservation): MissEvidence {
66
81
  isPresent(o.cachedRequestDigest) &&
67
82
  o.cachedRequestDigest !== o.requestDigest;
68
83
 
69
- const absent =
70
- !isPresent(o.cachedProfileId) &&
71
- !isPresent(o.cachedCoveredDigest) &&
72
- !isPresent(o.cachedRequestDigest) &&
73
- !isPresent(o.cachedDependencyHighWater);
74
-
75
84
  return {
76
85
  profileMismatch,
77
86
  rangeMismatch,
@@ -0,0 +1,230 @@
1
+ /**
2
+ * controller/_adaptive-fixture.ts — VC8B conformance fixture I/O + host builders.
3
+ *
4
+ * Reads conformance fixtures from the v2 `adaptive-policy/` domain, decodes
5
+ * them into the REAL production types (`PolicyInput`, `M7Host`) and feeds
6
+ * them verbatim into `evaluatePolicy` / `evaluateShadow` / `migratePressureV2`.
7
+ *
8
+ * No mocks, no stubs, no parallel "test shape": the decoded objects ARE the
9
+ * production types and drive the production functions directly.
10
+ * Mirrors `_diagnostics-fixture.ts` (VC7C) and `_economics-fixture.ts` (VC7B).
11
+ */
12
+
13
+ import { readFileSync, existsSync } from "node:fs";
14
+ import { join, dirname } from "node:path";
15
+ import { fileURLToPath } from "node:url";
16
+
17
+ import type { PolicyInput } from "./types.js";
18
+ import type {
19
+ M7Host,
20
+ PressureV1Row,
21
+ PressureV2Row,
22
+ } from "../migrations/pressure-v2-types.js";
23
+
24
+ const here = dirname(fileURLToPath(import.meta.url));
25
+
26
+ function repoRoot(from: string): string {
27
+ let dir = from;
28
+ for (let i = 0; i < 8; i++) {
29
+ if (existsSync(join(dir, "conformance", "vector-cortex"))) return dir;
30
+ const next = dirname(dir);
31
+ if (next === dir) break;
32
+ dir = next;
33
+ }
34
+ throw new Error("conformance corpus not found above " + from);
35
+ }
36
+
37
+ const V2 = join(repoRoot(here), "conformance", "vector-cortex", "v2");
38
+ const DIR = join(V2, "adaptive-policy");
39
+
40
+ /** Read + parse one conformance fixture by ID from adaptive-policy/. */
41
+ export function adaptiveFixture(id: string): Record<string, unknown> {
42
+ const raw = readFileSync(join(DIR, `${id}.json`), "utf8");
43
+ return JSON.parse(raw);
44
+ }
45
+
46
+ /** Run `fn` with MEGACOMPACT_VC8B set to `value`, restoring the prior value after. */
47
+ export function withVc8bFlag<T>(value: string, fn: () => T): T {
48
+ const prior = process.env.MEGACOMPACT_VC8B;
49
+ process.env.MEGACOMPACT_VC8B = value;
50
+ try {
51
+ return fn();
52
+ } finally {
53
+ if (prior === undefined) delete process.env.MEGACOMPACT_VC8B;
54
+ else process.env.MEGACOMPACT_VC8B = prior;
55
+ }
56
+ }
57
+
58
+ // ── Policy decision fixtures (POL-001..025 + POL-CLAMP-001) ──────────────────
59
+
60
+ interface PolFxInput {
61
+ decisionId: string;
62
+ sessionId: string;
63
+ pressure: string;
64
+ requestedBudget: number;
65
+ bounds: { minBudget: number; maxBudget: number };
66
+ ts: string;
67
+ alternateRequestedBudget?: number;
68
+ }
69
+
70
+ interface PolFxExpected {
71
+ ok: boolean;
72
+ action?: string;
73
+ budget?: number;
74
+ pressure?: string;
75
+ reason?: string;
76
+ code?: string;
77
+ alternateBudget?: number;
78
+ alternateReason?: string;
79
+ }
80
+
81
+ export interface PolFx {
82
+ id: string;
83
+ assertion: string;
84
+ input: PolFxInput;
85
+ expected: PolFxExpected;
86
+ }
87
+
88
+ /** Read a policy-decision fixture as a typed PolFx. */
89
+ export function polFx(id: string): PolFx {
90
+ return adaptiveFixture(id) as unknown as PolFx;
91
+ }
92
+
93
+ /** Decode the fixture's JSON input into the production PolicyInput. */
94
+ export function toPolicyInput(fx: PolFx): PolicyInput {
95
+ return {
96
+ decisionId: fx.input.decisionId,
97
+ sessionId: fx.input.sessionId,
98
+ pressure: fx.input.pressure,
99
+ requestedBudget: fx.input.requestedBudget,
100
+ bounds: {
101
+ minBudget: fx.input.bounds.minBudget,
102
+ maxBudget: fx.input.bounds.maxBudget,
103
+ },
104
+ ts: fx.input.ts,
105
+ };
106
+ }
107
+
108
+ // ── Shadow fixtures (POL-SHADOW-002) ────────────────────────────────────────
109
+
110
+ interface ShadowFxInput {
111
+ inputs: readonly PolFxInput[];
112
+ promptBytes: string;
113
+ }
114
+
115
+ interface ShadowFxExpected {
116
+ ok: boolean;
117
+ evaluated?: number;
118
+ clamped?: number;
119
+ rejected?: number;
120
+ liveMutations?: number;
121
+ promptUnchanged?: boolean;
122
+ }
123
+
124
+ export interface ShadowFx {
125
+ id: string;
126
+ assertion: string;
127
+ input: ShadowFxInput;
128
+ expected: ShadowFxExpected;
129
+ }
130
+
131
+ /** Read a policy-shadow fixture as a typed ShadowFx. */
132
+ export function shadowFx(id: string): ShadowFx {
133
+ return adaptiveFixture(id) as unknown as ShadowFx;
134
+ }
135
+
136
+ /** Decode shadow input rows into production PolicyInput[]. */
137
+ export function toShadowInputs(fx: ShadowFx): readonly PolicyInput[] {
138
+ return fx.input.inputs.map((i) => ({
139
+ decisionId: i.decisionId,
140
+ sessionId: i.sessionId,
141
+ pressure: i.pressure,
142
+ requestedBudget: i.requestedBudget,
143
+ bounds: {
144
+ minBudget: i.bounds.minBudget,
145
+ maxBudget: i.bounds.maxBudget,
146
+ },
147
+ ts: i.ts,
148
+ }));
149
+ }
150
+
151
+ // ── M7 pressure-v2 fixtures (M7-001..015 + M7-PRESSURE-003) ─────────────────
152
+
153
+ interface M7FxInput {
154
+ scenario: string;
155
+ v1Rows: readonly {
156
+ sessionId: string;
157
+ label: string;
158
+ effectiveSeq: number;
159
+ ts: string;
160
+ }[];
161
+ injectedRow?: {
162
+ sessionId: string;
163
+ label: string;
164
+ effectiveSeq: number;
165
+ ts: string;
166
+ };
167
+ activeVersion?: number;
168
+ }
169
+
170
+ interface M7FxExpected {
171
+ ok: boolean;
172
+ codes?: string[];
173
+ code?: string;
174
+ activeVersionAfter?: number;
175
+ rowCount?: number;
176
+ }
177
+
178
+ export interface M7Fx {
179
+ id: string;
180
+ assertion: string;
181
+ input: M7FxInput;
182
+ expected: M7FxExpected;
183
+ }
184
+
185
+ /** Read an M7 fixture as a typed M7Fx. */
186
+ export function m7Fx(id: string): M7Fx {
187
+ return adaptiveFixture(id) as unknown as M7Fx;
188
+ }
189
+
190
+ /** Build an in-memory M7Host from the fixture input. */
191
+ export function toM7Host(
192
+ fx: M7Fx,
193
+ ): M7Host & { activeVersionAfter: number; readonly v2RowCount: number } {
194
+ const v1Rows: PressureV1Row[] = fx.input.v1Rows.map((r) => ({
195
+ sessionId: r.sessionId,
196
+ label: r.label,
197
+ effectiveSeq: r.effectiveSeq,
198
+ ts: r.ts,
199
+ }));
200
+ // For inject-after-copy, the injected row carries a non-canonical label.
201
+ // migratePressureV2 calls m7Copy first, which throws M7_PRESSURE_UNKNOWN for
202
+ // the bad label — the result is the same: ok:false, pointer on v1.
203
+ if (fx.input.injectedRow) {
204
+ v1Rows.push({
205
+ sessionId: fx.input.injectedRow.sessionId,
206
+ label: fx.input.injectedRow.label,
207
+ effectiveSeq: fx.input.injectedRow.effectiveSeq,
208
+ ts: fx.input.injectedRow.ts,
209
+ });
210
+ }
211
+ const v2Rows: PressureV2Row[] = [];
212
+ let activeVersion = fx.input.activeVersion ?? 1;
213
+
214
+ const host: M7Host & { activeVersionAfter: number; readonly v2RowCount: number } = {
215
+ v1Rows: () => v1Rows,
216
+ existingV2: () => v2Rows,
217
+ putV2: (rows) => v2Rows.push(...rows),
218
+ activeVersion: () => activeVersion,
219
+ switchToV2: () => {
220
+ activeVersion = 2;
221
+ },
222
+ get activeVersionAfter() {
223
+ return activeVersion;
224
+ },
225
+ get v2RowCount() {
226
+ return v2Rows.length;
227
+ },
228
+ };
229
+ return host;
230
+ }
@@ -176,7 +176,7 @@ export function evaluatePolicy(input: PolicyInput): PolicyDecisionV1 {
176
176
  action: PRESSURE_ACTION[pressure],
177
177
  budget,
178
178
  pressure,
179
- reason: reasonFor(pressure, input.requestedBudget, budget, bounds),
179
+ reason: reasonFor(pressure, adjusted, budget, bounds),
180
180
  ts: input.ts,
181
181
  };
182
182
  }