tide-commander 1.84.3 → 1.84.4

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.
Files changed (36) hide show
  1. package/dist/assets/{BossLogsModal-AChwUNMW.js → BossLogsModal-RKUS5he3.js} +1 -1
  2. package/dist/assets/{BossSpawnModal-CD-7tjgm.js → BossSpawnModal-Z-KIzG1l.js} +1 -1
  3. package/dist/assets/{ControlsModal-CH-Q4q3O.js → ControlsModal-sWKF7juv.js} +1 -1
  4. package/dist/assets/{DockerLogsModal-BLDQ616U.js → DockerLogsModal-Chv6wO7i.js} +1 -1
  5. package/dist/assets/{EmbeddedEditor-LAmZJWtP.js → EmbeddedEditor-BnJunhJ5.js} +1 -1
  6. package/dist/assets/{GmailOAuthSetup-C22bjUss.js → GmailOAuthSetup-CD24tWFR.js} +1 -1
  7. package/dist/assets/{GoogleOAuthSetup-CWXUVT3D.js → GoogleOAuthSetup-D7lmU7_z.js} +1 -1
  8. package/dist/assets/{IframeModal-CKRhuKkv.js → IframeModal-B7M2Iclq.js} +1 -1
  9. package/dist/assets/{IntegrationsPanel-_mQKdqyz.js → IntegrationsPanel-BXniP3m6.js} +2 -2
  10. package/dist/assets/{LogViewerModal-BidPtpLY.js → LogViewerModal-BkbO5Lcx.js} +1 -1
  11. package/dist/assets/{MonitoringModal-BAEO1sSK.js → MonitoringModal-BLwOrxXn.js} +1 -1
  12. package/dist/assets/{PM2LogsModal-CSnd5VTs.js → PM2LogsModal-Cc5muLh8.js} +1 -1
  13. package/dist/assets/{RestoreArchivedAreaModal-CosgdjEy.js → RestoreArchivedAreaModal-C2kLOEom.js} +1 -1
  14. package/dist/assets/{Scene2DCanvas-uDyUWA_h.js → Scene2DCanvas-B_ILFcMh.js} +1 -1
  15. package/dist/assets/{SceneManager-CqX9oyfB.js → SceneManager-C24V9ffc.js} +1 -1
  16. package/dist/assets/{SkillsPanel-BSuHxISi.js → SkillsPanel-B7M9i9GP.js} +1 -1
  17. package/dist/assets/{SpawnModal-C3dwTSV0.js → SpawnModal-C47v5dNY.js} +1 -1
  18. package/dist/assets/{SubordinateAssignmentModal-RZJUO92_.js → SubordinateAssignmentModal-KRP5mXby.js} +1 -1
  19. package/dist/assets/{TriggerManagerPanel-DEkOU2da.js → TriggerManagerPanel-CLmwH7fs.js} +1 -1
  20. package/dist/assets/{WorkflowEditorPanel-C43Kawid.js → WorkflowEditorPanel-CFubZORK.js} +1 -1
  21. package/dist/assets/{index-CUgMzqD-.js → index-5oP0HT38.js} +3 -3
  22. package/dist/assets/{index-BCPAV-9V.js → index-7TgA90RK.js} +1 -1
  23. package/dist/assets/{index-BkwJ2ByJ.js → index-BEc3pZNf.js} +1 -1
  24. package/dist/assets/{index-DMhivE9i.js → index-C0L5LEWi.js} +1 -1
  25. package/dist/assets/{index-DLn-MFiJ.js → index-CO5NGvTa.js} +1 -1
  26. package/dist/assets/{index-BQgCNQRi.css → index-CmE9RJAK.css} +1 -1
  27. package/dist/assets/index-CztWNLcY.js +2 -0
  28. package/dist/assets/{index-Djj0po5C.js → index-D3lbWfGO.js} +2 -2
  29. package/dist/assets/{index-CMOZpYNj.js → index-D94lnP2P.js} +1 -1
  30. package/dist/assets/{index-BKFJ5pOR.js → index-DQVaH0CS.js} +1 -1
  31. package/dist/assets/{main-BxStxFko.js → main-DFVcOIIz.js} +4 -4
  32. package/dist/assets/{web-dETXjReH.js → web-BRpVSwLu.js} +1 -1
  33. package/dist/assets/{web-COTfP2Su.js → web-DskROW-O.js} +1 -1
  34. package/dist/index.html +1 -1
  35. package/package.json +1 -1
  36. package/dist/assets/index-DYBLXfaK.js +0 -2
