pi-mega-compact 0.20.51 → 0.20.53

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 (87) hide show
  1. package/assets/vector-cortex/encoder-v1/manifest.json +1 -1
  2. package/dist/config/vector-cortex-enc2budget.js +46 -0
  3. package/dist/config/vector-cortex.js +1 -0
  4. package/dist/config.js +1 -1
  5. package/dist/extensions/dashboard-server/api-contracts/vector-cortex-ledger.js +9 -0
  6. package/dist/extensions/dashboard-server/routes-rag-settings-vector-cortex.js +1 -0
  7. package/dist/extensions/dashboard-server/routes-setup-enc2budget.js +155 -0
  8. package/dist/extensions/dashboard-server/routes-setup.js +15 -0
  9. package/dist/extensions/dashboard-server/routes-vector-cortex-eval.js +4 -1
  10. package/dist/src/config/vector-cortex-enc2budget.js +46 -0
  11. package/dist/src/config/vector-cortex.js +1 -0
  12. package/dist/src/config.js +1 -1
  13. package/dist/src/vector-cortex/encoder/decision.js +34 -6
  14. package/dist/src/vector-cortex/encoder/runtime-select.js +24 -21
  15. package/dist/src/vector-cortex/setup-cortex-blockers-compute.js +2 -2
  16. package/dist/vector-cortex/encoder/decision.js +34 -6
  17. package/dist/vector-cortex/encoder/runtime-select.js +24 -21
  18. package/dist/vector-cortex/setup-cortex-blockers-compute.js +2 -2
  19. package/extensions/dashboard-client/dist/assets/{AreaChart-BFTUTmmW.js → AreaChart-COjQ_jJm.js} +2 -2
  20. package/extensions/dashboard-client/dist/assets/{AreaChart-BFTUTmmW.js.map → AreaChart-COjQ_jJm.js.map} +1 -1
  21. package/extensions/dashboard-client/dist/assets/{BarChart-DfFurESR.js → BarChart-eAIpwb8c.js} +2 -2
  22. package/extensions/dashboard-client/dist/assets/{BarChart-DfFurESR.js.map → BarChart-eAIpwb8c.js.map} +1 -1
  23. package/extensions/dashboard-client/dist/assets/{CacheTab-FpCJSmy8.js → CacheTab-BS_G9_YV.js} +2 -2
  24. package/extensions/dashboard-client/dist/assets/{CacheTab-FpCJSmy8.js.map → CacheTab-BS_G9_YV.js.map} +1 -1
  25. package/extensions/dashboard-client/dist/assets/{EventsTab--9lJFJtc.js → EventsTab-CDFk5d3P.js} +2 -2
  26. package/extensions/dashboard-client/dist/assets/{EventsTab--9lJFJtc.js.map → EventsTab-CDFk5d3P.js.map} +1 -1
  27. package/extensions/dashboard-client/dist/assets/{HealthTab-CkgtF1qa.js → HealthTab-zFyPJb5b.js} +2 -2
  28. package/extensions/dashboard-client/dist/assets/{HealthTab-CkgtF1qa.js.map → HealthTab-zFyPJb5b.js.map} +1 -1
  29. package/extensions/dashboard-client/dist/assets/{MaintenanceTab-ChXGq1or.js → MaintenanceTab-DxJX4lXh.js} +2 -2
  30. package/extensions/dashboard-client/dist/assets/{MaintenanceTab-ChXGq1or.js.map → MaintenanceTab-DxJX4lXh.js.map} +1 -1
  31. package/extensions/dashboard-client/dist/assets/{MemoryMapTab-CPpRR4MV.js → MemoryMapTab-CRy5I6mg.js} +2 -2
  32. package/extensions/dashboard-client/dist/assets/{MemoryMapTab-CPpRR4MV.js.map → MemoryMapTab-CRy5I6mg.js.map} +1 -1
  33. package/extensions/dashboard-client/dist/assets/{MetricsTab-Db1wkykf.js → MetricsTab-K4kPea0Q.js} +2 -2
  34. package/extensions/dashboard-client/dist/assets/{MetricsTab-Db1wkykf.js.map → MetricsTab-K4kPea0Q.js.map} +1 -1
  35. package/extensions/dashboard-client/dist/assets/{OverviewTab-LanDECrz.js → OverviewTab-BZoJ1oOv.js} +2 -2
  36. package/extensions/dashboard-client/dist/assets/{OverviewTab-LanDECrz.js.map → OverviewTab-BZoJ1oOv.js.map} +1 -1
  37. package/extensions/dashboard-client/dist/assets/{ReposTab-I2umKduk.js → ReposTab-uMFKxT0a.js} +2 -2
  38. package/extensions/dashboard-client/dist/assets/{ReposTab-I2umKduk.js.map → ReposTab-uMFKxT0a.js.map} +1 -1
  39. package/extensions/dashboard-client/dist/assets/{SessionsTab-D_IxuEt5.js → SessionsTab-DDzmcCuH.js} +2 -2
  40. package/extensions/dashboard-client/dist/assets/{SessionsTab-D_IxuEt5.js.map → SessionsTab-DDzmcCuH.js.map} +1 -1
  41. package/extensions/dashboard-client/dist/assets/SetupTab-KLTE-VKV.js +3 -0
  42. package/extensions/dashboard-client/dist/assets/{SetupTab-BZ7Jn5MR.js.map → SetupTab-KLTE-VKV.js.map} +1 -1
  43. package/extensions/dashboard-client/dist/assets/{TimeSavedCard-BTdcO1E2.js → TimeSavedCard-D_mBYAzE.js} +2 -2
  44. package/extensions/dashboard-client/dist/assets/{TimeSavedCard-BTdcO1E2.js.map → TimeSavedCard-D_mBYAzE.js.map} +1 -1
  45. package/extensions/dashboard-client/dist/assets/{TurnsTab-BXC8IL_B.js → TurnsTab-C6xr2lsO.js} +2 -2
  46. package/extensions/dashboard-client/dist/assets/{TurnsTab-BXC8IL_B.js.map → TurnsTab-C6xr2lsO.js.map} +1 -1
  47. package/extensions/dashboard-client/dist/assets/{VcStatusBadge-CNJnFtJo.js → VcStatusBadge-J0DVlxH0.js} +2 -2
  48. package/extensions/dashboard-client/dist/assets/{VcStatusBadge-CNJnFtJo.js.map → VcStatusBadge-J0DVlxH0.js.map} +1 -1
  49. package/extensions/dashboard-client/dist/assets/{VectorCortexTab-fsuWgA6e.js → VectorCortexTab-AvL73DpJ.js} +2 -2
  50. package/extensions/dashboard-client/dist/assets/{VectorCortexTab-fsuWgA6e.js.map → VectorCortexTab-AvL73DpJ.js.map} +1 -1
  51. package/extensions/dashboard-client/dist/assets/{WikiTab-Cn1BScDU.js → WikiTab-DVcIWjLT.js} +2 -2
  52. package/extensions/dashboard-client/dist/assets/{WikiTab-Cn1BScDU.js.map → WikiTab-DVcIWjLT.js.map} +1 -1
  53. package/extensions/dashboard-client/dist/assets/{button-B4_9rsul.js → button-Cl_gFaIf.js} +2 -2
  54. package/extensions/dashboard-client/dist/assets/{button-B4_9rsul.js.map → button-Cl_gFaIf.js.map} +1 -1
  55. package/extensions/dashboard-client/dist/assets/{card-DUvC_geI.js → card-DMzHffVs.js} +2 -2
  56. package/extensions/dashboard-client/dist/assets/{card-DUvC_geI.js.map → card-DMzHffVs.js.map} +1 -1
  57. package/extensions/dashboard-client/dist/assets/{client-extra-HaH97bzp.js → client-extra-Dkkppa5C.js} +2 -2
  58. package/extensions/dashboard-client/dist/assets/{client-extra-HaH97bzp.js.map → client-extra-Dkkppa5C.js.map} +1 -1
  59. package/extensions/dashboard-client/dist/assets/{generateCategoricalChart-BxFWU2Mt.js → generateCategoricalChart-Bi8zQmZN.js} +2 -2
  60. package/extensions/dashboard-client/dist/assets/{generateCategoricalChart-BxFWU2Mt.js.map → generateCategoricalChart-Bi8zQmZN.js.map} +1 -1
  61. package/extensions/dashboard-client/dist/assets/{index-xPdbZ73U.js → index-mZRDesSq.js} +3 -3
  62. package/extensions/dashboard-client/dist/assets/{index-xPdbZ73U.js.map → index-mZRDesSq.js.map} +1 -1
  63. package/extensions/dashboard-client/dist/assets/{switch-Bv3_1R_j.js → switch-K_lsOl6x.js} +2 -2
  64. package/extensions/dashboard-client/dist/assets/{switch-Bv3_1R_j.js.map → switch-K_lsOl6x.js.map} +1 -1
  65. package/extensions/dashboard-client/dist/assets/{toggle-DHXrB3Aw.js → toggle-67IU2JLn.js} +2 -2
  66. package/extensions/dashboard-client/dist/assets/{toggle-DHXrB3Aw.js.map → toggle-67IU2JLn.js.map} +1 -1
  67. package/extensions/dashboard-client/dist/assets/{useSSE-NigHeFyT.js → useSSE-DiLgyP7C.js} +2 -2
  68. package/extensions/dashboard-client/dist/assets/{useSSE-NigHeFyT.js.map → useSSE-DiLgyP7C.js.map} +1 -1
  69. package/extensions/dashboard-client/dist/index.html +1 -1
  70. package/extensions/dashboard-client/src/tabs/SetupTab/CortexRuntimeCard.tsx +98 -7
  71. package/extensions/dashboard-client/src/tabs/VectorCortexTab.tsx +7 -5
  72. package/extensions/dashboard-client/src/types/vector-cortex.ts +6 -0
  73. package/extensions/dashboard-server/api-contracts/setup.ts +13 -0
  74. package/extensions/dashboard-server/api-contracts/vector-cortex-ledger.ts +39 -0
  75. package/extensions/dashboard-server/api-contracts/vector-cortex.ts +10 -28
  76. package/extensions/dashboard-server/routes-rag-settings-vector-cortex.ts +6 -0
  77. package/extensions/dashboard-server/routes-setup-enc2budget.ts +171 -0
  78. package/extensions/dashboard-server/routes-setup.ts +19 -0
  79. package/extensions/dashboard-server/routes-vector-cortex-eval.ts +4 -1
  80. package/package.json +1 -1
  81. package/src/config/vector-cortex-enc2budget.ts +51 -0
  82. package/src/config/vector-cortex.ts +6 -0
  83. package/src/config.ts +4 -0
  84. package/src/vector-cortex/encoder/decision.ts +37 -6
  85. package/src/vector-cortex/encoder/runtime-select.ts +25 -23
  86. package/src/vector-cortex/setup-cortex-blockers-compute.ts +2 -2
  87. package/extensions/dashboard-client/dist/assets/SetupTab-BZ7Jn5MR.js +0 -3
