@wrongstack/webui 0.155.0 → 0.250.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,93 +0,0 @@
1
- import{r as e}from"./rolldown-runtime-QTnfLwEv.js";import{$ as t,$t as n,A as r,At as i,B as a,Bt as o,C as s,Ct as c,D as l,Dt as u,E as d,Et as f,F as p,Ft as m,G as h,Gt as g,H as _,Ht as v,I as y,It as b,J as x,Jt as S,K as C,Kt as w,L as T,Lt as E,M as D,Mt as O,N as k,Nt as A,O as j,Ot as M,P as N,Pt as ee,Q as P,Qt as te,R as ne,Rt as F,S as I,St as re,T as ie,Tt as ae,U as oe,Ut as se,V as ce,Vt as L,W as le,Wt as ue,X as de,Xt as fe,Y as pe,Yt as me,Z as he,Zt as ge,_ as _e,_t as R,a as ve,an as ye,at as be,b as xe,bt as Se,c as Ce,cn as we,ct as Te,d as Ee,dn as De,dt as Oe,en as ke,et as Ae,f as je,fn as Me,ft as Ne,g as Pe,gt as Fe,h as Ie,ht as Le,i as Re,in as ze,it as Be,j as Ve,jt as He,k as Ue,kt as We,l as Ge,ln as Ke,lt as qe,m as Je,mt as Ye,n as Xe,nn as Ze,nt as Qe,o as $e,on as et,ot as tt,p as nt,pt as rt,q as it,qt as at,r as ot,rn as st,rt as ct,s as lt,sn as ut,st as dt,t as ft,tn as pt,tt as mt,u as ht,un as z,ut as gt,v as _t,vt,w as yt,wt as bt,x as xt,xt as St,y as Ct,yt as wt,z as Tt,zt as Et}from"./vendor-C1_detLm.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 B(e,t){if(e==null)throw Error(t?`Expected ${t} to be defined`:`Expected value to be defined`);return e}var V=e(Me(),1),Dt=e(De(),1),Ot=`#4f46e5`;function kt(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="${Ot}" />
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 At(e){return`data:image/svg+xml;charset=utf-8,${encodeURIComponent(e)}`}function jt(){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 Mt=`idle`;function Nt(e){Mt=e;let t=jt();t&&(t.href=At(kt(e)))}var Pt=!1;function Ft(){Pt||typeof document>`u`||(Pt=!0,document.addEventListener(`visibilitychange`,()=>{!document.hidden&&(Mt===`ready`||Mt===`error`||Mt===`attention`)&&Nt(`idle`)}))}var It=`ws_token`;function Lt(){try{return sessionStorage.getItem(It)}catch{return null}}function Rt(e){try{sessionStorage.setItem(It,e)}catch{}}function zt(){try{sessionStorage.removeItem(It)}catch{}}var Bt=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??Wt()}async connect(){return new Promise((e,t)=>{if(this.ws?.readyState===WebSocket.OPEN){e();return}this.setStatus({state:`connecting`});try{let n=Lt(),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,console.log(`[WS Client] Connected`),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(`[WS Client] Failed to parse message`,e)}},this.ws.onerror=e=>{console.error(`[WS Client] Error`,e),this.lastErrorText=`Connection error (see browser devtools)`,a||(clearTimeout(i),t(Error(this.lastErrorText)))},this.ws.onclose=e=>{if(console.log(`[WS Client] Disconnected`,e.code,e.reason),!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){console.log(`[WS Client] Not reconnecting`),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;console.log(`[WS Client] Reconnecting in ${e}ms (attempt ${this.reconnectAttempts})`),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(`[WS Client] Reconnect failed`,e)}},e)}retryNow(){this.currentStatus.state!==`open`&&(this.reconnectTimer&&=(clearTimeout(this.reconnectTimer),null),this.reconnectAttempts=0,this.connect().catch(e=>console.warn(`[ws-client] reconnect failed: ${e}`)))}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,t.wsToken&&Rt(t.wsToken)}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(`[WS Client] Handler error for ${e.type}`,t)}}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}})}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}})}newSession(){this.send({type:`session.new`})}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}})}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){this.send({type:`files.list`,payload:{query:e,limit:t}})}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})}listSessions(e=50){this.send({type:`sessions.list`,payload:{limit:e}})}deleteSession(e){this.send({type:`session.delete`,payload:{id:e}})}resumeSession(e){this.send({type:`session.resume`,payload:{id:e}})}ping(){this.send({type:`ping`})}disconnect(){this.shouldReconnect=!1,this.reconnectTimer&&=(clearTimeout(this.reconnectTimer),null),this.ws?.close(),this.ws=null,zt()}get isConnected(){return this.ws?.readyState===WebSocket.OPEN}get currentSessionId(){return this.sessionId}},Vt=null,Ht=3457;function Ut(){if(typeof document>`u`)return Ht;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:Ht}function Wt(){let e=Ut();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 H(e){return Vt||=new Bt(e),Vt}function Gt(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 U=z()(Ke((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: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:Gt(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:(t,n)=>{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}),B(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:()=>({})})),W=z()(Ke(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`})),G=z()(Ke(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:``,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,projectName:t.projectName??e.projectName,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:()=>({})})),K=z()(Ke(e=>({sidebarOpen:!0,settingsOpen:!1,currentView:`chat`,showConfirmDialog:!1,confirmInfo:null,paletteOpen:!1,shortcutsOpen:!1,searchOpen:!1,searchQuery:``,promptHistory:[],sidebarWidth:288,pinnedIds:[],compactMode:!1,modelSwitcherOpen:!1,favoriteSessionIds:[],sessionNicknames:{},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}),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(200,Math.min(480,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}})}),{name:`wrongstack-ui`,partialize:e=>({sidebarOpen:e.sidebarOpen,sidebarWidth:e.sidebarWidth,promptHistory:e.promptHistory,pinnedIds:e.pinnedIds,compactMode:e.compactMode,favoriteSessionIds:e.favoriteSessionIds,sessionNicknames:e.sessionNicknames})})),Kt=z()(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:[]})})),qt=z()(e=>({worktrees:[],baseBranch:``,activity:[],setSnapshot:(t,n)=>e({worktrees:t,baseBranch:n}),pushEvent:t=>e(e=>({activity:[...e.activity,t].slice(-40)}))}));function Jt(e,t){return{id:e,name:t?.trim()||e,status:`running`,iteration:0,toolCalls:0,costUsd:0,ctxPct:0,ctxTokens:0,maxContext:0,extensions:0,startedAt:Date.now(),toolLog:[]}}var Yt=z()(e=>({agents:new Map,clear:()=>e({agents:new Map}),applyEvent:t=>e(e=>{let n=new Map(e.agents),r={...n.get(t.subagentId)??Jt(t.subagentId,t.name)};switch(t.kind){case`spawned`:r.name=t.name?.trim()||r.name,r.provider=t.provider??r.provider,r.model=t.model??r.model,r.description=t.description??r.description,r.taskId=t.taskId??r.taskId,r.status=`running`;break;case`task_started`:r.description=t.description??r.description,r.taskId=t.taskId??r.taskId,r.status=`running`;break;case`tool_executed`:r.lastTool=t.toolName??r.lastTool,r.toolCalls+=1,r.toolLog=[{name:t.toolName??`unknown`,ok:typeof t.ok==`boolean`?t.ok:!0,durationMs:typeof t.durationMs==`number`?t.durationMs:0,at:Date.now()},...r.toolLog].slice(0,50);break;case`iteration_summary`:r.iteration=t.iteration??r.iteration,typeof t.toolCalls==`number`&&(r.toolCalls=t.toolCalls),typeof t.costUsd==`number`&&(r.costUsd=t.costUsd),r.currentTool=t.currentTool??r.currentTool,typeof t.partialText==`string`&&t.partialText&&(r.partialText=t.partialText);break;case`budget_extended`:r.extensions=t.totalExtensions??r.extensions+1;break;case`ctx_pct`:r.ctxPct=Math.round(Math.min(1,Math.max(0,t.load??0))*100),r.ctxTokens=t.tokens??r.ctxTokens,r.maxContext=t.maxContext??r.maxContext;break;case`task_completed`:r.status=t.status===`success`?`completed`:t.status??`completed`,typeof t.iterations==`number`&&(r.iteration=t.iterations),typeof t.toolCalls==`number`&&(r.toolCalls=t.toolCalls),r.error=t.error,r.currentTool=void 0,r.completedAt=Date.now(),typeof t.finalText==`string`&&t.finalText&&(r.finalText=t.finalText);break}return n.set(t.subagentId,r),{agents:n}})}));function Xt(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 Zt=z()(e=>({goal:null,setGoal:t=>e({goal:Xt(t)}),clear:()=>e({goal:null}),refresh:()=>{try{H()?.send?.({type:`goal.get`})}catch{}}})),Qt=z()(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})})),$t={autonomy:`off`,autonomyDelayMs:0,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:`balanced`,logLevel:`info`,auditLevel:`standard`},en=z()(Ke(e=>({...$t,set:t=>e(t),reset:()=>e($t)}),{name:`wrongstack-local-prefs`}));function q(...e){return ut(we(e))}var J=xt(),tn=z(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)}))})),nn={success:(e,t=3500)=>tn.getState().push({message:e,variant:`success`,ttl:t}),error:(e,t=6e3)=>tn.getState().push({message:e,variant:`error`,ttl:t}),warn:(e,t=4500)=>tn.getState().push({message:e,variant:`warn`,ttl:t}),info:(e,t=3500)=>tn.getState().push({message:e,variant:`info`,ttl:t}),dismiss:e=>tn.getState().dismiss(e)};function rn({variant:e}){return e===`success`?(0,J.jsx)(g,{className:`h-4 w-4 text-green-500`}):e===`error`?(0,J.jsx)(se,{className:`h-4 w-4 text-destructive`}):e===`warn`?(0,J.jsx)(Ve,{className:`h-4 w-4 text-amber-500`}):(0,J.jsx)(c,{className:`h-4 w-4 text-blue-500`})}function an({entry:e}){let t=tn(e=>e.dismiss);return(0,V.useEffect)(()=>{let n=setTimeout(()=>t(e.id),e.ttl);return()=>clearTimeout(n)},[e.id,e.ttl,t]),(0,J.jsxs)(`div`,{className:q(`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,J.jsx)(rn,{variant:e.variant}),(0,J.jsx)(`div`,{className:`flex-1 min-w-0 whitespace-pre-wrap break-words leading-snug`,children:e.message}),(0,J.jsx)(`button`,{type:`button`,onClick:()=>t(e.id),className:`text-muted-foreground hover:text-foreground`,title:`Dismiss`,children:(0,J.jsx)(s,{className:`h-3.5 w-3.5`})})]})}function on(){let e=tn(e=>e.toasts);return e.length===0?null:(0,J.jsx)(`div`,{className:`fixed bottom-4 right-4 z-[60] flex flex-col gap-2 pointer-events-auto`,children:e.map(e=>(0,J.jsx)(an,{entry:e},e.id))})}var sn=null;function cn(){if(typeof window>`u`)return null;if(sn)return sn;let e=window.AudioContext||window.webkitAudioContext;if(!e)return null;try{sn=new e}catch{return null}return sn}function ln(e,t,n){let r=cn();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 un(){ln(659.25,0,.18),ln(880,.12,.24)}function dn(){ln(523.25,0,.15),ln(659.25,.1,.15),ln(783.99,.2,.25)}var fn=`default`;fn=typeof window<`u`&&`Notification`in window?Notification.permission:`unsupported`;async function pn(){if(fn===`unsupported`||fn===`granted`||fn===`denied`)return fn;try{let e=await Notification.requestPermission();return fn=e,e}catch{return`denied`}}function mn(e,t,n){if(!(typeof document>`u`||!document.hidden)&&fn===`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 hn(e){let t=e.payload,n=G.getState().session?.id,r=!n||n!==t.sessionId;G.getState().startSession({id:t.sessionId,startedAt:Date.now(),model:t.model,provider:t.provider}),G.getState().setEnv({maxContext:t.maxContext,projectName:t.projectName,mode:t.mode,contextMode:t.contextMode,inputCost:t.inputCost,outputCost:t.outputCost,cacheReadCost:t.cacheReadCost}),W.getState().setConfig({provider:t.provider,model:t.model}),(r||t.reset)&&(U.getState().clearMessages(),Yt.getState().clear());let i=t.replayMessages;if(i&&i.length>0){let e=U.getState();for(let t of i)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 r of t.content)if(r.type===`text`&&typeof r.text==`string`)n+=(n?`
10
- `:``)+r.text;else if(r.type===`tool_use`)n&&=(e.addMessage({role:t.role,content:n}),``),e.addMessage({role:`tool`,content:``,toolName:String(r.name??`tool`),toolInput:r.input,toolUseId:String(r.id??``)});else if(r.type===`tool_result`){let t=U.getState().messages,n;for(let e=t.length-1;e>=0;e--)if(t[e]?.toolUseId===String(r.tool_use_id??``)){n=B(t[e]);break}n&&e.setToolResult(n.id,typeof r.content==`string`?r.content:JSON.stringify(r.content),!r.is_error)}}n&&e.addMessage({role:t.role,content:n})}}}function gn(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);U.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(`
11
- `)})}function _n(e){let t=e.payload;t.success?nn.success(t.message):nn.error(t.message),H(W.getState().wsUrl).listSavedProviders()}function vn(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`),U.getState().addMessage({role:`assistant`,content:`🗜️ Context compacted: ${t.before} → ${t.after} tokens (saved ~${t.saved}). ${n}`}),G.setState({lastInputTokens:t.after})}function yn(e){let t=e.payload,n=t.usage,r=(n.input??0)+(n.cacheWrite??0)-(n.cacheRead??0);r>0&&G.setState({lastInputTokens:r}),G.getState().updateUsage(t.usage);let{inputCost:i,outputCost:a,cacheReadCost:o}=G.getState(),s=(t.usage.input*i+t.usage.output*a+(t.usage.cacheRead??0)*o)/1e6;s>0&&G.getState().addCost(s),t.stopReason!==`tool_use`&&t.stopReason!==`tool_call`&&U.getState().setLoading(!1);let c=U.getState().currentAssistantMessageId;c&&(U.getState().finalizeMessage(c),t.usage.output>0&&U.getState().updateMessage(c,{usage:t.usage})),U.getState().setCurrentAssistantMessage(null),U.getState().clearThinking()}function bn(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}.`:``;U.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 xn(){W.getState().setWsConnected(!1)}function Sn(e){let t=e.payload;G.getState().setIteration({index:t.index,max:t.maxIterations??0}),U.getState().setLoading(!0),typeof document<`u`&&document.hidden&&Nt(`running`),U.getState().runStart===null&&U.getState().setRunStart({at:Date.now(),cost:G.getState().cost}),U.getState().setCurrentAssistantMessage(null)}function Cn(e){let t=e.payload;U.getState().clearThinking();let n=U.getState().currentAssistantMessageId;n||(n=U.getState().addMessage({role:`assistant`,content:``,streaming:!0}),U.getState().setCurrentAssistantMessage(n)),U.getState().appendToMessage(n,t.text)}function wn(e){let t=e.payload;t.text&&U.getState().appendThinking(t.text)}function Tn(e){let t=e.payload,n=U.getState().messages.find(e=>e.toolUseId===t.id);if(n){U.getState().setCurrentToolId(n.id);return}U.getState().clearThinking(),U.getState().setCurrentAssistantMessage(null);let r=U.getState().addMessage({role:`tool`,content:``,toolName:t.name,toolInput:t.input,toolUseId:t.id});U.getState().setCurrentToolId(r),U.getState().addExecution({id:t.id,name:t.name,input:t.input,ok:!0,startedAt:Date.now()})}function En(e){let t=e.payload,n=(t.event?.text??``).trim();if(!n)return;let r=U.getState().messages.find(e=>e.toolUseId===t.id);if(!r)return;let i=t.event?.type===`warning`?`⚠ `:``;U.getState().appendToolProgress(r.id,i+n)}function Dn(e){let t=e.payload,{messages:n,currentToolId:r}=U.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&&(U.getState().setToolResult(i.id,t.output??``,t.ok),U.getState().updateMessage(i.id,{toolDurationMs:t.durationMs})),t.id&&U.getState().updateExecution(t.id,{completedAt:Date.now(),durationMs:t.durationMs,output:t.output,ok:t.ok}),r&&i&&i.id===r&&U.getState().setCurrentToolId(null))}function On(e){let t=e.payload;K.getState().showConfirm({id:t.id,toolName:t.toolName,input:t.input,suggestedPattern:t.suggestedPattern});try{dn()}catch{}pn(),mn(`${G.getState().projectName||`Agent`} needs approval`,`Tool "${t.toolName}" is waiting for your decision.`,`agent-confirm`),typeof document<`u`&&document.hidden&&Nt(`attention`)}function kn(e){let t=e.payload;G.getState().setIteration(null),U.getState().setLoading(!1),U.getState().setCurrentAssistantMessage(null),U.getState().clearThinking();let n=U.getState().runStart;if(n&&t.status===`done`){let e=U.getState().messages,r=-1,i=0;for(let t=e.length-1;t>=0;t--){let a=B(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=G.getState().cost;U.getState().updateMessage(e[r]?.id,{runSummary:{iterations:t.iterations,tools:i,durationMs:Date.now()-n.at,costDelta:Math.max(0,a-n.cost)}})}}if(U.getState().setRunStart(null),t.status!==`done`&&t.error)U.getState().addMessage({role:`assistant`,content:`Error: ${t.error.message}`,isError:!0}),nn.error(`Run ended: ${t.error.message}`),mn(`${G.getState().projectName||`Agent`} run failed`,t.error.message),typeof document<`u`&&document.hidden&&Nt(`error`);else if(t.status===`done`&&(typeof document<`u`&&document.hidden&&(nn.success(`Run completed in ${t.iterations} iteration${t.iterations===1?``:`s`}`),mn(`${G.getState().projectName||`Agent`} run finished`,`Completed in ${t.iterations} iteration${t.iterations===1?``:`s`}.`),Nt(`ready`)),pn(),W.getState().soundOnComplete))try{un()}catch{}let r=U.getState().dequeue();if(r){let e=H(W.getState().wsUrl);U.getState().addMessage({role:`user`,content:r}),U.getState().setLoading(!0),e.sendMessage(r)}}function An(e){let t=e.payload;U.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(`
12
- `)})}function jn(e){let t=e.payload,n=t.text?.trim();U.getState().addMessage({role:`assistant`,content:t.error?`Memory read failed: ${t.error}`:n?`🧠 **Memory** \n\n${n}`:`🧠 **Memory**
13
-
14
- _empty — nothing remembered yet_`})}function Mn(e){let t=e.payload;if(!t.enabled){U.getState().addMessage({role:`assistant`,content:`🎯 **Skills**
15
-
16
- _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}`),U.getState().addMessage({role:`assistant`,content:n.join(`
17
- `)})}function Nn(e){let t=e.payload;U.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(`
18
- `)})}function Pn(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`;U.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(`
19
- `)})}function Fn(e){let t=e.payload;G.getState().setTodos(t.todos??[])}function In(e){let t=e.payload;G.getState().setModes(t.modes.map(e=>({id:e.id,name:e.name,description:e.description}))),G.getState().setEnv({mode:t.activeId})}function Ln(e){let t=e.payload;G.getState().setContextModes(t.modes.map(e=>({id:e.id,name:e.name,description:e.description,thresholds:e.thresholds,preserveK:e.preserveK,eliseThreshold:e.eliseThreshold}))),G.getState().setEnv({contextMode:t.activeId})}function Rn(e){let t=e.payload;G.getState().setEnv({contextMode:t.id})}function zn(e){let t=e.payload;Kt.getState().setEntries(t.sessions??[],t.error??null)}function Bn(e){let t=e.payload;U.getState().addMessage({role:`assistant`,content:`[${t.phase}] ${t.message}`,isError:!0}),U.getState().setLoading(!1)}function Vn(e){let t=e.payload;qt.getState().setSnapshot(t.worktrees??[],t.baseBranch??``)}function Hn(e){let t=e.payload;qt.getState().pushEvent(t)}function Un(e){Yt.getState().applyEvent(e.payload)}function Wn(e){let t=e.payload;Qt.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 Gn(e){let t=e.payload;Zt.getState().setGoal(t)}var Kn={"session.start":hn,"context.debug":gn,"key.operation_result":_n,"context.compacted":vn,"provider.response":yn,"context.repaired":bn,"session.end":xn,"iteration.started":Sn,"provider.text_delta":Cn,"provider.thinking_delta":wn,"tool.started":Tn,"tool.progress":En,"tool.executed":Dn,"tool.confirm_needed":On,"run.result":kn,"tools.list":An,"memory.list":jn,"skills.list":Mn,"diag.get":Nn,"stats.get":Pn,"todos.updated":Fn,"modes.list":In,"context.modes.list":Ln,"context.mode.changed":Rn,"sessions.list":zn,error:Bn,"worktree.state":Vn,"worktree.event":Hn,"subagent.event":Un,"goal.updated":Gn,"autophase.state":Wn,"session.checkpoints":e=>{},"process.list":e=>{}};function qn(e){let t=[];for(let[n,r]of Object.entries(Kn))t.push(e.on(n,r));return()=>{for(let e of t)e()}}function Jn(){let{autoConnect:e,wsUrl:t}=W(),n=W(e=>e.setWsStatus),r=(0,V.useRef)(!1);(0,V.useEffect)(()=>{if(!e)return;Ft();let i=H(t),a=i.onStatus(e=>n(e));if(i.connect().catch(e=>{console.error(`[WS] Connection failed:`,e)}),r.current)return()=>{a()};r.current=!0;let o=qn(i);return()=>{o(),a()}},[e,t,n])}function Y(){let{wsUrl:e}=W(),t=H(e),n=(0,V.useCallback)(e=>t.isConnected?t.sendMessage(e):null,[t]),r=(0,V.useCallback)(()=>t.sendAbort(),[t]),{hideConfirm:i}=K();return{client:t,sendMessage:n,sendAbort:r,sendConfirm:(0,V.useCallback)((e,n)=>{t.sendConfirm(e,n),i()},[t,i]),switchModel:(0,V.useCallback)((e,n)=>t.switchModel(e,n),[t]),listProviders:(0,V.useCallback)(()=>t.listProviders(),[t]),listProviderModels:(0,V.useCallback)(e=>t.listProviderModels(e),[t]),listSavedProviders:(0,V.useCallback)(()=>t.listSavedProviders(),[t]),addKey:(0,V.useCallback)((e,n,r)=>t.addKey(e,n,r),[t]),updateKey:(0,V.useCallback)((e,n,r)=>t.updateKey(e,n,r),[t]),deleteKey:(0,V.useCallback)((e,n)=>t.deleteKey(e,n),[t]),setActiveKey:(0,V.useCallback)((e,n)=>t.setActiveKey(e,n),[t]),addProvider:(0,V.useCallback)((e,n,r,i)=>t.addProvider(e,n,r,i),[t]),removeProvider:(0,V.useCallback)(e=>t.removeProvider(e),[t]),listSessions:(0,V.useCallback)(e=>{Kt.getState().setLoading(!0),t.listSessions(e)},[t]),deleteSession:(0,V.useCallback)(e=>{Kt.getState().removeEntry(e),t.deleteSession(e)},[t]),resumeSession:(0,V.useCallback)(e=>t.resumeSessionById(e),[t]),saveSession:(0,V.useCallback)(()=>t.saveSession(),[t]),listTools:(0,V.useCallback)(()=>t.listTools(),[t]),listMemory:(0,V.useCallback)(()=>t.listMemory(),[t]),listSkills:(0,V.useCallback)(()=>t.listSkills(),[t]),getDiag:(0,V.useCallback)(()=>t.getDiag(),[t]),getStats:(0,V.useCallback)(()=>t.getStats(),[t]),listModes:(0,V.useCallback)(()=>t.listModes(),[t]),switchMode:(0,V.useCallback)(e=>t.switchMode(e),[t]),listContextModes:(0,V.useCallback)(()=>t.listContextModes(),[t]),switchContextMode:(0,V.useCallback)(e=>t.switchContextMode(e),[t]),repairContext:(0,V.useCallback)(()=>t.repairContext(),[t]),toggleAutoPhaseAutonomous:(0,V.useCallback)(e=>{t.send({type:`autophase.toggleAutonomous`,payload:{autonomous:e}})},[t]),startAutoPhase:(0,V.useCallback)((e,n,r=!0)=>{t.send({type:`autophase.start`,payload:{title:e,phases:n,autonomous:r}})},[t]),pauseAutoPhase:(0,V.useCallback)(()=>{t.send({type:`autophase.pause`,payload:{}})},[t]),resumeAutoPhase:(0,V.useCallback)(()=>{t.send({type:`autophase.resume`,payload:{}})},[t]),stopAutoPhase:(0,V.useCallback)(()=>{t.send({type:`autophase.stop`,payload:{}})},[t]),selectAutoPhase:(0,V.useCallback)(e=>{t.send({type:`autophase.selectPhase`,payload:{phaseId:e}})},[t])}}var Yn={pending:{icon:(0,J.jsx)(v,{className:`w-4 h-4`}),color:`text-slate-400`,bg:`bg-slate-100 dark:bg-slate-800`,label:`Pending`},ready:{icon:(0,J.jsx)(Ae,{className:`w-4 h-4`}),color:`text-blue-500`,bg:`bg-blue-50 dark:bg-blue-950`,label:`Ready`},running:{icon:(0,J.jsx)(L,{className:`w-4 h-4 animate-spin`}),color:`text-amber-500`,bg:`bg-amber-50 dark:bg-amber-950`,label:`Running`},paused:{icon:(0,J.jsx)(Be,{className:`w-4 h-4`}),color:`text-orange-500`,bg:`bg-orange-50 dark:bg-orange-950`,label:`Paused`},completed:{icon:(0,J.jsx)(g,{className:`w-4 h-4`}),color:`text-emerald-500`,bg:`bg-emerald-50 dark:bg-emerald-950`,label:`Completed`},failed:{icon:(0,J.jsx)(se,{className:`w-4 h-4`}),color:`text-red-500`,bg:`bg-red-50 dark:bg-red-950`,label:`Failed`},skipped:{icon:(0,J.jsx)(_,{className:`w-4 h-4`}),color:`text-slate-400`,bg:`bg-slate-100 dark:bg-slate-800`,label:`Skipped`}},Xn={critical:`bg-red-500`,high:`bg-orange-500`,medium:`bg-blue-500`,low:`bg-slate-400`};function Zn(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 Qn({phases:e,activePhaseId:t,onPhaseClick:n,overallPercent:r,autonomous:i,onToggleAutonomous:a,className:o}){return(0,J.jsxs)(`div`,{className:q(`flex flex-col h-full w-72 border-r border-border bg-card`,o),children:[(0,J.jsxs)(`div`,{className:`p-4 border-b border-border`,children:[(0,J.jsxs)(`div`,{className:`flex items-center justify-between mb-3`,children:[(0,J.jsx)(`h2`,{className:`text-sm font-semibold text-foreground`,children:`Phases`}),(0,J.jsx)(`button`,{type:`button`,onClick:a,className:q(`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 — pause`:`Autonomous mode inactive — start`,children:i?`● Auto`:`○ Manual`})]}),(0,J.jsxs)(`div`,{className:`space-y-1`,children:[(0,J.jsxs)(`div`,{className:`flex justify-between text-xs text-muted-foreground`,children:[(0,J.jsx)(`span`,{children:`Overall Progress`}),(0,J.jsxs)(`span`,{children:[r,`%`]})]}),(0,J.jsx)(`div`,{className:`h-2 bg-muted rounded-full overflow-hidden`,children:(0,J.jsx)(`div`,{className:`h-full bg-emerald-500 transition-all duration-500 rounded-full`,style:{width:`${r}%`}})})]})]}),(0,J.jsx)(`div`,{className:`flex-1 overflow-y-auto p-3 space-y-2`,children:e.map(e=>{let r=Yn[e.status];return(0,J.jsxs)(`button`,{type:`button`,onClick:()=>n?.(e.id),className:q(`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,J.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,J.jsx)(`span`,{className:q(`mt-0.5`,r.color),children:r.icon}),(0,J.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,J.jsx)(`div`,{className:q(`w-1.5 h-1.5 rounded-full`,Xn[e.priority])}),(0,J.jsx)(`span`,{className:`text-sm font-medium truncate`,children:e.name})]}),(0,J.jsx)(`p`,{className:`text-xs text-muted-foreground truncate mt-0.5`,children:e.description})]})]}),(0,J.jsxs)(`div`,{className:`mt-2 space-y-1`,children:[(0,J.jsxs)(`div`,{className:`flex justify-between text-xs`,children:[(0,J.jsxs)(`span`,{className:`text-muted-foreground`,children:[e.completedTasks,`/`,e.taskCount,` tasks`]}),(0,J.jsxs)(`span`,{className:`text-muted-foreground`,children:[e.progressPercent,`%`]})]}),(0,J.jsx)(`div`,{className:`h-1.5 bg-muted rounded-full overflow-hidden`,children:(0,J.jsx)(`div`,{className:q(`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,J.jsxs)(`div`,{className:`flex items-center gap-2 mt-2 text-xs text-muted-foreground`,children:[(0,J.jsxs)(`span`,{children:[`~`,e.estimateHours,`h`]}),e.actualDurationMs&&(0,J.jsxs)(`span`,{children:[`· `,Zn(e.actualDurationMs)]}),e.assignedAgents.length>0&&(0,J.jsxs)(`span`,{children:[`· `,e.assignedAgents.length,` agent`,e.assignedAgents.length===1?``:`s`]})]})]},e.id)})})]})}var $n={pending:{icon:(0,J.jsx)(v,{className:`w-4 h-4`}),color:`text-muted-foreground`,label:`Pending`},in_progress:{icon:(0,J.jsx)(L,{className:`w-4 h-4 animate-spin`}),color:`text-primary`,label:`In Progress`},blocked:{icon:(0,J.jsx)(Be,{className:`w-4 h-4`}),color:`text-[hsl(var(--warning))]`,label:`Blocked`},failed:{icon:(0,J.jsx)(se,{className:`w-4 h-4`}),color:`text-destructive`,label:`Failed`},review:{icon:(0,J.jsx)(pe,{className:`w-4 h-4`}),color:`text-[hsl(var(--info))]`,label:`Review`},completed:{icon:(0,J.jsx)(g,{className:`w-4 h-4`}),color:`text-[hsl(var(--success))]`,label:`Done`}},er={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`},tr={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 nr(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 rr({phaseName:e,phaseStatus:t,tasks:n,onTaskClick:r,onTaskStatusChange:i,className:a}){let o={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,J.jsxs)(`div`,{className:q(`flex flex-col h-full bg-background`,a),children:[(0,J.jsx)(`div`,{className:`p-4 border-b border-border`,children:(0,J.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,J.jsxs)(`div`,{children:[(0,J.jsx)(`h2`,{className:`text-lg font-semibold text-foreground`,children:e}),(0,J.jsxs)(`p`,{className:`text-sm text-muted-foreground mt-0.5`,children:[n.length,` tasks · `,n.filter(e=>e.status===`completed`).length,` completed`]})]}),(0,J.jsx)(`div`,{className:q(`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,J.jsx)(`div`,{className:`flex-1 overflow-y-auto p-4 space-y-6`,children:[`in_progress`,`pending`,`review`,`failed`,`completed`].map(e=>{let t=o[e];if(t.length===0)return null;let n={in_progress:`In Progress`,pending:`Pending`,review:`Review`,failed:`Failed`,completed:`Completed`}[e];return(0,J.jsxs)(`div`,{children:[(0,J.jsxs)(`h3`,{className:`text-xs font-semibold text-muted-foreground uppercase tracking-wider mb-2`,children:[n,` (`,t.length,`)`]}),(0,J.jsx)(`div`,{className:`space-y-2`,children:t.map(e=>{let t=$n[e.status];return(0,J.jsxs)(`button`,{type:`button`,onClick:()=>r?.(e.id),className:q(`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,J.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,J.jsx)(`span`,{className:q(`mt-0.5`,t.color),children:t.icon}),(0,J.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[(0,J.jsx)(`span`,{className:`text-sm font-medium`,children:e.title}),(0,J.jsx)(`span`,{className:q(`px-1.5 py-0.5 rounded text-[10px] font-medium`,er[e.priority]),children:e.priority}),(0,J.jsx)(`span`,{className:q(`px-1.5 py-0.5 rounded text-[10px] font-medium`,tr[e.type]),children:e.type})]}),(0,J.jsx)(`p`,{className:`text-xs text-muted-foreground mt-1 line-clamp-2`,children:e.description})]})]}),(0,J.jsxs)(`div`,{className:`flex items-center gap-3 mt-2 text-xs text-muted-foreground`,children:[e.estimateHours&&(0,J.jsxs)(`span`,{children:[`~`,e.estimateHours,`h`]}),e.actualHours&&(0,J.jsxs)(`span`,{children:[`• `,e.actualHours,`h`]}),e.assignee&&(0,J.jsxs)(`span`,{children:[`• `,e.assignee]}),e.startedAt&&(0,J.jsxs)(`span`,{children:[`• `,nr(Date.now()-e.startedAt)]})]}),e.tags.length>0&&(0,J.jsx)(`div`,{className:`flex flex-wrap gap-1 mt-2`,children:e.tags.map(e=>(0,J.jsx)(`span`,{className:`px-1.5 py-0.5 rounded text-[10px] bg-muted text-muted-foreground`,children:e},e))}),i&&e.status!==`completed`&&(0,J.jsxs)(`div`,{className:`flex gap-1 mt-2`,children:[e.status!==`in_progress`&&(0,J.jsx)(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),i(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,J.jsx)(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),i(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,J.jsx)(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),i(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 ir=[`#3b82f6`,`#06b6d4`,`#22c55e`,`#eab308`,`#f97316`,`#a855f7`,`#ec4899`],ar=e=>e.replace(/^wstack\/ap\//,``);function or(e){return[...e].sort((e,t)=>e.allocatedAt-t.allocatedAt).map((e,t)=>({handle:e,color:ir[t%ir.length],y:60+t*48}))}var sr={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 cr({worktrees:e,baseBranch:t}){let n=or(e),r=Math.max(120,60+n.length*48+20);return(0,J.jsx)(`div`,{className:`overflow-x-auto rounded-lg border border-[--color-border-dark] bg-[--color-card-dark]/40 p-3`,children:(0,J.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,J.jsx)(`title`,{children:`Worktree branch graph off ${t||`HEAD`}`}),(0,J.jsx)(`line`,{x1:40,y1:20,x2:40,y2:r-10,stroke:`#F93951`,strokeWidth:3}),(0,J.jsx)(`text`,{x:36,y:14,fontSize:11,fill:`#9ca3af`,children:t||`HEAD`}),(0,J.jsx)(`circle`,{cx:40,cy:20,r:5,fill:`#F93951`}),n.map(e=>{let n=sr[e.handle.status]??B(sr.active),r=e.handle.status===`merged`,i=e.handle.status===`needs-review`||e.handle.status===`failed`;return(0,J.jsxs)(`g`,{className:`transition-all duration-500`,children:[(0,J.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,J.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,J.jsx)(`circle`,{cx:220,cy:e.y,r:5,fill:i?`#e879f9`:e.color}),(0,J.jsx)(`text`,{x:232,y:e.y-6,fontSize:12,fill:`#e5e7eb`,fontFamily:`monospace`,children:ar(e.handle.branch)}),(0,J.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 lr={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 ur(e){return lr[e]??{icon:`?`,label:e,tint:`border-border`,dot:`bg-muted-foreground`}}var dr=e=>e.replace(/^wstack\/ap\//,``);function fr({worktrees:e,baseBranch:t}){if(e.length===0)return null;let n=[...e].sort((e,t)=>e.allocatedAt-t.allocatedAt);return(0,J.jsxs)(`div`,{className:`rounded-lg border bg-card/50 backdrop-blur-sm px-3 py-3`,children:[(0,J.jsxs)(`div`,{className:`mb-2 flex items-center gap-2 text-xs text-muted-foreground`,children:[(0,J.jsx)(`span`,{className:`font-semibold tracking-wide uppercase text-[10px]`,children:`Worktrees`}),(0,J.jsx)(`span`,{className:`opacity-60`,children:`· base`}),(0,J.jsx)(`code`,{className:`font-mono text-primary`,children:t||`HEAD`}),(0,J.jsxs)(`span`,{className:`opacity-60`,children:[`· `,n.length,` isolated`]})]}),(0,J.jsx)(`div`,{className:`flex flex-col gap-1.5`,children:n.map(e=>{let t=ur(e.status),n=e.status===`needs-review`,r=Math.min(100,e.insertions+e.deletions);return(0,J.jsxs)(`div`,{className:q(`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,J.jsx)(`span`,{className:q(`h-2.5 w-2.5 shrink-0 rounded-full`,t.dot),"aria-hidden":!0}),(0,J.jsx)(`code`,{className:`w-44 shrink-0 truncate font-mono text-sm`,children:dr(e.branch)}),(0,J.jsxs)(`span`,{className:`shrink-0 rounded bg-muted px-2 py-0.5 text-xs text-muted-foreground`,children:[`⟵ `,e.ownerLabel]}),n?(0,J.jsx)(`span`,{className:`font-mono text-xs font-bold text-fuchsia-400`,children:`CONFLICT`}):(0,J.jsxs)(`span`,{className:`flex items-center gap-1 font-mono text-xs transition-all duration-500`,children:[(0,J.jsxs)(`span`,{className:`text-emerald-500`,children:[`+`,e.insertions]}),(0,J.jsx)(`span`,{className:`text-muted-foreground`,children:`·`}),(0,J.jsxs)(`span`,{className:`text-rose-500`,children:[`-`,e.deletions]}),(0,J.jsxs)(`span`,{className:`ml-1 text-muted-foreground`,children:[e.files,`f`]})]}),(0,J.jsx)(`div`,{className:`ml-auto hidden h-1 w-24 overflow-hidden rounded-full bg-muted sm:block`,children:(0,J.jsx)(`div`,{className:`h-full bg-gradient-to-r from-emerald-500 to-rose-500 transition-all duration-700`,style:{width:`${r}%`}})}),(0,J.jsx)(`span`,{className:`w-20 shrink-0 text-right text-xs text-muted-foreground`,children:t.label}),e.recentActivity.length>0?(0,J.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 pr=Ct(`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`}}),X=V.forwardRef(({className:e,variant:t,size:n,asChild:r=!1,...i},a)=>(0,J.jsx)(r?xe:`button`,{className:q(pr({variant:t,size:n,className:e})),ref:a,...i}));X.displayName=`Button`;function mr({onClose:e}){let{client:t}=Y(),n=Qt(e=>e.phases),r=Qt(e=>e.activePhaseId),i=Qt(e=>e.overallPercent),a=Qt(e=>e.autonomous),o=Qt(e=>e.title),c=qt(e=>e.worktrees),l=qt(e=>e.baseBranch),[u,d]=(0,V.useState)(!1),f=(0,V.useCallback)(e=>{t?.send?.({type:`autophase.selectPhase`,payload:{phaseId:e}})},[t]),p=(0,V.useCallback)(()=>{t?.send?.({type:`autophase.toggleAutonomous`,payload:{}})},[t]),m=(0,V.useCallback)((e,n)=>{t?.send?.({type:`autophase.taskStatus`,payload:{taskId:e,status:n}})},[t]),h=n.find(e=>e.id===r),g=h?h.tasks??[]:[];return(0,J.jsxs)(`div`,{className:`flex flex-col h-full bg-background`,children:[(0,J.jsxs)(`header`,{className:`flex items-center justify-between px-4 py-2 border-b bg-card shrink-0`,children:[(0,J.jsxs)(`div`,{children:[(0,J.jsx)(`h1`,{className:`text-lg font-semibold`,children:o||`AutoPhase`}),n.length>0&&(0,J.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[n.length,` phase`,n.length===1?``:`s`,` · `,i,`% complete`]})]}),(0,J.jsx)(X,{variant:`ghost`,size:`icon`,onClick:e,children:(0,J.jsx)(s,{className:`h-4 w-4`})})]}),(0,J.jsxs)(`div`,{className:`flex min-h-0 flex-1`,children:[(0,J.jsx)(Qn,{phases:n,activePhaseId:r??void 0,onPhaseClick:f,overallPercent:i,autonomous:a,onToggleAutonomous:p,className:`w-72 shrink-0`}),(0,J.jsx)(`div`,{className:`flex min-w-0 flex-1 flex-col`,children:h?(0,J.jsx)(rr,{phaseName:h.name,phaseStatus:h.status,tasks:g.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:m}):(0,J.jsx)(`div`,{className:`flex h-full items-center justify-center text-muted-foreground`,children:(0,J.jsx)(`p`,{className:`text-sm`,children:`Select a phase from the left panel to view its tasks.`})})})]}),c.length>0&&(0,J.jsxs)(`div`,{className:`border-t bg-card/50 shrink-0`,children:[(0,J.jsxs)(`div`,{className:`flex items-center justify-end gap-2 px-4 pt-2 text-xs`,children:[(0,J.jsx)(`button`,{type:`button`,onClick:()=>d(!1),className:q(`rounded px-2 py-0.5 border transition-colors`,u?`border-border text-muted-foreground hover:text-foreground`:`bg-primary/10 border-primary/30 text-primary`),children:`Lanes`}),(0,J.jsx)(`button`,{type:`button`,onClick:()=>d(!0),className:q(`rounded px-2 py-0.5 border transition-colors`,u?`bg-primary/10 border-primary/30 text-primary`:`border-border text-muted-foreground hover:text-foreground`),children:`Graph`})]}),(0,J.jsx)(`div`,{className:`px-4 pb-3`,children:u?(0,J.jsx)(cr,{worktrees:c,baseBranch:l}):(0,J.jsx)(fr,{worktrees:c,baseBranch:l})})]})]})}var hr=[{mode:`off`,label:`Off`,description:`Full manual control — agent waits for your input.`,icon:(0,J.jsx)(Be,{className:`h-3.5 w-3.5`})},{mode:`suggest`,label:`Suggest`,description:`Agent suggests next steps but waits for approval.`,icon:(0,J.jsx)(st,{className:`h-3.5 w-3.5`})},{mode:`auto`,label:`Auto`,description:`Agent auto-proceeds after brief confirmation delay.`,icon:(0,J.jsx)(Ae,{className:`h-3.5 w-3.5`})},{mode:`eternal`,label:`Eternal`,description:`Agent runs autonomously until goal is complete.`,icon:(0,J.jsx)(et,{className:`h-3.5 w-3.5`})},{mode:`eternal-parallel`,label:`Eternal Parallel`,description:`Multi-agent autonomous execution — fleet mode.`,icon:(0,J.jsx)(et,{className:`h-3.5 w-3.5`})}];function gr({value:e,onChange:t,className:n,compact:r=!1}){let[i,a]=(0,V.useState)(!1),o=(0,V.useRef)(null);(0,V.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,V.useEffect)(()=>{if(!i)return;let e=e=>{e.key===`Escape`&&a(!1)};return document.addEventListener(`keydown`,e),()=>document.removeEventListener(`keydown`,e)},[i]);let s=hr.find(t=>t.mode===e);return(0,J.jsxs)(`div`,{ref:o,className:`relative`,children:[(0,J.jsxs)(`button`,{type:`button`,onClick:()=>a(e=>!e),className:q(`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,J.jsx)(`span`,{className:`truncate max-w-[7rem]`,children:s?.label??e}),(0,J.jsx)(me,{className:`h-3 w-3 opacity-60`})]}),i&&(0,J.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,J.jsx)(`div`,{className:`px-3 py-1.5 text-[10px] uppercase tracking-wider text-muted-foreground border-b mb-1`,children:`Autonomy Mode`}),hr.map(n=>(0,J.jsxs)(`button`,{type:`button`,onClick:()=>{t(n.mode),a(!1)},className:q(`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,J.jsx)(`span`,{className:`mt-0.5 text-muted-foreground`,children:n.icon}),(0,J.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,J.jsx)(`span`,{className:`text-sm font-medium`,children:n.label}),(0,J.jsx)(`p`,{className:`text-[10px] text-muted-foreground leading-snug`,children:n.description})]}),e===n.mode&&(0,J.jsx)(`span`,{className:`h-1.5 w-1.5 rounded-full bg-primary mt-2 shrink-0`})]},n.mode))]})]})}function _r(){let e=U.getState().messages,t=[],n=new Date().toISOString().slice(0,19).replace(/[:T]/g,`-`),r=G.getState().projectName||`chat`,i=G.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(`
20
- `)],{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 vr(){let e=U.getState().messages,t=G.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`
21
- <section class="bubble tool ${e.isError?`error`:``}">
22
- <header><span class="icon">🔧</span><code>${a(e.toolName??`tool`)}</code> ${t}</header>
23
- ${e.toolInput===void 0?``:`<details><summary>Input</summary><pre>${a(JSON.stringify(e.toolInput,null,2))}</pre></details>`}
24
- ${e.toolResult?`<details><summary>Output</summary><pre>${a(e.toolResult)}</pre></details>`:``}
25
- </section>`}return`
26
- <section class="bubble ${e.role===`user`?`user`:`assistant`}">
27
- <header><span class="icon">${e.role===`user`?`👤`:`🤖`}</span><strong>${e.role===`user`?`User`:`Assistant`}</strong></header>
28
- <pre class="content">${a(e.content)}</pre>
29
- </section>`}),s=`<!doctype html>
30
- <html lang="en"><head>
31
- <meta charset="utf-8">
32
- <title>${r} — chat export</title>
33
- <style>
34
- :root { color-scheme: light dark; }
35
- body { font: 14px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; max-width: 920px; margin: 24px auto; padding: 0 16px; }
36
- h1 { font-size: 20px; margin-bottom: 4px; }
37
- .meta { color: #666; font-size: 12px; margin-bottom: 24px; }
38
- .bubble { margin: 12px 0; padding: 10px 14px; border-radius: 10px; border: 1px solid #ddd; }
39
- .bubble header { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: #666; margin-bottom: 6px; }
40
- .bubble header .icon { margin-right: 4px; }
41
- .bubble.user { background: #eef4ff; border-color: #c8d8f5; }
42
- .bubble.assistant { background: #fff; }
43
- .bubble.tool { background: #fafafa; }
44
- .bubble.tool.error { background: #fff5f5; border-color: #f5c8c8; }
45
- pre.content, .bubble pre { white-space: pre-wrap; word-break: break-word; font: 12px/1.5 ui-monospace, Menlo, Consolas, monospace; margin: 0; }
46
- details summary { cursor: pointer; color: #555; font-size: 12px; }
47
- details pre { margin-top: 6px; background: #f4f4f4; padding: 8px; border-radius: 6px; max-height: 360px; overflow: auto; }
48
- @media (prefers-color-scheme: dark) {
49
- body { background: #0d0d0f; color: #e6e6e6; }
50
- .bubble { border-color: #2a2a2e; }
51
- .bubble.user { background: #16213a; border-color: #2a3d6b; }
52
- .bubble.assistant { background: #161618; }
53
- .bubble.tool { background: #131315; }
54
- .bubble.tool.error { background: #2a1717; border-color: #5c2a2a; }
55
- details pre { background: #1a1a1c; }
56
- .meta, .bubble header, details summary { color: #999; }
57
- }
58
- </style>
59
- </head><body>
60
- <h1>${r} — chat export</h1>
61
- <div class="meta">
62
- Exported ${new Date().toISOString()}${t.session?.provider?` · ${escape(t.session.provider)}/${escape(t.session.model)}`:``} · ${e.length} message${e.length===1?``:`s`}
63
- </div>
64
- ${o.join(``)}
65
- </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 yr(){let e=K(e=>e.paletteOpen),t=K(e=>e.setPaletteOpen),r=K(e=>e.setCurrentView),i=W(e=>e.setTheme),{entries:a}=Kt(),{addMessage:o,clearMessages:s}=U(),c=Y(),[u,d]=(0,V.useState)(``),[f,p]=(0,V.useState)(0),m=(0,V.useRef)(null);(0,V.useEffect)(()=>{e&&(d(``),p(0),requestAnimationFrame(()=>m.current?.focus()))},[e]),(0,V.useEffect)(()=>{let e=e=>{if((e.ctrlKey||e.metaKey)&&e.key.toLowerCase()===`k`){e.preventDefault(),t(!K.getState().paletteOpen);return}e.key===`Escape`&&K.getState().paletteOpen&&(e.preventDefault(),t(!1))};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[t]);let h=(0,V.useMemo)(()=>{let e=[{id:`help`,category:`Command`,label:`Show slash commands`,icon:ae,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:yt,keywords:[`tools`,`list`],run:()=>c.listTools()},{id:`memory`,category:`Command`,label:`Show memory`,icon:n,keywords:[`memory`,`remember`,`notes`],run:()=>c.listMemory()},{id:`skills`,category:`Command`,label:`List skills`,icon:ce,keywords:[`skills`],run:()=>c.listSkills()},{id:`diag`,category:`Command`,label:`Runtime diagnostics`,icon:ne,keywords:[`diag`,`diagnostics`,`debug`],run:()=>c.getDiag()},{id:`stats`,category:`Command`,label:`Session stats (tokens, cache, cost)`,icon:ge,keywords:[`stats`,`tokens`,`cost`,`cache`],run:()=>c.getStats()},{id:`clear`,category:`Session`,label:`Clear context`,hint:`Wipe in-memory context, keep session id`,icon:N,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?.()},{id:`compact`,category:`Session`,label:`Compact context`,icon:E,keywords:[`compact`,`shrink`,`context`],run:()=>c.client?.compactContext?.()},{id:`repair-context`,category:`Session`,label:`Repair context`,hint:`Remove orphan tool protocol blocks`,icon:yt,keywords:[`repair`,`context`,`tool_use`,`tool_result`],run:()=>c.client?.repairContext?.()},{id:`export`,category:`Session`,label:`Export chat as markdown`,icon:b,keywords:[`export`,`save`,`markdown`,`download`],run:()=>_r()},{id:`export-html`,category:`Session`,label:`Export chat as HTML`,hint:`Self-contained, opens in any browser`,icon:b,keywords:[`export`,`html`,`download`,`archive`],run:()=>vr()},{id:`history`,category:`Command`,label:`Open history`,icon:bt,keywords:[`history`,`sessions`],run:()=>r(`history`)},{id:`settings`,category:`Command`,label:`Open settings`,icon:C,keywords:[`settings`,`config`],run:()=>r(`settings`)},{id:`model`,category:`Command`,label:`Change provider/model`,icon:F,keywords:[`model`,`provider`,`change`],run:()=>r(`settings`)},{id:`theme-light`,category:`Theme`,label:`Theme: Light`,icon:T,keywords:[`theme`,`light`,`mode`],run:()=>i(`light`)},{id:`theme-dark`,category:`Theme`,label:`Theme: Dark`,icon:qe,keywords:[`theme`,`dark`,`mode`],run:()=>i(`dark`)},{id:`theme-system`,category:`Theme`,label:`Theme: Follow system`,icon:gt,keywords:[`theme`,`system`,`auto`],run:()=>i(`system`)},{id:`compact-toggle`,category:`Command`,label:`Toggle compact density`,icon:Ye,hint:`Ctrl+Shift+D`,keywords:[`compact`,`dense`,`density`,`size`],run:()=>K.getState().toggleCompactMode()},{id:`sound-toggle`,category:`Command`,label:W.getState().soundOnComplete?`Sound on completion: ON — turn off`:`Sound on completion: OFF — turn on`,icon:W.getState().soundOnComplete?j:l,hint:`Chime when a run finishes`,keywords:[`sound`,`audio`,`chime`,`notify`,`beep`],run:()=>{let e=!W.getState().soundOnComplete;W.getState().setSoundOnComplete(e),e&&un()}}];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:ye,keywords:[`resume`,t.title,t.id,t.provider,t.model],run:()=>c.resumeSession(t.id)});return e},[a,c,r,i,o,s]),g=(0,V.useMemo)(()=>{let e=u.toLowerCase().trim();return e?h.filter(t=>[t.label,t.hint??``,t.category,...t.keywords??[]].join(` `).toLowerCase().includes(e)):h},[h,u]);if((0,V.useEffect)(()=>{f>=g.length&&p(0)},[g.length,f]),!e)return null;let _=e=>{e&&(t(!1),e.run())};return(0,J.jsx)(`div`,{className:`fixed inset-0 z-50 bg-background/60 backdrop-blur-sm flex items-start justify-center pt-[14vh] px-4`,onClick:()=>t(!1),onKeyDown:e=>{e.key===`Escape`&&t(!1)},children:(0,J.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,J.jsxs)(`div`,{className:`flex items-center gap-2 px-4 py-3 border-b`,children:[(0,J.jsx)(x,{className:`h-4 w-4 text-muted-foreground`}),(0,J.jsx)(`input`,{ref:m,value:u,onChange:e=>d(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(),p(e=>(e+1)%Math.max(1,g.length))):e.key===`ArrowUp`?(e.preventDefault(),p(e=>(e-1+Math.max(1,g.length))%Math.max(1,g.length))):e.key===`Enter`&&(e.preventDefault(),_(g[f]))}}),(0,J.jsx)(`kbd`,{className:`text-[10px] text-muted-foreground border rounded px-1.5 py-0.5`,children:`Esc`})]}),(0,J.jsx)(`div`,{className:`max-h-[60vh] overflow-y-auto`,children:g.length===0?(0,J.jsxs)(`div`,{className:`px-4 py-8 text-center text-sm text-muted-foreground`,children:[`No matches for "`,u,`"`]}):br(g,f,_,p)}),(0,J.jsxs)(`div`,{className:`border-t px-4 py-2 text-[10px] uppercase tracking-wider text-muted-foreground flex items-center gap-3`,children:[(0,J.jsx)(`span`,{children:`↑↓ navigate`}),(0,J.jsx)(`span`,{children:`↵ select`}),(0,J.jsx)(`span`,{children:`Esc dismiss`})]})]})})}function br(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,J.jsx)(`div`,{className:`p-1`,children:Object.entries(i).map(([e,i])=>(0,J.jsxs)(`div`,{children:[(0,J.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,J.jsxs)(`button`,{type:`button`,onMouseEnter:()=>r(i),onClick:()=>n(e),className:q(`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,J.jsx)(a,{className:`h-4 w-4 text-muted-foreground shrink-0`}),(0,J.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,J.jsx)(`div`,{className:`truncate`,children:e.label}),e.hint&&(0,J.jsx)(`div`,{className:`text-xs text-muted-foreground truncate`,children:e.hint})]}),o&&(0,J.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:`↵`})]},e.id)})]},e))})}function xr({query:e,onPick:t,onClose:n}){let r=Y(),i=W(e=>e.wsUrl),[a,o]=(0,V.useState)([]),[s,c]=(0,V.useState)(0),l=(0,V.useRef)(null),u=(0,V.useRef)(null);return(0,V.useEffect)(()=>{let e=H(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,V.useEffect)(()=>(l.current&&clearTimeout(l.current),l.current=setTimeout(()=>{r.client.listFiles(e,50)},80),()=>{l.current&&clearTimeout(l.current)}),[e,r.client]),(0,V.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(B(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,J.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,J.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,J.jsxs)(`span`,{children:[`@ Files `,e&&`· "${e}"`]}),(0,J.jsx)(`span`,{children:`↑/↓ select · ↵ insert · Esc dismiss`})]}),a.length===0?(0,J.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,J.jsxs)(`button`,{type:`button`,onClick:()=>t(e),onMouseEnter:()=>c(n),className:q(`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,J.jsx)(We,{className:`h-3.5 w-3.5 text-muted-foreground shrink-0`}):(0,J.jsx)(He,{className:`h-3.5 w-3.5 text-muted-foreground shrink-0`}),(0,J.jsx)(`span`,{className:`truncate`,children:e})]},e))]})}var Sr=[{name:`/abort`,category:`Run`,aliases:[`/stop`],description:`Abort the current run`},{name:`/dev`,category:`Run`,description:`Run a shell command and see the output (LLM does not see it)`},{name:`/commit`,category:`Run`,aliases:[`/gc`],description:`Generate a conventional commit message (LLM-powered)`},{name:`/gitcheck`,category:`Run`,aliases:[`/gcstatus`],description:`Pre-commit sanity check (branch, diff, lint)`},{name:`/push`,category:`Run`,description:`Push the current branch to remote`},{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:`/repair`,category:`Session`,description:`Repair orphan tool_use/tool_result blocks in context`},{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:`/prune`,category:`Session`,description:`Delete old sessions (default older than 30 days)`},{name:`/export`,category:`Session`,description:`Download the current chat as markdown`},{name:`/debug`,category:`Inspect`,aliases:[`/context`],description:`Per-section context size breakdown`},{name:`/tools`,category:`Inspect`,description:`List every registered tool the model can call`},{name:`/memory`,category:`Inspect`,description:`Manage memory: show, remember, forget, clear, compact, stats`},{name:`/skill`,category:`Inspect`,aliases:[`/skills`],description:`List active skills`},{name:`/diag`,category:`Inspect`,description:`Runtime diagnostics (provider, tools, features, mode, usage)`},{name:`/stats`,category:`Inspect`,description:`Session stats: tokens, cache hit ratio, cost, elapsed`},{name:`/todos`,category:`Inspect`,description:"List current todos (try `/todos clear` to reset)"},{name:`/codebase-reindex`,category:`Inspect`,aliases:[`/reindex`],description:`Rebuild the codebase symbol index`},{name:`/security`,category:`Inspect`,description:`Security scanning: /security scan | audit | report`},{name:`/metrics`,category:`Inspect`,description:`Show runtime metrics snapshot (requires --metrics)`},{name:`/health`,category:`Inspect`,description:`Show health check status`},{name:`/spawn`,category:`Agent`,description:`Spawn an isolated subagent to handle a task`},{name:`/agents`,category:`Agent`,description:`Show status of spawned subagents`},{name:`/fleet`,category:`Agent`,description:`Inspect and control the agent fleet`},{name:`/director`,category:`Agent`,description:`Promote to director mode at runtime`},{name:`/autonomy`,category:`Agent`,description:`Toggle or query autonomy mode (self-driving agent)`},{name:`/goal`,category:`Agent`,description:`Set, inspect, or clear the autonomous mission`},{name:`/autophase`,category:`Agent`,description:`Autonomous phase-based workflow with subagents`},{name:`/fix`,category:`Agent`,description:`Diagnose and fix a reported error or bug`},{name:`/sdd`,category:`Agent`,description:`AI-driven Specification-Driven Development workflow`},{name:`/btw`,category:`Agent`,description:`Drop a mid-run note without interrupting the agent`},{name:`/collab`,category:`Agent`,description:`Live collaboration helpers (status / invite / history)`},{name:`/prompts`,category:`Agent`,description:`Manage prompt library: list, view, add, delete, edit, extend`},{name:`/plan`,category:`Agent`,description:`Strategic plan board: show, add, start, done, promote, clear`},{name:`/skill-gen`,category:`Agent`,description:`Generate a new skill from a description (LLM-powered)`},{name:`/skill-install`,category:`Agent`,description:`Install a skill from GitHub (user/repo or URL)`},{name:`/skill-update`,category:`Agent`,description:`Update an installed skill to the latest version`},{name:`/skill-uninstall`,category:`Agent`,description:`Remove an installed skill`},{name:`/settings`,category:`Config`,aliases:[`/model`],description:`Open settings (provider/model/keys)`},{name:`/setmodel`,category:`Config`,description:`Quick-switch the active provider/model`},{name:`/models`,category:`Config`,description:`List available providers and models`},{name:`/mode`,category:`Config`,description:`Switch the active mode (persona/skill set)`},{name:`/yolo`,category:`Config`,description:`Toggle or query YOLO (auto-approve) mode`},{name:`/next`,category:`Config`,description:`Toggle next-task prediction after each turn`},{name:`/enhance`,category:`Config`,description:`Toggle prompt refinement before sending`},{name:`/mcp`,category:`Config`,aliases:[`/mcp-servers`],description:`Manage MCP servers`},{name:`/plugin`,category:`Config`,aliases:[`/plugins`],description:`Manage plugins`},{name:`/statusline`,category:`Config`,aliases:[`/sl`],description:`Customize status bar chips`},{name:`/telegram-setup`,category:`Config`,aliases:[`/tg-setup`],description:`Configure Telegram bot token and chat`},{name:`/init`,category:`Config`,description:`Create or update .wrongstack/AGENTS.md project context`},{name:`/worktree`,category:`Config`,aliases:[`/wt`],description:`Inspect/manage git worktrees for AutoPhase`},{name:`/sync`,category:`Config`,description:`GitHub cloud sync for settings, skills, prompts, memory`},{name:`/help`,category:`App`,description:`Show every slash command and what it does`},{name:`/exit`,category:`App`,description:`Exit the current session`}],Cr=[`Run`,`Session`,`Inspect`,`Agent`,`Config`,`App`];function wr(e){let t=e.toLowerCase();return t===`/`||t===``?Sr:Sr.filter(e=>e.name.startsWith(t)||(e.aliases?.some(e=>e.startsWith(t))??!1))}function Tr(e,t){let n=t-1;for(;n>=0;){let r=B(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}function Er(){let{isLoading:e,setLoading:t,addMessage:n,clearMessages:r}=U(),i=U(e=>e.queue),o=U(e=>e.enqueue),s=U(e=>e.removeQueued),c=U(e=>e.clearQueue),{setCurrentView:l}=K(),u=K(e=>e.pushPrompt),d=K(e=>e.promptHistory),f=Y(),{sendMessage:p,sendAbort:m,client:h}=f,g=G(e=>e.lastInputTokens),_=G(e=>e.maxContext),[v,y]=(0,V.useState)(``),[b,x]=(0,V.useState)(0),[S,C]=(0,V.useState)(-1),[w,T]=(0,V.useState)(null),[E,D]=(0,V.useState)(null),[O,k]=(0,V.useState)(!1),A=(0,V.useRef)(null),j=(0,V.useCallback)(e=>{let i=e.trim(),a=i.indexOf(` `),o=(a===-1?i:i.slice(0,a)).toLowerCase(),s=a===-1?``:i.slice(a+1).trim(),c=o;switch(c){case`/help`:return n({role:`assistant`,content:[`📖 **Slash commands**`,``,...Sr.map(e=>`• \`${e.name}\`${e.aliases?.length?` (${e.aliases.map(e=>`\`${e}\``).join(`, `)})`:``} — ${e.description}`)].join(`
66
- `)}),!0;case`/clear`:return r(),h?.clearContext?.(),!0;case`/new`:return h?.newSession?.(),!0;case`/compact`:case`/compact!`:return h?.compactContext?.(c===`/compact!`),!0;case`/repair`:return h?.repairContext?.(),!0;case`/debug`:case`/context`:return h?.debugContext?.(),!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`/todos`:{if(s.toLowerCase()===`clear`)return h?.clearTodos?.(),!0;let e=G.getState().todos;if(e.length===0)return n({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._"),n({role:`assistant`,content:t.join(`
67
- `)}),!0}case`/export`:return _r(),n({role:`assistant`,content:`📥 Chat exported to your downloads folder.`}),!0;case`/abort`:case`/stop`:return m(),t(!1),!0;case`/settings`:case`/model`:return l(`settings`),!0;case`/suggest`:case`/next-steps`:return P(`What are the next steps I should take? Be specific and actionable.`),!0;case`/next`:{let e=s.trim().toLowerCase();return!e||e===`list`||e===`ls`||e===`show`?te():e===`clear`||e===`reset`?(n({role:`assistant`,content:`💡 _Suggestion list cleared._`}),!0):ne(s.trim())}default:return!1}},[n,r,h,m,t,l,f]),M=/💡\s*Next steps?\s*\n+((?:\d+\.\s+.+\n?)+)/i;function N(e){let t=M.exec(e);if(!t?.[1])return[];let n=[];for(let e of t[1].split(`
68
- `).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 ee(){let e=U.getState().messages;for(let t=e.length-1;t>=0;t--){let n=e[t];if(n?.role===`assistant`&&n.content)return N(n.content)}return[]}function P(r){if(e){o(r);return}n({role:`user`,content:r}),p(r)&&t(!0)}function te(){let e=U.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 r=N(t);if(r.length===0)return n({role:`assistant`,content:"💡 _No next-step suggestions found. Use `/suggest` to generate some._"}),!0;let i=[`💡 **Next steps**`,``];for(let e of r)i.push(`${e.index}. ${e.text}`);return i.push(``,"_Use `/next 1`, `/next 1 2 3` to execute._"),n({role:`assistant`,content:i.join(`
69
- `)}),!0}function ne(e){let t=ee();if(t.length===0)return n({role:`assistant`,content:"💡 _No suggestions available. Use `/suggest` first._"}),!0;let r=e.split(/[\s,]+/).filter(Boolean).map(e=>Number.parseInt(e,10)).filter(e=>!Number.isNaN(e)&&e>0);if(r.length===0)return n({role:`assistant`,content:`💡 _No valid suggestion numbers._`}),!0;let i=r.filter(e=>e>t.length);if(i.length>0)return n({role:`assistant`,content:`💡 _Invalid suggestion(s): ${i.join(`, `)}. Valid range: 1–${t.length}._`}),!0;for(let e of r){let n=t[e-1];n&&P(n.text)}return!0}let F=v.startsWith(`/`)&&!v.includes(` `)?wr(v):[];(0,V.useEffect)(()=>{b>=F.length&&x(0)},[F.length,b]);let I=(0,V.useCallback)(()=>{let t=A.current;t&&(t.value=``,t.style.height=`auto`,t.style.height=`${Math.min(t.scrollHeight,200)}px`,e||t.focus())},[e]),re=(0,V.useCallback)(async r=>{if(r.preventDefault(),!v.trim())return;let i=v.trim();if(i.startsWith(`/`)&&j(i)){u(i),y(``),C(-1),I();return}if(y(``),C(-1),I(),u(i),I(),e){o(i);return}try{h?.isConnected?(n({role:`user`,content:i}),t(!0),p(i)):console.error(`WebSocket not connected`)}catch(e){console.error(`Failed to send:`,e),t(!1)}},[v,e,o,h,p,t,n,j,u,I]),ie=(0,V.useCallback)(()=>{m(),t(!1)},[m,t]),ae=(0,V.useCallback)(()=>{m(),t(!1);let e=U.getState().messages;for(let t=e.length-1;t>=0;t--){let n=B(e[t]);if(n.role===`user`&&n.content){y(n.content),requestAnimationFrame(()=>{let e=A.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,t]),oe=(0,V.useCallback)(e=>{if(F.length===0&&!w&&d.length>0){if(e.key===`ArrowUp`){let t=e.currentTarget,n=t.value.slice(0,t.selectionStart);if(S>=0||n.indexOf(`
70
- `)===-1){e.preventDefault();let t=Math.min(d.length-1,S+1);C(t);let n=d[t]??``;y(n),requestAnimationFrame(()=>{let e=A.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`&&S>=0){e.preventDefault();let t=S-1;if(t<0)C(-1),y(``);else{C(t);let e=d[t]??``;y(e),requestAnimationFrame(()=>{let t=A.current;t&&(t.style.height=`auto`,t.style.height=`${Math.min(t.scrollHeight,200)}px`,t.setSelectionRange(e.length,e.length))})}return}}if(F.length>0){if(e.key===`ArrowDown`){e.preventDefault(),x(e=>(e+1)%F.length);return}if(e.key===`ArrowUp`){e.preventDefault(),x(e=>(e-1+F.length)%F.length);return}if(e.key===`Tab`){e.preventDefault();let t=F[b];t&&(y(t.name+` `),x(0));return}if(e.key===`Enter`&&!e.shiftKey){let t=F[b];if(t&&t.name!==v.toLowerCase().trim()){e.preventDefault(),y(``),j(t.name);return}}if(e.key===`Escape`){e.preventDefault(),y(``);return}}e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),re(e))},[F,b,w,d,S,v,j,re]),se=()=>{let e=A.current;e&&(e.style.height=`auto`,e.style.height=`${Math.min(e.scrollHeight,200)}px`)};return(0,J.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[E&&(0,J.jsxs)(`div`,{className:`rounded-md border border-amber-500/30 bg-amber-500/5 text-amber-700 dark:text-amber-300 px-2.5 py-1.5 text-xs flex items-center justify-between gap-2 animate-message`,children:[(0,J.jsxs)(`span`,{children:[`Pasted`,` `,(0,J.jsx)(`span`,{className:`font-mono tabular-nums`,children:E.chars.toLocaleString()}),` chars (`,(0,J.jsx)(`span`,{className:`font-mono tabular-nums`,children:E.lines}),` lines) — fenced code blocks render best with `,(0,J.jsx)(`span`,{className:`font-mono`,children:"```"}),`.`]}),(0,J.jsx)(`button`,{type:`button`,onClick:()=>D(null),className:`text-amber-600/70 hover:text-amber-600 dark:text-amber-300/70 dark:hover:text-amber-300 shrink-0`,title:`Dismiss`,children:`×`})]}),i.length>0&&(0,J.jsxs)(`div`,{className:`rounded-lg border bg-muted/30 p-2 text-xs`,children:[(0,J.jsxs)(`div`,{className:`flex items-center justify-between mb-1.5`,children:[(0,J.jsxs)(`span`,{className:`text-[10px] uppercase tracking-wider text-muted-foreground font-medium`,children:[`Queued (`,i.length,`)`]}),(0,J.jsx)(`button`,{type:`button`,onClick:c,className:`text-muted-foreground hover:text-destructive text-xs`,children:`Clear all`})]}),(0,J.jsx)(`ul`,{className:`space-y-1`,children:i.map((e,t)=>(0,J.jsxs)(`li`,{className:`flex items-start justify-between gap-2 rounded bg-background/60 border px-2 py-1`,children:[(0,J.jsx)(`span`,{className:`truncate flex-1 min-w-0`,children:e}),(0,J.jsx)(`button`,{type:`button`,onClick:()=>s(t),className:`text-muted-foreground hover:text-destructive shrink-0`,title:`Remove from queue`,children:`×`})]},t))})]}),(0,J.jsxs)(`form`,{onSubmit:re,onDragEnter:e=>{!e.dataTransfer||!Array.from(e.dataTransfer.types).includes(`Files`)||(e.preventDefault(),k(!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)||k(!1)},onDrop:e=>{if(!e.dataTransfer)return;let t=Array.from(e.dataTransfer.files??[]);if(t.length===0){k(!1);return}e.preventDefault(),k(!1);let n=A.current,r=n?.selectionStart??v.length,i=v.slice(0,r),a=v.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}`;y(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`}T({start:d,query:f})})},className:q(`flex items-end gap-2 relative rounded-lg transition-colors`,O&&`ring-2 ring-primary ring-offset-2 ring-offset-background bg-primary/5`),children:[O&&(0,J.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,J.jsxs)(`div`,{className:`relative flex-1`,children:[w&&(0,J.jsx)(xr,{query:w.query,onClose:()=>T(null),onPick:e=>{let t=v.slice(0,w.start),n=v.slice(w.start+1+w.query.length),r=`@${e} `;y(t+r+n),T(null),requestAnimationFrame(()=>{let e=A.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`}})}}),!w&&F.length>0&&(()=>{let e={};F.forEach((t,n)=>{e[t.category]||(e[t.category]=[]),e[t.category]?.push({cmd:t,idx:n})});let t=Cr.filter(t=>e[t]?.length);return(0,J.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,J.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,J.jsxs)(`div`,{className:`mb-1`,children:[(0,J.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,J.jsxs)(`button`,{type:`button`,onClick:()=>{y(``),j(e.name)},onMouseEnter:()=>x(t),className:q(`w-full text-left px-3 py-1.5 rounded transition-colors flex items-center gap-3`,t===b?`bg-accent text-accent-foreground`:`hover:bg-accent/40`),children:[(0,J.jsx)(`span`,{className:`font-mono shrink-0`,children:e.name}),e.aliases?.length?(0,J.jsxs)(`span`,{className:`text-xs text-muted-foreground/70 font-mono shrink-0`,children:[`(`,e.aliases.join(`, `),`)`]}):null,(0,J.jsxs)(`span`,{className:`text-xs text-muted-foreground truncate`,children:[`— `,e.description]})]},e.name))]},t))]})})(),(0,J.jsx)(`textarea`,{ref:A,value:v,onChange:e=>{let t=e.target.value;y(t),se(),S>=0&&C(-1),T(Tr(t,e.target.selectionStart??t.length))},onSelect:e=>{let t=e.currentTarget;T(Tr(t.value,t.selectionStart))},onKeyDown:oe,onPaste:e=>{let t=e.clipboardData?.getData(`text`)??``;if(t.length>800){let e=t.split(`
71
- `).length;D({chars:t.length,lines:e}),setTimeout(()=>D(null),4e3)}},placeholder:h?.isConnected?e?`Agent is running — type to queue a follow-up…`:`Message the agent… (type / for commands, @ for files)`:`Connect to server first…`,className:q(`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}),v.length>0&&(()=>{let e=v.length>=400,t=Math.ceil(v.length/4),n=`text-muted-foreground`,r;if(_>0&&e){let e=(g+t+64)/_*100;e>=100?(n=`text-red-600 dark:text-red-400 font-medium`,r=`Projected ${Math.round(e)}% of ${_.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 ${_.toLocaleString()} ctx — getting tight.`):r=`≈ ${t.toLocaleString()} tokens · projected ${Math.round(e)}% of ${_.toLocaleString()} ctx.`}else e&&(r=`≈ ${t.toLocaleString()} tokens (4-char heuristic)`);return(0,J.jsxs)(`span`,{className:q(`absolute bottom-1.5 right-12 text-xs tabular-nums`,n),title:r,children:[v.length,e&&(0,J.jsxs)(`span`,{className:`ml-1 opacity-70`,children:[`· ≈`,t>=1e3?`${(t/1e3).toFixed(1)}k`:t,`t`]})]})})()]}),(0,J.jsx)(`div`,{className:`flex gap-1`,children:e?(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(X,{type:`button`,size:`icon`,variant:`outline`,onClick:ae,className:`h-[44px] w-[44px] rounded-lg`,title:`Stop run and edit the last prompt (reuse + rewrite)`,children:(0,J.jsx)(ct,{className:`h-4 w-4`})}),(0,J.jsx)(X,{type:`button`,size:`icon`,variant:`destructive`,onClick:ie,className:`h-[44px] w-[44px] rounded-lg`,title:`Abort the current run`,children:(0,J.jsx)(a,{className:`h-4 w-4 fill-current`})})]}):(0,J.jsx)(X,{type:`submit`,size:`icon`,disabled:!v.trim()||!h?.isConnected,className:`h-[44px] w-[44px] rounded-lg`,children:(0,J.jsx)(it,{className:`h-4 w-4`})})})]})]})}function Dr({open:e,onClose:t,className:n}){let[r,i]=(0,V.useState)([]),[a,o]=(0,V.useState)(!1),c=Y(),l=(0,V.useRef)(null);(0,V.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,V.useCallback)(async e=>{o(!0),c.client.send?.({type:`session.rewind`,payload:{checkpointIndex:e}}),setTimeout(()=>{t(),o(!1)},800)},[c.client,t]);return e?(0,J.jsx)(`div`,{className:q(`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,J.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,J.jsxs)(`div`,{className:`flex items-center justify-between px-4 py-3 border-b shrink-0`,children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-2.5`,children:[(0,J.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,J.jsx)(bt,{className:`h-4 w-4`})}),(0,J.jsxs)(`div`,{children:[(0,J.jsx)(`h2`,{className:`text-sm font-semibold`,children:`Session Checkpoints`}),(0,J.jsxs)(`span`,{className:`text-[10px] text-muted-foreground tabular-nums`,children:[r.length,` checkpoint`,r.length===1?``:`s`]})]})]}),(0,J.jsx)(`button`,{type:`button`,onClick:t,className:`p-1.5 rounded-md hover:bg-muted transition-colors`,children:(0,J.jsx)(s,{className:`h-4 w-4`})})]}),(0,J.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,J.jsx)(`div`,{className:`flex-1 overflow-y-auto`,children:r.length===0?(0,J.jsxs)(`div`,{className:`flex flex-col items-center justify-center py-16 gap-3 text-muted-foreground`,children:[(0,J.jsx)(L,{className:`h-10 w-10 opacity-15`}),(0,J.jsx)(`p`,{className:`text-sm font-medium`,children:`No checkpoints yet`}),(0,J.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,J.jsx)(`div`,{className:`py-1`,children:[...r].reverse().map((e,t)=>{let n=t===0;return(0,J.jsxs)(`button`,{type:`button`,onClick:()=>u(e.index),disabled:a,className:q(`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,J.jsxs)(`div`,{className:`flex flex-col items-center mt-1.5`,children:[(0,J.jsx)(`div`,{className:q(`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.1)]`:`border-muted-foreground/30 bg-background group-hover:border-primary/40`)}),t<r.length-1&&(0,J.jsx)(`div`,{className:`w-px flex-1 min-h-[20px] bg-border/50`})]}),(0,J.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,J.jsxs)(`span`,{className:`text-xs font-mono text-muted-foreground tabular-nums shrink-0`,children:[`#`,e.index]}),(0,J.jsx)(`span`,{className:`text-xs font-medium truncate`,children:e.label}),n&&(0,J.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,J.jsxs)(`div`,{className:`flex items-center gap-2 mt-1 text-[10px] text-muted-foreground`,children:[(0,J.jsxs)(`span`,{className:`tabular-nums`,children:[e.messageCount,` msg`,e.messageCount===1?``:`s`]}),(0,J.jsx)(`span`,{children:`·`}),(0,J.jsxs)(`span`,{className:`tabular-nums`,children:[`~`,e.tokens.toLocaleString(),` tok`]}),(0,J.jsx)(`span`,{children:`·`}),(0,J.jsxs)(`span`,{className:`tabular-nums`,children:[`iter `,e.iteration]})]})]}),(0,J.jsx)(`span`,{className:`shrink-0 mt-1.5 opacity-0 group-hover:opacity-100 transition-opacity`,children:(0,J.jsx)(de,{className:`h-4 w-4 text-violet-500`})})]},e.index)})})}),(0,J.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,J.jsx)(`kbd`,{className:`px-1 py-0.5 rounded bg-muted font-mono text-[9px]`,children:`Esc`}),` to close`]})]})}):null}function Or({wsStatus:e,wsConnected:t}){let n=W(e=>e.wsUrl),[r,i]=(0,V.useState)(Date.now());(0,V.useEffect)(()=>{if(e.state!==`reconnecting`)return;let t=setInterval(()=>i(Date.now()),500);return()=>clearInterval(t)},[e.state]);let a=()=>H(n).retryNow();if(e.state===`open`&&t)return(0,J.jsx)(`div`,{className:`flex items-center gap-1 px-1.5 py-0.5 rounded-full text-[11px] font-medium shrink-0 bg-green-500/10 text-green-600 dark:text-green-400`,title:`Backend connected`,children:(0,J.jsx)(ie,{className:`h-3 w-3`})});if(e.state===`connecting`)return(0,J.jsxs)(`div`,{className:`flex items-center gap-1 px-1.5 py-0.5 rounded-full text-[11px] font-medium shrink-0 bg-yellow-500/10 text-yellow-600 dark:text-yellow-400`,title:`Connecting to backend`,children:[(0,J.jsx)(R,{className:`h-3 w-3 animate-spin`}),(0,J.jsx)(`span`,{children:`connecting`})]});if(e.state===`reconnecting`){let t=Math.max(0,Math.ceil((e.nextRetryAt-r)/1e3));return(0,J.jsxs)(`button`,{type:`button`,onClick:a,className:q(`flex items-center gap-1 px-1.5 py-0.5 rounded-full text-[11px] font-medium shrink-0`,`bg-orange-500/10 text-orange-600 dark:text-orange-400 hover:bg-orange-500/20`,`transition-colors`),title:e.lastError?`Reconnecting — last error: ${e.lastError}. Click to retry now.`:`Reconnecting — click to retry now.`,children:[(0,J.jsx)(R,{className:`h-3 w-3 animate-spin`}),(0,J.jsxs)(`span`,{children:[`retry #`,e.attempt,` in `,t,`s`]})]})}return(0,J.jsxs)(`button`,{type:`button`,onClick:a,className:`flex items-center gap-1 px-1.5 py-0.5 rounded-full text-[11px] font-medium shrink-0 bg-red-500/10 text-red-600 dark:text-red-400 hover:bg-red-500/20 transition-colors`,title:e.state===`closed`&&e.error?`Disconnected: ${e.error}. Click to retry.`:`Disconnected. Click to retry.`,children:[(0,J.jsx)(d,{className:`h-3 w-3`}),(0,J.jsxs)(`span`,{className:`flex items-center gap-0.5`,children:[`offline`,(0,J.jsx)(pe,{className:`h-3 w-3 opacity-70`})]})]})}var kr=[{id:`balanced`,name:`Balanced`,description:`Default rolling compaction`,thresholds:{warn:.6,soft:.75,hard:.9},preserveK:10,eliseThreshold:2e3}];function Ar(){let e=G(e=>e.contextMode),t=G(e=>e.contextModes),{listContextModes:n,switchContextMode:r}=Y(),[i,a]=(0,V.useState)(!1),o=(0,V.useRef)(null);(0,V.useEffect)(()=>{i&&n()},[i,n]),(0,V.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:kr,c=s.find(t=>t.id===e)??B(s[0]);return(0,J.jsxs)(`div`,{ref:o,className:`relative shrink-0`,children:[(0,J.jsxs)(`button`,{type:`button`,onClick:()=>a(e=>!e),className:q(`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,J.jsx)(M,{className:`h-3 w-3`}),`ctx: `,(0,J.jsx)(`span`,{className:`font-mono`,children:e||c.id}),(0,J.jsx)(me,{className:`h-3 w-3 opacity-60`})]}),i&&(0,J.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,J.jsx)(`div`,{className:`px-3 py-1.5 text-[10px] uppercase tracking-wider text-muted-foreground border-b`,children:`Context Window`}),s.map(t=>(0,J.jsxs)(`button`,{type:`button`,onClick:()=>{r(t.id),a(!1)},className:q(`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,J.jsx)(fe,{className:q(`h-3.5 w-3.5 mt-0.5 shrink-0`,t.id===e?`opacity-100 text-primary`:`opacity-0`)}),(0,J.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,J.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,J.jsx)(`span`,{className:`text-xs font-mono`,children:t.id}),t.thresholds?.warn!==void 0&&(0,J.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,J.jsx)(`div`,{className:`text-[11px] text-muted-foreground leading-snug`,children:t.description}),(t.preserveK||t.eliseThreshold)&&(0,J.jsxs)(`div`,{className:`mt-1 text-[10px] text-muted-foreground/80`,children:[`keep `,t.preserveK??`-`,` recent · elide `,t.eliseThreshold??`-`,`+ tokens`]})]})]},t.id))]})]})}function jr(){let e=G(e=>e.cost),t=G(e=>e.inputCost),n=G(e=>e.outputCost),r=G(e=>e.cacheReadCost),i=U(e=>e.messages),[a,o]=(0,V.useState)(!1),s=(0,V.useRef)(null);(0,V.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,J.jsxs)(`div`,{ref:s,className:`relative inline-block`,children:[(0,J.jsxs)(`button`,{type:`button`,onClick:()=>o(e=>!e),className:q(`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,J.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,J.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,J.jsx)(`span`,{className:`text-xs uppercase tracking-wider text-muted-foreground font-medium`,children:`Cost breakdown`}),(0,J.jsx)(`span`,{className:`font-mono tabular-nums text-sm font-semibold text-green-600 dark:text-green-400`,children:l(e)})]}),u?(0,J.jsxs)(`div`,{className:`text-[11px] text-muted-foreground font-mono mb-3 border-b pb-2`,children:[(0,J.jsxs)(`div`,{className:`flex justify-between`,children:[(0,J.jsx)(`span`,{children:`input /1M`}),(0,J.jsxs)(`span`,{children:[`$`,t.toFixed(2)]})]}),(0,J.jsxs)(`div`,{className:`flex justify-between`,children:[(0,J.jsx)(`span`,{children:`output /1M`}),(0,J.jsxs)(`span`,{children:[`$`,n.toFixed(2)]})]}),r>0&&(0,J.jsxs)(`div`,{className:`flex justify-between`,children:[(0,J.jsx)(`span`,{children:`cache /1M`}),(0,J.jsxs)(`span`,{children:[`$`,r.toFixed(2)]})]})]}):(0,J.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,J.jsx)(`div`,{className:`text-xs text-muted-foreground italic`,children:`No completed turns yet. Run a prompt to see per-turn cost here.`}):(0,J.jsxs)(J.Fragment,{children:[(0,J.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,J.jsx)(`ul`,{className:`space-y-1`,children:c.map(e=>(0,J.jsx)(`li`,{children:(0,J.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,J.jsxs)(`div`,{className:`flex items-baseline justify-between gap-2`,children:[(0,J.jsx)(`span`,{className:`text-xs truncate`,children:e.preview}),(0,J.jsx)(`span`,{className:`text-xs font-mono tabular-nums text-green-600 dark:text-green-400 shrink-0`,children:l(e.cost)})]}),(0,J.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 Mr=[`path`,`file_path`,`pattern`,`command`,`cmd`,`url`,`query`,`description`,`content`];function Nr(e,t){if(t==null)return``;if(typeof t!=`object`)return Pr(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=Fr(n),t=typeof n.old_string==`string`?n.old_string:``,r=typeof n.new_string==`string`?n.new_string:``,i=t?t.split(`
72
- `).length:0,a=r?r.split(`
73
- `).length:0;return`edit ${e||`(file)`}${i||a?` (${i} → ${a} lines)`:``}`}if(/^(write|write_file|create_file|new_file)$/.test(r)){let e=Fr(n),t=typeof n.content==`string`?n.content:``,r=t?t.split(`
74
- `).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`$ ${Pr(e,110)}`}if(/^(fetch|http|web|webfetch|curl|request)$/.test(r)){let e=n.url;if(typeof e==`string`)return`${(n.method??`GET`).toUpperCase()} ${Pr(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 ${Pr(e,60)} in ${t}`:`grep ${Pr(e,100)}`}if(/^(glob|find)$/.test(r)){let e=n.pattern??n.glob;if(typeof e==`string`)return`glob ${Pr(e,100)}`}if(/^(read|read_file|cat)$/.test(r)){let e=Fr(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 Mr){let t=n[e];if(typeof t==`string`&&t.length>0)return`${e}: ${Pr(t,100)}`}return Pr(Ir(t),120)}function Pr(e,t){return e.length>t?`${e.slice(0,t-1)}…`:e}function Fr(e){let t=e.file_path??e.path??e.filepath;return typeof t==`string`?t:``}function Ir(e){try{return JSON.stringify(e)}catch{return String(e)}}var Lr=(0,V.memo)(function({oldText:e,newText:t,caption:n}){let r=(0,V.useMemo)(()=>zr(e,t),[e,t]);if(r===null)return(0,J.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,J.jsxs)(`div`,{className:`rounded-lg border bg-background/40 overflow-hidden text-xs`,children:[(0,J.jsxs)(`div`,{className:`flex items-center justify-between px-3 py-1.5 border-b bg-muted/40`,children:[(0,J.jsx)(`span`,{className:`font-mono text-muted-foreground truncate`,children:n??`diff`}),(0,J.jsxs)(`span`,{className:`font-mono shrink-0`,children:[(0,J.jsxs)(`span`,{className:`text-emerald-600 dark:text-emerald-400`,children:[`+`,i]}),(0,J.jsx)(`span`,{className:`text-muted-foreground mx-1`,children:`·`}),(0,J.jsxs)(`span`,{className:`text-rose-600 dark:text-rose-400`,children:[`-`,a]})]})]}),(0,J.jsx)(`div`,{className:`font-mono leading-relaxed max-h-96 overflow-auto`,children:r.map((e,t)=>(0,J.jsxs)(`div`,{className:q(`flex`,e.kind===`add`&&`bg-emerald-500/10`,e.kind===`del`&&`bg-rose-500/10`),children:[(0,J.jsx)(`span`,{className:q(`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,J.jsx)(`pre`,{className:q(`whitespace-pre-wrap break-all flex-1 px-2`,e.kind===`ctx`&&`text-muted-foreground/70`),children:e.text||`\xA0`})]},t))})]})}),Rr=5e3;function zr(e,t){let n=e.split(`
75
- `),r=t.split(`
76
- `);if(n.length>Rr||r.length>Rr)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]?B(o[e])[t]=B(o[e+1]?.[t+1])+1:B(o[e])[t]=Math.max(B(o[e+1]?.[t]),B(o[e]?.[t+1]));let s=[],c=0,l=0;for(;c<i&&l<a;)n[c]===r[l]?(s.push({kind:`ctx`,text:B(n[c])}),c++,l++):B(o[c+1]?.[l])>=B(o[c]?.[l+1])?(s.push({kind:`del`,text:B(n[c])}),c++):(s.push({kind:`add`,text:B(r[l])}),l++);for(;c<i;)s.push({kind:`del`,text:B(n[c++])});for(;l<a;)s.push({kind:`add`,text:B(r[l++])});return s}function Br(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 Vr=25,Hr=12;function Ur({text:e,isError:t,className:n,wrapClass:r,showLineNumbers:i}){let a=(0,V.useMemo)(()=>e.split(`
77
- `),[e]),o=a.length>Vr,[s,c]=(0,V.useState)(!o),l=s?e:a.slice(0,Hr).join(`
78
- `),u=!!i&&o&&s;return(0,J.jsxs)(`div`,{className:q(`rounded-md border bg-background/40 overflow-hidden`,n),children:[u?(0,J.jsxs)(`div`,{className:`flex max-h-96 overflow-auto`,children:[(0,J.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:a.map((e,t)=>`${t+1}`).join(`
79
- `)}),(0,J.jsx)(`pre`,{className:q(`text-xs font-mono leading-[1.4] py-2 px-2 flex-1 whitespace-pre`,t?`text-destructive`:`text-foreground`),children:l})]}):(0,J.jsx)(`pre`,{className:q(`text-xs font-mono p-2 max-h-96 overflow-auto`,r,t?`text-destructive`:`text-foreground`),children:l}),o&&(0,J.jsx)(`button`,{type:`button`,onClick:()=>c(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:s?(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(w,{className:`h-3 w-3`}),`Collapse to first `,Hr,` lines`]}):(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(at,{className:`h-3 w-3`}),`Show all `,a.length,` lines (`,a.length-Hr,` more)`]})})]})}var Wr=(0,V.memo)(function({toolName:e,result:t,isError:n,className:r}){let i=(0,V.useMemo)(()=>Gr(e,t),[e,t]);return i.kind===`json`?(0,J.jsx)(Kr,{value:i.value,isError:n,className:r}):i.kind===`numbered`?(0,J.jsx)(Ur,{text:t,isError:n,className:r,wrapClass:`whitespace-pre`}):i.kind===`bash`?(0,J.jsxs)(`div`,{className:q(`rounded-md border bg-background/40 overflow-hidden`,r),children:[i.stdout&&(0,J.jsx)(Ur,{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,J.jsxs)(`div`,{className:q(`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,J.jsxs)(`span`,{children:[`exit code: `,(0,J.jsx)(`span`,{className:`font-mono`,children:i.exitCode})]}),i.duration&&(0,J.jsx)(`span`,{children:i.duration})]})]}):(0,J.jsx)(Ur,{text:t,isError:n,className:r,wrapClass:`whitespace-pre-wrap break-all`,showLineNumbers:!0})});function Gr(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 Kr({value:e,isError:t,className:n}){let r=(0,V.useMemo)(()=>{try{return JSON.stringify(e,null,2)}catch{return String(e)}},[e]),i=r.split(`
80
- `).length,[a,o]=(0,V.useState)(i<30);return(0,J.jsxs)(`div`,{className:q(`rounded-md border bg-background/40 overflow-hidden`,t&&`border-destructive/40`,n),children:[(0,J.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,J.jsxs)(`span`,{className:`flex items-center gap-1`,children:[a?(0,J.jsx)(me,{className:`h-3 w-3`}):(0,J.jsx)(S,{className:`h-3 w-3`}),(0,J.jsxs)(`span`,{className:`font-mono`,children:[`JSON · `,i,` lines`]})]}),(0,J.jsx)(`span`,{children:a?`collapse`:`expand`})]}),a&&(0,J.jsx)(`pre`,{className:q(`text-xs font-mono whitespace-pre p-2 max-h-96 overflow-auto`,t?`text-destructive`:`text-foreground`),children:r})]})}var qr=/💡\s*Next steps?\s*\n+((?:\d+\.\s+.+\n?)+)/i;function Jr(e){let t=qr.exec(e);if(!t?.[1])return[];let n=t[1].split(`
81
- `).filter(Boolean),r=[];for(let e of n){let t=/^(\d+)\.\s+(.+)$/.exec(e.trim());t&&r.push({index:Number.parseInt(t[1],10),text:t[2].trim()})}return r.slice(0,6)}function Yr(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 Xr({steps:e}){return e.length===0?null:(0,J.jsx)(`div`,{className:`mt-3 pt-2 border-t border-border/50`,children:(0,J.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:e.map(e=>(0,J.jsxs)(`button`,{type:`button`,onClick:()=>Yr(e.text),className:`inline-flex items-center gap-1 px-2.5 py-1 rounded-md text-[11px] border border-border/60 bg-muted/40 hover:bg-muted hover:border-primary/40 text-foreground/80 hover:text-foreground transition-colors group`,title:`Execute: ${e.text}`,children:[(0,J.jsx)(`span`,{className:`font-mono text-[10px] text-muted-foreground group-hover:text-primary tabular-nums`,children:e.index}),(0,J.jsx)(Ze,{className:`h-2.5 w-2.5 text-muted-foreground group-hover:text-primary`}),(0,J.jsx)(`span`,{className:`line-clamp-1 max-w-[28rem]`,children:e.text})]},e.index))})})}async function Zr(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 Qr(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 $r(e){let t=(e??``).toLowerCase();return/bash|shell|exec|run/.test(t)?`log`:(/grep|search|find/.test(t),`txt`)}function ei(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 ti={code({inline:e,className:t,children:n,...r}){let i=/language-(\w+)/.exec(t??``),a=String(n??``).replace(/\n$/,``);return e||!i?(0,J.jsx)(`code`,{className:q(`rounded bg-muted/60 px-1.5 py-0.5 text-[0.85em] font-mono`,t),...r,children:n}):(0,J.jsxs)(`div`,{className:`not-prose relative my-3 rounded-lg border bg-muted/30 overflow-hidden`,children:[(0,J.jsxs)(`div`,{className:`flex items-center justify-between px-3 py-1.5 border-b bg-muted/40 text-xs`,children:[(0,J.jsx)(`span`,{className:`font-mono text-muted-foreground`,children:i[1]}),(0,J.jsx)(ni,{text:a,label:``})]}),(0,J.jsx)(`pre`,{className:`overflow-x-auto p-3 text-xs leading-relaxed font-mono max-h-[40rem]`,children:(0,J.jsx)(`code`,{children:a})})]})}};function ni({text:e,className:t,label:n=`Copy`}){let[r,i]=(0,V.useState)(!1);return(0,J.jsx)(`button`,{type:`button`,onClick:async t=>{t.stopPropagation(),await Zr(e)&&(i(!0),setTimeout(()=>i(!1),1400))},className:q(`inline-flex items-center gap-1 text-xs text-muted-foreground hover:text-foreground transition-colors`,t),title:n,children:r?(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(fe,{className:`h-3 w-3 text-green-500`}),(0,J.jsx)(`span`,{children:`Copied`})]}):(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(Et,{className:`h-3 w-3`}),(0,J.jsx)(`span`,{children:n})]})})}function ri(e){let t=e.split(`
82
- `);for(let e=0;e<t.length;e++){let n=B(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 ii({text:e}){let t=ri(e),[n,r]=(0,V.useState)(!1);if(t===-1)return(0,J.jsx)(`pre`,{className:`whitespace-pre-wrap break-words font-mono text-xs leading-relaxed`,children:e});let i=e.split(`
83
- `),a=i.slice(0,t).join(`
84
- `).trim(),o=i.slice(t).join(`
85
- `),s=o.split(`
86
- `).filter(e=>e.trim().length>0).length;return(0,J.jsxs)(`div`,{className:`space-y-2`,children:[a&&(0,J.jsx)(`pre`,{className:`whitespace-pre-wrap break-words font-mono text-xs leading-relaxed`,children:a}),(0,J.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,J.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 ai({input:e}){let[t,n]=(0,V.useState)({});if(typeof e!=`object`||!e||Array.isArray(e))return(0,J.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,J.jsx)(`span`,{className:`text-xs text-muted-foreground italic`,children:`(no params)`}):(0,J.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(`
87
- `));return(0,J.jsxs)(`div`,{className:q(`py-0.5`,n?`flex flex-col gap-0.5`:`flex items-baseline gap-2`),children:[(0,J.jsxs)(`span`,{className:`text-muted-foreground shrink-0`,children:[e,`:`]}),(0,J.jsx)(`span`,{className:q(`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,J.jsxs)(`div`,{className:`py-0.5`,children:[(0,J.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,J.jsx)(`span`,{className:`text-muted-foreground/60 text-[10px]`,children:i?`▾`:`▸`}),(0,J.jsxs)(`span`,{className:`text-muted-foreground`,children:[e,`:`]}),(0,J.jsx)(`span`,{className:`text-violet-600 dark:text-violet-400`,children:a})]}),i&&(0,J.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 oi=(0,V.memo)(function({message:e,isFirst:t=!1,isContinuation:n=!1}){let[i,a]=(0,V.useState)({}),[o,s]=(0,V.useState)(!1),[c,l]=(0,V.useState)(``),[u,d]=(0,V.useState)(!1),f=e.role===`user`,m=e.role===`tool`;e.role;let h=U(e=>e.truncateAfter),_=U(e=>e.addMessage),v=U(e=>e.setLoading),y=U(e=>e.isLoading),x=W(e=>e.wsUrl),C=K(e=>e.pinnedIds),w=K(e=>e.togglePin),T=K(e=>e.compactMode),E=C.includes(e.id),D=G(e=>e.inputCost),O=G(e=>e.outputCost),k=G(e=>e.cacheReadCost),j=(()=>{if(e.role!==`assistant`||y)return!1;let t=U.getState().messages;for(let n=t.length-1;n>=0;n--){let r=B(t[n]);if(r.role===`assistant`)return r.id===e.id}return!1})(),M=()=>{let t=U.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=B(t[r]);h(i.id),_({role:`user`,content:i.content}),v(!0),H(x).sendMessage(i.content)},N=e=>{a(t=>({...t,[e]:!t[e]}))},ee=()=>{l(e.content),s(!0)},P=()=>{s(!1),l(``)},te=()=>{let t=c.trim();if(!t){P();return}h(e.id),_({role:`user`,content:t}),v(!0),H(x).sendMessage(t),s(!1),l(``)};return(0,J.jsxs)(`div`,{"data-message-id":e.id,"data-pinned":E?`1`:void 0,className:q(`group flex animate-message rounded-lg transition-shadow`,T?`gap-2`:`gap-3`,f?`flex-row-reverse`:`flex-row`,E&&`ring-1 ring-amber-500/30 bg-amber-500/[0.02] px-1 -mx-1`),children:[n?(0,J.jsx)(`div`,{className:`flex-shrink-0 w-8 h-8`,"aria-hidden":!0}):(0,J.jsx)(`div`,{className:q(`flex-shrink-0 w-8 h-8 rounded-full flex items-center justify-center`,`ring-2 ring-offset-2 ring-offset-background`,f?`bg-primary text-primary-foreground ring-primary/20`:m?`bg-secondary text-secondary-foreground ring-secondary/20`:`bg-accent text-accent-foreground ring-accent/20`),children:f?(0,J.jsx)(r,{className:`h-4 w-4`}):m?(0,J.jsx)(p,{className:`h-4 w-4`}):(0,J.jsx)(ke,{className:`h-4 w-4`})}),(0,J.jsxs)(`div`,{className:q(`flex flex-col gap-1.5 max-w-[85%]`,f&&`items-end`),children:[t&&!n&&(0,J.jsx)(`span`,{className:q(`text-xs font-medium px-1`,f?`text-primary`:m?`text-secondary`:`text-muted-foreground`),children:f?`You`:m?`Tool`:`Assistant`}),m&&e.toolName&&(0,J.jsxs)(`button`,{type:`button`,onClick:()=>N(e.id),className:q(`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,J.jsx)(`span`,{className:`text-muted-foreground/50`,children:i[e.id]?(0,J.jsx)(me,{className:`h-3 w-3`}):(0,J.jsx)(S,{className:`h-3 w-3`})}),(0,J.jsx)(p,{className:`h-3 w-3`}),(0,J.jsx)(`span`,{className:`font-mono`,children:e.toolName}),e.toolResult===void 0?(0,J.jsx)(`span`,{className:`h-1.5 w-1.5 rounded-full bg-amber-500 animate-pulse`,"aria-hidden":!0}):e.isError?(0,J.jsx)(se,{className:`h-3 w-3 text-destructive`}):(0,J.jsx)(g,{className:`h-3 w-3 text-green-500`}),typeof e.toolDurationMs==`number`&&(0,J.jsx)(`span`,{className:`text-xs text-muted-foreground tabular-nums font-normal`,children:ei(e.toolDurationMs)})]}),(0,J.jsx)(`div`,{className:q(`rounded-2xl`,T?`px-3 py-1.5`:`px-4 py-3`,f?`bg-primary text-primary-foreground rounded-br-md`:m?e.isError?`bg-destructive/5 border border-destructive/20 text-destructive`:`bg-muted/80 text-foreground`:`bg-card border text-foreground`,e.isError&&!m&&`border-destructive/20`),children:m?(()=>{let t=!!i[e.id],n=e.toolInput===void 0?``:Nr(e.toolName,e.toolInput),r=e.toolResult?e.toolResult.split(`
88
- `).length:0;return(0,J.jsxs)(`div`,{className:`space-y-1`,children:[n&&!t&&(0,J.jsx)(`div`,{className:`text-xs text-muted-foreground font-mono truncate`,children:n}),e.toolResult===void 0&&e.progressLines&&e.progressLines.length>0&&(0,J.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,J.jsx)(`div`,{className:`truncate text-muted-foreground`,children:e},`${e}-${n}`)})})()}),t&&e.toolInput!==void 0&&(()=>{let t=Br(e.toolName,e.toolInput);return t?(0,J.jsx)(Lr,{oldText:t.oldText,newText:t.newText,caption:t.caption}):(0,J.jsxs)(`div`,{className:`p-3 bg-muted/50 rounded-lg overflow-x-auto`,children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-1 text-muted-foreground mb-2 text-xs`,children:[(0,J.jsx)(L,{className:`h-3 w-3`}),(0,J.jsx)(`span`,{children:`Input`})]}),(0,J.jsx)(ai,{input:e.toolInput})]})})(),t&&e.toolResult!==void 0&&e.toolResult.length>0&&(0,J.jsxs)(`div`,{className:`relative group/tool`,children:[(0,J.jsx)(Wr,{toolName:e.toolName,result:e.toolResult,isError:e.isError}),(0,J.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,J.jsx)(ni,{text:e.toolResult,label:``,className:`bg-background/80 border rounded px-1.5 py-0.5`}),e.toolResult.split(`
89
- `).length>5&&(0,J.jsx)(`button`,{type:`button`,onClick:t=>{t.stopPropagation();let n=$r(e.toolName);Qr(`${(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,J.jsx)(b,{className:`h-3 w-3`})})]})]}),t&&e.toolResult!==void 0&&e.toolResult.length===0&&(0,J.jsx)(`span`,{className:`text-xs text-muted-foreground italic`,children:`(empty)`}),!t&&e.isError&&e.toolResult&&(0,J.jsx)(`div`,{className:`text-xs font-mono text-destructive truncate`,children:e.toolResult.split(`
90
- `)[0]}),(e.toolResult!==void 0&&e.toolResult.length>0||e.toolInput!==void 0&&Object.keys(e.toolInput??{}).length>0)&&(0,J.jsx)(`button`,{type:`button`,onClick:()=>N(e.id),className:`text-xs text-muted-foreground hover:text-foreground transition-colors`,children:t?`Hide details`:`Show details${r>0?` (${r} line${r===1?``:`s`})`:``}`})]})})():o&&f?(0,J.jsxs)(`div`,{className:`flex flex-col gap-2 min-w-[280px]`,children:[(0,J.jsx)(`textarea`,{value:c,onChange:e=>l(e.target.value),onKeyDown:e=>{e.key===`Escape`?(e.preventDefault(),P()):e.key===`Enter`&&(e.metaKey||e.ctrlKey)&&(e.preventDefault(),te())},rows:Math.min(8,Math.max(2,c.split(`
91
- `).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,J.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,J.jsx)(`span`,{className:`text-[10px] text-primary-foreground/60`,children:`⌘/Ctrl+Enter to save · Esc to cancel`}),(0,J.jsxs)(`div`,{className:`flex gap-1`,children:[(0,J.jsx)(`button`,{type:`button`,onClick:P,className:`text-xs px-2 py-0.5 rounded border border-primary-foreground/30 hover:bg-primary-foreground/10`,children:`Cancel`}),(0,J.jsx)(`button`,{type:`button`,onClick:te,disabled:!c.trim(),className:`text-xs px-2 py-0.5 rounded bg-primary-foreground text-primary disabled:opacity-50`,children:`Save & resend`})]})]})]}):(0,J.jsx)(`div`,{className:`text-sm leading-relaxed markdown-content`,children:e.content?u&&e.role===`assistant`?(0,J.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,J.jsx)(ii,{text:e.content}):(0,J.jsx)(_t,{remarkPlugins:[_e],components:ti,children:e.content}):e.streaming?(0,J.jsx)(`span`,{className:`inline-block animate-pulse text-muted-foreground`,children:`Typing...`}):(0,J.jsx)(`span`,{className:`text-muted-foreground italic`,children:`No content`})})}),j&&e.content&&(()=>{let t=Jr(e.content);return t.length===0?null:(0,J.jsx)(Xr,{steps:t})})(),(0,J.jsxs)(`div`,{className:q(`flex items-center gap-2 px-1`,f?`flex-row-reverse`:`flex-row`),children:[(0,J.jsx)(`span`,{className:`text-xs text-muted-foreground/50`,children:new Date(e.timestamp).toLocaleTimeString([],{hour:`2-digit`,minute:`2-digit`})}),e.runSummary&&(0,J.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*D+t.output*O+(t.cacheRead??0)*k)/1e6,r=D>0||O>0,i=n>=.01?`$${n.toFixed(4)}`:n>0?`$${n.toFixed(6).replace(/0+$/,``).replace(/\.$/,``)}`:``;return(0,J.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}`:``]})})(),!m&&e.content&&!e.streaming&&(0,J.jsx)(ni,{text:e.content,label:``,className:`opacity-0 group-hover:opacity-100 transition-opacity`}),e.role===`assistant`&&e.content&&!e.streaming&&(0,J.jsxs)(`button`,{type:`button`,onClick:()=>d(e=>!e),title:u?`Show rendered markdown`:`Show raw markdown source`,className:q(`text-xs inline-flex items-center gap-1 transition-opacity`,u?`text-primary hover:text-primary/80 opacity-100`:`opacity-0 group-hover:opacity-100 text-muted-foreground hover:text-foreground`),children:[(0,J.jsx)(A,{className:`h-3 w-3`}),(0,J.jsx)(`span`,{children:u?`Rendered`:`Raw`})]}),f&&!o&&!y&&e.content&&(0,J.jsxs)(`button`,{type:`button`,onClick:ee,title:`Edit & resend this prompt`,className:`opacity-0 group-hover:opacity-100 transition-opacity text-xs text-muted-foreground hover:text-foreground inline-flex items-center gap-1`,children:[(0,J.jsx)(ct,{className:`h-3 w-3`}),(0,J.jsx)(`span`,{children:`Edit`})]}),e.role===`assistant`&&e.content&&!e.streaming&&(0,J.jsxs)(`button`,{type:`button`,onClick:()=>w(e.id),title:E?`Unpin`:`Pin this answer`,className:q(`text-xs inline-flex items-center gap-1 transition-opacity`,E?`text-amber-500 hover:text-amber-600 opacity-100`:`opacity-0 group-hover:opacity-100 text-muted-foreground hover:text-foreground`),children:[E?(0,J.jsx)(mt,{className:`h-3 w-3`}):(0,J.jsx)(Qe,{className:`h-3 w-3`}),(0,J.jsx)(`span`,{children:E?`Pinned`:`Pin`})]}),j&&e.content&&!e.streaming&&(0,J.jsxs)(`button`,{type:`button`,onClick:M,title:`Regenerate this response`,className:`opacity-0 group-hover:opacity-100 transition-opacity text-xs text-muted-foreground hover:text-foreground inline-flex items-center gap-1`,children:[(0,J.jsx)(pe,{className:`h-3 w-3`}),(0,J.jsx)(`span`,{children:`Retry`})]})]})]})]})});function si(){let e=G(e=>e.mode),t=G(e=>e.modes),{listModes:n,switchMode:r}=Y(),[i,a]=(0,V.useState)(!1),o=(0,V.useRef)(null);(0,V.useEffect)(()=>{i&&n()},[i,n]),(0,V.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,J.jsxs)(`div`,{ref:o,className:`relative shrink-0`,children:[(0,J.jsxs)(`button`,{type:`button`,onClick:()=>a(e=>!e),className:q(`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,J.jsx)(`span`,{className:`font-mono`,children:e||`default`}),(0,J.jsx)(me,{className:`h-3 w-3 opacity-60`})]}),i&&(0,J.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,J.jsx)(`div`,{className:`px-3 py-1.5 text-[10px] uppercase tracking-wider text-muted-foreground border-b`,children:`Mode`}),s.map(t=>(0,J.jsxs)(`button`,{type:`button`,onClick:()=>{r(t.id),a(!1)},className:q(`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,J.jsx)(fe,{className:q(`h-3.5 w-3.5 mt-0.5 shrink-0`,t.id===e?`opacity-100 text-primary`:`opacity-0`)}),(0,J.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,J.jsx)(`div`,{className:`text-xs font-mono`,children:t.id}),t.description&&(0,J.jsx)(`div`,{className:`text-[11px] text-muted-foreground leading-snug`,children:t.description})]})]},t.id))]})]})}function ci({open:e,onClose:t,className:n}){let[r,i]=(0,V.useState)([]),o=Y(),c=(0,V.useRef)(null),l=(0,V.useRef)(null);(0,V.useEffect)(()=>{if(!(!e||!o.client?.isConnected))return o.client.send?.({type:`process.list`}),c.current=o.client.on?.(`process.list`,e=>{let t=e?.payload;t?.processes&&i(t.processes)})??null,l.current=setInterval(()=>{o.client.send?.({type:`process.list`})},3e3),()=>{c.current?.(),l.current&&clearInterval(l.current)}},[e,o.client]);let u=(0,V.useCallback)(e=>{o.client.send?.({type:`process.kill`,payload:{pid:e}})},[o.client]),d=(0,V.useCallback)(()=>{o.client.send?.({type:`process.killAll`})},[o.client]),f=r.filter(e=>e.status===`running`);return e?(0,J.jsx)(`div`,{className:q(`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,J.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,J.jsxs)(`div`,{className:`flex items-center justify-between px-4 py-3 border-b shrink-0`,children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-2.5`,children:[(0,J.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,J.jsx)(p,{className:`h-4 w-4`})}),(0,J.jsxs)(`div`,{children:[(0,J.jsx)(`h2`,{className:`text-sm font-semibold`,children:`Running Processes`}),(0,J.jsxs)(`span`,{className:`text-[10px] text-muted-foreground tabular-nums`,children:[f.length,` active · `,r.length,` total`]})]})]}),(0,J.jsxs)(`div`,{className:`flex items-center gap-1`,children:[f.length>0&&(0,J.jsxs)(`button`,{type:`button`,onClick:d,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,J.jsx)(a,{className:`h-3 w-3 fill-current`}),`Kill All`]}),(0,J.jsx)(`button`,{type:`button`,onClick:t,className:`p-1.5 rounded-md hover:bg-muted transition-colors`,children:(0,J.jsx)(s,{className:`h-4 w-4`})})]})]}),(0,J.jsx)(`div`,{className:`flex-1 overflow-y-auto`,children:r.length===0?(0,J.jsxs)(`div`,{className:`flex flex-col items-center justify-center py-16 gap-3 text-muted-foreground`,children:[(0,J.jsx)(p,{className:`h-10 w-10 opacity-15`}),(0,J.jsx)(`p`,{className:`text-sm font-medium`,children:`No processes tracked`}),(0,J.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,J.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,J.jsxs)(`div`,{className:q(`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,J.jsxs)(`div`,{className:`flex items-center gap-3 min-w-0 flex-1`,children:[(0,J.jsx)(`span`,{className:q(`led shrink-0`,e.status===`running`?r?`text-blue-400`:`text-[hsl(var(--success))] led-pulse`:`text-muted-foreground`)}),(0,J.jsxs)(`div`,{className:`min-w-0`,children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,J.jsxs)(`span`,{className:`font-mono text-[10px] text-muted-foreground shrink-0`,children:[`PID `,e.pid]}),(0,J.jsx)(`span`,{className:`font-medium truncate`,children:e.tool}),r&&(0,J.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,J.jsx)(le,{className:`h-2.5 w-2.5`}),`protected`]})]}),(0,J.jsx)(`code`,{className:`text-[10px] text-muted-foreground/70 truncate block mt-0.5 font-mono`,children:e.command})]})]}),(0,J.jsxs)(`div`,{className:`flex items-center gap-3 shrink-0 ml-3`,children:[n&&(0,J.jsx)(`span`,{className:`text-[10px] text-muted-foreground tabular-nums`,children:n}),e.status===`running`&&!r&&(0,J.jsx)(`button`,{type:`button`,onClick:()=>u(e.pid),className:`p-1.5 rounded-md hover:bg-destructive/10 hover:text-destructive transition-colors`,title:`Kill PID ${e.pid}`,children:(0,J.jsx)(a,{className:`h-3.5 w-3.5 fill-current`})})]})]},e.pid)})})})]})}):null}function li(){let e=K(e=>e.searchOpen),t=K(e=>e.setSearchOpen),n=K(e=>e.searchQuery),r=K(e=>e.setSearchQuery),i=U(e=>e.messages),a=(0,V.useRef)(null),[o,c]=(0,V.useState)(0);(0,V.useEffect)(()=>{e&&requestAnimationFrame(()=>a.current?.focus())},[e]);let l=(0,V.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,V.useEffect)(()=>{o>=l.length&&c(0)},[l,o]),(0,V.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`)},s=n.trim();if(!s||!e){a();return}let c=s.toLowerCase(),u=[],d=[],f=l[o];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),u.push(a),t&&d.push(a),i=e+c.length}}r=n.nextNode()}}return u.length>0?r.set(`chat-search`,new i(...u)):r.delete(`chat-search`),d.length>0?r.set(`chat-search-active`,new i(...d)):r.delete(`chat-search-active`),a},[n,l,o,e]),(0,V.useEffect)(()=>{let e=l[o];if(!e)return;let t=document.querySelector(`[data-message-id="${e}"]`);t&&t.scrollIntoView({behavior:`smooth`,block:`center`})},[l,o]),!e)return null;let u=e=>{l.length!==0&&c(t=>(t+e+l.length)%l.length)};return(0,J.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,J.jsxs)(`div`,{className:`flex items-center gap-2 px-3 py-2`,children:[(0,J.jsx)(x,{className:`h-4 w-4 text-muted-foreground shrink-0`}),(0,J.jsx)(`input`,{ref:a,value:n,onChange:e=>r(e.target.value),onKeyDown:e=>{e.key===`Escape`?(e.preventDefault(),t(!1)):e.key===`Enter`?(e.preventDefault(),u(e.shiftKey?-1:1)):e.key===`ArrowDown`?(e.preventDefault(),u(1)):e.key===`ArrowUp`&&(e.preventDefault(),u(-1))},placeholder:`Search in chat…`,className:`flex-1 bg-transparent outline-none text-sm placeholder:text-muted-foreground`}),(0,J.jsx)(`span`,{className:`text-xs text-muted-foreground tabular-nums shrink-0`,children:l.length===0?n?`0`:``:`${o+1} / ${l.length}`}),(0,J.jsx)(`button`,{type:`button`,onClick:()=>u(-1),disabled:l.length===0,className:q(`p-1 rounded hover:bg-muted disabled:opacity-30 disabled:cursor-not-allowed`),title:`Previous hit`,children:(0,J.jsx)(pt,{className:`h-3.5 w-3.5`})}),(0,J.jsx)(`button`,{type:`button`,onClick:()=>u(1),disabled:l.length===0,className:q(`p-1 rounded hover:bg-muted disabled:opacity-30 disabled:cursor-not-allowed`),title:`Next hit`,children:(0,J.jsx)(ze,{className:`h-3.5 w-3.5`})}),(0,J.jsx)(`button`,{type:`button`,onClick:()=>t(!1),className:`p-1 rounded hover:bg-muted text-muted-foreground`,title:`Close (Esc)`,children:(0,J.jsx)(s,{className:`h-3.5 w-3.5`})})]})})}var ui=(0,V.createContext)(void 0);function di({children:e,defaultTheme:t=`system`,storageKey:n=`wrongstack-theme`}){let{setTheme:r}=W(),[i,a]=(0,V.useState)(()=>typeof window<`u`&&localStorage.getItem(n)||t);(0,V.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,J.jsx)(ui.Provider,{value:o,children:e})}function fi(){let e=(0,V.useContext)(ui);if(e===void 0)throw Error(`useTheme must be used within a ThemeProvider`);return e}var pi=[{value:`light`,icon:T,label:`Light`},{value:`dark`,icon:qe,label:`Dark`},{value:`system`,icon:gt,label:`System`}];function mi({className:e}){let{theme:t,setTheme:n}=fi();return(0,J.jsx)(`div`,{className:q(`inline-flex items-center gap-0.5 rounded-lg border border-border bg-card/70 p-0.5 shadow-sm`,e),"aria-label":`Theme`,children:pi.map(({value:e,icon:r,label:i})=>{let a=t===e;return(0,J.jsx)(`button`,{type:`button`,"aria-pressed":a,title:`${i} theme`,"aria-label":`${i} theme`,onClick:()=>n(e),className:q(`grid h-7 w-7 place-items-center rounded-md transition-all duration-150`,a?`bg-primary/15 text-primary shadow-[inset_0_0_0_1px_hsl(var(--primary)/0.35)]`:`text-muted-foreground hover:bg-accent hover:text-foreground`),children:(0,J.jsx)(r,{className:`h-3.5 w-3.5`,strokeWidth:2.2})},e)})})}function hi(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 gi=(0,V.memo)(function({tools:e,defaultOpen:t=!1,isContinuation:n=!1}){let[r,i]=(0,V.useState)(t);if(e.length===1)return(0,J.jsx)(oi,{message:B(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,J.jsxs)(`div`,{className:`flex gap-3 animate-message`,children:[n?(0,J.jsx)(`div`,{className:`flex-shrink-0 w-8 h-8`,"aria-hidden":!0}):(0,J.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,J.jsx)(p,{className:`h-4 w-4`})}),(0,J.jsxs)(`div`,{className:`flex flex-col gap-1.5 max-w-[85%] flex-1 min-w-0`,children:[(0,J.jsxs)(`button`,{type:`button`,onClick:()=>i(e=>!e),className:q(`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,J.jsx)(me,{className:`h-3.5 w-3.5 text-muted-foreground`}):(0,J.jsx)(S,{className:`h-3.5 w-3.5 text-muted-foreground`}),(0,J.jsx)(p,{className:`h-3.5 w-3.5 text-muted-foreground`}),(0,J.jsxs)(`span`,{className:`font-mono text-xs`,children:[e.length,` tool call`,e.length===1?``:`s`]}),a>0?(0,J.jsx)(R,{className:`h-3 w-3 animate-spin text-amber-500`}):o>0?(0,J.jsx)(se,{className:`h-3 w-3 text-destructive`}):(0,J.jsx)(g,{className:`h-3 w-3 text-green-500`}),s>0&&(0,J.jsx)(`span`,{className:`text-xs text-muted-foreground tabular-nums font-normal`,children:hi(s)}),l&&(0,J.jsxs)(`span`,{className:`text-xs text-muted-foreground/80 font-mono truncate`,children:[`· `,l,u]})]}),r&&(0,J.jsx)(`div`,{className:`space-y-2 pl-3 border-l-2 border-border/40 ml-2`,children:e.map(e=>(0,J.jsx)(oi,{message:e,isFirst:!1},e.id))})]})]})}),_i=[{icon:x,title:`Explore`,hint:`Understand the code before changing it`,tone:`text-blue-600 dark:text-blue-400 bg-blue-500/10 border-blue-500/20`,prompts:[`Walk me through this codebase: what are the top-level packages or modules, what does each do, and how do they depend on one another? What cross-cutting patterns or abstractions should I understand first?`,`Find the public API surface of this project — all exported functions, classes, and types that external consumers rely on. Flag any that lack documentation or have unclear contracts.`,`Map the data flow for a single user action from entry point to persistence. Where does validation happen? Where are side effects triggered? Show me the call chain and any middleware involved.`]},{icon:yt,title:`Build`,hint:`Add a feature end-to-end`,tone:`text-emerald-600 dark:text-emerald-400 bg-emerald-500/10 border-emerald-500/20`,prompts:[`Add a new end-to-end feature. Walk through the layers: data model, API/serialization, business logic, UI (if applicable), and tests. Use existing patterns in this codebase rather than inventing new ones.`,`Write comprehensive tests for an existing module that has low coverage. Cover happy paths, edge cases, and error states. Use whatever test runner and patterns this project already uses.`,`Add structured logging or observability to a critical code path. Use the project’s existing logging conventions. Make sure errors carry enough context to debug without re-running.`]},{icon:te,title:`Debug`,hint:`Track a problem to its root cause`,tone:`text-amber-600 dark:text-amber-400 bg-amber-500/10 border-amber-500/20`,prompts:[`Something isn't behaving as expected — data looks wrong, a feature silently fails, or state drifts over time. Help me trace it: start from the symptom, follow the code path, and identify where the logic diverges from intent.`,`The app works fine locally but breaks in production or CI. Check for environment differences, missing config, race conditions, or infrastructure-level assumptions that might explain the gap.`,`Performance degrades under load or over time. Profile the hot path, identify bottlenecks (N+1 queries, blocking I/O, large allocations, expensive renders), and propose targeted fixes with measurable impact.`]},{icon:ce,title:`Refactor`,hint:`Clean up without breaking behavior`,tone:`text-violet-600 dark:text-violet-400 bg-violet-500/10 border-violet-500/20`,prompts:[`Find duplicated or near-duplicated logic across the codebase. Extract the shared pieces into a single module or utility, update call sites, and ensure the existing tests still pass.`,`Identify modules that have grown too large or have too many responsibilities. Propose a split that respects the project’s existing structure, keeps the public API stable, and can be done incrementally.`,`Audit error handling across the codebase: are errors propagated consistently? Are they wrapped with enough context? Are there swallowed errors or bare panics? Propose a uniform approach and apply it to the worst offenders.`]}],vi=[{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 yi(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 bi(){let{projectName:e}=G(),{provider:t,model:n}=W(),r=W(e=>e.wsConnected),i=W(e=>e.wsUrl),a=K(e=>e.setCurrentView),[o,s]=(0,V.useState)(void 0);(0,V.useEffect)(()=>{if(!r)return;let e=H(i),t=e.on(`providers.saved`,e=>{let t=e.payload;s(t.providers?.length??0)});return e.listSavedProviders(),()=>{t()}},[r,i]);let c=K(e=>e.promptHistory).slice(0,6),{listSessions:l,resumeSession:u}=Y(),d=Kt(e=>e.entries);(0,V.useEffect)(()=>{r&&d.length===0&&l(10)},[r]);let f=K(e=>e.sessionNicknames),p=d.filter(e=>!e.isCurrent).slice(0,4);return(0,J.jsxs)(`div`,{className:`flex flex-col gap-8 py-8 px-2 max-w-5xl mx-auto w-full`,children:[(0,J.jsxs)(`div`,{className:`flex flex-col items-center text-center gap-3`,children:[(0,J.jsxs)(`div`,{className:`relative`,children:[(0,J.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,J.jsx)(I,{className:`h-7 w-7 text-primary-foreground`})}),(0,J.jsx)(`div`,{className:`absolute -inset-3 bg-gradient-to-r from-transparent via-primary/10 to-transparent animate-pulse rounded-full -z-10`})]}),(0,J.jsxs)(`div`,{children:[(0,J.jsxs)(`h2`,{className:`text-2xl font-semibold tracking-tight`,children:[`Where do you want to start`,e?(0,J.jsxs)(J.Fragment,{children:[` in `,(0,J.jsx)(`span`,{className:`text-primary`,children:e})]}):``,`?`]}),(0,J.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,J.jsx)(`span`,{className:`font-mono text-foreground/80`,children:`/`}),` for the full command palette.`]}),t&&n&&(0,J.jsxs)(`p`,{className:`text-xs text-muted-foreground/70 mt-2 font-mono`,children:[t,` / `,n]})]})]}),r&&o===0&&(0,J.jsxs)(`button`,{type:`button`,onClick:()=>a(`settings`),className:q(`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,J.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,J.jsx)(re,{className:`h-6 w-6`})}),(0,J.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,J.jsx)(`h3`,{className:`text-base font-semibold mb-1`,children:`No API key configured yet`}),(0,J.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,J.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,J.jsx)(Ze,{className:`h-3.5 w-3.5`})]})]}),(0,J.jsx)(`div`,{className:`grid grid-cols-1 lg:grid-cols-2 gap-4`,children:_i.map(e=>{let t=e.icon;return(0,J.jsxs)(`div`,{className:`rounded-xl border bg-card/40 backdrop-blur-sm p-4 flex flex-col gap-3`,children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,J.jsx)(`span`,{className:q(`flex items-center justify-center w-8 h-8 rounded-lg border`,e.tone),children:(0,J.jsx)(t,{className:`h-4 w-4`})}),(0,J.jsxs)(`div`,{children:[(0,J.jsx)(`h3`,{className:`text-sm font-semibold`,children:e.title}),(0,J.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:e.hint})]})]}),(0,J.jsx)(`div`,{className:`flex flex-col gap-1.5`,children:e.prompts.map((e,t)=>(0,J.jsx)(`button`,{type:`button`,onClick:()=>yi(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)})}),p.length>0&&(0,J.jsxs)(`div`,{className:`rounded-xl border bg-muted/20 p-4`,children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-2 mb-3`,children:[(0,J.jsx)(ye,{className:`h-4 w-4 text-muted-foreground`}),(0,J.jsx)(`span`,{className:`text-xs uppercase tracking-wider text-muted-foreground font-medium`,children:`Pick back up`})]}),(0,J.jsx)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-2`,children:p.map(e=>(0,J.jsxs)(`button`,{type:`button`,onClick:()=>u(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,J.jsx)(`div`,{className:`text-sm font-medium truncate text-foreground group-hover/sess:text-primary`,children:f[e.id]||e.title||`(empty)`}),(0,J.jsxs)(`div`,{className:`text-[10px] text-muted-foreground font-mono truncate mt-0.5`,children:[e.provider,`/`,e.model,e.tokenTotal>0&&(0,J.jsxs)(`span`,{className:`ml-2`,children:[`· `,e.tokenTotal.toLocaleString(),` tok`]})]})]},e.id))})]}),c.length>0&&(0,J.jsxs)(`div`,{className:`rounded-xl border bg-muted/20 p-4`,children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-2 mb-3`,children:[(0,J.jsx)(L,{className:`h-4 w-4 text-muted-foreground`}),(0,J.jsx)(`span`,{className:`text-xs uppercase tracking-wider text-muted-foreground font-medium`,children:`Recent prompts`})]}),(0,J.jsx)(`div`,{className:`flex flex-col gap-1.5`,children:c.filter(e=>!e.startsWith(`/`)).slice(0,5).map((e,t)=>(0,J.jsx)(`button`,{type:`button`,onClick:()=>yi(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,J.jsxs)(`div`,{className:`rounded-xl border bg-muted/20 p-4`,children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-2 mb-3`,children:[(0,J.jsx)(Se,{className:`h-4 w-4 text-muted-foreground`}),(0,J.jsx)(`span`,{className:`text-xs uppercase tracking-wider text-muted-foreground font-medium`,children:`Quick commands`})]}),(0,J.jsx)(`div`,{className:`grid grid-cols-2 md:grid-cols-4 gap-2`,children:vi.map(e=>(0,J.jsxs)(`button`,{type:`button`,onClick:()=>yi(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,J.jsx)(`span`,{className:`font-mono text-xs text-foreground`,children:e.name}),(0,J.jsx)(`span`,{className:`text-[11px] text-muted-foreground truncate`,children:e.hint})]},e.name))})]})]})}var xi=V.forwardRef(({className:e,children:t,...n},r)=>(0,J.jsxs)(nt,{ref:r,className:q(`relative overflow-hidden`,e),...n,children:[(0,J.jsx)(Pe,{className:`h-full w-full rounded-[inherit]`,children:t}),(0,J.jsx)(Si,{}),(0,J.jsx)(je,{})]}));xi.displayName=nt.displayName;var Si=V.forwardRef(({className:e,orientation:t=`vertical`,...n},r)=>(0,J.jsx)(Je,{ref:r,orientation:t,className:q(`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,J.jsx)(Ie,{className:`relative flex-1 rounded-full bg-border`})}));Si.displayName=Je.displayName;function Ci(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(e>=1e4?0:1)}k`:String(e)}function wi(){let e=U(e=>e.thinkingBuffer);if(!e)return null;let t=e.split(`
92
- `).slice(-6).join(`
93
- `).trim();return(0,J.jsxs)(`div`,{className:`flex gap-3 animate-message`,children:[(0,J.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,J.jsx)(n,{className:`h-4 w-4 animate-pulse`})}),(0,J.jsxs)(`div`,{className:`flex flex-col gap-1 max-w-[85%] min-w-0`,children:[(0,J.jsx)(`span`,{className:`text-xs font-medium text-violet-600 dark:text-violet-400 px-1`,children:`Thinking…`}),(0,J.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,J.jsx)(`pre`,{className:`whitespace-pre-wrap break-words font-sans text-xs leading-relaxed italic max-h-32 overflow-hidden`,children:t||`…`})})]})]})}function Ti(){let{messages:e,isLoading:t}=U(),n=K(e=>e.setPaletteOpen),r=K(e=>e.setShortcutsOpen),a=K(e=>e.sidebarOpen),s=K(e=>e.toggleSidebar),c=K(e=>e.compactMode),{totalTokens:l,startTime:d,lastInputTokens:f,maxContext:m,projectName:h,iteration:_,todos:v,mode:y}=G(),b=G(e=>e.session),x=b?.id,S=K(e=>x?e.sessionNicknames[x]:void 0),w=K(e=>e.setSessionNickname),T=b?.title,[E,D]=(0,V.useState)(!1),[O,k]=(0,V.useState)(``),A=Kt(e=>e.entries),[j,M]=(0,V.useState)(!1),N=(0,V.useRef)(null);(0,V.useEffect)(()=>{if(!j)return;let e=e=>{N.current?.contains(e.target)||M(!1)},t=e=>{e.key===`Escape`&&M(!1)};return document.addEventListener(`mousedown`,e),document.addEventListener(`keydown`,t),()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`keydown`,t)}},[j]);let{wsConnected:ee,wsStatus:P,provider:te,model:ne}=W(),{setCurrentView:re}=K(),ie=(0,V.useRef)(null),ae=Yt(e=>e.agents),se=Object.values(ae).filter(e=>e.status===`running`).length,ce=Object.values(ae).length,L=Zt(e=>e.goal),le=qt(e=>e.worktrees),ue=qt(e=>e.baseBranch),de=v.filter(e=>e.status===`pending`).length,fe=v.filter(e=>e.status===`in_progress`).length,pe=v.filter(e=>e.status===`completed`).length,[he,ge]=(0,V.useState)(`off`),_e=(0,V.useCallback)(e=>{ge(e),H()?.send?.({type:`autonomy.switch`,payload:{mode:e}})},[]),[R,ve]=(0,V.useState)(!1),[ye,xe]=(0,V.useState)(!1),Se=m>0&&f>0?Math.min(100,Math.round(f/m*100)):0,Ce=Se>=85?`bg-red-500/15 text-red-600 dark:text-red-400`:Se>=70?`bg-amber-500/15 text-amber-600 dark:text-amber-400`:`bg-muted text-muted-foreground`,[we,Te]=(0,V.useState)(!0),[Ee,De]=(0,V.useState)(0),[Oe,Ae]=(0,V.useState)(!1),je=(0,V.useRef)(e.length),Me=(0,V.useCallback)(()=>ie.current?.querySelector(`[data-radix-scroll-area-viewport]`)??null,[]);(0,V.useEffect)(()=>{let t=Me();if(!t)return;let n=()=>{let n=t.scrollHeight-t.scrollTop-t.clientHeight<120;Te(n),n&&(De(0),je.current=e.length),Ae(t.scrollTop>t.clientHeight&&t.scrollHeight>t.clientHeight*2.5)};return t.addEventListener(`scroll`,n,{passive:!0}),()=>t.removeEventListener(`scroll`,n)},[Me,e.length]),(0,V.useEffect)(()=>{let t=Me();if(t)if(we)t.scrollTop=t.scrollHeight,je.current=e.length;else{let t=e.length-je.current;t>0&&De(t)}},[e,we,Me]);let Ne=(0,V.useCallback)(()=>{let t=Me();t&&(t.scrollTo({top:t.scrollHeight,behavior:`smooth`}),Te(!0),De(0),je.current=e.length)},[Me,e.length]),Pe=(0,V.useCallback)(()=>{let e=Me();e&&e.scrollTo({top:0,behavior:`smooth`})},[Me]),[Fe,Ie]=(0,V.useState)(null),[Le,Re]=(0,V.useState)(()=>Date.now()),Be=(0,V.useRef)(null);(0,V.useEffect)(()=>{t&&Fe===null&&Ie(Date.now()),!t&&Fe!==null&&Ie(null)},[t,Fe]),(0,V.useEffect)(()=>{if(!t)return;let e=setInterval(()=>Re(Date.now()),500);return()=>clearInterval(e)},[t]);let Ve=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`},He=(()=>{if(!t)return`idle`;let n=e[e.length-1];return n?.role===`assistant`&&n.content&&n.streaming?`streaming`:`thinking`})(),We=He===`idle`?`bg-muted text-muted-foreground`:He===`streaming`?`bg-blue-500/10 text-blue-600 dark:text-blue-400`:`bg-amber-500/10 text-amber-600 dark:text-amber-400`,Ge=m>0&&f>0||l.input>0||!!d;return(0,J.jsxs)(`div`,{className:`flex flex-col flex-1 min-h-0`,children:[(0,J.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,J.jsxs)(`div`,{className:`flex items-center justify-between gap-2 px-3 py-2`,children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-1.5 min-w-0 flex-1`,children:[!a&&(0,J.jsx)(X,{variant:`ghost`,size:`icon`,className:`h-7 w-7 shrink-0`,onClick:s,title:`Open sidebar (Ctrl+\\\\)`,children:(0,J.jsx)(be,{className:`h-4 w-4`})}),!a&&(0,J.jsx)(`div`,{className:`flex items-center gap-1.5 shrink-0 mr-1`,children:(0,J.jsx)(`div`,{className:`w-5 h-5 rounded bg-primary flex items-center justify-center`,children:(0,J.jsx)(I,{className:`h-3 w-3 text-primary-foreground`})})}),(0,J.jsx)(Or,{wsStatus:P,wsConnected:ee}),(0,J.jsxs)(`span`,{className:q(`flex items-center gap-1 px-1.5 py-0.5 rounded-full text-[11px] font-medium shrink-0 tabular-nums`,We),title:`Agent state: ${He}`,children:[He!==`idle`&&(0,J.jsx)(`span`,{className:`h-1.5 w-1.5 rounded-full bg-current animate-pulse`}),(0,J.jsx)(`span`,{children:He})]}),h&&(0,J.jsxs)(`span`,{className:`flex items-center gap-1 text-[11px] text-muted-foreground shrink-0 min-w-0`,title:`Project: ${h}`,children:[(0,J.jsx)(i,{className:`h-3 w-3 shrink-0`}),(0,J.jsx)(`span`,{className:`truncate max-w-[8rem]`,children:h})]}),x&&(E?(0,J.jsx)(`input`,{value:O,onChange:e=>k(e.target.value),onBlur:()=>{O.trim()&&w(x,O),D(!1)},onKeyDown:e=>{e.key===`Enter`?(e.preventDefault(),O.trim()&&w(x,O),D(!1)):e.key===`Escape`&&(e.preventDefault(),D(!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,J.jsxs)(`button`,{type:`button`,onClick:()=>{k(S||T||``),D(!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,J.jsx)(ct,{className:`h-2.5 w-2.5 text-muted-foreground shrink-0`}),(0,J.jsx)(`span`,{className:`truncate`,children:S||T||`Untitled`})]})),A.length>1&&(0,J.jsxs)(`div`,{ref:N,className:`relative shrink-0`,children:[(0,J.jsxs)(`button`,{type:`button`,onClick:()=>M(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,J.jsx)(bt,{className:`h-3 w-3`}),(0,J.jsx)(me,{className:`h-2.5 w-2.5`})]}),j&&(0,J.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:A.slice(0,15).map(e=>(0,J.jsxs)(`button`,{type:`button`,onClick:()=>{H()?.resumeSession?.(e.id),M(!1)},className:q(`w-full text-left px-2 py-1.5 rounded text-xs hover:bg-accent transition-colors`,e.isCurrent&&`bg-primary/10`),children:[(0,J.jsx)(`div`,{className:`font-medium truncate`,children:e.title||`(empty)`}),(0,J.jsxs)(`div`,{className:`text-[10px] text-muted-foreground font-mono truncate`,children:[e.provider,`/`,e.model,` · `,e.tokenTotal.toLocaleString(),` tok`]})]},e.id))})]}),(0,J.jsxs)(`button`,{type:`button`,onClick:()=>K.getState().setModelSwitcherOpen(!0),className:`group 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,J.jsx)(F,{className:`h-3 w-3 text-muted-foreground group-hover:text-foreground shrink-0`}),(0,J.jsxs)(`span`,{className:`font-mono truncate max-w-[16rem]`,children:[(0,J.jsx)(`span`,{className:`text-muted-foreground`,children:te||`no-provider`}),(0,J.jsx)(`span`,{className:`text-muted-foreground/40 mx-0.5`,children:`/`}),(0,J.jsx)(`span`,{className:`font-medium`,children:ne||`no-model`})]})]}),(0,J.jsx)(si,{}),(0,J.jsx)(Ar,{}),_&&(0,J.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,J.jsx)(et,{className:`h-3 w-3 animate-pulse`}),`iter `,_.index,_.max>0?`/${_.max}`:``]}),(de>0||fe>0)&&(0,J.jsxs)(`button`,{type:`button`,className:`flex items-center gap-1 px-1.5 py-0.5 rounded-full text-[11px] font-medium bg-amber-500/10 text-amber-600 dark:text-amber-400 shrink-0 hover:bg-amber-500/20 transition-colors cursor-pointer`,title:`Todos: ${pe}/${v.length} done — click to jump`,onClick:()=>document.getElementById(`panel-todos`)?.scrollIntoView({behavior:`smooth`,block:`start`}),children:[(0,J.jsx)(g,{className:`h-3 w-3`}),pe,`/`,v.length]}),ce>0&&(0,J.jsxs)(`button`,{type:`button`,className:q(`flex items-center gap-1 px-1.5 py-0.5 rounded-full text-[11px] font-medium shrink-0 cursor-pointer transition-colors`,se>0?`bg-emerald-500/10 text-emerald-600 dark:text-emerald-400 hover:bg-emerald-500/20`:`bg-muted text-muted-foreground hover:bg-muted/80`),title:`Fleet: ${se}/${ce} running — click to jump`,onClick:()=>document.getElementById(`panel-fleet`)?.scrollIntoView({behavior:`smooth`,block:`start`}),children:[(0,J.jsx)(Ue,{className:`h-3 w-3`}),se,`/`,ce]}),L&&(0,J.jsxs)(`button`,{type:`button`,className:q(`flex items-center gap-1 px-1.5 py-0.5 rounded-full text-[11px] font-medium shrink-0 cursor-pointer transition-colors`,L.goalState===`active`?`bg-rose-500/10 text-rose-600 dark:text-rose-400 hover:bg-rose-500/20`:`bg-muted text-muted-foreground hover:bg-muted/80`),title:`Goal: ${L.progress}% — ${L.goal.slice(0,60)} — click to jump`,onClick:()=>document.getElementById(`panel-goal`)?.scrollIntoView({behavior:`smooth`,block:`start`}),children:[(0,J.jsx)(et,{className:`h-3 w-3`}),L.progress,`%`]}),ue&&(0,J.jsxs)(`button`,{type:`button`,className:`flex items-center gap-1 px-1.5 py-0.5 rounded-full text-[11px] font-medium bg-violet-500/10 text-violet-600 dark:text-violet-400 shrink-0 hover:bg-violet-500/20 transition-colors cursor-pointer`,title:`Branch: ${ue}${le.length>0?` · ${le.length} worktree${le.length===1?``:`s`}`:``} — click to jump`,onClick:()=>document.getElementById(`panel-worktree`)?.scrollIntoView({behavior:`smooth`,block:`start`}),children:[(0,J.jsx)(u,{className:`h-3 w-3`}),ue]}),(0,J.jsx)(gr,{value:he,onChange:_e,compact:!0})]}),(0,J.jsxs)(`div`,{className:`flex items-center gap-0.5 shrink-0`,children:[(0,J.jsx)(X,{variant:`ghost`,size:`icon`,className:`h-7 w-7`,onClick:()=>K.getState().toggleCompactMode(),title:`Toggle compact mode (Ctrl+Shift+D)`,children:(0,J.jsx)(oe,{className:`h-4 w-4`})}),(0,J.jsxs)(X,{variant:R?`secondary`:`ghost`,size:`icon`,className:q(`h-7 w-7 relative`,R&&`bg-amber-500/10 text-amber-600 dark:text-amber-400`),onClick:()=>ve(e=>!e),title:`Running processes`,children:[(0,J.jsx)(p,{className:`h-4 w-4`}),R&&(0,J.jsx)(`span`,{className:`absolute -bottom-0.5 left-1/2 -translate-x-1/2 w-1 h-1 rounded-full bg-amber-500`})]}),(0,J.jsxs)(X,{variant:ye?`secondary`:`ghost`,size:`icon`,className:q(`h-7 w-7 relative`,ye&&`bg-violet-500/10 text-violet-600 dark:text-violet-400`),onClick:()=>xe(e=>!e),title:`Session checkpoints — rewind`,children:[(0,J.jsx)(bt,{className:`h-4 w-4`}),ye&&(0,J.jsx)(`span`,{className:`absolute -bottom-0.5 left-1/2 -translate-x-1/2 w-1 h-1 rounded-full bg-violet-500`})]}),(0,J.jsx)(X,{variant:`ghost`,size:`icon`,className:`h-7 w-7`,onClick:()=>n(!0),title:`Command palette (Ctrl+K)`,children:(0,J.jsx)(o,{className:`h-4 w-4`})}),(0,J.jsx)(mi,{className:`mx-0.5`}),(0,J.jsx)(X,{variant:`ghost`,size:`icon`,className:`h-7 w-7 font-mono text-xs`,onClick:()=>r(!0),title:`Keyboard shortcuts (?)`,children:`?`}),(0,J.jsx)(X,{variant:`ghost`,size:`icon`,className:`h-7 w-7`,onClick:()=>re(`settings`),title:`Settings`,children:(0,J.jsx)(C,{className:`h-4 w-4`})})]})]}),Ge&&(0,J.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,J.jsxs)(`div`,{className:`flex items-center gap-3 min-w-0 flex-1 tabular-nums`,children:[m>0&&f>0&&(0,J.jsxs)(`span`,{className:q(`flex items-center gap-1 px-1.5 py-0.5 rounded-full font-medium shrink-0`,Ce),title:`Last input: ${f.toLocaleString()} / ${m.toLocaleString()} tokens`,children:[`ctx `,Se,`% · `,Ci(f),`/`,Ci(m)]}),l.input>0&&(0,J.jsxs)(J.Fragment,{children:[(0,J.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,J.jsx)(`span`,{className:`font-medium text-foreground`,children:Ci(l.input)}),(0,J.jsx)(`span`,{children:`in`})]}),(0,J.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,J.jsx)(`span`,{className:`font-medium text-foreground`,children:Ci(l.output)}),(0,J.jsx)(`span`,{children:`out`})]}),l.cacheRead&&l.cacheRead>0&&(()=>{let e=(l.cacheRead??0)+l.input,t=e>0?Math.round((l.cacheRead??0)/e*100):0;return(0,J.jsxs)(`span`,{className:`flex items-center gap-1`,title:`Cache hit ratio: ${t}%`,children:[(0,J.jsx)(`span`,{className:`font-medium text-foreground`,children:Ci(l.cacheRead)}),(0,J.jsxs)(`span`,{children:[`cache (`,t,`%)`]})]})})(),(0,J.jsx)(jr,{})]})]}),d&&(0,J.jsx)(`span`,{className:`text-muted-foreground/70 tabular-nums shrink-0`,children:Ve(d)})]})]}),(0,J.jsxs)(`div`,{className:`flex-1 relative overflow-hidden`,children:[(0,J.jsx)(li,{}),!we&&(0,J.jsxs)(`button`,{type:`button`,onClick:Ne,className:q(`absolute bottom-4 left-1/2 -translate-x-1/2 z-10`,`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,J.jsx)(ze,{className:`h-3.5 w-3.5`}),Ee>0?`${Ee} new message${Ee===1?``:`s`}`:`Jump to latest`]}),Oe&&(0,J.jsxs)(`button`,{type:`button`,onClick:Pe,title:`Scroll to top (oldest)`,className:q(`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,J.jsx)(pt,{className:`h-3 w-3`}),(0,J.jsx)(`span`,{children:`Top`})]}),(0,J.jsx)(xi,{className:`h-full`,ref:ie,children:(0,J.jsxs)(`div`,{className:q(`mx-auto pb-8`,c?`max-w-5xl p-3 space-y-3`:`max-w-5xl p-4 space-y-6`),children:[e.length===0&&!t&&(0,J.jsx)(bi,{}),(()=>{let n=[];for(let t=0;t<e.length;t++){let r=B(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=null,a=e=>{let t=new Date(e);return`${t.getFullYear()}-${t.getMonth()}-${t.getDate()}`},o=e=>{let t=new Date(e),n=new Date,r=new Date(Date.now()-864e5);return a(e)===a(n.getTime())?`Today`:a(e)===a(r.getTime())?`Yesterday`:t.toLocaleDateString(void 0,{weekday:`short`,month:`short`,day:`numeric`,year:t.getFullYear()===n.getFullYear()?void 0:`numeric`})},s=e=>{if(e.kind===`user`)return e.message.timestamp;let t=B(e.items[0]);return t.kind===`msg`?t.message.timestamp:t.tools[0]?.timestamp},l=[];for(let e=0;e<r.length;e++){let n=B(r[e]),u=s(n),d=a(u);if(d!==i&&(l.push((0,J.jsxs)(`div`,{className:`flex items-center gap-3 py-1 text-[11px] text-muted-foreground/70 uppercase tracking-wider font-medium`,children:[(0,J.jsx)(`div`,{className:`flex-1 h-px bg-border/50`}),(0,J.jsx)(`span`,{children:o(u)}),(0,J.jsx)(`div`,{className:`flex-1 h-px bg-border/50`})]},`day-${d}-${e}`)),i=d),n.kind===`user`){l.push((0,J.jsx)(oi,{message:n.message,isFirst:!0},n.key));continue}let f=e===r.length-1;l.push((0,J.jsx)(`div`,{className:q(c?`space-y-1`:`space-y-1.5`),children:n.items.map((e,r)=>{let i=r>0;if(e.kind===`msg`)return(0,J.jsx)(oi,{message:e.message,isFirst:!i&&e.isFirst,isContinuation:i},e.message.id);let a=f&&r===n.items.length-1&&t&&e.tools.some(e=>e.toolResult===void 0);return(0,J.jsx)(gi,{tools:e.tools,defaultOpen:a,isContinuation:i},e.key)})},n.key))}return l})(),(0,J.jsxs)(`div`,{id:`chat-activity`,children:[(0,J.jsx)(wi,{}),t&&(()=>{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=Fe?Math.max(0,Math.floor((Le-Fe)/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=Be.current;if(!e||e.id!==s.id)Be.current={id:s.id,at:Date.now(),len:s.content.length};else{let t=Math.max(1,Le-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 Be.current&&=null;return(0,J.jsxs)(`div`,{className:`flex gap-3 animate-message`,children:[(0,J.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,J.jsx)(ke,{className:`h-4 w-4`})}),(0,J.jsx)(`div`,{className:`flex flex-col gap-1.5`,children:(0,J.jsx)(`div`,{className:`rounded-2xl px-4 py-3 bg-card border text-foreground`,children:(0,J.jsxs)(`div`,{className:`flex items-center gap-3 text-sm`,children:[(0,J.jsxs)(`span`,{className:`flex gap-1`,children:[(0,J.jsx)(`span`,{className:`h-1.5 w-1.5 rounded-full bg-primary/70 animate-bounce [animation-delay:-0.3s]`}),(0,J.jsx)(`span`,{className:`h-1.5 w-1.5 rounded-full bg-primary/70 animate-bounce [animation-delay:-0.15s]`}),(0,J.jsx)(`span`,{className:`h-1.5 w-1.5 rounded-full bg-primary/70 animate-bounce`})]}),(0,J.jsx)(`span`,{className:`text-foreground/90`,children:r}),(0,J.jsx)(`span`,{className:`text-xs text-muted-foreground tabular-nums`,children:a}),_&&(0,J.jsxs)(`span`,{className:`text-xs text-muted-foreground tabular-nums`,children:[`· iter `,_.index,_.max>0?`/${_.max}`:``]}),o&&(0,J.jsxs)(`span`,{className:`text-xs text-muted-foreground/80 tabular-nums`,children:[`· `,o]})]})})})]})})()]})]})})]}),(0,J.jsx)(`div`,{className:`border-t bg-card/50 backdrop-blur supports-[backdrop-filter]:bg-card/50 p-4 shrink-0`,children:(0,J.jsxs)(`div`,{className:`max-w-5xl mx-auto`,children:[(0,J.jsx)(Er,{}),(0,J.jsx)(`p`,{className:`text-xs text-center text-muted-foreground/50 mt-2`,children:`Press Enter to send, Shift+Enter for new line`})]})}),(0,J.jsx)(ci,{open:R,onClose:()=>ve(!1)}),(0,J.jsx)(Dr,{open:ye,onClose:()=>xe(!1)})]})}function Ei({sessionId:e,className:t}){let[n,r]=(0,V.useState)([]),[i,a]=(0,V.useState)(!1),[o,s]=(0,V.useState)(null),[c,l]=(0,V.useState)(null),[u,d]=(0,V.useState)(0),[f,p]=(0,V.useState)(!1),m=H(W(e=>e.wsUrl));(0,V.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,J.jsxs)(`div`,{className:q(`flex items-center gap-2 px-3 py-2 rounded-md border border-dashed border-border bg-card/40`,t),children:[(0,J.jsx)(Ue,{className:`w-4 h-4 text-muted-foreground`}),(0,J.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`No live observers`}),(0,J.jsxs)(`div`,{className:`ml-auto flex items-center gap-1`,children:[(0,J.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,J.jsx)(Fe,{className:`w-3 h-3`}),`observer`]}),(0,J.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,J.jsx)(rt,{className:`w-3 h-3`}),`annotator`]}),(0,J.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,J.jsx)(Be,{className:`w-3 h-3`}),`controller`]})]})]}):c?(0,J.jsxs)(`div`,{className:q(`flex items-center gap-2 px-3 py-2 rounded-md border border-destructive/50 bg-destructive/10`,t),role:`alert`,children:[(0,J.jsxs)(`span`,{className:`text-xs text-destructive`,children:[`Collab: `,c]}),(0,J.jsx)(`button`,{type:`button`,onClick:()=>{l(null),a(!1)},className:`ml-auto text-xs underline text-destructive`,children:`dismiss`})]}):(0,J.jsxs)(`div`,{className:q(`flex items-center gap-2 px-3 py-2 rounded-md border border-emerald-500/40 bg-emerald-500/5`,t),children:[(0,J.jsxs)(`span`,{className:`relative flex h-2 w-2`,"aria-label":`Live`,children:[(0,J.jsx)(`span`,{className:`absolute inline-flex h-full w-full rounded-full bg-emerald-400 opacity-75 animate-ping`}),(0,J.jsx)(`span`,{className:`relative inline-flex rounded-full h-2 w-2 bg-emerald-500`})]}),(0,J.jsx)(Ue,{className:`w-4 h-4 text-emerald-700 dark:text-emerald-400`}),(0,J.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,J.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,J.jsx)(rt,{className:`w-3 h-3`}),u,` note`,u===1?``:`s`]}),f&&(0,J.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,J.jsx)(Be,{className:`w-3 h-3`}),`paused`]}),(0,J.jsxs)(`div`,{className:`flex items-center gap-1 ml-2`,children:[n.slice(0,3).map(e=>(0,J.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,J.jsx)(ee,{className:`w-3 h-3`}),e.role]},e.participantId)),n.length>3&&(0,J.jsxs)(`span`,{className:`text-[10px] text-muted-foreground`,children:[`+`,n.length-3]})]}),i&&o===`controller`&&(f?(0,J.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,J.jsx)(Ae,{className:`w-3 h-3`}),`Resume`]}):(0,J.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,J.jsx)(Be,{className:`w-3 h-3`}),`Pause agent`]})),i&&o!==`controller`&&(0,J.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,J.jsx)(Le,{className:`w-3 h-3`}),`Leave`]})]})}var Di=ht,Oi=Ge,ki=V.forwardRef(({className:e,...t},n)=>(0,J.jsx)(Ce,{ref:n,className:q(`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}));ki.displayName=Ce.displayName;var Ai=V.forwardRef(({className:e,children:t,...n},r)=>(0,J.jsxs)(Oi,{children:[(0,J.jsx)(ki,{}),(0,J.jsxs)($e,{ref:r,className:q(`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,J.jsxs)(ve,{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,J.jsx)(s,{className:`h-4 w-4`}),(0,J.jsx)(`span`,{className:`sr-only`,children:`Close`})]})]})]}));Ai.displayName=$e.displayName;var ji=({className:e,...t})=>(0,J.jsx)(`div`,{className:q(`flex flex-col space-y-1.5 text-center sm:text-left`,e),...t});ji.displayName=`DialogHeader`;var Mi=({className:e,...t})=>(0,J.jsx)(`div`,{className:q(`flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2`,e),...t});Mi.displayName=`DialogFooter`;var Ni=V.forwardRef(({className:e,...t},n)=>(0,J.jsx)(Ee,{ref:n,className:q(`text-lg font-semibold leading-none tracking-tight`,e),...t}));Ni.displayName=Ee.displayName;var Pi=V.forwardRef(({className:e,...t},n)=>(0,J.jsx)(lt,{ref:n,className:q(`text-sm text-muted-foreground`,e),...t}));Pi.displayName=lt.displayName;function Fi(e){return/edit|write|create|patch/i.test(e)?O:/bash|shell|exec|run|command/i.test(e)?p:/fetch|http|web|curl|request/i.test(e)?f:yt}function Ii({toolName:e,input:t}){let n=Br(e,t);if(n)return(0,J.jsx)(`div`,{className:`rounded-lg overflow-hidden border`,children:(0,J.jsx)(Lr,{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,J.jsxs)(`div`,{className:`rounded-lg border bg-background/40 overflow-hidden`,children:[(0,J.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,J.jsx)(p,{className:`h-3 w-3`}),(0,J.jsx)(`span`,{children:`Command`})]}),(0,J.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,J.jsxs)(`div`,{className:`rounded-lg border bg-background/40 px-3 py-2 text-xs font-mono`,children:[(0,J.jsx)(`span`,{className:`text-muted-foreground`,children:(e.method??`GET`).toUpperCase()}),` `,(0,J.jsx)(`span`,{className:`break-all`,children:r})]})}return(0,J.jsxs)(`div`,{className:`p-3 rounded-lg bg-muted/50 border text-xs font-mono`,children:[(0,J.jsx)(`div`,{className:`text-muted-foreground mb-2`,children:`Input:`}),(0,J.jsx)(`pre`,{className:`whitespace-pre-wrap break-all max-h-60 overflow-auto`,children:JSON.stringify(t,null,2)})]})}function Li(){let{showConfirmDialog:e,confirmInfo:t,hideConfirm:n}=K(),{sendConfirm:r}=Y(),i=(0,V.useRef)(null),a=e=>{t&&r(t.id,e),n()};if((0,V.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,J.jsx)(Di,{open:e,onOpenChange:()=>n(),children:(0,J.jsx)(Ai,{})});let o=Fi(t.toolName),s=/edit|write/i.test(t.toolName);return(0,J.jsx)(Di,{open:e,onOpenChange:()=>n(),children:(0,J.jsxs)(Ai,{className:`sm:max-w-2xl border-yellow-500/50`,ref:i,tabIndex:-1,children:[(0,J.jsxs)(ji,{children:[(0,J.jsxs)(Ni,{className:`flex items-center gap-2`,children:[(0,J.jsx)(h,{className:`h-5 w-5 text-yellow-500 animate-pulse`}),`Approval required: `,t.toolName]}),(0,J.jsxs)(Pi,{children:[`The agent wants to `,s?`modify a file`:`run this tool`,`. Review the request below and decide whether to proceed.`]})]}),(0,J.jsxs)(`div`,{className:`py-2 space-y-3`,children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-3 p-3 rounded-lg bg-muted`,children:[(0,J.jsx)(o,{className:`h-5 w-5 text-muted-foreground`}),(0,J.jsxs)(`div`,{className:`min-w-0`,children:[(0,J.jsx)(`div`,{className:`font-medium font-mono truncate`,children:t.toolName}),(0,J.jsxs)(`div`,{className:`text-xs text-muted-foreground`,children:[s?`File modification`:`Tool execution`,` — preview below`]})]})]}),t.input!==void 0&&(0,J.jsx)(Ii,{toolName:t.toolName,input:t.input}),t.suggestedPattern&&(0,J.jsxs)(`div`,{className:`flex items-start gap-2 p-3 rounded-lg bg-yellow-500/10 border border-yellow-500/20`,children:[(0,J.jsx)(Ve,{className:`h-4 w-4 text-yellow-600 mt-0.5 shrink-0`}),(0,J.jsxs)(`div`,{className:`text-sm min-w-0`,children:[(0,J.jsx)(`div`,{className:`font-medium text-yellow-800 dark:text-yellow-200`,children:`Trust pattern suggestion`}),(0,J.jsx)(`div`,{className:`font-mono text-xs mt-1 break-all`,children:t.suggestedPattern}),(0,J.jsxs)(`div`,{className:`text-xs text-muted-foreground mt-1`,children:[`Picking `,(0,J.jsx)(`span`,{className:`font-medium`,children:`Always`}),` will whitelist matching calls for this project.`]})]})]})]}),(0,J.jsxs)(Mi,{className:`gap-2 sm:gap-2 flex-wrap`,children:[(0,J.jsxs)(X,{variant:`outline`,size:`sm`,onClick:()=>a(`deny`),title:`Reject this and all future calls matching the pattern (d)`,children:[`Deny always `,(0,J.jsx)(`kbd`,{className:`ml-1 text-[10px] border rounded px-1 bg-background`,children:`d`})]}),(0,J.jsxs)(X,{variant:`outline`,size:`sm`,onClick:()=>a(`no`),title:`Reject this single call (Esc / n)`,children:[`No `,(0,J.jsx)(`kbd`,{className:`ml-1 text-[10px] border rounded px-1 bg-background`,children:`n`})]}),(0,J.jsxs)(X,{variant:`outline`,size:`sm`,onClick:()=>a(`always`),title:`Approve and remember the pattern for the project (a)`,children:[`Always `,(0,J.jsx)(`kbd`,{className:`ml-1 text-[10px] border rounded px-1 bg-background`,children:`a`})]}),(0,J.jsxs)(X,{size:`sm`,onClick:()=>a(`yes`),title:`Approve this single call (y)`,children:[`Yes `,(0,J.jsx)(`kbd`,{className:`ml-1 text-[10px] border rounded px-1 bg-background/80`,children:`y`})]})]})]})})}function Ri(){let e=W(e=>e.wsStatus),t=W(e=>e.wsUrl),[n,r]=(0,V.useState)(!1),[i,a]=(0,V.useState)(Date.now());if((0,V.useEffect)(()=>{if(e.state!==`reconnecting`)return;let t=setInterval(()=>a(Date.now()),500);return()=>clearInterval(t)},[e.state]),(0,V.useEffect)(()=>{e.state===`open`&&r(!1)},[e.state]),e.state===`open`||e.state===`connecting`||n)return null;let o=()=>H(t).retryNow(),c=e.state===`reconnecting`,l=e.state===`closed`?e.error:e.state===`reconnecting`?e.lastError:void 0,u=c?Math.max(0,Math.ceil((e.nextRetryAt-i)/1e3)):0;return(0,J.jsxs)(`div`,{className:q(`flex items-center gap-3 px-4 py-2 border-b text-sm`,c?`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:[c?(0,J.jsx)(R,{className:`h-4 w-4 animate-spin shrink-0`}):(0,J.jsx)(d,{className:`h-4 w-4 shrink-0`}),(0,J.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,J.jsx)(`div`,{className:`font-medium`,children:c?`Reconnecting to backend (attempt ${e.attempt}) — retrying in ${u}s`:`Disconnected from backend`}),l&&(0,J.jsx)(`div`,{className:`text-xs opacity-80 truncate`,children:l})]}),(0,J.jsxs)(`button`,{type:`button`,onClick:o,className:q(`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`,c?`border-orange-500/40`:`border-red-500/40`),title:`Retry connection now`,children:[(0,J.jsx)(pe,{className:`h-3 w-3`}),`Retry now`]}),(0,J.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,J.jsx)(s,{className:`h-4 w-4`})})]})}var zi=class extends V.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,J.jsx)(`div`,{className:`flex items-center justify-center h-screen bg-background`,children:(0,J.jsxs)(`div`,{className:`flex flex-col items-center gap-4 p-8 max-w-md text-center`,children:[(0,J.jsx)(Ve,{className:`h-12 w-12 text-destructive`}),(0,J.jsx)(`h1`,{className:`text-lg font-semibold`,children:`Something went wrong`}),(0,J.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,J.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,J.jsxs)(`div`,{className:`flex gap-2`,children:[(0,J.jsxs)(X,{size:`sm`,variant:`outline`,onClick:()=>window.location.reload(),children:[(0,J.jsx)(he,{className:`h-4 w-4 mr-1`}),`Reload page`]}),(0,J.jsx)(X,{size:`sm`,onClick:this.handleReset,children:`Try again`})]})]})}):this.props.children}},Bi={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 Vi(e){return e<=0?`$0`:e>=.01?`$${e.toFixed(3)}`:`$${e.toFixed(5)}`.replace(/0+$/,``).replace(/\.$/,``)}function Hi(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}K`:String(e)}function Ui(e){let t=Math.floor(e/1e3);return t<60?`${t}s`:`${Math.floor(t/60)}m ${t%60}s`}function Wi({agent:e,onClose:t}){let n=Bi[e.status],r=e.status===`running`,i=e.currentTool??e.lastTool,a=Date.now()-e.startedAt,[o,c]=(0,V.useState)(!1),l=(0,V.useCallback)(async e=>{try{await navigator.clipboard.writeText(e),c(!0),setTimeout(()=>c(!1),2e3)}catch{}},[]),u=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,J.jsx)(`div`,{className:`fixed inset-0 z-50 flex items-start justify-center pt-[10vh] bg-black/40 backdrop-blur-sm`,children:(0,J.jsxs)(`div`,{className:`w-full max-w-xl max-h-[80vh] overflow-y-auto rounded-xl border bg-card shadow-2xl`,children:[(0,J.jsxs)(`div`,{className:q(`flex items-center justify-between px-4 py-3 border-b`,r?`border-primary/20`:`border-border`),children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,J.jsx)(`span`,{className:q(`led`,n.led,n.pulse&&`led-pulse`)}),(0,J.jsx)(`h3`,{className:`text-sm font-semibold`,children:e.name}),(0,J.jsx)(`span`,{className:`text-[10px] uppercase tracking-wider text-muted-foreground`,children:n.label})]}),(0,J.jsx)(`button`,{type:`button`,onClick:t,className:`p-1 rounded-md hover:bg-muted transition-colors`,children:(0,J.jsx)(s,{className:`h-4 w-4`})})]}),(0,J.jsxs)(`div`,{className:`p-4 space-y-4`,children:[e.description&&(0,J.jsx)(`div`,{className:`text-xs text-muted-foreground leading-relaxed`,children:e.description}),(0,J.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,J.jsxs)(`div`,{className:`rounded-lg border bg-muted/30 px-3 py-2`,children:[(0,J.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:`Provider / Model`}),(0,J.jsxs)(`div`,{className:`flex items-center gap-1 mt-0.5`,children:[(0,J.jsx)(F,{className:`h-3 w-3 text-muted-foreground`}),(0,J.jsxs)(`span`,{className:`text-xs font-mono font-medium`,children:[e.provider??`?`,`/`,e.model??`?`]})]})]}),(0,J.jsxs)(`div`,{className:`rounded-lg border bg-muted/30 px-3 py-2`,children:[(0,J.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:`Elapsed`}),(0,J.jsxs)(`div`,{className:`flex items-center gap-1 mt-0.5`,children:[(0,J.jsx)(L,{className:`h-3 w-3 text-muted-foreground`}),(0,J.jsx)(`span`,{className:`text-xs font-mono tabular`,children:Ui(a)}),r&&(0,J.jsx)(`span`,{className:`text-[10px] text-[hsl(var(--success))]`,children:`· running`})]})]}),(0,J.jsxs)(`div`,{className:`rounded-lg border bg-muted/30 px-3 py-2`,children:[(0,J.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:`Iterations`}),(0,J.jsx)(`span`,{className:`block text-xs font-mono font-medium mt-0.5 tabular`,children:e.iteration})]}),(0,J.jsxs)(`div`,{className:`rounded-lg border bg-muted/30 px-3 py-2`,children:[(0,J.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:`Tool Calls`}),(0,J.jsx)(`span`,{className:`block text-xs font-mono font-medium mt-0.5 tabular`,children:e.toolCalls})]}),(0,J.jsxs)(`div`,{className:`rounded-lg border bg-muted/30 px-3 py-2`,children:[(0,J.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:`Cost`}),(0,J.jsx)(`span`,{className:`block text-xs font-mono font-medium mt-0.5 tabular`,children:Vi(e.costUsd)})]}),e.extensions>0&&(0,J.jsxs)(`div`,{className:`rounded-lg border bg-muted/30 px-3 py-2`,children:[(0,J.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:`Budget Extensions`}),(0,J.jsx)(`span`,{className:`block text-xs font-mono font-medium mt-0.5 tabular`,children:e.extensions})]})]}),e.maxContext>0&&(0,J.jsxs)(`div`,{className:`space-y-1`,children:[(0,J.jsxs)(`div`,{className:`flex items-center justify-between text-[10px]`,children:[(0,J.jsx)(`span`,{className:`text-muted-foreground`,children:`Context window`}),(0,J.jsxs)(`span`,{className:q(`tabular font-medium`,u.replace(/bg-\S+\s*/g,``)),children:[e.ctxPct,`%`]})]}),(0,J.jsx)(`div`,{className:`h-1.5 w-full overflow-hidden rounded-full bg-muted`,children:(0,J.jsx)(`div`,{className:q(`h-full rounded-full transition-all`,e.ctxPct>=85?`bg-destructive`:e.ctxPct>=70?`bg-[hsl(var(--warning))]`:`bg-primary`),style:{width:`${Math.max(2,e.ctxPct)}%`}})}),(0,J.jsxs)(`div`,{className:`text-[10px] text-muted-foreground tabular text-right`,children:[Hi(e.ctxTokens),` / `,Hi(e.maxContext),` tokens`]})]}),i&&(0,J.jsxs)(`div`,{className:q(`flex items-center gap-2 rounded-lg border px-3 py-2`,r?`border-primary/30 bg-primary/[0.04]`:`border-border bg-muted/30`),children:[(0,J.jsx)(yt,{className:q(`h-3.5 w-3.5`,r?`text-primary animate-pulse`:`text-muted-foreground`)}),(0,J.jsx)(`span`,{className:`text-xs font-mono`,children:i}),(0,J.jsx)(`span`,{className:`text-[10px] text-muted-foreground ml-auto`,children:e.currentTool?`running…`:`last tool`})]}),e.error&&(0,J.jsxs)(`div`,{className:`rounded-lg border border-destructive/30 bg-destructive/5 p-3`,children:[(0,J.jsx)(`span`,{className:`text-[10px] font-semibold text-destructive uppercase tracking-wider`,children:`Error`}),(0,J.jsx)(`p`,{className:`text-xs text-destructive/90 mt-1 leading-relaxed`,children:e.error.message})]}),e.finalText?(0,J.jsxs)(`div`,{className:`rounded-lg border bg-muted/20 p-3`,children:[(0,J.jsxs)(`div`,{className:`flex items-center justify-between mb-1.5`,children:[(0,J.jsx)(`span`,{className:`text-[10px] font-semibold text-muted-foreground uppercase tracking-wider`,children:`Final Output`}),(0,J.jsxs)(`button`,{type:`button`,onClick:()=>l(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:[o?(0,J.jsx)(fe,{className:`h-3 w-3 text-emerald-500`}):(0,J.jsx)(Et,{className:`h-3 w-3`}),o?`Copied`:`Copy`]})]}),(0,J.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,J.jsxs)(`div`,{className:`rounded-lg border bg-muted/20 p-3`,children:[(0,J.jsxs)(`div`,{className:`flex items-center justify-between mb-1.5`,children:[(0,J.jsx)(`span`,{className:`text-[10px] font-semibold text-muted-foreground uppercase tracking-wider`,children:`Live Output`}),(0,J.jsxs)(`button`,{type:`button`,onClick:()=>l(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:[o?(0,J.jsx)(fe,{className:`h-3 w-3 text-emerald-500`}):(0,J.jsx)(Et,{className:`h-3 w-3`}),o?`Copied`:`Copy`]})]}),(0,J.jsx)(`pre`,{className:`text-xs whitespace-pre-wrap font-mono text-foreground/80 leading-relaxed max-h-48 overflow-y-auto`,children:e.partialText})]}):r?(0,J.jsxs)(`div`,{className:`rounded-lg border border-dashed border-border p-3 text-center`,children:[(0,J.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`Waiting for output…`}),(0,J.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,J.jsxs)(`div`,{className:`space-y-1`,children:[(0,J.jsxs)(`span`,{className:`text-[10px] font-semibold text-muted-foreground uppercase tracking-wider`,children:[`Tool Log (`,e.toolLog.length,`)`]}),(0,J.jsxs)(`div`,{className:`max-h-40 overflow-y-auto space-y-0.5`,children:[e.toolLog.slice(0,15).map((e,t)=>(0,J.jsxs)(`div`,{className:q(`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,J.jsx)(`span`,{className:q(`led shrink-0`,e.ok?`text-[hsl(var(--success))]`:`text-destructive`)}),(0,J.jsx)(`span`,{className:`font-mono truncate flex-1`,children:e.name}),(0,J.jsxs)(`span`,{className:`tabular text-muted-foreground`,children:[e.durationMs,`ms`]}),!e.ok&&(0,J.jsx)(`span`,{className:`text-destructive font-medium`,children:`fail`})]},`${e.name}-${e.at}-${t}`)),e.toolLog.length>15&&(0,J.jsxs)(`p`,{className:`text-[9px] text-muted-foreground text-center px-2 py-0.5`,children:[`+`,e.toolLog.length-15,` more tools`]})]})]})]})]})})}function Gi({a:e,onClick:t}){let n=Bi[e.status],r=e.status===`running`,i=e.currentTool??e.lastTool;return(0,J.jsxs)(`button`,{type:`button`,onClick:t,className:q(`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]`,r?`border-primary/30 bg-primary/[0.04]`:`border-border bg-card opacity-85`),children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-1.5 min-w-0`,children:[(0,J.jsx)(`span`,{className:q(`led shrink-0`,n.led,n.pulse&&`led-pulse`)}),(0,J.jsx)(`span`,{className:`truncate text-[11px] font-semibold text-foreground`,title:e.name,children:e.name}),(0,J.jsxs)(`span`,{className:`tabular ml-auto shrink-0 text-[10px] text-muted-foreground`,children:[e.iteration,`it · `,e.toolCalls,`t`]})]}),(0,J.jsxs)(`div`,{className:`flex items-center gap-1.5 min-w-0`,children:[e.model&&(0,J.jsxs)(`span`,{className:`flex items-center gap-0.5 text-[10px] text-muted-foreground truncate`,title:`${e.provider??``}/${e.model}`,children:[(0,J.jsx)(F,{className:`h-2.5 w-2.5 shrink-0`}),(0,J.jsx)(`span`,{className:`truncate font-mono`,children:e.model})]}),(0,J.jsx)(`span`,{className:`tabular text-[10px] text-foreground/75 ml-auto`,children:Vi(e.costUsd)})]}),i&&(0,J.jsxs)(`div`,{className:q(`flex items-center gap-1 text-[10px] truncate`,r?`text-primary`:`text-muted-foreground`),title:e.currentTool?`running ${i}`:`last: ${i}`,children:[(0,J.jsx)(yt,{className:q(`h-2.5 w-2.5 shrink-0`,r&&`animate-pulse`)}),(0,J.jsx)(`span`,{className:`truncate font-mono`,children:i})]}),r&&e.maxContext>0&&(0,J.jsxs)(`div`,{className:`flex items-center gap-1`,title:`Context ${e.ctxPct}%`,children:[(0,J.jsx)(`div`,{className:`h-1 flex-1 overflow-hidden rounded-full bg-muted`,children:(0,J.jsx)(`div`,{className:q(`h-full rounded-full transition-all`,e.ctxPct>=85?`bg-destructive`:e.ctxPct>=70?`bg-[hsl(var(--warning))]`:`bg-primary`),style:{width:`${Math.max(2,e.ctxPct)}%`}})}),(0,J.jsxs)(`span`,{className:`tabular text-[9px] text-muted-foreground`,children:[e.ctxPct,`%`]})]}),e.error&&(0,J.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 Ki({className:e}){let t=Yt(e=>e.agents),[n,r]=(0,V.useState)(!0),[i,a]=(0,V.useState)(null),o=(0,V.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,J.jsxs)(J.Fragment,{children:[(0,J.jsxs)(`div`,{className:q(`rounded-lg border border-border bg-card/50 backdrop-blur-sm overflow-hidden`,e),children:[(0,J.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,J.jsx)(ke,{className:`h-3.5 w-3.5 text-primary`}),(0,J.jsx)(`span`,{className:`text-[11px] font-semibold text-foreground`,children:`Fleet`}),(0,J.jsxs)(`span`,{className:`flex items-center gap-1.5 ml-auto text-[10px]`,children:[c.length>0&&(0,J.jsxs)(`span`,{className:`flex items-center gap-1 text-[hsl(var(--success))]`,children:[(0,J.jsx)(`span`,{className:`led led-pulse text-[hsl(var(--success))]`}),c.length]}),l.length>0&&(0,J.jsxs)(`span`,{className:`text-muted-foreground`,children:[l.length,` done`]}),u.length>0&&(0,J.jsxs)(`span`,{className:`text-destructive`,children:[u.length,` err`]}),d>0&&(0,J.jsx)(`span`,{className:`tabular text-foreground/70`,children:Vi(d)})]}),f?(0,J.jsx)(S,{className:`h-3.5 w-3.5 text-muted-foreground shrink-0`}):(0,J.jsx)(me,{className:`h-3.5 w-3.5 text-muted-foreground shrink-0`})]}),!f&&(0,J.jsx)(`div`,{className:`flex gap-2 overflow-x-auto px-2 pb-2`,children:o.map(e=>(0,J.jsx)(Gi,{a:e,onClick:()=>a(e.id)},e.id))})]}),s&&(0,J.jsx)(Wi,{agent:s,onClose:()=>a(null)})]})}var qi={up:(0,J.jsx)(D,{className:`h-3.5 w-3.5 text-emerald-500`}),down:(0,J.jsx)(k,{className:`h-3.5 w-3.5 text-red-500`}),stable:(0,J.jsx)(Oe,{className:`h-3.5 w-3.5 text-amber-500`})},Ji={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 Yi({goal:e,className:t}){let[n,r]=(0,V.useState)(!1);if((0,V.useEffect)(()=>{let e=H();e?.send?.({type:`goal.get`});let t=setInterval(()=>{e?.send?.({type:`goal.get`})},1e4);return()=>clearInterval(t)},[]),!e||e.goalState===`completed`||e.goalState===`failed`||e.goalState===`abandoned`)return null;(0,V.useEffect)(()=>{(!e||e.goalState===`completed`||e.goalState===`failed`||e.goalState===`abandoned`)&&r(!0)},[e]);let i=Ji[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?qi[e.progressTrend]:null;return(0,J.jsxs)(`div`,{className:q(`rounded-lg border border-border bg-card/60 backdrop-blur-sm`,t),children:[(0,J.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,J.jsx)(y,{className:`h-4 w-4 text-rose-500`}),(0,J.jsx)(`span`,{className:`text-xs font-semibold text-foreground flex-1 min-w-0 truncate`,children:`Goal`}),(0,J.jsx)(`span`,{className:q(`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,J.jsx)(S,{className:`h-3.5 w-3.5 text-muted-foreground shrink-0`}):(0,J.jsx)(me,{className:`h-3.5 w-3.5 text-muted-foreground shrink-0`})]}),!n&&(0,J.jsxs)(`div`,{className:`px-3 pb-3 space-y-3 border-t pt-2`,children:[(0,J.jsxs)(`div`,{children:[(0,J.jsx)(`p`,{className:`text-xs text-foreground leading-relaxed whitespace-pre-wrap break-words`,children:e.goal}),e.refinedGoal&&e.refinedGoal!==e.goal&&(0,J.jsxs)(`div`,{className:`mt-1.5 p-2 rounded bg-accent/40 border border-border/50`,children:[(0,J.jsx)(`p`,{className:`text-[10px] text-muted-foreground mb-0.5 uppercase tracking-wider font-medium`,children:`Refined`}),(0,J.jsx)(`p`,{className:`text-xs leading-relaxed whitespace-pre-wrap break-words`,children:e.refinedGoal})]})]}),(0,J.jsxs)(`div`,{className:`space-y-1`,children:[(0,J.jsxs)(`div`,{className:`flex items-center justify-between text-[10px]`,children:[(0,J.jsx)(`span`,{className:`text-muted-foreground uppercase tracking-wider font-medium`,children:`Progress`}),(0,J.jsxs)(`span`,{className:`flex items-center gap-1 tabular-nums`,children:[c,(0,J.jsxs)(`span`,{className:`font-medium text-foreground`,children:[e.progress,`%`]})]})]}),(0,J.jsx)(`div`,{className:`h-1.5 bg-muted rounded-full overflow-hidden`,children:(0,J.jsx)(`div`,{className:q(`h-full transition-all duration-700 rounded-full`,e.progress>=80?`bg-emerald-500`:e.progress>=50?`bg-amber-500`:`bg-primary`),style:{width:`${Math.max(2,e.progress)}%`}})}),e.progressNote&&(0,J.jsx)(`p`,{className:`text-[10px] text-muted-foreground italic`,children:e.progressNote})]}),(0,J.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[10px] text-muted-foreground`,children:[(0,J.jsx)(L,{className:`h-3 w-3`}),(0,J.jsx)(`span`,{className:`tabular-nums font-medium`,children:e.iterations}),(0,J.jsx)(`span`,{children:`iterations`}),e.lastStatus&&(0,J.jsx)(`span`,{className:`text-border`,children:`·`}),e.lastStatus&&(0,J.jsx)(`span`,{className:`truncate`,children:e.lastStatus})]}),o>0&&(0,J.jsxs)(`div`,{className:`space-y-1`,children:[(0,J.jsxs)(`div`,{className:`flex items-center justify-between text-[10px] text-muted-foreground uppercase tracking-wider font-medium`,children:[(0,J.jsx)(`span`,{children:`Deliverables`}),(0,J.jsxs)(`span`,{className:`tabular-nums`,children:[a,`/`,o]})]}),(0,J.jsx)(`ul`,{className:`space-y-0.5`,children:e.deliverables?.map(e=>(0,J.jsxs)(`li`,{className:`flex items-start gap-1.5 text-[11px]`,children:[e.status===`done`?(0,J.jsx)(g,{className:`h-3 w-3 text-emerald-500 mt-0.5 shrink-0`}):(0,J.jsx)(v,{className:`h-3 w-3 text-muted-foreground/50 mt-0.5 shrink-0`}),(0,J.jsx)(`span`,{className:q(`leading-snug`,e.status===`done`?`text-muted-foreground line-through`:`text-foreground`),children:e.text})]},e.id))})]}),s.length>0&&(0,J.jsxs)(`div`,{className:`space-y-1`,children:[(0,J.jsx)(`p`,{className:`text-[10px] text-muted-foreground uppercase tracking-wider font-medium`,children:`Recent Activity`}),(0,J.jsx)(`div`,{className:`space-y-1`,children:s.map((e,t)=>(0,J.jsxs)(`div`,{className:`flex items-start gap-1.5 text-[10px] text-muted-foreground`,children:[(0,J.jsxs)(`span`,{className:`font-mono tabular-nums shrink-0 text-foreground/60`,children:[`#`,e.iteration]}),(0,J.jsx)(`span`,{className:`truncate`,children:e.task||e.status||e.progressNote||`…`})]},`${e.iteration}-${t}`))})]})]})]})}function Xi(){let e=K(e=>e.modelSwitcherOpen),t=K(e=>e.setModelSwitcherOpen),[n,r]=(0,V.useState)(``),[i,a]=(0,V.useState)(0),[o,s]=(0,V.useState)([]),[c,l]=(0,V.useState)({}),u=(0,V.useRef)(null),d=W(e=>e.wsUrl),f=W(e=>e.provider),p=W(e=>e.model),m=K(e=>e.paletteOpen),h=Y();(0,V.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,V.useEffect)(()=>{let e=H(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,V.useEffect)(()=>{e&&(r(``),a(0),h.listSavedProviders(),requestAnimationFrame(()=>u.current?.focus()))},[e,h]),(0,V.useEffect)(()=>{if(e)for(let e of o)c[e.id]||h.listProviderModels(e.id)},[e,o,c,h]);let g=(0,V.useMemo)(()=>{let e=[];for(let t of o){let n=c[t.id]??[];for(let r of n)e.push({provider:t.id,model:r.id,modelName:r.name||r.id,contextWindow:r.contextWindow,isCurrent:t.id===f&&r.id===p})}let t=n.toLowerCase().trim();return(t?e.filter(e=>e.provider.toLowerCase().includes(t)||e.model.toLowerCase().includes(t)||e.modelName.toLowerCase().includes(t)):e).sort((e,t)=>e.isCurrent===t.isCurrent?e.provider.localeCompare(t.provider)||e.model.localeCompare(t.model):e.isCurrent?-1:1)},[o,c,n,f,p]);(0,V.useEffect)(()=>{i>=g.length&&a(0)},[g.length,i]);let _=e=>{let n=g[e];n&&(h.switchModel(n.provider,n.model),t(!1))};return e?(0,J.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,J.jsxs)(`div`,{className:`w-full max-w-xl rounded-xl border bg-popover shadow-2xl overflow-hidden`,children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-2 border-b px-3 py-2`,children:[(0,J.jsx)(x,{className:`h-4 w-4 text-muted-foreground`}),(0,J.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(g.length-1,e+1))):e.key===`ArrowUp`?(e.preventDefault(),a(e=>Math.max(0,e-1))):e.key===`Enter`?(e.preventDefault(),_(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,J.jsx)(`span`,{className:`text-[10px] text-muted-foreground font-mono`,children:`↑↓ · Enter · Esc`})]}),(0,J.jsx)(`div`,{className:`max-h-[50vh] overflow-y-auto py-1`,children:g.length===0?(0,J.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…`}):g.map((e,t)=>(0,J.jsxs)(`button`,{type:`button`,onClick:()=>_(t),onMouseEnter:()=>a(t),className:q(`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,J.jsx)(F,{className:q(`h-4 w-4 shrink-0`,e.isCurrent?`text-primary`:`text-muted-foreground`)}),(0,J.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,J.jsxs)(`div`,{className:`truncate`,children:[(0,J.jsx)(`span`,{className:`text-muted-foreground`,children:e.provider}),(0,J.jsx)(`span`,{className:`mx-1 text-muted-foreground/40`,children:`·`}),(0,J.jsx)(`span`,{children:e.modelName})]}),e.contextWindow&&(0,J.jsxs)(`div`,{className:`text-[10px] text-muted-foreground font-mono`,children:[e.model,` · ctx `,e.contextWindow.toLocaleString()]})]}),e.isCurrent?(0,J.jsx)(`span`,{className:`text-[10px] uppercase tracking-wide text-primary font-semibold`,children:`active`}):(0,J.jsx)(Ze,{className:`h-3.5 w-3.5 text-muted-foreground opacity-0 group-hover:opacity-100`})]},`${e.provider}:${e.model}`))})]})}):null}var Zi=V.forwardRef(({className:e,type:t,...n},r)=>(0,J.jsx)(`input`,{type:t,className:q(`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}));Zi.displayName=`Input`;var Qi=ot,$i=V.forwardRef(({className:e,...t},n)=>(0,J.jsx)(Xe,{ref:n,className:q(`inline-flex h-10 items-center justify-center rounded-md bg-muted p-1 text-muted-foreground`,e),...t}));$i.displayName=Xe.displayName;var Z=V.forwardRef(({className:e,...t},n)=>(0,J.jsx)(Re,{ref:n,className:q(`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}));Z.displayName=Re.displayName;var Q=V.forwardRef(({className:e,...t},n)=>(0,J.jsx)(ft,{ref:n,className:q(`mt-2 ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2`,e),...t}));Q.displayName=ft.displayName;function $({label:e,hint:t,selector:n,onChange:r,configKey:i}){let a=K(e=>n?n(e):!1),o=W(e=>i?e[i]:!1),s=n?a:o;return(0,J.jsxs)(`div`,{className:`flex items-start justify-between gap-3 py-2`,children:[(0,J.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,J.jsx)(`div`,{className:`text-sm font-medium`,children:e}),t&&(0,J.jsx)(`div`,{className:`text-xs text-muted-foreground mt-0.5`,children:t})]}),(0,J.jsx)(`button`,{type:`button`,role:`switch`,"aria-checked":s,onClick:()=>{if(n)r?.();else if(i===`soundOnComplete`){let e=!W.getState().soundOnComplete;W.getState().setSoundOnComplete(e),e&&un()}},className:q(`shrink-0 relative inline-flex h-5 w-9 rounded-full border transition-colors`,s?`bg-primary border-primary`:`bg-muted border-input hover:bg-muted/80`),children:(0,J.jsx)(`span`,{className:q(`absolute top-0.5 left-0.5 h-3.5 w-3.5 rounded-full bg-background shadow transition-transform`,s&&`translate-x-4`)})})]})}function ea({label:e,hint:t,value:n,min:r,max:i,step:a=1,onChange:o,unit:s}){return(0,J.jsxs)(`div`,{className:`flex items-start justify-between gap-3 py-2`,children:[(0,J.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,J.jsx)(`div`,{className:`text-sm font-medium`,children:e}),t&&(0,J.jsx)(`div`,{className:`text-xs text-muted-foreground mt-0.5`,children:t})]}),(0,J.jsxs)(`div`,{className:`flex items-center gap-2 shrink-0`,children:[(0,J.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,J.jsxs)(`span`,{className:`text-xs tabular-nums w-10 text-right text-muted-foreground`,children:[n,s??``]})]})]})}function ta({label:e,hint:t,value:n,options:r,onChange:i}){return(0,J.jsxs)(`div`,{className:`flex items-start justify-between gap-3 py-2`,children:[(0,J.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,J.jsx)(`div`,{className:`text-sm font-medium`,children:e}),t&&(0,J.jsx)(`div`,{className:`text-xs text-muted-foreground mt-0.5`,children:t})]}),(0,J.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,J.jsx)(`option`,{value:e.value,children:e.label},e.value))})]})}var na=[`anthropic`,`openai`,`google`,`openai-compatible`];function ra({activeProvider:e,catalogProviders:n,isLoadingCatalog:r,savedProviders:i,isLoadingSaved:a,providerTab:o,setProviderTab:s,onSelectProvider:c,onAddKey:l,onDeleteKey:u,onSetActiveKey:d,onAddProvider:p,onRemoveProvider:h,catalogQuery:_,setCatalogQuery:v}){let[y,b]=(0,V.useState)(null),[x,S]=(0,V.useState)(``),[C,w]=(0,V.useState)(``),[T,E]=(0,V.useState)(!1),[D,O]=(0,V.useState)(!1),[k,A]=(0,V.useState)(``),[j,M]=(0,V.useState)(`openai-compatible`),[P,te]=(0,V.useState)(``),[ne,F]=(0,V.useState)(``),I=(0,V.useCallback)(e=>{!x.trim()||!C.trim()||(l(e,x.trim(),C.trim()),S(``),w(``),b(null))},[l,x,C]),re=(0,V.useCallback)(()=>{k.trim()&&(p(k.trim(),j,P||void 0,ne||void 0),A(``),M(`openai-compatible`),te(``),F(``),O(!1))},[p,k,j,P,ne]),ie=_.trim()?n.filter(e=>{let t=_.trim().toLowerCase();return e.id.toLowerCase().includes(t)||e.name.toLowerCase().includes(t)||e.family.toLowerCase().includes(t)}):n,ae=ie.reduce((e,t)=>(e[t.family]||(e[t.family]=[]),e[t.family]?.push(t),e),{});return(0,J.jsxs)(`div`,{className:`space-y-4`,children:[(0,J.jsxs)(`div`,{className:`flex gap-2 mb-4`,children:[(0,J.jsxs)(X,{variant:o===`catalog`?`default`:`outline`,size:`sm`,onClick:()=>s(`catalog`),children:[(0,J.jsx)(f,{className:`h-4 w-4 mr-1`}),`Catalog`]}),(0,J.jsxs)(X,{variant:o===`saved`?`default`:`outline`,size:`sm`,onClick:()=>s(`saved`),children:[(0,J.jsx)(St,{className:`h-4 w-4 mr-1`}),`Saved (`,i.length,`)`]})]}),o===`catalog`&&(0,J.jsxs)(`div`,{className:`space-y-4`,children:[(0,J.jsx)(Zi,{placeholder:`Search ${n.length} providers (name / id / family)…`,value:_,onChange:e=>v(e.target.value),className:`text-sm`}),r&&n.length===0?(0,J.jsxs)(`div`,{className:`flex items-center justify-center py-8`,children:[(0,J.jsx)(R,{className:`h-6 w-6 animate-spin text-muted-foreground`}),(0,J.jsx)(`span`,{className:`ml-2 text-muted-foreground`,children:`Loading catalog...`})]}):ie.length===0&&_?(0,J.jsxs)(`div`,{className:`text-center py-8 text-muted-foreground text-sm`,children:[`No providers match "`,(0,J.jsx)(`span`,{className:`font-mono`,children:_}),`".`]}):(0,J.jsx)(J.Fragment,{children:na.map(t=>{let n=ae[t];return n?.length?(0,J.jsxs)(`div`,{className:`space-y-2`,children:[(0,J.jsx)(`h3`,{className:`text-sm font-semibold text-muted-foreground uppercase tracking-wider`,children:t}),(0,J.jsx)(`div`,{className:`grid grid-cols-1 gap-2`,children:n.map(t=>(0,J.jsxs)(`button`,{type:`button`,onClick:()=>c(t.id),className:q(`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,J.jsxs)(`div`,{className:`flex w-full justify-between items-start`,children:[(0,J.jsxs)(`div`,{children:[(0,J.jsx)(`span`,{className:`font-medium`,children:t.name}),(0,J.jsxs)(`span`,{className:`ml-2 text-xs text-muted-foreground`,children:[`(`,t.id,`)`]})]}),(0,J.jsxs)(`div`,{className:`flex items-center gap-2`,children:[t.hasApiKey&&(0,J.jsxs)(`span`,{className:`text-xs bg-green-500/10 text-green-600 px-2 py-0.5 rounded`,children:[(0,J.jsx)(St,{className:`h-3 w-3 inline mr-1`}),`Configured`]}),t.envVars[0]&&(0,J.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[`ENV: `,t.envVars[0]]}),e===t.id&&(0,J.jsx)(g,{className:`h-4 w-4 text-primary`})]})]}),(0,J.jsxs)(`div`,{className:`text-xs text-muted-foreground mt-1`,children:[t.modelCount,` models`,t.apiBase&&` · ${t.apiBase}`]})]},t.id))})]},t):null})})]}),o===`saved`&&(0,J.jsxs)(`div`,{className:`space-y-4`,children:[(0,J.jsxs)(`div`,{className:`flex justify-between items-center`,children:[(0,J.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Manage your API keys and provider configurations`}),(0,J.jsxs)(X,{size:`sm`,variant:`outline`,onClick:()=>O(!D),children:[(0,J.jsx)(t,{className:`h-4 w-4 mr-1`}),`Add Provider`]})]}),D&&(0,J.jsxs)(`div`,{className:`p-4 border rounded-lg space-y-3 bg-muted/50`,children:[(0,J.jsx)(`h4`,{className:`font-medium`,children:`Add Custom Provider`}),(0,J.jsx)(Zi,{placeholder:`Provider ID (e.g. my-llm-server)`,value:k,onChange:e=>A(e.target.value)}),(0,J.jsxs)(`select`,{className:`flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm`,value:j,onChange:e=>M(e.target.value),children:[(0,J.jsx)(`option`,{value:`anthropic`,children:`Anthropic`}),(0,J.jsx)(`option`,{value:`openai`,children:`OpenAI`}),(0,J.jsx)(`option`,{value:`openai-compatible`,children:`OpenAI Compatible`}),(0,J.jsx)(`option`,{value:`google`,children:`Google`})]}),(0,J.jsx)(Zi,{placeholder:`Base URL (optional, e.g. http://localhost:11434/v1)`,value:P,onChange:e=>te(e.target.value)}),(0,J.jsx)(Zi,{type:`password`,placeholder:`API Key (optional)`,value:ne,onChange:e=>F(e.target.value)}),(0,J.jsxs)(`div`,{className:`flex gap-2`,children:[(0,J.jsx)(X,{size:`sm`,onClick:re,disabled:!k.trim(),children:`Add`}),(0,J.jsx)(X,{size:`sm`,variant:`ghost`,onClick:()=>O(!1),children:`Cancel`})]})]}),a?(0,J.jsx)(`div`,{className:`flex items-center justify-center py-8`,children:(0,J.jsx)(R,{className:`h-6 w-6 animate-spin text-muted-foreground`})}):i.length===0?(0,J.jsxs)(`div`,{className:`text-center py-8 text-muted-foreground`,children:[(0,J.jsx)(St,{className:`h-8 w-8 mx-auto mb-2 opacity-50`}),(0,J.jsx)(`p`,{children:`No saved providers yet`}),(0,J.jsx)(`p`,{className:`text-sm`,children:`Add a provider to get started`})]}):i.map(e=>(0,J.jsxs)(`div`,{className:`border rounded-lg p-4 space-y-3`,children:[(0,J.jsxs)(`div`,{className:`flex justify-between items-start`,children:[(0,J.jsxs)(`div`,{children:[(0,J.jsx)(`h4`,{className:`font-medium`,children:e.id}),e.family&&(0,J.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:e.family})]}),(0,J.jsx)(`div`,{className:`flex gap-2`,children:(0,J.jsx)(X,{size:`icon`,variant:`ghost`,onClick:()=>h(e.id),children:(0,J.jsx)(N,{className:`h-4 w-4 text-destructive`})})})]}),e.baseUrl&&(0,J.jsxs)(`div`,{className:`text-xs text-muted-foreground`,children:[(0,J.jsx)(f,{className:`h-3 w-3 inline mr-1`}),e.baseUrl]}),(0,J.jsxs)(`div`,{className:`space-y-2`,children:[(0,J.jsxs)(`div`,{className:`flex justify-between items-center`,children:[(0,J.jsx)(`span`,{className:`text-sm font-medium`,children:`API Keys`}),(0,J.jsxs)(X,{size:`sm`,variant:`ghost`,onClick:()=>b(y===e.id?null:e.id),children:[(0,J.jsx)(t,{className:`h-3 w-3 mr-1`}),`Add Key`]})]}),e.apiKeys.length===0&&!y&&(0,J.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`No keys configured`}),e.apiKeys.map(t=>(0,J.jsxs)(`div`,{className:`flex items-center justify-between p-2 bg-muted/50 rounded`,children:[(0,J.jsxs)(`div`,{children:[(0,J.jsx)(`span`,{className:`text-sm font-medium`,children:t.label}),t.isActive&&(0,J.jsx)(`span`,{className:`ml-2 text-xs bg-green-500/10 text-green-600 px-1.5 py-0.5 rounded`,children:`Active`}),(0,J.jsx)(`div`,{className:`text-xs text-muted-foreground font-mono`,children:t.maskedKey})]}),(0,J.jsxs)(`div`,{className:`flex gap-1`,children:[!t.isActive&&(0,J.jsx)(X,{size:`sm`,variant:`ghost`,onClick:()=>d(e.id,t.label),children:`Set Active`}),(0,J.jsx)(X,{size:`icon`,variant:`ghost`,onClick:()=>u(e.id,t.label),children:(0,J.jsx)(N,{className:`h-3 w-3 text-destructive`})})]})]},t.label)),y===e.id&&(0,J.jsxs)(`div`,{className:`p-3 border rounded space-y-2 bg-background`,children:[(0,J.jsx)(Zi,{placeholder:`Key label (e.g. default, production)`,value:x,onChange:e=>S(e.target.value)}),(0,J.jsxs)(`div`,{className:`flex gap-2`,children:[(0,J.jsx)(Zi,{type:T?`text`:`password`,placeholder:`API key`,value:C,onChange:e=>w(e.target.value)}),(0,J.jsx)(X,{size:`icon`,variant:`ghost`,onClick:()=>E(!T),children:T?(0,J.jsx)(m,{className:`h-4 w-4`}):(0,J.jsx)(ee,{className:`h-4 w-4`})})]}),(0,J.jsxs)(`div`,{className:`flex gap-2`,children:[(0,J.jsx)(X,{size:`sm`,onClick:()=>I(e.id),disabled:!x.trim()||!C.trim(),children:`Save Key`}),(0,J.jsx)(X,{size:`sm`,variant:`ghost`,onClick:()=>{b(null),S(``),w(``)},children:`Cancel`})]})]})]})]},e.id))]})]})}function ia({provider:e,catalogModels:t,currentCatalogProvider:n,isLoadingModels:r,setIsLoadingModels:i,onModelSelect:a,refreshModels:o}){let s=W(e=>e.model);return(0,J.jsx)(`div`,{className:`space-y-4`,children:e?(0,J.jsxs)(J.Fragment,{children:[(0,J.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,J.jsxs)(`div`,{children:[(0,J.jsx)(`p`,{className:`text-sm font-medium`,children:n?.name||e}),(0,J.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:e})]}),(0,J.jsx)(X,{variant:`ghost`,size:`sm`,onClick:()=>{i(!0),o(e)},children:(0,J.jsx)(he,{className:q(`h-4 w-4`,r&&`animate-spin`)})})]}),r&&!t[e]?(0,J.jsxs)(`div`,{className:`flex items-center justify-center py-8`,children:[(0,J.jsx)(R,{className:`h-6 w-6 animate-spin text-muted-foreground`}),(0,J.jsx)(`span`,{className:`ml-2 text-muted-foreground`,children:`Loading models...`})]}):(0,J.jsxs)(`div`,{className:`space-y-1`,children:[(t[e]||[]).map(e=>(0,J.jsxs)(`button`,{type:`button`,onClick:()=>a(e.id),className:q(`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,J.jsxs)(`div`,{children:[(0,J.jsx)(`span`,{className:`font-medium`,children:e.name||e.id}),(0,J.jsx)(`div`,{className:`flex gap-2 mt-1`,children:e.capabilities.map(e=>(0,J.jsx)(`span`,{className:`text-xs bg-muted px-1.5 py-0.5 rounded`,children:e},e))})]}),(0,J.jsxs)(`div`,{className:`text-right text-xs text-muted-foreground`,children:[e.contextWindow&&(0,J.jsxs)(`div`,{children:[e.contextWindow/1e3,`k context`]}),e.inputCost&&e.outputCost&&(0,J.jsxs)(`div`,{children:[`$`,e.inputCost,`/$`,e.outputCost]}),s===e.id&&(0,J.jsx)(g,{className:`h-4 w-4 text-primary mt-1`})]})]},e.id)),t[e]?.length===0&&(0,J.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,J.jsxs)(`div`,{className:`text-center py-8 text-muted-foreground`,children:[(0,J.jsx)(F,{className:`h-8 w-8 mx-auto mb-2 opacity-50`}),(0,J.jsx)(`p`,{children:`Select a provider first`})]})})}function aa(){let{setCurrentView:e}=K(),{provider:t,model:n,setProvider:r,setModel:i,wsConnected:a}=W(),{theme:o,setTheme:c}=fi(),l=Y(),u=l.client,d=en(),[p,m]=(0,V.useState)([]),[h,g]=(0,V.useState)({}),[_,v]=(0,V.useState)([]),[y,b]=(0,V.useState)(!1),[x,S]=(0,V.useState)(!1),[C,w]=(0,V.useState)(!1),[E,D]=(0,V.useState)(`catalog`),[O,k]=(0,V.useState)(``),A=p.find(e=>e.id===t);(0,V.useEffect)(()=>{let e=e=>{if(e.type===`provider.catalog`){let t=e.payload;m(t.providers.sort((e,t)=>e.id.localeCompare(t.id))),b(!1)}},t=e=>{if(e.type===`provider.models`){let t=e.payload;g(e=>({...e,[t.provider]:t.models})),S(!1)}},n=e=>{if(e.type===`providers.saved`){let t=e.payload.providers.sort((e,t)=>e.id.localeCompare(t.id));v(t),w(!1),t.length>0&&D(`saved`)}};if(!a||!u)return;let r=u.on(`provider.catalog`,e),i=u.on(`provider.models`,t),o=u.on(`providers.saved`,n);return b(!0),w(!0),u.listProviders(),u.listSavedProviders(),()=>{r?.(),i?.(),o?.()}},[a,u]);let j=(0,V.useCallback)(e=>{r(e),h[e]||(S(!0),l.listProviderModels?.(e))},[h,r,l]),M=(0,V.useCallback)(e=>{i(e);let t=W.getState().provider;l.switchModel?.(t,e),nn.success(`Switching to ${t} / ${e}…`)},[i,l]),N=(0,V.useCallback)((e,t,n)=>{l.addKey?.(e,t,n)},[l]),ee=(0,V.useCallback)((e,t)=>{l.deleteKey?.(e,t)},[l]),te=(0,V.useCallback)((e,t)=>{l.setActiveKey?.(e,t)},[l]),ne=(0,V.useCallback)((e,t,n,r)=>{l.addProvider?.(e,t,n,r)},[l]),re=(0,V.useCallback)(e=>{l.removeProvider?.(e)},[l]);return(0,J.jsxs)(`div`,{className:`flex flex-col h-full`,children:[(0,J.jsxs)(`header`,{className:`flex items-center justify-between px-4 py-3 border-b bg-card shrink-0`,children:[(0,J.jsx)(`h1`,{className:`text-lg font-semibold`,children:`Settings`}),(0,J.jsx)(X,{variant:`ghost`,size:`icon`,onClick:()=>e(`chat`),children:(0,J.jsx)(s,{className:`h-4 w-4`})})]}),(0,J.jsx)(xi,{className:`flex-1`,children:(0,J.jsx)(`div`,{className:`p-6 max-w-2xl mx-auto`,children:(0,J.jsxs)(Qi,{defaultValue:`provider`,children:[(0,J.jsxs)($i,{className:`w-full justify-start mb-6 grid grid-cols-6`,children:[(0,J.jsxs)(Z,{value:`provider`,className:`gap-1 text-xs`,children:[(0,J.jsx)(Te,{className:`h-3.5 w-3.5`}),`Provider`]}),(0,J.jsxs)(Z,{value:`model`,className:`gap-1 text-xs`,children:[(0,J.jsx)(F,{className:`h-3.5 w-3.5`}),`Model`]}),(0,J.jsxs)(Z,{value:`connection`,className:`gap-1 text-xs`,children:[(0,J.jsx)(f,{className:`h-3.5 w-3.5`}),`Connect`]}),(0,J.jsxs)(Z,{value:`appearance`,className:`gap-1 text-xs`,children:[(0,J.jsx)(dt,{className:`h-3.5 w-3.5`}),`Look`]}),(0,J.jsxs)(Z,{value:`agent`,className:`gap-1 text-xs`,children:[(0,J.jsx)(ke,{className:`h-3.5 w-3.5`}),`Agent`]}),(0,J.jsxs)(Z,{value:`features`,className:`gap-1 text-xs`,children:[(0,J.jsx)(P,{className:`h-3.5 w-3.5`}),`Feat.`]})]}),(0,J.jsx)(Q,{value:`provider`,className:`space-y-4`,children:(0,J.jsx)(ra,{activeProvider:t,catalogProviders:p,isLoadingCatalog:y,savedProviders:_,isLoadingSaved:C,providerTab:E,setProviderTab:D,onSelectProvider:j,onAddKey:N,onDeleteKey:ee,onSetActiveKey:te,onAddProvider:ne,onRemoveProvider:re,catalogQuery:O,setCatalogQuery:k})}),(0,J.jsx)(Q,{value:`model`,className:`space-y-4`,children:(0,J.jsx)(ia,{provider:t,catalogModels:h,currentCatalogProvider:A,isLoadingModels:x,setIsLoadingModels:S,onModelSelect:M,refreshModels:e=>l.listProviderModels?.(e)})}),(0,J.jsxs)(Q,{value:`connection`,className:`space-y-4`,children:[(0,J.jsxs)(`div`,{className:`space-y-3`,children:[(0,J.jsxs)(`label`,{htmlFor:`websocket-url`,className:`text-sm font-medium flex items-center gap-2`,children:[(0,J.jsx)(f,{className:`h-4 w-4 text-muted-foreground`}),`WebSocket Server URL`]}),(0,J.jsx)(Zi,{id:`websocket-url`,value:W.getState().wsUrl,onChange:e=>W.getState().setConfig({wsUrl:e.target.value}),placeholder:`ws://localhost:3457`,className:`font-mono text-sm`}),(0,J.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`URL of the agent WebSocket server. The server runs alongside the CLI.`})]}),(0,J.jsxs)(`div`,{className:`p-4 rounded-lg border bg-muted/50`,children:[(0,J.jsx)(`h4`,{className:`text-sm font-medium mb-2`,children:`Starting the WebSocket Server`}),(0,J.jsxs)(`p`,{className:`text-xs text-muted-foreground mb-3`,children:[`Standalone: run `,(0,J.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,J.jsx)(`code`,{className:`bg-muted px-1 py-0.5 rounded`,children:`node packages/webui/dist/server/entry.js`}),`. Or alongside the CLI:`,` `,(0,J.jsx)(`code`,{className:`bg-muted px-1 py-0.5 rounded`,children:`wstack --webui`}),`.`]})]})]}),(0,J.jsxs)(Q,{value:`appearance`,className:`space-y-4`,children:[(0,J.jsxs)(`div`,{children:[(0,J.jsx)(`h3`,{className:`text-sm font-semibold mb-3`,children:`Theme`}),(0,J.jsxs)(`div`,{className:`grid grid-cols-3 gap-2 max-w-md`,children:[(0,J.jsxs)(X,{variant:o===`light`?`default`:`outline`,size:`sm`,onClick:()=>c(`light`),children:[(0,J.jsx)(T,{className:`h-4 w-4 mr-1`}),`Light`]}),(0,J.jsxs)(X,{variant:o===`dark`?`default`:`outline`,size:`sm`,onClick:()=>c(`dark`),children:[(0,J.jsx)(qe,{className:`h-4 w-4 mr-1`}),`Dark`]}),(0,J.jsxs)(X,{variant:o===`system`?`default`:`outline`,size:`sm`,onClick:()=>c(`system`),children:[(0,J.jsx)(gt,{className:`h-4 w-4 mr-1`}),`System`]})]}),(0,J.jsx)(`p`,{className:`text-xs text-muted-foreground mt-2`,children:`System follows your OS-level light/dark preference.`})]}),(0,J.jsxs)(`div`,{className:`pt-2 border-t`,children:[(0,J.jsx)(`h3`,{className:`text-sm font-semibold mb-3 mt-3`,children:`Preferences`}),(0,J.jsx)($,{label:`Compact density`,hint:`Tighter spacing throughout the chat.`,selector:e=>e.compactMode,onChange:()=>K.getState().toggleCompactMode()}),(0,J.jsx)($,{label:`Sound on completion`,hint:`Play a soft chime when a run finishes.`,selector:null,configKey:`soundOnComplete`})]})]}),(0,J.jsxs)(Q,{value:`agent`,className:`space-y-4`,children:[(0,J.jsxs)(`div`,{children:[(0,J.jsxs)(`h3`,{className:`text-sm font-semibold mb-3 flex items-center gap-2`,children:[(0,J.jsx)(et,{className:`h-4 w-4 text-muted-foreground`}),`Autonomy & Behavior`]}),(0,J.jsx)(ta,{label:`Autonomy mode`,hint:`How independently the agent proceeds between turns.`,value:d.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=>d.set({autonomy:e})}),(0,J.jsx)(ea,{label:`Auto-proceed delay`,hint:`Milliseconds before the agent auto-proceeds in Auto mode. 0 = immediate.`,value:d.autonomyDelayMs,min:0,max:1e4,step:500,unit:`ms`,onChange:e=>d.set({autonomyDelayMs:e})}),(0,J.jsx)($,{label:`YOLO mode`,hint:`Bypass tool confirmation prompts — the agent runs without asking.`,selector:null,onChange:()=>d.set({yolo:!d.yolo})})]}),(0,J.jsxs)(`div`,{className:`pt-2 border-t`,children:[(0,J.jsxs)(`h3`,{className:`text-sm font-semibold mb-3 mt-3 flex items-center gap-2`,children:[(0,J.jsx)(I,{className:`h-4 w-4 text-muted-foreground`}),`Execution`]}),(0,J.jsx)(ea,{label:`Max iterations per run`,hint:`Hard cap on LLM turns per agent.run().`,value:d.maxIterations,min:10,max:2e3,step:10,onChange:e=>d.set({maxIterations:e})}),(0,J.jsx)($,{label:`Confirm before exit`,hint:`First Ctrl+C aborts work, second confirms exit.`,selector:null,onChange:()=>d.set({confirmExit:!d.confirmExit})}),(0,J.jsx)($,{label:`Chime on completion`,hint:`Terminal bell when an agent run finishes.`,selector:null,onChange:()=>d.set({chime:!d.chime})})]}),(0,J.jsxs)(`div`,{className:`pt-2 border-t`,children:[(0,J.jsxs)(`h3`,{className:`text-sm font-semibold mb-3 mt-3 flex items-center gap-2`,children:[(0,J.jsx)(wt,{className:`h-4 w-4 text-muted-foreground`}),`Fleet & Streaming`]}),(0,J.jsx)($,{label:`Stream fleet events`,hint:`Show live subagent activity in the fleet panel.`,selector:null,onChange:()=>d.set({streamFleet:!d.streamFleet})}),(0,J.jsx)($,{label:`Next-step prediction`,hint:`After a turn completes, predict likely next steps.`,selector:null,onChange:()=>d.set({nextPrediction:!d.nextPrediction})})]})]}),(0,J.jsxs)(Q,{value:`features`,className:`space-y-4`,children:[(0,J.jsxs)(`div`,{children:[(0,J.jsxs)(`h3`,{className:`text-sm font-semibold mb-3 flex items-center gap-2`,children:[(0,J.jsx)(P,{className:`h-4 w-4 text-muted-foreground`}),`Feature Flags`]}),(0,J.jsx)($,{label:`MCP servers`,hint:`Enable Model Context Protocol integrations.`,selector:null,onChange:()=>d.set({featureMcp:!d.featureMcp})}),(0,J.jsx)($,{label:`Plugins`,hint:`Load and run user-installed plugins.`,selector:null,onChange:()=>d.set({featurePlugins:!d.featurePlugins})}),(0,J.jsx)($,{label:`Memory`,hint:`Persist and recall facts across sessions.`,selector:null,onChange:()=>d.set({featureMemory:!d.featureMemory})}),(0,J.jsx)($,{label:`Skills`,hint:`Load domain-specific skill prompts.`,selector:null,onChange:()=>d.set({featureSkills:!d.featureSkills})}),(0,J.jsx)($,{label:`Models registry`,hint:`Use the models.dev catalog for provider discovery.`,selector:null,onChange:()=>d.set({featureModelsRegistry:!d.featureModelsRegistry})}),(0,J.jsx)($,{label:`Index on start`,hint:`Build the codebase symbol index at session start.`,selector:null,onChange:()=>d.set({indexOnStart:!d.indexOnStart})})]}),(0,J.jsxs)(`div`,{className:`pt-2 border-t`,children:[(0,J.jsxs)(`h3`,{className:`text-sm font-semibold mb-3 mt-3 flex items-center gap-2`,children:[(0,J.jsx)(le,{className:`h-4 w-4 text-muted-foreground`}),`Context & Debug`]}),(0,J.jsx)($,{label:`Auto-compact context`,hint:`Automatically trim the context window when near limits.`,selector:null,onChange:()=>d.set({contextAutoCompact:!d.contextAutoCompact})}),(0,J.jsx)(ta,{label:`Context strategy`,hint:`How aggressively the context window is managed.`,value:d.contextStrategy,options:[{value:`frugal`,label:`Frugal — tight budget, compact early`},{value:`balanced`,label:`Balanced — moderate trimming`},{value:`deep`,label:`Deep — keep more history`},{value:`archival`,label:`Archival — maximum context retention`}],onChange:e=>d.set({contextStrategy:e})}),(0,J.jsx)(ta,{label:`Log level`,hint:`Minimum severity for server-side logging.`,value:d.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=>d.set({logLevel:e})}),(0,J.jsx)(ta,{label:`Audit level`,hint:`Detail level for session audit logs.`,value:d.auditLevel,options:[{value:`minimal`,label:`Minimal — errors only`},{value:`standard`,label:`Standard — tool calls + errors`},{value:`verbose`,label:`Verbose — every event`}],onChange:e=>d.set({auditLevel:e})})]})]})]})})})]})}var oa=[{section:`Global`,items:[{keys:[`Ctrl`,`K`],description:`Open command palette`},{keys:[`?`],description:`Show this shortcuts overlay`},{keys:[`Ctrl`,`\\`],description:`Toggle sidebar`},{keys:[`Ctrl`,`/`],description:`Focus the message input`}]},{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 sa(){let e=K(e=>e.shortcutsOpen),t=K(e=>e.setShortcutsOpen);return(0,V.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(!K.getState().shortcutsOpen);return}e.key===`Escape`&&K.getState().shortcutsOpen&&(e.preventDefault(),t(!1))};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[t]),e?(0,J.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,J.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,J.jsxs)(`div`,{className:`flex items-center justify-between px-5 py-4 border-b`,children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,J.jsx)(Se,{className:`h-4 w-4 text-muted-foreground`}),(0,J.jsx)(`h2`,{className:`text-sm font-semibold`,children:`Keyboard shortcuts`})]}),(0,J.jsx)(`button`,{type:`button`,onClick:()=>t(!1),className:`text-muted-foreground hover:text-foreground p-1 rounded hover:bg-muted`,children:(0,J.jsx)(s,{className:`h-4 w-4`})})]}),(0,J.jsx)(`div`,{className:`overflow-y-auto px-5 py-4 space-y-6`,children:oa.map(e=>(0,J.jsxs)(`div`,{children:[(0,J.jsx)(`div`,{className:`text-[10px] uppercase tracking-wider text-muted-foreground mb-2`,children:e.section}),(0,J.jsx)(`div`,{className:`grid grid-cols-1 gap-1.5`,children:e.items.map(e=>(0,J.jsxs)(`div`,{className:`flex items-center justify-between gap-3 text-sm px-2 py-1.5 rounded hover:bg-muted/40`,children:[(0,J.jsx)(`span`,{className:`text-foreground/80`,children:e.description}),(0,J.jsx)(`span`,{className:`flex items-center gap-1 shrink-0`,children:e.keys.map((e,t)=>(0,J.jsxs)(`span`,{className:`flex items-center gap-1`,children:[t>0&&(0,J.jsx)(`span`,{className:`text-muted-foreground/40 text-xs`,children:`+`}),(0,J.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,J.jsxs)(`div`,{className:`border-t px-5 py-3 text-xs text-muted-foreground`,children:[`Press`,` `,(0,J.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 ca({formatDuration:e}){let{wsConnected:t,wsUrl:n,provider:r,model:i}=W(),{totalTokens:a,cost:o,session:s,todos:c}=G(),{messages:l}=U(),u=K(e=>e.pinnedIds),f=K(e=>e.unpinAll),p=K(e=>e.setCurrentView),m=u.map(e=>l.find(t=>t.id===e)).filter(e=>!!e&&e.content.length>0);return(0,J.jsxs)(J.Fragment,{children:[(0,J.jsxs)(`div`,{className:`px-4 py-3 border-b`,children:[(0,J.jsxs)(`div`,{className:q(`flex items-center gap-2 px-3 py-2 rounded-lg text-sm`,t?`bg-green-500/10 text-green-600 dark:text-green-400`:`bg-yellow-500/10 text-yellow-600 dark:text-yellow-400`),children:[t?(0,J.jsx)(ie,{className:`h-4 w-4`}):(0,J.jsx)(d,{className:`h-4 w-4`}),(0,J.jsx)(`span`,{className:`font-medium`,children:t?`Connected`:`Disconnected`})]}),(0,J.jsx)(`div`,{className:`text-xs text-muted-foreground mt-2 px-1 font-mono`,children:n})]}),(0,J.jsxs)(`button`,{type:`button`,onClick:()=>p(`settings`),className:`px-4 py-3 border-b text-left hover:bg-muted/40 transition-colors`,children:[(0,J.jsx)(`div`,{className:`text-[10px] uppercase tracking-wider text-muted-foreground mb-1`,children:`Active model`}),(0,J.jsxs)(`div`,{className:`font-mono text-xs truncate`,children:[(0,J.jsx)(`span`,{className:`text-muted-foreground`,children:r||`—`}),(0,J.jsx)(`span`,{className:`text-muted-foreground/40 mx-1`,children:`/`}),(0,J.jsx)(`span`,{className:`font-medium`,children:i||`—`})]})]}),(0,J.jsxs)(`div`,{className:`px-4 py-3 border-b space-y-3`,children:[(0,J.jsxs)(`h3`,{className:`text-sm font-medium flex items-center gap-2`,children:[(0,J.jsx)(E,{className:`h-4 w-4 text-muted-foreground`}),`Session`]}),(0,J.jsxs)(`div`,{className:`grid grid-cols-2 gap-2 text-xs`,children:[(0,J.jsxs)(`div`,{className:`flex flex-col p-2 rounded-lg bg-muted/50`,children:[(0,J.jsx)(`span`,{className:`text-muted-foreground`,children:`Messages`}),(0,J.jsx)(`span`,{className:`text-lg font-semibold`,children:l.length})]}),(0,J.jsxs)(`div`,{className:`flex flex-col p-2 rounded-lg bg-muted/50`,children:[(0,J.jsx)(`span`,{className:`text-muted-foreground`,children:`Duration`}),(0,J.jsx)(`span`,{className:`text-lg font-semibold`,children:e(s?.startedAt??null)})]}),(0,J.jsxs)(`div`,{className:`flex flex-col p-2 rounded-lg bg-muted/50`,children:[(0,J.jsx)(`span`,{className:`text-muted-foreground`,children:`Input`}),(0,J.jsx)(`span`,{className:`text-lg font-semibold`,children:a.input.toLocaleString()})]}),(0,J.jsxs)(`div`,{className:`flex flex-col p-2 rounded-lg bg-muted/50`,children:[(0,J.jsx)(`span`,{className:`text-muted-foreground`,children:`Output`}),(0,J.jsx)(`span`,{className:`text-lg font-semibold`,children:a.output.toLocaleString()})]})]}),o>0&&(0,J.jsxs)(`div`,{className:`flex justify-between items-center p-2 rounded-lg bg-green-500/10`,children:[(0,J.jsx)(`span`,{className:`text-sm text-muted-foreground`,children:`Cost`}),(0,J.jsxs)(`span`,{className:`text-lg font-semibold text-green-600 dark:text-green-400`,children:[`$`,o.toFixed(4)]})]})]}),c.length>0&&(()=>{let e=c.filter(e=>e.status===`completed`).length,t=c.filter(e=>e.status===`in_progress`).length,n=c.length>0?Math.round(e/c.length*100):0,r=e===c.length;return(0,J.jsxs)(`div`,{className:`px-4 py-3 border-b space-y-2.5`,children:[(0,J.jsxs)(`h3`,{className:`text-sm font-medium flex items-center justify-between`,children:[(0,J.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,J.jsx)(vt,{className:`h-4 w-4 text-muted-foreground`}),`Plan`]}),(0,J.jsxs)(`span`,{className:`tabular text-[10px] text-muted-foreground`,children:[e,`/`,c.length]})]}),(0,J.jsx)(`div`,{className:q(`relative h-1.5 w-full overflow-hidden rounded-full bg-muted`,t>0&&`bar-sweep`),title:`${n}% complete`,children:(0,J.jsx)(`div`,{className:q(`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,J.jsx)(`ul`,{className:`space-y-0.5 max-h-56 overflow-y-auto pr-1 -mx-1`,children:c.map(e=>{let t=e.status===`completed`?g:e.status===`in_progress`?ue:v,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,J.jsxs)(`li`,{className:q(`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,J.jsx)(t,{className:q(`h-3.5 w-3.5 mt-0.5 shrink-0`,n&&`text-primary animate-pulse`)}),(0,J.jsx)(`span`,{className:`break-words`,children:n&&e.activeForm?e.activeForm:e.content})]},e.id)})})]})})(),m.length>0&&(0,J.jsxs)(`div`,{className:`px-4 py-3 border-b space-y-2`,children:[(0,J.jsxs)(`h3`,{className:`text-sm font-medium flex items-center justify-between`,children:[(0,J.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,J.jsx)(Qe,{className:`h-4 w-4 text-amber-500`}),`Pinned`]}),(0,J.jsx)(`button`,{type:`button`,onClick:f,className:`text-[10px] text-muted-foreground hover:text-destructive`,children:`Clear`})]}),(0,J.jsx)(`ul`,{className:`space-y-1 max-h-48 overflow-y-auto pr-1`,children:m.map(e=>{let t=e.content.replace(/\s+/g,` `).slice(0,80);return(0,J.jsx)(`li`,{children:(0,J.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)})})]})]})}function la({wsConnected:e}){let t=U(e=>e.clearMessages),{client:n}=Y();return(0,J.jsxs)(`div`,{className:`px-4 py-3 border-b space-y-2`,children:[(0,J.jsxs)(X,{variant:`outline`,size:`sm`,className:`w-full justify-start text-destructive hover:text-destructive`,onClick:()=>{t(),n?.clearContext?.()},children:[(0,J.jsx)(N,{className:`h-4 w-4 mr-2`}),`Clear context`]}),(0,J.jsxs)(X,{variant:`outline`,size:`sm`,className:`w-full justify-start`,onClick:()=>n?.newSession?.(),disabled:!e,children:[(0,J.jsx)(pe,{className:`h-4 w-4 mr-2`}),`New session`]}),(0,J.jsxs)(X,{variant:`outline`,size:`sm`,className:`w-full justify-start`,onClick:()=>n?.compactContext?.(),disabled:!e,children:[(0,J.jsx)(E,{className:`h-4 w-4 mr-2`}),`Compact context`]})]})}var ua=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 da({historyQuery:e,setHistoryQuery:t,historyEntries:n,historyLoading:r,historyError:i,wsConnected:a,listSessions:o,resumeSession:c,deleteSession:l}){let u=K(e=>e.favoriteSessionIds),d=K(e=>e.toggleFavoriteSession),f=K(e=>e.sessionNicknames),p=K(e=>e.setSessionNickname),[m,h]=(0,V.useState)(null),[g,_]=(0,V.useState)(``),v=(()=>{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 l=new Set(u),d=r.filter(e=>l.has(e.id)),f=[];d.length&&f.push({label:`Favorites`,rows:d,star:!0});let p=e=>e.filter(e=>!l.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,J.jsxs)(J.Fragment,{children:[(0,J.jsxs)(`div`,{className:`flex items-center justify-between px-4 py-2 border-b`,children:[(0,J.jsx)(`span`,{className:`text-xs uppercase tracking-wider text-muted-foreground`,children:`Recent sessions`}),(0,J.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,J.jsx)(R,{className:`h-3.5 w-3.5 animate-spin`}):(0,J.jsx)(he,{className:`h-3.5 w-3.5`})})]}),n.length>3&&(0,J.jsx)(`div`,{className:`px-3 py-2 border-b`,children:(0,J.jsxs)(`div`,{className:`relative`,children:[(0,J.jsx)(x,{className:`absolute left-2 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-muted-foreground/60`}),(0,J.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,J.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,J.jsx)(s,{className:`h-3 w-3`})})]})}),i&&(0,J.jsx)(`div`,{className:`px-4 py-2 text-xs text-destructive bg-destructive/5 border-b`,children:i}),(0,J.jsx)(xi,{className:`flex-1`,children:n.length===0&&!r?(0,J.jsxs)(`div`,{className:`text-center text-muted-foreground py-8 px-4`,children:[(0,J.jsx)(bt,{className:`h-8 w-8 mx-auto mb-3 opacity-20`}),(0,J.jsx)(`p`,{className:`text-sm font-medium`,children:`No history yet`}),(0,J.jsx)(`p`,{className:`text-xs mt-1`,children:`Your conversations will appear here`})]}):v.length===0?(0,J.jsxs)(`div`,{className:`text-center text-muted-foreground py-8 px-4`,children:[(0,J.jsx)(x,{className:`h-8 w-8 mx-auto mb-3 opacity-20`}),(0,J.jsx)(`p`,{className:`text-sm font-medium`,children:`No matches`}),(0,J.jsx)(`p`,{className:`text-xs mt-1`,children:`Try a different filter`})]}):(0,J.jsx)(`div`,{className:`p-2 space-y-3`,children:v.map(e=>(0,J.jsxs)(`div`,{className:`space-y-1`,children:[(0,J.jsxs)(`div`,{className:q(`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,J.jsx)(Tt,{className:`h-3 w-3 fill-current`}),e.label,` `,(0,J.jsxs)(`span`,{className:`text-muted-foreground/50 font-normal normal-case ml-1`,children:[`(`,e.rows.length,`)`]})]}),e.rows.map(e=>(0,J.jsxs)(`div`,{className:q(`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,J.jsx)(`button`,{type:`button`,disabled:e.isCurrent||m===e.id,onClick:()=>c(e.id),onDoubleClick:t=>{t.stopPropagation(),h(e.id),_(f[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,J.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[m===e.id?(0,J.jsx)(`input`,{value:g,onChange:e=>_(e.target.value),onClick:e=>e.stopPropagation(),onBlur:()=>{p(e.id,g),h(null)},onKeyDown:t=>{t.key===`Enter`?(t.preventDefault(),p(e.id,g),h(null)):t.key===`Escape`&&(t.preventDefault(),h(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,J.jsx)(`div`,{className:`font-medium truncate text-foreground`,title:f[e.id]?`${f[e.id]} — original: ${e.title}`:`${e.title}\n\nDouble-click to rename`,children:f[e.id]||e.title||`(empty)`}),(0,J.jsxs)(`div`,{className:`text-[10px] text-muted-foreground font-mono truncate mt-0.5`,children:[e.provider,`/`,e.model]}),(0,J.jsxs)(`div`,{className:`flex items-center gap-2 text-[10px] text-muted-foreground/80 mt-0.5`,children:[(0,J.jsx)(`span`,{children:ua(e.startedAt)}),e.tokenTotal>0&&(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(`span`,{children:`·`}),(0,J.jsxs)(`span`,{className:`tabular-nums`,children:[e.tokenTotal.toLocaleString(),` tok`]})]}),e.isCurrent&&(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(`span`,{children:`·`}),(0,J.jsx)(`span`,{className:`text-primary font-medium`,children:`active`})]})]})]})}),(0,J.jsxs)(`div`,{className:`absolute right-2 top-2 flex items-center gap-1`,children:[(0,J.jsx)(`button`,{type:`button`,onClick:()=>d(e.id),className:q(`transition-opacity hover:text-amber-500`,u.includes(e.id)?`opacity-100 text-amber-500`:`opacity-0 group-hover:opacity-100 text-muted-foreground`),title:u.includes(e.id)?`Unfavorite`:`Mark as favorite`,children:(0,J.jsx)(Tt,{className:q(`h-3.5 w-3.5`,u.includes(e.id)&&`fill-current`)})}),!e.isCurrent&&(0,J.jsx)(`button`,{type:`button`,onClick:()=>{window.confirm(`Delete session "${e.title}"?`)&&l(e.id)},className:`opacity-0 group-hover:opacity-100 transition-opacity text-muted-foreground hover:text-destructive`,title:`Delete session`,children:(0,J.jsx)(N,{className:`h-3.5 w-3.5`})})]})]},e.id))]},e.label))})})]})}var fa={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 pa(e){return e<=0?`$0`:e>=.01?`${e.toFixed(3)}`:`${e.toFixed(4)}`}function ma({agent:e,onClick:t}){let n=fa[e.status],r=e.status===`running`;return(0,J.jsxs)(`button`,{type:`button`,onClick:t,className:q(`w-full text-left rounded-lg border px-2.5 py-2 transition-colors`,`hover:border-primary/40 hover:bg-primary/[0.04]`,r?`border-primary/30 bg-primary/[0.03]`:`border-border/60 bg-card/40`),children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-1.5 min-w-0`,children:[(0,J.jsx)(`span`,{className:q(`led shrink-0`,n.led,n.pulse&&`led-pulse`)}),(0,J.jsx)(`span`,{className:`truncate text-[11px] font-semibold`,title:e.name,children:e.name}),(0,J.jsxs)(`span`,{className:`tabular ml-auto shrink-0 text-[10px] text-muted-foreground`,children:[e.iteration,`it`]})]}),(0,J.jsxs)(`div`,{className:`flex items-center gap-1.5 mt-0.5 min-w-0`,children:[e.model?(0,J.jsx)(`span`,{className:`text-[10px] text-muted-foreground truncate font-mono`,children:e.model}):(0,J.jsx)(`span`,{className:`text-[10px] text-muted-foreground italic`,children:`pending…`}),(0,J.jsx)(`span`,{className:`tabular ml-auto text-[10px] text-foreground/70`,children:pa(e.costUsd)})]}),(e.currentTool||e.lastTool)&&(0,J.jsxs)(`div`,{className:`flex items-center gap-1 mt-1 text-[10px] text-muted-foreground truncate`,children:[(0,J.jsx)(yt,{className:q(`h-2.5 w-2.5 shrink-0`,r&&`animate-pulse text-primary`)}),(0,J.jsx)(`span`,{className:`truncate font-mono`,children:e.currentTool??e.lastTool})]})]})}function ha(){let{toggleSidebar:e,currentView:t,setCurrentView:n}=K(),r=K(e=>e.sidebarWidth),i=K(e=>e.setSidebarWidth),{wsConnected:a,wsUrl:o}=W(),{entries:s,loading:c,error:l}=Kt(),{listSessions:u,deleteSession:d,resumeSession:f,client:p}=Y(),m=G(e=>e.session),h=G(e=>e.projectName),g=Yt(e=>e.agents),[_,v]=(0,V.useState)(null),y=(0,V.useMemo)(()=>{let e=Array.from(g.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},[g]),b=_?y.find(e=>e.id===_)??null:null;y.filter(e=>e.status===`running`).length;let x=y.length,[S,w]=(0,V.useState)(``),T=m?.id;return(0,V.useEffect)(()=>{a&&p?.getTodos?.()},[a,p]),(0,V.useEffect)(()=>{t===`history`&&a&&u(50)},[t,a,T,u]),(0,V.useEffect)(()=>{a&&u(50)},[a,T,u]),(0,J.jsxs)(`aside`,{style:{width:`${r}px`},className:`relative border-r bg-card flex flex-col shrink-0`,children:[(0,J.jsxs)(`div`,{onMouseDown:e=>{e.preventDefault();let t=e.clientX,n=r,a=e=>{i(n+(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:()=>i(288),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,J.jsx)(`div`,{className:`h-full w-px bg-border group-hover/handle:bg-primary/60 group-hover/handle:w-0.5 transition-all`}),(0,J.jsxs)(`div`,{className:`absolute right-0 top-1/2 -translate-y-1/2 flex flex-col gap-0.5 opacity-0 group-hover/handle:opacity-100 transition-opacity pr-0.5`,children:[(0,J.jsx)(`span`,{className:`h-1 w-1 rounded-full bg-primary/70`}),(0,J.jsx)(`span`,{className:`h-1 w-1 rounded-full bg-primary/70`}),(0,J.jsx)(`span`,{className:`h-1 w-1 rounded-full bg-primary/70`})]})]}),(0,J.jsxs)(`div`,{className:`flex items-center justify-between px-4 py-3 border-b`,children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-2.5`,children:[(0,J.jsx)(`div`,{className:`relative w-7 h-7 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)]`,children:(0,J.jsx)(I,{className:`h-4 w-4 text-primary-foreground`,strokeWidth:2.4})}),(0,J.jsxs)(`div`,{className:`flex flex-col leading-none`,children:[(0,J.jsx)(`span`,{className:`text-sm font-semibold tracking-tight`,children:h||`Agent`}),(0,J.jsxs)(`span`,{className:`flex items-center gap-1 text-[10px] text-muted-foreground mt-0.5`,children:[(0,J.jsx)(`span`,{className:q(`led`,a?`text-[hsl(var(--success))] led-pulse`:`text-[hsl(var(--warning))]`)}),(0,J.jsx)(`span`,{className:`tabular font-medium uppercase tracking-wider`,children:a?`online`:`offline`})]})]})]}),(0,J.jsx)(X,{variant:`ghost`,size:`icon`,onClick:e,title:`Collapse sidebar (Ctrl+\\\\)`,children:(0,J.jsx)(tt,{className:`h-4 w-4`})})]}),(0,J.jsxs)(Qi,{value:t===`chat`||t===`history`||t===`agents`?t:`__none__`,onValueChange:e=>n(e),className:`flex-1 flex flex-col`,children:[(0,J.jsxs)($i,{className:`w-full rounded-none bg-transparent p-2 h-auto grid grid-cols-3`,children:[(0,J.jsxs)(Z,{value:`chat`,className:`flex-col gap-1.5 py-2 data-[state=active]:bg-primary/10`,children:[(0,J.jsx)(Ne,{className:`h-4 w-4`}),(0,J.jsx)(`span`,{className:`text-xs`,children:`Chat`})]}),(0,J.jsxs)(Z,{value:`agents`,className:`flex-col gap-1.5 py-2 data-[state=active]:bg-primary/10`,children:[(0,J.jsx)(ke,{className:`h-4 w-4`}),(0,J.jsxs)(`span`,{className:`text-xs`,children:[`Agents`,x>0?` · ${x}`:``]})]}),(0,J.jsxs)(Z,{value:`history`,className:`flex-col gap-1.5 py-2 data-[state=active]:bg-primary/10`,children:[(0,J.jsx)(bt,{className:`h-4 w-4`}),(0,J.jsx)(`span`,{className:`text-xs`,children:`History`})]})]}),(0,J.jsxs)(Q,{value:`chat`,className:`flex-1 flex flex-col m-0 overflow-hidden`,children:[(0,J.jsx)(ca,{formatDuration:e=>{if(!e)return`--`;let t=Math.floor((Date.now()-e)/1e3);return t<60?`${t}s`:`${Math.floor(t/60)}m`}}),(0,J.jsx)(la,{wsConnected:a}),(0,J.jsx)(`div`,{className:`flex-1`}),(0,J.jsxs)(`div`,{className:`px-3 py-3 border-t space-y-1`,children:[(0,J.jsxs)(X,{variant:`ghost`,size:`sm`,className:`w-full justify-start`,onClick:()=>n(`settings`),children:[(0,J.jsx)(C,{className:`h-4 w-4 mr-2`}),`Settings`]}),(0,J.jsxs)(X,{variant:`ghost`,size:`sm`,className:`w-full justify-start`,onClick:()=>n(`autophase`),children:[(0,J.jsx)(wt,{className:`h-4 w-4 mr-2`}),`Phases`]})]})]}),(0,J.jsx)(Q,{value:`history`,className:`flex-1 m-0 flex flex-col overflow-hidden`,children:(0,J.jsx)(da,{historyQuery:S,setHistoryQuery:w,historyEntries:s,historyLoading:c,historyError:l,wsConnected:a,listSessions:u,resumeSession:f,deleteSession:d})}),(0,J.jsx)(Q,{value:`agents`,className:`flex-1 m-0 flex flex-col overflow-hidden`,children:x===0?(0,J.jsx)(`div`,{className:`flex-1 flex items-center justify-center p-4`,children:(0,J.jsxs)(`p`,{className:`text-xs text-muted-foreground text-center`,children:[`No agents running.`,(0,J.jsx)(`br`,{}),`Agents appear here when the fleet is active.`]})}):(0,J.jsx)(`div`,{className:`flex-1 overflow-y-auto p-2 space-y-1.5`,children:y.map(e=>(0,J.jsx)(ma,{agent:e,onClick:()=>v(e.id)},e.id))})})]}),b&&(0,J.jsx)(Wi,{agent:b,onClose:()=>v(null)})]})}var ga={in_progress:0,pending:1,completed:2};function _a(){let[e,t]=(0,V.useState)([]),[n,r]=(0,V.useState)(new Set),i=H(),a=(0,V.useRef)(null);(0,V.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,V.useCallback)(e=>{i.removeTodo(e)},[i]),s=[...e].sort((e,t)=>(ga[e.status]??9)-(ga[t.status]??9)),c=s.filter(e=>e.status===`in_progress`),l=s.filter(e=>e.status===`pending`),u=s.filter(e=>e.status===`completed`),d=u.length>0,f=n.has(`completed`),p=e=>{r(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},m=e=>{let t=e.status===`in_progress`&&e.activeForm?e.activeForm:e.content,n=e.status===`in_progress`,r=e.status===`completed`;return(0,J.jsxs)(`div`,{className:`px-3 py-1.5 flex items-start gap-2 text-[13px] group transition-colors ${n?`bg-yellow-50/40 dark:bg-yellow-950/25`:r?`bg-emerald-50/20 dark:bg-emerald-950/10`:``}`,children:[(0,J.jsx)(`span`,{className:`mt-0.5 shrink-0`,children:r?(0,J.jsx)(g,{className:`w-3.5 h-3.5 text-emerald-500`}):n?(0,J.jsx)(L,{className:`w-3.5 h-3.5 text-yellow-500 animate-spin`}):(0,J.jsx)(v,{className:`w-3.5 h-3.5 text-muted-foreground/40`})}),(0,J.jsx)(`span`,{className:`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,J.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`,children:(0,J.jsx)(N,{className:`w-3 h-3 text-muted-foreground`})})]},e.id)};return e.length===0?null:(0,J.jsxs)(`div`,{className:`rounded-lg border border-border bg-card/50 backdrop-blur-sm overflow-hidden`,children:[(0,J.jsxs)(`div`,{className:`px-3 py-1.5 flex items-center gap-2 border-b border-border/50`,children:[(0,J.jsx)(`h2`,{className:`text-[11px] font-semibold text-foreground uppercase tracking-wider`,children:`Todos`}),(0,J.jsxs)(`span`,{className:`tabular text-[10px] text-muted-foreground ml-auto`,children:[u.length,`/`,e.length]})]}),c.length>0&&(0,J.jsx)(`div`,{className:`border-b border-border/30 last:border-b-0`,children:c.map(m)}),l.length>0&&(0,J.jsx)(`div`,{className:`border-b border-border/30 last:border-b-0`,children:l.map(m)}),d&&(0,J.jsxs)(`div`,{children:[(0,J.jsx)(`button`,{type:`button`,onClick:()=>p(`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,J.jsxs)(`span`,{className:`tabular`,children:[f?`▶`:`▼`,` `,u.length,` completed`]})}),!f&&u.map(m)]})]})}function va(){let{theme:e}=fi(),{currentView:t,sidebarOpen:n,toggleSidebar:r,setSearchOpen:i,setSidebarOpen:a,setCurrentView:o}=K(),s=U(e=>e.isLoading),c=G(e=>e.iteration),l=G(e=>e.projectName),u=G(e=>e.session?.title),d=G(e=>e.session?.id),f=K(e=>d?e.sessionNicknames[d]:void 0),p=Zt(e=>e.goal),m=qt(e=>e.worktrees),h=qt(e=>e.baseBranch),g=Qt(e=>e),[_,v]=(0,V.useState)(`graph`);return(0,V.useEffect)(()=>{if(typeof window>`u`)return;let e=window.matchMedia(`(max-width: 768px)`),t=()=>{e.matches&&K.getState().sidebarOpen&&a(!1)};return t(),e.addEventListener(`change`,t),()=>e.removeEventListener(`change`,t)},[a]),Jn(),(0,V.useEffect)(()=>{let e=[];if(s){let t=c?` iter ${c.index}${c.max?`/${c.max}`:``}`:``;e.push(`●${t}`)}let t=f?.trim()||u?.trim(),n=l?.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=l||`AI Agent`}},[s,c,l,u,f]),(0,V.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.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(),U.getState().clearMessages(),H(W.getState().wsUrl)?.clearContext?.()):e.key.toLowerCase()===`n`?(e.preventDefault(),H(W.getState().wsUrl)?.newSession?.()):e.key.toLowerCase()===`e`&&(e.preventDefault(),_r())),o&&e.shiftKey&&e.key.toLowerCase()===`d`&&(e.preventDefault(),K.getState().toggleCompactMode()),!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(B(t[0]));return}if(e.key===`G`||e.key===`g`&&e.shiftKey){e.preventDefault(),i(B(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,J.jsxs)(`div`,{className:q(`flex h-screen`,e),children:[n&&(0,J.jsx)(ha,{}),(0,J.jsxs)(`main`,{className:`flex-1 flex flex-col overflow-hidden`,children:[(0,J.jsx)(Ri,{}),(t===`chat`||t===`agents`)&&(0,J.jsxs)(J.Fragment,{children:[d&&(0,J.jsxs)(`div`,{className:`px-4 pt-2 space-y-2`,children:[(0,J.jsx)(`div`,{id:`panel-collab`,children:(0,J.jsx)(Ei,{sessionId:d})}),(0,J.jsx)(`div`,{id:`panel-goal`,children:(0,J.jsx)(Yi,{goal:p})}),g.phases.length>0&&(0,J.jsx)(Qn,{phases:g.phases,activePhaseId:g.activePhaseId??void 0,overallPercent:g.overallPercent,autonomous:g.autonomous}),(0,J.jsx)(`div`,{id:`panel-fleet`,children:(0,J.jsx)(Ki,{})}),(0,J.jsx)(`div`,{id:`panel-todos`,children:(0,J.jsx)(_a,{})}),m.length>0&&(0,J.jsxs)(`div`,{id:`panel-worktree`,className:`space-y-2`,children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,J.jsx)(`button`,{type:`button`,onClick:()=>v(`graph`),className:q(`text-[10px] px-2 py-0.5 rounded-full border transition-colors`,_===`graph`?`bg-primary/10 border-primary/30 text-primary`:`border-border text-muted-foreground hover:text-foreground`),children:`Graph`}),(0,J.jsx)(`button`,{type:`button`,onClick:()=>v(`lanes`),className:q(`text-[10px] px-2 py-0.5 rounded-full border transition-colors`,_===`lanes`?`bg-primary/10 border-primary/30 text-primary`:`border-border text-muted-foreground hover:text-foreground`),children:`Lanes`})]}),_===`graph`?(0,J.jsx)(cr,{worktrees:m,baseBranch:h||`HEAD`}):(0,J.jsx)(fr,{worktrees:m,baseBranch:h||`HEAD`})]})]}),(0,J.jsx)(Ti,{})]}),t===`settings`&&(0,J.jsx)(aa,{}),t===`autophase`&&(0,J.jsx)(mr,{onClose:()=>o(`chat`)})]}),(0,J.jsx)(Li,{}),(0,J.jsx)(yr,{}),(0,J.jsx)(sa,{}),(0,J.jsx)(Xi,{}),(0,J.jsx)(on,{})]})}function ya(){return(0,J.jsx)(zi,{children:(0,J.jsx)(di,{defaultTheme:`system`,children:(0,J.jsx)(va,{})})})}Dt.createRoot(B(document.getElementById(`root`))).render((0,J.jsx)(V.StrictMode,{children:(0,J.jsx)(ya,{})}));