pi-mega-compact 0.20.50 → 0.20.51

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 (80) hide show
  1. package/dist/config/vector-cortex-enc1b.js +46 -0
  2. package/dist/config/vector-cortex.js +1 -0
  3. package/dist/config.js +1 -1
  4. package/dist/extensions/dashboard-server/routes-rag-settings-vector-cortex.js +1 -0
  5. package/dist/extensions/dashboard-server/routes-setup-enc1b.js +297 -0
  6. package/dist/extensions/dashboard-server/routes-setup-env-upsert.js +79 -0
  7. package/dist/extensions/dashboard-server/routes-setup.js +27 -26
  8. package/dist/src/config/vector-cortex-enc1b.js +46 -0
  9. package/dist/src/config/vector-cortex.js +1 -0
  10. package/dist/src/config.js +1 -1
  11. package/extensions/dashboard-client/dist/assets/{AreaChart-CeVnaV-0.js → AreaChart-BFTUTmmW.js} +2 -2
  12. package/extensions/dashboard-client/dist/assets/{AreaChart-CeVnaV-0.js.map → AreaChart-BFTUTmmW.js.map} +1 -1
  13. package/extensions/dashboard-client/dist/assets/{BarChart-DoNd35sw.js → BarChart-DfFurESR.js} +2 -2
  14. package/extensions/dashboard-client/dist/assets/{BarChart-DoNd35sw.js.map → BarChart-DfFurESR.js.map} +1 -1
  15. package/extensions/dashboard-client/dist/assets/{CacheTab-BROshdFf.js → CacheTab-FpCJSmy8.js} +2 -2
  16. package/extensions/dashboard-client/dist/assets/{CacheTab-BROshdFf.js.map → CacheTab-FpCJSmy8.js.map} +1 -1
  17. package/extensions/dashboard-client/dist/assets/{EventsTab-DAD6NeBR.js → EventsTab--9lJFJtc.js} +2 -2
  18. package/extensions/dashboard-client/dist/assets/{EventsTab-DAD6NeBR.js.map → EventsTab--9lJFJtc.js.map} +1 -1
  19. package/extensions/dashboard-client/dist/assets/{HealthTab-BBVMM54F.js → HealthTab-CkgtF1qa.js} +2 -2
  20. package/extensions/dashboard-client/dist/assets/{HealthTab-BBVMM54F.js.map → HealthTab-CkgtF1qa.js.map} +1 -1
  21. package/extensions/dashboard-client/dist/assets/{MaintenanceTab-f9VhlFco.js → MaintenanceTab-ChXGq1or.js} +2 -2
  22. package/extensions/dashboard-client/dist/assets/{MaintenanceTab-f9VhlFco.js.map → MaintenanceTab-ChXGq1or.js.map} +1 -1
  23. package/extensions/dashboard-client/dist/assets/{MemoryMapTab-BaxfyzN2.js → MemoryMapTab-CPpRR4MV.js} +2 -2
  24. package/extensions/dashboard-client/dist/assets/{MemoryMapTab-BaxfyzN2.js.map → MemoryMapTab-CPpRR4MV.js.map} +1 -1
  25. package/extensions/dashboard-client/dist/assets/{MetricsTab-DkUvoeS_.js → MetricsTab-Db1wkykf.js} +2 -2
  26. package/extensions/dashboard-client/dist/assets/{MetricsTab-DkUvoeS_.js.map → MetricsTab-Db1wkykf.js.map} +1 -1
  27. package/extensions/dashboard-client/dist/assets/{OverviewTab-BCpK1vgt.js → OverviewTab-LanDECrz.js} +2 -2
  28. package/extensions/dashboard-client/dist/assets/{OverviewTab-BCpK1vgt.js.map → OverviewTab-LanDECrz.js.map} +1 -1
  29. package/extensions/dashboard-client/dist/assets/{ReposTab-cJ5neYIG.js → ReposTab-I2umKduk.js} +2 -2
  30. package/extensions/dashboard-client/dist/assets/{ReposTab-cJ5neYIG.js.map → ReposTab-I2umKduk.js.map} +1 -1
  31. package/extensions/dashboard-client/dist/assets/{SessionsTab-8DyQv1Ry.js → SessionsTab-D_IxuEt5.js} +2 -2
  32. package/extensions/dashboard-client/dist/assets/{SessionsTab-8DyQv1Ry.js.map → SessionsTab-D_IxuEt5.js.map} +1 -1
  33. package/extensions/dashboard-client/dist/assets/SetupTab-BZ7Jn5MR.js +3 -0
  34. package/extensions/dashboard-client/dist/assets/SetupTab-BZ7Jn5MR.js.map +1 -0
  35. package/extensions/dashboard-client/dist/assets/{TimeSavedCard-8N7Vvlch.js → TimeSavedCard-BTdcO1E2.js} +2 -2
  36. package/extensions/dashboard-client/dist/assets/{TimeSavedCard-8N7Vvlch.js.map → TimeSavedCard-BTdcO1E2.js.map} +1 -1
  37. package/extensions/dashboard-client/dist/assets/{TurnsTab-CCijkQoH.js → TurnsTab-BXC8IL_B.js} +2 -2
  38. package/extensions/dashboard-client/dist/assets/{TurnsTab-CCijkQoH.js.map → TurnsTab-BXC8IL_B.js.map} +1 -1
  39. package/extensions/dashboard-client/dist/assets/{VcStatusBadge-D9a7By8x.js → VcStatusBadge-CNJnFtJo.js} +2 -2
  40. package/extensions/dashboard-client/dist/assets/{VcStatusBadge-D9a7By8x.js.map → VcStatusBadge-CNJnFtJo.js.map} +1 -1
  41. package/extensions/dashboard-client/dist/assets/{VectorCortexTab-pviD6CCy.js → VectorCortexTab-fsuWgA6e.js} +2 -2
  42. package/extensions/dashboard-client/dist/assets/{VectorCortexTab-pviD6CCy.js.map → VectorCortexTab-fsuWgA6e.js.map} +1 -1
  43. package/extensions/dashboard-client/dist/assets/{WikiTab-DLyicguz.js → WikiTab-Cn1BScDU.js} +2 -2
  44. package/extensions/dashboard-client/dist/assets/{WikiTab-DLyicguz.js.map → WikiTab-Cn1BScDU.js.map} +1 -1
  45. package/extensions/dashboard-client/dist/assets/{button-D8nKit8Y.js → button-B4_9rsul.js} +2 -2
  46. package/extensions/dashboard-client/dist/assets/{button-D8nKit8Y.js.map → button-B4_9rsul.js.map} +1 -1
  47. package/extensions/dashboard-client/dist/assets/{card-Xf5wHHBL.js → card-DUvC_geI.js} +2 -2
  48. package/extensions/dashboard-client/dist/assets/{card-Xf5wHHBL.js.map → card-DUvC_geI.js.map} +1 -1
  49. package/extensions/dashboard-client/dist/assets/{client-extra-CvxDLpQr.js → client-extra-HaH97bzp.js} +2 -2
  50. package/extensions/dashboard-client/dist/assets/{client-extra-CvxDLpQr.js.map → client-extra-HaH97bzp.js.map} +1 -1
  51. package/extensions/dashboard-client/dist/assets/{generateCategoricalChart-DhQquRa8.js → generateCategoricalChart-BxFWU2Mt.js} +2 -2
  52. package/extensions/dashboard-client/dist/assets/{generateCategoricalChart-DhQquRa8.js.map → generateCategoricalChart-BxFWU2Mt.js.map} +1 -1
  53. package/extensions/dashboard-client/dist/assets/index-C_aDd9kk.css +1 -0
  54. package/extensions/dashboard-client/dist/assets/{index-BUP3MK5S.js → index-xPdbZ73U.js} +3 -3
  55. package/extensions/dashboard-client/dist/assets/{index-BUP3MK5S.js.map → index-xPdbZ73U.js.map} +1 -1
  56. package/extensions/dashboard-client/dist/assets/{switch-B13rb8Z2.js → switch-Bv3_1R_j.js} +2 -2
  57. package/extensions/dashboard-client/dist/assets/{switch-B13rb8Z2.js.map → switch-Bv3_1R_j.js.map} +1 -1
  58. package/extensions/dashboard-client/dist/assets/{toggle-4h6DUEB5.js → toggle-DHXrB3Aw.js} +2 -2
  59. package/extensions/dashboard-client/dist/assets/{toggle-4h6DUEB5.js.map → toggle-DHXrB3Aw.js.map} +1 -1
  60. package/extensions/dashboard-client/dist/assets/{useSSE-Djom4z1K.js → useSSE-NigHeFyT.js} +2 -2
  61. package/extensions/dashboard-client/dist/assets/{useSSE-Djom4z1K.js.map → useSSE-NigHeFyT.js.map} +1 -1
  62. package/extensions/dashboard-client/dist/index.html +2 -2
  63. package/extensions/dashboard-client/src/tabs/SetupTab/CortexRuntimeCard.tsx +103 -0
  64. package/extensions/dashboard-client/src/tabs/SetupTab/CortexRuntimeCardStyles.ts +49 -0
  65. package/extensions/dashboard-client/src/tabs/SetupTab/CortexSetup.tsx +2 -0
  66. package/extensions/dashboard-client/src/tabs/SetupTab/CustomEndpointSection.tsx +122 -1
  67. package/extensions/dashboard-client/src/tabs/SetupTab/EmbedderSetup.tsx +57 -79
  68. package/extensions/dashboard-client/src/tabs/SetupTab/EmbedderSetupHelpers.tsx +75 -0
  69. package/extensions/dashboard-server/api-contracts/setup.ts +35 -0
  70. package/extensions/dashboard-server/routes-rag-settings-vector-cortex.ts +6 -0
  71. package/extensions/dashboard-server/routes-setup-enc1b.ts +336 -0
  72. package/extensions/dashboard-server/routes-setup-env-upsert.ts +93 -0
  73. package/extensions/dashboard-server/routes-setup.ts +26 -24
  74. package/package.json +1 -1
  75. package/src/config/vector-cortex-enc1b.ts +50 -0
  76. package/src/config/vector-cortex.ts +8 -0
  77. package/src/config.ts +1 -0
  78. package/extensions/dashboard-client/dist/assets/SetupTab-BQGPf9CI.js +0 -3
  79. package/extensions/dashboard-client/dist/assets/SetupTab-BQGPf9CI.js.map +0 -1
  80. package/extensions/dashboard-client/dist/assets/index-DbuGwYD7.css +0 -1