@@ -1 +1 @@
1
- {"batch":1,"heads":{"cacheStability":64,"contradiction":128,"dependency":128,"payloadRouting":32,"semantic":384},"hiddenWidth":384,"maxTokens":512,"modelVersion":"encoder-v1","onnx":{"bytes":33793354,"path":"model.onnx","sha256":"913a643a697a53fe88476395682995d5647c14f51321d344e69abcc3c4e854a2"},"opset":21,"platform":"linux-x64","schema":"model-manifest-v1","semanticWidth":384,"tokenizer":{"bytes":535343,"path":"tokenizer.json","sha256":"ea77de727ef7fd34d177b83b4b1f1d3bb8884c95c90b6554a0adb0b3b65350a9"},"totalBytes":34328697,"trainingManifestDigest":"e9b2550dbb79141af84440dda65ca21d3509904b2c09a89316145137a5b5e3de"}
1
+ {"batch":1,"heads":{"cacheStability":64,"contradiction":128,"dependency":128,"payloadRouting":32,"semantic":384},"hiddenWidth":384,"maxTokens":512,"modelVersion":"encoder-v1","onnx":{"bytes":33793354,"path":"model.onnx","sha256":"913a643a697a53fe88476395682995d5647c14f51321d344e69abcc3c4e854a2"},"opset":21,"platform":"linux-x64","schema":"model-manifest-v1","semanticWidth":384,"tokenizer":{"bytes":533603,"path":"tokenizer.json","sha256":"ea77de727ef7fd34d177b83b4b1f1d3bb8884c95c90b6554a0adb0b3b65350a9"},"totalBytes":34326957,"trainingManifestDigest":"e9b2550dbb79141af84440dda65ca21d3509904b2c09a89316145137a5b5e3de"}
@@ -0,0 +1,46 @@
1
+ /**
2
+ * config/vector-cortex-enc2budget.ts — ENC-2a operator-configurable native
3
+ * onnxruntime install-budget knob (dashboard Settings surface).
4
+ *
5
+ * Sibling of vector-cortex-enc1a.ts / vector-cortex-enc1b.ts so vector-cortex.ts
6
+ * stays under the 300-line soft limit (soft-as-hard gate). vector-cortex.ts
7
+ * re-exports the flag + constants below and root src/config.ts re-exports them,
8
+ * so no consumer import path changes.
9
+ *
10
+ * ENC-2a exposes the runtime's operator knob `MEGACOMPACT_NATIVE_ORT_BUDGET_MIB`
11
+ * as a dashboard Settings field. The knob itself is read at runtime by
12
+ * `installBudgetMib()` (`src/vector-cortex/encoder/decision.ts`) and gates the
13
+ * `budgetOk` decision in `src/vector-cortex/encoder/runtime-select.ts`. Setting
14
+ * it persists to the per-repo `.mega-compact.env` via the same upsert-writer
15
+ * path ENC-1a/ENC-1b use (never the global state dir — see the
16
+ * `statedir-per-repo-vs-global` memory).
17
+ *
18
+ * Bounds (mirror `decision.ts` clamp): positive integer, 1..8192 MiB. Out-of-
19
+ * range input is rejected by validation (400) and falls back to the default
20
+ * (300) in `installBudgetMib()` at runtime. Default 300 MiB was set on
21
+ * 2026-08-07 when the user lifted the prior 80 MiB restriction ("remove the
22
+ * 80mb limit that wasn't my design decision" → "set it to a number that is in
23
+ * the dashboard that defaults to lets say 300mb").
24
+ *
25
+ * `MEGACOMPACT_ENC_2BUDGET=0` disables: no new GET fields, no writer branch, no
26
+ * new Settings rows — byte-identical to the ENC-1b predecessor. The flag MUST
27
+ * also be a dashboard SETTINGS toggle (visible in config UI, never in
28
+ * EXCLUDED_SETTINGS — see `feedback_dashboard-flags-toggleable` memory).
29
+ *
30
+ * Pi-agnostic, dependency-free (PREVENT-PI-004 / PREVENT-011).
31
+ */
32
+ import { sprintFlag } from "./vector-cortex-flag.js";
33
+ /** ENC-2a knob: persisted env name, read by `installBudgetMib()` at runtime. */
34
+ export const ENC_2BUDGET_NATIVE_ORT_BUDGET_ENV = "MEGACOMPACT_NATIVE_ORT_BUDGET_MIB";
35
+ /** Upper bound on the budget (MiB). Mirrors decision.ts's clamp. */
36
+ export const ENC_2BUDGET_MAX_MIB = 8192;
37
+ /** Default budget (MiB) when the env var is unset or invalid. */
38
+ export const ENC_2BUDGET_DEFAULT_MIB = 300;
39
+ /**
40
+ * ENC-2a — operator-configurable native install budget Settings surface.
41
+ * Default ON. `MEGACOMPACT_ENC_2BUDGET=0` disables and is byte-identical to the
42
+ * ENC-1b predecessor: no new GET fields, no writer branch, no new Settings rows.
43
+ * This flag MUST also be a dashboard SETTINGS toggle (visible in config UI,
44
+ * never in EXCLUDED_SETTINGS).
45
+ */
46
+ export const ENC_2BUDGET_ENABLED = () => sprintFlag("MEGACOMPACT_ENC_2BUDGET");
@@ -34,5 +34,6 @@ export { ENC_0F_ENABLED } from "./vector-cortex-enc0f.js";
34
34
  export { ENC_0G_ENABLED } from "./vector-cortex-enc0g.js";
