pi-mega-compact 0.20.50 → 0.20.52

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 (88) hide show
  1. package/assets/vector-cortex/encoder-v1/manifest.json +1 -1
  2. package/dist/config/vector-cortex-enc1b.js +46 -0
  3. package/dist/config/vector-cortex.js +1 -0
  4. package/dist/config.js +1 -1
  5. package/dist/extensions/dashboard-server/api-contracts/vector-cortex-ledger.js +9 -0
  6. package/dist/extensions/dashboard-server/routes-rag-settings-vector-cortex.js +1 -0
  7. package/dist/extensions/dashboard-server/routes-setup-enc1b.js +297 -0
  8. package/dist/extensions/dashboard-server/routes-setup-env-upsert.js +79 -0
  9. package/dist/extensions/dashboard-server/routes-setup.js +27 -26
  10. package/dist/extensions/dashboard-server/routes-vector-cortex-eval.js +4 -1
  11. package/dist/src/config/vector-cortex-enc1b.js +46 -0
  12. package/dist/src/config/vector-cortex.js +1 -0
  13. package/dist/src/config.js +1 -1
  14. package/extensions/dashboard-client/dist/assets/{AreaChart-CeVnaV-0.js → AreaChart-Dika24if.js} +2 -2
  15. package/extensions/dashboard-client/dist/assets/{AreaChart-CeVnaV-0.js.map → AreaChart-Dika24if.js.map} +1 -1
  16. package/extensions/dashboard-client/dist/assets/{BarChart-DoNd35sw.js → BarChart-MxPpphaX.js} +2 -2
  17. package/extensions/dashboard-client/dist/assets/{BarChart-DoNd35sw.js.map → BarChart-MxPpphaX.js.map} +1 -1
  18. package/extensions/dashboard-client/dist/assets/{CacheTab-BROshdFf.js → CacheTab-e90mt1aw.js} +2 -2
  19. package/extensions/dashboard-client/dist/assets/{CacheTab-BROshdFf.js.map → CacheTab-e90mt1aw.js.map} +1 -1
  20. package/extensions/dashboard-client/dist/assets/{EventsTab-DAD6NeBR.js → EventsTab-CSl9CNXa.js} +2 -2
  21. package/extensions/dashboard-client/dist/assets/{EventsTab-DAD6NeBR.js.map → EventsTab-CSl9CNXa.js.map} +1 -1
  22. package/extensions/dashboard-client/dist/assets/{HealthTab-BBVMM54F.js → HealthTab-CgUm8sp5.js} +2 -2
  23. package/extensions/dashboard-client/dist/assets/{HealthTab-BBVMM54F.js.map → HealthTab-CgUm8sp5.js.map} +1 -1
  24. package/extensions/dashboard-client/dist/assets/{MaintenanceTab-f9VhlFco.js → MaintenanceTab-Dyhjzk6G.js} +2 -2
  25. package/extensions/dashboard-client/dist/assets/{MaintenanceTab-f9VhlFco.js.map → MaintenanceTab-Dyhjzk6G.js.map} +1 -1
  26. package/extensions/dashboard-client/dist/assets/{MemoryMapTab-BaxfyzN2.js → MemoryMapTab-C1YR7CoA.js} +2 -2
  27. package/extensions/dashboard-client/dist/assets/{MemoryMapTab-BaxfyzN2.js.map → MemoryMapTab-C1YR7CoA.js.map} +1 -1
  28. package/extensions/dashboard-client/dist/assets/{MetricsTab-DkUvoeS_.js → MetricsTab-Bktg-486.js} +2 -2
  29. package/extensions/dashboard-client/dist/assets/{MetricsTab-DkUvoeS_.js.map → MetricsTab-Bktg-486.js.map} +1 -1
  30. package/extensions/dashboard-client/dist/assets/{OverviewTab-BCpK1vgt.js → OverviewTab-B7qTLQc2.js} +2 -2
  31. package/extensions/dashboard-client/dist/assets/{OverviewTab-BCpK1vgt.js.map → OverviewTab-B7qTLQc2.js.map} +1 -1
  32. package/extensions/dashboard-client/dist/assets/{ReposTab-cJ5neYIG.js → ReposTab-Cr9W3KFw.js} +2 -2
  33. package/extensions/dashboard-client/dist/assets/{ReposTab-cJ5neYIG.js.map → ReposTab-Cr9W3KFw.js.map} +1 -1
  34. package/extensions/dashboard-client/dist/assets/{SessionsTab-8DyQv1Ry.js → SessionsTab-5x_LL9D8.js} +2 -2
  35. package/extensions/dashboard-client/dist/assets/{SessionsTab-8DyQv1Ry.js.map → SessionsTab-5x_LL9D8.js.map} +1 -1
  36. package/extensions/dashboard-client/dist/assets/SetupTab-vB72Y7pk.js +3 -0
  37. package/extensions/dashboard-client/dist/assets/SetupTab-vB72Y7pk.js.map +1 -0
  38. package/extensions/dashboard-client/dist/assets/{TimeSavedCard-8N7Vvlch.js → TimeSavedCard-hsMc2BFT.js} +2 -2
  39. package/extensions/dashboard-client/dist/assets/{TimeSavedCard-8N7Vvlch.js.map → TimeSavedCard-hsMc2BFT.js.map} +1 -1
  40. package/extensions/dashboard-client/dist/assets/{TurnsTab-CCijkQoH.js → TurnsTab-CjUIvDlj.js} +2 -2
  41. package/extensions/dashboard-client/dist/assets/{TurnsTab-CCijkQoH.js.map → TurnsTab-CjUIvDlj.js.map} +1 -1
  42. package/extensions/dashboard-client/dist/assets/{VcStatusBadge-D9a7By8x.js → VcStatusBadge-yDtZGtnm.js} +2 -2
  43. package/extensions/dashboard-client/dist/assets/{VcStatusBadge-D9a7By8x.js.map → VcStatusBadge-yDtZGtnm.js.map} +1 -1
  44. package/extensions/dashboard-client/dist/assets/{VectorCortexTab-pviD6CCy.js → VectorCortexTab-CvbaaeXD.js} +2 -2
  45. package/extensions/dashboard-client/dist/assets/{VectorCortexTab-pviD6CCy.js.map → VectorCortexTab-CvbaaeXD.js.map} +1 -1
  46. package/extensions/dashboard-client/dist/assets/{WikiTab-DLyicguz.js → WikiTab-c7K7kspY.js} +2 -2
  47. package/extensions/dashboard-client/dist/assets/{WikiTab-DLyicguz.js.map → WikiTab-c7K7kspY.js.map} +1 -1
  48. package/extensions/dashboard-client/dist/assets/{button-D8nKit8Y.js → button-vdqzHHyW.js} +2 -2
  49. package/extensions/dashboard-client/dist/assets/{button-D8nKit8Y.js.map → button-vdqzHHyW.js.map} +1 -1
  50. package/extensions/dashboard-client/dist/assets/{card-Xf5wHHBL.js → card-DEzbxZLz.js} +2 -2
  51. package/extensions/dashboard-client/dist/assets/{card-Xf5wHHBL.js.map → card-DEzbxZLz.js.map} +1 -1
  52. package/extensions/dashboard-client/dist/assets/{client-extra-CvxDLpQr.js → client-extra-CJe2UKEK.js} +2 -2
  53. package/extensions/dashboard-client/dist/assets/{client-extra-CvxDLpQr.js.map → client-extra-CJe2UKEK.js.map} +1 -1
  54. package/extensions/dashboard-client/dist/assets/{generateCategoricalChart-DhQquRa8.js → generateCategoricalChart-Br3cS-GZ.js} +2 -2
  55. package/extensions/dashboard-client/dist/assets/{generateCategoricalChart-DhQquRa8.js.map → generateCategoricalChart-Br3cS-GZ.js.map} +1 -1
  56. package/extensions/dashboard-client/dist/assets/{index-BUP3MK5S.js → index-CBMWirAB.js} +3 -3
  57. package/extensions/dashboard-client/dist/assets/{index-BUP3MK5S.js.map → index-CBMWirAB.js.map} +1 -1
  58. package/extensions/dashboard-client/dist/assets/index-C_aDd9kk.css +1 -0
  59. package/extensions/dashboard-client/dist/assets/{switch-B13rb8Z2.js → switch-D_uPnF8u.js} +2 -2
  60. package/extensions/dashboard-client/dist/assets/{switch-B13rb8Z2.js.map → switch-D_uPnF8u.js.map} +1 -1
  61. package/extensions/dashboard-client/dist/assets/{toggle-4h6DUEB5.js → toggle-DIaGjpNm.js} +2 -2
  62. package/extensions/dashboard-client/dist/assets/{toggle-4h6DUEB5.js.map → toggle-DIaGjpNm.js.map} +1 -1
  63. package/extensions/dashboard-client/dist/assets/{useSSE-Djom4z1K.js → useSSE-CJOcvXIe.js} +2 -2
  64. package/extensions/dashboard-client/dist/assets/{useSSE-Djom4z1K.js.map → useSSE-CJOcvXIe.js.map} +1 -1
  65. package/extensions/dashboard-client/dist/index.html +2 -2
  66. package/extensions/dashboard-client/src/tabs/SetupTab/CortexRuntimeCard.tsx +103 -0
  67. package/extensions/dashboard-client/src/tabs/SetupTab/CortexRuntimeCardStyles.ts +49 -0
  68. package/extensions/dashboard-client/src/tabs/SetupTab/CortexSetup.tsx +2 -0
  69. package/extensions/dashboard-client/src/tabs/SetupTab/CustomEndpointSection.tsx +122 -1
  70. package/extensions/dashboard-client/src/tabs/SetupTab/EmbedderSetup.tsx +57 -79
  71. package/extensions/dashboard-client/src/tabs/SetupTab/EmbedderSetupHelpers.tsx +75 -0
  72. package/extensions/dashboard-client/src/tabs/VectorCortexTab.tsx +7 -5
  73. package/extensions/dashboard-client/src/types/vector-cortex.ts +6 -0
  74. package/extensions/dashboard-server/api-contracts/setup.ts +35 -0
  75. package/extensions/dashboard-server/api-contracts/vector-cortex-ledger.ts +39 -0
  76. package/extensions/dashboard-server/api-contracts/vector-cortex.ts +10 -28
  77. package/extensions/dashboard-server/routes-rag-settings-vector-cortex.ts +6 -0
  78. package/extensions/dashboard-server/routes-setup-enc1b.ts +336 -0
  79. package/extensions/dashboard-server/routes-setup-env-upsert.ts +93 -0
  80. package/extensions/dashboard-server/routes-setup.ts +26 -24
  81. package/extensions/dashboard-server/routes-vector-cortex-eval.ts +4 -1
  82. package/package.json +1 -1
  83. package/src/config/vector-cortex-enc1b.ts +50 -0
  84. package/src/config/vector-cortex.ts +8 -0
  85. package/src/config.ts +1 -0
  86. package/extensions/dashboard-client/dist/assets/SetupTab-BQGPf9CI.js +0 -3
  87. package/extensions/dashboard-client/dist/assets/SetupTab-BQGPf9CI.js.map +0 -1
  88. package/extensions/dashboard-client/dist/assets/index-DbuGwYD7.css +0 -1
