@wrongstack/webui 0.260.0 β†’ 0.265.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,165 +0,0 @@
1
- import{r as e}from"./rolldown-runtime-QTnfLwEv.js";import{$ as t,$n as n,$t as r,A as i,An as a,At as o,B as s,Bn as c,Bt as l,C as u,Cn as d,Ct as f,D as p,Dn as m,Dt as h,E as g,En as _,Et as v,F as y,Fn as b,Ft as x,G as S,Gn as C,Gt as w,H as T,Hn as E,Ht as D,I as O,In as k,It as A,J as j,Jn as M,Jt as ee,K as te,Kn as N,Kt as ne,L as re,Ln as ie,Lt as ae,M as oe,Mn as se,Mt as ce,N as le,Nn as P,Nt as ue,O as de,On as fe,Ot as pe,P as me,Pn as he,Pt as ge,Q as F,Qn as _e,Qt as ve,R as ye,Rn as be,Rt as xe,S as Se,Sn as Ce,St as we,T as Te,Tn as Ee,Tt as De,U as Oe,Un as ke,Ut as Ae,V as je,Vn as Me,Vt as Ne,W as Pe,Wn as Fe,Wt as Ie,X as Le,Xn as Re,Xt as ze,Y as Be,Yn as Ve,Yt as He,Z as Ue,Zn as We,Zt as Ge,_ as Ke,_n as qe,_r as Je,_t as Ye,a as Xe,an as Ze,ar as Qe,at as $e,b as et,bn as tt,bt as nt,c as rt,cn as it,cr as at,ct as ot,d as st,dn as ct,dr as lt,dt as ut,en as dt,er as ft,et as pt,f as mt,fn as ht,fr as gt,ft as _t,g as vt,gn as yt,gr as bt,gt as xt,h as St,hn as Ct,hr as wt,ht as Tt,i as Et,in as Dt,ir as Ot,it as kt,j as At,jn as jt,jt as Mt,k as Nt,kn as Pt,kt as Ft,l as It,ln as Lt,lr as Rt,lt as zt,m as Bt,mn as Vt,mr as Ht,mt as Ut,n as Wt,nn as I,nr as Gt,nt as Kt,o as qt,on as Jt,or as Yt,ot as Xt,p as Zt,pn as Qt,pr as $t,pt as en,q as tn,qn as nn,qt as rn,r as an,rn as on,rr as sn,rt as cn,s as ln,sn as un,sr as L,st as dn,t as fn,tn as pn,tr as mn,tt as hn,u as gn,un as _n,ur as vn,ut as yn,v as bn,vn as xn,vr as Sn,vt as Cn,w as wn,wn as Tn,wt as En,x as Dn,xn as On,xt as kn,y as An,yn as jn,yt as Mn,z as Nn,zn as Pn,zt as Fn}from"./vendor-BRkhRU94.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)}})();function R(e,t){if(e==null){let e=Error(t?`Expected ${t} to be defined`:`Expected value to be defined`);throw e.name=`ExpectDefinedError`,e}return e}function In(e,t){let n=e=>e.trim().replace(/\s+/g,` `).toLowerCase();return n(e)===n(t)}var z=e(Sn(),1),Ln=e(Je(),1),Rn=`#4f46e5`;function zn(e){return`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64">
2
- <rect x="2" y="2" width="60" height="60" rx="14" fill="${Rn}" />
3
- <text x="32" y="44" text-anchor="middle" font-family="-apple-system,Segoe UI,Roboto,sans-serif" font-size="38" font-weight="700" fill="#fff">W</text>
4
- ${e===`ready`?`<circle cx="50" cy="14" r="14" fill="#22c55e" stroke="#fff" stroke-width="3" />`:e===`error`?`<circle cx="50" cy="14" r="14" fill="#ef4444" stroke="#fff" stroke-width="3" />`:e===`running`?`<circle cx="50" cy="14" r="14" fill="#f59e0b" stroke="#fff" stroke-width="3" />`:e===`attention`?`<circle cx="50" cy="14" r="14" fill="#eab308" stroke="#fff" stroke-width="3"><animate attributeName="opacity" values="1;0.3;1" dur="1s" repeatCount="indefinite"/></circle>`:``}
5
- </svg>`}function Bn(e){return`data:image/svg+xml;charset=utf-8,${encodeURIComponent(e)}`}function Vn(){if(typeof document>`u`)return null;let e=document.querySelector(`link[rel="icon"]`);return e||(e=document.createElement(`link`),e.rel=`icon`,e.type=`image/svg+xml`,document.head.appendChild(e)),e}var Hn=`idle`;function Un(e){Hn=e;let t=Vn();t&&(t.href=Bn(zn(e)))}var Wn=!1;function Gn(){Wn||typeof document>`u`||(Wn=!0,document.addEventListener(`visibilitychange`,()=>{!document.hidden&&(Hn===`ready`||Hn===`error`||Hn===`attention`)&&Un(`idle`)}))}function Kn(e){try{return new URL(e).searchParams.get(`token`)}catch{return null}}var qn=class{ws=null;url;handlers=new Map;reconnectAttempts=0;maxReconnectAttempts=10;reconnectDelay=1e3;shouldReconnect=!0;reconnectTimer=null;messageQueue=[];pendingConfirms=new Map;sessionId=null;lastErrorText;statusListeners=new Set;currentStatus={state:`connecting`};onStatus(e){return this.statusListeners.add(e),e(this.currentStatus),()=>this.statusListeners.delete(e)}get status(){return this.currentStatus}setStatus(e){this.currentStatus=e;for(let t of this.statusListeners)try{t(e)}catch{}}constructor(e){this.url=e??Zn()}async ensureAuthCookie(){if(typeof window>`u`||document.cookie.split(`;`).some(e=>e.trim().startsWith(`ws_token=`)))return;let e=Kn(this.url);if(!e)return;let t=Qn()+`/ws-auth?token=${encodeURIComponent(e)}`;try{let e=await fetch(t,{method:`GET`,credentials:`same-origin`,cache:`no-store`});e.ok||console.warn(JSON.stringify({level:`warn`,event:`ws_client.ws_auth_failed`,status:e.status,timestamp:new Date().toISOString()}))}catch(e){console.warn(JSON.stringify({level:`warn`,event:`ws_client.ws_auth_error`,message:e instanceof Error?e.message:String(e),timestamp:new Date().toISOString()}))}}async connect(){return await this.ensureAuthCookie(),new Promise((e,t)=>{if(this.ws?.readyState===WebSocket.OPEN){e();return}this.setStatus({state:`connecting`});try{let n=Kn(this.url),r=n?`${this.url}${this.url.includes(`?`)?`&`:`?`}token=${n}`:this.url;this.ws=new WebSocket(r),this.ws.binaryType=`arraybuffer`;let i=setTimeout(()=>{t(Error(`Connection timeout`))},1e4),a=!1;this.ws.onopen=()=>{clearTimeout(i),a=!0,this.reconnectAttempts=0,this.lastErrorText=void 0,this.setStatus({state:`open`}),this.flushMessageQueue(),e()},this.ws.onmessage=e=>{try{let t=JSON.parse(e.data);this.handleMessage(t)}catch(e){console.error(JSON.stringify({level:`error`,event:`ws_client.message_parse_failed`,message:e instanceof Error?e.message:String(e),timestamp:new Date().toISOString()}))}},this.ws.onerror=e=>{console.error(JSON.stringify({level:`error`,event:`ws_client.error`,message:e instanceof Error?e.message:String(e),timestamp:new Date().toISOString()})),this.lastErrorText=`Connection error (see browser devtools)`,a||(clearTimeout(i),t(Error(this.lastErrorText)))},this.ws.onclose=e=>{if(!a){clearTimeout(i);let n=e.reason||`Closed with code ${e.code}`;this.lastErrorText=n,t(Error(n));return}e.reason&&!this.lastErrorText?this.lastErrorText=`${e.reason} (code ${e.code})`:!this.lastErrorText&&e.code!==1e3&&(this.lastErrorText=`Closed with code ${e.code}`),this.attemptReconnect()}}catch(e){this.lastErrorText=e instanceof Error?e.message:String(e),this.setStatus({state:`closed`,error:this.lastErrorText}),t(e)}})}attemptReconnect(){if(!this.shouldReconnect||this.reconnectAttempts>=this.maxReconnectAttempts){this.reconnectTimer=null,this.setStatus({state:`closed`,error:this.lastErrorText??`Disconnected`});return}this.reconnectAttempts++;let e=Math.min(this.reconnectDelay*2**(this.reconnectAttempts-1),3e4),t=Date.now()+e;this.setStatus({state:`reconnecting`,attempt:this.reconnectAttempts,nextRetryAt:t,lastError:this.lastErrorText}),this.reconnectTimer=setTimeout(async()=>{if(this.shouldReconnect)try{await this.connect()}catch(e){console.error(JSON.stringify({level:`error`,event:`ws_client.reconnect_failed`,message:e instanceof Error?e.message:String(e),timestamp:new Date().toISOString()}))}},e)}retryNow(){this.currentStatus.state!==`open`&&(this.reconnectTimer&&=(clearTimeout(this.reconnectTimer),null),this.reconnectAttempts=0,this.connect().catch(e=>console.warn(JSON.stringify({level:`warn`,event:`ws_client.reconnect_failed`,message:e instanceof Error?e.message:String(e),timestamp:new Date().toISOString()}))))}flushMessageQueue(){for(;this.messageQueue.length>0;){let e=this.messageQueue.shift();e&&this.send(e)}}handleMessage(e){if(e.type===`tool.confirm_needed`){let t=e.payload;this.pendingConfirms.set(t.id,{resolve:t.resolve});let n={...e,payload:{...t,resolve:()=>{}}};this.emit(n);return}if(e.type===`session.start`){let t=e.payload;this.sessionId=t.sessionId}this.emit(e)}emit(e){let t=this.handlers.get(e.type);if(t)for(let n of t)try{n(e)}catch(t){console.error(JSON.stringify({level:`error`,event:`ws_client.handler_error`,messageType:e.type,message:t instanceof Error?t.message:String(t),timestamp:new Date().toISOString()}))}}send(e){this.ws?.readyState===WebSocket.OPEN?this.ws.send(JSON.stringify(e)):this.messageQueue.push(e)}on(e,t){let n=this.handlers.get(e);return n||(n=new Set,this.handlers.set(e,n)),n.add(t),()=>n?.delete(t)}off(e,t){this.handlers.get(e)?.delete(t)}sendMessage(e){let t=`msg_${Date.now()}_${crypto.randomUUID().slice(0,8)}`;return this.send({type:`user_message`,payload:{id:t,content:e,timestamp:Date.now()}}),t}sendAbort(){this.send({type:`abort`,payload:{}})}sendConfirm(e,t){let n=this.pendingConfirms.get(e);n&&(n.resolve(t),this.pendingConfirms.delete(e)),this.send({type:`tool.confirm_result`,payload:{id:e,decision:t}})}switchModel(e,t){this.send({type:`model.switch`,payload:{provider:e,model:t}})}newSession(){this.send({type:`session.new`})}listProviders(){this.send({type:`providers.list`})}listProviderModels(e){this.send({type:`provider.models`,payload:{providerId:e}})}listSavedProviders(){this.send({type:`providers.saved`})}addKey(e,t,n){this.send({type:`key.add`,payload:{providerId:e,label:t,apiKey:n}})}updateKey(e,t,n){this.send({type:`key.update`,payload:{providerId:e,label:t,apiKey:n}})}deleteKey(e,t){this.send({type:`key.delete`,payload:{providerId:e,label:t}})}setActiveKey(e,t){this.send({type:`key.set_active`,payload:{providerId:e,label:t}})}addProvider(e,t,n,r){this.send({type:`provider.add`,payload:{id:e,family:t,baseUrl:n,apiKey:r}})}removeProvider(e){this.send({type:`provider.remove`,payload:{providerId:e}})}clearContext(){this.send({type:`context.clear`})}compactContext(e=!1){this.send({type:`context.compact`,payload:{aggressive:e}})}repairContext(){this.send({type:`context.repair`})}debugContext(){this.send({type:`context.debug`})}listContextModes(){this.send({type:`context.modes.list`})}switchContextMode(e){this.send({type:`context.mode.switch`,payload:{id:e}})}createContextMode(e){this.send({type:`context.mode.create`,payload:e})}updateContextMode(e,t){this.send({type:`context.mode.update`,payload:{id:e,...t}})}deleteContextMode(e){this.send({type:`context.mode.delete`,payload:{id:e}})}switchAutonomy(e){this.send({type:`autonomy.switch`,payload:{mode:e}})}updatePrefs(e){this.send({type:`prefs.update`,payload:e})}getPrefs(){this.send({type:`prefs.get`})}listTools(){this.send({type:`tools.list`})}listMemory(){this.send({type:`memory.list`})}remember(e,t){this.send({type:`memory.remember`,payload:{text:e,scope:t}})}forget(e,t){this.send({type:`memory.forget`,payload:{text:e,scope:t}})}listSkills(){this.send({type:`skills.list`})}getDiag(){this.send({type:`diag.get`})}getStats(){this.send({type:`stats.get`})}saveSession(){this.send({type:`session.save`})}resumeSessionById(e){this.send({type:`session.resume`,payload:{id:e}})}listModes(){this.send({type:`modes.list`})}switchMode(e){this.send({type:`mode.switch`,payload:{id:e}})}listFiles(e,t,n){this.send({type:`files.list`,payload:{query:e,limit:t,path:n}})}getTodos(){this.send({type:`todos.get`})}clearTodos(){this.send({type:`todos.clear`})}removeTodo(e){let t=typeof e==`number`?{index:e}:{id:e};this.send({type:`todos.remove`,payload:t})}updateTodoStatus(e,t){this.send({type:`todo.update`,payload:{id:e,status:t}})}getTasks(){this.send({type:`tasks.get`})}updateTaskStatus(e,t){this.send({type:`task.update`,payload:{id:e,status:t}})}getPlan(){this.send({type:`plan.get`})}updatePlanItem(e,t){this.send({type:`plan.item.update`,payload:{target:e,status:t}})}listSessions(e=50){this.send({type:`sessions.list`,payload:{limit:e}})}deleteSession(e){this.send({type:`session.delete`,payload:{id:e}})}listProjects(){this.send({type:`projects.list`})}addProject(e,t){this.send({type:`projects.add`,payload:{root:e,name:t}})}selectProject(e,t){this.send({type:`projects.select`,payload:{root:e,name:t}})}setWorkingDir(e){this.send({type:`working_dir.set`,payload:{path:e}})}resumeSession(e){this.send({type:`session.resume`,payload:{id:e}})}ping(){this.send({type:`ping`})}refineModel(e){this.send({type:`model.refine`,payload:{text:e}})}disconnect(){this.shouldReconnect=!1,this.reconnectTimer&&=(clearTimeout(this.reconnectTimer),null),this.ws?.close(),this.ws=null}get isConnected(){return this.ws?.readyState===WebSocket.OPEN}get currentSessionId(){return this.sessionId}},Jn=null,Yn=3457;function Xn(){if(typeof document>`u`)return Yn;let e=document.querySelector(`meta[name="wrongstack-ws-port"]`)?.getAttribute(`content`),t=e?Number.parseInt(e,10):NaN;return Number.isFinite(t)&&t>0&&t<65536?t:Yn}function Zn(){let e=Xn();if(typeof window>`u`||!window.location?.hostname)return`ws://127.0.0.1:${e}`;let t=window.location.hostname.toLowerCase();return t===`localhost`||t===`127.0.0.1`||t===`[::1]`||t===`::1`?`ws://127.0.0.1:${e}`:`ws://${window.location.hostname}:${e}`}function Qn(){if(typeof window>`u`||!window.location?.hostname)return`http://127.0.0.1:3456`;let e=window.location.hostname.toLowerCase(),t=window.location.port?Number.parseInt(window.location.port,10):NaN,n=Number.isFinite(t)&&t>0?t:3456;return e===`localhost`||e===`127.0.0.1`||e===`[::1]`||e===`::1`?`http://127.0.0.1:${n}`:`http://${window.location.hostname}:${n}`}function B(e){return Jn||=new qn(e),Jn}function $n(e){if(!e)return e;let t=e.split(/\n{2,}/),n=[];for(let e of t)n.length>0&&n[n.length-1]?.trim()===e.trim()||n.push(e);return n.map(e=>{let t=e.split(`
6
- `),n=[];for(let e of t)n.length>0&&e.trim().length>0&&n[n.length-1]?.trim()===e.trim()||n.push(e);return n.join(`
7
- `)}).join(`
8
-
9
- `)}var V=bt()(wt((e,t)=>({messages:[],currentAssistantMessageId:null,currentToolId:null,isLoading:!1,abortController:null,executions:new Map,queue:[],runStart:null,thinkingBuffer:``,thinkingStartedAt:null,addMessage:t=>{let n=`msg_${Date.now()}_${crypto.randomUUID().slice(0,8)}`,r={...t,id:n,timestamp:t.timestamp??Date.now()};return e(e=>({messages:[...e.messages,r],currentAssistantMessageId:t.role===`assistant`?n:e.currentAssistantMessageId})),n},updateMessage:(t,n)=>{e(e=>({messages:e.messages.map(e=>e.id===t?{...e,...n}:e)}))},appendToMessage:(t,n)=>{e(e=>({messages:e.messages.map(e=>e.id===t?{...e,content:e.content+n}:e)}))},finalizeMessage:t=>{e(e=>({messages:e.messages.map(e=>e.id===t?{...e,content:$n(e.content),streaming:!1}:e)}))},setToolResult:(t,n,r)=>{e(e=>({messages:e.messages.map(e=>e.id===t?{...e,toolResult:n,isError:!r,progressLines:void 0}:e)}))},appendToolProgress:(e,n)=>{t().appendToolProgressLines(e,[n])},appendToolProgressLines:(t,n)=>{n.length!==0&&e(e=>({messages:e.messages.map(e=>{if(e.id!==t)return e;let r=[...e.progressLines??[],...n],i=r.length>30?r.slice(r.length-30):r;return{...e,progressLines:i}})}))},setLoading:t=>e({isLoading:t}),setAbortController:t=>e({abortController:t}),clearMessages:()=>e({messages:[],currentAssistantMessageId:null,currentToolId:null,executions:new Map}),setCurrentAssistantMessage:t=>e({currentAssistantMessageId:t}),setCurrentToolId:t=>e({currentToolId:t}),truncateAfter:t=>e(e=>{let n=e.messages.findIndex(e=>e.id===t);return n===-1?e:{messages:e.messages.slice(0,n),currentAssistantMessageId:null,currentToolId:null}}),addExecution:t=>{e(e=>{let n=new Map(e.executions);return n.set(t.id,t),{executions:n}})},updateExecution:(t,n)=>{e(e=>{let r=new Map(e.executions),i=r.get(t);return i&&r.set(t,{...i,...n}),{executions:r}})},enqueue:t=>e(e=>({queue:[...e.queue,t]})),dequeue:()=>{let{queue:n}=t();if(n.length===0)return null;let[r,...i]=n;return e({queue:i}),R(r)},removeQueued:t=>e(e=>({queue:e.queue.filter((e,n)=>n!==t)})),clearQueue:()=>e({queue:[]}),setRunStart:t=>e({runStart:t}),appendThinking:t=>e(e=>({thinkingBuffer:e.thinkingBuffer+t,thinkingStartedAt:e.thinkingStartedAt??Date.now()})),clearThinking:()=>e({thinkingBuffer:``,thinkingStartedAt:null})}),{name:`wrongstack-chat`,partialize:()=>({})})),H=bt()(wt(e=>({provider:`anthropic`,model:`claude-sonnet-4-20250514`,wsUrl:(()=>{if(typeof window>`u`||!window.location?.hostname)return`ws://127.0.0.1:3457`;let e=window.location.hostname.toLowerCase();return e===`localhost`||e===`127.0.0.1`||e===`[::1]`||e===`::1`?`ws://127.0.0.1:3457`:`ws://${window.location.hostname}:3457`})(),wsConnected:!1,wsStatus:{state:`connecting`},theme:`system`,autoConnect:!0,soundOnComplete:!1,setProvider:t=>e({provider:t}),setModel:t=>e({model:t}),setConfig:t=>e(t),setTheme:t=>e({theme:t}),setWsConnected:t=>e({wsConnected:t}),setWsStatus:t=>e({wsStatus:t,wsConnected:t.state===`open`}),setSoundOnComplete:t=>e({soundOnComplete:t})}),{name:`wrongstack-config`})),U=bt()(wt(e=>({session:null,totalTokens:{input:0,output:0,cacheRead:0,cacheWrite:0},lastInputTokens:0,cost:0,startTime:null,maxContext:0,inputCost:0,outputCost:0,cacheReadCost:0,projectName:``,projectRoot:``,cwd:``,mode:`default`,modes:[],contextMode:`balanced`,contextModes:[],iteration:null,todos:[],setSession:t=>e({session:t}),updateUsage:t=>e(e=>{let n=t.input+(t.cacheRead??0)+(t.cacheWrite??0),r=t.cacheRead??0,i=t.cacheWrite??0;return{totalTokens:{input:e.totalTokens.input+t.input,output:e.totalTokens.output+t.output,cacheRead:(e.totalTokens.cacheRead??0)+r,cacheWrite:(e.totalTokens.cacheWrite??0)+i},lastInputTokens:n||e.lastInputTokens}}),addCost:t=>e(e=>({cost:e.cost+t})),startSession:t=>e({session:t,startTime:Date.now(),iteration:null,lastInputTokens:0,totalTokens:{input:0,output:0,cacheRead:0,cacheWrite:0},cost:0}),endSession:()=>e({session:null,startTime:null,iteration:null}),setEnv:t=>e(e=>({maxContext:t.maxContext??e.maxContext,projectRoot:t.projectRoot??e.projectRoot,projectName:t.projectName??e.projectName,cwd:t.cwd??e.cwd,mode:t.mode??e.mode,contextMode:t.contextMode??e.contextMode,inputCost:t.inputCost??e.inputCost,outputCost:t.outputCost??e.outputCost,cacheReadCost:t.cacheReadCost??e.cacheReadCost})),setIteration:t=>e({iteration:t}),setModes:t=>e({modes:t}),setContextModes:t=>e({contextModes:t}),setTodos:t=>e({todos:t})}),{name:`wrongstack-session`,partialize:()=>({})})),er=[`chat`,`agents`,`history`,`files`,`projects`,`mailbox`];function tr(e){return er.includes(e)?e:e===`context`?`chat`:e===`sessions`?`history`:`chat`}var W=bt()(wt(e=>({sidebarOpen:!0,activeActivity:`chat`,settingsOpen:!1,currentView:`chat`,showConfirmDialog:!1,confirmInfo:null,paletteOpen:!1,shortcutsOpen:!1,searchOpen:!1,searchQuery:``,scrollTarget:null,promptHistory:[],sidebarWidth:304,pinnedIds:[],compactMode:!1,modelSwitcherOpen:!1,favoriteSessionIds:[],sessionNicknames:{},fileExplorerWidth:220,refineEnabled:!0,refinePanel:null,dockSection:null,fleetMonitorOpen:!1,agentsMonitorOpen:!1,inspectorOpen:!1,inspectorTab:`fleet`,selectActivity:t=>e({activeActivity:t}),toggleSidebar:()=>e(e=>({sidebarOpen:!e.sidebarOpen})),setSidebarOpen:t=>e({sidebarOpen:t}),setSettingsOpen:t=>e({settingsOpen:t}),setCurrentView:t=>e({currentView:t}),showConfirm:t=>e({showConfirmDialog:!0,confirmInfo:t}),hideConfirm:()=>e({showConfirmDialog:!1,confirmInfo:null}),setPaletteOpen:t=>e({paletteOpen:t}),setShortcutsOpen:t=>e({shortcutsOpen:t}),setSearchOpen:t=>e({searchOpen:t,searchQuery:``}),setSearchQuery:t=>e({searchQuery:t}),requestScrollToMessage:t=>e(e=>({scrollTarget:{id:t,nonce:(e.scrollTarget?.nonce??0)+1}})),pushPrompt:t=>e(e=>{let n=t.trim();return n?{promptHistory:[n,...e.promptHistory.filter(e=>e!==n)].slice(0,50)}:e}),setSidebarWidth:t=>e({sidebarWidth:Math.max(240,Math.min(560,Math.round(t)))}),togglePin:t=>e(e=>({pinnedIds:e.pinnedIds.includes(t)?e.pinnedIds.filter(e=>e!==t):[...e.pinnedIds,t]})),unpinAll:()=>e({pinnedIds:[]}),toggleCompactMode:()=>e(e=>({compactMode:!e.compactMode})),setModelSwitcherOpen:t=>e({modelSwitcherOpen:t}),toggleFavoriteSession:t=>e(e=>({favoriteSessionIds:e.favoriteSessionIds.includes(t)?e.favoriteSessionIds.filter(e=>e!==t):[...e.favoriteSessionIds,t]})),setSessionNickname:(t,n)=>e(e=>{let r=n.trim(),i={...e.sessionNicknames};return r?i[t]=r:delete i[t],{sessionNicknames:i}}),setFileExplorerWidth:t=>e({fileExplorerWidth:Math.max(160,Math.min(400,Math.round(t)))}),toggleRefineEnabled:()=>e(e=>({refineEnabled:!e.refineEnabled})),setRefinePanel:t=>e({refinePanel:t}),setDockSection:t=>e({dockSection:t}),toggleDockSection:t=>e(e=>({dockSection:e.dockSection===t?null:t})),setFleetMonitorOpen:t=>e({fleetMonitorOpen:t}),setAgentsMonitorOpen:t=>e({agentsMonitorOpen:t}),setInspectorOpen:t=>e({inspectorOpen:t}),setInspectorTab:t=>e({inspectorTab:t}),toggleInspector:()=>e(e=>({inspectorOpen:!e.inspectorOpen}))}),{name:`wrongstack-ui`,version:2,migrate:(e,t)=>{let n=e??{};return n.activeActivity=tr(n.activeActivity),typeof n.sidebarWidth==`number`&&(n.sidebarWidth=Math.max(240,Math.min(560,n.sidebarWidth))),t<2&&(delete n.fleetDrawerOpen,delete n.agentsDrawerOpen),n},partialize:e=>({sidebarOpen:e.sidebarOpen,activeActivity:e.activeActivity,sidebarWidth:e.sidebarWidth,promptHistory:e.promptHistory,pinnedIds:e.pinnedIds,compactMode:e.compactMode,favoriteSessionIds:e.favoriteSessionIds,sessionNicknames:e.sessionNicknames,fileExplorerWidth:e.fileExplorerWidth,refineEnabled:e.refineEnabled,inspectorOpen:e.inspectorOpen,inspectorTab:e.inspectorTab})})),nr=bt()(e=>({messages:[],agents:[],setMessages:t=>e({messages:t}),setAgents:t=>e({agents:t})}));function rr(e){return e.messages.filter(e=>e.readByCount===0&&!e.completed).length}var ir=bt()(e=>({entries:[],loading:!1,error:null,setEntries:(t,n=null)=>e({entries:t,error:n,loading:!1}),setLoading:t=>e({loading:t}),removeEntry:t=>e(e=>({entries:e.entries.filter(e=>e.id!==t)})),clearHistory:()=>e({entries:[]})})),ar=bt()(e=>({worktrees:[],baseBranch:``,activity:[],setSnapshot:(t,n)=>e({worktrees:t,baseBranch:n}),pushEvent:t=>e(e=>({activity:[...e.activity,t].slice(-40)}))})),G=Le(),or=/πŸ’‘\s*Next steps?\s*\n+((?:\d+\.\s+.+(?:\s+auto="true")?\n?)+)/i,sr=/^(\d+)\.\s+(.+?)(?:\s+auto="true")?$/;function cr(e){let t=or.exec(e);if(t?.[1]){let e=t[1];return lr(e)}return lr(e)}function lr(e){let t=e.split(`
10
- `).filter(Boolean),n=[];for(let e of t){let t=sr.exec(e.trim());if(t){let r=t[2].trim(),i=e.trim().endsWith(`auto="true"`);n.push({index:Number.parseInt(t[1],10),text:r,auto:i})}}return n.slice(0,6)}function ur(e){return e.replace(/<next_steps\b[^>]*>[\s\S]*?<\/next_steps>/gi,``).replace(/<next_steps\b[^>]*\/?>/gi,``).replace(/\n{3,}/g,`
11
-
12
- `).trim()}function dr(e){let t=document.querySelector(`textarea`);t&&((Object.getOwnPropertyDescriptor(window.HTMLTextAreaElement.prototype,`value`)?.set)?.call(t,e),t.dispatchEvent(new Event(`input`,{bubbles:!0})),t.focus())}function fr({delayMs:e,onComplete:t}){let[n,r]=(0,z.useState)(Math.ceil(e/1e3));return(0,z.useEffect)(()=>{if(n<=0){t();return}let e=setTimeout(()=>r(e=>e-1),1e3);return()=>clearTimeout(e)},[n,t]),(0,G.jsxs)(`span`,{className:`flex items-center gap-1 text-xs text-primary font-medium`,children:[(0,G.jsx)(ut,{className:`h-3 w-3`}),n,`s`]})}function pr({steps:e,yoloMode:t=!1,autoMode:n=!1,autoDelayMs:r=3e4,onAutoSubmit:i}){if(e.length===0)return null;let a=t&&n,o=a?e.find(e=>e.auto):void 0;return(0,G.jsxs)(`div`,{className:`mt-4 rounded-xl border border-primary/20 bg-primary/[0.03] overflow-hidden animate-message`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 px-3.5 py-2 border-b border-primary/10 bg-primary/[0.04]`,children:[(0,G.jsx)(`span`,{className:`flex items-center justify-center w-5 h-5 rounded-md bg-primary/15 text-primary`,children:(0,G.jsx)(Dt,{className:`h-3 w-3`})}),(0,G.jsx)(`span`,{className:`text-xs font-semibold text-foreground/90`,children:`Next steps`}),a&&o?(0,G.jsxs)(`span`,{className:`ml-auto flex items-center gap-1 text-xs text-primary`,children:[(0,G.jsx)(ut,{className:`h-3 w-3`}),`auto-submitting in `,(0,G.jsx)(fr,{delayMs:r,onComplete:()=>i?.(o.text)})]}):(0,G.jsx)(`span`,{className:`text-[10px] text-muted-foreground ml-auto`,children:`click to fill input`})]}),(0,G.jsx)(`div`,{className:`flex flex-col p-2 gap-1`,children:e.map(e=>{let t=a&&e.auto;return(0,G.jsxs)(`button`,{type:`button`,onClick:()=>dr(e.text),className:`group flex items-center gap-2.5 w-full text-left px-3 py-2 rounded-lg transition-all border ${t?`bg-primary/10 border-primary/30 ring-1 ring-primary/20`:`border-transparent hover:bg-primary/[0.08] hover:shadow-sm hover:border-primary/20`}`,title:`Click to fill: ${e.text}`,children:[(0,G.jsx)(`span`,{className:`flex items-center justify-center w-5 h-5 rounded-md text-[11px] font-mono font-semibold tabular-nums shrink-0 transition-colors ${t?`bg-primary/30 text-primary`:`bg-muted/80 group-hover:bg-primary/20 text-muted-foreground group-hover:text-primary`}`,children:e.index}),(0,G.jsx)(vn,{className:`h-3.5 w-3.5 shrink-0 transition-all ${t?`text-primary`:`text-muted-foreground/60 group-hover:text-primary group-hover:translate-x-0.5`}`}),(0,G.jsx)(`span`,{className:`text-sm leading-snug flex-1 min-w-0 transition-colors ${t?`text-foreground font-medium`:`text-foreground/80 group-hover:text-foreground`}`,children:e.text}),e.auto&&(0,G.jsxs)(`span`,{className:`flex items-center gap-1 text-[10px] text-primary/70`,children:[(0,G.jsx)(ut,{className:`h-3 w-3`}),`auto`]}),(0,G.jsx)(Ie,{className:`h-3.5 w-3.5 shrink-0 transition-all ${t?`opacity-100 text-primary/60`:`opacity-0 group-hover:opacity-100 text-primary/60`}`})]},e.index)})})]})}var mr=12,hr=20;function gr(e,t,n){return{id:e,name:t?.trim()||e,sessionId:n,status:`running`,iteration:0,toolCalls:0,costUsd:0,ctxPct:0,ctxTokens:0,maxContext:0,extensions:0,startedAt:Date.now(),toolLog:[],sparklineBins:Array(mr).fill(0)}}var _r=0;function vr(){return`tl_${Date.now()}_${++_r}`}function yr(e,t){return[t,...e].slice(0,hr)}function br(e){return[e[0]+1,...e.slice(0,mr-1)]}var K=bt()((e,t)=>({agents:new Map,leaderId:void 0,fleetTokensIn:0,fleetTokensOut:0,fleetConcurrency:0,fleetConcurrencyMax:4,eventTimeline:[],clear:()=>e({agents:new Map,leaderId:void 0,fleetTokensIn:0,fleetTokensOut:0,fleetConcurrency:0,eventTimeline:[]}),getAgentsBySession:e=>{let n=[];for(let r of t().agents.values())r.sessionId===e&&n.push(r);return n},applyEvent:t=>e(e=>{let n=new Map(e.agents),r=e.eventTimeline,i=e.leaderId,a=e.fleetTokensIn,o=e.fleetTokensOut;if(t.kind===`session_stopped`&&t.sessionId){for(let[e,r]of n)r.sessionId===t.sessionId&&n.delete(e);return{agents:n,leaderId:void 0,fleetTokensIn:0,fleetTokensOut:0}}if(t.kind===`leader_updated`&&t.subagentId){let a=e.leaderId;if(a&&a!==t.subagentId){let e=n.get(a);e&&n.set(a,{...e,isLeader:!1})}i=t.subagentId;let o=n.get(t.subagentId)??gr(t.subagentId,t.name,t.sessionId);return n.set(t.subagentId,{...o,isLeader:!0,name:t.name?.trim()||o.name}),r=yr(r,{id:vr(),kind:`leader_updated`,agentId:t.subagentId,agentName:t.name??i,timestamp:Date.now(),message:`${t.name??t.subagentId} became leader`}),{agents:n,leaderId:i,eventTimeline:r}}if(!t.subagentId)return e;let s=n.get(t.subagentId)??gr(t.subagentId,t.name,t.sessionId),c={...s},l=Date.now();switch(t.kind){case`spawned`:c.name=t.name?.trim()||c.name,c.provider=t.provider??c.provider,c.model=t.model??c.model,c.description=t.description??c.description,c.taskId=t.taskId??c.taskId,c.sessionId=t.sessionId??c.sessionId,c.status=`running`,c.sparklineBins=Array(mr).fill(0),r=yr(r,{id:vr(),kind:`spawned`,agentId:t.subagentId,agentName:c.name,timestamp:l,message:`${c.name} spawned`});break;case`task_started`:c.description=t.description??c.description,c.taskId=t.taskId??c.taskId,c.status=`running`,r=yr(r,{id:vr(),kind:`task_started`,agentId:t.subagentId,agentName:c.name,timestamp:l,message:`${c.name} started: ${t.description??`new task`}`});break;case`tool_executed`:{let e=typeof t.ok==`boolean`?t.ok:!0,n=typeof t.durationMs==`number`?t.durationMs:0;c.lastTool=t.toolName??c.lastTool,c.toolCalls+=1,c.toolLog=[{name:t.toolName??`unknown`,ok:e,durationMs:n,at:l},...c.toolLog].slice(0,50),c.sparklineBins=br(c.sparklineBins),r=yr(r,{id:vr(),kind:`tool_executed`,agentId:t.subagentId,agentName:c.name,timestamp:l,message:`${c.name} ${e?`βœ“`:`βœ—`} ${t.toolName??`tool`}`,value:n});break}case`iteration_summary`:c.iteration=t.iteration??c.iteration,typeof t.toolCalls==`number`&&(c.toolCalls=t.toolCalls),typeof t.costUsd==`number`&&(c.costUsd=t.costUsd),c.currentTool=t.currentTool??c.currentTool,typeof t.partialText==`string`&&t.partialText&&(c.partialText=t.partialText),c.sparklineBins=br(c.sparklineBins),r=yr(r,{id:vr(),kind:`iteration_summary`,agentId:t.subagentId,agentName:c.name,timestamp:l,message:`${c.name} iter ${t.iteration??c.iteration} Β· ${t.currentTool?`${t.currentTool}`:``}`,value:t.costUsd});break;case`budget_extended`:c.extensions=t.totalExtensions??c.extensions+1,c.budgetWarning=void 0,r=yr(r,{id:vr(),kind:`budget_extended`,agentId:t.subagentId,agentName:c.name,timestamp:l,message:`${c.name} extended budget βš‘Γ—${c.extensions}`});break;case`ctx_pct`:c.ctxPct=Math.round(Math.max(0,t.load??0)*100),c.ctxTokens=t.tokens??c.ctxTokens,c.maxContext=t.maxContext??c.maxContext,c.ctxPct>=80&&!c.budgetWarning&&(c.budgetWarning=c.ctxPct>=100?{kind:`hard`,used:c.ctxPct,limit:100}:{kind:`soft`,used:c.ctxPct,limit:100}),typeof t.costUsd==`number`&&(c.costUsd=t.costUsd),typeof t.tokensIn==`number`&&(c.tokensIn=t.tokensIn,a=a-(s.tokensIn??0)+t.tokensIn),typeof t.tokensOut==`number`&&(c.tokensOut=t.tokensOut,o=o-(s.tokensOut??0)+t.tokensOut),r=yr(r,{id:vr(),kind:`ctx_pct`,agentId:t.subagentId,agentName:c.name,timestamp:l,message:`${c.name} ctx ${c.ctxPct}%`,value:c.ctxPct});break;case`task_completed`:{c.status=t.status===`success`?`completed`:t.status??`completed`,typeof t.iterations==`number`&&(c.iteration=t.iterations),typeof t.toolCalls==`number`&&(c.toolCalls=t.toolCalls),c.error=t.error,c.currentTool=void 0,c.completedAt=l,c.failureReason=t.failureReason??c.failureReason,typeof t.finalText==`string`&&t.finalText&&(c.finalText=ur(t.finalText));let e=t.status===`success`?`βœ“ completed`:t.status===`failed`?`βœ— failed${t.failureReason?` (${t.failureReason})`:``}`:t.status===`timeout`?`⏱ timeout${t.failureReason?` (${t.failureReason})`:``}`:`stopped`;r=yr(r,{id:vr(),kind:`task_completed`,agentId:t.subagentId,agentName:c.name,timestamp:l,message:`${c.name} ${e}`,value:c.costUsd});break}}return n.set(t.subagentId,c),{agents:n,leaderId:i,fleetTokensIn:a,fleetTokensOut:o,eventTimeline:r}})}));function xr(e){return!e||typeof e.goal!=`string`||!e.goal.trim()?null:{goal:e.goal,refinedGoal:typeof e.refinedGoal==`string`?e.refinedGoal:void 0,goalState:[`active`,`paused`,`completed`,`failed`,`abandoned`].includes(e.goalState)?e.goalState:`active`,iterations:typeof e.iterations==`number`?e.iterations:0,progress:typeof e.progress==`number`?e.progress:0,progressNote:typeof e.progressNote==`string`?e.progressNote:void 0,progressTrend:e.progressTrend===`accelerating`?`up`:e.progressTrend===`stalling`?`down`:e.progressTrend===`steady`?`stable`:void 0,deliverables:Array.isArray(e.deliverables)?e.deliverables.map((e,t)=>typeof e==`string`?{id:`d${t}`,text:e,status:/^\[[xβœ“]\]|βœ…|\(done\)/i.test(e)?`done`:`pending`}:e):void 0,journal:Array.isArray(e.journal)?e.journal:void 0,lastTask:typeof e.lastTask==`string`?e.lastTask:void 0,lastStatus:typeof e.lastStatus==`string`?e.lastStatus:void 0}}var Sr=bt()(e=>({goal:null,setGoal:t=>e({goal:xr(t)}),clear:()=>e({goal:null}),refresh:()=>{try{B()?.send?.({type:`goal.get`})}catch{}}})),Cr=bt()(e=>({phases:[],activePhaseId:null,overallPercent:0,autonomous:!1,title:null,setState:t=>e(e=>({phases:t.phases??e.phases,activePhaseId:t.activePhaseId===void 0?e.activePhaseId:t.activePhaseId,overallPercent:t.overallPercent??e.overallPercent,autonomous:t.autonomous??e.autonomous,title:t.title===void 0?e.title:t.title})),clear:()=>e({phases:[],activePhaseId:null,overallPercent:0,autonomous:!1,title:null})})),wr={autonomy:`off`,autonomyDelayMs:45e3,autoProceedMaxIterations:50,yolo:!1,maxIterations:500,chime:!1,confirmExit:!0,streamFleet:!0,nextPrediction:!1,featureMcp:!0,featurePlugins:!0,featureMemory:!0,featureSkills:!0,featureModelsRegistry:!0,indexOnStart:!0,contextAutoCompact:!0,contextStrategy:`hybrid`,logLevel:`info`,auditLevel:`standard`,enhanceEnabled:!0,enhanceDelayMs:6e4,enhanceLanguage:`original`},Tr=bt()(wt(e=>({...wr,set:t=>e(t),reset:()=>e(wr)}),{name:`wrongstack-local-prefs`,version:2,migrate:e=>{let t=e??{};return[`hybrid`,`intelligent`,`selective`].includes(t.contextStrategy)||(t.contextStrategy=`hybrid`),t.auditLevel===`verbose`&&(t.auditLevel=`full`),[`minimal`,`standard`,`full`].includes(t.auditLevel)||(t.auditLevel=`standard`),typeof t.autoProceedMaxIterations!=`number`&&(t.autoProceedMaxIterations=50),t}})),q=bt()((e,t)=>({projectRoot:``,tree:[],openFiles:[],activeFilePath:null,treeLoading:!1,error:null,setTree:(t,n)=>e({projectRoot:t,tree:n,treeLoading:!1,error:null}),openFile:(n,r)=>{let i=t();if(i.openFiles.find(e=>e.path===n)){e({activeFilePath:n});return}e({openFiles:[...i.openFiles,{path:n,content:r,dirty:!1,savedContent:r}],activeFilePath:n})},closeFile:n=>{let r=t(),i=r.openFiles.findIndex(e=>e.path===n);if(i===-1)return;let a=[...r.openFiles];a.splice(i,1);let o=r.activeFilePath;r.activeFilePath===n&&(o=a.length===0?null:i<a.length?a[i].path:a[a.length-1].path),e({openFiles:a,activeFilePath:o})},setActiveFile:t=>e({activeFilePath:t}),updateContent:(t,n)=>{e(e=>({openFiles:e.openFiles.map(e=>e.path===t?{...e,content:n,dirty:n!==e.savedContent}:e)}))},markSaved:t=>{e(e=>({openFiles:e.openFiles.map(e=>e.path===t?{...e,dirty:!1,savedContent:e.content}:e)}))},setTreeLoading:t=>e({treeLoading:t}),setError:t=>e({error:t})})),Er=0;function J(){return`viz_${Date.now()}_${++Er}`}var Dr={provider:`hsl(180, 80%, 55%)`,agent:`hsl(280, 80%, 65%)`,tool:`hsl(40, 90%, 55%)`,mailbox:`hsl(140, 70%, 55%)`,session:`hsl(220, 80%, 60%)`,system:`hsl(0, 0%, 60%)`,error:`hsl(0, 80%, 55%)`},Or={"provider:call":`hsl(180, 80%, 55%)`,"provider:delta":`hsl(180, 60%, 70%)`,"agent:tool":`hsl(40, 90%, 55%)`,"mailbox:send":`hsl(140, 70%, 55%)`,default:`hsl(0, 0%, 40%)`},kr=bt()((e,t)=>({events:[],nodes:new Map,edges:new Map,isActive:!1,maxEvents:500,counters:{totalTokens:0,totalCost:0,totalToolCalls:0,activeAgents:0,completedTasks:0,errors:0,mailboxMessages:0},pushEvent:t=>e(e=>{let n=[{...t,id:J(),timestamp:t.timestamp||Date.now()},...e.events];return n.length>e.maxEvents&&(n.length=e.maxEvents),{events:n}}),upsertNode:t=>e(e=>{let n=new Map(e.nodes),r=n.get(t.id);return n.set(t.id,{...r,...t,lastSeenAt:Date.now()}),{nodes:n}}),removeNode:t=>e(e=>{let n=new Map(e.nodes);n.delete(t);let r=new Map(e.edges);for(let[e,n]of r)(n.source===t||n.target===t)&&r.delete(e);return{nodes:n,edges:r}}),upsertEdge:t=>e(e=>{let n=new Map(e.edges),r=n.get(t.id);return n.set(t.id,{...r,...t,lastActiveAt:Date.now(),intensity:t.intensity??r?.intensity??.5,color:t.color??Or[t.kind]??Or.default,totalMagnitude:(r?.totalMagnitude??0)+(t.totalMagnitude??0)}),{edges:n}}),removeEdge:t=>e(e=>{let n=new Map(e.edges);return n.delete(t),{edges:n}}),clear:()=>e({events:[],nodes:new Map,edges:new Map,counters:{totalTokens:0,totalCost:0,totalToolCalls:0,activeAgents:0,completedTasks:0,errors:0,mailboxMessages:0}}),setActive:t=>e({isActive:t}),decayActivity:()=>e(e=>{let t=new Map(e.nodes);for(let[e,n]of t)n.activity>.01&&t.set(e,{...n,activity:n.activity*.92});return{nodes:t}}),prunesStale:t=>e(e=>{let n=Date.now()-t,r=new Map(e.nodes);for(let[e,t]of r)t.lastSeenAt<n&&t.status!==`active`&&r.delete(e);let i=new Map(e.edges);for(let[e,t]of i)t.lastActiveAt<n&&i.delete(e);return{nodes:r,edges:i,events:e.events.filter(e=>e.timestamp>n)}})}));function Ar(e,t){switch(e){case`provider.text_delta`:{let e=t.text??``;return{id:J(),kind:`provider:delta`,timestamp:Date.now(),source:`provider`,target:`leader`,label:e.slice(0,60),magnitude:e.length,data:{text:e},color:Dr.provider,flowGroup:`provider`}}case`provider.response`:{let e=t.usage,n=(e?.input??0)+(e?.output??0);return{id:J(),kind:`provider:response`,timestamp:Date.now(),source:`provider`,target:`leader`,label:`${(e?.input??0).toLocaleString()} in / ${(e?.output??0).toLocaleString()} out`,magnitude:n,data:t,color:Dr.provider,flowGroup:`provider`}}case`tool.started`:{let e=t.name??`tool`;return{id:J(),kind:`tool:started`,timestamp:Date.now(),source:e,target:`filesystem`,label:e,magnitude:1,data:t,color:Dr.tool,flowGroup:`tool:${e}`}}case`tool.executed`:{let e=t.name??`tool`,n=t.ok??!0;return{id:J(),kind:`tool:executed`,timestamp:Date.now(),source:e,target:`leader`,label:`${e} ${n?`βœ“`:`βœ—`} (${t.durationMs??0}ms)`,magnitude:t.durationMs??0,data:t,color:n?Dr.tool:Dr.error,flowGroup:`tool:${e}`}}case`subagent.event`:{let e=t.kind,n=t.subagentId??`unknown`,r=t.name??n;switch(e){case`spawned`:return{id:J(),kind:`agent:spawned`,timestamp:Date.now(),source:n,target:`session`,label:`${r} spawned`,magnitude:1,data:t,color:Dr.agent,flowGroup:`agent:${n}`};case`tool_executed`:{let e=t.toolName??`tool`,r=t.ok??!0;return{id:J(),kind:`agent:tool`,timestamp:Date.now(),source:n,target:e,label:e,magnitude:t.durationMs??0,data:t,color:r?Dr.tool:Dr.error,flowGroup:`agent:${n}`}}case`task_completed`:{let e=t.status??`completed`;return{id:J(),kind:`agent:status`,timestamp:Date.now(),source:n,target:`session`,label:`${r} ${e}`,magnitude:1,data:t,color:e===`success`?`hsl(140, 70%, 55%)`:Dr.error,flowGroup:`agent:${n}`}}case`ctx_pct`:return{id:J(),kind:`agent:ctx`,timestamp:Date.now(),source:n,target:`session`,label:`ctx ${Math.round((t.load??0)*100)}%`,magnitude:t.tokens??0,data:t,color:Dr.agent,flowGroup:`agent:${n}`};case`iteration_summary`:return{id:J(),kind:`agent:text`,timestamp:Date.now(),source:n,target:`session`,label:(t.partialText??``).slice(0,80)||`iter ${t.iteration??0}`,magnitude:t.costUsd??0,data:t,color:Dr.agent,flowGroup:`agent:${n}`};case`budget_extended`:return{id:J(),kind:`budget:extended`,timestamp:Date.now(),source:n,target:`session`,label:`${r} extended budget`,magnitude:t.totalExtensions??1,data:t,color:`hsl(40, 90%, 55%)`,flowGroup:`agent:${n}`}}return null}case`mailbox.event`:{let e=t.event,n=t.from??`?`,r=t.to??`?`,i=t.subject??``,a=e===`mailbox.sent`;return{id:J(),kind:a?`mailbox:send`:`mailbox:deliver`,timestamp:Date.now(),source:n,target:r,label:i||(a?`β†’ ${r}`:`← ${n}`),magnitude:1,data:t,color:Dr.mailbox,flowGroup:`mailbox`}}case`iteration.started`:{let e=t.index??0;return{id:J(),kind:`iteration:start`,timestamp:Date.now(),source:`leader`,target:`session`,label:`Iteration ${e}`,magnitude:e,data:t,color:Dr.agent,flowGroup:`iteration`}}case`error`:{let e=t.message??`Error`;return{id:J(),kind:`error`,timestamp:Date.now(),source:t.phase??`system`,target:`session`,label:e,magnitude:1,data:t,color:Dr.error,flowGroup:`error`}}case`context.compacted`:return{id:J(),kind:`context:compacted`,timestamp:Date.now(),source:`system`,target:`session`,label:`Compacted: ${(t.saved??0).toLocaleString()} tokens`,magnitude:t.saved??0,data:t,color:`hsl(220, 60%, 50%)`,flowGroup:`context`};case`context.repaired`:return{id:J(),kind:`context:repaired`,timestamp:Date.now(),source:`system`,target:`session`,label:`Repaired: ${t.removedMessages??0} msgs`,magnitude:t.removedMessages??0,data:t,color:`hsl(220, 60%, 50%)`,flowGroup:`context`};case`session.start`:{let e=t.sessionId??`?`,n=t.projectName??``;return{id:J(),kind:`session:start`,timestamp:Date.now(),source:`session`,target:`leader`,label:n||e.slice(0,12),magnitude:1,data:t,color:Dr.session,flowGroup:`session`}}case`sessions.status_update`:{let e=t.sessions??[];return{id:J(),kind:`fleet:snapshot`,timestamp:Date.now(),source:`system`,target:`session`,label:`${e.length} session(s)`,magnitude:e.length,data:t,color:Dr.system,flowGroup:`fleet`}}default:return null}}function Y(...e){return j(Be(e))}var jr=bt(e=>({toasts:[],push:t=>{let n=`toast_${Date.now()}_${Math.random().toString(36).slice(2,7)}`;return e(e=>({toasts:[...e.toasts,{...t,id:n}]})),n},dismiss:t=>e(e=>({toasts:e.toasts.filter(e=>e.id!==t)}))})),X={success:(e,t=3500)=>jr.getState().push({message:e,variant:`success`,ttl:t}),error:(e,t=6e3)=>jr.getState().push({message:e,variant:`error`,ttl:t}),warn:(e,t=4500)=>jr.getState().push({message:e,variant:`warn`,ttl:t}),info:(e,t=3500)=>jr.getState().push({message:e,variant:`info`,ttl:t}),dismiss:e=>jr.getState().dismiss(e)};function Mr({variant:e}){return e===`success`?(0,G.jsx)(We,{className:`h-4 w-4 text-green-500`}):e===`error`?(0,G.jsx)(M,{className:`h-4 w-4 text-destructive`}):e===`warn`?(0,G.jsx)(dn,{className:`h-4 w-4 text-amber-500`}):(0,G.jsx)(_n,{className:`h-4 w-4 text-blue-500`})}function Nr({entry:e}){let t=jr(e=>e.dismiss);return(0,z.useEffect)(()=>{let n=setTimeout(()=>t(e.id),e.ttl);return()=>clearTimeout(n)},[e.id,e.ttl,t]),(0,G.jsxs)(`div`,{className:Y(`flex items-start gap-2 rounded-lg border bg-popover shadow-lg px-3 py-2 text-sm max-w-sm`,`animate-message`,e.variant===`error`&&`border-destructive/40`,e.variant===`warn`&&`border-amber-500/40`,e.variant===`success`&&`border-green-500/40`),children:[(0,G.jsx)(Mr,{variant:e.variant}),(0,G.jsx)(`div`,{className:`flex-1 min-w-0 whitespace-pre-wrap break-words leading-snug`,children:e.message}),(0,G.jsx)(`button`,{type:`button`,onClick:()=>t(e.id),className:`text-muted-foreground hover:text-foreground`,title:`Dismiss`,children:(0,G.jsx)(F,{className:`h-3.5 w-3.5`})})]})}function Pr(){let e=jr(e=>e.toasts);return e.length===0?null:(0,G.jsx)(`div`,{className:`fixed bottom-4 right-4 z-[60] flex flex-col gap-2 pointer-events-auto`,children:e.map(e=>(0,G.jsx)(Nr,{entry:e},e.id))})}var Fr=null;function Ir(){if(typeof window>`u`)return null;if(Fr)return Fr;let e=window.AudioContext||window.webkitAudioContext;if(!e)return null;try{Fr=new e}catch{return null}return Fr}function Lr(e,t,n){let r=Ir();if(!r)return;let i=r.currentTime+t,a=r.createOscillator(),o=r.createGain();a.type=`sine`,a.frequency.value=e,o.gain.setValueAtTime(0,i),o.gain.linearRampToValueAtTime(.18,i+.01),o.gain.exponentialRampToValueAtTime(1e-4,i+n),a.connect(o).connect(r.destination),a.start(i),a.stop(i+n+.02)}function Rr(){Lr(659.25,0,.18),Lr(880,.12,.24)}function zr(){Lr(523.25,0,.15),Lr(659.25,.1,.15),Lr(783.99,.2,.25)}var Br=`default`;Br=typeof window<`u`&&`Notification`in window?Notification.permission:`unsupported`;async function Vr(){if(Br===`unsupported`||Br===`granted`||Br===`denied`)return Br;try{let e=await Notification.requestPermission();return Br=e,e}catch{return`denied`}}function Hr(e,t,n){if(!(typeof document>`u`||!document.hidden)&&Br===`granted`)try{let r=new Notification(e,{body:t,icon:`/favicon.ico`,tag:n??`wrongstack-run`,requireInteraction:n===`wrongstack-confirm`});r.onclick=()=>{window.focus(),r.close()}}catch{}}function Ur(e){typeof requestAnimationFrame==`function`?requestAnimationFrame(e):queueMicrotask(e)}var Wr=new class{pending=new Map;scheduled=!1;push(e,t,n){if(!t)return;let r=this.pending.get(e);r?(r.buffer+=t,r.flush=n):this.pending.set(e,{buffer:t,flush:n}),this.schedule()}schedule(){this.scheduled||(this.scheduled=!0,Ur(()=>{this.scheduled=!1,this.drain()}))}drain(){if(this.pending.size===0)return;let e=Array.from(this.pending.entries());this.pending.clear();for(let[t,n]of e)n.buffer&&n.flush(t,n.buffer)}drop(e){this.pending.delete(e)}flush(e){let t=this.pending.get(e);t&&(this.pending.delete(e),t.buffer&&t.flush(e,t.buffer))}flushAll(){this.drain()}};function Gr(e){let t=Ar(`session.start`,e.payload);t&&(kr.getState().pushEvent(t),kr.getState().setActive(!0));let n=e.payload,r=U.getState().session?.id,i=!r||r!==n.sessionId||n.reset;if(n.needsSetup&&W.getState().setCurrentView(`setup`),i?U.getState().startSession({id:n.sessionId,startedAt:Date.now(),model:n.model,provider:n.provider}):U.getState().setSession({id:n.sessionId,startedAt:U.getState().session?.startedAt??Date.now(),model:n.model,provider:n.provider}),U.getState().setEnv({maxContext:n.maxContext,projectRoot:n.projectRoot??``,projectName:n.projectName,cwd:n.cwd,mode:n.mode,contextMode:n.contextMode,inputCost:n.inputCost,outputCost:n.outputCost,cacheReadCost:n.cacheReadCost}),H.getState().setConfig({provider:n.provider,model:n.model}),i){V.getState().clearMessages(),V.getState().setLoading(!1),U.setState({todos:[]}),Un(`ready`);let e=K.getState();if(n.clearedSessionId){let t=new Map;for(let[r,i]of e.agents)i.sessionId!==n.clearedSessionId&&t.set(r,i);K.setState({agents:t})}else e.clear();q.getState().setTreeLoading(!0),B().send({type:`files.tree`,payload:{path:U.getState().cwd}})}let a=n.replayMessages;if(a&&a.length>0){let e=V.getState();for(let t of a){let n=typeof t.ts==`string`?Date.parse(t.ts):NaN,r=Number.isFinite(n)?n:void 0;if(t.role===`user`||t.role===`assistant`||t.role===`system`){let n=``;if(typeof t.content==`string`)n=t.content;else if(Array.isArray(t.content)){for(let i of t.content)if(i.type===`text`&&typeof i.text==`string`)n+=(n?`
13
- `:``)+i.text;else if(i.type===`tool_use`)n&&=(e.addMessage({role:t.role,content:n,timestamp:r}),``),e.addMessage({role:`tool`,content:``,toolName:String(i.name??`tool`),toolInput:i.input,toolUseId:String(i.id??``),timestamp:r});else if(i.type===`tool_result`){let t=V.getState().messages,n;for(let e=t.length-1;e>=0;e--)if(t[e]?.toolUseId===String(i.tool_use_id??``)){n=R(t[e]);break}n&&e.setToolResult(n.id,typeof i.content==`string`?i.content:JSON.stringify(i.content),!i.is_error)}}n&&e.addMessage({role:t.role,content:n,timestamp:r})}}}if(a){let e=n.replayUsage;if(e){let t=U.getState(),n=e.input??0,r=e.output??0,i=e.cacheRead??0,a=e.cacheWrite??0;U.setState({totalTokens:{input:n,output:r,cacheRead:i,cacheWrite:a},cost:(n*t.inputCost+r*t.outputCost+i*t.cacheReadCost)/1e6})}W.getState().currentView!==`chat`&&W.getState().setCurrentView(`chat`),typeof window<`u`&&window.matchMedia?.(`(max-width: 768px)`).matches&&W.getState().setSidebarOpen(!1)}}function Kr(e){let t=e.payload,n=e=>e.toLocaleString(),r=[...t.tools.breakdown].sort((e,t)=>t.tokens-e.tokens).slice(0,8),i=[...t.messages.breakdown].sort((e,t)=>t.tokens-e.tokens).slice(0,8);V.getState().addMessage({role:`assistant`,content:[`πŸ“Š **Context breakdown** (heuristic β€” 4 chars/token)`,``,`**Total estimate:** ${n(t.total)} tokens`,`β€’ System prompt: ${n(t.systemPrompt)}`,`β€’ Tool schemas: ${n(t.tools.total)} (${t.tools.count} tools)`,`β€’ Messages: ${n(t.messages.total)} (${t.messages.count} messages)`,``,`**Top tool schemas:**`,...r.map(e=>` Β· ${e.name}: ${n(e.tokens)}`),``,`**Top messages:**`,...i.map(e=>` Β· #${e.index} ${e.role}: ${n(e.tokens)} β€” ${e.preview||`(empty)`}`)].join(`
14
- `)})}function qr(e){let t=e.payload;t.success?X.success(t.message):X.error(t.message),B(H.getState().wsUrl).listSavedProviders()}function Jr(e){xi(e);let t=e.payload,n=t.reductions.length?t.reductions.map(e=>`${e.phase}: ${e.saved}`).join(`, `):`no-op`;t.repaired&&(n+=`; repaired ${t.repaired.removedToolUses?.length??0} tool_use, ${t.repaired.removedToolResults?.length??0} tool_result, ${t.repaired.removedMessages} empty messages`),V.getState().addMessage({role:`assistant`,content:`πŸ—œοΈ Context compacted: ${t.before} β†’ ${t.after} tokens (saved ~${t.saved}). ${n}`}),U.setState({lastInputTokens:t.after})}function Yr(e){let t=e.payload,n=t.usage,r=(n.input??0)+(n.cacheWrite??0)-(n.cacheRead??0);r>0&&U.setState({lastInputTokens:r}),U.getState().updateUsage(t.usage);let{inputCost:i,outputCost:a,cacheReadCost:o}=U.getState(),s=(t.usage.input*i+t.usage.output*a+(t.usage.cacheRead??0)*o)/1e6;s>0&&U.getState().addCost(s),t.stopReason!==`tool_use`&&t.stopReason!==`tool_call`&&V.getState().setLoading(!1);let c=V.getState().currentAssistantMessageId;c&&(Wr.flush(c),V.getState().finalizeMessage(c),t.usage.output>0&&V.getState().updateMessage(c,{usage:t.usage})),V.getState().setCurrentAssistantMessage(null),V.getState().clearThinking()}function Xr(e){let t=e.payload,n=t.removedToolUses.length+t.removedToolResults.length+t.removedMessages,r=t.beforeMessages!==void 0&&t.afterMessages!==void 0?` Messages: ${t.beforeMessages} -> ${t.afterMessages}.`:``;V.getState().addMessage({role:`assistant`,content:`Context repaired: removed ${n} orphan protocol item(s).${r} tool_use ${t.removedToolUses.length}, tool_result ${t.removedToolResults.length}.`})}function Zr(){H.getState().setWsConnected(!1)}function Qr(e){xi(e);let t=e.payload;U.getState().setIteration({index:t.index,max:t.maxIterations??0}),V.getState().setLoading(!0),typeof document<`u`&&document.hidden&&Un(`running`),V.getState().runStart===null&&V.getState().setRunStart({at:Date.now(),cost:U.getState().cost}),V.getState().setCurrentAssistantMessage(null)}function $r(e){let t=e.payload;V.getState().clearThinking(),Wr.drop(`__thinking__`);let n=V.getState().currentAssistantMessageId;n||(n=V.getState().addMessage({role:`assistant`,content:``,streaming:!0}),V.getState().setCurrentAssistantMessage(n)),Wr.push(n,t.text,(e,t)=>V.getState().appendToMessage(e,t))}function ei(e){let t=e.payload;t.text&&Wr.push(`__thinking__`,t.text,(e,t)=>V.getState().appendThinking(t))}function ti(e){let t=e.payload,n=V.getState().messages.find(e=>e.toolUseId===t.id);if(n){V.getState().setCurrentToolId(n.id);return}V.getState().clearThinking(),Wr.drop(`__thinking__`),V.getState().setCurrentAssistantMessage(null);let r=V.getState().addMessage({role:`tool`,content:``,toolName:t.name,toolInput:t.input,toolUseId:t.id});V.getState().setCurrentToolId(r),V.getState().addExecution({id:t.id,name:t.name,input:t.input,ok:!0,startedAt:Date.now()})}function ni(e){let t=e.payload,n=(t.event?.text??``).trim();if(!n)return;let r=V.getState().messages.find(e=>e.toolUseId===t.id);if(!r)return;let i=t.event?.type===`warning`?`⚠ `:``;Wr.push(r.id,`${i}${n}\n`,(e,t)=>V.getState().appendToolProgressLines(e,t.split(`
15
- `).filter(e=>e.length>0)))}function ri(e){let t=e.payload,{messages:n,currentToolId:r}=V.getState(),i=t.id?n.find(e=>e.toolUseId===t.id):r?n.find(e=>e.id===r):void 0;i?.toolResult===void 0&&(i&&(Wr.drop(i.id),V.getState().setToolResult(i.id,t.output??``,t.ok),V.getState().updateMessage(i.id,{toolDurationMs:t.durationMs})),t.id&&V.getState().updateExecution(t.id,{completedAt:Date.now(),durationMs:t.durationMs,output:t.output,ok:t.ok}),r&&i&&i.id===r&&V.getState().setCurrentToolId(null))}function ii(e){let t=e.payload;W.getState().showConfirm({id:t.id,toolName:t.toolName,input:t.input,suggestedPattern:t.suggestedPattern});try{zr()}catch{}Vr(),Hr(`${U.getState().projectName||`Agent`} needs approval`,`Tool "${t.toolName}" is waiting for your decision.`,`agent-confirm`),typeof document<`u`&&document.hidden&&Un(`attention`)}function ai(e){let t=e.payload;Wr.flushAll(),U.getState().setIteration(null),V.getState().setLoading(!1),V.getState().setCurrentAssistantMessage(null),V.getState().clearThinking();let n=V.getState().runStart;if(n&&t.status===`done`){let e=V.getState().messages,r=-1,i=0;for(let t=e.length-1;t>=0;t--){let a=R(e[t]);if(a.role===`assistant`&&r===-1&&a.content&&(r=t),a.role===`tool`&&a.timestamp>=n.at&&(i+=1),a.role===`user`&&a.timestamp<=n.at)break}if(r!==-1){let a=U.getState().cost;V.getState().updateMessage(e[r]?.id,{runSummary:{iterations:t.iterations,tools:i,durationMs:Date.now()-n.at,costDelta:Math.max(0,a-n.cost)}})}}if(V.getState().setRunStart(null),t.status!==`done`&&t.error)V.getState().addMessage({role:`assistant`,content:`Error: ${t.error.message}`,isError:!0}),X.error(`Run ended: ${t.error.message}`),Hr(`${U.getState().projectName||`Agent`} run failed`,t.error.message),typeof document<`u`&&document.hidden&&Un(`error`);else if(t.status===`done`&&(typeof document<`u`&&document.hidden&&(X.success(`Run completed in ${t.iterations} iteration${t.iterations===1?``:`s`}`),Hr(`${U.getState().projectName||`Agent`} run finished`,`Completed in ${t.iterations} iteration${t.iterations===1?``:`s`}.`),Un(`ready`)),Vr(),H.getState().soundOnComplete))try{Rr()}catch{}let r=V.getState().dequeue();if(r){let e=B(H.getState().wsUrl);V.getState().addMessage({role:`user`,content:r}),V.getState().setLoading(!0),e.sendMessage(r)}}function oi(e){let t=e.payload;V.getState().addMessage({role:`assistant`,content:[`πŸ› οΈ **Registered tools** (${t.tools.length})`,``,...t.tools.map(e=>`β€’ \`${e.name}\`${e.params.length?` (${e.params.join(`, `)})`:``} β€” ${e.description||`_no description_`}`)].join(`
16
- `)})}function si(e){let t=e.payload,n=t.text?.trim();V.getState().addMessage({role:`assistant`,content:t.error?`Memory read failed: ${t.error}`:n?`🧠 **Memory** \n\n${n}`:`🧠 **Memory**
17
-
18
- _empty β€” nothing remembered yet_`})}function ci(e){let t=e.payload;if(!t.enabled){V.getState().addMessage({role:`assistant`,content:`🎯 **Skills**
19
-
20
- _disabled (config.features.skills = false)_`});return}let n=[`🎯 **Skills** (${t.skills.length})`,``,...t.skills.length===0?[`_none registered_`]:t.skills.map(e=>`β€’ \`${e.name}\`${e.version?` v${e.version}`:``} _(${e.source})_ β€” ${e.description||e.trigger||`_no description_`}`)];t.error&&n.push(``,`⚠ ${t.error}`),V.getState().addMessage({role:`assistant`,content:n.join(`
21
- `)})}function li(e){let t=e.payload;V.getState().addMessage({role:`assistant`,content:[`🩺 **Runtime diagnostics**`,``,`**Provider:** \`${t.provider}\` / \`${t.model}\``,`**Mode:** \`${t.mode}\``,`**Session:** \`${t.sessionId}\``,`**CWD:** \`${t.cwd}\``,``,`**Tools:** ${t.tools.count}`,`**Messages:** ${t.messages} Β· **Todos:** ${t.todos}`,`**Usage:** ${t.usage.input.toLocaleString()} in Β· ${t.usage.output.toLocaleString()} out${t.usage.cacheRead?` Β· ${t.usage.cacheRead.toLocaleString()} cache`:``}`,``,`**Features:** memory=${t.features.memory?`βœ“`:`βœ—`} Β· skills=${t.features.skills?`βœ“`:`βœ—`} Β· modelsRegistry=${t.features.modelsRegistry?`βœ“`:`βœ—`}`].join(`
22
- `)})}function ui(e){let t=e.payload,n=Math.floor(t.elapsedMs/1e3),r=n<60?`${n}s`:n<3600?`${Math.floor(n/60)}m ${n%60}s`:`${Math.floor(n/3600)}h ${Math.floor(n%3600/60)}m`;V.getState().addMessage({role:`assistant`,content:[`πŸ“ˆ **Session stats**`,``,`**Session:** \`${t.sessionId}\``,`**Provider/Model:** \`${t.provider}\` / \`${t.model}\``,`**Elapsed:** ${r}`,``,`**Usage:** ${t.usage.input.toLocaleString()} in Β· ${t.usage.output.toLocaleString()} out`,...t.cache&&t.cache.readTokens>0?[`**Cache:** ${t.cache.readTokens.toLocaleString()} read Β· ${t.cache.writeTokens.toLocaleString()} write Β· hit ratio ${(t.cache.hitRatio*100).toFixed(1)}%`]:[],`**Cost:** $${t.cost.toFixed(4)}`,``,`**Messages:** ${t.messages} Β· **Files read:** ${t.readFiles} Β· **Tools available:** ${t.tools}`].join(`
23
- `)})}function di(e){let t=e.payload;U.getState().setTodos(t.todos??[])}function fi(e){let t=e.payload;U.getState().setModes(t.modes.map(e=>({id:e.id,name:e.name,description:e.description}))),U.getState().setEnv({mode:t.activeId})}function pi(e){let t=e.payload;U.getState().setContextModes(t.modes.map(e=>({id:e.id,name:e.name,description:e.description,thresholds:e.thresholds,preserveK:e.preserveK,eliseThreshold:e.eliseThreshold,custom:e.custom}))),U.getState().setEnv({contextMode:t.activeId})}function mi(e){let t=e.payload;U.getState().setEnv({contextMode:t.id})}function hi(e){let t=e.payload;ir.getState().setEntries(t.sessions??[],t.error??null)}function gi(e){let t=e.payload;V.getState().addMessage({role:`assistant`,content:`[${t.phase}] ${t.message}`,isError:!0}),V.getState().setLoading(!1)}function _i(e){let t=e.payload;ar.getState().setSnapshot(t.worktrees??[],t.baseBranch??``)}function vi(e){let t=e.payload;ar.getState().pushEvent(t)}function yi(e){K.getState().applyEvent(e.payload);let t=Ar(`subagent.event`,e.payload);t&&(kr.getState().pushEvent(t),kr.getState().setActive(!0))}function bi(e){let t=e.payload;K.setState({fleetConcurrency:t.fleetConcurrency,fleetConcurrencyMax:t.fleetConcurrencyMax})}function xi(e){let t=Ar(e.type,e.payload);return t&&(kr.getState().pushEvent(t),kr.getState().setActive(!0)),e}function Si(e){let t=e.payload;Cr.getState().setState({phases:Array.isArray(t.phases)?t.phases:void 0,activePhaseId:typeof t.activePhaseId==`string`?t.activePhaseId:void 0,overallPercent:typeof t.overallPercent==`number`?t.overallPercent:void 0,autonomous:typeof t.autonomous==`boolean`?t.autonomous:void 0,title:typeof t.title==`string`?t.title:void 0})}function Ci(e){let t=e.payload;Sr.getState().setGoal(t)}function wi(e){let t=e.payload;Tr.getState().set(t)}function Ti(e){let t=e.payload;if(t.error){q.getState().setError(t.error);return}q.getState().setTree(t.root,t.tree)}function Ei(e){let t=e.payload;if(t.error){q.getState().setError(t.error);return}q.getState().openFile(t.filePath,t.content)}function Di(e){let t=e.payload;t.success?q.getState().markSaved(t.filePath):t.error&&q.getState().setError(`Save failed: ${t.error}`)}function Oi(){let e=B(H.getState().wsUrl);e?.send?.({type:`mailbox.messages`,payload:{limit:30}}),e?.send?.({type:`mailbox.agents`,payload:{}})}var ki={"session.start":e=>{Gr(e),Oi()},"context.debug":Kr,"key.operation_result":qr,"context.compacted":Jr,"provider.response":Yr,"context.repaired":Xr,"session.end":Zr,"iteration.started":Qr,"provider.text_delta":$r,"provider.thinking_delta":ei,"tool.started":ti,"tool.progress":ni,"tool.executed":ri,"tool.confirm_needed":ii,"run.result":ai,"tools.list":oi,"memory.list":si,"skills.list":ci,"diag.get":li,"stats.get":ui,"todos.updated":di,"tasks.updated":e=>{},"plan.updated":e=>{},"modes.list":fi,"context.modes.list":pi,"context.mode.changed":mi,"sessions.list":hi,error:gi,"worktree.state":_i,"worktree.event":vi,"subagent.event":yi,"fleet.concurrency_update":bi,"goal.updated":Ci,"prefs.updated":wi,"sessions.status_update":e=>{let t=Ar(`sessions.status_update`,e.payload);t&&(kr.getState().pushEvent(t),kr.getState().setActive(!0))},"files.tree":Ti,"files.read":Ei,"files.written":Di,"autophase.state":Si,"session.checkpoints":e=>{},"process.list":e=>{},"projects.list":e=>{},"projects.added":e=>{},"projects.selected":e=>{},"mailbox.event":e=>{let t=Ar(`mailbox.event`,e.payload);t&&(kr.getState().pushEvent(t),kr.getState().setActive(!0)),Oi()},"mailbox.messages":e=>{let t=e.payload;t?.messages&&nr.getState().setMessages(t.messages)},"mailbox.agents":e=>{let t=e.payload;t?.agents&&nr.getState().setAgents(t.agents)},"mailbox.cleared":e=>{nr.getState().setMessages([]),Oi()},"brain.status":e=>{let t=e.payload,n=[`🧠 **Brain** β€” policy β†’ LLM decision chain`,``,`Autonomy ceiling: \`${t.maxAutoRisk}\` _(change with \`/brain risk <off|low|medium|high|all>\`)_`];if(t.log.length===0)n.push(``,`_No decisions recorded yet this session._`);else{n.push(``,`Recent decisions (${t.log.length}):`);for(let e of t.log.slice(-10)){let t=Math.max(0,Math.round((Date.now()-e.at)/1e3)),r=t<60?`${t}s`:t<3600?`${Math.round(t/60)}m`:`${Math.round(t/3600)}h`,i=e.question.length>70?`${e.question.slice(0,67)}…`:e.question;n.push(`- \`${r} ago\` **${e.kind}** β€” ${i}${e.outcome?` β†’ _${e.outcome}_`:``}`)}}V.getState().addMessage({role:`assistant`,content:n.join(`
24
- `)})},"brain.answer":e=>{let t=e.payload,n;if(t.decision.type===`answer`){let e=t.decision.rationale&&t.decision.rationale!==t.decision.text?`\n\n_${t.decision.rationale}_`:``;n=`🧠 ${t.decision.text??``}${e}`}else n=t.decision.type===`deny`?`🧠 Denied: ${t.decision.reason??``}`:`🧠 The Brain escalated this question back to you β€” it needs human judgement.`;V.getState().addMessage({role:`assistant`,content:n})},"brain.event":e=>{let t=e.payload;if(t.event===`brain.intervention`){let e=t.decision?.rationale??t.decision?.text??``,n=t.intervened?`🧠 **Brain intervention** β€” corrective guidance was sent to the agent.`:`🧠 **Brain check** β€” a distress signal was reviewed; no action needed.`;V.getState().addMessage({role:`assistant`,content:[n,t.request?.question??``,e?`_${e}_`:``].filter(Boolean).join(`
25
-
26
- `)}),t.intervened&&X.info(`Brain intervened: agent steered`)}else t.event===`brain.decision_denied`&&X.warn(`Brain denied: ${t.decision?.reason??t.request?.question??`request`}`)},"working_dir.changed":e=>{let t=e.payload;U.getState().setEnv({cwd:t.cwd,projectRoot:t.projectRoot,projectName:t.projectRoot.split(/[/\\]/).pop()||t.projectRoot}),q.getState().setTreeLoading(!0),B().send({type:`files.tree`,payload:{path:t.cwd}})},"model.refine_result":e=>{let t=e.payload,n=W.getState().refinePanel;if(!n)return;if(t.error){X.error(`Refinement failed: ${t.error}`);let{original:e}=n;W.getState().setRefinePanel(null),V.getState().addMessage({role:`user`,content:e}),V.getState().setLoading(!0),B().send({type:`user_message`,payload:{id:`msg_${Date.now()}`,content:e,timestamp:Date.now()}});return}let r=n.original;if(In(t.refined,r)){W.getState().setRefinePanel(null),V.getState().addMessage({role:`user`,content:r}),V.getState().setLoading(!0),B().send({type:`user_message`,payload:{id:`msg_${Date.now()}`,content:r,timestamp:Date.now()}});return}W.getState().setRefinePanel({...n,refined:t.refined,english:t.english})}};function Ai(e){let t=[];for(let[n,r]of Object.entries(ki))t.push(e.on(n,r));return()=>{for(let e of t)e()}}function ji(){let{autoConnect:e,wsUrl:t}=H(),n=H(e=>e.setWsStatus),r=(0,z.useRef)(!1);(0,z.useEffect)(()=>{if(!e)return;Gn();let i=B(t),a=!1,o=i.onStatus(e=>{a||n(e)});if(i.connect().then(()=>{a||i.getPrefs()}).catch(e=>{a||console.warn(JSON.stringify({level:`warn`,event:`webui.ws_connection_failed`,message:e instanceof Error?e.message:String(e),timestamp:new Date().toISOString()}))}),r.current)return()=>{a=!0,o()};r.current=!0;let s=Ai(i);return()=>{a=!0,s(),o()}},[e,t,n])}function Z(){let{wsUrl:e}=H(),t=B(e),n=(0,z.useCallback)(e=>t.isConnected?t.sendMessage(e):null,[t]),r=(0,z.useCallback)(()=>t.sendAbort(),[t]),{hideConfirm:i}=W(),a=(0,z.useCallback)((e,n)=>{t.sendConfirm(e,n),i()},[t,i]),o=(0,z.useCallback)((e,n)=>t.switchModel(e,n),[t]),s=(0,z.useCallback)(()=>t.listProviders(),[t]),c=(0,z.useCallback)(e=>t.listProviderModels(e),[t]),l=(0,z.useCallback)(()=>t.listSavedProviders(),[t]),u=(0,z.useCallback)((e,n,r)=>t.addKey(e,n,r),[t]),d=(0,z.useCallback)((e,n,r)=>t.updateKey(e,n,r),[t]),f=(0,z.useCallback)((e,n)=>t.deleteKey(e,n),[t]),p=(0,z.useCallback)((e,n)=>t.setActiveKey(e,n),[t]),m=(0,z.useCallback)((e,n,r,i)=>t.addProvider(e,n,r,i),[t]),h=(0,z.useCallback)(e=>t.removeProvider(e),[t]),g=(0,z.useCallback)(e=>{ir.getState().setLoading(!0),t.listSessions(e)},[t]),_=(0,z.useCallback)(e=>{ir.getState().removeEntry(e),t.deleteSession(e)},[t]),v=(0,z.useCallback)(e=>t.resumeSessionById(e),[t]),y=(0,z.useCallback)(()=>t.saveSession(),[t]),b=(0,z.useCallback)(()=>t.listTools(),[t]),x=(0,z.useCallback)(()=>t.listMemory(),[t]),S=(0,z.useCallback)(()=>t.listSkills(),[t]),C=(0,z.useCallback)(()=>t.getDiag(),[t]),w=(0,z.useCallback)(()=>t.getStats(),[t]),T=(0,z.useCallback)(()=>t.getPlan(),[t]),E=(0,z.useCallback)(()=>t.listModes(),[t]),D=(0,z.useCallback)(e=>t.switchMode(e),[t]),O=(0,z.useCallback)(()=>t.listContextModes(),[t]),k=(0,z.useCallback)(e=>t.switchContextMode(e),[t]),A=(0,z.useCallback)(e=>t.createContextMode(e),[t]),j=(0,z.useCallback)((e,n)=>t.updateContextMode(e,n),[t]),M=(0,z.useCallback)(e=>t.deleteContextMode(e),[t]),ee=(0,z.useCallback)(()=>t.repairContext(),[t]),te=(0,z.useCallback)(e=>t.refineModel(e),[t]),N=(0,z.useCallback)(e=>t.switchAutonomy(e),[t]),ne=(0,z.useCallback)(e=>t.updatePrefs(e),[t]);return{client:t,sendMessage:n,sendAbort:r,sendConfirm:a,switchModel:o,listProviders:s,listProviderModels:c,listSavedProviders:l,addKey:u,updateKey:d,deleteKey:f,setActiveKey:p,addProvider:m,removeProvider:h,listSessions:g,deleteSession:_,resumeSession:v,saveSession:y,listTools:b,listMemory:x,listSkills:S,getDiag:C,getStats:w,getPlan:T,listModes:E,switchMode:D,listContextModes:O,switchContextMode:k,createContextMode:A,updateContextMode:j,deleteContextMode:M,repairContext:ee,toggleAutoPhaseAutonomous:(0,z.useCallback)(e=>{t.send({type:`autophase.toggleAutonomous`,payload:{autonomous:e}})},[t]),startAutoPhase:(0,z.useCallback)((e,n,r=!0)=>{t.send({type:`autophase.start`,payload:{title:e,phases:n,autonomous:r}})},[t]),pauseAutoPhase:(0,z.useCallback)(()=>{t.send({type:`autophase.pause`,payload:{}})},[t]),resumeAutoPhase:(0,z.useCallback)(()=>{t.send({type:`autophase.resume`,payload:{}})},[t]),stopAutoPhase:(0,z.useCallback)(()=>{t.send({type:`autophase.stop`,payload:{}})},[t]),selectAutoPhase:(0,z.useCallback)(e=>{t.send({type:`autophase.selectPhase`,payload:{phaseId:e}})},[t]),switchAutonomy:N,updatePrefs:ne,refineModel:te}}var Mi=(0,z.createContext)(void 0);function Ni({children:e,defaultTheme:t=`system`,storageKey:n=`wrongstack-theme`}){let{setTheme:r}=H(),[i,a]=(0,z.useState)(()=>typeof window<`u`&&localStorage.getItem(n)||t);(0,z.useEffect)(()=>{let e=window.document.documentElement;if(e.classList.remove(`light`,`dark`),i===`system`){let t=window.matchMedia(`(prefers-color-scheme: dark)`).matches?`dark`:`light`;e.classList.add(t)}else e.classList.add(i)},[i]);let o={theme:i,setTheme:e=>{localStorage.setItem(n,e),a(e),r(e)}};return(0,G.jsx)(Mi.Provider,{value:o,children:e})}function Pi(){let e=(0,z.useContext)(Mi);if(e===void 0)throw Error(`useTheme must be used within a ThemeProvider`);return e}var Fi=[{id:`chat`,icon:(0,G.jsx)(He,{size:16}),label:`Session`,shortcut:`Ctrl+1`,pairedView:`chat`},{id:`agents`,icon:(0,G.jsx)(L,{size:16}),label:`Agents`,shortcut:`Ctrl+2`},{id:`history`,icon:(0,G.jsx)(N,{size:16}),label:`History`,shortcut:`Ctrl+3`},{id:`files`,icon:(0,G.jsx)(jn,{size:16}),label:`Files`,shortcut:`Ctrl+4`,pairedView:`files`},{id:`projects`,icon:(0,G.jsx)(yt,{size:16}),label:`Projects`,shortcut:`Ctrl+5`},{id:`mailbox`,icon:(0,G.jsx)(ve,{size:16}),label:`Mailbox`,shortcut:`Ctrl+6`}],Ii=[{id:`autophase`,icon:(0,G.jsx)(Ft,{size:16}),label:`Phases`},{id:`agentflow`,icon:(0,G.jsx)(Vt,{size:16}),label:`Flow`},{id:`settings`,icon:(0,G.jsx)(En,{size:16}),label:`Settings`}];function Li(e){let t=W.getState();if(!t.sidebarOpen)t.setSidebarOpen(!0),t.selectActivity(e);else if(t.activeActivity===e){t.setSidebarOpen(!1);return}else t.selectActivity(e);let n=Fi.find(t=>t.id===e)?.pairedView;n&&t.currentView!==n&&t.setCurrentView(n)}var Ri=Fi.map(e=>e.id);function zi(){let e=W(e=>e.activeActivity),t=W(e=>e.sidebarOpen),n=W(e=>e.currentView),r=W(e=>e.setCurrentView),i=U(e=>e.projectName),a=U(e=>e.cwd),o=H(e=>e.wsConnected),s=K(e=>Array.from(e.agents.values()).filter(e=>e.status===`running`).length),c=nr(rr),l=e=>{if(e===`agents`)return s||void 0;if(e===`mailbox`)return c||void 0};return(0,G.jsxs)(`div`,{className:`flex flex-col h-full w-12 shrink-0 border-r bg-card/60`,children:[(0,G.jsxs)(`div`,{className:`flex flex-col items-center pt-2.5 pb-2 border-b border-border/50`,children:[(0,G.jsx)(`button`,{type:`button`,onClick:()=>{W.getState().setSidebarOpen(!0),W.getState().selectActivity(`chat`),r(`chat`)},title:i?`${i} β€” return to chat`:`WrongStack β€” return to chat`,className:`relative w-8 h-8 rounded-md bg-primary flex items-center justify-center shadow-[0_0_0_1px_hsl(var(--primary)/0.4),0_2px_8px_-2px_hsl(var(--primary)/0.5)] hover:shadow-[0_0_0_1px_hsl(var(--primary)/0.6),0_3px_12px_-2px_hsl(var(--primary)/0.6)] transition-shadow`,children:(0,G.jsx)(Ue,{className:`h-4 w-4 text-primary-foreground`,strokeWidth:2.4})}),(0,G.jsx)(`span`,{className:`mt-1.5 text-[8px] font-semibold tracking-tight text-muted-foreground text-center leading-tight w-10 truncate`,title:a||i||`WrongStack`,children:i||`WS`}),(0,G.jsx)(`span`,{className:Y(`mt-1 inline-block w-1.5 h-1.5 rounded-full`,o?`bg-[hsl(var(--success))] shadow-[0_0_4px_hsl(var(--success)/0.6)]`:`bg-[hsl(var(--warning))]`),title:o?`Connected`:`Disconnected`})]}),(0,G.jsx)(`div`,{className:`flex flex-col items-center gap-0.5 pt-2`,children:Fi.map(n=>(0,G.jsx)(Vi,{icon:n.icon,label:`${n.label} (${n.shortcut})`,active:t&&e===n.id,badge:l(n.id),onClick:()=>Li(n.id)},n.id))}),(0,G.jsx)(`div`,{className:`flex-1`}),(0,G.jsxs)(`div`,{className:`flex flex-col items-center gap-0.5 pb-2 border-b border-border/50 mb-2`,children:[(0,G.jsx)(Vi,{icon:(0,G.jsx)(C,{size:16}),label:`Command palette (Ctrl+K)`,active:!1,onClick:()=>W.getState().setPaletteOpen(!0)}),(0,G.jsx)(Bi,{}),(0,G.jsx)(Vi,{icon:(0,G.jsx)(un,{size:16}),label:`Keyboard shortcuts (?)`,active:!1,onClick:()=>W.getState().setShortcutsOpen(!0)}),(0,G.jsx)(Vi,{icon:(0,G.jsx)(Ze,{size:16}),label:`Fleet Monitor (Ctrl+Shift+M)`,active:W.getState().inspectorOpen&&W.getState().inspectorTab===`fleet`,onClick:()=>{let e=W.getState();e.inspectorOpen&&e.inspectorTab===`fleet`?e.setInspectorOpen(!1):(e.setInspectorTab(`fleet`),e.setInspectorOpen(!0))}}),(0,G.jsx)(Vi,{icon:(0,G.jsx)(Ht,{size:16}),label:`Agents Monitor (Ctrl+Shift+A)`,active:W.getState().inspectorOpen&&W.getState().inspectorTab===`agents`,onClick:()=>{let e=W.getState();e.inspectorOpen&&e.inspectorTab===`agents`?e.setInspectorOpen(!1):(e.setInspectorTab(`agents`),e.setInspectorOpen(!0))}})]}),(0,G.jsx)(`div`,{className:`flex flex-col items-center gap-0.5 pb-2`,children:Ii.map(e=>(0,G.jsx)(Vi,{icon:e.icon,label:e.label,active:n===e.id,onClick:()=>r(n===e.id?`chat`:e.id)},e.id))})]})}function Bi(){let{theme:e,setTheme:t}=Pi(),n=e===`light`?`dark`:e===`dark`?`system`:`light`;return(0,G.jsx)(Vi,{icon:e===`light`?(0,G.jsx)(Ut,{size:16}):e===`dark`?(0,G.jsx)(w,{size:16}):(0,G.jsx)(ne,{size:16}),label:`Theme: ${e} β€” click for ${n}`,active:!1,onClick:()=>t(n)})}function Vi({icon:e,label:t,active:n,badge:r,onClick:i}){return(0,G.jsxs)(`button`,{type:`button`,onClick:i,title:t,className:Y(`relative flex items-center justify-center w-10 h-10 rounded-lg transition-colors`,`text-muted-foreground hover:text-foreground hover:bg-muted/70`,n&&`text-primary bg-primary/10`),children:[n&&(0,G.jsx)(`span`,{className:`absolute left-0 top-1/2 -translate-y-1/2 w-0.5 h-6 rounded-r-full bg-primary`}),(0,G.jsx)(`span`,{className:`h-5 w-5`,children:e}),r!==void 0&&r>0&&(0,G.jsx)(`span`,{className:`absolute -top-0.5 -right-0.5 min-w-[15px] h-[15px] flex items-center justify-center rounded-full bg-primary text-[8px] font-bold text-primary-foreground leading-none px-1 tabular`,children:r>99?`99+`:r})]})}var Hi={pending:{icon:(0,G.jsx)(nn,{className:`w-4 h-4`}),color:`text-slate-400`,bg:`bg-slate-100 dark:bg-slate-800`,label:`Pending`},ready:{icon:(0,G.jsx)(ge,{className:`w-4 h-4`}),color:`text-blue-500`,bg:`bg-blue-50 dark:bg-blue-950`,label:`Ready`},running:{icon:(0,G.jsx)(N,{className:`w-4 h-4 animate-spin`,"aria-label":`Running`}),color:`text-amber-500`,bg:`bg-amber-50 dark:bg-amber-950`,label:`Running`},paused:{icon:(0,G.jsx)(Fn,{className:`w-4 h-4`}),color:`text-orange-500`,bg:`bg-orange-50 dark:bg-orange-950`,label:`Paused`},completed:{icon:(0,G.jsx)(We,{className:`w-4 h-4`}),color:`text-emerald-500`,bg:`bg-emerald-50 dark:bg-emerald-950`,label:`Completed`},failed:{icon:(0,G.jsx)(M,{className:`w-4 h-4`}),color:`text-red-500`,bg:`bg-red-50 dark:bg-red-950`,label:`Failed`},skipped:{icon:(0,G.jsx)(nt,{className:`w-4 h-4`}),color:`text-slate-400`,bg:`bg-slate-100 dark:bg-slate-800`,label:`Skipped`}},Ui={critical:`bg-red-500`,high:`bg-orange-500`,medium:`bg-blue-500`,low:`bg-slate-400`};function Wi(e){if(!e)return``;let t=Math.floor(e/6e4);if(t<60)return`${t}m`;let n=Math.floor(t/60),r=t%60;return r>0?`${n}h ${r}m`:`${n}h`}function Gi({phases:e,activePhaseId:t,onPhaseClick:n,overallPercent:r,autonomous:i,onToggleAutonomous:a,className:o}){return(0,G.jsxs)(`div`,{className:Y(`flex flex-col h-full border-r border-border bg-card`,o),children:[(0,G.jsxs)(`div`,{className:`p-4 border-b border-border`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between mb-3`,children:[(0,G.jsx)(`h2`,{className:`text-sm font-semibold text-foreground`,children:`Phases`}),(0,G.jsx)(`button`,{type:`button`,onClick:a,className:Y(`px-2 py-1 text-xs rounded-full transition-colors`,i?`bg-emerald-100 text-emerald-700 dark:bg-emerald-900 dark:text-emerald-300`:`bg-slate-100 text-slate-600 dark:bg-slate-800 dark:text-slate-400`),title:i?`Autonomous mode active β€” click to pause`:`Manual mode β€” click to enable autonomous`,children:i?`● Autonomous`:`β—‹ Manual`})]}),(0,G.jsxs)(`div`,{className:`space-y-1`,children:[(0,G.jsxs)(`div`,{className:`flex justify-between text-xs text-muted-foreground`,children:[(0,G.jsx)(`span`,{children:`Overall Progress`}),(0,G.jsxs)(`span`,{children:[r,`%`]})]}),(0,G.jsx)(`div`,{className:`h-2 bg-muted rounded-full overflow-hidden`,children:(0,G.jsx)(`div`,{className:`h-full bg-emerald-500 transition-all duration-500 rounded-full`,style:{width:`${r}%`}})})]})]}),(0,G.jsx)(`div`,{className:`flex-1 overflow-y-auto p-3 space-y-2`,children:e.map(e=>{let r=Hi[e.status];return(0,G.jsxs)(`button`,{type:`button`,onClick:()=>n?.(e.id),className:Y(`w-full text-left rounded-lg border p-3 transition-all hover:shadow-sm`,e.id===t?`border-amber-300 bg-amber-50/50 dark:bg-amber-950/30 ring-1 ring-amber-200`:`border-border bg-card hover:bg-accent/50`),children:[(0,G.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,G.jsx)(`span`,{className:Y(`mt-0.5`,r.color),children:r.icon}),(0,G.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,G.jsx)(`div`,{className:Y(`w-1.5 h-1.5 rounded-full`,Ui[e.priority])}),(0,G.jsx)(`span`,{className:`text-sm font-medium truncate`,children:e.name})]}),(0,G.jsx)(`p`,{className:`text-xs text-muted-foreground truncate mt-0.5`,children:e.description})]})]}),(0,G.jsxs)(`div`,{className:`mt-2 space-y-1`,children:[(0,G.jsxs)(`div`,{className:`flex justify-between text-xs`,children:[(0,G.jsxs)(`span`,{className:`text-muted-foreground`,children:[e.completedTasks,`/`,e.taskCount,` tasks`]}),(0,G.jsxs)(`span`,{className:`text-muted-foreground`,children:[e.progressPercent,`%`]})]}),(0,G.jsx)(`div`,{className:`h-1.5 bg-muted rounded-full overflow-hidden`,children:(0,G.jsx)(`div`,{className:Y(`h-full transition-all duration-500 rounded-full`,e.status===`completed`?`bg-emerald-500`:e.status===`failed`?`bg-red-500`:`bg-amber-500`),style:{width:`${e.progressPercent}%`}})})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2 mt-2 text-xs text-muted-foreground`,children:[(0,G.jsxs)(`span`,{children:[`~`,e.estimateHours,`h`]}),e.actualDurationMs&&(0,G.jsxs)(`span`,{children:[`Β· `,Wi(e.actualDurationMs)]}),e.assignedAgents.length>0&&(0,G.jsxs)(`span`,{children:[`Β· `,e.assignedAgents.length,` agent`,e.assignedAgents.length===1?``:`s`]})]})]},e.id)})})]})}var Ki={pending:{icon:(0,G.jsx)(nn,{className:`w-4 h-4`}),color:`text-muted-foreground`,label:`Pending`},in_progress:{icon:(0,G.jsx)(N,{className:`w-4 h-4 animate-spin`,"aria-label":`In Progress`}),color:`text-primary`,label:`In Progress`},blocked:{icon:(0,G.jsx)(Fn,{className:`w-4 h-4`}),color:`text-[hsl(var(--warning))]`,label:`Blocked`},failed:{icon:(0,G.jsx)(M,{className:`w-4 h-4`}),color:`text-destructive`,label:`Failed`},review:{icon:(0,G.jsx)(pe,{className:`w-4 h-4`}),color:`text-[hsl(var(--info))]`,label:`Review`},completed:{icon:(0,G.jsx)(We,{className:`w-4 h-4`}),color:`text-[hsl(var(--success))]`,label:`Done`}},qi={critical:`bg-destructive/15 text-destructive`,high:`bg-orange-500/15 text-orange-600 dark:text-orange-400`,medium:`bg-[hsl(var(--info)/0.15)] text-[hsl(var(--info))]`,low:`bg-muted text-muted-foreground`},Ji={feature:`bg-[hsl(var(--success)/0.15)] text-[hsl(var(--success))]`,bugfix:`bg-destructive/15 text-destructive`,refactor:`bg-violet-500/15 text-violet-600 dark:text-violet-400`,docs:`bg-sky-500/15 text-sky-600 dark:text-sky-400`,test:`bg-primary/15 text-primary`,chore:`bg-muted text-muted-foreground`};function Yi(e){if(!e)return``;let t=Math.floor(e/6e4);if(t<60)return`${t}m`;let n=Math.floor(t/60),r=t%60;return r>0?`${n}h ${r}m`:`${n}h`}function Xi({phaseName:e,phaseStatus:t,tasks:n,onTaskStatusChange:r,className:i}){let a={in_progress:n.filter(e=>e.status===`in_progress`),pending:n.filter(e=>e.status===`pending`||e.status===`blocked`),completed:n.filter(e=>e.status===`completed`),failed:n.filter(e=>e.status===`failed`),review:n.filter(e=>e.status===`review`)};return(0,G.jsxs)(`div`,{className:Y(`flex flex-col h-full bg-background`,i),children:[(0,G.jsx)(`div`,{className:`p-4 border-b border-border`,children:(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-foreground`,children:e}),(0,G.jsxs)(`p`,{className:`text-sm text-muted-foreground mt-0.5`,children:[n.length,` tasks Β· `,n.filter(e=>e.status===`completed`).length,` completed`]})]}),(0,G.jsx)(`div`,{className:Y(`px-3 py-1 rounded-full text-xs font-medium`,t===`running`?`bg-primary/15 text-primary`:t===`completed`?`bg-[hsl(var(--success)/0.15)] text-[hsl(var(--success))]`:t===`failed`?`bg-destructive/15 text-destructive`:`bg-muted text-muted-foreground`),children:t===`running`?`Running`:t===`completed`?`Completed`:t===`failed`?`Failed`:t===`paused`?`Paused`:t===`ready`?`Ready`:`Pending`})]})}),(0,G.jsx)(`div`,{className:`flex-1 overflow-y-auto p-4 space-y-6`,children:[`in_progress`,`pending`,`review`,`failed`,`completed`].map(e=>{let t=a[e];if(t.length===0)return null;let n={in_progress:`In Progress`,pending:`Pending`,review:`Review`,failed:`Failed`,completed:`Completed`}[e];return(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`h3`,{className:`text-xs font-semibold text-muted-foreground uppercase tracking-wider mb-2`,children:[n,` (`,t.length,`)`]}),(0,G.jsx)(`div`,{className:`space-y-2`,children:t.map(e=>{let t=Ki[e.status];return(0,G.jsxs)(`button`,{type:`button`,className:Y(`w-full text-left rounded-lg border p-3 transition-all hover:shadow-sm hover:border-primary/40 cursor-pointer`,e.status===`in_progress`?`border-primary/40 bg-primary/5`:e.status===`completed`?`border-[hsl(var(--success)/0.35)] bg-[hsl(var(--success)/0.06)]`:e.status===`failed`?`border-destructive/40 bg-destructive/5`:`border-border bg-card`),children:[(0,G.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,G.jsx)(`span`,{className:Y(`mt-0.5`,t.color),children:t.icon}),(0,G.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[(0,G.jsx)(`span`,{className:`text-sm font-medium`,children:e.title}),(0,G.jsx)(`span`,{className:Y(`px-1.5 py-0.5 rounded text-[10px] font-medium`,qi[e.priority]),children:e.priority}),(0,G.jsx)(`span`,{className:Y(`px-1.5 py-0.5 rounded text-[10px] font-medium`,Ji[e.type]),children:e.type})]}),(0,G.jsx)(`p`,{className:`text-xs text-muted-foreground mt-1 line-clamp-2`,children:e.description})]})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-3 mt-2 text-xs text-muted-foreground`,children:[e.estimateHours&&(0,G.jsxs)(`span`,{children:[`~`,e.estimateHours,`h`]}),e.actualHours&&(0,G.jsxs)(`span`,{children:[`β€’ `,e.actualHours,`h`]}),e.assignee&&(0,G.jsxs)(`span`,{children:[`β€’ `,e.assignee]}),e.startedAt&&(0,G.jsxs)(`span`,{children:[`β€’ `,Yi(Date.now()-e.startedAt)]})]}),e.tags.length>0&&(0,G.jsx)(`div`,{className:`flex flex-wrap gap-1 mt-2`,children:e.tags.map(e=>(0,G.jsx)(`span`,{className:`px-1.5 py-0.5 rounded text-[10px] bg-muted text-muted-foreground`,children:e},e))}),r&&e.status!==`completed`&&(0,G.jsxs)(`div`,{className:`flex gap-1 mt-2`,children:[e.status!==`in_progress`&&(0,G.jsx)(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),r(e.id,`in_progress`)},className:`px-2 py-0.5 text-[10px] rounded bg-primary/15 text-primary hover:bg-primary/25 transition-colors`,children:`Start`}),e.status===`in_progress`&&(0,G.jsx)(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),r(e.id,`completed`)},className:`px-2 py-0.5 text-[10px] rounded bg-[hsl(var(--success)/0.15)] text-[hsl(var(--success))] hover:bg-[hsl(var(--success)/0.25)] transition-colors`,children:`Complete`}),e.status!==`failed`&&(0,G.jsx)(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),r(e.id,`failed`)},className:`px-2 py-0.5 text-[10px] rounded bg-destructive/15 text-destructive hover:bg-destructive/25 transition-colors`,children:`Fail`})]})]},e.id)})})]},e)})})]})}var Zi=[`#3b82f6`,`#06b6d4`,`#22c55e`,`#eab308`,`#f97316`,`#a855f7`,`#ec4899`],Qi=e=>e.replace(/^wstack\/ap\//,``);function $i(e){return[...e].sort((e,t)=>e.allocatedAt-t.allocatedAt).map((e,t)=>({handle:e,color:Zi[t%Zi.length],y:60+t*48}))}var ea={allocating:{dash:`4 4`,opacity:.4},active:{dash:`4 4`,opacity:.6},committing:{dash:`4 4`,opacity:.8},merging:{dash:`0`,opacity:.9},merged:{dash:`0`,opacity:1},"needs-review":{dash:`2 3`,opacity:.9},failed:{dash:`2 3`,opacity:.6}};function ta({worktrees:e,baseBranch:t}){let n=$i(e),r=Math.max(120,60+n.length*48+20);return(0,G.jsx)(`div`,{className:`overflow-x-auto rounded-lg border border-[--color-border-dark] bg-[--color-card-dark]/40 p-3`,children:(0,G.jsxs)(`svg`,{width:`100%`,height:r,viewBox:`0 0 600 ${r}`,className:`min-w-[420px]`,role:`img`,"aria-label":`Worktree branch graph off ${t||`HEAD`}`,children:[(0,G.jsx)(`title`,{children:`Worktree branch graph off ${t||`HEAD`}`}),(0,G.jsx)(`line`,{x1:40,y1:20,x2:40,y2:r-10,stroke:`#F93951`,strokeWidth:3}),(0,G.jsx)(`text`,{x:36,y:14,fontSize:11,fill:`#9ca3af`,children:t||`HEAD`}),(0,G.jsx)(`circle`,{cx:40,cy:20,r:5,fill:`#F93951`}),n.map(e=>{let n=ea[e.handle.status]??R(ea.active),r=e.handle.status===`merged`,i=e.handle.status===`needs-review`||e.handle.status===`failed`;return(0,G.jsxs)(`g`,{className:`transition-all duration-500`,children:[(0,G.jsx)(`path`,{d:`M 40 ${e.y-24} C 100 ${e.y-24}, 160 ${e.y}, 220 ${e.y}`,fill:`none`,stroke:e.color,strokeWidth:2,strokeDasharray:n.dash,opacity:n.opacity}),r?(0,G.jsx)(`path`,{d:`M 220 ${e.y} C 160 ${e.y+20}, 100 ${e.y+24}, 40 ${e.y+24}`,fill:`none`,stroke:`#34d399`,strokeWidth:2,opacity:.9}):null,(0,G.jsx)(`circle`,{cx:220,cy:e.y,r:5,fill:i?`#e879f9`:e.color}),(0,G.jsx)(`text`,{x:232,y:e.y-6,fontSize:12,fill:`#e5e7eb`,fontFamily:`monospace`,children:Qi(e.handle.branch)}),(0,G.jsx)(`text`,{x:232,y:e.y+10,fontSize:10,fill:`#9ca3af`,children:i?`⚠ ${e.handle.status}`:r?`βœ“ merged β†’ ${t}`:`+${e.handle.insertions}/-${e.handle.deletions} Β· ${e.handle.ownerLabel}`})]},e.handle.handleId)})]})})}var na={allocating:{icon:`β—‹`,label:`allocating`,tint:`border-zinc-400/40`,dot:`bg-zinc-400`},active:{icon:`●`,label:`active`,tint:`border-amber-400/40`,dot:`bg-amber-400 animate-pulse`},committing:{icon:`◐`,label:`committing`,tint:`border-cyan-400/40`,dot:`bg-cyan-400 animate-pulse`},merging:{icon:`⇑`,label:`merging`,tint:`border-blue-400/40`,dot:`bg-blue-400 animate-pulse`},merged:{icon:`βœ“`,label:`merged`,tint:`border-emerald-400/40`,dot:`bg-emerald-400`},"needs-review":{icon:`⚠`,label:`conflict`,tint:`border-fuchsia-400/50`,dot:`bg-fuchsia-400`},failed:{icon:`βœ—`,label:`failed`,tint:`border-rose-400/50`,dot:`bg-rose-400`}};function ra(e){return na[e]??{icon:`?`,label:e,tint:`border-border`,dot:`bg-muted-foreground`}}var ia=e=>e.replace(/^wstack\/ap\//,``);function aa({worktrees:e,baseBranch:t}){if(e.length===0)return null;let n=[...e].sort((e,t)=>e.allocatedAt-t.allocatedAt);return(0,G.jsxs)(`div`,{className:`rounded-lg border bg-card/50 backdrop-blur-sm px-3 py-3`,children:[(0,G.jsxs)(`div`,{className:`mb-2 flex items-center gap-2 text-xs text-muted-foreground`,children:[(0,G.jsx)(`span`,{className:`font-semibold tracking-wide uppercase text-[10px]`,children:`Worktrees`}),(0,G.jsx)(`span`,{className:`opacity-60`,children:`Β· base`}),(0,G.jsx)(`code`,{className:`font-mono text-primary`,children:t||`HEAD`}),(0,G.jsxs)(`span`,{className:`opacity-60`,children:[`Β· `,n.length,` isolated`]})]}),(0,G.jsx)(`div`,{className:`flex flex-col gap-1.5`,children:n.map(e=>{let t=ra(e.status),n=e.status===`needs-review`,r=Math.min(100,e.insertions+e.deletions);return(0,G.jsxs)(`div`,{className:Y(`group relative flex items-center gap-3 rounded-lg border px-3 py-2 transition-all duration-500`,`bg-background/60 hover:bg-accent/20`,t.tint),children:[(0,G.jsx)(`span`,{className:Y(`h-2.5 w-2.5 shrink-0 rounded-full`,t.dot),"aria-hidden":!0}),(0,G.jsx)(`code`,{className:`w-44 shrink-0 truncate font-mono text-sm`,children:ia(e.branch)}),(0,G.jsxs)(`span`,{className:`shrink-0 rounded bg-muted px-2 py-0.5 text-xs text-muted-foreground`,children:[`⟡ `,e.ownerLabel]}),n?(0,G.jsx)(`span`,{className:`font-mono text-xs font-bold text-fuchsia-400`,children:`CONFLICT`}):(0,G.jsxs)(`span`,{className:`flex items-center gap-1 font-mono text-xs transition-all duration-500`,children:[(0,G.jsxs)(`span`,{className:`text-emerald-500`,children:[`+`,e.insertions]}),(0,G.jsx)(`span`,{className:`text-muted-foreground`,children:`Β·`}),(0,G.jsxs)(`span`,{className:`text-rose-500`,children:[`-`,e.deletions]}),(0,G.jsxs)(`span`,{className:`ml-1 text-muted-foreground`,children:[e.files,`f`]})]}),(0,G.jsx)(`div`,{className:`ml-auto hidden h-1 w-24 overflow-hidden rounded-full bg-muted sm:block`,children:(0,G.jsx)(`div`,{className:`h-full bg-gradient-to-r from-emerald-500 to-rose-500 transition-all duration-700`,style:{width:`${r}%`}})}),(0,G.jsx)(`span`,{className:`w-20 shrink-0 text-right text-xs text-muted-foreground`,children:t.label}),e.recentActivity.length>0?(0,G.jsxs)(`span`,{className:`absolute -bottom-2 left-9 max-w-[60%] truncate rounded bg-muted px-1.5 text-[10px] text-muted-foreground opacity-0 transition-opacity duration-300 group-hover:opacity-100`,children:[e.recentActivity[e.recentActivity.length-1]?.kind,`: `,e.recentActivity[e.recentActivity.length-1]?.text]}):null]},e.handleId)})})]})}var oa=te(`inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50`,{variants:{variant:{default:`bg-primary text-primary-foreground hover:bg-primary/90`,destructive:`bg-destructive text-destructive-foreground hover:bg-destructive/90`,outline:`border border-input bg-background hover:bg-accent hover:text-accent-foreground`,secondary:`bg-secondary text-secondary-foreground hover:bg-secondary/80`,ghost:`hover:bg-accent hover:text-accent-foreground`,link:`text-primary underline-offset-4 hover:underline`},size:{default:`h-10 px-4 py-2`,sm:`h-9 rounded-md px-3`,lg:`h-11 rounded-md px-8`,icon:`h-10 w-10`}},defaultVariants:{variant:`default`,size:`default`}}),Q=z.forwardRef(({className:e,variant:t,size:n,asChild:r=!1,...i},a)=>(0,G.jsx)(r?tn:`button`,{className:Y(oa({variant:t,size:n,className:e})),ref:a,...i}));Q.displayName=`Button`;function sa({onClose:e}){let{client:t}=Z(),n=Cr(e=>e.phases),r=Cr(e=>e.activePhaseId),i=Cr(e=>e.overallPercent),a=Cr(e=>e.autonomous),o=Cr(e=>e.title),s=ar(e=>e.worktrees),c=ar(e=>e.baseBranch),[l,u]=(0,z.useState)(``),[d,f]=(0,z.useState)(!1),[p,m]=(0,z.useState)(!1),h=n.length>0,g=(0,z.useCallback)(async()=>{let e=l.trim();!e||d||(f(!0),await new Promise(e=>setTimeout(e,100)),t?.send?.({type:`autophase.start`,payload:{title:e,autonomous:!0}}),f(!1))},[l,d,t]),_=(0,z.useCallback)(e=>{t?.send?.({type:`autophase.selectPhase`,payload:{phaseId:e}})},[t]),v=(0,z.useCallback)(()=>{t?.send?.({type:`autophase.toggleAutonomous`,payload:{}})},[t]),y=(0,z.useCallback)((e,n)=>{t?.send?.({type:`autophase.taskStatus`,payload:{taskId:e,status:n}})},[t]),b=n.find(e=>e.id===r),x=b?b.tasks??[]:[];return(0,G.jsxs)(`div`,{className:`flex flex-col h-full bg-background`,children:[(0,G.jsxs)(`header`,{className:`flex items-center justify-between px-4 py-2 border-b bg-card shrink-0`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(Jt,{className:`h-5 w-5 text-muted-foreground`}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`h1`,{className:`text-lg font-semibold`,children:h&&o||`AutoPhase`}),h&&(0,G.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[n.length,` phase`,n.length===1?``:`s`,` Β· `,i,`% complete`]})]})]}),(0,G.jsx)(Q,{variant:`ghost`,size:`icon`,onClick:e,children:(0,G.jsx)(F,{className:`h-4 w-4`})})]}),h?(0,G.jsxs)(`div`,{className:`flex min-h-0 flex-1`,children:[(0,G.jsx)(Gi,{phases:n,activePhaseId:r??void 0,onPhaseClick:_,overallPercent:i,autonomous:a,onToggleAutonomous:v,className:`w-72 shrink-0`}),(0,G.jsx)(`div`,{className:`flex min-w-0 flex-1 flex-col`,children:b?(0,G.jsx)(Xi,{phaseName:b.name,phaseStatus:b.status,tasks:x.map(e=>({id:e.id,title:e.title,description:e.description,status:e.status,priority:e.priority||`medium`,type:e.type||`feature`,estimateHours:e.estimateHours,assignee:e.assignee,tags:e.tags??[]})),onTaskStatusChange:y}):(0,G.jsx)(`div`,{className:`flex h-full items-center justify-center text-muted-foreground`,children:(0,G.jsx)(`p`,{className:`text-sm`,children:`Select a phase from the left panel to view its tasks.`})})})]}):(0,G.jsx)(`div`,{className:`flex-1 flex items-center justify-center p-8`,children:(0,G.jsxs)(`div`,{className:`max-w-lg w-full space-y-6`,children:[(0,G.jsxs)(`div`,{className:`text-center space-y-2`,children:[(0,G.jsx)(Ft,{className:`h-10 w-10 mx-auto text-primary/60`}),(0,G.jsx)(`h2`,{className:`text-xl font-semibold`,children:`Start a Phase Plan`}),(0,G.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Describe what you want to build. WrongStack will plan phases and tasks, then execute them autonomously.`})]}),(0,G.jsx)(`textarea`,{value:l,onChange:e=>u(e.target.value),placeholder:`e.g. Build a REST API for user management with Express and SQLite...`,rows:5,className:`w-full rounded-lg border border-border bg-card px-4 py-3 text-sm resize-none focus:outline-none focus:ring-2 focus:ring-primary/30 placeholder:text-muted-foreground/50`,onKeyDown:e=>{e.key===`Enter`&&(e.ctrlKey||e.metaKey)&&(e.preventDefault(),g())}}),(0,G.jsx)(`div`,{className:`flex items-center gap-3`,children:(0,G.jsxs)(Q,{onClick:g,disabled:!l.trim()||d,className:`flex-1 gap-2`,children:[(0,G.jsx)(ge,{className:`h-4 w-4`}),d?`Starting…`:`Start AutoPhase`]})}),(0,G.jsx)(`p`,{className:`text-xs text-muted-foreground text-center`,children:`Ctrl+Enter to start Β· Phases execute sequentially with full agent tool access`})]})}),s.length>0&&(0,G.jsxs)(`div`,{className:`border-t bg-card/50 shrink-0`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-end gap-2 px-4 pt-2 text-xs`,children:[(0,G.jsx)(`button`,{type:`button`,onClick:()=>m(!1),className:Y(`rounded px-2 py-0.5 border transition-colors`,p?`border-border text-muted-foreground hover:text-foreground`:`bg-primary/10 border-primary/30 text-primary`),children:`Lanes`}),(0,G.jsx)(`button`,{type:`button`,onClick:()=>m(!0),className:Y(`rounded px-2 py-0.5 border transition-colors`,p?`bg-primary/10 border-primary/30 text-primary`:`border-border text-muted-foreground hover:text-foreground`),children:`Graph`})]}),(0,G.jsx)(`div`,{className:`px-4 pb-3`,children:p?(0,G.jsx)(ta,{worktrees:s,baseBranch:c}):(0,G.jsx)(aa,{worktrees:s,baseBranch:c})})]})]})}var ca=[{mode:`off`,label:`Off`,description:`Full manual control β€” agent waits for your input.`,icon:(0,G.jsx)(Fn,{className:`h-3.5 w-3.5`})},{mode:`suggest`,label:`Suggest`,description:`Agent suggests next steps but waits for approval.`,icon:(0,G.jsx)(lt,{className:`h-3.5 w-3.5`})},{mode:`auto`,label:`Auto`,description:`Agent auto-proceeds after brief confirmation delay.`,icon:(0,G.jsx)(ge,{className:`h-3.5 w-3.5`})},{mode:`eternal`,label:`Eternal`,description:`Agent runs autonomously until goal is complete.`,icon:(0,G.jsx)(Ht,{className:`h-3.5 w-3.5`})},{mode:`eternal-parallel`,label:`Eternal Parallel`,description:`Multi-agent autonomous execution β€” fleet mode.`,icon:(0,G.jsx)(Ht,{className:`h-3.5 w-3.5`})}];function la({value:e,onChange:t,className:n,compact:r=!1}){let[i,a]=(0,z.useState)(!1),o=(0,z.useRef)(null);(0,z.useEffect)(()=>{if(!i)return;let e=e=>{o.current&&!o.current.contains(e.target)&&a(!1)};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[i]),(0,z.useEffect)(()=>{if(!i)return;let e=e=>{e.key===`Escape`&&a(!1)};return document.addEventListener(`keydown`,e),()=>document.removeEventListener(`keydown`,e)},[i]);let s=ca.find(t=>t.mode===e);return(0,G.jsxs)(`div`,{ref:o,className:`relative`,children:[(0,G.jsxs)(`button`,{type:`button`,onClick:()=>a(e=>!e),className:Y(`flex items-center gap-1 px-2 py-0.5 rounded-md border text-[11px] font-medium transition-colors hover:opacity-80`,e===`eternal`||e===`eternal-parallel`?`bg-rose-500/15 text-rose-600 dark:text-rose-400 border-rose-500/30`:e===`auto`?`bg-amber-500/15 text-amber-600 dark:text-amber-400 border-amber-500/30`:e===`suggest`?`bg-blue-500/15 text-blue-600 dark:text-blue-400 border-blue-500/30`:`bg-muted text-muted-foreground border-transparent`,n),title:`Autonomy: ${s?.label??e}`,children:[s?.icon,!r&&(0,G.jsx)(`span`,{className:`truncate max-w-[7rem]`,children:s?.label??e}),(0,G.jsx)(sn,{className:`h-3 w-3 opacity-60`})]}),i&&(0,G.jsxs)(`div`,{className:`absolute top-full mt-1 right-0 z-50 w-56 rounded-lg border bg-popover shadow-lg p-1`,children:[(0,G.jsx)(`div`,{className:`px-3 py-1.5 text-[10px] uppercase tracking-wider text-muted-foreground border-b mb-1`,children:`Autonomy Mode`}),ca.map(n=>(0,G.jsxs)(`button`,{type:`button`,onClick:()=>{t(n.mode),a(!1)},className:Y(`w-full flex items-start gap-2 px-3 py-2 rounded text-left transition-colors`,e===n.mode?`bg-accent text-accent-foreground`:`hover:bg-accent/40`),children:[(0,G.jsx)(`span`,{className:`mt-0.5 text-muted-foreground`,children:n.icon}),(0,G.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,G.jsx)(`span`,{className:`text-sm font-medium`,children:n.label}),(0,G.jsx)(`p`,{className:`text-[10px] text-muted-foreground leading-snug`,children:n.description})]}),e===n.mode&&(0,G.jsx)(`span`,{className:`h-1.5 w-1.5 rounded-full bg-primary mt-2 shrink-0`})]},n.mode))]})]})}function ua(){let e=V.getState().messages,t=[],n=new Date().toISOString().slice(0,19).replace(/[:T]/g,`-`),r=U.getState().projectName||`chat`,i=U.getState().session?.title||r;t.push(`# ${i} β€” chat export`),t.push(`*Exported: ${new Date().toISOString()}*`),t.push(``);for(let n of e)if(n.role===`user`)t.push(`## πŸ‘€ User`),t.push(``),t.push(n.content),t.push(``);else if(n.role===`assistant`)t.push(`## πŸ€– Assistant`),t.push(``),t.push(n.content),t.push(``);else if(n.role===`tool`){let e=n.isError?`❌`:n.toolResult===void 0?`⏳`:`βœ…`;t.push(`### πŸ”§ Tool: \`${n.toolName??`unknown`}\` ${e}`),n.toolInput!==void 0&&(t.push("```json"),t.push(JSON.stringify(n.toolInput,null,2)),t.push("```")),n.toolResult&&(t.push(`<details><summary>Output</summary>`),t.push(``),t.push("```"),t.push(n.toolResult),t.push("```"),t.push(`</details>`)),t.push(``)}let a=new Blob([t.join(`
27
- `)],{type:`text/markdown`}),o=URL.createObjectURL(a),s=document.createElement(`a`);s.href=o,s.download=`${r.toLowerCase().replace(/[^a-z0-9]+/g,`-`)}-chat-${n}.md`,document.body.appendChild(s),s.click(),document.body.removeChild(s),URL.revokeObjectURL(o)}function da(){let e=V.getState().messages,t=U.getState(),n=t.projectName||`chat`,r=escape(t.session?.title||n),i=new Date().toISOString().slice(0,19).replace(/[:T]/g,`-`),a=e=>e.replace(/&/g,`&amp;`).replace(/</g,`&lt;`).replace(/>/g,`&gt;`).replace(/"/g,`&quot;`).replace(/'/g,`&#39;`),o=e.map(e=>{if(e.role===`tool`){let t=e.isError?`❌`:e.toolResult===void 0?`⏳`:`βœ…`;return`
28
- <section class="bubble tool ${e.isError?`error`:``}">
29
- <header><span class="icon">πŸ”§</span><code>${a(e.toolName??`tool`)}</code> ${t}</header>
30
- ${e.toolInput===void 0?``:`<details><summary>Input</summary><pre>${a(JSON.stringify(e.toolInput,null,2))}</pre></details>`}
31
- ${e.toolResult?`<details><summary>Output</summary><pre>${a(e.toolResult)}</pre></details>`:``}
32
- </section>`}return`
33
- <section class="bubble ${e.role===`user`?`user`:`assistant`}">
34
- <header><span class="icon">${e.role===`user`?`πŸ‘€`:`πŸ€–`}</span><strong>${e.role===`user`?`User`:`Assistant`}</strong></header>
35
- <pre class="content">${a(e.content)}</pre>
36
- </section>`}),s=`<!doctype html>
37
- <html lang="en"><head>
38
- <meta charset="utf-8">
39
- <title>${r} β€” chat export</title>
40
- <style>
41
- :root { color-scheme: light dark; }
42
- body { font: 14px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; max-width: 920px; margin: 24px auto; padding: 0 16px; }
43
- h1 { font-size: 20px; margin-bottom: 4px; }
44
- .meta { color: #666; font-size: 12px; margin-bottom: 24px; }
45
- .bubble { margin: 12px 0; padding: 10px 14px; border-radius: 10px; border: 1px solid #ddd; }
46
- .bubble header { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: #666; margin-bottom: 6px; }
47
- .bubble header .icon { margin-right: 4px; }
48
- .bubble.user { background: #eef4ff; border-color: #c8d8f5; }
49
- .bubble.assistant { background: #fff; }
50
- .bubble.tool { background: #fafafa; }
51
- .bubble.tool.error { background: #fff5f5; border-color: #f5c8c8; }
52
- pre.content, .bubble pre { white-space: pre-wrap; word-break: break-word; font: 12px/1.5 ui-monospace, Menlo, Consolas, monospace; margin: 0; }
53
- details summary { cursor: pointer; color: #555; font-size: 12px; }
54
- details pre { margin-top: 6px; background: #f4f4f4; padding: 8px; border-radius: 6px; max-height: 360px; overflow: auto; }
55
- @media (prefers-color-scheme: dark) {
56
- body { background: #0d0d0f; color: #e6e6e6; }
57
- .bubble { border-color: #2a2a2e; }
58
- .bubble.user { background: #16213a; border-color: #2a3d6b; }
59
- .bubble.assistant { background: #161618; }
60
- .bubble.tool { background: #131315; }
61
- .bubble.tool.error { background: #2a1717; border-color: #5c2a2a; }
62
- details pre { background: #1a1a1c; }
63
- .meta, .bubble header, details summary { color: #999; }
64
- }
65
- </style>
66
- </head><body>
67
- <h1>${r} β€” chat export</h1>
68
- <div class="meta">
69
- Exported ${new Date().toISOString()}${t.session?.provider?` Β· ${escape(t.session.provider)}/${escape(t.session.model)}`:``} Β· ${e.length} message${e.length===1?``:`s`}
70
- </div>
71
- ${o.join(``)}
72
- </body></html>`,c=new Blob([s],{type:`text/html;charset=utf-8`}),l=URL.createObjectURL(c),u=document.createElement(`a`);u.href=l,u.download=`${n.toLowerCase().replace(/[^a-z0-9]+/g,`-`)}-chat-${i}.html`,document.body.appendChild(u),u.click(),document.body.removeChild(u),URL.revokeObjectURL(l)}function fa(){let e=W(e=>e.paletteOpen),n=W(e=>e.setPaletteOpen),r=W(e=>e.setCurrentView),i=H(e=>e.setTheme),{entries:a}=ir(),{addMessage:o,clearMessages:s}=V(),c=Z(),[l,u]=(0,z.useState)(``),[d,f]=(0,z.useState)(0),p=(0,z.useRef)(null);(0,z.useEffect)(()=>{e&&(u(``),f(0),requestAnimationFrame(()=>p.current?.focus()))},[e]),(0,z.useEffect)(()=>{let e=e=>{if((e.ctrlKey||e.metaKey)&&e.key.toLowerCase()===`k`){e.preventDefault(),n(!W.getState().paletteOpen);return}e.key===`Escape`&&W.getState().paletteOpen&&(e.preventDefault(),n(!1))};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[n]);let m=(0,z.useMemo)(()=>{let e=[{id:`help`,category:`Command`,label:`Show slash commands`,icon:ht,keywords:[`help`,`commands`,`?`],run:()=>{o({role:`assistant`,content:"Type `/` in the message box to see every slash command."})}},{id:`tools`,category:`Command`,label:`List tools`,icon:t,keywords:[`tools`,`list`],run:()=>c.listTools()},{id:`memory`,category:`Command`,label:`Show memory`,icon:Yt,keywords:[`memory`,`remember`,`notes`],run:()=>c.listMemory()},{id:`skills`,category:`Command`,label:`List skills`,icon:Cn,keywords:[`skills`],run:()=>c.listSkills()},{id:`diag`,category:`Command`,label:`Runtime diagnostics`,icon:Tt,keywords:[`diag`,`diagnostics`,`debug`],run:()=>c.getDiag()},{id:`stats`,category:`Command`,label:`Session stats (tokens, cache, cost)`,icon:Qe,keywords:[`stats`,`tokens`,`cost`,`cache`],run:()=>c.getStats()},{id:`clear`,category:`Session`,label:`Clear context`,hint:`Wipe in-memory context, keep session id`,icon:yn,keywords:[`clear`,`reset`,`wipe`],run:()=>{s(),c.client?.clearContext?.()}},{id:`new`,category:`Session`,label:`New session`,hint:`Brand-new on disk + memory`,icon:pe,keywords:[`new`,`fresh`,`session`],run:()=>{c.client?.newSession?.(),r(`chat`)}},{id:`compact`,category:`Session`,label:`Compact context`,icon:Pn,keywords:[`compact`,`shrink`,`context`],run:()=>c.client?.compactContext?.()},{id:`repair-context`,category:`Session`,label:`Repair context`,hint:`Remove orphan tool protocol blocks`,icon:t,keywords:[`repair`,`context`,`tool_use`,`tool_result`],run:()=>c.client?.repairContext?.()},{id:`export`,category:`Session`,label:`Export chat as markdown`,icon:ie,keywords:[`export`,`save`,`markdown`,`download`],run:()=>ua()},{id:`export-html`,category:`Session`,label:`Export chat as HTML`,hint:`Self-contained, opens in any browser`,icon:ie,keywords:[`export`,`html`,`download`,`archive`],run:()=>da()},{id:`history`,category:`Command`,label:`Open history panel`,icon:ct,keywords:[`history`,`sessions`],run:()=>{W.getState().setSidebarOpen(!0),W.getState().selectActivity(`history`)}},{id:`settings`,category:`Command`,label:`Open settings`,icon:En,keywords:[`settings`,`config`],run:()=>r(`settings`)},{id:`model`,category:`Command`,label:`Change provider/model`,icon:E,keywords:[`model`,`provider`,`change`],run:()=>W.getState().setModelSwitcherOpen(!0)},{id:`theme-light`,category:`Theme`,label:`Theme: Light`,icon:Ut,keywords:[`theme`,`light`,`mode`],run:()=>i(`light`)},{id:`theme-dark`,category:`Theme`,label:`Theme: Dark`,icon:w,keywords:[`theme`,`dark`,`mode`],run:()=>i(`dark`)},{id:`theme-system`,category:`Theme`,label:`Theme: Follow system`,icon:ne,keywords:[`theme`,`system`,`auto`],run:()=>i(`system`)},{id:`compact-toggle`,category:`Command`,label:`Toggle compact density`,icon:Ge,hint:`Ctrl+Shift+D`,keywords:[`compact`,`dense`,`density`,`size`],run:()=>W.getState().toggleCompactMode()},{id:`sound-toggle`,category:`Command`,label:H.getState().soundOnComplete?`Sound on completion: ON β€” turn off`:`Sound on completion: OFF β€” turn on`,icon:H.getState().soundOnComplete?cn:Kt,hint:`Chime when a run finishes`,keywords:[`sound`,`audio`,`chime`,`notify`,`beep`],run:()=>{let e=!H.getState().soundOnComplete;H.getState().setSoundOnComplete(e),e&&Rr()}},{id:`autophase-open`,category:`Command`,label:`Open AutoPhase view`,icon:Ft,keywords:[`autophase`,`autonomous`,`phases`,`rocket`],run:()=>r(`autophase`)},{id:`autophase-toggle`,category:`Command`,label:Cr.getState().autonomous?`Autonomous mode: ON β€” disable`:`Autonomous mode: OFF β€” enable`,icon:Cr.getState().autonomous?Fn:ge,hint:`Toggle autonomous phase execution`,keywords:[`autonomous`,`autophase`,`auto`,`pause`,`resume`],run:()=>{let e=!Cr.getState().autonomous;c.toggleAutoPhaseAutonomous(e)}},{id:`autophase-stop`,category:`Command`,label:`Stop AutoPhase`,icon:Ye,keywords:[`autophase`,`stop`,`autonomous`,`end`],run:()=>c.stopAutoPhase()}];for(let t of a.slice(0,10))t.isCurrent||e.push({id:`resume-${t.id}`,category:`Session`,label:`Resume: ${t.title||`(empty)`}`,hint:`${t.provider}/${t.model}`,icon:$t,keywords:[`resume`,t.title,t.id,t.provider,t.model],run:()=>c.resumeSession(t.id)});return e},[a,c,r,i,o,s]),h=(0,z.useMemo)(()=>{let e=l.toLowerCase().trim();return e?m.filter(t=>[t.label,t.hint??``,t.category,...t.keywords??[]].join(` `).toLowerCase().includes(e)):m},[m,l]);if((0,z.useEffect)(()=>{d>=h.length&&f(0)},[h.length,d]),!e)return null;let g=e=>{e&&(n(!1),e.run())};return(0,G.jsx)(`div`,{className:`fixed inset-0 z-50 bg-background/60 backdrop-blur-sm flex items-start justify-center pt-[14vh] px-4`,onClick:()=>n(!1),onKeyDown:e=>{e.key===`Escape`&&n(!1)},children:(0,G.jsxs)(`div`,{onClick:e=>e.stopPropagation(),onKeyDown:e=>e.stopPropagation(),className:`w-full max-w-2xl rounded-xl border bg-popover shadow-2xl overflow-hidden flex flex-col`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 px-4 py-3 border-b`,children:[(0,G.jsx)(v,{className:`h-4 w-4 text-muted-foreground`}),(0,G.jsx)(`input`,{ref:p,value:l,onChange:e=>u(e.target.value),placeholder:`Search commands, sessions, settings…`,className:`flex-1 bg-transparent outline-none text-sm placeholder:text-muted-foreground`,onKeyDown:e=>{e.key===`ArrowDown`?(e.preventDefault(),f(e=>(e+1)%Math.max(1,h.length))):e.key===`ArrowUp`?(e.preventDefault(),f(e=>(e-1+Math.max(1,h.length))%Math.max(1,h.length))):e.key===`Enter`&&(e.preventDefault(),g(h[d]))}}),(0,G.jsx)(`kbd`,{className:`text-[10px] text-muted-foreground border rounded px-1.5 py-0.5`,children:`Esc`})]}),(0,G.jsx)(`div`,{className:`max-h-[60vh] overflow-y-auto`,children:h.length===0?(0,G.jsxs)(`div`,{className:`px-4 py-8 text-center text-sm text-muted-foreground`,children:[`No matches for "`,l,`"`]}):pa(h,d,g,f)}),(0,G.jsxs)(`div`,{className:`border-t px-4 py-2 text-[10px] uppercase tracking-wider text-muted-foreground flex items-center gap-3`,children:[(0,G.jsx)(`span`,{children:`↑↓ navigate`}),(0,G.jsx)(`span`,{children:`↡ select`}),(0,G.jsx)(`span`,{children:`Esc dismiss`})]})]})})}function pa(e,t,n,r){let i={};return e.forEach((e,t)=>{i[e.category]||(i[e.category]=[]),i[e.category]?.push({item:e,globalIdx:t})}),(0,G.jsx)(`div`,{className:`p-1`,children:Object.entries(i).map(([e,i])=>(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`div`,{className:`px-3 pt-2 pb-1 text-[10px] uppercase tracking-wider text-muted-foreground`,children:e}),i.map(({item:e,globalIdx:i})=>{let a=e.icon,o=i===t;return(0,G.jsxs)(`button`,{type:`button`,onMouseEnter:()=>r(i),onClick:()=>n(e),className:Y(`w-full flex items-center gap-3 px-3 py-2 rounded text-left text-sm transition-colors`,o?`bg-accent text-accent-foreground`:`hover:bg-accent/40`),children:[(0,G.jsx)(a,{className:`h-4 w-4 text-muted-foreground shrink-0`}),(0,G.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,G.jsx)(`div`,{className:`truncate`,children:e.label}),e.hint&&(0,G.jsx)(`div`,{className:`text-xs text-muted-foreground truncate`,children:e.hint})]}),o&&(0,G.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:`↡`})]},e.id)})]},e))})}function ma({query:e,onPick:t,onClose:n}){let r=Z(),i=H(e=>e.wsUrl),[a,o]=(0,z.useState)([]),[s,c]=(0,z.useState)(0),l=(0,z.useRef)(null),u=(0,z.useRef)(null);return(0,z.useEffect)(()=>{let e=B(i).on(`files.list`,e=>{let t=e.payload;o(t.files??[]),c(0),u.current?.resolve(t.files??[]),u.current=null});return()=>e()},[i]),(0,z.useEffect)(()=>(l.current&&clearTimeout(l.current),l.current=setTimeout(()=>{r.client.listFiles(e,50)},80),()=>{l.current&&clearTimeout(l.current)}),[e,r.client]),(0,z.useEffect)(()=>{let e=e=>{if(e.key===`ArrowDown`)e.preventDefault(),c(e=>(e+1)%Math.max(1,a.length));else if(e.key===`ArrowUp`)e.preventDefault(),c(e=>(e-1+Math.max(1,a.length))%Math.max(1,a.length));else if(e.key===`Enter`||e.key===`Tab`){if(a.length===0)return;e.preventDefault(),t(R(a[s]))}else e.key===`Escape`&&(e.preventDefault(),n())};return window.addEventListener(`keydown`,e,!0),()=>window.removeEventListener(`keydown`,e,!0)},[a,s,t,n]),(0,G.jsxs)(`div`,{className:`absolute bottom-full left-0 right-0 mb-2 rounded-lg border bg-popover shadow-md p-1 text-sm max-h-72 overflow-auto`,children:[(0,G.jsxs)(`div`,{className:`px-3 py-1 text-[10px] uppercase tracking-wider text-muted-foreground border-b mb-1 flex items-center justify-between`,children:[(0,G.jsxs)(`span`,{children:[`@ Files `,e&&`Β· "${e}"`]}),(0,G.jsx)(`span`,{children:`↑/↓ select Β· ↡ insert Β· Esc dismiss`})]}),a.length===0?(0,G.jsx)(`div`,{className:`px-3 py-2 text-xs text-muted-foreground italic`,children:e?`No files match "${e}"`:`Searching project…`}):a.map((e,n)=>(0,G.jsxs)(`button`,{type:`button`,onClick:()=>t(e),onMouseEnter:()=>c(n),className:Y(`w-full text-left px-3 py-1.5 rounded transition-colors flex items-center gap-2 font-mono text-xs`,n===s?`bg-accent text-accent-foreground`:`hover:bg-accent/40`),children:[e.includes(`/`)?(0,G.jsx)(qe,{className:`h-3.5 w-3.5 text-muted-foreground shrink-0`}):(0,G.jsx)(Tn,{className:`h-3.5 w-3.5 text-muted-foreground shrink-0`}),(0,G.jsx)(`span`,{className:`truncate`,children:e})]},e))]})}var ha=[{name:`/new`,category:`Session`,description:`Start a brand-new session (fresh on disk and in memory)`},{name:`/clear`,category:`Session`,description:`Wipe current context (keeps session id, disk record stays)`},{name:`/compact`,category:`Session`,description:`Shrink context β€” elide ancient tool output`},{name:`/compact!`,category:`Session`,description:`Aggressively shrink context now`},{name:`/repair`,category:`Session`,description:`Repair orphan tool-use / tool-result protocol blocks`},{name:`/save`,category:`Session`,description:`Force-flush the session (auto-saved already)`},{name:`/load`,category:`Session`,aliases:[`/resume`],description:`Resume a previous session from disk`},{name:`/export`,category:`Session`,description:`Download the current chat as markdown`},{name:`/debug`,category:`Inspect`,aliases:[`/context`],description:`Context size breakdown per section`},{name:`/tools`,category:`Inspect`,description:`List every registered tool the model can call`},{name:`/memory`,category:`Inspect`,description:`Manage memory: show, remember, forget, clear, stats`},{name:`/todos`,category:`Inspect`,description:`List current todos`},{name:`/stats`,category:`Inspect`,description:`Session stats: tokens, cost, elapsed`},{name:`/skill`,category:`Inspect`,aliases:[`/skills`],description:`List active skills`},{name:`/diag`,category:`Inspect`,description:`Runtime diagnostics (provider, tools, mode, usage)`},{name:`/agents`,category:`Inspect`,description:`Show status of spawned subagents`},{name:`/brain`,category:`Inspect`,description:`Brain status, risk ceiling (risk <level>), or decision support (ask <question>)`},{name:`/plan`,category:`Inspect`,description:`Strategic plan board: show, add, start, done, promote, clear`},{name:`/suggest`,category:`Inspect`,aliases:[`/next-steps`],description:`Ask the agent for concrete next steps`},{name:`/next`,category:`Inspect`,description:`Show or run numbered next-step suggestions`},{name:`/settings`,category:`Config`,aliases:[`/model`],description:`Open settings (provider/model/keys)`},{name:`/enhance`,category:`Config`,description:`Toggle prompt refinement before sending`},{name:`/interrupt`,category:`Run`,aliases:[`/abort`,`/stop`,`/int`],description:`Stop the current run (abort the in-flight request)`},{name:`/help`,category:`App`,description:`Show every slash command and what it does`},{name:`/exit`,category:`App`,description:`Exit the session and close WebUI`}],ga=[`Run`,`Session`,`Inspect`,`Config`,`App`];function _a(e){let t=e.toLowerCase();return t===`/`||t===``?ha:ha.filter(e=>e.name.startsWith(t)||(e.aliases?.some(e=>e.startsWith(t))??!1))}function va(e,t){let n=t-1;for(;n>=0;){let r=R(e[n]);if(r===`@`){let r=n>0?e[n-1]:``;return n===0||/\s/.test(r??``)?{start:n,query:e.slice(n+1,t)}:null}if(/\s/.test(r))return null;n--}return null}var ya=[{lang:`typescript`,patterns:[{regex:/:\s*(string|number|boolean|void|never|any|unknown|Promise|Array|Record|Map|Set)\b/,weight:4},{regex:/\b(interface|type|enum|namespace|implements|extends|as|satisfies|infer)\b/,weight:3},{regex:/\b(import|export)\s+/,weight:3},{regex:/\b(const|let|var)\s+\w+\s*[:=]/,weight:2},{regex:/=>/,weight:1},{regex:/\.tsx?['"]/,weight:2}]},{lang:`javascript`,patterns:[{regex:/\b(import|export|require)\s*[({]/,weight:3},{regex:/\b(const|let|var)\s+\w+\s*=\s*require/,weight:2},{regex:/\bmodule\.exports/,weight:3},{regex:/\.jsx?['"]/,weight:2}]},{lang:`python`,patterns:[{regex:/^\s*def\s+\w+\s*\(/,weight:4},{regex:/^\s*class\s+\w+.*:/,weight:3},{regex:/\bimport\s+\w+/,weight:2},{regex:/\bfrom\s+\w+\s+import/,weight:3},{regex:/\bprint\(/,weight:1},{regex:/\bself\./,weight:2},{regex:/if\s+__name__\s*==\s*['"]__main__['"]/,weight:4}]},{lang:`rust`,patterns:[{regex:/\bfn\s+\w+\s*[<(]/,weight:4},{regex:/\blet\s+mut\s/,weight:3},{regex:/\b(struct|enum|impl|trait|mod)\s+\w+/,weight:3},{regex:/\bpub\s+(fn|struct|enum)/,weight:3},{regex:/->\s*\w+/,weight:1},{regex:/::\w+/,weight:1}]},{lang:`go`,patterns:[{regex:/\bfunc\s+\w+\s*\(/,weight:4},{regex:/\bpackage\s+\w+/,weight:4},{regex:/\bimport\s*\(/,weight:3},{regex:/\b(err|nil)\b/,weight:2},{regex:/:=/,weight:2},{regex:/\bdefer\s/,weight:2}]},{lang:`json`,patterns:[{regex:/^\s*[{[]/,weight:3},{regex:/"[^"]+"\s*:\s*/,weight:3},{regex:/^\s*[}\]]\s*$/,weight:1}]},{lang:`yaml`,patterns:[{regex:/^---\s*$/,weight:4},{regex:/^\s*\w[\w.-]*:\s/,weight:2},{regex:/^\s*-\s+\w/,weight:1}]},{lang:`html`,patterns:[{regex:/<(!DOCTYPE|html|head|body|div|span|a|p|ul|li|table)/i,weight:4},{regex:/<\/?\w+[\s>]/,weight:2},{regex:/\b(class|id|href|src)="/,weight:2}]},{lang:`css`,patterns:[{regex:/[{]\s*$/,weight:1},{regex:/^\s*[.#@]\S+\s*[{]/,weight:3},{regex:/\b(\d+px|\d+em|\d+rem|\d+vh|\d+vw)\b/,weight:3},{regex:/:\s*\w+\s*!important/,weight:3},{regex:/@(media|keyframes|import|apply)/,weight:3}]},{lang:`sql`,patterns:[{regex:/\b(SELECT|INSERT|UPDATE|DELETE|CREATE TABLE|ALTER TABLE|DROP TABLE)\b/i,weight:4},{regex:/\bFROM\s+\w+/i,weight:2},{regex:/\bWHERE\s+/i,weight:2},{regex:/\b(JOIN|INNER JOIN|LEFT JOIN)\b/i,weight:2}]},{lang:`bash`,patterns:[{regex:/^#!\/.*(bash|sh|zsh)/,weight:5},{regex:/\becho\s/,weight:2},{regex:/\bexport\s+\w+=/,weight:2},{regex:/\bif\s+\[\[?\s/,weight:2},{regex:/\$\{?\w+/,weight:1},{regex:/&&|\|\|/,weight:1}]},{lang:`toml`,patterns:[{regex:/^\s*\[.*\]\s*$/,weight:3},{regex:/^\s*\w+\s*=\s*['"]/,weight:2},{regex:/^\s*\[\[.*\]\]\s*$/,weight:3}]}],ba=6,xa=3,Sa=180;function Ca(e){let t=e.split(`
73
- `);if(t.length<xa)return!1;let n=0,r=0;for(let e of t){let t=e.trim();t.length!==0&&(t.length>Sa&&r++,/^ {2,}/.test(e)&&n++,/[.!?]$/.test(t)&&r++,/[{}();=<>[\]]/.test(t)&&n++,/[#$]/.test(t)&&!/^# /.test(t)&&n++)}return n>=r&&n>=2}function wa(e){if(!Ca(e))return null;let t={};for(let n of ya){let r=0;for(let{regex:t,weight:i}of n.patterns){let n=e.match(new RegExp(t.source,t.flags.includes(`g`)?t.flags:`${t.flags}g`));n&&(r+=n.length*i)}r>0&&(t[n.lang]=r)}t.javascript&&t.typescript&&(t.typescript>=t.javascript?delete t.javascript:t.javascript>t.typescript&&delete t.typescript);let n=null,r=0;for(let[e,i]of Object.entries(t))i>r&&(r=i,n=e);return r>=ba?n:null}function Ta(e){let t=e.trim();return/^```[\s\S]*```\s*$/.test(t)}function Ea(e){if(Ta(e))return null;let t=wa(e);return t?{fenced:`\`\`\`${t}\n${e}\n\`\`\``,lang:t}:null}function Da({original:e,refined:t,english:n,onDecision:r,autoSendDelayMs:i=0}){let a=W(e=>e.setRefinePanel),[o,s]=(0,z.useState)(i>0?Math.ceil(i/1e3):null),[c,l]=(0,z.useState)(t),[u,d]=(0,z.useState)(!1),f=(0,z.useRef)(null),p=(0,z.useRef)(null);(0,z.useEffect)(()=>{if(!(i<=0||u))return f.current=setInterval(()=>{s(e=>e===null||e<=1?(clearInterval(f.current),r(`refined`),null):e-1)},1e3),()=>{f.current&&clearInterval(f.current)}},[i,u,r]),(0,z.useEffect)(()=>{let e=e=>{if(!(e.target instanceof HTMLInputElement||e.target instanceof HTMLTextAreaElement))switch(e.key){case`Enter`:u||(e.preventDefault(),r(`refined`));break;case`e`:case`E`:u||(e.preventDefault(),r(`english`));break;case`o`:case`O`:u||(e.preventDefault(),r(`original`));break;case`t`:case`T`:u||(e.preventDefault(),d(!0));break;case`Escape`:e.preventDefault(),u?(d(!1),l(t)):(a(null),r(`original`));break}};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[u,r,t,a]),(0,z.useEffect)(()=>{u&&p.current&&p.current.querySelector(`textarea`)?.focus()},[u]);let m=e=>{f.current&&clearInterval(f.current),a(null),r(e)};return(0,G.jsxs)(`div`,{ref:p,className:`rounded-lg border bg-card text-card-foreground shadow-sm overflow-hidden animate-message`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between px-4 py-2 border-b bg-muted/30`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`span`,{className:`text-sm font-medium`,children:`✨ Refine Prompt`}),o!==null&&!u&&(0,G.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[`auto-send in `,o,`s`]})]}),(0,G.jsx)(`button`,{onClick:()=>m(`original`),className:`text-muted-foreground hover:text-foreground transition-colors`,title:`Cancel (Esc)`,children:(0,G.jsx)(F,{className:`h-4 w-4`})})]}),(0,G.jsx)(`div`,{className:`p-4 space-y-3`,children:u?(0,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsx)(`label`,{className:`text-xs text-muted-foreground font-medium`,children:`Edit refined prompt:`}),(0,G.jsx)(`textarea`,{value:c,onChange:e=>l(e.target.value),className:`w-full min-h-[80px] rounded-md border border-input bg-background px-3 py-2 text-sm resize-none focus:outline-none focus:ring-2 focus:ring-ring`,placeholder:`Edit the refined prompt...`}),(0,G.jsxs)(`div`,{className:`flex gap-2 justify-end`,children:[(0,G.jsx)(Q,{variant:`outline`,size:`sm`,onClick:()=>{d(!1),l(t)},children:`Cancel`}),(0,G.jsxs)(Q,{size:`sm`,onClick:()=>{c.trim()&&m(`edit`)},disabled:!c.trim(),children:[(0,G.jsx)(Ot,{className:`h-3 w-3 mr-1`}),`Use Edit`]})]})]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`div`,{className:`space-y-1`,children:[(0,G.jsx)(`div`,{className:`flex items-center gap-1 text-xs text-muted-foreground font-medium uppercase tracking-wider`,children:`Original`}),(0,G.jsx)(`div`,{className:`text-sm text-muted-foreground bg-muted/30 rounded-md px-3 py-2`,children:e.length>200?e.slice(0,200)+`...`:e})]}),(0,G.jsxs)(`div`,{className:`space-y-1`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-1 text-xs text-yellow-600 dark:text-yellow-400 font-medium uppercase tracking-wider`,children:[`Refined `,(0,G.jsx)(`span`,{className:`text-muted-foreground font-normal`,children:`(your language)`})]}),(0,G.jsx)(`div`,{className:Y(`text-sm bg-yellow-500/10 border border-yellow-500/20 rounded-md px-3 py-2 cursor-pointer`,`hover:bg-yellow-500/20 transition-colors`),onClick:()=>m(`refined`),title:`Click or press Enter to use this version`,children:t.length>300?t.slice(0,300)+`...`:t})]}),(0,G.jsxs)(`div`,{className:`space-y-1`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-1 text-xs text-blue-600 dark:text-blue-400 font-medium uppercase tracking-wider`,children:[(0,G.jsx)(Qt,{className:`h-3 w-3`}),`English`]}),(0,G.jsx)(`div`,{className:Y(`text-sm bg-blue-500/10 border border-blue-500/20 rounded-md px-3 py-2 cursor-pointer`,`hover:bg-blue-500/20 transition-colors`),onClick:()=>m(`english`),title:`Press e to use English version`,children:n.length>300?n.slice(0,300)+`...`:n})]})]})}),!u&&(0,G.jsxs)(`div`,{className:`flex items-center justify-between gap-2 px-4 py-3 border-t bg-muted/20`,children:[(0,G.jsxs)(`div`,{className:`flex gap-1 text-xs text-muted-foreground`,children:[(0,G.jsx)(`kbd`,{className:`px-1.5 py-0.5 rounded bg-muted border font-mono`,children:`Enter`}),(0,G.jsx)(`span`,{children:`refined`}),(0,G.jsx)(`kbd`,{className:`px-1.5 py-0.5 rounded bg-muted border font-mono ml-2`,children:`e`}),(0,G.jsx)(`span`,{children:`English`}),(0,G.jsx)(`kbd`,{className:`px-1.5 py-0.5 rounded bg-muted border font-mono ml-2`,children:`o`}),(0,G.jsx)(`span`,{children:`original`}),(0,G.jsx)(`kbd`,{className:`px-1.5 py-0.5 rounded bg-muted border font-mono ml-2`,children:`t`}),(0,G.jsx)(`span`,{children:`edit`})]}),(0,G.jsxs)(`div`,{className:`flex gap-2`,children:[(0,G.jsxs)(Q,{variant:`ghost`,size:`sm`,onClick:()=>m(`original`),className:`text-xs`,children:[(0,G.jsx)(F,{className:`h-3 w-3 mr-1`}),`Original`]}),(0,G.jsxs)(Q,{variant:`outline`,size:`sm`,onClick:()=>d(!0),className:`text-xs`,children:[(0,G.jsx)(xe,{className:`h-3 w-3 mr-1`}),`Edit`]}),(0,G.jsxs)(Q,{size:`sm`,onClick:()=>m(`refined`),className:`text-xs bg-yellow-600 hover:bg-yellow-700 text-white`,children:[(0,G.jsx)(Ot,{className:`h-3 w-3 mr-1`}),`Use Refined`]})]})]})]})}function Oa({onOpenBreakdown:e}={}){let{isLoading:t,setLoading:n,addMessage:r,clearMessages:i}=V(),a=V(e=>e.queue),o=V(e=>e.enqueue),s=V(e=>e.removeQueued),c=V(e=>e.clearQueue),{setCurrentView:l}=W(),u=W(e=>e.pushPrompt),d=W(e=>e.promptHistory),f=Z(),{sendMessage:p,sendAbort:m,client:h,refineModel:g}=f,_=W(e=>e.refineEnabled),v=W(e=>e.refinePanel),y=W(e=>e.toggleRefineEnabled),b=W(e=>e.setRefinePanel),x=U(e=>e.lastInputTokens),S=U(e=>e.maxContext),[C,w]=(0,z.useState)(``),[T,E]=(0,z.useState)(0),[D,O]=(0,z.useState)(-1),[k,A]=(0,z.useState)(null),[j,M]=(0,z.useState)(null),[ee,te]=(0,z.useState)(!1),N=(0,z.useRef)(null),ne=(0,z.useCallback)(t=>{let a=t.trim(),o=a.indexOf(` `),s=(o===-1?a:a.slice(0,o)).toLowerCase(),c=o===-1?``:a.slice(o+1).trim(),u=s;switch(u){case`/help`:return r({role:`assistant`,content:[`πŸ“– **Slash commands**`,``,...ha.map(e=>`β€’ \`${e.name}\`${e.aliases?.length?` (${e.aliases.map(e=>`\`${e}\``).join(`, `)})`:``} β€” ${e.description}`)].join(`
74
- `)}),!0;case`/clear`:return i(),h?.clearContext?.(),!0;case`/new`:return h?.newSession?.(),!0;case`/exit`:return h?.send?.({type:`webui.shutdown`,payload:{}}),r({role:`assistant`,content:`πŸ‘‹ Shutting down WebUI server…`}),!0;case`/compact`:case`/compact!`:return h?.compactContext?.(u===`/compact!`),!0;case`/repair`:return h?.repairContext?.(),!0;case`/debug`:case`/context`:return e?.(),!0;case`/tools`:return f.listTools(),!0;case`/memory`:return f.listMemory(),!0;case`/skill`:case`/skills`:return f.listSkills(),!0;case`/diag`:return f.getDiag(),!0;case`/stats`:return f.getStats(),!0;case`/save`:return f.saveSession(),!0;case`/load`:case`/resume`:return f.listSessions(50),l(`sessions`),!0;case`/agents`:return W.getState().setAgentsMonitorOpen(!0),!0;case`/brain`:{let[e,...t]=c.split(/\s+/).filter(Boolean),n=(e??``).toLowerCase();if(n===`risk`)h?.send?.({type:`brain.risk`,payload:{level:(t[0]??``).toLowerCase()}});else if(n===`ask`){let e=t.join(` `).trim();e?h?.send?.({type:`brain.ask`,payload:{question:e}}):r({role:`assistant`,content:"Usage: `/brain ask <question>`"})}else h?.send?.({type:`brain.status`});return!0}case`/plan`:return f.getPlan(),l(`chat`),W.getState().setDockSection(`work`),!0;case`/todos`:{if(c.toLowerCase()===`clear`)return h?.clearTodos?.(),!0;let e=U.getState().todos;if(e.length===0)return r({role:`assistant`,content:`βœ… **Todos** β€” _empty. Ask the agent to plan something and they'll show up here._`}),!0;let t=[`βœ… **Todos** (${e.filter(e=>e.status===`completed`).length}/${e.length} done)`,``];for(let n of e){let e=n.status===`completed`?`[x]`:n.status===`in_progress`?`[~]`:`[ ]`,r=n.status===`in_progress`&&n.activeForm?n.activeForm:n.content;t.push(`- ${e} ${r}`)}return t.push(``,"_Use `/todos clear` to wipe the list._"),r({role:`assistant`,content:t.join(`
75
- `)}),!0}case`/export`:return ua(),r({role:`assistant`,content:`πŸ“₯ Chat exported to your downloads folder.`}),!0;case`/interrupt`:case`/abort`:case`/stop`:case`/int`:return m(),n(!1),!0;case`/settings`:case`/model`:return l(`settings`),!0;case`/enhance`:{let e=!W.getState().refineEnabled;return y(),r({role:`assistant`,content:`Prompt refinement ${e?`enabled`:`disabled`}.`}),!0}case`/suggest`:case`/next-steps`:return se(`What are the next steps I should take? Be specific and actionable.`),!0;case`/next`:{let e=c.trim().toLowerCase();return!e||e===`list`||e===`ls`||e===`show`?ce():e===`clear`||e===`reset`?(r({role:`assistant`,content:`πŸ’‘ _Suggestion list cleared._`}),!0):le(c.trim())}default:return!1}},[r,i,h,m,n,l,y,f,e]),re=/πŸ’‘\s*Next steps?\s*\n+((?:\d+\.\s+.+\n?)+)/i;function ie(e){let t=re.exec(e);if(!t?.[1])return[];let n=[];for(let e of t[1].split(`
76
- `).filter(Boolean)){let t=/^(\d+)\.\s+(.+)$/.exec(e.trim());t&&n.push({index:Number.parseInt(t[1],10),text:t[2].trim()})}return n.slice(0,6)}function oe(){let e=V.getState().messages;for(let t=e.length-1;t>=0;t--){let n=e[t];if(n?.role===`assistant`&&n.content)return ie(n.content)}return[]}function se(e){if(t){o(e);return}r({role:`user`,content:e}),p(e)&&n(!0)}function ce(){let e=V.getState().messages,t=``;for(let n=e.length-1;n>=0;n--){let r=e[n];if(r?.role===`assistant`&&r.content){t=r.content;break}}let n=ie(t);if(n.length===0)return r({role:`assistant`,content:"πŸ’‘ _No next-step suggestions found. Use `/suggest` to generate some._"}),!0;let i=[`πŸ’‘ **Next steps**`,``];for(let e of n)i.push(`${e.index}. ${e.text}`);return i.push(``,"_Use `/next 1`, `/next 1 2 3` to execute._"),r({role:`assistant`,content:i.join(`
77
- `)}),!0}function le(e){let t=oe();if(t.length===0)return r({role:`assistant`,content:"πŸ’‘ _No suggestions available. Use `/suggest` first._"}),!0;let n=e.split(/[\s,]+/).filter(Boolean).map(e=>Number.parseInt(e,10)).filter(e=>!Number.isNaN(e)&&e>0);if(n.length===0)return r({role:`assistant`,content:`πŸ’‘ _No valid suggestion numbers._`}),!0;let i=n.filter(e=>e>t.length);if(i.length>0)return r({role:`assistant`,content:`πŸ’‘ _Invalid suggestion(s): ${i.join(`, `)}. Valid range: 1–${t.length}._`}),!0;for(let e of n){let n=t[e-1];n&&se(n.text)}return!0}let P=C.startsWith(`/`)&&!C.includes(` `)?_a(C):[];(0,z.useEffect)(()=>{T>=P.length&&E(0)},[P.length,T]);let ue=(0,z.useCallback)(()=>{let e=N.current;e&&(e.value=``,e.style.height=`auto`,e.style.height=`${Math.min(e.scrollHeight,200)}px`,t||e.focus())},[t]),de=(0,z.useCallback)(async e=>{if(e.preventDefault(),!C.trim())return;let i=C.trim();if(i.startsWith(`/`)&&ne(i)){u(i),w(``),O(-1),ue();return}if(w(``),O(-1),ue(),u(i),ue(),t){o(i);return}try{h?.isConnected?_&&g?(b({original:i,refined:i,english:i,resolve:e=>{}}),g(i)):(r({role:`user`,content:i}),n(!0),p(i)):console.warn(JSON.stringify({level:`warn`,event:`ws_send_failed`,reason:`not_connected`,timestamp:new Date().toISOString()}))}catch(e){console.warn(JSON.stringify({level:`warn`,event:`ws_send_error`,error:e instanceof Error?e.message:String(e),timestamp:new Date().toISOString()})),n(!1)}},[C,t,o,h,p,g,_,b,r,n,ne,u,ue]),fe=(0,z.useCallback)(()=>{m(),n(!1)},[m,n]),pe=(0,z.useCallback)(()=>{m(),n(!1);let e=V.getState().messages;for(let t=e.length-1;t>=0;t--){let n=R(e[t]);if(n.role===`user`&&n.content){w(n.content),requestAnimationFrame(()=>{let e=N.current;e&&(e.style.height=`auto`,e.style.height=`${Math.min(e.scrollHeight,200)}px`,e.focus(),e.setSelectionRange(n.content.length,n.content.length))});return}}},[m,n]),me=(0,z.useCallback)(e=>{if(P.length===0&&!k&&d.length>0){if(e.key===`ArrowUp`){let t=e.currentTarget,n=t.value.slice(0,t.selectionStart);if(D>=0||n.indexOf(`
78
- `)===-1){e.preventDefault();let t=Math.min(d.length-1,D+1);O(t);let n=d[t]??``;w(n),requestAnimationFrame(()=>{let e=N.current;e&&(e.style.height=`auto`,e.style.height=`${Math.min(e.scrollHeight,200)}px`,e.setSelectionRange(n.length,n.length))});return}}if(e.key===`ArrowDown`&&D>=0){e.preventDefault();let t=D-1;if(t<0)O(-1),w(``);else{O(t);let e=d[t]??``;w(e),requestAnimationFrame(()=>{let t=N.current;t&&(t.style.height=`auto`,t.style.height=`${Math.min(t.scrollHeight,200)}px`,t.setSelectionRange(e.length,e.length))})}return}}if(P.length>0){if(e.key===`ArrowDown`){e.preventDefault(),E(e=>(e+1)%P.length);return}if(e.key===`ArrowUp`){e.preventDefault(),E(e=>(e-1+P.length)%P.length);return}if(e.key===`Tab`){e.preventDefault();let t=P[T];t&&(w(t.name+` `),E(0));return}if(e.key===`Enter`&&!e.shiftKey){let t=P[T];if(t&&t.name!==C.toLowerCase().trim()){e.preventDefault(),w(``),ne(t.name);return}}if(e.key===`Escape`){e.preventDefault(),w(``);return}}e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),de(e))},[P,T,k,d,D,C,ne,de]),he=()=>{let e=N.current;e&&(e.style.height=`auto`,e.style.height=`${Math.min(e.scrollHeight,200)}px`)};return(0,G.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[j&&(0,G.jsxs)(`div`,{className:Y(`rounded-md border px-2.5 py-1.5 text-xs flex items-center justify-between gap-2 animate-message`,j.lang?`border-emerald-500/30 bg-emerald-500/5 text-emerald-700 dark:text-emerald-300`:`border-amber-500/30 bg-amber-500/5 text-amber-700 dark:text-amber-300`),children:[(0,G.jsx)(`span`,{children:j.lang?(0,G.jsxs)(G.Fragment,{children:[`Auto-fenced as`,` `,(0,G.jsx)(`span`,{className:`font-mono font-semibold`,children:j.lang}),` β€” `,(0,G.jsx)(`span`,{className:`font-mono tabular-nums`,children:j.chars.toLocaleString()}),` chars`,` (`,(0,G.jsx)(`span`,{className:`font-mono tabular-nums`,children:j.lines}),` lines)`]}):(0,G.jsxs)(G.Fragment,{children:[`Pasted`,` `,(0,G.jsx)(`span`,{className:`font-mono tabular-nums`,children:j.chars.toLocaleString()}),` chars`,` (`,(0,G.jsx)(`span`,{className:`font-mono tabular-nums`,children:j.lines}),` lines) β€” fenced code blocks render best with `,(0,G.jsx)(`span`,{className:`font-mono`,children:"```"}),`.`]})}),(0,G.jsxs)(`div`,{className:`flex items-center gap-1.5 shrink-0`,children:[j.undoFence&&(0,G.jsx)(`button`,{type:`button`,onClick:j.undoFence,className:`underline underline-offset-2 hover:opacity-80`,title:`Remove fences and restore raw text`,children:`Undo`}),(0,G.jsx)(`button`,{type:`button`,onClick:()=>M(null),className:`opacity-60 hover:opacity-100 shrink-0`,title:`Dismiss`,children:`Γ—`})]})]}),a.length>0&&(0,G.jsxs)(`div`,{className:`rounded-lg border bg-muted/30 p-2 text-xs`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between mb-1.5`,children:[(0,G.jsxs)(`span`,{className:`text-[10px] uppercase tracking-wider text-muted-foreground font-medium`,children:[`Queued (`,a.length,`)`]}),(0,G.jsx)(`button`,{type:`button`,onClick:c,className:`text-muted-foreground hover:text-destructive text-xs`,children:`Clear all`})]}),(0,G.jsx)(`ul`,{className:`space-y-1`,children:a.map((e,t)=>(0,G.jsxs)(`li`,{className:`flex items-start justify-between gap-2 rounded bg-background/60 border px-2 py-1`,children:[(0,G.jsx)(`span`,{className:`truncate flex-1 min-w-0`,children:e}),(0,G.jsx)(`button`,{type:`button`,onClick:()=>s(t),className:`text-muted-foreground hover:text-destructive shrink-0`,title:`Remove from queue`,children:`Γ—`})]},t))})]}),v&&(0,G.jsx)(Da,{original:v.original,refined:v.refined,english:v.english,onDecision:e=>{let{original:t,refined:i,english:a}=v,o=t;if(e===`refined`?o=i:e===`english`?o=a:e===`edit`&&(o=i),e===`edit`){w(i);return}b(null),h?.isConnected&&(r({role:`user`,content:o}),n(!0),p(o))}}),(0,G.jsxs)(`form`,{onSubmit:de,onDragEnter:e=>{!e.dataTransfer||!Array.from(e.dataTransfer.types).includes(`Files`)||(e.preventDefault(),te(!0))},onDragOver:e=>{!e.dataTransfer||!Array.from(e.dataTransfer.types).includes(`Files`)||(e.preventDefault(),e.dataTransfer.dropEffect=`copy`)},onDragLeave:e=>{e.currentTarget.contains(e.relatedTarget)||te(!1)},onDrop:e=>{if(!e.dataTransfer)return;let t=Array.from(e.dataTransfer.files??[]);if(t.length===0){te(!1);return}e.preventDefault(),te(!1);let n=N.current,r=n?.selectionStart??C.length,i=C.slice(0,r),a=C.slice(r),o=i.length>0&&!/\s$/.test(i)?` `:``,s=t.map(e=>`@${e.name}`),c=s.join(` `),l=a.length===0||!/^\s/.test(a)?` `:``,u=`${o}${c}${l}`;w(i+u+a);let d=i.length+o.length+s.slice(0,-1).join(` `).length+ +(s.length>1),f=t[t.length-1]?.name;requestAnimationFrame(()=>{if(n){let e=i.length+u.length-l.length;n.focus(),n.setSelectionRange(e,e),n.style.height=`auto`,n.style.height=`${Math.min(n.scrollHeight,200)}px`}A({start:d,query:f})})},className:Y(`flex items-end gap-2 relative rounded-lg transition-colors`,ee&&`ring-2 ring-primary ring-offset-2 ring-offset-background bg-primary/5`),children:[ee&&(0,G.jsxs)(`div`,{className:`absolute inset-0 z-20 flex items-center justify-center pointer-events-none rounded-lg bg-primary/10 text-primary text-sm font-medium`,children:[`Drop file`,`(s)`,` to attach as @-mention`]}),(0,G.jsxs)(`div`,{className:`relative flex-1`,children:[k&&(0,G.jsx)(ma,{query:k.query,onClose:()=>A(null),onPick:e=>{let t=C.slice(0,k.start),n=C.slice(k.start+1+k.query.length),r=`@${e} `;w(t+r+n),A(null),requestAnimationFrame(()=>{let e=N.current;if(e){let n=t.length+r.length;e.focus(),e.setSelectionRange(n,n),e.style.height=`auto`,e.style.height=`${Math.min(e.scrollHeight,200)}px`}})}}),!k&&P.length>0&&(()=>{let e={};P.forEach((t,n)=>{e[t.category]||(e[t.category]=[]),e[t.category]?.push({cmd:t,idx:n})});let t=ga.filter(t=>e[t]?.length);return(0,G.jsxs)(`div`,{className:`absolute bottom-full left-0 right-0 mb-2 rounded-lg border bg-popover shadow-md p-1 text-sm max-h-72 overflow-auto`,children:[(0,G.jsx)(`div`,{className:`px-3 py-1 text-[10px] uppercase tracking-wider text-muted-foreground border-b mb-1`,children:`↑/↓ select Β· Tab complete Β· Enter dispatch Β· Esc dismiss`}),t.map(t=>(0,G.jsxs)(`div`,{className:`mb-1`,children:[(0,G.jsx)(`div`,{className:`px-3 pt-1 pb-0.5 text-[10px] uppercase tracking-wider text-muted-foreground/70 font-semibold`,children:t}),e[t]?.map(({cmd:e,idx:t})=>(0,G.jsxs)(`button`,{type:`button`,onClick:()=>{w(``),ne(e.name)},onMouseEnter:()=>E(t),className:Y(`w-full text-left px-3 py-1.5 rounded transition-colors flex items-center gap-3`,t===T?`bg-accent text-accent-foreground`:`hover:bg-accent/40`),children:[(0,G.jsx)(`span`,{className:`font-mono shrink-0`,children:e.name}),e.aliases?.length?(0,G.jsxs)(`span`,{className:`text-xs text-muted-foreground/70 font-mono shrink-0`,children:[`(`,e.aliases.join(`, `),`)`]}):null,(0,G.jsxs)(`span`,{className:`text-xs text-muted-foreground truncate`,children:[`β€” `,e.description]})]},e.name))]},t))]})})(),(0,G.jsx)(`textarea`,{ref:N,value:C,onChange:e=>{let t=e.target.value;w(t),he(),D>=0&&O(-1),A(va(t,e.target.selectionStart??t.length))},onSelect:e=>{let t=e.currentTarget;A(va(t.value,t.selectionStart))},onKeyDown:me,onPaste:e=>{let t=e.clipboardData?.getData(`text`)??``;if(!t)return;let n=Ea(t);if(n){e.preventDefault();let r=N.current;if(!r)return;let i=r.selectionStart,a=r.selectionEnd,o=C.slice(0,i),s=C.slice(a),c=n.fenced;w(o+c+s);let l=t.split(`
79
- `).length;M({chars:t.length,lines:l,lang:n.lang,undoFence:()=>{w(o+t+s),M(null),requestAnimationFrame(()=>{r&&(r.focus(),r.style.height=`auto`,r.style.height=`${Math.min(r.scrollHeight,200)}px`)})}}),setTimeout(()=>M(null),6e3),requestAnimationFrame(()=>{r.style.height=`auto`,r.style.height=`${Math.min(r.scrollHeight,200)}px`;let e=o.length+c.length;r.setSelectionRange(e,e)});return}if(t.length>800){let e=t.split(`
80
- `).length;M({chars:t.length,lines:e}),setTimeout(()=>M(null),4e3)}},placeholder:h?.isConnected?t?`Agent is running β€” type to queue a follow-up…`:`Message the agent… (type / for commands, @ for files)`:`Connect to server first…`,className:Y(`flex min-h-[44px] w-full resize-none rounded-lg border border-input bg-background px-4 py-3 pr-12`,`text-sm ring-offset-background placeholder:text-muted-foreground`,`focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2`,`disabled:cursor-not-allowed disabled:opacity-50`,`scrollbar-thin`),rows:1,disabled:!h?.isConnected}),C.length>0&&(()=>{let e=C.length>=400,t=Math.ceil(C.length/4),n=`text-muted-foreground`,r;if(S>0&&e){let e=(x+t+64)/S*100;e>=100?(n=`text-red-600 dark:text-red-400 font-medium`,r=`Projected ${Math.round(e)}% of ${S.toLocaleString()} ctx β€” will likely error or compact.`):e>=85?(n=`text-amber-600 dark:text-amber-400 font-medium`,r=`Projected ${Math.round(e)}% of ${S.toLocaleString()} ctx β€” getting tight.`):r=`β‰ˆ ${t.toLocaleString()} tokens Β· projected ${Math.round(e)}% of ${S.toLocaleString()} ctx.`}else e&&(r=`β‰ˆ ${t.toLocaleString()} tokens (4-char heuristic)`);return(0,G.jsxs)(`span`,{className:Y(`absolute bottom-1.5 right-12 text-xs tabular-nums`,n),title:r,children:[C.length,e&&(0,G.jsxs)(`span`,{className:`ml-1 opacity-70`,children:[`Β· β‰ˆ`,t>=1e3?`${(t/1e3).toFixed(1)}k`:t,`t`]})]})})()]}),(0,G.jsx)(`div`,{className:`flex gap-1`,children:t?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Q,{type:`button`,size:`icon`,variant:`outline`,onClick:pe,className:`h-[44px] w-[44px] rounded-lg`,title:`Stop run and edit the last prompt (reuse + rewrite)`,children:(0,G.jsx)(ae,{className:`h-4 w-4`})}),(0,G.jsx)(Q,{type:`button`,size:`icon`,variant:`destructive`,onClick:fe,className:`h-[44px] w-[44px] rounded-lg`,title:`Abort the current run`,children:(0,G.jsx)(Ye,{className:`h-4 w-4 fill-current`})})]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Q,{type:`button`,size:`icon`,variant:_?`default`:`outline`,disabled:!h?.isConnected,onClick:y,className:Y(`h-[44px] w-[44px] rounded-lg transition-colors`,_&&`bg-yellow-500/20 hover:bg-yellow-500/30 text-yellow-600 dark:text-yellow-400 border-yellow-500/50`),title:_?`Refining enabled β€” click to disable`:`Refining disabled β€” click to enable`,children:(0,G.jsx)(Cn,{className:`h-4 w-4`})}),(0,G.jsx)(Q,{type:`submit`,size:`icon`,disabled:!C.trim()||!h?.isConnected,className:`h-[44px] w-[44px] rounded-lg`,children:(0,G.jsx)(De,{className:`h-4 w-4`})})]})})]})]})}function ka({open:e,onClose:t,className:n}){let[r,i]=(0,z.useState)([]),[a,s]=(0,z.useState)(!1),c=Z(),l=(0,z.useRef)(null);(0,z.useEffect)(()=>{if(!(!e||!c.client?.isConnected))return c.client.send?.({type:`session.checkpoints`}),l.current=c.client.on?.(`session.checkpoints`,e=>{let t=e?.payload;t?.checkpoints&&i(t.checkpoints)})??null,()=>{l.current?.()}},[e,c.client]);let u=(0,z.useCallback)(async e=>{s(!0),c.client.send?.({type:`session.rewind`,payload:{checkpointIndex:e}}),setTimeout(()=>{t(),s(!1)},800)},[c.client,t]);return e?(0,G.jsx)(`div`,{className:Y(`fixed inset-0 z-50 flex items-start justify-center pt-[10vh] bg-black/40 backdrop-blur-sm`,n),onClick:e=>{e.target===e.currentTarget&&t()},children:(0,G.jsxs)(`div`,{className:`w-full max-w-md rounded-xl border bg-card shadow-2xl max-h-[75vh] flex flex-col animate-in fade-in zoom-in-95`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between px-4 py-3 border-b shrink-0`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2.5`,children:[(0,G.jsx)(`span`,{className:`flex items-center justify-center w-8 h-8 rounded-lg bg-violet-500/10 text-violet-600 dark:text-violet-400`,children:(0,G.jsx)(ct,{className:`h-4 w-4`})}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`h2`,{className:`text-sm font-semibold`,children:`Session Checkpoints`}),(0,G.jsxs)(`span`,{className:`text-[10px] text-muted-foreground tabular-nums`,children:[r.length,` checkpoint`,r.length===1?``:`s`]})]})]}),(0,G.jsx)(`button`,{type:`button`,onClick:t,className:`p-1.5 rounded-md hover:bg-muted transition-colors`,children:(0,G.jsx)(F,{className:`h-4 w-4`})})]}),(0,G.jsx)(`div`,{className:`px-4 py-2.5 border-b bg-muted/20 text-[10px] text-muted-foreground leading-relaxed`,children:`Rewind the session to any checkpoint. Messages and file changes revert to that point β€” the LLM continues from there as if nothing happened after.`}),(0,G.jsx)(`div`,{className:`flex-1 overflow-y-auto`,children:r.length===0?(0,G.jsxs)(`div`,{className:`flex flex-col items-center justify-center py-16 gap-3 text-muted-foreground`,children:[(0,G.jsx)(N,{className:`h-10 w-10 opacity-15`}),(0,G.jsx)(`p`,{className:`text-sm font-medium`,children:`No checkpoints yet`}),(0,G.jsx)(`p`,{className:`text-xs text-center max-w-xs`,children:`Checkpoints are automatically created each time you send a message. Send a few messages and come back.`})]}):(0,G.jsx)(`div`,{className:`py-1`,children:[...r].reverse().map((e,t)=>{let n=t===0;return(0,G.jsxs)(`button`,{type:`button`,onClick:()=>u(e.index),disabled:a,className:Y(`w-full flex items-start gap-3 px-4 py-3 text-left transition-colors group`,n?`bg-primary/5 hover:bg-primary/10`:`hover:bg-accent/40`,a&&`opacity-50 pointer-events-none`),children:[(0,G.jsxs)(`div`,{className:`flex flex-col items-center mt-1.5`,children:[(0,G.jsx)(`div`,{className:Y(`w-2.5 h-2.5 rounded-full border-2 shrink-0 transition-colors`,n?`border-primary bg-primary/20 shadow-[0_0_0_3px_hsl(var(--primary)/0.25)]`:`border-muted-foreground/30 bg-background group-hover:border-primary/40`)}),t<r.length-1&&(0,G.jsx)(`div`,{className:`w-px flex-1 min-h-[20px] bg-border/50`})]}),(0,G.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsxs)(`span`,{className:`text-xs font-mono text-muted-foreground tabular-nums shrink-0`,children:[`#`,e.index]}),(0,G.jsx)(`span`,{className:`text-xs font-medium truncate`,children:e.label}),n&&(0,G.jsx)(`span`,{className:`text-[9px] px-1.5 py-0.5 rounded-full bg-primary/10 text-primary font-medium shrink-0`,children:`latest`})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2 mt-1 text-[10px] text-muted-foreground`,children:[(0,G.jsxs)(`span`,{className:`tabular-nums`,children:[e.messageCount,` msg`,e.messageCount===1?``:`s`]}),(0,G.jsx)(`span`,{className:`opacity-50`,children:`Β·`}),(0,G.jsxs)(`span`,{className:`tabular-nums`,children:[`~`,e.tokens.toLocaleString(),` tok`]}),(0,G.jsx)(`span`,{className:`opacity-50`,children:`Β·`}),(0,G.jsxs)(`span`,{className:`tabular-nums`,children:[`iter `,e.iteration]})]})]}),(0,G.jsx)(`span`,{className:`shrink-0 mt-1.5 opacity-0 group-hover:opacity-100 transition-opacity`,children:(0,G.jsx)(o,{className:`h-4 w-4 text-violet-500`})})]},e.index)})})}),(0,G.jsxs)(`div`,{className:`border-t px-4 py-2 text-[10px] text-muted-foreground text-center shrink-0`,children:[`Click any checkpoint to rewind Β·`,` `,(0,G.jsx)(`kbd`,{className:`px-1 py-0.5 rounded bg-muted font-mono text-[9px]`,children:`Esc`}),` to close`]})]})}):null}var Aa=[{id:`balanced`,name:`Balanced`,description:`Default rolling compaction`,thresholds:{warn:.6,soft:.75,hard:.9},preserveK:10,eliseThreshold:2e3}];function ja(){let e=U(e=>e.contextMode),n=U(e=>e.contextModes),{listContextModes:r,switchContextMode:i,client:a}=Z(),[o,s]=(0,z.useState)(!1),[c,l]=(0,z.useState)(!1),u=(0,z.useRef)(null),d=(0,z.useRef)(null);(0,z.useEffect)(()=>{o&&r()},[o,r]),(0,z.useEffect)(()=>{if(!o)return;let e=e=>{u.current?.contains(e.target)||s(!1)},t=e=>{e.key===`Escape`&&s(!1)};return document.addEventListener(`mousedown`,e),document.addEventListener(`keydown`,t),()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`keydown`,t)}},[o]),(0,z.useEffect)(()=>{if(!c)return;let e=e=>{d.current?.contains(e.target)||l(!1)};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[c]);let f=(0,z.useCallback)(e=>{a?.compactContext?.(e),l(!1),s(!1)},[a]),p=(0,z.useCallback)(()=>{a?.repairContext?.(),l(!1),s(!1)},[a]),m=n.length>0?n:Aa,h=m.find(t=>t.id===e)??R(m[0]);return(0,G.jsxs)(`div`,{ref:u,className:`relative shrink-0`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,G.jsxs)(`button`,{type:`button`,onClick:()=>s(e=>!e),className:Y(`flex items-center gap-1 px-2 py-0.5 rounded-full text-xs font-medium`,`bg-emerald-500/10 text-emerald-700 dark:text-emerald-300 hover:bg-emerald-500/15 transition-colors border border-transparent hover:border-emerald-500/30`),title:`Context-window mode`,children:[(0,G.jsx)(Ct,{className:`h-3 w-3`}),`ctx: `,(0,G.jsx)(`span`,{className:`font-mono`,children:e||h.id}),(0,G.jsx)(sn,{className:`h-3 w-3 opacity-60`})]}),(0,G.jsxs)(`div`,{ref:d,className:`relative`,children:[(0,G.jsx)(`button`,{type:`button`,onClick:()=>l(e=>!e),className:Y(`flex items-center justify-center h-5 w-5 rounded-full`,`text-muted-foreground hover:text-foreground hover:bg-accent/50 transition-colors`,c&&`bg-accent/50 text-foreground`),title:`Context operations`,children:(0,G.jsx)(t,{className:`h-3 w-3`})}),c&&(0,G.jsxs)(`div`,{className:`absolute top-full right-0 mt-1 w-52 rounded-md border bg-popover shadow-lg z-40 py-1`,children:[(0,G.jsx)(`div`,{className:`px-3 py-1.5 text-[10px] uppercase tracking-wider text-muted-foreground border-b`,children:`Context Operations`}),(0,G.jsxs)(`button`,{type:`button`,onClick:()=>f(!1),className:`w-full text-left px-3 py-2 hover:bg-accent/40 flex items-center gap-2`,children:[(0,G.jsx)(Ue,{className:`h-3.5 w-3.5 shrink-0 text-amber-500`}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`div`,{className:`text-xs`,children:`Compact Now`}),(0,G.jsx)(`div`,{className:`text-[10px] text-muted-foreground`,children:`Elide old tool output`})]})]}),(0,G.jsxs)(`button`,{type:`button`,onClick:()=>f(!0),className:`w-full text-left px-3 py-2 hover:bg-accent/40 flex items-center gap-2`,children:[(0,G.jsx)(Ue,{className:`h-3.5 w-3.5 shrink-0 text-red-400`}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`div`,{className:`text-xs`,children:`Compact Aggressive`}),(0,G.jsx)(`div`,{className:`text-[10px] text-muted-foreground`,children:`Maximum elision now`})]})]}),(0,G.jsxs)(`button`,{type:`button`,onClick:p,className:`w-full text-left px-3 py-2 hover:bg-accent/40 flex items-center gap-2`,children:[(0,G.jsx)(t,{className:`h-3.5 w-3.5 shrink-0 text-blue-400`}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`div`,{className:`text-xs`,children:`Repair Context`}),(0,G.jsx)(`div`,{className:`text-[10px] text-muted-foreground`,children:`Fix orphan tool-use blocks`})]})]}),(0,G.jsx)(`div`,{className:`border-t mt-1 pt-1 px-3 py-1.5`,children:(0,G.jsxs)(`button`,{type:`button`,onClick:()=>{document.dispatchEvent(new CustomEvent(`open:context-breakdown`)),l(!1),s(!1)},className:`w-full text-left px-3 py-2 hover:bg-accent/40 flex items-center gap-2`,children:[(0,G.jsx)(Ee,{className:`h-3.5 w-3.5 shrink-0 text-green-400`}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`div`,{className:`text-xs`,children:`Debug Context`}),(0,G.jsx)(`div`,{className:`text-[10px] text-muted-foreground`,children:`Size breakdown per section`})]})]})})]})]})]}),o&&(0,G.jsxs)(`div`,{className:`absolute top-full left-0 mt-1 w-80 rounded-md border bg-popover shadow-lg z-30 py-1`,children:[(0,G.jsx)(`div`,{className:`px-3 py-1.5 text-[10px] uppercase tracking-wider text-muted-foreground border-b`,children:`Context Window`}),m.map(t=>(0,G.jsxs)(`button`,{type:`button`,onClick:()=>{i(t.id),s(!1)},className:Y(`w-full text-left px-3 py-2 hover:bg-accent/40 flex items-start gap-2`,t.id===e&&`bg-accent/30`),children:[(0,G.jsx)(Ot,{className:Y(`h-3.5 w-3.5 mt-0.5 shrink-0`,t.id===e?`opacity-100 text-primary`:`opacity-0`)}),(0,G.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,G.jsx)(`span`,{className:`text-xs font-mono`,children:t.id}),t.thresholds?.warn!==void 0&&(0,G.jsxs)(`span`,{className:`text-[10px] text-muted-foreground tabular-nums`,children:[Math.round(t.thresholds.warn*100),`/`,Math.round(t.thresholds.soft*100),`/`,Math.round(t.thresholds.hard*100),`%`]})]}),(0,G.jsx)(`div`,{className:`text-[11px] text-muted-foreground leading-snug`,children:t.description}),(t.preserveK||t.eliseThreshold)&&(0,G.jsxs)(`div`,{className:`mt-1 text-[10px] text-muted-foreground/80`,children:[`keep `,t.preserveK??`-`,` recent Β· elide `,t.eliseThreshold??`-`,`+ tokens`]})]})]},t.id))]})]})}function $(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(e>=1e4?0:1)}k`:String(e)}var Ma=e=>{let t=new Date(e);return`${t.getFullYear()}-${t.getMonth()}-${t.getDate()}`};function Na(e,t){let n=new Date(e),r=new Date(t),i=new Date(t-864e5);return Ma(e)===Ma(r.getTime())?`Today`:Ma(e)===Ma(i.getTime())?`Yesterday`:n.toLocaleDateString(void 0,{weekday:`short`,month:`short`,day:`numeric`,year:n.getFullYear()===r.getFullYear()?void 0:`numeric`})}function Pa(e,t=Date.now()){let n=[];for(let t=0;t<e.length;t++){let r=R(e[t]);if(r.role===`tool`){let e=n[n.length-1];e&&e.kind===`tools`?e.tools.push(r):n.push({kind:`tools`,tools:[r],key:r.id})}else{let i=e[t-1];n.push({kind:`msg`,message:r,isFirst:!i||i.role!==r.role})}}let r=[];for(let e of n){if(e.kind===`msg`&&e.message.role===`user`){r.push({kind:`user`,message:e.message,key:e.message.id});continue}let t=r[r.length-1];if(t&&t.kind===`agent`)t.items.push(e);else{let t=e.kind===`msg`?e.message.id:e.key;r.push({kind:`agent`,items:[e],key:t})}}let i=e=>{if(e.kind===`user`)return e.message.timestamp;let t=R(e.items[0]);return t.kind===`msg`?t.message.timestamp:t.tools[0]?.timestamp??0},a=[],o=null;for(let e=0;e<r.length;e++){let n=R(r[e]),s=i(n),c=Ma(s);if(c!==o&&(a.push({kind:`day`,key:`day-${c}-${e}`,label:Na(s,t)}),o=c),n.kind===`user`){a.push({kind:`user`,key:n.key,message:n.message});continue}let l=e===r.length-1,u=n.items.map((e,t)=>{let r=t>0;return e.kind===`msg`?{kind:`msg`,key:e.message.id,message:e.message,isFirst:!r&&e.isFirst,isContinuation:r}:{kind:`tools`,key:e.key,tools:e.tools,isContinuation:r,isLastGroup:t===n.items.length-1,hasRunningTool:e.tools.some(e=>e.toolResult===void 0)}});a.push({kind:`agent`,key:n.key,items:u,isLastTurn:l})}return a}var Fa={0:``,1:`▏`,2:`β–Ž`,3:`▍`,4:`β–Œ`,5:`β–‹`,6:`β–Š`,7:`β–‰`,8:`β–ˆ`};function Ia(e){return e>=75?`bg-destructive`:e>=60?`bg-[hsl(var(--warning))]`:`bg-[hsl(var(--success))]`}function La(e){return e>=75?`text-destructive`:e>=60?`text-[hsl(var(--warning))]`:`text-[hsl(var(--success))]`}function Ra({pct:e,tokens:t,maxTokens:n,segments:r=10,showTokens:i=!0,className:a,onClick:o}){let s=Math.round(Math.max(0,Math.min(200,e))/100*r*8),c=[],l=s;for(let e=0;e<r;e++){let e=Math.min(8,l);c.push({fill:e}),l-=e}let u=e>=100?`${Math.round(e)}%+`:`${Math.round(e)}%`,d=i&&t!==void 0&&n!==void 0&&n>0?` ${$(t)}/${$(n)}`:``;return(0,G.jsxs)(`span`,{className:Y(`inline-flex items-center gap-1 px-1.5 py-0.5 rounded-full text-[11px] font-mono font-medium shrink-0`,o&&`cursor-pointer hover:ring-1 hover:ring-ring transition-shadow`,La(e),e>=75?`bg-red-500/10`:e>=60?`bg-amber-500/10`:`bg-emerald-500/10`,a),title:(t!==void 0&&n!==void 0?`Context window: ${t.toLocaleString()} / ${n.toLocaleString()} tokens (${u})`:`Context window: ${u}`)+(o?` β€” click for breakdown`:``),onClick:o?e=>{e.stopPropagation(),o()}:void 0,onKeyDown:o?e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),e.stopPropagation(),o())}:void 0,role:o?`button`:void 0,tabIndex:o?0:void 0,children:[(0,G.jsx)(`span`,{className:`inline-flex font-mono text-[10px] leading-none tracking-tight`,children:c.map((t,n)=>(0,G.jsx)(`span`,{className:Y(`tabular-nums w-[0.55em] text-center`,t.fill>0?La(e):`text-muted-foreground/30`),children:Fa[t.fill]??` `},n))}),(0,G.jsx)(`span`,{children:u}),d&&(0,G.jsx)(`span`,{className:`tabular-nums`,children:d})]})}function za({pct:e,tokens:t,maxTokens:n,showTokens:r=!0,className:i,onClick:a}){let o=Math.max(0,Math.min(200,e)),s=e>100?`${Math.round(e)}%+`:`${Math.round(e)}%`,c=r&&t!==void 0&&n!==void 0&&n>0?` ${$(t)}/${$(n)}`:``;return(0,G.jsxs)(`span`,{className:Y(`inline-flex items-center gap-1.5`,a&&`cursor-pointer hover:opacity-80 transition-opacity`,i),title:(t!==void 0&&n!==void 0?`Context window: ${t.toLocaleString()} / ${n.toLocaleString()} tokens (${s})`:`Context window: ${s}`)+(a?` β€” click for breakdown`:``),onClick:a?e=>{e.stopPropagation(),a()}:void 0,onKeyDown:a?e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),e.stopPropagation(),a())}:void 0,role:a?`button`:void 0,tabIndex:a?0:void 0,children:[(0,G.jsx)(`span`,{className:`h-1.5 w-16 overflow-hidden rounded-full bg-muted shrink-0`,children:(0,G.jsx)(`span`,{className:Y(`h-full rounded-full transition-all duration-300`,Ia(e)),style:{width:`${Math.max(2,o)}%`}})}),(0,G.jsx)(`span`,{className:Y(`text-[11px] font-mono tabular-nums font-medium`,La(e)),children:s}),c&&(0,G.jsx)(`span`,{className:`text-[10px] text-muted-foreground tabular-nums`,children:c})]})}function Ba({open:e,onClose:n}){let r=H(e=>e.wsUrl),{lastInputTokens:i,maxContext:a}=U(),[o,s]=(0,z.useState)(null),[c,l]=(0,z.useState)(!1),[u,d]=(0,z.useState)(null);if((0,z.useEffect)(()=>{if(!e){s(null),d(null);return}l(!0),d(null),s(null);let t=B(r);if(!t?.send){d(`WebSocket not connected`),l(!1);return}t.send({type:`context.debug`});let n=t.on(`context.debug`,e=>{e.type===`context.debug`&&(s(e.payload),l(!1))}),i=setTimeout(()=>{c&&(l(!1),d(`No debug data received. The server may not support context debugging.`))},5e3);return()=>{clearTimeout(i),n()}},[e,r]),(0,z.useEffect)(()=>{if(!e)return;let t=e=>{e.key===`Escape`&&n()};return document.addEventListener(`keydown`,t),()=>document.removeEventListener(`keydown`,t)},[e,n]),!e)return null;let f=a>0&&i>0?Math.min(100,Math.round(i/a*100)):0;return(0,G.jsx)(`div`,{className:`fixed inset-0 z-50 flex items-start justify-center pt-[10vh] bg-black/40 backdrop-blur-sm`,children:(0,G.jsxs)(`div`,{className:`w-full max-w-2xl max-h-[80vh] overflow-y-auto rounded-xl border bg-card shadow-2xl`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between px-4 py-3 border-b sticky top-0 bg-card z-10`,children:[(0,G.jsxs)(`h3`,{className:`text-sm font-semibold flex items-center gap-2`,children:[(0,G.jsx)(dn,{className:`h-4 w-4 text-[hsl(var(--warning))]`}),`Context Breakdown`]}),(0,G.jsx)(`button`,{type:`button`,onClick:n,className:`p-1 rounded-md hover:bg-muted transition-colors`,children:(0,G.jsx)(F,{className:`h-4 w-4`})})]}),(0,G.jsxs)(`div`,{className:`p-4 space-y-4`,children:[(0,G.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,G.jsxs)(`div`,{className:`rounded bg-muted/30 px-3 py-2`,children:[(0,G.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:`Window Usage`}),(0,G.jsxs)(`span`,{className:`block text-sm font-mono font-medium`,children:[$(i),` / `,$(a),` (`,f,`%)`]})]}),(0,G.jsxs)(`div`,{className:`rounded bg-muted/30 px-3 py-2`,children:[(0,G.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:`Context Mode`}),(0,G.jsx)(`span`,{className:`block text-sm font-mono font-medium`,children:o?.mode??`β€”`})]})]}),c?(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-muted-foreground py-4`,children:[(0,G.jsx)(Mt,{className:`h-4 w-4 animate-spin`}),`Fetching context breakdown…`]}):u?(0,G.jsx)(`div`,{className:`rounded-md bg-destructive/10 border border-destructive/20 p-3 text-sm text-destructive`,children:u}):o?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`div`,{className:`grid grid-cols-3 gap-2`,children:[(0,G.jsxs)(`div`,{className:`rounded bg-muted/30 px-3 py-2`,children:[(0,G.jsxs)(`span`,{className:`text-[10px] text-muted-foreground flex items-center gap-1`,children:[(0,G.jsx)(Tn,{className:`h-3 w-3`}),`System Prompt`]}),(0,G.jsx)(`span`,{className:`block text-sm font-mono font-medium`,children:$(o.systemPrompt)})]}),(0,G.jsxs)(`div`,{className:`rounded bg-muted/30 px-3 py-2`,children:[(0,G.jsxs)(`span`,{className:`text-[10px] text-muted-foreground flex items-center gap-1`,children:[(0,G.jsx)(t,{className:`h-3 w-3`}),`Tools`]}),(0,G.jsxs)(`span`,{className:`block text-sm font-mono font-medium`,children:[$(o.tools.total),` (`,o.tools.count,`)`]})]}),(0,G.jsxs)(`div`,{className:`rounded bg-muted/30 px-3 py-2`,children:[(0,G.jsxs)(`span`,{className:`text-[10px] text-muted-foreground flex items-center gap-1`,children:[(0,G.jsx)(He,{className:`h-3 w-3`}),`Messages`]}),(0,G.jsxs)(`span`,{className:`block text-sm font-mono font-medium`,children:[$(o.messages.total),` (`,o.messages.count,`)`]})]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`span`,{className:`text-[10px] uppercase tracking-wider text-muted-foreground font-semibold`,children:`Token Allocation`}),(0,G.jsx)(`div`,{className:`mt-1.5 h-3 w-full overflow-hidden rounded-full bg-muted flex`,children:o.total>0&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`span`,{className:`h-full bg-blue-500/70 transition-all`,style:{width:`${o.systemPrompt/o.total*100}%`},title:`System: ${$(o.systemPrompt)}`}),(0,G.jsx)(`span`,{className:`h-full bg-amber-500/70 transition-all`,style:{width:`${o.tools.total/o.total*100}%`},title:`Tools: ${$(o.tools.total)}`}),(0,G.jsx)(`span`,{className:`h-full bg-emerald-500/70 transition-all`,style:{width:`${o.messages.total/o.total*100}%`},title:`Messages: ${$(o.messages.total)}`})]})}),(0,G.jsxs)(`div`,{className:`flex gap-3 mt-1 text-[10px] text-muted-foreground`,children:[(0,G.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,G.jsx)(`span`,{className:`w-2 h-2 rounded-full bg-blue-500/70`}),` System`]}),(0,G.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,G.jsx)(`span`,{className:`w-2 h-2 rounded-full bg-amber-500/70`}),` Tools`]}),(0,G.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,G.jsx)(`span`,{className:`w-2 h-2 rounded-full bg-emerald-500/70`}),` Messages`]})]})]}),o.tools.breakdown.length>0&&(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`span`,{className:`text-[10px] uppercase tracking-wider text-muted-foreground font-semibold`,children:`Tool Breakdown`}),(0,G.jsx)(`div`,{className:`mt-1 space-y-0.5`,children:o.tools.breakdown.map(e=>(0,G.jsxs)(`div`,{className:`flex items-center justify-between text-xs py-0.5`,children:[(0,G.jsx)(`span`,{className:`font-mono`,children:e.name}),(0,G.jsxs)(`span`,{className:`tabular-nums text-muted-foreground`,children:[e.tokens.toLocaleString(),` tok`]})]},e.name))})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`span`,{className:`text-[10px] uppercase tracking-wider text-muted-foreground font-semibold`,children:[`Messages (`,o.messages.count,`) β€” `,$(o.messages.total),` tok`]}),(0,G.jsx)(`div`,{className:`mt-1 space-y-0.5 max-h-40 overflow-y-auto`,children:o.messages.breakdown.slice(0,20).map(e=>(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-xs py-0.5`,children:[(0,G.jsx)(`span`,{className:`text-muted-foreground font-mono w-6 text-right`,children:e.index}),(0,G.jsx)(`span`,{className:`text-muted-foreground font-mono w-14`,children:e.role}),(0,G.jsxs)(`span`,{className:`tabular-nums text-muted-foreground w-14`,children:[e.tokens.toLocaleString(),` tok`]}),(0,G.jsx)(`span`,{className:`text-muted-foreground/70 truncate flex-1`,children:e.preview.slice(0,80)})]},e.index))})]})]}):null]})]})})}function Va(){let e=U(e=>e.cost),t=U(e=>e.inputCost),n=U(e=>e.outputCost),r=U(e=>e.cacheReadCost),i=V(e=>e.messages),[a,o]=(0,z.useState)(!1),s=(0,z.useRef)(null);(0,z.useEffect)(()=>{if(!a)return;let e=e=>{s.current?.contains(e.target)||o(!1)},t=e=>{e.key===`Escape`&&o(!1)};return document.addEventListener(`mousedown`,e),document.addEventListener(`keydown`,t),()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`keydown`,t)}},[a]);let c=(()=>{let e=[];for(let t of i)t.role===`assistant`&&t.runSummary&&t.runSummary.costDelta>0&&e.push({id:t.id,preview:t.content.slice(0,80).replace(/\s+/g,` `).trim()||`(empty)`,cost:t.runSummary.costDelta,tools:t.runSummary.tools,ms:t.runSummary.durationMs,ts:t.timestamp});return e.sort((e,t)=>t.cost-e.cost),e.slice(0,5)})(),l=e=>e>=.01?`$${e.toFixed(4)}`:e>0?`$${e.toFixed(6).replace(/0+$/,``).replace(/\.$/,``)}`:`$0`,u=t>0||n>0;return(0,G.jsxs)(`div`,{ref:s,className:`relative inline-block`,children:[(0,G.jsxs)(`button`,{type:`button`,onClick:()=>o(e=>!e),className:Y(`font-medium text-green-600 dark:text-green-400 hover:underline tabular-nums`),title:`Click for per-turn cost breakdown`,children:[`$`,e.toFixed(4)]}),a&&(0,G.jsxs)(`div`,{className:`absolute right-0 top-full mt-1 z-30 w-80 rounded-md border bg-popover shadow-lg p-3 text-foreground`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,G.jsx)(`span`,{className:`text-xs uppercase tracking-wider text-muted-foreground font-medium`,children:`Cost breakdown`}),(0,G.jsx)(`span`,{className:`font-mono tabular-nums text-sm font-semibold text-green-600 dark:text-green-400`,children:l(e)})]}),u?(0,G.jsxs)(`div`,{className:`text-[11px] text-muted-foreground font-mono mb-3 border-b pb-2`,children:[(0,G.jsxs)(`div`,{className:`flex justify-between`,children:[(0,G.jsx)(`span`,{children:`input /1M`}),(0,G.jsxs)(`span`,{children:[`$`,t.toFixed(2)]})]}),(0,G.jsxs)(`div`,{className:`flex justify-between`,children:[(0,G.jsx)(`span`,{children:`output /1M`}),(0,G.jsxs)(`span`,{children:[`$`,n.toFixed(2)]})]}),r>0&&(0,G.jsxs)(`div`,{className:`flex justify-between`,children:[(0,G.jsx)(`span`,{children:`cache /1M`}),(0,G.jsxs)(`span`,{children:[`$`,r.toFixed(2)]})]})]}):(0,G.jsx)(`div`,{className:`text-[11px] text-muted-foreground italic mb-3 border-b pb-2`,children:`No pricing for the current model β€” cost figures are zero.`}),c.length===0?(0,G.jsx)(`div`,{className:`text-xs text-muted-foreground italic`,children:`No completed turns yet. Run a prompt to see per-turn cost here.`}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`div`,{className:`text-[10px] uppercase tracking-wider text-muted-foreground/80 mb-1`,children:[`Top `,c.length,` expensive turn`,c.length===1?``:`s`]}),(0,G.jsx)(`ul`,{className:`space-y-1`,children:c.map(e=>(0,G.jsx)(`li`,{children:(0,G.jsxs)(`button`,{type:`button`,onClick:()=>{let t=document.querySelector(`[data-message-id="${e.id}"]`);t&&t.scrollIntoView({behavior:`smooth`,block:`center`}),o(!1)},className:`w-full text-left rounded px-2 py-1.5 hover:bg-accent/40 transition-colors`,children:[(0,G.jsxs)(`div`,{className:`flex items-baseline justify-between gap-2`,children:[(0,G.jsx)(`span`,{className:`text-xs truncate`,children:e.preview}),(0,G.jsx)(`span`,{className:`text-xs font-mono tabular-nums text-green-600 dark:text-green-400 shrink-0`,children:l(e.cost)})]}),(0,G.jsxs)(`div`,{className:`text-[10px] text-muted-foreground font-mono mt-0.5`,children:[e.tools,` tool`,e.tools===1?``:`s`,` Β· `,(e.ms/1e3).toFixed(1),`s`]})]})},e.id))})]})]})]})}var Ha=[`path`,`file_path`,`pattern`,`command`,`cmd`,`url`,`query`,`description`,`content`];function Ua(e,t){if(t==null)return``;if(typeof t!=`object`)return Wa(String(t),120);let n=t,r=(e??``).toLowerCase();if(/^todo(_?write)?$|^todos$/i.test(r)||Array.isArray(n.todos)){let e=n.todos??[];if(Array.isArray(e)){let t=e.filter(e=>e.status===`completed`).length,n=e.filter(e=>e.status===`in_progress`).length,r=[`${e.length} todo${e.length===1?``:`s`}`];return t>0&&r.push(`${t} done`),n>0&&r.push(`${n} in-progress`),r.join(` Β· `)}}if(/batch|parallel/.test(r)||Array.isArray(n.tool_uses)||Array.isArray(n.calls)){let e=n.tool_uses??n.calls??n.batch;if(Array.isArray(e)){let t=new Set;for(let n of e)n&&typeof n==`object`&&`name`in n&&t.add(String(n.name));let n=[...t].slice(0,3).join(`, `),r=t.size>3?` +${t.size-3}`:``;return`${e.length} sub-tool${e.length===1?``:`s`}${n?` Β· ${n}${r}`:``}`}}if(/^(edit|str_replace|edit_file|patch)$/.test(r)){let e=Ga(n),t=typeof n.old_string==`string`?n.old_string:``,r=typeof n.new_string==`string`?n.new_string:``,i=t?t.split(`
81
- `).length:0,a=r?r.split(`
82
- `).length:0;return`edit ${e||`(file)`}${i||a?` (${i} β†’ ${a} lines)`:``}`}if(/^(write|write_file|create_file|new_file)$/.test(r)){let e=Ga(n),t=typeof n.content==`string`?n.content:``,r=t?t.split(`
83
- `).length:0;return`write ${e||`(file)`}${r?` Β· ${r} lines`:``}`}if(/^(bash|shell|exec|run|run_command|run_shell)$/.test(r)){let e=n.command??n.cmd??n.script;if(typeof e==`string`)return`$ ${Wa(e,110)}`}if(/^(fetch|http|web|webfetch|curl|request)$/.test(r)){let e=n.url;if(typeof e==`string`)return`${(n.method??`GET`).toUpperCase()} ${Wa(e,100)}`}if(/^(grep|search|ripgrep)$/.test(r)){let e=n.pattern,t=n.path??n.glob??n.type;if(typeof e==`string`)return t?`grep ${Wa(e,60)} in ${t}`:`grep ${Wa(e,100)}`}if(/^(glob|find)$/.test(r)){let e=n.pattern??n.glob;if(typeof e==`string`)return`glob ${Wa(e,100)}`}if(/^(read|read_file|cat)$/.test(r)){let e=Ga(n),t=n.offset,r=n.limit;if(e&&(typeof t==`number`||typeof r==`number`)){let n=t??0;return`read ${e} (${n}…${typeof r==`number`?n+r:``})`}if(e)return`read ${e}`}for(let e of Ha){let t=n[e];if(typeof t==`string`&&t.length>0)return`${e}: ${Wa(t,100)}`}return Wa(Ka(t),120)}function Wa(e,t){return e.length>t?`${e.slice(0,t-1)}…`:e}function Ga(e){let t=e.file_path??e.path??e.filepath;return typeof t==`string`?t:``}function Ka(e){try{return JSON.stringify(e)}catch{return String(e)}}var qa=(0,z.memo)(function({oldText:e,newText:t,caption:n}){let r=(0,z.useMemo)(()=>Ya(e,t),[e,t]);if(r===null)return(0,G.jsx)(`div`,{className:`text-xs text-muted-foreground italic px-3 py-2`,children:`Diff omitted (file too large to render inline).`});let i=r.filter(e=>e.kind===`add`).length,a=r.filter(e=>e.kind===`del`).length;return(0,G.jsxs)(`div`,{className:`rounded-lg border bg-background/40 overflow-hidden text-xs`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between px-3 py-1.5 border-b bg-muted/40`,children:[(0,G.jsx)(`span`,{className:`font-mono text-muted-foreground truncate`,children:n??`diff`}),(0,G.jsxs)(`span`,{className:`font-mono shrink-0`,children:[(0,G.jsxs)(`span`,{className:`text-emerald-600 dark:text-emerald-400`,children:[`+`,i]}),(0,G.jsx)(`span`,{className:`text-muted-foreground mx-1 opacity-50`,children:`Β·`}),(0,G.jsxs)(`span`,{className:`text-rose-600 dark:text-rose-400`,children:[`-`,a]})]})]}),(0,G.jsx)(`div`,{className:`font-mono leading-relaxed max-h-96 overflow-auto`,children:r.map((e,t)=>(0,G.jsxs)(`div`,{className:Y(`flex`,e.kind===`add`&&`bg-emerald-500/10`,e.kind===`del`&&`bg-rose-500/10`),children:[(0,G.jsx)(`span`,{className:Y(`w-6 shrink-0 text-center select-none`,e.kind===`add`&&`text-emerald-600 dark:text-emerald-400`,e.kind===`del`&&`text-rose-600 dark:text-rose-400`,e.kind===`ctx`&&`text-muted-foreground/40`),children:e.kind===`add`?`+`:e.kind===`del`?`-`:` `}),(0,G.jsx)(`pre`,{className:Y(`whitespace-pre-wrap break-all flex-1 px-2`,e.kind===`ctx`&&`text-muted-foreground/70`),children:e.text||`\xA0`})]},t))})]})}),Ja=5e3;function Ya(e,t){let n=e.split(`
84
- `),r=t.split(`
85
- `);if(n.length>Ja||r.length>Ja)return null;let i=n.length,a=r.length,o=Array.from({length:i+1},()=>Array(a+1).fill(0));for(let e=i-1;e>=0;e--)for(let t=a-1;t>=0;t--)n[e]===r[t]?R(o[e])[t]=R(o[e+1]?.[t+1])+1:R(o[e])[t]=Math.max(R(o[e+1]?.[t]),R(o[e]?.[t+1]));let s=[],c=0,l=0;for(;c<i&&l<a;)n[c]===r[l]?(s.push({kind:`ctx`,text:R(n[c])}),c++,l++):R(o[c+1]?.[l])>=R(o[c]?.[l+1])?(s.push({kind:`del`,text:R(n[c])}),c++):(s.push({kind:`add`,text:R(r[l])}),l++);for(;c<i;)s.push({kind:`del`,text:R(n[c++])});for(;l<a;)s.push({kind:`add`,text:R(r[l++])});return s}function Xa(e,t){if(!e||typeof t!=`object`||!t)return null;let n=t,r=String(n.file_path??n.path??``);switch(e){case`edit`:case`str_replace`:case`edit_file`:{let e=typeof n.old_string==`string`?n.old_string:``,t=typeof n.new_string==`string`?n.new_string:``;return!e&&!t?null:{oldText:e,newText:t,caption:`edit ${r}`}}case`write`:case`write_file`:case`create_file`:return{oldText:``,newText:typeof n.content==`string`?n.content:``,caption:`write ${r} (new)`};default:return null}}var Za=25,Qa=12;function $a({text:e,isError:t,className:r,wrapClass:i,showLineNumbers:a}){let o=(0,z.useMemo)(()=>e.split(`
86
- `),[e]),s=o.length>Za,[c,l]=(0,z.useState)(!s),u=c?e:o.slice(0,Qa).join(`
87
- `),d=!!a&&s&&c;return(0,G.jsxs)(`div`,{className:Y(`rounded-md border bg-background/40 overflow-hidden`,r),children:[d?(0,G.jsxs)(`div`,{className:`flex max-h-96 overflow-auto`,children:[(0,G.jsx)(`pre`,{"aria-hidden":!0,className:`text-xs font-mono leading-[1.4] py-2 pl-2 pr-2 text-muted-foreground/50 select-none border-r border-border/40 bg-muted/20 tabular-nums text-right whitespace-pre shrink-0`,children:o.map((e,t)=>`${t+1}`).join(`
88
- `)}),(0,G.jsx)(`pre`,{className:Y(`text-xs font-mono leading-[1.4] py-2 px-2 flex-1 whitespace-pre`,t?`text-destructive`:`text-foreground`),children:u})]}):(0,G.jsx)(`pre`,{className:Y(`text-xs font-mono p-2 max-h-96 overflow-auto`,i,t?`text-destructive`:`text-foreground`),children:u}),s&&(0,G.jsx)(`button`,{type:`button`,onClick:()=>l(e=>!e),className:`w-full flex items-center justify-center gap-1 px-2 py-1 border-t bg-muted/30 text-[11px] text-muted-foreground hover:text-foreground transition-colors`,children:c?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(_e,{className:`h-3 w-3`}),`Collapse to first `,Qa,` lines`]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(n,{className:`h-3 w-3`}),`Show all `,o.length,` lines (`,o.length-Qa,` more)`]})})]})}var eo=(0,z.memo)(function({toolName:e,result:t,isError:n,className:r}){let i=(0,z.useMemo)(()=>to(e,t),[e,t]);return i.kind===`json`?(0,G.jsx)(no,{value:i.value,isError:n,className:r}):i.kind===`numbered`?(0,G.jsx)($a,{text:t,isError:n,className:r,wrapClass:`whitespace-pre`}):i.kind===`bash`?(0,G.jsxs)(`div`,{className:Y(`rounded-md border bg-background/40 overflow-hidden`,r),children:[i.stdout&&(0,G.jsx)($a,{text:i.stdout,isError:n,className:`border-0 rounded-none bg-transparent`,wrapClass:`whitespace-pre-wrap break-all`,showLineNumbers:!0}),(i.exitCode!==void 0||i.duration)&&(0,G.jsxs)(`div`,{className:Y(`flex items-center gap-3 text-[11px] px-2 py-1 border-t bg-muted/30 tabular-nums`,i.exitCode&&i.exitCode!==0?`text-destructive`:`text-muted-foreground`),children:[i.exitCode!==void 0&&(0,G.jsxs)(`span`,{children:[`exit code: `,(0,G.jsx)(`span`,{className:`font-mono`,children:i.exitCode})]}),i.duration&&(0,G.jsx)(`span`,{children:i.duration})]})]}):(0,G.jsx)($a,{text:t,isError:n,className:r,wrapClass:`whitespace-pre-wrap break-all`,showLineNumbers:!0})});function to(e,t){let n=t.trim();if(/^\s*\d+β†’/m.test(t.slice(0,200)))return{kind:`numbered`};if(n.startsWith(`{`)&&n.endsWith(`}`)||n.startsWith(`[`)&&n.endsWith(`]`))try{let e=JSON.parse(n);if(typeof e==`object`&&e)return{kind:`json`,value:e}}catch{}let r=!!e&&/^(bash|shell|exec|run)/i.test(e),i=t.match(/(?:^|\n)\s*(?:\[?exit(?:\s*code)?\]?\s*[:=]?\s*)(\d+)\s*$/i),a=t.match(/(?:^|\s)(\d+\s*ms|\d+\.\d+s)\s*$/i);if(r||i){let e=t;return i&&(e=t.slice(0,i.index).trimEnd()),{kind:`bash`,stdout:e,exitCode:i?Number(i[1]):void 0,duration:a?.[1]}}return{kind:`plain`}}function no({value:e,isError:t,className:n}){let r=(0,z.useMemo)(()=>{try{return JSON.stringify(e,null,2)}catch{return String(e)}},[e]),i=r.split(`
89
- `).length,[a,o]=(0,z.useState)(i<30);return(0,G.jsxs)(`div`,{className:Y(`rounded-md border bg-background/40 overflow-hidden`,t&&`border-destructive/40`,n),children:[(0,G.jsxs)(`button`,{type:`button`,onClick:()=>o(e=>!e),className:`w-full flex items-center justify-between px-2 py-1 border-b bg-muted/30 text-[11px] text-muted-foreground hover:text-foreground`,children:[(0,G.jsxs)(`span`,{className:`flex items-center gap-1`,children:[a?(0,G.jsx)(sn,{className:`h-3 w-3`}):(0,G.jsx)(mn,{className:`h-3 w-3`}),(0,G.jsxs)(`span`,{className:`font-mono`,children:[`JSON Β· `,i,` lines`]})]}),(0,G.jsx)(`span`,{children:a?`collapse`:`expand`})]}),a&&(0,G.jsx)(`pre`,{className:Y(`text-xs font-mono whitespace-pre p-2 max-h-96 overflow-auto`,t?`text-destructive`:`text-foreground`),children:r})]})}async function ro(e){try{if(typeof navigator<`u`&&navigator.clipboard?.writeText)return await navigator.clipboard.writeText(e),!0}catch{}try{let t=document.createElement(`textarea`);t.value=e,t.style.position=`fixed`,t.style.opacity=`0`,document.body.appendChild(t),t.select();let n=document.execCommand(`copy`);return document.body.removeChild(t),n}catch{return!1}}function io(e,t){if(typeof document>`u`)return;let n=new Blob([t],{type:`text/plain;charset=utf-8`}),r=URL.createObjectURL(n),i=document.createElement(`a`);i.href=r,i.download=e,document.body.appendChild(i),i.click(),document.body.removeChild(i),setTimeout(()=>URL.revokeObjectURL(r),1e3)}function ao(e){let t=(e??``).toLowerCase();return/bash|shell|exec|run/.test(t)?`log`:(/grep|search|find/.test(t),`txt`)}function oo(e){return e<1e3?`${e} ms`:e<6e4?`${(e/1e3).toFixed(e<1e4?2:1)}s`:`${Math.floor(e/6e4)}m ${Math.floor(e%6e4/1e3)}s`}var so=[T];function co({text:e}){let[t,n]=(0,z.useState)(!1);return(0,G.jsxs)(`button`,{type:`button`,onClick:(0,z.useCallback)(async()=>{await ro(e)&&(n(!0),setTimeout(()=>n(!1),1500))},[e]),className:Y(`inline-flex items-center gap-1 rounded px-1.5 py-0.5 text-[10px] transition-colors`,`hover:bg-muted-foreground/10`,t?`text-emerald-500`:`text-muted-foreground hover:text-foreground`),title:t?`Copied!`:`Copy code`,children:[t?(0,G.jsx)(Ot,{className:`h-3 w-3`}):(0,G.jsx)(Fe,{className:`h-3 w-3`}),(0,G.jsx)(`span`,{children:t?`Copied`:`Copy`})]})}var lo={next_steps({children:e}){let t=typeof e==`string`?e.trim():``;if(!t)return null;let n=cr(t);return n.length===0?null:(0,G.jsx)(pr,{steps:n,onAutoSubmit:e=>{dr(e);let t=document.querySelector(`form[class*="flex items-end gap-2"]`);t&&t.dispatchEvent(new Event(`submit`,{bubbles:!0,cancelable:!0}))}})},code({inline:e,className:t,children:n,...r}){let i=/language-(\w+)/.exec(t??``),a=String(n??``).replace(/\n$/,``);if(e||!i)return(0,G.jsx)(`code`,{className:Y(`rounded border border-border/60 px-1.5 py-0.5 text-[0.85em] font-mono`,t),...r,children:n});let o=(0,z.useMemo)(()=>a.split(`
90
- `),[a]),s=o.length>1;return(0,G.jsxs)(`div`,{className:`not-prose relative my-3 rounded-lg border border-border overflow-hidden group/codeblock`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between px-3 py-1 border-b border-border text-xs`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(jt,{className:`h-3 w-3 text-muted-foreground`}),(0,G.jsx)(`span`,{className:`font-mono text-muted-foreground font-medium`,children:i[1]}),o.length>0&&(0,G.jsxs)(`span`,{className:`text-[10px] text-muted-foreground/60 tabular-nums`,children:[o.length,` line`,o.length===1?``:`s`]})]}),(0,G.jsx)(co,{text:a})]}),s?(0,G.jsxs)(`div`,{className:`flex max-h-[40rem] overflow-auto`,children:[(0,G.jsx)(`pre`,{"aria-hidden":!0,className:`text-xs font-mono leading-[1.55] py-3 pl-3 pr-2 text-muted-foreground/40 select-none border-r border-border/30 tabular-nums text-right shrink-0`,children:o.map((e,t)=>(0,G.jsx)(`div`,{children:t+1},t))}),(0,G.jsx)(`pre`,{className:`overflow-x-auto py-3 px-3 text-xs leading-[1.55] font-mono flex-1`,children:(0,G.jsx)(`code`,{className:Y(`hljs`,t),...r,children:n})})]}):(0,G.jsx)(`pre`,{className:`overflow-x-auto p-3 text-xs leading-relaxed font-mono max-h-[40rem]`,children:(0,G.jsx)(`code`,{className:Y(`hljs`,t),...r,children:n})}),(0,G.jsx)(`div`,{className:`pointer-events-none absolute bottom-8 left-0 right-0 h-8 bg-gradient-to-t from-black/10 to-transparent opacity-0 group-hover/codeblock:opacity-100 transition-opacity`})]})}};function uo({text:e,className:t,label:n=`Copy`}){let[r,i]=(0,z.useState)(!1);return(0,G.jsx)(`button`,{type:`button`,onClick:async t=>{t.stopPropagation(),await ro(e)&&(i(!0),setTimeout(()=>i(!1),1400))},className:Y(`inline-flex items-center gap-1 text-xs text-muted-foreground hover:text-foreground transition-colors`,t),title:n,children:r?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Ot,{className:`h-3 w-3 text-green-500`}),(0,G.jsx)(`span`,{children:`Copied`})]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Fe,{className:`h-3 w-3`}),(0,G.jsx)(`span`,{children:n})]})})}function fo(e){let t=e.split(`
91
- `);for(let e=0;e<t.length;e++){let n=R(t[e]);if(/^\s*at\s+\S+.*\(.*:\d+:\d+\)\s*$/.test(n)||/^\s*at\s+\S+\.\S+\(\S+\.java:\d+\)\s*$/.test(n)||/^\s+File "[^"]+", line \d+/.test(n))return e}return-1}function po({text:e}){let t=fo(e),[n,r]=(0,z.useState)(!1);if(t===-1)return(0,G.jsx)(`pre`,{className:`whitespace-pre-wrap break-words font-mono text-xs leading-relaxed`,children:e});let i=e.split(`
92
- `),a=i.slice(0,t).join(`
93
- `).trim(),o=i.slice(t).join(`
94
- `),s=o.split(`
95
- `).filter(e=>e.trim().length>0).length;return(0,G.jsxs)(`div`,{className:`space-y-2`,children:[a&&(0,G.jsx)(`pre`,{className:`whitespace-pre-wrap break-words font-mono text-xs leading-relaxed`,children:a}),(0,G.jsxs)(`button`,{type:`button`,onClick:()=>r(e=>!e),className:`inline-flex items-center gap-1 text-xs text-destructive hover:text-destructive/80 font-medium`,children:[n?`β–Ύ`:`β–Έ`,` `,n?`Hide`:`Show`,` stack trace (`,s,` frame`,s===1?``:`s`,`)`]}),n&&(0,G.jsx)(`pre`,{className:`whitespace-pre-wrap break-words font-mono text-[11px] leading-snug bg-destructive/5 border border-destructive/20 rounded p-2 max-h-80 overflow-auto`,children:o})]})}function mo({input:e}){let[t,n]=(0,z.useState)({});if(typeof e!=`object`||!e||Array.isArray(e))return(0,G.jsx)(`pre`,{className:`whitespace-pre-wrap break-all text-xs font-mono`,children:JSON.stringify(e,null,2)});let r=Object.entries(e);return r.length===0?(0,G.jsx)(`span`,{className:`text-xs text-muted-foreground italic`,children:`(no params)`}):(0,G.jsx)(`div`,{className:`text-xs font-mono`,children:r.map(([e,r])=>{if(r==null||typeof r==`string`||typeof r==`number`||typeof r==`boolean`){let t=r===null?`null`:r===void 0?`undefined`:typeof r==`string`?r:String(r),n=typeof r==`string`&&(t.length>80||t.includes(`
96
- `));return(0,G.jsxs)(`div`,{className:Y(`py-0.5`,n?`flex flex-col gap-0.5`:`flex items-baseline gap-2`),children:[(0,G.jsxs)(`span`,{className:`text-muted-foreground shrink-0`,children:[e,`:`]}),(0,G.jsx)(`span`,{className:Y(`text-foreground`,n?`whitespace-pre-wrap break-all bg-muted/40 rounded px-1.5 py-1`:`truncate`,typeof r==`string`?``:`text-amber-600 dark:text-amber-400`),title:typeof r==`string`&&!n?t:void 0,children:t})]},e)}let i=!!t[e],a=Array.isArray(r)?`[${r.length} item${r.length===1?``:`s`}]`:`{${Object.keys(r).length} key${Object.keys(r).length===1?``:`s`}}`;return(0,G.jsxs)(`div`,{className:`py-0.5`,children:[(0,G.jsxs)(`button`,{type:`button`,onClick:()=>n(t=>({...t,[e]:!t[e]})),className:`flex items-baseline gap-2 hover:bg-muted/30 rounded px-1 -mx-1`,children:[(0,G.jsx)(`span`,{className:`text-muted-foreground/60 text-[10px]`,children:i?`β–Ύ`:`β–Έ`}),(0,G.jsxs)(`span`,{className:`text-muted-foreground`,children:[e,`:`]}),(0,G.jsx)(`span`,{className:`text-violet-600 dark:text-violet-400`,children:a})]}),i&&(0,G.jsx)(`pre`,{className:`ml-3 mt-1 whitespace-pre-wrap break-all text-[11px] bg-muted/40 rounded px-2 py-1.5`,children:JSON.stringify(r,null,2)})]},e)})})}var ho=(0,z.memo)(function({message:e,isFirst:t=!1,isContinuation:n=!1}){let[r,i]=(0,z.useState)({}),[a,o]=(0,z.useState)(!1),[s,c]=(0,z.useState)(``),[l,u]=(0,z.useState)(!1),d=e.role===`user`,f=e.role===`tool`;e.role;let p=V(e=>e.truncateAfter),m=V(e=>e.addMessage),h=V(e=>e.setLoading),g=V(e=>e.isLoading),_=H(e=>e.wsUrl),v=W(e=>e.pinnedIds),y=W(e=>e.togglePin),b=W(e=>e.compactMode),S=v.includes(e.id),C=U(e=>e.inputCost),w=U(e=>e.outputCost),T=U(e=>e.cacheReadCost),E=Tr(),{autonomy:D,yolo:O}=E,k=e=>{m({role:`user`,content:e}),h(!0),B(_).sendMessage(e),dr(``)},j=(()=>{if(e.role!==`assistant`||g)return!1;let t=V.getState().messages;for(let n=t.length-1;n>=0;n--){let r=R(t[n]);if(r.role===`assistant`)return r.id===e.id}return!1})(),ee=()=>{let t=V.getState().messages,n=t.findIndex(t=>t.id===e.id);if(n===-1)return;let r=-1;for(let e=n-1;e>=0;e--)if(t[e]?.role===`user`){r=e;break}if(r===-1)return;let i=R(t[r]);p(i.id),m({role:`user`,content:i.content}),h(!0),B(_).sendMessage(i.content)},te=e=>{i(t=>({...t,[e]:!t[e]}))},ne=()=>{c(e.content),o(!0)},re=()=>{o(!1),c(``)},oe=()=>{let t=s.trim();if(!t){re();return}p(e.id),m({role:`user`,content:t}),h(!0),B(_).sendMessage(t),o(!1),c(``)};return(0,G.jsxs)(`div`,{"data-message-id":e.id,"data-pinned":S?`1`:void 0,className:Y(`group flex msg-bubble animate-message rounded-lg transition-shadow`,b?`gap-2`:`gap-3`,d?`flex-row-reverse`:`flex-row`,S&&`ring-1 ring-amber-500/30 bg-amber-500/[0.02] px-1 -mx-1`),children:[n?(0,G.jsx)(`div`,{className:`flex-shrink-0 w-8 h-8`,"aria-hidden":!0}):(0,G.jsx)(`div`,{className:Y(`flex-shrink-0 w-8 h-8 rounded-full flex items-center justify-center`,`ring-2 ring-offset-2 ring-offset-background`,d?`bg-primary text-primary-foreground ring-primary/20`:f?`bg-secondary text-secondary-foreground ring-secondary/20`:`bg-accent text-accent-foreground ring-accent/20`),children:d?(0,G.jsx)($e,{className:`h-4 w-4`}):f?(0,G.jsx)(_t,{className:`h-4 w-4`}):(0,G.jsx)(L,{className:`h-4 w-4`})}),(0,G.jsxs)(`div`,{className:Y(`flex flex-col gap-1.5 max-w-[85%]`,d&&`items-end`),children:[t&&!n&&(0,G.jsx)(`span`,{className:Y(`text-xs font-medium px-1`,d?`text-primary`:f?`text-secondary`:`text-muted-foreground`),children:d?`You`:f?`Tool`:`Assistant`}),f&&e.toolName&&(0,G.jsxs)(`button`,{type:`button`,onClick:()=>te(e.id),className:Y(`flex items-center gap-2 text-sm font-medium cursor-pointer select-none`,`hover:bg-muted/50 rounded-lg px-2 py-1 -mx-2 transition-colors`,e.isError?`text-destructive`:`text-foreground`),children:[(0,G.jsx)(`span`,{className:`text-muted-foreground/50`,children:r[e.id]?(0,G.jsx)(sn,{className:`h-3 w-3`}):(0,G.jsx)(mn,{className:`h-3 w-3`})}),(0,G.jsx)(_t,{className:`h-3 w-3`}),(0,G.jsx)(`span`,{className:`font-mono`,children:e.toolName}),e.toolResult===void 0?(0,G.jsx)(`span`,{className:`h-1.5 w-1.5 rounded-full bg-amber-500 animate-pulse`,"aria-hidden":!0}):e.isError?(0,G.jsx)(M,{className:`h-3 w-3 text-destructive`}):(0,G.jsx)(We,{className:`h-3 w-3 text-green-500`}),typeof e.toolDurationMs==`number`&&(0,G.jsx)(`span`,{className:`text-xs text-muted-foreground tabular-nums font-normal`,children:oo(e.toolDurationMs)})]}),(0,G.jsx)(`div`,{className:Y(`rounded-2xl`,b?`px-3 py-1.5`:`px-4 py-3`,d?`bg-primary text-primary-foreground rounded-br-md`:f?e.isError?`bg-destructive/5 border border-destructive/20 text-destructive`:`bg-muted/80 text-foreground`:`bg-card border text-foreground`,e.isError&&!f&&`border-destructive/20`),children:f?(()=>{let t=!!r[e.id],n=e.toolInput===void 0?``:Ua(e.toolName,e.toolInput),i=e.toolResult?e.toolResult.split(`
97
- `).length:0;return(0,G.jsxs)(`div`,{className:`space-y-1 tool-details`,children:[n&&!t&&(0,G.jsx)(`div`,{className:`text-xs text-muted-foreground font-mono truncate`,children:n}),e.toolResult===void 0&&e.progressLines&&e.progressLines.length>0&&(0,G.jsx)(`div`,{className:`mt-1 rounded-md border border-amber-500/20 bg-amber-500/5 p-1.5 text-[11px] font-mono leading-snug max-h-32 overflow-auto`,children:(()=>{let t=new Map;return e.progressLines.slice(-6).map(e=>{let n=t.get(e)??0;return t.set(e,n+1),(0,G.jsx)(`div`,{className:`truncate text-muted-foreground`,children:e},`${e}-${n}`)})})()}),t&&e.toolInput!==void 0&&(()=>{let t=Xa(e.toolName,e.toolInput);return t?(0,G.jsx)(qa,{oldText:t.oldText,newText:t.newText,caption:t.caption}):(0,G.jsxs)(`div`,{className:`p-3 bg-muted/50 rounded-lg overflow-x-auto`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-1 text-muted-foreground mb-2 text-xs`,children:[(0,G.jsx)(N,{className:`h-3 w-3`}),(0,G.jsx)(`span`,{children:`Input`})]}),(0,G.jsx)(mo,{input:e.toolInput})]})})(),t&&e.toolResult!==void 0&&e.toolResult.length>0&&(0,G.jsxs)(`div`,{className:`relative group/tool`,children:[(0,G.jsx)(eo,{toolName:e.toolName,result:e.toolResult,isError:e.isError}),(0,G.jsxs)(`div`,{className:`absolute top-1.5 right-1.5 flex items-center gap-1 opacity-0 group-hover/tool:opacity-100 transition-opacity`,children:[(0,G.jsx)(uo,{text:e.toolResult,label:``,className:`bg-background/80 border rounded px-1.5 py-0.5`}),e.toolResult.split(`
98
- `).length>5&&(0,G.jsx)(`button`,{type:`button`,onClick:t=>{t.stopPropagation();let n=ao(e.toolName);io(`${(e.toolName??`output`).replace(/[^a-z0-9_-]+/gi,`-`).toLowerCase()}-${new Date().toISOString().replace(/[:.]/g,`-`)}.${n}`,e.toolResult??``)},className:`inline-flex items-center gap-1 text-xs text-muted-foreground hover:text-foreground bg-background/80 border rounded px-1.5 py-0.5`,title:`Download as file`,children:(0,G.jsx)(ie,{className:`h-3 w-3`})})]})]}),t&&e.toolResult!==void 0&&e.toolResult.length===0&&(0,G.jsx)(`span`,{className:`text-xs text-muted-foreground italic`,children:`(empty)`}),!t&&e.isError&&e.toolResult&&(0,G.jsx)(`div`,{className:`text-xs font-mono text-destructive truncate`,children:e.toolResult.split(`
99
- `)[0]}),(e.toolResult!==void 0&&e.toolResult.length>0||e.toolInput!==void 0&&Object.keys(e.toolInput??{}).length>0)&&(0,G.jsx)(`button`,{type:`button`,onClick:()=>te(e.id),className:`text-xs text-muted-foreground hover:text-foreground transition-colors`,children:t?`Hide details`:`Show details${i>0?` (${i} line${i===1?``:`s`})`:``}`})]})})():a&&d?(0,G.jsxs)(`div`,{className:`flex flex-col gap-2 min-w-[280px]`,children:[(0,G.jsx)(`textarea`,{value:s,onChange:e=>c(e.target.value),onKeyDown:e=>{e.key===`Escape`?(e.preventDefault(),re()):e.key===`Enter`&&(e.metaKey||e.ctrlKey)&&(e.preventDefault(),oe())},rows:Math.min(8,Math.max(2,s.split(`
100
- `).length)),className:`w-full resize-none rounded-md border bg-background text-foreground px-2 py-1.5 text-sm font-mono focus:outline-none focus:ring-2 focus:ring-ring`}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,G.jsx)(`span`,{className:`text-[10px] text-primary-foreground/60`,children:`⌘/Ctrl+Enter to save Β· Esc to cancel`}),(0,G.jsxs)(`div`,{className:`flex gap-1`,children:[(0,G.jsx)(`button`,{type:`button`,onClick:re,className:`text-xs px-2 py-0.5 rounded border border-primary-foreground/30 hover:bg-primary-foreground/10`,children:`Cancel`}),(0,G.jsx)(`button`,{type:`button`,onClick:oe,disabled:!s.trim(),className:`text-xs px-2 py-0.5 rounded bg-primary-foreground text-primary disabled:opacity-50`,children:`Save & resend`})]})]})]}):(0,G.jsx)(`div`,{className:Y(`text-sm leading-relaxed markdown-content`,e.streaming&&`streaming-cursor`),children:e.content?l&&e.role===`assistant`?(0,G.jsx)(`pre`,{className:`whitespace-pre-wrap break-words font-mono text-xs leading-relaxed text-foreground/90 max-h-[40rem] overflow-auto`,children:e.content}):e.role===`assistant`&&e.isError?(0,G.jsx)(po,{text:e.content}):(0,G.jsx)(Pe,{remarkPlugins:[Oe],rehypePlugins:so,components:lo,children:e.content}):e.streaming?(0,G.jsx)(`span`,{className:`inline-block animate-pulse text-muted-foreground`,children:`Typing...`}):(0,G.jsx)(`span`,{className:`text-muted-foreground italic`,children:`No content`})})}),j&&e.content&&(()=>{let t=cr(e.content);return t.length===0?null:(0,G.jsx)(pr,{steps:t,yoloMode:O,autoMode:D===`auto`,autoDelayMs:E.autonomyDelayMs,onAutoSubmit:k})})(),(0,G.jsxs)(`div`,{className:Y(`flex items-center gap-2 px-1`,d?`flex-row-reverse`:`flex-row`),children:[(0,G.jsx)(`span`,{className:`text-xs text-muted-foreground/50`,children:new Date(e.timestamp).toLocaleTimeString([],{hour:`2-digit`,minute:`2-digit`})}),(0,G.jsx)(`span`,{className:`w-px h-3 bg-border/60 shrink-0`,"aria-hidden":!0}),e.runSummary&&(0,G.jsxs)(`span`,{className:`text-[10px] text-muted-foreground/60 font-mono tabular-nums`,title:[`Iterations: ${e.runSummary.iterations}`,`Tool calls: ${e.runSummary.tools}`,`Elapsed: ${(e.runSummary.durationMs/1e3).toFixed(2)}s`,e.runSummary.costDelta>0?`Cost: ${e.runSummary.costDelta.toFixed(4)}`:``].filter(Boolean).join(` Β· `),children:[e.runSummary.iterations,` iter`,e.runSummary.tools>0?` Β· ${e.runSummary.tools} tool${e.runSummary.tools===1?``:`s`}`:``,` Β· `,e.runSummary.durationMs<6e4?`${(e.runSummary.durationMs/1e3).toFixed(1)}s`:`${Math.floor(e.runSummary.durationMs/6e4)}m ${Math.floor(e.runSummary.durationMs%6e4/1e3)}s`,e.runSummary.costDelta>0?` Β· ${e.runSummary.costDelta>=.01?e.runSummary.costDelta.toFixed(4):e.runSummary.costDelta.toFixed(6).replace(/0+$/,``).replace(/\.$/,``)}`:``]}),e.usage&&(e.usage.input>0||e.usage.output>0)&&(()=>{let t=e.usage,n=(t.input*C+t.output*w+(t.cacheRead??0)*T)/1e6,r=C>0||w>0,i=n>=.01?`${n.toFixed(4)}`:n>0?`${n.toFixed(6).replace(/0+$/,``).replace(/\.$/,``)}`:``;return(0,G.jsxs)(`span`,{className:`text-[10px] text-muted-foreground/60 font-mono tabular-nums`,title:[`Input: ${t.input.toLocaleString()}`,`Output: ${t.output.toLocaleString()}`,t.cacheRead?`Cache read: ${t.cacheRead.toLocaleString()}`:``,r?`Cost: ${i}`:``].filter(Boolean).join(` Β· `),children:[t.input.toLocaleString(),`β†’`,t.output.toLocaleString(),t.cacheRead?` Β· ${t.cacheRead.toLocaleString()} β†Ί`:``,r&&i?` Β· ${i}`:``]})})(),!f&&e.content&&!e.streaming&&(0,G.jsx)(uo,{text:e.content,label:`Copy`,className:`opacity-50 hover:opacity-100 transition-opacity`}),e.role===`assistant`&&e.content&&!e.streaming&&(0,G.jsxs)(`button`,{type:`button`,onClick:()=>u(e=>!e),title:l?`Show rendered markdown`:`Show raw markdown source`,className:Y(`text-xs inline-flex items-center gap-1 transition-opacity`,l?`text-primary hover:text-primary/80 opacity-100`:`opacity-50 hover:opacity-100 text-muted-foreground hover:text-foreground`),children:[(0,G.jsx)(jt,{className:`h-3 w-3`}),(0,G.jsx)(`span`,{children:l?`Rendered`:`Raw`})]}),d&&!a&&!g&&e.content&&(0,G.jsxs)(`button`,{type:`button`,onClick:ne,title:`Edit & resend this prompt`,className:`opacity-50 hover:opacity-100 transition-opacity text-xs text-muted-foreground hover:text-foreground inline-flex items-center gap-1`,children:[(0,G.jsx)(ae,{className:`h-3 w-3`}),(0,G.jsx)(`span`,{children:`Edit`})]}),e.role===`assistant`&&e.content&&!e.streaming&&(0,G.jsxs)(`button`,{type:`button`,onClick:()=>y(e.id),title:S?`Unpin`:`Pin this answer`,className:Y(`text-xs inline-flex items-center gap-1 transition-opacity`,S?`text-amber-500 hover:text-amber-600 opacity-100`:`opacity-50 hover:opacity-100 text-muted-foreground hover:text-foreground`),children:[S?(0,G.jsx)(A,{className:`h-3 w-3`}):(0,G.jsx)(x,{className:`h-3 w-3`}),(0,G.jsx)(`span`,{children:S?`Pinned`:`Pin`})]}),j&&e.content&&!e.streaming&&(0,G.jsxs)(`button`,{type:`button`,onClick:ee,title:`Regenerate this response`,className:`opacity-50 hover:opacity-100 transition-opacity text-xs text-muted-foreground hover:text-foreground inline-flex items-center gap-1`,children:[(0,G.jsx)(pe,{className:`h-3 w-3`}),(0,G.jsx)(`span`,{children:`Retry`})]})]})]})]})});function go(){let e=U(e=>e.mode),t=U(e=>e.modes),{listModes:n,switchMode:r}=Z(),[i,a]=(0,z.useState)(!1),o=(0,z.useRef)(null);(0,z.useEffect)(()=>{i&&n()},[i,n]),(0,z.useEffect)(()=>{if(!i)return;let e=e=>{o.current?.contains(e.target)||a(!1)},t=e=>{e.key===`Escape`&&a(!1)};return document.addEventListener(`mousedown`,e),document.addEventListener(`keydown`,t),()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`keydown`,t)}},[i]);let s=t.length>0?t:[{id:`default`,name:`Default`,description:`Standard agent behaviour`}];return(0,G.jsxs)(`div`,{ref:o,className:`relative shrink-0`,children:[(0,G.jsxs)(`button`,{type:`button`,onClick:()=>a(e=>!e),className:Y(`flex items-center gap-1 px-2 py-0.5 rounded-full text-xs font-medium`,`bg-accent/40 text-foreground hover:bg-accent transition-colors border border-transparent hover:border-primary/30`),title:`Active mode`,children:[`mode: `,(0,G.jsx)(`span`,{className:`font-mono`,children:e||`default`}),(0,G.jsx)(sn,{className:`h-3 w-3 opacity-60`})]}),i&&(0,G.jsxs)(`div`,{className:`absolute top-full left-0 mt-1 w-64 rounded-md border bg-popover shadow-lg z-30 py-1`,children:[(0,G.jsx)(`div`,{className:`px-3 py-1.5 text-[10px] uppercase tracking-wider text-muted-foreground border-b`,children:`Mode`}),s.map(t=>(0,G.jsxs)(`button`,{type:`button`,onClick:()=>{r(t.id),a(!1)},className:Y(`w-full text-left px-3 py-2 hover:bg-accent/40 flex items-start gap-2`,t.id===e&&`bg-accent/30`),children:[(0,G.jsx)(Ot,{className:Y(`h-3.5 w-3.5 mt-0.5 shrink-0`,t.id===e?`opacity-100 text-primary`:`opacity-0`)}),(0,G.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,G.jsx)(`div`,{className:`text-xs font-mono`,children:t.id}),t.description&&(0,G.jsx)(`div`,{className:`text-[11px] text-muted-foreground leading-snug`,children:t.description})]})]},t.id))]})]})}function _o({open:e,onClose:t,className:n}){let[r,i]=(0,z.useState)([]),a=Z(),o=(0,z.useRef)(null),s=(0,z.useRef)(null);(0,z.useEffect)(()=>{if(!(!e||!a.client?.isConnected))return a.client.send?.({type:`process.list`}),o.current=a.client.on?.(`process.list`,e=>{let t=e?.payload;t?.processes&&i(t.processes)})??null,s.current=setInterval(()=>{a.client.send?.({type:`process.list`})},3e3),()=>{o.current?.(),s.current&&clearInterval(s.current)}},[e,a.client]);let c=(0,z.useCallback)(e=>{a.client.send?.({type:`process.kill`,payload:{pid:e}})},[a.client]),l=(0,z.useCallback)(()=>{a.client.send?.({type:`process.killAll`})},[a.client]),u=r.filter(e=>e.status===`running`);return e?(0,G.jsx)(`div`,{className:Y(`fixed inset-0 z-50 flex items-start justify-center pt-[10vh] bg-black/40 backdrop-blur-sm`,n),onClick:e=>{e.target===e.currentTarget&&t()},children:(0,G.jsxs)(`div`,{className:`w-full max-w-lg rounded-xl border bg-card shadow-2xl max-h-[75vh] flex flex-col animate-in fade-in zoom-in-95`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between px-4 py-3 border-b shrink-0`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2.5`,children:[(0,G.jsx)(`span`,{className:`flex items-center justify-center w-8 h-8 rounded-lg bg-amber-500/10 text-amber-600 dark:text-amber-400`,children:(0,G.jsx)(_t,{className:`h-4 w-4`})}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`h2`,{className:`text-sm font-semibold`,children:`Running Processes`}),(0,G.jsxs)(`span`,{className:`text-[10px] text-muted-foreground tabular-nums`,children:[u.length,` active Β· `,r.length,` total`]})]})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-1`,children:[u.length>0&&(0,G.jsxs)(`button`,{type:`button`,onClick:l,className:`flex items-center gap-1.5 px-2.5 py-1.5 rounded-md text-xs text-destructive hover:bg-destructive/10 transition-colors font-medium`,children:[(0,G.jsx)(Ye,{className:`h-3 w-3 fill-current`}),`Kill All`]}),(0,G.jsx)(`button`,{type:`button`,onClick:t,className:`p-1.5 rounded-md hover:bg-muted transition-colors`,children:(0,G.jsx)(F,{className:`h-4 w-4`})})]})]}),(0,G.jsx)(`div`,{className:`flex-1 overflow-y-auto`,children:r.length===0?(0,G.jsxs)(`div`,{className:`flex flex-col items-center justify-center py-16 gap-3 text-muted-foreground`,children:[(0,G.jsx)(_t,{className:`h-10 w-10 opacity-15`}),(0,G.jsx)(`p`,{className:`text-sm font-medium`,children:`No processes tracked`}),(0,G.jsx)(`p`,{className:`text-xs text-center max-w-xs`,children:`Processes appear here when the agent runs bash or exec tools. Active processes show a pulsing LED.`})]}):(0,G.jsx)(`div`,{className:`divide-y`,children:r.map(e=>{let t=e.status===`running`?Math.floor((Date.now()-e.startedAt)/1e3):null,n=t?t<60?`${t}s`:`${Math.floor(t/60)}m ${t%60}s`:null,r=e.protected===!0;return(0,G.jsxs)(`div`,{className:Y(`flex items-center justify-between px-4 py-3 text-xs transition-colors`,e.status===`running`?`bg-background hover:bg-muted/30`:`bg-muted/20 text-muted-foreground`),children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-3 min-w-0 flex-1`,children:[(0,G.jsx)(`span`,{className:Y(`led shrink-0`,e.status===`running`?r?`text-blue-400`:`text-[hsl(var(--success))] led-pulse`:`text-muted-foreground`)}),(0,G.jsxs)(`div`,{className:`min-w-0`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsxs)(`span`,{className:`font-mono text-[10px] text-muted-foreground shrink-0`,children:[`PID `,e.pid]}),(0,G.jsx)(`span`,{className:`font-medium truncate`,children:e.tool}),r&&(0,G.jsxs)(`span`,{className:`inline-flex items-center gap-0.5 px-1 py-0.5 rounded text-[9px] bg-blue-500/10 text-blue-600 dark:text-blue-400 font-medium shrink-0`,title:`Protected β€” survives kill/killAll`,children:[(0,G.jsx)(we,{className:`h-2.5 w-2.5`}),`protected`]})]}),(0,G.jsx)(`code`,{className:`text-[10px] text-muted-foreground/70 truncate block mt-0.5 font-mono`,children:e.command})]})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-3 shrink-0 ml-3`,children:[n&&(0,G.jsx)(`span`,{className:`text-[10px] text-muted-foreground tabular-nums`,children:n}),e.status===`running`&&!r&&(0,G.jsx)(`button`,{type:`button`,onClick:()=>c(e.pid),className:`p-1.5 rounded-md hover:bg-destructive/10 hover:text-destructive transition-colors`,title:`Kill PID ${e.pid}`,children:(0,G.jsx)(Ye,{className:`h-3.5 w-3.5 fill-current`})})]})]},e.pid)})})})]})}):null}var vo=`
101
- ::highlight(chat-search) { background-color: hsl(var(--primary) / 0.3); color: inherit; }
102
- ::highlight(chat-search-active) { background-color: hsl(var(--primary) / 0.85); color: hsl(var(--primary-foreground)); }
103
- `;function yo(){let e=W(e=>e.searchOpen),t=W(e=>e.setSearchOpen),n=W(e=>e.searchQuery),r=W(e=>e.setSearchQuery),i=V(e=>e.messages),a=W(e=>e.requestScrollToMessage),o=(0,z.useRef)(null),[s,c]=(0,z.useState)(0),[l,u]=(0,z.useState)(0);(0,z.useEffect)(()=>{e&&requestAnimationFrame(()=>o.current?.focus())},[e]),(0,z.useEffect)(()=>{let e=document.createElement(`style`);return e.textContent=vo,document.head.appendChild(e),()=>{document.head.removeChild(e)}},[]);let d=(0,z.useMemo)(()=>{let e=n.trim().toLowerCase();return e?i.filter(t=>t.role===`tool`?(t.toolName??``).toLowerCase().includes(e)||(t.toolResult??``).toLowerCase().includes(e)||JSON.stringify(t.toolInput??``).toLowerCase().includes(e):t.content.toLowerCase().includes(e)).map(e=>e.id):[]},[i,n]);if((0,z.useEffect)(()=>{s>=d.length&&c(0)},[d,s]),(0,z.useEffect)(()=>{let t=window,r=t.CSS?.highlights,i=t.Highlight;if(!r||!i)return;let a=()=>{r.delete(`chat-search`),r.delete(`chat-search-active`)},o=n.trim();if(!o||!e){a();return}let c=o.toLowerCase(),l=[],u=[],f=d[s];for(let e of document.querySelectorAll(`[data-message-id]`)){let t=e.dataset.messageId===f,n=document.createTreeWalker(e,NodeFilter.SHOW_TEXT),r=n.nextNode();for(;r;){let e=r.nodeValue??``;if(e.length>0){let n=e.toLowerCase(),i=0;for(;i<=n.length-c.length;){let e=n.indexOf(c,i);if(e===-1)break;let a=document.createRange();a.setStart(r,e),a.setEnd(r,e+c.length),l.push(a),t&&u.push(a),i=e+c.length}}r=n.nextNode()}}return l.length>0?r.set(`chat-search`,new i(...l)):r.delete(`chat-search`),u.length>0?r.set(`chat-search-active`,new i(...u)):r.delete(`chat-search-active`),a},[n,d,s,e,l]),(0,z.useEffect)(()=>{let e=d[s];if(!e)return;a(e);let t=0,n=requestAnimationFrame(function e(){u(e=>e+1),++t<3&&(n=requestAnimationFrame(e))});return()=>cancelAnimationFrame(n)},[d,s,a]),!e)return null;let f=e=>{d.length!==0&&c(t=>(t+e+d.length)%d.length)};return(0,G.jsx)(`div`,{className:`absolute top-2 right-4 z-30 w-[28rem] max-w-[calc(100%-2rem)] rounded-lg border bg-popover shadow-xl`,children:(0,G.jsxs)(`div`,{className:`flex items-center gap-2 px-3 py-2`,children:[(0,G.jsx)(v,{className:`h-4 w-4 text-muted-foreground shrink-0`}),(0,G.jsx)(`input`,{ref:o,value:n,onChange:e=>r(e.target.value),onKeyDown:e=>{e.key===`Escape`?(e.preventDefault(),t(!1)):e.key===`Enter`?(e.preventDefault(),f(e.shiftKey?-1:1)):e.key===`ArrowDown`?(e.preventDefault(),f(1)):e.key===`ArrowUp`&&(e.preventDefault(),f(-1))},placeholder:`Search in chat…`,className:`flex-1 bg-transparent outline-none text-sm placeholder:text-muted-foreground`}),(0,G.jsx)(`span`,{className:`text-xs text-muted-foreground tabular-nums shrink-0`,children:d.length===0?n?`0`:``:`${s+1} / ${d.length}`}),(0,G.jsx)(`button`,{type:`button`,onClick:()=>f(-1),disabled:d.length===0,className:Y(`p-1 rounded hover:bg-muted disabled:opacity-30 disabled:cursor-not-allowed`),title:`Previous hit`,children:(0,G.jsx)(Rt,{className:`h-3.5 w-3.5`})}),(0,G.jsx)(`button`,{type:`button`,onClick:()=>f(1),disabled:d.length===0,className:Y(`p-1 rounded hover:bg-muted disabled:opacity-30 disabled:cursor-not-allowed`),title:`Next hit`,children:(0,G.jsx)(gt,{className:`h-3.5 w-3.5`})}),(0,G.jsx)(`button`,{type:`button`,onClick:()=>t(!1),className:`p-1 rounded hover:bg-muted text-muted-foreground`,title:`Close (Esc)`,children:(0,G.jsx)(F,{className:`h-3.5 w-3.5`})})]})})}function bo(e){return e<1e3?`${e}ms`:e<6e4?`${(e/1e3).toFixed(e<1e4?2:1)}s`:`${Math.floor(e/6e4)}m${Math.floor(e%6e4/1e3)}s`}var xo=(0,z.memo)(function({tools:e,defaultOpen:t=!1,isContinuation:n=!1}){let[r,i]=(0,z.useState)(t);if(e.length===1)return(0,G.jsx)(ho,{message:R(e[0]),isFirst:!0,isContinuation:n});let a=e.filter(e=>e.toolResult===void 0).length,o=e.filter(e=>e.isError).length,s=e.reduce((e,t)=>e+(t.toolDurationMs??0),0),c=Array.from(new Set(e.map(e=>e.toolName).filter(Boolean))),l=c.slice(0,3).join(`, `),u=c.length>3?` +${c.length-3}`:``;return(0,G.jsxs)(`div`,{className:`flex gap-3 animate-message`,children:[n?(0,G.jsx)(`div`,{className:`flex-shrink-0 w-8 h-8`,"aria-hidden":!0}):(0,G.jsx)(`div`,{className:`flex-shrink-0 w-8 h-8 rounded-full flex items-center justify-center bg-secondary text-secondary-foreground ring-2 ring-offset-2 ring-offset-background ring-secondary/20`,children:(0,G.jsx)(_t,{className:`h-4 w-4`})}),(0,G.jsxs)(`div`,{className:`flex flex-col gap-1.5 max-w-[85%] flex-1 min-w-0`,children:[(0,G.jsxs)(`button`,{type:`button`,onClick:()=>i(e=>!e),className:Y(`flex items-center gap-2 text-sm font-medium cursor-pointer select-none`,`hover:bg-muted/50 rounded-lg px-2 py-1.5 -mx-2 transition-colors`,`border border-border/40 bg-muted/30`),children:[r?(0,G.jsx)(sn,{className:`h-3.5 w-3.5 text-muted-foreground`}):(0,G.jsx)(mn,{className:`h-3.5 w-3.5 text-muted-foreground`}),(0,G.jsx)(_t,{className:`h-3.5 w-3.5 text-muted-foreground`}),(0,G.jsxs)(`span`,{className:`font-mono text-xs`,children:[e.length,` tool call`,e.length===1?``:`s`]}),a>0?(0,G.jsx)(I,{className:`h-3 w-3 animate-spin text-amber-500`}):o>0?(0,G.jsx)(M,{className:`h-3 w-3 text-destructive`}):(0,G.jsx)(We,{className:`h-3 w-3 text-green-500`}),s>0&&(0,G.jsx)(`span`,{className:`text-xs text-muted-foreground tabular-nums font-normal`,children:bo(s)}),l&&(0,G.jsxs)(`span`,{className:`text-xs text-muted-foreground/80 font-mono truncate`,children:[`Β· `,l,u]})]}),r&&(0,G.jsx)(`div`,{className:`space-y-2 pl-3 border-l-2 border-border/40 ml-2 tool-details`,children:e.map(e=>(0,G.jsx)(ho,{message:e,isFirst:!1},e.id))})]})]})}),So=[{icon:v,title:`Understand`,hint:`Explore and analyze the codebase`,tone:`text-blue-600 dark:text-blue-400 bg-blue-500/10 border-blue-500/20`,prompts:[`Map out the structure of this codebase: what are the main modules or components, how do they depend on each other, and what are the key patterns used throughout?`,`Find and document the public API surface β€” all exported interfaces, functions, and types that other parts of the system depend on.`,`Trace the flow of data through the system for a typical operation. Where does input validation happen? Where are side effects triggered?`]},{icon:Dt,title:`Create`,hint:`Build new features and functionality`,tone:`text-emerald-600 dark:text-emerald-400 bg-emerald-500/10 border-emerald-500/20`,prompts:[`Add a new feature that covers the full stack: data model, business logic, and any UI or API layers. Follow existing patterns in this codebase.`,`Write comprehensive tests for a module with low coverage. Include happy paths, edge cases, and error scenarios.`,`Add observability to a critical path β€” structured logging, error tracking, or metrics that help diagnose issues in production.`]},{icon:Me,title:`Investigate`,hint:`Debug issues and find root causes`,tone:`text-amber-600 dark:text-amber-400 bg-amber-500/10 border-amber-500/20`,prompts:[`Something isn't working as expected β€” help me trace from the symptom to the root cause. Follow the code path and identify where behavior diverges from intent.`,`There's a difference between how this works locally versus in production or CI. Check for environment differences, configuration issues, or hidden assumptions.`,`Performance is degrading. Identify the bottlenecks β€” whether N+1 queries, blocking I/O, unnecessary allocations, or something else β€” and propose targeted fixes.`]},{icon:Cn,title:`Improve`,hint:`Refactor and optimize existing code`,tone:`text-violet-600 dark:text-violet-400 bg-violet-500/10 border-violet-500/20`,prompts:[`Find duplicated or similar logic that could be consolidated into shared utilities. Extract the common parts and update the call sites.`,`Identify modules that have grown too large or handle too many responsibilities. Propose a cleaner separation that can be done incrementally.`,`Review error handling across the codebase: are errors consistent, well-contextualized, and properly propagated? Suggest improvements to the worst cases.`]}],Co=[{name:`/help`,hint:`list every slash command`},{name:`/diag`,hint:`runtime diagnostics`},{name:`/stats`,hint:`tokens Β· cache Β· cost Β· elapsed`},{name:`/tools`,hint:`show registered tools`},{name:`/memory`,hint:`show remembered notes`},{name:`/compact`,hint:`shrink context`},{name:`/clear`,hint:`wipe current context`},{name:`/new`,hint:`fresh session`}];function wo(e){let t=document.querySelector(`textarea`);t&&((Object.getOwnPropertyDescriptor(window.HTMLTextAreaElement.prototype,`value`)?.set)?.call(t,e),t.dispatchEvent(new Event(`input`,{bubbles:!0})),t.focus())}function To(){let{projectName:e,cwd:t}=U(),{provider:n,model:r}=H(),i=H(e=>e.wsConnected),a=H(e=>e.wsUrl),o=W(e=>e.setCurrentView),[s,c]=(0,z.useState)(void 0);(0,z.useEffect)(()=>{if(!i)return;let e=B(a),t=e.on(`providers.saved`,e=>{let t=e.payload;c(t.providers?.length??0)});return e.listSavedProviders(),()=>{t()}},[i,a]);let l=W(e=>e.promptHistory).slice(0,6),{listSessions:u,resumeSession:d}=Z(),f=ir(e=>e.entries);(0,z.useEffect)(()=>{i&&f.length===0&&u(10)},[i]);let p=W(e=>e.sessionNicknames),m=f.filter(e=>!e.isCurrent).slice(0,4);return(0,G.jsxs)(`div`,{className:`flex flex-col gap-8 py-8 px-2 max-w-5xl mx-auto w-full`,children:[(0,G.jsxs)(`div`,{className:`flex flex-col items-center text-center gap-3`,children:[(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsx)(`div`,{className:`w-14 h-14 rounded-2xl bg-gradient-to-br from-primary via-primary to-primary/60 flex items-center justify-center shadow-lg shadow-primary/20`,children:(0,G.jsx)(Ue,{className:`h-7 w-7 text-primary-foreground`})}),(0,G.jsx)(`div`,{className:`absolute -inset-3 bg-gradient-to-r from-transparent via-primary/10 to-transparent animate-pulse rounded-full -z-10`})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`h2`,{className:`text-2xl font-semibold tracking-tight`,children:[`Where do you want to start`,e?(0,G.jsxs)(G.Fragment,{children:[` in `,(0,G.jsx)(`span`,{className:`text-primary`,children:e})]}):``,`?`]}),(0,G.jsxs)(`p`,{className:`text-sm text-muted-foreground mt-2 max-w-2xl mx-auto leading-relaxed`,children:[`The agent is connected to your project and ready to read, edit, run commands, search the codebase, track todos, and remember context across sessions. Pick a starting prompt below, write your own, or type`,` `,(0,G.jsx)(`span`,{className:`font-mono text-foreground/80`,children:`/`}),` for the full command palette.`]}),n&&r&&(0,G.jsxs)(`p`,{className:`text-xs text-muted-foreground/70 mt-2 font-mono`,children:[n,` / `,r]}),t&&(0,G.jsxs)(`p`,{className:`text-[11px] text-muted-foreground/50 mt-1 font-mono`,title:t,children:[`Working directory: `,t]})]})]}),i&&s===0&&(0,G.jsxs)(`button`,{type:`button`,onClick:()=>o(`settings`),className:Y(`group rounded-xl border bg-gradient-to-br from-amber-500/10 via-amber-500/5 to-transparent`,`border-amber-500/30 hover:border-amber-500/50 transition-colors`,`p-4 flex items-center gap-4 text-left`),children:[(0,G.jsx)(`span`,{className:`flex items-center justify-center w-12 h-12 rounded-lg bg-amber-500/15 text-amber-600 dark:text-amber-400 shrink-0`,children:(0,G.jsx)(Lt,{className:`h-6 w-6`})}),(0,G.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,G.jsx)(`h3`,{className:`text-base font-semibold mb-1`,children:`No API key configured yet`}),(0,G.jsx)(`p`,{className:`text-sm text-muted-foreground leading-relaxed`,children:`Register a provider in Settings before sending a message β€” otherwise the agent has nothing to talk to. Anthropic, OpenAI, Google, and any OpenAI-compatible endpoint all work.`})]}),(0,G.jsxs)(`span`,{className:`flex items-center gap-1 text-xs text-amber-600 dark:text-amber-400 font-medium shrink-0 group-hover:translate-x-0.5 transition-transform`,children:[`Open Settings `,(0,G.jsx)(vn,{className:`h-3.5 w-3.5`})]})]}),(0,G.jsx)(`div`,{className:`grid grid-cols-1 lg:grid-cols-2 gap-4`,children:So.map((e,t)=>{let n=e.icon;return(0,G.jsxs)(`div`,{className:`rounded-xl border bg-card/40 backdrop-blur-sm p-4 flex flex-col gap-3 animate-message hover:border-primary/20 hover:shadow-sm transition-all`,style:{animationDelay:`${t*80}ms`},children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`span`,{className:Y(`flex items-center justify-center w-8 h-8 rounded-lg border`,e.tone),children:(0,G.jsx)(n,{className:`h-4 w-4`})}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`h3`,{className:`text-sm font-semibold`,children:e.title}),(0,G.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:e.hint})]})]}),(0,G.jsx)(`div`,{className:`flex flex-col gap-1.5`,children:e.prompts.map((e,t)=>(0,G.jsx)(`button`,{type:`button`,onClick:()=>wo(e),className:`text-left text-xs leading-relaxed text-foreground/80 hover:text-foreground border border-transparent hover:border-border/60 rounded-lg px-3 py-2 hover:bg-muted/40 transition-colors line-clamp-3`,title:e,children:e},t))})]},e.title)})}),m.length>0&&(0,G.jsxs)(`div`,{className:`rounded-xl border bg-muted/20 p-4`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 mb-3`,children:[(0,G.jsx)($t,{className:`h-4 w-4 text-muted-foreground`}),(0,G.jsx)(`span`,{className:`text-xs uppercase tracking-wider text-muted-foreground font-medium`,children:`Pick back up`})]}),(0,G.jsx)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-2`,children:m.map(e=>(0,G.jsxs)(`button`,{type:`button`,onClick:()=>d(e.id),className:`text-left rounded-lg border border-border/40 bg-background/60 hover:border-primary/40 hover:bg-accent/30 px-3 py-2 transition-colors group/sess`,title:e.title,children:[(0,G.jsx)(`div`,{className:`text-sm font-medium truncate text-foreground group-hover/sess:text-primary`,children:p[e.id]||e.title||`(empty)`}),(0,G.jsxs)(`div`,{className:`text-[10px] text-muted-foreground font-mono truncate mt-0.5`,children:[e.provider,`/`,e.model,e.tokenTotal>0&&(0,G.jsxs)(`span`,{className:`ml-2`,children:[`Β· `,e.tokenTotal.toLocaleString(),` tok`]})]})]},e.id))})]}),l.length>0&&(0,G.jsxs)(`div`,{className:`rounded-xl border bg-muted/20 p-4`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 mb-3`,children:[(0,G.jsx)(N,{className:`h-4 w-4 text-muted-foreground`}),(0,G.jsx)(`span`,{className:`text-xs uppercase tracking-wider text-muted-foreground font-medium`,children:`Recent prompts`})]}),(0,G.jsx)(`div`,{className:`flex flex-col gap-1.5`,children:l.filter(e=>!e.startsWith(`/`)).slice(0,5).map((e,t)=>(0,G.jsx)(`button`,{type:`button`,onClick:()=>wo(e),className:`text-left text-xs leading-relaxed text-muted-foreground hover:text-foreground border border-transparent hover:border-border/60 rounded-lg px-3 py-2 hover:bg-background/60 transition-colors line-clamp-2`,title:e,children:e},t))})]}),(0,G.jsxs)(`div`,{className:`rounded-xl border bg-muted/20 p-4`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 mb-3`,children:[(0,G.jsx)(un,{className:`h-4 w-4 text-muted-foreground`}),(0,G.jsx)(`span`,{className:`text-xs uppercase tracking-wider text-muted-foreground font-medium`,children:`Quick commands`})]}),(0,G.jsx)(`div`,{className:`grid grid-cols-2 md:grid-cols-4 gap-2`,children:Co.map(e=>(0,G.jsxs)(`button`,{type:`button`,onClick:()=>wo(e.name),className:`text-left flex flex-col gap-0.5 rounded-md border border-border/40 bg-background/60 px-3 py-2 hover:border-primary/40 hover:bg-accent/40 transition-colors`,children:[(0,G.jsx)(`span`,{className:`font-mono text-xs text-foreground`,children:e.name}),(0,G.jsx)(`span`,{className:`text-[11px] text-muted-foreground truncate`,children:e.hint})]},e.name))})]})]})}function Eo(){let e=V(e=>e.thinkingBuffer);if(!e)return null;let t=e.split(`
104
- `).slice(-6).join(`
105
- `).trim();return(0,G.jsxs)(`div`,{className:`flex gap-3 animate-message`,children:[(0,G.jsx)(`div`,{className:`flex-shrink-0 w-8 h-8 rounded-full flex items-center justify-center bg-violet-500/10 text-violet-600 dark:text-violet-400 ring-2 ring-offset-2 ring-offset-background ring-violet-500/20`,children:(0,G.jsx)(Yt,{className:`h-4 w-4 animate-pulse`})}),(0,G.jsxs)(`div`,{className:`flex flex-col gap-1 max-w-[85%] min-w-0`,children:[(0,G.jsx)(`span`,{className:`text-xs font-medium text-violet-600 dark:text-violet-400 px-1`,children:`Thinking…`}),(0,G.jsx)(`div`,{className:`rounded-2xl rounded-bl-md px-3 py-2 bg-violet-500/[0.04] border border-violet-500/20 text-foreground/80`,children:(0,G.jsx)(`pre`,{className:`whitespace-pre-wrap break-words font-sans text-xs leading-relaxed italic max-h-32 overflow-hidden`,children:t||`…`})})]})]})}var Do=(0,z.memo)(function({row:e,isLoading:t,compactMode:n,isFirstRow:r}){let i=Y(`mx-auto max-w-5xl w-full px-4`,r&&`pt-4`,n?`pb-3`:`pb-6`);return e.kind===`day`?(0,G.jsx)(`div`,{className:i,children:(0,G.jsxs)(`div`,{className:`flex items-center gap-3 py-1 text-[11px] text-muted-foreground/70 uppercase tracking-wider font-medium`,children:[(0,G.jsx)(`div`,{className:`flex-1 h-px bg-border/50`}),(0,G.jsx)(`span`,{children:e.label}),(0,G.jsx)(`div`,{className:`flex-1 h-px bg-border/50`})]})}):e.kind===`user`?(0,G.jsx)(`div`,{className:i,children:(0,G.jsx)(ho,{message:e.message,isFirst:!0})}):(0,G.jsx)(`div`,{className:i,children:(0,G.jsx)(`div`,{className:Y(`chat-turn`,n?`space-y-1`:`space-y-1.5`),children:e.items.map(n=>{if(n.kind===`msg`)return(0,G.jsx)(ho,{message:n.message,isFirst:n.isFirst,isContinuation:n.isContinuation},n.key);let r=e.isLastTurn&&n.isLastGroup&&t&&n.hasRunningTool;return(0,G.jsx)(xo,{tools:n.tools,defaultOpen:r,isContinuation:n.isContinuation},n.key)})})})});function Oo(){let e=V(e=>e.messages),t=V(e=>e.isLoading),n=W(e=>e.sidebarOpen),r=W(e=>e.toggleSidebar),i=W(e=>e.compactMode),{totalTokens:a,startTime:o,lastInputTokens:s,maxContext:c,iteration:u}=U(),d=U(e=>e.session),f=d?.id,p=W(e=>f?e.sessionNicknames[f]:void 0),m=W(e=>e.setSessionNickname),h=d?.title,[g,_]=(0,z.useState)(!1),[v,y]=(0,z.useState)(``),b=ir(e=>e.entries),[x,C]=(0,z.useState)(!1),w=(0,z.useRef)(null);(0,z.useEffect)(()=>{if(!x)return;let e=e=>{w.current?.contains(e.target)||C(!1)},t=e=>{e.key===`Escape`&&C(!1)};return document.addEventListener(`mousedown`,e),document.addEventListener(`keydown`,t),()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`keydown`,t)}},[x]);let{provider:T,model:D}=H(),O=(0,z.useRef)(null),k=(0,z.useMemo)(()=>Pa(e),[e]),A=(0,z.useRef)(0);A.current=k.length+1;let j=(0,z.useMemo)(()=>{let e=new Map;return k.forEach((t,n)=>{if(t.kind===`user`)e.set(t.message.id,n);else if(t.kind===`agent`)for(let r of t.items)if(r.kind===`msg`)e.set(r.message.id,n);else for(let t of r.tools)e.set(t.id,n)}),e},[k]),M=W(e=>e.scrollTarget),ee=Tr(e=>e.autonomy),te=(0,z.useCallback)(e=>{Tr.getState().set({autonomy:e}),B()?.send?.({type:`autonomy.switch`,payload:{mode:e}})},[]),[N,ne]=(0,z.useState)(!1),[re,ie]=(0,z.useState)(!1),[oe,se]=(0,z.useState)(!1);(0,z.useEffect)(()=>{let e=()=>se(!0);return document.addEventListener(`open:context-breakdown`,e),()=>document.removeEventListener(`open:context-breakdown`,e)},[]);let ce=c>0&&s>0?Math.round(s/c*100):0,[le,P]=(0,z.useState)(!0),[ue,de]=(0,z.useState)(0),[fe,pe]=(0,z.useState)(!1),me=(0,z.useRef)(e.length),he=(0,z.useCallback)(()=>{let e=O.current;if(!e)return;let t=e.scrollSize-e.scrollOffset-e.viewportSize<120;P(t),t&&(de(0),me.current=V.getState().messages.length),pe(e.scrollOffset>e.viewportSize&&e.scrollSize>e.viewportSize*2.5)},[]),ge=(0,z.useCallback)(e=>{B()?.resumeSession?.(e),C(!1)},[]);(0,z.useEffect)(()=>{let t=O.current;if(t)if(le)t.scrollToIndex(A.current-1,{align:`end`}),me.current=e.length;else{let t=e.length-me.current;t>0&&de(t)}},[e,le]),(0,z.useEffect)(()=>{P(!0),de(0),me.current=V.getState().messages.length,requestAnimationFrame(()=>{O.current?.scrollToIndex(A.current-1,{align:`end`})})},[f]),(0,z.useEffect)(()=>{if(!M)return;let e=j.get(M.id);e!==void 0&&O.current?.scrollToIndex(e,{align:`center`,smooth:!0})},[M,j]);let F=(0,z.useCallback)(()=>{O.current?.scrollToIndex(A.current-1,{align:`end`,smooth:!0}),P(!0),de(0),me.current=V.getState().messages.length},[]),_e=(0,z.useCallback)(()=>{O.current?.scrollToIndex(0,{align:`start`,smooth:!0})},[]),[ve,ye]=(0,z.useState)(null),[be,xe]=(0,z.useState)(()=>Date.now()),Se=(0,z.useRef)(null),Ce=(0,z.useMemo)(()=>{let t=e[e.length-1],n=e.filter(e=>e.role===`tool`&&e.toolResult===void 0),r=`Thinking…`;if(n.length>0){let e=Array.from(new Set(n.map(e=>e.toolName).filter(Boolean))),t=e.slice(0,2).join(`, `),i=e.length>2?` +${e.length-2}`:``;r=n.length===1?`Running ${t||`tool`}…`:`Running ${n.length} tools (${t}${i})…`}else t?.role===`assistant`&&t.content?r=`Writing reply…`:t?.role===`tool`&&t.toolResult!==void 0&&(r=`Thinking about the next step…`);let i=ve?Math.max(0,Math.floor((be-ve)/1e3)):0,a=i<60?`${i}s`:`${Math.floor(i/60)}m ${i%60}s`,o=``,s=t?.role===`assistant`&&t.streaming&&t.content?t:null;if(s){let e=Se.current;if(!e||e.id!==s.id)Se.current={id:s.id,at:Date.now(),len:s.content.length};else{let t=Math.max(1,be-e.at),n=Math.max(0,s.content.length-e.len);if(t>500&&n>0){let e=n*1e3/t;o=e>=1e3?`${(e/1e3).toFixed(1)}k ch/s`:`${Math.round(e)} ch/s`}}}else Se.current&&=null;return{label:r,elapsed:a,speedLabel:o}},[e,be,ve]);(0,z.useEffect)(()=>{t&&ve===null&&ye(Date.now()),!t&&ve!==null&&ye(null)},[t,ve]),(0,z.useEffect)(()=>{if(!t)return;let e=setInterval(()=>xe(Date.now()),500);return()=>clearInterval(e)},[t]);let we=e=>{if(!e)return`--`;let t=Math.floor((Date.now()-e)/1e3);return t<60?`${t}s`:`${Math.floor(t/60)}m ${t%60}s`},Te=(()=>{if(!t)return`idle`;let n=e[e.length-1];return n?.role===`assistant`&&n.content&&n.streaming?`streaming`:`thinking`})(),Ee=Te===`idle`?`bg-muted text-muted-foreground`:Te===`streaming`?`bg-blue-500/10 text-blue-600 dark:text-blue-400`:`bg-amber-500/10 text-amber-600 dark:text-amber-400`,De=c>0&&s>0||a.input>0||!!o;return(0,G.jsxs)(`div`,{className:`flex flex-col flex-1 min-h-0`,children:[(0,G.jsxs)(`header`,{className:`flex flex-col border-b bg-card/95 backdrop-blur-sm supports-[backdrop-filter]:bg-card/80 shrink-0 sticky top-0 z-20`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between gap-2 px-3 py-2`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-1.5 min-w-0 flex-1 overflow-hidden`,children:[!n&&(0,G.jsx)(Q,{variant:`ghost`,size:`icon`,className:`h-7 w-7 shrink-0`,onClick:r,title:`Open sidebar (Ctrl+\\\\)`,children:(0,G.jsx)(l,{className:`h-4 w-4`})}),!n&&(0,G.jsx)(`div`,{className:`flex items-center gap-1.5 shrink-0 mr-1`,children:(0,G.jsx)(`div`,{className:`w-5 h-5 rounded bg-primary flex items-center justify-center`,children:(0,G.jsx)(Ue,{className:`h-3 w-3 text-primary-foreground`})})}),(0,G.jsxs)(`span`,{className:Y(`flex items-center gap-1 px-1.5 py-0.5 rounded-full text-[11px] font-medium shrink-0 tabular-nums`,Ee),title:`Agent state: ${Te}`,children:[Te!==`idle`&&(0,G.jsx)(`span`,{className:`h-1.5 w-1.5 rounded-full bg-current animate-pulse`}),(0,G.jsx)(`span`,{children:Te})]}),f&&(g?(0,G.jsx)(`input`,{value:v,onChange:e=>y(e.target.value),onBlur:()=>{v.trim()&&m(f,v),_(!1)},onKeyDown:e=>{e.key===`Enter`?(e.preventDefault(),v.trim()&&m(f,v),_(!1)):e.key===`Escape`&&(e.preventDefault(),_(!1))},placeholder:`Session name…`,className:`h-5 px-1.5 text-[11px] bg-background border border-primary/40 rounded focus:outline-none focus:ring-1 focus:ring-ring shrink-0 w-32`,autoFocus:!0}):(0,G.jsxs)(`button`,{type:`button`,onClick:()=>{y(p||h||``),_(!0)},className:`flex items-center gap-1 text-[11px] font-medium text-foreground/80 hover:text-foreground truncate max-w-[12rem] shrink-0 px-1 -mx-1 rounded hover:bg-muted/50 transition-colors`,title:`Click to rename session`,children:[(0,G.jsx)(ae,{className:`h-2.5 w-2.5 text-muted-foreground shrink-0`}),(0,G.jsx)(`span`,{className:`truncate`,children:p||h||`Untitled`})]}))]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-1.5 shrink-0`,children:[b.length>1&&(0,G.jsxs)(`div`,{ref:w,className:`relative shrink-0`,children:[(0,G.jsxs)(`button`,{type:`button`,onClick:()=>C(e=>!e),className:`flex items-center gap-0.5 px-1 py-0.5 rounded text-[10px] text-muted-foreground hover:text-foreground hover:bg-muted/50 transition-colors`,title:`Switch session`,children:[(0,G.jsx)(ct,{className:`h-3 w-3`}),(0,G.jsx)(sn,{className:`h-2.5 w-2.5`})]}),x&&(0,G.jsx)(`div`,{className:`absolute left-0 top-full mt-1 z-40 w-64 rounded-md border bg-popover shadow-lg p-1 max-h-60 overflow-y-auto`,children:b.slice(0,15).map(e=>(0,G.jsxs)(`button`,{type:`button`,onClick:()=>ge(e.id),className:Y(`w-full text-left px-2 py-1.5 rounded text-xs hover:bg-accent transition-colors`,e.isCurrent&&`bg-primary/10`),children:[(0,G.jsx)(`div`,{className:`font-medium truncate`,children:e.title||`(empty)`}),(0,G.jsxs)(`div`,{className:`text-[10px] text-muted-foreground font-mono truncate`,children:[e.provider,`/`,e.model,` Β· `,e.tokenTotal.toLocaleString(),` tok`]})]},e.id))})]}),(0,G.jsxs)(`button`,{type:`button`,onClick:()=>W.getState().setModelSwitcherOpen(!0),className:`group hidden sm:flex items-center gap-1 px-2 py-0.5 rounded-md border bg-background/50 hover:bg-accent hover:border-primary/40 transition-colors text-[11px] min-w-0 shrink-0`,title:`Change provider / model (Ctrl+M)`,children:[(0,G.jsx)(E,{className:`h-3 w-3 text-muted-foreground group-hover:text-foreground shrink-0`}),(0,G.jsxs)(`span`,{className:`font-mono truncate max-w-[9rem] xl:max-w-[16rem]`,children:[(0,G.jsx)(`span`,{className:`text-muted-foreground`,children:T||`no-provider`}),(0,G.jsx)(`span`,{className:`text-muted-foreground/40 mx-0.5`,children:`/`}),(0,G.jsx)(`span`,{className:`font-medium`,children:D||`no-model`})]})]}),(0,G.jsxs)(`div`,{className:`hidden md:flex items-center gap-1.5 shrink-0`,children:[(0,G.jsx)(go,{}),(0,G.jsx)(ja,{})]}),u&&(0,G.jsxs)(`button`,{type:`button`,className:`flex items-center gap-1 px-1.5 py-0.5 rounded-full text-[11px] font-medium bg-primary/10 text-primary shrink-0 hover:bg-primary/20 transition-colors cursor-pointer`,title:`Agent iteration β€” click to jump to live activity`,onClick:()=>document.getElementById(`chat-activity`)?.scrollIntoView({behavior:`smooth`,block:`center`}),children:[(0,G.jsx)(Ht,{className:`h-3 w-3 animate-pulse`}),`iter `,u.index,u.max>0?`/${u.max}`:``]}),(0,G.jsx)(la,{value:ee,onChange:te,compact:!0})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-0.5 shrink-0`,children:[(0,G.jsxs)(Q,{variant:N?`secondary`:`ghost`,size:`icon`,className:Y(`h-7 w-7 relative`,N&&`bg-amber-500/10 text-amber-600 dark:text-amber-400`),onClick:()=>ne(e=>!e),title:`Running processes`,children:[(0,G.jsx)(_t,{className:`h-4 w-4`}),N&&(0,G.jsx)(`span`,{className:`absolute -bottom-0.5 left-1/2 -translate-x-1/2 w-1 h-1 rounded-full bg-amber-500`})]}),(0,G.jsxs)(Q,{variant:re?`secondary`:`ghost`,size:`icon`,className:Y(`h-7 w-7 relative`,re&&`bg-violet-500/10 text-violet-600 dark:text-violet-400`),onClick:()=>ie(e=>!e),title:`Session checkpoints β€” rewind`,children:[(0,G.jsx)(ct,{className:`h-4 w-4`}),re&&(0,G.jsx)(`span`,{className:`absolute -bottom-0.5 left-1/2 -translate-x-1/2 w-1 h-1 rounded-full bg-violet-500`})]})]})]}),De&&(0,G.jsxs)(`div`,{className:`flex items-center justify-between gap-3 px-3 py-1 border-t bg-muted/20 text-[11px] text-muted-foreground`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-3 min-w-0 flex-1 tabular-nums`,children:[s>0&&(0,G.jsx)(za,{pct:ce,tokens:s,maxTokens:c>0?c:void 0,onClick:()=>se(!0)}),a.input>0&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,G.jsx)(`span`,{className:`font-medium text-foreground`,children:$(a.input)}),(0,G.jsx)(`span`,{children:`in`})]}),(0,G.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,G.jsx)(`span`,{className:`font-medium text-foreground`,children:$(a.output)}),(0,G.jsx)(`span`,{children:`out`})]}),a.cacheRead&&a.cacheRead>0&&(()=>{let e=(a.cacheRead??0)+a.input,t=e>0?Math.round((a.cacheRead??0)/e*100):0;return(0,G.jsxs)(`span`,{className:`flex items-center gap-1`,title:`Cache hit ratio: ${t}%`,children:[(0,G.jsx)(`span`,{className:`font-medium text-foreground`,children:$(a.cacheRead)}),(0,G.jsxs)(`span`,{children:[`cache (`,t,`%)`]})]})})(),(0,G.jsx)(Va,{})]})]}),o&&(0,G.jsx)(`span`,{className:`text-muted-foreground/70 tabular-nums shrink-0`,children:we(o)})]})]}),(0,G.jsxs)(`div`,{className:`flex-1 relative overflow-hidden`,children:[(0,G.jsx)(yo,{}),!le&&(0,G.jsxs)(`button`,{type:`button`,onClick:F,className:Y(`absolute bottom-4 left-1/2 -translate-x-1/2 z-10 jump-bottom`,`flex items-center gap-2 px-4 py-2 rounded-full shadow-lg`,`bg-primary text-primary-foreground text-xs font-medium`,`hover:bg-primary/90 transition-colors animate-message`),children:[(0,G.jsx)(gt,{className:`h-3.5 w-3.5`}),ue>0?`${ue} new message${ue===1?``:`s`}`:`Jump to latest`]}),fe&&(0,G.jsxs)(`button`,{type:`button`,onClick:_e,title:`Scroll to top (oldest)`,className:Y(`absolute top-3 right-3 z-10`,`flex items-center gap-1 px-2.5 py-1 rounded-full shadow-md border`,`bg-background/90 backdrop-blur-sm text-[11px] text-muted-foreground`,`hover:text-foreground hover:bg-background transition-colors animate-message`),children:[(0,G.jsx)(Rt,{className:`h-3 w-3`}),(0,G.jsx)(`span`,{children:`Top`})]}),k.length===0&&!t?(0,G.jsx)(`div`,{className:`mx-auto max-w-5xl w-full px-4 pt-4`,children:(0,G.jsx)(To,{})}):(0,G.jsxs)(S,{ref:O,className:`h-full`,onScroll:he,children:[k.map((e,n)=>(0,G.jsx)(Do,{row:e,isLoading:t,compactMode:i,isFirstRow:n===0},e.key)),(0,G.jsxs)(`div`,{id:`chat-activity`,className:Y(`mx-auto max-w-5xl w-full px-4`,i?`pb-3`:`pb-8`),children:[(0,G.jsx)(Eo,{}),t&&(0,G.jsxs)(`div`,{className:`flex gap-3 animate-message`,children:[(0,G.jsx)(`div`,{className:`flex-shrink-0 w-8 h-8 rounded-full flex items-center justify-center bg-accent text-accent-foreground ring-2 ring-offset-2 ring-offset-background ring-accent/20`,children:(0,G.jsx)(L,{className:`h-4 w-4`})}),(0,G.jsx)(`div`,{className:`flex flex-col gap-1.5`,children:(0,G.jsx)(`div`,{className:`rounded-2xl px-4 py-3 bg-card border text-foreground`,children:(0,G.jsxs)(`div`,{className:`flex items-center gap-3 text-sm`,children:[(0,G.jsxs)(`span`,{className:`flex gap-1`,children:[(0,G.jsx)(`span`,{className:`h-1.5 w-1.5 rounded-full bg-primary/70 animate-bounce [animation-delay:-0.3s]`}),(0,G.jsx)(`span`,{className:`h-1.5 w-1.5 rounded-full bg-primary/70 animate-bounce [animation-delay:-0.15s]`}),(0,G.jsx)(`span`,{className:`h-1.5 w-1.5 rounded-full bg-primary/70 animate-bounce`})]}),(0,G.jsx)(`span`,{className:`text-foreground/90`,children:Ce.label}),(0,G.jsx)(`span`,{className:`text-xs text-muted-foreground tabular-nums`,children:Ce.elapsed}),u&&(0,G.jsxs)(`span`,{className:`text-xs text-muted-foreground tabular-nums`,children:[`Β· iter `,u.index,u.max>0?`/${u.max}`:``]}),Ce.speedLabel&&(0,G.jsxs)(`span`,{className:`text-xs text-muted-foreground/80 tabular-nums`,children:[`Β· `,Ce.speedLabel]})]})})})]})]},`__live`)]})]}),(0,G.jsxs)(`div`,{className:`border-t bg-card/50 backdrop-blur supports-[backdrop-filter]:bg-card/50 shrink-0`,children:[(0,G.jsxs)(`div`,{className:`max-w-5xl mx-auto px-4 pt-1.5 flex items-center gap-3 text-[10px] text-muted-foreground/50 select-none overflow-x-auto`,children:[(0,G.jsxs)(`span`,{title:`Enter`,className:`inline-flex items-center gap-1`,children:[(0,G.jsx)(`kbd`,{children:`Enter`}),` send`]}),(0,G.jsx)(`span`,{className:`opacity-50`,children:`Β·`}),(0,G.jsxs)(`span`,{title:`Shift+Enter`,className:`inline-flex items-center gap-1`,children:[(0,G.jsx)(`kbd`,{children:`Shift`}),`+`,(0,G.jsx)(`kbd`,{children:`↡`}),` newline`]}),(0,G.jsx)(`span`,{className:`opacity-50`,children:`Β·`}),(0,G.jsxs)(`span`,{title:`Ctrl+\\\\`,className:`inline-flex items-center gap-1`,children:[(0,G.jsx)(`kbd`,{children:`Ctrl+\\`}),` sidebar`]}),(0,G.jsx)(`span`,{className:`opacity-50`,children:`Β·`}),(0,G.jsxs)(`span`,{title:`Ctrl+F`,className:`inline-flex items-center gap-1`,children:[(0,G.jsx)(`kbd`,{children:`Ctrl+F`}),` search`]}),(0,G.jsx)(`span`,{className:`opacity-50`,children:`Β·`}),(0,G.jsxs)(`span`,{title:`Ctrl+K`,className:`inline-flex items-center gap-1`,children:[(0,G.jsx)(`kbd`,{children:`Ctrl+K`}),` palette`]}),(0,G.jsx)(`span`,{className:`opacity-50`,children:`Β·`}),(0,G.jsxs)(`span`,{title:`Ctrl+L / Ctrl+N`,className:`inline-flex items-center gap-1`,children:[(0,G.jsx)(`kbd`,{children:`Ctrl+L`}),` clear`]}),(0,G.jsx)(`span`,{className:`opacity-50`,children:`Β·`}),(0,G.jsxs)(`span`,{title:`j/k to navigate`,className:`inline-flex items-center gap-1`,children:[(0,G.jsx)(`kbd`,{children:`j`}),(0,G.jsx)(`kbd`,{children:`k`}),` navigate`]}),(0,G.jsx)(`span`,{className:`opacity-50`,children:`Β·`}),(0,G.jsxs)(`span`,{title:`Ctrl+M`,className:`inline-flex items-center gap-1`,children:[(0,G.jsx)(`kbd`,{children:`Ctrl+M`}),` model`]}),(0,G.jsx)(`span`,{className:`opacity-50`,children:`Β·`}),(0,G.jsxs)(`span`,{title:`Ctrl+Shift+D`,className:`inline-flex items-center gap-1`,children:[(0,G.jsx)(`kbd`,{children:`Ctrl+⇧D`}),` density`]})]}),(0,G.jsx)(`div`,{className:`p-4`,children:(0,G.jsx)(`div`,{className:`max-w-5xl mx-auto`,children:(0,G.jsx)(Oa,{onOpenBreakdown:()=>se(!0)})})})]}),(0,G.jsx)(_o,{open:N,onClose:()=>ne(!1)}),(0,G.jsx)(ka,{open:re,onClose:()=>ie(!1)}),(0,G.jsx)(Ba,{open:oe,onClose:()=>se(!1)})]})}Nn.defineTheme(`wrongstack-dark`,{base:`vs-dark`,inherit:!0,rules:[{token:`comment`,foreground:`6e717a`,fontStyle:`italic`},{token:`comment.line`,foreground:`6e717a`,fontStyle:`italic`},{token:`comment.block`,foreground:`6e717a`,fontStyle:`italic`},{token:`comment.documentation`,foreground:`6e717a`,fontStyle:`italic`},{token:`string`,foreground:`64d488`},{token:`string.escape`,foreground:`49d3c5`},{token:`string.template`,foreground:`64d488`},{token:`number`,foreground:`f2a23a`},{token:`number.hex`,foreground:`f2a23a`},{token:`number.float`,foreground:`f2a23a`},{token:`keyword`,foreground:`f28dbc`},{token:`keyword.control`,foreground:`f28dbc`},{token:`keyword.operator`,foreground:`9ea0a8`},{token:`type`,foreground:`6cb6ff`},{token:`type.identifier`,foreground:`6cb6ff`},{token:`type.parameter`,foreground:`eeede7`},{token:`function`,foreground:`6cb6ff`},{token:`predefined`,foreground:`6cb6ff`},{token:`variable`,foreground:`eeede7`},{token:`variable.parameter`,foreground:`f2a23a`},{token:`variable.readonly`,foreground:`f2a23a`},{token:`variable.language`,foreground:`f28dbc`},{token:`tag`,foreground:`f47a95`},{token:`metatag`,foreground:`f47a95`},{token:`tag.html`,foreground:`f47a95`},{token:`tag.jsx`,foreground:`f47a95`},{token:`tag.tsx`,foreground:`f47a95`},{token:`attribute.name`,foreground:`ffb055`},{token:`attribute.value`,foreground:`64d488`},{token:`attribute.name.html`,foreground:`ffb055`},{token:`attribute.name.jsx`,foreground:`ffb055`},{token:`regexp`,foreground:`49d3c5`},{token:`delimiter`,foreground:`9ea0a8`},{token:`delimiter.bracket`,foreground:`9ea0a8`},{token:`delimiter.parenthesis`,foreground:`9ea0a8`},{token:`delimiter.curly`,foreground:`9ea0a8`},{token:`delimiter.square`,foreground:`9ea0a8`},{token:`delimiter.array`,foreground:`9ea0a8`},{token:`operator`,foreground:`9ea0a8`},{token:`constant`,foreground:`f2a23a`},{token:`constant.language`,foreground:`f28dbc`},{token:`support`,foreground:`6cb6ff`},{token:`support.function`,foreground:`6cb6ff`},{token:`support.type`,foreground:`6cb6ff`},{token:`support.constant`,foreground:`f2a23a`},{token:`support.variable`,foreground:`eeede7`},{token:`storage`,foreground:`f28dbc`},{token:`storage.modifier`,foreground:`f28dbc`},{token:`storage.type`,foreground:`6cb6ff`},{token:`entity.name.type`,foreground:`6cb6ff`},{token:`entity.name.function`,foreground:`6cb6ff`},{token:`entity.other.inherited-class`,foreground:`6cb6ff`},{token:`entity.name.tag`,foreground:`f47a95`},{token:`entity.other.attribute-name`,foreground:`ffb055`},{token:`invalid`,foreground:`d63c3c`},{token:`invalid.deprecated`,foreground:`d63c3c`},{token:`emphasis`,fontStyle:`italic`},{token:`strong`,fontStyle:`bold`},{token:`header`,foreground:`6cb6ff`,fontStyle:`bold`},{token:`link`,foreground:`49d3c5`,fontStyle:`underline`},{token:`class`,foreground:`6cb6ff`},{token:`interface`,foreground:`49d3c5`},{token:`enum`,foreground:`f2a23a`},{token:`enumMember`,foreground:`f2a23a`},{token:`typeParameter`,foreground:`f2a23a`},{token:`namespace`,foreground:`6cb6ff`},{token:`method`,foreground:`6cb6ff`},{token:`property`,foreground:`eeede7`},{token:`property.readonly`,foreground:`f2a23a`},{token:`property.static`,foreground:`eeede7`},{token:`parameter`,foreground:`f2a23a`},{token:`variable.defaultLibrary`,foreground:`6cb6ff`},{token:`function.defaultLibrary`,foreground:`6cb6ff`},{token:`macro`,foreground:`c4a0ff`},{token:`decorator`,foreground:`c4a0ff`},{token:`label`,foreground:`f2a23a`},{token:`comment.deprecated`,foreground:`6e717a`,fontStyle:`italic strikethrough`},{token:`variable.deprecated`,foreground:`6e717a`,fontStyle:`strikethrough`}],colors:{"editor.background":`#121318`,"editor.foreground":`#eeede7`,"editorCursor.foreground":`#f2a23a`,"editor.selectionBackground":`#f2a23a25`,"editor.selectionHighlightBackground":`#f2a23a15`,"editor.inactiveSelectionBackground":`#f2a23a10`,"editor.lineHighlightBackground":`#1a1c23`,"editorLineNumber.foreground":`#4a4d55`,"editorLineNumber.activeForeground":`#9ea0a8`,"editorRuler.foreground":`#1e2028`,"editorBracketMatch.background":`#f2a23a15`,"editorBracketMatch.border":`#f2a23a30`,"editor.findMatchBackground":`#f2a23a30`,"editor.findMatchHighlightBackground":`#f2a23a15`,"editorWidget.background":`#1a1c23`,"editorWidget.border":`#262830`,"editorSuggestWidget.background":`#1a1c23`,"editorSuggestWidget.border":`#262830`,"editorSuggestWidget.selectedBackground":`#262830`,"editorHoverWidget.background":`#1a1c23`,"editorHoverWidget.border":`#262830`,"scrollbar.shadow":`#00000000`,"scrollbarSlider.background":`#4a4d5530`,"scrollbarSlider.hoverBackground":`#f2a23a50`,"scrollbarSlider.activeBackground":`#f2a23a70`,"minimap.background":`#121318`,"diffEditor.insertedTextBackground":`#64d48815`,"diffEditor.removedTextBackground":`#d63c3c15`,"sideBar.background":`#121318`,"sideBar.border":`#1e2028`,"input.background":`#1a1c23`,"input.border":`#262830`,"input.foreground":`#eeede7`,"input.placeholderForeground":`#6e717a`,focusBorder:`#f2a23a40`,"list.activeSelectionBackground":`#262830`,"list.hoverBackground":`#1e2028`,"dropdown.background":`#1a1c23`,"dropdown.border":`#262830`,"badge.background":`#f2a23a`,"badge.foreground":`#1a1208`,"editorBracketHighlighting.foreground1":`#f2a23a`,"editorBracketHighlighting.foreground2":`#6cb6ff`,"editorBracketHighlighting.foreground3":`#f28dbc`,"editorBracketHighlighting.foreground4":`#64d488`,"editorBracketHighlighting.foreground5":`#49d3c5`,"editorBracketHighlighting.foreground6":`#c4a0ff`,"editorBracketPairGuide.background1":`#f2a23a18`,"editorBracketPairGuide.background2":`#6cb6ff18`,"editorBracketPairGuide.background3":`#f28dbc18`,"editorBracketPairGuide.background4":`#64d48818`,"editorBracketPairGuide.background5":`#49d3c518`,"editorBracketPairGuide.background6":`#c4a0ff18`,"editorBracketPairGuide.activeBackground1":`#f2a23a30`,"editorBracketPairGuide.activeBackground2":`#6cb6ff30`,"editorBracketPairGuide.activeBackground3":`#f28dbc30`,"editorBracketPairGuide.activeBackground4":`#64d48830`,"editorBracketPairGuide.activeBackground5":`#49d3c530`,"editorBracketPairGuide.activeBackground6":`#c4a0ff30`}}),Nn.defineTheme(`wrongstack-light`,{base:`vs`,inherit:!0,rules:[{token:`comment`,foreground:`9a9d99`,fontStyle:`italic`},{token:`comment.line`,foreground:`9a9d99`,fontStyle:`italic`},{token:`comment.block`,foreground:`9a9d99`,fontStyle:`italic`},{token:`comment.documentation`,foreground:`9a9d99`,fontStyle:`italic`},{token:`string`,foreground:`3b8c5a`},{token:`string.escape`,foreground:`17998e`},{token:`string.template`,foreground:`3b8c5a`},{token:`number`,foreground:`d97a12`},{token:`number.hex`,foreground:`d97a12`},{token:`number.float`,foreground:`d97a12`},{token:`keyword`,foreground:`d65a9a`},{token:`keyword.control`,foreground:`d65a9a`},{token:`keyword.operator`,foreground:`6b6d72`},{token:`type`,foreground:`3178c6`},{token:`type.identifier`,foreground:`3178c6`},{token:`type.parameter`,foreground:`1a1c23`},{token:`function`,foreground:`3178c6`},{token:`predefined`,foreground:`3178c6`},{token:`variable`,foreground:`1a1c23`},{token:`variable.parameter`,foreground:`d97a12`},{token:`variable.readonly`,foreground:`d97a12`},{token:`variable.language`,foreground:`d65a9a`},{token:`tag`,foreground:`c93a5e`},{token:`metatag`,foreground:`c93a5e`},{token:`tag.html`,foreground:`c93a5e`},{token:`tag.jsx`,foreground:`c93a5e`},{token:`tag.tsx`,foreground:`c93a5e`},{token:`attribute.name`,foreground:`d4893a`},{token:`attribute.value`,foreground:`3b8c5a`},{token:`attribute.name.html`,foreground:`d4893a`},{token:`attribute.name.jsx`,foreground:`d4893a`},{token:`regexp`,foreground:`17998e`},{token:`delimiter`,foreground:`6b6d72`},{token:`delimiter.bracket`,foreground:`6b6d72`},{token:`delimiter.parenthesis`,foreground:`6b6d72`},{token:`delimiter.curly`,foreground:`6b6d72`},{token:`delimiter.square`,foreground:`6b6d72`},{token:`delimiter.array`,foreground:`6b6d72`},{token:`operator`,foreground:`6b6d72`},{token:`constant`,foreground:`d97a12`},{token:`constant.language`,foreground:`d65a9a`},{token:`support`,foreground:`3178c6`},{token:`support.function`,foreground:`3178c6`},{token:`support.type`,foreground:`3178c6`},{token:`support.constant`,foreground:`d97a12`},{token:`support.variable`,foreground:`1a1c23`},{token:`storage`,foreground:`d65a9a`},{token:`storage.modifier`,foreground:`d65a9a`},{token:`storage.type`,foreground:`3178c6`},{token:`entity.name.type`,foreground:`3178c6`},{token:`entity.name.function`,foreground:`3178c6`},{token:`entity.other.inherited-class`,foreground:`3178c6`},{token:`entity.name.tag`,foreground:`c93a5e`},{token:`entity.other.attribute-name`,foreground:`d4893a`},{token:`invalid`,foreground:`d63c3c`},{token:`invalid.deprecated`,foreground:`d63c3c`},{token:`emphasis`,fontStyle:`italic`},{token:`strong`,fontStyle:`bold`},{token:`header`,foreground:`3178c6`,fontStyle:`bold`},{token:`link`,foreground:`17998e`,fontStyle:`underline`},{token:`class`,foreground:`3178c6`},{token:`interface`,foreground:`17998e`},{token:`enum`,foreground:`d97a12`},{token:`enumMember`,foreground:`d97a12`},{token:`typeParameter`,foreground:`d97a12`},{token:`namespace`,foreground:`3178c6`},{token:`method`,foreground:`3178c6`},{token:`property`,foreground:`1a1c23`},{token:`property.readonly`,foreground:`d97a12`},{token:`property.static`,foreground:`1a1c23`},{token:`parameter`,foreground:`d97a12`},{token:`variable.defaultLibrary`,foreground:`3178c6`},{token:`function.defaultLibrary`,foreground:`3178c6`},{token:`macro`,foreground:`8b5cf6`},{token:`decorator`,foreground:`8b5cf6`},{token:`label`,foreground:`d97a12`},{token:`comment.deprecated`,foreground:`9a9d99`,fontStyle:`italic strikethrough`},{token:`variable.deprecated`,foreground:`9a9d99`,fontStyle:`strikethrough`}],colors:{"editor.background":`#f7f7f5`,"editor.foreground":`#1a1c23`,"editorCursor.foreground":`#e07b0e`,"editor.selectionBackground":`#e07b0e18`,"editor.selectionHighlightBackground":`#e07b0e10`,"editor.inactiveSelectionBackground":`#e07b0e08`,"editor.lineHighlightBackground":`#f0efe9`,"editorLineNumber.foreground":`#bab8b0`,"editorLineNumber.activeForeground":`#6b6d72`,"editorRuler.foreground":`#e8e6de`,"editorBracketMatch.background":`#e07b0e12`,"editorBracketMatch.border":`#e07b0e25`,"editor.findMatchBackground":`#e07b0e25`,"editor.findMatchHighlightBackground":`#e07b0e12`,"editorWidget.background":`#f7f7f5`,"editorWidget.border":`#ddd9d0`,"editorSuggestWidget.background":`#f7f7f5`,"editorSuggestWidget.border":`#ddd9d0`,"editorSuggestWidget.selectedBackground":`#eeece2`,"editorHoverWidget.background":`#f7f7f5`,"editorHoverWidget.border":`#ddd9d0`,"scrollbar.shadow":`#00000000`,"scrollbarSlider.background":`#bab8b040`,"scrollbarSlider.hoverBackground":`#e07b0e50`,"scrollbarSlider.activeBackground":`#e07b0e70`,"minimap.background":`#f7f7f5`,"diffEditor.insertedTextBackground":`#3b8c5a12`,"diffEditor.removedTextBackground":`#d63c3c12`,"sideBar.background":`#f7f7f5`,"sideBar.border":`#e8e6de`,"input.background":`#ffffff`,"input.border":`#ddd9d0`,"input.foreground":`#1a1c23`,"input.placeholderForeground":`#9a9d99`,focusBorder:`#e07b0e35`,"list.activeSelectionBackground":`#eeece2`,"list.hoverBackground":`#f0efe9`,"dropdown.background":`#ffffff`,"dropdown.border":`#ddd9d0`,"badge.background":`#e07b0e`,"badge.foreground":`#ffffff`,"editorBracketHighlighting.foreground1":`#d97a12`,"editorBracketHighlighting.foreground2":`#3178c6`,"editorBracketHighlighting.foreground3":`#d65a9a`,"editorBracketHighlighting.foreground4":`#3b8c5a`,"editorBracketHighlighting.foreground5":`#17998e`,"editorBracketHighlighting.foreground6":`#8b5cf6`,"editorBracketPairGuide.background1":`#d97a1215`,"editorBracketPairGuide.background2":`#3178c615`,"editorBracketPairGuide.background3":`#d65a9a15`,"editorBracketPairGuide.background4":`#3b8c5a15`,"editorBracketPairGuide.background5":`#17998e15`,"editorBracketPairGuide.background6":`#8b5cf615`,"editorBracketPairGuide.activeBackground1":`#d97a1228`,"editorBracketPairGuide.activeBackground2":`#3178c628`,"editorBracketPairGuide.activeBackground3":`#d65a9a28`,"editorBracketPairGuide.activeBackground4":`#3b8c5a28`,"editorBracketPairGuide.activeBackground5":`#17998e28`,"editorBracketPairGuide.activeBackground6":`#8b5cf628`}});function ko(){return typeof document>`u`||document.documentElement.classList.contains(`dark`)?`wrongstack-dark`:`wrongstack-light`}je.config({monaco:ye});var Ao={ts:`typescript`,tsx:`typescript`,js:`javascript`,jsx:`javascript`,json:`json`,css:`css`,html:`html`,svg:`xml`,md:`markdown`,yml:`yaml`,yaml:`yaml`,toml:`toml`,sh:`shell`,bash:`shell`,ps1:`powershell`,py:`python`,rs:`rust`,go:`go`,rb:`ruby`,java:`java`,c:`c`,cpp:`cpp`,h:`c`,hpp:`cpp`,sql:`sql`,xml:`xml`};function jo(e){return Ao[e.split(`.`).pop()?.toLowerCase()??``]??`plaintext`}function Mo(){let e=q(e=>e.openFiles),t=q(e=>e.activeFilePath),n=q(e=>e.setActiveFile),r=q(e=>e.closeFile);return e.length===0?null:(0,G.jsx)(`div`,{className:`flex items-center border-b bg-muted/40 overflow-x-auto shrink-0`,children:e.map(e=>{let i=e.path===t,a=e.path.split(`/`).pop()??e.path;return(0,G.jsxs)(`button`,{type:`button`,onClick:()=>n(e.path),onMouseDown:t=>{t.button===1&&(t.preventDefault(),r(e.path))},className:Y(`group flex items-center gap-1.5 px-3 py-1.5 text-[11px] border-r whitespace-nowrap min-w-0 max-w-[180px] transition-colors`,i?`bg-background border-t-2 border-t-primary text-foreground -mb-px`:`text-muted-foreground hover:bg-muted/60 hover:text-foreground`),title:e.path,children:[e.dirty&&(0,G.jsx)(nn,{className:`h-2 w-2 fill-current text-primary shrink-0`}),(0,G.jsx)(`span`,{className:`truncate`,children:a}),(0,G.jsx)(F,{className:Y(`h-3 w-3 shrink-0 rounded-sm hover:bg-muted-foreground/20 opacity-0 group-hover:opacity-100 transition-opacity`,i&&`opacity-100`),onClick:t=>{t.stopPropagation(),r(e.path)}})]},e.path)})})}function No(){let e=q(e=>e.openFiles),t=q(e=>e.activeFilePath),n=q(e=>e.updateContent),{theme:r}=Pi(),i=(0,z.useRef)(null),a=(0,z.useMemo)(()=>e.find(e=>e.path===t)??null,[e,t]),o=t?jo(t):`plaintext`,c=ko();(0,z.useEffect)(()=>{let e=ko();Nn.setTheme(e)},[r]);let l=(0,z.useCallback)(e=>{i.current=e,Nn.setTheme(ko())},[]),u=(0,z.useCallback)(e=>{t&&e!==void 0&&n(t,e)},[t,n]);return(0,z.useEffect)(()=>{let e=e=>{let n=e.ctrlKey||e.metaKey,r=e.target?.tagName?.toLowerCase()===`textarea`||e.target?.closest(`.monaco-editor`)!==null;!n||!r||(e.key.toLowerCase()===`s`&&(e.preventDefault(),window.dispatchEvent(new CustomEvent(`wrongstack:save-file`,{detail:{filePath:t}}))),e.key.toLowerCase()===`w`&&(e.preventDefault(),t&&q.getState().closeFile(t)))};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[t]),e.length===0?(0,G.jsx)(`div`,{className:`flex-1 flex items-center justify-center`,children:(0,G.jsxs)(`div`,{className:`text-center space-y-2`,children:[(0,G.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`No files open`}),(0,G.jsx)(`p`,{className:`text-[11px] text-muted-foreground/60`,children:`Select a file from the explorer to start editing`})]})}):(0,G.jsxs)(`div`,{className:`flex-1 flex flex-col overflow-hidden`,children:[(0,G.jsx)(Mo,{}),(0,G.jsx)(`div`,{className:`flex-1 relative`,children:a?(0,G.jsx)(s,{language:o,value:a.content,onChange:u,theme:c,onMount:l,loading:(0,G.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,G.jsx)(`span`,{className:`text-[11px] text-muted-foreground animate-pulse`,children:`Loading editor…`})}),options:{minimap:{enabled:!1},fontSize:13,fontFamily:`'IBM Plex Mono', 'Cascadia Code', 'Fira Code', 'JetBrains Mono', monospace`,lineNumbers:`on`,renderWhitespace:`selection`,scrollBeyondLastLine:!1,wordWrap:`off`,tabSize:2,smoothScrolling:!0,cursorBlinking:`smooth`,cursorSmoothCaretAnimation:`on`,bracketPairColorization:{enabled:!0},"semanticHighlighting.enabled":!0,automaticLayout:!0,padding:{top:8}}},a.path):(0,G.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,G.jsx)(`p`,{className:`text-[11px] text-muted-foreground`,children:`Select a tab to view its content`})})})]})}var Po=y,Fo=re,Io=me,Lo=z.forwardRef(({className:e,...t},n)=>(0,G.jsx)(le,{ref:n,className:Y(`fixed inset-0 z-50 bg-black/80 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0`,e),...t}));Lo.displayName=le.displayName;var Ro=z.forwardRef(({className:e,children:t,...n},r)=>(0,G.jsxs)(Io,{children:[(0,G.jsx)(Lo,{}),(0,G.jsxs)(At,{ref:r,className:Y(`fixed left-[50%] top-[50%] z-50 grid w-full max-w-lg translate-x-[-50%] translate-y-[-50%] gap-4 border bg-background p-6 shadow-lg duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%] sm:rounded-lg`,e),...n,children:[t,(0,G.jsxs)(i,{className:`absolute right-4 top-4 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-accent data-[state=open]:text-muted-foreground`,children:[(0,G.jsx)(F,{className:`h-4 w-4`}),(0,G.jsx)(`span`,{className:`sr-only`,children:`Close`})]})]})]}));Ro.displayName=At.displayName;var zo=({className:e,...t})=>(0,G.jsx)(`div`,{className:Y(`flex flex-col space-y-1.5 text-center sm:text-left`,e),...t});zo.displayName=`DialogHeader`;var Bo=({className:e,...t})=>(0,G.jsx)(`div`,{className:Y(`flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2`,e),...t});Bo.displayName=`DialogFooter`;var Vo=z.forwardRef(({className:e,...t},n)=>(0,G.jsx)(O,{ref:n,className:Y(`text-lg font-semibold leading-none tracking-tight`,e),...t}));Vo.displayName=O.displayName;var Ho=z.forwardRef(({className:e,...t},n)=>(0,G.jsx)(oe,{ref:n,className:Y(`text-sm text-muted-foreground`,e),...t}));Ho.displayName=oe.displayName;function Uo(e){return/edit|write|create|patch/i.test(e)?_:/bash|shell|exec|run|command/i.test(e)?_t:/fetch|http|web|curl|request/i.test(e)?Qt:t}function Wo({toolName:e,input:t}){let n=Xa(e,t);if(n)return(0,G.jsx)(`div`,{className:`rounded-lg overflow-hidden border`,children:(0,G.jsx)(qa,{oldText:n.oldText,newText:n.newText,caption:n.caption})});if(typeof t==`object`&&t){let e=t,n=e.command??e.cmd??e.script;if(typeof n==`string`&&n.trim().length>0)return(0,G.jsxs)(`div`,{className:`rounded-lg border bg-background/40 overflow-hidden`,children:[(0,G.jsxs)(`div`,{className:`px-3 py-1.5 text-[10px] uppercase tracking-wider text-muted-foreground border-b bg-muted/40 flex items-center gap-1.5`,children:[(0,G.jsx)(_t,{className:`h-3 w-3`}),(0,G.jsx)(`span`,{children:`Command`})]}),(0,G.jsxs)(`pre`,{className:`px-3 py-2 text-xs font-mono whitespace-pre-wrap break-all max-h-40 overflow-auto`,children:[`$`,n]})]});let r=e.url;if(typeof r==`string`)return(0,G.jsxs)(`div`,{className:`rounded-lg border bg-background/40 px-3 py-2 text-xs font-mono`,children:[(0,G.jsx)(`span`,{className:`text-muted-foreground`,children:(e.method??`GET`).toUpperCase()}),` `,(0,G.jsx)(`span`,{className:`break-all`,children:r})]})}return(0,G.jsxs)(`div`,{className:`p-3 rounded-lg bg-muted/50 border text-xs font-mono`,children:[(0,G.jsx)(`div`,{className:`text-muted-foreground mb-2`,children:`Input:`}),(0,G.jsx)(`pre`,{className:`whitespace-pre-wrap break-all max-h-60 overflow-auto`,children:JSON.stringify(t,null,2)})]})}function Go(){let{showConfirmDialog:e,confirmInfo:t,hideConfirm:n}=W(),{sendConfirm:r}=Z(),i=(0,z.useRef)(null),a=e=>{t&&r(t.id,e),n()};if((0,z.useEffect)(()=>{if(!e)return;let t=e=>{let t=e.target?.tagName?.toLowerCase();t===`input`||t===`textarea`||(e.key===`y`||e.key===`Y`?(e.preventDefault(),a(`yes`)):e.key===`n`||e.key===`N`||e.key===`Escape`?(e.preventDefault(),a(`no`)):e.key===`a`||e.key===`A`?(e.preventDefault(),a(`always`)):(e.key===`d`||e.key===`D`)&&(e.preventDefault(),a(`deny`)))};return window.addEventListener(`keydown`,t),i.current?.focus(),()=>window.removeEventListener(`keydown`,t)},[e,t?.id]),!t)return(0,G.jsx)(Po,{open:e,onOpenChange:()=>n(),children:(0,G.jsx)(Ro,{})});let o=Uo(t.toolName),s=/edit|write/i.test(t.toolName);return(0,G.jsx)(Po,{open:e,onOpenChange:()=>n(),children:(0,G.jsxs)(Ro,{className:`sm:max-w-2xl border-yellow-500/50`,ref:i,tabIndex:-1,children:[(0,G.jsxs)(zo,{children:[(0,G.jsxs)(Vo,{className:`flex items-center gap-2`,children:[(0,G.jsx)(f,{className:`h-5 w-5 text-yellow-500 animate-pulse`}),`Approval required: `,t.toolName]}),(0,G.jsxs)(Ho,{children:[`The agent wants to `,s?`modify a file`:`run this tool`,`. Review the request below and decide whether to proceed.`]})]}),(0,G.jsxs)(`div`,{className:`py-2 space-y-3`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-3 p-3 rounded-lg bg-muted`,children:[(0,G.jsx)(o,{className:`h-5 w-5 text-muted-foreground`}),(0,G.jsxs)(`div`,{className:`min-w-0`,children:[(0,G.jsx)(`div`,{className:`font-medium font-mono truncate`,children:t.toolName}),(0,G.jsxs)(`div`,{className:`text-xs text-muted-foreground`,children:[s?`File modification`:`Tool execution`,` β€” preview below`]})]})]}),t.input!==void 0&&(0,G.jsx)(Wo,{toolName:t.toolName,input:t.input}),t.suggestedPattern&&(0,G.jsxs)(`div`,{className:`flex items-start gap-2 p-3 rounded-lg bg-yellow-500/10 border border-yellow-500/20`,children:[(0,G.jsx)(dn,{className:`h-4 w-4 text-yellow-600 mt-0.5 shrink-0`}),(0,G.jsxs)(`div`,{className:`text-sm min-w-0`,children:[(0,G.jsx)(`div`,{className:`font-medium text-yellow-800 dark:text-yellow-200`,children:`Trust pattern suggestion`}),(0,G.jsx)(`div`,{className:`font-mono text-xs mt-1 break-all`,children:t.suggestedPattern}),(0,G.jsxs)(`div`,{className:`text-xs text-muted-foreground mt-1`,children:[`Picking `,(0,G.jsx)(`span`,{className:`font-medium`,children:`Always`}),` will whitelist matching calls for this project.`]})]})]})]}),(0,G.jsxs)(Bo,{className:`gap-2 sm:gap-2 flex-wrap`,children:[(0,G.jsxs)(Q,{variant:`outline`,size:`sm`,onClick:()=>a(`deny`),title:`Reject this and all future calls matching the pattern (d)`,children:[`Deny always `,(0,G.jsx)(`kbd`,{className:`ml-1 text-[10px] border rounded px-1 bg-background`,children:`d`})]}),(0,G.jsxs)(Q,{variant:`outline`,size:`sm`,onClick:()=>a(`no`),title:`Reject this single call (Esc / n)`,children:[`No `,(0,G.jsx)(`kbd`,{className:`ml-1 text-[10px] border rounded px-1 bg-background`,children:`n`})]}),(0,G.jsxs)(Q,{variant:`outline`,size:`sm`,onClick:()=>a(`always`),title:`Approve and remember the pattern for the project (a)`,children:[`Always `,(0,G.jsx)(`kbd`,{className:`ml-1 text-[10px] border rounded px-1 bg-background`,children:`a`})]}),(0,G.jsxs)(Q,{size:`sm`,onClick:()=>a(`yes`),title:`Approve this single call (y)`,children:[`Yes `,(0,G.jsx)(`kbd`,{className:`ml-1 text-[10px] border rounded px-1 bg-background/80`,children:`y`})]})]})]})})}var Ko=bt()((e,t)=>({request:null,open:n=>{t().request?.resolve(!1),e({request:n})},settle:n=>{t().request?.resolve(n),e({request:null})}}));function qo(e){return new Promise(t=>{Ko.getState().open({...e,resolve:t})})}function Jo(){let e=Ko(e=>e.request),t=Ko(e=>e.settle);return(0,z.useEffect)(()=>{if(!e)return;let t=e=>{e.key===`Enter`&&(e.preventDefault(),Ko.getState().settle(!0))};return window.addEventListener(`keydown`,t),()=>window.removeEventListener(`keydown`,t)},[e]),(0,G.jsx)(Po,{open:e!==null,onOpenChange:e=>{e||t(!1)},children:(0,G.jsxs)(Ro,{className:`max-w-md`,children:[(0,G.jsxs)(zo,{children:[(0,G.jsx)(Vo,{children:e?.title}),e?.message&&(0,G.jsx)(Ho,{children:e.message})]}),(0,G.jsxs)(Bo,{className:`gap-2`,children:[(0,G.jsx)(Q,{variant:`outline`,size:`sm`,onClick:()=>t(!1),children:e?.cancelLabel??`Cancel`}),(0,G.jsx)(Q,{variant:e?.danger?`destructive`:`default`,size:`sm`,autoFocus:!0,onClick:()=>t(!0),children:e?.confirmLabel??`Confirm`})]})]})})}function Yo(){let e=H(e=>e.wsStatus),t=H(e=>e.wsUrl),[n,r]=(0,z.useState)(!1),[i,a]=(0,z.useState)(Date.now());if((0,z.useEffect)(()=>{if(e.state!==`reconnecting`)return;let t=setInterval(()=>a(Date.now()),500);return()=>clearInterval(t)},[e.state]),(0,z.useEffect)(()=>{e.state===`open`&&r(!1)},[e.state]),e.state===`open`||e.state===`connecting`||n)return null;let o=()=>B(t).retryNow(),s=e.state===`reconnecting`,c=e.state===`closed`?e.error:e.state===`reconnecting`?e.lastError:void 0,l=s?Math.max(0,Math.ceil((e.nextRetryAt-i)/1e3)):0;return(0,G.jsxs)(`div`,{className:Y(`flex items-center gap-3 px-4 py-2 border-b text-sm`,s?`bg-orange-500/10 text-orange-700 dark:text-orange-300 border-orange-500/30`:`bg-red-500/10 text-red-700 dark:text-red-300 border-red-500/30`),children:[s?(0,G.jsx)(I,{className:`h-4 w-4 animate-spin shrink-0`}):(0,G.jsx)(hn,{className:`h-4 w-4 shrink-0`}),(0,G.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,G.jsx)(`div`,{className:`font-medium`,children:s?`Reconnecting to backend (attempt ${e.attempt}) β€” retrying in ${l}s`:`Disconnected from backend`}),c&&(0,G.jsx)(`div`,{className:`text-xs opacity-80 truncate`,children:c})]}),(0,G.jsxs)(`button`,{type:`button`,onClick:o,className:Y(`inline-flex items-center gap-1 px-2.5 py-1 rounded-md border text-xs font-medium`,`hover:bg-background/30 transition-colors shrink-0`,s?`border-orange-500/40`:`border-red-500/40`),title:`Retry connection now`,children:[(0,G.jsx)(pe,{className:`h-3 w-3`}),`Retry now`]}),(0,G.jsx)(`button`,{type:`button`,onClick:()=>r(!0),className:`text-current/60 hover:text-current shrink-0`,title:`Dismiss (chip in topbar still shows status)`,children:(0,G.jsx)(F,{className:`h-4 w-4`})})]})}var Xo=class extends z.Component{state={error:null};static getDerivedStateFromError(e){return{error:e}}componentDidCatch(e,t){console.error(`[ErrorBoundary]`,e,t.componentStack),this.props.onError?.(e,t)}handleReset=()=>{this.setState({error:null})};render(){return this.state.error?(0,G.jsx)(`div`,{className:`flex items-center justify-center h-screen bg-background`,children:(0,G.jsxs)(`div`,{className:`flex flex-col items-center gap-4 p-8 max-w-md text-center`,children:[(0,G.jsx)(dn,{className:`h-12 w-12 text-destructive`}),(0,G.jsx)(`h1`,{className:`text-lg font-semibold`,children:`Something went wrong`}),(0,G.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`A rendering error occurred. Your session is still active on the server β€” reloading will pick up where you left off.`}),(0,G.jsx)(`pre`,{className:`text-xs font-mono text-muted-foreground bg-muted/50 rounded p-3 max-h-32 overflow-auto w-full text-left`,children:this.state.error.message}),(0,G.jsxs)(`div`,{className:`flex gap-2`,children:[(0,G.jsxs)(Q,{size:`sm`,variant:`outline`,onClick:()=>window.location.reload(),children:[(0,G.jsx)(Mt,{className:`h-4 w-4 mr-1`}),`Reload page`]}),(0,G.jsx)(Q,{size:`sm`,onClick:this.handleReset,children:`Try again`})]})]})}):this.props.children}};function Zo(e,t,n,r,i){let a=[];for(let n of e){let e=t[n.id]??[];for(let t of e)a.push({provider:n.id,model:t.id,modelName:t.name||t.id,contextWindow:t.contextWindow,isCurrent:n.id===r&&t.id===i})}let o=n.toLowerCase().trim();return(o?a.filter(e=>e.provider.toLowerCase().includes(o)||e.model.toLowerCase().includes(o)||e.modelName.toLowerCase().includes(o)):a).sort((e,t)=>e.isCurrent===t.isCurrent?e.provider.localeCompare(t.provider)||e.model.localeCompare(t.model):e.isCurrent?-1:1)}function Qo(){let e=W(e=>e.modelSwitcherOpen),t=W(e=>e.setModelSwitcherOpen),[n,r]=(0,z.useState)(``),[i,a]=(0,z.useState)(0),[o,s]=(0,z.useState)([]),[c,l]=(0,z.useState)({}),u=(0,z.useRef)(null),d=H(e=>e.wsUrl),f=H(e=>e.provider),p=H(e=>e.model),m=W(e=>e.paletteOpen),{listSavedProviders:h,listProviderModels:g,switchModel:_}=Z();(0,z.useEffect)(()=>{let n=n=>{if((n.ctrlKey||n.metaKey)&&n.key.toLowerCase()===`m`&&!n.shiftKey&&!n.altKey){if(m)return;n.preventDefault(),t(!e);return}n.key===`Escape`&&e&&(n.preventDefault(),t(!1))};return window.addEventListener(`keydown`,n),()=>window.removeEventListener(`keydown`,n)},[e,m]),(0,z.useEffect)(()=>{let e=B(d),t=e.on(`providers.saved`,e=>{let t=e.payload;s(t.providers??[])}),n=e.on(`provider.models`,e=>{let t=e.payload;l(e=>({...e,[t.provider]:t.models}))});return()=>{t(),n()}},[d]),(0,z.useEffect)(()=>{e&&(r(``),a(0),h(),requestAnimationFrame(()=>u.current?.focus()))},[e,h]),(0,z.useEffect)(()=>{if(e)for(let e of o)c[e.id]||g(e.id)},[e,o,c,g]);let y=(0,z.useMemo)(()=>Zo(o,c,n,f,p),[o,c,n,f,p]);(0,z.useEffect)(()=>{i>=y.length&&a(0)},[y.length,i]);let b=e=>{let n=y[e];n&&(_(n.provider,n.model),t(!1))};return e?(0,G.jsx)(`div`,{className:`fixed inset-0 z-50 flex items-start justify-center bg-background/60 backdrop-blur-sm pt-[15vh]`,onClick:e=>{e.target===e.currentTarget&&t(!1)},onKeyDown:e=>{e.key===`Escape`&&t(!1)},children:(0,G.jsxs)(`div`,{className:`w-full max-w-xl rounded-xl border bg-popover shadow-2xl overflow-hidden`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 border-b px-3 py-2`,children:[(0,G.jsx)(v,{className:`h-4 w-4 text-muted-foreground`}),(0,G.jsx)(`input`,{ref:u,value:n,onChange:e=>{r(e.target.value),a(0)},onKeyDown:e=>{e.key===`ArrowDown`?(e.preventDefault(),a(e=>Math.min(y.length-1,e+1))):e.key===`ArrowUp`?(e.preventDefault(),a(e=>Math.max(0,e-1))):e.key===`Enter`?(e.preventDefault(),b(i)):e.key===`Escape`&&(e.preventDefault(),t(!1))},placeholder:`Filter providers and models…`,className:`flex-1 bg-transparent outline-none text-sm placeholder:text-muted-foreground`}),(0,G.jsx)(`span`,{className:`text-[10px] text-muted-foreground font-mono`,children:`↑↓ Β· Enter Β· Esc`})]}),(0,G.jsx)(`div`,{className:`max-h-[50vh] overflow-y-auto py-1`,children:y.length===0?(0,G.jsx)(`div`,{className:`px-4 py-8 text-center text-sm text-muted-foreground`,children:o.length===0?`No saved providers β€” register a key in Settings first.`:`Loading models…`}):y.map((e,t)=>(0,G.jsxs)(`button`,{type:`button`,onClick:()=>b(t),onMouseEnter:()=>a(t),className:Y(`w-full flex items-center gap-3 px-3 py-2 text-left text-sm transition-colors`,t===i?`bg-accent text-accent-foreground`:`hover:bg-accent/40`,e.isCurrent&&`font-medium`),children:[(0,G.jsx)(E,{className:Y(`h-4 w-4 shrink-0`,e.isCurrent?`text-primary`:`text-muted-foreground`)}),(0,G.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,G.jsxs)(`div`,{className:`truncate`,children:[(0,G.jsx)(`span`,{className:`text-muted-foreground`,children:e.provider}),(0,G.jsx)(`span`,{className:`mx-1 text-muted-foreground/40`,children:`Β·`}),(0,G.jsx)(`span`,{children:e.modelName})]}),e.contextWindow&&(0,G.jsxs)(`div`,{className:`text-[10px] text-muted-foreground font-mono`,children:[e.model,` Β· ctx `,e.contextWindow.toLocaleString()]})]}),e.isCurrent?(0,G.jsx)(`span`,{className:`text-[10px] uppercase tracking-wide text-primary font-semibold`,children:`active`}):(0,G.jsx)(vn,{className:`h-3.5 w-3.5 text-muted-foreground opacity-0 group-hover:opacity-100`})]},`${e.provider}:${e.model}`))})]})}):null}var $o=z.forwardRef(({className:e,type:t,...n},r)=>(0,G.jsx)(`input`,{type:t,className:Y(`flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50`,e),ref:r,...n}));$o.displayName=`Input`;var es=z.forwardRef(({className:e,children:t,...n},r)=>(0,G.jsxs)(g,{ref:r,className:Y(`relative overflow-hidden`,e),...n,children:[(0,G.jsx)(Nt,{className:`h-full w-full rounded-[inherit]`,children:t}),(0,G.jsx)(ts,{}),(0,G.jsx)(Te,{})]}));es.displayName=g.displayName;var ts=z.forwardRef(({className:e,orientation:t=`vertical`,...n},r)=>(0,G.jsx)(p,{ref:r,orientation:t,className:Y(`flex touch-none select-none transition-colors`,t===`vertical`&&`h-full w-2.5 border-l border-l-transparent p-[1px]`,t===`horizontal`&&`h-2.5 flex-col border-t border-t-transparent p-[1px]`,e),...n,children:(0,G.jsx)(de,{className:`relative flex-1 rounded-full bg-border`})}));ts.displayName=p.displayName;var ns=u,rs=z.forwardRef(({className:e,...t},n)=>(0,G.jsx)(Se,{ref:n,className:Y(`inline-flex h-10 items-center justify-center rounded-md bg-muted p-1 text-muted-foreground`,e),...t}));rs.displayName=Se.displayName;var is=z.forwardRef(({className:e,...t},n)=>(0,G.jsx)(wn,{ref:n,className:Y(`inline-flex items-center justify-center whitespace-nowrap rounded-sm px-3 py-1.5 text-sm font-medium ring-offset-background transition-all focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 data-[state=active]:bg-background data-[state=active]:text-foreground data-[state=active]:shadow-sm`,e),...t}));is.displayName=wn.displayName;var as=z.forwardRef(({className:e,...t},n)=>(0,G.jsx)(Dn,{ref:n,className:Y(`mt-2 ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2`,e),...t}));as.displayName=Dn.displayName;function os({label:e,hint:t,selector:n,onChange:r,configKey:i,value:a}){let o=typeof a==`boolean`,s=W(e=>n?n(e):!1),c=H(e=>i?e[i]:!1),l=o?a:n?s:c;return(0,G.jsxs)(`div`,{className:`flex items-start justify-between gap-3 py-2`,children:[(0,G.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,G.jsx)(`div`,{className:`text-sm font-medium`,children:e}),t&&(0,G.jsx)(`div`,{className:`text-xs text-muted-foreground mt-0.5`,children:t})]}),(0,G.jsx)(`button`,{type:`button`,role:`switch`,"aria-checked":l,onClick:()=>{if(o)r?.();else if(n)r?.();else if(i===`soundOnComplete`){let e=!H.getState().soundOnComplete;H.getState().setSoundOnComplete(e),e&&Rr()}},className:Y(`shrink-0 relative inline-flex h-5 w-9 rounded-full border transition-colors`,l?`bg-primary border-primary`:`bg-muted border-input hover:bg-muted/80`),children:(0,G.jsx)(`span`,{className:Y(`absolute top-0.5 left-0.5 h-3.5 w-3.5 rounded-full bg-background shadow transition-transform`,l&&`translate-x-4`)})})]})}function ss({label:e,hint:t,value:n,min:r,max:i,step:a=1,onChange:o,unit:s}){return(0,G.jsxs)(`div`,{className:`flex items-start justify-between gap-3 py-2`,children:[(0,G.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,G.jsx)(`div`,{className:`text-sm font-medium`,children:e}),t&&(0,G.jsx)(`div`,{className:`text-xs text-muted-foreground mt-0.5`,children:t})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2 shrink-0`,children:[(0,G.jsx)(`input`,{type:`range`,min:r,max:i,step:a,value:n,onChange:e=>o(Number(e.target.value)),className:`w-24 h-1.5 accent-primary`}),(0,G.jsxs)(`span`,{className:`text-xs tabular-nums w-10 text-right text-muted-foreground`,children:[n,s??``]})]})]})}function cs({label:e,hint:t,value:n,options:r,onChange:i}){return(0,G.jsxs)(`div`,{className:`flex items-start justify-between gap-3 py-2`,children:[(0,G.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,G.jsx)(`div`,{className:`text-sm font-medium`,children:e}),t&&(0,G.jsx)(`div`,{className:`text-xs text-muted-foreground mt-0.5`,children:t})]}),(0,G.jsx)(`select`,{value:n,onChange:e=>i(e.target.value),className:`shrink-0 h-8 rounded-md border bg-background px-2 text-xs`,children:r.map(e=>(0,G.jsx)(`option`,{value:e.value,children:e.label},e.value))})]})}var ls=[`anthropic`,`openai`,`google`,`openai-compatible`];function us({activeProvider:e,catalogProviders:t,isLoadingCatalog:n,savedProviders:r,isLoadingSaved:i,providerTab:a,setProviderTab:o,onSelectProvider:s,onAddKey:c,onDeleteKey:l,onSetActiveKey:u,onAddProvider:d,onRemoveProvider:f,catalogQuery:p,setCatalogQuery:m}){let[h,g]=(0,z.useState)(null),[_,v]=(0,z.useState)(``),[y,b]=(0,z.useState)(``),[x,S]=(0,z.useState)(!1),[C,w]=(0,z.useState)(!1),[T,E]=(0,z.useState)(``),[D,O]=(0,z.useState)(`openai-compatible`),[k,A]=(0,z.useState)(``),[j,M]=(0,z.useState)(``),ee=(0,z.useCallback)(e=>{!_.trim()||!y.trim()||(c(e,_.trim(),y.trim()),v(``),b(``),g(null))},[c,_,y]),te=(0,z.useCallback)(()=>{T.trim()&&(d(T.trim(),D,k||void 0,j||void 0),E(``),O(`openai-compatible`),A(``),M(``),w(!1))},[d,T,D,k,j]),N=p.trim()?t.filter(e=>{let t=p.trim().toLowerCase();return e.id.toLowerCase().includes(t)||e.name.toLowerCase().includes(t)||e.family.toLowerCase().includes(t)}):t,ne=N.reduce((e,t)=>(e[t.family]||(e[t.family]=[]),e[t.family]?.push(t),e),{});return(0,G.jsxs)(`div`,{className:`space-y-4`,children:[(0,G.jsxs)(`div`,{className:`flex gap-2 mb-4`,children:[(0,G.jsxs)(Q,{variant:a===`catalog`?`default`:`outline`,size:`sm`,onClick:()=>o(`catalog`),children:[(0,G.jsx)(Qt,{className:`h-4 w-4 mr-1`}),`Catalog`]}),(0,G.jsxs)(Q,{variant:a===`saved`?`default`:`outline`,size:`sm`,onClick:()=>o(`saved`),children:[(0,G.jsx)(it,{className:`h-4 w-4 mr-1`}),`Saved (`,r.length,`)`]})]}),a===`catalog`&&(0,G.jsxs)(`div`,{className:`space-y-4`,children:[(0,G.jsx)($o,{placeholder:`Search ${t.length} providers (name / id / family)…`,value:p,onChange:e=>m(e.target.value),className:`text-sm`}),n&&t.length===0?(0,G.jsxs)(`div`,{className:`flex items-center justify-center py-8`,children:[(0,G.jsx)(I,{className:`h-6 w-6 animate-spin text-muted-foreground`}),(0,G.jsx)(`span`,{className:`ml-2 text-muted-foreground`,children:`Loading catalog...`})]}):N.length===0&&p?(0,G.jsxs)(`div`,{className:`text-center py-8 text-muted-foreground text-sm`,children:[`No providers match "`,(0,G.jsx)(`span`,{className:`font-mono`,children:p}),`".`]}):(0,G.jsx)(G.Fragment,{children:ls.map(t=>{let n=ne[t];return n?.length?(0,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsx)(`h3`,{className:`text-sm font-semibold text-muted-foreground uppercase tracking-wider`,children:t}),(0,G.jsx)(`div`,{className:`grid grid-cols-1 gap-2`,children:n.map(t=>(0,G.jsxs)(`button`,{type:`button`,onClick:()=>s(t.id),className:Y(`flex flex-col items-start p-3 rounded-lg border text-left transition-all`,e===t.id?`border-primary bg-primary/5 ring-2 ring-primary/20`:`border-border hover:bg-muted`),children:[(0,G.jsxs)(`div`,{className:`flex w-full justify-between items-start`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`span`,{className:`font-medium`,children:t.name}),(0,G.jsxs)(`span`,{className:`ml-2 text-xs text-muted-foreground`,children:[`(`,t.id,`)`]})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[t.hasApiKey&&(0,G.jsxs)(`span`,{className:`text-xs bg-green-500/10 text-green-600 px-2 py-0.5 rounded`,children:[(0,G.jsx)(it,{className:`h-3 w-3 inline mr-1`}),`Configured`]}),t.envVars[0]&&(0,G.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[`ENV: `,t.envVars[0]]}),e===t.id&&(0,G.jsx)(We,{className:`h-4 w-4 text-primary`})]})]}),(0,G.jsxs)(`div`,{className:`text-xs text-muted-foreground mt-1`,children:[t.modelCount,` models`,t.apiBase&&` Β· ${t.apiBase}`]})]},t.id))})]},t):null})})]}),a===`saved`&&(0,G.jsxs)(`div`,{className:`space-y-4`,children:[(0,G.jsxs)(`div`,{className:`flex justify-between items-center`,children:[(0,G.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Manage your API keys and provider configurations`}),(0,G.jsxs)(Q,{size:`sm`,variant:`outline`,onClick:()=>w(!C),children:[(0,G.jsx)(ue,{className:`h-4 w-4 mr-1`}),`Add Provider`]})]}),C&&(0,G.jsxs)(`div`,{className:`p-4 border rounded-lg space-y-3 bg-muted/50`,children:[(0,G.jsx)(`h4`,{className:`font-medium`,children:`Add Custom Provider`}),(0,G.jsx)($o,{placeholder:`Provider ID (e.g. my-llm-server)`,value:T,onChange:e=>E(e.target.value)}),(0,G.jsxs)(`select`,{className:`flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm`,value:D,onChange:e=>O(e.target.value),children:[(0,G.jsx)(`option`,{value:`anthropic`,children:`Anthropic`}),(0,G.jsx)(`option`,{value:`openai`,children:`OpenAI`}),(0,G.jsx)(`option`,{value:`openai-compatible`,children:`OpenAI Compatible`}),(0,G.jsx)(`option`,{value:`google`,children:`Google`})]}),(0,G.jsx)($o,{placeholder:`Base URL (optional, e.g. http://localhost:11434/v1)`,value:k,onChange:e=>A(e.target.value)}),(0,G.jsx)($o,{type:`password`,placeholder:`API Key (optional)`,value:j,onChange:e=>M(e.target.value)}),(0,G.jsxs)(`div`,{className:`flex gap-2`,children:[(0,G.jsx)(Q,{size:`sm`,onClick:te,disabled:!T.trim(),children:`Add`}),(0,G.jsx)(Q,{size:`sm`,variant:`ghost`,onClick:()=>w(!1),children:`Cancel`})]})]}),i?(0,G.jsx)(`div`,{className:`flex items-center justify-center py-8`,children:(0,G.jsx)(I,{className:`h-6 w-6 animate-spin text-muted-foreground`})}):r.length===0?(0,G.jsxs)(`div`,{className:`text-center py-8 text-muted-foreground`,children:[(0,G.jsx)(it,{className:`h-8 w-8 mx-auto mb-2 opacity-50`}),(0,G.jsx)(`p`,{children:`No saved providers yet`}),(0,G.jsx)(`p`,{className:`text-sm`,children:`Add a provider to get started`})]}):r.map(e=>(0,G.jsxs)(`div`,{className:`border rounded-lg p-4 space-y-3`,children:[(0,G.jsxs)(`div`,{className:`flex justify-between items-start`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`h4`,{className:`font-medium`,children:e.id}),e.family&&(0,G.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:e.family})]}),(0,G.jsx)(`div`,{className:`flex gap-2`,children:(0,G.jsx)(Q,{size:`icon`,variant:`ghost`,onClick:()=>f(e.id),children:(0,G.jsx)(yn,{className:`h-4 w-4 text-destructive`})})})]}),e.baseUrl&&(0,G.jsxs)(`div`,{className:`text-xs text-muted-foreground`,children:[(0,G.jsx)(Qt,{className:`h-3 w-3 inline mr-1`}),e.baseUrl]}),(0,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsxs)(`div`,{className:`flex justify-between items-center`,children:[(0,G.jsx)(`span`,{className:`text-sm font-medium`,children:`API Keys`}),(0,G.jsxs)(Q,{size:`sm`,variant:`ghost`,onClick:()=>g(h===e.id?null:e.id),children:[(0,G.jsx)(ue,{className:`h-3 w-3 mr-1`}),`Add Key`]})]}),e.apiKeys.length===0&&!h&&(0,G.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`No keys configured`}),e.apiKeys.map(t=>(0,G.jsxs)(`div`,{className:`flex items-center justify-between p-2 bg-muted/50 rounded`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`span`,{className:`text-sm font-medium`,children:t.label}),t.isActive&&(0,G.jsx)(`span`,{className:`ml-2 text-xs bg-green-500/10 text-green-600 px-1.5 py-0.5 rounded`,children:`Active`}),(0,G.jsx)(`div`,{className:`text-xs text-muted-foreground font-mono`,children:t.maskedKey})]}),(0,G.jsxs)(`div`,{className:`flex gap-1`,children:[!t.isActive&&(0,G.jsx)(Q,{size:`sm`,variant:`ghost`,onClick:()=>u(e.id,t.label),children:`Set Active`}),(0,G.jsx)(Q,{size:`icon`,variant:`ghost`,onClick:()=>l(e.id,t.label),children:(0,G.jsx)(yn,{className:`h-3 w-3 text-destructive`})})]})]},t.label)),h===e.id&&(0,G.jsxs)(`div`,{className:`p-3 border rounded space-y-2 bg-background`,children:[(0,G.jsx)($o,{placeholder:`Key label (e.g. default, production)`,value:_,onChange:e=>v(e.target.value)}),(0,G.jsxs)(`div`,{className:`flex gap-2`,children:[(0,G.jsx)($o,{type:x?`text`:`password`,placeholder:`API key`,value:y,onChange:e=>b(e.target.value)}),(0,G.jsx)(Q,{size:`icon`,variant:`ghost`,onClick:()=>S(!x),children:x?(0,G.jsx)(he,{className:`h-4 w-4`}):(0,G.jsx)(P,{className:`h-4 w-4`})})]}),(0,G.jsxs)(`div`,{className:`flex gap-2`,children:[(0,G.jsx)(Q,{size:`sm`,onClick:()=>ee(e.id),disabled:!_.trim()||!y.trim(),children:`Save Key`}),(0,G.jsx)(Q,{size:`sm`,variant:`ghost`,onClick:()=>{g(null),v(``),b(``)},children:`Cancel`})]})]})]})]},e.id))]})]})}function ds({provider:e,catalogModels:t,currentCatalogProvider:n,isLoadingModels:r,setIsLoadingModels:i,onModelSelect:a,refreshModels:o}){let s=H(e=>e.model);return(0,G.jsx)(`div`,{className:`space-y-4`,children:e?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-sm font-medium`,children:n?.name||e}),(0,G.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:e})]}),(0,G.jsx)(Q,{variant:`ghost`,size:`sm`,onClick:()=>{i(!0),o(e)},children:(0,G.jsx)(Mt,{className:Y(`h-4 w-4`,r&&`animate-spin`)})})]}),r&&!t[e]?(0,G.jsxs)(`div`,{className:`flex items-center justify-center py-8`,children:[(0,G.jsx)(I,{className:`h-6 w-6 animate-spin text-muted-foreground`}),(0,G.jsx)(`span`,{className:`ml-2 text-muted-foreground`,children:`Loading models...`})]}):(0,G.jsxs)(`div`,{className:`space-y-1`,children:[(t[e]||[]).map(e=>(0,G.jsxs)(`button`,{type:`button`,onClick:()=>a(e.id),className:Y(`w-full flex items-center justify-between p-3 rounded-lg border text-left transition-all`,s===e.id?`border-primary bg-primary/5 ring-2 ring-primary/20`:`border-border hover:bg-muted`),children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`span`,{className:`font-medium`,children:e.name||e.id}),(0,G.jsx)(`div`,{className:`flex gap-2 mt-1`,children:e.capabilities.map(e=>(0,G.jsx)(`span`,{className:`text-xs bg-muted px-1.5 py-0.5 rounded`,children:e},e))})]}),(0,G.jsxs)(`div`,{className:`text-right text-xs text-muted-foreground`,children:[e.contextWindow&&(0,G.jsxs)(`div`,{children:[e.contextWindow/1e3,`k context`]}),e.inputCost&&e.outputCost&&(0,G.jsxs)(`div`,{children:[`$`,e.inputCost,`/$`,e.outputCost]}),s===e.id&&(0,G.jsx)(We,{className:`h-4 w-4 text-primary mt-1`})]})]},e.id)),t[e]?.length===0&&(0,G.jsx)(`p`,{className:`text-sm text-muted-foreground text-center py-4`,children:`No models found for this provider. The catalog might be empty or still loading.`})]})]}):(0,G.jsxs)(`div`,{className:`text-center py-8 text-muted-foreground`,children:[(0,G.jsx)(E,{className:`h-8 w-8 mx-auto mb-2 opacity-50`}),(0,G.jsx)(`p`,{children:`Select a provider first`})]})})}function fs(){let{setCurrentView:e}=W(),{provider:t,model:n,setProvider:r,setModel:i,wsConnected:a}=H(),{theme:o,setTheme:s}=Pi(),c=Z(),l=c.client,{updatePrefs:u,switchAutonomy:d}=c,f=Tr(),p=(0,z.useCallback)((e,t)=>{f.set({[e]:t}),u({[e]:t})},[f,u]),[m,h]=(0,z.useState)([]),[g,_]=(0,z.useState)({}),[v,y]=(0,z.useState)([]),[b,x]=(0,z.useState)(!1),[S,C]=(0,z.useState)(!1),[T,O]=(0,z.useState)(!1),[k,A]=(0,z.useState)(`catalog`),[j,M]=(0,z.useState)(``),ee=m.find(e=>e.id===t);(0,z.useEffect)(()=>{let e=e=>{if(e.type===`provider.catalog`){let t=e.payload;h(t.providers.sort((e,t)=>e.id.localeCompare(t.id))),x(!1)}},t=e=>{if(e.type===`provider.models`){let t=e.payload;_(e=>({...e,[t.provider]:t.models})),C(!1)}},n=e=>{if(e.type===`providers.saved`){let t=e.payload.providers.sort((e,t)=>e.id.localeCompare(t.id));y(t),O(!1),t.length>0&&A(`saved`)}};if(!a||!l)return;let r=l.on(`provider.catalog`,e),i=l.on(`provider.models`,t),o=l.on(`providers.saved`,n);return x(!0),O(!0),l.listProviders(),l.listSavedProviders(),()=>{r?.(),i?.(),o?.()}},[a,l]);let te=(0,z.useCallback)(e=>{r(e),g[e]||(C(!0),c.listProviderModels?.(e))},[g,r,c]),N=(0,z.useCallback)(e=>{i(e);let t=H.getState().provider;c.switchModel?.(t,e),X.success(`Switching to ${t} / ${e}…`)},[i,c]),re=(0,z.useCallback)((e,t,n)=>{c.addKey?.(e,t,n)},[c]),ie=(0,z.useCallback)((e,t)=>{c.deleteKey?.(e,t)},[c]),ae=(0,z.useCallback)((e,t)=>{c.setActiveKey?.(e,t)},[c]),oe=(0,z.useCallback)((e,t,n,r)=>{c.addProvider?.(e,t,n,r)},[c]),se=(0,z.useCallback)(e=>{c.removeProvider?.(e)},[c]);return(0,G.jsxs)(`div`,{className:`flex flex-col h-full`,children:[(0,G.jsxs)(`header`,{className:`flex items-center justify-between px-4 py-3 border-b bg-card shrink-0`,children:[(0,G.jsx)(`h1`,{className:`text-lg font-semibold`,children:`Settings`}),(0,G.jsx)(Q,{variant:`ghost`,size:`icon`,onClick:()=>e(`chat`),children:(0,G.jsx)(F,{className:`h-4 w-4`})})]}),(0,G.jsx)(es,{className:`flex-1`,children:(0,G.jsx)(`div`,{className:`p-6 max-w-2xl mx-auto`,children:(0,G.jsxs)(ns,{defaultValue:`provider`,children:[(0,G.jsxs)(rs,{className:`w-full justify-start mb-6 grid grid-cols-5`,children:[(0,G.jsxs)(is,{value:`provider`,className:`gap-1 text-xs`,children:[(0,G.jsx)(Ae,{className:`h-3.5 w-3.5`}),`Provider`]}),(0,G.jsxs)(is,{value:`connection`,className:`gap-1 text-xs`,children:[(0,G.jsx)(Qt,{className:`h-3.5 w-3.5`}),`Connect`]}),(0,G.jsxs)(is,{value:`appearance`,className:`gap-1 text-xs`,children:[(0,G.jsx)(D,{className:`h-3.5 w-3.5`}),`Look`]}),(0,G.jsxs)(is,{value:`agent`,className:`gap-1 text-xs`,children:[(0,G.jsx)(L,{className:`h-3.5 w-3.5`}),`Agent`]}),(0,G.jsxs)(is,{value:`features`,className:`gap-1 text-xs`,children:[(0,G.jsx)(ce,{className:`h-3.5 w-3.5`}),`Feat.`]})]}),(0,G.jsxs)(as,{value:`provider`,className:`space-y-4`,children:[(0,G.jsx)(us,{activeProvider:t,catalogProviders:m,isLoadingCatalog:b,savedProviders:v,isLoadingSaved:T,providerTab:k,setProviderTab:A,onSelectProvider:te,onAddKey:re,onDeleteKey:ie,onSetActiveKey:ae,onAddProvider:oe,onRemoveProvider:se,catalogQuery:j,setCatalogQuery:M}),(0,G.jsxs)(`div`,{className:`pt-4 border-t`,children:[(0,G.jsxs)(`h3`,{className:`text-sm font-semibold mb-3 flex items-center gap-2`,children:[(0,G.jsx)(E,{className:`h-4 w-4 text-muted-foreground`}),`Model`]}),(0,G.jsx)(ds,{provider:t,catalogModels:g,currentCatalogProvider:ee,isLoadingModels:S,setIsLoadingModels:C,onModelSelect:N,refreshModels:e=>c.listProviderModels?.(e)})]})]}),(0,G.jsxs)(as,{value:`connection`,className:`space-y-4`,children:[(0,G.jsxs)(`div`,{className:`space-y-3`,children:[(0,G.jsxs)(`label`,{htmlFor:`websocket-url`,className:`text-sm font-medium flex items-center gap-2`,children:[(0,G.jsx)(Qt,{className:`h-4 w-4 text-muted-foreground`}),`WebSocket Server URL`]}),(0,G.jsx)($o,{id:`websocket-url`,value:H.getState().wsUrl,onChange:e=>H.getState().setConfig({wsUrl:e.target.value}),placeholder:`ws://localhost:3457`,className:`font-mono text-sm`}),(0,G.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`URL of the agent WebSocket server. The server runs alongside the CLI.`})]}),(0,G.jsxs)(`div`,{className:`p-4 rounded-lg border bg-muted/50`,children:[(0,G.jsx)(`h4`,{className:`text-sm font-medium mb-2`,children:`Starting the WebSocket Server`}),(0,G.jsxs)(`p`,{className:`text-xs text-muted-foreground mb-3`,children:[`Standalone: run `,(0,G.jsx)(`code`,{className:`bg-muted px-1 py-0.5 rounded`,children:`./dev.ps1`}),` `,`from the repo root, or set WS_HOST/WS_PORT before launching`,` `,(0,G.jsx)(`code`,{className:`bg-muted px-1 py-0.5 rounded`,children:`node packages/webui/dist/server/entry.js`}),`. Or alongside the CLI:`,` `,(0,G.jsx)(`code`,{className:`bg-muted px-1 py-0.5 rounded`,children:`wstack --webui`}),`.`]})]})]}),(0,G.jsxs)(as,{value:`appearance`,className:`space-y-4`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`h3`,{className:`text-sm font-semibold mb-3`,children:`Theme`}),(0,G.jsxs)(`div`,{className:`grid grid-cols-3 gap-2 max-w-md`,children:[(0,G.jsxs)(Q,{variant:o===`light`?`default`:`outline`,size:`sm`,onClick:()=>s(`light`),children:[(0,G.jsx)(Ut,{className:`h-4 w-4 mr-1`}),`Light`]}),(0,G.jsxs)(Q,{variant:o===`dark`?`default`:`outline`,size:`sm`,onClick:()=>s(`dark`),children:[(0,G.jsx)(w,{className:`h-4 w-4 mr-1`}),`Dark`]}),(0,G.jsxs)(Q,{variant:o===`system`?`default`:`outline`,size:`sm`,onClick:()=>s(`system`),children:[(0,G.jsx)(ne,{className:`h-4 w-4 mr-1`}),`System`]})]}),(0,G.jsx)(`p`,{className:`text-xs text-muted-foreground mt-2`,children:`System follows your OS-level light/dark preference.`})]}),(0,G.jsxs)(`div`,{className:`pt-2 border-t`,children:[(0,G.jsx)(`h3`,{className:`text-sm font-semibold mb-3 mt-3`,children:`Preferences`}),(0,G.jsx)(os,{label:`Compact density`,hint:`Tighter spacing throughout the chat.`,selector:e=>e.compactMode,onChange:()=>W.getState().toggleCompactMode()}),(0,G.jsx)(os,{label:`Sound on completion`,hint:`Play a soft chime when a run finishes.`,selector:null,configKey:`soundOnComplete`})]})]}),(0,G.jsxs)(as,{value:`agent`,className:`space-y-4`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`h3`,{className:`text-sm font-semibold mb-3 flex items-center gap-2`,children:[(0,G.jsx)(Ht,{className:`h-4 w-4 text-muted-foreground`}),`Autonomy & Behavior`]}),(0,G.jsx)(cs,{label:`Autonomy mode`,hint:`How independently the agent proceeds between turns.`,value:f.autonomy,options:[{value:`off`,label:`Off β€” full manual control`},{value:`suggest`,label:`Suggest β€” suggests next steps`},{value:`auto`,label:`Auto β€” brief confirmation delay`},{value:`eternal`,label:`Eternal β€” autonomous until goal done`},{value:`eternal-parallel`,label:`Eternal Parallel β€” multi-agent fleet`}],onChange:e=>{f.set({autonomy:e}),d(e)}}),(0,G.jsx)(ss,{label:`Auto-proceed delay`,hint:`Milliseconds before the agent auto-proceeds in Auto mode. 0 = immediate.`,value:f.autonomyDelayMs,min:0,max:1e4,step:500,unit:`ms`,onChange:e=>p(`autonomyDelayMs`,e)}),(0,G.jsx)(os,{label:`YOLO mode`,hint:`Bypass tool confirmation prompts β€” the agent runs without asking.`,value:f.yolo,onChange:()=>p(`yolo`,!f.yolo)})]}),(0,G.jsxs)(`div`,{className:`pt-2 border-t`,children:[(0,G.jsxs)(`h3`,{className:`text-sm font-semibold mb-3 mt-3 flex items-center gap-2`,children:[(0,G.jsx)(Ue,{className:`h-4 w-4 text-muted-foreground`}),`Prompt Refinement`]}),(0,G.jsx)(os,{label:`Enable refine`,hint:`Rewrite prompts before sending β€” clearer instructions, better results.`,value:f.enhanceEnabled,onChange:()=>p(`enhanceEnabled`,!f.enhanceEnabled)}),(0,G.jsx)(ss,{label:`Refine delay`,hint:`Countdown before the refined prompt auto-sends.`,value:f.enhanceDelayMs,min:3e4,max:12e4,step:15e3,unit:`ms`,onChange:e=>p(`enhanceDelayMs`,e)}),(0,G.jsx)(cs,{label:`Refine language`,hint:`Keep your language or translate to English for the model.`,value:f.enhanceLanguage,options:[{value:`original`,label:`Original β€” keep your language`},{value:`english`,label:`English β€” translate to English`}],onChange:e=>p(`enhanceLanguage`,e)})]}),(0,G.jsxs)(`div`,{className:`pt-2 border-t`,children:[(0,G.jsxs)(`h3`,{className:`text-sm font-semibold mb-3 mt-3 flex items-center gap-2`,children:[(0,G.jsx)(Ue,{className:`h-4 w-4 text-muted-foreground`}),`Execution`]}),(0,G.jsx)(ss,{label:`Max iterations per run`,hint:`Hard cap on LLM turns per agent.run().`,value:f.maxIterations,min:10,max:2e3,step:10,onChange:e=>p(`maxIterations`,e)}),(0,G.jsx)(ss,{label:`Auto-proceed max iterations`,hint:`Stop auto-proceed after N iterations. 0 = unlimited.`,value:f.autoProceedMaxIterations,min:0,max:250,step:5,onChange:e=>p(`autoProceedMaxIterations`,e)}),(0,G.jsx)(os,{label:`Confirm before exit`,hint:`First Ctrl+C aborts work, second confirms exit.`,value:f.confirmExit,onChange:()=>p(`confirmExit`,!f.confirmExit)}),(0,G.jsx)(os,{label:`Chime on completion`,hint:`Terminal bell when an agent run finishes.`,value:f.chime,onChange:()=>p(`chime`,!f.chime)})]}),(0,G.jsxs)(`div`,{className:`pt-2 border-t`,children:[(0,G.jsxs)(`h3`,{className:`text-sm font-semibold mb-3 mt-3 flex items-center gap-2`,children:[(0,G.jsx)(Jt,{className:`h-4 w-4 text-muted-foreground`}),`Fleet & Streaming`]}),(0,G.jsx)(os,{label:`Stream fleet events`,hint:`Show live subagent activity in the fleet panel.`,value:f.streamFleet,onChange:()=>p(`streamFleet`,!f.streamFleet)}),(0,G.jsx)(os,{label:`Next-step prediction`,hint:`After a turn completes, predict likely next steps.`,value:f.nextPrediction,onChange:()=>p(`nextPrediction`,!f.nextPrediction)})]})]}),(0,G.jsxs)(as,{value:`features`,className:`space-y-4`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`h3`,{className:`text-sm font-semibold mb-3 flex items-center gap-2`,children:[(0,G.jsx)(ce,{className:`h-4 w-4 text-muted-foreground`}),`Feature Flags`]}),(0,G.jsx)(os,{label:`MCP servers`,hint:`Enable Model Context Protocol integrations.`,value:f.featureMcp,onChange:()=>p(`featureMcp`,!f.featureMcp)}),(0,G.jsx)(os,{label:`Plugins`,hint:`Load and run user-installed plugins.`,value:f.featurePlugins,onChange:()=>p(`featurePlugins`,!f.featurePlugins)}),(0,G.jsx)(os,{label:`Memory`,hint:`Persist and recall facts across sessions.`,value:f.featureMemory,onChange:()=>p(`featureMemory`,!f.featureMemory)}),(0,G.jsx)(os,{label:`Skills`,hint:`Load domain-specific skill prompts.`,value:f.featureSkills,onChange:()=>p(`featureSkills`,!f.featureSkills)}),(0,G.jsx)(os,{label:`Models registry`,hint:`Use the models.dev catalog for provider discovery.`,value:f.featureModelsRegistry,onChange:()=>p(`featureModelsRegistry`,!f.featureModelsRegistry)}),(0,G.jsx)(os,{label:`Index on start`,hint:`Build the codebase symbol index at session start.`,value:f.indexOnStart,onChange:()=>p(`indexOnStart`,!f.indexOnStart)})]}),(0,G.jsxs)(`div`,{className:`pt-2 border-t`,children:[(0,G.jsxs)(`h3`,{className:`text-sm font-semibold mb-3 mt-3 flex items-center gap-2`,children:[(0,G.jsx)(we,{className:`h-4 w-4 text-muted-foreground`}),`Context & Debug`]}),(0,G.jsx)(os,{label:`Auto-compact context`,hint:`Automatically trim the context window when near limits.`,value:f.contextAutoCompact,onChange:()=>p(`contextAutoCompact`,!f.contextAutoCompact)}),(0,G.jsx)(cs,{label:`Compactor strategy`,hint:`How the context is compacted when it grows too large.`,value:f.contextStrategy,options:[{value:`hybrid`,label:`Hybrid β€” fast rules (default)`},{value:`intelligent`,label:`Intelligent β€” LLM summarization`},{value:`selective`,label:`Selective β€” LLM-driven selection`}],onChange:e=>p(`contextStrategy`,e)}),(0,G.jsx)(cs,{label:`Log level`,hint:`Minimum severity for server-side logging.`,value:f.logLevel,options:[{value:`debug`,label:`Debug β€” everything`},{value:`info`,label:`Info β€” normal flow`},{value:`warn`,label:`Warn β€” problems only`},{value:`error`,label:`Error β€” failures only`}],onChange:e=>p(`logLevel`,e)}),(0,G.jsx)(cs,{label:`Audit level`,hint:`Detail level for session audit logs.`,value:f.auditLevel,options:[{value:`minimal`,label:`Minimal β€” errors only`},{value:`standard`,label:`Standard β€” tool calls + errors`},{value:`full`,label:`Full β€” every event (large logs)`}],onChange:e=>p(`auditLevel`,e)})]})]})]})})})]})}function ps({provider:e,isSelected:t,onSelect:n}){return(0,G.jsx)(`button`,{type:`button`,onClick:n,className:Y(`w-full text-left rounded-xl border p-4 transition-all`,`hover:border-primary/40 hover:bg-primary/5`,t?`border-primary bg-primary/10 ring-1 ring-primary/30`:`border-border bg-card`),children:(0,G.jsxs)(`div`,{className:`flex items-start justify-between gap-3`,children:[(0,G.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`span`,{className:`font-semibold text-sm`,children:e.name}),e.hasApiKey&&(0,G.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-[10px] px-1.5 py-0.5 rounded-full bg-emerald-500/10 text-emerald-600 dark:text-emerald-400 border border-emerald-500/20`,children:[(0,G.jsx)(Ot,{className:`h-2.5 w-2.5`}),`Key set`]})]}),(0,G.jsxs)(`p`,{className:`text-xs text-muted-foreground mt-0.5`,children:[e.family,` Β· `,e.modelCount,` models`]})]}),t&&(0,G.jsx)(`div`,{className:`w-5 h-5 rounded-full bg-primary flex items-center justify-center shrink-0`,children:(0,G.jsx)(Ot,{className:`h-3 h-3 text-primary-foreground`})})]})})}function ms({model:e,isSelected:t,onSelect:n}){let r=e.inputCost==null?null:`$${e.inputCost}/1M tok`,i=e.outputCost==null?null:`$${e.outputCost}/1M tok`,a=e.contextWindow?`${(e.contextWindow/1e6).toFixed(0)}M ctx`:null;return(0,G.jsx)(`button`,{type:`button`,onClick:n,className:Y(`w-full text-left rounded-xl border p-3 transition-all`,`hover:border-primary/40 hover:bg-primary/5`,t?`border-primary bg-primary/10 ring-1 ring-primary/30`:`border-border bg-card`),children:(0,G.jsxs)(`div`,{className:`flex items-start justify-between gap-2`,children:[(0,G.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,G.jsx)(`span`,{className:`font-medium text-sm`,children:e.name}),(0,G.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5 mt-1`,children:[a&&(0,G.jsx)(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded bg-muted text-muted-foreground`,children:a}),r&&i&&(0,G.jsxs)(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded bg-muted text-muted-foreground`,children:[r,` Β· `,i]}),e.capabilities.slice(0,3).map(e=>(0,G.jsx)(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded bg-primary/10 text-primary border border-primary/20`,children:e},e))]})]}),t&&(0,G.jsx)(`div`,{className:`w-5 h-5 rounded-full bg-primary flex items-center justify-center shrink-0`,children:(0,G.jsx)(Ot,{className:`h-3 w-3 text-primary-foreground`})})]})})}function hs({providerId:e,onSave:t}){let[n,r]=(0,z.useState)(``),[i,a]=(0,z.useState)(`default`),[o,s]=(0,z.useState)(!1);return(0,G.jsxs)(`div`,{className:`space-y-3 p-4 rounded-xl border border-amber-500/30 bg-amber-500/5`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-amber-600 dark:text-amber-400`,children:[(0,G.jsx)(Lt,{className:`h-4 w-4`}),(0,G.jsx)(`span`,{className:`text-sm font-medium`,children:`API Key required`})]}),(0,G.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[`Enter your API key for `,e,`. The key is stored locally and never sent to any server other than the provider's API endpoint.`]}),(0,G.jsxs)(`div`,{className:`flex gap-2`,children:[(0,G.jsx)($o,{type:`password`,placeholder:`sk-...`,value:n,onChange:e=>r(e.target.value),className:`font-mono text-sm`}),(0,G.jsx)($o,{placeholder:`Label (optional)`,value:i,onChange:e=>a(e.target.value),className:`w-28 text-sm`})]}),(0,G.jsx)(Q,{onClick:async()=>{if(n.trim()){s(!0);try{B(H.getState().wsUrl).addKey(e,i.trim()||`default`,n.trim()),t(n.trim()),r(``),X.success(`API key saved`)}catch{X.error(`Failed to save API key`)}finally{s(!1)}}},disabled:!n.trim()||o,size:`sm`,children:o?(0,G.jsx)(I,{className:`h-4 w-4 animate-spin`}):`Save Key`})]})}function gs(){let{setCurrentView:e}=W(),{provider:t,model:n,setProvider:r,setModel:i,wsConnected:a,wsUrl:o}=H();Z();let[s,c]=(0,z.useState)(`provider`),[l,u]=(0,z.useState)([]),[d,f]=(0,z.useState)({}),[p,m]=(0,z.useState)([]),[h,g]=(0,z.useState)(!1),[_,v]=(0,z.useState)(!1),[y,b]=(0,z.useState)(null),[x,S]=(0,z.useState)(null);(0,z.useEffect)(()=>{if(!a)return;let e=B(o),r=e.on(`provider.catalog`,e=>{if(e.type===`provider.catalog`){let n=e.payload.providers.sort((e,t)=>e.id.localeCompare(t.id));u(n),g(!1),t&&n.some(e=>e.id===t)?b(t):n.length===1&&b(n[0].id)}}),i=e.on(`provider.models`,e=>{if(e.type===`provider.models`){let t=e.payload;f(e=>({...e,[t.provider]:t.models})),v(!1),t.models.length===1?S(t.models[0].id):n&&t.models.some(e=>e.id===n)&&S(n)}}),s=e.on(`providers.saved`,e=>{if(e.type===`providers.saved`){let t=e.payload;m(t.providers.sort((e,t)=>e.id.localeCompare(t.id)))}});return g(!0),e.listProviders(),()=>{r?.(),i?.(),s?.()}},[a,o,t,n]),(0,z.useEffect)(()=>{if(!y||!a)return;let e=B(o);d[y]||(v(!0),e.listProviderModels(y))},[y,a,o,d]);let C=l.find(e=>e.id===y),w=p.find(e=>e.id===y)?.apiKeys.some(e=>e.isActive)||C?.hasApiKey,T=(0,z.useCallback)(e=>{b(e),S(null),c(`model`)},[]),D=(0,z.useCallback)(e=>{S(e),c(w?`done`:`apikey`)},[w]),O=(0,z.useCallback)(()=>{c(`done`)},[]),k=(0,z.useCallback)(()=>{if(!y||!x)return;r(y),i(x);let t=B(o);t.switchModel(y,x);let n=null,a=()=>{n&&clearTimeout(n)},s=t.on(`key.operation_result`,n=>{let r=n.payload;a(),s(),r.success?(t.newSession(),e(`chat`)):X.error(r.message)});n=setTimeout(()=>{a(),s(),X.error(`Model switch timed out. Please try again.`)},5e3)},[y,x,r,i,o,e]),A=y?d[y]??[]:[];return(0,G.jsxs)(`div`,{className:`flex flex-col h-full`,children:[(0,G.jsx)(`header`,{className:`flex items-center justify-between px-6 py-4 border-b bg-card shrink-0`,children:(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,G.jsx)(`div`,{className:`w-10 h-10 rounded-xl bg-gradient-to-br from-primary via-primary to-primary/60 flex items-center justify-center`,children:(0,G.jsx)(Ue,{className:`h-5 w-5 text-primary-foreground`})}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`h1`,{className:`text-lg font-semibold`,children:`Welcome to WrongStack`}),(0,G.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Configure your AI provider to get started`})]})]})}),(0,G.jsx)(es,{className:`flex-1`,children:(0,G.jsxs)(`div`,{className:`p-6 max-w-2xl mx-auto space-y-8`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-sm`,children:[(0,G.jsxs)(`div`,{className:Y(`flex items-center gap-1.5`,s===`provider`&&`text-primary font-medium`),children:[(0,G.jsx)(Ae,{className:`h-4 w-4`}),(0,G.jsx)(`span`,{children:`Provider`})]}),(0,G.jsx)(mn,{className:`h-4 w-4 text-muted-foreground`}),(0,G.jsxs)(`div`,{className:Y(`flex items-center gap-1.5`,s===`model`&&`text-primary font-medium`),children:[(0,G.jsx)(E,{className:`h-4 w-4`}),(0,G.jsx)(`span`,{children:`Model`})]}),(0,G.jsx)(mn,{className:`h-4 w-4 text-muted-foreground`}),(0,G.jsxs)(`div`,{className:Y(`flex items-center gap-1.5`,(s===`apikey`||s===`done`)&&`text-primary font-medium`),children:[(0,G.jsx)(Lt,{className:`h-4 w-4`}),(0,G.jsx)(`span`,{children:`API Key`})]})]}),s===`provider`&&(0,G.jsxs)(`div`,{className:`space-y-4`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`h2`,{className:`text-base font-semibold flex items-center gap-2`,children:[(0,G.jsx)(Ae,{className:`h-4 w-4 text-primary`}),`Choose a Provider`]}),(0,G.jsx)(`p`,{className:`text-sm text-muted-foreground mt-1`,children:`Select the AI provider you want to use. You can add API keys in the next step.`})]}),h?(0,G.jsx)(`div`,{className:`flex items-center justify-center py-12`,children:(0,G.jsx)(I,{className:`h-6 w-6 animate-spin text-muted-foreground`})}):(0,G.jsx)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-3`,children:l.map(e=>(0,G.jsx)(ps,{provider:e,isSelected:y===e.id,onSelect:()=>T(e.id)},e.id))})]}),s===`model`&&(0,G.jsxs)(`div`,{className:`space-y-4`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`h2`,{className:`text-base font-semibold flex items-center gap-2`,children:[(0,G.jsx)(E,{className:`h-4 w-4 text-primary`}),`Choose a Model`]}),(0,G.jsx)(`p`,{className:`text-sm text-muted-foreground mt-1`,children:C?`Models available for ${C.name}`:`Loading models...`})]}),(0,G.jsx)(`button`,{type:`button`,onClick:()=>c(`provider`),className:`text-xs text-muted-foreground hover:text-foreground transition-colors`,children:`← Change provider`}),_?(0,G.jsx)(`div`,{className:`flex items-center justify-center py-12`,children:(0,G.jsx)(I,{className:`h-6 w-6 animate-spin text-muted-foreground`})}):A.length>0?(0,G.jsx)(`div`,{className:`grid grid-cols-1 gap-2`,children:A.map(e=>(0,G.jsx)(ms,{model:e,isSelected:x===e.id,onSelect:()=>D(e.id)},e.id))}):(0,G.jsx)(`p`,{className:`text-sm text-muted-foreground py-8 text-center`,children:`No models available. Please check your API key.`})]}),s===`apikey`&&(0,G.jsxs)(`div`,{className:`space-y-4`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`h2`,{className:`text-base font-semibold flex items-center gap-2`,children:[(0,G.jsx)(Lt,{className:`h-4 w-4 text-primary`}),`Add Your API Key`]}),(0,G.jsxs)(`p`,{className:`text-sm text-muted-foreground mt-1`,children:[C?`Enter your API key for ${C.name}. `:`Enter your API key. `,`The key is stored locally and encrypted.`]})]}),(0,G.jsx)(`button`,{type:`button`,onClick:()=>c(`model`),className:`text-xs text-muted-foreground hover:text-foreground transition-colors`,children:`← Change model`}),y&&(0,G.jsx)(hs,{providerId:y,onSave:O})]}),s===`done`&&(0,G.jsxs)(`div`,{className:`space-y-6`,children:[(0,G.jsxs)(`div`,{className:`flex flex-col items-center text-center py-8`,children:[(0,G.jsx)(`div`,{className:`w-16 h-16 rounded-2xl bg-gradient-to-br from-emerald-500/20 to-emerald-500/5 border border-emerald-500/30 flex items-center justify-center mb-4`,children:(0,G.jsx)(Ot,{className:`h-8 w-8 text-emerald-500`})}),(0,G.jsx)(`h2`,{className:`text-xl font-semibold`,children:`You're all set!`}),(0,G.jsx)(`p`,{className:`text-sm text-muted-foreground mt-2 max-w-sm`,children:`Configuration complete. Your agent is ready to start working.`})]}),(0,G.jsxs)(`div`,{className:`rounded-xl border bg-card p-4 space-y-3`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between text-sm`,children:[(0,G.jsx)(`span`,{className:`text-muted-foreground`,children:`Provider`}),(0,G.jsx)(`span`,{className:`font-medium`,children:y})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between text-sm`,children:[(0,G.jsx)(`span`,{className:`text-muted-foreground`,children:`Model`}),(0,G.jsx)(`span`,{className:`font-medium`,children:x})]})]}),(0,G.jsxs)(Q,{onClick:k,className:`w-full`,size:`lg`,children:[(0,G.jsx)(L,{className:`h-4 w-4 mr-2`}),`Start Session`,(0,G.jsx)(vn,{className:`h-4 w-4 ml-2`})]})]})]})})]})}function _s(e){switch(e){case`running`:return`β–Ά`;case`streaming`:return`↻`;case`waiting_user`:return`⏳`;case`error`:return`βœ—`;case`idle`:return`β– `;default:return`?`}}function vs(e){switch(e){case`running`:return`text-emerald-400`;case`streaming`:return`text-cyan-400`;case`waiting_user`:return`text-amber-400`;case`error`:return`text-red-400`;default:return`text-slate-500`}}function ys(e){switch(e){case`active`:return`text-emerald-400`;case`idle`:return`text-cyan-400`;case`closing`:return`text-amber-400`;default:return`text-slate-500`}}function bs(e){let t=Date.now()-new Date(e).getTime(),n=Math.floor(t/6e4);if(n<1)return`<1m`;if(n<60)return`${n}m`;let r=Math.floor(n/60);return r<24?`${r}h ${n%60}m`:`${Math.floor(r/24)}d`}function xs(e){let t=Date.now()-new Date(e).getTime(),n=Math.floor(t/1e3);if(n<10)return`just now`;if(n<60)return`${n}s ago`;let r=Math.floor(n/60);return r<60?`${r}m ago`:`${Math.floor(r/60)}h ago`}function Ss(){let[e,t]=(0,z.useState)([]),[n,r]=(0,z.useState)(!0),[i,a]=(0,z.useState)(null),o=(0,z.useCallback)(async()=>{try{let e=await fetch(`/api/sessions`);if(!e.ok){if(e.status===404){a(null),t([]);return}throw Error(`HTTP ${e.status}`)}t(await e.json()),a(null)}catch(e){a(e instanceof Error?e.message:String(e))}finally{r(!1)}},[]);return(0,z.useEffect)(()=>{o();let e=setInterval(o,5e3);return()=>clearInterval(e)},[o]),n?(0,G.jsxs)(`div`,{className:`flex items-center gap-2 p-4 text-slate-400`,children:[(0,G.jsx)(I,{className:`h-4 w-4 animate-spin`}),`Loading sessions...`]}):i?(0,G.jsxs)(`div`,{className:`p-4 text-slate-500 text-sm`,children:[`Session API unavailable β€” run `,(0,G.jsx)(`code`,{className:`text-cyan-400`,children:`wstack --webui`}),` with session tracking enabled.`]}):e.length===0?(0,G.jsx)(`div`,{className:`p-4 text-slate-500 text-sm`,children:`No live sessions. Open another wstack instance to see it here.`}):(0,G.jsxs)(`div`,{className:`p-4 space-y-3`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 mb-4`,children:[(0,G.jsxs)(`h2`,{className:`text-sm font-semibold text-slate-200 uppercase tracking-wider`,children:[`Live Sessions (`,e.length,`)`]}),(0,G.jsx)(`span`,{className:`text-xs text-slate-500`,children:`auto-refresh every 5s`})]}),e.map(e=>(0,G.jsxs)(`div`,{className:`rounded-lg border border-slate-700 bg-slate-800/50 p-3 space-y-2`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[(0,G.jsx)(`span`,{className:ys(e.status),children:e.status===`active`?(0,G.jsx)(pt,{className:`h-3.5 w-3.5 inline`}):e.status===`idle`?(0,G.jsx)(hn,{className:`h-3.5 w-3.5 inline`}):null}),(0,G.jsx)(`span`,{className:`font-medium text-slate-200 text-sm`,children:e.projectName}),(0,G.jsxs)(`span`,{className:`text-slate-500 text-xs`,children:[`[`,e.projectSlug,`]`]}),e.gitBranch?(0,G.jsxs)(`span`,{className:`text-purple-400 text-xs flex items-center gap-1`,children:[(0,G.jsx)(On,{className:`h-3 w-3`}),e.gitBranch]}):null,(0,G.jsxs)(`span`,{className:`text-slate-500 text-xs ml-auto flex items-center gap-1`,children:[(0,G.jsx)(N,{className:`h-3 w-3`}),bs(e.startedAt)]}),(0,G.jsxs)(`span`,{className:`text-slate-600 text-xs`,children:[`PID `,e.pid]})]}),(0,G.jsxs)(`div`,{className:`text-slate-500 text-xs flex items-center gap-1`,children:[(0,G.jsx)(E,{className:`h-3 w-3`}),e.workingDir]}),(0,G.jsxs)(`div`,{className:`space-y-1 mt-2`,children:[e.agents.slice(0,5).map(e=>(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-xs pl-2 border-l-2 border-slate-700`,children:[(0,G.jsx)(`span`,{className:vs(e.status),children:_s(e.status)}),(0,G.jsx)(`span`,{className:`text-slate-300 font-medium`,children:e.name}),e.currentTool?(0,G.jsxs)(`span`,{className:`text-slate-500`,children:[`[`,e.currentTool,`]`]}):null,(0,G.jsxs)(`span`,{className:`text-slate-600 ml-auto`,children:[e.iterations,` iter Β· `,e.toolCalls,` tools Β· `,xs(e.lastActivityAt)]})]},e.id)),e.agents.length>5?(0,G.jsxs)(`div`,{className:`text-slate-600 text-xs pl-4`,children:[`... and `,e.agents.length-5,` more`]}):null,e.agents.length===0?(0,G.jsx)(`div`,{className:`text-slate-600 text-xs pl-4`,children:`No agents`}):null]})]},e.sessionId))]})}var Cs=[{section:`Global`,items:[{keys:[`Ctrl`,`K`],description:`Open command palette`},{keys:[`?`],description:`Show this shortcuts overlay`},{keys:[`Ctrl`,`\\`],description:`Toggle sidebar`},{keys:[`Ctrl`,`1-6`],description:`Open side panel (Session, Agents, History, Files, Projects, Mailbox)`},{keys:[`Ctrl`,`/`],description:`Focus the message input`}]},{section:`Fleet & Agents`,items:[{keys:[`Ctrl`,`Shift`,`M`],description:`Open Fleet Monitor overlay`},{keys:[`Ctrl`,`Shift`,`A`],description:`Open Agents Monitor overlay`},{keys:[`↑`,`↓`],description:`Navigate agents in monitor`},{keys:[`Enter`],description:`Select focused agent`},{keys:[`Esc`],description:`Close active overlay`}]},{section:`Chat input`,items:[{keys:[`Enter`],description:`Send message`},{keys:[`Shift`,`Enter`],description:`Insert a newline`},{keys:[`↑`],description:`Recall previous prompt (in empty input)`},{keys:[`↓`],description:`Recall next prompt`},{keys:[`/`],description:`Open slash command popup`},{keys:[`Tab`],description:`Autocomplete highlighted command`},{keys:[`Esc`],description:`Dismiss popup / clear input`}]},{section:`Chat`,items:[{keys:[`Ctrl`,`F`],description:`Search within current chat`},{keys:[`Ctrl`,`L`],description:`Clear context (same as /clear)`},{keys:[`Ctrl`,`N`],description:`Start a new session (same as /new)`},{keys:[`Ctrl`,`E`],description:`Export chat as markdown`},{keys:[`Ctrl`,`M`],description:`Quick model switcher overlay`},{keys:[`Ctrl`,`Shift`,`D`],description:`Toggle compact UI density`},{keys:[`Esc`],description:`Abort the current run (when running)`}]},{section:`Chat navigation (when not typing)`,items:[{keys:[`j`],description:`Focus next message (alias: ↓)`},{keys:[`k`],description:`Focus previous message (alias: ↑)`},{keys:[`g`],description:`Jump to first message`},{keys:[`Shift`,`G`],description:`Jump to last message`},{keys:[`c`],description:`Copy focused message text`},{keys:[`Esc`],description:`Clear focused message`}]}];function ws(){let e=W(e=>e.shortcutsOpen),t=W(e=>e.setShortcutsOpen);return(0,z.useEffect)(()=>{let e=e=>{let n=e.target,r=n?.tagName?.toLowerCase();if(!(r===`input`||r===`textarea`||n?.isContentEditable)&&e.key===`?`&&!e.ctrlKey&&!e.metaKey&&!e.altKey){e.preventDefault(),t(!W.getState().shortcutsOpen);return}e.key===`Escape`&&W.getState().shortcutsOpen&&(e.preventDefault(),t(!1))};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[t]),e?(0,G.jsx)(`div`,{className:`fixed inset-0 z-50 bg-background/60 backdrop-blur-sm flex items-center justify-center px-4`,onClick:()=>t(!1),onKeyDown:e=>{e.key===`Escape`&&t(!1)},children:(0,G.jsxs)(`div`,{onClick:e=>e.stopPropagation(),onKeyDown:e=>e.stopPropagation(),className:`w-full max-w-2xl rounded-xl border bg-popover shadow-2xl overflow-hidden flex flex-col max-h-[80vh]`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between px-5 py-4 border-b`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(un,{className:`h-4 w-4 text-muted-foreground`}),(0,G.jsx)(`h2`,{className:`text-sm font-semibold`,children:`Keyboard shortcuts`})]}),(0,G.jsx)(`button`,{type:`button`,onClick:()=>t(!1),className:`text-muted-foreground hover:text-foreground p-1 rounded hover:bg-muted`,children:(0,G.jsx)(F,{className:`h-4 w-4`})})]}),(0,G.jsx)(`div`,{className:`overflow-y-auto px-5 py-4 space-y-6`,children:Cs.map(e=>(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`div`,{className:`text-[10px] uppercase tracking-wider text-muted-foreground mb-2`,children:e.section}),(0,G.jsx)(`div`,{className:`grid grid-cols-1 gap-1.5`,children:e.items.map(e=>(0,G.jsxs)(`div`,{className:`flex items-center justify-between gap-3 text-sm px-2 py-1.5 rounded hover:bg-muted/40`,children:[(0,G.jsx)(`span`,{className:`text-foreground/80`,children:e.description}),(0,G.jsx)(`span`,{className:`flex items-center gap-1 shrink-0`,children:e.keys.map((e,t)=>(0,G.jsxs)(`span`,{className:`flex items-center gap-1`,children:[t>0&&(0,G.jsx)(`span`,{className:`text-muted-foreground/40 text-xs`,children:`+`}),(0,G.jsx)(`kbd`,{className:`font-mono text-[10px] border rounded px-1.5 py-0.5 bg-background`,children:e})]},e))})]},e.description))})]},e.section))}),(0,G.jsxs)(`div`,{className:`border-t px-5 py-3 text-xs text-muted-foreground`,children:[`Press`,` `,(0,G.jsx)(`kbd`,{className:`font-mono text-[10px] border rounded px-1 py-0.5 bg-background`,children:`?`}),` `,`any time to reopen this list.`]})]})}):null}function Ts(){return(0,G.jsx)(`style`,{children:`
106
- .react-flow__node {
107
- cursor: pointer;
108
- transition: transform 0.15s ease;
109
- }
110
- .react-flow__node:hover {
111
- transform: scale(1.02);
112
- }
113
- .react-flow__edge-path {
114
- transition: stroke-width 0.2s ease, stroke-opacity 0.2s ease;
115
- }
116
- /* Animated edges with flowing dashes */
117
- .animated-edge {
118
- animation: flowDash 1s linear infinite;
119
- }
120
- @keyframes flowDash {
121
- 0% { stroke-dashoffset: 10; }
122
- 100% { stroke-dashoffset: 0; }
123
- }
124
- /* Custom controls styling */
125
- .react-flow__controls {
126
- box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
127
- border-radius: 8px;
128
- overflow: hidden;
129
- border: 1px solid hsl(var(--border));
130
- }
131
- .react-flow__controls-button {
132
- background: transparent;
133
- border: none;
134
- color: hsl(var(--foreground));
135
- transition: background 0.2s ease;
136
- }
137
- .react-flow__controls-button:hover {
138
- background: hsl(var(--muted));
139
- }
140
- .react-flow__controls-button svg {
141
- fill: currentColor;
142
- }
143
- /* MiniMap styling */
144
- .react-flow__minimap {
145
- border-radius: 8px;
146
- overflow: hidden;
147
- border: 1px solid hsl(var(--border));
148
- }
149
- /* Selection styling */
150
- .react-flow__node.selected {
151
- z-index: 100;
152
- }
153
- /* Edge hover */
154
- .react-flow__edge:hover .react-flow__edge-path {
155
- stroke-width: 3;
156
- }
157
- /* React Flow attribution hidden */
158
- .react-flow__attribution {
159
- display: none;
160
- }
161
- /* Background dots styling */
162
- .react-flow__background {
163
- background-color: hsl(var(--background));
164
- }
165
- `})}var Es={read:(0,G.jsx)(Tn,{className:`h-3 w-3`}),write:(0,G.jsx)(Tn,{className:`h-3 w-3`}),bash:(0,G.jsx)(_t,{className:`h-3 w-3`}),exec:(0,G.jsx)(_t,{className:`h-3 w-3`}),glob:(0,G.jsx)(jn,{className:`h-3 w-3`}),grep:(0,G.jsx)(en,{className:`h-3 w-3`}),edit:(0,G.jsx)(t,{className:`h-3 w-3`}),fetch:(0,G.jsx)(Qt,{className:`h-3 w-3`}),search:(0,G.jsx)(en,{className:`h-3 w-3`})};function Ds({data:e}){let t=e.status===`active`||e.status===`streaming`,n=e.color||`#22c55e`;return(0,G.jsxs)(`div`,{className:Y(`rounded-lg border-2 p-3 min-w-[160px] transition-all`,t?`border-emerald-500/50 bg-emerald-500/10`:`border-gray-500/40 bg-gray-500/10`),children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`div`,{className:Y(`flex items-center justify-center w-8 h-8 rounded-lg`,t?`bg-emerald-500/20`:`bg-gray-500/20`),children:(0,G.jsx)(jn,{className:`h-4 w-4`,style:{color:n}})}),(0,G.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,G.jsx)(`div`,{className:`text-[11px] font-bold truncate`,style:{color:n},children:e.label}),e.sublabel&&(0,G.jsx)(`div`,{className:`text-[9px] text-gray-500 truncate`,children:e.sublabel})]}),t&&(0,G.jsx)(`span`,{className:`w-2 h-2 rounded-full bg-emerald-400 animate-pulse`,style:{boxShadow:`0 0 8px hsl(140,70%,50%)`}})]}),e.stats&&(0,G.jsxs)(`div`,{className:`mt-2 pt-2 border-t border-white/10 grid grid-cols-3 gap-1 text-[9px]`,children:[e.stats.iterations!==void 0&&(0,G.jsxs)(`div`,{className:`text-center`,children:[(0,G.jsx)(`div`,{className:`font-mono text-emerald-400`,children:e.stats.iterations}),(0,G.jsx)(`div`,{className:`text-gray-500`,children:`iter`})]}),e.stats.toolCalls!==void 0&&(0,G.jsxs)(`div`,{className:`text-center`,children:[(0,G.jsx)(`div`,{className:`font-mono text-blue-400`,children:e.stats.toolCalls}),(0,G.jsx)(`div`,{className:`text-gray-500`,children:`tools`})]}),e.stats.costUsd!==void 0&&e.stats.costUsd>0&&(0,G.jsxs)(`div`,{className:`text-center`,children:[(0,G.jsxs)(`div`,{className:`font-mono text-amber-400`,children:[`$`,e.stats.costUsd.toFixed(3)]}),(0,G.jsx)(`div`,{className:`text-gray-500`,children:`cost`})]})]})]})}function Os({data:e}){let n=e.status===`active`||e.status===`streaming`,r=e.status===`error`,i=e.color||`#a855f7`;return(0,G.jsxs)(`div`,{className:Y(`rounded-lg border-2 p-2.5 min-w-[140px] transition-all`,n?`border-purple-500/50 bg-purple-500/10`:r?`border-red-500/50 bg-red-500/10`:`border-gray-500/40 bg-gray-500/10`),children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`div`,{className:Y(`flex items-center justify-center w-7 h-7 rounded-lg`,n?`bg-purple-500/20`:`bg-purple-500/10`),children:(0,G.jsx)(L,{className:`h-4 w-4`,style:{color:i}})}),(0,G.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,G.jsx)(`div`,{className:`text-[10px] font-bold truncate`,style:{color:i},children:e.label}),e.currentTool&&(0,G.jsxs)(`div`,{className:`flex items-center gap-1 text-[9px] text-amber-400/70`,children:[(0,G.jsx)(t,{className:`h-2.5 w-2.5`}),(0,G.jsx)(`span`,{className:`truncate font-mono`,children:e.currentTool})]})]}),n&&(0,G.jsx)(`span`,{className:`w-1.5 h-1.5 rounded-full bg-purple-400 animate-pulse`,style:{boxShadow:`0 0 6px hsl(280,80%,60%)`}})]}),(0,G.jsxs)(`div`,{className:`mt-1.5 flex items-center justify-between text-[9px]`,children:[(0,G.jsxs)(`span`,{className:`text-gray-500`,children:[`iter `,e.stats?.iterations??0]}),(0,G.jsxs)(`span`,{className:`text-gray-500`,children:[`tools `,e.stats?.toolCalls??0]}),e.stats?.costUsd!==void 0&&e.stats.costUsd>0&&(0,G.jsxs)(`span`,{className:`text-emerald-400/70`,children:[`$`,e.stats.costUsd.toFixed(3)]})]}),e.stats?.ctxPct!==void 0&&(0,G.jsxs)(`div`,{className:`mt-1.5`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between text-[9px] mb-0.5`,children:[(0,G.jsx)(`span`,{className:`text-gray-500`,children:`ctx`}),(0,G.jsxs)(`span`,{className:e.stats.ctxPct>80?`text-red-400`:e.stats.ctxPct>60?`text-amber-400`:`text-gray-400`,children:[e.stats.ctxPct,`%`]})]}),(0,G.jsx)(`div`,{className:`h-1 rounded-full bg-black/30 overflow-hidden`,children:(0,G.jsx)(`div`,{className:Y(`h-full rounded-full transition-all`,e.stats.ctxPct>80?`bg-red-500`:e.stats.ctxPct>60?`bg-amber-500`:`bg-blue-500`),style:{width:`${Math.min(100,e.stats.ctxPct)}%`}})})]})]})}function ks({data:e}){let n=e.color||`#f59e0b`,r=Es[e.label?.toLowerCase()??``]||(0,G.jsx)(t,{className:`h-3 w-3`});return(0,G.jsxs)(`div`,{className:`rounded-lg border border-amber-500/30 bg-amber-500/10 p-2 min-w-[100px] transition-all`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`span`,{style:{color:n},children:r}),(0,G.jsx)(`span`,{className:`text-[10px] font-mono font-medium truncate`,style:{color:n},children:e.label})]}),e.stats?.durationMs!==void 0&&(0,G.jsxs)(`div`,{className:`mt-1 text-[9px] text-gray-500 text-center`,children:[e.stats.durationMs,`ms`]})]})}function As({data:e}){let t=e.status===`active`||e.status===`streaming`,n=e.color||`#06b6d4`;return(0,G.jsx)(`div`,{className:Y(`rounded-lg border-2 p-3 min-w-[120px] transition-all`,t?`border-cyan-500/50 bg-cyan-500/10`:`border-cyan-500/30 bg-cyan-500/5`),children:(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`div`,{className:Y(`flex items-center justify-center w-8 h-8 rounded-lg`,t?`bg-cyan-500/20`:`bg-cyan-500/10`),children:(0,G.jsx)(E,{className:`h-4 w-4`,style:{color:n}})}),(0,G.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,G.jsx)(`div`,{className:`text-[10px] font-bold`,style:{color:n},children:`LLM`}),(0,G.jsx)(`div`,{className:`text-[9px] text-gray-500 truncate`,children:e.sublabel||`Provider`})]}),t&&(0,G.jsx)(`span`,{className:`w-2 h-2 rounded-full bg-cyan-400 animate-pulse`,style:{boxShadow:`0 0 8px hsl(180,80%,60%)`}})]})})}function js({data:e}){let t=e.color||`#3b82f6`;return(0,G.jsxs)(`div`,{className:`rounded-lg border border-blue-500/30 bg-blue-500/10 p-2 min-w-[90px] transition-all`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(Pn,{className:`h-3 w-3`,style:{color:t}}),(0,G.jsx)(`span`,{className:`text-[10px] font-medium`,style:{color:t},children:`Context`})]}),e.stats?.ctxPct!==void 0&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`div`,{className:`mt-1 text-[9px] text-center text-gray-400`,children:[e.stats.ctxPct,`%`]}),(0,G.jsx)(`div`,{className:`h-1 mt-0.5 rounded-full bg-black/30 overflow-hidden`,children:(0,G.jsx)(`div`,{className:`h-full rounded-full bg-blue-500`,style:{width:`${Math.min(100,e.stats.ctxPct)}%`}})})]})]})}var Ms={session:Ds,agent:Os,tool:ks,provider:As,context:js};function Ns({id:e,sourceX:t,sourceY:n,targetX:r,targetY:i,data:a,selected:o}){let[s,c,l]=Ps(t,n,r,i),u=a?.color||`#6366f1`,d=a?.animated,f=a?.flowType||`response`,p=a?.sequence,m={prompt:{icon:`πŸ“₯`,bg:`bg-blue-500/20`,text:`text-blue-400`},response:{icon:`πŸ“€`,bg:`bg-emerald-500/20`,text:`text-emerald-400`},tool_result:{icon:`πŸ”§`,bg:`bg-amber-500/20`,text:`text-amber-400`},tokens:{icon:`πŸ’Ž`,bg:`bg-cyan-500/20`,text:`text-cyan-400`},spawn:{icon:`✨`,bg:`bg-purple-500/20`,text:`text-purple-400`},status:{icon:`πŸ“Š`,bg:`bg-pink-500/20`,text:`text-pink-400`}},h=m[f]||m.response;return(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`path`,{id:e,d:s,fill:`none`,stroke:u,strokeWidth:o?3:2,strokeOpacity:o?.9:.4,className:`react-flow__edge-path`,markerEnd:`url(#arrow-${u.replace(`#`,``)})`}),d&&(0,G.jsx)(`path`,{d:s,fill:`none`,stroke:u,strokeWidth:2.5,strokeDasharray:`8 4`,className:`animated-edge`,opacity:.8}),p!==void 0&&(0,G.jsxs)(`g`,{transform:`translate(${c-6}, ${l-18})`,children:[(0,G.jsx)(`circle`,{r:`8`,fill:u,opacity:.9}),(0,G.jsx)(`text`,{x:`0`,y:`3`,textAnchor:`middle`,fill:`white`,fontSize:`9`,fontWeight:`bold`,children:p})]}),a?.label&&(0,G.jsx)(`foreignObject`,{width:100,height:28,x:c-50,y:l-14,className:`overflow-visible`,children:(0,G.jsxs)(`div`,{className:`flex items-center justify-center gap-1`,children:[(0,G.jsx)(`span`,{className:`text-[10px]`,children:h.icon}),(0,G.jsx)(`div`,{className:Y(`px-2 py-1 rounded-md border text-[9px] font-medium`,h.bg,`border-border/50`,h.text),children:a.label})]})}),(0,G.jsx)(`defs`,{children:(0,G.jsx)(`marker`,{id:`arrow-${u.replace(`#`,``)}`,viewBox:`0 0 10 10`,refX:`9`,refY:`5`,markerWidth:`6`,markerHeight:`6`,orient:`auto-start-reverse`,children:(0,G.jsx)(`path`,{d:`M 0 0 L 10 5 L 0 10 z`,fill:u,opacity:.7})})})]})}function Ps(e,t,n,r){let i=Math.abs(n-e),a=Math.max(40,i*.4),o=(e+n)/2,s=Math.min(t,r)-a;return[`M ${e} ${t} C ${e} ${s}, ${n} ${s}, ${n} ${r}`,o,s]}var Fs={flow:Ns};function Is({containerRef:e}){let{fitView:t}=et(),n=U(e=>e.session),r=U(e=>e.projectName),i=U(e=>e.iteration),a=U(e=>e.cost),o=U(e=>e.lastInputTokens),s=U(e=>e.maxContext),c=K(e=>e.agents);kr(e=>e.nodes),kr(e=>e.edges);let l=kr(e=>e.events),u=kr(e=>e.counters),[d,f,p]=An([]),[m,h,g]=bn([]),[_,v]=(0,z.useState)(null);(0,z.useEffect)(()=>{let e=[],l=[];e.push({id:`provider`,type:`provider`,position:{x:400,y:20},data:{label:`LLM`,sublabel:n?.model||`claude-3-5-sonnet`,type:`provider`,status:n?`active`:`idle`,color:`#06b6d4`}}),e.push({id:`session`,type:`session`,position:{x:400,y:120},data:{label:n?.title||r||`Session`,sublabel:n?.id.slice(0,8),type:`session`,status:n?`active`:`idle`,color:`#22c55e`,stats:{iterations:i?.index,toolCalls:Array.from(c.values()).reduce((e,t)=>e+t.toolCalls,0),costUsd:a}}});let u=s?Math.round(o/s*100):0;e.push({id:`context`,type:`context`,position:{x:700,y:200},data:{label:`Context`,type:`context`,status:u>80?`active`:`idle`,color:`#3b82f6`,stats:{ctxPct:u}}});let d=Array.from(c.values()),p=Math.min(200,800/(d.length+1)),m=Math.max(100,(800-(d.length-1)*p)/2);d.forEach((t,n)=>{let r=t.status===`running`,i=t.status===`failed`,a=`agent-${t.id}`,o=i?`#ef4444`:r?`#a855f7`:`#8b5cf6`;e.push({id:a,type:`agent`,position:{x:m+n*p,y:300},data:{label:t.name,type:`agent`,status:r?`active`:i?`error`:t.status===`completed`?`completed`:`idle`,color:o,stats:{iterations:t.iteration,toolCalls:t.toolCalls,costUsd:t.costUsd,ctxPct:t.ctxPct},currentTool:t.currentTool||t.lastTool}}),l.push({id:`session->${a}`,source:`session`,target:a,type:`flow`,animated:r,data:{color:o,animated:r,label:`task`,flowType:`prompt`,sequence:n+1}}),l.push({id:`${a}->provider`,source:a,target:`provider`,type:`flow`,animated:r,data:{color:`#06b6d4`,animated:r,label:`prompt`,flowType:`prompt`,sequence:0}});let s=t.currentTool||t.lastTool;if(s){let i=`tool-${t.id}-${d.indexOf(t)}`;e.push({id:i,type:`tool`,position:{x:m+n*p,y:450},data:{label:s,type:`tool`,status:r?`active`:`idle`,color:`#f59e0b`,stats:{durationMs:t.toolLog?.[0]?.durationMs}}}),l.push({id:`${a}->${i}`,source:a,target:i,type:`flow`,animated:r,data:{color:`#f59e0b`,animated:r,label:`execute`,flowType:`tool_result`,sequence:2}}),l.push({id:`${i}->${a}`,source:i,target:a,type:`flow`,animated:!1,data:{color:`#22c55e`,animated:!1,label:`result`,flowType:`tool_result`,sequence:3}})}}),l.push({id:`provider->session`,source:`provider`,target:`session`,type:`flow`,animated:!!n,data:{color:`#06b6d4`,animated:!!n,label:`response`,flowType:`response`,sequence:4}}),l.push({id:`context->session`,source:`context`,target:`session`,type:`flow`,data:{color:`#3b82f6`,animated:!1,label:`tokens`,flowType:`tokens`}}),f(e),h(l),setTimeout(()=>t({padding:.2,duration:300}),50)},[n,r,i,c,a,o,s,f,h,t]),(0,z.useEffect)(()=>{if(l.length===0)return;let e=l[0];if(e){if(e.kind===`agent:tool`&&e.source){let t=`agent-${e.source}`;f(n=>n.map(n=>n.id===t?{...n,data:{...n.data,status:`streaming`,currentTool:e.label}}:n))}if(e.kind===`agent:status`){let t=`agent-${e.source}`,n=e.label.includes(`completed`)?`completed`:e.label.includes(`failed`)?`error`:e.label.includes(`running`)?`active`:`idle`;f(e=>e.map(e=>e.id===t?{...e,data:{...e.data,status:n}}:e))}}},[l,f]);let y=(0,z.useCallback)(e=>h(t=>vt({...e,type:`flow`},t)),[h]),b=(0,z.useCallback)((e,t)=>{v(t)},[]),x=(0,z.useCallback)(()=>{v(null)},[]);return(0,G.jsxs)(`div`,{className:`w-full h-full bg-background relative`,children:[(0,G.jsx)(Ts,{}),(0,G.jsxs)(Ke,{nodes:d,edges:m,onNodesChange:p,onEdgesChange:g,onConnect:y,onNodeClick:b,onPaneClick:x,nodeTypes:Ms,edgeTypes:Fs,fitView:!0,attributionPosition:`bottom-left`,proOptions:{hideAttribution:!0},children:[(0,G.jsx)(st,{variant:mt.Dots,gap:20,size:1,color:`hsl(var(--border))`}),(0,G.jsx)(Zt,{className:`!bg-background/80 !border-border backdrop-blur`}),(0,G.jsx)(Bt,{className:`!bg-background/80 !border-border`,nodeColor:e=>{switch(e.type){case`session`:return`#22c55e`;case`agent`:return`#a855f7`;case`tool`:return`#f59e0b`;case`provider`:return`#06b6d4`;case`context`:return`#3b82f6`;default:return`#6366f1`}}})]}),_&&(0,G.jsxs)(`div`,{className:`absolute top-4 right-4 w-64 bg-background/95 border border-border rounded-lg shadow-xl backdrop-blur z-50`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between p-3 border-b border-border`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`span`,{className:`text-xs font-bold capitalize`,children:_.type}),(0,G.jsx)(`span`,{className:Y(`px-1.5 py-0.5 rounded text-[9px] font-medium`,_.data.status===`active`&&`bg-emerald-500/20 text-emerald-400`,_.data.status===`streaming`&&`bg-blue-500/20 text-blue-400`,_.data.status===`error`&&`bg-red-500/20 text-red-400`,_.data.status===`completed`&&`bg-blue-500/20 text-blue-400`,_.data.status===`idle`&&`bg-gray-500/20 text-gray-400`),children:_.data.status})]}),(0,G.jsx)(`button`,{onClick:()=>v(null),className:`text-muted-foreground hover:text-foreground`,children:(0,G.jsx)(F,{className:`h-4 w-4`})})]}),(0,G.jsxs)(`div`,{className:`p-3 space-y-2 text-[11px]`,children:[(0,G.jsxs)(`div`,{className:`flex justify-between`,children:[(0,G.jsx)(`span`,{className:`text-muted-foreground`,children:`Label`}),(0,G.jsx)(`span`,{className:`font-mono`,children:String(_.data.label??``)})]}),_.data.sublabel&&(0,G.jsxs)(`div`,{className:`flex justify-between`,children:[(0,G.jsx)(`span`,{className:`text-muted-foreground`,children:`Sublabel`}),(0,G.jsx)(`span`,{className:`font-mono text-[10px]`,children:String(_.data.sublabel)})]}),_.data.currentTool&&(0,G.jsxs)(`div`,{className:`flex justify-between`,children:[(0,G.jsx)(`span`,{className:`text-muted-foreground`,children:`Tool`}),(0,G.jsx)(`span`,{className:`font-mono text-amber-400`,children:String(_.data.currentTool)})]}),_.data.stats&&(0,G.jsxs)(G.Fragment,{children:[_.data.stats.iterations!==void 0&&(0,G.jsxs)(`div`,{className:`flex justify-between`,children:[(0,G.jsx)(`span`,{className:`text-muted-foreground`,children:`Iterations`}),(0,G.jsx)(`span`,{className:`font-mono`,children:_.data.stats.iterations})]}),_.data.stats.toolCalls!==void 0&&(0,G.jsxs)(`div`,{className:`flex justify-between`,children:[(0,G.jsx)(`span`,{className:`text-muted-foreground`,children:`Tool Calls`}),(0,G.jsx)(`span`,{className:`font-mono`,children:_.data.stats.toolCalls})]}),_.data.stats.costUsd!==void 0&&(0,G.jsxs)(`div`,{className:`flex justify-between`,children:[(0,G.jsx)(`span`,{className:`text-muted-foreground`,children:`Cost`}),(0,G.jsxs)(`span`,{className:`font-mono text-emerald-400`,children:[`$`,_.data.stats.costUsd.toFixed(4)]})]}),_.data.stats.ctxPct!==void 0&&(0,G.jsxs)(`div`,{className:`flex justify-between`,children:[(0,G.jsx)(`span`,{className:`text-muted-foreground`,children:`Context`}),(0,G.jsxs)(`span`,{className:`font-mono`,children:[_.data.stats.ctxPct,`%`]})]})]})]})]}),(0,G.jsxs)(`div`,{className:`absolute bottom-4 left-4 bg-background/95 border border-border rounded-lg p-2 backdrop-blur`,children:[(0,G.jsx)(`div`,{className:`text-[9px] text-muted-foreground mb-1 font-semibold uppercase tracking-wider`,children:`Live`}),(0,G.jsxs)(`div`,{className:`grid grid-cols-3 gap-x-3 gap-y-1 text-[10px]`,children:[(0,G.jsx)(Ls,{label:`Tokens`,value:u.totalTokens.toLocaleString()}),(0,G.jsx)(Ls,{label:`Cost`,value:`$${u.totalCost.toFixed(3)}`}),(0,G.jsx)(Ls,{label:`Tools`,value:u.totalToolCalls}),(0,G.jsx)(Ls,{label:`Agents`,value:u.activeAgents}),(0,G.jsx)(Ls,{label:`Done`,value:u.completedTasks}),(0,G.jsx)(Ls,{label:`Errors`,value:u.errors})]})]}),(0,G.jsxs)(`div`,{className:`absolute top-4 left-4 bg-background/95 border border-border rounded-lg p-3 backdrop-blur z-50 max-w-xs`,children:[(0,G.jsxs)(`div`,{className:`text-[9px] text-muted-foreground mb-2 font-semibold uppercase tracking-wider flex items-center gap-2`,children:[(0,G.jsx)(`span`,{className:`text-primary`,children:`⟳`}),` Flow Sequence`]}),(0,G.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,G.jsx)(zs,{sequence:0,icon:`πŸ“₯`,label:`Prompt`,description:`User input β†’ LLM`,color:`#06b6d4`}),(0,G.jsx)(zs,{sequence:1,icon:`πŸ‘€`,label:`Task`,description:`Session β†’ Agent`,color:`#a855f7`}),(0,G.jsx)(zs,{sequence:2,icon:`πŸ”§`,label:`Execute`,description:`Agent β†’ Tool`,color:`#f59e0b`}),(0,G.jsx)(zs,{sequence:3,icon:`βœ…`,label:`Result`,description:`Tool β†’ Agent`,color:`#22c55e`}),(0,G.jsx)(zs,{sequence:4,icon:`πŸ“€`,label:`Response`,description:`LLM β†’ Session`,color:`#06b6d4`})]}),(0,G.jsx)(`div`,{className:`mt-2 pt-2 border-t border-border`,children:(0,G.jsxs)(`div`,{className:`text-[9px] text-muted-foreground flex items-center gap-2`,children:[(0,G.jsx)(`span`,{children:`πŸ’Ž`}),` Tokens: Context β†’ Session`]})})]}),(0,G.jsxs)(`div`,{className:`absolute bottom-4 right-4 bg-background/95 border border-border rounded-lg p-2 backdrop-blur`,children:[(0,G.jsx)(`div`,{className:`text-[9px] text-muted-foreground mb-1 font-semibold uppercase tracking-wider`,children:`Nodes`}),(0,G.jsxs)(`div`,{className:`space-y-1`,children:[(0,G.jsx)(Rs,{color:`#22c55e`,label:`Session`}),(0,G.jsx)(Rs,{color:`#a855f7`,label:`Agent`}),(0,G.jsx)(Rs,{color:`#f59e0b`,label:`Tool`}),(0,G.jsx)(Rs,{color:`#06b6d4`,label:`Provider`}),(0,G.jsx)(Rs,{color:`#3b82f6`,label:`Context`})]})]})]})}function Ls({label:e,value:t}){return(0,G.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,G.jsx)(`span`,{className:`text-muted-foreground`,children:e}),(0,G.jsx)(`span`,{className:`font-mono font-bold text-foreground`,children:t})]})}function Rs({color:e,label:t}){return(0,G.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[10px]`,children:[(0,G.jsx)(`span`,{className:`w-2.5 h-2.5 rounded-sm`,style:{backgroundColor:e}}),(0,G.jsx)(`span`,{className:`text-muted-foreground`,children:t})]})}function zs({sequence:e,icon:t,label:n,description:r,color:i}){return(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-[10px]`,children:[(0,G.jsx)(`div`,{className:`w-5 h-5 rounded-full flex items-center justify-center text-[9px] font-bold text-white shrink-0`,style:{backgroundColor:i},children:e}),(0,G.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,G.jsx)(`span`,{children:t}),(0,G.jsx)(`span`,{className:`font-medium`,style:{color:i},children:n}),(0,G.jsx)(`span`,{className:`text-muted-foreground text-[9px]`,children:r})]})]})}function Bs(e){return(0,G.jsx)(St,{children:(0,G.jsx)(Is,{...e})})}var Vs={ts:a,tsx:a,js:a,jsx:a,mjs:a,cjs:a,json:se,lock:m,css:Tn,scss:Tn,less:Tn,html:d,htm:d,svg:fe,xml:d,md:Tn,mdx:Tn,txt:Tn,yml:Tn,yaml:Tn,toml:Pt,env:Pt,gitignore:Pt,editorconfig:Pt,sh:a,bash:a,zsh:a,fish:a,ps1:a,bat:a,py:a,pyi:a,pyx:a,rs:a,go:a,rb:a,java:a,c:a,cpp:a,h:a,hpp:a,sql:a,graphql:a,png:fe,jpg:fe,jpeg:fe,gif:fe,webp:fe,ico:fe};function Hs(e,t){if(t){let t=e.toLowerCase();return t===`.git`?`text-orange-500/80 dark:text-orange-400/80`:t===`node_modules`?`text-red-400/60 dark:text-red-500/60`:t===`src`||t===`lib`||t===`packages`?`text-amber-500/70 dark:text-amber-400/70`:t===`tests`||t===`test`||t===`__tests__`?`text-emerald-500/70 dark:text-emerald-400/70`:t===`dist`||t===`build`||t===`.next`?`text-muted-foreground/50`:`text-amber-500/70 dark:text-amber-400/70`}let n=e.split(`.`).pop()?.toLowerCase()??``;return/^(ts|tsx|js|jsx|mjs|cjs)$/.test(n)?`text-blue-500 dark:text-blue-400`:/^(json|lock)$/.test(n)?`text-amber-500 dark:text-amber-400`:/^(css|scss|less|sass)$/.test(n)?`text-teal-500 dark:text-teal-400`:/^(html|htm|xml|svg)$/.test(n)?`text-rose-500 dark:text-rose-400`:/^(md|mdx)$/.test(n)?`text-violet-500 dark:text-violet-400`:/^(yml|yaml|toml|env)$/.test(n)?`text-emerald-500 dark:text-emerald-400`:/^(sh|bash|zsh|fish|ps1|bat)$/.test(n)?`text-orange-400 dark:text-orange-300`:/^(py|pyi|pyx)$/.test(n)?`text-cyan-500 dark:text-cyan-400`:n===`rs`?`text-orange-500 dark:text-orange-400`:n===`go`?`text-sky-500 dark:text-sky-400`:n===`rb`?`text-red-400 dark:text-red-400`:/^(c|h|cpp|hpp|cc|hh)$/.test(n)?`text-slate-500 dark:text-slate-400`:/^(png|jpe?g|gif|webp|ico|svg)$/.test(n)?`text-purple-500 dark:text-purple-400`:/^(gitignore|editorconfig|prettierrc|eslintrc)$/.test(n)?`text-muted-foreground/60`:`text-muted-foreground`}function Us(e){return Vs[e.split(`.`).pop()?.toLowerCase()??``]??Ce}function Ws({node:e,depth:t,selectedPath:n,forceExpand:r,onSelect:i,onOpen:a}){let[o,s]=(0,z.useState)(t<1),c=q(e=>e.activeFilePath),l=e.type===`file`&&e.path===c;if((0,z.useEffect)(()=>{r!==null&&s(r)},[r]),e.type===`directory`){let c=(e.children?.length??0)>0,l=o?jn:qe,u=e.name===`.git`,d=Hs(e.name,!0);return(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`button`,{type:`button`,onClick:()=>s(e=>!e),className:Y(`flex items-center gap-1 w-full text-left px-1 py-0.5 text-[11px] rounded`,`hover:bg-muted/60 transition-colors`),style:{paddingLeft:`${t*14+4}px`},children:[(0,G.jsx)(mn,{className:Y(`h-3 w-3 shrink-0 text-muted-foreground transition-transform`,o&&`rotate-90`)}),u?(0,G.jsx)(tt,{className:Y(`h-3.5 w-3.5 shrink-0`,d)}):(0,G.jsx)(l,{className:Y(`h-3.5 w-3.5 shrink-0`,d)}),(0,G.jsx)(`span`,{className:`truncate font-medium flex-1 min-w-0`,children:e.name})]}),o&&c&&(0,G.jsx)(`div`,{children:(e.children??[]).map(e=>(0,G.jsx)(Ws,{node:e,depth:t+1,selectedPath:n,forceExpand:r,onSelect:i,onOpen:a},e.path))}),o&&!c&&(0,G.jsx)(`div`,{className:`text-[10px] text-muted-foreground italic py-0.5`,style:{paddingLeft:`${(t+1)*14+4}px`},children:`empty`})]})}let u=Us(e.name),d=Hs(e.name,!1),f=e.path===n;return(0,G.jsxs)(`button`,{type:`button`,onClick:()=>i(e.path),onDoubleClick:t=>{t.preventDefault(),a(e.path)},className:Y(`flex items-center gap-1.5 w-full text-left px-1 py-0.5 text-[11px] rounded`,`hover:bg-muted/60 transition-colors`,l&&`bg-primary/10 text-primary`,f&&!l&&`bg-muted/70 ring-1 ring-inset ring-border`),style:{paddingLeft:`${t*14+4}px`},children:[(0,G.jsx)(`span`,{className:`w-3 shrink-0`}),` `,(0,G.jsx)(u,{className:Y(`h-3.5 w-3.5 shrink-0`,d)}),(0,G.jsx)(`span`,{className:`truncate`,children:e.name})]})}function Gs(){let e=q(e=>e.tree),t=q(e=>e.treeLoading),n=q(e=>e.error),r=q(e=>e.openFiles),i=q(e=>e.activeFilePath),o=U(e=>e.cwd),s=U(e=>e.projectName),c=o?.includes(`\\`)?`\\`:`/`,l=(e,t=8,n=4)=>e.length<=t+n+2?e:`${e.slice(0,t)}…${e.slice(-n)}`,u=(()=>{if(!o||!s)return!0;let e=o.replace(/\\/g,`/`).split(`/`).filter(Boolean);return(e[e.length-1]??``)===s})(),d=(0,z.useMemo)(()=>{if(!o||!s)return[];let e=o.replace(/\\/g,`/`).split(`/`).filter(Boolean),t=-1;for(let n=e.length-1;n>=0;n--)if(e[n]===s){t=n;break}if(t===-1)return e.map((t,n)=>({label:t,path:`/`+e.slice(0,n+1).join(`/`),isLast:n===e.length-1}));let n=e.slice(t);return n.map((r,i)=>({label:r,path:`/`+e.slice(0,t+i+1).join(`/`),isLast:i===n.length-1}))},[o,s]),f=(0,z.useRef)(null);(0,z.useEffect)(()=>{let e=f.current;e&&d.length>1&&(e.scrollLeft=e.scrollWidth)},[d]);let p=(0,z.useCallback)(e=>{B().send({type:`working_dir.set`,payload:{path:e}})},[]),[m,h]=(0,z.useState)(null);(0,z.useEffect)(()=>{if(!m)return;let e=()=>h(null),t=t=>{t.key===`Escape`&&e()};return window.addEventListener(`click`,e),window.addEventListener(`keydown`,t),()=>{window.removeEventListener(`click`,e),window.removeEventListener(`keydown`,t)}},[m]);let g=(0,z.useCallback)((e,t)=>{e.preventDefault(),e.stopPropagation(),h({x:e.clientX,y:e.clientY,crumb:t})},[]),_=(0,z.useCallback)(e=>{navigator.clipboard.writeText(e),h(null)},[]),v=(0,z.useCallback)(()=>{if(!i)return;let e=i.replace(/\\/g,`/`).split(`/`).slice(0,-1).join(`/`)||`.`;B().send({type:`working_dir.set`,payload:{path:e}})},[i]),y=(0,z.useCallback)((e,t)=>{B().send({type:`shell.open`,payload:{path:e,target:t}}),h(null)},[]),b=(0,z.useCallback)(()=>{if(!o)return;let e=o.replace(/\\/g,`/`),t=e.split(`/`).slice(0,-1).join(`/`)||e;B().send({type:`working_dir.set`,payload:{path:t}})},[o]),[x,S]=(0,z.useState)(!1),C=(0,z.useRef)(null);(0,z.useEffect)(()=>(t?C.current=setTimeout(()=>S(!0),150):(C.current&&clearTimeout(C.current),S(!1)),()=>{C.current&&clearTimeout(C.current)}),[t]);let[w,T]=(0,z.useState)(null),[E,D]=(0,z.useState)(null),O=(0,z.useMemo)(()=>{let t=0,n=e=>{for(let r of e)r.type===`directory`&&t++,r.children&&n(r.children)};return n(e),t},[e]),k=(0,z.useMemo)(()=>{let t=0,n=0;for(let r of e)r.type===`directory`?n++:t++;return{files:t,dirs:n}},[e]),A={value:!1},j=(0,z.useCallback)(()=>{A.value=!0,D(!1),setTimeout(()=>{A.value=!1},400)},[]),M=(0,z.useCallback)(()=>{A.value=!0,D(!0),setTimeout(()=>{A.value=!1},400)},[]),te=(0,z.useCallback)(e=>{if(r.find(t=>t.path===e)){q.getState().setActiveFile(e);return}T(t=>t===e?null:e)},[r]),N=(0,z.useCallback)(e=>{window.dispatchEvent(new CustomEvent(`wrongstack:open-file`,{detail:{filePath:e}})),T(null)},[]);return(0,z.useEffect)(()=>{i&&T(null)},[i]),x?(0,G.jsx)(`div`,{className:`flex items-center justify-center h-full py-8`,children:(0,G.jsx)(I,{className:`h-5 w-5 animate-spin text-muted-foreground`})}):n?(0,G.jsxs)(`div`,{className:`p-3 text-[11px] text-destructive`,children:[`Failed to load files: `,n]}):(0,G.jsxs)(`div`,{className:`h-full flex flex-col overflow-hidden`,children:[e.length>0&&O>0&&(0,G.jsxs)(`div`,{className:`flex items-center gap-0.5 px-2 py-0.5 border-b shrink-0`,children:[(0,G.jsxs)(`button`,{type:`button`,onClick:M,className:Y(`flex items-center gap-1 px-1.5 py-0.5 rounded text-[10px] transition-colors`,`hover:bg-muted/60 text-muted-foreground hover:text-foreground`),title:`Expand all directories`,children:[(0,G.jsx)(yt,{className:`h-3 w-3`}),(0,G.jsx)(`span`,{children:`Expand all`})]}),(0,G.jsxs)(`button`,{type:`button`,onClick:j,className:Y(`flex items-center gap-1 px-1.5 py-0.5 rounded text-[10px] transition-colors`,`hover:bg-muted/60 text-muted-foreground hover:text-foreground`),title:`Collapse all directories`,children:[(0,G.jsx)(ee,{className:`h-3 w-3`}),(0,G.jsx)(`span`,{children:`Collapse`})]}),(0,G.jsxs)(`span`,{className:`ml-auto text-[9px] text-muted-foreground/50 tabular-nums`,children:[O,` folder`,O===1?``:`s`]})]}),(0,G.jsxs)(`div`,{className:`flex-1 overflow-y-auto py-1`,children:[d.length>0&&(0,G.jsxs)(`div`,{ref:f,className:`relative flex items-center gap-0.5 px-1 pb-1 border-b border-border/30 overflow-x-auto`,children:[(0,G.jsx)(`span`,{className:`sticky left-0 shrink-0 w-3 h-full bg-gradient-to-r from-background to-transparent pointer-events-none`}),d.map((e,t)=>{let n=e.isLast?e.label:l(e.label),r=e.path.replace(/\//g,c),i=o?o.replace(/\\/g,`/`).split(`/`).filter(Boolean):[],a=(()=>{for(let e=i.length-1;e>=0;e--)if(i[e]===s)return e;return-1})(),u=a>=0?i.slice(0,a+t+1):i.slice(0,t+1),d=c===`\\`?u.join(`\\`):`/`+u.join(`/`),f=(a>=0?i.slice(a+1,a+t+1):[]).join(c)||`.`;return(0,G.jsxs)(`span`,{className:`flex items-center gap-0.5 shrink-0`,children:[t>0&&(0,G.jsx)(`span`,{className:`text-[9px] text-muted-foreground/40 select-none`,children:c}),(0,G.jsx)(`button`,{type:`button`,onClick:()=>p(e.path),onContextMenu:e=>g(e,{absPath:d,relPath:f}),className:Y(`px-1 py-0.5 rounded text-[11px] transition-colors whitespace-nowrap`,e.isLast?`text-foreground font-medium`:`text-muted-foreground hover:text-foreground hover:bg-muted/60`),title:e.isLast?`Current directory: ${r}`:`Navigate to ${r}`,children:n})]},e.path)}),e.length>0&&(0,G.jsxs)(`span`,{className:`ml-auto shrink-0 text-[9px] text-muted-foreground/50 tabular-nums pl-2`,children:[k.files>0&&`${k.files} file${k.files===1?``:`s`}`,k.files>0&&k.dirs>0&&`, `,k.dirs>0&&`${k.dirs} folder${k.dirs===1?``:`s`}`]})]}),i&&(0,G.jsxs)(`button`,{type:`button`,onClick:v,className:`flex items-center gap-1 w-full text-left px-2 py-0.5 border-b border-border/30 text-[10px] text-muted-foreground hover:text-foreground hover:bg-accent/50 transition-colors`,title:`Navigate to parent directory of ${i.replace(/\//g,c)}`,children:[(0,G.jsx)(a,{className:`h-3 w-3 shrink-0`}),(0,G.jsx)(`span`,{className:`truncate`,children:(()=>{let e=i.replace(/\\/g,`/`).split(`/`);return e[e.length-1]??i})()}),(0,G.jsx)(`span`,{className:`ml-auto text-[8px] text-muted-foreground/40 shrink-0`,children:`go to dir`})]}),d.length===0&&!u&&(0,G.jsxs)(`button`,{type:`button`,onClick:b,className:Y(`flex items-center gap-1.5 w-full text-left px-1 py-0.5 text-[11px] rounded`,`hover:bg-muted/60 transition-colors text-muted-foreground hover:text-foreground`,`font-medium`),children:[(0,G.jsx)(ke,{className:`h-3.5 w-3.5 shrink-0`}),(0,G.jsx)(`span`,{children:`..`}),(0,G.jsx)(`span`,{className:`text-[9px] text-muted-foreground/50 ml-auto`,children:`parent directory`})]}),e.map(e=>(0,G.jsx)(Ws,{node:e,depth:0,selectedPath:w,forceExpand:E,onSelect:te,onOpen:N},e.path)),e.length===0&&(0,G.jsx)(`p`,{className:`text-[11px] text-muted-foreground italic p-2`,children:`No files found`})]}),m&&(0,G.jsxs)(`div`,{className:`fixed z-50 min-w-[140px] bg-popover border rounded-md shadow-md py-1 text-[11px]`,style:{left:m.x,top:m.y},children:[(0,G.jsx)(`button`,{type:`button`,onClick:()=>_(m.crumb.absPath),className:`flex items-center gap-2 w-full text-left px-3 py-1.5 hover:bg-accent transition-colors`,children:`Copy absolute path`}),(0,G.jsx)(`button`,{type:`button`,onClick:()=>_(m.crumb.relPath),className:`flex items-center gap-2 w-full text-left px-3 py-1.5 hover:bg-accent transition-colors`,children:`Copy relative path`}),(0,G.jsx)(`div`,{className:`border-t border-border/50 my-0.5`}),(0,G.jsx)(`button`,{type:`button`,onClick:()=>y(m.crumb.absPath,`terminal`),className:`flex items-center gap-2 w-full text-left px-3 py-1.5 hover:bg-accent transition-colors`,children:`Open in terminal`}),(0,G.jsx)(`button`,{type:`button`,onClick:()=>y(m.crumb.absPath,`file-manager`),className:`flex items-center gap-2 w-full text-left px-3 py-1.5 hover:bg-accent transition-colors`,children:`Open in file manager`}),(0,G.jsx)(`div`,{className:`border-t border-border/50 mt-0.5 pt-0.5`,children:(0,G.jsx)(`div`,{className:`px-3 py-1 text-[9px] text-muted-foreground/50 truncate max-w-[200px]`,children:m.crumb.absPath})})]})]})}var Ks={note:Tn,ask:Ve,assign:De,steer:h,btw:at,broadcast:De,status:nn,result:We};function qs(e){let t=new Date(e),n=Date.now()-t.getTime();return n<6e4?`now`:n<36e5?`${Math.round(n/6e4)}m`:n<864e5?`${Math.round(n/36e5)}h`:t.toLocaleDateString()}function Js({className:e}){let t=nr(e=>e.messages),n=nr(e=>e.agents),[i,a]=(0,z.useState)(!1),[o,s]=(0,z.useState)(!1),{client:c}=Z(),[l,u]=(0,z.useState)(c.status.state===`open`);(0,z.useEffect)(()=>{let e=c.onStatus(e=>u(e.state===`open`));return()=>e()},[c]),(0,z.useEffect)(()=>{l&&(c.send({type:`mailbox.messages`,payload:{limit:30}}),c.send({type:`mailbox.agents`,payload:{}}))},[l,c]);let d=t.filter(e=>!e.completed).length,f=n.filter(e=>e.online).length;async function p(){t.length!==0&&await qo({title:`Delete all ${t.length} message${t.length===1?``:`s`}?`,message:`The mailbox file is truncated for every agent. This cannot be undone.`,confirmLabel:`Delete all`,danger:!0})&&(s(!0),c.send({type:`mailbox.clear`}))}return(0,z.useEffect)(()=>{o&&t.length===0&&s(!1)},[o,t.length]),(0,G.jsxs)(`div`,{className:Y(`rounded-lg border border-border bg-card/60 backdrop-blur-sm`,e),children:[(0,G.jsxs)(`button`,{type:`button`,onClick:()=>a(e=>!e),className:`flex w-full items-center gap-2 px-3 py-2.5 text-left hover:bg-accent/40 rounded-t-lg transition-colors`,children:[(0,G.jsx)(ve,{className:`h-4 w-4 text-cyan-500`}),(0,G.jsx)(`span`,{className:`text-xs font-semibold text-foreground flex-1 min-w-0 truncate`,children:`Mailbox`}),d>0&&(0,G.jsx)(`span`,{className:`inline-flex items-center px-1.5 py-0.5 rounded-full text-[10px] font-bold bg-yellow-100 dark:bg-yellow-900/40 text-yellow-700 dark:text-yellow-400`,children:d}),(0,G.jsxs)(`span`,{className:`text-[10px] text-muted-foreground`,children:[f,` online`]})]}),!i&&(0,G.jsxs)(`div`,{className:`px-3 pb-3 space-y-2`,children:[t.length>0?(0,G.jsxs)(`div`,{className:`space-y-1`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsx)(`span`,{className:`text-[10px] font-semibold text-muted-foreground uppercase tracking-wide`,children:`Messages`}),(0,G.jsxs)(`button`,{type:`button`,onClick:p,disabled:o,className:`flex items-center gap-1 text-[10px] text-muted-foreground hover:text-red-500 disabled:opacity-40 transition-colors`,title:`Delete all messages`,children:[(0,G.jsx)(yn,{className:`h-3 w-3`}),o?`Deleting…`:`Delete all`]})]}),t.slice(0,8).map(e=>{let t=Ks[e.type]??He,n=e.readByCount>0;return(0,G.jsxs)(`div`,{className:Y(`flex items-start gap-2 px-2 py-1.5 rounded text-xs`,!n&&`bg-yellow-50 dark:bg-yellow-950/20`),children:[(0,G.jsx)(t,{className:Y(`h-3.5 w-3.5 mt-0.5 shrink-0`,n?`text-muted-foreground`:`text-yellow-600`)}),(0,G.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,G.jsx)(`span`,{className:Y(`font-medium truncate`,!n&&`text-yellow-800 dark:text-yellow-300`),children:e.from}),e.completed&&(0,G.jsx)(We,{className:`h-3 w-3 text-green-500 shrink-0`}),!n&&(0,G.jsx)(`span`,{className:`text-[9px] text-yellow-600 font-bold`,children:`NEW`})]}),(0,G.jsx)(`div`,{className:`text-muted-foreground truncate`,children:e.subject}),(0,G.jsxs)(`div`,{className:`text-[10px] text-muted-foreground/70 truncate`,children:[e.body.slice(0,60),e.body.length>60?`…`:``]})]}),(0,G.jsxs)(`div`,{className:`shrink-0 text-[10px] text-muted-foreground flex flex-col items-end gap-0.5`,children:[(0,G.jsx)(`span`,{children:qs(e.timestamp)}),n&&(0,G.jsxs)(`span`,{className:`flex items-center gap-0.5`,children:[(0,G.jsx)(Xt,{className:`h-3 w-3`}),e.readByCount]})]})]},e.id)})]}):(0,G.jsxs)(`div`,{className:`text-xs text-muted-foreground py-2 text-center`,children:[(0,G.jsx)(r,{className:`h-4 w-4 mx-auto mb-1 opacity-40`}),`No messages yet.`]}),n.length>0&&(0,G.jsxs)(`div`,{className:`border-t border-border pt-2`,children:[(0,G.jsxs)(`div`,{className:`text-[10px] font-semibold text-muted-foreground mb-1 flex items-center gap-1`,children:[(0,G.jsx)(kt,{className:`h-3 w-3`}),` Agents`]}),n.filter(e=>e.online).slice(0,5).map(e=>(0,G.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[10px] text-muted-foreground py-0.5`,children:[(0,G.jsx)(`span`,{className:Y(`h-1.5 w-1.5 rounded-full`,e.online?`bg-green-500`:`bg-muted-foreground/30`)}),(0,G.jsx)(`span`,{className:`font-medium text-foreground/80`,children:e.name}),e.role&&(0,G.jsxs)(`span`,{className:`opacity-60`,children:[`(`,e.role,`)`]}),(0,G.jsx)(`span`,{className:`opacity-50`,children:e.status}),e.currentTool&&(0,G.jsx)(`span`,{className:`text-cyan-500`,children:e.currentTool}),(0,G.jsx)(`span`,{className:`ml-auto opacity-50`,children:qs(e.lastSeenAt)})]},e.agentId)),n.filter(e=>!e.online).length>0&&(0,G.jsxs)(`div`,{className:`text-[10px] text-muted-foreground/50 mt-0.5`,children:[`+`,n.filter(e=>!e.online).length,` offline`]})]})]})]})}function Ys({fullView:e}){let[t,n]=(0,z.useState)([]),[r,i]=(0,z.useState)(!0),[a,o]=(0,z.useState)(!1),[s,c]=(0,z.useState)(``),[l,u]=(0,z.useState)(``),[d,f]=(0,z.useState)(!1),p=(0,z.useRef)(null),[m,h]=(0,z.useState)({open:!1,project:null,agentCount:0}),g=(0,z.useCallback)(()=>{B().send({type:`projects.list`})},[]);(0,z.useEffect)(()=>{i(!0);let e=B(),t=e.on(`projects.list`,e=>{let t=e.payload;n(t.projects??[]),i(!1)}),r=e.on(`projects.added`,e=>{let t=e.payload;t.slug?(X.success(t.message),g()):X.error(t.message)});return g(),()=>{t(),r()}},[g]);let _=e=>{if(!e)return`never`;let t=Date.now()-new Date(e).getTime(),n=Math.floor(t/6e4);if(n<1)return`just now`;if(n<60)return`${n}m ago`;let r=Math.floor(n/60);if(r<24)return`${r}h ago`;let i=Math.floor(r/24);return i===1?`yesterday`:i<30?`${i}d ago`:i<365?`${Math.floor(i/30)}mo ago`:`${Math.floor(i/365)}y ago`},v=(0,z.useCallback)(e=>{let t=U.getState().session?.id;if(t){let n=K.getState().getAgentsBySession(t).filter(e=>e.status===`running`);if(n.length>0){h({open:!0,project:e,agentCount:n.length});return}}y(e)},[]),y=(0,z.useCallback)(e=>{let t=B();t.send({type:`projects.select`,payload:{root:e.root,name:e.name}});let n=t.on(`projects.selected`,e=>{let t=e.payload;n();let r=t.message.match(/(https?:\/\/[^\s]+)/);r&&r[1]?(window.open(r[1],`_blank`),X.success(`Opening ${t.name} in a new tab...`)):X.info(t.message)})},[]),x=(0,z.useCallback)(()=>{let e=s.trim();if(!e){X.error(`Please enter a folder path.`);return}o(!0);let t=B();t.send({type:`projects.add`,payload:{root:e,name:l.trim()||void 0}});let n=t.on(`projects.added`,()=>{n(),o(!1),f(!1),c(``),u(``)})},[s,l]),S=m.open&&m.project&&(0,G.jsx)(Po,{open:!0,onOpenChange:()=>h({open:!1,project:null,agentCount:0}),children:(0,G.jsxs)(Ro,{className:`sm:max-w-sm`,children:[(0,G.jsxs)(zo,{children:[(0,G.jsx)(Vo,{children:`Running Agents`}),(0,G.jsxs)(Ho,{children:[m.agentCount,` agent`,m.agentCount===1?` is`:`s are`,` running in the current session. Switching projects will stop them.`]})]}),(0,G.jsxs)(Bo,{children:[(0,G.jsx)(Q,{variant:`outline`,size:`sm`,onClick:()=>h({open:!1,project:null,agentCount:0}),children:`Cancel`}),(0,G.jsx)(Q,{size:`sm`,variant:`destructive`,onClick:()=>{let e=m.project;h({open:!1,project:null,agentCount:0}),y(e)},children:`Switch anyway`})]})]})}),C=[...t].sort((e,t)=>e.lastSeen&&t.lastSeen?t.lastSeen.localeCompare(e.lastSeen):e.lastSeen?-1:t.lastSeen?1:e.name.localeCompare(t.name)),w=(0,G.jsxs)(Po,{open:d,onOpenChange:f,children:[(0,G.jsx)(Fo,{asChild:!0,children:(0,G.jsxs)(Q,{variant:`outline`,size:`sm`,className:`gap-1 h-7 text-xs`,children:[(0,G.jsx)(xn,{className:`h-3 w-3`}),`Register Project`]})}),(0,G.jsxs)(Ro,{className:`sm:max-w-md`,children:[(0,G.jsxs)(zo,{children:[(0,G.jsx)(Vo,{children:`Register New Project`}),(0,G.jsxs)(Ho,{children:[`Enter the absolute path to a project folder. The project will be added to`,` `,(0,G.jsx)(`code`,{className:`font-mono bg-muted/40 px-1 rounded text-xs`,children:`~/.wrongstack/projects.json`}),`.`]})]}),(0,G.jsxs)(`div`,{className:`space-y-3`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{htmlFor:`proj-folder`,className:`text-xs font-medium text-muted-foreground mb-1 block`,children:`Folder path`}),(0,G.jsx)($o,{id:`proj-folder`,placeholder:`/home/user/my-project or C:\\Users\\me\\my-project`,value:s,onChange:e=>c(e.target.value),onKeyDown:e=>{e.key===`Enter`&&p.current?.focus()}})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{htmlFor:`proj-name`,className:`text-xs font-medium text-muted-foreground mb-1 block`,children:`Project name (optional β€” defaults to folder name)`}),(0,G.jsx)($o,{id:`proj-name`,ref:p,placeholder:`My Project`,value:l,onChange:e=>u(e.target.value),onKeyDown:e=>{e.key===`Enter`&&x()}})]})]}),(0,G.jsxs)(Bo,{children:[(0,G.jsx)(Q,{variant:`outline`,size:`sm`,onClick:()=>f(!1),children:`Cancel`}),(0,G.jsxs)(Q,{size:`sm`,onClick:x,disabled:a||!s.trim(),children:[a?(0,G.jsx)(I,{className:`h-3 w-3 animate-spin mr-1`}):null,`Register`]})]})]})]});if(r){let t=(0,G.jsx)(`div`,{className:`flex items-center justify-center py-6`,children:(0,G.jsx)(I,{className:`h-4 w-4 animate-spin text-muted-foreground`})});return e?(0,G.jsxs)(`div`,{className:`h-full flex flex-col overflow-hidden`,children:[(0,G.jsx)(`div`,{className:`px-3 py-2 border-b flex items-center justify-between`,children:(0,G.jsx)(`h2`,{className:`text-xs font-semibold text-muted-foreground uppercase tracking-wider`,children:`Projects`})}),(0,G.jsx)(`div`,{className:`flex-1 flex items-center justify-center`,children:t})]}):t}let T=(0,G.jsx)(`div`,{className:Y(`space-y-1`,e&&`p-2`),children:C.map(e=>(0,G.jsxs)(`button`,{type:`button`,onClick:()=>v(e),className:`flex items-start gap-2 w-full text-left px-2 py-1.5 rounded border bg-card/40 text-xs hover:bg-accent hover:border-primary/40 transition-colors`,children:[(0,G.jsx)(qe,{className:`h-3.5 w-3.5 shrink-0 mt-0.5 text-muted-foreground`}),(0,G.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,G.jsx)(`div`,{className:`font-medium truncate`,children:e.name}),(0,G.jsx)(`div`,{className:`font-mono text-[10px] text-muted-foreground truncate`,children:e.root}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2 mt-0.5 text-[10px] text-muted-foreground/60`,children:[(0,G.jsx)(`span`,{className:`font-mono`,children:e.slug}),e.lastSeen&&(0,G.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,G.jsx)(ct,{className:`h-2.5 w-2.5`}),_(e.lastSeen)]})]})]}),(0,G.jsx)(b,{className:`h-3 w-3 shrink-0 mt-1 text-muted-foreground/40`})]},e.slug))});return e?(0,G.jsxs)(`div`,{className:`h-full flex flex-col overflow-hidden`,children:[S,(0,G.jsxs)(`div`,{className:`px-3 py-2 border-b shrink-0`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsx)(`h2`,{className:`text-xs font-semibold text-muted-foreground uppercase tracking-wider`,children:`Projects`}),w]}),(0,G.jsxs)(`p`,{className:`text-[10px] text-muted-foreground/60 mt-0.5`,children:[`Known projects from`,` `,(0,G.jsx)(`code`,{className:`font-mono bg-muted/40 px-0.5 rounded`,children:`~/.wrongstack/projects.json`})]})]}),t.length===0?(0,G.jsx)(`div`,{className:`flex-1 flex items-center justify-center`,children:(0,G.jsxs)(`div`,{className:`text-xs text-muted-foreground italic py-2`,children:[`No projects registered. Use the button above or run`,` `,(0,G.jsx)(`code`,{className:`font-mono bg-muted/40 px-1 rounded`,children:`wstack`}),` `,`in a directory to register it.`]})}):(0,G.jsx)(`div`,{className:`flex-1 overflow-y-auto`,children:T}),(0,G.jsx)(`div`,{className:`px-3 py-2 border-t shrink-0`,children:(0,G.jsx)(`p`,{className:`text-[9px] text-muted-foreground/40 text-center`,children:`Click a project to open it in a new WebUI tab`})})]}):(0,G.jsxs)(`div`,{className:`space-y-2`,children:[S,(0,G.jsx)(`div`,{className:`flex items-center justify-between`,children:w}),t.length===0?(0,G.jsxs)(`div`,{className:`text-xs text-muted-foreground italic py-2`,children:[`No projects registered. Use the button above or run`,` `,(0,G.jsx)(`code`,{className:`font-mono bg-muted/40 px-1 rounded`,children:`wstack`}),` `,`in a directory to register it.`]}):T]})}var Xs=[` `,`▁`,`β–‚`,`β–ƒ`,`β–„`,`β–…`,`β–†`,`β–‡`,`β–ˆ`],Zs=12;function Qs(e,t){return t===0?0:Math.min(8,Math.round(e/t*8))}function $s({bins:e,className:t,width:n=Zs}){let r=Array.from({length:Zs},(t,n)=>e.at(-(Zs-n))??0),i=Math.max(...r,1);return i===1&&r.every(e=>e===0)?(0,G.jsx)(`span`,{className:t,"aria-label":`No activity`,title:`No activity yet`,children:`β€”`}):(0,G.jsx)(`span`,{className:t,"aria-label":`Activity sparkline: max ${i} events`,title:`Activity sparkline β€” peak ${i} events/bucket`,children:r.map((e,t)=>{let n=Qs(e,i),r=Xs[n];return(0,G.jsx)(`span`,{style:{color:n>=7?`hsl(var(--success))`:`hsl(var(--muted-foreground))`,opacity:n>0?void 0:.3},children:r},t)})})}var ec={running:{led:`text-[hsl(var(--success))]`,label:`running`,pulse:!0},completed:{led:`text-[hsl(var(--success))]`,label:`done`,pulse:!1},failed:{led:`text-destructive`,label:`failed`,pulse:!1},timeout:{led:`text-[hsl(var(--warning))]`,label:`timeout`,pulse:!1},stopped:{led:`text-muted-foreground`,label:`stopped`,pulse:!1}};function tc(e){return e<=0?`$0`:e>=.01?`$${e.toFixed(3)}`:`$${e.toFixed(5)}`.replace(/0+$/,``).replace(/\.$/,``)}function nc(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}K`:String(e)}function rc(e){let t=Math.floor(e/1e3);return t<60?`${t}s`:`${Math.floor(t/60)}m ${t%60}s`}function ic({agent:e,onClose:n}){let r=ec[e.status],i=e.status===`running`,a=e.currentTool??e.lastTool,o=Date.now()-e.startedAt,[s,l]=(0,z.useState)(!1),u=K(e=>e.leaderId),d=e.id===u,f=(0,z.useCallback)(async e=>{try{await navigator.clipboard.writeText(e),l(!0),setTimeout(()=>l(!1),2e3)}catch{}},[]),p=e.ctxPct>=85?`bg-red-500/15 text-red-600 dark:text-red-400`:e.ctxPct>=70?`bg-amber-500/15 text-amber-600 dark:text-amber-400`:`bg-muted text-muted-foreground`;return(0,G.jsx)(`div`,{className:`fixed inset-0 z-50 flex items-start justify-center pt-[10vh] bg-black/40 backdrop-blur-sm`,children:(0,G.jsxs)(`div`,{className:`w-full max-w-xl max-h-[80vh] overflow-y-auto rounded-xl border bg-card shadow-2xl`,children:[(0,G.jsxs)(`div`,{className:Y(`flex items-center justify-between px-4 py-3 border-b`,i?`border-primary/20`:`border-border`),children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`span`,{className:Y(`led`,r.led,r.pulse&&`led-pulse`)}),(0,G.jsx)(`h3`,{className:`text-sm font-semibold`,children:e.name}),d&&(0,G.jsx)(c,{className:`h-3.5 w-3.5 text-amber-500 shrink-0`,"aria-label":`leader`}),(0,G.jsx)(`span`,{className:`text-[10px] uppercase tracking-wider text-muted-foreground`,children:r.label})]}),(0,G.jsx)(`button`,{type:`button`,onClick:n,className:`p-1 rounded-md hover:bg-muted transition-colors`,children:(0,G.jsx)(F,{className:`h-4 w-4`})})]}),(0,G.jsxs)(`div`,{className:`p-4 space-y-4`,children:[e.description&&(0,G.jsx)(`div`,{className:`text-xs text-muted-foreground leading-relaxed`,children:e.description}),(0,G.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,G.jsxs)(`div`,{className:`rounded-lg border bg-muted/30 px-3 py-2`,children:[(0,G.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:`Provider / Model`}),(0,G.jsxs)(`div`,{className:`flex items-center gap-1 mt-0.5`,children:[(0,G.jsx)(E,{className:`h-3 w-3 text-muted-foreground`}),(0,G.jsxs)(`span`,{className:`text-xs font-mono font-medium`,children:[e.provider??`?`,`/`,e.model??`?`]})]})]}),(0,G.jsxs)(`div`,{className:`rounded-lg border bg-muted/30 px-3 py-2`,children:[(0,G.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:`Elapsed`}),(0,G.jsxs)(`div`,{className:`flex items-center gap-1 mt-0.5`,children:[(0,G.jsx)(N,{className:`h-3 w-3 text-muted-foreground`}),(0,G.jsx)(`span`,{className:`text-xs font-mono tabular`,children:rc(o)}),i&&(0,G.jsx)(`span`,{className:`text-[10px] text-[hsl(var(--success))]`,children:`Β· running`})]})]}),(0,G.jsxs)(`div`,{className:`rounded-lg border bg-muted/30 px-3 py-2`,children:[(0,G.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:`Iterations`}),(0,G.jsx)(`span`,{className:`block text-xs font-mono font-medium mt-0.5 tabular`,children:e.iteration})]}),(0,G.jsxs)(`div`,{className:`rounded-lg border bg-muted/30 px-3 py-2`,children:[(0,G.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:`Tool Calls`}),(0,G.jsx)(`span`,{className:`block text-xs font-mono font-medium mt-0.5 tabular`,children:e.toolCalls})]}),(0,G.jsxs)(`div`,{className:`rounded-lg border bg-muted/30 px-3 py-2`,children:[(0,G.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:`Cost`}),(0,G.jsx)(`span`,{className:`block text-xs font-mono font-medium mt-0.5 tabular`,children:tc(e.costUsd)})]}),e.extensions>0&&(0,G.jsxs)(`div`,{className:`rounded-lg border bg-muted/30 px-3 py-2`,children:[(0,G.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:`Budget Extensions`}),(0,G.jsxs)(`span`,{className:`block text-xs font-mono font-medium mt-0.5 tabular`,children:[`βš‘Γ—`,e.extensions]})]})]}),i&&(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:`Activity`}),(0,G.jsx)($s,{bins:e.sparklineBins,className:`font-mono`})]}),e.budgetWarning&&(0,G.jsxs)(`div`,{className:`flex items-center gap-2 px-3 py-2 rounded-lg bg-amber-500/10 border border-amber-500/20 text-xs`,children:[(0,G.jsx)(Ue,{className:`h-3.5 w-3.5 text-amber-500 shrink-0`}),(0,G.jsxs)(`span`,{className:`text-amber-600 dark:text-amber-400`,children:[`⚑ hitting `,(0,G.jsx)(`strong`,{children:e.budgetWarning.kind}),` limit (`,e.budgetWarning.used,`/`,e.budgetWarning.limit,`) β€” extending`]})]}),e.maxContext>0&&(0,G.jsxs)(`div`,{className:`space-y-1`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between text-[10px]`,children:[(0,G.jsx)(`span`,{className:`text-muted-foreground`,children:`Context window`}),(0,G.jsxs)(`span`,{className:Y(`tabular font-medium`,p.replace(/bg-\S+\s*/g,``)),children:[e.ctxPct,`%`]})]}),(0,G.jsx)(`div`,{className:`h-1.5 w-full overflow-hidden rounded-full bg-muted`,children:(0,G.jsx)(`div`,{className:Y(`h-full rounded-full transition-all`,e.ctxPct>=85?`bg-destructive`:e.ctxPct>=70?`bg-[hsl(var(--warning))]`:`bg-primary`),style:{width:`${Math.min(200,Math.max(2,e.ctxPct))}%`}})}),(0,G.jsxs)(`div`,{className:`text-[10px] text-muted-foreground tabular text-right`,children:[nc(e.ctxTokens),` / `,nc(e.maxContext),` tokens`]})]}),a&&(0,G.jsxs)(`div`,{className:Y(`flex items-center gap-2 rounded-lg border px-3 py-2`,i?`border-primary/30 bg-primary/[0.04]`:`border-border bg-muted/30`),children:[(0,G.jsx)(t,{className:Y(`h-3.5 w-3.5`,i?`text-primary animate-pulse`:`text-muted-foreground`)}),(0,G.jsx)(`span`,{className:`text-xs font-mono`,children:a}),(0,G.jsx)(`span`,{className:`text-[10px] text-muted-foreground ml-auto`,children:e.currentTool?`running…`:`last tool`})]}),e.error&&(0,G.jsxs)(`div`,{className:`rounded-lg border border-destructive/30 bg-destructive/5 p-3`,children:[(0,G.jsx)(`span`,{className:`text-[10px] font-semibold text-destructive uppercase tracking-wider`,children:`Error`}),(0,G.jsx)(`p`,{className:`text-xs text-destructive/90 mt-1 leading-relaxed`,children:e.error.message})]}),e.finalText?(0,G.jsxs)(`div`,{className:`rounded-lg border bg-muted/20 p-3`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between mb-1.5`,children:[(0,G.jsx)(`span`,{className:`text-[10px] font-semibold text-muted-foreground uppercase tracking-wider`,children:`Final Output`}),(0,G.jsxs)(`button`,{type:`button`,onClick:()=>f(e.finalText),className:`flex items-center gap-1 px-1.5 py-0.5 rounded text-[10px] text-muted-foreground hover:text-foreground hover:bg-muted transition-colors`,title:`Copy output`,children:[s?(0,G.jsx)(Ot,{className:`h-3 w-3 text-emerald-500`}):(0,G.jsx)(Fe,{className:`h-3 w-3`}),s?`Copied`:`Copy`]})]}),(0,G.jsx)(`pre`,{className:`text-xs whitespace-pre-wrap font-mono text-foreground/80 leading-relaxed max-h-64 overflow-y-auto`,children:e.finalText})]}):e.partialText?(0,G.jsxs)(`div`,{className:`rounded-lg border bg-muted/20 p-3`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between mb-1.5`,children:[(0,G.jsx)(`span`,{className:`text-[10px] font-semibold text-muted-foreground uppercase tracking-wider`,children:`Live Output`}),(0,G.jsxs)(`button`,{type:`button`,onClick:()=>f(e.partialText),className:`flex items-center gap-1 px-1.5 py-0.5 rounded text-[10px] text-muted-foreground hover:text-foreground hover:bg-muted transition-colors`,title:`Copy output`,children:[s?(0,G.jsx)(Ot,{className:`h-3 w-3 text-emerald-500`}):(0,G.jsx)(Fe,{className:`h-3 w-3`}),s?`Copied`:`Copy`]})]}),(0,G.jsx)(`pre`,{className:`text-xs whitespace-pre-wrap font-mono text-foreground/80 leading-relaxed max-h-48 overflow-y-auto`,children:e.partialText})]}):i?(0,G.jsxs)(`div`,{className:`rounded-lg border border-dashed border-border p-3 text-center`,children:[(0,G.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`Waiting for output…`}),(0,G.jsx)(`p`,{className:`text-[10px] text-muted-foreground/60 mt-0.5`,children:`Output appears here as the agent streams text.`})]}):null,e.toolLog.length>0&&(0,G.jsxs)(`div`,{className:`space-y-1`,children:[(0,G.jsxs)(`span`,{className:`text-[10px] font-semibold text-muted-foreground uppercase tracking-wider`,children:[`Tool Log (`,e.toolLog.length,`)`]}),(0,G.jsxs)(`div`,{className:`max-h-40 overflow-y-auto space-y-0.5`,children:[e.toolLog.slice(0,15).map((e,t)=>(0,G.jsxs)(`div`,{className:Y(`flex items-center gap-2 rounded px-2 py-1 text-[10px]`,e.ok?`bg-muted/30`:`bg-destructive/5 border border-destructive/20`),children:[(0,G.jsx)(`span`,{className:Y(`led shrink-0`,e.ok?`text-[hsl(var(--success))]`:`text-destructive`)}),(0,G.jsx)(`span`,{className:`font-mono truncate flex-1`,children:e.name}),(0,G.jsxs)(`span`,{className:`tabular text-muted-foreground`,children:[e.durationMs,`ms`]}),!e.ok&&(0,G.jsx)(`span`,{className:`text-destructive font-medium`,children:`fail`})]},`${e.name}-${e.at}-${t}`)),e.toolLog.length>15&&(0,G.jsxs)(`p`,{className:`text-[9px] text-muted-foreground text-center px-2 py-0.5`,children:[`+`,e.toolLog.length-15,` more tools`]})]})]})]})]})})}function ac({a:e,onClick:n}){let r=ec[e.status],i=e.status===`running`,a=e.currentTool??e.lastTool;return(0,G.jsxs)(`button`,{type:`button`,onClick:n,className:Y(`flex min-w-[12rem] max-w-[15rem] flex-col gap-1 rounded-lg border p-2 transition-colors text-left cursor-pointer`,`hover:border-primary/40 hover:bg-primary/[0.06]`,i?`border-primary/30 bg-primary/[0.04]`:`border-border bg-card opacity-85`),children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-1.5 min-w-0`,children:[(0,G.jsx)(`span`,{className:Y(`led shrink-0`,r.led,r.pulse&&`led-pulse`)}),(0,G.jsx)(`span`,{className:`truncate text-[11px] font-semibold text-foreground`,title:e.name,children:e.name}),(0,G.jsxs)(`span`,{className:`tabular ml-auto shrink-0 text-[10px] text-muted-foreground`,children:[e.iteration,`it Β· `,e.toolCalls,`t`]})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-1.5 min-w-0`,children:[e.model&&(0,G.jsxs)(`span`,{className:`flex items-center gap-0.5 text-[10px] text-muted-foreground truncate`,title:`${e.provider??``}/${e.model}`,children:[(0,G.jsx)(E,{className:`h-2.5 w-2.5 shrink-0`}),(0,G.jsx)(`span`,{className:`truncate font-mono`,children:e.model})]}),(0,G.jsx)(`span`,{className:`tabular text-[10px] text-foreground/75 ml-auto`,children:tc(e.costUsd)})]}),a&&(0,G.jsxs)(`div`,{className:Y(`flex items-center gap-1 text-[10px] truncate`,i?`text-primary`:`text-muted-foreground`),title:e.currentTool?`running ${a}`:`last: ${a}`,children:[(0,G.jsx)(t,{className:Y(`h-2.5 w-2.5 shrink-0`,i&&`animate-pulse`)}),(0,G.jsx)(`span`,{className:`truncate font-mono`,children:a})]}),i&&e.maxContext>0&&(0,G.jsxs)(`div`,{className:`flex items-center gap-1`,title:`Context ${e.ctxPct}%`,children:[(0,G.jsx)(`div`,{className:`h-1 flex-1 overflow-hidden rounded-full bg-muted`,children:(0,G.jsx)(`div`,{className:Y(`h-full rounded-full transition-all`,e.ctxPct>=85?`bg-destructive`:e.ctxPct>=70?`bg-[hsl(var(--warning))]`:`bg-primary`),style:{width:`${Math.min(200,Math.max(2,e.ctxPct))}%`}})}),(0,G.jsx)(`span`,{className:`tabular text-[9px] text-muted-foreground`,children:e.maxContext>0?`${e.ctxPct}%`:`β€”`})]}),e.error&&(0,G.jsx)(`div`,{className:`truncate rounded bg-destructive/10 px-1 py-0.5 text-[9px] text-destructive`,title:e.error.message,children:e.error.message})]})}function oc({className:e}){let t=K(e=>e.agents),[n,r]=(0,z.useState)(!0),[i,a]=(0,z.useState)(null),o=(0,z.useMemo)(()=>{let e=Array.from(t.values());return e.sort((e,t)=>{let n=e.status===`running`?0:1,r=t.status===`running`?0:1;return n===r?e.startedAt-t.startedAt:n-r}),e},[t]),s=i?o.find(e=>e.id===i):null;if(o.length===0)return null;let c=o.filter(e=>e.status===`running`),l=o.filter(e=>e.status===`completed`),u=o.filter(e=>e.status===`failed`||e.status===`timeout`),d=o.reduce((e,t)=>e+(t.costUsd??0),0),f=n&&o.length>=3;return(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`div`,{className:Y(`rounded-lg border border-border bg-card/50 backdrop-blur-sm overflow-hidden`,e),children:[(0,G.jsxs)(`button`,{type:`button`,onClick:()=>r(e=>!e),className:`flex w-full items-center gap-2 px-3 py-1.5 text-left hover:bg-muted/30 transition-colors`,children:[(0,G.jsx)(L,{className:`h-3.5 w-3.5 text-primary`}),(0,G.jsx)(`span`,{className:`text-[11px] font-semibold text-foreground`,children:`Fleet`}),(0,G.jsxs)(`span`,{className:`flex items-center gap-1.5 ml-auto text-[10px]`,children:[c.length>0&&(0,G.jsxs)(`span`,{className:`flex items-center gap-1 text-[hsl(var(--success))]`,children:[(0,G.jsx)(`span`,{className:`led led-pulse text-[hsl(var(--success))]`}),c.length]}),l.length>0&&(0,G.jsxs)(`span`,{className:`text-muted-foreground`,children:[l.length,` done`]}),u.length>0&&(0,G.jsxs)(`span`,{className:`text-destructive`,children:[u.length,` err`]}),d>0&&(0,G.jsx)(`span`,{className:`tabular text-foreground/70`,children:tc(d)})]}),f?(0,G.jsx)(mn,{className:`h-3.5 w-3.5 text-muted-foreground shrink-0`}):(0,G.jsx)(sn,{className:`h-3.5 w-3.5 text-muted-foreground shrink-0`})]}),!f&&(0,G.jsx)(`div`,{className:`flex gap-2 overflow-x-auto px-2 pb-2`,children:o.map(e=>(0,G.jsx)(ac,{a:e,onClick:()=>a(e.id)},e.id))})]}),s&&(0,G.jsx)(ic,{agent:s,onClose:()=>a(null)})]})}var sc={running:{led:`text-[hsl(var(--success))]`,label:`running`,pulse:!0},completed:{led:`text-[hsl(var(--success))]`,label:`done`,pulse:!1},failed:{led:`text-destructive`,label:`failed`,pulse:!1},timeout:{led:`text-[hsl(var(--warning))]`,label:`timeout`,pulse:!1},stopped:{led:`text-muted-foreground`,label:`stopped`,pulse:!1}};function cc(e){return e<=0?`$0`:e>=.01?`$${e.toFixed(3)}`:`$${e.toFixed(4)}`}function lc({agent:e,onClick:n}){let r=sc[e.status],i=e.status===`running`;return(0,G.jsxs)(`button`,{type:`button`,onClick:n,className:Y(`w-full text-left rounded-lg border px-2.5 py-2 transition-colors`,`hover:border-primary/40 hover:bg-primary/[0.04]`,i?`border-primary/30 bg-primary/[0.03]`:`border-border/60 bg-card/40`),children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-1.5 min-w-0`,children:[(0,G.jsx)(`span`,{className:Y(`led shrink-0`,r.led,r.pulse&&`led-pulse`)}),(0,G.jsx)(`span`,{className:`truncate text-[11px] font-semibold`,title:e.name,children:e.name}),(0,G.jsxs)(`span`,{className:`tabular ml-auto shrink-0 text-[10px] text-muted-foreground`,children:[e.iteration,`it`]})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-1.5 mt-0.5 min-w-0`,children:[e.model?(0,G.jsx)(`span`,{className:`text-[10px] text-muted-foreground truncate font-mono`,children:e.model}):(0,G.jsx)(`span`,{className:`text-[10px] text-muted-foreground italic`,children:`pending…`}),(0,G.jsx)(`span`,{className:`tabular ml-auto text-[10px] text-foreground/70`,children:cc(e.costUsd)})]}),(e.currentTool||e.lastTool)&&(0,G.jsxs)(`div`,{className:`flex items-center gap-1 mt-1 text-[10px] text-muted-foreground truncate`,children:[(0,G.jsx)(t,{className:Y(`h-2.5 w-2.5 shrink-0`,i&&`animate-pulse text-primary`)}),(0,G.jsx)(`span`,{className:`truncate font-mono`,children:e.currentTool??e.lastTool})]})]})}function uc(){let e=K(e=>e.agents);W(e=>e.setCurrentView);let[t,n]=(0,z.useState)(null),r=(0,z.useMemo)(()=>{let t=Array.from(e.values());return t.sort((e,t)=>{let n=e.status===`running`?0:1,r=t.status===`running`?0:1;return n===r?e.startedAt-t.startedAt:n-r}),t},[e]),i=r.filter(e=>e.status===`running`).length,a=t?r.find(e=>e.id===t)??null:null;return r.length===0?(0,G.jsx)(`div`,{className:`flex-1 flex items-center justify-center p-4`,children:(0,G.jsxs)(`div`,{className:`text-center text-muted-foreground`,children:[(0,G.jsx)(L,{className:`h-8 w-8 mx-auto mb-3 opacity-20`}),(0,G.jsx)(`p`,{className:`text-sm font-medium`,children:`No agents yet`}),(0,G.jsx)(`p`,{className:`text-xs mt-1`,children:`Subagents appear here when the fleet is active.`})]})}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`div`,{className:`px-3 py-2 border-b text-[10px] text-muted-foreground flex items-center gap-2`,children:[(0,G.jsx)(`span`,{className:`font-semibold uppercase tracking-wider`,children:`Fleet`}),(0,G.jsxs)(`span`,{className:`ml-auto tabular-nums`,children:[i>0?`${i} running Β· `:``,r.length,` total`]})]}),(0,G.jsx)(`div`,{className:`flex-1 overflow-y-auto p-2 space-y-1.5`,children:r.map(e=>(0,G.jsx)(lc,{agent:e,onClick:()=>n(e.id)},e.id))}),(0,G.jsx)(`div`,{className:`border-t px-3 py-2 shrink-0`,children:(0,G.jsxs)(`button`,{type:`button`,onClick:()=>W.getState().setAgentsMonitorOpen(!0),className:`w-full flex items-center justify-center gap-1.5 h-7 rounded-md border border-border text-[11px] text-muted-foreground hover:text-foreground hover:bg-accent transition-colors`,children:[(0,G.jsx)(Ze,{className:`h-3 w-3`}),`Open full agents view`]})}),a&&(0,G.jsx)(ic,{agent:a,onClose:()=>n(null)})]})}var dc=e=>{let t=Date.parse(e);if(Number.isNaN(t))return``;let n=Date.now()-t;if(n<6e4)return`just now`;if(n<36e5)return`${Math.floor(n/6e4)}m ago`;if(n<864e5)return`${Math.floor(n/36e5)}h ago`;let r=Math.floor(n/864e5);return r<7?`${r}d ago`:new Date(t).toLocaleDateString()};function fc(e){return e.filter(e=>e.tokenTotal===0&&!e.isCurrent).map(e=>e.id)}function pc({historyQuery:e,setHistoryQuery:t,historyEntries:n,historyLoading:r,historyError:i,wsConnected:a,listSessions:o,resumeSession:s,deleteSession:c}){let l=W(e=>e.favoriteSessionIds),u=W(e=>e.toggleFavoriteSession),d=W(e=>e.sessionNicknames),f=W(e=>e.setSessionNickname),[p,m]=(0,z.useState)(null),[h,g]=(0,z.useState)(``),[_,y]=(0,z.useState)(null);(0,z.useEffect)(()=>{_&&n.some(e=>e.id===_&&e.isCurrent)&&y(null)},[_,n]);let b=(0,z.useCallback)(e=>{y(e),s(e),setTimeout(()=>y(t=>t===e?null:t),1e4)},[s]),x=(0,z.useMemo)(()=>fc(n),[n]),S=(0,z.useCallback)(async()=>{if(x.length!==0&&await qo({title:x.length===1?`Delete 1 empty session?`:`Delete ${x.length} empty sessions?`,message:`Sessions without any token usage are removed from disk.`,confirmLabel:`Delete`,danger:!0}))for(let e of x)c(e)},[x,c]),C=(()=>{let t=e.trim().toLowerCase(),r=t?n.filter(e=>e.title.toLowerCase().includes(t)||e.model.toLowerCase().includes(t)||e.provider.toLowerCase().includes(t)||e.id.toLowerCase().includes(t)):n,i=new Date;i.setHours(0,0,0,0);let a=i.getTime(),o=a-864e5,s=a-6*864e5,c={today:[],yesterday:[],week:[],older:[]};for(let e of r){let t=Date.parse(e.startedAt);if(Number.isNaN(t)){c.older.push(e);continue}t>=a?c.today.push(e):t>=o?c.yesterday.push(e):t>=s?c.week.push(e):c.older.push(e)}let u=new Set(l),d=r.filter(e=>u.has(e.id)),f=[];d.length&&f.push({label:`Favorites`,rows:d,star:!0});let p=e=>e.filter(e=>!u.has(e.id)),m=p(c.today),h=p(c.yesterday),g=p(c.week),_=p(c.older);return m.length&&f.push({label:`Today`,rows:m}),h.length&&f.push({label:`Yesterday`,rows:h}),g.length&&f.push({label:`This week`,rows:g}),_.length&&f.push({label:`Earlier`,rows:_}),f})();return(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between px-4 py-2 border-b`,children:[(0,G.jsx)(`span`,{className:`text-xs uppercase tracking-wider text-muted-foreground`,children:`Recent sessions`}),(0,G.jsxs)(`div`,{className:`flex items-center gap-1`,children:[x.length>0&&(0,G.jsx)(`button`,{type:`button`,className:`h-6 w-6 inline-flex items-center justify-center rounded-md hover:bg-muted text-muted-foreground hover:text-destructive`,onClick:S,disabled:!a,title:`Delete ${x.length} empty session${x.length===1?``:`s`}`,children:(0,G.jsx)(yn,{className:`h-3.5 w-3.5`})}),(0,G.jsx)(`button`,{type:`button`,className:`h-6 w-6 inline-flex items-center justify-center rounded-md hover:bg-muted`,onClick:()=>o(50),disabled:!a,title:`Refresh`,children:r?(0,G.jsx)(I,{className:`h-3.5 w-3.5 animate-spin`}):(0,G.jsx)(Mt,{className:`h-3.5 w-3.5`})})]})]}),n.length>3&&(0,G.jsx)(`div`,{className:`px-3 py-2 border-b`,children:(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsx)(v,{className:`absolute left-2 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-muted-foreground/60`}),(0,G.jsx)(`input`,{type:`text`,value:e,onChange:e=>t(e.target.value),placeholder:`Filter title, model, provider…`,className:`w-full pl-7 pr-7 py-1 text-xs rounded-md bg-muted/40 border border-transparent focus:bg-background focus:border-input focus:outline-none focus:ring-1 focus:ring-ring placeholder:text-muted-foreground/50`}),e&&(0,G.jsx)(`button`,{type:`button`,onClick:()=>t(``),className:`absolute right-1 top-1/2 -translate-y-1/2 text-muted-foreground/60 hover:text-foreground p-0.5`,title:`Clear filter`,children:(0,G.jsx)(F,{className:`h-3 w-3`})})]})}),i&&(0,G.jsx)(`div`,{className:`px-4 py-2 text-xs text-destructive bg-destructive/5 border-b`,children:i}),(0,G.jsx)(es,{className:`flex-1`,children:n.length===0&&!r?(0,G.jsxs)(`div`,{className:`text-center text-muted-foreground py-8 px-4`,children:[(0,G.jsx)(ct,{className:`h-8 w-8 mx-auto mb-3 opacity-20`}),(0,G.jsx)(`p`,{className:`text-sm font-medium`,children:`No history yet`}),(0,G.jsx)(`p`,{className:`text-xs mt-1`,children:`Your conversations will appear here`})]}):C.length===0?(0,G.jsxs)(`div`,{className:`text-center text-muted-foreground py-8 px-4`,children:[(0,G.jsx)(v,{className:`h-8 w-8 mx-auto mb-3 opacity-20`}),(0,G.jsx)(`p`,{className:`text-sm font-medium`,children:`No matches`}),(0,G.jsx)(`p`,{className:`text-xs mt-1`,children:`Try a different filter`})]}):(0,G.jsx)(`div`,{className:`p-2 space-y-3`,children:C.map(e=>(0,G.jsxs)(`div`,{className:`space-y-1`,children:[(0,G.jsxs)(`div`,{className:Y(`sticky top-0 z-[1] px-1 pb-1 text-[10px] uppercase tracking-wider font-semibold bg-card/90 backdrop-blur-sm flex items-center gap-1`,e.star?`text-amber-500`:`text-muted-foreground/80`),children:[e.star&&(0,G.jsx)(xt,{className:`h-3 w-3 fill-current`}),e.label,` `,(0,G.jsxs)(`span`,{className:`text-muted-foreground/50 font-normal normal-case ml-1`,children:[`(`,e.rows.length,`)`]})]}),e.rows.map(e=>(0,G.jsxs)(`div`,{className:Y(`group relative rounded-md border text-sm transition-colors`,e.isCurrent?`bg-primary/5 border-primary/40`:`bg-card border-border/60 hover:bg-muted/40 hover:border-primary/40`),children:[(0,G.jsx)(`button`,{type:`button`,disabled:e.isCurrent||p===e.id||_!==null,onClick:()=>b(e.id),onDoubleClick:t=>{t.stopPropagation(),m(e.id),g(d[e.id]??e.title??``)},className:`block w-full rounded-md px-3 py-2 pr-16 text-left disabled:cursor-default focus:outline-none focus-visible:ring-2 focus-visible:ring-ring`,children:(0,G.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[p===e.id?(0,G.jsx)(`input`,{value:h,onChange:e=>g(e.target.value),onClick:e=>e.stopPropagation(),onBlur:()=>{f(e.id,h),m(null)},onKeyDown:t=>{t.key===`Enter`?(t.preventDefault(),f(e.id,h),m(null)):t.key===`Escape`&&(t.preventDefault(),m(null))},placeholder:e.title||`Nickname`,className:`w-full text-sm bg-background border border-input rounded px-1.5 py-0.5 focus:outline-none focus:ring-1 focus:ring-ring`}):(0,G.jsx)(`div`,{className:`font-medium truncate text-foreground`,title:d[e.id]?`${d[e.id]} β€” original: ${e.title}`:`${e.title}\n\nDouble-click to rename`,children:d[e.id]||e.title||`(empty)`}),(0,G.jsxs)(`div`,{className:`text-[10px] text-muted-foreground font-mono truncate mt-0.5`,children:[e.provider,`/`,e.model]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-[10px] text-muted-foreground/80 mt-0.5`,children:[_===e.id?(0,G.jsxs)(`span`,{className:`flex items-center gap-1 text-primary font-medium`,children:[(0,G.jsx)(I,{className:`h-3 w-3 animate-spin`}),`resuming…`]}):(0,G.jsx)(`span`,{children:dc(e.startedAt)}),e.tokenTotal>0&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`span`,{className:`opacity-50`,children:`Β·`}),(0,G.jsxs)(`span`,{className:`tabular-nums`,children:[e.tokenTotal.toLocaleString(),` tok`]})]}),e.isCurrent&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`span`,{className:`opacity-50`,children:`Β·`}),(0,G.jsx)(`span`,{className:`text-primary font-medium`,children:`active`})]})]})]})}),(0,G.jsxs)(`div`,{className:`absolute right-2 top-2 flex items-center gap-1`,children:[(0,G.jsx)(`button`,{type:`button`,onClick:()=>u(e.id),className:Y(`transition-opacity hover:text-amber-500`,l.includes(e.id)?`opacity-100 text-amber-500`:`opacity-0 group-hover:opacity-100 text-muted-foreground`),title:l.includes(e.id)?`Unfavorite`:`Mark as favorite`,children:(0,G.jsx)(xt,{className:Y(`h-3.5 w-3.5`,l.includes(e.id)&&`fill-current`)})}),!e.isCurrent&&(0,G.jsx)(`button`,{type:`button`,onClick:async()=>{await qo({title:`Delete session?`,message:`"${d[e.id]||e.title||`(empty)`}" will be removed from disk. This cannot be undone.`,confirmLabel:`Delete`,danger:!0})&&c(e.id)},className:`opacity-0 group-hover:opacity-100 transition-opacity text-muted-foreground hover:text-destructive`,title:`Delete session`,children:(0,G.jsx)(yn,{className:`h-3.5 w-3.5`})})]})]},e.id))]},e.label))})})]})}function mc(){let e=H(e=>e.wsConnected),{entries:t,loading:n,error:r}=ir(),{listSessions:i,resumeSession:a,deleteSession:o}=Z(),s=W(e=>e.setCurrentView),c=U(e=>e.session?.id),[l,u]=(0,z.useState)(``);return(0,z.useEffect)(()=>{e&&i(50)},[e,c,i]),(0,G.jsxs)(`div`,{className:`flex-1 flex flex-col overflow-hidden`,children:[(0,G.jsx)(pc,{historyQuery:l,setHistoryQuery:u,historyEntries:t,historyLoading:n,historyError:r,wsConnected:e,listSessions:i,resumeSession:a,deleteSession:o}),(0,G.jsx)(`div`,{className:`border-t px-3 py-2 shrink-0`,children:(0,G.jsxs)(`button`,{type:`button`,onClick:()=>s(`sessions`),className:`w-full flex items-center justify-center gap-1.5 h-7 rounded-md border border-border text-[11px] text-muted-foreground hover:text-foreground hover:bg-accent transition-colors`,children:[(0,G.jsx)(Ze,{className:`h-3 w-3`}),`Open sessions dashboard`]})})]})}function hc(e){return e<=0?`$0.000`:e>=.01?`$${e.toFixed(3)}`:`$${e.toFixed(4)}`}function gc(e){if(e<=0)return`--`;let t=Math.floor(e/1e3);if(t<60)return`${t}s`;let n=Math.floor(t/60);return n<60?`${n}m ${t%60}s`:`${Math.floor(n/60)}h ${n%60}m`}function _c({icon:e,label:t,onClick:n,disabled:r,tone:i,title:a}){return(0,G.jsxs)(`button`,{type:`button`,onClick:n,disabled:r,title:a??t,className:Y(`flex items-center justify-center gap-1.5 h-8 rounded-md border text-[11px] font-medium transition-colors`,`disabled:opacity-40 disabled:cursor-not-allowed`,i===`primary`?`border-primary/40 bg-primary/10 text-primary hover:bg-primary/20`:i===`danger`?`border-destructive/40 bg-destructive/10 text-destructive hover:bg-destructive/20`:`border-border bg-card hover:bg-accent text-foreground/80`),children:[e,t]})}function vc({label:e,value:t,sub:n}){return(0,G.jsxs)(`div`,{className:`flex flex-col p-2 rounded-lg bg-muted/40 border border-border/40 min-w-0`,children:[(0,G.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:e}),(0,G.jsx)(`span`,{className:`text-sm font-semibold tabular-nums truncate`,children:t}),n&&(0,G.jsx)(`span`,{className:`text-[9px] text-muted-foreground/70 truncate`,children:n})]})}function yc({icon:e,label:t,right:n}){return(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`span`,{className:`flex items-center gap-1.5 text-[10px] uppercase tracking-wider text-muted-foreground font-semibold`,children:[e,t]}),n]})}function bc({label:e,value:t,onChange:n,title:r}){return(0,G.jsxs)(`div`,{className:`flex items-center justify-between gap-2 py-1`,title:r,children:[(0,G.jsx)(`span`,{className:`text-xs text-foreground/80`,children:e}),(0,G.jsx)(`button`,{type:`button`,role:`switch`,"aria-checked":t,onClick:n,className:Y(`shrink-0 relative inline-flex h-4 w-7 rounded-full border transition-colors`,t?`bg-primary border-primary`:`bg-muted border-input hover:bg-muted/80`),children:(0,G.jsx)(`span`,{className:Y(`absolute top-0.5 left-0.5 h-2.5 w-2.5 rounded-full bg-background shadow transition-transform`,t&&`translate-x-3`)})})]})}function xc(){let{client:e,updatePrefs:t,switchAutonomy:n}=Z(),r=H(e=>e.wsConnected),i=H(e=>e.wsUrl),a=H(e=>e.provider),o=H(e=>e.model),s=H(e=>e.soundOnComplete),c=U(e=>e.session),l=U(e=>e.totalTokens),u=U(e=>e.cost),d=U(e=>e.iteration),f=U(e=>e.todos),p=U(e=>e.lastInputTokens),m=U(e=>e.maxContext),h=V(e=>e.messages),g=V(e=>e.isLoading),_=K(e=>e.agents),v=W(e=>e.pinnedIds),y=W(e=>e.unpinAll),b=W(e=>e.setModelSwitcherOpen),S=Tr(),C=(0,z.useCallback)((e,n)=>{S.set({[e]:n}),t({[e]:n})},[S,t]),[w,T]=(0,z.useState)(!1),D=c?.startedAt??null,[O,A]=(0,z.useState)(()=>Date.now());(0,z.useEffect)(()=>{if(!D)return;let e=setInterval(()=>A(Date.now()),1e3);return()=>clearInterval(e)},[D]);let j=(0,z.useMemo)(()=>Array.from(_.values()).filter(e=>e.status===`running`).length,[_]),M=m>0&&p>0?Math.round(p/m*100):0,ee=v.map(e=>h.find(t=>t.id===e)).filter(e=>!!e&&e.content.length>0),te=e=>B(i)?.send?.(e);return(0,G.jsxs)(`div`,{className:`flex-1 overflow-y-auto`,children:[(0,G.jsxs)(`div`,{className:`px-3 py-2.5 border-b grid grid-cols-2 gap-1.5`,children:[g?(0,G.jsx)(_c,{icon:(0,G.jsx)(Ye,{className:`h-3 w-3`}),label:`Abort`,tone:`danger`,onClick:()=>te({type:`abort`,payload:{}}),disabled:!r}):(0,G.jsx)(_c,{icon:(0,G.jsx)(ue,{className:`h-3 w-3`}),label:`New session`,tone:`primary`,onClick:()=>{e?.newSession?.(),W.getState().setCurrentView(`chat`)},disabled:!r,title:`Start a new session (Ctrl+N)`}),(0,G.jsx)(_c,{icon:(0,G.jsx)(ie,{className:`h-3 w-3`}),label:`Export`,onClick:()=>ua(),title:`Export chat as markdown (Ctrl+E)`}),(0,G.jsx)(_c,{icon:(0,G.jsx)(kn,{className:`h-3 w-3`}),label:`Compact`,onClick:()=>te({type:`context.compact`,payload:{aggressive:!1}}),disabled:!r,title:`Compact the context window`}),(0,G.jsx)(_c,{icon:(0,G.jsx)(k,{className:`h-3 w-3`}),label:`Clear`,onClick:()=>te({type:`context.clear`}),disabled:!r,title:`Clear context (Ctrl+L)`})]}),(0,G.jsxs)(`button`,{type:`button`,onClick:()=>b(!0),className:`w-full px-4 py-2.5 border-b text-left hover:bg-muted/40 transition-colors`,title:`Change model (Ctrl+M)`,children:[(0,G.jsx)(`div`,{className:`text-[10px] uppercase tracking-wider text-muted-foreground mb-0.5`,children:`Model`}),(0,G.jsxs)(`div`,{className:`font-mono text-xs truncate`,children:[(0,G.jsx)(`span`,{className:`text-muted-foreground`,children:a||`β€”`}),(0,G.jsx)(`span`,{className:`text-muted-foreground/40 mx-1`,children:`/`}),(0,G.jsx)(`span`,{className:`font-medium`,children:o||`β€”`})]})]}),m>0&&(0,G.jsxs)(`div`,{className:`px-4 py-2.5 border-b space-y-1.5`,children:[(0,G.jsx)(`button`,{type:`button`,onClick:()=>T(!0),className:`w-full block text-left`,title:`Click for a context breakdown`,children:(0,G.jsx)(yc,{icon:null,label:`Context`,right:(0,G.jsxs)(`span`,{className:`text-[10px] text-muted-foreground tabular-nums font-mono`,children:[$(p),`/`,$(m),` Β· `,M,`%`]})})}),(0,G.jsx)(`button`,{type:`button`,onClick:()=>T(!0),className:`w-full block`,title:`Click for a context breakdown`,children:(0,G.jsx)(za,{pct:M,tokens:p,maxTokens:m,showTokens:!0})})]}),(0,G.jsxs)(`div`,{className:`px-3 py-2.5 border-b space-y-1.5`,children:[(0,G.jsx)(yc,{icon:(0,G.jsx)(E,{className:`h-3 w-3`}),label:`Session`}),(0,G.jsxs)(`div`,{className:`grid grid-cols-2 gap-1.5`,children:[(0,G.jsx)(vc,{label:`Messages`,value:h.length}),(0,G.jsx)(vc,{label:`Elapsed`,value:D?gc(O-D):`--`}),(0,G.jsx)(vc,{label:`Tokens`,value:$(l.input+l.output),sub:`${$(l.input)} in / ${$(l.output)} out`}),(0,G.jsx)(vc,{label:`Cost`,value:hc(u)}),d&&(0,G.jsx)(vc,{label:`Iteration`,value:d.index,sub:d.max?`of ${d.max}`:void 0}),_.size>0&&(0,G.jsx)(vc,{label:`Agents`,value:_.size,sub:j>0?`${j} running`:void 0})]})]}),f.length>0&&(()=>{let e=f.filter(e=>e.status===`completed`).length,t=f.filter(e=>e.status===`in_progress`).length,n=Math.round(e/f.length*100),r=e===f.length;return(0,G.jsxs)(`div`,{className:`px-3 py-2.5 border-b space-y-1.5`,children:[(0,G.jsx)(yc,{icon:(0,G.jsx)(on,{className:`h-3 w-3`}),label:`Plan`,right:(0,G.jsxs)(`span`,{className:`tabular-nums text-[10px] text-muted-foreground`,children:[e,`/`,f.length]})}),(0,G.jsx)(`div`,{className:Y(`relative h-1.5 w-full overflow-hidden rounded-full bg-muted`,t>0&&`bar-sweep`),title:`${n}% complete`,children:(0,G.jsx)(`div`,{className:Y(`h-full rounded-full transition-all duration-500`,r?`bg-[hsl(var(--success))]`:`bg-primary`),style:{width:`${Math.max(n,t>0?4:0)}%`}})}),(0,G.jsx)(`ul`,{className:`space-y-0.5 max-h-56 overflow-y-auto pr-1 -mx-1`,children:f.map(e=>{let t=e.status===`completed`?We:e.status===`in_progress`?Re:nn,n=e.status===`in_progress`,r=e.status===`completed`?`text-[hsl(var(--success))] line-through opacity-60`:n?`text-foreground`:`text-muted-foreground`;return(0,G.jsxs)(`li`,{className:Y(`flex items-start gap-2 text-xs leading-snug rounded-md px-1.5 py-1 transition-colors`,n&&`bg-primary/10 ring-1 ring-inset ring-primary/20`,r),children:[(0,G.jsx)(t,{className:Y(`h-3.5 w-3.5 mt-0.5 shrink-0`,n&&`text-primary animate-pulse`)}),(0,G.jsx)(`span`,{className:`break-words`,children:n&&e.activeForm?e.activeForm:e.content})]},e.id)})})]})})(),ee.length>0&&(0,G.jsxs)(`div`,{className:`px-3 py-2.5 border-b space-y-1.5`,children:[(0,G.jsx)(yc,{icon:(0,G.jsx)(x,{className:`h-3 w-3 text-amber-500`}),label:`Pinned`,right:(0,G.jsx)(`button`,{type:`button`,onClick:y,className:`text-[10px] text-muted-foreground hover:text-destructive`,children:`Clear`})}),(0,G.jsx)(`ul`,{className:`space-y-1 max-h-48 overflow-y-auto pr-1`,children:ee.map(e=>{let t=e.content.replace(/\s+/g,` `).slice(0,80);return(0,G.jsx)(`li`,{children:(0,G.jsxs)(`button`,{type:`button`,onClick:()=>{let t=document.querySelector(`[data-message-id="${e.id}"]`);t&&(t.scrollIntoView({behavior:`smooth`,block:`center`}),t.classList.add(`ring-2`,`ring-amber-500/60`),setTimeout(()=>{t.classList.remove(`ring-2`,`ring-amber-500/60`)},1600))},className:`w-full text-left text-xs px-2 py-1.5 rounded bg-muted/40 hover:bg-muted/70 border border-amber-500/20 leading-snug`,title:e.content.slice(0,400),children:[t,e.content.length>80?`…`:``]})},e.id)})})]}),(0,G.jsxs)(`div`,{className:`px-3 py-2.5 border-b space-y-1`,children:[(0,G.jsx)(yc,{icon:(0,G.jsx)(Mn,{className:`h-3 w-3`}),label:`Quick settings`}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between gap-2 py-1`,children:[(0,G.jsx)(`span`,{className:`text-xs text-foreground/80`,children:`Autonomy`}),(0,G.jsxs)(`select`,{value:S.autonomy,onChange:e=>{let t=e.target.value;S.set({autonomy:t}),n(t)},className:`shrink-0 h-6 max-w-[150px] rounded-md border bg-background px-1.5 text-[11px]`,children:[(0,G.jsx)(`option`,{value:`off`,children:`Off`}),(0,G.jsx)(`option`,{value:`suggest`,children:`Suggest`}),(0,G.jsx)(`option`,{value:`auto`,children:`Auto`}),(0,G.jsx)(`option`,{value:`eternal`,children:`Eternal`}),(0,G.jsx)(`option`,{value:`eternal-parallel`,children:`Eternal Parallel`})]})]}),(0,G.jsx)(bc,{label:`YOLO mode`,title:`Bypass tool confirmation prompts`,value:S.yolo,onChange:()=>C(`yolo`,!S.yolo)}),(0,G.jsx)(bc,{label:`Refine prompts`,title:`Rewrite prompts before sending`,value:S.enhanceEnabled,onChange:()=>C(`enhanceEnabled`,!S.enhanceEnabled)}),(0,G.jsx)(bc,{label:`Sound on completion`,title:`Play a soft chime when a run finishes`,value:s,onChange:()=>{let e=!H.getState().soundOnComplete;H.getState().setSoundOnComplete(e),e&&Rr()}})]}),(0,G.jsxs)(`div`,{className:`px-4 py-2.5`,children:[(0,G.jsxs)(`div`,{className:Y(`flex items-center gap-2 text-[11px]`,r?`text-[hsl(var(--success))]`:`text-[hsl(var(--warning))]`),children:[r?(0,G.jsx)(pt,{className:`h-3.5 w-3.5`}):(0,G.jsx)(hn,{className:`h-3.5 w-3.5`}),(0,G.jsx)(`span`,{className:`font-medium`,children:r?`Connected`:`Disconnected`}),(0,G.jsx)(`span`,{className:`text-muted-foreground font-mono truncate ml-auto`,title:i,children:i})]}),c&&(0,G.jsxs)(`div`,{className:`text-[10px] text-muted-foreground font-mono mt-1 truncate`,title:c.id,children:[`session `,c.id.slice(0,8)]})]}),(0,G.jsx)(Ba,{open:w,onClose:()=>T(!1)})]})}var Sc={chat:`Session`,agents:`Agents`,history:`History`,files:`Files`,projects:`Projects`,mailbox:`Mailbox`};function Cc(){let e=W(e=>e.activeActivity),t=W(e=>e.setSidebarOpen),n=W(e=>e.sidebarWidth),r=W(e=>e.setSidebarWidth),i=H(e=>e.wsConnected),{client:a}=Z();return(0,z.useEffect)(()=>{if(e!==`files`||!i)return;q.getState().setTreeLoading(!0);let t=U.getState().cwd;a?.send({type:`files.tree`,payload:t?{path:t}:{}})},[e,i,a]),(0,G.jsxs)(`aside`,{style:{width:`${n}px`},className:`relative border-r bg-card flex flex-col shrink-0 overflow-hidden animate-slide-in`,children:[(0,G.jsx)(`div`,{onMouseDown:e=>{e.preventDefault();let t=e.clientX,i=n,a=e=>r(i+(e.clientX-t)),o=()=>{window.removeEventListener(`mousemove`,a),window.removeEventListener(`mouseup`,o),document.body.style.cursor=``,document.body.style.userSelect=``};window.addEventListener(`mousemove`,a),window.addEventListener(`mouseup`,o),document.body.style.cursor=`col-resize`,document.body.style.userSelect=`none`},onDoubleClick:()=>r(304),className:`group/handle absolute top-0 right-0 h-full w-2 cursor-col-resize z-10 flex items-center justify-end`,title:`Drag to resize Β· double-click to reset`,children:(0,G.jsx)(`div`,{className:`h-full w-px bg-border group-hover/handle:bg-primary/60 group-hover/handle:w-0.5 transition-all`})}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between px-3 py-2.5 border-b shrink-0`,children:[(0,G.jsx)(`span`,{className:`text-xs font-semibold tracking-tight text-muted-foreground uppercase`,children:Sc[e]}),(0,G.jsx)(Q,{variant:`ghost`,size:`icon`,className:`h-6 w-6`,onClick:()=>t(!1),title:`Collapse panel (Ctrl+\\)`,children:(0,G.jsx)(Ne,{className:`h-3.5 w-3.5`})})]}),(0,G.jsxs)(`div`,{className:`flex-1 flex flex-col overflow-hidden`,children:[e===`chat`&&(0,G.jsx)(xc,{}),e===`agents`&&(0,G.jsx)(uc,{}),e===`history`&&(0,G.jsx)(mc,{}),e===`files`&&(0,G.jsx)(`div`,{className:`flex-1 overflow-y-auto`,children:(0,G.jsx)(Gs,{})}),e===`projects`&&(0,G.jsx)(`div`,{className:`flex-1 overflow-y-auto p-3`,children:(0,G.jsx)(Ys,{})}),e===`mailbox`&&(0,G.jsx)(`div`,{className:`flex-1 overflow-y-auto p-3`,children:(0,G.jsx)(Js,{})})]})]})}function wc({sessionId:e,className:t}){let[n,r]=(0,z.useState)([]),[i,a]=(0,z.useState)(!1),[o,s]=(0,z.useState)(null),[c,l]=(0,z.useState)(null),[u,d]=(0,z.useState)(0),[f,p]=(0,z.useState)(!1),m=B(H(e=>e.wsUrl));(0,z.useEffect)(()=>{let t=[];return t.push(m.on(`collab.state`,t=>{let n=t.payload;n.sessionId===e&&r(n.participants??[])})),t.push(m.on(`collab.participant.joined`,t=>{let n=t.payload;n.sessionId===e&&r(e=>e.some(e=>e.participantId===n.participantId)?e:[...e,{participantId:n.participantId,role:n.role,joinedAt:n.joinedAt}])})),t.push(m.on(`collab.participant.left`,t=>{let n=t.payload;if(n.sessionId!==e)return;let i=n.participantId;r(e=>e.filter(e=>e.participantId!==i))})),t.push(m.on(`error`,e=>{let t=e.payload;t.phase===`collab`&&(l(t.message),a(!1))})),t.push(m.on(`collab.annotation.added`,t=>{let n=t.payload;n.sessionId===e&&(n.annotation?.resolved||d(e=>e+1))})),t.push(m.on(`collab.annotation.resolved`,t=>{t.payload.sessionId===e&&d(e=>Math.max(0,e-1))})),t.push(m.on(`collab.pause.granted`,t=>{t.payload.sessionId===e&&p(!0)})),t.push(m.on(`collab.pause.released`,t=>{t.payload.sessionId===e&&p(!1)})),()=>{for(let e of t)e()}},[m,e]);let h=(t=`observer`)=>{l(null),m.send({type:`collab.join`,payload:{sessionId:e,role:t}}),a(!0),s(t)};return n.length===0&&!c?(0,G.jsxs)(`div`,{className:Y(`flex items-center gap-2 px-3 py-2 rounded-md border border-dashed border-border bg-card/40`,t),children:[(0,G.jsx)(kt,{className:`w-4 h-4 text-muted-foreground`}),(0,G.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`No live observers`}),(0,G.jsxs)(`div`,{className:`ml-auto flex items-center gap-1`,children:[(0,G.jsxs)(`button`,{type:`button`,onClick:()=>h(`observer`),className:`inline-flex items-center gap-1 text-xs px-2 py-1 rounded bg-primary text-primary-foreground hover:bg-primary/90 transition-colors`,title:`Join as a read-only observer (Phase 1)`,children:[(0,G.jsx)(pn,{className:`w-3 h-3`}),`observer`]}),(0,G.jsxs)(`button`,{type:`button`,onClick:()=>h(`annotator`),className:`inline-flex items-center gap-1 text-xs px-2 py-1 rounded border border-amber-500/40 bg-amber-500/10 text-amber-700 dark:text-amber-300 hover:bg-amber-500/20 transition-colors`,title:`Join as an annotator β€” leave inline notes on tool calls (Phase 2)`,children:[(0,G.jsx)(ze,{className:`w-3 h-3`}),`annotator`]}),(0,G.jsxs)(`button`,{type:`button`,onClick:()=>h(`controller`),className:`inline-flex items-center gap-1 text-xs px-2 py-1 rounded border border-rose-500/40 bg-rose-500/10 text-rose-700 dark:text-rose-300 hover:bg-rose-500/20 transition-colors`,title:`Join as a controller β€” can pause the agent loop (Phase 3)`,children:[(0,G.jsx)(Fn,{className:`w-3 h-3`}),`controller`]})]})]}):c?(0,G.jsxs)(`div`,{className:Y(`flex items-center gap-2 px-3 py-2 rounded-md border border-destructive/50 bg-destructive/10`,t),role:`alert`,children:[(0,G.jsxs)(`span`,{className:`text-xs text-destructive`,children:[`Collab: `,c]}),(0,G.jsx)(`button`,{type:`button`,onClick:()=>{l(null),a(!1)},className:`ml-auto text-xs underline text-destructive`,children:`dismiss`})]}):(0,G.jsxs)(`div`,{className:Y(`flex items-center gap-2 px-3 py-2 rounded-md border border-emerald-500/40 bg-emerald-500/5`,t),children:[(0,G.jsxs)(`span`,{className:`relative flex h-2 w-2`,"aria-label":`Live`,children:[(0,G.jsx)(`span`,{className:`absolute inline-flex h-full w-full rounded-full bg-emerald-400 opacity-75 animate-ping`}),(0,G.jsx)(`span`,{className:`relative inline-flex rounded-full h-2 w-2 bg-emerald-500`})]}),(0,G.jsx)(kt,{className:`w-4 h-4 text-emerald-700 dark:text-emerald-400`}),(0,G.jsxs)(`span`,{className:`text-xs font-medium text-emerald-700 dark:text-emerald-300`,children:[n.length,` `,n.length===1?`observer`:`observers`]}),u>0&&(0,G.jsxs)(`span`,{title:`${u} open annotation(s) β€” annotators reviewing this session`,className:`ml-2 inline-flex items-center gap-1 text-[10px] px-1.5 py-0.5 rounded bg-amber-500/15 text-amber-700 dark:text-amber-300 border border-amber-500/30`,children:[(0,G.jsx)(ze,{className:`w-3 h-3`}),u,` note`,u===1?``:`s`]}),f&&(0,G.jsxs)(`span`,{title:`Agent loop is paused β€” a controller is reviewing`,className:`ml-2 inline-flex items-center gap-1 text-[10px] px-1.5 py-0.5 rounded bg-rose-500/15 text-rose-700 dark:text-rose-300 border border-rose-500/40`,children:[(0,G.jsx)(Fn,{className:`w-3 h-3`}),`paused`]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-1 ml-2`,children:[n.slice(0,3).map(e=>(0,G.jsxs)(`span`,{title:`Joined ${new Date(e.joinedAt).toLocaleTimeString()}`,className:`inline-flex items-center gap-1 text-[10px] px-1.5 py-0.5 rounded bg-emerald-500/10 text-emerald-700 dark:text-emerald-300`,children:[(0,G.jsx)(P,{className:`w-3 h-3`}),e.role]},e.participantId)),n.length>3&&(0,G.jsxs)(`span`,{className:`text-[10px] text-muted-foreground`,children:[`+`,n.length-3]})]}),i&&o===`controller`&&(f?(0,G.jsxs)(`button`,{type:`button`,onClick:()=>{m.send({type:`collab.resume`,payload:{sessionId:e}})},className:`ml-auto inline-flex items-center gap-1 text-xs px-2 py-1 rounded border border-rose-500/40 bg-rose-500/10 text-rose-700 dark:text-rose-300 hover:bg-rose-500/20 transition-colors`,title:`Resume the agent loop`,children:[(0,G.jsx)(ge,{className:`w-3 h-3`}),`Resume`]}):(0,G.jsxs)(`button`,{type:`button`,onClick:()=>{m.send({type:`collab.request_pause`,payload:{sessionId:e}})},className:`ml-auto inline-flex items-center gap-1 text-xs px-2 py-1 rounded border border-amber-500/40 bg-amber-500/10 text-amber-700 dark:text-amber-300 hover:bg-amber-500/20 transition-colors`,title:`Pause the agent before the next tool call`,children:[(0,G.jsx)(Fn,{className:`w-3 h-3`}),`Pause agent`]})),i&&o!==`controller`&&(0,G.jsxs)(`button`,{type:`button`,onClick:()=>{m.send({type:`collab.leave`,payload:{sessionId:e}}),a(!1),r([])},className:`ml-auto inline-flex items-center gap-1 text-xs px-2 py-1 rounded border border-border hover:bg-muted transition-colors`,title:`Leave the observer session`,children:[(0,G.jsx)(dt,{className:`w-3 h-3`}),`Leave`]})]})}var Tc={up:(0,G.jsx)(ot,{className:`h-3.5 w-3.5 text-emerald-500`}),down:(0,G.jsx)(zt,{className:`h-3.5 w-3.5 text-red-500`}),stable:(0,G.jsx)(rn,{className:`h-3.5 w-3.5 text-amber-500`})},Ec={active:{color:`text-emerald-600 dark:text-emerald-400`,bg:`bg-emerald-100 dark:bg-emerald-900/40`,label:`Active`},paused:{color:`text-amber-600 dark:text-amber-400`,bg:`bg-amber-100 dark:bg-amber-900/40`,label:`Paused`},completed:{color:`text-blue-600 dark:text-blue-400`,bg:`bg-blue-100 dark:bg-blue-900/40`,label:`Done`},failed:{color:`text-red-600 dark:text-red-400`,bg:`bg-red-100 dark:bg-red-900/40`,label:`Failed`},abandoned:{color:`text-stone-600 dark:text-stone-400`,bg:`bg-stone-100 dark:bg-stone-900/40`,label:`Abandoned`}};function Dc({goal:e,className:t}){let[n,r]=(0,z.useState)(!1);if((0,z.useEffect)(()=>{let e=B();e?.send?.({type:`goal.get`});let t=setInterval(()=>{e?.send?.({type:`goal.get`})},1e4);return()=>clearInterval(t)},[]),(0,z.useEffect)(()=>{(!e||e.goalState===`completed`||e.goalState===`failed`||e.goalState===`abandoned`)&&r(!0)},[e]),!e||e.goalState===`completed`||e.goalState===`failed`||e.goalState===`abandoned`)return null;let i=Ec[e.goalState],a=e.deliverables?.filter(e=>e.status===`done`).length??0,o=e.deliverables?.length??0,s=e.journal?.slice(-5).reverse()??[],c=e.progressTrend?Tc[e.progressTrend]:null;return(0,G.jsxs)(`div`,{className:Y(`rounded-lg border border-border bg-card/60 backdrop-blur-sm`,t),children:[(0,G.jsxs)(`button`,{type:`button`,onClick:()=>r(e=>!e),className:`flex w-full items-center gap-2 px-3 py-2.5 text-left hover:bg-accent/40 rounded-t-lg transition-colors`,children:[(0,G.jsx)(en,{className:`h-4 w-4 text-rose-500`}),(0,G.jsx)(`span`,{className:`text-xs font-semibold text-foreground flex-1 min-w-0 truncate`,children:`Goal`}),(0,G.jsx)(`span`,{className:Y(`inline-flex items-center px-1.5 py-0.5 rounded-full text-[10px] font-medium shrink-0`,i.bg,i.color),children:i.label}),n?(0,G.jsx)(mn,{className:`h-3.5 w-3.5 text-muted-foreground shrink-0`}):(0,G.jsx)(sn,{className:`h-3.5 w-3.5 text-muted-foreground shrink-0`})]}),!n&&(0,G.jsxs)(`div`,{className:`px-3 pb-3 space-y-3 border-t pt-2`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-xs text-foreground leading-relaxed whitespace-pre-wrap break-words`,children:e.goal}),e.refinedGoal&&e.refinedGoal!==e.goal&&(0,G.jsxs)(`div`,{className:`mt-1.5 p-2 rounded bg-accent/40 border border-border/50`,children:[(0,G.jsx)(`p`,{className:`text-[10px] text-muted-foreground mb-0.5 uppercase tracking-wider font-medium`,children:`Refined`}),(0,G.jsx)(`p`,{className:`text-xs leading-relaxed whitespace-pre-wrap break-words`,children:e.refinedGoal})]})]}),(0,G.jsxs)(`div`,{className:`space-y-1`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between text-[10px]`,children:[(0,G.jsx)(`span`,{className:`text-muted-foreground uppercase tracking-wider font-medium`,children:`Progress`}),(0,G.jsxs)(`span`,{className:`flex items-center gap-1 tabular-nums`,children:[c,(0,G.jsxs)(`span`,{className:`font-medium text-foreground`,children:[e.progress,`%`]})]})]}),(0,G.jsx)(`div`,{className:`h-1.5 bg-muted rounded-full overflow-hidden`,children:(0,G.jsx)(`div`,{className:Y(`h-full transition-all duration-700 rounded-full`,e.progress>=80?`bg-emerald-500`:e.progress>=50?`bg-amber-500`:`bg-primary`),style:{width:`${e.progress>0?Math.max(2,e.progress):0}%`}})}),e.progressNote&&(0,G.jsx)(`p`,{className:`text-[10px] text-muted-foreground italic`,children:e.progressNote})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[10px] text-muted-foreground`,children:[(0,G.jsx)(N,{className:`h-3 w-3`}),(0,G.jsx)(`span`,{className:`tabular-nums font-medium`,children:e.iterations}),(0,G.jsx)(`span`,{children:`iterations`}),e.lastStatus&&(0,G.jsx)(`span`,{className:`text-border`,children:`Β·`}),e.lastStatus&&(0,G.jsx)(`span`,{className:`truncate`,children:e.lastStatus})]}),o>0&&(0,G.jsxs)(`div`,{className:`space-y-1`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between text-[10px] text-muted-foreground uppercase tracking-wider font-medium`,children:[(0,G.jsx)(`span`,{children:`Deliverables`}),(0,G.jsxs)(`span`,{className:`tabular-nums`,children:[a,`/`,o]})]}),(0,G.jsx)(`ul`,{className:`space-y-0.5`,children:e.deliverables?.map(e=>(0,G.jsxs)(`li`,{className:`flex items-start gap-1.5 text-[11px]`,children:[e.status===`done`?(0,G.jsx)(We,{className:`h-3 w-3 text-emerald-500 mt-0.5 shrink-0`}):(0,G.jsx)(nn,{className:`h-3 w-3 text-muted-foreground/50 mt-0.5 shrink-0`}),(0,G.jsx)(`span`,{className:Y(`leading-snug`,e.status===`done`?`text-muted-foreground line-through`:`text-foreground`),children:e.text})]},e.id))})]}),s.length>0&&(0,G.jsxs)(`div`,{className:`space-y-1`,children:[(0,G.jsx)(`p`,{className:`text-[10px] text-muted-foreground uppercase tracking-wider font-medium`,children:`Recent Activity`}),(0,G.jsx)(`div`,{className:`space-y-1`,children:s.map((e,t)=>(0,G.jsxs)(`div`,{className:`flex items-start gap-1.5 text-[10px] text-muted-foreground`,children:[(0,G.jsxs)(`span`,{className:`font-mono tabular-nums shrink-0 text-foreground/60`,children:[`#`,e.iteration]}),(0,G.jsx)(`span`,{className:`truncate`,children:e.task||e.status||e.progressNote||`…`})]},`${e.iteration}-${t}`))})]})]})]})}var Oc={in_progress:0,pending:1,completed:2};function kc(){let[e,t]=(0,z.useState)([]),[n,r]=(0,z.useState)(new Set),i=B(),a=(0,z.useRef)(null);(0,z.useEffect)(()=>(i.send({type:`todos.get`}),a.current=i.on(`todos.updated`,e=>{let n=e?.payload;n?.todos&&t(n.todos)}),()=>{a.current?.()}),[i]);let o=(0,z.useCallback)(e=>{i.removeTodo(e)},[i]),s=(0,z.useCallback)(e=>{if(e.status===`in_progress`)return;let t=e.status===`completed`?`pending`:`completed`;i.updateTodoStatus(e.id,t)},[i]),c=[...e].sort((e,t)=>(Oc[e.status]??9)-(Oc[t.status]??9)),l=c.filter(e=>e.status===`in_progress`),u=c.filter(e=>e.status===`pending`),d=c.filter(e=>e.status===`completed`),f=d.length>0,p=n.has(`completed`),m=e=>{r(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},h=e=>{let t=e.status===`in_progress`&&e.activeForm?e.activeForm:e.content,n=e.status===`in_progress`,r=e.status===`completed`,i=!n;return(0,G.jsxs)(`div`,{onClick:()=>i&&s(e),className:Y(`px-3 py-1.5 flex items-start gap-2 text-[13px] group transition-colors`,i&&`cursor-pointer hover:bg-accent/40`,n?`bg-yellow-50/40 dark:bg-yellow-950/25`:r?`bg-emerald-50/20 dark:bg-emerald-950/10`:`bg-background`),role:i?`button`:void 0,"aria-label":i?`Toggle ${e.content}`:void 0,tabIndex:i?0:void 0,onKeyDown:t=>{i&&(t.key===`Enter`||t.key===` `)&&(t.preventDefault(),s(e))},children:[(0,G.jsx)(`span`,{className:`mt-0.5 shrink-0`,children:r?(0,G.jsx)(We,{className:`w-3.5 h-3.5 text-emerald-500`}):n?(0,G.jsx)(N,{className:`w-3.5 h-3.5 text-yellow-500 animate-spin`}):(0,G.jsx)(nn,{className:Y(`w-3.5 h-3.5 transition-colors`,`text-muted-foreground/40 group-hover:text-emerald-400`)})}),(0,G.jsx)(`span`,{className:Y(`leading-snug flex-1 min-w-0`,n?`text-yellow-800 dark:text-yellow-200 font-medium`:r?`text-muted-foreground line-through`:`text-foreground/80`),children:t}),(0,G.jsx)(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),o(e.id)},className:`shrink-0 p-0.5 rounded opacity-0 group-hover:opacity-50 hover:opacity-100 hover:bg-destructive/10 transition-all`,title:`Remove todo`,"aria-label":`Remove "${e.content}"`,children:(0,G.jsx)(yn,{className:`w-3 h-3 text-muted-foreground`})})]},e.id)};return e.length===0?null:(0,G.jsxs)(`div`,{className:`rounded-lg border border-border bg-card/50 backdrop-blur-sm overflow-hidden`,children:[(0,G.jsxs)(`div`,{className:`px-3 py-1.5 flex items-center gap-2 border-b border-border/50`,children:[(0,G.jsx)(`h2`,{className:`text-[11px] font-semibold text-foreground uppercase tracking-wider`,children:`Todos`}),(0,G.jsxs)(`span`,{className:`tabular text-[10px] text-muted-foreground ml-auto`,children:[d.length,`/`,e.length]})]}),l.length>0&&(0,G.jsx)(`div`,{className:`border-b border-border/30 last:border-b-0`,children:l.map(h)}),u.length>0&&(0,G.jsx)(`div`,{className:`border-b border-border/30 last:border-b-0`,children:u.map(h)}),f&&(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`button`,{type:`button`,onClick:()=>m(`completed`),className:`w-full px-3 py-1 flex items-center gap-1.5 text-[10px] text-muted-foreground hover:text-foreground transition-colors`,children:(0,G.jsxs)(`span`,{className:`tabular`,children:[p?`β–Ά`:`β–Ό`,` `,d.length,` completed`]})}),!p&&d.map(h)]})]})}var Ac={pending:{icon:(0,G.jsx)(nn,{className:`w-3.5 h-3.5`}),label:`Pending`,color:`text-muted-foreground/50`},in_progress:{icon:(0,G.jsx)(N,{className:`w-3.5 h-3.5 animate-spin`}),label:`In Progress`,color:`text-yellow-500`},blocked:{icon:(0,G.jsx)(Fn,{className:`w-3.5 h-3.5`}),label:`Blocked`,color:`text-orange-500`},failed:{icon:(0,G.jsx)(M,{className:`w-3.5 h-3.5`}),label:`Failed`,color:`text-red-500`},review:{icon:(0,G.jsx)(pe,{className:`w-3.5 h-3.5`}),label:`Review`,color:`text-blue-500`},completed:{icon:(0,G.jsx)(We,{className:`w-3.5 h-3.5`}),label:`Done`,color:`text-emerald-500`}},jc={critical:`text-red-600 dark:text-red-400`,high:`text-orange-600 dark:text-orange-400`,medium:`text-yellow-600 dark:text-yellow-400`,low:`text-muted-foreground`},Mc={feature:`⚑`,bugfix:`πŸ›`,refactor:`♻️`,docs:`πŸ“`,test:`πŸ§ͺ`,chore:`πŸ”§`};function Nc(){let[e,t]=(0,z.useState)([]),[n,r]=(0,z.useState)(new Set),i=B(),a=(0,z.useRef)(null);(0,z.useEffect)(()=>(i.getTasks(),a.current=i.on(`tasks.updated`,e=>{let n=e?.payload;n?.tasks&&t(n.tasks)}),()=>{a.current?.()}),[i]);let o=(0,z.useCallback)(e=>{r(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),s=(0,z.useCallback)((e,t)=>{i.updateTaskStatus(e,t)},[i]),c=[`in_progress`,`blocked`,`review`,`pending`,`failed`,`completed`],l=new Map;for(let t of e){let e=l.get(t.status)??[];e.push(t),l.set(t.status,e)}let u=l.get(`completed`)?.length??0;return e.length===0?null:(0,G.jsxs)(`div`,{className:`rounded-lg border border-border bg-card/50 backdrop-blur-sm overflow-hidden`,children:[(0,G.jsxs)(`div`,{className:`px-3 py-1.5 flex items-center gap-2 border-b border-border/50`,children:[(0,G.jsx)(`h2`,{className:`text-[11px] font-semibold text-foreground uppercase tracking-wider`,children:`Tasks`}),(0,G.jsxs)(`span`,{className:`tabular text-[10px] text-muted-foreground ml-auto`,children:[u,`/`,e.length]})]}),c.map(e=>{let t=l.get(e);if(!t||t.length===0)return null;let r=Ac[e],i=n.has(e);return(0,G.jsxs)(`div`,{className:`border-b border-border/30 last:border-b-0`,children:[(0,G.jsx)(`button`,{type:`button`,onClick:()=>o(e),className:`w-full px-3 py-1 flex items-center gap-1.5 text-[10px] text-muted-foreground hover:text-foreground transition-colors`,children:(0,G.jsxs)(`span`,{className:`tabular`,children:[i?`β–Ά`:`β–Ό`,` `,t.length,` `,r.label]})}),!i&&t.map(e=>(0,G.jsxs)(`div`,{className:Y(`px-3 py-1.5 flex items-start gap-2 text-[13px] group`,e.status===`in_progress`?`bg-yellow-50/40 dark:bg-yellow-950/25`:``),children:[(0,G.jsx)(`span`,{className:Y(`mt-0.5 shrink-0`,r.color),children:r.icon}),(0,G.jsxs)(`span`,{className:`leading-snug flex-1 min-w-0`,children:[(0,G.jsxs)(`span`,{className:Y(e.status===`completed`?`text-muted-foreground line-through`:`text-foreground/80`),children:[Mc[e.type],` `,e.title]}),e.priority!==`medium`&&(0,G.jsx)(`span`,{className:Y(`ml-1 text-[10px]`,jc[e.priority]),children:e.priority}),e.assignee&&(0,G.jsxs)(`span`,{className:`ml-1 text-[10px] text-muted-foreground`,children:[`@`,e.assignee]}),e.estimateHours&&(0,G.jsxs)(`span`,{className:`ml-1 text-[10px] text-muted-foreground`,children:[e.estimateHours,`h`]})]}),(0,G.jsxs)(`div`,{className:`flex gap-0.5 opacity-0 group-hover:opacity-100 transition-opacity shrink-0`,children:[e.status!==`in_progress`&&e.status!==`completed`&&(0,G.jsx)(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),s(e.id,`in_progress`)},className:`px-1.5 py-0.5 text-[9px] rounded bg-primary/15 text-primary hover:bg-primary/25 transition-colors`,title:`Start`,children:`Start`}),e.status===`in_progress`&&(0,G.jsx)(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),s(e.id,`completed`)},className:`px-1.5 py-0.5 text-[9px] rounded bg-[hsl(var(--success)/0.15)] text-[hsl(var(--success))] hover:bg-[hsl(var(--success)/0.25)] transition-colors`,title:`Complete`,children:`Done`}),e.status!==`completed`&&e.status!==`failed`&&(0,G.jsx)(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),s(e.id,`failed`)},className:`px-1.5 py-0.5 text-[9px] rounded bg-destructive/15 text-destructive hover:bg-destructive/25 transition-colors`,title:`Mark failed`,children:`Fail`})]})]},e.id))]},e)})]})}var Pc={open:{icon:(0,G.jsx)(nn,{className:`w-3.5 h-3.5`}),label:`Open`,color:`text-muted-foreground/50`},in_progress:{icon:(0,G.jsx)(N,{className:`w-3.5 h-3.5 animate-spin`}),label:`In Progress`,color:`text-yellow-500`},done:{icon:(0,G.jsx)(We,{className:`w-3.5 h-3.5`}),label:`Done`,color:`text-emerald-500`}};function Fc(){let[e,t]=(0,z.useState)([]),[n,r]=(0,z.useState)(new Set),i=B(),a=(0,z.useRef)(null);(0,z.useEffect)(()=>(i.getPlan(),a.current=i.on(`plan.updated`,e=>{let n=e?.payload;n?.plan?.items&&t(n.plan.items)}),()=>{a.current?.()}),[i]);let o=(0,z.useCallback)(e=>{r(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),s=(0,z.useCallback)((e,t)=>{i.updatePlanItem(e.id,t)},[i]),c=[`in_progress`,`open`,`done`],l=new Map;for(let t of e){let e=l.get(t.status)??[];e.push(t),l.set(t.status,e)}let u=l.get(`done`)?.length??0;return e.length===0?null:(0,G.jsxs)(`div`,{className:`rounded-lg border border-border bg-card/50 backdrop-blur-sm overflow-hidden`,children:[(0,G.jsxs)(`div`,{className:`px-3 py-1.5 flex items-center gap-2 border-b border-border/50`,children:[(0,G.jsx)(`h2`,{className:`text-[11px] font-semibold text-foreground uppercase tracking-wider`,children:`πŸ“‹ Plan`}),(0,G.jsxs)(`span`,{className:`tabular text-[10px] text-muted-foreground ml-auto`,children:[u,`/`,e.length]})]}),c.map(e=>{let t=l.get(e);if(!t||t.length===0)return null;let r=Pc[e],i=n.has(e);return(0,G.jsxs)(`div`,{className:`border-b border-border/30 last:border-b-0`,children:[(0,G.jsx)(`button`,{type:`button`,onClick:()=>o(e),className:`w-full px-3 py-1 flex items-center gap-1.5 text-[10px] text-muted-foreground hover:text-foreground transition-colors`,children:(0,G.jsxs)(`span`,{className:`tabular`,children:[i?`β–Ά`:`β–Ό`,` `,t.length,` `,r.label]})}),!i&&t.map(e=>(0,G.jsxs)(`div`,{className:Y(`px-3 py-1.5 flex items-start gap-2 text-[13px] group`,e.status===`in_progress`?`bg-yellow-50/40 dark:bg-yellow-950/25`:``),children:[(0,G.jsx)(`span`,{className:Y(`mt-0.5 shrink-0`,r.color),children:r.icon}),(0,G.jsx)(`span`,{className:Y(`leading-snug flex-1 min-w-0`,e.status===`done`?`text-muted-foreground line-through`:`text-foreground/80`),children:e.title}),(0,G.jsxs)(`div`,{className:`flex gap-0.5 opacity-0 group-hover:opacity-100 transition-opacity shrink-0`,children:[e.status===`open`&&(0,G.jsx)(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),s(e,`in_progress`)},className:`px-1.5 py-0.5 text-[9px] rounded bg-primary/15 text-primary hover:bg-primary/25 transition-colors`,title:`Start`,children:`Start`}),e.status!==`done`&&(0,G.jsx)(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),s(e,`done`)},className:`px-1.5 py-0.5 text-[9px] rounded bg-[hsl(var(--success)/0.15)] text-[hsl(var(--success))] hover:bg-[hsl(var(--success)/0.25)] transition-colors`,title:`Mark done`,children:`Done`}),e.status===`done`&&(0,G.jsx)(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),s(e,`open`)},className:`px-1.5 py-0.5 text-[9px] rounded bg-muted text-muted-foreground hover:bg-accent hover:text-foreground transition-colors`,title:`Reopen`,children:`Reopen`})]})]},e.id))]},e)})]})}var Ic=[{id:`todos`,label:`Todos`,icon:`βœ…`},{id:`tasks`,label:`Tasks`,icon:`πŸ“‹`},{id:`plan`,label:`Plan`,icon:`πŸ—ΊοΈ`}];function Lc(){let[e,t]=(0,z.useState)(`todos`);return(0,G.jsxs)(`div`,{className:`rounded-lg border border-border bg-card/50 backdrop-blur-sm overflow-hidden`,children:[(0,G.jsx)(`div`,{className:`flex border-b border-border/50 bg-muted/30`,children:Ic.map(n=>(0,G.jsxs)(`button`,{type:`button`,onClick:()=>t(n.id),className:Y(`flex items-center gap-1 px-3 py-1.5 text-[11px] font-medium transition-colors`,`border-b-2 -mb-px`,e===n.id?`border-primary text-foreground bg-background`:`border-transparent text-muted-foreground hover:text-foreground hover:bg-accent/30`),children:[(0,G.jsx)(`span`,{className:`text-xs`,children:n.icon}),n.label]},n.id))}),(0,G.jsx)(`div`,{className:Y(e===`todos`?`block`:`hidden`),children:(0,G.jsx)(kc,{})}),(0,G.jsx)(`div`,{className:Y(e===`tasks`?`block`:`hidden`),children:(0,G.jsx)(Nc,{})}),(0,G.jsx)(`div`,{className:Y(e===`plan`?`block`:`hidden`),children:(0,G.jsx)(Fc,{})})]})}var Rc={autophase:{active:`bg-primary/15 border-primary/40 text-primary`,idle:`text-primary/80 hover:bg-primary/10`},goal:{active:`bg-rose-500/15 border-rose-500/40 text-rose-600 dark:text-rose-400`,idle:`text-rose-600/80 dark:text-rose-400/80 hover:bg-rose-500/10`},fleet:{active:`bg-emerald-500/15 border-emerald-500/40 text-emerald-600 dark:text-emerald-400`,idle:`text-emerald-600/80 dark:text-emerald-400/80 hover:bg-emerald-500/10`},work:{active:`bg-amber-500/15 border-amber-500/40 text-amber-600 dark:text-amber-400`,idle:`text-amber-600/80 dark:text-amber-400/80 hover:bg-amber-500/10`},worktrees:{active:`bg-violet-500/15 border-violet-500/40 text-violet-600 dark:text-violet-400`,idle:`text-violet-600/80 dark:text-violet-400/80 hover:bg-violet-500/10`},collab:{active:`bg-cyan-500/15 border-cyan-500/40 text-cyan-600 dark:text-cyan-400`,idle:`text-muted-foreground hover:bg-muted/60`}};function zc({section:e,icon:t,label:n,value:r,active:i,pulse:a,onClick:o}){let s=Rc[e];return(0,G.jsxs)(`button`,{type:`button`,onClick:o,title:i?`Collapse ${n}`:`Expand ${n}`,className:Y(`flex items-center gap-1.5 h-6 px-2 rounded-full border text-[11px] font-medium shrink-0 transition-colors`,i?s.active:Y(`border-transparent`,s.idle)),children:[(0,G.jsx)(`span`,{className:Y(a&&`animate-pulse`),children:t}),n,r&&(0,G.jsx)(`span`,{className:`tabular-nums opacity-80`,children:r})]})}function Bc({sessionId:e}){let{selectAutoPhase:t,toggleAutoPhaseAutonomous:n}=Z(),r=W(e=>e.dockSection),i=W(e=>e.toggleDockSection),a=W(e=>e.setCurrentView),o=Sr(e=>e.goal),s=Cr(e=>e),c=ar(e=>e.worktrees),l=ar(e=>e.baseBranch),u=U(e=>e.todos),d=K(e=>e.agents),f=(0,z.useCallback)(e=>t(e),[t]),p=(0,z.useCallback)(()=>n(!s.autonomous),[n,s.autonomous]),[m,h]=(0,z.useState)(`graph`),g=d.size,_=(0,z.useMemo)(()=>Array.from(d.values()).filter(e=>e.status===`running`).length,[d]),v=u.filter(e=>e.status===`completed`).length,y=u.some(e=>e.status===`in_progress`),b=s.phases.length>0,x=(0,z.useRef)(s.phases.length);(0,z.useEffect)(()=>{let e=W.getState();x.current===0&&s.phases.length>0&&e.dockSection===null&&e.setDockSection(`autophase`),s.phases.length===0&&e.dockSection===`autophase`&&e.setDockSection(null),x.current=s.phases.length},[s.phases.length]);let S={autophase:b,goal:o!==null,fleet:g>0,work:!0,worktrees:c.length>0,collab:!0},C=r&&S[r]?r:null;return(0,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1`,children:[S.autophase&&(0,G.jsx)(zc,{section:`autophase`,icon:(0,G.jsx)(Ft,{className:`h-3 w-3`}),label:`AutoPhase`,value:`${s.overallPercent}%`,active:C===`autophase`,pulse:s.activePhaseId!=null,onClick:()=>i(`autophase`)}),S.goal&&o&&(0,G.jsx)(zc,{section:`goal`,icon:(0,G.jsx)(en,{className:`h-3 w-3`}),label:`Goal`,value:`${o.progress}%`,active:C===`goal`,pulse:o.goalState===`active`,onClick:()=>i(`goal`)}),S.fleet&&(0,G.jsx)(zc,{section:`fleet`,icon:(0,G.jsx)(L,{className:`h-3 w-3`}),label:`Fleet`,value:`${_}/${g}`,active:C===`fleet`,pulse:_>0,onClick:()=>i(`fleet`)}),(0,G.jsx)(zc,{section:`work`,icon:(0,G.jsx)(on,{className:`h-3 w-3`}),label:`Work`,value:u.length>0?`${v}/${u.length}`:void 0,active:C===`work`,pulse:y,onClick:()=>i(`work`)}),S.worktrees&&(0,G.jsx)(zc,{section:`worktrees`,icon:(0,G.jsx)(Vt,{className:`h-3 w-3`}),label:`Worktrees`,value:String(c.length),active:C===`worktrees`,onClick:()=>i(`worktrees`)}),(0,G.jsx)(zc,{section:`collab`,icon:(0,G.jsx)(kt,{className:`h-3 w-3`}),label:`Collab`,active:C===`collab`,onClick:()=>i(`collab`)})]}),C===`autophase`&&b&&(0,G.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,G.jsx)(`div`,{className:`flex justify-end`,children:(0,G.jsxs)(Q,{variant:`outline`,size:`sm`,className:`h-6 gap-1 text-[10px]`,onClick:()=>a(`autophase`),children:[(0,G.jsx)(Ge,{className:`h-3 w-3`}),`Full view`]})}),(0,G.jsx)(Gi,{phases:s.phases,activePhaseId:s.activePhaseId??void 0,overallPercent:s.overallPercent,autonomous:s.autonomous,onPhaseClick:f,onToggleAutonomous:p,className:`w-72 shrink-0`})]}),C===`goal`&&(0,G.jsx)(Dc,{goal:o}),C===`fleet`&&(0,G.jsx)(oc,{}),C===`worktrees`&&(0,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsx)(`div`,{className:`flex items-center gap-2`,children:[`graph`,`lanes`].map(e=>(0,G.jsx)(`button`,{type:`button`,onClick:()=>h(e),className:Y(`text-[10px] px-2 py-0.5 rounded-full border transition-colors capitalize`,m===e?`bg-primary/10 border-primary/30 text-primary`:`border-border text-muted-foreground hover:text-foreground`),children:e},e))}),m===`graph`?(0,G.jsx)(ta,{worktrees:c,baseBranch:l||`HEAD`}):(0,G.jsx)(aa,{worktrees:c,baseBranch:l||`HEAD`})]}),(0,G.jsx)(`div`,{className:Y(C===`work`?`block`:`hidden`),id:`panel-work`,children:(0,G.jsx)(Lc,{})}),(0,G.jsx)(`div`,{className:Y(C===`collab`?`block`:`hidden`),children:(0,G.jsx)(wc,{sessionId:e})})]})}function Vc(e){return e<=0?`$0`:e>=.01?`$${e.toFixed(3)}`:`$${e.toFixed(5)}`.replace(/0+$/,``).replace(/\.$/,``)}function Hc(e){let t=Math.floor(e/1e3);return t<60?`${t}s`:`${Math.floor(t/60)}m ${t%60}s`}var Uc={running:{led:`bg-[hsl(var(--success))]`,label:`running`,pulse:!0,badge:`bg-[hsl(var(--success))]/15 text-[hsl(var(--success))]`},completed:{led:`bg-[hsl(var(--success))]`,label:`done`,pulse:!1,badge:`bg-muted text-muted-foreground`},failed:{led:`bg-destructive`,label:`failed`,pulse:!1,badge:`bg-destructive/15 text-destructive`},timeout:{led:`bg-[hsl(var(--warning))]`,label:`timeout`,pulse:!1,badge:`bg-amber-500/15 text-amber-500`},stopped:{led:`bg-muted-foreground`,label:`stopped`,pulse:!1,badge:`bg-muted text-muted-foreground`}};function Wc({agent:e,isLeader:n}){let r=Uc[e.status],i=e.status===`running`,a=Date.now()-e.startedAt,o=[...e.toolLog.slice(0,8)].reverse();return(0,G.jsxs)(`div`,{className:Y(`rounded-xl border p-4 space-y-3`,i?`border-primary/20 bg-primary/[0.02]`:`border-border bg-card`,n&&`ring-2 ring-amber-500/30`),children:[(0,G.jsxs)(`div`,{className:`flex items-start justify-between`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`span`,{className:Y(`led`,r.led,r.pulse&&`led-pulse`,`mt-0.5`)}),(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,G.jsx)(`span`,{className:`text-sm font-semibold`,children:e.name}),n&&(0,G.jsx)(c,{className:`h-3.5 w-3.5 text-amber-500`,"aria-label":`leader`}),e.extensions>0&&(0,G.jsxs)(`span`,{className:`inline-flex items-center gap-0.5 px-1.5 py-0.5 rounded-full bg-amber-500/15 text-[10px] text-amber-600 dark:text-amber-400 font-medium`,children:[(0,G.jsx)(Ue,{className:`h-2.5 w-2.5`}),`Γ—`,e.extensions]})]}),(0,G.jsx)(`span`,{className:Y(`inline-block mt-0.5 px-1.5 py-0.5 rounded text-[10px] font-medium`,r.badge),children:r.label})]})]}),(0,G.jsx)(`div`,{className:`flex items-center gap-1 text-[10px] text-muted-foreground`,children:n&&(0,G.jsx)(`span`,{className:`text-[9px] bg-amber-500/15 text-amber-600 dark:text-amber-400 px-1.5 py-0.5 rounded`,children:`LEADER`})})]}),e.description&&(0,G.jsx)(`p`,{className:`text-xs text-muted-foreground leading-relaxed line-clamp-2`,children:e.description}),e.budgetWarning&&(0,G.jsxs)(`div`,{className:`flex items-center gap-2 px-3 py-2 rounded-lg bg-amber-500/10 border border-amber-500/20 text-xs`,children:[(0,G.jsx)(Ue,{className:`h-3.5 w-3.5 text-amber-500 shrink-0`}),(0,G.jsxs)(`span`,{className:`text-amber-600 dark:text-amber-400`,children:[`⚑ hitting `,(0,G.jsx)(`strong`,{children:e.budgetWarning.kind}),` limit (`,e.budgetWarning.used,`/`,e.budgetWarning.limit,`) β€” extending`]})]}),e.failureReason&&(0,G.jsx)(`div`,{className:`flex items-center gap-2 px-3 py-2 rounded-lg bg-destructive/10 border border-destructive/20 text-xs`,children:(0,G.jsxs)(`span`,{className:`text-destructive font-medium`,children:[`βœ— `,e.failureReason]})}),(0,G.jsxs)(`div`,{className:`grid grid-cols-4 gap-2`,children:[(0,G.jsxs)(`div`,{className:`rounded-lg border bg-muted/30 px-2 py-1.5 text-center`,children:[(0,G.jsx)(`div`,{className:`text-[10px] text-muted-foreground`,children:`Iters`}),(0,G.jsx)(`div`,{className:`text-xs font-mono font-semibold tabular-nums`,children:e.iteration})]}),(0,G.jsxs)(`div`,{className:`rounded-lg border bg-muted/30 px-2 py-1.5 text-center`,children:[(0,G.jsx)(`div`,{className:`text-[10px] text-muted-foreground`,children:`Tools`}),(0,G.jsx)(`div`,{className:`text-xs font-mono font-semibold tabular-nums`,children:e.toolCalls})]}),(0,G.jsxs)(`div`,{className:`rounded-lg border bg-muted/30 px-2 py-1.5 text-center`,children:[(0,G.jsx)(`div`,{className:`text-[10px] text-muted-foreground`,children:`Cost`}),(0,G.jsx)(`div`,{className:`text-xs font-mono font-semibold tabular-nums`,children:Vc(e.costUsd)})]}),(0,G.jsxs)(`div`,{className:`rounded-lg border bg-muted/30 px-2 py-1.5 text-center`,children:[(0,G.jsx)(`div`,{className:`text-[10px] text-muted-foreground`,children:`Elapsed`}),(0,G.jsx)(`div`,{className:`text-xs font-mono font-semibold tabular-nums`,children:Hc(a)})]})]}),(0,G.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:`Activity (12 bins)`}),(0,G.jsx)($s,{bins:e.sparklineBins,className:`font-mono text-[9px]`})]}),(0,G.jsx)(Ra,{pct:e.ctxPct,tokens:e.ctxTokens,maxTokens:e.maxContext})]}),(e.provider||e.model)&&(0,G.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[10px] text-muted-foreground`,children:[(0,G.jsx)(E,{className:`h-3 w-3`}),(0,G.jsxs)(`span`,{className:`font-mono`,children:[e.provider??`?`,`/`,e.model??`?`]})]}),(e.currentTool||e.lastTool)&&(0,G.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[10px] text-muted-foreground`,children:[(0,G.jsx)(t,{className:Y(`h-3 w-3`,i&&`animate-pulse text-primary`)}),(0,G.jsx)(`span`,{className:`font-mono`,children:e.currentTool??e.lastTool}),i&&(0,G.jsx)(I,{className:`h-3 w-3 animate-spin`})]}),e.partialText&&i&&(0,G.jsxs)(`div`,{className:`rounded-lg border bg-muted/30 p-2`,children:[(0,G.jsx)(`div`,{className:`text-[9px] text-muted-foreground uppercase tracking-wider mb-1`,children:`Streaming output`}),(0,G.jsx)(`pre`,{className:`text-[10px] font-mono text-foreground/80 whitespace-pre-wrap line-clamp-3 leading-relaxed`,children:e.partialText})]}),o.length>0&&(0,G.jsxs)(`div`,{className:`space-y-1`,children:[(0,G.jsx)(`div`,{className:`text-[9px] text-muted-foreground uppercase tracking-wider`,children:`Recent tools`}),(0,G.jsx)(`div`,{className:`space-y-0.5`,children:o.map((e,t)=>(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-[10px] font-mono`,children:[(0,G.jsx)(`span`,{className:Y(`shrink-0`,e.ok?`text-[hsl(var(--success))]`:`text-destructive`),children:e.ok?`βœ“`:`βœ—`}),(0,G.jsx)(`span`,{className:`text-muted-foreground truncate`,children:e.name}),(0,G.jsx)(`span`,{className:`ml-auto tabular-nums text-muted-foreground shrink-0`,children:e.durationMs>=1e3?`${(e.durationMs/1e3).toFixed(1)}s`:`${e.durationMs}ms`})]},t))})]}),e.finalText&&!i&&(0,G.jsxs)(`div`,{className:`rounded-lg border bg-muted/30 p-2`,children:[(0,G.jsx)(`div`,{className:`text-[9px] text-muted-foreground uppercase tracking-wider mb-1`,children:`Final output`}),(0,G.jsx)(`pre`,{className:`text-[10px] font-mono text-foreground/80 whitespace-pre-wrap line-clamp-4 leading-relaxed`,children:e.finalText})]})]})}function Gc({onClose:e}){let t=K(e=>e.agents),n=K(e=>e.leaderId),[r,i]=(0,z.useState)(0),a=(0,z.useMemo)(()=>{let e=Array.from(t.values());return e.sort((e,t)=>{if(e.id===n)return-1;if(t.id===n)return 1;let r=e.status===`running`?0:1,i=t.status===`running`?0:1;return r===i?e.startedAt-t.startedAt:r-i}),e},[t,n]),o=(0,z.useCallback)(t=>{if(t.key===`Escape`){e();return}if(t.key===`ArrowDown`){t.preventDefault(),i(e=>Math.min(e+1,a.length-1));return}if(t.key===`ArrowUp`){t.preventDefault(),i(e=>Math.max(e-1,0));return}},[a.length,e]);(0,z.useEffect)(()=>{let t=t=>{t.key===`Escape`&&e()};return window.addEventListener(`keydown`,t),()=>window.removeEventListener(`keydown`,t)},[e]);let s=a[r]??null;return(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`div`,{className:`fixed inset-0 z-40 bg-black/10 backdrop-blur-[1px]`,onClick:e,"aria-hidden":`true`}),(0,G.jsxs)(`div`,{className:`fixed right-0 top-0 h-full z-50 w-[600px] max-w-[90vw] flex flex-col bg-background border-l shadow-2xl animate-slide-in-right`,onKeyDown:o,tabIndex:-1,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between px-4 py-3 border-b bg-card/80 backdrop-blur shrink-0`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,G.jsx)(L,{className:`h-5 w-5 text-primary`}),(0,G.jsx)(`h2`,{className:`text-sm font-semibold`,children:`Agents Monitor`}),(0,G.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[a.length,` total`]})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`button`,{type:`button`,onClick:()=>i(e=>Math.max(e-1,0)),className:`p-1.5 rounded-md hover:bg-muted transition-colors disabled:opacity-30`,disabled:r===0,"aria-label":`Previous agent`,children:(0,G.jsx)(Gt,{className:`h-4 w-4`})}),(0,G.jsx)(`span`,{className:`text-xs tabular-nums text-muted-foreground font-mono`,children:a.length>0?`${r+1}/${a.length}`:`0/0`}),(0,G.jsx)(`button`,{type:`button`,onClick:()=>i(e=>Math.min(e+1,a.length-1)),className:`p-1.5 rounded-md hover:bg-muted transition-colors disabled:opacity-30`,disabled:r>=a.length-1,"aria-label":`Next agent`,children:(0,G.jsx)(mn,{className:`h-4 w-4`})}),(0,G.jsx)(`button`,{type:`button`,onClick:e,className:`p-1.5 rounded-md hover:bg-muted transition-colors ml-2`,"aria-label":`Close agents monitor`,children:(0,G.jsx)(F,{className:`h-4 w-4`})})]})]}),(0,G.jsx)(`div`,{className:`flex-1 overflow-y-auto p-4`,children:a.length===0?(0,G.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full text-muted-foreground`,children:[(0,G.jsx)(L,{className:`h-12 w-12 mb-3 opacity-20`}),(0,G.jsx)(`p`,{className:`text-sm font-medium`,children:`No agents active`})]}):s?(0,G.jsx)(`div`,{className:`max-w-2xl mx-auto`,children:(0,G.jsx)(Wc,{agent:s,isLeader:s.id===n})}):null}),a.length>0&&(0,G.jsxs)(`div`,{className:`border-t bg-card/80 backdrop-blur shrink-0`,children:[(0,G.jsx)(`div`,{className:`px-4 py-2 flex items-center gap-2 overflow-x-auto`,children:a.map((e,t)=>(0,G.jsxs)(`button`,{type:`button`,onClick:()=>i(t),className:Y(`shrink-0 flex items-center gap-1.5 px-2 py-1 rounded-md text-[10px] transition-colors`,t===r?`bg-primary/15 text-primary ring-1 ring-primary/40`:`hover:bg-accent text-muted-foreground`),children:[(0,G.jsx)(`span`,{className:Y(`led`,Uc[e.status].led,Uc[e.status].pulse&&`led-pulse`,`shrink-0`)}),(0,G.jsx)(`span`,{children:e.name}),e.id===n&&(0,G.jsx)(c,{className:`h-2.5 w-2.5 text-amber-500 shrink-0`})]},e.id))}),(0,G.jsxs)(`div`,{className:`px-4 py-1.5 border-t text-[10px] text-muted-foreground flex items-center gap-4`,children:[(0,G.jsx)(`span`,{children:`←→ page`}),(0,G.jsx)(`span`,{children:`↑↓ navigate list`}),(0,G.jsx)(`span`,{children:`Esc close`})]})]})]})]})}var Kc=z.forwardRef(({className:e,inset:t,children:n,...r},i)=>(0,G.jsxs)(gn,{ref:i,className:Y(`flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none focus:bg-accent data-[state=open]:bg-accent`,t&&`pl-8`,e),...r,children:[n,(0,G.jsx)(mn,{className:`ml-auto h-4 w-4`})]}));Kc.displayName=gn.displayName;var qc=z.forwardRef(({className:e,...t},n)=>(0,G.jsx)(It,{ref:n,className:Y(`z-50 min-w-[8rem] overflow-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-lg data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2`,e),...t}));qc.displayName=It.displayName;var Jc=z.forwardRef(({className:e,sideOffset:t=4,...n},r)=>(0,G.jsx)(qt,{children:(0,G.jsx)(Wt,{ref:r,sideOffset:t,className:Y(`z-50 min-w-[8rem] overflow-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-md data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2`,e),...n})}));Jc.displayName=Wt.displayName;var Yc=z.forwardRef(({className:e,inset:t,...n},r)=>(0,G.jsx)(an,{ref:r,className:Y(`relative flex cursor-default select-none items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&>svg]:size-4 [&>svg]:shrink-0`,t&&`pl-8`,e),...n}));Yc.displayName=an.displayName;var Xc=z.forwardRef(({className:e,children:t,checked:n,...r},i)=>(0,G.jsxs)(fn,{ref:i,className:Y(`relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50`,e),checked:n,...r,children:[(0,G.jsx)(`span`,{className:`absolute left-2 flex h-3.5 w-3.5 items-center justify-center`,children:(0,G.jsx)(Et,{children:(0,G.jsx)(Ot,{className:`h-4 w-4`})})}),t]}));Xc.displayName=fn.displayName;var Zc=z.forwardRef(({className:e,children:t,...n},r)=>(0,G.jsxs)(ln,{ref:r,className:Y(`relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50`,e),...n,children:[(0,G.jsx)(`span`,{className:`absolute left-2 flex h-3.5 w-3.5 items-center justify-center`,children:(0,G.jsx)(Et,{children:(0,G.jsx)(nn,{className:`h-2 w-2 fill-current`})})}),t]}));Zc.displayName=ln.displayName;var Qc=z.forwardRef(({className:e,inset:t,...n},r)=>(0,G.jsx)(Xe,{ref:r,className:Y(`px-2 py-1.5 text-sm font-semibold`,t&&`pl-8`,e),...n}));Qc.displayName=Xe.displayName;var $c=z.forwardRef(({className:e,...t},n)=>(0,G.jsx)(rt,{ref:n,className:Y(`-mx-1 my-1 h-px bg-muted`,e),...t}));$c.displayName=rt.displayName;var el=({className:e,...t})=>(0,G.jsx)(`span`,{className:Y(`ml-auto text-xs tracking-widest opacity-60`,e),...t});el.displayName=`DropdownMenuShortcut`;function tl({current:e,max:t,className:n,showLabel:r=!0}){let i=Math.min(e,t),a=Math.max(0,t-i),o=t>0?i/t*100:0,s=o>=90?`text-destructive`:o>=70?`text-[hsl(var(--warning))]`:`text-[hsl(var(--success))]`;return(0,G.jsxs)(`span`,{className:n,title:`Fleet concurrency: ${e}/${t}`,children:[(0,G.jsxs)(`span`,{"aria-hidden":`true`,className:`font-mono text-[10px] tracking-tight`,children:[`[`,(0,G.jsx)(`span`,{className:s,children:`β–ˆ`.repeat(i)}),(0,G.jsx)(`span`,{className:`text-[hsl(var(--muted))]`,children:`β–‘`.repeat(a)}),`]`]}),r&&(0,G.jsxs)(`span`,{className:`ml-1.5 tabular-nums text-[10px] text-muted-foreground font-mono`,children:[e,`/`,t]})]})}function nl(e){let t=Date.now()-e;return t<5e3?`just now`:t<6e4?`${Math.floor(t/1e3)}s ago`:t<36e5?`${Math.floor(t/6e4)}m ago`:`${Math.floor(t/36e5)}h ago`}var rl={spawned:`πŸš€`,task_started:`β–Ά`,tool_executed:`⚑`,iteration_summary:`πŸ”„`,budget_extended:`⚑`,task_completed:`βœ…`,ctx_pct:`πŸ’¬`,leader_updated:`πŸ‘‘`};function il({events:e,max:t=20,className:n}){let r=e.slice(0,t);return r.length===0?(0,G.jsx)(`div`,{className:`py-4 text-center text-xs text-muted-foreground ${n??``}`,children:`No events yet.`}):(0,G.jsx)(`div`,{className:`space-y-0.5 overflow-y-auto max-h-48 ${n??``}`,children:r.map(e=>(0,G.jsxs)(`div`,{className:`flex items-start gap-2 text-[10px] leading-tight py-0.5 px-1 rounded hover:bg-accent/50 transition-colors`,children:[(0,G.jsx)(`span`,{className:`shrink-0 w-5 text-center`,"aria-hidden":`true`,children:rl[e.kind]??`Β·`}),(0,G.jsx)(`span`,{className:`shrink-0 w-12 text-right text-muted-foreground font-mono tabular-nums`,children:nl(e.timestamp)}),(0,G.jsx)(`span`,{className:`truncate text-foreground/90`,children:e.message}),e.value!==void 0&&e.kind===`tool_executed`&&(0,G.jsx)(`span`,{className:`ml-auto shrink-0 tabular-nums text-muted-foreground font-mono`,children:e.value>=1e3?`${(e.value/1e3).toFixed(1)}s`:`${e.value}ms`}),e.value!==void 0&&e.kind===`ctx_pct`&&(0,G.jsxs)(`span`,{className:`ml-auto shrink-0 tabular-nums text-muted-foreground font-mono`,children:[e.value,`%`]})]},e.id))})}function al(e){return e<=0?`$0`:e>=.01?`$${e.toFixed(3)}`:`$${e.toFixed(5)}`.replace(/0+$/,``).replace(/\.$/,``)}function ol(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}K`:String(e)}function sl(e){let t=Math.floor(e/1e3),n=Math.floor(t/60),r=Math.floor(n/60);return r>0?`${r}h ${n%60}m`:n>0?`${n}m ${t%60}s`:`${t}s`}var cl={running:{led:`bg-emerald-500`,label:`running`,pulse:!0,color:`text-emerald-500`},completed:{led:`bg-emerald-500`,label:`done`,pulse:!1,color:`text-emerald-500`},failed:{led:`bg-destructive`,label:`failed`,pulse:!1,color:`text-destructive`},timeout:{led:`bg-amber-500`,label:`timeout`,pulse:!1,color:`text-amber-500`},stopped:{led:`bg-muted-foreground`,label:`stopped`,pulse:!1,color:`text-muted-foreground`}};function ll({agent:e,now:n}){let[r,i]=(0,z.useState)(!1),[a,o]=(0,z.useState)(!1),s=cl[e.status],c=e.status===`running`,l=(0,z.useCallback)(async e=>{try{await navigator.clipboard.writeText(e),i(!0),setTimeout(()=>i(!1),2e3)}catch{}},[]),u=e.toolLog.reduce((e,t)=>e+t.durationMs,0),d=e.toolLog.length>0?Math.round(u/e.toolLog.length):0,f=(0,z.useMemo)(()=>{let t=new Set;return e.toolLog.forEach(e=>t.add(e.name)),t.size},[e.toolLog]),p=e.partialText||e.finalText||void 0,m=!e.finalText&&!!e.partialText;return(0,G.jsxs)(`div`,{className:`h-full flex flex-col`,children:[(0,G.jsxs)(`div`,{className:`shrink-0 border-b bg-card p-4 space-y-3`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,G.jsx)(`div`,{className:`flex items-center justify-center w-10 h-10 rounded-lg bg-primary/10`,children:(0,G.jsx)(L,{className:`h-5 w-5 text-primary`})}),(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`span`,{className:`text-base font-semibold`,children:e.name}),(0,G.jsx)(`span`,{className:Y(`px-2 py-0.5 rounded text-[10px] font-medium uppercase tracking-wider`,e.status===`running`?`bg-emerald-500/15 text-emerald-600 dark:text-emerald-400`:e.status===`failed`||e.status===`timeout`?`bg-destructive/15 text-destructive`:`bg-muted text-muted-foreground`),children:s.label})]}),(0,G.jsxs)(`span`,{className:`text-[10px] text-muted-foreground font-mono`,children:[`session: `,e.sessionId?.slice(0,12),`…`]})]})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-[11px] text-muted-foreground`,children:[c&&(0,G.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,G.jsx)(ut,{className:`h-3.5 w-3.5`}),(0,G.jsx)(`span`,{className:`tabular-nums font-mono`,children:sl(Math.max(0,n-e.startedAt))})]}),(0,G.jsx)(`span`,{className:Y(`led`,s.led,c&&`led-pulse`)})]})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-3 px-3 py-2 rounded-lg bg-muted/30`,children:[(0,G.jsx)(`span`,{className:`text-[10px] text-muted-foreground uppercase tracking-wider`,children:`Activity`}),(0,G.jsx)($s,{bins:e.sparklineBins,className:`font-mono text-[9px]`}),e.budgetWarning&&(0,G.jsxs)(`span`,{className:`ml-auto flex items-center gap-1 text-[10px] text-amber-500`,children:[(0,G.jsx)(Ue,{className:`h-3 w-3`}),`budget warning`]})]}),e.description&&(0,G.jsxs)(`div`,{className:`px-3 py-2 rounded-lg bg-muted/20 border border-border/50`,children:[(0,G.jsx)(`span`,{className:`text-[9px] text-muted-foreground uppercase tracking-wider`,children:`Current Task`}),(0,G.jsx)(`p`,{className:`text-xs mt-1 text-foreground/80`,children:e.description})]})]}),(0,G.jsxs)(`div`,{className:`flex-1 overflow-y-auto p-4 space-y-4`,children:[(0,G.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,G.jsxs)(`div`,{className:`rounded-lg border bg-card p-3`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-[9px] text-muted-foreground uppercase tracking-wider mb-2`,children:[(0,G.jsx)(E,{className:`h-3 w-3`}),` Provider / Model`]}),(0,G.jsxs)(`div`,{className:`text-sm font-mono font-medium`,children:[e.provider??`?`,`/`,e.model??`?`]})]}),(0,G.jsxs)(`div`,{className:`rounded-lg border bg-card p-3`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-[9px] text-muted-foreground uppercase tracking-wider mb-2`,children:[(0,G.jsx)(Ht,{className:`h-3 w-3`}),` Performance`]}),(0,G.jsxs)(`div`,{className:`space-y-1`,children:[(0,G.jsxs)(`div`,{className:`flex justify-between text-[11px]`,children:[(0,G.jsx)(`span`,{className:`text-muted-foreground`,children:`Iterations`}),(0,G.jsx)(`span`,{className:`font-mono font-medium`,children:e.iteration})]}),(0,G.jsxs)(`div`,{className:`flex justify-between text-[11px]`,children:[(0,G.jsx)(`span`,{className:`text-muted-foreground`,children:`Tool Calls`}),(0,G.jsx)(`span`,{className:`font-mono font-medium`,children:e.toolCalls})]}),(0,G.jsxs)(`div`,{className:`flex justify-between text-[11px]`,children:[(0,G.jsx)(`span`,{className:`text-muted-foreground`,children:`Unique Tools`}),(0,G.jsx)(`span`,{className:`font-mono font-medium`,children:f})]})]})]}),(0,G.jsxs)(`div`,{className:`rounded-lg border bg-card p-3`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-[9px] text-muted-foreground uppercase tracking-wider mb-2`,children:[(0,G.jsx)(be,{className:`h-3 w-3`}),` Cost`]}),(0,G.jsx)(`div`,{className:`text-lg font-mono font-bold text-emerald-500`,children:al(e.costUsd)}),(0,G.jsxs)(`div`,{className:`text-[10px] text-muted-foreground mt-1`,children:[`avg `,d,`ms per tool`]})]}),(0,G.jsxs)(`div`,{className:`rounded-lg border bg-card p-3`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-[9px] text-muted-foreground uppercase tracking-wider mb-2`,children:[(0,G.jsx)(Pn,{className:`h-3 w-3`}),` Context`]}),(0,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsxs)(`div`,{className:`flex justify-between text-[11px]`,children:[(0,G.jsx)(`span`,{className:`text-muted-foreground`,children:`Tokens`}),(0,G.jsx)(`span`,{className:`font-mono font-medium`,children:ol(e.ctxTokens)})]}),(0,G.jsx)(`div`,{className:`h-2 w-full rounded-full bg-muted overflow-hidden`,children:(0,G.jsx)(`div`,{className:Y(`h-full rounded-full transition-all`,e.ctxPct>=85?`bg-destructive`:e.ctxPct>=70?`bg-amber-500`:`bg-emerald-500`),style:{width:`${Math.min(200,e.ctxPct)}%`}})}),(0,G.jsxs)(`span`,{className:`text-[10px] text-muted-foreground tabular-nums font-mono`,children:[e.ctxPct,`% used`]})]})]})]}),e.currentTool&&(0,G.jsxs)(`div`,{className:Y(`rounded-lg border px-4 py-3 flex items-center gap-3`,c?`border-primary/30 bg-primary/[0.04]`:`border-border bg-muted/30`),children:[(0,G.jsx)(t,{className:Y(`h-4 w-4`,c?`text-primary animate-pulse`:`text-muted-foreground`)}),(0,G.jsx)(`span`,{className:`text-sm font-mono font-medium`,children:e.currentTool}),c?(0,G.jsxs)(`span`,{className:`ml-auto flex items-center gap-1.5 text-[10px] text-primary`,children:[(0,G.jsx)(I,{className:`h-3 w-3 animate-spin`}),` running…`]}):(0,G.jsx)(`span`,{className:`ml-auto text-[10px] text-muted-foreground`,children:`completed`})]}),p?(0,G.jsxs)(`div`,{className:`rounded-lg border bg-card`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between px-4 py-2 border-b bg-muted/30`,children:[(0,G.jsx)(`span`,{className:`text-[10px] font-semibold text-muted-foreground uppercase tracking-wider flex items-center gap-2`,children:m?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`span`,{className:`w-2 h-2 rounded-full bg-blue-500 animate-pulse`}),`Live Output`]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(jn,{className:`h-3 w-3`}),`Final Output`]})}),(0,G.jsx)(`button`,{type:`button`,onClick:()=>l(p),className:`flex items-center gap-1 px-2 py-1 rounded text-[10px] text-muted-foreground hover:text-foreground hover:bg-muted transition-colors`,children:r?`βœ“ Copied`:`Copy`})]}),(0,G.jsx)(`pre`,{className:`p-4 text-xs whitespace-pre-wrap font-mono text-foreground/80 leading-relaxed max-h-64 overflow-y-auto`,children:p})]}):c?(0,G.jsxs)(`div`,{className:`rounded-lg border border-dashed border-border p-6 text-center`,children:[(0,G.jsx)(I,{className:`h-6 w-6 mx-auto mb-2 text-muted-foreground/50 animate-spin`}),(0,G.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`Waiting for output…`})]}):null,e.budgetWarning&&(0,G.jsxs)(`div`,{className:`flex items-center gap-3 px-4 py-3 rounded-lg bg-amber-500/10 border border-amber-500/20`,children:[(0,G.jsx)(Ue,{className:`h-5 w-5 text-amber-500 shrink-0`}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`span`,{className:`text-sm font-medium text-amber-600 dark:text-amber-400`,children:`⚑ Budget Warning`}),(0,G.jsxs)(`p`,{className:`text-[11px] text-amber-600/80 dark:text-amber-400/80 mt-0.5`,children:[`Hitting `,e.budgetWarning.kind,` limit (`,e.budgetWarning.used,`/`,e.budgetWarning.limit,`)`]})]})]}),e.extensions>0&&(0,G.jsxs)(`div`,{className:`flex items-center gap-3 px-4 py-3 rounded-lg bg-amber-500/10 border border-amber-500/20`,children:[(0,G.jsx)(Ue,{className:`h-5 w-5 text-amber-500 shrink-0`}),(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`span`,{className:`text-sm font-medium`,children:[e.extensions,` Budget Extension`,e.extensions===1?``:`s`]}),(0,G.jsxs)(`p`,{className:`text-[11px] text-muted-foreground mt-0.5`,children:[`Agent extended its budget `,e.extensions,` time`,e.extensions===1?``:`s`,` due to long-running tasks`]})]})]}),e.error&&(0,G.jsxs)(`div`,{className:`rounded-lg border border-destructive/30 bg-destructive/5 p-4`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 mb-2`,children:[(0,G.jsx)(M,{className:`h-4 w-4 text-destructive`}),(0,G.jsx)(`span`,{className:`text-[10px] font-semibold text-destructive uppercase tracking-wider`,children:`Error`})]}),(0,G.jsx)(`p`,{className:`text-sm text-destructive/90`,children:e.error.message})]}),e.failureReason&&(0,G.jsxs)(`div`,{className:`rounded-lg border border-destructive/30 bg-destructive/5 p-4`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 mb-2`,children:[(0,G.jsx)(M,{className:`h-4 w-4 text-destructive`}),(0,G.jsx)(`span`,{className:`text-[10px] font-semibold text-destructive uppercase tracking-wider`,children:`Failure Reason`})]}),(0,G.jsx)(`p`,{className:`text-sm text-destructive/90`,children:e.failureReason})]}),e.toolLog.length>0&&(0,G.jsxs)(`div`,{className:`rounded-lg border bg-card`,children:[(0,G.jsxs)(`button`,{type:`button`,onClick:()=>o(!a),className:`w-full flex items-center justify-between px-4 py-2 border-b bg-muted/30 hover:bg-muted/50 transition-colors`,children:[(0,G.jsxs)(`span`,{className:`text-[10px] font-semibold text-muted-foreground uppercase tracking-wider flex items-center gap-2`,children:[(0,G.jsx)(t,{className:`h-3 w-3`}),`Tool Log (`,e.toolLog.length,` calls)`]}),(0,G.jsx)(mn,{className:Y(`h-4 w-4 text-muted-foreground transition-transform`,a&&`rotate-90`)})]}),(0,G.jsx)(`div`,{className:Y(`overflow-hidden transition-all`,a?`max-h-[500px]`:`max-h-48`),children:(0,G.jsx)(`div`,{className:`p-2 space-y-0.5`,children:e.toolLog.map((e,t)=>(0,G.jsxs)(`div`,{className:Y(`flex items-center gap-3 rounded px-3 py-2 text-[11px]`,e.ok?`bg-muted/30 hover:bg-muted/50`:`bg-destructive/5 border border-destructive/20`),children:[(0,G.jsx)(`span`,{className:Y(`led shrink-0`,e.ok?`bg-emerald-500`:`bg-destructive`)}),(0,G.jsx)(`span`,{className:Y(`font-mono font-medium w-20 shrink-0`,e.ok?`text-foreground`:`text-destructive`),children:e.name}),(0,G.jsx)(`span`,{className:`text-muted-foreground tabular-nums text-[10px]`,children:e.durationMs>=1e3?`${(e.durationMs/1e3).toFixed(2)}s`:`${e.durationMs}ms`}),!e.ok&&(0,G.jsx)(`span`,{className:`ml-auto text-[10px] text-destructive font-medium`,children:`Failed`}),(0,G.jsx)(`span`,{className:`ml-auto text-[9px] text-muted-foreground tabular-nums`,children:new Date(e.at).toLocaleTimeString()})]},`${e.name}-${e.at}-${t}`))})})]})]})]})}function ul({agent:e,isSelected:t,isLeader:n,onClick:r}){let i=cl[e.status],a=e.status===`running`;return(0,G.jsxs)(`button`,{type:`button`,onClick:r,className:Y(`w-full text-left grid grid-cols-[140px_60px_1fr_60px_60px_60px_60px_50px_50px] items-center gap-x-2 px-3 py-1.5 rounded-md text-xs transition-colors`,t?`bg-primary/15 ring-1 ring-primary/40`:`hover:bg-accent/50`,a&&!t&&`bg-muted/30`),children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-1 min-w-0`,children:[(0,G.jsx)(`span`,{className:Y(`led shrink-0`,i.led,i.pulse&&`led-pulse`)}),(0,G.jsx)(`span`,{className:`truncate font-medium`,children:e.name}),n&&(0,G.jsx)(c,{className:`h-3 w-3 shrink-0 text-amber-500`,"aria-label":`leader`})]}),(0,G.jsx)(`span`,{className:Y(`text-[10px] tabular-nums`,a?`text-emerald-500`:`text-muted-foreground`),children:i.label}),(0,G.jsxs)(`div`,{className:`flex items-center gap-1 min-w-0`,children:[(0,G.jsx)($s,{bins:e.sparklineBins,className:`font-mono text-[9px]`}),e.budgetWarning&&(0,G.jsx)(`span`,{title:`⚑ hitting ${e.budgetWarning.kind} limit (${e.budgetWarning.used}/${e.budgetWarning.limit})`,children:(0,G.jsx)(Ue,{className:`h-3 w-3 shrink-0 text-amber-500`,"aria-label":`budget warning`})})]}),(0,G.jsxs)(`span`,{className:`tabular-nums text-muted-foreground text-[10px]`,children:[e.iteration,`it`]}),(0,G.jsxs)(`span`,{className:`tabular-nums text-muted-foreground text-[10px]`,children:[e.toolCalls,`tc`]}),(0,G.jsx)(`span`,{className:`tabular-nums font-mono text-[10px]`,children:al(e.costUsd)}),(0,G.jsxs)(`div`,{className:`flex flex-col gap-0.5 min-w-0`,children:[(0,G.jsx)(`div`,{className:`h-1.5 w-full rounded-full bg-muted overflow-hidden`,children:(0,G.jsx)(`div`,{className:Y(`h-full rounded-full transition-all`,e.ctxPct>=85?`bg-destructive`:e.ctxPct>=70?`bg-amber-500`:`bg-emerald-500`),style:{width:`${Math.min(200,e.ctxPct)}%`}})}),(0,G.jsx)(`span`,{className:`text-[9px] tabular-nums text-muted-foreground font-mono leading-none`,children:e.maxContext>0?`${e.ctxPct}%`:`β€”`})]}),(0,G.jsx)(`span`,{className:`tabular-nums text-[10px] text-muted-foreground`,children:e.extensions>0?`βš‘Γ—${e.extensions}`:`β€”`}),(0,G.jsx)(`span`,{className:`text-[9px] text-destructive truncate`,title:e.failureReason,children:e.failureReason??``})]})}function dl({onClose:e,onSelectAgent:t}){let n=K(e=>e.agents),r=K(e=>e.leaderId),i=K(e=>e.fleetTokensIn),a=K(e=>e.fleetTokensOut),o=K(e=>e.fleetConcurrency),s=K(e=>e.fleetConcurrencyMax),c=K(e=>e.eventTimeline),[l,u]=(0,z.useState)(null),[d,f]=(0,z.useState)(Date.now());(0,z.useEffect)(()=>{let e=setInterval(()=>f(Date.now()),1e3);return()=>clearInterval(e)},[]);let p=(0,z.useMemo)(()=>{let e=Array.from(n.values());return e.sort((e,t)=>{if(e.id===r)return-1;if(t.id===r)return 1;let n=e.status===`running`?0:1,i=t.status===`running`?0:1;return n===i?e.startedAt-t.startedAt:n-i}),e},[n,r]),m=(0,z.useMemo)(()=>Array.from(n.values()).reduce((e,t)=>e+t.costUsd,0),[n]),h=p.filter(e=>e.status===`running`).length,g=l===null?null:p[l],_=(0,z.useCallback)(e=>u(t=>t===e?null:e),[]),v=(0,z.useCallback)(n=>{if(n.key===`Escape`){l===null?e&&e():u(null);return}if(n.key===`ArrowDown`){n.preventDefault(),u(e=>Math.min((e??-1)+1,p.length-1));return}if(n.key===`ArrowUp`){n.preventDefault(),u(e=>Math.max((e??0)-1,0));return}n.key===`Enter`&&p[l??0]&&t?.(p[l??0])},[p,l,e,t]);return(0,z.useEffect)(()=>{let t=t=>{t.key===`Escape`&&e()};return window.addEventListener(`keydown`,t),()=>window.removeEventListener(`keydown`,t)},[e]),(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`div`,{className:`fixed inset-0 z-40 bg-black/10 backdrop-blur-[1px]`,onClick:e,"aria-hidden":`true`}),(0,G.jsxs)(`div`,{className:`fixed right-0 top-0 h-full z-50 w-[720px] max-w-[95vw] flex flex-col bg-background border-l shadow-2xl animate-slide-in-right`,onKeyDown:v,tabIndex:-1,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between px-4 py-3 border-b bg-card/80 backdrop-blur shrink-0`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,G.jsx)(L,{className:`h-5 w-5 text-primary`}),(0,G.jsxs)(`h2`,{className:`text-sm font-semibold flex items-center gap-2`,children:[`FLEET MONITOR`,h>0&&(0,G.jsxs)(`span`,{className:`flex items-center gap-1 text-[11px] text-emerald-500 font-normal`,children:[(0,G.jsx)(`span`,{className:`led led-pulse bg-emerald-500`}),h,` running`]})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-xs text-muted-foreground`,children:[(0,G.jsxs)(`span`,{children:[p.length,` total agents`]}),(0,G.jsx)(tl,{current:o,max:s,showLabel:!0})]})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,G.jsxs)(`span`,{className:`text-xs text-muted-foreground tabular-nums font-mono`,children:[`↓`,ol(i),` ↑`,ol(a),` Β· `,al(m)]}),(0,G.jsx)(`span`,{className:`text-xs text-muted-foreground tabular-nums font-mono`,children:r?`πŸ‘‘ ${n.get(r)?.name??r}`:`no leader`}),(0,G.jsx)(`button`,{type:`button`,onClick:e,className:`p-1.5 rounded-md hover:bg-muted transition-colors`,"aria-label":`Close fleet monitor`,children:(0,G.jsx)(M,{className:`h-4 w-4`})})]})]}),(0,G.jsxs)(`div`,{className:`flex-1 flex overflow-hidden`,children:[(0,G.jsxs)(`div`,{className:Y(`flex flex-col border-r transition-all duration-200`,g?`w-[500px] shrink-0`:`w-full`),children:[(0,G.jsx)(`div`,{className:`border-b bg-card/80 px-3 py-2`,children:(0,G.jsxs)(`div`,{className:`grid grid-cols-[140px_60px_1fr_60px_60px_60px_60px_50px_50px] gap-x-2 text-[9px] uppercase tracking-wider text-muted-foreground font-medium`,children:[(0,G.jsx)(`span`,{children:`Name`}),(0,G.jsx)(`span`,{children:`Status`}),(0,G.jsx)(`span`,{children:`Activity`}),(0,G.jsx)(`span`,{children:`Iters`}),(0,G.jsx)(`span`,{children:`Tools`}),(0,G.jsx)(`span`,{children:`Cost`}),(0,G.jsx)(`span`,{children:`CTX`}),(0,G.jsx)(`span`,{children:`Ext`}),(0,G.jsx)(`span`,{children:`Reason`})]})}),(0,G.jsx)(`div`,{className:`flex-1 overflow-y-auto`,children:p.length===0?(0,G.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full text-muted-foreground`,children:[(0,G.jsx)(kt,{className:`h-12 w-12 mb-3 opacity-20`}),(0,G.jsx)(`p`,{className:`text-sm font-medium`,children:`No agents active`}),(0,G.jsx)(`p`,{className:`text-xs mt-1`,children:`Agents appear here when the fleet is active.`})]}):(0,G.jsx)(`div`,{className:`p-2 space-y-0.5`,children:p.map((e,t)=>(0,G.jsx)(ul,{agent:e,isSelected:t===l,isLeader:e.id===r,onClick:()=>_(t)},e.id))})}),(0,G.jsxs)(`div`,{className:`border-t bg-card/80 shrink-0`,children:[(0,G.jsx)(`div`,{className:`px-4 py-2 border-b`,children:(0,G.jsxs)(`span`,{className:`text-[10px] uppercase tracking-wider text-muted-foreground font-medium flex items-center gap-2`,children:[(0,G.jsx)(N,{className:`h-3 w-3`}),`Event Timeline`]})}),(0,G.jsx)(`div`,{className:`px-4 py-2 max-h-32 overflow-y-auto`,children:(0,G.jsx)(il,{events:c,max:10})}),(0,G.jsxs)(`div`,{className:`px-4 py-1.5 border-t text-[10px] text-muted-foreground flex items-center gap-4`,children:[(0,G.jsx)(`span`,{children:`↑↓ navigate`}),(0,G.jsx)(`span`,{children:`↡ select detail`}),(0,G.jsx)(`span`,{children:`Esc deselect / close`})]})]})]}),g&&(0,G.jsx)(`div`,{className:`flex-1 overflow-hidden bg-card/50`,children:(0,G.jsxs)(`div`,{className:`h-full flex flex-col`,children:[(0,G.jsxs)(`div`,{className:`shrink-0 px-4 py-2 border-b bg-card/80 flex items-center gap-2`,children:[(0,G.jsx)(vn,{className:`h-4 w-4 text-primary`}),(0,G.jsx)(`span`,{className:`text-xs font-semibold text-primary`,children:g.name}),(0,G.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:`detailed view`}),(0,G.jsx)(`button`,{type:`button`,onClick:()=>u(null),className:`ml-auto text-[10px] text-muted-foreground hover:text-foreground transition-colors flex items-center gap-1`,children:`βœ• close`})]}),(0,G.jsx)(`div`,{className:`flex-1 overflow-hidden`,children:(0,G.jsx)(ll,{agent:g,now:d})})]})}),!g&&p.length>0&&(0,G.jsx)(`div`,{className:`flex-1 flex items-center justify-center bg-muted/20`,children:(0,G.jsxs)(`div`,{className:`text-center space-y-3 max-w-sm`,children:[(0,G.jsx)(kt,{className:`h-12 w-12 text-muted-foreground/30 mx-auto`}),(0,G.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Select an agent to view detailed information`}),(0,G.jsx)(`p`,{className:`text-xs text-muted-foreground/60`,children:`Click on any agent in the list to see detailed metrics, tool logs, streaming output, and more β€” similar to the chat history detailed view.`}),(0,G.jsxs)(`div`,{className:`flex items-center justify-center gap-4 pt-2`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[10px] text-muted-foreground`,children:[(0,G.jsx)(`kbd`,{className:`px-1.5 py-0.5 rounded bg-muted border text-[9px]`,children:`↑`}),(0,G.jsx)(`kbd`,{className:`px-1.5 py-0.5 rounded bg-muted border text-[9px]`,children:`↓`}),(0,G.jsx)(`span`,{children:`navigate`})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[10px] text-muted-foreground`,children:[(0,G.jsx)(`kbd`,{className:`px-1.5 py-0.5 rounded bg-muted border text-[9px]`,children:`Enter`}),(0,G.jsx)(`span`,{children:`select`})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[10px] text-muted-foreground`,children:[(0,G.jsx)(`kbd`,{className:`px-1.5 py-0.5 rounded bg-muted border text-[9px]`,children:`Esc`}),(0,G.jsx)(`span`,{children:`deselect`})]})]})]})})]})]})]})}var fl=320;function pl(e){return e<=0?`$0`:e>=.01?`$${e.toFixed(3)}`:`$${e.toFixed(5)}`.replace(/0+$/,``).replace(/\.$/,``)}function ml(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}K`:String(e)}function hl(e,t){let n=Array.from(e.values());return n.sort((e,n)=>{if(e.id===t)return-1;if(n.id===t)return 1;let r=e.status===`running`?0:1,i=n.status===`running`?0:1;return r===i?e.startedAt-n.startedAt:r-i}),n}function gl(){let e=W(e=>e.inspectorOpen),t=W(e=>e.inspectorTab),n=W(e=>e.toggleInspector),r=W(e=>e.setInspectorOpen),i=W(e=>e.setInspectorTab),a=K(e=>e.agents),o=K(e=>e.leaderId),s=K(e=>e.fleetTokensIn),c=K(e=>e.fleetTokensOut),l=K(e=>e.fleetConcurrency),u=K(e=>e.fleetConcurrencyMax),d=K(e=>e.eventTimeline),f=(0,z.useMemo)(()=>hl(a,o),[a,o]),p=f.filter(e=>e.status===`running`).length,m=f.reduce((e,t)=>e+t.costUsd,0),h=f.length,[g,_]=(0,z.useState)(null),v=(0,z.useMemo)(()=>g?a.get(g)??f[0]??null:f[0]??null,[g,f,a]),y=()=>i(`fleet`),b=()=>i(`agents`);return(0,G.jsxs)(`div`,{className:`shrink-0 border-t bg-card flex flex-col`,children:[(0,G.jsxs)(`button`,{type:`button`,onClick:n,className:Y(`group w-full flex items-center justify-between gap-2 px-3 h-7 text-[11px]`,`text-muted-foreground hover:text-foreground hover:bg-accent/40 transition-colors`),title:e?`Hide inspector panel`:`Show inspector panel (Fleet / Agents)`,children:[(0,G.jsxs)(`span`,{className:`flex items-center gap-2 min-w-0`,children:[e?(0,G.jsx)(sn,{className:`h-3.5 w-3.5 shrink-0`}):(0,G.jsx)(ft,{className:`h-3.5 w-3.5 shrink-0`}),(0,G.jsx)(`span`,{className:`font-medium uppercase tracking-wider`,children:`Inspector`}),h>0&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`span`,{className:`opacity-40`,children:`Β·`}),(0,G.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,G.jsx)(`span`,{className:Y(`h-1.5 w-1.5 rounded-full`,p>0?`bg-emerald-500 animate-pulse`:`bg-muted-foreground/50`)}),(0,G.jsxs)(`span`,{className:`tabular-nums`,children:[p,`/`,h]})]}),(0,G.jsx)(`span`,{className:`opacity-40 hidden sm:inline`,children:`Β·`}),(0,G.jsxs)(`span`,{className:`tabular-nums font-mono hidden sm:inline`,children:[`↓`,ml(s),` ↑`,ml(c),` Β· `,pl(m)]})]})]}),(0,G.jsxs)(`span`,{className:`flex items-center gap-1 shrink-0 opacity-70 group-hover:opacity-100`,children:[(0,G.jsx)(L,{className:`h-3 w-3`}),(0,G.jsx)(kt,{className:`h-3 w-3`})]})]}),(0,G.jsx)(`div`,{className:`overflow-hidden transition-[height] duration-300 ease-[cubic-bezier(0.16,1,0.3,1)]`,style:{height:e?fl:0},children:(0,G.jsxs)(`div`,{className:`flex flex-col`,style:{height:fl},children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-1 px-2 h-8 border-b bg-muted/30 shrink-0`,children:[(0,G.jsx)(_l,{active:t===`fleet`,onClick:y,icon:(0,G.jsx)(L,{className:`h-3.5 w-3.5`}),label:`Fleet`,count:h,running:p}),(0,G.jsx)(_l,{active:t===`agents`,onClick:b,icon:(0,G.jsx)(kt,{className:`h-3.5 w-3.5`}),label:`Agents`,count:h}),(0,G.jsx)(`div`,{className:`flex-1`}),(0,G.jsx)(`button`,{type:`button`,onClick:()=>r(!1),className:`p-1 rounded hover:bg-muted transition-colors text-muted-foreground hover:text-foreground`,"aria-label":`Collapse inspector panel`,title:`Collapse (Esc)`,children:(0,G.jsx)(sn,{className:`h-4 w-4`})})]}),(0,G.jsx)(`div`,{className:`flex-1 min-h-0 overflow-y-auto`,children:t===`fleet`?(0,G.jsx)(vl,{fleetList:f,leaderId:o,selectedAgentId:g,runningCount:p,fleetConcurrency:l,fleetConcurrencyMax:u,fleetTokensIn:s,fleetTokensOut:c,totalCost:m,eventTimeline:d,onSelectAgent:e=>{_(e.id),b()}}):(0,G.jsx)(yl,{fleetList:f,selectedAgent:v,leaderId:o,selectedAgentId:v?.id??null,onSelectAgent:_})})]})})]})}function _l({active:e,onClick:t,icon:n,label:r,count:i,running:a}){return(0,G.jsxs)(`button`,{type:`button`,onClick:t,className:Y(`flex items-center gap-1.5 px-2.5 h-6 rounded-md text-[11px] font-medium transition-colors`,e?`bg-background text-foreground shadow-sm ring-1 ring-border`:`text-muted-foreground hover:text-foreground hover:bg-background/60`),children:[n,r,i>0&&(0,G.jsx)(`span`,{className:Y(`tabular-nums text-[10px] px-1 rounded-full`,a&&a>0?`bg-emerald-500/15 text-emerald-600 dark:text-emerald-400`:`bg-muted text-muted-foreground`),children:a===void 0?i:`${a}/${i}`})]})}function vl({fleetList:e,leaderId:t,selectedAgentId:n,runningCount:r,fleetConcurrency:i,fleetConcurrencyMax:a,fleetTokensIn:o,fleetTokensOut:s,totalCost:c,eventTimeline:l,onSelectAgent:u}){return(0,G.jsxs)(`div`,{className:`flex flex-col h-full`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-3 px-3 py-1.5 border-b text-[11px] text-muted-foreground shrink-0`,children:[(0,G.jsxs)(`span`,{className:`flex items-center gap-1`,children:[r>0&&(0,G.jsx)(`span`,{className:`h-1.5 w-1.5 rounded-full bg-emerald-500 animate-pulse`}),(0,G.jsxs)(`span`,{className:`tabular-nums`,children:[r,` running Β· `,e.length,` total`]})]}),(0,G.jsx)(tl,{current:i,max:a,showLabel:!0}),(0,G.jsx)(`div`,{className:`flex-1`}),(0,G.jsxs)(`span`,{className:`tabular-nums font-mono`,children:[`↓`,ml(o),` ↑`,ml(s),` Β· `,pl(c)]})]}),e.length===0?(0,G.jsxs)(`div`,{className:`flex flex-col items-center justify-center py-8 text-muted-foreground`,children:[(0,G.jsx)(kt,{className:`h-8 w-8 mb-2 opacity-20`}),(0,G.jsx)(`p`,{className:`text-xs font-medium`,children:`No agents active`}),(0,G.jsx)(`p`,{className:`text-[11px] mt-0.5`,children:`Agents appear here when the fleet is active.`})]}):(0,G.jsx)(`div`,{className:`flex-1 min-h-0 overflow-y-auto p-1.5`,children:e.map(e=>(0,G.jsx)(ul,{agent:e,isSelected:n===e.id,isLeader:e.id===t,onClick:()=>u(e)},e.id))}),l.length>0&&(0,G.jsx)(`div`,{className:`border-t px-3 py-1.5 shrink-0`,children:(0,G.jsx)(il,{events:l,max:4})})]})}function yl({fleetList:e,selectedAgent:t,leaderId:n,selectedAgentId:r,onSelectAgent:i}){if(e.length===0)return(0,G.jsxs)(`div`,{className:`flex flex-col items-center justify-center py-8 text-muted-foreground`,children:[(0,G.jsx)(L,{className:`h-8 w-8 mb-2 opacity-20`}),(0,G.jsx)(`p`,{className:`text-xs font-medium`,children:`No agents active`})]});if(!t)return null;let a=Math.max(0,e.findIndex(e=>e.id===r));return(0,G.jsxs)(`div`,{className:`flex flex-col h-full`,children:[(0,G.jsx)(`div`,{className:`flex-1 min-h-0 overflow-y-auto p-3`,children:(0,G.jsx)(`div`,{className:`max-w-2xl mx-auto`,children:(0,G.jsx)(Wc,{agent:t,isLeader:t.id===n})})}),(0,G.jsx)(`div`,{className:`border-t px-2 py-1.5 shrink-0`,children:(0,G.jsx)(`div`,{className:`flex items-center gap-1 overflow-x-auto pb-0.5`,children:e.map((e,n)=>(0,G.jsxs)(`button`,{type:`button`,onClick:()=>i(e.id),className:Y(`shrink-0 flex items-center gap-1.5 px-2 py-1 rounded-md text-[10px] transition-colors`,e.id===t?.id?`bg-primary/15 text-primary ring-1 ring-primary/40`:`hover:bg-accent text-muted-foreground`),title:`${e.name}${n===a?` (selected)`:``}`,children:[(0,G.jsx)(`span`,{className:Y(`h-1.5 w-1.5 rounded-full shrink-0`,e.status===`running`?`bg-emerald-500 animate-pulse`:e.status===`failed`?`bg-destructive`:`bg-muted-foreground/50`)}),(0,G.jsx)(`span`,{className:`truncate max-w-[8rem]`,children:e.name})]},e.id))})})]})}function bl(){let{theme:e}=Pi(),{currentView:t,sidebarOpen:n,toggleSidebar:r,setSearchOpen:i,setSidebarOpen:a,setCurrentView:o,setInspectorTab:s,toggleInspector:c,fleetMonitorOpen:l,agentsMonitorOpen:u,setFleetMonitorOpen:d,setAgentsMonitorOpen:f}=W(),p=V(e=>e.isLoading),m=U(e=>e.iteration),h=U(e=>e.projectName),g=U(e=>e.session?.title),_=U(e=>e.session?.id),v=W(e=>_?e.sessionNicknames[_]:void 0);return(0,z.useEffect)(()=>{let e=e=>{let{filePath:t}=e.detail,n=B(H.getState().wsUrl);n&&n.send({type:`files.read`,payload:{filePath:t}})};return window.addEventListener(`wrongstack:open-file`,e),()=>window.removeEventListener(`wrongstack:open-file`,e)},[]),(0,z.useEffect)(()=>{let e=e=>{let{filePath:t}=e.detail,n=q.getState().openFiles.find(e=>e.path===t);if(!n)return;let r=B(H.getState().wsUrl);r&&r.send({type:`files.write`,payload:{filePath:t,content:n.content}})};return window.addEventListener(`wrongstack:save-file`,e),()=>window.removeEventListener(`wrongstack:save-file`,e)},[]),(0,z.useEffect)(()=>{if(typeof window>`u`)return;let e=window.matchMedia(`(max-width: 768px)`),t=()=>{e.matches&&W.getState().sidebarOpen&&a(!1)};return t(),e.addEventListener(`change`,t),()=>e.removeEventListener(`change`,t)},[a]),ji(),(0,z.useEffect)(()=>{let e=[];if(p){let t=m?` iter ${m.index}${m.max?`/${m.max}`:``}`:``;e.push(`●${t}`)}let t=v?.trim()||g?.trim(),n=h?.trim();t&&e.push(t),n&&e.push(n),e.length===0&&e.push(n||`AI Agent`);let r=e.filter(Boolean).join(` Β· `);return document.title=r,()=>{document.title=h||`AI Agent`}},[p,m,h,g,v]),(0,z.useEffect)(()=>{let e=e=>{let t=e.target,n=t?.tagName?.toLowerCase(),a=n===`input`||n===`textarea`||t?.isContentEditable,o=e.ctrlKey||e.metaKey;if(o&&e.key===`\\`){e.preventDefault(),r();return}if(o&&!e.shiftKey&&!e.altKey&&e.key>=`1`&&e.key<=String(Ri.length)){let t=Ri[Number(e.key)-1];if(t){e.preventDefault(),Li(t);return}}if(o&&e.key.toLowerCase()===`f`){e.preventDefault(),i(!0);return}if(o&&e.key.toLowerCase()===`/`){e.preventDefault(),document.querySelector(`textarea`)?.focus();return}if(o&&!a&&(e.key.toLowerCase()===`l`?(e.preventDefault(),V.getState().clearMessages(),B(H.getState().wsUrl)?.clearContext?.()):e.key.toLowerCase()===`n`?(e.preventDefault(),B(H.getState().wsUrl)?.newSession?.(),W.getState().setCurrentView(`chat`)):e.key.toLowerCase()===`e`&&(e.preventDefault(),ua())),o&&e.shiftKey&&e.key.toLowerCase()===`d`&&(e.preventDefault(),W.getState().toggleCompactMode()),o&&e.shiftKey&&e.key.toLowerCase()===`m`){e.preventDefault();let t=W.getState();t.inspectorOpen&&t.inspectorTab===`fleet`?c():(s(`fleet`),t.inspectorOpen||c())}if(o&&e.shiftKey&&e.key.toLowerCase()===`a`){e.preventDefault();let t=W.getState();t.inspectorOpen&&t.inspectorTab===`agents`?c():(s(`agents`),t.inspectorOpen||c())}if(e.key===`Escape`&&!o&&W.getState().inspectorOpen&&W.getState().setInspectorOpen(!1),!a&&!o&&!e.altKey){let t=Array.from(document.querySelectorAll(`[data-message-id]`));if(t.length===0)return;let n=document.querySelector(`[data-message-id][data-focused="true"]`),r=n?t.indexOf(n):-1,i=e=>{for(let e of t)e.removeAttribute(`data-focused`);e.setAttribute(`data-focused`,`true`),e.scrollIntoView({behavior:`smooth`,block:`center`})};if(e.key===`j`||e.key===`ArrowDown`){let n=t[Math.min(t.length-1,Math.max(0,r+1))];n&&(e.preventDefault(),i(n));return}if(e.key===`k`||e.key===`ArrowUp`){let n=t[Math.max(0,r<=0?0:r-1)];n&&(e.preventDefault(),i(n));return}if(e.key===`g`&&!e.shiftKey){e.preventDefault(),i(R(t[0]));return}if(e.key===`G`||e.key===`g`&&e.shiftKey){e.preventDefault(),i(R(t[t.length-1]));return}if(e.key===`Escape`&&n){e.preventDefault(),n.removeAttribute(`data-focused`);return}if(e.key===`c`&&n){let t=n.querySelector(`.markdown-content`)?.innerText??n.innerText;t&&(navigator.clipboard?.writeText(t).catch(()=>{}),e.preventDefault());return}}};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[r,i]),(0,G.jsxs)(`div`,{className:Y(`flex h-screen`,e),children:[t!==`setup`&&(0,G.jsx)(zi,{}),n&&t!==`setup`&&(0,G.jsx)(Cc,{}),(0,G.jsxs)(`main`,{className:`flex-1 flex flex-col overflow-hidden`,children:[t!==`setup`&&(0,G.jsx)(Yo,{}),t===`chat`&&(0,G.jsxs)(G.Fragment,{children:[_&&(0,G.jsx)(`div`,{className:`px-4 pt-2`,children:(0,G.jsx)(Bc,{sessionId:_})}),(0,G.jsx)(Oo,{}),(0,G.jsx)(gl,{})]}),t===`settings`&&(0,G.jsx)(fs,{}),t===`setup`&&(0,G.jsx)(gs,{}),t===`autophase`&&(0,G.jsx)(sa,{onClose:()=>o(`chat`)}),t===`agentflow`&&(0,G.jsx)(`div`,{className:`flex-1 flex flex-col overflow-hidden`,children:(0,G.jsx)(Bs,{})}),t===`sessions`&&(0,G.jsx)(`div`,{className:`flex-1 overflow-y-auto`,children:(0,G.jsx)(Ss,{})}),t===`files`&&(0,G.jsx)(No,{})]}),l&&(0,G.jsx)(dl,{onClose:()=>d(!1)}),u&&(0,G.jsx)(Gc,{onClose:()=>f(!1)}),(0,G.jsx)(Go,{}),(0,G.jsx)(Jo,{}),(0,G.jsx)(fa,{}),(0,G.jsx)(ws,{}),(0,G.jsx)(Qo,{}),(0,G.jsx)(Pr,{})]})}function xl(){return(0,G.jsx)(Xo,{children:(0,G.jsx)(Ni,{defaultTheme:`system`,children:(0,G.jsx)(bl,{})})})}Ln.createRoot(R(document.getElementById(`root`))).render((0,G.jsx)(z.StrictMode,{children:(0,G.jsx)(xl,{})}));