35
35
  export { ENC_1A_ENABLED } from "./vector-cortex-enc1a.js";
36
36
  export { ENC_1B_ENABLED, ENC_1B_MAX_EMBEDDING_DIM, ENC_1B_EMBEDDING_DIM_ENV, ENC_1B_EMBEDDING_HEADERS_ENV, ENC_1B_ALLOW_REMOTE_EMBEDDER_ENV, ENC_1B_ENCODER_NATIVE_ENV, } from "./vector-cortex-enc1b.js";
37
+ export { ENC_2BUDGET_ENABLED, ENC_2BUDGET_NATIVE_ORT_BUDGET_ENV, ENC_2BUDGET_MAX_MIB, ENC_2BUDGET_DEFAULT_MIB, } from "./vector-cortex-enc2budget.js";
37
38
  // Breaker constants (TRIAD_RESILIENCE.md §breaker) extracted to vector-cortex-breakers.ts.
38
39
  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, DEDUP_ATTR_ENABLED, ENC_0A_ENABLED, ENC_0B_ENABLED, ENC_0C_ENABLED, ENC_0D_ENABLED, ENC_0E_ENABLED, ENC_0F_ENABLED, ENC_0G_ENABLED, ENC_1A_ENABLED, ENC_1B_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, ENC_0B_ENABLED, ENC_0C_ENABLED, ENC_0D_ENABLED, ENC_0E_ENABLED, ENC_0F_ENABLED, ENC_0G_ENABLED, ENC_1A_ENABLED, ENC_1B_ENABLED, ENC_2BUDGET_ENABLED, ENC_2BUDGET_NATIVE_ORT_BUDGET_ENV, ENC_2BUDGET_MAX_MIB, ENC_2BUDGET_DEFAULT_MIB, 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,9 @@
1
+ /**
2
+ * api-contracts/vector-cortex-ledger.ts — VC1B occurrence-ledger surface.
3
+ *
4
+ * Extracted from `vector-cortex.ts` so the combined api-contracts module stays
5
+ * under the 400-line `extensions/` soft limit. Owns the reader-only ledger
6
+ * views (VC1B aggregate + identity rows). PREVENT-PI-004: type definitions
7
+ * only, no network code. PREVENT-011: no `any` type.
8
+ */
9
+ export {};
@@ -67,5 +67,6 @@ export const VECTOR_CORTEX_SETTINGS = {
67
67
  boolDirect("MEGACOMPACT_ENC_0G", "ENC-0g Setup Cortex honest state (verdict override + live blockers)", "ENC-0g makes the Setup Cortex status route honest: reads the ENC-0f QualificationV1 record (when ENC_0F is ON and a record exists) and lets its verdict override the structural verify for the qualification field; computes the blocker list from (platform, record, manifest head-count) with corrected HG statuses/wording; re-derives VC9B action gating from live blockers. OFF = verdict from verifyEncoderAsset alone, static SETUP_CORTEX_BLOCKERS, static action gating (byte-identical ENC-0f predecessor).", true),
68
68
  boolDirect("MEGACOMPACT_ENC_1A", "ENC-1a external embedder API key + endpoint Settings fields", "ENC-1a adds a Settings-visible field pair for the external embedder endpoint URL + optional Bearer API key, persisted by the setup-configure writer branch to the per-repo .mega-compact.env (MEGACOMPACT_EMBEDDING_URL / MEGACOMPACT_EMBEDDING_KEY). The GET status route echoes the endpoint URL and reports embeddingApiKeySet as a boolean ONLY — the raw key is never returned. OFF = no new GET fields, no writer branch, no new Settings text rows (byte-identical ENC-0g predecessor).", true),
69
69
  boolDirect("MEGACOMPACT_ENC_1B", "ENC-1b ONNX runtime backend + embedder API settings", "ENC-1b completes the embedder API Settings surface (dim / headers / allow-remote persisted to the per-repo .mega-compact.env) and surfaces the ONNX runtime selection knob (MEGACOMPACT_ENCODER_NATIVE) as a toggle plus the current effective backend + demotion reason. OFF = no new GET fields, no writer branch, no new Settings rows or toggle (byte-identical ENC-1a predecessor).", true),
70
+ boolDirect("MEGACOMPACT_ENC_2BUDGET", "ENC-2a operator-configurable native install-budget knob", "ENC-2a exposes the runtime operator knob MEGACOMPACT_NATIVE_ORT_BUDGET_MIB (default 300 MiB, clamp 8192) as a dashboard Settings field. The knob gates budgetOk in the encoder runtime decision (decision.ts installBudgetMib + runtime-select.ts selectRuntimeBackend). Persisted to the per-repo .mega-compact.env via the setup-configure writer branch; the GET status route surfaces the persisted value AND the effective integer installBudgetMib() resolves to (so the dashboard shows the runtime's actual operand). OFF = no new GET fields, no writer branch, no new Settings rows (byte-identical ENC-1b predecessor).", true),
70
71
  ],