@@ -0,0 +1,50 @@
1
+ /**
2
+ * config/vector-cortex-enc1b.ts — ENC-1b ONNX runtime backend + embedder API
3
+ * Settings fields.
4
+ *
5
+ * Extracted from vector-cortex.ts so that file stays under the 300-line soft
6
+ * limit (soft-as-hard gate), exactly as the ENC-1a sibling was. vector-cortex.ts
7
+ * re-exports the flag + constants below and root src/config.ts re-exports them,
8
+ * so no consumer import path changes.
9
+ *
10
+ * ENC-1b adds two Settings surfaces. (A) Embedder API completion: the three
11
+ * remaining env vars the runtime reads (src/httpEmbedder.ts:embeddingConfigFromEnv)
12
+ * gain dashboard-visible fields — `MEGACOMPACT_EMBEDDING_DIM` (numeric, validated
13
+ * positive int bounded by `ENC_1B_MAX_EMBEDDING_DIM`), `MEGACOMPACT_EMBEDDING_HEADERS`
14
+ * (JSON object string — secret-bearing, written verbatim to the per-repo
15
+ * `.mega-compact.env`, NEVER echoed raw; the GET reports only a boolean
16
+ * presence marker), and `MEGACOMPACT_ALLOW_REMOTE_EMBEDDER` (boolDirect toggle,
17
+ * default off — a deliberate escape hatch that skips the loopback-only check).
18
+ * (B) ONNX runtime selection surface: `MEGACOMPACT_ENCODER_NATIVE` is persisted
19
+ * to the per-repo env + surfaced as a Settings toggle, and the GET status route
20
+ * computes the current effective backend + demotion reason through the existing
21
+ * `selectRuntimeBackend` (reader-only — no selection literals reimplemented).
22
+ *
23
+ * `MEGACOMPACT_ENC_1B=0` disables: no new GET fields, no writer branch, no new
24
+ * Settings rows or toggle — byte-identical to the ENC-1a predecessor. The flag
25
+ * MUST also be a dashboard SETTINGS toggle (visible in config UI, never in
26
+ * EXCLUDED_SETTINGS).
27
+ *
28
+ * Pi-agnostic, dependency-free (PREVENT-PI-004 / PREVENT-011).
29
+ */
30
+
31
+ import { sprintFlag } from "./vector-cortex-flag.js";
32
+
33
+ /** ENC-1b `MEGACOMPACT_EMBEDDING_DIM` upper bound (positive integer string). */
34
+ export const ENC_1B_MAX_EMBEDDING_DIM = 8192;
35
+
36
+ /** Persisted env names pinned here so the aggregator scan + the routes share
37
+ * one source of truth (exactly the names embeddingConfigFromEnv reads). */
38
+ export const ENC_1B_EMBEDDING_DIM_ENV = "MEGACOMPACT_EMBEDDING_DIM";
39
+ export const ENC_1B_EMBEDDING_HEADERS_ENV = "MEGACOMPACT_EMBEDDING_HEADERS";
40
+ export const ENC_1B_ALLOW_REMOTE_EMBEDDER_ENV = "MEGACOMPACT_ALLOW_REMOTE_EMBEDDER";
41
+ export const ENC_1B_ENCODER_NATIVE_ENV = "MEGACOMPACT_ENCODER_NATIVE";
42
+
43
+ /**
44
+ * ENC-1b — ONNX runtime backend + embedder API Settings fields. Default ON.
45
+ * `MEGACOMPACT_ENC_1B=0` disables and is byte-identical to the ENC-1a
46
+ * predecessor: no new GET fields, no writer branch, no new Settings rows or
47
+ * toggle. This flag MUST also be a dashboard SETTINGS toggle (visible in config
48
+ * UI, never in EXCLUDED_SETTINGS).
49
+ */
50
+ export const ENC_1B_ENABLED = (): boolean => sprintFlag("MEGACOMPACT_ENC_1B");
@@ -63,6 +63,14 @@ export { ENC_0E_ENABLED } from "./vector-cortex-enc0e.js";
63
63
  export { ENC_0F_ENABLED } from "./vector-cortex-enc0f.js";
