pi-mega-compact 0.20.52 → 0.20.53
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/config/vector-cortex-enc2budget.js +46 -0
- package/dist/config/vector-cortex.js +1 -0
- package/dist/config.js +1 -1
- package/dist/extensions/dashboard-server/routes-rag-settings-vector-cortex.js +1 -0
- package/dist/extensions/dashboard-server/routes-setup-enc2budget.js +155 -0
- package/dist/extensions/dashboard-server/routes-setup.js +15 -0
- package/dist/src/config/vector-cortex-enc2budget.js +46 -0
- package/dist/src/config/vector-cortex.js +1 -0
- package/dist/src/config.js +1 -1
- package/dist/src/vector-cortex/encoder/decision.js +34 -6
- package/dist/src/vector-cortex/encoder/runtime-select.js +24 -21
- package/dist/src/vector-cortex/setup-cortex-blockers-compute.js +2 -2
- package/dist/vector-cortex/encoder/decision.js +34 -6
- package/dist/vector-cortex/encoder/runtime-select.js +24 -21
- package/dist/vector-cortex/setup-cortex-blockers-compute.js +2 -2
- package/extensions/dashboard-client/dist/assets/{AreaChart-Dika24if.js → AreaChart-COjQ_jJm.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{AreaChart-Dika24if.js.map → AreaChart-COjQ_jJm.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{BarChart-MxPpphaX.js → BarChart-eAIpwb8c.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{BarChart-MxPpphaX.js.map → BarChart-eAIpwb8c.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{CacheTab-e90mt1aw.js → CacheTab-BS_G9_YV.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{CacheTab-e90mt1aw.js.map → CacheTab-BS_G9_YV.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{EventsTab-CSl9CNXa.js → EventsTab-CDFk5d3P.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{EventsTab-CSl9CNXa.js.map → EventsTab-CDFk5d3P.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{HealthTab-CgUm8sp5.js → HealthTab-zFyPJb5b.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{HealthTab-CgUm8sp5.js.map → HealthTab-zFyPJb5b.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{MaintenanceTab-Dyhjzk6G.js → MaintenanceTab-DxJX4lXh.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{MaintenanceTab-Dyhjzk6G.js.map → MaintenanceTab-DxJX4lXh.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{MemoryMapTab-C1YR7CoA.js → MemoryMapTab-CRy5I6mg.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{MemoryMapTab-C1YR7CoA.js.map → MemoryMapTab-CRy5I6mg.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{MetricsTab-Bktg-486.js → MetricsTab-K4kPea0Q.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{MetricsTab-Bktg-486.js.map → MetricsTab-K4kPea0Q.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{OverviewTab-B7qTLQc2.js → OverviewTab-BZoJ1oOv.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{OverviewTab-B7qTLQc2.js.map → OverviewTab-BZoJ1oOv.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{ReposTab-Cr9W3KFw.js → ReposTab-uMFKxT0a.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{ReposTab-Cr9W3KFw.js.map → ReposTab-uMFKxT0a.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{SessionsTab-5x_LL9D8.js → SessionsTab-DDzmcCuH.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{SessionsTab-5x_LL9D8.js.map → SessionsTab-DDzmcCuH.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/SetupTab-KLTE-VKV.js +3 -0
- package/extensions/dashboard-client/dist/assets/{SetupTab-vB72Y7pk.js.map → SetupTab-KLTE-VKV.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{TimeSavedCard-hsMc2BFT.js → TimeSavedCard-D_mBYAzE.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{TimeSavedCard-hsMc2BFT.js.map → TimeSavedCard-D_mBYAzE.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{TurnsTab-CjUIvDlj.js → TurnsTab-C6xr2lsO.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{TurnsTab-CjUIvDlj.js.map → TurnsTab-C6xr2lsO.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{VcStatusBadge-yDtZGtnm.js → VcStatusBadge-J0DVlxH0.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{VcStatusBadge-yDtZGtnm.js.map → VcStatusBadge-J0DVlxH0.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{VectorCortexTab-CvbaaeXD.js → VectorCortexTab-AvL73DpJ.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{VectorCortexTab-CvbaaeXD.js.map → VectorCortexTab-AvL73DpJ.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{WikiTab-c7K7kspY.js → WikiTab-DVcIWjLT.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{WikiTab-c7K7kspY.js.map → WikiTab-DVcIWjLT.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{button-vdqzHHyW.js → button-Cl_gFaIf.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{button-vdqzHHyW.js.map → button-Cl_gFaIf.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{card-DEzbxZLz.js → card-DMzHffVs.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{card-DEzbxZLz.js.map → card-DMzHffVs.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{client-extra-CJe2UKEK.js → client-extra-Dkkppa5C.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{client-extra-CJe2UKEK.js.map → client-extra-Dkkppa5C.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{generateCategoricalChart-Br3cS-GZ.js → generateCategoricalChart-Bi8zQmZN.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{generateCategoricalChart-Br3cS-GZ.js.map → generateCategoricalChart-Bi8zQmZN.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{index-CBMWirAB.js → index-mZRDesSq.js} +3 -3
- package/extensions/dashboard-client/dist/assets/{index-CBMWirAB.js.map → index-mZRDesSq.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{switch-D_uPnF8u.js → switch-K_lsOl6x.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{switch-D_uPnF8u.js.map → switch-K_lsOl6x.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{toggle-DIaGjpNm.js → toggle-67IU2JLn.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{toggle-DIaGjpNm.js.map → toggle-67IU2JLn.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{useSSE-CJOcvXIe.js → useSSE-DiLgyP7C.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{useSSE-CJOcvXIe.js.map → useSSE-DiLgyP7C.js.map} +1 -1
- package/extensions/dashboard-client/dist/index.html +1 -1
- package/extensions/dashboard-client/src/tabs/SetupTab/CortexRuntimeCard.tsx +98 -7
- package/extensions/dashboard-server/api-contracts/setup.ts +13 -0
- package/extensions/dashboard-server/routes-rag-settings-vector-cortex.ts +6 -0
- package/extensions/dashboard-server/routes-setup-enc2budget.ts +171 -0
- package/extensions/dashboard-server/routes-setup.ts +19 -0
- package/package.json +1 -1
- package/src/config/vector-cortex-enc2budget.ts +51 -0
- package/src/config/vector-cortex.ts +6 -0
- package/src/config.ts +4 -0
- package/src/vector-cortex/encoder/decision.ts +37 -6
- package/src/vector-cortex/encoder/runtime-select.ts +25 -23
- package/src/vector-cortex/setup-cortex-blockers-compute.ts +2 -2
- package/extensions/dashboard-client/dist/assets/SetupTab-vB72Y7pk.js +0 -3
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* dashboard-server/routes-setup-enc2budget.ts — ENC-2a operator-configurable
|
|
3
|
+
* native onnxruntime install budget (MiB) Settings read/write + the additive
|
|
4
|
+
* writer branch.
|
|
5
|
+
*
|
|
6
|
+
* Extracted out of routes-setup.ts (which hovers at the 300-line source soft
|
|
7
|
+
* cap, mirroring the ENC-1a/ENC-1b sibling extracts) so the ENC-2a additive
|
|
8
|
+
* read/write of the per-repo `.mega-compact.env` key lives in a sibling impl
|
|
9
|
+
* file. One key is managed here: `MEGACOMPACT_NATIVE_ORT_BUDGET_MIB` — the exact
|
|
10
|
+
* name `installBudgetMib()` (`src/vector-cortex/encoder/decision.ts`) reads at
|
|
11
|
+
* runtime.
|
|
12
|
+
*
|
|
13
|
+
* The write is create-or-append: it upserts the key into the existing per-repo
|
|
14
|
+
* `.mega-compact.env`, preserving every unrelated line and never deleting
|
|
15
|
+
* another key. The read reports the persisted raw string AND the effective
|
|
16
|
+
* integer `installBudgetMib()` resolves to (so the dashboard shows what the
|
|
17
|
+
* runtime will actually use — including the 300 MiB default fallback when the
|
|
18
|
+
* knob is unset or invalid). Reader-only: setter/getter never reimplements
|
|
19
|
+
* `installBudgetMib()`'s clamp rule, it imports it.
|
|
20
|
+
*
|
|
21
|
+
* Guardrails: PREVENT-PI-004 (local filesystem reads/writes only — zero
|
|
22
|
+
* network), PREVENT-001 (null-safe), PREVENT-011 (no `any`).
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
import { writeFileSync, mkdirSync, readFileSync, existsSync } from "node:fs";
|
|
26
|
+
import { join } from "node:path";
|
|
27
|
+
import {
|
|
28
|
+
ENC_2BUDGET_ENABLED,
|
|
29
|
+
ENC_2BUDGET_MAX_MIB,
|
|
30
|
+
ENC_2BUDGET_NATIVE_ORT_BUDGET_ENV,
|
|
31
|
+
} from "../../src/config/vector-cortex.js";
|
|
32
|
+
import {
|
|
33
|
+
installBudgetMib,
|
|
34
|
+
resolveInstallBudgetMib,
|
|
35
|
+
} from "../../src/vector-cortex/encoder/decision.js";
|
|
36
|
+
import type { SetupConfigureRequest } from "./api-contracts/setup.js";
|
|
37
|
+
|
|
38
|
+
function envPath(stateDir: string): string {
|
|
39
|
+
return join(stateDir, ".mega-compact.env");
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** Extract the value of `export MEGACOMPACT_X="..."` (or unquoted) from a line. */
|
|
43
|
+
function lineValue(line: string, key: string): string | null {
|
|
44
|
+
const m = line.match(new RegExp(`^export\\s+${key}=(.*)$`));
|
|
45
|
+
if (!m) return null;
|
|
46
|
+
const rest = m[1].trim();
|
|
47
|
+
if (rest.length === 0) return null;
|
|
48
|
+
const q = rest.match(/^"([^"]*)"$/);
|
|
49
|
+
return q ? q[1] : rest;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** True when the payload carries the ENC-2a key (flag-gated). */
|
|
53
|
+
export function wantsEnc2Budget(body: SetupConfigureRequest): boolean {
|
|
54
|
+
return ENC_2BUDGET_ENABLED() && typeof body.nativeOrtBudgetMib === "string";
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** Read the ENC-2a knob from the per-repo `.mega-compact.env`. Returns the raw
|
|
58
|
+
* persisted string when present, or null when absent. */
|
|
59
|
+
export function readEnc2BudgetEnv(stateDir: string): { raw: string | null } {
|
|
60
|
+
try {
|
|
61
|
+
const p = envPath(stateDir);
|
|
62
|
+
if (!existsSync(p)) return { raw: null };
|
|
63
|
+
const lines = readFileSync(p, "utf8").split(/\r?\n/);
|
|
64
|
+
for (const line of lines) {
|
|
65
|
+
const v = lineValue(line, ENC_2BUDGET_NATIVE_ORT_BUDGET_ENV);
|
|
66
|
+
if (v !== null && v.length > 0) return { raw: v };
|
|
67
|
+
}
|
|
68
|
+
return { raw: null };
|
|
69
|
+
} catch {
|
|
70
|
+
return { raw: null };
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* ENC-2a additive GET status fields. Omitted when flag-off. Surfaces the raw
|
|
76
|
+
* persisted value (when set) AND the effective runtime operand — the integer
|
|
77
|
+
* MiB `installBudgetMib()` actually resolves to. Reading `installBudgetMib()`
|
|
78
|
+
* here (instead of reimplementing the clamp) keeps the dashboard honest when
|
|
79
|
+
* the env var is unset or out-of-range.
|
|
80
|
+
*/
|
|
81
|
+
export function enc2BudgetStatusFields(stateDir: string): {
|
|
82
|
+
nativeOrtBudgetMib?: string;
|
|
83
|
+
nativeOrtBudgetEffectiveMib?: string;
|
|
84
|
+
} {
|
|
85
|
+
if (!ENC_2BUDGET_ENABLED()) return {};
|
|
86
|
+
const { raw } = readEnc2BudgetEnv(stateDir);
|
|
87
|
+
// The EFFECTIVE operand is what the runtime WILL use: if a value has been
|
|
88
|
+
// persisted to the disk file, resolve THAT through the clamp (the operator
|
|
89
|
+
// just POSTed it; the running process has not re-sourced `.mega-compact.env`
|
|
90
|
+
// yet so `installBudgetMib()` reads the stale env). On restart the saved
|
|
91
|
+
// value is what the runtime loads. When nothing is persisted, fall back to
|
|
92
|
+
// the live env var / process.env (= `installBudgetMib()`).
|
|
93
|
+
const effective = raw !== null ? resolveInstallBudgetMib(raw) : installBudgetMib();
|
|
94
|
+
return {
|
|
95
|
+
...(raw !== null ? { nativeOrtBudgetMib: raw } : {}),
|
|
96
|
+
nativeOrtBudgetEffectiveMib: String(effective),
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/** Upsert the ENC-2a knob into the per-repo `.mega-compact.env`. Creates the
|
|
101
|
+
* file if absent; preserves every unrelated line; never deletes other keys.
|
|
102
|
+
* `entries.raw === null` leaves the key's line untouched. */
|
|
103
|
+
export function writeEnc2BudgetEnv(
|
|
104
|
+
stateDir: string,
|
|
105
|
+
entries: { raw?: string | null },
|
|
106
|
+
): string {
|
|
107
|
+
const p = envPath(stateDir);
|
|
108
|
+
const existingLines: string[] = existsSync(p) ? readFileSync(p, "utf8").split(/\r?\n/) : [];
|
|
109
|
+
const out: string[] = [];
|
|
110
|
+
let written = false;
|
|
111
|
+
for (const line of existingLines) {
|
|
112
|
+
if (
|
|
113
|
+
entries.raw !== null &&
|
|
114
|
+
entries.raw !== undefined &&
|
|
115
|
+
lineValue(line, ENC_2BUDGET_NATIVE_ORT_BUDGET_ENV) !== null
|
|
116
|
+
) {
|
|
117
|
+
out.push(`export ${ENC_2BUDGET_NATIVE_ORT_BUDGET_ENV}="${entries.raw}"`);
|
|
118
|
+
written = true;
|
|
119
|
+
continue;
|
|
120
|
+
}
|
|
121
|
+
out.push(line);
|
|
122
|
+
}
|
|
123
|
+
if (entries.raw !== null && entries.raw !== undefined && !written) {
|
|
124
|
+
out.push(`export ${ENC_2BUDGET_NATIVE_ORT_BUDGET_ENV}="${entries.raw}"`);
|
|
125
|
+
}
|
|
126
|
+
mkdirSync(stateDir, { recursive: true });
|
|
127
|
+
writeFileSync(p, out.join("\n"), "utf-8");
|
|
128
|
+
return p;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/** Validate `nativeOrtBudgetMib` as a positive integer string within
|
|
132
|
+
* `ENC_2BUDGET_MAX_MIB`. Returns `null` when valid, else the error code.
|
|
133
|
+
* Exported so the routes host (combined-payload path) and the aggregator share
|
|
134
|
+
* the same rule. */
|
|
135
|
+
export function validateNativeOrtBudgetMib(value: unknown): string | null {
|
|
136
|
+
if (typeof value !== "string" || value.trim().length === 0) return "invalid_native_ort_budget_mib";
|
|
137
|
+
if (!/^\d+$/.test(value)) return "invalid_native_ort_budget_mib";
|
|
138
|
+
const n = Number(value);
|
|
139
|
+
if (!Number.isSafeInteger(n) || n < 1 || n > ENC_2BUDGET_MAX_MIB) {
|
|
140
|
+
return "invalid_native_ort_budget_mib";
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
return null;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* Combined-payload upsert: after the main embedder write has freshly written
|
|
148
|
+
* the per-repo env, append the ENC-2a key when carried alongside a valid
|
|
149
|
+
* embedder selection (flag-gated, additive). No-op when flag-off or no ENC-2a
|
|
150
|
+
* key present.
|
|
151
|
+
*/
|
|
152
|
+
export function tryEnc2BudgetInto(stateDir: string, body: SetupConfigureRequest): void {
|
|
153
|
+
if (!wantsEnc2Budget(body)) return;
|
|
154
|
+
writeEnc2BudgetEnv(stateDir, {
|
|
155
|
+
raw: typeof body.nativeOrtBudgetMib === "string" ? body.nativeOrtBudgetMib : null,
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Combined-path validation: the routes host runs this before the combined
|
|
161
|
+
* upsert when a payload ALSO carries a valid embedder — returned as the error
|
|
162
|
+
* code string, or `null` if validation passes (or the flag is off).
|
|
163
|
+
*/
|
|
164
|
+
export function enc2BudgetValidateCombined(body: SetupConfigureRequest): string | null {
|
|
165
|
+
if (!ENC_2BUDGET_ENABLED()) return null;
|
|
166
|
+
if (body.nativeOrtBudgetMib !== undefined) {
|
|
167
|
+
const e = validateNativeOrtBudgetMib(body.nativeOrtBudgetMib);
|
|
168
|
+
if (e !== null) return e;
|
|
169
|
+
}
|
|
170
|
+
return null;
|
|
171
|
+
}
|
|
@@ -16,6 +16,11 @@ import type { RouteContext } from "./routes-core.js";
|
|
|
16
16
|
import { VC9D_ENABLED } from "../../src/config.js";
|
|
17
17
|
import { enc1aStatusFields, writeEnc1aEnv, tryEnc1aConfigure, wantsEnc1a } from "./routes-setup-enc1a.js";
|
|
18
18
|
import { enc1bStatusFields, tryEnc1bConfigure, tryEnc1bInto, enc1bValidateCombined } from "./routes-setup-enc1b.js";
|
|
19
|
+
import {
|
|
20
|
+
enc2BudgetStatusFields,
|
|
21
|
+
tryEnc2BudgetInto,
|
|
22
|
+
enc2BudgetValidateCombined,
|
|
23
|
+
} from "./routes-setup-enc2budget.js";
|
|
19
24
|
import { writeEmbedderEnv } from "./routes-setup-env-upsert.js";
|
|
20
25
|
import {
|
|
21
26
|
detectOllama,
|
|
@@ -94,6 +99,7 @@ export function handleSetupStatus(
|
|
|
94
99
|
(process.env["MEGACOMPACT_MINILM"] ?? "").trim().toLowerCase(),
|
|
95
100
|
),
|
|
96
101
|
...enc1aStatusFields(ctx.stateDir), ...enc1bStatusFields(ctx.stateDir),
|
|
102
|
+
...enc2BudgetStatusFields(ctx.stateDir),
|
|
97
103
|
};
|
|
98
104
|
// guardrails-allow PREVENT-PI-004: loopback dashboard response (local)
|
|
99
105
|
res.writeHead(200, { "Content-Type": "application/json" });
|
|
@@ -232,6 +238,18 @@ export function handleSetupConfigure(
|
|
|
232
238
|
res.end(JSON.stringify({ error: combinedError }));
|
|
233
239
|
return;
|
|
234
240
|
}
|
|
241
|
+
// ENC-2a combined-payload validation: when a payload carries a valid
|
|
242
|
+
// embedder PLUS the budget key, validate the budget BEFORE the upsert so
|
|
243
|
+
// the combined path is rejected with the same 400 code. Flag-off:
|
|
244
|
+
// enc2BudgetValidateCombined returns null (byte-identical predecessor —
|
|
245
|
+
// the unknown key falls through untouched).
|
|
246
|
+
const budgetCombinedError = enc2BudgetValidateCombined(body);
|
|
247
|
+
if (budgetCombinedError !== null) {
|
|
248
|
+
// guardrails-allow PREVENT-PI-004: loopback dashboard response (local)
|
|
249
|
+
res.writeHead(400, { "Content-Type": "application/json" });
|
|
250
|
+
res.end(JSON.stringify({ error: budgetCombinedError }));
|
|
251
|
+
return;
|
|
252
|
+
}
|
|
235
253
|
const embedder = body.embedder;
|
|
236
254
|
if (embedder !== "ollama" && embedder !== "llama" && embedder !== "trigram" && embedder !== "custom" && embedder !== "onnx") {
|
|
237
255
|
res.writeHead(400, { "Content-Type": "application/json" });
|
|
@@ -281,6 +299,7 @@ export function handleSetupConfigure(
|
|
|
281
299
|
});
|
|
282
300
|
}
|
|
283
301
|
tryEnc1bInto(stateDir, body); // ENC-1b combined upsert (dim/headers/allow-remote/native)
|
|
302
|
+
tryEnc2BudgetInto(stateDir, body); // ENC-2a combined upsert (native budget MiB)
|
|
284
303
|
// Detect if the new config matches what's already active (no restart needed).
|
|
285
304
|
const currentUrl = process.env["MEGACOMPACT_EMBEDDING_URL"];
|
|
286
305
|
const alreadyActive = (resolvedUrl === null && !currentUrl) || (resolvedUrl !== null && currentUrl === resolvedUrl);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-mega-compact",
|
|
3
|
-
"version": "0.20.
|
|
3
|
+
"version": "0.20.53",
|
|
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,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* config/vector-cortex-enc2budget.ts — ENC-2a operator-configurable native
|
|
3
|
+
* onnxruntime install-budget knob (dashboard Settings surface).
|
|
4
|
+
*
|
|
5
|
+
* Sibling of vector-cortex-enc1a.ts / vector-cortex-enc1b.ts so vector-cortex.ts
|
|
6
|
+
* stays under the 300-line soft limit (soft-as-hard gate). vector-cortex.ts
|
|
7
|
+
* re-exports the flag + constants below and root src/config.ts re-exports them,
|
|
8
|
+
* so no consumer import path changes.
|
|
9
|
+
*
|
|
10
|
+
* ENC-2a exposes the runtime's operator knob `MEGACOMPACT_NATIVE_ORT_BUDGET_MIB`
|
|
11
|
+
* as a dashboard Settings field. The knob itself is read at runtime by
|
|
12
|
+
* `installBudgetMib()` (`src/vector-cortex/encoder/decision.ts`) and gates the
|
|
13
|
+
* `budgetOk` decision in `src/vector-cortex/encoder/runtime-select.ts`. Setting
|
|
14
|
+
* it persists to the per-repo `.mega-compact.env` via the same upsert-writer
|
|
15
|
+
* path ENC-1a/ENC-1b use (never the global state dir — see the
|
|
16
|
+
* `statedir-per-repo-vs-global` memory).
|
|
17
|
+
*
|
|
18
|
+
* Bounds (mirror `decision.ts` clamp): positive integer, 1..8192 MiB. Out-of-
|
|
19
|
+
* range input is rejected by validation (400) and falls back to the default
|
|
20
|
+
* (300) in `installBudgetMib()` at runtime. Default 300 MiB was set on
|
|
21
|
+
* 2026-08-07 when the user lifted the prior 80 MiB restriction ("remove the
|
|
22
|
+
* 80mb limit that wasn't my design decision" → "set it to a number that is in
|
|
23
|
+
* the dashboard that defaults to lets say 300mb").
|
|
24
|
+
*
|
|
25
|
+
* `MEGACOMPACT_ENC_2BUDGET=0` disables: no new GET fields, no writer branch, no
|
|
26
|
+
* new Settings rows — byte-identical to the ENC-1b predecessor. The flag MUST
|
|
27
|
+
* also be a dashboard SETTINGS toggle (visible in config UI, never in
|
|
28
|
+
* EXCLUDED_SETTINGS — see `feedback_dashboard-flags-toggleable` memory).
|
|
29
|
+
*
|
|
30
|
+
* Pi-agnostic, dependency-free (PREVENT-PI-004 / PREVENT-011).
|
|
31
|
+
*/
|
|
32
|
+
|
|
33
|
+
import { sprintFlag } from "./vector-cortex-flag.js";
|
|
34
|
+
|
|
35
|
+
/** ENC-2a knob: persisted env name, read by `installBudgetMib()` at runtime. */
|
|
36
|
+
export const ENC_2BUDGET_NATIVE_ORT_BUDGET_ENV = "MEGACOMPACT_NATIVE_ORT_BUDGET_MIB";
|
|
37
|
+
|
|
38
|
+
/** Upper bound on the budget (MiB). Mirrors decision.ts's clamp. */
|
|
39
|
+
export const ENC_2BUDGET_MAX_MIB = 8192;
|
|
40
|
+
|
|
41
|
+
/** Default budget (MiB) when the env var is unset or invalid. */
|
|
42
|
+
export const ENC_2BUDGET_DEFAULT_MIB = 300;
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* ENC-2a — operator-configurable native install budget Settings surface.
|
|
46
|
+
* Default ON. `MEGACOMPACT_ENC_2BUDGET=0` disables and is byte-identical to the
|
|
47
|
+
* ENC-1b predecessor: no new GET fields, no writer branch, no new Settings rows.
|
|
48
|
+
* This flag MUST also be a dashboard SETTINGS toggle (visible in config UI,
|
|
49
|
+
* never in EXCLUDED_SETTINGS).
|
|
50
|
+
*/
|
|
51
|
+
export const ENC_2BUDGET_ENABLED = (): boolean => sprintFlag("MEGACOMPACT_ENC_2BUDGET");
|
|
@@ -71,6 +71,12 @@ export {
|
|
|
71
71
|
ENC_1B_ALLOW_REMOTE_EMBEDDER_ENV,
|
|
72
72
|
ENC_1B_ENCODER_NATIVE_ENV,
|
|
73
73
|
} from "./vector-cortex-enc1b.js";
|
|
74
|
+
export {
|
|
75
|
+
ENC_2BUDGET_ENABLED,
|
|
76
|
+
ENC_2BUDGET_NATIVE_ORT_BUDGET_ENV,
|
|
77
|
+
ENC_2BUDGET_MAX_MIB,
|
|
78
|
+
ENC_2BUDGET_DEFAULT_MIB,
|
|
79
|
+
} from "./vector-cortex-enc2budget.js";
|
|
74
80
|
// Breaker constants (TRIAD_RESILIENCE.md §breaker) extracted to vector-cortex-breakers.ts.
|
|
75
81
|
export {
|
|
76
82
|
BREAKER_WINDOW_MS,
|
package/src/config.ts
CHANGED
|
@@ -198,6 +198,10 @@ export {
|
|
|
198
198
|
ENC_0G_ENABLED,
|
|
199
199
|
ENC_1A_ENABLED,
|
|
200
200
|
ENC_1B_ENABLED,
|
|
201
|
+
ENC_2BUDGET_ENABLED,
|
|
202
|
+
ENC_2BUDGET_NATIVE_ORT_BUDGET_ENV,
|
|
203
|
+
ENC_2BUDGET_MAX_MIB,
|
|
204
|
+
ENC_2BUDGET_DEFAULT_MIB,
|
|
201
205
|
BREAKER_WINDOW_MS,
|
|
202
206
|
BREAKER_MIN_ATTEMPTS,
|
|
203
207
|
BREAKER_PERF_FAILURES,
|
|
@@ -3,9 +3,10 @@
|
|
|
3
3
|
*
|
|
4
4
|
* The durable EncoderBackendDecisionV1 record: which ONNX runtime backend the
|
|
5
5
|
* real learned encoder ships on (transformers.js/WASM vs onnxruntime-node
|
|
6
|
-
* native), whether the
|
|
7
|
-
*
|
|
8
|
-
* the
|
|
6
|
+
* native), whether the configurable install budget holds (default 300 MiB;
|
|
7
|
+
* operator-overridable via `MEGACOMPACT_NATIVE_ORT_BUDGET_MIB`), the per-platform
|
|
8
|
+
* install matrix, the opset baseline (locked 21 by ENC-0a), the license
|
|
9
|
+
* verdict, and the pinned model/tokenizer sha256 digests.
|
|
9
10
|
*
|
|
10
11
|
* ENC-0a is the DECISION + MEASUREMENT sprint: this contract is what the
|
|
11
12
|
* deterministic resolver (`scripts/encoder/resolve-backend-decision.mjs`) and
|
|
@@ -83,10 +84,40 @@ export interface EncoderBackendDecisionV1 {
|
|
|
83
84
|
}
|
|
84
85
|
|
|
85
86
|
/**
|
|
86
|
-
* The
|
|
87
|
-
*
|
|
87
|
+
* The operator-configurable native-ort install byte-budget (MiB). Default 300
|
|
88
|
+
* (shipped 5-platform ~160 MiB comfortably fits); override via
|
|
89
|
+
* `MEGACOMPACT_NATIVE_ORT_BUDGET_MIB`. Safe upper clamp `INSTALL_BUDGET_CLAMP_MIB`
|
|
90
|
+
* rejects absurd values. Backend qualifies (`budgetOk`) iff the shipped
|
|
91
|
+
* byte-count fits the configured budget.
|
|
88
92
|
*/
|
|
89
|
-
export const
|
|
93
|
+
export const INSTALL_BUDGET_CLAMP_MIB = 8192;
|
|
94
|
+
export const INSTALL_BUDGET_DEFAULT_MIB = 300;
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Pure resolver: given a raw string (or null/undefined when the env var is
|
|
98
|
+
* unset), return the integer budget the runtime will use. Out-of-range /
|
|
99
|
+
* non-integer / empty input falls back to the default. Exported so the
|
|
100
|
+
* dashboard Settings surface can compute the EFFECTIVE operand from a
|
|
101
|
+
* persisted-but-not-yet-env-loaded value (the operator just POSTed a new
|
|
102
|
+
* budget to disk; the running process has not sourced `.mega-compact.env`,
|
|
103
|
+
* so `installBudgetMib()` reads the stale env, but the dashboard should show
|
|
104
|
+
* what the runtime WILL use after the restart the dashboard itself tells the
|
|
105
|
+
* operator is required).
|
|
106
|
+
*/
|
|
107
|
+
export function resolveInstallBudgetMib(
|
|
108
|
+
raw: string | null | undefined,
|
|
109
|
+
): number {
|
|
110
|
+
if (raw === undefined || raw === null || raw === "") return INSTALL_BUDGET_DEFAULT_MIB;
|
|
111
|
+
const n = Number(raw);
|
|
112
|
+
if (!Number.isInteger(n) || n <= 0 || n > INSTALL_BUDGET_CLAMP_MIB) {
|
|
113
|
+
return INSTALL_BUDGET_DEFAULT_MIB;
|
|
114
|
+
}
|
|
115
|
+
return n;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
export function installBudgetMib(): number {
|
|
119
|
+
return resolveInstallBudgetMib(process.env.MEGACOMPACT_NATIVE_ORT_BUDGET_MIB);
|
|
120
|
+
}
|
|
90
121
|
|
|
91
122
|
/** The p95 latency gate at 512 tokens / 4 threads on linux-x64 (ms). */
|
|
92
123
|
export const ENCODER_DECISION_P95_MS = 40;
|
|
@@ -25,6 +25,7 @@ import {
|
|
|
25
25
|
} from "./types.js";
|
|
26
26
|
import type { BenchResultV1 } from "./bench-export.js";
|
|
27
27
|
import { ML5C_ENABLED, ENC_0E_ENABLED } from "../../config/vector-cortex.js";
|
|
28
|
+
import { installBudgetMib } from "./decision.js";
|
|
28
29
|
import type { EncoderPlatformRow } from "./decision.js";
|
|
29
30
|
import {
|
|
30
31
|
DARWIN_X64_DEMOTION_REASON,
|
|
@@ -53,7 +54,7 @@ export interface RuntimeSelectionInput {
|
|
|
53
54
|
export interface RuntimeSelectionResult {
|
|
54
55
|
/** The chosen backend. */
|
|
55
56
|
readonly backend: RuntimeBackendChoice;
|
|
56
|
-
/** HG-3 closure state: whether the
|
|
57
|
+
/** HG-3 closure state: whether the operator-configured install budget (`MEGACOMPACT_NATIVE_ORT_BUDGET_MIB`, default 300 MiB) is satisfied. */
|
|
57
58
|
readonly budgetOk: boolean;
|
|
58
59
|
/** The measured p95 (ms) that drove the decision, from BenchResultV1. */
|
|
59
60
|
readonly p95Ms: number | null;
|
|
@@ -69,17 +70,14 @@ export interface RuntimeSelectionResult {
|
|
|
69
70
|
readonly demotionReason: string | null;
|
|
70
71
|
}
|
|
71
72
|
|
|
72
|
-
/** The 80 MiB install budget in bytes (the HG-3 ceiling, unamended). */
|
|
73
|
-
export const RUNTIME_NATIVE_INSTALL_BUDGET_MIB = 80;
|
|
74
|
-
|
|
75
73
|
/**
|
|
76
74
|
* Per-platform optionalDependency footprint of onnxruntime-node (MiB, approx).
|
|
77
75
|
* These sum to ~160 MiB SHIPPED in the npm package (every target platform is
|
|
78
|
-
* included so the resolver lands on a concrete row at install time)
|
|
79
|
-
*
|
|
80
|
-
*
|
|
81
|
-
*
|
|
82
|
-
*
|
|
76
|
+
* included so the resolver lands on a concrete row at install time). Compared
|
|
77
|
+
* against the configurable install budget (`installBudgetMib()`, default 300
|
|
78
|
+
* MiB) to set `budgetOk` — the per-host INSTALLED footprint (one row only,
|
|
79
|
+
* 28–35 MiB) is irrelevant to this ceiling; the budget covers the shipped
|
|
80
|
+
* tarball, not the single-platform install.
|
|
83
81
|
*/
|
|
84
82
|
export const NATIVE_FOOTPRINT_MIB: Readonly<Record<EncoderPlatform, number>> = {
|
|
85
83
|
"linux-x64": 33,
|
|
@@ -132,41 +130,43 @@ export function selectRuntimeBackend(input: RuntimeSelectionInput): RuntimeSelec
|
|
|
132
130
|
}
|
|
133
131
|
|
|
134
132
|
// Native opt-in short-circuits: operator explicitly wants the native path.
|
|
135
|
-
// The
|
|
136
|
-
//
|
|
137
|
-
//
|
|
138
|
-
//
|
|
139
|
-
//
|
|
133
|
+
// The budget compares the SHIPPED byte-count (sum across every platform row
|
|
134
|
+
// in the package's optionalDependencies map) against the configurable
|
|
135
|
+
// `installBudgetMib()` ceiling (default 300 MiB; operator-overridable). At
|
|
136
|
+
// the default, shipped ~160 MiB fits — budgetOk:true. The operator may lower
|
|
137
|
+
// it (e.g. 100) to surface a budget breach in `budgetOk:false` and the
|
|
138
|
+
// rationale string; the decision rule does not gate on it.
|
|
140
139
|
if (input.nativeOptIn) {
|
|
141
140
|
const shippedMib = Object.values(NATIVE_FOOTPRINT_MIB).reduce((a, b) => a + b, 0);
|
|
141
|
+
const budgetMib = installBudgetMib();
|
|
142
142
|
return {
|
|
143
143
|
backend: "native",
|
|
144
|
-
budgetOk: shippedMib <=
|
|
144
|
+
budgetOk: shippedMib <= budgetMib,
|
|
145
145
|
p95Ms: input.benchRecord?.p95Ms ?? null,
|
|
146
146
|
platform: input.platform,
|
|
147
|
-
rationale: `native opt-in (MEGACOMPACT_ENCODER_NATIVE=1); shipped ${shippedMib} MiB across 5 platforms
|
|
147
|
+
rationale: `native opt-in (MEGACOMPACT_ENCODER_NATIVE=1); shipped ${shippedMib} MiB across 5 platforms vs ${budgetMib} MiB budget`,
|
|
148
148
|
demotionReason: null,
|
|
149
149
|
};
|
|
150
150
|
}
|
|
151
151
|
|
|
152
152
|
// No bench record or degraded (gates.all:false) → WASM cannot qualify (the
|
|
153
153
|
// placeholder 42-byte asset has no measured real p95), so native is selected
|
|
154
|
-
// with the SAME
|
|
155
|
-
// evidence records the closed HG-3 amendment.
|
|
154
|
+
// with the SAME budget comparison as the opt-in path above (configurable).
|
|
156
155
|
if (!input.benchRecord || !input.benchRecord.gates.all || input.benchRecord.p95Ms === null) {
|
|
157
156
|
const shippedMib = Object.values(NATIVE_FOOTPRINT_MIB).reduce((a, b) => a + b, 0);
|
|
157
|
+
const budgetMib = installBudgetMib();
|
|
158
158
|
return {
|
|
159
159
|
backend: "native",
|
|
160
|
-
budgetOk:
|
|
160
|
+
budgetOk: shippedMib <= budgetMib,
|
|
161
161
|
p95Ms: input.benchRecord?.p95Ms ?? null,
|
|
162
162
|
platform: input.platform,
|
|
163
|
-
rationale: `no qualifying bench record — native fallback
|
|
163
|
+
rationale: `no qualifying bench record — native fallback (shipped ${shippedMib} MiB vs ${budgetMib} MiB budget)`,
|
|
164
164
|
demotionReason: null,
|
|
165
165
|
};
|
|
166
166
|
}
|
|
167
167
|
|
|
168
168
|
// The decision rule: WASM iff p95 <= 40 ms (linux-x64, 512 tokens, 4 threads) —
|
|
169
|
-
// native required otherwise, with the same budget
|
|
169
|
+
// native required otherwise, with the same configurable budget comparison.
|
|
170
170
|
if (input.benchRecord.p95Ms <= ENCODER_LATENCY_P95_MS) {
|
|
171
171
|
return {
|
|
172
172
|
backend: "wasm",
|
|
@@ -178,12 +178,14 @@ export function selectRuntimeBackend(input: RuntimeSelectionInput): RuntimeSelec
|
|
|
178
178
|
};
|
|
179
179
|
}
|
|
180
180
|
|
|
181
|
+
const shippedMib = Object.values(NATIVE_FOOTPRINT_MIB).reduce((a, b) => a + b, 0);
|
|
182
|
+
const budgetMib = installBudgetMib();
|
|
181
183
|
return {
|
|
182
184
|
backend: "native",
|
|
183
|
-
budgetOk:
|
|
185
|
+
budgetOk: shippedMib <= budgetMib,
|
|
184
186
|
p95Ms: input.benchRecord.p95Ms,
|
|
185
187
|
platform: input.platform,
|
|
186
|
-
rationale: `native required: p95 ${input.benchRecord.p95Ms}ms > ${ENCODER_LATENCY_P95_MS}ms on WASM`,
|
|
188
|
+
rationale: `native required: p95 ${input.benchRecord.p95Ms}ms > ${ENCODER_LATENCY_P95_MS}ms on WASM (shipped ${shippedMib} MiB vs ${budgetMib} MiB budget)`,
|
|
187
189
|
demotionReason: null,
|
|
188
190
|
};
|
|
189
191
|
}
|
|
@@ -85,11 +85,11 @@ export const SETUP_CORTEX_BLOCKERS: readonly SetupCortexBlockerV1[] = [
|
|
|
85
85
|
},
|
|
86
86
|
{
|
|
87
87
|
id: "HG-3",
|
|
88
|
-
title: "onnxruntime-node install
|
|
88
|
+
title: "native onnxruntime-node install path unresolved (needs operator install + probe), currently demoted to WASM",
|
|
89
89
|
severity: "blocker",
|
|
90
90
|
status: "open",
|
|
91
91
|
resolution:
|
|
92
|
-
"onnxruntime-node
|
|
92
|
+
"operator-run install of the pinned onnxruntime-node version into ~/.pi/mega-compact/native-ort, then re-run the ENC-0f qualification gate. The install byte-budget is operator-configurable (MEGACOMPACT_NATIVE_ORT_BUDGET_MIB, default 300 MiB; shipped 5-platform ~160 MiB fits at the default).",
|
|
93
93
|
},
|
|
94
94
|
{
|
|
95
95
|
id: "HG-4",
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import{r as s,j as e,h as L,i as X,k as K,p as te,l as se,m as ne,C as re,n as ae,o as oe,q as le,s as J,t as Q,v as ie}from"./index-CBMWirAB.js";import{S as ce}from"./switch-D_uPnF8u.js";import{f as de,p as me,d as ue}from"./client-extra-CJe2UKEK.js";import{V as he}from"./VcStatusBadge-yDtZGtnm.js";import{T as fe}from"./toggle-DIaGjpNm.js";function ge(t){try{return new Date(t*1e3).toLocaleString()}catch{return"—"}}function Y({achievements:t}){const a=s.useRef(0),[n,l]=s.useState(null),r=t.reduce((c,d)=>Math.max(c,d.unlocked_at??0),0),i=a.current;s.useEffect(()=>{r>a.current&&(a.current=r)},[r]),s.useEffect(()=>{if(i>0&&r>i){const c=t.filter(d=>d.unlocked_at!=null&&(d.unlocked_at??0)>i);if(c.length>0){const d=c.map(m=>`${m.icon??""} ${m.title}`.trim()).join(", ")+" unlocked!";l(d);const x=setTimeout(()=>l(null),4e3);return()=>clearTimeout(x)}}},[t,r,i]);const u=t.filter(c=>!(c.hidden===1&&c.unlocked_at==null));return e.jsxs("div",{className:"ach-section",children:[n!=null&&e.jsx("div",{className:"ach-toast show",children:n}),e.jsxs("div",{className:"ach-tiles",children:[u.length===0&&e.jsx("span",{className:"repo-none",children:"no achievements yet"}),u.map(c=>{if(c.unlocked_at!=null){const d=i>0&&(c.unlocked_at??0)>i;return e.jsxs("div",{className:`ach-tile unlocked${d?" just-unlocked":""}`,children:[c.icon??""," ",c.title,e.jsxs("span",{className:"ach-detail",children:["unlocked ",ge(c.unlocked_at)]})]},c.id)}return e.jsxs("div",{className:"ach-tile locked",children:["??? ",c.title]},c.id)})]})]})}function P(t){return(Math.round(t*10)/10).toString()+"%"}function W(t){return t!=null?new Date(t).toLocaleString():"—"}function F(t){return t&&typeof t=="object"?t:{}}function xe(t){return t.split("/").pop()||t}function D({title:t,rows:a,badge:n,renderValue:l}){return e.jsxs("div",{className:"lb-card",children:[e.jsxs("h3",{children:[t,n]}),a.length===0?e.jsx("div",{className:"lb-empty",children:"—"}):e.jsx("table",{children:e.jsx("tbody",{children:a.map((r,i)=>e.jsxs("tr",{children:[e.jsx("td",{title:r.repo_root,children:xe(r.repo_root)}),e.jsx("td",{className:"num",children:l(r)})]},`${r.repo_root}-${i}`))})})]})}function pe(){const[t,a]=s.useState({}),[n,l]=s.useState(0),[r,i]=s.useState([]),[u,c]=s.useState(!1),[d,x]=s.useState(!0),[m,h]=s.useState(null),o=s.useRef(0),f=s.useCallback(async()=>{try{const[b,p,C,T,$,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}),X()]),O=T.find(B=>B.ts>o.current&&B.value>100);o.current>0&&O&&(h(`oopsie! cache went to ${Math.round(O.value)}% — MEGA CACHE 🥧`),setTimeout(()=>h(null),4e3)),T.length>0&&(o.current=Math.max(...T.map(B=>B.ts))),a({cache:b,dedupe:p,turns:C,mega_cache:T}),l($[0]?.value??0),i(U)}catch{}finally{x(!1)}},[]);s.useEffect(()=>{let b=!0;const p=async()=>{b&&await f()};p();const C=setInterval(()=>void p(),15e3);return()=>{b=!1,clearInterval(C)}},[f]),s.useEffect(()=>{let b=!0;const p=async()=>{try{const T=await K();b&&(c(!!T.game_mode_on),T.theme&&(document.documentElement.dataset.theme=T.theme))}catch{}};p();const C=setInterval(()=>void p(),15e3);return()=>{b=!1,clearInterval(C)}},[]);const j=t.mega_cache??[];let v=null,w=null;for(const b of j){(v==null||b.value>v)&&(v=b.value);const p=F(b.meta),C=p.firstSeenTs??p.firstSeen??b.ts;(w==null||C<w)&&(w=C)}const k=v!=null&&v>100,S=t.turns??[],A=S.reduce((b,p)=>Math.max(b,p.value),0),N=Math.floor(Math.log2(A+1))+1,E=(t.cache?.length??0)>0||(t.dedupe?.length??0)>0||S.length>0||j.length>0||n>0;return e.jsxs("div",{className:`game-tab${u?" game-mode-on":""}`,children:[m!=null&&e.jsx("div",{className:"mega-cache-toast show",children:m}),k&&e.jsxs("div",{className:"mega-cache-banner",children:["🥧"," MEGA CACHE! peak ",P(v)," — first reached ",W(w)]}),k&&e.jsxs("div",{className:"achievement-tile unlocked",children:["🏆"," Opie's Wild Ride",e.jsxs("span",{className:"ach-detail",children:["best ",P(v)," · first ",W(w)]})]}),e.jsx("h2",{children:"High Scores"}),!E&&!d&&e.jsx("div",{className:"game-empty",children:"No scores yet — run a session with game mode on."}),E&&e.jsxs("div",{className:"game-leaderboards",children:[e.jsx(D,{title:"Cache %",rows:t.cache??[],renderValue:b=>P(b.value)}),e.jsx(D,{title:"Dedupe (collapsed)",rows:t.dedupe??[],renderValue:b=>b.value.toLocaleString()}),e.jsx(D,{title:"Turns",rows:S,badge:S.length>0?e.jsxs("span",{className:"lvl-badge",children:["LVL ",N]}):void 0,renderValue:b=>b.value.toLocaleString()}),e.jsx(D,{title:"MEGA CACHE trophies",rows:j,renderValue:b=>e.jsxs(e.Fragment,{children:[P(b.value),e.jsx("span",{className:"lb-meta",children:W(F(b.meta).firstSeenTs??F(b.meta).firstSeen??b.ts)})]})})]}),n>0&&e.jsx("div",{className:"repos-badge-line",children:e.jsxs("span",{className:"repos-badge",children:[n," repos"]})}),e.jsx("h3",{children:"Achievements"}),e.jsx(Y,{achievements:r})]})}function be(){const[t,a]=s.useState([]),[n,l]=s.useState(!0),[r,i]=s.useState(null),u=s.useCallback(async()=>{try{const c=await X();a(c),i(null)}catch(c){i(c instanceof Error?c:new Error(String(c)))}finally{l(!1)}},[]);return s.useEffect(()=>{let c=!0;const d=async()=>{c&&await u()};d();const x=setInterval(()=>void d(),15e3);return()=>{c=!1,clearInterval(x)}},[u]),n&&t.length===0?e.jsx("div",{className:"tab-stub",children:"Loading achievements…"}):r&&t.length===0?e.jsxs("div",{className:"tab-stub",children:["Error: ",r.message]}):e.jsxs("div",{className:"achievements-tab",children:[e.jsx("h2",{children:"Achievements"}),e.jsx(Y,{achievements:t})]})}const Z=[{id:"transparent",label:"Transparent (accents only)",css:{bg:null,fg:"#c9d1d9",accent:"#3fb950",mega:"#f0883e"},ansi:{bg:null,fg:"39",accent:"32",mega:"33"}},{id:"retro",label:"Retro 8-bit green",css:{bg:"#003300",fg:"#33ff33",accent:"#00ff41",mega:"#39ff14"},ansi:{bg:"40",fg:"92",accent:"92",mega:"1;92"}},{id:"orange-bold",label:"Orange bold",css:{bg:"#1a0f00",fg:"#ff8c00",accent:"#ff6b00",mega:"#ff4500"},ansi:{bg:"48;5;52",fg:"38;5;208",accent:"38;5;208",mega:"1;38;5;202"}},{id:"cyan-neon",label:"Cyan neon",css:{bg:"#001a1a",fg:"#00ffff",accent:"#22d3ee",mega:"#7df9ff"},ansi:{bg:"48;5;23",fg:"38;5;51",accent:"38;5;51",mega:"1;38;5;51"}},{id:"amber-mono",label:"Amber phosphor",css:{bg:"#1a1200",fg:"#ffb000",accent:"#ff8c00",mega:"#ff5500"},ansi:{bg:"48;5;58",fg:"38;5;214",accent:"38;5;214",mega:"1;38;5;208"}},{id:"grayscale",label:"Grayscale minimal",css:{bg:"#161616",fg:"#b0b0b0",accent:"#8b949e",mega:"#e6edf3"},ansi:{bg:"48;5;235",fg:"38;5;249",accent:"38;5;249",mega:"1;38;5;255"}}],H=Z.map(t=>t.id),R={gameMode:"Turn game mode on/off (themes the widget + dashboard)",theme:"Visual theme (applies instantly)",tuiMode:"TUI widget display density",tier:"Live pressure band — climbs low→mega as context fills the window.",preset:"The env-resolved base compaction preset (low/medium/high/ultra/mega) that set the token threshold.",pressure:"Live pressure = currentTokens / threshold — % of the model context window (threshold fires at the tier's % of window).",threshold:"Compaction threshold = tierPct × model context window — mega-compact trims BELOW pi's native ~80% auto-compact for any model size.",fastGate:"Fast-gate arming floor — the live trim arms once context passes this % of the window."};function je(t,a,n){let l=t.toLocaleString();return a!=null&&n>0&&(l+=` (${Math.round(a*100)}% of ${n.toLocaleString()})`),l}function ye(t){return`${Math.round((t||0)*100)}%`}function ve(){const[t,a]=s.useState(null),[n,l]=s.useState(null),[r,i]=s.useState(!1);s.useEffect(()=>{let o=!0;const f=async()=>{try{const v=await se();o&&a(v)}catch{}};f();const j=setInterval(()=>void f(),5e3);return()=>{o=!1,clearInterval(j)}},[]),s.useEffect(()=>{let o=!0;const f=async()=>{try{const v=await K();o&&(l(v),v.theme&&(document.documentElement.dataset.theme=v.theme))}catch{}};f();const j=setInterval(()=>void f(),5e3);return()=>{o=!1,clearInterval(j)}},[]);const u=s.useCallback(async o=>{i(!0);try{const f=await te(o);l(f),f.theme&&(document.documentElement.dataset.theme=f.theme)}catch{}i(!1)},[]),c=n?.game_mode_on??!1,d=n?.theme??"transparent",x=n?.tui_display_mode??"full",m=t?.config,h=t?.context.contextWindow??0;return e.jsxs("div",{className:"config-tab",children:[e.jsxs("section",{className:"config-settings",children:[e.jsx("h3",{children:"Settings"}),e.jsx("div",{className:"settings-row",children:e.jsxs("label",{title:R.gameMode,children:[e.jsx("input",{type:"checkbox",checked:c,onChange:o=>u({game_mode_on:o.currentTarget.checked}),disabled:r}),"Game Mode"]})}),e.jsx("div",{className:"settings-row",children:e.jsxs("label",{title:R.theme,children:["Theme",e.jsx("select",{value:d,onChange:o=>u({theme:o.currentTarget.value}),disabled:r,children:Z.map(o=>e.jsx("option",{value:o.id,children:o.label},o.id))}),e.jsx("button",{type:"button",disabled:r,className:"theme-cycle-btn",title:"Cycle to the next theme (P3)",onClick:()=>{const o=H.indexOf(d),f=H[(o<0?0:o+1)%H.length];f&&u({theme:f})},children:"Next theme →"})]})}),e.jsx("div",{className:"settings-row",children:e.jsxs("label",{title:R.tuiMode,children:["TUI Mode",e.jsxs("select",{value:x,onChange:o=>u({tui_display_mode:o.currentTarget.value}),disabled:r,children:[e.jsx("option",{value:"full",children:"Full"}),e.jsx("option",{value:"minimal",children:"Minimal"})]})," ",e.jsx("span",{className:"tui-mode-hint",children:"(affects the in-app TUI widget; not shown here)"})]})})]}),e.jsxs("section",{className:"config-display",children:[e.jsx("h3",{children:"Configuration"}),e.jsxs("div",{className:"config-grid",children:[e.jsxs("div",{className:"config-item",children:[e.jsx("span",{className:"config-label",title:R.tier,children:"Tier"}),e.jsx("span",{className:"config-value",children:t?`${t.tier} (live)`:"—"})]}),e.jsxs("div",{className:"config-item",children:[e.jsx("span",{className:"config-label",title:R.preset,children:"Preset"}),e.jsx("span",{className:"config-value",children:t?.presetTier??"—"})]}),e.jsxs("div",{className:"config-item",children:[e.jsx("span",{className:"config-label",title:R.pressure,children:"Pressure"}),e.jsx("span",{className:"config-value",children:t?ye(t.pressure):"—"})]}),e.jsxs("div",{className:"config-item",children:[e.jsx("span",{className:"config-label",title:R.threshold,children:"Threshold"}),e.jsx("span",{className:"config-value",children:m?je(m.thresholdTokens,m.tierPct,h):"—"})]}),e.jsxs("div",{className:"config-item",children:[e.jsx("span",{className:"config-label",title:R.fastGate,children:"Fast Gate"}),e.jsx("span",{className:"config-value",children:m?`${m.fastGatePct}%`:"—"})]}),e.jsxs("div",{className:"config-item",children:[e.jsx("span",{className:"config-label",children:"Auto"}),e.jsx("span",{className:"config-value",children:m?m.auto?"enabled":"disabled":"—"})]}),e.jsxs("div",{className:"config-item",children:[e.jsx("span",{className:"config-label",children:"Anchor"}),e.jsx("span",{className:"config-value",children:m?.anchorUserMessages??"—"})]})]})]})]})}const M={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,a]=s.useState(null),[n,l]=s.useState(null),r=s.useCallback(()=>{ne().then(a).catch(x=>l(x instanceof Error?x.message:String(x)))},[]);s.useEffect(()=>{r()},[r]),s.useEffect(()=>{const x=setInterval(r,3e4);return()=>clearInterval(x)},[r]);const i=t?.status==="ok",u=t?.status==="ok"?"Working":t?.status==="unreachable"?"Unreachable":"Error",c=i?"#4caf50":"#f44336",d=i?"✓":"✗";return e.jsxs("div",{style:M.section,children:[e.jsx("h3",{style:M.sectionTitle,children:"Embedder Health"}),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:"Probing embedder..."}),t&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{style:M.row,children:[e.jsxs("span",{style:{...M.label,color:`${c}`},children:[d," ",u,":"]}),e.jsxs("span",{style:M.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:M.row,children:[e.jsx("span",{style:M.label,children:"Endpoint:"}),e.jsx("span",{style:M.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:a}){const[n,l]=s.useState(!0),r=`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:()=>l(i=>!i),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":n,"aria-controls":r,children:[e.jsx("span",{children:t}),e.jsx(re,{className:ae("h-4 w-4 text-muted-foreground transition-transform",n&&"rotate-180"),"aria-hidden":"true"})]}),n&&e.jsx("div",{id:r,className:"divide-y divide-border px-4 py-1",children:a})]})}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 Ne(){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 Ce({setting:t,id:a,llmActive:n,saving:l,onUpdate:r}){const[i,u]=s.useState(null),c=t.requiresLlm&&!n,d=s.useRef(null);s.useEffect(()=>()=>{d.current&&clearTimeout(d.current)},[]);const x=s.useCallback(o=>{r(t.key,o).then(f=>u(f)).catch(f=>u(f instanceof Error?f.message:String(f)))},[r,t.key]),m=s.useCallback(o=>{d.current&&clearTimeout(d.current),d.current=setTimeout(()=>x(o),500)},[x]),h=l||c;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:`${a}-input`,className:"cursor-pointer",children:t.label}),t.requiresLlm&&!n&&e.jsx(Ne,{})]}),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(ce,{id:`${a}-input`,checked:!!t.value,disabled:h||c,onCheckedChange:o=>x(String(o)),"aria-label":t.label}):e.jsxs(e.Fragment,{children:[e.jsx("input",{id:`${a}-input`,type:t.type==="number"?"number":"text",defaultValue:String(t.value??""),min:t.min,max:t.max,disabled:h,onChange:o=>m(o.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})]})})]}),i&&e.jsxs("p",{className:"mt-1 text-xs text-danger",children:["Error: ",i]})]})}function Ee(){const[t,a]=s.useState(null),[n,l]=s.useState(null),[r,i]=s.useState(!1),[u,c]=s.useState(null),d=s.useCallback(()=>{oe().then(a).catch(m=>l(m instanceof Error?m.message:String(m)))},[]);s.useEffect(()=>{d()},[d]);const x=s.useCallback(async(m,h)=>{i(!0);try{const o=await le({key:m,value:h});return c(o.restartRequired?"Saved — restart pi to apply changes.":"Saved."),d(),null}catch(o){return o instanceof Error?o.message:String(o)}finally{i(!1)}},[d]);return e.jsxs("div",{className:"flex flex-col gap-3",children:[n&&e.jsxs("p",{className:"text-sm text-danger",children:["Error: ",n]}),!t&&!n&&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(h=>e.jsx(Ce,{setting:h,id:`${m.name.replace(/[^a-z0-9]+/gi,"-")}-${h.key}`,llmActive:t.llmActive,saving:r,onUpdate:x},h.key))},m.name)),u&&e.jsx("div",{className:"mt-1 rounded-md border border-warning/40 bg-warning/10 p-2 text-xs text-warning",role:"status",children:u})]})}const g={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:a,applyEmbedder:n,configuring:l,inputEnabled:r,apiKeySet:i,embeddingDim:u,embeddingHeadersSet:c,allowRemoteEmbedder:d,configureResult:x,configureError:m}){const[h,o]=s.useState(""),[f,j]=s.useState(""),[v,w]=s.useState(!1),[k,S]=s.useState(""),[A,N]=s.useState(!1),[E,b]=s.useState(!1);return r&&!v&&typeof u=="string"&&(j(u),w(!0)),r&&!E&&typeof d=="boolean"&&(N(d),b(!0)),e.jsxs("div",{style:g.section,children:[e.jsx("h3",{style:g.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=>a(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"}}),r&&e.jsx("input",{type:"password",autoComplete:"new-password","aria-label":"API key (optional Bearer)",placeholder:"API key (optional Bearer)",value:h,onChange:p=>o(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"}}),r&&i&&e.jsx("span",{style:{fontSize:"0.75rem",color:"#81c784",border:"1px solid #2a4e2a",borderRadius:"4px",padding:"0.15rem 0.45rem"},children:"API key saved"}),r&&c&&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:{...g.button,opacity:t?1:.4},onClick:()=>n("custom",t,h,f,k,A),disabled:!t||l!==null,children:l==="custom"?"Writing...":"Use Custom URL"})]}),r&&e.jsxs("div",{style:{marginTop:"0.75rem"},children:[e.jsxs("div",{style:{marginBottom:"0.5rem"},children:[e.jsx("label",{style:{...g.label,display:"block",marginBottom:"0.25rem"},children:"Embedding dim (optional)"}),e.jsx("input",{type:"number",min:1,placeholder:"e.g. 384",value:f,onChange:p=>j(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:{...g.label,display:"block",marginBottom:"0.25rem"},children:"Embedding headers (JSON, write-only — never re-displayed)"}),e.jsx("textarea",{placeholder:'{"Authorization": "Bearer ..."}',value:k,onChange:p=>S(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:A,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]}),x!==null&&x.embedder==="custom"&&e.jsx("div",{style:g.warning,children:Te}),e.jsxs("div",{style:g.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 q(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 Me(t){return t?.currentEmbedder!=="trigram"?null:e.jsxs("div",{style:g.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 a=t?"#1a5a1a":"#3a1a1a",n=t?"#4caf50":"#f44336";return e.jsx("span",{style:{...g.badge,background:a,color:n},children:t?"Detected":"Not found"})}function ze({status:t,statusError:a}){return e.jsxs("div",{style:g.section,children:[e.jsx("h3",{style:g.sectionTitle,children:"Current Embedder Configuration"}),a&&e.jsxs("p",{style:{color:"#f44336",fontSize:"0.85rem"},children:["Error: ",a]}),t&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{style:g.row,children:[e.jsx("span",{style:g.label,children:"Active Embedder:"}),e.jsx("span",{style:g.value,children:q(t.currentEmbedder)})]}),"configuredEmbedder"in t&&t.configuredEmbedder!==t.currentEmbedder&&e.jsxs("div",{style:g.warning,children:[e.jsx("strong",{children:"Configured but not active:"})," ",q(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:{...g.row,color:"#ff9800"},children:[e.jsx("span",{style:g.label,children:"Status:"}),e.jsx("span",{style:g.value,children:"Restart required to activate the configured embedder"})]}),e.jsxs("div",{style:g.row,children:[e.jsx("span",{style:g.label,children:"Embedding URL:"}),e.jsx("span",{style:g.value,children:t.embeddingUrl??e.jsx("span",{style:{color:"#888"},children:"not set"})})]}),e.jsxs("div",{style:g.row,children:[e.jsx("span",{style:g.label,children:"Embed Cache:"}),e.jsx("span",{style:g.value,children:t.embedCache??e.jsx("span",{style:{color:"#888"},children:"not set"})})]}),e.jsxs("div",{style:g.row,children:[e.jsx("span",{style:g.label,children:"MiniLM:"}),e.jsx("span",{style:g.value,children:t.minilm?"enabled":"disabled"})]}),Me(t)]}),!t&&!a&&e.jsx("p",{style:{color:"#888",fontSize:"0.85rem"},children:"Loading configuration..."})]})}function Ae(){const[t,a]=s.useState(null),[n,l]=s.useState(null),[r,i]=s.useState(null),[u,c]=s.useState(null),[d,x]=s.useState(!1),[m,h]=s.useState(null),[o,f]=s.useState(null),[j,v]=s.useState(null),[w,k]=s.useState(""),[S,A]=s.useState(!1),N=s.useCallback(()=>{J().then(a).catch(p=>i(p instanceof Error?p.message:String(p)))},[]),E=s.useCallback((p,C,T,$,U,O)=>{h(p),v(null),f(null);const B="embeddingHeadersSet"in(t??{});Q({embedder:p,url:C,embeddingEndpointUrl:C,embeddingApiKey:T,...B?{embeddingDim:$,embeddingHeaders:U,allowRemoteEmbedder:O}:{}}).then(I=>{f(I),h(null),N()}).catch(I=>{v(I instanceof Error?I.message:String(I)),h(null)})},[N,t]),b=s.useCallback(()=>{x(!0),c(null),ie().then(p=>{l(p),x(!1)}).catch(p=>{c(p instanceof Error?p.message:String(p)),x(!1)})},[]);return s.useEffect(()=>{N()},[N]),s.useEffect(()=>{S||t&&typeof t.embeddingEndpointUrl=="string"&&t.embeddingEndpointUrl.length>0&&(k(t.embeddingEndpointUrl),A(!0))},[t,S]),s.useEffect(()=>{const p=setInterval(N,5e3);return()=>clearInterval(p)},[N]),s.useEffect(()=>{b();const p=setInterval(b,5e3);return()=>clearInterval(p)},[b]),e.jsxs("div",{style:g.container,children:[e.jsx("h2",{style:{fontSize:"1.3rem",marginTop:0,marginBottom:"1rem"},children:"Embedder Setup"}),e.jsx(Se,{}),e.jsx(ze,{status:t,statusError:r}),e.jsxs("div",{style:g.section,children:[e.jsx("h3",{style:g.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."}),n&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{style:g.detectRow,children:[e.jsx("span",{children:e.jsx("strong",{children:"Ollama"})}),n.ollama!==null?e.jsxs("span",{children:[G(n.ollama.installed),n.ollama.installed&&e.jsx("span",{style:{fontSize:"0.8rem",color:"#a0a0c0",marginLeft:"0.5rem"},children:n.ollama.running?`server running, ${n.ollama.models.length} model(s)`:"server not running"})]}):e.jsx("span",{style:{color:"#888",fontSize:"0.85rem"},children:"not checked"})]}),e.jsxs("div",{style:g.detectRow,children:[e.jsx("span",{children:e.jsx("strong",{children:"llama.cpp"})}),n.llamaCpp!==null?e.jsxs("span",{children:[G(n.llamaCpp.installed),n.llamaCpp.installed&&n.llamaCpp.detail&&e.jsx("span",{style:{fontSize:"0.8rem",color:"#a0a0c0",marginLeft:"0.5rem"},children:n.llamaCpp.detail})]}):e.jsx("span",{style:{color:"#888",fontSize:"0.85rem"},children:"not checked"})]}),e.jsxs("div",{style:g.detectRow,children:[e.jsx("span",{children:e.jsx("strong",{children:"ONNX Runtime"})}),n.onnx!==null?e.jsxs("span",{children:[G(n.onnx.installed),n.onnx.installed&&n.onnx.detail&&e.jsx("span",{style:{fontSize:"0.8rem",color:"#a0a0c0",marginLeft:"0.5rem"},children:n.onnx.detail})]}):e.jsx("span",{style:{color:"#888",fontSize:"0.85rem"},children:"not checked"})]}),n.error&&e.jsxs("p",{style:{color:"#f44336",fontSize:"0.8rem",marginTop:"0.5rem"},children:["Detection error: ",n.error]})]}),u&&e.jsxs("p",{style:{color:"#f44336",fontSize:"0.85rem"},children:["Error: ",u]}),e.jsxs("div",{style:{marginTop:"1rem"},children:[e.jsx("button",{style:g.button,onClick:b,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."]})]}),n&&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:{...g.button,opacity:n.ollama?.installed?1:.4},onClick:()=>E("ollama"),disabled:!n.ollama?.installed||m!==null,children:m==="ollama"?"Writing...":"Use Ollama"}),e.jsx("button",{style:{...g.button,opacity:n.llamaCpp?.installed?1:.4},onClick:()=>E("llama"),disabled:!n.llamaCpp?.installed||m!==null,children:m==="llama"?"Writing...":"Use llama.cpp"}),e.jsx("button",{style:{...g.button,opacity:n.onnx?.installed?1:.4},onClick:()=>E("onnx"),disabled:!n.onnx?.installed||m!==null,children:m==="onnx"?"Writing...":"Use ONNX"}),e.jsx("button",{style:{...g.button,background:"#444"},onClick:()=>E("trigram"),disabled:m!==null,children:m==="trigram"?"Writing...":"Use Trigram (default)"})]}),o&&o.embedder!=="custom"&&e.jsx("div",{style:g.warning,children:o.alreadyActive?"Already active — no restart needed.":`Configured ${o.embedder}. Restart pi to activate (config written to ${o.envPath}).`}),j&&e.jsxs("p",{style:{color:"#f44336",fontSize:"0.85rem",marginTop:"0.5rem"},children:["Configure error: ",j]})]})]}),e.jsx(Re,{customUrl:w,setCustomUrl:k,applyEmbedder:E,configuring:m,inputEnabled:t!==null&&"embeddingApiKeySet"in t,apiKeySet:t?.embeddingApiKeySet===!0,embeddingDim:t?.embeddingDim,embeddingHeadersSet:t?.embeddingHeadersSet===!0,allowRemoteEmbedder:t?.allowRemoteEmbedder,configureResult:o,configureError:j}),e.jsxs("div",{style:g.section,children:[e.jsx("h3",{style:g.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:g.section,children:[e.jsx("h3",{style:g.sectionTitle,children:"Settings"}),e.jsx(Ee,{})]})]})}function _(t){return t>=1e6?`${(t/1e6).toFixed(2)}M`:t>=1e3?`${Math.round(t/1e3)}K`:String(t)}function Be(t,a,n){if(t<=0)return"—";const r=(a>0?a:Math.ceil(t*.1))+Math.ceil(t*(n/100)),i=t-r;return i<=0?"0 (at risk)":`${_(i)} tokens`}function V({label:t,value:a,min:n,max:l,step:r=1,onChange:i,warning:u}){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 ${u?"text-warning":"text-fg"}`,title:u,children:[a,"%"]})]}),e.jsx("input",{type:"range",min:n,max:l,step:r,value:a,onChange:c=>i(Number(c.target.value)),className:"threshold-slider w-full"}),u&&e.jsxs("p",{className:"text-[10px] text-warning",children:["⚠ ",u]})]})}function Ie({model:t,defaults:a,safetyRange:n,fireRange:l,onSave:r,onReset:i,saving:u}){const[c,d]=s.useState(t.threshold.safetyMarginPct),[x,m]=s.useState(t.threshold.firePointPct),[h,o]=s.useState(!1),[f,j]=s.useState(null);s.useEffect(()=>{d(t.threshold.safetyMarginPct),m(t.threshold.firePointPct),o(!1)},[t.threshold.safetyMarginPct,t.threshold.firePointPct]);const v=c<5?'Low safety margin — risks "conversation too long" errors when a single turn injects a large tool output between gate fires.':void 0,w=x>85?"High fire point — compaction may trigger close to the window cap; a single large turn can overshoot before the gate fires.":void 0,k=s.useCallback(async()=>{j(null);try{await r(t.modelId,c,x),o(!1)}catch(S){j(S instanceof Error?S.message:String(S))}},[t.modelId,c,x,r]);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:Be(t.contextWindow,t.maxTokens,c)})]}),e.jsxs("div",{children:["Compaction fires at:"," ",e.jsx("span",{className:"font-mono text-fg",children:_(Math.ceil(t.contextWindow*(x/100)))})]})]})]}),e.jsxs("div",{className:"grid grid-cols-1 gap-3 sm:grid-cols-2",children:[e.jsx(V,{label:"Safety margin",value:c,min:n[0],max:n[1],onChange:S=>{d(S),o(!0)},warning:v}),e.jsx(V,{label:"Fire point",value:x,min:l[0],max:l[1],onChange:S=>{m(S),o(!0)},warning:w})]}),e.jsxs("div",{className:"mt-2 flex items-center gap-2",children:[e.jsx("button",{type:"button",onClick:k,disabled:!h||u,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:h?"Save override":"Saved"}),t.threshold.isOverride&&e.jsxs("button",{type:"button",onClick:()=>i(t.modelId),disabled:u,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 (",a.safetyMarginPct,"% /"," ",a.firePointPct,"%)"]}),f&&e.jsx("span",{className:"text-[11px] text-error",children:f})]})]})}function Le(){const[t,a]=s.useState(null),[n,l]=s.useState(!0),[r,i]=s.useState(null),[u,c]=s.useState(!1),d=s.useCallback(async()=>{try{i(null),a(await de())}catch(h){i(h instanceof Error?h.message:String(h))}finally{l(!1)}},[]);s.useEffect(()=>{d()},[d]);const x=s.useCallback(async(h,o,f)=>{c(!0);try{await me({modelId:h,safetyMarginPct:o,firePointPct:f}),await d()}finally{c(!1)}},[d]),m=s.useCallback(async h=>{c(!0);try{await ue(h),await d()}finally{c(!1)}},[d]);return n?e.jsx("div",{className:"p-4 text-sm text-fg-muted",children:"Loading thresholds…"}):r?e.jsxs("div",{className:"p-4 text-sm text-error",children:["Error: ",r]}):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(h=>e.jsx(Ie,{model:h,defaults:t.defaults,safetyRange:t.defaults.safetyMarginRange,fireRange:t.defaults.firePointRange,onSave:x,onReset:m,saving:u},h.modelId))})]}):e.jsx("div",{className:"p-4 text-sm text-fg-muted",children:"No data."})}async function Oe(){const t=await fetch("/api/setup-cortex-status");if(!t.ok)throw new Error(`setup-cortex status: ${t.status}`);return t.json()}async function Pe(t){const a=await fetch("/api/setup-cortex-action",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)});if(a.ok)return{ok:!0,result:await a.json()};let n;try{n=await a.json()}catch{n={error:"disabled"}}return{ok:!1,status:a.status,error:n}}async function De(t){const a=await fetch(`/api/setup-cortex-action-log?name=${encodeURIComponent(t)}`);if(!a.ok)throw new Error(`setup-cortex action-log: ${a.status}`);return a.json()}function _e(t){return t===null?!0:t.enabled&&t.status!=="off"}function ee(){const[t,a]=s.useState({loading:!0,error:null,data:null}),n=s.useCallback(()=>{a(l=>({...l,loading:!0})),Oe().then(l=>a(r=>({...r,data:l,loading:!1,error:null}))).catch(l=>a(r=>({...r,loading:!1,error:l instanceof Error?l.message:String(l)})))},[]);return s.useEffect(()=>{n();const l=setInterval(n,5e3);return()=>clearInterval(l)},[n]),[t,n]}const y={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 Ue(t){const a=t==="qualified"?"#1a5a1a":t==="demoted"?"#3a3a1a":"#3a1a1a",n=t==="qualified"?"#4caf50":t==="demoted"?"#ffcc00":"#f44336";return e.jsx("span",{style:{...y.badge,background:a,color:n},children:t??"unknown"})}function We({data:t,error:a}){return e.jsxs("div",{style:y.section,children:[e.jsxs("h3",{style:y.sectionTitle,children:[e.jsx("span",{style:{marginRight:"0.5rem"},children:"Cortex Encoder"}),e.jsx(he,{status:t?.status})]}),a&&e.jsxs("p",{style:{color:"#f44336",fontSize:"0.85rem"},children:["Error: ",a]}),!t&&!a&&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:y.row,children:[e.jsx("span",{style:y.label,children:"Mode:"}),e.jsx("span",{style:y.value,children:$e(t?.encoderHealth.mode)})]}),e.jsxs("div",{style:y.row,children:[e.jsx("span",{style:y.label,children:"Asset digest prefix:"}),e.jsx("span",{style:{...y.value,...y.mono},children:t?.assetDigestPrefix??e.jsx("span",{style:{color:"#888"},children:"not available"})})]}),e.jsxs("div",{style:y.row,children:[e.jsx("span",{style:y.label,children:"Qualification:"}),Ue(t?.qualification.verdict)]}),(t?.qualification.thresholdFailures.length??0)>0&&e.jsxs("div",{style:y.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:a,darwinX64:n}){const l=a??[];return e.jsxs("div",{style:y.section,children:[e.jsxs("h3",{style:y.sectionTitle,children:["Open Hard-Gate Blockers",e.jsx("span",{style:{...y.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."}),n?.demoted===!0&&e.jsxs("div",{style:y.blockerRow,"data-darwin-x64-demoted":"true",children:[e.jsx("span",{style:{...y.mono,fontWeight:700},children:"HG-4"}),e.jsx("span",{style:{flex:1,color:"#e0e0e0"},children:n.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(r=>{const i=l.includes(r.id);return e.jsxs("div",{style:{...y.blockerRow,...i?y.blockerRowHighlighted:{}},children:[e.jsx("span",{style:{...y.mono,fontWeight:700},children:r.id}),e.jsx("span",{style:{flex:1,color:"#e0e0e0"},children:r.title}),e.jsx("span",{style:{color:Fe(r.severity)},children:r.severity}),e.jsx("span",{style:{color:"#a0a0c0",fontStyle:"italic"},children:i?"gates this action":r.status})]},r.id)}),l.length>0&&e.jsxs("div",{style:y.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:a,onAction:n}){const[l,r]=s.useState(null),[i,u]=s.useState(null),[c,d]=s.useState(null),[x,m]=s.useState(!1),h=s.useCallback(async f=>{r(f.key),d(null),u(null),m(!1),a([]);try{const j=await Pe({action:f.key,confirm:!0});if(j.ok){const v=j.result;let w=null,k=null;try{const S=await De(v.logName);w=S.tail,k=S.complete}catch{}u({action:v.action,logName:v.logName,tail:w,complete:k,message:v.ok?`${v.action} completed (spawned: ${v.spawned})`:`${v.action} did not complete cleanly`}),n()}else j.error.error==="action_blocked_by_open_item"?(a(j.error.blockers),d("The action is blocked by an open hard-gate item and was not run.")):j.error.error==="confirmation_required"?d("The server rejected the action: explicit confirmation is required."):(m(!0),d(j.status===404?"Setup Cortex actions are disabled (off).":`Action failed (${j.status}).`))}catch(j){d(j instanceof Error?j.message:String(j))}finally{r(null)}},[a,n]),o=f=>{window.confirm(f.confirm)&&h(f)};return e.jsxs("div",{style:y.section,children:[e.jsx("h3",{style:y.sectionTitle,children:"Cortex Actions"}),Ge.map(f=>{const j=l===f.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:f.label}),e.jsx("div",{style:{fontSize:"0.8rem",color:"#a0a0c0"},children:f.desc})]}),e.jsx("button",{style:f.dangerous?y.buttonDanger:y.button,disabled:l!==null,onClick:()=>o(f),children:j?"Running…":"Run"})]},f.key)}),x&&e.jsx("div",{style:y.blocked,children:"Setup Cortex actions are disabled. Enable MEGACOMPACT_VC9B to run them."}),c&&!x&&e.jsx("p",{style:{color:"#f44336",fontSize:"0.85rem",marginTop:"0.5rem"},children:c}),i&&e.jsxs("div",{style:y.warning,"data-testid":"cortex-action-result",children:[e.jsxs("strong",{children:["Result (",i.action,"):"]})," ",i.message,i.logName&&e.jsxs("span",{style:{...y.mono,marginLeft:"0.5rem"},children:["log: ",i.logName]}),i.tail!==null&&e.jsxs("pre",{style:{whiteSpace:"pre-wrap",wordBreak:"break-word",fontSize:"0.75rem",maxHeight:"12rem",overflow:"auto",marginTop:"0.5rem"},children:[i.tail,i.complete===!1&&`
|
|
2
|
-
… (truncated)`]})]}),!t?.enabled&&!x&&e.jsx("p",{style:{color:"#a0a0c0",fontSize:"0.8rem",marginTop:"0.5rem"},children:"Cortex status unavailable — actions may not be schedulable."})]})}const z={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"}};function Ve(){const[t,a]=s.useState(null),[n,l]=s.useState(null),[r,i]=s.useState(!1),u=s.useCallback(()=>{J().then(a).catch(h=>l(h instanceof Error?h.message:String(h)))},[]);s.useEffect(()=>{u()},[u]),s.useEffect(()=>{const h=setInterval(u,5e3);return()=>clearInterval(h)},[u]);const c=t!==null&&"encoderNativeOptIn"in t,d=s.useCallback(h=>{i(!0),l(null),Q({embedder:"custom",url:t?.embeddingEndpointUrl??void 0,encoderNativeOptIn:h}).then(()=>{i(!1),u()}).catch(o=>{l(o instanceof Error?o.message:String(o)),i(!1)})},[t,u]);if(!c)return e.jsx(e.Fragment,{});const x=t?.encoderBackend??"wasm",m=t?.encoderDemotionReason??null;return e.jsxs("div",{style:z.section,children:[e.jsx("h3",{style:z.sectionTitle,children:"Encoder Runtime"}),e.jsx("p",{style:z.subtitle,children:"ONNX backend selection"}),e.jsxs("div",{style:z.toggleRow,children:[e.jsx("input",{type:"checkbox",checked:t?.encoderNativeOptIn===!0,onChange:h=>d(h.target.checked),disabled:r,"aria-label":"Native ONNX runtime (onnxruntime-node)"}),e.jsx("label",{children:"Native ONNX runtime (onnxruntime-node)"}),r&&e.jsx("span",{style:{fontSize:"0.8rem",color:"#a0a0c0"},children:"saving..."})]}),e.jsxs("div",{style:z.row,children:[e.jsx("span",{style:z.label,children:"Effective backend:"}),e.jsx("span",{style:z.value,children:x})]}),m!==null&&e.jsxs("div",{style:z.warning,children:[e.jsx("strong",{children:"Demoted:"})," ",m]}),n&&e.jsxs("p",{style:{color:"#f44336",fontSize:"0.85rem"},children:["Error: ",n]})]})}function Xe(){const[t,a]=ee(),[n,l]=s.useState([]),r=s.useCallback(u=>{l(u)},[]),i=s.useCallback(()=>{a()},[a]);return e.jsxs("div",{style:y.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(We,{data:t.data,error:t.error}),e.jsx(Ve,{}),e.jsx(He,{blockers:t.data?.blockers??[],highlight:n,darwinX64:t.data?.darwinX64}),e.jsx(qe,{data:t.data,onBlocked:r,onAction:i})]})}const Ke=[{id:"embedder",label:"Embedder"},{id:"thresholds",label:"Thresholds"},{id:"config",label:"Config"},{id:"game",label:"Game Mode"},{id:"achievements",label:"Achievements"}],Je={id:"cortex",label:"Cortex"};function st(){const[t,a]=s.useState("embedder"),[n]=ee(),l=s.useMemo(()=>{const r=[...Ke];return _e(n.data)&&r.push(Je),r},[n.data]);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(r=>e.jsx(fe,{pressed:t===r.id,onClick:()=>a(r.id),children:r.label},r.id))}),t==="embedder"&&e.jsx(Ae,{}),t==="thresholds"&&e.jsx(Le,{}),t==="config"&&e.jsx(ve,{}),t==="game"&&e.jsx(pe,{}),t==="achievements"&&e.jsx(be,{}),t==="cortex"&&e.jsx(Xe,{})]})}export{st as default};
|
|
3
|
-
//# sourceMappingURL=SetupTab-vB72Y7pk.js.map
|