71
72
  };
@@ -0,0 +1,155 @@
1
+ /**
2
+ * dashboard-server/routes-setup-enc2budget.ts — ENC-2a operator-configurable
3
+ * native onnxruntime install budget (MiB) Settings read/write + the additive
4
+ * writer branch.
5
+ *
6
+ * Extracted out of routes-setup.ts (which hovers at the 300-line source soft
7
+ * cap, mirroring the ENC-1a/ENC-1b sibling extracts) so the ENC-2a additive
8
+ * read/write of the per-repo `.mega-compact.env` key lives in a sibling impl
9
+ * file. One key is managed here: `MEGACOMPACT_NATIVE_ORT_BUDGET_MIB` — the exact
10
+ * name `installBudgetMib()` (`src/vector-cortex/encoder/decision.ts`) reads at
11
+ * runtime.
12
+ *
13
+ * The write is create-or-append: it upserts the key into the existing per-repo
14
+ * `.mega-compact.env`, preserving every unrelated line and never deleting
15
+ * another key. The read reports the persisted raw string AND the effective
16
+ * integer `installBudgetMib()` resolves to (so the dashboard shows what the
17
+ * runtime will actually use — including the 300 MiB default fallback when the
18
+ * knob is unset or invalid). Reader-only: setter/getter never reimplements
19
+ * `installBudgetMib()`'s clamp rule, it imports it.
20
+ *
21
+ * Guardrails: PREVENT-PI-004 (local filesystem reads/writes only — zero
22
+ * network), PREVENT-001 (null-safe), PREVENT-011 (no `any`).
23
+ */
24
+ import { writeFileSync, mkdirSync, readFileSync, existsSync } from "node:fs";
25
+ import { join } from "node:path";
26
+ import { ENC_2BUDGET_ENABLED, ENC_2BUDGET_MAX_MIB, ENC_2BUDGET_NATIVE_ORT_BUDGET_ENV, } from "../../src/config/vector-cortex.js";
27
+ import { installBudgetMib, resolveInstallBudgetMib, } from "../../src/vector-cortex/encoder/decision.js";
28
+ function envPath(stateDir) {
29
+ return join(stateDir, ".mega-compact.env");
30
+ }
31
+ /** Extract the value of `export MEGACOMPACT_X="..."` (or unquoted) from a line. */
32
+ function lineValue(line, key) {
33
+ const m = line.match(new RegExp(`^export\\s+${key}=(.*)$`));
34
+ if (!m)
35
+ return null;
36
+ const rest = m[1].trim();
37
+ if (rest.length === 0)
38
+ return null;
39
+ const q = rest.match(/^"([^"]*)"$/);
40
+ return q ? q[1] : rest;
41
+ }
42
+ /** True when the payload carries the ENC-2a key (flag-gated). */
43
+ export function wantsEnc2Budget(body) {
44
+ return ENC_2BUDGET_ENABLED() && typeof body.nativeOrtBudgetMib === "string";
45
+ }
46
+ /** Read the ENC-2a knob from the per-repo `.mega-compact.env`. Returns the raw
47
+ * persisted string when present, or null when absent. */
48
+ export function readEnc2BudgetEnv(stateDir) {
49
+ try {
50
+ const p = envPath(stateDir);
51
+ if (!existsSync(p))
52
+ return { raw: null };
53
+ const lines = readFileSync(p, "utf8").split(/\r?\n/);
54
+ for (const line of lines) {
55
+ const v = lineValue(line, ENC_2BUDGET_NATIVE_ORT_BUDGET_ENV);
56
+ if (v !== null && v.length > 0)
57
+ return { raw: v };
58
+ }
59
+ return { raw: null };
60
+ }
61
+ catch {
62
+ return { raw: null };
63
+ }
64
+ }
65
+ /**
66
+ * ENC-2a additive GET status fields. Omitted when flag-off. Surfaces the raw
67
+ * persisted value (when set) AND the effective runtime operand — the integer
68
+ * MiB `installBudgetMib()` actually resolves to. Reading `installBudgetMib()`
69
+ * here (instead of reimplementing the clamp) keeps the dashboard honest when
70
+ * the env var is unset or out-of-range.
71
+ */
72
+ export function enc2BudgetStatusFields(stateDir) {
73
+ if (!ENC_2BUDGET_ENABLED())
74
+ return {};
75
+ const { raw } = readEnc2BudgetEnv(stateDir);
76
+ // The EFFECTIVE operand is what the runtime WILL use: if a value has been
77
+ // persisted to the disk file, resolve THAT through the clamp (the operator
78
+ // just POSTed it; the running process has not re-sourced `.mega-compact.env`
79
+ // yet so `installBudgetMib()` reads the stale env). On restart the saved
80
+ // value is what the runtime loads. When nothing is persisted, fall back to
81
+ // the live env var / process.env (= `installBudgetMib()`).
82
+ const effective = raw !== null ? resolveInstallBudgetMib(raw) : installBudgetMib();
83
+ return {
84
+ ...(raw !== null ? { nativeOrtBudgetMib: raw } : {}),
85
+ nativeOrtBudgetEffectiveMib: String(effective),
86
+ };
87
+ }
88
+ /** Upsert the ENC-2a knob into the per-repo `.mega-compact.env`. Creates the
89
+ * file if absent; preserves every unrelated line; never deletes other keys.
90
+ * `entries.raw === null` leaves the key's line untouched. */
91
+ export function writeEnc2BudgetEnv(stateDir, entries) {
92
+ const p = envPath(stateDir);
93
+ const existingLines = existsSync(p) ? readFileSync(p, "utf8").split(/\r?\n/) : [];
94
+ const out = [];
95
+ let written = false;
96
+ for (const line of existingLines) {
97
+ if (entries.raw !== null &&
98
+ entries.raw !== undefined &&
99
+ lineValue(line, ENC_2BUDGET_NATIVE_ORT_BUDGET_ENV) !== null) {
100
+ out.push(`export ${ENC_2BUDGET_NATIVE_ORT_BUDGET_ENV}="${entries.raw}"`);
101
+ written = true;
102
+ continue;
103
+ }
104
+ out.push(line);
105
+ }
106
+ if (entries.raw !== null && entries.raw !== undefined && !written) {
107
+ out.push(`export ${ENC_2BUDGET_NATIVE_ORT_BUDGET_ENV}="${entries.raw}"`);
108
+ }
109
+ mkdirSync(stateDir, { recursive: true });
110
+ writeFileSync(p, out.join("\n"), "utf-8");
111
+ return p;
112
+ }
113
+ /** Validate `nativeOrtBudgetMib` as a positive integer string within
114
+ * `ENC_2BUDGET_MAX_MIB`. Returns `null` when valid, else the error code.
115
+ * Exported so the routes host (combined-payload path) and the aggregator share
116
+ * the same rule. */
117
+ export function validateNativeOrtBudgetMib(value) {
118
+ if (typeof value !== "string" || value.trim().length === 0)
119
+ return "invalid_native_ort_budget_mib";
120
+ if (!/^\d+$/.test(value))
121
+ return "invalid_native_ort_budget_mib";
122
+ const n = Number(value);
123
+ if (!Number.isSafeInteger(n) || n < 1 || n > ENC_2BUDGET_MAX_MIB) {
124
+ return "invalid_native_ort_budget_mib";
125
+ }
126
+ return null;
127
+ }
128
+ /**
129
+ * Combined-payload upsert: after the main embedder write has freshly written
130
+ * the per-repo env, append the ENC-2a key when carried alongside a valid
131
+ * embedder selection (flag-gated, additive). No-op when flag-off or no ENC-2a
132
+ * key present.
133
+ */
134
+ export function tryEnc2BudgetInto(stateDir, body) {
135
+ if (!wantsEnc2Budget(body))
136
+ return;
137
+ writeEnc2BudgetEnv(stateDir, {
138
+ raw: typeof body.nativeOrtBudgetMib === "string" ? body.nativeOrtBudgetMib : null,
139
+ });
140
+ }
141
+ /**
142
+ * Combined-path validation: the routes host runs this before the combined
143
+ * upsert when a payload ALSO carries a valid embedder — returned as the error
144
+ * code string, or `null` if validation passes (or the flag is off).
145
+ */
146
+ export function enc2BudgetValidateCombined(body) {
147
+ if (!ENC_2BUDGET_ENABLED())
148
+ return null;
149
+ if (body.nativeOrtBudgetMib !== undefined) {
150
+ const e = validateNativeOrtBudgetMib(body.nativeOrtBudgetMib);
151
+ if (e !== null)
152
+ return e;
153
+ }
154
+ return null;
155
+ }
@@ -13,6 +13,7 @@ import { join } from "node:path";
13
13
  import { VC9D_ENABLED } from "../../src/config.js";