@@ -0,0 +1,46 @@
1
+ /**
2
+ * config/vector-cortex-enc1b.ts — ENC-1b ONNX runtime backend + embedder API
3
+ * Settings fields.
4
+ *
5
+ * Extracted from vector-cortex.ts so that file stays under the 300-line soft
6
+ * limit (soft-as-hard gate), exactly as the ENC-1a sibling was. 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-1b adds two Settings surfaces. (A) Embedder API completion: the three
11
+ * remaining env vars the runtime reads (src/httpEmbedder.ts:embeddingConfigFromEnv)
12
+ * gain dashboard-visible fields — `MEGACOMPACT_EMBEDDING_DIM` (numeric, validated
13
+ * positive int bounded by `ENC_1B_MAX_EMBEDDING_DIM`), `MEGACOMPACT_EMBEDDING_HEADERS`
14
+ * (JSON object string — secret-bearing, written verbatim to the per-repo
15
+ * `.mega-compact.env`, NEVER echoed raw; the GET reports only a boolean
16
+ * presence marker), and `MEGACOMPACT_ALLOW_REMOTE_EMBEDDER` (boolDirect toggle,
17
+ * default off — a deliberate escape hatch that skips the loopback-only check).
18
+ * (B) ONNX runtime selection surface: `MEGACOMPACT_ENCODER_NATIVE` is persisted
19
+ * to the per-repo env + surfaced as a Settings toggle, and the GET status route
20
+ * computes the current effective backend + demotion reason through the existing
21
+ * `selectRuntimeBackend` (reader-only — no selection literals reimplemented).
22
+ *
23
+ * `MEGACOMPACT_ENC_1B=0` disables: no new GET fields, no writer branch, no new
24
+ * Settings rows or toggle — byte-identical to the ENC-1a predecessor. The flag
25
+ * MUST also be a dashboard SETTINGS toggle (visible in config UI, never in
26
+ * EXCLUDED_SETTINGS).
27
+ *
28
+ * Pi-agnostic, dependency-free (PREVENT-PI-004 / PREVENT-011).
29
+ */
30
+ import { sprintFlag } from "./vector-cortex-flag.js";
31
+ /** ENC-1b `MEGACOMPACT_EMBEDDING_DIM` upper bound (positive integer string). */
32
+ export const ENC_1B_MAX_EMBEDDING_DIM = 8192;
33
+ /** Persisted env names pinned here so the aggregator scan + the routes share
34
+ * one source of truth (exactly the names embeddingConfigFromEnv reads). */
35
+ export const ENC_1B_EMBEDDING_DIM_ENV = "MEGACOMPACT_EMBEDDING_DIM";
36
+ export const ENC_1B_EMBEDDING_HEADERS_ENV = "MEGACOMPACT_EMBEDDING_HEADERS";
37
+ export const ENC_1B_ALLOW_REMOTE_EMBEDDER_ENV = "MEGACOMPACT_ALLOW_REMOTE_EMBEDDER";
38
+ export const ENC_1B_ENCODER_NATIVE_ENV = "MEGACOMPACT_ENCODER_NATIVE";
39
+ /**
40
+ * ENC-1b — ONNX runtime backend + embedder API Settings fields. Default ON.
41
+ * `MEGACOMPACT_ENC_1B=0` disables and is byte-identical to the ENC-1a
42
+ * predecessor: no new GET fields, no writer branch, no new Settings rows or
43
+ * toggle. This flag MUST also be a dashboard SETTINGS toggle (visible in config
44
+ * UI, never in EXCLUDED_SETTINGS).
45
+ */
46
+ export const ENC_1B_ENABLED = () => sprintFlag("MEGACOMPACT_ENC_1B");
@@ -33,5 +33,6 @@ export { ENC_0E_ENABLED } from "./vector-cortex-enc0e.js";
33
33
  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
