pi-mega-compact 0.20.63 → 0.20.64

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 (85) hide show
  1. package/dist/config/vector-cortex-enc2a.js +35 -0
  2. package/dist/config/vector-cortex.js +2 -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-enc2a.js +119 -0
  6. package/dist/extensions/dashboard-server/routes-setup.js +26 -0
  7. package/dist/src/config/vector-cortex-enc2a.js +35 -0
  8. package/dist/src/config/vector-cortex.js +2 -0
  9. package/dist/src/config.js +1 -1
  10. package/dist/src/vector-cortex/encoder/native-install-artifacts.js +43 -0
  11. package/dist/vector-cortex/encoder/native-install-artifacts.js +43 -0
  12. package/extensions/dashboard-client/dist/assets/{AdminTab-DrJ9VWRu.js → AdminTab-sjV8P5A4.js} +2 -2
  13. package/extensions/dashboard-client/dist/assets/{AdminTab-DrJ9VWRu.js.map → AdminTab-sjV8P5A4.js.map} +1 -1
  14. package/extensions/dashboard-client/dist/assets/{AreaChart-B1OkLRGT.js → AreaChart-C03yuld4.js} +2 -2
  15. package/extensions/dashboard-client/dist/assets/{AreaChart-B1OkLRGT.js.map → AreaChart-C03yuld4.js.map} +1 -1
  16. package/extensions/dashboard-client/dist/assets/{BarChart-IWwm38i0.js → BarChart-B9jtJ7ud.js} +2 -2
  17. package/extensions/dashboard-client/dist/assets/{BarChart-IWwm38i0.js.map → BarChart-B9jtJ7ud.js.map} +1 -1
  18. package/extensions/dashboard-client/dist/assets/{CacheTab-DvNlBxzX.js → CacheTab-B7Eh3qfp.js} +2 -2
  19. package/extensions/dashboard-client/dist/assets/{CacheTab-DvNlBxzX.js.map → CacheTab-B7Eh3qfp.js.map} +1 -1
  20. package/extensions/dashboard-client/dist/assets/{ConfigTab-C1t0EM2H.js → ConfigTab-DDTqosv2.js} +2 -2
  21. package/extensions/dashboard-client/dist/assets/{ConfigTab-C1t0EM2H.js.map → ConfigTab-DDTqosv2.js.map} +1 -1
  22. package/extensions/dashboard-client/dist/assets/{EventsTab-CCexdJjG.js → EventsTab-BmyQGmUa.js} +2 -2
  23. package/extensions/dashboard-client/dist/assets/{EventsTab-CCexdJjG.js.map → EventsTab-BmyQGmUa.js.map} +1 -1
  24. package/extensions/dashboard-client/dist/assets/{HealthTab-BkAKwtxe.js → HealthTab-DzPqNqpm.js} +2 -2
  25. package/extensions/dashboard-client/dist/assets/{HealthTab-BkAKwtxe.js.map → HealthTab-DzPqNqpm.js.map} +1 -1
  26. package/extensions/dashboard-client/dist/assets/{MaintenanceTab-Beb59xuJ.js → MaintenanceTab-6g3d-M1p.js} +2 -2
  27. package/extensions/dashboard-client/dist/assets/{MaintenanceTab-Beb59xuJ.js.map → MaintenanceTab-6g3d-M1p.js.map} +1 -1
  28. package/extensions/dashboard-client/dist/assets/{MemoryMapTab-P04ao17z.js → MemoryMapTab-Nk2yYPMS.js} +2 -2
  29. package/extensions/dashboard-client/dist/assets/{MemoryMapTab-P04ao17z.js.map → MemoryMapTab-Nk2yYPMS.js.map} +1 -1
  30. package/extensions/dashboard-client/dist/assets/{MetricsCards-YlmnUe01.js → MetricsCards-BlIiuZp5.js} +2 -2
  31. package/extensions/dashboard-client/dist/assets/{MetricsCards-YlmnUe01.js.map → MetricsCards-BlIiuZp5.js.map} +1 -1
  32. package/extensions/dashboard-client/dist/assets/MetricsTab-DfRDIAEU.js +2 -0
  33. package/extensions/dashboard-client/dist/assets/{MetricsTab-C2rXqvoD.js.map → MetricsTab-DfRDIAEU.js.map} +1 -1
  34. package/extensions/dashboard-client/dist/assets/{OverviewTab-BBNvmR3X.js → OverviewTab-xkuFE5GV.js} +2 -2
  35. package/extensions/dashboard-client/dist/assets/{OverviewTab-BBNvmR3X.js.map → OverviewTab-xkuFE5GV.js.map} +1 -1
  36. package/extensions/dashboard-client/dist/assets/{ReposTab-CjlumghA.js → ReposTab-C6qZmmgQ.js} +2 -2
  37. package/extensions/dashboard-client/dist/assets/{ReposTab-CjlumghA.js.map → ReposTab-C6qZmmgQ.js.map} +1 -1
  38. package/extensions/dashboard-client/dist/assets/{SessionsTab-D1tWcUn-.js → SessionsTab-Bkd_In3n.js} +2 -2
  39. package/extensions/dashboard-client/dist/assets/{SessionsTab-D1tWcUn-.js.map → SessionsTab-Bkd_In3n.js.map} +1 -1
  40. package/extensions/dashboard-client/dist/assets/SetupTab-CEXL71VP.js +3 -0
  41. package/extensions/dashboard-client/dist/assets/SetupTab-CEXL71VP.js.map +1 -0
  42. package/extensions/dashboard-client/dist/assets/{TimeSavedCard-DzBeE2y4.js → TimeSavedCard-Dr0KNUed.js} +2 -2
  43. package/extensions/dashboard-client/dist/assets/{TimeSavedCard-DzBeE2y4.js.map → TimeSavedCard-Dr0KNUed.js.map} +1 -1
  44. package/extensions/dashboard-client/dist/assets/{TurnMemoryView-DKVIkjot.js → TurnMemoryView-CjmSiRQ_.js} +2 -2
  45. package/extensions/dashboard-client/dist/assets/{TurnMemoryView-DKVIkjot.js.map → TurnMemoryView-CjmSiRQ_.js.map} +1 -1
  46. package/extensions/dashboard-client/dist/assets/TurnsTab-JsDstDDA.js +2 -0
  47. package/extensions/dashboard-client/dist/assets/{TurnsTab-Cqyq6fVe.js.map → TurnsTab-JsDstDDA.js.map} +1 -1
  48. package/extensions/dashboard-client/dist/assets/{VcStatusBadge-CBtRo20h.js → VcStatusBadge-C96wfemg.js} +2 -2
  49. package/extensions/dashboard-client/dist/assets/{VcStatusBadge-CBtRo20h.js.map → VcStatusBadge-C96wfemg.js.map} +1 -1
  50. package/extensions/dashboard-client/dist/assets/{VectorCortexTab-Bk53uJZZ.js → VectorCortexTab-DGV3kA7X.js} +2 -2
  51. package/extensions/dashboard-client/dist/assets/{VectorCortexTab-Bk53uJZZ.js.map → VectorCortexTab-DGV3kA7X.js.map} +1 -1
  52. package/extensions/dashboard-client/dist/assets/{WikiTab-CemxY6Lm.js → WikiTab-EFfy5v-D.js} +2 -2
  53. package/extensions/dashboard-client/dist/assets/{WikiTab-CemxY6Lm.js.map → WikiTab-EFfy5v-D.js.map} +1 -1
  54. package/extensions/dashboard-client/dist/assets/{button-BJiUJyhV.js → button-CvaPx9Bu.js} +2 -2
  55. package/extensions/dashboard-client/dist/assets/{button-BJiUJyhV.js.map → button-CvaPx9Bu.js.map} +1 -1
  56. package/extensions/dashboard-client/dist/assets/{card-Cg_LPWdl.js → card-Crs5SwRQ.js} +2 -2
  57. package/extensions/dashboard-client/dist/assets/{card-Cg_LPWdl.js.map → card-Crs5SwRQ.js.map} +1 -1
  58. package/extensions/dashboard-client/dist/assets/{client-extra-DxQFx7HY.js → client-extra-Bd27WKSo.js} +2 -2
  59. package/extensions/dashboard-client/dist/assets/{client-extra-DxQFx7HY.js.map → client-extra-Bd27WKSo.js.map} +1 -1
  60. package/extensions/dashboard-client/dist/assets/{generateCategoricalChart-sE5oI3Ee.js → generateCategoricalChart-qnHql9Es.js} +2 -2
  61. package/extensions/dashboard-client/dist/assets/{generateCategoricalChart-sE5oI3Ee.js.map → generateCategoricalChart-qnHql9Es.js.map} +1 -1
  62. package/extensions/dashboard-client/dist/assets/{index-CeBW9Vtt.js → index-B4twCFnn.js} +3 -3
  63. package/extensions/dashboard-client/dist/assets/{index-CeBW9Vtt.js.map → index-B4twCFnn.js.map} +1 -1
  64. package/extensions/dashboard-client/dist/assets/{switch-CmkMKtTG.js → switch-BXutQI5d.js} +2 -2
  65. package/extensions/dashboard-client/dist/assets/{switch-CmkMKtTG.js.map → switch-BXutQI5d.js.map} +1 -1
  66. package/extensions/dashboard-client/dist/assets/{toggle-CqpZacm5.js → toggle-uE-OSaba.js} +2 -2
  67. package/extensions/dashboard-client/dist/assets/{toggle-CqpZacm5.js.map → toggle-uE-OSaba.js.map} +1 -1
  68. package/extensions/dashboard-client/dist/assets/{useSSE-DCKHmvXr.js → useSSE-BRgPAqeS.js} +2 -2
  69. package/extensions/dashboard-client/dist/assets/{useSSE-DCKHmvXr.js.map → useSSE-BRgPAqeS.js.map} +1 -1
  70. package/extensions/dashboard-client/dist/index.html +1 -1
  71. package/extensions/dashboard-client/src/tabs/SetupTab/CortexRuntimeInstallCard.tsx +103 -0
  72. package/extensions/dashboard-client/src/tabs/SetupTab/CortexSetup.tsx +2 -0
  73. package/extensions/dashboard-server/api-contracts/setup.ts +24 -0
  74. package/extensions/dashboard-server/routes-rag-settings-vector-cortex.ts +6 -0
  75. package/extensions/dashboard-server/routes-setup-enc2a.ts +140 -0
  76. package/extensions/dashboard-server/routes-setup.ts +26 -0
  77. package/package.json +1 -1
  78. package/src/config/vector-cortex-enc2a.ts +37 -0
  79. package/src/config/vector-cortex.ts +2 -0
  80. package/src/config.ts +1 -0
  81. package/src/vector-cortex/encoder/native-install-artifacts.ts +60 -0
  82. package/extensions/dashboard-client/dist/assets/MetricsTab-C2rXqvoD.js +0 -2
  83. package/extensions/dashboard-client/dist/assets/SetupTab-CgC4Rz38.js +0 -3
  84. package/extensions/dashboard-client/dist/assets/SetupTab-CgC4Rz38.js.map +0 -1
  85. package/extensions/dashboard-client/dist/assets/TurnsTab-Cqyq6fVe.js +0 -2