14
14
  import { enc1aStatusFields, writeEnc1aEnv, tryEnc1aConfigure, wantsEnc1a } from "./routes-setup-enc1a.js";
15
15
  import { enc1bStatusFields, tryEnc1bConfigure, tryEnc1bInto, enc1bValidateCombined } from "./routes-setup-enc1b.js";
16
+ import { enc2BudgetStatusFields, tryEnc2BudgetInto, enc2BudgetValidateCombined, } from "./routes-setup-enc2budget.js";
16
17
  import { writeEmbedderEnv } from "./routes-setup-env-upsert.js";
17
18
  import { detectOllama, detectLlamaCpp, detectOnnx, memoizedDetectOllama, memoizedDetectLlamaCpp, memoizedDetectOnnx, } from "./routes-setup-detect-cache.js";
18
19
  // ---------------------------------------------------------------------------
@@ -71,6 +72,7 @@ export function handleSetupStatus(req, res, ctx) {
71
72
  embedCache: process.env["MEGACOMPACT_EMBED_CACHE"] ?? null,
72
73
  minilm: ["1", "true", "yes"].includes((process.env["MEGACOMPACT_MINILM"] ?? "").trim().toLowerCase()),
73
74
  ...enc1aStatusFields(ctx.stateDir), ...enc1bStatusFields(ctx.stateDir),
75
+ ...enc2BudgetStatusFields(ctx.stateDir),
74
76
  };
75
77
  // guardrails-allow PREVENT-PI-004: loopback dashboard response (local)
76
78
  res.writeHead(200, { "Content-Type": "application/json" });
@@ -194,6 +196,18 @@ export function handleSetupConfigure(req, res, ctx) {
194
196
  res.end(JSON.stringify({ error: combinedError }));
195
197
  return;
196
198
  }
199
+ // ENC-2a combined-payload validation: when a payload carries a valid
200
+ // embedder PLUS the budget key, validate the budget BEFORE the upsert so
201
+ // the combined path is rejected with the same 400 code. Flag-off:
202
+ // enc2BudgetValidateCombined returns null (byte-identical predecessor —
203
+ // the unknown key falls through untouched).
204
+ const budgetCombinedError = enc2BudgetValidateCombined(body);
205
+ if (budgetCombinedError !== null) {
206
+ // guardrails-allow PREVENT-PI-004: loopback dashboard response (local)
207
+ res.writeHead(400, { "Content-Type": "application/json" });
208
+ res.end(JSON.stringify({ error: budgetCombinedError }));
209
+ return;
210
+ }
197
211
  const embedder = body.embedder;
198
212
  if (embedder !== "ollama" && embedder !== "llama" && embedder !== "trigram" && embedder !== "custom" && embedder !== "onnx") {
199
213
  res.writeHead(400, { "Content-Type": "application/json" });
@@ -247,6 +261,7 @@ export function handleSetupConfigure(req, res, ctx) {
247
261
  });
248
262
  }
249
263
  tryEnc1bInto(stateDir, body); // ENC-1b combined upsert (dim/headers/allow-remote/native)
264
+ tryEnc2BudgetInto(stateDir, body); // ENC-2a combined upsert (native budget MiB)
250
265
  // Detect if the new config matches what's already active (no restart needed).
251
266
  const currentUrl = process.env["MEGACOMPACT_EMBEDDING_URL"];
252
267
  const alreadyActive = (resolvedUrl === null && !currentUrl) || (resolvedUrl !== null && currentUrl === resolvedUrl);
@@ -9,7 +9,7 @@
9
9
  * Guardrails: PREVENT-PI-004 (local filesystem read only), PREVENT-011 (no
10
10
  * `any`), reader-only aggregate (never payloads/prompts/ledger — EVAL-REDACT-002).
11
11
  */
12
- import { VC0A_ENABLED } from "../../src/config.js";
12
+ import { VC0A_ENABLED, ML5D_ENABLED } from "../../src/config.js";
13
13
  import { readEvalRows } from "../../src/vector-cortex/eval/persist.js";
14
14
  import { summarizeEvalRows } from "../../src/vector-cortex/eval/reader.js";
15
15
  import { sendJson } from "./routes-vector-cortex-shared.js";
@@ -43,6 +43,9 @@ export function handleVectorCortexEvaluation(req, res, ctx) {
43
43
  total: summary.histogram.total,
44
44
  },
45
45
  rejects: [], // VC0C wires live breaker/reject telemetry here
46
+ // ML5-D: additive, present only when the flag is enabled → the client can
47
+ // omit the ModelImprovementCard when off (byte-identical to ML5-C-era tab).
48
+ ...(ML5D_ENABLED() ? { ml5dEnabled: true } : {}),
46
49
  updatedAt: new Date().toISOString(),
