pi-mega-compact 0.20.41 → 0.20.43

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 (112) hide show
  1. package/assets/vector-cortex/encoder-v1/manifest.json +1 -1
  2. package/dist/config/vector-cortex-dedup-attr.js +14 -0
  3. package/dist/config/vector-cortex-enc0a.js +32 -0
  4. package/dist/config/vector-cortex.js +3 -3
  5. package/dist/config.js +1 -1
  6. package/dist/extensions/dashboard-server/api-contracts/dedup-attribution.js +13 -0
  7. package/dist/extensions/dashboard-server/api-contracts/endpoints/registry-ext.js +7 -0
  8. package/dist/extensions/dashboard-server/route-dispatch.js +3 -1
  9. package/dist/extensions/dashboard-server/routes-dedup-attribution.js +150 -0
  10. package/dist/extensions/dashboard-server/routes-rag-settings-vector-cortex.js +2 -0
  11. package/dist/extensions/dashboard-server/routes.js +1 -0
  12. package/dist/src/config/vector-cortex-dedup-attr.js +14 -0
  13. package/dist/src/config/vector-cortex-enc0a.js +32 -0
  14. package/dist/src/config/vector-cortex.js +3 -3
  15. package/dist/src/config.js +1 -1
  16. package/dist/src/vector-cortex/_acceptance-enc0a-contract.js +60 -0
  17. package/dist/src/vector-cortex/_acceptance-vc2a-conformance.js +90 -0
  18. package/dist/src/vector-cortex/_acceptance-vc2a-runtime.js +285 -0
  19. package/dist/src/vector-cortex/_acceptance-vc2b-conformance.js +92 -0
  20. package/dist/src/vector-cortex/_acceptance-vc2b-heads.js +221 -0
  21. package/dist/src/vector-cortex/dedup-attr/rollup.js +97 -0
  22. package/dist/src/vector-cortex/encoder/asset.js +3 -2
  23. package/dist/src/vector-cortex/encoder/decision.js +75 -0
  24. package/dist/src/vector-cortex/encoder/types-vc2c.js +41 -0
  25. package/dist/src/vector-cortex/encoder/types.js +13 -34
  26. package/dist/vector-cortex/_acceptance-enc0a-contract.js +60 -0
  27. package/dist/vector-cortex/_acceptance-vc2a-conformance.js +90 -0
  28. package/dist/vector-cortex/_acceptance-vc2a-runtime.js +285 -0
  29. package/dist/vector-cortex/_acceptance-vc2b-conformance.js +92 -0
  30. package/dist/vector-cortex/_acceptance-vc2b-heads.js +221 -0
  31. package/dist/vector-cortex/dedup-attr/rollup.js +97 -0
  32. package/dist/vector-cortex/encoder/asset.js +3 -2
  33. package/dist/vector-cortex/encoder/decision.js +75 -0
  34. package/dist/vector-cortex/encoder/types-vc2c.js +41 -0
  35. package/dist/vector-cortex/encoder/types.js +13 -34
  36. package/extensions/dashboard-client/dist/assets/{AreaChart-BT7YPcp7.js → AreaChart-Cn6X7epL.js} +2 -2
  37. package/extensions/dashboard-client/dist/assets/{AreaChart-BT7YPcp7.js.map → AreaChart-Cn6X7epL.js.map} +1 -1
  38. package/extensions/dashboard-client/dist/assets/{BarChart-DceGcBUh.js → BarChart-APy1Wc7z.js} +2 -2
  39. package/extensions/dashboard-client/dist/assets/{BarChart-DceGcBUh.js.map → BarChart-APy1Wc7z.js.map} +1 -1
  40. package/extensions/dashboard-client/dist/assets/{CacheTab-B9lCouRl.js → CacheTab-CEv_Ss9O.js} +2 -2
  41. package/extensions/dashboard-client/dist/assets/{CacheTab-B9lCouRl.js.map → CacheTab-CEv_Ss9O.js.map} +1 -1
  42. package/extensions/dashboard-client/dist/assets/{EventsTab-oqJ11jY7.js → EventsTab-8jV1Pr0C.js} +2 -2
  43. package/extensions/dashboard-client/dist/assets/{EventsTab-oqJ11jY7.js.map → EventsTab-8jV1Pr0C.js.map} +1 -1
  44. package/extensions/dashboard-client/dist/assets/{HealthTab-Dbosf2Ik.js → HealthTab-B2VgEz1j.js} +2 -2
  45. package/extensions/dashboard-client/dist/assets/{HealthTab-Dbosf2Ik.js.map → HealthTab-B2VgEz1j.js.map} +1 -1
  46. package/extensions/dashboard-client/dist/assets/{MaintenanceTab-6TiApCVE.js → MaintenanceTab-m37AlTbg.js} +2 -2
  47. package/extensions/dashboard-client/dist/assets/{MaintenanceTab-6TiApCVE.js.map → MaintenanceTab-m37AlTbg.js.map} +1 -1
  48. package/extensions/dashboard-client/dist/assets/{MemoryMapTab-cBsE4mTf.js → MemoryMapTab-Co2jbqdT.js} +2 -2
  49. package/extensions/dashboard-client/dist/assets/{MemoryMapTab-cBsE4mTf.js.map → MemoryMapTab-Co2jbqdT.js.map} +1 -1
  50. package/extensions/dashboard-client/dist/assets/{MetricsTab-CX-X9hhy.js → MetricsTab-D0yV9X6D.js} +2 -2
  51. package/extensions/dashboard-client/dist/assets/{MetricsTab-CX-X9hhy.js.map → MetricsTab-D0yV9X6D.js.map} +1 -1
  52. package/extensions/dashboard-client/dist/assets/{OverviewTab-CpPYaTJF.js → OverviewTab-J5TjXB14.js} +2 -2
  53. package/extensions/dashboard-client/dist/assets/{OverviewTab-CpPYaTJF.js.map → OverviewTab-J5TjXB14.js.map} +1 -1
  54. package/extensions/dashboard-client/dist/assets/{ReposTab-D_Ot4QbU.js → ReposTab-BadNIkWu.js} +2 -2
  55. package/extensions/dashboard-client/dist/assets/{ReposTab-D_Ot4QbU.js.map → ReposTab-BadNIkWu.js.map} +1 -1
  56. package/extensions/dashboard-client/dist/assets/{SessionsTab-BUzO3iGK.js → SessionsTab-CdKShJuR.js} +2 -2
  57. package/extensions/dashboard-client/dist/assets/{SessionsTab-BUzO3iGK.js.map → SessionsTab-CdKShJuR.js.map} +1 -1
  58. package/extensions/dashboard-client/dist/assets/{SetupTab-Be4w9v4j.js → SetupTab-CPemizDx.js} +2 -2
  59. package/extensions/dashboard-client/dist/assets/{SetupTab-Be4w9v4j.js.map → SetupTab-CPemizDx.js.map} +1 -1
  60. package/extensions/dashboard-client/dist/assets/{TimeSavedCard-Cx-g6CXH.js → TimeSavedCard-TvULibwW.js} +2 -2
  61. package/extensions/dashboard-client/dist/assets/{TimeSavedCard-Cx-g6CXH.js.map → TimeSavedCard-TvULibwW.js.map} +1 -1
  62. package/extensions/dashboard-client/dist/assets/{TurnsTab-CC_7T7ad.js → TurnsTab-CglFIcYy.js} +2 -2
  63. package/extensions/dashboard-client/dist/assets/{TurnsTab-CC_7T7ad.js.map → TurnsTab-CglFIcYy.js.map} +1 -1
  64. package/extensions/dashboard-client/dist/assets/{VcStatusBadge-ZTItXSiH.js → VcStatusBadge-H2bBNhrR.js} +2 -2
  65. package/extensions/dashboard-client/dist/assets/{VcStatusBadge-ZTItXSiH.js.map → VcStatusBadge-H2bBNhrR.js.map} +1 -1
  66. package/extensions/dashboard-client/dist/assets/{VectorCortexTab-DgAUZ4Pg.js → VectorCortexTab-CXPv3sYQ.js} +2 -2
  67. package/extensions/dashboard-client/dist/assets/{VectorCortexTab-DgAUZ4Pg.js.map → VectorCortexTab-CXPv3sYQ.js.map} +1 -1
  68. package/extensions/dashboard-client/dist/assets/{WikiTab-DnKupXTv.js → WikiTab-BNfN175_.js} +2 -2
  69. package/extensions/dashboard-client/dist/assets/{WikiTab-DnKupXTv.js.map → WikiTab-BNfN175_.js.map} +1 -1
  70. package/extensions/dashboard-client/dist/assets/{button-CFt3e0yc.js → button-DjN7aqD2.js} +2 -2
  71. package/extensions/dashboard-client/dist/assets/{button-CFt3e0yc.js.map → button-DjN7aqD2.js.map} +1 -1
  72. package/extensions/dashboard-client/dist/assets/{card-C6ZjsHrl.js → card-DLHA5XP8.js} +2 -2
  73. package/extensions/dashboard-client/dist/assets/{card-C6ZjsHrl.js.map → card-DLHA5XP8.js.map} +1 -1
  74. package/extensions/dashboard-client/dist/assets/{client-extra-DdEdGTIe.js → client-extra-ZT6mIQZS.js} +2 -2
  75. package/extensions/dashboard-client/dist/assets/{client-extra-DdEdGTIe.js.map → client-extra-ZT6mIQZS.js.map} +1 -1
  76. package/extensions/dashboard-client/dist/assets/{generateCategoricalChart-C9_fu2hc.js → generateCategoricalChart-DAl4dRVG.js} +2 -2
  77. package/extensions/dashboard-client/dist/assets/{generateCategoricalChart-C9_fu2hc.js.map → generateCategoricalChart-DAl4dRVG.js.map} +1 -1
  78. package/extensions/dashboard-client/dist/assets/{index-DY81TY4f.js → index-H-sfROoW.js} +16 -16
  79. package/extensions/dashboard-client/dist/assets/index-H-sfROoW.js.map +1 -0
  80. package/extensions/dashboard-client/dist/assets/{switch-BOqa1d6x.js → switch-BCxvJYon.js} +2 -2
  81. package/extensions/dashboard-client/dist/assets/{switch-BOqa1d6x.js.map → switch-BCxvJYon.js.map} +1 -1
  82. package/extensions/dashboard-client/dist/assets/{toggle-DToFaIEd.js → toggle-DviUMYeg.js} +2 -2
  83. package/extensions/dashboard-client/dist/assets/{toggle-DToFaIEd.js.map → toggle-DviUMYeg.js.map} +1 -1
  84. package/extensions/dashboard-client/dist/assets/{useSSE-CZqkhU18.js → useSSE-DP2O8vHY.js} +2 -2
  85. package/extensions/dashboard-client/dist/assets/{useSSE-CZqkhU18.js.map → useSSE-DP2O8vHY.js.map} +1 -1
  86. package/extensions/dashboard-client/dist/index.html +1 -1
  87. package/extensions/dashboard-server/api-contracts/dedup-attribution.ts +69 -0
  88. package/extensions/dashboard-server/api-contracts/endpoints/registry-ext.ts +15 -0
  89. package/extensions/dashboard-server/api-contracts/index.ts +8 -0
  90. package/extensions/dashboard-server/route-dispatch.ts +2 -0
  91. package/extensions/dashboard-server/routes-dedup-attribution.ts +166 -0
  92. package/extensions/dashboard-server/routes-rag-settings-vector-cortex.ts +12 -0
  93. package/extensions/dashboard-server/routes.ts +1 -0
  94. package/package.json +1 -1
  95. package/src/config/vector-cortex-dedup-attr.ts +16 -0
  96. package/src/config/vector-cortex-enc0a.ts +34 -0
  97. package/src/config/vector-cortex.ts +3 -3
  98. package/src/config.ts +2 -0
  99. package/src/vector-cortex/_acceptance-enc0a-contract.ts +71 -0
  100. package/src/vector-cortex/_acceptance-vc2a-conformance.ts +119 -0
  101. package/src/vector-cortex/_acceptance-vc2a-runtime.ts +300 -0
  102. package/src/vector-cortex/_acceptance-vc2b-conformance.ts +121 -0
  103. package/src/vector-cortex/_acceptance-vc2b-heads.ts +234 -0
  104. package/src/vector-cortex/dedup-attr/rollup.ts +136 -0
  105. package/src/vector-cortex/encoder/asset.ts +3 -2
  106. package/src/vector-cortex/encoder/bench-export.ts +2 -2
  107. package/src/vector-cortex/encoder/decision.ts +125 -0
  108. package/src/vector-cortex/encoder/runtime-native.ts +1 -1
  109. package/src/vector-cortex/encoder/runtime-wasm.ts +1 -1
  110. package/src/vector-cortex/encoder/types-vc2c.ts +124 -0
  111. package/src/vector-cortex/encoder/types.ts +18 -115
  112. package/extensions/dashboard-client/dist/assets/index-DY81TY4f.js.map +0 -1
