tide-commander 1.199.0 → 1.199.2

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 (126) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/dist/assets/{AudioPlayer-CusBq3ON.js → AudioPlayer-XaWiU7f4.js} +1 -1
  3. package/dist/assets/{BossLogsModal-B1PLdne_.js → BossLogsModal-1tI-leZQ.js} +1 -1
  4. package/dist/assets/{BossSpawnModal-DQN_2lzh.js → BossSpawnModal-CRoChH0J.js} +1 -1
  5. package/dist/assets/{ControlsModal-D4JsU4VU.js → ControlsModal-Cu7kwhct.js} +1 -1
  6. package/dist/assets/{DockerLogsModal-BuCiJ02l.js → DockerLogsModal-DFAiOsWH.js} +1 -1
  7. package/dist/assets/{EmbeddedEditor-CBaRvdh1.js → EmbeddedEditor-hnSknX5L.js} +1 -1
  8. package/dist/assets/{FcStdViewer-CpJhmVIt.js → FcStdViewer-B_cbRz1w.js} +1 -1
  9. package/dist/assets/{GcodeViewer-B8BHZMmG.js → GcodeViewer-CFgwEZ6g.js} +1 -1
  10. package/dist/assets/{GlbViewer-DdVYw2Jh.js → GlbViewer-14WSSXX7.js} +1 -1
  11. package/dist/assets/{GmailOAuthSetup-Cj0r8z52.js → GmailOAuthSetup-waw2142C.js} +1 -1
  12. package/dist/assets/{GoogleOAuthSetup-BO0udRUZ.js → GoogleOAuthSetup-Bo59grtp.js} +1 -1
  13. package/dist/assets/{IframeModal-CecB4A27.js → IframeModal-B3M77grB.js} +1 -1
  14. package/dist/assets/{IntegrationsPanel-BVnzRrTb.js → IntegrationsPanel-BLHrC0GX.js} +2 -2
  15. package/dist/assets/{LogViewerModal-CNbfgDQK.js → LogViewerModal-CitlmDgQ.js} +1 -1
  16. package/dist/assets/{MonitoringModal-CUXXMqLv.js → MonitoringModal-BcKOCSRM.js} +1 -1
  17. package/dist/assets/{OrbitControls-DS7gPhsZ.js → OrbitControls-ANLmgNeR.js} +1 -1
  18. package/dist/assets/{PM2LogsModal-DFAuRDwm.js → PM2LogsModal-DrHpuMNf.js} +1 -1
  19. package/dist/assets/{RestoreArchivedAreaModal-DT5-U0A8.js → RestoreArchivedAreaModal-DcD3vdUJ.js} +1 -1
  20. package/dist/assets/{Scene2DCanvas-DqakJMdS.js → Scene2DCanvas-DKUcFYZW.js} +1 -1
  21. package/dist/assets/SceneManager-DPojKMM-.js +104 -0
  22. package/dist/assets/{SkillsPanel-1hYjREqo.js → SkillsPanel-CUW0prbh.js} +1 -1
  23. package/dist/assets/{SlackMultiInstanceSetup-C6EtUfP8.js → SlackMultiInstanceSetup-YFYeZ94t.js} +1 -1
  24. package/dist/assets/{SpawnModal-BmMZFOUj.js → SpawnModal-DPvq-R5b.js} +1 -1
  25. package/dist/assets/{StatisticsModal-mmqE6JaF.js → StatisticsModal-Dt-Hof51.js} +1 -1
  26. package/dist/assets/{StlViewer-D0XChi1U.js → StlViewer-GyyomEax.js} +1 -1
  27. package/dist/assets/{SubordinateAssignmentModal-CBISWK7c.js → SubordinateAssignmentModal-ahzGBjr4.js} +1 -1
  28. package/dist/assets/{ThreeAreaSelector-C_7zwy_Q.js → ThreeAreaSelector-Bj_mL6NG.js} +1 -1
  29. package/dist/assets/{ThreeViewShortcuts-DZZmjQAV.js → ThreeViewShortcuts-CKtE3yZV.js} +1 -1
  30. package/dist/assets/{TriggerManagerPanel-Bwd5-VGg.js → TriggerManagerPanel-DtdbOk9B.js} +1 -1
  31. package/dist/assets/{VideoPlayer-BuFPsPNu.js → VideoPlayer-Crq-MwPS.js} +1 -1
  32. package/dist/assets/{WorkflowEditorPanel-DxQfrs71.js → WorkflowEditorPanel-CitR9Em3.js} +1 -1
  33. package/dist/assets/{abnfDiagram-VRR7QNED-AhR0vtDs.js → abnfDiagram-VRR7QNED-QFcuJYPe.js} +1 -1
  34. package/dist/assets/{arc-CTR1mrNz.js → arc-CLuSzQ4E.js} +1 -1
  35. package/dist/assets/{architectureDiagram-ZJ3FMSHR-DrsB_-NW.js → architectureDiagram-ZJ3FMSHR-DlhVck93.js} +1 -1
  36. package/dist/assets/{area-logos-D_dodLqh.js → area-logos-DYARiYqI.js} +1 -1
  37. package/dist/assets/{blockDiagram-677ZJIJ3-Bf6BktPD.js → blockDiagram-677ZJIJ3-CJwOmsfj.js} +1 -1
  38. package/dist/assets/{c4Diagram-LMCZKHZV--UrsSHrg.js → c4Diagram-LMCZKHZV-OsgCNPWJ.js} +1 -1
  39. package/dist/assets/channel-cpl_NpAy.js +1 -0
  40. package/dist/assets/{chunk-2Q5K7J3B-DajcrDU0.js → chunk-2Q5K7J3B-KG-L7vvm.js} +1 -1
  41. package/dist/assets/{chunk-32BRIVSS-BoJToPN6.js → chunk-32BRIVSS-BXGbqO9v.js} +1 -1
  42. package/dist/assets/{chunk-5VM5RSS4-CWyIsEjs.js → chunk-5VM5RSS4-BWXkm8f0.js} +1 -1
  43. package/dist/assets/{chunk-EX3LRPZG-BxQt59EY.js → chunk-EX3LRPZG-7-8ulJ19.js} +1 -1
  44. package/dist/assets/{chunk-JWPE2WC7-CcltxnxE.js → chunk-JWPE2WC7-mkwFN5xu.js} +1 -1
  45. package/dist/assets/{chunk-MOJQB5TN-CoFz0cis.js → chunk-MOJQB5TN-WEfWznKE.js} +1 -1
  46. package/dist/assets/{chunk-RYQCIY6F-CqD5SIAs.js → chunk-RYQCIY6F-ByP5odu4.js} +1 -1
  47. package/dist/assets/{chunk-V7JOEXUC-B38vYRK3.js → chunk-V7JOEXUC-yWHmp1L1.js} +1 -1
  48. package/dist/assets/{chunk-VR4S4FIN-CVwpBl0T.js → chunk-VR4S4FIN-DHbZaHzt.js} +1 -1
  49. package/dist/assets/{chunk-XXDRQBXY-DznOU5hd.js → chunk-XXDRQBXY-SNa-Wh3U.js} +1 -1
  50. package/dist/assets/classDiagram-OUVF2IWQ-D_lsO4mm.js +1 -0
  51. package/dist/assets/classDiagram-v2-EOCWNBFH-D_lsO4mm.js +1 -0
  52. package/dist/assets/{cose-bilkent-JH36ORCC-B1uTqWwQ.js → cose-bilkent-JH36ORCC-CyxHYUhP.js} +1 -1
  53. package/dist/assets/{cynefin-VYW2F7L2-DgpqdGRT.js → cynefin-VYW2F7L2-BvwjSDiQ.js} +1 -1
  54. package/dist/assets/{cynefinDiagram-TSTJHNR4-Ld74Dvow.js → cynefinDiagram-TSTJHNR4-C8doInhn.js} +1 -1
  55. package/dist/assets/{dagre-VKFMJZFB-DAp2Br8X.js → dagre-VKFMJZFB-BNDcupek.js} +1 -1
  56. package/dist/assets/{diagram-FQU43EPY-CaMUb0eE.js → diagram-FQU43EPY-Bst0bBnQ.js} +1 -1
  57. package/dist/assets/{diagram-G47NLZAW-kTOq861A.js → diagram-G47NLZAW-CfEv0aTY.js} +1 -1
  58. package/dist/assets/{diagram-NH7WQ7WH-LWZrE7zu.js → diagram-NH7WQ7WH-B7MYvWXL.js} +1 -1
  59. package/dist/assets/{diagram-OA4YK3LP-Csm-frID.js → diagram-OA4YK3LP-BIzII0d2.js} +1 -1
  60. package/dist/assets/{diagram-WEI45ONY-BconZEMM.js → diagram-WEI45ONY-D5yd1HWr.js} +1 -1
  61. package/dist/assets/{ebnfDiagram-CCIWWBDH-Cr5xwAgl.js → ebnfDiagram-CCIWWBDH-gyhVYUos.js} +1 -1
  62. package/dist/assets/{erDiagram-Q63AITRT-76P2E9Q6.js → erDiagram-Q63AITRT-Duz-DwfE.js} +1 -1
  63. package/dist/assets/{flowDiagram-23GEKE2U-CciJAjTA.js → flowDiagram-23GEKE2U-CrnARkmw.js} +1 -1
  64. package/dist/assets/{ganttDiagram-NO4QXBWP-D7VgBp68.js → ganttDiagram-NO4QXBWP-D6cBteIN.js} +1 -1
  65. package/dist/assets/{gitGraphDiagram-IHSO6WYX-CxICR8Bg.js → gitGraphDiagram-IHSO6WYX-CMHfr_lR.js} +1 -1
  66. package/dist/assets/{index-Cd53q1WZ.js → index-2427ATYD.js} +3 -3
  67. package/dist/assets/{index-lQifR7XC.js → index-B1vOCcI-.js} +1 -1
  68. package/dist/assets/index-B5wHDczA.js +2 -0
  69. package/dist/assets/{index-BNsHVfai.js → index-CbMtvQTH.js} +1 -1
  70. package/dist/assets/{index-DzzLdCr9.js → index-D5O_0aq9.js} +1 -1
  71. package/dist/assets/{index-Bfmfqbw7.js → index-D5pIRxFm.js} +1 -1
  72. package/dist/assets/index-DJKuwqJG.js +2 -0
  73. package/dist/assets/{index-Dc4yP2fA.js → index-DeqoOoo6.js} +3 -3
  74. package/dist/assets/{index-Z0bYekBH.js → index-fiC5OXgR.js} +1 -1
  75. package/dist/assets/{infoDiagram-FWYZ7A6U-h-R7gGrP.js → infoDiagram-FWYZ7A6U-Mvk2Mpp3.js} +1 -1
  76. package/dist/assets/{ishikawaDiagram-FXEZZL3T-D1RbbiMz.js → ishikawaDiagram-FXEZZL3T-DXsaNDYg.js} +1 -1
  77. package/dist/assets/{journeyDiagram-5HDEW3XC-BnNUbZMI.js → journeyDiagram-5HDEW3XC-6QlK8xHN.js} +1 -1
  78. package/dist/assets/{kanban-definition-HUTT4EX6-kX3kneLI.js → kanban-definition-HUTT4EX6-D5EeRs07.js} +1 -1
  79. package/dist/assets/{linear-DC5X1tTJ.js → linear-D_aP9MD5.js} +1 -1
  80. package/dist/assets/main-B2ZLroL1.css +1 -0
  81. package/dist/assets/{main-Bb9H5jmt.js → main-Dk3qq80S.js} +156 -156
  82. package/dist/assets/{mermaid.core-BE33DHym.js → mermaid.core-CEculPxD.js} +4 -4
  83. package/dist/assets/{mindmap-definition-LN4V7U3C-CY3A4tSH.js → mindmap-definition-LN4V7U3C-Vjj9vgEN.js} +1 -1
  84. package/dist/assets/{pegDiagram-2B236MQR-B99ZSEym.js → pegDiagram-2B236MQR-B-AwbaoO.js} +1 -1
  85. package/dist/assets/{pieDiagram-ENE6RG2P-7PsmMteT.js → pieDiagram-ENE6RG2P-D5o1UYPK.js} +1 -1
  86. package/dist/assets/{quadrantDiagram-ABIIQ3AL-DjShiKUv.js → quadrantDiagram-ABIIQ3AL-Bl_Rbmz-.js} +1 -1
  87. package/dist/assets/{railroadDiagram-RFXS5EU6-B6KuCiHH.js → railroadDiagram-RFXS5EU6-CW-qy1dp.js} +1 -1
  88. package/dist/assets/{requirementDiagram-TGXJPOKE-k_7TCScw.js → requirementDiagram-TGXJPOKE-DGUQpy3K.js} +1 -1
  89. package/dist/assets/{sankeyDiagram-HTMAVEWB-D2YbTfpK.js → sankeyDiagram-HTMAVEWB-CUlWZH9G.js} +1 -1
  90. package/dist/assets/{sequenceDiagram-DBY2YBRQ-CuYh53OC.js → sequenceDiagram-DBY2YBRQ-CeDVJrbJ.js} +1 -1
  91. package/dist/assets/{sizeCapture-X5ZJPWSS-D4_qcFkr.js → sizeCapture-X5ZJPWSS-BGSL3ofq.js} +1 -1
  92. package/dist/assets/{stateDiagram-2N3HPSRC-DO9QVMBT.js → stateDiagram-2N3HPSRC-9A8tAPIu.js} +1 -1
  93. package/dist/assets/stateDiagram-v2-6OUMAXLB-DzVFFq0g.js +1 -0
  94. package/dist/assets/{swimlanes-5IMT3BWC-gMS-z6zh.js → swimlanes-5IMT3BWC-CipRR1uk.js} +2 -2
  95. package/dist/assets/swimlanesDiagram-G3AALYLV-XDQw-C4e.js +8 -0
  96. package/dist/assets/{timeline-definition-FHXFAJF6-CUmQCwOG.js → timeline-definition-FHXFAJF6-IgrCsFe-.js} +1 -1
  97. package/dist/assets/{vendor-three-CBPuP1jE.js → vendor-three-DYBBrXTx.js} +1 -1
  98. package/dist/assets/{vennDiagram-L72KCM5P-CIP-5b8u.js → vennDiagram-L72KCM5P-okSGsDy3.js} +1 -1
  99. package/dist/assets/{wardleyDiagram-EHGQE667-DlQqKMjr.js → wardleyDiagram-EHGQE667-G0RLggUt.js} +1 -1
  100. package/dist/assets/{web-DmAaMs-2.js → web-B5BfOO5C.js} +1 -1
  101. package/dist/assets/{web-D42BXPx5.js → web-BPOqvnJL.js} +1 -1
  102. package/dist/assets/{web-DVkGXGfI.js → web-Q8DwQW0W.js} +1 -1
  103. package/dist/assets/{xychartDiagram-FW5EYKEG-CekYCp3d.js → xychartDiagram-FW5EYKEG-DtVJEFyI.js} +1 -1
  104. package/dist/build-info.json +1 -1
  105. package/dist/index.html +3 -3
  106. package/dist/src/packages/server/app.js +26 -1
  107. package/dist/src/packages/server/claude/backend.js +5 -4
  108. package/dist/src/packages/server/claude/runner/stdout-pipeline.js +29 -30
  109. package/dist/src/packages/server/claude/runner/watchdog.js +2 -1
  110. package/dist/src/packages/server/claude/session-loader.js +141 -81
  111. package/dist/src/packages/server/data/index.js +35 -2
  112. package/dist/src/packages/server/routes/perf.js +50 -39
  113. package/dist/src/packages/server/services/git-watch-service.js +14 -2
  114. package/dist/src/packages/server/services/runtime-service.js +85 -39
  115. package/dist/src/packages/server/websocket/handler.js +33 -8
  116. package/dist/src/packages/server/websocket/listeners/runtime-listeners.js +5 -2
  117. package/package.json +3 -1
  118. package/dist/assets/SceneManager-htGN7YfA.js +0 -104
  119. package/dist/assets/channel-BkokQZXi.js +0 -1
  120. package/dist/assets/classDiagram-OUVF2IWQ-DibSrtP1.js +0 -1
  121. package/dist/assets/classDiagram-v2-EOCWNBFH-DibSrtP1.js +0 -1
  122. package/dist/assets/index-C8zT43_7.js +0 -2
  123. package/dist/assets/index-WhxnTPGa.js +0 -2
  124. package/dist/assets/main-CSv15YYo.css +0 -1
  125. package/dist/assets/stateDiagram-v2-6OUMAXLB-CekJ4qac.js +0 -1
  126. package/dist/assets/swimlanesDiagram-G3AALYLV-CfPVdXRk.js +0 -8