@@ -1 +1 @@
1
- import{ci as a}from"./main-BxStxFko.js";import{ImpactStyle as i,NotificationType as r}from"./index-Djj0po5C.js";import"./vendor-react--Eh9ivFN.js";import"./vendor-three-Chj50gSY.js";class h extends a{constructor(){super(...arguments),this.selectionStarted=!1}async impact(t){const e=this.patternForImpact(t==null?void 0:t.style);this.vibrateWithPattern(e)}async notification(t){const e=this.patternForNotification(t==null?void 0:t.type);this.vibrateWithPattern(e)}async vibrate(t){const e=(t==null?void 0:t.duration)||300;this.vibrateWithPattern([e])}async selectionStart(){this.selectionStarted=!0}async selectionChanged(){this.selectionStarted&&this.vibrateWithPattern([70])}async selectionEnd(){this.selectionStarted=!1}patternForImpact(t=i.Heavy){return t===i.Medium?[43]:t===i.Light?[20]:[61]}patternForNotification(t=r.Success){return t===r.Warning?[30,40,30,50,60]:t===r.Error?[27,45,50]:[35,65,21]}vibrateWithPattern(t){if(navigator.vibrate)navigator.vibrate(t);else throw this.unavailable("Browser does not support the vibrate API")}}export{h as HapticsWeb};
1
+ import{ci as a}from"./main-DFVcOIIz.js";import{ImpactStyle as i,NotificationType as r}from"./index-D3lbWfGO.js";import"./vendor-react--Eh9ivFN.js";import"./vendor-three-Chj50gSY.js";class h extends a{constructor(){super(...arguments),this.selectionStarted=!1}async impact(t){const e=this.patternForImpact(t==null?void 0:t.style);this.vibrateWithPattern(e)}async notification(t){const e=this.patternForNotification(t==null?void 0:t.type);this.vibrateWithPattern(e)}async vibrate(t){const e=(t==null?void 0:t.duration)||300;this.vibrateWithPattern([e])}async selectionStart(){this.selectionStarted=!0}async selectionChanged(){this.selectionStarted&&this.vibrateWithPattern([70])}async selectionEnd(){this.selectionStarted=!1}patternForImpact(t=i.Heavy){return t===i.Medium?[43]:t===i.Light?[20]:[61]}patternForNotification(t=r.Success){return t===r.Warning?[30,40,30,50,60]:t===r.Error?[27,45,50]:[35,65,21]}vibrateWithPattern(t){if(navigator.vibrate)navigator.vibrate(t);else throw this.unavailable("Browser does not support the vibrate API")}}export{h as HapticsWeb};
@@ -1 +1 @@
1
- import{ci as s}from"./main-BxStxFko.js";import"./vendor-react--Eh9ivFN.js";import"./vendor-three-Chj50gSY.js";class l extends s{constructor(){super(...arguments),this.pending=[],this.deliveredNotifications=[],this.hasNotificationSupport=()=>{if(!("Notification"in window)||!Notification.requestPermission)return!1;if(Notification.permission!=="granted")try{new Notification("")}catch(i){if(i instanceof Error&&i.name==="TypeError")return!1}return!0}}async getDeliveredNotifications(){const i=[];for(const t of this.deliveredNotifications){const e={title:t.title,id:parseInt(t.tag),body:t.body};i.push(e)}return{notifications:i}}async removeDeliveredNotifications(i){for(const t of i.notifications){const e=this.deliveredNotifications.find(n=>n.tag===String(t.id));e==null||e.close(),this.deliveredNotifications=this.deliveredNotifications.filter(()=>!e)}}async removeAllDeliveredNotifications(){for(const i of this.deliveredNotifications)i.close();this.deliveredNotifications=[]}async createChannel(){throw this.unimplemented("Not implemented on web.")}async deleteChannel(){throw this.unimplemented("Not implemented on web.")}async listChannels(){throw this.unimplemented("Not implemented on web.")}async schedule(i){if(!this.hasNotificationSupport())throw this.unavailable("Notifications not supported in this browser.");for(const t of i.notifications)this.sendNotification(t);return{notifications:i.notifications.map(t=>({id:t.id}))}}async getPending(){return{notifications:this.pending}}async registerActionTypes(){throw this.unimplemented("Not implemented on web.")}async cancel(i){this.pending=this.pending.filter(t=>!i.notifications.find(e=>e.id===t.id))}async areEnabled(){const{display:i}=await this.checkPermissions();return{value:i==="granted"}}async changeExactNotificationSetting(){throw this.unimplemented("Not implemented on web.")}async checkExactNotificationSetting(){throw this.unimplemented("Not implemented on web.")}async requestPermissions(){if(!this.hasNotificationSupport())throw this.unavailable("Notifications not supported in this browser.");return{display:this.transformNotificationPermission(await Notification.requestPermission())}}async checkPermissions(){if(!this.hasNotificationSupport())throw this.unavailable("Notifications not supported in this browser.");return{display:this.transformNotificationPermission(Notification.permission)}}transformNotificationPermission(i){switch(i){case"granted":return"granted";case"denied":return"denied";default:return"prompt"}}sendPending(){var i;const t=[],e=new Date().getTime();for(const n of this.pending)!((i=n.schedule)===null||i===void 0)&&i.at&&n.schedule.at.getTime()<=e&&(this.buildNotification(n),t.push(n));this.pending=this.pending.filter(n=>!t.find(o=>o===n))}sendNotification(i){var t;if(!((t=i.schedule)===null||t===void 0)&&t.at){const e=i.schedule.at.getTime()-new Date().getTime();this.pending.push(i),setTimeout(()=>{this.sendPending()},e);return}this.buildNotification(i)}buildNotification(i){const t=new Notification(i.title,{body:i.body,tag:String(i.id)});return t.addEventListener("click",this.onClick.bind(this,i),!1),t.addEventListener("show",this.onShow.bind(this,i),!1),t.addEventListener("close",()=>{this.deliveredNotifications=this.deliveredNotifications.filter(()=>!this)},!1),this.deliveredNotifications.push(t),t}onClick(i){const t={actionId:"tap",notification:i};this.notifyListeners("localNotificationActionPerformed",t)}onShow(i){this.notifyListeners("localNotificationReceived",i)}}export{l as LocalNotificationsWeb};
1
+ import{ci as s}from"./main-DFVcOIIz.js";import"./vendor-react--Eh9ivFN.js";import"./vendor-three-Chj50gSY.js";class l extends s{constructor(){super(...arguments),this.pending=[],this.deliveredNotifications=[],this.hasNotificationSupport=()=>{if(!("Notification"in window)||!Notification.requestPermission)return!1;if(Notification.permission!=="granted")try{new Notification("")}catch(i){if(i instanceof Error&&i.name==="TypeError")return!1}return!0}}async getDeliveredNotifications(){const i=[];for(const t of this.deliveredNotifications){const e={title:t.title,id:parseInt(t.tag),body:t.body};i.push(e)}return{notifications:i}}async removeDeliveredNotifications(i){for(const t of i.notifications){const e=this.deliveredNotifications.find(n=>n.tag===String(t.id));e==null||e.close(),this.deliveredNotifications=this.deliveredNotifications.filter(()=>!e)}}async removeAllDeliveredNotifications(){for(const i of this.deliveredNotifications)i.close();this.deliveredNotifications=[]}async createChannel(){throw this.unimplemented("Not implemented on web.")}async deleteChannel(){throw this.unimplemented("Not implemented on web.")}async listChannels(){throw this.unimplemented("Not implemented on web.")}async schedule(i){if(!this.hasNotificationSupport())throw this.unavailable("Notifications not supported in this browser.");for(const t of i.notifications)this.sendNotification(t);return{notifications:i.notifications.map(t=>({id:t.id}))}}async getPending(){return{notifications:this.pending}}async registerActionTypes(){throw this.unimplemented("Not implemented on web.")}async cancel(i){this.pending=this.pending.filter(t=>!i.notifications.find(e=>e.id===t.id))}async areEnabled(){const{display:i}=await this.checkPermissions();return{value:i==="granted"}}async changeExactNotificationSetting(){throw this.unimplemented("Not implemented on web.")}async checkExactNotificationSetting(){throw this.unimplemented("Not implemented on web.")}async requestPermissions(){if(!this.hasNotificationSupport())throw this.unavailable("Notifications not supported in this browser.");return{display:this.transformNotificationPermission(await Notification.requestPermission())}}async checkPermissions(){if(!this.hasNotificationSupport())throw this.unavailable("Notifications not supported in this browser.");return{display:this.transformNotificationPermission(Notification.permission)}}transformNotificationPermission(i){switch(i){case"granted":return"granted";case"denied":return"denied";default:return"prompt"}}sendPending(){var i;const t=[],e=new Date().getTime();for(const n of this.pending)!((i=n.schedule)===null||i===void 0)&&i.at&&n.schedule.at.getTime()<=e&&(this.buildNotification(n),t.push(n));this.pending=this.pending.filter(n=>!t.find(o=>o===n))}sendNotification(i){var t;if(!((t=i.schedule)===null||t===void 0)&&t.at){const e=i.schedule.at.getTime()-new Date().getTime();this.pending.push(i),setTimeout(()=>{this.sendPending()},e);return}this.buildNotification(i)}buildNotification(i){const t=new Notification(i.title,{body:i.body,tag:String(i.id)});return t.addEventListener("click",this.onClick.bind(this,i),!1),t.addEventListener("show",this.onShow.bind(this,i),!1),t.addEventListener("close",()=>{this.deliveredNotifications=this.deliveredNotifications.filter(()=>!this)},!1),this.deliveredNotifications.push(t),t}onClick(i){const t={actionId:"tap",notification:i};this.notifyListeners("localNotificationActionPerformed",t)}onShow(i){this.notifyListeners("localNotificationReceived",i)}}export{l as LocalNotificationsWeb};
package/dist/index.html CHANGED
@@ -22,7 +22,7 @@
22
22
  <link rel="icon" type="image/png" sizes="16x16" href="/assets/icons/favicon-16x16.png" />
23
23
  <link rel="apple-touch-icon" sizes="180x180" href="/assets/icons/apple-touch-icon.png" />
24
24
  <title>Tide Commander</title>
25
- <script type="module" crossorigin src="/assets/main-BxStxFko.js"></script>
25
+ <script type="module" crossorigin src="/assets/main-DFVcOIIz.js"></script>
26
26
  <link rel="modulepreload" crossorigin href="/assets/vendor-react--Eh9ivFN.js">
27
27
  <link rel="modulepreload" crossorigin href="/assets/vendor-three-Chj50gSY.js">
28
28
  <link rel="stylesheet" crossorigin href="/assets/main-CFu_SP_0.css">
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tide-commander",
3
- "version": "1.84.3",
3
+ "version": "1.84.4",
4
4
  "description": "Visual multi-agent orchestrator and manager for Claude Code with 3D/2D interface",