+ 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";
36
37
  // Breaker constants (TRIAD_RESILIENCE.md §breaker) extracted to vector-cortex-breakers.ts.
37
38
  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, 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, 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";
@@ -66,5 +66,6 @@ export const VECTOR_CORTEX_SETTINGS = {
66
66
  boolDirect("MEGACOMPACT_ENC_0F", "ENC-0f p95 + marginal-RSS Qualification Gate", "ENC-0f p95 + marginal-RSS qualification gate (real trained asset → mode A): runs the ENC-0d-promoted trained asset through the bench under --expose-gc, asserts p95 ≤ 40 ms @ 512/4 threads, marginal RSS ≤ 150 MiB (baseline-subtracted), determinism, and opset-21; on pass emits QualificationV1 + flips runtime to qualified mode A, on failure asset stays demoted to mode B. OFF = no qualification gate runs, no QualificationV1 written, runtime keeps serving the ENC-0d survivor (byte-identical predecessor).", true),
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
+ 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),
69
70
  ],
70
71
  };
@@ -0,0 +1,297 @@
1
+ /**
2
+ * dashboard-server/routes-setup-enc1b.ts — ENC-1b embedder API completion +
3
+ * ONNX runtime selection Settings read/write + the additive writer branch.
4
+ *
5
+ * Extracted out of routes-setup.ts (which hovers at the 300-line source soft
6
+ * cap, mirroring the ENC-1a sibling extract) so the ENC-1b additive read/write
7
+ * of the per-repo `.mega-compact.env` keys AND the runtime-backend computation
8
+ * live in a sibling impl file. Four keys are managed here:
9
+ * `MEGACOMPACT_EMBEDDING_DIM`, `MEGACOMPACT_EMBEDDING_HEADERS`,
10
+ * `MEGACOMPACT_ALLOW_REMOTE_EMBEDDER`, `MEGACOMPACT_ENCODER_NATIVE` — the exact
11
+ * names `embeddingConfigFromEnv` (src/httpEmbedder.ts) and the runtime selector
12
+ * read at runtime.
13
+ *
14
+ * The write is create-or-append: it upserts the four keys into the existing
15
+ * per-repo `.mega-compact.env`, preserving every unrelated line and never
16
+ * deleting another key. The read reports the persisted dim, booleans for
17
+ * headers-set / allow-remote / native-opt-in, and computes the current
18
+ * effective backend + demotion reason through the EXISTING `selectRuntimeBackend`
19
+ * (reader-only — the runtime's own selection, never a reimplemented literal,
20
+ * never install logic). The raw headers JSON is NEVER returned, logged or
21
+ * emitted (redaction invariant — it may carry secrets such as an Authorization
22
+ * header for a TEI/ONNX server).
23
+ *
24
+ * Guardrails: PREVENT-PI-004 (local filesystem reads/writes + in-memory
25
+ * runtime selection only, zero network), PREVENT-001 (null-safe JSON),
26
+ * PREVENT-011 (no `any`).
27
+ */
28
+ import { writeFileSync, mkdirSync, readFileSync, existsSync } from "node:fs";
29
+ import { join } from "node:path";
30
+ import { 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 "../../src/config/vector-cortex.js";
31
+ import { selectRuntimeBackend } from "../../src/vector-cortex/encoder/runtime-select.js";
32
+ import { detectPlatform } from "../../src/vector-cortex/encoder/asset.js";
33
+ function envPath(stateDir) {
34
+ return join(stateDir, ".mega-compact.env");
35
+ }
36
+ /** Extract the value of `export MEGACOMPACT_X="..."` (or unquoted) from a line. */
37
+ function lineValue(line, key) {
38
+ const m = line.match(new RegExp(`^export\\s+${key}=(.*)$`));
39
+ if (!m)
40
+ return null;
41
+ const rest = m[1].trim();
42
+ if (rest.length === 0)
43
+ return null;
44
+ const q = rest.match(/^"([^"]*)"$/);
45
+ return q ? q[1] : rest;
46
+ }
47
+ /** True when the payload carries any ENC-1b key (flag-gated). */
48
+ export function wantsEnc1b(body) {
49
+ return (ENC_1B_ENABLED() &&
50
+ (typeof body.embeddingDim === "string" ||
51
+ typeof body.embeddingHeaders === "string" ||
52
+ typeof body.allowRemoteEmbedder === "boolean" ||
53
+ typeof body.encoderNativeOptIn === "boolean"));
54
+ }
55
+ /** Read the ENC-1b keys from the per-repo `.mega-compact.env`. The headers
56
+ * value is NEVER surfaced to callers — only its presence boolean. */
57
+ export function readEnc1bEnv(stateDir) {
58
+ try {
59
+ const p = envPath(stateDir);
60
+ if (!existsSync(p))
61
+ return { dim: null, headersSet: false, allowRemote: false, nativeOptIn: false };
62
+ const lines = readFileSync(p, "utf8").split(/\r?\n/);
63
+ let dim = null;
64
+ let headersSet = false;
65
+ let allowRemote = false;
66
+ let nativeOptIn = false;
67
+ for (const line of lines) {
68
+ const d = lineValue(line, ENC_1B_EMBEDDING_DIM_ENV);
69
+ if (d !== null && d.length > 0)
70
+ dim = d;
71
+ const h = lineValue(line, ENC_1B_EMBEDDING_HEADERS_ENV);
72
+ if (h !== null && h.length > 0)
73
+ headersSet = true;
74
+ const a = lineValue(line, ENC_1B_ALLOW_REMOTE_EMBEDDER_ENV);
75
+ if (a !== null && ["1", "true", "yes"].includes(a.trim().toLowerCase()))
76
+ allowRemote = true;
77
+ const n = lineValue(line, ENC_1B_ENCODER_NATIVE_ENV);
78
+ if (n !== null && ["1", "true", "yes"].includes(n.trim().toLowerCase()))
79
+ nativeOptIn = true;
80
+ }
81
+ return { dim, headersSet, allowRemote, nativeOptIn };
82
+ }
83
+ catch {
84
+ return { dim: null, headersSet: false, allowRemote: false, nativeOptIn: false };
85
+ }
86
+ }
87
+ /**
88
+ * ENC-1b additive GET status fields. All omitted when flag-off. The Cortex
89
+ * trio (native opt-in + effective backend + demotion reason) is computed here
90
+ * (reader-only): the stored opt-in + current platform drive the EXISTING
91
+ * `selectRuntimeBackend`, whose own demotion reason is surfaced verbatim when
92
+ * the runtime falls back. `modeB` (flag-off selection) is projected to `wasm`
93
+ * for display. Returns `{}` when the flag is off (byte-identical predecessor).
94
+ */
95
+ export function enc1bStatusFields(stateDir) {
96
+ if (!ENC_1B_ENABLED())
97
+ return {};
98
+ const env = readEnc1bEnv(stateDir);
99
+ const platform = detectPlatform();
100
+ const chosen = selectRuntimeBackend({
101
+ platform: platform ?? "unsupported",
102
+ benchRecord: null,
103
+ nativeOptIn: env.nativeOptIn,
104
+ });
105
+ const backend = chosen.backend === "native" ? "native" : "wasm";
106
+ return {
107
+ ...(env.dim !== null ? { embeddingDim: env.dim } : {}),
108
+ embeddingHeadersSet: env.headersSet,
109
+ allowRemoteEmbedder: env.allowRemote,
110
+ encoderNativeOptIn: env.nativeOptIn,
111
+ encoderBackend: backend,
112
+ encoderDemotionReason: chosen.demotionReason,
113
+ };
114
+ }
115
+ /** Upsert the ENC-1b keys into the per-repo `.mega-compact.env`. Creates the
116
+ * file if absent; preserves every unrelated line; never deletes other keys.
117
+ * A `null` entry leaves that key's line untouched. The headers value is
118
+ * wrapped in single quotes so the inner JSON double quotes survive the env
119
+ * loader's outer-quote strip (shell-sourceable + loader-compatible). */
120
+ export function writeEnc1bEnv(stateDir, entries) {
121
+ const p = envPath(stateDir);
122
+ const existingLines = existsSync(p) ? readFileSync(p, "utf8").split(/\r?\n/) : [];
123
+ const out = [];
124
+ const keys = new Set([
125
+ {
126
+ key: ENC_1B_EMBEDDING_DIM_ENV,
127
+ present: () => entries.dim !== null,
128
+ push: () => out.push(`export ${ENC_1B_EMBEDDING_DIM_ENV}="${entries.dim ?? ""}"`),
129
+ },
130
+ {
131
+ key: ENC_1B_EMBEDDING_HEADERS_ENV,
132
+ present: () => entries.headers !== null,
133
+ push: () => out.push(`export ${ENC_1B_EMBEDDING_HEADERS_ENV}='${entries.headers ?? ""}'`),
134
+ },
135
+ {
136
+ key: ENC_1B_ALLOW_REMOTE_EMBEDDER_ENV,
137
+ present: () => entries.allowRemote !== null,
138
+ push: () => out.push(entries.allowRemote
139
+ ? `export ${ENC_1B_ALLOW_REMOTE_EMBEDDER_ENV}="1"`
140
+ : `export ${ENC_1B_ALLOW_REMOTE_EMBEDDER_ENV}="0"`),
141
+ },
142
+ {
143
+ key: ENC_1B_ENCODER_NATIVE_ENV,
144
+ present: () => entries.nativeOptIn !== null,
145
+ push: () => out.push(entries.nativeOptIn
146
+ ? `export ${ENC_1B_ENCODER_NATIVE_ENV}="1"`
147
+ : `export ${ENC_1B_ENCODER_NATIVE_ENV}="0"`),
148
+ },
149
+ ]);
150
+ const written = new Set();
151
+ for (const line of existingLines) {
152
+ let replaced = false;
153
+ for (const k of keys) {
154
+ if (k.present() && lineValue(line, k.key) !== null) {
155
+ k.push();
156
+ written.add(k.key);
157
+ replaced = true;
158
+ break;
159
+ }
160
+ }
161
+ if (!replaced)
162
+ out.push(line);
163
+ }
164
+ for (const k of keys) {
165
+ if (k.present() && !written.has(k.key))
166
+ k.push();
167
+ }
168
+ mkdirSync(stateDir, { recursive: true });
169
+ writeFileSync(p, out.join("\n"), "utf-8");
170
+ return p;
171
+ }
172
+ /** Validate `embeddingDim` as a positive integer string within the ENC-1b cap.
173
+ * Returns `null` when valid, else the error code. Exported so the routes host
174
+ * (combined-payload path) and the aggregator share the same rule. */
175
+ export function validateDim(value) {
176
+ if (typeof value !== "string" || value.trim().length === 0)
177
+ return "invalid_embedding_dim";
178
+ if (!/^\d+$/.test(value))
179
+ return "invalid_embedding_dim";
180
+ const n = Number(value);
181
+ if (!Number.isSafeInteger(n) || n < 1 || n > ENC_1B_MAX_EMBEDDING_DIM) {
182
+ return "invalid_embedding_dim";
183
+ }
184
+ return null;
185
+ }
186
+ /** Validate `embeddingHeaders` as a string that parses to a JSON object.
187
+ * Returns `null` when valid, else the error code. Exported so the routes host
188
+ * (combined-payload path) and the aggregator share the same rule. */
189
+ export function validateHeaders(value) {
190
+ if (typeof value !== "string" || value.trim().length === 0)
191
+ return "invalid_embedding_headers";
192
+ let parsed;
193
+ try {
194
+ parsed = JSON.parse(value);
195
+ }
196
+ catch {
197
+ return "invalid_embedding_headers";
198
+ }
199
+ if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) {
200
+ return "invalid_embedding_headers";
201
+ }
202
+ return null;
203
+ }
204
+ /**
205
+ * Combined-payload upsert: after the main embedder write has freshly written
206
+ * the per-repo env, append any ENC-1b keys carried alongside a valid embedder
207
+ * selection (flag-gated, additive). No-op when flag-off or no ENC-1b key.
208
+ */
209
+ export function tryEnc1bInto(stateDir, body) {
210
+ if (!wantsEnc1b(body))
211
+ return;
212
+ writeEnc1bEnv(stateDir, {
213
+ dim: typeof body.embeddingDim === "string" ? body.embeddingDim : null,
214
+ headers: typeof body.embeddingHeaders === "string" ? body.embeddingHeaders : null,
215
+ allowRemote: typeof body.allowRemoteEmbedder === "boolean" ? body.allowRemoteEmbedder : null,
216
+ nativeOptIn: typeof body.encoderNativeOptIn === "boolean" ? body.encoderNativeOptIn : null,
217
+ });
218
+ }
219
+ /**
220
+ * If the payload is a pure ENC-1b configure (new keys, no embedder selection),
221
+ * validate + write them additively to the per-repo env and reply. Returns true
222
+ * when it fully handled the request. On a validation failure it replies 400
223
+ * with the code and leaves the file byte-unchanged. Flag-off = keys are not
224
+ * recognized and this returns false (byte-identical ENC-1a predecessor).
225
+ */
226
+ /**
227
+ * Combined-path validation: the standalone `tryEnc1bConfigure` handles the
228
+ * pure-ENC-1b shape; when a payload ALSO carries a valid embedder the sibling
229
+ * writer returns false and the routes host is responsible for running the same
230
+ * dim/headers validation before the combined upsert — returned as the error
231
+ * code string, or `null` if everything passes (or the flag is off).
232
+ */
233
+ export function enc1bValidateCombined(body) {
234
+ if (!ENC_1B_ENABLED())
235
+ return null;
236
+ if (body.embeddingDim !== undefined) {
237
+ const e = validateDim(body.embeddingDim);
238
+ if (e !== null)
239
+ return e;
240
+ }
241
+ if (body.embeddingHeaders !== undefined) {
242
+ const e = validateHeaders(body.embeddingHeaders);
243
+ if (e !== null)
244
+ return e;
245
+ }
246
+ return null;
247
+ }
248
+ export function tryEnc1bConfigure(body, res, ctx) {
249
+ if (!wantsEnc1b(body))
250
+ return false;
251
+ const embedder = body.embedder;
252
+ const embedderValid = !!embedder &&
253
+ (embedder === "ollama" || embedder === "llama" || embedder === "trigram" ||
254
+ embedder === "custom" || embedder === "onnx");
255
+ if (embedderValid)
256
+ return false; // combined payload — integrated after the embedder write
257
+ // Each key is optional: only validate the ones actually carried in the
258
+ // payload (absent keys are left untouched, never rejected).
259
+ const dimError = body.embeddingDim === undefined ? null : validateDim(body.embeddingDim);
260
+ if (dimError !== null) {
261
+ // guardrails-allow PREVENT-PI-004: loopback dashboard response (local)
262
+ res.writeHead(400, { "Content-Type": "application/json" });
263
+ res.end(JSON.stringify({ error: dimError }));
264
+ return true;
265
+ }
266
+ const headersError = body.embeddingHeaders === undefined ? null : validateHeaders(body.embeddingHeaders);
267
+ if (headersError !== null) {
268
+ // guardrails-allow PREVENT-PI-004: loopback dashboard response (local)
269
+ res.writeHead(400, { "Content-Type": "application/json" });
270
+ res.end(JSON.stringify({ error: headersError }));
271
+ return true;
272
+ }
273
+ try {
274
+ const envPath = writeEnc1bEnv(ctx.stateDir, {
275
+ dim: typeof body.embeddingDim === "string" ? body.embeddingDim : null,
276
+ headers: typeof body.embeddingHeaders === "string" ? body.embeddingHeaders : null,
277
+ allowRemote: typeof body.allowRemoteEmbedder === "boolean" ? body.allowRemoteEmbedder : null,
278
+ nativeOptIn: typeof body.encoderNativeOptIn === "boolean" ? body.encoderNativeOptIn : null,
279
+ });
280
+ const resp = {
281
+ embedder: "custom",
282
+ url: null,
283
+ envPath,
284
+ restartRequired: true,
285
+ alreadyActive: false,
286
+ };
287
+ // guardrails-allow PREVENT-PI-004: loopback dashboard response (local)
288
+ res.writeHead(200, { "Content-Type": "application/json" });
289
+ res.end(JSON.stringify(resp));
290
+ return true;
291
+ }
292
+ catch (e) {
293
+ res.writeHead(500, { "Content-Type": "application/json" });
294
+ res.end(JSON.stringify({ error: `write_failed: ${e instanceof Error ? e.message : String(e)}` }));
295
+ return true;
296
+ }
297
+ }
@@ -0,0 +1,79 @@
1
+ /**
2
+ * routes-setup-env-upsert.ts — upsert-style write of the per-repo
3
+ * `.mega-compact.env` for the primary embedder selection.
4
+ *
5
+ * Extracted from routes-setup.ts so the route stays under the 300-line soft
6
+ * cap. The writer preserves every unrelated line (ENC-1a's endpoint/key,
7
+ * ENC-1b's dim/headers, operator comments) and replaces only the three keys
8
+ * this primary write owns — MEGACOMPACT_EMBEDDING_URL,
9
+ * MEGACOMPACT_ALLOW_REMOTE_EMBEDDER, MEGACOMPACT_MINILM. URLs already persisted
10
+ * by enc1a/enc1b helpers are NOT clobbered across a later native-opt-in POST
11
+ * (the ENC-1b defect class caught in live review).
12
+ */
13
+ import { writeFileSync, mkdirSync, readFileSync, existsSync } from "node:fs";
14
+ import { join } from "node:path";
15
+ /** Line-prefix recognizer for an owned key (covers active, commented, and prose forms). */
16
+ function ownsKey(line, key) {
17
+ return (line.startsWith(`export ${key}=`) ||
18
+ line.startsWith(`# export ${key}=`) ||
19
+ line.startsWith(`# ${key} `));
20
+ }
21
+ const OWNED_PREFIXES = [
22
+ "MEGACOMPACT_EMBEDDING_URL",
23
+ "MEGACOMPACT_ALLOW_REMOTE_EMBEDDER",
24
+ "MEGACOMPACT_MINILM",
25
+ ];
26
+ const SCAFFOLD_COMMENTS = new Set([
27
+ "# Mega-Compact Embedder Configuration",
28
+ "# trigram: built-in embedder, no URL needed",
29
+ "# unset MEGACOMPACT_EMBEDDING_URL (commented to override any shell-set value)",
30
+ "# MEGACOMPACT_ALLOW_REMOTE_EMBEDDER not set (loopback-only)",
31
+ ]);
32
+ function isScaffoldComment(line) {
33
+ return (SCAFFOLD_COMMENTS.has(line) ||
34
+ line.startsWith("# Configured via dashboard Setup tab at "));
35
+ }
36
+ /**
37
+ * Write the embedder selection upsert-style into `<stateDir>/.mega-compact.env`.
38
+ * `resolvedUrl === null` selects the trigram (built-in) path — the emitted
39
+ * lines carry only the scaffold comments for that case (the URL/remote lines
40
+ * are intentionally absent, matching the pre-refactor byte shape).
41
+ */
42
+ export function writeEmbedderEnv(stateDir, resolvedUrl, allowRemote) {
43
+ const envPath = join(stateDir, ".mega-compact.env");
44
+ const existingLines = (() => {
45
+ try {
46
+ return existsSync(envPath) ? readFileSync(envPath, "utf-8").split("\n") : [];
47
+ }
48
+ catch {
49
+ return [];
50
+ }
51
+ })();
52
+ const preserved = existingLines.filter((l) => l.trim().length > 0 &&
53
+ !isScaffoldComment(l) &&
54
+ !OWNED_PREFIXES.some((p) => ownsKey(l, p)));
55
+ const next = [
56
+ "# Mega-Compact Embedder Configuration",
57
+ `# Configured via dashboard Setup tab at ${new Date().toISOString()}`,
58
+ ...preserved,
59
+ ];
60
+ if (resolvedUrl !== null) {
61
+ next.push(`export MEGACOMPACT_EMBEDDING_URL="${resolvedUrl}"`);
62
+ if (allowRemote) {
63
+ next.push(`export MEGACOMPACT_ALLOW_REMOTE_EMBEDDER="1"`);
64
+ }
65
+ else {
66
+ next.push(`# MEGACOMPACT_ALLOW_REMOTE_EMBEDDER not set (loopback-only)`);
67
+ }
68
+ }
69
+ else {
70
+ next.push("# trigram: built-in embedder, no URL needed");
71
+ next.push("# unset MEGACOMPACT_EMBEDDING_URL (commented to override any shell-set value)");
72
+ next.push("# export MEGACOMPACT_EMBEDDING_URL=");
73
+ next.push("# export MEGACOMPACT_ALLOW_REMOTE_EMBEDDER=");
74
+ }
75
+ next.push("");
76
+ mkdirSync(stateDir, { recursive: true });
77
+ writeFileSync(envPath, next.join("\n"), "utf-8");
78
+ return envPath;
79
+ }
@@ -8,10 +8,12 @@
8
8
  * The detection commands run local subprocesses via spawnSync, NOT network calls.
