@wrongstack/webui 0.275.0 → 0.275.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -133,7 +133,7 @@ Type while the agent is running to queue messages; they are sent automatically w
|
|
|
133
133
|
`):``),v(i.url??``)):(o(``),c(`stdio`),u(``),b(!0),S(!1),f(``),m(``),g(``),v(``)))},[n,i,e]);let C=()=>{if(!a.trim()){Z.error(`Server name is required`);return}let e={};if(h.trim())for(let t of h.trim().split(`
|
|
134
134
|
`)){let n=t.indexOf(`=`);n>0&&(e[t.slice(0,n).trim()]=t.slice(n+1).trim())}r({name:a.trim(),transport:s,description:l.trim()||void 0,enabled:y,command:d.trim()||void 0,args:p.trim()?p.trim().split(/\s+/):void 0,env:Object.keys(e).length>0?e:void 0,url:_.trim()||void 0,lazy:x}),t(!1)},w=!!n,T=!!i;return(0,J.jsx)(sc,{open:e,onOpenChange:t,children:(0,J.jsxs)(dc,{children:[(0,J.jsx)(fc,{children:(0,J.jsx)(mc,{children:w?`Edit MCP Server`:T?`Add MCP Server`:`Add Custom MCP Server`})}),(0,J.jsxs)(`div`,{className:`space-y-4 py-4`,children:[(0,J.jsxs)(`div`,{className:`space-y-2`,children:[(0,J.jsx)(`label`,{className:`text-sm font-medium`,children:`Name`}),(0,J.jsx)(gc,{value:a,onChange:e=>o(e.target.value),placeholder:`e.g., github, filesystem`,disabled:w||T})]}),(0,J.jsxs)(`div`,{className:`space-y-2`,children:[(0,J.jsx)(`label`,{className:`text-sm font-medium`,children:`Transport`}),(0,J.jsxs)(`select`,{className:`w-full h-10 px-3 rounded-md border border-input bg-background text-sm`,value:s,onChange:e=>c(e.target.value),disabled:T,children:[(0,J.jsx)(`option`,{value:`stdio`,children:`stdio`}),(0,J.jsx)(`option`,{value:`sse`,children:`sse`}),(0,J.jsx)(`option`,{value:`streamable-http`,children:`streamable-http`}),(0,J.jsx)(`option`,{value:`http`,children:`http`})]})]}),(s===`streamable-http`||s===`sse`||s===`http`)&&(0,J.jsxs)(`div`,{className:`space-y-2`,children:[(0,J.jsx)(`label`,{className:`text-sm font-medium`,children:`URL`}),(0,J.jsx)(gc,{value:_,onChange:e=>v(e.target.value),placeholder:`https://mcp.example.com/mcp`,disabled:T})]}),s===`stdio`&&(0,J.jsxs)(J.Fragment,{children:[(0,J.jsxs)(`div`,{className:`space-y-2`,children:[(0,J.jsx)(`label`,{className:`text-sm font-medium`,children:`Command`}),(0,J.jsx)(gc,{value:d,onChange:e=>f(e.target.value),placeholder:`e.g., npx`,disabled:T})]}),(0,J.jsxs)(`div`,{className:`space-y-2`,children:[(0,J.jsxs)(`label`,{className:`text-sm font-medium`,children:[`Args `,(0,J.jsx)(`span`,{className:`text-muted-foreground font-normal`,children:`(space-separated)`})]}),(0,J.jsx)(gc,{value:p,onChange:e=>m(e.target.value),placeholder:`e.g., -y @modelcontextprotocol/server-github`,disabled:T})]})]}),(0,J.jsxs)(`div`,{className:`space-y-2`,children:[(0,J.jsxs)(`label`,{className:`text-sm font-medium`,children:[`Env vars`,` `,(0,J.jsx)(`span`,{className:`text-muted-foreground font-normal`,children:`(KEY=value, one per line)`})]}),(0,J.jsx)(`textarea`,{className:`w-full h-20 px-3 py-2 rounded-md border border-input bg-background text-sm font-mono resize-none`,value:h,onChange:e=>g(e.target.value),placeholder:`GITHUB_TOKEN=ghp_...
|
|
135
135
|
AWS_REGION=us-east-1`})]}),(0,J.jsxs)(`div`,{className:`space-y-2`,children:[(0,J.jsx)(`label`,{className:`text-sm font-medium`,children:`Description`}),(0,J.jsx)(gc,{value:l,onChange:e=>u(e.target.value),placeholder:`GitHub MCP server for repository access`})]}),(0,J.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,J.jsx)(`input`,{type:`checkbox`,id:`server-enabled`,checked:y,onChange:e=>b(e.target.checked),className:`rounded`}),(0,J.jsx)(`label`,{htmlFor:`server-enabled`,className:`text-sm`,children:`Enable server`})]}),(0,J.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,J.jsx)(`input`,{type:`checkbox`,id:`server-lazy`,checked:x,onChange:e=>S(e.target.checked),className:`rounded`}),(0,J.jsxs)(`label`,{htmlFor:`server-lazy`,className:`text-sm`,children:[`Lazy connect`,` `,(0,J.jsx)(`span`,{className:`text-muted-foreground font-normal`,children:`(don't start until first tool call; auto-sleeps when idle)`})]})]})]}),(0,J.jsxs)(pc,{children:[(0,J.jsx)($,{variant:`outline`,onClick:()=>t(!1),children:`Cancel`}),(0,J.jsx)($,{onClick:C,children:w?`Save Changes`:`Add Server`})]})]})})}function pf({server:e,isAdded:t,onAdd:n}){return(0,J.jsxs)(`div`,{className:`border rounded-lg p-3 bg-card flex items-start justify-between gap-3`,children:[(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:`font-medium text-sm`,children:e.name}),e.badge&&(0,J.jsx)(of,{variant:`secondary`,className:`text-xs shrink-0`,children:e.badge}),(0,J.jsx)(of,{variant:`outline`,className:`text-xs shrink-0`,children:e.transport})]}),(0,J.jsx)(`p`,{className:`text-xs text-muted-foreground mt-1`,children:e.description}),e.requiresEnvVars&&e.requiresEnvVars.length>0&&(0,J.jsxs)(`p`,{className:`text-xs text-amber-600 dark:text-amber-400 mt-1`,children:[`Requires: `,e.requiresEnvVars.join(`, `)]})]}),(0,J.jsx)(`div`,{className:`shrink-0`,children:t?(0,J.jsxs)($,{variant:`ghost`,size:`sm`,disabled:!0,children:[(0,J.jsx)(i,{className:`w-4 h-4 mr-1`}),`Added`]}):(0,J.jsxs)($,{size:`sm`,variant:`outline`,onClick:n,children:[(0,J.jsx)(tr,{className:`w-4 h-4 mr-1`}),`Add`]})})]})}function mf(){let e=Q(),[t,n]=(0,H.useState)([]),[r,i]=(0,H.useState)(!1),[a,o]=(0,H.useState)(`list`),[s,c]=(0,H.useState)(),[l,u]=(0,H.useState)(!1),[d,f]=(0,H.useState)(!1),[p,m]=(0,H.useState)(),[h,g]=(0,H.useState)(null);(0,H.useEffect)(()=>{if(!e.client)return;let t=e=>{if(e.type===`mcp.list`){let t=e.payload;n(t.servers??[]),i(!1)}},r=e=>{if(e.type===`mcp.server.added`){let t=e.payload;n(e=>[...e.filter(e=>e.name!==t.server.name),t.server]),Z.success(`Server "${t.server.name}" added`)}},a=e=>{if(e.type===`mcp.server.removed`){let t=e.payload;n(e=>e.filter(e=>e.name!==t.name)),Z.success(`Server "${t.name}" removed`)}},o=e=>{if(e.type===`mcp.server.updated`){let t=e.payload;n(e=>e.map(e=>e.name===t.server.name?t.server:e))}},s=e=>{if(e.type===`mcp.server.discovered`){let t=e.payload;n(e=>e.map(e=>e.name===t.name?{...e,status:`sleeping`,tools:t.tools}:e)),g(null),Z.success(`Discovered ${t.tools.length} tools from "${t.name}"`)}},c=e=>{if(e.type===`mcp.server.sleeping`){let t=e.payload;n(e=>e.map(e=>e.name===t.name?{...e,status:`sleeping`}:e)),g(null),Z.info(`Server "${t.name}" is now sleeping`)}},l=e=>{if(e.type===`mcp.server.waking`){let t=e.payload;n(e=>e.map(e=>e.name===t.name?{...e,status:`connecting`}:e))}},u=e=>{if(e.type===`mcp.server.connected`){let t=e.payload;n(e=>e.map(e=>e.name===t.name?{...e,status:`connected`,pid:t.pid,error:void 0,lastError:void 0}:e)),g(null),Z.success(`Server "${t.name}" connected`)}},d=e=>{if(e.type===`mcp.server.reconnected`){let t=e.payload;n(e=>e.map(e=>e.name===t.name?{...e,status:`connected`,error:void 0,lastError:void 0}:e)),g(null),Z.success(`Server "${t.name}" reconnected`)}},f=e=>{if(e.type===`mcp.server.disconnected`){let t=e.payload;n(e=>e.map(e=>e.name===t.name?{...e,status:`error`,error:t.reason,lastError:t.reason,pid:void 0}:e)),g(null),Z.warn(`Server "${t.name}" disconnected: ${t.reason}`)}},p=e=>{if(e.type===`mcp.server.error`){let t=e.payload;n(e=>e.map(e=>e.name===t.name?{...e,status:`error`,error:t.error}:e)),g(null),Z.error(`Server "${t.name}" error: ${t.error}`)}},m=e=>{if(e.type===`mcp.operation_result`){let t=e.payload;t.success||Z.error(t.message),g(null)}},h=e.client.on(`mcp.list`,t),_=e.client.on(`mcp.server.added`,r),v=e.client.on(`mcp.server.removed`,a),y=e.client.on(`mcp.server.updated`,o),b=e.client.on(`mcp.server.discovered`,s),x=e.client.on(`mcp.server.sleeping`,c),S=e.client.on(`mcp.server.waking`,l),C=e.client.on(`mcp.server.connected`,u),w=e.client.on(`mcp.server.error`,p),T=e.client.on(`mcp.operation_result`,m),E=e.client.on(`mcp.server.reconnected`,d),D=e.client.on(`mcp.server.disconnected`,f);return i(!0),e.client?.listMcpServers(),()=>{h?.(),_?.(),v?.(),y?.(),b?.(),x?.(),S?.(),C?.(),w?.(),T?.(),E?.(),D?.()}},[e.client]);let _=(0,H.useCallback)(t=>{e.client?.addMcpServer(t)},[e]),v=(0,H.useCallback)(e=>{m(cf(e,!1)),f(!0)},[]),y=(0,H.useCallback)(t=>{vc({title:`Remove server "${t}"?`,message:`This removes the MCP server from your configuration.`,confirmLabel:`Remove`,danger:!0}).then(n=>{n&&e.client?.removeMcpServer(t)})},[e]),b=(0,H.useCallback)(e=>{c(e),m(void 0),u(!0)},[]),x=(0,H.useCallback)(t=>{e.client?.updateMcpServer(t)},[e]),S=(0,H.useCallback)(t=>{g(t),e.client?.wakeMcpServer(t)},[e]),C=(0,H.useCallback)(t=>{g(t),e.client?.sleepMcpServer(t)},[e]),w=(0,H.useCallback)(t=>{g(t),e.client?.discoverMcpServer(t)},[e]),T=(0,H.useCallback)(()=>{i(!0),e.client?.listMcpServers()},[e]),E=t.filter(e=>e.status===`connected`).length,D=t.filter(e=>e.status===`sleeping`).length,O=new Set(t.map(e=>e.name));return(0,J.jsxs)(`div`,{className:`space-y-4`,children:[(0,J.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,J.jsx)(se,{className:`w-5 h-5`}),(0,J.jsx)(`h2`,{className:`text-lg font-semibold`,children:`MCP Servers`}),t.length>0&&(0,J.jsxs)(`span`,{className:`text-sm text-muted-foreground`,children:[E,` connected · `,D,` sleeping · `,t.length,` total`]})]}),(0,J.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,J.jsxs)($,{variant:`outline`,size:`sm`,onClick:T,disabled:r,children:[r?(0,J.jsx)(z,{className:`w-4 h-4 animate-spin`}):null,`Refresh`]}),(0,J.jsxs)($,{size:`sm`,onClick:()=>{m(void 0),f(!0)},children:[(0,J.jsx)(tr,{className:`w-4 h-4 mr-1`}),`Add Custom`]})]})]}),(0,J.jsxs)(ef,{value:a,onValueChange:e=>o(e),children:[(0,J.jsxs)(tf,{children:[(0,J.jsxs)(nf,{value:`recommended`,children:[(0,J.jsx)(re,{className:`w-3.5 h-3.5 mr-1`}),`Recommended`]}),(0,J.jsx)(nf,{value:`list`,children:`Servers`}),(0,J.jsx)(nf,{value:`add`,children:`Add Custom`})]}),(0,J.jsxs)(rf,{value:`recommended`,className:`space-y-3`,children:[(0,J.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`One-click add for popular MCP servers. Click Add to pre-fill the configuration, then confirm. Servers requiring credentials will need their env vars set before use.`}),(0,J.jsx)(`div`,{className:`grid gap-2`,children:sf.map(e=>(0,J.jsx)(pf,{server:e,isAdded:O.has(e.name),onAdd:()=>v(e)},e.name))})]}),(0,J.jsx)(rf,{value:`list`,className:`space-y-3`,children:r&&t.length===0?(0,J.jsxs)(`div`,{className:`flex items-center justify-center py-8 text-muted-foreground`,children:[(0,J.jsx)(z,{className:`w-5 h-5 animate-spin mr-2`}),`Loading servers...`]}):t.length===0?(0,J.jsxs)(`div`,{className:`text-center py-8 text-muted-foreground`,children:[(0,J.jsx)(se,{className:`w-10 h-10 mx-auto mb-2 opacity-50`}),(0,J.jsx)(`p`,{children:`No MCP servers configured`}),(0,J.jsx)(`p`,{className:`text-sm`,children:`Switch to the Recommended tab to add popular servers, or Add Custom for your own.`})]}):t.map(e=>(0,J.jsx)(df,{server:e,onWake:()=>S(e.name),onSleep:()=>C(e.name),onDiscover:()=>w(e.name),onEdit:()=>b(e),onRemove:()=>y(e.name)},e.name))}),(0,J.jsx)(rf,{value:`add`,children:(0,J.jsxs)(`div`,{className:`text-sm text-muted-foreground`,children:[(0,J.jsx)(`p`,{children:`Configure a custom MCP server with stdio, SSE, or HTTP transport.`}),(0,J.jsx)(`p`,{className:`mt-1`,children:`For popular servers, use the Recommended tab instead — everything is pre-configured for you.`})]})})]}),(0,J.jsx)(ff,{open:d,onOpenChange:e=>{e||(f(!1),m(void 0))},prefillConfig:p,onSave:_}),(0,J.jsx)(ff,{open:l,onOpenChange:u,server:s,onSave:x})]})}function hf({provider:e,catalogModels:t,currentCatalogProvider:n,isLoadingModels:r,setIsLoadingModels:i,onModelSelect:a,refreshModels:o}){let s=G(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)($,{variant:`ghost`,size:`sm`,onClick:()=>{i(!0),o(e)},children:(0,J.jsx)(Ct,{className:X(`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)(z,{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:X(`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)(M,{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)(_e,{className:`h-8 w-8 mx-auto mb-2 opacity-50`}),(0,J.jsx)(`p`,{children:`Select a provider first`})]})})}function gf({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 _f({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))})]})}function vf({label:e,hint:t,selector:n,onChange:r,configKey:i,value:a}){let o=typeof a==`boolean`,s=q(e=>n?n(e):!1),c=G(e=>i?e[i]:!1),l=o?a:n?s:c;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":l,onClick:()=>{if(o)r?.();else if(n)r?.();else if(i===`soundOnComplete`){let e=!G.getState().soundOnComplete;G.getState().setSoundOnComplete(e),e&&ja()}},className:X(`shrink-0 relative inline-flex h-5 w-9 rounded-full border transition-colors`,l?`bg-primary border-primary`:`bg-muted border-input hover:bg-muted/80`),children:(0,J.jsx)(`span`,{className:X(`absolute top-0.5 left-0.5 h-3.5 w-3.5 rounded-full bg-background shadow transition-transform`,l&&`translate-x-4`)})})]})}function yf({open:e,providerId:t,modelCount:n,onConfirm:r,onCancel:i}){let a=(0,H.useRef)(null);return(0,H.useEffect)(()=>{if(!e)return;let t=e=>{e.key===`Enter`?(e.preventDefault(),r()):e.key===`Escape`&&(e.preventDefault(),i())};return window.addEventListener(`keydown`,t),a.current?.focus(),()=>window.removeEventListener(`keydown`,t)},[e,r,i]),(0,J.jsx)(sc,{open:e,onOpenChange:e=>{e||i()},children:(0,J.jsxs)(dc,{className:`sm:max-w-md border-amber-500/50`,ref:a,tabIndex:-1,"data-clear-allowlist-dialog":!0,children:[(0,J.jsxs)(fc,{children:[(0,J.jsxs)(mc,{className:`flex items-center gap-2`,children:[(0,J.jsx)(Ge,{className:`h-5 w-5 text-amber-500`}),`Clear saved allowlist?`]}),(0,J.jsxs)(hc,{children:[`This will remove the `,n,` pinned model`,n===1?``:`s`,` for`,(0,J.jsxs)(`span`,{className:`font-mono font-medium`,children:[` `,t]}),`. The model picker will fall back to the models.dev catalog.`]})]}),(0,J.jsx)(`div`,{className:`rounded-md bg-muted/50 border border-border/60 px-3 py-2 text-xs text-muted-foreground`,children:`You can undo this for 8 seconds after confirming.`}),(0,J.jsxs)(pc,{className:`gap-2 sm:gap-2 flex-wrap`,children:[(0,J.jsxs)($,{variant:`outline`,size:`sm`,onClick:i,title:`Keep the allowlist (Esc)`,"data-action":`cancel`,children:[`Cancel `,(0,J.jsx)(`kbd`,{className:`ml-1 text-[10px] border rounded px-1 bg-background`,children:`Esc`})]}),(0,J.jsxs)($,{variant:`destructive`,size:`sm`,onClick:r,title:`Clear the allowlist (Enter)`,"data-action":`confirm`,children:[`Clear allowlist `,(0,J.jsx)(`kbd`,{className:`ml-1 text-[10px] border rounded px-1 bg-background/80`,children:`↵`})]})]})]})})}function bf(){return{inFlight:!1,last:null,picked:null}}function xf(e){return{providerId:e.providerId,ok:e.ok,status:e.status,...e.httpStatus===void 0?{}:{httpStatus:e.httpStatus},...e.elapsedMs===void 0?{}:{elapsedMs:e.elapsedMs},...e.modelCount===void 0?{}:{modelCount:e.modelCount},...e.modelIds===void 0?{}:{modelIds:e.modelIds},...e.detail===void 0?{}:{detail:e.detail}}}function Sf(e,t,n){return e.picked?e.picked:e.last?.ok&&e.last.modelIds&&e.last.modelIds.length>0&&e.last.modelIds[0]?e.last.modelIds[0]:t||(n&&n.length>0&&n[0]?n[0]:``)}function Cf(e){if(e.inFlight)return{text:`Probing…`,tone:`muted`};let t=e.last;if(!t)return{text:`Click "Refresh from server" to re-probe /v1/models.`,tone:`muted`};let n=t.elapsedMs===void 0?``:` (${t.elapsedMs}ms)`;switch(t.status){case`ok`:{let e=t.modelCount??t.modelIds?.length??0;return{text:`ok — ${e} model${e===1?``:`s`}${n}`,tone:`success`}}case`unreachable`:return{text:`server unreachable${t.detail?` — ${t.detail}`:``}`,tone:`error`};case`timeout`:return{text:`timed out${t.detail?` — ${t.detail}`:``}`,tone:`error`};case`http_error`:return{text:`got${t.httpStatus===void 0?``:` HTTP ${t.httpStatus}`}${t.detail?` — ${t.detail}`:``}`,tone:`warning`};case`invalid_response`:return{text:t.detail?`unexpected response — ${t.detail}`:`unexpected response shape`,tone:`warning`};case`no_provider`:return{text:`no saved provider — the config may have been removed`,tone:`error`};case`no_base_url`:return{text:`no baseUrl configured`,tone:`warning`}}}function wf(e,t){return e.last?.ok&&e.last.modelIds&&e.last.modelIds.length>0?e.last.modelIds:t??[]}function Tf(e,t){if(!e.last?.ok)return!1;let n=e.last.modelIds;if(!n||n.length===0)return!1;let r=t??[];if(r.length!==n.length)return!0;for(let e=0;e<n.length;e++)if(r[e]!==n[e])return!0;return!1}function Ef(e){return(e?.length??0)>0}function Df(e,t){return`Allowlist cleared for ${e} — ${t} model${t===1?``:`s`} removed`}function Of(e){return e.length>0}function kf(e){return e.previousModels.length===0?{kind:`skip`}:e.onUndoClear?{kind:`callback`,providerId:e.providerId,previousModels:e.previousModels}:{kind:`ws-default`,providerId:e.providerId,previousModels:e.previousModels}}var Af=3e3;function jf({providerId:e,savedPickedModelId:t,savedModels:n,ws:r,onPickModel:i,onClearModels:a,onUndoClear:o}){let[s,c]=(0,H.useState)(()=>bf()),[l,u]=(0,H.useState)(!1);(0,H.useEffect)(()=>r.on(`provider.probe`,t=>{t.type===`provider.probe`&&t.payload.providerId===e&&c(e=>({...e,inFlight:!1,last:xf(t.payload)}))}),[r,e]);let d=(0,H.useCallback)(()=>{c(e=>({...e,inFlight:!0})),r.probeProvider(e,Af)},[r,e]),f=(0,H.useCallback)(t=>{c(e=>({...e,picked:t})),i?.(e,t)},[i,e]),p=(0,H.useCallback)(()=>{u(!0)},[]),m=(0,H.useCallback)(()=>{u(!1)},[]),h=(0,H.useCallback)(()=>{u(!1);let t=n?[...n]:[];c(e=>({...e,picked:null,last:null})),a?a(e):r.clearProviderModels(e),Of(t)&&Z.undoable(Df(e,t.length),()=>{let n=kf({providerId:e,previousModels:t,onUndoClear:o});switch(n.kind){case`skip`:return;case`callback`:o?.(n.providerId,n.previousModels);return;case`ws-default`:r.undoProviderClear(n.providerId,n.previousModels);return}})},[a,o,r,e,n]),g=(0,H.useMemo)(()=>Sf(s,t,n),[s,t,n]),_=(0,H.useMemo)(()=>wf(s,n),[s,n]),v=(0,H.useMemo)(()=>Cf(s),[s]),y=(0,H.useMemo)(()=>Tf(s,n),[s,n]),b=(0,H.useMemo)(()=>Ef(n),[n]);return(0,J.jsxs)(`div`,{className:`rounded-md border border-border/60 bg-muted/30 px-3 py-2`,"data-provider-models-panel":e,children:[(0,J.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-2 min-w-0`,children:[(0,J.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`Using`}),g?(0,J.jsx)(`span`,{className:`text-xs font-mono px-2 py-0.5 rounded bg-primary/10 text-primary`,children:g}):(0,J.jsx)(`span`,{className:`text-xs text-muted-foreground italic`,children:`(no model picked)`})]}),(0,J.jsxs)(`div`,{className:`flex items-center gap-1`,children:[b&&(0,J.jsx)($,{variant:`ghost`,size:`sm`,onClick:p,"aria-label":`Clear saved allowlist for ${e}`,"data-action":`clear-models`,children:`Clear allowlist`}),(0,J.jsx)($,{variant:`ghost`,size:`sm`,onClick:d,disabled:s.inFlight,"aria-label":`Refresh model list for ${e}`,children:s.inFlight?`Probing…`:`Refresh from server`})]})]}),(0,J.jsx)(Mf,{formatted:v}),_.length>0&&(0,J.jsx)(`ul`,{className:`mt-2 flex flex-wrap gap-1.5`,"data-provider-models-list":e,children:_.map(t=>(0,J.jsxs)(`li`,{className:`flex items-center gap-1`,children:[(0,J.jsx)(`span`,{className:t===g?`text-xs font-mono px-2 py-0.5 rounded bg-primary/10 text-primary`:`text-xs font-mono px-2 py-0.5 rounded border border-border text-foreground/80`,children:t}),t!==g&&(0,J.jsx)($,{variant:`link`,size:`sm`,onClick:()=>f(t),className:`text-xs h-5 px-1`,"aria-label":`Use model ${t} for ${e}`,children:`Use`})]},t))}),y&&(0,J.jsxs)(`p`,{className:`mt-2 text-xs text-muted-foreground`,children:[`Probed list differs from the saved allowlist — re-run`,(0,J.jsx)(`span`,{className:`font-mono`,children:` wstack auth local --model first`}),`to persist.`]}),(0,J.jsx)(yf,{open:l,providerId:e,modelCount:n?.length??0,onConfirm:h,onCancel:m})]})}function Mf({formatted:e}){return(0,J.jsx)(`p`,{className:`mt-1 text-xs ${e.tone===`success`?`text-emerald-600 dark:text-emerald-400`:e.tone===`warning`?`text-amber-600 dark:text-amber-400`:e.tone===`error`?`text-rose-600 dark:text-rose-400`:`text-muted-foreground`}`,"data-probe-tone":e.tone,children:e.text})}var Nf=[`anthropic`,`openai`,`google`,`openai-compatible`];function Pf({activeProvider:e,catalogProviders:t,isLoadingCatalog:n,savedProviders:r,isLoadingSaved:i,providerTab:a,setProviderTab:o,onSelectProvider:s,onAddKey:c,onDeleteKey:l,onSetActiveKey:u,onAddProvider:d,onRemoveProvider:f,onPickProviderModel:p,ws:m,catalogQuery:h,setCatalogQuery:_}){let[v,y]=(0,H.useState)(null),[b,x]=(0,H.useState)(``),[S,C]=(0,H.useState)(``),[w,T]=(0,H.useState)(!1),[E,D]=(0,H.useState)(!1),[O,k]=(0,H.useState)(``),[A,j]=(0,H.useState)(`openai-compatible`),[N,P]=(0,H.useState)(``),[F,I]=(0,H.useState)(``),ee=(0,H.useCallback)(e=>{!b.trim()||!S.trim()||(c(e,b.trim(),S.trim()),x(``),C(``),y(null))},[c,b,S]),te=(0,H.useCallback)(()=>{O.trim()&&(d(O.trim(),A,N||void 0,F||void 0),k(``),j(`openai-compatible`),P(``),I(``),D(!1))},[d,O,A,N,F]),L=h.trim()?t.filter(e=>{let t=h.trim().toLowerCase();return e.id.toLowerCase().includes(t)||e.name.toLowerCase().includes(t)||e.family.toLowerCase().includes(t)}):t,ne=L.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)($,{variant:a===`catalog`?`default`:`outline`,size:`sm`,onClick:()=>o(`catalog`),children:[(0,J.jsx)(at,{className:`h-4 w-4 mr-1`}),`Catalog`]}),(0,J.jsxs)($,{variant:a===`saved`?`default`:`outline`,size:`sm`,onClick:()=>o(`saved`),children:[(0,J.jsx)(qe,{className:`h-4 w-4 mr-1`}),`Saved (`,r.length,`)`]})]}),a===`catalog`&&(0,J.jsxs)(`div`,{className:`space-y-4`,children:[(0,J.jsx)(gc,{placeholder:`Search ${t.length} providers (name / id / family)…`,value:h,onChange:e=>_(e.target.value),className:`text-sm`}),n&&t.length===0?(0,J.jsxs)(`div`,{className:`flex items-center justify-center py-8`,children:[(0,J.jsx)(z,{className:`h-6 w-6 animate-spin text-muted-foreground`}),(0,J.jsx)(`span`,{className:`ml-2 text-muted-foreground`,children:`Loading catalog...`})]}):L.length===0&&h?(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:h}),`".`]}):Nf.map(t=>{let n=ne[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:()=>s(t.id),className:X(`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)(qe,{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)(M,{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})]}),a===`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)($,{size:`sm`,variant:`outline`,onClick:()=>D(!E),children:[(0,J.jsx)(tr,{className:`h-4 w-4 mr-1`}),`Add Provider`]})]}),E&&(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)(gc,{placeholder:`Provider ID (e.g. my-llm-server)`,value:O,onChange:e=>k(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:A,onChange:e=>j(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)(gc,{placeholder:`Base URL (optional, e.g. http://localhost:11434/v1)`,value:N,onChange:e=>P(e.target.value)}),(0,J.jsx)(gc,{type:`password`,placeholder:`API Key (optional)`,value:F,onChange:e=>I(e.target.value)}),(0,J.jsxs)(`div`,{className:`flex gap-2`,children:[(0,J.jsx)($,{size:`sm`,onClick:te,disabled:!O.trim(),children:`Add`}),(0,J.jsx)($,{size:`sm`,variant:`ghost`,onClick:()=>D(!1),children:`Cancel`})]})]}),i?(0,J.jsx)(`div`,{className:`flex items-center justify-center py-8`,children:(0,J.jsx)(z,{className:`h-6 w-6 animate-spin text-muted-foreground`})}):r.length===0?(0,J.jsxs)(`div`,{className:`text-center py-8 text-muted-foreground`,children:[(0,J.jsx)(qe,{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`})]}):r.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)($,{size:`icon`,variant:`ghost`,onClick:()=>f(e.id),children:(0,J.jsx)(Te,{className:`h-4 w-4 text-destructive`})})})]}),e.baseUrl&&(0,J.jsxs)(`div`,{className:`text-xs text-muted-foreground`,children:[(0,J.jsx)(at,{className:`h-3 w-3 inline mr-1`}),e.baseUrl]}),(0,J.jsx)(jf,{providerId:e.id,savedPickedModelId:e.pickedModelId,savedModels:e.models,ws:m,onPickModel:p}),(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)($,{size:`sm`,variant:`ghost`,onClick:()=>y(v===e.id?null:e.id),children:[(0,J.jsx)(tr,{className:`h-3 w-3 mr-1`}),`Add Key`]})]}),e.apiKeys.length===0&&!v&&(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)($,{size:`sm`,variant:`ghost`,onClick:()=>u(e.id,t.label),children:`Set Active`}),(0,J.jsx)($,{size:`icon`,variant:`ghost`,onClick:()=>l(e.id,t.label),children:(0,J.jsx)(Te,{className:`h-3 w-3 text-destructive`})})]})]},t.label)),v===e.id&&(0,J.jsxs)(`div`,{className:`p-3 border rounded space-y-2 bg-background`,children:[(0,J.jsx)(gc,{placeholder:`Key label (e.g. default, production)`,value:b,onChange:e=>x(e.target.value)}),(0,J.jsxs)(`div`,{className:`flex gap-2`,children:[(0,J.jsx)(gc,{type:w?`text`:`password`,placeholder:`API key`,value:S,onChange:e=>C(e.target.value)}),(0,J.jsx)($,{size:`icon`,variant:`ghost`,onClick:()=>T(!w),children:w?(0,J.jsx)(g,{className:`h-4 w-4`}):(0,J.jsx)(Be,{className:`h-4 w-4`})})]}),(0,J.jsxs)(`div`,{className:`flex gap-2`,children:[(0,J.jsx)($,{size:`sm`,onClick:()=>ee(e.id),disabled:!b.trim()||!S.trim(),children:`Save Key`}),(0,J.jsx)($,{size:`sm`,variant:`ghost`,onClick:()=>{y(null),x(``),C(``)},children:`Cancel`})]})]})]})]},e.id))]})]})}function Ff(){let{setCurrentView:e}=q(),{provider:t,model:n,setProvider:r,setModel:i,setConfig:a,wsConnected:o,wsUrl:s}=G(),{theme:c,setTheme:l}=Ps(),u=Q(),d=u.client,{updatePrefs:f,switchAutonomy:p}=u,m=Ji(),h=Kc(!0),g=(0,H.useCallback)((e,t)=>{m.set({[e]:t}),f({[e]:t})},[m,f]),[_,v]=(0,H.useState)([]),[y,b]=(0,H.useState)({}),[x,S]=(0,H.useState)([]),[C,w]=(0,H.useState)(!1),[T,E]=(0,H.useState)(!1),[O,k]=(0,H.useState)(!1),[A,j]=(0,H.useState)(`catalog`),[M,N]=(0,H.useState)(``),[P,F]=(0,H.useState)(``),[I,ee]=(0,H.useState)(`*`),[te,L]=(0,H.useState)(``),ne=_.find(e=>e.id===t);(0,H.useEffect)(()=>{let e=e=>{if(e.type===`provider.catalog`){let t=e.payload;v(t.providers.sort((e,t)=>e.id.localeCompare(t.id))),w(!1)}},t=e=>{if(e.type===`provider.models`){let t=e.payload;b(e=>({...e,[t.provider]:t.models})),E(!1)}},n=e=>{if(e.type===`providers.saved`){let t=e.payload.providers.sort((e,t)=>e.id.localeCompare(t.id));S(t),k(!1),t.length>0&&j(`saved`)}};if(!o||!d)return;let r=d.on(`provider.catalog`,e),i=d.on(`provider.models`,t),a=d.on(`providers.saved`,n);return w(!0),k(!0),d.listProviders(),d.listSavedProviders(),()=>{r?.(),i?.(),a?.()}},[o,d]);let re=(0,H.useCallback)(e=>{r(e),y[e]||(E(!0),u.listProviderModels?.(e))},[y,r,u]),ie=(0,H.useCallback)(e=>{i(e);let t=G.getState().provider;u.switchModel?.(t,e),Z.success(`Switching to ${t} / ${e}…`)},[i,u]),ae=(0,H.useCallback)((e,t,n)=>{u.addKey?.(e,t,n)},[u]),oe=(0,H.useCallback)((e,t)=>{u.deleteKey?.(e,t)},[u]),ce=(0,H.useCallback)((e,t)=>{u.setActiveKey?.(e,t)},[u]),le=(0,H.useCallback)((e,t,n,r)=>{u.addProvider?.(e,t,n,r)},[u]),ue=(0,H.useCallback)(e=>{u.removeProvider?.(e)},[u]),de=(0,H.useCallback)((e,t)=>{u.client.updateProvider({id:e,models:[t]}),e===G.getState().provider&&i(t)},[i,u.client]),R=(0,H.useCallback)(e=>g(`fallbackProfiles`,e),[g]),fe=(0,H.useCallback)(()=>{let e=P.trim();if(e){if(m.fallbackProfiles[e]){Z.error(`Fallback profile "${e}" already exists`);return}R({...m.fallbackProfiles,[e]:[]}),F(``)}},[m.fallbackProfiles,P,R]),pe=(0,H.useCallback)(()=>{let e=t&&n?`${t}/${n}`:``;if(!e){Z.error(`Select a provider and model first`);return}let r=[e,...m.fallbackModels].filter((e,t,n)=>e&&n.indexOf(e)===t);R({...m.fallbackProfiles,default:r}),Z.success(`Default fallback profile created`)},[n,m.fallbackModels,m.fallbackProfiles,t,R]);(0,H.useEffect)(()=>{if(Object.keys(m.fallbackProfiles).length>0)return;let e=t&&n?`${t}/${n}`:``;e&&R({default:[e,...m.fallbackModels].filter((e,t,n)=>e&&n.indexOf(e)===t)})},[n,m.fallbackModels,m.fallbackProfiles,t,R]);let me=(0,H.useCallback)((e,t)=>{R({...m.fallbackProfiles,[e]:t})},[m.fallbackProfiles,R]),he=(0,H.useCallback)(e=>{let{[e]:t,...n}=m.fallbackProfiles;R(n)},[m.fallbackProfiles,R]),ge=(0,H.useCallback)(e=>{g(`fallbackModels`,m.fallbackProfiles[e]??[])},[m.fallbackProfiles,g]),ve=(0,H.useCallback)(e=>{let n=m.fallbackProfiles[e]??[],a=n[0];if(!a){Z.error(`Fallback profile "${e}" is empty`);return}let o=a.indexOf(`/`),s=o>0?a.slice(0,o):t,c=o>0?a.slice(o+1):a;r(s),i(c),u.switchModel?.(s,c),g(`fallbackModels`,n.slice(1)),Z.success(`Leader set from ${e}`)},[m.fallbackProfiles,t,i,r,g,u]),ye=(0,H.useCallback)(e=>g(`modelMatrix`,e),[g]),z=(0,H.useCallback)(()=>{let e=I.trim(),t=te.trim();if(!e||!t)return;let n=m.fallbackProfiles[t]?{fallbackProfile:t}:t.includes(`/`)?{provider:t.slice(0,t.indexOf(`/`)),model:t.slice(t.indexOf(`/`)+1)}:{model:t};ye({...m.modelMatrix,[e]:n}),L(``)},[m.fallbackProfiles,m.modelMatrix,I,te,ye]),be=(0,H.useCallback)(e=>{let{[e]:t,...n}=m.modelMatrix;ye(n)},[m.modelMatrix,ye]),xe=e=>e.fallbackProfile&&!e.model?`profile:${e.fallbackProfile}`:[e.provider&&e.model?`${e.provider}/${e.model}`:e.model,e.fallbackProfile?`profile:${e.fallbackProfile}`:``].filter(Boolean).join(` + `);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)($,{variant:`ghost`,size:`icon`,onClick:()=>e(`chat`),children:(0,J.jsx)(B,{className:`h-4 w-4`})})]}),(0,J.jsx)(Qd,{className:`flex-1`,children:(0,J.jsx)(`div`,{className:`p-6 max-w-2xl mx-auto`,children:(0,J.jsxs)(ef,{defaultValue:`provider`,children:[(0,J.jsxs)(tf,{className:`w-full justify-start mb-6 grid grid-cols-6`,children:[(0,J.jsxs)(nf,{value:`provider`,className:`gap-1 text-xs`,children:[(0,J.jsx)(Ar,{className:`h-3.5 w-3.5`}),`Provider`]}),(0,J.jsxs)(nf,{value:`connection`,className:`gap-1 text-xs`,children:[(0,J.jsx)(at,{className:`h-3.5 w-3.5`}),`Connect`]}),(0,J.jsxs)(nf,{value:`appearance`,className:`gap-1 text-xs`,children:[(0,J.jsx)(vt,{className:`h-3.5 w-3.5`}),`Look`]}),(0,J.jsxs)(nf,{value:`agent`,className:`gap-1 text-xs`,children:[(0,J.jsx)(Yn,{className:`h-3.5 w-3.5`}),`Agent`]}),(0,J.jsxs)(nf,{value:`features`,className:`gap-1 text-xs`,children:[(0,J.jsx)(In,{className:`h-3.5 w-3.5`}),`Feat.`]}),(0,J.jsxs)(nf,{value:`mcp`,className:`gap-1 text-xs`,children:[(0,J.jsx)(se,{className:`h-3.5 w-3.5`}),`MCP`]})]}),(0,J.jsxs)(rf,{value:`provider`,className:`space-y-4`,children:[(0,J.jsx)(Pf,{activeProvider:t,catalogProviders:_,isLoadingCatalog:C,savedProviders:x,isLoadingSaved:O,providerTab:A,setProviderTab:j,onSelectProvider:re,onAddKey:ae,onDeleteKey:oe,onSetActiveKey:ce,onAddProvider:le,onRemoveProvider:ue,onPickProviderModel:de,ws:u.client,catalogQuery:M,setCatalogQuery:N}),(0,J.jsxs)(`div`,{className:`pt-4 border-t`,children:[(0,J.jsxs)(`h3`,{className:`text-sm font-semibold mb-3 flex items-center gap-2`,children:[(0,J.jsx)(_e,{className:`h-4 w-4 text-muted-foreground`}),`Model`]}),(0,J.jsx)(hf,{provider:t,catalogModels:y,currentCatalogProvider:ne,isLoadingModels:T,setIsLoadingModels:E,onModelSelect:ie,refreshModels:e=>u.listProviderModels?.(e)})]})]}),(0,J.jsxs)(rf,{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)(at,{className:`h-4 w-4 text-muted-foreground`}),`WebSocket Server URL`]}),(0,J.jsx)(gc,{id:`websocket-url`,value:s,onChange:e=>a({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:`wstackui`}),`. Or alongside the CLI:`,` `,(0,J.jsx)(`code`,{className:`bg-muted px-1 py-0.5 rounded`,children:`wstack --webui`}),`.`]})]})]}),(0,J.jsxs)(rf,{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)($,{variant:c===`light`?`default`:`outline`,size:`sm`,onClick:()=>l(`light`),children:[(0,J.jsx)(ke,{className:`h-4 w-4 mr-1`}),`Light`]}),(0,J.jsxs)($,{variant:c===`dark`?`default`:`outline`,size:`sm`,onClick:()=>l(`dark`),children:[(0,J.jsx)(Tr,{className:`h-4 w-4 mr-1`}),`Dark`]}),(0,J.jsxs)($,{variant:c===`system`?`default`:`outline`,size:`sm`,onClick:()=>l(`system`),children:[(0,J.jsx)(ze,{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)(vf,{label:`Compact density`,hint:`Tighter spacing throughout the chat.`,selector:e=>e.compactMode,onChange:()=>q.getState().toggleCompactMode()}),(0,J.jsx)(vf,{label:`Sound on completion`,hint:`Play a soft chime when a run finishes.`,selector:null,configKey:`soundOnComplete`}),(0,J.jsx)(vf,{label:`Title animation`,hint:`Show animated terminal title in the CLI.`,value:m.titleAnimation,onChange:()=>g(`titleAnimation`,!m.titleAnimation)})]})]}),(0,J.jsxs)(rf,{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)(_t,{className:`h-4 w-4 text-muted-foreground`}),`Autonomy & Behavior`]}),(0,J.jsx)(_f,{label:`Autonomy mode`,hint:`How independently the agent proceeds between turns.`,value:m.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=>{m.set({autonomy:e}),p(e)}}),(0,J.jsx)(gf,{label:`Auto-proceed delay`,hint:`Milliseconds before the agent auto-proceeds in Auto mode. 0 = immediate.`,value:m.autonomyDelayMs,min:0,max:1e4,step:500,unit:`ms`,onChange:e=>g(`autonomyDelayMs`,e)}),(0,J.jsx)(vf,{label:`YOLO mode`,hint:`Bypass tool confirmation prompts — the agent runs without asking.`,value:m.yolo,onChange:()=>g(`yolo`,!m.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)(Bt,{className:`h-4 w-4 text-muted-foreground`}),`Prompt Refinement`]}),(0,J.jsx)(vf,{label:`Enable refine`,hint:`Rewrite prompts before sending — clearer instructions, better results.`,value:m.enhanceEnabled,onChange:()=>g(`enhanceEnabled`,!m.enhanceEnabled)}),(0,J.jsx)(gf,{label:`Refine delay`,hint:`Countdown before the refined prompt auto-sends.`,value:m.enhanceDelayMs,min:3e4,max:12e4,step:15e3,unit:`ms`,onChange:e=>g(`enhanceDelayMs`,e)}),(0,J.jsx)(_f,{label:`Refine language`,hint:`Keep your language or translate to English for the model.`,value:m.enhanceLanguage,options:[{value:`original`,label:`Original — keep your language`},{value:`english`,label:`English — translate to English`}],onChange:e=>g(`enhanceLanguage`,e)})]}),(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)(_e,{className:`h-4 w-4 text-muted-foreground`}),`Reasoning & Cache`]}),(0,J.jsx)(_f,{label:`Reasoning mode`,hint:`Control how the model uses extended thinking. Auto = provider default.`,value:m.reasoningMode,options:[{value:`auto`,label:`Auto — provider default`},{value:`on`,label:`On — force thinking on`},{value:`off`,label:`Off — force thinking off`}],onChange:e=>g(`reasoningMode`,e)}),(0,J.jsx)(_f,{label:`Reasoning effort`,hint:`How much compute the model spends thinking. Only sent when the model supports it.`,value:m.reasoningEffort,options:[{value:`none`,label:`None`},{value:`minimal`,label:`Minimal`},{value:`low`,label:`Low`},{value:`medium`,label:`Medium`},{value:`high`,label:`High`},{value:`xhigh`,label:`Extra High`},{value:`max`,label:`Max`}],onChange:e=>g(`reasoningEffort`,e)}),(0,J.jsx)(vf,{label:`Preserve thinking`,hint:`Keep reasoning blocks across turns for context continuity.`,value:m.reasoningPreserve,onChange:()=>g(`reasoningPreserve`,!m.reasoningPreserve)}),(0,J.jsx)(_f,{label:`Cache TTL`,hint:`Prompt cache time-to-live. 1h costs more on write but saves on repeat reads (Anthropic).`,value:m.cacheTtl,options:[{value:`default`,label:`Default — provider default`},{value:`5m`,label:`5 minutes`},{value:`1h`,label:`1 hour`}],onChange:e=>g(`cacheTtl`,e)}),(0,J.jsxs)(`p`,{className:`text-xs text-muted-foreground mt-2`,children:[`Use `,(0,J.jsx)(`code`,{className:`bg-muted px-1 py-0.5 rounded`,children:`wstack models caps`}),` to check what the current model supports. Unsupported settings are silently omitted per-request.`]})]}),(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)(_e,{className:`h-4 w-4 text-muted-foreground`}),`Model Fallbacks`]}),(0,J.jsx)(`p`,{className:`mb-2 text-xs text-muted-foreground`,children:`When the active model rate-limits (429/529), 5xx-errors, or stalls — after its own retries — the agent rotates to the next model in this chain. Also used as the default for SDD worker subagents.`}),(0,J.jsx)(Dl,{value:m.fallbackModels,candidates:h,onChange:e=>g(`fallbackModels`,e)}),(0,J.jsxs)(`div`,{className:`pt-1`,children:[(0,J.jsx)(vf,{label:`Auto fallback`,hint:`When the chain above is empty, auto-derive one from your keyed providers.`,value:m.fallbackAuto,onChange:()=>g(`fallbackAuto`,!m.fallbackAuto)}),(0,J.jsx)(vf,{label:`Favorites only`,hint:`When auto fallback derives a chain, restrict it to your favorite models.`,value:m.favoriteModelsOnly,onChange:()=>g(`favoriteModelsOnly`,!m.favoriteModelsOnly)})]})]}),(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)(D,{className:`h-4 w-4 text-muted-foreground`}),`Fallback Profiles`]}),(0,J.jsxs)(`div`,{className:`flex gap-2`,children:[(0,J.jsx)(gc,{value:P,onChange:e=>F(e.target.value),placeholder:`fallback1`,className:`font-mono text-sm`,onKeyDown:e=>{e.key===`Enter`&&fe()}}),(0,J.jsx)($,{type:`button`,variant:`outline`,onClick:fe,children:`Add`})]}),(0,J.jsx)(`div`,{className:`mt-3 space-y-3`,children:Object.keys(m.fallbackProfiles).length===0?(0,J.jsxs)(`div`,{className:`rounded-md border border-dashed border-border p-3`,children:[(0,J.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`No named fallback profiles yet.`}),(0,J.jsx)($,{type:`button`,variant:`outline`,size:`sm`,className:`mt-2`,onClick:pe,children:`Create default from active model`})]}):Object.entries(m.fallbackProfiles).sort(([e],[t])=>e.localeCompare(t)).map(([e,t])=>(0,J.jsxs)(`div`,{className:`rounded-md border border-border p-3`,children:[(0,J.jsxs)(`div`,{className:`mb-2 flex items-center justify-between gap-2`,children:[(0,J.jsx)(`span`,{className:`font-mono text-sm font-medium`,children:e}),(0,J.jsxs)(`div`,{className:`flex gap-1`,children:[(0,J.jsx)($,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>ge(e),children:`Use chain`}),(0,J.jsx)($,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>ve(e),children:`Set leader`}),(0,J.jsx)($,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>he(e),children:`Remove`})]})]}),(0,J.jsx)(Dl,{value:t,candidates:h,placeholder:`Add model to profile…`,emptyHint:`Profile is empty.`,onChange:t=>me(e,t)})]},e))})]}),(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)(_e,{className:`h-4 w-4 text-muted-foreground`}),`Favorite Models`]}),(0,J.jsx)(Dl,{value:m.favoriteModels,candidates:h,placeholder:`Add favorite model…`,emptyHint:`Favorites are shown first and can constrain auto fallback.`,onChange:e=>g(`favoriteModels`,e)})]}),(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)(Ze,{className:`h-4 w-4 text-muted-foreground`}),`Model Routing`]}),(0,J.jsxs)(`div`,{className:`grid grid-cols-[120px_1fr_auto] gap-2`,children:[(0,J.jsx)(gc,{value:I,onChange:e=>ee(e.target.value),placeholder:`*`,className:`font-mono text-sm`}),(0,J.jsx)(gc,{value:te,onChange:e=>L(e.target.value),onKeyDown:e=>{e.key===`Enter`&&z()},placeholder:`fallback1 or provider/model`,className:`font-mono text-sm`}),(0,J.jsx)($,{type:`button`,variant:`outline`,onClick:z,children:`Set`})]}),(0,J.jsx)(`div`,{className:`mt-3 space-y-1.5`,children:Object.keys(m.modelMatrix).length===0?(0,J.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`No model routes yet.`}):Object.entries(m.modelMatrix).sort(([e],[t])=>e.localeCompare(t)).map(([e,t])=>(0,J.jsxs)(`div`,{className:`flex items-center gap-2 rounded-md border border-border bg-muted px-2 py-1.5 text-xs`,children:[(0,J.jsx)(`span`,{className:`w-28 shrink-0 font-mono text-muted-foreground`,children:e}),(0,J.jsx)(`span`,{className:`min-w-0 flex-1 truncate font-mono`,children:xe(t)}),(0,J.jsx)($,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>be(e),children:`Remove`})]},e))})]}),(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)(Ar,{className:`h-4 w-4 text-muted-foreground`}),`HQ Client`]}),(0,J.jsx)(vf,{label:`HQ publishing`,hint:`Publish this WebUI/client session to WrongStack HQ. Same-machine clients can auto-discover local HQ auth; remote clients use the URL/token below.`,value:m.hqEnabled,onChange:()=>g(`hqEnabled`,!m.hqEnabled)}),(0,J.jsxs)(`div`,{className:`space-y-1 py-2`,children:[(0,J.jsx)(`label`,{className:`text-sm font-medium`,children:`HQ URL`}),(0,J.jsx)(gc,{value:m.hqUrl,placeholder:`http://host:3499`,onChange:e=>g(`hqUrl`,e.target.value)}),(0,J.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Leave empty for same-machine auto-discovery.`})]}),(0,J.jsxs)(`div`,{className:`space-y-1 py-2`,children:[(0,J.jsx)(`label`,{className:`text-sm font-medium`,children:`HQ client token`}),(0,J.jsx)(gc,{type:`password`,value:m.hqToken,placeholder:`Client token from wstack --hq`,onChange:e=>g(`hqToken`,e.target.value)})]}),(0,J.jsx)(vf,{label:`Raw HQ content`,hint:`Send raw content previews to HQ instead of redacted previews.`,value:m.hqRawContent,onChange:()=>g(`hqRawContent`,!m.hqRawContent)})]}),(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)(Bt,{className:`h-4 w-4 text-muted-foreground`}),`Execution`]}),(0,J.jsx)(gf,{label:`Max iterations per run`,hint:`Hard cap on LLM turns per agent.run().`,value:m.maxIterations,min:10,max:2e3,step:10,onChange:e=>g(`maxIterations`,e)}),(0,J.jsx)(gf,{label:`Auto-proceed max iterations`,hint:`Stop auto-proceed after N iterations. 0 = unlimited.`,value:m.autoProceedMaxIterations,min:0,max:250,step:5,onChange:e=>g(`autoProceedMaxIterations`,e)}),(0,J.jsx)(vf,{label:`Confirm before exit`,hint:`First Ctrl+C aborts work, second confirms exit.`,value:m.confirmExit,onChange:()=>g(`confirmExit`,!m.confirmExit)}),(0,J.jsx)(vf,{label:`Chime on completion`,hint:`Terminal bell when an agent run finishes.`,value:m.chime,onChange:()=>g(`chime`,!m.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)(Ze,{className:`h-4 w-4 text-muted-foreground`}),`Fleet & Streaming`]}),(0,J.jsx)(vf,{label:`Stream fleet events`,hint:`Show live subagent activity in the fleet panel.`,value:m.streamFleet,onChange:()=>g(`streamFleet`,!m.streamFleet)}),(0,J.jsx)(gf,{label:`Max concurrent subagents`,hint:`Maximum number of subagents that can run simultaneously.`,value:m.maxConcurrent,min:1,max:50,step:1,onChange:e=>g(`maxConcurrent`,e)}),(0,J.jsx)(vf,{label:`Next-step prediction`,hint:`After a turn completes, predict likely next steps.`,value:m.nextPrediction,onChange:()=>g(`nextPrediction`,!m.nextPrediction)})]}),(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)(dt,{className:`h-4 w-4 text-muted-foreground`}),`Telegram Notifications`]}),m.tgConfigured?(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(vf,{label:`Session end`,hint:`Send a summary when a session ends.`,value:m.tgSessionEnd,onChange:()=>g(`tgSessionEnd`,!m.tgSessionEnd)}),(0,J.jsx)(vf,{label:`Delegate finished`,hint:`Send a humanized note when a subagent completes.`,value:m.tgDelegate,onChange:()=>g(`tgDelegate`,!m.tgDelegate)}),(0,J.jsx)(vf,{label:`Long-running tools`,hint:`Notify when a tool exceeds ${m.tgLongToolMs}ms. Set 0 to disable.`,value:m.tgLongToolMs>0,onChange:()=>g(`tgLongToolMs`,m.tgLongToolMs>0?0:3e4)}),(0,J.jsx)(`p`,{className:`text-xs text-muted-foreground mt-2`,children:`Changes apply immediately.`})]}):(0,J.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[`Telegram is not configured. Run`,` `,(0,J.jsx)(`code`,{className:`bg-muted px-1 py-0.5 rounded`,children:`/telegram-setup`}),` in the CLI to connect a bot first.`]})]})]}),(0,J.jsxs)(rf,{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)(In,{className:`h-4 w-4 text-muted-foreground`}),`Feature Flags`]}),(0,J.jsx)(vf,{label:`MCP servers`,hint:`Enable Model Context Protocol integrations.`,value:m.featureMcp,onChange:()=>g(`featureMcp`,!m.featureMcp)}),(0,J.jsx)(vf,{label:`Plugins`,hint:`Load and run user-installed plugins.`,value:m.featurePlugins,onChange:()=>g(`featurePlugins`,!m.featurePlugins)}),(0,J.jsx)(vf,{label:`Memory`,hint:`Persist and recall facts across sessions.`,value:m.featureMemory,onChange:()=>g(`featureMemory`,!m.featureMemory)}),(0,J.jsx)(vf,{label:`Skills`,hint:`Load domain-specific skill prompts.`,value:m.featureSkills,onChange:()=>g(`featureSkills`,!m.featureSkills)}),(0,J.jsx)(vf,{label:`Models registry`,hint:`Use the models.dev catalog for provider discovery.`,value:m.featureModelsRegistry,onChange:()=>g(`featureModelsRegistry`,!m.featureModelsRegistry)}),(0,J.jsx)(vf,{label:`Index on start`,hint:`Build the codebase symbol index at session start.`,value:m.indexOnStart,onChange:()=>g(`indexOnStart`,!m.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)(Ye,{className:`h-4 w-4 text-muted-foreground`}),`Context & Debug`]}),(0,J.jsx)(vf,{label:`Auto-compact context`,hint:`Automatically trim the context window when near limits.`,value:m.contextAutoCompact,onChange:()=>g(`contextAutoCompact`,!m.contextAutoCompact)}),(0,J.jsx)(_f,{label:`Compactor strategy`,hint:`How the context is compacted when it grows too large.`,value:m.contextStrategy,options:[{value:`hybrid`,label:`Hybrid — fast rules (default)`},{value:`intelligent`,label:`Intelligent — LLM summarization`},{value:`selective`,label:`Selective — LLM-driven selection`}],onChange:e=>g(`contextStrategy`,e)}),(0,J.jsx)(_f,{label:`Context mode`,hint:`Context window policy — balanced is the default.`,value:m.contextMode,options:[{value:`balanced`,label:`Balanced — normal context usage`},{value:`frugal`,label:`Frugal — conservative token use`},{value:`deep`,label:`Deep — larger context for complex tasks`},{value:`archival`,label:`Archival — maximize context retention`}],onChange:e=>g(`contextMode`,e)}),(0,J.jsx)(_f,{label:`Token-saving mode`,hint:`How aggressively to reduce token usage.`,value:m.tokenSavingTier,options:[{value:`off`,label:`Off — no token saving`},{value:`minimal`,label:`Minimal — basic optimization`},{value:`light`,label:`Light — moderate reduction`},{value:`medium`,label:`Medium — significant savings`},{value:`aggressive`,label:`Aggressive — maximum compression`}],onChange:e=>g(`tokenSavingTier`,e)}),(0,J.jsx)(_f,{label:`Log level`,hint:`Minimum severity for server-side logging.`,value:m.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=>g(`logLevel`,e)}),(0,J.jsx)(_f,{label:`Audit level`,hint:`Detail level for session audit logs.`,value:m.auditLevel,options:[{value:`minimal`,label:`Minimal — errors only`},{value:`standard`,label:`Standard — tool calls + errors`},{value:`full`,label:`Full — every event (large logs)`}],onChange:e=>g(`auditLevel`,e)})]})]}),(0,J.jsx)(rf,{value:`mcp`,className:`space-y-4`,children:m.featureMcp?(0,J.jsx)(mf,{}):(0,J.jsxs)(`div`,{className:`text-center py-8 text-muted-foreground`,children:[(0,J.jsx)(se,{className:`w-10 h-10 mx-auto mb-2 opacity-50`}),(0,J.jsx)(`p`,{children:`MCP servers are disabled.`}),(0,J.jsx)(`p`,{className:`text-sm mt-1`,children:`Enable the "MCP servers" feature flag in the Features tab to use this section.`})]})})]})})})]})}function If({provider:e,isSelected:t,onSelect:n}){return(0,J.jsx)(`button`,{type:`button`,onClick:n,className:X(`w-full text-left rounded-xl border p-4 transition-all`,`hover:border-primary/40 hover:bg-primary/5`,t?`border-primary bg-primary/10 ring-1 ring-primary/30`:`border-border bg-card`),children:(0,J.jsxs)(`div`,{className:`flex items-start justify-between gap-3`,children:[(0,J.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,J.jsx)(`span`,{className:`font-semibold text-sm`,children:e.name}),e.hasApiKey&&(0,J.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-[10px] px-1.5 py-0.5 rounded-full bg-emerald-500/10 text-emerald-600 dark:text-emerald-400 border border-emerald-500/20`,children:[(0,J.jsx)(i,{className:`h-2.5 w-2.5`}),`Key set`]})]}),(0,J.jsxs)(`p`,{className:`text-xs text-muted-foreground mt-0.5`,children:[e.family,` · `,e.modelCount,` models`]})]}),t&&(0,J.jsx)(`div`,{className:`w-5 h-5 rounded-full bg-primary flex items-center justify-center shrink-0`,children:(0,J.jsx)(i,{className:`h-3 h-3 text-primary-foreground`})})]})})}function Lf({model:e,isSelected:t,onSelect:n}){let r=e.inputCost==null?null:`$${e.inputCost}/1M tok`,a=e.outputCost==null?null:`$${e.outputCost}/1M tok`,o=e.contextWindow?`${(e.contextWindow/1e6).toFixed(0)}M ctx`:null;return(0,J.jsx)(`button`,{type:`button`,onClick:n,className:X(`w-full text-left rounded-xl border p-3 transition-all`,`hover:border-primary/40 hover:bg-primary/5`,t?`border-primary bg-primary/10 ring-1 ring-primary/30`:`border-border bg-card`),children:(0,J.jsxs)(`div`,{className:`flex items-start justify-between gap-2`,children:[(0,J.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,J.jsx)(`span`,{className:`font-medium text-sm`,children:e.name}),(0,J.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5 mt-1`,children:[o&&(0,J.jsx)(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded bg-muted text-muted-foreground`,children:o}),r&&a&&(0,J.jsxs)(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded bg-muted text-muted-foreground`,children:[r,` · `,a]}),e.capabilities.slice(0,3).map(e=>(0,J.jsx)(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded bg-primary/10 text-primary border border-primary/20`,children:e},e))]})]}),t&&(0,J.jsx)(`div`,{className:`w-5 h-5 rounded-full bg-primary flex items-center justify-center shrink-0`,children:(0,J.jsx)(i,{className:`h-3 w-3 text-primary-foreground`})})]})})}function Rf({providerId:e,onSave:t}){let[n,r]=(0,H.useState)(``),[i,a]=(0,H.useState)(`default`),[o,s]=(0,H.useState)(!1);return(0,J.jsxs)(`div`,{className:`space-y-3 p-4 rounded-xl border border-amber-500/30 bg-amber-500/5`,children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-2 text-amber-600 dark:text-amber-400`,children:[(0,J.jsx)(tt,{className:`h-4 w-4`}),(0,J.jsx)(`span`,{className:`text-sm font-medium`,children:`API Key required`})]}),(0,J.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[`Enter your API key for `,e,`. The key is stored locally and never sent to any server other than the provider's API endpoint.`]}),(0,J.jsxs)(`div`,{className:`flex gap-2`,children:[(0,J.jsx)(gc,{type:`password`,placeholder:`sk-...`,value:n,onChange:e=>r(e.target.value),className:`font-mono text-sm`}),(0,J.jsx)(gc,{placeholder:`Label (optional)`,value:i,onChange:e=>a(e.target.value),className:`w-28 text-sm`})]}),(0,J.jsx)($,{onClick:async()=>{if(n.trim()){s(!0);try{U(G.getState().wsUrl).addKey(e,i.trim()||`default`,n.trim()),t(n.trim()),r(``),Z.success(`API key saved`)}catch{Z.error(`Failed to save API key`)}finally{s(!1)}}},disabled:!n.trim()||o,size:`sm`,children:o?(0,J.jsx)(z,{className:`h-4 w-4 animate-spin`}):`Save Key`})]})}function zf(){let{setCurrentView:e}=q(),{provider:t,model:n,setProvider:r,setModel:a,wsConnected:o,wsUrl:s}=G();Q();let[c,l]=(0,H.useState)(`provider`),[u,d]=(0,H.useState)([]),[f,p]=(0,H.useState)({}),[m,h]=(0,H.useState)([]),[g,_]=(0,H.useState)(!1),[v,y]=(0,H.useState)(!1),[b,x]=(0,H.useState)(null),[S,C]=(0,H.useState)(0),[w,T]=(0,H.useState)(null),[E,D]=(0,H.useState)(null);(0,H.useEffect)(()=>{if(!o)return;let e=U(s),r=setTimeout(()=>{r=null,_(!1),x(`The backend is not responding. It may have crashed or the connection dropped.`)},8e3),i=()=>{r&&=(clearTimeout(r),null)},a=e.on(`provider.catalog`,e=>{if(e.type===`provider.catalog`){i(),x(null);let n=e.payload.providers.sort((e,t)=>e.id.localeCompare(t.id));d(n),_(!1),t&&n.some(e=>e.id===t)?T(t):n.length===1&&T(n[0].id)}}),c=e.on(`provider.models`,e=>{if(e.type===`provider.models`){let t=e.payload;p(e=>({...e,[t.provider]:t.models})),y(!1),t.models.length===1?D(t.models[0].id):n&&t.models.some(e=>e.id===n)&&D(n)}}),l=e.on(`providers.saved`,e=>{if(e.type===`providers.saved`){let t=e.payload;h(t.providers.sort((e,t)=>e.id.localeCompare(t.id)))}});return x(null),_(!0),e.listProviders(),()=>{i(),a?.(),c?.(),l?.()}},[o,s,t,n,S]);let O=(0,H.useCallback)(()=>{x(null),C(e=>e+1)},[]);(0,H.useEffect)(()=>{if(!w||!o)return;let e=U(s);f[w]||(y(!0),e.listProviderModels(w))},[w,o,s,f]);let k=u.find(e=>e.id===w),A=m.find(e=>e.id===w)?.apiKeys.some(e=>e.isActive)||k?.hasApiKey,j=(0,H.useCallback)(e=>{T(e),D(null),l(`model`)},[]),M=(0,H.useCallback)(e=>{D(e),l(A?`done`:`apikey`)},[A]),N=(0,H.useCallback)(()=>{l(`done`)},[]),P=(0,H.useCallback)(()=>{if(!w||!E)return;r(w),a(E);let t=U(s);t.switchModel(w,E);let n=null,i=()=>{n&&clearTimeout(n)},o=t.on(`key.operation_result`,n=>{let r=n.payload;i(),o(),r.success?(t.newSession(),e(`chat`)):Z.error(r.message)});n=setTimeout(()=>{i(),o(),Z.error(`Model switch timed out. Please try again.`)},5e3)},[w,E,r,a,s,e]),F=w?f[w]??[]:[];return(0,J.jsxs)(`div`,{className:`flex flex-col h-full`,children:[(0,J.jsx)(`header`,{className:`flex items-center justify-between px-6 py-4 border-b bg-card shrink-0`,children:(0,J.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,J.jsx)(`div`,{className:`w-10 h-10 rounded-xl bg-gradient-to-br from-primary via-primary to-primary/60 flex items-center justify-center`,children:(0,J.jsx)(Bt,{className:`h-5 w-5 text-primary-foreground`})}),(0,J.jsxs)(`div`,{children:[(0,J.jsx)(`h1`,{className:`text-lg font-semibold`,children:`Welcome to WrongStack`}),(0,J.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Configure your AI provider to get started`})]})]})}),(0,J.jsx)(Qd,{className:`flex-1`,children:(0,J.jsxs)(`div`,{className:`p-6 max-w-2xl mx-auto space-y-8`,children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-2 text-sm`,children:[(0,J.jsxs)(`div`,{className:X(`flex items-center gap-1.5`,c===`provider`&&`text-primary font-medium`),children:[(0,J.jsx)(Ar,{className:`h-4 w-4`}),(0,J.jsx)(`span`,{children:`Provider`})]}),(0,J.jsx)(ot,{className:`h-4 w-4 text-muted-foreground`}),(0,J.jsxs)(`div`,{className:X(`flex items-center gap-1.5`,c===`model`&&`text-primary font-medium`),children:[(0,J.jsx)(_e,{className:`h-4 w-4`}),(0,J.jsx)(`span`,{children:`Model`})]}),(0,J.jsx)(ot,{className:`h-4 w-4 text-muted-foreground`}),(0,J.jsxs)(`div`,{className:X(`flex items-center gap-1.5`,(c===`apikey`||c===`done`)&&`text-primary font-medium`),children:[(0,J.jsx)(tt,{className:`h-4 w-4`}),(0,J.jsx)(`span`,{children:`API Key`})]})]}),c===`provider`&&(0,J.jsxs)(`div`,{className:`space-y-4`,children:[(0,J.jsxs)(`div`,{children:[(0,J.jsxs)(`h2`,{className:`text-base font-semibold flex items-center gap-2`,children:[(0,J.jsx)(Ar,{className:`h-4 w-4 text-primary`}),`Choose a Provider`]}),(0,J.jsx)(`p`,{className:`text-sm text-muted-foreground mt-1`,children:`Select the AI provider you want to use. You can add API keys in the next step.`})]}),b?(0,J.jsxs)(`div`,{className:`flex flex-col items-center text-center gap-4 py-12 rounded-xl border border-destructive/30 bg-destructive/5 px-6`,children:[(0,J.jsx)(`div`,{className:`w-12 h-12 rounded-xl bg-destructive/10 border border-destructive/30 flex items-center justify-center`,children:(0,J.jsx)(Ar,{className:`h-6 w-6 text-destructive`})}),(0,J.jsxs)(`div`,{children:[(0,J.jsx)(`p`,{className:`text-sm font-medium text-destructive`,children:`Can't reach the backend`}),(0,J.jsx)(`p`,{className:`text-xs text-muted-foreground mt-1 max-w-sm`,children:b})]}),(0,J.jsxs)($,{onClick:O,size:`sm`,variant:`outline`,children:[(0,J.jsx)(z,{className:`h-4 w-4 mr-2`}),`Retry`]})]}):g?(0,J.jsx)(`div`,{className:`flex items-center justify-center py-12`,children:(0,J.jsx)(z,{className:`h-6 w-6 animate-spin text-muted-foreground`})}):(0,J.jsx)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-3`,children:u.map(e=>(0,J.jsx)(If,{provider:e,isSelected:w===e.id,onSelect:()=>j(e.id)},e.id))})]}),c===`model`&&(0,J.jsxs)(`div`,{className:`space-y-4`,children:[(0,J.jsxs)(`div`,{children:[(0,J.jsxs)(`h2`,{className:`text-base font-semibold flex items-center gap-2`,children:[(0,J.jsx)(_e,{className:`h-4 w-4 text-primary`}),`Choose a Model`]}),(0,J.jsx)(`p`,{className:`text-sm text-muted-foreground mt-1`,children:k?`Models available for ${k.name}`:`Loading models...`})]}),(0,J.jsx)(`button`,{type:`button`,onClick:()=>l(`provider`),className:`text-xs text-muted-foreground hover:text-foreground transition-colors`,children:`← Change provider`}),v?(0,J.jsx)(`div`,{className:`flex items-center justify-center py-12`,children:(0,J.jsx)(z,{className:`h-6 w-6 animate-spin text-muted-foreground`})}):F.length>0?(0,J.jsx)(`div`,{className:`grid grid-cols-1 gap-2`,children:F.map(e=>(0,J.jsx)(Lf,{model:e,isSelected:E===e.id,onSelect:()=>M(e.id)},e.id))}):(0,J.jsx)(`p`,{className:`text-sm text-muted-foreground py-8 text-center`,children:`No models available. Please check your API key.`})]}),c===`apikey`&&(0,J.jsxs)(`div`,{className:`space-y-4`,children:[(0,J.jsxs)(`div`,{children:[(0,J.jsxs)(`h2`,{className:`text-base font-semibold flex items-center gap-2`,children:[(0,J.jsx)(tt,{className:`h-4 w-4 text-primary`}),`Add Your API Key`]}),(0,J.jsxs)(`p`,{className:`text-sm text-muted-foreground mt-1`,children:[k?`Enter your API key for ${k.name}. `:`Enter your API key. `,`The key is stored locally and encrypted.`]})]}),(0,J.jsx)(`button`,{type:`button`,onClick:()=>l(`model`),className:`text-xs text-muted-foreground hover:text-foreground transition-colors`,children:`← Change model`}),w&&(0,J.jsx)(Rf,{providerId:w,onSave:N})]}),c===`done`&&(0,J.jsxs)(`div`,{className:`space-y-6`,children:[(0,J.jsxs)(`div`,{className:`flex flex-col items-center text-center py-8`,children:[(0,J.jsx)(`div`,{className:`w-16 h-16 rounded-2xl bg-gradient-to-br from-emerald-500/20 to-emerald-500/5 border border-emerald-500/30 flex items-center justify-center mb-4`,children:(0,J.jsx)(i,{className:`h-8 w-8 text-emerald-500`})}),(0,J.jsx)(`h2`,{className:`text-xl font-semibold`,children:`You're all set!`}),(0,J.jsx)(`p`,{className:`text-sm text-muted-foreground mt-2 max-w-sm`,children:`Configuration complete. Your agent is ready to start working.`})]}),(0,J.jsxs)(`div`,{className:`rounded-xl border bg-card p-4 space-y-3`,children:[(0,J.jsxs)(`div`,{className:`flex items-center justify-between text-sm`,children:[(0,J.jsx)(`span`,{className:`text-muted-foreground`,children:`Provider`}),(0,J.jsx)(`span`,{className:`font-medium`,children:w})]}),(0,J.jsxs)(`div`,{className:`flex items-center justify-between text-sm`,children:[(0,J.jsx)(`span`,{className:`text-muted-foreground`,children:`Model`}),(0,J.jsx)(`span`,{className:`font-medium`,children:E})]})]}),(0,J.jsxs)($,{onClick:P,className:`w-full`,size:`lg`,children:[(0,J.jsx)(Yn,{className:`h-4 w-4 mr-2`}),`Start Session`,(0,J.jsx)(ur,{className:`h-4 w-4 ml-2`})]})]})]})})]})}function Bf(e){switch(e){case`running`:return`▶`;case`streaming`:return`↻`;case`waiting_user`:return`⏳`;case`error`:return`✗`;case`idle`:return`■`;default:return`?`}}function Vf(e){switch(e){case`running`:return`text-emerald-400`;case`streaming`:return`text-cyan-400`;case`waiting_user`:return`text-amber-400`;case`error`:return`text-red-400`;default:return`text-slate-500`}}function Hf(e){switch(e){case`active`:return`text-emerald-400`;case`idle`:return`text-cyan-400`;case`closing`:return`text-amber-400`;default:return`text-slate-500`}}function Uf(e){let t=Date.now()-new Date(e).getTime(),n=Math.floor(t/6e4);if(n<1)return`<1m`;if(n<60)return`${n}m`;let r=Math.floor(n/60);return r<24?`${r}h ${n%60}m`:`${Math.floor(r/24)}d`}function Wf(e){let t=Date.now()-new Date(e).getTime(),n=Math.floor(t/1e3);if(n<10)return`just now`;if(n<60)return`${n}s ago`;let r=Math.floor(n/60);return r<60?`${r}m ago`:`${Math.floor(r/60)}h ago`}function Gf(){let[e,t]=(0,H.useState)([]),[n,r]=(0,H.useState)(!0),[i,a]=(0,H.useState)(null),o=(0,H.useCallback)(async()=>{try{let e=await fetch(`/api/sessions`);if(!e.ok){if(e.status===404){a(null),t([]);return}throw Error(`HTTP ${e.status}`)}t(await e.json()),a(null)}catch(e){a(e instanceof Error?e.message:String(e))}finally{r(!1)}},[]);return(0,H.useEffect)(()=>{o();let e=setInterval(o,5e3);return()=>clearInterval(e)},[o]),n?(0,J.jsxs)(`div`,{className:`flex items-center gap-2 p-4 text-slate-400`,children:[(0,J.jsx)(z,{className:`h-4 w-4 animate-spin`}),`Loading sessions...`]}):i?(0,J.jsxs)(`div`,{className:`p-4 text-slate-500 text-sm`,children:[`Session API unavailable — run `,(0,J.jsx)(`code`,{className:`text-cyan-400`,children:`wstack --webui`}),` with session tracking enabled.`]}):e.length===0?(0,J.jsx)(`div`,{className:`p-4 text-slate-500 text-sm`,children:`No live sessions. Open another wstack instance to see it here.`}):(0,J.jsxs)(`div`,{className:`p-4 space-y-3`,children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-2 mb-4`,children:[(0,J.jsxs)(`h2`,{className:`text-sm font-semibold text-slate-200 uppercase tracking-wider`,children:[`Live Sessions (`,e.length,`)`]}),(0,J.jsx)(`span`,{className:`text-xs text-slate-500`,children:`auto-refresh every 5s`})]}),e.map(e=>(0,J.jsxs)(`div`,{className:`rounded-lg border border-slate-700 bg-slate-800/50 p-3 space-y-2`,children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[(0,J.jsx)(`span`,{className:Hf(e.status),children:e.status===`active`?(0,J.jsx)(On,{className:`h-3.5 w-3.5 inline`}):e.status===`idle`?(0,J.jsx)(an,{className:`h-3.5 w-3.5 inline`}):null}),(0,J.jsx)(`span`,{className:`font-medium text-slate-200 text-sm`,children:e.projectName}),(0,J.jsxs)(`span`,{className:`text-slate-500 text-xs`,children:[`[`,e.projectSlug,`]`]}),e.gitBranch?(0,J.jsxs)(`span`,{className:`text-purple-400 text-xs flex items-center gap-1`,children:[(0,J.jsx)(nr,{className:`h-3 w-3`}),e.gitBranch]}):null,(0,J.jsxs)(`span`,{className:`text-slate-500 text-xs ml-auto flex items-center gap-1`,children:[(0,J.jsx)(Fr,{className:`h-3 w-3`}),Uf(e.startedAt)]}),(0,J.jsxs)(`span`,{className:`text-slate-600 text-xs`,children:[`PID `,e.pid]})]}),(0,J.jsxs)(`div`,{className:`text-slate-500 text-xs flex items-center gap-1`,children:[(0,J.jsx)(_e,{className:`h-3 w-3`}),e.workingDir]}),(0,J.jsxs)(`div`,{className:`space-y-1 mt-2`,children:[e.agents.slice(0,5).map(e=>(0,J.jsxs)(`div`,{className:`flex items-center gap-2 text-xs pl-2 border-l-2 border-slate-700`,children:[(0,J.jsx)(`span`,{className:Vf(e.status),children:Bf(e.status)}),(0,J.jsx)(`span`,{className:`text-slate-300 font-medium`,children:e.name}),e.currentTool?(0,J.jsxs)(`span`,{className:`text-slate-500`,children:[`[`,e.currentTool,`]`]}):null,(0,J.jsxs)(`span`,{className:`text-slate-600 ml-auto`,children:[e.iterations,` iter · `,e.toolCalls,` tools · `,Wf(e.lastActivityAt)]})]},e.id)),e.agents.length>5?(0,J.jsxs)(`div`,{className:`text-slate-600 text-xs pl-4`,children:[`... and `,e.agents.length-5,` more`]}):null,e.agents.length===0?(0,J.jsx)(`div`,{className:`text-slate-600 text-xs pl-4`,children:`No agents`}):null]})]},e.sessionId))]})}var Kf=[{section:`Global`,items:[{keys:[`Ctrl`,`K`],description:`Open command palette`},{keys:[`?`],description:`Show this shortcuts overlay`},{keys:[`Ctrl`,`\\`],description:`Toggle sidebar`},{keys:[`Ctrl`,`1-9`],description:`Open side panel (Session, Agents, History, Files, Changes, Projects, Mailbox, Skills, Office Map)`},{keys:[`Ctrl`,`/`],description:`Focus the message input`}]},{section:`TUI Panel Parity`,items:[{keys:[`F1`],description:`Project switcher`},{keys:[`F2`],description:`Fleet monitor overlay`},{keys:[`F3`],description:`Agents monitor overlay`},{keys:[`F4`],description:`Worktree monitor`},{keys:[`F5`],description:`Plan panel`},{keys:[`F6`],description:`Todos panel`},{keys:[`F7`],description:`Queue panel`},{keys:[`F8`],description:`Process monitor`},{keys:[`F9`],description:`Goal panel`},{keys:[`F10`],description:`Sessions dashboard`},{keys:[`F11`],description:`Coordinator office map`},{keys:[`F12`],description:`Dock chip picker`}]},{section:`Fleet & Agents`,items:[{keys:[`Ctrl`,`Shift`,`M`],description:`Open Fleet Monitor overlay`},{keys:[`Ctrl`,`Shift`,`A`],description:`Open Agents Monitor overlay`},{keys:[`↑`,`↓`],description:`Navigate agents in monitor`},{keys:[`Enter`],description:`Select focused agent`},{keys:[`Esc`],description:`Close active overlay`}]},{section:`Chat input`,items:[{keys:[`Enter`],description:`Send message`},{keys:[`Shift`,`Enter`],description:`Insert a newline`},{keys:[`↑`],description:`Recall previous prompt (in empty input)`},{keys:[`↓`],description:`Recall next prompt`},{keys:[`/`],description:`Open slash command popup`},{keys:[`Tab`],description:`Autocomplete highlighted command`},{keys:[`Esc`],description:`Dismiss popup / clear input`}]},{section:`Chat`,items:[{keys:[`Ctrl`,`F`],description:`Search within current chat`},{keys:[`Ctrl`,`L`],description:`Clear context (same as /clear)`},{keys:[`Ctrl`,`N`],description:`Start a new session (same as /new)`},{keys:[`Ctrl`,`E`],description:`Export chat as markdown`},{keys:[`Ctrl`,`M`],description:`Quick model switcher overlay`},{keys:[`Ctrl`,`Shift`,`D`],description:`Toggle compact UI density`},{keys:[`Esc`],description:`Abort the current run (when running)`}]},{section:`Chat navigation (when not typing)`,items:[{keys:[`j`],description:`Focus next message (alias: ↓)`},{keys:[`k`],description:`Focus previous message (alias: ↑)`},{keys:[`g`],description:`Jump to first message`},{keys:[`Shift`,`G`],description:`Jump to last message`},{keys:[`c`],description:`Copy focused message text`},{keys:[`Esc`],description:`Clear focused message`}]}];function qf(){let e=q(e=>e.shortcutsOpen),t=q(e=>e.setShortcutsOpen);return(0,H.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(!q.getState().shortcutsOpen);return}e.key===`Escape`&&q.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)(F,{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)(B,{className:`h-4 w-4`})})]}),(0,J.jsx)(`div`,{className:`overflow-y-auto px-5 py-4 space-y-6`,children:Kf.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}var Jf={ts:jr,tsx:jr,js:jr,jsx:jr,mjs:jr,cjs:jr,json:Er,lock:Dn,css:zt,scss:zt,less:zt,html:fr,htm:fr,svg:rn,xml:fr,md:zt,mdx:zt,txt:zt,yml:zt,yaml:zt,toml:_r,env:_r,gitignore:_r,editorconfig:_r,sh:jr,bash:jr,zsh:jr,fish:jr,ps1:jr,bat:jr,py:jr,pyi:jr,pyx:jr,rs:jr,go:jr,rb:jr,java:jr,c:jr,cpp:jr,h:jr,hpp:jr,sql:jr,graphql:jr,png:rn,jpg:rn,jpeg:rn,gif:rn,webp:rn,ico:rn};function Yf(e,t){if(t){let t=e.toLowerCase();return t===`.git`?`text-orange-500/80 dark:text-orange-400/80`:t===`node_modules`?`text-red-400/60 dark:text-red-500/60`:t===`src`||t===`lib`||t===`packages`?`text-amber-500/70 dark:text-amber-400/70`:t===`tests`||t===`test`||t===`__tests__`?`text-emerald-500/70 dark:text-emerald-400/70`:t===`dist`||t===`build`||t===`.next`?`text-muted-foreground/50`:`text-amber-500/70 dark:text-amber-400/70`}let n=e.split(`.`).pop()?.toLowerCase()??``;return/^(ts|tsx|js|jsx|mjs|cjs)$/.test(n)?`text-blue-500 dark:text-blue-400`:/^(json|lock)$/.test(n)?`text-amber-500 dark:text-amber-400`:/^(css|scss|less|sass)$/.test(n)?`text-teal-500 dark:text-teal-400`:/^(html|htm|xml|svg)$/.test(n)?`text-rose-500 dark:text-rose-400`:/^(md|mdx)$/.test(n)?`text-violet-500 dark:text-violet-400`:/^(yml|yaml|toml|env)$/.test(n)?`text-emerald-500 dark:text-emerald-400`:/^(sh|bash|zsh|fish|ps1|bat)$/.test(n)?`text-orange-400 dark:text-orange-300`:/^(py|pyi|pyx)$/.test(n)?`text-cyan-500 dark:text-cyan-400`:n===`rs`?`text-orange-500 dark:text-orange-400`:n===`go`?`text-sky-500 dark:text-sky-400`:n===`rb`?`text-red-400 dark:text-red-400`:/^(c|h|cpp|hpp|cc|hh)$/.test(n)?`text-slate-500 dark:text-slate-400`:/^(png|jpe?g|gif|webp|ico|svg)$/.test(n)?`text-purple-500 dark:text-purple-400`:/^(gitignore|editorconfig|prettierrc|eslintrc)$/.test(n)?`text-muted-foreground/60`:`text-muted-foreground`}function Xf(e){return Jf[e.split(`.`).pop()?.toLowerCase()??``]??Sn}function Zf({node:e,depth:t,selectedPath:n,forceExpand:r,onSelect:i,onOpen:a}){let[o,s]=(0,H.useState)(t<1),c=Yi(e=>e.activeFilePath),l=e.type===`file`&&e.path===c;if((0,H.useEffect)(()=>{r!==null&&s(r)},[r]),e.type===`directory`){let c=(e.children?.length??0)>0,l=o?wt:Mn,u=e.name===`.git`,d=Yf(e.name,!0);return(0,J.jsxs)(`div`,{children:[(0,J.jsxs)(`button`,{type:`button`,onClick:()=>s(e=>!e),className:X(`flex items-center gap-1 w-full text-left px-1 py-0.5 text-[11px] rounded`,`hover:bg-muted/60 transition-colors`),style:{paddingLeft:`${t*14+4}px`},children:[(0,J.jsx)(ot,{className:X(`h-3 w-3 shrink-0 text-muted-foreground transition-transform`,o&&`rotate-90`)}),u?(0,J.jsx)(Ln,{className:X(`h-3.5 w-3.5 shrink-0`,d)}):(0,J.jsx)(l,{className:X(`h-3.5 w-3.5 shrink-0`,d)}),(0,J.jsx)(`span`,{className:`truncate font-medium flex-1 min-w-0`,children:e.name})]}),o&&c&&(0,J.jsx)(`div`,{children:(e.children??[]).map(e=>(0,J.jsx)(Zf,{node:e,depth:t+1,selectedPath:n,forceExpand:r,onSelect:i,onOpen:a},e.path))}),o&&!c&&(0,J.jsx)(`div`,{className:`text-[10px] text-muted-foreground italic py-0.5`,style:{paddingLeft:`${(t+1)*14+4}px`},children:`empty`})]})}let u=Xf(e.name),d=Yf(e.name,!1),f=e.path===n;return(0,J.jsxs)(`button`,{type:`button`,onClick:()=>i(e.path),onDoubleClick:t=>{t.preventDefault(),a(e.path)},className:X(`flex items-center gap-1.5 w-full text-left px-1 py-0.5 text-[11px] rounded`,`hover:bg-muted/60 transition-colors`,l&&`bg-primary/10 text-primary`,f&&!l&&`bg-muted/70 ring-1 ring-inset ring-border`),style:{paddingLeft:`${t*14+4}px`},children:[(0,J.jsx)(`span`,{className:`w-3 shrink-0`}),` `,(0,J.jsx)(u,{className:X(`h-3.5 w-3.5 shrink-0`,d)}),(0,J.jsx)(`span`,{className:`truncate`,children:e.name})]})}function Qf(){let e=Yi(e=>e.tree),t=Yi(e=>e.treeLoading),n=Yi(e=>e.error),r=Yi(e=>e.openFiles),i=Yi(e=>e.activeFilePath),a=K(e=>e.cwd),o=K(e=>e.projectName),s=a?.includes(`\\`)?`\\`:`/`,c=(e,t=8,n=4)=>e.length<=t+n+2?e:`${e.slice(0,t)}…${e.slice(-n)}`,l=(()=>{if(!a||!o)return!0;let e=a.replace(/\\/g,`/`).split(`/`).filter(Boolean);return(e[e.length-1]??``)===o})(),u=(0,H.useMemo)(()=>{if(!a||!o)return[];let e=a.replace(/\\/g,`/`).split(`/`).filter(Boolean),t=-1;for(let n=e.length-1;n>=0;n--)if(e[n]===o){t=n;break}if(t===-1)return e.map((t,n)=>({label:t,path:`/`+e.slice(0,n+1).join(`/`),isLast:n===e.length-1}));let n=e.slice(t);return n.map((r,i)=>({label:r,path:`/`+e.slice(0,t+i+1).join(`/`),isLast:i===n.length-1}))},[a,o]),d=(0,H.useRef)(null);(0,H.useEffect)(()=>{let e=d.current;e&&u.length>1&&(e.scrollLeft=e.scrollWidth)},[u]);let f=(0,H.useCallback)(e=>{U().send({type:`working_dir.set`,payload:{path:e}})},[]),[p,m]=(0,H.useState)(null);(0,H.useEffect)(()=>{if(!p)return;let e=()=>m(null),t=t=>{t.key===`Escape`&&e()};return window.addEventListener(`click`,e),window.addEventListener(`keydown`,t),()=>{window.removeEventListener(`click`,e),window.removeEventListener(`keydown`,t)}},[p]);let h=(0,H.useCallback)((e,t)=>{e.preventDefault(),e.stopPropagation(),m({x:e.clientX,y:e.clientY,crumb:t})},[]),g=(0,H.useCallback)(e=>{navigator.clipboard.writeText(e),m(null)},[]),_=(0,H.useCallback)(()=>{if(!i)return;let e=i.replace(/\\/g,`/`).split(`/`).slice(0,-1).join(`/`)||`.`;U().send({type:`working_dir.set`,payload:{path:e}})},[i]),v=(0,H.useCallback)((e,t)=>{U().send({type:`shell.open`,payload:{path:e,target:t}}),m(null)},[]),y=(0,H.useCallback)(()=>{if(!a)return;let e=a.replace(/\\/g,`/`),t=e.split(`/`).slice(0,-1).join(`/`)||e;U().send({type:`working_dir.set`,payload:{path:t}})},[a]),[b,x]=(0,H.useState)(!1),S=(0,H.useRef)(null);(0,H.useEffect)(()=>(t?S.current=setTimeout(()=>x(!0),150):(S.current&&clearTimeout(S.current),x(!1)),()=>{S.current&&clearTimeout(S.current)}),[t]);let[C,w]=(0,H.useState)(null),[T,E]=(0,H.useState)(null),D=(0,H.useMemo)(()=>{let t=0,n=e=>{for(let r of e)r.type===`directory`&&t++,r.children&&n(r.children)};return n(e),t},[e]),O=(0,H.useMemo)(()=>{let t=0,n=0;for(let r of e)r.type===`directory`?n++:t++;return{files:t,dirs:n}},[e]),k={value:!1},A=(0,H.useCallback)(()=>{k.value=!0,E(!1),setTimeout(()=>{k.value=!1},400)},[]),j=(0,H.useCallback)(()=>{k.value=!0,E(!0),setTimeout(()=>{k.value=!1},400)},[]),M=(0,H.useCallback)(e=>{if(r.find(t=>t.path===e)){Yi.getState().setActiveFile(e);return}w(t=>t===e?null:e)},[r]),N=(0,H.useCallback)(e=>{window.dispatchEvent(new CustomEvent(`wrongstack:open-file`,{detail:{filePath:e}})),w(null)},[]);return(0,H.useEffect)(()=>{i&&w(null)},[i]),b?(0,J.jsx)(`div`,{className:`flex items-center justify-center h-full py-8`,children:(0,J.jsx)(z,{className:`h-5 w-5 animate-spin text-muted-foreground`})}):n?(0,J.jsxs)(`div`,{className:`p-3 text-[11px] text-destructive`,children:[`Failed to load files: `,n]}):(0,J.jsxs)(`div`,{className:`h-full flex flex-col overflow-hidden`,children:[e.length>0&&D>0&&(0,J.jsxs)(`div`,{className:`flex items-center gap-0.5 px-2 py-0.5 border-b shrink-0`,children:[(0,J.jsxs)(`button`,{type:`button`,onClick:j,className:X(`flex items-center gap-1 px-1.5 py-0.5 rounded text-[10px] transition-colors`,`hover:bg-muted/60 text-muted-foreground hover:text-foreground`),title:`Expand all directories`,children:[(0,J.jsx)(sr,{className:`h-3 w-3`}),(0,J.jsx)(`span`,{children:`Expand all`})]}),(0,J.jsxs)(`button`,{type:`button`,onClick:A,className:X(`flex items-center gap-1 px-1.5 py-0.5 rounded text-[10px] transition-colors`,`hover:bg-muted/60 text-muted-foreground hover:text-foreground`),title:`Collapse all directories`,children:[(0,J.jsx)(br,{className:`h-3 w-3`}),(0,J.jsx)(`span`,{children:`Collapse`})]}),(0,J.jsxs)(`span`,{className:`ml-auto text-[9px] text-muted-foreground/50 tabular-nums`,children:[D,` folder`,D===1?``:`s`]})]}),(0,J.jsxs)(`div`,{className:`flex-1 overflow-y-auto py-1`,children:[u.length>0&&(0,J.jsxs)(`div`,{ref:d,className:`relative flex items-center gap-0.5 px-1 pb-1 border-b border-border/30 overflow-x-auto`,children:[(0,J.jsx)(`span`,{className:`sticky left-0 shrink-0 w-3 h-full bg-gradient-to-r from-background to-transparent pointer-events-none`}),u.map((e,t)=>{let n=e.isLast?e.label:c(e.label),r=e.path.replace(/\//g,s),i=a?a.replace(/\\/g,`/`).split(`/`).filter(Boolean):[],l=(()=>{for(let e=i.length-1;e>=0;e--)if(i[e]===o)return e;return-1})(),u=l>=0?i.slice(0,l+t+1):i.slice(0,t+1),d=s===`\\`?u.join(`\\`):`/`+u.join(`/`),p=(l>=0?i.slice(l+1,l+t+1):[]).join(s)||`.`;return(0,J.jsxs)(`span`,{className:`flex items-center gap-0.5 shrink-0`,children:[t>0&&(0,J.jsx)(`span`,{className:`text-[9px] text-muted-foreground/40 select-none`,children:s}),(0,J.jsx)(`button`,{type:`button`,onClick:()=>f(e.path),onContextMenu:e=>h(e,{absPath:d,relPath:p}),className:X(`px-1 py-0.5 rounded text-[11px] transition-colors whitespace-nowrap`,e.isLast?`text-foreground font-medium`:`text-muted-foreground hover:text-foreground hover:bg-muted/60`),title:e.isLast?`Current directory: ${r}`:`Navigate to ${r}`,children:n})]},e.path)}),e.length>0&&(0,J.jsxs)(`span`,{className:`ml-auto shrink-0 text-[9px] text-muted-foreground/50 tabular-nums pl-2`,children:[O.files>0&&`${O.files} file${O.files===1?``:`s`}`,O.files>0&&O.dirs>0&&`, `,O.dirs>0&&`${O.dirs} folder${O.dirs===1?``:`s`}`]})]}),i&&(0,J.jsxs)(`button`,{type:`button`,onClick:_,className:`flex items-center gap-1 w-full text-left px-2 py-0.5 border-b border-border/30 text-[10px] text-muted-foreground hover:text-foreground hover:bg-accent/50 transition-colors`,title:`Navigate to parent directory of ${i.replace(/\//g,s)}`,children:[(0,J.jsx)(jr,{className:`h-3 w-3 shrink-0`}),(0,J.jsx)(`span`,{className:`truncate`,children:(()=>{let e=i.replace(/\\/g,`/`).split(`/`);return e[e.length-1]??i})()}),(0,J.jsx)(`span`,{className:`ml-auto text-[8px] text-muted-foreground/40 shrink-0`,children:`go to dir`})]}),u.length===0&&!l&&(0,J.jsxs)(`button`,{type:`button`,onClick:y,className:X(`flex items-center gap-1.5 w-full text-left px-1 py-0.5 text-[11px] rounded`,`hover:bg-muted/60 transition-colors text-muted-foreground hover:text-foreground`,`font-medium`),children:[(0,J.jsx)(be,{className:`h-3.5 w-3.5 shrink-0`}),(0,J.jsx)(`span`,{children:`..`}),(0,J.jsx)(`span`,{className:`text-[9px] text-muted-foreground/50 ml-auto`,children:`parent directory`})]}),e.map(e=>(0,J.jsx)(Zf,{node:e,depth:0,selectedPath:C,forceExpand:T,onSelect:M,onOpen:N},e.path)),e.length===0&&(0,J.jsx)(`p`,{className:`text-[11px] text-muted-foreground italic p-2`,children:`No files found`})]}),p&&(0,J.jsxs)(`div`,{className:`fixed z-50 min-w-[140px] bg-popover border rounded-md shadow-md py-1 text-[11px]`,style:{left:p.x,top:p.y},children:[(0,J.jsx)(`button`,{type:`button`,onClick:()=>g(p.crumb.absPath),className:`flex items-center gap-2 w-full text-left px-3 py-1.5 hover:bg-accent transition-colors`,children:`Copy absolute path`}),(0,J.jsx)(`button`,{type:`button`,onClick:()=>g(p.crumb.relPath),className:`flex items-center gap-2 w-full text-left px-3 py-1.5 hover:bg-accent transition-colors`,children:`Copy relative path`}),(0,J.jsx)(`div`,{className:`border-t border-border/50 my-0.5`}),(0,J.jsx)(`button`,{type:`button`,onClick:()=>v(p.crumb.absPath,`terminal`),className:`flex items-center gap-2 w-full text-left px-3 py-1.5 hover:bg-accent transition-colors`,children:`Open in terminal`}),(0,J.jsx)(`button`,{type:`button`,onClick:()=>v(p.crumb.absPath,`file-manager`),className:`flex items-center gap-2 w-full text-left px-3 py-1.5 hover:bg-accent transition-colors`,children:`Open in file manager`}),(0,J.jsx)(`div`,{className:`border-t border-border/50 mt-0.5 pt-0.5`,children:(0,J.jsx)(`div`,{className:`px-3 py-1 text-[9px] text-muted-foreground/50 truncate max-w-[200px]`,children:p.crumb.absPath})})]})]})}var $f={note:zt,ask:Je,assign:dt,steer:Ht,btw:St,broadcast:dt,status:Qe,result:M};function ep(e){let t=new Date(e),n=Date.now()-t.getTime();return n<6e4?`now`:n<36e5?`${Math.round(n/6e4)}m`:n<864e5?`${Math.round(n/36e5)}h`:t.toLocaleDateString()}function tp({className:e}){let t=gi(e=>e.messages),n=gi(e=>e.agents),[r,i]=(0,H.useState)(!1),[a,o]=(0,H.useState)(!1),[s,c]=(0,H.useState)(!1),{client:l}=Q(),[u,d]=(0,H.useState)(l.status.state===`open`);(0,H.useEffect)(()=>{let e=l.onStatus(e=>d(e.state===`open`));return()=>e()},[l]),(0,H.useEffect)(()=>{u&&(l.send({type:`mailbox.messages`,payload:{limit:30}}),l.send({type:`mailbox.agents`,payload:{}}))},[u,l]);let f=q(e=>e.selectedMailMessage),m=q(e=>e.setSelectedMailMessage),h=q(e=>e.selectActivity),g=q(e=>e.setCurrentView),v=q(e=>e.setSidebarOpen);function y(e){if(f?.id===e.id){m(null),g(`chat`);return}m(e),v(!0),h(`mailbox`),g(`mailbox`)}let b=t.filter(e=>!e.completed).length,x=n.filter(e=>e.online).length;async function S(){t.length!==0&&await vc({title:`Delete all ${t.length} message${t.length===1?``:`s`}?`,message:`The mailbox file is truncated for every agent. This cannot be undone.`,confirmLabel:`Delete all`,danger:!0})&&(o(!0),l.send({type:`mailbox.clear`}))}(0,H.useEffect)(()=>{a&&t.length===0&&o(!1)},[a,t.length]);async function C(){await vc({title:`Purge stale messages?`,message:`Removes completed messages older than 1 day and incomplete messages older than 7 days. Active messages are preserved.`,confirmLabel:`Purge`,danger:!1})&&(c(!0),l.send({type:`mailbox.purge`}))}return(0,H.useEffect)(()=>{if(s){let e=setTimeout(()=>c(!1),3e3);return()=>clearTimeout(e)}},[s]),(0,J.jsxs)(`div`,{className:X(`rounded-lg border border-border bg-card/60 backdrop-blur-sm`,e),children:[(0,J.jsxs)(`button`,{type:`button`,onClick:()=>i(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)(Ce,{className:`h-4 w-4 text-cyan-500`}),(0,J.jsx)(`span`,{className:`text-xs font-semibold text-foreground flex-1 min-w-0 truncate`,children:`Mailbox`}),b>0&&(0,J.jsx)(`span`,{className:`inline-flex items-center px-1.5 py-0.5 rounded-full text-[10px] font-bold bg-yellow-100 dark:bg-yellow-900/40 text-yellow-700 dark:text-yellow-400`,children:b}),(0,J.jsxs)(`span`,{className:`text-[10px] text-muted-foreground`,children:[x,` online`]})]}),!r&&(0,J.jsxs)(`div`,{className:`px-3 pb-3 space-y-2`,children:[t.length>0?(0,J.jsxs)(`div`,{className:`space-y-1`,children:[(0,J.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,J.jsx)(`span`,{className:`text-[10px] font-semibold text-muted-foreground uppercase tracking-wide`,children:`Messages`}),(0,J.jsxs)(`button`,{type:`button`,onClick:S,disabled:a,className:`flex items-center gap-1 text-[10px] text-muted-foreground hover:text-red-500 disabled:opacity-40 transition-colors`,title:`Delete all messages`,children:[(0,J.jsx)(Te,{className:`h-3 w-3`}),a?`Deleting…`:`Delete all`]}),(0,J.jsxs)(`button`,{type:`button`,onClick:C,disabled:s,className:`flex items-center gap-1 text-[10px] text-muted-foreground hover:text-cyan-500 disabled:opacity-40 transition-colors`,title:`Purge stale/orphaned messages`,children:[(0,J.jsx)(p,{className:`h-3 w-3`}),s?`Purging…`:`Purge`]})]}),t.slice(0,8).map(e=>{let t=$f[e.type]??Ue,n=e.readByCount>0,r=f?.id===e.id;return(0,J.jsxs)(`button`,{type:`button`,onClick:()=>y(e),className:X(`flex items-start gap-2 px-2 py-1.5 rounded text-xs w-full text-left cursor-pointer transition-colors hover:bg-accent/60`,!n&&`bg-yellow-50 dark:bg-yellow-950/20`,r&&`ring-1 ring-primary bg-primary/5`),children:[(0,J.jsx)(t,{className:X(`h-3.5 w-3.5 mt-0.5 shrink-0`,n?`text-muted-foreground`:`text-yellow-600`)}),(0,J.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,J.jsx)(`span`,{className:X(`font-medium truncate`,!n&&`text-yellow-800 dark:text-yellow-300`),children:e.from}),e.completed&&(0,J.jsx)(M,{className:`h-3 w-3 text-green-500 shrink-0`}),!n&&(0,J.jsx)(`span`,{className:`text-[9px] text-yellow-600 font-bold`,children:`NEW`})]}),(0,J.jsx)(`div`,{className:`text-muted-foreground truncate`,children:e.subject}),(0,J.jsxs)(`div`,{className:`text-[10px] text-muted-foreground/70 truncate`,children:[e.body.slice(0,60),e.body.length>60?`…`:``]})]}),(0,J.jsxs)(`div`,{className:`shrink-0 text-[10px] text-muted-foreground flex flex-col items-end gap-0.5`,children:[(0,J.jsx)(`span`,{children:ep(e.timestamp)}),n&&(0,J.jsxs)(`span`,{className:`flex items-center gap-0.5`,children:[(0,J.jsx)(_,{className:`h-3 w-3`}),e.readByCount]})]})]},e.id)})]}):(0,J.jsxs)(`div`,{className:`text-xs text-muted-foreground py-2 text-center`,children:[(0,J.jsx)(gn,{className:`h-4 w-4 mx-auto mb-1 opacity-40`}),`No messages yet.`]}),n.length>0&&(0,J.jsxs)(`div`,{className:`border-t border-border pt-2`,children:[(0,J.jsxs)(`div`,{className:`text-[10px] font-semibold text-muted-foreground mb-1 flex items-center gap-1`,children:[(0,J.jsx)(Mr,{className:`h-3 w-3`}),` Agents`]}),n.filter(e=>e.online).slice(0,5).map(e=>(0,J.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[10px] text-muted-foreground py-0.5`,children:[(0,J.jsx)(`span`,{className:X(`h-1.5 w-1.5 rounded-full`,e.online?`bg-green-500`:`bg-muted-foreground/30`)}),(0,J.jsx)(`span`,{className:`font-medium text-foreground/80`,children:e.name}),e.role&&(0,J.jsxs)(`span`,{className:`opacity-60`,children:[`(`,e.role,`)`]}),(0,J.jsx)(`span`,{className:`opacity-50`,children:e.status}),e.currentTool&&(0,J.jsx)(`span`,{className:`text-cyan-500`,children:e.currentTool}),(0,J.jsx)(`span`,{className:`ml-auto opacity-50`,children:ep(e.lastSeenAt)})]},e.agentId)),n.filter(e=>!e.online).length>0&&(0,J.jsxs)(`div`,{className:`text-[10px] text-muted-foreground/50 mt-0.5`,children:[`+`,n.filter(e=>!e.online).length,` offline`]})]})]})]})}function np({fullView:e}){let[t,n]=(0,H.useState)([]),[r,i]=(0,H.useState)(!0),[a,o]=(0,H.useState)(!1),[s,c]=(0,H.useState)(``),[l,u]=(0,H.useState)(``),[d,f]=(0,H.useState)(!1),p=(0,H.useRef)(null),[m,h]=(0,H.useState)({open:!1,project:null,agentCount:0}),g=(0,H.useCallback)(()=>{U().send({type:`projects.list`})},[]);(0,H.useEffect)(()=>{i(!0);let e=U(),t=e.on(`projects.list`,e=>{let t=e.payload;n(t.projects??[]),i(!1)}),r=e.on(`projects.added`,e=>{let t=e.payload;t.slug?(Z.success(t.message),g()):Z.error(t.message)});return g(),()=>{t(),r()}},[g]);let _=e=>{if(!e)return`never`;let t=Date.now()-new Date(e).getTime(),n=Math.floor(t/6e4);if(n<1)return`just now`;if(n<60)return`${n}m ago`;let r=Math.floor(n/60);if(r<24)return`${r}h ago`;let i=Math.floor(r/24);return i===1?`yesterday`:i<30?`${i}d ago`:i<365?`${Math.floor(i/30)}mo ago`:`${Math.floor(i/365)}y ago`},v=(0,H.useCallback)(e=>{let t=K.getState().session?.id;if(t){let n=Y.getState().getAgentsBySession(t).filter(e=>e.status===`running`);if(n.length>0){h({open:!0,project:e,agentCount:n.length});return}}y(e)},[]),y=(0,H.useCallback)(e=>{let t=U();t.send({type:`projects.select`,payload:{root:e.root,name:e.name}});let n=t.on(`projects.selected`,e=>{let t=e.payload;n();let r=t.message.match(/(https?:\/\/[^\s]+)/);r?.[1]?(window.open(r[1],`_blank`),Z.success(`Opening ${t.name} in a new tab...`)):Z.info(t.message)})},[]),b=(0,H.useCallback)(()=>{let e=s.trim();if(!e){Z.error(`Please enter a folder path.`);return}o(!0);let t=U();t.send({type:`projects.add`,payload:{root:e,name:l.trim()||void 0}});let n=t.on(`projects.added`,()=>{n(),o(!1),f(!1),c(``),u(``)})},[s,l]),x=m.open&&m.project&&(0,J.jsx)(sc,{open:!0,onOpenChange:()=>h({open:!1,project:null,agentCount:0}),children:(0,J.jsxs)(dc,{className:`sm:max-w-sm`,children:[(0,J.jsxs)(fc,{children:[(0,J.jsx)(mc,{children:`Running Agents`}),(0,J.jsxs)(hc,{children:[m.agentCount,` agent`,m.agentCount===1?` is`:`s are`,` running in the current session. Switching projects will stop them.`]})]}),(0,J.jsxs)(pc,{children:[(0,J.jsx)($,{variant:`outline`,size:`sm`,onClick:()=>h({open:!1,project:null,agentCount:0}),children:`Cancel`}),(0,J.jsx)($,{size:`sm`,variant:`destructive`,onClick:()=>{let e=m.project;h({open:!1,project:null,agentCount:0}),y(e)},children:`Switch anyway`})]})]})}),S=[...t].sort((e,t)=>e.lastSeen&&t.lastSeen?t.lastSeen.localeCompare(e.lastSeen):e.lastSeen?-1:t.lastSeen?1:e.name.localeCompare(t.name)),C=(0,J.jsxs)(sc,{open:d,onOpenChange:f,children:[(0,J.jsx)(cc,{asChild:!0,children:(0,J.jsxs)($,{variant:`outline`,size:`sm`,className:`gap-1 h-7 text-xs`,children:[(0,J.jsx)(ln,{className:`h-3 w-3`}),`Register Project`]})}),(0,J.jsxs)(dc,{className:`sm:max-w-md`,children:[(0,J.jsxs)(fc,{children:[(0,J.jsx)(mc,{children:`Register New Project`}),(0,J.jsxs)(hc,{children:[`Enter the absolute path to a project folder. The project will be added to`,` `,(0,J.jsx)(`code`,{className:`font-mono bg-muted/40 px-1 rounded text-xs`,children:`~/.wrongstack/projects.json`}),`.`]})]}),(0,J.jsxs)(`div`,{className:`space-y-3`,children:[(0,J.jsxs)(`div`,{children:[(0,J.jsx)(`label`,{htmlFor:`proj-folder`,className:`text-xs font-medium text-muted-foreground mb-1 block`,children:`Folder path`}),(0,J.jsx)(gc,{id:`proj-folder`,placeholder:`/home/user/my-project or C:\\Users\\me\\my-project`,value:s,onChange:e=>c(e.target.value),onKeyDown:e=>{e.key===`Enter`&&p.current?.focus()}})]}),(0,J.jsxs)(`div`,{children:[(0,J.jsx)(`label`,{htmlFor:`proj-name`,className:`text-xs font-medium text-muted-foreground mb-1 block`,children:`Project name (optional — defaults to folder name)`}),(0,J.jsx)(gc,{id:`proj-name`,ref:p,placeholder:`My Project`,value:l,onChange:e=>u(e.target.value),onKeyDown:e=>{e.key===`Enter`&&b()}})]})]}),(0,J.jsxs)(pc,{children:[(0,J.jsx)($,{variant:`outline`,size:`sm`,onClick:()=>f(!1),children:`Cancel`}),(0,J.jsxs)($,{size:`sm`,onClick:b,disabled:a||!s.trim(),children:[a?(0,J.jsx)(z,{className:`h-3 w-3 animate-spin mr-1`}):null,`Register`]})]})]})]});if(r){let t=(0,J.jsx)(`div`,{className:`flex items-center justify-center py-6`,children:(0,J.jsx)(z,{className:`h-4 w-4 animate-spin text-muted-foreground`})});return e?(0,J.jsxs)(`div`,{className:`h-full flex flex-col overflow-hidden`,children:[(0,J.jsx)(`div`,{className:`px-3 py-2 border-b flex items-center justify-between`,children:(0,J.jsx)(`h2`,{className:`text-xs font-semibold text-muted-foreground uppercase tracking-wider`,children:`Projects`})}),(0,J.jsx)(`div`,{className:`flex-1 flex items-center justify-center`,children:t})]}):t}let w=(0,J.jsx)(`div`,{className:X(`space-y-1`,e&&`p-2`),children:S.map(e=>(0,J.jsxs)(`button`,{type:`button`,onClick:()=>v(e),className:`flex items-start gap-2 w-full text-left px-2 py-1.5 rounded border bg-card/40 text-xs hover:bg-accent hover:border-primary/40 transition-colors`,children:[(0,J.jsx)(Mn,{className:`h-3.5 w-3.5 shrink-0 mt-0.5 text-muted-foreground`}),(0,J.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,J.jsx)(`div`,{className:`font-medium truncate`,children:e.name}),(0,J.jsx)(`div`,{className:`font-mono text-[10px] text-muted-foreground truncate`,children:e.root}),(0,J.jsxs)(`div`,{className:`flex items-center gap-2 mt-0.5 text-[10px] text-muted-foreground/60`,children:[(0,J.jsx)(`span`,{className:`font-mono`,children:e.slug}),e.lastSeen&&(0,J.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,J.jsx)(Gn,{className:`h-2.5 w-2.5`}),_(e.lastSeen)]})]})]}),(0,J.jsx)(xr,{className:`h-3 w-3 shrink-0 mt-1 text-muted-foreground/40`})]},e.slug))});return e?(0,J.jsxs)(`div`,{className:`h-full flex flex-col overflow-hidden`,children:[x,(0,J.jsxs)(`div`,{className:`px-3 py-2 border-b shrink-0`,children:[(0,J.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,J.jsx)(`h2`,{className:`text-xs font-semibold text-muted-foreground uppercase tracking-wider`,children:`Projects`}),C]}),(0,J.jsxs)(`p`,{className:`text-[10px] text-muted-foreground/60 mt-0.5`,children:[`Known projects from`,` `,(0,J.jsx)(`code`,{className:`font-mono bg-muted/40 px-0.5 rounded`,children:`~/.wrongstack/projects.json`})]})]}),t.length===0?(0,J.jsx)(`div`,{className:`flex-1 flex items-center justify-center`,children:(0,J.jsxs)(`div`,{className:`text-xs text-muted-foreground italic py-2`,children:[`No projects registered. Use the button above or run`,` `,(0,J.jsx)(`code`,{className:`font-mono bg-muted/40 px-1 rounded`,children:`wstack`}),` `,`in a directory to register it.`]})}):(0,J.jsx)(`div`,{className:`flex-1 overflow-y-auto`,children:w}),(0,J.jsx)(`div`,{className:`px-3 py-2 border-t shrink-0`,children:(0,J.jsx)(`p`,{className:`text-[9px] text-muted-foreground/40 text-center`,children:`Click a project to open it in a new WebUI tab`})})]}):(0,J.jsxs)(`div`,{className:`space-y-2`,children:[x,(0,J.jsx)(`div`,{className:`flex items-center justify-between`,children:C}),t.length===0?(0,J.jsxs)(`div`,{className:`text-xs text-muted-foreground italic py-2`,children:[`No projects registered. Use the button above or run`,` `,(0,J.jsx)(`code`,{className:`font-mono bg-muted/40 px-1 rounded`,children:`wstack`}),` `,`in a directory to register it.`]}):w]})}function rp(e){return e===`running`}function ip(e,t){let n=+!rp(e.status),r=+!rp(t.status);return n===r?e.startedAt-t.startedAt:n-r}function ap(e){let t=0,n=0,r=0;for(let i of e)i.status===`running`?t++:i.status===`completed`?n++:(i.status===`failed`||i.status===`timeout`)&&r++;return{running:t,completed:n,failed:r,total:e.length}}var op=[` `,`▁`,`▂`,`▃`,`▄`,`▅`,`▆`,`▇`,`█`],sp=12;function cp(e,t){return t===0?0:Math.min(8,Math.round(e/t*8))}function lp({bins:e,className:t}){let n=Array.from({length:sp},(t,n)=>e.at(-(sp-n))??0),r=Math.max(...n,1);return r===1&&n.every(e=>e===0)?(0,J.jsx)(`span`,{className:t,"aria-label":`No activity`,title:`No activity yet`,children:`—`}):(0,J.jsx)(`span`,{className:t,"aria-label":`Activity sparkline: max ${r} events`,title:`Activity sparkline — peak ${r} events/bucket`,children:n.map((e,t)=>{let n=cp(e,r),i=op[n];return(0,J.jsx)(`span`,{style:{color:n>=7?`hsl(var(--success))`:`hsl(var(--muted-foreground))`,opacity:n>0?void 0:.3},children:i},t)})})}function up(e){return e==null||!Number.isFinite(e)||e<0?`$0.0000`:e<.01?`$${e.toFixed(4)}`:e<1?`$${e.toFixed(3)}`:`$${e.toFixed(2)}`}function dp(e){return e==null||!Number.isFinite(e)?`0`:e<1e3?String(Math.round(e)):e<1e6?`${(e/1e3).toFixed(1)}k`:`${(e/1e6).toFixed(1)}M`}function fp(e){if(e==null||!Number.isFinite(e)||e<0)return`—`;let t=Math.round(e/1e3);return t<60?`${t}s`:t<3600?`${Math.floor(t/60)}m`:`${Math.floor(t/3600)}h`}var pp={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 mp({agent:e,onClose:t}){let n=pp[e.status],r=e.status===`running`,a=e.currentTool??e.lastTool,o=Date.now()-e.startedAt,[s,l]=(0,H.useState)(!1),u=Y(e=>e.leaderId),d=e.id===u,f=Math.min(100,Math.max(0,e.ctxPct)),p=(0,H.useCallback)(async e=>{try{await navigator.clipboard.writeText(e),l(!0),setTimeout(()=>l(!1),2e3)}catch{}},[]),m=f>=85?`bg-red-500/15 text-red-600 dark:text-red-400`:f>=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:X(`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:X(`led`,n.led,n.pulse&&`led-pulse`)}),(0,J.jsx)(`h3`,{className:`text-sm font-semibold`,children:e.name}),d&&(0,J.jsx)(c,{className:`h-3.5 w-3.5 text-amber-500 shrink-0`,"aria-label":`leader`}),(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)(B,{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)(_e,{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)(Fr,{className:`h-3 w-3 text-muted-foreground`}),(0,J.jsx)(`span`,{className:`text-xs font-mono tabular`,children:fp(o)}),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:up(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.jsxs)(`span`,{className:`block text-xs font-mono font-medium mt-0.5 tabular`,children:[`⚡×`,e.extensions]})]})]}),r&&(0,J.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,J.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:`Activity`}),(0,J.jsx)(lp,{bins:e.sparklineBins,className:`font-mono`})]}),e.budgetWarning&&(0,J.jsxs)(`div`,{className:`flex items-center gap-2 px-3 py-2 rounded-lg bg-amber-500/10 border border-amber-500/20 text-xs`,children:[(0,J.jsx)(Bt,{className:`h-3.5 w-3.5 text-amber-500 shrink-0`}),(0,J.jsxs)(`span`,{className:`text-amber-600 dark:text-amber-400`,children:[`⚡ hitting `,(0,J.jsx)(`strong`,{children:e.budgetWarning.kind}),` limit (`,e.budgetWarning.used,`/`,e.budgetWarning.limit,`) — extending`]})]}),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:X(`tabular font-medium`,m.replace(/bg-\S+\s*/g,``)),children:[f,`%`]})]}),(0,J.jsx)(`div`,{className:`h-1.5 w-full overflow-hidden rounded-full bg-muted`,children:(0,J.jsx)(`div`,{className:X(`h-full rounded-full transition-all`,f>=85?`bg-destructive`:f>=70?`bg-[hsl(var(--warning))]`:`bg-primary`),style:{width:`${Math.max(2,f)}%`}})}),(0,J.jsxs)(`div`,{className:`text-[10px] text-muted-foreground tabular text-right`,children:[dp(e.ctxTokens),` / `,dp(e.maxContext),` tokens`]})]}),a&&(0,J.jsxs)(`div`,{className:X(`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)(Un,{className:X(`h-3.5 w-3.5`,r?`text-primary animate-pulse`:`text-muted-foreground`)}),(0,J.jsx)(`span`,{className:`text-xs font-mono`,children:a}),(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:()=>p(e.finalText),className:`flex items-center gap-1 px-1.5 py-0.5 rounded text-[10px] text-muted-foreground hover:text-foreground hover:bg-muted transition-colors`,title:`Copy output`,children:[s?(0,J.jsx)(i,{className:`h-3 w-3 text-emerald-500`}):(0,J.jsx)(Oe,{className:`h-3 w-3`}),s?`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:()=>p(e.partialText),className:`flex items-center gap-1 px-1.5 py-0.5 rounded text-[10px] text-muted-foreground hover:text-foreground hover:bg-muted transition-colors`,title:`Copy output`,children:[s?(0,J.jsx)(i,{className:`h-3 w-3 text-emerald-500`}):(0,J.jsx)(Oe,{className:`h-3 w-3`}),s?`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:X(`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:X(`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 hp({a:e,onClick:t}){let n=pp[e.status],r=e.status===`running`,i=e.currentTool??e.lastTool,a=Math.min(100,Math.max(0,e.ctxPct));return(0,J.jsxs)(`button`,{type:`button`,onClick:t,className:X(`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:X(`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)(_e,{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:up(e.costUsd)})]}),i&&(0,J.jsxs)(`div`,{className:X(`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)(Un,{className:X(`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 ${a}%`,children:[(0,J.jsx)(`div`,{className:`h-1 flex-1 overflow-hidden rounded-full bg-muted`,children:(0,J.jsx)(`div`,{className:X(`h-full rounded-full transition-all`,a>=85?`bg-destructive`:a>=70?`bg-[hsl(var(--warning))]`:`bg-primary`),style:{width:`${Math.max(2,a)}%`}})}),(0,J.jsx)(`span`,{className:`tabular text-[9px] text-muted-foreground`,children:e.maxContext>0?`${a}%`:`—`})]}),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 gp({className:e}){let t=Y(e=>e.agents),[n,r]=(0,H.useState)(!0),[i,a]=(0,H.useState)(null),o=(0,H.useMemo)(()=>{let e=Array.from(t.values());return e.sort(ip),e},[t]),s=i?o.find(e=>e.id===i):null;if(o.length===0)return null;let c=ap(o),l=o.reduce((e,t)=>e+(t.costUsd??0),0),u=n&&o.length>=3;return(0,J.jsxs)(J.Fragment,{children:[(0,J.jsxs)(`div`,{className:X(`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)(Yn,{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.running>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.running]}),c.completed>0&&(0,J.jsxs)(`span`,{className:`text-muted-foreground`,children:[c.completed,` done`]}),c.failed>0&&(0,J.jsxs)(`span`,{className:`text-destructive`,children:[c.failed,` err`]}),l>0&&(0,J.jsx)(`span`,{className:`tabular text-foreground/70`,children:up(l)})]}),u?(0,J.jsx)(ot,{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`})]}),!u&&(0,J.jsx)(`div`,{className:`flex gap-2 overflow-x-auto px-2 pb-2`,children:o.map(e=>(0,J.jsx)(hp,{a:e,onClick:()=>a(e.id)},e.id))})]}),s&&(0,J.jsx)(mp,{agent:s,onClose:()=>a(null)})]})}var _p={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 vp(e){return e<=0?`$0`:e>=.01?`$${e.toFixed(3)}`:`$${e.toFixed(4)}`}function yp({agent:e,onClick:t}){let n=_p[e.status],r=e.status===`running`;return(0,J.jsxs)(`button`,{type:`button`,onClick:t,className:X(`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:X(`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:vp(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)(Un,{className:X(`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 bp(){let e=Y(e=>e.agents),[t,n]=(0,H.useState)(null),r=(0,H.useMemo)(()=>{let t=Array.from(e.values());return t.sort((e,t)=>{let n=e.status===`running`?0:1,r=t.status===`running`?0:1;return n===r?e.startedAt-t.startedAt:n-r}),t},[e]),i=r.filter(e=>e.status===`running`).length,a=t?r.find(e=>e.id===t)??null:null;return r.length===0?(0,J.jsx)(`div`,{className:`flex-1 flex items-center justify-center p-4`,children:(0,J.jsxs)(`div`,{className:`text-center text-muted-foreground`,children:[(0,J.jsx)(Yn,{className:`h-8 w-8 mx-auto mb-3 opacity-20`}),(0,J.jsx)(`p`,{className:`text-sm font-medium`,children:`No agents yet`}),(0,J.jsx)(`p`,{className:`text-xs mt-1`,children:`Subagents appear here when the fleet is active.`})]})}):(0,J.jsxs)(J.Fragment,{children:[(0,J.jsxs)(`div`,{className:`px-3 py-2 border-b text-[10px] text-muted-foreground flex items-center gap-2`,children:[(0,J.jsx)(`span`,{className:`font-semibold uppercase tracking-wider`,children:`Fleet`}),(0,J.jsxs)(`span`,{className:`ml-auto tabular-nums`,children:[i>0?`${i} running · `:``,r.length,` total`]})]}),(0,J.jsx)(`div`,{className:`flex-1 overflow-y-auto p-2 space-y-1.5`,children:r.map(e=>(0,J.jsx)(yp,{agent:e,onClick:()=>n(e.id)},e.id))}),(0,J.jsx)(`div`,{className:`border-t px-3 py-2 shrink-0`,children:(0,J.jsxs)(`button`,{type:`button`,onClick:()=>q.getState().setAgentsMonitorOpen(!0),className:`w-full flex items-center justify-center gap-1.5 h-7 rounded-md border border-border text-[11px] text-muted-foreground hover:text-foreground hover:bg-accent transition-colors`,children:[(0,J.jsx)(Pr,{className:`h-3 w-3`}),`Open full agents view`]})}),a&&(0,J.jsx)(mp,{agent:a,onClose:()=>n(null)})]})}var xp={M:{label:`M`,cls:`text-amber-600 dark:text-amber-400`},A:{label:`A`,cls:`text-emerald-600 dark:text-emerald-400`},D:{label:`D`,cls:`text-rose-600 dark:text-rose-400`},R:{label:`R`,cls:`text-sky-600 dark:text-sky-400`},C:{label:`C`,cls:`text-sky-600 dark:text-sky-400`},U:{label:`U`,cls:`text-orange-600 dark:text-orange-400`},"?":{label:`U`,cls:`text-muted-foreground`}};function Sp(e){let t=e.lastIndexOf(`/`);return t<0?{name:e,dir:``}:{name:e.slice(t+1),dir:e.slice(0,t+1)}}function Cp({file:e,active:t,onSelect:n}){let r=xp[e.status]??xp.M,{name:i,dir:a}=Sp(e.path);return(0,J.jsxs)(`button`,{type:`button`,onClick:n,title:e.path,className:X(`group flex items-center gap-2 w-full px-2 py-1 text-left text-xs rounded hover:bg-accent/60`,t&&`bg-accent`),children:[(0,J.jsx)(`span`,{className:X(`w-3 shrink-0 text-center font-mono font-bold`,r?.cls),children:r?.label}),(0,J.jsxs)(`span`,{className:`flex-1 min-w-0 truncate`,children:[(0,J.jsx)(`span`,{className:X(e.status===`D`&&`line-through opacity-70`),children:i}),a&&(0,J.jsx)(`span`,{className:`text-muted-foreground/60 ml-1 truncate`,children:a})]}),(0,J.jsxs)(`span`,{className:`shrink-0 font-mono text-[10px] tabular-nums`,children:[e.added>0&&(0,J.jsxs)(`span`,{className:`text-emerald-600 dark:text-emerald-400`,children:[`+`,e.added]}),e.deleted>0&&(0,J.jsxs)(`span`,{className:`text-rose-600 dark:text-rose-400 ml-1`,children:[`-`,e.deleted]})]})]})}function wp(){let{client:e}=Q(),t=G(e=>e.wsConnected),n=bi(e=>e.files),r=bi(e=>e.error),i=bi(e=>e.loadingList),a=bi(e=>e.selectedPath),o=(0,H.useCallback)(()=>{t&&(bi.getState().setListLoading(!0),e?.getGitChanges?.())},[e,t]);(0,H.useEffect)(()=>{o()},[o]);let s=t=>{bi.getState().select(t),e?.getGitDiff?.(t),q.getState().setCurrentView(`changes`)},c=n.reduce((e,t)=>e+t.added,0),l=n.reduce((e,t)=>e+t.deleted,0);return(0,J.jsxs)(`div`,{className:`flex flex-col h-full overflow-hidden`,children:[(0,J.jsxs)(`div`,{className:`flex items-center justify-between px-3 py-2 border-b shrink-0`,children:[(0,J.jsxs)(`span`,{className:`text-[11px] text-muted-foreground font-mono`,children:[n.length,` `,n.length===1?`file`:`files`,n.length>0&&(0,J.jsxs)(J.Fragment,{children:[` · `,(0,J.jsxs)(`span`,{className:`text-emerald-600 dark:text-emerald-400`,children:[`+`,c]}),` `,(0,J.jsxs)(`span`,{className:`text-rose-600 dark:text-rose-400`,children:[`-`,l]})]})]}),(0,J.jsx)(`button`,{type:`button`,onClick:o,title:`Refresh changes`,className:`h-6 w-6 inline-flex items-center justify-center rounded hover:bg-accent text-muted-foreground`,children:i?(0,J.jsx)(z,{className:`h-3.5 w-3.5 animate-spin`}):(0,J.jsx)(Ct,{className:`h-3.5 w-3.5`})})]}),(0,J.jsx)(`div`,{className:`flex-1 overflow-y-auto p-1.5`,children:r?(0,J.jsx)(`div`,{className:`px-2 py-6 text-center text-xs text-muted-foreground`,children:r}):n.length===0?(0,J.jsxs)(`div`,{className:`flex flex-col items-center gap-2 px-2 py-10 text-center text-xs text-muted-foreground`,children:[(0,J.jsx)(je,{className:`h-6 w-6 opacity-40`}),i?`Loading changes…`:`No changes — working tree is clean.`]}):(0,J.jsx)(`div`,{className:`flex flex-col gap-0.5`,children:n.map(e=>(0,J.jsx)(Cp,{file:e,active:e.path===a,onSelect:()=>s(e.path)},e.path))})})]})}var Tp=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 Ep(e){return e.filter(e=>e.tokenTotal===0&&!e.isCurrent).map(e=>e.id)}function Dp({historyQuery:e,setHistoryQuery:t,historyEntries:n,historyLoading:r,historyError:i,wsConnected:a,listSessions:o,resumeSession:s,deleteSession:c}){let l=q(e=>e.favoriteSessionIds),u=q(e=>e.toggleFavoriteSession),d=q(e=>e.sessionNicknames),f=q(e=>e.setSessionNickname),[p,m]=(0,H.useState)(null),[h,g]=(0,H.useState)(``),[_,v]=(0,H.useState)(null);(0,H.useEffect)(()=>{_&&n.some(e=>e.id===_&&e.isCurrent)&&v(null)},[_,n]);let y=(0,H.useCallback)(e=>{v(e),s(e),setTimeout(()=>v(t=>t===e?null:t),1e4)},[s]),b=(0,H.useMemo)(()=>Ep(n),[n]),x=(0,H.useCallback)(async()=>{if(b.length!==0&&await vc({title:b.length===1?`Delete 1 empty session?`:`Delete ${b.length} empty sessions?`,message:`Sessions without any token usage are removed from disk.`,confirmLabel:`Delete`,danger:!0}))for(let e of b)c(e)},[b,c]),S=(()=>{let t=e.trim().toLowerCase(),r=t?n.filter(e=>e.title.toLowerCase().includes(t)||e.model.toLowerCase().includes(t)||e.provider.toLowerCase().includes(t)||e.id.toLowerCase().includes(t)):n,i=new Date;i.setHours(0,0,0,0);let a=i.getTime(),o=a-864e5,s=a-6*864e5,c={today:[],yesterday:[],week:[],older:[]};for(let e of r){let t=Date.parse(e.startedAt);if(Number.isNaN(t)){c.older.push(e);continue}t>=a?c.today.push(e):t>=o?c.yesterday.push(e):t>=s?c.week.push(e):c.older.push(e)}let u=new Set(l),d=r.filter(e=>u.has(e.id)),f=[];d.length&&f.push({label:`Favorites`,rows:d,star:!0});let p=e=>e.filter(e=>!u.has(e.id)),m=p(c.today),h=p(c.yesterday),g=p(c.week),_=p(c.older);return m.length&&f.push({label:`Today`,rows:m}),h.length&&f.push({label:`Yesterday`,rows:h}),g.length&&f.push({label:`This week`,rows:g}),_.length&&f.push({label:`Earlier`,rows:_}),f})();return(0,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.jsxs)(`div`,{className:`flex items-center gap-1`,children:[b.length>0&&(0,J.jsx)(`button`,{type:`button`,className:`h-6 w-6 inline-flex items-center justify-center rounded-md hover:bg-muted text-muted-foreground hover:text-destructive`,onClick:x,disabled:!a,title:`Delete ${b.length} empty session${b.length===1?``:`s`}`,children:(0,J.jsx)(Te,{className:`h-3.5 w-3.5`})}),(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)(z,{className:`h-3.5 w-3.5 animate-spin`}):(0,J.jsx)(Ct,{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)(st,{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)(B,{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)(Qd,{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)(Gn,{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`})]}):S.length===0?(0,J.jsxs)(`div`,{className:`text-center text-muted-foreground py-8 px-4`,children:[(0,J.jsx)(st,{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:S.map(e=>(0,J.jsxs)(`div`,{className:`space-y-1`,children:[(0,J.jsxs)(`div`,{className:X(`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)(re,{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:X(`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||p===e.id||_!==null,onClick:()=>y(e.id),onDoubleClick:t=>{t.stopPropagation(),m(e.id),g(d[e.id]??e.title??``)},className:`block w-full rounded-md px-3 py-2 pr-16 text-left disabled:cursor-default focus:outline-none focus-visible:ring-2 focus-visible:ring-ring`,children:(0,J.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[p===e.id?(0,J.jsx)(`input`,{value:h,onChange:e=>g(e.target.value),onClick:e=>e.stopPropagation(),onBlur:()=>{f(e.id,h),m(null)},onKeyDown:t=>{t.key===`Enter`?(t.preventDefault(),f(e.id,h),m(null)):t.key===`Escape`&&(t.preventDefault(),m(null))},placeholder:e.title||`Nickname`,className:`w-full text-sm bg-background border border-input rounded px-1.5 py-0.5 focus:outline-none focus:ring-1 focus:ring-ring`}):(0,J.jsx)(`div`,{className:`font-medium truncate text-foreground`,title:d[e.id]?`${d[e.id]} — original: ${e.title}`:`${e.title}\n\nDouble-click to rename`,children:d[e.id]||e.title||`(empty)`}),(0,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:[_===e.id?(0,J.jsxs)(`span`,{className:`flex items-center gap-1 text-primary font-medium`,children:[(0,J.jsx)(z,{className:`h-3 w-3 animate-spin`}),`resuming…`]}):(0,J.jsx)(`span`,{children:Tp(e.startedAt)}),e.tokenTotal>0&&(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(`span`,{className:`opacity-50`,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`,{className:`opacity-50`,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:()=>u(e.id),className:X(`transition-opacity hover:text-amber-500`,l.includes(e.id)?`opacity-100 text-amber-500`:`opacity-0 group-hover:opacity-100 text-muted-foreground`),title:l.includes(e.id)?`Unfavorite`:`Mark as favorite`,children:(0,J.jsx)(re,{className:X(`h-3.5 w-3.5`,l.includes(e.id)&&`fill-current`)})}),!e.isCurrent&&(0,J.jsx)(`button`,{type:`button`,onClick:async()=>{await vc({title:`Delete session?`,message:`"${d[e.id]||e.title||`(empty)`}" will be removed from disk. This cannot be undone.`,confirmLabel:`Delete`,danger:!0})&&c(e.id)},className:`opacity-0 group-hover:opacity-100 transition-opacity text-muted-foreground hover:text-destructive`,title:`Delete session`,children:(0,J.jsx)(Te,{className:`h-3.5 w-3.5`})})]})]},e.id))]},e.label))})})]})}function Op(){let e=G(e=>e.wsConnected),{entries:t,loading:n,error:r}=xi(),{listSessions:i,resumeSession:a,deleteSession:o}=Q(),s=q(e=>e.setCurrentView),c=K(e=>e.session?.id),[l,u]=(0,H.useState)(``);return(0,H.useEffect)(()=>{e&&i(50)},[e,c,i]),(0,J.jsxs)(`div`,{className:`flex-1 flex flex-col overflow-hidden`,children:[(0,J.jsx)(Dp,{historyQuery:l,setHistoryQuery:u,historyEntries:t,historyLoading:n,historyError:r,wsConnected:e,listSessions:i,resumeSession:a,deleteSession:o}),(0,J.jsx)(`div`,{className:`border-t px-3 py-2 shrink-0`,children:(0,J.jsxs)(`button`,{type:`button`,onClick:()=>s(`sessions`),className:`w-full flex items-center justify-center gap-1.5 h-7 rounded-md border border-border text-[11px] text-muted-foreground hover:text-foreground hover:bg-accent transition-colors`,children:[(0,J.jsx)(Pr,{className:`h-3 w-3`}),`Open sessions dashboard`]})})]})}function kp(e){return e<=0?`$0.000`:e>=.01?`$${e.toFixed(3)}`:`$${e.toFixed(4)}`}function Ap(e){if(e<=0)return`--`;let t=Math.floor(e/1e3);if(t<60)return`${t}s`;let n=Math.floor(t/60);return n<60?`${n}m ${t%60}s`:`${Math.floor(n/60)}h ${n%60}m`}function jp({icon:e,label:t,onClick:n,disabled:r,tone:i,title:a}){return(0,J.jsxs)(`button`,{type:`button`,onClick:n,disabled:r,title:a??t,className:X(`flex items-center justify-center gap-1.5 h-8 rounded-md border text-[11px] font-medium transition-colors`,`disabled:opacity-40 disabled:cursor-not-allowed`,i===`primary`?`border-primary/40 bg-primary/10 text-primary hover:bg-primary/20`:i===`danger`?`border-destructive/40 bg-destructive/10 text-destructive hover:bg-destructive/20`:`border-border bg-card hover:bg-accent text-foreground/80`),children:[e,t]})}function Mp({label:e,value:t,sub:n}){return(0,J.jsxs)(`div`,{className:`flex flex-col p-2 rounded-lg bg-muted/40 border border-border/40 min-w-0`,children:[(0,J.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:e}),(0,J.jsx)(`span`,{className:`text-sm font-semibold tabular-nums truncate`,children:t}),n&&(0,J.jsx)(`span`,{className:`text-[9px] text-muted-foreground/70 truncate`,children:n})]})}function Np({icon:e,label:t,right:n}){return(0,J.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,J.jsxs)(`span`,{className:`flex items-center gap-1.5 text-[10px] uppercase tracking-wider text-muted-foreground font-semibold`,children:[e,t]}),n]})}function Pp({label:e,value:t,onChange:n,title:r}){return(0,J.jsxs)(`div`,{className:`flex items-center justify-between gap-2 py-1`,title:r,children:[(0,J.jsx)(`span`,{className:`text-xs text-foreground/80`,children:e}),(0,J.jsx)(`button`,{type:`button`,role:`switch`,"aria-checked":t,onClick:n,className:X(`shrink-0 relative inline-flex h-4 w-7 rounded-full border transition-colors`,t?`bg-primary border-primary`:`bg-muted border-input hover:bg-muted/80`),children:(0,J.jsx)(`span`,{className:X(`absolute top-0.5 left-0.5 h-2.5 w-2.5 rounded-full bg-background shadow transition-transform`,t&&`translate-x-3`)})})]})}function Fp(){let{client:e,updatePrefs:t,switchAutonomy:n}=Q(),r=G(e=>e.wsConnected),i=G(e=>e.wsUrl),a=G(e=>e.provider),o=G(e=>e.model),s=G(e=>e.soundOnComplete),c=K(e=>e.session),l=K(e=>e.totalTokens),u=K(e=>e.cost),d=K(e=>e.iteration),f=K(e=>e.todos),p=K(e=>e.lastInputTokens),m=K(e=>e.maxContext),h=W(e=>e.messages),g=W(e=>e.isLoading),_=Y(e=>e.agents),v=q(e=>e.pinnedIds),y=q(e=>e.unpinAll),x=q(e=>e.setModelSwitcherOpen),S=Ji(),C=(0,H.useCallback)((e,n)=>{S.set({[e]:n}),t({[e]:n})},[S,t]),[w,T]=(0,H.useState)(!1),E=c?.startedAt??null,[D,O]=(0,H.useState)(()=>Date.now());(0,H.useEffect)(()=>{if(!E)return;let e=setInterval(()=>O(Date.now()),1e3);return()=>clearInterval(e)},[E]);let k=(0,H.useMemo)(()=>Array.from(_.values()).filter(e=>e.status===`running`).length,[_]),A=m>0&&p>0?Math.min(100,Math.round(p/m*100)):0,j=v.map(e=>h.find(t=>t.id===e)).filter(e=>!!e&&e.content.length>0),N=e=>U(i)?.send?.(e);return(0,J.jsxs)(`div`,{className:`flex-1 overflow-y-auto`,children:[(0,J.jsxs)(`div`,{className:`px-3 py-2.5 border-b grid grid-cols-2 gap-1.5`,children:[g?(0,J.jsx)(jp,{icon:(0,J.jsx)(me,{className:`h-3 w-3`}),label:`Abort`,tone:`danger`,onClick:()=>N({type:`abort`,payload:{}}),disabled:!r}):(0,J.jsx)(jp,{icon:(0,J.jsx)(tr,{className:`h-3 w-3`}),label:`New session`,tone:`primary`,onClick:()=>{e?.newSession?.(),q.getState().setCurrentView(`chat`)},disabled:!r,title:`Start a new session (Ctrl+N)`}),(0,J.jsx)(jp,{icon:(0,J.jsx)(b,{className:`h-3 w-3`}),label:`Export`,onClick:()=>Yl(),title:`Export chat as markdown (Ctrl+E)`}),(0,J.jsx)(jp,{icon:(0,J.jsx)(ee,{className:`h-3 w-3`}),label:`Compact`,onClick:()=>N({type:`context.compact`,payload:{aggressive:!1}}),disabled:!r,title:`Compact the context window`}),(0,J.jsx)(jp,{icon:(0,J.jsx)(We,{className:`h-3 w-3`}),label:`Clear`,onClick:()=>N({type:`context.clear`}),disabled:!r,title:`Clear context (Ctrl+L)`})]}),(0,J.jsxs)(`button`,{type:`button`,onClick:()=>x(!0),className:`w-full px-4 py-2.5 border-b text-left hover:bg-muted/40 transition-colors`,title:`Change model (Ctrl+M)`,children:[(0,J.jsx)(`div`,{className:`text-[10px] uppercase tracking-wider text-muted-foreground mb-0.5`,children:`Model`}),(0,J.jsxs)(`div`,{className:`font-mono text-xs truncate`,children:[(0,J.jsx)(`span`,{className:`text-muted-foreground`,children:a||`—`}),(0,J.jsx)(`span`,{className:`text-muted-foreground/40 mx-1`,children:`/`}),(0,J.jsx)(`span`,{className:`font-medium`,children:o||`—`})]})]}),m>0&&(0,J.jsxs)(`div`,{className:`px-4 py-2.5 border-b space-y-1.5`,children:[(0,J.jsx)(`button`,{type:`button`,onClick:()=>T(!0),className:`w-full block text-left`,title:`Click for a context breakdown`,children:(0,J.jsx)(Np,{icon:null,label:`Context`,right:(0,J.jsxs)(`span`,{className:`text-[10px] text-muted-foreground tabular-nums font-mono`,children:[yu(p),`/`,yu(m),` · `,A,`%`]})})}),(0,J.jsx)(`button`,{type:`button`,onClick:()=>T(!0),className:`w-full block`,title:`Click for a context breakdown`,children:(0,J.jsx)(Ou,{pct:A,tokens:p,maxTokens:m,showTokens:!0})})]}),(0,J.jsxs)(`div`,{className:`px-3 py-2.5 border-b space-y-1.5`,children:[(0,J.jsx)(Np,{icon:(0,J.jsx)(_e,{className:`h-3 w-3`}),label:`Session`}),(0,J.jsxs)(`div`,{className:`grid grid-cols-2 gap-1.5`,children:[(0,J.jsx)(Mp,{label:`Messages`,value:h.length}),(0,J.jsx)(Mp,{label:`Elapsed`,value:E?Ap(D-E):`--`}),(0,J.jsx)(Mp,{label:`Tokens`,value:yu(l.input+l.output),sub:`${yu(l.input)} in / ${yu(l.output)} out`}),(0,J.jsx)(Mp,{label:`Cost`,value:kp(u)}),d&&(0,J.jsx)(Mp,{label:`Iteration`,value:d.index,sub:d.max?`of ${d.max}`:void 0}),_.size>0&&(0,J.jsx)(Mp,{label:`Agents`,value:_.size,sub:k>0?`${k} running`:void 0})]})]}),f.length>0&&(()=>{let e=f.filter(e=>e.status===`completed`).length,t=f.filter(e=>e.status===`in_progress`).length,n=Math.round(e/f.length*100),r=e===f.length;return(0,J.jsxs)(`div`,{className:`px-3 py-2.5 border-b space-y-1.5`,children:[(0,J.jsx)(Np,{icon:(0,J.jsx)(De,{className:`h-3 w-3`}),label:`Plan`,right:(0,J.jsxs)(`span`,{className:`tabular-nums text-[10px] text-muted-foreground`,children:[e,`/`,f.length]})}),(0,J.jsx)(`div`,{className:X(`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:X(`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:f.map(e=>{let t=e.status===`completed`?M:e.status===`in_progress`?nt:Qe,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:X(`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:X(`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)})})]})})(),j.length>0&&(0,J.jsxs)(`div`,{className:`px-3 py-2.5 border-b space-y-1.5`,children:[(0,J.jsx)(Np,{icon:(0,J.jsx)(xn,{className:`h-3 w-3 text-amber-500`}),label:`Pinned`,right:(0,J.jsx)(`button`,{type:`button`,onClick:y,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:j.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)})})]}),(0,J.jsxs)(`div`,{className:`px-3 py-2.5 border-b space-y-1`,children:[(0,J.jsx)(Np,{icon:(0,J.jsx)($e,{className:`h-3 w-3`}),label:`Quick settings`}),(0,J.jsxs)(`div`,{className:`flex items-center justify-between gap-2 py-1`,children:[(0,J.jsx)(`span`,{className:`text-xs text-foreground/80`,children:`Autonomy`}),(0,J.jsxs)(`select`,{value:S.autonomy,onChange:e=>{let t=e.target.value;S.set({autonomy:t}),n(t)},className:`shrink-0 h-6 max-w-[150px] rounded-md border bg-background px-1.5 text-[11px]`,children:[(0,J.jsx)(`option`,{value:`off`,children:`Off`}),(0,J.jsx)(`option`,{value:`suggest`,children:`Suggest`}),(0,J.jsx)(`option`,{value:`auto`,children:`Auto`}),(0,J.jsx)(`option`,{value:`eternal`,children:`Eternal`}),(0,J.jsx)(`option`,{value:`eternal-parallel`,children:`Eternal Parallel`})]})]}),(0,J.jsx)(Pp,{label:`YOLO mode`,title:`Bypass tool confirmation prompts`,value:S.yolo,onChange:()=>C(`yolo`,!S.yolo)}),(0,J.jsx)(Pp,{label:`Refine prompts`,title:`Rewrite prompts before sending`,value:S.enhanceEnabled,onChange:()=>C(`enhanceEnabled`,!S.enhanceEnabled)}),(0,J.jsx)(Pp,{label:`Sound on completion`,title:`Play a soft chime when a run finishes`,value:s,onChange:()=>{let e=!G.getState().soundOnComplete;G.getState().setSoundOnComplete(e),e&&ja()}})]}),(0,J.jsxs)(`div`,{className:`px-4 py-2.5`,children:[(0,J.jsxs)(`div`,{className:X(`flex items-center gap-2 text-[11px]`,r?`text-[hsl(var(--success))]`:`text-[hsl(var(--warning))]`),children:[r?(0,J.jsx)(On,{className:`h-3.5 w-3.5`}):(0,J.jsx)(an,{className:`h-3.5 w-3.5`}),(0,J.jsx)(`span`,{className:`font-medium`,children:r?`Connected`:`Disconnected`}),(0,J.jsx)(`span`,{className:`text-muted-foreground font-mono truncate ml-auto`,title:i,children:i})]}),c&&(0,J.jsxs)(`div`,{className:`text-[10px] text-muted-foreground font-mono mt-1 truncate`,title:c.id,children:[`session `,c.id.slice(0,8)]})]}),(0,J.jsx)(ku,{open:w,onClose:()=>T(!1)})]})}var Ip={project:`Project`,user:`Global`,bundled:`Bundled`};function Lp({source:e}){let t=`bundled`;return e===`project`?t=`project`:e===`user`&&(t=`user`),(0,J.jsx)(`span`,{className:X(`inline-flex items-center px-1.5 py-0.5 rounded text-[9px] font-semibold uppercase tracking-wide`,t===`project`&&`bg-emerald-100 text-emerald-700 dark:bg-emerald-950 dark:text-emerald-400`,t===`user`&&`bg-violet-100 text-violet-700 dark:bg-violet-950 dark:text-violet-400`,t===`bundled`&&`bg-slate-100 text-slate-600 dark:bg-slate-800 dark:text-slate-400`),children:Ip[t]??t})}function Rp({className:e}){let{client:t}=Q(),n=q(e=>e.skillsState),r=q(e=>e.setSkillsState),i=q(e=>e.setCurrentView),[a,o]=(0,H.useState)([]),[s,c]=(0,H.useState)(!1),[l,u]=(0,H.useState)(`all`),[d,f]=(0,H.useState)(``),m=(0,H.useRef)(n);m.current=n;let[h,g]=(0,H.useState)(!1),[_,v]=(0,H.useState)(``),[y,x]=(0,H.useState)(!1),[S,C]=(0,H.useState)(!1),[w,T]=(0,H.useState)(null),[E,D]=(0,H.useState)(null),[O,k]=(0,H.useState)(!1),[A,j]=(0,H.useState)(``),[M,N]=(0,H.useState)(``),[P,F]=(0,H.useState)(`project`),[I,ee]=(0,H.useState)(!1),[te,L]=(0,H.useState)(null),[ne,re]=(0,H.useState)(null),[ie,ae]=(0,H.useState)(!1),[oe,se]=(0,H.useState)(!1),ce=(0,H.useCallback)(async()=>{if(!t||!_.trim())return;C(!0),T(null),D(null);let e=n=>{let r=n;C(!1),r.payload.success?(D(`Installed: ${r.payload.results?.map(e=>e.name).join(`, `)??_}`),t.send({type:`skills.list`})):T(r.payload.error??`Installation failed`),t.off(`skills.installed`,e)};t.on(`skills.installed`,e),t.installSkill(_.trim(),y)},[t,_,y]),le=(0,H.useCallback)(()=>{if(!t||!A.trim()||!M.trim())return;ee(!0),L(null),re(null);let e=n=>{let r=n;ee(!1),r.payload.success?(re(`Created: ${r.payload.skill?.name}`),t.send({type:`skills.list`})):L(r.payload.error??`Creation failed`),t.off(`skills.created`,e)};t.on(`skills.created`,e),t.createSkill(A.trim(),M.trim(),P)},[t,A,M,P]),ue=(0,H.useCallback)(()=>{t&&(se(!0),t.checkForUpdates(void 0,void 0))},[t]),de=(0,H.useCallback)(()=>{if(!t)return;ae(!0);let e=n=>{let r=n;if(ae(!1),r.payload.error)console.error(`[skills.export]`,r.payload.error);else{let e=atob(r.payload.zipBase64),t=new Uint8Array(e.length);for(let n=0;n<e.length;n++)t[n]=e.charCodeAt(n);let n=new Blob([t],{type:`application/zip`}),i=URL.createObjectURL(n),a=document.createElement(`a`);a.href=i,a.download=`wrongstack-skills-${Date.now()}.zip`,document.body.appendChild(a),a.click(),document.body.removeChild(a),URL.revokeObjectURL(i)}t.off(`skills.exported`,e)};t.on(`skills.exported`,e),t.exportAllSkills()},[t]);(0,H.useEffect)(()=>{if(!t)return;c(!0);let e=e=>{let t=e;if(t.payload.enabled&&t.payload.skills){o(t.payload.skills);let e=m.current,n=e.knownRefs,i=0,a={...n};for(let e of t.payload.skills){if(e.source===`bundled`)continue;let t=e.ref;if(!t)continue;let r=n[e.name];a[e.name]=t,r&&r!==t&&i++}r({...e,knownRefs:a,updateAvailableCount:i})}c(!1)},n=e=>{let n=e;if(se(!1),n.payload.success){let e=m.current,i={...e.knownRefs};for(let e of n.payload.updated??[])i[e.name]=e.newRef;r({...e,knownRefs:i,updateAvailableCount:0}),t.send({type:`skills.list`})}};return t.on(`skills.list`,e),t.on(`skills.updated`,n),t.send({type:`skills.list`}),()=>{t.off(`skills.list`,e),t.off(`skills.updated`,n)}},[t,r]);let R=(0,H.useCallback)(e=>{r({...m.current,selectedSkill:e,navHistory:[e],historyIndex:0,detailOpen:!0}),i(`skill`)},[r,i]),fe=(0,H.useMemo)(()=>{let e=a;if(l!==`all`&&(e=e.filter(e=>e.source===l)),d.trim()){let t=d.toLowerCase();e=e.filter(e=>e.name.toLowerCase().includes(t)||e.description.toLowerCase().includes(t)||e.trigger.toLowerCase().includes(t))}return e},[a,l,d]),pe=(0,H.useMemo)(()=>{let e={project:[],user:[],bundled:[]};for(let t of fe){let n=t.source||`bundled`;e[n]?e[n].push(t):e.bundled.push(t)}return e},[fe]),me=n.selectedSkill?.name;return(0,J.jsxs)(`div`,{className:X(`flex flex-col h-full overflow-hidden`,e),children:[(0,J.jsxs)(`div`,{className:`w-full border-b flex items-center gap-1 px-2 py-2`,children:[(0,J.jsx)(`button`,{type:`button`,onClick:()=>{v(``),T(null),D(null),x(!1),g(!0)},className:`flex items-center justify-center w-8 h-8 rounded-lg text-muted-foreground hover:text-foreground hover:bg-accent transition-colors`,title:`Install skill`,children:(0,J.jsx)(tr,{className:`h-4 w-4`})}),(0,J.jsx)(`button`,{type:`button`,onClick:()=>{j(``),N(``),F(`project`),L(null),re(null),k(!0)},className:`flex items-center justify-center w-8 h-8 rounded-lg text-muted-foreground hover:text-foreground hover:bg-accent transition-colors`,title:`Create skill`,children:(0,J.jsx)(zt,{className:`h-4 w-4`})}),(0,J.jsx)(`button`,{type:`button`,onClick:de,disabled:ie||a.length===0,className:`flex items-center justify-center w-8 h-8 rounded-lg text-muted-foreground hover:text-foreground hover:bg-accent transition-colors disabled:opacity-40`,title:`Export all skills as .zip`,children:ie?(0,J.jsx)(z,{className:`h-4 w-4 animate-spin`}):(0,J.jsx)(b,{className:`h-4 w-4`})}),(0,J.jsxs)(`button`,{type:`button`,onClick:ue,disabled:oe,className:`flex items-center justify-center w-8 h-8 rounded-lg text-muted-foreground hover:text-foreground hover:bg-accent transition-colors disabled:opacity-40 relative`,title:`Check for updates (all skills)`,children:[oe?(0,J.jsx)(z,{className:`h-4 w-4 animate-spin`}):(0,J.jsx)(Ct,{className:`h-4 w-4`}),!oe&&n.updateAvailableCount>0&&(0,J.jsx)(`span`,{className:`absolute top-0.5 right-0.5 h-2.5 w-2.5 rounded-full bg-primary text-[8px] font-bold text-primary-foreground flex items-center justify-center`,children:n.updateAvailableCount>9?`9+`:n.updateAvailableCount})]})]}),(0,J.jsxs)(`div`,{className:`p-2 space-y-2 border-b shrink-0`,children:[(0,J.jsx)(`input`,{type:`text`,value:d,onChange:e=>f(e.target.value),placeholder:`Search skills…`,className:`w-full px-2 py-1.5 text-xs rounded border border-border bg-background focus:outline-none focus:ring-1 focus:ring-ring`}),(0,J.jsx)(`div`,{className:`flex gap-1 flex-wrap`,children:[`all`,`project`,`user`,`bundled`].map(e=>{let t=e===`all`?fe.length:fe.filter(t=>t.source===e).length;return(0,J.jsxs)(`button`,{type:`button`,onClick:()=>u(e),className:X(`px-1.5 py-0.5 text-[10px] rounded transition-colors`,l===e?`bg-primary text-primary-foreground`:`bg-muted text-muted-foreground hover:bg-accent`),children:[e===`all`?`All`:Ip[e],(0,J.jsxs)(`span`,{className:X(`ml-1 font-medium`,l===e?`opacity-90`:`opacity-60`,t===0&&`line-through`),children:[`(`,t,`)`]})]},e)})})]}),(0,J.jsx)(`div`,{className:`flex-1 overflow-y-auto`,children:s?(0,J.jsx)(`div`,{className:`p-4 text-xs text-muted-foreground text-center`,children:`Loading…`}):fe.length===0?(0,J.jsx)(`div`,{className:`p-4 text-xs text-muted-foreground text-center`,children:a.length===0?`No skills installed`:`No skills match filter`}):(0,J.jsx)(`div`,{className:`py-1`,children:[`project`,`user`,`bundled`].map(e=>{let t=pe[e];return t.length===0?null:(0,J.jsxs)(`div`,{children:[(0,J.jsxs)(`div`,{className:`px-2 py-1 text-[10px] font-semibold text-muted-foreground uppercase tracking-wide flex items-center gap-1`,children:[(0,J.jsx)(Lp,{source:e}),(0,J.jsx)(`span`,{className:`ml-auto opacity-60`,children:t.length})]}),t.map(e=>(0,J.jsxs)(`button`,{type:`button`,onClick:()=>R(e),className:X(`w-full text-left px-2 py-1.5 text-xs transition-colors`,me===e.name?`bg-primary/10 text-primary`:`hover:bg-accent/50 text-foreground`),children:[(0,J.jsxs)(`div`,{className:`font-medium truncate flex items-center gap-1`,children:[(0,J.jsx)(p,{className:`h-3 w-3 shrink-0`}),e.name]}),(0,J.jsx)(`div`,{className:`text-[10px] text-muted-foreground truncate mt-0.5`,children:e.trigger||e.description?.slice(0,50)||`No description`})]},e.name))]},e)})})}),h&&(0,J.jsx)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/40`,onClick:e=>{e.target===e.currentTarget&&g(!1)},children:(0,J.jsxs)(`div`,{className:`bg-background rounded-lg border shadow-xl w-[420px] max-w-[90vw]`,children:[(0,J.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-b`,children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,J.jsx)(b,{className:`h-4 w-4 text-primary`}),(0,J.jsx)(`span`,{className:`font-semibold text-sm`,children:`Install Skill`})]}),(0,J.jsx)(`button`,{type:`button`,onClick:()=>g(!1),className:`p-1 rounded hover:bg-accent text-muted-foreground cursor-pointer`,children:`✕`})]}),(0,J.jsxs)(`div`,{className:`p-4 space-y-3`,children:[(0,J.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[`Enter a GitHub repository reference (`,(0,J.jsx)(`span`,{className:`font-mono text-[10px]`,children:`owner/repo`}),`) or full URL.`]}),(0,J.jsx)(`input`,{type:`text`,value:_,onChange:e=>{v(e.target.value),T(null),D(null)},onKeyDown:e=>{e.key===`Enter`&&!S&&ce()},placeholder:`e.g. wrongstack/skill-name or https://github.com/owner/repo`,className:`w-full px-3 py-2 text-xs rounded border border-border bg-background focus:outline-none focus:ring-1 focus:ring-ring`,autoFocus:!0}),(0,J.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,J.jsx)(`label`,{className:`text-xs text-muted-foreground`,children:`Install scope:`}),(0,J.jsxs)(`div`,{className:`flex rounded border border-border overflow-hidden`,children:[(0,J.jsx)(`button`,{type:`button`,onClick:()=>x(!1),className:X(`px-2 py-1 text-[10px] transition-colors`,y?`bg-background hover:bg-accent`:`bg-primary text-primary-foreground`),children:`Project`}),(0,J.jsx)(`button`,{type:`button`,onClick:()=>x(!0),className:X(`px-2 py-1 text-[10px] transition-colors border-l border-border`,y?`bg-primary text-primary-foreground`:`bg-background hover:bg-accent`),children:`Global`})]})]}),w&&(0,J.jsx)(`p`,{className:`text-xs text-destructive bg-destructive/10 rounded px-2 py-1`,children:w}),E&&(0,J.jsx)(`p`,{className:`text-xs text-emerald-600 dark:text-emerald-400 bg-emerald-500/10 rounded px-2 py-1`,children:E})]}),(0,J.jsxs)(`div`,{className:`flex justify-end gap-2 p-4 border-t bg-muted/20`,children:[(0,J.jsx)(`button`,{type:`button`,onClick:()=>g(!1),className:`px-3 py-1.5 text-xs rounded border border-border hover:bg-accent transition-colors`,children:E?`Close`:`Cancel`}),!E&&(0,J.jsxs)(`button`,{type:`button`,onClick:ce,disabled:S||!_.trim(),className:`flex items-center gap-1.5 px-3 py-1.5 text-xs rounded bg-primary text-primary-foreground hover:bg-primary/90 disabled:opacity-50 disabled:cursor-not-allowed transition-colors`,children:[S&&(0,J.jsx)(z,{className:`h-3 w-3 animate-spin`}),`Install`]})]})]})}),O&&(0,J.jsx)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/40`,onClick:e=>{e.target===e.currentTarget&&k(!1)},children:(0,J.jsxs)(`div`,{className:`bg-background rounded-lg border shadow-xl w-[480px] max-w-[90vw]`,children:[(0,J.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-b`,children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,J.jsx)(zt,{className:`h-4 w-4 text-primary`}),(0,J.jsx)(`span`,{className:`font-semibold text-sm`,children:`Create Skill`})]}),(0,J.jsx)(`button`,{type:`button`,onClick:()=>k(!1),className:`p-1 rounded hover:bg-accent text-muted-foreground cursor-pointer`,children:`✕`})]}),(0,J.jsxs)(`div`,{className:`p-4 space-y-3`,children:[(0,J.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Scaffold a new skill. The first line is the trigger; additional lines form the description.`}),(0,J.jsxs)(`div`,{children:[(0,J.jsxs)(`label`,{className:`block text-xs font-medium mb-1`,children:[`Name `,(0,J.jsx)(`span`,{className:`text-destructive`,children:`*`})]}),(0,J.jsx)(`input`,{type:`text`,value:A,onChange:e=>{j(e.target.value.trim().toLowerCase().replace(/\s+/g,`-`).replace(/[^a-z0-9-]/g,``)),L(null),re(null)},placeholder:`e.g. my-new-skill`,className:`w-full px-3 py-2 text-xs rounded border border-border bg-background focus:outline-none focus:ring-1 focus:ring-ring font-mono`,autoFocus:!0})]}),(0,J.jsxs)(`div`,{children:[(0,J.jsxs)(`label`,{className:`block text-xs font-medium mb-1`,children:[`Description / Trigger `,(0,J.jsx)(`span`,{className:`text-destructive`,children:`*`})]}),(0,J.jsx)(`textarea`,{value:M,onChange:e=>{N(e.target.value),L(null),re(null)},onKeyDown:e=>{e.key===`Enter`&&(e.metaKey||e.ctrlKey)&&!I&&le()},placeholder:`Use this skill when <trigger situation>.
|
|
136
|
-
Triggers: user says "keyword", "another".`,rows:4,className:`w-full px-3 py-2 text-xs rounded border border-border bg-background focus:outline-none focus:ring-1 focus:ring-ring resize-y`})]}),(0,J.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,J.jsx)(`label`,{className:`text-xs text-muted-foreground`,children:`Save in:`}),(0,J.jsxs)(`div`,{className:`flex rounded border border-border overflow-hidden`,children:[(0,J.jsx)(`button`,{type:`button`,onClick:()=>F(`project`),className:X(`px-2 py-1 text-[10px] transition-colors`,P===`project`?`bg-primary text-primary-foreground`:`bg-background hover:bg-accent`),children:`Project`}),(0,J.jsx)(`button`,{type:`button`,onClick:()=>F(`global`),className:X(`px-2 py-1 text-[10px] transition-colors border-l border-border`,P===`global`?`bg-primary text-primary-foreground`:`bg-background hover:bg-accent`),children:`Global`})]})]}),te&&(0,J.jsx)(`p`,{className:`text-xs text-destructive bg-destructive/10 rounded px-2 py-1`,children:te}),ne&&(0,J.jsx)(`p`,{className:`text-xs text-emerald-600 dark:text-emerald-400 bg-emerald-500/10 rounded px-2 py-1`,children:ne})]}),(0,J.jsxs)(`div`,{className:`flex justify-end gap-2 p-4 border-t bg-muted/20`,children:[(0,J.jsx)(`button`,{type:`button`,onClick:()=>k(!1),className:`px-3 py-1.5 text-xs rounded border border-border hover:bg-accent transition-colors`,children:ne?`Close`:`Cancel`}),!ne&&(0,J.jsxs)(`button`,{type:`button`,onClick:le,disabled:I||!A.trim()||!M.trim(),className:`flex items-center gap-1.5 px-3 py-1.5 text-xs rounded bg-primary text-primary-foreground hover:bg-primary/90 disabled:opacity-50 disabled:cursor-not-allowed transition-colors`,children:[I&&(0,J.jsx)(z,{className:`h-3 w-3 animate-spin`}),`Create Skill`]})]})]})})]})}var zp=[`web`,`react-native`,`flutter`,`swiftui`,`compose`],Bp=[`bg`,`surface`,`primary`,`accent`,`fg`,`border`];function Vp({tokens:e,label:t}){let n=Bp.filter(t=>e[t]);return n.length===0?null:(0,J.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,J.jsx)(`span`,{className:`text-[9px] uppercase tracking-wide text-muted-foreground w-7`,children:t}),(0,J.jsx)(`div`,{className:`flex gap-0.5`,children:n.map(t=>(0,J.jsx)(`div`,{className:`w-4 h-4 rounded-sm border border-black/10 dark:border-white/10`,style:{backgroundColor:e[t]},title:`${t}: ${e[t]}`},t))})]})}function Hp({className:e}){let{client:t}=Q(),n=q(e=>e.setCurrentView),[r,a]=(0,H.useState)([]),[o,s]=(0,H.useState)(null),[c,l]=(0,H.useState)(!0),[u,d]=(0,H.useState)(`web`),[f,p]=(0,H.useState)(null);(0,H.useEffect)(()=>{if(!t)return;let e=e=>{let t=e.payload;a(t?.kits??[]),s(t?.activeKit??null),l(!1)},n=e=>{let t=e.payload;p(null),t?.ok&&t.kit&&s(t.kit)};return t.on(`design.list`,e),t.on(`design.use`,n),t.send({type:`design.list`}),()=>{t.off(`design.list`,e),t.off(`design.use`,n)}},[t]);let m=(0,H.useCallback)(e=>{t&&(p(e),t.send({type:`design.use`,payload:{kit:e,stack:u}}))},[t,u]),h=(0,H.useMemo)(()=>[...r].sort((e,t)=>e.name.localeCompare(t.name)),[r]);return(0,J.jsxs)(`div`,{className:X(`flex flex-col h-full`,e),children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-2 px-3 py-2 border-b border-border/50`,children:[(0,J.jsx)(vt,{className:`w-4 h-4 text-muted-foreground`}),(0,J.jsx)(`span`,{className:`text-xs text-muted-foreground flex-1`,children:`Pick a kit — the agent will adhere to it.`}),(0,J.jsxs)(`button`,{type:`button`,onClick:()=>n(`design-gallery`),className:`inline-flex items-center gap-1 text-[11px] px-1.5 py-0.5 rounded border border-border/60 hover:bg-muted`,title:`Open live preview gallery`,children:[(0,J.jsx)(Pr,{className:`w-3 h-3`}),` Gallery`]}),(0,J.jsx)(`select`,{value:u,onChange:e=>d(e.target.value),className:`text-[11px] bg-transparent border border-border/60 rounded px-1 py-0.5`,title:`Target stack`,children:zp.map(e=>(0,J.jsx)(`option`,{value:e,children:e},e))})]}),(0,J.jsxs)(`div`,{className:`flex-1 overflow-y-auto p-2 space-y-2`,children:[c&&(0,J.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-muted-foreground p-3`,children:[(0,J.jsx)(z,{className:`w-4 h-4 animate-spin`}),` Loading kits…`]}),!c&&h.length===0&&(0,J.jsx)(`p`,{className:`text-sm text-muted-foreground p-3`,children:`No design kits found.`}),h.map(e=>{let t=o===e.id;return(0,J.jsxs)(`div`,{className:X(`rounded-lg border p-3 transition-colors`,t?`border-primary/60 bg-primary/5`:`border-border/60 hover:border-border`),children:[(0,J.jsxs)(`div`,{className:`flex items-start justify-between gap-2`,children:[(0,J.jsxs)(`div`,{className:`min-w-0`,children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,J.jsx)(`h3`,{className:`text-sm font-semibold truncate`,children:e.name}),t&&(0,J.jsxs)(`span`,{className:`inline-flex items-center gap-0.5 text-[9px] font-semibold uppercase text-primary`,children:[(0,J.jsx)(i,{className:`w-3 h-3`}),` Active`]})]}),(0,J.jsx)(`p`,{className:`text-[11px] text-muted-foreground leading-snug mt-0.5`,children:e.aesthetic})]}),(0,J.jsx)(`button`,{type:`button`,onClick:()=>m(e.id),disabled:f===e.id,className:X(`shrink-0 text-[11px] px-2 py-1 rounded font-medium`,t?`bg-primary/10 text-primary`:`bg-primary text-primary-foreground hover:opacity-90`),children:f===e.id?`…`:t?`Reapply`:`Use`})]}),(0,J.jsxs)(`div`,{className:`mt-2 space-y-1`,children:[(0,J.jsx)(Vp,{tokens:e.light,label:`Light`}),(0,J.jsx)(Vp,{tokens:e.dark,label:`Dark`})]}),e.bestFor&&(0,J.jsxs)(`p`,{className:`text-[10px] text-muted-foreground mt-2 leading-snug`,children:[(0,J.jsx)(`span`,{className:`font-medium`,children:`Best for:`}),` `,e.bestFor]}),(0,J.jsx)(`div`,{className:`flex flex-wrap gap-1 mt-1.5`,children:e.stacks.map(e=>(0,J.jsx)(`span`,{className:`text-[9px] px-1 py-0.5 rounded bg-muted text-muted-foreground`,children:e},e))})]},e.id)})]})]})}var Up=e=>e?e.replace(/^wstack\/ap\//,``):`(detached)`,Wp=new Set([`allocating`,`active`,`committing`,`merging`]),Gp={active:`text-amber-500`,committing:`text-cyan-500`,merging:`text-blue-500`,merged:`text-emerald-500`,"needs-review":`text-fuchsia-500`,failed:`text-rose-500`,orphan:`text-zinc-400`};function Kp(){let{client:e}=Q(),t=Si(e=>e.worktrees),n=Si(e=>e.orphans),i=Si(e=>e.baseBranch),a=Si(e=>e.canClean),o=Si(e=>e.cleanResult),s=Si(e=>e.mergeResult),c=Si(e=>e.diffByDir),[u,d]=(0,H.useState)(null),[f,p]=(0,H.useState)(null),m=e?.send;(0,H.useEffect)(()=>{m?.({type:`worktree.scan`})},[m]),(0,H.useEffect)(()=>{d(null)},[s,o]);let h=(0,H.useMemo)(()=>{let e=new Set(t.map(e=>e.branch)),r=t.map(e=>({branch:e.branch,dir:e.dir,status:e.status,baseBranch:e.baseBranch,insertions:e.insertions,deletions:e.deletions,files:e.files,owner:e.ownerLabel,live:Wp.has(e.status)}));for(let t of n)t.branch&&e.has(t.branch)||r.push({branch:t.branch,dir:t.dir,status:`orphan`,insertions:0,deletions:0,files:0,live:!1});return r},[t,n]),g=(e,t)=>{e&&m?.({type:`shell.open`,payload:{path:e,target:t}})},_=e=>{e&&(m?.({type:`worktree.diff`,payload:{dir:e}}),p(t=>t===e?null:e))},v=async e=>{e&&await vc({title:`Merge ${Up(e)} into ${i||`base`}?`,message:`Squash-merges this branch onto the base branch. Aborts cleanly if it conflicts.`,confirmLabel:`Merge`})&&(d(e),m?.({type:`worktree.merge`,payload:{branch:e}}))},y=async e=>{await vc({title:`Remove ${Up(e.branch)}?`,message:`Force-removes the worktree checkout and deletes its branch. Un-merged work is discarded.`,confirmLabel:`Remove`,danger:!0})&&(d(e.branch??``),m?.({type:`worktree.remove`,payload:{dir:e.dir,branch:e.branch}}))};return(0,J.jsxs)(`div`,{className:`flex h-full flex-col`,children:[(0,J.jsxs)(`div`,{className:`flex items-center justify-between gap-2 px-3 py-2`,children:[(0,J.jsxs)(`span`,{className:`text-[11px] text-muted-foreground`,children:[h.length,` worktree`,h.length===1?``:`s`,i?` · base ${i}`:``]}),(0,J.jsxs)(`div`,{className:`flex items-center gap-1`,children:[n.length>0&&(0,J.jsxs)(`button`,{type:`button`,disabled:!a,onClick:()=>m?.({type:`worktree.cleanup`}),title:a?`Remove all orphaned worktrees`:`A run is live — stop it first`,className:`inline-flex items-center gap-1 rounded bg-amber-600/90 px-1.5 py-0.5 text-[11px] font-medium text-white hover:bg-amber-700 disabled:opacity-50`,children:[(0,J.jsx)(We,{className:`h-3 w-3`}),` Clean orphans`]}),(0,J.jsx)(`button`,{type:`button`,onClick:()=>m?.({type:`worktree.scan`}),title:`Rescan`,className:`rounded p-1 text-muted-foreground hover:bg-muted hover:text-foreground`,children:(0,J.jsx)(Ct,{className:`h-3.5 w-3.5`})})]})]}),o&&(0,J.jsx)(Jp,{ok:o.ok,children:o.ok?`Removed ${o.removed} worktree(s).`:o.reason??`Failed`}),s&&(0,J.jsx)(Jp,{ok:s.ok,children:s.ok?`Merged ${Up(s.branch)} into base.`:s.conflict?`Conflict merging ${Up(s.branch)}: ${(s.conflictFiles??[]).join(`, `)||`see git`}`:`Merge failed: ${s.reason??`unknown`}`}),(0,J.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto px-2 pb-3`,children:h.length===0?(0,J.jsxs)(`div`,{className:`flex h-full flex-col items-center justify-center gap-2 text-center text-xs text-muted-foreground`,children:[(0,J.jsx)(r,{className:`h-8 w-8 opacity-30`}),(0,J.jsx)(`p`,{children:`No worktrees.`}),(0,J.jsx)(`p`,{className:`max-w-[200px]`,children:`SDD / AutoPhase runs create isolated worktrees here. Orphans from crashed runs show up too.`})]}):h.map((e,t)=>{let n=u===(e.branch??``),i=e.dir?c[e.dir]:void 0;return(0,J.jsxs)(`div`,{className:`mb-1.5 rounded-md border border-border bg-card/60 px-2.5 py-2`,children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,J.jsx)(r,{className:X(`h-3.5 w-3.5 shrink-0`,Gp[e.status]??`text-muted-foreground`)}),(0,J.jsx)(`span`,{className:`min-w-0 flex-1 truncate font-mono text-xs text-foreground`,title:e.branch,children:Up(e.branch)}),(0,J.jsx)(`span`,{className:X(`shrink-0 text-[10px] uppercase`,Gp[e.status]??`text-muted-foreground`),children:e.status})]}),(0,J.jsxs)(`div`,{className:`mt-0.5 flex items-center gap-2 pl-5 text-[10px] text-muted-foreground`,children:[e.owner&&(0,J.jsx)(`span`,{className:`truncate`,children:e.owner}),(e.insertions>0||e.deletions>0)&&(0,J.jsxs)(`span`,{className:`shrink-0`,children:[(0,J.jsxs)(`span`,{className:`text-emerald-500`,children:[`+`,e.insertions]}),` `,(0,J.jsxs)(`span`,{className:`text-rose-500`,children:[`−`,e.deletions]}),` · `,e.files,`f`]})]}),(0,J.jsxs)(`div`,{className:`mt-1.5 flex items-center gap-0.5 pl-5`,children:[(0,J.jsx)(qp,{title:`Open in terminal`,disabled:!e.dir,onClick:()=>g(e.dir,`terminal`),children:(0,J.jsx)(l,{className:`h-3.5 w-3.5`})}),(0,J.jsx)(qp,{title:`Open folder`,disabled:!e.dir,onClick:()=>g(e.dir,`file-manager`),children:(0,J.jsx)(wt,{className:`h-3.5 w-3.5`})}),(0,J.jsx)(qp,{title:`View changes`,disabled:!e.dir,onClick:()=>_(e.dir),children:(0,J.jsx)(Be,{className:`h-3.5 w-3.5`})}),(0,J.jsx)(qp,{title:`Merge to base`,disabled:e.live||!e.branch,onClick:()=>v(e.branch),children:n?(0,J.jsx)(z,{className:`h-3.5 w-3.5 animate-spin`}):(0,J.jsx)(pt,{className:`h-3.5 w-3.5`})}),(0,J.jsx)(qp,{title:`Remove / discard`,danger:!0,disabled:e.live,onClick:()=>y(e),children:(0,J.jsx)(Te,{className:`h-3.5 w-3.5`})}),e.live&&(0,J.jsx)(`span`,{className:`ml-1 text-[10px] text-amber-500`,children:`live`})]}),f===e.dir&&i!==void 0&&(0,J.jsx)(`div`,{className:`mt-1.5 ml-5 rounded bg-muted/50 p-1.5 text-[10px]`,children:i===null||i.files.length===0?(0,J.jsxs)(`span`,{className:`text-muted-foreground`,children:[`No uncommitted changes`,i&&i.commits>0?` · ${i.commits} commit(s) ahead`:``,`.`]}):(0,J.jsxs)(J.Fragment,{children:[(0,J.jsxs)(`div`,{className:`mb-1 text-muted-foreground`,children:[i.commits>0?`${i.commits} commit(s) ahead · `:``,(0,J.jsxs)(`span`,{className:`text-emerald-500`,children:[`+`,i.insertions]}),` `,(0,J.jsxs)(`span`,{className:`text-rose-500`,children:[`−`,i.deletions]})]}),i.files.slice(0,12).map(e=>(0,J.jsxs)(`div`,{className:`truncate font-mono`,children:[(0,J.jsxs)(`span`,{className:`text-emerald-500`,children:[`+`,e.insertions]}),` `,(0,J.jsxs)(`span`,{className:`text-rose-500`,children:[`−`,e.deletions]}),` `,e.path]},e.path)),i.files.length>12&&(0,J.jsxs)(`div`,{className:`text-muted-foreground`,children:[`…`,i.files.length-12,` more`]})]})})]},`${e.branch??e.dir??t}`)})})]})}function qp({title:e,onClick:t,disabled:n,danger:r,children:i}){return(0,J.jsx)(`button`,{type:`button`,title:e,disabled:n,onClick:t,className:X(`rounded p-1 text-muted-foreground hover:bg-muted disabled:cursor-not-allowed disabled:opacity-30`,r?`hover:text-rose-500`:`hover:text-foreground`),children:i})}function Jp({ok:e,children:t}){return(0,J.jsxs)(`div`,{className:X(`flex items-start gap-1.5 border-y px-3 py-1.5 text-[11px]`,e?`border-emerald-500/30 bg-emerald-500/5 text-emerald-600 dark:text-emerald-300`:`border-amber-500/30 bg-amber-500/5 text-amber-600 dark:text-amber-300`),children:[e?(0,J.jsx)(M,{className:`mt-0.5 h-3.5 w-3.5 shrink-0`}):(0,J.jsx)(Ge,{className:`mt-0.5 h-3.5 w-3.5 shrink-0`}),(0,J.jsx)(`span`,{className:`min-w-0 flex-1`,children:t}),!e&&(0,J.jsx)(I,{className:`mt-0.5 h-3 w-3 shrink-0 opacity-40`})]})}function Yp({label:e,checked:t,onChange:n}){return(0,J.jsxs)(`button`,{type:`button`,onClick:()=>n(!t),className:`flex w-full items-center justify-between px-2 py-1.5 rounded text-xs hover:bg-accent/50 transition-colors`,children:[(0,J.jsx)(`span`,{className:`text-foreground`,children:e}),(0,J.jsx)(`span`,{className:X(`relative inline-flex h-4 w-7 shrink-0 items-center rounded-full transition-colors`,t?`bg-primary`:`bg-muted`),children:(0,J.jsx)(`span`,{className:X(`inline-block h-3 w-3 transform rounded-full bg-background transition-transform`,t?`translate-x-3.5`:`translate-x-0.5`)})})]})}var Xp=[{value:`dots`,label:`Dots`},{value:`lines`,label:`Lines`},{value:`cross`,label:`Cross`},{value:`none`,label:`None`}];function Zp(){let{showHud:e,showLegend:t,showMinimap:n,showControls:r,animateEdges:i,background:a,setShowHud:o,setShowLegend:s,setShowMinimap:c,setShowControls:l,setAnimateEdges:u,setBackground:d}=xa(),{clientCounts:f,currentSession:p,totalAgents:m,activeAgents:h}=da(),g=f.tui+f.webui+f.repl;return(0,J.jsxs)(`div`,{className:`flex flex-col h-full overflow-y-auto p-3 gap-4`,children:[(0,J.jsxs)(`div`,{children:[(0,J.jsx)(`div`,{className:`text-[10px] font-semibold text-muted-foreground uppercase tracking-wide mb-2`,children:`Live`}),(0,J.jsxs)(`div`,{className:`space-y-1.5 text-xs`,children:[(0,J.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,J.jsxs)(`span`,{className:`flex items-center gap-1.5 text-muted-foreground`,children:[(0,J.jsx)(Mr,{className:`h-3.5 w-3.5`}),` Clients`]}),(0,J.jsx)(`span`,{className:`font-mono`,children:g})]}),(0,J.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,J.jsxs)(`span`,{className:`flex items-center gap-1.5 text-muted-foreground`,children:[(0,J.jsx)(Yn,{className:`h-3.5 w-3.5`}),` Agents`]}),(0,J.jsxs)(`span`,{className:`font-mono`,children:[h,(0,J.jsxs)(`span`,{className:`text-muted-foreground`,children:[` / `,m]})]})]}),p.model&&(0,J.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,J.jsxs)(`span`,{className:`flex items-center gap-1.5 text-muted-foreground`,children:[(0,J.jsx)(_e,{className:`h-3.5 w-3.5`}),` Model`]}),(0,J.jsx)(`span`,{className:`font-mono truncate max-w-[140px]`,title:p.model,children:p.model.split(`/`).pop()})]}),p.mode&&(0,J.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,J.jsxs)(`span`,{className:`flex items-center gap-1.5 text-muted-foreground`,children:[(0,J.jsx)(Bt,{className:`h-3.5 w-3.5`}),` Mode`]}),(0,J.jsx)(`span`,{className:`font-mono uppercase text-[10px]`,children:p.mode})]}),(0,J.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,J.jsxs)(`span`,{className:`flex items-center gap-1.5 text-muted-foreground`,children:[(0,J.jsx)(_t,{className:`h-3.5 w-3.5`}),` Tool calls`]}),(0,J.jsx)(`span`,{className:`font-mono`,children:(e=>e?.toLocaleString()??`0`)(p.toolCalls)})]})]})]}),(0,J.jsxs)(`div`,{children:[(0,J.jsx)(`div`,{className:`text-[10px] font-semibold text-muted-foreground uppercase tracking-wide mb-1`,children:`Display`}),(0,J.jsxs)(`div`,{className:`space-y-0.5`,children:[(0,J.jsx)(Yp,{label:`Stats HUD`,checked:e,onChange:o}),(0,J.jsx)(Yp,{label:`Legends`,checked:t,onChange:s}),(0,J.jsx)(Yp,{label:`Minimap`,checked:n,onChange:c}),(0,J.jsx)(Yp,{label:`Zoom controls`,checked:r,onChange:l}),(0,J.jsx)(Yp,{label:`Animate wires`,checked:i,onChange:u})]})]}),(0,J.jsxs)(`div`,{children:[(0,J.jsx)(`div`,{className:`text-[10px] font-semibold text-muted-foreground uppercase tracking-wide mb-1.5 px-2`,children:`Background`}),(0,J.jsx)(`div`,{className:`flex flex-wrap gap-1 px-2`,children:Xp.map(e=>(0,J.jsx)(`button`,{type:`button`,onClick:()=>d(e.value),className:X(`px-2 py-1 text-[10px] rounded transition-colors`,a===e.value?`bg-primary text-primary-foreground`:`bg-muted text-muted-foreground hover:bg-accent`),children:e.label},e.value))})]})]})}var Qp={chat:`Session`,agents:`Agents`,history:`History`,files:`Files`,changes:`Changes`,projects:`Projects`,mailbox:`Mailbox`,skills:`Skills`,design:`Design Studio`,worktrees:`Worktrees`,officemap:`Office Map`};function $p(){let e=q(e=>e.activeActivity),t=q(e=>e.setSidebarOpen),n=q(e=>e.sidebarWidth),r=q(e=>e.setSidebarWidth),i=G(e=>e.wsConnected),{client:a}=Q();return(0,H.useEffect)(()=>{if(e!==`files`||!i)return;Yi.getState().setTreeLoading(!0);let t=K.getState().cwd;a?.send({type:`files.tree`,payload:t?{path:t}:{}})},[e,i,a]),(0,J.jsxs)(`aside`,{style:{width:`${n}px`},className:`relative border-r bg-card flex flex-col shrink-0 overflow-hidden animate-slide-in`,children:[(0,J.jsx)(`div`,{onMouseDown:e=>{e.preventDefault();let t=e.clientX,i=n,a=e=>r(i+(e.clientX-t)),o=()=>{window.removeEventListener(`mousemove`,a),window.removeEventListener(`mouseup`,o),document.body.style.cursor=``,document.body.style.userSelect=``};window.addEventListener(`mousemove`,a),window.addEventListener(`mouseup`,o),document.body.style.cursor=`col-resize`,document.body.style.userSelect=`none`},onDoubleClick:()=>r(304),className:`group/handle absolute top-0 right-0 h-full w-2 cursor-col-resize z-10 flex items-center justify-end`,title:`Drag to resize · double-click to reset`,children:(0,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:`flex items-center justify-between px-3 py-2.5 border-b shrink-0`,children:[(0,J.jsx)(`span`,{className:`text-xs font-semibold tracking-tight text-muted-foreground uppercase`,children:Qp[e]}),(0,J.jsx)($,{variant:`ghost`,size:`icon`,className:`h-6 w-6`,onClick:()=>t(!1),title:`Collapse panel (Ctrl+\\)`,children:(0,J.jsx)(Zt,{className:`h-3.5 w-3.5`})})]}),(0,J.jsxs)(`div`,{className:`flex-1 flex flex-col overflow-hidden`,children:[e===`chat`&&(0,J.jsx)(Fp,{}),e===`agents`&&(0,J.jsx)(bp,{}),e===`history`&&(0,J.jsx)(Op,{}),e===`files`&&(0,J.jsx)(`div`,{className:`flex-1 overflow-y-auto`,children:(0,J.jsx)(Qf,{})}),e===`changes`&&(0,J.jsx)(wp,{}),e===`projects`&&(0,J.jsx)(`div`,{className:`flex-1 overflow-y-auto p-3`,children:(0,J.jsx)(np,{})}),e===`mailbox`&&(0,J.jsx)(`div`,{className:`flex-1 overflow-y-auto p-3`,children:(0,J.jsx)(tp,{})}),e===`skills`&&(0,J.jsx)(`div`,{className:`flex-1 overflow-hidden`,children:(0,J.jsx)(Rp,{className:`h-full`})}),e===`design`&&(0,J.jsx)(`div`,{className:`flex-1 overflow-hidden`,children:(0,J.jsx)(Hp,{className:`h-full`})}),e===`worktrees`&&(0,J.jsx)(`div`,{className:`flex-1 overflow-hidden`,children:(0,J.jsx)(Kp,{})}),e===`officemap`&&(0,J.jsx)(`div`,{className:`flex-1 overflow-hidden`,children:(0,J.jsx)(Zp,{})})]})]})}function em(){let e=vi(e=>e.info),{client:t}=Q(),n=(0,H.useRef)(null),r=(0,H.useCallback)(()=>{t?.getGitInfo?.()},[t]);return(0,H.useEffect)(()=>(r(),n.current=setInterval(r,3e4),()=>{n.current&&clearInterval(n.current)}),[r]),e}function tm({sessionId:e,className:t}){let[n,r]=(0,H.useState)([]),[i,a]=(0,H.useState)(!1),[o,c]=(0,H.useState)(null),[l,u]=(0,H.useState)(null),[d,f]=(0,H.useState)(0),[p,m]=(0,H.useState)(!1),[h,g]=(0,H.useState)(!1),[_,v]=(0,H.useState)(``),[y,b]=(0,H.useState)(``),[x,S]=(0,H.useState)(!1),[w,T]=(0,H.useState)(``),E=U(G(e=>e.wsUrl)),D=W(e=>e.messages).filter(e=>e.role===`tool`&&e.toolResult===void 0&&!!e.toolUseId);(0,H.useEffect)(()=>{let t=[];return t.push(E.on(`collab.state`,t=>{let n=t.payload;n.sessionId===e&&r(n.participants??[])})),t.push(E.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(E.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(E.on(`error`,e=>{let t=e.payload;t.phase===`collab`&&(u(t.message),a(!1))})),t.push(E.on(`collab.annotation.added`,t=>{let n=t.payload;n.sessionId===e&&(n.annotation?.resolved||f(e=>e+1))})),t.push(E.on(`collab.annotation.resolved`,t=>{t.payload.sessionId===e&&f(e=>Math.max(0,e-1))})),t.push(E.on(`collab.pause.granted`,t=>{t.payload.sessionId===e&&m(!0)})),t.push(E.on(`collab.pause.released`,t=>{t.payload.sessionId===e&&m(!1)})),()=>{for(let e of t)e()}},[E,e]);let O=(t=`observer`)=>{u(null),E.send({type:`collab.join`,payload:{sessionId:e,role:t}}),a(!0),c(t)},k=()=>{E.send({type:`collab.request_pause`,payload:{sessionId:e}})},A=()=>{E.send({type:`collab.resume`,payload:{sessionId:e}})},j=()=>{E.send({type:`collab.leave`,payload:{sessionId:e}}),a(!1),r([])},M=t=>{E.send({type:`collab.grant_control`,payload:{sessionId:e,toParticipant:t}})},N=()=>{_&&(E.send({type:`collab.inject_tool`,payload:{sessionId:e,toolUseId:_,content:y,isError:x,reason:w.trim()||`controller injection`}}),g(!1),v(``),b(``),S(!1),T(``))},P=i&&o===`controller`;return n.length===0&&!l?(0,J.jsxs)(`div`,{className:X(`flex items-center gap-2 px-3 py-2 rounded-md border border-dashed border-border bg-card/40`,t),children:[(0,J.jsx)(Mr,{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:()=>O(`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)(fn,{className:`w-3 h-3`}),`observer`]}),(0,J.jsxs)(`button`,{type:`button`,onClick:()=>O(`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)(C,{className:`w-3 h-3`}),`annotator`]}),(0,J.jsxs)(`button`,{type:`button`,onClick:()=>O(`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)(Vn,{className:`w-3 h-3`}),`controller`]})]})]}):l?(0,J.jsxs)(`div`,{className:X(`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: `,l]}),(0,J.jsx)(`button`,{type:`button`,onClick:()=>{u(null),a(!1)},className:`ml-auto text-xs underline text-destructive`,children:`dismiss`})]}):(0,J.jsxs)(`div`,{className:X(`relative 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)(Mr,{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`]}),d>0&&(0,J.jsxs)(`span`,{title:`${d} 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)(C,{className:`w-3 h-3`}),d,` note`,d===1?``:`s`]}),p&&(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)(Vn,{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)(Be,{className:`w-3 h-3`}),e.role,P&&e.role!==`controller`&&(0,J.jsx)(`button`,{type:`button`,onClick:()=>M(e.participantId),title:`Grant control — promote this participant to controller`,className:`ml-0.5 inline-flex items-center rounded hover:bg-emerald-500/20 transition-colors`,children:(0,J.jsx)(Dr,{className:`w-3 h-3`})})]},e.participantId)),n.length>3&&(0,J.jsxs)(`span`,{className:`text-[10px] text-muted-foreground`,children:[`+`,n.length-3]})]}),P&&(0,J.jsxs)(`div`,{className:`ml-auto flex items-center gap-1`,children:[(0,J.jsxs)(`button`,{type:`button`,onClick:()=>g(e=>!e),className:`inline-flex items-center gap-1 text-xs px-2 py-1 rounded border border-sky-500/40 bg-sky-500/10 text-sky-700 dark:text-sky-300 hover:bg-sky-500/20 transition-colors`,title:`Inject a synthetic result for an in-flight tool call`,children:[(0,J.jsx)(xe,{className:`w-3 h-3`}),`Inject`]}),p?(0,J.jsxs)(`button`,{type:`button`,onClick:A,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:`Resume the agent loop`,children:[(0,J.jsx)(Nt,{className:`w-3 h-3`}),`Resume`]}):(0,J.jsxs)(`button`,{type:`button`,onClick:k,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:`Pause the agent before the next tool call`,children:[(0,J.jsx)(Vn,{className:`w-3 h-3`}),`Pause agent`]})]}),i&&o!==`controller`&&(0,J.jsxs)(`button`,{type:`button`,onClick:j,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)(s,{className:`w-3 h-3`}),`Leave`]}),P&&h&&(0,J.jsxs)(`div`,{className:`absolute top-full left-0 right-0 mt-1 z-50 flex flex-col gap-2 p-3 rounded-md border border-sky-500/40 bg-card shadow-lg text-xs`,children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,J.jsx)(xe,{className:`w-3.5 h-3.5 text-sky-600 dark:text-sky-400`}),(0,J.jsx)(`span`,{className:`font-medium`,children:`Inject tool result`}),(0,J.jsx)(`button`,{type:`button`,onClick:()=>g(!1),className:`ml-auto text-muted-foreground hover:text-foreground`,children:`close`})]}),(0,J.jsxs)(`label`,{className:`flex flex-col gap-1`,children:[(0,J.jsx)(`span`,{className:`text-muted-foreground`,children:`Target tool_use id`}),(0,J.jsx)(`input`,{list:`collab-inject-tools`,value:_,onChange:e=>v(e.target.value),placeholder:`pick an in-flight call or type a tool_use id`,className:`px-2 py-1 rounded border border-border bg-background font-mono`}),(0,J.jsx)(`datalist`,{id:`collab-inject-tools`,children:D.map(e=>{let t=e.toolInput===void 0?``:` — ${JSON.stringify(e.toolInput).slice(0,40)}`;return(0,J.jsxs)(`option`,{value:e.toolUseId,children:[e.toolName??`tool`,t]},e.toolUseId)})}),D.length===0&&(0,J.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:`No in-flight tool calls — type a tool_use id to pre-queue, or pause the agent first.`})]}),(0,J.jsxs)(`label`,{className:`flex flex-col gap-1`,children:[(0,J.jsx)(`span`,{className:`text-muted-foreground`,children:`Result content`}),(0,J.jsx)(`textarea`,{value:y,onChange:e=>b(e.target.value),rows:3,placeholder:`Synthetic tool result fed to the agent in place of running the tool`,className:`px-2 py-1 rounded border border-border bg-background font-mono`})]}),(0,J.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,J.jsxs)(`label`,{className:`flex items-center gap-1`,children:[(0,J.jsx)(`input`,{type:`checkbox`,checked:x,onChange:e=>S(e.target.checked)}),(0,J.jsx)(`span`,{children:`mark as error`})]}),(0,J.jsx)(`input`,{type:`text`,value:w,onChange:e=>T(e.target.value),placeholder:`reason (audit log)`,className:`flex-1 px-2 py-1 rounded border border-border bg-background`})]}),(0,J.jsxs)(`button`,{type:`button`,onClick:N,disabled:!_,className:`self-end inline-flex items-center gap-1 text-xs px-3 py-1 rounded bg-sky-600 text-white hover:bg-sky-700 disabled:opacity-50 disabled:cursor-not-allowed transition-colors`,children:[(0,J.jsx)(xe,{className:`w-3 h-3`}),`Queue injection`]})]})]})}var nm={up:(0,J.jsx)(T,{className:`h-3.5 w-3.5 text-emerald-500`}),down:(0,J.jsx)(x,{className:`h-3.5 w-3.5 text-red-500`}),stable:(0,J.jsx)(h,{className:`h-3.5 w-3.5 text-amber-500`})},rm={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 im({goal:e,className:t}){let[n,r]=(0,H.useState)(!1);if((0,H.useEffect)(()=>{let e=U();e?.send?.({type:`goal.get`});let t=setInterval(()=>{e?.send?.({type:`goal.get`})},1e4);return()=>clearInterval(t)},[]),(0,H.useEffect)(()=>{(!e||e.goalState===`completed`||e.goalState===`failed`||e.goalState===`abandoned`)&&r(!0)},[e]),!e||e.goalState===`completed`||e.goalState===`failed`||e.goalState===`abandoned`)return null;let i=rm[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?nm[e.progressTrend]:null;return(0,J.jsxs)(`div`,{className:X(`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)(mn,{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:X(`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)(ot,{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:X(`h-full transition-all duration-700 rounded-full`,e.progress>=80?`bg-emerald-500`:e.progress>=50?`bg-amber-500`:`bg-primary`),style:{width:`${e.progress>0?Math.max(2,e.progress):0}%`}})}),e.progressNote&&(0,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)(Fr,{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)(M,{className:`h-3 w-3 text-emerald-500 mt-0.5 shrink-0`}):(0,J.jsx)(Qe,{className:`h-3 w-3 text-muted-foreground/50 mt-0.5 shrink-0`}),(0,J.jsx)(`span`,{className:X(`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}`))})]})]})]})}var am={in_progress:0,pending:1,completed:2};function om(){let[e,t]=(0,H.useState)([]),[n,r]=(0,H.useState)(new Set),i=U(),a=(0,H.useRef)(null);(0,H.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,H.useCallback)(e=>{i.removeTodo(e)},[i]),s=(0,H.useCallback)(e=>{if(e.status===`in_progress`)return;let t=e.status===`completed`?`pending`:`completed`;i.updateTodoStatus(e.id,t)},[i]),c=[...e].sort((e,t)=>(am[e.status]??9)-(am[t.status]??9)),l=c.filter(e=>e.status===`in_progress`),u=c.filter(e=>e.status===`pending`),d=c.filter(e=>e.status===`completed`),f=d.length>0,p=n.has(`completed`),m=e=>{r(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},h=e=>{let t=e.status===`in_progress`&&e.activeForm?e.activeForm:e.content,n=e.status===`in_progress`,r=e.status===`completed`,i=!n;return(0,J.jsxs)(`div`,{onClick:()=>i&&s(e),className:X(`px-3 py-1.5 flex items-start gap-2 text-[13px] group transition-colors`,i&&`cursor-pointer hover:bg-accent/40`,n?`bg-yellow-50/40 dark:bg-yellow-950/25`:r?`bg-emerald-50/20 dark:bg-emerald-950/10`:`bg-background`),role:i?`button`:void 0,"aria-label":i?`Toggle ${e.content}`:void 0,tabIndex:i?0:void 0,onKeyDown:t=>{i&&(t.key===`Enter`||t.key===` `)&&(t.preventDefault(),s(e))},children:[(0,J.jsx)(`span`,{className:`mt-0.5 shrink-0`,children:r?(0,J.jsx)(M,{className:`w-3.5 h-3.5 text-emerald-500`}):n?(0,J.jsx)(Fr,{className:`w-3.5 h-3.5 text-yellow-500 animate-spin`}):(0,J.jsx)(Qe,{className:X(`w-3.5 h-3.5 transition-colors`,`text-muted-foreground/40 group-hover:text-emerald-400`)})}),(0,J.jsx)(`span`,{className:X(`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`,"aria-label":`Remove "${e.content}"`,children:(0,J.jsx)(Te,{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:[d.length,`/`,e.length]})]}),l.length>0&&(0,J.jsx)(`div`,{className:`border-b border-border/30 last:border-b-0`,children:l.map(h)}),u.length>0&&(0,J.jsx)(`div`,{className:`border-b border-border/30 last:border-b-0`,children:u.map(h)}),f&&(0,J.jsxs)(`div`,{children:[(0,J.jsx)(`button`,{type:`button`,onClick:()=>m(`completed`),className:`w-full px-3 py-1 flex items-center gap-1.5 text-[10px] text-muted-foreground hover:text-foreground transition-colors`,children:(0,J.jsxs)(`span`,{className:`tabular`,children:[p?`▶`:`▼`,` `,d.length,` completed`]})}),!p&&d.map(h)]})]})}var sm={pending:{icon:(0,J.jsx)(Qe,{className:`w-3.5 h-3.5`}),label:`Pending`,color:`text-muted-foreground/50`},in_progress:{icon:(0,J.jsx)(Fr,{className:`w-3.5 h-3.5 animate-spin`}),label:`In Progress`,color:`text-yellow-500`},blocked:{icon:(0,J.jsx)(Vn,{className:`w-3.5 h-3.5`}),label:`Blocked`,color:`text-orange-500`},failed:{icon:(0,J.jsx)(I,{className:`w-3.5 h-3.5`}),label:`Failed`,color:`text-red-500`},review:{icon:(0,J.jsx)(or,{className:`w-3.5 h-3.5`}),label:`Review`,color:`text-blue-500`},completed:{icon:(0,J.jsx)(M,{className:`w-3.5 h-3.5`}),label:`Done`,color:`text-emerald-500`}},cm={critical:`text-red-600 dark:text-red-400`,high:`text-orange-600 dark:text-orange-400`,medium:`text-yellow-600 dark:text-yellow-400`,low:`text-muted-foreground`},lm={feature:`⚡`,bugfix:`🐛`,refactor:`♻️`,docs:`📝`,test:`🧪`,chore:`🔧`};function um(){let[e,t]=(0,H.useState)([]),[n,r]=(0,H.useState)(new Set),i=U(),a=(0,H.useRef)(null);(0,H.useEffect)(()=>(i.getTasks(),a.current=i.on(`tasks.updated`,e=>{let n=e?.payload;n?.tasks&&t(n.tasks)}),()=>{a.current?.()}),[i]);let o=(0,H.useCallback)(e=>{r(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),s=(0,H.useCallback)((e,t)=>{i.updateTaskStatus(e,t)},[i]),c=[`in_progress`,`blocked`,`review`,`pending`,`failed`,`completed`],l=new Map;for(let t of e){let e=l.get(t.status)??[];e.push(t),l.set(t.status,e)}let u=l.get(`completed`)?.length??0;return e.length===0?null:(0,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:`Tasks`}),(0,J.jsxs)(`span`,{className:`tabular text-[10px] text-muted-foreground ml-auto`,children:[u,`/`,e.length]})]}),c.map(e=>{let t=l.get(e);if(!t||t.length===0)return null;let r=sm[e],i=n.has(e);return(0,J.jsxs)(`div`,{className:`border-b border-border/30 last:border-b-0`,children:[(0,J.jsx)(`button`,{type:`button`,onClick:()=>o(e),className:`w-full px-3 py-1 flex items-center gap-1.5 text-[10px] text-muted-foreground hover:text-foreground transition-colors`,children:(0,J.jsxs)(`span`,{className:`tabular`,children:[i?`▶`:`▼`,` `,t.length,` `,r.label]})}),!i&&t.map(e=>(0,J.jsxs)(`div`,{className:X(`px-3 py-1.5 flex items-start gap-2 text-[13px] group`,e.status===`in_progress`?`bg-yellow-50/40 dark:bg-yellow-950/25`:``),children:[(0,J.jsx)(`span`,{className:X(`mt-0.5 shrink-0`,r.color),children:r.icon}),(0,J.jsxs)(`span`,{className:`leading-snug flex-1 min-w-0`,children:[(0,J.jsxs)(`span`,{className:X(e.status===`completed`?`text-muted-foreground line-through`:`text-foreground/80`),children:[lm[e.type],` `,e.title]}),e.priority!==`medium`&&(0,J.jsx)(`span`,{className:X(`ml-1 text-[10px]`,cm[e.priority]),children:e.priority}),e.assignee&&(0,J.jsxs)(`span`,{className:`ml-1 text-[10px] text-muted-foreground`,children:[`@`,e.assignee]}),e.estimateHours&&(0,J.jsxs)(`span`,{className:`ml-1 text-[10px] text-muted-foreground`,children:[e.estimateHours,`h`]})]}),(0,J.jsxs)(`div`,{className:`flex gap-0.5 opacity-0 group-hover:opacity-100 transition-opacity shrink-0`,children:[e.status!==`in_progress`&&e.status!==`completed`&&(0,J.jsx)(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),s(e.id,`in_progress`)},className:`px-1.5 py-0.5 text-[9px] rounded bg-primary/15 text-primary hover:bg-primary/25 transition-colors`,title:`Start`,children:`Start`}),e.status===`in_progress`&&(0,J.jsx)(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),s(e.id,`completed`)},className:`px-1.5 py-0.5 text-[9px] rounded bg-[hsl(var(--success)/0.15)] text-[hsl(var(--success))] hover:bg-[hsl(var(--success)/0.25)] transition-colors`,title:`Complete`,children:`Done`}),e.status!==`completed`&&e.status!==`failed`&&(0,J.jsx)(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),s(e.id,`failed`)},className:`px-1.5 py-0.5 text-[9px] rounded bg-destructive/15 text-destructive hover:bg-destructive/25 transition-colors`,title:`Mark failed`,children:`Fail`})]})]},e.id))]},e)})]})}var dm={open:{icon:(0,J.jsx)(Qe,{className:`w-3.5 h-3.5`}),label:`Open`,color:`text-muted-foreground/50`},in_progress:{icon:(0,J.jsx)(Fr,{className:`w-3.5 h-3.5 animate-spin`}),label:`In Progress`,color:`text-yellow-500`},done:{icon:(0,J.jsx)(M,{className:`w-3.5 h-3.5`}),label:`Done`,color:`text-emerald-500`}};function fm(){let[e,t]=(0,H.useState)([]),[n,r]=(0,H.useState)(new Set),i=U(),a=(0,H.useRef)(null);(0,H.useEffect)(()=>(i.getPlan(),a.current=i.on(`plan.updated`,e=>{let n=e?.payload;n?.plan?.items&&t(n.plan.items)}),()=>{a.current?.()}),[i]);let o=(0,H.useCallback)(e=>{r(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),s=(0,H.useCallback)((e,t)=>{i.updatePlanItem(e.id,t)},[i]),c=[`in_progress`,`open`,`done`],l=new Map;for(let t of e){let e=l.get(t.status)??[];e.push(t),l.set(t.status,e)}let u=l.get(`done`)?.length??0;return e.length===0?null:(0,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:`📋 Plan`}),(0,J.jsxs)(`span`,{className:`tabular text-[10px] text-muted-foreground ml-auto`,children:[u,`/`,e.length]})]}),c.map(e=>{let t=l.get(e);if(!t||t.length===0)return null;let r=dm[e],i=n.has(e);return(0,J.jsxs)(`div`,{className:`border-b border-border/30 last:border-b-0`,children:[(0,J.jsx)(`button`,{type:`button`,onClick:()=>o(e),className:`w-full px-3 py-1 flex items-center gap-1.5 text-[10px] text-muted-foreground hover:text-foreground transition-colors`,children:(0,J.jsxs)(`span`,{className:`tabular`,children:[i?`▶`:`▼`,` `,t.length,` `,r.label]})}),!i&&t.map(e=>(0,J.jsxs)(`div`,{className:X(`px-3 py-1.5 flex items-start gap-2 text-[13px] group`,e.status===`in_progress`?`bg-yellow-50/40 dark:bg-yellow-950/25`:``),children:[(0,J.jsx)(`span`,{className:X(`mt-0.5 shrink-0`,r.color),children:r.icon}),(0,J.jsx)(`span`,{className:X(`leading-snug flex-1 min-w-0`,e.status===`done`?`text-muted-foreground line-through`:`text-foreground/80`),children:e.title}),(0,J.jsxs)(`div`,{className:`flex gap-0.5 opacity-0 group-hover:opacity-100 transition-opacity shrink-0`,children:[e.status===`open`&&(0,J.jsx)(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),s(e,`in_progress`)},className:`px-1.5 py-0.5 text-[9px] rounded bg-primary/15 text-primary hover:bg-primary/25 transition-colors`,title:`Start`,children:`Start`}),e.status!==`done`&&(0,J.jsx)(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),s(e,`done`)},className:`px-1.5 py-0.5 text-[9px] rounded bg-[hsl(var(--success)/0.15)] text-[hsl(var(--success))] hover:bg-[hsl(var(--success)/0.25)] transition-colors`,title:`Mark done`,children:`Done`}),e.status===`done`&&(0,J.jsx)(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),s(e,`open`)},className:`px-1.5 py-0.5 text-[9px] rounded bg-muted text-muted-foreground hover:bg-accent hover:text-foreground transition-colors`,title:`Reopen`,children:`Reopen`})]})]},e.id))]},e)})]})}var pm=[{id:`todos`,label:`Todos`,icon:`✅`},{id:`tasks`,label:`Tasks`,icon:`📋`},{id:`plan`,label:`Plan`,icon:`🗺️`}];function mm(){let e=q(e=>e.workDashboardTab),t=q(e=>e.setWorkDashboardTab);return(0,J.jsxs)(`div`,{className:`rounded-lg border border-border bg-card/50 backdrop-blur-sm overflow-hidden`,children:[(0,J.jsx)(`div`,{className:`flex border-b border-border/50 bg-muted/30`,children:pm.map(n=>(0,J.jsxs)(`button`,{type:`button`,onClick:()=>t(n.id),className:X(`flex items-center gap-1 px-3 py-1.5 text-[11px] font-medium transition-colors`,`border-b-2 -mb-px`,e===n.id?`border-primary text-foreground bg-background`:`border-transparent text-muted-foreground hover:text-foreground hover:bg-accent/30`),children:[(0,J.jsx)(`span`,{className:`text-xs`,children:n.icon}),n.label]},n.id))}),(0,J.jsx)(`div`,{className:X(e===`todos`?`block`:`hidden`),children:(0,J.jsx)(om,{})}),(0,J.jsx)(`div`,{className:X(e===`tasks`?`block`:`hidden`),children:(0,J.jsx)(um,{})}),(0,J.jsx)(`div`,{className:X(e===`plan`?`block`:`hidden`),children:(0,J.jsx)(fm,{})})]})}var hm={autophase:{active:`bg-primary/15 border-primary/40 text-primary`,idle:`text-primary/80 hover:bg-primary/10`},goal:{active:`bg-rose-500/15 border-rose-500/40 text-rose-600 dark:text-rose-400`,idle:`text-rose-600/80 dark:text-rose-400/80 hover:bg-rose-500/10`},fleet:{active:`bg-emerald-500/15 border-emerald-500/40 text-emerald-600 dark:text-emerald-400`,idle:`text-emerald-600/80 dark:text-emerald-400/80 hover:bg-emerald-500/10`},work:{active:`bg-amber-500/15 border-amber-500/40 text-amber-600 dark:text-amber-400`,idle:`text-amber-600/80 dark:text-amber-400/80 hover:bg-amber-500/10`},worktrees:{active:`bg-violet-500/15 border-violet-500/40 text-violet-600 dark:text-violet-400`,idle:`text-violet-600/80 dark:text-violet-400/80 hover:bg-violet-500/10`},collab:{active:`bg-cyan-500/15 border-cyan-500/40 text-cyan-600 dark:text-cyan-400`,idle:`text-muted-foreground hover:bg-muted/60`}},gm={autophase:`AutoPhase`,goal:`Goal`,fleet:`Fleet`,work:`Work`,worktrees:`Worktrees`,collab:`Collab`},_m=[`autophase`,`goal`,`fleet`,`work`,`worktrees`,`collab`];function vm({section:e,icon:t,label:n,value:r,active:i,pulse:a,onClick:o}){let s=hm[e];return(0,J.jsxs)(`button`,{type:`button`,onClick:o,title:i?`Collapse ${n}`:`Expand ${n}`,className:X(`flex items-center gap-2 h-7 px-2.5 rounded-full border text-xs font-medium shrink-0 transition-colors`,i?s.active:X(`border-border/40`,s.idle)),children:[(0,J.jsx)(`span`,{className:X(a&&`animate-pulse`),children:t}),n,r&&(0,J.jsx)(`span`,{className:`tabular-nums opacity-80`,children:r})]})}function ym({sessionId:e}){let t=q(e=>e.dockSection),n=q(e=>e.toggleDockSection),i=q(e=>e.setCurrentView),a=q(e=>e.hiddenChips),o=q(e=>e.toggleChipHidden),s=q(e=>e.dockCustomizeOpen),c=q(e=>e.setDockCustomizeOpen),l=Hi(e=>e.goal),u=Ui(e=>e.phases.length),d=Ui(e=>e.overallPercent),f=Ui(e=>e.activePhaseId),p=Si(e=>e.worktrees),m=Si(e=>e.baseBranch),h=K(e=>e.todos),g=Y(e=>e.agents),_=em(),[v,y]=(0,H.useState)(`graph`),b=g.size,x=(0,H.useMemo)(()=>Array.from(g.values()).filter(e=>e.status===`running`).length,[g]),S=h.filter(e=>e.status===`completed`).length,C=h.some(e=>e.status===`in_progress`),w=u>0,T=(0,H.useMemo)(()=>new Set(a),[a]),E={autophase:w,goal:l!==null,fleet:b>0,work:!0,worktrees:p.length>0,collab:!0},D={autophase:E.autophase&&!T.has(`autophase`),goal:E.goal&&!T.has(`goal`),fleet:E.fleet&&!T.has(`fleet`),work:E.work&&!T.has(`work`),worktrees:E.worktrees&&!T.has(`worktrees`),collab:E.collab&&!T.has(`collab`)},O=t&&D[t]?t:null;return(0,J.jsxs)(`div`,{className:`space-y-2`,children:[(0,J.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5 rounded-lg border border-border/50 bg-muted/20 px-2 py-1.5`,children:[D.autophase&&(0,J.jsx)(vm,{section:`autophase`,icon:(0,J.jsx)(jn,{className:`h-3 w-3`}),label:`AutoPhase`,value:`${d}%`,active:!1,pulse:f!=null,onClick:()=>i(`autophase`)}),D.goal&&l&&(0,J.jsx)(vm,{section:`goal`,icon:(0,J.jsx)(mn,{className:`h-3 w-3`}),label:`Goal`,value:`${l.progress}%`,active:O===`goal`,pulse:l.goalState===`active`,onClick:()=>n(`goal`)}),D.fleet&&(0,J.jsx)(vm,{section:`fleet`,icon:(0,J.jsx)(Yn,{className:`h-3 w-3`}),label:`Fleet`,value:`${x}/${b}`,active:O===`fleet`,pulse:x>0,onClick:()=>n(`fleet`)}),(0,J.jsx)(vm,{section:`work`,icon:(0,J.jsx)(De,{className:`h-3 w-3`}),label:`Work`,value:h.length>0?`${S}/${h.length}`:void 0,active:O===`work`,pulse:C,onClick:()=>n(`work`)}),D.worktrees&&(0,J.jsx)(vm,{section:`worktrees`,icon:(0,J.jsx)(r,{className:`h-3 w-3`}),label:`Worktrees`,value:String(p.length),active:O===`worktrees`,onClick:()=>n(`worktrees`)}),_&&(0,J.jsxs)(`button`,{type:`button`,onClick:()=>{},className:`inline-flex items-center gap-1.5 h-7 px-2.5 rounded-full border border-border/40 text-xs font-mono hover:bg-muted/60 transition-colors`,children:[(0,J.jsx)(r,{className:`h-3 w-3 shrink-0 text-muted-foreground`}),(0,J.jsx)(`span`,{className:`font-semibold text-foreground`,children:_.branch}),_.ahead>0&&(0,J.jsxs)(`span`,{className:`text-emerald-600 dark:text-emerald-400`,title:`${_.ahead} ahead`,children:[`↑`,_.ahead]}),_.behind>0&&(0,J.jsxs)(`span`,{className:`text-amber-600 dark:text-amber-400`,title:`${_.behind} behind`,children:[`↓`,_.behind]}),_.added>0&&(0,J.jsxs)(`span`,{className:`text-emerald-600 dark:text-emerald-400`,title:`${_.added} lines added`,children:[`+`,_.added]}),_.deleted>0&&(0,J.jsxs)(`span`,{className:`text-red-600 dark:text-red-400`,title:`${_.deleted} lines deleted`,children:[`-`,_.deleted]}),_.untracked>0&&(0,J.jsxs)(`span`,{className:`text-muted-foreground`,title:`${_.untracked} untracked files`,children:[_.untracked,`?`]})]}),(0,J.jsx)(vm,{section:`collab`,icon:(0,J.jsx)(Mr,{className:`h-3 w-3`}),label:`Collab`,active:O===`collab`,onClick:()=>n(`collab`)}),(0,J.jsxs)(Fs,{open:s,onOpenChange:c,children:[(0,J.jsx)(Is,{asChild:!0,children:(0,J.jsx)(`button`,{type:`button`,title:`Customize dock chips`,className:`ml-auto inline-flex items-center justify-center h-7 w-7 rounded-full border border-border/40 text-muted-foreground hover:bg-muted/60 transition-colors shrink-0`,children:(0,J.jsx)($e,{className:`h-3 w-3`})})}),(0,J.jsxs)(Bs,{align:`end`,className:`w-44`,children:[(0,J.jsx)(Ws,{children:`Dock chips`}),(0,J.jsx)(Gs,{}),_m.map(e=>(0,J.jsx)(Hs,{checked:!T.has(e),onCheckedChange:()=>o(e),onSelect:e=>e.preventDefault(),children:gm[e]},e))]})]})]}),O&&(0,J.jsx)(`div`,{className:`border-t border-border/40 pt-2`}),O===`goal`&&(0,J.jsx)(im,{goal:l}),O===`fleet`&&(0,J.jsx)(gp,{}),O===`worktrees`&&(0,J.jsxs)(`div`,{className:`space-y-2`,children:[(0,J.jsx)(`div`,{className:`flex items-center gap-2`,children:[`graph`,`lanes`].map(e=>(0,J.jsx)(`button`,{type:`button`,onClick:()=>y(e),className:X(`text-xs px-2.5 py-0.5 rounded-full border transition-colors capitalize`,v===e?`bg-primary/10 border-primary/30 text-primary`:`border-border text-muted-foreground hover:text-foreground`),children:e},e))}),(0,J.jsx)(Lc,{}),v===`graph`?(0,J.jsx)(jc,{worktrees:p,baseBranch:m||`HEAD`}):(0,J.jsx)(Fc,{worktrees:p,baseBranch:m||`HEAD`})]}),(0,J.jsx)(`div`,{className:X(O===`work`?`block`:`hidden`),id:`panel-work`,children:(0,J.jsx)(mm,{})}),(0,J.jsx)(`div`,{className:X(O===`collab`?`block`:`hidden`),children:(0,J.jsx)(tm,{sessionId:e})})]})}function bm(e){return e<=0?`$0`:e>=.01?`$${e.toFixed(3)}`:`$${e.toFixed(5)}`.replace(/0+$/,``).replace(/\.$/,``)}function xm(e){let t=Math.floor(e/1e3);return t<60?`${t}s`:`${Math.floor(t/60)}m ${t%60}s`}var Sm={running:{led:`bg-[hsl(var(--success))]`,label:`running`,pulse:!0,badge:`bg-[hsl(var(--success))]/15 text-[hsl(var(--success))]`},completed:{led:`bg-[hsl(var(--success))]`,label:`done`,pulse:!1,badge:`bg-muted text-muted-foreground`},failed:{led:`bg-destructive`,label:`failed`,pulse:!1,badge:`bg-destructive/15 text-destructive`},timeout:{led:`bg-[hsl(var(--warning))]`,label:`timeout`,pulse:!1,badge:`bg-amber-500/15 text-amber-500`},stopped:{led:`bg-muted-foreground`,label:`stopped`,pulse:!1,badge:`bg-muted text-muted-foreground`}};function Cm({agent:e,isLeader:t}){let n=Sm[e.status],r=e.status===`running`,i=Date.now()-e.startedAt,a=[...e.toolLog.slice(0,8)].reverse();return(0,J.jsxs)(`div`,{className:X(`rounded-xl border p-4 space-y-3`,r?`border-primary/20 bg-primary/[0.02]`:`border-border bg-card`,t&&`ring-2 ring-amber-500/30`),children:[(0,J.jsxs)(`div`,{className:`flex items-start justify-between`,children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,J.jsx)(`span`,{className:X(`led`,n.led,n.pulse&&`led-pulse`,`mt-0.5`)}),(0,J.jsxs)(`div`,{children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,J.jsx)(`span`,{className:`text-sm font-semibold`,children:e.name}),t&&(0,J.jsx)(c,{className:`h-3.5 w-3.5 text-amber-500`,"aria-label":`leader`}),e.extensions>0&&(0,J.jsxs)(`span`,{className:`inline-flex items-center gap-0.5 px-1.5 py-0.5 rounded-full bg-amber-500/15 text-[10px] text-amber-600 dark:text-amber-400 font-medium`,children:[(0,J.jsx)(Bt,{className:`h-2.5 w-2.5`}),`×`,e.extensions]})]}),(0,J.jsx)(`span`,{className:X(`inline-block mt-0.5 px-1.5 py-0.5 rounded text-[10px] font-medium`,n.badge),children:n.label})]})]}),(0,J.jsx)(`div`,{className:`flex items-center gap-1 text-[10px] text-muted-foreground`,children:t&&(0,J.jsx)(`span`,{className:`text-[9px] bg-amber-500/15 text-amber-600 dark:text-amber-400 px-1.5 py-0.5 rounded`,children:`LEADER`})})]}),e.description&&(0,J.jsx)(`p`,{className:`text-xs text-muted-foreground leading-relaxed line-clamp-2`,children:e.description}),e.budgetWarning&&(0,J.jsxs)(`div`,{className:`flex items-center gap-2 px-3 py-2 rounded-lg bg-amber-500/10 border border-amber-500/20 text-xs`,children:[(0,J.jsx)(Bt,{className:`h-3.5 w-3.5 text-amber-500 shrink-0`}),(0,J.jsxs)(`span`,{className:`text-amber-600 dark:text-amber-400`,children:[`⚡ hitting `,(0,J.jsx)(`strong`,{children:e.budgetWarning.kind}),` limit (`,e.budgetWarning.used,`/`,e.budgetWarning.limit,`) — extending`]})]}),e.failureReason&&(0,J.jsx)(`div`,{className:`flex items-center gap-2 px-3 py-2 rounded-lg bg-destructive/10 border border-destructive/20 text-xs`,children:(0,J.jsxs)(`span`,{className:`text-destructive font-medium`,children:[`✗ `,e.failureReason]})}),(0,J.jsxs)(`div`,{className:`grid grid-cols-4 gap-2`,children:[(0,J.jsxs)(`div`,{className:`rounded-lg border bg-muted/30 px-2 py-1.5 text-center`,children:[(0,J.jsx)(`div`,{className:`text-[10px] text-muted-foreground`,children:`Iters`}),(0,J.jsx)(`div`,{className:`text-xs font-mono font-semibold tabular-nums`,children:e.iteration})]}),(0,J.jsxs)(`div`,{className:`rounded-lg border bg-muted/30 px-2 py-1.5 text-center`,children:[(0,J.jsx)(`div`,{className:`text-[10px] text-muted-foreground`,children:`Tools`}),(0,J.jsx)(`div`,{className:`text-xs font-mono font-semibold tabular-nums`,children:e.toolCalls})]}),(0,J.jsxs)(`div`,{className:`rounded-lg border bg-muted/30 px-2 py-1.5 text-center`,children:[(0,J.jsx)(`div`,{className:`text-[10px] text-muted-foreground`,children:`Cost`}),(0,J.jsx)(`div`,{className:`text-xs font-mono font-semibold tabular-nums`,children:bm(e.costUsd)})]}),(0,J.jsxs)(`div`,{className:`rounded-lg border bg-muted/30 px-2 py-1.5 text-center`,children:[(0,J.jsx)(`div`,{className:`text-[10px] text-muted-foreground`,children:`Elapsed`}),(0,J.jsx)(`div`,{className:`text-xs font-mono font-semibold tabular-nums`,children:xm(i)})]})]}),(0,J.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,J.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,J.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:`Activity (12 bins)`}),(0,J.jsx)(lp,{bins:e.sparklineBins,className:`font-mono text-[9px]`})]}),(0,J.jsx)(Du,{pct:e.ctxPct,tokens:e.ctxTokens,maxTokens:e.maxContext})]}),(e.provider||e.model)&&(0,J.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[10px] text-muted-foreground`,children:[(0,J.jsx)(_e,{className:`h-3 w-3`}),(0,J.jsxs)(`span`,{className:`font-mono`,children:[e.provider??`?`,`/`,e.model??`?`]})]}),(e.currentTool||e.lastTool)&&(0,J.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[10px] text-muted-foreground`,children:[(0,J.jsx)(Un,{className:X(`h-3 w-3`,r&&`animate-pulse text-primary`)}),(0,J.jsx)(`span`,{className:`font-mono`,children:e.currentTool??e.lastTool}),r&&(0,J.jsx)(z,{className:`h-3 w-3 animate-spin`})]}),e.partialText&&r&&(0,J.jsxs)(`div`,{className:`rounded-lg border bg-muted/30 p-2`,children:[(0,J.jsx)(`div`,{className:`text-[9px] text-muted-foreground uppercase tracking-wider mb-1`,children:`Streaming output`}),(0,J.jsx)(`pre`,{className:`text-[10px] font-mono text-foreground/80 whitespace-pre-wrap line-clamp-3 leading-relaxed`,children:e.partialText})]}),a.length>0&&(0,J.jsxs)(`div`,{className:`space-y-1`,children:[(0,J.jsx)(`div`,{className:`text-[9px] text-muted-foreground uppercase tracking-wider`,children:`Recent tools`}),(0,J.jsx)(`div`,{className:`space-y-0.5`,children:a.map((e,t)=>(0,J.jsxs)(`div`,{className:`flex items-center gap-2 text-[10px] font-mono`,children:[(0,J.jsx)(`span`,{className:X(`shrink-0`,e.ok?`text-[hsl(var(--success))]`:`text-destructive`),children:e.ok?`✓`:`✗`}),(0,J.jsx)(`span`,{className:`text-muted-foreground truncate`,children:e.name}),(0,J.jsx)(`span`,{className:`ml-auto tabular-nums text-muted-foreground shrink-0`,children:e.durationMs>=1e3?`${(e.durationMs/1e3).toFixed(1)}s`:`${e.durationMs}ms`})]},t))})]}),e.finalText&&!r&&(0,J.jsxs)(`div`,{className:`rounded-lg border bg-muted/30 p-2`,children:[(0,J.jsx)(`div`,{className:`text-[9px] text-muted-foreground uppercase tracking-wider mb-1`,children:`Final output`}),(0,J.jsx)(`pre`,{className:`text-[10px] font-mono text-foreground/80 whitespace-pre-wrap line-clamp-4 leading-relaxed`,children:e.finalText})]})]})}function wm({onClose:e}){let t=Y(e=>e.agents),n=Y(e=>e.leaderId),[r,i]=(0,H.useState)(0),a=(0,H.useMemo)(()=>{let e=Array.from(t.values());return e.sort((e,t)=>{if(e.id===n)return-1;if(t.id===n)return 1;let r=e.status===`running`?0:1,i=t.status===`running`?0:1;return r===i?e.startedAt-t.startedAt:r-i}),e},[t,n]),o=(0,H.useCallback)(t=>{if(t.key===`Escape`){e();return}if(t.key===`ArrowDown`){t.preventDefault(),i(e=>Math.min(e+1,a.length-1));return}if(t.key===`ArrowUp`){t.preventDefault(),i(e=>Math.max(e-1,0));return}},[a.length,e]);(0,H.useEffect)(()=>{let t=t=>{t.key===`Escape`&&e()};return window.addEventListener(`keydown`,t),()=>window.removeEventListener(`keydown`,t)},[e]);let s=a[r]??null;return(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(`div`,{className:`fixed inset-0 z-40 bg-black/10 backdrop-blur-[1px]`,onClick:e,"aria-hidden":`true`}),(0,J.jsxs)(`div`,{className:`fixed right-0 top-0 h-full z-50 w-[600px] max-w-[90vw] flex flex-col bg-background border-l shadow-2xl animate-slide-in-right`,onKeyDown:o,tabIndex:-1,children:[(0,J.jsxs)(`div`,{className:`flex items-center justify-between px-4 py-3 border-b bg-card/80 backdrop-blur shrink-0`,children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,J.jsx)(Yn,{className:`h-5 w-5 text-primary`}),(0,J.jsx)(`h2`,{className:`text-sm font-semibold`,children:`Agents Monitor`}),(0,J.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[a.length,` total`]})]}),(0,J.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,J.jsx)(`button`,{type:`button`,onClick:()=>i(e=>Math.max(e-1,0)),className:`p-1.5 rounded-md hover:bg-muted transition-colors disabled:opacity-30`,disabled:r===0,"aria-label":`Previous agent`,children:(0,J.jsx)(mt,{className:`h-4 w-4`})}),(0,J.jsx)(`span`,{className:`text-xs tabular-nums text-muted-foreground font-mono`,children:a.length>0?`${r+1}/${a.length}`:`0/0`}),(0,J.jsx)(`button`,{type:`button`,onClick:()=>i(e=>Math.min(e+1,a.length-1)),className:`p-1.5 rounded-md hover:bg-muted transition-colors disabled:opacity-30`,disabled:r>=a.length-1,"aria-label":`Next agent`,children:(0,J.jsx)(ot,{className:`h-4 w-4`})}),(0,J.jsx)(`button`,{type:`button`,onClick:e,className:`p-1.5 rounded-md hover:bg-muted transition-colors ml-2`,"aria-label":`Close agents monitor`,children:(0,J.jsx)(B,{className:`h-4 w-4`})})]})]}),(0,J.jsx)(`div`,{className:`flex-1 overflow-y-auto p-4`,children:a.length===0?(0,J.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full text-muted-foreground`,children:[(0,J.jsx)(Yn,{className:`h-12 w-12 mb-3 opacity-20`}),(0,J.jsx)(`p`,{className:`text-sm font-medium`,children:`No agents active`})]}):s?(0,J.jsx)(`div`,{className:`max-w-2xl mx-auto`,children:(0,J.jsx)(Cm,{agent:s,isLeader:s.id===n})}):null}),a.length>0&&(0,J.jsxs)(`div`,{className:`border-t bg-card/80 backdrop-blur shrink-0`,children:[(0,J.jsx)(`div`,{className:`px-4 py-2 flex items-center gap-2 overflow-x-auto`,children:a.map((e,t)=>(0,J.jsxs)(`button`,{type:`button`,onClick:()=>i(t),className:X(`shrink-0 flex items-center gap-1.5 px-2 py-1 rounded-md text-[10px] transition-colors`,t===r?`bg-primary/15 text-primary ring-1 ring-primary/40`:`hover:bg-accent text-muted-foreground`),children:[(0,J.jsx)(`span`,{className:X(`led`,Sm[e.status].led,Sm[e.status].pulse&&`led-pulse`,`shrink-0`)}),(0,J.jsx)(`span`,{children:e.name}),e.id===n&&(0,J.jsx)(c,{className:`h-2.5 w-2.5 text-amber-500 shrink-0`})]},e.id))}),(0,J.jsxs)(`div`,{className:`px-4 py-1.5 border-t text-[10px] text-muted-foreground flex items-center gap-4`,children:[(0,J.jsx)(`span`,{children:`←→ page`}),(0,J.jsx)(`span`,{children:`↑↓ navigate list`}),(0,J.jsx)(`span`,{children:`Esc close`})]})]})]})]})}function Tm({current:e,max:t,className:n,showLabel:r=!0}){let i=Math.min(e,t),a=Math.max(0,t-i),o=t>0?i/t*100:0,s=o>=90?`text-destructive`:o>=70?`text-[hsl(var(--warning))]`:`text-[hsl(var(--success))]`;return(0,J.jsxs)(`span`,{className:n,title:`Fleet concurrency: ${e}/${t}`,children:[(0,J.jsxs)(`span`,{"aria-hidden":`true`,className:`font-mono text-[10px] tracking-tight`,children:[`[`,(0,J.jsx)(`span`,{className:s,children:`█`.repeat(i)}),(0,J.jsx)(`span`,{className:`text-[hsl(var(--muted))]`,children:`░`.repeat(a)}),`]`]}),r&&(0,J.jsxs)(`span`,{className:`ml-1.5 tabular-nums text-[10px] text-muted-foreground font-mono`,children:[e,`/`,t]})]})}function Em(e){let t=Date.now()-e;return t<5e3?`just now`:t<6e4?`${Math.floor(t/1e3)}s ago`:t<36e5?`${Math.floor(t/6e4)}m ago`:`${Math.floor(t/36e5)}h ago`}var Dm={spawned:`🚀`,task_started:`▶`,tool_executed:`⚡`,iteration_summary:`🔄`,budget_warning:`!`,budget_extended:`⚡`,task_completed:`✅`,ctx_pct:`💬`,leader_updated:`👑`};function Om({events:e,max:t=20,className:n}){let r=e.slice(0,t);return r.length===0?(0,J.jsx)(`div`,{className:`py-4 text-center text-xs text-muted-foreground ${n??``}`,children:`No events yet.`}):(0,J.jsx)(`div`,{className:`space-y-0.5 overflow-y-auto max-h-48 ${n??``}`,children:r.map(e=>(0,J.jsxs)(`div`,{className:`flex items-start gap-2 text-[10px] leading-tight py-0.5 px-1 rounded hover:bg-accent/50 transition-colors`,children:[(0,J.jsx)(`span`,{className:`shrink-0 w-5 text-center`,"aria-hidden":`true`,children:Dm[e.kind]??`·`}),(0,J.jsx)(`span`,{className:`shrink-0 w-12 text-right text-muted-foreground font-mono tabular-nums`,children:Em(e.timestamp)}),(0,J.jsx)(`span`,{className:`truncate text-foreground/90`,children:e.message}),e.value!==void 0&&e.kind===`tool_executed`&&(0,J.jsx)(`span`,{className:`ml-auto shrink-0 tabular-nums text-muted-foreground font-mono`,children:e.value>=1e3?`${(e.value/1e3).toFixed(1)}s`:`${e.value}ms`}),e.value!==void 0&&e.kind===`ctx_pct`&&(0,J.jsxs)(`span`,{className:`ml-auto shrink-0 tabular-nums text-muted-foreground font-mono`,children:[e.value,`%`]})]},e.id))})}var km={running:{led:`bg-emerald-500`,label:`running`,pulse:!0,color:`text-emerald-500`},completed:{led:`bg-emerald-500`,label:`done`,pulse:!1,color:`text-emerald-500`},failed:{led:`bg-destructive`,label:`failed`,pulse:!1,color:`text-destructive`},timeout:{led:`bg-amber-500`,label:`timeout`,pulse:!1,color:`text-amber-500`},stopped:{led:`bg-muted-foreground`,label:`stopped`,pulse:!1,color:`text-muted-foreground`}};function Am({agent:e,now:t}){let[n,r]=(0,H.useState)(!1),[i,a]=(0,H.useState)(!1),o=km[e.status],s=e.status===`running`,c=Math.min(100,Math.max(0,e.ctxPct)),l=(0,H.useCallback)(async e=>{try{await navigator.clipboard.writeText(e),r(!0),setTimeout(()=>r(!1),2e3)}catch{}},[]),u=e.toolLog.reduce((e,t)=>e+t.durationMs,0),d=e.toolLog.length>0?Math.round(u/e.toolLog.length):0,f=(0,H.useMemo)(()=>{let t=new Set;for(let n of e.toolLog)t.add(n.name);return t.size},[e.toolLog]),p=e.partialText||e.finalText||void 0,m=!e.finalText&&!!e.partialText;return(0,J.jsxs)(`div`,{className:`h-full flex flex-col`,children:[(0,J.jsxs)(`div`,{className:`shrink-0 border-b bg-card p-4 space-y-3`,children:[(0,J.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,J.jsx)(`div`,{className:`flex items-center justify-center w-10 h-10 rounded-lg bg-primary/10`,children:(0,J.jsx)(Yn,{className:`h-5 w-5 text-primary`})}),(0,J.jsxs)(`div`,{children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,J.jsx)(`span`,{className:`text-base font-semibold`,children:e.name}),(0,J.jsx)(`span`,{className:X(`px-2 py-0.5 rounded text-[10px] font-medium uppercase tracking-wider`,e.status===`running`?`bg-emerald-500/15 text-emerald-600 dark:text-emerald-400`:e.status===`failed`||e.status===`timeout`?`bg-destructive/15 text-destructive`:`bg-muted text-muted-foreground`),children:o.label})]}),(0,J.jsxs)(`span`,{className:`text-[10px] text-muted-foreground font-mono`,children:[`session: `,e.sessionId?.slice(0,12),`…`]})]})]}),(0,J.jsxs)(`div`,{className:`flex items-center gap-2 text-[11px] text-muted-foreground`,children:[s&&(0,J.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,J.jsx)(vn,{className:`h-3.5 w-3.5`}),(0,J.jsx)(`span`,{className:`tabular-nums font-mono`,children:fp(Math.max(0,t-e.startedAt))})]}),(0,J.jsx)(`span`,{className:X(`led`,o.led,s&&`led-pulse`)})]})]}),(0,J.jsxs)(`div`,{className:`flex items-center gap-3 px-3 py-2 rounded-lg bg-muted/30`,children:[(0,J.jsx)(`span`,{className:`text-[10px] text-muted-foreground uppercase tracking-wider`,children:`Activity`}),(0,J.jsx)(lp,{bins:e.sparklineBins,className:`font-mono text-[9px]`}),e.budgetWarning&&(0,J.jsxs)(`span`,{className:`ml-auto flex items-center gap-1 text-[10px] text-amber-500`,children:[(0,J.jsx)(Bt,{className:`h-3 w-3`}),`budget warning`]})]}),e.description&&(0,J.jsxs)(`div`,{className:`px-3 py-2 rounded-lg bg-muted/20 border border-border/50`,children:[(0,J.jsx)(`span`,{className:`text-[9px] text-muted-foreground uppercase tracking-wider`,children:`Current Task`}),(0,J.jsx)(`p`,{className:`text-xs mt-1 text-foreground/80`,children:e.description})]})]}),(0,J.jsxs)(`div`,{className:`flex-1 overflow-y-auto p-4 space-y-4`,children:[(0,J.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,J.jsxs)(`div`,{className:`rounded-lg border bg-card p-3`,children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-2 text-[9px] text-muted-foreground uppercase tracking-wider mb-2`,children:[(0,J.jsx)(_e,{className:`h-3 w-3`}),` Provider / Model`]}),(0,J.jsxs)(`div`,{className:`text-sm font-mono font-medium`,children:[e.provider??`?`,`/`,e.model??`?`]})]}),(0,J.jsxs)(`div`,{className:`rounded-lg border bg-card p-3`,children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-2 text-[9px] text-muted-foreground uppercase tracking-wider mb-2`,children:[(0,J.jsx)(_t,{className:`h-3 w-3`}),` Performance`]}),(0,J.jsxs)(`div`,{className:`space-y-1`,children:[(0,J.jsxs)(`div`,{className:`flex justify-between text-[11px]`,children:[(0,J.jsx)(`span`,{className:`text-muted-foreground`,children:`Iterations`}),(0,J.jsx)(`span`,{className:`font-mono font-medium`,children:e.iteration})]}),(0,J.jsxs)(`div`,{className:`flex justify-between text-[11px]`,children:[(0,J.jsx)(`span`,{className:`text-muted-foreground`,children:`Tool Calls`}),(0,J.jsx)(`span`,{className:`font-mono font-medium`,children:e.toolCalls})]}),(0,J.jsxs)(`div`,{className:`flex justify-between text-[11px]`,children:[(0,J.jsx)(`span`,{className:`text-muted-foreground`,children:`Unique Tools`}),(0,J.jsx)(`span`,{className:`font-mono font-medium`,children:f})]})]})]}),(0,J.jsxs)(`div`,{className:`rounded-lg border bg-card p-3`,children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-2 text-[9px] text-muted-foreground uppercase tracking-wider mb-2`,children:[(0,J.jsx)(we,{className:`h-3 w-3`}),` Cost`]}),(0,J.jsx)(`div`,{className:`text-lg font-mono font-bold text-emerald-500`,children:up(e.costUsd)}),(0,J.jsxs)(`div`,{className:`text-[10px] text-muted-foreground mt-1`,children:[`avg `,d,`ms per tool`]})]}),(0,J.jsxs)(`div`,{className:`rounded-lg border bg-card p-3`,children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-2 text-[9px] text-muted-foreground uppercase tracking-wider mb-2`,children:[(0,J.jsx)(_n,{className:`h-3 w-3`}),` Context`]}),(0,J.jsxs)(`div`,{className:`space-y-2`,children:[(0,J.jsxs)(`div`,{className:`flex justify-between text-[11px]`,children:[(0,J.jsx)(`span`,{className:`text-muted-foreground`,children:`Tokens`}),(0,J.jsx)(`span`,{className:`font-mono font-medium`,children:dp(e.ctxTokens)})]}),(0,J.jsx)(`div`,{className:`h-2 w-full rounded-full bg-muted overflow-hidden`,children:(0,J.jsx)(`div`,{className:X(`h-full rounded-full transition-all`,c>=85?`bg-destructive`:c>=70?`bg-amber-500`:`bg-emerald-500`),style:{width:`${c}%`}})}),(0,J.jsxs)(`span`,{className:`text-[10px] text-muted-foreground tabular-nums font-mono`,children:[c,`% used`]})]})]})]}),e.currentTool&&(0,J.jsxs)(`div`,{className:X(`rounded-lg border px-4 py-3 flex items-center gap-3`,s?`border-primary/30 bg-primary/[0.04]`:`border-border bg-muted/30`),children:[(0,J.jsx)(Un,{className:X(`h-4 w-4`,s?`text-primary animate-pulse`:`text-muted-foreground`)}),(0,J.jsx)(`span`,{className:`text-sm font-mono font-medium`,children:e.currentTool}),s?(0,J.jsxs)(`span`,{className:`ml-auto flex items-center gap-1.5 text-[10px] text-primary`,children:[(0,J.jsx)(z,{className:`h-3 w-3 animate-spin`}),` running…`]}):(0,J.jsx)(`span`,{className:`ml-auto text-[10px] text-muted-foreground`,children:`completed`})]}),p?(0,J.jsxs)(`div`,{className:`rounded-lg border bg-card`,children:[(0,J.jsxs)(`div`,{className:`flex items-center justify-between px-4 py-2 border-b bg-muted/30`,children:[(0,J.jsx)(`span`,{className:`text-[10px] font-semibold text-muted-foreground uppercase tracking-wider flex items-center gap-2`,children:m?(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(`span`,{className:`w-2 h-2 rounded-full bg-blue-500 animate-pulse`}),`Live Output`]}):(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(wt,{className:`h-3 w-3`}),`Final Output`]})}),(0,J.jsx)(`button`,{type:`button`,onClick:()=>l(p),className:`flex items-center gap-1 px-2 py-1 rounded text-[10px] text-muted-foreground hover:text-foreground hover:bg-muted transition-colors`,children:n?`✓ Copied`:`Copy`})]}),(0,J.jsx)(`pre`,{className:`p-4 text-xs whitespace-pre-wrap font-mono text-foreground/80 leading-relaxed max-h-64 overflow-y-auto`,children:p})]}):s?(0,J.jsxs)(`div`,{className:`rounded-lg border border-dashed border-border p-6 text-center`,children:[(0,J.jsx)(z,{className:`h-6 w-6 mx-auto mb-2 text-muted-foreground/50 animate-spin`}),(0,J.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`Waiting for output…`})]}):null,e.budgetWarning&&(0,J.jsxs)(`div`,{className:`flex items-center gap-3 px-4 py-3 rounded-lg bg-amber-500/10 border border-amber-500/20`,children:[(0,J.jsx)(Bt,{className:`h-5 w-5 text-amber-500 shrink-0`}),(0,J.jsxs)(`div`,{children:[(0,J.jsx)(`span`,{className:`text-sm font-medium text-amber-600 dark:text-amber-400`,children:`⚡ Budget Warning`}),(0,J.jsxs)(`p`,{className:`text-[11px] text-amber-600/80 dark:text-amber-400/80 mt-0.5`,children:[`Hitting `,e.budgetWarning.kind,` limit (`,e.budgetWarning.used,`/`,e.budgetWarning.limit,`)`]})]})]}),e.extensions>0&&(0,J.jsxs)(`div`,{className:`flex items-center gap-3 px-4 py-3 rounded-lg bg-amber-500/10 border border-amber-500/20`,children:[(0,J.jsx)(Bt,{className:`h-5 w-5 text-amber-500 shrink-0`}),(0,J.jsxs)(`div`,{children:[(0,J.jsxs)(`span`,{className:`text-sm font-medium`,children:[e.extensions,` Budget Extension`,e.extensions===1?``:`s`]}),(0,J.jsxs)(`p`,{className:`text-[11px] text-muted-foreground mt-0.5`,children:[`Agent extended its budget `,e.extensions,` time`,e.extensions===1?``:`s`,` due to long-running tasks`]})]})]}),e.error&&(0,J.jsxs)(`div`,{className:`rounded-lg border border-destructive/30 bg-destructive/5 p-4`,children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-2 mb-2`,children:[(0,J.jsx)(I,{className:`h-4 w-4 text-destructive`}),(0,J.jsx)(`span`,{className:`text-[10px] font-semibold text-destructive uppercase tracking-wider`,children:`Error`})]}),(0,J.jsx)(`p`,{className:`text-sm text-destructive/90`,children:e.error.message})]}),e.failureReason&&(0,J.jsxs)(`div`,{className:`rounded-lg border border-destructive/30 bg-destructive/5 p-4`,children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-2 mb-2`,children:[(0,J.jsx)(I,{className:`h-4 w-4 text-destructive`}),(0,J.jsx)(`span`,{className:`text-[10px] font-semibold text-destructive uppercase tracking-wider`,children:`Failure Reason`})]}),(0,J.jsx)(`p`,{className:`text-sm text-destructive/90`,children:e.failureReason})]}),e.toolLog.length>0&&(0,J.jsxs)(`div`,{className:`rounded-lg border bg-card`,children:[(0,J.jsxs)(`button`,{type:`button`,onClick:()=>a(!i),className:`w-full flex items-center justify-between px-4 py-2 border-b bg-muted/30 hover:bg-muted/50 transition-colors`,children:[(0,J.jsxs)(`span`,{className:`text-[10px] font-semibold text-muted-foreground uppercase tracking-wider flex items-center gap-2`,children:[(0,J.jsx)(Un,{className:`h-3 w-3`}),`Tool Log (`,e.toolLog.length,` calls)`]}),(0,J.jsx)(ot,{className:X(`h-4 w-4 text-muted-foreground transition-transform`,i&&`rotate-90`)})]}),(0,J.jsx)(`div`,{className:X(`overflow-hidden transition-all`,i?`max-h-[500px]`:`max-h-48`),children:(0,J.jsx)(`div`,{className:`p-2 space-y-0.5`,children:e.toolLog.map((e,t)=>(0,J.jsxs)(`div`,{className:X(`flex items-center gap-3 rounded px-3 py-2 text-[11px]`,e.ok?`bg-muted/30 hover:bg-muted/50`:`bg-destructive/5 border border-destructive/20`),children:[(0,J.jsx)(`span`,{className:X(`led shrink-0`,e.ok?`bg-emerald-500`:`bg-destructive`)}),(0,J.jsx)(`span`,{className:X(`font-mono font-medium w-20 shrink-0`,e.ok?`text-foreground`:`text-destructive`),children:e.name}),(0,J.jsx)(`span`,{className:`text-muted-foreground tabular-nums text-[10px]`,children:e.durationMs>=1e3?`${(e.durationMs/1e3).toFixed(2)}s`:`${e.durationMs}ms`}),!e.ok&&(0,J.jsx)(`span`,{className:`ml-auto text-[10px] text-destructive font-medium`,children:`Failed`}),(0,J.jsx)(`span`,{className:`ml-auto text-[9px] text-muted-foreground tabular-nums`,children:new Date(e.at).toLocaleTimeString()})]},`${e.name}-${e.at}-${t}`))})})]})]})]})}function jm({agent:e,isSelected:t,isLeader:n,onClick:r}){let i=km[e.status],a=e.status===`running`,o=Math.min(100,Math.max(0,e.ctxPct));return(0,J.jsxs)(`button`,{type:`button`,onClick:r,className:X(`w-full text-left grid grid-cols-[140px_60px_1fr_60px_60px_60px_60px_50px_50px] items-center gap-x-2 px-3 py-1.5 rounded-md text-xs transition-colors`,t?`bg-primary/15 ring-1 ring-primary/40`:`hover:bg-accent/50`,a&&!t&&`bg-muted/30`),children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-1 min-w-0`,children:[(0,J.jsx)(`span`,{className:X(`led shrink-0`,i.led,i.pulse&&`led-pulse`)}),(0,J.jsx)(`span`,{className:`truncate font-medium`,children:e.name}),n&&(0,J.jsx)(c,{className:`h-3 w-3 shrink-0 text-amber-500`,"aria-label":`leader`})]}),(0,J.jsx)(`span`,{className:X(`text-[10px] tabular-nums`,a?`text-emerald-500`:`text-muted-foreground`),children:i.label}),(0,J.jsxs)(`div`,{className:`flex items-center gap-1 min-w-0`,children:[(0,J.jsx)(lp,{bins:e.sparklineBins,className:`font-mono text-[9px]`}),e.budgetWarning&&(0,J.jsx)(`span`,{title:`⚡ hitting ${e.budgetWarning.kind} limit (${e.budgetWarning.used}/${e.budgetWarning.limit})`,children:(0,J.jsx)(Bt,{className:`h-3 w-3 shrink-0 text-amber-500`,"aria-label":`budget warning`})})]}),(0,J.jsxs)(`span`,{className:`tabular-nums text-muted-foreground text-[10px]`,children:[e.iteration,`it`]}),(0,J.jsxs)(`span`,{className:`tabular-nums text-muted-foreground text-[10px]`,children:[e.toolCalls,`tc`]}),(0,J.jsx)(`span`,{className:`tabular-nums font-mono text-[10px]`,children:up(e.costUsd)}),(0,J.jsxs)(`div`,{className:`flex flex-col gap-0.5 min-w-0`,children:[(0,J.jsx)(`div`,{className:`h-1.5 w-full rounded-full bg-muted overflow-hidden`,children:(0,J.jsx)(`div`,{className:X(`h-full rounded-full transition-all`,o>=85?`bg-destructive`:o>=70?`bg-amber-500`:`bg-emerald-500`),style:{width:`${o}%`}})}),(0,J.jsx)(`span`,{className:`text-[9px] tabular-nums text-muted-foreground font-mono leading-none`,children:e.maxContext>0?`${o}%`:`—`})]}),(0,J.jsx)(`span`,{className:`tabular-nums text-[10px] text-muted-foreground`,children:e.extensions>0?`⚡×${e.extensions}`:`—`}),(0,J.jsx)(`span`,{className:`text-[9px] text-destructive truncate`,title:e.failureReason,children:e.failureReason??``})]})}function Mm({onClose:e,onSelectAgent:t}){let n=Y(e=>e.agents),r=Y(e=>e.leaderId),i=Y(e=>e.fleetTokensIn),a=Y(e=>e.fleetTokensOut),o=Y(e=>e.fleetConcurrency),s=Y(e=>e.fleetConcurrencyMax),c=Y(e=>e.eventTimeline),l=Y(e=>e.agentTimeline),[u,d]=(0,H.useState)(null),[f,p]=(0,H.useState)(Date.now());(0,H.useEffect)(()=>{let e=setInterval(()=>p(Date.now()),1e3);return()=>clearInterval(e)},[]);let m=(0,H.useMemo)(()=>{let e=Array.from(n.values());return e.sort((e,t)=>e.id===r?-1:t.id===r?1:ip(e,t)),e},[n,r]),h=(0,H.useMemo)(()=>Array.from(n.values()).reduce((e,t)=>e+t.costUsd,0),[n]),g=ap(m).running,_=u===null?null:m[u],v=(0,H.useCallback)(e=>d(t=>t===e?null:e),[]),y=(0,H.useCallback)(n=>{if(n.key===`Escape`){u===null?e&&e():d(null);return}if(n.key===`ArrowDown`){n.preventDefault(),d(e=>Math.min((e??-1)+1,m.length-1));return}if(n.key===`ArrowUp`){n.preventDefault(),d(e=>Math.max((e??0)-1,0));return}n.key===`Enter`&&m[u??0]&&t?.(m[u??0])},[m,u,e,t]);return(0,H.useEffect)(()=>{let t=t=>{t.key===`Escape`&&e()};return window.addEventListener(`keydown`,t),()=>window.removeEventListener(`keydown`,t)},[e]),(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(`div`,{className:`fixed inset-0 z-40 bg-black/10 backdrop-blur-[1px]`,onClick:e,"aria-hidden":`true`}),(0,J.jsxs)(`div`,{className:`fixed right-0 top-0 h-full z-50 w-[720px] max-w-[95vw] flex flex-col bg-background border-l shadow-2xl animate-slide-in-right`,onKeyDown:y,tabIndex:-1,children:[(0,J.jsxs)(`div`,{className:`flex items-center justify-between px-4 py-3 border-b bg-card/80 backdrop-blur shrink-0`,children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,J.jsx)(Yn,{className:`h-5 w-5 text-primary`}),(0,J.jsxs)(`h2`,{className:`text-sm font-semibold flex items-center gap-2`,children:[`FLEET MONITOR`,g>0&&(0,J.jsxs)(`span`,{className:`flex items-center gap-1 text-[11px] text-emerald-500 font-normal`,children:[(0,J.jsx)(`span`,{className:`led led-pulse bg-emerald-500`}),g,` running`]})]}),(0,J.jsxs)(`div`,{className:`flex items-center gap-2 text-xs text-muted-foreground`,children:[(0,J.jsxs)(`span`,{children:[m.length,` total agents`]}),(0,J.jsx)(Tm,{current:o,max:s,showLabel:!0})]})]}),(0,J.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,J.jsxs)(`span`,{className:`text-xs text-muted-foreground tabular-nums font-mono`,children:[`↓`,dp(i),` ↑`,dp(a),` · `,up(h)]}),(0,J.jsx)(`span`,{className:`text-xs text-muted-foreground tabular-nums font-mono`,children:r?`👑 ${n.get(r)?.name??r}`:`no leader`}),(0,J.jsx)(`button`,{type:`button`,onClick:e,className:`p-1.5 rounded-md hover:bg-muted transition-colors`,"aria-label":`Close fleet monitor`,children:(0,J.jsx)(I,{className:`h-4 w-4`})})]})]}),(0,J.jsxs)(`div`,{className:`flex-1 flex overflow-hidden`,children:[(0,J.jsxs)(`div`,{className:X(`flex flex-col border-r transition-all duration-200`,_?`w-[500px] shrink-0`:`w-full`),children:[(0,J.jsx)(`div`,{className:`border-b bg-card/80 px-3 py-2`,children:(0,J.jsxs)(`div`,{className:`grid grid-cols-[140px_60px_1fr_60px_60px_60px_60px_50px_50px] gap-x-2 text-[9px] uppercase tracking-wider text-muted-foreground font-medium`,children:[(0,J.jsx)(`span`,{children:`Name`}),(0,J.jsx)(`span`,{children:`Status`}),(0,J.jsx)(`span`,{children:`Activity`}),(0,J.jsx)(`span`,{children:`Iters`}),(0,J.jsx)(`span`,{children:`Tools`}),(0,J.jsx)(`span`,{children:`Cost`}),(0,J.jsx)(`span`,{children:`CTX`}),(0,J.jsx)(`span`,{children:`Ext`}),(0,J.jsx)(`span`,{children:`Reason`})]})}),(0,J.jsx)(`div`,{className:`flex-1 overflow-y-auto`,children:m.length===0?(0,J.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full text-muted-foreground`,children:[(0,J.jsx)(Mr,{className:`h-12 w-12 mb-3 opacity-20`}),(0,J.jsx)(`p`,{className:`text-sm font-medium`,children:`No agents active`}),(0,J.jsx)(`p`,{className:`text-xs mt-1`,children:`Agents appear here when the fleet is active.`})]}):(0,J.jsx)(`div`,{className:`p-2 space-y-0.5`,children:m.map((e,t)=>(0,J.jsx)(jm,{agent:e,isSelected:t===u,isLeader:e.id===r,onClick:()=>v(t)},e.id))})}),(0,J.jsxs)(`div`,{className:`border-t bg-card/80 shrink-0`,children:[(0,J.jsx)(`div`,{className:`px-4 py-2 border-b`,children:(0,J.jsxs)(`span`,{className:`text-[10px] uppercase tracking-wider text-muted-foreground font-medium flex items-center gap-2`,children:[(0,J.jsx)(Fr,{className:`h-3 w-3`}),`Agent Timeline`]})}),(0,J.jsx)(`div`,{className:`px-4 py-2 max-h-32 overflow-y-auto`,children:(0,J.jsx)(Om,{events:c,max:10})}),(0,J.jsx)(`div`,{className:`border-t border-dashed`}),(0,J.jsx)(`div`,{className:`px-4 py-2 max-h-40 overflow-y-auto`,children:l.length===0?(0,J.jsx)(`p`,{className:`text-[10px] text-muted-foreground italic`,children:`No agent conversation events yet.`}):(0,J.jsx)(`div`,{className:`space-y-1`,children:l.slice(0,15).map(e=>{let t={text:`💬`,tool_use:`🔧`,error:`❌`,status:`💬`}[e.kind]??`●`,n=e.status===`running`||e.status===`spawned`?`text-emerald-500`:e.status===`failed`||e.status===`timeout`?`text-destructive`:`text-muted-foreground`;return(0,J.jsxs)(`div`,{className:`flex items-start gap-1.5 text-[10px] leading-tight`,children:[(0,J.jsx)(`span`,{className:`shrink-0`,children:t}),(0,J.jsx)(`span`,{className:`font-medium text-primary shrink-0`,children:e.agentName}),e.status&&(0,J.jsx)(`span`,{className:`${n} shrink-0`,children:e.status}),e.toolName&&(0,J.jsxs)(`span`,{className:`text-muted-foreground shrink-0`,children:[`[`,e.toolName,`]`]}),(0,J.jsx)(`span`,{className:`text-muted-foreground truncate`,children:e.content})]},e.id)})})}),(0,J.jsxs)(`div`,{className:`px-4 py-1.5 border-t text-[10px] text-muted-foreground flex items-center gap-4`,children:[(0,J.jsx)(`span`,{children:`↑↓ navigate`}),(0,J.jsx)(`span`,{children:`↵ select detail`}),(0,J.jsx)(`span`,{children:`Esc deselect / close`})]})]})]}),_&&(0,J.jsx)(`div`,{className:`flex-1 overflow-hidden bg-card/50`,children:(0,J.jsxs)(`div`,{className:`h-full flex flex-col`,children:[(0,J.jsxs)(`div`,{className:`shrink-0 px-4 py-2 border-b bg-card/80 flex items-center gap-2`,children:[(0,J.jsx)(ur,{className:`h-4 w-4 text-primary`}),(0,J.jsx)(`span`,{className:`text-xs font-semibold text-primary`,children:_.name}),(0,J.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:`detailed view`}),(0,J.jsx)(`button`,{type:`button`,onClick:()=>d(null),className:`ml-auto text-[10px] text-muted-foreground hover:text-foreground transition-colors flex items-center gap-1`,children:`✕ close`})]}),(0,J.jsx)(`div`,{className:`flex-1 overflow-hidden`,children:(0,J.jsx)(Am,{agent:_,now:f})})]})}),!_&&m.length>0&&(0,J.jsx)(`div`,{className:`flex-1 flex items-center justify-center bg-muted/20`,children:(0,J.jsxs)(`div`,{className:`text-center space-y-3 max-w-sm`,children:[(0,J.jsx)(Mr,{className:`h-12 w-12 text-muted-foreground/30 mx-auto`}),(0,J.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Select an agent to view detailed information`}),(0,J.jsx)(`p`,{className:`text-xs text-muted-foreground/60`,children:`Click on any agent in the list to see detailed metrics, tool logs, streaming output, and more — similar to the chat history detailed view.`}),(0,J.jsxs)(`div`,{className:`flex items-center justify-center gap-4 pt-2`,children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[10px] text-muted-foreground`,children:[(0,J.jsx)(`kbd`,{className:`px-1.5 py-0.5 rounded bg-muted border text-[9px]`,children:`↑`}),(0,J.jsx)(`kbd`,{className:`px-1.5 py-0.5 rounded bg-muted border text-[9px]`,children:`↓`}),(0,J.jsx)(`span`,{children:`navigate`})]}),(0,J.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[10px] text-muted-foreground`,children:[(0,J.jsx)(`kbd`,{className:`px-1.5 py-0.5 rounded bg-muted border text-[9px]`,children:`Enter`}),(0,J.jsx)(`span`,{children:`select`})]}),(0,J.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[10px] text-muted-foreground`,children:[(0,J.jsx)(`kbd`,{className:`px-1.5 py-0.5 rounded bg-muted border text-[9px]`,children:`Esc`}),(0,J.jsx)(`span`,{children:`deselect`})]})]})]})})]})]})]})}var Nm={shell:l,package:gr,network:at,"fs.write":_t,config:_t},Pm={shell:`text-orange-400`,package:`text-blue-400`,network:`text-green-400`,"fs.write":`text-purple-400`,config:`text-yellow-400`},Fm=[`all`,`shell`,`package`,`network`,`fs.write`,`config`];function Im(e){try{return new Date(e).toLocaleTimeString([],{hour:`2-digit`,minute:`2-digit`,second:`2-digit`})}catch{return e.slice(11,19)}}function Lm(e){if(e.input.command)return String(e.input.command).slice(0,80);if(e.input.url)return String(e.input.url).slice(0,80);if(e.input.packages){let t=e.input.packages;return Array.isArray(t)?t.join(`, `).slice(0,80):String(t).slice(0,80)}return JSON.stringify(e.input).slice(0,80)}function Rm(e){return/[",\n]/.test(e)?`"${e.replace(/"/g,`""`)}"`:e}function zm(e){let t=[`timestamp,tool,risk,detail,outcome`,...e.map(e=>{let t=e.input.command??e.input.url??e.input.packages??JSON.stringify(e.input);return[Rm(e.ts),Rm(e.toolName),Rm(e.risk),Rm(String(t)),Rm(e.outcome??``)].join(`,`)})].join(`
|
|
136
|
+
Triggers: user says "keyword", "another".`,rows:4,className:`w-full px-3 py-2 text-xs rounded border border-border bg-background focus:outline-none focus:ring-1 focus:ring-ring resize-y`})]}),(0,J.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,J.jsx)(`label`,{className:`text-xs text-muted-foreground`,children:`Save in:`}),(0,J.jsxs)(`div`,{className:`flex rounded border border-border overflow-hidden`,children:[(0,J.jsx)(`button`,{type:`button`,onClick:()=>F(`project`),className:X(`px-2 py-1 text-[10px] transition-colors`,P===`project`?`bg-primary text-primary-foreground`:`bg-background hover:bg-accent`),children:`Project`}),(0,J.jsx)(`button`,{type:`button`,onClick:()=>F(`global`),className:X(`px-2 py-1 text-[10px] transition-colors border-l border-border`,P===`global`?`bg-primary text-primary-foreground`:`bg-background hover:bg-accent`),children:`Global`})]})]}),te&&(0,J.jsx)(`p`,{className:`text-xs text-destructive bg-destructive/10 rounded px-2 py-1`,children:te}),ne&&(0,J.jsx)(`p`,{className:`text-xs text-emerald-600 dark:text-emerald-400 bg-emerald-500/10 rounded px-2 py-1`,children:ne})]}),(0,J.jsxs)(`div`,{className:`flex justify-end gap-2 p-4 border-t bg-muted/20`,children:[(0,J.jsx)(`button`,{type:`button`,onClick:()=>k(!1),className:`px-3 py-1.5 text-xs rounded border border-border hover:bg-accent transition-colors`,children:ne?`Close`:`Cancel`}),!ne&&(0,J.jsxs)(`button`,{type:`button`,onClick:le,disabled:I||!A.trim()||!M.trim(),className:`flex items-center gap-1.5 px-3 py-1.5 text-xs rounded bg-primary text-primary-foreground hover:bg-primary/90 disabled:opacity-50 disabled:cursor-not-allowed transition-colors`,children:[I&&(0,J.jsx)(z,{className:`h-3 w-3 animate-spin`}),`Create Skill`]})]})]})})]})}var zp=[`web`,`react-native`,`flutter`,`swiftui`,`compose`],Bp=[`bg`,`surface`,`primary`,`accent`,`fg`,`border`];function Vp({tokens:e,label:t}){let n=Bp.filter(t=>e[t]);return n.length===0?null:(0,J.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,J.jsx)(`span`,{className:`text-[9px] uppercase tracking-wide text-muted-foreground w-7`,children:t}),(0,J.jsx)(`div`,{className:`flex gap-0.5`,children:n.map(t=>(0,J.jsx)(`div`,{className:`w-4 h-4 rounded-sm border border-black/10 dark:border-white/10`,style:{backgroundColor:e[t]},title:`${t}: ${e[t]}`},t))})]})}function Hp({className:e}){let{client:t}=Q(),n=q(e=>e.setCurrentView),[r,a]=(0,H.useState)([]),[o,s]=(0,H.useState)(null),[c,l]=(0,H.useState)(!0),[u,d]=(0,H.useState)(`web`),[f,p]=(0,H.useState)(null);(0,H.useEffect)(()=>{if(!t)return;let e=e=>{let t=e.payload;a(t?.kits??[]),s(t?.activeKit??null),l(!1)},n=e=>{let t=e.payload;p(null),t?.ok&&t.kit&&s(t.kit)};return t.on(`design.list`,e),t.on(`design.use`,n),t.send({type:`design.list`}),()=>{t.off(`design.list`,e),t.off(`design.use`,n)}},[t]);let m=(0,H.useCallback)(e=>{t&&(p(e),t.send({type:`design.use`,payload:{kit:e,stack:u}}))},[t,u]),h=(0,H.useMemo)(()=>[...r].sort((e,t)=>e.name.localeCompare(t.name)),[r]);return(0,J.jsxs)(`div`,{className:X(`flex flex-col h-full`,e),children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-2 px-3 py-2 border-b border-border/50`,children:[(0,J.jsx)(vt,{className:`w-4 h-4 text-muted-foreground`}),(0,J.jsx)(`span`,{className:`text-xs text-muted-foreground flex-1`,children:`Pick a kit — the agent will adhere to it.`}),(0,J.jsxs)(`button`,{type:`button`,onClick:()=>n(`design-gallery`),className:`inline-flex items-center gap-1 text-[11px] px-1.5 py-0.5 rounded border border-border/60 hover:bg-muted`,title:`Open live preview gallery`,children:[(0,J.jsx)(Pr,{className:`w-3 h-3`}),` Gallery`]}),(0,J.jsx)(`select`,{value:u,onChange:e=>d(e.target.value),className:`text-[11px] bg-transparent border border-border/60 rounded px-1 py-0.5`,title:`Target stack`,children:zp.map(e=>(0,J.jsx)(`option`,{value:e,children:e},e))})]}),(0,J.jsxs)(`div`,{className:`flex-1 overflow-y-auto p-2 space-y-2`,children:[c&&(0,J.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-muted-foreground p-3`,children:[(0,J.jsx)(z,{className:`w-4 h-4 animate-spin`}),` Loading kits…`]}),!c&&h.length===0&&(0,J.jsx)(`p`,{className:`text-sm text-muted-foreground p-3`,children:`No design kits found.`}),h.map(e=>{let t=o===e.id;return(0,J.jsxs)(`div`,{className:X(`rounded-lg border p-3 transition-colors`,t?`border-primary/60 bg-primary/5`:`border-border/60 hover:border-border`),children:[(0,J.jsxs)(`div`,{className:`flex items-start justify-between gap-2`,children:[(0,J.jsxs)(`div`,{className:`min-w-0`,children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,J.jsx)(`h3`,{className:`text-sm font-semibold truncate`,children:e.name}),t&&(0,J.jsxs)(`span`,{className:`inline-flex items-center gap-0.5 text-[9px] font-semibold uppercase text-primary`,children:[(0,J.jsx)(i,{className:`w-3 h-3`}),` Active`]})]}),(0,J.jsx)(`p`,{className:`text-[11px] text-muted-foreground leading-snug mt-0.5`,children:e.aesthetic})]}),(0,J.jsx)(`button`,{type:`button`,onClick:()=>m(e.id),disabled:f===e.id,className:X(`shrink-0 text-[11px] px-2 py-1 rounded font-medium`,t?`bg-primary/10 text-primary`:`bg-primary text-primary-foreground hover:opacity-90`),children:f===e.id?`…`:t?`Reapply`:`Use`})]}),(0,J.jsxs)(`div`,{className:`mt-2 space-y-1`,children:[(0,J.jsx)(Vp,{tokens:e.light,label:`Light`}),(0,J.jsx)(Vp,{tokens:e.dark,label:`Dark`})]}),e.bestFor&&(0,J.jsxs)(`p`,{className:`text-[10px] text-muted-foreground mt-2 leading-snug`,children:[(0,J.jsx)(`span`,{className:`font-medium`,children:`Best for:`}),` `,e.bestFor]}),(0,J.jsx)(`div`,{className:`flex flex-wrap gap-1 mt-1.5`,children:e.stacks.map(e=>(0,J.jsx)(`span`,{className:`text-[9px] px-1 py-0.5 rounded bg-muted text-muted-foreground`,children:e},e))})]},e.id)})]})]})}var Up=e=>e?e.replace(/^wstack\/ap\//,``):`(detached)`,Wp=new Set([`allocating`,`active`,`committing`,`merging`]),Gp={active:`text-amber-500`,committing:`text-cyan-500`,merging:`text-blue-500`,merged:`text-emerald-500`,"needs-review":`text-fuchsia-500`,failed:`text-rose-500`,orphan:`text-zinc-400`};function Kp(){let{client:e}=Q(),t=Si(e=>e.worktrees),n=Si(e=>e.orphans),i=Si(e=>e.baseBranch),a=Si(e=>e.canClean),o=Si(e=>e.cleanResult),s=Si(e=>e.mergeResult),c=Si(e=>e.diffByDir),[u,d]=(0,H.useState)(null),[f,p]=(0,H.useState)(null),m=(0,H.useMemo)(()=>e?e.send.bind(e):void 0,[e]);(0,H.useEffect)(()=>{m?.({type:`worktree.scan`})},[m]),(0,H.useEffect)(()=>{d(null)},[s,o]);let h=(0,H.useMemo)(()=>{let e=new Set(t.map(e=>e.branch)),r=t.map(e=>({branch:e.branch,dir:e.dir,status:e.status,baseBranch:e.baseBranch,insertions:e.insertions,deletions:e.deletions,files:e.files,owner:e.ownerLabel,live:Wp.has(e.status)}));for(let t of n)t.branch&&e.has(t.branch)||r.push({branch:t.branch,dir:t.dir,status:`orphan`,insertions:0,deletions:0,files:0,live:!1});return r},[t,n]),g=(e,t)=>{e&&m?.({type:`shell.open`,payload:{path:e,target:t}})},_=e=>{e&&(m?.({type:`worktree.diff`,payload:{dir:e}}),p(t=>t===e?null:e))},v=async e=>{e&&await vc({title:`Merge ${Up(e)} into ${i||`base`}?`,message:`Squash-merges this branch onto the base branch. Aborts cleanly if it conflicts.`,confirmLabel:`Merge`})&&(d(e),m?.({type:`worktree.merge`,payload:{branch:e}}))},y=async e=>{await vc({title:`Remove ${Up(e.branch)}?`,message:`Force-removes the worktree checkout and deletes its branch. Un-merged work is discarded.`,confirmLabel:`Remove`,danger:!0})&&(d(e.branch??``),m?.({type:`worktree.remove`,payload:{dir:e.dir,branch:e.branch}}))};return(0,J.jsxs)(`div`,{className:`flex h-full flex-col`,children:[(0,J.jsxs)(`div`,{className:`flex items-center justify-between gap-2 px-3 py-2`,children:[(0,J.jsxs)(`span`,{className:`text-[11px] text-muted-foreground`,children:[h.length,` worktree`,h.length===1?``:`s`,i?` · base ${i}`:``]}),(0,J.jsxs)(`div`,{className:`flex items-center gap-1`,children:[n.length>0&&(0,J.jsxs)(`button`,{type:`button`,disabled:!a,onClick:()=>m?.({type:`worktree.cleanup`}),title:a?`Remove all orphaned worktrees`:`A run is live — stop it first`,className:`inline-flex items-center gap-1 rounded bg-amber-600/90 px-1.5 py-0.5 text-[11px] font-medium text-white hover:bg-amber-700 disabled:opacity-50`,children:[(0,J.jsx)(We,{className:`h-3 w-3`}),` Clean orphans`]}),(0,J.jsx)(`button`,{type:`button`,onClick:()=>m?.({type:`worktree.scan`}),title:`Rescan`,className:`rounded p-1 text-muted-foreground hover:bg-muted hover:text-foreground`,children:(0,J.jsx)(Ct,{className:`h-3.5 w-3.5`})})]})]}),o&&(0,J.jsx)(Jp,{ok:o.ok,children:o.ok?`Removed ${o.removed} worktree(s).`:o.reason??`Failed`}),s&&(0,J.jsx)(Jp,{ok:s.ok,children:s.ok?`Merged ${Up(s.branch)} into base.`:s.conflict?`Conflict merging ${Up(s.branch)}: ${(s.conflictFiles??[]).join(`, `)||`see git`}`:`Merge failed: ${s.reason??`unknown`}`}),(0,J.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto px-2 pb-3`,children:h.length===0?(0,J.jsxs)(`div`,{className:`flex h-full flex-col items-center justify-center gap-2 text-center text-xs text-muted-foreground`,children:[(0,J.jsx)(r,{className:`h-8 w-8 opacity-30`}),(0,J.jsx)(`p`,{children:`No worktrees.`}),(0,J.jsx)(`p`,{className:`max-w-[200px]`,children:`SDD / AutoPhase runs create isolated worktrees here. Orphans from crashed runs show up too.`})]}):h.map((e,t)=>{let n=u===(e.branch??``),i=e.dir?c[e.dir]:void 0;return(0,J.jsxs)(`div`,{className:`mb-1.5 rounded-md border border-border bg-card/60 px-2.5 py-2`,children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,J.jsx)(r,{className:X(`h-3.5 w-3.5 shrink-0`,Gp[e.status]??`text-muted-foreground`)}),(0,J.jsx)(`span`,{className:`min-w-0 flex-1 truncate font-mono text-xs text-foreground`,title:e.branch,children:Up(e.branch)}),(0,J.jsx)(`span`,{className:X(`shrink-0 text-[10px] uppercase`,Gp[e.status]??`text-muted-foreground`),children:e.status})]}),(0,J.jsxs)(`div`,{className:`mt-0.5 flex items-center gap-2 pl-5 text-[10px] text-muted-foreground`,children:[e.owner&&(0,J.jsx)(`span`,{className:`truncate`,children:e.owner}),(e.insertions>0||e.deletions>0)&&(0,J.jsxs)(`span`,{className:`shrink-0`,children:[(0,J.jsxs)(`span`,{className:`text-emerald-500`,children:[`+`,e.insertions]}),` `,(0,J.jsxs)(`span`,{className:`text-rose-500`,children:[`−`,e.deletions]}),` · `,e.files,`f`]})]}),(0,J.jsxs)(`div`,{className:`mt-1.5 flex items-center gap-0.5 pl-5`,children:[(0,J.jsx)(qp,{title:`Open in terminal`,disabled:!e.dir,onClick:()=>g(e.dir,`terminal`),children:(0,J.jsx)(l,{className:`h-3.5 w-3.5`})}),(0,J.jsx)(qp,{title:`Open folder`,disabled:!e.dir,onClick:()=>g(e.dir,`file-manager`),children:(0,J.jsx)(wt,{className:`h-3.5 w-3.5`})}),(0,J.jsx)(qp,{title:`View changes`,disabled:!e.dir,onClick:()=>_(e.dir),children:(0,J.jsx)(Be,{className:`h-3.5 w-3.5`})}),(0,J.jsx)(qp,{title:`Merge to base`,disabled:e.live||!e.branch,onClick:()=>v(e.branch),children:n?(0,J.jsx)(z,{className:`h-3.5 w-3.5 animate-spin`}):(0,J.jsx)(pt,{className:`h-3.5 w-3.5`})}),(0,J.jsx)(qp,{title:`Remove / discard`,danger:!0,disabled:e.live,onClick:()=>y(e),children:(0,J.jsx)(Te,{className:`h-3.5 w-3.5`})}),e.live&&(0,J.jsx)(`span`,{className:`ml-1 text-[10px] text-amber-500`,children:`live`})]}),f===e.dir&&i!==void 0&&(0,J.jsx)(`div`,{className:`mt-1.5 ml-5 rounded bg-muted/50 p-1.5 text-[10px]`,children:i===null||i.files.length===0?(0,J.jsxs)(`span`,{className:`text-muted-foreground`,children:[`No uncommitted changes`,i&&i.commits>0?` · ${i.commits} commit(s) ahead`:``,`.`]}):(0,J.jsxs)(J.Fragment,{children:[(0,J.jsxs)(`div`,{className:`mb-1 text-muted-foreground`,children:[i.commits>0?`${i.commits} commit(s) ahead · `:``,(0,J.jsxs)(`span`,{className:`text-emerald-500`,children:[`+`,i.insertions]}),` `,(0,J.jsxs)(`span`,{className:`text-rose-500`,children:[`−`,i.deletions]})]}),i.files.slice(0,12).map(e=>(0,J.jsxs)(`div`,{className:`truncate font-mono`,children:[(0,J.jsxs)(`span`,{className:`text-emerald-500`,children:[`+`,e.insertions]}),` `,(0,J.jsxs)(`span`,{className:`text-rose-500`,children:[`−`,e.deletions]}),` `,e.path]},e.path)),i.files.length>12&&(0,J.jsxs)(`div`,{className:`text-muted-foreground`,children:[`…`,i.files.length-12,` more`]})]})})]},`${e.branch??e.dir??t}`)})})]})}function qp({title:e,onClick:t,disabled:n,danger:r,children:i}){return(0,J.jsx)(`button`,{type:`button`,title:e,disabled:n,onClick:t,className:X(`rounded p-1 text-muted-foreground hover:bg-muted disabled:cursor-not-allowed disabled:opacity-30`,r?`hover:text-rose-500`:`hover:text-foreground`),children:i})}function Jp({ok:e,children:t}){return(0,J.jsxs)(`div`,{className:X(`flex items-start gap-1.5 border-y px-3 py-1.5 text-[11px]`,e?`border-emerald-500/30 bg-emerald-500/5 text-emerald-600 dark:text-emerald-300`:`border-amber-500/30 bg-amber-500/5 text-amber-600 dark:text-amber-300`),children:[e?(0,J.jsx)(M,{className:`mt-0.5 h-3.5 w-3.5 shrink-0`}):(0,J.jsx)(Ge,{className:`mt-0.5 h-3.5 w-3.5 shrink-0`}),(0,J.jsx)(`span`,{className:`min-w-0 flex-1`,children:t}),!e&&(0,J.jsx)(I,{className:`mt-0.5 h-3 w-3 shrink-0 opacity-40`})]})}function Yp({label:e,checked:t,onChange:n}){return(0,J.jsxs)(`button`,{type:`button`,onClick:()=>n(!t),className:`flex w-full items-center justify-between px-2 py-1.5 rounded text-xs hover:bg-accent/50 transition-colors`,children:[(0,J.jsx)(`span`,{className:`text-foreground`,children:e}),(0,J.jsx)(`span`,{className:X(`relative inline-flex h-4 w-7 shrink-0 items-center rounded-full transition-colors`,t?`bg-primary`:`bg-muted`),children:(0,J.jsx)(`span`,{className:X(`inline-block h-3 w-3 transform rounded-full bg-background transition-transform`,t?`translate-x-3.5`:`translate-x-0.5`)})})]})}var Xp=[{value:`dots`,label:`Dots`},{value:`lines`,label:`Lines`},{value:`cross`,label:`Cross`},{value:`none`,label:`None`}];function Zp(){let{showHud:e,showLegend:t,showMinimap:n,showControls:r,animateEdges:i,background:a,setShowHud:o,setShowLegend:s,setShowMinimap:c,setShowControls:l,setAnimateEdges:u,setBackground:d}=xa(),{clientCounts:f,currentSession:p,totalAgents:m,activeAgents:h}=da(),g=f.tui+f.webui+f.repl;return(0,J.jsxs)(`div`,{className:`flex flex-col h-full overflow-y-auto p-3 gap-4`,children:[(0,J.jsxs)(`div`,{children:[(0,J.jsx)(`div`,{className:`text-[10px] font-semibold text-muted-foreground uppercase tracking-wide mb-2`,children:`Live`}),(0,J.jsxs)(`div`,{className:`space-y-1.5 text-xs`,children:[(0,J.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,J.jsxs)(`span`,{className:`flex items-center gap-1.5 text-muted-foreground`,children:[(0,J.jsx)(Mr,{className:`h-3.5 w-3.5`}),` Clients`]}),(0,J.jsx)(`span`,{className:`font-mono`,children:g})]}),(0,J.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,J.jsxs)(`span`,{className:`flex items-center gap-1.5 text-muted-foreground`,children:[(0,J.jsx)(Yn,{className:`h-3.5 w-3.5`}),` Agents`]}),(0,J.jsxs)(`span`,{className:`font-mono`,children:[h,(0,J.jsxs)(`span`,{className:`text-muted-foreground`,children:[` / `,m]})]})]}),p.model&&(0,J.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,J.jsxs)(`span`,{className:`flex items-center gap-1.5 text-muted-foreground`,children:[(0,J.jsx)(_e,{className:`h-3.5 w-3.5`}),` Model`]}),(0,J.jsx)(`span`,{className:`font-mono truncate max-w-[140px]`,title:p.model,children:p.model.split(`/`).pop()})]}),p.mode&&(0,J.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,J.jsxs)(`span`,{className:`flex items-center gap-1.5 text-muted-foreground`,children:[(0,J.jsx)(Bt,{className:`h-3.5 w-3.5`}),` Mode`]}),(0,J.jsx)(`span`,{className:`font-mono uppercase text-[10px]`,children:p.mode})]}),(0,J.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,J.jsxs)(`span`,{className:`flex items-center gap-1.5 text-muted-foreground`,children:[(0,J.jsx)(_t,{className:`h-3.5 w-3.5`}),` Tool calls`]}),(0,J.jsx)(`span`,{className:`font-mono`,children:(e=>e?.toLocaleString()??`0`)(p.toolCalls)})]})]})]}),(0,J.jsxs)(`div`,{children:[(0,J.jsx)(`div`,{className:`text-[10px] font-semibold text-muted-foreground uppercase tracking-wide mb-1`,children:`Display`}),(0,J.jsxs)(`div`,{className:`space-y-0.5`,children:[(0,J.jsx)(Yp,{label:`Stats HUD`,checked:e,onChange:o}),(0,J.jsx)(Yp,{label:`Legends`,checked:t,onChange:s}),(0,J.jsx)(Yp,{label:`Minimap`,checked:n,onChange:c}),(0,J.jsx)(Yp,{label:`Zoom controls`,checked:r,onChange:l}),(0,J.jsx)(Yp,{label:`Animate wires`,checked:i,onChange:u})]})]}),(0,J.jsxs)(`div`,{children:[(0,J.jsx)(`div`,{className:`text-[10px] font-semibold text-muted-foreground uppercase tracking-wide mb-1.5 px-2`,children:`Background`}),(0,J.jsx)(`div`,{className:`flex flex-wrap gap-1 px-2`,children:Xp.map(e=>(0,J.jsx)(`button`,{type:`button`,onClick:()=>d(e.value),className:X(`px-2 py-1 text-[10px] rounded transition-colors`,a===e.value?`bg-primary text-primary-foreground`:`bg-muted text-muted-foreground hover:bg-accent`),children:e.label},e.value))})]})]})}var Qp={chat:`Session`,agents:`Agents`,history:`History`,files:`Files`,changes:`Changes`,projects:`Projects`,mailbox:`Mailbox`,skills:`Skills`,design:`Design Studio`,worktrees:`Worktrees`,officemap:`Office Map`};function $p(){let e=q(e=>e.activeActivity),t=q(e=>e.setSidebarOpen),n=q(e=>e.sidebarWidth),r=q(e=>e.setSidebarWidth),i=G(e=>e.wsConnected),{client:a}=Q();return(0,H.useEffect)(()=>{if(e!==`files`||!i)return;Yi.getState().setTreeLoading(!0);let t=K.getState().cwd;a?.send({type:`files.tree`,payload:t?{path:t}:{}})},[e,i,a]),(0,J.jsxs)(`aside`,{style:{width:`${n}px`},className:`relative border-r bg-card flex flex-col shrink-0 overflow-hidden animate-slide-in`,children:[(0,J.jsx)(`div`,{onMouseDown:e=>{e.preventDefault();let t=e.clientX,i=n,a=e=>r(i+(e.clientX-t)),o=()=>{window.removeEventListener(`mousemove`,a),window.removeEventListener(`mouseup`,o),document.body.style.cursor=``,document.body.style.userSelect=``};window.addEventListener(`mousemove`,a),window.addEventListener(`mouseup`,o),document.body.style.cursor=`col-resize`,document.body.style.userSelect=`none`},onDoubleClick:()=>r(304),className:`group/handle absolute top-0 right-0 h-full w-2 cursor-col-resize z-10 flex items-center justify-end`,title:`Drag to resize · double-click to reset`,children:(0,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:`flex items-center justify-between px-3 py-2.5 border-b shrink-0`,children:[(0,J.jsx)(`span`,{className:`text-xs font-semibold tracking-tight text-muted-foreground uppercase`,children:Qp[e]}),(0,J.jsx)($,{variant:`ghost`,size:`icon`,className:`h-6 w-6`,onClick:()=>t(!1),title:`Collapse panel (Ctrl+\\)`,children:(0,J.jsx)(Zt,{className:`h-3.5 w-3.5`})})]}),(0,J.jsxs)(`div`,{className:`flex-1 flex flex-col overflow-hidden`,children:[e===`chat`&&(0,J.jsx)(Fp,{}),e===`agents`&&(0,J.jsx)(bp,{}),e===`history`&&(0,J.jsx)(Op,{}),e===`files`&&(0,J.jsx)(`div`,{className:`flex-1 overflow-y-auto`,children:(0,J.jsx)(Qf,{})}),e===`changes`&&(0,J.jsx)(wp,{}),e===`projects`&&(0,J.jsx)(`div`,{className:`flex-1 overflow-y-auto p-3`,children:(0,J.jsx)(np,{})}),e===`mailbox`&&(0,J.jsx)(`div`,{className:`flex-1 overflow-y-auto p-3`,children:(0,J.jsx)(tp,{})}),e===`skills`&&(0,J.jsx)(`div`,{className:`flex-1 overflow-hidden`,children:(0,J.jsx)(Rp,{className:`h-full`})}),e===`design`&&(0,J.jsx)(`div`,{className:`flex-1 overflow-hidden`,children:(0,J.jsx)(Hp,{className:`h-full`})}),e===`worktrees`&&(0,J.jsx)(`div`,{className:`flex-1 overflow-hidden`,children:(0,J.jsx)(Kp,{})}),e===`officemap`&&(0,J.jsx)(`div`,{className:`flex-1 overflow-hidden`,children:(0,J.jsx)(Zp,{})})]})]})}function em(){let e=vi(e=>e.info),{client:t}=Q(),n=(0,H.useRef)(null),r=(0,H.useCallback)(()=>{t?.getGitInfo?.()},[t]);return(0,H.useEffect)(()=>(r(),n.current=setInterval(r,3e4),()=>{n.current&&clearInterval(n.current)}),[r]),e}function tm({sessionId:e,className:t}){let[n,r]=(0,H.useState)([]),[i,a]=(0,H.useState)(!1),[o,c]=(0,H.useState)(null),[l,u]=(0,H.useState)(null),[d,f]=(0,H.useState)(0),[p,m]=(0,H.useState)(!1),[h,g]=(0,H.useState)(!1),[_,v]=(0,H.useState)(``),[y,b]=(0,H.useState)(``),[x,S]=(0,H.useState)(!1),[w,T]=(0,H.useState)(``),E=U(G(e=>e.wsUrl)),D=W(e=>e.messages).filter(e=>e.role===`tool`&&e.toolResult===void 0&&!!e.toolUseId);(0,H.useEffect)(()=>{let t=[];return t.push(E.on(`collab.state`,t=>{let n=t.payload;n.sessionId===e&&r(n.participants??[])})),t.push(E.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(E.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(E.on(`error`,e=>{let t=e.payload;t.phase===`collab`&&(u(t.message),a(!1))})),t.push(E.on(`collab.annotation.added`,t=>{let n=t.payload;n.sessionId===e&&(n.annotation?.resolved||f(e=>e+1))})),t.push(E.on(`collab.annotation.resolved`,t=>{t.payload.sessionId===e&&f(e=>Math.max(0,e-1))})),t.push(E.on(`collab.pause.granted`,t=>{t.payload.sessionId===e&&m(!0)})),t.push(E.on(`collab.pause.released`,t=>{t.payload.sessionId===e&&m(!1)})),()=>{for(let e of t)e()}},[E,e]);let O=(t=`observer`)=>{u(null),E.send({type:`collab.join`,payload:{sessionId:e,role:t}}),a(!0),c(t)},k=()=>{E.send({type:`collab.request_pause`,payload:{sessionId:e}})},A=()=>{E.send({type:`collab.resume`,payload:{sessionId:e}})},j=()=>{E.send({type:`collab.leave`,payload:{sessionId:e}}),a(!1),r([])},M=t=>{E.send({type:`collab.grant_control`,payload:{sessionId:e,toParticipant:t}})},N=()=>{_&&(E.send({type:`collab.inject_tool`,payload:{sessionId:e,toolUseId:_,content:y,isError:x,reason:w.trim()||`controller injection`}}),g(!1),v(``),b(``),S(!1),T(``))},P=i&&o===`controller`;return n.length===0&&!l?(0,J.jsxs)(`div`,{className:X(`flex items-center gap-2 px-3 py-2 rounded-md border border-dashed border-border bg-card/40`,t),children:[(0,J.jsx)(Mr,{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:()=>O(`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)(fn,{className:`w-3 h-3`}),`observer`]}),(0,J.jsxs)(`button`,{type:`button`,onClick:()=>O(`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)(C,{className:`w-3 h-3`}),`annotator`]}),(0,J.jsxs)(`button`,{type:`button`,onClick:()=>O(`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)(Vn,{className:`w-3 h-3`}),`controller`]})]})]}):l?(0,J.jsxs)(`div`,{className:X(`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: `,l]}),(0,J.jsx)(`button`,{type:`button`,onClick:()=>{u(null),a(!1)},className:`ml-auto text-xs underline text-destructive`,children:`dismiss`})]}):(0,J.jsxs)(`div`,{className:X(`relative 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)(Mr,{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`]}),d>0&&(0,J.jsxs)(`span`,{title:`${d} 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)(C,{className:`w-3 h-3`}),d,` note`,d===1?``:`s`]}),p&&(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)(Vn,{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)(Be,{className:`w-3 h-3`}),e.role,P&&e.role!==`controller`&&(0,J.jsx)(`button`,{type:`button`,onClick:()=>M(e.participantId),title:`Grant control — promote this participant to controller`,className:`ml-0.5 inline-flex items-center rounded hover:bg-emerald-500/20 transition-colors`,children:(0,J.jsx)(Dr,{className:`w-3 h-3`})})]},e.participantId)),n.length>3&&(0,J.jsxs)(`span`,{className:`text-[10px] text-muted-foreground`,children:[`+`,n.length-3]})]}),P&&(0,J.jsxs)(`div`,{className:`ml-auto flex items-center gap-1`,children:[(0,J.jsxs)(`button`,{type:`button`,onClick:()=>g(e=>!e),className:`inline-flex items-center gap-1 text-xs px-2 py-1 rounded border border-sky-500/40 bg-sky-500/10 text-sky-700 dark:text-sky-300 hover:bg-sky-500/20 transition-colors`,title:`Inject a synthetic result for an in-flight tool call`,children:[(0,J.jsx)(xe,{className:`w-3 h-3`}),`Inject`]}),p?(0,J.jsxs)(`button`,{type:`button`,onClick:A,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:`Resume the agent loop`,children:[(0,J.jsx)(Nt,{className:`w-3 h-3`}),`Resume`]}):(0,J.jsxs)(`button`,{type:`button`,onClick:k,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:`Pause the agent before the next tool call`,children:[(0,J.jsx)(Vn,{className:`w-3 h-3`}),`Pause agent`]})]}),i&&o!==`controller`&&(0,J.jsxs)(`button`,{type:`button`,onClick:j,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)(s,{className:`w-3 h-3`}),`Leave`]}),P&&h&&(0,J.jsxs)(`div`,{className:`absolute top-full left-0 right-0 mt-1 z-50 flex flex-col gap-2 p-3 rounded-md border border-sky-500/40 bg-card shadow-lg text-xs`,children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,J.jsx)(xe,{className:`w-3.5 h-3.5 text-sky-600 dark:text-sky-400`}),(0,J.jsx)(`span`,{className:`font-medium`,children:`Inject tool result`}),(0,J.jsx)(`button`,{type:`button`,onClick:()=>g(!1),className:`ml-auto text-muted-foreground hover:text-foreground`,children:`close`})]}),(0,J.jsxs)(`label`,{className:`flex flex-col gap-1`,children:[(0,J.jsx)(`span`,{className:`text-muted-foreground`,children:`Target tool_use id`}),(0,J.jsx)(`input`,{list:`collab-inject-tools`,value:_,onChange:e=>v(e.target.value),placeholder:`pick an in-flight call or type a tool_use id`,className:`px-2 py-1 rounded border border-border bg-background font-mono`}),(0,J.jsx)(`datalist`,{id:`collab-inject-tools`,children:D.map(e=>{let t=e.toolInput===void 0?``:` — ${JSON.stringify(e.toolInput).slice(0,40)}`;return(0,J.jsxs)(`option`,{value:e.toolUseId,children:[e.toolName??`tool`,t]},e.toolUseId)})}),D.length===0&&(0,J.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:`No in-flight tool calls — type a tool_use id to pre-queue, or pause the agent first.`})]}),(0,J.jsxs)(`label`,{className:`flex flex-col gap-1`,children:[(0,J.jsx)(`span`,{className:`text-muted-foreground`,children:`Result content`}),(0,J.jsx)(`textarea`,{value:y,onChange:e=>b(e.target.value),rows:3,placeholder:`Synthetic tool result fed to the agent in place of running the tool`,className:`px-2 py-1 rounded border border-border bg-background font-mono`})]}),(0,J.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,J.jsxs)(`label`,{className:`flex items-center gap-1`,children:[(0,J.jsx)(`input`,{type:`checkbox`,checked:x,onChange:e=>S(e.target.checked)}),(0,J.jsx)(`span`,{children:`mark as error`})]}),(0,J.jsx)(`input`,{type:`text`,value:w,onChange:e=>T(e.target.value),placeholder:`reason (audit log)`,className:`flex-1 px-2 py-1 rounded border border-border bg-background`})]}),(0,J.jsxs)(`button`,{type:`button`,onClick:N,disabled:!_,className:`self-end inline-flex items-center gap-1 text-xs px-3 py-1 rounded bg-sky-600 text-white hover:bg-sky-700 disabled:opacity-50 disabled:cursor-not-allowed transition-colors`,children:[(0,J.jsx)(xe,{className:`w-3 h-3`}),`Queue injection`]})]})]})}var nm={up:(0,J.jsx)(T,{className:`h-3.5 w-3.5 text-emerald-500`}),down:(0,J.jsx)(x,{className:`h-3.5 w-3.5 text-red-500`}),stable:(0,J.jsx)(h,{className:`h-3.5 w-3.5 text-amber-500`})},rm={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 im({goal:e,className:t}){let[n,r]=(0,H.useState)(!1);if((0,H.useEffect)(()=>{let e=U();e?.send?.({type:`goal.get`});let t=setInterval(()=>{e?.send?.({type:`goal.get`})},1e4);return()=>clearInterval(t)},[]),(0,H.useEffect)(()=>{(!e||e.goalState===`completed`||e.goalState===`failed`||e.goalState===`abandoned`)&&r(!0)},[e]),!e||e.goalState===`completed`||e.goalState===`failed`||e.goalState===`abandoned`)return null;let i=rm[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?nm[e.progressTrend]:null;return(0,J.jsxs)(`div`,{className:X(`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)(mn,{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:X(`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)(ot,{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:X(`h-full transition-all duration-700 rounded-full`,e.progress>=80?`bg-emerald-500`:e.progress>=50?`bg-amber-500`:`bg-primary`),style:{width:`${e.progress>0?Math.max(2,e.progress):0}%`}})}),e.progressNote&&(0,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)(Fr,{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)(M,{className:`h-3 w-3 text-emerald-500 mt-0.5 shrink-0`}):(0,J.jsx)(Qe,{className:`h-3 w-3 text-muted-foreground/50 mt-0.5 shrink-0`}),(0,J.jsx)(`span`,{className:X(`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}`))})]})]})]})}var am={in_progress:0,pending:1,completed:2};function om(){let[e,t]=(0,H.useState)([]),[n,r]=(0,H.useState)(new Set),i=U(),a=(0,H.useRef)(null);(0,H.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,H.useCallback)(e=>{i.removeTodo(e)},[i]),s=(0,H.useCallback)(e=>{if(e.status===`in_progress`)return;let t=e.status===`completed`?`pending`:`completed`;i.updateTodoStatus(e.id,t)},[i]),c=[...e].sort((e,t)=>(am[e.status]??9)-(am[t.status]??9)),l=c.filter(e=>e.status===`in_progress`),u=c.filter(e=>e.status===`pending`),d=c.filter(e=>e.status===`completed`),f=d.length>0,p=n.has(`completed`),m=e=>{r(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},h=e=>{let t=e.status===`in_progress`&&e.activeForm?e.activeForm:e.content,n=e.status===`in_progress`,r=e.status===`completed`,i=!n;return(0,J.jsxs)(`div`,{onClick:()=>i&&s(e),className:X(`px-3 py-1.5 flex items-start gap-2 text-[13px] group transition-colors`,i&&`cursor-pointer hover:bg-accent/40`,n?`bg-yellow-50/40 dark:bg-yellow-950/25`:r?`bg-emerald-50/20 dark:bg-emerald-950/10`:`bg-background`),role:i?`button`:void 0,"aria-label":i?`Toggle ${e.content}`:void 0,tabIndex:i?0:void 0,onKeyDown:t=>{i&&(t.key===`Enter`||t.key===` `)&&(t.preventDefault(),s(e))},children:[(0,J.jsx)(`span`,{className:`mt-0.5 shrink-0`,children:r?(0,J.jsx)(M,{className:`w-3.5 h-3.5 text-emerald-500`}):n?(0,J.jsx)(Fr,{className:`w-3.5 h-3.5 text-yellow-500 animate-spin`}):(0,J.jsx)(Qe,{className:X(`w-3.5 h-3.5 transition-colors`,`text-muted-foreground/40 group-hover:text-emerald-400`)})}),(0,J.jsx)(`span`,{className:X(`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`,"aria-label":`Remove "${e.content}"`,children:(0,J.jsx)(Te,{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:[d.length,`/`,e.length]})]}),l.length>0&&(0,J.jsx)(`div`,{className:`border-b border-border/30 last:border-b-0`,children:l.map(h)}),u.length>0&&(0,J.jsx)(`div`,{className:`border-b border-border/30 last:border-b-0`,children:u.map(h)}),f&&(0,J.jsxs)(`div`,{children:[(0,J.jsx)(`button`,{type:`button`,onClick:()=>m(`completed`),className:`w-full px-3 py-1 flex items-center gap-1.5 text-[10px] text-muted-foreground hover:text-foreground transition-colors`,children:(0,J.jsxs)(`span`,{className:`tabular`,children:[p?`▶`:`▼`,` `,d.length,` completed`]})}),!p&&d.map(h)]})]})}var sm={pending:{icon:(0,J.jsx)(Qe,{className:`w-3.5 h-3.5`}),label:`Pending`,color:`text-muted-foreground/50`},in_progress:{icon:(0,J.jsx)(Fr,{className:`w-3.5 h-3.5 animate-spin`}),label:`In Progress`,color:`text-yellow-500`},blocked:{icon:(0,J.jsx)(Vn,{className:`w-3.5 h-3.5`}),label:`Blocked`,color:`text-orange-500`},failed:{icon:(0,J.jsx)(I,{className:`w-3.5 h-3.5`}),label:`Failed`,color:`text-red-500`},review:{icon:(0,J.jsx)(or,{className:`w-3.5 h-3.5`}),label:`Review`,color:`text-blue-500`},completed:{icon:(0,J.jsx)(M,{className:`w-3.5 h-3.5`}),label:`Done`,color:`text-emerald-500`}},cm={critical:`text-red-600 dark:text-red-400`,high:`text-orange-600 dark:text-orange-400`,medium:`text-yellow-600 dark:text-yellow-400`,low:`text-muted-foreground`},lm={feature:`⚡`,bugfix:`🐛`,refactor:`♻️`,docs:`📝`,test:`🧪`,chore:`🔧`};function um(){let[e,t]=(0,H.useState)([]),[n,r]=(0,H.useState)(new Set),i=U(),a=(0,H.useRef)(null);(0,H.useEffect)(()=>(i.getTasks(),a.current=i.on(`tasks.updated`,e=>{let n=e?.payload;n?.tasks&&t(n.tasks)}),()=>{a.current?.()}),[i]);let o=(0,H.useCallback)(e=>{r(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),s=(0,H.useCallback)((e,t)=>{i.updateTaskStatus(e,t)},[i]),c=[`in_progress`,`blocked`,`review`,`pending`,`failed`,`completed`],l=new Map;for(let t of e){let e=l.get(t.status)??[];e.push(t),l.set(t.status,e)}let u=l.get(`completed`)?.length??0;return e.length===0?null:(0,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:`Tasks`}),(0,J.jsxs)(`span`,{className:`tabular text-[10px] text-muted-foreground ml-auto`,children:[u,`/`,e.length]})]}),c.map(e=>{let t=l.get(e);if(!t||t.length===0)return null;let r=sm[e],i=n.has(e);return(0,J.jsxs)(`div`,{className:`border-b border-border/30 last:border-b-0`,children:[(0,J.jsx)(`button`,{type:`button`,onClick:()=>o(e),className:`w-full px-3 py-1 flex items-center gap-1.5 text-[10px] text-muted-foreground hover:text-foreground transition-colors`,children:(0,J.jsxs)(`span`,{className:`tabular`,children:[i?`▶`:`▼`,` `,t.length,` `,r.label]})}),!i&&t.map(e=>(0,J.jsxs)(`div`,{className:X(`px-3 py-1.5 flex items-start gap-2 text-[13px] group`,e.status===`in_progress`?`bg-yellow-50/40 dark:bg-yellow-950/25`:``),children:[(0,J.jsx)(`span`,{className:X(`mt-0.5 shrink-0`,r.color),children:r.icon}),(0,J.jsxs)(`span`,{className:`leading-snug flex-1 min-w-0`,children:[(0,J.jsxs)(`span`,{className:X(e.status===`completed`?`text-muted-foreground line-through`:`text-foreground/80`),children:[lm[e.type],` `,e.title]}),e.priority!==`medium`&&(0,J.jsx)(`span`,{className:X(`ml-1 text-[10px]`,cm[e.priority]),children:e.priority}),e.assignee&&(0,J.jsxs)(`span`,{className:`ml-1 text-[10px] text-muted-foreground`,children:[`@`,e.assignee]}),e.estimateHours&&(0,J.jsxs)(`span`,{className:`ml-1 text-[10px] text-muted-foreground`,children:[e.estimateHours,`h`]})]}),(0,J.jsxs)(`div`,{className:`flex gap-0.5 opacity-0 group-hover:opacity-100 transition-opacity shrink-0`,children:[e.status!==`in_progress`&&e.status!==`completed`&&(0,J.jsx)(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),s(e.id,`in_progress`)},className:`px-1.5 py-0.5 text-[9px] rounded bg-primary/15 text-primary hover:bg-primary/25 transition-colors`,title:`Start`,children:`Start`}),e.status===`in_progress`&&(0,J.jsx)(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),s(e.id,`completed`)},className:`px-1.5 py-0.5 text-[9px] rounded bg-[hsl(var(--success)/0.15)] text-[hsl(var(--success))] hover:bg-[hsl(var(--success)/0.25)] transition-colors`,title:`Complete`,children:`Done`}),e.status!==`completed`&&e.status!==`failed`&&(0,J.jsx)(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),s(e.id,`failed`)},className:`px-1.5 py-0.5 text-[9px] rounded bg-destructive/15 text-destructive hover:bg-destructive/25 transition-colors`,title:`Mark failed`,children:`Fail`})]})]},e.id))]},e)})]})}var dm={open:{icon:(0,J.jsx)(Qe,{className:`w-3.5 h-3.5`}),label:`Open`,color:`text-muted-foreground/50`},in_progress:{icon:(0,J.jsx)(Fr,{className:`w-3.5 h-3.5 animate-spin`}),label:`In Progress`,color:`text-yellow-500`},done:{icon:(0,J.jsx)(M,{className:`w-3.5 h-3.5`}),label:`Done`,color:`text-emerald-500`}};function fm(){let[e,t]=(0,H.useState)([]),[n,r]=(0,H.useState)(new Set),i=U(),a=(0,H.useRef)(null);(0,H.useEffect)(()=>(i.getPlan(),a.current=i.on(`plan.updated`,e=>{let n=e?.payload;n?.plan?.items&&t(n.plan.items)}),()=>{a.current?.()}),[i]);let o=(0,H.useCallback)(e=>{r(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),s=(0,H.useCallback)((e,t)=>{i.updatePlanItem(e.id,t)},[i]),c=[`in_progress`,`open`,`done`],l=new Map;for(let t of e){let e=l.get(t.status)??[];e.push(t),l.set(t.status,e)}let u=l.get(`done`)?.length??0;return e.length===0?null:(0,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:`📋 Plan`}),(0,J.jsxs)(`span`,{className:`tabular text-[10px] text-muted-foreground ml-auto`,children:[u,`/`,e.length]})]}),c.map(e=>{let t=l.get(e);if(!t||t.length===0)return null;let r=dm[e],i=n.has(e);return(0,J.jsxs)(`div`,{className:`border-b border-border/30 last:border-b-0`,children:[(0,J.jsx)(`button`,{type:`button`,onClick:()=>o(e),className:`w-full px-3 py-1 flex items-center gap-1.5 text-[10px] text-muted-foreground hover:text-foreground transition-colors`,children:(0,J.jsxs)(`span`,{className:`tabular`,children:[i?`▶`:`▼`,` `,t.length,` `,r.label]})}),!i&&t.map(e=>(0,J.jsxs)(`div`,{className:X(`px-3 py-1.5 flex items-start gap-2 text-[13px] group`,e.status===`in_progress`?`bg-yellow-50/40 dark:bg-yellow-950/25`:``),children:[(0,J.jsx)(`span`,{className:X(`mt-0.5 shrink-0`,r.color),children:r.icon}),(0,J.jsx)(`span`,{className:X(`leading-snug flex-1 min-w-0`,e.status===`done`?`text-muted-foreground line-through`:`text-foreground/80`),children:e.title}),(0,J.jsxs)(`div`,{className:`flex gap-0.5 opacity-0 group-hover:opacity-100 transition-opacity shrink-0`,children:[e.status===`open`&&(0,J.jsx)(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),s(e,`in_progress`)},className:`px-1.5 py-0.5 text-[9px] rounded bg-primary/15 text-primary hover:bg-primary/25 transition-colors`,title:`Start`,children:`Start`}),e.status!==`done`&&(0,J.jsx)(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),s(e,`done`)},className:`px-1.5 py-0.5 text-[9px] rounded bg-[hsl(var(--success)/0.15)] text-[hsl(var(--success))] hover:bg-[hsl(var(--success)/0.25)] transition-colors`,title:`Mark done`,children:`Done`}),e.status===`done`&&(0,J.jsx)(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),s(e,`open`)},className:`px-1.5 py-0.5 text-[9px] rounded bg-muted text-muted-foreground hover:bg-accent hover:text-foreground transition-colors`,title:`Reopen`,children:`Reopen`})]})]},e.id))]},e)})]})}var pm=[{id:`todos`,label:`Todos`,icon:`✅`},{id:`tasks`,label:`Tasks`,icon:`📋`},{id:`plan`,label:`Plan`,icon:`🗺️`}];function mm(){let e=q(e=>e.workDashboardTab),t=q(e=>e.setWorkDashboardTab);return(0,J.jsxs)(`div`,{className:`rounded-lg border border-border bg-card/50 backdrop-blur-sm overflow-hidden`,children:[(0,J.jsx)(`div`,{className:`flex border-b border-border/50 bg-muted/30`,children:pm.map(n=>(0,J.jsxs)(`button`,{type:`button`,onClick:()=>t(n.id),className:X(`flex items-center gap-1 px-3 py-1.5 text-[11px] font-medium transition-colors`,`border-b-2 -mb-px`,e===n.id?`border-primary text-foreground bg-background`:`border-transparent text-muted-foreground hover:text-foreground hover:bg-accent/30`),children:[(0,J.jsx)(`span`,{className:`text-xs`,children:n.icon}),n.label]},n.id))}),(0,J.jsx)(`div`,{className:X(e===`todos`?`block`:`hidden`),children:(0,J.jsx)(om,{})}),(0,J.jsx)(`div`,{className:X(e===`tasks`?`block`:`hidden`),children:(0,J.jsx)(um,{})}),(0,J.jsx)(`div`,{className:X(e===`plan`?`block`:`hidden`),children:(0,J.jsx)(fm,{})})]})}var hm={autophase:{active:`bg-primary/15 border-primary/40 text-primary`,idle:`text-primary/80 hover:bg-primary/10`},goal:{active:`bg-rose-500/15 border-rose-500/40 text-rose-600 dark:text-rose-400`,idle:`text-rose-600/80 dark:text-rose-400/80 hover:bg-rose-500/10`},fleet:{active:`bg-emerald-500/15 border-emerald-500/40 text-emerald-600 dark:text-emerald-400`,idle:`text-emerald-600/80 dark:text-emerald-400/80 hover:bg-emerald-500/10`},work:{active:`bg-amber-500/15 border-amber-500/40 text-amber-600 dark:text-amber-400`,idle:`text-amber-600/80 dark:text-amber-400/80 hover:bg-amber-500/10`},worktrees:{active:`bg-violet-500/15 border-violet-500/40 text-violet-600 dark:text-violet-400`,idle:`text-violet-600/80 dark:text-violet-400/80 hover:bg-violet-500/10`},collab:{active:`bg-cyan-500/15 border-cyan-500/40 text-cyan-600 dark:text-cyan-400`,idle:`text-muted-foreground hover:bg-muted/60`}},gm={autophase:`AutoPhase`,goal:`Goal`,fleet:`Fleet`,work:`Work`,worktrees:`Worktrees`,collab:`Collab`},_m=[`autophase`,`goal`,`fleet`,`work`,`worktrees`,`collab`];function vm({section:e,icon:t,label:n,value:r,active:i,pulse:a,onClick:o}){let s=hm[e];return(0,J.jsxs)(`button`,{type:`button`,onClick:o,title:i?`Collapse ${n}`:`Expand ${n}`,className:X(`flex items-center gap-2 h-7 px-2.5 rounded-full border text-xs font-medium shrink-0 transition-colors`,i?s.active:X(`border-border/40`,s.idle)),children:[(0,J.jsx)(`span`,{className:X(a&&`animate-pulse`),children:t}),n,r&&(0,J.jsx)(`span`,{className:`tabular-nums opacity-80`,children:r})]})}function ym({sessionId:e}){let t=q(e=>e.dockSection),n=q(e=>e.toggleDockSection),i=q(e=>e.setCurrentView),a=q(e=>e.hiddenChips),o=q(e=>e.toggleChipHidden),s=q(e=>e.dockCustomizeOpen),c=q(e=>e.setDockCustomizeOpen),l=Hi(e=>e.goal),u=Ui(e=>e.phases.length),d=Ui(e=>e.overallPercent),f=Ui(e=>e.activePhaseId),p=Si(e=>e.worktrees),m=Si(e=>e.baseBranch),h=K(e=>e.todos),g=Y(e=>e.agents),_=em(),[v,y]=(0,H.useState)(`graph`),b=g.size,x=(0,H.useMemo)(()=>Array.from(g.values()).filter(e=>e.status===`running`).length,[g]),S=h.filter(e=>e.status===`completed`).length,C=h.some(e=>e.status===`in_progress`),w=u>0,T=(0,H.useMemo)(()=>new Set(a),[a]),E={autophase:w,goal:l!==null,fleet:b>0,work:!0,worktrees:p.length>0,collab:!0},D={autophase:E.autophase&&!T.has(`autophase`),goal:E.goal&&!T.has(`goal`),fleet:E.fleet&&!T.has(`fleet`),work:E.work&&!T.has(`work`),worktrees:E.worktrees&&!T.has(`worktrees`),collab:E.collab&&!T.has(`collab`)},O=t&&D[t]?t:null;return(0,J.jsxs)(`div`,{className:`space-y-2`,children:[(0,J.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5 rounded-lg border border-border/50 bg-muted/20 px-2 py-1.5`,children:[D.autophase&&(0,J.jsx)(vm,{section:`autophase`,icon:(0,J.jsx)(jn,{className:`h-3 w-3`}),label:`AutoPhase`,value:`${d}%`,active:!1,pulse:f!=null,onClick:()=>i(`autophase`)}),D.goal&&l&&(0,J.jsx)(vm,{section:`goal`,icon:(0,J.jsx)(mn,{className:`h-3 w-3`}),label:`Goal`,value:`${l.progress}%`,active:O===`goal`,pulse:l.goalState===`active`,onClick:()=>n(`goal`)}),D.fleet&&(0,J.jsx)(vm,{section:`fleet`,icon:(0,J.jsx)(Yn,{className:`h-3 w-3`}),label:`Fleet`,value:`${x}/${b}`,active:O===`fleet`,pulse:x>0,onClick:()=>n(`fleet`)}),(0,J.jsx)(vm,{section:`work`,icon:(0,J.jsx)(De,{className:`h-3 w-3`}),label:`Work`,value:h.length>0?`${S}/${h.length}`:void 0,active:O===`work`,pulse:C,onClick:()=>n(`work`)}),D.worktrees&&(0,J.jsx)(vm,{section:`worktrees`,icon:(0,J.jsx)(r,{className:`h-3 w-3`}),label:`Worktrees`,value:String(p.length),active:O===`worktrees`,onClick:()=>n(`worktrees`)}),_&&(0,J.jsxs)(`button`,{type:`button`,onClick:()=>{},className:`inline-flex items-center gap-1.5 h-7 px-2.5 rounded-full border border-border/40 text-xs font-mono hover:bg-muted/60 transition-colors`,children:[(0,J.jsx)(r,{className:`h-3 w-3 shrink-0 text-muted-foreground`}),(0,J.jsx)(`span`,{className:`font-semibold text-foreground`,children:_.branch}),_.ahead>0&&(0,J.jsxs)(`span`,{className:`text-emerald-600 dark:text-emerald-400`,title:`${_.ahead} ahead`,children:[`↑`,_.ahead]}),_.behind>0&&(0,J.jsxs)(`span`,{className:`text-amber-600 dark:text-amber-400`,title:`${_.behind} behind`,children:[`↓`,_.behind]}),_.added>0&&(0,J.jsxs)(`span`,{className:`text-emerald-600 dark:text-emerald-400`,title:`${_.added} lines added`,children:[`+`,_.added]}),_.deleted>0&&(0,J.jsxs)(`span`,{className:`text-red-600 dark:text-red-400`,title:`${_.deleted} lines deleted`,children:[`-`,_.deleted]}),_.untracked>0&&(0,J.jsxs)(`span`,{className:`text-muted-foreground`,title:`${_.untracked} untracked files`,children:[_.untracked,`?`]})]}),(0,J.jsx)(vm,{section:`collab`,icon:(0,J.jsx)(Mr,{className:`h-3 w-3`}),label:`Collab`,active:O===`collab`,onClick:()=>n(`collab`)}),(0,J.jsxs)(Fs,{open:s,onOpenChange:c,children:[(0,J.jsx)(Is,{asChild:!0,children:(0,J.jsx)(`button`,{type:`button`,title:`Customize dock chips`,className:`ml-auto inline-flex items-center justify-center h-7 w-7 rounded-full border border-border/40 text-muted-foreground hover:bg-muted/60 transition-colors shrink-0`,children:(0,J.jsx)($e,{className:`h-3 w-3`})})}),(0,J.jsxs)(Bs,{align:`end`,className:`w-44`,children:[(0,J.jsx)(Ws,{children:`Dock chips`}),(0,J.jsx)(Gs,{}),_m.map(e=>(0,J.jsx)(Hs,{checked:!T.has(e),onCheckedChange:()=>o(e),onSelect:e=>e.preventDefault(),children:gm[e]},e))]})]})]}),O&&(0,J.jsx)(`div`,{className:`border-t border-border/40 pt-2`}),O===`goal`&&(0,J.jsx)(im,{goal:l}),O===`fleet`&&(0,J.jsx)(gp,{}),O===`worktrees`&&(0,J.jsxs)(`div`,{className:`space-y-2`,children:[(0,J.jsx)(`div`,{className:`flex items-center gap-2`,children:[`graph`,`lanes`].map(e=>(0,J.jsx)(`button`,{type:`button`,onClick:()=>y(e),className:X(`text-xs px-2.5 py-0.5 rounded-full border transition-colors capitalize`,v===e?`bg-primary/10 border-primary/30 text-primary`:`border-border text-muted-foreground hover:text-foreground`),children:e},e))}),(0,J.jsx)(Lc,{}),v===`graph`?(0,J.jsx)(jc,{worktrees:p,baseBranch:m||`HEAD`}):(0,J.jsx)(Fc,{worktrees:p,baseBranch:m||`HEAD`})]}),(0,J.jsx)(`div`,{className:X(O===`work`?`block`:`hidden`),id:`panel-work`,children:(0,J.jsx)(mm,{})}),(0,J.jsx)(`div`,{className:X(O===`collab`?`block`:`hidden`),children:(0,J.jsx)(tm,{sessionId:e})})]})}function bm(e){return e<=0?`$0`:e>=.01?`$${e.toFixed(3)}`:`$${e.toFixed(5)}`.replace(/0+$/,``).replace(/\.$/,``)}function xm(e){let t=Math.floor(e/1e3);return t<60?`${t}s`:`${Math.floor(t/60)}m ${t%60}s`}var Sm={running:{led:`bg-[hsl(var(--success))]`,label:`running`,pulse:!0,badge:`bg-[hsl(var(--success))]/15 text-[hsl(var(--success))]`},completed:{led:`bg-[hsl(var(--success))]`,label:`done`,pulse:!1,badge:`bg-muted text-muted-foreground`},failed:{led:`bg-destructive`,label:`failed`,pulse:!1,badge:`bg-destructive/15 text-destructive`},timeout:{led:`bg-[hsl(var(--warning))]`,label:`timeout`,pulse:!1,badge:`bg-amber-500/15 text-amber-500`},stopped:{led:`bg-muted-foreground`,label:`stopped`,pulse:!1,badge:`bg-muted text-muted-foreground`}};function Cm({agent:e,isLeader:t}){let n=Sm[e.status],r=e.status===`running`,i=Date.now()-e.startedAt,a=[...e.toolLog.slice(0,8)].reverse();return(0,J.jsxs)(`div`,{className:X(`rounded-xl border p-4 space-y-3`,r?`border-primary/20 bg-primary/[0.02]`:`border-border bg-card`,t&&`ring-2 ring-amber-500/30`),children:[(0,J.jsxs)(`div`,{className:`flex items-start justify-between`,children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,J.jsx)(`span`,{className:X(`led`,n.led,n.pulse&&`led-pulse`,`mt-0.5`)}),(0,J.jsxs)(`div`,{children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,J.jsx)(`span`,{className:`text-sm font-semibold`,children:e.name}),t&&(0,J.jsx)(c,{className:`h-3.5 w-3.5 text-amber-500`,"aria-label":`leader`}),e.extensions>0&&(0,J.jsxs)(`span`,{className:`inline-flex items-center gap-0.5 px-1.5 py-0.5 rounded-full bg-amber-500/15 text-[10px] text-amber-600 dark:text-amber-400 font-medium`,children:[(0,J.jsx)(Bt,{className:`h-2.5 w-2.5`}),`×`,e.extensions]})]}),(0,J.jsx)(`span`,{className:X(`inline-block mt-0.5 px-1.5 py-0.5 rounded text-[10px] font-medium`,n.badge),children:n.label})]})]}),(0,J.jsx)(`div`,{className:`flex items-center gap-1 text-[10px] text-muted-foreground`,children:t&&(0,J.jsx)(`span`,{className:`text-[9px] bg-amber-500/15 text-amber-600 dark:text-amber-400 px-1.5 py-0.5 rounded`,children:`LEADER`})})]}),e.description&&(0,J.jsx)(`p`,{className:`text-xs text-muted-foreground leading-relaxed line-clamp-2`,children:e.description}),e.budgetWarning&&(0,J.jsxs)(`div`,{className:`flex items-center gap-2 px-3 py-2 rounded-lg bg-amber-500/10 border border-amber-500/20 text-xs`,children:[(0,J.jsx)(Bt,{className:`h-3.5 w-3.5 text-amber-500 shrink-0`}),(0,J.jsxs)(`span`,{className:`text-amber-600 dark:text-amber-400`,children:[`⚡ hitting `,(0,J.jsx)(`strong`,{children:e.budgetWarning.kind}),` limit (`,e.budgetWarning.used,`/`,e.budgetWarning.limit,`) — extending`]})]}),e.failureReason&&(0,J.jsx)(`div`,{className:`flex items-center gap-2 px-3 py-2 rounded-lg bg-destructive/10 border border-destructive/20 text-xs`,children:(0,J.jsxs)(`span`,{className:`text-destructive font-medium`,children:[`✗ `,e.failureReason]})}),(0,J.jsxs)(`div`,{className:`grid grid-cols-4 gap-2`,children:[(0,J.jsxs)(`div`,{className:`rounded-lg border bg-muted/30 px-2 py-1.5 text-center`,children:[(0,J.jsx)(`div`,{className:`text-[10px] text-muted-foreground`,children:`Iters`}),(0,J.jsx)(`div`,{className:`text-xs font-mono font-semibold tabular-nums`,children:e.iteration})]}),(0,J.jsxs)(`div`,{className:`rounded-lg border bg-muted/30 px-2 py-1.5 text-center`,children:[(0,J.jsx)(`div`,{className:`text-[10px] text-muted-foreground`,children:`Tools`}),(0,J.jsx)(`div`,{className:`text-xs font-mono font-semibold tabular-nums`,children:e.toolCalls})]}),(0,J.jsxs)(`div`,{className:`rounded-lg border bg-muted/30 px-2 py-1.5 text-center`,children:[(0,J.jsx)(`div`,{className:`text-[10px] text-muted-foreground`,children:`Cost`}),(0,J.jsx)(`div`,{className:`text-xs font-mono font-semibold tabular-nums`,children:bm(e.costUsd)})]}),(0,J.jsxs)(`div`,{className:`rounded-lg border bg-muted/30 px-2 py-1.5 text-center`,children:[(0,J.jsx)(`div`,{className:`text-[10px] text-muted-foreground`,children:`Elapsed`}),(0,J.jsx)(`div`,{className:`text-xs font-mono font-semibold tabular-nums`,children:xm(i)})]})]}),(0,J.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,J.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,J.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:`Activity (12 bins)`}),(0,J.jsx)(lp,{bins:e.sparklineBins,className:`font-mono text-[9px]`})]}),(0,J.jsx)(Du,{pct:e.ctxPct,tokens:e.ctxTokens,maxTokens:e.maxContext})]}),(e.provider||e.model)&&(0,J.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[10px] text-muted-foreground`,children:[(0,J.jsx)(_e,{className:`h-3 w-3`}),(0,J.jsxs)(`span`,{className:`font-mono`,children:[e.provider??`?`,`/`,e.model??`?`]})]}),(e.currentTool||e.lastTool)&&(0,J.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[10px] text-muted-foreground`,children:[(0,J.jsx)(Un,{className:X(`h-3 w-3`,r&&`animate-pulse text-primary`)}),(0,J.jsx)(`span`,{className:`font-mono`,children:e.currentTool??e.lastTool}),r&&(0,J.jsx)(z,{className:`h-3 w-3 animate-spin`})]}),e.partialText&&r&&(0,J.jsxs)(`div`,{className:`rounded-lg border bg-muted/30 p-2`,children:[(0,J.jsx)(`div`,{className:`text-[9px] text-muted-foreground uppercase tracking-wider mb-1`,children:`Streaming output`}),(0,J.jsx)(`pre`,{className:`text-[10px] font-mono text-foreground/80 whitespace-pre-wrap line-clamp-3 leading-relaxed`,children:e.partialText})]}),a.length>0&&(0,J.jsxs)(`div`,{className:`space-y-1`,children:[(0,J.jsx)(`div`,{className:`text-[9px] text-muted-foreground uppercase tracking-wider`,children:`Recent tools`}),(0,J.jsx)(`div`,{className:`space-y-0.5`,children:a.map((e,t)=>(0,J.jsxs)(`div`,{className:`flex items-center gap-2 text-[10px] font-mono`,children:[(0,J.jsx)(`span`,{className:X(`shrink-0`,e.ok?`text-[hsl(var(--success))]`:`text-destructive`),children:e.ok?`✓`:`✗`}),(0,J.jsx)(`span`,{className:`text-muted-foreground truncate`,children:e.name}),(0,J.jsx)(`span`,{className:`ml-auto tabular-nums text-muted-foreground shrink-0`,children:e.durationMs>=1e3?`${(e.durationMs/1e3).toFixed(1)}s`:`${e.durationMs}ms`})]},t))})]}),e.finalText&&!r&&(0,J.jsxs)(`div`,{className:`rounded-lg border bg-muted/30 p-2`,children:[(0,J.jsx)(`div`,{className:`text-[9px] text-muted-foreground uppercase tracking-wider mb-1`,children:`Final output`}),(0,J.jsx)(`pre`,{className:`text-[10px] font-mono text-foreground/80 whitespace-pre-wrap line-clamp-4 leading-relaxed`,children:e.finalText})]})]})}function wm({onClose:e}){let t=Y(e=>e.agents),n=Y(e=>e.leaderId),[r,i]=(0,H.useState)(0),a=(0,H.useMemo)(()=>{let e=Array.from(t.values());return e.sort((e,t)=>{if(e.id===n)return-1;if(t.id===n)return 1;let r=e.status===`running`?0:1,i=t.status===`running`?0:1;return r===i?e.startedAt-t.startedAt:r-i}),e},[t,n]),o=(0,H.useCallback)(t=>{if(t.key===`Escape`){e();return}if(t.key===`ArrowDown`){t.preventDefault(),i(e=>Math.min(e+1,a.length-1));return}if(t.key===`ArrowUp`){t.preventDefault(),i(e=>Math.max(e-1,0));return}},[a.length,e]);(0,H.useEffect)(()=>{let t=t=>{t.key===`Escape`&&e()};return window.addEventListener(`keydown`,t),()=>window.removeEventListener(`keydown`,t)},[e]);let s=a[r]??null;return(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(`div`,{className:`fixed inset-0 z-40 bg-black/10 backdrop-blur-[1px]`,onClick:e,"aria-hidden":`true`}),(0,J.jsxs)(`div`,{className:`fixed right-0 top-0 h-full z-50 w-[600px] max-w-[90vw] flex flex-col bg-background border-l shadow-2xl animate-slide-in-right`,onKeyDown:o,tabIndex:-1,children:[(0,J.jsxs)(`div`,{className:`flex items-center justify-between px-4 py-3 border-b bg-card/80 backdrop-blur shrink-0`,children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,J.jsx)(Yn,{className:`h-5 w-5 text-primary`}),(0,J.jsx)(`h2`,{className:`text-sm font-semibold`,children:`Agents Monitor`}),(0,J.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[a.length,` total`]})]}),(0,J.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,J.jsx)(`button`,{type:`button`,onClick:()=>i(e=>Math.max(e-1,0)),className:`p-1.5 rounded-md hover:bg-muted transition-colors disabled:opacity-30`,disabled:r===0,"aria-label":`Previous agent`,children:(0,J.jsx)(mt,{className:`h-4 w-4`})}),(0,J.jsx)(`span`,{className:`text-xs tabular-nums text-muted-foreground font-mono`,children:a.length>0?`${r+1}/${a.length}`:`0/0`}),(0,J.jsx)(`button`,{type:`button`,onClick:()=>i(e=>Math.min(e+1,a.length-1)),className:`p-1.5 rounded-md hover:bg-muted transition-colors disabled:opacity-30`,disabled:r>=a.length-1,"aria-label":`Next agent`,children:(0,J.jsx)(ot,{className:`h-4 w-4`})}),(0,J.jsx)(`button`,{type:`button`,onClick:e,className:`p-1.5 rounded-md hover:bg-muted transition-colors ml-2`,"aria-label":`Close agents monitor`,children:(0,J.jsx)(B,{className:`h-4 w-4`})})]})]}),(0,J.jsx)(`div`,{className:`flex-1 overflow-y-auto p-4`,children:a.length===0?(0,J.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full text-muted-foreground`,children:[(0,J.jsx)(Yn,{className:`h-12 w-12 mb-3 opacity-20`}),(0,J.jsx)(`p`,{className:`text-sm font-medium`,children:`No agents active`})]}):s?(0,J.jsx)(`div`,{className:`max-w-2xl mx-auto`,children:(0,J.jsx)(Cm,{agent:s,isLeader:s.id===n})}):null}),a.length>0&&(0,J.jsxs)(`div`,{className:`border-t bg-card/80 backdrop-blur shrink-0`,children:[(0,J.jsx)(`div`,{className:`px-4 py-2 flex items-center gap-2 overflow-x-auto`,children:a.map((e,t)=>(0,J.jsxs)(`button`,{type:`button`,onClick:()=>i(t),className:X(`shrink-0 flex items-center gap-1.5 px-2 py-1 rounded-md text-[10px] transition-colors`,t===r?`bg-primary/15 text-primary ring-1 ring-primary/40`:`hover:bg-accent text-muted-foreground`),children:[(0,J.jsx)(`span`,{className:X(`led`,Sm[e.status].led,Sm[e.status].pulse&&`led-pulse`,`shrink-0`)}),(0,J.jsx)(`span`,{children:e.name}),e.id===n&&(0,J.jsx)(c,{className:`h-2.5 w-2.5 text-amber-500 shrink-0`})]},e.id))}),(0,J.jsxs)(`div`,{className:`px-4 py-1.5 border-t text-[10px] text-muted-foreground flex items-center gap-4`,children:[(0,J.jsx)(`span`,{children:`←→ page`}),(0,J.jsx)(`span`,{children:`↑↓ navigate list`}),(0,J.jsx)(`span`,{children:`Esc close`})]})]})]})]})}function Tm({current:e,max:t,className:n,showLabel:r=!0}){let i=Math.min(e,t),a=Math.max(0,t-i),o=t>0?i/t*100:0,s=o>=90?`text-destructive`:o>=70?`text-[hsl(var(--warning))]`:`text-[hsl(var(--success))]`;return(0,J.jsxs)(`span`,{className:n,title:`Fleet concurrency: ${e}/${t}`,children:[(0,J.jsxs)(`span`,{"aria-hidden":`true`,className:`font-mono text-[10px] tracking-tight`,children:[`[`,(0,J.jsx)(`span`,{className:s,children:`█`.repeat(i)}),(0,J.jsx)(`span`,{className:`text-[hsl(var(--muted))]`,children:`░`.repeat(a)}),`]`]}),r&&(0,J.jsxs)(`span`,{className:`ml-1.5 tabular-nums text-[10px] text-muted-foreground font-mono`,children:[e,`/`,t]})]})}function Em(e){let t=Date.now()-e;return t<5e3?`just now`:t<6e4?`${Math.floor(t/1e3)}s ago`:t<36e5?`${Math.floor(t/6e4)}m ago`:`${Math.floor(t/36e5)}h ago`}var Dm={spawned:`🚀`,task_started:`▶`,tool_executed:`⚡`,iteration_summary:`🔄`,budget_warning:`!`,budget_extended:`⚡`,task_completed:`✅`,ctx_pct:`💬`,leader_updated:`👑`};function Om({events:e,max:t=20,className:n}){let r=e.slice(0,t);return r.length===0?(0,J.jsx)(`div`,{className:`py-4 text-center text-xs text-muted-foreground ${n??``}`,children:`No events yet.`}):(0,J.jsx)(`div`,{className:`space-y-0.5 overflow-y-auto max-h-48 ${n??``}`,children:r.map(e=>(0,J.jsxs)(`div`,{className:`flex items-start gap-2 text-[10px] leading-tight py-0.5 px-1 rounded hover:bg-accent/50 transition-colors`,children:[(0,J.jsx)(`span`,{className:`shrink-0 w-5 text-center`,"aria-hidden":`true`,children:Dm[e.kind]??`·`}),(0,J.jsx)(`span`,{className:`shrink-0 w-12 text-right text-muted-foreground font-mono tabular-nums`,children:Em(e.timestamp)}),(0,J.jsx)(`span`,{className:`truncate text-foreground/90`,children:e.message}),e.value!==void 0&&e.kind===`tool_executed`&&(0,J.jsx)(`span`,{className:`ml-auto shrink-0 tabular-nums text-muted-foreground font-mono`,children:e.value>=1e3?`${(e.value/1e3).toFixed(1)}s`:`${e.value}ms`}),e.value!==void 0&&e.kind===`ctx_pct`&&(0,J.jsxs)(`span`,{className:`ml-auto shrink-0 tabular-nums text-muted-foreground font-mono`,children:[e.value,`%`]})]},e.id))})}var km={running:{led:`bg-emerald-500`,label:`running`,pulse:!0,color:`text-emerald-500`},completed:{led:`bg-emerald-500`,label:`done`,pulse:!1,color:`text-emerald-500`},failed:{led:`bg-destructive`,label:`failed`,pulse:!1,color:`text-destructive`},timeout:{led:`bg-amber-500`,label:`timeout`,pulse:!1,color:`text-amber-500`},stopped:{led:`bg-muted-foreground`,label:`stopped`,pulse:!1,color:`text-muted-foreground`}};function Am({agent:e,now:t}){let[n,r]=(0,H.useState)(!1),[i,a]=(0,H.useState)(!1),o=km[e.status],s=e.status===`running`,c=Math.min(100,Math.max(0,e.ctxPct)),l=(0,H.useCallback)(async e=>{try{await navigator.clipboard.writeText(e),r(!0),setTimeout(()=>r(!1),2e3)}catch{}},[]),u=e.toolLog.reduce((e,t)=>e+t.durationMs,0),d=e.toolLog.length>0?Math.round(u/e.toolLog.length):0,f=(0,H.useMemo)(()=>{let t=new Set;for(let n of e.toolLog)t.add(n.name);return t.size},[e.toolLog]),p=e.partialText||e.finalText||void 0,m=!e.finalText&&!!e.partialText;return(0,J.jsxs)(`div`,{className:`h-full flex flex-col`,children:[(0,J.jsxs)(`div`,{className:`shrink-0 border-b bg-card p-4 space-y-3`,children:[(0,J.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,J.jsx)(`div`,{className:`flex items-center justify-center w-10 h-10 rounded-lg bg-primary/10`,children:(0,J.jsx)(Yn,{className:`h-5 w-5 text-primary`})}),(0,J.jsxs)(`div`,{children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,J.jsx)(`span`,{className:`text-base font-semibold`,children:e.name}),(0,J.jsx)(`span`,{className:X(`px-2 py-0.5 rounded text-[10px] font-medium uppercase tracking-wider`,e.status===`running`?`bg-emerald-500/15 text-emerald-600 dark:text-emerald-400`:e.status===`failed`||e.status===`timeout`?`bg-destructive/15 text-destructive`:`bg-muted text-muted-foreground`),children:o.label})]}),(0,J.jsxs)(`span`,{className:`text-[10px] text-muted-foreground font-mono`,children:[`session: `,e.sessionId?.slice(0,12),`…`]})]})]}),(0,J.jsxs)(`div`,{className:`flex items-center gap-2 text-[11px] text-muted-foreground`,children:[s&&(0,J.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,J.jsx)(vn,{className:`h-3.5 w-3.5`}),(0,J.jsx)(`span`,{className:`tabular-nums font-mono`,children:fp(Math.max(0,t-e.startedAt))})]}),(0,J.jsx)(`span`,{className:X(`led`,o.led,s&&`led-pulse`)})]})]}),(0,J.jsxs)(`div`,{className:`flex items-center gap-3 px-3 py-2 rounded-lg bg-muted/30`,children:[(0,J.jsx)(`span`,{className:`text-[10px] text-muted-foreground uppercase tracking-wider`,children:`Activity`}),(0,J.jsx)(lp,{bins:e.sparklineBins,className:`font-mono text-[9px]`}),e.budgetWarning&&(0,J.jsxs)(`span`,{className:`ml-auto flex items-center gap-1 text-[10px] text-amber-500`,children:[(0,J.jsx)(Bt,{className:`h-3 w-3`}),`budget warning`]})]}),e.description&&(0,J.jsxs)(`div`,{className:`px-3 py-2 rounded-lg bg-muted/20 border border-border/50`,children:[(0,J.jsx)(`span`,{className:`text-[9px] text-muted-foreground uppercase tracking-wider`,children:`Current Task`}),(0,J.jsx)(`p`,{className:`text-xs mt-1 text-foreground/80`,children:e.description})]})]}),(0,J.jsxs)(`div`,{className:`flex-1 overflow-y-auto p-4 space-y-4`,children:[(0,J.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,J.jsxs)(`div`,{className:`rounded-lg border bg-card p-3`,children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-2 text-[9px] text-muted-foreground uppercase tracking-wider mb-2`,children:[(0,J.jsx)(_e,{className:`h-3 w-3`}),` Provider / Model`]}),(0,J.jsxs)(`div`,{className:`text-sm font-mono font-medium`,children:[e.provider??`?`,`/`,e.model??`?`]})]}),(0,J.jsxs)(`div`,{className:`rounded-lg border bg-card p-3`,children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-2 text-[9px] text-muted-foreground uppercase tracking-wider mb-2`,children:[(0,J.jsx)(_t,{className:`h-3 w-3`}),` Performance`]}),(0,J.jsxs)(`div`,{className:`space-y-1`,children:[(0,J.jsxs)(`div`,{className:`flex justify-between text-[11px]`,children:[(0,J.jsx)(`span`,{className:`text-muted-foreground`,children:`Iterations`}),(0,J.jsx)(`span`,{className:`font-mono font-medium`,children:e.iteration})]}),(0,J.jsxs)(`div`,{className:`flex justify-between text-[11px]`,children:[(0,J.jsx)(`span`,{className:`text-muted-foreground`,children:`Tool Calls`}),(0,J.jsx)(`span`,{className:`font-mono font-medium`,children:e.toolCalls})]}),(0,J.jsxs)(`div`,{className:`flex justify-between text-[11px]`,children:[(0,J.jsx)(`span`,{className:`text-muted-foreground`,children:`Unique Tools`}),(0,J.jsx)(`span`,{className:`font-mono font-medium`,children:f})]})]})]}),(0,J.jsxs)(`div`,{className:`rounded-lg border bg-card p-3`,children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-2 text-[9px] text-muted-foreground uppercase tracking-wider mb-2`,children:[(0,J.jsx)(we,{className:`h-3 w-3`}),` Cost`]}),(0,J.jsx)(`div`,{className:`text-lg font-mono font-bold text-emerald-500`,children:up(e.costUsd)}),(0,J.jsxs)(`div`,{className:`text-[10px] text-muted-foreground mt-1`,children:[`avg `,d,`ms per tool`]})]}),(0,J.jsxs)(`div`,{className:`rounded-lg border bg-card p-3`,children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-2 text-[9px] text-muted-foreground uppercase tracking-wider mb-2`,children:[(0,J.jsx)(_n,{className:`h-3 w-3`}),` Context`]}),(0,J.jsxs)(`div`,{className:`space-y-2`,children:[(0,J.jsxs)(`div`,{className:`flex justify-between text-[11px]`,children:[(0,J.jsx)(`span`,{className:`text-muted-foreground`,children:`Tokens`}),(0,J.jsx)(`span`,{className:`font-mono font-medium`,children:dp(e.ctxTokens)})]}),(0,J.jsx)(`div`,{className:`h-2 w-full rounded-full bg-muted overflow-hidden`,children:(0,J.jsx)(`div`,{className:X(`h-full rounded-full transition-all`,c>=85?`bg-destructive`:c>=70?`bg-amber-500`:`bg-emerald-500`),style:{width:`${c}%`}})}),(0,J.jsxs)(`span`,{className:`text-[10px] text-muted-foreground tabular-nums font-mono`,children:[c,`% used`]})]})]})]}),e.currentTool&&(0,J.jsxs)(`div`,{className:X(`rounded-lg border px-4 py-3 flex items-center gap-3`,s?`border-primary/30 bg-primary/[0.04]`:`border-border bg-muted/30`),children:[(0,J.jsx)(Un,{className:X(`h-4 w-4`,s?`text-primary animate-pulse`:`text-muted-foreground`)}),(0,J.jsx)(`span`,{className:`text-sm font-mono font-medium`,children:e.currentTool}),s?(0,J.jsxs)(`span`,{className:`ml-auto flex items-center gap-1.5 text-[10px] text-primary`,children:[(0,J.jsx)(z,{className:`h-3 w-3 animate-spin`}),` running…`]}):(0,J.jsx)(`span`,{className:`ml-auto text-[10px] text-muted-foreground`,children:`completed`})]}),p?(0,J.jsxs)(`div`,{className:`rounded-lg border bg-card`,children:[(0,J.jsxs)(`div`,{className:`flex items-center justify-between px-4 py-2 border-b bg-muted/30`,children:[(0,J.jsx)(`span`,{className:`text-[10px] font-semibold text-muted-foreground uppercase tracking-wider flex items-center gap-2`,children:m?(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(`span`,{className:`w-2 h-2 rounded-full bg-blue-500 animate-pulse`}),`Live Output`]}):(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(wt,{className:`h-3 w-3`}),`Final Output`]})}),(0,J.jsx)(`button`,{type:`button`,onClick:()=>l(p),className:`flex items-center gap-1 px-2 py-1 rounded text-[10px] text-muted-foreground hover:text-foreground hover:bg-muted transition-colors`,children:n?`✓ Copied`:`Copy`})]}),(0,J.jsx)(`pre`,{className:`p-4 text-xs whitespace-pre-wrap font-mono text-foreground/80 leading-relaxed max-h-64 overflow-y-auto`,children:p})]}):s?(0,J.jsxs)(`div`,{className:`rounded-lg border border-dashed border-border p-6 text-center`,children:[(0,J.jsx)(z,{className:`h-6 w-6 mx-auto mb-2 text-muted-foreground/50 animate-spin`}),(0,J.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`Waiting for output…`})]}):null,e.budgetWarning&&(0,J.jsxs)(`div`,{className:`flex items-center gap-3 px-4 py-3 rounded-lg bg-amber-500/10 border border-amber-500/20`,children:[(0,J.jsx)(Bt,{className:`h-5 w-5 text-amber-500 shrink-0`}),(0,J.jsxs)(`div`,{children:[(0,J.jsx)(`span`,{className:`text-sm font-medium text-amber-600 dark:text-amber-400`,children:`⚡ Budget Warning`}),(0,J.jsxs)(`p`,{className:`text-[11px] text-amber-600/80 dark:text-amber-400/80 mt-0.5`,children:[`Hitting `,e.budgetWarning.kind,` limit (`,e.budgetWarning.used,`/`,e.budgetWarning.limit,`)`]})]})]}),e.extensions>0&&(0,J.jsxs)(`div`,{className:`flex items-center gap-3 px-4 py-3 rounded-lg bg-amber-500/10 border border-amber-500/20`,children:[(0,J.jsx)(Bt,{className:`h-5 w-5 text-amber-500 shrink-0`}),(0,J.jsxs)(`div`,{children:[(0,J.jsxs)(`span`,{className:`text-sm font-medium`,children:[e.extensions,` Budget Extension`,e.extensions===1?``:`s`]}),(0,J.jsxs)(`p`,{className:`text-[11px] text-muted-foreground mt-0.5`,children:[`Agent extended its budget `,e.extensions,` time`,e.extensions===1?``:`s`,` due to long-running tasks`]})]})]}),e.error&&(0,J.jsxs)(`div`,{className:`rounded-lg border border-destructive/30 bg-destructive/5 p-4`,children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-2 mb-2`,children:[(0,J.jsx)(I,{className:`h-4 w-4 text-destructive`}),(0,J.jsx)(`span`,{className:`text-[10px] font-semibold text-destructive uppercase tracking-wider`,children:`Error`})]}),(0,J.jsx)(`p`,{className:`text-sm text-destructive/90`,children:e.error.message})]}),e.failureReason&&(0,J.jsxs)(`div`,{className:`rounded-lg border border-destructive/30 bg-destructive/5 p-4`,children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-2 mb-2`,children:[(0,J.jsx)(I,{className:`h-4 w-4 text-destructive`}),(0,J.jsx)(`span`,{className:`text-[10px] font-semibold text-destructive uppercase tracking-wider`,children:`Failure Reason`})]}),(0,J.jsx)(`p`,{className:`text-sm text-destructive/90`,children:e.failureReason})]}),e.toolLog.length>0&&(0,J.jsxs)(`div`,{className:`rounded-lg border bg-card`,children:[(0,J.jsxs)(`button`,{type:`button`,onClick:()=>a(!i),className:`w-full flex items-center justify-between px-4 py-2 border-b bg-muted/30 hover:bg-muted/50 transition-colors`,children:[(0,J.jsxs)(`span`,{className:`text-[10px] font-semibold text-muted-foreground uppercase tracking-wider flex items-center gap-2`,children:[(0,J.jsx)(Un,{className:`h-3 w-3`}),`Tool Log (`,e.toolLog.length,` calls)`]}),(0,J.jsx)(ot,{className:X(`h-4 w-4 text-muted-foreground transition-transform`,i&&`rotate-90`)})]}),(0,J.jsx)(`div`,{className:X(`overflow-hidden transition-all`,i?`max-h-[500px]`:`max-h-48`),children:(0,J.jsx)(`div`,{className:`p-2 space-y-0.5`,children:e.toolLog.map((e,t)=>(0,J.jsxs)(`div`,{className:X(`flex items-center gap-3 rounded px-3 py-2 text-[11px]`,e.ok?`bg-muted/30 hover:bg-muted/50`:`bg-destructive/5 border border-destructive/20`),children:[(0,J.jsx)(`span`,{className:X(`led shrink-0`,e.ok?`bg-emerald-500`:`bg-destructive`)}),(0,J.jsx)(`span`,{className:X(`font-mono font-medium w-20 shrink-0`,e.ok?`text-foreground`:`text-destructive`),children:e.name}),(0,J.jsx)(`span`,{className:`text-muted-foreground tabular-nums text-[10px]`,children:e.durationMs>=1e3?`${(e.durationMs/1e3).toFixed(2)}s`:`${e.durationMs}ms`}),!e.ok&&(0,J.jsx)(`span`,{className:`ml-auto text-[10px] text-destructive font-medium`,children:`Failed`}),(0,J.jsx)(`span`,{className:`ml-auto text-[9px] text-muted-foreground tabular-nums`,children:new Date(e.at).toLocaleTimeString()})]},`${e.name}-${e.at}-${t}`))})})]})]})]})}function jm({agent:e,isSelected:t,isLeader:n,onClick:r}){let i=km[e.status],a=e.status===`running`,o=Math.min(100,Math.max(0,e.ctxPct));return(0,J.jsxs)(`button`,{type:`button`,onClick:r,className:X(`w-full text-left grid grid-cols-[140px_60px_1fr_60px_60px_60px_60px_50px_50px] items-center gap-x-2 px-3 py-1.5 rounded-md text-xs transition-colors`,t?`bg-primary/15 ring-1 ring-primary/40`:`hover:bg-accent/50`,a&&!t&&`bg-muted/30`),children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-1 min-w-0`,children:[(0,J.jsx)(`span`,{className:X(`led shrink-0`,i.led,i.pulse&&`led-pulse`)}),(0,J.jsx)(`span`,{className:`truncate font-medium`,children:e.name}),n&&(0,J.jsx)(c,{className:`h-3 w-3 shrink-0 text-amber-500`,"aria-label":`leader`})]}),(0,J.jsx)(`span`,{className:X(`text-[10px] tabular-nums`,a?`text-emerald-500`:`text-muted-foreground`),children:i.label}),(0,J.jsxs)(`div`,{className:`flex items-center gap-1 min-w-0`,children:[(0,J.jsx)(lp,{bins:e.sparklineBins,className:`font-mono text-[9px]`}),e.budgetWarning&&(0,J.jsx)(`span`,{title:`⚡ hitting ${e.budgetWarning.kind} limit (${e.budgetWarning.used}/${e.budgetWarning.limit})`,children:(0,J.jsx)(Bt,{className:`h-3 w-3 shrink-0 text-amber-500`,"aria-label":`budget warning`})})]}),(0,J.jsxs)(`span`,{className:`tabular-nums text-muted-foreground text-[10px]`,children:[e.iteration,`it`]}),(0,J.jsxs)(`span`,{className:`tabular-nums text-muted-foreground text-[10px]`,children:[e.toolCalls,`tc`]}),(0,J.jsx)(`span`,{className:`tabular-nums font-mono text-[10px]`,children:up(e.costUsd)}),(0,J.jsxs)(`div`,{className:`flex flex-col gap-0.5 min-w-0`,children:[(0,J.jsx)(`div`,{className:`h-1.5 w-full rounded-full bg-muted overflow-hidden`,children:(0,J.jsx)(`div`,{className:X(`h-full rounded-full transition-all`,o>=85?`bg-destructive`:o>=70?`bg-amber-500`:`bg-emerald-500`),style:{width:`${o}%`}})}),(0,J.jsx)(`span`,{className:`text-[9px] tabular-nums text-muted-foreground font-mono leading-none`,children:e.maxContext>0?`${o}%`:`—`})]}),(0,J.jsx)(`span`,{className:`tabular-nums text-[10px] text-muted-foreground`,children:e.extensions>0?`⚡×${e.extensions}`:`—`}),(0,J.jsx)(`span`,{className:`text-[9px] text-destructive truncate`,title:e.failureReason,children:e.failureReason??``})]})}function Mm({onClose:e,onSelectAgent:t}){let n=Y(e=>e.agents),r=Y(e=>e.leaderId),i=Y(e=>e.fleetTokensIn),a=Y(e=>e.fleetTokensOut),o=Y(e=>e.fleetConcurrency),s=Y(e=>e.fleetConcurrencyMax),c=Y(e=>e.eventTimeline),l=Y(e=>e.agentTimeline),[u,d]=(0,H.useState)(null),[f,p]=(0,H.useState)(Date.now());(0,H.useEffect)(()=>{let e=setInterval(()=>p(Date.now()),1e3);return()=>clearInterval(e)},[]);let m=(0,H.useMemo)(()=>{let e=Array.from(n.values());return e.sort((e,t)=>e.id===r?-1:t.id===r?1:ip(e,t)),e},[n,r]),h=(0,H.useMemo)(()=>Array.from(n.values()).reduce((e,t)=>e+t.costUsd,0),[n]),g=ap(m).running,_=u===null?null:m[u],v=(0,H.useCallback)(e=>d(t=>t===e?null:e),[]),y=(0,H.useCallback)(n=>{if(n.key===`Escape`){u===null?e&&e():d(null);return}if(n.key===`ArrowDown`){n.preventDefault(),d(e=>Math.min((e??-1)+1,m.length-1));return}if(n.key===`ArrowUp`){n.preventDefault(),d(e=>Math.max((e??0)-1,0));return}n.key===`Enter`&&m[u??0]&&t?.(m[u??0])},[m,u,e,t]);return(0,H.useEffect)(()=>{let t=t=>{t.key===`Escape`&&e()};return window.addEventListener(`keydown`,t),()=>window.removeEventListener(`keydown`,t)},[e]),(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(`div`,{className:`fixed inset-0 z-40 bg-black/10 backdrop-blur-[1px]`,onClick:e,"aria-hidden":`true`}),(0,J.jsxs)(`div`,{className:`fixed right-0 top-0 h-full z-50 w-[720px] max-w-[95vw] flex flex-col bg-background border-l shadow-2xl animate-slide-in-right`,onKeyDown:y,tabIndex:-1,children:[(0,J.jsxs)(`div`,{className:`flex items-center justify-between px-4 py-3 border-b bg-card/80 backdrop-blur shrink-0`,children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,J.jsx)(Yn,{className:`h-5 w-5 text-primary`}),(0,J.jsxs)(`h2`,{className:`text-sm font-semibold flex items-center gap-2`,children:[`FLEET MONITOR`,g>0&&(0,J.jsxs)(`span`,{className:`flex items-center gap-1 text-[11px] text-emerald-500 font-normal`,children:[(0,J.jsx)(`span`,{className:`led led-pulse bg-emerald-500`}),g,` running`]})]}),(0,J.jsxs)(`div`,{className:`flex items-center gap-2 text-xs text-muted-foreground`,children:[(0,J.jsxs)(`span`,{children:[m.length,` total agents`]}),(0,J.jsx)(Tm,{current:o,max:s,showLabel:!0})]})]}),(0,J.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,J.jsxs)(`span`,{className:`text-xs text-muted-foreground tabular-nums font-mono`,children:[`↓`,dp(i),` ↑`,dp(a),` · `,up(h)]}),(0,J.jsx)(`span`,{className:`text-xs text-muted-foreground tabular-nums font-mono`,children:r?`👑 ${n.get(r)?.name??r}`:`no leader`}),(0,J.jsx)(`button`,{type:`button`,onClick:e,className:`p-1.5 rounded-md hover:bg-muted transition-colors`,"aria-label":`Close fleet monitor`,children:(0,J.jsx)(I,{className:`h-4 w-4`})})]})]}),(0,J.jsxs)(`div`,{className:`flex-1 flex overflow-hidden`,children:[(0,J.jsxs)(`div`,{className:X(`flex flex-col border-r transition-all duration-200`,_?`w-[500px] shrink-0`:`w-full`),children:[(0,J.jsx)(`div`,{className:`border-b bg-card/80 px-3 py-2`,children:(0,J.jsxs)(`div`,{className:`grid grid-cols-[140px_60px_1fr_60px_60px_60px_60px_50px_50px] gap-x-2 text-[9px] uppercase tracking-wider text-muted-foreground font-medium`,children:[(0,J.jsx)(`span`,{children:`Name`}),(0,J.jsx)(`span`,{children:`Status`}),(0,J.jsx)(`span`,{children:`Activity`}),(0,J.jsx)(`span`,{children:`Iters`}),(0,J.jsx)(`span`,{children:`Tools`}),(0,J.jsx)(`span`,{children:`Cost`}),(0,J.jsx)(`span`,{children:`CTX`}),(0,J.jsx)(`span`,{children:`Ext`}),(0,J.jsx)(`span`,{children:`Reason`})]})}),(0,J.jsx)(`div`,{className:`flex-1 overflow-y-auto`,children:m.length===0?(0,J.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full text-muted-foreground`,children:[(0,J.jsx)(Mr,{className:`h-12 w-12 mb-3 opacity-20`}),(0,J.jsx)(`p`,{className:`text-sm font-medium`,children:`No agents active`}),(0,J.jsx)(`p`,{className:`text-xs mt-1`,children:`Agents appear here when the fleet is active.`})]}):(0,J.jsx)(`div`,{className:`p-2 space-y-0.5`,children:m.map((e,t)=>(0,J.jsx)(jm,{agent:e,isSelected:t===u,isLeader:e.id===r,onClick:()=>v(t)},e.id))})}),(0,J.jsxs)(`div`,{className:`border-t bg-card/80 shrink-0`,children:[(0,J.jsx)(`div`,{className:`px-4 py-2 border-b`,children:(0,J.jsxs)(`span`,{className:`text-[10px] uppercase tracking-wider text-muted-foreground font-medium flex items-center gap-2`,children:[(0,J.jsx)(Fr,{className:`h-3 w-3`}),`Agent Timeline`]})}),(0,J.jsx)(`div`,{className:`px-4 py-2 max-h-32 overflow-y-auto`,children:(0,J.jsx)(Om,{events:c,max:10})}),(0,J.jsx)(`div`,{className:`border-t border-dashed`}),(0,J.jsx)(`div`,{className:`px-4 py-2 max-h-40 overflow-y-auto`,children:l.length===0?(0,J.jsx)(`p`,{className:`text-[10px] text-muted-foreground italic`,children:`No agent conversation events yet.`}):(0,J.jsx)(`div`,{className:`space-y-1`,children:l.slice(0,15).map(e=>{let t={text:`💬`,tool_use:`🔧`,error:`❌`,status:`💬`}[e.kind]??`●`,n=e.status===`running`||e.status===`spawned`?`text-emerald-500`:e.status===`failed`||e.status===`timeout`?`text-destructive`:`text-muted-foreground`;return(0,J.jsxs)(`div`,{className:`flex items-start gap-1.5 text-[10px] leading-tight`,children:[(0,J.jsx)(`span`,{className:`shrink-0`,children:t}),(0,J.jsx)(`span`,{className:`font-medium text-primary shrink-0`,children:e.agentName}),e.status&&(0,J.jsx)(`span`,{className:`${n} shrink-0`,children:e.status}),e.toolName&&(0,J.jsxs)(`span`,{className:`text-muted-foreground shrink-0`,children:[`[`,e.toolName,`]`]}),(0,J.jsx)(`span`,{className:`text-muted-foreground truncate`,children:e.content})]},e.id)})})}),(0,J.jsxs)(`div`,{className:`px-4 py-1.5 border-t text-[10px] text-muted-foreground flex items-center gap-4`,children:[(0,J.jsx)(`span`,{children:`↑↓ navigate`}),(0,J.jsx)(`span`,{children:`↵ select detail`}),(0,J.jsx)(`span`,{children:`Esc deselect / close`})]})]})]}),_&&(0,J.jsx)(`div`,{className:`flex-1 overflow-hidden bg-card/50`,children:(0,J.jsxs)(`div`,{className:`h-full flex flex-col`,children:[(0,J.jsxs)(`div`,{className:`shrink-0 px-4 py-2 border-b bg-card/80 flex items-center gap-2`,children:[(0,J.jsx)(ur,{className:`h-4 w-4 text-primary`}),(0,J.jsx)(`span`,{className:`text-xs font-semibold text-primary`,children:_.name}),(0,J.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:`detailed view`}),(0,J.jsx)(`button`,{type:`button`,onClick:()=>d(null),className:`ml-auto text-[10px] text-muted-foreground hover:text-foreground transition-colors flex items-center gap-1`,children:`✕ close`})]}),(0,J.jsx)(`div`,{className:`flex-1 overflow-hidden`,children:(0,J.jsx)(Am,{agent:_,now:f})})]})}),!_&&m.length>0&&(0,J.jsx)(`div`,{className:`flex-1 flex items-center justify-center bg-muted/20`,children:(0,J.jsxs)(`div`,{className:`text-center space-y-3 max-w-sm`,children:[(0,J.jsx)(Mr,{className:`h-12 w-12 text-muted-foreground/30 mx-auto`}),(0,J.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Select an agent to view detailed information`}),(0,J.jsx)(`p`,{className:`text-xs text-muted-foreground/60`,children:`Click on any agent in the list to see detailed metrics, tool logs, streaming output, and more — similar to the chat history detailed view.`}),(0,J.jsxs)(`div`,{className:`flex items-center justify-center gap-4 pt-2`,children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[10px] text-muted-foreground`,children:[(0,J.jsx)(`kbd`,{className:`px-1.5 py-0.5 rounded bg-muted border text-[9px]`,children:`↑`}),(0,J.jsx)(`kbd`,{className:`px-1.5 py-0.5 rounded bg-muted border text-[9px]`,children:`↓`}),(0,J.jsx)(`span`,{children:`navigate`})]}),(0,J.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[10px] text-muted-foreground`,children:[(0,J.jsx)(`kbd`,{className:`px-1.5 py-0.5 rounded bg-muted border text-[9px]`,children:`Enter`}),(0,J.jsx)(`span`,{children:`select`})]}),(0,J.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[10px] text-muted-foreground`,children:[(0,J.jsx)(`kbd`,{className:`px-1.5 py-0.5 rounded bg-muted border text-[9px]`,children:`Esc`}),(0,J.jsx)(`span`,{children:`deselect`})]})]})]})})]})]})]})}var Nm={shell:l,package:gr,network:at,"fs.write":_t,config:_t},Pm={shell:`text-orange-400`,package:`text-blue-400`,network:`text-green-400`,"fs.write":`text-purple-400`,config:`text-yellow-400`},Fm=[`all`,`shell`,`package`,`network`,`fs.write`,`config`];function Im(e){try{return new Date(e).toLocaleTimeString([],{hour:`2-digit`,minute:`2-digit`,second:`2-digit`})}catch{return e.slice(11,19)}}function Lm(e){if(e.input.command)return String(e.input.command).slice(0,80);if(e.input.url)return String(e.input.url).slice(0,80);if(e.input.packages){let t=e.input.packages;return Array.isArray(t)?t.join(`, `).slice(0,80):String(t).slice(0,80)}return JSON.stringify(e.input).slice(0,80)}function Rm(e){return/[",\n]/.test(e)?`"${e.replace(/"/g,`""`)}"`:e}function zm(e){let t=[`timestamp,tool,risk,detail,outcome`,...e.map(e=>{let t=e.input.command??e.input.url??e.input.packages??JSON.stringify(e.input);return[Rm(e.ts),Rm(e.toolName),Rm(e.risk),Rm(String(t)),Rm(e.outcome??``)].join(`,`)})].join(`
|
|
137
137
|
`),n=new Blob([t],{type:`text/csv;charset=utf-8`}),r=URL.createObjectURL(n),i=document.createElement(`a`);i.href=r,i.download=`side-effects-${new Date().toISOString().slice(0,19).replace(/[:.]/g,`-`)}.csv`,i.click(),URL.revokeObjectURL(r)}function Bm(){let e=yi(e=>e.sideEffects),t=yi(e=>e.loading),[n,r]=(0,H.useState)(`all`),[i,a]=(0,H.useState)(`time`),[o,s]=(0,H.useState)(`desc`);(0,H.useEffect)(()=>{yi.getState().setLoading(!0),wn(async()=>{let{getWSClient:e}=await Promise.resolve().then(()=>ci);return{getWSClient:e}},void 0).then(({getWSClient:e})=>{e().send({type:`side_effects.list`})})},[]);let c=()=>{yi.getState().setLoading(!0),wn(async()=>{let{getWSClient:e}=await Promise.resolve().then(()=>ci);return{getWSClient:e}},void 0).then(({getWSClient:e})=>{e().send({type:`side_effects.list`})})},l=e=>{i===e?s(o===`asc`?`desc`:`asc`):(a(e),s(e===`time`?`desc`:`asc`))},u=(0,H.useMemo)(()=>{let t=n===`all`?[...e]:e.filter(e=>e.risk===n);return t.sort((e,t)=>{let n=0;return i===`time`?n=e.ts.localeCompare(t.ts):i===`tool`?n=e.toolName.localeCompare(t.toolName):i===`risk`&&(n=e.risk.localeCompare(t.risk)),o===`asc`?n:-n}),t},[e,n,i,o]);if(e.length===0&&!t)return(0,J.jsxs)(`div`,{className:`flex flex-col items-center justify-center gap-2 py-8 text-zinc-500`,children:[(0,J.jsx)(_t,{className:`h-8 w-8 opacity-40`}),(0,J.jsx)(`p`,{className:`text-sm`,children:`No side effects recorded yet.`}),(0,J.jsx)(`p`,{className:`text-xs text-zinc-600`,children:`Bash commands, package installs, and network requests will appear here.`})]});let d=({column:e})=>i===e?o===`asc`?(0,J.jsx)(ut,{className:`inline h-3 w-3`}):(0,J.jsx)(Me,{className:`inline h-3 w-3`}):(0,J.jsx)(`span`,{className:`opacity-30`,children:`↕`});return(0,J.jsxs)(`div`,{className:`flex h-full flex-col`,children:[(0,J.jsxs)(`div`,{className:`flex items-center justify-between border-b border-zinc-800 px-3 py-2`,children:[(0,J.jsxs)(`h3`,{className:`text-xs font-semibold uppercase tracking-wide text-zinc-400`,children:[`Side Effects (`,u.length,n===`all`?``:`/${e.length}`,`)`]}),(0,J.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,J.jsxs)(`button`,{onClick:()=>zm(u),disabled:u.length===0,className:`flex items-center gap-1 rounded px-2 py-1 text-xs text-zinc-500 hover:bg-zinc-800 hover:text-zinc-300 disabled:opacity-30 disabled:cursor-not-allowed`,title:`Export filtered side effects as CSV`,children:[(0,J.jsx)(b,{className:`h-3 w-3`}),`CSV`]}),(0,J.jsxs)(`button`,{onClick:c,className:`flex items-center gap-1 rounded px-2 py-1 text-xs text-zinc-500 hover:bg-zinc-800 hover:text-zinc-300`,children:[(0,J.jsx)(Ct,{className:X(`h-3 w-3`,t&&`animate-spin`)}),`Refresh`]})]})]}),(0,J.jsx)(`div`,{className:`flex items-center gap-1 border-b border-zinc-800/50 px-2 py-1`,children:Fm.map(e=>(0,J.jsx)(`button`,{onClick:()=>r(e),className:X(`rounded px-2 py-0.5 text-[10px] font-medium uppercase transition-colors`,n===e?`bg-zinc-700 text-zinc-200`:`text-zinc-500 hover:bg-zinc-800 hover:text-zinc-400`),children:e===`all`?`All`:e},e))}),(0,J.jsx)(`div`,{className:`flex-1 overflow-y-auto`,children:(0,J.jsxs)(`table`,{className:`w-full text-xs`,children:[(0,J.jsx)(`thead`,{className:`sticky top-0 bg-zinc-900 text-zinc-500`,children:(0,J.jsxs)(`tr`,{children:[(0,J.jsxs)(`th`,{className:`cursor-pointer select-none px-2 py-1 text-left font-medium hover:text-zinc-300`,onClick:()=>l(`time`),children:[`Time `,(0,J.jsx)(d,{column:`time`})]}),(0,J.jsxs)(`th`,{className:`cursor-pointer select-none px-2 py-1 text-left font-medium hover:text-zinc-300`,onClick:()=>l(`tool`),children:[`Tool `,(0,J.jsx)(d,{column:`tool`})]}),(0,J.jsxs)(`th`,{className:`cursor-pointer select-none px-2 py-1 text-left font-medium hover:text-zinc-300`,onClick:()=>l(`risk`),children:[`Risk `,(0,J.jsx)(d,{column:`risk`})]}),(0,J.jsx)(`th`,{className:`px-2 py-1 text-left font-medium`,children:`Detail`}),(0,J.jsx)(`th`,{className:`px-2 py-1 text-left font-medium`,children:`Outcome`})]})}),(0,J.jsx)(`tbody`,{children:u.map((e,t)=>{let n=Nm[e.risk]??_t,r=Pm[e.risk]??`text-zinc-400`;return(0,J.jsxs)(`tr`,{className:`border-b border-zinc-900 hover:bg-zinc-800/50`,children:[(0,J.jsx)(`td`,{className:`whitespace-nowrap px-2 py-1.5 text-zinc-500`,children:Im(e.ts)}),(0,J.jsx)(`td`,{className:`whitespace-nowrap px-2 py-1.5 font-medium text-zinc-300`,children:e.toolName}),(0,J.jsx)(`td`,{className:`whitespace-nowrap px-2 py-1.5`,children:(0,J.jsxs)(`span`,{className:X(`flex items-center gap-1`,r),children:[(0,J.jsx)(n,{className:`h-3 w-3`}),e.risk]})}),(0,J.jsx)(`td`,{className:`max-w-xs truncate px-2 py-1.5 font-mono text-zinc-400`,children:Lm(e)}),(0,J.jsx)(`td`,{className:`whitespace-nowrap px-2 py-1.5 text-zinc-500`,children:e.outcome??``})]},`${e.toolUseId}-${t}`)})})]})})]})}var Vm=320;function Hm(e){return e<=0?`$0`:e>=.01?`$${e.toFixed(3)}`:`$${e.toFixed(5)}`.replace(/0+$/,``).replace(/\.$/,``)}function Um(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}K`:String(e)}function Wm(e,t){let n=Array.from(e.values());return n.sort((e,n)=>{if(e.id===t)return-1;if(n.id===t)return 1;let r=e.status===`running`?0:1,i=n.status===`running`?0:1;return r===i?e.startedAt-n.startedAt:r-i}),n}function Gm(){let e=q(e=>e.inspectorOpen),t=q(e=>e.inspectorTab),n=q(e=>e.toggleInspector),r=q(e=>e.setInspectorOpen),i=q(e=>e.setInspectorTab),a=Y(e=>e.agents),o=Y(e=>e.leaderId),s=Y(e=>e.fleetTokensIn),c=Y(e=>e.fleetTokensOut),l=Y(e=>e.fleetConcurrency),u=Y(e=>e.fleetConcurrencyMax),d=Y(e=>e.eventTimeline),f=(0,H.useMemo)(()=>Wm(a,o),[a,o]),p=f.filter(e=>e.status===`running`).length,m=f.reduce((e,t)=>e+t.costUsd,0),h=f.length,[g,_]=(0,H.useState)(null),v=(0,H.useMemo)(()=>g?a.get(g)??f[0]??null:f[0]??null,[g,f,a]),y=()=>i(`fleet`),b=()=>i(`agents`),x=()=>i(`sideEffects`),S=yi(e=>e.sideEffects.length);return(0,J.jsxs)(`div`,{className:`shrink-0 border-t bg-card flex flex-col`,children:[(0,J.jsxs)(`button`,{type:`button`,onClick:n,className:X(`group w-full flex items-center justify-between gap-2 px-3 h-7 text-[11px]`,`text-muted-foreground hover:text-foreground hover:bg-accent/40 transition-colors`),title:e?`Hide inspector panel`:`Show inspector panel (Fleet / Agents / Audit)`,children:[(0,J.jsxs)(`span`,{className:`flex items-center gap-2 min-w-0`,children:[e?(0,J.jsx)(Me,{className:`h-3.5 w-3.5 shrink-0`}):(0,J.jsx)(ut,{className:`h-3.5 w-3.5 shrink-0`}),(0,J.jsx)(`span`,{className:`font-medium uppercase tracking-wider`,children:`Inspector`}),h>0&&(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(`span`,{className:`opacity-40`,children:`·`}),(0,J.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,J.jsx)(`span`,{className:X(`h-1.5 w-1.5 rounded-full`,p>0?`bg-emerald-500 animate-pulse`:`bg-muted-foreground/50`)}),(0,J.jsxs)(`span`,{className:`tabular-nums`,children:[p,`/`,h]})]}),(0,J.jsx)(`span`,{className:`opacity-40 hidden sm:inline`,children:`·`}),(0,J.jsxs)(`span`,{className:`tabular-nums font-mono hidden sm:inline`,children:[`↓`,Um(s),` ↑`,Um(c),` · `,Hm(m)]})]}),S>0&&(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(`span`,{className:`opacity-40`,children:`·`}),(0,J.jsxs)(`button`,{onClick:e=>{e.stopPropagation(),r(!0),i(`sideEffects`)},className:`flex items-center gap-1 text-yellow-500 hover:text-yellow-400 transition-colors`,title:`Open Audit tab`,children:[(0,J.jsx)(_t,{className:`h-3 w-3`}),(0,J.jsx)(`span`,{className:`tabular-nums`,children:S})]})]})]}),(0,J.jsxs)(`span`,{className:`flex items-center gap-1 shrink-0 opacity-70 group-hover:opacity-100`,children:[(0,J.jsx)(Yn,{className:`h-3 w-3`}),(0,J.jsx)(Mr,{className:`h-3 w-3`}),(0,J.jsx)(_t,{className:`h-3 w-3`})]})]}),(0,J.jsx)(`div`,{className:`overflow-hidden transition-[height] duration-300 ease-[cubic-bezier(0.16,1,0.3,1)]`,style:{height:e?Vm:0},children:(0,J.jsxs)(`div`,{className:`flex flex-col`,style:{height:Vm},children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-1 px-2 h-8 border-b bg-muted/30 shrink-0`,children:[(0,J.jsx)(Km,{active:t===`fleet`,onClick:y,icon:(0,J.jsx)(Yn,{className:`h-3.5 w-3.5`}),label:`Fleet`,count:h,running:p}),(0,J.jsx)(Km,{active:t===`agents`,onClick:b,icon:(0,J.jsx)(Mr,{className:`h-3.5 w-3.5`}),label:`Agents`,count:h}),(0,J.jsx)(Km,{active:t===`sideEffects`,onClick:x,icon:(0,J.jsx)(_t,{className:`h-3.5 w-3.5`}),label:`Audit`,count:S}),(0,J.jsx)(`div`,{className:`flex-1`}),(0,J.jsx)(`button`,{type:`button`,onClick:()=>r(!1),className:`p-1 rounded hover:bg-muted transition-colors text-muted-foreground hover:text-foreground`,"aria-label":`Collapse inspector panel`,title:`Collapse (Esc)`,children:(0,J.jsx)(Me,{className:`h-4 w-4`})})]}),(0,J.jsx)(`div`,{className:`flex-1 min-h-0 overflow-y-auto`,children:t===`fleet`?(0,J.jsx)(qm,{fleetList:f,leaderId:o,selectedAgentId:g,runningCount:p,fleetConcurrency:l,fleetConcurrencyMax:u,fleetTokensIn:s,fleetTokensOut:c,totalCost:m,eventTimeline:d,onSelectAgent:e=>{_(e.id),b()}}):t===`agents`?(0,J.jsx)(Jm,{fleetList:f,selectedAgent:v,leaderId:o,selectedAgentId:v?.id??null,onSelectAgent:_}):(0,J.jsx)(Bm,{})})]})})]})}function Km({active:e,onClick:t,icon:n,label:r,count:i,running:a}){return(0,J.jsxs)(`button`,{type:`button`,onClick:t,className:X(`flex items-center gap-1.5 px-2.5 h-6 rounded-md text-[11px] font-medium transition-colors`,e?`bg-background text-foreground shadow-sm ring-1 ring-border`:`text-muted-foreground hover:text-foreground hover:bg-background/60`),children:[n,r,i>0&&(0,J.jsx)(`span`,{className:X(`tabular-nums text-[10px] px-1 rounded-full`,a&&a>0?`bg-emerald-500/15 text-emerald-600 dark:text-emerald-400`:`bg-muted text-muted-foreground`),children:a===void 0?i:`${a}/${i}`})]})}function qm({fleetList:e,leaderId:t,selectedAgentId:n,runningCount:r,fleetConcurrency:i,fleetConcurrencyMax:a,fleetTokensIn:o,fleetTokensOut:s,totalCost:c,eventTimeline:l,onSelectAgent:u}){return(0,J.jsxs)(`div`,{className:`flex flex-col h-full`,children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-3 px-3 py-1.5 border-b text-[11px] text-muted-foreground shrink-0`,children:[(0,J.jsxs)(`span`,{className:`flex items-center gap-1`,children:[r>0&&(0,J.jsx)(`span`,{className:`h-1.5 w-1.5 rounded-full bg-emerald-500 animate-pulse`}),(0,J.jsxs)(`span`,{className:`tabular-nums`,children:[r,` running · `,e.length,` total`]})]}),(0,J.jsx)(Tm,{current:i,max:a,showLabel:!0}),(0,J.jsx)(`div`,{className:`flex-1`}),(0,J.jsxs)(`span`,{className:`tabular-nums font-mono`,children:[`↓`,Um(o),` ↑`,Um(s),` · `,Hm(c)]})]}),e.length===0?(0,J.jsxs)(`div`,{className:`flex flex-col items-center justify-center py-8 text-muted-foreground`,children:[(0,J.jsx)(Mr,{className:`h-8 w-8 mb-2 opacity-20`}),(0,J.jsx)(`p`,{className:`text-xs font-medium`,children:`No agents active`}),(0,J.jsx)(`p`,{className:`text-[11px] mt-0.5`,children:`Agents appear here when the fleet is active.`})]}):(0,J.jsx)(`div`,{className:`flex-1 min-h-0 overflow-y-auto p-1.5`,children:e.map(e=>(0,J.jsx)(jm,{agent:e,isSelected:n===e.id,isLeader:e.id===t,onClick:()=>u(e)},e.id))}),l.length>0&&(0,J.jsx)(`div`,{className:`border-t px-3 py-1.5 shrink-0`,children:(0,J.jsx)(Om,{events:l,max:4})})]})}function Jm({fleetList:e,selectedAgent:t,leaderId:n,selectedAgentId:r,onSelectAgent:i}){if(e.length===0)return(0,J.jsxs)(`div`,{className:`flex flex-col items-center justify-center py-8 text-muted-foreground`,children:[(0,J.jsx)(Yn,{className:`h-8 w-8 mb-2 opacity-20`}),(0,J.jsx)(`p`,{className:`text-xs font-medium`,children:`No agents active`})]});if(!t)return null;let a=Math.max(0,e.findIndex(e=>e.id===r));return(0,J.jsxs)(`div`,{className:`flex flex-col h-full`,children:[(0,J.jsx)(`div`,{className:`flex-1 min-h-0 overflow-y-auto p-3`,children:(0,J.jsx)(`div`,{className:`max-w-2xl mx-auto`,children:(0,J.jsx)(Cm,{agent:t,isLeader:t.id===n})})}),(0,J.jsx)(`div`,{className:`border-t px-2 py-1.5 shrink-0`,children:(0,J.jsx)(`div`,{className:`flex items-center gap-1 overflow-x-auto pb-0.5`,children:e.map((e,n)=>(0,J.jsxs)(`button`,{type:`button`,onClick:()=>i(e.id),className:X(`shrink-0 flex items-center gap-1.5 px-2 py-1 rounded-md text-[10px] transition-colors`,e.id===t?.id?`bg-primary/15 text-primary ring-1 ring-primary/40`:`hover:bg-accent text-muted-foreground`),title:`${e.name}${n===a?` (selected)`:``}`,children:[(0,J.jsx)(`span`,{className:X(`h-1.5 w-1.5 rounded-full shrink-0`,e.status===`running`?`bg-emerald-500 animate-pulse`:e.status===`failed`?`bg-destructive`:`bg-muted-foreground/50`)}),(0,J.jsx)(`span`,{className:`truncate max-w-[8rem]`,children:e.name})]},e.id))})})]})}var Ym={btw:{label:`btw`,title:`By-the-way — sent as follow-up without interrupting the running agent`,tone:`bg-sky-500/10 text-sky-700 dark:text-sky-300 border-sky-500/30`},steer:{label:`steer`,title:`Steer — interrupts the running agent and redirects it with this message`,tone:`bg-amber-500/10 text-amber-700 dark:text-amber-300 border-amber-500/30`},queue:{label:`queue`,title:`Queued — held until the current agent run completes, then sent in order`,tone:`bg-indigo-500/10 text-indigo-700 dark:text-indigo-300 border-indigo-500/30`}};function Xm({open:e,onClose:t,className:n}){let r=W(e=>e.queue),i=W(e=>e.removeQueued),a=W(e=>e.clearQueue),[o,s]=(0,H.useState)(`oldest`),c=(0,H.useCallback)(e=>{i(e)},[i]),l=(0,H.useMemo)(()=>{let e=r.map((e,t)=>({item:e,sourceIdx:t}));return e.sort((e,t)=>o===`newest`?t.item.addedAt-e.item.addedAt:e.item.addedAt-t.item.addedAt),e},[r,o]);return e?(0,J.jsx)(`div`,{className:X(`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-[70vh] 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-indigo-500/10 text-indigo-600 dark:text-indigo-400`,children:(0,J.jsx)(L,{className:`h-4 w-4`})}),(0,J.jsxs)(`div`,{children:[(0,J.jsx)(`h2`,{className:`text-sm font-semibold`,children:`Message Queue`}),(0,J.jsxs)(`span`,{className:`text-[10px] text-muted-foreground tabular-nums`,children:[r.length,` queued · messages sent before the agent finishes`]})]})]}),(0,J.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,J.jsxs)(`button`,{type:`button`,onClick:()=>s(e=>e===`newest`?`oldest`:`newest`),className:X(`flex items-center gap-1.5 px-2.5 py-1.5 rounded-md text-xs transition-colors font-medium`,`text-muted-foreground hover:bg-muted hover:text-foreground`),title:o===`newest`?`Sorted newest first — click to sort oldest first`:`Sorted oldest first — click to sort newest first`,"data-testid":`queue-sort-toggle`,children:[o===`newest`?(0,J.jsx)(Tn,{className:`h-3 w-3`}):(0,J.jsx)(bn,{className:`h-3 w-3`}),o===`newest`?`Newest`:`Oldest`]}),r.length>0&&(0,J.jsxs)(`button`,{type:`button`,onClick:()=>a(),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`,title:`Clear all queued messages`,"data-testid":`queue-clear-all`,children:[(0,J.jsx)(Te,{className:`h-3 w-3`}),`Clear`]}),(0,J.jsx)(`button`,{type:`button`,onClick:t,className:`p-1.5 rounded-md hover:bg-muted transition-colors`,title:`Close`,children:(0,J.jsx)(B,{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)(L,{className:`h-10 w-10 opacity-15`}),(0,J.jsx)(`p`,{className:`text-sm font-medium`,children:`Queue is empty`}),(0,J.jsxs)(`p`,{className:`text-xs text-center max-w-xs`,children:[`Use the `,(0,J.jsx)(`span`,{className:`font-mono`,children:`btw`}),` /`,` `,(0,J.jsx)(`span`,{className:`font-mono`,children:`steer`}),` /`,` `,(0,J.jsx)(`span`,{className:`font-mono`,children:`add queue`}),` buttons beside the input to add messages. Queued items are sent in order when the current agent run completes.`]})]}):(0,J.jsx)(`ul`,{className:`divide-y`,"data-testid":`queue-list`,children:l.map(({item:e,sourceIdx:t},n)=>{let r=Ym[e.mode];return(0,J.jsxs)(`li`,{className:`flex items-start justify-between px-4 py-3 text-xs hover:bg-muted/30 transition-colors gap-3`,"data-testid":`queue-item`,children:[(0,J.jsxs)(`div`,{className:`flex items-start gap-3 min-w-0 flex-1`,children:[(0,J.jsxs)(`span`,{className:`mt-1 text-[10px] font-mono text-muted-foreground shrink-0 w-5 text-right tabular-nums`,children:[n+1,`.`]}),(0,J.jsx)(`span`,{className:X(`shrink-0 inline-flex items-center justify-center text-[10px] font-semibold uppercase tracking-wider px-1.5 py-0.5 rounded border`,r.tone),title:r.title,"data-testid":`queue-mode-${e.mode}`,children:r.label}),(0,J.jsx)(`p`,{className:`text-sm text-foreground leading-relaxed min-w-0 break-words`,children:e.text.length>120?`${e.text.slice(0,117)}…`:e.text})]}),(0,J.jsx)(`button`,{type:`button`,onClick:()=>c(t),className:`ml-1 p-1.5 rounded-md shrink-0 hover:bg-destructive/10 hover:text-destructive transition-colors`,title:`Remove from queue`,"data-testid":`queue-remove-${t}`,children:(0,J.jsx)(B,{className:`h-3.5 w-3.5`})})]},`${e.addedAt}-${t}`)})})}),r.length>0&&(0,J.jsx)(`div`,{className:`px-4 py-2.5 border-t shrink-0`,children:(0,J.jsx)(`p`,{className:`text-[10px] text-muted-foreground text-center`,children:`Messages are sent in arrival order when the current agent run completes. Use the sort toggle to view newest-first.`})})]})}):null}var Zm={background:`#1e1e2e`,foreground:`#cdd6f4`,cursor:`#f5e0dc`,selectionBackground:`#585b70`,black:`#45475a`,red:`#f38ba8`,green:`#a6e3a1`,yellow:`#f9e2af`,blue:`#89b4fa`,magenta:`#f5c2e7`,cyan:`#94e2d5`,white:`#bac2de`,brightBlack:`#585b70`,brightRed:`#f38ba8`,brightGreen:`#a6e3a1`,brightYellow:`#f9e2af`,brightBlue:`#89b4fa`,brightMagenta:`#f5c2e7`,brightCyan:`#94e2d5`,brightWhite:`#a6adc8`};function Qm(){try{return crypto.randomUUID()}catch{return`term-${Date.now()}-${Math.floor(Math.random()*1e6)}`}}function $m({onClose:e}){let t=(0,H.useRef)(null);return(0,H.useEffect)(()=>{let e=t.current;if(!e)return;let n=new kn({fontFamily:`"IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, monospace`,fontSize:13,cursorBlink:!0,theme:Zm,scrollback:5e3}),r=new Jn;n.loadAddon(r),n.open(e);try{r.fit()}catch{}let i=Qm(),a=U(G.getState().wsUrl);a.send({type:`terminal.create`,payload:{id:i,cols:n.cols,rows:n.rows}});let o=a.on(`terminal.output`,e=>{e.type===`terminal.output`&&e.payload.id===i&&n.write(e.payload.data)}),s=a.on(`terminal.exit`,e=>{e.type===`terminal.exit`&&e.payload.id===i&&n.write(`\r\n\x1b[2m[process exited with code ${e.payload.exitCode}]\x1b[0m\r\n`)}),c=n.onData(e=>{a.send({type:`terminal.input`,payload:{id:i,data:e}})}),l=new ResizeObserver(()=>{try{r.fit(),a.send({type:`terminal.resize`,payload:{id:i,cols:n.cols,rows:n.rows}})}catch{}});return l.observe(e),n.focus(),()=>{o(),s(),c.dispose(),l.disconnect(),a.send({type:`terminal.close`,payload:{id:i}}),n.dispose()}},[G(e=>e.wsConnected)]),(0,J.jsxs)(`div`,{className:`fixed bottom-0 left-0 right-0 z-40 h-[40vh] min-h-[200px] flex flex-col border-t border-border bg-[#1e1e2e] shadow-2xl`,children:[(0,J.jsxs)(`div`,{className:`flex items-center justify-between px-3 py-1.5 border-b border-border/40 bg-[#181825]`,children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-2 text-xs text-[#cdd6f4]`,children:[(0,J.jsx)(Le,{className:`h-3.5 w-3.5`}),(0,J.jsx)(`span`,{className:`font-medium`,children:`Terminal`})]}),(0,J.jsx)(`button`,{type:`button`,onClick:e,title:"Close terminal (Ctrl+`)",className:`inline-flex items-center justify-center h-6 w-6 rounded text-[#a6adc8] hover:bg-white/10 transition-colors`,children:(0,J.jsx)(B,{className:`h-4 w-4`})})]}),(0,J.jsx)(`div`,{ref:t,className:`flex-1 overflow-hidden px-2 py-1`})]})}var eh={note:zt,ask:Je,assign:dt,steer:Ht,btw:St,broadcast:dt,status:Qe,result:M},th={note:`Note`,ask:`Question`,assign:`Assignment`,steer:`Steer`,btw:`By the way`,broadcast:`Broadcast`,status:`Status`,result:`Result`},nh={high:`text-red-600 bg-red-50 dark:bg-red-950/30`,normal:`text-muted-foreground bg-muted`,low:`text-slate-500 bg-slate-50 dark:bg-slate-950/20`};function rh(e){return new Date(e).toLocaleString()}function ih(e){let t=new Date(e),n=Date.now()-t.getTime();return n<6e4?`just now`:n<36e5?`${Math.round(n/6e4)}m ago`:n<864e5?`${Math.round(n/36e5)}h ago`:n<6048e5?`${Math.round(n/864e5)}d ago`:t.toLocaleDateString()}function ah(){return(0,J.jsxs)(`div`,{className:`flex-1 flex flex-col items-center justify-center text-muted-foreground gap-3`,children:[(0,J.jsx)(Ce,{className:`h-12 w-12 opacity-20`}),(0,J.jsx)(`div`,{className:`text-sm font-medium`,children:`No message selected`}),(0,J.jsx)(`div`,{className:`text-xs max-w-[260px] text-center opacity-60`,children:`Click a message in the Mailbox panel to view it here.`})]})}function oh({readBy:e}){let t=Object.entries(e);return t.length===0?null:(0,J.jsxs)(`div`,{className:`space-y-1`,children:[(0,J.jsx)(`div`,{className:`text-[10px] font-semibold text-muted-foreground uppercase tracking-wide`,children:`Read by`}),(0,J.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:t.map(([e,t])=>(0,J.jsxs)(`span`,{className:`inline-flex items-center gap-1 px-1.5 py-0.5 rounded text-[10px] bg-green-50 text-green-700 dark:bg-green-950/30 dark:text-green-400`,title:rh(t),children:[(0,J.jsx)(M,{className:`h-2.5 w-2.5`}),e]},e))})]})}function sh({className:e}){let t=q(e=>e.selectedMailMessage),n=q(e=>e.setSelectedMailMessage),r=q(e=>e.setCurrentView);(0,H.useEffect)(()=>()=>{n(null)},[n]);function i(){n(null),r(`chat`)}if(!t)return(0,J.jsx)(ah,{});let a=eh[t.type]??Ue,o=th[t.type]??t.type,s=nh[t.priority]??nh.normal;return(0,J.jsxs)(`div`,{className:X(`flex-1 flex flex-col overflow-hidden`,e),children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-3 px-4 py-2.5 border-b border-border bg-card/40 shrink-0`,children:[(0,J.jsx)(`button`,{type:`button`,onClick:i,className:`flex items-center justify-center w-7 h-7 rounded-md hover:bg-accent text-muted-foreground hover:text-foreground transition-colors shrink-0`,title:`Back to chat`,children:(0,J.jsx)(Kt,{className:`h-4 w-4`})}),(0,J.jsx)(`div`,{className:X(`p-1.5 rounded-md shrink-0`,t.completed?`bg-green-100 dark:bg-green-950/40`:`bg-amber-100 dark:bg-amber-950/40`),children:(0,J.jsx)(a,{className:X(`h-4 w-4`,t.completed?`text-green-600 dark:text-green-400`:`text-amber-600 dark:text-amber-400`)})}),(0,J.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,J.jsx)(`h2`,{className:`text-sm font-semibold text-foreground truncate`,children:t.subject}),t.completed&&(0,J.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-[10px] font-medium text-green-600 dark:text-green-400 shrink-0`,children:[(0,J.jsx)(M,{className:`h-3 w-3`}),`Completed`]})]}),(0,J.jsxs)(`div`,{className:`flex items-center gap-2 text-[11px] text-muted-foreground mt-0.5`,children:[(0,J.jsx)(`span`,{className:`font-medium text-foreground/80`,children:t.from}),(0,J.jsx)(`span`,{children:`→`}),(0,J.jsx)(`span`,{children:t.to===`*`||t.to===`all`?`everyone`:t.to}),(0,J.jsx)(`span`,{className:`opacity-40`,children:`•`}),(0,J.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,J.jsx)(Fr,{className:`h-3 w-3`}),ih(t.timestamp)]})]})]}),(0,J.jsx)(`button`,{type:`button`,onClick:i,className:`flex items-center justify-center w-7 h-7 rounded-md hover:bg-accent text-muted-foreground hover:text-foreground transition-colors shrink-0`,title:`Close (Esc)`,children:(0,J.jsx)(B,{className:`h-4 w-4`})})]}),(0,J.jsx)(`div`,{className:`flex-1 overflow-y-auto`,children:(0,J.jsx)(`div`,{className:`px-4 py-4`,children:(0,J.jsx)(`div`,{className:`markdown-content prose prose-sm dark:prose-invert max-w-none text-sm leading-relaxed`,children:(0,J.jsx)(Re,{components:od,children:t.body})})})}),(0,J.jsxs)(`div`,{className:`border-t border-border bg-card/30 px-4 py-3 shrink-0`,children:[(0,J.jsxs)(`div`,{className:`grid grid-cols-2 sm:grid-cols-4 gap-x-6 gap-y-2 text-xs`,children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-1.5 text-muted-foreground`,children:[(0,J.jsx)(ve,{className:`h-3 w-3 shrink-0`}),(0,J.jsx)(`span`,{children:o})]}),(0,J.jsx)(`div`,{className:`flex items-center gap-1.5`,children:(0,J.jsx)(`span`,{className:X(`px-1.5 py-0.5 rounded text-[10px] font-semibold uppercase`,s),children:t.priority||`normal`})}),(0,J.jsxs)(`div`,{className:`flex items-center gap-1.5 text-muted-foreground`,children:[(0,J.jsx)(At,{className:`h-3 w-3 shrink-0`}),(0,J.jsx)(`span`,{className:`truncate`,title:t.from,children:t.from})]}),(0,J.jsxs)(`div`,{className:`flex items-center gap-1.5 text-muted-foreground`,children:[(0,J.jsx)(Fr,{className:`h-3 w-3 shrink-0`}),(0,J.jsx)(`span`,{children:rh(t.timestamp)})]}),t.replyTo&&(0,J.jsxs)(`div`,{className:`flex items-center gap-1.5 text-muted-foreground col-span-2`,children:[(0,J.jsx)(cn,{className:`h-3 w-3 shrink-0`}),(0,J.jsxs)(`span`,{className:`truncate`,children:[`In reply to: `,t.replyTo]})]}),t.completed&&t.completedBy&&(0,J.jsxs)(`div`,{className:`flex items-center gap-1.5 text-muted-foreground col-span-2`,children:[(0,J.jsx)(M,{className:`h-3 w-3 shrink-0 text-green-500`}),(0,J.jsxs)(`span`,{children:[`Completed by `,t.completedBy,t.completedAt?` at ${rh(t.completedAt)}`:``]})]}),t.outcome&&(0,J.jsxs)(`div`,{className:`flex items-start gap-1.5 text-muted-foreground col-span-2 sm:col-span-4`,children:[(0,J.jsx)(`span`,{className:`text-[10px] font-semibold uppercase tracking-wide shrink-0 mt-0.5`,children:`Outcome:`}),(0,J.jsx)(`span`,{children:t.outcome})]}),t.taskContext&&(0,J.jsxs)(`div`,{className:`flex items-start gap-1.5 text-muted-foreground col-span-2 sm:col-span-4`,children:[(0,J.jsx)(`span`,{className:`text-[10px] font-semibold uppercase tracking-wide shrink-0 mt-0.5`,children:`Task:`}),(0,J.jsx)(`span`,{children:t.taskContext})]})]}),Object.keys(t.readBy??{}).length>0&&(0,J.jsx)(`div`,{className:`mt-3 pt-3 border-t border-border/50`,children:(0,J.jsx)(oh,{readBy:t.readBy})})]})]})}function ch(e){let t=e.match(/^(.+?)\/SKILL(?:\.save)?\.md$/);return t?t[1]:null}function lh({source:e}){let t=e===`project`?`project`:e===`user`?`user`:`bundled`;return(0,J.jsx)(`span`,{className:X(`inline-flex items-center px-1.5 py-0.5 rounded text-[10px] font-semibold uppercase tracking-wide`,t===`project`&&`bg-emerald-100 text-emerald-700 dark:bg-emerald-950 dark:text-emerald-400`,t===`user`&&`bg-violet-100 text-violet-700 dark:bg-violet-950 dark:text-violet-400`,t===`bundled`&&`bg-slate-100 text-slate-600 dark:bg-slate-800 dark:text-slate-400`),children:{project:`Project`,user:`Global`,bundled:`Bundled`}[t]})}function uh({className:e}){let{client:t}=Q(),n=q(e=>e.skillsState),r=q(e=>e.setSkillsState),a=q(e=>e.setCurrentView),o=n.selectedSkill,s=n.navHistory,c=n.historyIndex,[l,u]=(0,H.useState)(null),[d,f]=(0,H.useState)(!1),[m,h]=(0,H.useState)(null),[g,_]=(0,H.useState)(!1),[v,y]=(0,H.useState)(``),[x,S]=(0,H.useState)(!1),[C,w]=(0,H.useState)(null),[T,E]=(0,H.useState)(!1),[D,O]=(0,H.useState)(null),[k,A]=(0,H.useState)(!1),j=(0,H.useRef)(``),[M,N]=(0,H.useState)(!1),[P,F]=(0,H.useState)(null),[I,ee]=(0,H.useState)(!1),[te,L]=(0,H.useState)(null),[ne,re]=(0,H.useState)(!1),[ie,ae]=(0,H.useState)([]),oe=(0,H.useRef)(n);oe.current=n;let se=(0,H.useRef)(!1),ce=(0,H.useMemo)(()=>v?{lines:v.split(`
|
|
138
138
|
`).length,words:v.trim()?v.trim().split(/\s+/).length:0,chars:v.length}:{lines:0,words:0,chars:0},[v]),le=(0,H.useMemo)(()=>{if(!v)return null;let e=5*1024*1024,t=new Blob([v]).size;return t>=e?{level:`critical`,used:t,limit:e}:t>=4194304?{level:`warn`,used:t,limit:e}:null},[v]);(0,H.useEffect)(()=>{if(!D)return;let e=setTimeout(()=>O(null),2e3);return()=>clearTimeout(e)},[D]),(0,H.useEffect)(()=>{if(!g||!o)return;let e=setInterval(()=>{v&&v!==j.current&&(j.current=v,localStorage.setItem(`skills_draft_${o.name}`,JSON.stringify({content:v,savedAt:Date.now()})),O(Date.now()))},5e3);return()=>clearInterval(e)},[g,v,o]),(0,H.useEffect)(()=>{if(!o||!g)return;let e=localStorage.getItem(`skills_draft_${o.name}`);if(e)try{let{content:t}=JSON.parse(e);t&&t!==v&&t!==j.current&&(y(t),j.current=t,A(!0))}catch{}},[o?.name,g]),(0,H.useEffect)(()=>{if(!t||!o)return;f(!0),u(null),h(null);let e=setTimeout(()=>{f(!1),h(`Request timed out. Please try again.`)},1e4),n=t=>{clearTimeout(e);let n=t;n.payload.error?h(n.payload.error):n.payload.name&&u(n.payload),f(!1)},i=e=>{let n=e;N(!1);let i=oe.current;if(n.payload.success){let e={...i.knownRefs};for(let t of n.payload.updated??[])e[t.name]=t.newRef;r({...i,knownRefs:e,updateAvailableCount:0}),F({updated:n.payload.updated??[],unchanged:n.payload.unchanged??[],errors:n.payload.errors??[]}),t.send({type:`skills.list`})}else F({updated:[],unchanged:[],errors:[{name:``,error:n.payload.error??`Update failed`}]})},a=e=>{let t=e;t.payload.skills&&ae(t.payload.skills)};return t.on(`skills.content`,n),t.on(`skills.updated`,i),t.on(`skills.list`,a),t.send({type:`skills.content`,payload:{name:o.name,source:o.source}}),()=>{clearTimeout(e),t.off(`skills.content`,n),t.off(`skills.updated`,i),t.off(`skills.list`,a)}},[t,o?.name,o?.source]),(0,H.useEffect)(()=>{g&&(_(!1),y(``),w(null))},[o?.name]);let ue=(0,H.useCallback)(e=>ie.find(t=>t.name.toLowerCase()===e.toLowerCase()),[ie]),de=(0,H.useCallback)(e=>{let t=ue(e);if(t){se.current=!1;let e=s.slice(0,c+1);e.push(t),r({...oe.current,selectedSkill:t,navHistory:e,historyIndex:e.length-1}),_(!1),y(``),F(null)}},[ue,s,c,r]),R=(0,H.useCallback)(()=>{if(c<=0)return;se.current=!0;let e=c-1,t=s[e];r({...oe.current,selectedSkill:t,historyIndex:e}),_(!1),y(``),F(null)},[c,s,r]),fe=(0,H.useCallback)(()=>{if(c>=s.length-1)return;se.current=!0;let e=c+1,t=s[e];r({...oe.current,selectedSkill:t,historyIndex:e}),_(!1),y(``),F(null)},[c,s,r]),pe=(0,H.useCallback)(()=>{a(`chat`)},[a]),me=(0,H.useCallback)(()=>{l&&(y(l.body),j.current=l.body,A(!1),w(null),_(!0),E(!1))},[l]),he=(0,H.useCallback)(()=>{_(!1),y(``),w(null),E(!1),A(!1),o&&localStorage.removeItem(`skills_draft_${o.name}`)},[o]),ge=(0,H.useCallback)(()=>{!o||!l||(A(!1),y(l.body),j.current=l.body,o&&localStorage.removeItem(`skills_draft_${o.name}`))},[o,l]),_e=(0,H.useCallback)(()=>{if(!t||!o||!v.trim())return;S(!0),w(null);let e=n=>{let r=n;S(!1),r.payload.success?(j.current=``,localStorage.removeItem(`skills_draft_${o.name}`),A(!1),_(!1),t.send({type:`skills.content`,payload:{name:o.name,source:o.source}}),t.send({type:`skills.list`})):w(r.payload.error??`Save failed`),t.off(`skills.edited`,e)};t.on(`skills.edited`,e),t.editSkill(o.name,v)},[t,o,v]),ve=(0,H.useCallback)(()=>{!t||!o||(N(!0),F(null),t.checkForUpdates(o.name,o.source===`user`))},[t,o]),ye=(0,H.useCallback)(()=>{o?.sourceUrl&&navigator.clipboard.writeText(o.sourceUrl).then(()=>{ee(!0),setTimeout(()=>ee(!1),2e3)})},[o]),be=(0,H.useCallback)(()=>{if(!l?.body)return;let e=new Blob([l.body],{type:`text/markdown`}),t=URL.createObjectURL(e),n=document.createElement(`a`);n.href=t,n.download=`${l.name.replace(/\//g,`_`)}-SKILL.md`,document.body.appendChild(n),n.click(),document.body.removeChild(n),URL.revokeObjectURL(t)},[l]),xe=(0,H.useCallback)(async e=>{if(!t||!e)return;re(!0);let n=e=>{let r=e;re(!1),r.payload.success?(L(null),t.send({type:`skills.list`}),pe()):w(r.payload.error??`Uninstall failed`),t.off(`skills.uninstalled`,n)};t.on(`skills.uninstalled`,n),t.uninstallSkill(e.name,e.source===`user`)},[t,pe]);return o?(0,J.jsxs)(`div`,{className:X(`flex flex-col h-full overflow-hidden bg-background`,e),children:[(0,J.jsxs)(`div`,{className:`px-4 py-3 border-b bg-card shrink-0`,children:[(0,J.jsxs)(`div`,{className:`flex items-start justify-between gap-3`,children:[(0,J.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,J.jsx)(p,{className:`h-4 w-4 text-primary shrink-0`}),(0,J.jsx)(`h1`,{className:`text-base font-semibold truncate`,children:o.name}),o.version&&(0,J.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[`v`,o.version]}),(0,J.jsx)(lh,{source:o.source})]}),(0,J.jsx)(`p`,{className:`text-sm text-muted-foreground mt-1 line-clamp-2`,children:o.description||o.trigger}),o.sourceUrl&&(0,J.jsxs)(`div`,{className:`flex items-center gap-1 mt-2`,children:[(0,J.jsxs)(`a`,{href:`https://${o.sourceUrl.replace(`github:`,``)}`,target:`_blank`,rel:`noopener noreferrer`,className:`flex items-center gap-1 text-xs text-muted-foreground hover:text-foreground transition-colors cursor-pointer`,title:`Open source repo`,children:[(0,J.jsx)(at,{className:`h-3 w-3 shrink-0`}),(0,J.jsx)(`span`,{className:`truncate font-mono`,children:o.sourceUrl})]}),(0,J.jsx)(`button`,{type:`button`,onClick:ye,className:`flex items-center shrink-0 text-muted-foreground hover:text-foreground transition-colors cursor-pointer`,title:`Copy source URL`,children:I?(0,J.jsx)(i,{className:`h-3 w-3 text-green-500`}):(0,J.jsx)(Oe,{className:`h-3 w-3`})})]}),o.scope.length>0&&(0,J.jsx)(`div`,{className:`flex flex-wrap gap-1 mt-2`,children:o.scope.map(e=>(0,J.jsx)(`span`,{className:`px-1.5 py-0.5 text-[10px] rounded bg-muted text-muted-foreground`,children:e},e))}),P&&(0,J.jsxs)(`div`,{className:`mt-2 text-xs space-y-1`,children:[P.updated.length>0&&(0,J.jsxs)(`div`,{className:`text-green-600`,children:[`↑ Updated: `,P.updated.map(e=>`${e.name} (${e.oldRef} → ${e.newRef})`).join(`, `)]}),P.unchanged.length>0&&(0,J.jsxs)(`div`,{className:`text-muted-foreground`,children:[`— Up to date: `,P.unchanged.join(`, `)]}),P.errors.length>0&&(0,J.jsxs)(`div`,{className:`text-destructive`,children:[`✗ `,P.errors.map(e=>`${e.name?`${e.name}: `:``}${e.error}`).join(`; `)]})]})]}),(0,J.jsxs)(`div`,{className:`flex items-center gap-1 ml-auto shrink-0`,children:[o.source!==`bundled`&&o.sourceUrl&&(0,J.jsx)(`button`,{type:`button`,onClick:ve,disabled:M,className:`flex items-center gap-1 px-2 py-1.5 text-xs rounded text-muted-foreground hover:text-foreground hover:bg-accent transition-colors cursor-pointer disabled:opacity-50`,title:`Check for updates`,children:M?(0,J.jsx)(z,{className:`h-3.5 w-3.5 animate-spin`}):(0,J.jsx)(Ct,{className:`h-3.5 w-3.5`})}),o.source!==`bundled`&&!g&&(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(`button`,{type:`button`,onClick:be,className:`flex items-center gap-1 px-2 py-1.5 text-xs rounded text-muted-foreground hover:text-foreground hover:bg-accent transition-colors cursor-pointer`,title:`Export skill as .md`,children:(0,J.jsx)(b,{className:`h-3.5 w-3.5`})}),(0,J.jsx)(`button`,{type:`button`,onClick:me,className:`flex items-center gap-1 px-2 py-1.5 text-xs rounded text-muted-foreground hover:text-foreground hover:bg-accent transition-colors cursor-pointer`,title:`Edit skill`,children:(0,J.jsx)(Rt,{className:`h-3.5 w-3.5`})})]}),o.source!==`bundled`&&(0,J.jsx)(`button`,{type:`button`,onClick:()=>L(o),className:`flex items-center gap-1 px-2 py-1.5 text-xs rounded text-muted-foreground hover:text-destructive hover:bg-destructive/10 transition-colors cursor-pointer`,title:`Uninstall skill`,children:(0,J.jsx)(Te,{className:`h-3.5 w-3.5`})}),(0,J.jsx)(`button`,{type:`button`,onClick:pe,className:`p-1.5 rounded hover:bg-accent text-muted-foreground cursor-pointer`,title:`Close and go to chat`,children:(0,J.jsx)(B,{className:`h-4 w-4`})})]})]}),s.length>1&&(0,J.jsxs)(`div`,{className:`flex items-center gap-1 mt-2`,children:[(0,J.jsx)(`button`,{type:`button`,onClick:R,disabled:c<=0,className:X(`p-1 rounded transition-colors`,c<=0?`text-muted-foreground/40 cursor-not-allowed`:`hover:bg-accent text-muted-foreground cursor-pointer`),title:`Go back`,children:(0,J.jsx)(mt,{className:`h-4 w-4`})}),(0,J.jsx)(`button`,{type:`button`,onClick:fe,disabled:c>=s.length-1,className:X(`p-1 rounded transition-colors`,c>=s.length-1?`text-muted-foreground/40 cursor-not-allowed`:`hover:bg-accent text-muted-foreground cursor-pointer`),title:`Go forward`,children:(0,J.jsx)(ot,{className:`h-4 w-4`})}),(0,J.jsx)(`div`,{className:`flex items-center gap-0.5 overflow-x-auto text-xs`,children:s.map((e,t)=>(0,J.jsxs)(`span`,{className:`flex items-center shrink-0`,children:[t>0&&(0,J.jsx)(ot,{className:`h-3 w-3 text-muted-foreground/40 mx-0.5 shrink-0`}),(0,J.jsx)(`button`,{type:`button`,onClick:()=>{t<c&&(se.current=!0,r({...oe.current,selectedSkill:e,historyIndex:t}),_(!1),y(``),F(null))},className:X(`hover:text-primary cursor-pointer transition-colors`,t===c?`text-primary font-medium`:`text-muted-foreground`),children:e.name})]},e.name+t))})]})]}),l&&(l.relatedFiles.length>0||l.references.length>0)&&(0,J.jsxs)(`div`,{className:`px-4 py-2 border-b bg-muted/30 shrink-0 space-y-2`,children:[l.relatedFiles.length>0&&(0,J.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-1 text-[10px] text-muted-foreground`,children:[(0,J.jsx)(wt,{className:`h-3 w-3`}),(0,J.jsx)(`span`,{className:`font-medium uppercase tracking-wide`,children:`Related Files`})]}),l.relatedFiles.map(e=>{let t=ch(e);return t&&ue(t)?(0,J.jsxs)(`button`,{type:`button`,onClick:()=>de(t),className:`inline-flex items-center gap-1 px-1.5 py-0.5 text-[10px] rounded bg-background border border-border hover:border-primary hover:text-primary transition-colors cursor-pointer`,title:`Go to ${t}`,children:[(0,J.jsx)(Mt,{className:`h-2.5 w-2.5`}),e]},e):(0,J.jsx)(`span`,{className:`px-1.5 py-0.5 text-[10px] rounded bg-background border border-border text-muted-foreground`,children:e},e)})]}),l.references.length>0&&(0,J.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-1 text-[10px] text-muted-foreground`,children:[(0,J.jsx)(zt,{className:`h-3 w-3`}),(0,J.jsx)(`span`,{className:`font-medium uppercase tracking-wide`,children:`References`})]}),l.references.map(e=>{let t=ch(e)??e.replace(/\.md$/,``);return ue(t)?(0,J.jsxs)(`button`,{type:`button`,onClick:()=>de(t),className:`inline-flex items-center gap-1 px-1.5 py-0.5 text-[10px] rounded bg-primary/5 border border-primary/20 text-primary hover:bg-primary/10 hover:border-primary/30 transition-colors cursor-pointer`,title:`Go to ${t}`,children:[(0,J.jsx)(Mt,{className:`h-2.5 w-2.5`}),t]},e):(0,J.jsx)(`span`,{className:`px-1.5 py-0.5 text-[10px] rounded bg-muted text-muted-foreground`,children:t},e)})]})]}),(0,J.jsx)(`div`,{className:`flex-1 overflow-y-auto`,children:d?(0,J.jsxs)(`div`,{className:`p-8 text-center text-muted-foreground`,children:[(0,J.jsx)(z,{className:`h-6 w-6 animate-spin mx-auto mb-2`}),(0,J.jsx)(`p`,{children:`Loading skill content…`})]}):g?(0,J.jsxs)(`div`,{className:`flex flex-col h-full`,children:[(0,J.jsxs)(`div`,{className:`px-4 py-2 border-b shrink-0 flex items-center justify-between gap-2`,children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,J.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[`Editing `,(0,J.jsx)(`span`,{className:`font-medium text-foreground`,children:o.name})]}),(0,J.jsxs)(`span`,{className:`text-xs text-muted-foreground tabular-nums`,children:[ce.lines,` line`,ce.lines===1?``:`s`,` · `,ce.words,` word`,ce.words===1?``:`s`,` · `,ce.chars,` char`,ce.chars===1?``:`s`]}),le&&(0,J.jsxs)(`span`,{className:`text-xs tabular-nums ${le.level===`critical`?`text-red-500 font-medium`:`text-amber-500`}`,children:[`⚠ `,(le.used/(1024*1024)).toFixed(1),`\xA0MB / `,(le.limit/(1024*1024)).toFixed(0),`\xA0MB`]}),D&&(0,J.jsx)(`span`,{className:`text-xs text-green-500 animate-pulse`,children:`Draft saved`}),k&&(0,J.jsx)(`span`,{className:`text-xs text-amber-500 animate-pulse`,children:`Draft restored`})]}),(0,J.jsxs)(`div`,{className:`flex items-center gap-2`,children:[C&&(0,J.jsx)(`span`,{className:`text-xs text-destructive`,children:C}),k&&(0,J.jsx)(`button`,{type:`button`,onClick:ge,className:`px-2 py-1 text-[10px] rounded border border-amber-500/50 text-amber-600 dark:text-amber-400 hover:bg-amber-500/10 transition-colors cursor-pointer`,children:`Discard draft`}),(0,J.jsx)(`button`,{type:`button`,onClick:he,className:`px-2 py-1 text-xs rounded border border-border hover:bg-accent transition-colors cursor-pointer`,children:`Cancel`}),(0,J.jsx)(`button`,{type:`button`,onClick:()=>E(e=>!e),title:T?`Hide preview`:`Split view`,className:`px-2 py-1 text-xs rounded border transition-colors cursor-pointer ${T?`border-primary bg-primary/10 text-primary`:`border-border hover:bg-accent text-muted-foreground`}`,children:(0,J.jsx)(En,{className:`h-3 w-3 inline`})}),(0,J.jsx)(`button`,{type:`button`,onClick:_e,disabled:x||!v.trim(),className:`px-3 py-1 text-xs rounded bg-primary text-primary-foreground hover:bg-primary/90 disabled:opacity-50 transition-colors cursor-pointer`,children:x?(0,J.jsx)(z,{className:`h-3 w-3 animate-spin inline`}):`Save`})]})]}),T?(0,J.jsxs)(`div`,{className:`flex flex-1 min-h-0 gap-0.5`,children:[(0,J.jsx)(`div`,{className:`flex-1 min-w-0 flex flex-col min-h-0`,children:(0,J.jsx)(ir,{value:v,onChange:e=>y(e.target.value??``),language:`markdown`,className:`flex-1`,style:{fontSize:12,backgroundColor:`transparent`,minHeight:0},placeholder:`Skill content (markdown)...`})}),(0,J.jsx)(`div`,{className:`w-px bg-border flex-shrink-0`}),(0,J.jsx)(`div`,{className:`flex-1 min-w-0 overflow-y-auto p-4 prose prose-sm dark:prose-invert max-w-none`,children:(0,J.jsx)(Re,{rehypePlugins:[Et],components:od,children:v})})]}):(0,J.jsx)(ir,{value:v,onChange:e=>y(e.target.value??``),language:`markdown`,className:`flex-1`,style:{fontSize:12,backgroundColor:`transparent`,minHeight:0},placeholder:`Skill content (markdown)...`})]}):l?(0,J.jsx)(`div`,{className:`p-6 prose prose-sm dark:prose-invert max-w-none`,children:(0,J.jsx)(Re,{rehypePlugins:[Et],components:od,children:l.body})}):m?(0,J.jsxs)(`div`,{className:`p-8 text-center`,children:[(0,J.jsx)(`p`,{className:`text-destructive mb-2`,children:`Failed to load skill content`}),(0,J.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:m}),(0,J.jsx)(`button`,{type:`button`,onClick:()=>{t&&o&&(f(!0),h(null),t.send({type:`skills.content`,payload:{name:o.name,source:o.source}}))},className:`mt-4 px-3 py-1.5 text-xs rounded border border-border hover:bg-accent transition-colors`,children:`Retry`})]}):(0,J.jsx)(`div`,{className:`p-8 text-center text-muted-foreground`,children:`No skill content available`})}),te&&(0,J.jsx)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/40`,onClick:e=>{e.target===e.currentTarget&&L(null)},children:(0,J.jsxs)(`div`,{className:`bg-background rounded-lg border shadow-xl w-[380px] max-w-[90vw]`,children:[(0,J.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-b`,children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,J.jsx)(Te,{className:`h-4 w-4 text-destructive`}),(0,J.jsx)(`span`,{className:`font-semibold text-sm`,children:`Uninstall Skill`})]}),(0,J.jsx)(`button`,{type:`button`,onClick:()=>L(null),className:`p-1 rounded hover:bg-accent text-muted-foreground cursor-pointer`,children:(0,J.jsx)(B,{className:`h-4 w-4`})})]}),(0,J.jsxs)(`div`,{className:`p-4 space-y-2`,children:[(0,J.jsxs)(`p`,{className:`text-sm`,children:[`Uninstall `,(0,J.jsx)(`span`,{className:`font-semibold`,children:te.name}),`?`]}),(0,J.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[`This will remove the skill from`,` `,(0,J.jsx)(`span`,{className:`font-mono text-[10px]`,children:te.source===`user`?`~/.wrongstack/skills`:`.wrongstack/skills`}),` `,`and cannot be undone.`]})]}),(0,J.jsxs)(`div`,{className:`flex justify-end gap-2 p-4 border-t bg-muted/20`,children:[(0,J.jsx)(`button`,{type:`button`,onClick:()=>L(null),disabled:ne,className:`px-3 py-1.5 text-xs rounded border border-border hover:bg-accent transition-colors disabled:opacity-50`,children:`Cancel`}),(0,J.jsxs)(`button`,{type:`button`,onClick:()=>xe(te),disabled:ne,className:`flex items-center gap-1.5 px-3 py-1.5 text-xs rounded bg-destructive text-destructive-foreground hover:bg-destructive/90 disabled:opacity-50 disabled:cursor-not-allowed transition-colors`,children:[ne&&(0,J.jsx)(z,{className:`h-3 w-3 animate-spin`}),`Uninstall`]})]})]})})]}):(0,J.jsxs)(`div`,{className:X(`flex-1 flex flex-col items-center justify-center text-muted-foreground p-8`,e),children:[(0,J.jsx)(sn,{className:`h-12 w-12 mb-4 opacity-20`}),(0,J.jsx)(`p`,{className:`text-base font-medium`,children:`No skill selected`}),(0,J.jsx)(`p`,{className:`text-sm mt-1 text-center max-w-[300px]`,children:`Select a skill from the sidebar to view its documentation`}),(0,J.jsx)(`button`,{type:`button`,onClick:pe,className:`mt-4 px-4 py-2 text-sm rounded-md border border-border hover:bg-accent transition-colors`,children:`Go to chat`})]})}function dh(e,t,n){return e<t?t:e>n?n:e}function fh(e){let t=/^oklch\(\s*([^)]+)\)$/i.exec(e.trim());if(!t?.[1])return null;let n=(t[1].split(`/`)[0]??``).trim().split(/\s+/);if(n.length<3||!n[0]||!n[1]||!n[2])return null;let r=n[0].endsWith(`%`)?Number.parseFloat(n[0])/100:Number.parseFloat(n[0]),i=n[1].endsWith(`%`)?Number.parseFloat(n[1])/100*.4:Number.parseFloat(n[1]),a=Number.parseFloat(n[2].replace(/deg$/i,``));return[r,i,a].every(Number.isFinite)?[dh(r,0,1),Math.max(0,i),a]:null}function ph(e){return dh(e<=.0031308?12.92*e:1.055*e**(1/2.4)-.055,0,1)}function mh(e){return Math.round(e*255).toString(16).padStart(2,`0`)}function hh(e){let t=fh(e);if(!t)return null;let[n,r,i]=t,a=i*Math.PI/180,o=r*Math.cos(a),s=r*Math.sin(a),c=n+.3963377774*o+.2158037573*s,l=n-.1055613458*o-.0638541728*s,u=n-.0894841775*o-1.291485548*s,d=c**3,f=l**3,p=u**3,m=4.0767416621*d-3.3077115913*f+.2309699292*p,h=-1.2684380046*d+2.6097574011*f-.3413193965*p,g=-.0041960863*d-.7034186147*f+1.707614701*p;return`#${mh(ph(m))}${mh(ph(h))}${mh(ph(g))}`}function gh(e){let t=e.trim(),n=hh(t);if(n)return n.toLowerCase();let r=/^#([0-9a-f]{6})([0-9a-f]{2})?$/i.exec(t);if(r?.[1])return`#${r[1].toLowerCase()}`;let i=/^#([0-9a-f]{3})$/i.exec(t);return i?.[1]?`#${i[1].split(``).map(e=>e+e).join(``).toLowerCase()}`:null}var _h=[`web`,`react-native`,`flutter`,`swiftui`,`compose`],vh=[`primary`,`accent`,`bg`,`surface`,`fg`,`border`];function yh(e,t,n){let r={...e};for(let[e,i]of Object.entries(t))e.startsWith(`light.`)?n===`light`&&(r[e.slice(6)]=i):e.startsWith(`dark.`)?n===`dark`&&(r[e.slice(5)]=i):r[e]=i;return r}function bh({t:e,label:t}){let n=e.bg??`#fff`,r=e.surface??n,i=e.fg??`#111`,a=e.muted??i,o=e.primary??`#3b82f6`,s=e.accent??o,c=e.border??a,l=e.radius??`0.5rem`,u=e.fontSans??`system-ui, sans-serif`,d=e.fontDisplay??u,f=e.shadow&&e.shadow!==`none`?e.shadow:void 0;return(0,J.jsxs)(`div`,{style:{background:n,color:i,fontFamily:u},className:`p-3 flex flex-col gap-2 overflow-hidden`,children:[(0,J.jsx)(`div`,{className:`text-[9px] uppercase tracking-wide`,style:{color:a},children:t}),(0,J.jsxs)(`div`,{style:{background:r,border:`1px solid ${c}`,borderRadius:l,boxShadow:f},className:`p-3 flex flex-col gap-2`,children:[(0,J.jsx)(`div`,{style:{fontFamily:d},className:`text-base font-bold leading-tight`,children:`Aa Heading`}),(0,J.jsx)(`div`,{className:`text-[11px] leading-snug`,style:{color:a},children:`The quick brown fox jumps over the lazy dog.`}),(0,J.jsxs)(`div`,{className:`flex items-center gap-1.5 mt-1`,children:[(0,J.jsx)(`span`,{style:{background:o,color:n,borderRadius:l},className:`text-[10px] font-semibold px-2.5 py-1`,children:`Primary`}),(0,J.jsx)(`span`,{style:{border:`1px solid ${c}`,color:i,borderRadius:l},className:`text-[10px] px-2 py-1`,children:`Ghost`}),(0,J.jsx)(`span`,{style:{background:s,color:n,borderRadius:`999px`},className:`text-[9px] font-semibold px-2 py-0.5 ml-auto`,children:`Badge`})]}),(0,J.jsx)(`div`,{style:{border:`1px solid ${c}`,borderRadius:l,color:a},className:`text-[10px] px-2 py-1.5 mt-1`,children:`Input field…`})]})]})}function xh({kit:e,overrides:t,onSet:n}){let[r,i]=(0,H.useState)(`light`),a=yh(r===`light`?e.light:e.dark,t,r);return(0,J.jsxs)(`div`,{className:`mt-1 rounded-lg border border-border/60 p-2 bg-muted/30`,children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-2 mb-1.5`,children:[(0,J.jsx)(`span`,{className:`text-[10px] font-semibold uppercase text-muted-foreground`,children:`Colors`}),(0,J.jsx)(`div`,{className:`ml-auto inline-flex rounded border border-border/60 overflow-hidden`,children:[`light`,`dark`].map(e=>(0,J.jsx)(`button`,{type:`button`,onClick:()=>i(e),className:X(`text-[10px] px-1.5 py-0.5`,r===e?`bg-primary text-primary-foreground`:`text-muted-foreground`),children:e},e))})]}),(0,J.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:vh.filter(e=>a[e]).map(e=>{let t=gh(a[e]??``)??`#000000`;return(0,J.jsxs)(`label`,{className:`flex flex-col items-center gap-0.5`,title:`${e}: ${a[e]}`,children:[(0,J.jsx)(`input`,{type:`color`,value:t,onChange:t=>n(`${r}.${e}`,t.target.value),className:`w-6 h-6 rounded cursor-pointer bg-transparent border border-border/60 p-0`}),(0,J.jsx)(`span`,{className:`text-[8px] text-muted-foreground`,children:e})]},e)})})]})}function Sh({className:e}){let{client:t}=Q(),n=q(e=>e.setCurrentView),[r,a]=(0,H.useState)([]),[o,s]=(0,H.useState)(null),[c,l]=(0,H.useState)({}),[u,d]=(0,H.useState)(`web`),[f,p]=(0,H.useState)(``),[m,h]=(0,H.useState)(null);(0,H.useEffect)(()=>{if(!t)return;let e=e=>{let t=e.payload;a(t?.kits??[]),s(t?.activeKit??null),l(t?.overrides??{})},n=e=>{let t=e.payload;t?.ok&&t.kit&&(s(t.kit),l(t.overrides??{}))},r=e=>{let t=e.payload;t?.ok&&t.overrides&&l(t.overrides)},i=e=>{let t=e.payload;h(t?.ok?`Wrote ${t.path}`:`Materialize failed: ${t?.error??`error`}`)},o=e=>{let t=e.payload;if(!t?.ok){h(`Verify: ${t?.error??`error`}`);return}let n=Math.round((t.score??1)*100);h(t.violationCount?`Verify: ${n}% on-palette — ${t.violationCount} off-palette in ${t.filesScanned} file(s)`:`Verify: clean ✓ (${t.filesScanned} file(s) on-palette)`)};return t.on(`design.list`,e),t.on(`design.use`,n),t.on(`design.set`,r),t.on(`design.materialize`,i),t.on(`design.verify`,o),t.send({type:`design.list`}),()=>{t.off(`design.list`,e),t.off(`design.use`,n),t.off(`design.set`,r),t.off(`design.materialize`,i),t.off(`design.verify`,o)}},[t]);let g=(0,H.useCallback)(e=>t?.send({type:`design.use`,payload:{kit:e,stack:u}}),[t,u]),_=(0,H.useCallback)((e,n)=>{l(t=>({...t,[e]:n})),t?.send({type:`design.set`,payload:{overrides:{[e]:n}}})},[t]),v=(0,H.useCallback)(()=>{h(`Writing theme file…`),t?.send({type:`design.materialize`,payload:{stack:u}})},[t,u]),y=(0,H.useCallback)(()=>{h(`Scanning UI files…`),t?.send({type:`design.verify`})},[t]),x=(0,H.useMemo)(()=>{let e=f.trim().toLowerCase();return[...e?r.filter(t=>t.id.includes(e)||t.name.toLowerCase().includes(e)||t.aesthetic.toLowerCase().includes(e)||t.tags.some(t=>t.includes(e))):r].sort((e,t)=>e.name.localeCompare(t.name))},[r,f]);return(0,J.jsxs)(`div`,{className:X(`flex flex-col h-full`,e),children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-2 px-4 py-3 border-b border-border/60`,children:[(0,J.jsx)(vt,{className:`w-5 h-5 text-muted-foreground`}),(0,J.jsx)(`h2`,{className:`text-sm font-semibold`,children:`Design Studio — Gallery`}),(0,J.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[x.length,` kits`]}),(0,J.jsx)(`input`,{value:f,onChange:e=>p(e.target.value),placeholder:`Search kits…`,className:`ml-2 text-xs bg-transparent border border-border/60 rounded px-2 py-1 w-44`}),(0,J.jsx)(`select`,{value:u,onChange:e=>d(e.target.value),className:`text-xs bg-transparent border border-border/60 rounded px-1.5 py-1`,title:`Stack for Use + Materialize`,children:_h.map(e=>(0,J.jsx)(`option`,{value:e,children:e},e))}),m&&(0,J.jsx)(`span`,{className:`text-[11px] text-muted-foreground max-w-48 truncate`,children:m}),(0,J.jsx)(`button`,{type:`button`,onClick:()=>n(`chat`),className:`ml-auto p-1 rounded hover:bg-muted text-muted-foreground`,title:`Close`,children:(0,J.jsx)(B,{className:`w-4 h-4`})})]}),(0,J.jsx)(`div`,{className:`flex-1 overflow-y-auto p-4`,children:(0,J.jsx)(`div`,{className:`grid gap-4 [grid-template-columns:repeat(auto-fill,minmax(300px,1fr))]`,children:x.map(e=>{let t=o===e.id,n=t?c:{};return(0,J.jsxs)(`div`,{className:X(`rounded-xl border overflow-hidden flex flex-col`,t?`border-primary/60 ring-1 ring-primary/40`:`border-border/60`),children:[(0,J.jsxs)(`div`,{className:`grid grid-cols-2`,children:[(0,J.jsx)(bh,{t:yh(e.light,n,`light`),label:`Light`}),(0,J.jsx)(bh,{t:yh(e.dark,n,`dark`),label:`Dark`})]}),(0,J.jsxs)(`div`,{className:`p-3 border-t border-border/60 flex flex-col gap-1.5 bg-card`,children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,J.jsx)(`h3`,{className:`text-sm font-semibold truncate`,children:e.name}),(0,J.jsx)(`code`,{className:`text-[10px] text-muted-foreground`,children:e.id}),t&&(0,J.jsxs)(`span`,{className:`inline-flex items-center gap-0.5 text-[9px] font-semibold uppercase text-primary ml-auto`,children:[(0,J.jsx)(i,{className:`w-3 h-3`}),` Active`]})]}),(0,J.jsx)(`p`,{className:`text-[11px] text-muted-foreground leading-snug`,children:e.aesthetic}),(0,J.jsxs)(`div`,{className:`flex items-center gap-2 mt-1`,children:[(0,J.jsx)(`button`,{type:`button`,onClick:()=>g(e.id),className:X(`text-[11px] px-2.5 py-1 rounded font-medium`,t?`bg-primary/10 text-primary`:`bg-primary text-primary-foreground hover:opacity-90`),children:t?`Reapply`:`Use`}),t&&(0,J.jsxs)(`button`,{type:`button`,onClick:v,className:`inline-flex items-center gap-1 text-[11px] px-2 py-1 rounded font-medium border border-border/60 hover:bg-muted`,title:`Write tokens to a ${u} theme file`,children:[(0,J.jsx)(b,{className:`w-3 h-3`}),` Materialize`]}),t&&(0,J.jsxs)(`button`,{type:`button`,onClick:y,className:`inline-flex items-center gap-1 text-[11px] px-2 py-1 rounded font-medium border border-border/60 hover:bg-muted`,title:`Scan UI files for off-palette colors`,children:[(0,J.jsx)(rt,{className:`w-3 h-3`}),` Verify`]}),(0,J.jsx)(`span`,{className:`text-[10px] text-muted-foreground truncate`,children:e.bestFor})]}),t&&(0,J.jsx)(xh,{kit:e,overrides:n,onSet:_})]})]},e.id)})})})]})}function Ch(e){if(e<1e3)return`${e}ms`;let t=Math.round(e/100);return t<600?`${(t/10).toFixed(1)}s`:`${Math.floor(t/600)}m ${Math.round(t%600/10)}s`}var wh={user:{Icon:At,label:`You`,avatarBg:`bg-primary`,avatarColor:`text-primary-foreground`,avatarRing:`ring-2 ring-offset-2 ring-offset-background ring-primary/20`,bubbleBg:`bg-primary`,bubbleBorder:`border-transparent`,textColor:`text-primary-foreground`},assistant:{Icon:Yn,label:`Assistant`,avatarBg:`bg-accent`,avatarColor:`text-accent-foreground`,avatarRing:`ring-2 ring-offset-2 ring-offset-background ring-accent/20`,bubbleBg:`bg-card`,bubbleBorder:`border-border`,textColor:`text-foreground`},tool:{Icon:l,label:`Tool`,avatarBg:`bg-secondary`,avatarColor:`text-secondary-foreground`,avatarRing:`ring-2 ring-offset-2 ring-offset-background ring-secondary/20`,bubbleBg:`bg-muted/80`,bubbleBorder:`border-border`,textColor:`text-foreground`},system:{Icon:Yn,label:`System`,avatarBg:`bg-muted`,avatarColor:`text-muted-foreground`,avatarRing:`ring-2 ring-offset-2 ring-offset-background ring-muted/20`,bubbleBg:`bg-muted/50`,bubbleBorder:`border-border`,textColor:`text-muted-foreground`},error:{Icon:ue,label:`Error`,avatarBg:`bg-destructive`,avatarColor:`text-destructive-foreground`,avatarRing:`ring-2 ring-offset-2 ring-offset-background ring-destructive/20`,bubbleBg:`bg-destructive/5`,bubbleBorder:`border-destructive/20`,textColor:`text-destructive`}};function Th({entry:e}){return e.role===`error`?(0,J.jsx)(ld,{text:e.text}):e.role===`tool`?(0,J.jsxs)(`div`,{className:`flex flex-col gap-1.5 tool-details`,children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-1.5 text-sm font-medium text-foreground`,children:[(0,J.jsx)(l,{className:`h-3 w-3`}),(0,J.jsx)(`span`,{className:`font-mono`,children:e.tool??`tool`}),e.durationMs!==void 0&&(0,J.jsxs)(`span`,{className:`ml-auto text-[10px] text-muted-foreground font-normal tabular-nums`,children:[(0,J.jsx)(Fr,{className:`h-3 w-3 inline mr-0.5 align-text-bottom`}),Ch(e.durationMs)]})]}),e.input!==void 0&&e.input!==null&&(0,J.jsx)(`div`,{className:`p-3 bg-muted/50 rounded-lg overflow-x-auto`,children:(0,J.jsx)(ud,{input:e.input})}),e.output!==void 0&&e.output!==null?(0,J.jsx)(`div`,{className:`text-sm leading-relaxed markdown-content`,children:typeof e.output==`string`?(0,J.jsx)(Re,{remarkPlugins:[Cr],rehypePlugins:id,components:od,children:e.output}):(0,J.jsx)(`pre`,{className:`whitespace-pre-wrap font-mono text-xs bg-card rounded-lg p-2 border border-border overflow-x-auto`,children:JSON.stringify(e.output,null,2)})}):e.text?(0,J.jsx)(`div`,{className:`text-sm leading-relaxed markdown-content`,children:(0,J.jsx)(Re,{remarkPlugins:[Cr],rehypePlugins:id,components:od,children:e.text})}):null,e.isError&&(0,J.jsxs)(`div`,{className:`rounded-lg border border-destructive/30 bg-destructive/5 px-3 py-2`,children:[(0,J.jsx)(`span`,{className:`text-xs font-medium text-destructive`,children:`Tool failed`}),e.text&&(0,J.jsx)(`pre`,{className:`mt-1 text-xs whitespace-pre-wrap text-destructive/80`,children:e.text})]})]}):(0,J.jsx)(`div`,{className:`text-sm leading-relaxed markdown-content`,children:(0,J.jsx)(Re,{remarkPlugins:[Cr],rehypePlugins:id,components:od,children:e.text})})}function Eh({entry:e,isContinuation:t=!1}){let n=wh[e.role],r=n.Icon;return(0,J.jsxs)(`div`,{className:`group flex gap-3 animate-message msg-bubble rounded-lg transition-shadow`,children:[t?(0,J.jsx)(`div`,{className:`flex-shrink-0 w-8`}):(0,J.jsx)(`div`,{className:X(`flex-shrink-0 w-8 h-8 rounded-full flex items-center justify-center`,n.avatarBg,n.avatarColor,n.avatarRing),children:(0,J.jsx)(r,{className:`h-4 w-4`})}),(0,J.jsxs)(`div`,{className:`flex flex-col gap-1.5 min-w-0 flex-1`,children:[!t&&(0,J.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,J.jsx)(`span`,{className:X(`text-xs font-medium`,n.textColor),children:e.role===`tool`&&e.tool?e.tool:n.label}),(0,J.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:new Date(e.ts).toLocaleTimeString([],{hour:`2-digit`,minute:`2-digit`})}),e.role===`tool`&&e.durationMs!==void 0&&(0,J.jsxs)(`span`,{className:`text-[10px] text-muted-foreground tabular-nums`,children:[`· `,Ch(e.durationMs)]})]}),(0,J.jsx)(`div`,{className:X(`rounded-2xl px-4 py-3 border`,e.role===`user`&&`rounded-br-md`,e.role===`assistant`&&`rounded-bl-md`,e.role===`tool`&&`rounded-bl-sm`,e.role===`system`&&`rounded-bl-sm opacity-70`,e.role===`error`&&`rounded-bl-sm`,n.bubbleBg,n.bubbleBorder),children:(0,J.jsx)(`div`,{className:X(`text-sm leading-relaxed markdown-content`,n.textColor),children:(0,J.jsx)(Th,{entry:e})})}),e.text&&e.role!==`error`&&(0,J.jsx)(`div`,{className:`opacity-0 group-hover:opacity-100 transition-opacity`,children:(0,J.jsx)(sd,{text:e.text,label:`Copy`})})]})]})}var Dh=[{value:`steer`,label:`🔄 Steer`,hint:`Adjust behavior mid-task`},{value:`ask`,label:`❓ Ask`,hint:`Question — expects a reply`},{value:`assign`,label:`📋 Assign`,hint:`A task to act on`},{value:`note`,label:`💬 Note`,hint:`FYI, non-urgent`}],Oh=2500;function kh({sessionId:e,limit:t=200}){let[n,r]=(0,H.useState)(null),[i,a]=(0,H.useState)(null),[o,s]=(0,H.useState)(``),[c,l]=(0,H.useState)(!1),[u,d]=(0,H.useState)(null),[f,p]=(0,H.useState)(`steer`),[m,h]=(0,H.useState)(`high`),[g,_]=(0,H.useState)([]),[v,y]=(0,H.useState)(!1),b=(0,H.useRef)(null),x=(0,H.useRef)(!0),S=(0,H.useRef)(!0),C=da(e=>e.liveSessions),w=(0,H.useMemo)(()=>C.find(t=>t.sessionId===e),[C,e]),T=(0,H.useMemo)(()=>{let e=w;return e?`${e.status}|${e.agents.map(e=>`${e.id}:${e.status}:${e.toolCalls??0}:${e.iterations??0}`).join(`,`)}`:``},[w]),E=w?.status===`active`||(w?.agents.some(e=>e.status===`running`||e.status===`streaming`)??!1),D=(0,H.useMemo)(()=>{if(!w)return null;let e=w.agents.find(e=>e.status===`running`||e.status===`streaming`);return e?.currentTool?`🔧 ${e.currentTool}`:e?`${e.name??e.id} · working`:null},[w]),O=(0,H.useMemo)(()=>{if(!w)return null;let e=w.agents.find(e=>e.partialText&&(e.status===`streaming`||e.status===`running`))??w.agents.find(e=>e.partialText);return e?.partialText?{label:e.id===`leader`?`Claude`:e.name||e.id,text:e.partialText}:null},[w]),k=(0,H.useCallback)(async()=>{try{let n=await fetch(`/api/sessions/${encodeURIComponent(e)}/events?limit=${t}`);if(!n.ok)throw Error(`HTTP ${n.status}`);let i=await n.json();S.current&&(r(i),a(null))}catch(e){S.current&&a(e instanceof Error?e.message:String(e))}},[e,t]),A=(0,H.useCallback)(async()=>{try{let t=await fetch(`/api/sessions/${encodeURIComponent(e)}/mailbox`);if(!t.ok)return;let n=await t.json();S.current&&Array.isArray(n.thread)&&_(n.thread)}catch{}},[e]);(0,H.useEffect)(()=>{S.current=!0,r(null),a(null),_([]),k(),A();let e=setInterval(()=>void k(),Oh),t=setInterval(()=>void A(),Oh);return()=>{S.current=!1,clearInterval(e),clearInterval(t)}},[k,A]),(0,H.useEffect)(()=>{T&&k()},[T,k]),(0,H.useEffect)(()=>{x.current&&b.current&&(b.current.scrollTop=b.current.scrollHeight)},[n,O]);let j=()=>{let e=b.current;e&&(x.current=e.scrollHeight-e.scrollTop-e.clientHeight<40)},M=async()=>{let t=o.trim();if(!(!t||c)){l(!0),d(null);try{let n=await fetch(`/api/sessions/${encodeURIComponent(e)}/message`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({text:t,type:f,priority:m})});if(!n.ok)throw Error(`HTTP ${n.status}`);s(``),d(E?`Delivered — the running agent sees it on its next step`:`Delivered — target is idle; appears in its mailbox, read when it next runs`),A()}catch(e){d(`Failed: ${e instanceof Error?e.message:String(e)}`)}finally{l(!1)}}},N=async()=>{if(!v){y(!0),d(null);try{let t=await fetch(`/api/sessions/${encodeURIComponent(e)}/interrupt`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({reason:`Operator requested stop from Fleet HQ`})});if(!t.ok)throw Error(`HTTP ${t.status}`);d(`Interrupt sent — agent stops at its next step (not a kill)`),A()}catch(e){d(`Interrupt failed: ${e instanceof Error?e.message:String(e)}`)}finally{y(!1)}}},P=n?.entries??[];return(0,J.jsxs)(`div`,{className:`flex flex-col h-full min-h-0`,children:[(0,J.jsxs)(`div`,{className:`flex items-center justify-between mb-1.5 shrink-0`,children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[10px] uppercase tracking-wide text-muted-foreground`,children:[(0,J.jsx)(`span`,{className:X(`h-1.5 w-1.5 rounded-full`,E?`bg-green-500 animate-pulse`:`bg-muted-foreground`)}),`Live stream`]}),(0,J.jsxs)(`div`,{className:`flex items-center gap-2`,children:[n&&(0,J.jsxs)(`div`,{className:`text-[10px] text-muted-foreground`,children:[n.total,` event`,n.total===1?``:`s`,` · `,n.status]}),E&&(0,J.jsx)(`button`,{type:`button`,onClick:()=>void N(),disabled:v,title:`Cooperatively stop this agent at its next step (not a process kill)`,className:`rounded border border-destructive/40 bg-destructive/15 px-1.5 py-0.5 text-[10px] text-destructive hover:bg-destructive/25 disabled:opacity-40 transition-colors`,children:v?`…`:`⏸ Interrupt`})]})]}),D&&(0,J.jsxs)(`div`,{className:`mb-1.5 shrink-0 text-[10px] text-foreground truncate`,children:[`▶ `,D]}),i&&(0,J.jsxs)(`div`,{className:`text-[11px] text-destructive mb-1 shrink-0`,children:[`· `,i]}),(0,J.jsxs)(`div`,{ref:b,onScroll:j,className:`flex-1 overflow-y-auto space-y-1.5 pr-1 min-h-0`,children:[P.length===0&&!i&&(0,J.jsx)(`div`,{className:`text-[11px] text-muted-foreground italic`,children:`Loading session…`}),P.map((e,t)=>(0,J.jsx)(Eh,{entry:e,isContinuation:t>0&&P[t-1].role===e.role},`${e.ts}-${t}`)),O&&(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)(Yn,{className:`h-4 w-4 animate-pulse`})}),(0,J.jsxs)(`div`,{className:`flex flex-col gap-1.5 max-w-[85%] min-w-0`,children:[(0,J.jsx)(`span`,{className:`text-xs font-medium text-muted-foreground px-1`,children:O.label}),(0,J.jsx)(`div`,{className:`rounded-2xl rounded-bl-md px-4 py-3 bg-card border border-border`,children:(0,J.jsxs)(`span`,{className:`text-sm leading-relaxed text-foreground whitespace-pre-wrap break-words`,children:[O.text,(0,J.jsx)(`span`,{className:`animate-pulse text-primary`,children:`▋`})]})})]})]})]}),g.length>0&&(0,J.jsxs)(`div`,{className:`mt-2 pt-2 border-t border-border shrink-0 max-h-28 overflow-y-auto space-y-1`,children:[(0,J.jsx)(`div`,{className:`text-[9px] uppercase tracking-wide text-muted-foreground`,children:`Messages`}),g.slice(-6).map(e=>{let t=e.completed?`✓✓ done`:e.readByLeader?`✓ read`:`⏳ delivered`;return(0,J.jsxs)(`div`,{className:`text-[10px] leading-snug`,children:[(0,J.jsx)(`span`,{className:X(`font-semibold mr-1.5`,e.fromLeader?`text-accent`:`text-primary`),children:e.fromLeader?`Agent`:`You`}),(0,J.jsx)(`span`,{className:`text-foreground whitespace-pre-wrap break-words`,children:e.body}),!e.fromLeader&&(0,J.jsx)(`span`,{className:X(`ml-1.5 text-[9px]`,e.completed?`text-green-500`:e.readByLeader?`text-cyan-500`:`text-muted-foreground`),children:t})]},e.id)})]}),(0,J.jsxs)(`div`,{className:`mt-2 pt-2 border-t border-border shrink-0`,children:[(0,J.jsxs)(`div`,{className:`mb-1 flex items-center gap-1.5`,children:[(0,J.jsx)(`select`,{value:f,onChange:e=>p(e.target.value),title:Dh.find(e=>e.value===f)?.hint,className:`rounded bg-muted border border-border px-1.5 py-0.5 text-[10px] text-foreground focus:outline-none focus:ring-1 focus:ring-ring`,children:Dh.map(e=>(0,J.jsx)(`option`,{value:e.value,children:e.label},e.value))}),(0,J.jsxs)(`select`,{value:m,onChange:e=>h(e.target.value),title:`Priority`,className:`rounded bg-muted border border-border px-1.5 py-0.5 text-[10px] text-foreground focus:outline-none focus:ring-1 focus:ring-ring`,children:[(0,J.jsx)(`option`,{value:`high`,children:`high`}),(0,J.jsx)(`option`,{value:`normal`,children:`normal`}),(0,J.jsx)(`option`,{value:`low`,children:`low`})]})]}),(0,J.jsxs)(`div`,{className:`flex items-end gap-1.5`,children:[(0,J.jsx)(`textarea`,{value:o,onChange:e=>s(e.target.value),onKeyDown:e=>{e.key===`Enter`&&(e.metaKey||e.ctrlKey)&&(e.preventDefault(),M())},rows:2,placeholder:`${Dh.find(e=>e.value===f)?.label??`Send`} → this session…`,className:`flex-1 resize-none rounded-md bg-muted border border-border px-2 py-1 text-sm text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-ring`}),(0,J.jsx)(`button`,{type:`button`,onClick:()=>void M(),disabled:c||!o.trim(),className:`shrink-0 rounded-md bg-primary text-primary-foreground px-2.5 py-1.5 text-xs hover:bg-primary/90 disabled:opacity-40 disabled:cursor-not-allowed transition-colors`,children:c?`…`:`Send`})]}),u&&(0,J.jsx)(`div`,{className:`mt-1 text-[10px] text-muted-foreground`,children:u}),(0,J.jsx)(`div`,{className:`mt-0.5 text-[9px] text-muted-foreground`,children:`⌘/Ctrl+Enter to send · seen on the agent's next iteration`})]})]})}function Ah(e){return e==null||!Number.isFinite(e)?`0`:e<1e3?String(Math.round(e)):e<1e6?`${(e/1e3).toFixed(1)}k`:`${(e/1e6).toFixed(1)}M`}function jh(e,t){if(!e)return`never`;let n=Date.parse(e);if(!Number.isFinite(n))return`never`;let r=Math.max(0,Math.round((t-n)/1e3));return r<60?`${r}s ago`:r<3600?`${Math.round(r/60)}m ago`:r<86400?`${Math.round(r/3600)}h ago`:`${Math.round(r/86400)}d ago`}function Mh(e,t){if(!e)return``;let n=Date.parse(e);if(!Number.isFinite(n))return``;let r=Math.max(0,Math.round((t-n)/1e3));return r<60?`${r}s`:r<3600?`${Math.round(r/60)}m`:`${Math.round(r/3600)}h`}function Nh(e){if(!e)return;let t=e.split(`/`);return t[t.length-1]?.slice(0,18)}function Ph(e,t=380){let n=new Map,r=Math.max(1,e.length);return e.forEach((e,i)=>{let a=(i-(r-1)/2)*t;n.set(e,600+a)}),n}function Fh(e,t,n){let r=Math.min(3,n),i=Math.floor(t/r),a=t%r;return{x:e-(Math.min(r,n-i*r)-1)*190/2+a*190,y:640+i*150}}function Ih(e){return e===`tui`?`tui`:e===`repl`||e===`cli`?`repl`:`webui`}function Lh(e){return e===`tui`?`TUI`:e===`repl`?`REPL`:`WebUI`}function Rh(e){switch(e){case`running`:case`active`:return`active`;case`idle`:return`idle`;case`completed`:return`completed`;case`failed`:case`error`:return`error`;case`stopped`:return`offline`;default:return`idle`}}function zh(e,t){let n=new Set,r=[];for(let i of e){let e=Ih(i.clientType),a=`client-${i.pid??i.sessionId}`,o=[],s=!1;for(let e of i.agents){n.add(e.id);let r=t.get(e.id),i=Rh(r?.status??e.status);(i===`active`||i===`streaming`)&&(s=!0),o.push({officeId:`${a}__agent-${e.id}`,serverId:e.id,name:r?.name??e.name??e.id,status:i,iteration:r?.iteration??e.iterations??0,toolCalls:r?.toolCalls??e.toolCalls??0,costUsd:r?.costUsd??e.costUsd??0,tokensIn:r?.tokensIn??e.tokensIn??0,tokensOut:r?.tokensOut??e.tokensOut??0,ctxPct:r?.ctxPct??e.ctxPct,model:r?.model??e.model,lastActivityAt:e.lastActivityAt,currentTask:r?.currentTool??r?.lastTool??e.currentTool})}let c=i.status===`closing`||i.status===`stale`?`offline`:s?`active`:`idle`;r.push({id:a,type:e,label:i.projectName||Lh(e),sublabel:[Lh(e),i.gitBranch?`⎇ ${i.gitBranch}`:``,i.pid?`pid ${i.pid}`:``].filter(Boolean).join(` · `),status:c,sessionId:i.sessionId,pid:i.pid,branch:i.gitBranch,workingDir:i.workingDir,startedAt:i.startedAt,agents:o})}let i=[...t.values()].filter(e=>!n.has(e.id));if(i.length>0){let e=r.find(e=>e.type===`webui`);e||(e={id:`client-self`,type:`webui`,label:`This WebUI`,sublabel:`Web UI`,status:`idle`,agents:[]},r.push(e));for(let t of i){let n=Rh(t.status);(n===`active`||n===`streaming`)&&(e.status=`active`),e.agents.push({officeId:`${e.id}__agent-${t.id}`,serverId:t.id,name:t.name,status:n,iteration:t.iteration??0,toolCalls:t.toolCalls??0,costUsd:t.costUsd??0,tokensIn:t.tokensIn??0,tokensOut:t.tokensOut??0,ctxPct:t.ctxPct,model:t.model,currentTask:t.currentTool??t.lastTool})}}return r.length===0&&r.push({id:`client-self`,type:`webui`,label:`This WebUI`,sublabel:`Web UI · connecting…`,status:`idle`,agents:[]}),r}function Bh(e){return e.startsWith(`tool`)?`#eab308`:e.startsWith(`mailbox`)?`#06b6d4`:e.startsWith(`provider`)?`#a855f7`:e.startsWith(`agent`)||e.startsWith(`subagent`)?`#22c55e`:e.includes(`error`)?`#ef4444`:`#6366f1`}function Vh(e){return Math.min(100,Math.max(0,e??0))}function Hh({status:e,small:t,activity:n=0}){let r=t?`w-2 h-2`:`w-3 h-3`,i=t?4+n*4:6+n*6;return(0,J.jsx)(`span`,{className:X(`rounded-full`,r,n>0&&`animate-pulse`,{idle:`bg-gray-500`,active:`bg-emerald-500`,streaming:`bg-blue-500`,completed:`bg-blue-500`,error:`bg-red-500`,offline:`bg-gray-600`}[e]),style:{boxShadow:n>0?`0 0 ${i}px ${{idle:`#9ca3af`,active:`#22c55e`,streaming:`#3b82f6`,completed:`#3b82f6`,error:`#ef4444`,offline:`#6b7280`}[e]}`:void 0}})}function Uh(){let{clientCounts:e,currentSession:t,totalAgents:n,activeAgents:r,aggregate:i}=da(),a=e.tui+e.webui+e.repl,o=e=>e?.toLocaleString()??`0`;return(0,J.jsxs)(`div`,{className:`absolute top-20 left-4 z-10 bg-slate-800/95 backdrop-blur border border-slate-700 rounded-lg p-3 shadow-xl`,children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-2 mb-2`,children:[(0,J.jsx)(_t,{className:`h-3.5 w-3.5 text-emerald-400`}),(0,J.jsx)(`span`,{className:`text-[10px] font-bold text-gray-300 uppercase tracking-wide`,children:`Session Stats`})]}),(0,J.jsxs)(`div`,{className:`space-y-1.5 text-[10px]`,children:[(0,J.jsxs)(`div`,{className:`flex items-center justify-between gap-4`,children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,J.jsx)(Mr,{className:`h-3 w-3 text-gray-500`}),(0,J.jsx)(`span`,{className:`text-gray-400`,children:`Clients`})]}),(0,J.jsxs)(`span`,{className:`text-gray-200 font-mono`,children:[r,` `,(0,J.jsx)(`span`,{className:`text-gray-500`,children:`/`}),` `,(0,J.jsx)(`span`,{className:`text-emerald-400`,children:a})]})]}),(0,J.jsxs)(`div`,{className:`flex items-center gap-3 pl-4 text-[9px]`,children:[e.tui>0&&(0,J.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,J.jsx)(l,{className:`h-2.5 w-2.5 text-emerald-500`}),(0,J.jsx)(`span`,{className:`text-gray-400`,children:`TUI`}),(0,J.jsx)(`span`,{className:`text-emerald-400 font-mono`,children:e.tui})]}),e.webui>0&&(0,J.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,J.jsx)(ze,{className:`h-2.5 w-2.5 text-blue-500`}),(0,J.jsx)(`span`,{className:`text-gray-400`,children:`WebUI`}),(0,J.jsx)(`span`,{className:`text-blue-400 font-mono`,children:e.webui})]}),e.repl>0&&(0,J.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,J.jsx)(l,{className:`h-2.5 w-2.5 text-amber-500`}),(0,J.jsx)(`span`,{className:`text-gray-400`,children:`REPL`}),(0,J.jsx)(`span`,{className:`text-amber-400 font-mono`,children:e.repl})]})]}),(0,J.jsxs)(`div`,{className:`flex items-center justify-between gap-4`,children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,J.jsx)(Yn,{className:`h-3 w-3 text-gray-500`}),(0,J.jsx)(`span`,{className:`text-gray-400`,children:`Agents`})]}),(0,J.jsxs)(`span`,{className:`text-gray-200 font-mono`,children:[r,` `,(0,J.jsx)(`span`,{className:`text-gray-500`,children:`/`}),` `,(0,J.jsx)(`span`,{className:`text-cyan-400`,children:n})]})]}),t.model&&(0,J.jsxs)(`div`,{className:`flex items-center justify-between gap-4`,children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,J.jsx)(_e,{className:`h-3 w-3 text-gray-500`}),(0,J.jsx)(`span`,{className:`text-gray-400`,children:`Model`})]}),(0,J.jsx)(`span`,{className:`text-cyan-400 font-mono truncate max-w-[120px]`,title:t.model,children:t.model.split(`/`).pop()?.slice(0,16)})]}),t.mode&&(0,J.jsxs)(`div`,{className:`flex items-center justify-between gap-4`,children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,J.jsx)(Bt,{className:`h-3 w-3 text-gray-500`}),(0,J.jsx)(`span`,{className:`text-gray-400`,children:`Mode`})]}),(0,J.jsx)(`span`,{className:X(`font-mono uppercase text-[9px] px-1.5 py-0.5 rounded`,t.mode===`auto`&&`bg-purple-500/20 text-purple-400`,t.mode===`suggest`&&`bg-blue-500/20 text-blue-400`,t.mode===`off`&&`bg-gray-500/20 text-gray-400`,![`auto`,`suggest`,`off`].includes(t.mode||``)&&`bg-gray-500/20 text-gray-400`),children:t.mode})]}),(0,J.jsxs)(`div`,{className:`flex items-center justify-between gap-4`,children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,J.jsx)(ae,{className:`h-3 w-3 text-gray-500`}),(0,J.jsx)(`span`,{className:`text-gray-400`,children:`Tool Calls`})]}),(0,J.jsx)(`span`,{className:`text-yellow-400 font-mono`,children:o(i.toolCalls)})]}),(0,J.jsxs)(`div`,{className:`border-t border-slate-700 pt-1.5 mt-1.5 space-y-1`,children:[(0,J.jsxs)(`div`,{className:`flex items-center justify-between gap-4`,children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,J.jsx)(`span`,{className:`text-gray-500 text-[8px]`,children:`IN`}),(0,J.jsx)(`span`,{className:`text-gray-400`,children:`Input`})]}),(0,J.jsx)(`span`,{className:`text-gray-300 font-mono text-[9px]`,children:o(i.tokensIn)})]}),(0,J.jsxs)(`div`,{className:`flex items-center justify-between gap-4`,children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,J.jsx)(`span`,{className:`text-gray-500 text-[8px]`,children:`OUT`}),(0,J.jsx)(`span`,{className:`text-gray-400`,children:`Output`})]}),(0,J.jsx)(`span`,{className:`text-gray-300 font-mono text-[9px]`,children:o(i.tokensOut)})]})]}),(0,J.jsxs)(`div`,{className:`flex items-center justify-between gap-4 border-t border-slate-700 pt-1.5 mt-1.5`,children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,J.jsx)(we,{className:`h-3 w-3 text-gray-500`}),(0,J.jsx)(`span`,{className:`text-gray-400`,children:`Cost`})]}),(0,J.jsx)(`span`,{className:`text-emerald-400 font-mono font-medium`,children:(e=>e==null?`$0.0000`:`$${e.toFixed(4)}`)(i.costUsd)})]})]})]})}function Wh(){let e={opacity:0,width:1,height:1,minWidth:0,border:`none`,background:`transparent`};return(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(Se,{type:`target`,position:R.Top,style:e,isConnectable:!1}),(0,J.jsx)(Se,{type:`source`,position:R.Bottom,style:e,isConnectable:!1})]})}function Gh({data:e}){return(0,J.jsxs)(`div`,{className:`mt-2 flex items-center justify-between border-t border-white/5 pt-1.5 text-[8px] text-gray-500`,children:[(0,J.jsxs)(`span`,{children:[(0,J.jsx)(`span`,{className:`font-mono text-gray-300`,children:e.agentCount??0}),` agents`]}),e.startedAt&&(0,J.jsxs)(`span`,{children:[`up `,Mh(e.startedAt,Date.now())]})]})}function Kh({data:e}){let t=e.status===`active`||e.status===`streaming`,n=e.status===`error`,r=e.status===`offline`,i=e.color||`#3b82f6`;return(0,J.jsxs)(`div`,{className:X(`rounded-xl border-2 p-4 min-w-[180px] transition-all backdrop-blur-sm`,t&&`shadow-lg shadow-blue-500/20`,n&&`border-red-500/50 bg-red-500/10`,r&&`border-gray-500/30 bg-gray-500/5 opacity-60`,!t&&!n&&!r&&`border-blue-500/30 bg-blue-500/10`),children:[(0,J.jsx)(Wh,{}),(0,J.jsxs)(`div`,{className:`flex items-center gap-3 mb-3`,children:[(0,J.jsx)(`div`,{className:X(`flex items-center justify-center w-10 h-10 rounded-lg`,t?`bg-blue-500/20`:`bg-blue-500/10`),children:(0,J.jsx)(ze,{className:`h-5 w-5`,style:{color:i}})}),(0,J.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,J.jsx)(`div`,{className:`text-xs font-bold truncate`,style:{color:i},children:e.label}),(0,J.jsx)(`div`,{className:`text-[10px] text-gray-500`,children:`WebUI Client`})]}),(0,J.jsx)(Hh,{status:e.status,activity:e.vizActivity??0})]}),e.sublabel&&(0,J.jsx)(`div`,{className:`text-[10px] text-gray-400 mb-2 truncate`,children:e.sublabel}),(0,J.jsx)(`div`,{className:`flex items-center gap-2 text-[10px] text-gray-500`,children:r?(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(an,{className:`h-3 w-3 text-gray-500`}),(0,J.jsx)(`span`,{children:`Disconnected`})]}):(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(On,{className:`h-3 w-3 text-emerald-500`}),(0,J.jsx)(`span`,{children:`Connected`})]})}),t&&(0,J.jsx)(`div`,{className:`mt-2 h-1 rounded-full bg-blue-500/30 overflow-hidden`,children:(0,J.jsx)(`div`,{className:`h-full bg-blue-500 animate-pulse`,style:{width:`60%`}})}),(0,J.jsx)(Gh,{data:e})]})}function qh({data:e}){let t=e.status===`active`||e.status===`streaming`,n=e.status===`error`,r=e.color||`#22c55e`;return(0,J.jsxs)(`div`,{className:X(`rounded-xl border-2 p-4 min-w-[180px] transition-all backdrop-blur-sm`,t&&`shadow-lg shadow-emerald-500/20`,n&&`border-red-500/50 bg-red-500/10`,!t&&!n&&`border-emerald-500/30 bg-emerald-500/10`),children:[(0,J.jsx)(Wh,{}),(0,J.jsxs)(`div`,{className:`flex items-center gap-3 mb-3`,children:[(0,J.jsx)(`div`,{className:X(`flex items-center justify-center w-10 h-10 rounded-lg`,t?`bg-emerald-500/20`:`bg-emerald-500/10`),children:(0,J.jsx)(l,{className:`h-5 w-5`,style:{color:r}})}),(0,J.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,J.jsx)(`div`,{className:`text-xs font-bold truncate`,style:{color:r},children:e.label}),(0,J.jsx)(`div`,{className:`text-[10px] text-gray-500`,children:`TUI Client`})]}),(0,J.jsx)(Hh,{status:e.status,activity:e.vizActivity??0})]}),e.sublabel&&(0,J.jsx)(`div`,{className:`text-[10px] text-gray-400 mb-2 truncate`,children:e.sublabel}),(0,J.jsxs)(`div`,{className:`flex items-center gap-2 text-[10px] text-gray-500`,children:[(0,J.jsx)(l,{className:`h-3 w-3 text-emerald-500`}),(0,J.jsx)(`span`,{children:`Terminal`})]}),(0,J.jsx)(Gh,{data:e})]})}function Jh({data:e}){let t=e.status===`active`||e.status===`streaming`,n=e.color||`#f59e0b`;return(0,J.jsxs)(`div`,{className:X(`rounded-xl border-2 p-4 min-w-[160px] transition-all backdrop-blur-sm`,t&&`shadow-lg shadow-amber-500/20`,!t&&`border-amber-500/30 bg-amber-500/10`),children:[(0,J.jsx)(Wh,{}),(0,J.jsxs)(`div`,{className:`flex items-center gap-3 mb-3`,children:[(0,J.jsx)(`div`,{className:X(`flex items-center justify-center w-10 h-10 rounded-lg`,t?`bg-amber-500/20`:`bg-amber-500/10`),children:(0,J.jsx)(l,{className:`h-5 w-5`,style:{color:n}})}),(0,J.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,J.jsx)(`div`,{className:`text-xs font-bold truncate`,style:{color:n},children:e.label}),(0,J.jsx)(`div`,{className:`text-[10px] text-gray-500`,children:`REPL`})]}),(0,J.jsx)(Hh,{status:e.status,activity:e.vizActivity??0})]}),e.sublabel&&(0,J.jsx)(`div`,{className:`text-[10px] text-gray-400 mb-1 truncate`,children:e.sublabel}),(0,J.jsx)(Gh,{data:e})]})}function Yh({data:e}){let t=e.status===`active`||e.status===`streaming`,n=e.color||`#a855f7`;return(0,J.jsxs)(`div`,{className:`rounded-xl border-2 p-4 min-w-[200px] transition-all backdrop-blur-sm relative bg-slate-900/90`,children:[(0,J.jsx)(Wh,{}),(0,J.jsx)(`div`,{className:`absolute -top-3 left-1/2 -translate-x-1/2 px-2 py-0.5 bg-purple-600 text-white text-[9px] rounded-full font-bold`,children:`COORDINATOR`}),(0,J.jsxs)(`div`,{className:`flex items-center gap-3 mb-3 mt-2`,children:[(0,J.jsx)(`div`,{className:X(`flex items-center justify-center w-12 h-12 rounded-xl`,t?`bg-purple-500/20`:`bg-purple-500/10`),children:(0,J.jsx)(_e,{className:`h-6 w-6`,style:{color:n}})}),(0,J.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,J.jsx)(`div`,{className:`text-sm font-bold truncate`,style:{color:n},children:e.label}),(0,J.jsx)(`div`,{className:`text-[10px] text-gray-500`,children:e.sublabel||`Fleet summary`})]}),(0,J.jsx)(Hh,{status:e.status,activity:e.vizActivity??0})]}),(0,J.jsxs)(`div`,{className:`grid grid-cols-2 gap-2 text-[10px] mb-2`,children:[(0,J.jsxs)(`div`,{className:`bg-black/20 rounded p-1.5 text-center`,children:[(0,J.jsxs)(`div`,{className:`font-mono`,children:[(0,J.jsx)(`span`,{className:`text-emerald-400`,children:e.agentsActive||0}),(0,J.jsx)(`span`,{className:`text-gray-500`,children:` / `}),(0,J.jsx)(`span`,{className:`text-purple-400`,children:e.agentsTotal||0})]}),(0,J.jsx)(`div`,{className:`text-gray-500`,children:`Agents`})]}),(0,J.jsxs)(`div`,{className:`bg-black/20 rounded p-1.5 text-center`,children:[(0,J.jsx)(`div`,{className:`font-mono text-yellow-400`,children:(e.toolCalls||0).toLocaleString()}),(0,J.jsx)(`div`,{className:`text-gray-500`,children:`Tool calls`})]}),(0,J.jsxs)(`div`,{className:`bg-black/20 rounded p-1.5 text-center`,children:[(0,J.jsx)(`div`,{className:`font-mono text-gray-300`,children:Ah(e.tokensIn)}),(0,J.jsx)(`div`,{className:`text-gray-500`,children:`Tokens`})]}),(0,J.jsxs)(`div`,{className:`bg-black/20 rounded p-1.5 text-center`,children:[(0,J.jsxs)(`div`,{className:`font-mono text-emerald-400`,children:[`$`,(e.costUsd||0).toFixed(3)]}),(0,J.jsx)(`div`,{className:`text-gray-500`,children:`Cost`})]})]}),t&&(0,J.jsxs)(`div`,{className:`flex items-center gap-2 text-[10px] text-purple-400`,children:[(0,J.jsx)(`span`,{className:`w-2 h-2 rounded-full bg-purple-400 animate-pulse`}),`Coordinating fleet`]})]})}function Xh({data:e}){let t=e.status===`active`||e.status===`streaming`,n=e.status===`error`,r=e.status===`completed`,i=e.color||`#06b6d4`,a=Vh(e.ctxPct);return(0,J.jsxs)(`div`,{className:X(`rounded-lg border p-3 min-w-[150px] transition-all backdrop-blur-sm`,t&&`border-cyan-500/50 bg-cyan-500/10 shadow-lg shadow-cyan-500/10`,n&&`border-red-500/50 bg-red-500/10`,r&&`border-gray-500/30 bg-gray-500/5`,!t&&!n&&!r&&`border-cyan-500/30 bg-cyan-500/10`),children:[(0,J.jsx)(Wh,{}),(0,J.jsxs)(`div`,{className:`flex items-center gap-2 mb-1.5`,children:[(0,J.jsx)(Yn,{className:`h-4 w-4 shrink-0`,style:{color:i}}),(0,J.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,J.jsx)(`div`,{className:`text-[11px] font-bold truncate`,style:{color:i},children:e.label}),e.model&&(0,J.jsx)(`div`,{className:`text-[8px] text-gray-500 truncate`,children:Nh(e.model)})]}),(0,J.jsx)(Hh,{status:e.status,small:!0,activity:e.vizActivity??0})]}),e.currentTask&&(0,J.jsxs)(`div`,{className:`flex items-center gap-1 text-[9px] text-cyan-300/90 truncate mb-1.5`,children:[(0,J.jsx)(`span`,{className:X(`w-1.5 h-1.5 rounded-full bg-cyan-400 shrink-0`,t&&`animate-pulse`)}),(0,J.jsx)(`span`,{className:`truncate font-mono`,children:e.currentTask})]}),(0,J.jsxs)(`div`,{className:`grid grid-cols-2 gap-x-2 gap-y-0.5 text-[9px] mb-1.5`,children:[(0,J.jsxs)(`div`,{className:`flex justify-between`,children:[(0,J.jsx)(`span`,{className:`text-gray-500`,children:`iter`}),(0,J.jsx)(`span`,{className:`text-gray-300 font-mono`,children:e.iteration||0})]}),(0,J.jsxs)(`div`,{className:`flex justify-between`,children:[(0,J.jsx)(`span`,{className:`text-gray-500`,children:`tools`}),(0,J.jsx)(`span`,{className:`text-yellow-400/90 font-mono`,children:e.toolCalls||0})]}),(0,J.jsxs)(`div`,{className:`flex justify-between`,children:[(0,J.jsx)(`span`,{className:`text-gray-500`,children:`tok`}),(0,J.jsx)(`span`,{className:`text-gray-300 font-mono`,children:Ah((e.tokensIn||0)+(e.tokensOut||0))})]}),(0,J.jsxs)(`div`,{className:`flex justify-between`,children:[(0,J.jsx)(`span`,{className:`text-gray-500`,children:`cost`}),(0,J.jsxs)(`span`,{className:`text-emerald-400/90 font-mono`,children:[`$`,(e.costUsd||0).toFixed(3)]})]})]}),a>0&&(0,J.jsxs)(`div`,{className:`mb-1`,children:[(0,J.jsxs)(`div`,{className:`flex justify-between text-[8px] text-gray-500 mb-0.5`,children:[(0,J.jsx)(`span`,{children:`ctx`}),(0,J.jsxs)(`span`,{className:X(`font-mono`,a>=90?`text-red-400`:a>=70?`text-amber-400`:`text-gray-400`),children:[a,`%`]})]}),(0,J.jsx)(`div`,{className:`h-1 rounded-full bg-slate-700/60 overflow-hidden`,children:(0,J.jsx)(`div`,{className:X(`h-full`,a>=90?`bg-red-500`:a>=70?`bg-amber-500`:`bg-cyan-500`),style:{width:`${a}%`}})})]}),e.lastActivityAt&&(0,J.jsxs)(`div`,{className:X(`flex items-center gap-1 text-[8px]`,t?`text-gray-600`:`text-gray-500`),children:[r&&(0,J.jsx)(`span`,{className:`text-emerald-500/70`,children:`✓ done ·`}),n&&(0,J.jsx)(`span`,{className:`text-red-400/80`,children:`✕ failed ·`}),(0,J.jsxs)(`span`,{children:[`seen `,jh(e.lastActivityAt,Date.now())]})]})]})}function Zh({data:e}){return(0,J.jsxs)(`div`,{className:X(`rounded-lg border border-dashed p-3 min-w-[120px] transition-all opacity-40`,`border-gray-600 bg-gray-800/30`),children:[(0,J.jsx)(Wh,{}),(0,J.jsxs)(`div`,{className:`flex items-center gap-2 mb-2`,children:[(0,J.jsx)(tn,{className:`h-4 w-4 text-gray-600`}),(0,J.jsx)(`div`,{className:`flex-1 min-w-0`,children:(0,J.jsx)(`div`,{className:`text-[10px] text-gray-500 truncate`,children:e.label})}),(0,J.jsx)(Hh,{status:e.status,small:!0,activity:e.vizActivity??0})]}),(0,J.jsx)(`div`,{className:`text-[9px] text-gray-600`,children:`Available desk`})]})}function Qh({data:e}){let t=e.color||`#eab308`,n=(e.unreadCount||0)>0;return(0,J.jsxs)(`div`,{className:X(`rounded-xl border-2 p-4 min-w-[160px] transition-all backdrop-blur-sm`,n&&`border-yellow-500/50 bg-yellow-500/10 shadow-lg shadow-yellow-500/10`,!n&&`border-yellow-500/30 bg-yellow-500/5`),children:[(0,J.jsx)(Wh,{}),(0,J.jsxs)(`div`,{className:`flex items-center gap-3 mb-3`,children:[(0,J.jsx)(`div`,{className:X(`flex items-center justify-center w-10 h-10 rounded-lg`,n?`bg-yellow-500/20`:`bg-yellow-500/10`),children:(0,J.jsx)(Ce,{className:`h-5 w-5`,style:{color:t}})}),(0,J.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,J.jsx)(`div`,{className:`text-xs font-bold`,style:{color:t},children:`Mailbox Hub`}),(0,J.jsx)(`div`,{className:`text-[10px] text-gray-500`,children:n?`${e.unreadCount} unread`:`All clear`})]}),n&&(0,J.jsx)(`div`,{className:`w-5 h-5 rounded-full bg-yellow-500 text-black text-[10px] font-bold flex items-center justify-center`,children:e.unreadCount})]}),(0,J.jsxs)(`div`,{className:`grid grid-cols-2 gap-2 text-[10px]`,children:[(0,J.jsxs)(`div`,{className:`bg-black/20 rounded p-1.5 text-center`,children:[(0,J.jsxs)(`div`,{className:`flex items-center justify-center gap-1 text-yellow-400`,children:[(0,J.jsx)(dt,{className:`h-3 w-3`}),(0,J.jsx)(`span`,{children:e.messageCount||0})]}),(0,J.jsx)(`div`,{className:`text-gray-500`,children:`Total`})]}),(0,J.jsxs)(`div`,{className:`bg-black/20 rounded p-1.5 text-center`,children:[(0,J.jsxs)(`div`,{className:`flex items-center justify-center gap-1 text-emerald-400`,children:[(0,J.jsx)(le,{className:`h-3 w-3`}),(0,J.jsx)(`span`,{children:e.unreadCount||0})]}),(0,J.jsx)(`div`,{className:`text-gray-500`,children:`Unread`})]})]}),e.sublabel&&(0,J.jsxs)(`div`,{className:`mt-2 truncate border-t border-white/5 pt-1.5 text-[9px] text-gray-400`,children:[`✉ `,e.sublabel]})]})}var $h={webui:Kh,tui:qh,repl:Jh,coordinator:Yh,agent:Xh,mailbox:Qh,desk:Zh},eg={wire:({sourceX:e,sourceY:t,targetX:n,targetY:r,sourcePosition:i,targetPosition:a,data:o,selected:s})=>{let c=o?.color||`#6366f1`,l=xa(e=>e.animateEdges),u=o?.animated&&l?Math.max(.15,o?.intensity??.6):0,[d,f,p]=Pe({sourceX:e,sourceY:t,sourcePosition:i??R.Bottom,targetX:n,targetY:r,targetPosition:a??R.Top,curvature:.28}),m=5+u*7,h=5+u*4,g=m+h,_=`${Math.max(.5,1.6-u).toFixed(2)}s`;return(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(`path`,{d,fill:`none`,stroke:c,strokeWidth:s?2.5:1.4,strokeOpacity:s?.9:.28,className:`react-flow__edge-path`}),u>.05&&(0,J.jsx)(`path`,{d,fill:`none`,stroke:c,strokeWidth:2.2,strokeOpacity:.45+u*.5,strokeDasharray:`${m} ${h}`,strokeLinecap:`round`,style:{filter:`drop-shadow(0 0 ${2+u*4}px ${c})`},children:(0,J.jsx)(`animate`,{attributeName:`stroke-dashoffset`,from:g,to:`0`,dur:_,repeatCount:`indefinite`})}),o?.label&&u>.1&&(0,J.jsx)(v,{children:(0,J.jsx)(`div`,{style:{position:`absolute`,transform:`translate(-50%, -50%) translate(${f}px, ${p}px)`},className:`pointer-events-none rounded-full border border-white/15 bg-slate-800/90 px-1.5 py-0.5 text-[8px] font-medium text-white/85 backdrop-blur-sm`,children:o.label})})]})}};function tg({events:e,now:t}){let n=e.slice(0,14);return(0,J.jsx)(`div`,{className:`absolute bottom-0 left-0 right-0 z-10 pointer-events-none px-3 pb-3`,children:(0,J.jsxs)(`div`,{className:`pointer-events-auto rounded-lg bg-slate-900/85 border border-slate-700/70 backdrop-blur px-3 py-2 max-w-3xl mx-auto`,children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-1.5 mb-1.5 text-[10px] uppercase tracking-wide text-cyan-400/80`,children:[(0,J.jsx)(_t,{className:`h-3 w-3`}),`Live activity`]}),n.length===0?(0,J.jsx)(`div`,{className:`text-[11px] text-gray-500 italic`,children:`Waiting for activity…`}):(0,J.jsx)(`div`,{className:`flex flex-col gap-0.5 max-h-32 overflow-hidden`,children:n.map(e=>{let n=Math.max(0,Math.round((t-e.timestamp)/1e3));return(0,J.jsxs)(`div`,{className:`flex items-center gap-2 text-[11px] leading-tight`,children:[(0,J.jsx)(`span`,{className:`w-1.5 h-1.5 rounded-full shrink-0`,style:{backgroundColor:Bh(e.kind)}}),(0,J.jsx)(`span`,{className:`text-gray-300 truncate flex-1`,children:e.label}),(0,J.jsx)(`span`,{className:`text-gray-600 shrink-0 tabular-nums`,children:n<1?`now`:`${n}s`})]},e.id)})})]})})}function ng(){let{fitView:e}=te(),t=ia(e=>e.events),n=Y(e=>e.agents),r=Y(e=>e.leaderId),i=da(e=>e.liveSessions),a=gi(e=>e.messages),s=K(e=>e.session),c=(0,H.useMemo)(()=>zh(i,n),[i,n]),u=xa(e=>e.showHud),d=xa(e=>e.showLegend),f=xa(e=>e.showMinimap),p=xa(e=>e.showControls),m=xa(e=>e.showFeed),h=xa(e=>e.setShowFeed),g=xa(e=>e.background),[_,v,b]=E([]),[x,C,w]=Ee([]),[T,D]=(0,H.useState)(null),[O,k]=(0,H.useState)(null),[A,j]=(0,H.useState)(!1),[M,N]=(0,H.useState)(``),[P,F]=(0,H.useState)(!1),[I,ee]=(0,H.useState)(null),L=(0,H.useCallback)(async()=>{let e=M.trim();if(!(!e||P)){F(!0),ee(null);try{let t=await fetch(`/api/fleet/broadcast`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({text:e})});if(!t.ok)throw Error(`HTTP ${t.status}`);let n=await t.json();N(``),ee(`Delivered to ${n.delivered??0}/${n.targets??0} session(s)`)}catch(e){ee(`Failed: ${e instanceof Error?e.message:String(e)}`)}finally{F(!1)}}},[M,P]),ne=(0,H.useRef)(new Map),re=4e3,ie=(0,H.useRef)(new Map),ae=(0,H.useRef)(new Map),oe=(0,H.useRef)(new Map),se=(0,H.useRef)(new Map),ce=(0,H.useRef)(``);(0,H.useEffect)(()=>{let t=[],i=[],o=Date.now(),s=Math.max(1,...c.map(e=>e.agents.length||1)),l=Math.max(380,Math.min(3,s)*190+80),u=Ph(c.map(e=>e.id),l),d=a.filter(e=>!e.completed&&(e.readByCount??0)===0).length,f=a.length?[...a].sort((e,t)=>Date.parse(t.timestamp)-Date.parse(e.timestamp))[0]:void 0;t.push({id:`mailbox`,type:`mailbox`,position:{x:830,y:50},data:{label:`Mailbox Hub`,kind:`mailbox`,status:d>0?`active`:`idle`,unreadCount:d,messageCount:a.length,sublabel:f?`${f.from} → ${f.to}: ${f.subject}`:void 0,color:`#eab308`}});let p=0,m=0,h=0,g=0,_=0;for(let e of c)for(let t of e.agents)m+=1,(t.status===`active`||t.status===`streaming`)&&(p+=1),h+=t.toolCalls,g+=t.costUsd,_+=t.tokensIn+t.tokensOut;let y=r?n.get(r):null,b=p>0;t.push({id:`coordinator`,type:`coordinator`,position:{x:370,y:50},data:{label:`Fleet HQ`,sublabel:`${c.length} client${c.length===1?``:`s`}`,kind:`coordinator`,status:y?.status===`failed`?`error`:b?`active`:`idle`,connections:c.length,agentsActive:p,agentsTotal:m,toolCalls:h,costUsd:g,tokensIn:_,color:`#a855f7`}});let x={tui:`#22c55e`,webui:`#3b82f6`,repl:`#f59e0b`};for(let e of c){let n=u.get(e.id)??600,r=x[e.type],a=e.status===`active`;if(t.push({id:e.id,type:e.type,position:{x:n,y:370},data:{label:e.label,sublabel:e.sublabel,kind:e.type,status:e.status,sessionId:e.sessionId,pid:e.pid,branch:e.branch,workingDir:e.workingDir,startedAt:e.startedAt,agentCount:e.agents.length,color:r}}),i.push({id:`${e.id}->coordinator`,source:e.id,target:`coordinator`,type:`wire`,animated:a,data:{color:r,animated:a,label:`control`,flowType:`task`}}),i.push({id:`mailbox->${e.id}`,source:`mailbox`,target:e.id,type:`wire`,animated:d>0,data:{color:`#eab308`,animated:d>0,label:d>0?`${d}`:void 0,flowType:`mail`}}),e.agents.length===0){t.push({id:`desk-${e.id}`,type:`desk`,position:{x:n,y:640},data:{label:`Idle desk`,kind:`agent`,status:`idle`,color:`#374151`}});continue}e.agents.forEach((r,a)=>{let s=r.status===`active`||r.status===`streaming`,c=se.current.get(r.serverId);if(c&&(r.toolCalls>c.toolCalls||r.iteration>c.iteration)||s){ne.current.set(r.officeId,o+re);let t=ae.current.get(r.officeId)??0;ae.current.set(r.officeId,Math.min(1,t+(1-t)*.5));for(let t of[`${e.id}->${r.officeId}`,`${e.id}->coordinator`]){let e=ie.current.get(t)??0;ie.current.set(t,Math.min(1,e+.5))}}se.current.set(r.serverId,{toolCalls:r.toolCalls,iteration:r.iteration}),t.push({id:r.officeId,type:`agent`,position:Fh(n,a,e.agents.length),data:{label:r.name,kind:`agent`,status:r.status,sessionId:e.sessionId,currentTask:r.currentTask,iteration:r.iteration,toolCalls:r.toolCalls,costUsd:r.costUsd,tokensIn:r.tokensIn,tokensOut:r.tokensOut,ctxPct:r.ctxPct,model:r.model,lastActivityAt:r.lastActivityAt,color:`#06b6d4`}}),i.push({id:`${e.id}->${r.officeId}`,source:e.id,target:r.officeId,type:`wire`,animated:s,data:{color:`#06b6d4`,animated:s,label:s?r.currentTask??`task`:void 0,flowType:`task`}})})}let S=new Set(c.flatMap(e=>e.agents.map(e=>e.serverId)));for(let e of[...se.current.keys()])S.has(e)||se.current.delete(e);let w=t.map(e=>{let t=ne.current.get(e.id),n=ae.current.get(e.id)??0;return t&&t>o&&e.data.status!==`error`&&e.data.status!==`offline`?{...e,data:{...e.data,status:`active`,vizActivity:n}}:{...e,data:{...e.data,vizActivity:n}}}),T=i.map(e=>{let t=ie.current.get(e.id)??0;return t>.05?{...e,animated:!0,data:{...e.data,animated:!0,intensity:t}}:e}),E=new Map;for(let e of w)E.set(e.id,{...e.position});oe.current=E,v(w),C(T);let D=w.map(e=>e.id).sort().join(`|`);if(D!==ce.current){ce.current=D;let t=setTimeout(()=>e({padding:.2,duration:300}),50);return()=>clearTimeout(t)}},[c,r,n,a,s,re,v,C,e]);let le=c.flatMap(e=>e.agents.map(t=>({clientId:e.id,clientType:e.type,officeId:t.officeId,serverId:t.serverId}))),ue=c.map(e=>e.id),de=new Map;for(let e of le)(!de.has(e.serverId)||e.clientType===`webui`)&&de.set(e.serverId,e.officeId);function R(e){return de.get(e)??`agent-${e}`}function fe(e){let t=e.split(`__agent-`)[0];return t&&t!==e?`${t}->${e}`:`coordinator->${e}`}function pe(e){switch(e.kind){case`mailbox:send`:case`mailbox:deliver`:return{nodes:[`mailbox`],edges:e.kind===`mailbox:send`?ue.map(e=>`mailbox->${e}`):[],status:`active`};case`agent:spawned`:{let t=R(e.source);return{nodes:[`coordinator`,t],edges:[fe(t)],status:`active`}}case`agent:tool`:case`tool:started`:case`tool:progress`:{let t=R(e.source);return{nodes:[`coordinator`,t],edges:[fe(t)],status:e.kind===`tool:progress`||e.kind===`tool:started`?`streaming`:`active`}}case`tool:executed`:{let t=R(e.target??e.source);return{nodes:[t],edges:[fe(t)],status:`active`}}case`provider:call`:case`provider:delta`:case`provider:response`:return{nodes:[`coordinator`],edges:[],status:e.kind===`provider:delta`?`streaming`:`active`};case`iteration:start`:case`iteration:end`:return{nodes:[`coordinator`],edges:le.map(e=>fe(e.officeId)),status:e.kind===`iteration:start`?`streaming`:`active`};case`agent:text`:{let t=R(e.source);return{nodes:[t],edges:[fe(t)],status:`streaming`}}case`agent:status`:{let t=R(e.source);return{nodes:[`coordinator`,t],edges:[fe(t)],status:e.data&&typeof e.data==`object`&&`status`in e.data&&String(e.data.status)===`failed`?`error`:`completed`}}case`agent:ctx`:return{nodes:[R(e.source)],edges:[],status:`active`};case`budget:extended`:return{nodes:[`coordinator`,R(e.source)],edges:[],status:`active`};case`context:compacted`:case`context:repaired`:return{nodes:[`coordinator`],edges:[],status:`active`};case`error`:return{nodes:e.source?[R(e.source)]:[],edges:[],status:`error`};case`cost:update`:return{nodes:[`coordinator`],edges:[],status:`active`};case`fleet:snapshot`:{let t=e.data?.sessions??[],n=[`coordinator`];for(let e of t)if(e.agents)for(let t of e.agents){let e=R(t.id);n.includes(e)||n.push(e)}return{nodes:n,edges:[],status:`active`}}default:return{nodes:[],edges:[],status:`idle`}}}(0,H.useEffect)(()=>{if(t.length===0)return;let e=t[0];if(!e)return;let{nodes:n,edges:r,status:i}=pe(e),a=Date.now();n.length>0&&(n.forEach(e=>{ne.current.set(e,a+re);let t=ae.current.get(e)??0;ae.current.set(e,Math.min(1,t+(1-t)*.5))}),v(e=>e.map(e=>n.includes(e.id)?{...e,data:{...e.data,status:i,vizActivity:ae.current.get(e.id)??0}}:e))),r.length>0&&(r.forEach(e=>{let t=ie.current.get(e)??0;ie.current.set(e,Math.min(1,t+.5))}),C(e=>e.map(e=>r.includes(e.id)?{...e,animated:!0,data:{...e.data,animated:!0,intensity:ie.current.get(e.id)??1}}:e)))},[t,v,C,re,n]),(0,H.useEffect)(()=>{let e=setInterval(()=>{for(let[e,t]of ie.current){let n=t*.85;n<.05?(ie.current.delete(e),C(t=>t.map(t=>t.id===e?{...t,animated:!1,data:{...t.data,animated:!1}}:t))):(ie.current.set(e,n),C(t=>t.map(t=>t.id===e?{...t,data:{...t.data,intensity:n}}:t)))}for(let[e,t]of ae.current){let n=t*.9;n<.03?(ae.current.delete(e),v(t=>t.map(t=>t.id===e?{...t,data:{...t.data,vizActivity:0}}:t))):(ae.current.set(e,n),v(t=>t.map(t=>t.id===e?{...t,data:{...t.data,vizActivity:n}}:t)))}},1e3);return()=>clearInterval(e)},[C,v]);let me=(0,H.useCallback)(e=>C(t=>he({...e,type:`wire`},t)),[C]),ge=(0,H.useCallback)((e,t)=>{D(t)},[]),ve=(0,H.useCallback)(()=>{D(null)},[]);(0,H.useEffect)(()=>{if(!O)return;let e=e=>{e.key===`Escape`&&k(null)};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[O]);let z=(0,H.useCallback)(()=>{v(e=>e.map(e=>{let t=oe.current.get(e.id);return t?{...e,position:{...t}}:e})),setTimeout(()=>e({padding:.2,duration:300}),50)},[v,e]),[,be]=(0,H.useState)(0);return(0,H.useEffect)(()=>{let e=setInterval(()=>be(e=>e+1),2e3);return()=>clearInterval(e)},[]),(0,J.jsxs)(`div`,{className:`w-full h-full bg-gradient-to-br from-slate-900 via-slate-800 to-slate-900 relative overflow-hidden`,children:[(0,J.jsx)(`div`,{className:`absolute inset-0 opacity-[0.03]`,style:{backgroundImage:`
|
|
139
139
|
linear-gradient(rgba(255,255,255,0.1) 1px, transparent 1px),
|