@@ -1 +1 @@
1
- {"batch":1,"heads":{"cacheStability":64,"contradiction":128,"dependency":128,"payloadRouting":32,"semantic":384},"hiddenWidth":384,"maxTokens":512,"modelVersion":"encoder-v1-placeholder","onnx":{"bytes":42,"path":"model.onnx","sha256":"01cbed8b0b301609542ff8c392c3e7d927b0d848ac53a768dfffd33bfe6005ff"},"opset":17,"platform":"linux-x64","schema":"model-manifest-v1","semanticWidth":384,"tokenizer":{"bytes":8518,"path":"tokenizer.json","sha256":"ada18e5c4dfcb5c369c05f4ffc10bc40298ce707e78f16135c6d33019f6db8cd"},"totalBytes":8560,"trainingManifestDigest":"e9b2550dbb79141af84440dda65ca21d3509904b2c09a89316145137a5b5e3de"}
1
+ {"batch":1,"heads":{"cacheStability":64,"contradiction":128,"dependency":128,"payloadRouting":32,"semantic":384},"hiddenWidth":384,"maxTokens":512,"modelVersion":"encoder-v1-placeholder","onnx":{"bytes":42,"path":"model.onnx","sha256":"01cbed8b0b301609542ff8c392c3e7d927b0d848ac53a768dfffd33bfe6005ff"},"opset":21,"platform":"linux-x64","schema":"model-manifest-v1","semanticWidth":384,"tokenizer":{"bytes":8518,"path":"tokenizer.json","sha256":"ada18e5c4dfcb5c369c05f4ffc10bc40298ce707e78f16135c6d33019f6db8cd"},"totalBytes":8560,"trainingManifestDigest":"e9b2550dbb79141af84440dda65ca21d3509904b2c09a89316145137a5b5e3de"}
@@ -0,0 +1,14 @@
1
+ /**
2
+ * config/vector-cortex-dedup-attr.ts — DEDUP-ATTR tier-attribution flag.
3
+ *
4
+ * The single positive sprint flag for the dedup tier-attribution rollup
5
+ * (external-audit item #6). Default ON; `MEGACOMPACT_DEDUP_ATTR=0` / `=false` /
6
+ * `_DISABLED=true` disables and is byte-identical to the predecessor: the
7
+ * `/api/dedup-tier-attribution` endpoint 404s and no rollup cache file is
8
+ * written.
9
+ *
10
+ * Pi-agnostic, dependency-free (PREVENT-PI-004 / PREVENT-011).
11
+ */
12
+ import { sprintFlag } from "./vector-cortex-flag.js";
13
+ /** Positive sprint flag: `=0` or `_DISABLED=true` disables (default ON). */
14
+ export const DEDUP_ATTR_ENABLED = () => sprintFlag("MEGACOMPACT_DEDUP_ATTR");
@@ -0,0 +1,32 @@
1
+ /**
2
+ * config/vector-cortex-enc0a.ts — ENC-0a learned-encoder backend-decision 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-vc9a.ts..vector-cortex-vc9d.ts
6
+ * were. This is the first ENC (real learned encoder) sprint flag. vector-cortex.ts
7
+ * re-exports the ENUM below and root src/config.ts re-exports it, so no consumer
8
+ * import path changes.
9
+ *
10
+ * ENC-0a locks the runtime-backend choice (transformers.js/WASM vs
11
+ * onnxruntime-node native), the per-platform install-size matrix, the opset
12
+ * baseline (re-baselined 17 -> 21) and the license/pinning audit. It writes a
13
+ * durable decision record and bench JSON but touches neither the store schema
14
+ * nor stateDir tables (pure migration).
15
+ *
16
+ * The split is purely mechanical: ENC_0A_ENABLED is byte-identical in name,
17
+ * semantics, and default to the definition it replaces, and vector-cortex.ts
18
+ * re-exports it so every existing `from "./config/vector-cortex.js"` import
19
+ * keeps resolving unchanged.
20
+ *
21
+ * Pi-agnostic, dependency-free (PREVENT-PI-004 / PREVENT-011).
22
+ */
23
+ import { sprintFlag } from "./vector-cortex-flag.js";
24
+ /**
25
+ * ENC-0a — learned-encoder backend-decision lock. Default ON.
26
+ * `MEGACOMPACT_ENC_0A=0` disables and is byte-identical to the predecessor
27
+ * (placeholder encoder): no decision record is written and no newer
28
+ * backend-resolution script runs — the runtime keeps serving mode B trigram
29
+ * exactly as before. This flag MUST also be a dashboard SETTINGS toggle (visible
30
+ * in config UI, never in EXCLUDED_SETTINGS), mirroring VC4A..VC9D.
31
+ */
32
+ export const ENC_0A_ENABLED = () => sprintFlag("MEGACOMPACT_ENC_0A");
@@ -5,8 +5,7 @@
5
5
  * `=0`/`_DISABLED` off. Flag-OFF is byte-identical to the predecessor sprint's
