tide-commander 1.170.0 → 1.172.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +15 -0
- package/dist/assets/{BossLogsModal-BPAHzrbZ.js → BossLogsModal-BfjrR-ig.js} +1 -1
- package/dist/assets/{BossSpawnModal-CaMQAL4B.js → BossSpawnModal-DCGHQ875.js} +1 -1
- package/dist/assets/{ControlsModal-CCCOEUic.js → ControlsModal-CnGtaFru.js} +1 -1
- package/dist/assets/{DockerLogsModal-eipz4JMG.js → DockerLogsModal-Cgz7skdG.js} +1 -1
- package/dist/assets/{EmbeddedEditor-Dxi_G2S1.js → EmbeddedEditor-BvL6TmAS.js} +1 -1
- package/dist/assets/{GmailOAuthSetup-DtK4z83H.js → GmailOAuthSetup-DoBBE3aO.js} +1 -1
- package/dist/assets/{GoogleOAuthSetup-CsxxXsHU.js → GoogleOAuthSetup-yXSspz66.js} +1 -1
- package/dist/assets/{IframeModal-MlgHd01n.js → IframeModal-Biahp5sK.js} +1 -1
- package/dist/assets/{IntegrationsPanel-Ci-4UMQg.js → IntegrationsPanel-KhWt4Xlz.js} +2 -2
- package/dist/assets/{LogViewerModal-1A5doXcl.js → LogViewerModal-94UiSojX.js} +1 -1
- package/dist/assets/{MonitoringModal-CgsxxYKS.js → MonitoringModal-BHBp9zYq.js} +1 -1
- package/dist/assets/{PM2LogsModal-g7HH5Va8.js → PM2LogsModal-Cmxg4Tdh.js} +1 -1
- package/dist/assets/{RestoreArchivedAreaModal-J4ANUsTT.js → RestoreArchivedAreaModal-BjD27IeT.js} +1 -1
- package/dist/assets/{Scene2DCanvas-CS2Ec3fo.js → Scene2DCanvas-krrnvfm2.js} +1 -1
- package/dist/assets/{SceneManager-B3KisMqb.js → SceneManager-CufxRVfp.js} +1 -1
- package/dist/assets/{SkillsPanel-CcSLi_lV.js → SkillsPanel-Be7V8Myg.js} +1 -1
- package/dist/assets/{SlackMultiInstanceSetup-CkDgMh7O.js → SlackMultiInstanceSetup-D4bO4-wA.js} +1 -1
- package/dist/assets/{SpawnModal-DDkDa4lH.js → SpawnModal-DBAjKaEJ.js} +1 -1
- package/dist/assets/{StatisticsModal-DefIHAFP.js → StatisticsModal-Ck2SaX0C.js} +1 -1
- package/dist/assets/{SubordinateAssignmentModal-HXgM72IC.js → SubordinateAssignmentModal-COc54Xcg.js} +1 -1
- package/dist/assets/{TriggerManagerPanel-CuE7hxxv.js → TriggerManagerPanel-BPI36Swd.js} +1 -1
- package/dist/assets/{WorkflowEditorPanel-CtNhGXaK.js → WorkflowEditorPanel-uIICa9ZA.js} +1 -1
- package/dist/assets/{abnfDiagram-VRR7QNED-BUlnnP_1.js → abnfDiagram-VRR7QNED-CYckXHwv.js} +1 -1
- package/dist/assets/{arc-BBtryQAN.js → arc-DKM1r4jO.js} +1 -1
- package/dist/assets/{architectureDiagram-ZJ3FMSHR-C0kI5Z7d.js → architectureDiagram-ZJ3FMSHR-i9sds9KO.js} +1 -1
- package/dist/assets/{area-logos-BjCgZv0Z.js → area-logos-DRbo7OkE.js} +1 -1
- package/dist/assets/{blockDiagram-677ZJIJ3-C3Qr8pSs.js → blockDiagram-677ZJIJ3-BY6FRf8G.js} +1 -1
- package/dist/assets/{c4Diagram-LMCZKHZV-BGNVz2Pl.js → c4Diagram-LMCZKHZV-Di9zEQ50.js} +1 -1
- package/dist/assets/channel-BmnfqaSp.js +1 -0
- package/dist/assets/{chunk-2Q5K7J3B-BfRYa0Ce.js → chunk-2Q5K7J3B-CJHcs_7e.js} +1 -1
- package/dist/assets/{chunk-32BRIVSS-QaQwn5eJ.js → chunk-32BRIVSS-8wx_d9CG.js} +1 -1
- package/dist/assets/{chunk-5VM5RSS4-CBz119og.js → chunk-5VM5RSS4-0Vwmtk7O.js} +1 -1
- package/dist/assets/{chunk-EX3LRPZG-CjKB5rDB.js → chunk-EX3LRPZG-Bugn6LUu.js} +1 -1
- package/dist/assets/{chunk-JWPE2WC7-BY_eTYH-.js → chunk-JWPE2WC7-DNjmFpDA.js} +1 -1
- package/dist/assets/{chunk-MOJQB5TN-D-jZu9aq.js → chunk-MOJQB5TN-pwKIkQIP.js} +1 -1
- package/dist/assets/{chunk-RYQCIY6F-9tDKSaCa.js → chunk-RYQCIY6F-BedLhhhr.js} +1 -1
- package/dist/assets/{chunk-V7JOEXUC-DAcdz5JR.js → chunk-V7JOEXUC-DsRtiT2x.js} +1 -1
- package/dist/assets/{chunk-VR4S4FIN-D0Gs0s1C.js → chunk-VR4S4FIN-DDSmX474.js} +1 -1
- package/dist/assets/{chunk-XXDRQBXY-BbFQhnEi.js → chunk-XXDRQBXY-DyrlBiER.js} +1 -1
- package/dist/assets/classDiagram-OUVF2IWQ-DgBOoX8f.js +1 -0
- package/dist/assets/classDiagram-v2-EOCWNBFH-DgBOoX8f.js +1 -0
- package/dist/assets/{cose-bilkent-JH36ORCC-C_Zzgy_G.js → cose-bilkent-JH36ORCC-D_QAo009.js} +1 -1
- package/dist/assets/{cynefin-VYW2F7L2-C8Z0Gw9s.js → cynefin-VYW2F7L2-Dk-lm0Wy.js} +1 -1
- package/dist/assets/{cynefinDiagram-TSTJHNR4-C6iZsj7V.js → cynefinDiagram-TSTJHNR4-BqVbwlAe.js} +1 -1
- package/dist/assets/{dagre-VKFMJZFB-BIMPhAGq.js → dagre-VKFMJZFB-ehsHFsTF.js} +1 -1
- package/dist/assets/{diagram-FQU43EPY-BT3deX2Y.js → diagram-FQU43EPY-JHnOlGyN.js} +1 -1
- package/dist/assets/{diagram-G47NLZAW-RdBVaRH-.js → diagram-G47NLZAW-CjKWIeBY.js} +1 -1
- package/dist/assets/{diagram-NH7WQ7WH-DSr98n7w.js → diagram-NH7WQ7WH-DfzmKOFc.js} +1 -1
- package/dist/assets/{diagram-OA4YK3LP-DVZbdjtc.js → diagram-OA4YK3LP-DZevP0dI.js} +1 -1
- package/dist/assets/{diagram-WEI45ONY-BIrvSxLv.js → diagram-WEI45ONY-D6aQzA6L.js} +1 -1
- package/dist/assets/{ebnfDiagram-CCIWWBDH-B3IYx45j.js → ebnfDiagram-CCIWWBDH-DiVLHNE7.js} +1 -1
- package/dist/assets/{erDiagram-Q63AITRT-CV_YuDOI.js → erDiagram-Q63AITRT-CfUINFZr.js} +1 -1
- package/dist/assets/{flowDiagram-23GEKE2U-DYyiTzbJ.js → flowDiagram-23GEKE2U-Crui2G2i.js} +1 -1
- package/dist/assets/{ganttDiagram-NO4QXBWP-CvnfbOAj.js → ganttDiagram-NO4QXBWP-DtPc0A8G.js} +1 -1
- package/dist/assets/{gitGraphDiagram-IHSO6WYX-J_g1ozi2.js → gitGraphDiagram-IHSO6WYX-CTT_kpsT.js} +1 -1
- package/dist/assets/index---m-V9Ve.js +1 -0
- package/dist/assets/{index-BgKnXI_I.js → index-B5c8lVZz.js} +1 -1
- package/dist/assets/{index-D9L5KXBG.js → index-Belb0RtH.js} +1 -1
- package/dist/assets/{index-DGGpeHyi.js → index-BzXmmQUX.js} +2 -2
- package/dist/assets/{index-DkcDKqa-.js → index-Cq9VfNYq.js} +2 -2
- package/dist/assets/{index-YquOzpmw.js → index-DSoB3-8O.js} +1 -1
- package/dist/assets/{index-CzsLF0a9.js → index-DVMmKvDa.js} +1 -1
- package/dist/assets/{index-9o_y4lu7.js → index-JYba9gLW.js} +3 -3
- package/dist/assets/{index-BhAy_8sx.js → index-QZg8i9rn.js} +1 -1
- package/dist/assets/{infoDiagram-FWYZ7A6U-D5Mm8I_o.js → infoDiagram-FWYZ7A6U-1le6xBqE.js} +1 -1
- package/dist/assets/{ishikawaDiagram-FXEZZL3T-Ce9yNDRK.js → ishikawaDiagram-FXEZZL3T-DwrRd8gX.js} +1 -1
- package/dist/assets/{journeyDiagram-5HDEW3XC-hK5WUkcb.js → journeyDiagram-5HDEW3XC-C5-PZAy5.js} +1 -1
- package/dist/assets/{kanban-definition-HUTT4EX6-BIIQCAOg.js → kanban-definition-HUTT4EX6-Cwb0BgNh.js} +1 -1
- package/dist/assets/{linear-BBTmd6GJ.js → linear-5XPm8-aP.js} +1 -1
- package/dist/assets/{main-D0DYgXWa.js → main-CvV6YpbU.js} +129 -129
- package/dist/assets/{main-Bt0ZVYXE.css → main-h6n299s0.css} +1 -1
- package/dist/assets/{mermaid.core-DxOQypXd.js → mermaid.core-Df-1XMOY.js} +4 -4
- package/dist/assets/{mindmap-definition-LN4V7U3C-DopTVGAH.js → mindmap-definition-LN4V7U3C-B8YefZzZ.js} +1 -1
- package/dist/assets/notification-sounds/CREDITS.md +32 -0
- package/dist/assets/notification-sounds/alert-low.mp3 +0 -0
- package/dist/assets/notification-sounds/alert.mp3 +0 -0
- package/dist/assets/notification-sounds/bell.mp3 +0 -0
- package/dist/assets/notification-sounds/blip-soft.mp3 +0 -0
- package/dist/assets/notification-sounds/blip.mp3 +0 -0
- package/dist/assets/notification-sounds/chime-double.mp3 +0 -0
- package/dist/assets/notification-sounds/chime-soft.mp3 +0 -0
- package/dist/assets/notification-sounds/chime.mp3 +0 -0
- package/dist/assets/notification-sounds/drop-soft.mp3 +0 -0
- package/dist/assets/notification-sounds/drop.mp3 +0 -0
- package/dist/assets/notification-sounds/glass-tap.mp3 +0 -0
- package/dist/assets/notification-sounds/glass.mp3 +0 -0
- package/dist/assets/notification-sounds/pluck.mp3 +0 -0
- package/dist/assets/notification-sounds/pop.mp3 +0 -0
- package/dist/assets/notification-sounds/question-bright.mp3 +0 -0
- package/dist/assets/notification-sounds/question-soft.mp3 +0 -0
- package/dist/assets/notification-sounds/question.mp3 +0 -0
- package/dist/assets/notification-sounds/switch-soft.mp3 +0 -0
- package/dist/assets/notification-sounds/switch.mp3 +0 -0
- package/dist/assets/notification-sounds/tick.mp3 +0 -0
- package/dist/assets/{pegDiagram-2B236MQR-BDFZz7xQ.js → pegDiagram-2B236MQR-D3Y7MTnN.js} +1 -1
- package/dist/assets/{pieDiagram-ENE6RG2P-DUxtuyZ8.js → pieDiagram-ENE6RG2P-D1KQcsvx.js} +1 -1
- package/dist/assets/{quadrantDiagram-ABIIQ3AL-CYQ6z89q.js → quadrantDiagram-ABIIQ3AL-qcSxExjT.js} +1 -1
- package/dist/assets/{railroadDiagram-RFXS5EU6-CPZeXSzB.js → railroadDiagram-RFXS5EU6-rd8I_s6H.js} +1 -1
- package/dist/assets/{requirementDiagram-TGXJPOKE-DS-bSy_p.js → requirementDiagram-TGXJPOKE-0N5tREFz.js} +1 -1
- package/dist/assets/{sankeyDiagram-HTMAVEWB-BSf-G1Jv.js → sankeyDiagram-HTMAVEWB-DWwsywl2.js} +1 -1
- package/dist/assets/{sequenceDiagram-DBY2YBRQ-Bsbp5-fW.js → sequenceDiagram-DBY2YBRQ-Bd3F2Qo4.js} +1 -1
- package/dist/assets/{sizeCapture-X5ZJPWSS-0oauMclt.js → sizeCapture-X5ZJPWSS-DlhT1fDP.js} +1 -1
- package/dist/assets/{stateDiagram-2N3HPSRC-DxjtPYnw.js → stateDiagram-2N3HPSRC-CGS5O9OJ.js} +1 -1
- package/dist/assets/stateDiagram-v2-6OUMAXLB-DHC7EZAb.js +1 -0
- package/dist/assets/{swimlanes-5IMT3BWC-ClT0R_qt.js → swimlanes-5IMT3BWC-DBiQ99CL.js} +2 -2
- package/dist/assets/swimlanesDiagram-G3AALYLV-Cmj0juvO.js +8 -0
- package/dist/assets/{timeline-definition-FHXFAJF6-B_adEXyf.js → timeline-definition-FHXFAJF6-D9rOqzNQ.js} +1 -1
- package/dist/assets/{vennDiagram-L72KCM5P-DHLTq5FV.js → vennDiagram-L72KCM5P-D_3pqGll.js} +1 -1
- package/dist/assets/{wardleyDiagram-EHGQE667-B1HJZmfL.js → wardleyDiagram-EHGQE667-BO8sF6ut.js} +1 -1
- package/dist/assets/{web-Bm712dX7.js → web-B62Goe5e.js} +1 -1
- package/dist/assets/{web-DmrF7XGy.js → web-BDVMZHAK.js} +1 -1
- package/dist/assets/{web-SQqqv-F3.js → web-IbBu4hoi.js} +1 -1
- package/dist/assets/{xychartDiagram-FW5EYKEG-D2QD2opl.js → xychartDiagram-FW5EYKEG-BnZf67Rr.js} +1 -1
- package/dist/build-info.json +1 -1
- package/dist/index.html +2 -2
- package/dist/locales/en/common.json +3 -1
- package/dist/locales/en/terminal.json +4 -1
- package/dist/src/packages/server/websocket/handlers/agent-handler.js +3 -0
- package/package.json +1 -1
- package/dist/assets/channel-DfrQjJNO.js +0 -1
- package/dist/assets/classDiagram-OUVF2IWQ-Cojz9UCF.js +0 -1
- package/dist/assets/classDiagram-v2-EOCWNBFH-Cojz9UCF.js +0 -1
- package/dist/assets/index-CqZv3WSe.js +0 -1
- package/dist/assets/stateDiagram-v2-6OUMAXLB-DgB5IYLl.js +0 -1
- package/dist/assets/swimlanesDiagram-G3AALYLV-D0FT2zjl.js +0 -8
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{r as s,aP as Aa,aQ as ea,K as ma,aR as pa,j as e,aS as fa,aT as Ea,u as Kt,aU as Ma,aV as Ia,aW as Ta,aX as La,aY as Pa,an as $a,ae as Ra,av as ha,m as ta,S as M,w as aa,aZ as Yt,a_ as na,a$ as Mt,b0 as _e,b1 as Da,s as g,_ as ga,f as xa,b2 as za,b3 as sa,b4 as ia,I as d,b5 as Oa,ay as Ba,b6 as Fa,n as ba,b7 as _a,b8 as wa,b9 as va,ba as Wa,bb as Ha,bc as Ua,ad as Ga,bd as Va,be as Xa,bf as qa,aB as Ya,aC as Ka,aD as Za,bg as Ja,bh as Qa,bi as la,X as en,R as tn,E as ra,bj as an,bk as nn,bl as sn,bm as ln,bn as rn,bo as on,bp as cn,bq as dn,br as un,bs as mn,x as pn,bt as fn,bu as hn,bv as gn,bw as xn,bx as it,by as bn,bz as _n,bA as wn,bB as vn,bC as gt,bD as jn,bE as Cn,bF as kn,bG as Nn,p as yn,q as oa,o as Sn}from"./main-D0DYgXWa.js";import{g as An}from"./area-logos-BjCgZv0Z.js";import"./vendor-react--Eh9ivFN.js";import"./vendor-three-3OKhI9bz.js";function En(c){const r=s.useRef(c);r.current=c,s.useEffect(()=>{if(!Aa())return;let p=null,b=!1;return ea.addListener("backButton",()=>{r.current()==="exit"&&ea.exitApp()}).then(N=>{b?N.remove():p=N}),()=>{b=!0,p&&(p.remove(),p=null)}},[])}async function Mn(c){const r=ma(),p=await fetch(`${pa()}/api/agents/${c}/terminal`,{method:"POST",headers:{Authorization:`Bearer ${r}`}});if(!p.ok){const b=await p.json().catch(()=>({}));throw new Error((b==null?void 0:b.error)||`Failed to start terminal (${p.status})`)}return p.json()}async function In(c){const r=ma();await fetch(`${pa()}/api/agents/${c}/terminal`,{method:"DELETE",headers:{Authorization:`Bearer ${r}`}})}const xt=new Map;function Tn({agentId:c}){const[r,p]=s.useState(null),[b,N]=s.useState(null);return s.useEffect(()=>{let I=!1;const A=xt.get(c);return A&&(clearTimeout(A),xt.delete(c)),p(null),N(null),Mn(c).then(y=>{I||p(y.url)}).catch(y=>{I||N(y instanceof Error?y.message:"Failed to start terminal")}),()=>{I=!0;const y=xt.get(c);y&&clearTimeout(y),xt.set(c,setTimeout(()=>{xt.delete(c),In(c)},2500))}},[c]),b?e.jsx("div",{className:"flat-classic-terminal flat-classic-terminal--message",children:e.jsx("span",{children:b})}):r?e.jsx("div",{className:"flat-classic-terminal",children:e.jsx(fa,{terminalUrl:r,visible:!0})}):e.jsx("div",{className:"flat-classic-terminal flat-classic-terminal--message",children:e.jsx("span",{children:"Attaching to interactive session…"})})}const Gt=new Map,Ln=6e4;function ca(c){return Number.isFinite(c)?Math.abs(c)>=1e3?c.toLocaleString(void 0,{maximumFractionDigits:0}):c.toLocaleString(void 0,{maximumFractionDigits:2}):String(c)}function Pn(c,r){var N,I,A;const p=[];if(!c.rateLimits)return p;if(c.provider==="claude"){const y=c,K=[{key:"fiveHour",label:r("terminal:usage.currentSession"),window:y.rateLimits.fiveHour},{key:"sevenDay",label:r("terminal:usage.currentWeekAll"),window:y.rateLimits.sevenDay},{key:"sevenDayOpus",label:r("terminal:usage.currentWeekOpus"),window:y.rateLimits.sevenDayOpus},{key:"sevenDayFable",label:r("terminal:usage.currentWeekFable"),window:y.rateLimits.sevenDayFable}];for(const v of K)(v.window||v.key==="sevenDayFable")&&p.push(v);return p}const b=c;return(N=b.rateLimits)!=null&&N.weekly&&p.push({key:"weekly",label:r("terminal:usage.weeklyLimit"),window:b.rateLimits.weekly}),(I=b.rateLimits)!=null&&I.monthly&&p.push({key:"monthly",label:r("terminal:usage.monthlyLimit"),window:b.rateLimits.monthly}),(A=b.rateLimits)!=null&&A.onDemand&&p.push({key:"onDemand",label:r("terminal:usage.onDemandLimit"),window:b.rateLimits.onDemand}),p}function $n({agentId:c,contextSummary:r}){const{t:p}=Kt(["terminal","common"]),[b,N]=s.useState(()=>{var R;return((R=Gt.get(c))==null?void 0:R.snapshot)??null}),[I,A]=s.useState(!1),[y,K]=s.useState(null),v=s.useRef(0);s.useEffect(()=>{const R=Gt.get(c);if(R&&Date.now()-R.fetchedAt<Ln){N(R.snapshot);return}const re=++v.current;A(!0),K(null),Ma(c).then(T=>{re===v.current&&(Gt.set(c,{snapshot:T,fetchedAt:Date.now()}),N(T),A(!1))}).catch(T=>{re===v.current&&(K(T.message||"Failed to load plan limits"),A(!1))})},[c]);const H=b?Pn(b,p):[];return e.jsxs("div",{className:"plan-limits-tooltip",children:[r&&e.jsx("div",{className:"plan-limits-tooltip__context",children:r}),e.jsx("div",{className:"plan-limits-tooltip__title",children:p("terminal:usage.limits")}),I&&!b&&e.jsxs("div",{className:"plan-limits-tooltip__muted",children:[p("common:status.loading"),"…"]}),!I&&y&&!b&&e.jsx("div",{className:"plan-limits-tooltip__muted",children:p("terminal:usage.limitsError",{message:y})}),H.length>0?e.jsx("div",{className:"plan-limits-tooltip__gauges",children:H.map(({key:R,label:re,window:T})=>{const Ee=T?Math.max(0,Math.min(100,T.utilization)):0,oe=Ta(Ee),ce=T!=null&&typeof T.used=="number"&&typeof T.limit=="number"&&Number.isFinite(T.used)&&Number.isFinite(T.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:re}),e.jsx("span",{className:"plan-limits-tooltip__gauge-percent",style:{color:oe},children:p("terminal:usage.percentUsed",{percent:Math.round(Ee)})})]}),e.jsx("div",{className:"plan-limits-tooltip__bar",children:e.jsx("div",{className:"plan-limits-tooltip__bar-fill",style:{width:`${Ee}%`,background:oe}})}),e.jsxs("div",{className:"plan-limits-tooltip__reset",children:[T&&p("terminal:usage.resets",{time:Ia(T.resetsAt)}),ce&&e.jsx("span",{style:{marginLeft:8},children:p("terminal:usage.creditsUsed",{used:ca(T.used),limit:ca(T.limit)})})]})]},R)})}):b&&!I&&e.jsx("div",{className:"plan-limits-tooltip__muted",children:b.rateLimitsError?p("terminal:usage.limitsError",{message:b.rateLimitsError}):b.cliHint})]})}function Rn({agentId:c,disabled:r,contextSummary:p,children:b}){return e.jsx(Ea,{position:"top",maxWidth:320,disabled:r,className:"plan-limits-tooltip-wrapper",triggerStyle:{display:"inline-flex",alignItems:"center"},content:e.jsx($n,{agentId:c,contextSummary:p}),children:b})}const Dn=s.memo(function({className:r=""}){const{t:p}=Kt(["common"]),[b,N]=La(),I=s.useRef(null),[A,y]=s.useState(null);s.useLayoutEffect(()=>{const v=I.current;if(!v)return;const H=v.querySelector(".view-mode-toggle__btn--active");H&&y({left:H.offsetLeft,width:H.offsetWidth})},[b]);const K=s.useCallback(v=>{if(v!==b){if(typeof window<"u"&&window.dispatchEvent(new CustomEvent("tide:viewmode-switch-pressed",{detail:{mode:v}})),v==="3d"){requestAnimationFrame(()=>N(v));return}N(v)}},[b,N]);return e.jsxs("div",{className:`view-mode-toggle ${r}`,ref:I,children:[A&&e.jsx("div",{className:"view-mode-toggle__indicator",style:{left:A.left,width:A.width}}),Pa.map(v=>e.jsxs("button",{className:`view-mode-toggle__btn ${b===v?"view-mode-toggle__btn--active":""}`,onClick:()=>K(v),title:p(`common:viewMode.descriptions.${v}`),children:[e.jsxs("span",{className:"view-mode-toggle__icon",children:[v==="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"})]}),v==="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"})]}),v==="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"})]}),v==="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:p(`common:viewMode.labels.${v}`)})]},v))]})}),It=3,Tt=280,da=320,Vt=240,ua=64,zn=["simple","chat","advanced"],On={simple:"Simple",chat:"Chat",advanced:"Advanced"},Bn={simple:"○",chat:"◐",advanced:"◉"},Fn={simple:"Simple view — clean messages only",chat:"Chat view — assistant replies (no tool calls)",advanced:"Advanced view — everything including tools"},Xt="flat-clear-context",ja="tide:flat-embedded-panels";function Ca(){try{const c=localStorage.getItem(ja),r=c?JSON.parse(c):{};return r&&typeof r=="object"?r:{}}catch{return{}}}function qt(c,r){try{const p=Ca();r?p[c]=r:delete p[c],localStorage.setItem(ja,JSON.stringify(p))}catch{}}function Wn(c){const r=c.split("/").filter(Boolean);return r.length===0?c:r.slice(-2).join("/")}function Hn(c){if(c.provider==="codex"){const I=c.codexModel||"gpt-5.6-luna",A=yn[I];return{model:(A==null?void 0:A.label)||I}}if(c.provider==="opencode")return{model:c.opencodeModel||"opencode"};if(c.provider==="grok"){const I=c.grokModel||"grok-4.5",A=c.effort,y=A?oa[A]:void 0;return{model:I,effort:y==null?void 0:y.label}}const r=c.model||"sonnet",p=Sn[r],b=c.effort,N=b?oa[b]:void 0;return{model:(p==null?void 0:p.label)||r,effort:N==null?void 0:N.label}}function Un(c,r){if(r.type==="rectangle"&&r.width&&r.height){const p=r.width/2,b=r.height/2;return c.x>=r.center.x-p&&c.x<=r.center.x+p&&c.z>=r.center.z-b&&c.z<=r.center.z+b}if(r.type==="circle"&&r.radius){const p=c.x-r.center.x,b=c.z-r.center.z;return p*p+b*b<=r.radius*r.radius}return!1}const Gn=tn.memo(function({agentId:r,terminalViewMode:p,onTerminalViewModeChange:b,inspectorOpen:N,onToggleInspector:I,onShowTaskBoard:A,onImageClick:y,onFileClick:K,onBashClick:v,onViewMarkdown:H,onRequestClearSubordinates:R,keyboard:re,canNavigateBack:T,canNavigateForward:Ee,onNavigateBack:oe,onNavigateForward:ce,agentInfoOpen:Oe,onToggleAgentInfo:bt,onHeaderContextMenu:we,onBuildingContextMenu:ve}){var Nt,yt;const u=ra(r),D=xa(),Me=an(),Ie=s.useRef(null),Ze=s.useRef(null),{displayedAgentId:Te,fadingOut:Lt}=nn(r),_t=ra(Te),Je=!!Me.interactiveMode&&((u==null?void 0:u.provider)??"claude")==="claude"&&!!(u!=null&&u.sessionId),[de,Qe]=s.useState(!1),[Be,ue]=s.useState(!1),$=s.useCallback(()=>ue(!1),[]);ha("flat-chat-actions",Be,$),s.useEffect(()=>{const a=()=>ue(o=>!o);return window.addEventListener("tide:toggle-chat-actions",a),()=>window.removeEventListener("tide:toggle-chat-actions",a)},[]),s.useEffect(()=>{Qe(!1),ue(!1)},[r]),s.useEffect(()=>{!Je&&de&&Qe(!1)},[Je,de]),s.useEffect(()=>{const a=Ze.current;if(!a)return;const o=m=>{m.button===3?(m.preventDefault(),m.stopPropagation(),oe()):m.button===4&&(m.preventDefault(),m.stopPropagation(),ce())},i=m=>{(m.button===3||m.button===4)&&m.preventDefault()};return a.addEventListener("mouseup",o),a.addEventListener("mousedown",i),()=>{a.removeEventListener("mouseup",o),a.removeEventListener("mousedown",i)}},[oe,ce]),s.useEffect(()=>{const a=Ze.current;if(!a)return;let o=0,i=0,m=0;const X=250,Q=600,L=80,st=1.5,ae=ne=>{let U=ne instanceof HTMLElement?ne:null;for(;U&&U!==a;){const St=window.getComputedStyle(U).overflowX;if((St==="auto"||St==="scroll")&&U.scrollWidth>U.clientWidth)return!0;U=U.parentElement}return!1},Ye=ne=>{const U=Date.now();if(U<m){ne.preventDefault();return}if(Math.abs(ne.deltaX)<=Math.abs(ne.deltaY)*st){o=0;return}if(ae(ne.target)){o=0;return}U-i>X&&(o=0),i=U,o+=ne.deltaX,o<=-L?(o=0,m=U+Q,ne.preventDefault(),oe()):o>=L&&(o=0,m=U+Q,ne.preventDefault(),ce())};return a.addEventListener("wheel",Ye,{passive:!1}),()=>a.removeEventListener("wheel",Ye)},[oe,ce]);const me=ga(),lt=s.useMemo(()=>{if(!u)return null;const a=new Set,o=[];for(const i of me.values())i.archived||i.directories.length===0||i.assignedAgentIds.includes(r)&&(a.add(i.id),o.push(i));for(const i of me.values())i.archived||i.directories.length===0||a.has(i.id)||Un({x:u.position.x,z:u.position.z},i)&&(a.add(i.id),o.push(i));return o.length===0?null:o.flatMap(i=>i.directories.filter(m=>m&&m.trim().length>0).map(m=>({areaId:i.id,areaName:i.name,dir:m})))},[u,r,me]),{branches:wt,fetchRemote:Fe,fetchingDirs:Le}=sn(lt),pe=s.useMemo(()=>{var i;const a=g.getAreaForAgent(r);if(!a)return[];const o=[];for(const m of D.values())m.type==="terminal"&&g.isPositionInArea(m.position,a)&&o.push({id:m.id,name:m.name,hasUrl:!!((i=m.terminalStatus)!=null&&i.url)});return o},[r,D]),je=s.useMemo(()=>{var i;const a=g.getAreaForAgent(r);if(!a)return[];const o=[];for(const m of D.values())m.type==="server"&&((i=m.pm2)!=null&&i.enabled)&&g.isPositionInArea(m.position,a)&&o.push({id:m.id,name:m.name});return o},[r,D]),Z=s.useMemo(()=>{const a=g.getAreaForAgent(r);if(!a)return[];const o=[];for(const i of D.values())i.type==="database"&&i.database&&g.isPositionInArea(i.position,a)&&o.push({id:i.id,name:i.name});return o},[r,D]),We=ln(),se=s.useMemo(()=>{const a=g.getAreaForAgent(r);if(!a)return[];const o=[];for(const i of D.values())if(i.type==="tests"&&g.isPositionInArea(i.position,a)){const m=!!i.folderPath&&We.some(X=>rn(X,i.folderPath));o.push({id:i.id,name:i.name,working:m})}return o},[r,D,We]),ie=s.useMemo(()=>{const a=g.getAreaForAgent(r);if(!a)return[];const o=[];for(const i of D.values())i.type==="http"&&g.isPositionInArea(i.position,a)&&o.push({id:i.id,name:i.name});return o},[r,D]),[,Pt]=s.useReducer(a=>a+1,0),Ce=((Nt=Ie.current)==null?void 0:Nt.search.searchMode)??!1,rt=s.useCallback(()=>{var a;(a=Ie.current)==null||a.search.toggleSearch(),Pt()},[]),Pe=on(),$e=Pe.isPending(Xt),[j,te]=s.useState(null),J=j?D.get(j.buildingId):null,[He,Re]=s.useState(""),[Ue,$t]=s.useState(()=>cn()),z=s.useMemo(()=>{var a;return((a=g.getAreaForAgent(r))==null?void 0:a.id)??null},[r,D]),Ge=s.useCallback((a,o)=>{Re(""),te(i=>{const m=(i==null?void 0:i.buildingId)===o?null:{type:a,buildingId:o};return z&&qt(z,m),m})},[z]),ke=s.useCallback(()=>{Re(""),te(null),z&&qt(z,null)},[z]);s.useEffect(()=>{if((j==null?void 0:j.type)!=="pm2-logs")return;const a=j.buildingId;return g.startLogStreaming(a,200),()=>g.stopLogStreaming(a)},[j]);const{height:Rt,onResizeStart:Dt}=dn(),{sidePanelWidth:zt,handleSidePanelResizeStart:ot}=un(),[w,vt]=s.useState(()=>Yt(M.GIT_PANEL_OPEN,!1)),[De,fe]=s.useState(()=>Yt(M.BUILDINGS_PANEL_OPEN,!1)),[O,Ve]=s.useState(!1),ct=s.useCallback(()=>{Ve(a=>{const o=!a;return o&&mn.setEnabled(!0),o})},[]),Ot=s.useCallback(()=>Ve(!1),[]),jt=s.useCallback(()=>{vt(a=>{const o=!a;return _e(M.GIT_PANEL_OPEN,o),o})},[]),Ct=s.useCallback(()=>{fe(a=>{const o=!a;return _e(M.BUILDINGS_PANEL_OPEN,o),o})},[]),Bt=s.useCallback(()=>{vt(!1),_e(M.GIT_PANEL_OPEN,!1)},[]),dt=s.useCallback(()=>{fe(!1),_e(M.BUILDINGS_PANEL_OPEN,!1)},[]),Xe=pn(),he=s.useMemo(()=>({terminal:pe,"pm2-logs":je,database:Z,tests:se,http:ie}),[pe,je,Z,se,ie]);s.useEffect(()=>{if(!j)return;he[j.type].some(o=>o.id===j.buildingId)||(Re(""),te(null))},[j,he]);const Ne=s.useRef(void 0);s.useEffect(()=>{var o;if(Ne.current===z)return;Ne.current=z;const a=z?Ca()[z]:void 0;Re(""),a&&((o=he[a.type])!=null&&o.some(i=>i.id===a.buildingId))?te(a):te(null)},[z,he]),s.useEffect(()=>{const a=o=>{var X;const i=o.detail;if(!(i!=null&&i.buildingId)||!(i!=null&&i.type)||!((X=he[i.type])!=null&&X.some(Q=>Q.id===i.buildingId)))return;i.handled=!0,Re("");const m={type:i.type,buildingId:i.buildingId};te(m),z&&qt(z,m)};return window.addEventListener("tide:dock-building-flat",a),()=>window.removeEventListener("tide:dock-building-flat",a)},[he,z]);const[qe,B]=s.useState(!1),ge=s.useRef(null);if(s.useEffect(()=>{if(!qe)return;const a=o=>{ge.current&&!ge.current.contains(o.target)&&B(!1)};return document.addEventListener("mousedown",a),()=>document.removeEventListener("mousedown",a)},[qe]),!u)return e.jsx("div",{className:"flat-chat flat-chat--empty",children:e.jsxs("div",{className:"flat-chat__placeholder",children:[e.jsx("span",{className:"flat-chat__placeholder-icon",children:"💬"}),e.jsx("span",{className:"flat-chat__placeholder-text",children:"Select an agent to start chatting"})]})});const ye=u.contextStats,ut=!!ye,et=ye?ye.totalTokens:u.contextUsed||0,mt=ye?ye.contextWindow:u.contextLimit||(u.provider==="grok"?5e5:2e5),Ft=ye?ye.usedPercent:Math.round(et/mt*100),ze=Math.max(0,Math.min(100,Ft)),kt=Math.round(ze*10)/10,xe=Math.round((100-ze)*10)/10,tt=ze>=80?"#ff4a4a":ze>=60?"#ff9e4a":ze>=40?"#ffd700":"#4aff9e",at=(et/1e3).toFixed(1),pt=(mt/1e3).toFixed(1),be=u.cwd,ft=be?Wn(be):null,Se=((yt=u.subordinateIds)==null?void 0:yt.length)||0,nt=Se>0;return e.jsxs("div",{ref:Ze,className:`flat-terminal-wrapper ${w||De||O?"flat-terminal-wrapper--with-side-panel":""} ${Lt?"pane-fading-out":""}`,style:{"--guake-side-panel-width":`min(${zt}px, 70%)`},children:[e.jsxs("div",{className:"flat-terminal-wrapper__header",children:[e.jsxs("button",{type:"button",className:`flat-terminal-wrapper__header-main ${Oe?"flat-terminal-wrapper__header-main--active":""}`,onClick:bt,onContextMenu:a=>{a.preventDefault(),a.stopPropagation(),we({x:a.clientX,y:a.clientY})},title:Oe?"Hide agent info":"Show agent info","aria-pressed":Oe,children:[e.jsx("span",{className:`flat-terminal-wrapper__header-avatar${u.status==="working"?" is-working":""}`,children:e.jsx(ba,{agent:u,size:28})}),e.jsxs("span",{className:"flat-terminal-wrapper__header-info",children:[e.jsx("span",{className:"flat-terminal-wrapper__header-name",children:u.name}),e.jsx("span",{className:"flat-terminal-wrapper__header-status",style:{color:va(u.status)},title:u.status==="error"&&u.lastError?u.lastError:void 0,children:u.status})]}),u.taskLabel&&e.jsxs("span",{className:"flat-terminal-wrapper__header-task",title:u.taskLabel,children:["📋 ",u.taskLabel]}),e.jsxs("span",{className:"flat-terminal-wrapper__header-model",children:[e.jsx("img",{src:wa(u.provider,"/"),alt:u.provider,className:"flat-terminal-wrapper__header-provider-icon",title:_a(u.provider)}),(()=>{const{model:a,effort:o}=Hn(u);return e.jsxs("span",{className:"flat-terminal-wrapper__header-model-chip",title:o?`Model: ${a} · Effort: ${o}`:`Model: ${a}`,children:[e.jsx("span",{className:"flat-terminal-wrapper__header-model-name",children:a}),o&&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:o})]})]})})()]})]}),e.jsxs("div",{className:"flat-terminal-wrapper__header-meta",children:[e.jsxs("div",{className:"flat-terminal-wrapper__view-mode",role:"group","aria-label":"Message view mode",children:[zn.map(a=>e.jsxs("button",{type:"button",className:`flat-terminal-wrapper__view-mode-btn ${!de&&p===a?"flat-terminal-wrapper__view-mode-btn--active":""}`,onClick:()=>{Qe(!1),b(a)},title:Fn[a],"aria-pressed":!de&&p===a,children:[e.jsx("span",{className:"flat-terminal-wrapper__view-mode-icon","aria-hidden":"true",children:Bn[a]}),e.jsx("span",{className:"flat-terminal-wrapper__view-mode-label",children:On[a]})]},a)),Je&&e.jsxs("button",{type:"button",className:`flat-terminal-wrapper__view-mode-btn ${de?"flat-terminal-wrapper__view-mode-btn--active":""}`,onClick:()=>Qe(a=>!a),title:"Classic TUI — attach to the live interactive claude session in a terminal","aria-pressed":de,children:[e.jsx("span",{className:"flat-terminal-wrapper__view-mode-icon","aria-hidden":"true",children:e.jsx(d,{name:"terminal",size:13})}),e.jsx("span",{className:"flat-terminal-wrapper__view-mode-label",children:"Classic TUI"})]})]}),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:oe,disabled:!T,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:ce,disabled:!Ee,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 ${Ce?"flat-terminal-wrapper__action-btn--active":""}`,onClick:rt,title:Ce?"Close search":"Search messages","aria-pressed":Ce,children:e.jsx(d,{name:Ce?"cross":"search",size:14})}),e.jsx("button",{type:"button",className:`flat-terminal-wrapper__action-btn flat-terminal-wrapper__action-btn--danger ${$e?"flat-terminal-wrapper__action-btn--confirm":""}`,onClick:()=>Pe.handleClick(Xt,()=>{var a;g.clearContext(r),(a=Ie.current)==null||a.historyLoader.clearHistory()}),title:$e?"Click again to confirm clear context":"Clear context",children:e.jsx(d,{name:$e?"question":"clear",size:14})}),e.jsx("button",{type:"button",className:`flat-terminal-wrapper__action-btn ${w?"flat-terminal-wrapper__action-btn--active":""}`,onClick:jt,title:w?"Hide git panel":"Show git changes","aria-pressed":w,children:e.jsx(d,{name:"git-branch",size:14})}),e.jsx("button",{type:"button",className:`flat-terminal-wrapper__action-btn ${De?"flat-terminal-wrapper__action-btn--active":""}`,onClick:Ct,title:De?"Hide buildings panel":"Show area buildings","aria-pressed":De,children:e.jsx(d,{name:"buildings",size:14})}),e.jsxs("div",{className:"flat-terminal-wrapper__more",ref:ge,children:[e.jsx("button",{type:"button",className:`flat-terminal-wrapper__action-btn ${qe?"flat-terminal-wrapper__action-btn--active":""}`,onClick:()=>B(a=>!a),title:"More actions","aria-expanded":qe,children:"⋮"}),qe&&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 ${O?"flat-terminal-wrapper__more-item--active":""}`,onClick:()=>{ct(),B(!1)},title:O?"Hide Debug Panel":"Show Debug Panel",children:[e.jsx(d,{name:"bug",size:14}),e.jsx("span",{children:O?"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(r),B(!1)},disabled:u.status!=="idle",title:u.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"})]}),nt&&e.jsxs("button",{type:"button",role:"menuitem",className:"flat-terminal-wrapper__more-item flat-terminal-wrapper__more-item--danger",onClick:()=>{R(r,Se),B(!1)},children:[e.jsx(d,{name:"crown",size:14}),e.jsxs("span",{children:["Clear ",Se," subordinate",Se===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(r),B(!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 ${N?"flat-terminal-wrapper__inspector-toggle--active":""}`,onClick:I,title:N?"Hide inspector panel":"Show inspector panel","aria-label":N?"Hide inspector panel":"Show inspector panel","aria-pressed":N,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})})]})]}),Be&&e.jsxs("div",{className:"flat-chat-actions-sheet-root",role:"presentation",children:[e.jsx("div",{className:"flat-chat-actions-sheet__backdrop",onClick:$}),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:u.name}),e.jsx("button",{type:"button",className:"flat-chat-actions-sheet__done",onClick:$,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 ${Ce?"is-active":""}`,onClick:()=>{rt(),$()},children:[e.jsx(d,{name:Ce?"cross":"search",size:20}),e.jsx("span",{children:Ce?"Close search":"Search"})]}),e.jsxs("button",{type:"button",role:"menuitem",className:`flat-chat-actions-sheet__item ${w?"is-active":""}`,onClick:()=>{jt(),$()},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 ${De?"is-active":""}`,onClick:()=>{Ct(),$()},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 ${O?"is-active":""}`,onClick:()=>{ct(),$()},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 ${$e?"is-armed":""}`,onClick:()=>Pe.handleClick(Xt,()=>{var a;g.clearContext(r),(a=Ie.current)==null||a.historyLoader.clearHistory(),$()}),children:[e.jsx(d,{name:$e?"question":"clear",size:18}),e.jsx("span",{children:$e?"Tap again to confirm clear":"Clear context"})]}),e.jsxs("button",{type:"button",role:"menuitem",className:"flat-chat-actions-sheet__row",disabled:u.status!=="idle",onClick:()=>{g.collapseContext(r),$()},children:[e.jsx(d,{name:"package",size:18}),e.jsx("span",{children:"Collapse context"})]}),nt&&e.jsxs("button",{type:"button",role:"menuitem",className:"flat-chat-actions-sheet__row flat-chat-actions-sheet__row--danger",onClick:()=>{R(r,Se),$()},children:[e.jsx(d,{name:"crown",size:18}),e.jsxs("span",{children:["Clear ",Se," subordinate",Se===1?"":"s"]})]}),e.jsxs("button",{type:"button",role:"menuitem",className:"flat-chat-actions-sheet__row flat-chat-actions-sheet__row--danger",onClick:()=>{g.killAgent(r),$()},children:[e.jsx(d,{name:"cross",size:18}),e.jsx("span",{children:"Remove agent"})]})]})]})]}),e.jsx(fn,{agent:u,onClick:A}),de&&Je?e.jsx(Tn,{agentId:r}):Te&&_t?e.jsx(hn,{ref:Ie,agentId:Te,agent:_t,viewMode:p,isOpen:!0,onImageClick:y,onFileClick:K,onBashClick:v,onViewMarkdown:H,keyboard:re,hasModalOpen:!1},Te):null,j&&J&&(()=>{var X,Q;const a=j.type,o={terminal:"terminal","pm2-logs":"scroll",database:"hard-drives",tests:"flask",http:"globe"},i=a==="terminal"&&!((X=J.terminalStatus)!=null&&X.url),m=!i;return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"guake-bottom-terminal-resize",onMouseDown:Dt,role:"separator","aria-orientation":"horizontal","aria-label":"Resize embedded panel"}),e.jsxs("div",{className:"flat-bottom-panel",role:"region","aria-label":`${J.name} panel`,style:{height:Rt},children:[e.jsxs("div",{className:"flat-bottom-panel__header",children:[e.jsxs("span",{className:"flat-bottom-panel__title",children:[e.jsx(d,{name:o[a],size:12}),e.jsx("span",{children:J.name}),i&&e.jsx("span",{className:"flat-bottom-panel__muted",children:"(starting...)"})]}),e.jsxs("span",{className:"flat-bottom-panel__header-actions",children:[a==="pm2-logs"&&e.jsxs(e.Fragment,{children:[e.jsx("input",{type:"text",className:"guake-bottom-terminal-filter",value:He,onChange:L=>Re(L.target.value),placeholder:"Filter logs","aria-label":`Filter logs for ${J.name}`,spellCheck:!1}),e.jsx("select",{className:"guake-bottom-terminal-retention",value:Ue===null?"unlimited":String(Ue),onChange:L=>{const st=L.target.value==="unlimited"?null:Number(L.target.value);$t(st),xn(st)},"aria-label":`Max log retention for ${J.name}`,children:gn.map(L=>e.jsx("option",{value:L===null?"unlimited":String(L),children:L===null?"Unlimited":`${L.toLocaleString()} lines`},L===null?"unlimited":L))}),e.jsx("button",{type:"button",className:"flat-bottom-panel__close",onClick:()=>g.clearStreamingLogs(j.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(j.buildingId,"restart"),title:"Restart",children:e.jsx(d,{name:"restart",size:12})})]}),m&&e.jsx("button",{type:"button",className:"flat-bottom-panel__close",onClick:()=>{ke(),it(j.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:ke,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"?(Q=J.terminalStatus)!=null&&Q.url?e.jsx(fa,{terminalUrl:J.terminalStatus.url,visible:!0}):e.jsx("div",{className:"flat-bottom-panel__placeholder",children:"Starting terminal..."}):a==="pm2-logs"?e.jsx(bn,{buildingId:j.buildingId,filterText:He,maxRetention:Ue}):a==="database"?e.jsx(_n,{building:J}):a==="tests"?e.jsx("div",{className:"tests-panel-host",children:e.jsx(wn,{building:J,autoFocusSearch:!1})}):e.jsx("div",{className:"http-requests-panel-host",children:e.jsx(vn,{building:J,autoFocusSearch:!1})})})]})]})})(),e.jsxs("div",{className:"flat-terminal-wrapper__statusbar",role:"contentinfo",children:[u.isDetached&&e.jsxs("span",{className:"flat-terminal-wrapper__detached",title:"Reattaching session...",children:[e.jsx(d,{name:"refresh",size:12}),e.jsx("span",{children:"Reattaching"})]}),be&&ft&&e.jsxs("span",{className:"flat-terminal-wrapper__cwd",title:`Open in file explorer: ${be}`,"aria-label":`Open ${be} in file explorer`,role:"button",tabIndex:0,onClick:()=>g.openFileExplorer(be),onKeyDown:a=>{(a.key==="Enter"||a.key===" ")&&(a.preventDefault(),g.openFileExplorer(be))},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:ft})]}),lt&<.map(({areaId:a,areaName:o,dir:i})=>{const m=wt.get(i),X=Le.has(i),Q=i.split("/").filter(Boolean).pop()||i;return e.jsxs("span",{className:"flat-terminal-wrapper__area-dir",title:`${o}: ${i}${m?` (${m.branch}${m.ahead?` ↑${m.ahead}`:""}${m.behind?` ↓${m.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:Q}),m&&e.jsxs(e.Fragment,{children:[e.jsxs("span",{className:"flat-terminal-wrapper__area-dir-branch",children:[e.jsx(d,{name:"git-branch",size:10})," ",m.branch]}),m.ahead>0&&e.jsxs("span",{className:"flat-terminal-wrapper__branch-ahead",title:`${m.ahead} ahead`,children:[e.jsx(d,{name:"arrow-up",size:9}),m.ahead]}),m.behind>0&&e.jsxs("span",{className:"flat-terminal-wrapper__branch-behind",title:`${m.behind} behind`,children:[e.jsx(d,{name:"arrow-down",size:9}),m.behind]}),e.jsx("span",{className:`flat-terminal-wrapper__area-fetch ${X?"flat-terminal-wrapper__area-fetch--fetching":""}`,title:"Git fetch",onClick:L=>{L.stopPropagation(),Fe(i)},children:e.jsx(d,{name:X?"hourglass":"download",size:12})})]})]},`${a}:${i}`)}),e.jsx(Rn,{agentId:r,disabled:((u==null?void 0:u.provider)??"claude")!=="claude"&&((u==null?void 0:u.provider)??"claude")!=="grok",contextSummary:ut?`Context: ${at}k / ${pt}k tokens (${kt}% used)`:void 0,children:e.jsxs("span",{className:"flat-terminal-wrapper__context",tabIndex:0,role:"button",onClick:()=>g.setContextModalAgentId(r),onKeyDown:a=>{(a.key==="Enter"||a.key===" ")&&(a.preventDefault(),g.setContextModalAgentId(r))},title:((u==null?void 0:u.provider)??"claude")!=="claude"&&((u==null?void 0:u.provider)??"claude")!=="grok"?ut?`Context usage: ${at}k / ${pt}k tokens (${kt}% used). Click to view stats.`:"Click to fetch context stats":void 0,children:[e.jsx("span",{className:"flat-terminal-wrapper__context-icon",children:e.jsx(d,{name:"dashboard",size:12})}),e.jsx("span",{className:"flat-terminal-wrapper__context-label",children:"Ctx:"}),e.jsx("span",{className:"flat-terminal-wrapper__context-bar",children:e.jsx("span",{className:"flat-terminal-wrapper__context-bar-fill",style:{width:`${ze}%`,backgroundColor:tt}})}),e.jsxs("span",{className:"flat-terminal-wrapper__context-tokens",style:{color:tt},children:[at,"k/",pt,"k"]}),e.jsxs("span",{className:"flat-terminal-wrapper__context-free",children:["(",xe,"% free)"]}),!ut&&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"}),pe.length>0&&e.jsx("span",{className:"flat-terminal-wrapper__buildings",role:"group","aria-label":"Area terminals",children:pe.map(a=>{const o=(j==null?void 0:j.buildingId)===a.id;return e.jsx("button",{type:"button",className:`flat-terminal-wrapper__building-btn ${o?"flat-terminal-wrapper__building-btn--active":""} ${a.hasUrl?"":"flat-terminal-wrapper__building-btn--offline"}`,title:`${o?"Hide":"Show"} terminal: ${a.name}${a.hasUrl?"":" (starting...)"}`,onClick:()=>{if(o){ke();return}if(a.hasUrl&>(a.id)==="modal"){it(a.id);return}a.hasUrl||g.sendBuildingCommand(a.id,"start"),Ge("terminal",a.id)},onContextMenu:i=>{i.preventDefault(),i.stopPropagation(),ve(a.id,{x:i.clientX,y:i.clientY})},children:e.jsx(d,{name:"terminal",size:14})},a.id)})}),je.length>0&&e.jsx("span",{className:"flat-terminal-wrapper__buildings",role:"group","aria-label":"Area PM2 logs",children:je.map(a=>{const o=(j==null?void 0:j.buildingId)===a.id;return e.jsx("button",{type:"button",className:`flat-terminal-wrapper__building-btn ${o?"flat-terminal-wrapper__building-btn--active":""}`,title:`${o?"Hide":"Show"} logs: ${a.name}`,onClick:()=>{o?ke():gt(a.id)==="modal"?it(a.id):Ge("pm2-logs",a.id)},onContextMenu:i=>{i.preventDefault(),i.stopPropagation(),ve(a.id,{x:i.clientX,y:i.clientY})},children:e.jsx(d,{name:"scroll",size:14})},a.id)})}),Z.length>0&&e.jsx("span",{className:"flat-terminal-wrapper__buildings",role:"group","aria-label":"Area databases",children:Z.map(a=>{const o=(j==null?void 0:j.buildingId)===a.id;return e.jsx("button",{type:"button",className:`flat-terminal-wrapper__building-btn ${o?"flat-terminal-wrapper__building-btn--active":""}`,title:`${o?"Hide":"Show"} database: ${a.name}`,onClick:()=>{o?ke():gt(a.id)==="modal"?it(a.id):Ge("database",a.id)},onContextMenu:i=>{i.preventDefault(),i.stopPropagation(),ve(a.id,{x:i.clientX,y:i.clientY})},children:e.jsx(d,{name:"hard-drives",size:14})},a.id)})}),se.length>0&&e.jsx("span",{className:"flat-terminal-wrapper__buildings",role:"group","aria-label":"Area tests",children:se.map(a=>{const o=(j==null?void 0:j.buildingId)===a.id;return e.jsx("button",{type:"button",className:`flat-terminal-wrapper__building-btn ${o?"flat-terminal-wrapper__building-btn--active":""} ${a.working?"flat-terminal-wrapper__building-btn--tests-working":""}`,title:a.working?`Running tests: ${a.name}`:`${o?"Hide":"Show"} tests: ${a.name}`,onClick:()=>{o?ke():gt(a.id)==="modal"?it(a.id):Ge("tests",a.id)},onContextMenu:i=>{i.preventDefault(),i.stopPropagation(),ve(a.id,{x:i.clientX,y:i.clientY})},children:e.jsx(d,{name:"flask",size:14})},a.id)})}),ie.length>0&&e.jsx("span",{className:"flat-terminal-wrapper__buildings",role:"group","aria-label":"Area HTTP requests",children:ie.map(a=>{const o=(j==null?void 0:j.buildingId)===a.id;return e.jsx("button",{type:"button",className:`flat-terminal-wrapper__building-btn ${o?"flat-terminal-wrapper__building-btn--active":""}`,title:`${o?"Hide":"Show"} HTTP requests: ${a.name}`,onClick:()=>{o?ke():gt(a.id)==="modal"?it(a.id):Ge("http",a.id)},onContextMenu:i=>{i.preventDefault(),i.stopPropagation(),ve(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(jn,{})})]}),w&&e.jsx(Cn,{agentId:r,agents:Xe,onClose:Bt,branchInfoMap:wt,fetchRemote:Fe,fetchingDirs:Le,onResizeStart:a=>ot(a,"right")}),De&&e.jsx(kn,{agentId:r,onClose:dt}),O&&e.jsx(Nn,{agentId:r,onClose:Ot})]})}),Vn={groups:[],gridCols:1,gridRows:1,positions:new Map};function Zn({onAgentClick:c,onBuildingClick:r,onBuildingDoubleClick:p,onBuildingPopup:b,onAreaContextMenu:N,onOpenSpawnModal:I,onOpenBossSpawnModal:A,onOpenAreaModal:y}){const{t:K}=Kt(["common"]),v=$a(),H=Ra(),[R,re]=s.useState(null),[T,Ee]=s.useState(null),[oe,ce]=s.useState(null);ha("flatview-image-modal",R!==null,()=>re(null));const[Oe,bt]=s.useState(null),[we,ve]=s.useState(null),[u,D]=s.useState(null),[Me,Ie]=s.useState(null),[Ze,Te]=s.useState(!1),Lt=s.useCallback(()=>{Te(t=>!t)},[]),_t=s.useCallback(()=>{Te(!1)},[]),[Je,de]=s.useState(()=>{const t=ta(M.VIEW_MODE);return t==="simple"||t==="chat"||t==="advanced"?t:"simple"}),Qe=s.useCallback(t=>{de(t),aa(M.VIEW_MODE,t)},[]);s.useEffect(()=>{const t=n=>{if(n.key!==M.VIEW_MODE)return;const l=n.newValue;(l==="simple"||l==="chat"||l==="advanced")&&de(l)};return window.addEventListener("storage",t),()=>window.removeEventListener("storage",t)},[]);const[Be,ue]=s.useState(()=>Yt(M.FLAT_INSPECTOR_OPEN,!1)),[$,me]=s.useState(!1),lt=s.useCallback(()=>me(t=>!t),[]),wt=s.useCallback(()=>me(!1),[]);s.useEffect(()=>{window.dispatchEvent(new CustomEvent("tide-flat-agents-drawer-state",{detail:{open:$}}))},[$]),s.useEffect(()=>{window.dispatchEvent(new CustomEvent("tide-flat-inspector-state",{detail:{open:Be}}))},[Be]),s.useEffect(()=>{const t=()=>me(k=>!k),n=()=>{ue(k=>{const E=!k;return _e(M.FLAT_INSPECTOR_OPEN,E),E})},l=()=>{me(!1),ue(!1),_e(M.FLAT_INSPECTOR_OPEN,!1)},x=()=>me(!1),_=()=>{ue(!1),_e(M.FLAT_INSPECTOR_OPEN,!1)};return window.addEventListener("tide-toggle-flat-agents-drawer",t),window.addEventListener("tide-toggle-flat-inspector",n),window.addEventListener("tide-close-flat-side-views",l),window.addEventListener("tide-close-flat-agents-drawer-only",x),window.addEventListener("tide-close-flat-inspector-only",_),()=>{window.removeEventListener("tide-toggle-flat-agents-drawer",t),window.removeEventListener("tide-toggle-flat-inspector",n),window.removeEventListener("tide-close-flat-side-views",l),window.removeEventListener("tide-close-flat-agents-drawer-only",x),window.removeEventListener("tide-close-flat-inspector-only",_)}},[]);const Fe=s.useRef(null),Le=s.useRef(null),[pe,je]=s.useState(()=>{const t=na(M.FLAT_MIDDLE_WIDTH,0);return t>=Tt?t:null}),[Z,We]=s.useState(()=>{const t=na(M.FLAT_INSPECTOR_WIDTH,0);return t>=Vt?t:null}),se=s.useCallback(t=>{if(typeof window>"u")return t;const n=Z!==null?It+Z:0,l=window.innerWidth-ua-It-da-n;return Math.max(Tt,Math.min(Math.max(l,Tt),t))},[Z]),ie=s.useCallback(t=>{var _;if(typeof window>"u")return t;const n=(_=Fe.current)==null?void 0:_.querySelector(".flat-middle"),l=(n==null?void 0:n.getBoundingClientRect().width)??Tt,x=window.innerWidth-ua-l-It-da-It;return Math.max(Vt,Math.min(Math.max(x,Vt),t))},[]);s.useEffect(()=>{if(pe===null&&Z===null)return;const t=()=>{je(n=>{if(n===null)return n;const l=se(n);return l===n?n:l}),We(n=>{if(n===null)return n;const l=ie(n);return l===n?n:l})};return window.addEventListener("resize",t),()=>window.removeEventListener("resize",t)},[pe,Z,se,ie]);const Pt=s.useCallback(t=>{var l;if(t.button!==0)return;const n=(l=Fe.current)==null?void 0:l.querySelector(".flat-middle");n&&(t.currentTarget.setPointerCapture(t.pointerId),Le.current={kind:"middle",startX:t.clientX,startWidth:n.getBoundingClientRect().width,pointerId:t.pointerId},document.body.classList.add("flat-splitter-dragging"))},[]),Ce=s.useCallback(t=>{var l;if(t.button!==0)return;const n=(l=Fe.current)==null?void 0:l.querySelector(".flat-inspector");n&&(t.currentTarget.setPointerCapture(t.pointerId),Le.current={kind:"inspector",startX:t.clientX,startWidth:n.getBoundingClientRect().width,pointerId:t.pointerId},document.body.classList.add("flat-splitter-dragging"))},[]),rt=s.useCallback(t=>{const n=Le.current;if(!n||t.pointerId!==n.pointerId)return;const l=t.clientX-n.startX;n.kind==="middle"?je(se(n.startWidth+l)):We(ie(n.startWidth-l))},[se,ie]),Pe=s.useCallback(t=>{const n=Le.current;if(!n||t.pointerId!==n.pointerId)return;try{t.currentTarget.releasePointerCapture(t.pointerId)}catch{}if(Le.current=null,document.body.classList.remove("flat-splitter-dragging"),!(Math.abs(t.clientX-n.startX)>2))return;const x=t.clientX-n.startX;if(n.kind==="middle"){const _=se(n.startWidth+x);je(_),Mt(M.FLAT_MIDDLE_WIDTH,_)}else{const _=ie(n.startWidth-x);We(_),Mt(M.FLAT_INSPECTOR_WIDTH,_)}},[se,ie]),$e=s.useCallback(()=>{je(null),Mt(M.FLAT_MIDDLE_WIDTH,0)},[]),j=s.useCallback(()=>{We(null),Mt(M.FLAT_INSPECTOR_WIDTH,0)},[]),[te,J]=s.useState(()=>ta(M.FLAT_INSPECTOR_VIEW)==="tracking"?"tracking":"agent"),He=s.useCallback(t=>{J(t),aa(M.FLAT_INSPECTOR_VIEW,t)},[]),Re=s.useCallback(()=>{ue(t=>{const n=!t;return _e(M.FLAT_INSPECTOR_OPEN,n),n})},[]),Ue=s.useCallback(()=>{ue(!1),_e(M.FLAT_INSPECTOR_OPEN,!1)},[]),$t=s.useCallback(()=>{He("tracking"),ue(!0),_e(M.FLAT_INSPECTOR_OPEN,!0)},[He]),z=Da(),Ge=s.useCallback((t,n)=>{re({url:t,name:n})},[]),ke=s.useCallback((t,n)=>{Ee({command:t,output:n,isLive:!1})},[]),Rt=s.useCallback((t,n)=>{var _;const l=H.size>0?Array.from(H)[0]:null,x=l?(_=g.getState().agents.get(l))==null?void 0:_.cwd:void 0;g.setFileViewerPath(t,n,x)},[H]),Dt=s.useCallback(t=>{ce(t)},[]),zt=s.useCallback((t,n)=>{bt({agentId:t,count:n})},[]),ot=s.useCallback(t=>{p?p(t):r(t)},[r,p]),w=s.useMemo(()=>H.size>0?Array.from(H)[0]:null,[H]),vt=s.useCallback(t=>{w&&ve({agentId:w,position:t})},[w]),De=s.useCallback((t,n)=>{D({buildingId:t,position:n})},[]);s.useEffect(()=>{Te(!1)},[w]);const fe=s.useRef([]),O=s.useRef(-1),Ve=s.useRef(!1),ct=s.useRef(null),[Ot,jt]=s.useState(!1),[Ct,Bt]=s.useState(!1),dt=s.useRef(!1),Xe=s.useRef(null),he=s.useRef(!1),Ne=s.useMemo(()=>new Set(v.map(t=>t.id)),[v]),qe=s.useMemo(()=>{const t=new Map(v.map(l=>[l.id,l])),n=new Map;for(const l of v)if((l.isBoss||l.class==="boss")&&l.subordinateIds&&l.subordinateIds.length>0){const x=l.subordinateIds.map(_=>t.get(_)).filter(_=>_!==void 0);x.length>0&&n.set(l.id,x)}return n},[v]),B=s.useCallback(()=>{const t=fe.current,n=O.current;jt(n>0),Bt(n>=0&&n<t.length-1)},[]),ge=s.useCallback(t=>{const n=fe.current;if(n.length===0)return;let l=O.current+t;for(;l>=0&&l<n.length;){const x=n[l];if(Ne.has(x)){Ve.current=!0,O.current=l,B(),g.selectAgent(x);return}l+=t}},[Ne,B]),ye=s.useCallback(()=>ge(-1),[ge]),ut=s.useCallback(()=>ge(1),[ge]);En(s.useCallback(()=>{const t=fe.current,n=O.current;return t.length>0&&n>0?(ge(-1),"handled"):"exit"},[ge]));const et=s.useCallback((t,n)=>{if(typeof window>"u")return;const l=window.history.state,_={...typeof l=="object"&&l!==null?l:{},__flatAgentNav:{agentId:t}};n==="replace"?window.history.replaceState(_,"",window.location.href):window.history.pushState(_,"",window.location.href)},[]);s.useEffect(()=>{if(!w){dt.current=!1,Xe.current=null;return}if(!dt.current){et(w,"replace"),dt.current=!0,Xe.current=w;return}if(he.current){he.current=!1,Xe.current=w;return}Xe.current!==w&&(et(w,"push"),Xe.current=w)},[w,et]),s.useEffect(()=>{const t=n=>{var k,E;const l=(E=(k=n.state)==null?void 0:k.__flatAgentNav)==null?void 0:E.agentId;if(!l||typeof l!="string"||!Ne.has(l)||l===w)return;he.current=!0,Ve.current=!0;const x=fe.current,_=x.lastIndexOf(l);_>=0?O.current=_:(x.push(l),O.current=x.length-1),B(),g.selectAgent(l)};return window.addEventListener("popstate",t),()=>window.removeEventListener("popstate",t)},[Ne,w,B]),s.useEffect(()=>{if(!w){fe.current=[],O.current=-1,B();return}if(ct.current=w,Ve.current){Ve.current=!1,B();return}const t=fe.current,n=O.current;if(n>=0&&t[n]===w){B();return}const l=n<t.length-1?t.slice(0,n+1):t.slice();l.push(w),l.length>100&&l.shift(),fe.current=l,O.current=l.length-1,B()},[w,B]);const mt=s.useCallback(t=>{c(t),me(!1)},[c]),Ft=w??"",ze=s.useCallback(()=>{},[]),kt=s.useCallback(t=>{mt(t)},[mt]),xe=Be,[tt,at]=s.useState(xe),[pt,be]=s.useState(xe);s.useEffect(()=>{if(xe){at(!0);return}be(!1);const t=setTimeout(()=>at(!1),240);return()=>clearTimeout(t)},[xe]),s.useEffect(()=>{if(!tt||!xe)return;let t=0;const n=requestAnimationFrame(()=>{t=requestAnimationFrame(()=>be(!0))});return()=>{cancelAnimationFrame(n),cancelAnimationFrame(t)}},[tt,xe]);const ft=s.useRef(null);s.useEffect(()=>{if(w)return;const t=n=>{if(n.key!==" "&&n.key!=="Backspace")return;const l=n.target;if(l.tagName==="INPUT"||l.tagName==="TEXTAREA"||l.isContentEditable)return;const x=ct.current;!x||!Ne.has(x)||(n.preventDefault(),g.selectAgent(x))};return document.addEventListener("keydown",t),()=>document.removeEventListener("keydown",t)},[w,Ne]);const[Se,nt]=s.useState(new Set),Nt=s.useCallback(t=>{nt(n=>{const l=new Set(n);return l.has(t)?l.delete(t):l.add(t),l})},[]),yt=s.useCallback(t=>{nt(new Set(t))},[]),[a,o]=s.useState(()=>typeof window<"u"&&window.matchMedia("(max-width: 768px)").matches);s.useEffect(()=>{if(typeof window>"u")return;const t=window.matchMedia("(max-width: 768px)"),n=l=>o(l.matches);return t.addEventListener("change",n),()=>t.removeEventListener("change",n)},[]);const[i,m]=s.useState(null),X=s.useCallback(t=>{m(n=>n===t?null:t)},[]),Q=ga(),L=xa(),[st]=za(),ae=s.useMemo(()=>{if(w)return Vn;const t=new Map,n=[];for(const h of v){const C=g.getAreaForAgent(h.id);if(!sa((C==null?void 0:C.id)??null))continue;if(!C||C.archived){n.push(h);continue}const P=t.get(C.id);P?P.push(h):t.set(C.id,[h])}const l=new Map,x=[];for(const h of L.values()){let C=!1;for(const P of Q.values())if(!P.archived&&ia(P.id)&&g.isPositionInArea(h.position,P)){const le=l.get(P.id);le?le.push(h):l.set(P.id,[h]),C=!0;break}!C&&sa(null)&&x.push(h)}const _=[];for(const[,h]of Q){if(h.archived||!ia(h.id))continue;const C=t.get(h.id),P=l.get(h.id)??[];(C&&C.length>0||P.length>0)&&_.push({area:h,agents:C??[],buildings:P})}(n.length>0||x.length>0)&&_.push({area:{id:"__unassigned__",name:"Unassigned",color:"#6272a4",center:{x:0,z:0},type:"circle",radius:0,directories:[],archived:!1,assignedAgentIds:[],zIndex:0},agents:n,buildings:x});const k=_.filter(h=>h.area.id!=="__unassigned__"),E=_.filter(h=>h.area.id==="__unassigned__");let G=1,F=1;const f=new Map;if(k.length>1){let h=1/0,C=-1/0,P=1/0,le=-1/0;for(const q of k)h=Math.min(h,q.area.center.x),C=Math.max(C,q.area.center.x),P=Math.min(P,q.area.center.z),le=Math.max(le,q.area.center.z);const Ae=C-h||1,At=le-P||1;if(k.length<=4){G=k.length,F=1;const q=[...k].sort((Y,Wt)=>Y.area.center.x-Wt.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=[...k].sort((S,W)=>S.area.center.x-W.area.center.x),Y=[];for(let S=1;S<q.length;S++)Y.push(q[S].area.center.x-q[S-1].area.center.x);const Wt=Y.reduce((S,W)=>S+W,0)/Y.length||1;let Zt=1;for(const S of Y)S>Wt*1.3&&Zt++;G=Math.max(2,Math.min(Zt,k.length));const Ht=[...k].sort((S,W)=>S.area.center.z-W.area.center.z),Et=[];for(let S=1;S<Ht.length;S++)Et.push(Ht[S].area.center.z-Ht[S-1].area.center.z);const ka=Et.reduce((S,W)=>S+W,0)/Et.length||1;let Jt=1;for(const S of Et)S>ka*1.3&&Jt++;F=Math.max(2,Math.min(Jt,k.length)),G=Math.max(G,Math.ceil(k.length/F)),F=Math.max(F,Math.ceil(k.length/G));const Na=Ae/G,ya=At/F,Ut=new Set;for(const S of k){let W=Math.min(G-1,Math.max(0,Math.floor((S.area.center.x-h)/Na))),Ke=Math.min(F-1,Math.max(0,Math.floor((S.area.center.z-P)/ya))),ht=`${Ke},${W}`,Qt=0;const Sa=F*G;for(;Ut.has(ht)&&Qt<Sa;)W++,W>=G&&(W=0,Ke=(Ke+1)%F),ht=`${Ke},${W}`,Qt++;Ut.has(ht)&&(Ke=F,W=0,ht=`${Ke},${W}`,F++),Ut.add(ht),f.set(S.area.id,{row:Ke+1,col:W+1})}}}const ee=h=>{h.sort((C,P)=>{var Ae,At,q,Y;const le=(((Ae=C.position)==null?void 0:Ae.z)??0)-(((At=P.position)==null?void 0:At.z)??0);return le!==0?le:(((q=C.position)==null?void 0:q.x)??0)-(((Y=P.position)==null?void 0:Y.x)??0)})};for(const h of k)ee(h.agents);for(const h of E)ee(h.agents);const V=[...k,...E].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(),V.forEach((h,C)=>{f.set(h.area.id,{row:Math.floor(C/G)+1,col:C%G+1})}),F=Math.max(1,Math.ceil(V.length/G)),{groups:V,gridCols:G,gridRows:F,positions:f}},[v,Q,L,st,w]),Ye=s.useMemo(()=>{let t=0,n=0;for(const l of ae.groups)t+=l.agents.length,n+=l.agents.filter(x=>x.status==="working").length;return{areaCount:ae.groups.length,agentCount:t,workingCount:n}},[ae]),ne=s.useMemo(()=>{if(!we)return[];const t=v.find(n=>n.id===we.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:()=>{Ie({agentId:t.id,name:t.name})}}]:[]},[we,v,c]),U=s.useMemo(()=>{var k;if(!u)return[];const t=L.get(u.buildingId);if(!t)return[];const n=[],l=t.type==="server"||t.type==="docker"||t.type==="terminal",x=t.status==="running",_=t.type==="boss";if(n.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"&&((k=t.pm2)!=null&&k.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:()=>ot(t.id)}),l&&(x||n.push({id:"start",label:"Start",icon:e.jsx(d,{name:"play",size:14}),onClick:()=>g.sendBuildingCommand(t.id,"start")}),x&&(n.push({id:"restart",label:"Restart",icon:e.jsx(d,{name:"refresh",size:14}),onClick:()=>g.sendBuildingCommand(t.id,"restart")}),n.push({id:"stop",label:"Stop",icon:e.jsx(d,{name:"stop",size:14}),onClick:()=>g.sendBuildingCommand(t.id,"stop")}))),_&&t.subordinateBuildingIds&&t.subordinateBuildingIds.length>0&&(n.push({id:"start-all",label:"Start All Subordinates",icon:e.jsx(d,{name:"launch",size:14}),onClick:()=>{for(const E of t.subordinateBuildingIds)g.sendBuildingCommand(E,"start")}}),n.push({id:"stop-all",label:"Stop All Subordinates",icon:e.jsx(d,{name:"pause",size:14}),onClick:()=>{for(const E of t.subordinateBuildingIds)g.sendBuildingCommand(E,"stop")}}),n.push({id:"restart-all",label:"Restart All Subordinates",icon:e.jsx(d,{name:"restart",size:14}),onClick:()=>{for(const E of t.subordinateBuildingIds)g.sendBuildingCommand(E,"restart")}})),l&&n.push({id:"health-check",label:"Health Check",icon:e.jsx(d,{name:"health",size:14}),onClick:()=>g.sendBuildingCommand(t.id,"healthCheck")}),n.push({id:"divider-edit",label:"",divider:!0,onClick:()=>{}}),n.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}}))}}),n.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 E of t.urls)n.push({id:`url-${E.label}`,label:E.label,icon:e.jsx(d,{name:"link",size:14}),onClick:()=>window.open(E.url,"_blank","noopener,noreferrer")});return n.push({id:"divider-danger",label:"",divider:!0,onClick:()=>{}}),n.push({id:"delete",label:"Delete Building",icon:e.jsx(d,{name:"trash",size:14}),danger:!0,onClick:()=>g.deleteBuilding(t.id)}),n},[u,L,ot]),St=s.useCallback(t=>{nt(new Set([t])),requestAnimationFrame(()=>{const n=ft.current;if(!n)return;const l=n.querySelector(`[data-area-id="${t}"]`);if(!l)return;const x=n.getBoundingClientRect(),k=l.getBoundingClientRect().top-x.top+n.scrollTop-8;n.scrollTo({top:Math.max(0,k),behavior:"smooth"})})},[]);return e.jsxs("div",{ref:Fe,className:`flat-view ${xe?"flat-view--with-inspector":""} ${w?"flat-view--has-chat":""} ${$?"flat-view--mobile-sidebar-open":""}`,style:(()=>{if(pe===null&&Z===null)return;const t={};return pe!==null&&(t["--flat-middle-width"]=`${pe}px`),Z!==null&&(t["--flat-inspector-width"]=`${Z}px`),t})(),children:[$&&e.jsx("div",{className:"flat-mobile-sidebar-backdrop",onClick:wt,"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:I,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:y,title:"Create new area",children:"+ Area"})]})}),e.jsx("div",{className:"flat-middle__content",children:e.jsx(Oa,{activeAgentId:Ft,onClose:ze,onSelectAgent:kt,expandedAreas:Se,onToggleArea:Nt,onSetExpandedAreas:yt,agentListRef:ft})})]}),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:Pt,onPointerMove:rt,onPointerUp:Pe,onPointerCancel:Pe,onDoubleClick:$e}),e.jsxs("div",{className:"flat-right",children:[e.jsxs("button",{type:"button",className:"flat-mobile-sidebar-toggle","aria-label":$?"Close agents sidebar":"Open agents sidebar","aria-expanded":$,onClick:lt,children:[e.jsx(d,{name:"list",size:18}),e.jsx("span",{className:"flat-mobile-sidebar-toggle__label",children:"Agents"})]}),w?e.jsx(Gn,{agentId:w,terminalViewMode:Je,onTerminalViewModeChange:Qe,inspectorOpen:Be,onToggleInspector:Re,onShowTaskBoard:$t,onImageClick:Ge,onFileClick:Rt,onBashClick:ke,onViewMarkdown:Dt,onRequestClearSubordinates:zt,keyboard:z,canNavigateBack:Ot,canNavigateForward:Ct,onNavigateBack:ye,onNavigateForward:ut,agentInfoOpen:Ze,onToggleAgentInfo:Lt,onHeaderContextMenu:vt,onBuildingContextMenu:De}):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:[Ye.areaCount," areas"]}),e.jsxs("span",{children:[Ye.agentCount," agents"]}),Ye.workingCount>0&&e.jsxs("span",{className:"flat-map__stats-working",children:[e.jsx("span",{className:"flat-map__stats-dot","aria-hidden":"true"}),Ye.workingCount," working"]})]}),e.jsx(Dn,{className:"flat-map__view-mode"})]}),e.jsx("div",{className:"flat-map__grid",style:{gridTemplateColumns:a?"repeat(2, minmax(0, 1fr))":`repeat(${ae.gridCols}, 1fr)`},children:ae.groups.length===0?e.jsx("div",{className:"flat-map__empty",children:e.jsx("span",{children:"No areas or agents yet"})}):(a?[...ae.groups].sort((n,l)=>{const x=ae.positions.get(n.area.id),_=ae.positions.get(l.area.id);return!x&&!_?0:x?_?x.row-_.row||x.col-_.col:-1:1}):ae.groups).map(n=>{var F;const l=n.area.id,x=ae.positions.get(l),_=n.agents.filter(f=>f.status==="working").length,k=_>0,E=a&&i!==l,G=a&&!E;return e.jsxs("div",{className:`flat-map-area-card${k?" flat-map-area-card--working":""}${E?" flat-map-area-card--collapsed":""}${G?" flat-map-area-card--expanded":""}`,style:{"--area-color":n.area.color,gridRow:a||x==null?void 0:x.row,gridColumn:a||x==null?void 0:x.col},onContextMenu:f=>{N&&(f.preventDefault(),f.stopPropagation(),N(l,{x:f.clientX,y:f.clientY}))},children:[e.jsxs("button",{type:"button",className:"flat-map-area-card__header",onClick:()=>a?X(l):St(l),title:a?E?`Expand ${n.area.name}`:`Collapse ${n.area.name}`:`Focus ${n.area.name} in left panel`,"aria-expanded":a?!E:void 0,children:[e.jsx("span",{className:"flat-map-area-card__color",style:{background:n.area.color}}),((F=n.area.logo)==null?void 0:F.filename)&&e.jsx("img",{className:"flat-map-area-card__logo",src:An(n.area.logo.filename),alt:"","aria-hidden":"true",onError:f=>{f.currentTarget.style.display="none"}}),e.jsx("span",{className:"flat-map-area-card__name",children:n.area.name}),e.jsxs("span",{className:"flat-map-area-card__count",title:`${n.agents.length} agent${n.agents.length===1?"":"s"}`,"aria-label":`${n.agents.length} agent${n.agents.length===1?"":"s"}`,children:[e.jsx(d,{name:"users",size:10}),n.agents.length]}),k&&e.jsxs("span",{className:"flat-map-area-card__working",title:`${_} working agent${_===1?"":"s"}`,"aria-label":`${_} working agent${_===1?"":"s"}`,children:[e.jsxs("span",{className:"flat-map-area-card__working-bars","aria-hidden":"true",children:[e.jsx("i",{}),e.jsx("i",{}),e.jsx("i",{})]}),e.jsx("span",{className:"flat-map-area-card__working-count",children:_})]}),a&&e.jsx(d,{name:E?"caret-down":"caret-up",size:11,className:"flat-map-area-card__caret"})]}),e.jsx("div",{className:"flat-map-area-card__agents",children:n.agents.map(f=>{const ee=f.isBoss||f.class==="boss",V=ee?qe.get(f.id):void 0,h=Ba(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)`,le=f.latestTodos&&f.latestTodos.length>0||V&&V.length>0;return e.jsx(Fa,{todos:f.latestTodos,subordinates:V,position:"top",children:e.jsxs("button",{type:"button",className:`flat-map-agent-chip ${f.status}`,onClick:()=>c(f.id),onContextMenu:Ae=>{Ae.preventDefault(),Ae.stopPropagation(),ve({agentId:f.id,position:{x:Ae.clientX,y:Ae.clientY}})},title:le?void 0:`${ee?"Boss · ":""}Open chat with ${f.name}
|
|
2
|
-
${P}`,children:[e.jsx(ba,{agent:f,size:16}),ee&&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("img",{src:wa(f.provider,"/"),alt:f.provider,className:"flat-map-agent-chip__provider-icon",title:_a(f.provider)}),e.jsx("span",{className:"flat-map-agent-chip__dot",style:{backgroundColor:va(f.status)}}),f.latestTodos&&f.latestTodos.length>0&&e.jsx(Wa,{todos:f.latestTodos,maxDots:6}),ee&&V&&V.length>0&&e.jsx(Ha,{subordinates:V,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)})}),n.area.directories.length>0&&e.jsx("div",{className:"flat-map-area-card__folders",role:"group","aria-label":`${n.area.name} folders`,children:n.area.directories.map(f=>{const ee=f.split("/").filter(Boolean).pop()||f;return e.jsxs("button",{type:"button",className:"flat-map-folder-chip",onClick:V=>{V.stopPropagation(),g.openFileExplorerForAreaFolder(l,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:ee})]},f)})}),n.buildings.length>0&&e.jsx("div",{className:"flat-map-area-card__buildings",children:n.buildings.map(f=>{var V;const ee=(V=Ua[f.type])==null?void 0:V.color;return e.jsxs("button",{type:"button",className:`flat-map-building-chip flat-map-building-chip--${f.status}`,style:ee?{"--building-type-color":ee}:void 0,onClick:h=>{if(b){const C=h.currentTarget.getBoundingClientRect();b(f.id,{x:C.right,y:C.top+C.height/2})}else ot(f.id)},onContextMenu:h=>{h.preventDefault(),h.stopPropagation(),
|
|
1
|
+
import{r as s,aP as Sa,aQ as aa,K as ma,aR as pa,j as e,aS as fa,aT as Ea,u as Jt,aU as Ma,aV as Ia,aW as Ta,aX as La,aY as Pa,an as $a,ae as Da,av as ha,m as Gt,S as y,w as Vt,aZ as Zt,a_ as na,a$ as Mt,b0 as _e,b1 as Ra,s as g,_ as ga,f as xa,b2 as za,b3 as sa,b4 as ia,I as d,b5 as Oa,ay as Ba,b6 as Fa,n as ba,b7 as _a,b8 as wa,b9 as va,ba as Wa,bb as Ha,bc as Ua,ad as Ga,bd as Va,be as Xa,bf as qa,aB as Ya,aC as Ka,aD as Za,bg as Ja,bh as Qa,bi as la,X as en,R as tn,E as ra,bj as an,bk as nn,bl as sn,bm as ln,bn as rn,bo as on,bp as cn,bq as dn,br as un,bs as mn,x as pn,bt as fn,bu as hn,bv as gn,bw as xn,bx as it,by as bn,bz as _n,bA as wn,bB as vn,bC as gt,bD as jn,bE as Cn,bF as kn,bG as Nn,p as yn,q as oa,o as An}from"./main-CvV6YpbU.js";import{g as Sn}from"./area-logos-DRbo7OkE.js";import"./vendor-react--Eh9ivFN.js";import"./vendor-three-3OKhI9bz.js";function En(c){const r=s.useRef(c);r.current=c,s.useEffect(()=>{if(!Sa())return;let p=null,b=!1;return aa.addListener("backButton",()=>{r.current()==="exit"&&aa.exitApp()}).then(N=>{b?N.remove():p=N}),()=>{b=!0,p&&(p.remove(),p=null)}},[])}async function Mn(c){const r=ma(),p=await fetch(`${pa()}/api/agents/${c}/terminal`,{method:"POST",headers:{Authorization:`Bearer ${r}`}});if(!p.ok){const b=await p.json().catch(()=>({}));throw new Error((b==null?void 0:b.error)||`Failed to start terminal (${p.status})`)}return p.json()}async function In(c){const r=ma();await fetch(`${pa()}/api/agents/${c}/terminal`,{method:"DELETE",headers:{Authorization:`Bearer ${r}`}})}const xt=new Map;function Tn({agentId:c}){const[r,p]=s.useState(null),[b,N]=s.useState(null);return s.useEffect(()=>{let I=!1;const E=xt.get(c);return E&&(clearTimeout(E),xt.delete(c)),p(null),N(null),Mn(c).then(A=>{I||p(A.url)}).catch(A=>{I||N(A instanceof Error?A.message:"Failed to start terminal")}),()=>{I=!0;const A=xt.get(c);A&&clearTimeout(A),xt.set(c,setTimeout(()=>{xt.delete(c),In(c)},2500))}},[c]),b?e.jsx("div",{className:"flat-classic-terminal flat-classic-terminal--message",children:e.jsx("span",{children:b})}):r?e.jsx("div",{className:"flat-classic-terminal",children:e.jsx(fa,{terminalUrl:r,visible:!0})}):e.jsx("div",{className:"flat-classic-terminal flat-classic-terminal--message",children:e.jsx("span",{children:"Attaching to interactive session…"})})}const Xt=new Map,Ln=6e4;function ca(c){return Number.isFinite(c)?Math.abs(c)>=1e3?c.toLocaleString(void 0,{maximumFractionDigits:0}):c.toLocaleString(void 0,{maximumFractionDigits:2}):String(c)}function Pn(c,r){var N,I,E;const p=[];if(!c.rateLimits)return p;if(c.provider==="claude"){const A=c,K=[{key:"fiveHour",label:r("terminal:usage.currentSession"),window:A.rateLimits.fiveHour},{key:"sevenDay",label:r("terminal:usage.currentWeekAll"),window:A.rateLimits.sevenDay},{key:"sevenDayOpus",label:r("terminal:usage.currentWeekOpus"),window:A.rateLimits.sevenDayOpus},{key:"sevenDayFable",label:r("terminal:usage.currentWeekFable"),window:A.rateLimits.sevenDayFable}];for(const v of K)(v.window||v.key==="sevenDayFable")&&p.push(v);return p}const b=c;return(N=b.rateLimits)!=null&&N.weekly&&p.push({key:"weekly",label:r("terminal:usage.weeklyLimit"),window:b.rateLimits.weekly}),(I=b.rateLimits)!=null&&I.monthly&&p.push({key:"monthly",label:r("terminal:usage.monthlyLimit"),window:b.rateLimits.monthly}),(E=b.rateLimits)!=null&&E.onDemand&&p.push({key:"onDemand",label:r("terminal:usage.onDemandLimit"),window:b.rateLimits.onDemand}),p}function $n({agentId:c,contextSummary:r}){const{t:p}=Jt(["terminal","common"]),[b,N]=s.useState(()=>{var D;return((D=Xt.get(c))==null?void 0:D.snapshot)??null}),[I,E]=s.useState(!1),[A,K]=s.useState(null),v=s.useRef(0);s.useEffect(()=>{const D=Xt.get(c);if(D&&Date.now()-D.fetchedAt<Ln){N(D.snapshot);return}const re=++v.current;E(!0),K(null),Ma(c).then(T=>{re===v.current&&(Xt.set(c,{snapshot:T,fetchedAt:Date.now()}),N(T),E(!1))}).catch(T=>{re===v.current&&(K(T.message||"Failed to load plan limits"),E(!1))})},[c]);const H=b?Pn(b,p):[];return e.jsxs("div",{className:"plan-limits-tooltip",children:[r&&e.jsx("div",{className:"plan-limits-tooltip__context",children:r}),e.jsx("div",{className:"plan-limits-tooltip__title",children:p("terminal:usage.limits")}),I&&!b&&e.jsxs("div",{className:"plan-limits-tooltip__muted",children:[p("common:status.loading"),"…"]}),!I&&A&&!b&&e.jsx("div",{className:"plan-limits-tooltip__muted",children:p("terminal:usage.limitsError",{message:A})}),H.length>0?e.jsx("div",{className:"plan-limits-tooltip__gauges",children:H.map(({key:D,label:re,window:T})=>{const Ee=T?Math.max(0,Math.min(100,T.utilization)):0,oe=Ta(Ee),ce=T!=null&&typeof T.used=="number"&&typeof T.limit=="number"&&Number.isFinite(T.used)&&Number.isFinite(T.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:re}),e.jsx("span",{className:"plan-limits-tooltip__gauge-percent",style:{color:oe},children:p("terminal:usage.percentUsed",{percent:Math.round(Ee)})})]}),e.jsx("div",{className:"plan-limits-tooltip__bar",children:e.jsx("div",{className:"plan-limits-tooltip__bar-fill",style:{width:`${Ee}%`,background:oe}})}),e.jsxs("div",{className:"plan-limits-tooltip__reset",children:[T&&p("terminal:usage.resets",{time:Ia(T.resetsAt)}),ce&&e.jsx("span",{style:{marginLeft:8},children:p("terminal:usage.creditsUsed",{used:ca(T.used),limit:ca(T.limit)})})]})]},D)})}):b&&!I&&e.jsx("div",{className:"plan-limits-tooltip__muted",children:b.rateLimitsError?p("terminal:usage.limitsError",{message:b.rateLimitsError}):b.cliHint})]})}function Dn({agentId:c,disabled:r,contextSummary:p,children:b}){return e.jsx(Ea,{position:"top",maxWidth:320,disabled:r,className:"plan-limits-tooltip-wrapper",triggerStyle:{display:"inline-flex",alignItems:"center"},content:e.jsx($n,{agentId:c,contextSummary:p}),children:b})}const Rn=s.memo(function({className:r=""}){const{t:p}=Jt(["common"]),[b,N]=La(),I=s.useRef(null),[E,A]=s.useState(null);s.useLayoutEffect(()=>{const v=I.current;if(!v)return;const H=v.querySelector(".view-mode-toggle__btn--active");H&&A({left:H.offsetLeft,width:H.offsetWidth})},[b]);const K=s.useCallback(v=>{if(v!==b){if(typeof window<"u"&&window.dispatchEvent(new CustomEvent("tide:viewmode-switch-pressed",{detail:{mode:v}})),v==="3d"){requestAnimationFrame(()=>N(v));return}N(v)}},[b,N]);return e.jsxs("div",{className:`view-mode-toggle ${r}`,ref:I,children:[E&&e.jsx("div",{className:"view-mode-toggle__indicator",style:{left:E.left,width:E.width}}),Pa.map(v=>e.jsxs("button",{className:`view-mode-toggle__btn ${b===v?"view-mode-toggle__btn--active":""}`,onClick:()=>K(v),title:p(`common:viewMode.descriptions.${v}`),children:[e.jsxs("span",{className:"view-mode-toggle__icon",children:[v==="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"})]}),v==="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"})]}),v==="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"})]}),v==="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:p(`common:viewMode.labels.${v}`)})]},v))]})}),It=3,Tt=280,da=320,qt=240,ua=64,zn=["simple","chat","advanced"],On={simple:"Simple",chat:"Chat",advanced:"Advanced"},Bn={simple:"○",chat:"◐",advanced:"◉"},Fn={simple:"Simple view — clean messages only",chat:"Chat view — assistant replies (no tool calls)",advanced:"Advanced view — everything including tools"},Yt="flat-clear-context",ja="tide:flat-embedded-panels";function Ca(){try{const c=localStorage.getItem(ja),r=c?JSON.parse(c):{};return r&&typeof r=="object"?r:{}}catch{return{}}}function Kt(c,r){try{const p=Ca();r?p[c]=r:delete p[c],localStorage.setItem(ja,JSON.stringify(p))}catch{}}function Wn(c){const r=c.split("/").filter(Boolean);return r.length===0?c:r.slice(-2).join("/")}function Hn(c){if(c.provider==="codex"){const I=c.codexModel||"gpt-5.6-luna",E=yn[I];return{model:(E==null?void 0:E.label)||I}}if(c.provider==="opencode")return{model:c.opencodeModel||"opencode"};if(c.provider==="grok"){const I=c.grokModel||"grok-4.5",E=c.effort,A=E?oa[E]:void 0;return{model:I,effort:A==null?void 0:A.label}}const r=c.model||"sonnet",p=An[r],b=c.effort,N=b?oa[b]:void 0;return{model:(p==null?void 0:p.label)||r,effort:N==null?void 0:N.label}}function Un(c,r){if(r.type==="rectangle"&&r.width&&r.height){const p=r.width/2,b=r.height/2;return c.x>=r.center.x-p&&c.x<=r.center.x+p&&c.z>=r.center.z-b&&c.z<=r.center.z+b}if(r.type==="circle"&&r.radius){const p=c.x-r.center.x,b=c.z-r.center.z;return p*p+b*b<=r.radius*r.radius}return!1}const Gn=tn.memo(function({agentId:r,terminalViewMode:p,onTerminalViewModeChange:b,inspectorOpen:N,onToggleInspector:I,onShowTaskBoard:E,onImageClick:A,onFileClick:K,onBashClick:v,onViewMarkdown:H,onRequestClearSubordinates:D,keyboard:re,canNavigateBack:T,canNavigateForward:Ee,onNavigateBack:oe,onNavigateForward:ce,agentInfoOpen:Oe,onToggleAgentInfo:bt,onHeaderContextMenu:we,onBuildingContextMenu:ve}){var Nt,yt;const u=ra(r),R=xa(),Me=an(),Ie=s.useRef(null),Ze=s.useRef(null),{displayedAgentId:Te,fadingOut:Lt}=nn(r),_t=ra(Te),Je=!!Me.interactiveMode&&((u==null?void 0:u.provider)??"claude")==="claude"&&!!(u!=null&&u.sessionId),[de,Qe]=s.useState(!1),[Be,ue]=s.useState(!1),$=s.useCallback(()=>ue(!1),[]);ha("flat-chat-actions",Be,$),s.useEffect(()=>{const a=()=>ue(o=>!o);return window.addEventListener("tide:toggle-chat-actions",a),()=>window.removeEventListener("tide:toggle-chat-actions",a)},[]),s.useEffect(()=>{Qe(!1),ue(!1)},[r]),s.useEffect(()=>{!Je&&de&&Qe(!1)},[Je,de]),s.useEffect(()=>{const a=Ze.current;if(!a)return;const o=m=>{m.button===3?(m.preventDefault(),m.stopPropagation(),oe()):m.button===4&&(m.preventDefault(),m.stopPropagation(),ce())},i=m=>{(m.button===3||m.button===4)&&m.preventDefault()};return a.addEventListener("mouseup",o),a.addEventListener("mousedown",i),()=>{a.removeEventListener("mouseup",o),a.removeEventListener("mousedown",i)}},[oe,ce]),s.useEffect(()=>{const a=Ze.current;if(!a)return;let o=0,i=0,m=0;const X=250,Q=600,L=80,st=1.5,ae=ne=>{let U=ne instanceof HTMLElement?ne:null;for(;U&&U!==a;){const At=window.getComputedStyle(U).overflowX;if((At==="auto"||At==="scroll")&&U.scrollWidth>U.clientWidth)return!0;U=U.parentElement}return!1},Ye=ne=>{const U=Date.now();if(U<m){ne.preventDefault();return}if(Math.abs(ne.deltaX)<=Math.abs(ne.deltaY)*st){o=0;return}if(ae(ne.target)){o=0;return}U-i>X&&(o=0),i=U,o+=ne.deltaX,o<=-L?(o=0,m=U+Q,ne.preventDefault(),oe()):o>=L&&(o=0,m=U+Q,ne.preventDefault(),ce())};return a.addEventListener("wheel",Ye,{passive:!1}),()=>a.removeEventListener("wheel",Ye)},[oe,ce]);const me=ga(),lt=s.useMemo(()=>{if(!u)return null;const a=new Set,o=[];for(const i of me.values())i.archived||i.directories.length===0||i.assignedAgentIds.includes(r)&&(a.add(i.id),o.push(i));for(const i of me.values())i.archived||i.directories.length===0||a.has(i.id)||Un({x:u.position.x,z:u.position.z},i)&&(a.add(i.id),o.push(i));return o.length===0?null:o.flatMap(i=>i.directories.filter(m=>m&&m.trim().length>0).map(m=>({areaId:i.id,areaName:i.name,dir:m})))},[u,r,me]),{branches:wt,fetchRemote:Fe,fetchingDirs:Le}=sn(lt),pe=s.useMemo(()=>{var i;const a=g.getAreaForAgent(r);if(!a)return[];const o=[];for(const m of R.values())m.type==="terminal"&&g.isPositionInArea(m.position,a)&&o.push({id:m.id,name:m.name,hasUrl:!!((i=m.terminalStatus)!=null&&i.url)});return o},[r,R]),je=s.useMemo(()=>{var i;const a=g.getAreaForAgent(r);if(!a)return[];const o=[];for(const m of R.values())m.type==="server"&&((i=m.pm2)!=null&&i.enabled)&&g.isPositionInArea(m.position,a)&&o.push({id:m.id,name:m.name});return o},[r,R]),Z=s.useMemo(()=>{const a=g.getAreaForAgent(r);if(!a)return[];const o=[];for(const i of R.values())i.type==="database"&&i.database&&g.isPositionInArea(i.position,a)&&o.push({id:i.id,name:i.name});return o},[r,R]),We=ln(),se=s.useMemo(()=>{const a=g.getAreaForAgent(r);if(!a)return[];const o=[];for(const i of R.values())if(i.type==="tests"&&g.isPositionInArea(i.position,a)){const m=!!i.folderPath&&We.some(X=>rn(X,i.folderPath));o.push({id:i.id,name:i.name,working:m})}return o},[r,R,We]),ie=s.useMemo(()=>{const a=g.getAreaForAgent(r);if(!a)return[];const o=[];for(const i of R.values())i.type==="http"&&g.isPositionInArea(i.position,a)&&o.push({id:i.id,name:i.name});return o},[r,R]),[,Pt]=s.useReducer(a=>a+1,0),Ce=((Nt=Ie.current)==null?void 0:Nt.search.searchMode)??!1,rt=s.useCallback(()=>{var a;(a=Ie.current)==null||a.search.toggleSearch(),Pt()},[]),Pe=on(),$e=Pe.isPending(Yt),[j,te]=s.useState(null),J=j?R.get(j.buildingId):null,[He,De]=s.useState(""),[Ue,$t]=s.useState(()=>cn()),z=s.useMemo(()=>{var a;return((a=g.getAreaForAgent(r))==null?void 0:a.id)??null},[r,R]),Ge=s.useCallback((a,o)=>{De(""),te(i=>{const m=(i==null?void 0:i.buildingId)===o?null:{type:a,buildingId:o};return z&&Kt(z,m),m})},[z]),ke=s.useCallback(()=>{De(""),te(null),z&&Kt(z,null)},[z]);s.useEffect(()=>{if((j==null?void 0:j.type)!=="pm2-logs")return;const a=j.buildingId;return g.startLogStreaming(a,200),()=>g.stopLogStreaming(a)},[j]);const{height:Dt,onResizeStart:Rt}=dn(),{sidePanelWidth:zt,handleSidePanelResizeStart:ot}=un(),[w,vt]=s.useState(()=>Zt(y.GIT_PANEL_OPEN,!1)),[Re,fe]=s.useState(()=>Zt(y.BUILDINGS_PANEL_OPEN,!1)),[O,Ve]=s.useState(!1),ct=s.useCallback(()=>{Ve(a=>{const o=!a;return o&&mn.setEnabled(!0),o})},[]),Ot=s.useCallback(()=>Ve(!1),[]),jt=s.useCallback(()=>{vt(a=>{const o=!a;return _e(y.GIT_PANEL_OPEN,o),o})},[]),Ct=s.useCallback(()=>{fe(a=>{const o=!a;return _e(y.BUILDINGS_PANEL_OPEN,o),o})},[]),Bt=s.useCallback(()=>{vt(!1),_e(y.GIT_PANEL_OPEN,!1)},[]),dt=s.useCallback(()=>{fe(!1),_e(y.BUILDINGS_PANEL_OPEN,!1)},[]),Xe=pn(),he=s.useMemo(()=>({terminal:pe,"pm2-logs":je,database:Z,tests:se,http:ie}),[pe,je,Z,se,ie]);s.useEffect(()=>{if(!j)return;he[j.type].some(o=>o.id===j.buildingId)||(De(""),te(null))},[j,he]);const Ne=s.useRef(void 0);s.useEffect(()=>{var o;if(Ne.current===z)return;Ne.current=z;const a=z?Ca()[z]:void 0;De(""),a&&((o=he[a.type])!=null&&o.some(i=>i.id===a.buildingId))?te(a):te(null)},[z,he]),s.useEffect(()=>{const a=o=>{var X;const i=o.detail;if(!(i!=null&&i.buildingId)||!(i!=null&&i.type)||!((X=he[i.type])!=null&&X.some(Q=>Q.id===i.buildingId)))return;i.handled=!0,De("");const m={type:i.type,buildingId:i.buildingId};te(m),z&&Kt(z,m)};return window.addEventListener("tide:dock-building-flat",a),()=>window.removeEventListener("tide:dock-building-flat",a)},[he,z]);const[qe,B]=s.useState(!1),ge=s.useRef(null);if(s.useEffect(()=>{if(!qe)return;const a=o=>{ge.current&&!ge.current.contains(o.target)&&B(!1)};return document.addEventListener("mousedown",a),()=>document.removeEventListener("mousedown",a)},[qe]),!u)return e.jsx("div",{className:"flat-chat flat-chat--empty",children:e.jsxs("div",{className:"flat-chat__placeholder",children:[e.jsx("span",{className:"flat-chat__placeholder-icon",children:"💬"}),e.jsx("span",{className:"flat-chat__placeholder-text",children:"Select an agent to start chatting"})]})});const ye=u.contextStats,ut=!!ye,et=ye?ye.totalTokens:u.contextUsed||0,mt=ye?ye.contextWindow:u.contextLimit||(u.provider==="grok"?5e5:2e5),Ft=ye?ye.usedPercent:Math.round(et/mt*100),ze=Math.max(0,Math.min(100,Ft)),kt=Math.round(ze*10)/10,xe=Math.round((100-ze)*10)/10,tt=ze>=80?"#ff4a4a":ze>=60?"#ff9e4a":ze>=40?"#ffd700":"#4aff9e",at=(et/1e3).toFixed(1),pt=(mt/1e3).toFixed(1),be=u.cwd,ft=be?Wn(be):null,Ae=((yt=u.subordinateIds)==null?void 0:yt.length)||0,nt=Ae>0;return e.jsxs("div",{ref:Ze,className:`flat-terminal-wrapper ${w||Re||O?"flat-terminal-wrapper--with-side-panel":""} ${Lt?"pane-fading-out":""}`,style:{"--guake-side-panel-width":`min(${zt}px, 70%)`},children:[e.jsxs("div",{className:"flat-terminal-wrapper__header",children:[e.jsxs("button",{type:"button",className:`flat-terminal-wrapper__header-main ${Oe?"flat-terminal-wrapper__header-main--active":""}`,onClick:bt,onContextMenu:a=>{a.preventDefault(),a.stopPropagation(),we({x:a.clientX,y:a.clientY})},title:Oe?"Hide agent info":"Show agent info","aria-pressed":Oe,children:[e.jsx("span",{className:`flat-terminal-wrapper__header-avatar${u.status==="working"?" is-working":""}`,children:e.jsx(ba,{agent:u,size:28})}),e.jsxs("span",{className:"flat-terminal-wrapper__header-info",children:[e.jsx("span",{className:"flat-terminal-wrapper__header-name",children:u.name}),e.jsx("span",{className:"flat-terminal-wrapper__header-status",style:{color:va(u.status)},title:u.status==="error"&&u.lastError?u.lastError:void 0,children:u.status})]}),u.taskLabel&&e.jsxs("span",{className:"flat-terminal-wrapper__header-task",title:u.taskLabel,children:["📋 ",u.taskLabel]}),e.jsxs("span",{className:"flat-terminal-wrapper__header-model",children:[e.jsx("img",{src:wa(u.provider,"/"),alt:u.provider,className:"flat-terminal-wrapper__header-provider-icon",title:_a(u.provider)}),(()=>{const{model:a,effort:o}=Hn(u);return e.jsxs("span",{className:"flat-terminal-wrapper__header-model-chip",title:o?`Model: ${a} · Effort: ${o}`:`Model: ${a}`,children:[e.jsx("span",{className:"flat-terminal-wrapper__header-model-name",children:a}),o&&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:o})]})]})})()]})]}),e.jsxs("div",{className:"flat-terminal-wrapper__header-meta",children:[e.jsxs("div",{className:"flat-terminal-wrapper__view-mode",role:"group","aria-label":"Message view mode",children:[zn.map(a=>e.jsxs("button",{type:"button",className:`flat-terminal-wrapper__view-mode-btn ${!de&&p===a?"flat-terminal-wrapper__view-mode-btn--active":""}`,onClick:()=>{Qe(!1),b(a)},title:Fn[a],"aria-pressed":!de&&p===a,children:[e.jsx("span",{className:"flat-terminal-wrapper__view-mode-icon","aria-hidden":"true",children:Bn[a]}),e.jsx("span",{className:"flat-terminal-wrapper__view-mode-label",children:On[a]})]},a)),Je&&e.jsxs("button",{type:"button",className:`flat-terminal-wrapper__view-mode-btn ${de?"flat-terminal-wrapper__view-mode-btn--active":""}`,onClick:()=>Qe(a=>!a),title:"Classic TUI — attach to the live interactive claude session in a terminal","aria-pressed":de,children:[e.jsx("span",{className:"flat-terminal-wrapper__view-mode-icon","aria-hidden":"true",children:e.jsx(d,{name:"terminal",size:13})}),e.jsx("span",{className:"flat-terminal-wrapper__view-mode-label",children:"Classic TUI"})]})]}),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:oe,disabled:!T,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:ce,disabled:!Ee,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 ${Ce?"flat-terminal-wrapper__action-btn--active":""}`,onClick:rt,title:Ce?"Close search":"Search messages","aria-pressed":Ce,children:e.jsx(d,{name:Ce?"cross":"search",size:14})}),e.jsx("button",{type:"button",className:`flat-terminal-wrapper__action-btn flat-terminal-wrapper__action-btn--danger ${$e?"flat-terminal-wrapper__action-btn--confirm":""}`,onClick:()=>Pe.handleClick(Yt,()=>{var a;g.clearContext(r),(a=Ie.current)==null||a.historyLoader.clearHistory()}),title:$e?"Click again to confirm clear context":"Clear context",children:e.jsx(d,{name:$e?"question":"clear",size:14})}),e.jsx("button",{type:"button",className:`flat-terminal-wrapper__action-btn ${w?"flat-terminal-wrapper__action-btn--active":""}`,onClick:jt,title:w?"Hide git panel":"Show git changes","aria-pressed":w,children:e.jsx(d,{name:"git-branch",size:14})}),e.jsx("button",{type:"button",className:`flat-terminal-wrapper__action-btn ${Re?"flat-terminal-wrapper__action-btn--active":""}`,onClick:Ct,title:Re?"Hide buildings panel":"Show area buildings","aria-pressed":Re,children:e.jsx(d,{name:"buildings",size:14})}),e.jsxs("div",{className:"flat-terminal-wrapper__more",ref:ge,children:[e.jsx("button",{type:"button",className:`flat-terminal-wrapper__action-btn ${qe?"flat-terminal-wrapper__action-btn--active":""}`,onClick:()=>B(a=>!a),title:"More actions","aria-expanded":qe,children:"⋮"}),qe&&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 ${O?"flat-terminal-wrapper__more-item--active":""}`,onClick:()=>{ct(),B(!1)},title:O?"Hide Debug Panel":"Show Debug Panel",children:[e.jsx(d,{name:"bug",size:14}),e.jsx("span",{children:O?"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(r),B(!1)},disabled:u.status!=="idle",title:u.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"})]}),nt&&e.jsxs("button",{type:"button",role:"menuitem",className:"flat-terminal-wrapper__more-item flat-terminal-wrapper__more-item--danger",onClick:()=>{D(r,Ae),B(!1)},children:[e.jsx(d,{name:"crown",size:14}),e.jsxs("span",{children:["Clear ",Ae," subordinate",Ae===1?"":"s"]})]}),e.jsx("div",{className:"flat-terminal-wrapper__more-divider"}),e.jsxs("button",{type:"button",role:"menuitem",className:"flat-terminal-wrapper__more-item flat-terminal-wrapper__more-item--danger",onClick:()=>{g.killAgent(r),B(!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 ${N?"flat-terminal-wrapper__inspector-toggle--active":""}`,onClick:I,title:N?"Hide inspector panel":"Show inspector panel","aria-label":N?"Hide inspector panel":"Show inspector panel","aria-pressed":N,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})})]})]}),Be&&e.jsxs("div",{className:"flat-chat-actions-sheet-root",role:"presentation",children:[e.jsx("div",{className:"flat-chat-actions-sheet__backdrop",onClick:$}),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:u.name}),e.jsx("button",{type:"button",className:"flat-chat-actions-sheet__done",onClick:$,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 ${Ce?"is-active":""}`,onClick:()=>{rt(),$()},children:[e.jsx(d,{name:Ce?"cross":"search",size:20}),e.jsx("span",{children:Ce?"Close search":"Search"})]}),e.jsxs("button",{type:"button",role:"menuitem",className:`flat-chat-actions-sheet__item ${w?"is-active":""}`,onClick:()=>{jt(),$()},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 ${Re?"is-active":""}`,onClick:()=>{Ct(),$()},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 ${O?"is-active":""}`,onClick:()=>{ct(),$()},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 ${$e?"is-armed":""}`,onClick:()=>Pe.handleClick(Yt,()=>{var a;g.clearContext(r),(a=Ie.current)==null||a.historyLoader.clearHistory(),$()}),children:[e.jsx(d,{name:$e?"question":"clear",size:18}),e.jsx("span",{children:$e?"Tap again to confirm clear":"Clear context"})]}),e.jsxs("button",{type:"button",role:"menuitem",className:"flat-chat-actions-sheet__row",disabled:u.status!=="idle",onClick:()=>{g.collapseContext(r),$()},children:[e.jsx(d,{name:"package",size:18}),e.jsx("span",{children:"Collapse context"})]}),nt&&e.jsxs("button",{type:"button",role:"menuitem",className:"flat-chat-actions-sheet__row flat-chat-actions-sheet__row--danger",onClick:()=>{D(r,Ae),$()},children:[e.jsx(d,{name:"crown",size:18}),e.jsxs("span",{children:["Clear ",Ae," subordinate",Ae===1?"":"s"]})]}),e.jsxs("button",{type:"button",role:"menuitem",className:"flat-chat-actions-sheet__row flat-chat-actions-sheet__row--danger",onClick:()=>{g.killAgent(r),$()},children:[e.jsx(d,{name:"cross",size:18}),e.jsx("span",{children:"Remove agent"})]})]})]})]}),e.jsx(fn,{agent:u,onClick:E}),de&&Je?e.jsx(Tn,{agentId:r}):Te&&_t?e.jsx(hn,{ref:Ie,agentId:Te,agent:_t,viewMode:p,isOpen:!0,onImageClick:A,onFileClick:K,onBashClick:v,onViewMarkdown:H,keyboard:re,hasModalOpen:!1},Te):null,j&&J&&(()=>{var X,Q;const a=j.type,o={terminal:"terminal","pm2-logs":"scroll",database:"hard-drives",tests:"flask",http:"globe"},i=a==="terminal"&&!((X=J.terminalStatus)!=null&&X.url),m=!i;return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"guake-bottom-terminal-resize",onMouseDown:Rt,role:"separator","aria-orientation":"horizontal","aria-label":"Resize embedded panel"}),e.jsxs("div",{className:"flat-bottom-panel",role:"region","aria-label":`${J.name} panel`,style:{height:Dt},children:[e.jsxs("div",{className:"flat-bottom-panel__header",children:[e.jsxs("span",{className:"flat-bottom-panel__title",children:[e.jsx(d,{name:o[a],size:12}),e.jsx("span",{children:J.name}),i&&e.jsx("span",{className:"flat-bottom-panel__muted",children:"(starting...)"})]}),e.jsxs("span",{className:"flat-bottom-panel__header-actions",children:[a==="pm2-logs"&&e.jsxs(e.Fragment,{children:[e.jsx("input",{type:"text",className:"guake-bottom-terminal-filter",value:He,onChange:L=>De(L.target.value),placeholder:"Filter logs","aria-label":`Filter logs for ${J.name}`,spellCheck:!1}),e.jsx("select",{className:"guake-bottom-terminal-retention",value:Ue===null?"unlimited":String(Ue),onChange:L=>{const st=L.target.value==="unlimited"?null:Number(L.target.value);$t(st),xn(st)},"aria-label":`Max log retention for ${J.name}`,children:gn.map(L=>e.jsx("option",{value:L===null?"unlimited":String(L),children:L===null?"Unlimited":`${L.toLocaleString()} lines`},L===null?"unlimited":L))}),e.jsx("button",{type:"button",className:"flat-bottom-panel__close",onClick:()=>g.clearStreamingLogs(j.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(j.buildingId,"restart"),title:"Restart",children:e.jsx(d,{name:"restart",size:12})})]}),m&&e.jsx("button",{type:"button",className:"flat-bottom-panel__close",onClick:()=>{ke(),it(j.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:ke,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"?(Q=J.terminalStatus)!=null&&Q.url?e.jsx(fa,{terminalUrl:J.terminalStatus.url,visible:!0}):e.jsx("div",{className:"flat-bottom-panel__placeholder",children:"Starting terminal..."}):a==="pm2-logs"?e.jsx(bn,{buildingId:j.buildingId,filterText:He,maxRetention:Ue}):a==="database"?e.jsx(_n,{building:J}):a==="tests"?e.jsx("div",{className:"tests-panel-host",children:e.jsx(wn,{building:J,autoFocusSearch:!1})}):e.jsx("div",{className:"http-requests-panel-host",children:e.jsx(vn,{building:J,autoFocusSearch:!1})})})]})]})})(),e.jsxs("div",{className:"flat-terminal-wrapper__statusbar",role:"contentinfo",children:[u.isDetached&&e.jsxs("span",{className:"flat-terminal-wrapper__detached",title:"Reattaching session...",children:[e.jsx(d,{name:"refresh",size:12}),e.jsx("span",{children:"Reattaching"})]}),be&&ft&&e.jsxs("span",{className:"flat-terminal-wrapper__cwd",title:`Open in file explorer: ${be}`,"aria-label":`Open ${be} in file explorer`,role:"button",tabIndex:0,onClick:()=>g.openFileExplorer(be),onKeyDown:a=>{(a.key==="Enter"||a.key===" ")&&(a.preventDefault(),g.openFileExplorer(be))},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:ft})]}),lt&<.map(({areaId:a,areaName:o,dir:i})=>{const m=wt.get(i),X=Le.has(i),Q=i.split("/").filter(Boolean).pop()||i;return e.jsxs("span",{className:"flat-terminal-wrapper__area-dir",title:`${o}: ${i}${m?` (${m.branch}${m.ahead?` ↑${m.ahead}`:""}${m.behind?` ↓${m.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:Q}),m&&e.jsxs(e.Fragment,{children:[e.jsxs("span",{className:"flat-terminal-wrapper__area-dir-branch",children:[e.jsx(d,{name:"git-branch",size:10})," ",m.branch]}),m.ahead>0&&e.jsxs("span",{className:"flat-terminal-wrapper__branch-ahead",title:`${m.ahead} ahead`,children:[e.jsx(d,{name:"arrow-up",size:9}),m.ahead]}),m.behind>0&&e.jsxs("span",{className:"flat-terminal-wrapper__branch-behind",title:`${m.behind} behind`,children:[e.jsx(d,{name:"arrow-down",size:9}),m.behind]}),e.jsx("span",{className:`flat-terminal-wrapper__area-fetch ${X?"flat-terminal-wrapper__area-fetch--fetching":""}`,title:"Git fetch",onClick:L=>{L.stopPropagation(),Fe(i)},children:e.jsx(d,{name:X?"hourglass":"download",size:12})})]})]},`${a}:${i}`)}),e.jsx(Dn,{agentId:r,disabled:((u==null?void 0:u.provider)??"claude")!=="claude"&&((u==null?void 0:u.provider)??"claude")!=="grok",contextSummary:ut?`Context: ${at}k / ${pt}k tokens (${kt}% used)`:void 0,children:e.jsxs("span",{className:"flat-terminal-wrapper__context",tabIndex:0,role:"button",onClick:()=>g.setContextModalAgentId(r),onKeyDown:a=>{(a.key==="Enter"||a.key===" ")&&(a.preventDefault(),g.setContextModalAgentId(r))},title:((u==null?void 0:u.provider)??"claude")!=="claude"&&((u==null?void 0:u.provider)??"claude")!=="grok"?ut?`Context usage: ${at}k / ${pt}k tokens (${kt}% used). Click to view stats.`:"Click to fetch context stats":void 0,children:[e.jsx("span",{className:"flat-terminal-wrapper__context-icon",children:e.jsx(d,{name:"dashboard",size:12})}),e.jsx("span",{className:"flat-terminal-wrapper__context-label",children:"Ctx:"}),e.jsx("span",{className:"flat-terminal-wrapper__context-bar",children:e.jsx("span",{className:"flat-terminal-wrapper__context-bar-fill",style:{width:`${ze}%`,backgroundColor:tt}})}),e.jsxs("span",{className:"flat-terminal-wrapper__context-tokens",style:{color:tt},children:[at,"k/",pt,"k"]}),e.jsxs("span",{className:"flat-terminal-wrapper__context-free",children:["(",xe,"% free)"]}),!ut&&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"}),pe.length>0&&e.jsx("span",{className:"flat-terminal-wrapper__buildings",role:"group","aria-label":"Area terminals",children:pe.map(a=>{const o=(j==null?void 0:j.buildingId)===a.id;return e.jsx("button",{type:"button",className:`flat-terminal-wrapper__building-btn ${o?"flat-terminal-wrapper__building-btn--active":""} ${a.hasUrl?"":"flat-terminal-wrapper__building-btn--offline"}`,title:`${o?"Hide":"Show"} terminal: ${a.name}${a.hasUrl?"":" (starting...)"}`,onClick:()=>{if(o){ke();return}if(a.hasUrl&>(a.id)==="modal"){it(a.id);return}a.hasUrl||g.sendBuildingCommand(a.id,"start"),Ge("terminal",a.id)},onContextMenu:i=>{i.preventDefault(),i.stopPropagation(),ve(a.id,{x:i.clientX,y:i.clientY})},children:e.jsx(d,{name:"terminal",size:14})},a.id)})}),je.length>0&&e.jsx("span",{className:"flat-terminal-wrapper__buildings",role:"group","aria-label":"Area PM2 logs",children:je.map(a=>{const o=(j==null?void 0:j.buildingId)===a.id;return e.jsx("button",{type:"button",className:`flat-terminal-wrapper__building-btn ${o?"flat-terminal-wrapper__building-btn--active":""}`,title:`${o?"Hide":"Show"} logs: ${a.name}`,onClick:()=>{o?ke():gt(a.id)==="modal"?it(a.id):Ge("pm2-logs",a.id)},onContextMenu:i=>{i.preventDefault(),i.stopPropagation(),ve(a.id,{x:i.clientX,y:i.clientY})},children:e.jsx(d,{name:"scroll",size:14})},a.id)})}),Z.length>0&&e.jsx("span",{className:"flat-terminal-wrapper__buildings",role:"group","aria-label":"Area databases",children:Z.map(a=>{const o=(j==null?void 0:j.buildingId)===a.id;return e.jsx("button",{type:"button",className:`flat-terminal-wrapper__building-btn ${o?"flat-terminal-wrapper__building-btn--active":""}`,title:`${o?"Hide":"Show"} database: ${a.name}`,onClick:()=>{o?ke():gt(a.id)==="modal"?it(a.id):Ge("database",a.id)},onContextMenu:i=>{i.preventDefault(),i.stopPropagation(),ve(a.id,{x:i.clientX,y:i.clientY})},children:e.jsx(d,{name:"hard-drives",size:14})},a.id)})}),se.length>0&&e.jsx("span",{className:"flat-terminal-wrapper__buildings",role:"group","aria-label":"Area tests",children:se.map(a=>{const o=(j==null?void 0:j.buildingId)===a.id;return e.jsx("button",{type:"button",className:`flat-terminal-wrapper__building-btn ${o?"flat-terminal-wrapper__building-btn--active":""} ${a.working?"flat-terminal-wrapper__building-btn--tests-working":""}`,title:a.working?`Running tests: ${a.name}`:`${o?"Hide":"Show"} tests: ${a.name}`,onClick:()=>{o?ke():gt(a.id)==="modal"?it(a.id):Ge("tests",a.id)},onContextMenu:i=>{i.preventDefault(),i.stopPropagation(),ve(a.id,{x:i.clientX,y:i.clientY})},children:e.jsx(d,{name:"flask",size:14})},a.id)})}),ie.length>0&&e.jsx("span",{className:"flat-terminal-wrapper__buildings",role:"group","aria-label":"Area HTTP requests",children:ie.map(a=>{const o=(j==null?void 0:j.buildingId)===a.id;return e.jsx("button",{type:"button",className:`flat-terminal-wrapper__building-btn ${o?"flat-terminal-wrapper__building-btn--active":""}`,title:`${o?"Hide":"Show"} HTTP requests: ${a.name}`,onClick:()=>{o?ke():gt(a.id)==="modal"?it(a.id):Ge("http",a.id)},onContextMenu:i=>{i.preventDefault(),i.stopPropagation(),ve(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(jn,{})})]}),w&&e.jsx(Cn,{agentId:r,agents:Xe,onClose:Bt,branchInfoMap:wt,fetchRemote:Fe,fetchingDirs:Le,onResizeStart:a=>ot(a,"right")}),Re&&e.jsx(kn,{agentId:r,onClose:dt}),O&&e.jsx(Nn,{agentId:r,onClose:Ot})]})}),Vn={groups:[],gridCols:1,gridRows:1,positions:new Map};function Zn({onAgentClick:c,onBuildingClick:r,onBuildingDoubleClick:p,onBuildingPopup:b,onAreaContextMenu:N,onOpenSpawnModal:I,onOpenBossSpawnModal:E,onOpenAreaModal:A}){const{t:K}=Jt(["common"]),v=$a(),H=Da(),[D,re]=s.useState(null),[T,Ee]=s.useState(null),[oe,ce]=s.useState(null);ha("flatview-image-modal",D!==null,()=>re(null));const[Oe,bt]=s.useState(null),[we,ve]=s.useState(null),[u,R]=s.useState(null),[Me,Ie]=s.useState(null),[Ze,Te]=s.useState(!1),Lt=s.useCallback(()=>{Te(t=>!t)},[]),_t=s.useCallback(()=>{Te(!1)},[]),[Je,de]=s.useState(()=>{const t=Gt(y.VIEW_MODE);return t==="simple"||t==="chat"||t==="advanced"?t:"simple"}),Qe=s.useCallback(t=>{de(t),Vt(y.VIEW_MODE,t)},[]);s.useEffect(()=>{const t=n=>{if(n.key!==y.VIEW_MODE)return;const l=n.newValue;(l==="simple"||l==="chat"||l==="advanced")&&de(l)};return window.addEventListener("storage",t),()=>window.removeEventListener("storage",t)},[]);const[Be,ue]=s.useState(()=>Zt(y.FLAT_INSPECTOR_OPEN,!1)),[$,me]=s.useState(!1),lt=s.useCallback(()=>me(t=>!t),[]),wt=s.useCallback(()=>me(!1),[]);s.useEffect(()=>{window.dispatchEvent(new CustomEvent("tide-flat-agents-drawer-state",{detail:{open:$}}))},[$]),s.useEffect(()=>{window.dispatchEvent(new CustomEvent("tide-flat-inspector-state",{detail:{open:Be}}))},[Be]),s.useEffect(()=>{const t=()=>me(k=>!k),n=()=>{ue(k=>{const M=!k;return _e(y.FLAT_INSPECTOR_OPEN,M),M})},l=()=>{me(!1),ue(!1),_e(y.FLAT_INSPECTOR_OPEN,!1)},x=()=>me(!1),_=()=>{ue(!1),_e(y.FLAT_INSPECTOR_OPEN,!1)};return window.addEventListener("tide-toggle-flat-agents-drawer",t),window.addEventListener("tide-toggle-flat-inspector",n),window.addEventListener("tide-close-flat-side-views",l),window.addEventListener("tide-close-flat-agents-drawer-only",x),window.addEventListener("tide-close-flat-inspector-only",_),()=>{window.removeEventListener("tide-toggle-flat-agents-drawer",t),window.removeEventListener("tide-toggle-flat-inspector",n),window.removeEventListener("tide-close-flat-side-views",l),window.removeEventListener("tide-close-flat-agents-drawer-only",x),window.removeEventListener("tide-close-flat-inspector-only",_)}},[]);const Fe=s.useRef(null),Le=s.useRef(null),[pe,je]=s.useState(()=>{const t=na(y.FLAT_MIDDLE_WIDTH,0);return t>=Tt?t:null}),[Z,We]=s.useState(()=>{const t=na(y.FLAT_INSPECTOR_WIDTH,0);return t>=qt?t:null}),se=s.useCallback(t=>{if(typeof window>"u")return t;const n=Z!==null?It+Z:0,l=window.innerWidth-ua-It-da-n;return Math.max(Tt,Math.min(Math.max(l,Tt),t))},[Z]),ie=s.useCallback(t=>{var _;if(typeof window>"u")return t;const n=(_=Fe.current)==null?void 0:_.querySelector(".flat-middle"),l=(n==null?void 0:n.getBoundingClientRect().width)??Tt,x=window.innerWidth-ua-l-It-da-It;return Math.max(qt,Math.min(Math.max(x,qt),t))},[]);s.useEffect(()=>{if(pe===null&&Z===null)return;const t=()=>{je(n=>{if(n===null)return n;const l=se(n);return l===n?n:l}),We(n=>{if(n===null)return n;const l=ie(n);return l===n?n:l})};return window.addEventListener("resize",t),()=>window.removeEventListener("resize",t)},[pe,Z,se,ie]);const Pt=s.useCallback(t=>{var l;if(t.button!==0)return;const n=(l=Fe.current)==null?void 0:l.querySelector(".flat-middle");n&&(t.currentTarget.setPointerCapture(t.pointerId),Le.current={kind:"middle",startX:t.clientX,startWidth:n.getBoundingClientRect().width,pointerId:t.pointerId},document.body.classList.add("flat-splitter-dragging"))},[]),Ce=s.useCallback(t=>{var l;if(t.button!==0)return;const n=(l=Fe.current)==null?void 0:l.querySelector(".flat-inspector");n&&(t.currentTarget.setPointerCapture(t.pointerId),Le.current={kind:"inspector",startX:t.clientX,startWidth:n.getBoundingClientRect().width,pointerId:t.pointerId},document.body.classList.add("flat-splitter-dragging"))},[]),rt=s.useCallback(t=>{const n=Le.current;if(!n||t.pointerId!==n.pointerId)return;const l=t.clientX-n.startX;n.kind==="middle"?je(se(n.startWidth+l)):We(ie(n.startWidth-l))},[se,ie]),Pe=s.useCallback(t=>{const n=Le.current;if(!n||t.pointerId!==n.pointerId)return;try{t.currentTarget.releasePointerCapture(t.pointerId)}catch{}if(Le.current=null,document.body.classList.remove("flat-splitter-dragging"),!(Math.abs(t.clientX-n.startX)>2))return;const x=t.clientX-n.startX;if(n.kind==="middle"){const _=se(n.startWidth+x);je(_),Mt(y.FLAT_MIDDLE_WIDTH,_)}else{const _=ie(n.startWidth-x);We(_),Mt(y.FLAT_INSPECTOR_WIDTH,_)}},[se,ie]),$e=s.useCallback(()=>{je(null),Mt(y.FLAT_MIDDLE_WIDTH,0)},[]),j=s.useCallback(()=>{We(null),Mt(y.FLAT_INSPECTOR_WIDTH,0)},[]),[te,J]=s.useState(()=>Gt(y.FLAT_INSPECTOR_VIEW)==="tracking"?"tracking":"agent"),He=s.useCallback(t=>{J(t),Vt(y.FLAT_INSPECTOR_VIEW,t)},[]),De=s.useCallback(()=>{ue(t=>{const n=!t;return _e(y.FLAT_INSPECTOR_OPEN,n),n})},[]),Ue=s.useCallback(()=>{ue(!1),_e(y.FLAT_INSPECTOR_OPEN,!1)},[]),$t=s.useCallback(()=>{He("tracking"),ue(!0),_e(y.FLAT_INSPECTOR_OPEN,!0)},[He]),z=Ra(),Ge=s.useCallback((t,n)=>{re({url:t,name:n})},[]),ke=s.useCallback((t,n)=>{Ee({command:t,output:n,isLive:!1})},[]),Dt=s.useCallback((t,n)=>{var _;const l=H.size>0?Array.from(H)[0]:null,x=l?(_=g.getState().agents.get(l))==null?void 0:_.cwd:void 0;g.setFileViewerPath(t,n,x)},[H]),Rt=s.useCallback(t=>{ce(t)},[]),zt=s.useCallback((t,n)=>{bt({agentId:t,count:n})},[]),ot=s.useCallback(t=>{p?p(t):r(t)},[r,p]),w=s.useMemo(()=>H.size>0?Array.from(H)[0]:null,[H]),vt=s.useCallback(t=>{w&&ve({agentId:w,position:t})},[w]),Re=s.useCallback((t,n)=>{R({buildingId:t,position:n})},[]);s.useEffect(()=>{Te(!1)},[w]);const fe=s.useRef([]),O=s.useRef(-1),Ve=s.useRef(!1),ct=s.useRef(Gt(y.LAST_OPENED_AGENT,"")||null),[Ot,jt]=s.useState(!1),[Ct,Bt]=s.useState(!1),dt=s.useRef(!1),Xe=s.useRef(null),he=s.useRef(!1),Ne=s.useMemo(()=>new Set(v.map(t=>t.id)),[v]),qe=s.useMemo(()=>{const t=new Map(v.map(l=>[l.id,l])),n=new Map;for(const l of v)if((l.isBoss||l.class==="boss")&&l.subordinateIds&&l.subordinateIds.length>0){const x=l.subordinateIds.map(_=>t.get(_)).filter(_=>_!==void 0);x.length>0&&n.set(l.id,x)}return n},[v]),B=s.useCallback(()=>{const t=fe.current,n=O.current;jt(n>0),Bt(n>=0&&n<t.length-1)},[]),ge=s.useCallback(t=>{const n=fe.current;if(n.length===0)return;let l=O.current+t;for(;l>=0&&l<n.length;){const x=n[l];if(Ne.has(x)){Ve.current=!0,O.current=l,B(),g.selectAgent(x);return}l+=t}},[Ne,B]),ye=s.useCallback(()=>ge(-1),[ge]),ut=s.useCallback(()=>ge(1),[ge]);En(s.useCallback(()=>{const t=fe.current,n=O.current;return t.length>0&&n>0?(ge(-1),"handled"):"exit"},[ge]));const et=s.useCallback((t,n)=>{if(typeof window>"u")return;const l=window.history.state,_={...typeof l=="object"&&l!==null?l:{},__flatAgentNav:{agentId:t}};n==="replace"?window.history.replaceState(_,"",window.location.href):window.history.pushState(_,"",window.location.href)},[]);s.useEffect(()=>{if(!w){dt.current=!1,Xe.current=null;return}if(!dt.current){et(w,"replace"),dt.current=!0,Xe.current=w;return}if(he.current){he.current=!1,Xe.current=w;return}Xe.current!==w&&(et(w,"push"),Xe.current=w)},[w,et]),s.useEffect(()=>{const t=n=>{var k,M;const l=(M=(k=n.state)==null?void 0:k.__flatAgentNav)==null?void 0:M.agentId;if(!l||typeof l!="string"||!Ne.has(l)||l===w)return;he.current=!0,Ve.current=!0;const x=fe.current,_=x.lastIndexOf(l);_>=0?O.current=_:(x.push(l),O.current=x.length-1),B(),g.selectAgent(l)};return window.addEventListener("popstate",t),()=>window.removeEventListener("popstate",t)},[Ne,w,B]),s.useEffect(()=>{if(!w){fe.current=[],O.current=-1,B();return}if(ct.current=w,Vt(y.LAST_OPENED_AGENT,w),Ve.current){Ve.current=!1,B();return}const t=fe.current,n=O.current;if(n>=0&&t[n]===w){B();return}const l=n<t.length-1?t.slice(0,n+1):t.slice();l.push(w),l.length>100&&l.shift(),fe.current=l,O.current=l.length-1,B()},[w,B]);const mt=s.useCallback(t=>{c(t),me(!1)},[c]),Ft=w??"",ze=s.useCallback(()=>{},[]),kt=s.useCallback(t=>{mt(t)},[mt]),xe=Be,[tt,at]=s.useState(xe),[pt,be]=s.useState(xe);s.useEffect(()=>{if(xe){at(!0);return}be(!1);const t=setTimeout(()=>at(!1),240);return()=>clearTimeout(t)},[xe]),s.useEffect(()=>{if(!tt||!xe)return;let t=0;const n=requestAnimationFrame(()=>{t=requestAnimationFrame(()=>be(!0))});return()=>{cancelAnimationFrame(n),cancelAnimationFrame(t)}},[tt,xe]);const ft=s.useRef(null);s.useEffect(()=>{if(w)return;const t=n=>{if(n.key!==" "&&n.key!=="Backspace")return;const l=n.target;if(l.tagName==="INPUT"||l.tagName==="TEXTAREA"||l.isContentEditable)return;const x=ct.current;!x||!Ne.has(x)||(n.preventDefault(),g.selectAgent(x))};return document.addEventListener("keydown",t),()=>document.removeEventListener("keydown",t)},[w,Ne]);const[Ae,nt]=s.useState(new Set),Nt=s.useCallback(t=>{nt(n=>{const l=new Set(n);return l.has(t)?l.delete(t):l.add(t),l})},[]),yt=s.useCallback(t=>{nt(new Set(t))},[]),[a,o]=s.useState(()=>typeof window<"u"&&window.matchMedia("(max-width: 768px)").matches);s.useEffect(()=>{if(typeof window>"u")return;const t=window.matchMedia("(max-width: 768px)"),n=l=>o(l.matches);return t.addEventListener("change",n),()=>t.removeEventListener("change",n)},[]);const[i,m]=s.useState(null),X=s.useCallback(t=>{m(n=>n===t?null:t)},[]),Q=ga(),L=xa(),[st]=za(),ae=s.useMemo(()=>{if(w)return Vn;const t=new Map,n=[];for(const h of v){const C=g.getAreaForAgent(h.id);if(!sa((C==null?void 0:C.id)??null))continue;if(!C||C.archived){n.push(h);continue}const P=t.get(C.id);P?P.push(h):t.set(C.id,[h])}const l=new Map,x=[];for(const h of L.values()){let C=!1;for(const P of Q.values())if(!P.archived&&ia(P.id)&&g.isPositionInArea(h.position,P)){const le=l.get(P.id);le?le.push(h):l.set(P.id,[h]),C=!0;break}!C&&sa(null)&&x.push(h)}const _=[];for(const[,h]of Q){if(h.archived||!ia(h.id))continue;const C=t.get(h.id),P=l.get(h.id)??[];(C&&C.length>0||P.length>0)&&_.push({area:h,agents:C??[],buildings:P})}(n.length>0||x.length>0)&&_.push({area:{id:"__unassigned__",name:"Unassigned",color:"#6272a4",center:{x:0,z:0},type:"circle",radius:0,directories:[],archived:!1,assignedAgentIds:[],zIndex:0},agents:n,buildings:x});const k=_.filter(h=>h.area.id!=="__unassigned__"),M=_.filter(h=>h.area.id==="__unassigned__");let G=1,F=1;const f=new Map;if(k.length>1){let h=1/0,C=-1/0,P=1/0,le=-1/0;for(const q of k)h=Math.min(h,q.area.center.x),C=Math.max(C,q.area.center.x),P=Math.min(P,q.area.center.z),le=Math.max(le,q.area.center.z);const Se=C-h||1,St=le-P||1;if(k.length<=4){G=k.length,F=1;const q=[...k].sort((Y,Wt)=>Y.area.center.x-Wt.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=[...k].sort((S,W)=>S.area.center.x-W.area.center.x),Y=[];for(let S=1;S<q.length;S++)Y.push(q[S].area.center.x-q[S-1].area.center.x);const Wt=Y.reduce((S,W)=>S+W,0)/Y.length||1;let Qt=1;for(const S of Y)S>Wt*1.3&&Qt++;G=Math.max(2,Math.min(Qt,k.length));const Ht=[...k].sort((S,W)=>S.area.center.z-W.area.center.z),Et=[];for(let S=1;S<Ht.length;S++)Et.push(Ht[S].area.center.z-Ht[S-1].area.center.z);const ka=Et.reduce((S,W)=>S+W,0)/Et.length||1;let ea=1;for(const S of Et)S>ka*1.3&&ea++;F=Math.max(2,Math.min(ea,k.length)),G=Math.max(G,Math.ceil(k.length/F)),F=Math.max(F,Math.ceil(k.length/G));const Na=Se/G,ya=St/F,Ut=new Set;for(const S of k){let W=Math.min(G-1,Math.max(0,Math.floor((S.area.center.x-h)/Na))),Ke=Math.min(F-1,Math.max(0,Math.floor((S.area.center.z-P)/ya))),ht=`${Ke},${W}`,ta=0;const Aa=F*G;for(;Ut.has(ht)&&ta<Aa;)W++,W>=G&&(W=0,Ke=(Ke+1)%F),ht=`${Ke},${W}`,ta++;Ut.has(ht)&&(Ke=F,W=0,ht=`${Ke},${W}`,F++),Ut.add(ht),f.set(S.area.id,{row:Ke+1,col:W+1})}}}const ee=h=>{h.sort((C,P)=>{var Se,St,q,Y;const le=(((Se=C.position)==null?void 0:Se.z)??0)-(((St=P.position)==null?void 0:St.z)??0);return le!==0?le:(((q=C.position)==null?void 0:q.x)??0)-(((Y=P.position)==null?void 0:Y.x)??0)})};for(const h of k)ee(h.agents);for(const h of M)ee(h.agents);const V=[...k,...M].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(),V.forEach((h,C)=>{f.set(h.area.id,{row:Math.floor(C/G)+1,col:C%G+1})}),F=Math.max(1,Math.ceil(V.length/G)),{groups:V,gridCols:G,gridRows:F,positions:f}},[v,Q,L,st,w]),Ye=s.useMemo(()=>{let t=0,n=0;for(const l of ae.groups)t+=l.agents.length,n+=l.agents.filter(x=>x.status==="working").length;return{areaCount:ae.groups.length,agentCount:t,workingCount:n}},[ae]),ne=s.useMemo(()=>{if(!we)return[];const t=v.find(n=>n.id===we.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:()=>{Ie({agentId:t.id,name:t.name})}}]:[]},[we,v,c]),U=s.useMemo(()=>{var k;if(!u)return[];const t=L.get(u.buildingId);if(!t)return[];const n=[],l=t.type==="server"||t.type==="docker"||t.type==="terminal",x=t.status==="running",_=t.type==="boss";if(n.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"&&((k=t.pm2)!=null&&k.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:()=>ot(t.id)}),l&&(x||n.push({id:"start",label:"Start",icon:e.jsx(d,{name:"play",size:14}),onClick:()=>g.sendBuildingCommand(t.id,"start")}),x&&(n.push({id:"restart",label:"Restart",icon:e.jsx(d,{name:"refresh",size:14}),onClick:()=>g.sendBuildingCommand(t.id,"restart")}),n.push({id:"stop",label:"Stop",icon:e.jsx(d,{name:"stop",size:14}),onClick:()=>g.sendBuildingCommand(t.id,"stop")}))),_&&t.subordinateBuildingIds&&t.subordinateBuildingIds.length>0&&(n.push({id:"start-all",label:"Start All Subordinates",icon:e.jsx(d,{name:"launch",size:14}),onClick:()=>{for(const M of t.subordinateBuildingIds)g.sendBuildingCommand(M,"start")}}),n.push({id:"stop-all",label:"Stop All Subordinates",icon:e.jsx(d,{name:"pause",size:14}),onClick:()=>{for(const M of t.subordinateBuildingIds)g.sendBuildingCommand(M,"stop")}}),n.push({id:"restart-all",label:"Restart All Subordinates",icon:e.jsx(d,{name:"restart",size:14}),onClick:()=>{for(const M of t.subordinateBuildingIds)g.sendBuildingCommand(M,"restart")}})),l&&n.push({id:"health-check",label:"Health Check",icon:e.jsx(d,{name:"health",size:14}),onClick:()=>g.sendBuildingCommand(t.id,"healthCheck")}),n.push({id:"divider-edit",label:"",divider:!0,onClick:()=>{}}),n.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}}))}}),n.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 M of t.urls)n.push({id:`url-${M.label}`,label:M.label,icon:e.jsx(d,{name:"link",size:14}),onClick:()=>window.open(M.url,"_blank","noopener,noreferrer")});return n.push({id:"divider-danger",label:"",divider:!0,onClick:()=>{}}),n.push({id:"delete",label:"Delete Building",icon:e.jsx(d,{name:"trash",size:14}),danger:!0,onClick:()=>g.deleteBuilding(t.id)}),n},[u,L,ot]),At=s.useCallback(t=>{nt(new Set([t])),requestAnimationFrame(()=>{const n=ft.current;if(!n)return;const l=n.querySelector(`[data-area-id="${t}"]`);if(!l)return;const x=n.getBoundingClientRect(),k=l.getBoundingClientRect().top-x.top+n.scrollTop-8;n.scrollTo({top:Math.max(0,k),behavior:"smooth"})})},[]);return e.jsxs("div",{ref:Fe,className:`flat-view ${xe?"flat-view--with-inspector":""} ${w?"flat-view--has-chat":""} ${$?"flat-view--mobile-sidebar-open":""}`,style:(()=>{if(pe===null&&Z===null)return;const t={};return pe!==null&&(t["--flat-middle-width"]=`${pe}px`),Z!==null&&(t["--flat-inspector-width"]=`${Z}px`),t})(),children:[$&&e.jsx("div",{className:"flat-mobile-sidebar-backdrop",onClick:wt,"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:I,title:"Create new agent",children:"+ Agent"}),e.jsx("button",{className:"flat-cta-btn flat-cta-btn--boss",onClick:E,title:"Create new boss agent",children:"+ Boss"}),e.jsx("button",{className:"flat-cta-btn flat-cta-btn--area",onClick:A,title:"Create new area",children:"+ Area"})]})}),e.jsx("div",{className:"flat-middle__content",children:e.jsx(Oa,{activeAgentId:Ft,onClose:ze,onSelectAgent:kt,expandedAreas:Ae,onToggleArea:Nt,onSetExpandedAreas:yt,agentListRef:ft})})]}),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:Pt,onPointerMove:rt,onPointerUp:Pe,onPointerCancel:Pe,onDoubleClick:$e}),e.jsxs("div",{className:"flat-right",children:[e.jsxs("button",{type:"button",className:"flat-mobile-sidebar-toggle","aria-label":$?"Close agents sidebar":"Open agents sidebar","aria-expanded":$,onClick:lt,children:[e.jsx(d,{name:"list",size:18}),e.jsx("span",{className:"flat-mobile-sidebar-toggle__label",children:"Agents"})]}),w?e.jsx(Gn,{agentId:w,terminalViewMode:Je,onTerminalViewModeChange:Qe,inspectorOpen:Be,onToggleInspector:De,onShowTaskBoard:$t,onImageClick:Ge,onFileClick:Dt,onBashClick:ke,onViewMarkdown:Rt,onRequestClearSubordinates:zt,keyboard:z,canNavigateBack:Ot,canNavigateForward:Ct,onNavigateBack:ye,onNavigateForward:ut,agentInfoOpen:Ze,onToggleAgentInfo:Lt,onHeaderContextMenu:vt,onBuildingContextMenu:Re}):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:[Ye.areaCount," areas"]}),e.jsxs("span",{children:[Ye.agentCount," agents"]}),Ye.workingCount>0&&e.jsxs("span",{className:"flat-map__stats-working",children:[e.jsx("span",{className:"flat-map__stats-dot","aria-hidden":"true"}),Ye.workingCount," working"]})]}),e.jsx(Rn,{className:"flat-map__view-mode"})]}),e.jsx("div",{className:"flat-map__grid",style:{gridTemplateColumns:a?"repeat(2, minmax(0, 1fr))":`repeat(${ae.gridCols}, 1fr)`},children:ae.groups.length===0?e.jsx("div",{className:"flat-map__empty",children:e.jsx("span",{children:"No areas or agents yet"})}):(a?[...ae.groups].sort((n,l)=>{const x=ae.positions.get(n.area.id),_=ae.positions.get(l.area.id);return!x&&!_?0:x?_?x.row-_.row||x.col-_.col:-1:1}):ae.groups).map(n=>{var F;const l=n.area.id,x=ae.positions.get(l),_=n.agents.filter(f=>f.status==="working").length,k=_>0,M=a&&i!==l,G=a&&!M;return e.jsxs("div",{className:`flat-map-area-card${k?" flat-map-area-card--working":""}${M?" flat-map-area-card--collapsed":""}${G?" flat-map-area-card--expanded":""}`,style:{"--area-color":n.area.color,gridRow:a||x==null?void 0:x.row,gridColumn:a||x==null?void 0:x.col},onContextMenu:f=>{N&&(f.preventDefault(),f.stopPropagation(),N(l,{x:f.clientX,y:f.clientY}))},children:[e.jsxs("button",{type:"button",className:"flat-map-area-card__header",onClick:()=>a?X(l):At(l),title:a?M?`Expand ${n.area.name}`:`Collapse ${n.area.name}`:`Focus ${n.area.name} in left panel`,"aria-expanded":a?!M:void 0,children:[e.jsx("span",{className:"flat-map-area-card__color",style:{background:n.area.color}}),((F=n.area.logo)==null?void 0:F.filename)&&e.jsx("img",{className:"flat-map-area-card__logo",src:Sn(n.area.logo.filename),alt:"","aria-hidden":"true",onError:f=>{f.currentTarget.style.display="none"}}),e.jsx("span",{className:"flat-map-area-card__name",children:n.area.name}),e.jsxs("span",{className:"flat-map-area-card__count",title:`${n.agents.length} agent${n.agents.length===1?"":"s"}`,"aria-label":`${n.agents.length} agent${n.agents.length===1?"":"s"}`,children:[e.jsx(d,{name:"users",size:10}),n.agents.length]}),k&&e.jsxs("span",{className:"flat-map-area-card__working",title:`${_} working agent${_===1?"":"s"}`,"aria-label":`${_} working agent${_===1?"":"s"}`,children:[e.jsxs("span",{className:"flat-map-area-card__working-bars","aria-hidden":"true",children:[e.jsx("i",{}),e.jsx("i",{}),e.jsx("i",{})]}),e.jsx("span",{className:"flat-map-area-card__working-count",children:_})]}),a&&e.jsx(d,{name:M?"caret-down":"caret-up",size:11,className:"flat-map-area-card__caret"})]}),e.jsx("div",{className:"flat-map-area-card__agents",children:n.agents.map(f=>{const ee=f.isBoss||f.class==="boss",V=ee?qe.get(f.id):void 0,h=Ba(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)`,le=f.latestTodos&&f.latestTodos.length>0||V&&V.length>0;return e.jsx(Fa,{todos:f.latestTodos,subordinates:V,position:"top",children:e.jsxs("button",{type:"button",className:`flat-map-agent-chip ${f.status}`,onClick:()=>c(f.id),onContextMenu:Se=>{Se.preventDefault(),Se.stopPropagation(),ve({agentId:f.id,position:{x:Se.clientX,y:Se.clientY}})},title:le?void 0:`${ee?"Boss · ":""}Open chat with ${f.name}
|
|
2
|
+
${P}`,children:[e.jsx(ba,{agent:f,size:16}),ee&&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("img",{src:wa(f.provider,"/"),alt:f.provider,className:"flat-map-agent-chip__provider-icon",title:_a(f.provider)}),e.jsx("span",{className:"flat-map-agent-chip__dot",style:{backgroundColor:va(f.status)}}),f.latestTodos&&f.latestTodos.length>0&&e.jsx(Wa,{todos:f.latestTodos,maxDots:6}),ee&&V&&V.length>0&&e.jsx(Ha,{subordinates:V,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)})}),n.area.directories.length>0&&e.jsx("div",{className:"flat-map-area-card__folders",role:"group","aria-label":`${n.area.name} folders`,children:n.area.directories.map(f=>{const ee=f.split("/").filter(Boolean).pop()||f;return e.jsxs("button",{type:"button",className:"flat-map-folder-chip",onClick:V=>{V.stopPropagation(),g.openFileExplorerForAreaFolder(l,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:ee})]},f)})}),n.buildings.length>0&&e.jsx("div",{className:"flat-map-area-card__buildings",children:n.buildings.map(f=>{var V;const ee=(V=Ua[f.type])==null?void 0:V.color;return e.jsxs("button",{type:"button",className:`flat-map-building-chip flat-map-building-chip--${f.status}`,style:ee?{"--building-type-color":ee}:void 0,onClick:h=>{if(b){const C=h.currentTarget.getBoundingClientRect();b(f.id,{x:C.right,y:C.top+C.height/2})}else ot(f.id)},onContextMenu:h=>{h.preventDefault(),h.stopPropagation(),R({buildingId:f.id,position:{x:h.clientX,y:h.clientY}})},title:`${f.name} · ${f.type} · ${f.status}`,children:[e.jsx(d,{name:Ga(f.type),size:12,color:ee}),e.jsx("span",{className:"flat-map-building-chip__name",children:f.name}),e.jsx("span",{className:"flat-map-building-chip__dot",style:{backgroundColor:Va(f.status)}})]},f.id)})})]},l)})})]})})]}),xe&&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:Ce,onPointerMove:rt,onPointerUp:Pe,onPointerCancel:Pe,onDoubleClick:j}),tt&&e.jsxs("aside",{className:`flat-inspector ${pt?"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":te==="agent",className:`flat-inspector__tab ${te==="agent"?"flat-inspector__tab--active":""}`,onClick:()=>He("agent"),children:"Agent"}),e.jsx("button",{type:"button",role:"tab","aria-selected":te==="tracking",className:`flat-inspector__tab ${te==="tracking"?"flat-inspector__tab--active":""}`,onClick:()=>He("tracking"),children:"Tracking"})]}),e.jsx("button",{type:"button",className:"flat-inspector__close",onClick:Ue,title:"Close inspector","aria-label":"Close inspector",children:"✕"})]}),e.jsx("div",{className:"flat-inspector__body",children:te==="tracking"?e.jsx(Xa,{activeAgentId:w??"",onSelectAgent:t=>{c(t),window.innerWidth<=768&&Ue()}}):(()=>{if(!w)return e.jsx("div",{className:"flat-inspector__empty",children:e.jsx("span",{children:"Select an agent to inspect"})});const t=v.find(n=>n.id===w);return t?e.jsx(qa,{agent:t,onFocusAgent:n=>{c(n),window.innerWidth<=768&&Ue()},onKillAgent:n=>g.killAgent(n)}):e.jsx("div",{className:"flat-inspector__empty",children:e.jsx("span",{children:"Agent not found"})})})()})]}),D&&e.jsx(Ya,{url:D.url,name:D.name,onClose:()=>re(null)}),T&&e.jsx(Ka,{state:T,onClose:()=>Ee(null)}),e.jsx(Za,{agent:w?v.find(t=>t.id===w)??null:null,content:oe,onClose:()=>ce(null)}),Oe&&e.jsx(Ja,{action:"clear-subordinates",selectedAgentId:Oe.agentId,subordinateCount:Oe.count,onClose:()=>bt(null),onClearHistory:()=>{}}),e.jsx(Qa,{agent:w?v.find(t=>t.id===w)??null:null,isOpen:Ze&&!!w,onClose:_t}),e.jsx(la,{isOpen:we!==null,position:(we==null?void 0:we.position)??{x:0,y:0},worldPosition:{x:0,z:0},actions:ne,onClose:()=>ve(null)}),e.jsx(la,{isOpen:u!==null,position:(u==null?void 0:u.position)??{x:0,y:0},worldPosition:{x:0,z:0},actions:U,onClose:()=>R(null)}),e.jsx(en,{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:()=>Ie(null)})]})}export{Zn as FlatView};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{c as At,d as yt,x as Et,_ as xt,f as Ct,bH as Mt,bI as wt,a6 as Ft,r as d,w as St,S as pe,bJ as bt,bK as fe,s as Y,bL as Bt,j as f,I as ne,T as Ye,bM as vt,n as It,bN as _t,bO as Dt,bP as Ee,R as Be,m as Rt,bQ as nt,u as we,bR as Je}from"./main-D0DYgXWa.js";import{bS as Ls,bT as $s,bU as js,bV as Ns,bW as Ps}from"./main-D0DYgXWa.js";import"./vendor-react--Eh9ivFN.js";import"./vendor-three-3OKhI9bz.js";function re(t){return Array.isArray?Array.isArray(t):ct(t)==="[object Array]"}function kt(t){if(typeof t=="string")return t;let e=t+"";return e=="0"&&1/t==-1/0?"-0":e}function Tt(t){return t==null?"":kt(t)}function q(t){return typeof t=="string"}function rt(t){return typeof t=="number"}function Lt(t){return t===!0||t===!1||$t(t)&&ct(t)=="[object Boolean]"}function it(t){return typeof t=="object"}function $t(t){return it(t)&&t!==null}function Q(t){return t!=null}function ve(t){return!t.trim().length}function ct(t){return t==null?t===void 0?"[object Undefined]":"[object Null]":Object.prototype.toString.call(t)}const jt="Incorrect 'index' type",Nt=t=>`Invalid value for key ${t}`,Pt=t=>`Pattern length exceeds max of ${t}.`,Kt=t=>`Missing ${t} property in key`,Ot=t=>`Property 'weight' in key '${t}' must be a positive integer`,Xe=Object.prototype.hasOwnProperty;class zt{constructor(e){this._keys=[],this._keyMap={};let n=0;e.forEach(r=>{let i=ot(r);this._keys.push(i),this._keyMap[i.id]=i,n+=i.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 ot(t){let e=null,n=null,r=null,i=1,c=null;if(q(t)||re(t))r=t,e=Ze(t),n=Ie(t);else{if(!Xe.call(t,"name"))throw new Error(Kt("name"));const o=t.name;if(r=o,Xe.call(t,"weight")&&(i=t.weight,i<=0))throw new Error(Ot(o));e=Ze(o),n=Ie(o),c=t.getFn}return{path:e,id:n,weight:i,src:r,getFn:c}}function Ze(t){return re(t)?t:t.split(".")}function Ie(t){return re(t)?t.join("."):t}function Qt(t,e){let n=[],r=!1;const i=(c,o,a)=>{if(Q(c))if(!o[a])n.push(c);else{let u=o[a];const l=c[u];if(!Q(l))return;if(a===o.length-1&&(q(l)||rt(l)||Lt(l)))n.push(Tt(l));else if(re(l)){r=!0;for(let h=0,E=l.length;h<E;h+=1)i(l[h],o,a+1)}else o.length&&i(l,o,a+1)}};return i(t,q(e)?e.split("."):e,0),r?n:n[0]}const Gt={includeMatches:!1,findAllMatches:!1,minMatchCharLength:1},Wt={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},Ht={location:0,threshold:.6,distance:100},Ut={useExtendedSearch:!1,getFn:Qt,ignoreLocation:!1,ignoreFieldNorm:!1,fieldNormWeight:1};var y={...Wt,...Gt,...Ht,...Ut};const Vt=/[^ ]+/g;function Yt(t=1,e=3){const n=new Map,r=Math.pow(10,e);return{get(i){const c=i.match(Vt).length;if(n.has(c))return n.get(c);const o=1/Math.pow(c,.5*t),a=parseFloat(Math.round(o*r)/r);return n.set(c,a),a},clear(){n.clear()}}}class Le{constructor({getFn:e=y.getFn,fieldNormWeight:n=y.fieldNormWeight}={}){this.norm=Yt(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,q(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();q(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(!Q(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((i,c)=>{let o=i.getFn?i.getFn(e):this.getFn(e,i.path);if(Q(o)){if(re(o)){let a=[];const u=[{nestedArrIndex:-1,value:o}];for(;u.length;){const{nestedArrIndex:l,value:h}=u.pop();if(Q(h))if(q(h)&&!ve(h)){let E={v:h,i:l,n:this.norm.get(h)};a.push(E)}else re(h)&&h.forEach((E,C)=>{u.push({nestedArrIndex:C,value:E})})}r.$[c]=a}else if(q(o)&&!ve(o)){let a={v:o,n:this.norm.get(o)};r.$[c]=a}}}),this.records.push(r)}toJSON(){return{keys:this.keys,records:this.records}}}function at(t,e,{getFn:n=y.getFn,fieldNormWeight:r=y.fieldNormWeight}={}){const i=new Le({getFn:n,fieldNormWeight:r});return i.setKeys(t.map(ot)),i.setSources(e),i.create(),i}function Jt(t,{getFn:e=y.getFn,fieldNormWeight:n=y.fieldNormWeight}={}){const{keys:r,records:i}=t,c=new Le({getFn:e,fieldNormWeight:n});return c.setKeys(r),c.setIndexRecords(i),c}function xe(t,{errors:e=0,currentLocation:n=0,expectedLocation:r=0,distance:i=y.distance,ignoreLocation:c=y.ignoreLocation}={}){const o=e/t.length;if(c)return o;const a=Math.abs(r-n);return i?o+a/i:a?1:o}function Xt(t=[],e=y.minMatchCharLength){let n=[],r=-1,i=-1,c=0;for(let o=t.length;c<o;c+=1){let a=t[c];a&&r===-1?r=c:!a&&r!==-1&&(i=c-1,i-r+1>=e&&n.push([r,i]),r=-1)}return t[c-1]&&c-r>=e&&n.push([r,c-1]),n}const le=32;function Zt(t,e,n,{location:r=y.location,distance:i=y.distance,threshold:c=y.threshold,findAllMatches:o=y.findAllMatches,minMatchCharLength:a=y.minMatchCharLength,includeMatches:u=y.includeMatches,ignoreLocation:l=y.ignoreLocation}={}){if(e.length>le)throw new Error(Pt(le));const h=e.length,E=t.length,C=Math.max(0,Math.min(r,E));let g=c,p=C;const S=a>1||u,F=S?Array(E):[];let T;for(;(T=t.indexOf(e,p))>-1;){let $=xe(e,{currentLocation:T,expectedLocation:C,distance:i,ignoreLocation:l});if(g=Math.min($,g),p=T+h,S){let N=0;for(;N<h;)F[T+N]=1,N+=1}}p=-1;let j=[],G=1,W=h+E;const oe=1<<h-1;for(let $=0;$<h;$+=1){let N=0,_=W;for(;N<_;)xe(e,{errors:$,currentLocation:C+_,expectedLocation:C,distance:i,ignoreLocation:l})<=g?N=_:W=_,_=Math.floor((W-N)/2+N);W=_;let ae=Math.max(1,C-_+1),H=o?E:Math.min(C+_,E)+h,b=Array(H+2);b[H+1]=(1<<$)-1;for(let R=H;R>=ae;R-=1){let X=R-1,O=n[t.charAt(X)];if(S&&(F[X]=+!!O),b[R]=(b[R+1]<<1|1)&O,$&&(b[R]|=(j[R+1]|j[R])<<1|1|j[R+1]),b[R]&oe&&(G=xe(e,{errors:$,currentLocation:X,expectedLocation:C,distance:i,ignoreLocation:l}),G<=g)){if(g=G,p=X,p<=C)break;ae=Math.max(1,2*C-p)}}if(xe(e,{errors:$+1,currentLocation:C,expectedLocation:C,distance:i,ignoreLocation:l})>g)break;j=b}const ie={isMatch:p>=0,score:Math.max(.001,G)};if(S){const $=Xt(F,a);$.length?u&&(ie.indices=$):ie.isMatch=!1}return ie}function qt(t){let e={};for(let n=0,r=t.length;n<r;n+=1){const i=t.charAt(n);e[i]=(e[i]||0)|1<<r-n-1}return e}const Ce=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 ut{constructor(e,{location:n=y.location,threshold:r=y.threshold,distance:i=y.distance,includeMatches:c=y.includeMatches,findAllMatches:o=y.findAllMatches,minMatchCharLength:a=y.minMatchCharLength,isCaseSensitive:u=y.isCaseSensitive,ignoreDiacritics:l=y.ignoreDiacritics,ignoreLocation:h=y.ignoreLocation}={}){if(this.options={location:n,threshold:r,distance:i,includeMatches:c,findAllMatches:o,minMatchCharLength:a,isCaseSensitive:u,ignoreDiacritics:l,ignoreLocation:h},e=u?e:e.toLowerCase(),e=l?Ce(e):e,this.pattern=e,this.chunks=[],!this.pattern.length)return;const E=(g,p)=>{this.chunks.push({pattern:g,alphabet:qt(g),startIndex:p})},C=this.pattern.length;if(C>le){let g=0;const p=C%le,S=C-p;for(;g<S;)E(this.pattern.substr(g,le),g),g+=le;if(p){const F=C-le;E(this.pattern.substr(F),F)}}else E(this.pattern,0)}searchIn(e){const{isCaseSensitive:n,ignoreDiacritics:r,includeMatches:i}=this.options;if(e=n?e:e.toLowerCase(),e=r?Ce(e):e,this.pattern===e){let S={isMatch:!0,score:0};return i&&(S.indices=[[0,e.length-1]]),S}const{location:c,distance:o,threshold:a,findAllMatches:u,minMatchCharLength:l,ignoreLocation:h}=this.options;let E=[],C=0,g=!1;this.chunks.forEach(({pattern:S,alphabet:F,startIndex:T})=>{const{isMatch:j,score:G,indices:W}=Zt(e,S,F,{location:c+T,distance:o,threshold:a,findAllMatches:u,minMatchCharLength:l,includeMatches:i,ignoreLocation:h});j&&(g=!0),C+=G,j&&W&&(E=[...E,...W])});let p={isMatch:g,score:g?C/this.chunks.length:1};return g&&i&&(p.indices=E),p}}class ce{constructor(e){this.pattern=e}static isMultiMatch(e){return qe(e,this.multiRegex)}static isSingleMatch(e){return qe(e,this.singleRegex)}search(){}}function qe(t,e){const n=t.match(e);return n?n[1]:null}class es extends ce{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 ts extends ce{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 ss extends ce{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 ns extends ce{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 rs extends ce{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 is extends ce{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 lt extends ce{constructor(e,{location:n=y.location,threshold:r=y.threshold,distance:i=y.distance,includeMatches:c=y.includeMatches,findAllMatches:o=y.findAllMatches,minMatchCharLength:a=y.minMatchCharLength,isCaseSensitive:u=y.isCaseSensitive,ignoreDiacritics:l=y.ignoreDiacritics,ignoreLocation:h=y.ignoreLocation}={}){super(e),this._bitapSearch=new ut(e,{location:n,threshold:r,distance:i,includeMatches:c,findAllMatches:o,minMatchCharLength:a,isCaseSensitive:u,ignoreDiacritics:l,ignoreLocation:h})}static get type(){return"fuzzy"}static get multiRegex(){return/^"(.*)"$/}static get singleRegex(){return/^(.*)$/}search(e){return this._bitapSearch.searchIn(e)}}class ht extends ce{constructor(e){super(e)}static get type(){return"include"}static get multiRegex(){return/^'"(.*)"$/}static get singleRegex(){return/^'(.*)$/}search(e){let n=0,r;const i=[],c=this.pattern.length;for(;(r=e.indexOf(this.pattern,n))>-1;)n=r+c,i.push([r,n-1]);const o=!!i.length;return{isMatch:o,score:o?0:1,indices:i}}}const _e=[es,ht,ss,ns,is,rs,ts,lt],et=_e.length,cs=/ +(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)/,os="|";function as(t,e={}){return t.split(os).map(n=>{let r=n.trim().split(cs).filter(c=>c&&!!c.trim()),i=[];for(let c=0,o=r.length;c<o;c+=1){const a=r[c];let u=!1,l=-1;for(;!u&&++l<et;){const h=_e[l];let E=h.isMultiMatch(a);E&&(i.push(new h(E,e)),u=!0)}if(!u)for(l=-1;++l<et;){const h=_e[l];let E=h.isSingleMatch(a);if(E){i.push(new h(E,e));break}}}return i})}const us=new Set([lt.type,ht.type]);class ls{constructor(e,{isCaseSensitive:n=y.isCaseSensitive,ignoreDiacritics:r=y.ignoreDiacritics,includeMatches:i=y.includeMatches,minMatchCharLength:c=y.minMatchCharLength,ignoreLocation:o=y.ignoreLocation,findAllMatches:a=y.findAllMatches,location:u=y.location,threshold:l=y.threshold,distance:h=y.distance}={}){this.query=null,this.options={isCaseSensitive:n,ignoreDiacritics:r,includeMatches:i,minMatchCharLength:c,findAllMatches:a,ignoreLocation:o,location:u,threshold:l,distance:h},e=n?e:e.toLowerCase(),e=r?Ce(e):e,this.pattern=e,this.query=as(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:i,ignoreDiacritics:c}=this.options;e=i?e:e.toLowerCase(),e=c?Ce(e):e;let o=0,a=[],u=0;for(let l=0,h=n.length;l<h;l+=1){const E=n[l];a.length=0,o=0;for(let C=0,g=E.length;C<g;C+=1){const p=E[C],{isMatch:S,indices:F,score:T}=p.search(e);if(S){if(o+=1,u+=T,r){const j=p.constructor.type;us.has(j)?a=[...a,...F]:a.push(F)}}else{u=0,o=0,a.length=0;break}}if(o){let C={isMatch:!0,score:u/o};return r&&(C.indices=a),C}}return{isMatch:!1,score:1}}}const De=[];function hs(...t){De.push(...t)}function Re(t,e){for(let n=0,r=De.length;n<r;n+=1){let i=De[n];if(i.condition(t,e))return new i(t,e)}return new ut(t,e)}const Me={AND:"$and",OR:"$or"},ke={PATH:"$path",PATTERN:"$val"},Te=t=>!!(t[Me.AND]||t[Me.OR]),ds=t=>!!t[ke.PATH],fs=t=>!re(t)&&it(t)&&!Te(t),tt=t=>({[Me.AND]:Object.keys(t).map(e=>({[e]:t[e]}))});function dt(t,e,{auto:n=!0}={}){const r=i=>{let c=Object.keys(i);const o=ds(i);if(!o&&c.length>1&&!Te(i))return r(tt(i));if(fs(i)){const u=o?i[ke.PATH]:c[0],l=o?i[ke.PATTERN]:i[u];if(!q(l))throw new Error(Nt(u));const h={keyId:Ie(u),pattern:l};return n&&(h.searcher=Re(l,e)),h}let a={children:[],operator:c[0]};return c.forEach(u=>{const l=i[u];re(l)&&l.forEach(h=>{a.children.push(r(h))})}),a};return Te(t)||(t=tt(t)),r(t)}function gs(t,{ignoreFieldNorm:e=y.ignoreFieldNorm}){t.forEach(n=>{let r=1;n.matches.forEach(({key:i,norm:c,score:o})=>{const a=i?i.weight:null;r*=Math.pow(o===0&&a?Number.EPSILON:o,(a||1)*(e?1:c))}),n.score=r})}function ps(t,e){const n=t.matches;e.matches=[],Q(n)&&n.forEach(r=>{if(!Q(r.indices)||!r.indices.length)return;const{indices:i,value:c}=r;let o={indices:i,value:c};r.key&&(o.key=r.key.src),r.idx>-1&&(o.refIndex=r.idx),e.matches.push(o)})}function ms(t,e){e.score=t.score}function As(t,e,{includeMatches:n=y.includeMatches,includeScore:r=y.includeScore}={}){const i=[];return n&&i.push(ps),r&&i.push(ms),t.map(c=>{const{idx:o}=c,a={item:e[o],refIndex:o};return i.length&&i.forEach(u=>{u(c,a)}),a})}class Z{constructor(e,n={},r){this.options={...y,...n},this.options.useExtendedSearch,this._keyStore=new zt(this.options.keys),this.setCollection(e,r)}setCollection(e,n){if(this._docs=e,n&&!(n instanceof Le))throw new Error(jt);this._myIndex=n||at(this.options.keys,this._docs,{getFn:this.options.getFn,fieldNormWeight:this.options.fieldNormWeight})}add(e){Q(e)&&(this._docs.push(e),this._myIndex.add(e))}remove(e=()=>!1){const n=[];for(let r=0,i=this._docs.length;r<i;r+=1){const c=this._docs[r];e(c,r)&&(this.removeAt(r),r-=1,i-=1,n.push(c))}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:i,shouldSort:c,sortFn:o,ignoreFieldNorm:a}=this.options;let u=q(e)?q(this._docs[0])?this._searchStringList(e):this._searchObjectList(e):this._searchLogical(e);return gs(u,{ignoreFieldNorm:a}),c&&u.sort(o),rt(n)&&n>-1&&(u=u.slice(0,n)),As(u,this._docs,{includeMatches:r,includeScore:i})}_searchStringList(e){const n=Re(e,this.options),{records:r}=this._myIndex,i=[];return r.forEach(({v:c,i:o,n:a})=>{if(!Q(c))return;const{isMatch:u,score:l,indices:h}=n.searchIn(c);u&&i.push({item:c,idx:o,matches:[{score:l,value:c,norm:a,indices:h}]})}),i}_searchLogical(e){const n=dt(e,this.options),r=(a,u,l)=>{if(!a.children){const{keyId:E,searcher:C}=a,g=this._findMatches({key:this._keyStore.get(E),value:this._myIndex.getValueForItemAtKeyId(u,E),searcher:C});return g&&g.length?[{idx:l,item:u,matches:g}]:[]}const h=[];for(let E=0,C=a.children.length;E<C;E+=1){const g=a.children[E],p=r(g,u,l);if(p.length)h.push(...p);else if(a.operator===Me.AND)return[]}return h},i=this._myIndex.records,c={},o=[];return i.forEach(({$:a,i:u})=>{if(Q(a)){let l=r(n,a,u);l.length&&(c[u]||(c[u]={idx:u,item:a,matches:[]},o.push(c[u])),l.forEach(({matches:h})=>{c[u].matches.push(...h)}))}}),o}_searchObjectList(e){const n=Re(e,this.options),{keys:r,records:i}=this._myIndex,c=[];return i.forEach(({$:o,i:a})=>{if(!Q(o))return;let u=[];r.forEach((l,h)=>{u.push(...this._findMatches({key:l,value:o[h],searcher:n}))}),u.length&&c.push({idx:a,item:o,matches:u})}),c}_findMatches({key:e,value:n,searcher:r}){if(!Q(n))return[];let i=[];if(re(n))n.forEach(({v:c,i:o,n:a})=>{if(!Q(c))return;const{isMatch:u,score:l,indices:h}=r.searchIn(c);u&&i.push({score:l,key:e,value:c,idx:o,norm:a,indices:h})});else{const{v:c,n:o}=n,{isMatch:a,score:u,indices:l}=r.searchIn(c);a&&i.push({score:u,key:e,value:c,norm:o,indices:l})}return i}}Z.version="7.1.0";Z.createIndex=at;Z.parseIndex=Jt;Z.config=y;Z.parseQuery=dt;hs(ls);async function ys(t){const e=new URLSearchParams({q:t}),n=await At(yt(`/api/folders/search?${e.toString()}`));if(!n.ok){const i=await n.json().catch(()=>({}));throw new Error(i.error||`Failed to search folders: ${n.statusText}`)}const r=await n.json();return Array.isArray(r.folders)?r.folders:[]}const Es=["command","agent","building","area","folder","modified-file"],xs=2;function Cs(){const t=nt(pe.SPOTLIGHT_TAB,"all");return fe.includes(t)?t:"all"}function st(){return Rt(pe.SPOTLIGHT_QUERY,"")}function Ms(){const t=nt(pe.AOP_CONFIG,{});return t.sortMode==="name"||t.sortMode==="status"||t.sortMode==="recent"?t.sortMode:"recent"}function ws({isOpen:t,onClose:e,onOpenSpawnModal:n,onOpenCommanderView:r,onOpenToolbox:i,onOpenFileExplorer:c,onOpenPM2LogsModal:o,onOpenBossLogsModal:a,onOpenDatabasePanel:u,onOpenMonitoringModal:l}){const h=Et(),E=xt(),C=Ct(),g=Mt(),p=wt(),S=Ft(),F=d.useRef(e);F.current=e;const T=d.useRef(n);T.current=n;const j=d.useRef(r);j.current=r;const G=d.useRef(i);G.current=i;const W=d.useRef(c);W.current=c;const oe=d.useRef(o);oe.current=o;const ie=d.useRef(a);ie.current=a;const $=d.useRef(u);$.current=u;const N=d.useRef(l);N.current=l;const[_,ae]=d.useState(st),[H,b]=d.useState(0),[M,R]=d.useState(Cs),[X,O]=d.useState([]),ft=d.useCallback(s=>{ae(s),St(pe.SPOTLIGHT_QUERY,s)},[]);d.useEffect(()=>{t&&(ae(st()),b(0))},[t]),d.useEffect(()=>{if(!t){O([]);return}const s=_.trim();if(s.length<xs){O([]);return}let m=!1;const w=setTimeout(()=>{ys(s).then(x=>{m||O(x)}).catch(()=>{m||O([])})},250);return()=>{m=!0,clearTimeout(w)}},[t,_]);const Fe=d.useCallback(s=>{R(s),bt(pe.SPOTLIGHT_TAB,s)},[]),$e=d.useRef(M);$e.current=M;const gt=d.useCallback(s=>{const m=fe.indexOf($e.current),w=fe[(m+s+fe.length)%fe.length];Fe(w)},[Fe]);d.useEffect(()=>{b(0)},[M]);const Se=Y.getShortcuts(),ge=d.useMemo(()=>t?Bt():{},[t]),me=d.useMemo(()=>{if(!t)return[];const s=window.matchMedia("(pointer: coarse)").matches,m=Se.find(x=>x.id==="spawn-agent"),w=Se.find(x=>x.id==="toggle-commander");return[{id:"cmd-spawn",type:"command",title:"Spawn New Agent",subtitle:s?"":m?Ye(m):"Alt+N",icon:f.jsx(ne,{name:"plus",size:16}),action:()=>{F.current(),T.current()}},{id:"cmd-commander",type:"command",title:"Commander View",subtitle:s?"":w!=null&&w.key?Ye(w):"Tab",icon:f.jsx(ne,{name:"dashboard",size:16}),action:()=>{F.current(),j.current()}},{id:"cmd-settings",type:"command",title:"Settings & Tools",subtitle:"Configure Tide Commander",icon:f.jsx(ne,{name:"gear",size:16}),action:()=>{F.current(),G.current()}},{id:"cmd-monitoring",type:"command",title:"Monitoring & Logs",subtitle:"Triggers, workflows, events",icon:f.jsx(ne,{name:"chart-line",size:16}),action:()=>{var x;F.current(),(x=N.current)==null||x.call(N)}}]},[t,Se]),he=d.useMemo(()=>t?Array.from(h.values()).map(s=>{const m=(g||[]).filter(V=>V.agentId===s.id).map(V=>V.filePath),w=[...new Set(m)],x=w.map(V=>V.split("/").pop()||V),B=[];s.lastAssignedTask&&B.push(s.lastAssignedTask);const L=`${s.class} • ${s.cwd}`;let D=`${s.name} ${s.class} ${s.status} ${s.cwd}`;s.taskLabel&&(D+=` ${s.taskLabel}`),x.length>0&&(D+=` ${x.join(" ")} ${w.join(" ")}`),B.length>0&&(D+=` ${B.join(" ")}`);const P=Date.now()-s.lastActivity;let U;return s.lastAssignedTask&&(s.lastAssignedTask.length>150?U=s.lastAssignedTask.slice(0,150)+"...":U=s.lastAssignedTask),{id:`agent-${s.id}`,type:"agent",title:s.name,subtitle:L,lastUserInput:U,timeAway:P,icon:f.jsx(It,{agent:s,size:20}),_searchText:D,_modifiedFiles:w,_userQueries:B,_agentId:s.id,_lastActivity:s.lastActivity,_taskLabel:s.taskLabel,_status:s.status,action:()=>{F.current(),vt(s.id),Y.selectAgent(s.id),Y.getState().viewMode!=="flat"&&Y.requestTerminalExpand()}}}):[],[t,h,g]),Ae=d.useMemo(()=>t?Array.from(E.values()).map(s=>{var m;return{id:`area-${s.id}`,type:"area",title:s.name,subtitle:`${s.assignedAgentIds.length} agents • ${((m=s.directories)==null?void 0:m.length)||0} folders`,icon:f.jsx(ne,{name:"map",size:16}),action:()=>{F.current(),Y.selectArea(s.id)}}}):[],[t,E]),je=d.useMemo(()=>{const s=new Map;for(const m of he)m._agentId&&s.set(m._agentId,m);return s},[he]),Ne=d.useMemo(()=>{const s=new Map;if(!t)return s;for(const m of h.values()){const w=Y.getAreaForAgent(m.id);if(!w||w.archived)continue;const x=s.get(w.id);x?x.push(m):s.set(w.id,[m])}return s},[t,h,E]),Pe=d.useMemo(()=>{const s=new Map;for(const m of p)s.has(m.agentId)||s.set(m.agentId,m.timestamp);return s},[p]),be=d.useMemo(()=>{if(!t)return[];const s=_.trim().toLowerCase(),m=_t({sortMode:Ms(),agentsWithUnseenOutput:S,getLatestToolTimestamp:B=>Pe.get(B)}),w=Array.from(E.values()).filter(B=>!B.archived).filter(B=>s?B.name.toLowerCase().includes(s):!0).sort((B,L)=>B.name.localeCompare(L.name,void 0,{sensitivity:"base"})),x=[];for(const B of w){const D=(Ne.get(B.id)||[]).slice().sort(m).map(P=>je.get(P.id)).filter(P=>!!P);!s&&D.length===0||x.push({areaId:B.id,areaName:B.name,areaColor:B.color,agents:D})}return x},[t,_,E,Ne,je,S,Pe]),ye=d.useMemo(()=>t?Array.from(C.values()).filter(s=>s.type==="server"||s.type==="boss"||s.type==="database"||s.type==="tests").map(s=>{var P,U,V,ue,ee;const m=s.status==="running"?"#4ade80":s.status==="stopped"?"#f87171":"#facc15",w=s.type==="boss"?"crown":s.type==="database"?"database":s.type==="tests"?"flask":"desktop",x=s.type==="boss"?"Boss":s.type==="database"?"Database":s.type==="tests"?"Tests":"Server";let B=`${x} • ${s.status}`;if(s.type==="database"&&((U=(P=s.database)==null?void 0:P.connections)!=null&&U.length)){const z=s.database.connections[0];B+=` • ${z.engine} @ ${z.host}`}else s.type==="tests"&&s.folderPath?B=`${x} • ${s.folderPath}`:s.cwd&&(B+=` • ${s.cwd}`);const L=((V=s.pm2Status)==null?void 0:V.ports)||[];let D=`${s.name} ${s.type} ${s.status} ${s.cwd||""} ${((ue=s.pm2)==null?void 0:ue.name)||""}`;if(s.type==="tests"&&(D+=` ${s.folderPath||""} tests junit maven`),L.length>0&&(D+=` ${L.join(" ")}`),s.type==="database"&&((ee=s.database)!=null&&ee.connections))for(const z of s.database.connections)D+=` ${z.name} ${z.engine} ${z.host} ${z.database||""} mysql postgresql sql`;return{id:`building-${s.id}`,type:"building",title:s.name,subtitle:B,_ports:L,icon:f.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:4},children:[f.jsx(ne,{name:"status-pending",size:10,weight:"fill",color:m}),f.jsx(ne,{name:w,size:16})]}),_searchText:D,action:()=>{var z;F.current(),s.type==="boss"?ie.current(s.id):s.type==="database"?$.current(s.id):s.type==="tests"?Y.openTestsBuilding(s.id):s.type==="http"?Y.openHttpBuilding(s.id):(z=s.pm2)!=null&&z.enabled&&oe.current(s.id)}}}):[],[t,C]),Ke=d.useMemo(()=>{if(!t)return[];const s=g||[],m=new Set,w=[];for(const x of s){if(m.has(x.filePath))continue;m.add(x.filePath);const B=x.filePath.split("/").pop()||x.filePath,L=x.action==="created"?"Created":x.action==="modified"?"Modified":x.action==="deleted"?"Deleted":"Read";if(w.push({id:`modified-${x.filePath}-${x.timestamp}`,type:"modified-file",title:B,subtitle:`${L} by ${x.agentName} • ${x.filePath}`,matchedText:x.filePath,icon:x.action==="deleted"?f.jsx(ne,{name:"trash",size:16}):Dt(x.filePath),action:()=>{F.current();const D=Array.from(Y.getState().areas.values());for(const P of D)for(const U of P.directories||[])if(x.filePath.startsWith(U)){Y.setFileViewerPath(x.filePath),W.current(P.id);return}Y.selectAgent(x.agentId)}}),w.length>=50)break}return w},[t,g]),Oe=d.useMemo(()=>t?X.map(s=>{const m=s.isGitRepo&&s.gitBranch?`${s.path} • ${s.gitBranch}`:s.path;return{id:`folder-${s.path}`,type:"folder",title:s.name,subtitle:m,matchedText:s.path,icon:f.jsx(ne,{name:s.isGitRepo?"git-branch":"folder",size:16}),_searchText:`${s.name} ${s.path}`,_isGitRepo:s.isGitRepo,_gitBranch:s.gitBranch,action:()=>{F.current(),Y.openFileExplorer(s.path)}}}):[],[t,X]),ze=d.useMemo(()=>new Z(he,{keys:["title","subtitle","_searchText","lastUserInput"],threshold:.4,ignoreLocation:!0,includeScore:!0,includeMatches:!0}),[he]),Qe=d.useMemo(()=>new Z(me,{keys:["title","subtitle"],threshold:.4,includeScore:!0,includeMatches:!0}),[me]),Ge=d.useMemo(()=>new Z(Ae,{keys:["title","subtitle"],threshold:.4,includeScore:!0,includeMatches:!0}),[Ae]),We=d.useMemo(()=>new Z(Ke,{keys:["title","subtitle","matchedText"],threshold:.4,ignoreLocation:!0,includeScore:!0,includeMatches:!0}),[Ke]),He=d.useMemo(()=>new Z(ye,{keys:["title","subtitle","_searchText"],threshold:.4,ignoreLocation:!0,includeScore:!0,includeMatches:!0}),[ye]),de=d.useMemo(()=>{if(!_.trim()){const A=[];A.push(...ye);const v=[...he].sort((k,K)=>{const te=Ee(k._agentId,k._lastActivity,ge);return Ee(K._agentId,K._lastActivity,ge)-te});A.push(...v),A.push(...me.slice(0,2)),A.push(...Ae.slice(0,2));const I={};return Es.forEach((k,K)=>{I[k]=K}),A.sort((k,K)=>(I[k.type]??999)-(I[K.type]??999)),A}const s=_.trim().toLowerCase(),m=ze.search(_).slice(0,8),w=Qe.search(_).slice(0,3),x=Ge.search(_).slice(0,2),B=We.search(_).slice(0,3),L=Oe.slice(0,8),D=He.search(_).filter(A=>{const v=A.score??1;return`${A.item.title} ${A.item.subtitle||""} ${A.item._searchText||""}`.toLowerCase().includes(s)||v<=.2}).slice(0,4),P={agent:6,building:5,folder:4,command:3,area:2,"modified-file":1},U=A=>{if(!s)return 1;const v=A.title.toLowerCase();return v===s?6:v.startsWith(s)?5:v.split(/[^a-z0-9]+/i).includes(s)?4:v.includes(s)?3:`${A.subtitle||""} ${A._searchText||""} ${A.matchedText||""}`.toLowerCase().includes(s)?2:1},V=(A,v)=>{const I=(1-Math.min(1,v??1))*4;return U(A)*100+(P[A.type]??0)*5+I},ue=new Map,ee=(A,v)=>{const I=ue.get(A.type),k={item:A,score:V(A,v)};I?I.push(k):ue.set(A.type,[k])};for(const A of m){const v={...A.item};if(v._modifiedFiles&&v._modifiedFiles.length>0){const I=v._modifiedFiles.filter(k=>{var se;const K=((se=k.split("/").pop())==null?void 0:se.toLowerCase())||"",te=k.toLowerCase();return K.includes(s)||te.includes(s)});I.length>0&&(v.matchedFiles=I)}if(v._userQueries&&v._userQueries.length>0){const I=v._userQueries.find(k=>k.toLowerCase().includes(s));if(I)if(I.length>200){const K=I.toLowerCase().indexOf(s),te=Math.max(0,K-60),se=Math.min(I.length,K+s.length+100);v.matchedQuery=(te>0?"...":"")+I.slice(te,se)+(se<I.length?"...":"")}else v.matchedQuery=I}ee(v,A.score)}for(const A of D)ee(A.item,A.score);for(const A of w)ee(A.item,A.score);for(const A of x)ee(A.item,A.score);for(const A of B)ee(A.item,A.score);for(const A of L)ee(A,void 0);for(const[A,v]of ue)A==="agent"?v.sort((I,k)=>{const K=U(I.item),te=U(k.item);if(te!==K)return te-K;const se=Ee(I.item._agentId,I.item._lastActivity,ge),Ve=Ee(k.item._agentId,k.item._lastActivity,ge);return Ve!==se?Ve-se:k.score-I.score}):v.sort((I,k)=>k.score-I.score);const z=A=>A.reduce((v,I)=>Math.max(v,I.score),-1),Ue=[];return Array.from(ue.values()).sort((A,v)=>z(v)-z(A)).forEach(A=>{for(const v of A)Ue.push(v.item)}),Ue},[_,ze,Qe,Ge,We,He,me,he,Ae,ye,Oe,ge]),J=d.useMemo(()=>{switch(M){case"agents":return de.filter(s=>s.type==="agent");case"buildings":return de.filter(s=>s.type==="building");case"commands":return de.filter(s=>s.type==="command");case"folders":return de.filter(s=>s.type==="folder");case"areas":return be.flatMap(s=>s.agents);case"all":default:return de}},[M,de,be]);d.useEffect(()=>{H>=J.length&&b(Math.max(0,J.length-1))},[J.length,H]);const pt=d.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 m=s.key.toLowerCase();b(m==="p"?w=>w>0?w-1:J.length-1:w=>w<J.length-1?w+1:0);return}switch(s.key){case"Escape":s.preventDefault(),F.current();break;case"ArrowUp":s.preventDefault(),b(m=>m>0?m-1:J.length-1);break;case"ArrowDown":s.preventDefault(),b(m=>m<J.length-1?m+1:0);break;case"Enter":s.preventDefault(),J[H]&&J[H].action();break}},[J,H]),mt=d.useCallback((s,m)=>{if(!m||!s)return s;const w=s.toLowerCase(),x=m.toLowerCase(),B=[];let L=0,D=w.indexOf(x),P=0;for(;D!==-1;)D>L&&B.push(s.slice(L,D)),B.push(Be.createElement("mark",{key:P++,className:"spotlight-highlight"},s.slice(D,D+m.length))),L=D+m.length,D=w.indexOf(x,L);return L<s.length&&B.push(s.slice(L)),B.length>0?Be.createElement(Be.Fragment,null,...B):s},[]);return{query:_,setQuery:ft,selectedIndex:H,setSelectedIndex:b,results:J,activeTab:M,setActiveTab:Fe,cycleTab:gt,areaSections:be,handleKeyDown:pt,highlightMatch:mt}}const Fs=d.forwardRef(function({query:e,onQueryChange:n,onKeyDown:r,onResetSelection:i},c){const{t:o}=we(["common"]);return f.jsxs("div",{className:"spotlight-input-wrapper",children:[f.jsx("span",{className:"spotlight-search-icon",children:"⌘"}),f.jsx("input",{ref:c,type:"text",className:"spotlight-input",placeholder:o("common:search.spotlightPlaceholder"),value:e,onChange:a=>{n(a.target.value),i()},onKeyDown:r,autoFocus:!0,spellCheck:!1}),f.jsxs("div",{className:"spotlight-input-hints",children:[f.jsx("span",{className:"spotlight-shortcut-hint",children:"↑↓"}),f.jsx("span",{className:"spotlight-shortcut-hint",children:"Enter"}),f.jsx("span",{className:"spotlight-shortcut-hint",children:"Esc"})]})]})}),Ss=d.memo(function({activeTab:e,onSelect:n}){const{t:r}=we(["terminal"]);return f.jsxs("div",{className:"spotlight-tabs",role:"tablist","aria-label":r("terminal:spotlight.tabsLabel"),children:[fe.map(i=>f.jsx("button",{type:"button",role:"tab","aria-selected":i===e,tabIndex:-1,className:`spotlight-tab${i===e?" active":""}`,onClick:()=>n(i),children:r(`terminal:spotlight.tabs.${i}`)},i)),f.jsx("span",{className:"spotlight-tabs-hint",children:f.jsx("kbd",{children:"Tab"})})]})}),bs=d.forwardRef(function({results:e,selectedIndex:n,query:r,activeTab:i,areaSections:c,highlightMatch:o,onSelectIndex:a},u){const{t:l}=we(["terminal"]),h=d.useRef(!1);d.useEffect(()=>{h.current=!1},[e]),d.useEffect(()=>{const g=typeof u=="function"?null:u==null?void 0:u.current;if(!g)return;const p=()=>{h.current=!0};return g.addEventListener("mousemove",p),()=>{g.removeEventListener("mousemove",p)}},[u,e]);const E={command:l("terminal:spotlight.categories.commands"),agent:l("terminal:spotlight.categories.agents"),building:l("terminal:spotlight.categories.infrastructure"),area:l("terminal:spotlight.categories.areas"),folder:l("terminal:spotlight.categories.folders"),"modified-file":l("terminal:spotlight.categories.modifiedFiles")},C=d.useMemo(()=>{const g=[];let p=null,S=[];return e.forEach((F,T)=>{F.type!==p&&(p!==null&&S.length>0&&g.push([p,S]),p=F.type,S=[]),S.push({result:F,index:T})}),p!==null&&S.length>0&&g.push([p,S]),g},[e]);if(d.useEffect(()=>{if(!u||typeof u=="function")return;const g=u.current;if(!g)return;const p=g.querySelector(".spotlight-item.selected");p&&p.scrollIntoView({block:"nearest",behavior:"smooth"})},[n,u]),i==="areas"){if(c.length===0)return f.jsx("div",{className:"spotlight-results",ref:u,children:f.jsx("div",{className:"spotlight-empty",children:l("terminal:spotlight.noResults")})});let g=0;return f.jsx("div",{className:"spotlight-results",ref:u,children:c.map(p=>f.jsxs("div",{children:[f.jsxs("div",{className:"spotlight-category-header spotlight-area-section-header",children:[f.jsx("span",{className:"spotlight-area-dot",style:{background:p.areaColor},"aria-hidden":"true"}),f.jsx("span",{className:"spotlight-area-name",children:p.areaName}),f.jsx("span",{className:"spotlight-area-count",children:p.agents.length})]}),p.agents.length===0?f.jsx("div",{className:"spotlight-area-empty",children:l("terminal:spotlight.noAgentsInArea")}):p.agents.map(S=>{const F=g++;return f.jsx(Je,{result:S,isSelected:F===n,query:r,highlightMatch:o,onClick:()=>S.action(),onMouseEnter:()=>{h.current&&a(F)}},S.id)})]},p.areaId))})}return e.length===0?f.jsx("div",{className:"spotlight-results",ref:u,children:f.jsx("div",{className:"spotlight-empty",children:l("terminal:spotlight.noResults")})}):f.jsx("div",{className:"spotlight-results",ref:u,children:C.map(([g,p])=>f.jsxs("div",{children:[C.length>1&&f.jsx("div",{className:"spotlight-category-header",children:E[g]||g}),p.map(({result:S,index:F})=>f.jsx(Je,{result:S,isSelected:F===n,query:r,highlightMatch:o,onClick:()=>S.action(),onMouseEnter:()=>{h.current&&a(F)}},S.id))]},g))})}),Bs=d.memo(function(){const{t:e}=we(["terminal"]);return f.jsxs("div",{className:"spotlight-footer",children:[f.jsxs("div",{className:"spotlight-footer-left",children:[f.jsxs("span",{className:"spotlight-footer-hint",children:[f.jsx("kbd",{children:"↑"}),f.jsx("kbd",{children:"↓"})," ",f.jsx("kbd",{children:"Alt+N"}),f.jsx("kbd",{children:"Alt+P"})," ",e("terminal:spotlight.navigate")]}),f.jsxs("span",{className:"spotlight-footer-hint",children:[f.jsx("kbd",{children:"Enter"})," ",e("terminal:spotlight.select")]}),f.jsxs("span",{className:"spotlight-footer-hint",children:[f.jsx("kbd",{children:"Tab"})," ",e("terminal:spotlight.switchTabs")]})]}),f.jsx("div",{className:"spotlight-footer-right",children:f.jsxs("span",{className:"spotlight-footer-hint",children:[f.jsx("kbd",{children:"Esc"})," ",e("common:buttons.close")]})})]})}),vs=768;function Rs({isOpen:t,onClose:e,onOpenSpawnModal:n,onOpenCommanderView:r,onOpenToolbox:i,onOpenFileExplorer:c,onOpenPM2LogsModal:o,onOpenBossLogsModal:a,onOpenDatabasePanel:u,onOpenMonitoringModal:l}){const h=d.useRef(null),E=d.useRef(null),C=d.useRef(null),g=d.useRef(0),{query:p,setQuery:S,selectedIndex:F,setSelectedIndex:T,results:j,activeTab:G,setActiveTab:W,cycleTab:oe,areaSections:ie,handleKeyDown:$,highlightMatch:N}=ws({isOpen:t,onClose:e,onOpenSpawnModal:n,onOpenCommanderView:r,onOpenToolbox:i,onOpenFileExplorer:c,onOpenPM2LogsModal:o,onOpenBossLogsModal:a,onOpenDatabasePanel:u,onOpenMonitoringModal:l});g.current=j.length;const _=d.useRef(oe);_.current=oe,d.useEffect(()=>{t&&setTimeout(()=>{var b,M;(b=h.current)==null||b.focus(),(M=h.current)==null||M.select()},50)},[t]),d.useEffect(()=>{if(!t)return;const b=window.visualViewport;if(!b||window.innerWidth>vs)return;const M=()=>{const R=E.current;R&&(R.style.height=`${b.height}px`,R.style.top=`${b.offsetTop}px`)};return M(),b.addEventListener("resize",M),b.addEventListener("scroll",M),()=>{b.removeEventListener("resize",M),b.removeEventListener("scroll",M);const R=E.current;R&&(R.style.height="",R.style.top="")}},[t]),d.useEffect(()=>{if(!t)return;const b=M=>{if(M.key==="Escape"){M.preventDefault(),M.stopPropagation(),M.stopImmediatePropagation(),e();return}if(M.key==="Tab"){M.preventDefault(),M.stopPropagation(),M.stopImmediatePropagation(),_.current(M.shiftKey?-1:1);return}if(M.altKey&&!M.ctrlKey&&!M.metaKey&&(M.key==="n"||M.key==="p"||M.key==="N"||M.key==="P")){M.preventDefault(),M.stopPropagation(),M.stopImmediatePropagation();const R=M.key.toLowerCase(),X=g.current;T(R==="p"?O=>O>0?O-1:X-1:O=>O<X-1?O+1:0);return}};return window.addEventListener("keydown",b,{capture:!0}),()=>{window.removeEventListener("keydown",b,{capture:!0})}},[t,e]);const ae=d.useCallback(b=>{b.target===b.currentTarget&&e()},[e]),H=d.useCallback(()=>{T(0)},[T]);return t?f.jsx("div",{ref:E,className:"spotlight-overlay",onClick:ae,children:f.jsxs("div",{className:"spotlight-modal",children:[f.jsx(Fs,{ref:h,query:p,onQueryChange:S,onKeyDown:$,onResetSelection:H}),f.jsx(Ss,{activeTab:G,onSelect:W}),f.jsx(bs,{ref:C,results:j,selectedIndex:F,query:p,activeTab:G,areaSections:ie,highlightMatch:N,onSelectIndex:T}),f.jsx(Bs,{})]})}):null}export{Ls as FILE_ICON_NAMES,Rs as Spotlight,Bs as SpotlightFooter,Fs as SpotlightInput,Je as SpotlightItem,bs as SpotlightResults,$s as formatDuration,js as formatRelativeTime,Ns as getAgentIcon,Dt as getFileIconFromPath,Ps as getTypeLabel,ws as useSpotlightSearch};
|
|
1
|
+
import{c as At,d as yt,x as Et,_ as xt,f as Ct,bH as Mt,bI as wt,a6 as Ft,r as d,w as St,S as pe,bJ as bt,bK as fe,s as Y,bL as Bt,j as f,I as ne,T as Ye,bM as vt,n as It,bN as _t,bO as Dt,bP as Ee,R as Be,m as Rt,bQ as nt,u as we,bR as Je}from"./main-CvV6YpbU.js";import{bS as Ls,bT as $s,bU as js,bV as Ns,bW as Ps}from"./main-CvV6YpbU.js";import"./vendor-react--Eh9ivFN.js";import"./vendor-three-3OKhI9bz.js";function re(t){return Array.isArray?Array.isArray(t):ct(t)==="[object Array]"}function kt(t){if(typeof t=="string")return t;let e=t+"";return e=="0"&&1/t==-1/0?"-0":e}function Tt(t){return t==null?"":kt(t)}function q(t){return typeof t=="string"}function rt(t){return typeof t=="number"}function Lt(t){return t===!0||t===!1||$t(t)&&ct(t)=="[object Boolean]"}function it(t){return typeof t=="object"}function $t(t){return it(t)&&t!==null}function Q(t){return t!=null}function ve(t){return!t.trim().length}function ct(t){return t==null?t===void 0?"[object Undefined]":"[object Null]":Object.prototype.toString.call(t)}const jt="Incorrect 'index' type",Nt=t=>`Invalid value for key ${t}`,Pt=t=>`Pattern length exceeds max of ${t}.`,Kt=t=>`Missing ${t} property in key`,Ot=t=>`Property 'weight' in key '${t}' must be a positive integer`,Xe=Object.prototype.hasOwnProperty;class zt{constructor(e){this._keys=[],this._keyMap={};let n=0;e.forEach(r=>{let i=ot(r);this._keys.push(i),this._keyMap[i.id]=i,n+=i.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 ot(t){let e=null,n=null,r=null,i=1,c=null;if(q(t)||re(t))r=t,e=Ze(t),n=Ie(t);else{if(!Xe.call(t,"name"))throw new Error(Kt("name"));const o=t.name;if(r=o,Xe.call(t,"weight")&&(i=t.weight,i<=0))throw new Error(Ot(o));e=Ze(o),n=Ie(o),c=t.getFn}return{path:e,id:n,weight:i,src:r,getFn:c}}function Ze(t){return re(t)?t:t.split(".")}function Ie(t){return re(t)?t.join("."):t}function Qt(t,e){let n=[],r=!1;const i=(c,o,a)=>{if(Q(c))if(!o[a])n.push(c);else{let u=o[a];const l=c[u];if(!Q(l))return;if(a===o.length-1&&(q(l)||rt(l)||Lt(l)))n.push(Tt(l));else if(re(l)){r=!0;for(let h=0,E=l.length;h<E;h+=1)i(l[h],o,a+1)}else o.length&&i(l,o,a+1)}};return i(t,q(e)?e.split("."):e,0),r?n:n[0]}const Gt={includeMatches:!1,findAllMatches:!1,minMatchCharLength:1},Wt={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},Ht={location:0,threshold:.6,distance:100},Ut={useExtendedSearch:!1,getFn:Qt,ignoreLocation:!1,ignoreFieldNorm:!1,fieldNormWeight:1};var y={...Wt,...Gt,...Ht,...Ut};const Vt=/[^ ]+/g;function Yt(t=1,e=3){const n=new Map,r=Math.pow(10,e);return{get(i){const c=i.match(Vt).length;if(n.has(c))return n.get(c);const o=1/Math.pow(c,.5*t),a=parseFloat(Math.round(o*r)/r);return n.set(c,a),a},clear(){n.clear()}}}class Le{constructor({getFn:e=y.getFn,fieldNormWeight:n=y.fieldNormWeight}={}){this.norm=Yt(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,q(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();q(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(!Q(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((i,c)=>{let o=i.getFn?i.getFn(e):this.getFn(e,i.path);if(Q(o)){if(re(o)){let a=[];const u=[{nestedArrIndex:-1,value:o}];for(;u.length;){const{nestedArrIndex:l,value:h}=u.pop();if(Q(h))if(q(h)&&!ve(h)){let E={v:h,i:l,n:this.norm.get(h)};a.push(E)}else re(h)&&h.forEach((E,C)=>{u.push({nestedArrIndex:C,value:E})})}r.$[c]=a}else if(q(o)&&!ve(o)){let a={v:o,n:this.norm.get(o)};r.$[c]=a}}}),this.records.push(r)}toJSON(){return{keys:this.keys,records:this.records}}}function at(t,e,{getFn:n=y.getFn,fieldNormWeight:r=y.fieldNormWeight}={}){const i=new Le({getFn:n,fieldNormWeight:r});return i.setKeys(t.map(ot)),i.setSources(e),i.create(),i}function Jt(t,{getFn:e=y.getFn,fieldNormWeight:n=y.fieldNormWeight}={}){const{keys:r,records:i}=t,c=new Le({getFn:e,fieldNormWeight:n});return c.setKeys(r),c.setIndexRecords(i),c}function xe(t,{errors:e=0,currentLocation:n=0,expectedLocation:r=0,distance:i=y.distance,ignoreLocation:c=y.ignoreLocation}={}){const o=e/t.length;if(c)return o;const a=Math.abs(r-n);return i?o+a/i:a?1:o}function Xt(t=[],e=y.minMatchCharLength){let n=[],r=-1,i=-1,c=0;for(let o=t.length;c<o;c+=1){let a=t[c];a&&r===-1?r=c:!a&&r!==-1&&(i=c-1,i-r+1>=e&&n.push([r,i]),r=-1)}return t[c-1]&&c-r>=e&&n.push([r,c-1]),n}const le=32;function Zt(t,e,n,{location:r=y.location,distance:i=y.distance,threshold:c=y.threshold,findAllMatches:o=y.findAllMatches,minMatchCharLength:a=y.minMatchCharLength,includeMatches:u=y.includeMatches,ignoreLocation:l=y.ignoreLocation}={}){if(e.length>le)throw new Error(Pt(le));const h=e.length,E=t.length,C=Math.max(0,Math.min(r,E));let g=c,p=C;const S=a>1||u,F=S?Array(E):[];let T;for(;(T=t.indexOf(e,p))>-1;){let $=xe(e,{currentLocation:T,expectedLocation:C,distance:i,ignoreLocation:l});if(g=Math.min($,g),p=T+h,S){let N=0;for(;N<h;)F[T+N]=1,N+=1}}p=-1;let j=[],G=1,W=h+E;const oe=1<<h-1;for(let $=0;$<h;$+=1){let N=0,_=W;for(;N<_;)xe(e,{errors:$,currentLocation:C+_,expectedLocation:C,distance:i,ignoreLocation:l})<=g?N=_:W=_,_=Math.floor((W-N)/2+N);W=_;let ae=Math.max(1,C-_+1),H=o?E:Math.min(C+_,E)+h,b=Array(H+2);b[H+1]=(1<<$)-1;for(let R=H;R>=ae;R-=1){let X=R-1,O=n[t.charAt(X)];if(S&&(F[X]=+!!O),b[R]=(b[R+1]<<1|1)&O,$&&(b[R]|=(j[R+1]|j[R])<<1|1|j[R+1]),b[R]&oe&&(G=xe(e,{errors:$,currentLocation:X,expectedLocation:C,distance:i,ignoreLocation:l}),G<=g)){if(g=G,p=X,p<=C)break;ae=Math.max(1,2*C-p)}}if(xe(e,{errors:$+1,currentLocation:C,expectedLocation:C,distance:i,ignoreLocation:l})>g)break;j=b}const ie={isMatch:p>=0,score:Math.max(.001,G)};if(S){const $=Xt(F,a);$.length?u&&(ie.indices=$):ie.isMatch=!1}return ie}function qt(t){let e={};for(let n=0,r=t.length;n<r;n+=1){const i=t.charAt(n);e[i]=(e[i]||0)|1<<r-n-1}return e}const Ce=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 ut{constructor(e,{location:n=y.location,threshold:r=y.threshold,distance:i=y.distance,includeMatches:c=y.includeMatches,findAllMatches:o=y.findAllMatches,minMatchCharLength:a=y.minMatchCharLength,isCaseSensitive:u=y.isCaseSensitive,ignoreDiacritics:l=y.ignoreDiacritics,ignoreLocation:h=y.ignoreLocation}={}){if(this.options={location:n,threshold:r,distance:i,includeMatches:c,findAllMatches:o,minMatchCharLength:a,isCaseSensitive:u,ignoreDiacritics:l,ignoreLocation:h},e=u?e:e.toLowerCase(),e=l?Ce(e):e,this.pattern=e,this.chunks=[],!this.pattern.length)return;const E=(g,p)=>{this.chunks.push({pattern:g,alphabet:qt(g),startIndex:p})},C=this.pattern.length;if(C>le){let g=0;const p=C%le,S=C-p;for(;g<S;)E(this.pattern.substr(g,le),g),g+=le;if(p){const F=C-le;E(this.pattern.substr(F),F)}}else E(this.pattern,0)}searchIn(e){const{isCaseSensitive:n,ignoreDiacritics:r,includeMatches:i}=this.options;if(e=n?e:e.toLowerCase(),e=r?Ce(e):e,this.pattern===e){let S={isMatch:!0,score:0};return i&&(S.indices=[[0,e.length-1]]),S}const{location:c,distance:o,threshold:a,findAllMatches:u,minMatchCharLength:l,ignoreLocation:h}=this.options;let E=[],C=0,g=!1;this.chunks.forEach(({pattern:S,alphabet:F,startIndex:T})=>{const{isMatch:j,score:G,indices:W}=Zt(e,S,F,{location:c+T,distance:o,threshold:a,findAllMatches:u,minMatchCharLength:l,includeMatches:i,ignoreLocation:h});j&&(g=!0),C+=G,j&&W&&(E=[...E,...W])});let p={isMatch:g,score:g?C/this.chunks.length:1};return g&&i&&(p.indices=E),p}}class ce{constructor(e){this.pattern=e}static isMultiMatch(e){return qe(e,this.multiRegex)}static isSingleMatch(e){return qe(e,this.singleRegex)}search(){}}function qe(t,e){const n=t.match(e);return n?n[1]:null}class es extends ce{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 ts extends ce{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 ss extends ce{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 ns extends ce{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 rs extends ce{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 is extends ce{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 lt extends ce{constructor(e,{location:n=y.location,threshold:r=y.threshold,distance:i=y.distance,includeMatches:c=y.includeMatches,findAllMatches:o=y.findAllMatches,minMatchCharLength:a=y.minMatchCharLength,isCaseSensitive:u=y.isCaseSensitive,ignoreDiacritics:l=y.ignoreDiacritics,ignoreLocation:h=y.ignoreLocation}={}){super(e),this._bitapSearch=new ut(e,{location:n,threshold:r,distance:i,includeMatches:c,findAllMatches:o,minMatchCharLength:a,isCaseSensitive:u,ignoreDiacritics:l,ignoreLocation:h})}static get type(){return"fuzzy"}static get multiRegex(){return/^"(.*)"$/}static get singleRegex(){return/^(.*)$/}search(e){return this._bitapSearch.searchIn(e)}}class ht extends ce{constructor(e){super(e)}static get type(){return"include"}static get multiRegex(){return/^'"(.*)"$/}static get singleRegex(){return/^'(.*)$/}search(e){let n=0,r;const i=[],c=this.pattern.length;for(;(r=e.indexOf(this.pattern,n))>-1;)n=r+c,i.push([r,n-1]);const o=!!i.length;return{isMatch:o,score:o?0:1,indices:i}}}const _e=[es,ht,ss,ns,is,rs,ts,lt],et=_e.length,cs=/ +(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)/,os="|";function as(t,e={}){return t.split(os).map(n=>{let r=n.trim().split(cs).filter(c=>c&&!!c.trim()),i=[];for(let c=0,o=r.length;c<o;c+=1){const a=r[c];let u=!1,l=-1;for(;!u&&++l<et;){const h=_e[l];let E=h.isMultiMatch(a);E&&(i.push(new h(E,e)),u=!0)}if(!u)for(l=-1;++l<et;){const h=_e[l];let E=h.isSingleMatch(a);if(E){i.push(new h(E,e));break}}}return i})}const us=new Set([lt.type,ht.type]);class ls{constructor(e,{isCaseSensitive:n=y.isCaseSensitive,ignoreDiacritics:r=y.ignoreDiacritics,includeMatches:i=y.includeMatches,minMatchCharLength:c=y.minMatchCharLength,ignoreLocation:o=y.ignoreLocation,findAllMatches:a=y.findAllMatches,location:u=y.location,threshold:l=y.threshold,distance:h=y.distance}={}){this.query=null,this.options={isCaseSensitive:n,ignoreDiacritics:r,includeMatches:i,minMatchCharLength:c,findAllMatches:a,ignoreLocation:o,location:u,threshold:l,distance:h},e=n?e:e.toLowerCase(),e=r?Ce(e):e,this.pattern=e,this.query=as(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:i,ignoreDiacritics:c}=this.options;e=i?e:e.toLowerCase(),e=c?Ce(e):e;let o=0,a=[],u=0;for(let l=0,h=n.length;l<h;l+=1){const E=n[l];a.length=0,o=0;for(let C=0,g=E.length;C<g;C+=1){const p=E[C],{isMatch:S,indices:F,score:T}=p.search(e);if(S){if(o+=1,u+=T,r){const j=p.constructor.type;us.has(j)?a=[...a,...F]:a.push(F)}}else{u=0,o=0,a.length=0;break}}if(o){let C={isMatch:!0,score:u/o};return r&&(C.indices=a),C}}return{isMatch:!1,score:1}}}const De=[];function hs(...t){De.push(...t)}function Re(t,e){for(let n=0,r=De.length;n<r;n+=1){let i=De[n];if(i.condition(t,e))return new i(t,e)}return new ut(t,e)}const Me={AND:"$and",OR:"$or"},ke={PATH:"$path",PATTERN:"$val"},Te=t=>!!(t[Me.AND]||t[Me.OR]),ds=t=>!!t[ke.PATH],fs=t=>!re(t)&&it(t)&&!Te(t),tt=t=>({[Me.AND]:Object.keys(t).map(e=>({[e]:t[e]}))});function dt(t,e,{auto:n=!0}={}){const r=i=>{let c=Object.keys(i);const o=ds(i);if(!o&&c.length>1&&!Te(i))return r(tt(i));if(fs(i)){const u=o?i[ke.PATH]:c[0],l=o?i[ke.PATTERN]:i[u];if(!q(l))throw new Error(Nt(u));const h={keyId:Ie(u),pattern:l};return n&&(h.searcher=Re(l,e)),h}let a={children:[],operator:c[0]};return c.forEach(u=>{const l=i[u];re(l)&&l.forEach(h=>{a.children.push(r(h))})}),a};return Te(t)||(t=tt(t)),r(t)}function gs(t,{ignoreFieldNorm:e=y.ignoreFieldNorm}){t.forEach(n=>{let r=1;n.matches.forEach(({key:i,norm:c,score:o})=>{const a=i?i.weight:null;r*=Math.pow(o===0&&a?Number.EPSILON:o,(a||1)*(e?1:c))}),n.score=r})}function ps(t,e){const n=t.matches;e.matches=[],Q(n)&&n.forEach(r=>{if(!Q(r.indices)||!r.indices.length)return;const{indices:i,value:c}=r;let o={indices:i,value:c};r.key&&(o.key=r.key.src),r.idx>-1&&(o.refIndex=r.idx),e.matches.push(o)})}function ms(t,e){e.score=t.score}function As(t,e,{includeMatches:n=y.includeMatches,includeScore:r=y.includeScore}={}){const i=[];return n&&i.push(ps),r&&i.push(ms),t.map(c=>{const{idx:o}=c,a={item:e[o],refIndex:o};return i.length&&i.forEach(u=>{u(c,a)}),a})}class Z{constructor(e,n={},r){this.options={...y,...n},this.options.useExtendedSearch,this._keyStore=new zt(this.options.keys),this.setCollection(e,r)}setCollection(e,n){if(this._docs=e,n&&!(n instanceof Le))throw new Error(jt);this._myIndex=n||at(this.options.keys,this._docs,{getFn:this.options.getFn,fieldNormWeight:this.options.fieldNormWeight})}add(e){Q(e)&&(this._docs.push(e),this._myIndex.add(e))}remove(e=()=>!1){const n=[];for(let r=0,i=this._docs.length;r<i;r+=1){const c=this._docs[r];e(c,r)&&(this.removeAt(r),r-=1,i-=1,n.push(c))}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:i,shouldSort:c,sortFn:o,ignoreFieldNorm:a}=this.options;let u=q(e)?q(this._docs[0])?this._searchStringList(e):this._searchObjectList(e):this._searchLogical(e);return gs(u,{ignoreFieldNorm:a}),c&&u.sort(o),rt(n)&&n>-1&&(u=u.slice(0,n)),As(u,this._docs,{includeMatches:r,includeScore:i})}_searchStringList(e){const n=Re(e,this.options),{records:r}=this._myIndex,i=[];return r.forEach(({v:c,i:o,n:a})=>{if(!Q(c))return;const{isMatch:u,score:l,indices:h}=n.searchIn(c);u&&i.push({item:c,idx:o,matches:[{score:l,value:c,norm:a,indices:h}]})}),i}_searchLogical(e){const n=dt(e,this.options),r=(a,u,l)=>{if(!a.children){const{keyId:E,searcher:C}=a,g=this._findMatches({key:this._keyStore.get(E),value:this._myIndex.getValueForItemAtKeyId(u,E),searcher:C});return g&&g.length?[{idx:l,item:u,matches:g}]:[]}const h=[];for(let E=0,C=a.children.length;E<C;E+=1){const g=a.children[E],p=r(g,u,l);if(p.length)h.push(...p);else if(a.operator===Me.AND)return[]}return h},i=this._myIndex.records,c={},o=[];return i.forEach(({$:a,i:u})=>{if(Q(a)){let l=r(n,a,u);l.length&&(c[u]||(c[u]={idx:u,item:a,matches:[]},o.push(c[u])),l.forEach(({matches:h})=>{c[u].matches.push(...h)}))}}),o}_searchObjectList(e){const n=Re(e,this.options),{keys:r,records:i}=this._myIndex,c=[];return i.forEach(({$:o,i:a})=>{if(!Q(o))return;let u=[];r.forEach((l,h)=>{u.push(...this._findMatches({key:l,value:o[h],searcher:n}))}),u.length&&c.push({idx:a,item:o,matches:u})}),c}_findMatches({key:e,value:n,searcher:r}){if(!Q(n))return[];let i=[];if(re(n))n.forEach(({v:c,i:o,n:a})=>{if(!Q(c))return;const{isMatch:u,score:l,indices:h}=r.searchIn(c);u&&i.push({score:l,key:e,value:c,idx:o,norm:a,indices:h})});else{const{v:c,n:o}=n,{isMatch:a,score:u,indices:l}=r.searchIn(c);a&&i.push({score:u,key:e,value:c,norm:o,indices:l})}return i}}Z.version="7.1.0";Z.createIndex=at;Z.parseIndex=Jt;Z.config=y;Z.parseQuery=dt;hs(ls);async function ys(t){const e=new URLSearchParams({q:t}),n=await At(yt(`/api/folders/search?${e.toString()}`));if(!n.ok){const i=await n.json().catch(()=>({}));throw new Error(i.error||`Failed to search folders: ${n.statusText}`)}const r=await n.json();return Array.isArray(r.folders)?r.folders:[]}const Es=["command","agent","building","area","folder","modified-file"],xs=2;function Cs(){const t=nt(pe.SPOTLIGHT_TAB,"all");return fe.includes(t)?t:"all"}function st(){return Rt(pe.SPOTLIGHT_QUERY,"")}function Ms(){const t=nt(pe.AOP_CONFIG,{});return t.sortMode==="name"||t.sortMode==="status"||t.sortMode==="recent"?t.sortMode:"recent"}function ws({isOpen:t,onClose:e,onOpenSpawnModal:n,onOpenCommanderView:r,onOpenToolbox:i,onOpenFileExplorer:c,onOpenPM2LogsModal:o,onOpenBossLogsModal:a,onOpenDatabasePanel:u,onOpenMonitoringModal:l}){const h=Et(),E=xt(),C=Ct(),g=Mt(),p=wt(),S=Ft(),F=d.useRef(e);F.current=e;const T=d.useRef(n);T.current=n;const j=d.useRef(r);j.current=r;const G=d.useRef(i);G.current=i;const W=d.useRef(c);W.current=c;const oe=d.useRef(o);oe.current=o;const ie=d.useRef(a);ie.current=a;const $=d.useRef(u);$.current=u;const N=d.useRef(l);N.current=l;const[_,ae]=d.useState(st),[H,b]=d.useState(0),[M,R]=d.useState(Cs),[X,O]=d.useState([]),ft=d.useCallback(s=>{ae(s),St(pe.SPOTLIGHT_QUERY,s)},[]);d.useEffect(()=>{t&&(ae(st()),b(0))},[t]),d.useEffect(()=>{if(!t){O([]);return}const s=_.trim();if(s.length<xs){O([]);return}let m=!1;const w=setTimeout(()=>{ys(s).then(x=>{m||O(x)}).catch(()=>{m||O([])})},250);return()=>{m=!0,clearTimeout(w)}},[t,_]);const Fe=d.useCallback(s=>{R(s),bt(pe.SPOTLIGHT_TAB,s)},[]),$e=d.useRef(M);$e.current=M;const gt=d.useCallback(s=>{const m=fe.indexOf($e.current),w=fe[(m+s+fe.length)%fe.length];Fe(w)},[Fe]);d.useEffect(()=>{b(0)},[M]);const Se=Y.getShortcuts(),ge=d.useMemo(()=>t?Bt():{},[t]),me=d.useMemo(()=>{if(!t)return[];const s=window.matchMedia("(pointer: coarse)").matches,m=Se.find(x=>x.id==="spawn-agent"),w=Se.find(x=>x.id==="toggle-commander");return[{id:"cmd-spawn",type:"command",title:"Spawn New Agent",subtitle:s?"":m?Ye(m):"Alt+N",icon:f.jsx(ne,{name:"plus",size:16}),action:()=>{F.current(),T.current()}},{id:"cmd-commander",type:"command",title:"Commander View",subtitle:s?"":w!=null&&w.key?Ye(w):"Tab",icon:f.jsx(ne,{name:"dashboard",size:16}),action:()=>{F.current(),j.current()}},{id:"cmd-settings",type:"command",title:"Settings & Tools",subtitle:"Configure Tide Commander",icon:f.jsx(ne,{name:"gear",size:16}),action:()=>{F.current(),G.current()}},{id:"cmd-monitoring",type:"command",title:"Monitoring & Logs",subtitle:"Triggers, workflows, events",icon:f.jsx(ne,{name:"chart-line",size:16}),action:()=>{var x;F.current(),(x=N.current)==null||x.call(N)}}]},[t,Se]),he=d.useMemo(()=>t?Array.from(h.values()).map(s=>{const m=(g||[]).filter(V=>V.agentId===s.id).map(V=>V.filePath),w=[...new Set(m)],x=w.map(V=>V.split("/").pop()||V),B=[];s.lastAssignedTask&&B.push(s.lastAssignedTask);const L=`${s.class} • ${s.cwd}`;let D=`${s.name} ${s.class} ${s.status} ${s.cwd}`;s.taskLabel&&(D+=` ${s.taskLabel}`),x.length>0&&(D+=` ${x.join(" ")} ${w.join(" ")}`),B.length>0&&(D+=` ${B.join(" ")}`);const P=Date.now()-s.lastActivity;let U;return s.lastAssignedTask&&(s.lastAssignedTask.length>150?U=s.lastAssignedTask.slice(0,150)+"...":U=s.lastAssignedTask),{id:`agent-${s.id}`,type:"agent",title:s.name,subtitle:L,lastUserInput:U,timeAway:P,icon:f.jsx(It,{agent:s,size:20}),_searchText:D,_modifiedFiles:w,_userQueries:B,_agentId:s.id,_lastActivity:s.lastActivity,_taskLabel:s.taskLabel,_status:s.status,action:()=>{F.current(),vt(s.id),Y.selectAgent(s.id),Y.getState().viewMode!=="flat"&&Y.requestTerminalExpand()}}}):[],[t,h,g]),Ae=d.useMemo(()=>t?Array.from(E.values()).map(s=>{var m;return{id:`area-${s.id}`,type:"area",title:s.name,subtitle:`${s.assignedAgentIds.length} agents • ${((m=s.directories)==null?void 0:m.length)||0} folders`,icon:f.jsx(ne,{name:"map",size:16}),action:()=>{F.current(),Y.selectArea(s.id)}}}):[],[t,E]),je=d.useMemo(()=>{const s=new Map;for(const m of he)m._agentId&&s.set(m._agentId,m);return s},[he]),Ne=d.useMemo(()=>{const s=new Map;if(!t)return s;for(const m of h.values()){const w=Y.getAreaForAgent(m.id);if(!w||w.archived)continue;const x=s.get(w.id);x?x.push(m):s.set(w.id,[m])}return s},[t,h,E]),Pe=d.useMemo(()=>{const s=new Map;for(const m of p)s.has(m.agentId)||s.set(m.agentId,m.timestamp);return s},[p]),be=d.useMemo(()=>{if(!t)return[];const s=_.trim().toLowerCase(),m=_t({sortMode:Ms(),agentsWithUnseenOutput:S,getLatestToolTimestamp:B=>Pe.get(B)}),w=Array.from(E.values()).filter(B=>!B.archived).filter(B=>s?B.name.toLowerCase().includes(s):!0).sort((B,L)=>B.name.localeCompare(L.name,void 0,{sensitivity:"base"})),x=[];for(const B of w){const D=(Ne.get(B.id)||[]).slice().sort(m).map(P=>je.get(P.id)).filter(P=>!!P);!s&&D.length===0||x.push({areaId:B.id,areaName:B.name,areaColor:B.color,agents:D})}return x},[t,_,E,Ne,je,S,Pe]),ye=d.useMemo(()=>t?Array.from(C.values()).filter(s=>s.type==="server"||s.type==="boss"||s.type==="database"||s.type==="tests").map(s=>{var P,U,V,ue,ee;const m=s.status==="running"?"#4ade80":s.status==="stopped"?"#f87171":"#facc15",w=s.type==="boss"?"crown":s.type==="database"?"database":s.type==="tests"?"flask":"desktop",x=s.type==="boss"?"Boss":s.type==="database"?"Database":s.type==="tests"?"Tests":"Server";let B=`${x} • ${s.status}`;if(s.type==="database"&&((U=(P=s.database)==null?void 0:P.connections)!=null&&U.length)){const z=s.database.connections[0];B+=` • ${z.engine} @ ${z.host}`}else s.type==="tests"&&s.folderPath?B=`${x} • ${s.folderPath}`:s.cwd&&(B+=` • ${s.cwd}`);const L=((V=s.pm2Status)==null?void 0:V.ports)||[];let D=`${s.name} ${s.type} ${s.status} ${s.cwd||""} ${((ue=s.pm2)==null?void 0:ue.name)||""}`;if(s.type==="tests"&&(D+=` ${s.folderPath||""} tests junit maven`),L.length>0&&(D+=` ${L.join(" ")}`),s.type==="database"&&((ee=s.database)!=null&&ee.connections))for(const z of s.database.connections)D+=` ${z.name} ${z.engine} ${z.host} ${z.database||""} mysql postgresql sql`;return{id:`building-${s.id}`,type:"building",title:s.name,subtitle:B,_ports:L,icon:f.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:4},children:[f.jsx(ne,{name:"status-pending",size:10,weight:"fill",color:m}),f.jsx(ne,{name:w,size:16})]}),_searchText:D,action:()=>{var z;F.current(),s.type==="boss"?ie.current(s.id):s.type==="database"?$.current(s.id):s.type==="tests"?Y.openTestsBuilding(s.id):s.type==="http"?Y.openHttpBuilding(s.id):(z=s.pm2)!=null&&z.enabled&&oe.current(s.id)}}}):[],[t,C]),Ke=d.useMemo(()=>{if(!t)return[];const s=g||[],m=new Set,w=[];for(const x of s){if(m.has(x.filePath))continue;m.add(x.filePath);const B=x.filePath.split("/").pop()||x.filePath,L=x.action==="created"?"Created":x.action==="modified"?"Modified":x.action==="deleted"?"Deleted":"Read";if(w.push({id:`modified-${x.filePath}-${x.timestamp}`,type:"modified-file",title:B,subtitle:`${L} by ${x.agentName} • ${x.filePath}`,matchedText:x.filePath,icon:x.action==="deleted"?f.jsx(ne,{name:"trash",size:16}):Dt(x.filePath),action:()=>{F.current();const D=Array.from(Y.getState().areas.values());for(const P of D)for(const U of P.directories||[])if(x.filePath.startsWith(U)){Y.setFileViewerPath(x.filePath),W.current(P.id);return}Y.selectAgent(x.agentId)}}),w.length>=50)break}return w},[t,g]),Oe=d.useMemo(()=>t?X.map(s=>{const m=s.isGitRepo&&s.gitBranch?`${s.path} • ${s.gitBranch}`:s.path;return{id:`folder-${s.path}`,type:"folder",title:s.name,subtitle:m,matchedText:s.path,icon:f.jsx(ne,{name:s.isGitRepo?"git-branch":"folder",size:16}),_searchText:`${s.name} ${s.path}`,_isGitRepo:s.isGitRepo,_gitBranch:s.gitBranch,action:()=>{F.current(),Y.openFileExplorer(s.path)}}}):[],[t,X]),ze=d.useMemo(()=>new Z(he,{keys:["title","subtitle","_searchText","lastUserInput"],threshold:.4,ignoreLocation:!0,includeScore:!0,includeMatches:!0}),[he]),Qe=d.useMemo(()=>new Z(me,{keys:["title","subtitle"],threshold:.4,includeScore:!0,includeMatches:!0}),[me]),Ge=d.useMemo(()=>new Z(Ae,{keys:["title","subtitle"],threshold:.4,includeScore:!0,includeMatches:!0}),[Ae]),We=d.useMemo(()=>new Z(Ke,{keys:["title","subtitle","matchedText"],threshold:.4,ignoreLocation:!0,includeScore:!0,includeMatches:!0}),[Ke]),He=d.useMemo(()=>new Z(ye,{keys:["title","subtitle","_searchText"],threshold:.4,ignoreLocation:!0,includeScore:!0,includeMatches:!0}),[ye]),de=d.useMemo(()=>{if(!_.trim()){const A=[];A.push(...ye);const v=[...he].sort((k,K)=>{const te=Ee(k._agentId,k._lastActivity,ge);return Ee(K._agentId,K._lastActivity,ge)-te});A.push(...v),A.push(...me.slice(0,2)),A.push(...Ae.slice(0,2));const I={};return Es.forEach((k,K)=>{I[k]=K}),A.sort((k,K)=>(I[k.type]??999)-(I[K.type]??999)),A}const s=_.trim().toLowerCase(),m=ze.search(_).slice(0,8),w=Qe.search(_).slice(0,3),x=Ge.search(_).slice(0,2),B=We.search(_).slice(0,3),L=Oe.slice(0,8),D=He.search(_).filter(A=>{const v=A.score??1;return`${A.item.title} ${A.item.subtitle||""} ${A.item._searchText||""}`.toLowerCase().includes(s)||v<=.2}).slice(0,4),P={agent:6,building:5,folder:4,command:3,area:2,"modified-file":1},U=A=>{if(!s)return 1;const v=A.title.toLowerCase();return v===s?6:v.startsWith(s)?5:v.split(/[^a-z0-9]+/i).includes(s)?4:v.includes(s)?3:`${A.subtitle||""} ${A._searchText||""} ${A.matchedText||""}`.toLowerCase().includes(s)?2:1},V=(A,v)=>{const I=(1-Math.min(1,v??1))*4;return U(A)*100+(P[A.type]??0)*5+I},ue=new Map,ee=(A,v)=>{const I=ue.get(A.type),k={item:A,score:V(A,v)};I?I.push(k):ue.set(A.type,[k])};for(const A of m){const v={...A.item};if(v._modifiedFiles&&v._modifiedFiles.length>0){const I=v._modifiedFiles.filter(k=>{var se;const K=((se=k.split("/").pop())==null?void 0:se.toLowerCase())||"",te=k.toLowerCase();return K.includes(s)||te.includes(s)});I.length>0&&(v.matchedFiles=I)}if(v._userQueries&&v._userQueries.length>0){const I=v._userQueries.find(k=>k.toLowerCase().includes(s));if(I)if(I.length>200){const K=I.toLowerCase().indexOf(s),te=Math.max(0,K-60),se=Math.min(I.length,K+s.length+100);v.matchedQuery=(te>0?"...":"")+I.slice(te,se)+(se<I.length?"...":"")}else v.matchedQuery=I}ee(v,A.score)}for(const A of D)ee(A.item,A.score);for(const A of w)ee(A.item,A.score);for(const A of x)ee(A.item,A.score);for(const A of B)ee(A.item,A.score);for(const A of L)ee(A,void 0);for(const[A,v]of ue)A==="agent"?v.sort((I,k)=>{const K=U(I.item),te=U(k.item);if(te!==K)return te-K;const se=Ee(I.item._agentId,I.item._lastActivity,ge),Ve=Ee(k.item._agentId,k.item._lastActivity,ge);return Ve!==se?Ve-se:k.score-I.score}):v.sort((I,k)=>k.score-I.score);const z=A=>A.reduce((v,I)=>Math.max(v,I.score),-1),Ue=[];return Array.from(ue.values()).sort((A,v)=>z(v)-z(A)).forEach(A=>{for(const v of A)Ue.push(v.item)}),Ue},[_,ze,Qe,Ge,We,He,me,he,Ae,ye,Oe,ge]),J=d.useMemo(()=>{switch(M){case"agents":return de.filter(s=>s.type==="agent");case"buildings":return de.filter(s=>s.type==="building");case"commands":return de.filter(s=>s.type==="command");case"folders":return de.filter(s=>s.type==="folder");case"areas":return be.flatMap(s=>s.agents);case"all":default:return de}},[M,de,be]);d.useEffect(()=>{H>=J.length&&b(Math.max(0,J.length-1))},[J.length,H]);const pt=d.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 m=s.key.toLowerCase();b(m==="p"?w=>w>0?w-1:J.length-1:w=>w<J.length-1?w+1:0);return}switch(s.key){case"Escape":s.preventDefault(),F.current();break;case"ArrowUp":s.preventDefault(),b(m=>m>0?m-1:J.length-1);break;case"ArrowDown":s.preventDefault(),b(m=>m<J.length-1?m+1:0);break;case"Enter":s.preventDefault(),J[H]&&J[H].action();break}},[J,H]),mt=d.useCallback((s,m)=>{if(!m||!s)return s;const w=s.toLowerCase(),x=m.toLowerCase(),B=[];let L=0,D=w.indexOf(x),P=0;for(;D!==-1;)D>L&&B.push(s.slice(L,D)),B.push(Be.createElement("mark",{key:P++,className:"spotlight-highlight"},s.slice(D,D+m.length))),L=D+m.length,D=w.indexOf(x,L);return L<s.length&&B.push(s.slice(L)),B.length>0?Be.createElement(Be.Fragment,null,...B):s},[]);return{query:_,setQuery:ft,selectedIndex:H,setSelectedIndex:b,results:J,activeTab:M,setActiveTab:Fe,cycleTab:gt,areaSections:be,handleKeyDown:pt,highlightMatch:mt}}const Fs=d.forwardRef(function({query:e,onQueryChange:n,onKeyDown:r,onResetSelection:i},c){const{t:o}=we(["common"]);return f.jsxs("div",{className:"spotlight-input-wrapper",children:[f.jsx("span",{className:"spotlight-search-icon",children:"⌘"}),f.jsx("input",{ref:c,type:"text",className:"spotlight-input",placeholder:o("common:search.spotlightPlaceholder"),value:e,onChange:a=>{n(a.target.value),i()},onKeyDown:r,autoFocus:!0,spellCheck:!1}),f.jsxs("div",{className:"spotlight-input-hints",children:[f.jsx("span",{className:"spotlight-shortcut-hint",children:"↑↓"}),f.jsx("span",{className:"spotlight-shortcut-hint",children:"Enter"}),f.jsx("span",{className:"spotlight-shortcut-hint",children:"Esc"})]})]})}),Ss=d.memo(function({activeTab:e,onSelect:n}){const{t:r}=we(["terminal"]);return f.jsxs("div",{className:"spotlight-tabs",role:"tablist","aria-label":r("terminal:spotlight.tabsLabel"),children:[fe.map(i=>f.jsx("button",{type:"button",role:"tab","aria-selected":i===e,tabIndex:-1,className:`spotlight-tab${i===e?" active":""}`,onClick:()=>n(i),children:r(`terminal:spotlight.tabs.${i}`)},i)),f.jsx("span",{className:"spotlight-tabs-hint",children:f.jsx("kbd",{children:"Tab"})})]})}),bs=d.forwardRef(function({results:e,selectedIndex:n,query:r,activeTab:i,areaSections:c,highlightMatch:o,onSelectIndex:a},u){const{t:l}=we(["terminal"]),h=d.useRef(!1);d.useEffect(()=>{h.current=!1},[e]),d.useEffect(()=>{const g=typeof u=="function"?null:u==null?void 0:u.current;if(!g)return;const p=()=>{h.current=!0};return g.addEventListener("mousemove",p),()=>{g.removeEventListener("mousemove",p)}},[u,e]);const E={command:l("terminal:spotlight.categories.commands"),agent:l("terminal:spotlight.categories.agents"),building:l("terminal:spotlight.categories.infrastructure"),area:l("terminal:spotlight.categories.areas"),folder:l("terminal:spotlight.categories.folders"),"modified-file":l("terminal:spotlight.categories.modifiedFiles")},C=d.useMemo(()=>{const g=[];let p=null,S=[];return e.forEach((F,T)=>{F.type!==p&&(p!==null&&S.length>0&&g.push([p,S]),p=F.type,S=[]),S.push({result:F,index:T})}),p!==null&&S.length>0&&g.push([p,S]),g},[e]);if(d.useEffect(()=>{if(!u||typeof u=="function")return;const g=u.current;if(!g)return;const p=g.querySelector(".spotlight-item.selected");p&&p.scrollIntoView({block:"nearest",behavior:"smooth"})},[n,u]),i==="areas"){if(c.length===0)return f.jsx("div",{className:"spotlight-results",ref:u,children:f.jsx("div",{className:"spotlight-empty",children:l("terminal:spotlight.noResults")})});let g=0;return f.jsx("div",{className:"spotlight-results",ref:u,children:c.map(p=>f.jsxs("div",{children:[f.jsxs("div",{className:"spotlight-category-header spotlight-area-section-header",children:[f.jsx("span",{className:"spotlight-area-dot",style:{background:p.areaColor},"aria-hidden":"true"}),f.jsx("span",{className:"spotlight-area-name",children:p.areaName}),f.jsx("span",{className:"spotlight-area-count",children:p.agents.length})]}),p.agents.length===0?f.jsx("div",{className:"spotlight-area-empty",children:l("terminal:spotlight.noAgentsInArea")}):p.agents.map(S=>{const F=g++;return f.jsx(Je,{result:S,isSelected:F===n,query:r,highlightMatch:o,onClick:()=>S.action(),onMouseEnter:()=>{h.current&&a(F)}},S.id)})]},p.areaId))})}return e.length===0?f.jsx("div",{className:"spotlight-results",ref:u,children:f.jsx("div",{className:"spotlight-empty",children:l("terminal:spotlight.noResults")})}):f.jsx("div",{className:"spotlight-results",ref:u,children:C.map(([g,p])=>f.jsxs("div",{children:[C.length>1&&f.jsx("div",{className:"spotlight-category-header",children:E[g]||g}),p.map(({result:S,index:F})=>f.jsx(Je,{result:S,isSelected:F===n,query:r,highlightMatch:o,onClick:()=>S.action(),onMouseEnter:()=>{h.current&&a(F)}},S.id))]},g))})}),Bs=d.memo(function(){const{t:e}=we(["terminal"]);return f.jsxs("div",{className:"spotlight-footer",children:[f.jsxs("div",{className:"spotlight-footer-left",children:[f.jsxs("span",{className:"spotlight-footer-hint",children:[f.jsx("kbd",{children:"↑"}),f.jsx("kbd",{children:"↓"})," ",f.jsx("kbd",{children:"Alt+N"}),f.jsx("kbd",{children:"Alt+P"})," ",e("terminal:spotlight.navigate")]}),f.jsxs("span",{className:"spotlight-footer-hint",children:[f.jsx("kbd",{children:"Enter"})," ",e("terminal:spotlight.select")]}),f.jsxs("span",{className:"spotlight-footer-hint",children:[f.jsx("kbd",{children:"Tab"})," ",e("terminal:spotlight.switchTabs")]})]}),f.jsx("div",{className:"spotlight-footer-right",children:f.jsxs("span",{className:"spotlight-footer-hint",children:[f.jsx("kbd",{children:"Esc"})," ",e("common:buttons.close")]})})]})}),vs=768;function Rs({isOpen:t,onClose:e,onOpenSpawnModal:n,onOpenCommanderView:r,onOpenToolbox:i,onOpenFileExplorer:c,onOpenPM2LogsModal:o,onOpenBossLogsModal:a,onOpenDatabasePanel:u,onOpenMonitoringModal:l}){const h=d.useRef(null),E=d.useRef(null),C=d.useRef(null),g=d.useRef(0),{query:p,setQuery:S,selectedIndex:F,setSelectedIndex:T,results:j,activeTab:G,setActiveTab:W,cycleTab:oe,areaSections:ie,handleKeyDown:$,highlightMatch:N}=ws({isOpen:t,onClose:e,onOpenSpawnModal:n,onOpenCommanderView:r,onOpenToolbox:i,onOpenFileExplorer:c,onOpenPM2LogsModal:o,onOpenBossLogsModal:a,onOpenDatabasePanel:u,onOpenMonitoringModal:l});g.current=j.length;const _=d.useRef(oe);_.current=oe,d.useEffect(()=>{t&&setTimeout(()=>{var b,M;(b=h.current)==null||b.focus(),(M=h.current)==null||M.select()},50)},[t]),d.useEffect(()=>{if(!t)return;const b=window.visualViewport;if(!b||window.innerWidth>vs)return;const M=()=>{const R=E.current;R&&(R.style.height=`${b.height}px`,R.style.top=`${b.offsetTop}px`)};return M(),b.addEventListener("resize",M),b.addEventListener("scroll",M),()=>{b.removeEventListener("resize",M),b.removeEventListener("scroll",M);const R=E.current;R&&(R.style.height="",R.style.top="")}},[t]),d.useEffect(()=>{if(!t)return;const b=M=>{if(M.key==="Escape"){M.preventDefault(),M.stopPropagation(),M.stopImmediatePropagation(),e();return}if(M.key==="Tab"){M.preventDefault(),M.stopPropagation(),M.stopImmediatePropagation(),_.current(M.shiftKey?-1:1);return}if(M.altKey&&!M.ctrlKey&&!M.metaKey&&(M.key==="n"||M.key==="p"||M.key==="N"||M.key==="P")){M.preventDefault(),M.stopPropagation(),M.stopImmediatePropagation();const R=M.key.toLowerCase(),X=g.current;T(R==="p"?O=>O>0?O-1:X-1:O=>O<X-1?O+1:0);return}};return window.addEventListener("keydown",b,{capture:!0}),()=>{window.removeEventListener("keydown",b,{capture:!0})}},[t,e]);const ae=d.useCallback(b=>{b.target===b.currentTarget&&e()},[e]),H=d.useCallback(()=>{T(0)},[T]);return t?f.jsx("div",{ref:E,className:"spotlight-overlay",onClick:ae,children:f.jsxs("div",{className:"spotlight-modal",children:[f.jsx(Fs,{ref:h,query:p,onQueryChange:S,onKeyDown:$,onResetSelection:H}),f.jsx(Ss,{activeTab:G,onSelect:W}),f.jsx(bs,{ref:C,results:j,selectedIndex:F,query:p,activeTab:G,areaSections:ie,highlightMatch:N,onSelectIndex:T}),f.jsx(Bs,{})]})}):null}export{Ls as FILE_ICON_NAMES,Rs as Spotlight,Bs as SpotlightFooter,Fs as SpotlightInput,Je as SpotlightItem,bs as SpotlightResults,$s as formatDuration,js as formatRelativeTime,Ns as getAgentIcon,Dt as getFileIconFromPath,Ps as getTypeLabel,ws as useSpotlightSearch};
|