9
9
  * Each decoration line carries a guardrails-allow annotation.
10
10
  */
11
- import { writeFileSync, mkdirSync, readFileSync, existsSync } from "node:fs";
11
+ import { readFileSync, existsSync } from "node:fs";
12
12
  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
+ import { enc1bStatusFields, tryEnc1bConfigure, tryEnc1bInto, enc1bValidateCombined } from "./routes-setup-enc1b.js";
16
+ import { writeEmbedderEnv } from "./routes-setup-env-upsert.js";
15
17
  import { detectOllama, detectLlamaCpp, detectOnnx, memoizedDetectOllama, memoizedDetectLlamaCpp, memoizedDetectOnnx, } from "./routes-setup-detect-cache.js";
16
18
  // ---------------------------------------------------------------------------
17
19
  // handleSetupStatus — "/api/setup-status"
@@ -68,7 +70,7 @@ export function handleSetupStatus(req, res, ctx) {
68
70
  embeddingUrl: process.env["MEGACOMPACT_EMBEDDING_URL"] ?? configured.url,
69
71
  embedCache: process.env["MEGACOMPACT_EMBED_CACHE"] ?? null,
70
72
  minilm: ["1", "true", "yes"].includes((process.env["MEGACOMPACT_MINILM"] ?? "").trim().toLowerCase()),
71
- ...enc1aStatusFields(ctx.stateDir),
73
+ ...enc1aStatusFields(ctx.stateDir), ...enc1bStatusFields(ctx.stateDir),
72
74
  };