6
6
  * behavior (for VC0A: mode C — observer absent, zero evaluation writes).
7
7
  *
8
- * The breaker/triad constants (TRIAD_RESILIENCE.md) live here so VC0C consumes
9
- * them without re-declaring the ownership boundary. Pi-agnostic, dependency-free.
8
+ * Breaker/triad constants (TRIAD_RESILIENCE.md) live here; pi-agnostic, dep-free.
10
9
  */
11
10
  import { sprintFlag } from "./vector-cortex-flag.js";
12
11
  // VC0/VC1/VC2 foundation-phase flags in vector-cortex-early.ts; re-exported
@@ -240,7 +239,6 @@ export const VC8A_ENABLED = () => sprintFlag("MEGACOMPACT_VC8A");
240
239
  export const VC8B_ENABLED = () => sprintFlag("MEGACOMPACT_VC8B");
241
240
  // VC8C extracted to vector-cortex-vc8c.ts; re-exported so existing imports keep resolving.
242
241
  export { VC8C_ENABLED } from "./vector-cortex-vc8c.js";
243
- // Sibling extracts: stay under the 300-line soft limit.
244
242
  export { VC9A_ENABLED } from "./vector-cortex-vc9a.js";
245
243
  export { VC9B_ENABLED } from "./vector-cortex-vc9b.js";
246
244
  export { VC9C_ENABLED } from "./vector-cortex-vc9c.js";
@@ -251,5 +249,7 @@ export { ML5B_ENABLED } from "./vector-cortex-ml5b.js";
251
249
  export { ML5C_ENABLED } from "./vector-cortex-ml5c.js";
252
250
  export { ML5D_ENABLED } from "./vector-cortex-ml5d.js";
253
251
  export { ML5E_ENABLED } from "./vector-cortex-ml5e.js";
252
+ export { DEDUP_ATTR_ENABLED } from "./vector-cortex-dedup-attr.js";
253
+ export { ENC_0A_ENABLED } from "./vector-cortex-enc0a.js";
254
254
  // Breaker constants (TRIAD_RESILIENCE.md §breaker) extracted to vector-cortex-breakers.ts.
255
255
  export { BREAKER_WINDOW_MS, BREAKER_MIN_ATTEMPTS, BREAKER_PERF_FAILURES, BREAKER_PERF_FAILURE_RATE, BREAKER_CORRECTNESS_FAILURES, BREAKER_COOLDOWN_MS, BREAKER_PROBE_COUNT, BREAKER_RETRY_BASE_MS, BREAKER_RETRY_CAP_MS, BREAKER_RETRY_JITTER, BREAKER_HYSTERESIS_FAILURE_RATE, BREAKER_HYSTERESIS_BUDGET_P95_MS, BREAKER_MIN_HEALTHY_RESIDENCE_MS, } from "./vector-cortex-breakers.js";
package/dist/config.js CHANGED
@@ -114,4 +114,4 @@ export const NEW_UI = () => ragEnabled("MEGACOMPACT_NEW_UI");
114
114
  // default ON, `=0`/`_DISABLED` off. Re-exported from src/config/vector-cortex.ts
115
115
  // so root consumers share one source of truth.
116
116
  // ---------------------------------------------------------------------------