5
5
  "repository": {
6
6
  "type": "git",
@@ -1,2 +0,0 @@
1
- import{r as a,u as zt,z as Zt,j as e,V as Jt,B as Qt,E as en,G as It,S as v,H as At,J as wt,K as St,L as lt,M as ne,N as tn,s as f,O as Dt,P as Ot,U as nn,v as Et,w as Mt,I as u,W as an,m as sn,X as ln,Y as $t,Z as Bt,_ as rn,$ as on,a0 as cn,a1 as dn,a2 as un,a3 as pn,a4 as mn,a5 as fn,a6 as hn,a7 as gn,a8 as Tt,C as xn,a9 as bn,aa as _n,ab as wn,ac as Cn,ad as vn,ae as jn,af as Nn,ag as kn,ah as yn,ai as In,aj as An,ak as Sn,al as En,am as Mn,an as Tn,ao as Pn}from"./main-BxStxFko.js";import"./vendor-react--Eh9ivFN.js";import"./vendor-three-Chj50gSY.js";const Ln=a.memo(function({className:c=""}){const{t:N}=zt(["common"]),[y,E]=Zt(),q=a.useRef(null),[F,ae]=a.useState(null);a.useLayoutEffect(()=>{const C=q.current;if(!C)return;const K=C.querySelector(".view-mode-toggle__btn--active");K&&ae({left:K.offsetLeft,width:K.offsetWidth})},[y]);const S=a.useCallback(C=>{if(C!==y){if(typeof window<"u"&&window.dispatchEvent(new CustomEvent("tide:viewmode-switch-pressed",{detail:{mode:C}})),C==="3d"){requestAnimationFrame(()=>E(C));return}E(C)}},[y,E]);return e.jsxs("div",{className:`view-mode-toggle ${c}`,ref:q,children:[F&&e.jsx("div",{className:"view-mode-toggle__indicator",style:{left:F.left,width:F.width}}),Jt.map(C=>e.jsxs("button",{className:`view-mode-toggle__btn ${y===C?"view-mode-toggle__btn--active":""}`,onClick:()=>S(C),title:N(`common:viewMode.descriptions.${C}`),children:[e.jsxs("span",{className:"view-mode-toggle__icon",children:[C==="2d"&&e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[e.jsx("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2"}),e.jsx("line",{x1:"3",y1:"12",x2:"21",y2:"12"}),e.jsx("line",{x1:"12",y1:"3",x2:"12",y2:"21"})]}),C==="3d"&&e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[e.jsx("path",{d:"M12 2L2 7l10 5 10-5-10-5z"}),e.jsx("path",{d:"M2 17l10 5 10-5"}),e.jsx("path",{d:"M2 12l10 5 10-5"})]}),C==="flat"&&e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[e.jsx("rect",{x:"3",y:"3",width:"8",height:"8",rx:"1"}),e.jsx("rect",{x:"13",y:"3",width:"8",height:"8",rx:"1"}),e.jsx("rect",{x:"3",y:"13",width:"8",height:"8",rx:"1"}),e.jsx("rect",{x:"13",y:"13",width:"8",height:"8",rx:"1"})]}),C==="dashboard"&&e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[e.jsx("rect",{x:"3",y:"3",width:"7",height:"9",rx:"1"}),e.jsx("rect",{x:"14",y:"3",width:"7",height:"5",rx:"1"}),e.jsx("rect",{x:"14",y:"12",width:"7",height:"9",rx:"1"}),e.jsx("rect",{x:"3",y:"16",width:"7",height:"5",rx:"1"})]})]}),e.jsx("span",{className:"view-mode-toggle__label",children:N(`common:viewMode.labels.${C}`)})]},C))]})}),it=3,rt=280,Pt=320,_t=240,Lt=64,Rn=["simple","chat","advanced"],zn={simple:"Simple",chat:"Chat",advanced:"Advanced"},Dn={simple:"○",chat:"◐",advanced:"◉"},On={simple:"Simple view — clean messages only",chat:"Chat view — assistant replies (no tool calls)",advanced:"Advanced view — everything including tools"},Rt="flat-clear-context";function $n(_){const c=_.split("/").filter(Boolean);return c.length===0?_:c.slice(-2).join("/")}function Bn(_){if(_.provider==="codex"){const q=_.codexModel||"gpt-5.3-codex",F=Mn[q];return{model:(F==null?void 0:F.label)||q}}if(_.provider==="opencode")return{model:_.opencodeModel||"opencode"};const c=_.model||"sonnet",N=Pn[c],y=_.effort,E=y?Tn[y]:void 0;return{model:(N==null?void 0:N.label)||c,effort:E==null?void 0:E.label}}function Fn(_,c){if(c.type==="rectangle"&&c.width&&c.height){const N=c.width/2,y=c.height/2;return _.x>=c.center.x-N&&_.x<=c.center.x+N&&_.z>=c.center.z-y&&_.z<=c.center.z+y}if(c.type==="circle"&&c.radius){const N=_.x-c.center.x,y=_.z-c.center.z;return N*N+y*y<=c.radius*c.radius}return!1}const Wn=bn.memo(function({agentId:c,terminalViewMode:N,onTerminalViewModeChange:y,inspectorOpen:E,onToggleInspector:q,onImageClick:F,onFileClick:ae,onBashClick:S,onViewMarkdown:C,onRequestClearSubordinates:K,onOpenBuilding:Te,keyboard:We,canNavigateBack:He,canNavigateForward:Pe,onNavigateBack:se,onNavigateForward:z,agentInfoOpen:Ne,onToggleAgentInfo:Y}){var de,Se,ee,Qe;const h=_n(c),M=Ot(),pe=a.useRef(null),ke=a.useRef(null);a.useEffect(()=>{const l=ke.current;if(!l)return;const r=o=>{o.button===3?(o.preventDefault(),o.stopPropagation(),se()):o.button===4&&(o.preventDefault(),o.stopPropagation(),z())},d=o=>{(o.button===3||o.button===4)&&o.preventDefault()};return l.addEventListener("mouseup",r),l.addEventListener("mousedown",d),()=>{l.removeEventListener("mouseup",r),l.removeEventListener("mousedown",d)}},[se,z]),a.useEffect(()=>{const l=ke.current;if(!l)return;let r=0,d=0,o=0;const ue=250,Ce=600,Ee=80,mt=1.5,ft=T=>{let I=T instanceof HTMLElement?T:null;for(;I&&I!==l;){const et=window.getComputedStyle(I).overflowX;if((et==="auto"||et==="scroll")&&I.scrollWidth>I.clientWidth)return!0;I=I.parentElement}return!1},V=T=>{const I=Date.now();if(I<o){T.preventDefault();return}if(Math.abs(T.deltaX)<=Math.abs(T.deltaY)*mt){r=0;return}if(ft(T.target)){r=0;return}I-d>ue&&(r=0),d=I,r+=T.deltaX,r<=-Ee?(r=0,o=I+Ce,T.preventDefault(),se()):r>=Ee&&(r=0,o=I+Ce,T.preventDefault(),z())};return l.addEventListener("wheel",V,{passive:!1}),()=>l.removeEventListener("wheel",V)},[se,z]);const me=Dt(),Le=a.useMemo(()=>{if(!h)return null;const l=new Set,r=[];for(const d of me.values())d.archived||d.directories.length===0||d.assignedAgentIds.includes(c)&&(l.add(d.id),r.push(d));for(const d of me.values())d.archived||d.directories.length===0||l.has(d.id)||Fn({x:h.position.x,z:h.position.z},d)&&(l.add(d.id),r.push(d));return r.length===0?null:r.flatMap(d=>d.directories.filter(o=>o&&o.trim().length>0).map(o=>({areaId:d.id,areaName:d.name,dir:o})))},[h,c,me]),{branches:Ve,fetchRemote:Ge,fetchingDirs:Re}=wn(Le),ye=a.useMemo(()=>{var d;const l=f.getAreaForAgent(c);if(!l)return[];const r=[];for(const o of M.values())o.type==="terminal"&&f.isPositionInArea(o.position,l)&&r.push({id:o.id,name:o.name,hasUrl:!!((d=o.terminalStatus)!=null&&d.url)});return r},[c,M]),fe=a.useMemo(()=>{var d;const l=f.getAreaForAgent(c);if(!l)return[];const r=[];for(const o of M.values())o.type==="server"&&((d=o.pm2)!=null&&d.enabled)&&f.isPositionInArea(o.position,l)&&r.push({id:o.id,name:o.name});return r},[c,M]),le=a.useMemo(()=>{const l=f.getAreaForAgent(c);if(!l)return[];const r=[];for(const d of M.values())d.type==="database"&&d.database&&f.isPositionInArea(d.position,l)&&r.push({id:d.id,name:d.name});return r},[c,M]),[,ie]=a.useReducer(l=>l+1,0),W=((de=pe.current)==null?void 0:de.search.searchMode)??!1,ot=a.useCallback(()=>{var l;(l=pe.current)==null||l.search.toggleSearch(),ie()},[]),Xe=Cn(),re=Xe.isPending(Rt),[O,G]=a.useState(null),H=O?M.get(O):null,{height:X,onResizeStart:Ie}=vn(),[$,Z]=a.useState(()=>wt(v.GIT_PANEL_OPEN,!1)),[he,Ue]=a.useState(()=>wt(v.BUILDINGS_PANEL_OPEN,!1)),[oe,ge]=a.useState(!1),ct=a.useCallback(()=>{ge(l=>{const r=!l;return r&&jn.setEnabled(!0),r})},[]),dt=a.useCallback(()=>ge(!1),[]),xe=a.useCallback(()=>{Z(l=>{const r=!l;return ne(v.GIT_PANEL_OPEN,r),r})},[]),ut=a.useCallback(()=>{Ue(l=>{const r=!l;return ne(v.BUILDINGS_PANEL_OPEN,r),r})},[]),qe=a.useCallback(()=>{Z(!1),ne(v.GIT_PANEL_OPEN,!1)},[]),pt=a.useCallback(()=>{Ue(!1),ne(v.BUILDINGS_PANEL_OPEN,!1)},[]),ze=Nn();a.useEffect(()=>{if(!O)return;ye.some(r=>r.id===O)||G(null)},[O,ye]);const[be,ce]=a.useState(!1),De=a.useRef(null);if(a.useEffect(()=>{if(!be)return;const l=r=>{De.current&&!De.current.contains(r.target)&&ce(!1)};return document.addEventListener("mousedown",l),()=>document.removeEventListener("mousedown",l)},[be]),!h)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 J=h.contextStats,Ke=!!J,Ye=J?J.totalTokens:h.contextUsed||0,_e=J?J.contextWindow:h.contextLimit||2e5,g=J?J.usedPercent:Math.round(Ye/_e*100),D=Math.max(0,Math.min(100,g)),U=Math.max(0,100-D),we=D>=80?"#ff4a4a":D>=60?"#ff9e4a":D>=40?"#ffd700":"#4aff9e",Oe=(Ye/1e3).toFixed(1),Ze=(_e/1e3).toFixed(1),Q=h.cwd,Je=Q?$n(Q):null,Ae=((Se=h.subordinateIds)==null?void 0:Se.length)||0,$e=Ae>0;return e.jsxs("div",{ref:ke,className:`flat-terminal-wrapper ${$||he||oe?"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 ${Ne?"flat-terminal-wrapper__header-main--active":""}`,onClick:Y,title:Ne?"Hide agent info":"Show agent info","aria-pressed":Ne,children:[e.jsx($t,{agent:h,size:28}),e.jsxs("span",{className:"flat-terminal-wrapper__header-info",children:[e.jsx("span",{className:"flat-terminal-wrapper__header-name",children:h.name}),e.jsx("span",{className:"flat-terminal-wrapper__header-status",style:{color:Bt(h.status)},children:h.status})]}),h.taskLabel&&e.jsxs("span",{className:"flat-terminal-wrapper__header-task",title:h.taskLabel,children:["📋 ",h.taskLabel]}),e.jsxs("span",{className:"flat-terminal-wrapper__header-model",children:[e.jsx("img",{src:h.provider==="codex"?"/assets/codex.png":h.provider==="opencode"?"/assets/opencode.png":"/assets/claude.png",alt:h.provider,className:"flat-terminal-wrapper__header-provider-icon",title:h.provider==="codex"?"Codex Agent":h.provider==="opencode"?"OpenCode Agent":"Claude Agent"}),(()=>{const{model:l,effort:r}=Bn(h);return e.jsxs("span",{className:"flat-terminal-wrapper__header-model-chip",title:r?`Model: ${l} · Effort: ${r}`:`Model: ${l}`,children:[e.jsx("span",{className:"flat-terminal-wrapper__header-model-name",children:l}),r&&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:r})]})]})})()]})]}),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:Rn.map(l=>e.jsxs("button",{type:"button",className:`flat-terminal-wrapper__view-mode-btn ${N===l?"flat-terminal-wrapper__view-mode-btn--active":""}`,onClick:()=>y(l),title:On[l],"aria-pressed":N===l,children:[e.jsx("span",{className:"flat-terminal-wrapper__view-mode-icon","aria-hidden":"true",children:Dn[l]}),e.jsx("span",{className:"flat-terminal-wrapper__view-mode-label",children:zn[l]})]},l))}),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:se,disabled:!He,title:"Back to previous agent","aria-label":"Back to previous agent",children:e.jsx(u,{name:"arrow-left",size:14})}),e.jsx("button",{type:"button",className:"flat-terminal-wrapper__action-btn",onClick:z,disabled:!Pe,title:"Forward to next agent","aria-label":"Forward to next agent",children:e.jsx(u,{name:"arrow-right",size:14})}),e.jsx("button",{type:"button",className:`flat-terminal-wrapper__action-btn ${W?"flat-terminal-wrapper__action-btn--active":""}`,onClick:ot,title:W?"Close search":"Search messages","aria-pressed":W,children:e.jsx(u,{name:W?"cross":"search",size:14})}),e.jsx("button",{type:"button",className:`flat-terminal-wrapper__action-btn flat-terminal-wrapper__action-btn--danger ${re?"flat-terminal-wrapper__action-btn--confirm":""}`,onClick:()=>Xe.handleClick(Rt,()=>{var l;f.clearContext(c),(l=pe.current)==null||l.historyLoader.clearHistory()}),title:re?"Click again to confirm clear context":"Clear context",children:e.jsx(u,{name:re?"question":"clear",size:14})}),e.jsx("button",{type:"button",className:`flat-terminal-wrapper__action-btn ${$?"flat-terminal-wrapper__action-btn--active":""}`,onClick:xe,title:$?"Hide git panel":"Show git changes","aria-pressed":$,children:e.jsx(u,{name:"git-branch",size:14})}),e.jsx("button",{type:"button",className:`flat-terminal-wrapper__action-btn ${he?"flat-terminal-wrapper__action-btn--active":""}`,onClick:ut,title:he?"Hide buildings panel":"Show area buildings","aria-pressed":he,children:e.jsx(u,{name:"buildings",size:14})}),e.jsxs("div",{className:"flat-terminal-wrapper__more",ref:De,children:[e.jsx("button",{type:"button",className:`flat-terminal-wrapper__action-btn ${be?"flat-terminal-wrapper__action-btn--active":""}`,onClick:()=>ce(l=>!l),title:"More actions","aria-expanded":be,children:"⋮"}),be&&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 ${oe?"flat-terminal-wrapper__more-item--active":""}`,onClick:()=>{ct(),ce(!1)},title:oe?"Hide Debug Panel":"Show Debug Panel",children:[e.jsx(u,{name:"bug",size:14}),e.jsx("span",{children:oe?"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:()=>{f.collapseContext(c),ce(!1)},disabled:h.status!=="idle",title:h.status!=="idle"?"Agent must be idle to collapse context":"Collapse context",children:[e.jsx(u,{name:"package",size:14}),e.jsx("span",{children:"Collapse context"})]}),$e&&e.jsxs("button",{type:"button",role:"menuitem",className:"flat-terminal-wrapper__more-item flat-terminal-wrapper__more-item--danger",onClick:()=>{K(c,Ae),ce(!1)},children:[e.jsx(u,{name:"crown",size:14}),e.jsxs("span",{children:["Clear ",Ae," subordinate",Ae===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:()=>{f.killAgent(c),ce(!1)},children:[e.jsx(u,{name:"cross",size:14}),e.jsx("span",{children:"Remove agent"})]})]})]})]}),e.jsxs("button",{type:"button",className:`flat-terminal-wrapper__inspector-toggle ${E?"flat-terminal-wrapper__inspector-toggle--active":""}`,onClick:q,title:E?"Hide inspector panel":"Show inspector panel","aria-label":E?"Hide inspector panel":"Show inspector panel","aria-pressed":E,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:()=>f.deselectAll(),title:"Close chat","aria-label":"Close chat",children:e.jsx(u,{name:"cross",size:14})})]})]}),e.jsx(kn,{ref:pe,agentId:c,agent:h,viewMode:N,isOpen:!0,onImageClick:F,onFileClick:ae,onBashClick:S,onViewMarkdown:C,keyboard:We,hasModalOpen:!1}),H&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"guake-bottom-terminal-resize",onMouseDown:Ie,role:"separator","aria-orientation":"horizontal","aria-label":"Resize embedded terminal"}),e.jsxs("div",{className:"flat-bottom-panel",role:"region","aria-label":`Embedded terminal: ${H.name}`,style:{height:X},children:[e.jsxs("div",{className:"flat-bottom-panel__header",children:[e.jsxs("span",{className:"flat-bottom-panel__title",children:[e.jsx(u,{name:"terminal",size:12}),e.jsx("span",{children:H.name}),!((ee=H.terminalStatus)!=null&&ee.url)&&e.jsx("span",{className:"flat-bottom-panel__muted",children:"(starting...)"})]}),e.jsx("button",{type:"button",className:"flat-bottom-panel__close",onClick:()=>G(null),title:"Close embedded terminal","aria-label":"Close embedded terminal",children:e.jsx(u,{name:"cross",size:12})})]}),e.jsx("div",{className:"flat-bottom-panel__body",children:(Qe=H.terminalStatus)!=null&&Qe.url?e.jsx(yn,{terminalUrl:H.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:[h.isDetached&&e.jsxs("span",{className:"flat-terminal-wrapper__detached",title:"Reattaching session...",children:[e.jsx(u,{name:"refresh",size:12}),e.jsx("span",{children:"Reattaching"})]}),Q&&Je&&e.jsxs("span",{className:"flat-terminal-wrapper__cwd",title:`Open in file explorer: ${Q}`,"aria-label":`Open ${Q} in file explorer`,role:"button",tabIndex:0,onClick:()=>f.openFileExplorer(Q),onKeyDown:l=>{(l.key==="Enter"||l.key===" ")&&(l.preventDefault(),f.openFileExplorer(Q))},children:[e.jsx("span",{className:"flat-terminal-wrapper__cwd-icon",children:e.jsx(u,{name:"folder",size:12})}),e.jsx("span",{className:"flat-terminal-wrapper__cwd-text",children:Je})]}),Le&&Le.map(({areaId:l,areaName:r,dir:d})=>{const o=Ve.get(d),ue=Re.has(d),Ce=d.split("/").filter(Boolean).pop()||d;return e.jsxs("span",{className:"flat-terminal-wrapper__area-dir",title:`${r}: ${d}${o?` (${o.branch}${o.ahead?` ↑${o.ahead}`:""}${o.behind?` ↓${o.behind}`:""})`:""}`,onClick:()=>f.openFileExplorerForAreaFolder(l,d),children:[e.jsx(u,{name:"folder-open",size:12}),e.jsx("span",{className:"flat-terminal-wrapper__area-dir-name",children:Ce}),o&&e.jsxs(e.Fragment,{children:[e.jsxs("span",{className:"flat-terminal-wrapper__area-dir-branch",children:[e.jsx(u,{name:"git-branch",size:10})," ",o.branch]}),o.ahead>0&&e.jsxs("span",{className:"flat-terminal-wrapper__branch-ahead",title:`${o.ahead} ahead`,children:[e.jsx(u,{name:"arrow-up",size:9}),o.ahead]}),o.behind>0&&e.jsxs("span",{className:"flat-terminal-wrapper__branch-behind",title:`${o.behind} behind`,children:[e.jsx(u,{name:"arrow-down",size:9}),o.behind]}),e.jsx("span",{className:`flat-terminal-wrapper__area-fetch ${ue?"flat-terminal-wrapper__area-fetch--fetching":""}`,title:"Git fetch",onClick:Ee=>{Ee.stopPropagation(),Ge(d)},children:e.jsx(u,{name:ue?"hourglass":"download",size:12})})]})]},`${l}:${d}`)}),e.jsxs("span",{className:"flat-terminal-wrapper__context",onClick:()=>f.setContextModalAgentId(c),title:Ke?`Context usage: ${Oe}k / ${Ze}k tokens (${D}% used). Click to view stats.`:"Click to fetch context stats",children:[e.jsx("span",{className:"flat-terminal-wrapper__context-icon",children:e.jsx(u,{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:`${D}%`,backgroundColor:we}})}),e.jsxs("span",{className:"flat-terminal-wrapper__context-tokens",style:{color:we},children:[Oe,"k/",Ze,"k"]}),e.jsxs("span",{className:"flat-terminal-wrapper__context-free",children:["(",U,"% free)"]}),!Ke&&e.jsx("span",{className:"flat-terminal-wrapper__context-warning",title:"No context stats yet",children:e.jsx(u,{name:"warn",size:12})})]}),e.jsx("div",{className:"flat-terminal-wrapper__statusbar-spacer","aria-hidden":"true"}),ye.length>0&&e.jsx("span",{className:"flat-terminal-wrapper__buildings",role:"group","aria-label":"Area terminals",children:ye.map(l=>{const r=O===l.id;return e.jsx("button",{type:"button",className:`flat-terminal-wrapper__building-btn ${r?"flat-terminal-wrapper__building-btn--active":""} ${l.hasUrl?"":"flat-terminal-wrapper__building-btn--offline"}`,title:`${r?"Hide":"Show"} terminal: ${l.name}${l.hasUrl?"":" (starting...)"}`,onClick:()=>{if(r){G(null);return}l.hasUrl||f.sendBuildingCommand(l.id,"start"),G(l.id)},children:e.jsx(u,{name:"terminal",size:14})},l.id)})}),fe.length>0&&e.jsx("span",{className:"flat-terminal-wrapper__buildings",role:"group","aria-label":"Area PM2 logs",children:fe.map(l=>e.jsx("button",{type:"button",className:"flat-terminal-wrapper__building-btn",title:`Open logs: ${l.name}`,onClick:()=>Te(l.id),children:e.jsx(u,{name:"scroll",size:14})},l.id))}),le.length>0&&e.jsx("span",{className:"flat-terminal-wrapper__buildings",role:"group","aria-label":"Area databases",children:le.map(l=>e.jsx("button",{type:"button",className:"flat-terminal-wrapper__building-btn",title:`Open database: ${l.name}`,onClick:()=>Te(l.id),children:e.jsx(u,{name:"hard-drives",size:14})},l.id))}),e.jsx("div",{className:"flat-terminal-wrapper__theme",children:e.jsx(In,{})})]}),$&&e.jsx(An,{agentId:c,agents:ze,onClose:qe,branchInfoMap:Ve,fetchRemote:Ge,fetchingDirs:Re}),he&&e.jsx(Sn,{agentId:c,onClose:pt}),oe&&e.jsx(En,{agentId:c,onClose:dt})]})});function Xn({onAgentClick:_,onBuildingClick:c,onBuildingDoubleClick:N,onBuildingPopup:y,onOpenSpawnModal:E,onOpenBossSpawnModal:q,onOpenAreaModal:F}){const{t:ae}=zt(["common"]),S=Qt(),C=en(),[K,Te]=a.useState(null),[We,He]=a.useState(null),[Pe,se]=a.useState(null),[z,Ne]=a.useState(null),[Y,h]=a.useState(null),[M,pe]=a.useState(null),[ke,me]=a.useState(!1),Le=a.useCallback(()=>{me(t=>!t)},[]),Ve=a.useCallback(()=>{me(!1)},[]),[Ge,Re]=a.useState(()=>{const t=It(v.VIEW_MODE);return t==="simple"||t==="chat"||t==="advanced"?t:"simple"}),ye=a.useCallback(t=>{Re(t),At(v.VIEW_MODE,t)},[]);a.useEffect(()=>{const t=n=>{if(n.key!==v.VIEW_MODE)return;const s=n.newValue;(s==="simple"||s==="chat"||s==="advanced")&&Re(s)};return window.addEventListener("storage",t),()=>window.removeEventListener("storage",t)},[]);const[fe,le]=a.useState(()=>wt(v.FLAT_INSPECTOR_OPEN,!1)),[ie,W]=a.useState(!1),ot=a.useCallback(()=>W(t=>!t),[]),Xe=a.useCallback(()=>W(!1),[]);a.useEffect(()=>{window.dispatchEvent(new CustomEvent("tide-flat-agents-drawer-state",{detail:{open:ie}}))},[ie]),a.useEffect(()=>{window.dispatchEvent(new CustomEvent("tide-flat-inspector-state",{detail:{open:fe}}))},[fe]),a.useEffect(()=>{const t=()=>W(m=>!m),n=()=>{le(m=>{const b=!m;return ne(v.FLAT_INSPECTOR_OPEN,b),b})},s=()=>{W(!1),le(!1),ne(v.FLAT_INSPECTOR_OPEN,!1)},i=()=>W(!1),p=()=>{le(!1),ne(v.FLAT_INSPECTOR_OPEN,!1)};return window.addEventListener("tide-toggle-flat-agents-drawer",t),window.addEventListener("tide-toggle-flat-inspector",n),window.addEventListener("tide-close-flat-side-views",s),window.addEventListener("tide-close-flat-agents-drawer-only",i),window.addEventListener("tide-close-flat-inspector-only",p),()=>{window.removeEventListener("tide-toggle-flat-agents-drawer",t),window.removeEventListener("tide-toggle-flat-inspector",n),window.removeEventListener("tide-close-flat-side-views",s),window.removeEventListener("tide-close-flat-agents-drawer-only",i),window.removeEventListener("tide-close-flat-inspector-only",p)}},[]);const re=a.useRef(null),O=a.useRef(null),[G,H]=a.useState(()=>{const t=St(v.FLAT_MIDDLE_WIDTH,0);return t>=rt?t:null}),[X,Ie]=a.useState(()=>{const t=St(v.FLAT_INSPECTOR_WIDTH,0);return t>=_t?t:null}),$=a.useCallback(t=>{if(typeof window>"u")return t;const n=X!==null?it+X:0,s=window.innerWidth-Lt-it-Pt-n;return Math.max(rt,Math.min(Math.max(s,rt),t))},[X]),Z=a.useCallback(t=>{var p;if(typeof window>"u")return t;const n=(p=re.current)==null?void 0:p.querySelector(".flat-middle"),s=(n==null?void 0:n.getBoundingClientRect().width)??rt,i=window.innerWidth-Lt-s-it-Pt-it;return Math.max(_t,Math.min(Math.max(i,_t),t))},[]);a.useEffect(()=>{if(G===null&&X===null)return;const t=()=>{H(n=>{if(n===null)return n;const s=$(n);return s===n?n:s}),Ie(n=>{if(n===null)return n;const s=Z(n);return s===n?n:s})};return window.addEventListener("resize",t),()=>window.removeEventListener("resize",t)},[G,X,$,Z]);const he=a.useCallback(t=>{var s;if(t.button!==0)return;const n=(s=re.current)==null?void 0:s.querySelector(".flat-middle");n&&(t.currentTarget.setPointerCapture(t.pointerId),O.current={kind:"middle",startX:t.clientX,startWidth:n.getBoundingClientRect().width,pointerId:t.pointerId},document.body.classList.add("flat-splitter-dragging"))},[]),Ue=a.useCallback(t=>{var s;if(t.button!==0)return;const n=(s=re.current)==null?void 0:s.querySelector(".flat-inspector");n&&(t.currentTarget.setPointerCapture(t.pointerId),O.current={kind:"inspector",startX:t.clientX,startWidth:n.getBoundingClientRect().width,pointerId:t.pointerId},document.body.classList.add("flat-splitter-dragging"))},[]),oe=a.useCallback(t=>{const n=O.current;if(!n||t.pointerId!==n.pointerId)return;const s=t.clientX-n.startX;n.kind==="middle"?H($(n.startWidth+s)):Ie(Z(n.startWidth-s))},[$,Z]),ge=a.useCallback(t=>{const n=O.current;if(!n||t.pointerId!==n.pointerId)return;try{t.currentTarget.releasePointerCapture(t.pointerId)}catch{}if(O.current=null,document.body.classList.remove("flat-splitter-dragging"),!(Math.abs(t.clientX-n.startX)>2))return;const i=t.clientX-n.startX;if(n.kind==="middle"){const p=$(n.startWidth+i);H(p),lt(v.FLAT_MIDDLE_WIDTH,p)}else{const p=Z(n.startWidth-i);Ie(p),lt(v.FLAT_INSPECTOR_WIDTH,p)}},[$,Z]),ct=a.useCallback(()=>{H(null),lt(v.FLAT_MIDDLE_WIDTH,0)},[]),dt=a.useCallback(()=>{Ie(null),lt(v.FLAT_INSPECTOR_WIDTH,0)},[]),[xe,ut]=a.useState(()=>It(v.FLAT_INSPECTOR_VIEW)==="tracking"?"tracking":"agent"),qe=a.useCallback(t=>{ut(t),At(v.FLAT_INSPECTOR_VIEW,t)},[]),pt=a.useCallback(()=>{le(t=>{const n=!t;return ne(v.FLAT_INSPECTOR_OPEN,n),n})},[]),ze=a.useCallback(()=>{le(!1),ne(v.FLAT_INSPECTOR_OPEN,!1)},[]),be=tn(),ce=a.useCallback((t,n)=>{Te({url:t,name:n})},[]),De=a.useCallback((t,n)=>{He({command:t,output:n,isLive:!1})},[]),J=a.useCallback((t,n)=>{f.setFileViewerPath(t,n)},[]),Ke=a.useCallback(t=>{},[]),Ye=a.useCallback((t,n)=>{se({agentId:t,count:n})},[]),_e=a.useCallback(t=>{N?N(t):c(t)},[c,N]),g=a.useMemo(()=>C.size>0?Array.from(C)[0]:null,[C]);a.useEffect(()=>{me(!1)},[g]);const D=a.useRef([]),U=a.useRef(-1),we=a.useRef(!1),Oe=a.useRef(null),[Ze,Q]=a.useState(!1),[Je,Ae]=a.useState(!1),$e=a.useRef(!1),de=a.useRef(null),Se=a.useRef(!1),ee=a.useMemo(()=>new Set(S.map(t=>t.id)),[S]),Qe=a.useMemo(()=>{const t=new Map(S.map(s=>[s.id,s])),n=new Map;for(const s of S)if((s.isBoss||s.class==="boss")&&s.subordinateIds&&s.subordinateIds.length>0){const i=s.subordinateIds.map(p=>t.get(p)).filter(p=>p!==void 0);i.length>0&&n.set(s.id,i)}return n},[S]),l=a.useCallback(()=>{const t=D.current,n=U.current;Q(n>0),Ae(n>=0&&n<t.length-1)},[]),r=a.useCallback(t=>{const n=D.current;if(n.length===0)return;let s=U.current+t;for(;s>=0&&s<n.length;){const i=n[s];if(ee.has(i)){we.current=!0,U.current=s,l(),f.selectAgent(i);return}s+=t}},[ee,l]),d=a.useCallback(()=>r(-1),[r]),o=a.useCallback(()=>r(1),[r]),ue=a.useCallback((t,n)=>{if(typeof window>"u")return;const s=window.history.state,p={...typeof s=="object"&&s!==null?s:{},__flatAgentNav:{agentId:t}};n==="replace"?window.history.replaceState(p,"",window.location.href):window.history.pushState(p,"",window.location.href)},[]);a.useEffect(()=>{if(!g){$e.current=!1,de.current=null;return}if(!$e.current){ue(g,"replace"),$e.current=!0,de.current=g;return}if(Se.current){Se.current=!1,de.current=g;return}de.current!==g&&(ue(g,"push"),de.current=g)},[g,ue]),a.useEffect(()=>{const t=n=>{var m,b;const s=(b=(m=n.state)==null?void 0:m.__flatAgentNav)==null?void 0:b.agentId;if(!s||typeof s!="string"||!ee.has(s)||s===g)return;Se.current=!0,we.current=!0;const i=D.current,p=i.lastIndexOf(s);p>=0?U.current=p:(i.push(s),U.current=i.length-1),l(),f.selectAgent(s)};return window.addEventListener("popstate",t),()=>window.removeEventListener("popstate",t)},[ee,g,l]),a.useEffect(()=>{if(!g){D.current=[],U.current=-1,l();return}if(Oe.current=g,we.current){we.current=!1,l();return}const t=D.current,n=U.current;if(n>=0&&t[n]===g){l();return}const s=n<t.length-1?t.slice(0,n+1):t.slice();s.push(g),s.length>100&&s.shift(),D.current=s,U.current=s.length-1,l()},[g,l]);const Ce=a.useCallback(t=>{_(t),W(!1)},[_]),Ee=g??"",mt=a.useCallback(()=>{},[]),ft=a.useCallback(t=>{Ce(t)},[Ce]),V=fe,[T,I]=a.useState(V),[et,Ct]=a.useState(V);a.useEffect(()=>{if(V){I(!0);return}Ct(!1);const t=setTimeout(()=>I(!1),240);return()=>clearTimeout(t)},[V]),a.useEffect(()=>{if(!T||!V)return;let t=0;const n=requestAnimationFrame(()=>{t=requestAnimationFrame(()=>Ct(!0))});return()=>{cancelAnimationFrame(n),cancelAnimationFrame(t)}},[T,V]);const vt=a.useRef(null);a.useEffect(()=>{if(g)return;const t=n=>{if(n.key!==" "&&n.key!=="Backspace")return;const s=n.target;if(s.tagName==="INPUT"||s.tagName==="TEXTAREA"||s.isContentEditable)return;const i=Oe.current;!i||!ee.has(i)||(n.preventDefault(),f.selectAgent(i))};return document.addEventListener("keydown",t),()=>document.removeEventListener("keydown",t)},[g,ee]);const[Ft,jt]=a.useState(new Set),Wt=a.useCallback(t=>{jt(n=>{const s=new Set(n);return s.has(t)?s.delete(t):s.add(t),s})},[]),ht=Dt(),tt=Ot(),[Ht]=nn(),Me=a.useMemo(()=>{const t=new Map,n=[];for(const x of S){const j=f.getAreaForAgent(x.id);if(!Et((j==null?void 0:j.id)??null))continue;if(!j||j.archived){n.push(x);continue}const k=t.get(j.id);k?k.push(x):t.set(j.id,[x])}const s=new Map,i=[];for(const x of tt.values()){let j=!1;for(const k of ht.values())if(!k.archived&&Mt(k.id)&&f.isPositionInArea(x.position,k)){const te=s.get(k.id);te?te.push(x):s.set(k.id,[x]),j=!0;break}!j&&Et(null)&&i.push(x)}const p=[];for(const[,x]of ht){if(x.archived||!Mt(x.id))continue;const j=t.get(x.id),k=s.get(x.id)??[];(j&&j.length>0||k.length>0)&&p.push({area:x,agents:j??[],buildings:k})}(n.length>0||i.length>0)&&p.push({area:{id:"__unassigned__",name:"Unassigned",color:"#6272a4",center:{x:0,z:0},type:"circle",radius:0,directories:[],archived:!1,assignedAgentIds:[],zIndex:0},agents:n,buildings:i});const m=p.filter(x=>x.area.id!=="__unassigned__"),b=p.filter(x=>x.area.id==="__unassigned__");let B=1,P=1;const Be=new Map;if(m.length>1){let x=1/0,j=-1/0,k=1/0,te=-1/0;for(const L of m)x=Math.min(x,L.area.center.x),j=Math.max(j,L.area.center.x),k=Math.min(k,L.area.center.z),te=Math.max(te,L.area.center.z);const nt=j-x||1,at=te-k||1;if(m.length<=4){B=m.length,P=1;const L=[...m].sort((R,gt)=>R.area.center.x-gt.area.center.x);for(let R=0;R<L.length;R++)Be.set(L[R].area.id,{row:1,col:R+1})}else{const L=[...m].sort((w,A)=>w.area.center.x-A.area.center.x),R=[];for(let w=1;w<L.length;w++)R.push(L[w].area.center.x-L[w-1].area.center.x);const gt=R.reduce((w,A)=>w+A,0)/R.length||1;let Nt=1;for(const w of R)w>gt*1.3&&Nt++;B=Math.max(2,Math.min(Nt,m.length));const xt=[...m].sort((w,A)=>w.area.center.z-A.area.center.z),st=[];for(let w=1;w<xt.length;w++)st.push(xt[w].area.center.z-xt[w-1].area.center.z);const Ut=st.reduce((w,A)=>w+A,0)/st.length||1;let kt=1;for(const w of st)w>Ut*1.3&&kt++;P=Math.max(2,Math.min(kt,m.length)),B=Math.max(B,Math.ceil(m.length/P)),P=Math.max(P,Math.ceil(m.length/B));const qt=nt/B,Kt=at/P,bt=new Set;for(const w of m){let A=Math.min(B-1,Math.max(0,Math.floor((w.area.center.x-x)/qt))),je=Math.min(P-1,Math.max(0,Math.floor((w.area.center.z-k)/Kt))),Fe=`${je},${A}`,yt=0;const Yt=P*B;for(;bt.has(Fe)&&yt<Yt;)A++,A>=B&&(A=0,je=(je+1)%P),Fe=`${je},${A}`,yt++;bt.has(Fe)&&(je=P,A=0,Fe=`${je},${A}`,P++),bt.add(Fe),Be.set(w.area.id,{row:je+1,col:A+1})}}}const ve=x=>{x.sort((j,k)=>{var nt,at,L,R;const te=(((nt=j.position)==null?void 0:nt.z)??0)-(((at=k.position)==null?void 0:at.z)??0);return te!==0?te:(((L=j.position)==null?void 0:L.x)??0)-(((R=k.position)==null?void 0:R.x)??0)})};for(const x of m)ve(x.agents);for(const x of b)ve(x.agents);return{groups:[...m,...b],gridCols:B,gridRows:P,positions:Be}},[S,ht,tt,Ht]),Vt=a.useMemo(()=>{if(!z)return[];const t=S.find(n=>n.id===z.agentId);return t?[{id:"edit-agent",label:"Edit Agent",icon:e.jsx(u,{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(u,{name:"chat",size:14}),onClick:()=>_(t.id)},{id:"delete-agent",label:"Delete Agent",icon:e.jsx(u,{name:"trash",size:14}),danger:!0,onClick:()=>{pe({agentId:t.id,name:t.name})}}]:[]},[z,S,_]),Gt=a.useMemo(()=>{var m;if(!Y)return[];const t=tt.get(Y.buildingId);if(!t)return[];const n=[],s=t.type==="server"||t.type==="docker"||t.type==="terminal",i=t.status==="running",p=t.type==="boss";if(n.push({id:"open",label:t.type==="database"?"Open Database":t.type==="folder"?"Open Folder":t.type==="boss"?"View Boss Logs":t.type==="terminal"?"Open Terminal":t.type==="server"&&((m=t.pm2)!=null&&m.enabled)?"View PM2 Logs":"Open",icon:e.jsx(u,{name:t.type==="database"?"database":t.type==="folder"?"folder":t.type==="terminal"?"terminal":"eye",size:14}),onClick:()=>_e(t.id)}),s&&(i||n.push({id:"start",label:"Start",icon:e.jsx(u,{name:"play",size:14}),onClick:()=>f.sendBuildingCommand(t.id,"start")}),i&&(n.push({id:"restart",label:"Restart",icon:e.jsx(u,{name:"refresh",size:14}),onClick:()=>f.sendBuildingCommand(t.id,"restart")}),n.push({id:"stop",label:"Stop",icon:e.jsx(u,{name:"stop",size:14}),onClick:()=>f.sendBuildingCommand(t.id,"stop")}))),p&&t.subordinateBuildingIds&&t.subordinateBuildingIds.length>0&&(n.push({id:"start-all",label:"Start All Subordinates",icon:e.jsx(u,{name:"launch",size:14}),onClick:()=>{for(const b of t.subordinateBuildingIds)f.sendBuildingCommand(b,"start")}}),n.push({id:"stop-all",label:"Stop All Subordinates",icon:e.jsx(u,{name:"pause",size:14}),onClick:()=>{for(const b of t.subordinateBuildingIds)f.sendBuildingCommand(b,"stop")}}),n.push({id:"restart-all",label:"Restart All Subordinates",icon:e.jsx(u,{name:"restart",size:14}),onClick:()=>{for(const b of t.subordinateBuildingIds)f.sendBuildingCommand(b,"restart")}})),s&&n.push({id:"health-check",label:"Health Check",icon:e.jsx(u,{name:"health",size:14}),onClick:()=>f.sendBuildingCommand(t.id,"healthCheck")}),n.push({id:"divider-edit",label:"",divider:!0,onClick:()=>{}}),n.push({id:"edit",label:"Edit Building",icon:e.jsx(u,{name:"edit",size:14}),onClick:()=>{window.dispatchEvent(new CustomEvent("tide:building-edit",{detail:{buildingId:t.id}}))}}),n.push({id:"clone",label:"Clone Building",icon:e.jsx(u,{name:"copy",size:14}),onClick:()=>{f.createBuilding({name:`${t.name} (Copy)`,type:t.type,style:t.style,color:t.color,scale:t.scale,position:{x:t.position.x+2,z:t.position.z+2},cwd:t.cwd,folderPath:t.folderPath,commands:t.commands,pm2:t.pm2,docker:t.docker,database:t.database,terminal:t.terminal,urls:t.urls,subordinateBuildingIds:t.subordinateBuildingIds})}}),t.urls&&t.urls.length>0)for(const b of t.urls)n.push({id:`url-${b.label}`,label:b.label,icon:e.jsx(u,{name:"link",size:14}),onClick:()=>window.open(b.url,"_blank","noopener,noreferrer")});return n.push({id:"divider-danger",label:"",divider:!0,onClick:()=>{}}),n.push({id:"delete",label:"Delete Building",icon:e.jsx(u,{name:"trash",size:14}),danger:!0,onClick:()=>f.deleteBuilding(t.id)}),n},[Y,tt,_e]),Xt=a.useCallback(t=>{const n=new Set(Me.groups.map(s=>s.area.id));n.delete(t),jt(n),requestAnimationFrame(()=>{const s=vt.current;if(!s)return;const i=s.querySelector(`[data-area-id="${t}"]`);if(!i)return;const p=s.getBoundingClientRect(),b=i.getBoundingClientRect().top-p.top+s.scrollTop-8;s.scrollTo({top:Math.max(0,b),behavior:"smooth"})})},[Me]);return e.jsxs("div",{ref:re,className:`flat-view ${V?"flat-view--with-inspector":""} ${g?"flat-view--has-chat":""} ${ie?"flat-view--mobile-sidebar-open":""}`,style:(()=>{if(G===null&&X===null)return;const t={};return G!==null&&(t["--flat-middle-width"]=`${G}px`),X!==null&&(t["--flat-inspector-width"]=`${X}px`),t})(),children:[ie&&e.jsx("div",{className:"flat-mobile-sidebar-backdrop",onClick:Xe,"aria-hidden":"true"}),e.jsxs("div",{className:"flat-middle",children:[e.jsx("div",{className:"flat-middle__header",children: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:q,title:"Create new boss agent",children:"+ Boss"}),e.jsx("button",{className:"flat-cta-btn flat-cta-btn--area",onClick:F,title:"Create new area",children:"+ Area"})]})}),e.jsx("div",{className:"flat-middle__content",children:e.jsx(an,{activeAgentId:Ee,onClose:mt,onSelectAgent:ft,collapsedAreas:Ft,onToggleArea:Wt,agentListRef:vt})})]}),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:he,onPointerMove:oe,onPointerUp:ge,onPointerCancel:ge,onDoubleClick:ct}),e.jsxs("div",{className:"flat-right",children:[e.jsxs("button",{type:"button",className:"flat-mobile-sidebar-toggle","aria-label":ie?"Close agents sidebar":"Open agents sidebar","aria-expanded":ie,onClick:ot,children:[e.jsx(u,{name:"list",size:18}),e.jsx("span",{className:"flat-mobile-sidebar-toggle__label",children:"Agents"})]}),g?e.jsx(Wn,{agentId:g,terminalViewMode:Ge,onTerminalViewModeChange:ye,inspectorOpen:fe,onToggleInspector:pt,onImageClick:ce,onFileClick:J,onBashClick:De,onViewMarkdown:Ke,onRequestClearSubordinates:Ye,onOpenBuilding:_e,keyboard:be,canNavigateBack:Ze,canNavigateForward:Je,onNavigateBack:d,onNavigateForward:o,agentInfoOpen:ke,onToggleAgentInfo:Le}):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(Ln,{className:"flat-map__view-mode"})]}),e.jsx("div",{className:"flat-map__grid",style:{gridTemplateColumns:`repeat(${Me.gridCols}, 1fr)`},children:Me.groups.length===0?e.jsx("div",{className:"flat-map__empty",children:e.jsx("span",{children:"No areas or agents yet"})}):Me.groups.map(t=>{const n=t.area.id,s=Me.positions.get(n);return e.jsxs("div",{className:"flat-map-area-card",style:{"--area-color":t.area.color,gridRow:s==null?void 0:s.row,gridColumn:s==null?void 0:s.col},children:[e.jsxs("button",{type:"button",className:"flat-map-area-card__header",onClick:()=>Xt(n),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(i=>{const p=i.isBoss||i.class==="boss",m=p?Qe.get(i.id):void 0,b=sn(i),B=b.usedPercent>=80?"#ff4a4a":b.usedPercent>=60?"#ff9e4a":b.usedPercent>=40?"#ffd700":"#4aff9e",P=`Context: ${(b.totalTokens/1e3).toFixed(1)}k / ${(b.contextWindow/1e3).toFixed(1)}k (${b.usedPercent}% used, ${b.freePercent}% free)`,Be=i.latestTodos&&i.latestTodos.length>0||m&&m.length>0;return e.jsx(ln,{todos:i.latestTodos,subordinates:m,position:"top",children:e.jsxs("button",{type:"button",className:`flat-map-agent-chip ${i.status}`,onClick:()=>_(i.id),onContextMenu:ve=>{ve.preventDefault(),ve.stopPropagation(),Ne({agentId:i.id,position:{x:ve.clientX,y:ve.clientY}})},title:Be?void 0:`${p?"Boss · ":""}Open chat with ${i.name}
2
- ${P}`,children:[e.jsx($t,{agent:i,size:16}),p&&e.jsx("span",{className:"flat-map-agent-chip__crown","aria-hidden":"true",children:e.jsx(u,{name:"crown",size:11,color:"#ffd700",weight:"fill"})}),e.jsx("span",{className:"flat-map-agent-chip__name",children:i.name}),e.jsx("img",{src:i.provider==="codex"?"/assets/codex.png":i.provider==="opencode"?"/assets/opencode.png":"/assets/claude.png",alt:i.provider,className:"flat-map-agent-chip__provider-icon",title:i.provider==="codex"?"Codex Agent":i.provider==="opencode"?"OpenCode Agent":"Claude Agent"}),e.jsx("span",{className:"flat-map-agent-chip__dot",style:{backgroundColor:Bt(i.status)}}),i.latestTodos&&i.latestTodos.length>0&&e.jsx(rn,{todos:i.latestTodos,maxDots:6}),p&&m&&m.length>0&&e.jsx(on,{subordinates:m,maxDots:6}),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:`${b.usedPercent}%`,backgroundColor:B}})})]})},i.id)})}),t.buildings.length>0&&e.jsx("div",{className:"flat-map-area-card__buildings",children:t.buildings.map(i=>e.jsxs("button",{type:"button",className:`flat-map-building-chip flat-map-building-chip--${i.status}`,onClick:p=>{if(y){const m=p.currentTarget.getBoundingClientRect();y(i.id,{x:m.right,y:m.top+m.height/2})}else _e(i.id)},onContextMenu:p=>{p.preventDefault(),p.stopPropagation(),h({buildingId:i.id,position:{x:p.clientX,y:p.clientY}})},title:`${i.name} · ${i.type} · ${i.status}`,children:[e.jsx(u,{name:cn(i.type),size:12}),e.jsx("span",{className:"flat-map-building-chip__name",children:i.name}),e.jsx("span",{className:"flat-map-building-chip__dot",style:{backgroundColor:dn(i.status)}})]},i.id))})]},n)})})]})})]}),V&&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:Ue,onPointerMove:oe,onPointerUp:ge,onPointerCancel:ge,onDoubleClick:dt}),T&&e.jsxs("aside",{className:`flat-inspector ${et?"flat-inspector--open":"flat-inspector--closing"}`,"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":xe==="agent",className:`flat-inspector__tab ${xe==="agent"?"flat-inspector__tab--active":""}`,onClick:()=>qe("agent"),children:"Agent"}),e.jsx("button",{type:"button",role:"tab","aria-selected":xe==="tracking",className:`flat-inspector__tab ${xe==="tracking"?"flat-inspector__tab--active":""}`,onClick:()=>qe("tracking"),children:"Tracking"})]}),e.jsx("button",{type:"button",className:"flat-inspector__close",onClick:ze,title:"Close inspector","aria-label":"Close inspector",children:"✕"})]}),e.jsx("div",{className:"flat-inspector__body",children:xe==="tracking"?e.jsx(un,{activeAgentId:g??"",onSelectAgent:t=>{_(t),ze()}}):(()=>{if(!g)return e.jsx("div",{className:"flat-inspector__empty",children:e.jsx("span",{children:"Select an agent to inspect"})});const t=S.find(n=>n.id===g);return t?e.jsx(pn,{agent:t,onFocusAgent:n=>{_(n),ze()},onKillAgent:n=>f.killAgent(n)}):e.jsx("div",{className:"flat-inspector__empty",children:e.jsx("span",{children:"Agent not found"})})})()})]}),K&&e.jsx(mn,{url:K.url,name:K.name,onClose:()=>Te(null)}),We&&e.jsx(fn,{state:We,onClose:()=>He(null)}),Pe&&e.jsx(hn,{action:"clear-subordinates",selectedAgentId:Pe.agentId,subordinateCount:Pe.count,onClose:()=>se(null),onClearHistory:()=>{}}),e.jsx(gn,{agent:g?S.find(t=>t.id===g)??null:null,isOpen:ke&&!!g,onClose:Ve}),e.jsx(Tt,{isOpen:z!==null,position:(z==null?void 0:z.position)??{x:0,y:0},worldPosition:{x:0,z:0},actions:Vt,onClose:()=>Ne(null)}),e.jsx(Tt,{isOpen:Y!==null,position:(Y==null?void 0:Y.position)??{x:0,y:0},worldPosition:{x:0,z:0},actions:Gt,onClose:()=>h(null)}),e.jsx(xn,{isOpen:M!==null,title:ae("common:confirm.removeAgentTitle"),message:ae("common:confirm.removeAgentMessage",{name:(M==null?void 0:M.name)??""}),confirmLabel:ae("common:buttons.remove"),cancelLabel:ae("common:buttons.cancel"),variant:"danger",onConfirm:()=>{M&&f.removeAgentFromServer(M.agentId)},onClose:()=>pe(null)})]})}export{Xn as FlatView};