codesesh 0.6.0 → 0.7.0

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.
@@ -0,0 +1,108 @@
1
+ import{r as e}from"./rolldown-runtime-Dw2cE7zH.js";import{l as t,t as n,u as r}from"./markdown-CnUlvKkZ.js";import{n as i,r as a,t as o}from"./react-DT3QPCDf.js";import{A as s,C as c,D as l,E as u,M as d,N as f,O as p,P as m,S as h,T as g,_,a as ee,b as te,c as ne,d as v,f as y,g as re,h as b,j as ie,k as x,l as ae,m as oe,n as S,o as se,p as ce,r as le,s as ue,t as de,u as fe,v as C,w as pe,x as w,y as me}from"./vendor-Bs5B_LvM.js";import{C as T,S as he,_ as E,a as ge,b as _e,c as ve,d as D,f as ye,g as O,h as be,i as xe,l as Se,m as k,n as Ce,o as we,p as A,r as Te,s as Ee,t as De,u as Oe,v as ke,x as Ae,y as je}from"./syntax-DcanuzfQ.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),e.crossOrigin===`use-credentials`?t.credentials=`include`:e.crossOrigin===`anonymous`?t.credentials=`omit`:t.credentials=`same-origin`,t}function n(e){if(e.ep)return;e.ep=!0;let n=t(e);fetch(e.href,n)}})();var j=e(r(),1),Me=e(a(),1),M={agents:{opencode:{name:`OpenCode`,icon:`/icon/agent/opencode.svg`},codex:{name:`Codex`,icon:`/icon/agent/codex.svg`},cursor:{name:`Cursor`,icon:`/icon/agent/cursor.svg`},kimi:{name:`Kimi-Cli`,icon:`/icon/agent/kimi.svg`},claudecode:{name:`Claude Code`,icon:`/icon/agent/claudecode.svg`},kilo:{name:`Kilo Code`,icon:`/icon/agent/kilocode.svg`},antigravity:{name:`Antigravity`,icon:`/icon/agent/antigravity.svg`}},getDefaultAgentKey(){let e=Object.keys(this.agents);return e.length>0?e[0]:null},getAgentName(e){let t=this.agents[e];return t||=this.agents[e.toLowerCase()],t?t.name:e}};async function Ne(){let e=await fetch(`/api/config`);if(!e.ok)throw Error(`Failed to fetch config`);return e.json()}async function Pe(){let e=await fetch(`/api/status`);if(!e.ok)throw Error(`Failed to fetch scan status`);return e.json()}async function Fe(){let e=await fetch(`/api/agents`);if(!e.ok)throw Error(`Failed to fetch agents`);return e.json()}async function Ie(){let e=await fetch(`/api/projects`);if(!e.ok)throw Error(`Failed to fetch projects`);return e.json()}async function Le(e={}){let t=new URLSearchParams;e.agent&&t.set(`agent`,e.agent),e.projectKey&&t.set(`projectKey`,e.projectKey),e.from!=null&&t.set(`from`,new Date(e.from).toISOString()),e.to!=null&&t.set(`to`,new Date(e.to).toISOString());let n=await fetch(`/api/sessions?${t}`);if(!n.ok)throw Error(`Failed to fetch sessions`);return n.json()}async function Re(e,t){let n=await fetch(`/api/sessions/${e}/${t}`);if(!n.ok)throw Error(`Failed to fetch session data`);return n.json()}async function ze(e,t={}){let n=new URLSearchParams;e?.from!=null&&n.set(`from`,new Date(e.from).toISOString()),e?.to!=null&&n.set(`to`,new Date(e.to).toISOString()),e?.days!=null&&e.days>0&&n.set(`days`,String(e.days)),t.projectKind&&n.set(`projectKind`,t.projectKind),t.projectKey&&n.set(`projectKey`,t.projectKey),t.agent&&n.set(`agent`,t.agent);let r=n.toString(),i=await fetch(r?`/api/dashboard?${r}`:`/api/dashboard`);if(!i.ok)throw Error(`Failed to fetch dashboard`);return i.json()}async function Be(e,t={}){let n=new URLSearchParams;n.set(`q`,e),t.agent&&n.set(`agent`,t.agent),t.projectKey&&n.set(`projectKey`,t.projectKey),t.tag&&n.set(`tag`,t.tag),t.tool&&n.set(`tool`,t.tool),t.fileKind&&n.set(`fileActivity`,t.fileKind),t.costMin!=null&&n.set(`costMin`,String(t.costMin)),t.costMax!=null&&n.set(`costMax`,String(t.costMax));let r=await fetch(`/api/search?${n}`);if(!r.ok)throw Error(`Failed to fetch search results`);return r.json()}async function Ve(){let e=await fetch(`/api/bookmarks`);if(!e.ok)throw Error(`Failed to fetch bookmarks`);return e.json()}async function He(e){let t=await fetch(`/api/bookmarks`,{method:`PUT`,headers:{"Content-Type":`application/json`},body:JSON.stringify(e)});if(!t.ok)throw Error(`Failed to save bookmark`);return t.json()}async function Ue(e){let t=await fetch(`/api/bookmarks/import`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(e)});if(!t.ok)throw Error(`Failed to import bookmarks`);return t.json()}async function We(e,t){if(!(await fetch(`/api/bookmarks/${e}/${t}`,{method:`DELETE`})).ok)throw Error(`Failed to delete bookmark`)}function N(e,t={}){let n=JSON.stringify({event:e,data:t});try{if(typeof navigator<`u`&&navigator.sendBeacon){let e=new Blob([n],{type:`application/json`});if(navigator.sendBeacon(`/api/logs`,e))return}}catch{}fetch(`/api/logs`,{method:`POST`,headers:{"Content-Type":`application/json`},body:n,keepalive:!0}).catch(()=>{})}function Ge(e,t){let n=new EventSource(`/api/events`);return n.addEventListener(`sessions-updated`,t=>{try{e(JSON.parse(t.data))}catch(e){console.error(`Failed to parse session update event:`,e)}}),n.addEventListener(`scan-status`,e=>{if(t)try{t(JSON.parse(e.data))}catch(e){console.error(`Failed to parse scan status event:`,e)}}),n.onerror=()=>{n.readyState!==EventSource.CLOSED&&console.warn(`Session update stream disconnected`)},()=>{n.close()}}function P(...e){return se(ue(e))}var F=t(),Ke={bugfix:`bugfix`,refactoring:`refactoring`,"feature-dev":`feature-dev`,testing:`testing`,docs:`docs`,"git-ops":`git-ops`,"build-deploy":`build-deploy`,exploration:`exploration`,planning:`planning`},qe={bugfix:{text:`#B42318`,border:`#FECDCA`,background:`#FEF3F2`,bar:`#F04438`},refactoring:{text:`#6941C6`,border:`#D9D6FE`,background:`#F4F3FF`,bar:`#7A5AF8`},"feature-dev":{text:`#175CD3`,border:`#B2DDFF`,background:`#EFF8FF`,bar:`#2E90FA`},testing:{text:`#027A48`,border:`#ABEFC6`,background:`#ECFDF3`,bar:`#12B76A`},docs:{text:`#B54708`,border:`#FEDF89`,background:`#FFFAEB`,bar:`#F79009`},"git-ops":{text:`#3538CD`,border:`#C7D7FE`,background:`#EEF4FF`,bar:`#444CE7`},"build-deploy":{text:`#C4320A`,border:`#F9DBAF`,background:`#FEF6EE`,bar:`#EF6820`},exploration:{text:`#0E7090`,border:`#A5F0FC`,background:`#ECFDFF`,bar:`#06AED4`},planning:{text:`#C11574`,border:`#FCCEEE`,background:`#FDF2FA`,bar:`#EE46BC`}};function I(e){return qe[e]}function L(e){let t=I(e);return{color:t.text,borderColor:t.border,backgroundColor:t.background}}function Je({tags:e,limit:t=4,className:n=``}){if(!e||e.length===0)return null;let r=e.slice(0,t),i=e.length-r.length;return(0,F.jsxs)(`div`,{className:`flex flex-wrap gap-1 ${n}`,children:[r.map(e=>(0,F.jsx)(`span`,{className:`console-mono rounded-sm border px-1.5 py-0.5 text-[10px] font-medium`,style:L(e),children:Ke[e]},e)),i>0?(0,F.jsxs)(`span`,{className:`console-mono rounded-sm border border-[var(--console-border)] bg-[var(--console-surface-muted)] px-1.5 py-0.5 text-[10px] text-[var(--console-muted)]`,children:[`+`,i]}):null]})}function Ye(e,t){return e?Math.abs(e.receiptWidth-t.receiptWidth)>.5||Math.abs(e.receiptHeight-t.receiptHeight)>.5||Math.abs(e.startX-t.startX)>.5||Math.abs(e.startY-t.startY)>.5:!0}var R=18,z=42,Xe=5,B=270,V=500,H=2;function Ze(e){return Math.round(e??0).toLocaleString(`en-US`)}function Qe(e){return`$${(e??0).toFixed(4)}`}function $e(e){return new Date(e).toLocaleString(`en-US`,{month:`short`,day:`2-digit`,hour:`2-digit`,minute:`2-digit`})}function et(e){let t=2166136261;for(let n=0;n<e.length;n+=1)t^=e.charCodeAt(n),t=Math.imul(t,16777619);return t>>>0}function tt(e){let t=e||1;return()=>(t=Math.imul(t^t>>>15,1|t),t^=t+Math.imul(t^t>>>7,61|t),((t^t>>>14)>>>0)/4294967296)}function nt(e){let t=[{label:`User`,count:e.counts.user},{label:`Agent Responses`,count:e.counts.agent_message},{label:`Thinking`,count:e.counts.thinking},{label:`Plans`,count:e.counts.plan},{label:`Tools`,count:e.counts.tools_all}].filter(e=>e.count>0),n=e.tools.map(e=>({label:e.label,count:e.count})),r=Math.max(0,9-t.length),i=n.length>r?n.slice(0,Math.max(0,r-1)):n,a=n.slice(i.length).reduce((e,t)=>e+t.count,0);return a>0&&i.push({label:`Other tools`,count:a}),[...t,...i].slice(0,9)}function rt(e){return!e||e.length===0?`SESSION ACTIVITY RECEIPT`:e.map(e=>Ke[e]).join(` / `)}function it(e,t){let n=e.slug?.split(`/`)[0]||`codesesh`;return{id:e.id,title:e.title||`Untitled session`,agent:n,updatedAt:e.time_updated??e.time_created,tags:e.smart_tags,stats:e.stats,items:nt(t)}}function at(e,t,n,r,i){let a=t.toUpperCase(),o=n.toUpperCase();e.fillText(a,18,r),e.fillText(o,i-18-e.measureText(o).width,r)}function ot(e,t,n){if(e.measureText(t).width<=n)return t;let r=t;for(;r.length>1&&e.measureText(`${r}...`).width>n;)r=r.slice(0,-1);return`${r}...`}function U(e,t,n,r){let i=t.toUpperCase().split(/\s+/).filter(Boolean),a=[],o=``;for(let t of i){let i=o?`${o} ${t}`:t;if(e.measureText(i).width<=n){o=i;continue}if(o?(a.push(o),o=t):(a.push(ot(e,t,n)),o=``),a.length===r)break}return a.length<r&&o&&a.push(o),a.length>0&&a.length===r&&(a[a.length-1]=ot(e,a[a.length-1]??``,n)),a.slice(0,r)}function st(e){let t=document.createElement(`canvas`);t.width=B*H,t.height=V*H;let n=t.getContext(`2d`);if(!n)return t;n.scale(H,H);let r=n.createLinearGradient(0,0,B,V);r.addColorStop(0,`#ffffff`),r.addColorStop(.55,`#fafaf6`),r.addColorStop(1,`#f2f2ec`),n.fillStyle=r,n.fillRect(0,0,B,V);let i=tt(et(e.id));n.fillStyle=`rgba(0, 0, 0, 0.035)`;for(let e=0;e<1200;e+=1)n.globalAlpha=.12+i()*.14,n.fillRect(i()*B,i()*V,.7,.7);n.globalAlpha=1,n.fillStyle=`rgba(0, 0, 0, 0.78)`,n.font=`700 18px 'Courier New', monospace`,n.textAlign=`center`,n.fillText(`CODESESH MART`,B/2,34),n.font=`11px 'Courier New', monospace`,n.fillText(ot(n,rt(e.tags).toUpperCase(),B-36),B/2,51),n.strokeStyle=`rgba(0, 0, 0, 0.5)`,n.lineWidth=1,n.setLineDash([4,4]),n.beginPath(),n.moveTo(18,66),n.lineTo(B-18,66),n.stroke(),n.setLineDash([]),n.textAlign=`left`,n.fillStyle=`rgba(0, 0, 0, 0.74)`,n.font=`11px 'Courier New', monospace`,at(n,`Agent`,e.agent,88,B),at(n,`Updated`,$e(e.updatedAt),104,B),at(n,`Session`,`#${e.id.slice(0,8)}`,120,B),n.setLineDash([2,3]),n.beginPath(),n.moveTo(18,140),n.lineTo(B-18,140),n.stroke(),n.setLineDash([]),n.font=`700 12px 'Courier New', monospace`,n.fillText(`SESSION TOC RECEIPT LIST`,18,163),n.font=`11px 'Courier New', monospace`;let a=185;for(let t of e.items){let e=Ze(t.count);n.fillText(ot(n,t.label,168),18,a),n.fillText(e,B-18-n.measureText(e).width,a),a+=17}return n.strokeStyle=`rgba(0, 0, 0, 0.62)`,n.lineWidth=1.5,n.beginPath(),n.moveTo(18,a+5),n.lineTo(B-18,a+5),n.stroke(),a+=26,at(n,`Input tokens`,Ze(e.stats.total_input_tokens),a,B),a+=16,at(n,`Output tokens`,Ze(e.stats.total_output_tokens),a,B),a+=16,at(n,`Messages`,Ze(e.stats.message_count),a,B),a+=22,n.font=`700 13px 'Courier New', monospace`,at(n,`TOTAL COST`,Qe(e.stats.total_cost),a,B),n.strokeStyle=`rgba(0, 0, 0, 0.45)`,n.setLineDash([4,4]),n.beginPath(),n.moveTo(18,a+18),n.lineTo(B-18,a+18),n.stroke(),n.setLineDash([]),n.font=`10px 'Courier New', monospace`,n.textAlign=`center`,n.fillStyle=`rgba(0, 0, 0, 0.62)`,U(n,e.title,B-36,2).forEach((e,t)=>{n.fillText(e,B/2,a+38+t*13)}),t}function W(e,t){return e*R+t}function ct(e){let{receiptWidth:t,receiptHeight:n,startX:r,startY:i}=e,a=t/(R-1),o=n/(z-1),s=[],c=[];for(let e=0;e<z;e+=1)for(let t=0;t<R;t+=1){let n=r+t*a,c=i+e*o;s.push({x:n,y:c,oldX:n,oldY:c,fixedX:e===0?n:null,fixedY:e===0?c:null})}let l=(e,t,n)=>{let r=s[e],i=s[t];!r||!i||c.push({a:e,b:t,length:Math.hypot(i.x-r.x,i.y-r.y),stiffness:n})};for(let e=0;e<z;e+=1)for(let t=0;t<R;t+=1){let n=W(e,t);t<R-1&&l(n,W(e,t+1),.98),e<z-1&&l(n,W(e+1,t),.92),e<z-1&&t<R-1&&(l(n,W(e+1,t+1),.46),l(W(e+1,t),W(e,t+1),.46)),t<R-2&&l(n,W(e,t+2),.35),e<z-2&&l(n,W(e+2,t),.28)}return{particles:s,constraints:c,receiptWidth:t,receiptHeight:n}}function lt(e,t){let n=t.receiptWidth/(R-1);for(let r=0;r<R;r+=1){let i=e[r];i&&(i.fixedX=t.startX+r*n,i.fixedY=t.startY)}}function ut(e){for(let t=0;t<R;t+=1){let n=e[t];!n||n.fixedX==null||n.fixedY==null||(n.x=n.fixedX,n.y=n.fixedY,n.oldX=n.fixedX,n.oldY=n.fixedY)}}function dt(e,t){let n=e[t.a],r=e[t.b];if(!n||!r)return;let i=r.x-n.x,a=r.y-n.y,o=Math.hypot(i,a);if(o<1e-4)return;let s=(o-t.length)/o*t.stiffness,c=n.fixedX!=null&&n.fixedY!=null,l=r.fixedX!=null&&r.fixedY!=null,u=c?0:l?1:.5,d=l?0:c?1:.5,f=i*s,p=a*s;c||(n.x+=f*u,n.y+=p*u),l||(r.x-=f*d,r.y-=p*d)}function ft(e,t,n,r,i){let a=n[W(r,i)],o=n[W(r,i+1)],s=n[W(r+1,i)],c=n[W(r+1,i+1)];if(!a||!o||!s||!c)return;let l=i/(R-1)*t.width,u=r/(z-1)*t.height,d=t.width/(R-1),f=t.height/(z-1);e.save(),e.beginPath(),e.moveTo(a.x,a.y),e.lineTo(o.x,o.y),e.lineTo(c.x,c.y),e.lineTo(s.x,s.y),e.closePath(),e.clip(),e.transform((o.x-a.x)/d,(o.y-a.y)/d,(s.x-a.x)/f,(s.y-a.y)/f,a.x,a.y),e.drawImage(t,l,u,d+1,f+1,0,0,d+1,f+1),e.restore();let p=Math.atan2(o.y-a.y,o.x-a.x),m=Math.hypot(s.x-a.x,s.y-a.y)/(V/(z-1)),h=Math.sin(p)*.08+(m-1)*.16;Math.abs(h)<.01||(e.save(),e.beginPath(),e.moveTo(a.x,a.y),e.lineTo(o.x,o.y),e.lineTo(c.x,c.y),e.lineTo(s.x,s.y),e.closePath(),e.fillStyle=h>0?`rgba(255,255,255,${h})`:`rgba(0,0,0,${-h})`,e.fill(),e.restore())}function pt(e,t,n){let r=null,i=44;for(let a=R;a<e.length;a+=1){let o=e[a];if(!o)continue;let s=Math.hypot(o.x-t,o.y-n);s<i&&(i=s,r=a)}return r}function mt({session:e,toc:t}){let n=(0,j.useRef)(null),r=(0,j.useRef)(null),i=(0,j.useRef)(null),a=(0,j.useMemo)(()=>it(e,t),[e,t]);return(0,j.useLayoutEffect)(()=>{let e=n.current,t=r.current,o=i.current;if(!e||!t||!o)return;let s=e.getContext(`2d`,{alpha:!0});if(!s)return;let c={id:null,x:0,y:0,prevX:0,prevY:0,vx:0,vy:0,grabbedIndex:null},l=st(a),u=0,d=0,f=0,p=ct({receiptWidth:B,receiptHeight:V,startX:0,startY:32}),m=performance.now(),h=null,g=0,_=0,ee=!1,te=!0,ne=!1,v=window.matchMedia(`(min-width: 1280px)`),y=()=>v.matches&&document.visibilityState===`visible`&&te,re=()=>{let e=t.getBoundingClientRect(),n=Math.max(280,e.width||320),r=Math.min(B,n-34);return{receiptWidth:r,receiptHeight:Math.min(V,Math.max(320,f-e.top-42)),startX:e.left+(e.width-r)/2,startY:e.top+32}},b=t=>{ee!==t&&(ee=t,e.style.visibility=t?`visible`:`hidden`,o.style.visibility=t?`visible`:`hidden`)},ie=()=>{ne=!1,u&&=(window.cancelAnimationFrame(u),0),b(!1)},x=(e,t=performance.now())=>{p=ct(e),h=e,m=t},ae=()=>{let t=window.devicePixelRatio||1;d=Math.max(1,window.innerWidth),f=Math.max(1,window.innerHeight),e.width=Math.floor(d*t),e.height=Math.floor(f*t),s.setTransform(t,0,0,t,0,0),g=0,_=0,b(!1),x(re()),y()&&oe()},oe=()=>{ne||!y()||(ne=!0,u=window.requestAnimationFrame(T))},S=()=>{y()?ae():ie()},se=e=>({x:e.clientX,y:e.clientY}),ce=e=>{if(e.button!==0)return;let t=se(e),n=pt(p.particles,t.x,t.y);n!=null&&(e.preventDefault(),o.setPointerCapture(e.pointerId),c.id=e.pointerId,c.x=t.x,c.y=t.y,c.prevX=t.x,c.prevY=t.y,c.vx=0,c.vy=0,c.grabbedIndex=n,_=0,oe())},le=e=>{if(c.id!==e.pointerId)return;let t=se(e);c.vx=t.x-c.prevX,c.vy=t.y-c.prevY,c.prevX=t.x,c.prevY=t.y,c.x=t.x,c.y=t.y},ue=e=>{if(c.id!==e.pointerId)return;let t=c.grabbedIndex==null?null:p.particles[c.grabbedIndex];t&&(t.oldX=t.x-c.vx*.9,t.oldY=t.y-c.vy*.9),c.id=null,c.grabbedIndex=null},de=e=>{let t=(e-m)/1e3;for(let e=R;e<p.particles.length;e+=1){let n=p.particles[e];if(!n)continue;let r=(n.x-n.oldX)*.985,i=(n.y-n.oldY)*.985;n.oldX=n.x,n.oldY=n.y,n.x+=r+Math.sin(t*1.7+e*.19)*.018,n.y+=i+.22}let n=c.grabbedIndex==null?null:p.particles[c.grabbedIndex];n&&(n.x+=(c.x-n.x)*.72,n.y+=(c.y-n.y)*.72)},fe=()=>{for(let e=0;e<Xe;e+=1){ut(p.particles);for(let e of p.constraints)dt(p.particles,e)}ut(p.particles)},C=()=>{let e=1/0,t=1/0,n=-1/0,r=-1/0;for(let i of p.particles)e=Math.min(e,i.x),t=Math.min(t,i.y),n=Math.max(n,i.x),r=Math.max(r,i.y);o.style.transform=`translate3d(${e-20}px, ${t-20}px, 0)`,o.style.width=`${n-e+40}px`,o.style.height=`${r-t+40}px`},pe=()=>{let e=p.particles[0],t=p.particles[R-1],n=p.particles[z*R-1],r=p.particles[(z-1)*R];!e||!t||!n||!r||(s.save(),s.shadowColor=`rgba(0,0,0,0.24)`,s.shadowBlur=24,s.shadowOffsetY=16,s.fillStyle=`rgba(0,0,0,0.14)`,s.beginPath(),s.moveTo(e.x,e.y),s.lineTo(t.x,t.y),s.lineTo(n.x,n.y),s.lineTo(r.x,r.y),s.closePath(),s.fill(),s.restore())},w=()=>{let e=p.particles[0],t=p.particles[R-1];!e||!t||(s.save(),s.strokeStyle=`rgba(0,0,0,0.72)`,s.lineWidth=4,s.lineCap=`round`,s.beginPath(),s.moveTo(e.x-10,e.y-3),s.lineTo(t.x+10,t.y-3),s.stroke(),s.strokeStyle=`rgba(255,255,255,0.55)`,s.lineWidth=1,s.beginPath(),s.moveTo(e.x-8,e.y-5),s.lineTo(t.x+8,t.y-5),s.stroke(),s.restore())},me=()=>{s.clearRect(0,0,d,f),pe();for(let e=0;e<z-1;e+=1)for(let t=0;t<R-1;t+=1)ft(s,l,p.particles,e,t);w(),C()},T=e=>{if(!ne)return;if(!y()){ie();return}let t=re();if(Ye(h,t)&&c.id==null?(g=0,b(!1),x(t,e)):(g+=1,h=t),lt(p.particles,t),de(e),fe(),me(),_=c.id==null?_+1:0,g>=2&&b(!0),g>=2&&_>=90){ne=!1,u=0;return}u=window.requestAnimationFrame(T)};b(!1),y()&&ae();let he=new ResizeObserver(ae);he.observe(t);let E=new IntersectionObserver(([e])=>{te=!!e?.isIntersecting,S()});return E.observe(t),v.addEventListener(`change`,S),document.addEventListener(`visibilitychange`,S),window.addEventListener(`resize`,S),o.addEventListener(`pointerdown`,ce),o.addEventListener(`pointermove`,le),o.addEventListener(`pointerup`,ue),o.addEventListener(`pointercancel`,ue),oe(),()=>{ie(),he.disconnect(),E.disconnect(),v.removeEventListener(`change`,S),document.removeEventListener(`visibilitychange`,S),window.removeEventListener(`resize`,S),o.removeEventListener(`pointerdown`,ce),o.removeEventListener(`pointermove`,le),o.removeEventListener(`pointerup`,ue),o.removeEventListener(`pointercancel`,ue)}},[a]),(0,F.jsx)(`aside`,{className:`hidden xl:block`,children:(0,F.jsxs)(`div`,{ref:r,className:`sticky top-4 h-[560px]`,children:[(0,F.jsx)(`canvas`,{ref:n,className:`invisible pointer-events-none fixed inset-0 z-40 block h-screen w-screen touch-none`,"aria-hidden":`true`}),(0,F.jsx)(`div`,{ref:i,className:`invisible fixed left-0 top-0 z-40 cursor-grab touch-none active:cursor-grabbing`,"aria-label":`Interactive thermal receipt with Verlet paper simulation`})]})})}var ht={a:({children:e})=>(0,F.jsx)(`span`,{className:`console-markdown-link`,children:e})};function gt(e){return e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`)}function _t(e){let t=e?.trim();if(!t)return null;let n=Array.from(new Set((t.match(/"[^"]+"|\S+/g)??[]).map(e=>e.replace(/^"|"$/g,``).trim()).filter(Boolean).filter(e=>!/^OR$/i.test(e))));return n.length===0?null:RegExp(`(${n.map(gt).join(`|`)})`,`gi`)}function vt({text:e,highlightQuery:t}){let r=(0,j.useRef)(null),i=(0,j.useMemo)(()=>_t(t),[t]);return(0,j.useEffect)(()=>{let e=r.current;if(!e||!i)return;let t=document.createTreeWalker(e,NodeFilter.SHOW_TEXT),n=[];for(;t.nextNode();){let e=t.currentNode;if(!(e instanceof Text))continue;let r=e.parentElement;r&&(r.closest(`mark, pre, code`)||e.textContent?.trim()&&n.push(e))}for(let e of n){let t=e.textContent??``;if(i.lastIndex=0,!i.test(t))continue;let n=document.createDocumentFragment(),r=0;i.lastIndex=0;for(let e of t.matchAll(i)){let i=e.index??0,a=e[0]??``;i>r&&n.append(t.slice(r,i));let o=document.createElement(`mark`);o.textContent=a,n.append(o),r=i+a.length}r<t.length&&n.append(t.slice(r)),e.parentNode?.replaceChild(n,e)}},[i,e]),(0,F.jsx)(`div`,{ref:r,children:(0,F.jsx)(n,{components:ht,children:e})})}function G(e){if(typeof e==`string`)return e;if(Array.isArray(e))return e.map(e=>{if(typeof e==`string`)return e;if(e&&typeof e==`object`){let t=e,n=G(t.text);if(n.trim())return n;let r=G(t.content);if(r.trim())return r}return``}).filter(Boolean).join(`
2
+
3
+ `);if(e&&typeof e==`object`){let t=e,n=G(t.text);if(n.trim())return n;let r=G(t.content);if(r.trim())return r}return``}function yt(e){return e.type===`tool`||e.type===`plan`?!0:e.type===`text`||e.type===`reasoning`?!!G(e.text).trim():!1}function bt(e){return e.reduce((e,t)=>{if(!yt(t))return e;let n=e.at(-1);return t.type!==`plan`&&n?.type===t.type?(n.parts.push(t),e):(e.push({type:t.type,parts:[t]}),e)},[])}var xt=`<turn_aborted>
4
+ The user interrupted the previous turn on purpose. Any running unified exec processes were terminated. If any tools/commands were aborted, they may have partially executed; verify current state before retrying.
5
+ </turn_aborted>`;function St(e){return e.replace(/\r\n/g,`
6
+ `).trim()}function K(e,t){if(t.toLowerCase()!==`codex`||e.role!==`user`||e.parts.length!==1)return!1;let[n]=e.parts;return!n||n.type!==`text`||typeof n.text!=`string`?!1:St(n.text)===St(xt)}function q(e){return e&&typeof e==`object`&&!Array.isArray(e)?e:{}}function Ct(e){return typeof e==`string`?e:``}function wt(e){return e.replace(/\\n/g,`
7
+ `)}function Tt(e){let t=q(e),n=Ct(t.type);return n?{type:n,path:Ct(t.path),oldPath:Ct(t.old_path),targetPath:Ct(t.targetPath),content:Ct(t.content)||Ct(q(t.input).content)}:null}function J(e){return(Array.isArray(e)?e:Array.isArray(q(e).content)?q(e).content:[]).map(e=>Tt(e)).filter(e=>e!=null)}function Et(e,t,n){return`${e} ${e===1?t:n}`}function Dt(e){let t=e.filter(e=>e.type===`write_file`).length,n=e.filter(e=>e.type===`edit_file`).length,r=e.filter(e=>e.type===`delete_file`).length,i=e.filter(e=>e.type===`move_file`).length,a=[];return t>0&&a.push(Et(t,`write`,`writes`)),n>0&&a.push(Et(n,`edit`,`edits`)),r>0&&a.push(Et(r,`delete`,`deletes`)),i>0&&a.push(Et(i,`move`,`moves`)),a.join(` · `)}function Ot(e){return e.targetPath||e.path||e.oldPath||e.type}function kt(e,t){return e.reduce((e,n)=>n.type===`write_file`?(e.push({label:Ot(n),operation:`write`,language:t(n.path),isCode:!0,text:wt(n.content)}),e):n.type===`edit_file`?(e.push({label:Ot(n),operation:`edit`,language:`diff`,isCode:!0,text:wt(n.content)}),e):n.type===`delete_file`?(e.push({label:Ot(n),operation:`edit`,language:`text`,isCode:!1,text:`File deleted.`}),e):(n.type===`move_file`&&e.push({label:Ot(n),operation:`edit`,language:`text`,isCode:!1,text:n.targetPath&&n.path?`Moved from ${n.path} to ${n.targetPath}`:n.oldPath?`Moved from ${n.oldPath}`:`File moved.`}),e),[])}function At(e,t,n){let r=kt(e,n);return r.length>0?{kind:`file-sections`,sections:r}:{kind:`plain`,text:t,language:`text`,isCode:!1}}function jt(e){if(typeof e==`string`)return e.trim();if(Array.isArray(e))return e.map(e=>jt(e)).filter(Boolean).join(`
8
+
9
+ `).trim();if(e&&typeof e==`object`){let t=e,n=jt(t.text);if(n)return n;let r=jt(t.content);if(r)return r}return``}function Mt(e){let t=e.approval_status===`fail`?`fail`:`success`,n=jt(t===`fail`?e.output:e.input);return{title:`plan`,secondaryText:void 0,approvalStatus:t,expandable:!!n,contentLabel:t===`fail`?`Rejected`:`Plan`,contentMarkdown:n}}function Nt(e){return e&&typeof e==`object`&&!Array.isArray(e)?e:{}}function Pt(e){return typeof e==`string`?e.trim():``}function Ft(e){return typeof e==`string`?e:``}function It(e){return typeof e==`string`?e.trim():typeof e==`number`||typeof e==`bigint`||typeof e==`boolean`?`${e}`:``}function Lt(e){return e.replace(/\\n/g,`
10
+ `)}function Rt(e){return e.replace(/\s*\(Recommended\)\s*$/i,``).trim()}function zt(e){let t=e.trim();return{label:Rt(t),recommended:/\(Recommended\)\s*$/i.test(t)}}function Bt(e){return e.replace(/\s+/g,` `).trim()}function Vt(e,t=88){let n=Bt(e);return n?n.length>t?`${n.slice(0,t)}...`:n:``}function Ht(e,t){return Vt([`${t} questions`,...e.filter(Boolean).slice(0,2)].join(` · `),96)}function Ut(e){try{return JSON.parse(e)}catch{return null}}function Wt(e){let t=Lt(e).split(`
11
+ `);if(t.length<5||!(/^Chunk ID:\s+\S+/.test(t[0]||``)&&/^Wall time:\s+/.test(t[1]||``)&&/^Process (?:exited with code \d+|running with session ID \d+)/.test(t[2]||``)&&/^Original token count:\s+\d+/.test(t[3]||``)&&/^Output:$/.test(t[4]||``)))return e;let n=5;for(;n<t.length&&t[n]?.trim()===``;)n+=1;let r=t.slice(n).join(`
12
+ `);return r.trim()?r:e}function Gt(e,t,n){n.trim()&&e.push({label:t,value:n})}function Kt(e){return e.startsWith(`"`)&&e.endsWith(`"`)||e.startsWith(`'`)&&e.endsWith(`'`)?e.slice(1,-1):e}function qt(e){return e.trim()?!/[|&;<>()$`*?{}[\]\\]/.test(e):!1}function Jt(e){let t=Kt(e.trim());return qt(t)?t:null}function Yt(e){let t=e.trim();if(!t)return null;let n=t.match(/^nl\s+-ba\s+([^\s]+)\s*\|\s*sed\s+-n\s+['"][^'"]+['"]$/);if(n)return Jt(n[1]||``);for(let e of[/^cat\s+([^\s]+)$/,/^sed\s+-n\s+['"][^'"]+['"]\s+([^\s]+)$/,/^head\s+-n\s+\d+\s+([^\s]+)$/,/^tail\s+-n\s+\d+\s+([^\s]+)$/]){let n=t.match(e);if(n)return Jt(n[1]||``)}return null}function Xt(e){let t=e.split(`
13
+ `),n=t.filter(e=>e.trim());if(n.length===0)return e;let r=/^\s*\d+(?:\t|\|\s?)/;return n.filter(e=>r.test(e)).length/n.length<.6?e:t.map(e=>e.replace(/^\s*\d+(?:\t|\|\s?)/,``)).join(`
14
+ `)}function Zt(e){return/\b(Test Files|Tests|Coverage report|coverage: platform|Ran \d+ tests)\b/.test(e)||/^(PASS|FAIL|stdout\s+\|)/m.test(e)||/\bmodules transformed\b/.test(e)}function Qt(e){let t=e.trim();return!t||Zt(t)?null:(t.startsWith(`{`)||t.startsWith(`[`))&&Ut(t)!=null?`json`:/<(!DOCTYPE html|html\b|body\b|div\b|span\b|main\b|section\b|svg\b|\/[a-z])/i.test(t)?`markup`:[/^#{1,6}\s/m,/^[-*]\s/m,/^\d+\.\s/m,/^```/m].filter(e=>e.test(t)).length>=1&&!/[{};]\s*$/.test(t)?`markdown`:(t.match(/^[A-Za-z0-9_-]+:\s.+$/gm)||[]).length>=2&&!/\b(import|export|const|let|function|class)\b/.test(t)&&!/[{}()[\];]/.test(t)?`yaml`:[/^(from\s+\S+\s+import\s+.+|import\s+\S+)/m,/^def\s+\w+\(/m,/^class\s+\w+[:(]/m].filter(e=>e.test(t)).length>=2||/^(from\s+\S+\s+import\s+.+|import\s+\S+)/m.test(t)&&/^def\s+\w+\(/m.test(t)?`python`:[/\binterface\s+\w+/,/\btype\s+\w+\s*=/,/\bimplements\b/,/\bas const\b/,/:\s*[A-Z][A-Za-z0-9_<>,[\] |&?]+/].filter(e=>e.test(t)).length>=1&&/\b(import|export|const|let|function|class)\b/.test(t)?`typescript`:[/^\s*import\s.+from\s/m,/^\s*export\s/m,/\b(const|let|function|class)\b/].filter(e=>e.test(t)).length>=2?`javascript`:null}function $t(e,t,n){let r=Wt(t),i=Yt(e);if(i){let e=n(i);return{text:Xt(r),language:e,isCode:e!==`text`,sourcePath:i,confidence:`path`}}let a=Qt(r);return a?{text:r,language:a,isCode:!0,confidence:`content`}:{text:r,language:`text`,isCode:!1,confidence:`plain`}}function en(e,t,n){let r=Nt(e),i=Pt(r.cmd),a=Pt(r.workdir),o=Pt(r.sandbox_permissions),s=Pt(r.justification),c=[];Gt(c,`Command`,i),Gt(c,`Workdir`,a),Gt(c,`Escalation`,o),Gt(c,`Justification`,s);let l=Vt(i);return{secondaryText:s?[s,l].filter(Boolean).join(`
15
+ `):l||void 0,details:c,outputAnalysis:$t(i,t,n)}}function tn(e,t,n){let r=Nt(e),i=It(r.session_id),a=Ft(r.chars),o=a?`stdin`:`poll`,s=[];return Gt(s,`Session`,i),s.push({label:`Chars`,value:a||`(empty)`}),{secondaryText:i?`session #${i} · ${o}`:o,details:s,outputAnalysis:$t(``,t,n)}}function nn(e,t){let n=Nt(e),r=Array.isArray(n.questions)?n.questions:null;if(!r||r.length===0)return{secondaryText:void 0,details:[],outputContent:{kind:`plain`,text:t,language:`text`,isCode:!1}};let i=Nt(Ut(t)?.answers),a=r.map(e=>{let t=Nt(e),n=Nt(i[Pt(t.id)]),r=(Array.isArray(n.answers)?n.answers:[]).map(e=>typeof e==`string`?Rt(e):``).filter(Boolean),a=Array.isArray(t.options)?t.options.map(e=>{let t=Nt(e),n=zt(Pt(t.label));return n.label?{label:n.label,description:Pt(t.description)||void 0,recommended:n.recommended||void 0}:null}).filter(e=>e!=null):[],o=Pt(t.question);return o?{header:Pt(t.header)||void 0,question:o,options:a,answers:r}:null}).filter(e=>e!=null);return a.length===0?{secondaryText:void 0,details:[],outputContent:{kind:`plain`,text:t,language:`text`,isCode:!1}}:{secondaryText:Ht(a.map(e=>e.header||``),a.length),details:[],outputContent:{kind:`question-list`,questions:a}}}function rn(e){return ln(e)?`Browser`:typeof e.title==`string`&&e.title.trim()?on(e.title):typeof e.tool==`string`&&e.tool.trim()?on(e.tool):`tool`}function an(e){return ln(e)?`browser`:on(typeof e.tool==`string`&&e.tool.trim()?e.tool:rn(e)).toLowerCase()}function on(e){return e.trim().replace(/^tool:\s*/i,``).replace(/^\.+(?=\w)/,``)}function sn(e){return e&&typeof e==`object`&&!Array.isArray(e)?e:{}}function cn(e){return typeof e==`string`?e.trim():``}function ln(e){let t=cn(sn(e.state?.metadata).namespace);return on(cn(e.tool)).toLowerCase()===`js`&&(t===`mcp__node_repl__`||t===`mcp__node_repl__.js`)}function un(e,t){let n=an(t),r=`tool:${n}`,i=e.get(n);if(i){i.count+=1;return}e.set(n,{id:r,toolKey:n,label:rn(t),count:1})}function dn(e){let t={user:0,agent_message:0,thinking:0,plan:0,tools_all:0},n=new Set,r=new Map;for(let{msg:i,blocks:a}of e)for(let e of a){if(i.role===`user`){t.user+=1,n.add(`user`);continue}if(e.type===`text`){t.agent_message+=1,n.add(`agent_message`);continue}if(e.type===`reasoning`){t.thinking+=1,n.add(`thinking`);continue}if(e.type===`plan`){t.plan+=1,n.add(`plan`);continue}t.tools_all+=e.parts.length,n.add(`tools_all`);for(let t of e.parts)un(r,t),n.add(`tool:${an(t)}`)}return{filterIds:n,counts:t,tools:[...r.values()].toSorted((e,t)=>e.label.localeCompare(t.label))}}function fn(e,t){return t.has(`tools_all`)?t.has(`tool:${an(e)}`):!1}function pn(e,t,n){return t.role===`user`?n.has(`user`):e.type===`text`?n.has(`agent_message`):e.type===`reasoning`?n.has(`thinking`):e.type===`plan`?n.has(`plan`):e.parts.some(e=>fn(e,n))}function mn(e,t){let n=e.parts.filter(e=>fn(e,t));return n.length===0?null:{...e,parts:n}}function hn(e,t){return e.map(e=>{let n=e.blocks.filter(n=>pn(n,e.msg,t)).map(e=>e.type===`tool`?mn(e,t):e).filter(e=>e!=null);return n.length===0?null:{msg:e.msg,blocks:n,index:e.index}}).filter(e=>e!=null)}function gn(e){let t=[];for(let n of e){let e=bt(n.parts);e.length!==0&&t.push({msg:n,blocks:e,index:t.length})}return t}var _n={".bashrc":`bash`,".zshrc":`bash`,".profile":`bash`,dockerfile:`docker`,".env":`ini`},vn={ts:`typescript`,tsx:`tsx`,js:`javascript`,jsx:`jsx`,py:`python`,sql:`sql`,rs:`rust`,go:`go`,java:`java`,c:`c`,h:`c`,cc:`cpp`,cpp:`cpp`,cxx:`cpp`,hpp:`cpp`,cs:`csharp`,sh:`bash`,bash:`bash`,zsh:`bash`,html:`html`,css:`css`,yaml:`yaml`,yml:`yaml`,json:`json`,md:`markdown`,toml:`toml`,conf:`ini`,xml:`markup`,svg:`markup`,properties:`ini`,dockerfile:`docker`};function Y(e){let t=e.split(`/`).pop()?.toLowerCase()??``;if(!t)return`text`;let n=_n[t];if(n)return n;if(t.startsWith(`.env.`))return`ini`;let r=t.includes(`.`)?t.split(`.`).pop()??``:``;return r&&vn[r]||`text`}T.registerLanguage(`bash`,he),T.registerLanguage(`c`,Ae),T.registerLanguage(`cpp`,_e),T.registerLanguage(`csharp`,je),T.registerLanguage(`css`,ke),T.registerLanguage(`docker`,E),T.registerLanguage(`go`,O),T.registerLanguage(`ini`,be),T.registerLanguage(`java`,k),T.registerLanguage(`javascript`,A),T.registerLanguage(`jsx`,ye),T.registerLanguage(`json`,D),T.registerLanguage(`markdown`,Oe),T.registerLanguage(`markup`,Se),T.registerLanguage(`python`,ve),T.registerLanguage(`rust`,Ee),T.registerLanguage(`sql`,we),T.registerLanguage(`toml`,ge),T.registerLanguage(`tsx`,xe),T.registerLanguage(`typescript`,Te),T.registerLanguage(`yaml`,Ce);function yn(e){return e===`html`||e===`xml`?`markup`:e}function bn({language:e,text:t}){return(0,F.jsx)(T,{language:yn(e),style:De,customStyle:{margin:0,padding:`0.75rem`,borderRadius:0,background:`transparent`,fontSize:`0.75rem`,lineHeight:1.55},codeTagProps:{className:`console-mono`},wrapLongLines:!0,children:t})}function xn(e,t){return`${e}:${t}`}function Sn(e){return/^(Index:|diff\s|===)/.test(e)?`text-[var(--console-text)] bg-[#f3f4f6]`:e.startsWith(`@@`)?`text-[#7c3aed] bg-[#f5f3ff]`:e.startsWith(`+++ `)||e.startsWith(`--- `)?`text-[#1d4ed8] bg-[#eff6ff]`:e.startsWith(`+`)?`text-[#15803d] bg-[#f0fdf4]`:e.startsWith(`-`)?`text-[#b91c1c] bg-[#fef2f2]`:`text-[var(--console-text)]`}function Cn({text:e}){let t=e.split(`
16
+ `),n=new Map;return(0,F.jsx)(`pre`,{className:`console-mono max-h-[420px] overflow-auto whitespace-pre rounded-sm border border-[var(--console-border)] bg-[#fafafa] p-3 text-xs leading-relaxed`,children:t.map(e=>{let t=n.get(e)??0;return n.set(e,t+1),(0,F.jsx)(`span`,{className:`block rounded-[2px] px-1 ${Sn(e)}`,children:e||` `},xn(e,t))})})}function wn(e){let t=e.text||`No output captured.`;return!e.isCode||e.language===`text`?(0,F.jsx)(`pre`,{className:`console-mono max-h-[420px] overflow-auto whitespace-pre-wrap break-all p-3 text-xs leading-relaxed text-[var(--console-text)]`,children:t}):e.language===`diff`?(0,F.jsx)(Cn,{text:t}):(0,F.jsx)(`div`,{className:`max-h-[420px] overflow-auto bg-[#fafafa]`,children:(0,F.jsx)(bn,{language:e.language,text:t})})}function Tn({sections:e}){return(0,F.jsx)(`div`,{className:`space-y-3`,children:e.map(e=>(0,F.jsxs)(`div`,{className:`overflow-hidden rounded-sm border border-[var(--console-border)] bg-[#fafafa]`,children:[(0,F.jsx)(`div`,{className:`border-b border-[var(--console-border)] bg-[var(--console-surface-muted)] px-3 py-1.5`,children:(0,F.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,F.jsx)(`span`,{className:`console-mono rounded-sm border border-[var(--console-border)] bg-white px-1.5 py-0.5 text-[10px] font-semibold uppercase tracking-wide text-[var(--console-muted)]`,children:e.operation}),(0,F.jsx)(`span`,{className:`console-mono text-[11px] font-semibold text-[var(--console-muted)]`,children:e.label})]})}),wn(e)]},`${e.operation}:${e.label}:${e.language}`))})}function En({questions:e}){return(0,F.jsx)(`div`,{className:`space-y-3`,children:e.map(e=>(0,F.jsxs)(`div`,{className:`overflow-hidden rounded-sm border border-[var(--console-border)] bg-[#fafafa]`,children:[(0,F.jsxs)(`div`,{className:`border-b border-[var(--console-border)] bg-[var(--console-surface-muted)] px-3 py-2`,children:[(0,F.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[e.header?(0,F.jsx)(`span`,{className:`console-mono rounded-sm border border-[var(--console-border)] bg-white px-1.5 py-0.5 text-[10px] font-semibold uppercase tracking-wide text-[var(--console-muted)]`,children:e.header}):null,e.answers.length>0?(0,F.jsx)(`span`,{className:`console-mono text-[11px] font-semibold text-[var(--console-success)]`,children:`Answered`}):(0,F.jsx)(`span`,{className:`console-mono text-[11px] font-semibold text-[var(--console-muted)]`,children:`Pending`})]}),(0,F.jsx)(`p`,{className:`mt-2 text-sm leading-relaxed text-[var(--console-text)]`,children:e.question})]}),(0,F.jsx)(`div`,{className:`space-y-2 p-3`,children:e.options.map(t=>{let n=e.answers.includes(t.label);return(0,F.jsxs)(`div`,{className:`rounded-sm border px-3 py-2 ${n?`border-[var(--console-success-border)] bg-[var(--console-success-bg)]`:`border-[var(--console-border)] bg-white`}`,children:[(0,F.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,F.jsx)(`span`,{className:`console-mono text-xs font-semibold ${n?`text-[var(--console-success)]`:`text-[var(--console-text)]`}`,children:t.label}),t.recommended?(0,F.jsx)(`span`,{className:`console-mono rounded-sm border border-[var(--console-border)] bg-[var(--console-surface-muted)] px-1.5 py-0.5 text-[10px] text-[var(--console-muted)]`,children:`Recommended`}):null,n?(0,F.jsx)(`span`,{className:`console-mono rounded-sm border border-[var(--console-success-border)] bg-white px-1.5 py-0.5 text-[10px] text-[var(--console-success)]`,children:`Selected`}):null]}),t.description?(0,F.jsx)(`p`,{className:`mt-1 text-xs leading-relaxed text-[var(--console-muted)]`,children:t.description}):null]},`${e.question}:${t.label}`)})})]},`${e.header??`question`}:${e.question}`))})}function Dn(e){return`${e.label}:${e.lines.map(e=>`${e.type}:${e.text}`).join(`
17
+ `)}`}function On(e){return e===`add`?`text-[#15803d] bg-[#f0fdf4]`:e===`remove`?`text-[#b91c1c] bg-[#fef2f2]`:`text-[var(--console-text)]`}function kn({blocks:e}){return(0,F.jsx)(`div`,{className:`space-y-3`,children:e.map(e=>{let t=new Map;return(0,F.jsxs)(`div`,{className:`overflow-hidden rounded-sm border border-[var(--console-border)] bg-[#fafafa]`,children:[(0,F.jsx)(`div`,{className:`border-b border-[var(--console-border)] bg-[var(--console-surface-muted)] px-3 py-1.5`,children:(0,F.jsx)(`span`,{className:`console-mono text-[11px] font-semibold text-[var(--console-muted)]`,children:e.label})}),(0,F.jsx)(`pre`,{className:`console-mono max-h-[280px] overflow-auto whitespace-pre p-3 text-xs leading-relaxed`,children:e.lines.map(e=>{let n=`${e.type}:${e.text}`,r=t.get(n)??0;return t.set(n,r+1),(0,F.jsxs)(`span`,{className:`block rounded-[2px] px-1 ${On(e.type)}`,children:[e.type===`add`?`+`:e.type===`remove`?`-`:` `,e.text||` `]},`${n}:${r}`)})})]},Dn(e))})})}function An({outputContent:e}){if(e.kind===`structured-diff`)return(0,F.jsx)(kn,{blocks:e.blocks});if(e.kind===`file-sections`)return(0,F.jsx)(Tn,{sections:e.sections});if(e.kind===`question-list`)return(0,F.jsx)(En,{questions:e.questions});let t=e.text||`No output captured.`;return!e.isCode||e.language===`text`?(0,F.jsx)(`pre`,{className:`console-mono max-h-[420px] overflow-auto whitespace-pre-wrap break-all rounded-sm border border-[var(--console-border)] bg-[#fafafa] p-3 text-xs leading-relaxed text-[var(--console-text)]`,children:t}):e.language===`diff`?(0,F.jsx)(Cn,{text:t}):(0,F.jsx)(`div`,{className:`max-h-[420px] overflow-auto rounded-sm border border-[var(--console-border)] bg-[#fafafa]`,children:(0,F.jsx)(bn,{language:e.language,text:t})})}var jn={completed:{label:`Success`,className:`border-[var(--console-success-border)] bg-[var(--console-success-bg)] text-[var(--console-success)]`,icon:c},error:{label:`Failed`,className:`border-[var(--console-error-border)] bg-[var(--console-error-bg)] text-[var(--console-error)]`,icon:w},running:{label:`Running`,className:`border-[var(--console-warning-border)] bg-[var(--console-warning-bg)] text-[var(--console-warning)]`,icon:oe}},Mn=32,Nn=80,Pn=280,Fn=6;function In(e){return e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`)}function Ln(e){let t=e?.trim();if(!t)return null;let n=Array.from(new Set((t.match(/"[^"]+"|\S+/g)??[]).map(e=>e.replace(/^"|"$/g,``).trim()).filter(Boolean).filter(e=>!/^OR$/i.test(e))));return n.length===0?null:RegExp(`(${n.map(In).join(`|`)})`,`gi`)}function Rn(e,t){let n=Ln(t);return n?e.split(n).map((e,t)=>e.match(n)?(0,F.jsx)(`mark`,{children:e},`${e}-${t}`):(0,F.jsx)(`span`,{children:e},`${e}-${t}`)):e}function zn({text:e,highlightQuery:t}){return(0,F.jsx)(vt,{text:e,highlightQuery:t})}function Bn(e){if(e==null)return``;if(typeof e==`string`){let t=e.trim();if(!t)return``;try{let e=JSON.parse(t);return JSON.stringify(e,null,2)}catch{return e}}try{return JSON.stringify(e,null,2)}catch{return typeof e==`number`||typeof e==`bigint`||typeof e==`boolean`?`${e}`:typeof e==`symbol`?e.description?`Symbol(${e.description})`:`Symbol`:typeof e==`function`?`[Function]`:`[Unserializable value]`}}function Vn(e){if(typeof e!=`string`)return e;try{return JSON.parse(e)}catch{return e}}function Hn(e){if(typeof e==`string`)return[e];if(Array.isArray(e))return e.flatMap(e=>Hn(e));if(e&&typeof e==`object`){let t=e;if(typeof t.text==`string`)return[t.text];if(t.content!==void 0)return Hn(t.content)}return[]}function Un(e){return e.replace(/^<system>/i,``).replace(/<\/system>$/i,``).trim()}function Wn(e,t=!0){let n=Hn(e).map(e=>e.trim()).filter(e=>t?!!e:!!e&&!/^<system>[\s\S]*<\/system>$/i.test(e));return n.length===0?``:n.map(e=>t&&/^<system>[\s\S]*<\/system>$/i.test(e)?Un(e):e).join(`
18
+ `)}function Gn(e){let t=Vn(e);if(t&&typeof t==`object`){let e=t;if(typeof e.cmd==`string`)return e.cmd;if(typeof e.command==`string`)return e.command}return``}function Kn(e){return typeof e==`string`?e.trim():``}function X(e){return e&&typeof e==`object`&&!Array.isArray(e)?e:{}}function Z(e){return typeof e==`string`?e.trim():``}function qn(e){return typeof e==`string`?e:``}function Jn(e){return typeof e.title==`string`&&e.title.trim()?lr(e.title):typeof e.tool==`string`&&e.tool.trim()?lr(e.tool):`tool`}function Yn(e){return Jn(e).trim().toLowerCase()}function Xn(e,t){return`tool-${e}-${t}`}function Zn(e){let t=e.trim();return!t||t.length>300||t.includes(`
19
+ `)||/^[a-z]+:\/\//i.test(t)||/[<>{}]/.test(t)?!1:t.startsWith(`/`)||t.startsWith(`./`)||t.startsWith(`../`)||t.startsWith(`~/`)||t.includes(`/`)||t.includes(`\\`)?!0:/^[A-Za-z0-9_.@-]+\.[A-Za-z0-9_-]+$/.test(t)}function Qn(e){let t=e.trim().toLowerCase();return!t||t.includes(`command`)||t.includes(`content`)||t.includes(`text`)||t.includes(`prompt`)||t.includes(`url`)||t.includes(`body`)||t.includes(`title`)||t.includes(`description`)||t===`cwd`||t===`workdir`||t===`directory`?!1:t===`path`||t===`paths`||t.includes(`file`)||t.includes(`path`)}function $n(e,t,n,r=0){if(!(e==null||r>4)){if(typeof e==`string`){Qn(t)&&Zn(e)&&n.add(e.trim());return}if(Array.isArray(e)){for(let i of e)$n(i,t,n,r+1);return}if(typeof e==`object`)for(let[t,i]of Object.entries(e))$n(i,t,n,r+1)}}function er(e){let t=new Set;return $n(e,``,t),[...t]}function tr(e){return e.state?.arguments??e.state?.input??e.input??null}function nr(e){let t=Yn(e);return t===`read`?`read`:t===`edit`||t===`multiedit`||t===`apply_patch`||t===`notebookedit`?`edit`:t===`write`||t===`create_file`||t===`write_file`?`write`:t===`delete`||t===`delete_file`?`delete`:null}function rr(e){let t=new Map;for(let n of e){let e=t.get(n.path);if(e){e.count+=1,e.anchors.push({anchorId:n.anchorId,time:n.time,toolLabel:n.toolLabel}),n.time>=e.latestTime&&(e.latestTime=n.time,e.latestAnchorId=n.anchorId,e.toolLabel=n.toolLabel);continue}t.set(n.path,{path:n.path,count:1,latestTime:n.time,latestAnchorId:n.anchorId,toolLabel:n.toolLabel,anchors:[{anchorId:n.anchorId,time:n.time,toolLabel:n.toolLabel}]})}return[...t.values()].map(e=>({...e,anchors:e.anchors.toSorted((e,t)=>e.time-t.time)})).toSorted((e,t)=>t.latestTime===e.latestTime?e.path.localeCompare(t.path):t.latestTime-e.latestTime)}function ir(e){let t=new Map,n=new Map,r={read:[],edit:[],write:[],delete:[]};return e.forEach(({msg:e,blocks:i,index:a})=>{let o=0;for(let s of i)if(s.type===`tool`)for(let i of s.parts){let s=Xn(a,o);o+=1,t.set(i,s),n.set(s,a);let c=tr(i),l=Jn(i),u=i.time_created??e.time_created,d=J(c);if(d.length>0){for(let e of d){let t=(e.path||e.oldPath).trim();if(!t)continue;let n=e.type===`write_file`?`write`:e.type===`delete_file`?`delete`:`edit`;r[n].push({kind:n,path:t,anchorId:s,time:u,toolLabel:l})}continue}let f=nr(i);if(!f)continue;let p=er(c);for(let e of p)r[f].push({kind:f,path:e,anchorId:s,time:u,toolLabel:l})}}),{toolAnchorIds:t,anchorMessageIndexes:n,summary:{read:rr(r.read),edit:rr(r.edit),write:rr(r.write),delete:rr(r.delete)}}}function ar(e,t){if(!e)return t;let n={read:[],edit:[],write:[],delete:[]},r=new Map;for(let e of[`read`,`edit`,`write`,`delete`])for(let n of t[e])r.set(`${e}\0${n.path}`,n);for(let t of e){let e=r.get(`${t.kind}\0${t.path}`);n[t.kind].push({path:t.path,count:t.count,latestTime:t.latest_time,latestAnchorId:e?.latestAnchorId??``,toolLabel:e?.toolLabel??t.kind,anchors:e?.anchors??[]})}for(let e of[`read`,`edit`,`write`,`delete`])n[e].sort((e,t)=>t.latestTime===e.latestTime?e.path.localeCompare(t.path):t.latestTime-e.latestTime);return n}function or(e,t){return e.startsWith(`${t}/`)?e.slice(t.length+1):e}function sr(e,t){if(typeof document>`u`)return;let n=document.getElementById(e);if(!n&&t){t();let r=0,i=()=>{if(n=document.getElementById(e),n){n.scrollIntoView({behavior:`smooth`,block:`center`});return}r+=1,r<8&&requestAnimationFrame(i)};requestAnimationFrame(i);return}n&&n.scrollIntoView({behavior:`smooth`,block:`center`})}function cr(e){try{return JSON.parse(e)}catch{return null}}function Q(e){return e.replace(/\\n/g,`
20
+ `)}function lr(e){let t=e.trim();return t?t.replace(/^tool:\s*/i,``).replace(/^\.+(?=\w)/,``):``}function ur(e,t=`Tool`){return lr(Z(e.title))||Z(e.tool)||t}function dr(e){return Q(Wn(e)||Bn(e))||`No output captured.`}function $(e){let t=dr(e.outputValue);if(t!==`No output captured.`)return t;let n=dr(e.errorValue);return n===`No output captured.`?`No output captured.`:n}function fr(e){let t=e.indexOf(`Output:
21
+ `);if(t===-1)return e;let n=cr(e.slice(t+8).trim());return Array.isArray(n)&&n.map(e=>Z(X(e).text)).filter(Boolean).join(`
22
+ `)||e}function pr(e){let t=X(e);return Z(t.filePath)||Z(t.file_path)||Z(t.path)||Z(t.targetFile)||Z(t.effectiveUri)||Z(t.relativeWorkspacePath)||``}function mr(e){return e&&typeof e==`object`&&!Array.isArray(e)?e:typeof e==`string`&&cr(e)||{}}function hr(e){return e.replace(/\n*<system-reminder>[\s\S]*$/i,``).trimEnd()}function gr(e){let t=Wn(e,!1)||dr(e);return t===`No output captured.`?t:hr(t.replace(/^<file>\s*/i,``).replace(/\s*<\/file>\s*$/i,``)).split(`
23
+ `).filter(e=>!/^\(End of file - total \d+ lines\)$/.test(e.trim())).map(e=>e.replace(/^\d+\|\s?/,``).replace(/^\s*\d+\t/,``)).join(`
24
+ `).trimEnd()||`No output captured.`}function _r(e){let t=qn(mr(e).contents);return t?Q(t):`No output captured.`}function vr(e){let t=mr(e),n=Array.isArray(t.directories)?t.directories:[];if(n.length===0)return dr(e);let r=n.flatMap(e=>{let t=X(e);return[Z(t.absPath),...(Array.isArray(t.files)?t.files:[]).map(e=>{let t=X(e);return Z(t.relPath)||Z(t.absPath)}).filter(Boolean).map(e=>` ${e}`)].filter(Boolean)});return r.length>0?r.join(`
25
+ `):`No output captured.`}function yr(e,t,n){return!t.trim()&&!n.trim()?[]:[{label:wr(e),lines:Sr(s(Q(t),Q(n)))}]}function br(e,t){let n=Q(e).split(`
26
+ `),r=Q(t).split(`
27
+ `);return[`@@`,...n.map(e=>`- ${e}`),...r.map(e=>`+ ${e}`)].join(`
28
+ `)}function xr(e){let t=Q(e),n=t.split(`
29
+ `);return t.endsWith(`
30
+ `)&&n.pop(),n}function Sr(e){return e.flatMap(e=>{let t=e.added?`add`:e.removed?`remove`:`context`;return xr(e.value).map(e=>({type:t,text:e}))})}function Cr(e){let t=X(e).edit;return Array.isArray(t)?t:t&&typeof t==`object`?[t]:[]}function wr(e){let t=e.trim();if(!t)return`edit`;let n=t.split(`/`).pop()||t;return n===t?n:`${n} · ${t}`}function Tr(e,t){let n=Cr(e.inputValue),r=wr(t);return n.map(e=>{let t=X(e),n=qn(t.old),i=qn(t.new);return!n.trim()&&!i.trim()?null:{label:r,lines:Sr(s(Q(n),Q(i)))}}).filter(e=>e!=null&&e.lines.length>0)}function Er(e){let t=qn(X(e.metadataValue).diff);if(t.trim())return Q(t);let n=Cr(e.inputValue).map(e=>{let t=X(e),n=qn(t.old),r=qn(t.new);return!n.trim()&&!r.trim()?``:br(n,r)}).filter(Boolean).join(`
31
+
32
+ `);return n.trim()?n:$(e)}function Dr(e){let t=X(e.inputValue);if(e.status===`completed`){let e=qn(t.content);if(e.trim())return Q(e)}return $(e)}function Or(e){let t=X(X(e.state).arguments),n=Kn(t.agent_type),r=Kn(e.nickname),i=[Kn(t.model),Kn(t.reasoning_effort)].filter(Boolean).join(`-`);return[[n,r].filter(Boolean).join(` - `),i].filter(Boolean).join(` `)}function kr(e){let t=X(e.state);return Kn(t.prompt)||Kn(X(t.arguments).message)||``}function Ar(e){let t=Kn(e.nickname);return e.role===`assistant`&&t?`AGENT (${t})`:e.role===`user`?`USER`:e.role===`tool`?`TOOL`:`AGENT`}function jr(e,t){if(t.toLowerCase()!==`cursor`)return e;let n=[];for(let t of e){if(t.role!==`tool`){n.push({...t,parts:[...t.parts]});continue}let e=n.at(-1);if(e?.role===`assistant`){e.parts.push(...t.parts);continue}n.push({...t,parts:[...t.parts]})}return n}function Mr(e){let t=e.state||{},n=t.status,r=n===`running`||n===`error`||n===`completed`?n:`completed`,i=t.output??t.result??``,a=t.error??``,o=Vn(t.input??t.arguments??{}),s=t.metadata??{};return{status:r,command:Gn(o),inputValue:o,outputValue:i,errorValue:a,metadataValue:s,inputText:Bn(o)}}function Nr(e,t){let n=(t.command||t.inputText||`{}`).replace(/\s+/g,` `).trim(),r=n.length>72?`${n.slice(0,72)}...`:n;return{Icon:v,title:ur(e),secondaryText:r?`(${r})`:void 0,details:[],expandable:!0,showInputPreview:!0,outputContent:{kind:`plain`,text:$(t),language:`text`,isCode:!1}}}function Pr(e,t,n){let r=Z(X(t.inputValue).name);return{...n,Icon:ne,title:Z(e.tool)||`skill`,secondaryText:r||void 0,expandable:!1,showInputPreview:!1}}function Fr(e,t){let n=Nr(e,t),r=(e.tool||``).toLowerCase(),i=X(t.inputValue),a=pr(t.inputValue);if(r===`read`)return{...n,Icon:x,title:`read`,secondaryText:a||void 0,showInputPreview:!1,outputContent:{kind:`plain`,text:gr(t.outputValue),language:Y(a),isCode:!0}};if(r===`edit`){let e=yr(a,qn(i.old_string),qn(i.new_string));return{...n,Icon:me,title:`edit`,secondaryText:a||void 0,showInputPreview:!1,outputContent:e.length>0?{kind:`structured-diff`,blocks:e}:{kind:`plain`,text:$(t),language:`text`,isCode:!1}}}return r===`write`?{...n,Icon:y,title:`write`,secondaryText:a||void 0,showInputPreview:!1,outputContent:{kind:`plain`,text:Dr(t),language:Y(a),isCode:!0}}:{...n,title:ur(e)}}function Ir(e,t){let n=Nr(e,t),r=(e.tool||``).toLowerCase(),i=X(t.inputValue);if(r===`glob`){let r=Z(i.pattern);return{...n,Icon:C,title:e.tool||`glob`,secondaryText:r||void 0,showInputPreview:!1,outputContent:{kind:`plain`,text:$(t),language:`text`,isCode:!1}}}if(r===`grep`){let r=[Z(i.path),Z(i.pattern)].filter(Boolean).join(` · `);return{...n,Icon:C,title:e.tool||`grep`,secondaryText:r||void 0,showInputPreview:!1,outputContent:{kind:`plain`,text:$(t),language:`text`,isCode:!1}}}if(r===`bash`){let r=Z(i.description),a=Z(i.command),o=r?`${r}${a?` (${a})`:``}`:a?`(${a})`:void 0;return{...n,Icon:v,title:e.tool||`bash`,secondaryText:o,showInputPreview:!1,outputContent:{kind:`plain`,text:$(t),language:`text`,isCode:!1}}}if(r===`read`){let r=pr(t.inputValue);return{...n,Icon:x,title:e.tool||`read`,secondaryText:r||void 0,showInputPreview:!1,outputContent:{kind:`plain`,text:gr(t.outputValue),language:Y(r),isCode:!0}}}if(r===`edit`){let r=pr(t.inputValue);return{...n,Icon:me,title:e.tool||`edit`,secondaryText:r||void 0,showInputPreview:!1,outputContent:{kind:`plain`,text:Er(t),language:`diff`,isCode:!0}}}if(r===`write`){let r=pr(t.inputValue),i=t.status===`completed`;return{...n,Icon:y,title:e.tool||`write`,secondaryText:r||void 0,showInputPreview:!1,outputContent:{kind:`plain`,text:Dr(t),language:Y(r),isCode:i}}}return r===`skill`?Pr(e,t,n):n}function Lr(e,t){let n=Nr(e,t),r=(e.tool||``).toLowerCase(),i=X(t.inputValue);if(r===`glob`){let r=Z(i.pattern);return{...n,Icon:C,title:e.title||`glob`,secondaryText:r||void 0,showInputPreview:!1,outputContent:{kind:`plain`,text:$(t),language:`text`,isCode:!1}}}if(r===`grep`){let r=[Z(i.path),Z(i.pattern)].filter(Boolean).join(` · `);return{...n,Icon:C,title:e.title||`grep`,secondaryText:r||void 0,showInputPreview:!1,outputContent:{kind:`plain`,text:$(t),language:`text`,isCode:!1}}}if(r===`shell`){let r=Z(i.command);return{...n,Icon:v,title:e.title||`bash`,secondaryText:r?`(${r})`:void 0,showInputPreview:!1,outputContent:{kind:`plain`,text:$(t),language:`text`,isCode:!1}}}if(r===`readfile`){let r=pr(t.inputValue);return{...n,Icon:x,title:e.title||`read`,secondaryText:r||void 0,showInputPreview:!1,outputContent:{kind:`plain`,text:gr(t.outputValue),language:Y(r),isCode:!0}}}if(r===`strreplacefile`){let r=pr(t.inputValue),i=Tr(t,r);return{...n,Icon:me,title:e.title||`edit`,secondaryText:r||void 0,showInputPreview:!1,outputContent:i.length>0?{kind:`structured-diff`,blocks:i}:{kind:`plain`,text:Er(t),language:`diff`,isCode:!0}}}if(r===`writefile`){let r=pr(t.inputValue);return{...n,Icon:y,title:e.title||`write`,secondaryText:r||void 0,showInputPreview:!1,outputContent:{kind:`plain`,text:Dr(t),language:Y(r),isCode:t.status===`completed`}}}return n}function Rr(e,t){let n=Nr(e,t),r=Yn(e),i=Z(X(t.metadataValue).namespace);if(r===`skill`)return Pr(e,t,n);if(r===`js`&&(i===`mcp__node_repl__`||i===`mcp__node_repl__.js`)){let e=Z(X(t.inputValue).title);return{...n,Icon:v,title:`Browser`,secondaryText:e||void 0,details:[],showInputPreview:!1,outputContent:{kind:`plain`,text:fr($(t)),language:`text`,isCode:!1}}}if(r===`exec_command`||r===`bash`){let e=en(t.inputValue,$(t),Y);return{...n,Icon:v,title:`bash`,secondaryText:e.secondaryText,details:e.details,showInputPreview:!1,outputContent:{kind:`plain`,text:e.outputAnalysis.text,language:e.outputAnalysis.language,isCode:e.outputAnalysis.isCode}}}if(r===`write_stdin`){let e=tn(t.inputValue,$(t),Y);return{...n,Icon:v,title:`bash`,secondaryText:e.secondaryText,details:e.details,showInputPreview:!1,outputContent:{kind:`plain`,text:e.outputAnalysis.text,language:e.outputAnalysis.language,isCode:e.outputAnalysis.isCode}}}if(r===`request_user_input`){let e=nn(t.inputValue,$(t));return{...n,Icon:h,title:`ask`,secondaryText:e.secondaryText,details:e.details,showInputPreview:!1,outputContent:e.outputContent}}if(r===`patch`){let r=J(t.inputValue),i=Dt(r);return{...n,Icon:me,title:ur(e,`patch`),secondaryText:i||void 0,details:[],showInputPreview:!1,outputContent:At(r,$(t),Y)}}if(r===`subagent`){let r=kr(e),i=$(t);return{...n,Icon:p,title:Or(e)||ur(e,`subagent`),secondaryText:void 0,details:[],showInputPreview:!1,outputContent:{kind:`plain`,text:r||i,language:`markdown`,isCode:!1}}}return n}function zr(e,t){let n=Nr(e,t),r=(e.tool||``).toLowerCase(),i=X(t.inputValue),a=pr(t.inputValue);if(r===`read_file_v2`){let e=_r(t.outputValue);return{...n,Icon:x,title:`read`,secondaryText:a||void 0,details:e===`No output captured.`?[{label:`Lines`,value:Z(mr(t.outputValue).totalLinesInFile)}]:[],showInputPreview:!1,outputContent:{kind:`plain`,text:e,language:Y(a),isCode:e!==`No output captured.`}}}if(r===`edit_file_v2`){let e=Q(qn(i.streamingContent));return{...n,Icon:me,title:`edit`,secondaryText:a||void 0,showInputPreview:!1,outputContent:{kind:`plain`,text:e||$(t),language:e?`diff`:`text`,isCode:!!e}}}if(r===`ripgrep_raw_search`){let e=Z(i.pattern),r=[Z(i.path),e].filter(Boolean).join(` · `);return{...n,Icon:C,title:`grep`,secondaryText:r||void 0,details:[],showInputPreview:!1,outputContent:{kind:`plain`,text:$(t),language:`text`,isCode:!1}}}if(r===`glob_file_search`){let e=Z(i.globPattern),r=[Z(i.targetDirectory),e].filter(Boolean).join(` · `);return{...n,Icon:C,title:`glob`,secondaryText:r||void 0,details:[],showInputPreview:!1,outputContent:{kind:`plain`,text:vr(t.outputValue),language:`text`,isCode:!1}}}if(r===`run_terminal_command_v2`){let e=Z(i.command),r=Z(i.commandDescription),a=r?`${r}${e?` (${e})`:``}`:e?`(${e})`:void 0;return{...n,Icon:v,title:`bash`,secondaryText:a,details:[],showInputPreview:!1,outputContent:{kind:`plain`,text:$(t),language:`text`,isCode:!1}}}return{...n,title:ur(e)}}function Br(e,t,n){let r=e.toLowerCase();return r===`opencode`?Ir(t,n):r===`codex`?Rr(t,n):r===`kimi`?Lr(t,n):r===`claudecode`?Fr(t,n):r===`cursor`?zr(t,n):Nr(t,n)}function Vr(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}K`:e.toString()}function Hr(e){if(typeof e==`number`&&e<=0)return`Unknown time`;let t=null;if(typeof e==`number`){let n=e<10**12?e*1e3:e;t=new Date(n)}else if(typeof e==`string`&&e.trim()){let n=Number(e);t=!Number.isNaN(n)&&n>0?new Date(n<10**12?n*1e3:n):new Date(e)}return!t||Number.isNaN(t.getTime())?`Unknown time`:t.toLocaleTimeString(`en-US`,{hour:`2-digit`,minute:`2-digit`,second:`2-digit`,hour12:!0})}function Ur(e){return e===window}function Wr(e,t){let n=[],r=0;for(let i=0;i<e;i+=1){let a=t[i]??Pn,o=r,s=o+a;n.push({start:o,end:s}),r=s+(i===e-1?0:Mn)}return{items:n,totalSize:r}}function Gr(e,t){let n=0,r=e.length;for(;n<r;){let i=Math.floor((n+r)/2),a=e[i];a&&a.end<t?n=i+1:r=i}return n}function Kr(e,t){let n=0,r=e.length;for(;n<r;){let i=Math.floor((n+r)/2),a=e[i];a&&a.start<=t?n=i+1:r=i}return n}function qr(e){let t=e.parentElement;for(;t;){let{overflowY:e}=window.getComputedStyle(t);if(e===`auto`||e===`scroll`||e===`overlay`)return t;t=t.parentElement}return window}function Jr(e){return Ur(e)?window.scrollY:e.scrollTop}function Yr(e){return Ur(e)?window.innerHeight||900:e.clientHeight}function Xr(e,t){if(Ur(t))return e.getBoundingClientRect().top+window.scrollY;let n=t.getBoundingClientRect(),r=e.getBoundingClientRect();return t.scrollTop+r.top-n.top}function Zr(e,t){if(Ur(e)){window.scrollTo({top:t,behavior:`auto`});return}e.scrollTo({top:t,behavior:`auto`})}function Qr({messages:e,toolAnchorIds:t,sessionAgentKey:n,highlightQuery:r,apiRef:i}){let a=e.length>Nn;return(0,j.useEffect)(()=>{a||(i.current=null)},[i,a]),a?(0,F.jsx)($r,{messages:e,toolAnchorIds:t,sessionAgentKey:n,highlightQuery:r,apiRef:i}):(0,F.jsx)(`div`,{className:`flex min-w-0 flex-col gap-8`,children:e.map(({msg:e,blocks:i,index:a})=>(0,F.jsx)(ci,{msg:e,blocks:i,toolAnchorIds:t,formatTokens:Vr,sessionAgentKey:n,highlightQuery:r},`${e.id}:${a}`))})}function $r({messages:e,toolAnchorIds:t,sessionAgentKey:n,highlightQuery:r,apiRef:i}){let a=(0,j.useRef)(null),o=(0,j.useRef)(null),[s,c]=(0,j.useState)([]),[l,u]=(0,j.useState)(null),[d,f]=(0,j.useState)(()=>({scrollTop:0,height:900,listTop:0})),p=(0,j.useRef)(d);(0,j.useEffect)(()=>{p.current=d},[d]);let m=(0,j.useCallback)(()=>{if(typeof window>`u`)return;let e=a.current,t=e?qr(e):window;o.current=t;let n=e?Xr(e,t):0,r={scrollTop:Jr(t),height:Yr(t),listTop:n},i=p.current;Math.abs(i.scrollTop-r.scrollTop)<1&&Math.abs(i.height-r.height)<1&&Math.abs(i.listTop-r.listTop)<1||(p.current=r,f(r))},[]);(0,j.useEffect)(()=>{m();let e=o.current??window,t=0,n=()=>{t||=requestAnimationFrame(()=>{t=0,m()})};e.addEventListener(`scroll`,n,{passive:!0}),window.addEventListener(`resize`,n);let r=window.setInterval(m,100),i=null;return typeof ResizeObserver<`u`&&(i=new ResizeObserver(n),a.current&&i.observe(a.current),Ur(e)||i.observe(e),document.body&&i.observe(document.body)),()=>{t&&cancelAnimationFrame(t),i?.disconnect(),window.clearInterval(r),e.removeEventListener(`scroll`,n),window.removeEventListener(`resize`,n)}},[m]),(0,j.useEffect)(()=>{c([]),u(null),m()},[e,m]);let h=(0,j.useMemo)(()=>Wr(e.length,s),[s,e.length]),g=(0,j.useCallback)((e,t)=>{let n=Math.ceil(t);!Number.isFinite(n)||n<=0||c(t=>{let r=t[e];if(r!=null&&Math.abs(r-n)<=1)return t;let i=[...t];return i[e]=n,i})},[]),_=(0,j.useMemo)(()=>{if(e.length===0)return[];let t=Math.max(0,d.scrollTop-d.listTop),n=t+d.height,r=Math.max(0,Gr(h.items,t)-Fn),i=Math.min(e.length,Kr(h.items,n)+Fn),a=[];for(let e=r;e<i;e+=1){let t=h.items[e];t&&a.push({index:e,start:t.start})}if(l!=null&&l>=0&&l<e.length){let e=h.items[l];e&&!a.some(e=>e.index===l)&&(a.push({index:l,start:e.start}),a.sort((e,t)=>e.start-t.start))}return a},[l,h,e.length,d]),ee=(0,j.useCallback)(e=>{if(typeof window>`u`)return;let t=h.items[e];if(!t)return;u(e);let n=a.current,r=n?qr(n):o.current??window;o.current=r;let i=n?Xr(n,r):0,s=Math.max(0,i+t.start-24);Zr(r,s);let c={scrollTop:s,height:Yr(r),listTop:i};p.current=c,f(c)},[h.items]);return(0,j.useEffect)(()=>(i.current={scrollToIndex:ee},()=>{i.current?.scrollToIndex===ee&&(i.current=null)}),[i,ee]),(0,F.jsx)(`div`,{ref:a,className:`relative min-w-0`,style:{height:Math.max(1,h.totalSize)},children:_.map(({index:i,start:a})=>{let o=e[i];return o?(0,F.jsx)(ei,{index:i,top:a,onMeasure:g,children:(0,F.jsx)(ci,{msg:o.msg,blocks:o.blocks,toolAnchorIds:t,formatTokens:Vr,sessionAgentKey:n,highlightQuery:r})},`${o.msg.id}:${o.index}`):null})})}function ei({index:e,top:t,onMeasure:n,children:r}){let i=(0,j.useRef)(null);return(0,j.useEffect)(()=>{let t=i.current;if(!t)return;let r=()=>n(e,t.getBoundingClientRect().height);if(r(),typeof ResizeObserver>`u`)return;let a=new ResizeObserver(r);return a.observe(t),()=>a.disconnect()},[e,n]),(0,F.jsx)(`div`,{ref:i,className:`absolute left-0 top-0 w-full`,style:{transform:`translateY(${t}px)`},children:r})}function ti({session:e,highlightQuery:t}){let n=(e.slug||``).split(`/`)[0]||M.getDefaultAgentKey()||`claudecode`,r=(0,j.useMemo)(()=>jr(e.messages,n),[e.messages,n]),i=(0,j.useMemo)(()=>gn(r),[r]),{toolAnchorIds:a,anchorMessageIndexes:o,summary:s}=(0,j.useMemo)(()=>ir(i),[i]),c=(0,j.useMemo)(()=>dn(i),[i]),[l,u]=(0,j.useState)(()=>new Set(c.filterIds)),d=(0,j.useMemo)(()=>[...c.filterIds].toSorted().join(`|`),[c.filterIds]),f=(0,j.useMemo)(()=>[...l].toSorted().join(`|`),[l]),p=(0,j.useMemo)(()=>hn(i,l),[i,l]),m=(0,j.useRef)(null),h=(0,j.useMemo)(()=>{let e=new Map;return p.forEach((t,n)=>{e.set(t.index,n)}),e},[p]),g=(0,j.useMemo)(()=>ar(e.file_activity,s),[e.file_activity,s]),_=(0,j.useCallback)(e=>{let t=o.get(e),n=t==null?void 0:h.get(t);sr(e,()=>{n!=null&&m.current?.scrollToIndex(n)})},[h,o]);return(0,j.useEffect)(()=>{u(new Set(c.filterIds))},[d,c.filterIds]),i.length===0?(0,F.jsx)(`div`,{"data-testid":`session-detail`,className:`mx-auto max-w-4xl rounded-sm border border-[var(--console-border)] bg-white p-6 text-sm text-[var(--console-muted)]`,children:`当前会话暂无可展示的消息内容。`}):(0,F.jsxs)(`div`,{"data-testid":`session-detail`,className:`mx-auto w-full max-w-[1440px] space-y-8 px-2 md:px-4 animate-in fade-in slide-in-from-bottom-2 duration-300`,children:[(0,F.jsx)(si,{summary:typeof e.summary_files==`string`?e.summary_files:void 0}),(0,F.jsxs)(`div`,{className:`grid gap-6 lg:grid-cols-[240px_minmax(0,1fr)] xl:grid-cols-[220px_minmax(0,1fr)_320px] lg:items-start`,children:[(0,F.jsx)(ri,{toc:c,fileChangeSummary:g,baseDirectory:e.directory,selectedFilters:l,onToggle:e=>u(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n}),onJumpToAnchor:_}),(0,F.jsx)(`div`,{className:`flex min-w-0 flex-col gap-8`,children:p.length>0?(0,F.jsx)(Qr,{messages:p,toolAnchorIds:a,sessionAgentKey:n,highlightQuery:t,apiRef:m},`${e.id}:${f}`):(0,F.jsx)(`div`,{className:`rounded-sm border border-[var(--console-border)] bg-white p-6 text-sm text-[var(--console-muted)]`,children:`当前筛选条件下暂无可展示的消息内容。`})}),(0,F.jsx)(mt,{session:e,toc:c},e.id)]})]})}var ni=[{id:`user`,label:`User`},{id:`agent_message`,label:`Agent Responses`},{id:`thinking`,label:`Thinking`},{id:`plan`,label:`Plans`},{id:`tools_all`,label:`Tools`}];function ri({toc:e,fileChangeSummary:t,baseDirectory:n,selectedFilters:r,onToggle:i,onJumpToAnchor:a}){let o=r.has(`tools_all`);return(0,F.jsx)(`aside`,{className:`console-scrollbar lg:sticky lg:top-4 lg:max-h-[calc(100dvh-14rem)] lg:overflow-y-auto lg:overscroll-contain`,children:(0,F.jsxs)(`div`,{className:`space-y-4`,children:[(0,F.jsxs)(`div`,{className:`rounded-sm border border-[var(--console-border)] bg-white shadow-[0_1px_2px_rgba(15,23,42,0.04)]`,children:[(0,F.jsxs)(`div`,{className:`flex items-center gap-2 border-b border-[var(--console-border)] px-4 py-3`,children:[(0,F.jsx)(re,{className:`size-3.5 text-[var(--console-accent)]`}),(0,F.jsx)(`span`,{className:`console-mono text-xs font-semibold uppercase tracking-[0.16em] text-[var(--console-text)]`,children:`Session TOC`})]}),(0,F.jsxs)(`div`,{className:`space-y-1 p-3`,children:[ni.filter(({id:t})=>e.counts[t]>0).map(({id:t,label:n})=>(0,F.jsxs)(`label`,{className:`flex cursor-pointer items-start gap-3 rounded-sm px-2 py-2 transition-colors hover:bg-[var(--console-surface-muted)]`,children:[(0,F.jsx)(`input`,{type:`checkbox`,checked:r.has(t),onChange:()=>i(t),className:`mt-0.5 size-3.5 shrink-0 rounded border-[var(--console-border-strong)] accent-[var(--console-accent-strong)]`}),(0,F.jsx)(`span`,{className:`console-mono min-w-0 flex-1 break-all text-xs leading-relaxed text-[var(--console-text)]`,children:n}),(0,F.jsx)(`span`,{className:`console-mono shrink-0 text-[11px] text-[var(--console-muted)]`,children:e.counts[t]})]},t)),e.tools.length>0?(0,F.jsx)(`div`,{className:`space-y-1 border-t border-[var(--console-border)] pt-2`,children:e.tools.map(e=>(0,F.jsxs)(`label`,{className:P(`flex items-start gap-3 rounded-sm px-2 py-2 transition-colors`,o?`cursor-pointer hover:bg-[var(--console-surface-muted)]`:`cursor-not-allowed opacity-50`),children:[(0,F.jsx)(`input`,{type:`checkbox`,checked:o&&r.has(e.id),disabled:!o,onChange:()=>i(e.id),className:`mt-0.5 size-3.5 shrink-0 rounded border-[var(--console-border-strong)] accent-[var(--console-accent-strong)]`}),(0,F.jsx)(`span`,{className:`console-mono min-w-0 flex-1 break-all text-xs leading-relaxed text-[var(--console-muted)]`,children:e.label}),(0,F.jsx)(`span`,{className:`console-mono shrink-0 text-[11px] text-[var(--console-muted)]`,children:e.count})]},e.id))}):null]})]}),(0,F.jsx)(ii,{summary:t,baseDirectory:n,onJumpToAnchor:a})]})})}function ii({summary:e,baseDirectory:t,onJumpToAnchor:n}){let r=[{key:`read`,label:`Read`,Icon:C,items:e.read},{key:`edit`,label:`Edit`,Icon:me,items:e.edit},{key:`write`,label:`Write`,Icon:y,items:e.write},{key:`delete`,label:`Delete`,Icon:w,items:e.delete}].filter(e=>e.items.length>0);return r.length===0?null:(0,F.jsxs)(`div`,{className:`rounded-sm border border-[var(--console-border)] bg-white shadow-[0_1px_2px_rgba(15,23,42,0.04)]`,children:[(0,F.jsxs)(`div`,{className:`flex items-center gap-2 border-b border-[var(--console-border)] px-4 py-3`,children:[(0,F.jsx)(_,{className:`size-3.5 text-[var(--console-accent)]`}),(0,F.jsx)(`span`,{className:`console-mono text-xs font-semibold uppercase tracking-[0.16em] text-[var(--console-text)]`,children:`File Tracker`})]}),(0,F.jsx)(`div`,{className:`space-y-3 p-3`,children:r.map(({key:e,label:r,Icon:i,items:a})=>(0,F.jsx)(ai,{label:r,Icon:i,items:a,baseDirectory:t,onJumpToAnchor:n},e))})]})}function ai({label:e,Icon:t,items:n,baseDirectory:r,onJumpToAnchor:i}){let[a,o]=(0,j.useState)(!1);return(0,F.jsxs)(`div`,{className:`rounded-sm border border-[var(--console-border)] bg-[#fafafa]`,children:[(0,F.jsxs)(`button`,{type:`button`,onClick:()=>o(e=>!e),className:`flex w-full items-center gap-2 px-3 py-2 text-left transition-colors hover:bg-[var(--console-surface-muted)]`,children:[(0,F.jsx)(t,{className:`size-3.5 shrink-0 text-[var(--console-accent)]`}),(0,F.jsx)(`span`,{className:`console-mono min-w-0 flex-1 text-[11px] font-semibold uppercase tracking-[0.12em] text-[var(--console-muted)]`,children:e}),(0,F.jsx)(`span`,{className:`console-mono shrink-0 text-[10px] text-[var(--console-muted)]`,children:n.length}),a?(0,F.jsx)(pe,{className:`size-3.5 shrink-0 text-[var(--console-muted)]`}):(0,F.jsx)(g,{className:`size-3.5 shrink-0 text-[var(--console-muted)]`})]}),a?(0,F.jsx)(`div`,{className:`space-y-1 border-t border-[var(--console-border)] p-2`,children:n.map(e=>(0,F.jsx)(oi,{item:e,baseDirectory:r,onJumpToAnchor:i},`${e.path}:${e.latestAnchorId||e.latestTime}`))}):null]})}function oi({item:e,baseDirectory:t,onJumpToAnchor:n}){let[r,i]=(0,j.useState)(0);function a(t){let r=e.anchors.length;if(r===0)return;let a=(t%r+r)%r;i(a);let o=e.anchors[a];o&&n(o.anchorId)}return(0,F.jsxs)(`div`,{className:`flex items-start gap-2 rounded-sm px-2 py-2 transition-colors hover:bg-[var(--console-surface-muted)]`,children:[(0,F.jsx)(`button`,{type:`button`,title:e.path,onClick:()=>a(r),className:`min-w-0 flex-1 text-left`,children:(0,F.jsx)(`span`,{className:`console-mono block break-all text-xs text-[var(--console-text)]`,children:or(e.path,t)})}),e.anchors.length>1?(0,F.jsxs)(`div`,{className:`flex shrink-0 items-center gap-1`,children:[(0,F.jsx)(`button`,{type:`button`,"aria-label":`Previous ${e.path}`,onClick:()=>a(r-1),className:`rounded-sm border border-[var(--console-border)] p-1 text-[var(--console-muted)] transition-colors hover:bg-white`,children:(0,F.jsx)(pe,{className:`size-3`})}),(0,F.jsxs)(`span`,{className:`console-mono text-[10px] text-[var(--console-muted)]`,children:[r+1,`/`,e.anchors.length]}),(0,F.jsx)(`button`,{type:`button`,"aria-label":`Next ${e.path}`,onClick:()=>a(r+1),className:`rounded-sm border border-[var(--console-border)] p-1 text-[var(--console-muted)] transition-colors hover:bg-white`,children:(0,F.jsx)(g,{className:`size-3`})})]}):(0,F.jsx)(`button`,{type:`button`,title:`Jump to tool call`,onClick:()=>a(0),className:`console-mono shrink-0 text-[10px] text-[var(--console-muted)]`,children:e.count})]})}function si({summary:e,defaultExpanded:t=!1}){let n=typeof e==`string`?e.trim():``,[r,i]=(0,j.useState)(t);return n?(0,F.jsxs)(`section`,{className:`rounded-sm border border-[var(--console-border)] bg-white shadow-[0_1px_2px_rgba(15,23,42,0.04)]`,children:[(0,F.jsxs)(`button`,{type:`button`,className:`flex w-full items-center justify-between gap-3 px-4 py-3 text-left`,onClick:()=>i(e=>!e),children:[(0,F.jsxs)(`span`,{className:`console-mono inline-flex items-center gap-2 text-xs font-semibold uppercase tracking-[0.16em] text-[var(--console-text)]`,children:[(0,F.jsx)(_,{className:`size-3.5 text-[var(--console-accent)]`}),`Session Summary`]}),r?(0,F.jsx)(pe,{className:`size-3.5 text-[var(--console-muted)]`}):(0,F.jsx)(g,{className:`size-3.5 text-[var(--console-muted)]`})]}),r?(0,F.jsx)(`div`,{className:`border-t border-[var(--console-border)] px-4 py-4`,children:(0,F.jsx)(`div`,{className:`console-markdown text-sm leading-relaxed text-[var(--console-text)]`,children:(0,F.jsx)(vt,{text:n})})}):null]}):null}function ci({msg:e,blocks:t,toolAnchorIds:n,formatTokens:r,sessionAgentKey:i,highlightQuery:a}){let o=e.role===`user`,s=K(e,i),c=()=>{let e=i.toLowerCase(),t=M.getAgentName(e),n=M.agents[e]?.icon;return(0,F.jsx)(F.Fragment,{children:n?(0,F.jsx)(`img`,{src:n,alt:t,className:`size-4 rounded-sm object-cover`}):(0,F.jsx)(p,{className:`size-4 text-[var(--console-muted)]`})})},l=e.mode?e.mode.toUpperCase():null,u=e.model||null,d=Ar(e),f=Hr(e.time_created);return(0,F.jsx)(`article`,{className:`w-full border-l-2 border-[var(--console-thread)] pl-4 pr-3 md:pr-5`,children:(0,F.jsxs)(`div`,{className:`flex gap-4`,children:[(0,F.jsx)(`div`,{className:`shrink-0 pt-1`,children:(0,F.jsx)(`div`,{className:`flex size-8 items-center justify-center rounded-sm border border-[var(--console-border)] bg-[var(--console-surface-muted)]`,children:o?(0,F.jsx)(ae,{className:`size-4 text-[var(--console-muted)]`}):c()})}),(0,F.jsxs)(`div`,{className:`min-w-0 flex-1 space-y-3`,children:[(0,F.jsxs)(`div`,{className:`flex items-baseline gap-3`,children:[(0,F.jsx)(`span`,{className:`console-mono text-sm font-bold tracking-wide text-[var(--console-text)]`,children:d}),(0,F.jsx)(`time`,{className:`console-mono text-xs text-[var(--console-muted)]`,children:f}),l&&(0,F.jsx)(`span`,{className:`console-mono rounded-sm border border-[var(--console-border)] bg-[var(--console-surface-muted)] px-1.5 py-0.5 text-[10px] text-[var(--console-muted)]`,children:l}),u&&(0,F.jsx)(`span`,{className:`console-mono rounded-sm border border-[var(--console-border)] bg-[var(--console-surface-muted)] px-1.5 py-0.5 text-[10px] text-[var(--console-muted)]`,children:u})]}),s?(0,F.jsx)(li,{}):t.map((e,t)=>e.type===`reasoning`?(0,F.jsx)(ui,{parts:e.parts,highlightQuery:a},t):e.type===`plan`?(0,F.jsx)(fi,{parts:e.parts,highlightQuery:a},t):e.type===`tool`?(0,F.jsx)(di,{parts:e.parts,toolAnchorIds:n,sessionAgentKey:i,highlightQuery:a},t):(0,F.jsx)(`div`,{className:`rounded-sm border border-[var(--console-border)] bg-white p-4 shadow-[0_1px_2px_rgba(15,23,42,0.04)]`,children:(0,F.jsx)(`div`,{className:`console-markdown text-sm leading-relaxed text-[var(--console-text)]`,children:e.parts.map((e,t)=>(0,F.jsx)(zn,{text:G(e.text),highlightQuery:a},t))})},t)),!o&&(e.tokens||e.cost)&&(0,F.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[e.tokens?.input?(0,F.jsxs)(`span`,{className:`console-mono rounded-sm border border-[var(--console-border)] bg-[var(--console-surface-muted)] px-2 py-1 text-[11px] text-[var(--console-muted)]`,children:[`INPUT `,r(e.tokens.input)]}):null,e.tokens?.output?(0,F.jsxs)(`span`,{className:`console-mono rounded-sm border border-[var(--console-border)] bg-[var(--console-surface-muted)] px-2 py-1 text-[11px] text-[var(--console-muted)]`,children:[`OUTPUT `,r(e.tokens.output)]}):null,e.tokens?.reasoning?(0,F.jsxs)(`span`,{className:`console-mono rounded-sm border border-[var(--console-border)] bg-[var(--console-surface-muted)] px-2 py-1 text-[11px] text-[var(--console-muted)]`,children:[`REASONING `,r(e.tokens.reasoning)]}):null,e.cost?(0,F.jsxs)(`span`,{className:`console-mono rounded-sm border border-[var(--console-border)] bg-[var(--console-surface-muted)] px-2 py-1 text-[11px] text-[var(--console-muted)]`,children:[e.cost_source===`estimated`?`EST COST`:`COST`,` $`,e.cost.toFixed(4)]}):null]})]})]})})}function li(){return(0,F.jsx)(`div`,{className:`space-y-2`,children:(0,F.jsx)(`div`,{className:`flex flex-wrap items-start gap-2`,children:(0,F.jsx)(`div`,{className:`w-full rounded-sm border border-[var(--console-border-strong)] bg-white px-3 py-2 text-left shadow-[2px_2px_0_0_rgba(15,23,42,0.05)] md:w-[560px]`,children:(0,F.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,F.jsx)(ce,{className:`mt-0.5 size-3.5 shrink-0 text-[var(--console-accent)]`}),(0,F.jsx)(`span`,{className:`min-w-0 flex-1`,children:(0,F.jsx)(`span`,{className:`console-mono block text-xs font-semibold text-[var(--console-text)]`,children:`abort`})})]})})})})}function ui({parts:e,highlightQuery:t}){let[n,r]=(0,j.useState)(!1),i=e.map(e=>G(e.text)).filter(Boolean).join(`
33
+
34
+ `);return(0,F.jsxs)(`div`,{className:`overflow-hidden rounded-sm border border-[var(--console-thinking-border)] bg-[var(--console-thinking-bg)]`,children:[(0,F.jsxs)(`div`,{className:`flex cursor-pointer items-center justify-between bg-[var(--console-surface-muted)] px-3 py-2`,onClick:()=>r(!n),children:[(0,F.jsxs)(`span`,{className:`console-mono flex items-center gap-2 text-xs font-medium text-[var(--console-muted)]`,children:[(0,F.jsx)(b,{className:`size-3.5`}),`Thinking`]}),(0,F.jsx)(`span`,{className:`text-[var(--console-muted)]`,children:n?(0,F.jsx)(pe,{className:`w-4 h-4`}):(0,F.jsx)(g,{className:`w-4 h-4`})})]}),n&&(0,F.jsx)(`div`,{className:`border-t border-dashed border-[var(--console-thinking-border)] px-4 py-3`,children:(0,F.jsx)(`div`,{className:`console-mono whitespace-pre-wrap text-xs leading-relaxed text-[var(--console-muted)]`,children:Rn(i,t)})})]})}function di({parts:e,toolAnchorIds:t,sessionAgentKey:n,highlightQuery:r}){return(0,F.jsx)(`div`,{className:`space-y-2`,children:(0,F.jsx)(`div`,{className:`space-y-2`,children:e.map((e,i)=>(0,F.jsx)(mi,{tool:e,anchorId:t.get(e),sessionAgentKey:n,highlightQuery:r},i))})})}function fi({parts:e,highlightQuery:t}){return(0,F.jsx)(`div`,{className:`space-y-2`,children:e.map((e,n)=>(0,F.jsx)(pi,{part:e,highlightQuery:t},n))})}function pi({part:e,highlightQuery:t}){let[n,r]=(0,j.useState)(!1),i=Mt(e),a=i.approvalStatus===`fail`?jn.error:jn.completed,o=a.icon;return(0,F.jsxs)(`div`,{className:`space-y-2`,children:[(0,F.jsxs)(`div`,{className:`flex flex-wrap items-start gap-2`,children:[(0,F.jsx)(`div`,{className:`w-full md:w-[560px] rounded-sm border border-[var(--console-border-strong)] bg-white px-3 py-2 text-left shadow-[2px_2px_0_0_rgba(15,23,42,0.05)] ${i.expandable?`transition-colors hover:bg-[var(--console-surface-muted)]`:``}`,children:i.expandable?(0,F.jsxs)(`button`,{type:`button`,className:`flex w-full items-start gap-2 text-left`,onClick:()=>r(!n),children:[(0,F.jsx)(l,{className:`mt-0.5 size-3.5 shrink-0 text-[var(--console-accent)]`}),(0,F.jsx)(`span`,{className:`min-w-0 flex-1`,children:(0,F.jsx)(`span`,{className:`console-mono block text-xs font-semibold text-[var(--console-text)]`,children:i.title})}),(0,F.jsx)(`span`,{className:`mt-0.5 shrink-0 text-[var(--console-muted)]`,children:n?(0,F.jsx)(pe,{className:`size-3.5`}):(0,F.jsx)(g,{className:`size-3.5`})})]}):(0,F.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,F.jsx)(l,{className:`mt-0.5 size-3.5 shrink-0 text-[var(--console-accent)]`}),(0,F.jsx)(`span`,{className:`min-w-0 flex-1`,children:(0,F.jsx)(`span`,{className:`console-mono block text-xs font-semibold text-[var(--console-text)]`,children:i.title})})]})}),(0,F.jsxs)(`span`,{className:`console-mono inline-flex items-center gap-1 rounded-sm border px-2 py-0.5 text-[10px] font-bold uppercase tracking-wider ${a.className}`,children:[(0,F.jsx)(o,{className:`size-3`}),a.label]})]}),i.expandable&&n?(0,F.jsxs)(`div`,{className:`overflow-hidden rounded-sm border border-[var(--console-border)] bg-white shadow-[0_1px_2px_rgba(15,23,42,0.04)]`,children:[(0,F.jsx)(`div`,{className:`border-b border-[var(--console-border)] bg-[var(--console-surface-muted)] px-3 py-1.5`,children:(0,F.jsx)(`span`,{className:`console-mono text-xs text-[var(--console-muted)]`,children:i.contentLabel})}),(0,F.jsx)(`div`,{className:`p-4`,children:(0,F.jsx)(`div`,{className:`console-markdown text-sm leading-relaxed text-[var(--console-text)]`,children:(0,F.jsx)(zn,{text:i.contentMarkdown,highlightQuery:t})})})]}):null]})}function mi({tool:e,anchorId:t,sessionAgentKey:n,highlightQuery:r}){let[i,a]=(0,j.useState)(!1),o=Mr(e),s=Br(n,e,o),c=jn[o.status],l=c.icon,u=s.Icon;return(0,F.jsxs)(`div`,{id:t,className:`scroll-mt-6 space-y-2`,children:[(0,F.jsxs)(`div`,{className:`flex flex-wrap items-start gap-2`,children:[(0,F.jsx)(`div`,{className:`w-full md:w-[560px] rounded-sm border border-[var(--console-border-strong)] bg-white px-3 py-2 text-left shadow-[2px_2px_0_0_rgba(15,23,42,0.05)] ${s.expandable?`transition-colors hover:bg-[var(--console-surface-muted)]`:``}`,children:s.expandable?(0,F.jsxs)(`button`,{type:`button`,className:`flex w-full items-start gap-2 text-left`,onClick:()=>a(!i),children:[(0,F.jsx)(u,{className:`mt-0.5 size-3.5 shrink-0 text-[var(--console-accent)]`}),(0,F.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,F.jsx)(`span`,{className:`console-mono block text-xs font-semibold text-[var(--console-text)]`,children:s.title}),s.secondaryText?(0,F.jsx)(`span`,{className:`console-mono mt-0.5 block whitespace-pre-wrap break-words text-xs leading-relaxed text-[var(--console-muted)]`,children:Rn(s.secondaryText,r)}):null]}),(0,F.jsx)(`span`,{className:`mt-0.5 shrink-0 text-[var(--console-muted)]`,children:i?(0,F.jsx)(pe,{className:`size-3.5`}):(0,F.jsx)(g,{className:`size-3.5`})})]}):(0,F.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,F.jsx)(u,{className:`mt-0.5 size-3.5 shrink-0 text-[var(--console-accent)]`}),(0,F.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,F.jsx)(`span`,{className:`console-mono block text-xs font-semibold text-[var(--console-text)]`,children:s.title}),s.secondaryText?(0,F.jsx)(`span`,{className:`console-mono mt-0.5 block whitespace-pre-wrap break-words text-xs leading-relaxed text-[var(--console-muted)]`,children:Rn(s.secondaryText,r)}):null]})]})}),(0,F.jsxs)(`span`,{className:`console-mono inline-flex items-center gap-1 rounded-sm border px-2 py-0.5 text-[10px] font-bold uppercase tracking-wider ${c.className}`,children:[(0,F.jsx)(l,{className:`size-3 ${o.status===`running`?`animate-spin`:``}`}),c.label]})]}),s.expandable&&i?(0,F.jsxs)(`div`,{className:`overflow-hidden rounded-sm border border-[var(--console-border)] bg-white shadow-[0_1px_2px_rgba(15,23,42,0.04)]`,children:[(0,F.jsx)(`div`,{className:`border-b border-[var(--console-border)] bg-[var(--console-surface-muted)] px-3 py-1.5`,children:(0,F.jsx)(`span`,{className:`console-mono text-xs text-[var(--console-muted)]`,children:`Output`})}),(0,F.jsxs)(`div`,{className:`space-y-3 p-3`,children:[s.details.length>0?(0,F.jsx)(`div`,{className:`rounded-sm border border-[var(--console-border)] bg-[#fafafa] px-3 py-2`,children:(0,F.jsx)(`div`,{className:`space-y-2`,children:s.details.map(e=>(0,F.jsxs)(`div`,{className:`flex flex-col gap-1 md:flex-row md:items-start md:gap-3`,children:[(0,F.jsx)(`span`,{className:`console-mono shrink-0 text-[11px] font-semibold uppercase tracking-wide text-[var(--console-muted)] md:w-24`,children:e.label}),(0,F.jsx)(`span`,{className:`console-mono whitespace-pre-wrap break-all text-xs leading-relaxed text-[var(--console-text)]`,children:Rn(e.value,r)})]},`${e.label}:${e.value}`))})}):null,(0,F.jsx)(An,{outputContent:s.outputContent})]}),s.showInputPreview?(0,F.jsxs)(`div`,{className:`border-t border-[var(--console-border)] bg-[#fafafa] px-3 py-2`,children:[(0,F.jsx)(`span`,{className:`console-mono text-[11px] text-[var(--console-muted)]`,children:`Input Preview`}),(0,F.jsx)(`pre`,{className:`console-mono mt-1 max-h-[200px] overflow-x-auto whitespace-pre-wrap break-all text-xs leading-relaxed text-[var(--console-muted)]`,children:Rn(o.inputText||`{}`,r)})]}):null]}):null]})}var hi=[{id:`1`,roleWidth:`w-14`,timeWidth:`w-20`,bodyWidths:[`w-full`,`w-10/12`,`w-7/12`]},{id:`2`,roleWidth:`w-16`,timeWidth:`w-24`,bodyWidths:[`w-9/12`,`w-7/12`]},{id:`3`,roleWidth:`w-14`,timeWidth:`w-16`,bodyWidths:[`w-full`,`w-11/12`,`w-8/12`,`w-5/12`]},{id:`4`,roleWidth:`w-16`,timeWidth:`w-20`,bodyWidths:[`w-10/12`,`w-8/12`]},{id:`5`,roleWidth:`w-14`,timeWidth:`w-24`,bodyWidths:[`w-full`,`w-10/12`,`w-9/12`]}];function gi({className:e}){return(0,F.jsx)(`div`,{className:`rounded-sm bg-[var(--console-border)] ${e}`})}function _i(){return(0,F.jsxs)(`div`,{className:`mx-auto flex min-h-full w-full max-w-5xl flex-col gap-8 px-2 md:px-4`,children:[(0,F.jsx)(`div`,{className:`flex flex-1 flex-col gap-8`,children:hi.map(e=>(0,F.jsx)(`article`,{className:`w-full border-l-2 border-[var(--console-thread)] pl-4 pr-3 md:pr-5`,children:(0,F.jsxs)(`div`,{className:`flex gap-4`,children:[(0,F.jsx)(`div`,{className:`shrink-0 pt-1`,children:(0,F.jsx)(`div`,{className:`flex size-8 items-center justify-center rounded-sm border border-[var(--console-border)] bg-[var(--console-surface-muted)]`,children:(0,F.jsx)(`div`,{className:`size-3.5 rounded-sm bg-[var(--console-border-strong)] animate-pulse`})})}),(0,F.jsxs)(`div`,{className:`min-w-0 flex-1 space-y-3`,children:[(0,F.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,F.jsx)(gi,{className:`${e.roleWidth} h-3 animate-pulse`}),(0,F.jsx)(gi,{className:`${e.timeWidth} h-2.5 animate-pulse`})]}),(0,F.jsx)(`div`,{className:`rounded-sm border border-[var(--console-border)] bg-white p-4 shadow-[0_1px_2px_rgba(15,23,42,0.04)]`,children:(0,F.jsx)(`div`,{className:`space-y-2`,children:e.bodyWidths.map(t=>(0,F.jsx)(gi,{className:`${t} h-3 animate-pulse`},`${e.id}-${t}`))})})]})]})},e.id))}),(0,F.jsx)(`div`,{className:`min-h-24 flex-1 rounded-sm border border-[var(--console-border)] bg-white/60 animate-pulse`})]})}function vi({active:e,onToggle:t,className:n=``}){return(0,F.jsx)(`button`,{type:`button`,onClick:e=>{e.preventDefault(),e.stopPropagation(),t()},"aria-label":e?`取消收藏会话`:`收藏会话`,title:e?`取消收藏`:`收藏`,className:`inline-flex size-6 shrink-0 items-center justify-center rounded-sm border transition-colors ${n} ${e?`border-[var(--console-border)] bg-[var(--console-surface-muted)] text-[var(--console-text)]`:`border-transparent text-[var(--console-muted)] opacity-70 hover:border-[var(--console-border)] hover:bg-[var(--console-surface-muted)] hover:text-[var(--console-text)] hover:opacity-100`}`,children:(0,F.jsx)(fe,{className:`size-3`,strokeWidth:1.8,fill:e?`currentColor`:`none`})})}function yi(e){return e.toLocaleString(`en-US`)}function bi(e){return e===0?`$0.00`:e<.01?`$${e.toFixed(4)}`:`$${e.toFixed(2)}`}function xi(e){if(e===`recorded`)return`recorded`;if(e===`estimated`)return`estimated`}function Si(e){return e.total_tokens??e.total_input_tokens+e.total_output_tokens}function Ci(e){if(!e)return`unknown`;let t=Date.now()-e;if(Number.isNaN(t)||t<0)return`just now`;let 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 wi({label:e,value:t,hint:n}){return(0,F.jsxs)(`div`,{className:`rounded-sm border border-[var(--console-border)] bg-white p-4`,children:[(0,F.jsx)(`p`,{className:`console-mono text-[11px] uppercase tracking-wider text-[var(--console-muted)]`,children:e}),(0,F.jsx)(`p`,{className:`console-mono mt-2 text-xl font-semibold text-[var(--console-text)]`,children:t}),n?(0,F.jsx)(`p`,{className:`mt-1 text-xs text-[var(--console-muted)]`,children:n}):null]})}function Ti({label:e,value:t}){return(0,F.jsxs)(`div`,{className:`rounded-sm border border-[var(--console-border)] bg-[var(--console-surface-muted)] p-3`,children:[(0,F.jsx)(`p`,{className:`console-mono text-[11px] uppercase tracking-wider text-[var(--console-muted)]`,children:e}),(0,F.jsx)(`p`,{className:`console-mono mt-2 break-all text-sm leading-6 text-[var(--console-text)]`,children:t})]})}function Ei({code:e,title:t,description:n,aside:r,iconSrc:i,iconAlt:a}){return(0,F.jsx)(`div`,{className:`rounded-sm border border-[var(--console-border-strong)] bg-white p-5 md:p-6`,children:(0,F.jsxs)(`div`,{className:`flex flex-col gap-5 md:flex-row md:items-start md:justify-between`,children:[(0,F.jsxs)(`div`,{className:`max-w-2xl`,children:[(0,F.jsx)(`span`,{className:`console-mono inline-flex rounded-sm border border-[var(--console-border)] bg-[var(--console-surface-muted)] px-2 py-1 text-[11px] font-semibold uppercase tracking-[0.16em] text-[var(--console-muted)]`,children:e}),(0,F.jsxs)(`div`,{className:`mt-4 flex items-start gap-3`,children:[i?(0,F.jsx)(`img`,{src:i,alt:a||``,className:`mt-1 size-8 shrink-0 object-contain`}):null,(0,F.jsx)(`h2`,{className:`console-mono text-2xl leading-tight font-semibold tracking-tight text-[var(--console-text)] md:text-[2rem]`,children:t})]}),(0,F.jsx)(`p`,{className:`mt-3 max-w-[42rem] text-sm leading-7 text-[var(--console-muted)]`,children:n})]}),(0,F.jsxs)(`div`,{className:`min-w-0 rounded-sm border border-dashed border-[var(--console-border)] bg-[var(--console-surface-muted)] px-4 py-3 md:max-w-xs`,children:[(0,F.jsx)(`p`,{className:`console-mono text-[11px] uppercase tracking-[0.16em] text-[var(--console-muted)]`,children:`STATUS NOTE`}),(0,F.jsx)(`p`,{className:`mt-2 text-sm leading-6 text-[var(--console-text)]`,children:r})]})]})})}function Di({agentItems:e}){return(0,F.jsxs)(`div`,{className:`rounded-sm border border-[var(--console-border)] bg-white p-4`,children:[(0,F.jsxs)(`div`,{className:`mb-3 flex items-center justify-between gap-3`,children:[(0,F.jsx)(`h3`,{className:`console-mono text-xs font-bold uppercase text-[var(--console-text)]`,children:`Known Agents`}),(0,F.jsxs)(`span`,{className:`console-mono text-[11px] text-[var(--console-muted)]`,children:[e.length,` items`]})]}),(0,F.jsx)(`ul`,{className:`grid gap-2 sm:grid-cols-2`,children:e.map(e=>(0,F.jsx)(`li`,{children:(0,F.jsxs)(d,{to:`/${e.key}`,className:`flex min-h-11 items-center gap-2 rounded-sm border border-transparent px-3 py-2 transition-colors duration-200 hover:border-[var(--console-border)] hover:bg-[var(--console-surface-muted)] focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-[var(--console-accent)]`,children:[(0,F.jsx)(`img`,{src:e.icon,alt:e.name,className:`size-4 object-contain`}),(0,F.jsx)(`span`,{className:`console-mono flex-1 text-xs text-[var(--console-text)]`,children:e.name}),(0,F.jsx)(`span`,{className:`console-mono text-[11px] text-[var(--console-muted)]`,children:e.count})]})},e.key))})]})}function Oi({sessions:e,isBookmarked:t,onToggleBookmark:n}){return e.length===0?(0,F.jsx)(`div`,{className:`rounded-sm border border-[var(--console-border)] bg-white p-4 text-sm text-[var(--console-muted)]`,children:`No sessions yet`}):(0,F.jsxs)(`div`,{className:`rounded-sm border border-[var(--console-border)] bg-white p-4`,children:[(0,F.jsxs)(`div`,{className:`mb-3 flex items-center justify-between`,children:[(0,F.jsx)(`h3`,{className:`console-mono text-xs font-bold uppercase text-[var(--console-text)]`,children:`Recent Sessions`}),(0,F.jsxs)(`span`,{className:`console-mono text-[11px] text-[var(--console-muted)]`,children:[e.length,` items`]})]}),(0,F.jsx)(`ul`,{className:`space-y-2`,children:e.map(e=>{let r=t(e.agentKey,e.id);return(0,F.jsx)(`li`,{children:(0,F.jsxs)(`div`,{className:`flex items-start gap-2 rounded-sm border border-transparent px-2 py-1.5 transition-colors hover:border-[var(--console-border)] hover:bg-[var(--console-surface-muted)]`,children:[(0,F.jsxs)(d,{to:`/${e.fullPath}`,className:`min-w-0 flex-1`,children:[(0,F.jsx)(`p`,{className:`line-clamp-1 text-sm text-[var(--console-text)]`,children:e.title}),(0,F.jsxs)(`p`,{className:`console-mono mt-0.5 text-[11px] text-[var(--console-muted)]`,children:[`/`,e.fullPath,` ·`,` `,Ci(e.time_updated||e.time_created)]}),(0,F.jsx)(Je,{tags:e.smart_tags,className:`mt-1.5`})]}),(0,F.jsx)(vi,{active:r,onToggle:()=>n(e)})]})},e.id)})})]})}function ki({type:e,sessions:t,agentItems:n,activeAgentKey:r,attemptedAgentKey:i,attemptedSessionSlug:a,isBookmarked:o,onToggleBookmark:s}){let c=t.toSorted((e,t)=>(t.time_updated||t.time_created||0)-(e.time_updated||e.time_created||0)),l=c.slice(0,5),u=t.reduce((e,t)=>e+t.stats.message_count,0),f=t.reduce((e,t)=>e+Si(t.stats),0),p=t.reduce((e,t)=>e+t.stats.total_cost,0),m=p>0?t.some(e=>e.stats.cost_source===`estimated`)?`estimated`:`recorded`:void 0,h=c[0]?.time_updated||c[0]?.time_created;if(e===`missing-agent`){let e=`/${i||`unknown`}${a?`/${a}`:``}`;return(0,F.jsxs)(`div`,{className:`mx-auto max-w-4xl space-y-4`,children:[(0,F.jsx)(Ei,{code:`404 / AGENT`,title:`This agent isn't on the roster.`,description:`The path you requested is valid in shape, but there is no matching agent in the current registry. It may not be connected yet, or its name may not match what the system recognizes.`,aside:`Choose one of the available agents to continue.`}),(0,F.jsxs)(`div`,{className:`grid gap-3 md:grid-cols-3`,children:[(0,F.jsx)(Ti,{label:`Requested Agent`,value:i||`unknown`}),(0,F.jsx)(Ti,{label:`Requested Path`,value:e}),a?(0,F.jsx)(Ti,{label:`Requested Session`,value:a}):null]}),(0,F.jsx)(Di,{agentItems:n})]})}if(e===`missing-session`){let e=r||M.getDefaultAgentKey()||`claudecode`,t=M.agents[e],n=t?.name||e,i=t?.icon,c=a||`unknown-session`;return(0,F.jsxs)(`div`,{className:`mx-auto max-w-4xl space-y-4`,children:[(0,F.jsx)(Ei,{code:`404 / SESSION`,title:`This session isn't in the index.`,description:`${n} is available, but the session you're looking for does not exist in the current index. The slug may be incorrect, or the record may never have been part of this dataset.`,aside:`We checked the current path, but nothing matched. The session list on the left is still available.`,iconSrc:i,iconAlt:n}),(0,F.jsxs)(`div`,{className:`grid gap-3 md:grid-cols-2`,children:[(0,F.jsxs)(`div`,{className:`rounded-sm border border-[var(--console-border)] bg-[var(--console-surface-muted)] p-3`,children:[(0,F.jsx)(`p`,{className:`console-mono text-[11px] uppercase tracking-wider text-[var(--console-muted)]`,children:`Agent`}),(0,F.jsxs)(`div`,{className:`mt-2 flex items-center gap-2`,children:[i?(0,F.jsx)(`img`,{src:i,alt:n,className:`size-4 shrink-0 object-contain`}):null,(0,F.jsx)(`p`,{className:`console-mono break-all text-sm leading-6 text-[var(--console-text)]`,children:n})]})]}),(0,F.jsx)(Ti,{label:`Session`,value:c})]}),(0,F.jsx)(Oi,{sessions:l,isBookmarked:o,onToggleBookmark:s})]})}if(e===`global`)return(0,F.jsxs)(`div`,{className:`mx-auto max-w-4xl space-y-4`,children:[(0,F.jsxs)(`div`,{className:`grid gap-3 md:grid-cols-3`,children:[(0,F.jsx)(wi,{label:`Total Sessions`,value:yi(t.length)}),(0,F.jsx)(wi,{label:`Total Messages`,value:yi(u)}),(0,F.jsx)(wi,{label:`Latest Activity`,value:Ci(h),hint:h?new Date(h).toLocaleString(`zh-CN`):void 0})]}),(0,F.jsxs)(`div`,{className:`rounded-sm border border-[var(--console-border)] bg-white p-4`,children:[(0,F.jsx)(`h3`,{className:`console-mono mb-3 text-xs font-bold uppercase text-[var(--console-text)]`,children:`Agents`}),(0,F.jsx)(`ul`,{className:`grid gap-2 sm:grid-cols-2`,children:n.map(e=>(0,F.jsx)(`li`,{children:(0,F.jsxs)(d,{to:`/${e.key}`,className:`flex items-center gap-2 rounded-sm border border-transparent px-2 py-1.5 transition-colors hover:border-[var(--console-border)] hover:bg-[var(--console-surface-muted)]`,children:[(0,F.jsx)(`img`,{src:e.icon,alt:e.name,className:`size-4 object-contain`}),(0,F.jsx)(`span`,{className:`console-mono flex-1 text-xs text-[var(--console-text)]`,children:e.name}),(0,F.jsx)(`span`,{className:`console-mono text-[11px] text-[var(--console-muted)]`,children:e.count})]})},e.key))})]}),(0,F.jsx)(Oi,{sessions:l,isBookmarked:o,onToggleBookmark:s})]});let g=r?M.agents[r]:null,_=g?g.name:`Unknown Agent`;return(0,F.jsxs)(`div`,{className:`mx-auto max-w-4xl space-y-4`,children:[(0,F.jsx)(`div`,{className:`rounded-sm border border-[var(--console-border)] bg-white p-4`,children:(0,F.jsxs)(`div`,{className:`flex items-center gap-3`,children:[g?(0,F.jsx)(`img`,{src:g.icon,alt:_,className:`size-6 object-contain`}):null,(0,F.jsxs)(`div`,{children:[(0,F.jsx)(`h3`,{className:`console-mono text-sm font-semibold text-[var(--console-text)]`,children:_}),(0,F.jsx)(`p`,{className:`console-mono text-xs text-[var(--console-muted)]`,children:`Select a session from the left to view details`})]})]})}),(0,F.jsxs)(`div`,{className:`grid gap-3 md:grid-cols-4`,children:[(0,F.jsx)(wi,{label:`Sessions`,value:yi(t.length)}),(0,F.jsx)(wi,{label:`Messages`,value:yi(u)}),(0,F.jsx)(wi,{label:`Tokens`,value:yi(f)}),(0,F.jsx)(wi,{label:`Total Cost`,value:bi(p),hint:xi(m)})]}),(0,F.jsx)(Oi,{sessions:l,isBookmarked:o,onToggleBookmark:s})]})}var Ai=`codesesh:bookmarks:v1`;function ji(e){return typeof e==`object`&&!!e}function Mi(e){return ji(e)?typeof e.message_count==`number`&&typeof e.total_input_tokens==`number`&&typeof e.total_output_tokens==`number`&&typeof e.total_cost==`number`&&(e.total_tokens==null||typeof e.total_tokens==`number`):!1}function Ni(e){return ji(e)?typeof e.sessionId==`string`&&typeof e.agentKey==`string`&&typeof e.fullPath==`string`&&typeof e.title==`string`&&typeof e.directory==`string`&&typeof e.time_created==`number`&&(e.time_updated==null||typeof e.time_updated==`number`)&&(e.bookmarked_at==null||typeof e.bookmarked_at==`number`)&&Mi(e.stats):!1}function Pi(e,t){return`${e}:${t}`}function Fi(e,t){return{sessionId:e.id,agentKey:t,fullPath:e.slug,title:e.title,directory:e.directory,time_created:e.time_created,time_updated:e.time_updated,stats:e.stats,bookmarked_at:Date.now()}}function Ii(){if(typeof window>`u`)return[];try{let e=window.localStorage.getItem(Ai);if(!e)return[];let t=JSON.parse(e);return Array.isArray(t)?t.filter(Ni).toSorted(Ri):[]}catch{return[]}}function Li(){typeof window>`u`||window.localStorage.removeItem(Ai)}function Ri(e,t){let n=e.time_updated??e.time_created;return(t.time_updated??t.time_created)-n}function zi(e,t){if(e.length===0||t.length===0)return e;let n=new Map(t.map(e=>{let t=Fi(e,e.slug.split(`/`)[0]?.toLowerCase()??`unknown`);return[Pi(t.agentKey,t.sessionId),t]})),r=!1,i=e.map(e=>{let t=n.get(Pi(e.agentKey,e.sessionId));return!t||t.fullPath===e.fullPath&&t.title===e.title&&t.directory===e.directory&&t.time_created===e.time_created&&t.time_updated===e.time_updated&&t.stats.message_count===e.stats.message_count&&t.stats.total_input_tokens===e.stats.total_input_tokens&&t.stats.total_output_tokens===e.stats.total_output_tokens&&t.stats.total_cost===e.stats.total_cost&&t.stats.total_tokens===e.stats.total_tokens?e:(r=!0,{...t,bookmarked_at:e.bookmarked_at})});return r?i.toSorted(Ri):e}var Bi=new Set([`git_remote`,`git_common_dir`,`manifest_path`,`synthetic`,`path`,`loose`]);function Vi(e){return Bi.has(e)}function Hi(e){return`${e.kind}:${e.key}`}function Ui(e){return decodeURIComponent(e)}function Wi(e){return`/projects/${encodeURIComponent(e.kind)}/${encodeURIComponent(e.key)}`}var Gi={light:``,dark:`.dark`},Ki={width:320,height:200},qi=j.createContext(null);function Ji(){let e=j.useContext(qi);if(!e)throw Error(`useChart must be used within a <ChartContainer />`);return e}function Yi({id:e,className:t,children:n,config:r,initialDimension:i=Ki,...a}){let o=j.useId(),s=`chart-${e??o.replace(/:/g,``)}`;return(0,F.jsx)(qi.Provider,{value:{config:r},children:(0,F.jsxs)(`div`,{"data-slot":`chart`,"data-chart":s,className:P(`flex aspect-video justify-center text-xs [&_.recharts-cartesian-axis-tick_text]:fill-muted-foreground [&_.recharts-cartesian-grid_line[stroke='#ccc']]:stroke-border/50 [&_.recharts-curve.recharts-tooltip-cursor]:stroke-border [&_.recharts-dot[stroke='#fff']]:stroke-transparent [&_.recharts-layer]:outline-hidden [&_.recharts-polar-grid_[stroke='#ccc']]:stroke-border [&_.recharts-radial-bar-background-sector]:fill-muted [&_.recharts-rectangle.recharts-tooltip-cursor]:fill-muted [&_.recharts-reference-line_[stroke='#ccc']]:stroke-border [&_.recharts-sector]:outline-hidden [&_.recharts-sector[stroke='#fff']]:stroke-transparent [&_.recharts-surface]:outline-hidden`,t),...a,children:[(0,F.jsx)(Xi,{id:s,config:r}),(0,F.jsx)(ee,{initialDimension:i,children:n})]})})}var Xi=({id:e,config:t})=>{let n=Object.entries(t).filter(([,e])=>e.theme??e.color);return n.length?(0,F.jsx)(`style`,{dangerouslySetInnerHTML:{__html:Object.entries(Gi).map(([t,r])=>`
35
+ ${r} [data-chart=${e}] {
36
+ ${n.map(([e,n])=>{let r=n.theme?.[t]??n.color;return r?` --color-${e}: ${r};`:null}).join(`
37
+ `)}
38
+ }
39
+ `).join(`
40
+ `)}}):null},Zi=le;function Qi({active:e,payload:t,className:n,indicator:r=`dot`,hideLabel:i=!1,hideIndicator:a=!1,label:o,labelFormatter:s,labelClassName:c,formatter:l,color:u,nameKey:d,labelKey:f}){let{config:p}=Ji(),m=j.useMemo(()=>{if(i||!t?.length)return null;let[e]=t,n=$i(p,e,`${f??e?.dataKey??e?.name??`value`}`),r=!f&&typeof o==`string`?p[o]?.label??o:n?.label;return s?(0,F.jsx)(`div`,{className:P(`font-medium`,c),children:s(r,t)}):r?(0,F.jsx)(`div`,{className:P(`font-medium`,c),children:r}):null},[o,s,t,i,c,p,f]);if(!e||!t?.length)return null;let h=t.length===1&&r!==`dot`;return(0,F.jsxs)(`div`,{className:P(`grid min-w-[8rem] items-start gap-1.5 rounded-lg border border-border/50 bg-background px-2.5 py-1.5 text-xs shadow-xl`,n),children:[h?null:m,(0,F.jsx)(`div`,{className:`grid gap-1.5`,children:t.filter(e=>e.type!==`none`).map((e,t)=>{let n=$i(p,e,`${d??e.name??e.dataKey??`value`}`),i=u??e.payload?.fill??e.color;return(0,F.jsx)(`div`,{className:P(`flex w-full flex-wrap items-stretch gap-2 [&>svg]:h-2.5 [&>svg]:w-2.5 [&>svg]:text-muted-foreground`,r===`dot`&&`items-center`),children:l&&e?.value!==void 0&&e.name?l(e.value,e.name,e,t,e.payload):(0,F.jsxs)(F.Fragment,{children:[n?.icon?(0,F.jsx)(n.icon,{}):!a&&(0,F.jsx)(`div`,{className:P(`shrink-0 rounded-[2px] border-(--color-border) bg-(--color-bg)`,{"h-2.5 w-2.5":r===`dot`,"w-1":r===`line`,"w-0 border-[1.5px] border-dashed bg-transparent":r===`dashed`,"my-0.5":h&&r===`dashed`}),style:{"--color-bg":i,"--color-border":i}}),(0,F.jsxs)(`div`,{className:P(`flex flex-1 justify-between leading-none`,h?`items-end`:`items-center`),children:[(0,F.jsxs)(`div`,{className:`grid gap-1.5`,children:[h?m:null,(0,F.jsx)(`span`,{className:`text-muted-foreground`,children:n?.label??e.name})]}),e.value!=null&&(0,F.jsx)(`span`,{className:`font-mono font-medium text-foreground tabular-nums`,children:typeof e.value==`number`?e.value.toLocaleString():String(e.value)})]})]})},t)})})]})}function $i(e,t,n){if(typeof t!=`object`||!t)return;let r=`payload`in t&&typeof t.payload==`object`&&t.payload!==null?t.payload:void 0,i=n;return n in t&&typeof t[n]==`string`?i=t[n]:r&&n in r&&typeof r[n]==`string`&&(i=r[n]),i in e?e[i]:e[n]}function ea(e){return e.toLocaleString(`en-US`)}function ta(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}k`:ea(e)}function na(e){return e===0?`$0.00`:e<.01?`$${e.toFixed(4)}`:`$${e.toFixed(2)}`}function ra(e){if(e===`recorded`)return`recorded`;if(e===`estimated`)return`estimated`}function ia(e){if(!e)return`unknown`;let t=Date.now()-e;if(Number.isNaN(t)||t<0)return`just now`;let 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 aa({label:e,value:t,hint:n}){return(0,F.jsxs)(`div`,{className:`rounded-sm border border-[var(--console-border)] bg-white p-4`,children:[(0,F.jsx)(`p`,{className:`console-mono text-[11px] uppercase tracking-wider text-[var(--console-muted)]`,children:e}),(0,F.jsx)(`p`,{className:`console-mono mt-2 text-xl font-semibold text-[var(--console-text)]`,children:t}),n?(0,F.jsx)(`p`,{className:`mt-1 text-xs text-[var(--console-muted)]`,children:n}):null]})}function oa(e){return e.length>=10?e.slice(5):e}function sa({buckets:e}){let[t,n]=(0,j.useState)(null),r=(0,j.useMemo)(()=>Math.max(1,...e.map(e=>e.sessions)),[e]),i=(0,j.useMemo)(()=>e.reduce((e,t)=>e+t.sessions,0),[e]),a=(0,j.useMemo)(()=>{if(e.length===0)return new Set;let t=Math.min(6,e.length);if(t===1)return new Set([0]);let n=new Set;for(let r=0;r<t;r+=1)n.add(Math.round(r*(e.length-1)/(t-1)));return n},[e.length]);return(0,F.jsxs)(`div`,{className:`rounded-sm border border-[var(--console-border)] bg-white p-4`,children:[(0,F.jsxs)(`div`,{className:`mb-3 flex items-center justify-between gap-3`,children:[(0,F.jsxs)(`div`,{children:[(0,F.jsx)(`h3`,{className:`console-mono text-xs font-bold uppercase text-[var(--console-text)]`,children:`Daily Activity`}),(0,F.jsxs)(`p`,{className:`console-mono mt-1 text-[11px] text-[var(--console-muted)]`,children:[`Session activity · last `,e.length,` days`]})]}),(0,F.jsx)(`span`,{className:`console-mono text-right text-[11px] text-[var(--console-muted)]`,children:t?`${t.date} · ${ea(t.sessions)} sessions · ${ea(t.messages)} msgs`:`${ea(i)} in range`})]}),(0,F.jsx)(`div`,{className:`flex h-32 items-end gap-[2px]`,onMouseLeave:()=>n(null),children:e.map(e=>{let i=e.sessions>0?Math.max(Math.round(e.sessions/r*128),4):2,a=`${e.date} · ${e.sessions} sessions · ${e.messages} msgs`,o=t?.date===e.date;return(0,F.jsx)(`div`,{title:a,onMouseEnter:()=>n(e),className:`flex-1 cursor-default rounded-t-[1px] transition-opacity ${e.sessions>0?`bg-[var(--console-accent)]`:`bg-[var(--console-surface-muted)]`} ${o?`opacity-70`:`opacity-100`}`,style:{height:`${i}px`}},e.date)})}),(0,F.jsx)(`div`,{className:`console-mono mt-2 flex text-[10px] text-[var(--console-muted)]`,children:e.map((e,t)=>(0,F.jsx)(`span`,{className:`flex-1 text-center`,children:a.has(t)?oa(e.date):``},e.date))})]})}var ca={input:`#4A9EFF`,output:`#7C5CFF`,cache_read:`#3FB68B`,cache_create:`#E8A23B`},la={input:`Input`,output:`Output`,cache_read:`Cache Read`,cache_create:`Cache Create`};function ua({buckets:e}){let[t,n]=(0,j.useState)(null),r=(0,j.useMemo)(()=>Math.max(1,...e.map(e=>e.input+e.output+e.cache_read+e.cache_create)),[e]),i=(0,j.useMemo)(()=>e.reduce((e,t)=>e+t.input+t.output+t.cache_read+t.cache_create,0),[e]),a=(0,j.useMemo)(()=>{if(e.length===0)return new Set;let t=Math.min(6,e.length);if(t===1)return new Set([0]);let n=new Set;for(let r=0;r<t;r+=1)n.add(Math.round(r*(e.length-1)/(t-1)));return n},[e.length]);return i===0?null:(0,F.jsxs)(`div`,{className:`rounded-sm border border-[var(--console-border)] bg-white p-4`,children:[(0,F.jsxs)(`div`,{className:`mb-3 flex items-center justify-between gap-3`,children:[(0,F.jsxs)(`div`,{children:[(0,F.jsx)(`h3`,{className:`console-mono text-xs font-bold uppercase text-[var(--console-text)]`,children:`Daily Token Activity`}),(0,F.jsxs)(`p`,{className:`console-mono mt-1 text-[11px] text-[var(--console-muted)]`,children:[`Token breakdown · last `,e.length,` days`]})]}),(0,F.jsx)(`span`,{className:`console-mono text-right text-[11px] text-[var(--console-muted)]`,children:t?`${t.date} · ${ta(t.input+t.output+t.cache_read+t.cache_create)} total`:`${ta(i)} in range`})]}),t?(0,F.jsx)(`div`,{className:`mb-2 flex gap-4`,children:[`input`,`output`,`cache_read`,`cache_create`].map(e=>(0,F.jsxs)(`span`,{className:`console-mono flex items-center gap-1.5 text-[10px] text-[var(--console-muted)]`,children:[(0,F.jsx)(`span`,{className:`inline-block size-2 rounded-full`,style:{backgroundColor:ca[e]}}),la[e],`: `,ta(t[e])]},e))}):(0,F.jsx)(`div`,{className:`mb-2 flex gap-4`,children:[`input`,`output`,`cache_read`,`cache_create`].map(e=>(0,F.jsxs)(`span`,{className:`console-mono flex items-center gap-1.5 text-[10px] text-[var(--console-muted)]`,children:[(0,F.jsx)(`span`,{className:`inline-block size-2 rounded-full`,style:{backgroundColor:ca[e]}}),la[e]]},e))}),(0,F.jsx)(`div`,{className:`flex h-32 items-end gap-[2px]`,onMouseLeave:()=>n(null),children:e.map(e=>{let i=e.input+e.output+e.cache_read+e.cache_create,a=i>0?Math.max(Math.round(i/r*128),4):2,o=t?.date===e.date,s=i>0?[{key:`input`,value:e.input},{key:`output`,value:e.output},{key:`cache_read`,value:e.cache_read},{key:`cache_create`,value:e.cache_create}]:[];return(0,F.jsx)(`div`,{onMouseEnter:()=>n(e),className:`flex flex-1 cursor-default flex-col justify-end overflow-hidden rounded-t-[1px] transition-opacity ${o?`opacity-70`:`opacity-100`}`,style:{height:`${a}px`},children:i>0?s.map(e=>{let t=Math.max(Math.round(e.value/i*a),0);return t===0?null:(0,F.jsx)(`div`,{style:{height:`${t}px`,backgroundColor:ca[e.key]}},e.key)}):(0,F.jsx)(`div`,{className:`h-full bg-[var(--console-surface-muted)]`})},e.date)})}),(0,F.jsx)(`div`,{className:`console-mono mt-2 flex text-[10px] text-[var(--console-muted)]`,children:e.map((e,t)=>(0,F.jsx)(`span`,{className:`flex-1 text-center`,children:a.has(t)?oa(e.date):``},e.date))})]})}var da=[`#4A9EFF`,`#7C5CFF`,`#3FB68B`,`#E8A23B`,`#E5484D`,`#5BCEDA`,`#F472B6`,`#A78BFA`,`#FB923C`,`#6EE7B7`];function fa({entries:e}){let t=(0,j.useMemo)(()=>e.filter(e=>e.tokens>0),[e]),n=(0,j.useMemo)(()=>t.reduce((e,t)=>e+t.tokens,0),[t]);if(t.length===0||n===0)return(0,F.jsx)(`div`,{className:`rounded-sm border border-[var(--console-border)] bg-white p-4 text-sm text-[var(--console-muted)]`,children:`No model data yet`});let r=t.map((e,t)=>({...e,chartKey:`model${t}`,fraction:e.tokens/n,fill:da[t%da.length]})),i=r.reduce((e,t)=>(e[t.chartKey]={label:t.model,color:t.fill},e),{});return(0,F.jsxs)(`div`,{className:`rounded-sm border border-[var(--console-border)] bg-white p-4`,children:[(0,F.jsxs)(`div`,{className:`mb-3 flex items-center justify-between gap-3`,children:[(0,F.jsx)(`h3`,{className:`console-mono text-xs font-bold uppercase text-[var(--console-text)]`,children:`Model Distribution`}),(0,F.jsxs)(`span`,{className:`console-mono text-[11px] text-[var(--console-muted)]`,children:[t.length,` models`]})]}),(0,F.jsxs)(`div`,{className:`flex items-center gap-6`,children:[(0,F.jsxs)(`div`,{className:`flex shrink-0 flex-col items-center`,children:[(0,F.jsx)(Yi,{config:i,className:`aspect-square size-[160px]`,children:(0,F.jsxs)(de,{children:[(0,F.jsx)(Zi,{content:(0,F.jsx)(Qi,{hideLabel:!0,nameKey:`chartKey`,formatter:e=>(0,F.jsxs)(`span`,{className:`font-mono font-medium text-foreground tabular-nums`,children:[ea(Number(e)),` tokens`]})})}),(0,F.jsx)(S,{data:r,dataKey:`tokens`,nameKey:`chartKey`,outerRadius:70,paddingAngle:1,strokeWidth:0,isAnimationActive:!1})]})}),(0,F.jsxs)(`div`,{className:`console-mono -mt-1 text-center`,children:[(0,F.jsx)(`div`,{className:`text-xs font-semibold text-[var(--console-text)]`,children:ta(n)}),(0,F.jsx)(`div`,{className:`text-[10px] text-[var(--console-muted)]`,children:`tokens`})]})]}),(0,F.jsx)(`ul`,{className:`min-w-0 flex-1 space-y-1.5`,children:r.map(e=>(0,F.jsxs)(`li`,{className:`flex items-center gap-2`,children:[(0,F.jsx)(`span`,{className:`inline-block size-2.5 shrink-0 rounded-full`,style:{backgroundColor:e.fill}}),(0,F.jsx)(`span`,{className:`console-mono min-w-0 flex-1 truncate text-xs text-[var(--console-text)]`,children:e.model}),(0,F.jsxs)(`span`,{className:`console-mono shrink-0 text-[11px] text-[var(--console-muted)]`,children:[(e.fraction*100).toFixed(1),`%`]})]},e.model))})]})]})}function pa({perAgent:e}){let t=(0,j.useMemo)(()=>e.reduce((e,t)=>e+t.sessions,0),[e]);return t===0||e.length===0?(0,F.jsx)(`div`,{className:`rounded-sm border border-[var(--console-border)] bg-white p-4 text-sm text-[var(--console-muted)]`,children:`No agent data yet`}):(0,F.jsxs)(`div`,{className:`rounded-sm border border-[var(--console-border)] bg-white p-4`,children:[(0,F.jsxs)(`div`,{className:`mb-3 flex items-center justify-between gap-3`,children:[(0,F.jsx)(`h3`,{className:`console-mono text-xs font-bold uppercase text-[var(--console-text)]`,children:`Agent Distribution`}),(0,F.jsxs)(`span`,{className:`console-mono text-[11px] text-[var(--console-muted)]`,children:[e.length,` agents`]})]}),(0,F.jsx)(`ul`,{className:`space-y-2`,children:e.map(e=>{let n=t>0?e.sessions/t*100:0;return(0,F.jsx)(`li`,{children:(0,F.jsxs)(d,{to:`/${e.name.toLowerCase()}`,className:`block rounded-sm border border-transparent px-2 py-1.5 transition-colors hover:border-[var(--console-border)] hover:bg-[var(--console-surface-muted)]`,children:[(0,F.jsxs)(`div`,{className:`flex items-center gap-2`,children:[e.icon?(0,F.jsx)(`img`,{src:e.icon,alt:e.displayName,className:`size-4 object-contain`}):null,(0,F.jsx)(`span`,{className:`console-mono flex-1 text-xs text-[var(--console-text)]`,children:e.displayName}),(0,F.jsxs)(`span`,{className:`console-mono text-[11px] text-[var(--console-muted)]`,children:[ea(e.sessions),` · `,n.toFixed(1),`%`]})]}),(0,F.jsx)(`div`,{className:`mt-1.5 h-1.5 overflow-hidden rounded-sm bg-[var(--console-surface-muted)]`,children:(0,F.jsx)(`div`,{className:`h-full bg-[var(--console-accent)]`,style:{width:`${n}%`}})}),(0,F.jsxs)(`div`,{className:`console-mono mt-1 flex gap-3 text-[10px] text-[var(--console-muted)]`,children:[(0,F.jsxs)(`span`,{children:[ea(e.messages),` msgs`]}),(0,F.jsxs)(`span`,{children:[ta(e.tokens),` tokens`]})]})]})},e.name)})})]})}function ma({projects:e}){return e.length===0?null:(0,F.jsxs)(`div`,{className:`rounded-sm border border-[var(--console-border)] bg-white p-4`,children:[(0,F.jsxs)(`div`,{className:`mb-3 flex items-center justify-between gap-3`,children:[(0,F.jsx)(`h3`,{className:`console-mono text-xs font-bold uppercase text-[var(--console-text)]`,children:`Projects`}),(0,F.jsx)(d,{to:`/projects`,className:`console-mono text-[11px] text-[var(--console-muted)] transition-colors hover:text-[var(--console-text)]`,children:`View all`})]}),(0,F.jsx)(`ul`,{className:`space-y-2`,children:e.slice(0,5).map(e=>{let t=e.agentStats.slice(0,3);return(0,F.jsx)(`li`,{children:(0,F.jsxs)(d,{to:Wi({kind:e.identityKind,key:e.identityKey}),className:`block rounded-sm border border-transparent px-2 py-1.5 transition-colors hover:border-[var(--console-border)] hover:bg-[var(--console-surface-muted)]`,children:[(0,F.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,F.jsx)(`span`,{className:`console-mono min-w-0 flex-1 truncate text-xs text-[var(--console-text)]`,children:e.displayName}),(0,F.jsxs)(`span`,{className:`console-mono shrink-0 text-[11px] text-[var(--console-muted)]`,children:[ea(e.sessionCount),` · `,na(e.cost)]})]}),(0,F.jsxs)(`div`,{className:`mt-1.5 flex flex-wrap items-center gap-1.5`,children:[t.map(e=>{let t=M.agents[e.name];return(0,F.jsxs)(`span`,{className:`console-mono inline-flex items-center gap-1 rounded-sm border border-[var(--console-border)] bg-white px-1.5 py-0.5 text-[10px] text-[var(--console-muted)]`,children:[t?.icon?(0,F.jsx)(`img`,{src:t.icon,alt:t.name,className:`size-3 object-contain`}):null,t?.name??e.name,` · `,e.sessions]},e.name)}),(0,F.jsxs)(`span`,{className:`console-mono min-w-0 truncate text-[10px] text-[var(--console-muted)]`,children:[ta(e.tokens),` tokens`]})]})]})},`${e.identityKind}:${e.identityKey}`)})})]})}function ha({sessions:e,onToggleBookmark:t}){return e.length===0?null:(0,F.jsxs)(`div`,{className:`rounded-sm border border-[var(--console-border)] bg-white p-4`,children:[(0,F.jsxs)(`div`,{className:`mb-3 flex items-center justify-between`,children:[(0,F.jsx)(`h3`,{className:`console-mono text-xs font-bold uppercase text-[var(--console-text)]`,children:`Bookmarked Sessions`}),(0,F.jsxs)(`span`,{className:`console-mono text-[11px] text-[var(--console-muted)]`,children:[e.length,` items`]})]}),(0,F.jsx)(`ul`,{className:`space-y-2`,children:e.map(e=>{let n=M.agents[e.agentKey],r=e.time_updated??e.time_created;return(0,F.jsx)(`li`,{children:(0,F.jsxs)(`div`,{className:`flex items-start gap-2 rounded-sm border border-transparent px-2 py-1.5 transition-colors hover:border-[var(--console-border)] hover:bg-[var(--console-surface-muted)]`,children:[(0,F.jsxs)(d,{to:`/${e.fullPath}`,className:`flex min-w-0 flex-1 items-start gap-2`,children:[n?.icon?(0,F.jsx)(`img`,{src:n.icon,alt:n.name,className:`mt-0.5 size-3.5 shrink-0 object-contain`}):null,(0,F.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,F.jsx)(`p`,{className:`line-clamp-1 text-sm text-[var(--console-text)]`,children:e.title}),(0,F.jsxs)(`p`,{className:`console-mono mt-0.5 line-clamp-1 text-[11px] text-[var(--console-muted)]`,children:[`/`,e.fullPath,` · `,ia(r)]})]})]}),(0,F.jsx)(vi,{active:!0,onToggle:()=>t(e)})]})},Pi(e.agentKey,e.sessionId))})})]})}function ga({sessions:e,isBookmarked:t,onToggleBookmark:n}){return e.length===0?(0,F.jsx)(`div`,{className:`rounded-sm border border-[var(--console-border)] bg-white p-4 text-sm text-[var(--console-muted)]`,children:`No sessions yet`}):(0,F.jsxs)(`div`,{className:`rounded-sm border border-[var(--console-border)] bg-white p-4`,children:[(0,F.jsxs)(`div`,{className:`mb-3 flex items-center justify-between`,children:[(0,F.jsx)(`h3`,{className:`console-mono text-xs font-bold uppercase text-[var(--console-text)]`,children:`Recent Activity`}),(0,F.jsxs)(`span`,{className:`console-mono text-[11px] text-[var(--console-muted)]`,children:[e.length,` items`]})]}),(0,F.jsx)(`ul`,{className:`space-y-2`,children:e.map(e=>{let r=e.agentName.toLowerCase(),i=M.agents[r],a=e.time_updated??e.time_created,o=t(r,e.id);return(0,F.jsx)(`li`,{children:(0,F.jsxs)(`div`,{className:`flex items-start gap-2 rounded-sm border border-transparent px-2 py-1.5 transition-colors hover:border-[var(--console-border)] hover:bg-[var(--console-surface-muted)]`,children:[(0,F.jsxs)(d,{to:`/${e.slug}`,className:`min-w-0 flex-1`,children:[(0,F.jsxs)(`div`,{className:`flex items-center gap-2`,children:[i?.icon?(0,F.jsx)(`img`,{src:i.icon,alt:i.name,className:`size-3.5 shrink-0 object-contain`}):null,(0,F.jsx)(`p`,{className:`line-clamp-1 flex-1 text-sm text-[var(--console-text)]`,children:e.title}),(0,F.jsx)(`span`,{className:`console-mono shrink-0 text-[11px] text-[var(--console-muted)]`,children:ia(a)})]}),(0,F.jsxs)(`p`,{className:`console-mono mt-0.5 line-clamp-1 text-[11px] text-[var(--console-muted)]`,children:[`/`,e.slug]}),(0,F.jsx)(Je,{tags:e.smart_tags,className:`mt-1.5`})]}),(0,F.jsx)(vi,{active:o,onToggle:()=>n(e,r)})]})},e.id)})})]})}function _a({activity:e}){return e.length===0?(0,F.jsx)(`div`,{className:`rounded-sm border border-[var(--console-border)] bg-white p-4 text-sm text-[var(--console-muted)]`,children:`No file activity yet`}):(0,F.jsxs)(`div`,{className:`rounded-sm border border-[var(--console-border)] bg-white p-4`,children:[(0,F.jsxs)(`div`,{className:`mb-3 flex items-center justify-between`,children:[(0,F.jsx)(`h3`,{className:`console-mono text-xs font-bold uppercase text-[var(--console-text)]`,children:`Recently Touched Files`}),(0,F.jsxs)(`span`,{className:`console-mono text-[11px] text-[var(--console-muted)]`,children:[e.length,` files`]})]}),(0,F.jsx)(`ul`,{className:`space-y-2`,children:e.map(e=>{let t=e.latest_time;return(0,F.jsx)(`li`,{children:(0,F.jsxs)(d,{to:`/${e.session.slug}`,className:`block rounded-sm border border-transparent px-2 py-1.5 transition-colors hover:border-[var(--console-border)] hover:bg-[var(--console-surface-muted)]`,children:[(0,F.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,F.jsx)(`span`,{className:`console-mono rounded-sm border border-[var(--console-border)] bg-[var(--console-surface-muted)] px-1.5 py-0.5 text-[10px] uppercase text-[var(--console-muted)]`,children:e.kind}),(0,F.jsx)(`span`,{className:`console-mono min-w-0 flex-1 truncate text-xs text-[var(--console-text)]`,children:e.path}),(0,F.jsx)(`span`,{className:`console-mono shrink-0 text-[11px] text-[var(--console-muted)]`,children:ia(t)})]}),(0,F.jsxs)(`p`,{className:`console-mono mt-1 line-clamp-1 text-[11px] text-[var(--console-muted)]`,children:[e.session.project_identity?.displayName??e.session.directory,` ·`,` `,e.session.title,` · `,e.count,` events`]})]})},`${e.agent_name}/${e.session_id}/${e.kind}/${e.path}`)})})]})}function va({data:e,projects:t=[],bookmarkedSessions:n,isBookmarked:r,onToggleBookmark:i}){let{totals:a,perAgent:o,dailyActivity:s,dailyTokenActivity:c,modelDistribution:l,recentSessions:u,recentFileActivities:d=[]}=e;return(0,F.jsxs)(`div`,{"data-testid":`dashboard`,className:`mx-auto max-w-5xl space-y-4`,children:[(0,F.jsxs)(`div`,{className:`grid gap-3 md:grid-cols-5`,children:[(0,F.jsx)(aa,{label:`Total Sessions`,value:ea(a.sessions)}),(0,F.jsx)(aa,{label:`Total Messages`,value:ea(a.messages)}),(0,F.jsx)(aa,{label:`Total Tokens`,value:ta(a.tokens)}),(0,F.jsx)(aa,{label:`Total Cost`,value:na(a.cost),hint:ra(a.cost_source)}),(0,F.jsx)(aa,{label:`Latest Activity`,value:ia(a.latestActivity),hint:a.latestActivity?new Date(a.latestActivity).toLocaleString(`zh-CN`):void 0})]}),(0,F.jsx)(sa,{buckets:s}),(0,F.jsx)(ua,{buckets:c}),(0,F.jsxs)(`div`,{className:`grid gap-4 lg:grid-cols-2`,children:[(0,F.jsx)(fa,{entries:l}),(0,F.jsx)(pa,{perAgent:o})]}),(0,F.jsx)(ma,{projects:t}),(0,F.jsx)(ga,{sessions:u,isBookmarked:r,onToggleBookmark:i}),(0,F.jsx)(_a,{activity:d}),(0,F.jsx)(ha,{sessions:n,onToggleBookmark:e=>i(e)})]})}function ya(e){return e.toLocaleString(`en-US`)}function ba(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}k`:ya(e)}function xa(e){return e===0?`$0.00`:e<.01?`$${e.toFixed(4)}`:`$${e.toFixed(2)}`}function Sa(e){if(!e)return`unknown`;let t=Date.now()-e;if(Number.isNaN(t)||t<0)return`just now`;let 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 Ca(e){return e.stats.total_tokens??e.stats.total_input_tokens+e.stats.total_output_tokens}function wa({label:e,value:t,hint:n}){return(0,F.jsxs)(`div`,{className:`rounded-sm border border-[var(--console-border)] bg-white p-4`,children:[(0,F.jsx)(`p`,{className:`console-mono text-[11px] uppercase tracking-wider text-[var(--console-muted)]`,children:e}),(0,F.jsx)(`p`,{className:`console-mono mt-2 text-xl font-semibold text-[var(--console-text)]`,children:t}),n?(0,F.jsx)(`p`,{className:`mt-1 text-xs text-[var(--console-muted)]`,children:n}):null]})}function Ta({agents:e}){return e.length===0?null:(0,F.jsx)(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:e.slice(0,4).map(e=>{let t=M.agents[e.name];return(0,F.jsxs)(`span`,{className:`console-mono inline-flex items-center gap-1 rounded-sm border border-[var(--console-border)] bg-white px-1.5 py-0.5 text-[10px] text-[var(--console-muted)]`,children:[t?.icon?(0,F.jsx)(`img`,{src:t.icon,alt:t.name,className:`size-3 object-contain`}):null,t?.name??e.name,` · `,e.sessions]},e.name)})})}function Ea({project:e}){return(0,F.jsx)(`li`,{children:(0,F.jsxs)(d,{to:Wi({kind:e.identityKind,key:e.identityKey}),className:`block rounded-sm border border-[var(--console-border)] bg-white/85 p-4 transition-colors hover:border-[var(--console-border-strong)] hover:bg-white`,children:[(0,F.jsxs)(`div`,{className:`flex flex-col gap-3 md:flex-row md:items-start md:justify-between`,children:[(0,F.jsxs)(`div`,{className:`min-w-0`,children:[(0,F.jsx)(`h2`,{className:`console-mono line-clamp-1 text-sm font-semibold text-[var(--console-text)]`,children:e.displayName}),(0,F.jsx)(`p`,{className:`console-mono mt-1 break-all text-[11px] text-[var(--console-muted)]`,children:e.identityKey})]}),(0,F.jsxs)(`div`,{className:`console-mono flex shrink-0 flex-wrap gap-2 text-[11px] text-[var(--console-muted)]`,children:[(0,F.jsxs)(`span`,{children:[ya(e.sessionCount),` sessions`]}),(0,F.jsxs)(`span`,{children:[ba(e.tokens),` tokens`]}),(0,F.jsx)(`span`,{children:xa(e.cost)}),(0,F.jsx)(`span`,{children:Sa(e.lastActivity)})]})]}),(0,F.jsxs)(`div`,{className:`mt-3 flex flex-col gap-2 md:flex-row md:items-center md:justify-between`,children:[(0,F.jsx)(Ta,{agents:e.agentStats}),(0,F.jsx)(`span`,{className:`console-mono text-[10px] uppercase text-[var(--console-muted)]`,children:e.identityKind})]})]})})}function Da({projects:e}){let t=e.reduce((e,t)=>e+t.sessionCount,0),n=e.reduce((e,t)=>e+t.tokens,0),r=e.reduce((e,t)=>e+t.cost,0),i=Math.max(0,...e.map(e=>e.lastActivity??0));return e.length===0?(0,F.jsx)(`div`,{className:`mx-auto max-w-5xl rounded-sm border border-[var(--console-border)] bg-white p-6 text-sm text-[var(--console-muted)]`,children:`No projects found`}):(0,F.jsxs)(`div`,{className:`mx-auto max-w-5xl space-y-4`,children:[(0,F.jsxs)(`div`,{className:`grid gap-3 md:grid-cols-4`,children:[(0,F.jsx)(wa,{label:`Projects`,value:ya(e.length)}),(0,F.jsx)(wa,{label:`Sessions`,value:ya(t)}),(0,F.jsx)(wa,{label:`Tokens`,value:ba(n)}),(0,F.jsx)(wa,{label:`Total Cost`,value:xa(r),hint:i?`Latest ${Sa(i)}`:void 0})]}),(0,F.jsx)(`ul`,{className:`grid gap-3`,children:e.map(e=>(0,F.jsx)(Ea,{project:e},`${e.identityKind}:${e.identityKey}`))})]})}function Oa({agents:e,activeAgent:t,onChange:n}){return(0,F.jsx)(`div`,{className:`rounded-sm border border-[var(--console-border)] bg-white p-3`,children:(0,F.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,F.jsx)(`span`,{className:`console-mono text-[10px] font-semibold uppercase text-[var(--console-muted)]`,children:`Agent`}),(0,F.jsx)(`button`,{type:`button`,onClick:()=>n(void 0),className:`console-mono rounded-sm border px-2 py-1 text-[10px] transition-colors ${t?`border-[var(--console-border)] bg-[var(--console-surface-muted)] text-[var(--console-muted)] hover:bg-white`:`border-[var(--console-border-strong)] bg-[var(--console-accent)] text-white`}`,children:`All Agents`}),e.map(e=>{let r=M.agents[e.name],i=t===e.name;return(0,F.jsxs)(`button`,{type:`button`,onClick:()=>n(i?void 0:e.name),className:`console-mono inline-flex items-center gap-1 rounded-sm border px-2 py-1 text-[10px] transition-colors ${i?`border-[var(--console-border-strong)] bg-[var(--console-accent)] text-white`:`border-[var(--console-border)] bg-[var(--console-surface-muted)] text-[var(--console-muted)] hover:bg-white`}`,children:[r?.icon?(0,F.jsx)(`img`,{src:r.icon,alt:r.name,className:`size-3 object-contain`}):null,r?.name??e.name,` · `,e.sessions]},e.name)})]})})}function ka({project:e}){return(0,F.jsx)(`div`,{className:`rounded-sm border border-[var(--console-border)] bg-white p-4`,children:(0,F.jsxs)(`div`,{className:`flex flex-col gap-3 md:flex-row md:items-start md:justify-between`,children:[(0,F.jsxs)(`div`,{className:`min-w-0`,children:[(0,F.jsx)(`h2`,{className:`console-mono text-base font-semibold text-[var(--console-text)]`,children:e.displayName}),(0,F.jsxs)(`p`,{className:`console-mono mt-1 break-all text-[11px] text-[var(--console-muted)]`,children:[e.identityKind,`: `,e.identityKey]})]}),(0,F.jsx)(Ta,{agents:e.agentStats})]})})}function Aa({sessions:e}){if(e.length===0)return null;let t=e.toSorted((e,t)=>t.stats.total_cost-e.stats.total_cost).slice(0,5);return(0,F.jsxs)(`div`,{className:`rounded-sm border border-[var(--console-border)] bg-white p-4`,children:[(0,F.jsxs)(`div`,{className:`mb-3 flex items-center justify-between gap-3`,children:[(0,F.jsx)(`h3`,{className:`console-mono text-xs font-bold uppercase text-[var(--console-text)]`,children:`Top Cost`}),(0,F.jsxs)(`span`,{className:`console-mono text-[11px] text-[var(--console-muted)]`,children:[t.length,` sessions`]})]}),(0,F.jsx)(`ul`,{className:`space-y-2`,children:t.map(e=>{let t=M.agents[e.agentKey];return(0,F.jsx)(`li`,{children:(0,F.jsxs)(d,{to:`/${e.fullPath}`,className:`block rounded-sm border border-transparent px-2 py-1.5 transition-colors hover:border-[var(--console-border)] hover:bg-[var(--console-surface-muted)]`,children:[(0,F.jsxs)(`div`,{className:`flex items-center gap-2`,children:[t?.icon?(0,F.jsx)(`img`,{src:t.icon,alt:t.name,className:`size-3.5 object-contain`}):null,(0,F.jsx)(`span`,{className:`line-clamp-1 flex-1 text-sm text-[var(--console-text)]`,children:e.title}),(0,F.jsx)(`span`,{className:`console-mono text-[11px] text-[var(--console-muted)]`,children:xa(e.stats.total_cost)})]}),(0,F.jsxs)(`p`,{className:`console-mono mt-1 text-[11px] text-[var(--console-muted)]`,children:[`/`,e.fullPath,` · `,ba(Ca(e)),` tokens`]})]})},e.fullPath)})})]})}function ja({project:e,projectKey:t,dashboard:n,loading:r,error:i,sessions:a,activeAgent:o,onChangeAgent:s,isBookmarked:c,onToggleSessionBookmark:l}){if(!e)return(0,F.jsxs)(`div`,{className:`mx-auto max-w-4xl rounded-sm border border-[var(--console-border)] bg-white p-6`,children:[(0,F.jsx)(`h2`,{className:`console-mono text-sm font-semibold text-[var(--console-text)]`,children:`Project Not Found`}),(0,F.jsx)(`p`,{className:`console-mono mt-2 break-all text-xs text-[var(--console-muted)]`,children:t}),(0,F.jsx)(d,{to:`/projects`,className:`console-mono mt-4 inline-flex rounded-sm border border-[var(--console-border)] bg-[var(--console-surface-muted)] px-2 py-1 text-xs text-[var(--console-text)] transition-colors hover:bg-white`,children:`Back to Projects`})]});let u=o?a.filter(e=>e.agentKey===o):a;return(0,F.jsxs)(`div`,{className:`mx-auto max-w-5xl space-y-4`,children:[(0,F.jsx)(ka,{project:e}),(0,F.jsx)(Oa,{agents:e.agentStats,activeAgent:o,onChange:s}),r?(0,F.jsx)(`div`,{className:`rounded-sm border border-[var(--console-border)] bg-white p-6 text-sm text-[var(--console-muted)]`,children:`Loading project dashboard`}):i?(0,F.jsx)(`div`,{className:`rounded-sm border border-[var(--console-error-border)] bg-[var(--console-error-bg)] p-6 text-sm text-[var(--console-error)]`,children:i}):n?(0,F.jsx)(va,{data:n,projects:[],bookmarkedSessions:[],isBookmarked:c,onToggleBookmark:(e,t)=>{`agentName`in e&&l(e,t??e.agentName.toLowerCase())}}):null,(0,F.jsx)(Aa,{sessions:u})]})}var Ma=class extends j.Component{constructor(e){super(e),this.state={hasError:!1}}static getDerivedStateFromError(e){return{hasError:!0,error:e}}componentDidCatch(e,t){console.error(`ErrorBoundary caught error:`,e,t)}render(){return this.state.hasError?this.props.fallback?this.props.fallback:(0,F.jsxs)(`div`,{className:`rounded-sm border border-[var(--console-error-border)] bg-[var(--console-error-bg)] p-6`,children:[(0,F.jsx)(`h3`,{className:`console-mono mb-2 text-sm font-semibold text-[var(--console-error)]`,children:`Something went wrong`}),(0,F.jsx)(`p`,{className:`console-mono text-xs text-[var(--console-muted)]`,children:this.state.error?.message||`Unknown error`})]}):this.props.children}};function Na(e){return`'${e.replace(/'/g,`'\\''`)}'`}var Pa={claudecode:`claude --resume`,codex:`codex resume`,kimi:`kimi -r`,opencode:`opencode -s`};function Fa(e){let t=e.toLowerCase();return t in Pa?Pa[t]:null}function Ia({agentName:e,sessionId:t,directory:n}){let r=Fa(e);if(!r)return null;let i=`${r} ${Na(t)}`,a=n??``;return a.trim()?`cd ${Na(a)} && ${i}`:i}async function La(e){if(typeof navigator<`u`&&navigator.clipboard?.writeText)try{return await navigator.clipboard.writeText(e),!0}catch{}if(typeof document>`u`)return!1;let t=document.createElement(`textarea`);t.value=e,t.setAttribute(`readonly`,``),t.style.position=`fixed`,t.style.opacity=`0`,document.body.appendChild(t),t.select();let n=!1;try{n=document.execCommand(`copy`)}catch{n=!1}return document.body.removeChild(t),n}function Ra({agentName:e,sessionId:t,directory:n,className:r=``}){let[i,a]=(0,j.useState)(!1),o=Ia({agentName:e,sessionId:t,directory:n});return(0,j.useEffect)(()=>{if(!i)return;let e=window.setTimeout(()=>a(!1),1500);return()=>window.clearTimeout(e)},[i]),o?(0,F.jsxs)(`button`,{type:`button`,onClick:e=>{e.preventDefault(),e.stopPropagation(),La(o).then(e=>{e&&a(!0)})},"aria-label":i?`Resume command copied: ${o}`:`Copy resume command: ${o}`,title:i?`Copied: ${o}`:`Copy: ${o}`,className:`console-mono inline-flex items-center gap-1.5 rounded-sm border px-2 py-1 text-[11px] transition-colors ${r} ${i?`border-[var(--console-border-strong)] bg-[var(--console-surface-muted)] text-[var(--console-text)]`:`border-[var(--console-border)] bg-[var(--console-surface-muted)] text-[var(--console-muted)] hover:border-[var(--console-border-strong)] hover:text-[var(--console-text)]`}`,children:[i?(0,F.jsx)(u,{className:`size-3`,strokeWidth:1.8}):(0,F.jsx)(te,{className:`size-3`,strokeWidth:1.8}),(0,F.jsx)(`span`,{children:i?`Copied`:`Copy resume`})]}):null}var za=`
41
+ [data-type='item'][data-item-type='file'] > [data-item-section='icon'] {
42
+ display: none;
43
+ }
44
+
45
+ [data-type='item'][data-item-type='file'] > [data-item-section='spacing'] {
46
+ padding-left: 2px;
47
+ }
48
+
49
+ [data-type='item'][data-item-type='file'] > [data-item-section='spacing'] > [data-item-section='spacing-item'] {
50
+ margin-right: 4px;
51
+ }
52
+
53
+ [data-type='item'][data-item-type='file'] > [data-item-section='content'] {
54
+ flex: 1 1 auto;
55
+ }
56
+
57
+ [data-type='item'][data-item-type='file'] > [data-item-section='decoration'] {
58
+ flex: 0 0 auto;
59
+ padding-inline: 8px 6px;
60
+ }
61
+
62
+ [data-type='item'][data-item-type='file'] > [data-item-section='decoration'] > span {
63
+ cursor: pointer;
64
+ font-size: 18px;
65
+ line-height: 1;
66
+ }
67
+
68
+ [data-type='item'][data-item-type='file'] [data-truncate-group-container='middle'] {
69
+ width: 100%;
70
+ }
71
+
72
+ [data-type='item'][data-item-type='file']
73
+ [data-truncate-group-container='middle']
74
+ > div[data-truncate-segment-priority='2'] {
75
+ flex: 0 1 auto;
76
+ }
77
+
78
+ [data-type='item'][data-item-type='file']
79
+ [data-truncate-group-container='middle']
80
+ > div[data-truncate-segment-priority='1'] {
81
+ flex: 1 999999 auto;
82
+ }
83
+
84
+ [data-type='item'][data-item-type='file']
85
+ [data-truncate-group-container='middle']
86
+ [data-truncate-container='fruncate']
87
+ [data-truncate-grid] {
88
+ grid-template-columns: minmax(0, max-content) 0;
89
+ }
90
+
91
+ [data-type='item'][data-item-type='file']
92
+ [data-truncate-group-container='middle']
93
+ [data-truncate-container='fruncate']
94
+ [data-truncate-content] {
95
+ direction: ltr;
96
+ }
97
+
98
+ [data-type='item'][data-item-type='file']
99
+ [data-truncate-group-container='middle']
100
+ [data-truncate-container='fruncate']
101
+ [data-truncate-marker] {
102
+ right: 0;
103
+ }
104
+
105
+ [data-type='item'][data-item-type='file'] [data-truncate-marker] {
106
+ display: none;
107
+ }
108
+ `;function Ba(e){return e.replaceAll(`/`,`∕`).trim()||`(untitled)`}function Va(e){return e.replace(/\/+$/,``).split(`/`).at(-1)?.trim()||`(unknown)`}function Ha(e){let t=e.project_identity;if(t)return{key:`${t.kind}:${t.key}`,label:t.displayName||Va(e.directory)};let n=Va(e.directory);return{key:n===`(unknown)`?`__unknown__`:`path:${e.directory||n}`,label:n}}function Ua(e){return e.time_updated??e.time_created}function Wa(e,t,n){let r=e.get(t.path)??2**53-1,i=e.get(n.path)??2**53-1;return r===i?t.path.localeCompare(n.path):r-i}function Ga(e){let t=new Map,n=new Map,r=new Map,i=new Map,a=new Map,o=new Map,s=new Set,c=[],l=new Map;for(let t of e){let{key:e,label:n}=Ha(t),r=l.get(e);r?r.sessions.push(t):l.set(e,{label:n,sessions:[t]})}let u=[...l.entries()].sort(([,e],[,t])=>{if(e.label===`(unknown)`)return 1;if(t.label===`(unknown)`)return-1;let n=Math.max(...e.sessions.map(Ua));return Math.max(...t.sessions.map(Ua))-n}),d=0,f=new Set;for(let[,e]of u){let l=Ba(e.label),u=`${l}/`,p=2;for(;f.has(u);)u=`${l} (${p})/`,p+=1;f.add(u);let m=u.slice(0,-1),h=new Map;t.set(u,d),t.set(m,d),d+=1,a.set(u,`${e.sessions.length}`),a.set(m,`${e.sessions.length}`);for(let t of e.sessions)h.set(t.title,(h.get(t.title)??0)+1);for(let a of e.sessions){let e=(h.get(a.title)??0)>1?`${Ba(a.title)} #${a.id.slice(0,8)}`:Ba(a.title),l=`${u}${e}`,f=2;for(;s.has(l);)l=`${u}${e} (${f})`,f+=1;s.add(l),c.push(l),t.set(l,d),d+=1,n.set(a.id,l),r.set(a.id,u),i.set(l,a.id),o.set(l,a)}}return{paths:c,sortOrderByPath:t,pathBySessionId:n,groupPathBySessionId:r,sessionIdByPath:i,groupCountByPath:a,sessionByPath:o}}function Ka({sessions:e,activeSessionId:t,selectedSessionId:n,onSelectSession:r,bookmarkedSessionIds:a,onToggleBookmark:s}){let c=(0,j.useMemo)(()=>Ga(e),[e]),l=(0,j.useRef)(c.sortOrderByPath),u=(0,j.useRef)(c.sessionIdByPath),d=(0,j.useRef)(c.groupCountByPath),f=(0,j.useRef)(c.sessionByPath),p=(0,j.useRef)(a),m=(0,j.useRef)(r),h=(0,j.useRef)(s),g={"--trees-bg-override":`transparent`,"--trees-border-color-override":`var(--console-border)`,"--trees-fg-override":`var(--console-text)`,"--trees-fg-muted-override":`var(--console-muted)`,"--trees-font-family-override":`"JetBrains Mono", "IBM Plex Mono", "SFMono-Regular", Menlo, Monaco, Consolas, monospace`,"--trees-font-size-override":`12px`,"--trees-item-margin-x-override":`0px`,"--trees-item-padding-x-override":`8px`,"--trees-selected-bg-override":`var(--console-surface-muted)`},{model:_}=o({flattenEmptyDirectories:!1,initialExpansion:`closed`,paths:c.paths,sort:(e,t)=>Wa(l.current,e,t),density:`compact`,unsafeCSS:za,onSelectionChange(e){let t=u.current.get(e[0]??``);t&&m.current(t)},renderRowDecoration({item:e}){let t=f.current.get(e.path);if(t){let e=p.current.has(t.id);return{text:e?`★`:`☆`,title:e?`Remove bookmark`:`Add bookmark`}}return d.current.get(e.path)?{text:d.current.get(e.path),title:`Sessions`}:null}});(0,j.useEffect)(()=>{l.current=c.sortOrderByPath,u.current=c.sessionIdByPath,d.current=c.groupCountByPath,f.current=c.sessionByPath,_.resetPaths(c.paths)},[_,c]),(0,j.useEffect)(()=>{m.current=r},[r]),(0,j.useEffect)(()=>{p.current=a,_.resetPaths(c.paths)},[a,_,c.paths]),(0,j.useEffect)(()=>{h.current=s},[s]);function ee(e){let t=e.nativeEvent.composedPath(),n=t.find(e=>e instanceof HTMLElement&&e.parentElement?.getAttribute(`data-item-section`)===`decoration`),r=t.find(e=>e instanceof HTMLElement&&e.getAttribute(`data-type`)===`item`),i=r?f.current.get(r.getAttribute(`data-item-path`)??``):null;!n||!i||(e.preventDefault(),e.stopPropagation(),h.current(i))}return(0,j.useEffect)(()=>{let e=c.pathBySessionId.get(t??``),r=c.pathBySessionId.get(n??``)??e,i=n??t??``,a=c.groupPathBySessionId.get(i);if(e&&_.getItem(e)?.select(),r&&t){let e=a?_.getItem(a):null;e&&`expand`in e&&e.expand(),_.focusPath(r);return}a&&_.focusPath(a)},[t,_,c,n]),(0,F.jsx)(`div`,{className:`session-tree h-[min(560px,calc(100vh-410px))] min-h-56 overflow-hidden`,style:g,onClickCapture:ee,children:(0,F.jsx)(i,{model:_,style:{height:`100%`},"aria-label":`Sessions`})})}function qa(e,t){return(t.time_updated??t.time_created)-(e.time_updated??e.time_created)}function Ja(e){return e.slug.split(`/`)[0]?.toLowerCase()||`unknown`}function Ya(e,t){return`${e.toLowerCase()}/${t}`}function Xa(e,t){return`${e}\0${t.toLowerCase()}`}function Za(e,t,n){let r=e.get(t);if(r){r.push(n);return}e.set(t,[n])}function Qa(e,t){let n=new Map,r=new Map,i=new Map,a=new Map,o=new Map,s=new Map,c=new Map,l=new Map,u=[],d=new Set(t.map(e=>e.name.toLowerCase()));for(let e of d)r.set(e,[]),s.set(e,[]);for(let t of e){let e=Ja(t),r={...t,agentKey:e,sessionSlug:t.id,fullPath:t.slug};u.push(r);let i=Ya(e,t.id);n.has(i)||n.set(i,t),d.has(e)&&s.get(e).push(r);let a=t.project_identity;if(!a?.key)continue;Za(c,Hi(a),r);let o=l.get(a.key);o?o.count+=1:l.set(a.key,{key:a.key,label:a.displayName||t.directory,count:1})}let f=e.toSorted(qa);for(let e of f){let t=Ja(e);d.has(t)&&r.get(t).push(e);let n=e.project_identity;if(!n?.key)continue;let s=Hi(n);Za(i,s,e),Za(a,Xa(s,t),e),Za(o,n.key,e)}return{byRouteKey:n,byAgent:r,byProjectIdentityKey:i,byProjectAgentKey:a,byProjectKey:o,byLandingAgent:s,byLandingProjectIdentityKey:c,landingSessions:u,sessionsByActivity:f,projectOptions:[...l.values()].toSorted((e,t)=>t.count-e.count).slice(0,8)}}function $a(e){let t=new Map,n=new Map;for(let r=0;r<e.length;r+=1){let i=e[r];t.has(i.id)||(t.set(i.id,i),n.set(i.id,r))}return{byId:t,indexById:n}}function eo(e,t){let n=e.replace(/^\/+|\/+$/g,``),r=n?n.split(`/`).map(e=>e.trim()).filter(Boolean):[];if(r.length===0)return{mode:`root`,activeAgentKey:null,activeSessionSlug:null};if(r[0]?.toLowerCase()===`projects`){if(r.length===1)return{mode:`projects`,activeAgentKey:null,activeSessionSlug:null};if(r.length===3)try{let e=decodeURIComponent(r[1]);return Vi(e)?{mode:`project`,activeAgentKey:null,activeSessionSlug:null,activeProjectKind:e,activeProjectKey:Ui(r[2])}:{mode:`invalidRoute`,activeAgentKey:null,activeSessionSlug:null}}catch{return{mode:`invalidRoute`,activeAgentKey:null,activeSessionSlug:null}}return{mode:`invalidRoute`,activeAgentKey:null,activeSessionSlug:null}}if(r.length===1){let e=r[0].toLowerCase();return t.has(e)?{mode:`agent`,activeAgentKey:e,activeSessionSlug:null}:{mode:`missingAgent`,activeAgentKey:null,activeSessionSlug:null,attemptedKey:e}}if(r.length===2){let e=r[0].toLowerCase(),n=r[1];return t.has(e)&&n?{mode:`session`,activeAgentKey:e,activeSessionSlug:n}:t.has(e)?{mode:`missingSession`,activeAgentKey:e,activeSessionSlug:n,attemptedSessionSlug:n}:{mode:`missingAgent`,activeAgentKey:null,activeSessionSlug:null,attemptedKey:e}}return{mode:`invalidRoute`,activeAgentKey:null,activeSessionSlug:null}}function to(e){let t=new Date(e);return`${t.getFullYear()}-${String(t.getMonth()+1).padStart(2,`0`)}-${String(t.getDate()).padStart(2,`0`)}`}function no(e){if(!e)return null;let{from:t,to:n,days:r}=e.window;if(t==null)return`All time`;let i=to(t),a=to(n??Date.now());return r?`Last ${r}d · ${i} → ${a}`:`${i} → ${a}`}function ro(e,t,n){return t?e?`Searching for "${e}"`:`Loading recent sessions`:e?`${n} matches for "${e}"`:`${n} recent sessions`}function io(e){if(!e?.active)return null;let t=e.completedAgents.length,n=e.totalAgents,r=e.scanningAgents[0],i=r?e.agentStatuses[r]:null,a=i?.total&&i.processed!=null?` · ${i.processed}/${i.total}`:``,o=n>0?r?` · ${r}${a} · ${t}/${n} agents ready`:` · ${t}/${n} agents ready`:``;return e.phase===`initializing`?`First-run setup: indexing all local sessions${o}. Your selected time window appears after this finishes.`:e.phase===`indexing`?`Preparing local session index`:n>0?r?`Checking for new or changed sessions · ${r}${a} · ${t}/${n} agents ready`:`Checking for new or changed sessions · ${t}/${n} agents ready`:`Checking for new or changed sessions`}function ao(e,t){let n=e?.agentStatuses[t];return!n||n.status===`complete`?null:n.total&&n.processed!=null?`${n.processed}/${n.total}`:n.status===`scanning`?`Scanning`:`Pending`}function oo(e,t,n){let r=e?.agentStatuses[t];return r?.status===`complete`&&r.sessions!=null?r.sessions:n}function so(e){return{kind:e.identityKind,key:e.identityKey}}function co(e){if(!e)return`unknown`;let t=Date.now()-e;if(Number.isNaN(t)||t<0)return`just now`;let 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 lo(e,t){return(t.time_updated??t.time_created)-(e.time_updated??e.time_created)}function uo(e,t){if(!t.changedSessionHeads||!t.removedSessionRefs)return null;let n=new Map(e.map(e=>[Ya(Ja(e),e.id),e]));for(let{agentName:e,sessionId:r}of t.removedSessionRefs)n.delete(Ya(e,r));for(let{agentName:e,session:r}of t.changedSessionHeads)n.set(Ya(e,r.id),r);return[...n.values()].sort(lo)}function fo(e){return e.replaceAll(`&`,`&amp;`).replaceAll(`<`,`&lt;`).replaceAll(`>`,`&gt;`).replaceAll(`"`,`&quot;`).replaceAll(`'`,`&#39;`).replaceAll(`&lt;mark&gt;`,`<mark>`).replaceAll(`&lt;/mark&gt;`,`</mark>`)}var po=`codesesh.shortcuts-hint-dismissed`,mo=[`bugfix`,`refactoring`,`feature-dev`,`testing`,`docs`,`git-ops`,`build-deploy`,`exploration`,`planning`],ho=[`apply_patch`,`bash`,`read`,`edit`,`grep`],go=[{kind:`read`,label:`Read`},{kind:`edit`,label:`Edit`},{kind:`write`,label:`Write`},{kind:`delete`,label:`Delete`}],_o=[{id:`paid`,label:`Cost > $0`,costMin:1e-6},{id:`one_plus`,label:`Cost >= $1`,costMin:1},{id:`ten_plus`,label:`Cost >= $10`,costMin:10}],vo={recent:`Recent`,title:`Title`,user_message:`User message`,assistant_reply:`Assistant reply`,tool_output:`Tool output`,file_path:`File path`},yo=[{title:`Navigation`,items:[{keys:`j / k`,description:`Move through sessions or search results`},{keys:`Enter`,description:`Open the current selection`},{keys:`g / G`,description:`Jump to the first or last item`}]},{title:`Search`,items:[{keys:`Cmd/Ctrl K`,description:`Open global search`},{keys:`/`,description:`Focus the search box`},{keys:`Esc`,description:`Exit search or close the current detail view`}]},{title:`Groups`,items:[{keys:`g / G`,description:`Jump to the first or last session`},{keys:`?`,description:`Open this shortcuts panel`}]}];function bo(e){if(!(e instanceof HTMLElement))return!1;let t=e.tagName.toLowerCase();return t===`input`||t===`textarea`||t===`select`||e.isContentEditable}function xo({value:e,onChange:t,projectsDisabled:n=!1}){return(0,F.jsx)(`div`,{role:`radiogroup`,"aria-label":`Browse by`,className:`grid gap-1.5`,children:[{value:`projects`,label:`Projects`},{value:`agents`,label:`Agents`}].map(r=>{let i=e===r.value,a=r.value===`projects`&&n;return(0,F.jsxs)(`button`,{type:`button`,role:`radio`,"aria-checked":i,disabled:a,onClick:()=>t(r.value),className:`console-mono flex items-center gap-2 rounded-sm border px-3 py-1.5 text-left text-xs transition-colors ${a?`cursor-not-allowed border-transparent text-[var(--console-muted)] opacity-45`:i?`border-[var(--console-border-strong)] bg-white text-[var(--console-text)]`:`border-transparent text-[var(--console-muted)] hover:border-[var(--console-border)] hover:bg-[var(--console-surface-muted)]`}`,title:a?`Project grouping is available after the current scan finishes`:void 0,children:[(0,F.jsx)(`span`,{className:`flex size-3 shrink-0 items-center justify-center rounded-full border ${i?`border-[var(--console-accent)]`:`border-[var(--console-border-strong)]`}`,children:i?(0,F.jsx)(`span`,{className:`size-1.5 rounded-full bg-[var(--console-accent)]`}):null}),(0,F.jsx)(`span`,{children:r.label})]},r.value)})})}function So({sessions:e,activeSessionId:t,selectedSessionId:n,bookmarkedSessionIds:r,onSelectSession:i,onToggleBookmark:a}){return(0,F.jsx)(`div`,{className:`console-scrollbar h-[min(560px,calc(100vh-410px))] min-h-56 overflow-y-auto`,children:(0,F.jsx)(`ul`,{className:`space-y-1`,children:e.map(e=>{let o=Ja(e),s=M.agents[o],c=t===e.id,l=n===e.id;return(0,F.jsx)(`li`,{children:(0,F.jsxs)(`div`,{className:`flex items-start gap-1 rounded-sm border px-2 py-1.5 transition-colors ${c||l?`border-[var(--console-border-strong)] bg-white text-[var(--console-text)]`:`border-transparent text-[var(--console-muted)] hover:border-[var(--console-border)] hover:bg-[var(--console-surface-muted)]`}`,children:[(0,F.jsxs)(`button`,{type:`button`,onClick:()=>i(e),className:`min-w-0 flex-1 text-left`,children:[(0,F.jsxs)(`span`,{className:`flex min-w-0 items-center gap-1.5`,children:[s?.icon?(0,F.jsx)(`img`,{src:s.icon,alt:s.name,className:`size-3.5 shrink-0 object-contain`}):null,(0,F.jsx)(`span`,{className:`console-mono line-clamp-1 text-xs text-[var(--console-text)]`,children:e.title})]}),(0,F.jsx)(`span`,{className:`console-mono mt-0.5 block truncate text-[10px] text-[var(--console-muted)]`,children:co(e.time_updated??e.time_created)})]}),(0,F.jsx)(vi,{active:r.has(e.id),onToggle:()=>a(e)})]})},e.slug)})})})}function Co(){let e=m(),[t,n]=(0,j.useState)([]),[r,i]=(0,j.useState)([]),[a,o]=(0,j.useState)([]),[s,c]=(0,j.useState)(!0),[l,u]=(0,j.useState)(null),[p,h]=(0,j.useState)(null),[g,_]=(0,j.useState)(!1),[ee,te]=(0,j.useState)(null),[ne,v]=(0,j.useState)(null),[y,re]=(0,j.useState)(null),[b,ie]=(0,j.useState)([]),[x,ae]=(0,j.useState)(`agents`),[oe,S]=(0,j.useState)(null),[se,ce]=(0,j.useState)(null),[le,ue]=(0,j.useState)(!1),[de,fe]=(0,j.useState)(null),[C,pe]=(0,j.useState)(void 0),[w,me]=(0,j.useState)(null),[T,he]=(0,j.useState)(``),[E,ge]=(0,j.useState)(``),[_e,ve]=(0,j.useState)(!1),[D,ye]=(0,j.useState)({}),[O,be]=(0,j.useState)([]),[xe,Se]=(0,j.useState)(!1),[k,Ce]=(0,j.useState)(null),[we,A]=(0,j.useState)(null),[Te,Ee]=(0,j.useState)(0),[De,Oe]=(0,j.useState)(!1),[ke,Ae]=(0,j.useState)(!0),je=(0,j.useRef)(null),Me=(0,j.useRef)(new Map);(0,j.useEffect)(()=>{let e=new AbortController,t=performance.now();return N(`app.load.start`,{path:window.location.pathname}),(async()=>{try{let e=await Ne();me(e);let[r,a,s,c,l,u]=await Promise.all([Fe(),Le({from:e.window.from,to:e.window.to}),ze(e.window).catch(e=>(console.error(`Failed to load dashboard:`,e),null)),Ie().catch(e=>(console.error(`Failed to load projects:`,e),{projects:[]})),Ve(),Pe().catch(e=>(console.error(`Failed to load scan status:`,e),null))]);n(r),i(a.sessions),ie(c.projects),o(l.bookmarks),u&&Ce(u),s&&re(s),N(`app.load.done`,{duration_ms:Math.round(performance.now()-t),agents:r.length,sessions:a.sessions.length,projects:c.projects.length,dashboard:!!s})}catch(e){console.error(`Failed to load data:`,e),N(`app.load.error`,{duration_ms:Math.round(performance.now()-t),error:e instanceof Error?e.message:String(e)}),u(`Failed to load data. Is the CLI server running?`)}finally{c(!1)}})(),()=>e.abort()},[]);let P=f(),Ke=(0,j.useMemo)(()=>new Set(t.map(e=>e.name.toLowerCase())),[t]),qe=(0,j.useMemo)(()=>new Map(t.map(e=>[e.name.toLowerCase(),e.displayName])),[t]),I=_e,L=(0,j.useMemo)(()=>eo(P.pathname,Ke),[P.pathname,Ke]);(0,j.useEffect)(()=>{N(`route.change`,{path:P.pathname,mode:L.mode,agent:L.activeAgentKey,session:L.activeSessionSlug})},[P.pathname,L.mode,L.activeAgentKey,L.activeSessionSlug]),(0,j.useEffect)(()=>{if(L.mode===`projects`||L.mode===`project`){ae(`projects`),L.mode===`project`&&S({kind:L.activeProjectKind,key:L.activeProjectKey});return}(L.mode===`agent`||L.mode===`missingAgent`)&&ae(`agents`)},[L]);let Ye=I?E:typeof P.state==`object`&&P.state!==null&&`searchQuery`in P.state&&typeof P.state.searchQuery==`string`?P.state.searchQuery:``,R=(0,j.useMemo)(()=>Qa(r,t),[r,t]);(0,j.useEffect)(()=>{let e=!1;return o(t=>{let n=zi(t,r);return n===t?t:(Ue(n.map(({bookmarked_at:e,...t})=>t)).catch(t=>{e||console.error(`Failed to sync bookmark snapshots:`,t)}),n)}),()=>{e=!0}},[r]),(0,j.useEffect)(()=>{let e=!1;return(async()=>{let t=Ii();if(t.length!==0)try{let n=await Ue(t.map(({bookmarked_at:e,...t})=>t));if(e)return;o(n.bookmarks),Li()}catch(t){e||console.error(`Failed to migrate legacy bookmarks:`,t)}})(),()=>{e=!0}},[]);let z=(0,j.useMemo)(()=>new Set(a.map(e=>Pi(e.agentKey,e.sessionId))),[a]);function Xe(e,t){return z.has(Pi(e,t))}function B(e){let t=Pi(e.agentKey,e.sessionId),n=z.has(t),r=a;o(n?r.filter(e=>Pi(e.agentKey,e.sessionId)!==t):[...r,e].toSorted((e,t)=>{let n=e.time_updated??e.time_created;return(t.time_updated??t.time_created)-n})),N(n?`bookmark.delete`:`bookmark.add`,{agent:e.agentKey,session:e.sessionId}),(n?We(e.agentKey,e.sessionId):He({agentKey:e.agentKey,sessionId:e.sessionId,fullPath:e.fullPath,title:e.title,directory:e.directory,time_created:e.time_created,time_updated:e.time_updated,stats:e.stats})).catch(e=>{console.error(`Failed to toggle bookmark:`,e),o(r)})}function V(e,t){B(Fi(e,t))}let H=L.activeAgentKey,Ze=L.mode===`project`?L.activeProjectKind:null,Qe=L.mode===`project`?L.activeProjectKey:null,$e=(0,j.useMemo)(()=>Ze&&Qe?{kind:Ze,key:Qe}:null,[Ze,Qe]),et=$e?Hi($e):null,tt=(0,j.useMemo)(()=>L.mode===`session`?R.byRouteKey.get(Ya(L.activeAgentKey,L.activeSessionSlug))??null:null,[R,L]),nt=(L.mode===`session`&&p?.id===L.activeSessionSlug?p:null)?.project_identity??tt?.project_identity??null,rt=x===`projects`?$e??(L.mode===`session`?nt:oe):null,it=rt?Hi(rt):null,at=(0,j.useMemo)(()=>H?R.byAgent.get(H)??[]:[],[H,R]),ot=(0,j.useMemo)(()=>it?C?R.byProjectAgentKey.get(Xa(it,C))??[]:R.byProjectIdentityKey.get(it)??[]:[],[C,it,R]),U=x===`projects`?ot:at,st=(0,j.useMemo)(()=>$a(U),[U]),W=(0,j.useMemo)(()=>U.length===0?new Set:new Set(U.filter(e=>z.has(Pi(Ja(e),e.id))).map(e=>e.id)),[z,U]),ct=(0,j.useMemo)(()=>a.toSorted((e,t)=>(t.time_updated??t.time_created)-(e.time_updated??e.time_created)),[a]),lt=(0,j.useMemo)(()=>{let e=_o.find(e=>e.id===D.costRange);return{agent:D.agent,projectKey:D.projectKey,tag:D.tag,tool:D.tool,fileKind:D.fileKind,costMin:e?.costMin}},[D]),ut=E.trim().length>0||!!(D.tool||D.fileKind),dt=io(k),ft=k?.active===!0,pt=(0,j.useMemo)(()=>{let e=_o.find(e=>e.id===D.costRange),t=D.agent?R.byAgent.get(D.agent)??[]:null,n=D.projectKey?R.byProjectKey.get(D.projectKey)??[]:null,r=t&&n?t.length<=n.length?t:n:t??n??R.sessionsByActivity,i=[];for(let t of r)if(!(D.agent&&Ja(t)!==D.agent)&&!(D.projectKey&&t.project_identity?.key!==D.projectKey)&&!(D.tag&&!t.smart_tags?.includes(D.tag))&&!(e&&t.stats.total_cost<e.costMin)&&(i.push({agentName:Ja(t),session:t,snippet:`Recent session · ${t.directory}`,matchType:`recent`}),i.length>=50))break;return i},[D,R]),mt=L.mode===`session`?`${L.activeAgentKey}/${L.activeSessionSlug}`:``,ht=(0,j.useEffectEvent)(async e=>{try{let t=!!(e.changedSessionHeads&&e.removedSessionRefs);t&&i(t=>uo(t,e)??t);let[r,a,o,s,c,l]=await Promise.all([Fe(),t?Promise.resolve(null):Le({from:w?.window.from,to:w?.window.to}),ze(w?.window).catch(e=>(console.error(`Failed to refresh dashboard:`,e),null)),Ie().catch(e=>(console.error(`Failed to refresh projects:`,e),{projects:[]})),L.mode===`project`?ze(w?.window,{projectKind:L.activeProjectKind,projectKey:L.activeProjectKey,agent:C}).catch(e=>(console.error(`Failed to refresh project dashboard:`,e),null)):Promise.resolve(null),I&&ut?Be(E,lt).catch(e=>(console.error(`Failed to refresh search results:`,e),{results:[]})):Promise.resolve(null)]);if(n(r),a&&i(a.sessions),ie(s.projects),o&&re(o),c&&ce(c),l&&be(l.results),L.mode===`session`)try{h(await Re(L.activeAgentKey,L.activeSessionSlug)),te(null)}catch{h(null),te(`Session not found`)}e.newSessions>0&&v(`发现 ${e.newSessions} 个新会话,列表已自动刷新`)}catch(e){console.error(`Failed to sync live session update:`,e)}});(0,j.useEffect)(()=>{if(!I){be([]),Se(!1);return}if(!ut){be(pt),Se(!1);return}let e=!1;Se(!0);let t=performance.now();return N(`search.start`,{query_length:E.length}),Be(E,lt).then(n=>{e||(be(n.results),N(`search.done`,{duration_ms:Math.round(performance.now()-t),results:n.results.length}))}).catch(n=>{e||(console.error(`Failed to load search results:`,n),N(`search.error`,{duration_ms:Math.round(performance.now()-t),error:n instanceof Error?n.message:String(n)}),be([]))}).finally(()=>{e||Se(!1)}),()=>{e=!0}},[E,I,pt,lt,ut]),(0,j.useEffect)(()=>{if(L.mode!==`session`){h(null),te(null);return}let e=new AbortController;_(!0),te(null);let t=performance.now();return N(`session.open.start`,{agent:L.activeAgentKey,session:L.activeSessionSlug}),(async()=>{try{let e=await Re(L.activeAgentKey,L.activeSessionSlug);h(e),N(`session.open.done`,{agent:L.activeAgentKey,session:L.activeSessionSlug,duration_ms:Math.round(performance.now()-t),messages:e.messages.length})}catch(e){N(`session.open.error`,{agent:L.activeAgentKey,session:L.activeSessionSlug,duration_ms:Math.round(performance.now()-t),error:e instanceof Error?e.message:String(e)}),te(`Session not found`),h(null)}finally{_(!1)}})(),()=>e.abort()},[mt,L.activeAgentKey,L.activeSessionSlug,L.mode]),(0,j.useEffect)(()=>{et&&pe(void 0)},[et]),(0,j.useEffect)(()=>{if(!Qe||!w){ce(null),fe(null),ue(!1);return}let e=!1;return ue(!0),fe(null),ze(w.window,{projectKind:Ze??void 0,projectKey:Qe,agent:C}).then(t=>{e||ce(t)}).catch(t=>{e||(console.error(`Failed to load project dashboard:`,t),ce(null),fe(`Failed to load project dashboard`))}).finally(()=>{e||ue(!1)}),()=>{e=!0}},[Ze,Qe,w,C]),(0,j.useEffect)(()=>Ge(e=>{ht(e)},e=>{Ce(e)}),[]),(0,j.useEffect)(()=>{if(!ne)return;let e=window.setTimeout(()=>{v(null)},3500);return()=>{window.clearTimeout(e)}},[ne]),(0,j.useEffect)(()=>{try{Ae(window.localStorage.getItem(po)===`1`)}catch{Ae(!0)}},[]),(0,j.useEffect)(()=>{if(I){Ee(e=>O.length===0?0:Math.min(e,O.length-1));return}if(L.mode===`session`){A(L.activeSessionSlug);return}if(L.mode===`agent`){A(null);return}A(null)},[I,O.length,L.mode,L.activeSessionSlug,U]),(0,j.useEffect)(()=>{if(!I)return;let e=O[Te];if(!e)return;let t=`${e.agentName}/${e.session.id}`;Me.current.get(t)?.scrollIntoView({block:`nearest`})},[I,O,Te]);let gt=R.landingSessions,_t=(0,j.useMemo)(()=>et?R.byLandingProjectIdentityKey.get(et)??[]:[],[et,R]),vt=(0,j.useMemo)(()=>t.filter(e=>e.count>0).map(e=>({key:e.name.toLowerCase(),name:e.displayName,icon:e.icon,count:e.count})),[t]),G=(0,j.useMemo)(()=>t.find(e=>e.name.toLowerCase()===H)??null,[H,t]),yt=(0,j.useMemo)(()=>b.find(e=>et===Hi(so(e)))??null,[et,b]),bt=(0,j.useMemo)(()=>b.find(e=>it===Hi(so(e)))??null,[b,it]),xt=R.projectOptions,St=(0,j.useMemo)(()=>{if(!ut)return xt;let e=new Map,t=xe?[]:O;for(let n of t){let t=n.session.project_identity;if(!t?.key)continue;let r=e.get(t.key);r?r.count+=1:e.set(t.key,{key:t.key,label:t.displayName||n.session.directory,count:1,showCount:!1})}if(D.projectKey&&!e.has(D.projectKey)){let t=xt.find(e=>e.key===D.projectKey);t&&e.set(t.key,{...t,count:0,showCount:!1})}return[...e.values()].toSorted((e,t)=>t.count-e.count).slice(0,8)},[xt,D.projectKey,xe,O,ut]),K=`CodeSesh`,q=`Select an agent to browse sessions`;if(L.mode===`root`&&(K=I?`Search`:`Dashboard`,q=I?ro(E,xe,O.length):y?`${y.totals.sessions.toLocaleString(`en-US`)} total sessions across ${y.perAgent.length} agents`:`Aggregated view across all agents`),L.mode===`projects`&&(K=`Projects`,q=`${b.length.toLocaleString(`en-US`)} projects across ${r.length.toLocaleString(`en-US`)} sessions`),L.mode===`project`&&(K=yt?.displayName??`Project`,q=yt?`${yt.sessionCount.toLocaleString(`en-US`)} sessions · ${yt.agentStats.length} agents`:L.activeProjectKey),L.mode===`agent`&&H&&(K=G?.displayName??H,q=`${U.length} sessions`),L.mode===`session`){if(ee)K=`Session Not Found`,q=`Requested /${H}/${L.activeSessionSlug}`;else if(p){K=p.title||`Conversation`;let e=p.time_updated??p.time_created;q=(0,F.jsxs)(F.Fragment,{children:[(0,F.jsxs)(`span`,{children:[`ID: #`,p.id.slice(0,8)]}),(0,F.jsx)(`span`,{children:`·`}),(0,F.jsxs)(`span`,{children:[`Updated `,co(e)]}),(0,F.jsx)(Je,{tags:p.smart_tags,limit:9,className:`inline-flex`})]})}}L.mode===`missingAgent`&&(K=`Agent Not Found`,q=`Requested /${L.attemptedKey}`),L.mode===`missingSession`&&(K=`Session Not Found`,q=`Session not found in /${H}`),I&&(K=`Search`,q=ro(E,xe,O.length));let Ct=(0,j.useMemo)(()=>{if(I)return[{label:`Search`}];let e={label:`Dashboard`,to:x===`agents`&&L.mode===`root`||x===`projects`&&L.mode===`projects`?void 0:x===`projects`?`/projects`:`/`};if(L.mode===`root`)return[{label:`Dashboard`}];let t={label:`Projects`,to:L.mode===`project`?`/projects`:void 0};if(L.mode===`projects`)return[e,{label:`Projects`}];if(L.mode===`project`)return[e,t,{label:yt?.displayName??L.activeProjectKey}];if(L.mode===`session`&&x===`projects`&&rt)return[e,{label:`Projects`,to:`/projects`},{label:bt?.displayName??rt.key,to:Wi(rt)},{label:p?.title||L.activeSessionSlug||`Conversation`}];if(L.mode===`missingAgent`)return[e,{label:L.attemptedKey}];let n=G?.displayName??H??`Unknown Agent`,r={label:n,to:L.mode===`session`?`/${H}`:void 0};return L.mode===`agent`?[e,{label:n}]:L.mode===`missingSession`?[e,r,{label:L.attemptedSessionSlug}]:L.mode===`session`?[e,r,{label:p?.title||L.activeSessionSlug||`Conversation`}]:[e,{label:`Invalid Route`}]},[G,H,yt,x,I,bt,rt,p?.title,L]),wt;wt=s?(0,F.jsx)(_i,{}):I?(0,F.jsx)(wo,{query:E,loading:xe,results:O,agentNameMap:qe,agents:t,projects:St,filters:D,onChangeFilters:ye,onOpenResult:()=>{ve(!1),ge(``)},selectedIndex:Te,registerResultRef:(e,t)=>{t?Me.current.set(e,t):Me.current.delete(e)}}):l?(0,F.jsx)(`div`,{className:`mx-auto max-w-4xl rounded-sm border border-[var(--console-error-border)] bg-[var(--console-error-bg)] p-6 text-sm text-[var(--console-error)]`,children:l}):L.mode===`root`?y?(0,F.jsx)(va,{data:y,projects:b,bookmarkedSessions:ct,isBookmarked:Xe,onToggleBookmark:(e,t)=>{if(`agentName`in e){V(e,t??e.agentName.toLowerCase());return}B(e)}}):(0,F.jsx)(ki,{type:`global`,sessions:gt,agentItems:vt,isBookmarked:Xe,onToggleBookmark:e=>V(e,e.agentKey)}):L.mode===`projects`?(0,F.jsx)(Da,{projects:b}):L.mode===`project`?(0,F.jsx)(ja,{project:yt,projectKey:L.activeProjectKey,dashboard:se,loading:le,error:de,sessions:_t,activeAgent:C,onChangeAgent:pe,isBookmarked:Xe,onToggleSessionBookmark:V}):L.mode===`agent`&&H?(0,F.jsx)(ki,{type:`agent`,sessions:R.byLandingAgent.get(H)??[],agentItems:vt,activeAgentKey:H,isBookmarked:Xe,onToggleBookmark:e=>V(e,e.agentKey)}):L.mode===`session`?g?(0,F.jsx)(_i,{}):ee||!p?(0,F.jsx)(ki,{type:`missing-session`,sessions:R.byLandingAgent.get(L.activeAgentKey)??[],agentItems:vt,activeAgentKey:L.activeAgentKey,attemptedSessionSlug:L.activeSessionSlug,isBookmarked:Xe,onToggleBookmark:e=>V(e,e.agentKey)}):(0,F.jsx)(ti,{session:p,highlightQuery:Ye}):L.mode===`missingAgent`?(0,F.jsx)(ki,{type:`missing-agent`,sessions:gt,agentItems:vt,attemptedAgentKey:L.attemptedKey,isBookmarked:Xe,onToggleBookmark:e=>V(e,e.agentKey)}):(0,F.jsx)(`div`,{className:`text-sm text-[var(--console-muted)]`,children:`Invalid route.`});function Tt(){ge(T.trim()),ve(!0),Ee(0)}function J(){Ae(!0);try{window.localStorage.setItem(po,`1`)}catch{}}function Et(t){if(!(t===`projects`&&ft)){if(ae(t),A(null),t===`projects`){let t=nt??(L.mode===`session`?null:oe);e(t?Wi(t):`/projects`);return}e(`/`)}}let Dt=(0,j.useEffectEvent)(t=>{let n=t.key;if((t.metaKey||t.ctrlKey)&&n.toLowerCase()===`k`){t.preventDefault(),ve(!0),Ee(0),window.setTimeout(()=>{je.current?.focus(),je.current?.select()},0);return}if(t.defaultPrevented||t.metaKey||t.ctrlKey||t.altKey||t.isComposing)return;let r=t.target,i=bo(r);if(De){n===`Escape`&&(t.preventDefault(),Oe(!1));return}if(i){n===`Escape`&&(t.preventDefault(),r instanceof HTMLElement&&r.blur());return}if(n===`?`){t.preventDefault(),Oe(!0),J();return}if(n===`/`){t.preventDefault(),J(),ve(!0),je.current?.focus(),je.current?.select();return}if(n===`Escape`){if(t.preventDefault(),I){ve(!1),ge(``),he(``);return}if(L.mode===`session`&&L.activeAgentKey){if(x===`projects`&&rt){e(Wi(rt));return}e(`/${L.activeAgentKey}`)}return}if(I){if(O.length===0)return;if(n===`j`){t.preventDefault(),J(),Ee(e=>Math.min(e+1,O.length-1));return}if(n===`k`){t.preventDefault(),J(),Ee(e=>Math.max(e-1,0));return}if(n===`g`){t.preventDefault(),J(),Ee(0);return}if(n===`G`){t.preventDefault(),J(),Ee(O.length-1);return}if(n===`Enter`){let n=O[Te];if(!n)return;t.preventDefault(),J(),ve(!1),ge(``),e(`/${n.agentName.toLowerCase()}/${n.session.id}`,{state:{searchQuery:E}})}return}if(x===`agents`&&!H||U.length===0)return;let a=e=>{J();let t=we==null?-1:st.indexById.get(we)??-1,n=t>=0?t:e>=0?-1:U.length;A(U[Math.max(0,Math.min(n+e,U.length-1))]?.id??null)};if(n===`j`){t.preventDefault(),a(1);return}if(n===`k`){t.preventDefault(),a(-1);return}if(n===`g`){t.preventDefault(),J(),A(U[0]?.id??null);return}if(n===`G`){t.preventDefault(),J(),A(U.at(-1)?.id??null);return}if(n===`Enter`){let n=we==null?null:st.byId.get(we);if(!n)return;t.preventDefault(),J(),e(x===`projects`?`/${n.slug}`:`/${H}/${n.id}`)}});return(0,j.useEffect)(()=>(window.addEventListener(`keydown`,Dt),()=>window.removeEventListener(`keydown`,Dt)),[]),(0,F.jsxs)(`div`,{className:`console-ui flex h-screen flex-col overflow-hidden bg-[var(--console-bg)] text-[var(--console-text)]`,children:[(0,F.jsx)(`header`,{className:`shrink-0 border-b border-[var(--console-border)] bg-white/85 backdrop-blur-sm`,children:(0,F.jsxs)(`div`,{className:`grid min-h-14 grid-cols-[auto_1fr] items-center gap-3 px-4 py-2 sm:grid-cols-[auto_1fr_auto] sm:py-0`,children:[(0,F.jsxs)(d,{to:`/`,className:`flex items-center gap-2 text-[var(--console-text)]`,children:[(0,F.jsx)(`img`,{src:`/logo.svg?v=3`,alt:`CodeSesh`,className:`h-6 w-6 rounded-sm`}),(0,F.jsx)(`span`,{className:`console-mono text-sm font-semibold uppercase tracking-[0.05em]`,children:`CodeSesh`})]}),(0,F.jsxs)(`form`,{className:`order-3 col-span-2 flex w-full items-center justify-center gap-2 sm:order-none sm:col-span-1 sm:mx-auto sm:max-w-[560px]`,onSubmit:e=>{e.preventDefault(),Tt()},children:[(0,F.jsx)(`label`,{className:`flex min-w-0 flex-1 items-center rounded-sm border border-[var(--console-border)] bg-white px-2 py-1`,children:(0,F.jsx)(`input`,{ref:je,value:T,onChange:e=>he(e.target.value),placeholder:`Search sessions /`,className:`console-mono w-full min-w-0 bg-transparent text-xs text-[var(--console-text)] outline-none placeholder:text-[var(--console-muted)]`})}),(0,F.jsx)(`button`,{type:`submit`,className:`console-mono rounded-sm border border-[var(--console-border-strong)] bg-[var(--console-surface-muted)] px-3 py-1 text-xs text-[var(--console-text)] transition-colors hover:bg-white`,children:`Search`})]}),(0,F.jsxs)(`div`,{className:`flex items-center justify-end gap-2`,children:[(0,F.jsxs)(`button`,{type:`button`,onClick:()=>{Oe(!0),J()},className:`console-mono rounded-sm border border-[var(--console-border)] bg-white px-2 py-1 text-xs text-[var(--console-text)] transition-colors hover:bg-[var(--console-surface-muted)]`,title:`Show keyboard shortcuts`,children:[`?`,(0,F.jsx)(`span`,{className:`hidden sm:inline`,children:` Shortcuts`})]}),no(w)?(0,F.jsx)(`span`,{className:`console-mono hidden rounded-sm border border-[var(--console-border)] bg-white px-2 py-1 text-xs text-[var(--console-text)] md:inline-flex`,title:`Time window applied to agent counts, dashboard, and session list`,children:no(w)}):null,(0,F.jsxs)(`span`,{className:`console-mono hidden rounded-sm border border-[var(--console-border)] bg-[var(--console-surface-muted)] px-2 py-1 text-xs text-[var(--console-muted)] sm:inline-flex`,children:[`v`,`0.7.0`]})]})]})}),(0,F.jsxs)(`div`,{className:`flex min-h-0 flex-1`,children:[(0,F.jsx)(`aside`,{className:`hidden w-64 shrink-0 flex-col border-r border-[var(--console-border)] bg-[var(--console-sidebar-bg)] lg:flex`,children:(0,F.jsxs)(`div`,{className:`console-scrollbar flex-1 space-y-8 overflow-y-auto px-4 py-6`,children:[(0,F.jsxs)(`section`,{children:[(0,F.jsx)(`h3`,{className:`console-mono mb-3 text-xs font-bold uppercase text-[var(--console-text)]`,children:`BROWSE BY`}),(0,F.jsx)(xo,{value:x,onChange:Et,projectsDisabled:ft})]}),(0,F.jsxs)(`section`,{children:[(0,F.jsx)(`h3`,{className:`console-mono mb-3 text-xs font-bold uppercase text-[var(--console-text)]`,children:`NAVIGATION`}),(0,F.jsxs)(`ul`,{className:`space-y-1 ${x===`projects`?`console-scrollbar max-h-[min(280px,calc(100vh-440px))] overflow-y-auto pr-1`:``}`,children:[(0,F.jsx)(`li`,{children:(0,F.jsxs)(d,{to:x===`projects`?`/projects`:`/`,className:`flex items-center gap-2 rounded-sm border px-3 py-1.5 text-left transition-colors ${x===`agents`&&L.mode===`root`||x===`projects`&&L.mode===`projects`?`border-[var(--console-border-strong)] bg-white text-[var(--console-text)]`:`border-transparent text-[var(--console-muted)] hover:border-[var(--console-border)] hover:bg-[var(--console-surface-muted)]`}`,children:[(0,F.jsx)(`img`,{src:`/logo.svg?v=3`,alt:`Dashboard`,className:`size-3.5 rounded-[2px]`}),(0,F.jsx)(`span`,{className:`console-mono line-clamp-1 flex-1 text-xs`,children:`Dashboard`})]})}),x===`agents`?t.map(e=>{let t=e.name.toLowerCase(),n=t===H,r=M.agents[t],i=ao(k,e.name),a=ft&&i!==null,o=`ml-4 flex items-center gap-2 rounded-sm border px-3 py-1.5 text-left transition-colors ${a?`cursor-not-allowed border-transparent text-[var(--console-muted)] opacity-50`:n?`border-[var(--console-border-strong)] bg-white text-[var(--console-text)]`:`border-transparent text-[var(--console-muted)] hover:border-[var(--console-border)] hover:bg-[var(--console-surface-muted)]`}`,s=(0,F.jsxs)(F.Fragment,{children:[r?.icon&&(0,F.jsx)(`img`,{src:r.icon,alt:e.displayName,className:`size-3.5 object-contain`}),(0,F.jsx)(`span`,{className:`console-mono line-clamp-1 flex-1 text-xs`,children:e.displayName}),(0,F.jsx)(`span`,{className:`console-mono text-[11px] text-[var(--console-muted)]`,children:i??oo(k,e.name,e.count)})]});return(0,F.jsxs)(`li`,{children:[a?(0,F.jsx)(`span`,{className:o,title:`Available after this agent scan completes`,children:s}):(0,F.jsx)(d,{to:`/${t}`,className:o,children:s}),i?(0,F.jsx)(`span`,{className:`ml-4 mt-1 block h-1 overflow-hidden rounded-sm bg-[var(--console-surface-muted)]`,children:(0,F.jsx)(`span`,{className:`block h-full bg-[var(--console-accent)]`,style:{width:`${k?.agentStatuses[e.name]?.total?Math.round((k.agentStatuses[e.name]?.processed??0)/k.agentStatuses[e.name].total*100):8}%`}})}):null]},e.name)}):b.map(e=>{let t=so(e),n=it===Hi(t);return(0,F.jsx)(`li`,{children:(0,F.jsxs)(d,{to:Wi(t),onClick:()=>S(t),className:`ml-4 flex min-w-0 items-center gap-2 rounded-sm border px-3 py-1.5 text-left transition-colors ${n?`border-[var(--console-border-strong)] bg-white text-[var(--console-text)]`:`border-transparent text-[var(--console-muted)] hover:border-[var(--console-border)] hover:bg-[var(--console-surface-muted)]`}`,children:[(0,F.jsx)(`span`,{className:`console-mono min-w-0 flex-1 truncate text-xs`,children:e.displayName}),(0,F.jsx)(`span`,{className:`console-mono shrink-0 text-[11px] text-[var(--console-muted)]`,children:e.sessionCount})]})},`${e.identityKind}:${e.identityKey}`)}),x===`agents`&&t.length===0&&!s?(0,F.jsx)(`li`,{children:(0,F.jsx)(`span`,{className:`console-mono block rounded-sm px-3 py-1.5 text-xs text-[var(--console-muted)]`,children:k?.active?`Scanning agents...`:`No agents found`})}):null,x===`projects`&&b.length===0&&!s?(0,F.jsx)(`li`,{children:(0,F.jsx)(`span`,{className:`console-mono block rounded-sm px-3 py-1.5 text-xs text-[var(--console-muted)]`,children:k?.active?`Scanning projects...`:`No projects found`})}):null]})]}),(0,F.jsxs)(`section`,{children:[(0,F.jsx)(`h3`,{className:`console-mono mb-3 text-xs font-bold uppercase text-[var(--console-text)]`,children:`BOOKMARKS`}),ct.length===0?(0,F.jsx)(`span`,{className:`console-mono block rounded-sm px-3 py-1.5 text-xs text-[var(--console-muted)]`,children:`No bookmarks yet`}):(0,F.jsx)(`ul`,{className:`space-y-1`,children:ct.map(e=>{let t=L.mode===`session`&&L.activeAgentKey===e.agentKey&&L.activeSessionSlug===e.sessionId,n=M.agents[e.agentKey];return(0,F.jsx)(`li`,{children:(0,F.jsxs)(`div`,{className:`flex items-start gap-2 rounded-sm border px-2 py-1.5 transition-colors ${t?`border-[var(--console-border-strong)] bg-white text-[var(--console-text)]`:`border-transparent text-[var(--console-muted)] hover:border-[var(--console-border)] hover:bg-[var(--console-surface-muted)]`}`,children:[(0,F.jsxs)(d,{to:`/${e.fullPath}`,className:`flex min-w-0 flex-1 items-start gap-2`,children:[n?.icon?(0,F.jsx)(`img`,{src:n.icon,alt:n.name,className:`mt-0.5 size-3.5 shrink-0 object-contain`}):null,(0,F.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,F.jsx)(`span`,{className:`console-mono line-clamp-1 block text-xs`,children:e.title}),(0,F.jsx)(`span`,{className:`console-mono mt-0.5 line-clamp-1 block text-[10px] text-[var(--console-muted)]`,children:n?.name??e.agentKey})]})]}),(0,F.jsx)(vi,{active:!0,onToggle:()=>B(e)})]})},Pi(e.agentKey,e.sessionId))})})]}),(0,F.jsxs)(`section`,{children:[(0,F.jsxs)(`h3`,{className:`console-mono mb-3 text-xs font-bold uppercase text-[var(--console-text)]`,children:[`SESSIONS`,U.length>0?(0,F.jsx)(`span`,{className:`ml-2 text-[10px] font-normal text-[var(--console-muted)]`,children:`Navigate j k · Open Enter`}):null]}),x===`agents`&&!H?(0,F.jsx)(`span`,{className:`console-mono block rounded-sm px-3 py-1.5 text-xs text-[var(--console-muted)]`,children:`Select an agent`}):x===`projects`&&!it?(0,F.jsx)(`span`,{className:`console-mono block rounded-sm px-3 py-1.5 text-xs text-[var(--console-muted)]`,children:`Select a project`}):U.length===0?(0,F.jsx)(`span`,{className:`console-mono block rounded-sm px-3 py-1.5 text-xs text-[var(--console-muted)]`,children:k?.active?`Scanning sessions...`:`No sessions yet`}):x===`projects`?(0,F.jsx)(So,{sessions:U,activeSessionId:L.mode===`session`?L.activeSessionSlug:null,selectedSessionId:we,bookmarkedSessionIds:W,onSelectSession:t=>{A(t.id),e(`/${t.slug}`)},onToggleBookmark:e=>V(e,Ja(e))}):(0,F.jsx)(Ka,{sessions:U,activeSessionId:L.mode===`session`?L.activeSessionSlug:null,selectedSessionId:we,onSelectSession:t=>{A(t);let n=st.byId.get(t);n&&e(`/${n.slug}`)},bookmarkedSessionIds:W,onToggleBookmark:e=>V(e,Ja(e))})]})]})}),(0,F.jsxs)(`main`,{className:`flex min-w-0 flex-1 flex-col`,children:[(0,F.jsx)(`section`,{className:`shrink-0 border-b border-[var(--console-border)] bg-white/70 px-4 py-4 backdrop-blur-sm md:px-8`,children:(0,F.jsxs)(`div`,{children:[(0,F.jsx)(`nav`,{"aria-label":`Breadcrumb`,className:`console-mono mb-2 flex flex-wrap items-center gap-1 text-[11px] text-[var(--console-muted)]`,children:Ct.map((e,t)=>(0,F.jsxs)(`span`,{className:`flex items-center gap-1`,children:[e.to?(0,F.jsx)(d,{to:e.to,className:`transition-colors hover:text-[var(--console-text)]`,children:e.label}):(0,F.jsx)(`span`,{className:`text-[var(--console-text)]`,children:e.label}),t<Ct.length-1?(0,F.jsx)(`span`,{children:`/`}):null]},`${e.label}-${t}`))}),(0,F.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,F.jsx)(`span`,{className:`console-mono rounded-sm border border-[var(--console-border)] bg-[var(--console-surface-muted)] px-1.5 py-0.5 text-[10px] font-bold uppercase text-[var(--console-muted)]`,children:L.mode===`session`?`Session`:L.mode===`root`?`Dashboard`:L.mode===`projects`?`Projects`:L.mode===`project`?`Project`:`Landing`}),(0,F.jsx)(`h1`,{className:`console-mono text-xl font-semibold tracking-tight text-[var(--console-text)]`,children:K})]}),(0,F.jsx)(`div`,{className:`console-mono mt-1 flex flex-wrap items-center gap-x-2 gap-y-1 text-xs text-[var(--console-muted)]`,children:q}),(0,F.jsxs)(`div`,{className:`mt-2 flex flex-wrap items-center gap-2`,children:[ke?null:(0,F.jsxs)(`div`,{className:`console-mono inline-flex items-center gap-2 rounded-sm border border-[var(--console-border)] bg-[var(--console-surface-muted)] px-2 py-1 text-[11px] text-[var(--console-text)]`,children:[(0,F.jsx)(`span`,{children:`Keyboard navigation available`}),(0,F.jsx)(`span`,{className:`rounded-sm border border-[var(--console-border)] bg-white px-1`,children:`?`}),(0,F.jsx)(`button`,{type:`button`,onClick:J,className:`text-[var(--console-muted)] transition-colors hover:text-[var(--console-text)]`,"aria-label":`Dismiss keyboard shortcuts hint`,children:`×`})]}),!I&&L.mode===`session`?(0,F.jsx)(`span`,{className:`console-mono inline-flex rounded-sm border border-[var(--console-border)] bg-[var(--console-surface-muted)] px-2 py-1 text-[11px] text-[var(--console-muted)]`,children:`Esc back`}):null,!I&&L.mode===`session`&&p?(0,F.jsx)(Ra,{agentName:L.activeAgentKey,sessionId:p.id,directory:p.directory}):null]}),ne?(0,F.jsx)(`p`,{className:`console-mono mt-2 inline-flex rounded-sm border border-[var(--console-border)] bg-[var(--console-surface-muted)] px-2 py-1 text-[11px] text-[var(--console-text)]`,children:ne}):null,dt&&L.mode===`root`?(0,F.jsx)(`p`,{className:`console-mono mt-2 inline-flex max-w-4xl rounded-sm border border-[var(--console-warning-border)] bg-[var(--console-warning-bg)] px-2 py-1 text-[11px] leading-relaxed text-[var(--console-warning)]`,children:dt}):null]})}),(0,F.jsx)(`section`,{className:`console-scrollbar bg-grid min-h-0 flex-1 overflow-y-auto px-4 py-6 md:px-8`,children:(0,F.jsx)(Ma,{children:wt})})]})]}),De?(0,F.jsx)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/35 px-4`,onClick:()=>Oe(!1),children:(0,F.jsxs)(`div`,{role:`dialog`,"aria-modal":`true`,"aria-label":`Keyboard shortcuts`,className:`w-full max-w-2xl rounded-sm border border-[var(--console-border-strong)] bg-white p-5 shadow-2xl`,onClick:e=>e.stopPropagation(),children:[(0,F.jsxs)(`div`,{className:`flex items-start justify-between gap-4`,children:[(0,F.jsxs)(`div`,{children:[(0,F.jsx)(`p`,{className:`console-mono text-[11px] uppercase tracking-[0.16em] text-[var(--console-muted)]`,children:`Keyboard Shortcuts`}),(0,F.jsx)(`h2`,{className:`console-mono mt-2 text-xl font-semibold text-[var(--console-text)]`,children:`Navigate without leaving the keyboard`})]}),(0,F.jsx)(`button`,{type:`button`,onClick:()=>Oe(!1),className:`console-mono rounded-sm border border-[var(--console-border)] bg-[var(--console-surface-muted)] px-2 py-1 text-xs text-[var(--console-text)] transition-colors hover:bg-white`,children:`Esc`})]}),(0,F.jsx)(`div`,{className:`mt-5 grid gap-4 md:grid-cols-3`,children:yo.map(e=>(0,F.jsxs)(`div`,{className:`rounded-sm border border-[var(--console-border)] bg-[var(--console-surface-muted)] p-4`,children:[(0,F.jsx)(`h3`,{className:`console-mono text-xs font-bold uppercase text-[var(--console-text)]`,children:e.title}),(0,F.jsx)(`div`,{className:`mt-3 space-y-3`,children:e.items.map(e=>(0,F.jsxs)(`div`,{children:[(0,F.jsx)(`p`,{className:`console-mono text-xs text-[var(--console-text)]`,children:e.keys}),(0,F.jsx)(`p`,{className:`mt-1 text-sm leading-6 text-[var(--console-muted)]`,children:e.description})]},e.keys))})]},e.title))})]})}):null]})}function wo({query:e,loading:t,results:n,agentNameMap:r,agents:i,projects:a,filters:o,onChangeFilters:s,onOpenResult:c,selectedIndex:l,registerResultRef:u}){let f=(0,F.jsx)(To,{agents:i,projects:a,filters:o,onChangeFilters:s});return t?(0,F.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[f,(0,F.jsx)(`div`,{className:`grid gap-3`,children:Array.from({length:4}).map((e,t)=>(0,F.jsxs)(`div`,{className:`animate-pulse rounded-sm border border-[var(--console-border)] bg-white/80 p-4`,children:[(0,F.jsx)(`div`,{className:`h-3 w-32 rounded bg-[var(--console-surface-muted)]`}),(0,F.jsx)(`div`,{className:`mt-3 h-4 w-2/3 rounded bg-[var(--console-surface-muted)]`}),(0,F.jsx)(`div`,{className:`mt-2 h-3 w-full rounded bg-[var(--console-surface-muted)]`}),(0,F.jsx)(`div`,{className:`mt-1 h-3 w-5/6 rounded bg-[var(--console-surface-muted)]`})]},t))})]}):n.length===0?(0,F.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[f,(0,F.jsxs)(`div`,{className:`rounded-sm border border-[var(--console-border)] bg-white/80 p-6`,children:[(0,F.jsx)(`h2`,{className:`console-mono text-sm font-semibold text-[var(--console-text)]`,children:e?`No matches`:`No recent sessions`}),e?(0,F.jsxs)(`p`,{className:`console-mono mt-2 text-xs text-[var(--console-muted)]`,children:[`Query: `,e]}):null]})]}):(0,F.jsxs)(`div`,{className:`grid gap-3`,children:[f,(0,F.jsx)(`div`,{className:`console-mono text-[11px] text-[var(--console-muted)]`,children:`Navigate j k · Open Enter · Exit Esc`}),n.map((t,n)=>{let i=t.agentName.toLowerCase(),a=r.get(i)??t.agentName,o=`${t.agentName}/${t.session.id}`;return(0,F.jsxs)(d,{ref:e=>u(o,e),to:`/${i}/${t.session.id}`,state:{searchQuery:e},onClick:c,className:`rounded-sm border bg-white/85 p-4 transition-colors hover:border-[var(--console-border-strong)] hover:bg-white ${n===l?`border-[var(--console-border-strong)]`:`border-[var(--console-border)]`}`,children:[(0,F.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,F.jsx)(`span`,{className:`console-mono rounded-sm border border-[var(--console-border)] bg-[var(--console-surface-muted)] px-1.5 py-0.5 text-[10px] uppercase text-[var(--console-muted)]`,children:a}),(0,F.jsx)(`span`,{className:`console-mono rounded-sm border border-[var(--console-border)] bg-white px-1.5 py-0.5 text-[10px] uppercase text-[var(--console-muted)]`,children:vo[t.matchType]}),(0,F.jsx)(`span`,{className:`console-mono text-[11px] text-[var(--console-muted)]`,children:t.session.directory})]}),(0,F.jsx)(`h2`,{className:`console-mono mt-3 text-sm font-semibold text-[var(--console-text)]`,children:t.session.title}),(0,F.jsx)(Je,{tags:t.session.smart_tags,className:`mt-2`}),(0,F.jsx)(`p`,{className:`console-mono mt-2 text-xs leading-6 text-[var(--console-muted)] [&_mark]:bg-[var(--console-accent)] [&_mark]:px-0.5 [&_mark]:text-white`,dangerouslySetInnerHTML:{__html:fo(t.snippet||t.session.title)}})]},o)})]})}function To({agents:e,projects:t,filters:n,onChangeFilters:r}){let i=Object.values(n).some(Boolean),a=(e,t)=>{r(n=>({...n,[e]:n[e]===t?void 0:t}))};return(0,F.jsxs)(`div`,{className:`rounded-sm border border-[var(--console-border)] bg-white/85 p-3`,children:[(0,F.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,F.jsx)(`span`,{className:`console-mono text-[10px] font-semibold uppercase text-[var(--console-muted)]`,children:`Scope`}),(0,F.jsx)(Eo,{active:!n.projectKey,label:`All`,onClick:()=>r(e=>({...e,projectKey:void 0}))}),t.map(e=>(0,F.jsx)(Eo,{active:n.projectKey===e.key,label:e.showCount===!1?e.label:`${e.label} · ${e.count}`,onClick:()=>a(`projectKey`,e.key)},e.key))]}),(0,F.jsxs)(`div`,{className:`mt-3 flex flex-wrap items-center gap-2`,children:[(0,F.jsx)(`span`,{className:`console-mono text-[10px] font-semibold uppercase text-[var(--console-muted)]`,children:`Agent`}),(0,F.jsx)(Eo,{active:!n.agent,label:`All Agents`,onClick:()=>r(e=>({...e,agent:void 0}))}),e.map(e=>(0,F.jsx)(Eo,{active:n.agent===e.name,label:e.displayName,onClick:()=>a(`agent`,e.name)},e.name))]}),(0,F.jsxs)(`div`,{className:`mt-3 flex flex-wrap items-center gap-2`,children:[(0,F.jsx)(`span`,{className:`console-mono text-[10px] font-semibold uppercase text-[var(--console-muted)]`,children:`Tag`}),mo.map(e=>(0,F.jsx)(Eo,{active:n.tag===e,label:Ke[e],onClick:()=>a(`tag`,e)},e))]}),(0,F.jsxs)(`div`,{className:`mt-3 flex flex-wrap items-center gap-2`,children:[(0,F.jsx)(`span`,{className:`console-mono text-[10px] font-semibold uppercase text-[var(--console-muted)]`,children:`Signal`}),ho.map(e=>(0,F.jsx)(Eo,{active:n.tool===e,label:`tool:${e}`,onClick:()=>a(`tool`,e)},e))]}),(0,F.jsxs)(`div`,{className:`mt-3 flex flex-wrap items-center gap-2`,children:[(0,F.jsx)(`span`,{className:`console-mono text-[10px] font-semibold uppercase text-[var(--console-muted)]`,children:`File Activity`}),go.map(e=>(0,F.jsx)(Eo,{active:n.fileKind===e.kind,label:e.label,onClick:()=>a(`fileKind`,e.kind)},e.kind))]}),(0,F.jsxs)(`div`,{className:`mt-3 flex flex-wrap items-center gap-2`,children:[(0,F.jsx)(`span`,{className:`console-mono text-[10px] font-semibold uppercase text-[var(--console-muted)]`,children:`Cost Range`}),(0,F.jsx)(Eo,{active:!n.costRange,label:`Any Cost`,onClick:()=>r(e=>({...e,costRange:void 0}))}),_o.map(e=>(0,F.jsx)(Eo,{active:n.costRange===e.id,label:e.label,onClick:()=>a(`costRange`,e.id)},e.id)),i?(0,F.jsx)(`button`,{type:`button`,onClick:()=>r({}),className:`console-mono ml-auto rounded-sm border border-[var(--console-border)] bg-[var(--console-surface-muted)] px-2 py-1 text-[10px] text-[var(--console-muted)] transition-colors hover:bg-white`,children:`Clear`}):null]})]})}function Eo({active:e,label:t,onClick:n}){return(0,F.jsx)(`button`,{type:`button`,onClick:n,className:`console-mono rounded-sm border px-2 py-1 text-[10px] transition-colors ${e?`border-[var(--console-border-strong)] bg-[var(--console-accent)] text-white`:`border-[var(--console-border)] bg-[var(--console-surface-muted)] text-[var(--console-muted)] hover:bg-white`}`,children:t})}Me.createRoot(document.getElementById(`root`)).render((0,F.jsx)(j.StrictMode,{children:(0,F.jsx)(ie,{children:(0,F.jsx)(Co,{})})}));