117
- export { VC0A_ENABLED, VC0B_ENABLED, VC1A_ENABLED, VC0C_ENABLED, VC1B_ENABLED, VC1C_ENABLED, VC2A_ENABLED, VC2B_ENABLED, VC2C_ENABLED, VC3A_ENABLED, VC3B_ENABLED, VC3C_ENABLED, VC4A_ENABLED, VC4B_ENABLED, VC4C_ENABLED, VC5A_ENABLED, VC5B_ENABLED, VC5C_ENABLED, VC6A_ENABLED, VC6B_ENABLED, VC6C_ENABLED, VC7A_ENABLED, VC7B_ENABLED, VC7C_ENABLED, VC8A_ENABLED, VC8B_ENABLED, VC8C_ENABLED, VC9A_ENABLED, VC9B_ENABLED, VC9C_ENABLED, VC9D_ENABLED, PCC_ENABLED, ML5A_ENABLED, ML5B_ENABLED, ML5C_ENABLED, ML5D_ENABLED, ML5E_ENABLED, BREAKER_WINDOW_MS, BREAKER_MIN_ATTEMPTS, BREAKER_PERF_FAILURES, BREAKER_PERF_FAILURE_RATE, BREAKER_CORRECTNESS_FAILURES, BREAKER_COOLDOWN_MS, BREAKER_PROBE_COUNT, BREAKER_RETRY_BASE_MS, BREAKER_RETRY_CAP_MS, BREAKER_RETRY_JITTER, BREAKER_HYSTERESIS_FAILURE_RATE, BREAKER_HYSTERESIS_BUDGET_P95_MS, BREAKER_MIN_HEALTHY_RESIDENCE_MS, } from "./config/vector-cortex.js";
117
+ export { VC0A_ENABLED, VC0B_ENABLED, VC1A_ENABLED, VC0C_ENABLED, VC1B_ENABLED, VC1C_ENABLED, VC2A_ENABLED, VC2B_ENABLED, VC2C_ENABLED, VC3A_ENABLED, VC3B_ENABLED, VC3C_ENABLED, VC4A_ENABLED, VC4B_ENABLED, VC4C_ENABLED, VC5A_ENABLED, VC5B_ENABLED, VC5C_ENABLED, VC6A_ENABLED, VC6B_ENABLED, VC6C_ENABLED, VC7A_ENABLED, VC7B_ENABLED, VC7C_ENABLED, VC8A_ENABLED, VC8B_ENABLED, VC8C_ENABLED, VC9A_ENABLED, VC9B_ENABLED, VC9C_ENABLED, VC9D_ENABLED, PCC_ENABLED, ML5A_ENABLED, ML5B_ENABLED, ML5C_ENABLED, ML5D_ENABLED, ML5E_ENABLED, DEDUP_ATTR_ENABLED, ENC_0A_ENABLED, BREAKER_WINDOW_MS, BREAKER_MIN_ATTEMPTS, BREAKER_PERF_FAILURES, BREAKER_PERF_FAILURE_RATE, BREAKER_CORRECTNESS_FAILURES, BREAKER_COOLDOWN_MS, BREAKER_PROBE_COUNT, BREAKER_RETRY_BASE_MS, BREAKER_RETRY_CAP_MS, BREAKER_RETRY_JITTER, BREAKER_HYSTERESIS_FAILURE_RATE, BREAKER_HYSTERESIS_BUDGET_P95_MS, BREAKER_MIN_HEALTHY_RESIDENCE_MS, } from "./config/vector-cortex.js";
@@ -0,0 +1,13 @@
1
+ /**
2
+ * api-contracts/dedup-attribution.ts — Dedup tier-attribution rollup types (DEDUP-ATTR).
3
+ *
4
+ * Types for GET /api/dedup-tier-attribution — the reader-only aggregate that
5
+ * answers "L0/L1/L2/new percent of dedup decisions in window W". Inputs are the
6
+ * produced `dedup_audit` events in the local events.log (shape DedupAuditEvent
7
+ * in src/vectorStore/dedup-audit.ts). Outputs are counts + shares only — never
8
+ * matched checkpoint paths/text, never raw user query (EVAL-REDACT-002).
9
+ *
10
+ * PREVENT-PI-004: type definitions only, no network code.
11
+ * PREVENT-011: no `any` type — all types are explicit.
12
+ */
13
+ export {};
@@ -67,4 +67,11 @@ export const EXTRA_ENDPOINTS = {
67
67
  path: "/api/cortex/improve/status/:jobId",
68
68
  description: "Poll an in-process Cortex improve job to terminal qualified / demoted_to_B. Unknown jobId or flag-off returns 404. Read-only, in-memory job state.",
69
69
  },
70
+ // ─── DEDUP-ATTR tier-attribution rollup ───────────────────────────
71
+ /** GET /api/dedup-tier-attribution — reader-only per-tier dedup shares. */
72
+ dedupTierAttribution: {
73
+ method: "GET",
74
+ path: "/api/dedup-tier-attribution",
75
+ description: "Reader-only dedup tier-attribution rollup (DEDUP-ATTR): L0/L1/L2/new percent of dedup decisions in a query window (default 24h, ?windowMs=, capped 30d). Counts + shares only, never matched checkpoint contents or raw query text. Flag-off returns 404.",
76
+ },
70
77
  };
@@ -8,7 +8,7 @@
8
8
  * PREVENT-PI-004: local filesystem read only, no network.
9
9
  * PREVENT-011: no `any` type.
10
10
  */
11
- import { handleIndex, handleRepoIndex, handleEvents, handleGameState, handleGameScores, handlePerfSamples, handlePerf, handleAchievements, handleSessions, handleTopics, handleTurns, handleMaintenance, handleProviderCache, handleMemoryStatus, handleCacheStripes, handlePrefixStability, handleSetupStatus, handleSetupDetect, handleSetupConfigure, handleMemoryMap, handleRaptorTree, handleRaptorBuildHistory, handleContextHealth, handleCachePoison, handleHealthSettings, handleEmbedderHealth, handleRagSettings, handleRagMetrics, handleModelThresholds, handleWiki, handleVectorCortexEvaluation, handleVectorCortexHealth, handleVectorCortexBreakersReset, handleVectorCortexLedger, handleVectorCortexTopology, handleVectorCortexQuery, handleVectorCortexShards, handleVectorCortexResidual, handleVectorCortexReconstruct, handleVectorCortexPlans, handleVectorCortexRender, handleVectorCortexRollout, handleVectorCortexClosureProof, handleVectorCortexRestore, handleSetupCortexStatus, handleSetupCortexAction, handleSetupCortexActionLog, handleImproveCortex, handleImproveCortexStatus, } from "./routes.js";
11
+ import { handleIndex, handleRepoIndex, handleEvents, handleGameState, handleGameScores, handlePerfSamples, handlePerf, handleAchievements, handleSessions, handleTopics, handleTurns, handleMaintenance, handleProviderCache, handleMemoryStatus, handleCacheStripes, handlePrefixStability, handleSetupStatus, handleSetupDetect, handleSetupConfigure, handleMemoryMap, handleRaptorTree, handleRaptorBuildHistory, handleContextHealth, handleCachePoison, handleHealthSettings, handleEmbedderHealth, handleRagSettings, handleRagMetrics, handleModelThresholds, handleWiki, handleVectorCortexEvaluation, handleVectorCortexHealth, handleVectorCortexBreakersReset, handleVectorCortexLedger, handleVectorCortexTopology, handleVectorCortexQuery, handleVectorCortexShards, handleVectorCortexResidual, handleVectorCortexReconstruct, handleVectorCortexPlans, handleVectorCortexRender, handleVectorCortexRollout, handleVectorCortexClosureProof, handleVectorCortexRestore, handleSetupCortexStatus, handleSetupCortexAction, handleSetupCortexActionLog, handleImproveCortex, handleImproveCortexStatus, handleDedupTierAttribution, } from "./routes.js";
12
12
  // VC6C repair lives in its own module (routes-vector-cortex-repair.ts) so the
