pi-mega-compact 0.20.5 → 0.20.6

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 (94) hide show
  1. package/dist/config/vector-cortex.js +12 -0
  2. package/dist/config.js +1 -1
  3. package/dist/extensions/dashboard-server/routes-rag-settings-helpers.js +1 -0
  4. package/dist/extensions/dashboard-server/routes-vector-cortex-rollout.js +43 -0
  5. package/dist/extensions/dashboard-server/routes-vector-cortex.js +1 -0
  6. package/dist/extensions/dashboard-server/routes.js +1 -1
  7. package/dist/extensions/dashboard-server/server.js +3 -1
  8. package/dist/extensions/mega-runtime/vector-cortex-live.js +105 -0
  9. package/dist/src/config/vector-cortex.js +12 -0
  10. package/dist/src/config.js +1 -1
  11. package/dist/src/vector-cortex/rollout/_acceptance-fixture.js +55 -0
  12. package/dist/src/vector-cortex/rollout/_acceptance-helpers.js +8 -0
  13. package/dist/src/vector-cortex/rollout/_acceptance-scenario.js +70 -0
  14. package/dist/src/vector-cortex/rollout/assign.js +56 -0
  15. package/dist/src/vector-cortex/rollout/emit.js +50 -0
  16. package/dist/src/vector-cortex/rollout/gate.js +75 -0
  17. package/dist/src/vector-cortex/rollout/types.js +39 -0
  18. package/dist/vector-cortex/rollout/_acceptance-fixture.js +55 -0
  19. package/dist/vector-cortex/rollout/_acceptance-helpers.js +8 -0
  20. package/dist/vector-cortex/rollout/_acceptance-scenario.js +70 -0
  21. package/dist/vector-cortex/rollout/assign.js +56 -0
  22. package/dist/vector-cortex/rollout/emit.js +50 -0
  23. package/dist/vector-cortex/rollout/gate.js +75 -0
  24. package/dist/vector-cortex/rollout/types.js +39 -0
  25. package/extensions/dashboard-client/dist/assets/{AreaChart-CGL29Tcl.js → AreaChart-DqTbaSRA.js} +2 -2
  26. package/extensions/dashboard-client/dist/assets/{AreaChart-CGL29Tcl.js.map → AreaChart-DqTbaSRA.js.map} +1 -1
  27. package/extensions/dashboard-client/dist/assets/{BarChart-OxhalIZa.js → BarChart-BfNBeOvF.js} +2 -2
  28. package/extensions/dashboard-client/dist/assets/{BarChart-OxhalIZa.js.map → BarChart-BfNBeOvF.js.map} +1 -1
  29. package/extensions/dashboard-client/dist/assets/{CacheTab-VcMFwL-6.js → CacheTab-C9SOMYB5.js} +2 -2
  30. package/extensions/dashboard-client/dist/assets/{CacheTab-VcMFwL-6.js.map → CacheTab-C9SOMYB5.js.map} +1 -1
  31. package/extensions/dashboard-client/dist/assets/{EventsTab-DePofXDM.js → EventsTab-GsMKP10_.js} +2 -2
  32. package/extensions/dashboard-client/dist/assets/{EventsTab-DePofXDM.js.map → EventsTab-GsMKP10_.js.map} +1 -1
  33. package/extensions/dashboard-client/dist/assets/{HealthTab-nQd1tjSF.js → HealthTab-DAOCXwRP.js} +2 -2
  34. package/extensions/dashboard-client/dist/assets/{HealthTab-nQd1tjSF.js.map → HealthTab-DAOCXwRP.js.map} +1 -1
  35. package/extensions/dashboard-client/dist/assets/{MaintenanceTab-CzvA8-F6.js → MaintenanceTab-BtBeMkB5.js} +2 -2
  36. package/extensions/dashboard-client/dist/assets/{MaintenanceTab-CzvA8-F6.js.map → MaintenanceTab-BtBeMkB5.js.map} +1 -1
  37. package/extensions/dashboard-client/dist/assets/{MemoryMapTab-3lxgWBvU.js → MemoryMapTab-DzndtgkZ.js} +2 -2
  38. package/extensions/dashboard-client/dist/assets/{MemoryMapTab-3lxgWBvU.js.map → MemoryMapTab-DzndtgkZ.js.map} +1 -1
  39. package/extensions/dashboard-client/dist/assets/{MetricsTab-D_FcA6kN.js → MetricsTab-DyxJ4eb8.js} +2 -2
  40. package/extensions/dashboard-client/dist/assets/{MetricsTab-D_FcA6kN.js.map → MetricsTab-DyxJ4eb8.js.map} +1 -1
  41. package/extensions/dashboard-client/dist/assets/{OverviewTab-BU6R4aEs.js → OverviewTab-DCiEdVWR.js} +2 -2
  42. package/extensions/dashboard-client/dist/assets/{OverviewTab-BU6R4aEs.js.map → OverviewTab-DCiEdVWR.js.map} +1 -1
  43. package/extensions/dashboard-client/dist/assets/{ReposTab-DFjy1isz.js → ReposTab-B5SIqVHA.js} +2 -2
  44. package/extensions/dashboard-client/dist/assets/{ReposTab-DFjy1isz.js.map → ReposTab-B5SIqVHA.js.map} +1 -1
  45. package/extensions/dashboard-client/dist/assets/{SessionsTab-UGIzIH25.js → SessionsTab-DLWFJ9xI.js} +2 -2
  46. package/extensions/dashboard-client/dist/assets/{SessionsTab-UGIzIH25.js.map → SessionsTab-DLWFJ9xI.js.map} +1 -1
  47. package/extensions/dashboard-client/dist/assets/{SetupTab-CECrgMKI.js → SetupTab-CvGXZyej.js} +2 -2
  48. package/extensions/dashboard-client/dist/assets/{SetupTab-CECrgMKI.js.map → SetupTab-CvGXZyej.js.map} +1 -1
  49. package/extensions/dashboard-client/dist/assets/{TimeSavedCard-Dyy4SCDk.js → TimeSavedCard-wZuQGxLS.js} +2 -2
  50. package/extensions/dashboard-client/dist/assets/{TimeSavedCard-Dyy4SCDk.js.map → TimeSavedCard-wZuQGxLS.js.map} +1 -1
  51. package/extensions/dashboard-client/dist/assets/{TurnsTab-B0LPcVs1.js → TurnsTab-B7aOejch.js} +2 -2
  52. package/extensions/dashboard-client/dist/assets/{TurnsTab-B0LPcVs1.js.map → TurnsTab-B7aOejch.js.map} +1 -1
  53. package/extensions/dashboard-client/dist/assets/VectorCortexTab-eHVt9yDx.js +2 -0
  54. package/extensions/dashboard-client/dist/assets/VectorCortexTab-eHVt9yDx.js.map +1 -0
  55. package/extensions/dashboard-client/dist/assets/{WikiTab-DWk9Qvut.js → WikiTab-DhWHjAtt.js} +2 -2
  56. package/extensions/dashboard-client/dist/assets/{WikiTab-DWk9Qvut.js.map → WikiTab-DhWHjAtt.js.map} +1 -1
  57. package/extensions/dashboard-client/dist/assets/{button-O59wPr5H.js → button-BrC-W87h.js} +2 -2
  58. package/extensions/dashboard-client/dist/assets/{button-O59wPr5H.js.map → button-BrC-W87h.js.map} +1 -1
  59. package/extensions/dashboard-client/dist/assets/{card-C-DxXv1-.js → card-0rgfRgr3.js} +2 -2
  60. package/extensions/dashboard-client/dist/assets/{card-C-DxXv1-.js.map → card-0rgfRgr3.js.map} +1 -1
  61. package/extensions/dashboard-client/dist/assets/{generateCategoricalChart-Dw5YnE5s.js → generateCategoricalChart-DRresOQF.js} +2 -2
  62. package/extensions/dashboard-client/dist/assets/{generateCategoricalChart-Dw5YnE5s.js.map → generateCategoricalChart-DRresOQF.js.map} +1 -1
  63. package/extensions/dashboard-client/dist/assets/{index-i9oaPE0a.js → index-DohmtZWL.js} +3 -3
  64. package/extensions/dashboard-client/dist/assets/{index-i9oaPE0a.js.map → index-DohmtZWL.js.map} +1 -1
  65. package/extensions/dashboard-client/dist/assets/{switch-B69QY3IM.js → switch-Bs8g_zB5.js} +2 -2
  66. package/extensions/dashboard-client/dist/assets/{switch-B69QY3IM.js.map → switch-Bs8g_zB5.js.map} +1 -1
  67. package/extensions/dashboard-client/dist/assets/{toggle-BJ4Kwggu.js → toggle-DVVauIo8.js} +2 -2
  68. package/extensions/dashboard-client/dist/assets/{toggle-BJ4Kwggu.js.map → toggle-DVVauIo8.js.map} +1 -1
  69. package/extensions/dashboard-client/dist/assets/{useSSE-BpuA8sPd.js → useSSE-DxH1PTAR.js} +2 -2
  70. package/extensions/dashboard-client/dist/assets/{useSSE-BpuA8sPd.js.map → useSSE-DxH1PTAR.js.map} +1 -1
  71. package/extensions/dashboard-client/dist/index.html +1 -1
  72. package/extensions/dashboard-client/src/api/vector-cortex.ts +9 -0
  73. package/extensions/dashboard-client/src/tabs/VectorCortexRolloutCard.tsx +44 -0
  74. package/extensions/dashboard-client/src/tabs/VectorCortexTab.tsx +8 -0
  75. package/extensions/dashboard-client/src/types/vector-cortex.ts +17 -0
  76. package/extensions/dashboard-server/api-contracts/vector-cortex.ts +32 -1
  77. package/extensions/dashboard-server/routes-rag-settings-helpers.ts +6 -0
  78. package/extensions/dashboard-server/routes-vector-cortex-rollout.ts +52 -0
  79. package/extensions/dashboard-server/routes-vector-cortex.ts +1 -0
  80. package/extensions/dashboard-server/routes.ts +1 -0
  81. package/extensions/dashboard-server/server.ts +2 -0
  82. package/extensions/mega-runtime/vector-cortex-live.ts +165 -0
  83. package/package.json +1 -1
  84. package/src/config/vector-cortex.ts +13 -0
  85. package/src/config.ts +1 -0
  86. package/src/vector-cortex/rollout/_acceptance-fixture.ts +94 -0
  87. package/src/vector-cortex/rollout/_acceptance-helpers.ts +24 -0
  88. package/src/vector-cortex/rollout/_acceptance-scenario.ts +96 -0
  89. package/src/vector-cortex/rollout/assign.ts +67 -0
  90. package/src/vector-cortex/rollout/emit.ts +81 -0
  91. package/src/vector-cortex/rollout/gate.ts +119 -0
  92. package/src/vector-cortex/rollout/types.ts +111 -0
  93. package/extensions/dashboard-client/dist/assets/VectorCortexTab-BWi3u_gp.js +0 -2
  94. package/extensions/dashboard-client/dist/assets/VectorCortexTab-BWi3u_gp.js.map +0 -1
