tide-commander 1.72.0 → 1.74.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assets/{BossLogsModal-DlpAJubL.js → BossLogsModal-XZupQ15_.js} +1 -1
- package/dist/assets/{BossSpawnModal-CNFxhhc5.js → BossSpawnModal-BkggsiGJ.js} +1 -1
- package/dist/assets/{ControlsModal-DaxduzM0.js → ControlsModal-BACb1yEc.js} +1 -1
- package/dist/assets/{DockerLogsModal-CL1yesIS.js → DockerLogsModal-YHRrsjQp.js} +1 -1
- package/dist/assets/{EmbeddedEditor-CPnEchoJ.js → EmbeddedEditor-BSRJDqGd.js} +1 -1
- package/dist/assets/{GmailOAuthSetup-D-elay-s.js → GmailOAuthSetup-2Ppyuv5K.js} +1 -1
- package/dist/assets/{GoogleOAuthSetup-CZlI2XXd.js → GoogleOAuthSetup-gENk0zRj.js} +1 -1
- package/dist/assets/{IframeModal-CZIQrQEx.js → IframeModal-_fp3neFL.js} +1 -1
- package/dist/assets/{IntegrationsPanel-Bz6bFSVE.js → IntegrationsPanel-B89N7AAS.js} +2 -2
- package/dist/assets/{LogViewerModal-BqZ7cNOD.js → LogViewerModal-DuGXmrPm.js} +1 -1
- package/dist/assets/{MonitoringModal-BLSJCF0o.js → MonitoringModal-D9PPfBx9.js} +1 -1
- package/dist/assets/{PM2LogsModal-B2iZEmM3.js → PM2LogsModal-r8jxzq2F.js} +1 -1
- package/dist/assets/{RestoreArchivedAreaModal-BT_7W4MX.js → RestoreArchivedAreaModal-BzAJjHn6.js} +1 -1
- package/dist/assets/{Scene2DCanvas-SlszbWjN.js → Scene2DCanvas-CLn_E93K.js} +1 -1
- package/dist/assets/{SceneManager-fQ9mY-na.js → SceneManager--vMpx8gM.js} +1 -1
- package/dist/assets/{SkillsPanel-oWxlFfS4.js → SkillsPanel-qhKWxfpL.js} +1 -1
- package/dist/assets/{SpawnModal-BDR39F-T.js → SpawnModal-Ca4C2H3v.js} +1 -1
- package/dist/assets/{SubordinateAssignmentModal-UEenzUT0.js → SubordinateAssignmentModal-DVbBhkFt.js} +1 -1
- package/dist/assets/{TriggerManagerPanel-omMLL6Mi.js → TriggerManagerPanel-DNsMPzBx.js} +1 -1
- package/dist/assets/{WorkflowEditorPanel-X403MCNp.js → WorkflowEditorPanel-BEae9pPl.js} +1 -1
- package/dist/assets/{index-BvX7U4GZ.js → index-BinaXrmY.js} +1 -1
- package/dist/assets/{index-Dy4hZ0Me.js → index-BtQIlMbZ.js} +3 -3
- package/dist/assets/{index-BoMGSybR.js → index-CDGC6iEM.js} +1 -1
- package/dist/assets/{index-CTz_qHJG.js → index-Cho7e9wl.js} +2 -2
- package/dist/assets/{index-CUbWwZvL.js → index-Cpm8pHhE.js} +1 -1
- package/dist/assets/{index-DLtcDXEt.js → index-G2EIaT8y.js} +1 -1
- package/dist/assets/{index-Dkx8tXJi.js → index-Ulo84ewo.js} +1 -1
- package/dist/assets/{index-DmmNbFv1.js → index-WfwvOPbk.js} +1 -1
- package/dist/assets/{index-C-dhn0OI.js → index-rKeTU0Q2.js} +1 -1
- package/dist/assets/main-BCNShZjZ.css +1 -0
- package/dist/assets/{main-mSA6_Yi8.js → main-BnUsuS5B.js} +69 -69
- package/dist/assets/{web-6zI01vYP.js → web-Bz9_47wH.js} +1 -1
- package/dist/assets/{web-DEhWQfjr.js → web-CA59D-C5.js} +1 -1
- package/dist/index.html +2 -2
- package/dist/locales/de/common.json +1 -2
- package/dist/locales/en/common.json +1 -2
- package/dist/locales/en/terminal.json +1 -0
- package/dist/locales/es/common.json +1 -2
- package/dist/locales/fr/common.json +1 -2
- package/dist/locales/hi/common.json +1 -2
- package/dist/locales/it/common.json +1 -2
- package/dist/locales/ja/common.json +1 -2
- package/dist/locales/pt/common.json +1 -2
- package/dist/locales/ru/common.json +1 -2
- package/dist/locales/zh-CN/common.json +1 -2
- package/dist/src/packages/server/data/index.js +1 -0
- package/package.json +1 -1
- package/dist/assets/main-DN-PQyw6.css +0 -1
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{z as It,B as St,r as n,C as mt,S as x,E as ft,G as ct,H as ht,J as Ge,K as xe,L as Mt,s as b,M as bt,N as Et,v as yt,w as Tt,j as e,I as p,O as Pt,m as Rt,P as wt,U as Ct,V as Dt,W as zt,X as $t,Y as Lt,Z as Ot,_ as Ft,$ as Wt,a0 as Bt,a1 as Ht,a2 as Gt,a3 as Vt,a4 as Ut,a5 as Xt,a6 as qt,a7 as Kt,a8 as Yt,a9 as Zt,aa as Jt,ab as Qt,ac as ea,ad as ta,ae as aa,af as na,ag as sa}from"./main-mSA6_Yi8.js";import"./vendor-react--Eh9ivFN.js";import"./vendor-three-Chj50gSY.js";const Ve=3,Ue=280,gt=320,ot=240,_t=64,la=["simple","chat","advanced"],ra={simple:"Simple",chat:"Chat",advanced:"Advanced"},ia={simple:"○",chat:"◐",advanced:"◉"},oa={simple:"Simple view — clean messages only",chat:"Chat view — assistant replies (no tool calls)",advanced:"Advanced view — everything including tools"},xt="flat-clear-context";function ca(m){const o=m.split("/").filter(Boolean);return o.length===0?m:o.slice(-2).join("/")}function da(m){if(m.provider==="codex"){const re=m.codexModel||"gpt-5.3-codex",k=aa[re];return{model:(k==null?void 0:k.label)||re}}if(m.provider==="opencode")return{model:m.opencodeModel||"opencode"};const o=m.model||"sonnet",C=sa[o],E=m.effort,T=E?na[E]:void 0;return{model:(C==null?void 0:C.label)||o,effort:T==null?void 0:T.label}}function pa(m,o){if(o.type==="rectangle"&&o.width&&o.height){const C=o.width/2,E=o.height/2;return m.x>=o.center.x-C&&m.x<=o.center.x+C&&m.z>=o.center.z-E&&m.z<=o.center.z+E}if(o.type==="circle"&&o.radius){const C=m.x-o.center.x,E=m.z-o.center.z;return C*C+E*E<=o.radius*o.radius}return!1}const ua=Bt.memo(function({agentId:o,terminalViewMode:C,onTerminalViewModeChange:E,inspectorOpen:T,onToggleInspector:re,onImageClick:k,onFileClick:be,onBashClick:we,onViewMarkdown:Ie,onRequestClearSubordinates:Se,onOpenBuilding:Ce,keyboard:je,canNavigateBack:Me,canNavigateForward:$,onNavigateBack:ie,onNavigateForward:oe,agentInfoOpen:U,onToggleAgentInfo:Xe}){var Le,Oe,ge,ve;const u=Ht(o),L=Gt(),X=n.useRef(null),Ee=n.useRef(null);n.useEffect(()=>{const s=Ee.current;if(!s)return;const c=i=>{i.button===3?(i.preventDefault(),i.stopPropagation(),ie()):i.button===4&&(i.preventDefault(),i.stopPropagation(),oe())},d=i=>{(i.button===3||i.button===4)&&i.preventDefault()};return s.addEventListener("mouseup",c),s.addEventListener("mousedown",d),()=>{s.removeEventListener("mouseup",c),s.removeEventListener("mousedown",d)}},[ie,oe]);const ce=bt(),de=n.useMemo(()=>{if(!u)return null;const s=new Set,c=[];for(const d of ce.values())d.archived||d.directories.length===0||d.assignedAgentIds.includes(o)&&(s.add(d.id),c.push(d));for(const d of ce.values())d.archived||d.directories.length===0||s.has(d.id)||pa({x:u.position.x,z:u.position.z},d)&&(s.add(d.id),c.push(d));return c.length===0?null:c.flatMap(d=>d.directories.filter(i=>i&&i.trim().length>0).map(i=>({areaId:d.id,areaName:d.name,dir:i})))},[u,o,ce]),{branches:q,fetchRemote:pe,fetchingDirs:ye}=Vt(de),ue=n.useMemo(()=>{var d;const s=b.getAreaForAgent(o);if(!s)return[];const c=[];for(const i of L.values())i.type==="terminal"&&b.isPositionInArea(i.position,s)&&c.push({id:i.id,name:i.name,hasUrl:!!((d=i.terminalStatus)!=null&&d.url)});return c},[o,L]),K=n.useMemo(()=>{var d;const s=b.getAreaForAgent(o);if(!s)return[];const c=[];for(const i of L.values())i.type==="server"&&((d=i.pm2)!=null&&d.enabled)&&b.isPositionInArea(i.position,s)&&c.push({id:i.id,name:i.name});return c},[o,L]),W=n.useMemo(()=>{const s=b.getAreaForAgent(o);if(!s)return[];const c=[];for(const d of L.values())d.type==="database"&&d.database&&b.isPositionInArea(d.position,s)&&c.push({id:d.id,name:d.name});return c},[o,L]),[,Y]=n.useReducer(s=>s+1,0),O=((Le=X.current)==null?void 0:Le.search.searchMode)??!1,P=n.useCallback(()=>{var s;(s=X.current)==null||s.search.toggleSearch(),Y()},[]),Z=Ut(),R=Z.isPending(xt),[M,me]=n.useState(null),B=M?L.get(M):null,{height:Te,onResizeStart:fe}=Xt(),[J,Pe]=n.useState(()=>ct(x.GIT_PANEL_OPEN,!1)),[y,Re]=n.useState(()=>ct(x.BUILDINGS_PANEL_OPEN,!1)),[H,De]=n.useState(!1),qe=n.useCallback(()=>{De(s=>{const c=!s;return c&&qt.setEnabled(!0),c})},[]),Ke=n.useCallback(()=>De(!1),[]),Ye=n.useCallback(()=>{Pe(s=>{const c=!s;return xe(x.GIT_PANEL_OPEN,c),c})},[]),Ze=n.useCallback(()=>{Re(s=>{const c=!s;return xe(x.BUILDINGS_PANEL_OPEN,c),c})},[]),Je=n.useCallback(()=>{Pe(!1),xe(x.GIT_PANEL_OPEN,!1)},[]),Qe=n.useCallback(()=>{Re(!1),xe(x.BUILDINGS_PANEL_OPEN,!1)},[]),et=Kt();n.useEffect(()=>{if(!M)return;ue.some(c=>c.id===M)||me(null)},[M,ue]);const[Q,f]=n.useState(!1),F=n.useRef(null);if(n.useEffect(()=>{if(!Q)return;const s=c=>{F.current&&!F.current.contains(c.target)&&f(!1)};return document.addEventListener("mousedown",s),()=>document.removeEventListener("mousedown",s)},[Q]),!u)return e.jsx("div",{className:"flat-chat flat-chat--empty",children:e.jsxs("div",{className:"flat-chat__placeholder",children:[e.jsx("span",{className:"flat-chat__placeholder-icon",children:"💬"}),e.jsx("span",{className:"flat-chat__placeholder-text",children:"Select an agent to start chatting"})]})});const A=u.contextStats,he=!!A,Ne=A?A.totalTokens:u.contextUsed||0,ze=A?A.contextWindow:u.contextLimit||2e5,tt=A?A.usedPercent:Math.round(Ne/ze*100),G=Math.max(0,Math.min(100,tt)),at=Math.max(0,100-G),ee=G>=80?"#ff4a4a":G>=60?"#ff9e4a":G>=40?"#ffd700":"#4aff9e",D=(Ne/1e3).toFixed(1),te=(ze/1e3).toFixed(1),ae=u.cwd,$e=ae?ca(ae):null,ne=((Oe=u.subordinateIds)==null?void 0:Oe.length)||0,nt=ne>0;return e.jsxs("div",{ref:Ee,className:`flat-terminal-wrapper ${J||y||H?"flat-terminal-wrapper--with-side-panel":""}`,children:[e.jsxs("div",{className:"flat-terminal-wrapper__header",children:[e.jsxs("button",{type:"button",className:`flat-terminal-wrapper__header-main ${U?"flat-terminal-wrapper__header-main--active":""}`,onClick:Xe,title:U?"Hide agent info":"Show agent info","aria-pressed":U,children:[e.jsx(wt,{agent:u,size:28}),e.jsxs("span",{className:"flat-terminal-wrapper__header-info",children:[e.jsx("span",{className:"flat-terminal-wrapper__header-name",children:u.name}),e.jsx("span",{className:"flat-terminal-wrapper__header-status",style:{color:Ct(u.status)},children:u.status})]}),u.taskLabel&&e.jsxs("span",{className:"flat-terminal-wrapper__header-task",title:u.taskLabel,children:["📋 ",u.taskLabel]}),e.jsxs("span",{className:"flat-terminal-wrapper__header-model",children:[e.jsx("img",{src:u.provider==="codex"?"/assets/codex.png":u.provider==="opencode"?"/assets/opencode.png":"/assets/claude.png",alt:u.provider,className:"flat-terminal-wrapper__header-provider-icon",title:u.provider==="codex"?"Codex Agent":u.provider==="opencode"?"OpenCode Agent":"Claude Agent"}),(()=>{const{model:s,effort:c}=da(u);return e.jsxs("span",{className:"flat-terminal-wrapper__header-model-chip",title:c?`Model: ${s} · Effort: ${c}`:`Model: ${s}`,children:[e.jsx("span",{className:"flat-terminal-wrapper__header-model-name",children:s}),c&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"flat-terminal-wrapper__header-model-sep","aria-hidden":"true",children:"·"}),e.jsx("span",{className:"flat-terminal-wrapper__header-model-effort",children:c})]})]})})()]})]}),e.jsxs("div",{className:"flat-terminal-wrapper__header-meta",children:[e.jsx("div",{className:"flat-terminal-wrapper__view-mode",role:"group","aria-label":"Message view mode",children:la.map(s=>e.jsxs("button",{type:"button",className:`flat-terminal-wrapper__view-mode-btn ${C===s?"flat-terminal-wrapper__view-mode-btn--active":""}`,onClick:()=>E(s),title:oa[s],"aria-pressed":C===s,children:[e.jsx("span",{className:"flat-terminal-wrapper__view-mode-icon","aria-hidden":"true",children:ia[s]}),e.jsx("span",{className:"flat-terminal-wrapper__view-mode-label",children:ra[s]})]},s))}),e.jsxs("div",{className:"flat-terminal-wrapper__actions",role:"group","aria-label":"Terminal actions",children:[e.jsx("button",{type:"button",className:"flat-terminal-wrapper__action-btn",onClick:ie,disabled:!Me,title:"Back to previous agent","aria-label":"Back to previous agent",children:e.jsx(p,{name:"arrow-left",size:14})}),e.jsx("button",{type:"button",className:"flat-terminal-wrapper__action-btn",onClick:oe,disabled:!$,title:"Forward to next agent","aria-label":"Forward to next agent",children:e.jsx(p,{name:"arrow-right",size:14})}),e.jsx("button",{type:"button",className:`flat-terminal-wrapper__action-btn ${O?"flat-terminal-wrapper__action-btn--active":""}`,onClick:P,title:O?"Close search":"Search messages","aria-pressed":O,children:e.jsx(p,{name:O?"cross":"search",size:14})}),e.jsx("button",{type:"button",className:`flat-terminal-wrapper__action-btn flat-terminal-wrapper__action-btn--danger ${R?"flat-terminal-wrapper__action-btn--confirm":""}`,onClick:()=>Z.handleClick(xt,()=>{var s;b.clearContext(o),(s=X.current)==null||s.historyLoader.clearHistory()}),title:R?"Click again to confirm clear context":"Clear context",children:e.jsx(p,{name:R?"question":"clear",size:14})}),e.jsx("button",{type:"button",className:`flat-terminal-wrapper__action-btn ${J?"flat-terminal-wrapper__action-btn--active":""}`,onClick:Ye,title:J?"Hide git panel":"Show git changes","aria-pressed":J,children:e.jsx(p,{name:"git-branch",size:14})}),e.jsx("button",{type:"button",className:`flat-terminal-wrapper__action-btn ${y?"flat-terminal-wrapper__action-btn--active":""}`,onClick:Ze,title:y?"Hide buildings panel":"Show area buildings","aria-pressed":y,children:e.jsx(p,{name:"buildings",size:14})}),e.jsxs("div",{className:"flat-terminal-wrapper__more",ref:F,children:[e.jsx("button",{type:"button",className:`flat-terminal-wrapper__action-btn ${Q?"flat-terminal-wrapper__action-btn--active":""}`,onClick:()=>f(s=>!s),title:"More actions","aria-expanded":Q,children:"⋮"}),Q&&e.jsxs("div",{className:"flat-terminal-wrapper__more-menu",role:"menu",children:[e.jsxs("button",{type:"button",role:"menuitem",className:`flat-terminal-wrapper__more-item ${H?"flat-terminal-wrapper__more-item--active":""}`,onClick:()=>{qe(),f(!1)},title:H?"Hide Debug Panel":"Show Debug Panel",children:[e.jsx(p,{name:"bug",size:14}),e.jsx("span",{children:H?"Hide Debug Panel":"Show Debug Panel"})]}),e.jsx("div",{className:"flat-terminal-wrapper__more-divider"}),e.jsxs("button",{type:"button",role:"menuitem",className:"flat-terminal-wrapper__more-item",onClick:()=>{b.collapseContext(o),f(!1)},disabled:u.status!=="idle",title:u.status!=="idle"?"Agent must be idle to collapse context":"Collapse context",children:[e.jsx(p,{name:"package",size:14}),e.jsx("span",{children:"Collapse context"})]}),nt&&e.jsxs("button",{type:"button",role:"menuitem",className:"flat-terminal-wrapper__more-item flat-terminal-wrapper__more-item--danger",onClick:()=>{Se(o,ne),f(!1)},children:[e.jsx(p,{name:"crown",size:14}),e.jsxs("span",{children:["Clear ",ne," subordinate",ne===1?"":"s"]})]}),e.jsx("div",{className:"flat-terminal-wrapper__more-divider"}),e.jsxs("button",{type:"button",role:"menuitem",className:"flat-terminal-wrapper__more-item flat-terminal-wrapper__more-item--danger",onClick:()=>{b.killAgent(o),f(!1)},children:[e.jsx(p,{name:"cross",size:14}),e.jsx("span",{children:"Remove agent"})]})]})]})]}),e.jsxs("button",{type:"button",className:`flat-terminal-wrapper__inspector-toggle ${T?"flat-terminal-wrapper__inspector-toggle--active":""}`,onClick:re,title:T?"Hide inspector panel":"Show inspector panel","aria-label":T?"Hide inspector panel":"Show inspector panel","aria-pressed":T,children:[e.jsx("span",{className:"flat-terminal-wrapper__inspector-icon","aria-hidden":"true",children:e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("rect",{x:"1.5",y:"2.5",width:"13",height:"11",rx:"1.5"}),e.jsx("line",{x1:"10",y1:"2.5",x2:"10",y2:"13.5"})]})}),e.jsx("span",{className:"flat-terminal-wrapper__inspector-label",children:"Inspector"})]}),e.jsx("button",{type:"button",className:"flat-terminal-wrapper__close",onClick:()=>b.deselectAll(),title:"Close chat","aria-label":"Close chat",children:e.jsx(p,{name:"cross",size:14})})]})]}),e.jsx(Yt,{ref:X,agentId:o,agent:u,viewMode:C,isOpen:!0,onImageClick:k,onFileClick:be,onBashClick:we,onViewMarkdown:Ie,keyboard:je,hasModalOpen:!1}),B&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"guake-bottom-terminal-resize",onMouseDown:fe,role:"separator","aria-orientation":"horizontal","aria-label":"Resize embedded terminal"}),e.jsxs("div",{className:"flat-bottom-panel",role:"region","aria-label":`Embedded terminal: ${B.name}`,style:{height:Te},children:[e.jsxs("div",{className:"flat-bottom-panel__header",children:[e.jsxs("span",{className:"flat-bottom-panel__title",children:[e.jsx(p,{name:"terminal",size:12}),e.jsx("span",{children:B.name}),!((ge=B.terminalStatus)!=null&&ge.url)&&e.jsx("span",{className:"flat-bottom-panel__muted",children:"(starting...)"})]}),e.jsx("button",{type:"button",className:"flat-bottom-panel__close",onClick:()=>me(null),title:"Close embedded terminal","aria-label":"Close embedded terminal",children:e.jsx(p,{name:"cross",size:12})})]}),e.jsx("div",{className:"flat-bottom-panel__body",children:(ve=B.terminalStatus)!=null&&ve.url?e.jsx(Zt,{terminalUrl:B.terminalStatus.url,visible:!0}):e.jsx("div",{className:"flat-bottom-panel__placeholder",children:"Starting terminal..."})})]})]}),e.jsxs("div",{className:"flat-terminal-wrapper__statusbar",role:"contentinfo",children:[u.isDetached&&e.jsxs("span",{className:"flat-terminal-wrapper__detached",title:"Reattaching session...",children:[e.jsx(p,{name:"refresh",size:12}),e.jsx("span",{children:"Reattaching"})]}),ae&&$e&&e.jsxs("span",{className:"flat-terminal-wrapper__cwd",title:ae,onClick:()=>b.setFileViewerPath(ae),children:[e.jsx("span",{className:"flat-terminal-wrapper__cwd-icon",children:e.jsx(p,{name:"folder",size:12})}),e.jsx("span",{className:"flat-terminal-wrapper__cwd-text",children:$e})]}),de&&de.map(({areaId:s,areaName:c,dir:d})=>{const i=q.get(d),Fe=ye.has(d),V=d.split("/").filter(Boolean).pop()||d;return e.jsxs("span",{className:"flat-terminal-wrapper__area-dir",title:`${c}: ${d}${i?` (${i.branch}${i.ahead?` ↑${i.ahead}`:""}${i.behind?` ↓${i.behind}`:""})`:""}`,onClick:()=>b.openFileExplorerForAreaFolder(s,d),children:[e.jsx(p,{name:"folder-open",size:12}),e.jsx("span",{className:"flat-terminal-wrapper__area-dir-name",children:V}),i&&e.jsxs(e.Fragment,{children:[e.jsxs("span",{className:"flat-terminal-wrapper__area-dir-branch",children:[e.jsx(p,{name:"git-branch",size:10})," ",i.branch]}),i.ahead>0&&e.jsxs("span",{className:"flat-terminal-wrapper__branch-ahead",title:`${i.ahead} ahead`,children:[e.jsx(p,{name:"arrow-up",size:9}),i.ahead]}),i.behind>0&&e.jsxs("span",{className:"flat-terminal-wrapper__branch-behind",title:`${i.behind} behind`,children:[e.jsx(p,{name:"arrow-down",size:9}),i.behind]}),e.jsx("span",{className:`flat-terminal-wrapper__area-fetch ${Fe?"flat-terminal-wrapper__area-fetch--fetching":""}`,title:"Git fetch",onClick:st=>{st.stopPropagation(),pe(d)},children:e.jsx(p,{name:Fe?"hourglass":"download",size:12})})]})]},`${s}:${d}`)}),e.jsxs("span",{className:"flat-terminal-wrapper__context",onClick:()=>b.setContextModalAgentId(o),title:he?`Context usage: ${D}k / ${te}k tokens (${G}% used). Click to view stats.`:"Click to fetch context stats",children:[e.jsx("span",{className:"flat-terminal-wrapper__context-icon",children:e.jsx(p,{name:"dashboard",size:12})}),e.jsx("span",{className:"flat-terminal-wrapper__context-label",children:"Ctx:"}),e.jsx("span",{className:"flat-terminal-wrapper__context-bar",children:e.jsx("span",{className:"flat-terminal-wrapper__context-bar-fill",style:{width:`${G}%`,backgroundColor:ee}})}),e.jsxs("span",{className:"flat-terminal-wrapper__context-tokens",style:{color:ee},children:[D,"k/",te,"k"]}),e.jsxs("span",{className:"flat-terminal-wrapper__context-free",children:["(",at,"% free)"]}),!he&&e.jsx("span",{className:"flat-terminal-wrapper__context-warning",title:"No context stats yet",children:e.jsx(p,{name:"warn",size:12})})]}),e.jsx("div",{className:"flat-terminal-wrapper__statusbar-spacer","aria-hidden":"true"}),ue.length>0&&e.jsx("span",{className:"flat-terminal-wrapper__buildings",role:"group","aria-label":"Area terminals",children:ue.map(s=>{const c=M===s.id;return e.jsx("button",{type:"button",className:`flat-terminal-wrapper__building-btn ${c?"flat-terminal-wrapper__building-btn--active":""} ${s.hasUrl?"":"flat-terminal-wrapper__building-btn--offline"}`,title:`${c?"Hide":"Show"} terminal: ${s.name}${s.hasUrl?"":" (starting...)"}`,onClick:()=>{if(c){me(null);return}s.hasUrl||b.sendBuildingCommand(s.id,"start"),me(s.id)},children:e.jsx(p,{name:"terminal",size:14})},s.id)})}),K.length>0&&e.jsx("span",{className:"flat-terminal-wrapper__buildings",role:"group","aria-label":"Area PM2 logs",children:K.map(s=>e.jsx("button",{type:"button",className:"flat-terminal-wrapper__building-btn",title:`Open logs: ${s.name}`,onClick:()=>Ce(s.id),children:e.jsx(p,{name:"scroll",size:14})},s.id))}),W.length>0&&e.jsx("span",{className:"flat-terminal-wrapper__buildings",role:"group","aria-label":"Area databases",children:W.map(s=>e.jsx("button",{type:"button",className:"flat-terminal-wrapper__building-btn",title:`Open database: ${s.name}`,onClick:()=>Ce(s.id),children:e.jsx(p,{name:"hard-drives",size:14})},s.id))}),e.jsx("div",{className:"flat-terminal-wrapper__theme",children:e.jsx(Jt,{})})]}),J&&e.jsx(Qt,{agentId:o,agents:et,onClose:Je,branchInfoMap:q,fetchRemote:pe,fetchingDirs:ye}),y&&e.jsx(ea,{agentId:o,onClose:Qe}),H&&e.jsx(ta,{agentId:o,onClose:Ke})]})});function ga({onAgentClick:m,onBuildingClick:o,onBuildingDoubleClick:C,onOpenSpawnModal:E,onOpenBossSpawnModal:T,onOpenAreaModal:re}){const k=It(),be=St(),[we,Ie]=n.useState(null),[Se,Ce]=n.useState(null),[je,Me]=n.useState(null),[$,ie]=n.useState(null),[oe,U]=n.useState(!1),Xe=n.useCallback(()=>{U(t=>!t)},[]),u=n.useCallback(()=>{U(!1)},[]),[L,X]=n.useState(()=>{const t=mt(x.VIEW_MODE);return t==="simple"||t==="chat"||t==="advanced"?t:"simple"}),Ee=n.useCallback(t=>{X(t),ft(x.VIEW_MODE,t)},[]);n.useEffect(()=>{const t=a=>{if(a.key!==x.VIEW_MODE)return;const l=a.newValue;(l==="simple"||l==="chat"||l==="advanced")&&X(l)};return window.addEventListener("storage",t),()=>window.removeEventListener("storage",t)},[]);const[ce,de]=n.useState(()=>ct(x.FLAT_INSPECTOR_OPEN,!1)),[q,pe]=n.useState(!1),ye=n.useCallback(()=>pe(t=>!t),[]),ue=n.useCallback(()=>pe(!1),[]),K=n.useRef(null),W=n.useRef(null),[Y,O]=n.useState(()=>{const t=ht(x.FLAT_MIDDLE_WIDTH,0);return t>=Ue?t:null}),[P,Z]=n.useState(()=>{const t=ht(x.FLAT_INSPECTOR_WIDTH,0);return t>=ot?t:null}),R=n.useCallback(t=>{if(typeof window>"u")return t;const a=P!==null?Ve+P:0,l=window.innerWidth-_t-Ve-gt-a;return Math.max(Ue,Math.min(Math.max(l,Ue),t))},[P]),M=n.useCallback(t=>{var j;if(typeof window>"u")return t;const a=(j=K.current)==null?void 0:j.querySelector(".flat-middle"),l=(a==null?void 0:a.getBoundingClientRect().width)??Ue,r=window.innerWidth-_t-l-Ve-gt-Ve;return Math.max(ot,Math.min(Math.max(r,ot),t))},[]);n.useEffect(()=>{if(Y===null&&P===null)return;const t=()=>{O(a=>{if(a===null)return a;const l=R(a);return l===a?a:l}),Z(a=>{if(a===null)return a;const l=M(a);return l===a?a:l})};return window.addEventListener("resize",t),()=>window.removeEventListener("resize",t)},[Y,P,R,M]);const me=n.useCallback(t=>{var l;if(t.button!==0)return;const a=(l=K.current)==null?void 0:l.querySelector(".flat-middle");a&&(t.currentTarget.setPointerCapture(t.pointerId),W.current={kind:"middle",startX:t.clientX,startWidth:a.getBoundingClientRect().width,pointerId:t.pointerId},document.body.classList.add("flat-splitter-dragging"))},[]),B=n.useCallback(t=>{var l;if(t.button!==0)return;const a=(l=K.current)==null?void 0:l.querySelector(".flat-inspector");a&&(t.currentTarget.setPointerCapture(t.pointerId),W.current={kind:"inspector",startX:t.clientX,startWidth:a.getBoundingClientRect().width,pointerId:t.pointerId},document.body.classList.add("flat-splitter-dragging"))},[]),Te=n.useCallback(t=>{const a=W.current;if(!a||t.pointerId!==a.pointerId)return;const l=t.clientX-a.startX;a.kind==="middle"?O(R(a.startWidth+l)):Z(M(a.startWidth-l))},[R,M]),fe=n.useCallback(t=>{const a=W.current;if(!a||t.pointerId!==a.pointerId)return;try{t.currentTarget.releasePointerCapture(t.pointerId)}catch{}if(W.current=null,document.body.classList.remove("flat-splitter-dragging"),!(Math.abs(t.clientX-a.startX)>2))return;const r=t.clientX-a.startX;if(a.kind==="middle"){const j=R(a.startWidth+r);O(j),Ge(x.FLAT_MIDDLE_WIDTH,j)}else{const j=M(a.startWidth-r);Z(j),Ge(x.FLAT_INSPECTOR_WIDTH,j)}},[R,M]),J=n.useCallback(()=>{O(null),Ge(x.FLAT_MIDDLE_WIDTH,0)},[]),Pe=n.useCallback(()=>{Z(null),Ge(x.FLAT_INSPECTOR_WIDTH,0)},[]),[y,Re]=n.useState(()=>mt(x.FLAT_INSPECTOR_VIEW)==="tracking"?"tracking":"agent"),H=n.useCallback(t=>{Re(t),ft(x.FLAT_INSPECTOR_VIEW,t)},[]),De=n.useCallback(()=>{de(t=>{const a=!t;return xe(x.FLAT_INSPECTOR_OPEN,a),a})},[]),qe=n.useCallback(()=>{de(!1),xe(x.FLAT_INSPECTOR_OPEN,!1)},[]),Ke=Mt(),Ye=n.useCallback((t,a)=>{Ie({url:t,name:a})},[]),Ze=n.useCallback((t,a)=>{Ce({command:t,output:a,isLive:!1})},[]),Je=n.useCallback((t,a)=>{b.setFileViewerPath(t,a)},[]),Qe=n.useCallback(t=>{},[]),et=n.useCallback((t,a)=>{Me({agentId:t,count:a})},[]),Q=n.useCallback(t=>{C?C(t):o(t)},[o,C]),f=n.useMemo(()=>be.size>0?Array.from(be)[0]:null,[be]);n.useEffect(()=>{U(!1)},[f]);const F=n.useRef([]),A=n.useRef(-1),he=n.useRef(!1),Ne=n.useRef(null),[ze,tt]=n.useState(!1),[G,at]=n.useState(!1),ee=n.useMemo(()=>new Set(k.map(t=>t.id)),[k]),D=n.useCallback(()=>{const t=F.current,a=A.current;tt(a>0),at(a>=0&&a<t.length-1)},[]),te=n.useCallback(t=>{const a=F.current;if(a.length===0)return;let l=A.current+t;for(;l>=0&&l<a.length;){const r=a[l];if(ee.has(r)){he.current=!0,A.current=l,D(),b.selectAgent(r);return}l+=t}},[ee,D]),ae=n.useCallback(()=>te(-1),[te]),$e=n.useCallback(()=>te(1),[te]);n.useEffect(()=>{if(!f){F.current=[],A.current=-1,D();return}if(Ne.current=f,he.current){he.current=!1,D();return}const t=F.current,a=A.current;if(a>=0&&t[a]===f){D();return}const l=a<t.length-1?t.slice(0,a+1):t.slice();l.push(f),l.length>100&&l.shift(),F.current=l,A.current=l.length-1,D()},[f,D]);const ne=n.useCallback(t=>{m(t),pe(!1)},[m]),nt=f??"",Le=n.useCallback(()=>{},[]),Oe=n.useCallback(t=>{ne(t)},[ne]),ge=ce,ve=n.useRef(null);n.useEffect(()=>{if(f)return;const t=a=>{if(a.key!==" "&&a.key!=="Backspace")return;const l=a.target;if(l.tagName==="INPUT"||l.tagName==="TEXTAREA"||l.isContentEditable)return;const r=Ne.current;!r||!ee.has(r)||(a.preventDefault(),b.selectAgent(r))};return document.addEventListener("keydown",t),()=>document.removeEventListener("keydown",t)},[f,ee]);const[s,c]=n.useState(new Set),d=n.useCallback(t=>{c(a=>{const l=new Set(a);return l.has(t)?l.delete(t):l.add(t),l})},[]),i=bt(),[Fe]=Et(),V=n.useMemo(()=>{const t=new Map,a=[];for(const g of k){const w=b.getAreaForAgent(g.id);if(!yt((w==null?void 0:w.id)??null))continue;if(!w||w.archived){a.push(g);continue}const z=t.get(w.id);z?z.push(g):t.set(w.id,[g])}const l=[];for(const[,g]of i){if(g.archived||!Tt(g.id))continue;const w=t.get(g.id);w&&w.length>0&&l.push({area:g,agents:w})}a.length>0&&l.push({area:{id:"__unassigned__",name:"Unassigned",color:"#6272a4",center:{x:0,z:0},type:"circle",radius:0,directories:[],archived:!1,assignedAgentIds:[],zIndex:0},agents:a});const r=l.filter(g=>g.area.id!=="__unassigned__"),j=l.filter(g=>g.area.id==="__unassigned__");let _=1,N=1;const ke=new Map;if(r.length>1){let g=1/0,w=-1/0,z=1/0,_e=-1/0;for(const I of r)g=Math.min(g,I.area.center.x),w=Math.max(w,I.area.center.x),z=Math.min(z,I.area.center.z),_e=Math.max(_e,I.area.center.z);const We=w-g||1,Be=_e-z||1;if(r.length<=4){_=r.length,N=1;const I=[...r].sort((S,lt)=>S.area.center.x-lt.area.center.x);for(let S=0;S<I.length;S++)ke.set(I[S].area.id,{row:1,col:S+1})}else{const I=[...r].sort((h,v)=>h.area.center.x-v.area.center.x),S=[];for(let h=1;h<I.length;h++)S.push(I[h].area.center.x-I[h-1].area.center.x);const lt=S.reduce((h,v)=>h+v,0)/S.length||1;let dt=1;for(const h of S)h>lt*1.3&&dt++;_=Math.max(2,Math.min(dt,r.length));const rt=[...r].sort((h,v)=>h.area.center.z-v.area.center.z),He=[];for(let h=1;h<rt.length;h++)He.push(rt[h].area.center.z-rt[h-1].area.center.z);const Nt=He.reduce((h,v)=>h+v,0)/He.length||1;let pt=1;for(const h of He)h>Nt*1.3&&pt++;N=Math.max(2,Math.min(pt,r.length)),_=Math.max(_,Math.ceil(r.length/N)),N=Math.max(N,Math.ceil(r.length/_));const vt=We/_,kt=Be/N,it=new Set;for(const h of r){let v=Math.min(_-1,Math.max(0,Math.floor((h.area.center.x-g)/vt))),le=Math.min(N-1,Math.max(0,Math.floor((h.area.center.z-z)/kt))),Ae=`${le},${v}`,ut=0;const At=N*_;for(;it.has(Ae)&&ut<At;)v++,v>=_&&(v=0,le=(le+1)%N),Ae=`${le},${v}`,ut++;it.has(Ae)&&(le=N,v=0,Ae=`${le},${v}`,N++),it.add(Ae),ke.set(h.area.id,{row:le+1,col:v+1})}}}const se=g=>{g.sort((w,z)=>{var We,Be,I,S;const _e=(((We=w.position)==null?void 0:We.z)??0)-(((Be=z.position)==null?void 0:Be.z)??0);return _e!==0?_e:(((I=w.position)==null?void 0:I.x)??0)-(((S=z.position)==null?void 0:S.x)??0)})};for(const g of r)se(g.agents);for(const g of j)se(g.agents);return{groups:[...r,...j],gridCols:_,gridRows:N,positions:ke}},[k,i,Fe]),st=n.useMemo(()=>{if(!$)return[];const t=k.find(a=>a.id===$.agentId);return t?[{id:"edit-agent",label:"Edit Agent",icon:e.jsx(p,{name:"edit",size:14}),onClick:()=>{window.dispatchEvent(new CustomEvent("tide:open-agent-edit",{detail:{agentId:t.id}}))}},{id:"open-chat",label:"Open Chat",icon:e.jsx(p,{name:"chat",size:14}),onClick:()=>m(t.id)},{id:"delete-agent",label:"Delete Agent",icon:e.jsx(p,{name:"trash",size:14}),danger:!0,onClick:()=>{window.confirm(`Remove ${t.name} from view?`)&&b.removeAgentFromServer(t.id)}}]:[]},[$,k,m]),jt=n.useCallback(t=>{const a=new Set(V.groups.map(l=>l.area.id));a.delete(t),c(a),requestAnimationFrame(()=>{const l=ve.current;if(!l)return;const r=l.querySelector(`[data-area-id="${t}"]`);if(!r)return;const j=l.getBoundingClientRect(),N=r.getBoundingClientRect().top-j.top+l.scrollTop-8;l.scrollTo({top:Math.max(0,N),behavior:"smooth"})})},[V]);return e.jsxs("div",{ref:K,className:`flat-view ${ge?"flat-view--with-inspector":""} ${f?"flat-view--has-chat":""} ${q?"flat-view--mobile-sidebar-open":""}`,style:(()=>{if(Y===null&&P===null)return;const t={};return Y!==null&&(t["--flat-middle-width"]=`${Y}px`),P!==null&&(t["--flat-inspector-width"]=`${P}px`),t})(),children:[q&&e.jsx("div",{className:"flat-mobile-sidebar-backdrop",onClick:ue,"aria-hidden":"true"}),e.jsxs("div",{className:"flat-middle",children:[e.jsxs("div",{className:"flat-middle__header",children:[e.jsx("h2",{className:"flat-middle__title",children:"👥 Agents"}),e.jsxs("div",{className:"flat-middle__actions",children:[e.jsx("button",{className:"flat-cta-btn flat-cta-btn--agent",onClick:E,title:"Create new agent",children:"+ Agent"}),e.jsx("button",{className:"flat-cta-btn flat-cta-btn--boss",onClick:T,title:"Create new boss agent",children:"+ Boss"}),e.jsx("button",{className:"flat-cta-btn flat-cta-btn--area",onClick:re,title:"Create new area",children:"+ Area"})]})]}),e.jsx("div",{className:"flat-middle__content",children:e.jsx(Pt,{activeAgentId:nt,onClose:Le,onSelectAgent:Oe,collapsedAreas:s,onToggleArea:d,agentListRef:ve})})]}),e.jsx("div",{className:"flat-splitter flat-splitter--middle",role:"separator","aria-orientation":"vertical","aria-label":"Resize agents panel",title:"Drag to resize · Double-click to reset",onPointerDown:me,onPointerMove:Te,onPointerUp:fe,onPointerCancel:fe,onDoubleClick:J}),e.jsxs("div",{className:"flat-right",children:[e.jsxs("button",{type:"button",className:"flat-mobile-sidebar-toggle","aria-label":q?"Close agents sidebar":"Open agents sidebar","aria-expanded":q,onClick:ye,children:[e.jsx(p,{name:"list",size:18}),e.jsx("span",{className:"flat-mobile-sidebar-toggle__label",children:"Agents"})]}),f?e.jsx(ua,{agentId:f,terminalViewMode:L,onTerminalViewModeChange:Ee,inspectorOpen:ce,onToggleInspector:De,onImageClick:Ye,onFileClick:Je,onBashClick:Ze,onViewMarkdown:Qe,onRequestClearSubordinates:et,onOpenBuilding:Q,keyboard:Ke,canNavigateBack:ze,canNavigateForward:G,onNavigateBack:ae,onNavigateForward:$e,agentInfoOpen:oe,onToggleAgentInfo:Xe}):e.jsx("div",{className:"flat-chat flat-chat--empty",children:e.jsxs("div",{className:"flat-map",children:[e.jsxs("div",{className:"flat-map__header",children:[e.jsx("span",{className:"flat-map__title",children:"🗺️ Areas"}),e.jsx("span",{className:"flat-map__hint",children:"Click an area to focus it, or an agent to chat"})]}),e.jsx("div",{className:"flat-map__grid",style:{gridTemplateColumns:`repeat(${V.gridCols}, 1fr)`},children:V.groups.length===0?e.jsx("div",{className:"flat-map__empty",children:e.jsx("span",{children:"No areas or agents yet"})}):V.groups.map(t=>{const a=t.area.id,l=V.positions.get(a);return e.jsxs("div",{className:"flat-map-area-card",style:{"--area-color":t.area.color,gridRow:l==null?void 0:l.row,gridColumn:l==null?void 0:l.col},children:[e.jsxs("button",{type:"button",className:"flat-map-area-card__header",onClick:()=>jt(a),title:`Focus ${t.area.name} in left panel`,children:[e.jsx("span",{className:"flat-map-area-card__color",style:{background:t.area.color}}),e.jsx("span",{className:"flat-map-area-card__name",children:t.area.name}),e.jsx("span",{className:"flat-map-area-card__count",children:t.agents.length})]}),e.jsx("div",{className:"flat-map-area-card__agents",children:t.agents.map(r=>{const j=r.isBoss||r.class==="boss",_=Rt(r),N=_.usedPercent>=80?"#ff4a4a":_.usedPercent>=60?"#ff9e4a":_.usedPercent>=40?"#ffd700":"#4aff9e",ke=`Context: ${(_.totalTokens/1e3).toFixed(1)}k / ${(_.contextWindow/1e3).toFixed(1)}k (${_.usedPercent}% used, ${_.freePercent}% free)`;return e.jsxs("button",{type:"button",className:`flat-map-agent-chip ${r.status}`,onClick:()=>m(r.id),onContextMenu:se=>{se.preventDefault(),se.stopPropagation(),ie({agentId:r.id,position:{x:se.clientX,y:se.clientY}})},title:`${j?"Boss · ":""}Open chat with ${r.name}
|
|
1
|
+
import{z as It,B as St,r as n,C as mt,S as x,E as ft,G as ct,H as ht,J as Ge,K as xe,L as Mt,s as b,M as bt,N as Et,v as yt,w as Tt,j as e,I as p,O as Pt,m as Rt,P as wt,U as Ct,V as Dt,W as zt,X as $t,Y as Lt,Z as Ot,_ as Ft,$ as Wt,a0 as Bt,a1 as Ht,a2 as Gt,a3 as Vt,a4 as Ut,a5 as Xt,a6 as qt,a7 as Kt,a8 as Yt,a9 as Zt,aa as Jt,ab as Qt,ac as ea,ad as ta,ae as aa,af as na,ag as sa}from"./main-BnUsuS5B.js";import"./vendor-react--Eh9ivFN.js";import"./vendor-three-Chj50gSY.js";const Ve=3,Ue=280,gt=320,ot=240,_t=64,la=["simple","chat","advanced"],ra={simple:"Simple",chat:"Chat",advanced:"Advanced"},ia={simple:"○",chat:"◐",advanced:"◉"},oa={simple:"Simple view — clean messages only",chat:"Chat view — assistant replies (no tool calls)",advanced:"Advanced view — everything including tools"},xt="flat-clear-context";function ca(m){const o=m.split("/").filter(Boolean);return o.length===0?m:o.slice(-2).join("/")}function da(m){if(m.provider==="codex"){const re=m.codexModel||"gpt-5.3-codex",k=aa[re];return{model:(k==null?void 0:k.label)||re}}if(m.provider==="opencode")return{model:m.opencodeModel||"opencode"};const o=m.model||"sonnet",C=sa[o],E=m.effort,T=E?na[E]:void 0;return{model:(C==null?void 0:C.label)||o,effort:T==null?void 0:T.label}}function pa(m,o){if(o.type==="rectangle"&&o.width&&o.height){const C=o.width/2,E=o.height/2;return m.x>=o.center.x-C&&m.x<=o.center.x+C&&m.z>=o.center.z-E&&m.z<=o.center.z+E}if(o.type==="circle"&&o.radius){const C=m.x-o.center.x,E=m.z-o.center.z;return C*C+E*E<=o.radius*o.radius}return!1}const ua=Bt.memo(function({agentId:o,terminalViewMode:C,onTerminalViewModeChange:E,inspectorOpen:T,onToggleInspector:re,onImageClick:k,onFileClick:be,onBashClick:we,onViewMarkdown:Ie,onRequestClearSubordinates:Se,onOpenBuilding:Ce,keyboard:je,canNavigateBack:Me,canNavigateForward:$,onNavigateBack:ie,onNavigateForward:oe,agentInfoOpen:U,onToggleAgentInfo:Xe}){var Le,Oe,ge,ve;const u=Ht(o),L=Gt(),X=n.useRef(null),Ee=n.useRef(null);n.useEffect(()=>{const s=Ee.current;if(!s)return;const c=i=>{i.button===3?(i.preventDefault(),i.stopPropagation(),ie()):i.button===4&&(i.preventDefault(),i.stopPropagation(),oe())},d=i=>{(i.button===3||i.button===4)&&i.preventDefault()};return s.addEventListener("mouseup",c),s.addEventListener("mousedown",d),()=>{s.removeEventListener("mouseup",c),s.removeEventListener("mousedown",d)}},[ie,oe]);const ce=bt(),de=n.useMemo(()=>{if(!u)return null;const s=new Set,c=[];for(const d of ce.values())d.archived||d.directories.length===0||d.assignedAgentIds.includes(o)&&(s.add(d.id),c.push(d));for(const d of ce.values())d.archived||d.directories.length===0||s.has(d.id)||pa({x:u.position.x,z:u.position.z},d)&&(s.add(d.id),c.push(d));return c.length===0?null:c.flatMap(d=>d.directories.filter(i=>i&&i.trim().length>0).map(i=>({areaId:d.id,areaName:d.name,dir:i})))},[u,o,ce]),{branches:q,fetchRemote:pe,fetchingDirs:ye}=Vt(de),ue=n.useMemo(()=>{var d;const s=b.getAreaForAgent(o);if(!s)return[];const c=[];for(const i of L.values())i.type==="terminal"&&b.isPositionInArea(i.position,s)&&c.push({id:i.id,name:i.name,hasUrl:!!((d=i.terminalStatus)!=null&&d.url)});return c},[o,L]),K=n.useMemo(()=>{var d;const s=b.getAreaForAgent(o);if(!s)return[];const c=[];for(const i of L.values())i.type==="server"&&((d=i.pm2)!=null&&d.enabled)&&b.isPositionInArea(i.position,s)&&c.push({id:i.id,name:i.name});return c},[o,L]),W=n.useMemo(()=>{const s=b.getAreaForAgent(o);if(!s)return[];const c=[];for(const d of L.values())d.type==="database"&&d.database&&b.isPositionInArea(d.position,s)&&c.push({id:d.id,name:d.name});return c},[o,L]),[,Y]=n.useReducer(s=>s+1,0),O=((Le=X.current)==null?void 0:Le.search.searchMode)??!1,P=n.useCallback(()=>{var s;(s=X.current)==null||s.search.toggleSearch(),Y()},[]),Z=Ut(),R=Z.isPending(xt),[M,me]=n.useState(null),B=M?L.get(M):null,{height:Te,onResizeStart:fe}=Xt(),[J,Pe]=n.useState(()=>ct(x.GIT_PANEL_OPEN,!1)),[y,Re]=n.useState(()=>ct(x.BUILDINGS_PANEL_OPEN,!1)),[H,De]=n.useState(!1),qe=n.useCallback(()=>{De(s=>{const c=!s;return c&&qt.setEnabled(!0),c})},[]),Ke=n.useCallback(()=>De(!1),[]),Ye=n.useCallback(()=>{Pe(s=>{const c=!s;return xe(x.GIT_PANEL_OPEN,c),c})},[]),Ze=n.useCallback(()=>{Re(s=>{const c=!s;return xe(x.BUILDINGS_PANEL_OPEN,c),c})},[]),Je=n.useCallback(()=>{Pe(!1),xe(x.GIT_PANEL_OPEN,!1)},[]),Qe=n.useCallback(()=>{Re(!1),xe(x.BUILDINGS_PANEL_OPEN,!1)},[]),et=Kt();n.useEffect(()=>{if(!M)return;ue.some(c=>c.id===M)||me(null)},[M,ue]);const[Q,f]=n.useState(!1),F=n.useRef(null);if(n.useEffect(()=>{if(!Q)return;const s=c=>{F.current&&!F.current.contains(c.target)&&f(!1)};return document.addEventListener("mousedown",s),()=>document.removeEventListener("mousedown",s)},[Q]),!u)return e.jsx("div",{className:"flat-chat flat-chat--empty",children:e.jsxs("div",{className:"flat-chat__placeholder",children:[e.jsx("span",{className:"flat-chat__placeholder-icon",children:"💬"}),e.jsx("span",{className:"flat-chat__placeholder-text",children:"Select an agent to start chatting"})]})});const A=u.contextStats,he=!!A,Ne=A?A.totalTokens:u.contextUsed||0,ze=A?A.contextWindow:u.contextLimit||2e5,tt=A?A.usedPercent:Math.round(Ne/ze*100),G=Math.max(0,Math.min(100,tt)),at=Math.max(0,100-G),ee=G>=80?"#ff4a4a":G>=60?"#ff9e4a":G>=40?"#ffd700":"#4aff9e",D=(Ne/1e3).toFixed(1),te=(ze/1e3).toFixed(1),ae=u.cwd,$e=ae?ca(ae):null,ne=((Oe=u.subordinateIds)==null?void 0:Oe.length)||0,nt=ne>0;return e.jsxs("div",{ref:Ee,className:`flat-terminal-wrapper ${J||y||H?"flat-terminal-wrapper--with-side-panel":""}`,children:[e.jsxs("div",{className:"flat-terminal-wrapper__header",children:[e.jsxs("button",{type:"button",className:`flat-terminal-wrapper__header-main ${U?"flat-terminal-wrapper__header-main--active":""}`,onClick:Xe,title:U?"Hide agent info":"Show agent info","aria-pressed":U,children:[e.jsx(wt,{agent:u,size:28}),e.jsxs("span",{className:"flat-terminal-wrapper__header-info",children:[e.jsx("span",{className:"flat-terminal-wrapper__header-name",children:u.name}),e.jsx("span",{className:"flat-terminal-wrapper__header-status",style:{color:Ct(u.status)},children:u.status})]}),u.taskLabel&&e.jsxs("span",{className:"flat-terminal-wrapper__header-task",title:u.taskLabel,children:["📋 ",u.taskLabel]}),e.jsxs("span",{className:"flat-terminal-wrapper__header-model",children:[e.jsx("img",{src:u.provider==="codex"?"/assets/codex.png":u.provider==="opencode"?"/assets/opencode.png":"/assets/claude.png",alt:u.provider,className:"flat-terminal-wrapper__header-provider-icon",title:u.provider==="codex"?"Codex Agent":u.provider==="opencode"?"OpenCode Agent":"Claude Agent"}),(()=>{const{model:s,effort:c}=da(u);return e.jsxs("span",{className:"flat-terminal-wrapper__header-model-chip",title:c?`Model: ${s} · Effort: ${c}`:`Model: ${s}`,children:[e.jsx("span",{className:"flat-terminal-wrapper__header-model-name",children:s}),c&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"flat-terminal-wrapper__header-model-sep","aria-hidden":"true",children:"·"}),e.jsx("span",{className:"flat-terminal-wrapper__header-model-effort",children:c})]})]})})()]})]}),e.jsxs("div",{className:"flat-terminal-wrapper__header-meta",children:[e.jsx("div",{className:"flat-terminal-wrapper__view-mode",role:"group","aria-label":"Message view mode",children:la.map(s=>e.jsxs("button",{type:"button",className:`flat-terminal-wrapper__view-mode-btn ${C===s?"flat-terminal-wrapper__view-mode-btn--active":""}`,onClick:()=>E(s),title:oa[s],"aria-pressed":C===s,children:[e.jsx("span",{className:"flat-terminal-wrapper__view-mode-icon","aria-hidden":"true",children:ia[s]}),e.jsx("span",{className:"flat-terminal-wrapper__view-mode-label",children:ra[s]})]},s))}),e.jsxs("div",{className:"flat-terminal-wrapper__actions",role:"group","aria-label":"Terminal actions",children:[e.jsx("button",{type:"button",className:"flat-terminal-wrapper__action-btn",onClick:ie,disabled:!Me,title:"Back to previous agent","aria-label":"Back to previous agent",children:e.jsx(p,{name:"arrow-left",size:14})}),e.jsx("button",{type:"button",className:"flat-terminal-wrapper__action-btn",onClick:oe,disabled:!$,title:"Forward to next agent","aria-label":"Forward to next agent",children:e.jsx(p,{name:"arrow-right",size:14})}),e.jsx("button",{type:"button",className:`flat-terminal-wrapper__action-btn ${O?"flat-terminal-wrapper__action-btn--active":""}`,onClick:P,title:O?"Close search":"Search messages","aria-pressed":O,children:e.jsx(p,{name:O?"cross":"search",size:14})}),e.jsx("button",{type:"button",className:`flat-terminal-wrapper__action-btn flat-terminal-wrapper__action-btn--danger ${R?"flat-terminal-wrapper__action-btn--confirm":""}`,onClick:()=>Z.handleClick(xt,()=>{var s;b.clearContext(o),(s=X.current)==null||s.historyLoader.clearHistory()}),title:R?"Click again to confirm clear context":"Clear context",children:e.jsx(p,{name:R?"question":"clear",size:14})}),e.jsx("button",{type:"button",className:`flat-terminal-wrapper__action-btn ${J?"flat-terminal-wrapper__action-btn--active":""}`,onClick:Ye,title:J?"Hide git panel":"Show git changes","aria-pressed":J,children:e.jsx(p,{name:"git-branch",size:14})}),e.jsx("button",{type:"button",className:`flat-terminal-wrapper__action-btn ${y?"flat-terminal-wrapper__action-btn--active":""}`,onClick:Ze,title:y?"Hide buildings panel":"Show area buildings","aria-pressed":y,children:e.jsx(p,{name:"buildings",size:14})}),e.jsxs("div",{className:"flat-terminal-wrapper__more",ref:F,children:[e.jsx("button",{type:"button",className:`flat-terminal-wrapper__action-btn ${Q?"flat-terminal-wrapper__action-btn--active":""}`,onClick:()=>f(s=>!s),title:"More actions","aria-expanded":Q,children:"⋮"}),Q&&e.jsxs("div",{className:"flat-terminal-wrapper__more-menu",role:"menu",children:[e.jsxs("button",{type:"button",role:"menuitem",className:`flat-terminal-wrapper__more-item ${H?"flat-terminal-wrapper__more-item--active":""}`,onClick:()=>{qe(),f(!1)},title:H?"Hide Debug Panel":"Show Debug Panel",children:[e.jsx(p,{name:"bug",size:14}),e.jsx("span",{children:H?"Hide Debug Panel":"Show Debug Panel"})]}),e.jsx("div",{className:"flat-terminal-wrapper__more-divider"}),e.jsxs("button",{type:"button",role:"menuitem",className:"flat-terminal-wrapper__more-item",onClick:()=>{b.collapseContext(o),f(!1)},disabled:u.status!=="idle",title:u.status!=="idle"?"Agent must be idle to collapse context":"Collapse context",children:[e.jsx(p,{name:"package",size:14}),e.jsx("span",{children:"Collapse context"})]}),nt&&e.jsxs("button",{type:"button",role:"menuitem",className:"flat-terminal-wrapper__more-item flat-terminal-wrapper__more-item--danger",onClick:()=>{Se(o,ne),f(!1)},children:[e.jsx(p,{name:"crown",size:14}),e.jsxs("span",{children:["Clear ",ne," subordinate",ne===1?"":"s"]})]}),e.jsx("div",{className:"flat-terminal-wrapper__more-divider"}),e.jsxs("button",{type:"button",role:"menuitem",className:"flat-terminal-wrapper__more-item flat-terminal-wrapper__more-item--danger",onClick:()=>{b.killAgent(o),f(!1)},children:[e.jsx(p,{name:"cross",size:14}),e.jsx("span",{children:"Remove agent"})]})]})]})]}),e.jsxs("button",{type:"button",className:`flat-terminal-wrapper__inspector-toggle ${T?"flat-terminal-wrapper__inspector-toggle--active":""}`,onClick:re,title:T?"Hide inspector panel":"Show inspector panel","aria-label":T?"Hide inspector panel":"Show inspector panel","aria-pressed":T,children:[e.jsx("span",{className:"flat-terminal-wrapper__inspector-icon","aria-hidden":"true",children:e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("rect",{x:"1.5",y:"2.5",width:"13",height:"11",rx:"1.5"}),e.jsx("line",{x1:"10",y1:"2.5",x2:"10",y2:"13.5"})]})}),e.jsx("span",{className:"flat-terminal-wrapper__inspector-label",children:"Inspector"})]}),e.jsx("button",{type:"button",className:"flat-terminal-wrapper__close",onClick:()=>b.deselectAll(),title:"Close chat","aria-label":"Close chat",children:e.jsx(p,{name:"cross",size:14})})]})]}),e.jsx(Yt,{ref:X,agentId:o,agent:u,viewMode:C,isOpen:!0,onImageClick:k,onFileClick:be,onBashClick:we,onViewMarkdown:Ie,keyboard:je,hasModalOpen:!1}),B&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"guake-bottom-terminal-resize",onMouseDown:fe,role:"separator","aria-orientation":"horizontal","aria-label":"Resize embedded terminal"}),e.jsxs("div",{className:"flat-bottom-panel",role:"region","aria-label":`Embedded terminal: ${B.name}`,style:{height:Te},children:[e.jsxs("div",{className:"flat-bottom-panel__header",children:[e.jsxs("span",{className:"flat-bottom-panel__title",children:[e.jsx(p,{name:"terminal",size:12}),e.jsx("span",{children:B.name}),!((ge=B.terminalStatus)!=null&&ge.url)&&e.jsx("span",{className:"flat-bottom-panel__muted",children:"(starting...)"})]}),e.jsx("button",{type:"button",className:"flat-bottom-panel__close",onClick:()=>me(null),title:"Close embedded terminal","aria-label":"Close embedded terminal",children:e.jsx(p,{name:"cross",size:12})})]}),e.jsx("div",{className:"flat-bottom-panel__body",children:(ve=B.terminalStatus)!=null&&ve.url?e.jsx(Zt,{terminalUrl:B.terminalStatus.url,visible:!0}):e.jsx("div",{className:"flat-bottom-panel__placeholder",children:"Starting terminal..."})})]})]}),e.jsxs("div",{className:"flat-terminal-wrapper__statusbar",role:"contentinfo",children:[u.isDetached&&e.jsxs("span",{className:"flat-terminal-wrapper__detached",title:"Reattaching session...",children:[e.jsx(p,{name:"refresh",size:12}),e.jsx("span",{children:"Reattaching"})]}),ae&&$e&&e.jsxs("span",{className:"flat-terminal-wrapper__cwd",title:ae,onClick:()=>b.setFileViewerPath(ae),children:[e.jsx("span",{className:"flat-terminal-wrapper__cwd-icon",children:e.jsx(p,{name:"folder",size:12})}),e.jsx("span",{className:"flat-terminal-wrapper__cwd-text",children:$e})]}),de&&de.map(({areaId:s,areaName:c,dir:d})=>{const i=q.get(d),Fe=ye.has(d),V=d.split("/").filter(Boolean).pop()||d;return e.jsxs("span",{className:"flat-terminal-wrapper__area-dir",title:`${c}: ${d}${i?` (${i.branch}${i.ahead?` ↑${i.ahead}`:""}${i.behind?` ↓${i.behind}`:""})`:""}`,onClick:()=>b.openFileExplorerForAreaFolder(s,d),children:[e.jsx(p,{name:"folder-open",size:12}),e.jsx("span",{className:"flat-terminal-wrapper__area-dir-name",children:V}),i&&e.jsxs(e.Fragment,{children:[e.jsxs("span",{className:"flat-terminal-wrapper__area-dir-branch",children:[e.jsx(p,{name:"git-branch",size:10})," ",i.branch]}),i.ahead>0&&e.jsxs("span",{className:"flat-terminal-wrapper__branch-ahead",title:`${i.ahead} ahead`,children:[e.jsx(p,{name:"arrow-up",size:9}),i.ahead]}),i.behind>0&&e.jsxs("span",{className:"flat-terminal-wrapper__branch-behind",title:`${i.behind} behind`,children:[e.jsx(p,{name:"arrow-down",size:9}),i.behind]}),e.jsx("span",{className:`flat-terminal-wrapper__area-fetch ${Fe?"flat-terminal-wrapper__area-fetch--fetching":""}`,title:"Git fetch",onClick:st=>{st.stopPropagation(),pe(d)},children:e.jsx(p,{name:Fe?"hourglass":"download",size:12})})]})]},`${s}:${d}`)}),e.jsxs("span",{className:"flat-terminal-wrapper__context",onClick:()=>b.setContextModalAgentId(o),title:he?`Context usage: ${D}k / ${te}k tokens (${G}% used). Click to view stats.`:"Click to fetch context stats",children:[e.jsx("span",{className:"flat-terminal-wrapper__context-icon",children:e.jsx(p,{name:"dashboard",size:12})}),e.jsx("span",{className:"flat-terminal-wrapper__context-label",children:"Ctx:"}),e.jsx("span",{className:"flat-terminal-wrapper__context-bar",children:e.jsx("span",{className:"flat-terminal-wrapper__context-bar-fill",style:{width:`${G}%`,backgroundColor:ee}})}),e.jsxs("span",{className:"flat-terminal-wrapper__context-tokens",style:{color:ee},children:[D,"k/",te,"k"]}),e.jsxs("span",{className:"flat-terminal-wrapper__context-free",children:["(",at,"% free)"]}),!he&&e.jsx("span",{className:"flat-terminal-wrapper__context-warning",title:"No context stats yet",children:e.jsx(p,{name:"warn",size:12})})]}),e.jsx("div",{className:"flat-terminal-wrapper__statusbar-spacer","aria-hidden":"true"}),ue.length>0&&e.jsx("span",{className:"flat-terminal-wrapper__buildings",role:"group","aria-label":"Area terminals",children:ue.map(s=>{const c=M===s.id;return e.jsx("button",{type:"button",className:`flat-terminal-wrapper__building-btn ${c?"flat-terminal-wrapper__building-btn--active":""} ${s.hasUrl?"":"flat-terminal-wrapper__building-btn--offline"}`,title:`${c?"Hide":"Show"} terminal: ${s.name}${s.hasUrl?"":" (starting...)"}`,onClick:()=>{if(c){me(null);return}s.hasUrl||b.sendBuildingCommand(s.id,"start"),me(s.id)},children:e.jsx(p,{name:"terminal",size:14})},s.id)})}),K.length>0&&e.jsx("span",{className:"flat-terminal-wrapper__buildings",role:"group","aria-label":"Area PM2 logs",children:K.map(s=>e.jsx("button",{type:"button",className:"flat-terminal-wrapper__building-btn",title:`Open logs: ${s.name}`,onClick:()=>Ce(s.id),children:e.jsx(p,{name:"scroll",size:14})},s.id))}),W.length>0&&e.jsx("span",{className:"flat-terminal-wrapper__buildings",role:"group","aria-label":"Area databases",children:W.map(s=>e.jsx("button",{type:"button",className:"flat-terminal-wrapper__building-btn",title:`Open database: ${s.name}`,onClick:()=>Ce(s.id),children:e.jsx(p,{name:"hard-drives",size:14})},s.id))}),e.jsx("div",{className:"flat-terminal-wrapper__theme",children:e.jsx(Jt,{})})]}),J&&e.jsx(Qt,{agentId:o,agents:et,onClose:Je,branchInfoMap:q,fetchRemote:pe,fetchingDirs:ye}),y&&e.jsx(ea,{agentId:o,onClose:Qe}),H&&e.jsx(ta,{agentId:o,onClose:Ke})]})});function ga({onAgentClick:m,onBuildingClick:o,onBuildingDoubleClick:C,onOpenSpawnModal:E,onOpenBossSpawnModal:T,onOpenAreaModal:re}){const k=It(),be=St(),[we,Ie]=n.useState(null),[Se,Ce]=n.useState(null),[je,Me]=n.useState(null),[$,ie]=n.useState(null),[oe,U]=n.useState(!1),Xe=n.useCallback(()=>{U(t=>!t)},[]),u=n.useCallback(()=>{U(!1)},[]),[L,X]=n.useState(()=>{const t=mt(x.VIEW_MODE);return t==="simple"||t==="chat"||t==="advanced"?t:"simple"}),Ee=n.useCallback(t=>{X(t),ft(x.VIEW_MODE,t)},[]);n.useEffect(()=>{const t=a=>{if(a.key!==x.VIEW_MODE)return;const l=a.newValue;(l==="simple"||l==="chat"||l==="advanced")&&X(l)};return window.addEventListener("storage",t),()=>window.removeEventListener("storage",t)},[]);const[ce,de]=n.useState(()=>ct(x.FLAT_INSPECTOR_OPEN,!1)),[q,pe]=n.useState(!1),ye=n.useCallback(()=>pe(t=>!t),[]),ue=n.useCallback(()=>pe(!1),[]),K=n.useRef(null),W=n.useRef(null),[Y,O]=n.useState(()=>{const t=ht(x.FLAT_MIDDLE_WIDTH,0);return t>=Ue?t:null}),[P,Z]=n.useState(()=>{const t=ht(x.FLAT_INSPECTOR_WIDTH,0);return t>=ot?t:null}),R=n.useCallback(t=>{if(typeof window>"u")return t;const a=P!==null?Ve+P:0,l=window.innerWidth-_t-Ve-gt-a;return Math.max(Ue,Math.min(Math.max(l,Ue),t))},[P]),M=n.useCallback(t=>{var j;if(typeof window>"u")return t;const a=(j=K.current)==null?void 0:j.querySelector(".flat-middle"),l=(a==null?void 0:a.getBoundingClientRect().width)??Ue,r=window.innerWidth-_t-l-Ve-gt-Ve;return Math.max(ot,Math.min(Math.max(r,ot),t))},[]);n.useEffect(()=>{if(Y===null&&P===null)return;const t=()=>{O(a=>{if(a===null)return a;const l=R(a);return l===a?a:l}),Z(a=>{if(a===null)return a;const l=M(a);return l===a?a:l})};return window.addEventListener("resize",t),()=>window.removeEventListener("resize",t)},[Y,P,R,M]);const me=n.useCallback(t=>{var l;if(t.button!==0)return;const a=(l=K.current)==null?void 0:l.querySelector(".flat-middle");a&&(t.currentTarget.setPointerCapture(t.pointerId),W.current={kind:"middle",startX:t.clientX,startWidth:a.getBoundingClientRect().width,pointerId:t.pointerId},document.body.classList.add("flat-splitter-dragging"))},[]),B=n.useCallback(t=>{var l;if(t.button!==0)return;const a=(l=K.current)==null?void 0:l.querySelector(".flat-inspector");a&&(t.currentTarget.setPointerCapture(t.pointerId),W.current={kind:"inspector",startX:t.clientX,startWidth:a.getBoundingClientRect().width,pointerId:t.pointerId},document.body.classList.add("flat-splitter-dragging"))},[]),Te=n.useCallback(t=>{const a=W.current;if(!a||t.pointerId!==a.pointerId)return;const l=t.clientX-a.startX;a.kind==="middle"?O(R(a.startWidth+l)):Z(M(a.startWidth-l))},[R,M]),fe=n.useCallback(t=>{const a=W.current;if(!a||t.pointerId!==a.pointerId)return;try{t.currentTarget.releasePointerCapture(t.pointerId)}catch{}if(W.current=null,document.body.classList.remove("flat-splitter-dragging"),!(Math.abs(t.clientX-a.startX)>2))return;const r=t.clientX-a.startX;if(a.kind==="middle"){const j=R(a.startWidth+r);O(j),Ge(x.FLAT_MIDDLE_WIDTH,j)}else{const j=M(a.startWidth-r);Z(j),Ge(x.FLAT_INSPECTOR_WIDTH,j)}},[R,M]),J=n.useCallback(()=>{O(null),Ge(x.FLAT_MIDDLE_WIDTH,0)},[]),Pe=n.useCallback(()=>{Z(null),Ge(x.FLAT_INSPECTOR_WIDTH,0)},[]),[y,Re]=n.useState(()=>mt(x.FLAT_INSPECTOR_VIEW)==="tracking"?"tracking":"agent"),H=n.useCallback(t=>{Re(t),ft(x.FLAT_INSPECTOR_VIEW,t)},[]),De=n.useCallback(()=>{de(t=>{const a=!t;return xe(x.FLAT_INSPECTOR_OPEN,a),a})},[]),qe=n.useCallback(()=>{de(!1),xe(x.FLAT_INSPECTOR_OPEN,!1)},[]),Ke=Mt(),Ye=n.useCallback((t,a)=>{Ie({url:t,name:a})},[]),Ze=n.useCallback((t,a)=>{Ce({command:t,output:a,isLive:!1})},[]),Je=n.useCallback((t,a)=>{b.setFileViewerPath(t,a)},[]),Qe=n.useCallback(t=>{},[]),et=n.useCallback((t,a)=>{Me({agentId:t,count:a})},[]),Q=n.useCallback(t=>{C?C(t):o(t)},[o,C]),f=n.useMemo(()=>be.size>0?Array.from(be)[0]:null,[be]);n.useEffect(()=>{U(!1)},[f]);const F=n.useRef([]),A=n.useRef(-1),he=n.useRef(!1),Ne=n.useRef(null),[ze,tt]=n.useState(!1),[G,at]=n.useState(!1),ee=n.useMemo(()=>new Set(k.map(t=>t.id)),[k]),D=n.useCallback(()=>{const t=F.current,a=A.current;tt(a>0),at(a>=0&&a<t.length-1)},[]),te=n.useCallback(t=>{const a=F.current;if(a.length===0)return;let l=A.current+t;for(;l>=0&&l<a.length;){const r=a[l];if(ee.has(r)){he.current=!0,A.current=l,D(),b.selectAgent(r);return}l+=t}},[ee,D]),ae=n.useCallback(()=>te(-1),[te]),$e=n.useCallback(()=>te(1),[te]);n.useEffect(()=>{if(!f){F.current=[],A.current=-1,D();return}if(Ne.current=f,he.current){he.current=!1,D();return}const t=F.current,a=A.current;if(a>=0&&t[a]===f){D();return}const l=a<t.length-1?t.slice(0,a+1):t.slice();l.push(f),l.length>100&&l.shift(),F.current=l,A.current=l.length-1,D()},[f,D]);const ne=n.useCallback(t=>{m(t),pe(!1)},[m]),nt=f??"",Le=n.useCallback(()=>{},[]),Oe=n.useCallback(t=>{ne(t)},[ne]),ge=ce,ve=n.useRef(null);n.useEffect(()=>{if(f)return;const t=a=>{if(a.key!==" "&&a.key!=="Backspace")return;const l=a.target;if(l.tagName==="INPUT"||l.tagName==="TEXTAREA"||l.isContentEditable)return;const r=Ne.current;!r||!ee.has(r)||(a.preventDefault(),b.selectAgent(r))};return document.addEventListener("keydown",t),()=>document.removeEventListener("keydown",t)},[f,ee]);const[s,c]=n.useState(new Set),d=n.useCallback(t=>{c(a=>{const l=new Set(a);return l.has(t)?l.delete(t):l.add(t),l})},[]),i=bt(),[Fe]=Et(),V=n.useMemo(()=>{const t=new Map,a=[];for(const g of k){const w=b.getAreaForAgent(g.id);if(!yt((w==null?void 0:w.id)??null))continue;if(!w||w.archived){a.push(g);continue}const z=t.get(w.id);z?z.push(g):t.set(w.id,[g])}const l=[];for(const[,g]of i){if(g.archived||!Tt(g.id))continue;const w=t.get(g.id);w&&w.length>0&&l.push({area:g,agents:w})}a.length>0&&l.push({area:{id:"__unassigned__",name:"Unassigned",color:"#6272a4",center:{x:0,z:0},type:"circle",radius:0,directories:[],archived:!1,assignedAgentIds:[],zIndex:0},agents:a});const r=l.filter(g=>g.area.id!=="__unassigned__"),j=l.filter(g=>g.area.id==="__unassigned__");let _=1,N=1;const ke=new Map;if(r.length>1){let g=1/0,w=-1/0,z=1/0,_e=-1/0;for(const I of r)g=Math.min(g,I.area.center.x),w=Math.max(w,I.area.center.x),z=Math.min(z,I.area.center.z),_e=Math.max(_e,I.area.center.z);const We=w-g||1,Be=_e-z||1;if(r.length<=4){_=r.length,N=1;const I=[...r].sort((S,lt)=>S.area.center.x-lt.area.center.x);for(let S=0;S<I.length;S++)ke.set(I[S].area.id,{row:1,col:S+1})}else{const I=[...r].sort((h,v)=>h.area.center.x-v.area.center.x),S=[];for(let h=1;h<I.length;h++)S.push(I[h].area.center.x-I[h-1].area.center.x);const lt=S.reduce((h,v)=>h+v,0)/S.length||1;let dt=1;for(const h of S)h>lt*1.3&&dt++;_=Math.max(2,Math.min(dt,r.length));const rt=[...r].sort((h,v)=>h.area.center.z-v.area.center.z),He=[];for(let h=1;h<rt.length;h++)He.push(rt[h].area.center.z-rt[h-1].area.center.z);const Nt=He.reduce((h,v)=>h+v,0)/He.length||1;let pt=1;for(const h of He)h>Nt*1.3&&pt++;N=Math.max(2,Math.min(pt,r.length)),_=Math.max(_,Math.ceil(r.length/N)),N=Math.max(N,Math.ceil(r.length/_));const vt=We/_,kt=Be/N,it=new Set;for(const h of r){let v=Math.min(_-1,Math.max(0,Math.floor((h.area.center.x-g)/vt))),le=Math.min(N-1,Math.max(0,Math.floor((h.area.center.z-z)/kt))),Ae=`${le},${v}`,ut=0;const At=N*_;for(;it.has(Ae)&&ut<At;)v++,v>=_&&(v=0,le=(le+1)%N),Ae=`${le},${v}`,ut++;it.has(Ae)&&(le=N,v=0,Ae=`${le},${v}`,N++),it.add(Ae),ke.set(h.area.id,{row:le+1,col:v+1})}}}const se=g=>{g.sort((w,z)=>{var We,Be,I,S;const _e=(((We=w.position)==null?void 0:We.z)??0)-(((Be=z.position)==null?void 0:Be.z)??0);return _e!==0?_e:(((I=w.position)==null?void 0:I.x)??0)-(((S=z.position)==null?void 0:S.x)??0)})};for(const g of r)se(g.agents);for(const g of j)se(g.agents);return{groups:[...r,...j],gridCols:_,gridRows:N,positions:ke}},[k,i,Fe]),st=n.useMemo(()=>{if(!$)return[];const t=k.find(a=>a.id===$.agentId);return t?[{id:"edit-agent",label:"Edit Agent",icon:e.jsx(p,{name:"edit",size:14}),onClick:()=>{window.dispatchEvent(new CustomEvent("tide:open-agent-edit",{detail:{agentId:t.id}}))}},{id:"open-chat",label:"Open Chat",icon:e.jsx(p,{name:"chat",size:14}),onClick:()=>m(t.id)},{id:"delete-agent",label:"Delete Agent",icon:e.jsx(p,{name:"trash",size:14}),danger:!0,onClick:()=>{window.confirm(`Remove ${t.name} from view?`)&&b.removeAgentFromServer(t.id)}}]:[]},[$,k,m]),jt=n.useCallback(t=>{const a=new Set(V.groups.map(l=>l.area.id));a.delete(t),c(a),requestAnimationFrame(()=>{const l=ve.current;if(!l)return;const r=l.querySelector(`[data-area-id="${t}"]`);if(!r)return;const j=l.getBoundingClientRect(),N=r.getBoundingClientRect().top-j.top+l.scrollTop-8;l.scrollTo({top:Math.max(0,N),behavior:"smooth"})})},[V]);return e.jsxs("div",{ref:K,className:`flat-view ${ge?"flat-view--with-inspector":""} ${f?"flat-view--has-chat":""} ${q?"flat-view--mobile-sidebar-open":""}`,style:(()=>{if(Y===null&&P===null)return;const t={};return Y!==null&&(t["--flat-middle-width"]=`${Y}px`),P!==null&&(t["--flat-inspector-width"]=`${P}px`),t})(),children:[q&&e.jsx("div",{className:"flat-mobile-sidebar-backdrop",onClick:ue,"aria-hidden":"true"}),e.jsxs("div",{className:"flat-middle",children:[e.jsxs("div",{className:"flat-middle__header",children:[e.jsx("h2",{className:"flat-middle__title",children:"👥 Agents"}),e.jsxs("div",{className:"flat-middle__actions",children:[e.jsx("button",{className:"flat-cta-btn flat-cta-btn--agent",onClick:E,title:"Create new agent",children:"+ Agent"}),e.jsx("button",{className:"flat-cta-btn flat-cta-btn--boss",onClick:T,title:"Create new boss agent",children:"+ Boss"}),e.jsx("button",{className:"flat-cta-btn flat-cta-btn--area",onClick:re,title:"Create new area",children:"+ Area"})]})]}),e.jsx("div",{className:"flat-middle__content",children:e.jsx(Pt,{activeAgentId:nt,onClose:Le,onSelectAgent:Oe,collapsedAreas:s,onToggleArea:d,agentListRef:ve})})]}),e.jsx("div",{className:"flat-splitter flat-splitter--middle",role:"separator","aria-orientation":"vertical","aria-label":"Resize agents panel",title:"Drag to resize · Double-click to reset",onPointerDown:me,onPointerMove:Te,onPointerUp:fe,onPointerCancel:fe,onDoubleClick:J}),e.jsxs("div",{className:"flat-right",children:[e.jsxs("button",{type:"button",className:"flat-mobile-sidebar-toggle","aria-label":q?"Close agents sidebar":"Open agents sidebar","aria-expanded":q,onClick:ye,children:[e.jsx(p,{name:"list",size:18}),e.jsx("span",{className:"flat-mobile-sidebar-toggle__label",children:"Agents"})]}),f?e.jsx(ua,{agentId:f,terminalViewMode:L,onTerminalViewModeChange:Ee,inspectorOpen:ce,onToggleInspector:De,onImageClick:Ye,onFileClick:Je,onBashClick:Ze,onViewMarkdown:Qe,onRequestClearSubordinates:et,onOpenBuilding:Q,keyboard:Ke,canNavigateBack:ze,canNavigateForward:G,onNavigateBack:ae,onNavigateForward:$e,agentInfoOpen:oe,onToggleAgentInfo:Xe}):e.jsx("div",{className:"flat-chat flat-chat--empty",children:e.jsxs("div",{className:"flat-map",children:[e.jsxs("div",{className:"flat-map__header",children:[e.jsx("span",{className:"flat-map__title",children:"🗺️ Areas"}),e.jsx("span",{className:"flat-map__hint",children:"Click an area to focus it, or an agent to chat"})]}),e.jsx("div",{className:"flat-map__grid",style:{gridTemplateColumns:`repeat(${V.gridCols}, 1fr)`},children:V.groups.length===0?e.jsx("div",{className:"flat-map__empty",children:e.jsx("span",{children:"No areas or agents yet"})}):V.groups.map(t=>{const a=t.area.id,l=V.positions.get(a);return e.jsxs("div",{className:"flat-map-area-card",style:{"--area-color":t.area.color,gridRow:l==null?void 0:l.row,gridColumn:l==null?void 0:l.col},children:[e.jsxs("button",{type:"button",className:"flat-map-area-card__header",onClick:()=>jt(a),title:`Focus ${t.area.name} in left panel`,children:[e.jsx("span",{className:"flat-map-area-card__color",style:{background:t.area.color}}),e.jsx("span",{className:"flat-map-area-card__name",children:t.area.name}),e.jsx("span",{className:"flat-map-area-card__count",children:t.agents.length})]}),e.jsx("div",{className:"flat-map-area-card__agents",children:t.agents.map(r=>{const j=r.isBoss||r.class==="boss",_=Rt(r),N=_.usedPercent>=80?"#ff4a4a":_.usedPercent>=60?"#ff9e4a":_.usedPercent>=40?"#ffd700":"#4aff9e",ke=`Context: ${(_.totalTokens/1e3).toFixed(1)}k / ${(_.contextWindow/1e3).toFixed(1)}k (${_.usedPercent}% used, ${_.freePercent}% free)`;return e.jsxs("button",{type:"button",className:`flat-map-agent-chip ${r.status}`,onClick:()=>m(r.id),onContextMenu:se=>{se.preventDefault(),se.stopPropagation(),ie({agentId:r.id,position:{x:se.clientX,y:se.clientY}})},title:`${j?"Boss · ":""}Open chat with ${r.name}
|
|
2
2
|
${ke}`,children:[e.jsx(wt,{agent:r,size:16}),j&&e.jsx("span",{className:"flat-map-agent-chip__crown","aria-hidden":"true",children:e.jsx(p,{name:"crown",size:11,color:"#ffd700",weight:"fill"})}),e.jsx("span",{className:"flat-map-agent-chip__name",children:r.name}),e.jsx("img",{src:r.provider==="codex"?"/assets/codex.png":r.provider==="opencode"?"/assets/opencode.png":"/assets/claude.png",alt:r.provider,className:"flat-map-agent-chip__provider-icon",title:r.provider==="codex"?"Codex Agent":r.provider==="opencode"?"OpenCode Agent":"Claude Agent"}),e.jsx("span",{className:"flat-map-agent-chip__dot",style:{backgroundColor:Ct(r.status)}}),e.jsx("span",{className:"flat-map-agent-chip__context-bar","aria-hidden":"true",children:e.jsx("span",{className:"flat-map-agent-chip__context-bar-fill",style:{width:`${_.usedPercent}%`,backgroundColor:N}})})]},r.id)})})]},a)})})]})})]}),ge&&e.jsx("div",{className:"flat-splitter flat-splitter--inspector",role:"separator","aria-orientation":"vertical","aria-label":"Resize inspector panel",title:"Drag to resize · Double-click to reset",onPointerDown:B,onPointerMove:Te,onPointerUp:fe,onPointerCancel:fe,onDoubleClick:Pe}),ge&&e.jsxs("aside",{className:"flat-inspector","aria-label":"Inspector panel",children:[e.jsxs("div",{className:"flat-inspector__header",children:[e.jsxs("div",{className:"flat-inspector__tabs",role:"tablist","aria-label":"Inspector view",children:[e.jsx("button",{type:"button",role:"tab","aria-selected":y==="agent",className:`flat-inspector__tab ${y==="agent"?"flat-inspector__tab--active":""}`,onClick:()=>H("agent"),children:"Agent"}),e.jsx("button",{type:"button",role:"tab","aria-selected":y==="tracking",className:`flat-inspector__tab ${y==="tracking"?"flat-inspector__tab--active":""}`,onClick:()=>H("tracking"),children:"Tracking"})]}),e.jsx("button",{type:"button",className:"flat-inspector__close",onClick:qe,title:"Close inspector","aria-label":"Close inspector",children:"✕"})]}),e.jsx("div",{className:"flat-inspector__body",children:y==="tracking"?e.jsx(Dt,{activeAgentId:f??"",onSelectAgent:t=>m(t)}):(()=>{if(!f)return e.jsx("div",{className:"flat-inspector__empty",children:e.jsx("span",{children:"Select an agent to inspect"})});const t=k.find(a=>a.id===f);return t?e.jsx(zt,{agent:t,onFocusAgent:a=>m(a),onKillAgent:a=>b.killAgent(a)}):e.jsx("div",{className:"flat-inspector__empty",children:e.jsx("span",{children:"Agent not found"})})})()})]}),we&&e.jsx($t,{url:we.url,name:we.name,onClose:()=>Ie(null)}),Se&&e.jsx(Lt,{state:Se,onClose:()=>Ce(null)}),je&&e.jsx(Ot,{action:"clear-subordinates",selectedAgentId:je.agentId,subordinateCount:je.count,onClose:()=>Me(null),onClearHistory:()=>{}}),e.jsx(Ft,{agent:f?k.find(t=>t.id===f)??null:null,isOpen:oe&&!!f,onClose:u}),e.jsx(Wt,{isOpen:$!==null,position:($==null?void 0:$.position)??{x:0,y:0},worldPosition:{x:0,z:0},actions:st,onClose:()=>ie(null)})]})}export{ga as FlatView};
|