13
13
  // heal route file stays well under the 400-line extension soft limit.
14
14
  import { handleVectorCortexRepair } from "./routes-vector-cortex-repair.js";
@@ -153,5 +153,7 @@ export function dispatchRoutes(req, res, ctx) {
153
153
  return true;
154
154
  if (handleImproveCortexStatus(req, res, ctx))
155
155
  return true;
156
+ if (handleDedupTierAttribution(req, res, ctx))
157
+ return true;
156
158
  return false;
157
159
  }
@@ -0,0 +1,150 @@
1
+ /**
2
+ * dashboard-server/routes-dedup-attribution.ts — DEDUP-ATTR tier attribution route.
3
+ *
4
+ * GET /api/dedup-tier-attribution?windowMs=<n> — reader-only aggregate answering
5
+ * "L0/L1/L2/new percent of dedup decisions in window W". Reads the repo's local
6
+ * events.log (per-repo stateDir, bounded 8 MiB tail), parses `dedup_audit` lines
7
+ * (PREVENT-001 guarded), and sends the pure rollup with a shared-derived status.
8
+ *
9
+ * Flag-off (MEGACOMPACT_DEDUP_ATTR=0) returns 404 and writes NO durable cache
10
+ * file — byte-identical predecessor. Reader-only: emits tier counts + shares,
11
+ * never matched checkpoint paths/text, never raw user query (EVAL-REDACT-002).
12
+ *
13
+ * Memoization mirrors routes-vector-cortex-health.ts: an in-memory facts cache
14
+ * keyed on {events.log mtime+size, windowMs} is served when ≤5s old, so repeated
15
+ * dashboard polls stay cheap while any on-disk log mutation still invalidates.
16
+ *
17
+ * Guardrails: PREVENT-PI-004 (local filesystem read + loopback response only),
18
+ * PREVENT-001 (JSON.parse guarded), PREVENT-011 (no `any`).
19
+ */
20
+ import { readFileSync, statSync, writeFileSync, mkdirSync } from "node:fs";
21
+ import { join, dirname } from "node:path";
22
+ import { sendJson } from "./routes-vector-cortex-shared.js";
23
+ import { DEDUP_ATTR_ENABLED } from "../../src/config.js";
24
+ import { computeDedupTierRollup } from "../../src/vector-cortex/dedup-attr/rollup.js";
25
+ import { deriveVcStatus } from "./vc-status.js";
26
+ const DEFAULT_WINDOW_MS = 24 * 60 * 60 * 1000; // 24h
27
+ const MAX_WINDOW_MS = 30 * 24 * 60 * 60 * 1000; // 30 days
28
+ const MAX_TAIL_BYTES = 8 * 1024 * 1024; // 8 MiB
29
+ const MEMO_TTL_MS = 5000; // ≤5s per stateDir
30
+ let memo = null;
31
+ /** Parse one events.log line into a DedupAuditEvent, or null (PREVENT-001). */
32
+ function parseAuditLine(line) {
33
+ if (!line.includes('"dedup_audit"'))
34
+ return null;
35
+ let parsed;
36
+ try {
37
+ parsed = JSON.parse(line);
38
+ }
39
+ catch {
40
+ return null;
41
+ }
42
+ if (!parsed || typeof parsed !== "object" || Array.isArray(parsed))
43
+ return null;
44
+ const obj = parsed;
45
+ if (obj.type !== "dedup_audit")
46
+ return null;
47
+ if (typeof obj.ts !== "string")
48
+ return null;
49
+ const tier = obj.tier;
50
+ const status = obj.status;
51
+ if (tier !== "L0" && tier !== "L1" && tier !== "L2" && tier !== "new")
52
+ return null;
53
+ if (status !== "deduped" && status !== "passed" && status !== "stored")
54
+ return null;
55
+ // sessionId is never read by the rollup; a parsed line may omit richer fields.
56
+ return { type: "dedup_audit", ts: obj.ts, tier, status, sessionId: "" };
57
+ }
58
+ /** Read the bounded tail of events.log into parsed dedup_audit events. */
59
+ function readAuditEvents(eventsPath) {
60
+ let buf;
61
+ try {
62
+ buf = readFileSync(eventsPath); // guardrails-allow PREVENT-PI-004: local events.log read (loopback dashboard)
63
+ }
64
+ catch {
65
+ return [];
66
+ }
67
+ const tail = buf.length > MAX_TAIL_BYTES ? buf.subarray(buf.length - MAX_TAIL_BYTES) : buf;
68
+ const text = tail.toString("utf-8");
69
+ const lines = text.split("\n");
70
+ // Drop a leading fragment when we truncated mid-line (first line may be partial).
71
+ const start = buf.length > MAX_TAIL_BYTES ? 1 : 0;
72
+ const out = [];
73
+ for (let i = start; i < lines.length; i++) {
74
+ const line = lines[i];
75
+ if (!line)
76
+ continue;
77
+ const ev = parseAuditLine(line);
78
+ if (ev)
79
+ out.push(ev);
80
+ }
81
+ return out;
82
+ }
83
+ /** Resolve windowMs from the ?windowMs= query param (default 24h, capped 30d). */
84
+ function resolveWindowMs(url) {
85
+ if (!url.includes("?"))
86
+ return DEFAULT_WINDOW_MS;
87
+ const params = new URLSearchParams(url.slice(url.indexOf("?")));
88
+ const raw = params.get("windowMs");
89
+ if (raw == null)
90
+ return DEFAULT_WINDOW_MS;
91
+ const n = Number(raw);
92
+ if (!Number.isFinite(n) || n <= 0)
93
+ return DEFAULT_WINDOW_MS;
94
+ return Math.min(n, MAX_WINDOW_MS);
95
+ }
96
+ /** Best-effort durable snapshot write (never breaks the response). */
97
+ function writeDurableSnapshot(stateDir, rollup) {
98
+ try {
99
+ mkdirSync(dirname(join(stateDir, "dedup-tier-attribution.json")), { recursive: true });
100
+ writeFileSync(join(stateDir, "dedup-tier-attribution.json"), `${JSON.stringify(rollup)}\n`, "utf-8");
101
+ }
102
+ catch {
103
+ /* best-effort — instrumentation must never break the read path */
104
+ }
105
+ }
106
+ export function handleDedupTierAttribution(req, res, ctx) {
107
+ const url = req.url ?? "";
108
+ const path = url.split("?", 1)[0] ?? url;
109
+ if (path !== "/api/dedup-tier-attribution")
110
+ return false;
111
+ if (req.method !== "GET") {
112
+ sendJson(res, 405, { error: "method_not_allowed" });
113
+ return true;
114
+ }
115
+ if (!DEDUP_ATTR_ENABLED()) {
116
+ // Flag-off: 404 + no durable cache write — byte-identical predecessor.
117
+ sendJson(res, 404, { error: "not_found" });
118
+ return true;
119
+ }
120
+ const eventsPath = ctx.eventsPath;
121
+ const windowMs = resolveWindowMs(url);
122
+ const now = new Date();
123
+ // Memoized-facts pattern (mirrors routes-vector-cortex-health.ts): serve a
124
+ // still-fresh entry keyed on {events.log mtime+size, windowMs}.
125
+ let keyBase = null;
126
+ try {
127
+ const s = statSync(eventsPath); // guardrails-allow PREVENT-PI-004: local events.log stat (loopback)
128
+ keyBase = { mtimeMs: s.mtimeMs, size: s.size };
129
+ }
130
+ catch {
131
+ keyBase = { mtimeMs: 0, size: 0 };
132
+ }
133
+ const key = `${keyBase.mtimeMs}:${keyBase.size}:${windowMs}`;
134
+ if (memo !== null && memo.key === key && now.getTime() - memo.at <= MEMO_TTL_MS) {
135
+ sendJson(res, 200, memo.body);
136
+ return true;
137
+ }
138
+ const auditEvents = readAuditEvents(eventsPath);
139
+ const rollup = computeDedupTierRollup(auditEvents, windowMs, now);
140
+ const status = deriveVcStatus({
141
+ enabled: true,
142
+ hasData: auditEvents.length > 0,
143
+ structuralOnly: false,
144
+ });
145
+ const body = { ...rollup, status };
146
+ memo = { key, at: now.getTime(), body };
147
+ writeDurableSnapshot(ctx.stateDir, body);
148
+ sendJson(res, 200, body);
149
+ return true;
150
+ }
@@ -57,5 +57,7 @@ export const VECTOR_CORTEX_SETTINGS = {
57
57
  boolDirect("MEGACOMPACT_ML5_C", "ML5-C Runtime Decision + Packaging", "ML5-C runtime backend selection (WASM vs native): selects the ONNX runtime backend based on the ML5-B bench record and platform support. ON (default) = the runtime-selection dispatch runs and emits vector_cortex_runtime_selected. OFF = no selection runs — encoder serves mode B trigram, byte-identical to ML5-B.", true),
58
58
  boolDirect("MEGACOMPACT_ML5_D", "ML5-D Dashboard Improve Cortex", "ML5-D dashboard 'Improve Cortex' surface: the ModelImprovementCard + POST /api/cortex/improve + GET /api/cortex/improve/status/:jobId. ON (default) = the card renders and Improve launches a local ML5-A training job. OFF = both improve endpoints return 404 and VectorCortexTab omits the card, byte-identical to ML5-C.", true),
59
59
  boolDirect("MEGACOMPACT_ML5_E", "ML5-E Nightly Retraining Cron", "ML5-E nightly retraining + feedback loop: the user's own post-redaction conversation turns become fresh training signal, the five heads are re-fit nightly via system cron, calibration is re-validated, and mode-A promotion is re-checked without human intervention. The cron is system-configured (crontab -e); the extension never installs or writes a crontab. Candidates are written to ~/.pi/mega-compact-encoder/candidates/ and promoted via the ML5-D Improve Cortex flow. ON (default) = the scripts may be invoked by the system cron. OFF = scripts are never invoked; byte-identical to ML5-D.", true),
60
+ boolDirect("MEGACOMPACT_DEDUP_ATTR", "Dedup Tier Attribution Rollup", "Dedup tier-attribution rollup: per-tier dedup catch shares (L0/L1/L2/new percent of dedup decisions) read from the local events.log dedup_audit stream (GET /api/dedup-tier-attribution). OFF = 404 + no cache file, byte-identical predecessor.", true),
61
+ boolDirect("MEGACOMPACT_ENC_0A", "ENC-0a Encoder Backend Decision", "ENC-0a learned-encoder backend-decision lock: records the transformers.js/WASM vs onnxruntime-node choice, per-platform install matrix, opset-21 baseline and pinned digests in docs/vector-cortex/encoder-backend-decision.md. OFF = no decision record written / no resolver runs, mode B trigram byte-identical predecessor.", true),
60
62
  ],
