codesesh 0.10.0 → 0.11.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,113 @@
1
+ import{r as e}from"./rolldown-runtime-QTnfLwEv.js";import{l as t,t as n,u as r}from"./markdown-Bm__FT1K.js";import{n as i,r as a,t as o}from"./react-CGUTVnhO.js";import{A as s,B as c,C as l,D as u,E as d,F as f,I as p,L as m,M as h,N as g,O as _,P as v,R as y,S as ee,T as b,_ as te,a as x,b as ne,c as S,d as re,f as C,g as ie,h as ae,i as w,j as oe,k as se,l as ce,m as le,n as ue,o as de,p as fe,r as pe,s as T,t as me,u as he,v as ge,w as E,x as _e,y as ve,z as ye}from"./vendor-CR3FdUHs.js";import{C as D,S as O,_ as be,a as k,b as xe,c as Se,d as Ce,f as A,g as we,h as Te,i as Ee,l as De,m as Oe,n as ke,o as Ae,p as je,r as Me,s as Ne,t as Pe,u as Fe,v as Ie,x as Le,y as Re}from"./syntax-Cjw-OADI.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),ze=e(a(),1),M={agents:{opencode:{name:`OpenCode`,icon:`/icon/agent/opencode.svg`},zcode:{name:`ZCode`,icon:`/icon/agent/zcode.svg`},codex:{name:`Codex`,icon:`/icon/agent/codex.svg`},pi:{name:`Pi`,icon:`/icon/agent/pi.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 Be(){let e=await fetch(`/api/config`);if(!e.ok)throw Error(`Failed to fetch config`);return e.json()}async function Ve(){let e=await fetch(`/api/status`);if(!e.ok)throw Error(`Failed to fetch scan status`);return e.json()}async function He(){let e=await fetch(`/api/agents`);if(!e.ok)throw Error(`Failed to fetch agents`);return e.json()}async function Ue(){let e=await fetch(`/api/projects`);if(!e.ok)throw Error(`Failed to fetch projects`);return e.json()}async function We(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 Ge(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 Ke(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 qe(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 Je(){let e=await fetch(`/api/bookmarks`);if(!e.ok)throw Error(`Failed to fetch bookmarks`);return e.json()}async function Ye(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 Xe(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 Ze(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 Qe(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()}}var P=t(),F={bugfix:`bugfix`,refactoring:`refactoring`,"feature-dev":`feature-dev`,testing:`testing`,docs:`docs`,"git-ops":`git-ops`,"build-deploy":`build-deploy`,exploration:`exploration`,planning:`planning`},I={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 $e(e){return I[e]}function L(e){let t=$e(e);return{color:t.text,borderColor:t.border,backgroundColor:t.background}}function et({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,P.jsxs)(`div`,{className:`flex flex-wrap gap-1 ${n}`,children:[r.map(e=>(0,P.jsx)(`span`,{className:`console-mono rounded-sm border px-1.5 py-0.5 text-[10px] font-medium`,style:L(e),children:F[e]},e)),i>0?(0,P.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 tt(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,nt=5,B=270,V=500,rt=2;function it(e){return Math.round(e??0).toLocaleString(`en-US`)}function at(e){return`$${(e??0).toFixed(4)}`}function ot(e){return new Date(e).toLocaleString(`en-US`,{month:`short`,day:`2-digit`,hour:`2-digit`,minute:`2-digit`})}function st(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 ct(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 lt(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 ut(e){return!e||e.length===0?`SESSION ACTIVITY RECEIPT`:e.map(e=>F[e]).join(` / `)}function dt(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:lt(t)}}function H(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 ft(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 pt(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(ft(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]=ft(e,a[a.length-1]??``,n)),a.slice(0,r)}function mt(e){let t=document.createElement(`canvas`);t.width=B*rt,t.height=V*rt;let n=t.getContext(`2d`);if(!n)return t;n.scale(rt,rt);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=ct(st(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(ft(n,ut(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`,H(n,`Agent`,e.agent,88,B),H(n,`Updated`,ot(e.updatedAt),104,B),H(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=it(t.count);n.fillText(ft(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,H(n,`Input tokens`,it(e.stats.total_input_tokens),a,B),a+=16,H(n,`Output tokens`,it(e.stats.total_output_tokens),a,B),a+=16,H(n,`Messages`,it(e.stats.message_count),a,B),a+=22,n.font=`700 13px 'Courier New', monospace`,H(n,`TOTAL COST`,at(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)`,pt(n,e.title,B-36,2).forEach((e,t)=>{n.fillText(e,B/2,a+38+t*13)}),t}function U(e,t){return e*R+t}function ht(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=U(e,t);t<R-1&&l(n,U(e,t+1),.98),e<z-1&&l(n,U(e+1,t),.92),e<z-1&&t<R-1&&(l(n,U(e+1,t+1),.46),l(U(e+1,t),U(e,t+1),.46)),t<R-2&&l(n,U(e,t+2),.35),e<z-2&&l(n,U(e+2,t),.28)}return{particles:s,constraints:c,receiptWidth:t,receiptHeight:n}}function gt(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 _t(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 vt(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 yt(e,t,n,r,i){let a=n[U(r,i)],o=n[U(r,i+1)],s=n[U(r+1,i)],c=n[U(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 bt(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 xt({session:e,toc:t,minWidthQuery:n=`(min-width: 1025px)`}){let r=(0,j.useRef)(null),i=(0,j.useRef)(null),a=(0,j.useRef)(null),o=(0,j.useMemo)(()=>dt(e,t),[e,t]);return(0,j.useLayoutEffect)(()=>{let e=r.current,t=i.current,s=a.current;if(!e||!t||!s)return;let c=e.getContext(`2d`,{alpha:!0});if(!c)return;let l={id:null,x:0,y:0,prevX:0,prevY:0,vx:0,vy:0,grabbedIndex:null},u=mt(o),d=0,f=0,p=0,m=ht({receiptWidth:B,receiptHeight:V,startX:0,startY:32}),h=performance.now(),g=null,_=0,v=0,y=!1,ee=!0,b=!1,te=window.matchMedia(n),x=()=>te.matches&&document.visibilityState===`visible`&&ee,ne=()=>{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,p-e.top-42)),startX:e.left+(e.width-r)/2,startY:e.top+32}},S=t=>{y!==t&&(y=t,e.style.visibility=t?`visible`:`hidden`,s.style.visibility=t?`visible`:`hidden`)},re=()=>{b=!1,d&&=(window.cancelAnimationFrame(d),0),S(!1)},C=(e,t=performance.now())=>{m=ht(e),g=e,h=t},ie=()=>{let t=window.devicePixelRatio||1;f=Math.max(1,window.innerWidth),p=Math.max(1,window.innerHeight),e.width=Math.floor(f*t),e.height=Math.floor(p*t),c.setTransform(t,0,0,t,0,0),_=0,v=0,S(!1),C(ne()),x()&&ae()},ae=()=>{b||!x()||(b=!0,d=window.requestAnimationFrame(he))},w=()=>{x()?ie():re()},oe=e=>({x:e.clientX,y:e.clientY}),se=e=>{if(e.button!==0)return;let t=oe(e),n=bt(m.particles,t.x,t.y);n!=null&&(e.preventDefault(),s.setPointerCapture(e.pointerId),l.id=e.pointerId,l.x=t.x,l.y=t.y,l.prevX=t.x,l.prevY=t.y,l.vx=0,l.vy=0,l.grabbedIndex=n,v=0,ae())},ce=e=>{if(l.id!==e.pointerId)return;let t=oe(e);l.vx=t.x-l.prevX,l.vy=t.y-l.prevY,l.prevX=t.x,l.prevY=t.y,l.x=t.x,l.y=t.y},le=e=>{if(l.id!==e.pointerId)return;let t=l.grabbedIndex==null?null:m.particles[l.grabbedIndex];t&&(t.oldX=t.x-l.vx*.9,t.oldY=t.y-l.vy*.9),l.id=null,l.grabbedIndex=null},ue=e=>{let t=(e-h)/1e3;for(let e=R;e<m.particles.length;e+=1){let n=m.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=l.grabbedIndex==null?null:m.particles[l.grabbedIndex];n&&(n.x+=(l.x-n.x)*.72,n.y+=(l.y-n.y)*.72)},de=()=>{for(let e=0;e<nt;e+=1){_t(m.particles);for(let e of m.constraints)vt(m.particles,e)}_t(m.particles)},fe=()=>{let e=1/0,t=1/0,n=-1/0,r=-1/0;for(let i of m.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);s.style.transform=`translate3d(${e-20}px, ${t-20}px, 0)`,s.style.width=`${n-e+40}px`,s.style.height=`${r-t+40}px`},pe=()=>{let e=m.particles[0],t=m.particles[R-1],n=m.particles[z*R-1],r=m.particles[(z-1)*R];!e||!t||!n||!r||(c.save(),c.shadowColor=`rgba(0,0,0,0.24)`,c.shadowBlur=24,c.shadowOffsetY=16,c.fillStyle=`rgba(0,0,0,0.14)`,c.beginPath(),c.moveTo(e.x,e.y),c.lineTo(t.x,t.y),c.lineTo(n.x,n.y),c.lineTo(r.x,r.y),c.closePath(),c.fill(),c.restore())},T=()=>{let e=m.particles[0],t=m.particles[R-1];!e||!t||(c.save(),c.strokeStyle=`rgba(0,0,0,0.72)`,c.lineWidth=4,c.lineCap=`round`,c.beginPath(),c.moveTo(e.x-10,e.y-3),c.lineTo(t.x+10,t.y-3),c.stroke(),c.strokeStyle=`rgba(255,255,255,0.55)`,c.lineWidth=1,c.beginPath(),c.moveTo(e.x-8,e.y-5),c.lineTo(t.x+8,t.y-5),c.stroke(),c.restore())},me=()=>{c.clearRect(0,0,f,p),pe();for(let e=0;e<z-1;e+=1)for(let t=0;t<R-1;t+=1)yt(c,u,m.particles,e,t);T(),fe()},he=e=>{if(!b)return;if(!x()){re();return}let t=ne();if(tt(g,t)&&l.id==null?(_=0,S(!1),C(t,e)):(_+=1,g=t),gt(m.particles,t),ue(e),de(),me(),v=l.id==null?v+1:0,_>=2&&S(!0),_>=2&&v>=90){b=!1,d=0;return}d=window.requestAnimationFrame(he)};S(!1),x()&&ie();let ge=new ResizeObserver(ie);ge.observe(t);let E=new IntersectionObserver(([e])=>{ee=!!e?.isIntersecting,w()});return E.observe(t),te.addEventListener(`change`,w),document.addEventListener(`visibilitychange`,w),window.addEventListener(`resize`,w),s.addEventListener(`pointerdown`,se),s.addEventListener(`pointermove`,ce),s.addEventListener(`pointerup`,le),s.addEventListener(`pointercancel`,le),ae(),()=>{re(),ge.disconnect(),E.disconnect(),te.removeEventListener(`change`,w),document.removeEventListener(`visibilitychange`,w),window.removeEventListener(`resize`,w),s.removeEventListener(`pointerdown`,se),s.removeEventListener(`pointermove`,ce),s.removeEventListener(`pointerup`,le),s.removeEventListener(`pointercancel`,le)}},[n,o]),(0,P.jsxs)(`div`,{ref:i,className:`h-[calc(100dvh-5.5rem)] min-h-[420px]`,children:[(0,P.jsx)(`canvas`,{ref:r,className:`invisible pointer-events-none fixed inset-0 z-[61] block h-screen w-screen touch-none`,"aria-hidden":`true`}),(0,P.jsx)(`div`,{ref:a,className:`invisible fixed left-0 top-0 z-[62] cursor-grab touch-none active:cursor-grabbing`,"aria-label":`Interactive thermal receipt with Verlet paper simulation`})]})}var St={a:({children:e})=>(0,P.jsx)(`span`,{className:`console-markdown-link`,children:e})};function Ct(e){return e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`)}function wt(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(Ct).join(`|`)})`,`gi`)}function Tt({text:e,highlightQuery:t}){let r=(0,j.useRef)(null),i=(0,j.useMemo)(()=>wt(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,P.jsx)(`div`,{ref:r,children:(0,P.jsx)(n,{components:St,children:e})})}var Et=`codeseshProfiler`,Dt=`codeseshProfilerLog`,Ot=16,kt=500;function At(){if(typeof window>`u`)return!1;try{return window.localStorage.getItem(Et)===`1`}catch{return!1}}function jt(){if(typeof window>`u`)return!1;try{return window.localStorage.getItem(Dt)===`1`}catch{return!1}}function W(e){let t=window.__CODESHESH_RENDER_PROFILE__??[];t.push(e),t.length>kt&&t.splice(0,t.length-kt),window.__CODESHESH_RENDER_PROFILE__=t}function G(e){if(!At()||typeof window>`u`)return;let t=performance.now();W({...e,startTime:Mt(e.startTime??t),commitTime:Mt(e.commitTime??t),route:e.route??window.location.pathname})}function Mt(e){return Math.round(e*100)/100}function Nt({id:e,detail:t,children:n}){return At()?(0,P.jsx)(j.Profiler,{id:e,onRender:(e,n,r,i,a,o)=>{let s={id:e,source:`react-profiler`,phase:n,actualDuration:Mt(r),baseDuration:Mt(i),startTime:Mt(a),commitTime:Mt(o),route:window.location.pathname,...t?{detail:t}:{}};W(s),s.actualDuration>=Ot&&jt()&&N(`react.profiler.commit`,{...s})},children:(0,P.jsx)(Pt,{id:e,detail:t,children:n})}):n}function Pt({id:e,detail:t,children:n}){let r=performance.now(),i=(0,j.useRef)(0);return(0,j.useLayoutEffect)(()=>{i.current+=1;let n=performance.now();W({id:e,source:`commit-latency`,phase:i.current===1?`mount`:`update`,actualDuration:Mt(n-r),baseDuration:0,startTime:Mt(r),commitTime:Mt(n),route:window.location.pathname,...t?{detail:t}:{}})}),n}function Ft(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=Ft(t.text);if(n.trim())return n;let r=Ft(t.content);if(r.trim())return r}return``}).filter(Boolean).join(`
2
+
3
+ `);if(e&&typeof e==`object`){let t=e,n=Ft(t.text);if(n.trim())return n;let r=Ft(t.content);if(r.trim())return r}return``}function K(e){return e.type===`tool`||e.type===`plan`?!0:e.type===`text`||e.type===`reasoning`?!!Ft(e.text).trim():!1}function It(e){return e.reduce((e,t)=>{if(!K(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 Lt=`<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 Rt(e){return e.replace(/\r\n/g,`
6
+ `).trim()}function zt(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:Rt(n.text)===Rt(Lt)}function Bt(e){if(typeof e==`string`)return e.trim();if(Array.isArray(e))return e.map(e=>Bt(e)).filter(Boolean).join(`
7
+
8
+ `).trim();if(e&&typeof e==`object`){let t=e,n=Bt(t.text);if(n)return n;let r=Bt(t.content);if(r)return r}return``}function Vt(e){let t=e.approval_status===`fail`?`fail`:`success`,n=Bt(t===`fail`?e.output:e.input);return{title:`plan`,secondaryText:void 0,approvalStatus:t,expandable:!!n,contentLabel:t===`fail`?`Rejected`:`Plan`,contentMarkdown:n}}function Ht(e){return qt(e)?`Browser`:typeof e.title==`string`&&e.title.trim()?Wt(e.title):typeof e.tool==`string`&&e.tool.trim()?Wt(e.tool):`tool`}function Ut(e){return qt(e)?`browser`:Wt(typeof e.tool==`string`&&e.tool.trim()?e.tool:Ht(e)).toLowerCase()}function Wt(e){return e.trim().replace(/^tool:\s*/i,``).replace(/^\.+(?=\w)/,``)}function Gt(e){return e&&typeof e==`object`&&!Array.isArray(e)?e:{}}function Kt(e){return typeof e==`string`?e.trim():``}function qt(e){let t=Kt(Gt(e.state?.metadata).namespace);return Wt(Kt(e.tool)).toLowerCase()===`js`&&(t===`mcp__node_repl__`||t===`mcp__node_repl__.js`)}function Jt(e,t){let n=Ut(t),r=`tool:${n}`,i=e.get(n);if(i){i.count+=1;return}e.set(n,{id:r,toolKey:n,label:Ht(t),count:1})}function Yt(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)Jt(r,t),n.add(`tool:${Ut(t)}`)}return{filterIds:n,counts:t,tools:[...r.values()].toSorted((e,t)=>e.label.localeCompare(t.label))}}function Xt(e,t){return t.has(`tool:${Ut(e)}`)}function Zt(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=>Xt(e,n))}function Qt(e,t){let n=e.parts.filter(e=>Xt(e,t));return n.length===0?null:{...e,parts:n}}function $t(e,t){return e.map(e=>{let n=e.blocks.filter(n=>Zt(n,e.msg,t)).map(e=>e.type===`tool`?Qt(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 en(e){let t=[];for(let n of e){let e=It(n.parts);e.length!==0&&t.push({msg:n,blocks:e,index:t.length})}return t}function tn(e){return e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`)}function nn(e){if(typeof e!=`string`)return e;try{return JSON.parse(e)}catch{return e}}function rn(e){return typeof e==`string`?e.trim():``}function q(e){return e&&typeof e==`object`&&!Array.isArray(e)?e:{}}function J(e){return typeof e==`string`?e.trim():``}function Y(e){return typeof e==`string`?e:``}function an(e){try{return JSON.parse(e)}catch{return null}}function X(e){return e.replaceAll(/\\n/g,`
9
+ `)}function on(e){return e&&typeof e==`object`&&!Array.isArray(e)?e:{}}function sn(e){return typeof e==`string`?e:``}function cn(e){return e.replace(/\\n/g,`
10
+ `)}function ln(e){let t=on(e),n=sn(t.type);return n?{type:n,path:sn(t.path),oldPath:sn(t.old_path),targetPath:sn(t.targetPath),content:sn(t.content)||sn(on(t.input).content)}:null}function un(e){return(Array.isArray(e)?e:Array.isArray(on(e).content)?on(e).content:[]).map(e=>ln(e)).filter(e=>e!=null)}function dn(e,t,n){return`${e} ${e===1?t:n}`}function fn(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(dn(t,`write`,`writes`)),n>0&&a.push(dn(n,`edit`,`edits`)),r>0&&a.push(dn(r,`delete`,`deletes`)),i>0&&a.push(dn(i,`move`,`moves`)),a.join(` · `)}function pn(e){return e.targetPath||e.path||e.oldPath||e.type}function mn(e,t,n){return e.reduce((e,r)=>r.type===`write_file`?(e.push({label:n(pn(r)),operation:`write`,language:t(r.path),isCode:!0,text:cn(r.content)}),e):r.type===`edit_file`?(e.push({label:n(pn(r)),operation:`edit`,language:`diff`,isCode:!0,text:cn(r.content)}),e):r.type===`delete_file`?(e.push({label:n(pn(r)),operation:`edit`,language:`text`,isCode:!1,text:`File deleted.`}),e):(r.type===`move_file`&&e.push({label:n(pn(r)),operation:`edit`,language:`text`,isCode:!1,text:r.targetPath&&r.path?`Moved from ${n(r.path)} to ${n(r.targetPath)}`:r.oldPath?`Moved from ${n(r.oldPath)}`:`File moved.`}),e),[])}function hn(e,t,n,r=e=>e){let i=mn(e,n,r);return i.length>0?{kind:`file-sections`,sections:i}:{kind:`plain`,text:t,language:`text`,isCode:!1}}function gn(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 _n(e){if(typeof e==`string`)return[e];if(Array.isArray(e))return e.flatMap(e=>_n(e));if(e&&typeof e==`object`){let t=e;if(typeof t.text==`string`)return[t.text];if(t.content!==void 0)return _n(t.content)}return[]}function vn(e){return e.replace(/^<system>/i,``).replace(/<\/system>$/i,``).trim()}function yn(e,t=!0){let n=_n(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)?vn(e):e).join(`
11
+ `)}function bn(e){let t=nn(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 xn(e){let t=e.trim();return t?t.replace(/^tool:\s*/i,``).replace(/^\.+(?=\w)/,``):``}function Sn(e){return typeof e.title==`string`&&e.title.trim()?xn(e.title):typeof e.tool==`string`&&e.tool.trim()?xn(e.tool):`tool`}function Cn(e){return Sn(e).trim().toLowerCase()}function wn(e,t=`Tool`){return xn(J(e.title))||J(e.tool)||t}function Tn(e){return X(yn(e)||gn(e))||`No output captured.`}function Z(e){let t=Tn(e.outputValue);if(t!==`No output captured.`)return t;let n=Tn(e.errorValue);return n===`No output captured.`?`No output captured.`:n}function En(e){let t=e.trim();return!t||t.length>300||t.includes(`
12
+ `)||/^[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 Dn(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 On(e,t,n,r=0){if(!(e==null||r>4)){if(typeof e==`string`){Dn(t)&&En(e)&&n.add(e.trim());return}if(Array.isArray(e)){for(let i of e)On(i,t,n,r+1);return}if(typeof e==`object`)for(let[t,i]of Object.entries(e))On(i,t,n,r+1)}}function kn(e){let t=new Set;return On(e,``,t),[...t]}function An(e){return e.state?.arguments??e.state?.input??e.input??null}function jn(e){let t=q(e);return J(t.filePath)||J(t.file_path)||J(t.path)||J(t.targetFile)||J(t.effectiveUri)||J(t.relativeWorkspacePath)||``}function Q(e,t){let n=e.trim(),r=(t??``).replace(/\/+$/,``);return!n||!r?n:n===r?`.`:n.startsWith(`${r}/`)?n.slice(r.length+1):n}function Mn(e,t){let n=(t??``).replace(/\/+$/,``);return!e||!n?e:e.replace(RegExp(`${tn(n)}(?=$|/|[\\s"'\\)\\]}:;,])`,`g`),`.`)}function Nn(e,t){return e.startsWith(`${t}/`)?e.slice(t.length+1):e}function Pn(e,t){return`tool-${e}-${t}`}function Fn(e){let t=Cn(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 In(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 Ln(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=Pn(a,o);o+=1,t.set(i,s),n.set(s,a);let c=An(i),l=Sn(i),u=i.time_created??e.time_created,d=un(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=Fn(i);if(!f)continue;let p=kn(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:In(r.read),edit:In(r.edit),write:In(r.write),delete:In(r.delete)}}}function Rn(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}var zn={".bashrc":`bash`,".zshrc":`bash`,".profile":`bash`,dockerfile:`docker`,".env":`ini`},Bn={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 $(e){let t=e.split(`/`).pop()?.toLowerCase()??``;if(!t)return`text`;let n=zn[t];if(n)return n;if(t.startsWith(`.env.`))return`ini`;let r=t.includes(`.`)?t.split(`.`).pop()??``:``;return r&&Bn[r]||`text`}function Vn(e){return e&&typeof e==`object`&&!Array.isArray(e)?e:{}}function Hn(e){return typeof e==`string`?e.trim():``}function Un(e){return typeof e==`string`?e:``}function Wn(e){return typeof e==`string`?e.trim():typeof e==`number`||typeof e==`bigint`||typeof e==`boolean`?`${e}`:``}function Gn(e){return e.replace(/\\n/g,`
13
+ `)}function Kn(e){return e.replace(/\s*\(Recommended\)\s*$/i,``).trim()}function qn(e){let t=e.trim();return{label:Kn(t),recommended:/\(Recommended\)\s*$/i.test(t)}}function Jn(e){return e.replace(/\s+/g,` `).trim()}function Yn(e,t=88){let n=Jn(e);return n?n.length>t?`${n.slice(0,t)}...`:n:``}function Xn(e,t){return Yn([`${t} questions`,...e.filter(Boolean).slice(0,2)].join(` · `),96)}function Zn(e){try{return JSON.parse(e)}catch{return null}}function Qn(e){let t=Gn(e).split(`
14
+ `);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(`
15
+ `);return r.trim()?r:e}function $n(e,t,n){n.trim()&&e.push({label:t,value:n})}function er(e){return e.startsWith(`"`)&&e.endsWith(`"`)||e.startsWith(`'`)&&e.endsWith(`'`)?e.slice(1,-1):e}function tr(e){return e.trim()?!/[|&;<>()$`*?{}[\]\\]/.test(e):!1}function nr(e){let t=er(e.trim());return tr(t)?t:null}function rr(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 nr(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 nr(n[1]||``)}return null}function ir(e){let t=e.split(`
16
+ `),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(`
17
+ `)}function ar(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 or(e){let t=e.trim();return!t||ar(t)?null:(t.startsWith(`{`)||t.startsWith(`[`))&&Zn(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 sr(e,t,n){let r=Qn(t),i=rr(e);if(i){let e=n(i);return{text:ir(r),language:e,isCode:e!==`text`,sourcePath:i,confidence:`path`}}let a=or(r);return a?{text:r,language:a,isCode:!0,confidence:`content`}:{text:r,language:`text`,isCode:!1,confidence:`plain`}}function cr(e,t,n,r=e=>e,i=e=>e){let a=Vn(e),o=Hn(a.cmd),s=Hn(a.workdir),c=Hn(a.sandbox_permissions),l=Hn(a.justification),u=i(o),d=[];$n(d,`Command`,u),$n(d,`Workdir`,r(s)),$n(d,`Escalation`,c),$n(d,`Justification`,l);let f=Yn(u);return{secondaryText:l?[l,f].filter(Boolean).join(`
18
+ `):f||void 0,details:d,outputAnalysis:sr(o,t,n)}}function lr(e,t,n){let r=Vn(e),i=Wn(r.session_id),a=Un(r.chars),o=a?`stdin`:`poll`,s=[];return $n(s,`Session`,i),s.push({label:`Chars`,value:a||`(empty)`}),{secondaryText:i?`session #${i} · ${o}`:o,details:s,outputAnalysis:sr(``,t,n)}}function ur(e,t){let n=Vn(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=Vn(Zn(t)?.answers),a=r.map(e=>{let t=Vn(e),n=Vn(i[Hn(t.id)]),r=(Array.isArray(n.answers)?n.answers:[]).map(e=>typeof e==`string`?Kn(e):``).filter(Boolean),a=Array.isArray(t.options)?t.options.map(e=>{let t=Vn(e),n=qn(Hn(t.label));return n.label?{label:n.label,description:Hn(t.description)||void 0,recommended:n.recommended||void 0}:null}).filter(e=>e!=null):[],o=Hn(t.question);return o?{header:Hn(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:Xn(a.map(e=>e.header||``),a.length),details:[],outputContent:{kind:`question-list`,questions:a}}}function dr(e,t,n){return!t.trim()&&!n.trim()?[]:[{label:gr(e),lines:mr(T(X(t),X(n)))}]}function fr(e,t){let n=X(e).split(`
19
+ `),r=X(t).split(`
20
+ `);return[`@@`,...n.map(e=>`- ${e}`),...r.map(e=>`+ ${e}`)].join(`
21
+ `)}function pr(e){let t=X(e),n=t.split(`
22
+ `);return t.endsWith(`
23
+ `)&&n.pop(),n}function mr(e){return e.flatMap(e=>{let t=e.added?`add`:e.removed?`remove`:`context`;return pr(e.value).map(e=>({type:t,text:e}))})}function hr(e){let t=q(e).edit;return Array.isArray(t)?t:t&&typeof t==`object`?[t]:[]}function gr(e){let t=e.trim();if(!t)return`edit`;let n=t.split(`/`).pop()||t;return n===t?n:`${n} · ${t}`}function _r(e,t){let n=hr(e.inputValue),r=gr(t);return n.map(e=>{let t=q(e),n=Y(t.old),i=Y(t.new);return!n.trim()&&!i.trim()?null:{label:r,lines:mr(T(X(n),X(i)))}}).filter(e=>e!=null&&e.lines.length>0)}function vr(e,t){let n=q(e.inputValue),r=Array.isArray(n.edits)?n.edits:[],i=gr(t),a=r.map(e=>{let t=q(e),n=Y(t.oldText)||Y(t.old),r=Y(t.newText)||Y(t.new);return!n.trim()&&!r.trim()?null:{label:i,lines:mr(T(X(n),X(r)))}}).filter(e=>e!=null&&e.lines.length>0);if(a.length>0)return a;let o=q(e.metadataValue),s=Y(o.patch)||Y(o.diff);return s.trim()?[{label:i,lines:s.split(`
24
+ `).map(e=>({type:e.startsWith(`+`)?`add`:e.startsWith(`-`)?`remove`:`context`,text:e}))}]:[]}function yr(e){return e.startsWith(`@@`)?{type:`context`,text:e}:e.startsWith(`+`)?{type:`add`,text:e.slice(1)}:e.startsWith(`-`)?{type:`remove`,text:e.slice(1)}:e.startsWith(` `)?{type:`context`,text:e.slice(1)}:{type:`context`,text:e}}function br(e,t){let n=q(q(e.metadataValue).display),r=Array.isArray(n.structuredPatch)?n.structuredPatch:[],i=Y(n.filePath)||t;return r.map(e=>{let t=q(e),n=(Array.isArray(t.lines)?t.lines:[]).map(e=>typeof e==`string`?yr(e):null).filter(e=>e!=null);return n.length===0?null:{label:gr(i),lines:n}}).filter(e=>e!=null)}function xr(e){let t=Y(q(e.metadataValue).diff);if(t.trim())return X(t);let n=hr(e.inputValue).map(e=>{let t=q(e),n=Y(t.old),r=Y(t.new);return!n.trim()&&!r.trim()?``:fr(n,r)}).filter(Boolean).join(`
25
+
26
+ `);return n.trim()?n:Z(e)}function Sr(e){let t=e.indexOf(`Output:
27
+ `);if(t===-1)return e;let n=an(e.slice(t+8).trim());return Array.isArray(n)&&n.map(e=>J(q(e).text)).filter(Boolean).join(`
28
+ `)||e}function Cr(e){return e&&typeof e==`object`&&!Array.isArray(e)?e:typeof e==`string`&&an(e)||{}}function wr(e){return e.replace(/\n*<system-reminder>[\s\S]*$/i,``).trimEnd()}function Tr(e){let t=yn(e,!1)||Tn(e);return t===`No output captured.`?t:wr(t.replace(/^<file>\s*/i,``).replace(/\s*<\/file>\s*$/i,``)).split(`
29
+ `).filter(e=>!/^\(End of file - total \d+ lines\)$/.test(e.trim())).map(e=>e.replace(/^\d+\|\s?/,``).replace(/^\s*\d+\t/,``)).join(`
30
+ `).trimEnd()||`No output captured.`}function Er(e){let t=Y(Cr(e).contents);return t?X(t):`No output captured.`}function Dr(e){let t=Cr(e),n=Array.isArray(t.directories)?t.directories:[];if(n.length===0)return Tn(e);let r=n.flatMap(e=>{let t=q(e);return[J(t.absPath),...(Array.isArray(t.files)?t.files:[]).map(e=>{let t=q(e);return J(t.relPath)||J(t.absPath)}).filter(Boolean).map(e=>` ${e}`)].filter(Boolean)});return r.length>0?r.join(`
31
+ `):`No output captured.`}function Or(e){let t=q(e.inputValue),n=q(e.metadataValue),r=Array.isArray(n.tasks)?n.tasks:[],i=Number(t.id);return q(Number.isFinite(i)&&i>0?r.find(e=>Number(q(e).id)===i):r.at(-1))}function kr(e){let t=Z(e).match(/\(([^()]+?)\s*→\s*([^()]+?)\)/);return t?`${t[1]} -> ${t[2]}`:``}function Ar(e){let t=(e.split(`
32
+ `)[0]??``).match(/^Agent:\s*(.+)$/i),n=e.split(`
33
+ `).find(e=>e.includes(`Status:`)),r=[];return t?.[1]&&r.push({label:`Agent`,value:t[1].trim()}),n&&r.push({label:`Summary`,value:n.trim()}),r}function jr(e){return e.replace(/\s*[((](?:Recommended|推荐)[))]\s*$/i,``).trim()}function Mr(e){let t=new Map;return{text:e.map(e=>{let n=q(e),r=J(n.status)||`pending`,i=J(n.priority),a=J(n.content);t.set(r,(t.get(r)??0)+1);let o=r===`completed`?`x`:r===`in_progress`?`~`:` `,s=i?` _${i}_`:``;return`- [${o}] ${a||`(empty todo)`}${s}`}).join(`
34
+ `)||`No todos captured.`,summary:[...t.entries()].map(([e,t])=>`${t} ${e}`).join(` · `),details:[...t.entries()].map(([e,t])=>({label:e,value:String(t)}))}}function Nr(e){let t=new Map;for(let n of e.matchAll(/"([^"]+)"="([^"]+)"/g)){let e=n[1]?.trim(),r=n[2]?.trim();!e||!r||t.set(e,[jr(r)])}return t}function Pr(e,t){let n=q(e),r=Array.isArray(n.questions)?n.questions:[],i=Nr(t),a=r.map(e=>{let t=q(e),n=J(t.question);if(!n)return null;let r=Array.isArray(t.options)?t.options.map(e=>{let t=q(e),n=J(t.label),r=jr(n);return r?{label:r,description:J(t.description)||void 0,recommended:r!==n.trim()||void 0}:null}).filter(e=>e!=null):[];return{header:J(t.header)||void 0,question:n,options:r,answers:i.get(n)??[]}}).filter(e=>e!=null);return a.length===0?{secondaryText:void 0,outputContent:{kind:`plain`,text:t,language:`text`,isCode:!1}}:{secondaryText:`${a.length} question${a.length===1?``:`s`}`,outputContent:{kind:`question-list`,questions:a}}}function Fr(e){let t=q(e.inputValue);if(e.status===`completed`){let e=Y(t.content);if(e.trim())return X(e)}return Z(e)}function Ir(e){let t=q(q(e.state).arguments),n=rn(t.agent_type),r=rn(e.nickname),i=[rn(t.model),rn(t.reasoning_effort)].filter(Boolean).join(`-`);return[[n,r].filter(Boolean).join(` - `),i].filter(Boolean).join(` `)}function Lr(e){let t=q(e.state);return rn(t.prompt)||rn(q(t.arguments).message)||``}function Rr(e){let t=rn(e.nickname);return e.role===`assistant`&&t?`AGENT (${t})`:e.role===`user`?`USER`:e.role===`tool`?`TOOL`:`AGENT`}function zr(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 Br(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=nn(t.input??t.arguments??{}),s=t.metadata??{};return{status:r,command:bn(o),inputValue:o,outputValue:i,errorValue:a,metadataValue:s,inputText:gn(o)}}function Vr(e,t,n){let r=Mn(t.command||t.inputText||`{}`,n).replace(/\s+/g,` `).trim(),i=r.length>72?`${r.slice(0,72)}...`:r;return{Icon:C,title:wn(e),secondaryText:i?`(${i})`:void 0,details:[],expandable:!0,showInputPreview:!0,outputContent:{kind:`plain`,text:Z(t),language:`text`,isCode:!1}}}function Hr(e,t,n,r){let i=Mn(J(q(t.inputValue).name),r);return{...n,Icon:ce,title:J(e.tool)||`skill`,secondaryText:i||void 0,expandable:!1,showInputPreview:!1}}function Ur(e,t,n){let r=Vr(e,t,n),i=(e.tool||``).toLowerCase(),a=q(t.inputValue),o=jn(t.inputValue),s=Q(o,n);if(i===`read`)return{...r,Icon:p,title:`read`,secondaryText:s||void 0,showInputPreview:!1,outputContent:{kind:`plain`,text:Tr(t.outputValue),language:$(o),isCode:!0}};if(i===`edit`){let e=Y(a.old_string),n=Y(a.new_string),i=dr(s||o,e,n);return{...r,Icon:d,title:`edit`,secondaryText:s||void 0,showInputPreview:!1,outputContent:i.length>0?{kind:`structured-diff`,blocks:i}:{kind:`plain`,text:Z(t),language:`text`,isCode:!1}}}return i===`write`?{...r,Icon:ae,title:`write`,secondaryText:s||void 0,showInputPreview:!1,outputContent:{kind:`plain`,text:Fr(t),language:$(o),isCode:!0}}:{...r,title:wn(e)}}function Wr(e,t,n){let r=Vr(e,t,n),i=(e.tool||``).toLowerCase(),a=q(t.inputValue);if(i===`glob`){let n=J(a.pattern);return{...r,Icon:E,title:e.tool||`glob`,secondaryText:n||void 0,showInputPreview:!1,outputContent:{kind:`plain`,text:Z(t),language:`text`,isCode:!1}}}if(i===`grep`){let i=J(a.path),o=J(a.pattern),s=[Q(i,n),o].filter(Boolean).join(` · `);return{...r,Icon:E,title:e.tool||`grep`,secondaryText:s||void 0,showInputPreview:!1,outputContent:{kind:`plain`,text:Z(t),language:`text`,isCode:!1}}}if(i===`bash`){let i=J(a.description),o=Mn(J(a.command),n),s=i?`${i}${o?` (${o})`:``}`:o?`(${o})`:void 0;return{...r,Icon:C,title:e.tool||`bash`,secondaryText:s,showInputPreview:!1,outputContent:{kind:`plain`,text:Z(t),language:`text`,isCode:!1}}}if(i===`read`){let i=jn(t.inputValue),a=Q(i,n);return{...r,Icon:p,title:e.tool||`read`,secondaryText:a||void 0,showInputPreview:!1,outputContent:{kind:`plain`,text:Tr(t.outputValue),language:$(i),isCode:!0}}}if(i===`edit`){let i=Q(jn(t.inputValue),n);return{...r,Icon:d,title:e.tool||`edit`,secondaryText:i||void 0,showInputPreview:!1,outputContent:{kind:`plain`,text:xr(t),language:`diff`,isCode:!0}}}if(i===`write`){let i=jn(t.inputValue),a=Q(i,n),o=t.status===`completed`;return{...r,Icon:ae,title:e.tool||`write`,secondaryText:a||void 0,showInputPreview:!1,outputContent:{kind:`plain`,text:Fr(t),language:$(i),isCode:o}}}return i===`skill`?Hr(e,t,r,n):r}function Gr(e,t,n){let r=Vr(e,t,n),i=(e.tool||``).toLowerCase(),a=q(t.inputValue);if(i===`glob`){let n=J(a.pattern);return{...r,Icon:E,title:e.title||`glob`,secondaryText:n||void 0,showInputPreview:!1,outputContent:{kind:`plain`,text:Z(t),language:`text`,isCode:!1}}}if(i===`grep`){let i=J(a.path),o=J(a.pattern),s=[Q(i,n),o].filter(Boolean).join(` · `);return{...r,Icon:E,title:e.title||`grep`,secondaryText:s||void 0,showInputPreview:!1,outputContent:{kind:`plain`,text:Z(t),language:`text`,isCode:!1}}}if(i===`shell`){let i=Mn(J(a.command),n);return{...r,Icon:C,title:e.title||`bash`,secondaryText:i?`(${i})`:void 0,showInputPreview:!1,outputContent:{kind:`plain`,text:Z(t),language:`text`,isCode:!1}}}if(i===`readfile`){let i=jn(t.inputValue),a=Q(i,n);return{...r,Icon:p,title:e.title||`read`,secondaryText:a||void 0,showInputPreview:!1,outputContent:{kind:`plain`,text:Tr(t.outputValue),language:$(i),isCode:!0}}}if(i===`strreplacefile`){let i=jn(t.inputValue),a=Q(i,n),o=_r(t,a||i);return{...r,Icon:d,title:e.title||`edit`,secondaryText:a||void 0,showInputPreview:!1,outputContent:o.length>0?{kind:`structured-diff`,blocks:o}:{kind:`plain`,text:xr(t),language:`diff`,isCode:!0}}}if(i===`writefile`){let i=jn(t.inputValue),a=Q(i,n);return{...r,Icon:ae,title:e.title||`write`,secondaryText:a||void 0,showInputPreview:!1,outputContent:{kind:`plain`,text:Fr(t),language:$(i),isCode:t.status===`completed`}}}return r}function Kr(e,t,n){let r=Vr(e,t,n),i=Cn(e),a=J(q(t.metadataValue).namespace),o=e=>Q(e,n),s=e=>Mn(e,n);if(i===`skill`)return Hr(e,t,r,n);if(i===`js`&&(a===`mcp__node_repl__`||a===`mcp__node_repl__.js`)){let e=J(q(t.inputValue).title);return{...r,Icon:C,title:`Browser`,secondaryText:e||void 0,details:[],showInputPreview:!1,outputContent:{kind:`plain`,text:Sr(Z(t)),language:`text`,isCode:!1}}}if(i===`exec_command`||i===`bash`){let e=cr(t.inputValue,Z(t),$,o,s);return{...r,Icon:C,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(i===`write_stdin`){let e=lr(t.inputValue,Z(t),$);return{...r,Icon:C,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(i===`request_user_input`){let e=ur(t.inputValue,Z(t));return{...r,Icon:se,title:`ask`,secondaryText:e.secondaryText,details:e.details,showInputPreview:!1,outputContent:e.outputContent}}if(i===`patch`){let n=un(t.inputValue),i=fn(n);return{...r,Icon:d,title:wn(e,`patch`),secondaryText:i||void 0,details:[],showInputPreview:!1,outputContent:hn(n,Z(t),$,o)}}if(i===`subagent`){let n=Lr(e),i=Z(t);return{...r,Icon:f,title:Ir(e)||wn(e,`subagent`),secondaryText:void 0,details:[],showInputPreview:!1,outputContent:{kind:`plain`,text:n||i,language:`markdown`,isCode:!1}}}return r}function qr(e,t,n){let r=Vr(e,t,n),i=(e.tool||``).toLowerCase(),a=q(t.inputValue),o=jn(t.inputValue),s=Q(o,n);if(i===`read_file_v2`){let e=Er(t.outputValue);return{...r,Icon:p,title:`read`,secondaryText:s||void 0,details:e===`No output captured.`?[{label:`Lines`,value:J(Cr(t.outputValue).totalLinesInFile)}]:[],showInputPreview:!1,outputContent:{kind:`plain`,text:e,language:$(o),isCode:e!==`No output captured.`}}}if(i===`edit_file_v2`){let e=X(Y(a.streamingContent));return{...r,Icon:d,title:`edit`,secondaryText:s||void 0,showInputPreview:!1,outputContent:{kind:`plain`,text:e||Z(t),language:e?`diff`:`text`,isCode:!!e}}}if(i===`ripgrep_raw_search`){let e=J(a.pattern),i=[Q(J(a.path),n),e].filter(Boolean).join(` · `);return{...r,Icon:E,title:`grep`,secondaryText:i||void 0,details:[],showInputPreview:!1,outputContent:{kind:`plain`,text:Z(t),language:`text`,isCode:!1}}}if(i===`glob_file_search`){let e=J(a.globPattern),i=[Q(J(a.targetDirectory),n),e].filter(Boolean).join(` · `);return{...r,Icon:E,title:`glob`,secondaryText:i||void 0,details:[],showInputPreview:!1,outputContent:{kind:`plain`,text:Dr(t.outputValue),language:`text`,isCode:!1}}}if(i===`run_terminal_command_v2`){let e=Mn(J(a.command),n),i=J(a.commandDescription),o=i?`${i}${e?` (${e})`:``}`:e?`(${e})`:void 0;return{...r,Icon:C,title:`bash`,secondaryText:o,details:[],showInputPreview:!1,outputContent:{kind:`plain`,text:Z(t),language:`text`,isCode:!1}}}return{...r,title:wn(e)}}function Jr(e,t,n){let r=Vr(e,t,n),i=(e.tool||``).toLowerCase(),a=q(t.inputValue),o=q(t.metadataValue),s=jn(t.inputValue),c=Q(s,n);if(i===`todo`){let e=J(a.action)||J(o.action)||`todo`,n=Or(t),i=Number(n.id)||Number(a.id),s=J(n.subject)||J(a.subject),c=J(n.description)||J(a.description),l=J(n.status)||J(a.status),u=kr(t),d=[i?`#${i}`:``,s,e===`update`&&u?u:l].filter(Boolean);return{...r,Icon:ve,title:e===`create`?`todo create`:e===`update`?`todo update`:`todo`,secondaryText:d.join(` · `)||void 0,details:[i?{label:`ID`,value:`#${i}`}:null,s?{label:`Subject`,value:s}:null,l?{label:`Status`,value:l}:null,u?{label:`Change`,value:u}:null].filter(e=>e!=null),showInputPreview:!1,outputContent:{kind:`plain`,text:c||Z(t),language:`markdown`,isCode:!1}}}if(i===`read`)return{...r,Icon:p,title:`read`,secondaryText:c||void 0,showInputPreview:!1,outputContent:{kind:`plain`,text:Tr(t.outputValue),language:$(s),isCode:!0}};if(i===`write`)return{...r,Icon:b,title:`write`,secondaryText:c||void 0,showInputPreview:!1,outputContent:{kind:`plain`,text:Fr(t),language:$(s),isCode:t.status===`completed`}};if(i===`edit`){let e=vr(t,c||s),n=typeof o.firstChangedLine==`number`?String(o.firstChangedLine):Y(o.firstChangedLine);return{...r,Icon:d,title:`edit`,secondaryText:c||void 0,details:n?[{label:`Line`,value:n}]:[],showInputPreview:!1,outputContent:e.length>0?{kind:`structured-diff`,blocks:e}:{kind:`plain`,text:Z(t),language:`text`,isCode:!1}}}if(i===`agent`){let e=J(a.description)||J(o.description),n=J(a.subagent_type)||J(o.subagentType),i=J(o.agentId),s=J(o.status);return{...r,Icon:f,title:n?`agent · ${n}`:`agent`,secondaryText:[i?`#${i}`:``,e].filter(Boolean).join(` · `),details:[i?{label:`Agent`,value:i}:null,n?{label:`Type`,value:n}:null,s?{label:`Status`,value:s}:null].filter(e=>e!=null),showInputPreview:!1,outputContent:{kind:`plain`,text:Y(a.prompt)||Z(t),language:`markdown`,isCode:!1}}}if(i===`get_subagent_result`){let e=J(a.agent_id),n=Z(t);return{...r,Icon:f,title:`subagent result`,secondaryText:e?`#${e}`:void 0,details:Ar(n),showInputPreview:!1,outputContent:{kind:`plain`,text:n,language:`markdown`,isCode:!1}}}if(i===`analyze_image`){let e=Array.isArray(a.images)?a.images.map(e=>Y(e)).filter(Boolean):[],i=Y(a.question);return{...r,Icon:_e,title:`analyze image`,secondaryText:e.map(e=>Q(e,n)).join(`, `),details:[...e.map((e,t)=>({label:t===0?`Image`:`Image ${t+1}`,value:Q(e,n)})),i?{label:`Question`,value:i}:null].filter(e=>e!=null),showInputPreview:!1,outputContent:{kind:`plain`,text:Z(t),language:`markdown`,isCode:!1}}}if(i===`bash`||i===`batch`){let e=Mn(J(a.command),n);return{...r,Icon:C,title:i===`batch`?`batch`:`bash`,secondaryText:e?`(${e})`:void 0,showInputPreview:!1,outputContent:{kind:`plain`,text:Z(t),language:`text`,isCode:!1}}}return r}function Yr(e,t,n){let r=Vr(e,t,n),i=Cn(e),a=q(t.inputValue),o=q(t.metadataValue),s=jn(t.inputValue),c=Q(s,n),l=Z(t);if(i===`bash`){let e=J(a.description),t=J(a.command),i=Mn(t,n),o=l===`(Bash completed with no output)`?`No output captured.`:l;return{...r,Icon:C,title:`bash`,secondaryText:e?`${e}${i?` (${i})`:``}`:i?`(${i})`:void 0,details:t?[{label:`Command`,value:i||t}]:[],showInputPreview:!1,outputContent:{kind:`plain`,text:o,language:`text`,isCode:!1}}}if(i===`read`)return{...r,Icon:p,title:`read`,secondaryText:c||void 0,showInputPreview:!1,outputContent:{kind:`plain`,text:Tr(t.outputValue),language:$(s),isCode:!0}};if(i===`edit`){let e=br(t,c||s),n=Y(a.old_string),i=Y(a.new_string),u=dr(c||s,n,i),f=e.length>0?e:u,p=q(o.display);return{...r,Icon:d,title:`edit`,secondaryText:c||void 0,details:[typeof p.additions==`number`?{label:`Additions`,value:String(p.additions)}:null,typeof p.deletions==`number`?{label:`Deletions`,value:String(p.deletions)}:null].filter(e=>e!=null),showInputPreview:!1,outputContent:f.length>0?{kind:`structured-diff`,blocks:f}:{kind:`plain`,text:l,language:`text`,isCode:!1}}}if(i===`write`)return{...r,Icon:b,title:`write`,secondaryText:c||void 0,showInputPreview:!1,outputContent:{kind:`plain`,text:Fr(t),language:$(s),isCode:t.status===`completed`}};if(i===`glob`||i===`grep`){let e=J(a.path),t=J(a.pattern),o=[Q(e,n),t].filter(Boolean).join(` · `);return{...r,Icon:E,title:i,secondaryText:o||void 0,showInputPreview:!1,outputContent:{kind:`plain`,text:l,language:`text`,isCode:!1}}}if(i===`todowrite`){let e=Mr(Array.isArray(a.todos)?a.todos:[]);return{...r,Icon:ve,title:`todo`,secondaryText:e.summary||void 0,details:e.details,showInputPreview:!1,outputContent:{kind:`plain`,text:e.text,language:`markdown`,isCode:!1}}}if(i===`agent`){let e=J(a.subagent_type),t=J(a.description);return{...r,Icon:f,title:e?`agent · ${e}`:`agent`,secondaryText:t||void 0,details:e?[{label:`Type`,value:e}]:[],showInputPreview:!1,outputContent:{kind:`plain`,text:l,language:`markdown`,isCode:!1}}}if(i===`askuserquestion`){let e=Pr(t.inputValue,l);return{...r,Icon:se,title:`ask`,secondaryText:e.secondaryText,details:[],showInputPreview:!1,outputContent:e.outputContent}}if(i===`enterplanmode`||i===`exitplanmode`){let e=Y(a.plan);return{...r,Icon:ve,title:i===`enterplanmode`?`plan mode`:`plan approved`,secondaryText:e.split(`
35
+ `).find(e=>e.trim())?.replace(/^#+\s*/,``)||void 0,showInputPreview:!1,outputContent:{kind:`plain`,text:e||l,language:`markdown`,isCode:!1}}}if(i===`websearch`){let e=J(a.query);return{...r,Icon:E,title:`web search`,secondaryText:e||void 0,showInputPreview:!1,outputContent:{kind:`plain`,text:l,language:`markdown`,isCode:!1}}}if(i===`skill`){let e=J(a.skill);return{...r,Icon:ce,title:`skill`,secondaryText:e||void 0,showInputPreview:!1,outputContent:{kind:`plain`,text:l,language:`markdown`,isCode:!1}}}return r}function Xr(e,t,n,r){let i=e.toLowerCase();return i===`opencode`?Wr(t,n,r):i===`codex`?Kr(t,n,r):i===`kimi`?Gr(t,n,r):i===`claudecode`?Ur(t,n,r):i===`cursor`?qr(t,n,r):i===`pi`?Jr(t,n,r):i===`zcode`?Yr(t,n,r):Vr(t,n,r)}function Zr(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}K`:e.toString()}function Qr(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})}D.registerLanguage(`bash`,O),D.registerLanguage(`c`,Le),D.registerLanguage(`cpp`,xe),D.registerLanguage(`csharp`,Re),D.registerLanguage(`css`,Ie),D.registerLanguage(`docker`,be),D.registerLanguage(`go`,we),D.registerLanguage(`ini`,Te),D.registerLanguage(`java`,Oe),D.registerLanguage(`javascript`,je),D.registerLanguage(`jsx`,A),D.registerLanguage(`json`,Ce),D.registerLanguage(`markdown`,Fe),D.registerLanguage(`markup`,De),D.registerLanguage(`python`,Se),D.registerLanguage(`rust`,Ne),D.registerLanguage(`sql`,Ae),D.registerLanguage(`toml`,k),D.registerLanguage(`tsx`,Ee),D.registerLanguage(`typescript`,Me),D.registerLanguage(`yaml`,ke);function $r(e){return e===`html`||e===`xml`?`markup`:e}function ei({language:e,text:t}){return(0,P.jsx)(D,{language:$r(e),style:Pe,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 ti(e,t){return`${e}:${t}`}function ni(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 ri({text:e}){let t=e.split(`
36
+ `),n=new Map;return(0,P.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,P.jsx)(`span`,{className:`block rounded-[2px] px-1 ${ni(e)}`,children:e||` `},ti(e,t))})})}function ii(e){let t=e.text||`No output captured.`;return!e.isCode||e.language===`text`?(0,P.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,P.jsx)(ri,{text:t}):(0,P.jsx)(`div`,{className:`max-h-[420px] overflow-auto bg-[#fafafa]`,children:(0,P.jsx)(ei,{language:e.language,text:t})})}function ai({sections:e}){return(0,P.jsx)(`div`,{className:`space-y-3`,children:e.map(e=>(0,P.jsxs)(`div`,{className:`overflow-hidden rounded-sm border border-[var(--console-border)] bg-[#fafafa]`,children:[(0,P.jsx)(`div`,{className:`border-b border-[var(--console-border)] bg-[var(--console-surface-muted)] px-3 py-1.5`,children:(0,P.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,P.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,P.jsx)(`span`,{className:`console-mono text-[11px] font-semibold text-[var(--console-muted)]`,children:e.label})]})}),ii(e)]},`${e.operation}:${e.label}:${e.language}`))})}function oi({questions:e}){return(0,P.jsx)(`div`,{className:`space-y-3`,children:e.map(e=>(0,P.jsxs)(`div`,{className:`overflow-hidden rounded-sm border border-[var(--console-border)] bg-[#fafafa]`,children:[(0,P.jsxs)(`div`,{className:`border-b border-[var(--console-border)] bg-[var(--console-surface-muted)] px-3 py-2`,children:[(0,P.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[e.header?(0,P.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,P.jsx)(`span`,{className:`console-mono text-[11px] font-semibold text-[var(--console-success)]`,children:`Answered`}):(0,P.jsx)(`span`,{className:`console-mono text-[11px] font-semibold text-[var(--console-muted)]`,children:`Pending`})]}),(0,P.jsx)(`p`,{className:`mt-2 text-sm leading-relaxed text-[var(--console-text)]`,children:e.question})]}),(0,P.jsx)(`div`,{className:`space-y-2 p-3`,children:e.options.map(t=>{let n=e.answers.includes(t.label);return(0,P.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,P.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,P.jsx)(`span`,{className:`console-mono text-xs font-semibold ${n?`text-[var(--console-success)]`:`text-[var(--console-text)]`}`,children:t.label}),t.recommended?(0,P.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,P.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,P.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 si(e){return`${e.label}:${e.lines.map(e=>`${e.type}:${e.text}`).join(`
37
+ `)}`}function ci(e){return e===`add`?`text-[#15803d] bg-[#f0fdf4]`:e===`remove`?`text-[#b91c1c] bg-[#fef2f2]`:`text-[var(--console-text)]`}function li({blocks:e}){return(0,P.jsx)(`div`,{className:`space-y-3`,children:e.map(e=>{let t=new Map;return(0,P.jsxs)(`div`,{className:`overflow-hidden rounded-sm border border-[var(--console-border)] bg-[#fafafa]`,children:[(0,P.jsx)(`div`,{className:`border-b border-[var(--console-border)] bg-[var(--console-surface-muted)] px-3 py-1.5`,children:(0,P.jsx)(`span`,{className:`console-mono text-[11px] font-semibold text-[var(--console-muted)]`,children:e.label})}),(0,P.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,P.jsxs)(`span`,{className:`block rounded-[2px] px-1 ${ci(e.type)}`,children:[e.type===`add`?`+`:e.type===`remove`?`-`:` `,e.text||` `]},`${n}:${r}`)})})]},si(e))})})}function ui({outputContent:e}){if(e.kind===`structured-diff`)return(0,P.jsx)(li,{blocks:e.blocks});if(e.kind===`file-sections`)return(0,P.jsx)(ai,{sections:e.sections});if(e.kind===`question-list`)return(0,P.jsx)(oi,{questions:e.questions});let t=e.text||`No output captured.`;return!e.isCode||e.language===`text`?(0,P.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,P.jsx)(ri,{text:t}):(0,P.jsx)(`div`,{className:`max-h-[420px] overflow-auto rounded-sm border border-[var(--console-border)] bg-[#fafafa]`,children:(0,P.jsx)(ei,{language:e.language,text:t})})}var di={completed:{label:`Success`,className:`border-[var(--console-success-border)] bg-[var(--console-success-bg)] text-[var(--console-success)]`,icon:s},error:{label:`Failed`,className:`border-[var(--console-error-border)] bg-[var(--console-error-bg)] text-[var(--console-error)]`,icon:_},running:{label:`Running`,className:`border-[var(--console-warning-border)] bg-[var(--console-warning-bg)] text-[var(--console-warning)]`,icon:ge}},fi=32,pi=80,mi=280,hi=6;function gi(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(tn).join(`|`)})`,`gi`)}function _i(e,t){let n=gi(t);return n?e.split(n).map((e,t)=>e.match(n)?(0,P.jsx)(`mark`,{children:e},`${e}-${t}`):(0,P.jsx)(`span`,{children:e},`${e}-${t}`)):e}function vi({text:e,highlightQuery:t}){return(0,P.jsx)(Tt,{text:e,highlightQuery:t})}function yi(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 bi(e,t){if(!At())return t();let n=performance.now(),r=t(),i=performance.now();return G({id:e,source:`custom-timing`,phase:`measure`,actualDuration:Math.round((i-n)*100)/100,baseDuration:0,startTime:n,commitTime:i}),r}function xi({session:e,toc:t}){let[n,r]=(0,j.useState)(!1),[i,a]=(0,j.useState)(!1);return(0,j.useEffect)(()=>{r(!1)},[e.id]),(0,j.useEffect)(()=>{if(!n){a(!1);return}a(!1);let e=0,t=requestAnimationFrame(()=>{e=requestAnimationFrame(()=>a(!0))}),i=window.matchMedia(`(min-width: 1025px)`),o=()=>{i.matches||r(!1)},s=e=>{e.key===`Escape`&&r(!1)},c=document.body.style.overflow;return document.body.style.overflow=`hidden`,window.addEventListener(`keydown`,s),i.addEventListener(`change`,o),o(),()=>{cancelAnimationFrame(t),e&&cancelAnimationFrame(e),document.body.style.overflow=c,window.removeEventListener(`keydown`,s),i.removeEventListener(`change`,o)}},[n]),(0,P.jsxs)(P.Fragment,{children:[(0,P.jsx)(`button`,{type:`button`,"aria-expanded":n,"aria-label":`Open session receipt`,onClick:()=>r(!0),className:`console-mono fixed right-0 top-1/2 z-40 hidden h-32 w-10 -translate-y-1/2 items-center justify-center rounded-l-sm border border-r-0 border-[var(--console-border)] bg-white text-[10px] font-semibold uppercase tracking-[0.14em] text-[var(--console-text)] shadow-[-2px_4px_14px_rgba(15,23,42,0.14)] transition-colors hover:bg-[var(--console-surface-muted)] min-[1025px]:flex`,children:(0,P.jsx)(`span`,{className:`[writing-mode:vertical-rl]`,children:`Receipt`})}),n?(0,P.jsxs)(`div`,{className:`fixed inset-0 z-[60] hidden min-[1025px]:block`,children:[(0,P.jsx)(`button`,{type:`button`,"aria-label":`Close session receipt`,onClick:()=>r(!1),className:`absolute inset-0 bg-black/20`}),(0,P.jsxs)(`aside`,{className:`absolute right-0 top-0 z-10 h-full w-[min(92vw,430px)] border-l border-[var(--console-border)] bg-[var(--console-bg)] p-4 shadow-[-12px_0_32px_rgba(15,23,42,0.18)]`,children:[(0,P.jsxs)(`div`,{className:`mb-3 flex items-center justify-between gap-3`,children:[(0,P.jsx)(`span`,{className:`console-mono text-xs font-semibold uppercase tracking-[0.16em] text-[var(--console-text)]`,children:`Session Receipt`}),(0,P.jsx)(`button`,{type:`button`,"aria-label":`Close session receipt`,onClick:()=>r(!1),className:`rounded-sm border border-[var(--console-border)] bg-white p-2 text-[var(--console-muted)] transition-colors hover:bg-[var(--console-surface-muted)]`,children:(0,P.jsx)(S,{className:`size-4`})})]}),i?(0,P.jsx)(Nt,{id:`InteractiveReceipt`,children:(0,P.jsx)(xt,{session:e,toc:t},e.id)}):(0,P.jsx)(`div`,{className:`h-[calc(100dvh-5.5rem)] min-h-[420px] rounded-sm border border-[var(--console-border)] bg-white`})]})]}):null]})}function Si(e){return e===window}function Ci(e,t){let n=[],r=0;for(let i=0;i<e;i+=1){let a=t[i]??mi,o=r,s=o+a;n.push({start:o,end:s}),r=s+(i===e-1?0:fi)}return{items:n,totalSize:r}}function wi(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 Ti(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 Ei(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 Di(e){return Si(e)?window.scrollY:e.scrollTop}function Oi(e){return Si(e)?window.innerHeight||900:e.clientHeight}function ki(e,t){if(Si(t))return e.getBoundingClientRect().top+window.scrollY;let n=t.getBoundingClientRect(),r=e.getBoundingClientRect();return t.scrollTop+r.top-n.top}function Ai(e,t){if(Si(e)){window.scrollTo({top:t,behavior:`auto`});return}e.scrollTo({top:t,behavior:`auto`})}function ji({messages:e,toolAnchorIds:t,sessionAgentKey:n,baseDirectory:r,highlightQuery:i,apiRef:a}){let o=e.length>pi;return(0,j.useEffect)(()=>{o||(a.current=null)},[a,o]),o?(0,P.jsx)(Mi,{messages:e,toolAnchorIds:t,sessionAgentKey:n,baseDirectory:r,highlightQuery:i,apiRef:a}):(0,P.jsx)(`div`,{className:`flex min-w-0 flex-col gap-8`,children:e.map(({msg:e,blocks:a,index:o})=>(0,P.jsx)(Ji,{msg:e,blocks:a,toolAnchorIds:t,formatTokens:Zr,sessionAgentKey:n,baseDirectory:r,highlightQuery:i},`${e.id}:${o}`))})}function Mi({messages:e,toolAnchorIds:t,sessionAgentKey:n,baseDirectory:r,highlightQuery:i,apiRef:a}){let o=(0,j.useRef)(null),s=(0,j.useRef)(null),[c,l]=(0,j.useState)([]),[u,d]=(0,j.useState)(null),[f,p]=(0,j.useState)(()=>({scrollTop:0,height:900,listTop:0})),m=(0,j.useRef)(f);(0,j.useEffect)(()=>{m.current=f},[f]);let h=(0,j.useCallback)(()=>{if(typeof window>`u`)return;let e=o.current,t=e?Ei(e):window;s.current=t;let n=e?ki(e,t):0,r={scrollTop:Di(t),height:Oi(t),listTop:n},i=m.current;Math.abs(i.scrollTop-r.scrollTop)<1&&Math.abs(i.height-r.height)<1&&Math.abs(i.listTop-r.listTop)<1||(m.current=r,p(r))},[]);(0,j.useEffect)(()=>{h();let e=s.current??window,t=0,n=()=>{t||=requestAnimationFrame(()=>{t=0,h()})};e.addEventListener(`scroll`,n,{passive:!0}),window.addEventListener(`resize`,n);let r=window.setInterval(h,100),i=null;return typeof ResizeObserver<`u`&&(i=new ResizeObserver(n),o.current&&i.observe(o.current),Si(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)}},[h]),(0,j.useEffect)(()=>{l([]),d(null),h()},[e,h]);let g=(0,j.useMemo)(()=>Ci(e.length,c),[c,e.length]),_=(0,j.useCallback)((e,t)=>{let n=Math.ceil(t);!Number.isFinite(n)||n<=0||l(t=>{let r=t[e];if(r!=null&&Math.abs(r-n)<=1)return t;let i=[...t];return i[e]=n,i})},[]),v=(0,j.useMemo)(()=>{if(e.length===0)return[];let t=Math.max(0,f.scrollTop-f.listTop),n=t+f.height,r=Math.max(0,wi(g.items,t)-hi),i=Math.min(e.length,Ti(g.items,n)+hi),a=[];for(let e=r;e<i;e+=1){let t=g.items[e];t&&a.push({index:e,start:t.start})}if(u!=null&&u>=0&&u<e.length){let e=g.items[u];e&&!a.some(e=>e.index===u)&&(a.push({index:u,start:e.start}),a.sort((e,t)=>e.start-t.start))}return a},[u,g,e.length,f]),y=(0,j.useCallback)(e=>{if(typeof window>`u`)return;let t=g.items[e];if(!t)return;d(e);let n=o.current,r=n?Ei(n):s.current??window;s.current=r;let i=n?ki(n,r):0,a=Math.max(0,i+t.start-24);Ai(r,a);let c={scrollTop:a,height:Oi(r),listTop:i};m.current=c,p(c)},[g.items]);return(0,j.useEffect)(()=>(a.current={scrollToIndex:y},()=>{a.current?.scrollToIndex===y&&(a.current=null)}),[a,y]),(0,P.jsx)(`div`,{ref:o,className:`relative min-w-0`,style:{height:Math.max(1,g.totalSize)},children:v.map(({index:a,start:o})=>{let s=e[a];return s?(0,P.jsx)(Ni,{index:a,top:o,onMeasure:_,children:(0,P.jsx)(Ji,{msg:s.msg,blocks:s.blocks,toolAnchorIds:t,formatTokens:Zr,sessionAgentKey:n,baseDirectory:r,highlightQuery:i})},`${s.msg.id}:${s.index}`):null})})}function Ni({index:e,top:t,onMeasure:n,children:r}){let i=(0,j.useRef)(null);return(0,j.useLayoutEffect)(()=>{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,P.jsx)(`div`,{ref:i,className:`absolute left-0 top-0 w-full`,style:{transform:`translateY(${t}px)`},children:r})}function Pi({session:e,highlightQuery:t}){let n=(e.slug||``).split(`/`)[0]||M.getDefaultAgentKey()||`claudecode`,r=(0,j.useMemo)(()=>bi(`SessionDetail:normalizeMessages`,()=>zr(e.messages,n)),[e.messages,n]),i=(0,j.useMemo)(()=>bi(`SessionDetail:buildMessageDisplayModels`,()=>en(r)),[r]),{toolAnchorIds:a,anchorMessageIndexes:o,summary:s}=(0,j.useMemo)(()=>bi(`SessionDetail:buildFileChangeSummary`,()=>Ln(i)),[i]),c=(0,j.useMemo)(()=>bi(`SessionDetail:buildSessionDetailToc`,()=>Yt(i)),[i]),[l,u]=(0,j.useState)(()=>new Set(c.filterIds)),[d,f]=(0,j.useState)(null),p=(0,j.useMemo)(()=>[...c.filterIds].toSorted().join(`|`),[c.filterIds]),m=(0,j.useMemo)(()=>[...l].toSorted().join(`|`),[l]),h=(0,j.useMemo)(()=>bi(`SessionDetail:filterSessionMessages`,()=>$t(i,l)),[i,l]),g=(0,j.useRef)(null),_=(0,j.useMemo)(()=>bi(`SessionDetail:buildAnchorListIndexes`,()=>{let e=new Map;return h.forEach((t,n)=>{e.set(t.index,n)}),e}),[h]),v=(0,j.useMemo)(()=>bi(`SessionDetail:mergeFileActivitySummary`,()=>Rn(e.file_activity,s)),[e.file_activity,s]),y=(0,j.useCallback)(e=>{let t=o.get(e),n=t==null?void 0:_.get(t);yi(e,()=>{n!=null&&g.current?.scrollToIndex(n)})},[_,o]);return(0,j.useEffect)(()=>{u(new Set(c.filterIds))},[p,c.filterIds]),i.length===0?(0,P.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,P.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,P.jsx)(qi,{summary:typeof e.summary_files==`string`?e.summary_files:void 0}),(0,P.jsxs)(`div`,{className:`grid gap-6 min-[1025px]:grid-cols-[240px_minmax(0,1fr)] min-[1025px]:items-start min-[1280px]:grid-cols-[220px_minmax(0,1fr)]`,children:[(0,P.jsx)(zi,{toc:c,fileChangeSummary:v,onOpen:f}),(0,P.jsx)(Bi,{openPanel:d,toc:c,fileChangeSummary:v,baseDirectory:e.directory,selectedFilters:l,onClose:()=>f(null),onToggle:e=>u(t=>Li(t,e,c)),onJumpToAnchor:e=>{f(null),y(e)}}),(0,P.jsx)(Hi,{toc:c,fileChangeSummary:v,baseDirectory:e.directory,selectedFilters:l,onToggle:e=>u(t=>Li(t,e,c)),onJumpToAnchor:y}),(0,P.jsx)(`div`,{className:`flex min-w-0 flex-col gap-8`,children:h.length>0?(0,P.jsx)(Nt,{id:`MessageList`,detail:{messages:h.length,virtualized:h.length>pi},children:(0,P.jsx)(ji,{messages:h,toolAnchorIds:a,sessionAgentKey:n,baseDirectory:e.directory,highlightQuery:t,apiRef:g},`${e.id}:${m}`)}):(0,P.jsx)(`div`,{className:`rounded-sm border border-[var(--console-border)] bg-white p-6 text-sm text-[var(--console-muted)]`,children:`当前筛选条件下暂无可展示的消息内容。`})})]}),(0,P.jsx)(xi,{session:e,toc:c})]})}var Fi=[{id:`user`,label:`User`},{id:`agent_message`,label:`Agent Responses`},{id:`thinking`,label:`Thinking`},{id:`plan`,label:`Plans`},{id:`tools_all`,label:`Tools`}];function Ii(e){return e.tools.map(e=>e.id)}function Li(e,t,n){let r=new Set(e),i=Ii(n);if(t===`tools_all`){if(i.filter(e=>r.has(e)).length<i.length){r.add(`tools_all`);for(let e of i)r.add(e)}else{r.delete(`tools_all`);for(let e of i)r.delete(e)}return r}return t.startsWith(`tool:`)?(r.has(t)?r.delete(t):r.add(t),i.filter(e=>r.has(e)).length===i.length?r.add(`tools_all`):r.delete(`tools_all`),r):(r.has(t)?r.delete(t):r.add(t),r)}function Ri(e){return e.read.length+e.edit.length+e.write.length+e.delete.length}function zi({toc:e,fileChangeSummary:t,onOpen:n}){let r=Ri(t);return(0,P.jsxs)(`div`,{className:`flex flex-wrap gap-2 min-[1025px]:hidden`,children:[(0,P.jsxs)(`button`,{type:`button`,onClick:()=>n(`toc`),className:`console-mono inline-flex h-9 items-center gap-2 rounded-sm border border-[var(--console-border)] bg-white px-3 text-xs font-semibold uppercase tracking-[0.12em] text-[var(--console-text)] shadow-[0_1px_2px_rgba(15,23,42,0.04)] transition-colors hover:bg-[var(--console-surface-muted)]`,children:[(0,P.jsx)(ee,{className:`size-3.5 text-[var(--console-accent)]`}),`TOC`,(0,P.jsx)(`span`,{className:`text-[var(--console-muted)]`,children:e.counts.tools_all})]}),r>0?(0,P.jsxs)(`button`,{type:`button`,onClick:()=>n(`files`),className:`console-mono inline-flex h-9 items-center gap-2 rounded-sm border border-[var(--console-border)] bg-white px-3 text-xs font-semibold uppercase tracking-[0.12em] text-[var(--console-text)] shadow-[0_1px_2px_rgba(15,23,42,0.04)] transition-colors hover:bg-[var(--console-surface-muted)]`,children:[(0,P.jsx)(l,{className:`size-3.5 text-[var(--console-accent)]`}),`Files`,(0,P.jsx)(`span`,{className:`text-[var(--console-muted)]`,children:r})]}):null]})}function Bi({openPanel:e,toc:t,fileChangeSummary:n,baseDirectory:r,selectedFilters:i,onClose:a,onToggle:o,onJumpToAnchor:s}){return(0,j.useEffect)(()=>{if(!e)return;let t=e=>{e.key===`Escape`&&a()},n=document.body.style.overflow,r=window.matchMedia(`(min-width: 1025px)`),i=()=>{r.matches&&a()};return document.body.style.overflow=`hidden`,window.addEventListener(`keydown`,t),r.addEventListener(`change`,i),i(),()=>{document.body.style.overflow=n,window.removeEventListener(`keydown`,t),r.removeEventListener(`change`,i)}},[a,e]),e?(0,P.jsxs)(`div`,{className:`fixed inset-0 z-50 min-[1025px]:hidden`,children:[(0,P.jsx)(`button`,{type:`button`,"aria-label":`Close navigation panel`,onClick:a,className:`absolute inset-0 bg-black/30`}),(0,P.jsxs)(`aside`,{className:`console-scrollbar absolute right-0 top-0 h-full w-[min(90vw,380px)] overflow-y-auto border-l border-[var(--console-border)] bg-[var(--console-bg)] p-3 shadow-[-10px_0_30px_rgba(15,23,42,0.16)]`,children:[(0,P.jsxs)(`div`,{className:`mb-3 flex items-center justify-between gap-3`,children:[(0,P.jsx)(`span`,{className:`console-mono text-xs font-semibold uppercase tracking-[0.16em] text-[var(--console-text)]`,children:e===`toc`?`Session TOC`:`File Tracker`}),(0,P.jsx)(`button`,{type:`button`,"aria-label":`Close navigation panel`,onClick:a,className:`rounded-sm border border-[var(--console-border)] bg-white p-2 text-[var(--console-muted)] transition-colors hover:bg-[var(--console-surface-muted)]`,children:(0,P.jsx)(S,{className:`size-4`})})]}),e===`toc`?(0,P.jsx)(Ui,{toc:t,selectedFilters:i,onToggle:o}):(0,P.jsx)(Wi,{summary:n,baseDirectory:r,onJumpToAnchor:s})]})]}):null}function Vi({checked:e,indeterminate:t=!1,onChange:n}){let r=(0,j.useRef)(null);return(0,j.useLayoutEffect)(()=>{r.current&&(r.current.indeterminate=t)},[t]),(0,P.jsxs)(`span`,{className:`relative mt-0.5 size-3.5 shrink-0`,children:[(0,P.jsx)(`input`,{ref:r,type:`checkbox`,checked:e,"aria-checked":t?`mixed`:e,"data-indeterminate":t?`true`:void 0,onChange:n,className:`absolute inset-0 z-10 size-full cursor-pointer opacity-0`}),(0,P.jsx)(`span`,{"aria-hidden":`true`,className:`flex size-3.5 items-center justify-center rounded border ${e||t?`border-[var(--console-accent-strong)] bg-[var(--console-accent-strong)] text-white`:`border-[var(--console-border-strong)] bg-white text-transparent`}`,children:t?(0,P.jsx)(ie,{className:`size-2.5 stroke-[3]`}):e?(0,P.jsx)(g,{className:`size-2.5 stroke-[3]`}):null})]})}function Hi({toc:e,fileChangeSummary:t,baseDirectory:n,selectedFilters:r,onToggle:i,onJumpToAnchor:a}){return(0,P.jsx)(`aside`,{className:`console-scrollbar hidden min-[1025px]:sticky min-[1025px]:top-4 min-[1025px]:block min-[1025px]:max-h-[calc(100dvh-14rem)] min-[1025px]:overflow-y-auto min-[1025px]:overscroll-contain`,children:(0,P.jsxs)(`div`,{className:`space-y-4`,children:[(0,P.jsx)(Ui,{toc:e,selectedFilters:r,onToggle:i}),(0,P.jsx)(Wi,{summary:t,baseDirectory:n,onJumpToAnchor:a})]})})}function Ui({toc:e,selectedFilters:t,onToggle:n}){let r=Ii(e),i=r.filter(e=>t.has(e)).length,a=r.length>0&&i===r.length,o=i>0&&i<r.length;return(0,P.jsxs)(`div`,{className:`rounded-sm border border-[var(--console-border)] bg-white shadow-[0_1px_2px_rgba(15,23,42,0.04)]`,children:[(0,P.jsxs)(`div`,{className:`flex items-center gap-2 border-b border-[var(--console-border)] px-4 py-3`,children:[(0,P.jsx)(ee,{className:`size-3.5 text-[var(--console-accent)]`}),(0,P.jsx)(`span`,{className:`console-mono text-xs font-semibold uppercase tracking-[0.16em] text-[var(--console-text)]`,children:`Session TOC`})]}),(0,P.jsxs)(`div`,{className:`space-y-1 p-3`,children:[Fi.filter(({id:t})=>e.counts[t]>0).map(({id:r,label:i})=>(0,P.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,P.jsx)(Vi,{checked:r===`tools_all`?a:t.has(r),indeterminate:r===`tools_all`?o:!1,onChange:()=>n(r)}),(0,P.jsx)(`span`,{className:`console-mono min-w-0 flex-1 break-all text-xs leading-relaxed text-[var(--console-text)]`,children:i}),(0,P.jsx)(`span`,{className:`console-mono shrink-0 text-[11px] text-[var(--console-muted)]`,children:e.counts[r]})]},r)),e.tools.length>0?(0,P.jsx)(`div`,{className:`space-y-1 border-t border-[var(--console-border)] pt-2`,children:e.tools.map(e=>(0,P.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,P.jsx)(Vi,{checked:t.has(e.id),onChange:()=>n(e.id)}),(0,P.jsx)(`span`,{className:`console-mono min-w-0 flex-1 break-all text-xs leading-relaxed text-[var(--console-muted)]`,children:e.label}),(0,P.jsx)(`span`,{className:`console-mono shrink-0 text-[11px] text-[var(--console-muted)]`,children:e.count})]},e.id))}):null]})]})}function Wi({summary:e,baseDirectory:t,onJumpToAnchor:n}){let r=[{key:`read`,label:`Read`,Icon:E,items:e.read},{key:`edit`,label:`Edit`,Icon:d,items:e.edit},{key:`write`,label:`Write`,Icon:ae,items:e.write},{key:`delete`,label:`Delete`,Icon:_,items:e.delete}].filter(e=>e.items.length>0);return r.length===0?null:(0,P.jsxs)(`div`,{className:`rounded-sm border border-[var(--console-border)] bg-white shadow-[0_1px_2px_rgba(15,23,42,0.04)]`,children:[(0,P.jsxs)(`div`,{className:`flex items-center gap-2 border-b border-[var(--console-border)] px-4 py-3`,children:[(0,P.jsx)(l,{className:`size-3.5 text-[var(--console-accent)]`}),(0,P.jsx)(`span`,{className:`console-mono text-xs font-semibold uppercase tracking-[0.16em] text-[var(--console-text)]`,children:`File Tracker`})]}),(0,P.jsx)(`div`,{className:`space-y-3 p-3`,children:r.map(({key:e,label:r,Icon:i,items:a})=>(0,P.jsx)(Gi,{label:r,Icon:i,items:a,baseDirectory:t,onJumpToAnchor:n},e))})]})}function Gi({label:e,Icon:t,items:n,baseDirectory:r,onJumpToAnchor:i}){let[a,o]=(0,j.useState)(!1);return(0,P.jsxs)(`div`,{className:`rounded-sm border border-[var(--console-border)] bg-[#fafafa]`,children:[(0,P.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,P.jsx)(t,{className:`size-3.5 shrink-0 text-[var(--console-accent)]`}),(0,P.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,P.jsx)(`span`,{className:`console-mono shrink-0 text-[10px] text-[var(--console-muted)]`,children:n.length}),a?(0,P.jsx)(oe,{className:`size-3.5 shrink-0 text-[var(--console-muted)]`}):(0,P.jsx)(h,{className:`size-3.5 shrink-0 text-[var(--console-muted)]`})]}),a?(0,P.jsx)(`div`,{className:`space-y-1 border-t border-[var(--console-border)] p-2`,children:n.map(e=>(0,P.jsx)(Ki,{item:e,baseDirectory:r,onJumpToAnchor:i},`${e.path}:${e.latestAnchorId||e.latestTime}`))}):null]})}function Ki({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,P.jsxs)(`div`,{className:`flex items-start gap-2 rounded-sm px-2 py-2 transition-colors hover:bg-[var(--console-surface-muted)]`,children:[(0,P.jsx)(`button`,{type:`button`,title:e.path,onClick:()=>a(r),className:`min-w-0 flex-1 text-left`,children:(0,P.jsx)(`span`,{className:`console-mono block break-all text-xs text-[var(--console-text)]`,children:Nn(e.path,t)})}),e.anchors.length>1?(0,P.jsxs)(`div`,{className:`flex shrink-0 items-center gap-1`,children:[(0,P.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,P.jsx)(oe,{className:`size-3`})}),(0,P.jsxs)(`span`,{className:`console-mono text-[10px] text-[var(--console-muted)]`,children:[r+1,`/`,e.anchors.length]}),(0,P.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,P.jsx)(h,{className:`size-3`})})]}):(0,P.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 qi({summary:e,defaultExpanded:t=!1}){let n=typeof e==`string`?e.trim():``,[r,i]=(0,j.useState)(t);return n?(0,P.jsxs)(`section`,{className:`rounded-sm border border-[var(--console-border)] bg-white shadow-[0_1px_2px_rgba(15,23,42,0.04)]`,children:[(0,P.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,P.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,P.jsx)(l,{className:`size-3.5 text-[var(--console-accent)]`}),`Session Summary`]}),r?(0,P.jsx)(oe,{className:`size-3.5 text-[var(--console-muted)]`}):(0,P.jsx)(h,{className:`size-3.5 text-[var(--console-muted)]`})]}),r?(0,P.jsx)(`div`,{className:`border-t border-[var(--console-border)] px-4 py-4`,children:(0,P.jsx)(`div`,{className:`console-markdown text-sm leading-relaxed text-[var(--console-text)]`,children:(0,P.jsx)(Tt,{text:n})})}):null]}):null}function Ji({msg:e,blocks:t,toolAnchorIds:n,formatTokens:r,sessionAgentKey:i,baseDirectory:a,highlightQuery:o}){let s=e.role===`user`,c=zt(e,i),l=()=>{let e=i.toLowerCase(),t=M.getAgentName(e),n=M.agents[e]?.icon;return(0,P.jsx)(P.Fragment,{children:n?(0,P.jsx)(`img`,{src:n,alt:t,className:`size-4 rounded-sm object-cover`}):(0,P.jsx)(f,{className:`size-4 text-[var(--console-muted)]`})})},u=e.mode?e.mode.toUpperCase():null,d=e.model||null,p=Rr(e),m=Qr(e.time_created);return(0,P.jsx)(`article`,{className:`w-full border-l-2 border-[var(--console-thread)] pl-4 pr-3 md:pr-5`,children:(0,P.jsxs)(`div`,{className:`flex gap-4`,children:[(0,P.jsx)(`div`,{className:`shrink-0 pt-1`,children:(0,P.jsx)(`div`,{className:`flex size-8 items-center justify-center rounded-sm border border-[var(--console-border)] bg-[var(--console-surface-muted)]`,children:s?(0,P.jsx)(he,{className:`size-4 text-[var(--console-muted)]`}):l()})}),(0,P.jsxs)(`div`,{className:`min-w-0 flex-1 space-y-3`,children:[(0,P.jsxs)(`div`,{className:`flex items-baseline gap-3`,children:[(0,P.jsx)(`span`,{className:`console-mono text-sm font-bold tracking-wide text-[var(--console-text)]`,children:p}),(0,P.jsx)(`time`,{className:`console-mono text-xs text-[var(--console-muted)]`,children:m}),u&&(0,P.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}),d&&(0,P.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:d})]}),c?(0,P.jsx)(Yi,{}):t.map((e,t)=>e.type===`reasoning`?(0,P.jsx)(Xi,{parts:e.parts,highlightQuery:o},t):e.type===`plan`?(0,P.jsx)(Qi,{parts:e.parts,highlightQuery:o},t):e.type===`tool`?(0,P.jsx)(Zi,{parts:e.parts,toolAnchorIds:n,sessionAgentKey:i,baseDirectory:a,highlightQuery:o},t):(0,P.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,P.jsx)(`div`,{className:`console-markdown text-sm leading-relaxed text-[var(--console-text)]`,children:e.parts.map((e,t)=>(0,P.jsx)(vi,{text:Ft(e.text),highlightQuery:o},t))})},t)),!s&&(e.tokens||e.cost)&&(0,P.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[e.tokens?.input?(0,P.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,P.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,P.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,P.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 Yi(){return(0,P.jsx)(`div`,{className:`space-y-2`,children:(0,P.jsx)(`div`,{className:`flex flex-wrap items-start gap-2`,children:(0,P.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,P.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,P.jsx)(te,{className:`mt-0.5 size-3.5 shrink-0 text-[var(--console-accent)]`}),(0,P.jsx)(`span`,{className:`min-w-0 flex-1`,children:(0,P.jsx)(`span`,{className:`console-mono block text-xs font-semibold text-[var(--console-text)]`,children:`abort`})})]})})})})}function Xi({parts:e,highlightQuery:t}){let[n,r]=(0,j.useState)(!1),i=e.map(e=>Ft(e.text)).filter(Boolean).join(`
38
+
39
+ `);return(0,P.jsxs)(`div`,{className:`overflow-hidden rounded-sm border border-[var(--console-thinking-border)] bg-[var(--console-thinking-bg)]`,children:[(0,P.jsxs)(`div`,{className:`flex cursor-pointer items-center justify-between bg-[var(--console-surface-muted)] px-3 py-2`,onClick:()=>r(!n),children:[(0,P.jsxs)(`span`,{className:`console-mono flex items-center gap-2 text-xs font-medium text-[var(--console-muted)]`,children:[(0,P.jsx)(ne,{className:`size-3.5`}),`Thinking`]}),(0,P.jsx)(`span`,{className:`text-[var(--console-muted)]`,children:n?(0,P.jsx)(oe,{className:`w-4 h-4`}):(0,P.jsx)(h,{className:`w-4 h-4`})})]}),n&&(0,P.jsx)(`div`,{className:`border-t border-dashed border-[var(--console-thinking-border)] px-4 py-3`,children:(0,P.jsx)(`div`,{className:`console-mono whitespace-pre-wrap text-xs leading-relaxed text-[var(--console-muted)]`,children:_i(i,t)})})]})}function Zi({parts:e,toolAnchorIds:t,sessionAgentKey:n,baseDirectory:r,highlightQuery:i}){return(0,P.jsx)(`div`,{className:`space-y-2`,children:(0,P.jsx)(`div`,{className:`space-y-2`,children:e.map((e,a)=>(0,P.jsx)(ea,{tool:e,anchorId:t.get(e),sessionAgentKey:n,baseDirectory:r,highlightQuery:i},a))})})}function Qi({parts:e,highlightQuery:t}){return(0,P.jsx)(`div`,{className:`space-y-2`,children:e.map((e,n)=>(0,P.jsx)($i,{part:e,highlightQuery:t},n))})}function $i({part:e,highlightQuery:t}){let[n,r]=(0,j.useState)(!1),i=Vt(e),a=i.approvalStatus===`fail`?di.error:di.completed,o=a.icon;return(0,P.jsxs)(`div`,{className:`space-y-2`,children:[(0,P.jsxs)(`div`,{className:`flex flex-wrap items-start gap-2`,children:[(0,P.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,P.jsxs)(`button`,{type:`button`,className:`flex w-full items-start gap-2 text-left`,onClick:()=>r(!n),children:[(0,P.jsx)(v,{className:`mt-0.5 size-3.5 shrink-0 text-[var(--console-accent)]`}),(0,P.jsx)(`span`,{className:`min-w-0 flex-1`,children:(0,P.jsx)(`span`,{className:`console-mono block text-xs font-semibold text-[var(--console-text)]`,children:i.title})}),(0,P.jsx)(`span`,{className:`mt-0.5 shrink-0 text-[var(--console-muted)]`,children:n?(0,P.jsx)(oe,{className:`size-3.5`}):(0,P.jsx)(h,{className:`size-3.5`})})]}):(0,P.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,P.jsx)(v,{className:`mt-0.5 size-3.5 shrink-0 text-[var(--console-accent)]`}),(0,P.jsx)(`span`,{className:`min-w-0 flex-1`,children:(0,P.jsx)(`span`,{className:`console-mono block text-xs font-semibold text-[var(--console-text)]`,children:i.title})})]})}),(0,P.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,P.jsx)(o,{className:`size-3`}),a.label]})]}),i.expandable&&n?(0,P.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,P.jsx)(`div`,{className:`border-b border-[var(--console-border)] bg-[var(--console-surface-muted)] px-3 py-1.5`,children:(0,P.jsx)(`span`,{className:`console-mono text-xs text-[var(--console-muted)]`,children:i.contentLabel})}),(0,P.jsx)(`div`,{className:`p-4`,children:(0,P.jsx)(`div`,{className:`console-markdown text-sm leading-relaxed text-[var(--console-text)]`,children:(0,P.jsx)(vi,{text:i.contentMarkdown,highlightQuery:t})})})]}):null]})}function ea({tool:e,anchorId:t,sessionAgentKey:n,baseDirectory:r,highlightQuery:i}){let[a,o]=(0,j.useState)(!1),s=Br(e),c=Xr(n,e,s,r),l=Mn(s.inputText||`{}`,r),u=di[s.status],d=u.icon,f=c.Icon;return(0,P.jsxs)(`div`,{id:t,className:`scroll-mt-6 space-y-2`,children:[(0,P.jsxs)(`div`,{className:`flex flex-wrap items-start gap-2`,children:[(0,P.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)] ${c.expandable?`transition-colors hover:bg-[var(--console-surface-muted)]`:``}`,children:c.expandable?(0,P.jsxs)(`button`,{type:`button`,className:`flex w-full items-start gap-2 text-left`,onClick:()=>o(!a),children:[(0,P.jsx)(f,{className:`mt-0.5 size-3.5 shrink-0 text-[var(--console-accent)]`}),(0,P.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,P.jsx)(`span`,{className:`console-mono block text-xs font-semibold text-[var(--console-text)]`,children:c.title}),c.secondaryText?(0,P.jsx)(`span`,{className:`console-mono mt-0.5 block whitespace-pre-wrap break-words text-xs leading-relaxed text-[var(--console-muted)]`,children:_i(c.secondaryText,i)}):null]}),(0,P.jsx)(`span`,{className:`mt-0.5 shrink-0 text-[var(--console-muted)]`,children:a?(0,P.jsx)(oe,{className:`size-3.5`}):(0,P.jsx)(h,{className:`size-3.5`})})]}):(0,P.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,P.jsx)(f,{className:`mt-0.5 size-3.5 shrink-0 text-[var(--console-accent)]`}),(0,P.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,P.jsx)(`span`,{className:`console-mono block text-xs font-semibold text-[var(--console-text)]`,children:c.title}),c.secondaryText?(0,P.jsx)(`span`,{className:`console-mono mt-0.5 block whitespace-pre-wrap break-words text-xs leading-relaxed text-[var(--console-muted)]`,children:_i(c.secondaryText,i)}):null]})]})}),(0,P.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 ${u.className}`,children:[(0,P.jsx)(d,{className:`size-3 ${s.status===`running`?`animate-spin`:``}`}),u.label]})]}),c.expandable&&a?(0,P.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,P.jsx)(`div`,{className:`border-b border-[var(--console-border)] bg-[var(--console-surface-muted)] px-3 py-1.5`,children:(0,P.jsx)(`span`,{className:`console-mono text-xs text-[var(--console-muted)]`,children:`Output`})}),(0,P.jsxs)(`div`,{className:`space-y-3 p-3`,children:[c.details.length>0?(0,P.jsx)(`div`,{className:`rounded-sm border border-[var(--console-border)] bg-[#fafafa] px-3 py-2`,children:(0,P.jsx)(`div`,{className:`space-y-2`,children:c.details.map(e=>(0,P.jsxs)(`div`,{className:`flex flex-col gap-1 md:flex-row md:items-start md:gap-3`,children:[(0,P.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,P.jsx)(`span`,{className:`console-mono whitespace-pre-wrap break-all text-xs leading-relaxed text-[var(--console-text)]`,children:_i(e.value,i)})]},`${e.label}:${e.value}`))})}):null,(0,P.jsx)(ui,{outputContent:c.outputContent})]}),c.showInputPreview?(0,P.jsxs)(`div`,{className:`border-t border-[var(--console-border)] bg-[#fafafa] px-3 py-2`,children:[(0,P.jsx)(`span`,{className:`console-mono text-[11px] text-[var(--console-muted)]`,children:`Input Preview`}),(0,P.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:_i(l,i)})]}):null]}):null]})}var ta=[{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 na({className:e}){return(0,P.jsx)(`div`,{className:`rounded-sm bg-[var(--console-border)] ${e}`})}function ra(){return(0,P.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,P.jsx)(`div`,{className:`flex flex-1 flex-col gap-8`,children:ta.map(e=>(0,P.jsx)(`article`,{className:`w-full border-l-2 border-[var(--console-thread)] pl-4 pr-3 md:pr-5`,children:(0,P.jsxs)(`div`,{className:`flex gap-4`,children:[(0,P.jsx)(`div`,{className:`shrink-0 pt-1`,children:(0,P.jsx)(`div`,{className:`flex size-8 items-center justify-center rounded-sm border border-[var(--console-border)] bg-[var(--console-surface-muted)]`,children:(0,P.jsx)(`div`,{className:`size-3.5 rounded-sm bg-[var(--console-border-strong)] animate-pulse`})})}),(0,P.jsxs)(`div`,{className:`min-w-0 flex-1 space-y-3`,children:[(0,P.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,P.jsx)(na,{className:`${e.roleWidth} h-3 animate-pulse`}),(0,P.jsx)(na,{className:`${e.timeWidth} h-2.5 animate-pulse`})]}),(0,P.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,P.jsx)(`div`,{className:`space-y-2`,children:e.bodyWidths.map(t=>(0,P.jsx)(na,{className:`${t} h-3 animate-pulse`},`${e.id}-${t}`))})})]})]})},e.id))}),(0,P.jsx)(`div`,{className:`min-h-24 flex-1 rounded-sm border border-[var(--console-border)] bg-white/60 animate-pulse`})]})}function ia({active:e,onToggle:t,className:n=``}){return(0,P.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,P.jsx)(re,{className:`size-3`,strokeWidth:1.8,fill:e?`currentColor`:`none`})})}function aa(e){return e.toLocaleString(`en-US`)}function oa(e){return e===0?`$0.00`:e<.01?`$${e.toFixed(4)}`:`$${e.toFixed(2)}`}function sa(e){if(e===`recorded`)return`recorded`;if(e===`estimated`)return`estimated`}function ca(e){return e.total_tokens??e.total_input_tokens+e.total_output_tokens}function la(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 ua({label:e,value:t,hint:n}){return(0,P.jsxs)(`div`,{className:`rounded-sm border border-[var(--console-border)] bg-white p-4`,children:[(0,P.jsx)(`p`,{className:`console-mono text-[11px] uppercase tracking-wider text-[var(--console-muted)]`,children:e}),(0,P.jsx)(`p`,{className:`console-mono mt-2 text-xl font-semibold text-[var(--console-text)]`,children:t}),n?(0,P.jsx)(`p`,{className:`mt-1 text-xs text-[var(--console-muted)]`,children:n}):null]})}function da({label:e,value:t}){return(0,P.jsxs)(`div`,{className:`rounded-sm border border-[var(--console-border)] bg-[var(--console-surface-muted)] p-3`,children:[(0,P.jsx)(`p`,{className:`console-mono text-[11px] uppercase tracking-wider text-[var(--console-muted)]`,children:e}),(0,P.jsx)(`p`,{className:`console-mono mt-2 break-all text-sm leading-6 text-[var(--console-text)]`,children:t})]})}function fa({code:e,title:t,description:n,aside:r,iconSrc:i,iconAlt:a}){return(0,P.jsx)(`div`,{className:`rounded-sm border border-[var(--console-border-strong)] bg-white p-5 md:p-6`,children:(0,P.jsxs)(`div`,{className:`flex flex-col gap-5 md:flex-row md:items-start md:justify-between`,children:[(0,P.jsxs)(`div`,{className:`max-w-2xl`,children:[(0,P.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,P.jsxs)(`div`,{className:`mt-4 flex items-start gap-3`,children:[i?(0,P.jsx)(`img`,{src:i,alt:a||``,className:`mt-1 size-8 shrink-0 object-contain`}):null,(0,P.jsx)(`h2`,{className:`console-mono text-2xl leading-tight font-semibold tracking-tight text-[var(--console-text)] md:text-[2rem]`,children:t})]}),(0,P.jsx)(`p`,{className:`mt-3 max-w-[42rem] text-sm leading-7 text-[var(--console-muted)]`,children:n})]}),(0,P.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,P.jsx)(`p`,{className:`console-mono text-[11px] uppercase tracking-[0.16em] text-[var(--console-muted)]`,children:`STATUS NOTE`}),(0,P.jsx)(`p`,{className:`mt-2 text-sm leading-6 text-[var(--console-text)]`,children:r})]})]})})}function pa({agentItems:e}){return(0,P.jsxs)(`div`,{className:`rounded-sm border border-[var(--console-border)] bg-white p-4`,children:[(0,P.jsxs)(`div`,{className:`mb-3 flex items-center justify-between gap-3`,children:[(0,P.jsx)(`h3`,{className:`console-mono text-xs font-bold uppercase text-[var(--console-text)]`,children:`Known Agents`}),(0,P.jsxs)(`span`,{className:`console-mono text-[11px] text-[var(--console-muted)]`,children:[e.length,` items`]})]}),(0,P.jsx)(`ul`,{className:`grid gap-2 sm:grid-cols-2`,children:e.map(e=>(0,P.jsx)(`li`,{children:(0,P.jsxs)(y,{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,P.jsx)(`img`,{src:e.icon,alt:e.name,className:`size-4 object-contain`}),(0,P.jsx)(`span`,{className:`console-mono flex-1 text-xs text-[var(--console-text)]`,children:e.name}),(0,P.jsx)(`span`,{className:`console-mono text-[11px] text-[var(--console-muted)]`,children:e.count})]})},e.key))})]})}function ma({sessions:e,isBookmarked:t,onToggleBookmark:n}){return e.length===0?(0,P.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,P.jsxs)(`div`,{className:`rounded-sm border border-[var(--console-border)] bg-white p-4`,children:[(0,P.jsxs)(`div`,{className:`mb-3 flex items-center justify-between`,children:[(0,P.jsx)(`h3`,{className:`console-mono text-xs font-bold uppercase text-[var(--console-text)]`,children:`Recent Sessions`}),(0,P.jsxs)(`span`,{className:`console-mono text-[11px] text-[var(--console-muted)]`,children:[e.length,` items`]})]}),(0,P.jsx)(`ul`,{className:`space-y-2`,children:e.map(e=>{let r=t(e.agentKey,e.id);return(0,P.jsx)(`li`,{children:(0,P.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,P.jsxs)(y,{to:`/${e.fullPath}`,className:`min-w-0 flex-1`,children:[(0,P.jsx)(`p`,{className:`line-clamp-1 text-sm text-[var(--console-text)]`,children:e.title}),(0,P.jsxs)(`p`,{className:`console-mono mt-0.5 text-[11px] text-[var(--console-muted)]`,children:[`/`,e.fullPath,` ·`,` `,la(e.time_updated||e.time_created)]}),(0,P.jsx)(et,{tags:e.smart_tags,className:`mt-1.5`})]}),(0,P.jsx)(ia,{active:r,onToggle:()=>n(e)})]})},e.id)})})]})}function ha({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),d=t.reduce((e,t)=>e+ca(t.stats),0),f=t.reduce((e,t)=>e+t.stats.total_cost,0),p=f>0?t.some(e=>e.stats.cost_source===`estimated`)?`estimated`:`recorded`:void 0,m=c[0]?.time_updated||c[0]?.time_created;if(e===`missing-agent`){let e=`/${i||`unknown`}${a?`/${a}`:``}`;return(0,P.jsxs)(`div`,{className:`mx-auto max-w-4xl space-y-4`,children:[(0,P.jsx)(fa,{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,P.jsxs)(`div`,{className:`grid gap-3 md:grid-cols-3`,children:[(0,P.jsx)(da,{label:`Requested Agent`,value:i||`unknown`}),(0,P.jsx)(da,{label:`Requested Path`,value:e}),a?(0,P.jsx)(da,{label:`Requested Session`,value:a}):null]}),(0,P.jsx)(pa,{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,P.jsxs)(`div`,{className:`mx-auto max-w-4xl space-y-4`,children:[(0,P.jsx)(fa,{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,P.jsxs)(`div`,{className:`grid gap-3 md:grid-cols-2`,children:[(0,P.jsxs)(`div`,{className:`rounded-sm border border-[var(--console-border)] bg-[var(--console-surface-muted)] p-3`,children:[(0,P.jsx)(`p`,{className:`console-mono text-[11px] uppercase tracking-wider text-[var(--console-muted)]`,children:`Agent`}),(0,P.jsxs)(`div`,{className:`mt-2 flex items-center gap-2`,children:[i?(0,P.jsx)(`img`,{src:i,alt:n,className:`size-4 shrink-0 object-contain`}):null,(0,P.jsx)(`p`,{className:`console-mono break-all text-sm leading-6 text-[var(--console-text)]`,children:n})]})]}),(0,P.jsx)(da,{label:`Session`,value:c})]}),(0,P.jsx)(ma,{sessions:l,isBookmarked:o,onToggleBookmark:s})]})}if(e===`global`)return(0,P.jsxs)(`div`,{className:`mx-auto max-w-4xl space-y-4`,children:[(0,P.jsxs)(`div`,{className:`grid gap-3 md:grid-cols-3`,children:[(0,P.jsx)(ua,{label:`Total Sessions`,value:aa(t.length)}),(0,P.jsx)(ua,{label:`Total Messages`,value:aa(u)}),(0,P.jsx)(ua,{label:`Latest Activity`,value:la(m),hint:m?new Date(m).toLocaleString(`zh-CN`):void 0})]}),(0,P.jsxs)(`div`,{className:`rounded-sm border border-[var(--console-border)] bg-white p-4`,children:[(0,P.jsx)(`h3`,{className:`console-mono mb-3 text-xs font-bold uppercase text-[var(--console-text)]`,children:`Agents`}),(0,P.jsx)(`ul`,{className:`grid gap-2 sm:grid-cols-2`,children:n.map(e=>(0,P.jsx)(`li`,{children:(0,P.jsxs)(y,{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,P.jsx)(`img`,{src:e.icon,alt:e.name,className:`size-4 object-contain`}),(0,P.jsx)(`span`,{className:`console-mono flex-1 text-xs text-[var(--console-text)]`,children:e.name}),(0,P.jsx)(`span`,{className:`console-mono text-[11px] text-[var(--console-muted)]`,children:e.count})]})},e.key))})]}),(0,P.jsx)(ma,{sessions:l,isBookmarked:o,onToggleBookmark:s})]});let h=r?M.agents[r]:null,g=h?h.name:`Unknown Agent`;return(0,P.jsxs)(`div`,{className:`mx-auto max-w-4xl space-y-4`,children:[(0,P.jsx)(`div`,{className:`rounded-sm border border-[var(--console-border)] bg-white p-4`,children:(0,P.jsxs)(`div`,{className:`flex items-center gap-3`,children:[h?(0,P.jsx)(`img`,{src:h.icon,alt:g,className:`size-6 object-contain`}):null,(0,P.jsxs)(`div`,{children:[(0,P.jsx)(`h3`,{className:`console-mono text-sm font-semibold text-[var(--console-text)]`,children:g}),(0,P.jsx)(`p`,{className:`console-mono text-xs text-[var(--console-muted)]`,children:`Select a session from the left to view details`})]})]})}),(0,P.jsxs)(`div`,{className:`grid gap-3 md:grid-cols-4`,children:[(0,P.jsx)(ua,{label:`Sessions`,value:aa(t.length)}),(0,P.jsx)(ua,{label:`Messages`,value:aa(u)}),(0,P.jsx)(ua,{label:`Tokens`,value:aa(d)}),(0,P.jsx)(ua,{label:`Total Cost`,value:oa(f),hint:sa(p)})]}),(0,P.jsx)(ma,{sessions:l,isBookmarked:o,onToggleBookmark:s})]})}var ga=`codesesh:bookmarks:v1`;function _a(e){return typeof e==`object`&&!!e}function va(e){return _a(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 ya(e){return _a(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`)&&va(e.stats):!1}function ba(e,t){return`${e}:${t}`}function xa(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 Sa(){if(typeof window>`u`)return[];try{let e=window.localStorage.getItem(ga);if(!e)return[];let t=JSON.parse(e);return Array.isArray(t)?t.filter(ya).toSorted(wa):[]}catch{return[]}}function Ca(){typeof window>`u`||window.localStorage.removeItem(ga)}function wa(e,t){let n=e.time_updated??e.time_created;return(t.time_updated??t.time_created)-n}function Ta(e,t){if(e.length===0||t.length===0)return e;let n=new Map(t.map(e=>{let t=xa(e,e.slug.split(`/`)[0]?.toLowerCase()??`unknown`);return[ba(t.agentKey,t.sessionId),t]})),r=!1,i=e.map(e=>{let t=n.get(ba(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(wa):e}var Ea=new Set([`git_remote`,`git_common_dir`,`manifest_path`,`synthetic`,`path`,`loose`]);function Da(e){return Ea.has(e)}function Oa(e){return`${e.kind}:${e.key}`}function ka(e){return decodeURIComponent(e)}function Aa(e){return`/projects/${encodeURIComponent(e.kind)}/${encodeURIComponent(e.key)}`}function ja(...e){return me(de(e))}var Ma={light:``,dark:`.dark`},Na={width:320,height:200},Pa=j.createContext(null);function Fa(){let e=j.useContext(Pa);if(!e)throw Error(`useChart must be used within a <ChartContainer />`);return e}function Ia({id:e,className:t,children:n,config:r,initialDimension:i=Na,...a}){let o=j.useId(),s=`chart-${e??o.replace(/:/g,``)}`;return(0,P.jsx)(Pa.Provider,{value:{config:r},children:(0,P.jsxs)(`div`,{"data-slot":`chart`,"data-chart":s,className:ja(`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,P.jsx)(La,{id:s,config:r}),(0,P.jsx)(x,{initialDimension:i,children:n})]})})}var La=({id:e,config:t})=>{let n=Object.entries(t).filter(([,e])=>e.theme??e.color);return n.length?(0,P.jsx)(`style`,{dangerouslySetInnerHTML:{__html:Object.entries(Ma).map(([t,r])=>`
40
+ ${r} [data-chart=${e}] {
41
+ ${n.map(([e,n])=>{let r=n.theme?.[t]??n.color;return r?` --color-${e}: ${r};`:null}).join(`
42
+ `)}
43
+ }
44
+ `).join(`
45
+ `)}}):null},Ra=w;function za({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}=Fa(),m=j.useMemo(()=>{if(i||!t?.length)return null;let[e]=t,n=Ba(p,e,`${f??e?.dataKey??e?.name??`value`}`),r=!f&&typeof o==`string`?p[o]?.label??o:n?.label;return s?(0,P.jsx)(`div`,{className:ja(`font-medium`,c),children:s(r,t)}):r?(0,P.jsx)(`div`,{className:ja(`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,P.jsxs)(`div`,{className:ja(`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,P.jsx)(`div`,{className:`grid gap-1.5`,children:t.filter(e=>e.type!==`none`).map((e,t)=>{let n=Ba(p,e,`${d??e.name??e.dataKey??`value`}`),i=u??e.payload?.fill??e.color;return(0,P.jsx)(`div`,{className:ja(`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,P.jsxs)(P.Fragment,{children:[n?.icon?(0,P.jsx)(n.icon,{}):!a&&(0,P.jsx)(`div`,{className:ja(`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,P.jsxs)(`div`,{className:ja(`flex flex-1 justify-between leading-none`,h?`items-end`:`items-center`),children:[(0,P.jsxs)(`div`,{className:`grid gap-1.5`,children:[h?m:null,(0,P.jsx)(`span`,{className:`text-muted-foreground`,children:n?.label??e.name})]}),e.value!=null&&(0,P.jsx)(`span`,{className:`font-mono font-medium text-foreground tabular-nums`,children:typeof e.value==`number`?e.value.toLocaleString():String(e.value)})]})]})},t)})})]})}function Ba(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 Va(e){return e.toLocaleString(`en-US`)}function Ha(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}k`:Va(e)}function Ua(e){return e===0?`$0.00`:e<.01?`$${e.toFixed(4)}`:`$${e.toFixed(2)}`}function Wa(e){if(e===`recorded`)return`recorded`;if(e===`estimated`)return`estimated`}function Ga(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 Ka({label:e,value:t,hint:n}){return(0,P.jsxs)(`div`,{className:`rounded-sm border border-[var(--console-border)] bg-white p-4`,children:[(0,P.jsx)(`p`,{className:`console-mono text-[11px] uppercase tracking-wider text-[var(--console-muted)]`,children:e}),(0,P.jsx)(`p`,{className:`console-mono mt-2 text-xl font-semibold text-[var(--console-text)]`,children:t}),n?(0,P.jsx)(`p`,{className:`mt-1 text-xs text-[var(--console-muted)]`,children:n}):null]})}function qa(e){return e.length>=10?e.slice(5):e}function Ja({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,P.jsxs)(`div`,{className:`rounded-sm border border-[var(--console-border)] bg-white p-4`,children:[(0,P.jsxs)(`div`,{className:`mb-3 flex items-center justify-between gap-3`,children:[(0,P.jsxs)(`div`,{children:[(0,P.jsx)(`h3`,{className:`console-mono text-xs font-bold uppercase text-[var(--console-text)]`,children:`Daily Activity`}),(0,P.jsxs)(`p`,{className:`console-mono mt-1 text-[11px] text-[var(--console-muted)]`,children:[`Session activity · last `,e.length,` days`]})]}),(0,P.jsx)(`span`,{className:`console-mono text-right text-[11px] text-[var(--console-muted)]`,children:t?`${t.date} · ${Va(t.sessions)} sessions · ${Va(t.messages)} msgs`:`${Va(i)} in range`})]}),(0,P.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,P.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,P.jsx)(`div`,{className:`console-mono mt-2 flex text-[10px] text-[var(--console-muted)]`,children:e.map((e,t)=>(0,P.jsx)(`span`,{className:`flex-1 text-center`,children:a.has(t)?qa(e.date):``},e.date))})]})}var Ya={input:`#4A9EFF`,output:`#7C5CFF`,cache_read:`#3FB68B`,cache_create:`#E8A23B`},Xa={input:`Input`,output:`Output`,cache_read:`Cache Read`,cache_create:`Cache Create`};function Za({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,P.jsxs)(`div`,{className:`rounded-sm border border-[var(--console-border)] bg-white p-4`,children:[(0,P.jsxs)(`div`,{className:`mb-3 flex items-center justify-between gap-3`,children:[(0,P.jsxs)(`div`,{children:[(0,P.jsx)(`h3`,{className:`console-mono text-xs font-bold uppercase text-[var(--console-text)]`,children:`Daily Token Activity`}),(0,P.jsxs)(`p`,{className:`console-mono mt-1 text-[11px] text-[var(--console-muted)]`,children:[`Token breakdown · last `,e.length,` days`]})]}),(0,P.jsx)(`span`,{className:`console-mono text-right text-[11px] text-[var(--console-muted)]`,children:t?`${t.date} · ${Ha(t.input+t.output+t.cache_read+t.cache_create)} total`:`${Ha(i)} in range`})]}),t?(0,P.jsx)(`div`,{className:`mb-2 flex gap-4`,children:[`input`,`output`,`cache_read`,`cache_create`].map(e=>(0,P.jsxs)(`span`,{className:`console-mono flex items-center gap-1.5 text-[10px] text-[var(--console-muted)]`,children:[(0,P.jsx)(`span`,{className:`inline-block size-2 rounded-full`,style:{backgroundColor:Ya[e]}}),Xa[e],`: `,Ha(t[e])]},e))}):(0,P.jsx)(`div`,{className:`mb-2 flex gap-4`,children:[`input`,`output`,`cache_read`,`cache_create`].map(e=>(0,P.jsxs)(`span`,{className:`console-mono flex items-center gap-1.5 text-[10px] text-[var(--console-muted)]`,children:[(0,P.jsx)(`span`,{className:`inline-block size-2 rounded-full`,style:{backgroundColor:Ya[e]}}),Xa[e]]},e))}),(0,P.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,P.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,P.jsx)(`div`,{style:{height:`${t}px`,backgroundColor:Ya[e.key]}},e.key)}):(0,P.jsx)(`div`,{className:`h-full bg-[var(--console-surface-muted)]`})},e.date)})}),(0,P.jsx)(`div`,{className:`console-mono mt-2 flex text-[10px] text-[var(--console-muted)]`,children:e.map((e,t)=>(0,P.jsx)(`span`,{className:`flex-1 text-center`,children:a.has(t)?qa(e.date):``},e.date))})]})}var Qa=[`#4A9EFF`,`#7C5CFF`,`#3FB68B`,`#E8A23B`,`#E5484D`,`#5BCEDA`,`#F472B6`,`#A78BFA`,`#FB923C`,`#6EE7B7`];function $a({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,P.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:Qa[t%Qa.length]})),i=r.reduce((e,t)=>(e[t.chartKey]={label:t.model,color:t.fill},e),{});return(0,P.jsxs)(`div`,{className:`rounded-sm border border-[var(--console-border)] bg-white p-4`,children:[(0,P.jsxs)(`div`,{className:`mb-3 flex items-center justify-between gap-3`,children:[(0,P.jsx)(`h3`,{className:`console-mono text-xs font-bold uppercase text-[var(--console-text)]`,children:`Model Distribution`}),(0,P.jsxs)(`span`,{className:`console-mono text-[11px] text-[var(--console-muted)]`,children:[t.length,` models`]})]}),(0,P.jsxs)(`div`,{className:`flex items-center gap-6`,children:[(0,P.jsxs)(`div`,{className:`flex shrink-0 flex-col items-center`,children:[(0,P.jsx)(Ia,{config:i,className:`aspect-square size-[160px]`,children:(0,P.jsxs)(ue,{children:[(0,P.jsx)(Ra,{content:(0,P.jsx)(za,{hideLabel:!0,nameKey:`chartKey`,formatter:e=>(0,P.jsxs)(`span`,{className:`font-mono font-medium text-foreground tabular-nums`,children:[Va(Number(e)),` tokens`]})})}),(0,P.jsx)(pe,{data:r,dataKey:`tokens`,nameKey:`chartKey`,outerRadius:70,paddingAngle:1,strokeWidth:0,isAnimationActive:!1})]})}),(0,P.jsxs)(`div`,{className:`console-mono -mt-1 text-center`,children:[(0,P.jsx)(`div`,{className:`text-xs font-semibold text-[var(--console-text)]`,children:Ha(n)}),(0,P.jsx)(`div`,{className:`text-[10px] text-[var(--console-muted)]`,children:`tokens`})]})]}),(0,P.jsx)(`ul`,{className:`min-w-0 flex-1 space-y-1.5`,children:r.map(e=>(0,P.jsxs)(`li`,{className:`flex items-center gap-2`,children:[(0,P.jsx)(`span`,{className:`inline-block size-2.5 shrink-0 rounded-full`,style:{backgroundColor:e.fill}}),(0,P.jsx)(`span`,{className:`console-mono min-w-0 flex-1 truncate text-xs text-[var(--console-text)]`,children:e.model}),(0,P.jsxs)(`span`,{className:`console-mono shrink-0 text-[11px] text-[var(--console-muted)]`,children:[(e.fraction*100).toFixed(1),`%`]})]},e.model))})]})]})}function eo({perAgent:e}){let t=(0,j.useMemo)(()=>e.reduce((e,t)=>e+t.sessions,0),[e]);return t===0||e.length===0?(0,P.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,P.jsxs)(`div`,{className:`rounded-sm border border-[var(--console-border)] bg-white p-4`,children:[(0,P.jsxs)(`div`,{className:`mb-3 flex items-center justify-between gap-3`,children:[(0,P.jsx)(`h3`,{className:`console-mono text-xs font-bold uppercase text-[var(--console-text)]`,children:`Agent Distribution`}),(0,P.jsxs)(`span`,{className:`console-mono text-[11px] text-[var(--console-muted)]`,children:[e.length,` agents`]})]}),(0,P.jsx)(`ul`,{className:`space-y-2`,children:e.map(e=>{let n=t>0?e.sessions/t*100:0;return(0,P.jsx)(`li`,{children:(0,P.jsxs)(y,{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,P.jsxs)(`div`,{className:`flex items-center gap-2`,children:[e.icon?(0,P.jsx)(`img`,{src:e.icon,alt:e.displayName,className:`size-4 object-contain`}):null,(0,P.jsx)(`span`,{className:`console-mono flex-1 text-xs text-[var(--console-text)]`,children:e.displayName}),(0,P.jsxs)(`span`,{className:`console-mono text-[11px] text-[var(--console-muted)]`,children:[Va(e.sessions),` · `,n.toFixed(1),`%`]})]}),(0,P.jsx)(`div`,{className:`mt-1.5 h-1.5 overflow-hidden rounded-sm bg-[var(--console-surface-muted)]`,children:(0,P.jsx)(`div`,{className:`h-full bg-[var(--console-accent)]`,style:{width:`${n}%`}})}),(0,P.jsxs)(`div`,{className:`console-mono mt-1 flex gap-3 text-[10px] text-[var(--console-muted)]`,children:[(0,P.jsxs)(`span`,{children:[Va(e.messages),` msgs`]}),(0,P.jsxs)(`span`,{children:[Ha(e.tokens),` tokens`]})]})]})},e.name)})})]})}function to({projects:e}){return e.length===0?null:(0,P.jsxs)(`div`,{className:`rounded-sm border border-[var(--console-border)] bg-white p-4`,children:[(0,P.jsxs)(`div`,{className:`mb-3 flex items-center justify-between gap-3`,children:[(0,P.jsx)(`h3`,{className:`console-mono text-xs font-bold uppercase text-[var(--console-text)]`,children:`Projects`}),(0,P.jsx)(y,{to:`/projects`,className:`console-mono text-[11px] text-[var(--console-muted)] transition-colors hover:text-[var(--console-text)]`,children:`View all`})]}),(0,P.jsx)(`ul`,{className:`space-y-2`,children:e.slice(0,5).map(e=>{let t=e.agentStats.slice(0,3);return(0,P.jsx)(`li`,{children:(0,P.jsxs)(y,{to:Aa({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,P.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,P.jsx)(`span`,{className:`console-mono min-w-0 flex-1 truncate text-xs text-[var(--console-text)]`,children:e.displayName}),(0,P.jsxs)(`span`,{className:`console-mono shrink-0 text-[11px] text-[var(--console-muted)]`,children:[Va(e.sessionCount),` · `,Ua(e.cost)]})]}),(0,P.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,P.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,P.jsx)(`img`,{src:t.icon,alt:t.name,className:`size-3 object-contain`}):null,t?.name??e.name,` · `,e.sessions]},e.name)}),(0,P.jsxs)(`span`,{className:`console-mono min-w-0 truncate text-[10px] text-[var(--console-muted)]`,children:[Ha(e.tokens),` tokens`]})]})]})},`${e.identityKind}:${e.identityKey}`)})})]})}function no({sessions:e,onToggleBookmark:t}){return e.length===0?null:(0,P.jsxs)(`div`,{className:`rounded-sm border border-[var(--console-border)] bg-white p-4`,children:[(0,P.jsxs)(`div`,{className:`mb-3 flex items-center justify-between`,children:[(0,P.jsx)(`h3`,{className:`console-mono text-xs font-bold uppercase text-[var(--console-text)]`,children:`Bookmarked Sessions`}),(0,P.jsxs)(`span`,{className:`console-mono text-[11px] text-[var(--console-muted)]`,children:[e.length,` items`]})]}),(0,P.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,P.jsx)(`li`,{children:(0,P.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,P.jsxs)(y,{to:`/${e.fullPath}`,className:`flex min-w-0 flex-1 items-start gap-2`,children:[n?.icon?(0,P.jsx)(`img`,{src:n.icon,alt:n.name,className:`mt-0.5 size-3.5 shrink-0 object-contain`}):null,(0,P.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,P.jsx)(`p`,{className:`line-clamp-1 text-sm text-[var(--console-text)]`,children:e.title}),(0,P.jsxs)(`p`,{className:`console-mono mt-0.5 line-clamp-1 text-[11px] text-[var(--console-muted)]`,children:[`/`,e.fullPath,` · `,Ga(r)]})]})]}),(0,P.jsx)(ia,{active:!0,onToggle:()=>t(e)})]})},ba(e.agentKey,e.sessionId))})})]})}function ro({sessions:e,isBookmarked:t,onToggleBookmark:n}){return e.length===0?(0,P.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,P.jsxs)(`div`,{className:`rounded-sm border border-[var(--console-border)] bg-white p-4`,children:[(0,P.jsxs)(`div`,{className:`mb-3 flex items-center justify-between`,children:[(0,P.jsx)(`h3`,{className:`console-mono text-xs font-bold uppercase text-[var(--console-text)]`,children:`Recent Activity`}),(0,P.jsxs)(`span`,{className:`console-mono text-[11px] text-[var(--console-muted)]`,children:[e.length,` items`]})]}),(0,P.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,P.jsx)(`li`,{children:(0,P.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,P.jsxs)(y,{to:`/${e.slug}`,className:`min-w-0 flex-1`,children:[(0,P.jsxs)(`div`,{className:`flex items-center gap-2`,children:[i?.icon?(0,P.jsx)(`img`,{src:i.icon,alt:i.name,className:`size-3.5 shrink-0 object-contain`}):null,(0,P.jsx)(`p`,{className:`line-clamp-1 flex-1 text-sm text-[var(--console-text)]`,children:e.title}),(0,P.jsx)(`span`,{className:`console-mono shrink-0 text-[11px] text-[var(--console-muted)]`,children:Ga(a)})]}),(0,P.jsxs)(`p`,{className:`console-mono mt-0.5 line-clamp-1 text-[11px] text-[var(--console-muted)]`,children:[`/`,e.slug]}),(0,P.jsx)(et,{tags:e.smart_tags,className:`mt-1.5`})]}),(0,P.jsx)(ia,{active:o,onToggle:()=>n(e,r)})]})},e.id)})})]})}function io({activity:e}){return e.length===0?(0,P.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,P.jsxs)(`div`,{className:`rounded-sm border border-[var(--console-border)] bg-white p-4`,children:[(0,P.jsxs)(`div`,{className:`mb-3 flex items-center justify-between`,children:[(0,P.jsx)(`h3`,{className:`console-mono text-xs font-bold uppercase text-[var(--console-text)]`,children:`Recently Touched Files`}),(0,P.jsxs)(`span`,{className:`console-mono text-[11px] text-[var(--console-muted)]`,children:[e.length,` files`]})]}),(0,P.jsx)(`ul`,{className:`space-y-2`,children:e.map(e=>{let t=e.latest_time;return(0,P.jsx)(`li`,{children:(0,P.jsxs)(y,{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,P.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,P.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,P.jsx)(`span`,{className:`console-mono min-w-0 flex-1 truncate text-xs text-[var(--console-text)]`,children:e.path}),(0,P.jsx)(`span`,{className:`console-mono shrink-0 text-[11px] text-[var(--console-muted)]`,children:Ga(t)})]}),(0,P.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 ao({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,P.jsxs)(`div`,{"data-testid":`dashboard`,className:`mx-auto max-w-5xl space-y-4`,children:[(0,P.jsxs)(`div`,{className:`grid gap-3 md:grid-cols-5`,children:[(0,P.jsx)(Ka,{label:`Total Sessions`,value:Va(a.sessions)}),(0,P.jsx)(Ka,{label:`Total Messages`,value:Va(a.messages)}),(0,P.jsx)(Ka,{label:`Total Tokens`,value:Ha(a.tokens)}),(0,P.jsx)(Ka,{label:`Total Cost`,value:Ua(a.cost),hint:Wa(a.cost_source)}),(0,P.jsx)(Ka,{label:`Latest Activity`,value:Ga(a.latestActivity),hint:a.latestActivity?new Date(a.latestActivity).toLocaleString(`zh-CN`):void 0})]}),(0,P.jsx)(Ja,{buckets:s}),(0,P.jsx)(Za,{buckets:c}),(0,P.jsxs)(`div`,{className:`grid gap-4 lg:grid-cols-2`,children:[(0,P.jsx)($a,{entries:l}),(0,P.jsx)(eo,{perAgent:o})]}),(0,P.jsx)(to,{projects:t}),(0,P.jsx)(ro,{sessions:u,isBookmarked:r,onToggleBookmark:i}),(0,P.jsx)(io,{activity:d}),(0,P.jsx)(no,{sessions:n,onToggleBookmark:e=>i(e)})]})}function oo(e){return e.toLocaleString(`en-US`)}function so(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}k`:oo(e)}function co(e){return e===0?`$0.00`:e<.01?`$${e.toFixed(4)}`:`$${e.toFixed(2)}`}function lo(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 uo(e){return e.stats.total_tokens??e.stats.total_input_tokens+e.stats.total_output_tokens}function fo({label:e,value:t,hint:n}){return(0,P.jsxs)(`div`,{className:`rounded-sm border border-[var(--console-border)] bg-white p-4`,children:[(0,P.jsx)(`p`,{className:`console-mono text-[11px] uppercase tracking-wider text-[var(--console-muted)]`,children:e}),(0,P.jsx)(`p`,{className:`console-mono mt-2 text-xl font-semibold text-[var(--console-text)]`,children:t}),n?(0,P.jsx)(`p`,{className:`mt-1 text-xs text-[var(--console-muted)]`,children:n}):null]})}function po({agents:e}){return e.length===0?null:(0,P.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,P.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,P.jsx)(`img`,{src:t.icon,alt:t.name,className:`size-3 object-contain`}):null,t?.name??e.name,` · `,e.sessions]},e.name)})})}function mo({project:e}){return(0,P.jsx)(`li`,{children:(0,P.jsxs)(y,{to:Aa({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,P.jsxs)(`div`,{className:`flex flex-col gap-3 md:flex-row md:items-start md:justify-between`,children:[(0,P.jsxs)(`div`,{className:`min-w-0`,children:[(0,P.jsx)(`h2`,{className:`console-mono line-clamp-1 text-sm font-semibold text-[var(--console-text)]`,children:e.displayName}),(0,P.jsx)(`p`,{className:`console-mono mt-1 break-all text-[11px] text-[var(--console-muted)]`,children:e.identityKey})]}),(0,P.jsxs)(`div`,{className:`console-mono flex shrink-0 flex-wrap gap-2 text-[11px] text-[var(--console-muted)]`,children:[(0,P.jsxs)(`span`,{children:[oo(e.sessionCount),` sessions`]}),(0,P.jsxs)(`span`,{children:[so(e.tokens),` tokens`]}),(0,P.jsx)(`span`,{children:co(e.cost)}),(0,P.jsx)(`span`,{children:lo(e.lastActivity)})]})]}),(0,P.jsxs)(`div`,{className:`mt-3 flex flex-col gap-2 md:flex-row md:items-center md:justify-between`,children:[(0,P.jsx)(po,{agents:e.agentStats}),(0,P.jsx)(`span`,{className:`console-mono text-[10px] uppercase text-[var(--console-muted)]`,children:e.identityKind})]})]})})}function ho({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,P.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,P.jsxs)(`div`,{className:`mx-auto max-w-5xl space-y-4`,children:[(0,P.jsxs)(`div`,{className:`grid gap-3 md:grid-cols-4`,children:[(0,P.jsx)(fo,{label:`Projects`,value:oo(e.length)}),(0,P.jsx)(fo,{label:`Sessions`,value:oo(t)}),(0,P.jsx)(fo,{label:`Tokens`,value:so(n)}),(0,P.jsx)(fo,{label:`Total Cost`,value:co(r),hint:i?`Latest ${lo(i)}`:void 0})]}),(0,P.jsx)(`ul`,{className:`grid gap-3`,children:e.map(e=>(0,P.jsx)(mo,{project:e},`${e.identityKind}:${e.identityKey}`))})]})}function go({agents:e,activeAgent:t,onChange:n}){return(0,P.jsx)(`div`,{className:`rounded-sm border border-[var(--console-border)] bg-white p-3`,children:(0,P.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,P.jsx)(`span`,{className:`console-mono text-[10px] font-semibold uppercase text-[var(--console-muted)]`,children:`Agent`}),(0,P.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,P.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,P.jsx)(`img`,{src:r.icon,alt:r.name,className:`size-3 object-contain`}):null,r?.name??e.name,` · `,e.sessions]},e.name)})]})})}function _o({project:e}){return(0,P.jsx)(`div`,{className:`rounded-sm border border-[var(--console-border)] bg-white p-4`,children:(0,P.jsxs)(`div`,{className:`flex flex-col gap-3 md:flex-row md:items-start md:justify-between`,children:[(0,P.jsxs)(`div`,{className:`min-w-0`,children:[(0,P.jsx)(`h2`,{className:`console-mono text-base font-semibold text-[var(--console-text)]`,children:e.displayName}),(0,P.jsxs)(`p`,{className:`console-mono mt-1 break-all text-[11px] text-[var(--console-muted)]`,children:[e.identityKind,`: `,e.identityKey]})]}),(0,P.jsx)(po,{agents:e.agentStats})]})})}function vo({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,P.jsxs)(`div`,{className:`rounded-sm border border-[var(--console-border)] bg-white p-4`,children:[(0,P.jsxs)(`div`,{className:`mb-3 flex items-center justify-between gap-3`,children:[(0,P.jsx)(`h3`,{className:`console-mono text-xs font-bold uppercase text-[var(--console-text)]`,children:`Top Cost`}),(0,P.jsxs)(`span`,{className:`console-mono text-[11px] text-[var(--console-muted)]`,children:[t.length,` sessions`]})]}),(0,P.jsx)(`ul`,{className:`space-y-2`,children:t.map(e=>{let t=M.agents[e.agentKey];return(0,P.jsx)(`li`,{children:(0,P.jsxs)(y,{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,P.jsxs)(`div`,{className:`flex items-center gap-2`,children:[t?.icon?(0,P.jsx)(`img`,{src:t.icon,alt:t.name,className:`size-3.5 object-contain`}):null,(0,P.jsx)(`span`,{className:`line-clamp-1 flex-1 text-sm text-[var(--console-text)]`,children:e.title}),(0,P.jsx)(`span`,{className:`console-mono text-[11px] text-[var(--console-muted)]`,children:co(e.stats.total_cost)})]}),(0,P.jsxs)(`p`,{className:`console-mono mt-1 text-[11px] text-[var(--console-muted)]`,children:[`/`,e.fullPath,` · `,so(uo(e)),` tokens`]})]})},e.fullPath)})})]})}function yo({project:e,projectKey:t,dashboard:n,loading:r,error:i,sessions:a,activeAgent:o,onChangeAgent:s,isBookmarked:c,onToggleSessionBookmark:l}){if(!e)return(0,P.jsxs)(`div`,{className:`mx-auto max-w-4xl rounded-sm border border-[var(--console-border)] bg-white p-6`,children:[(0,P.jsx)(`h2`,{className:`console-mono text-sm font-semibold text-[var(--console-text)]`,children:`Project Not Found`}),(0,P.jsx)(`p`,{className:`console-mono mt-2 break-all text-xs text-[var(--console-muted)]`,children:t}),(0,P.jsx)(y,{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,P.jsxs)(`div`,{className:`mx-auto max-w-5xl space-y-4`,children:[(0,P.jsx)(_o,{project:e}),(0,P.jsx)(go,{agents:e.agentStats,activeAgent:o,onChange:s}),r?(0,P.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,P.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,P.jsx)(ao,{data:n,projects:[],bookmarkedSessions:[],isBookmarked:c,onToggleBookmark:(e,t)=>{`agentName`in e&&l(e,t??e.agentName.toLowerCase())}}):null,(0,P.jsx)(vo,{sessions:u})]})}var bo=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,P.jsxs)(`div`,{className:`rounded-sm border border-[var(--console-error-border)] bg-[var(--console-error-bg)] p-6`,children:[(0,P.jsx)(`h3`,{className:`console-mono mb-2 text-sm font-semibold text-[var(--console-error)]`,children:`Something went wrong`}),(0,P.jsx)(`p`,{className:`console-mono text-xs text-[var(--console-muted)]`,children:this.state.error?.message||`Unknown error`})]}):this.props.children}};function xo(e){return`'${e.replace(/'/g,`'\\''`)}'`}var So={claudecode:`claude --resume`,codex:`codex resume`,kimi:`kimi -r`,opencode:`opencode -s`,pi:`pi --session`};function Co(e){let t=e.toLowerCase();return t in So?So[t]:null}function wo({agentName:e,sessionId:t,directory:n}){let r=Co(e);if(!r)return null;let i=`${r} ${xo(t)}`,a=n??``;return a.trim()?`cd ${xo(a)} && ${i}`:i}async function To(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 Eo({agentName:e,sessionId:t,directory:n,className:r=``}){let[i,a]=(0,j.useState)(!1),o=wo({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,P.jsxs)(`button`,{type:`button`,onClick:e=>{e.preventDefault(),e.stopPropagation(),To(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,P.jsx)(g,{className:`size-3`,strokeWidth:1.8}):(0,P.jsx)(u,{className:`size-3`,strokeWidth:1.8}),(0,P.jsx)(`span`,{children:i?`Copied`:`Copy resume`})]}):null}var Do=`
46
+ [data-type='item'][data-item-type='file'] > [data-item-section='icon'] {
47
+ display: none;
48
+ }
49
+
50
+ [data-type='item'][data-item-type='file'] > [data-item-section='spacing'] {
51
+ padding-left: 2px;
52
+ }
53
+
54
+ [data-type='item'][data-item-type='file'] > [data-item-section='spacing'] > [data-item-section='spacing-item'] {
55
+ margin-right: 4px;
56
+ }
57
+
58
+ [data-type='item'][data-item-type='file'] > [data-item-section='content'] {
59
+ flex: 1 1 auto;
60
+ }
61
+
62
+ [data-type='item'][data-item-type='file'] > [data-item-section='decoration'] {
63
+ flex: 0 0 auto;
64
+ padding-inline: 8px 6px;
65
+ }
66
+
67
+ [data-type='item'][data-item-type='file'] > [data-item-section='decoration'] > span {
68
+ cursor: pointer;
69
+ font-size: 18px;
70
+ line-height: 1;
71
+ }
72
+
73
+ [data-type='item'][data-item-type='file'] [data-truncate-group-container='middle'] {
74
+ width: 100%;
75
+ }
76
+
77
+ [data-type='item'][data-item-type='file']
78
+ [data-truncate-group-container='middle']
79
+ > div[data-truncate-segment-priority='2'] {
80
+ flex: 0 1 auto;
81
+ }
82
+
83
+ [data-type='item'][data-item-type='file']
84
+ [data-truncate-group-container='middle']
85
+ > div[data-truncate-segment-priority='1'] {
86
+ flex: 1 999999 auto;
87
+ }
88
+
89
+ [data-type='item'][data-item-type='file']
90
+ [data-truncate-group-container='middle']
91
+ [data-truncate-container='fruncate']
92
+ [data-truncate-grid] {
93
+ grid-template-columns: minmax(0, max-content) 0;
94
+ }
95
+
96
+ [data-type='item'][data-item-type='file']
97
+ [data-truncate-group-container='middle']
98
+ [data-truncate-container='fruncate']
99
+ [data-truncate-content] {
100
+ direction: ltr;
101
+ }
102
+
103
+ [data-type='item'][data-item-type='file']
104
+ [data-truncate-group-container='middle']
105
+ [data-truncate-container='fruncate']
106
+ [data-truncate-marker] {
107
+ right: 0;
108
+ }
109
+
110
+ [data-type='item'][data-item-type='file'] [data-truncate-marker] {
111
+ display: none;
112
+ }
113
+ `;function Oo(e){return e.replaceAll(`/`,`∕`).trim()||`(untitled)`}function ko(e){return e.replace(/\/+$/,``).split(`/`).at(-1)?.trim()||`(unknown)`}function Ao(e){let t=e.project_identity;if(t)return{key:`${t.kind}:${t.key}`,label:t.displayName||ko(e.directory)};let n=ko(e.directory);return{key:n===`(unknown)`?`__unknown__`:`path:${e.directory||n}`,label:n}}function jo(e){return e.time_updated??e.time_created}function Mo(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 No(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}=Ao(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(jo));return Math.max(...t.sessions.map(jo))-n}),d=0,f=new Set;for(let[,e]of u){let l=Oo(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?`${Oo(a.title)} #${a.id.slice(0,8)}`:Oo(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 Po(e,t){if(!At())return t();let n=performance.now(),r=t(),i=performance.now();return G({id:e,source:`custom-timing`,phase:`measure`,actualDuration:Math.round((i-n)*100)/100,baseDuration:0,startTime:n,commitTime:i}),r}var Fo=(0,j.memo)(function({sessions:e,activeSessionId:t,selectedSessionId:n,onSelectSession:r,bookmarkedSessionIds:a,onToggleBookmark:s}){let c=(0,j.useMemo)(()=>Po(`SessionTreeSidebar:buildTreeModel`,()=>No(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)=>Mo(l.current,e,t),density:`compact`,unsafeCSS:Do,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 v(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,P.jsx)(`div`,{className:`session-tree h-[min(560px,calc(100vh-410px))] min-h-56 overflow-hidden`,style:g,onClickCapture:v,children:(0,P.jsx)(i,{model:_,style:{height:`100%`},"aria-label":`Sessions`})})});function Io(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 Da(e)?{mode:`project`,activeAgentKey:null,activeSessionSlug:null,activeProjectKind:e,activeProjectKey:ka(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 Lo({value:e,onChange:t,projectsDisabled:n=!1}){return(0,P.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,P.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,P.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,P.jsx)(`span`,{className:`size-1.5 rounded-full bg-[var(--console-accent)]`}):null}),(0,P.jsx)(`span`,{children:r.label})]},r.value)})})}function Ro(e,t){return(t.time_updated??t.time_created)-(e.time_updated??e.time_created)}function zo(e){return e.slug.split(`/`)[0]?.toLowerCase()||`unknown`}function Bo(e,t){return`${e.toLowerCase()}/${t}`}function Vo(e,t){return`${e}\0${t.toLowerCase()}`}function Ho(e,t,n){let r=e.get(t);if(r){r.push(n);return}e.set(t,[n])}function Uo(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=zo(t),r={...t,agentKey:e,sessionSlug:t.id,fullPath:t.slug};u.push(r);let i=Bo(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;Ho(c,Oa(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(Ro);for(let e of f){let t=zo(e);d.has(t)&&r.get(t).push(e);let n=e.project_identity;if(!n?.key)continue;let s=Oa(n);Ho(i,s,e),Ho(a,Vo(s,t),e),Ho(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 Wo(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 Go(e){let t=new Date(e);return`${t.getFullYear()}-${String(t.getMonth()+1).padStart(2,`0`)}-${String(t.getDate()).padStart(2,`0`)}`}function Ko(e){if(!e)return null;let{from:t,to:n,days:r}=e.window;if(t==null)return`All time`;let i=Go(t),a=Go(n??Date.now());return r?`Last ${r}d · ${i} → ${a}`:`${i} → ${a}`}function qo(e,t,n){return t?e?`Searching for "${e}"`:`Loading recent sessions`:e?`${n} matches for "${e}"`:`${n} recent sessions`}function Jo(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 Yo(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 Xo(e,t,n){let r=e?.agentStatuses[t];return r?.status===`complete`&&r.sessions!=null?r.sessions:n}function Zo(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 Qo({sessions:e,activeSessionId:t,selectedSessionId:n,bookmarkedSessionIds:r,onSelectSession:i,onToggleBookmark:a}){return(0,P.jsx)(`div`,{className:`console-scrollbar h-[min(560px,calc(100vh-410px))] min-h-56 overflow-y-auto`,children:(0,P.jsx)(`ul`,{className:`space-y-1`,children:e.map(e=>{let o=zo(e),s=M.agents[o],c=t===e.id,l=n===e.id;return(0,P.jsx)(`li`,{children:(0,P.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,P.jsxs)(`button`,{type:`button`,onClick:()=>i(e),className:`min-w-0 flex-1 text-left`,children:[(0,P.jsxs)(`span`,{className:`flex min-w-0 items-center gap-1.5`,children:[s?.icon?(0,P.jsx)(`img`,{src:s.icon,alt:s.name,className:`size-3.5 shrink-0 object-contain`}):null,(0,P.jsx)(`span`,{className:`console-mono line-clamp-1 text-xs text-[var(--console-text)]`,children:e.title})]}),(0,P.jsx)(`span`,{className:`console-mono mt-0.5 block truncate text-[10px] text-[var(--console-muted)]`,children:Zo(e.time_updated??e.time_created)})]}),(0,P.jsx)(ia,{active:r.has(e.id),onToggle:()=>a(e)})]})},e.slug)})})})}function $o({active:e,label:t,onClick:n}){return(0,P.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})}var es=[`bugfix`,`refactoring`,`feature-dev`,`testing`,`docs`,`git-ops`,`build-deploy`,`exploration`,`planning`],ts=[`apply_patch`,`bash`,`read`,`edit`,`grep`],ns=[{kind:`read`,label:`Read`},{kind:`edit`,label:`Edit`},{kind:`write`,label:`Write`},{kind:`delete`,label:`Delete`}],rs=[{id:`paid`,label:`Cost > $0`,costMin:1e-6},{id:`one_plus`,label:`Cost >= $1`,costMin:1},{id:`ten_plus`,label:`Cost >= $10`,costMin:10}];function is({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,P.jsxs)(`div`,{className:`rounded-sm border border-[var(--console-border)] bg-white/85 p-3`,children:[(0,P.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,P.jsx)(`span`,{className:`console-mono text-[10px] font-semibold uppercase text-[var(--console-muted)]`,children:`Scope`}),(0,P.jsx)($o,{active:!n.projectKey,label:`All`,onClick:()=>r(e=>({...e,projectKey:void 0}))}),t.map(e=>(0,P.jsx)($o,{active:n.projectKey===e.key,label:e.showCount===!1?e.label:`${e.label} · ${e.count}`,onClick:()=>a(`projectKey`,e.key)},e.key))]}),(0,P.jsxs)(`div`,{className:`mt-3 flex flex-wrap items-center gap-2`,children:[(0,P.jsx)(`span`,{className:`console-mono text-[10px] font-semibold uppercase text-[var(--console-muted)]`,children:`Agent`}),(0,P.jsx)($o,{active:!n.agent,label:`All Agents`,onClick:()=>r(e=>({...e,agent:void 0}))}),e.map(e=>(0,P.jsx)($o,{active:n.agent===e.name,label:e.displayName,onClick:()=>a(`agent`,e.name)},e.name))]}),(0,P.jsxs)(`div`,{className:`mt-3 flex flex-wrap items-center gap-2`,children:[(0,P.jsx)(`span`,{className:`console-mono text-[10px] font-semibold uppercase text-[var(--console-muted)]`,children:`Tag`}),es.map(e=>(0,P.jsx)($o,{active:n.tag===e,label:F[e],onClick:()=>a(`tag`,e)},e))]}),(0,P.jsxs)(`div`,{className:`mt-3 flex flex-wrap items-center gap-2`,children:[(0,P.jsx)(`span`,{className:`console-mono text-[10px] font-semibold uppercase text-[var(--console-muted)]`,children:`Signal`}),ts.map(e=>(0,P.jsx)($o,{active:n.tool===e,label:`tool:${e}`,onClick:()=>a(`tool`,e)},e))]}),(0,P.jsxs)(`div`,{className:`mt-3 flex flex-wrap items-center gap-2`,children:[(0,P.jsx)(`span`,{className:`console-mono text-[10px] font-semibold uppercase text-[var(--console-muted)]`,children:`File Activity`}),ns.map(e=>(0,P.jsx)($o,{active:n.fileKind===e.kind,label:e.label,onClick:()=>a(`fileKind`,e.kind)},e.kind))]}),(0,P.jsxs)(`div`,{className:`mt-3 flex flex-wrap items-center gap-2`,children:[(0,P.jsx)(`span`,{className:`console-mono text-[10px] font-semibold uppercase text-[var(--console-muted)]`,children:`Cost Range`}),(0,P.jsx)($o,{active:!n.costRange,label:`Any Cost`,onClick:()=>r(e=>({...e,costRange:void 0}))}),rs.map(e=>(0,P.jsx)($o,{active:n.costRange===e.id,label:e.label,onClick:()=>a(`costRange`,e.id)},e.id)),i?(0,P.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]})]})}var as={recent:`Recent`,title:`Title`,user_message:`User message`,assistant_reply:`Assistant reply`,tool_output:`Tool output`,file_path:`File path`};function os(e){return e.replaceAll(`&`,`&amp;`).replaceAll(`<`,`&lt;`).replaceAll(`>`,`&gt;`).replaceAll(`"`,`&quot;`).replaceAll(`'`,`&#39;`).replaceAll(`&lt;mark&gt;`,`<mark>`).replaceAll(`&lt;/mark&gt;`,`</mark>`)}function ss({query:e,loading:t,results:n,agentNameMap:r,agents:i,projects:a,filters:o,onChangeFilters:s,onOpenResult:c,selectedIndex:l,registerResultRef:u}){let d=(0,P.jsx)(is,{agents:i,projects:a,filters:o,onChangeFilters:s});return t?(0,P.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[d,(0,P.jsx)(`div`,{className:`grid gap-3`,children:Array.from({length:4}).map((e,t)=>(0,P.jsxs)(`div`,{className:`animate-pulse rounded-sm border border-[var(--console-border)] bg-white/80 p-4`,children:[(0,P.jsx)(`div`,{className:`h-3 w-32 rounded bg-[var(--console-surface-muted)]`}),(0,P.jsx)(`div`,{className:`mt-3 h-4 w-2/3 rounded bg-[var(--console-surface-muted)]`}),(0,P.jsx)(`div`,{className:`mt-2 h-3 w-full rounded bg-[var(--console-surface-muted)]`}),(0,P.jsx)(`div`,{className:`mt-1 h-3 w-5/6 rounded bg-[var(--console-surface-muted)]`})]},t))})]}):n.length===0?(0,P.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[d,(0,P.jsxs)(`div`,{className:`rounded-sm border border-[var(--console-border)] bg-white/80 p-6`,children:[(0,P.jsx)(`h2`,{className:`console-mono text-sm font-semibold text-[var(--console-text)]`,children:e?`No matches`:`No recent sessions`}),e?(0,P.jsxs)(`p`,{className:`console-mono mt-2 text-xs text-[var(--console-muted)]`,children:[`Query: `,e]}):null]})]}):(0,P.jsxs)(`div`,{className:`grid gap-3`,children:[d,(0,P.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,P.jsxs)(y,{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,P.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,P.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,P.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:as[t.matchType]}),(0,P.jsx)(`span`,{className:`console-mono text-[11px] text-[var(--console-muted)]`,children:t.session.directory})]}),(0,P.jsx)(`h2`,{className:`console-mono mt-3 text-sm font-semibold text-[var(--console-text)]`,children:t.session.title}),(0,P.jsx)(et,{tags:t.session.smart_tags,className:`mt-2`}),(0,P.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:os(t.snippet||t.session.title)}})]},o)})]})}function cs(e,t){return(t.time_updated??t.time_created)-(e.time_updated??e.time_created)}function ls(e,t){if(!t.changedSessionHeads||!t.removedSessionRefs)return null;let n=new Map(e.map(e=>[Bo(zo(e),e.id),e]));for(let{agentName:e,sessionId:r}of t.removedSessionRefs)n.delete(Bo(e,r));for(let{agentName:e,session:r}of t.changedSessionHeads)n.set(Bo(e,r.id),r);return[...n.values()].sort(cs)}function us(e){return{kind:e.identityKind,key:e.identityKey}}var ds=`codesesh.shortcuts-hint-dismissed`,fs=[{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 ps(e){if(!(e instanceof HTMLElement))return!1;let t=e.tagName.toLowerCase();return t===`input`||t===`textarea`||t===`select`||e.isContentEditable}function ms(){let e=c(),[t,n]=(0,j.useState)([]),[r,i]=(0,j.useState)([]),[a,o]=(0,j.useState)([]),[s,l]=(0,j.useState)(!0),[u,d]=(0,j.useState)(null),[f,p]=(0,j.useState)(null),[m,h]=(0,j.useState)(!1),[g,_]=(0,j.useState)(null),[v,ee]=(0,j.useState)(null),[b,te]=(0,j.useState)(null),[x,ne]=(0,j.useState)([]),[S,re]=(0,j.useState)(`agents`),[C,ie]=(0,j.useState)(null),[ae,w]=(0,j.useState)(null),[oe,se]=(0,j.useState)(!1),[ce,ue]=(0,j.useState)(null),[de,pe]=(0,j.useState)(void 0),[T,me]=(0,j.useState)(null),[he,ge]=(0,j.useState)(``),[E,_e]=(0,j.useState)(``),[ve,D]=(0,j.useState)(!1),[O,be]=(0,j.useState)({}),[k,xe]=(0,j.useState)([]),[Se,Ce]=(0,j.useState)(!1),[A,we]=(0,j.useState)(null),[Te,Ee]=(0,j.useState)(null),[De,Oe]=(0,j.useState)(0),[ke,Ae]=(0,j.useState)(!1),[je,Me]=(0,j.useState)(!0),[Ne,Pe]=(0,j.useState)(!1),Fe=(0,j.useRef)(null),Ie=(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 Be();me(e);let[r,a,s,c,l,u]=await Promise.all([He(),We({from:e.window.from,to:e.window.to}),Ke(e.window).catch(e=>(console.error(`Failed to load dashboard:`,e),null)),Ue().catch(e=>(console.error(`Failed to load projects:`,e),{projects:[]})),Je(),Ve().catch(e=>(console.error(`Failed to load scan status:`,e),null))]);n(r),i(a.sessions),ne(c.projects),o(l.bookmarks),u&&we(u),s&&te(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)}),d(`Failed to load data. Is the CLI server running?`)}finally{l(!1)}})(),()=>e.abort()},[]);let Le=ye(),Re=(0,j.useMemo)(()=>new Set(t.map(e=>e.name.toLowerCase())),[t]),ze=(0,j.useMemo)(()=>new Map(t.map(e=>[e.name.toLowerCase(),e.displayName])),[t]),F=ve,I=(0,j.useMemo)(()=>Io(Le.pathname,Re),[Le.pathname,Re]);(0,j.useEffect)(()=>{N(`route.change`,{path:Le.pathname,mode:I.mode,agent:I.activeAgentKey,session:I.activeSessionSlug})},[Le.pathname,I.mode,I.activeAgentKey,I.activeSessionSlug]),(0,j.useEffect)(()=>{if(I.mode===`projects`||I.mode===`project`){re(`projects`),I.mode===`project`&&ie({kind:I.activeProjectKind,key:I.activeProjectKey});return}(I.mode===`agent`||I.mode===`missingAgent`)&&re(`agents`)},[I]);let $e=F?E:typeof Le.state==`object`&&Le.state!==null&&`searchQuery`in Le.state&&typeof Le.state.searchQuery==`string`?Le.state.searchQuery:``,L=(0,j.useMemo)(()=>Uo(r,t),[r,t]);(0,j.useEffect)(()=>{let e=!1;return o(t=>{let n=Ta(t,r);return n===t?t:(Xe(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=Sa();if(t.length!==0)try{let n=await Xe(t.map(({bookmarked_at:e,...t})=>t));if(e)return;o(n.bookmarks),Ca()}catch(t){e||console.error(`Failed to migrate legacy bookmarks:`,t)}})(),()=>{e=!0}},[]);let tt=(0,j.useMemo)(()=>new Set(a.map(e=>ba(e.agentKey,e.sessionId))),[a]),R=(0,j.useCallback)((e,t)=>tt.has(ba(e,t)),[tt]),z=(0,j.useCallback)(e=>{let t=ba(e.agentKey,e.sessionId),n=tt.has(t),r=a;o(n?r.filter(e=>ba(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?Ze(e.agentKey,e.sessionId):Ye({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)})},[tt,a]),nt=(0,j.useCallback)((e,t)=>{z(xa(e,t))},[z]),B=I.activeAgentKey,V=I.mode===`project`?I.activeProjectKind:null,rt=I.mode===`project`?I.activeProjectKey:null,it=(0,j.useMemo)(()=>V&&rt?{kind:V,key:rt}:null,[V,rt]),at=it?Oa(it):null,ot=(0,j.useMemo)(()=>I.mode===`session`?L.byRouteKey.get(Bo(I.activeAgentKey,I.activeSessionSlug))??null:null,[L,I]),st=(I.mode===`session`&&f?.id===I.activeSessionSlug?f:null)?.project_identity??ot?.project_identity??null,ct=S===`projects`?it??(I.mode===`session`?st:C):null,lt=ct?Oa(ct):null,ut=(0,j.useMemo)(()=>B?L.byAgent.get(B)??[]:[],[B,L]),dt=(0,j.useMemo)(()=>lt?de?L.byProjectAgentKey.get(Vo(lt,de))??[]:L.byProjectIdentityKey.get(lt)??[]:[],[de,lt,L]),H=S===`projects`?dt:ut,ft=(0,j.useMemo)(()=>Wo(H),[H]),pt=(0,j.useMemo)(()=>H.length===0?new Set:new Set(H.filter(e=>tt.has(ba(zo(e),e.id))).map(e=>e.id)),[tt,H]),mt=(0,j.useMemo)(()=>a.toSorted((e,t)=>(t.time_updated??t.time_created)-(e.time_updated??e.time_created)),[a]),U=(0,j.useCallback)(t=>{Ee(t.id),e(`/${t.slug}`)},[e]),ht=(0,j.useCallback)(e=>{nt(e,zo(e))},[nt]),gt=(0,j.useCallback)(t=>{Ee(t);let n=ft.byId.get(t);n&&e(`/${n.slug}`)},[e,ft]),_t=(0,j.useMemo)(()=>{let e=rs.find(e=>e.id===O.costRange);return{agent:O.agent,projectKey:O.projectKey,tag:O.tag,tool:O.tool,fileKind:O.fileKind,costMin:e?.costMin}},[O]),vt=E.trim().length>0||!!(O.tool||O.fileKind),yt=Jo(A),bt=A?.active===!0,xt=(0,j.useMemo)(()=>{let e=rs.find(e=>e.id===O.costRange),t=O.agent?L.byAgent.get(O.agent)??[]:null,n=O.projectKey?L.byProjectKey.get(O.projectKey)??[]:null,r=t&&n?t.length<=n.length?t:n:t??n??L.sessionsByActivity,i=[];for(let t of r)if(!(O.agent&&zo(t)!==O.agent)&&!(O.projectKey&&t.project_identity?.key!==O.projectKey)&&!(O.tag&&!t.smart_tags?.includes(O.tag))&&!(e&&t.stats.total_cost<e.costMin)&&(i.push({agentName:zo(t),session:t,snippet:`Recent session · ${t.directory}`,matchType:`recent`}),i.length>=50))break;return i},[O,L]),St=I.mode===`session`?`${I.activeAgentKey}/${I.activeSessionSlug}`:``,Ct=(0,j.useEffectEvent)(async e=>{try{let t=!!(e.changedSessionHeads&&e.removedSessionRefs);t&&i(t=>ls(t,e)??t);let[r,a,o,s,c,l]=await Promise.all([He(),t?Promise.resolve(null):We({from:T?.window.from,to:T?.window.to}),Ke(T?.window).catch(e=>(console.error(`Failed to refresh dashboard:`,e),null)),Ue().catch(e=>(console.error(`Failed to refresh projects:`,e),{projects:[]})),I.mode===`project`?Ke(T?.window,{projectKind:I.activeProjectKind,projectKey:I.activeProjectKey,agent:de}).catch(e=>(console.error(`Failed to refresh project dashboard:`,e),null)):Promise.resolve(null),F&&vt?qe(E,_t).catch(e=>(console.error(`Failed to refresh search results:`,e),{results:[]})):Promise.resolve(null)]);if(n(r),a&&i(a.sessions),ne(s.projects),o&&te(o),c&&w(c),l&&xe(l.results),I.mode===`session`)try{p(await Ge(I.activeAgentKey,I.activeSessionSlug)),_(null)}catch{p(null),_(`Session not found`)}e.newSessions>0&&ee(`发现 ${e.newSessions} 个新会话,列表已自动刷新`)}catch(e){console.error(`Failed to sync live session update:`,e)}});(0,j.useEffect)(()=>{if(!F){xe([]),Ce(!1);return}if(!vt){xe(xt),Ce(!1);return}let e=!1;Ce(!0);let t=performance.now();return N(`search.start`,{query_length:E.length}),qe(E,_t).then(n=>{e||(xe(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)}),xe([]))}).finally(()=>{e||Ce(!1)}),()=>{e=!0}},[E,F,xt,_t,vt]),(0,j.useEffect)(()=>{if(I.mode!==`session`){p(null),_(null);return}let e=new AbortController;h(!0),_(null);let t=performance.now();return N(`session.open.start`,{agent:I.activeAgentKey,session:I.activeSessionSlug}),(async()=>{try{let e=await Ge(I.activeAgentKey,I.activeSessionSlug);p(e),N(`session.open.done`,{agent:I.activeAgentKey,session:I.activeSessionSlug,duration_ms:Math.round(performance.now()-t),messages:e.messages.length})}catch(e){N(`session.open.error`,{agent:I.activeAgentKey,session:I.activeSessionSlug,duration_ms:Math.round(performance.now()-t),error:e instanceof Error?e.message:String(e)}),_(`Session not found`),p(null)}finally{h(!1)}})(),()=>e.abort()},[St,I.activeAgentKey,I.activeSessionSlug,I.mode]),(0,j.useEffect)(()=>{at&&pe(void 0)},[at]),(0,j.useEffect)(()=>{if(!rt||!T){w(null),ue(null),se(!1);return}let e=!1;return se(!0),ue(null),Ke(T.window,{projectKind:V??void 0,projectKey:rt,agent:de}).then(t=>{e||w(t)}).catch(t=>{e||(console.error(`Failed to load project dashboard:`,t),w(null),ue(`Failed to load project dashboard`))}).finally(()=>{e||se(!1)}),()=>{e=!0}},[V,rt,T,de]),(0,j.useEffect)(()=>Qe(e=>{Ct(e)},e=>{we(e)}),[]),(0,j.useEffect)(()=>{if(!v)return;let e=window.setTimeout(()=>{ee(null)},3500);return()=>{window.clearTimeout(e)}},[v]),(0,j.useEffect)(()=>{try{Me(window.localStorage.getItem(ds)===`1`)}catch{Me(!0)}},[]),(0,j.useEffect)(()=>{if(F){Oe(e=>k.length===0?0:Math.min(e,k.length-1));return}if(I.mode===`session`){Ee(I.activeSessionSlug);return}if(I.mode===`agent`){Ee(null);return}Ee(null)},[F,k.length,I.mode,I.activeSessionSlug,H]),(0,j.useEffect)(()=>{if(!F)return;let e=k[De];if(!e)return;let t=`${e.agentName}/${e.session.id}`;Ie.current.get(t)?.scrollIntoView({block:`nearest`})},[F,k,De]);let wt=L.landingSessions,Tt=(0,j.useMemo)(()=>at?L.byLandingProjectIdentityKey.get(at)??[]:[],[at,L]),Et=(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]),Dt=(0,j.useMemo)(()=>t.find(e=>e.name.toLowerCase()===B)??null,[B,t]),Ot=(0,j.useMemo)(()=>x.find(e=>at===Oa(us(e)))??null,[at,x]),kt=(0,j.useMemo)(()=>x.find(e=>lt===Oa(us(e)))??null,[x,lt]),At=L.projectOptions,jt=(0,j.useMemo)(()=>{if(!vt)return At;let e=new Map,t=Se?[]:k;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(O.projectKey&&!e.has(O.projectKey)){let t=At.find(e=>e.key===O.projectKey);t&&e.set(t.key,{...t,count:0,showCount:!1})}return[...e.values()].toSorted((e,t)=>t.count-e.count).slice(0,8)},[At,O.projectKey,Se,k,vt]),W=`CodeSesh`,G=`Select an agent to browse sessions`;if(I.mode===`root`&&(W=F?`Search`:`Dashboard`,G=F?qo(E,Se,k.length):b?`${b.totals.sessions.toLocaleString(`en-US`)} total sessions across ${b.perAgent.length} agents`:`Aggregated view across all agents`),I.mode===`projects`&&(W=`Projects`,G=`${x.length.toLocaleString(`en-US`)} projects across ${r.length.toLocaleString(`en-US`)} sessions`),I.mode===`project`&&(W=Ot?.displayName??`Project`,G=Ot?`${Ot.sessionCount.toLocaleString(`en-US`)} sessions · ${Ot.agentStats.length} agents`:I.activeProjectKey),I.mode===`agent`&&B&&(W=Dt?.displayName??B,G=`${H.length} sessions`),I.mode===`session`){if(g)W=`Session Not Found`,G=`Requested /${B}/${I.activeSessionSlug}`;else if(f){W=f.title||`Conversation`;let e=f.time_updated??f.time_created;G=(0,P.jsxs)(P.Fragment,{children:[(0,P.jsxs)(`span`,{children:[`ID: #`,f.id.slice(0,8)]}),(0,P.jsx)(`span`,{children:`·`}),(0,P.jsxs)(`span`,{children:[`Updated `,Zo(e)]}),(0,P.jsx)(et,{tags:f.smart_tags,limit:9,className:`inline-flex`})]})}}I.mode===`missingAgent`&&(W=`Agent Not Found`,G=`Requested /${I.attemptedKey}`),I.mode===`missingSession`&&(W=`Session Not Found`,G=`Session not found in /${B}`),F&&(W=`Search`,G=qo(E,Se,k.length));let Mt=(0,j.useMemo)(()=>{if(F)return[{label:`Search`}];let e={label:`Dashboard`,to:S===`agents`&&I.mode===`root`||S===`projects`&&I.mode===`projects`?void 0:S===`projects`?`/projects`:`/`};if(I.mode===`root`)return[{label:`Dashboard`}];let t={label:`Projects`,to:I.mode===`project`?`/projects`:void 0};if(I.mode===`projects`)return[e,{label:`Projects`}];if(I.mode===`project`)return[e,t,{label:Ot?.displayName??I.activeProjectKey}];if(I.mode===`session`&&S===`projects`&&ct)return[e,{label:`Projects`,to:`/projects`},{label:kt?.displayName??ct.key,to:Aa(ct)},{label:f?.title||I.activeSessionSlug||`Conversation`}];if(I.mode===`missingAgent`)return[e,{label:I.attemptedKey}];let n=Dt?.displayName??B??`Unknown Agent`,r={label:n,to:I.mode===`session`?`/${B}`:void 0};return I.mode===`agent`?[e,{label:n}]:I.mode===`missingSession`?[e,r,{label:I.attemptedSessionSlug}]:I.mode===`session`?[e,r,{label:f?.title||I.activeSessionSlug||`Conversation`}]:[e,{label:`Invalid Route`}]},[Dt,B,Ot,S,F,kt,ct,f?.title,I]),Pt;Pt=s?(0,P.jsx)(ra,{}):F?(0,P.jsx)(Nt,{id:`SearchResultsPanel`,detail:{results:k.length,loading:Se},children:(0,P.jsx)(ss,{query:E,loading:Se,results:k,agentNameMap:ze,agents:t,projects:jt,filters:O,onChangeFilters:be,onOpenResult:()=>{D(!1),_e(``)},selectedIndex:De,registerResultRef:(e,t)=>{t?Ie.current.set(e,t):Ie.current.delete(e)}})}):u?(0,P.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:u}):I.mode===`root`?b?(0,P.jsx)(Nt,{id:`Dashboard`,detail:{sessions:b.totals.sessions,projects:x.length},children:(0,P.jsx)(ao,{data:b,projects:x,bookmarkedSessions:mt,isBookmarked:R,onToggleBookmark:(e,t)=>{if(`agentName`in e){nt(e,t??e.agentName.toLowerCase());return}z(e)}})}):(0,P.jsx)(ha,{type:`global`,sessions:wt,agentItems:Et,isBookmarked:R,onToggleBookmark:e=>nt(e,e.agentKey)}):I.mode===`projects`?(0,P.jsx)(ho,{projects:x}):I.mode===`project`?(0,P.jsx)(yo,{project:Ot,projectKey:I.activeProjectKey,dashboard:ae,loading:oe,error:ce,sessions:Tt,activeAgent:de,onChangeAgent:pe,isBookmarked:R,onToggleSessionBookmark:nt}):I.mode===`agent`&&B?(0,P.jsx)(ha,{type:`agent`,sessions:L.byLandingAgent.get(B)??[],agentItems:Et,activeAgentKey:B,isBookmarked:R,onToggleBookmark:e=>nt(e,e.agentKey)}):I.mode===`session`?m?(0,P.jsx)(ra,{}):g||!f?(0,P.jsx)(ha,{type:`missing-session`,sessions:L.byLandingAgent.get(I.activeAgentKey)??[],agentItems:Et,activeAgentKey:I.activeAgentKey,attemptedSessionSlug:I.activeSessionSlug,isBookmarked:R,onToggleBookmark:e=>nt(e,e.agentKey)}):(0,P.jsx)(Nt,{id:`SessionDetail`,detail:{messages:f.messages.length,session:f.id},children:(0,P.jsx)(Pi,{session:f,highlightQuery:$e})}):I.mode===`missingAgent`?(0,P.jsx)(ha,{type:`missing-agent`,sessions:wt,agentItems:Et,attemptedAgentKey:I.attemptedKey,isBookmarked:R,onToggleBookmark:e=>nt(e,e.agentKey)}):(0,P.jsx)(`div`,{className:`text-sm text-[var(--console-muted)]`,children:`Invalid route.`});function Ft(){_e(he.trim()),D(!0),Oe(0)}function K(){Me(!0);try{window.localStorage.setItem(ds,`1`)}catch{}}function It(t){if(!(t===`projects`&&bt)){if(re(t),Ee(null),t===`projects`){let t=st??(I.mode===`session`?null:C);e(t?Aa(t):`/projects`);return}e(`/`)}}let Lt=(0,j.useEffectEvent)(t=>{let n=t.key;if((t.metaKey||t.ctrlKey)&&n.toLowerCase()===`k`){t.preventDefault(),D(!0),Oe(0),window.setTimeout(()=>{Fe.current?.focus(),Fe.current?.select()},0);return}if(t.defaultPrevented||t.metaKey||t.ctrlKey||t.altKey||t.isComposing)return;let r=t.target,i=ps(r);if(ke){n===`Escape`&&(t.preventDefault(),Ae(!1));return}if(i){n===`Escape`&&(t.preventDefault(),r instanceof HTMLElement&&r.blur());return}if(n===`?`){t.preventDefault(),Ae(!0),K();return}if(n===`/`){t.preventDefault(),K(),D(!0),Fe.current?.focus(),Fe.current?.select();return}if(n===`Escape`){if(t.preventDefault(),F){D(!1),_e(``),ge(``);return}if(I.mode===`session`&&I.activeAgentKey){if(S===`projects`&&ct){e(Aa(ct));return}e(`/${I.activeAgentKey}`)}return}if(F){if(k.length===0)return;if(n===`j`){t.preventDefault(),K(),Oe(e=>Math.min(e+1,k.length-1));return}if(n===`k`){t.preventDefault(),K(),Oe(e=>Math.max(e-1,0));return}if(n===`g`){t.preventDefault(),K(),Oe(0);return}if(n===`G`){t.preventDefault(),K(),Oe(k.length-1);return}if(n===`Enter`){let n=k[De];if(!n)return;t.preventDefault(),K(),D(!1),_e(``),e(`/${n.agentName.toLowerCase()}/${n.session.id}`,{state:{searchQuery:E}})}return}if(S===`agents`&&!B||H.length===0)return;let a=e=>{K();let t=Te==null?-1:ft.indexById.get(Te)??-1,n=t>=0?t:e>=0?-1:H.length;Ee(H[Math.max(0,Math.min(n+e,H.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(),K(),Ee(H[0]?.id??null);return}if(n===`G`){t.preventDefault(),K(),Ee(H.at(-1)?.id??null);return}if(n===`Enter`){let n=Te==null?null:ft.byId.get(Te);if(!n)return;t.preventDefault(),K(),e(S===`projects`?`/${n.slug}`:`/${B}/${n.id}`)}});return(0,j.useEffect)(()=>(window.addEventListener(`keydown`,Lt),()=>window.removeEventListener(`keydown`,Lt)),[]),(0,P.jsxs)(`div`,{className:`console-ui flex h-screen flex-col overflow-hidden bg-[var(--console-bg)] text-[var(--console-text)]`,children:[(0,P.jsx)(`header`,{className:`shrink-0 border-b border-[var(--console-border)] bg-white/85 backdrop-blur-sm`,children:(0,P.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,P.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,P.jsx)(`button`,{type:`button`,"aria-expanded":!Ne,"aria-label":Ne?`Expand sidebar`:`Collapse sidebar`,title:Ne?`Expand sidebar`:`Collapse sidebar`,onClick:()=>Pe(e=>!e),className:`hidden rounded-sm border border-[var(--console-border)] bg-white p-1.5 text-[var(--console-muted)] transition-colors hover:bg-[var(--console-surface-muted)] hover:text-[var(--console-text)] lg:inline-flex`,children:Ne?(0,P.jsx)(fe,{className:`size-4`}):(0,P.jsx)(le,{className:`size-4`})}),(0,P.jsxs)(y,{to:`/`,className:`flex items-center gap-2 text-[var(--console-text)]`,children:[(0,P.jsx)(`img`,{src:`/logo.svg?v=3`,alt:`CodeSesh`,className:`h-6 w-6 rounded-sm`}),(0,P.jsx)(`span`,{className:`console-mono text-sm font-semibold uppercase tracking-[0.05em]`,children:`CodeSesh`})]})]}),(0,P.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(),Ft()},children:[(0,P.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,P.jsx)(`input`,{ref:Fe,value:he,onChange:e=>ge(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,P.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,P.jsxs)(`div`,{className:`flex items-center justify-end gap-2`,children:[(0,P.jsxs)(`button`,{type:`button`,onClick:()=>{Ae(!0),K()},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,P.jsx)(`span`,{className:`hidden sm:inline`,children:` Shortcuts`})]}),Ko(T)?(0,P.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:Ko(T)}):null,(0,P.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.11.0`]})]})]})}),(0,P.jsxs)(`div`,{className:`flex min-h-0 flex-1`,children:[(0,P.jsx)(`aside`,{className:`w-64 shrink-0 flex-col border-r border-[var(--console-border)] bg-[var(--console-sidebar-bg)] ${Ne?`hidden`:`hidden lg:flex`}`,children:(0,P.jsxs)(`div`,{className:`console-scrollbar flex-1 space-y-8 overflow-y-auto px-4 py-6`,children:[(0,P.jsxs)(`section`,{children:[(0,P.jsx)(`h3`,{className:`console-mono mb-3 text-xs font-bold uppercase text-[var(--console-text)]`,children:`BROWSE BY`}),(0,P.jsx)(Lo,{value:S,onChange:It,projectsDisabled:bt})]}),(0,P.jsxs)(`section`,{children:[(0,P.jsx)(`h3`,{className:`console-mono mb-3 text-xs font-bold uppercase text-[var(--console-text)]`,children:`NAVIGATION`}),(0,P.jsxs)(`ul`,{className:`space-y-1 ${S===`projects`?`console-scrollbar max-h-[min(280px,calc(100vh-440px))] overflow-y-auto pr-1`:``}`,children:[(0,P.jsx)(`li`,{children:(0,P.jsxs)(y,{to:S===`projects`?`/projects`:`/`,className:`flex items-center gap-2 rounded-sm border px-3 py-1.5 text-left transition-colors ${S===`agents`&&I.mode===`root`||S===`projects`&&I.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,P.jsx)(`img`,{src:`/logo.svg?v=3`,alt:`Dashboard`,className:`size-3.5 rounded-[2px]`}),(0,P.jsx)(`span`,{className:`console-mono line-clamp-1 flex-1 text-xs`,children:`Dashboard`})]})}),S===`agents`?t.map(e=>{let t=e.name.toLowerCase(),n=t===B,r=M.agents[t],i=Yo(A,e.name),a=bt&&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,P.jsxs)(P.Fragment,{children:[r?.icon&&(0,P.jsx)(`img`,{src:r.icon,alt:e.displayName,className:`size-3.5 object-contain`}),(0,P.jsx)(`span`,{className:`console-mono line-clamp-1 flex-1 text-xs`,children:e.displayName}),(0,P.jsx)(`span`,{className:`console-mono text-[11px] text-[var(--console-muted)]`,children:i??Xo(A,e.name,e.count)})]});return(0,P.jsxs)(`li`,{children:[a?(0,P.jsx)(`span`,{className:o,title:`Available after this agent scan completes`,children:s}):(0,P.jsx)(y,{to:`/${t}`,className:o,children:s}),i?(0,P.jsx)(`span`,{className:`ml-4 mt-1 block h-1 overflow-hidden rounded-sm bg-[var(--console-surface-muted)]`,children:(0,P.jsx)(`span`,{className:`block h-full bg-[var(--console-accent)]`,style:{width:`${A?.agentStatuses[e.name]?.total?Math.round((A.agentStatuses[e.name]?.processed??0)/A.agentStatuses[e.name].total*100):8}%`}})}):null]},e.name)}):x.map(e=>{let t=us(e),n=lt===Oa(t);return(0,P.jsx)(`li`,{children:(0,P.jsxs)(y,{to:Aa(t),onClick:()=>ie(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,P.jsx)(`span`,{className:`console-mono min-w-0 flex-1 truncate text-xs`,children:e.displayName}),(0,P.jsx)(`span`,{className:`console-mono shrink-0 text-[11px] text-[var(--console-muted)]`,children:e.sessionCount})]})},`${e.identityKind}:${e.identityKey}`)}),S===`agents`&&t.length===0&&!s?(0,P.jsx)(`li`,{children:(0,P.jsx)(`span`,{className:`console-mono block rounded-sm px-3 py-1.5 text-xs text-[var(--console-muted)]`,children:A?.active?`Scanning agents...`:`No agents found`})}):null,S===`projects`&&x.length===0&&!s?(0,P.jsx)(`li`,{children:(0,P.jsx)(`span`,{className:`console-mono block rounded-sm px-3 py-1.5 text-xs text-[var(--console-muted)]`,children:A?.active?`Scanning projects...`:`No projects found`})}):null]})]}),(0,P.jsxs)(`section`,{children:[(0,P.jsx)(`h3`,{className:`console-mono mb-3 text-xs font-bold uppercase text-[var(--console-text)]`,children:`BOOKMARKS`}),mt.length===0?(0,P.jsx)(`span`,{className:`console-mono block rounded-sm px-3 py-1.5 text-xs text-[var(--console-muted)]`,children:`No bookmarks yet`}):(0,P.jsx)(`ul`,{className:`space-y-1`,children:mt.map(e=>{let t=I.mode===`session`&&I.activeAgentKey===e.agentKey&&I.activeSessionSlug===e.sessionId,n=M.agents[e.agentKey];return(0,P.jsx)(`li`,{children:(0,P.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,P.jsxs)(y,{to:`/${e.fullPath}`,className:`flex min-w-0 flex-1 items-start gap-2`,children:[n?.icon?(0,P.jsx)(`img`,{src:n.icon,alt:n.name,className:`mt-0.5 size-3.5 shrink-0 object-contain`}):null,(0,P.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,P.jsx)(`span`,{className:`console-mono line-clamp-1 block text-xs`,children:e.title}),(0,P.jsx)(`span`,{className:`console-mono mt-0.5 line-clamp-1 block text-[10px] text-[var(--console-muted)]`,children:n?.name??e.agentKey})]})]}),(0,P.jsx)(ia,{active:!0,onToggle:()=>z(e)})]})},ba(e.agentKey,e.sessionId))})})]}),(0,P.jsxs)(`section`,{children:[(0,P.jsxs)(`h3`,{className:`console-mono mb-3 text-xs font-bold uppercase text-[var(--console-text)]`,children:[`SESSIONS`,H.length>0?(0,P.jsx)(`span`,{className:`ml-2 text-[10px] font-normal text-[var(--console-muted)]`,children:`Navigate j k · Open Enter`}):null]}),S===`agents`&&!B?(0,P.jsx)(`span`,{className:`console-mono block rounded-sm px-3 py-1.5 text-xs text-[var(--console-muted)]`,children:`Select an agent`}):S===`projects`&&!lt?(0,P.jsx)(`span`,{className:`console-mono block rounded-sm px-3 py-1.5 text-xs text-[var(--console-muted)]`,children:`Select a project`}):H.length===0?(0,P.jsx)(`span`,{className:`console-mono block rounded-sm px-3 py-1.5 text-xs text-[var(--console-muted)]`,children:A?.active?`Scanning sessions...`:`No sessions yet`}):S===`projects`?(0,P.jsx)(Qo,{sessions:H,activeSessionId:I.mode===`session`?I.activeSessionSlug:null,selectedSessionId:Te,bookmarkedSessionIds:pt,onSelectSession:U,onToggleBookmark:ht}):(0,P.jsx)(Nt,{id:`SessionTreeSidebar`,detail:{sessions:H.length},children:(0,P.jsx)(Fo,{sessions:H,activeSessionId:I.mode===`session`?I.activeSessionSlug:null,selectedSessionId:Te,onSelectSession:gt,bookmarkedSessionIds:pt,onToggleBookmark:ht})})]})]})}),(0,P.jsxs)(`main`,{className:`flex min-w-0 flex-1 flex-col`,children:[(0,P.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,P.jsxs)(`div`,{children:[(0,P.jsx)(`nav`,{"aria-label":`Breadcrumb`,className:`console-mono mb-2 flex flex-wrap items-center gap-1 text-[11px] text-[var(--console-muted)]`,children:Mt.map((e,t)=>(0,P.jsxs)(`span`,{className:`flex items-center gap-1`,children:[e.to?(0,P.jsx)(y,{to:e.to,className:`transition-colors hover:text-[var(--console-text)]`,children:e.label}):(0,P.jsx)(`span`,{className:`text-[var(--console-text)]`,children:e.label}),t<Mt.length-1?(0,P.jsx)(`span`,{children:`/`}):null]},`${e.label}-${t}`))}),(0,P.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,P.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:I.mode===`session`?`Session`:I.mode===`root`?`Dashboard`:I.mode===`projects`?`Projects`:I.mode===`project`?`Project`:`Landing`}),(0,P.jsx)(`h1`,{className:`console-mono text-xl font-semibold tracking-tight text-[var(--console-text)]`,children:W})]}),(0,P.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:G}),(0,P.jsxs)(`div`,{className:`mt-2 flex flex-wrap items-center gap-2`,children:[je?null:(0,P.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,P.jsx)(`span`,{children:`Keyboard navigation available`}),(0,P.jsx)(`span`,{className:`rounded-sm border border-[var(--console-border)] bg-white px-1`,children:`?`}),(0,P.jsx)(`button`,{type:`button`,onClick:K,className:`text-[var(--console-muted)] transition-colors hover:text-[var(--console-text)]`,"aria-label":`Dismiss keyboard shortcuts hint`,children:`×`})]}),!F&&I.mode===`session`?(0,P.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,!F&&I.mode===`session`&&f?(0,P.jsx)(Eo,{agentName:I.activeAgentKey,sessionId:f.id,directory:f.directory}):null]}),v?(0,P.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:v}):null,yt&&I.mode===`root`?(0,P.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:yt}):null]})}),(0,P.jsx)(`section`,{className:`console-scrollbar bg-grid min-h-0 flex-1 overflow-y-auto px-4 py-6 md:px-8`,children:(0,P.jsx)(bo,{children:(0,P.jsx)(Nt,{id:`MainContent`,detail:{mode:I.mode,search:F,sessions:r.length},children:Pt})})})]})]}),ke?(0,P.jsx)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/35 px-4`,onClick:()=>Ae(!1),children:(0,P.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,P.jsxs)(`div`,{className:`flex items-start justify-between gap-4`,children:[(0,P.jsxs)(`div`,{children:[(0,P.jsx)(`p`,{className:`console-mono text-[11px] uppercase tracking-[0.16em] text-[var(--console-muted)]`,children:`Keyboard Shortcuts`}),(0,P.jsx)(`h2`,{className:`console-mono mt-2 text-xl font-semibold text-[var(--console-text)]`,children:`Navigate without leaving the keyboard`})]}),(0,P.jsx)(`button`,{type:`button`,onClick:()=>Ae(!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,P.jsx)(`div`,{className:`mt-5 grid gap-4 md:grid-cols-3`,children:fs.map(e=>(0,P.jsxs)(`div`,{className:`rounded-sm border border-[var(--console-border)] bg-[var(--console-surface-muted)] p-4`,children:[(0,P.jsx)(`h3`,{className:`console-mono text-xs font-bold uppercase text-[var(--console-text)]`,children:e.title}),(0,P.jsx)(`div`,{className:`mt-3 space-y-3`,children:e.items.map(e=>(0,P.jsxs)(`div`,{children:[(0,P.jsx)(`p`,{className:`console-mono text-xs text-[var(--console-text)]`,children:e.keys}),(0,P.jsx)(`p`,{className:`mt-1 text-sm leading-6 text-[var(--console-muted)]`,children:e.description})]},e.keys))})]},e.title))})]})}):null]})}ze.createRoot(document.getElementById(`root`)).render((0,P.jsx)(j.StrictMode,{children:(0,P.jsx)(m,{children:(0,P.jsx)(Nt,{id:`App`,children:(0,P.jsx)(ms,{})})})}));