@@ -0,0 +1,140 @@
1
+ /**
2
+ * dashboard-server/routes-setup-enc2a.ts — ENC-2a native onnxruntime install
3
+ * GUIDE (reader-only) + installed-version probe.
4
+ *
5
+ * Extracted out of routes-setup.ts (which hovers at the 300-line source soft
6
+ * cap, mirroring the ENC-1a/ENC-1b/ENC-2budget sibling extracts) so the
7
+ * ENC-2a additive GET fields — the platform-matched native install guide and
8
+ * the installed-version probe — live in a sibling impl file and routes-setup.ts
9
+ * stays a thin host.
10
+ *
11
+ * The guide's job is OPERATOR run-script assist: when the operator opted into
12
+ * the native backend (`MEGACOMPACT_ENCODER_NATIVE=1`) but the effective runtime
13
+ * is still `"wasm"` (onnxruntime-node not yet installed) AND the host platform
14
+ * is installable, the GET status response carries a `nativeOrtInstallGuide`
15
+ * object with the [install, restart, verify] copy-paste commands + the committed
16
+ * operator script path. The commands/URL/hash are built ONLY from the artifacts
17
+ * module constants (`src/vector-cortex/encoder/native-install-artifacts.ts`) —
18
+ * never an inline registry URL or literal hash (PREVENT-PI-004). The installed-
19
+ * version probe reads the local `~/.pi/mega-compact/native-ort/` package.json
20
+ * when present (reader-only filesystem read, zero network).
21
+ *
22
+ * The flag is off (or opt-in off / unsupported platform / non-wasm backend) ->
23
+ * guide `null` and installedVersion `null` -> the host omits both fields,
24
+ * byte-identical to the ENC-1b-era shape.
25
+ *
26
+ * Guardrails: PREVENT-PI-004 (local filesystem reads + in-memory backend
27
+ * selection only, zero network), PREVENT-001 (null-safe JSON), PREVENT-011
28
+ * (no `any`).
29
+ */
30
+
31
+ import { readFileSync, existsSync } from "node:fs";
32
+ import { join } from "node:path";
33
+ import { ENC_2A_ENABLED } from "../../src/config/vector-cortex.js";
34
+ import { readEnc1bEnv } from "./routes-setup-enc1b.js";
35
+ import { selectRuntimeBackend } from "../../src/vector-cortex/encoder/runtime-select.js";
36
+ import { detectPlatform } from "../../src/vector-cortex/encoder/asset.js";
37
+ import {
38
+ NATIVE_ORT_VERSION,
39
+ NATIVE_ORT_PACKAGE,
40
+ NATIVE_ORT_INSTALLABLE_PLATFORMS,
41
+ } from "../../src/vector-cortex/encoder/native-install-artifacts.js";
42
+ import type { SetupConfigureRequest } from "./api-contracts/setup.js";
43
+
44
+ /** The committed operator script that performs the install (repo-relative). */
45
+ const ENC_2A_SCRIPT_PATH = "scripts/encoder/install-native-ort.mjs";
46
+
47
+ /** Where the operator script installs the native binding (absolute install
48
+ * prefix used verbatim in the guide commands + the version probe). */
49
+ function nativeOrtDir(): string {
50
+ return join(process.env.HOME ?? "", ".pi", "mega-compact", "native-ort");
51
+ }
52
+
53
+ /**
54
+ * True when the payload carries the ENC-2a guide-request key `false`/`true`
55
+ * (flag-gated, additive). `false` -> 400 (operator-driven no-op); `true` -> 200
56
+ * + the guide echoed (still no server execution — the execute path is ENC-2c).
57
+ * Flag-off -> null so the key falls through unrecognized (byte-identical
58
+ * ENC-1b-era predecessor).
59
+ */
60
+ export function enc2aGuideRequest(
61
+ body: SetupConfigureRequest,
62
+ ): { status: 400 } | { status: 200 } | null {
63
+ if (!ENC_2A_ENABLED()) return null;
64
+ if (body.nativeOrtInstallGuide === true) return { status: 200 };
65
+ if (body.nativeOrtInstallGuide === false) return { status: 400 };
66
+ return null;
67
+ }
68
+
69
+ /**
70
+ * Read the ENC-2a native install GUIDE + installed-version, additive GET fields.
71
+ *
72
+ * The guide renders only when EVERY gate passes: flag on, operator opted into
73
+ * native, effective backend is still `"wasm"` (onnxruntime-node absent), and the
74
+ * host platform is installable (darwin-x64 is excluded — no native binding
75
+ * upstream, the ENC-0e demotion sentinel). The effective backend + demotion
76
+ * reason go through the EXISTING `selectRuntimeBackend` (reader-only — never a
77
+ * reimplemented literal). `installedVersion` probes
78
+ * `~/.pi/mega-compact/native-ort/node_modules/onnxruntime-node/package.json`
79
+ * when present; null otherwise. Returns `{ guide: null, installedVersion: null }`
80
+ * when the flag is off (byte-identical predecessor).
81
+ */
82
+ export function readEnc2aGuide(stateDir: string): {
83
+ guide: { platform: string; commands: readonly string[]; scriptPath: string } | null;
84
+ installedVersion: string | null;
85
+ } {
86
+ if (!ENC_2A_ENABLED()) return { guide: null, installedVersion: null };
87
+ const env = readEnc1bEnv(stateDir);
88
+ const platform = detectPlatform();
89
+ const chosen = selectRuntimeBackend({
90
+ platform: platform ?? "unsupported",
91
+ benchRecord: null,
92
+ nativeOptIn: env.nativeOptIn,
93
+ });
94
+ const backend = chosen.backend === "native" ? "native" : "wasm";
95
+
96
+ let guide: { platform: string; commands: readonly string[]; scriptPath: string } | null = null;
97
+ if (
98
+ env.nativeOptIn &&
99
+ backend === "wasm" &&
100
+ platform !== null &&
101
+ (NATIVE_ORT_INSTALLABLE_PLATFORMS as readonly string[]).includes(platform)
102
+ ) {
103
+ guide = {
104
+ platform,
105
+ commands: [
106
+ `npm install --prefix ${nativeOrtDir()} ${NATIVE_ORT_PACKAGE}@${NATIVE_ORT_VERSION}`,
107
+ "pi update --extensions && pi session-start",
108
+ "expect encoderBackend: native on next status poll",
109
+ ],
110
+ scriptPath: ENC_2A_SCRIPT_PATH,
111
+ };
112
+ }
113
+
114
+ return { guide, installedVersion: probeInstalledVersion() };
115
+ }
116
+
117
+ /** Probe the local native-ort package.json for the installed onnxruntime-node
118
+ * version. Null when the package is absent/unreadable (reader-only, local). */
119
+ function probeInstalledVersion(): string | null {
120
+ try {
121
+ const pkgPath = join(
122
+ nativeOrtDir(),
123
+ "node_modules",
124
+ NATIVE_ORT_PACKAGE,
125
+ "package.json",
126
+ );
127
+ if (!existsSync(pkgPath)) return null;
128
+ const raw = JSON.parse(readFileSync(pkgPath, "utf8")) as unknown;
129
+ if (
130
+ typeof raw === "object" &&
131
+ raw !== null &&
132
+ typeof (raw as { version?: unknown }).version === "string"
133
+ ) {
134
+ return (raw as { version: string }).version;
135
+ }
136
+ return null;
137
+ } catch {
138
+ return null;
139
+ }
140
+ }
@@ -21,6 +21,7 @@ import {
21
21
  tryEnc2BudgetInto,
22
22
  enc2BudgetValidateCombined,
23
23
  } from "./routes-setup-enc2budget.js";
24
+ import { readEnc2aGuide, enc2aGuideRequest } from "./routes-setup-enc2a.js";
24
25
  import { writeEmbedderEnv } from "./routes-setup-env-upsert.js";
25
26
  import {
26
27
  detectOllama,
@@ -85,6 +86,11 @@ export function handleSetupStatus(
85
86
  }
86
87
  const configured = detectConfiguredEmbedder(ctx.stateDir);
87
88
  const active = detectCurrentEmbedder();
89
+ // ENC-2a (flag-gated, additive): the native install-guide + installed-version
90
+ // fields. Optional fields are added only when present/installable; when the
91
+ // flag is off readEnc2aGuide returns nulls so the body stays byte-identical
92
+ // to the ENC-1b-era shape.
93
+ const enc2a = readEnc2aGuide(ctx.stateDir);
88
94
  // ENC-1a (flag-gated, additive): echo the persisted endpoint URL and an
89
95
  // embeddingApiKeySet boolean ONLY — the raw API key is never returned. When
90
96
  // the flag is off (or neither is set) both fields are simply omitted.
@@ -100,6 +106,8 @@ export function handleSetupStatus(
100
106
  ),
101
107
  ...enc1aStatusFields(ctx.stateDir), ...enc1bStatusFields(ctx.stateDir),
102
108
  ...enc2BudgetStatusFields(ctx.stateDir),
109
+ ...(enc2a.guide !== null ? { nativeOrtInstallGuide: enc2a.guide } : {}),
110
+ ...(enc2a.installedVersion !== null ? { nativeOrtInstalledVersion: enc2a.installedVersion } : {}),
103
111
  };
104
112
  // guardrails-allow PREVENT-PI-004: loopback dashboard response (local)
105
113
  res.writeHead(200, { "Content-Type": "application/json" });
@@ -218,10 +226,28 @@ export function handleSetupConfigure(
218
226
  return;
219
227
  }
220
228
  const body = parsed.value as unknown as SetupConfigureRequest;
229
+ // ENC-2a guide-request key (flag-gated, additive): `false` → 400 (an
230
+ // operator-driven no-op — this sprint conveys the GUIDE only, no server
231
+ // execution), `true` → 200 + the guide echoed (still no execution; the
232
+ // execute path is ENC-2c). Flag-off: enc2aGuideRequest returns null so the
233
+ // key falls through unrecognized (byte-identical ENC-1b-era predecessor).
234
+ const guideReq = enc2aGuideRequest(body);
235
+ // guardrails-allow PREVENT-PI-004: loopback dashboard response (local)
236
+ if (guideReq !== null && guideReq.status === 400) {
237
+ res.writeHead(400, { "Content-Type": "application/json" });
238
+ res.end(JSON.stringify({ error: "guide_rejected_false_nothing_to_do" }));
239
+ return;
240
+ }
221
241
  // ENC-1a (flag-gated, additive): a pure external-embedder configure
222
242
  // (new keys, no embedder selection) is handled by the sibling writer.
223
243
  // Flag-off = the keys are simply not recognized, falling through to the
224
244
  // pre-ENC-1a embedder path below (byte-identical predecessor).
245
+ if (guideReq !== null && guideReq.status === 200) {
246
+ // guardrails-allow PREVENT-PI-004: loopback dashboard response (local)
247
+ res.writeHead(200, { "Content-Type": "application/json" });
248
+ res.end(JSON.stringify({ nativeOrtInstallGuide: readEnc2aGuide(ctx.stateDir).guide }));
249
+ return;
250
+ }
225
251
  if (tryEnc1aConfigure(body, res, ctx)) return;
226
252
  if (tryEnc1bConfigure(body, res, ctx)) return; // pure ENC-1b configure (dim/headers/allow-remote/native)
227
253
  // ENC-1b combined-payload validation: when a payload carries a valid
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-mega-compact",
3
- "version": "0.20.63",
3
+ "version": "0.20.64",
4
4
  "description": "Layered, local, vector-backed context compressor for pi — supersede/collapse/cluster compaction with deduped inline recall.",
5
5
  "type": "module",
6
6
  "license": "BSD-3-Clause",