@@ -1 +1 @@
1
- import{c as Ze,d as et,z as cs,a0 as us,f as ls,br as hs,b_ as fs,aa as ds,r as h,y as gs,S as _e,b$ as Ye,c0 as ms,c1 as ps,c2 as ys,as as As,c3 as ye,s as U,c4 as xs,j as d,I as V,V as Tt,c5 as Ft,n as Nt,c6 as Es,c7 as Dt,c8 as We,U as qe,m as Ms,ar as Gt,u as Oe,c9 as Rt,aC as Cs,ca as jt,cb as Is}from"./main-Bb9H5jmt.js";import{cc as zn,cd as Kn,ce as On,cf as Un,cg as Gn}from"./main-Bb9H5jmt.js";import"./vendor-react--Eh9ivFN.js";import"./vendor-three-CBPuP1jE.js";function ce(t){return Array.isArray?Array.isArray(t):Wt(t)==="[object Array]"}function _s(t){if(typeof t=="string")return t;let e=t+"";return e=="0"&&1/t==-1/0?"-0":e}function Ss(t){return t==null?"":_s(t)}function oe(t){return typeof t=="string"}function Ht(t){return typeof t=="number"}function vs(t){return t===!0||t===!1||ws(t)&&Wt(t)=="[object Boolean]"}function Yt(t){return typeof t=="object"}function ws(t){return Yt(t)&&t!==null}function X(t){return t!=null}function Ve(t){return!t.trim().length}function Wt(t){return t==null?t===void 0?"[object Undefined]":"[object Null]":Object.prototype.toString.call(t)}const bs="Incorrect 'index' type",Ls=t=>`Invalid value for key ${t}`,Ts=t=>`Pattern length exceeds max of ${t}.`,Fs=t=>`Missing ${t} property in key`,Ns=t=>`Property 'weight' in key '${t}' must be a positive integer`,kt=Object.prototype.hasOwnProperty;class Ds{constructor(e){this._keys=[],this._keyMap={};let n=0;e.forEach(r=>{let o=qt(r);this._keys.push(o),this._keyMap[o.id]=o,n+=o.weight}),this._keys.forEach(r=>{r.weight/=n})}get(e){return this._keyMap[e]}keys(){return this._keys}toJSON(){return JSON.stringify(this._keys)}}function qt(t){let e=null,n=null,r=null,o=1,a=null;if(oe(t)||ce(t))r=t,e=$t(t),n=tt(t);else{if(!kt.call(t,"name"))throw new Error(Fs("name"));const c=t.name;if(r=c,kt.call(t,"weight")&&(o=t.weight,o<=0))throw new Error(Ns(c));e=$t(c),n=tt(c),a=t.getFn}return{path:e,id:n,weight:o,src:r,getFn:a}}function $t(t){return ce(t)?t:t.split(".")}function tt(t){return ce(t)?t.join("."):t}function Rs(t,e){let n=[],r=!1;const o=(a,c,u)=>{if(X(a))if(!c[u])n.push(a);else{let f=c[u];const l=a[f];if(!X(l))return;if(u===c.length-1&&(oe(l)||Ht(l)||vs(l)))n.push(Ss(l));else if(ce(l)){r=!0;for(let g=0,x=l.length;g<x;g+=1)o(l[g],c,u+1)}else c.length&&o(l,c,u+1)}};return o(t,oe(e)?e.split("."):e,0),r?n:n[0]}const js={includeMatches:!1,findAllMatches:!1,minMatchCharLength:1},ks={isCaseSensitive:!1,ignoreDiacritics:!1,includeScore:!1,keys:[],shouldSort:!0,sortFn:(t,e)=>t.score===e.score?t.idx<e.idx?-1:1:t.score<e.score?-1:1},$s={location:0,threshold:.6,distance:100},Bs={useExtendedSearch:!1,getFn:Rs,ignoreLocation:!1,ignoreFieldNorm:!1,fieldNormWeight:1};var C={...ks,...js,...$s,...Bs};const Ps=/[^ ]+/g;function Qs(t=1,e=3){const n=new Map,r=Math.pow(10,e);return{get(o){const a=o.match(Ps).length;if(n.has(a))return n.get(a);const c=1/Math.pow(a,.5*t),u=parseFloat(Math.round(c*r)/r);return n.set(a,u),u},clear(){n.clear()}}}class at{constructor({getFn:e=C.getFn,fieldNormWeight:n=C.fieldNormWeight}={}){this.norm=Qs(n,3),this.getFn=e,this.isCreated=!1,this.setIndexRecords()}setSources(e=[]){this.docs=e}setIndexRecords(e=[]){this.records=e}setKeys(e=[]){this.keys=e,this._keysMap={},e.forEach((n,r)=>{this._keysMap[n.id]=r})}create(){this.isCreated||!this.docs.length||(this.isCreated=!0,oe(this.docs[0])?this.docs.forEach((e,n)=>{this._addString(e,n)}):this.docs.forEach((e,n)=>{this._addObject(e,n)}),this.norm.clear())}add(e){const n=this.size();oe(e)?this._addString(e,n):this._addObject(e,n)}removeAt(e){this.records.splice(e,1);for(let n=e,r=this.size();n<r;n+=1)this.records[n].i-=1}getValueForItemAtKeyId(e,n){return e[this._keysMap[n]]}size(){return this.records.length}_addString(e,n){if(!X(e)||Ve(e))return;let r={v:e,i:n,n:this.norm.get(e)};this.records.push(r)}_addObject(e,n){let r={i:n,$:{}};this.keys.forEach((o,a)=>{let c=o.getFn?o.getFn(e):this.getFn(e,o.path);if(X(c)){if(ce(c)){let u=[];const f=[{nestedArrIndex:-1,value:c}];for(;f.length;){const{nestedArrIndex:l,value:g}=f.pop();if(X(g))if(oe(g)&&!Ve(g)){let x={v:g,i:l,n:this.norm.get(g)};u.push(x)}else ce(g)&&g.forEach((x,y)=>{f.push({nestedArrIndex:y,value:x})})}r.$[a]=u}else if(oe(c)&&!Ve(c)){let u={v:c,n:this.norm.get(c)};r.$[a]=u}}}),this.records.push(r)}toJSON(){return{keys:this.keys,records:this.records}}}function Vt(t,e,{getFn:n=C.getFn,fieldNormWeight:r=C.fieldNormWeight}={}){const o=new at({getFn:n,fieldNormWeight:r});return o.setKeys(t.map(qt)),o.setSources(e),o.create(),o}function zs(t,{getFn:e=C.getFn,fieldNormWeight:n=C.fieldNormWeight}={}){const{keys:r,records:o}=t,a=new at({getFn:e,fieldNormWeight:n});return a.setKeys(r),a.setIndexRecords(o),a}function Pe(t,{errors:e=0,currentLocation:n=0,expectedLocation:r=0,distance:o=C.distance,ignoreLocation:a=C.ignoreLocation}={}){const c=e/t.length;if(a)return c;const u=Math.abs(r-n);return o?c+u/o:u?1:c}function Ks(t=[],e=C.minMatchCharLength){let n=[],r=-1,o=-1,a=0;for(let c=t.length;a<c;a+=1){let u=t[a];u&&r===-1?r=a:!u&&r!==-1&&(o=a-1,o-r+1>=e&&n.push([r,o]),r=-1)}return t[a-1]&&a-r>=e&&n.push([r,a-1]),n}const me=32;function Os(t,e,n,{location:r=C.location,distance:o=C.distance,threshold:a=C.threshold,findAllMatches:c=C.findAllMatches,minMatchCharLength:u=C.minMatchCharLength,includeMatches:f=C.includeMatches,ignoreLocation:l=C.ignoreLocation}={}){if(e.length>me)throw new Error(Ts(me));const g=e.length,x=t.length,y=Math.max(0,Math.min(r,x));let E=a,A=y;const M=u>1||f,S=M?Array(x):[];let R;for(;(R=t.indexOf(e,A))>-1;){let B=Pe(e,{currentLocation:R,expectedLocation:y,distance:o,ignoreLocation:l});if(E=Math.min(B,E),A=R+g,M){let Y=0;for(;Y<g;)S[R+Y]=1,Y+=1}}A=-1;let w=[],j=1,K=g+x;const le=1<<g-1;for(let B=0;B<g;B+=1){let Y=0,G=K;for(;Y<G;)Pe(e,{errors:B,currentLocation:y+G,expectedLocation:y,distance:o,ignoreLocation:l})<=E?Y=G:K=G,G=Math.floor((K-Y)/2+Y);K=G;let ie=Math.max(1,y-G+1),re=c?x:Math.min(y+G,x)+g,J=Array(re+2);J[re+1]=(1<<B)-1;for(let O=re;O>=ie;O-=1){let W=O-1,N=n[t.charAt(W)];if(M&&(S[W]=+!!N),J[O]=(J[O+1]<<1|1)&N,B&&(J[O]|=(w[O+1]|w[O])<<1|1|w[O+1]),J[O]&le&&(j=Pe(e,{errors:B,currentLocation:W,expectedLocation:y,distance:o,ignoreLocation:l}),j<=E)){if(E=j,A=W,A<=y)break;ie=Math.max(1,2*y-A)}}if(Pe(e,{errors:B+1,currentLocation:y,expectedLocation:y,distance:o,ignoreLocation:l})>E)break;w=J}const he={isMatch:A>=0,score:Math.max(.001,j)};if(M){const B=Ks(S,u);B.length?f&&(he.indices=B):he.isMatch=!1}return he}function Us(t){let e={};for(let n=0,r=t.length;n<r;n+=1){const o=t.charAt(n);e[o]=(e[o]||0)|1<<r-n-1}return e}const ze=String.prototype.normalize?(t=>t.normalize("NFD").replace(/[\u0300-\u036F\u0483-\u0489\u0591-\u05BD\u05BF\u05C1\u05C2\u05C4\u05C5\u05C7\u0610-\u061A\u064B-\u065F\u0670\u06D6-\u06DC\u06DF-\u06E4\u06E7\u06E8\u06EA-\u06ED\u0711\u0730-\u074A\u07A6-\u07B0\u07EB-\u07F3\u07FD\u0816-\u0819\u081B-\u0823\u0825-\u0827\u0829-\u082D\u0859-\u085B\u08D3-\u08E1\u08E3-\u0903\u093A-\u093C\u093E-\u094F\u0951-\u0957\u0962\u0963\u0981-\u0983\u09BC\u09BE-\u09C4\u09C7\u09C8\u09CB-\u09CD\u09D7\u09E2\u09E3\u09FE\u0A01-\u0A03\u0A3C\u0A3E-\u0A42\u0A47\u0A48\u0A4B-\u0A4D\u0A51\u0A70\u0A71\u0A75\u0A81-\u0A83\u0ABC\u0ABE-\u0AC5\u0AC7-\u0AC9\u0ACB-\u0ACD\u0AE2\u0AE3\u0AFA-\u0AFF\u0B01-\u0B03\u0B3C\u0B3E-\u0B44\u0B47\u0B48\u0B4B-\u0B4D\u0B56\u0B57\u0B62\u0B63\u0B82\u0BBE-\u0BC2\u0BC6-\u0BC8\u0BCA-\u0BCD\u0BD7\u0C00-\u0C04\u0C3E-\u0C44\u0C46-\u0C48\u0C4A-\u0C4D\u0C55\u0C56\u0C62\u0C63\u0C81-\u0C83\u0CBC\u0CBE-\u0CC4\u0CC6-\u0CC8\u0CCA-\u0CCD\u0CD5\u0CD6\u0CE2\u0CE3\u0D00-\u0D03\u0D3B\u0D3C\u0D3E-\u0D44\u0D46-\u0D48\u0D4A-\u0D4D\u0D57\u0D62\u0D63\u0D82\u0D83\u0DCA\u0DCF-\u0DD4\u0DD6\u0DD8-\u0DDF\u0DF2\u0DF3\u0E31\u0E34-\u0E3A\u0E47-\u0E4E\u0EB1\u0EB4-\u0EB9\u0EBB\u0EBC\u0EC8-\u0ECD\u0F18\u0F19\u0F35\u0F37\u0F39\u0F3E\u0F3F\u0F71-\u0F84\u0F86\u0F87\u0F8D-\u0F97\u0F99-\u0FBC\u0FC6\u102B-\u103E\u1056-\u1059\u105E-\u1060\u1062-\u1064\u1067-\u106D\u1071-\u1074\u1082-\u108D\u108F\u109A-\u109D\u135D-\u135F\u1712-\u1714\u1732-\u1734\u1752\u1753\u1772\u1773\u17B4-\u17D3\u17DD\u180B-\u180D\u1885\u1886\u18A9\u1920-\u192B\u1930-\u193B\u1A17-\u1A1B\u1A55-\u1A5E\u1A60-\u1A7C\u1A7F\u1AB0-\u1ABE\u1B00-\u1B04\u1B34-\u1B44\u1B6B-\u1B73\u1B80-\u1B82\u1BA1-\u1BAD\u1BE6-\u1BF3\u1C24-\u1C37\u1CD0-\u1CD2\u1CD4-\u1CE8\u1CED\u1CF2-\u1CF4\u1CF7-\u1CF9\u1DC0-\u1DF9\u1DFB-\u1DFF\u20D0-\u20F0\u2CEF-\u2CF1\u2D7F\u2DE0-\u2DFF\u302A-\u302F\u3099\u309A\uA66F-\uA672\uA674-\uA67D\uA69E\uA69F\uA6F0\uA6F1\uA802\uA806\uA80B\uA823-\uA827\uA880\uA881\uA8B4-\uA8C5\uA8E0-\uA8F1\uA8FF\uA926-\uA92D\uA947-\uA953\uA980-\uA983\uA9B3-\uA9C0\uA9E5\uAA29-\uAA36\uAA43\uAA4C\uAA4D\uAA7B-\uAA7D\uAAB0\uAAB2-\uAAB4\uAAB7\uAAB8\uAABE\uAABF\uAAC1\uAAEB-\uAAEF\uAAF5\uAAF6\uABE3-\uABEA\uABEC\uABED\uFB1E\uFE00-\uFE0F\uFE20-\uFE2F]/g,"")):(t=>t);class Xt{constructor(e,{location:n=C.location,threshold:r=C.threshold,distance:o=C.distance,includeMatches:a=C.includeMatches,findAllMatches:c=C.findAllMatches,minMatchCharLength:u=C.minMatchCharLength,isCaseSensitive:f=C.isCaseSensitive,ignoreDiacritics:l=C.ignoreDiacritics,ignoreLocation:g=C.ignoreLocation}={}){if(this.options={location:n,threshold:r,distance:o,includeMatches:a,findAllMatches:c,minMatchCharLength:u,isCaseSensitive:f,ignoreDiacritics:l,ignoreLocation:g},e=f?e:e.toLowerCase(),e=l?ze(e):e,this.pattern=e,this.chunks=[],!this.pattern.length)return;const x=(E,A)=>{this.chunks.push({pattern:E,alphabet:Us(E),startIndex:A})},y=this.pattern.length;if(y>me){let E=0;const A=y%me,M=y-A;for(;E<M;)x(this.pattern.substr(E,me),E),E+=me;if(A){const S=y-me;x(this.pattern.substr(S),S)}}else x(this.pattern,0)}searchIn(e){const{isCaseSensitive:n,ignoreDiacritics:r,includeMatches:o}=this.options;if(e=n?e:e.toLowerCase(),e=r?ze(e):e,this.pattern===e){let M={isMatch:!0,score:0};return o&&(M.indices=[[0,e.length-1]]),M}const{location:a,distance:c,threshold:u,findAllMatches:f,minMatchCharLength:l,ignoreLocation:g}=this.options;let x=[],y=0,E=!1;this.chunks.forEach(({pattern:M,alphabet:S,startIndex:R})=>{const{isMatch:w,score:j,indices:K}=Os(e,M,S,{location:a+R,distance:c,threshold:u,findAllMatches:f,minMatchCharLength:l,includeMatches:o,ignoreLocation:g});w&&(E=!0),y+=j,w&&K&&(x=[...x,...K])});let A={isMatch:E,score:E?y/this.chunks.length:1};return E&&o&&(A.indices=x),A}}class ue{constructor(e){this.pattern=e}static isMultiMatch(e){return Bt(e,this.multiRegex)}static isSingleMatch(e){return Bt(e,this.singleRegex)}search(){}}function Bt(t,e){const n=t.match(e);return n?n[1]:null}class Gs extends ue{constructor(e){super(e)}static get type(){return"exact"}static get multiRegex(){return/^="(.*)"$/}static get singleRegex(){return/^=(.*)$/}search(e){const n=e===this.pattern;return{isMatch:n,score:n?0:1,indices:[0,this.pattern.length-1]}}}class Hs extends ue{constructor(e){super(e)}static get type(){return"inverse-exact"}static get multiRegex(){return/^!"(.*)"$/}static get singleRegex(){return/^!(.*)$/}search(e){const r=e.indexOf(this.pattern)===-1;return{isMatch:r,score:r?0:1,indices:[0,e.length-1]}}}class Ys extends ue{constructor(e){super(e)}static get type(){return"prefix-exact"}static get multiRegex(){return/^\^"(.*)"$/}static get singleRegex(){return/^\^(.*)$/}search(e){const n=e.startsWith(this.pattern);return{isMatch:n,score:n?0:1,indices:[0,this.pattern.length-1]}}}class Ws extends ue{constructor(e){super(e)}static get type(){return"inverse-prefix-exact"}static get multiRegex(){return/^!\^"(.*)"$/}static get singleRegex(){return/^!\^(.*)$/}search(e){const n=!e.startsWith(this.pattern);return{isMatch:n,score:n?0:1,indices:[0,e.length-1]}}}class qs extends ue{constructor(e){super(e)}static get type(){return"suffix-exact"}static get multiRegex(){return/^"(.*)"\$$/}static get singleRegex(){return/^(.*)\$$/}search(e){const n=e.endsWith(this.pattern);return{isMatch:n,score:n?0:1,indices:[e.length-this.pattern.length,e.length-1]}}}class Vs extends ue{constructor(e){super(e)}static get type(){return"inverse-suffix-exact"}static get multiRegex(){return/^!"(.*)"\$$/}static get singleRegex(){return/^!(.*)\$$/}search(e){const n=!e.endsWith(this.pattern);return{isMatch:n,score:n?0:1,indices:[0,e.length-1]}}}class Jt extends ue{constructor(e,{location:n=C.location,threshold:r=C.threshold,distance:o=C.distance,includeMatches:a=C.includeMatches,findAllMatches:c=C.findAllMatches,minMatchCharLength:u=C.minMatchCharLength,isCaseSensitive:f=C.isCaseSensitive,ignoreDiacritics:l=C.ignoreDiacritics,ignoreLocation:g=C.ignoreLocation}={}){super(e),this._bitapSearch=new Xt(e,{location:n,threshold:r,distance:o,includeMatches:a,findAllMatches:c,minMatchCharLength:u,isCaseSensitive:f,ignoreDiacritics:l,ignoreLocation:g})}static get type(){return"fuzzy"}static get multiRegex(){return/^"(.*)"$/}static get singleRegex(){return/^(.*)$/}search(e){return this._bitapSearch.searchIn(e)}}class Zt extends ue{constructor(e){super(e)}static get type(){return"include"}static get multiRegex(){return/^'"(.*)"$/}static get singleRegex(){return/^'(.*)$/}search(e){let n=0,r;const o=[],a=this.pattern.length;for(;(r=e.indexOf(this.pattern,n))>-1;)n=r+a,o.push([r,n-1]);const c=!!o.length;return{isMatch:c,score:c?0:1,indices:o}}}const st=[Gs,Zt,Ys,Ws,Vs,qs,Hs,Jt],Pt=st.length,Xs=/ +(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)/,Js="|";function Zs(t,e={}){return t.split(Js).map(n=>{let r=n.trim().split(Xs).filter(a=>a&&!!a.trim()),o=[];for(let a=0,c=r.length;a<c;a+=1){const u=r[a];let f=!1,l=-1;for(;!f&&++l<Pt;){const g=st[l];let x=g.isMultiMatch(u);x&&(o.push(new g(x,e)),f=!0)}if(!f)for(l=-1;++l<Pt;){const g=st[l];let x=g.isSingleMatch(u);if(x){o.push(new g(x,e));break}}}return o})}const en=new Set([Jt.type,Zt.type]);class tn{constructor(e,{isCaseSensitive:n=C.isCaseSensitive,ignoreDiacritics:r=C.ignoreDiacritics,includeMatches:o=C.includeMatches,minMatchCharLength:a=C.minMatchCharLength,ignoreLocation:c=C.ignoreLocation,findAllMatches:u=C.findAllMatches,location:f=C.location,threshold:l=C.threshold,distance:g=C.distance}={}){this.query=null,this.options={isCaseSensitive:n,ignoreDiacritics:r,includeMatches:o,minMatchCharLength:a,findAllMatches:u,ignoreLocation:c,location:f,threshold:l,distance:g},e=n?e:e.toLowerCase(),e=r?ze(e):e,this.pattern=e,this.query=Zs(this.pattern,this.options)}static condition(e,n){return n.useExtendedSearch}searchIn(e){const n=this.query;if(!n)return{isMatch:!1,score:1};const{includeMatches:r,isCaseSensitive:o,ignoreDiacritics:a}=this.options;e=o?e:e.toLowerCase(),e=a?ze(e):e;let c=0,u=[],f=0;for(let l=0,g=n.length;l<g;l+=1){const x=n[l];u.length=0,c=0;for(let y=0,E=x.length;y<E;y+=1){const A=x[y],{isMatch:M,indices:S,score:R}=A.search(e);if(M){if(c+=1,f+=R,r){const w=A.constructor.type;en.has(w)?u=[...u,...S]:u.push(S)}}else{f=0,c=0,u.length=0;break}}if(c){let y={isMatch:!0,score:f/c};return r&&(y.indices=u),y}}return{isMatch:!1,score:1}}}const nt=[];function sn(...t){nt.push(...t)}function rt(t,e){for(let n=0,r=nt.length;n<r;n+=1){let o=nt[n];if(o.condition(t,e))return new o(t,e)}return new Xt(t,e)}const Ke={AND:"$and",OR:"$or"},ot={PATH:"$path",PATTERN:"$val"},it=t=>!!(t[Ke.AND]||t[Ke.OR]),nn=t=>!!t[ot.PATH],rn=t=>!ce(t)&&Yt(t)&&!it(t),Qt=t=>({[Ke.AND]:Object.keys(t).map(e=>({[e]:t[e]}))});function es(t,e,{auto:n=!0}={}){const r=o=>{let a=Object.keys(o);const c=nn(o);if(!c&&a.length>1&&!it(o))return r(Qt(o));if(rn(o)){const f=c?o[ot.PATH]:a[0],l=c?o[ot.PATTERN]:o[f];if(!oe(l))throw new Error(Ls(f));const g={keyId:tt(f),pattern:l};return n&&(g.searcher=rt(l,e)),g}let u={children:[],operator:a[0]};return a.forEach(f=>{const l=o[f];ce(l)&&l.forEach(g=>{u.children.push(r(g))})}),u};return it(t)||(t=Qt(t)),r(t)}function on(t,{ignoreFieldNorm:e=C.ignoreFieldNorm}){t.forEach(n=>{let r=1;n.matches.forEach(({key:o,norm:a,score:c})=>{const u=o?o.weight:null;r*=Math.pow(c===0&&u?Number.EPSILON:c,(u||1)*(e?1:a))}),n.score=r})}function an(t,e){const n=t.matches;e.matches=[],X(n)&&n.forEach(r=>{if(!X(r.indices)||!r.indices.length)return;const{indices:o,value:a}=r;let c={indices:o,value:a};r.key&&(c.key=r.key.src),r.idx>-1&&(c.refIndex=r.idx),e.matches.push(c)})}function cn(t,e){e.score=t.score}function un(t,e,{includeMatches:n=C.includeMatches,includeScore:r=C.includeScore}={}){const o=[];return n&&o.push(an),r&&o.push(cn),t.map(a=>{const{idx:c}=a,u={item:e[c],refIndex:c};return o.length&&o.forEach(f=>{f(a,u)}),u})}class ae{constructor(e,n={},r){this.options={...C,...n},this.options.useExtendedSearch,this._keyStore=new Ds(this.options.keys),this.setCollection(e,r)}setCollection(e,n){if(this._docs=e,n&&!(n instanceof at))throw new Error(bs);this._myIndex=n||Vt(this.options.keys,this._docs,{getFn:this.options.getFn,fieldNormWeight:this.options.fieldNormWeight})}add(e){X(e)&&(this._docs.push(e),this._myIndex.add(e))}remove(e=()=>!1){const n=[];for(let r=0,o=this._docs.length;r<o;r+=1){const a=this._docs[r];e(a,r)&&(this.removeAt(r),r-=1,o-=1,n.push(a))}return n}removeAt(e){this._docs.splice(e,1),this._myIndex.removeAt(e)}getIndex(){return this._myIndex}search(e,{limit:n=-1}={}){const{includeMatches:r,includeScore:o,shouldSort:a,sortFn:c,ignoreFieldNorm:u}=this.options;let f=oe(e)?oe(this._docs[0])?this._searchStringList(e):this._searchObjectList(e):this._searchLogical(e);return on(f,{ignoreFieldNorm:u}),a&&f.sort(c),Ht(n)&&n>-1&&(f=f.slice(0,n)),un(f,this._docs,{includeMatches:r,includeScore:o})}_searchStringList(e){const n=rt(e,this.options),{records:r}=this._myIndex,o=[];return r.forEach(({v:a,i:c,n:u})=>{if(!X(a))return;const{isMatch:f,score:l,indices:g}=n.searchIn(a);f&&o.push({item:a,idx:c,matches:[{score:l,value:a,norm:u,indices:g}]})}),o}_searchLogical(e){const n=es(e,this.options),r=(u,f,l)=>{if(!u.children){const{keyId:x,searcher:y}=u,E=this._findMatches({key:this._keyStore.get(x),value:this._myIndex.getValueForItemAtKeyId(f,x),searcher:y});return E&&E.length?[{idx:l,item:f,matches:E}]:[]}const g=[];for(let x=0,y=u.children.length;x<y;x+=1){const E=u.children[x],A=r(E,f,l);if(A.length)g.push(...A);else if(u.operator===Ke.AND)return[]}return g},o=this._myIndex.records,a={},c=[];return o.forEach(({$:u,i:f})=>{if(X(u)){let l=r(n,u,f);l.length&&(a[f]||(a[f]={idx:f,item:u,matches:[]},c.push(a[f])),l.forEach(({matches:g})=>{a[f].matches.push(...g)}))}}),c}_searchObjectList(e){const n=rt(e,this.options),{keys:r,records:o}=this._myIndex,a=[];return o.forEach(({$:c,i:u})=>{if(!X(c))return;let f=[];r.forEach((l,g)=>{f.push(...this._findMatches({key:l,value:c[g],searcher:n}))}),f.length&&a.push({idx:u,item:c,matches:f})}),a}_findMatches({key:e,value:n,searcher:r}){if(!X(n))return[];let o=[];if(ce(n))n.forEach(({v:a,i:c,n:u})=>{if(!X(a))return;const{isMatch:f,score:l,indices:g}=r.searchIn(a);f&&o.push({score:l,key:e,value:a,idx:c,norm:u,indices:g})});else{const{v:a,n:c}=n,{isMatch:u,score:f,indices:l}=r.searchIn(a);u&&o.push({score:f,key:e,value:a,norm:c,indices:l})}return o}}ae.version="7.1.0";ae.createIndex=Vt;ae.parseIndex=zs;ae.config=C;ae.parseQuery=es;sn(tn);function Ie(t){return t.trim().toLowerCase().split(/\s+/).filter(Boolean)}function ln(t){return t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function Qe(t,e){const n=e.trim(),r=Ie(n);if(r.length<=1)return t.search(n);const[o,...a]=r.map(f=>t.search(f)),c=a.map(f=>{const l=new Map;for(const g of f)l.set(g.refIndex,g.score??1);return l}),u=[];for(const f of o){let l=f.score??1,g=!0;for(const x of c){const y=x.get(f.refIndex);if(y===void 0){g=!1;break}l+=y}g&&u.push({item:f.item,score:l/r.length})}return u.sort((f,l)=>(f.score??1)-(l.score??1)),u}function zt(t,e,n){return e===t?6:e.startsWith(t)?5:e.split(/[^a-z0-9]+/i).includes(t)?4:e.includes(t)?3:n.includes(t)?2:1}function hn(t,e,n){const r=Ie(t);if(r.length===0)return 1;const o=e.toLowerCase(),a=n.toLowerCase(),c=zt(r.join(" "),o,a);if(r.length===1)return c;let u=6;for(const f of r)u=Math.min(u,zt(f,o,a));return Math.max(c,u)}const fn=4;function Kt(t){return t.replace(/…|\.\.\./g," ").replace(/\s+/g," ").trim().toLowerCase()}const dn=24;function gn(t,e){const n=Kt(t),r=Kt(e);return n===r?!0:Math.min(n.length,r.length)<dn?!1:n.includes(r)||r.includes(n)}function mn(t,e){const n=[],r=o=>{!o||!o.text.trim()||n.length>=fn||n.some(a=>gn(a.text,o.text))||n.push(o)};t&&r({text:t,kind:"user"});for(const o of e??[])r(o);return n.length>0?n:void 0}async function pn(t){const e=new URLSearchParams({q:t}),n=await Ze(et(`/api/folders/search?${e.toString()}`));if(!n.ok){const o=await n.json().catch(()=>({}));throw new Error(o.error||`Failed to search folders: ${n.statusText}`)}const r=await n.json();return Array.isArray(r.folders)?r.folders:[]}const Ot=["agent","session","building","file","file-content","folder","area"],yn=2,An=2,xn=50,En=10,Mn=3,Cn=30,In=8,_n=3,Sn=15,Xe=5,Je=5;function vn(){const t=Gt(_e.SPOTLIGHT_TAB,"all");return ye.includes(t)?t:"all"}function Ut(){return Ms(_e.SPOTLIGHT_QUERY,"")}function wn(){const t=Gt(_e.AOP_CONFIG,{});return t.sortMode==="name"||t.sortMode==="status"||t.sortMode==="recent"?t.sortMode:"recent"}function bn({isOpen:t,onClose:e,onOpenSpawnModal:n,onOpenCommanderView:r,onOpenToolbox:o,onOpenFileExplorer:a,onOpenPM2LogsModal:c,onOpenBossLogsModal:u,onOpenDatabasePanel:f,onOpenMonitoringModal:l,onOpenSessionFinder:g,onOpenFileDetail:x}){const y=cs(),E=us(),A=ls(),M=hs(),S=fs(),R=ds(),w=h.useRef(e);w.current=e;const j=h.useRef(n);j.current=n;const K=h.useRef(r);K.current=r;const le=h.useRef(o);le.current=o;const he=h.useRef(a);he.current=a;const B=h.useRef(c);B.current=c;const Y=h.useRef(u);Y.current=u;const G=h.useRef(f);G.current=f;const ie=h.useRef(l);ie.current=l;const re=h.useRef(g);re.current=g;const J=h.useRef(x);J.current=x;const[F,O]=h.useState(Ut),[W,N]=h.useState(0),[v,ee]=h.useState(vn),[Ae,te]=h.useState([]),[ct,xe]=h.useState([]),[ut,Ee]=h.useState([]),[lt,Se]=h.useState(!1),[ht,ve]=h.useState(!1),[ft,we]=h.useState(!1),[dt,be]=h.useState(!1),[Le,Me]=h.useState({query:"",rows:[]}),[gt,mt]=h.useState(!1),[pt,yt]=h.useState(!1);h.useEffect(()=>{mt(!1),yt(!1)},[F,t]);const ts=h.useCallback(s=>{O(s),gs(_e.SPOTLIGHT_QUERY,s)},[]);h.useEffect(()=>{t&&(O(Ut()),N(0))},[t]),h.useEffect(()=>{if(!t){te([]),Se(!1);return}const s=F.trim();if(s.length<yn){te([]),Se(!1);return}te([]),Se(!0);let i=!1;const m=setTimeout(()=>{pn(s).then(I=>{i||te(I)}).catch(()=>{i||te([])}).finally(()=>{i||Se(!1)})},250);return()=>{i=!0,clearTimeout(m)}},[t,F]);const At=(M.fileSearchExcludeDirs??Ye).join(",");h.useEffect(()=>{if(!t){xe([]),ve(!1);return}const s=F.trim();if(s.length<An){xe([]),ve(!1);return}xe([]),ve(!0);let i=!1;const m=setTimeout(()=>{ms(s,{exclude:M.fileSearchExcludeDirs??[...Ye],limit:xn}).then(I=>{i||xe(I)}).catch(()=>{i||xe([])}).finally(()=>{i||ve(!1)})},250);return()=>{i=!0,clearTimeout(m)}},[t,F,At,M.fileSearchExcludeDirs]),h.useEffect(()=>{if(!t){Ee([]),we(!1);return}const s=F.trim();if(s.length<Mn){Ee([]),we(!1);return}Ee([]),we(!0);const i=new AbortController,m=setTimeout(()=>{ps(s,{exclude:M.fileSearchExcludeDirs??[...Ye],limit:Cn,signal:i.signal}).then(I=>{i.signal.aborted||Ee(I)}).catch(()=>{i.signal.aborted||Ee([])}).finally(()=>{i.signal.aborted||we(!1)})},300);return()=>{clearTimeout(m),i.abort()}},[t,F,At,M.fileSearchExcludeDirs]),h.useEffect(()=>{if(!t){Me({query:"",rows:[]}),be(!1);return}const s=F.trim();if(s.length<_n){Me({query:"",rows:[]}),be(!1);return}Me({query:"",rows:[]}),be(!0);let i=!1;const m=setTimeout(()=>{ys(s,{limit:Sn}).then(I=>{i||Me({query:s,rows:I})}).catch(()=>{i||Me({query:"",rows:[]})}).finally(()=>{i||be(!1)})},250);return()=>{i=!0,clearTimeout(m)}},[t,F]);const Ue=h.useCallback(s=>{ee(s),As(_e.SPOTLIGHT_TAB,s)},[]),xt=h.useRef(v);xt.current=v;const ss=h.useCallback(s=>{const i=ye.indexOf(xt.current),m=ye[(i+s+ye.length)%ye.length];Ue(m)},[Ue]);h.useEffect(()=>{N(0)},[v]);const Ge=U.getShortcuts(),Te=h.useMemo(()=>t?xs():{},[t]),Fe=h.useMemo(()=>{if(!t)return[];const s=window.matchMedia("(pointer: coarse)").matches,i=Ge.find(I=>I.id==="spawn-agent"),m=Ge.find(I=>I.id==="toggle-commander");return[{id:"cmd-spawn",type:"command",title:"Spawn New Agent",subtitle:s?"":i?Tt(i):"Alt+N",icon:d.jsx(V,{name:"plus",size:16}),action:()=>{w.current(),j.current()}},{id:"cmd-commander",type:"command",title:"Commander View",subtitle:s?"":m!=null&&m.key?Tt(m):"Tab",icon:d.jsx(V,{name:"dashboard",size:16}),action:()=>{w.current(),K.current()}},{id:"cmd-settings",type:"command",title:"Settings & Tools",subtitle:"Configure Tide Commander",icon:d.jsx(V,{name:"gear",size:16}),action:()=>{w.current(),le.current()}},{id:"cmd-monitoring",type:"command",title:"Monitoring & Logs",subtitle:"Triggers, workflows, events",icon:d.jsx(V,{name:"chart-line",size:16}),action:()=>{var I;w.current(),(I=ie.current)==null||I.call(ie)}}]},[t,Ge]),Ne=h.useMemo(()=>{const s=new Map;if(!t)return s;const i=Array.from(E.values());for(const m of y.values())for(const I of i)if(U.isPositionInArea({x:m.position.x,z:m.position.z},I)){s.set(m.id,I);break}return s},[t,y,E]),pe=h.useMemo(()=>t?Array.from(y.values()).map(s=>{const i=[];s.lastAssignedTask&&i.push(s.lastAssignedTask);const m=`${s.class} • ${s.cwd}`,I=Ne.get(s.id),k=(I==null?void 0:I.name)||"";let b=`${s.name} ${s.class} ${s.status} ${s.cwd}`;s.taskLabel&&(b+=` ${s.taskLabel}`),k&&(b+=` ${k}`),i.length>0&&(b+=` ${i.join(" ")}`);const $=Date.now()-s.lastActivity;let D;return s.lastAssignedTask&&(s.lastAssignedTask.length>150?D=s.lastAssignedTask.slice(0,150)+"...":D=s.lastAssignedTask),{id:`agent-${s.id}`,type:"agent",title:s.name,subtitle:m,lastUserInput:D,timeAway:$,icon:d.jsx(Nt,{agent:s,size:20}),_searchText:b,_userQueries:i,_agentId:s.id,_lastActivity:s.lastActivity,_taskLabel:s.taskLabel,_status:s.status,_provider:s.provider??"claude",_piModel:s.piModel,_piModelProvider:s.piModelProvider,_areaName:k||void 0,_areaColor:I==null?void 0:I.color,action:()=>{w.current(),Ft(s.id),U.selectAgent(s.id),U.getState().viewMode!=="flat"&&U.requestTerminalExpand()}}}):[],[t,y,Ne]),De=h.useMemo(()=>t?Array.from(E.values()).map(s=>{var i;return{id:`area-${s.id}`,type:"area",title:s.name,subtitle:`${s.assignedAgentIds.length} agents • ${((i=s.directories)==null?void 0:i.length)||0} folders`,icon:d.jsx(V,{name:"map",size:16}),action:()=>{w.current(),U.selectArea(s.id)}}}):[],[t,E]),Re=h.useMemo(()=>{const s=new Map;for(const i of pe)i._agentId&&s.set(i._agentId,i);return s},[pe]),Et=h.useMemo(()=>{const s=new Map;if(!t)return s;for(const i of y.values()){const m=Ne.get(i.id);if(!m||m.archived)continue;const I=s.get(m.id);I?I.push(i):s.set(m.id,[i])}return s},[t,y,Ne]),Mt=h.useMemo(()=>{const s=new Map;for(const i of S)s.has(i.agentId)||s.set(i.agentId,i.timestamp);return s},[S]),He=h.useMemo(()=>{if(!t)return[];const s=F.trim().toLowerCase(),i=Ie(s),m=Es({sortMode:wn(),agentsWithUnseenOutput:R,getLatestToolTimestamp:b=>Mt.get(b)}),I=Array.from(E.values()).filter(b=>!b.archived).filter(b=>{if(i.length===0)return!0;const $=b.name.toLowerCase();return i.some(D=>$.includes(D))}).sort((b,$)=>b.name.localeCompare($.name,void 0,{sensitivity:"base"})),k=[];for(const b of I){const $=b.name.toLowerCase(),D=i.filter(P=>!$.includes(P));let H=(Et.get(b.id)||[]).slice().sort(m).map(P=>Re.get(P.id)).filter(P=>!!P);D.length>0&&(H=H.filter(P=>{const Z=`${P.title} ${P.subtitle||""} ${P._searchText||""}`.toLowerCase();return D.every(Q=>Z.includes(Q))}),H.length===0)||!s&&H.length===0||k.push({areaId:b.id,areaName:b.name,areaColor:b.color,agents:H})}return k},[t,F,E,Et,Re,R,Mt]),je=h.useMemo(()=>t?Array.from(A.values()).filter(s=>s.type==="server"||s.type==="boss"||s.type==="database"||s.type==="tests").map(s=>{var D,q,H,P,Z;const i=s.status==="running"?"#4ade80":s.status==="stopped"?"#f87171":"#facc15",m=s.type==="boss"?"crown":s.type==="database"?"database":s.type==="tests"?"flask":"desktop",I=s.type==="boss"?"Boss":s.type==="database"?"Database":s.type==="tests"?"Tests":"Server";let k=`${I} • ${s.status}`;if(s.type==="database"&&((q=(D=s.database)==null?void 0:D.connections)!=null&&q.length)){const Q=s.database.connections[0];k+=` • ${Q.engine} @ ${Q.host}`}else s.type==="tests"&&s.folderPath?k=`${I} • ${s.folderPath}`:s.cwd&&(k+=` • ${s.cwd}`);const b=((H=s.pm2Status)==null?void 0:H.ports)||[];let $=`${s.name} ${s.type} ${s.status} ${s.cwd||""} ${((P=s.pm2)==null?void 0:P.name)||""}`;if(s.type==="tests"&&($+=` ${s.folderPath||""} tests junit maven`),b.length>0&&($+=` ${b.join(" ")}`),s.type==="database"&&((Z=s.database)!=null&&Z.connections))for(const Q of s.database.connections)$+=` ${Q.name} ${Q.engine} ${Q.host} ${Q.database||""} mysql postgresql sql`;return{id:`building-${s.id}`,type:"building",title:s.name,subtitle:k,_ports:b,icon:d.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:4},children:[d.jsx(V,{name:"status-pending",size:10,weight:"fill",color:i}),d.jsx(V,{name:m,size:16})]}),_searchText:$,action:()=>{var Q;w.current(),s.type==="boss"?Y.current(s.id):s.type==="database"?G.current(s.id):s.type==="tests"?U.openTestsBuilding(s.id):s.type==="http"?U.openHttpBuilding(s.id):(Q=s.pm2)!=null&&Q.enabled&&B.current(s.id)}}}):[],[t,A]),Ct=h.useMemo(()=>t?Ae.map(s=>{const i=s.isGitRepo&&s.gitBranch?`${s.path} • ${s.gitBranch}`:s.path;return{id:`folder-${s.path}`,type:"folder",title:s.name,subtitle:i,matchedText:s.path,icon:d.jsx(V,{name:s.isGitRepo?"git-branch":"folder",size:16}),_searchText:`${s.name} ${s.path}`,_isGitRepo:s.isGitRepo,_gitBranch:s.gitBranch,action:()=>{w.current(),U.openFileExplorer(s.path)}}}):[],[t,Ae]),ke=h.useMemo(()=>t?ct.map(s=>{const i=s.areaName&&s.areaName!==s.projectName?`${s.projectName} · ${s.areaName}`:s.projectName;return{id:`file-${s.path}`,type:"file",title:s.name,subtitle:s.relativePath,matchedText:`${s.path} ${i}`,icon:Dt(s.path),_searchText:`${s.name} ${s.relativePath} ${s.path} ${s.projectName} ${s.areaName}`,_projectName:s.projectName,_areaName:s.areaName,action:()=>{w.current(),J.current({filePath:s.path,projectRoot:s.projectRoot,searchQuery:F.trim()})}}}):[],[t,ct,F]),$e=h.useMemo(()=>t?ut.map(s=>{const i=s.matches[0],m=s.areaName&&s.areaName!==s.projectName?`${s.projectName} · ${s.areaName}`:s.projectName;return{id:`file-content-${s.path}`,type:"file-content",title:s.name,subtitle:`${s.relativePath}${i!=null&&i.line?`:${i.line}`:""}`,matchedQuery:i==null?void 0:i.content,matchedText:`${s.path} ${m}`,icon:Dt(s.path),_projectName:s.projectName,_areaName:s.areaName,_lineNumber:i==null?void 0:i.line,action:()=>{w.current(),J.current({filePath:s.path,projectRoot:s.projectRoot,targetLine:i==null?void 0:i.line,searchQuery:F.trim()})}}}):[],[t,ut,F]),fe=h.useMemo(()=>{if(!t)return[];const s=i=>{const m=Date.now()-new Date(i).getTime();return!Number.isFinite(m)||m<0?"":m<36e5?`${Math.max(1,Math.floor(m/6e4))}m`:m<864e5?`${Math.floor(m/36e5)}h`:`${Math.floor(m/864e5)}d`};return Le.rows.map(i=>{const m=Array.from(y.values()).find(D=>D.sessionId===i.sessionId),I=m??(i.agentId?y.get(i.agentId):void 0),k=(i.firstPrompt||i.snippet||i.sessionId).slice(0,90),b=[i.projectPath||i.projectDir];I&&b.push(`→ ${I.name}${m?"":" (past session)"}`);const $=s(i.lastModified);return $&&b.push($),b.push(`${i.totalMatches}×`),{id:`session-${i.sessionId}`,type:"session",title:k,subtitle:b.join(" • "),matchedQuery:i.snippet||void 0,matchedExtracts:i.extracts&&i.extracts.length>0?i.extracts:void 0,_agentId:I==null?void 0:I.id,_sessionMatches:i.totalMatches,_provider:i.provider||"claude",icon:I?d.jsx(Nt,{agent:I,size:20}):d.jsx(V,{name:"history",size:16}),action:()=>{var q;w.current();const D=Array.from(U.getState().agents.values()).find(H=>H.sessionId===i.sessionId);D?(Ft(D.id),U.selectAgent(D.id),U.getState().viewMode!=="flat"&&U.requestTerminalExpand(),U.requestTerminalSearch(D.id,Le.query)):(q=re.current)==null||q.call(re,{initialQuery:Le.query,initialSessionKey:`${i.projectPath}::${i.sessionId}`})}}})},[t,Le,y]),It=h.useMemo(()=>new ae(pe,{keys:["title","subtitle","_searchText","lastUserInput"],threshold:.4,ignoreLocation:!0,includeScore:!0,includeMatches:!0}),[pe]),_t=h.useMemo(()=>new ae(Fe,{keys:["title","subtitle"],threshold:.4,includeScore:!0,includeMatches:!0}),[Fe]),St=h.useMemo(()=>new ae(De,{keys:["title","subtitle"],threshold:.4,includeScore:!0,includeMatches:!0}),[De]),vt=h.useMemo(()=>new ae(je,{keys:["title","subtitle","_searchText"],threshold:.4,ignoreLocation:!0,includeScore:!0,includeMatches:!0}),[je]),Ce=h.useMemo(()=>{if(!F.trim()){const p=[];p.push(...je);const _=[...pe].sort((T,z)=>{const ne=We(T._agentId,T._lastActivity,Te);return We(z._agentId,z._lastActivity,Te)-ne});p.push(..._),p.push(...De.slice(0,2));const L={};return Ot.forEach((T,z)=>{L[T]=z}),p.sort((T,z)=>(L[T.type]??999)-(L[z.type]??999)),p}const s=F.trim().toLowerCase(),i=Ie(s),m=Qe(It,F).slice(0,30),I=Qe(St,F).slice(0,2),k=Ct.slice(0,8),b=ke.slice(0,En),$=Qe(vt,F).filter(p=>{const _=p.score??1,L=`${p.item.title} ${p.item.subtitle||""} ${p.item._searchText||""}`.toLowerCase();return i.every(T=>L.includes(T))||_<=.2}).slice(0,4),D={agent:6,building:5,folder:4,file:4,"file-content":4,command:3,area:2,"modified-file":1,session:0},q=p=>hn(s,p.title,`${p.subtitle||""} ${p._searchText||""} ${p.matchedText||""}`),H=(p,_)=>{const L=(1-Math.min(1,_??1))*4;return q(p)*100+(D[p.type]??0)*5+L},P=new Map,Z=(p,_)=>{const L=P.get(p.type),T={item:p,score:H(p,_)};L?L.push(T):P.set(p.type,[T])},Q=new Map;for(const p of fe)p._agentId&&!Q.has(p._agentId)&&Q.set(p._agentId,p);for(const p of m){const _={...p.item};if(_._userQueries&&_._userQueries.length>0){const T=_._userQueries.find(z=>i.some(ne=>z.toLowerCase().includes(ne)));if(T){const z=T.toLowerCase(),ne=z.includes(s)?s:i.find(ge=>z.includes(ge))??s;if(T.length>200){const ge=z.indexOf(ne),bt=Math.max(0,ge-60),Lt=Math.min(T.length,ge+ne.length+100);_.matchedQuery=(bt>0?"...":"")+T.slice(bt,Lt)+(Lt<T.length?"...":"")}else _.matchedQuery=T}}const L=_._agentId?Q.get(_._agentId):void 0;if(L){_.matchedQuery||(_.matchedQuery=L.matchedQuery);const T=_.matchedQuery,z=(T==null?void 0:T.toLowerCase())??"";_.matchedExtracts=mn(T&&i.every(ne=>z.includes(ne))?T:void 0,L.matchedExtracts),_.action=L.action,_._sessionMatches=L._sessionMatches,_._searchText=`${_._searchText||""} ${L.matchedQuery||""} ${s}`}Z(_,p.score)}for(const[p,_]of Q){if(m.some(T=>T.item._agentId===p))continue;const L=Re.get(p);L&&Z({...L,matchedQuery:_.matchedQuery,matchedExtracts:_.matchedExtracts,action:_.action,_sessionMatches:_._sessionMatches,_searchText:`${L._searchText||""} ${_.matchedQuery||""} ${s}`},void 0)}for(const p of $)Z(p.item,p.score);for(const p of I)Z(p.item,p.score);for(const p of k)Z(p,void 0);for(const p of b)Z(p,void 0);for(const p of $e.slice(0,In))Z(p,void 0);const is=24*36e5,as=Date.now(),wt=p=>{const _=We(p.item._agentId,p.item._lastActivity,Te),L=Math.exp(-Math.LN2*Math.max(0,as-_)/is);return Math.log2(1+(p.item._sessionMatches??0))+4*L};for(const[p,_]of P)p==="agent"?_.sort((L,T)=>{const z=q(L.item),ne=q(T.item);if(ne!==z)return ne-z;const Be=wt(L),ge=wt(T);return ge!==Be?ge-Be:T.score-L.score}):_.sort((L,T)=>T.score-L.score);const de=[];for(const p of Ot){if(p==="session"){!pt&&fe.length>Xe?(de.push(...fe.slice(0,Xe)),de.push({id:"session-show-all",type:"session",title:`Show all conversations (${fe.length})`,subtitle:`${fe.length-Xe} more matches`,icon:d.jsx(V,{name:"arrow-down",size:16}),action:()=>yt(!0)})):de.push(...fe);continue}const _=P.get(p);if(_){if(p==="agent"&&!gt&&_.length>Je){for(const L of _.slice(0,Je))de.push(L.item);de.push({id:"agent-show-all",type:"agent",title:`Show all agents (${_.length})`,subtitle:`${_.length-Je} more matches`,icon:d.jsx(V,{name:"arrow-down",size:16}),action:()=>mt(!0)});continue}for(const L of _)de.push(L.item)}}return de},[F,It,St,vt,pe,Re,De,je,Ct,ke,$e,fe,Te,gt,pt]),se=h.useMemo(()=>{switch(v){case"agents":return Ce.filter(s=>s.type==="agent");case"buildings":return Ce.filter(s=>s.type==="building");case"commands":return F.trim()?Qe(_t,F).slice(0,3).map(s=>s.item):Fe;case"folders":return Ce.filter(s=>s.type==="folder");case"files":return ke;case"contents":return $e;case"areas":return He.flatMap(s=>s.agents);case"all":default:return Ce}},[v,Ce,He,ke,$e,F,_t,Fe]),ns=h.useMemo(()=>{const s=[];if(dt&&s.push("session"),ht&&s.push("file"),ft&&s.push("file-content"),lt&&s.push("folder"),v==="all")return s;const m={buildings:"building",folders:"folder",files:"file",contents:"file-content",agents:"agent",commands:"command"}[v];return m&&s.includes(m)?[m]:[]},[v,dt,ht,ft,lt]);h.useEffect(()=>{W>=se.length&&N(Math.max(0,se.length-1))},[se.length,W]);const rs=h.useCallback(s=>{if(s.altKey&&!s.ctrlKey&&!s.metaKey&&(s.key==="p"||s.key==="n"||s.key==="P"||s.key==="N")){s.preventDefault(),s.stopPropagation(),s.nativeEvent.stopImmediatePropagation();const i=s.key.toLowerCase();N(i==="p"?m=>m>0?m-1:se.length-1:m=>m<se.length-1?m+1:0);return}switch(s.key){case"Escape":s.preventDefault(),w.current();break;case"ArrowUp":s.preventDefault(),N(i=>i>0?i-1:se.length-1);break;case"ArrowDown":s.preventDefault(),N(i=>i<se.length-1?i+1:0);break;case"Enter":s.preventDefault(),se[W]&&se[W].action();break}},[se,W]),os=h.useCallback((s,i)=>{if(!i||!s)return s;const m=Ie(i);if(m.length===0)return s;const I=new RegExp(m.map(ln).sort((q,H)=>H.length-q.length).join("|"),"gi"),k=[];let b=0,$=0,D;for(;(D=I.exec(s))!==null;)D.index>b&&k.push(s.slice(b,D.index)),k.push(qe.createElement("mark",{key:$++,className:"spotlight-highlight"},D[0])),b=D.index+D[0].length;return b<s.length&&k.push(s.slice(b)),k.length>0?qe.createElement(qe.Fragment,null,...k):s},[]);return{query:F,setQuery:ts,selectedIndex:W,setSelectedIndex:N,results:se,loadingTypes:ns,activeTab:v,setActiveTab:Ue,cycleTab:ss,areaSections:He,handleKeyDown:rs,highlightMatch:os}}const Ln=h.forwardRef(function({query:e,onQueryChange:n,onKeyDown:r,onResetSelection:o},a){const{t:c}=Oe(["common"]);return d.jsxs("div",{className:"spotlight-input-wrapper",children:[d.jsx("span",{className:"spotlight-search-icon",children:"⌘"}),d.jsx("input",{ref:a,type:"text",className:"spotlight-input",placeholder:c("common:search.spotlightPlaceholder"),value:e,onChange:u=>{n(u.target.value),o()},onKeyDown:r,autoFocus:!0,spellCheck:!1}),d.jsxs("div",{className:"spotlight-input-hints",children:[d.jsx("span",{className:"spotlight-shortcut-hint",children:"↑↓"}),d.jsx("span",{className:"spotlight-shortcut-hint",children:"Enter"}),d.jsx("span",{className:"spotlight-shortcut-hint",children:"Esc"})]})]})}),Tn=h.memo(function({activeTab:e,onSelect:n}){const{t:r}=Oe(["terminal"]);return d.jsxs("div",{className:"spotlight-tabs",role:"tablist","aria-label":r("terminal:spotlight.tabsLabel"),children:[ye.map(o=>d.jsx("button",{type:"button",role:"tab","aria-selected":o===e,tabIndex:-1,className:`spotlight-tab${o===e?" active":""}`,onClick:()=>n(o),children:r(`terminal:spotlight.tabs.${o}`)},o)),d.jsx("span",{className:"spotlight-tabs-hint",children:d.jsx("kbd",{children:"Tab"})})]})}),Fn=h.forwardRef(function({results:e,loadingTypes:n,selectedIndex:r,query:o,activeTab:a,areaSections:c,highlightMatch:u,onSelectIndex:f},l){const{t:g}=Oe(["terminal"]),x=h.useRef(!1);h.useEffect(()=>{x.current=!1},[e]),h.useEffect(()=>{const A=typeof l=="function"?null:l==null?void 0:l.current;if(!A)return;const M=()=>{x.current=!0};return A.addEventListener("mousemove",M),()=>{A.removeEventListener("mousemove",M)}},[l,e]);const y={command:g("terminal:spotlight.categories.commands"),agent:g("terminal:spotlight.categories.agents"),building:g("terminal:spotlight.categories.infrastructure"),area:g("terminal:spotlight.categories.areas"),folder:g("terminal:spotlight.categories.folders"),file:g("terminal:spotlight.categories.files"),"file-content":g("terminal:spotlight.categories.fileContents"),"modified-file":g("terminal:spotlight.categories.modifiedFiles"),session:g("terminal:spotlight.categories.sessions")},E=h.useMemo(()=>{const A=[];let M=null,S=[];e.forEach((w,j)=>{w.type!==M&&(M!==null&&S.length>0&&A.push([M,S]),M=w.type,S=[]),S.push({result:w,index:j})}),M!==null&&S.length>0&&A.push([M,S]);for(const w of n)A.some(([j])=>j===w)||A.push([w,[]]);const R=["agent","session","building","file","file-content","folder","area","command"];return A.sort(([w],[j])=>R.indexOf(w)-R.indexOf(j)),A},[e,n]);if(h.useEffect(()=>{if(!l||typeof l=="function")return;const A=l.current;if(!A)return;const M=A.querySelector(".spotlight-item.selected");M&&M.scrollIntoView({block:"nearest",behavior:"smooth"})},[r,l]),a==="areas"){if(c.length===0)return d.jsx("div",{className:"spotlight-results",ref:l,children:d.jsx("div",{className:"spotlight-empty",children:g("terminal:spotlight.noResults")})});let A=0;return d.jsx("div",{className:"spotlight-results",ref:l,children:c.map(M=>d.jsxs("div",{children:[d.jsxs("div",{className:"spotlight-category-header spotlight-area-section-header",children:[d.jsx("span",{className:"spotlight-area-dot",style:{background:M.areaColor},"aria-hidden":"true"}),d.jsx("span",{className:"spotlight-area-name",children:M.areaName}),d.jsx("span",{className:"spotlight-area-count",children:M.agents.length})]}),M.agents.length===0?d.jsx("div",{className:"spotlight-area-empty",children:g("terminal:spotlight.noAgentsInArea")}):M.agents.map(S=>{const R=A++;return d.jsx(Rt,{result:S,isSelected:R===r,query:o,highlightMatch:u,onClick:()=>S.action(),onMouseEnter:()=>{x.current&&f(R)}},S.id)})]},M.areaId))})}return e.length===0&&n.length===0?d.jsx("div",{className:"spotlight-results",ref:l,children:d.jsx("div",{className:"spotlight-empty",children:g("terminal:spotlight.noResults")})}):d.jsx("div",{className:"spotlight-results",ref:l,children:E.map(([A,M])=>d.jsxs("div",{children:[(a==="all"||E.length>1)&&d.jsx("div",{className:"spotlight-category-header",children:y[A]||A}),n.includes(A)&&d.jsxs("div",{className:"spotlight-block-loading",role:"status",children:[d.jsx("span",{className:"spotlight-loading-spinner","aria-hidden":"true"}),g("terminal:spotlight.searching")]}),M.map(({result:S,index:R})=>d.jsx(Rt,{result:S,isSelected:R===r,query:o,highlightMatch:u,onClick:()=>S.action(),onMouseEnter:()=>{x.current&&f(R)}},S.id))]},A))})}),Nn=h.memo(function(){const{t:e}=Oe(["terminal"]);return d.jsxs("div",{className:"spotlight-footer",children:[d.jsxs("div",{className:"spotlight-footer-left",children:[d.jsxs("span",{className:"spotlight-footer-hint",children:[d.jsx("kbd",{children:"↑"}),d.jsx("kbd",{children:"↓"})," ",d.jsx("kbd",{children:"Alt+N"}),d.jsx("kbd",{children:"Alt+P"})," ",e("terminal:spotlight.navigate")]}),d.jsxs("span",{className:"spotlight-footer-hint",children:[d.jsx("kbd",{children:"Enter"})," ",e("terminal:spotlight.select")]}),d.jsxs("span",{className:"spotlight-footer-hint",children:[d.jsx("kbd",{children:"Tab"})," ",e("terminal:spotlight.switchTabs")]})]}),d.jsx("div",{className:"spotlight-footer-right",children:d.jsxs("span",{className:"spotlight-footer-hint",children:[d.jsx("kbd",{children:"Esc"})," ",e("common:buttons.close")]})})]})});function Dn({detail:t,onClose:e}){const[n,r]=h.useState(null),[o,a]=h.useState(!0),[c,u]=h.useState(null);Cs("spotlight-file-detail",!0,e),h.useEffect(()=>{const E=new AbortController;return a(!0),u(null),r(null),(async()=>{try{const M=await Ze(et(`/api/files/read?path=${encodeURIComponent(t.filePath)}`),{signal:E.signal}),S=await M.json();if(!M.ok)throw new Error(S.error||"Unable to read file");let R=null;if(!S.binary)try{const w=await Ze(et(`/api/files/git-original?path=${encodeURIComponent(t.filePath)}`),{signal:E.signal}),j=await w.json();w.ok&&!j.binary&&typeof j.content=="string"&&(R=j.content)}catch{}E.signal.aborted||r({filename:S.filename||t.filePath.split("/").pop()||t.filePath,content:typeof S.content=="string"?S.content:"",originalContent:R,binary:S.binary===!0})}catch(M){E.signal.aborted||u(M instanceof Error?M.message:"Unable to load file")}finally{E.signal.aborted||a(!1)}})(),()=>E.abort()},[t.filePath]),h.useEffect(()=>{const E=A=>{A.key==="Escape"&&(A.preventDefault(),A.stopImmediatePropagation(),e())};return document.addEventListener("keydown",E,!0),()=>document.removeEventListener("keydown",E,!0)},[e]);const f=()=>{U.revealFileInExplorer(t.filePath,t.projectRoot,t.targetLine),e()},l=(n==null?void 0:n.filename)||t.filePath,g=l.lastIndexOf(".")>=0?l.slice(l.lastIndexOf(".")):"",x=Is(g),y=(n==null?void 0:n.originalContent)!=null&&n.originalContent!==n.content;return d.jsx("div",{className:"guake-git-diff-modal-overlay",onClick:e,children:d.jsxs("div",{className:"guake-git-diff-modal",onClick:E=>E.stopPropagation(),children:[d.jsxs("div",{className:"guake-git-diff-modal-header",children:[d.jsxs("div",{className:"guake-git-diff-path spotlight-file-detail-path",title:t.filePath,children:[t.filePath,t.targetLine?d.jsxs("span",{className:"spotlight-file-detail-line",children:[":",t.targetLine]}):null]}),d.jsxs("button",{type:"button",className:"spotlight-file-detail-explorer",onClick:f,title:"Open in File Explorer",children:[d.jsx(V,{name:"folder-open",size:14}),"Open in File Explorer"]}),d.jsx("button",{className:"guake-git-close",onClick:e,title:"Close (Esc)",children:d.jsx(V,{name:"close",size:14})})]}),d.jsxs("div",{className:"guake-git-diff-content",children:[o&&d.jsx("div",{className:"guake-git-diff-loading-overlay",children:d.jsx("div",{className:"diff-image-spinner"})}),c&&d.jsx("div",{className:"spotlight-file-detail-message",children:c}),(n==null?void 0:n.binary)&&d.jsx("div",{className:"spotlight-file-detail-message",children:"Binary preview is available in the File Explorer."}),n&&!n.binary&&(y?d.jsx(jt,{originalContent:n.originalContent||"",modifiedContent:n.content,filename:n.filename,filePath:t.filePath,language:x,searchQuery:t.searchQuery,targetLine:t.targetLine}):d.jsx(jt,{originalContent:"",modifiedContent:n.content,filename:n.filename,filePath:t.filePath,language:x,initialModifiedOnly:!0,searchQuery:t.searchQuery,targetLine:t.targetLine,readOnly:!0}))]})]})})}const Rn=768;function Bn({isOpen:t,onClose:e,onOpenSpawnModal:n,onOpenCommanderView:r,onOpenToolbox:o,onOpenFileExplorer:a,onOpenPM2LogsModal:c,onOpenBossLogsModal:u,onOpenDatabasePanel:f,onOpenMonitoringModal:l,onOpenSessionFinder:g}){const x=h.useRef(null),y=h.useRef(null),E=h.useRef(null),A=h.useRef(0),[M,S]=h.useState(null),{query:R,setQuery:w,selectedIndex:j,setSelectedIndex:K,results:le,loadingTypes:he,activeTab:B,setActiveTab:Y,cycleTab:G,areaSections:ie,handleKeyDown:re,highlightMatch:J}=bn({isOpen:t,onClose:e,onOpenSpawnModal:n,onOpenCommanderView:r,onOpenToolbox:o,onOpenFileExplorer:a,onOpenPM2LogsModal:c,onOpenBossLogsModal:u,onOpenDatabasePanel:f,onOpenMonitoringModal:l,onOpenSessionFinder:g,onOpenFileDetail:S});A.current=le.length;const F=h.useRef(G);F.current=G,h.useEffect(()=>{t&&setTimeout(()=>{var N,v;(N=x.current)==null||N.focus(),(v=x.current)==null||v.select()},50)},[t]),h.useEffect(()=>{if(!t)return;const N=window.visualViewport;if(!N||window.innerWidth>Rn)return;const v=()=>{const ee=y.current;ee&&(ee.style.height=`${N.height}px`,ee.style.top=`${N.offsetTop}px`)};return v(),N.addEventListener("resize",v),N.addEventListener("scroll",v),()=>{N.removeEventListener("resize",v),N.removeEventListener("scroll",v);const ee=y.current;ee&&(ee.style.height="",ee.style.top="")}},[t]),h.useEffect(()=>{if(!t)return;const N=v=>{if(v.key==="Escape"){v.preventDefault(),v.stopPropagation(),v.stopImmediatePropagation(),e();return}if(v.key==="Tab"){v.preventDefault(),v.stopPropagation(),v.stopImmediatePropagation(),F.current(v.shiftKey?-1:1);return}if(v.altKey&&!v.ctrlKey&&!v.metaKey&&(v.key==="n"||v.key==="p"||v.key==="N"||v.key==="P")){v.preventDefault(),v.stopPropagation(),v.stopImmediatePropagation();const ee=v.key.toLowerCase(),Ae=A.current;K(ee==="p"?te=>te>0?te-1:Ae-1:te=>te<Ae-1?te+1:0);return}};return window.addEventListener("keydown",N,{capture:!0}),()=>{window.removeEventListener("keydown",N,{capture:!0})}},[t,e]);const O=h.useCallback(N=>{N.target===N.currentTarget&&e()},[e]),W=h.useCallback(()=>{K(0)},[K]);return t?d.jsx("div",{ref:y,className:"spotlight-overlay",onClick:O,children:d.jsxs("div",{className:"spotlight-modal",children:[d.jsx(Ln,{ref:x,query:R,onQueryChange:w,onKeyDown:re,onResetSelection:W}),d.jsx(Tn,{activeTab:B,onSelect:Y}),d.jsx(Fn,{ref:E,results:le,loadingTypes:he,selectedIndex:j,query:R,activeTab:B,areaSections:ie,highlightMatch:J,onSelectIndex:K}),d.jsx(Nn,{})]})}):M?d.jsx(Dn,{detail:M,onClose:()=>S(null)}):null}export{zn as FILE_ICON_NAMES,Bn as Spotlight,Nn as SpotlightFooter,Ln as SpotlightInput,Rt as SpotlightItem,Fn as SpotlightResults,Kn as formatDuration,On as formatRelativeTime,Un as getAgentIcon,Dt as getFileIconFromPath,Gn as getTypeLabel,bn as useSpotlightSearch};
1
+ import{c as Ze,d as et,z as cs,a0 as us,f as ls,br as hs,bZ as fs,aa as ds,r as h,y as gs,S as _e,b_ as Ye,b$ as ms,c0 as ps,c1 as ys,as as As,c2 as ye,s as U,c3 as xs,j as d,I as V,V as Tt,c4 as Ft,n as Nt,c5 as Es,c6 as Dt,c7 as We,U as qe,m as Ms,ar as Gt,u as Oe,c8 as Rt,aC as Cs,c9 as jt,ca as Is}from"./main-Dk3qq80S.js";import{cb as zn,cc as Kn,cd as On,ce as Un,cf as Gn}from"./main-Dk3qq80S.js";import"./vendor-react--Eh9ivFN.js";import"./vendor-three-DYBBrXTx.js";function ce(t){return Array.isArray?Array.isArray(t):Wt(t)==="[object Array]"}function _s(t){if(typeof t=="string")return t;let e=t+"";return e=="0"&&1/t==-1/0?"-0":e}function Ss(t){return t==null?"":_s(t)}function oe(t){return typeof t=="string"}function Ht(t){return typeof t=="number"}function vs(t){return t===!0||t===!1||ws(t)&&Wt(t)=="[object Boolean]"}function Yt(t){return typeof t=="object"}function ws(t){return Yt(t)&&t!==null}function X(t){return t!=null}function Ve(t){return!t.trim().length}function Wt(t){return t==null?t===void 0?"[object Undefined]":"[object Null]":Object.prototype.toString.call(t)}const bs="Incorrect 'index' type",Ls=t=>`Invalid value for key ${t}`,Ts=t=>`Pattern length exceeds max of ${t}.`,Fs=t=>`Missing ${t} property in key`,Ns=t=>`Property 'weight' in key '${t}' must be a positive integer`,kt=Object.prototype.hasOwnProperty;class Ds{constructor(e){this._keys=[],this._keyMap={};let n=0;e.forEach(r=>{let o=qt(r);this._keys.push(o),this._keyMap[o.id]=o,n+=o.weight}),this._keys.forEach(r=>{r.weight/=n})}get(e){return this._keyMap[e]}keys(){return this._keys}toJSON(){return JSON.stringify(this._keys)}}function qt(t){let e=null,n=null,r=null,o=1,a=null;if(oe(t)||ce(t))r=t,e=$t(t),n=tt(t);else{if(!kt.call(t,"name"))throw new Error(Fs("name"));const c=t.name;if(r=c,kt.call(t,"weight")&&(o=t.weight,o<=0))throw new Error(Ns(c));e=$t(c),n=tt(c),a=t.getFn}return{path:e,id:n,weight:o,src:r,getFn:a}}function $t(t){return ce(t)?t:t.split(".")}function tt(t){return ce(t)?t.join("."):t}function Rs(t,e){let n=[],r=!1;const o=(a,c,u)=>{if(X(a))if(!c[u])n.push(a);else{let f=c[u];const l=a[f];if(!X(l))return;if(u===c.length-1&&(oe(l)||Ht(l)||vs(l)))n.push(Ss(l));else if(ce(l)){r=!0;for(let g=0,x=l.length;g<x;g+=1)o(l[g],c,u+1)}else c.length&&o(l,c,u+1)}};return o(t,oe(e)?e.split("."):e,0),r?n:n[0]}const js={includeMatches:!1,findAllMatches:!1,minMatchCharLength:1},ks={isCaseSensitive:!1,ignoreDiacritics:!1,includeScore:!1,keys:[],shouldSort:!0,sortFn:(t,e)=>t.score===e.score?t.idx<e.idx?-1:1:t.score<e.score?-1:1},$s={location:0,threshold:.6,distance:100},Bs={useExtendedSearch:!1,getFn:Rs,ignoreLocation:!1,ignoreFieldNorm:!1,fieldNormWeight:1};var C={...ks,...js,...$s,...Bs};const Ps=/[^ ]+/g;function Qs(t=1,e=3){const n=new Map,r=Math.pow(10,e);return{get(o){const a=o.match(Ps).length;if(n.has(a))return n.get(a);const c=1/Math.pow(a,.5*t),u=parseFloat(Math.round(c*r)/r);return n.set(a,u),u},clear(){n.clear()}}}class at{constructor({getFn:e=C.getFn,fieldNormWeight:n=C.fieldNormWeight}={}){this.norm=Qs(n,3),this.getFn=e,this.isCreated=!1,this.setIndexRecords()}setSources(e=[]){this.docs=e}setIndexRecords(e=[]){this.records=e}setKeys(e=[]){this.keys=e,this._keysMap={},e.forEach((n,r)=>{this._keysMap[n.id]=r})}create(){this.isCreated||!this.docs.length||(this.isCreated=!0,oe(this.docs[0])?this.docs.forEach((e,n)=>{this._addString(e,n)}):this.docs.forEach((e,n)=>{this._addObject(e,n)}),this.norm.clear())}add(e){const n=this.size();oe(e)?this._addString(e,n):this._addObject(e,n)}removeAt(e){this.records.splice(e,1);for(let n=e,r=this.size();n<r;n+=1)this.records[n].i-=1}getValueForItemAtKeyId(e,n){return e[this._keysMap[n]]}size(){return this.records.length}_addString(e,n){if(!X(e)||Ve(e))return;let r={v:e,i:n,n:this.norm.get(e)};this.records.push(r)}_addObject(e,n){let r={i:n,$:{}};this.keys.forEach((o,a)=>{let c=o.getFn?o.getFn(e):this.getFn(e,o.path);if(X(c)){if(ce(c)){let u=[];const f=[{nestedArrIndex:-1,value:c}];for(;f.length;){const{nestedArrIndex:l,value:g}=f.pop();if(X(g))if(oe(g)&&!Ve(g)){let x={v:g,i:l,n:this.norm.get(g)};u.push(x)}else ce(g)&&g.forEach((x,y)=>{f.push({nestedArrIndex:y,value:x})})}r.$[a]=u}else if(oe(c)&&!Ve(c)){let u={v:c,n:this.norm.get(c)};r.$[a]=u}}}),this.records.push(r)}toJSON(){return{keys:this.keys,records:this.records}}}function Vt(t,e,{getFn:n=C.getFn,fieldNormWeight:r=C.fieldNormWeight}={}){const o=new at({getFn:n,fieldNormWeight:r});return o.setKeys(t.map(qt)),o.setSources(e),o.create(),o}function zs(t,{getFn:e=C.getFn,fieldNormWeight:n=C.fieldNormWeight}={}){const{keys:r,records:o}=t,a=new at({getFn:e,fieldNormWeight:n});return a.setKeys(r),a.setIndexRecords(o),a}function Pe(t,{errors:e=0,currentLocation:n=0,expectedLocation:r=0,distance:o=C.distance,ignoreLocation:a=C.ignoreLocation}={}){const c=e/t.length;if(a)return c;const u=Math.abs(r-n);return o?c+u/o:u?1:c}function Ks(t=[],e=C.minMatchCharLength){let n=[],r=-1,o=-1,a=0;for(let c=t.length;a<c;a+=1){let u=t[a];u&&r===-1?r=a:!u&&r!==-1&&(o=a-1,o-r+1>=e&&n.push([r,o]),r=-1)}return t[a-1]&&a-r>=e&&n.push([r,a-1]),n}const me=32;function Os(t,e,n,{location:r=C.location,distance:o=C.distance,threshold:a=C.threshold,findAllMatches:c=C.findAllMatches,minMatchCharLength:u=C.minMatchCharLength,includeMatches:f=C.includeMatches,ignoreLocation:l=C.ignoreLocation}={}){if(e.length>me)throw new Error(Ts(me));const g=e.length,x=t.length,y=Math.max(0,Math.min(r,x));let E=a,A=y;const M=u>1||f,S=M?Array(x):[];let R;for(;(R=t.indexOf(e,A))>-1;){let B=Pe(e,{currentLocation:R,expectedLocation:y,distance:o,ignoreLocation:l});if(E=Math.min(B,E),A=R+g,M){let Y=0;for(;Y<g;)S[R+Y]=1,Y+=1}}A=-1;let w=[],j=1,K=g+x;const le=1<<g-1;for(let B=0;B<g;B+=1){let Y=0,G=K;for(;Y<G;)Pe(e,{errors:B,currentLocation:y+G,expectedLocation:y,distance:o,ignoreLocation:l})<=E?Y=G:K=G,G=Math.floor((K-Y)/2+Y);K=G;let ie=Math.max(1,y-G+1),re=c?x:Math.min(y+G,x)+g,J=Array(re+2);J[re+1]=(1<<B)-1;for(let O=re;O>=ie;O-=1){let W=O-1,N=n[t.charAt(W)];if(M&&(S[W]=+!!N),J[O]=(J[O+1]<<1|1)&N,B&&(J[O]|=(w[O+1]|w[O])<<1|1|w[O+1]),J[O]&le&&(j=Pe(e,{errors:B,currentLocation:W,expectedLocation:y,distance:o,ignoreLocation:l}),j<=E)){if(E=j,A=W,A<=y)break;ie=Math.max(1,2*y-A)}}if(Pe(e,{errors:B+1,currentLocation:y,expectedLocation:y,distance:o,ignoreLocation:l})>E)break;w=J}const he={isMatch:A>=0,score:Math.max(.001,j)};if(M){const B=Ks(S,u);B.length?f&&(he.indices=B):he.isMatch=!1}return he}function Us(t){let e={};for(let n=0,r=t.length;n<r;n+=1){const o=t.charAt(n);e[o]=(e[o]||0)|1<<r-n-1}return e}const ze=String.prototype.normalize?(t=>t.normalize("NFD").replace(/[\u0300-\u036F\u0483-\u0489\u0591-\u05BD\u05BF\u05C1\u05C2\u05C4\u05C5\u05C7\u0610-\u061A\u064B-\u065F\u0670\u06D6-\u06DC\u06DF-\u06E4\u06E7\u06E8\u06EA-\u06ED\u0711\u0730-\u074A\u07A6-\u07B0\u07EB-\u07F3\u07FD\u0816-\u0819\u081B-\u0823\u0825-\u0827\u0829-\u082D\u0859-\u085B\u08D3-\u08E1\u08E3-\u0903\u093A-\u093C\u093E-\u094F\u0951-\u0957\u0962\u0963\u0981-\u0983\u09BC\u09BE-\u09C4\u09C7\u09C8\u09CB-\u09CD\u09D7\u09E2\u09E3\u09FE\u0A01-\u0A03\u0A3C\u0A3E-\u0A42\u0A47\u0A48\u0A4B-\u0A4D\u0A51\u0A70\u0A71\u0A75\u0A81-\u0A83\u0ABC\u0ABE-\u0AC5\u0AC7-\u0AC9\u0ACB-\u0ACD\u0AE2\u0AE3\u0AFA-\u0AFF\u0B01-\u0B03\u0B3C\u0B3E-\u0B44\u0B47\u0B48\u0B4B-\u0B4D\u0B56\u0B57\u0B62\u0B63\u0B82\u0BBE-\u0BC2\u0BC6-\u0BC8\u0BCA-\u0BCD\u0BD7\u0C00-\u0C04\u0C3E-\u0C44\u0C46-\u0C48\u0C4A-\u0C4D\u0C55\u0C56\u0C62\u0C63\u0C81-\u0C83\u0CBC\u0CBE-\u0CC4\u0CC6-\u0CC8\u0CCA-\u0CCD\u0CD5\u0CD6\u0CE2\u0CE3\u0D00-\u0D03\u0D3B\u0D3C\u0D3E-\u0D44\u0D46-\u0D48\u0D4A-\u0D4D\u0D57\u0D62\u0D63\u0D82\u0D83\u0DCA\u0DCF-\u0DD4\u0DD6\u0DD8-\u0DDF\u0DF2\u0DF3\u0E31\u0E34-\u0E3A\u0E47-\u0E4E\u0EB1\u0EB4-\u0EB9\u0EBB\u0EBC\u0EC8-\u0ECD\u0F18\u0F19\u0F35\u0F37\u0F39\u0F3E\u0F3F\u0F71-\u0F84\u0F86\u0F87\u0F8D-\u0F97\u0F99-\u0FBC\u0FC6\u102B-\u103E\u1056-\u1059\u105E-\u1060\u1062-\u1064\u1067-\u106D\u1071-\u1074\u1082-\u108D\u108F\u109A-\u109D\u135D-\u135F\u1712-\u1714\u1732-\u1734\u1752\u1753\u1772\u1773\u17B4-\u17D3\u17DD\u180B-\u180D\u1885\u1886\u18A9\u1920-\u192B\u1930-\u193B\u1A17-\u1A1B\u1A55-\u1A5E\u1A60-\u1A7C\u1A7F\u1AB0-\u1ABE\u1B00-\u1B04\u1B34-\u1B44\u1B6B-\u1B73\u1B80-\u1B82\u1BA1-\u1BAD\u1BE6-\u1BF3\u1C24-\u1C37\u1CD0-\u1CD2\u1CD4-\u1CE8\u1CED\u1CF2-\u1CF4\u1CF7-\u1CF9\u1DC0-\u1DF9\u1DFB-\u1DFF\u20D0-\u20F0\u2CEF-\u2CF1\u2D7F\u2DE0-\u2DFF\u302A-\u302F\u3099\u309A\uA66F-\uA672\uA674-\uA67D\uA69E\uA69F\uA6F0\uA6F1\uA802\uA806\uA80B\uA823-\uA827\uA880\uA881\uA8B4-\uA8C5\uA8E0-\uA8F1\uA8FF\uA926-\uA92D\uA947-\uA953\uA980-\uA983\uA9B3-\uA9C0\uA9E5\uAA29-\uAA36\uAA43\uAA4C\uAA4D\uAA7B-\uAA7D\uAAB0\uAAB2-\uAAB4\uAAB7\uAAB8\uAABE\uAABF\uAAC1\uAAEB-\uAAEF\uAAF5\uAAF6\uABE3-\uABEA\uABEC\uABED\uFB1E\uFE00-\uFE0F\uFE20-\uFE2F]/g,"")):(t=>t);class Xt{constructor(e,{location:n=C.location,threshold:r=C.threshold,distance:o=C.distance,includeMatches:a=C.includeMatches,findAllMatches:c=C.findAllMatches,minMatchCharLength:u=C.minMatchCharLength,isCaseSensitive:f=C.isCaseSensitive,ignoreDiacritics:l=C.ignoreDiacritics,ignoreLocation:g=C.ignoreLocation}={}){if(this.options={location:n,threshold:r,distance:o,includeMatches:a,findAllMatches:c,minMatchCharLength:u,isCaseSensitive:f,ignoreDiacritics:l,ignoreLocation:g},e=f?e:e.toLowerCase(),e=l?ze(e):e,this.pattern=e,this.chunks=[],!this.pattern.length)return;const x=(E,A)=>{this.chunks.push({pattern:E,alphabet:Us(E),startIndex:A})},y=this.pattern.length;if(y>me){let E=0;const A=y%me,M=y-A;for(;E<M;)x(this.pattern.substr(E,me),E),E+=me;if(A){const S=y-me;x(this.pattern.substr(S),S)}}else x(this.pattern,0)}searchIn(e){const{isCaseSensitive:n,ignoreDiacritics:r,includeMatches:o}=this.options;if(e=n?e:e.toLowerCase(),e=r?ze(e):e,this.pattern===e){let M={isMatch:!0,score:0};return o&&(M.indices=[[0,e.length-1]]),M}const{location:a,distance:c,threshold:u,findAllMatches:f,minMatchCharLength:l,ignoreLocation:g}=this.options;let x=[],y=0,E=!1;this.chunks.forEach(({pattern:M,alphabet:S,startIndex:R})=>{const{isMatch:w,score:j,indices:K}=Os(e,M,S,{location:a+R,distance:c,threshold:u,findAllMatches:f,minMatchCharLength:l,includeMatches:o,ignoreLocation:g});w&&(E=!0),y+=j,w&&K&&(x=[...x,...K])});let A={isMatch:E,score:E?y/this.chunks.length:1};return E&&o&&(A.indices=x),A}}class ue{constructor(e){this.pattern=e}static isMultiMatch(e){return Bt(e,this.multiRegex)}static isSingleMatch(e){return Bt(e,this.singleRegex)}search(){}}function Bt(t,e){const n=t.match(e);return n?n[1]:null}class Gs extends ue{constructor(e){super(e)}static get type(){return"exact"}static get multiRegex(){return/^="(.*)"$/}static get singleRegex(){return/^=(.*)$/}search(e){const n=e===this.pattern;return{isMatch:n,score:n?0:1,indices:[0,this.pattern.length-1]}}}class Hs extends ue{constructor(e){super(e)}static get type(){return"inverse-exact"}static get multiRegex(){return/^!"(.*)"$/}static get singleRegex(){return/^!(.*)$/}search(e){const r=e.indexOf(this.pattern)===-1;return{isMatch:r,score:r?0:1,indices:[0,e.length-1]}}}class Ys extends ue{constructor(e){super(e)}static get type(){return"prefix-exact"}static get multiRegex(){return/^\^"(.*)"$/}static get singleRegex(){return/^\^(.*)$/}search(e){const n=e.startsWith(this.pattern);return{isMatch:n,score:n?0:1,indices:[0,this.pattern.length-1]}}}class Ws extends ue{constructor(e){super(e)}static get type(){return"inverse-prefix-exact"}static get multiRegex(){return/^!\^"(.*)"$/}static get singleRegex(){return/^!\^(.*)$/}search(e){const n=!e.startsWith(this.pattern);return{isMatch:n,score:n?0:1,indices:[0,e.length-1]}}}class qs extends ue{constructor(e){super(e)}static get type(){return"suffix-exact"}static get multiRegex(){return/^"(.*)"\$$/}static get singleRegex(){return/^(.*)\$$/}search(e){const n=e.endsWith(this.pattern);return{isMatch:n,score:n?0:1,indices:[e.length-this.pattern.length,e.length-1]}}}class Vs extends ue{constructor(e){super(e)}static get type(){return"inverse-suffix-exact"}static get multiRegex(){return/^!"(.*)"\$$/}static get singleRegex(){return/^!(.*)\$$/}search(e){const n=!e.endsWith(this.pattern);return{isMatch:n,score:n?0:1,indices:[0,e.length-1]}}}class Jt extends ue{constructor(e,{location:n=C.location,threshold:r=C.threshold,distance:o=C.distance,includeMatches:a=C.includeMatches,findAllMatches:c=C.findAllMatches,minMatchCharLength:u=C.minMatchCharLength,isCaseSensitive:f=C.isCaseSensitive,ignoreDiacritics:l=C.ignoreDiacritics,ignoreLocation:g=C.ignoreLocation}={}){super(e),this._bitapSearch=new Xt(e,{location:n,threshold:r,distance:o,includeMatches:a,findAllMatches:c,minMatchCharLength:u,isCaseSensitive:f,ignoreDiacritics:l,ignoreLocation:g})}static get type(){return"fuzzy"}static get multiRegex(){return/^"(.*)"$/}static get singleRegex(){return/^(.*)$/}search(e){return this._bitapSearch.searchIn(e)}}class Zt extends ue{constructor(e){super(e)}static get type(){return"include"}static get multiRegex(){return/^'"(.*)"$/}static get singleRegex(){return/^'(.*)$/}search(e){let n=0,r;const o=[],a=this.pattern.length;for(;(r=e.indexOf(this.pattern,n))>-1;)n=r+a,o.push([r,n-1]);const c=!!o.length;return{isMatch:c,score:c?0:1,indices:o}}}const st=[Gs,Zt,Ys,Ws,Vs,qs,Hs,Jt],Pt=st.length,Xs=/ +(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)/,Js="|";function Zs(t,e={}){return t.split(Js).map(n=>{let r=n.trim().split(Xs).filter(a=>a&&!!a.trim()),o=[];for(let a=0,c=r.length;a<c;a+=1){const u=r[a];let f=!1,l=-1;for(;!f&&++l<Pt;){const g=st[l];let x=g.isMultiMatch(u);x&&(o.push(new g(x,e)),f=!0)}if(!f)for(l=-1;++l<Pt;){const g=st[l];let x=g.isSingleMatch(u);if(x){o.push(new g(x,e));break}}}return o})}const en=new Set([Jt.type,Zt.type]);class tn{constructor(e,{isCaseSensitive:n=C.isCaseSensitive,ignoreDiacritics:r=C.ignoreDiacritics,includeMatches:o=C.includeMatches,minMatchCharLength:a=C.minMatchCharLength,ignoreLocation:c=C.ignoreLocation,findAllMatches:u=C.findAllMatches,location:f=C.location,threshold:l=C.threshold,distance:g=C.distance}={}){this.query=null,this.options={isCaseSensitive:n,ignoreDiacritics:r,includeMatches:o,minMatchCharLength:a,findAllMatches:u,ignoreLocation:c,location:f,threshold:l,distance:g},e=n?e:e.toLowerCase(),e=r?ze(e):e,this.pattern=e,this.query=Zs(this.pattern,this.options)}static condition(e,n){return n.useExtendedSearch}searchIn(e){const n=this.query;if(!n)return{isMatch:!1,score:1};const{includeMatches:r,isCaseSensitive:o,ignoreDiacritics:a}=this.options;e=o?e:e.toLowerCase(),e=a?ze(e):e;let c=0,u=[],f=0;for(let l=0,g=n.length;l<g;l+=1){const x=n[l];u.length=0,c=0;for(let y=0,E=x.length;y<E;y+=1){const A=x[y],{isMatch:M,indices:S,score:R}=A.search(e);if(M){if(c+=1,f+=R,r){const w=A.constructor.type;en.has(w)?u=[...u,...S]:u.push(S)}}else{f=0,c=0,u.length=0;break}}if(c){let y={isMatch:!0,score:f/c};return r&&(y.indices=u),y}}return{isMatch:!1,score:1}}}const nt=[];function sn(...t){nt.push(...t)}function rt(t,e){for(let n=0,r=nt.length;n<r;n+=1){let o=nt[n];if(o.condition(t,e))return new o(t,e)}return new Xt(t,e)}const Ke={AND:"$and",OR:"$or"},ot={PATH:"$path",PATTERN:"$val"},it=t=>!!(t[Ke.AND]||t[Ke.OR]),nn=t=>!!t[ot.PATH],rn=t=>!ce(t)&&Yt(t)&&!it(t),Qt=t=>({[Ke.AND]:Object.keys(t).map(e=>({[e]:t[e]}))});function es(t,e,{auto:n=!0}={}){const r=o=>{let a=Object.keys(o);const c=nn(o);if(!c&&a.length>1&&!it(o))return r(Qt(o));if(rn(o)){const f=c?o[ot.PATH]:a[0],l=c?o[ot.PATTERN]:o[f];if(!oe(l))throw new Error(Ls(f));const g={keyId:tt(f),pattern:l};return n&&(g.searcher=rt(l,e)),g}let u={children:[],operator:a[0]};return a.forEach(f=>{const l=o[f];ce(l)&&l.forEach(g=>{u.children.push(r(g))})}),u};return it(t)||(t=Qt(t)),r(t)}function on(t,{ignoreFieldNorm:e=C.ignoreFieldNorm}){t.forEach(n=>{let r=1;n.matches.forEach(({key:o,norm:a,score:c})=>{const u=o?o.weight:null;r*=Math.pow(c===0&&u?Number.EPSILON:c,(u||1)*(e?1:a))}),n.score=r})}function an(t,e){const n=t.matches;e.matches=[],X(n)&&n.forEach(r=>{if(!X(r.indices)||!r.indices.length)return;const{indices:o,value:a}=r;let c={indices:o,value:a};r.key&&(c.key=r.key.src),r.idx>-1&&(c.refIndex=r.idx),e.matches.push(c)})}function cn(t,e){e.score=t.score}function un(t,e,{includeMatches:n=C.includeMatches,includeScore:r=C.includeScore}={}){const o=[];return n&&o.push(an),r&&o.push(cn),t.map(a=>{const{idx:c}=a,u={item:e[c],refIndex:c};return o.length&&o.forEach(f=>{f(a,u)}),u})}class ae{constructor(e,n={},r){this.options={...C,...n},this.options.useExtendedSearch,this._keyStore=new Ds(this.options.keys),this.setCollection(e,r)}setCollection(e,n){if(this._docs=e,n&&!(n instanceof at))throw new Error(bs);this._myIndex=n||Vt(this.options.keys,this._docs,{getFn:this.options.getFn,fieldNormWeight:this.options.fieldNormWeight})}add(e){X(e)&&(this._docs.push(e),this._myIndex.add(e))}remove(e=()=>!1){const n=[];for(let r=0,o=this._docs.length;r<o;r+=1){const a=this._docs[r];e(a,r)&&(this.removeAt(r),r-=1,o-=1,n.push(a))}return n}removeAt(e){this._docs.splice(e,1),this._myIndex.removeAt(e)}getIndex(){return this._myIndex}search(e,{limit:n=-1}={}){const{includeMatches:r,includeScore:o,shouldSort:a,sortFn:c,ignoreFieldNorm:u}=this.options;let f=oe(e)?oe(this._docs[0])?this._searchStringList(e):this._searchObjectList(e):this._searchLogical(e);return on(f,{ignoreFieldNorm:u}),a&&f.sort(c),Ht(n)&&n>-1&&(f=f.slice(0,n)),un(f,this._docs,{includeMatches:r,includeScore:o})}_searchStringList(e){const n=rt(e,this.options),{records:r}=this._myIndex,o=[];return r.forEach(({v:a,i:c,n:u})=>{if(!X(a))return;const{isMatch:f,score:l,indices:g}=n.searchIn(a);f&&o.push({item:a,idx:c,matches:[{score:l,value:a,norm:u,indices:g}]})}),o}_searchLogical(e){const n=es(e,this.options),r=(u,f,l)=>{if(!u.children){const{keyId:x,searcher:y}=u,E=this._findMatches({key:this._keyStore.get(x),value:this._myIndex.getValueForItemAtKeyId(f,x),searcher:y});return E&&E.length?[{idx:l,item:f,matches:E}]:[]}const g=[];for(let x=0,y=u.children.length;x<y;x+=1){const E=u.children[x],A=r(E,f,l);if(A.length)g.push(...A);else if(u.operator===Ke.AND)return[]}return g},o=this._myIndex.records,a={},c=[];return o.forEach(({$:u,i:f})=>{if(X(u)){let l=r(n,u,f);l.length&&(a[f]||(a[f]={idx:f,item:u,matches:[]},c.push(a[f])),l.forEach(({matches:g})=>{a[f].matches.push(...g)}))}}),c}_searchObjectList(e){const n=rt(e,this.options),{keys:r,records:o}=this._myIndex,a=[];return o.forEach(({$:c,i:u})=>{if(!X(c))return;let f=[];r.forEach((l,g)=>{f.push(...this._findMatches({key:l,value:c[g],searcher:n}))}),f.length&&a.push({idx:u,item:c,matches:f})}),a}_findMatches({key:e,value:n,searcher:r}){if(!X(n))return[];let o=[];if(ce(n))n.forEach(({v:a,i:c,n:u})=>{if(!X(a))return;const{isMatch:f,score:l,indices:g}=r.searchIn(a);f&&o.push({score:l,key:e,value:a,idx:c,norm:u,indices:g})});else{const{v:a,n:c}=n,{isMatch:u,score:f,indices:l}=r.searchIn(a);u&&o.push({score:f,key:e,value:a,norm:c,indices:l})}return o}}ae.version="7.1.0";ae.createIndex=Vt;ae.parseIndex=zs;ae.config=C;ae.parseQuery=es;sn(tn);function Ie(t){return t.trim().toLowerCase().split(/\s+/).filter(Boolean)}function ln(t){return t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function Qe(t,e){const n=e.trim(),r=Ie(n);if(r.length<=1)return t.search(n);const[o,...a]=r.map(f=>t.search(f)),c=a.map(f=>{const l=new Map;for(const g of f)l.set(g.refIndex,g.score??1);return l}),u=[];for(const f of o){let l=f.score??1,g=!0;for(const x of c){const y=x.get(f.refIndex);if(y===void 0){g=!1;break}l+=y}g&&u.push({item:f.item,score:l/r.length})}return u.sort((f,l)=>(f.score??1)-(l.score??1)),u}function zt(t,e,n){return e===t?6:e.startsWith(t)?5:e.split(/[^a-z0-9]+/i).includes(t)?4:e.includes(t)?3:n.includes(t)?2:1}function hn(t,e,n){const r=Ie(t);if(r.length===0)return 1;const o=e.toLowerCase(),a=n.toLowerCase(),c=zt(r.join(" "),o,a);if(r.length===1)return c;let u=6;for(const f of r)u=Math.min(u,zt(f,o,a));return Math.max(c,u)}const fn=4;function Kt(t){return t.replace(/…|\.\.\./g," ").replace(/\s+/g," ").trim().toLowerCase()}const dn=24;function gn(t,e){const n=Kt(t),r=Kt(e);return n===r?!0:Math.min(n.length,r.length)<dn?!1:n.includes(r)||r.includes(n)}function mn(t,e){const n=[],r=o=>{!o||!o.text.trim()||n.length>=fn||n.some(a=>gn(a.text,o.text))||n.push(o)};t&&r({text:t,kind:"user"});for(const o of e??[])r(o);return n.length>0?n:void 0}async function pn(t){const e=new URLSearchParams({q:t}),n=await Ze(et(`/api/folders/search?${e.toString()}`));if(!n.ok){const o=await n.json().catch(()=>({}));throw new Error(o.error||`Failed to search folders: ${n.statusText}`)}const r=await n.json();return Array.isArray(r.folders)?r.folders:[]}const Ot=["agent","session","building","file","file-content","folder","area"],yn=2,An=2,xn=50,En=10,Mn=3,Cn=30,In=8,_n=3,Sn=15,Xe=5,Je=5;function vn(){const t=Gt(_e.SPOTLIGHT_TAB,"all");return ye.includes(t)?t:"all"}function Ut(){return Ms(_e.SPOTLIGHT_QUERY,"")}function wn(){const t=Gt(_e.AOP_CONFIG,{});return t.sortMode==="name"||t.sortMode==="status"||t.sortMode==="recent"?t.sortMode:"recent"}function bn({isOpen:t,onClose:e,onOpenSpawnModal:n,onOpenCommanderView:r,onOpenToolbox:o,onOpenFileExplorer:a,onOpenPM2LogsModal:c,onOpenBossLogsModal:u,onOpenDatabasePanel:f,onOpenMonitoringModal:l,onOpenSessionFinder:g,onOpenFileDetail:x}){const y=cs(),E=us(),A=ls(),M=hs(),S=fs(),R=ds(),w=h.useRef(e);w.current=e;const j=h.useRef(n);j.current=n;const K=h.useRef(r);K.current=r;const le=h.useRef(o);le.current=o;const he=h.useRef(a);he.current=a;const B=h.useRef(c);B.current=c;const Y=h.useRef(u);Y.current=u;const G=h.useRef(f);G.current=f;const ie=h.useRef(l);ie.current=l;const re=h.useRef(g);re.current=g;const J=h.useRef(x);J.current=x;const[F,O]=h.useState(Ut),[W,N]=h.useState(0),[v,ee]=h.useState(vn),[Ae,te]=h.useState([]),[ct,xe]=h.useState([]),[ut,Ee]=h.useState([]),[lt,Se]=h.useState(!1),[ht,ve]=h.useState(!1),[ft,we]=h.useState(!1),[dt,be]=h.useState(!1),[Le,Me]=h.useState({query:"",rows:[]}),[gt,mt]=h.useState(!1),[pt,yt]=h.useState(!1);h.useEffect(()=>{mt(!1),yt(!1)},[F,t]);const ts=h.useCallback(s=>{O(s),gs(_e.SPOTLIGHT_QUERY,s)},[]);h.useEffect(()=>{t&&(O(Ut()),N(0))},[t]),h.useEffect(()=>{if(!t){te([]),Se(!1);return}const s=F.trim();if(s.length<yn){te([]),Se(!1);return}te([]),Se(!0);let i=!1;const m=setTimeout(()=>{pn(s).then(I=>{i||te(I)}).catch(()=>{i||te([])}).finally(()=>{i||Se(!1)})},250);return()=>{i=!0,clearTimeout(m)}},[t,F]);const At=(M.fileSearchExcludeDirs??Ye).join(",");h.useEffect(()=>{if(!t){xe([]),ve(!1);return}const s=F.trim();if(s.length<An){xe([]),ve(!1);return}xe([]),ve(!0);let i=!1;const m=setTimeout(()=>{ms(s,{exclude:M.fileSearchExcludeDirs??[...Ye],limit:xn}).then(I=>{i||xe(I)}).catch(()=>{i||xe([])}).finally(()=>{i||ve(!1)})},250);return()=>{i=!0,clearTimeout(m)}},[t,F,At,M.fileSearchExcludeDirs]),h.useEffect(()=>{if(!t){Ee([]),we(!1);return}const s=F.trim();if(s.length<Mn){Ee([]),we(!1);return}Ee([]),we(!0);const i=new AbortController,m=setTimeout(()=>{ps(s,{exclude:M.fileSearchExcludeDirs??[...Ye],limit:Cn,signal:i.signal}).then(I=>{i.signal.aborted||Ee(I)}).catch(()=>{i.signal.aborted||Ee([])}).finally(()=>{i.signal.aborted||we(!1)})},300);return()=>{clearTimeout(m),i.abort()}},[t,F,At,M.fileSearchExcludeDirs]),h.useEffect(()=>{if(!t){Me({query:"",rows:[]}),be(!1);return}const s=F.trim();if(s.length<_n){Me({query:"",rows:[]}),be(!1);return}Me({query:"",rows:[]}),be(!0);let i=!1;const m=setTimeout(()=>{ys(s,{limit:Sn}).then(I=>{i||Me({query:s,rows:I})}).catch(()=>{i||Me({query:"",rows:[]})}).finally(()=>{i||be(!1)})},250);return()=>{i=!0,clearTimeout(m)}},[t,F]);const Ue=h.useCallback(s=>{ee(s),As(_e.SPOTLIGHT_TAB,s)},[]),xt=h.useRef(v);xt.current=v;const ss=h.useCallback(s=>{const i=ye.indexOf(xt.current),m=ye[(i+s+ye.length)%ye.length];Ue(m)},[Ue]);h.useEffect(()=>{N(0)},[v]);const Ge=U.getShortcuts(),Te=h.useMemo(()=>t?xs():{},[t]),Fe=h.useMemo(()=>{if(!t)return[];const s=window.matchMedia("(pointer: coarse)").matches,i=Ge.find(I=>I.id==="spawn-agent"),m=Ge.find(I=>I.id==="toggle-commander");return[{id:"cmd-spawn",type:"command",title:"Spawn New Agent",subtitle:s?"":i?Tt(i):"Alt+N",icon:d.jsx(V,{name:"plus",size:16}),action:()=>{w.current(),j.current()}},{id:"cmd-commander",type:"command",title:"Commander View",subtitle:s?"":m!=null&&m.key?Tt(m):"Tab",icon:d.jsx(V,{name:"dashboard",size:16}),action:()=>{w.current(),K.current()}},{id:"cmd-settings",type:"command",title:"Settings & Tools",subtitle:"Configure Tide Commander",icon:d.jsx(V,{name:"gear",size:16}),action:()=>{w.current(),le.current()}},{id:"cmd-monitoring",type:"command",title:"Monitoring & Logs",subtitle:"Triggers, workflows, events",icon:d.jsx(V,{name:"chart-line",size:16}),action:()=>{var I;w.current(),(I=ie.current)==null||I.call(ie)}}]},[t,Ge]),Ne=h.useMemo(()=>{const s=new Map;if(!t)return s;const i=Array.from(E.values());for(const m of y.values())for(const I of i)if(U.isPositionInArea({x:m.position.x,z:m.position.z},I)){s.set(m.id,I);break}return s},[t,y,E]),pe=h.useMemo(()=>t?Array.from(y.values()).map(s=>{const i=[];s.lastAssignedTask&&i.push(s.lastAssignedTask);const m=`${s.class} • ${s.cwd}`,I=Ne.get(s.id),k=(I==null?void 0:I.name)||"";let b=`${s.name} ${s.class} ${s.status} ${s.cwd}`;s.taskLabel&&(b+=` ${s.taskLabel}`),k&&(b+=` ${k}`),i.length>0&&(b+=` ${i.join(" ")}`);const $=Date.now()-s.lastActivity;let D;return s.lastAssignedTask&&(s.lastAssignedTask.length>150?D=s.lastAssignedTask.slice(0,150)+"...":D=s.lastAssignedTask),{id:`agent-${s.id}`,type:"agent",title:s.name,subtitle:m,lastUserInput:D,timeAway:$,icon:d.jsx(Nt,{agent:s,size:20}),_searchText:b,_userQueries:i,_agentId:s.id,_lastActivity:s.lastActivity,_taskLabel:s.taskLabel,_status:s.status,_provider:s.provider??"claude",_piModel:s.piModel,_piModelProvider:s.piModelProvider,_areaName:k||void 0,_areaColor:I==null?void 0:I.color,action:()=>{w.current(),Ft(s.id),U.selectAgent(s.id),U.getState().viewMode!=="flat"&&U.requestTerminalExpand()}}}):[],[t,y,Ne]),De=h.useMemo(()=>t?Array.from(E.values()).map(s=>{var i;return{id:`area-${s.id}`,type:"area",title:s.name,subtitle:`${s.assignedAgentIds.length} agents • ${((i=s.directories)==null?void 0:i.length)||0} folders`,icon:d.jsx(V,{name:"map",size:16}),action:()=>{w.current(),U.selectArea(s.id)}}}):[],[t,E]),Re=h.useMemo(()=>{const s=new Map;for(const i of pe)i._agentId&&s.set(i._agentId,i);return s},[pe]),Et=h.useMemo(()=>{const s=new Map;if(!t)return s;for(const i of y.values()){const m=Ne.get(i.id);if(!m||m.archived)continue;const I=s.get(m.id);I?I.push(i):s.set(m.id,[i])}return s},[t,y,Ne]),Mt=h.useMemo(()=>{const s=new Map;for(const i of S)s.has(i.agentId)||s.set(i.agentId,i.timestamp);return s},[S]),He=h.useMemo(()=>{if(!t)return[];const s=F.trim().toLowerCase(),i=Ie(s),m=Es({sortMode:wn(),agentsWithUnseenOutput:R,getLatestToolTimestamp:b=>Mt.get(b)}),I=Array.from(E.values()).filter(b=>!b.archived).filter(b=>{if(i.length===0)return!0;const $=b.name.toLowerCase();return i.some(D=>$.includes(D))}).sort((b,$)=>b.name.localeCompare($.name,void 0,{sensitivity:"base"})),k=[];for(const b of I){const $=b.name.toLowerCase(),D=i.filter(P=>!$.includes(P));let H=(Et.get(b.id)||[]).slice().sort(m).map(P=>Re.get(P.id)).filter(P=>!!P);D.length>0&&(H=H.filter(P=>{const Z=`${P.title} ${P.subtitle||""} ${P._searchText||""}`.toLowerCase();return D.every(Q=>Z.includes(Q))}),H.length===0)||!s&&H.length===0||k.push({areaId:b.id,areaName:b.name,areaColor:b.color,agents:H})}return k},[t,F,E,Et,Re,R,Mt]),je=h.useMemo(()=>t?Array.from(A.values()).filter(s=>s.type==="server"||s.type==="boss"||s.type==="database"||s.type==="tests").map(s=>{var D,q,H,P,Z;const i=s.status==="running"?"#4ade80":s.status==="stopped"?"#f87171":"#facc15",m=s.type==="boss"?"crown":s.type==="database"?"database":s.type==="tests"?"flask":"desktop",I=s.type==="boss"?"Boss":s.type==="database"?"Database":s.type==="tests"?"Tests":"Server";let k=`${I} • ${s.status}`;if(s.type==="database"&&((q=(D=s.database)==null?void 0:D.connections)!=null&&q.length)){const Q=s.database.connections[0];k+=` • ${Q.engine} @ ${Q.host}`}else s.type==="tests"&&s.folderPath?k=`${I} • ${s.folderPath}`:s.cwd&&(k+=` • ${s.cwd}`);const b=((H=s.pm2Status)==null?void 0:H.ports)||[];let $=`${s.name} ${s.type} ${s.status} ${s.cwd||""} ${((P=s.pm2)==null?void 0:P.name)||""}`;if(s.type==="tests"&&($+=` ${s.folderPath||""} tests junit maven`),b.length>0&&($+=` ${b.join(" ")}`),s.type==="database"&&((Z=s.database)!=null&&Z.connections))for(const Q of s.database.connections)$+=` ${Q.name} ${Q.engine} ${Q.host} ${Q.database||""} mysql postgresql sql`;return{id:`building-${s.id}`,type:"building",title:s.name,subtitle:k,_ports:b,icon:d.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:4},children:[d.jsx(V,{name:"status-pending",size:10,weight:"fill",color:i}),d.jsx(V,{name:m,size:16})]}),_searchText:$,action:()=>{var Q;w.current(),s.type==="boss"?Y.current(s.id):s.type==="database"?G.current(s.id):s.type==="tests"?U.openTestsBuilding(s.id):s.type==="http"?U.openHttpBuilding(s.id):(Q=s.pm2)!=null&&Q.enabled&&B.current(s.id)}}}):[],[t,A]),Ct=h.useMemo(()=>t?Ae.map(s=>{const i=s.isGitRepo&&s.gitBranch?`${s.path} • ${s.gitBranch}`:s.path;return{id:`folder-${s.path}`,type:"folder",title:s.name,subtitle:i,matchedText:s.path,icon:d.jsx(V,{name:s.isGitRepo?"git-branch":"folder",size:16}),_searchText:`${s.name} ${s.path}`,_isGitRepo:s.isGitRepo,_gitBranch:s.gitBranch,action:()=>{w.current(),U.openFileExplorer(s.path)}}}):[],[t,Ae]),ke=h.useMemo(()=>t?ct.map(s=>{const i=s.areaName&&s.areaName!==s.projectName?`${s.projectName} · ${s.areaName}`:s.projectName;return{id:`file-${s.path}`,type:"file",title:s.name,subtitle:s.relativePath,matchedText:`${s.path} ${i}`,icon:Dt(s.path),_searchText:`${s.name} ${s.relativePath} ${s.path} ${s.projectName} ${s.areaName}`,_projectName:s.projectName,_areaName:s.areaName,action:()=>{w.current(),J.current({filePath:s.path,projectRoot:s.projectRoot,searchQuery:F.trim()})}}}):[],[t,ct,F]),$e=h.useMemo(()=>t?ut.map(s=>{const i=s.matches[0],m=s.areaName&&s.areaName!==s.projectName?`${s.projectName} · ${s.areaName}`:s.projectName;return{id:`file-content-${s.path}`,type:"file-content",title:s.name,subtitle:`${s.relativePath}${i!=null&&i.line?`:${i.line}`:""}`,matchedQuery:i==null?void 0:i.content,matchedText:`${s.path} ${m}`,icon:Dt(s.path),_projectName:s.projectName,_areaName:s.areaName,_lineNumber:i==null?void 0:i.line,action:()=>{w.current(),J.current({filePath:s.path,projectRoot:s.projectRoot,targetLine:i==null?void 0:i.line,searchQuery:F.trim()})}}}):[],[t,ut,F]),fe=h.useMemo(()=>{if(!t)return[];const s=i=>{const m=Date.now()-new Date(i).getTime();return!Number.isFinite(m)||m<0?"":m<36e5?`${Math.max(1,Math.floor(m/6e4))}m`:m<864e5?`${Math.floor(m/36e5)}h`:`${Math.floor(m/864e5)}d`};return Le.rows.map(i=>{const m=Array.from(y.values()).find(D=>D.sessionId===i.sessionId),I=m??(i.agentId?y.get(i.agentId):void 0),k=(i.firstPrompt||i.snippet||i.sessionId).slice(0,90),b=[i.projectPath||i.projectDir];I&&b.push(`→ ${I.name}${m?"":" (past session)"}`);const $=s(i.lastModified);return $&&b.push($),b.push(`${i.totalMatches}×`),{id:`session-${i.sessionId}`,type:"session",title:k,subtitle:b.join(" • "),matchedQuery:i.snippet||void 0,matchedExtracts:i.extracts&&i.extracts.length>0?i.extracts:void 0,_agentId:I==null?void 0:I.id,_sessionMatches:i.totalMatches,_provider:i.provider||"claude",icon:I?d.jsx(Nt,{agent:I,size:20}):d.jsx(V,{name:"history",size:16}),action:()=>{var q;w.current();const D=Array.from(U.getState().agents.values()).find(H=>H.sessionId===i.sessionId);D?(Ft(D.id),U.selectAgent(D.id),U.getState().viewMode!=="flat"&&U.requestTerminalExpand(),U.requestTerminalSearch(D.id,Le.query)):(q=re.current)==null||q.call(re,{initialQuery:Le.query,initialSessionKey:`${i.projectPath}::${i.sessionId}`})}}})},[t,Le,y]),It=h.useMemo(()=>new ae(pe,{keys:["title","subtitle","_searchText","lastUserInput"],threshold:.4,ignoreLocation:!0,includeScore:!0,includeMatches:!0}),[pe]),_t=h.useMemo(()=>new ae(Fe,{keys:["title","subtitle"],threshold:.4,includeScore:!0,includeMatches:!0}),[Fe]),St=h.useMemo(()=>new ae(De,{keys:["title","subtitle"],threshold:.4,includeScore:!0,includeMatches:!0}),[De]),vt=h.useMemo(()=>new ae(je,{keys:["title","subtitle","_searchText"],threshold:.4,ignoreLocation:!0,includeScore:!0,includeMatches:!0}),[je]),Ce=h.useMemo(()=>{if(!F.trim()){const p=[];p.push(...je);const _=[...pe].sort((T,z)=>{const ne=We(T._agentId,T._lastActivity,Te);return We(z._agentId,z._lastActivity,Te)-ne});p.push(..._),p.push(...De.slice(0,2));const L={};return Ot.forEach((T,z)=>{L[T]=z}),p.sort((T,z)=>(L[T.type]??999)-(L[z.type]??999)),p}const s=F.trim().toLowerCase(),i=Ie(s),m=Qe(It,F).slice(0,30),I=Qe(St,F).slice(0,2),k=Ct.slice(0,8),b=ke.slice(0,En),$=Qe(vt,F).filter(p=>{const _=p.score??1,L=`${p.item.title} ${p.item.subtitle||""} ${p.item._searchText||""}`.toLowerCase();return i.every(T=>L.includes(T))||_<=.2}).slice(0,4),D={agent:6,building:5,folder:4,file:4,"file-content":4,command:3,area:2,"modified-file":1,session:0},q=p=>hn(s,p.title,`${p.subtitle||""} ${p._searchText||""} ${p.matchedText||""}`),H=(p,_)=>{const L=(1-Math.min(1,_??1))*4;return q(p)*100+(D[p.type]??0)*5+L},P=new Map,Z=(p,_)=>{const L=P.get(p.type),T={item:p,score:H(p,_)};L?L.push(T):P.set(p.type,[T])},Q=new Map;for(const p of fe)p._agentId&&!Q.has(p._agentId)&&Q.set(p._agentId,p);for(const p of m){const _={...p.item};if(_._userQueries&&_._userQueries.length>0){const T=_._userQueries.find(z=>i.some(ne=>z.toLowerCase().includes(ne)));if(T){const z=T.toLowerCase(),ne=z.includes(s)?s:i.find(ge=>z.includes(ge))??s;if(T.length>200){const ge=z.indexOf(ne),bt=Math.max(0,ge-60),Lt=Math.min(T.length,ge+ne.length+100);_.matchedQuery=(bt>0?"...":"")+T.slice(bt,Lt)+(Lt<T.length?"...":"")}else _.matchedQuery=T}}const L=_._agentId?Q.get(_._agentId):void 0;if(L){_.matchedQuery||(_.matchedQuery=L.matchedQuery);const T=_.matchedQuery,z=(T==null?void 0:T.toLowerCase())??"";_.matchedExtracts=mn(T&&i.every(ne=>z.includes(ne))?T:void 0,L.matchedExtracts),_.action=L.action,_._sessionMatches=L._sessionMatches,_._searchText=`${_._searchText||""} ${L.matchedQuery||""} ${s}`}Z(_,p.score)}for(const[p,_]of Q){if(m.some(T=>T.item._agentId===p))continue;const L=Re.get(p);L&&Z({...L,matchedQuery:_.matchedQuery,matchedExtracts:_.matchedExtracts,action:_.action,_sessionMatches:_._sessionMatches,_searchText:`${L._searchText||""} ${_.matchedQuery||""} ${s}`},void 0)}for(const p of $)Z(p.item,p.score);for(const p of I)Z(p.item,p.score);for(const p of k)Z(p,void 0);for(const p of b)Z(p,void 0);for(const p of $e.slice(0,In))Z(p,void 0);const is=24*36e5,as=Date.now(),wt=p=>{const _=We(p.item._agentId,p.item._lastActivity,Te),L=Math.exp(-Math.LN2*Math.max(0,as-_)/is);return Math.log2(1+(p.item._sessionMatches??0))+4*L};for(const[p,_]of P)p==="agent"?_.sort((L,T)=>{const z=q(L.item),ne=q(T.item);if(ne!==z)return ne-z;const Be=wt(L),ge=wt(T);return ge!==Be?ge-Be:T.score-L.score}):_.sort((L,T)=>T.score-L.score);const de=[];for(const p of Ot){if(p==="session"){!pt&&fe.length>Xe?(de.push(...fe.slice(0,Xe)),de.push({id:"session-show-all",type:"session",title:`Show all conversations (${fe.length})`,subtitle:`${fe.length-Xe} more matches`,icon:d.jsx(V,{name:"arrow-down",size:16}),action:()=>yt(!0)})):de.push(...fe);continue}const _=P.get(p);if(_){if(p==="agent"&&!gt&&_.length>Je){for(const L of _.slice(0,Je))de.push(L.item);de.push({id:"agent-show-all",type:"agent",title:`Show all agents (${_.length})`,subtitle:`${_.length-Je} more matches`,icon:d.jsx(V,{name:"arrow-down",size:16}),action:()=>mt(!0)});continue}for(const L of _)de.push(L.item)}}return de},[F,It,St,vt,pe,Re,De,je,Ct,ke,$e,fe,Te,gt,pt]),se=h.useMemo(()=>{switch(v){case"agents":return Ce.filter(s=>s.type==="agent");case"buildings":return Ce.filter(s=>s.type==="building");case"commands":return F.trim()?Qe(_t,F).slice(0,3).map(s=>s.item):Fe;case"folders":return Ce.filter(s=>s.type==="folder");case"files":return ke;case"contents":return $e;case"areas":return He.flatMap(s=>s.agents);case"all":default:return Ce}},[v,Ce,He,ke,$e,F,_t,Fe]),ns=h.useMemo(()=>{const s=[];if(dt&&s.push("session"),ht&&s.push("file"),ft&&s.push("file-content"),lt&&s.push("folder"),v==="all")return s;const m={buildings:"building",folders:"folder",files:"file",contents:"file-content",agents:"agent",commands:"command"}[v];return m&&s.includes(m)?[m]:[]},[v,dt,ht,ft,lt]);h.useEffect(()=>{W>=se.length&&N(Math.max(0,se.length-1))},[se.length,W]);const rs=h.useCallback(s=>{if(s.altKey&&!s.ctrlKey&&!s.metaKey&&(s.key==="p"||s.key==="n"||s.key==="P"||s.key==="N")){s.preventDefault(),s.stopPropagation(),s.nativeEvent.stopImmediatePropagation();const i=s.key.toLowerCase();N(i==="p"?m=>m>0?m-1:se.length-1:m=>m<se.length-1?m+1:0);return}switch(s.key){case"Escape":s.preventDefault(),w.current();break;case"ArrowUp":s.preventDefault(),N(i=>i>0?i-1:se.length-1);break;case"ArrowDown":s.preventDefault(),N(i=>i<se.length-1?i+1:0);break;case"Enter":s.preventDefault(),se[W]&&se[W].action();break}},[se,W]),os=h.useCallback((s,i)=>{if(!i||!s)return s;const m=Ie(i);if(m.length===0)return s;const I=new RegExp(m.map(ln).sort((q,H)=>H.length-q.length).join("|"),"gi"),k=[];let b=0,$=0,D;for(;(D=I.exec(s))!==null;)D.index>b&&k.push(s.slice(b,D.index)),k.push(qe.createElement("mark",{key:$++,className:"spotlight-highlight"},D[0])),b=D.index+D[0].length;return b<s.length&&k.push(s.slice(b)),k.length>0?qe.createElement(qe.Fragment,null,...k):s},[]);return{query:F,setQuery:ts,selectedIndex:W,setSelectedIndex:N,results:se,loadingTypes:ns,activeTab:v,setActiveTab:Ue,cycleTab:ss,areaSections:He,handleKeyDown:rs,highlightMatch:os}}const Ln=h.forwardRef(function({query:e,onQueryChange:n,onKeyDown:r,onResetSelection:o},a){const{t:c}=Oe(["common"]);return d.jsxs("div",{className:"spotlight-input-wrapper",children:[d.jsx("span",{className:"spotlight-search-icon",children:"⌘"}),d.jsx("input",{ref:a,type:"text",className:"spotlight-input",placeholder:c("common:search.spotlightPlaceholder"),value:e,onChange:u=>{n(u.target.value),o()},onKeyDown:r,autoFocus:!0,spellCheck:!1}),d.jsxs("div",{className:"spotlight-input-hints",children:[d.jsx("span",{className:"spotlight-shortcut-hint",children:"↑↓"}),d.jsx("span",{className:"spotlight-shortcut-hint",children:"Enter"}),d.jsx("span",{className:"spotlight-shortcut-hint",children:"Esc"})]})]})}),Tn=h.memo(function({activeTab:e,onSelect:n}){const{t:r}=Oe(["terminal"]);return d.jsxs("div",{className:"spotlight-tabs",role:"tablist","aria-label":r("terminal:spotlight.tabsLabel"),children:[ye.map(o=>d.jsx("button",{type:"button",role:"tab","aria-selected":o===e,tabIndex:-1,className:`spotlight-tab${o===e?" active":""}`,onClick:()=>n(o),children:r(`terminal:spotlight.tabs.${o}`)},o)),d.jsx("span",{className:"spotlight-tabs-hint",children:d.jsx("kbd",{children:"Tab"})})]})}),Fn=h.forwardRef(function({results:e,loadingTypes:n,selectedIndex:r,query:o,activeTab:a,areaSections:c,highlightMatch:u,onSelectIndex:f},l){const{t:g}=Oe(["terminal"]),x=h.useRef(!1);h.useEffect(()=>{x.current=!1},[e]),h.useEffect(()=>{const A=typeof l=="function"?null:l==null?void 0:l.current;if(!A)return;const M=()=>{x.current=!0};return A.addEventListener("mousemove",M),()=>{A.removeEventListener("mousemove",M)}},[l,e]);const y={command:g("terminal:spotlight.categories.commands"),agent:g("terminal:spotlight.categories.agents"),building:g("terminal:spotlight.categories.infrastructure"),area:g("terminal:spotlight.categories.areas"),folder:g("terminal:spotlight.categories.folders"),file:g("terminal:spotlight.categories.files"),"file-content":g("terminal:spotlight.categories.fileContents"),"modified-file":g("terminal:spotlight.categories.modifiedFiles"),session:g("terminal:spotlight.categories.sessions")},E=h.useMemo(()=>{const A=[];let M=null,S=[];e.forEach((w,j)=>{w.type!==M&&(M!==null&&S.length>0&&A.push([M,S]),M=w.type,S=[]),S.push({result:w,index:j})}),M!==null&&S.length>0&&A.push([M,S]);for(const w of n)A.some(([j])=>j===w)||A.push([w,[]]);const R=["agent","session","building","file","file-content","folder","area","command"];return A.sort(([w],[j])=>R.indexOf(w)-R.indexOf(j)),A},[e,n]);if(h.useEffect(()=>{if(!l||typeof l=="function")return;const A=l.current;if(!A)return;const M=A.querySelector(".spotlight-item.selected");M&&M.scrollIntoView({block:"nearest",behavior:"smooth"})},[r,l]),a==="areas"){if(c.length===0)return d.jsx("div",{className:"spotlight-results",ref:l,children:d.jsx("div",{className:"spotlight-empty",children:g("terminal:spotlight.noResults")})});let A=0;return d.jsx("div",{className:"spotlight-results",ref:l,children:c.map(M=>d.jsxs("div",{children:[d.jsxs("div",{className:"spotlight-category-header spotlight-area-section-header",children:[d.jsx("span",{className:"spotlight-area-dot",style:{background:M.areaColor},"aria-hidden":"true"}),d.jsx("span",{className:"spotlight-area-name",children:M.areaName}),d.jsx("span",{className:"spotlight-area-count",children:M.agents.length})]}),M.agents.length===0?d.jsx("div",{className:"spotlight-area-empty",children:g("terminal:spotlight.noAgentsInArea")}):M.agents.map(S=>{const R=A++;return d.jsx(Rt,{result:S,isSelected:R===r,query:o,highlightMatch:u,onClick:()=>S.action(),onMouseEnter:()=>{x.current&&f(R)}},S.id)})]},M.areaId))})}return e.length===0&&n.length===0?d.jsx("div",{className:"spotlight-results",ref:l,children:d.jsx("div",{className:"spotlight-empty",children:g("terminal:spotlight.noResults")})}):d.jsx("div",{className:"spotlight-results",ref:l,children:E.map(([A,M])=>d.jsxs("div",{children:[(a==="all"||E.length>1)&&d.jsx("div",{className:"spotlight-category-header",children:y[A]||A}),n.includes(A)&&d.jsxs("div",{className:"spotlight-block-loading",role:"status",children:[d.jsx("span",{className:"spotlight-loading-spinner","aria-hidden":"true"}),g("terminal:spotlight.searching")]}),M.map(({result:S,index:R})=>d.jsx(Rt,{result:S,isSelected:R===r,query:o,highlightMatch:u,onClick:()=>S.action(),onMouseEnter:()=>{x.current&&f(R)}},S.id))]},A))})}),Nn=h.memo(function(){const{t:e}=Oe(["terminal"]);return d.jsxs("div",{className:"spotlight-footer",children:[d.jsxs("div",{className:"spotlight-footer-left",children:[d.jsxs("span",{className:"spotlight-footer-hint",children:[d.jsx("kbd",{children:"↑"}),d.jsx("kbd",{children:"↓"})," ",d.jsx("kbd",{children:"Alt+N"}),d.jsx("kbd",{children:"Alt+P"})," ",e("terminal:spotlight.navigate")]}),d.jsxs("span",{className:"spotlight-footer-hint",children:[d.jsx("kbd",{children:"Enter"})," ",e("terminal:spotlight.select")]}),d.jsxs("span",{className:"spotlight-footer-hint",children:[d.jsx("kbd",{children:"Tab"})," ",e("terminal:spotlight.switchTabs")]})]}),d.jsx("div",{className:"spotlight-footer-right",children:d.jsxs("span",{className:"spotlight-footer-hint",children:[d.jsx("kbd",{children:"Esc"})," ",e("common:buttons.close")]})})]})});function Dn({detail:t,onClose:e}){const[n,r]=h.useState(null),[o,a]=h.useState(!0),[c,u]=h.useState(null);Cs("spotlight-file-detail",!0,e),h.useEffect(()=>{const E=new AbortController;return a(!0),u(null),r(null),(async()=>{try{const M=await Ze(et(`/api/files/read?path=${encodeURIComponent(t.filePath)}`),{signal:E.signal}),S=await M.json();if(!M.ok)throw new Error(S.error||"Unable to read file");let R=null;if(!S.binary)try{const w=await Ze(et(`/api/files/git-original?path=${encodeURIComponent(t.filePath)}`),{signal:E.signal}),j=await w.json();w.ok&&!j.binary&&typeof j.content=="string"&&(R=j.content)}catch{}E.signal.aborted||r({filename:S.filename||t.filePath.split("/").pop()||t.filePath,content:typeof S.content=="string"?S.content:"",originalContent:R,binary:S.binary===!0})}catch(M){E.signal.aborted||u(M instanceof Error?M.message:"Unable to load file")}finally{E.signal.aborted||a(!1)}})(),()=>E.abort()},[t.filePath]),h.useEffect(()=>{const E=A=>{A.key==="Escape"&&(A.preventDefault(),A.stopImmediatePropagation(),e())};return document.addEventListener("keydown",E,!0),()=>document.removeEventListener("keydown",E,!0)},[e]);const f=()=>{U.revealFileInExplorer(t.filePath,t.projectRoot,t.targetLine),e()},l=(n==null?void 0:n.filename)||t.filePath,g=l.lastIndexOf(".")>=0?l.slice(l.lastIndexOf(".")):"",x=Is(g),y=(n==null?void 0:n.originalContent)!=null&&n.originalContent!==n.content;return d.jsx("div",{className:"guake-git-diff-modal-overlay",onClick:e,children:d.jsxs("div",{className:"guake-git-diff-modal",onClick:E=>E.stopPropagation(),children:[d.jsxs("div",{className:"guake-git-diff-modal-header",children:[d.jsxs("div",{className:"guake-git-diff-path spotlight-file-detail-path",title:t.filePath,children:[t.filePath,t.targetLine?d.jsxs("span",{className:"spotlight-file-detail-line",children:[":",t.targetLine]}):null]}),d.jsxs("button",{type:"button",className:"spotlight-file-detail-explorer",onClick:f,title:"Open in File Explorer",children:[d.jsx(V,{name:"folder-open",size:14}),"Open in File Explorer"]}),d.jsx("button",{className:"guake-git-close",onClick:e,title:"Close (Esc)",children:d.jsx(V,{name:"close",size:14})})]}),d.jsxs("div",{className:"guake-git-diff-content",children:[o&&d.jsx("div",{className:"guake-git-diff-loading-overlay",children:d.jsx("div",{className:"diff-image-spinner"})}),c&&d.jsx("div",{className:"spotlight-file-detail-message",children:c}),(n==null?void 0:n.binary)&&d.jsx("div",{className:"spotlight-file-detail-message",children:"Binary preview is available in the File Explorer."}),n&&!n.binary&&(y?d.jsx(jt,{originalContent:n.originalContent||"",modifiedContent:n.content,filename:n.filename,filePath:t.filePath,language:x,searchQuery:t.searchQuery,targetLine:t.targetLine}):d.jsx(jt,{originalContent:"",modifiedContent:n.content,filename:n.filename,filePath:t.filePath,language:x,initialModifiedOnly:!0,searchQuery:t.searchQuery,targetLine:t.targetLine,readOnly:!0}))]})]})})}const Rn=768;function Bn({isOpen:t,onClose:e,onOpenSpawnModal:n,onOpenCommanderView:r,onOpenToolbox:o,onOpenFileExplorer:a,onOpenPM2LogsModal:c,onOpenBossLogsModal:u,onOpenDatabasePanel:f,onOpenMonitoringModal:l,onOpenSessionFinder:g}){const x=h.useRef(null),y=h.useRef(null),E=h.useRef(null),A=h.useRef(0),[M,S]=h.useState(null),{query:R,setQuery:w,selectedIndex:j,setSelectedIndex:K,results:le,loadingTypes:he,activeTab:B,setActiveTab:Y,cycleTab:G,areaSections:ie,handleKeyDown:re,highlightMatch:J}=bn({isOpen:t,onClose:e,onOpenSpawnModal:n,onOpenCommanderView:r,onOpenToolbox:o,onOpenFileExplorer:a,onOpenPM2LogsModal:c,onOpenBossLogsModal:u,onOpenDatabasePanel:f,onOpenMonitoringModal:l,onOpenSessionFinder:g,onOpenFileDetail:S});A.current=le.length;const F=h.useRef(G);F.current=G,h.useEffect(()=>{t&&setTimeout(()=>{var N,v;(N=x.current)==null||N.focus(),(v=x.current)==null||v.select()},50)},[t]),h.useEffect(()=>{if(!t)return;const N=window.visualViewport;if(!N||window.innerWidth>Rn)return;const v=()=>{const ee=y.current;ee&&(ee.style.height=`${N.height}px`,ee.style.top=`${N.offsetTop}px`)};return v(),N.addEventListener("resize",v),N.addEventListener("scroll",v),()=>{N.removeEventListener("resize",v),N.removeEventListener("scroll",v);const ee=y.current;ee&&(ee.style.height="",ee.style.top="")}},[t]),h.useEffect(()=>{if(!t)return;const N=v=>{if(v.key==="Escape"){v.preventDefault(),v.stopPropagation(),v.stopImmediatePropagation(),e();return}if(v.key==="Tab"){v.preventDefault(),v.stopPropagation(),v.stopImmediatePropagation(),F.current(v.shiftKey?-1:1);return}if(v.altKey&&!v.ctrlKey&&!v.metaKey&&(v.key==="n"||v.key==="p"||v.key==="N"||v.key==="P")){v.preventDefault(),v.stopPropagation(),v.stopImmediatePropagation();const ee=v.key.toLowerCase(),Ae=A.current;K(ee==="p"?te=>te>0?te-1:Ae-1:te=>te<Ae-1?te+1:0);return}};return window.addEventListener("keydown",N,{capture:!0}),()=>{window.removeEventListener("keydown",N,{capture:!0})}},[t,e]);const O=h.useCallback(N=>{N.target===N.currentTarget&&e()},[e]),W=h.useCallback(()=>{K(0)},[K]);return t?d.jsx("div",{ref:y,className:"spotlight-overlay",onClick:O,children:d.jsxs("div",{className:"spotlight-modal",children:[d.jsx(Ln,{ref:x,query:R,onQueryChange:w,onKeyDown:re,onResetSelection:W}),d.jsx(Tn,{activeTab:B,onSelect:Y}),d.jsx(Fn,{ref:E,results:le,loadingTypes:he,selectedIndex:j,query:R,activeTab:B,areaSections:ie,highlightMatch:J,onSelectIndex:K}),d.jsx(Nn,{})]})}):M?d.jsx(Dn,{detail:M,onClose:()=>S(null)}):null}export{zn as FILE_ICON_NAMES,Bn as Spotlight,Nn as SpotlightFooter,Ln as SpotlightInput,Rt as SpotlightItem,Fn as SpotlightResults,Kn as formatDuration,On as formatRelativeTime,Un as getAgentIcon,Dt as getFileIconFromPath,Gn as getTypeLabel,bn as useSpotlightSearch};
@@ -0,0 +1,2 @@
1
+ import{r as n,aW as $a,aX as oa,N as ba,aY as _a,j as e,aZ as wa,a_ as Da,u as sa,a$ as za,b0 as Ra,b1 as Oa,b2 as Fa,b3 as Ba,aj as Wa,b4 as Ha,b5 as Ua,aC as va,m as Vt,S as E,y as qt,b6 as ta,b7 as ca,b8 as Lt,b9 as xe,ba as Ga,s as g,K as ja,a0 as Ca,f as ka,bb as Xa,bc as da,bd as ua,I as d,be as Va,bf as aa,aF as Na,bg as qa,n as ya,ad as Aa,bh as Sa,bi as Ya,bj as Ka,bk as Za,ai as Ja,bl as Qa,bm as en,bn as tn,aI as an,aJ as nn,aK as sn,bo as ln,bp as rn,bq as na,Z as on,U as cn,br as dn,bs as un,bt as mn,bu as pn,bv as fn,bw as hn,bx as gn,by as Yt,bz as ma,bA as xn,bB as bn,bC as _n,z as wn,bD as vn,bE as jn,bF as Cn,bG as kn,bH as ct,bI as Nn,bJ as yn,bK as An,bL as Sn,bM as wt,bN as En,bO as In,bP as Mn,bQ as Tn,p as Ln,D as Pn,t as Kt,o as $n}from"./main-Dk3qq80S.js";import{g as Dn}from"./area-logos-DYARiYqI.js";import"./vendor-react--Eh9ivFN.js";import"./vendor-three-DYBBrXTx.js";function zn(c){const o=n.useRef(c);o.current=c,n.useEffect(()=>{if(!$a())return;let m=null,b=!1;return oa.addListener("backButton",()=>{o.current()==="exit"&&oa.exitApp()}).then(y=>{b?y.remove():m=y}),()=>{b=!0,m&&(m.remove(),m=null)}},[])}async function Rn(c){const o=ba(),m=await fetch(`${_a()}/api/agents/${c}/terminal`,{method:"POST",headers:{Authorization:`Bearer ${o}`}});if(!m.ok){const b=await m.json().catch(()=>({}));throw new Error((b==null?void 0:b.error)||`Failed to start terminal (${m.status})`)}return m.json()}async function On(c){const o=ba();await fetch(`${_a()}/api/agents/${c}/terminal`,{method:"DELETE",headers:{Authorization:`Bearer ${o}`}})}const vt=new Map;function Fn({agentId:c}){const[o,m]=n.useState(null),[b,y]=n.useState(null);return n.useEffect(()=>{let M=!1;const A=vt.get(c);return A&&(clearTimeout(A),vt.delete(c)),m(null),y(null),Rn(c).then(k=>{M||m(k.url)}).catch(k=>{M||y(k instanceof Error?k.message:"Failed to start terminal")}),()=>{M=!0;const k=vt.get(c);k&&clearTimeout(k),vt.set(c,setTimeout(()=>{vt.delete(c),On(c)},2500))}},[c]),b?e.jsx("div",{className:"flat-classic-terminal flat-classic-terminal--message",children:e.jsx("span",{children:b})}):o?e.jsx("div",{className:"flat-classic-terminal",children:e.jsx(wa,{terminalUrl:o,visible:!0})}):e.jsx("div",{className:"flat-classic-terminal flat-classic-terminal--message",children:e.jsx("span",{children:"Attaching to interactive session…"})})}const Zt=new Map,Bn=6e4;function pa(c){return Number.isFinite(c)?Math.abs(c)>=1e3?c.toLocaleString(void 0,{maximumFractionDigits:0}):c.toLocaleString(void 0,{maximumFractionDigits:2}):String(c)}function Wn(c,o){var y,M,A;const m=[];if(!c.rateLimits)return m;if(c.provider==="claude"){const k=c,K=[{key:"fiveHour",label:o("terminal:usage.currentSession"),window:k.rateLimits.fiveHour},{key:"sevenDay",label:o("terminal:usage.currentWeekAll"),window:k.rateLimits.sevenDay},{key:"sevenDayOpus",label:o("terminal:usage.currentWeekOpus"),window:k.rateLimits.sevenDayOpus},{key:"sevenDayFable",label:o("terminal:usage.currentWeekFable"),window:k.rateLimits.sevenDayFable}];for(const j of K)(j.window||j.key==="sevenDayFable")&&m.push(j);return m}const b=c;return(y=b.rateLimits)!=null&&y.weekly&&m.push({key:"weekly",label:o("terminal:usage.weeklyLimit"),window:b.rateLimits.weekly}),(M=b.rateLimits)!=null&&M.monthly&&m.push({key:"monthly",label:o("terminal:usage.monthlyLimit"),window:b.rateLimits.monthly}),(A=b.rateLimits)!=null&&A.onDemand&&m.push({key:"onDemand",label:o("terminal:usage.onDemandLimit"),window:b.rateLimits.onDemand}),m}function Hn({agentId:c,contextSummary:o}){const{t:m}=sa(["terminal","common"]),[b,y]=n.useState(()=>{var R;return((R=Zt.get(c))==null?void 0:R.snapshot)??null}),[M,A]=n.useState(!1),[k,K]=n.useState(null),j=n.useRef(0);n.useEffect(()=>{const R=Zt.get(c);if(R&&Date.now()-R.fetchedAt<Bn){y(R.snapshot);return}const be=++j.current;A(!0),K(null),za(c).then(L=>{be===j.current&&(Zt.set(c,{snapshot:L,fetchedAt:Date.now()}),y(L),A(!1))}).catch(L=>{be===j.current&&(K(L.message||"Failed to load plan limits"),A(!1))})},[c]);const v=b?Wn(b,m):[];return e.jsxs("div",{className:"plan-limits-tooltip",children:[o&&e.jsx("div",{className:"plan-limits-tooltip__context",children:o}),e.jsx("div",{className:"plan-limits-tooltip__title",children:m("terminal:usage.limits")}),M&&!b&&e.jsxs("div",{className:"plan-limits-tooltip__muted",children:[m("common:status.loading"),"…"]}),!M&&k&&!b&&e.jsx("div",{className:"plan-limits-tooltip__muted",children:m("terminal:usage.limitsError",{message:k})}),v.length>0?e.jsx("div",{className:"plan-limits-tooltip__gauges",children:v.map(({key:R,label:be,window:L})=>{const _e=L?Math.max(0,Math.min(100,L.utilization)):0,te=Oa(_e),ue=L!=null&&typeof L.used=="number"&&typeof L.limit=="number"&&Number.isFinite(L.used)&&Number.isFinite(L.limit);return e.jsxs("div",{className:"plan-limits-tooltip__gauge",children:[e.jsxs("div",{className:"plan-limits-tooltip__gauge-head",children:[e.jsx("span",{className:"plan-limits-tooltip__gauge-label",children:be}),e.jsx("span",{className:"plan-limits-tooltip__gauge-percent",style:{color:te},children:m("terminal:usage.percentUsed",{percent:Math.round(_e)})})]}),e.jsx("div",{className:"plan-limits-tooltip__bar",children:e.jsx("div",{className:"plan-limits-tooltip__bar-fill",style:{width:`${_e}%`,background:te}})}),e.jsxs("div",{className:"plan-limits-tooltip__reset",children:[L&&m("terminal:usage.resets",{time:Ra(L.resetsAt)}),ue&&e.jsx("span",{style:{marginLeft:8},children:m("terminal:usage.creditsUsed",{used:pa(L.used),limit:pa(L.limit)})})]})]},R)})}):b&&!M&&e.jsx("div",{className:"plan-limits-tooltip__muted",children:b.rateLimitsError?m("terminal:usage.limitsError",{message:b.rateLimitsError}):b.cliHint})]})}function Un({agentId:c,disabled:o,contextSummary:m,children:b}){return e.jsx(Da,{position:"top",maxWidth:320,disabled:o,className:"plan-limits-tooltip-wrapper",triggerStyle:{display:"inline-flex",alignItems:"center"},content:e.jsx(Hn,{agentId:c,contextSummary:m}),children:b})}const Gn=n.memo(function({className:o=""}){const{t:m}=sa(["common"]),[b,y]=Fa(),M=n.useRef(null),[A,k]=n.useState(null);n.useLayoutEffect(()=>{const j=M.current;if(!j)return;const v=j.querySelector(".view-mode-toggle__btn--active");v&&k({left:v.offsetLeft,width:v.offsetWidth})},[b]);const K=n.useCallback(j=>{if(j!==b){if(typeof window<"u"&&window.dispatchEvent(new CustomEvent("tide:viewmode-switch-pressed",{detail:{mode:j}})),j==="3d"){requestAnimationFrame(()=>y(j));return}y(j)}},[b,y]);return e.jsxs("div",{className:`view-mode-toggle ${o}`,ref:M,children:[A&&e.jsx("div",{className:"view-mode-toggle__indicator",style:{left:A.left,width:A.width}}),Ba.map(j=>e.jsxs("button",{className:`view-mode-toggle__btn ${b===j?"view-mode-toggle__btn--active":""}`,onClick:()=>K(j),title:m(`common:viewMode.descriptions.${j}`),children:[e.jsxs("span",{className:"view-mode-toggle__icon",children:[j==="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"})]}),j==="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"})]}),j==="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"})]}),j==="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:m(`common:viewMode.labels.${j}`)})]},j))]})}),Pt=3,$t=280,fa=320,Jt=240,ha=64,Xn=["simple","chat","advanced"],ga={simple:"Simple",chat:"Chat",advanced:"Advanced"},xa={simple:"○",chat:"◐",advanced:"◉"},Vn={simple:"Simple view — clean messages only",chat:"Chat view — assistant replies (no tool calls)",advanced:"Advanced view — everything including tools"},Qt="flat-clear-context",Ea="tide:flat-embedded-panels";function Ia(){try{const c=localStorage.getItem(Ea),o=c?JSON.parse(c):{};return o&&typeof o=="object"?o:{}}catch{return{}}}function ea(c,o){try{const m=Ia();o?m[c]=o:delete m[c],localStorage.setItem(Ea,JSON.stringify(m))}catch{}}function qn(c){const o=c.split("/").filter(Boolean);return o.length===0?c:o.slice(-2).join("/")}function Yn(c){if(c.provider==="codex"){const M=c.codexModel||"gpt-5.6-luna",A=Ln[M];return{model:(A==null?void 0:A.label)||M}}if(c.provider==="opencode")return{model:c.opencodeModel||"opencode"};if(c.provider==="grok"){const M=c.grokModel||Pn,A=c.effort,k=A?Kt[A]:void 0;return{model:M,effort:k==null?void 0:k.label}}if(c.provider==="pi"){const M=c.piModel||"pi default",A=c.effort,k=A?Kt[A]:void 0;return{model:M,effort:k==null?void 0:k.label}}const o=c.model||c.detectedModel||"default",m=$n[o],b=c.effort,y=b?Kt[b]:void 0;return{model:(m==null?void 0:m.label)||o,effort:y==null?void 0:y.label}}function Kn(c,o){if(o.type==="rectangle"&&o.width&&o.height){const m=o.width/2,b=o.height/2;return c.x>=o.center.x-m&&c.x<=o.center.x+m&&c.z>=o.center.z-b&&c.z<=o.center.z+b}if(o.type==="circle"&&o.radius){const m=c.x-o.center.x,b=c.z-o.center.z;return m*m+b*b<=o.radius*o.radius}return!1}const Zn=cn.memo(function({agentId:o,terminalViewMode:m,onTerminalViewModeChange:b,inspectorOpen:y,onToggleInspector:M,onShowTaskBoard:A,onImageClick:k,onFileClick:K,onBashClick:j,onViewMarkdown:v,onRequestClearSubordinates:R,keyboard:be,canNavigateBack:L,canNavigateForward:_e,onNavigateBack:te,onNavigateForward:ue,agentInfoOpen:Ze,onToggleAgentInfo:jt,onHeaderContextMenu:dt,onBuildingContextMenu:$e}){var Z,It;const p=ja(o),O=ka(),we=dn(),ve=n.useRef(null),me=n.useRef(null),Je=o,Qe=p,je=!!we.interactiveMode&&((p==null?void 0:p.provider)??"claude")==="claude"&&!!(p!=null&&p.sessionId),[ae,et]=n.useState(!1),[tt,Ue]=n.useState(null),Dt=n.useMemo(()=>{const a=Xn.map(l=>{const i=!ae&&m===l;return{id:`view-mode-${l}`,label:ga[l],icon:e.jsx("span",{className:"flat-terminal-wrapper__view-mode-icon",children:xa[l]}),shortcut:i?"✓":void 0,onClick:()=>{et(!1),b(l),Ue(null)}}});return je&&a.push({id:"view-mode-classic-tui",label:"Classic TUI",icon:e.jsx(d,{name:"terminal",size:13}),shortcut:ae?"✓":void 0,onClick:()=>{et(l=>!l),Ue(null)}}),a},[je,ae,m,b]),[Ge,pe]=n.useState(!1),D=n.useCallback(()=>pe(!1),[]);va("flat-chat-actions",Ge,D),n.useEffect(()=>{const a=()=>pe(l=>!l);return window.addEventListener("tide:toggle-chat-actions",a),()=>window.removeEventListener("tide:toggle-chat-actions",a)},[]),n.useEffect(()=>{et(!1),pe(!1)},[o]),n.useEffect(()=>{!je&&ae&&et(!1)},[je,ae]),n.useEffect(()=>{const a=me.current;if(!a)return;const l=u=>{u.button===3?(u.preventDefault(),u.stopPropagation(),te()):u.button===4&&(u.preventDefault(),u.stopPropagation(),ue())},i=u=>{(u.button===3||u.button===4)&&u.preventDefault()};return a.addEventListener("mouseup",l),a.addEventListener("mousedown",i),()=>{a.removeEventListener("mouseup",l),a.removeEventListener("mousedown",i)}},[te,ue]),n.useEffect(()=>{const a=me.current;if(!a)return;let l=0,i=0,u=0;const $=250,V=600,S=80,Le=1.5,ot=U=>{let t=U instanceof HTMLElement?U:null;for(;t&&t!==a;){const s=window.getComputedStyle(t).overflowX;if((s==="auto"||s==="scroll")&&t.scrollWidth>t.clientWidth)return!0;t=t.parentElement}return!1},z=U=>{const t=Date.now();if(t<u){U.preventDefault();return}if(Math.abs(U.deltaX)<=Math.abs(U.deltaY)*Le){l=0;return}if(ot(U.target)){l=0;return}t-i>$&&(l=0),i=t,l+=U.deltaX,l<=-S?(l=0,u=t+V,U.preventDefault(),te()):l>=S&&(l=0,u=t+V,U.preventDefault(),ue())};return a.addEventListener("wheel",z,{passive:!1}),()=>a.removeEventListener("wheel",z)},[te,ue]);const ne=Ca(),ut=n.useMemo(()=>{if(!p)return null;const a=new Set,l=[];for(const i of ne.values())i.archived||i.directories.length===0||i.assignedAgentIds.includes(o)&&(a.add(i.id),l.push(i));for(const i of ne.values())i.archived||i.directories.length===0||a.has(i.id)||Kn({x:p.position.x,z:p.position.z},i)&&(a.add(i.id),l.push(i));return l.length===0?null:l.flatMap(i=>i.directories.filter(u=>u&&u.trim().length>0).map(u=>({areaId:i.id,areaName:i.name,dir:u})))},[p,o,ne]),{branches:Ct,fetchRemote:Xe,fetchingDirs:De}=un(ut),[Ce,at]=n.useState({}),[fe,Ve]=n.useState(null),Q=n.useMemo(()=>{var $,V;const a=g.getAreaForAgent(o);if(!a)return[];const l=[],i=($=a.directories.find(S=>S&&S.trim().length>0))==null?void 0:$.trim(),u=i?i.split("/").filter(Boolean).pop()||i:a.name;l.push({id:mn(a.id),name:u,hasUrl:!!Ce[a.id],isDefault:!0});for(const S of O.values())S.type==="terminal"&&g.isPositionInArea(S.position,a)&&l.push({id:S.id,name:S.name,hasUrl:!!((V=S.terminalStatus)!=null&&V.url)});return l},[o,O,ne,Ce]),se=n.useMemo(()=>{var i;const a=g.getAreaForAgent(o);if(!a)return[];const l=[];for(const u of O.values())u.type==="server"&&((i=u.pm2)!=null&&i.enabled)&&g.isPositionInArea(u.position,a)&&l.push({id:u.id,name:u.name});return l},[o,O]),nt=n.useMemo(()=>{const a=g.getAreaForAgent(o);if(!a)return[];const l=[];for(const i of O.values())i.type==="database"&&i.database&&g.isPositionInArea(i.position,a)&&l.push({id:i.id,name:i.name});return l},[o,O]),kt=pn(),qe=n.useMemo(()=>{const a=g.getAreaForAgent(o);if(!a)return[];const l=[];for(const i of O.values())if(i.type==="tests"&&g.isPositionInArea(i.position,a)){const u=!!i.folderPath&&kt.some($=>fn($,i.folderPath));l.push({id:i.id,name:i.name,working:u})}return l},[o,O,kt]),ke=n.useMemo(()=>{const a=g.getAreaForAgent(o);if(!a)return[];const l=[];for(const i of O.values())i.type==="http"&&g.isPositionInArea(i.position,a)&&l.push({id:i.id,name:i.name});return l},[o,O]),[,zt]=n.useReducer(a=>a+1,0),Ne=((Z=ve.current)==null?void 0:Z.search.searchMode)??!1,ye=n.useCallback(()=>{var a;(a=ve.current)==null||a.search.toggleSearch(),zt()},[]),mt=hn(),ie=mt.isPending(Qt),[_,he]=n.useState(null),F=_?O.get(_.buildingId):null,[Nt,ze]=n.useState(""),[pt,Rt]=n.useState(()=>gn()),B=n.useMemo(()=>{var a;return((a=g.getAreaForAgent(o))==null?void 0:a.id)??null},[o,O]),Re=n.useCallback((a,l)=>{ze(""),he(i=>{const u=(i==null?void 0:i.buildingId)===l?null:{type:a,buildingId:l};return B&&ea(B,u),u})},[B]),ee=n.useCallback(()=>{ze(""),he(null),B&&ea(B,null)},[B]);n.useEffect(()=>{if((_==null?void 0:_.type)!=="pm2-logs")return;const a=_.buildingId;return g.startLogStreaming(a,200),()=>g.stopLogStreaming(a)},[_]),n.useEffect(()=>{if(Ve(null),(_==null?void 0:_.type)!=="terminal"||!Yt(_.buildingId))return;const a=ma(_.buildingId);let l=!1;return xn(a).then(i=>{l||at(u=>u[a]===i.url?u:{...u,[a]:i.url})}).catch(i=>{l||Ve(i instanceof Error?i.message:"Failed to start terminal")}),()=>{l=!0}},[_]);const{height:Ot,onResizeStart:Ft}=bn(),{sidePanelWidth:Ae,handleSidePanelResizeStart:le}=_n(),[re,ft]=n.useState(()=>ta(E.GIT_PANEL_OPEN,!1)),[Oe,yt]=n.useState(()=>ta(E.BUILDINGS_PANEL_OPEN,!1)),[Fe,At]=n.useState(!1),st=n.useCallback(()=>{At(a=>!a)},[]),Ye=n.useCallback(()=>At(!1),[]),it=n.useCallback(()=>{ft(a=>{const l=!a;return xe(E.GIT_PANEL_OPEN,l),l})},[]),Se=n.useCallback(()=>{yt(a=>{const l=!a;return xe(E.BUILDINGS_PANEL_OPEN,l),l})},[]),Bt=n.useCallback(()=>{ft(!1),xe(E.GIT_PANEL_OPEN,!1)},[]),oe=n.useCallback(()=>{yt(!1),xe(E.BUILDINGS_PANEL_OPEN,!1)},[]),Be=wn(),We=n.useMemo(()=>({terminal:Q,"pm2-logs":se,database:nt,tests:qe,http:ke}),[Q,se,nt,qe,ke]);n.useEffect(()=>{if(!_)return;We[_.type].some(l=>l.id===_.buildingId)||(ze(""),he(null))},[_,We]);const St=n.useRef(void 0);n.useEffect(()=>{var l;if(St.current===B)return;St.current=B;const a=B?Ia()[B]:void 0;ze(""),a&&((l=We[a.type])!=null&&l.some(i=>i.id===a.buildingId))?he(a):he(null)},[B,We]),n.useEffect(()=>{const a=l=>{var $;const i=l.detail;if(!(i!=null&&i.buildingId)||!(i!=null&&i.type)||!(($=We[i.type])!=null&&$.some(V=>V.id===i.buildingId)))return;i.handled=!0,ze("");const u={type:i.type,buildingId:i.buildingId};he(u),B&&ea(B,u)};return window.addEventListener("tide:dock-building-flat",a),()=>window.removeEventListener("tide:dock-building-flat",a)},[We,B]);const[Ee,Ie]=n.useState(!1),ht=n.useRef(null);if(n.useEffect(()=>{if(!Ee)return;const a=l=>{ht.current&&!ht.current.contains(l.target)&&Ie(!1)};return document.addEventListener("mousedown",a),()=>document.removeEventListener("mousedown",a)},[Ee]),!p)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 gt=!!p.contextStats,{totalTokens:Wt,contextWindow:ge,usedPercent:ce}=Na(p),xt=Math.round(ce*10)/10,Ht=Math.round((100-ce)*10)/10,bt=ce>=80?"#ff4a4a":ce>=60?"#ff9e4a":ce>=40?"#ffd700":"#4aff9e",He=(Wt/1e3).toFixed(1),lt=(ge/1e3).toFixed(1),Me=p.cwd,rt=Me?qn(Me):null,Te=((It=p.subordinateIds)==null?void 0:It.length)||0,Et=Te>0;return e.jsxs("div",{ref:me,className:`flat-terminal-wrapper ${re||Oe||Fe?"flat-terminal-wrapper--with-side-panel":""}`,style:{"--guake-side-panel-width":`min(${Ae}px, 70%)`},children:[e.jsxs("div",{className:"flat-terminal-wrapper__header",children:[e.jsxs("button",{type:"button",className:`flat-terminal-wrapper__header-main ${Ze?"flat-terminal-wrapper__header-main--active":""}`,onClick:jt,onContextMenu:a=>{a.preventDefault(),a.stopPropagation(),dt({x:a.clientX,y:a.clientY})},title:Ze?"Hide agent info":"Show agent info","aria-pressed":Ze,children:[e.jsxs("span",{className:`flat-terminal-wrapper__header-avatar${p.status==="working"?" is-working":""}`,children:[e.jsx(ya,{agent:p,size:28}),p.status==="working"&&e.jsx(aa,{animated:!0,size:12,className:"flat-terminal-wrapper__header-activity"})]}),e.jsxs("span",{className:"flat-terminal-wrapper__header-info",children:[e.jsx("span",{className:"flat-terminal-wrapper__header-name",children:p.name}),e.jsx("span",{className:"flat-terminal-wrapper__header-status",style:{color:Sa(p.status)},title:p.status==="error"&&p.lastError?p.lastError:void 0,children:p.status})]}),p.taskLabel&&e.jsxs("span",{className:"flat-terminal-wrapper__header-task",title:p.taskLabel,children:["📋 ",p.taskLabel]}),e.jsxs("span",{className:"flat-terminal-wrapper__header-model",children:[e.jsx(Aa,{agent:p,alt:`${p.name} provider`,className:"flat-terminal-wrapper__header-provider-icon"}),(()=>{const{model:a,effort:l}=Yn(p);return e.jsxs("span",{className:"flat-terminal-wrapper__header-model-chip",title:l?`Model: ${a} · Effort: ${l}`:`Model: ${a}`,children:[e.jsx("span",{className:"flat-terminal-wrapper__header-model-name",children:a}),l&&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:l})]})]})})()]})]}),e.jsxs("div",{className:"flat-terminal-wrapper__header-meta",children:[e.jsx("div",{className:"flat-terminal-wrapper__view-mode",children:e.jsxs("button",{type:"button",className:`flat-terminal-wrapper__view-mode-btn flat-terminal-wrapper__view-mode-trigger${tt?" flat-terminal-wrapper__view-mode-trigger--open":""}`,onClick:a=>{const l=a.currentTarget.getBoundingClientRect();Ue({x:l.left,y:l.bottom+4})},title:ae?"Classic TUI — attach to the live interactive claude session in a terminal":Vn[m],"aria-haspopup":"menu","aria-expanded":!!tt,"aria-label":"Message view mode",children:[e.jsx("span",{className:"flat-terminal-wrapper__view-mode-icon","aria-hidden":"true",children:ae?e.jsx(d,{name:"terminal",size:13}):xa[m]}),e.jsx("span",{className:"flat-terminal-wrapper__view-mode-label",children:ae?"Classic TUI":ga[m]}),e.jsx(d,{name:"caret-down",size:9})]})}),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:te,disabled:!L,title:"Back to previous agent","aria-label":"Back to previous agent",children:e.jsx(d,{name:"arrow-left",size:14})}),e.jsx("button",{type:"button",className:"flat-terminal-wrapper__action-btn",onClick:ue,disabled:!_e,title:"Forward to next agent","aria-label":"Forward to next agent",children:e.jsx(d,{name:"arrow-right",size:14})}),e.jsx("button",{type:"button",className:`flat-terminal-wrapper__action-btn ${Ne?"flat-terminal-wrapper__action-btn--active":""}`,onClick:ye,title:Ne?"Close search":"Search messages","aria-pressed":Ne,children:e.jsx(d,{name:Ne?"cross":"search",size:14})}),e.jsx("button",{type:"button",className:`flat-terminal-wrapper__action-btn flat-terminal-wrapper__action-btn--danger ${ie?"flat-terminal-wrapper__action-btn--confirm":""}`,onClick:()=>mt.handleClick(Qt,()=>{var a;g.clearContext(o),(a=ve.current)==null||a.historyLoader.clearHistory()}),title:ie?"Click again to confirm clear context":"Clear context",children:e.jsx(d,{name:ie?"question":"clear",size:14})}),e.jsx("button",{type:"button",className:`flat-terminal-wrapper__action-btn ${re?"flat-terminal-wrapper__action-btn--active":""}`,onClick:it,title:re?"Hide git panel":"Show git changes","aria-pressed":re,children:e.jsx(d,{name:"git-branch",size:14})}),e.jsx("button",{type:"button",className:`flat-terminal-wrapper__action-btn ${Oe?"flat-terminal-wrapper__action-btn--active":""}`,onClick:Se,title:Oe?"Hide buildings panel":"Show area buildings","aria-pressed":Oe,children:e.jsx(d,{name:"buildings",size:14})}),e.jsxs("div",{className:"flat-terminal-wrapper__more",ref:ht,children:[e.jsx("button",{type:"button",className:`flat-terminal-wrapper__action-btn ${Ee?"flat-terminal-wrapper__action-btn--active":""}`,onClick:()=>Ie(a=>!a),title:"More actions","aria-expanded":Ee,children:"⋮"}),Ee&&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 ${Fe?"flat-terminal-wrapper__more-item--active":""}`,onClick:()=>{st(),Ie(!1)},title:Fe?"Hide Debug Panel":"Show Debug Panel",children:[e.jsx(d,{name:"bug",size:14}),e.jsx("span",{children:Fe?"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:()=>{g.collapseContext(o),Ie(!1)},disabled:p.status!=="idle",title:p.status!=="idle"?"Agent must be idle to collapse context":"Collapse context",children:[e.jsx(d,{name:"package",size:14}),e.jsx("span",{children:"Collapse context"})]}),Et&&e.jsxs("button",{type:"button",role:"menuitem",className:"flat-terminal-wrapper__more-item flat-terminal-wrapper__more-item--danger",onClick:()=>{R(o,Te),Ie(!1)},children:[e.jsx(d,{name:"crown",size:14}),e.jsxs("span",{children:["Clear ",Te," subordinate",Te===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:()=>{g.killAgent(o),Ie(!1)},children:[e.jsx(d,{name:"cross",size:14}),e.jsx("span",{children:"Remove agent"})]})]})]})]}),e.jsxs("button",{type:"button",className:`flat-terminal-wrapper__inspector-toggle ${y?"flat-terminal-wrapper__inspector-toggle--active":""}`,onClick:M,title:y?"Hide inspector panel":"Show inspector panel","aria-label":y?"Hide inspector panel":"Show inspector panel","aria-pressed":y,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:()=>g.deselectAll(),title:"Close chat","aria-label":"Close chat",children:e.jsx(d,{name:"cross",size:14})})]})]}),Ge&&e.jsxs("div",{className:"flat-chat-actions-sheet-root",role:"presentation",children:[e.jsx("div",{className:"flat-chat-actions-sheet__backdrop",onClick:D}),e.jsxs("div",{className:"flat-chat-actions-sheet",role:"menu","aria-label":"Chat actions",children:[e.jsx("div",{className:"flat-chat-actions-sheet__grabber","aria-hidden":"true"}),e.jsxs("div",{className:"flat-chat-actions-sheet__title-row",children:[e.jsx("span",{className:"flat-chat-actions-sheet__title",children:p.name}),e.jsx("button",{type:"button",className:"flat-chat-actions-sheet__done",onClick:D,children:"Done"})]}),e.jsxs("div",{className:"flat-chat-actions-sheet__grid",children:[e.jsxs("button",{type:"button",role:"menuitem",className:`flat-chat-actions-sheet__item ${Ne?"is-active":""}`,onClick:()=>{ye(),D()},children:[e.jsx(d,{name:Ne?"cross":"search",size:20}),e.jsx("span",{children:Ne?"Close search":"Search"})]}),e.jsxs("button",{type:"button",role:"menuitem",className:`flat-chat-actions-sheet__item ${re?"is-active":""}`,onClick:()=>{it(),D()},children:[e.jsx(d,{name:"git-branch",size:20}),e.jsx("span",{children:"Git changes"})]}),e.jsxs("button",{type:"button",role:"menuitem",className:`flat-chat-actions-sheet__item ${Oe?"is-active":""}`,onClick:()=>{Se(),D()},children:[e.jsx(d,{name:"buildings",size:20}),e.jsx("span",{children:"Buildings"})]}),e.jsxs("button",{type:"button",role:"menuitem",className:`flat-chat-actions-sheet__item ${Fe?"is-active":""}`,onClick:()=>{st(),D()},children:[e.jsx(d,{name:"bug",size:20}),e.jsx("span",{children:"Debug"})]})]}),e.jsxs("div",{className:"flat-chat-actions-sheet__list",children:[e.jsxs("button",{type:"button",role:"menuitem",className:`flat-chat-actions-sheet__row flat-chat-actions-sheet__row--danger ${ie?"is-armed":""}`,onClick:()=>mt.handleClick(Qt,()=>{var a;g.clearContext(o),(a=ve.current)==null||a.historyLoader.clearHistory(),D()}),children:[e.jsx(d,{name:ie?"question":"clear",size:18}),e.jsx("span",{children:ie?"Tap again to confirm clear":"Clear context"})]}),e.jsxs("button",{type:"button",role:"menuitem",className:"flat-chat-actions-sheet__row",disabled:p.status!=="idle",onClick:()=>{g.collapseContext(o),D()},children:[e.jsx(d,{name:"package",size:18}),e.jsx("span",{children:"Collapse context"})]}),Et&&e.jsxs("button",{type:"button",role:"menuitem",className:"flat-chat-actions-sheet__row flat-chat-actions-sheet__row--danger",onClick:()=>{R(o,Te),D()},children:[e.jsx(d,{name:"crown",size:18}),e.jsxs("span",{children:["Clear ",Te," subordinate",Te===1?"":"s"]})]}),e.jsxs("button",{type:"button",role:"menuitem",className:"flat-chat-actions-sheet__row flat-chat-actions-sheet__row--danger",onClick:()=>{g.killAgent(o),D()},children:[e.jsx(d,{name:"cross",size:18}),e.jsx("span",{children:"Remove agent"})]})]})]})]}),e.jsx(vn,{agent:p,onClick:A}),ae&&je?e.jsx(Fn,{agentId:o}):Je&&Qe?e.jsx(jn,{ref:ve,agentId:Je,agent:Qe,viewMode:m,isOpen:!0,onImageClick:k,onFileClick:K,onBashClick:j,onViewMarkdown:v,keyboard:be,hasModalOpen:!1},Je):null,_&&(F||Yt(_.buildingId))&&(()=>{var Le,ot;const a=_.type,l=Yt(_.buildingId),i=(F==null?void 0:F.name)??`Terminal — ${((Le=Q.find(z=>z.id===_.buildingId))==null?void 0:Le.name)??"area"}`,u=l?Ce[ma(_.buildingId)]:(ot=F==null?void 0:F.terminalStatus)==null?void 0:ot.url,$={terminal:"terminal","pm2-logs":"scroll",database:"hard-drives",tests:"flask",http:"globe"},V=a==="terminal"&&!u,S=!V&&!l;return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"guake-bottom-terminal-resize",onMouseDown:Ft,role:"separator","aria-orientation":"horizontal","aria-label":"Resize embedded panel"}),e.jsxs("div",{className:"flat-bottom-panel",role:"region","aria-label":`${i} panel`,style:{height:Ot},children:[e.jsxs("div",{className:"flat-bottom-panel__header",children:[e.jsxs("span",{className:"flat-bottom-panel__title",children:[e.jsx(d,{name:$[a],size:12}),e.jsx("span",{children:i}),V&&e.jsx("span",{className:"flat-bottom-panel__muted",children:"(starting...)"})]}),e.jsxs("span",{className:"flat-bottom-panel__header-actions",children:[a==="pm2-logs"&&F&&e.jsxs(e.Fragment,{children:[e.jsx("input",{type:"text",className:"guake-bottom-terminal-filter",value:Nt,onChange:z=>ze(z.target.value),placeholder:"Filter logs","aria-label":`Filter logs for ${F.name}`,spellCheck:!1}),e.jsx("select",{className:"guake-bottom-terminal-retention",value:pt===null?"unlimited":String(pt),onChange:z=>{const U=z.target.value==="unlimited"?null:Number(z.target.value);Rt(U),kn(U)},"aria-label":`Max log retention for ${F.name}`,children:Cn.map(z=>e.jsx("option",{value:z===null?"unlimited":String(z),children:z===null?"Unlimited":`${z.toLocaleString()} lines`},z===null?"unlimited":z))}),e.jsx("button",{type:"button",className:"flat-bottom-panel__close",onClick:()=>g.clearStreamingLogs(_.buildingId),title:"Clear logs",children:e.jsx(d,{name:"trash",size:12})}),e.jsx("button",{type:"button",className:"flat-bottom-panel__close",onClick:()=>g.sendBuildingCommand(_.buildingId,"restart"),title:"Restart",children:e.jsx(d,{name:"restart",size:12})})]}),S&&e.jsx("button",{type:"button",className:"flat-bottom-panel__close",onClick:()=>{ee(),ct(_.buildingId)},title:"Maximize — open as modal","aria-label":"Open as modal",children:e.jsx(d,{name:"fullscreen",size:12})}),e.jsx("button",{type:"button",className:"flat-bottom-panel__close",onClick:ee,title:"Close panel","aria-label":"Close panel",children:e.jsx(d,{name:"cross",size:12})})]})]}),e.jsx("div",{className:"flat-bottom-panel__body",children:a==="terminal"?u?e.jsx(wa,{terminalUrl:u,visible:!0}):e.jsx("div",{className:"flat-bottom-panel__placeholder",children:fe??"Starting terminal..."}):a==="pm2-logs"?e.jsx(Nn,{buildingId:_.buildingId,filterText:Nt,maxRetention:pt}):F?a==="database"?e.jsx(yn,{building:F}):a==="tests"?e.jsx("div",{className:"tests-panel-host",children:e.jsx(An,{building:F,autoFocusSearch:!1})}):e.jsx("div",{className:"http-requests-panel-host",children:e.jsx(Sn,{building:F,autoFocusSearch:!1})}):null})]})]})})(),e.jsxs("div",{className:"flat-terminal-wrapper__statusbar",role:"contentinfo",children:[p.isDetached&&e.jsxs("span",{className:"flat-terminal-wrapper__detached",title:"Reattaching session...",children:[e.jsx(d,{name:"refresh",size:12}),e.jsx("span",{children:"Reattaching"})]}),Me&&rt&&e.jsxs("span",{className:"flat-terminal-wrapper__cwd",title:`Open in file explorer: ${Me}`,"aria-label":`Open ${Me} in file explorer`,role:"button",tabIndex:0,onClick:()=>g.openFileExplorer(Me),onKeyDown:a=>{(a.key==="Enter"||a.key===" ")&&(a.preventDefault(),g.openFileExplorer(Me))},children:[e.jsx("span",{className:"flat-terminal-wrapper__cwd-icon",children:e.jsx(d,{name:"folder",size:12})}),e.jsx("span",{className:"flat-terminal-wrapper__cwd-text",children:rt})]}),ut&&ut.map(({areaId:a,areaName:l,dir:i})=>{const u=Ct.get(i),$=De.has(i),V=i.split("/").filter(Boolean).pop()||i;return e.jsxs("span",{className:"flat-terminal-wrapper__area-dir",title:`${l}: ${i}${u?` (${u.branch}${u.ahead?` ↑${u.ahead}`:""}${u.behind?` ↓${u.behind}`:""})`:""}`,onClick:()=>g.openFileExplorerForAreaFolder(a,i),children:[e.jsx(d,{name:"folder-open",size:12}),e.jsx("span",{className:"flat-terminal-wrapper__area-dir-name",children:V}),u&&e.jsxs(e.Fragment,{children:[e.jsxs("span",{className:"flat-terminal-wrapper__area-dir-branch",children:[e.jsx(d,{name:"git-branch",size:10})," ",u.branch]}),u.ahead>0&&e.jsxs("span",{className:"flat-terminal-wrapper__branch-ahead",title:`${u.ahead} ahead`,children:[e.jsx(d,{name:"arrow-up",size:9}),u.ahead]}),u.behind>0&&e.jsxs("span",{className:"flat-terminal-wrapper__branch-behind",title:`${u.behind} behind`,children:[e.jsx(d,{name:"arrow-down",size:9}),u.behind]}),e.jsx("span",{className:`flat-terminal-wrapper__area-fetch ${$?"flat-terminal-wrapper__area-fetch--fetching":""}`,title:"Git fetch",onClick:S=>{S.stopPropagation(),Xe(i)},children:e.jsx(d,{name:$?"hourglass":"download",size:12})})]})]},`${a}:${i}`)}),e.jsx(Un,{agentId:o,disabled:((p==null?void 0:p.provider)??"claude")!=="claude"&&((p==null?void 0:p.provider)??"claude")!=="grok",contextSummary:gt?`Context: ${He}k / ${lt}k tokens (${xt}% used)`:void 0,children:e.jsxs("span",{className:"flat-terminal-wrapper__context",tabIndex:0,role:"button",onClick:()=>g.setContextModalAgentId(o),onKeyDown:a=>{(a.key==="Enter"||a.key===" ")&&(a.preventDefault(),g.setContextModalAgentId(o))},title:((p==null?void 0:p.provider)??"claude")!=="claude"&&((p==null?void 0:p.provider)??"claude")!=="grok"?gt?`Context usage: ${He}k / ${lt}k tokens (${xt}% used). Click to view stats.`:"Click to fetch context stats":void 0,children:[e.jsx("span",{className:"flat-terminal-wrapper__context-bar",children:e.jsx("span",{className:"flat-terminal-wrapper__context-bar-fill",style:{width:`${ce}%`,backgroundColor:bt}})}),e.jsxs("span",{className:"flat-terminal-wrapper__context-tokens",style:{color:bt},children:[He,"k/",lt,"k"]}),e.jsxs("span",{className:"flat-terminal-wrapper__context-free",children:["(",Ht,"% free)"]}),!gt&&e.jsx("span",{className:"flat-terminal-wrapper__context-warning",title:"No context stats yet",children:e.jsx(d,{name:"warn",size:12})})]})}),e.jsx("div",{className:"flat-terminal-wrapper__statusbar-spacer","aria-hidden":"true"}),Q.length>0&&e.jsx("span",{className:"flat-terminal-wrapper__buildings",role:"group","aria-label":"Area terminals",children:Q.map(a=>{const l=(_==null?void 0:_.buildingId)===a.id;return a.isDefault?e.jsx("button",{type:"button",className:`flat-terminal-wrapper__building-btn flat-terminal-wrapper__building-btn--default ${l?"flat-terminal-wrapper__building-btn--active":""}`,title:`${l?"Hide":"Show"} area terminal: ${a.name}`,onClick:()=>{l?ee():Re("terminal",a.id)},children:e.jsx(d,{name:"terminal",size:14})},a.id):e.jsx("button",{type:"button",className:`flat-terminal-wrapper__building-btn ${l?"flat-terminal-wrapper__building-btn--active":""} ${a.hasUrl?"":"flat-terminal-wrapper__building-btn--offline"}`,title:`${l?"Hide":"Show"} terminal: ${a.name}${a.hasUrl?"":" (starting...)"}`,onClick:()=>{if(l){ee();return}if(a.hasUrl&&wt(a.id)==="modal"){ct(a.id);return}a.hasUrl||g.sendBuildingCommand(a.id,"start"),Re("terminal",a.id)},onContextMenu:i=>{i.preventDefault(),i.stopPropagation(),$e(a.id,{x:i.clientX,y:i.clientY})},children:e.jsx(d,{name:"terminal",size:14})},a.id)})}),se.length>0&&e.jsx("span",{className:"flat-terminal-wrapper__buildings",role:"group","aria-label":"Area PM2 logs",children:se.map(a=>{const l=(_==null?void 0:_.buildingId)===a.id;return e.jsx("button",{type:"button",className:`flat-terminal-wrapper__building-btn ${l?"flat-terminal-wrapper__building-btn--active":""}`,title:`${l?"Hide":"Show"} logs: ${a.name}`,onClick:()=>{l?ee():wt(a.id)==="modal"?ct(a.id):Re("pm2-logs",a.id)},onContextMenu:i=>{i.preventDefault(),i.stopPropagation(),$e(a.id,{x:i.clientX,y:i.clientY})},children:e.jsx(d,{name:"scroll",size:14})},a.id)})}),nt.length>0&&e.jsx("span",{className:"flat-terminal-wrapper__buildings",role:"group","aria-label":"Area databases",children:nt.map(a=>{const l=(_==null?void 0:_.buildingId)===a.id;return e.jsx("button",{type:"button",className:`flat-terminal-wrapper__building-btn ${l?"flat-terminal-wrapper__building-btn--active":""}`,title:`${l?"Hide":"Show"} database: ${a.name}`,onClick:()=>{l?ee():wt(a.id)==="modal"?ct(a.id):Re("database",a.id)},onContextMenu:i=>{i.preventDefault(),i.stopPropagation(),$e(a.id,{x:i.clientX,y:i.clientY})},children:e.jsx(d,{name:"hard-drives",size:14})},a.id)})}),qe.length>0&&e.jsx("span",{className:"flat-terminal-wrapper__buildings",role:"group","aria-label":"Area tests",children:qe.map(a=>{const l=(_==null?void 0:_.buildingId)===a.id;return e.jsx("button",{type:"button",className:`flat-terminal-wrapper__building-btn ${l?"flat-terminal-wrapper__building-btn--active":""} ${a.working?"flat-terminal-wrapper__building-btn--tests-working":""}`,title:a.working?`Running tests: ${a.name}`:`${l?"Hide":"Show"} tests: ${a.name}`,onClick:()=>{l?ee():wt(a.id)==="modal"?ct(a.id):Re("tests",a.id)},onContextMenu:i=>{i.preventDefault(),i.stopPropagation(),$e(a.id,{x:i.clientX,y:i.clientY})},children:e.jsx(d,{name:"flask",size:14})},a.id)})}),ke.length>0&&e.jsx("span",{className:"flat-terminal-wrapper__buildings",role:"group","aria-label":"Area HTTP requests",children:ke.map(a=>{const l=(_==null?void 0:_.buildingId)===a.id;return e.jsx("button",{type:"button",className:`flat-terminal-wrapper__building-btn ${l?"flat-terminal-wrapper__building-btn--active":""}`,title:`${l?"Hide":"Show"} HTTP requests: ${a.name}`,onClick:()=>{l?ee():wt(a.id)==="modal"?ct(a.id):Re("http",a.id)},onContextMenu:i=>{i.preventDefault(),i.stopPropagation(),$e(a.id,{x:i.clientX,y:i.clientY})},children:e.jsx(d,{name:"globe",size:14})},a.id)})}),e.jsx("div",{className:"flat-terminal-wrapper__theme",children:e.jsx(En,{iconOnly:!0})})]}),re&&e.jsx(In,{agentId:o,agents:Be,onClose:Bt,branchInfoMap:Ct,fetchRemote:Xe,fetchingDirs:De,onResizeStart:a=>le(a,"right")}),Oe&&e.jsx(Mn,{agentId:o,onClose:oe}),Fe&&e.jsx(Tn,{agentId:o,onClose:Ye}),e.jsx(na,{isOpen:tt!==null,position:tt??{x:0,y:0},worldPosition:{x:0,z:0},actions:Dt,onClose:()=>Ue(null)})]})}),Jn={groups:[],gridCols:1,gridRows:1,positions:new Map};function ns({onAgentClick:c,onBuildingClick:o,onBuildingDoubleClick:m,onBuildingPopup:b,onAreaContextMenu:y,onOpenSpawnModal:M,onOpenBossSpawnModal:A,onOpenAreaModal:k}){const{t:K}=sa(["common"]),j=Wa(),v=n.useMemo(()=>j.size>0?j.values().next().value??null:null,[j]),R=Ha(v===null),be=Ua(),[L,_e]=n.useState(null),[te,ue]=n.useState(null),[Ze,jt]=n.useState(null);va("flatview-image-modal",L!==null,()=>_e(null));const[dt,$e]=n.useState(null),[p,O]=n.useState(null),[we,ve]=n.useState(null),[me,Je]=n.useState(null),[Qe,je]=n.useState(!1),ae=n.useCallback(()=>{je(t=>!t)},[]),et=n.useCallback(()=>{je(!1)},[]),[tt,Ue]=n.useState(()=>{const t=Vt(E.VIEW_MODE);return t==="simple"||t==="chat"||t==="advanced"?t:"simple"}),Dt=n.useCallback(t=>{Ue(t),qt(E.VIEW_MODE,t)},[]);n.useEffect(()=>{const t=s=>{if(s.key!==E.VIEW_MODE)return;const r=s.newValue;(r==="simple"||r==="chat"||r==="advanced")&&Ue(r)};return window.addEventListener("storage",t),()=>window.removeEventListener("storage",t)},[]);const[Ge,pe]=n.useState(()=>ta(E.FLAT_INSPECTOR_OPEN,!1)),[D,ne]=n.useState(!1),ut=n.useCallback(()=>ne(t=>!t),[]),Ct=n.useCallback(()=>ne(!1),[]);n.useEffect(()=>{window.dispatchEvent(new CustomEvent("tide-flat-agents-drawer-state",{detail:{open:D}}))},[D]),n.useEffect(()=>{window.dispatchEvent(new CustomEvent("tide-flat-inspector-state",{detail:{open:Ge}}))},[Ge]),n.useEffect(()=>{const t=()=>ne(N=>!N),s=()=>{pe(N=>{const T=!N;return xe(E.FLAT_INSPECTOR_OPEN,T),T})},r=()=>{ne(!1),pe(!1),xe(E.FLAT_INSPECTOR_OPEN,!1)},x=()=>ne(!1),w=()=>{pe(!1),xe(E.FLAT_INSPECTOR_OPEN,!1)};return window.addEventListener("tide-toggle-flat-agents-drawer",t),window.addEventListener("tide-toggle-flat-inspector",s),window.addEventListener("tide-close-flat-side-views",r),window.addEventListener("tide-close-flat-agents-drawer-only",x),window.addEventListener("tide-close-flat-inspector-only",w),()=>{window.removeEventListener("tide-toggle-flat-agents-drawer",t),window.removeEventListener("tide-toggle-flat-inspector",s),window.removeEventListener("tide-close-flat-side-views",r),window.removeEventListener("tide-close-flat-agents-drawer-only",x),window.removeEventListener("tide-close-flat-inspector-only",w)}},[]);const Xe=n.useRef(null),De=n.useRef(null),[Ce,at]=n.useState(()=>{const t=ca(E.FLAT_MIDDLE_WIDTH,0);return t>=$t?t:null}),[fe,Ve]=n.useState(()=>{const t=ca(E.FLAT_INSPECTOR_WIDTH,0);return t>=Jt?t:null}),Q=n.useCallback(t=>{if(typeof window>"u")return t;const s=fe!==null?Pt+fe:0,r=window.innerWidth-ha-Pt-fa-s;return Math.max($t,Math.min(Math.max(r,$t),t))},[fe]),se=n.useCallback(t=>{var w;if(typeof window>"u")return t;const s=(w=Xe.current)==null?void 0:w.querySelector(".flat-middle"),r=(s==null?void 0:s.getBoundingClientRect().width)??$t,x=window.innerWidth-ha-r-Pt-fa-Pt;return Math.max(Jt,Math.min(Math.max(x,Jt),t))},[]);n.useEffect(()=>{if(Ce===null&&fe===null)return;const t=()=>{at(s=>{if(s===null)return s;const r=Q(s);return r===s?s:r}),Ve(s=>{if(s===null)return s;const r=se(s);return r===s?s:r})};return window.addEventListener("resize",t),()=>window.removeEventListener("resize",t)},[Ce,fe,Q,se]);const nt=n.useCallback(t=>{var r;if(t.button!==0)return;const s=(r=Xe.current)==null?void 0:r.querySelector(".flat-middle");s&&(t.currentTarget.setPointerCapture(t.pointerId),De.current={kind:"middle",startX:t.clientX,startWidth:s.getBoundingClientRect().width,pointerId:t.pointerId},document.body.classList.add("flat-splitter-dragging"))},[]),kt=n.useCallback(t=>{var r;if(t.button!==0)return;const s=(r=Xe.current)==null?void 0:r.querySelector(".flat-inspector");s&&(t.currentTarget.setPointerCapture(t.pointerId),De.current={kind:"inspector",startX:t.clientX,startWidth:s.getBoundingClientRect().width,pointerId:t.pointerId},document.body.classList.add("flat-splitter-dragging"))},[]),qe=n.useCallback(t=>{const s=De.current;if(!s||t.pointerId!==s.pointerId)return;const r=t.clientX-s.startX;s.kind==="middle"?at(Q(s.startWidth+r)):Ve(se(s.startWidth-r))},[Q,se]),ke=n.useCallback(t=>{const s=De.current;if(!s||t.pointerId!==s.pointerId)return;try{t.currentTarget.releasePointerCapture(t.pointerId)}catch{}if(De.current=null,document.body.classList.remove("flat-splitter-dragging"),!(Math.abs(t.clientX-s.startX)>2))return;const x=t.clientX-s.startX;if(s.kind==="middle"){const w=Q(s.startWidth+x);at(w),Lt(E.FLAT_MIDDLE_WIDTH,w)}else{const w=se(s.startWidth-x);Ve(w),Lt(E.FLAT_INSPECTOR_WIDTH,w)}},[Q,se]),zt=n.useCallback(()=>{at(null),Lt(E.FLAT_MIDDLE_WIDTH,0)},[]),Ne=n.useCallback(()=>{Ve(null),Lt(E.FLAT_INSPECTOR_WIDTH,0)},[]),[ye,mt]=n.useState(()=>Vt(E.FLAT_INSPECTOR_VIEW)==="tracking"?"tracking":"agent"),ie=n.useCallback(t=>{mt(t),qt(E.FLAT_INSPECTOR_VIEW,t)},[]),_=n.useCallback(()=>{pe(t=>{const s=!t;return xe(E.FLAT_INSPECTOR_OPEN,s),s})},[]),he=n.useCallback(()=>{pe(!1),xe(E.FLAT_INSPECTOR_OPEN,!1)},[]),F=n.useCallback(()=>{ie("tracking"),pe(!0),xe(E.FLAT_INSPECTOR_OPEN,!0)},[ie]),Nt=Ga(),ze=n.useCallback((t,s)=>{_e({url:t,name:s})},[]),pt=n.useCallback((t,s)=>{ue({command:t,output:s,isLive:!1})},[]),Rt=n.useCallback((t,s)=>{var w;const r=j.size>0?Array.from(j)[0]:null,x=r?(w=g.getState().agents.get(r))==null?void 0:w.cwd:void 0;g.setFileViewerPath(t,s,x)},[j]),B=n.useCallback(t=>{jt(t)},[]),Re=n.useCallback((t,s)=>{$e({agentId:t,count:s})},[]),ee=n.useCallback(t=>{m?m(t):o(t)},[o,m]),Ot=n.useCallback(t=>{v&&O({agentId:v,position:t})},[v]),Ft=n.useCallback((t,s)=>{ve({buildingId:t,position:s})},[]);n.useEffect(()=>{je(!1)},[v]);const Ae=n.useRef([]),le=n.useRef(-1),re=n.useRef(!1),ft=n.useRef(Vt(E.LAST_OPENED_AGENT,"")||null),[Oe,yt]=n.useState(!1),[Fe,At]=n.useState(!1),st=n.useRef(!1),Ye=n.useRef(null),it=n.useRef(!1),Se=n.useMemo(()=>new Set(be),[be]),Bt=n.useMemo(()=>{const t=new Map(R.map(r=>[r.id,r])),s=new Map;for(const r of R)if((r.isBoss||r.class==="boss")&&r.subordinateIds&&r.subordinateIds.length>0){const x=r.subordinateIds.map(w=>t.get(w)).filter(w=>w!==void 0);x.length>0&&s.set(r.id,x)}return s},[R]),oe=n.useCallback(()=>{const t=Ae.current,s=le.current;yt(s>0),At(s>=0&&s<t.length-1)},[]),Be=n.useCallback(t=>{const s=Ae.current;if(s.length===0)return;let r=le.current+t;for(;r>=0&&r<s.length;){const x=s[r];if(Se.has(x)){re.current=!0,le.current=r,oe(),g.selectAgent(x);return}r+=t}},[Se,oe]),We=n.useCallback(()=>Be(-1),[Be]),St=n.useCallback(()=>Be(1),[Be]);zn(n.useCallback(()=>{const t=Ae.current,s=le.current;return t.length>0&&s>0?(Be(-1),"handled"):"exit"},[Be]));const Ee=n.useCallback((t,s)=>{if(typeof window>"u")return;const r=window.history.state,w={...typeof r=="object"&&r!==null?r:{},__flatAgentNav:{agentId:t}};s==="replace"?window.history.replaceState(w,"",window.location.href):window.history.pushState(w,"",window.location.href)},[]);n.useEffect(()=>{if(!v){st.current=!1,Ye.current=null;return}if(!st.current){Ee(v,"replace"),st.current=!0,Ye.current=v;return}if(it.current){it.current=!1,Ye.current=v;return}Ye.current!==v&&(Ee(v,"push"),Ye.current=v)},[v,Ee]),n.useEffect(()=>{const t=s=>{var N,T;const r=(T=(N=s.state)==null?void 0:N.__flatAgentNav)==null?void 0:T.agentId;if(!r||typeof r!="string"||!Se.has(r)||r===v)return;it.current=!0,re.current=!0;const x=Ae.current,w=x.lastIndexOf(r);w>=0?le.current=w:(x.push(r),le.current=x.length-1),oe(),g.selectAgent(r)};return window.addEventListener("popstate",t),()=>window.removeEventListener("popstate",t)},[Se,v,oe]),n.useEffect(()=>{if(!v){Ae.current=[],le.current=-1,oe();return}if(ft.current=v,qt(E.LAST_OPENED_AGENT,v),re.current){re.current=!1,oe();return}const t=Ae.current,s=le.current;if(s>=0&&t[s]===v){oe();return}const r=s<t.length-1?t.slice(0,s+1):t.slice();r.push(v),r.length>100&&r.shift(),Ae.current=r,le.current=r.length-1,oe()},[v,oe]);const Ie=n.useCallback(t=>{c(t),ne(!1)},[c]),ht=v??"",gt=n.useCallback(()=>{},[]),Wt=n.useCallback(t=>{Ie(t)},[Ie]),ge=Ge,[ce,xt]=n.useState(ge),[Ht,bt]=n.useState(ge),He=ja(Qe||Ze!==null||ce&&ye==="agent"?v:null);n.useEffect(()=>{if(ge){xt(!0);return}bt(!1);const t=setTimeout(()=>xt(!1),240);return()=>clearTimeout(t)},[ge]),n.useEffect(()=>{if(!ce||!ge)return;let t=0;const s=requestAnimationFrame(()=>{t=requestAnimationFrame(()=>bt(!0))});return()=>{cancelAnimationFrame(s),cancelAnimationFrame(t)}},[ce,ge]);const lt=n.useRef(null);n.useEffect(()=>{if(v)return;const t=s=>{if(s.key!==" "&&s.key!=="Backspace")return;const r=s.target;if(r.tagName==="INPUT"||r.tagName==="TEXTAREA"||r.isContentEditable)return;const x=ft.current;!x||!Se.has(x)||(s.preventDefault(),g.selectAgent(x))};return document.addEventListener("keydown",t),()=>document.removeEventListener("keydown",t)},[v,Se]);const[Me,rt]=n.useState(new Set),Te=n.useCallback(t=>{rt(s=>{const r=new Set(s);return r.has(t)?r.delete(t):r.add(t),r})},[]),Et=n.useCallback(t=>{rt(new Set(t))},[]),[Z,It]=n.useState(()=>typeof window<"u"&&window.matchMedia("(max-width: 768px)").matches);n.useEffect(()=>{if(typeof window>"u")return;const t=window.matchMedia("(max-width: 768px)"),s=r=>It(r.matches);return t.addEventListener("change",s),()=>t.removeEventListener("change",s)},[]);const[a,l]=n.useState(null),i=n.useCallback(t=>{l(s=>s===t?null:t)},[]),u=Ca(),$=ka(),[V]=Xa(),S=n.useMemo(()=>{if(v)return Jn;const t=new Map,s=[];for(const h of R){const C=g.getAreaForAgent(h.id);if(!da((C==null?void 0:C.id)??null))continue;if(!C||C.archived){s.push(h);continue}const P=t.get(C.id);P?P.push(h):t.set(C.id,[h])}const r=new Map,x=[];for(const h of $.values()){let C=!1;for(const P of u.values())if(!P.archived&&ua(P.id)&&g.isPositionInArea(h.position,P)){const de=r.get(P.id);de?de.push(h):r.set(P.id,[h]),C=!0;break}!C&&da(null)&&x.push(h)}const w=[];for(const[,h]of u){if(h.archived||!ua(h.id))continue;const C=t.get(h.id),P=r.get(h.id)??[];(C&&C.length>0||P.length>0)&&w.push({area:h,agents:C??[],buildings:P})}(s.length>0||x.length>0)&&w.push({area:{id:"__unassigned__",name:"Unassigned",color:"#6272a4",center:{x:0,z:0},type:"circle",radius:0,directories:[],archived:!1,assignedAgentIds:[],zIndex:0},agents:s,buildings:x});const N=w.filter(h=>h.area.id!=="__unassigned__"),T=w.filter(h=>h.area.id==="__unassigned__");let G=1,W=1;const f=new Map;if(N.length>1){let h=1/0,C=-1/0,P=1/0,de=-1/0;for(const q of N)h=Math.min(h,q.area.center.x),C=Math.max(C,q.area.center.x),P=Math.min(P,q.area.center.z),de=Math.max(de,q.area.center.z);const Pe=C-h||1,Mt=de-P||1;if(N.length<=4){G=N.length,W=1;const q=[...N].sort((Y,Ut)=>Y.area.center.x-Ut.area.center.x);for(let Y=0;Y<q.length;Y++)f.set(q[Y].area.id,{row:1,col:Y+1})}else{const q=[...N].sort((I,H)=>I.area.center.x-H.area.center.x),Y=[];for(let I=1;I<q.length;I++)Y.push(q[I].area.center.x-q[I-1].area.center.x);const Ut=Y.reduce((I,H)=>I+H,0)/Y.length||1;let ia=1;for(const I of Y)I>Ut*1.3&&ia++;G=Math.max(2,Math.min(ia,N.length));const Gt=[...N].sort((I,H)=>I.area.center.z-H.area.center.z),Tt=[];for(let I=1;I<Gt.length;I++)Tt.push(Gt[I].area.center.z-Gt[I-1].area.center.z);const Ma=Tt.reduce((I,H)=>I+H,0)/Tt.length||1;let la=1;for(const I of Tt)I>Ma*1.3&&la++;W=Math.max(2,Math.min(la,N.length)),G=Math.max(G,Math.ceil(N.length/W)),W=Math.max(W,Math.ceil(N.length/G));const Ta=Pe/G,La=Mt/W,Xt=new Set;for(const I of N){let H=Math.min(G-1,Math.max(0,Math.floor((I.area.center.x-h)/Ta))),Ke=Math.min(W-1,Math.max(0,Math.floor((I.area.center.z-P)/La))),_t=`${Ke},${H}`,ra=0;const Pa=W*G;for(;Xt.has(_t)&&ra<Pa;)H++,H>=G&&(H=0,Ke=(Ke+1)%W),_t=`${Ke},${H}`,ra++;Xt.has(_t)&&(Ke=W,H=0,_t=`${Ke},${H}`,W++),Xt.add(_t),f.set(I.area.id,{row:Ke+1,col:H+1})}}}const J=h=>{h.sort((C,P)=>{var Pe,Mt,q,Y;const de=(((Pe=C.position)==null?void 0:Pe.z)??0)-(((Mt=P.position)==null?void 0:Mt.z)??0);return de!==0?de:(((q=C.position)==null?void 0:q.x)??0)-(((Y=P.position)==null?void 0:Y.x)??0)})};for(const h of N)J(h.agents);for(const h of T)J(h.agents);const X=[...N,...T].sort((h,C)=>h.area.name.localeCompare(C.area.name,void 0,{sensitivity:"base",numeric:!0})||h.area.id.localeCompare(C.area.id));return f.clear(),X.forEach((h,C)=>{f.set(h.area.id,{row:Math.floor(C/G)+1,col:C%G+1})}),W=Math.max(1,Math.ceil(X.length/G)),{groups:X,gridCols:G,gridRows:W,positions:f}},[R,u,$,V,v]),Le=n.useMemo(()=>{let t=0,s=0;for(const r of S.groups)t+=r.agents.length,s+=r.agents.filter(x=>x.status==="working").length;return{areaCount:S.groups.length,agentCount:t,workingCount:s}},[S]),ot=n.useMemo(()=>{if(!p)return[];const t=g.getState().agents.get(p.agentId);return t?[{id:"edit-agent",label:"Edit Agent",icon:e.jsx(d,{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(d,{name:"chat",size:14}),onClick:()=>c(t.id)},{id:"clone-agent",label:"Clone Agent",icon:e.jsx(d,{name:"clipboard",size:14}),onClick:()=>g.cloneAgent(t.id)},{id:"fork-agent",label:"Fork Agent (with history)",icon:e.jsx(d,{name:"git-branch",size:14}),onClick:()=>g.forkAgent(t.id)},{id:"delete-agent",label:"Delete Agent",icon:e.jsx(d,{name:"trash",size:14}),danger:!0,onClick:()=>{Je({agentId:t.id,name:t.name})}}]:[]},[p,c]),z=n.useMemo(()=>{var N;if(!we)return[];const t=$.get(we.buildingId);if(!t)return[];const s=[],r=t.type==="server"||t.type==="docker"||t.type==="terminal",x=t.status==="running",w=t.type==="boss";if(s.push({id:"open",label:t.type==="database"?"Open Database":t.type==="folder"?"Open Folder":t.type==="tests"?"Open Tests":t.type==="http"?"Open Requests":t.type==="boss"?"View Boss Logs":t.type==="terminal"?"Open Terminal":t.type==="server"&&((N=t.pm2)!=null&&N.enabled)?"View PM2 Logs":"Open",icon:e.jsx(d,{name:t.type==="database"?"database":t.type==="folder"?"folder":t.type==="tests"?"flask":t.type==="http"?"globe":t.type==="terminal"?"terminal":"eye",size:14}),onClick:()=>ee(t.id)}),r&&(x||s.push({id:"start",label:"Start",icon:e.jsx(d,{name:"play",size:14}),onClick:()=>g.sendBuildingCommand(t.id,"start")}),x&&(s.push({id:"restart",label:"Restart",icon:e.jsx(d,{name:"refresh",size:14}),onClick:()=>g.sendBuildingCommand(t.id,"restart")}),s.push({id:"stop",label:"Stop",icon:e.jsx(d,{name:"stop",size:14}),onClick:()=>g.sendBuildingCommand(t.id,"stop")}))),w&&t.subordinateBuildingIds&&t.subordinateBuildingIds.length>0&&(s.push({id:"start-all",label:"Start All Subordinates",icon:e.jsx(d,{name:"launch",size:14}),onClick:()=>{for(const T of t.subordinateBuildingIds)g.sendBuildingCommand(T,"start")}}),s.push({id:"stop-all",label:"Stop All Subordinates",icon:e.jsx(d,{name:"pause",size:14}),onClick:()=>{for(const T of t.subordinateBuildingIds)g.sendBuildingCommand(T,"stop")}}),s.push({id:"restart-all",label:"Restart All Subordinates",icon:e.jsx(d,{name:"restart",size:14}),onClick:()=>{for(const T of t.subordinateBuildingIds)g.sendBuildingCommand(T,"restart")}})),r&&s.push({id:"health-check",label:"Health Check",icon:e.jsx(d,{name:"health",size:14}),onClick:()=>g.sendBuildingCommand(t.id,"healthCheck")}),s.push({id:"divider-edit",label:"",divider:!0,onClick:()=>{}}),s.push({id:"edit",label:"Edit Building",icon:e.jsx(d,{name:"edit",size:14}),onClick:()=>{window.dispatchEvent(new CustomEvent("tide:building-edit",{detail:{buildingId:t.id}}))}}),s.push({id:"clone",label:"Clone Building",icon:e.jsx(d,{name:"copy",size:14}),onClick:()=>{g.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 T of t.urls)s.push({id:`url-${T.label}`,label:T.label,icon:e.jsx(d,{name:"link",size:14}),onClick:()=>window.open(T.url,"_blank","noopener,noreferrer")});return s.push({id:"divider-danger",label:"",divider:!0,onClick:()=>{}}),s.push({id:"delete",label:"Delete Building",icon:e.jsx(d,{name:"trash",size:14}),danger:!0,onClick:()=>g.deleteBuilding(t.id)}),s},[we,$,ee]),U=n.useCallback(t=>{rt(new Set([t])),requestAnimationFrame(()=>{const s=lt.current;if(!s)return;const r=s.querySelector(`[data-area-id="${t}"]`);if(!r)return;const x=s.getBoundingClientRect(),N=r.getBoundingClientRect().top-x.top+s.scrollTop-8;s.scrollTo({top:Math.max(0,N),behavior:"smooth"})})},[]);return e.jsxs("div",{ref:Xe,className:`flat-view ${ge?"flat-view--with-inspector":""} ${v?"flat-view--has-chat":""} ${D?"flat-view--mobile-sidebar-open":""}`,style:(()=>{if(Ce===null&&fe===null)return;const t={};return Ce!==null&&(t["--flat-middle-width"]=`${Ce}px`),fe!==null&&(t["--flat-inspector-width"]=`${fe}px`),t})(),children:[D&&e.jsx("div",{className:"flat-mobile-sidebar-backdrop",onClick:Ct,"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:M,title:"Create new agent",children:"+ Agent"}),e.jsx("button",{className:"flat-cta-btn flat-cta-btn--boss",onClick:A,title:"Create new boss agent",children:"+ Boss"}),e.jsx("button",{className:"flat-cta-btn flat-cta-btn--area",onClick:k,title:"Create new area",children:"+ Area"})]})}),e.jsx("div",{className:"flat-middle__content",children:e.jsx(Va,{activeAgentId:ht,onClose:gt,onSelectAgent:Wt,expandedAreas:Me,onToggleArea:Te,onSetExpandedAreas:Et,agentListRef:lt})})]}),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:nt,onPointerMove:qe,onPointerUp:ke,onPointerCancel:ke,onDoubleClick:zt}),e.jsxs("div",{className:"flat-right",children:[e.jsxs("button",{type:"button",className:"flat-mobile-sidebar-toggle","aria-label":D?"Close agents sidebar":"Open agents sidebar","aria-expanded":D,onClick:ut,children:[e.jsx(d,{name:"list",size:18}),e.jsx("span",{className:"flat-mobile-sidebar-toggle__label",children:"Agents"})]}),v?e.jsx(Zn,{agentId:v,terminalViewMode:tt,onTerminalViewModeChange:Dt,inspectorOpen:Ge,onToggleInspector:_,onShowTaskBoard:F,onImageClick:ze,onFileClick:Rt,onBashClick:pt,onViewMarkdown:B,onRequestClearSubordinates:Re,keyboard:Nt,canNavigateBack:Oe,canNavigateForward:Fe,onNavigateBack:We,onNavigateForward:St,agentInfoOpen:Qe,onToggleAgentInfo:ae,onHeaderContextMenu:Ot,onBuildingContextMenu:Ft}):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.jsxs("span",{className:"flat-map__stats",children:[e.jsxs("span",{children:[Le.areaCount," areas"]}),e.jsxs("span",{children:[Le.agentCount," agents"]}),Le.workingCount>0&&e.jsxs("span",{className:"flat-map__stats-working",children:[e.jsx("span",{className:"flat-map__stats-dot","aria-hidden":"true"}),Le.workingCount," working"]})]}),e.jsx(Gn,{className:"flat-map__view-mode"})]}),e.jsx("div",{className:"flat-map__grid",style:{gridTemplateColumns:Z?"repeat(2, minmax(0, 1fr))":`repeat(${S.gridCols}, 1fr)`},children:S.groups.length===0?e.jsx("div",{className:"flat-map__empty",children:e.jsx("span",{children:"No areas or agents yet"})}):(Z?[...S.groups].sort((s,r)=>{const x=S.positions.get(s.area.id),w=S.positions.get(r.area.id);return!x&&!w?0:x?w?x.row-w.row||x.col-w.col:-1:1}):S.groups).map(s=>{var W;const r=s.area.id,x=S.positions.get(r),w=s.agents.filter(f=>f.status==="working").length,N=w>0,T=Z&&a!==r,G=Z&&!T;return e.jsxs("div",{className:`flat-map-area-card${N?" flat-map-area-card--working":""}${T?" flat-map-area-card--collapsed":""}${G?" flat-map-area-card--expanded":""}`,style:{"--area-color":s.area.color,gridRow:Z||x==null?void 0:x.row,gridColumn:Z||x==null?void 0:x.col},onContextMenu:f=>{y&&(f.preventDefault(),f.stopPropagation(),y(r,{x:f.clientX,y:f.clientY}))},children:[e.jsxs("button",{type:"button",className:"flat-map-area-card__header",onClick:()=>Z?i(r):U(r),title:Z?T?`Expand ${s.area.name}`:`Collapse ${s.area.name}`:`Focus ${s.area.name} in left panel`,"aria-expanded":Z?!T:void 0,children:[e.jsx("span",{className:"flat-map-area-card__color",style:{background:s.area.color}}),((W=s.area.logo)==null?void 0:W.filename)&&e.jsx("img",{className:"flat-map-area-card__logo",src:Dn(s.area.logo.filename),alt:"","aria-hidden":"true",onError:f=>{f.currentTarget.style.display="none"}}),e.jsx("span",{className:"flat-map-area-card__name",children:s.area.name}),e.jsxs("span",{className:"flat-map-area-card__count",title:`${s.agents.length} agent${s.agents.length===1?"":"s"}`,"aria-label":`${s.agents.length} agent${s.agents.length===1?"":"s"}`,children:[e.jsx(d,{name:"users",size:10}),s.agents.length]}),N&&e.jsxs("span",{className:"flat-map-area-card__working",title:`${w} working agent${w===1?"":"s"}`,"aria-label":`${w} working agent${w===1?"":"s"}`,children:[e.jsx(aa,{animated:!0,size:12,className:"flat-map-area-card__working-glyph"}),e.jsx("span",{className:"flat-map-area-card__working-count",children:w})]}),Z&&e.jsx(d,{name:T?"caret-down":"caret-up",size:11,className:"flat-map-area-card__caret"})]}),e.jsx("div",{className:"flat-map-area-card__agents",children:s.agents.map(f=>{const J=f.isBoss||f.class==="boss",X=J?Bt.get(f.id):void 0,h=Na(f),C=h.usedPercent>=80?"#ff4a4a":h.usedPercent>=60?"#ff9e4a":h.usedPercent>=40?"#ffd700":"#4aff9e",P=`Context: ${(h.totalTokens/1e3).toFixed(1)}k / ${(h.contextWindow/1e3).toFixed(1)}k (${h.usedPercent}% used, ${h.freePercent}% free)`,de=f.latestTodos&&f.latestTodos.length>0||X&&X.length>0;return e.jsx(qa,{todos:f.latestTodos,subordinates:X,position:"top",children:e.jsxs("button",{type:"button",className:`flat-map-agent-chip ${f.status}`,onClick:()=>c(f.id),onContextMenu:Pe=>{Pe.preventDefault(),Pe.stopPropagation(),O({agentId:f.id,position:{x:Pe.clientX,y:Pe.clientY}})},title:de?void 0:`${J?"Boss · ":""}Open chat with ${f.name}
2
+ ${P}`,children:[e.jsx(ya,{agent:f,size:16}),J&&e.jsx("span",{className:"flat-map-agent-chip__crown","aria-hidden":"true",children:e.jsx(d,{name:"crown",size:11,color:"#ffd700",weight:"fill"})}),e.jsx("span",{className:"flat-map-agent-chip__name",children:f.name}),e.jsx(Aa,{agent:f,alt:`${f.name} provider`,className:"flat-map-agent-chip__provider-icon"}),f.status==="working"?e.jsx(aa,{animated:!0,size:11,className:"flat-map-agent-chip__activity"}):e.jsx("span",{className:"flat-map-agent-chip__dot",style:{backgroundColor:Sa(f.status)}}),f.latestTodos&&f.latestTodos.length>0&&e.jsx(Ya,{todos:f.latestTodos,maxDots:6}),J&&X&&X.length>0&&e.jsx(Ka,{subordinates:X,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:`${h.usedPercent}%`,backgroundColor:C}})})]})},f.id)})}),s.area.directories.length>0&&e.jsx("div",{className:"flat-map-area-card__folders",role:"group","aria-label":`${s.area.name} folders`,children:s.area.directories.map(f=>{const J=f.split("/").filter(Boolean).pop()||f;return e.jsxs("button",{type:"button",className:"flat-map-folder-chip",onClick:X=>{X.stopPropagation(),g.openFileExplorerForAreaFolder(r,f)},title:`Open in file explorer: ${f}`,children:[e.jsx(d,{name:"folder-open",size:12}),e.jsx("span",{className:"flat-map-folder-chip__name",children:J})]},f)})}),s.buildings.length>0&&e.jsx("div",{className:"flat-map-area-card__buildings",children:s.buildings.map(f=>{var X;const J=(X=Za[f.type])==null?void 0:X.color;return e.jsxs("button",{type:"button",className:`flat-map-building-chip flat-map-building-chip--${f.status}`,style:J?{"--building-type-color":J}:void 0,onClick:h=>{if(b){const C=h.currentTarget.getBoundingClientRect();b(f.id,{x:C.right,y:C.top+C.height/2})}else ee(f.id)},onContextMenu:h=>{h.preventDefault(),h.stopPropagation(),ve({buildingId:f.id,position:{x:h.clientX,y:h.clientY}})},title:`${f.name} · ${f.type} · ${f.status}`,children:[e.jsx(d,{name:Ja(f.type),size:12,color:J}),e.jsx("span",{className:"flat-map-building-chip__name",children:f.name}),e.jsx("span",{className:"flat-map-building-chip__dot",style:{backgroundColor:Qa(f.status)}})]},f.id)})})]},r)})})]})})]}),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:kt,onPointerMove:qe,onPointerUp:ke,onPointerCancel:ke,onDoubleClick:Ne}),ce&&e.jsxs("aside",{className:`flat-inspector ${Ht?"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":ye==="agent",className:`flat-inspector__tab ${ye==="agent"?"flat-inspector__tab--active":""}`,onClick:()=>ie("agent"),children:"Agent"}),e.jsx("button",{type:"button",role:"tab","aria-selected":ye==="tracking",className:`flat-inspector__tab ${ye==="tracking"?"flat-inspector__tab--active":""}`,onClick:()=>ie("tracking"),children:"Tracking"})]}),e.jsx("button",{type:"button",className:"flat-inspector__close",onClick:he,title:"Close inspector","aria-label":"Close inspector",children:"✕"})]}),e.jsx("div",{className:"flat-inspector__body",children:ye==="tracking"?e.jsx(en,{activeAgentId:v??"",onSelectAgent:t=>{c(t),window.innerWidth<=768&&he()}}):v?He?e.jsx(tn,{agent:He,onFocusAgent:t=>{c(t),window.innerWidth<=768&&he()},onKillAgent:t=>g.killAgent(t)}):e.jsx("div",{className:"flat-inspector__empty",children:e.jsx("span",{children:"Agent not found"})}):e.jsx("div",{className:"flat-inspector__empty",children:e.jsx("span",{children:"Select an agent to inspect"})})})]}),L&&e.jsx(an,{url:L.url,name:L.name,onClose:()=>_e(null)}),te&&e.jsx(nn,{state:te,onClose:()=>ue(null)}),e.jsx(sn,{agent:He??null,content:Ze,onClose:()=>jt(null)}),dt&&e.jsx(ln,{action:"clear-subordinates",selectedAgentId:dt.agentId,subordinateCount:dt.count,onClose:()=>$e(null),onClearHistory:()=>{}}),e.jsx(rn,{agent:He??null,isOpen:Qe&&!!v,onClose:et}),e.jsx(na,{isOpen:p!==null,position:(p==null?void 0:p.position)??{x:0,y:0},worldPosition:{x:0,z:0},actions:ot,onClose:()=>O(null)}),e.jsx(na,{isOpen:we!==null,position:(we==null?void 0:we.position)??{x:0,y:0},worldPosition:{x:0,z:0},actions:z,onClose:()=>ve(null)}),e.jsx(on,{isOpen:me!==null,title:K("common:confirm.removeAgentTitle"),message:K("common:confirm.removeAgentMessage",{name:(me==null?void 0:me.name)??""}),confirmLabel:K("common:buttons.remove"),cancelLabel:K("common:buttons.cancel"),variant:"danger",onConfirm:()=>{me&&g.removeAgentFromServer(me.agentId)},onClose:()=>Je(null)})]})}export{ns as FlatView};
@@ -1,4 +1,4 @@
1
- import{az as He,r as t,s as I,d as ye,aA as Ee,c as Oe,j as e,I as O,u as fe,aB as _e,aC as Te,aD as Be,aE as Ue,aF as Ke,aG as We,ad as Ve,a5 as De,aH as Ge,aI as qe,aJ as Je,aK as Ye,J as Xe,m as Me,S as le,F as Qe,C as Ze,n as et,y as Ie,z as tt,a0 as st,aL as nt,aq as X,aM as at}from"./main-Bb9H5jmt.js";import{FileExplorerPanel as ct}from"./index-Cd53q1WZ.js";import"./vendor-react--Eh9ivFN.js";import"./vendor-three-CBPuP1jE.js";const Se={status:"all",activity:"all",sort:"activity"},lt={"1h":3600*1e3,"6h":360*60*1e3,"24h":1440*60*1e3},Ae=20,me=3,ot={idle:"#4aff9e",working:"#4a9eff",waiting:"#ff9e4a",waiting_permission:"#ffcc00",error:"#ff4a4a",offline:"#888888",orphaned:"#ff9e4a"},rt=12e4;function it(s){return s.trim().replace(/\r\n/g,`
1
+ import{az as He,r as t,s as I,d as ye,aA as Ee,c as Oe,j as e,I as O,u as fe,aB as _e,aC as Te,aD as Be,aE as Ue,aF as Ke,aG as We,ad as Ve,a5 as De,aH as Ge,aI as qe,aJ as Je,aK as Ye,J as Xe,m as Me,S as le,F as Qe,C as Ze,n as et,y as Ie,z as tt,a0 as st,aL as nt,aq as X,aM as at}from"./main-Dk3qq80S.js";import{FileExplorerPanel as ct}from"./index-2427ATYD.js";import"./vendor-react--Eh9ivFN.js";import"./vendor-three-DYBBrXTx.js";const Se={status:"all",activity:"all",sort:"activity"},lt={"1h":3600*1e3,"6h":360*60*1e3,"24h":1440*60*1e3},Ae=20,me=3,ot={idle:"#4aff9e",working:"#4a9eff",waiting:"#ff9e4a",waiting_permission:"#ffcc00",error:"#ff4a4a",offline:"#888888",orphaned:"#ff9e4a"},rt=12e4;function it(s){return s.trim().replace(/\r\n/g,`
2
2
  `)}function $e(s,a){return`${s}:${it(a)}`}function dt(s,a,c,f){if(s.uuid&&a.has(s.uuid))return!1;if(s.uuid)return!0;const p=s.isUserPrompt?"user":"assistant",d=$e(p,s.text),M=s.timestamp||0,A=c.get(d);return A!==void 0&&Math.abs(M-A)<=rt?!1:M>f}function ut({isOpen:s,agents:a}){const c=He(),[f,p]=t.useState(new Map),d=t.useRef(new Set);t.useRef(a);const M=t.useMemo(()=>Array.from(a.keys()).sort().join(","),[a]),A=t.useMemo(()=>Array.from(a.values()).map(j=>`${j.id}:${j.sessionId||""}`).sort().join(","),[a]);t.useEffect(()=>{s||(d.current.clear(),p(new Map))},[s]),t.useEffect(()=>{if(!s)return;const j=new Set(Array.from(a.keys()));for(const i of d.current)j.has(i)||d.current.delete(i);let h=null;c>0&&(h=I.preserveOutputs(),d.current.clear());const v=async(i,b,$=0)=>{if(d.current.add(i.id),$>0&&await new Promise(x=>setTimeout(x,$)),p(x=>{const N=new Map(x);return N.set(i.id,{agentId:i.id,messages:[],loading:!0,hasMore:!1,totalCount:0}),N}),!i.sessionId){b&&b.length>0&&I.mergeOutputsWithHistory(i.id,[],b),p(x=>{const N=new Map(x);return N.set(i.id,{agentId:i.id,messages:[],loading:!1,hasMore:!1,totalCount:0}),N});return}try{const N=await(await Oe(ye(`/api/agents/${i.id}/history?limit=${Ee}&offset=0`))).json(),P=N.messages||[],W=P.length>0?Math.max(...P.map(C=>C.timestamp?new Date(C.timestamp).getTime():0)):0,J=new Set(P.map(C=>C.uuid).filter(C=>!!C)),V=new Map;for(const C of P){if(C.type!=="user"&&C.type!=="assistant")continue;const o=$e(C.type,C.content),L=C.timestamp?new Date(C.timestamp).getTime():0,K=V.get(o)??0;L>K&&V.set(o,L)}const G=I.getOutputs(i.id),U=(b&&b.length>0?[...b,...G]:G).filter(C=>dt(C,J,V,W));I.clearOutputs(i.id);for(const C of U)I.addOutput(i.id,C);p(C=>{const o=new Map(C);return o.set(i.id,{agentId:i.id,messages:P,loading:!1,hasMore:N.hasMore||!1,totalCount:N.totalCount||0}),o})}catch(x){if(console.error(`Failed to load history for ${i.name}:`,x),b&&b.length>0){I.clearOutputs(i.id);for(const N of b)I.addOutput(i.id,N)}p(N=>{const P=new Map(N);return P.set(i.id,{agentId:i.id,messages:[],loading:!1,hasMore:!1,totalCount:0}),P})}},u=c>0?500:0,D=Array.from(a.values());for(const i of D)if(!d.current.has(i.id)){const b=h==null?void 0:h.get(i.id);v(i,b,u)}},[s,M,A,c]);const R=t.useRef(a),k=t.useRef(f);R.current=a,k.current=f;const w=t.useCallback(async j=>{const h=R.current.get(j),v=k.current.get(j);if(!(h!=null&&h.sessionId)||!v||!v.hasMore)return;const u=v.messages.length;try{const i=await(await fetch(ye(`/api/agents/${j}/history?limit=${Ee}&offset=${u}`))).json();i.messages&&i.messages.length>0&&p(b=>{const $=new Map(b),x=b.get(j);return x&&$.set(j,{...x,messages:[...i.messages,...x.messages],hasMore:i.hasMore||!1}),$})}catch(D){console.error(`Failed to load more history for agent ${j}:`,D)}},[]),E=t.useCallback(j=>{d.current.delete(j),p(h=>{const v=new Map(h),u=h.get(j);return u&&v.set(j,{...u,messages:[],hasMore:!1,totalCount:0,loading:!1}),v})},[]);return{histories:f,loadMoreHistory:w,clearAgentHistory:E}}function mt({command:s,onCommandChange:a,useTextarea:c,forceTextarea:f,onForceTextarea:p,onSend:d,canSend:M,attachedFiles:A,onAddFile:R,onRemoveFile:k,uploadFile:w,onAddPastedText:E,placeholder:j="Message...",className:h="",compact:v=!1,inputRef:u}){const D=t.useRef(null),i=t.useRef(null),b=t.useRef(c);t.useEffect(()=>{if(c&&!b.current&&i.current){const o=i.current;o.focus(),o.selectionStart=o.selectionEnd=o.value.length}b.current=c},[c]),t.useEffect(()=>{const o=i.current;if(!o||!c)return;o.style.height="auto";const L=v?120:180,K=Math.min(o.scrollHeight,L);o.style.height=`${K}px`},[s,c,v]);const $=t.useCallback(async o=>{const L=o.clipboardData.items;for(const _ of L)if(_.type.startsWith("image/")){o.preventDefault();const F=_.getAsFile();if(F){const z=await w(F);z&&R(z)}return}const K=o.clipboardData.files;if(K.length>0){o.preventDefault();for(const _ of K){const F=await w(_);F&&R(F)}return}const B=o.clipboardData.getData("text"),te=(B.match(/\n/g)||[]).length+1;if(te>5){o.preventDefault();const F=`[Pasted text #${E(B)} +${te} lines]`,z=o.target,se=z.selectionStart||0,ae=z.selectionEnd||0,ne=s.slice(0,se)+F+s.slice(ae);a(ne),c||p(!0)}},[s,a,c,p,w,R,E]),x=t.useCallback(async o=>{const L=o.target.files;if(L){for(const K of L){const B=await w(K);B&&R(B)}D.current&&(D.current.value="")}},[w,R]),N=t.useCallback(o=>{if(o.key==="Enter"&&o.shiftKey){c||(o.preventDefault(),p(!0));return}o.key==="Enter"&&(o.preventDefault(),d())},[c,p,d]),P=t.useCallback(o=>{},[]),W=t.useCallback(o=>{o.button===1&&(o.preventDefault(),o.stopPropagation())},[]),J=t.useCallback(o=>{i.current=o,u==null||u(o)},[u]),V=v?"agent-panel-input":"guake-input",G=v?"agent-panel-input-container":"guake-input-container",Q=v?"agent-panel-attach-btn":"guake-attach-btn",U=v?"agent-panel-send-btn":"",C=c?v?"agent-panel-input-expanded":"guake-input-expanded":"";return e.jsxs(e.Fragment,{children:[A.length>0&&e.jsx("div",{className:v?"agent-panel-attachments":"guake-attachments",children:A.map(o=>e.jsxs("div",{className:`${v?"agent-panel-attachment":"guake-attachment"} ${o.isImage?"is-image":""}`,children:[e.jsx("span",{className:v?"agent-panel-attachment-icon":"guake-attachment-icon",children:e.jsx(O,{name:o.isImage?"file":"paperclip",size:12})}),e.jsx("span",{className:v?"agent-panel-attachment-name":"guake-attachment-name",title:o.path,children:o.name}),!v&&e.jsxs("span",{className:"guake-attachment-size",children:["(",Math.round(o.size/1024),"KB)"]}),e.jsx("button",{className:v?"agent-panel-attachment-remove":"guake-attachment-remove",onClick:()=>k(o.id),title:"Remove",children:"×"})]},o.id))}),e.jsxs("div",{className:`${V} ${C} ${h}`,children:[e.jsx("input",{ref:D,type:"file",multiple:!0,onChange:x,style:{display:"none"},accept:"*"}),e.jsxs("div",{className:G,onAuxClick:W,children:[e.jsx("button",{className:Q,onClick:()=>{var o;return(o=D.current)==null?void 0:o.click()},title:"Attach file (or paste image)",children:e.jsx(O,{name:"paperclip",size:14})}),c?e.jsx("textarea",{ref:J,placeholder:j,value:s,onChange:o=>a(o.target.value),onKeyDown:N,onPaste:$,onMouseDown:P}):e.jsx("input",{ref:u,type:"text",placeholder:j,value:s,onChange:o=>a(o.target.value),onKeyDown:N,onPaste:$,onMouseDown:P}),e.jsx("button",{className:U,onClick:d,disabled:!M,title:"Send",children:e.jsx(O,{name:"send",size:14})})]})]})]})}function ft(s){const a=Math.floor(s/1e3),c=Math.floor(a/60),f=a%60;return`${c}:${f.toString().padStart(2,"0")}`}const pt=t.memo(function({agentId:a,isWorking:c,timestamp:f}){const{t:p}=fe(["terminal"]),[d,M]=t.useState(0);return t.useEffect(()=>{if(!c||!f){M(0);return}M(Date.now()-f);const A=setInterval(()=>{M(Date.now()-f)},1e3);return()=>clearInterval(A)},[c,f]),c?e.jsxs("div",{className:"guake-stop-bar",children:[e.jsx("span",{className:"guake-elapsed-timer",children:ft(d)}),e.jsxs("button",{className:"guake-stop-btn",onClick:()=>I.stopAgent(a),title:p("terminal:input.stopOperation"),children:[e.jsx("span",{className:"stop-icon",children:e.jsx(O,{name:"stop",size:12,weight:"fill"})}),e.jsx("span",{className:"stop-label",children:p("terminal:input.stop")})]})]}):null});function ht({agent:s,history:a,outputs:c,isExpanded:f,isFocused:p,advancedView:d,onExpand:M,onFocus:A,inputRef:R,onLoadMore:k,onClearHistory:w}){const{t:E}=fe(["terminal","common"]),j=_e(s.id),h=t.useRef(null),[v,u]=t.useState(!1),D=t.useRef(0),i=t.useRef(!1),[b,$]=t.useState(!0),[x,N]=t.useState(!1),[P,W]=t.useState(null),[J,V]=t.useState(null),[G,Q]=t.useState(null);Te(`commander-image-modal-${s.id}`,P!==null,()=>W(null));const{command:U,setCommand:C,forceTextarea:o,setForceTextarea:L,useTextarea:K,setPastedTexts:B,incrementPastedCount:te,resetPastedCount:_,attachedFiles:F,setAttachedFiles:z,removeAttachedFile:se,uploadFile:ae,expandPastedTexts:ne}=Be({selectedAgentId:s.id}),ce=U.trim().length>0||F.length>0,n=Ue({outputs:c,viewMode:d?"advanced":"simple"}),l=t.useMemo(()=>{const S=Ke(s);return{usedPercent:S.usedPercent,freePercent:S.freePercent,hasData:!!s.contextStats,totalTokens:S.totalTokens,contextWindow:S.contextWindow}},[s.contextStats,s.contextUsed,s.contextLimit]),g=t.useCallback(()=>{!v&&(a!=null&&a.hasMore)&&k&&(u(!0),D.current=h.current?h.current.scrollHeight-h.current.scrollTop:0,k())},[v,a==null?void 0:a.hasMore,k]);t.useEffect(()=>{v&&a&&!a.loading&&u(!1)},[a,v]);const m=t.useCallback(()=>{i.current=!0,$(!1)},[]),T=t.useRef(f),Z=t.useRef(p);t.useEffect(()=>{(f&&!T.current||p&&!Z.current)&&(i.current=!1,$(!0),N(!0)),T.current=f,Z.current=p},[f,p]);const ee=t.useRef(a==null?void 0:a.loading);t.useEffect(()=>{ee.current&&!(a!=null&&a.loading)&&(i.current=!1,$(!0),N(!0)),ee.current=a==null?void 0:a.loading},[a==null?void 0:a.loading]),t.useEffect(()=>{if(!x)return;const S=h.current;if(!S)return;const y=performance.now();let H=0,ue=-1,be;const Re=()=>{const{scrollTop:Fe,scrollHeight:Ne,clientHeight:Le}=S,ze=Ne-Fe-Le<=2;if(Math.abs(Ne-ue)<=1&&ze?H+=1:H=0,ue=Ne,H>=3){N(!1);return}if(performance.now()-y>5e3){N(!1);return}be=requestAnimationFrame(Re)};return be=requestAnimationFrame(Re),()=>cancelAnimationFrame(be)},[x]),t.useEffect(()=>{i.current||$(!0)},[n.length]);const q=t.useCallback(()=>!1,[]),ie=t.useCallback(S=>{const y=te();return B(H=>new Map(H).set(y,S)),y},[te,B]),he=t.useCallback(S=>{z(y=>[...y,S])},[z]),xe=t.useCallback(()=>{if(!ce)return;if(U.trim()==="/clear"&&F.length===0){I.clearContext(s.id),w(),C(""),L(!1),B(new Map),z([]),_();return}let S=ne(U.trim());if(F.length>0){const y=F.map(H=>H.isImage?`[Image: ${H.path}]`:`[File: ${H.path}]`).join(`
3
3
  `);S=S?`${S}
4
4