47
50
  status: deriveVcStatus({ enabled, hasData: summary.samples > 0 }),
48
51
  };
@@ -0,0 +1,46 @@
1
+ /**
2
+ * config/vector-cortex-enc2budget.ts — ENC-2a operator-configurable native
3
+ * onnxruntime install-budget knob (dashboard Settings surface).
4
+ *
5
+ * Sibling of vector-cortex-enc1a.ts / vector-cortex-enc1b.ts so vector-cortex.ts
6
+ * stays under the 300-line soft limit (soft-as-hard gate). vector-cortex.ts
7
+ * re-exports the flag + constants below and root src/config.ts re-exports them,
8
+ * so no consumer import path changes.
9
+ *
10
+ * ENC-2a exposes the runtime's operator knob `MEGACOMPACT_NATIVE_ORT_BUDGET_MIB`
11
+ * as a dashboard Settings field. The knob itself is read at runtime by
12
+ * `installBudgetMib()` (`src/vector-cortex/encoder/decision.ts`) and gates the
13
+ * `budgetOk` decision in `src/vector-cortex/encoder/runtime-select.ts`. Setting
14
+ * it persists to the per-repo `.mega-compact.env` via the same upsert-writer
15
+ * path ENC-1a/ENC-1b use (never the global state dir — see the
16
+ * `statedir-per-repo-vs-global` memory).
17
+ *
18
+ * Bounds (mirror `decision.ts` clamp): positive integer, 1..8192 MiB. Out-of-
19
+ * range input is rejected by validation (400) and falls back to the default
20
+ * (300) in `installBudgetMib()` at runtime. Default 300 MiB was set on
21
+ * 2026-08-07 when the user lifted the prior 80 MiB restriction ("remove the
22
+ * 80mb limit that wasn't my design decision" → "set it to a number that is in
23
+ * the dashboard that defaults to lets say 300mb").
24
+ *
25
+ * `MEGACOMPACT_ENC_2BUDGET=0` disables: no new GET fields, no writer branch, no
26
+ * new Settings rows — byte-identical to the ENC-1b predecessor. The flag MUST
27
+ * also be a dashboard SETTINGS toggle (visible in config UI, never in
28
+ * EXCLUDED_SETTINGS — see `feedback_dashboard-flags-toggleable` memory).
29
+ *
30
+ * Pi-agnostic, dependency-free (PREVENT-PI-004 / PREVENT-011).
31
+ */
32
+ import { sprintFlag } from "./vector-cortex-flag.js";
33
+ /** ENC-2a knob: persisted env name, read by `installBudgetMib()` at runtime. */
34
+ export const ENC_2BUDGET_NATIVE_ORT_BUDGET_ENV = "MEGACOMPACT_NATIVE_ORT_BUDGET_MIB";
35
+ /** Upper bound on the budget (MiB). Mirrors decision.ts's clamp. */
36
+ export const ENC_2BUDGET_MAX_MIB = 8192;
37
+ /** Default budget (MiB) when the env var is unset or invalid. */
38
+ export const ENC_2BUDGET_DEFAULT_MIB = 300;
39
+ /**
40
+ * ENC-2a — operator-configurable native install budget Settings surface.
41
+ * Default ON. `MEGACOMPACT_ENC_2BUDGET=0` disables and is byte-identical to the
42
+ * ENC-1b predecessor: no new GET fields, no writer branch, no new Settings rows.
43
+ * This flag MUST also be a dashboard SETTINGS toggle (visible in config UI,
44
+ * never in EXCLUDED_SETTINGS).
45
+ */
46
+ export const ENC_2BUDGET_ENABLED = () => sprintFlag("MEGACOMPACT_ENC_2BUDGET");
@@ -34,5 +34,6 @@ export { ENC_0F_ENABLED } from "./vector-cortex-enc0f.js";
34
34
  export { ENC_0G_ENABLED } from "./vector-cortex-enc0g.js";
35
35
  export { ENC_1A_ENABLED } from "./vector-cortex-enc1a.js";
36
36
  export { ENC_1B_ENABLED, ENC_1B_MAX_EMBEDDING_DIM, ENC_1B_EMBEDDING_DIM_ENV, ENC_1B_EMBEDDING_HEADERS_ENV, ENC_1B_ALLOW_REMOTE_EMBEDDER_ENV, ENC_1B_ENCODER_NATIVE_ENV, } from "./vector-cortex-enc1b.js";
37
+ export { ENC_2BUDGET_ENABLED, ENC_2BUDGET_NATIVE_ORT_BUDGET_ENV, ENC_2BUDGET_MAX_MIB, ENC_2BUDGET_DEFAULT_MIB, } from "./vector-cortex-enc2budget.js";
37
38
  // Breaker constants (TRIAD_RESILIENCE.md §breaker) extracted to vector-cortex-breakers.ts.
38
39
  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, DEDUP_ATTR_ENABLED, ENC_0A_ENABLED, ENC_0B_ENABLED, ENC_0C_ENABLED, ENC_0D_ENABLED, ENC_0E_ENABLED, ENC_0F_ENABLED, ENC_0G_ENABLED, ENC_1A_ENABLED, ENC_1B_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, ENC_0B_ENABLED, ENC_0C_ENABLED, ENC_0D_ENABLED, ENC_0E_ENABLED, ENC_0F_ENABLED, ENC_0G_ENABLED, ENC_1A_ENABLED, ENC_1B_ENABLED, ENC_2BUDGET_ENABLED, ENC_2BUDGET_NATIVE_ORT_BUDGET_ENV, ENC_2BUDGET_MAX_MIB, ENC_2BUDGET_DEFAULT_MIB, 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";
@@ -3,9 +3,10 @@
3
3
  *
4
4
  * The durable EncoderBackendDecisionV1 record: which ONNX runtime backend the
5
5
  * real learned encoder ships on (transformers.js/WASM vs onnxruntime-node
6
- * native), whether the 80 MiB install budget holds, the per-platform install
7
- * matrix, the opset baseline (locked 21 by ENC-0a), the license verdict, and
8
- * the pinned model/tokenizer sha256 digests.
6
+ * native), whether the configurable install budget holds (default 300 MiB;
7
+ * operator-overridable via `MEGACOMPACT_NATIVE_ORT_BUDGET_MIB`), the per-platform
8
+ * install matrix, the opset baseline (locked 21 by ENC-0a), the license
9
+ * verdict, and the pinned model/tokenizer sha256 digests.
9
10
  *
10
11
  * ENC-0a is the DECISION + MEASUREMENT sprint: this contract is what the
11
12
  * deterministic resolver (`scripts/encoder/resolve-backend-decision.mjs`) and
@@ -37,10 +38,37 @@ export const DARWIN_X64_DEMOTION_REASON = "darwin-x64: no native binary upstream
37
38
  */
38
39
  export const DARWIN_X64_DEMOTION_REASON_SENTINEL = "darwin-x64: demoted to WASM (reason unavailable in platform matrix)";
