opencode-rag-plugin 2.10.1 → 2.11.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/ReadMe.md +40 -28
- package/dist/api.js +1 -0
- package/dist/chunker/grammar.d.ts +4 -1
- package/dist/chunker/grammar.js +9 -3
- package/dist/chunker/skeleton.js +61 -4
- package/dist/cli/commands/clickhouse.d.ts +61 -0
- package/dist/cli/commands/clickhouse.js +335 -0
- package/dist/cli/commands/eval-tuner.js +1 -1
- package/dist/cli/commands/eval.js +1 -1
- package/dist/cli/commands/index-command.js +2 -1
- package/dist/cli/commands/index.d.ts +1 -0
- package/dist/cli/commands/index.js +1 -0
- package/dist/cli/commands/init-helpers.js +2 -2
- package/dist/cli/commands/init.js +49 -11
- package/dist/cli/commands/quirk.js +6 -6
- package/dist/cli/commands/status.js +70 -6
- package/dist/cli/commands/ui.js +2 -2
- package/dist/cli/index.js +2 -1
- package/dist/cli/types.d.ts +14 -0
- package/dist/core/bootstrap.d.ts +7 -0
- package/dist/core/bootstrap.js +40 -9
- package/dist/core/config.d.ts +128 -5
- package/dist/core/config.js +205 -8
- package/dist/core/interfaces.d.ts +54 -0
- package/dist/core/runtime-overrides.d.ts +9 -0
- package/dist/core/runtime-overrides.js +44 -0
- package/dist/core/state-sync.d.ts +91 -0
- package/dist/core/state-sync.js +273 -0
- package/dist/eval/fast-index.js +2 -2
- package/dist/eval/rerank-eval.js +2 -2
- package/dist/eval/run-branch-compare.js +2 -2
- package/dist/eval/run-token-test.js +2 -2
- package/dist/index.d.ts +5 -2
- package/dist/index.js +2 -1
- package/dist/indexer/pipeline.d.ts +6 -0
- package/dist/indexer/pipeline.js +173 -56
- package/dist/indexer/progress.d.ts +75 -0
- package/dist/indexer/progress.js +114 -0
- package/dist/indexer/stats.d.ts +14 -0
- package/dist/plugin.d.ts +6 -3
- package/dist/plugin.js +39 -20
- package/dist/quirks/quirk-store.d.ts +10 -0
- package/dist/quirks/quirk-store.js +110 -15
- package/dist/quirks/types.d.ts +7 -0
- package/dist/tui.js +128 -111
- package/dist/vectorstore/clickhouse.d.ts +150 -0
- package/dist/vectorstore/clickhouse.js +931 -0
- package/dist/vectorstore/dimension.d.ts +19 -0
- package/dist/vectorstore/dimension.js +36 -0
- package/dist/vectorstore/factory.d.ts +9 -3
- package/dist/vectorstore/factory.js +11 -2
- package/dist/vectorstore/lancedb.d.ts +2 -2
- package/dist/watcher.d.ts +29 -0
- package/dist/watcher.js +76 -2
- package/dist/web/api.d.ts +3 -4
- package/dist/web/api.js +18 -3
- package/dist/web/server.js +28 -2
- package/dist/web/ui/assets/{ScatterPlot3D-CKwyh1Ec.js → ScatterPlot3D-XjXIwavM.js} +5 -5
- package/dist/web/ui/assets/index-B-RH6fko.css +2 -0
- package/dist/web/ui/assets/index-FFPRbgLx.js +4 -0
- package/dist/web/ui/index.html +2 -2
- package/package.json +7 -2
- package/dist/web/ui/assets/index-CWcp0jNf.css +0 -2
- package/dist/web/ui/assets/index-DbXFrn53.js +0 -4
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/ScatterPlot3D-CKwyh1Ec.js","assets/vendor-Dg8wMT7C.js"])))=>i.map(i=>d[i]);
|
|
2
|
-
import{a as e,c as t,d as n,f as r,i,l as a,n as o,o as s,p as c,r as l,s as u,t as d,u as f}from"./vendor-Dg8wMT7C.js";(function(){let e=document.createElement(`link`).relList;if(e&&e.supports&&e.supports(`modulepreload`))return;for(let e of document.querySelectorAll(`link[rel="modulepreload"]`))n(e);new MutationObserver(e=>{for(let t of e)if(t.type===`childList`)for(let e of t.addedNodes)e.tagName===`LINK`&&e.rel===`modulepreload`&&n(e)}).observe(document,{childList:!0,subtree:!0});function t(e){let t={};return e.integrity&&(t.integrity=e.integrity),e.referrerPolicy&&(t.referrerPolicy=e.referrerPolicy),t.credentials=e.crossOrigin===`use-credentials`?`include`:e.crossOrigin===`anonymous`?`omit`:`same-origin`,t}function n(e){if(e.ep)return;e.ep=!0;let n=t(e);fetch(e.href,n)}})();function p(){let e=location.hash.slice(1)||`dashboard`,t=e.indexOf(`?`),n=t>=0?e.slice(0,t):e,r={};if(t>=0){let n=e.slice(t+1);for(let e of n.split(`&`)){let t=e.indexOf(`=`);if(t>=0)try{r[decodeURIComponent(e.slice(0,t))]=decodeURIComponent(e.slice(t+1))}catch{}}}return{view:n||`dashboard`,params:r}}function m(){let[e,t]=s(p);return u(()=>{let e=()=>t(p());return addEventListener(`hashchange`,e),()=>removeEventListener(`hashchange`,e)},[]),e}var h=Symbol.for(`preact-signals`);function g(){if(S>1)S--;else{var e,t=!1;for((function(){var e=T;for(T=void 0;e!==void 0;){var t=e.S;if(t.v===e.v)for(var n=t.t;n!==void 0;n=n.x)n.i===e.i&&(n.i=t.i);e=e.o}})();x!==void 0;){var n=x;for(x=void 0,C++;n!==void 0;){var r=n.u;if(n.u=void 0,n.f&=-3,!(8&n.f)&&re(n))try{n.c()}catch(n){t||=(e=n,!0)}n=r}}if(C=0,S--,t)throw e}}function _(e){if(S>0)return e();w=++ee,S++;try{return e()}finally{g()}}var v,y=void 0;function b(e){var t=y,n=v;y=void 0,v=void 0;try{return e()}finally{y=t,v=n}}var x=void 0,S=0,C=0,ee=0,w=0,T=void 0,te=0;function ne(e){if(y!==void 0){var t=e.n;if(t===void 0||t.t!==y)return t={i:0,S:e,p:y.s,n:void 0,t:y,e:void 0,x:void 0,r:t},y.s!==void 0&&(y.s.n=t),y.s=t,e.n=t,32&y.f&&e.S(t),t;if(t.i===-1)return t.i=0,t.n!==void 0&&(t.n.p=t.p,t.p!==void 0&&(t.p.n=t.n),t.p=y.s,t.n=void 0,y.s.n=t,y.s=t),t}}function E(e,t){this.v=e,this.i=0,this.n=void 0,this.t=void 0,this.l=0,this.W=t?.watched,this.Z=t?.unwatched,this.name=t?.name}E.prototype.brand=h,E.prototype.h=function(){return!0},E.prototype.S=function(e){var t=this,n=this.t;n!==e&&e.e===void 0&&(e.x=n,this.t=e,n===void 0?b(function(){var e;(e=t.W)==null||e.call(t)}):n.e=e)},E.prototype.U=function(e){var t=this;if(this.t!==void 0){var n=e.e,r=e.x;n!==void 0&&(n.x=r,e.e=void 0),r!==void 0&&(r.e=n,e.x=void 0),e===this.t&&(this.t=r,r===void 0&&b(function(){var e;(e=t.Z)==null||e.call(t)}))}},E.prototype.subscribe=function(e){var t=this;return j(function(){var n=t.value;b(function(){return e(n)})},{name:`sub`})},E.prototype.valueOf=function(){return this.value},E.prototype.toString=function(){return this.value+``},E.prototype.toJSON=function(){return this.value},E.prototype.peek=function(){var e=this;return b(function(){return e.value})},Object.defineProperty(E.prototype,"value",{get:function(){var e=ne(this);return e!==void 0&&(e.i=this.i),this.v},set:function(e){if(e!==this.v){if(C>100)throw Error(`Cycle detected`);(function(e){S!==0&&C===0&&e.l!==w&&(e.l=w,T={S:e,v:e.v,i:e.i,o:T})})(this),this.v=e,this.i++,te++,S++;try{for(var t=this.t;t!==void 0;t=t.x)t.t.N()}finally{g()}}}});function D(e,t){return new E(e,t)}function re(e){for(var t=e.s;t!==void 0;t=t.n)if(t.S.i!==t.i||!t.S.h()||t.S.i!==t.i)return!0;return!1}function ie(e){for(var t=e.s;t!==void 0;t=t.n){var n=t.S.n;if(n!==void 0&&(t.r=n),t.S.n=t,t.i=-1,t.n===void 0){e.s=t;break}}}function ae(e){for(var t=e.s,n=void 0;t!==void 0;){var r=t.p;t.i===-1?(t.S.U(t),r!==void 0&&(r.n=t.n),t.n!==void 0&&(t.n.p=r)):n=t,t.S.n=t.r,t.r!==void 0&&(t.r=void 0),t=r}e.s=n}function O(e,t){E.call(this,void 0,t),this.x=e,this.s=void 0,this.g=te-1,this.f=4}O.prototype=new E,O.prototype.h=function(){if(this.f&=-3,1&this.f)return!1;if((36&this.f)==32||(this.f&=-5,this.g===te))return!0;if(this.g=te,this.f|=1,this.i>0&&!re(this))return this.f&=-2,!0;var e=y;try{ie(this),y=this;var t=this.x();(16&this.f||this.v!==t||this.i===0)&&(this.v=t,this.f&=-17,this.i++)}catch(e){this.v=e,this.f|=16,this.i++}return y=e,ae(this),this.f&=-2,!0},O.prototype.S=function(e){if(this.t===void 0){this.f|=36;for(var t=this.s;t!==void 0;t=t.n)t.S.S(t)}E.prototype.S.call(this,e)},O.prototype.U=function(e){if(this.t!==void 0&&(E.prototype.U.call(this,e),this.t===void 0)){this.f&=-33;for(var t=this.s;t!==void 0;t=t.n)t.S.U(t)}},O.prototype.N=function(){if(!(2&this.f)){this.f|=6;for(var e=this.t;e!==void 0;e=e.x)e.t.N()}},Object.defineProperty(O.prototype,"value",{get:function(){if(1&this.f)throw Error(`Cycle detected`);var e=ne(this);if(this.h(),e!==void 0&&(e.i=this.i),16&this.f)throw this.v;return this.v}});function oe(e,t){return new O(e,t)}function se(e){var t=e.m;if(e.m=void 0,typeof t==`function`){S++;var n=y;y=void 0;try{t()}catch(t){throw e.f&=-2,e.f|=8,ce(e),t}finally{y=n,g()}}}function ce(e){for(var t=e.s;t!==void 0;t=t.n)t.S.U(t);e.x=void 0,e.s=void 0,se(e)}function k(e){if(y!==this)throw Error(`Out-of-order effect`);ae(this),y=e,this.f&=-2,8&this.f&&ce(this),g()}function A(e,t){this.x=e,this.m=void 0,this.s=void 0,this.u=void 0,this.f=32,this.name=t?.name,v&&v.push(this)}A.prototype.c=function(){var e=this.S();try{if(8&this.f||this.x===void 0)return;var t=this.x();typeof t==`function`&&(this.m=t)}finally{e()}},A.prototype.S=function(){if(1&this.f)throw Error(`Cycle detected`);this.f|=1,this.f&=-9,se(this),ie(this),S++;var e=y;return y=this,k.bind(this,e)},A.prototype.N=function(){2&this.f||(this.f|=2,this.u=x,x=this)},A.prototype.d=function(){this.f|=8,1&this.f||ce(this)},A.prototype.dispose=function(){this.d()};function j(e,t){var n=new A(e,t);try{n.c()}catch(e){throw n.d(),e}var r=n.d.bind(n);return r[Symbol.dispose]=r,r}var M,N,le=typeof window<`u`&&!!window.__PREACT_SIGNALS_DEVTOOLS__,ue=[],de=[];j(function(){M=this.N})();function fe(e,t){r[e]=t.bind(null,r[e]||function(){})}function pe(e){if(N){var t=N;N=void 0,t()}N=e&&e.S()}function me(t){var n=this,r=t.data,i=ge(r);i.name=`ReactiveDom`,i.value=r;var a=e(function(){for(var e=n,t=n.__v;t=t.__;)if(t.__c){t.__c.__$f|=4;break}var r=oe(function(){var e=i.value.value;return e===0?0:!0===e?``:e||``}),a=oe(function(){return!Array.isArray(r.value)&&!c(r.value)}),o=j(function(){if(this.N=Se,a.value){var t=r.value;e.__v&&e.__v.__e&&e.__v.__e.nodeType===3&&(e.__v.__e.data=t)}}),s=n.__$u.d;return n.__$u.d=function(){o(),s.call(this)},[a,r]},[]),o=a[0],s=a[1];return o.value?s.peek():s.value}me.displayName=`ReactiveTextNode`,Object.defineProperties(E.prototype,{constructor:{configurable:!0,value:void 0},type:{configurable:!0,value:me},props:{configurable:!0,get:function(){var e=this;return{data:{get value(){return e.value}}}}},__b:{configurable:!0,value:1}}),fe(`__b`,function(e,t){if(typeof t.type==`string`){var n,r=t.props;for(var i in r)if(i!==`children`){var a=r[i];a instanceof E&&(n||(t.__np=n={}),n[i]=a,r[i]=a.peek())}}e(t)}),fe(`__r`,function(e,t){if(e(t),t.type!==n){pe();var r,i=t.__c;i&&(i.__$f&=-2,(r=i.__$u)===void 0&&(i.__$u=r=function(e,t){var n;return j(function(){n=this},{name:t}),n.c=e,n}(function(){var e;le&&((e=r.y)==null||e.call(r)),i.__$f|=1,i.setState({})},typeof t.type==`function`?t.type.displayName||t.type.name:``))),pe(r)}}),fe(`__e`,function(e,t,n,r){pe(),e(t,n,r)}),fe(`diffed`,function(e,t){pe();var n;if(typeof t.type==`string`&&(n=t.__e)){var r=t.__np,i=t.props,a=n.U;if(a)for(var o in a){var s=a[o];s===void 0||r&&o in r||(s.d(),a[o]=void 0)}if(r)for(var c in a||(a={},n.U=a),r){var l=a[c],u=r[c];l===void 0?(l=he(n,c,u,i),a[c]=l):l.o(u,i)}}e(t)});function he(e,t,n,r){var i=t in e&&e.ownerSVGElement===void 0,a=D(n);return{o:function(e,t){a.value=e,r=t},d:j(function(){this.N=Se;var n=a.value.value;r[t]!==n&&(r[t]=n,i?e[t]=n:n!=null&&(!1!==n||t[4]===`-`)?e.setAttribute(t,n):e.removeAttribute(t))})}}fe(`unmount`,function(e,t){if(typeof t.type==`string`){var n=t.__e;if(n){var r=n.U;if(r)for(var i in n.U=void 0,r){var a=r[i];a&&a.d()}}var o=t.__np;if(o){var s=t.props;for(var c in o)s[c]=o[c]}t.__np=void 0}else{var l=t.__c;if(l){var u=l.__$u;u&&(l.__$u=void 0,u.d())}}e(t)}),fe(`__h`,function(e,t,n,r){r<3&&(t.__$f|=2),e(t,n,r)}),a.prototype.shouldComponentUpdate=function(e,t){if(this.__R)return!0;var n=this.__$u,r=n&&n.s!==void 0;for(var i in t)return!0;if(this.__f||typeof this.u==`boolean`&&!0===this.u){var a=2&this.__$f;if(!(r||a||4&this.__$f)||1&this.__$f)return!0}else if(!(r||4&this.__$f)||3&this.__$f)return!0;for(var o in e)if(o!==`__source`&&e[o]!==this.props[o])return!0;for(var s in this.props)if(!(s in e))return!0;return!1};function ge(t,n){return e(function(){return D(t,n)},[])}var _e=typeof requestAnimationFrame>`u`?setTimeout:function(e){var t=function(){clearTimeout(n),cancelAnimationFrame(r),e()},n=setTimeout(t,35),r=requestAnimationFrame(t)},ve=function(e){queueMicrotask(function(){queueMicrotask(e)})};function ye(){_(function(){for(var e;e=ue.shift();)M.call(e)})}function be(){ue.push(this)===1&&(r.requestAnimationFrame||_e)(ye)}function xe(){_(function(){for(var e;e=de.shift();)M.call(e)})}function Se(){de.push(this)===1&&(r.requestAnimationFrame||ve)(xe)}function Ce(e,t){var n=i(e);n.current=e,u(function(){return j(function(){return this.N=be,n.current()},t)},[])}var we=D(`dashboard`),P=D(null),Te=D(null),Ee=D(null),De=D(0),Oe=D(50),F=D(new Set),ke=D(new Set),I=D(``),L=D({topK:10,minScore:.35,keywordWeight:.4,hybrid:!0,pathFilter:``,langFilter:``,extFilter:``}),R=D([]),Ae=D([]);D(!1),D(null),D([]),D(new Set),D(null),D(null);var z=D(typeof localStorage<`u`?localStorage.getItem(`theme`)??`dark`:`dark`),je=D(!0);function Me(e){return Math.min(560,Math.max(180,Math.round(e)))}function Ne(){if(typeof localStorage>`u`)return 256;let e=Number(localStorage.getItem(`sidebarWidth`));return Number.isFinite(e)&&e>0?Me(e):256}var B=D(Ne());function Pe(e){B.value=Me(e)}function Fe(){try{localStorage.setItem(`sidebarWidth`,String(B.value))}catch{}}var Ie=D([]),Le=0;function V(e,t,n=4e3){let r=Le++;Ie.value=[...Ie.value,{id:r,type:e,message:t,duration:n}],setTimeout(()=>{Ie.value=Ie.value.filter(e=>e.id!==r)},n)}function H(e){window.location.hash=e}function Re(){return u(()=>{document.documentElement.classList.toggle(`dark`,z.value===`dark`),localStorage.setItem(`theme`,z.value)},[z.value]),{theme:z.value,toggle:()=>{z.value=z.value===`dark`?`light`:`dark`}}}function ze(){u(()=>{let e=null,t=null,n=()=>{e&&=(clearTimeout(e),null),t&&=(window.removeEventListener(`keydown`,t),null)},r=r=>{let i=r.target,a=i.tagName===`INPUT`||i.tagName===`TEXTAREA`||i.isContentEditable;if((r.metaKey||r.ctrlKey)&&r.key===`k`){r.preventDefault(),H(`search`),setTimeout(()=>{document.querySelector(`.global-search-input`)?.focus()},0);return}if(!a&&r.key===`g`){let r={d:()=>H(`dashboard`),s:()=>H(`search`),c:()=>H(`chunks`),f:()=>H(`files`),e:()=>H(`evaluate`),q:()=>H(`quirks`)};n();let i=e=>{r[e.key]?.(),n()};t=i,window.addEventListener(`keydown`,i),e=setTimeout(n,500);return}};return window.addEventListener(`keydown`,r),()=>{window.removeEventListener(`keydown`,r),n()}},[])}function Be(){return l(`div`,{className:`fixed top-4 right-4 z-[9999] flex flex-col gap-2 pointer-events-none`,children:Ie.value.map(e=>l(`div`,{className:`pointer-events-auto px-4 py-2.5 rounded-lg shadow-lg text-sm font-medium transition-all duration-300 animate-slide-in ${e.type===`success`?`bg-green-600 text-white`:e.type===`error`?`bg-red-600 text-white`:`bg-brand-600 text-white`}`,children:e.message},e.id))})}function Ve(){let e=z.value===`dark`;return l(`button`,{className:`p-2 rounded-lg transition-colors`,style:{color:`var(--text-muted)`},onClick:()=>{z.value=e?`light`:`dark`},"aria-label":e?`Switch to light mode`:`Switch to dark mode`,title:e?`Light mode`:`Dark mode`,children:[l(`span`,{className:`sr-only`,children:e?`Switch to light mode`:`Switch to dark mode`}),e?l(`svg`,{className:`w-5 h-5`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,"aria-hidden":`true`,children:l(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:2,d:`M12 3v1m0 16v1m9-9h-1M4 12H3m15.364 6.364l-.707-.707M6.343 6.343l-.707-.707m12.728 0l-.707.707M6.343 17.657l-.707.707M16 12a4 4 0 11-8 0 4 4 0 018 0z`})}):l(`svg`,{className:`w-5 h-5`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,"aria-hidden":`true`,children:l(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:2,d:`M20.354 15.354A9 9 0 018.646 3.646 9.003 9.003 0 0012 21a9.003 9.003 0 008.354-5.646z`})})]})}function He(e,t){let[n,r]=s(e);return u(()=>{let n=setTimeout(()=>r(e),t);return()=>clearTimeout(n)},[e,t]),n}var Ue=`/api`,We=`opencode-rag-token`;function Ge(){let e=new URLSearchParams(window.location.search).get(`token`);if(e){sessionStorage.setItem(We,e);let t=window.location.pathname+window.location.hash;return window.history.replaceState(null,``,t),e}return sessionStorage.getItem(We)}function Ke(){let e=Ge();return e?{Authorization:`Bearer ${e}`}:{}}function qe(e){let t=new URLSearchParams;for(let[n,r]of Object.entries(e))r!==void 0&&r!==``&&t.set(n,String(r));return t.toString()}async function U(e,t){let n={...t?.headers??{},...Ke()},r=await fetch(Ue+e,{...t,headers:n}),i=await r.json();if(!r.ok)throw Error(i.error??r.statusText);return i}var W={stats:()=>U(`/stats`),files:()=>U(`/files`),chunks:e=>U(`/chunks?${qe(e)}`),chunk:e=>U(`/chunks/${encodeURIComponent(e)}`),search:(e,t=20)=>U(`/search?q=${encodeURIComponent(e)}&topK=${t}`),compare:e=>U(`/compare?ids=${e.join(`,`)}`),retrieve:e=>U(`/retrieve?${qe(e)}`),evalSessions:()=>U(`/eval/sessions`),evalSession:e=>U(`/eval/sessions/${encodeURIComponent(e)}`),evalDeleteSession:e=>U(`/eval/sessions/${encodeURIComponent(e)}`,{method:`DELETE`}),evalCompare:(e,t)=>U(`/eval/compare?a=${e}&b=${t}`),evalTokenCompare:(e,t)=>U(`/eval/token-compare?a=${e}&b=${t}`),evalAnalysis:e=>U(`/eval/sessions/${encodeURIComponent(e)}/analysis`),evalProjectSavings:e=>U(`/eval/project-savings`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(e)}),quirks:()=>U(`/quirks`),quirkLint:()=>U(`/quirks/lint`),deleteQuirk:e=>U(`/quirks/${encodeURIComponent(e)}`,{method:`DELETE`}),indexStatus:()=>U(`/indexing/status`),triggerReindex:()=>U(`/indexing/reindex`,{method:`POST`}),config:()=>U(`/config`),updateConfig:e=>U(`/config`,{method:`PUT`,headers:{"Content-Type":`application/json`},body:JSON.stringify(e)}),tree:()=>U(`/tree`),embeddingProj:(e=5e3,t=2)=>U(`/embeddings/projection?maxChunks=${e}&dims=${t}`)},Je={typescript:`text-blue-400`,javascript:`text-yellow-400`,python:`text-green-400`,java:`text-red-400`,go:`text-cyan-400`,rust:`text-orange-400`,ruby:`text-pink-400`,csharp:`text-purple-400`,cpp:`text-indigo-400`,c:`text-gray-400`,markdown:`text-gray-300`,html:`text-orange-300`,css:`text-blue-300`,json:`text-yellow-300`,kotlin:`text-purple-300`,swift:`text-orange-400`,tex:`text-emerald-400`,sql:`text-cyan-300`};function Ye(e){return Je[e]??`text-slate-400`}function G(e){return`<span class="inline-block px-1.5 py-0.5 rounded text-xs font-mono ${Ye(e)} bg-slate-800">${Xe(e)}</span>`}function Xe(e){return e.replace(/&/g,`&`).replace(/</g,`<`).replace(/>/g,`>`)}function K(e){return typeof e==`string`?e.replace(/&/g,`&`).replace(/</g,`<`).replace(/>/g,`>`).replace(/"/g,`"`).replace(/'/g,`'`):``}function Ze(e,t=80){let n=typeof e==`string`?e:String(e??``);return n.length>t?n.slice(0,t)+`...`:n}function Qe(){let[e,t]=s(``),[n,r]=s([]),[a,o]=s(!1),c=i(null),d=i(null),f=He(e,300);u(()=>{if(!f.trim()){r([]),o(!1);return}let e=!1;return W.search(f,10).then(t=>{e||(r(t?.results??[]),o(!0))}).catch(()=>{e||o(!1)}),()=>{e=!0}},[f]),u(()=>{let e=e=>{d.current&&!d.current.contains(e.target)&&o(!1)};return document.addEventListener(`click`,e),()=>document.removeEventListener(`click`,e)},[]);let p=e=>{e.key===`Escape`&&o(!1)},m=async e=>{o(!1),t(``),H(`chunks`)};return l(`div`,{ref:d,className:`relative`,children:[l(`input`,{ref:c,type:`text`,placeholder:`Search codebase...`,value:e,onInput:e=>t(e.target.value),onKeyDown:p,className:`global-search-input w-56 px-3 py-1.5 bg-slate-800 border border-slate-600 rounded text-sm text-slate-200 placeholder-slate-500 focus:outline-none focus:border-brand-400`,"aria-label":`Global search`,role:`combobox`,"aria-expanded":a}),a&&n.length>0&&l(`div`,{className:`absolute top-full right-0 mt-1 w-96 bg-slate-800 border border-slate-600 rounded-lg shadow-xl z-50 max-h-80 overflow-y-auto`,role:`listbox`,children:n.map(e=>l(`div`,{className:`search-result p-2 hover:bg-slate-700 cursor-pointer border-b border-slate-700 last:border-0`,onClick:()=>m(e.chunk.id),role:`option`,children:[l(`div`,{className:`flex items-center gap-2 text-xs`,children:[l(`span`,{className:`text-yellow-400 font-mono`,children:[K(e.chunk.filePath),`:`,e.chunk.startLine,`-`,e.chunk.endLine]}),l(`span`,{dangerouslySetInnerHTML:{__html:G(e.chunk.language)}}),l(`span`,{className:`ml-auto text-slate-500`,children:e.score})]}),l(`div`,{className:`text-xs text-slate-400 mt-1 truncate`,children:K(e.chunk.content??``).slice(0,80)})]},e.chunk.id))}),a&&e.trim()&&n.length===0&&l(`div`,{className:`absolute top-full right-0 mt-1 w-96 bg-slate-800 border border-slate-600 rounded-lg shadow-xl z-50 p-3 text-sm text-slate-500`,children:`No results`})]})}function q(e,t=[]){let[n,r]=s(null),[i,a]=s(!0),[o,c]=s(null),[l,d]=s(0);return u(()=>{let t=!1;return a(!0),c(null),e().then(e=>{t||(r(e),a(!1))}).catch(e=>{t||(c(e.message),a(!1))}),()=>{t=!0}},[...t,l]),{data:n,isLoading:i,error:o,refresh:()=>d(e=>e+1)}}function $e(){let{data:e}=q(()=>W.files()),t=e??[],[n,r]=s(``),i=He(n,300),a=i?t.filter(e=>e.filePath.toLowerCase().includes(i.toLowerCase())):t;return l(`div`,{className:`flex flex-col h-full`,children:[l(`div`,{className:`flex items-center justify-between mb-2 px-3 pt-3`,children:[l(`h2`,{className:`text-xs font-semibold text-slate-400 uppercase tracking-wide`,children:`Files`}),l(`span`,{className:`text-xs text-slate-500`,children:a.length})]}),l(`div`,{className:`px-3 mb-2`,children:l(`input`,{type:`text`,placeholder:`Filter files...`,value:n,onInput:e=>r(e.target.value),className:`w-full px-2 py-1 bg-slate-900 border border-slate-700 rounded text-xs focus:outline-none focus:border-brand-400 text-slate-200 placeholder-slate-500`})}),l(`div`,{className:`flex-1 overflow-y-auto px-1`,children:l(et,{files:a})})]})}function et({files:e}){let t={};for(let n of e){let e=n.filePath.split(`/`),r=t;for(let t=0;t<e.length-1;t++)r[e[t]]||(r[e[t]]={}),r=r[e[t]];r.__files||(r.__files=[]),r.__files.push(n)}return l(nt,{obj:t,depth:0,parentPath:``})}function tt(e){let t=(e.__files||[]).length;for(let[n,r]of Object.entries(e))n!==`__files`&&(t+=tt(r));return t}function nt({obj:e,depth:t,parentPath:r}){let i=Object.entries(e).filter(([e])=>e!==`__files`).sort(([e],[t])=>e.localeCompare(t)),a=e.__files||[];return l(n,{children:[i.map(([e,n])=>{let i=r?`${r}/${e}`:e,a=tt(n),o=ke.value.has(i),s=o?`▸`:`▾`;return l(`div`,{children:[l(`div`,{className:`file-item flex items-center gap-1 py-0.5 px-2 rounded cursor-pointer text-slate-400 hover:text-white`,style:{paddingLeft:`${t*12+8}px`},onClick:()=>{let e=new Set(ke.value);e.has(i)?e.delete(i):e.add(i),ke.value=e},role:`treeitem`,"aria-expanded":!o,children:[l(`span`,{className:`text-xs`,children:s}),l(`span`,{className:`text-xs`,children:`📁`}),l(`span`,{className:`text-xs`,children:K(e)}),l(`span`,{className:`text-xs text-slate-600 ml-auto`,children:a})]}),!o&&l(`div`,{className:`dir-children`,children:l(nt,{obj:n,depth:t+1,parentPath:i})})]},i)}),a.map(e=>{let n=e.filePath.split(`/`).pop()??e.filePath,r=P.value===e.filePath;return l(`div`,{className:`file-item flex items-center gap-1 py-0.5 px-2 rounded cursor-pointer ${r?`active text-white`:`text-slate-400 hover:text-white`}`,style:{paddingLeft:`${t*12+8}px`},onClick:()=>{P.value=e.filePath,H(`chunks?file=${encodeURIComponent(e.filePath)}`)},role:`treeitem`,tabIndex:0,children:[l(`span`,{className:`text-xs ${Ye(e.language)}`,children:`♦`}),l(`span`,{className:`text-xs truncate`,children:K(n)}),l(`span`,{className:`text-xs text-slate-600 ml-auto`,children:e.chunkCount})]},e.filePath)})]})}function rt(e){let t=[...e].sort(),n=[];for(let e of t)n.some(t=>e.startsWith(`${t}/`))||n.push(e);return n}function it(e,t){return t.includes(e)?`checked`:t.some(t=>t.startsWith(`${e}/`))?`partial`:`unchecked`}function at(){let e=q(()=>W.tree()),t=q(()=>W.config()),[r,i]=s(!1),[a,o]=s([]),[c,d]=s([]),[f,p]=s(!1),[m,h]=s(!1),[g,_]=s(!1),v=t.data?.body?.config??t.data?.config,y=e.data?.body?.tree??e.data?.tree;u(()=>{if(v&&!f){let e=v.indexing?.includeDirs??[];o(e),d(e),p(!0)}},[v,f]);let b=rt(a),x=rt(c).join(`|`)!==b.join(`|`),S=b.length===0;function C(e){let t=new Set(a);if(it(e,a)===`checked`)for(let n of a)(n===e||n.startsWith(`${e}/`))&&t.delete(n);else{t.add(e);for(let n of a)n.startsWith(`${e}/`)&&t.delete(n)}o([...t])}function ee(){o([])}async function w(){if(!m){h(!0);try{await W.updateConfig({indexing:{includeDirs:b}}),o(b),d(b),_(!0)}catch(e){V(`error`,`Failed to save scope: ${e.message}`)}finally{h(!1)}}}async function T(){_(!1),V(`info`,`Scope saved — starting reindex…`);try{await W.triggerReindex(),V(`success`,`Reindex started in the background.`)}catch(e){V(`error`,`Reindex failed to start: ${e.message}`)}}return l(`div`,{className:`border-b`,style:{borderColor:`var(--border)`},children:[l(`button`,{type:`button`,className:`w-full flex items-center gap-1 px-3 py-2 text-xs font-semibold text-slate-400 uppercase tracking-wide hover:text-white`,onClick:()=>i(e=>!e),"aria-expanded":r,children:[l(`span`,{className:`text-xs`,children:r?`▾`:`▸`}),l(`span`,{children:`Indexing scope`}),b.length>0&&l(`span`,{className:`ml-auto text-xs text-slate-500`,children:[b.length,` folder`,b.length===1?``:`s`]})]}),r&&l(`div`,{className:`px-2 pb-3 text-xs`,children:[e.error&&l(`p`,{className:`text-red-400 px-2 py-1`,children:[`Could not load workspace tree: `,e.error,l(`button`,{type:`button`,className:`ml-2 underline`,onClick:e.refresh,children:`Retry`})]}),!e.error&&!y&&l(`p`,{className:`px-2 py-1 text-slate-500`,children:`Loading folders…`}),y&&l(n,{children:[l(`label`,{className:`flex items-center gap-1.5 py-1 px-2 rounded cursor-pointer text-slate-300 hover:text-white`,children:[l(`input`,{type:`checkbox`,checked:S,onChange:ee}),l(`span`,{children:`Whole workspace`}),!S&&l(`span`,{className:`text-slate-500`,children:`(include all folders)`})]}),l(`p`,{className:`px-2 py-1 text-slate-600`,children:`Selecting a folder includes all of its subfolders. Files directly in the workspace root are only indexed with "Whole workspace".`}),l(`div`,{className:`max-h-48 overflow-y-auto border rounded`,style:{borderColor:`var(--border)`},children:l(ot,{dirs:y,depth:0,selection:a,onToggle:C})}),l(`button`,{type:`button`,disabled:!x||m,className:`mt-2 w-full px-3 py-1.5 rounded font-semibold disabled:opacity-40 disabled:cursor-not-allowed`,style:{background:`var(--accent)`,color:`#fff`},onClick:w,children:m?`Saving…`:x?`Save scope`:`Saved`}),l(`p`,{className:`mt-1.5 px-2 text-slate-600`,children:[`Saved to `,l(`code`,{children:`opencode-rag.json`}),`. The background watcher applies the new scope after an OpenCode restart.`]})]})]}),g&&l(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center`,style:{background:`rgba(0,0,0,0.55)`},children:l(`div`,{className:`rounded-lg p-5 max-w-sm w-full shadow-xl`,style:{background:`var(--bg-secondary)`,border:`1px solid var(--border)`},children:[l(`h3`,{className:`text-base font-bold mb-2`,children:`Scope saved`}),l(`p`,{className:`text-sm mb-4`,style:{color:`var(--text-muted)`},children:`The includeDirs setting was written to opencode-rag.json. Reindex now so the index matches the new scope?`}),l(`div`,{className:`flex justify-end gap-2`,children:[l(`button`,{type:`button`,className:`px-3 py-1.5 rounded text-sm`,style:{background:`var(--bg-primary)`,border:`1px solid var(--border)`},onClick:()=>{_(!1),V(`success`,`Scope saved — applies on the next index pass.`)},children:`Later`}),l(`button`,{type:`button`,className:`px-3 py-1.5 rounded text-sm font-semibold text-white`,style:{background:`var(--accent)`},onClick:T,children:`Reindex now`})]})]})})]})}function ot({dirs:e,depth:t,selection:r,onToggle:i}){return l(n,{children:e.map(e=>{let n=it(e.path,r);return l(`div`,{children:[l(`label`,{className:`flex items-center gap-1.5 py-0.5 px-2 rounded cursor-pointer text-slate-400 hover:text-white`,style:{paddingLeft:`${t*12+8}px`},children:[l(`input`,{type:`checkbox`,checked:n===`checked`,ref:e=>{e&&(e.indeterminate=n===`partial`)},onChange:()=>i(e.path)}),l(`span`,{className:`text-xs`,children:`📁`}),l(`span`,{className:`text-xs truncate`,children:e.name})]}),e.children.length>0&&l(ot,{dirs:e.children,depth:t+1,selection:r,onToggle:i})]},e.path)})})}function st(e){let t=i(null),[n,r]=s(!1);Ce(()=>{let t=e.current;t&&(t.style.width=`${B.value}px`)});let a=()=>{t.current=null,r(!1),document.body.style.cursor=``,document.body.style.userSelect=``},o=e=>{if(e.button===0){try{e.currentTarget.setPointerCapture(e.pointerId)}catch{}t.current={pointerId:e.pointerId,startX:e.clientX,startWidth:B.peek()},r(!0),document.body.style.cursor=`col-resize`,document.body.style.userSelect=`none`}},c=e=>{let n=t.current;n&&n.pointerId===e.pointerId&&Pe(n.startWidth+(e.clientX-n.startX))},l=e=>{let n=t.current;n&&n.pointerId===e.pointerId&&(a(),Fe())};return{dragging:n,handleProps:{onPointerDown:o,onPointerMove:c,onPointerUp:l,onPointerCancel:l,onKeyDown:e=>{if(e.key!==`ArrowLeft`&&e.key!==`ArrowRight`)return;e.preventDefault();let t=e.key===`ArrowLeft`?-16:16;Pe(B.peek()+t),Fe()},onDblClick:()=>{Pe(256),Fe()}}}}function ct({targetRef:e}){let{dragging:t,handleProps:n}=st(e);return l(`div`,{className:`sidebar-resizer hidden lg:block ${t?`dragging`:``}`,role:`separator`,"aria-orientation":`vertical`,"aria-label":`Resize file tree`,"aria-valuemin":180,"aria-valuemax":560,"aria-valuenow":B.value,tabIndex:0,title:`Drag to resize · double-click to reset`,...n})}var J=`bg-gradient-to-r from-slate-700 via-slate-600 to-slate-700 bg-[length:200%_100%]`;function Y({type:e=`card`}){return l(`div`,{className:`animate-pulse space-y-4`,children:[l(`div`,{className:`h-8 ${J} rounded w-48`}),e===`card`&&l(`div`,{className:`grid grid-cols-2 lg:grid-cols-4 gap-4`,children:[1,2,3,4].map(e=>l(`div`,{className:`h-24 bg-slate-800 rounded-lg border border-slate-700 p-4`,children:[l(`div`,{className:`h-3 ${J} rounded w-16 mb-2`}),l(`div`,{className:`h-6 ${J} rounded w-24`})]},e))}),e===`table`&&l(`div`,{className:`space-y-2`,children:[l(`div`,{className:`h-10 ${J} rounded w-full`}),[1,2,3,4,5].map(e=>l(`div`,{className:`h-8 ${J} rounded w-full`},e))]}),e===`chart`&&l(`div`,{className:`h-64 ${J} rounded-lg`}),e===`detail`&&l(`div`,{className:`flex gap-4`,children:[l(`div`,{className:`flex-1 space-y-3`,children:[l(`div`,{className:`h-6 ${J} rounded w-48`}),l(`div`,{className:`h-4 ${J} rounded w-32`}),l(`div`,{className:`h-32 ${J} rounded-lg`})]}),l(`div`,{className:`flex-1 space-y-3`,children:[l(`div`,{className:`h-6 ${J} rounded w-48`}),l(`div`,{className:`h-4 ${J} rounded w-32`}),l(`div`,{className:`h-32 ${J} rounded-lg`})]})]})]})}function X({message:e,onRetry:t}){return l(`div`,{className:`flex flex-col items-center justify-center py-12 text-center`,role:`alert`,children:[l(`span`,{className:`text-4xl mb-3`,children:`⚠️`}),l(`p`,{className:`text-slate-400 mb-4`,children:e}),t&&l(`button`,{className:`bg-brand-600 hover:bg-brand-500 text-white px-4 py-2 rounded transition-colors`,onClick:t,children:`Retry`})]})}function Z({icon:e,message:t,action:n}){return l(`div`,{className:`flex flex-col items-center justify-center py-16 text-center`,role:`status`,children:[l(`span`,{className:`text-5xl mb-4`,role:`img`,"aria-label":e,children:e}),l(`p`,{className:`text-slate-400 mb-4`,children:t}),n&&l(`button`,{className:`bg-brand-600 hover:bg-brand-500 text-white px-4 py-2 rounded transition-colors`,onClick:n.onClick,children:n.label})]})}function Q({label:e,value:t,icon:n}){return l(`div`,{className:`kpi-card p-4`,children:[n&&l(`span`,{className:`text-lg mb-1 block`,children:n}),l(`div`,{className:`text-slate-400 text-xs mb-1`,children:e}),l(`div`,{className:`text-3xl font-bold text-white`,children:t})]})}function $(e){return e>=1e6?(e/1e6).toFixed(1)+`M`:e>=1e3?(e/1e3).toFixed(1)+`k`:String(e)}function lt(e){return e===0?`$0.00`:e<.01?`$`+e.toFixed(4):`$`+e.toFixed(2)}function ut(e){return e>=6e4?(e/6e4).toFixed(1)+`m`:e>=1e3?(e/1e3).toFixed(1)+`s`:e+`ms`}function dt(e){if(!e)return`-`;let t=new Date(e);return t.toLocaleDateString()+` `+t.toLocaleTimeString([],{hour:`2-digit`,minute:`2-digit`})}function ft(e){let t=Date.now()-new Date(e).getTime(),n=Math.floor(t/6e4);if(n<1)return`just now`;if(n<60)return`${n}m ago`;let r=Math.floor(n/60);return r<24?`${r}h ago`:`${Math.floor(r/24)}d ago`}function pt(){let[e,t]=s(null),[n,r]=s(!0),[a,o]=s(!1),c=i(null),d=async()=>{try{let e=await W.indexStatus();t(e.body??e)}catch{}r(!1)};u(()=>{d()},[]),u(()=>()=>{c.current&&clearInterval(c.current)},[]);let f=async()=>{o(!0);try{await W.triggerReindex(),V(`info`,`Reindex started in background`);let n=e?.manifest?.lastIndexedAt,r=Date.now();c.current=setInterval(async()=>{if(Date.now()-r>6e5){c.current&&clearInterval(c.current),c.current=null,o(!1),V(`info`,`Reindex is still running — check back later`);return}try{let e=await W.indexStatus(),r=e.body??e;r.manifest?.lastIndexedAt!==n&&(c.current&&clearInterval(c.current),c.current=null,t(r),o(!1),V(`success`,`Reindex complete!`))}catch{}},2e3)}catch(e){let t=e.message??``;V(`error`,/already running/i.test(t)?`A reindex is already running`:`Reindex failed: ${t}`),o(!1)}};if(n)return null;let p=e?.manifest?.lastIndexedAt?ft(e.manifest.lastIndexedAt):`Never`,m=e?.staleFileCount??0,h=m===0?`text-green-400`:m<50?`text-amber-400`:`text-red-400`;return l(`div`,{className:`kpi-card p-4 mb-6`,children:[l(`div`,{className:`flex items-center justify-between mb-3`,children:l(`h2`,{className:`text-lg font-semibold`,children:`Index Status`})}),e?.manifest?l(`div`,{className:`grid grid-cols-2 lg:grid-cols-4 gap-4`,children:[l(`div`,{children:[l(`span`,{className:`text-xs text-slate-500 block`,children:`Last Indexed`}),l(`span`,{className:`text-sm font-mono`,children:p})]}),l(`div`,{children:[l(`span`,{className:`text-xs text-slate-500 block`,children:`Total Chunks`}),l(`span`,{className:`text-sm font-mono`,children:$(e.manifest.totalChunks)})]}),l(`div`,{children:[l(`span`,{className:`text-xs text-slate-500 block`,children:`Total Files`}),l(`span`,{className:`text-sm font-mono`,children:$(e.manifest.totalFiles)})]}),l(`div`,{children:[l(`span`,{className:`text-xs text-slate-500 block`,children:`Schema Version`}),l(`span`,{className:`text-sm font-mono`,children:e.manifest.schemaVersion})]}),l(`div`,{className:`col-span-2`,children:[l(`span`,{className:`text-xs text-slate-500 block`,children:`Index Freshness`}),l(`span`,{className:`text-sm font-mono ${h}`,children:m===0?`✓ Up to date`:`⚠ ${m} file${m===1?``:`s`} modified since last index`})]}),l(`div`,{className:`col-span-2 flex items-end`,children:a?l(`div`,{className:`flex items-center gap-2`,children:[l(`span`,{className:`animate-spin`,children:`⟳`}),l(`span`,{className:`text-sm text-amber-400`,children:`Reindexing...`})]}):l(`button`,{className:`bg-brand-600 hover:bg-brand-500 text-white px-4 py-1.5 rounded text-sm transition-colors`,onClick:f,children:`Reindex Now`})})]}):l(`div`,{className:`text-sm text-slate-400`,children:[`No index found. Run `,l(`code`,{className:`text-brand-400`,children:`opencode-rag index`}),` first.`]})]})}function mt(){let{data:e,isLoading:t,error:n,refresh:r}=q(()=>W.stats()),{data:i}=q(()=>W.files());if(t)return l(Y,{type:`card`});if(n)return l(X,{message:n,onRetry:r});if(!e)return l(Z,{icon:`📊`,message:`No dashboard data available.`});let a=e,o=i?.body?.length??a.totalFiles??0,s=a.totalChunks??0,c=a.languages?.length??0,u=o>0?(s/o).toFixed(1):`0`,d=(a.languages??[]).slice(0,8),f=d[0]?.count??1;return l(`div`,{children:[l(`h1`,{className:`text-2xl font-bold mb-6`,children:`Dashboard`}),l(`div`,{className:`grid grid-cols-2 lg:grid-cols-4 gap-4 mb-8`,children:[l(Q,{label:`Total Chunks`,value:s.toLocaleString(),icon:`🧩`}),l(Q,{label:`Total Files`,value:o.toLocaleString(),icon:`📄`}),l(Q,{label:`Languages`,value:c,icon:`🔤`}),l(Q,{label:`Avg Chunks/File`,value:u,icon:`📊`})]}),l(`div`,{className:`kpi-card p-4`,children:[l(`h3`,{className:`text-sm font-semibold text-slate-300 mb-3`,children:`Language Distribution`}),l(`div`,{className:`space-y-2`,children:d.map(e=>l(`div`,{className:`flex items-center gap-3`,children:[l(`span`,{className:`w-24 text-xs text-right ${Ye(e.language)}`,children:e.language}),l(`div`,{className:`flex-1 bg-slate-800 rounded-full h-5 overflow-hidden`,children:l(`div`,{className:`h-full rounded-full bg-brand-500 flex items-center pl-2`,style:{width:`${Math.max(8,e.count/f*100)}%`},children:l(`span`,{className:`text-xs font-medium text-white`,children:e.count})})}),l(`span`,{className:`text-xs text-slate-500 w-12 text-right`,children:[(e.count/s*100).toFixed(0),`%`]})]},e.language))})]}),l(pt,{}),l(`div`,{className:`mt-6`,children:l(`h2`,{className:`text-lg font-semibold mb-3`,children:l(`a`,{href:`#config`,className:`hover:text-brand-400 transition-colors`,children:`Configuration`})})})]})}function ht({text:e,color:t,onDismiss:n}){return l(`span`,{className:`inline-flex items-center gap-1 px-1.5 py-0.5 rounded text-xs font-mono bg-slate-800 ${t??`text-slate-400`}`,children:[e,n&&l(`button`,{className:`ml-0.5 text-slate-500 hover:text-white`,onClick:n,"aria-label":`Dismiss ${e} filter`,children:`×`})]})}function gt(){let e=m();u(()=>{e.params.file&&(P.value=e.params.file),e.params.lang&&(Te.value=e.params.lang)},[e.params.file,e.params.lang]);let t=De.value,n=Oe.value,r=P.value,i=Te.value,{data:a,isLoading:o,error:s,refresh:c}=q(()=>W.chunks({offset:t,limit:n,lang:i??``,file:r??``}),[t,n,r,i]);if(o)return l(Y,{type:`detail`});if(s)return l(X,{message:s,onRetry:c});let d=a?.chunks??[],f=a?.total??d.length,p=Math.ceil(f/n),h=Math.floor(t/n)+1;return l(`div`,{className:`flex gap-4 h-full`,children:[l(`div`,{className:`w-1/2 flex flex-col`,children:[l(`div`,{className:`flex items-center gap-3 mb-3 flex-wrap`,children:[l(`h2`,{className:`text-lg font-semibold text-white`,children:`Chunks`}),l(`span`,{className:`text-sm text-slate-400`,children:[f,` total`]}),Te.value&&l(ht,{text:Te.value,color:Ye(Te.value),onDismiss:()=>{Te.value=null,Ee.value=null,De.value=0}}),P.value&&l(ht,{text:P.value,onDismiss:()=>{P.value=null,Ee.value=null,De.value=0}})]}),l(`div`,{className:`bg-slate-900 rounded-lg border border-slate-700 overflow-hidden flex-1`,children:l(`table`,{className:`w-full text-sm`,role:`table`,children:[l(`thead`,{children:l(`tr`,{className:`bg-slate-800 text-slate-400 text-xs`,children:[l(`th`,{className:`px-2 py-2 w-8`,children:l(`input`,{type:`checkbox`,className:`accent-brand-500`,checked:d.length>0&&d.every(e=>F.value.has(e.id||`chunk-${d.indexOf(e)}`)),onChange:()=>{let e=d.map((e,t)=>e.id||`chunk-${t}`),t=e.every(e=>F.value.has(e)),n=new Set(F.value);for(let r of e)t?n.delete(r):n.add(r);F.value=n},"aria-label":`Select all chunks on this page`})}),l(`th`,{className:`px-3 py-2 text-left`,children:`File`}),l(`th`,{className:`px-3 py-2 text-left w-20`,children:`Lang`}),l(`th`,{className:`px-3 py-2 text-left`,children:`Description`})]})}),l(`tbody`,{children:d.length===0?l(`tr`,{children:l(`td`,{colSpan:4,className:`px-3 py-8 text-center text-slate-500`,children:[l(`span`,{className:`text-2xl block mb-2`,children:`🔍`}),`No chunks found`]})}):d.map((e,t)=>{let n=e.id||`chunk-${t}`,r=Ee.value===n,i=F.value.has(n);return l(`tr`,{className:`chunk-row border-t border-slate-800 cursor-pointer ${r?`selected`:``}`,onClick:()=>{Ee.value=n},role:`row`,tabIndex:0,children:[l(`td`,{className:`px-2 py-2`,onClick:e=>e.stopPropagation(),children:l(`input`,{type:`checkbox`,className:`accent-brand-500`,checked:i,onChange:()=>{let e=new Set(F.value);e.has(n)?e.delete(n):e.add(n),F.value=e},"aria-label":`Select chunk ${n}`})}),l(`td`,{className:`px-3 py-2 text-yellow-400 font-mono text-xs`,children:[K(e.filePath),`:`,e.startLine,`-`,e.endLine]}),l(`td`,{className:`px-3 py-2`,dangerouslySetInnerHTML:{__html:G(e.language)}}),l(`td`,{className:`px-3 py-2 text-slate-400 text-xs`,children:K(e.description??``).slice(0,50)})]},n)})})]})}),l(`div`,{className:`flex items-center justify-between mt-3`,children:[l(`button`,{className:`px-3 py-1 bg-slate-700 rounded text-sm hover:bg-slate-600 disabled:opacity-50`,disabled:h<=1,onClick:()=>{De.value=Math.max(0,t-n)},children:`Previous`}),l(`span`,{className:`text-sm text-slate-400`,children:[`Page `,h,` of `,p||1]}),l(`button`,{className:`px-3 py-1 bg-slate-700 rounded text-sm hover:bg-slate-600 disabled:opacity-50`,disabled:h>=p,onClick:()=>{De.value+=n},children:`Next`})]}),F.value.size>=2&&F.value.size<=3&&l(`div`,{className:`fixed bottom-6 right-6 z-50`,children:l(`button`,{className:`bg-brand-600 hover:bg-brand-500 text-white px-6 py-3 rounded-full shadow-lg font-bold transition-all transform hover:scale-105`,onClick:()=>{let e=[...F.value];F.value=new Set,H(`compare?ids=${e.join(`,`)}`)},children:[`Compare (`,F.value.size,`)`]})})]}),l(`div`,{className:`w-1/2 overflow-y-auto`,children:Ee.value?l(_t,{chunkId:Ee.value,chunks:d}):l(`div`,{className:`flex items-center justify-center h-full text-slate-500`,children:l(`div`,{className:`text-center`,children:[l(`div`,{className:`text-4xl mb-2`,children:`📄`}),l(`div`,{className:`text-sm`,children:`Select a chunk to view details`})]})})})]})}function _t({chunkId:e,chunks:t}){let[n,r]=s(null),[a,o]=s(!1),c=i(null);if(u(()=>{let n=!1,i=t.find(t=>t.id===e);return i?r(i):W.chunk(e).then(e=>{n||r(e)}).catch(()=>{n||r({id:e,content:``,filePath:`not found`,language:``,startLine:0,endLine:0,description:``})}),()=>{n=!0}},[e,t]),u(()=>()=>{c.current&&clearTimeout(c.current)},[]),!n)return l(Y,{type:`detail`});let d=n,f=d.language===`image`;return l(`div`,{children:[l(`div`,{className:`mb-3`,children:[l(`div`,{className:`flex items-center gap-3 mb-1`,children:l(`span`,{className:`text-yellow-400 font-mono text-sm`,children:K(d.filePath)})}),l(`div`,{className:`flex items-center gap-3 text-sm text-slate-400`,children:[l(`span`,{children:[`Lines `,d.startLine,`-`,d.endLine]}),l(`span`,{dangerouslySetInnerHTML:{__html:G(d.language)}}),d.id&&l(`span`,{className:`text-xs text-slate-600 font-mono`,children:d.id})]})]}),d.description&&l(`div`,{className:`kpi-card p-3 mb-3`,children:[l(`h3`,{className:`text-xs font-semibold text-slate-400 mb-1`,children:`Description`}),l(`p`,{className:`text-sm text-slate-300`,children:K(d.description)})]}),f&&l(`div`,{className:`bg-slate-900 rounded-lg border border-slate-700 overflow-hidden mb-3`,children:[l(`div`,{className:`px-3 py-1.5 bg-slate-800 border-b border-slate-700`,children:l(`span`,{className:`text-xs text-slate-400`,children:`Image Preview`})}),l(`div`,{className:`p-3 flex items-center justify-center bg-slate-950`,children:l(`img`,{src:`/api/file?path=${encodeURIComponent(d.filePath)}`,alt:d.filePath,className:`max-w-full max-h-[60vh] object-contain rounded`,onError:e=>{let t=e.currentTarget;t.style.display=`none`,t.parentElement.innerHTML=`<span class="text-slate-500 text-sm">Image not available</span>`}})})]}),l(`div`,{className:`bg-slate-900 rounded-lg border border-slate-700 overflow-hidden`,children:[l(`div`,{className:`px-3 py-1.5 bg-slate-800 border-b border-slate-700 flex items-center justify-between`,children:[l(`span`,{className:`text-xs text-slate-400`,children:f?`Vision Analysis`:`Source Code`}),l(`button`,{className:`text-xs text-slate-500 hover:text-white transition-colors`,onClick:()=>{navigator.clipboard.writeText(d.content).then(()=>{o(!0),c.current&&clearTimeout(c.current),c.current=setTimeout(()=>o(!1),1500)})},children:a?`Copied!`:`Copy`})]}),l(`pre`,{className:`p-3 overflow-x-auto text-sm max-h-[calc(100vh-220px)]`,children:l(`code`,{className:`language-${f?`text`:d.language}`,children:K(d.content)})})]})]})}function vt(){let{data:e,isLoading:t,error:n,refresh:r}=q(()=>W.files());if(t)return l(Y,{type:`table`});if(n)return l(X,{message:n,onRetry:r});let i=e??[];if(i.length===0)return l(Z,{icon:`📂`,message:`No files indexed yet.`});let a=i.reduce((e,t)=>e+t.chunkCount,0);return l(`div`,{children:[l(`div`,{className:`flex items-center gap-3 mb-4`,children:[l(`h1`,{className:`text-2xl font-bold`,children:`Files`}),l(`span`,{className:`text-sm text-slate-400`,children:[i.length,` files, `,a,` chunks`]})]}),l(`div`,{className:`bg-slate-900 rounded-lg border border-slate-700 overflow-hidden`,children:l(`table`,{className:`w-full text-sm`,role:`table`,"aria-label":`Indexed files`,children:[l(`thead`,{children:l(`tr`,{className:`bg-slate-800 text-slate-400 text-xs`,children:[l(`th`,{className:`px-3 py-2 text-left`,children:`File`}),l(`th`,{className:`px-3 py-2 text-left w-28`,children:`Language`}),l(`th`,{className:`px-3 py-2 text-left w-20`,children:`Chunks`}),l(`th`,{className:`px-3 py-2 text-left w-24`})]})}),l(`tbody`,{children:i.map(e=>l(`tr`,{className:`border-t border-slate-800 hover:bg-slate-800 cursor-pointer`,onClick:()=>H(`chunks?file=${encodeURIComponent(e.filePath)}`),role:`row`,tabIndex:0,onKeyDown:t=>{t.key===`Enter`&&H(`chunks?file=${encodeURIComponent(e.filePath)}`)},children:[l(`td`,{className:`px-3 py-2 text-yellow-400 font-mono text-xs`,children:e.filePath}),l(`td`,{className:`px-3 py-2`,dangerouslySetInnerHTML:{__html:G(e.language)}}),l(`td`,{className:`px-3 py-2 text-slate-300`,children:e.chunkCount}),l(`td`,{className:`px-3 py-2 text-slate-500 text-xs`,children:l(`span`,{className:`hover:text-white transition-colors`,children:`View chunks`})})]},e.filePath))})]})})]})}function yt({segments:e,size:t=180,innerRadius:n,centerLabel:r}){let i=t/2,a=t/2,o=t/2-10,s=n??o*.6,c=e.reduce((e,t)=>e+t.value,0);if(c===0)return l(`svg`,{width:t,height:t,viewBox:`0 0 ${t} ${t}`,children:[l(`circle`,{cx:i,cy:a,r:o,fill:`none`,stroke:`#334155`,"stroke-width":o-s}),l(`circle`,{cx:i,cy:a,r:s,fill:`#0f172a`})]});let u=0,d=e.map(e=>{let t=e.value/c*360,n=u,r=u+t;return u+=t,`<path d="${bt(i,a,o,n,r,s)}" fill="${e.color}" />`}).join(``),f=r??``;return l(`svg`,{width:t,height:t,viewBox:`0 0 ${t} ${t}`,className:`chart-svg`,children:[l(`g`,{dangerouslySetInnerHTML:{__html:d}}),l(`text`,{x:i,y:a-6,"text-anchor":`middle`,fill:`white`,"font-size":`22`,"font-weight":`bold`,children:f}),l(`text`,{x:i,y:a+14,"text-anchor":`middle`,fill:`#64748b`,"font-size":`11`,children:`tokens`})]})}function bt(e,t,n,r,i,a){let o=i-r;if(o>=359.99)return`M${e},${t-n} A${n},${n} 0 1,1 ${e-.01},${t-n} L${e-.01},${t-a} A${a},${a} 0 1,0 ${e},${t-a} Z`;let s=e=>(e-90)*Math.PI/180,c=e+n*Math.cos(s(r)),l=t+n*Math.sin(s(r)),u=e+n*Math.cos(s(i)),d=t+n*Math.sin(s(i)),f=e+a*Math.cos(s(i)),p=t+a*Math.sin(s(i)),m=e+a*Math.cos(s(r)),h=t+a*Math.sin(s(r)),g=+(o>180);return[`M${c},${l}`,`A${n},${n} 0 ${g} 1 ${u},${d}`,`L${f},${p}`,`A${a},${a} 0 ${g} 0 ${m},${h}`,`Z`].join(` `)}function xt(){let e=m();return e.params.compare?l(wt,{ids:[e.params.a??``,e.params.b??``]}):e.params.session?l(Ct,{sessionId:e.params.session}):l(St,{})}function St(){let{data:e,isLoading:t,error:n,refresh:r}=q(()=>W.evalSessions()),[i,a]=s(new Set);if(t)return l(Y,{type:`table`});if(n)return l(X,{message:n,onRetry:r});let o=e?.sessions??[];if(o.length===0)return l(Z,{icon:`📊`,message:`No sessions recorded yet.`});let c=e=>{let t=new Set(i);t.has(e)?t.delete(e):t.add(e),a(t)};return l(`div`,{children:[l(`div`,{className:`flex items-center justify-between mb-4`,children:[l(`h1`,{className:`text-2xl font-bold`,children:`Evaluate`}),l(`div`,{className:`flex gap-2`,children:[i.size===2&&l(`button`,{className:`bg-brand-600 hover:bg-brand-500 text-white px-3 py-1 rounded text-sm transition-colors`,onClick:()=>{let[e,t]=[...i];H(`evaluate?compare&a=${encodeURIComponent(e)}&b=${encodeURIComponent(t)}`)},children:`Compare Selected`}),i.size>0&&l(`button`,{className:`text-xs text-slate-400 hover:text-white`,onClick:()=>a(new Set),children:[`Clear (`,i.size,`)`]})]})]}),l(`div`,{className:`bg-slate-900 rounded-lg border border-slate-700 overflow-x-auto`,children:l(`table`,{className:`w-full text-sm`,role:`table`,children:[l(`thead`,{children:l(`tr`,{className:`bg-slate-800 text-slate-400 text-xs`,children:[l(`th`,{className:`px-2 py-2 w-8`}),l(`th`,{className:`px-3 py-2 text-left`,children:`Session`}),l(`th`,{className:`px-3 py-2 text-left`,children:`Last Activity`}),l(`th`,{className:`px-3 py-2 text-right`,children:`Messages`}),l(`th`,{className:`px-3 py-2 text-right`,children:`Input Tokens`}),l(`th`,{className:`px-3 py-2 text-right`,children:`Output Tokens`}),l(`th`,{className:`px-3 py-2 text-right`,children:`Cost`}),l(`th`,{className:`px-3 py-2 text-right`,children:`RAG Calls`}),l(`th`,{className:`px-3 py-2 text-right`,children:`RAG Tokens`}),l(`th`,{className:`px-3 py-2 text-left`,children:`Model`}),l(`th`,{className:`px-3 py-2 w-8`})]})}),l(`tbody`,{children:o.map(e=>l(`tr`,{className:`border-t border-slate-800 hover:bg-slate-800 cursor-pointer`,onClick:()=>H(`evaluate?session=${encodeURIComponent(e.sessionID)}`),children:[l(`td`,{className:`px-2 py-2`,onClick:e=>e.stopPropagation(),children:l(`input`,{type:`checkbox`,className:`accent-brand-500`,checked:i.has(e.sessionID),onChange:()=>c(e.sessionID),"aria-label":`Select session ${e.title??e.sessionID}`})}),l(`td`,{className:`px-3 py-2 text-slate-200 font-mono text-xs`,children:e.title??e.sessionID.slice(0,8)}),l(`td`,{className:`px-3 py-2 text-slate-400 text-xs`,children:dt(e.lastEventAt)}),l(`td`,{className:`px-3 py-2 text-slate-300 text-right`,children:e.messageCount}),l(`td`,{className:`px-3 py-2 text-slate-300 text-right`,children:$((e.totalTokens?.input??0)+(e.totalTokens?.cacheRead??0))}),l(`td`,{className:`px-3 py-2 text-slate-300 text-right`,children:$(e.totalTokens?.output??0)}),l(`td`,{className:`px-3 py-2 text-slate-300 text-right`,children:lt(e.totalCost??0)}),l(`td`,{className:`px-3 py-2 text-slate-300 text-right`,children:e.ragContextCount??0}),l(`td`,{className:`px-3 py-2 text-slate-300 text-right`,children:$(e.ragContextTokens??0)}),l(`td`,{className:`px-3 py-2 text-slate-400 text-xs`,children:e.models?.[0]??`-`}),l(`td`,{className:`px-3 py-2`,onClick:e=>e.stopPropagation(),children:l(`button`,{className:`text-slate-600 hover:text-red-400 text-xs`,onClick:async()=>{if(confirm(`Delete this session?`))try{await W.evalDeleteSession(e.sessionID),V(`success`,`Session deleted`),r()}catch(e){V(`error`,`Delete failed: ${e.message}`)}},"aria-label":`Delete session`,children:`🗑`})})]},e.sessionID))})]})})]})}function Ct({sessionId:e}){let{data:t,isLoading:n,error:r,refresh:i}=q(()=>W.evalSession(e));if(n)return l(Y,{type:`detail`});if(r)return l(X,{message:r,onRetry:i});let a=t?.summary??t,o=t?.events??[],s=a.toolCallCounts??{};[`search_semantic`,`get_file_skeleton`,`find_usages`,`describe_image`].reduce((e,t)=>e+(s[t]??0),0);let c=[{label:`Input`,value:(a.totalTokens?.input??0)+(a.totalTokens?.cacheRead??0),color:`#3b82f6`},{label:`Output`,value:a.totalTokens?.output??0,color:`#a855f7`},{label:`RAG`,value:a.ragContextTokens??0,color:`#06b6d4`},{label:`Reasoning`,value:a.totalTokens?.reasoning??0,color:`#f59e0b`}].filter(e=>e.value>0),u=c.reduce((e,t)=>e+t.value,0);return l(`div`,{children:[l(`div`,{className:`flex items-center gap-3 mb-4`,children:[l(`button`,{className:`text-sm text-slate-400 hover:text-white`,onClick:()=>H(`evaluate`),children:`← Back`}),l(`h1`,{className:`text-xl font-bold`,children:a.title??a.sessionID?.slice(0,12)})]}),l(`div`,{className:`grid grid-cols-3 lg:grid-cols-5 gap-3 mb-6`,children:[l(Q,{label:`Total Tokens`,value:$(u)}),l(Q,{label:`Input`,value:$((a.totalTokens?.input??0)+(a.totalTokens?.cacheRead??0))}),l(Q,{label:`Output`,value:$(a.totalTokens?.output??0)}),l(Q,{label:`Cost`,value:lt(a.totalCost??0)}),l(Q,{label:`RAG Context`,value:$(a.ragContextTokens??0)})]}),l(`div`,{className:`flex items-center gap-6 mb-6`,children:[l(yt,{segments:c,centerLabel:$(u)}),l(`div`,{className:`flex flex-wrap gap-3`,children:c.map(e=>l(`div`,{className:`flex items-center gap-1.5 text-xs text-slate-400`,children:[l(`span`,{className:`inline-block w-3 h-3 rounded-sm`,style:{background:e.color}}),e.label,`: `,$(e.value),` (`,(e.value/u*100).toFixed(1),`%)`]},e.label))})]}),l(`div`,{className:`grid grid-cols-2 lg:grid-cols-4 gap-3 mb-6`,children:[l(Q,{label:`Messages`,value:a.messageCount??0}),l(Q,{label:`Steps`,value:a.totalSteps??0}),l(Q,{label:`RAG Injections`,value:a.ragContextCount??0}),l(Q,{label:`Avg Response`,value:ut(a.avgResponseTimeMs??0)})]}),Object.keys(s).length>0&&l(`div`,{className:`kpi-card p-4 mb-6`,children:[l(`h3`,{className:`text-sm font-semibold text-slate-300 mb-3`,children:`Tool Calls`}),l(`div`,{className:`grid grid-cols-2 lg:grid-cols-4 gap-2`,children:Object.entries(s).map(([e,t])=>l(`div`,{className:`flex justify-between text-xs text-slate-400`,children:[l(`span`,{className:`font-mono`,children:e}),l(`span`,{className:`text-white`,children:String(t)})]},e))})]}),a.models&&a.models.length>0&&l(`div`,{className:`kpi-card p-4 mb-6`,children:[l(`h3`,{className:`text-sm font-semibold text-slate-300 mb-2`,children:`Models`}),l(`div`,{className:`flex flex-wrap gap-2`,children:a.models.map(e=>l(`span`,{className:`px-2 py-0.5 rounded text-xs font-mono bg-slate-800 text-slate-300`,children:e},e))})]}),o.length>0&&l(`div`,{className:`kpi-card p-4`,children:[l(`h3`,{className:`text-sm font-semibold text-slate-300 mb-3`,children:`Event Timeline`}),l(`div`,{className:`space-y-1 max-h-64 overflow-y-auto`,children:o.map((e,t)=>l(`div`,{className:`flex gap-2 text-xs border-b border-slate-700/50 py-1`,children:[l(`span`,{className:`text-slate-500 shrink-0 w-16`,children:dt(e.ts)}),l(`span`,{className:`text-slate-400`,children:e.event}),e.tool&&l(`span`,{className:`text-slate-500 font-mono`,children:e.tool}),e.toolStatus&&l(`span`,{className:`text-xs ${e.toolStatus===`completed`?`text-green-400`:e.toolStatus===`running`?`text-amber-400`:`text-slate-500`}`,children:e.toolStatus})]},t))})]})]})}function wt({ids:e}){let[t,n]=e,{data:r,isLoading:i,error:a}=q(()=>Promise.all([W.evalCompare(t,n),W.evalTokenCompare(t,n)]),[t,n]);if(i)return l(Y,{type:`chart`});if(a)return l(X,{message:a});if(!r)return null;let o=r[0],s=r[1],c=s.sessionA?.savings??0,u=s.sessionB?.savings??0;return l(`div`,{children:[l(`div`,{className:`flex items-center gap-3 mb-4`,children:[l(`button`,{className:`text-sm text-slate-400 hover:text-white`,onClick:()=>H(`evaluate`),children:`← Back`}),l(`h1`,{className:`text-xl font-bold`,children:`Session Comparison`})]}),l(`div`,{className:`px-4 py-3 rounded-lg mb-4 font-semibold text-sm ${c>0&&u>0?`bg-green-900/50 text-green-300 border border-green-700`:`bg-amber-900/50 text-amber-300 border border-amber-700`}`,children:c>0&&u>0?`RAG saves tokens`:`Mixed results`}),l(`div`,{className:`grid grid-cols-2 gap-4`,children:[l(`div`,{className:`kpi-card p-4`,children:[l(`h3`,{className:`text-sm font-semibold text-slate-300 mb-2`,children:o.sessionA?.title??`Session A`}),l(`div`,{className:`space-y-1 text-sm`,children:[l(`div`,{className:`flex justify-between`,children:[l(`span`,{className:`text-slate-400`,children:`Total Tokens`}),l(`span`,{children:$(o.sessionA?.totalTokens??0)})]}),l(`div`,{className:`flex justify-between`,children:[l(`span`,{className:`text-slate-400`,children:`Cost`}),l(`span`,{children:lt(o.sessionA?.totalCost??0)})]}),l(`div`,{className:`flex justify-between`,children:[l(`span`,{className:`text-slate-400`,children:`RAG Savings`}),l(`span`,{className:c>0?`text-green-400`:`text-red-400`,children:[$(Math.abs(c)),` (`,c>0?`+`:``,c>0?`+`:``,`)`]})]})]})]}),l(`div`,{className:`kpi-card p-4`,children:[l(`h3`,{className:`text-sm font-semibold text-slate-300 mb-2`,children:o.sessionB?.title??`Session B`}),l(`div`,{className:`space-y-1 text-sm`,children:[l(`div`,{className:`flex justify-between`,children:[l(`span`,{className:`text-slate-400`,children:`Total Tokens`}),l(`span`,{children:$(o.sessionB?.totalTokens??0)})]}),l(`div`,{className:`flex justify-between`,children:[l(`span`,{className:`text-slate-400`,children:`Cost`}),l(`span`,{children:lt(o.sessionB?.totalCost??0)})]}),l(`div`,{className:`flex justify-between`,children:[l(`span`,{className:`text-slate-400`,children:`RAG Savings`}),l(`span`,{className:u>0?`text-green-400`:`text-red-400`,children:$(Math.abs(u))})]})]})]})]})]})}var Tt={gotcha:`text-amber-400 bg-amber-900/20`,preference:`text-emerald-400 bg-emerald-900/20`,decision:`text-sky-400 bg-sky-900/20`,"environment-constraint":`text-rose-400 bg-rose-900/20`};function Et(e){return`<span class="inline-block px-1.5 py-0.5 rounded text-xs font-mono ${Tt[e]??`text-slate-400 bg-slate-800`}">${K(e||`general`)}</span>`}function Dt(){let{data:e,isLoading:t,error:n,refresh:r}=q(()=>W.quirks()),[i,a]=s(null),[o,c]=s(null),[u,d]=s(!1);if(t)return l(Y,{type:`card`});if(n)return l(X,{message:n,onRetry:r});let f=e?.quirks??[],p=[...new Set(f.map(e=>e.type||`general`))],m=i?f.filter(e=>(e.type||`general`)===i):f,h=async e=>{if(confirm(`Delete this quirk?`))try{await W.deleteQuirk(e),V(`success`,`Quirk deleted`),r()}catch(e){V(`error`,`Delete failed: ${e.message}`)}};return l(`div`,{children:[l(`div`,{className:`flex items-center justify-between mb-4`,children:[l(`h1`,{className:`text-2xl font-bold`,children:`Quirks`}),l(`button`,{className:`bg-slate-700 hover:bg-slate-600 text-white px-3 py-1 rounded text-sm transition-colors`,onClick:async()=>{d(!0);try{let e=await W.quirkLint();c(e)}catch(e){c({error:e.message})}d(!1)},disabled:u,children:u?`Linting...`:`Lint`})]}),l(`div`,{className:`flex gap-2 mb-4 flex-wrap`,children:[l(`button`,{className:`px-2 py-1 rounded text-xs font-medium transition-colors ${i===null?`bg-brand-600 text-white`:`bg-slate-700 text-slate-300 hover:bg-slate-600`}`,onClick:()=>a(null),children:`All`}),p.map(e=>l(`button`,{className:`px-2 py-1 rounded text-xs font-medium transition-colors ${i===e?`bg-brand-600 text-white`:`bg-slate-700 text-slate-300 hover:bg-slate-600`}`,onClick:()=>a(e),children:e},e))]}),o&&l(`div`,{className:`mb-4 p-3 rounded-lg border text-sm ${o.success?`bg-green-900/30 border-green-700 text-green-300`:o.error?`bg-red-900/30 border-red-700 text-red-300`:`bg-amber-900/30 border-amber-700 text-amber-300`}`,children:l(`pre`,{className:`text-xs whitespace-pre-wrap`,children:JSON.stringify(o,null,2)})}),m.length===0?l(Z,{icon:`💡`,message:`No quirks stored yet.`}):l(`div`,{className:`grid grid-cols-1 lg:grid-cols-2 gap-3`,children:m.map(e=>l(`div`,{className:`bg-slate-900 rounded-lg border border-slate-700 p-3 flex flex-col`,children:[l(`div`,{className:`flex items-center justify-between mb-2`,children:[l(`span`,{dangerouslySetInnerHTML:{__html:Et(e.type)}}),l(`span`,{className:`text-xs font-mono ${e.confidence>.7?`text-green-400`:e.confidence>.4?`text-amber-400`:`text-red-400`}`,children:[(e.confidence*100).toFixed(0),`%`]})]}),l(`p`,{className:`text-sm text-slate-200 mb-2 flex-1`,children:K(e.content)}),e.tags&&e.tags.length>0&&l(`div`,{className:`flex gap-1 flex-wrap mb-2`,children:e.tags.map(e=>l(`span`,{className:`text-xs bg-slate-800 text-slate-400 px-1.5 py-0.5 rounded`,children:[`#`,e]},e))}),l(`div`,{className:`flex items-center justify-between text-xs text-slate-600 mt-auto`,children:[e.sourceRef&&l(`span`,{className:`font-mono`,children:K(e.sourceRef)}),l(`span`,{className:`font-mono`,children:e.id})]}),l(`button`,{className:`self-end mt-2 text-xs text-slate-600 hover:text-red-400 transition-colors`,onClick:()=>h(e.id),"aria-label":`Delete quirk`,children:`Delete`})]},e.id))})]})}function Ot(){let[e,t]=s([]),[n,r]=s(!1),[i,a]=s(null),[o,c]=s(!1),l=He(L.value,300);return u(()=>{let e=I.value.trim();if(!e){t([]),a(null),r(!1),R.value=[];return}let n=!1;return(async()=>{r(!0),a(null);try{let i=await W.retrieve({q:e,topK:l.topK,minScore:l.minScore,keywordWeight:l.keywordWeight,hybrid:l.hybrid?`true`:`false`,path:l.pathFilter||void 0,lang:l.langFilter||void 0,ext:l.extFilter||void 0,explain:`true`});if(n)return;if(i.status===503){a(i.body?.error??`Embedding model unavailable`),r(!1);return}c(!1);let o=i.body?.results??i.results??[];t(o),R.value=o,Ae.value=[{query:e,params:{...l}},...Ae.value.filter(t=>t.query!==e).slice(0,19)]}catch(e){n||a(e.message)}finally{n||r(!1)}})(),()=>{n=!0}},[I.value,l]),{results:e,isLoading:n,isInitializing:o,error:i,setResults:t}}function kt({explanation:e}){let{vectorScore:t,keywordScore:n,rawVectorScore:r,rawKeywordScore:i,keywordWeight:a,vectorRank:o,keywordRank:s}=e.scoreBreakdown,c=Math.max(t+n,.001),u=(t/c*100).toFixed(0),d=(n/c*100).toFixed(0);return l(`div`,{className:`mb-2`,children:[l(`div`,{className:`flex items-center gap-2 text-xs mb-1`,children:[l(`span`,{className:`text-cyan-400`,title:`Vector: ${r.toFixed(3)}${o===void 0?``:`, rank #${o+1}`}`,children:[`Vector `,u,`%`]}),l(`span`,{className:`text-amber-400`,title:`Keyword: ${i.toFixed(3)}${s===void 0?``:`, rank #${s+1}`}`,children:[`Keyword `,d,`%`]}),l(`span`,{className:`text-slate-500 ml-auto`,children:[`kw=`,a.toFixed(1)]})]}),l(`div`,{className:`h-2 bg-slate-700 rounded-full overflow-hidden flex`,children:[l(`div`,{className:`h-full bg-cyan-500 transition-all duration-200`,style:{width:`${u}%`}}),l(`div`,{className:`h-full bg-amber-500 transition-all duration-200`,style:{width:`${d}%`}})]})]})}function At(){let e=m(),{results:t,isLoading:n,isInitializing:r,error:i}=Ot();return u(()=>{e.params.query&&(I.value=e.params.query,L.value={...L.value,topK:parseInt(e.params.topK??`10`,10),minScore:parseFloat(e.params.minScore??`0.35`),keywordWeight:parseFloat(e.params.keywordWeight??`0.4`),hybrid:e.params.hybrid!==`false`,pathFilter:e.params.path??``,langFilter:e.params.lang??``,extFilter:e.params.ext??``})},[]),u(()=>{if(I.value.trim()){let e=new URLSearchParams({query:I.value,topK:String(L.value.topK),minScore:String(L.value.minScore),keywordWeight:String(L.value.keywordWeight),hybrid:String(L.value.hybrid)});L.value.pathFilter&&e.set(`path`,L.value.pathFilter),L.value.langFilter&&e.set(`lang`,L.value.langFilter),L.value.extFilter&&e.set(`ext`,L.value.extFilter);let t=`search?${e.toString()}`;location.hash!==`#${t}`&&history.replaceState(null,``,`#${t}`)}},[I.value,L.value]),l(`div`,{children:[l(`h1`,{className:`text-2xl font-bold mb-4`,children:`Semantic Search`}),l(`div`,{className:`flex gap-3 mb-4`,children:l(`input`,{type:`text`,value:I.value,onInput:e=>{I.value=e.target.value,R.value=[]},onKeyDown:e=>{e.key===`Enter`&&I.value.trim()},placeholder:`Search your codebase semantically... (e.g., 'how does authentication work?')`,className:`flex-1 px-4 py-2 bg-slate-800 border border-slate-600 rounded-lg text-sm text-slate-200 placeholder-slate-500 focus:outline-none focus:border-brand-400`,autoFocus:!0,"aria-label":`Semantic search query`})}),l(`details`,{className:`mb-4 bg-slate-800 rounded-lg border border-slate-700`,children:[l(`summary`,{className:`px-3 py-2 text-xs text-slate-400 cursor-pointer hover:text-white font-medium`,children:`Search Parameters`}),l(`div`,{className:`px-3 pb-3 space-y-3`,children:[l(Nt,{label:`topK`,min:1,max:25,step:1,value:L.value.topK,onChange:e=>{L.value={...L.value,topK:e}}}),l(Nt,{label:`minScore`,min:0,max:1,step:.05,value:L.value.minScore,onChange:e=>{L.value={...L.value,minScore:e}}}),l(Nt,{label:`keywordWeight`,min:0,max:1,step:.1,value:L.value.keywordWeight,onChange:e=>{L.value={...L.value,keywordWeight:e}}}),l(`div`,{className:`flex items-center gap-2`,children:[l(`label`,{className:`text-xs text-slate-400 w-28`,children:`Hybrid mode`}),l(`input`,{type:`checkbox`,checked:L.value.hybrid,onChange:e=>{L.value={...L.value,hybrid:e.target.checked}},className:`accent-brand-500`})]}),l(`div`,{className:`flex items-center gap-3`,children:[l(`label`,{className:`text-xs text-slate-400 w-28 shrink-0`,children:`Extensions`}),l(`input`,{type:`text`,value:L.value.extFilter,onInput:e=>{L.value={...L.value,extFilter:e.target.value}},placeholder:`.ts, .py (comma-separated)`,className:`flex-1 px-2 py-1 bg-slate-900 border border-slate-600 rounded text-xs text-slate-200 placeholder-slate-500 focus:outline-none focus:border-brand-400`,"aria-label":`File extension filter`})]}),l(`div`,{className:`flex items-center gap-3`,children:[l(`label`,{className:`text-xs text-slate-400 w-28 shrink-0`,children:`Languages`}),l(`input`,{type:`text`,value:L.value.langFilter,onInput:e=>{L.value={...L.value,langFilter:e.target.value}},placeholder:`typescript, python (comma-separated)`,className:`flex-1 px-2 py-1 bg-slate-900 border border-slate-600 rounded text-xs text-slate-200 placeholder-slate-500 focus:outline-none focus:border-brand-400`,"aria-label":`Language filter`})]}),l(`div`,{className:`flex items-center gap-3`,children:[l(`label`,{className:`text-xs text-slate-400 w-28 shrink-0`,children:`Path`}),l(`input`,{type:`text`,value:L.value.pathFilter,onInput:e=>{L.value={...L.value,pathFilter:e.target.value}},placeholder:`src/** (comma-separated)`,className:`flex-1 px-2 py-1 bg-slate-900 border border-slate-600 rounded text-xs text-slate-200 placeholder-slate-500 focus:outline-none focus:border-brand-400`,"aria-label":`Path filter`})]})]})]}),r&&l(`div`,{className:`text-center py-10 text-slate-400`,children:[l(`span`,{className:`animate-spin inline-block mr-2`,children:`⟳`}),`Initializing embedding model...`]}),i&&l(X,{message:i}),!n&&!i&&I.value.trim()&&t.length===0&&l(`div`,{className:`text-center py-16 text-slate-500`,children:[l(`div`,{className:`text-4xl mb-2`,children:`🔍`}),l(`div`,{children:[`No results found for "`,K(I.value),`"`]})]}),!n&&!i&&!I.value.trim()&&l(`div`,{className:`text-center py-16 text-slate-500`,children:[l(`div`,{className:`text-4xl mb-2`,children:`🔍`}),l(`div`,{children:`Enter a query to search your codebase`}),Ae.value.length>0&&l(`div`,{className:`mt-6`,children:[l(`p`,{className:`text-xs text-slate-600 mb-2`,children:`Recent queries:`}),l(`div`,{className:`flex flex-wrap gap-2 justify-center`,children:Ae.value.slice(0,10).map((e,t)=>l(`button`,{className:`px-2 py-1 bg-slate-800 rounded text-xs text-slate-400 hover:text-white hover:bg-slate-700 transition-colors`,onClick:()=>{I.value=e.query},children:K(e.query)},t))})]})]}),t.length>0&&l(`div`,{className:`space-y-3`,children:[l(`div`,{className:`flex items-center justify-between text-sm text-slate-400 mb-2`,children:[l(`span`,{children:[t.length,` result`,t.length===1?``:`s`]}),n&&l(`span`,{className:`text-xs text-brand-400 animate-pulse`,children:`Searching...`})]}),t.map(e=>l(jt,{result:e},e.chunk.id))]}),n&&t.length===0&&l(`div`,{className:`text-center py-10 text-slate-400`,children:[l(`span`,{className:`animate-spin inline-block mr-2`,children:`⟳`}),`Searching...`]})]})}function jt({result:e}){let t=e.chunk,n=e.score;return l(`div`,{className:`bg-slate-800 rounded-lg p-4 border border-slate-700 hover:border-brand-500/50 transition-colors cursor-pointer`,onClick:()=>H(`chunks?id=${encodeURIComponent(t.id)}`),children:[l(`div`,{className:`flex items-center justify-between mb-2`,children:[l(`div`,{className:`flex items-center gap-2 min-w-0`,children:[l(`span`,{className:`text-sm text-yellow-400 font-mono truncate`,children:[K(t.filePath),`:`,t.startLine,`-`,t.endLine]}),l(`span`,{dangerouslySetInnerHTML:{__html:G(t.language)}})]}),l(`span`,{className:`text-lg font-bold shrink-0 ml-2`,style:{color:Mt(n)},children:n.toFixed(2)})]}),e.explanation&&l(kt,{explanation:e.explanation}),e.explanation?.matchedTerms?.length>0&&l(`div`,{className:`flex gap-1 flex-wrap mb-2`,children:e.explanation.matchedTerms.map(e=>l(`span`,{className:`text-xs bg-amber-500/20 text-amber-300 px-1.5 py-0.5 rounded`,children:K(e)},e))}),t.description&&l(`p`,{className:`text-sm text-slate-400 mb-2 line-clamp-2`,children:K(t.description)}),l(`pre`,{className:`text-xs overflow-x-auto max-h-32 rounded bg-slate-900/50 p-2`,children:l(`code`,{children:K(t.content??``).slice(0,500)})})]})}function Mt(e){return e>=.8?`#22c55e`:e>=.6?`#06b6d4`:e>=.4?`#f59e0b`:`#ef4444`}function Nt({label:e,min:t,max:n,step:r,value:i,onChange:a}){return l(`div`,{className:`flex items-center gap-3`,children:[l(`label`,{className:`text-xs text-slate-400 w-28 shrink-0`,children:e}),l(`input`,{type:`range`,min:t,max:n,step:r,value:i,onInput:e=>a(parseFloat(e.target.value)),className:`flex-1 accent-brand-500`}),l(`span`,{className:`text-xs text-slate-300 font-mono w-12 text-right`,children:i})]})}function Pt(){let e=m().params.ids?.split(`,`).filter(Boolean)??[],[t,n]=s([]),[r,i]=s(!0),[a,o]=s(null);return u(()=>{let t=!1;if(e.length<2){o(`Select 2-3 chunks to compare.`),i(!1);return}return W.compare(e).then(e=>{t||(n(e?.body?.chunks??e?.chunks??[]),i(!1))}).catch(e=>{t||(o(e.message),i(!1))}),()=>{t=!0}},[e.join(`,`)]),r?l(Y,{type:`detail`}):a?l(X,{message:a}):t.length<2?l(Z,{icon:`📋`,message:`Select 2-3 chunks from the Chunks view to compare them.`}):l(`div`,{children:[l(`div`,{className:`flex items-center justify-between mb-4`,children:[l(`h1`,{className:`text-2xl font-bold`,children:`Chunk Comparison`}),l(`button`,{className:`text-sm text-slate-400 hover:text-white transition-colors`,onClick:()=>H(`chunks`),children:`← Back to Chunks`})]}),l(`div`,{className:`grid gap-4 ${t.length===2?`grid-cols-2`:`grid-cols-3`}`,children:t.map((e,n)=>l(Ft,{chunk:e,index:n,baseChunk:n>0?t[0]:void 0},e.id))})]})}function Ft({chunk:e,index:t,baseChunk:n}){let r=e.content.split(`
|
|
3
|
-
`),i=n?.content.split(`
|
|
4
|
-
`)??[];return l(`div`,{className:`bg-slate-800 rounded-lg border border-slate-700 overflow-hidden flex flex-col`,children:[l(`div`,{className:`p-3 border-b border-slate-700 bg-slate-800/80`,children:[l(`div`,{className:`flex items-center justify-between mb-1`,children:[l(`span`,{className:`text-sm font-mono text-brand-400 truncate mr-2`,children:[K(e.filePath),`:`,e.startLine,`-`,e.endLine]}),l(`span`,{className:`shrink-0`,dangerouslySetInnerHTML:{__html:G(e.language)}})]}),e.description&&l(`p`,{className:`text-xs text-slate-400 truncate`,children:K(e.description)})]}),l(`div`,{className:`overflow-x-auto flex-1 max-h-[70vh]`,children:l(`table`,{className:`w-full text-xs font-mono border-collapse`,children:l(`tbody`,{children:r.map((t,n)=>{let r=(e.startLine??1)+n,a=i[n]===void 0?`bg-green-900/30`:t===``&&i[n]!==``?`bg-red-900/30`:t===i[n]?``:`bg-amber-900/20`;return l(`tr`,{className:a,children:[l(`td`,{className:`text-right text-slate-600 select-none px-2 w-10 border-r border-slate-700 align-top`,children:r}),l(`td`,{className:`px-3 py-0 whitespace-pre-wrap break-all`,children:K(t)||`\xA0`})]},n)})})})}),l(`div`,{className:`px-3 py-1.5 bg-slate-900 border-t border-slate-700 text-xs text-slate-500`,children:[`Chunk `,t+1,t===0&&l(`span`,{className:`text-slate-600 ml-1`,children:`(reference)`})]})]})}function It(){let{data:e,isLoading:t,error:n,refresh:r}=q(()=>W.config());if(t)return l(Y,{type:`card`});if(n)return l(X,{message:n,onRetry:r});let i=e?.body?.config??e?.config;return i?l(`div`,{children:[l(`h1`,{className:`text-2xl font-bold mb-6`,children:`Configuration`}),l(`p`,{className:`text-sm text-slate-400 mb-4`,children:[`Effective configuration from `,l(`code`,{className:`text-brand-400`,children:`opencode-rag.json`}),`. API keys are redacted.`]}),l(`div`,{className:`space-y-4`,children:Object.entries(i).map(([e,t])=>l(`details`,{className:`bg-slate-800 rounded-lg border border-slate-700`,open:!0,children:[l(`summary`,{className:`px-4 py-2 cursor-pointer hover:bg-slate-700 font-mono text-sm font-semibold capitalize text-slate-300`,children:e.replace(/([A-Z])/g,` $1`)}),l(`div`,{className:`px-4 pb-3`,children:typeof t==`object`&&t?Object.entries(t).map(([e,t])=>l(`div`,{className:`flex justify-between py-1 border-b border-slate-700/50 text-sm`,children:[l(`span`,{className:`text-slate-400 font-mono`,children:e}),l(`span`,{className:`text-slate-200 font-mono text-xs text-right ml-4`,children:Lt(t)})]},e)):l(`div`,{className:`flex justify-between py-1 text-sm`,children:l(`span`,{className:`text-slate-200 font-mono`,children:String(t)})})})]},e))})]}):l(Z,{icon:`⚙`,message:`No configuration available.`})}function Lt(e){return e===null?`null`:e===void 0?`undefined`:typeof e==`boolean`?e?`true`:`false`:Array.isArray(e)?`[${e.join(`, `)}]`:typeof e==`object`?JSON.stringify(e).slice(0,150):String(e)}var Rt=10;function zt({points:e,width:n=800,height:r=600,onPointClick:a,renderTooltip:o}){let c=i(null),[d,f]=s({x:0,y:0,scale:1}),[p,m]=s(null),[h,g]=s(!1),_=i({x:0,y:0}),v=i(null),y=i(null),b=i(e);b.current=e;let x=t(e=>{v.current=e(v.current??d),y.current===null&&(y.current=requestAnimationFrame(()=>{y.current=null,v.current&&=(f(v.current),null)}))},[d]);u(()=>()=>{y.current!==null&&cancelAnimationFrame(y.current)},[]);let S=t((e,t)=>{let i=c.current;if(!i)return null;let a=i.getBoundingClientRect(),o=v.current??d,s=e-a.left,l=t-a.top,u=null,f=Rt;for(let e of b.current){let t=e.x*n*o.scale+o.x,i=e.y*r*o.scale+o.y,a=s-t,c=l-i,d=Math.sqrt(a*a+c*c);d<=f&&(f=d,u=e)}return u},[d,n,r]);u(()=>{let t=c.current;if(!t)return;let i=t.getContext(`2d`);if(!i)return;let a=window.devicePixelRatio||1;t.width=n*a,t.height=r*a,i.scale(a,a),i.clearRect(0,0,n,r),i.save(),i.translate(d.x,d.y),i.scale(d.scale,d.scale);for(let t of e){let e=t.x*n,a=t.y*r,o=(t.radius??3)*(t.highlighted?2:1);i.beginPath(),i.arc(e,a,o,0,Math.PI*2),i.fillStyle=t.color,i.globalAlpha=t.highlighted?1:.6,i.fill(),t.highlighted&&(i.strokeStyle=`#22d3ee`,i.lineWidth=2,i.stroke())}i.restore()},[e,d,n,r]);let C=e=>{e.preventDefault();let t=e.deltaY>0?.9:1.1;x(e=>({...e,scale:Math.max(.5,Math.min(10,e.scale*t))}))},ee=e=>{g(!0),_.current={x:e.clientX-d.x,y:e.clientY-d.y}},w=e=>{if(h){x(t=>({...t,x:e.clientX-_.current.x,y:e.clientY-_.current.y}));return}let t=S(e.clientX,e.clientY);m(e=>e?.id===t?.id?e:t)},T=()=>g(!1);return l(`div`,{className:`relative overflow-hidden rounded-lg border border-slate-700 bg-slate-900`,style:{width:n,height:r},children:[l(`canvas`,{ref:c,className:`absolute inset-0 cursor-grab active:cursor-grabbing`,onMouseDown:ee,onMouseMove:w,onMouseUp:T,onMouseLeave:T,onClick:e=>{if(h)return;let t=S(e.clientX,e.clientY);t&&a?.(t.id)},onWheel:C}),p&&o&&l(`div`,{className:`absolute bg-slate-800 border border-slate-600 rounded-lg p-3 shadow-xl text-sm z-10 pointer-events-none`,style:{left:Math.min(p.x*n*d.scale+d.x+12,n-200),top:Math.min(p.y*r*d.scale+d.y-12,r-80)},children:o(p)}),d.scale!==1&&l(`button`,{className:`absolute bottom-3 right-3 px-2 py-1 bg-slate-700 hover:bg-slate-600 rounded text-xs text-white transition-colors z-20`,onClick:()=>{f({x:0,y:0,scale:1}),v.current=null},children:`Reset zoom`})]})}function Bt(e,t){let n=e.x-t.x,r=e.y-t.y,i=(e.z??0)-(t.z??0);return Math.sqrt(n*n+r*r+i*i)}function Vt(e,t=8,n=20){let r=e.length;if(r<=t)return e.map((e,t)=>t);let i=Array(r).fill(0),a=[];a.push(e[Math.floor(Math.random()*r)]);for(let n=1;n<t;n++){let t=e.map(e=>Math.min(...a.map(t=>Bt(e,t)))),n=t.reduce((e,t)=>e+t*t,0),i=Math.random()*n;for(let n=0;n<r;n++)if(i-=t[n]*t[n],i<=0){a.push(e[n]);break}}for(let t=0;t<n;t++){for(let t=0;t<r;t++){let n=0,r=Bt(e[t],a[0]);for(let i=1;i<a.length;i++){let o=Bt(e[t],a[i]);o<r&&(r=o,n=i)}i[t]=n}let t=a.map(()=>({x:0,y:0,z:0,count:0}));for(let n=0;n<r;n++){let r=i[n];t[r].x+=e[n].x,t[r].y+=e[n].y,t[r].z+=e[n].z??0,t[r].count++}a.forEach((e,n)=>{t[n].count>0&&(e.x=t[n].x/t[n].count,e.y=t[n].y/t[n].count,e.z!==void 0&&(e.z=t[n].z/t[n].count))})}return i}function Ht(e,t,n){let r=n.map((n,r)=>{let i=e.filter((e,n)=>t[n]===r).map(e=>Bt(e,n)),a=i.reduce((e,t)=>e+t,0)/i.length,o=i.reduce((e,t)=>e+(t-a)**2,0)/i.length;return Math.sqrt(o)}),i=new Set;for(let a=0;a<e.length;a++){let o=t[a];Bt(e[a],n[o])>2*(r[o]??0)&&i.add(a)}return i}var Ut=`modulepreload`,Wt=function(e){return`/ui/`+e},Gt={},Kt=function(e,t,n){let r=Promise.resolve();if(t&&t.length>0){let e=document.getElementsByTagName(`link`),i=document.querySelector(`meta[property=csp-nonce]`),a=i?.nonce||i?.getAttribute(`nonce`);function o(e){return Promise.all(e.map(e=>Promise.resolve(e).then(e=>({status:`fulfilled`,value:e}),e=>({status:`rejected`,reason:e}))))}function s(e){return import.meta.resolve?import.meta.resolve(e):new URL(e,import.meta.url).href}r=o(t.map(t=>{if(t=Wt(t,n),t=s(t),t in Gt)return;Gt[t]=!0;let r=t.endsWith(`.css`);for(let n=e.length-1;n>=0;n--){let i=e[n];if(i.href===t&&(!r||i.rel===`stylesheet`))return}let i=document.createElement(`link`);if(i.rel=r?`stylesheet`:Ut,r||(i.as=`script`),i.crossOrigin=``,i.href=t,a&&i.setAttribute(`nonce`,a),document.head.appendChild(i),r)return new Promise((e,n)=>{i.addEventListener(`load`,e),i.addEventListener(`error`,()=>n(Error(`Unable to preload CSS for ${t}`)))})}).filter(e=>e!==void 0))}function i(e){let t=new Event(`vite:preloadError`,{cancelable:!0});if(t.payload=e,window.dispatchEvent(t),!t.defaultPrevented)throw e}return r.then(t=>{for(let e of t||[])e.status===`rejected`&&i(e.reason);return e().catch(i)})},qt=o(()=>Kt(()=>import(`./ScatterPlot3D-CKwyh1Ec.js`).then(e=>({default:e.ScatterPlot3D})),__vite__mapDeps([0,1]))),Jt=[`#3b82f6`,`#ef4444`,`#22c55e`,`#f59e0b`,`#a855f7`,`#06b6d4`,`#ec4899`,`#84cc16`,`#f97316`,`#14b8a6`,`#8b5cf6`,`#e11d48`,`#65a30d`,`#0ea5e9`,`#d946ef`,`#ca8a04`,`#64748b`,`#4ade80`,`#fb7185`,`#38bdf8`],Yt=2,Xt=50,Zt=5,Qt=200,$t=20,en=12;function tn(){let{data:t,isLoading:r,error:a,refresh:o}=q(()=>W.embeddingProj(5e3,3)),[c,f]=s(`language`),[p,m]=s(`3d`),[h,g]=s(!1),[_,v]=s(8),[y,b]=s(20),[x,S]=s(!1),[C,ee]=s(new Set),[w,T]=s(5),[te,ne]=s(0),[E,D]=s(null),[re,ie]=s(!1),ae=i(0),[O,oe]=s(null),[se,ce]=s(new Set),k=t?.body?.points??t?.points??[],A=t?.body?.totalChunks??t?.totalChunks??0;if(u(()=>{if(c===`cluster`&&k.length>0){let e=Math.max(Yt,Math.min(_,k.length)),t=Vt(k,e,y);if(oe(t),h){let n=[];for(let r=0;r<e;r++){let e=k.filter((e,n)=>t[n]===r);if(e.length>0){let t=e[0]?.z!==void 0;n.push({x:e.reduce((e,t)=>e+t.x,0)/e.length,y:e.reduce((e,t)=>e+t.y,0)/e.length,...t?{z:e.reduce((e,t)=>e+(t.z??0),0)/e.length}:{}})}}ce(Ht(k,t,n))}}else oe(null),ce(new Set)},[c,h,_,y,k]),u(()=>{x&&R.value.length>0?ee(new Set(R.value.map(e=>e.chunk.id))):ee(new Set)},[x,R.value]),r)return l(Y,{type:`chart`});if(a)return l(X,{message:a,onRetry:o});if(k.length===0)return l(Z,{icon:`🌐`,message:`No embedding data available. Index some files first.`});let j=e(()=>an(k),[k]),M=e(()=>k.map((e,t)=>{let n;n=c===`language`?Ye(e.language)===`text-slate-400`?`#94a3b8`:on(e.language):c===`file`?j.get(e.filePath)??`#94a3b8`:Jt[(O?.[t]??0)%Jt.length];let r=se.has(t),i=C.has(e.id);return{id:e.id,x:e.x,y:e.y,z:e.z??.5,color:i?`#22d3ee`:r?`#f97316`:n,label:`${e.filePath}:${e.startLine}-${e.endLine} [${e.language}]`,radius:i?6:r?5:3,highlighted:i}}),[k,c,O,se,C,j]),N=e(()=>{if(c!==`file`)return[];let e=rn(k.map(e=>e.filePath)),t=new Map;for(let e of k)t.set(e.filePath,(t.get(e.filePath)??0)+1);return[...t.entries()].sort((e,t)=>t[1]-e[1]).slice(0,en).map(([t,n])=>({label:t.slice(e.length)||t,count:n,color:j.get(t)??`#94a3b8`}))},[c,k,j]),le=e(()=>c===`file`?new Set(k.map(e=>e.filePath)).size-N.length:0,[c,k,N]),ue=e=>{let t=++ae.current;D(null),ie(!0),W.chunk(e).then(e=>{t===ae.current&&(D(e),ie(!1))}).catch(()=>{t===ae.current&&(D({id:e,content:``,filePath:`not found`,language:``,startLine:0,endLine:0,description:`Error loading chunk details.`}),ie(!1))})};return l(`div`,{children:[l(`h1`,{className:`text-2xl font-bold mb-4`,children:`Embedding Space Explorer`}),l(`div`,{className:`flex flex-wrap gap-3 mb-4 items-center`,children:[l(`div`,{className:`flex items-center gap-1 bg-slate-800 border border-slate-600 rounded-lg p-0.5`,children:[`2d`,`3d`].map(e=>l(`button`,{className:`px-2 py-0.5 rounded text-xs transition-colors ${p===e?`bg-slate-600 text-white`:`text-slate-400 hover:text-slate-200`}`,onClick:()=>m(e),children:e.toUpperCase()},e))}),l(`label`,{className:`text-xs text-slate-400`,children:`Color by:`}),l(`select`,{className:`bg-slate-800 border border-slate-600 rounded text-xs text-slate-200 px-2 py-1`,value:c,onChange:e=>f(e.target.value),children:[l(`option`,{value:`language`,children:`Language`}),l(`option`,{value:`file`,children:`File`}),l(`option`,{value:`cluster`,children:`Cluster`})]}),c===`cluster`&&l(n,{children:[l(`label`,{className:`text-xs text-slate-400`,children:`K:`}),l(`input`,{type:`number`,min:Yt,max:Xt,value:_,onChange:e=>v(nn(e.target,Yt,Xt,8)),className:`bg-slate-800 border border-slate-600 rounded text-xs text-slate-200 px-2 py-1 w-16`,title:`Number of clusters`}),l(`label`,{className:`text-xs text-slate-400`,children:`Iterations:`}),l(`input`,{type:`number`,min:Zt,max:Qt,value:y,onChange:e=>b(nn(e.target,Zt,Qt,20)),className:`bg-slate-800 border border-slate-600 rounded text-xs text-slate-200 px-2 py-1 w-20`,title:`Maximum k-means iterations`})]}),l(`label`,{className:`flex items-center gap-1.5 text-xs text-slate-400`,children:[l(`input`,{type:`checkbox`,className:`accent-brand-500`,checked:h,onChange:e=>g(e.target.checked)}),`Outliers`]}),R.value.length>0&&l(`label`,{className:`flex items-center gap-1.5 text-xs text-slate-400`,children:[l(`input`,{type:`checkbox`,className:`accent-brand-500`,checked:x,onChange:e=>S(e.target.checked)}),`Search overlay (`,R.value.length,` results)`]}),p===`3d`&&l(n,{children:[l(`label`,{className:`text-xs text-slate-400`,children:`Point size:`}),l(`input`,{type:`range`,min:1,max:20,value:w,onChange:e=>T(Number(e.target.value)),className:`w-24 accent-brand-500`}),l(`button`,{className:`px-2 py-1 bg-slate-700 hover:bg-slate-600 rounded text-xs text-white transition-colors`,onClick:()=>ne(e=>e+1),children:`Reset camera`})]})]}),c===`cluster`&&O&&l(`div`,{className:`flex flex-wrap gap-2 mb-3 text-xs`,children:(()=>{let e=Array.from(new Set(O)).sort((e,t)=>e-t),t=e.slice(0,$t),r=e.length-t.length;return l(n,{children:[t.map(e=>l(`span`,{className:`flex items-center gap-1 text-slate-400`,children:[l(`span`,{className:`inline-block w-2 h-2 rounded-full`,style:{background:Jt[e%Jt.length]}}),`Cluster `,e+1]},e)),r>0&&l(`span`,{className:`text-slate-500`,children:[`+`,r,` more`]})]})})()}),c===`file`&&N.length>0&&l(`div`,{className:`flex flex-wrap gap-2 mb-3 text-xs`,children:[N.map(({label:e,count:t,color:n})=>l(`span`,{className:`flex items-center gap-1 text-slate-400`,title:e,children:[l(`span`,{className:`inline-block w-2 h-2 rounded-full`,style:{background:n}}),K(Ze(e,40)),` (`,t,`)`]},e)),le>0&&l(`span`,{className:`text-slate-500`,children:[`+`,le,` more files`]})]}),p===`3d`?l(d,{fallback:l(Y,{type:`chart`}),children:l(qt,{points:M,width:900,height:600,onPointClick:ue,pointSize:w,resetKey:te,selectedId:E?.id??null})}):l(zt,{points:M,width:900,height:600,onPointClick:ue,renderTooltip:e=>{let t=k.find(t=>t.id===e.id);return l(`div`,{children:[l(`div`,{className:`text-yellow-400 font-mono text-xs`,children:K(e.label)}),t?.description&&l(`div`,{className:`text-slate-400 text-xs mt-1`,children:K(Ze(t.description,80))})]})}}),re&&l(Y,{type:`detail`}),E&&!re&&l(`div`,{className:`kpi-card p-4 mt-4`,children:[l(`div`,{className:`flex items-center gap-3 mb-1 flex-wrap`,children:[l(`span`,{className:`text-yellow-400 font-mono text-sm`,children:K(E.filePath)}),l(`span`,{className:`text-slate-400 text-xs`,children:[`Lines `,E.startLine,`-`,E.endLine]}),l(`span`,{dangerouslySetInnerHTML:{__html:G(E.language)}}),E.id&&l(`span`,{className:`text-xs text-slate-600 font-mono`,children:E.id}),l(`button`,{className:`ml-auto px-2 py-1 bg-slate-700 hover:bg-slate-600 rounded text-xs text-white transition-colors`,onClick:()=>H(`chunks?id=${encodeURIComponent(E.id)}`),children:`Open in Chunks`})]}),E.description&&l(`div`,{className:`mb-3`,children:[l(`h3`,{className:`text-xs font-semibold text-slate-400 mb-1`,children:`Description`}),l(`p`,{className:`text-sm text-slate-300`,children:K(E.description)})]}),E.content&&l(`div`,{children:[l(`h3`,{className:`text-xs font-semibold text-slate-400 mb-1`,children:`Content`}),l(`pre`,{className:`text-xs text-slate-300 bg-slate-900 border border-slate-700 rounded p-3 overflow-auto max-h-64 font-mono whitespace-pre`,children:K(E.content)})]})]}),l(`p`,{className:`text-xs text-slate-500 mt-2`,children:[M.length,` of `,A,` chunks displayed`,M.length<A&&` (chunks without embeddings omitted)`]})]})}function nn(e,t,n,r){let i=parseInt(e?.value??``,10);return Number.isNaN(i)?r:Math.max(t,Math.min(n,i))}function rn(e){if(e.length===0)return``;let t=e[0]??``;for(let n of e)for(;n&&t&&!n.startsWith(t);)t=t.slice(0,-1);let n=t.lastIndexOf(`/`);return n>=0?t.slice(0,n+1):``}function an(e){let t=new Map;for(let n of e){let e=t.get(n.filePath)??{x:0,y:0,z:0,n:0};e.x+=n.x,e.y+=n.y,e.z+=n.z??0,e.n++,t.set(n.filePath,e)}let n=[];for(let[e,r]of t)n.push({file:e,x:r.x/r.n,y:r.y/r.n,z:r.z/r.n});let r=n.reduce((e,t)=>e+t.x,0)/n.length,i=n.reduce((e,t)=>e+t.y,0)/n.length,a=n.reduce((e,t)=>e+t.z,0)/n.length,o=n.reduce((e,t)=>e+(t.x-r)**2,0),s=n.reduce((e,t)=>e+(t.y-i)**2,0),c=n.reduce((e,t)=>e+(t.z-a)**2,0),l=o>=s&&o>=c?`x`:s>=c?`y`:`z`,u=[`x`,`y`,`z`].filter(e=>e!==l);n.sort((e,t)=>e[l]-t[l]||e[u[0]]-t[u[0]]||e[u[1]]-t[u[1]]);let d=new Map;for(let e=0;e<n.length;e++){let t=e*137.508%360,r=e%2==0?55:40;d.set(n[e].file,`hsl(${t.toFixed(1)}, 80%, ${r}%)`)}return d}function on(e){return{typescript:`#60a5fa`,javascript:`#facc15`,python:`#4ade80`,java:`#f87171`,go:`#22d3ee`,rust:`#fb923c`,ruby:`#f472b6`,csharp:`#a78bfa`,cpp:`#818cf8`,c:`#9ca3af`,markdown:`#d1d5db`,html:`#fdba74`,css:`#60a5fa`,json:`#fde047`,kotlin:`#c084fc`,swift:`#fb923c`,tex:`#34d399`,sql:`#67e8f9`,text:`#94a3b8`,image:`#a78bfa`,quirk:`#fbbf24`}[e]??`#94a3b8`}var sn=[{view:`dashboard`,label:`Dashboard`,icon:`📊`},{view:`search`,label:`Search`,icon:`🔍`},{view:`embeddings`,label:`Embeddings`,icon:`🌐`},{view:`chunks`,label:`Chunks`,icon:`🧩`},{view:`files`,label:`Files`,icon:`📄`},{view:`evaluate`,label:`Evaluate`,icon:`📈`},{view:`quirks`,label:`Quirks`,icon:`💡`}];function cn(){Re(),ze();let e=m(),t=i(null);we.value=e.view;let r=()=>{je.value=!je.value};return l(`div`,{className:`h-screen flex flex-col overflow-hidden`,children:[l(`header`,{className:`flex items-center gap-3 px-4 py-2 border-b shrink-0`,style:{borderColor:`var(--border)`},children:[l(`h1`,{className:`text-lg font-bold shrink-0`,style:{color:`var(--accent)`},children:`OpenCodeRAG`}),l(`nav`,{className:`flex gap-1 flex-1`,role:`navigation`,"aria-label":`Main navigation`,children:sn.map(e=>l(`button`,{id:`nav-${e.view}`,className:`nav-btn ${we.value===e.view?`active`:``}`,onClick:()=>window.location.hash=e.view,role:`tab`,"aria-selected":we.value===e.view,children:[e.icon,` `,e.label]},e.view))}),l(Qe,{}),l(Ve,{}),l(`button`,{className:`p-2 rounded-lg transition-colors hidden lg:block`,style:{color:`var(--text-muted)`},onClick:r,"aria-label":`Toggle file tree`,title:`Toggle file tree`,children:`☰`}),l(`button`,{className:`p-2 rounded-lg transition-colors lg:hidden`,style:{color:`var(--text-muted)`},onClick:r,"aria-label":`Toggle file tree`,title:`Toggle file tree`,children:`☰`})]}),l(`div`,{className:`flex flex-1 overflow-hidden`,children:[je.value&&l(n,{children:[l(`div`,{className:`fixed inset-0 z-30 lg:hidden`,style:{background:`rgba(0,0,0,0.5)`},onClick:()=>{je.value=!1}}),l(`aside`,{ref:t,className:`shrink-0 border-r z-40 fixed lg:relative inset-y-0 left-0 flex flex-col max-w-[85vw] lg:max-w-none`,style:{background:`var(--bg-secondary)`,borderColor:`var(--border)`,width:`${B.peek()}px`},children:[l(`div`,{className:`flex-1 min-h-0 overflow-y-auto`,role:`tree`,"aria-label":`File tree`,children:[l(at,{}),l($e,{})]}),l(ct,{targetRef:t})]})]}),l(`main`,{className:`flex-1 overflow-y-auto p-6`,id:`main-content`,tabIndex:-1,children:[e.view===`dashboard`&&l(mt,{}),e.view===`search`&&l(At,{}),e.view===`embeddings`&&l(tn,{}),e.view===`compare`&&l(Pt,{}),e.view===`chunks`&&l(gt,{}),e.view===`files`&&l(vt,{}),e.view===`evaluate`&&l(xt,{}),e.view===`quirks`&&l(Dt,{}),e.view===`config`&&l(It,{})]})]}),l(Be,{})]})}f(l(cn,{}),document.getElementById(`app`));
|