61
63
  };
@@ -28,3 +28,4 @@ export { handleVectorCortexEvaluation, handleVectorCortexHealth, handleVectorCor
28
28
  export { handleSetupCortexStatus } from "./routes-setup-cortex.js";
29
29
  export { handleSetupCortexAction, handleSetupCortexActionLog, } from "./routes-setup-cortex-actions.js";
30
30
  export { handleImproveCortex, handleImproveCortexStatus, } from "./routes-cortex-improve.js";
31
+ export { handleDedupTierAttribution } from "./routes-dedup-attribution.js";
@@ -0,0 +1,14 @@
1
+ /**
2
+ * config/vector-cortex-dedup-attr.ts — DEDUP-ATTR tier-attribution flag.
3
+ *
4
+ * The single positive sprint flag for the dedup tier-attribution rollup
5
+ * (external-audit item #6). Default ON; `MEGACOMPACT_DEDUP_ATTR=0` / `=false` /
6
+ * `_DISABLED=true` disables and is byte-identical to the predecessor: the
7
+ * `/api/dedup-tier-attribution` endpoint 404s and no rollup cache file is
8
+ * written.
9
+ *
10
+ * Pi-agnostic, dependency-free (PREVENT-PI-004 / PREVENT-011).
11
+ */
12
+ import { sprintFlag } from "./vector-cortex-flag.js";
13
+ /** Positive sprint flag: `=0` or `_DISABLED=true` disables (default ON). */
14
+ export const DEDUP_ATTR_ENABLED = () => sprintFlag("MEGACOMPACT_DEDUP_ATTR");
@@ -0,0 +1,32 @@
1
+ /**
2
+ * config/vector-cortex-enc0a.ts — ENC-0a learned-encoder backend-decision 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-vc9a.ts..vector-cortex-vc9d.ts
6
+ * were. This is the first ENC (real learned encoder) sprint flag. vector-cortex.ts
7
+ * re-exports the ENUM below and root src/config.ts re-exports it, so no consumer
8
+ * import path changes.
9
+ *
10
+ * ENC-0a locks the runtime-backend choice (transformers.js/WASM vs
11
+ * onnxruntime-node native), the per-platform install-size matrix, the opset
12
+ * baseline (re-baselined 17 -> 21) and the license/pinning audit. It writes a
13
+ * durable decision record and bench JSON but touches neither the store schema
14
+ * nor stateDir tables (pure migration).
15
+ *
16
+ * The split is purely mechanical: ENC_0A_ENABLED is byte-identical in name,
17
+ * semantics, and default to the definition it replaces, and vector-cortex.ts
18
+ * re-exports it so every existing `from "./config/vector-cortex.js"` import
19
+ * keeps resolving unchanged.
20
+ *
21
+ * Pi-agnostic, dependency-free (PREVENT-PI-004 / PREVENT-011).
22
+ */
23
+ import { sprintFlag } from "./vector-cortex-flag.js";
24
+ /**
25
+ * ENC-0a — learned-encoder backend-decision lock. Default ON.
26
+ * `MEGACOMPACT_ENC_0A=0` disables and is byte-identical to the predecessor
27
+ * (placeholder encoder): no decision record is written and no newer
28
+ * backend-resolution script runs — the runtime keeps serving mode B trigram
29
+ * exactly as before. This flag MUST also be a dashboard SETTINGS toggle (visible
30
+ * in config UI, never in EXCLUDED_SETTINGS), mirroring VC4A..VC9D.
31
+ */
32
+ export const ENC_0A_ENABLED = () => sprintFlag("MEGACOMPACT_ENC_0A");
@@ -5,8 +5,7 @@
5
5
  * `=0`/`_DISABLED` off. Flag-OFF is byte-identical to the predecessor sprint's
6
6
  * behavior (for VC0A: mode C — observer absent, zero evaluation writes).
7
7
  *
8
- * The breaker/triad constants (TRIAD_RESILIENCE.md) live here so VC0C consumes
9
- * them without re-declaring the ownership boundary. Pi-agnostic, dependency-free.
8
+ * Breaker/triad constants (TRIAD_RESILIENCE.md) live here; pi-agnostic, dep-free.
10
9
  */
11
10
  import { sprintFlag } from "./vector-cortex-flag.js";
12
11
  // VC0/VC1/VC2 foundation-phase flags in vector-cortex-early.ts; re-exported
@@ -240,7 +239,6 @@ export const VC8A_ENABLED = () => sprintFlag("MEGACOMPACT_VC8A");
240
239
  export const VC8B_ENABLED = () => sprintFlag("MEGACOMPACT_VC8B");
241
240
  // VC8C extracted to vector-cortex-vc8c.ts; re-exported so existing imports keep resolving.
242
241
  export { VC8C_ENABLED } from "./vector-cortex-vc8c.js";
243
- // Sibling extracts: stay under the 300-line soft limit.
244
242
  export { VC9A_ENABLED } from "./vector-cortex-vc9a.js";
245
243
  export { VC9B_ENABLED } from "./vector-cortex-vc9b.js";
246
244
  export { VC9C_ENABLED } from "./vector-cortex-vc9c.js";
@@ -251,5 +249,7 @@ export { ML5B_ENABLED } from "./vector-cortex-ml5b.js";
251
249
  export { ML5C_ENABLED } from "./vector-cortex-ml5c.js";
252
250
  export { ML5D_ENABLED } from "./vector-cortex-ml5d.js";
253
251
  export { ML5E_ENABLED } from "./vector-cortex-ml5e.js";
252
+ export { DEDUP_ATTR_ENABLED } from "./vector-cortex-dedup-attr.js";
253
+ export { ENC_0A_ENABLED } from "./vector-cortex-enc0a.js";
254
254
  // Breaker constants (TRIAD_RESILIENCE.md §breaker) extracted to vector-cortex-breakers.ts.
255
255
  export { BREAKER_WINDOW_MS, BREAKER_MIN_ATTEMPTS, BREAKER_PERF_FAILURES, BREAKER_PERF_FAILURE_RATE, BREAKER_CORRECTNESS_FAILURES, BREAKER_COOLDOWN_MS, BREAKER_PROBE_COUNT, BREAKER_RETRY_BASE_MS, BREAKER_RETRY_CAP_MS, BREAKER_RETRY_JITTER, BREAKER_HYSTERESIS_FAILURE_RATE, BREAKER_HYSTERESIS_BUDGET_P95_MS, BREAKER_MIN_HEALTHY_RESIDENCE_MS, } from "./vector-cortex-breakers.js";
@@ -114,4 +114,4 @@ export const NEW_UI = () => ragEnabled("MEGACOMPACT_NEW_UI");
114
114
  // default ON, `=0`/`_DISABLED` off. Re-exported from src/config/vector-cortex.ts
115
115
  // so root consumers share one source of truth.
116
116
  // ---------------------------------------------------------------------------
117
- export { VC0A_ENABLED, VC0B_ENABLED, VC1A_ENABLED, VC0C_ENABLED, VC1B_ENABLED, VC1C_ENABLED, VC2A_ENABLED, VC2B_ENABLED, VC2C_ENABLED, VC3A_ENABLED, VC3B_ENABLED, VC3C_ENABLED, VC4A_ENABLED, VC4B_ENABLED, VC4C_ENABLED, VC5A_ENABLED, VC5B_ENABLED, VC5C_ENABLED, VC6A_ENABLED, VC6B_ENABLED, VC6C_ENABLED, VC7A_ENABLED, VC7B_ENABLED, VC7C_ENABLED, VC8A_ENABLED, VC8B_ENABLED, VC8C_ENABLED, VC9A_ENABLED, VC9B_ENABLED, VC9C_ENABLED, VC9D_ENABLED, PCC_ENABLED, ML5A_ENABLED, ML5B_ENABLED, ML5C_ENABLED, ML5D_ENABLED, ML5E_ENABLED, BREAKER_WINDOW_MS, BREAKER_MIN_ATTEMPTS, BREAKER_PERF_FAILURES, BREAKER_PERF_FAILURE_RATE, BREAKER_CORRECTNESS_FAILURES, BREAKER_COOLDOWN_MS, BREAKER_PROBE_COUNT, BREAKER_RETRY_BASE_MS, BREAKER_RETRY_CAP_MS, BREAKER_RETRY_JITTER, BREAKER_HYSTERESIS_FAILURE_RATE, BREAKER_HYSTERESIS_BUDGET_P95_MS, BREAKER_MIN_HEALTHY_RESIDENCE_MS, } from "./config/vector-cortex.js";
117
+ export { VC0A_ENABLED, VC0B_ENABLED, VC1A_ENABLED, VC0C_ENABLED, VC1B_ENABLED, VC1C_ENABLED, VC2A_ENABLED, VC2B_ENABLED, VC2C_ENABLED, VC3A_ENABLED, VC3B_ENABLED, VC3C_ENABLED, VC4A_ENABLED, VC4B_ENABLED, VC4C_ENABLED, VC5A_ENABLED, VC5B_ENABLED, VC5C_ENABLED, VC6A_ENABLED, VC6B_ENABLED, VC6C_ENABLED, VC7A_ENABLED, VC7B_ENABLED, VC7C_ENABLED, VC8A_ENABLED, VC8B_ENABLED, VC8C_ENABLED, VC9A_ENABLED, VC9B_ENABLED, VC9C_ENABLED, VC9D_ENABLED, PCC_ENABLED, ML5A_ENABLED, ML5B_ENABLED, ML5C_ENABLED, ML5D_ENABLED, ML5E_ENABLED, DEDUP_ATTR_ENABLED, ENC_0A_ENABLED, BREAKER_WINDOW_MS, BREAKER_MIN_ATTEMPTS, BREAKER_PERF_FAILURES, BREAKER_PERF_FAILURE_RATE, BREAKER_CORRECTNESS_FAILURES, BREAKER_COOLDOWN_MS, BREAKER_PROBE_COUNT, BREAKER_RETRY_BASE_MS, BREAKER_RETRY_CAP_MS, BREAKER_RETRY_JITTER, BREAKER_HYSTERESIS_FAILURE_RATE, BREAKER_HYSTERESIS_BUDGET_P95_MS, BREAKER_MIN_HEALTHY_RESIDENCE_MS, } from "./config/vector-cortex.js";
@@ -0,0 +1,60 @@
1
+ /** ENC-0a buildDecision contract constructor suite — extracted from
2
+ * enc0a-acceptance.test.ts for soft-limit compliance. Receives the contract
3
+ * constructor + constants from the aggregator (no import cycle).
4
+ */
5
+ import { test, describe } from "node:test";
6
+ import assert from "node:assert/strict";
7
+ export function registerEnc0aContract(ctx) {
8
+ const { buildDecision, PLATFORMS } = ctx;
9
+ describe("buildDecision contract constructor", () => {
10
+ test("rejects an incomplete platform matrix", () => {
11
+ const matrix = {
12
+ "linux-x64": { runtime: "onnxruntime-web", installMiB: 33, demotion: "none" },
13
+ "linux-arm64": { runtime: "onnxruntime-web", installMiB: 33, demotion: "none" },
14
+ "darwin-x64": { runtime: "onnxruntime-web", installMiB: 33, demotion: "wasm" },
15
+ "darwin-arm64": { runtime: "onnxruntime-web", installMiB: 33, demotion: "none" },
16
+ // win32-x64 omitted
17
+ };
18
+ assert.throws(() => buildDecision({
19
+ backend: "wasm",
20
+ budgetOk: true,
21
+ p95Ms: 18.2,
22
+ platformMatrix: matrix,
23
+ modelPath: "model.onnx",
24
+ modelBytes: 1,
25
+ modelSha256: "a".repeat(64),
26
+ tokenizerPath: "tokenizer.json",
27
+ tokenizerBytes: 1,
28
+ tokenizerSha256: "b".repeat(64),
29
+ blockedBy: [],
30
+ }));
31
+ });
32
+ test("builds a valid decision with opset 21 + MIT license for a complete matrix", () => {
33
+ const matrix = {
34
+ "linux-x64": { runtime: "onnxruntime-web", installMiB: 33, demotion: "none" },
35
+ "linux-arm64": { runtime: "onnxruntime-web", installMiB: 33, demotion: "none" },
36
+ "darwin-x64": { runtime: "onnxruntime-web", installMiB: 33, demotion: "wasm" },
37
+ "darwin-arm64": { runtime: "onnxruntime-web", installMiB: 33, demotion: "none" },
38
+ "win32-x64": { runtime: "onnxruntime-web", installMiB: 33, demotion: "none" },
39
+ };
40
+ const d = buildDecision({
41
+ backend: "wasm",
42
+ budgetOk: true,
43
+ p95Ms: 18.2,
44
+ platformMatrix: matrix,
45
+ modelPath: "model.onnx",
46
+ modelBytes: 24117248,
47
+ modelSha256: "a".repeat(64),
48
+ tokenizerPath: "tokenizer.json",
49
+ tokenizerBytes: 50000,
50
+ tokenizerSha256: "b".repeat(64),
51
+ blockedBy: [],
52
+ });
53
+ assert.equal(d.schema, "encoder-backend-decision-v1");
54
+ assert.equal(d.opset, 21);
55
+ assert.equal(d.backend, "wasm");
56
+ assert.deepEqual(d.license, { spdx: "MIT", redistribution: true });
57
+ assert.equal(d.platformMatrix["darwin-x64"].demotion, "wasm");
58
+ });
59
+ });
60
+ }
@@ -0,0 +1,90 @@
1
+ /**
2
+ * _acceptance-vc2a-conformance.ts — ENC-001..008 conformance rows + the named
3
+ * assertions (ENC-ASSET-001 / ENC-DIGEST-002 / ENC-PLATFORM-003), each driven
4
+ * through the REAL encoder asset/runtime (no mocks). Extracted from
5
+ * vc2a-acceptance.test.ts so the aggregator stays under the tests/ soft limit.
6
+ *
7
+ * The aggregator passes its shared imports/helpers as a context object, so this
8
+ * sibling never imports the aggregator (no import cycle at module load).
9
+ */
10
+ import { test, describe } from "node:test";
11
+ import assert from "node:assert/strict";
12
+ export function registerVc2aConformance(ctx) {
13
+ const { ENC_IDS, ENC_FAIL, fixture, buildDir, rmBuilt, optionsFor, createEncoderRuntime, verifyEncoderAsset, readEncoderManifest, } = ctx;
14
+ // -------------------------------------------------------------------------
15
+ // ENC-001..008 conformance rows through the real runtime
16
+ // -------------------------------------------------------------------------
17
+ describe("ENC-001..008 conformance rows", () => {
18
+ for (const id of ENC_IDS) {
19
+ test(`${id}: resolves through the real runtime to the documented result`, () => {
20
+ const fx = fixture(id);
21
+ const built = buildDir(fx.input.scenario);
22
+ try {
23
+ const rt = createEncoderRuntime(optionsFor(fx.input.scenario));
24
+ const load = rt.load(built.dir);
25
+ assert.equal(load.ok, fx.expected.ok, `${id} ok`);
26
+ if (!load.ok) {
27
+ assert.equal(load.code, fx.expected.code, `${id} exact failure code`);
28
+ if (fx.expected.mode)
29
+ assert.equal(load.mode, fx.expected.mode, `${id} mode`);
30
+ }
31
+ else {
32
+ assert.equal(load.mode, "A", `${id} should be mode A`);
33
+ }
34
+ }
35
+ finally {
36
+ rmBuilt(built);
37
+ }
38
+ });
39
+ }
40
+ });
41
+ // -------------------------------------------------------------------------
42
+ // VC2A named assertions
43
+ // -------------------------------------------------------------------------
44
+ describe("VC2A named assertions", () => {
45
+ test("ENC-ASSET-001: opset21 manifest + matching digests load as mode A", () => {
46
+ const fx = fixture("ENC-ASSET-001");
47
+ assert.equal(fx.expected.ok, true);
48
+ const built = buildDir("valid");
49
+ try {
50
+ const load = createEncoderRuntime().load(built.dir);
51
+ assert.equal(load.ok, true);
52
+ if (load.ok)
53
+ assert.equal(load.mode, "A");
54
+ }
55
+ finally {
56
+ rmBuilt(built);
57
+ }
58
+ });
59
+ test("ENC-DIGEST-002: one-byte model mutation demotes before load", () => {
60
+ const fx = fixture("ENC-DIGEST-002");
61
+ assert.equal(fx.expected.code, ENC_FAIL.DIGEST_MISMATCH);
62
+ const built = buildDir("mutate-onnx");
63
+ try {
64
+ const res = verifyEncoderAsset(built.dir, readEncoderManifest(built.dir));
65
+ assert.equal(res.ok, false);
66
+ if (!res.ok)
67
+ assert.equal(res.code, ENC_FAIL.DIGEST_MISMATCH);
68
+ }
69
+ finally {
70
+ rmBuilt(built);
71
+ }
72
+ });
73
+ test("ENC-PLATFORM-003: unsupported architecture selects trigram B", () => {
74
+ const fx = fixture("ENC-PLATFORM-003");
75
+ assert.equal(fx.expected.mode, "B");
76
+ const built = buildDir("valid");
77
+ try {
78
+ const load = createEncoderRuntime({ platform: () => null }).load(built.dir);
79
+ assert.equal(load.ok, false);
80
+ if (!load.ok) {
81
+ assert.equal(load.mode, "B", "trigram B selected");
82
+ assert.equal(load.code, ENC_FAIL.PLATFORM_UNSUPPORTED);
83
+ }
84
+ }
85
+ finally {
86
+ rmBuilt(built);
87
+ }
88
+ });
89
+ });
90
+ }