39
40
  /**
40
- * The normative ENC-0a budget: the 80 MiB install/asset cap (MODEL_ASSET.md
41
- * §Qualification). Backend qualifies (budgetOk) iff the shipped byte-count fits.
41
+ * The operator-configurable native-ort install byte-budget (MiB). Default 300
42
+ * (shipped 5-platform ~160 MiB comfortably fits); override via
43
+ * `MEGACOMPACT_NATIVE_ORT_BUDGET_MIB`. Safe upper clamp `INSTALL_BUDGET_CLAMP_MIB`
44
+ * rejects absurd values. Backend qualifies (`budgetOk`) iff the shipped
45
+ * byte-count fits the configured budget.
42
46
  */
43
- export const ENCODER_INSTALL_BUDGET_MIB = 80;
47
+ export const INSTALL_BUDGET_CLAMP_MIB = 8192;
48
+ export const INSTALL_BUDGET_DEFAULT_MIB = 300;
49
+ /**
50
+ * Pure resolver: given a raw string (or null/undefined when the env var is
51
+ * unset), return the integer budget the runtime will use. Out-of-range /
52
+ * non-integer / empty input falls back to the default. Exported so the
53
+ * dashboard Settings surface can compute the EFFECTIVE operand from a
54
+ * persisted-but-not-yet-env-loaded value (the operator just POSTed a new
55
+ * budget to disk; the running process has not sourced `.mega-compact.env`,
56
+ * so `installBudgetMib()` reads the stale env, but the dashboard should show
57
+ * what the runtime WILL use after the restart the dashboard itself tells the
58
+ * operator is required).
59
+ */
60
+ export function resolveInstallBudgetMib(raw) {
61
+ if (raw === undefined || raw === null || raw === "")
62
+ return INSTALL_BUDGET_DEFAULT_MIB;
63
+ const n = Number(raw);
64
+ if (!Number.isInteger(n) || n <= 0 || n > INSTALL_BUDGET_CLAMP_MIB) {
65
+ return INSTALL_BUDGET_DEFAULT_MIB;
66
+ }
67
+ return n;
68
+ }
69
+ export function installBudgetMib() {
70
+ return resolveInstallBudgetMib(process.env.MEGACOMPACT_NATIVE_ORT_BUDGET_MIB);
71
+ }
44
72
  /** The p95 latency gate at 512 tokens / 4 threads on linux-x64 (ms). */
45
73
  export const ENCODER_DECISION_P95_MS = 40;
46
74
  /**
@@ -20,17 +20,16 @@
20
20
  */
21
21
  import { ENCODER_LATENCY_P95_MS, } from "./types.js";
22
22
  import { ML5C_ENABLED, ENC_0E_ENABLED } from "../../config/vector-cortex.js";
23
+ import { installBudgetMib } from "./decision.js";
23
24
  import { DARWIN_X64_DEMOTION_REASON, DARWIN_X64_DEMOTION_REASON_SENTINEL, } from "./decision.js";
24
- /** The 80 MiB install budget in bytes (the HG-3 ceiling, unamended). */
25
- export const RUNTIME_NATIVE_INSTALL_BUDGET_MIB = 80;
26
25
  /**
27
26
  * Per-platform optionalDependency footprint of onnxruntime-node (MiB, approx).
28
27
  * These sum to ~160 MiB SHIPPED in the npm package (every target platform is
29
- * included so the resolver lands on a concrete row at install time) — which is
30
- * what exceeds the 80 MiB HG-3 budget and forces the amendment the fixtures
31
- * record (ML5-RUNTIME-001). The per-host INSTALLED footprint (one row only)
32
- * is 28–35 MiB and irrelevant to the 80 MiB ceiling the budget covers the
33
- * shipped tarball, not the single-platform install.
28
+ * included so the resolver lands on a concrete row at install time). Compared
29
+ * against the configurable install budget (`installBudgetMib()`, default 300
30
+ * MiB) to set `budgetOk` — the per-host INSTALLED footprint (one row only,
31
+ * 28–35 MiB) is irrelevant to this ceiling; the budget covers the shipped
32
+ * tarball, not the single-platform install.
34
33
  */
35
34
  export const NATIVE_FOOTPRINT_MIB = {
36
35
  "linux-x64": 33,
@@ -80,39 +79,41 @@ export function selectRuntimeBackend(input) {
80
79
  };
81
80
  }
82
81
  // Native opt-in short-circuits: operator explicitly wants the native path.
83
- // The HG-3 budget compares the SHIPPED byte-count (sum across every platform
84
- // row in the package's optionalDependencies map) against the 80 MiB ceiling
85
- // not the single-platform install size. Native always exceeds 80 MiB across
86
- // 5 platforms (~160 MiB shipped), so budgetOk is false and the evidence
87
- // records the amended budget (the ML5-C spec, HG-3 closure).
82
+ // The budget compares the SHIPPED byte-count (sum across every platform row
83
+ // in the package's optionalDependencies map) against the configurable
84
+ // `installBudgetMib()` ceiling (default 300 MiB; operator-overridable). At
85
+ // the default, shipped ~160 MiB fits budgetOk:true. The operator may lower
86
+ // it (e.g. 100) to surface a budget breach in `budgetOk:false` and the
87
+ // rationale string; the decision rule does not gate on it.
88
88
  if (input.nativeOptIn) {
89
89
  const shippedMib = Object.values(NATIVE_FOOTPRINT_MIB).reduce((a, b) => a + b, 0);
90
+ const budgetMib = installBudgetMib();
90
91
  return {
91
92
  backend: "native",
92
- budgetOk: shippedMib <= RUNTIME_NATIVE_INSTALL_BUDGET_MIB,
93
+ budgetOk: shippedMib <= budgetMib,
93
94
  p95Ms: input.benchRecord?.p95Ms ?? null,
94
95
  platform: input.platform,
95
- rationale: `native opt-in (MEGACOMPACT_ENCODER_NATIVE=1); shipped ${shippedMib} MiB across 5 platforms budget amended to ${shippedMib} MiB`,
96
+ rationale: `native opt-in (MEGACOMPACT_ENCODER_NATIVE=1); shipped ${shippedMib} MiB across 5 platforms vs ${budgetMib} MiB budget`,
96
97
  demotionReason: null,
97
98
  };
98
99
  }
99
100
  // No bench record or degraded (gates.all:false) → WASM cannot qualify (the
100
101
  // placeholder 42-byte asset has no measured real p95), so native is selected