@@ -0,0 +1,37 @@
1
+ /**
2
+ * config/vector-cortex-enc2a.ts — ENC-2a native onnxruntime install-guide flag
3
+ * (operator run-script assist).
4
+ *
5
+ * Sibling of vector-cortex-enc1a.ts / vector-cortex-enc1b.ts /
6
+ * vector-cortex-enc2budget.ts so vector-cortex.ts stays under the 300-line soft
7
+ * limit (soft-as-hard gate). vector-cortex.ts re-exports the flag below and
8
+ * root src/config.ts re-exports it, so no consumer import path changes.
9
+ *
10
+ * ENC-2a, when the operator opted into the native backend
11
+ * (`MEGACOMPACT_ENCODER_NATIVE=1`) but `encoderBackend` is still `"wasm"`
12
+ * (onnxruntime-node absent / not yet installed), surfaces an "Encoder Runtime
13
+ * Install" card on the Cortex sub-tab with copy-paste operator commands: the
14
+ * install + restart + verify steps built ONLY from the artifacts-module
15
+ * constants (`src/vector-cortex/encoder/native-install-artifacts.ts`) — never
16
+ * an inline registry URL or hash in the route (PREVENT-PI-004). The guide
17
+ * renders only on an installable host platform; the ENC-0e darwin-x64 demotion
18
+ * sentinel keeps it absent on an Intel Mac (no native binding upstream).
19
+ *
20
+ * `MEGACOMPACT_ENC_2A=0` disables: no guide fields, no install card, no absent
21
+ * read — byte-identical to the ENC-1b predecessor. The flag MUST also be a
22
+ * dashboard SETTINGS toggle (visible in config UI, never in EXCLUDED_SETTINGS
23
+ * — see `feedback_dashboard-flags-toggleable` memory).
24
+ *
25
+ * Pi-agnostic, dependency-free (PREVENT-PI-004 / PREVENT-011).
26
+ */
27
+
28
+ import { sprintFlag } from "./vector-cortex-flag.js";
29
+
30
+ /**
31
+ * ENC-2a — operator run-script assist (dashboard install guide for the
32
+ * onnxruntime-node native binding). Default ON. `MEGACOMPACT_ENC_2A=0` disables
33
+ * and is byte-identical to the ENC-1b predecessor: no guide/absent fields, no
34
+ * install card. This flag MUST also be a dashboard SETTINGS toggle (visible in
35
+ * config UI, never in EXCLUDED_SETTINGS).
36
+ */
37
+ export const ENC_2A_ENABLED = (): boolean => sprintFlag("MEGACOMPACT_ENC_2A");
@@ -92,6 +92,8 @@ export {
92
92
  ENC_2BUDGET_MAX_MIB,
93
93
  ENC_2BUDGET_DEFAULT_MIB,
94
94
  } from "./vector-cortex-enc2budget.js";
95
+ // ENC-2a native onnxruntime install-guide flag extracted to vector-cortex-enc2a.ts.
96
+ export { ENC_2A_ENABLED } from "./vector-cortex-enc2a.js";
95
97
  // Breaker constants (TRIAD_RESILIENCE.md §breaker) extracted to vector-cortex-breakers.ts.
