pi-mega-compact 0.20.51 → 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 (60) hide show
  1. package/assets/vector-cortex/encoder-v1/manifest.json +1 -1
  2. package/dist/extensions/dashboard-server/api-contracts/vector-cortex-ledger.js +9 -0
  3. package/dist/extensions/dashboard-server/routes-vector-cortex-eval.js +4 -1
  4. package/extensions/dashboard-client/dist/assets/{AreaChart-BFTUTmmW.js → AreaChart-Dika24if.js} +2 -2
  5. package/extensions/dashboard-client/dist/assets/{AreaChart-BFTUTmmW.js.map → AreaChart-Dika24if.js.map} +1 -1
  6. package/extensions/dashboard-client/dist/assets/{BarChart-DfFurESR.js → BarChart-MxPpphaX.js} +2 -2
  7. package/extensions/dashboard-client/dist/assets/{BarChart-DfFurESR.js.map → BarChart-MxPpphaX.js.map} +1 -1
  8. package/extensions/dashboard-client/dist/assets/{CacheTab-FpCJSmy8.js → CacheTab-e90mt1aw.js} +2 -2
  9. package/extensions/dashboard-client/dist/assets/{CacheTab-FpCJSmy8.js.map → CacheTab-e90mt1aw.js.map} +1 -1
  10. package/extensions/dashboard-client/dist/assets/{EventsTab--9lJFJtc.js → EventsTab-CSl9CNXa.js} +2 -2
  11. package/extensions/dashboard-client/dist/assets/{EventsTab--9lJFJtc.js.map → EventsTab-CSl9CNXa.js.map} +1 -1
  12. package/extensions/dashboard-client/dist/assets/{HealthTab-CkgtF1qa.js → HealthTab-CgUm8sp5.js} +2 -2
  13. package/extensions/dashboard-client/dist/assets/{HealthTab-CkgtF1qa.js.map → HealthTab-CgUm8sp5.js.map} +1 -1
  14. package/extensions/dashboard-client/dist/assets/{MaintenanceTab-ChXGq1or.js → MaintenanceTab-Dyhjzk6G.js} +2 -2
  15. package/extensions/dashboard-client/dist/assets/{MaintenanceTab-ChXGq1or.js.map → MaintenanceTab-Dyhjzk6G.js.map} +1 -1
  16. package/extensions/dashboard-client/dist/assets/{MemoryMapTab-CPpRR4MV.js → MemoryMapTab-C1YR7CoA.js} +2 -2
  17. package/extensions/dashboard-client/dist/assets/{MemoryMapTab-CPpRR4MV.js.map → MemoryMapTab-C1YR7CoA.js.map} +1 -1
  18. package/extensions/dashboard-client/dist/assets/{MetricsTab-Db1wkykf.js → MetricsTab-Bktg-486.js} +2 -2
  19. package/extensions/dashboard-client/dist/assets/{MetricsTab-Db1wkykf.js.map → MetricsTab-Bktg-486.js.map} +1 -1
  20. package/extensions/dashboard-client/dist/assets/{OverviewTab-LanDECrz.js → OverviewTab-B7qTLQc2.js} +2 -2
  21. package/extensions/dashboard-client/dist/assets/{OverviewTab-LanDECrz.js.map → OverviewTab-B7qTLQc2.js.map} +1 -1
  22. package/extensions/dashboard-client/dist/assets/{ReposTab-I2umKduk.js → ReposTab-Cr9W3KFw.js} +2 -2
  23. package/extensions/dashboard-client/dist/assets/{ReposTab-I2umKduk.js.map → ReposTab-Cr9W3KFw.js.map} +1 -1
  24. package/extensions/dashboard-client/dist/assets/{SessionsTab-D_IxuEt5.js → SessionsTab-5x_LL9D8.js} +2 -2
  25. package/extensions/dashboard-client/dist/assets/{SessionsTab-D_IxuEt5.js.map → SessionsTab-5x_LL9D8.js.map} +1 -1
  26. package/extensions/dashboard-client/dist/assets/{SetupTab-BZ7Jn5MR.js → SetupTab-vB72Y7pk.js} +2 -2
  27. package/extensions/dashboard-client/dist/assets/{SetupTab-BZ7Jn5MR.js.map → SetupTab-vB72Y7pk.js.map} +1 -1
  28. package/extensions/dashboard-client/dist/assets/{TimeSavedCard-BTdcO1E2.js → TimeSavedCard-hsMc2BFT.js} +2 -2
  29. package/extensions/dashboard-client/dist/assets/{TimeSavedCard-BTdcO1E2.js.map → TimeSavedCard-hsMc2BFT.js.map} +1 -1
  30. package/extensions/dashboard-client/dist/assets/{TurnsTab-BXC8IL_B.js → TurnsTab-CjUIvDlj.js} +2 -2
  31. package/extensions/dashboard-client/dist/assets/{TurnsTab-BXC8IL_B.js.map → TurnsTab-CjUIvDlj.js.map} +1 -1
  32. package/extensions/dashboard-client/dist/assets/{VcStatusBadge-CNJnFtJo.js → VcStatusBadge-yDtZGtnm.js} +2 -2
  33. package/extensions/dashboard-client/dist/assets/{VcStatusBadge-CNJnFtJo.js.map → VcStatusBadge-yDtZGtnm.js.map} +1 -1
  34. package/extensions/dashboard-client/dist/assets/{VectorCortexTab-fsuWgA6e.js → VectorCortexTab-CvbaaeXD.js} +2 -2
  35. package/extensions/dashboard-client/dist/assets/{VectorCortexTab-fsuWgA6e.js.map → VectorCortexTab-CvbaaeXD.js.map} +1 -1
  36. package/extensions/dashboard-client/dist/assets/{WikiTab-Cn1BScDU.js → WikiTab-c7K7kspY.js} +2 -2
  37. package/extensions/dashboard-client/dist/assets/{WikiTab-Cn1BScDU.js.map → WikiTab-c7K7kspY.js.map} +1 -1
  38. package/extensions/dashboard-client/dist/assets/{button-B4_9rsul.js → button-vdqzHHyW.js} +2 -2
  39. package/extensions/dashboard-client/dist/assets/{button-B4_9rsul.js.map → button-vdqzHHyW.js.map} +1 -1
  40. package/extensions/dashboard-client/dist/assets/{card-DUvC_geI.js → card-DEzbxZLz.js} +2 -2
  41. package/extensions/dashboard-client/dist/assets/{card-DUvC_geI.js.map → card-DEzbxZLz.js.map} +1 -1
  42. package/extensions/dashboard-client/dist/assets/{client-extra-HaH97bzp.js → client-extra-CJe2UKEK.js} +2 -2
  43. package/extensions/dashboard-client/dist/assets/{client-extra-HaH97bzp.js.map → client-extra-CJe2UKEK.js.map} +1 -1
  44. package/extensions/dashboard-client/dist/assets/{generateCategoricalChart-BxFWU2Mt.js → generateCategoricalChart-Br3cS-GZ.js} +2 -2
  45. package/extensions/dashboard-client/dist/assets/{generateCategoricalChart-BxFWU2Mt.js.map → generateCategoricalChart-Br3cS-GZ.js.map} +1 -1
  46. package/extensions/dashboard-client/dist/assets/{index-xPdbZ73U.js → index-CBMWirAB.js} +3 -3
  47. package/extensions/dashboard-client/dist/assets/{index-xPdbZ73U.js.map → index-CBMWirAB.js.map} +1 -1
  48. package/extensions/dashboard-client/dist/assets/{switch-Bv3_1R_j.js → switch-D_uPnF8u.js} +2 -2
  49. package/extensions/dashboard-client/dist/assets/{switch-Bv3_1R_j.js.map → switch-D_uPnF8u.js.map} +1 -1
  50. package/extensions/dashboard-client/dist/assets/{toggle-DHXrB3Aw.js → toggle-DIaGjpNm.js} +2 -2
  51. package/extensions/dashboard-client/dist/assets/{toggle-DHXrB3Aw.js.map → toggle-DIaGjpNm.js.map} +1 -1
  52. package/extensions/dashboard-client/dist/assets/{useSSE-NigHeFyT.js → useSSE-CJOcvXIe.js} +2 -2
  53. package/extensions/dashboard-client/dist/assets/{useSSE-NigHeFyT.js.map → useSSE-CJOcvXIe.js.map} +1 -1
  54. package/extensions/dashboard-client/dist/index.html +1 -1
  55. package/extensions/dashboard-client/src/tabs/VectorCortexTab.tsx +7 -5
  56. package/extensions/dashboard-client/src/types/vector-cortex.ts +6 -0
  57. package/extensions/dashboard-server/api-contracts/vector-cortex-ledger.ts +39 -0
  58. package/extensions/dashboard-server/api-contracts/vector-cortex.ts +10 -28
  59. package/extensions/dashboard-server/routes-vector-cortex-eval.ts +4 -1
  60. package/package.json +1 -1
@@ -1,3 +1,3 @@
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-xPdbZ73U.js";import{S as ce}from"./switch-Bv3_1R_j.js";import{f as de,p as me,d as ue}from"./client-extra-HaH97bzp.js";import{V as he}from"./VcStatusBadge-CNJnFtJo.js";import{T as fe}from"./toggle-DHXrB3Aw.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&&`
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
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-BZ7Jn5MR.js.map
3
+ //# sourceMappingURL=SetupTab-vB72Y7pk.js.map