73
75
  // guardrails-allow PREVENT-PI-004: loopback dashboard response (local)
74
76
  res.writeHead(200, { "Content-Type": "application/json" });
@@ -176,6 +178,22 @@ export function handleSetupConfigure(req, res, ctx) {
176
178
  // pre-ENC-1a embedder path below (byte-identical predecessor).
177
179
  if (tryEnc1aConfigure(body, res, ctx))
178
180
  return;
181
+ if (tryEnc1bConfigure(body, res, ctx))
182
+ return; // pure ENC-1b configure (dim/headers/allow-remote/native)
183
+ // ENC-1b combined-payload validation: when a payload carries a valid
184
+ // embedder PLUS the ENC-1b keys, tryEnc1bConfigure above returned false
185
+ // (it handles only the pure-ENC-1b shape) and tryEnc1bInto below would
186
+ // write WITHOUT validating. Run the same dim/headers validation here so
187
+ // the combined path is rejected with the same 400 codes. Flag-off:
188
+ // enc1bValidateCombined returns null (byte-identical predecessor — the
189
+ // unknown keys fall through untouched).
190
+ const combinedError = enc1bValidateCombined(body);
191
+ if (combinedError !== null) {
192
+ // guardrails-allow PREVENT-PI-004: loopback dashboard response (local)
193
+ res.writeHead(400, { "Content-Type": "application/json" });
194
+ res.end(JSON.stringify({ error: combinedError }));
195
+ return;
196
+ }
179
197
  const embedder = body.embedder;
180
198
  if (embedder !== "ollama" && embedder !== "llama" && embedder !== "trigram" && embedder !== "custom" && embedder !== "onnx") {
181
199
  res.writeHead(400, { "Content-Type": "application/json" });
@@ -204,32 +222,14 @@ export function handleSetupConfigure(req, res, ctx) {
204
222
  }
205
223
  else
206
224
  resolvedUrl = null;
207
- // Write .mega-compact.env to the state dir (loaded by env-loader at next startup).
225
+ // Upsert-style write of the per-repo .mega-compact.env (sibling impl):
226
+ // preserves ENC-1a's endpoint/key + ENC-1b's dim/headers lines and any
227
+ // operator comments, replacing only the three keys this primary embedder
228
+ // write owns (URL / ALLOW_REMOTE / MINILM).
208
229
  const stateDir = ctx.stateDir;
209
- const envPath = join(stateDir, ".mega-compact.env");
210
- const lines = [
211
- "# Mega-Compact Embedder Configuration",
212
- `# Configured via dashboard Setup tab at ${new Date().toISOString()}`,
213
- ];
214
- if (resolvedUrl) {
215
- lines.push(`export MEGACOMPACT_EMBEDDING_URL="${resolvedUrl}"`);
216
- if (allowRemote) {
217
- lines.push(`export MEGACOMPACT_ALLOW_REMOTE_EMBEDDER="1"`);
218
- }
219
- else {
220
- lines.push(`# MEGACOMPACT_ALLOW_REMOTE_EMBEDDER not set (loopback-only)`);
221
- }
222
- }
223
- else {
224
- lines.push("# trigram: built-in embedder, no URL needed");
225
- lines.push("# unset MEGACOMPACT_EMBEDDING_URL (commented to override any shell-set value)");
226
- lines.push("# export MEGACOMPACT_EMBEDDING_URL=");
227
- lines.push("# export MEGACOMPACT_ALLOW_REMOTE_EMBEDDER=");
228
- }
229
- lines.push("");
230
+ let envPath;
230
231
  try {
231
- mkdirSync(stateDir, { recursive: true });
232
- writeFileSync(envPath, lines.join("\n"), "utf-8");
232
+ envPath = writeEmbedderEnv(stateDir, resolvedUrl, allowRemote);
233
233
  }
234
234
  catch (e) {
235
235
  res.writeHead(500, { "Content-Type": "application/json" });
@@ -246,6 +246,7 @@ export function handleSetupConfigure(req, res, ctx) {
246
246
  apiKey: typeof body.embeddingApiKey === "string" ? body.embeddingApiKey : null,
247
247
  });
248
248
  }
249
+ tryEnc1bInto(stateDir, body); // ENC-1b combined upsert (dim/headers/allow-remote/native)
249
250
  // Detect if the new config matches what's already active (no restart needed).
250
251
  const currentUrl = process.env["MEGACOMPACT_EMBEDDING_URL"];
251
252
  const alreadyActive = (resolvedUrl === null && !currentUrl) || (resolvedUrl !== null && currentUrl === resolvedUrl);
@@ -0,0 +1,46 @@
1
+ /**
2
+ * config/vector-cortex-enc1b.ts — ENC-1b ONNX runtime backend + embedder API
3
+ * Settings fields.
4
+ *
5
+ * Extracted from vector-cortex.ts so that file stays under the 300-line soft
6
+ * limit (soft-as-hard gate), exactly as the ENC-1a sibling was. 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-1b adds two Settings surfaces. (A) Embedder API completion: the three
11
+ * remaining env vars the runtime reads (src/httpEmbedder.ts:embeddingConfigFromEnv)
12
+ * gain dashboard-visible fields — `MEGACOMPACT_EMBEDDING_DIM` (numeric, validated
13
+ * positive int bounded by `ENC_1B_MAX_EMBEDDING_DIM`), `MEGACOMPACT_EMBEDDING_HEADERS`
14
+ * (JSON object string — secret-bearing, written verbatim to the per-repo
15
+ * `.mega-compact.env`, NEVER echoed raw; the GET reports only a boolean
16
+ * presence marker), and `MEGACOMPACT_ALLOW_REMOTE_EMBEDDER` (boolDirect toggle,
17
+ * default off — a deliberate escape hatch that skips the loopback-only check).
18
+ * (B) ONNX runtime selection surface: `MEGACOMPACT_ENCODER_NATIVE` is persisted
19
+ * to the per-repo env + surfaced as a Settings toggle, and the GET status route
20
+ * computes the current effective backend + demotion reason through the existing
21
+ * `selectRuntimeBackend` (reader-only — no selection literals reimplemented).
22
+ *
23
+ * `MEGACOMPACT_ENC_1B=0` disables: no new GET fields, no writer branch, no new
24
+ * Settings rows or toggle — byte-identical to the ENC-1a predecessor. The flag
25
+ * MUST also be a dashboard SETTINGS toggle (visible in config UI, never in
26
+ * EXCLUDED_SETTINGS).
27
+ *
28
+ * Pi-agnostic, dependency-free (PREVENT-PI-004 / PREVENT-011).
29
+ */
30
+ import { sprintFlag } from "./vector-cortex-flag.js";
31
+ /** ENC-1b `MEGACOMPACT_EMBEDDING_DIM` upper bound (positive integer string). */
32
+ export const ENC_1B_MAX_EMBEDDING_DIM = 8192;
33
+ /** Persisted env names pinned here so the aggregator scan + the routes share
34
+ * one source of truth (exactly the names embeddingConfigFromEnv reads). */
35
+ export const ENC_1B_EMBEDDING_DIM_ENV = "MEGACOMPACT_EMBEDDING_DIM";
36
+ export const ENC_1B_EMBEDDING_HEADERS_ENV = "MEGACOMPACT_EMBEDDING_HEADERS";
37
+ export const ENC_1B_ALLOW_REMOTE_EMBEDDER_ENV = "MEGACOMPACT_ALLOW_REMOTE_EMBEDDER";
38
+ export const ENC_1B_ENCODER_NATIVE_ENV = "MEGACOMPACT_ENCODER_NATIVE";
39
+ /**
40
+ * ENC-1b — ONNX runtime backend + embedder API Settings fields. Default ON.
41
+ * `MEGACOMPACT_ENC_1B=0` disables and is byte-identical to the ENC-1a
42
+ * predecessor: no new GET fields, no writer branch, no new Settings rows or
43
+ * toggle. This flag MUST also be a dashboard SETTINGS toggle (visible in config
44
+ * UI, never in EXCLUDED_SETTINGS).
45
+ */
46
+ export const ENC_1B_ENABLED = () => sprintFlag("MEGACOMPACT_ENC_1B");
@@ -33,5 +33,6 @@ export { ENC_0E_ENABLED } from "./vector-cortex-enc0e.js";
33
33
  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
+ 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";
36
37
  // Breaker constants (TRIAD_RESILIENCE.md §breaker) extracted to vector-cortex-breakers.ts.
37
38
  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, 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, 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";