96
98
  export {
97
99
  BREAKER_WINDOW_MS,
package/src/config.ts CHANGED
@@ -202,6 +202,7 @@ export {
202
202
  ENC_2BUDGET_NATIVE_ORT_BUDGET_ENV,
203
203
  ENC_2BUDGET_MAX_MIB,
204
204
  ENC_2BUDGET_DEFAULT_MIB,
205
+ ENC_2A_ENABLED,
205
206
  COSINE_FP_BENCH_ENABLED,
206
207
  COSINE_FP_REAL_ENABLED,
207
208
  REPO_CORPUS_ENABLED,
@@ -0,0 +1,60 @@
1
+ /**
2
+ * vector-cortex/encoder/native-install-artifacts.ts — ENC-2a native
3
+ * onnxruntime install-guide constants (PURE data module).
4
+ *
5
+ * Single source of truth for the operator's native-backend install guide
6
+ * (`onnxruntime-node`, the sole onnxruntime Node.js binding this extension's
7
+ * native path uses). The guide rendered by
8
+ * `extensions/dashboard-server/routes-setup-enc2a.ts` and the operator script
9
+ * `scripts/encoder/install-native-ort.mjs` build their commands/URLs ONLY from
10
+ * these scalars — never an inline registry URL or literal hash in the route or
11
+ * extension runtime (PREVENT-PI-004: the registry tarball URL is derived by
12
+ * callers from `NATIVE_ORT_PACKAGE` + "@" + `NATIVE_ORT_VERSION`, so no network
13
+ * path and no literal registry URL or scheme appears in src/).
14
+ *
15
+ * Package facts (verified, not invented):
16
+ * - onnxruntime-node publishes ONE monolithic ~100MB npm tarball — not
17
+ * per-platform `optionalDependencies` — so a single
18
+ * `NATIVE_ORT_TARBALL_SHA256` pins the whole artifact for every host.
19
+ * - darwin-x64 has NO native binding (arm64-only upstream since 1.17), so the
20
+ * guide stays absent on an Intel Mac (the ENC-0e demotion sentinel).
21
+ * - `NATIVE_ORT_TARBALL_SHA256` was computed from TWO independent downloads of
22
+ * the 1.27.0 tarball (real, cross-checked, not guessed).
23
+ *
24
+ * Pi-agnostic, dependency-free, pure data — zero I/O, zero network
25
+ * (PREVENT-PI-004 / PREVENT-011).
26
+ */
27
+
28
+ /** onnxruntime-node version the guide installs (real published version). */
29
+ export const NATIVE_ORT_VERSION: string = "1.27.0";
30
+
31
+ /** onnxruntime-node npm package name (the native onnxruntime binding). */
32
+ export const NATIVE_ORT_PACKAGE: string = "onnxruntime-node";
33
+
34
+ /** SHA-256 of the onnxruntime-node@1.27.0 npm tarball (one sha for all hosts).
35
+ * Computed from TWO independent tarball downloads; lowercase hex, 64 chars. */
36
+ export const NATIVE_ORT_TARBALL_SHA256: string =
37
+ "c3779c01c59832f8c03e2c392ac3af10bf08579f1822e8b1c63cc451edb302a2";
38
+
39
+ /**
40
+ * The host platform the guide can render for. darwin-x64 is deliberately NOT
41
+ * installable (no native onnxruntime binding upstream — arm64-only since 1.17);
42
+ * the guide stays absent on an Intel Mac (ENC-0e demotion sentinel).
43
+ */
44
+ export type EncoderPlatform =
45
+ | "linux-x64"
46
+ | "linux-arm64"
47
+ | "darwin-arm64"
48
+ | "win32-x64"
49
+ | "darwin-x64";
50
+
51
+ /**
52
+ * Platforms for which an operator install-guide can be rendered (native
53
+ * binding exists upstream). darwin-x64 is excluded — it has NO native binding.
54
+ */
55
+ export const NATIVE_ORT_INSTALLABLE_PLATFORMS: readonly EncoderPlatform[] = [
56
+ "linux-x64",
57
+ "linux-arm64",
58
+ "darwin-arm64",
59
+ "win32-x64",
60
+ ];
@@ -1,2 +0,0 @@
1
- import{j as r}from"./index-CeBW9Vtt.js";import{M as t}from"./MetricsCards-YlmnUe01.js";import"./card-Cg_LPWdl.js";import"./generateCategoricalChart-sE5oI3Ee.js";import"./BarChart-IWwm38i0.js";import"./AreaChart-B1OkLRGT.js";function e(){return r.jsx(t,{})}export{e as default};
2
- //# sourceMappingURL=MetricsTab-C2rXqvoD.js.map
@@ -1,3 +0,0 @@
1
- import{r as s,j as e,o as L,p as Y,q as ae,s as oe,C as le,t as ie,e as Z,v as de,w as ee,x as V,y as ce,u as X,z as te,A as se}from"./index-CeBW9Vtt.js";import{C as me}from"./ConfigTab-C1t0EM2H.js";import{S as ue}from"./switch-CmkMKtTG.js";import{b as he,p as pe,d as ge}from"./client-extra-DxQFx7HY.js";import{V as fe}from"./VcStatusBadge-CBtRo20h.js";import{T as xe}from"./toggle-CqpZacm5.js";function be(t){try{return new Date(t*1e3).toLocaleString()}catch{return"—"}}function re({achievements:t}){const n=s.useRef(0),[r,o]=s.useState(null),a=t.reduce((i,d)=>Math.max(i,d.unlocked_at??0),0),l=n.current;s.useEffect(()=>{a>n.current&&(n.current=a)},[a]),s.useEffect(()=>{if(l>0&&a>l){const i=t.filter(d=>d.unlocked_at!=null&&(d.unlocked_at??0)>l);if(i.length>0){const d=i.map(m=>`${m.icon??""} ${m.title}`.trim()).join(", ")+" unlocked!";o(d);const g=setTimeout(()=>o(null),4e3);return()=>clearTimeout(g)}}},[t,a,l]);const c=t.filter(i=>!(i.hidden===1&&i.unlocked_at==null));return e.jsxs("div",{className:"ach-section",children:[r!=null&&e.jsx("div",{className:"ach-toast show",children:r}),e.jsxs("div",{className:"ach-tiles",children:[c.length===0&&e.jsx("span",{className:"repo-none",children:"no achievements yet"}),c.map(i=>{if(i.unlocked_at!=null){const d=l>0&&(i.unlocked_at??0)>l;return e.jsxs("div",{className:`ach-tile unlocked${d?" just-unlocked":""}`,children:[i.icon??""," ",i.title,e.jsxs("span",{className:"ach-detail",children:["unlocked ",be(i.unlocked_at)]})]},i.id)}return e.jsxs("div",{className:"ach-tile locked",children:["??? ",i.title]},i.id)})]})]})}function P(t){return(Math.round(t*10)/10).toString()+"%"}function F(t){return t!=null?new Date(t).toLocaleString():"—"}function H(t){return t&&typeof t=="object"?t:{}}function ye(t){return t.split("/").pop()||t}function _({title:t,rows:n,badge:r,renderValue:o}){return e.jsxs("div",{className:"lb-card",children:[e.jsxs("h3",{children:[t,r]}),n.length===0?e.jsx("div",{className:"lb-empty",children:"—"}):e.jsx("table",{children:e.jsx("tbody",{children:n.map((a,l)=>e.jsxs("tr",{children:[e.jsx("td",{title:a.repo_root,children:ye(a.repo_root)}),e.jsx("td",{className:"num",children:o(a)})]},`${a.repo_root}-${l}`))})})]})}function je(){const[t,n]=s.useState({}),[r,o]=s.useState(0),[a,l]=s.useState([]),[c,i]=s.useState(!1),[d,g]=s.useState(!0),[m,x]=s.useState(null),f=s.useRef(0),b=s.useCallback(async()=>{try{const[y,p,R,z,W,U]=await Promise.all([L({metric:"cache",limit:25}),L({metric:"dedupe",limit:25}),L({metric:"turns",limit:25}),L({metric:"mega_cache",limit:25}),L({metric:"repos",limit:1}),Y()]),D=z.find(O=>O.ts>f.current&&O.value>100);f.current>0&&D&&(x(`oopsie! cache went to ${Math.round(D.value)}% — MEGA CACHE 🥧`),setTimeout(()=>x(null),4e3)),z.length>0&&(f.current=Math.max(...z.map(O=>O.ts))),n({cache:y,dedupe:p,turns:R,mega_cache:z}),o(W[0]?.value??0),l(U)}catch{}finally{g(!1)}},[]);s.useEffect(()=>{let y=!0;const p=async()=>{y&&await b()};p();const R=setInterval(()=>void p(),15e3);return()=>{y=!1,clearInterval(R)}},[b]),s.useEffect(()=>{let y=!0;const p=async()=>{try{const z=await ae();y&&(i(!!z.game_mode_on),z.theme&&(document.documentElement.dataset.theme=z.theme))}catch{}};p();const R=setInterval(()=>void p(),15e3);return()=>{y=!1,clearInterval(R)}},[]);const v=t.mega_cache??[];let S=null,w=null;for(const y of v){(S==null||y.value>S)&&(S=y.value);const p=H(y.meta),R=p.firstSeenTs??p.firstSeen??y.ts;(w==null||R<w)&&(w=R)}const E=S!=null&&S>100,h=t.turns??[],T=h.reduce((y,p)=>Math.max(y,p.value),0),N=Math.floor(Math.log2(T+1))+1,M=(t.cache?.length??0)>0||(t.dedupe?.length??0)>0||h.length>0||v.length>0||r>0;return e.jsxs("div",{className:`game-tab${c?" game-mode-on":""}`,children:[m!=null&&e.jsx("div",{className:"mega-cache-toast show",children:m}),E&&e.jsxs("div",{className:"mega-cache-banner",children:["🥧"," MEGA CACHE! peak ",P(S)," — first reached ",F(w)]}),E&&e.jsxs("div",{className:"achievement-tile unlocked",children:["🏆"," Opie's Wild Ride",e.jsxs("span",{className:"ach-detail",children:["best ",P(S)," · first ",F(w)]})]}),e.jsx("h2",{children:"High Scores"}),!M&&!d&&e.jsx("div",{className:"game-empty",children:"No scores yet — run a session with game mode on."}),M&&e.jsxs("div",{className:"game-leaderboards",children:[e.jsx(_,{title:"Cache %",rows:t.cache??[],renderValue:y=>P(y.value)}),e.jsx(_,{title:"Dedupe (collapsed)",rows:t.dedupe??[],renderValue:y=>y.value.toLocaleString()}),e.jsx(_,{title:"Turns",rows:h,badge:h.length>0?e.jsxs("span",{className:"lvl-badge",children:["LVL ",N]}):void 0,renderValue:y=>y.value.toLocaleString()}),e.jsx(_,{title:"MEGA CACHE trophies",rows:v,renderValue:y=>e.jsxs(e.Fragment,{children:[P(y.value),e.jsx("span",{className:"lb-meta",children:F(H(y.meta).firstSeenTs??H(y.meta).firstSeen??y.ts)})]})})]}),r>0&&e.jsx("div",{className:"repos-badge-line",children:e.jsxs("span",{className:"repos-badge",children:[r," repos"]})}),e.jsx("h3",{children:"Achievements"}),e.jsx(re,{achievements:a})]})}function ve(){const[t,n]=s.useState([]),[r,o]=s.useState(!0),[a,l]=s.useState(null),c=s.useCallback(async()=>{try{const i=await Y();n(i),l(null)}catch(i){l(i instanceof Error?i:new Error(String(i)))}finally{o(!1)}},[]);return s.useEffect(()=>{let i=!0;const d=async()=>{i&&await c()};d();const g=setInterval(()=>void d(),15e3);return()=>{i=!1,clearInterval(g)}},[c]),r&&t.length===0?e.jsx("div",{className:"tab-stub",children:"Loading achievements…"}):a&&t.length===0?e.jsxs("div",{className:"tab-stub",children:["Error: ",a.message]}):e.jsxs("div",{className:"achievements-tab",children:[e.jsx("h2",{children:"Achievements"}),e.jsx(re,{achievements:t})]})}const A={section:{background:"#1a1a2e",borderRadius:"8px",padding:"1rem",marginBottom:"1rem",border:"1px solid #2a2a4e"},sectionTitle:{fontSize:"1.1rem",fontWeight:700,marginTop:0,marginBottom:"0.75rem",color:"#e0e0e0",borderBottom:"1px solid #333",paddingBottom:"0.5rem"},label:{fontWeight:600,color:"#a0a0c0",marginRight:"0.5rem"},value:{color:"#e0e0e0"},row:{marginBottom:"0.4rem",fontSize:"0.9rem"}};function Se(){const[t,n]=s.useState(null),[r,o]=s.useState(null),a=s.useCallback(()=>{oe().then(n).catch(g=>o(g instanceof Error?g.message:String(g)))},[]);s.useEffect(()=>{a()},[a]),s.useEffect(()=>{const g=setInterval(a,3e4);return()=>clearInterval(g)},[a]);const l=t?.status==="ok",c=t?.status==="ok"?"Working":t?.status==="unreachable"?"Unreachable":"Error",i=l?"#4caf50":"#f44336",d=l?"✓":"✗";return e.jsxs("div",{style:A.section,children:[e.jsx("h3",{style:A.sectionTitle,children:"Embedder Health"}),r&&e.jsxs("p",{style:{color:"#f44336",fontSize:"0.85rem"},children:["Error: ",r]}),!t&&!r&&e.jsx("p",{style:{color:"#888",fontSize:"0.85rem"},children:"Probing embedder..."}),t&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{style:A.row,children:[e.jsxs("span",{style:{...A.label,color:`${i}`},children:[d," ",c,":"]}),e.jsxs("span",{style:A.value,children:[t.dim," dims"]}),t.latencyMs!==void 0&&e.jsxs("span",{style:{color:"#a0a0c0",marginLeft:"0.5rem"},children:["(",t.latencyMs.toFixed(1)," ms)"]})]}),e.jsxs("div",{style:A.row,children:[e.jsx("span",{style:A.label,children:"Endpoint:"}),e.jsx("span",{style:A.value,children:t.url??e.jsx("span",{style:{color:"#888"},children:"built-in (no URL)"})})]}),t.error&&e.jsx("p",{style:{color:"#f44336",fontSize:"0.85rem"},children:t.error})]})]})}function we({title:t,children:n}){const[r,o]=s.useState(!0),a=`settings-${t.toLowerCase().replace(/[^a-z0-9]+/g,"-")}`;return e.jsxs("section",{className:"overflow-hidden rounded-xl border border-border bg-bg-elevated/40",children:[e.jsxs("button",{type:"button",onClick:()=>o(l=>!l),className:"flex w-full items-center justify-between rounded-t-xl bg-bg-elevated/60 px-4 py-3 text-left text-sm font-semibold text-foreground transition-colors hover:bg-bg-elevated","aria-expanded":r,"aria-controls":a,children:[e.jsx("span",{children:t}),e.jsx(le,{className:ie("h-4 w-4 text-muted-foreground transition-transform",r&&"rotate-180"),"aria-hidden":"true"})]}),r&&e.jsx("div",{id:a,className:"divide-y divide-border px-4 py-1",children:n})]})}const ke="rounded-md border border-border bg-bg-elevated/50 px-2 py-1 text-sm outline-none transition-colors focus:border-primary disabled:cursor-not-allowed disabled:opacity-50";function Ce(){return e.jsx("span",{className:"ml-2 inline-flex items-center rounded-md border border-warning/40 bg-warning/15 px-1.5 py-0.5 text-[10px] font-semibold uppercase tracking-wide text-warning",title:"Requires an LLM embedder (Ollama/HTTP) to be effective",children:"LLM"})}function Ee({setting:t,id:n,llmActive:r,saving:o,onUpdate:a}){const[l,c]=s.useState(null),i=t.requiresLlm&&!r,d=s.useRef(null);s.useEffect(()=>()=>{d.current&&clearTimeout(d.current)},[]);const g=s.useCallback(f=>{a(t.key,f).then(b=>c(b)).catch(b=>c(b instanceof Error?b.message:String(b)))},[a,t.key]),m=s.useCallback(f=>{d.current&&clearTimeout(d.current),d.current=setTimeout(()=>g(f),500)},[g]),x=o||i;return e.jsxs("div",{className:"py-2.5",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center text-sm font-semibold text-foreground",children:[e.jsx("label",{htmlFor:`${n}-input`,className:"cursor-pointer",children:t.label}),t.requiresLlm&&!r&&e.jsx(Ce,{})]}),e.jsx("div",{className:"mt-0.5 text-xs text-muted-foreground",children:t.description})]}),e.jsx("div",{className:"flex shrink-0 items-center gap-2",children:t.type==="boolean"?e.jsx(ue,{id:`${n}-input`,checked:!!t.value,disabled:x||i,onCheckedChange:f=>g(String(f)),"aria-label":t.label}):e.jsxs(e.Fragment,{children:[e.jsx("input",{id:`${n}-input`,type:t.type==="number"?"number":"text",defaultValue:String(t.value??""),min:t.min,max:t.max,disabled:x,onChange:f=>m(f.target.value),className:`${ke} ${t.type==="number"?"w-24":"w-56"}`}),t.unit&&e.jsx("span",{className:"text-xs text-muted-foreground",children:t.unit})]})})]}),l&&e.jsxs("p",{className:"mt-1 text-xs text-danger",children:["Error: ",l]})]})}function Ne(){const[t,n]=s.useState(null),[r,o]=s.useState(null),[a,l]=s.useState(!1),[c,i]=s.useState(null),d=s.useCallback(()=>{Z().then(n).catch(m=>o(m instanceof Error?m.message:String(m)))},[]);s.useEffect(()=>{d()},[d]);const g=s.useCallback(async(m,x)=>{l(!0);try{const f=await de({key:m,value:x});return i(f.restartRequired?"Saved — restart pi to apply changes.":"Saved."),d(),null}catch(f){return f instanceof Error?f.message:String(f)}finally{l(!1)}},[d]);return e.jsxs("div",{className:"flex flex-col gap-3",children:[r&&e.jsxs("p",{className:"text-sm text-danger",children:["Error: ",r]}),!t&&!r&&e.jsx("p",{className:"text-sm text-muted-foreground",children:"Loading settings..."}),t?.categories.map(m=>e.jsx(we,{title:m.name,children:m.settings.map(x=>e.jsx(Ee,{setting:x,id:`${m.name.replace(/[^a-z0-9]+/gi,"-")}-${x.key}`,llmActive:t.llmActive,saving:a,onUpdate:g},x.key))},m.name)),c&&e.jsx("div",{className:"mt-1 rounded-md border border-warning/40 bg-warning/10 p-2 text-xs text-warning",role:"status",children:c})]})}const u={container:{padding:"1rem",maxWidth:"720px",margin:"0 auto",fontFamily:"system-ui, sans-serif",color:"#e0e0e0"},section:{background:"#1a1a2e",borderRadius:"8px",padding:"1rem",marginBottom:"1rem",border:"1px solid #2a2a4e"},sectionTitle:{fontSize:"1.1rem",fontWeight:700,marginTop:0,marginBottom:"0.75rem",color:"#e0e0e0",borderBottom:"1px solid #333",paddingBottom:"0.5rem"},label:{fontWeight:600,color:"#a0a0c0",marginRight:"0.5rem"},value:{color:"#e0e0e0"},row:{marginBottom:"0.4rem",fontSize:"0.9rem"},warning:{background:"#3a2a00",border:"1px solid #665500",borderRadius:"8px",padding:"0.75rem",marginTop:"0.5rem",color:"#ffcc00",fontSize:"0.85rem"},badge:{display:"inline-block",padding:"0.15rem 0.5rem",borderRadius:"4px",fontSize:"0.8rem",fontWeight:600,marginLeft:"0.5rem"},detectRow:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"0.5rem 0",borderBottom:"1px solid #2a2a4e"},button:{background:"#3a5a9f",color:"#fff",border:"none",borderRadius:"6px",padding:"0.5rem 1rem",cursor:"pointer",fontSize:"0.9rem",fontWeight:600}},Te="Saved; takes effect on next session start";function Re({customUrl:t,setCustomUrl:n,applyEmbedder:r,configuring:o,inputEnabled:a,apiKeySet:l,embeddingDim:c,embeddingHeadersSet:i,allowRemoteEmbedder:d,configureResult:g,configureError:m}){const[x,f]=s.useState(""),[b,v]=s.useState(""),[S,w]=s.useState(!1),[E,h]=s.useState(""),[T,N]=s.useState(!1),[M,y]=s.useState(!1);return a&&!S&&typeof c=="string"&&(v(c),w(!0)),a&&!M&&typeof d=="boolean"&&(N(d),y(!0)),e.jsxs("div",{style:u.section,children:[e.jsx("h3",{style:u.sectionTitle,children:"Custom Endpoint (remote / third-party)"}),e.jsxs("p",{style:{fontSize:"0.85rem",color:"#a0a0c0",marginTop:0},children:["Point at any OpenAI-compatible embeddings API or hosted endpoint. This opts in to a non-loopback connection (sets"," ",e.jsx("code",{children:"MEGACOMPACT_ALLOW_REMOTE_EMBEDDER=1"}),") — your prompts' embedding requests will be sent to the URL you enter. Default is loopback-only."]}),e.jsxs("div",{style:{display:"flex",gap:"0.5rem",flexWrap:"wrap",alignItems:"center"},children:[e.jsx("input",{type:"url",placeholder:"https://api.example.com/v1/embeddings",value:t,onChange:p=>n(p.target.value),style:{flex:"1 1 300px",background:"#12122a",color:"#e0e0e0",border:"1px solid #2a2a4e",borderRadius:"6px",padding:"0.4rem 0.6rem",fontSize:"0.85rem",fontFamily:"monospace"}}),a&&e.jsx("input",{type:"password",autoComplete:"new-password","aria-label":"API key (optional Bearer)",placeholder:"API key (optional Bearer)",value:x,onChange:p=>f(p.target.value),style:{flex:"1 1 300px",background:"#12122a",color:"#e0e0e0",border:"1px solid #2a2a4e",borderRadius:"6px",padding:"0.4rem 0.6rem",fontSize:"0.85rem",fontFamily:"monospace"}}),a&&l&&e.jsx("span",{style:{fontSize:"0.75rem",color:"#81c784",border:"1px solid #2a4e2a",borderRadius:"4px",padding:"0.15rem 0.45rem"},children:"API key saved"}),a&&i&&e.jsx("span",{style:{fontSize:"0.75rem",color:"#81c784",border:"1px solid #2a4e2a",borderRadius:"4px",padding:"0.15rem 0.45rem"},children:"Headers saved"}),e.jsx("button",{style:{...u.button,opacity:t?1:.4},onClick:()=>r("custom",t,x,b,E,T),disabled:!t||o!==null,children:o==="custom"?"Writing...":"Use Custom URL"})]}),a&&e.jsxs("div",{style:{marginTop:"0.75rem"},children:[e.jsxs("div",{style:{marginBottom:"0.5rem"},children:[e.jsx("label",{style:{...u.label,display:"block",marginBottom:"0.25rem"},children:"Embedding dim (optional)"}),e.jsx("input",{type:"number",min:1,placeholder:"e.g. 384",value:b,onChange:p=>v(p.target.value),style:{width:"200px",background:"#12122a",color:"#e0e0e0",border:"1px solid #2a2a4e",borderRadius:"6px",padding:"0.4rem 0.6rem",fontSize:"0.85rem",fontFamily:"monospace"}})]}),e.jsxs("div",{style:{marginBottom:"0.5rem"},children:[e.jsx("label",{style:{...u.label,display:"block",marginBottom:"0.25rem"},children:"Embedding headers (JSON, write-only — never re-displayed)"}),e.jsx("textarea",{placeholder:'{"Authorization": "Bearer ..."}',value:E,onChange:p=>h(p.target.value),"aria-label":"Embedding headers JSON (write-only — never re-displayed)",rows:2,style:{width:"100%",background:"#12122a",color:"#e0e0e0",border:"1px solid #2a2a4e",borderRadius:"6px",padding:"0.4rem 0.6rem",fontSize:"0.85rem",fontFamily:"monospace",resize:"vertical"}})]}),e.jsxs("label",{style:{display:"flex",alignItems:"center",gap:"0.5rem",fontSize:"0.85rem"},children:[e.jsx("input",{type:"checkbox",checked:T,onChange:p=>N(p.target.checked),"aria-label":"Allow remote embedder (skips loopback-only check)"}),"Allow remote embedder (skips loopback-only check)"]})]}),m!==null&&e.jsxs("p",{style:{color:"#f44336",fontSize:"0.85rem",marginTop:"0.5rem"},children:["Configure error: ",m]}),g!==null&&g.embedder==="custom"&&e.jsx("div",{style:u.warning,children:Te}),e.jsxs("div",{style:u.warning,children:[e.jsx("strong",{children:"Heads up:"})," a remote endpoint receives the text you embed (it does NOT receive your full conversation — only the strings passed to",e.jsx("code",{children:" embed()"})," for recall/dedup). Verify the endpoint's privacy policy before use."]})]})}function K(t){switch(t){case"trigram":return"TrigramEmbedder (heuristic, default)";case"http":return"HTTP Embedder (BYO localhost)";case"minilm":return"MiniLM (experimental)";default:return"Unknown"}}function Be(t){return t?.currentEmbedder!=="trigram"?null:e.jsxs("div",{style:u.warning,children:[e.jsx("strong",{children:"Note:"})," TrigramEmbedder is a heuristic-strength default embedder. It works without any setup but recall quality may be lower than a dedicated embedding backend. If you notice poor recall results, consider installing Ollama and running the"," ",e.jsx("code",{children:"/megasetup"})," command, or set"," ",e.jsx("code",{children:"MEGACOMPACT_EMBEDDING_URL"})," to point at your own localhost embedding server."]})}function G(t){const n=t?"#1a5a1a":"#3a1a1a",r=t?"#4caf50":"#f44336";return e.jsx("span",{style:{...u.badge,background:n,color:r},children:t?"Detected":"Not found"})}function Me({status:t,statusError:n}){return e.jsxs("div",{style:u.section,children:[e.jsx("h3",{style:u.sectionTitle,children:"Current Embedder Configuration"}),n&&e.jsxs("p",{style:{color:"#f44336",fontSize:"0.85rem"},children:["Error: ",n]}),t&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{style:u.row,children:[e.jsx("span",{style:u.label,children:"Active Embedder:"}),e.jsx("span",{style:u.value,children:K(t.currentEmbedder)})]}),"configuredEmbedder"in t&&t.configuredEmbedder!==t.currentEmbedder&&e.jsxs("div",{style:u.warning,children:[e.jsx("strong",{children:"Configured but not active:"})," ",K(t.configuredEmbedder)," is configured in .mega-compact.env but not yet loaded."," ",e.jsx("strong",{children:"Restart pi"})," to activate it.",t.configuredUrl&&e.jsxs(e.Fragment,{children:[" (",t.configuredUrl,")"]})]}),"restartRequired"in t&&t.restartRequired&&e.jsxs("div",{style:{...u.row,color:"#ff9800"},children:[e.jsx("span",{style:u.label,children:"Status:"}),e.jsx("span",{style:u.value,children:"Restart required to activate the configured embedder"})]}),e.jsxs("div",{style:u.row,children:[e.jsx("span",{style:u.label,children:"Embedding URL:"}),e.jsx("span",{style:u.value,children:t.embeddingUrl??e.jsx("span",{style:{color:"#888"},children:"not set"})})]}),e.jsxs("div",{style:u.row,children:[e.jsx("span",{style:u.label,children:"Embed Cache:"}),e.jsx("span",{style:u.value,children:t.embedCache??e.jsx("span",{style:{color:"#888"},children:"not set"})})]}),e.jsxs("div",{style:u.row,children:[e.jsx("span",{style:u.label,children:"MiniLM:"}),e.jsx("span",{style:u.value,children:t.minilm?"enabled":"disabled"})]}),Be(t)]}),!t&&!n&&e.jsx("p",{style:{color:"#888",fontSize:"0.85rem"},children:"Loading configuration..."})]})}function ze(){const[t,n]=s.useState(null),[r,o]=s.useState(null),[a,l]=s.useState(null),[c,i]=s.useState(null),[d,g]=s.useState(!1),[m,x]=s.useState(null),[f,b]=s.useState(null),[v,S]=s.useState(null),[w,E]=s.useState(""),[h,T]=s.useState(!1),N=s.useCallback(()=>{ee().then(n).catch(p=>l(p instanceof Error?p.message:String(p)))},[]),M=s.useCallback((p,R,z,W,U,D)=>{x(p),S(null),b(null);const O="embeddingHeadersSet"in(t??{});V({embedder:p,url:R,embeddingEndpointUrl:R,embeddingApiKey:z,...O?{embeddingDim:W,embeddingHeaders:U,allowRemoteEmbedder:D}:{}}).then(I=>{b(I),x(null),N()}).catch(I=>{S(I instanceof Error?I.message:String(I)),x(null)})},[N,t]),y=s.useCallback(()=>{g(!0),i(null),ce().then(p=>{o(p),g(!1)}).catch(p=>{i(p instanceof Error?p.message:String(p)),g(!1)})},[]);return s.useEffect(()=>{N()},[N]),s.useEffect(()=>{h||t&&typeof t.embeddingEndpointUrl=="string"&&t.embeddingEndpointUrl.length>0&&(E(t.embeddingEndpointUrl),T(!0))},[t,h]),s.useEffect(()=>{const p=setInterval(N,5e3);return()=>clearInterval(p)},[N]),s.useEffect(()=>{y();const p=setInterval(y,5e3);return()=>clearInterval(p)},[y]),e.jsxs("div",{style:u.container,children:[e.jsx("h2",{style:{fontSize:"1.3rem",marginTop:0,marginBottom:"1rem"},children:"Embedder Setup"}),e.jsx(Se,{}),e.jsx(Me,{status:t,statusError:a}),e.jsxs("div",{style:u.section,children:[e.jsx("h3",{style:u.sectionTitle,children:"Local Embedder Detection"}),e.jsx("p",{style:{fontSize:"0.85rem",color:"#a0a0c0",marginTop:0},children:"Detect which local embedding backends are available on this machine. No software is installed — detection only."}),r&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{style:u.detectRow,children:[e.jsx("span",{children:e.jsx("strong",{children:"Ollama"})}),r.ollama!==null?e.jsxs("span",{children:[G(r.ollama.installed),r.ollama.installed&&e.jsx("span",{style:{fontSize:"0.8rem",color:"#a0a0c0",marginLeft:"0.5rem"},children:r.ollama.running?`server running, ${r.ollama.models.length} model(s)`:"server not running"})]}):e.jsx("span",{style:{color:"#888",fontSize:"0.85rem"},children:"not checked"})]}),e.jsxs("div",{style:u.detectRow,children:[e.jsx("span",{children:e.jsx("strong",{children:"llama.cpp"})}),r.llamaCpp!==null?e.jsxs("span",{children:[G(r.llamaCpp.installed),r.llamaCpp.installed&&r.llamaCpp.detail&&e.jsx("span",{style:{fontSize:"0.8rem",color:"#a0a0c0",marginLeft:"0.5rem"},children:r.llamaCpp.detail})]}):e.jsx("span",{style:{color:"#888",fontSize:"0.85rem"},children:"not checked"})]}),e.jsxs("div",{style:u.detectRow,children:[e.jsx("span",{children:e.jsx("strong",{children:"ONNX Runtime"})}),r.onnx!==null?e.jsxs("span",{children:[G(r.onnx.installed),r.onnx.installed&&r.onnx.detail&&e.jsx("span",{style:{fontSize:"0.8rem",color:"#a0a0c0",marginLeft:"0.5rem"},children:r.onnx.detail})]}):e.jsx("span",{style:{color:"#888",fontSize:"0.85rem"},children:"not checked"})]}),r.error&&e.jsxs("p",{style:{color:"#f44336",fontSize:"0.8rem",marginTop:"0.5rem"},children:["Detection error: ",r.error]})]}),c&&e.jsxs("p",{style:{color:"#f44336",fontSize:"0.85rem"},children:["Error: ",c]}),e.jsxs("div",{style:{marginTop:"1rem"},children:[e.jsx("button",{style:u.button,onClick:y,disabled:d,children:d?"Detecting...":"Run Detection"}),e.jsxs("span",{style:{fontSize:"0.8rem",color:"#888",marginLeft:"0.75rem"},children:["Or run ",e.jsx("code",{children:"/megasetup"})," in the chat for an interactive wizard."]})]}),r&&e.jsxs("div",{style:{marginTop:"1rem",paddingTop:"0.75rem",borderTop:"1px solid #2a2a4e"},children:[e.jsx("div",{style:{fontSize:"0.9rem",fontWeight:600,marginBottom:"0.5rem"},children:"Configure"}),e.jsxs("div",{style:{display:"flex",gap:"0.5rem",flexWrap:"wrap"},children:[e.jsx("button",{style:{...u.button,opacity:r.ollama?.installed?1:.4},onClick:()=>M("ollama"),disabled:!r.ollama?.installed||m!==null,children:m==="ollama"?"Writing...":"Use Ollama"}),e.jsx("button",{style:{...u.button,opacity:r.llamaCpp?.installed?1:.4},onClick:()=>M("llama"),disabled:!r.llamaCpp?.installed||m!==null,children:m==="llama"?"Writing...":"Use llama.cpp"}),e.jsx("button",{style:{...u.button,opacity:r.onnx?.installed?1:.4},onClick:()=>M("onnx"),disabled:!r.onnx?.installed||m!==null,children:m==="onnx"?"Writing...":"Use ONNX"}),e.jsx("button",{style:{...u.button,background:"#444"},onClick:()=>M("trigram"),disabled:m!==null,children:m==="trigram"?"Writing...":"Use Trigram (default)"})]}),f&&f.embedder!=="custom"&&e.jsx("div",{style:u.warning,children:f.alreadyActive?"Already active — no restart needed.":`Configured ${f.embedder}. Restart pi to activate (config written to ${f.envPath}).`}),v&&e.jsxs("p",{style:{color:"#f44336",fontSize:"0.85rem",marginTop:"0.5rem"},children:["Configure error: ",v]})]})]}),e.jsx(Re,{customUrl:w,setCustomUrl:E,applyEmbedder:M,configuring:m,inputEnabled:t!==null&&"embeddingApiKeySet"in t,apiKeySet:t?.embeddingApiKeySet===!0,embeddingDim:t?.embeddingDim,embeddingHeadersSet:t?.embeddingHeadersSet===!0,allowRemoteEmbedder:t?.allowRemoteEmbedder,configureResult:f,configureError:v}),e.jsxs("div",{style:u.section,children:[e.jsx("h3",{style:u.sectionTitle,children:"How to Upgrade"}),e.jsxs("ul",{style:{fontSize:"0.85rem",lineHeight:1.6,paddingLeft:"1.25rem"},children:[e.jsxs("li",{children:[e.jsx("strong",{children:"Ollama:"})," Install from"," ",e.jsx("a",{href:"https://ollama.com",style:{color:"#6a9fff"},target:"_blank",rel:"noopener noreferrer",children:"ollama.com"}),", then ",e.jsx("code",{children:"ollama pull nomic-embed-text"})," and restart pi. Set ",e.jsx("code",{children:"MEGACOMPACT_EMBEDDING_URL=http://localhost:11434/api/embeddings"}),"."]}),e.jsxs("li",{children:[e.jsx("strong",{children:"llama.cpp:"})," Build or install llama.cpp, run"," ",e.jsx("code",{children:"llama-server"})," with an embedding model, and set the URL accordingly."]}),e.jsxs("li",{children:[e.jsx("strong",{children:"ONNX Runtime:"})," Run a local text-embeddings server (e.g. TEI) and click ",e.jsx("strong",{children:"Use ONNX"})," above. Default URL: ",e.jsx("code",{children:"http://localhost:8081/v1/embeddings"}),"."]})]})]}),e.jsxs("div",{style:u.section,children:[e.jsx("h3",{style:u.sectionTitle,children:"Settings"}),e.jsx(Ne,{})]})]})}function $(t){return t>=1e6?`${(t/1e6).toFixed(2)}M`:t>=1e3?`${Math.round(t/1e3)}K`:String(t)}function Ae(t,n,r){if(t<=0)return"—";const a=(n>0?n:Math.ceil(t*.1))+Math.ceil(t*(r/100)),l=t-a;return l<=0?"0 (at risk)":`${$(l)} tokens`}function J({label:t,value:n,min:r,max:o,step:a=1,onChange:l,warning:c}){return e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsxs("div",{className:"flex items-center justify-between text-xs",children:[e.jsx("span",{className:"font-medium text-fg-muted",children:t}),e.jsxs("span",{className:`font-mono ${c?"text-warning":"text-fg"}`,title:c,children:[n,"%"]})]}),e.jsx("input",{type:"range",min:r,max:o,step:a,value:n,onChange:i=>l(Number(i.target.value)),className:"threshold-slider w-full"}),c&&e.jsxs("p",{className:"text-[10px] text-warning",children:["⚠ ",c]})]})}function Oe({model:t,defaults:n,safetyRange:r,fireRange:o,onSave:a,onReset:l,saving:c}){const[i,d]=s.useState(t.threshold.safetyMarginPct),[g,m]=s.useState(t.threshold.firePointPct),[x,f]=s.useState(!1),[b,v]=s.useState(null);s.useEffect(()=>{d(t.threshold.safetyMarginPct),m(t.threshold.firePointPct),f(!1)},[t.threshold.safetyMarginPct,t.threshold.firePointPct]);const S=i<5?'Low safety margin — risks "conversation too long" errors when a single turn injects a large tool output between gate fires.':void 0,w=g>85?"High fire point — compaction may trigger close to the window cap; a single large turn can overshoot before the gate fires.":void 0,E=s.useCallback(async()=>{v(null);try{await a(t.modelId,i,g),f(!1)}catch(h){v(h instanceof Error?h.message:String(h))}},[t.modelId,i,g,a]);return e.jsxs("div",{className:"rounded-md border border-border bg-bg-elevated/30 p-3",children:[e.jsxs("div",{className:"mb-2 flex items-start justify-between",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-sm font-semibold text-fg",children:t.modelName??t.modelId}),t.threshold.isOverride&&e.jsx("span",{className:"rounded border border-primary/40 bg-primary/15 px-1.5 py-0.5 text-[10px] font-semibold uppercase text-primary",title:"This model has a custom override (not the default)",children:"Override"})]}),e.jsxs("div",{className:"text-[11px] text-fg-muted",children:[t.provider," · ",$(t.contextWindow)," window ·"," ",$(t.maxTokens)," output"]})]}),e.jsxs("div",{className:"text-right text-[11px] text-fg-muted",children:[e.jsxs("div",{children:["Usable tail:"," ",e.jsx("span",{className:"font-mono text-fg",children:Ae(t.contextWindow,t.maxTokens,i)})]}),e.jsxs("div",{children:["Compaction fires at:"," ",e.jsx("span",{className:"font-mono text-fg",children:$(Math.ceil(t.contextWindow*(g/100)))})]})]})]}),e.jsxs("div",{className:"grid grid-cols-1 gap-3 sm:grid-cols-2",children:[e.jsx(J,{label:"Safety margin",value:i,min:r[0],max:r[1],onChange:h=>{d(h),f(!0)},warning:S}),e.jsx(J,{label:"Fire point",value:g,min:o[0],max:o[1],onChange:h=>{m(h),f(!0)},warning:w})]}),e.jsxs("div",{className:"mt-2 flex items-center gap-2",children:[e.jsx("button",{type:"button",onClick:E,disabled:!x||c,className:"rounded-md bg-primary px-2.5 py-1 text-xs font-semibold text-primary-fg disabled:cursor-not-allowed disabled:opacity-50",children:x?"Save override":"Saved"}),t.threshold.isOverride&&e.jsxs("button",{type:"button",onClick:()=>l(t.modelId),disabled:c,className:"rounded-md border border-border px-2.5 py-1 text-xs text-fg-muted disabled:cursor-not-allowed disabled:opacity-50",children:["Reset to default (",n.safetyMarginPct,"% /"," ",n.firePointPct,"%)"]}),b&&e.jsx("span",{className:"text-[11px] text-error",children:b})]})]})}function Ie(){const[t,n]=s.useState(null),[r,o]=s.useState(!0),[a,l]=s.useState(null),[c,i]=s.useState(!1),d=s.useCallback(async()=>{try{l(null),n(await he())}catch(x){l(x instanceof Error?x.message:String(x))}finally{o(!1)}},[]);s.useEffect(()=>{d()},[d]);const g=s.useCallback(async(x,f,b)=>{i(!0);try{await pe({modelId:x,safetyMarginPct:f,firePointPct:b}),await d()}finally{i(!1)}},[d]),m=s.useCallback(async x=>{i(!0);try{await ge(x),await d()}finally{i(!1)}},[d]);return r?e.jsx("div",{className:"p-4 text-sm text-fg-muted",children:"Loading thresholds…"}):a?e.jsxs("div",{className:"p-4 text-sm text-error",children:["Error: ",a]}):t?e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsxs("div",{className:"rounded-md border border-border bg-bg-elevated/20 p-3",children:[e.jsx("h3",{className:"text-sm font-semibold",children:"Per-Model Compaction Thresholds"}),e.jsxs("p",{className:"mt-1 text-[11px] text-fg-muted",children:["Tune when compaction fires + how much safety margin to reserve,",e.jsx("strong",{children:" per model"}),". Different providers' models range from 8K to 1M+ context — one global % is wrong. Defaults:"," ",e.jsxs("span",{className:"font-mono",children:[t.defaults.safetyMarginPct,"% safety"]})," ","/"," ",e.jsxs("span",{className:"font-mono",children:[t.defaults.firePointPct,"% fire"]}),". Values outside the safe band show warnings."]})]}),t.models.length===0?e.jsx("div",{className:"rounded-md border border-border p-4 text-sm text-fg-muted",children:"No models captured yet. Start a pi session in any repo to populate model snapshots, then return here to tune per-model thresholds."}):e.jsx("div",{className:"flex flex-col gap-3",children:t.models.map(x=>e.jsx(Oe,{model:x,defaults:t.defaults,safetyRange:t.defaults.safetyMarginRange,fireRange:t.defaults.firePointRange,onSave:g,onReset:m,saving:c},x.modelId))})]}):e.jsx("div",{className:"p-4 text-sm text-fg-muted",children:"No data."})}async function Le(){const t=await fetch("/api/setup-cortex-status");if(!t.ok)throw new Error(`setup-cortex status: ${t.status}`);return t.json()}async function De(t){const n=await fetch("/api/setup-cortex-action",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)});if(n.ok)return{ok:!0,result:await n.json()};let r;try{r=await n.json()}catch{r={error:"disabled"}}return{ok:!1,status:n.status,error:r}}async function Pe(t){const n=await fetch(`/api/setup-cortex-action-log?name=${encodeURIComponent(t)}`);if(!n.ok)throw new Error(`setup-cortex action-log: ${n.status}`);return n.json()}function _e(t){return t===null?!0:t.enabled&&t.status!=="off"}function ne(){const[t,n]=s.useState({loading:!0,error:null,data:null}),r=s.useCallback(()=>{n(o=>({...o,loading:!0})),Le().then(o=>n(a=>({...a,data:o,loading:!1,error:null}))).catch(o=>n(a=>({...a,loading:!1,error:o instanceof Error?o.message:String(o)})))},[]);return s.useEffect(()=>{r();const o=setInterval(r,5e3);return()=>clearInterval(o)},[r]),[t,r]}const j={container:{padding:"1rem",maxWidth:"720px",margin:"0 auto",fontFamily:"system-ui, sans-serif",color:"#e0e0e0"},section:{background:"#1a1a2e",borderRadius:"8px",padding:"1rem",marginBottom:"1rem",border:"1px solid #2a2a4e"},sectionTitle:{fontSize:"1.1rem",fontWeight:700,marginTop:0,marginBottom:"0.75rem",color:"#e0e0e0",borderBottom:"1px solid #333",paddingBottom:"0.5rem"},label:{fontWeight:600,color:"#a0a0c0",marginRight:"0.5rem"},value:{color:"#e0e0e0"},row:{marginBottom:"0.4rem",fontSize:"0.9rem"},warning:{background:"#3a2a00",border:"1px solid #665500",borderRadius:"8px",padding:"0.75rem",marginTop:"0.5rem",color:"#ffcc00",fontSize:"0.85rem"},blocked:{background:"#3a1a1a",border:"1px solid #662222",borderRadius:"8px",padding:"0.75rem",marginTop:"0.5rem",color:"#ff6666",fontSize:"0.85rem"},badge:{display:"inline-block",padding:"0.15rem 0.5rem",borderRadius:"4px",fontSize:"0.8rem",fontWeight:600,marginLeft:"0.5rem"},button:{background:"#3a5a9f",color:"#fff",border:"none",borderRadius:"6px",padding:"0.5rem 1rem",cursor:"pointer",fontSize:"0.9rem",fontWeight:600},buttonDanger:{background:"#6a2a2a",color:"#ffb3b3",border:"1px solid #662222",borderRadius:"6px",padding:"0.5rem 1rem",cursor:"pointer",fontSize:"0.9rem",fontWeight:600},blockerRow:{display:"flex",justifyContent:"space-between",alignItems:"center",gap:"0.5rem",padding:"0.5rem 0.6rem",borderRadius:"6px",marginBottom:"0.35rem",fontSize:"0.85rem"},blockerRowHighlighted:{background:"#3a1a1a",border:"1px solid #662222"},mono:{fontFamily:"ui-monospace, monospace",fontSize:"0.8rem"}};function $e(t){switch(t){case"A":return"A — qualified learned encoder asset";case"B":return"B — demoted (heuristic/trigram)";case"C":return"C — absent (asset not verified)";default:return"—"}}function We(t){const n=t==="qualified"?"#1a5a1a":t==="demoted"?"#3a3a1a":"#3a1a1a",r=t==="qualified"?"#4caf50":t==="demoted"?"#ffcc00":"#f44336";return e.jsx("span",{style:{...j.badge,background:n,color:r},children:t??"unknown"})}function Ue({data:t,error:n}){return e.jsxs("div",{style:j.section,children:[e.jsxs("h3",{style:j.sectionTitle,children:[e.jsx("span",{style:{marginRight:"0.5rem"},children:"Cortex Encoder"}),e.jsx(fe,{status:t?.status})]}),n&&e.jsxs("p",{style:{color:"#f44336",fontSize:"0.85rem"},children:["Error: ",n]}),!t&&!n&&e.jsx("p",{style:{color:"#888",fontSize:"0.85rem"},children:"Loading cortex status..."}),!t?.enabled&&e.jsx("p",{style:{color:"#f44336",fontSize:"0.85rem"},children:"Cortex status disabled (VC9A off)."}),e.jsxs("div",{style:j.row,children:[e.jsx("span",{style:j.label,children:"Mode:"}),e.jsx("span",{style:j.value,children:$e(t?.encoderHealth.mode)})]}),e.jsxs("div",{style:j.row,children:[e.jsx("span",{style:j.label,children:"Asset digest prefix:"}),e.jsx("span",{style:{...j.value,...j.mono},children:t?.assetDigestPrefix??e.jsx("span",{style:{color:"#888"},children:"not available"})})]}),e.jsxs("div",{style:j.row,children:[e.jsx("span",{style:j.label,children:"Qualification:"}),We(t?.qualification.verdict)]}),(t?.qualification.thresholdFailures.length??0)>0&&e.jsxs("div",{style:j.warning,children:[e.jsx("strong",{children:"Threshold failure(s):"})," ",t?.qualification.thresholdFailures.join(", ")]}),t?.status==="awaiting_data"&&e.jsx("p",{style:{color:"#a0a0c0",fontSize:"0.85rem"},children:"Awaiting encoder data. Qualification will appear once an asset is present."}),t?.status==="deferred"&&e.jsx("p",{style:{color:"#a0a0c0",fontSize:"0.85rem"},children:"Encoder status deferred."})]})}function Fe(t){switch(t){case"blocker":return"#f44336";case"high":return"#ff9800";default:return"#a0a0c0"}}function He({blockers:t,highlight:n,darwinX64:r}){const o=n??[];return e.jsxs("div",{style:j.section,children:[e.jsxs("h3",{style:j.sectionTitle,children:["Open Hard-Gate Blockers",e.jsx("span",{style:{...j.badge,background:"#3a1a1a",color:"#f44336"},children:t.length})]}),t.length===0&&e.jsx("p",{style:{color:"#4caf50",fontSize:"0.85rem"},children:"No open hard-gate blockers."}),r?.demoted===!0&&e.jsxs("div",{style:j.blockerRow,"data-darwin-x64-demoted":"true",children:[e.jsx("span",{style:{...j.mono,fontWeight:700},children:"HG-4"}),e.jsx("span",{style:{flex:1,color:"#e0e0e0"},children:r.reason||"darwin-x64: demoted to WASM (reason unavailable)"}),e.jsx("span",{style:{color:"#ff9800"},children:"high"}),e.jsx("span",{style:{color:"#4caf50",fontStyle:"italic"},children:"diagnosed"})]}),t.map(a=>{const l=o.includes(a.id);return e.jsxs("div",{style:{...j.blockerRow,...l?j.blockerRowHighlighted:{}},children:[e.jsx("span",{style:{...j.mono,fontWeight:700},children:a.id}),e.jsx("span",{style:{flex:1,color:"#e0e0e0"},children:a.title}),e.jsx("span",{style:{color:Fe(a.severity)},children:a.severity}),e.jsx("span",{style:{color:"#a0a0c0",fontStyle:"italic"},children:l?"gates this action":a.status})]},a.id)}),o.length>0&&e.jsxs("div",{style:j.blocked,children:[e.jsx("strong",{children:"Blocked:"})," the requested action is gated by the highlighted open hard-gate item(s). It was not run."]})]})}const Ge=[{key:"fetch-model",label:"Fetch Model",desc:"Fetch the qualified encoder model asset",dangerous:!0,confirm:"Fetch the encoder model asset onto this host? (Gated by any open hard gate.)"},{key:"bench",label:"Bench Encoder",desc:"Benchmark the encoder runtime on this host",dangerous:!0,confirm:"Run an encoder benchmark on this host? (Gated by any open hard gate.)"},{key:"verify-asset",label:"Verify Asset",desc:"Re-verify the committed encoder asset",dangerous:!1,confirm:"Re-verify the committed encoder asset?"}];function qe({data:t,onBlocked:n,onAction:r}){const[o,a]=s.useState(null),[l,c]=s.useState(null),[i,d]=s.useState(null),[g,m]=s.useState(!1),x=s.useCallback(async b=>{a(b.key),d(null),c(null),m(!1),n([]);try{const v=await De({action:b.key,confirm:!0});if(v.ok){const S=v.result;let w=null,E=null;try{const h=await Pe(S.logName);w=h.tail,E=h.complete}catch{}c({action:S.action,logName:S.logName,tail:w,complete:E,message:S.ok?`${S.action} completed (spawned: ${S.spawned})`:`${S.action} did not complete cleanly`}),r()}else v.error.error==="action_blocked_by_open_item"?(n(v.error.blockers),d("The action is blocked by an open hard-gate item and was not run.")):v.error.error==="confirmation_required"?d("The server rejected the action: explicit confirmation is required."):(m(!0),d(v.status===404?"Setup Cortex actions are disabled (off).":`Action failed (${v.status}).`))}catch(v){d(v instanceof Error?v.message:String(v))}finally{a(null)}},[n,r]),f=b=>{window.confirm(b.confirm)&&x(b)};return e.jsxs("div",{style:j.section,children:[e.jsx("h3",{style:j.sectionTitle,children:"Cortex Actions"}),Ge.map(b=>{const v=o===b.key;return e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:"0.5rem",padding:"0.5rem 0",borderBottom:"1px solid #2a2a4e"},children:[e.jsxs("div",{children:[e.jsx("div",{style:{fontWeight:600},children:b.label}),e.jsx("div",{style:{fontSize:"0.8rem",color:"#a0a0c0"},children:b.desc})]}),e.jsx("button",{style:b.dangerous?j.buttonDanger:j.button,disabled:o!==null,onClick:()=>f(b),children:v?"Running…":"Run"})]},b.key)}),g&&e.jsx("div",{style:j.blocked,children:"Setup Cortex actions are disabled. Enable MEGACOMPACT_VC9B to run them."}),i&&!g&&e.jsx("p",{style:{color:"#f44336",fontSize:"0.85rem",marginTop:"0.5rem"},children:i}),l&&e.jsxs("div",{style:j.warning,"data-testid":"cortex-action-result",children:[e.jsxs("strong",{children:["Result (",l.action,"):"]})," ",l.message,l.logName&&e.jsxs("span",{style:{...j.mono,marginLeft:"0.5rem"},children:["log: ",l.logName]}),l.tail!==null&&e.jsxs("pre",{style:{whiteSpace:"pre-wrap",wordBreak:"break-word",fontSize:"0.75rem",maxHeight:"12rem",overflow:"auto",marginTop:"0.5rem"},children:[l.tail,l.complete===!1&&`
2
- … (truncated)`]})]}),!t?.enabled&&!g&&e.jsx("p",{style:{color:"#a0a0c0",fontSize:"0.8rem",marginTop:"0.5rem"},children:"Cortex status unavailable — actions may not be schedulable."})]})}const B={section:{background:"#1a1a2e",borderRadius:"8px",padding:"1rem",marginBottom:"1rem",border:"1px solid #2a2a4e"},sectionTitle:{fontSize:"1.1rem",fontWeight:700,marginTop:0,marginBottom:"0.25rem",color:"#e0e0e0"},subtitle:{fontSize:"0.85rem",color:"#a0a0c0",marginTop:0,marginBottom:"0.75rem"},row:{marginBottom:"0.4rem",fontSize:"0.9rem"},label:{fontWeight:600,color:"#a0a0c0",marginRight:"0.5rem"},value:{color:"#e0e0e0"},warning:{background:"#3a2a00",border:"1px solid #665500",borderRadius:"8px",padding:"0.75rem",marginTop:"0.5rem",color:"#ffcc00",fontSize:"0.85rem"},toggleRow:{display:"flex",alignItems:"center",gap:"0.5rem",marginBottom:"0.75rem",fontSize:"0.9rem"}},q=8192;function Ve(){const[t,n]=s.useState(null),[r,o]=s.useState(null),[a,l]=s.useState(!1),[c,i]=s.useState(""),[d,g]=s.useState(!1),m=s.useCallback(()=>{ee().then(n).catch(h=>o(h instanceof Error?h.message:String(h)))},[]);s.useEffect(()=>{m()},[m]),s.useEffect(()=>{const h=setInterval(m,5e3);return()=>clearInterval(h)},[m]);const x=t!==null&&"encoderNativeOptIn"in t,f=t?.nativeOrtBudgetEffectiveMib;s.useEffect(()=>{if(!d&&t&&"nativeOrtBudgetEffectiveMib"in t){const h=t.nativeOrtBudgetMib??t.nativeOrtBudgetEffectiveMib??"";typeof h=="string"&&i(h),g(!0)}},[d,t]);const b=s.useCallback(h=>{l(!0),o(null),V({embedder:"custom",url:t?.embeddingEndpointUrl??void 0,encoderNativeOptIn:h}).then(()=>{l(!1),m()}).catch(T=>{o(T instanceof Error?T.message:String(T)),l(!1)})},[t,m]),v=s.useCallback(()=>{const h=c.trim();if(!/^\d+$/.test(h)){o("Install budget must be a positive integer (MiB)");return}const T=Number(h);if(!Number.isSafeInteger(T)||T<1||T>q){o(`Install budget must be between 1 and ${q} MiB`);return}l(!0),o(null),V({embedder:"custom",url:t?.embeddingEndpointUrl??void 0,nativeOrtBudgetMib:h}).then(()=>{l(!1),m()}).catch(N=>{o(N instanceof Error?N.message:String(N)),l(!1)})},[c,t,m]);if(!x)return e.jsx(e.Fragment,{});const S=t?.encoderBackend??"wasm",w=t?.encoderDemotionReason??null,E=t!==null&&"nativeOrtBudgetEffectiveMib"in t;return e.jsxs("div",{style:B.section,children:[e.jsx("h3",{style:B.sectionTitle,children:"Encoder Runtime"}),e.jsx("p",{style:B.subtitle,children:"ONNX backend selection"}),e.jsxs("div",{style:B.toggleRow,children:[e.jsx("input",{type:"checkbox",checked:t?.encoderNativeOptIn===!0,onChange:h=>b(h.target.checked),disabled:a,"aria-label":"Native ONNX runtime (onnxruntime-node)"}),e.jsx("label",{children:"Native ONNX runtime (onnxruntime-node)"}),a&&e.jsx("span",{style:{fontSize:"0.8rem",color:"#a0a0c0"},children:"saving..."})]}),e.jsxs("div",{style:B.row,children:[e.jsx("span",{style:B.label,children:"Effective backend:"}),e.jsx("span",{style:B.value,children:S})]}),E&&e.jsxs("div",{style:B.row,children:[e.jsx("label",{htmlFor:"enc2-budget-input",style:{...B.label,marginRight:"0.5rem"},children:"Native install budget (MiB):"}),e.jsx("input",{id:"enc2-budget-input",type:"number",min:1,max:q,step:1,value:c,onChange:h=>i(h.target.value),disabled:a,style:{width:"6rem"},"aria-label":"Native onnxruntime install budget in MiB"}),e.jsx("button",{type:"button",onClick:v,disabled:a||c.trim().length===0,style:{marginLeft:"0.5rem"},children:"Save"}),f!==void 0&&e.jsxs("span",{style:{...B.value,marginLeft:"0.5rem"},children:["(effective: ",f," MiB)"]})]}),w!==null&&e.jsxs("div",{style:B.warning,children:[e.jsx("strong",{children:"Demoted:"})," ",w]}),r&&e.jsxs("p",{style:{color:"#f44336",fontSize:"0.85rem"},children:["Error: ",r]})]})}const k={section:{background:"#1a1a2e",borderRadius:"8px",padding:"1rem",marginBottom:"1rem",border:"1px solid #2a2a4e"},sectionTitle:{fontSize:"1.1rem",fontWeight:700,marginTop:0,marginBottom:"0.25rem",color:"#e0e0e0"},subtitle:{fontSize:"0.85rem",color:"#a0a0c0",marginTop:0,marginBottom:"0.75rem"},row:{marginBottom:"0.4rem",fontSize:"0.9rem"},label:{fontWeight:600,color:"#a0a0c0",marginRight:"0.5rem"},value:{color:"#e0e0e0"},disabled:{background:"#1a1a2e",border:"1px solid #2a2a4e",borderRadius:"8px",padding:"1rem",marginBottom:"1rem",color:"#a0a0c0",fontSize:"0.85rem"}},Xe=()=>{const{data:t,error:n,loading:r}=X(s.useMemo(()=>()=>te("/api/cosine-fp-report").catch(o=>{if(o instanceof se&&o.status===404)return null;throw o}),[]),{pollInterval:5e3});return t===null&&!n&&!r?e.jsx("div",{style:k.disabled,children:"Cosine FP synthetic bench: disabled (MEGACOMPACT_COSINE_FP_BENCH=0)."}):e.jsxs("div",{style:k.section,children:[e.jsx("h3",{style:k.sectionTitle,children:"Cosine FP threshold"}),e.jsx("p",{style:k.subtitle,children:"Last synthetic bench threshold recommendation"}),n!==null?e.jsxs("p",{style:{color:"#f44336",fontSize:"0.85rem"},children:["Error loading report: ",n.message]}):t===null?e.jsx("div",{style:k.value,children:"Loading…"}):e.jsxs("div",{children:[e.jsxs("div",{style:k.row,children:[e.jsx("span",{style:k.label,children:"Recommended default:"}),e.jsxs("span",{style:k.value,children:[t.recommendedDefault??"—"," (shipped"," ",t.shippedDefault,")"]})]}),e.jsxs("div",{style:k.row,children:[e.jsx("span",{style:k.label,children:"Overrides:"}),e.jsxs("span",{style:k.value,children:["CODE ",t.overrides?.code??"—"," · PROSE"," ",t.overrides?.prose??"—"," · MIXED"," ",t.overrides?.mixed??"—"]})]}),e.jsxs("div",{style:k.row,children:[e.jsx("span",{style:k.label,children:"Grid:"}),e.jsx("span",{style:k.value,children:t.grid?`${t.grid.lo} → ${t.grid.hi} (${t.grid.points} points)`:"—"})]}),e.jsxs("div",{style:k.row,children:[e.jsx("span",{style:k.label,children:"Report digest:"}),e.jsx("span",{style:k.value,title:t.digest??void 0,children:t.digest?t.digest.slice(0,16)+"…":"—"})]})]})]})},C={section:{background:"#1a1a2e",borderRadius:"8px",padding:"1rem",marginBottom:"1rem",border:"1px solid #2a2a4e"},sectionTitle:{fontSize:"1.1rem",fontWeight:700,marginTop:0,marginBottom:"0.25rem",color:"#e0e0e0"},subtitle:{fontSize:"0.85rem",color:"#a0a0c0",marginTop:0,marginBottom:"0.75rem"},row:{marginBottom:"0.4rem",fontSize:"0.9rem"},label:{fontWeight:600,color:"#a0a0c0",marginRight:"0.5rem"},value:{color:"#e0e0e0"},disabled:{background:"#1a1a2e",border:"1px solid #2a2a4e",borderRadius:"8px",padding:"1rem",marginBottom:"1rem",color:"#a0a0c0",fontSize:"0.85rem"}},Ke=()=>{const{data:t,error:n,loading:r}=X(s.useMemo(()=>()=>te("/api/repo-corpus").catch(o=>{if(o instanceof se&&o.status===404)return null;throw o}),[]),{pollInterval:5e3});return t===null&&!n&&!r?e.jsx("div",{style:C.disabled,children:"Cross-repo corpus: disabled (MEGACOMPACT_REPO_CORPUS=0)."}):e.jsxs("div",{style:C.section,children:[e.jsx("h3",{style:C.sectionTitle,children:"Cross-Repo Corpus"}),e.jsx("p",{style:C.subtitle,children:"Pseudonymous consent status across donated repos"}),n!==null?e.jsxs("p",{style:{color:"#f44336",fontSize:"0.85rem"},children:["Error loading corpus: ",n.message]}):t===null?e.jsx("div",{style:C.value,children:"Loading…"}):e.jsxs("div",{children:[e.jsxs("div",{style:C.row,children:[e.jsx("span",{style:C.label,children:"Status:"}),e.jsx("span",{style:C.value,children:t.status})]}),e.jsxs("div",{style:C.row,children:[e.jsx("span",{style:C.label,children:"Total events:"}),e.jsx("span",{style:C.value,children:t.totalEvents})]}),e.jsxs("div",{style:C.row,children:[e.jsx("span",{style:C.label,children:"Overlap pairs:"}),e.jsx("span",{style:C.value,children:t.corpus?t.corpus.overlaps.length:0})]}),e.jsx("div",{style:{marginTop:"0.5rem"},children:(t.perRepo??[]).map(o=>e.jsxs("div",{style:C.row,children:[e.jsxs("span",{style:C.label,children:[o.repoPseudonym.slice(0,8),":"]}),e.jsxs("span",{style:C.value,children:[o.sessions," sessions ·"," ",o.consentedCrossRepo?o.revokedAt?`revoked ${o.revokedAt}`:"consented":"not consented"]})]},o.repoPseudonym))})]})]})};function Je(){const[t,n]=ne(),[r,o]=s.useState([]),a=s.useCallback(c=>{o(c)},[]),l=s.useCallback(()=>{n()},[n]);return e.jsxs("div",{style:j.container,children:[e.jsx("h2",{style:{fontSize:"1.3rem",marginTop:0,marginBottom:"1rem"},children:"Setup Cortex"}),e.jsx("p",{style:{fontSize:"0.85rem",color:"#a0a0c0",marginTop:0},children:"Vector-cortex encoder gate: mode, qualification, open hard-gate blockers, and the confirmation-gated fetch/bench/verify actions."}),e.jsx(Ue,{data:t.data,error:t.error}),e.jsx(Ve,{}),e.jsx(Xe,{}),e.jsx(Ke,{}),e.jsx(He,{blockers:t.data?.blockers??[],highlight:r,darwinX64:t.data?.darwinX64}),e.jsx(qe,{data:t.data,onBlocked:a,onAction:l})]})}const Qe="MEGACOMPACT_DASH_0C";function Ye(t){if(!t)return!1;for(const n of t.categories)for(const r of n.settings)if(r.key===Qe&&r.type==="boolean")return r.value===!0;return!1}const Q=[{id:"embedder",label:"Embedder"},{id:"thresholds",label:"Thresholds"},{id:"config",label:"Config"},{id:"game",label:"Game Mode"},{id:"achievements",label:"Achievements"}],Ze={id:"cortex",label:"Cortex"};function ot(){const[t,n]=s.useState("embedder"),[r]=ne(),{data:o}=X(s.useCallback(()=>Z(),[]),{pollInterval:0,maxRetries:0}),a=Ye(o),l=s.useMemo(()=>{const c=a?Q.filter(i=>i.id!=="config"):[...Q];return _e(r.data)&&c.push(Ze),c},[r.data,a]);return e.jsxs("div",{className:"mx-auto flex max-w-3xl flex-col gap-4 p-4",children:[e.jsx("nav",{className:"flex gap-2 border-b border-border pb-2","aria-label":"Setup sections",children:l.map(c=>e.jsx(xe,{pressed:t===c.id,onClick:()=>n(c.id),children:c.label},c.id))}),t==="embedder"&&e.jsx(ze,{}),t==="thresholds"&&e.jsx(Ie,{}),t==="config"&&!a&&e.jsx(me,{}),t==="game"&&e.jsx(je,{}),t==="achievements"&&e.jsx(ve,{}),t==="cortex"&&e.jsx(Je,{})]})}export{ot as default};
3
- //# sourceMappingURL=SetupTab-CgC4Rz38.js.map