64
64
  export { ENC_0G_ENABLED } from "./vector-cortex-enc0g.js";
65
65
  export { ENC_1A_ENABLED } from "./vector-cortex-enc1a.js";
66
+ export {
67
+ ENC_1B_ENABLED,
68
+ ENC_1B_MAX_EMBEDDING_DIM,
69
+ ENC_1B_EMBEDDING_DIM_ENV,
70
+ ENC_1B_EMBEDDING_HEADERS_ENV,
71
+ ENC_1B_ALLOW_REMOTE_EMBEDDER_ENV,
72
+ ENC_1B_ENCODER_NATIVE_ENV,
73
+ } from "./vector-cortex-enc1b.js";
66
74
  // Breaker constants (TRIAD_RESILIENCE.md §breaker) extracted to vector-cortex-breakers.ts.
67
75
  export {
68
76
  BREAKER_WINDOW_MS,
package/src/config.ts CHANGED
@@ -197,6 +197,7 @@ export {
197
197
  ENC_0F_ENABLED,
198
198
  ENC_0G_ENABLED,
199
199
  ENC_1A_ENABLED,
200
+ ENC_1B_ENABLED,
200
201
  BREAKER_WINDOW_MS,
201
202
  BREAKER_MIN_ATTEMPTS,
202
203
  BREAKER_PERF_FAILURES,
@@ -1,3 +0,0 @@
1
- import{r as n,j as e,h as L,i as G,k as H,p as J,l as Y,m as Z,C as ee,n as te,o as se,q as ne,s as re,t as ae,v as le}from"./index-BUP3MK5S.js";import{S as oe}from"./switch-B13rb8Z2.js";import{f as ie,p as ce,d as de}from"./client-extra-CvxDLpQr.js";import{V as me}from"./VcStatusBadge-D9a7By8x.js";import{T as ue}from"./toggle-4h6DUEB5.js";function he(t){try{return new Date(t*1e3).toLocaleString()}catch{return"—"}}function q({achievements:t}){const a=n.useRef(0),[s,i]=n.useState(null),r=t.reduce((l,d)=>Math.max(l,d.unlocked_at??0),0),o=a.current;n.useEffect(()=>{r>a.current&&(a.current=r)},[r]),n.useEffect(()=>{if(o>0&&r>o){const l=t.filter(d=>d.unlocked_at!=null&&(d.unlocked_at??0)>o);if(l.length>0){const d=l.map(m=>`${m.icon??""} ${m.title}`.trim()).join(", ")+" unlocked!";i(d);const g=setTimeout(()=>i(null),4e3);return()=>clearTimeout(g)}}},[t,r,o]);const h=t.filter(l=>!(l.hidden===1&&l.unlocked_at==null));return e.jsxs("div",{className:"ach-section",children:[s!=null&&e.jsx("div",{className:"ach-toast show",children:s}),e.jsxs("div",{className:"ach-tiles",children:[h.length===0&&e.jsx("span",{className:"repo-none",children:"no achievements yet"}),h.map(l=>{if(l.unlocked_at!=null){const d=o>0&&(l.unlocked_at??0)>o;return e.jsxs("div",{className:`ach-tile unlocked${d?" just-unlocked":""}`,children:[l.icon??""," ",l.title,e.jsxs("span",{className:"ach-detail",children:["unlocked ",he(l.unlocked_at)]})]},l.id)}return e.jsxs("div",{className:"ach-tile locked",children:["??? ",l.title]},l.id)})]})]})}function I(t){return(Math.round(t*10)/10).toString()+"%"}function _(t){return t!=null?new Date(t).toLocaleString():"—"}function O(t){return t&&typeof t=="object"?t:{}}function fe(t){return t.split("/").pop()||t}function B({title:t,rows:a,badge:s,renderValue:i}){return e.jsxs("div",{className:"lb-card",children:[e.jsxs("h3",{children:[t,s]}),a.length===0?e.jsx("div",{className:"lb-empty",children:"—"}):e.jsx("table",{children:e.jsx("tbody",{children:a.map((r,o)=>e.jsxs("tr",{children:[e.jsx("td",{title:r.repo_root,children:fe(r.repo_root)}),e.jsx("td",{className:"num",children:i(r)})]},`${r.repo_root}-${o}`))})})]})}function ge(){const[t,a]=n.useState({}),[s,i]=n.useState(0),[r,o]=n.useState([]),[h,l]=n.useState(!1),[d,g]=n.useState(!0),[m,x]=n.useState(null),c=n.useRef(0),u=n.useCallback(async()=>{try{const[j,w,k,T,X,Q]=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}),G()]),W=T.find(z=>z.ts>c.current&&z.value>100);c.current>0&&W&&(x(`oopsie! cache went to ${Math.round(W.value)}% — MEGA CACHE 🥧`),setTimeout(()=>x(null),4e3)),T.length>0&&(c.current=Math.max(...T.map(z=>z.ts))),a({cache:j,dedupe:w,turns:k,mega_cache:T}),i(X[0]?.value??0),o(Q)}catch{}finally{g(!1)}},[]);n.useEffect(()=>{let j=!0;const w=async()=>{j&&await u()};w();const k=setInterval(()=>void w(),15e3);return()=>{j=!1,clearInterval(k)}},[u]),n.useEffect(()=>{let j=!0;const w=async()=>{try{const T=await H();j&&(l(!!T.game_mode_on),T.theme&&(document.documentElement.dataset.theme=T.theme))}catch{}};w();const k=setInterval(()=>void w(),15e3);return()=>{j=!1,clearInterval(k)}},[]);const b=t.mega_cache??[];let y=null,N=null;for(const j of b){(y==null||j.value>y)&&(y=j.value);const w=O(j.meta),k=w.firstSeenTs??w.firstSeen??j.ts;(N==null||k<N)&&(N=k)}const C=y!=null&&y>100,v=t.turns??[],M=v.reduce((j,w)=>Math.max(j,w.value),0),A=Math.floor(Math.log2(M+1))+1,S=(t.cache?.length??0)>0||(t.dedupe?.length??0)>0||v.length>0||b.length>0||s>0;return e.jsxs("div",{className:`game-tab${h?" game-mode-on":""}`,children:[m!=null&&e.jsx("div",{className:"mega-cache-toast show",children:m}),C&&e.jsxs("div",{className:"mega-cache-banner",children:["🥧"," MEGA CACHE! peak ",I(y)," — first reached ",_(N)]}),C&&e.jsxs("div",{className:"achievement-tile unlocked",children:["🏆"," Opie's Wild Ride",e.jsxs("span",{className:"ach-detail",children:["best ",I(y)," · first ",_(N)]})]}),e.jsx("h2",{children:"High Scores"}),!S&&!d&&e.jsx("div",{className:"game-empty",children:"No scores yet — run a session with game mode on."}),S&&e.jsxs("div",{className:"game-leaderboards",children:[e.jsx(B,{title:"Cache %",rows:t.cache??[],renderValue:j=>I(j.value)}),e.jsx(B,{title:"Dedupe (collapsed)",rows:t.dedupe??[],renderValue:j=>j.value.toLocaleString()}),e.jsx(B,{title:"Turns",rows:v,badge:v.length>0?e.jsxs("span",{className:"lvl-badge",children:["LVL ",A]}):void 0,renderValue:j=>j.value.toLocaleString()}),e.jsx(B,{title:"MEGA CACHE trophies",rows:b,renderValue:j=>e.jsxs(e.Fragment,{children:[I(j.value),e.jsx("span",{className:"lb-meta",children:_(O(j.meta).firstSeenTs??O(j.meta).firstSeen??j.ts)})]})})]}),s>0&&e.jsx("div",{className:"repos-badge-line",children:e.jsxs("span",{className:"repos-badge",children:[s," repos"]})}),e.jsx("h3",{children:"Achievements"}),e.jsx(q,{achievements:r})]})}function xe(){const[t,a]=n.useState([]),[s,i]=n.useState(!0),[r,o]=n.useState(null),h=n.useCallback(async()=>{try{const l=await G();a(l),o(null)}catch(l){o(l instanceof Error?l:new Error(String(l)))}finally{i(!1)}},[]);return n.useEffect(()=>{let l=!0;const d=async()=>{l&&await h()};d();const g=setInterval(()=>void d(),15e3);return()=>{l=!1,clearInterval(g)}},[h]),s&&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(q,{achievements:t})]})}const V=[{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"}}],D=V.map(t=>t.id),E={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 pe(t,a,s){let i=t.toLocaleString();return a!=null&&s>0&&(i+=` (${Math.round(a*100)}% of ${s.toLocaleString()})`),i}function be(t){return`${Math.round((t||0)*100)}%`}function je(){const[t,a]=n.useState(null),[s,i]=n.useState(null),[r,o]=n.useState(!1);n.useEffect(()=>{let c=!0;const u=async()=>{try{const y=await Y();c&&a(y)}catch{}};u();const b=setInterval(()=>void u(),5e3);return()=>{c=!1,clearInterval(b)}},[]),n.useEffect(()=>{let c=!0;const u=async()=>{try{const y=await H();c&&(i(y),y.theme&&(document.documentElement.dataset.theme=y.theme))}catch{}};u();const b=setInterval(()=>void u(),5e3);return()=>{c=!1,clearInterval(b)}},[]);const h=n.useCallback(async c=>{o(!0);try{const u=await J(c);i(u),u.theme&&(document.documentElement.dataset.theme=u.theme)}catch{}o(!1)},[]),l=s?.game_mode_on??!1,d=s?.theme??"transparent",g=s?.tui_display_mode??"full",m=t?.config,x=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:E.gameMode,children:[e.jsx("input",{type:"checkbox",checked:l,onChange:c=>h({game_mode_on:c.currentTarget.checked}),disabled:r}),"Game Mode"]})}),e.jsx("div",{className:"settings-row",children:e.jsxs("label",{title:E.theme,children:["Theme",e.jsx("select",{value:d,onChange:c=>h({theme:c.currentTarget.value}),disabled:r,children:V.map(c=>e.jsx("option",{value:c.id,children:c.label},c.id))}),e.jsx("button",{type:"button",disabled:r,className:"theme-cycle-btn",title:"Cycle to the next theme (P3)",onClick:()=>{const c=D.indexOf(d),u=D[(c<0?0:c+1)%D.length];u&&h({theme:u})},children:"Next theme →"})]})}),e.jsx("div",{className:"settings-row",children:e.jsxs("label",{title:E.tuiMode,children:["TUI Mode",e.jsxs("select",{value:g,onChange:c=>h({tui_display_mode:c.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:E.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:E.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:E.pressure,children:"Pressure"}),e.jsx("span",{className:"config-value",children:t?be(t.pressure):"—"})]}),e.jsxs("div",{className:"config-item",children:[e.jsx("span",{className:"config-label",title:E.threshold,children:"Threshold"}),e.jsx("span",{className:"config-value",children:m?pe(m.thresholdTokens,m.tierPct,x):"—"})]}),e.jsxs("div",{className:"config-item",children:[e.jsx("span",{className:"config-label",title:E.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 R={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 ye(){const[t,a]=n.useState(null),[s,i]=n.useState(null),r=n.useCallback(()=>{Z().then(a).catch(g=>i(g instanceof Error?g.message:String(g)))},[]);n.useEffect(()=>{r()},[r]),n.useEffect(()=>{const g=setInterval(r,3e4);return()=>clearInterval(g)},[r]);const o=t?.status==="ok",h=t?.status==="ok"?"Working":t?.status==="unreachable"?"Unreachable":"Error",l=o?"#4caf50":"#f44336",d=o?"✓":"✗";return e.jsxs("div",{style:R.section,children:[e.jsx("h3",{style:R.sectionTitle,children:"Embedder Health"}),s&&e.jsxs("p",{style:{color:"#f44336",fontSize:"0.85rem"},children:["Error: ",s]}),!t&&!s&&e.jsx("p",{style:{color:"#888",fontSize:"0.85rem"},children:"Probing embedder..."}),t&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{style:R.row,children:[e.jsxs("span",{style:{...R.label,color:`${l}`},children:[d," ",h,":"]}),e.jsxs("span",{style:R.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:R.row,children:[e.jsx("span",{style:R.label,children:"Endpoint:"}),e.jsx("span",{style:R.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 ve({title:t,children:a}){const[s,i]=n.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:()=>i(o=>!o),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":s,"aria-controls":r,children:[e.jsx("span",{children:t}),e.jsx(ee,{className:te("h-4 w-4 text-muted-foreground transition-transform",s&&"rotate-180"),"aria-hidden":"true"})]}),s&&e.jsx("div",{id:r,className:"divide-y divide-border px-4 py-1",children:a})]})}const Se="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 we(){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 ke({setting:t,id:a,llmActive:s,saving:i,onUpdate:r}){const[o,h]=n.useState(null),l=t.requiresLlm&&!s,d=n.useRef(null);n.useEffect(()=>()=>{d.current&&clearTimeout(d.current)},[]);const g=n.useCallback(c=>{r(t.key,c).then(u=>h(u)).catch(u=>h(u instanceof Error?u.message:String(u)))},[r,t.key]),m=n.useCallback(c=>{d.current&&clearTimeout(d.current),d.current=setTimeout(()=>g(c),500)},[g]),x=i||l;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&&!s&&e.jsx(we,{})]}),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(oe,{id:`${a}-input`,checked:!!t.value,disabled:x||l,onCheckedChange:c=>g(String(c)),"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:x,onChange:c=>m(c.target.value),className:`${Se} ${t.type==="number"?"w-24":"w-56"}`}),t.unit&&e.jsx("span",{className:"text-xs text-muted-foreground",children:t.unit})]})})]}),o&&e.jsxs("p",{className:"mt-1 text-xs text-danger",children:["Error: ",o]})]})}function Ne(){const[t,a]=n.useState(null),[s,i]=n.useState(null),[r,o]=n.useState(!1),[h,l]=n.useState(null),d=n.useCallback(()=>{se().then(a).catch(m=>i(m instanceof Error?m.message:String(m)))},[]);n.useEffect(()=>{d()},[d]);const g=n.useCallback(async(m,x)=>{o(!0);try{const c=await ne({key:m,value:x});return l(c.restartRequired?"Saved — restart pi to apply changes.":"Saved."),d(),null}catch(c){return c instanceof Error?c.message:String(c)}finally{o(!1)}},[d]);return e.jsxs("div",{className:"flex flex-col gap-3",children:[s&&e.jsxs("p",{className:"text-sm text-danger",children:["Error: ",s]}),!t&&!s&&e.jsx("p",{className:"text-sm text-muted-foreground",children:"Loading settings..."}),t?.categories.map(m=>e.jsx(ve,{title:m.name,children:m.settings.map(x=>e.jsx(ke,{setting:x,id:`${m.name.replace(/[^a-z0-9]+/gi,"-")}-${x.key}`,llmActive:t.llmActive,saving:r,onUpdate:g},x.key))},m.name)),h&&e.jsx("div",{className:"mt-1 rounded-md border border-warning/40 bg-warning/10 p-2 text-xs text-warning",role:"status",children:h})]})}const f={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}},Ce="Saved; takes effect on next session start";function Te({customUrl:t,setCustomUrl:a,applyEmbedder:s,configuring:i,inputEnabled:r,configureResult:o,configureError:h}){const[l,d]=n.useState("");return e.jsxs("div",{style:f.section,children:[e.jsx("h3",{style:f.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:g=>a(g.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:l,onChange:g=>d(g.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"}}),e.jsx("button",{style:{...f.button,opacity:t?1:.4},onClick:()=>s("custom",t,l),disabled:!t||i!==null,children:i==="custom"?"Writing...":"Use Custom URL"})]}),h!==null&&e.jsxs("p",{style:{color:"#f44336",fontSize:"0.85rem",marginTop:"0.5rem"},children:["Configure error: ",h]}),o!==null&&o.embedder==="custom"&&e.jsx("div",{style:f.warning,children:Ce}),e.jsxs("div",{style:f.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 U(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 Ee(t){return t?.currentEmbedder!=="trigram"?null:e.jsxs("div",{style:f.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 $(t){const a=t?"#1a5a1a":"#3a1a1a",s=t?"#4caf50":"#f44336";return e.jsx("span",{style:{...f.badge,background:a,color:s},children:t?"Detected":"Not found"})}function Re(){const[t,a]=n.useState(null),[s,i]=n.useState(null),[r,o]=n.useState(null),[h,l]=n.useState(null),[d,g]=n.useState(!1),[m,x]=n.useState(null),[c,u]=n.useState(null),[b,y]=n.useState(null),[N,C]=n.useState(""),v=n.useCallback(()=>{re().then(a).catch(S=>o(S instanceof Error?S.message:String(S)))},[]),M=n.useCallback((S,j,w)=>{x(S),y(null),u(null),ae({embedder:S,url:j,embeddingEndpointUrl:j,embeddingApiKey:w}).then(k=>{u(k),x(null),v()}).catch(k=>{y(k instanceof Error?k.message:String(k)),x(null)})},[v]),A=n.useCallback(()=>{g(!0),l(null),le().then(S=>{i(S),g(!1)}).catch(S=>{l(S instanceof Error?S.message:String(S)),g(!1)})},[]);return n.useEffect(()=>{v()},[v]),n.useEffect(()=>{const S=setInterval(v,5e3);return()=>clearInterval(S)},[v]),n.useEffect(()=>{A();const S=setInterval(A,5e3);return()=>clearInterval(S)},[A]),e.jsxs("div",{style:f.container,children:[e.jsx("h2",{style:{fontSize:"1.3rem",marginTop:0,marginBottom:"1rem"},children:"Embedder Setup"}),e.jsx(ye,{}),e.jsxs("div",{style:f.section,children:[e.jsx("h3",{style:f.sectionTitle,children:"Current Embedder Configuration"}),r&&e.jsxs("p",{style:{color:"#f44336",fontSize:"0.85rem"},children:["Error: ",r]}),t&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{style:f.row,children:[e.jsx("span",{style:f.label,children:"Active Embedder:"}),e.jsx("span",{style:f.value,children:U(t.currentEmbedder)})]}),"configuredEmbedder"in t&&t.configuredEmbedder!==t.currentEmbedder&&e.jsxs("div",{style:f.warning,children:[e.jsx("strong",{children:"Configured but not active:"})," ",U(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:{...f.row,color:"#ff9800"},children:[e.jsx("span",{style:f.label,children:"Status:"}),e.jsx("span",{style:f.value,children:"Restart required to activate the configured embedder"})]}),e.jsxs("div",{style:f.row,children:[e.jsx("span",{style:f.label,children:"Embedding URL:"}),e.jsx("span",{style:f.value,children:t.embeddingUrl??e.jsx("span",{style:{color:"#888"},children:"not set"})})]}),e.jsxs("div",{style:f.row,children:[e.jsx("span",{style:f.label,children:"Embed Cache:"}),e.jsx("span",{style:f.value,children:t.embedCache??e.jsx("span",{style:{color:"#888"},children:"not set"})})]}),e.jsxs("div",{style:f.row,children:[e.jsx("span",{style:f.label,children:"MiniLM:"}),e.jsx("span",{style:f.value,children:t.minilm?"enabled":"disabled"})]}),Ee(t)]}),!t&&!r&&e.jsx("p",{style:{color:"#888",fontSize:"0.85rem"},children:"Loading configuration..."})]}),e.jsxs("div",{style:f.section,children:[e.jsx("h3",{style:f.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."}),s&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{style:f.detectRow,children:[e.jsx("span",{children:e.jsx("strong",{children:"Ollama"})}),s.ollama!==null?e.jsxs("span",{children:[$(s.ollama.installed),s.ollama.installed&&e.jsx("span",{style:{fontSize:"0.8rem",color:"#a0a0c0",marginLeft:"0.5rem"},children:s.ollama.running?`server running, ${s.ollama.models.length} model(s)`:"server not running"})]}):e.jsx("span",{style:{color:"#888",fontSize:"0.85rem"},children:"not checked"})]}),e.jsxs("div",{style:f.detectRow,children:[e.jsx("span",{children:e.jsx("strong",{children:"llama.cpp"})}),s.llamaCpp!==null?e.jsxs("span",{children:[$(s.llamaCpp.installed),s.llamaCpp.installed&&s.llamaCpp.detail&&e.jsx("span",{style:{fontSize:"0.8rem",color:"#a0a0c0",marginLeft:"0.5rem"},children:s.llamaCpp.detail})]}):e.jsx("span",{style:{color:"#888",fontSize:"0.85rem"},children:"not checked"})]}),e.jsxs("div",{style:f.detectRow,children:[e.jsx("span",{children:e.jsx("strong",{children:"ONNX Runtime"})}),s.onnx!==null?e.jsxs("span",{children:[$(s.onnx.installed),s.onnx.installed&&s.onnx.detail&&e.jsx("span",{style:{fontSize:"0.8rem",color:"#a0a0c0",marginLeft:"0.5rem"},children:s.onnx.detail})]}):e.jsx("span",{style:{color:"#888",fontSize:"0.85rem"},children:"not checked"})]}),s.error&&e.jsxs("p",{style:{color:"#f44336",fontSize:"0.8rem",marginTop:"0.5rem"},children:["Detection error: ",s.error]})]}),h&&e.jsxs("p",{style:{color:"#f44336",fontSize:"0.85rem"},children:["Error: ",h]}),e.jsxs("div",{style:{marginTop:"1rem"},children:[e.jsx("button",{style:f.button,onClick:A,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."]})]}),s&&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:{...f.button,opacity:s.ollama?.installed?1:.4},onClick:()=>M("ollama"),disabled:!s.ollama?.installed||m!==null,children:m==="ollama"?"Writing...":"Use Ollama"}),e.jsx("button",{style:{...f.button,opacity:s.llamaCpp?.installed?1:.4},onClick:()=>M("llama"),disabled:!s.llamaCpp?.installed||m!==null,children:m==="llama"?"Writing...":"Use llama.cpp"}),e.jsx("button",{style:{...f.button,opacity:s.onnx?.installed?1:.4},onClick:()=>M("onnx"),disabled:!s.onnx?.installed||m!==null,children:m==="onnx"?"Writing...":"Use ONNX"}),e.jsx("button",{style:{...f.button,background:"#444"},onClick:()=>M("trigram"),disabled:m!==null,children:m==="trigram"?"Writing...":"Use Trigram (default)"})]}),c&&c.embedder!=="custom"&&e.jsx("div",{style:f.warning,children:c.alreadyActive?"Already active — no restart needed.":`Configured ${c.embedder}. Restart pi to activate (config written to ${c.envPath}).`}),b&&e.jsxs("p",{style:{color:"#f44336",fontSize:"0.85rem",marginTop:"0.5rem"},children:["Configure error: ",b]})]})]}),e.jsx(Te,{customUrl:N,setCustomUrl:C,applyEmbedder:M,configuring:m,inputEnabled:t!==null&&"embeddingApiKeySet"in t,configureResult:c,configureError:b}),e.jsxs("div",{style:f.section,children:[e.jsx("h3",{style:f.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:f.section,children:[e.jsx("h3",{style:f.sectionTitle,children:"Settings"}),e.jsx(Ne,{})]})]})}function P(t){return t>=1e6?`${(t/1e6).toFixed(2)}M`:t>=1e3?`${Math.round(t/1e3)}K`:String(t)}function Me(t,a,s){if(t<=0)return"—";const r=(a>0?a:Math.ceil(t*.1))+Math.ceil(t*(s/100)),o=t-r;return o<=0?"0 (at risk)":`${P(o)} tokens`}function F({label:t,value:a,min:s,max:i,step:r=1,onChange:o,warning:h}){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 ${h?"text-warning":"text-fg"}`,title:h,children:[a,"%"]})]}),e.jsx("input",{type:"range",min:s,max:i,step:r,value:a,onChange:l=>o(Number(l.target.value)),className:"threshold-slider w-full"}),h&&e.jsxs("p",{className:"text-[10px] text-warning",children:["⚠ ",h]})]})}function Ae({model:t,defaults:a,safetyRange:s,fireRange:i,onSave:r,onReset:o,saving:h}){const[l,d]=n.useState(t.threshold.safetyMarginPct),[g,m]=n.useState(t.threshold.firePointPct),[x,c]=n.useState(!1),[u,b]=n.useState(null);n.useEffect(()=>{d(t.threshold.safetyMarginPct),m(t.threshold.firePointPct),c(!1)},[t.threshold.safetyMarginPct,t.threshold.firePointPct]);const y=l<5?'Low safety margin — risks "conversation too long" errors when a single turn injects a large tool output between gate fires.':void 0,N=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,C=n.useCallback(async()=>{b(null);try{await r(t.modelId,l,g),c(!1)}catch(v){b(v instanceof Error?v.message:String(v))}},[t.modelId,l,g,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," · ",P(t.contextWindow)," window ·"," ",P(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:Me(t.contextWindow,t.maxTokens,l)})]}),e.jsxs("div",{children:["Compaction fires at:"," ",e.jsx("span",{className:"font-mono text-fg",children:P(Math.ceil(t.contextWindow*(g/100)))})]})]})]}),e.jsxs("div",{className:"grid grid-cols-1 gap-3 sm:grid-cols-2",children:[e.jsx(F,{label:"Safety margin",value:l,min:s[0],max:s[1],onChange:v=>{d(v),c(!0)},warning:y}),e.jsx(F,{label:"Fire point",value:g,min:i[0],max:i[1],onChange:v=>{m(v),c(!0)},warning:N})]}),e.jsxs("div",{className:"mt-2 flex items-center gap-2",children:[e.jsx("button",{type:"button",onClick:C,disabled:!x||h,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:()=>o(t.modelId),disabled:h,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,"%)"]}),u&&e.jsx("span",{className:"text-[11px] text-error",children:u})]})]})}function Le(){const[t,a]=n.useState(null),[s,i]=n.useState(!0),[r,o]=n.useState(null),[h,l]=n.useState(!1),d=n.useCallback(async()=>{try{o(null),a(await ie())}catch(x){o(x instanceof Error?x.message:String(x))}finally{i(!1)}},[]);n.useEffect(()=>{d()},[d]);const g=n.useCallback(async(x,c,u)=>{l(!0);try{await ce({modelId:x,safetyMarginPct:c,firePointPct:u}),await d()}finally{l(!1)}},[d]),m=n.useCallback(async x=>{l(!0);try{await de(x),await d()}finally{l(!1)}},[d]);return s?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(x=>e.jsx(Ae,{model:x,defaults:t.defaults,safetyRange:t.defaults.safetyMarginRange,fireRange:t.defaults.firePointRange,onSave:g,onReset:m,saving:h},x.modelId))})]}):e.jsx("div",{className:"p-4 text-sm text-fg-muted",children:"No data."})}async function ze(){const t=await fetch("/api/setup-cortex-status");if(!t.ok)throw new Error(`setup-cortex status: ${t.status}`);return t.json()}async function Ie(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 s;try{s=await a.json()}catch{s={error:"disabled"}}return{ok:!1,status:a.status,error:s}}async function Be(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 Pe(t){return t===null?!0:t.enabled&&t.status!=="off"}function K(){const[t,a]=n.useState({loading:!0,error:null,data:null}),s=n.useCallback(()=>{a(i=>({...i,loading:!0})),ze().then(i=>a(r=>({...r,data:i,loading:!1,error:null}))).catch(i=>a(r=>({...r,loading:!1,error:i instanceof Error?i.message:String(i)})))},[]);return n.useEffect(()=>{s();const i=setInterval(s,5e3);return()=>clearInterval(i)},[s]),[t,s]}const p={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 Oe(t){const a=t==="qualified"?"#1a5a1a":t==="demoted"?"#3a3a1a":"#3a1a1a",s=t==="qualified"?"#4caf50":t==="demoted"?"#ffcc00":"#f44336";return e.jsx("span",{style:{...p.badge,background:a,color:s},children:t??"unknown"})}function De({data:t,error:a}){return e.jsxs("div",{style:p.section,children:[e.jsxs("h3",{style:p.sectionTitle,children:[e.jsx("span",{style:{marginRight:"0.5rem"},children:"Cortex Encoder"}),e.jsx(me,{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:p.row,children:[e.jsx("span",{style:p.label,children:"Mode:"}),e.jsx("span",{style:p.value,children:_e(t?.encoderHealth.mode)})]}),e.jsxs("div",{style:p.row,children:[e.jsx("span",{style:p.label,children:"Asset digest prefix:"}),e.jsx("span",{style:{...p.value,...p.mono},children:t?.assetDigestPrefix??e.jsx("span",{style:{color:"#888"},children:"not available"})})]}),e.jsxs("div",{style:p.row,children:[e.jsx("span",{style:p.label,children:"Qualification:"}),Oe(t?.qualification.verdict)]}),(t?.qualification.thresholdFailures.length??0)>0&&e.jsxs("div",{style:p.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 $e(t){switch(t){case"blocker":return"#f44336";case"high":return"#ff9800";default:return"#a0a0c0"}}function We({blockers:t,highlight:a,darwinX64:s}){const i=a??[];return e.jsxs("div",{style:p.section,children:[e.jsxs("h3",{style:p.sectionTitle,children:["Open Hard-Gate Blockers",e.jsx("span",{style:{...p.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."}),s?.demoted===!0&&e.jsxs("div",{style:p.blockerRow,"data-darwin-x64-demoted":"true",children:[e.jsx("span",{style:{...p.mono,fontWeight:700},children:"HG-4"}),e.jsx("span",{style:{flex:1,color:"#e0e0e0"},children:s.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 o=i.includes(r.id);return e.jsxs("div",{style:{...p.blockerRow,...o?p.blockerRowHighlighted:{}},children:[e.jsx("span",{style:{...p.mono,fontWeight:700},children:r.id}),e.jsx("span",{style:{flex:1,color:"#e0e0e0"},children:r.title}),e.jsx("span",{style:{color:$e(r.severity)},children:r.severity}),e.jsx("span",{style:{color:"#a0a0c0",fontStyle:"italic"},children:o?"gates this action":r.status})]},r.id)}),i.length>0&&e.jsxs("div",{style:p.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 Ue=[{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 Fe({data:t,onBlocked:a,onAction:s}){const[i,r]=n.useState(null),[o,h]=n.useState(null),[l,d]=n.useState(null),[g,m]=n.useState(!1),x=n.useCallback(async u=>{r(u.key),d(null),h(null),m(!1),a([]);try{const b=await Ie({action:u.key,confirm:!0});if(b.ok){const y=b.result;let N=null,C=null;try{const v=await Be(y.logName);N=v.tail,C=v.complete}catch{}h({action:y.action,logName:y.logName,tail:N,complete:C,message:y.ok?`${y.action} completed (spawned: ${y.spawned})`:`${y.action} did not complete cleanly`}),s()}else b.error.error==="action_blocked_by_open_item"?(a(b.error.blockers),d("The action is blocked by an open hard-gate item and was not run.")):b.error.error==="confirmation_required"?d("The server rejected the action: explicit confirmation is required."):(m(!0),d(b.status===404?"Setup Cortex actions are disabled (off).":`Action failed (${b.status}).`))}catch(b){d(b instanceof Error?b.message:String(b))}finally{r(null)}},[a,s]),c=u=>{window.confirm(u.confirm)&&x(u)};return e.jsxs("div",{style:p.section,children:[e.jsx("h3",{style:p.sectionTitle,children:"Cortex Actions"}),Ue.map(u=>{const b=i===u.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:u.label}),e.jsx("div",{style:{fontSize:"0.8rem",color:"#a0a0c0"},children:u.desc})]}),e.jsx("button",{style:u.dangerous?p.buttonDanger:p.button,disabled:i!==null,onClick:()=>c(u),children:b?"Running…":"Run"})]},u.key)}),g&&e.jsx("div",{style:p.blocked,children:"Setup Cortex actions are disabled. Enable MEGACOMPACT_VC9B to run them."}),l&&!g&&e.jsx("p",{style:{color:"#f44336",fontSize:"0.85rem",marginTop:"0.5rem"},children:l}),o&&e.jsxs("div",{style:p.warning,"data-testid":"cortex-action-result",children:[e.jsxs("strong",{children:["Result (",o.action,"):"]})," ",o.message,o.logName&&e.jsxs("span",{style:{...p.mono,marginLeft:"0.5rem"},children:["log: ",o.logName]}),o.tail!==null&&e.jsxs("pre",{style:{whiteSpace:"pre-wrap",wordBreak:"break-word",fontSize:"0.75rem",maxHeight:"12rem",overflow:"auto",marginTop:"0.5rem"},children:[o.tail,o.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."})]})}function Ge(){const[t,a]=K(),[s,i]=n.useState([]),r=n.useCallback(h=>{i(h)},[]),o=n.useCallback(()=>{a()},[a]);return e.jsxs("div",{style:p.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(De,{data:t.data,error:t.error}),e.jsx(We,{blockers:t.data?.blockers??[],highlight:s,darwinX64:t.data?.darwinX64}),e.jsx(Fe,{data:t.data,onBlocked:r,onAction:o})]})}const He=[{id:"embedder",label:"Embedder"},{id:"thresholds",label:"Thresholds"},{id:"config",label:"Config"},{id:"game",label:"Game Mode"},{id:"achievements",label:"Achievements"}],qe={id:"cortex",label:"Cortex"};function Ye(){const[t,a]=n.useState("embedder"),[s]=K(),i=n.useMemo(()=>{const r=[...He];return Pe(s.data)&&r.push(qe),r},[s.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:i.map(r=>e.jsx(ue,{pressed:t===r.id,onClick:()=>a(r.id),children:r.label},r.id))}),t==="embedder"&&e.jsx(Re,{}),t==="thresholds"&&e.jsx(Le,{}),t==="config"&&e.jsx(je,{}),t==="game"&&e.jsx(ge,{}),t==="achievements"&&e.jsx(xe,{}),t==="cortex"&&e.jsx(Ge,{})]})}export{Ye as default};
3
- //# sourceMappingURL=SetupTab-BQGPf9CI.js.map