101
- // with the SAME amended-budget disposition as the opt-in path above: the
102
- // evidence records the closed HG-3 amendment.
102
+ // with the SAME budget comparison as the opt-in path above (configurable).
103
103
  if (!input.benchRecord || !input.benchRecord.gates.all || input.benchRecord.p95Ms === null) {
104
104
  const shippedMib = Object.values(NATIVE_FOOTPRINT_MIB).reduce((a, b) => a + b, 0);
105
+ const budgetMib = installBudgetMib();
105
106
  return {
106
107
  backend: "native",
107
- budgetOk: false, // amended: native ships > 80 MiB across the 5-platform matrix
108
+ budgetOk: shippedMib <= budgetMib,
108
109
  p95Ms: input.benchRecord?.p95Ms ?? null,
109
110
  platform: input.platform,
110
- rationale: `no qualifying bench record — native fallback with budget amendment (${shippedMib} MiB shipped, HG-3 amendment recorded)`,
111
+ rationale: `no qualifying bench record — native fallback (shipped ${shippedMib} MiB vs ${budgetMib} MiB budget)`,
111
112
  demotionReason: null,
112
113
  };
113
114
  }
114
115
  // The decision rule: WASM iff p95 <= 40 ms (linux-x64, 512 tokens, 4 threads) —
115
- // native required otherwise, with the same budget amendment recorded.
116
+ // native required otherwise, with the same configurable budget comparison.
116
117
  if (input.benchRecord.p95Ms <= ENCODER_LATENCY_P95_MS) {
117
118
  return {
118
119
  backend: "wasm",
@@ -123,12 +124,14 @@ export function selectRuntimeBackend(input) {
123
124
  demotionReason: null,
124
125
  };
125
126
  }
127
+ const shippedMib = Object.values(NATIVE_FOOTPRINT_MIB).reduce((a, b) => a + b, 0);
128
+ const budgetMib = installBudgetMib();
126
129
  return {
127
130
  backend: "native",
128
- budgetOk: false, // amended: native exceeds the 80 MiB budget per the evidence
131
+ budgetOk: shippedMib <= budgetMib,
129
132
  p95Ms: input.benchRecord.p95Ms,
130
133
  platform: input.platform,
131
- rationale: `native required: p95 ${input.benchRecord.p95Ms}ms > ${ENCODER_LATENCY_P95_MS}ms on WASM`,
134
+ rationale: `native required: p95 ${input.benchRecord.p95Ms}ms > ${ENCODER_LATENCY_P95_MS}ms on WASM (shipped ${shippedMib} MiB vs ${budgetMib} MiB budget)`,
132
135
  demotionReason: null,
133
136
  };
134
137
  }
@@ -52,10 +52,10 @@ export const SETUP_CORTEX_BLOCKERS = [
52
52
  },
53
53
  {
54
54
  id: "HG-3",
55
- title: "onnxruntime-node install exceeds the 80 MiB asset budget",
55
+ title: "native onnxruntime-node install path unresolved (needs operator install + probe), currently demoted to WASM",
56
56
  severity: "blocker",
57
57
  status: "open",
58
- resolution: "onnxruntime-node bundles ~258 MiB across all platforms. Candidate: transformers.js v4.2.0 (9.5 MiB shell, pure-Node via onnxruntime-web WASM) measured against budget + p95 gate before committing.",
58
+ resolution: "operator-run install of the pinned onnxruntime-node version into ~/.pi/mega-compact/native-ort, then re-run the ENC-0f qualification gate. The install byte-budget is operator-configurable (MEGACOMPACT_NATIVE_ORT_BUDGET_MIB, default 300 MiB; shipped 5-platform ~160 MiB fits at the default).",
59
59
  },
60
60
  {
61
61
  id: "HG-4",
@@ -3,9 +3,10 @@
3
3
  *
4
4
  * The durable EncoderBackendDecisionV1 record: which ONNX runtime backend the
5
5
  * real learned encoder ships on (transformers.js/WASM vs onnxruntime-node
6
- * native), whether the 80 MiB install budget holds, the per-platform install
7
- * matrix, the opset baseline (locked 21 by ENC-0a), the license verdict, and
8
- * the pinned model/tokenizer sha256 digests.
6
+ * native), whether the configurable install budget holds (default 300 MiB;
7
+ * operator-overridable via `MEGACOMPACT_NATIVE_ORT_BUDGET_MIB`), the per-platform
8
+ * install matrix, the opset baseline (locked 21 by ENC-0a), the license
9
+ * verdict, and the pinned model/tokenizer sha256 digests.
9
10
  *
10
11
  * ENC-0a is the DECISION + MEASUREMENT sprint: this contract is what the
11
12
  * deterministic resolver (`scripts/encoder/resolve-backend-decision.mjs`) and
@@ -37,10 +38,37 @@ export const DARWIN_X64_DEMOTION_REASON = "darwin-x64: no native binary upstream
37
38
  */
38
39
  export const DARWIN_X64_DEMOTION_REASON_SENTINEL = "darwin-x64: demoted to WASM (reason unavailable in platform matrix)";
39
40
  /**
40
- * The normative ENC-0a budget: the 80 MiB install/asset cap (MODEL_ASSET.md
41
- * §Qualification). Backend qualifies (budgetOk) iff the shipped byte-count fits.
41
+ * The operator-configurable native-ort install byte-budget (MiB). Default 300
42
+ * (shipped 5-platform ~160 MiB comfortably fits); override via
43
+ * `MEGACOMPACT_NATIVE_ORT_BUDGET_MIB`. Safe upper clamp `INSTALL_BUDGET_CLAMP_MIB`
44
+ * rejects absurd values. Backend qualifies (`budgetOk`) iff the shipped
45
+ * byte-count fits the configured budget.
42
46
  */
43
- export const ENCODER_INSTALL_BUDGET_MIB = 80;
47
+ export const INSTALL_BUDGET_CLAMP_MIB = 8192;
48
+ export const INSTALL_BUDGET_DEFAULT_MIB = 300;
49
+ /**
50
+ * Pure resolver: given a raw string (or null/undefined when the env var is
51
+ * unset), return the integer budget the runtime will use. Out-of-range /
52
+ * non-integer / empty input falls back to the default. Exported so the
53
+ * dashboard Settings surface can compute the EFFECTIVE operand from a
54
+ * persisted-but-not-yet-env-loaded value (the operator just POSTed a new
55
+ * budget to disk; the running process has not sourced `.mega-compact.env`,
56
+ * so `installBudgetMib()` reads the stale env, but the dashboard should show
57
+ * what the runtime WILL use after the restart the dashboard itself tells the
58
+ * operator is required).
59
+ */
60
+ export function resolveInstallBudgetMib(raw) {
61
+ if (raw === undefined || raw === null || raw === "")
62
+ return INSTALL_BUDGET_DEFAULT_MIB;
63
+ const n = Number(raw);
64
+ if (!Number.isInteger(n) || n <= 0 || n > INSTALL_BUDGET_CLAMP_MIB) {
65
+ return INSTALL_BUDGET_DEFAULT_MIB;
66
+ }
67
+ return n;
68
+ }
69
+ export function installBudgetMib() {
70
+ return resolveInstallBudgetMib(process.env.MEGACOMPACT_NATIVE_ORT_BUDGET_MIB);
71
+ }
44
72
  /** The p95 latency gate at 512 tokens / 4 threads on linux-x64 (ms). */
45
73
  export const ENCODER_DECISION_P95_MS = 40;
46
74
  /**