@@ -1,2 +1,2 @@
1
- import{r as s,j as e,h as L,i as W,k as F,p as q,l as K,m as X,C as Y,n as J,o as Q,q as Z,s as ee,t as te,v as se,w as ne,x as ae,y as re}from"./index-i9oaPE0a.js";import{S as le}from"./switch-B69QY3IM.js";import{T as ie}from"./toggle-BJ4Kwggu.js";function oe(t){try{return new Date(t*1e3).toLocaleString()}catch{return"—"}}function G({achievements:t}){const c=s.useRef(0),[n,h]=s.useState(null),l=t.reduce((a,i)=>Math.max(a,i.unlocked_at??0),0),d=c.current;s.useEffect(()=>{l>c.current&&(c.current=l)},[l]),s.useEffect(()=>{if(d>0&&l>d){const a=t.filter(i=>i.unlocked_at!=null&&(i.unlocked_at??0)>d);if(a.length>0){const i=a.map(o=>`${o.icon??""} ${o.title}`.trim()).join(", ")+" unlocked!";h(i);const f=setTimeout(()=>h(null),4e3);return()=>clearTimeout(f)}}},[t,l,d]);const u=t.filter(a=>!(a.hidden===1&&a.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(a=>{if(a.unlocked_at!=null){const i=d>0&&(a.unlocked_at??0)>d;return e.jsxs("div",{className:`ach-tile unlocked${i?" just-unlocked":""}`,children:[a.icon??""," ",a.title,e.jsxs("span",{className:"ach-detail",children:["unlocked ",oe(a.unlocked_at)]})]},a.id)}return e.jsxs("div",{className:"ach-tile locked",children:["??? ",a.title]},a.id)})]})]})}function I(t){return(Math.round(t*10)/10).toString()+"%"}function D(t){return t!=null?new Date(t).toLocaleString():"—"}function O(t){return t&&typeof t=="object"?t:{}}function ce(t){return t.split("/").pop()||t}function _({title:t,rows:c,badge:n,renderValue:h}){return e.jsxs("div",{className:"lb-card",children:[e.jsxs("h3",{children:[t,n]}),c.length===0?e.jsx("div",{className:"lb-empty",children:"—"}):e.jsx("table",{children:e.jsx("tbody",{children:c.map((l,d)=>e.jsxs("tr",{children:[e.jsx("td",{title:l.repo_root,children:ce(l.repo_root)}),e.jsx("td",{className:"num",children:h(l)})]},`${l.repo_root}-${d}`))})})]})}function de(){const[t,c]=s.useState({}),[n,h]=s.useState(0),[l,d]=s.useState([]),[u,a]=s.useState(!1),[i,f]=s.useState(!0),[o,g]=s.useState(null),r=s.useRef(0),p=s.useCallback(async()=>{try{const[b,y,x,N,E,V]=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}),W()]),U=N.find(P=>P.ts>r.current&&P.value>100);r.current>0&&U&&(g(`oopsie! cache went to ${Math.round(U.value)}% — MEGA CACHE 🥧`),setTimeout(()=>g(null),4e3)),N.length>0&&(r.current=Math.max(...N.map(P=>P.ts))),c({cache:b,dedupe:y,turns:x,mega_cache:N}),h(E[0]?.value??0),d(V)}catch{}finally{f(!1)}},[]);s.useEffect(()=>{let b=!0;const y=async()=>{b&&await p()};y();const x=setInterval(()=>void y(),15e3);return()=>{b=!1,clearInterval(x)}},[p]),s.useEffect(()=>{let b=!0;const y=async()=>{try{const N=await F();b&&(a(!!N.game_mode_on),N.theme&&(document.documentElement.dataset.theme=N.theme))}catch{}};y();const x=setInterval(()=>void y(),15e3);return()=>{b=!1,clearInterval(x)}},[]);const S=t.mega_cache??[];let v=null,w=null;for(const b of S){(v==null||b.value>v)&&(v=b.value);const y=O(b.meta),x=y.firstSeenTs??y.firstSeen??b.ts;(w==null||x<w)&&(w=x)}const k=v!=null&&v>100,j=t.turns??[],M=j.reduce((b,y)=>Math.max(b,y.value),0),z=Math.floor(Math.log2(M+1))+1,R=(t.cache?.length??0)>0||(t.dedupe?.length??0)>0||j.length>0||S.length>0||n>0;return e.jsxs("div",{className:`game-tab${u?" game-mode-on":""}`,children:[o!=null&&e.jsx("div",{className:"mega-cache-toast show",children:o}),k&&e.jsxs("div",{className:"mega-cache-banner",children:["🥧"," MEGA CACHE! peak ",I(v)," — first reached ",D(w)]}),k&&e.jsxs("div",{className:"achievement-tile unlocked",children:["🏆"," Opie's Wild Ride",e.jsxs("span",{className:"ach-detail",children:["best ",I(v)," · first ",D(w)]})]}),e.jsx("h2",{children:"High Scores"}),!R&&!i&&e.jsx("div",{className:"game-empty",children:"No scores yet — run a session with game mode on."}),R&&e.jsxs("div",{className:"game-leaderboards",children:[e.jsx(_,{title:"Cache %",rows:t.cache??[],renderValue:b=>I(b.value)}),e.jsx(_,{title:"Dedupe (collapsed)",rows:t.dedupe??[],renderValue:b=>b.value.toLocaleString()}),e.jsx(_,{title:"Turns",rows:j,badge:j.length>0?e.jsxs("span",{className:"lvl-badge",children:["LVL ",z]}):void 0,renderValue:b=>b.value.toLocaleString()}),e.jsx(_,{title:"MEGA CACHE trophies",rows:S,renderValue:b=>e.jsxs(e.Fragment,{children:[I(b.value),e.jsx("span",{className:"lb-meta",children:D(O(b.meta).firstSeenTs??O(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(G,{achievements:l})]})}function me(){const[t,c]=s.useState([]),[n,h]=s.useState(!0),[l,d]=s.useState(null),u=s.useCallback(async()=>{try{const a=await W();c(a),d(null)}catch(a){d(a instanceof Error?a:new Error(String(a)))}finally{h(!1)}},[]);return s.useEffect(()=>{let a=!0;const i=async()=>{a&&await u()};i();const f=setInterval(()=>void i(),15e3);return()=>{a=!1,clearInterval(f)}},[u]),n&&t.length===0?e.jsx("div",{className:"tab-stub",children:"Loading achievements…"}):l&&t.length===0?e.jsxs("div",{className:"tab-stub",children:["Error: ",l.message]}):e.jsxs("div",{className:"achievements-tab",children:[e.jsx("h2",{children:"Achievements"}),e.jsx(G,{achievements:t})]})}const H=[{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.map(t=>t.id),T={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 ue(t,c,n){let h=t.toLocaleString();return c!=null&&n>0&&(h+=` (${Math.round(c*100)}% of ${n.toLocaleString()})`),h}function he(t){return`${Math.round((t||0)*100)}%`}function fe(){const[t,c]=s.useState(null),[n,h]=s.useState(null),[l,d]=s.useState(!1);s.useEffect(()=>{let r=!0;const p=async()=>{try{const v=await K();r&&c(v)}catch{}};p();const S=setInterval(()=>void p(),5e3);return()=>{r=!1,clearInterval(S)}},[]),s.useEffect(()=>{let r=!0;const p=async()=>{try{const v=await F();r&&(h(v),v.theme&&(document.documentElement.dataset.theme=v.theme))}catch{}};p();const S=setInterval(()=>void p(),5e3);return()=>{r=!1,clearInterval(S)}},[]);const u=s.useCallback(async r=>{d(!0);try{const p=await q(r);h(p),p.theme&&(document.documentElement.dataset.theme=p.theme)}catch{}d(!1)},[]),a=n?.game_mode_on??!1,i=n?.theme??"transparent",f=n?.tui_display_mode??"full",o=t?.config,g=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:T.gameMode,children:[e.jsx("input",{type:"checkbox",checked:a,onChange:r=>u({game_mode_on:r.currentTarget.checked}),disabled:l}),"Game Mode"]})}),e.jsx("div",{className:"settings-row",children:e.jsxs("label",{title:T.theme,children:["Theme",e.jsx("select",{value:i,onChange:r=>u({theme:r.currentTarget.value}),disabled:l,children:H.map(r=>e.jsx("option",{value:r.id,children:r.label},r.id))}),e.jsx("button",{type:"button",disabled:l,className:"theme-cycle-btn",title:"Cycle to the next theme (P3)",onClick:()=>{const r=$.indexOf(i),p=$[(r<0?0:r+1)%$.length];p&&u({theme:p})},children:"Next theme →"})]})}),e.jsx("div",{className:"settings-row",children:e.jsxs("label",{title:T.tuiMode,children:["TUI Mode",e.jsxs("select",{value:f,onChange:r=>u({tui_display_mode:r.currentTarget.value}),disabled:l,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:T.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:T.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:T.pressure,children:"Pressure"}),e.jsx("span",{className:"config-value",children:t?he(t.pressure):"—"})]}),e.jsxs("div",{className:"config-item",children:[e.jsx("span",{className:"config-label",title:T.threshold,children:"Threshold"}),e.jsx("span",{className:"config-value",children:o?ue(o.thresholdTokens,o.tierPct,g):"—"})]}),e.jsxs("div",{className:"config-item",children:[e.jsx("span",{className:"config-label",title:T.fastGate,children:"Fast Gate"}),e.jsx("span",{className:"config-value",children:o?`${o.fastGatePct}%`:"—"})]}),e.jsxs("div",{className:"config-item",children:[e.jsx("span",{className:"config-label",children:"Auto"}),e.jsx("span",{className:"config-value",children:o?o.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:o?.anchorUserMessages??"—"})]})]})]})]})}const C={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 ge(){const[t,c]=s.useState(null),[n,h]=s.useState(null),l=s.useCallback(()=>{X().then(c).catch(f=>h(f instanceof Error?f.message:String(f)))},[]);s.useEffect(()=>{l()},[l]),s.useEffect(()=>{const f=setInterval(l,3e4);return()=>clearInterval(f)},[l]);const d=t?.status==="ok",u=t?.status==="ok"?"Working":t?.status==="unreachable"?"Unreachable":"Error",a=d?"#4caf50":"#f44336",i=d?"✓":"✗";return e.jsxs("div",{style:C.section,children:[e.jsx("h3",{style:C.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:C.row,children:[e.jsxs("span",{style:{...C.label,color:`${a}`},children:[i," ",u,":"]}),e.jsxs("span",{style:C.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:C.row,children:[e.jsx("span",{style:C.label,children:"Endpoint:"}),e.jsx("span",{style:C.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 xe({title:t,children:c}){const[n,h]=s.useState(!0),l=`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:()=>h(d=>!d),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":l,children:[e.jsx("span",{children:t}),e.jsx(Y,{className:J("h-4 w-4 text-muted-foreground transition-transform",n&&"rotate-180"),"aria-hidden":"true"})]}),n&&e.jsx("div",{id:l,className:"divide-y divide-border px-4 py-1",children:c})]})}const pe="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 be(){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 je({setting:t,id:c,llmActive:n,saving:h,onUpdate:l}){const[d,u]=s.useState(null),a=t.requiresLlm&&!n,i=s.useRef(null);s.useEffect(()=>()=>{i.current&&clearTimeout(i.current)},[]);const f=s.useCallback(r=>{l(t.key,r).then(p=>u(p)).catch(p=>u(p instanceof Error?p.message:String(p)))},[l,t.key]),o=s.useCallback(r=>{i.current&&clearTimeout(i.current),i.current=setTimeout(()=>f(r),500)},[f]),g=h||a;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:`${c}-input`,className:"cursor-pointer",children:t.label}),t.requiresLlm&&!n&&e.jsx(be,{})]}),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(le,{id:`${c}-input`,checked:!!t.value,disabled:g||a,onCheckedChange:r=>f(String(r)),"aria-label":t.label}):e.jsxs(e.Fragment,{children:[e.jsx("input",{id:`${c}-input`,type:t.type==="number"?"number":"text",defaultValue:String(t.value??""),min:t.min,max:t.max,disabled:g,onChange:r=>o(r.target.value),className:`${pe} ${t.type==="number"?"w-24":"w-56"}`}),t.unit&&e.jsx("span",{className:"text-xs text-muted-foreground",children:t.unit})]})})]}),d&&e.jsxs("p",{className:"mt-1 text-xs text-danger",children:["Error: ",d]})]})}function ve(){const[t,c]=s.useState(null),[n,h]=s.useState(null),[l,d]=s.useState(!1),[u,a]=s.useState(null),i=s.useCallback(()=>{Q().then(c).catch(o=>h(o instanceof Error?o.message:String(o)))},[]);s.useEffect(()=>{i()},[i]);const f=s.useCallback(async(o,g)=>{d(!0);try{const r=await Z({key:o,value:g});return a(r.restartRequired?"Saved — restart pi to apply changes.":"Saved."),i(),null}catch(r){return r instanceof Error?r.message:String(r)}finally{d(!1)}},[i]);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(o=>e.jsx(xe,{title:o.name,children:o.settings.map(g=>e.jsx(je,{setting:g,id:`${o.name.replace(/[^a-z0-9]+/gi,"-")}-${g.key}`,llmActive:t.llmActive,saving:l,onUpdate:f},g.key))},o.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 m={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}};function ye(){const[t,c]=s.useState(null),[n,h]=s.useState(null),[l,d]=s.useState(null),[u,a]=s.useState(null),[i,f]=s.useState(!1),[o,g]=s.useState(null),[r,p]=s.useState(null),[S,v]=s.useState(null),[w,k]=s.useState(""),j=s.useCallback(()=>{ee().then(c).catch(x=>d(x instanceof Error?x.message:String(x)))},[]),M=s.useCallback((x,N)=>{g(x),v(null),p(null),te({embedder:x,url:N}).then(E=>{p(E),g(null),j()}).catch(E=>{v(E instanceof Error?E.message:String(E)),g(null)})},[j]),z=s.useCallback(()=>{f(!0),a(null),se().then(x=>{h(x),f(!1)}).catch(x=>{a(x instanceof Error?x.message:String(x)),f(!1)})},[]);s.useEffect(()=>{j()},[j]),s.useEffect(()=>{const x=setInterval(j,3e4);return()=>clearInterval(x)},[j]);const R=x=>{switch(x){case"trigram":return"TrigramEmbedder (heuristic, default)";case"http":return"HTTP Embedder (BYO localhost)";case"minilm":return"MiniLM (experimental)";default:return"Unknown"}},b=t?.currentEmbedder==="trigram"&&e.jsxs("div",{style:m.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."]}),y=x=>{const N=x?"#1a5a1a":"#3a1a1a",E=x?"#4caf50":"#f44336";return e.jsx("span",{style:{...m.badge,background:N,color:E},children:x?"Detected":"Not found"})};return e.jsxs("div",{style:m.container,children:[e.jsx("h2",{style:{fontSize:"1.3rem",marginTop:0,marginBottom:"1rem"},children:"Embedder Setup"}),e.jsx(ge,{}),e.jsxs("div",{style:m.section,children:[e.jsx("h3",{style:m.sectionTitle,children:"Current Embedder Configuration"}),l&&e.jsxs("p",{style:{color:"#f44336",fontSize:"0.85rem"},children:["Error: ",l]}),t&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{style:m.row,children:[e.jsx("span",{style:m.label,children:"Active Embedder:"}),e.jsx("span",{style:m.value,children:R(t.currentEmbedder)})]}),"configuredEmbedder"in t&&t.configuredEmbedder!==t.currentEmbedder&&e.jsxs("div",{style:m.warning,children:[e.jsx("strong",{children:"Configured but not active:"})," ",R(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:{...m.row,color:"#ff9800"},children:[e.jsx("span",{style:m.label,children:"Status:"}),e.jsx("span",{style:m.value,children:"Restart required to activate the configured embedder"})]}),e.jsxs("div",{style:m.row,children:[e.jsx("span",{style:m.label,children:"Embedding URL:"}),e.jsx("span",{style:m.value,children:t.embeddingUrl??e.jsx("span",{style:{color:"#888"},children:"not set"})})]}),e.jsxs("div",{style:m.row,children:[e.jsx("span",{style:m.label,children:"Embed Cache:"}),e.jsx("span",{style:m.value,children:t.embedCache??e.jsx("span",{style:{color:"#888"},children:"not set"})})]}),e.jsxs("div",{style:m.row,children:[e.jsx("span",{style:m.label,children:"MiniLM:"}),e.jsx("span",{style:m.value,children:t.minilm?"enabled":"disabled"})]}),b]}),!t&&!l&&e.jsx("p",{style:{color:"#888",fontSize:"0.85rem"},children:"Loading configuration..."})]}),e.jsxs("div",{style:m.section,children:[e.jsx("h3",{style:m.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:m.detectRow,children:[e.jsx("span",{children:e.jsx("strong",{children:"Ollama"})}),n.ollama!==null?e.jsxs("span",{children:[y(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:m.detectRow,children:[e.jsx("span",{children:e.jsx("strong",{children:"llama.cpp"})}),n.llamaCpp!==null?e.jsxs("span",{children:[y(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:m.detectRow,children:[e.jsx("span",{children:e.jsx("strong",{children:"ONNX Runtime"})}),n.onnx!==null?e.jsxs("span",{children:[y(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:m.button,onClick:z,disabled:i,children:i?"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:{...m.button,opacity:n.ollama?.installed?1:.4},onClick:()=>M("ollama"),disabled:!n.ollama?.installed||o!==null,children:o==="ollama"?"Writing...":"Use Ollama"}),e.jsx("button",{style:{...m.button,opacity:n.llamaCpp?.installed?1:.4},onClick:()=>M("llama"),disabled:!n.llamaCpp?.installed||o!==null,children:o==="llama"?"Writing...":"Use llama.cpp"}),e.jsx("button",{style:{...m.button,background:"#444"},onClick:()=>M("trigram"),disabled:o!==null,children:o==="trigram"?"Writing...":"Use Trigram (default)"})]}),r&&e.jsx("div",{style:m.warning,children:r.alreadyActive?"Already active — no restart needed.":`Configured ${r.embedder}. Restart pi to activate (config written to ${r.envPath}).`}),S&&e.jsxs("p",{style:{color:"#f44336",fontSize:"0.85rem",marginTop:"0.5rem"},children:["Configure error: ",S]})]})]}),e.jsxs("div",{style:m.section,children:[e.jsx("h3",{style:m.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:w,onChange:x=>k(x.target.value),style:{flex:"1 1 300px",background:"#12122a",color:"#e0e0e0",border:"1px solid #2a2a4e",borderRadius:"6px",padding:"0.4rem 0.6rem",fontSize:"0.85rem",fontFamily:"monospace"}}),e.jsx("button",{style:{...m.button,opacity:w?1:.4},onClick:()=>M("custom",w),disabled:!w||o!==null,children:o==="custom"?"Writing...":"Use Custom URL"})]}),e.jsxs("div",{style:m.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."]})]}),e.jsxs("div",{style:m.section,children:[e.jsx("h3",{style:m.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:"})," Install"," ",e.jsx("code",{children:"onnxruntime-node"})," in the project root. Not yet integrated — see docs for manual setup."]})]})]}),e.jsxs("div",{style:m.section,children:[e.jsx("h3",{style:m.sectionTitle,children:"Settings"}),e.jsx(ve,{})]})]})}function A(t){return t>=1e6?`${(t/1e6).toFixed(2)}M`:t>=1e3?`${Math.round(t/1e3)}K`:String(t)}function Se(t,c,n){if(t<=0)return"—";const l=(c>0?c:Math.ceil(t*.1))+Math.ceil(t*(n/100)),d=t-l;return d<=0?"0 (at risk)":`${A(d)} tokens`}function B({label:t,value:c,min:n,max:h,step:l=1,onChange:d,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:[c,"%"]})]}),e.jsx("input",{type:"range",min:n,max:h,step:l,value:c,onChange:a=>d(Number(a.target.value)),className:"threshold-slider w-full"}),u&&e.jsxs("p",{className:"text-[10px] text-warning",children:["⚠ ",u]})]})}function we({model:t,defaults:c,safetyRange:n,fireRange:h,onSave:l,onReset:d,saving:u}){const[a,i]=s.useState(t.threshold.safetyMarginPct),[f,o]=s.useState(t.threshold.firePointPct),[g,r]=s.useState(!1),[p,S]=s.useState(null);s.useEffect(()=>{i(t.threshold.safetyMarginPct),o(t.threshold.firePointPct),r(!1)},[t.threshold.safetyMarginPct,t.threshold.firePointPct]);const v=a<5?'Low safety margin — risks "conversation too long" errors when a single turn injects a large tool output between gate fires.':void 0,w=f>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()=>{S(null);try{await l(t.modelId,a,f),r(!1)}catch(j){S(j instanceof Error?j.message:String(j))}},[t.modelId,a,f,l]);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," · ",A(t.contextWindow)," window ·"," ",A(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:Se(t.contextWindow,t.maxTokens,a)})]}),e.jsxs("div",{children:["Compaction fires at:"," ",e.jsx("span",{className:"font-mono text-fg",children:A(Math.ceil(t.contextWindow*(f/100)))})]})]})]}),e.jsxs("div",{className:"grid grid-cols-1 gap-3 sm:grid-cols-2",children:[e.jsx(B,{label:"Safety margin",value:a,min:n[0],max:n[1],onChange:j=>{i(j),r(!0)},warning:v}),e.jsx(B,{label:"Fire point",value:f,min:h[0],max:h[1],onChange:j=>{o(j),r(!0)},warning:w})]}),e.jsxs("div",{className:"mt-2 flex items-center gap-2",children:[e.jsx("button",{type:"button",onClick:k,disabled:!g||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:g?"Save override":"Saved"}),t.threshold.isOverride&&e.jsxs("button",{type:"button",onClick:()=>d(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 (",c.safetyMarginPct,"% /"," ",c.firePointPct,"%)"]}),p&&e.jsx("span",{className:"text-[11px] text-error",children:p})]})]})}function Ne(){const[t,c]=s.useState(null),[n,h]=s.useState(!0),[l,d]=s.useState(null),[u,a]=s.useState(!1),i=s.useCallback(async()=>{try{d(null),c(await ne())}catch(g){d(g instanceof Error?g.message:String(g))}finally{h(!1)}},[]);s.useEffect(()=>{i()},[i]);const f=s.useCallback(async(g,r,p)=>{a(!0);try{await ae({modelId:g,safetyMarginPct:r,firePointPct:p}),await i()}finally{a(!1)}},[i]),o=s.useCallback(async g=>{a(!0);try{await re(g),await i()}finally{a(!1)}},[i]);return n?e.jsx("div",{className:"p-4 text-sm text-fg-muted",children:"Loading thresholds…"}):l?e.jsxs("div",{className:"p-4 text-sm text-error",children:["Error: ",l]}):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(g=>e.jsx(we,{model:g,defaults:t.defaults,safetyRange:t.defaults.safetyMarginRange,fireRange:t.defaults.firePointRange,onSave:f,onReset:o,saving:u},g.modelId))})]}):e.jsx("div",{className:"p-4 text-sm text-fg-muted",children:"No data."})}const Ee=[{id:"embedder",label:"Embedder"},{id:"thresholds",label:"Thresholds"},{id:"config",label:"Config"},{id:"game",label:"Game Mode"},{id:"achievements",label:"Achievements"}];function Me(){const[t,c]=s.useState("embedder");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:Ee.map(n=>e.jsx(ie,{pressed:t===n.id,onClick:()=>c(n.id),children:n.label},n.id))}),t==="embedder"&&e.jsx(ye,{}),t==="thresholds"&&e.jsx(Ne,{}),t==="config"&&e.jsx(fe,{}),t==="game"&&e.jsx(de,{}),t==="achievements"&&e.jsx(me,{})]})}export{Me as default};
2
- //# sourceMappingURL=SetupTab-CECrgMKI.js.map
1
+ import{r as s,j as e,h as L,i as W,k as F,p as q,l as K,m as X,C as Y,n as J,o as Q,q as Z,s as ee,t as te,v as se,w as ne,x as ae,y as re}from"./index-DohmtZWL.js";import{S as le}from"./switch-Bs8g_zB5.js";import{T as ie}from"./toggle-DVVauIo8.js";function oe(t){try{return new Date(t*1e3).toLocaleString()}catch{return"—"}}function G({achievements:t}){const c=s.useRef(0),[n,h]=s.useState(null),l=t.reduce((a,i)=>Math.max(a,i.unlocked_at??0),0),d=c.current;s.useEffect(()=>{l>c.current&&(c.current=l)},[l]),s.useEffect(()=>{if(d>0&&l>d){const a=t.filter(i=>i.unlocked_at!=null&&(i.unlocked_at??0)>d);if(a.length>0){const i=a.map(o=>`${o.icon??""} ${o.title}`.trim()).join(", ")+" unlocked!";h(i);const f=setTimeout(()=>h(null),4e3);return()=>clearTimeout(f)}}},[t,l,d]);const u=t.filter(a=>!(a.hidden===1&&a.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(a=>{if(a.unlocked_at!=null){const i=d>0&&(a.unlocked_at??0)>d;return e.jsxs("div",{className:`ach-tile unlocked${i?" just-unlocked":""}`,children:[a.icon??""," ",a.title,e.jsxs("span",{className:"ach-detail",children:["unlocked ",oe(a.unlocked_at)]})]},a.id)}return e.jsxs("div",{className:"ach-tile locked",children:["??? ",a.title]},a.id)})]})]})}function I(t){return(Math.round(t*10)/10).toString()+"%"}function D(t){return t!=null?new Date(t).toLocaleString():"—"}function O(t){return t&&typeof t=="object"?t:{}}function ce(t){return t.split("/").pop()||t}function _({title:t,rows:c,badge:n,renderValue:h}){return e.jsxs("div",{className:"lb-card",children:[e.jsxs("h3",{children:[t,n]}),c.length===0?e.jsx("div",{className:"lb-empty",children:"—"}):e.jsx("table",{children:e.jsx("tbody",{children:c.map((l,d)=>e.jsxs("tr",{children:[e.jsx("td",{title:l.repo_root,children:ce(l.repo_root)}),e.jsx("td",{className:"num",children:h(l)})]},`${l.repo_root}-${d}`))})})]})}function de(){const[t,c]=s.useState({}),[n,h]=s.useState(0),[l,d]=s.useState([]),[u,a]=s.useState(!1),[i,f]=s.useState(!0),[o,g]=s.useState(null),r=s.useRef(0),p=s.useCallback(async()=>{try{const[b,y,x,N,E,V]=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}),W()]),U=N.find(P=>P.ts>r.current&&P.value>100);r.current>0&&U&&(g(`oopsie! cache went to ${Math.round(U.value)}% — MEGA CACHE 🥧`),setTimeout(()=>g(null),4e3)),N.length>0&&(r.current=Math.max(...N.map(P=>P.ts))),c({cache:b,dedupe:y,turns:x,mega_cache:N}),h(E[0]?.value??0),d(V)}catch{}finally{f(!1)}},[]);s.useEffect(()=>{let b=!0;const y=async()=>{b&&await p()};y();const x=setInterval(()=>void y(),15e3);return()=>{b=!1,clearInterval(x)}},[p]),s.useEffect(()=>{let b=!0;const y=async()=>{try{const N=await F();b&&(a(!!N.game_mode_on),N.theme&&(document.documentElement.dataset.theme=N.theme))}catch{}};y();const x=setInterval(()=>void y(),15e3);return()=>{b=!1,clearInterval(x)}},[]);const S=t.mega_cache??[];let v=null,w=null;for(const b of S){(v==null||b.value>v)&&(v=b.value);const y=O(b.meta),x=y.firstSeenTs??y.firstSeen??b.ts;(w==null||x<w)&&(w=x)}const k=v!=null&&v>100,j=t.turns??[],M=j.reduce((b,y)=>Math.max(b,y.value),0),z=Math.floor(Math.log2(M+1))+1,R=(t.cache?.length??0)>0||(t.dedupe?.length??0)>0||j.length>0||S.length>0||n>0;return e.jsxs("div",{className:`game-tab${u?" game-mode-on":""}`,children:[o!=null&&e.jsx("div",{className:"mega-cache-toast show",children:o}),k&&e.jsxs("div",{className:"mega-cache-banner",children:["🥧"," MEGA CACHE! peak ",I(v)," — first reached ",D(w)]}),k&&e.jsxs("div",{className:"achievement-tile unlocked",children:["🏆"," Opie's Wild Ride",e.jsxs("span",{className:"ach-detail",children:["best ",I(v)," · first ",D(w)]})]}),e.jsx("h2",{children:"High Scores"}),!R&&!i&&e.jsx("div",{className:"game-empty",children:"No scores yet — run a session with game mode on."}),R&&e.jsxs("div",{className:"game-leaderboards",children:[e.jsx(_,{title:"Cache %",rows:t.cache??[],renderValue:b=>I(b.value)}),e.jsx(_,{title:"Dedupe (collapsed)",rows:t.dedupe??[],renderValue:b=>b.value.toLocaleString()}),e.jsx(_,{title:"Turns",rows:j,badge:j.length>0?e.jsxs("span",{className:"lvl-badge",children:["LVL ",z]}):void 0,renderValue:b=>b.value.toLocaleString()}),e.jsx(_,{title:"MEGA CACHE trophies",rows:S,renderValue:b=>e.jsxs(e.Fragment,{children:[I(b.value),e.jsx("span",{className:"lb-meta",children:D(O(b.meta).firstSeenTs??O(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(G,{achievements:l})]})}function me(){const[t,c]=s.useState([]),[n,h]=s.useState(!0),[l,d]=s.useState(null),u=s.useCallback(async()=>{try{const a=await W();c(a),d(null)}catch(a){d(a instanceof Error?a:new Error(String(a)))}finally{h(!1)}},[]);return s.useEffect(()=>{let a=!0;const i=async()=>{a&&await u()};i();const f=setInterval(()=>void i(),15e3);return()=>{a=!1,clearInterval(f)}},[u]),n&&t.length===0?e.jsx("div",{className:"tab-stub",children:"Loading achievements…"}):l&&t.length===0?e.jsxs("div",{className:"tab-stub",children:["Error: ",l.message]}):e.jsxs("div",{className:"achievements-tab",children:[e.jsx("h2",{children:"Achievements"}),e.jsx(G,{achievements:t})]})}const H=[{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.map(t=>t.id),T={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 ue(t,c,n){let h=t.toLocaleString();return c!=null&&n>0&&(h+=` (${Math.round(c*100)}% of ${n.toLocaleString()})`),h}function he(t){return`${Math.round((t||0)*100)}%`}function fe(){const[t,c]=s.useState(null),[n,h]=s.useState(null),[l,d]=s.useState(!1);s.useEffect(()=>{let r=!0;const p=async()=>{try{const v=await K();r&&c(v)}catch{}};p();const S=setInterval(()=>void p(),5e3);return()=>{r=!1,clearInterval(S)}},[]),s.useEffect(()=>{let r=!0;const p=async()=>{try{const v=await F();r&&(h(v),v.theme&&(document.documentElement.dataset.theme=v.theme))}catch{}};p();const S=setInterval(()=>void p(),5e3);return()=>{r=!1,clearInterval(S)}},[]);const u=s.useCallback(async r=>{d(!0);try{const p=await q(r);h(p),p.theme&&(document.documentElement.dataset.theme=p.theme)}catch{}d(!1)},[]),a=n?.game_mode_on??!1,i=n?.theme??"transparent",f=n?.tui_display_mode??"full",o=t?.config,g=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:T.gameMode,children:[e.jsx("input",{type:"checkbox",checked:a,onChange:r=>u({game_mode_on:r.currentTarget.checked}),disabled:l}),"Game Mode"]})}),e.jsx("div",{className:"settings-row",children:e.jsxs("label",{title:T.theme,children:["Theme",e.jsx("select",{value:i,onChange:r=>u({theme:r.currentTarget.value}),disabled:l,children:H.map(r=>e.jsx("option",{value:r.id,children:r.label},r.id))}),e.jsx("button",{type:"button",disabled:l,className:"theme-cycle-btn",title:"Cycle to the next theme (P3)",onClick:()=>{const r=$.indexOf(i),p=$[(r<0?0:r+1)%$.length];p&&u({theme:p})},children:"Next theme →"})]})}),e.jsx("div",{className:"settings-row",children:e.jsxs("label",{title:T.tuiMode,children:["TUI Mode",e.jsxs("select",{value:f,onChange:r=>u({tui_display_mode:r.currentTarget.value}),disabled:l,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:T.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:T.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:T.pressure,children:"Pressure"}),e.jsx("span",{className:"config-value",children:t?he(t.pressure):"—"})]}),e.jsxs("div",{className:"config-item",children:[e.jsx("span",{className:"config-label",title:T.threshold,children:"Threshold"}),e.jsx("span",{className:"config-value",children:o?ue(o.thresholdTokens,o.tierPct,g):"—"})]}),e.jsxs("div",{className:"config-item",children:[e.jsx("span",{className:"config-label",title:T.fastGate,children:"Fast Gate"}),e.jsx("span",{className:"config-value",children:o?`${o.fastGatePct}%`:"—"})]}),e.jsxs("div",{className:"config-item",children:[e.jsx("span",{className:"config-label",children:"Auto"}),e.jsx("span",{className:"config-value",children:o?o.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:o?.anchorUserMessages??"—"})]})]})]})]})}const C={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 ge(){const[t,c]=s.useState(null),[n,h]=s.useState(null),l=s.useCallback(()=>{X().then(c).catch(f=>h(f instanceof Error?f.message:String(f)))},[]);s.useEffect(()=>{l()},[l]),s.useEffect(()=>{const f=setInterval(l,3e4);return()=>clearInterval(f)},[l]);const d=t?.status==="ok",u=t?.status==="ok"?"Working":t?.status==="unreachable"?"Unreachable":"Error",a=d?"#4caf50":"#f44336",i=d?"✓":"✗";return e.jsxs("div",{style:C.section,children:[e.jsx("h3",{style:C.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:C.row,children:[e.jsxs("span",{style:{...C.label,color:`${a}`},children:[i," ",u,":"]}),e.jsxs("span",{style:C.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:C.row,children:[e.jsx("span",{style:C.label,children:"Endpoint:"}),e.jsx("span",{style:C.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 xe({title:t,children:c}){const[n,h]=s.useState(!0),l=`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:()=>h(d=>!d),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":l,children:[e.jsx("span",{children:t}),e.jsx(Y,{className:J("h-4 w-4 text-muted-foreground transition-transform",n&&"rotate-180"),"aria-hidden":"true"})]}),n&&e.jsx("div",{id:l,className:"divide-y divide-border px-4 py-1",children:c})]})}const pe="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 be(){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 je({setting:t,id:c,llmActive:n,saving:h,onUpdate:l}){const[d,u]=s.useState(null),a=t.requiresLlm&&!n,i=s.useRef(null);s.useEffect(()=>()=>{i.current&&clearTimeout(i.current)},[]);const f=s.useCallback(r=>{l(t.key,r).then(p=>u(p)).catch(p=>u(p instanceof Error?p.message:String(p)))},[l,t.key]),o=s.useCallback(r=>{i.current&&clearTimeout(i.current),i.current=setTimeout(()=>f(r),500)},[f]),g=h||a;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:`${c}-input`,className:"cursor-pointer",children:t.label}),t.requiresLlm&&!n&&e.jsx(be,{})]}),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(le,{id:`${c}-input`,checked:!!t.value,disabled:g||a,onCheckedChange:r=>f(String(r)),"aria-label":t.label}):e.jsxs(e.Fragment,{children:[e.jsx("input",{id:`${c}-input`,type:t.type==="number"?"number":"text",defaultValue:String(t.value??""),min:t.min,max:t.max,disabled:g,onChange:r=>o(r.target.value),className:`${pe} ${t.type==="number"?"w-24":"w-56"}`}),t.unit&&e.jsx("span",{className:"text-xs text-muted-foreground",children:t.unit})]})})]}),d&&e.jsxs("p",{className:"mt-1 text-xs text-danger",children:["Error: ",d]})]})}function ve(){const[t,c]=s.useState(null),[n,h]=s.useState(null),[l,d]=s.useState(!1),[u,a]=s.useState(null),i=s.useCallback(()=>{Q().then(c).catch(o=>h(o instanceof Error?o.message:String(o)))},[]);s.useEffect(()=>{i()},[i]);const f=s.useCallback(async(o,g)=>{d(!0);try{const r=await Z({key:o,value:g});return a(r.restartRequired?"Saved — restart pi to apply changes.":"Saved."),i(),null}catch(r){return r instanceof Error?r.message:String(r)}finally{d(!1)}},[i]);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(o=>e.jsx(xe,{title:o.name,children:o.settings.map(g=>e.jsx(je,{setting:g,id:`${o.name.replace(/[^a-z0-9]+/gi,"-")}-${g.key}`,llmActive:t.llmActive,saving:l,onUpdate:f},g.key))},o.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 m={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}};function ye(){const[t,c]=s.useState(null),[n,h]=s.useState(null),[l,d]=s.useState(null),[u,a]=s.useState(null),[i,f]=s.useState(!1),[o,g]=s.useState(null),[r,p]=s.useState(null),[S,v]=s.useState(null),[w,k]=s.useState(""),j=s.useCallback(()=>{ee().then(c).catch(x=>d(x instanceof Error?x.message:String(x)))},[]),M=s.useCallback((x,N)=>{g(x),v(null),p(null),te({embedder:x,url:N}).then(E=>{p(E),g(null),j()}).catch(E=>{v(E instanceof Error?E.message:String(E)),g(null)})},[j]),z=s.useCallback(()=>{f(!0),a(null),se().then(x=>{h(x),f(!1)}).catch(x=>{a(x instanceof Error?x.message:String(x)),f(!1)})},[]);s.useEffect(()=>{j()},[j]),s.useEffect(()=>{const x=setInterval(j,3e4);return()=>clearInterval(x)},[j]);const R=x=>{switch(x){case"trigram":return"TrigramEmbedder (heuristic, default)";case"http":return"HTTP Embedder (BYO localhost)";case"minilm":return"MiniLM (experimental)";default:return"Unknown"}},b=t?.currentEmbedder==="trigram"&&e.jsxs("div",{style:m.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."]}),y=x=>{const N=x?"#1a5a1a":"#3a1a1a",E=x?"#4caf50":"#f44336";return e.jsx("span",{style:{...m.badge,background:N,color:E},children:x?"Detected":"Not found"})};return e.jsxs("div",{style:m.container,children:[e.jsx("h2",{style:{fontSize:"1.3rem",marginTop:0,marginBottom:"1rem"},children:"Embedder Setup"}),e.jsx(ge,{}),e.jsxs("div",{style:m.section,children:[e.jsx("h3",{style:m.sectionTitle,children:"Current Embedder Configuration"}),l&&e.jsxs("p",{style:{color:"#f44336",fontSize:"0.85rem"},children:["Error: ",l]}),t&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{style:m.row,children:[e.jsx("span",{style:m.label,children:"Active Embedder:"}),e.jsx("span",{style:m.value,children:R(t.currentEmbedder)})]}),"configuredEmbedder"in t&&t.configuredEmbedder!==t.currentEmbedder&&e.jsxs("div",{style:m.warning,children:[e.jsx("strong",{children:"Configured but not active:"})," ",R(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:{...m.row,color:"#ff9800"},children:[e.jsx("span",{style:m.label,children:"Status:"}),e.jsx("span",{style:m.value,children:"Restart required to activate the configured embedder"})]}),e.jsxs("div",{style:m.row,children:[e.jsx("span",{style:m.label,children:"Embedding URL:"}),e.jsx("span",{style:m.value,children:t.embeddingUrl??e.jsx("span",{style:{color:"#888"},children:"not set"})})]}),e.jsxs("div",{style:m.row,children:[e.jsx("span",{style:m.label,children:"Embed Cache:"}),e.jsx("span",{style:m.value,children:t.embedCache??e.jsx("span",{style:{color:"#888"},children:"not set"})})]}),e.jsxs("div",{style:m.row,children:[e.jsx("span",{style:m.label,children:"MiniLM:"}),e.jsx("span",{style:m.value,children:t.minilm?"enabled":"disabled"})]}),b]}),!t&&!l&&e.jsx("p",{style:{color:"#888",fontSize:"0.85rem"},children:"Loading configuration..."})]}),e.jsxs("div",{style:m.section,children:[e.jsx("h3",{style:m.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:m.detectRow,children:[e.jsx("span",{children:e.jsx("strong",{children:"Ollama"})}),n.ollama!==null?e.jsxs("span",{children:[y(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:m.detectRow,children:[e.jsx("span",{children:e.jsx("strong",{children:"llama.cpp"})}),n.llamaCpp!==null?e.jsxs("span",{children:[y(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:m.detectRow,children:[e.jsx("span",{children:e.jsx("strong",{children:"ONNX Runtime"})}),n.onnx!==null?e.jsxs("span",{children:[y(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:m.button,onClick:z,disabled:i,children:i?"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:{...m.button,opacity:n.ollama?.installed?1:.4},onClick:()=>M("ollama"),disabled:!n.ollama?.installed||o!==null,children:o==="ollama"?"Writing...":"Use Ollama"}),e.jsx("button",{style:{...m.button,opacity:n.llamaCpp?.installed?1:.4},onClick:()=>M("llama"),disabled:!n.llamaCpp?.installed||o!==null,children:o==="llama"?"Writing...":"Use llama.cpp"}),e.jsx("button",{style:{...m.button,background:"#444"},onClick:()=>M("trigram"),disabled:o!==null,children:o==="trigram"?"Writing...":"Use Trigram (default)"})]}),r&&e.jsx("div",{style:m.warning,children:r.alreadyActive?"Already active — no restart needed.":`Configured ${r.embedder}. Restart pi to activate (config written to ${r.envPath}).`}),S&&e.jsxs("p",{style:{color:"#f44336",fontSize:"0.85rem",marginTop:"0.5rem"},children:["Configure error: ",S]})]})]}),e.jsxs("div",{style:m.section,children:[e.jsx("h3",{style:m.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:w,onChange:x=>k(x.target.value),style:{flex:"1 1 300px",background:"#12122a",color:"#e0e0e0",border:"1px solid #2a2a4e",borderRadius:"6px",padding:"0.4rem 0.6rem",fontSize:"0.85rem",fontFamily:"monospace"}}),e.jsx("button",{style:{...m.button,opacity:w?1:.4},onClick:()=>M("custom",w),disabled:!w||o!==null,children:o==="custom"?"Writing...":"Use Custom URL"})]}),e.jsxs("div",{style:m.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."]})]}),e.jsxs("div",{style:m.section,children:[e.jsx("h3",{style:m.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:"})," Install"," ",e.jsx("code",{children:"onnxruntime-node"})," in the project root. Not yet integrated — see docs for manual setup."]})]})]}),e.jsxs("div",{style:m.section,children:[e.jsx("h3",{style:m.sectionTitle,children:"Settings"}),e.jsx(ve,{})]})]})}function A(t){return t>=1e6?`${(t/1e6).toFixed(2)}M`:t>=1e3?`${Math.round(t/1e3)}K`:String(t)}function Se(t,c,n){if(t<=0)return"—";const l=(c>0?c:Math.ceil(t*.1))+Math.ceil(t*(n/100)),d=t-l;return d<=0?"0 (at risk)":`${A(d)} tokens`}function B({label:t,value:c,min:n,max:h,step:l=1,onChange:d,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:[c,"%"]})]}),e.jsx("input",{type:"range",min:n,max:h,step:l,value:c,onChange:a=>d(Number(a.target.value)),className:"threshold-slider w-full"}),u&&e.jsxs("p",{className:"text-[10px] text-warning",children:["⚠ ",u]})]})}function we({model:t,defaults:c,safetyRange:n,fireRange:h,onSave:l,onReset:d,saving:u}){const[a,i]=s.useState(t.threshold.safetyMarginPct),[f,o]=s.useState(t.threshold.firePointPct),[g,r]=s.useState(!1),[p,S]=s.useState(null);s.useEffect(()=>{i(t.threshold.safetyMarginPct),o(t.threshold.firePointPct),r(!1)},[t.threshold.safetyMarginPct,t.threshold.firePointPct]);const v=a<5?'Low safety margin — risks "conversation too long" errors when a single turn injects a large tool output between gate fires.':void 0,w=f>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()=>{S(null);try{await l(t.modelId,a,f),r(!1)}catch(j){S(j instanceof Error?j.message:String(j))}},[t.modelId,a,f,l]);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," · ",A(t.contextWindow)," window ·"," ",A(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:Se(t.contextWindow,t.maxTokens,a)})]}),e.jsxs("div",{children:["Compaction fires at:"," ",e.jsx("span",{className:"font-mono text-fg",children:A(Math.ceil(t.contextWindow*(f/100)))})]})]})]}),e.jsxs("div",{className:"grid grid-cols-1 gap-3 sm:grid-cols-2",children:[e.jsx(B,{label:"Safety margin",value:a,min:n[0],max:n[1],onChange:j=>{i(j),r(!0)},warning:v}),e.jsx(B,{label:"Fire point",value:f,min:h[0],max:h[1],onChange:j=>{o(j),r(!0)},warning:w})]}),e.jsxs("div",{className:"mt-2 flex items-center gap-2",children:[e.jsx("button",{type:"button",onClick:k,disabled:!g||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:g?"Save override":"Saved"}),t.threshold.isOverride&&e.jsxs("button",{type:"button",onClick:()=>d(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 (",c.safetyMarginPct,"% /"," ",c.firePointPct,"%)"]}),p&&e.jsx("span",{className:"text-[11px] text-error",children:p})]})]})}function Ne(){const[t,c]=s.useState(null),[n,h]=s.useState(!0),[l,d]=s.useState(null),[u,a]=s.useState(!1),i=s.useCallback(async()=>{try{d(null),c(await ne())}catch(g){d(g instanceof Error?g.message:String(g))}finally{h(!1)}},[]);s.useEffect(()=>{i()},[i]);const f=s.useCallback(async(g,r,p)=>{a(!0);try{await ae({modelId:g,safetyMarginPct:r,firePointPct:p}),await i()}finally{a(!1)}},[i]),o=s.useCallback(async g=>{a(!0);try{await re(g),await i()}finally{a(!1)}},[i]);return n?e.jsx("div",{className:"p-4 text-sm text-fg-muted",children:"Loading thresholds…"}):l?e.jsxs("div",{className:"p-4 text-sm text-error",children:["Error: ",l]}):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(g=>e.jsx(we,{model:g,defaults:t.defaults,safetyRange:t.defaults.safetyMarginRange,fireRange:t.defaults.firePointRange,onSave:f,onReset:o,saving:u},g.modelId))})]}):e.jsx("div",{className:"p-4 text-sm text-fg-muted",children:"No data."})}const Ee=[{id:"embedder",label:"Embedder"},{id:"thresholds",label:"Thresholds"},{id:"config",label:"Config"},{id:"game",label:"Game Mode"},{id:"achievements",label:"Achievements"}];function Me(){const[t,c]=s.useState("embedder");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:Ee.map(n=>e.jsx(ie,{pressed:t===n.id,onClick:()=>c(n.id),children:n.label},n.id))}),t==="embedder"&&e.jsx(ye,{}),t==="thresholds"&&e.jsx(Ne,{}),t==="config"&&e.jsx(fe,{}),t==="game"&&e.jsx(de,{}),t==="achievements"&&e.jsx(me,{})]})}export{Me as default};
2
+ //# sourceMappingURL=SetupTab-CvGXZyej.js.map