tide-commander 1.159.2 → 1.159.3
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 +5 -0
- package/dist/assets/{BossLogsModal-D7DRbxuN.js → BossLogsModal-DII7aJf5.js} +1 -1
- package/dist/assets/{BossSpawnModal-qWqV6cXb.js → BossSpawnModal-CQfEy11F.js} +1 -1
- package/dist/assets/{ControlsModal-Dx4Sd-zd.js → ControlsModal-DFo7lwSp.js} +1 -1
- package/dist/assets/{DockerLogsModal-DnBm69YT.js → DockerLogsModal-CXPYYhUg.js} +1 -1
- package/dist/assets/{EmbeddedEditor-egK0IcwH.js → EmbeddedEditor-Dboxn7s4.js} +1 -1
- package/dist/assets/{GmailOAuthSetup-Bi51Jkf8.js → GmailOAuthSetup-BXsCPLsp.js} +1 -1
- package/dist/assets/{GoogleOAuthSetup-BAREZ_c-.js → GoogleOAuthSetup-Bl-vieRg.js} +1 -1
- package/dist/assets/{IframeModal-Rh1yC6CF.js → IframeModal-BCRKWZQa.js} +1 -1
- package/dist/assets/{IntegrationsPanel-BPmG30Kf.js → IntegrationsPanel-C3Ia477x.js} +2 -2
- package/dist/assets/{LogViewerModal-V3LGKLOd.js → LogViewerModal--Ij8llxK.js} +1 -1
- package/dist/assets/{MonitoringModal-D5ObJhXH.js → MonitoringModal-OUrEUALC.js} +1 -1
- package/dist/assets/{PM2LogsModal-DyNAmc5D.js → PM2LogsModal-BIS752lh.js} +1 -1
- package/dist/assets/{RestoreArchivedAreaModal-C1afIOVX.js → RestoreArchivedAreaModal-07vSKn4W.js} +1 -1
- package/dist/assets/{Scene2DCanvas-C7weuP-e.js → Scene2DCanvas-JDJNFXK3.js} +1 -1
- package/dist/assets/{SceneManager-Cub1EW5Y.js → SceneManager-CkUd1aHW.js} +1 -1
- package/dist/assets/{SkillsPanel-C3PG0A6A.js → SkillsPanel-DiLbHStJ.js} +1 -1
- package/dist/assets/{SlackMultiInstanceSetup-vq1FipyR.js → SlackMultiInstanceSetup-F17-870l.js} +1 -1
- package/dist/assets/{SpawnModal-Df2Vp-HA.js → SpawnModal-DLmbxM30.js} +1 -1
- package/dist/assets/{StatisticsModal-D0yo2rbm.js → StatisticsModal-l6Ed7xxb.js} +1 -1
- package/dist/assets/{SubordinateAssignmentModal-BHQS1Xc_.js → SubordinateAssignmentModal-BNUrwWAx.js} +1 -1
- package/dist/assets/{TriggerManagerPanel-CEVMReTJ.js → TriggerManagerPanel-DruR51gp.js} +1 -1
- package/dist/assets/{WorkflowEditorPanel-BQbr0HYZ.js → WorkflowEditorPanel-D8O8NnFd.js} +1 -1
- package/dist/assets/{area-logos-CbdG7b49.js → area-logos-Baka5-sr.js} +1 -1
- package/dist/assets/{index-BvEk2Spw.js → index-3mmNpr_o.js} +3 -3
- package/dist/assets/{index-CxUhEi9L.js → index-BEtUppej.js} +1 -1
- package/dist/assets/{index-B4PPDHAS.js → index-C2F5Uash.js} +1 -1
- package/dist/assets/{index-C57r58R1.js → index-CGn4UG1-.js} +1 -1
- package/dist/assets/{index-Vee1Cpl9.js → index-CifRfrvD.js} +1 -1
- package/dist/assets/{index--FFJ9DPS.js → index-D89rSdZ_.js} +1 -1
- package/dist/assets/{index-EAqEvdMn.js → index-D_M5cgOI.js} +2 -2
- package/dist/assets/{index-fFR_58oB.js → index-LhjqVC1x.js} +1 -1
- package/dist/assets/{index-DN1jWADn.js → index-T8mnacEC.js} +1 -1
- package/dist/assets/{main-Btdl34Y5.js → main-Cn0uJsZU.js} +8 -8
- package/dist/assets/{web-Brq808vy.js → web-BLnXgjVn.js} +1 -1
- package/dist/assets/{web-CACmzQOn.js → web-BjfQGXzj.js} +1 -1
- package/dist/assets/{web-DPUDmaxp.js → web-DY_H8hM_.js} +1 -1
- package/dist/build-info.json +1 -1
- package/dist/index.html +1 -1
- package/dist/src/packages/server/claude/runner/tmux-helper.js +80 -18
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
import{i as At,k as yt,aC as Et,a5 as xt,m as Ct,cB as Mt,cC as Ft,aU as wt,r as d,$ as St,S as pe,cD as Bt,cE as fe,s as V,cF as vt,j as f,I as ne,cG as Ve,cH as It,a9 as _t,cI as Dt,cJ as kt,cK as Ee,aq as ve,_ as Rt,v as nt,u as Fe,cL as Je}from"./main-Btdl34Y5.js";import{cM as Ls,cN as $s,cO as js,cP as Ns,cQ as Ps}from"./main-Btdl34Y5.js";import"./vendor-react--Eh9ivFN.js";import"./vendor-three-Chj50gSY.js";function re(t){return Array.isArray?Array.isArray(t):ct(t)==="[object Array]"}function bt(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?"":bt(t)}function Z(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 G(t){return t!=null}function Ie(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(Z(t)||re(t))r=t,e=qe(t),n=_e(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=qe(o),n=_e(o),c=t.getFn}return{path:e,id:n,weight:i,src:r,getFn:c}}function qe(t){return re(t)?t:t.split(".")}function _e(t){return re(t)?t.join("."):t}function Gt(t,e){let n=[],r=!1;const i=(c,o,a)=>{if(G(c))if(!o[a])n.push(c);else{let u=o[a];const l=c[u];if(!G(l))return;if(a===o.length-1&&(Z(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,Z(e)?e.split("."):e,0),r?n:n[0]}const Qt={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:Gt,ignoreLocation:!1,ignoreFieldNorm:!1,fieldNormWeight:1};var y={...Wt,...Qt,...Ht,...Ut};const Yt=/[^ ]+/g;function Vt(t=1,e=3){const n=new Map,r=Math.pow(10,e);return{get(i){const c=i.match(Yt).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=Vt(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,Z(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();Z(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(!G(e)||Ie(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(G(o)){if(re(o)){let a=[];const u=[{nestedArrIndex:-1,value:o}];for(;u.length;){const{nestedArrIndex:l,value:h}=u.pop();if(G(h))if(Z(h)&&!Ie(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(Z(o)&&!Ie(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 qt(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,w=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;)w[T+N]=1,N+=1}}p=-1;let j=[],Q=1,W=h+E;const oe=1<<h-1;for(let $=0;$<h;$+=1){let N=0,D=W;for(;N<D;)xe(e,{errors:$,currentLocation:C+D,expectedLocation:C,distance:i,ignoreLocation:l})<=g?N=D:W=D,D=Math.floor((W-N)/2+N);W=D;let ae=Math.max(1,C-D+1),H=o?E:Math.min(C+D,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&&(w[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&&(Q=xe(e,{errors:$,currentLocation:X,expectedLocation:C,distance:i,ignoreLocation:l}),Q<=g)){if(g=Q,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,Q)};if(S){const $=Xt(w,a);$.length?u&&(ie.indices=$):ie.isMatch=!1}return ie}function Zt(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:Zt(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 w=C-le;E(this.pattern.substr(w),w)}}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:w,startIndex:T})=>{const{isMatch:j,score:Q,indices:W}=qt(e,S,w,{location:c+T,distance:o,threshold:a,findAllMatches:u,minMatchCharLength:l,includeMatches:i,ignoreLocation:h});j&&(g=!0),C+=Q,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 Ze(e,this.multiRegex)}static isSingleMatch(e){return Ze(e,this.singleRegex)}search(){}}function Ze(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 De=[es,ht,ss,ns,is,rs,ts,lt],et=De.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=De[l];let E=h.isMultiMatch(a);E&&(i.push(new h(E,e)),u=!0)}if(!u)for(l=-1;++l<et;){const h=De[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:w,score:T}=p.search(e);if(S){if(o+=1,u+=T,r){const j=p.constructor.type;us.has(j)?a=[...a,...w]:a.push(w)}}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 ke=[];function hs(...t){ke.push(...t)}function Re(t,e){for(let n=0,r=ke.length;n<r;n+=1){let i=ke[n];if(i.condition(t,e))return new i(t,e)}return new ut(t,e)}const Me={AND:"$and",OR:"$or"},be={PATH:"$path",PATTERN:"$val"},Te=t=>!!(t[Me.AND]||t[Me.OR]),ds=t=>!!t[be.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[be.PATH]:c[0],l=o?i[be.PATTERN]:i[u];if(!Z(l))throw new Error(Nt(u));const h={keyId:_e(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=[],G(n)&&n.forEach(r=>{if(!G(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 q{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){G(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=Z(e)?Z(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(!G(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(G(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(!G(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(!G(n))return[];let i=[];if(re(n))n.forEach(({v:c,i:o,n:a})=>{if(!G(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}}q.version="7.1.0";q.createIndex=at;q.parseIndex=Jt;q.config=y;q.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 Fs({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=Ft(),S=wt(),w=d.useRef(e);w.current=e;const T=d.useRef(n);T.current=n;const j=d.useRef(r);j.current=r;const Q=d.useRef(i);Q.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[D,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=D.trim();if(s.length<xs){O([]);return}let m=!1;const F=setTimeout(()=>{ys(s).then(x=>{m||O(x)}).catch(()=>{m||O([])})},250);return()=>{m=!0,clearTimeout(F)}},[t,D]);const we=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),F=fe[(m+s+fe.length)%fe.length];we(F)},[we]);d.useEffect(()=>{B(0)},[M]);const Se=V.getShortcuts(),ge=d.useMemo(()=>t?vt():{},[t]),me=d.useMemo(()=>{if(!t)return[];const s=window.matchMedia("(pointer: coarse)").matches,m=Se.find(x=>x.id==="spawn-agent"),F=Se.find(x=>x.id==="toggle-commander");return[{id:"cmd-spawn",type:"command",title:"Spawn New Agent",subtitle:s?"":m?Ve(m):"Alt+N",icon:f.jsx(ne,{name:"plus",size:16}),action:()=>{w.current(),T.current()}},{id:"cmd-commander",type:"command",title:"Commander View",subtitle:s?"":F!=null&&F.key?Ve(F):"Tab",icon:f.jsx(ne,{name:"dashboard",size:16}),action:()=>{w.current(),j.current()}},{id:"cmd-settings",type:"command",title:"Settings & Tools",subtitle:"Configure Tide Commander",icon:f.jsx(ne,{name:"gear",size:16}),action:()=>{w.current(),Q.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;w.current(),(x=N.current)==null||x.call(N)}}]},[t,Se]),he=d.useMemo(()=>t?Array.from(h.values()).map(s=>{const m=(g||[]).filter(Y=>Y.agentId===s.id).map(Y=>Y.filePath),F=[...new Set(m)],x=F.map(Y=>Y.split("/").pop()||Y),v=[];s.lastAssignedTask&&v.push(s.lastAssignedTask);const L=`${s.class} • ${s.cwd}`;let k=`${s.name} ${s.class} ${s.status} ${s.cwd}`;s.taskLabel&&(k+=` ${s.taskLabel}`),x.length>0&&(k+=` ${x.join(" ")} ${F.join(" ")}`),v.length>0&&(k+=` ${v.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(_t,{agent:s,size:20}),_searchText:k,_modifiedFiles:F,_userQueries:v,_agentId:s.id,_lastActivity:s.lastActivity,_taskLabel:s.taskLabel,_status:s.status,action:()=>{w.current(),It(s.id),V.selectAgent(s.id),V.getState().viewMode!=="flat"&&V.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:()=>{w.current(),V.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 F=V.getAreaForAgent(m.id);if(!F||F.archived)continue;const x=s.get(F.id);x?x.push(m):s.set(F.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=D.trim().toLowerCase(),m=Dt({sortMode:Ms(),agentsWithUnseenOutput:S,getLatestToolTimestamp:v=>Pe.get(v)}),F=Array.from(E.values()).filter(v=>!v.archived).filter(v=>s?v.name.toLowerCase().includes(s):!0).sort((v,L)=>v.name.localeCompare(L.name,void 0,{sensitivity:"base"})),x=[];for(const v of F){const k=(Ne.get(v.id)||[]).slice().sort(m).map(P=>je.get(P.id)).filter(P=>!!P);!s&&k.length===0||x.push({areaId:v.id,areaName:v.name,areaColor:v.color,agents:k})}return x},[t,D,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,Y,ue,ee;const m=s.status==="running"?"#4ade80":s.status==="stopped"?"#f87171":"#facc15",F=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 v=`${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];v+=` • ${z.engine} @ ${z.host}`}else s.type==="tests"&&s.folderPath?v=`${x} • ${s.folderPath}`:s.cwd&&(v+=` • ${s.cwd}`);const L=((Y=s.pm2Status)==null?void 0:Y.ports)||[];let k=`${s.name} ${s.type} ${s.status} ${s.cwd||""} ${((ue=s.pm2)==null?void 0:ue.name)||""}`;if(s.type==="tests"&&(k+=` ${s.folderPath||""} tests junit maven`),L.length>0&&(k+=` ${L.join(" ")}`),s.type==="database"&&((ee=s.database)!=null&&ee.connections))for(const z of s.database.connections)k+=` ${z.name} ${z.engine} ${z.host} ${z.database||""} mysql postgresql sql`;return{id:`building-${s.id}`,type:"building",title:s.name,subtitle:v,_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:F,size:16})]}),_searchText:k,action:()=>{var z;w.current(),s.type==="boss"?ie.current(s.id):s.type==="database"?$.current(s.id):s.type==="tests"?V.openTestsBuilding(s.id):s.type==="http"?V.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,F=[];for(const x of s){if(m.has(x.filePath))continue;m.add(x.filePath);const v=x.filePath.split("/").pop()||x.filePath,L=x.action==="created"?"Created":x.action==="modified"?"Modified":x.action==="deleted"?"Deleted":"Read";if(F.push({id:`modified-${x.filePath}-${x.timestamp}`,type:"modified-file",title:v,subtitle:`${L} by ${x.agentName} • ${x.filePath}`,matchedText:x.filePath,icon:x.action==="deleted"?f.jsx(ne,{name:"trash",size:16}):kt(x.filePath),action:()=>{w.current();const k=Array.from(V.getState().areas.values());for(const P of k)for(const U of P.directories||[])if(x.filePath.startsWith(U)){V.setFileViewerPath(x.filePath),W.current(P.id);return}V.selectAgent(x.agentId)}}),F.length>=50)break}return F},[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:()=>{w.current(),V.openFileExplorer(s.path)}}}):[],[t,X]),ze=d.useMemo(()=>new q(he,{keys:["title","subtitle","_searchText","lastUserInput"],threshold:.4,ignoreLocation:!0,includeScore:!0,includeMatches:!0}),[he]),Ge=d.useMemo(()=>new q(me,{keys:["title","subtitle"],threshold:.4,includeScore:!0,includeMatches:!0}),[me]),Qe=d.useMemo(()=>new q(Ae,{keys:["title","subtitle"],threshold:.4,includeScore:!0,includeMatches:!0}),[Ae]),We=d.useMemo(()=>new q(Ke,{keys:["title","subtitle","matchedText"],threshold:.4,ignoreLocation:!0,includeScore:!0,includeMatches:!0}),[Ke]),He=d.useMemo(()=>new q(ye,{keys:["title","subtitle","_searchText"],threshold:.4,ignoreLocation:!0,includeScore:!0,includeMatches:!0}),[ye]),de=d.useMemo(()=>{if(!D.trim()){const A=[];A.push(...ye);const I=[...he].sort((b,K)=>{const te=Ee(b._agentId,b._lastActivity,ge);return Ee(K._agentId,K._lastActivity,ge)-te});A.push(...I),A.push(...me.slice(0,2)),A.push(...Ae.slice(0,2));const _={};return Es.forEach((b,K)=>{_[b]=K}),A.sort((b,K)=>(_[b.type]??999)-(_[K.type]??999)),A}const s=D.trim().toLowerCase(),m=ze.search(D).slice(0,8),F=Ge.search(D).slice(0,3),x=Qe.search(D).slice(0,2),v=We.search(D).slice(0,3),L=Oe.slice(0,8),k=He.search(D).filter(A=>{const I=A.score??1;return`${A.item.title} ${A.item.subtitle||""} ${A.item._searchText||""}`.toLowerCase().includes(s)||I<=.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 I=A.title.toLowerCase();return I===s?6:I.startsWith(s)?5:I.split(/[^a-z0-9]+/i).includes(s)?4:I.includes(s)?3:`${A.subtitle||""} ${A._searchText||""} ${A.matchedText||""}`.toLowerCase().includes(s)?2:1},Y=(A,I)=>{const _=(1-Math.min(1,I??1))*4;return U(A)*100+(P[A.type]??0)*5+_},ue=new Map,ee=(A,I)=>{const _=ue.get(A.type),b={item:A,score:Y(A,I)};_?_.push(b):ue.set(A.type,[b])};for(const A of m){const I={...A.item};if(I._modifiedFiles&&I._modifiedFiles.length>0){const _=I._modifiedFiles.filter(b=>{var se;const K=((se=b.split("/").pop())==null?void 0:se.toLowerCase())||"",te=b.toLowerCase();return K.includes(s)||te.includes(s)});_.length>0&&(I.matchedFiles=_)}if(I._userQueries&&I._userQueries.length>0){const _=I._userQueries.find(b=>b.toLowerCase().includes(s));if(_)if(_.length>200){const K=_.toLowerCase().indexOf(s),te=Math.max(0,K-60),se=Math.min(_.length,K+s.length+100);I.matchedQuery=(te>0?"...":"")+_.slice(te,se)+(se<_.length?"...":"")}else I.matchedQuery=_}ee(I,A.score)}for(const A of k)ee(A.item,A.score);for(const A of F)ee(A.item,A.score);for(const A of x)ee(A.item,A.score);for(const A of v)ee(A.item,A.score);for(const A of L)ee(A,void 0);for(const[A,I]of ue)A==="agent"?I.sort((_,b)=>{const K=U(_.item),te=U(b.item);if(te!==K)return te-K;const se=Ee(_.item._agentId,_.item._lastActivity,ge),Ye=Ee(b.item._agentId,b.item._lastActivity,ge);return Ye!==se?Ye-se:b.score-_.score}):I.sort((_,b)=>b.score-_.score);const z=A=>A.reduce((I,_)=>Math.max(I,_.score),-1),Ue=[];return Array.from(ue.values()).sort((A,I)=>z(I)-z(A)).forEach(A=>{for(const I of A)Ue.push(I.item)}),Ue},[D,ze,Ge,Qe,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"?F=>F>0?F-1:J.length-1:F=>F<J.length-1?F+1:0);return}switch(s.key){case"Escape":s.preventDefault(),w.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 F=s.toLowerCase(),x=m.toLowerCase(),v=[];let L=0,k=F.indexOf(x),P=0;for(;k!==-1;)k>L&&v.push(s.slice(L,k)),v.push(ve.createElement("mark",{key:P++,className:"spotlight-highlight"},s.slice(k,k+m.length))),L=k+m.length,k=F.indexOf(x,L);return L<s.length&&v.push(s.slice(L)),v.length>0?ve.createElement(ve.Fragment,null,...v):s},[]);return{query:D,setQuery:ft,selectedIndex:H,setSelectedIndex:B,results:J,activeTab:M,setActiveTab:we,cycleTab:gt,areaSections:Be,handleKeyDown:pt,highlightMatch:mt}}const ws=d.forwardRef(function({query:e,onQueryChange:n,onKeyDown:r,onResetSelection:i},c){const{t:o}=Fe(["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}=Fe(["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}=Fe(["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((w,T)=>{w.type!==p&&(p!==null&&S.length>0&&g.push([p,S]),p=w.type,S=[]),S.push({result:w,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 w=g++;return f.jsx(Je,{result:S,isSelected:w===n,query:r,highlightMatch:o,onClick:()=>S.action(),onMouseEnter:()=>{h.current&&a(w)}},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:w})=>f.jsx(Je,{result:S,isSelected:w===n,query:r,highlightMatch:o,onClick:()=>S.action(),onMouseEnter:()=>{h.current&&a(w)}},S.id))]},g))})}),vs=d.memo(function(){const{t:e}=Fe(["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")]})})]})}),Is=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:w,setSelectedIndex:T,results:j,activeTab:Q,setActiveTab:W,cycleTab:oe,areaSections:ie,handleKeyDown:$,highlightMatch:N}=Fs({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=d.useRef(oe);D.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>Is)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(),D.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(ws,{ref:h,query:p,onQueryChange:S,onKeyDown:$,onResetSelection:H}),f.jsx(Ss,{activeTab:Q,onSelect:W}),f.jsx(Bs,{ref:C,results:j,selectedIndex:w,query:p,activeTab:Q,areaSections:ie,highlightMatch:N,onSelectIndex:T}),f.jsx(vs,{})]})}):null}export{Ls as FILE_ICON_NAMES,Rs as Spotlight,vs as SpotlightFooter,ws as SpotlightInput,Je as SpotlightItem,Bs as SpotlightResults,$s as formatDuration,js as formatRelativeTime,Ns as getAgentIcon,kt as getFileIconFromPath,Ps as getTypeLabel,Fs as useSpotlightSearch};
|
|
1
|
+
import{i as At,k as yt,aC as Et,a5 as xt,m as Ct,cB as Mt,cC as Ft,aU as wt,r as d,$ as St,S as pe,cD as Bt,cE as fe,s as V,cF as vt,j as f,I as ne,cG as Ve,cH as It,a9 as _t,cI as Dt,cJ as kt,cK as Ee,aq as ve,_ as Rt,v as nt,u as Fe,cL as Je}from"./main-Cn0uJsZU.js";import{cM as Ls,cN as $s,cO as js,cP as Ns,cQ as Ps}from"./main-Cn0uJsZU.js";import"./vendor-react--Eh9ivFN.js";import"./vendor-three-Chj50gSY.js";function re(t){return Array.isArray?Array.isArray(t):ct(t)==="[object Array]"}function bt(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?"":bt(t)}function Z(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 G(t){return t!=null}function Ie(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(Z(t)||re(t))r=t,e=qe(t),n=_e(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=qe(o),n=_e(o),c=t.getFn}return{path:e,id:n,weight:i,src:r,getFn:c}}function qe(t){return re(t)?t:t.split(".")}function _e(t){return re(t)?t.join("."):t}function Gt(t,e){let n=[],r=!1;const i=(c,o,a)=>{if(G(c))if(!o[a])n.push(c);else{let u=o[a];const l=c[u];if(!G(l))return;if(a===o.length-1&&(Z(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,Z(e)?e.split("."):e,0),r?n:n[0]}const Qt={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:Gt,ignoreLocation:!1,ignoreFieldNorm:!1,fieldNormWeight:1};var y={...Wt,...Qt,...Ht,...Ut};const Yt=/[^ ]+/g;function Vt(t=1,e=3){const n=new Map,r=Math.pow(10,e);return{get(i){const c=i.match(Yt).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=Vt(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,Z(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();Z(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(!G(e)||Ie(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(G(o)){if(re(o)){let a=[];const u=[{nestedArrIndex:-1,value:o}];for(;u.length;){const{nestedArrIndex:l,value:h}=u.pop();if(G(h))if(Z(h)&&!Ie(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(Z(o)&&!Ie(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 qt(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,w=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;)w[T+N]=1,N+=1}}p=-1;let j=[],Q=1,W=h+E;const oe=1<<h-1;for(let $=0;$<h;$+=1){let N=0,D=W;for(;N<D;)xe(e,{errors:$,currentLocation:C+D,expectedLocation:C,distance:i,ignoreLocation:l})<=g?N=D:W=D,D=Math.floor((W-N)/2+N);W=D;let ae=Math.max(1,C-D+1),H=o?E:Math.min(C+D,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&&(w[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&&(Q=xe(e,{errors:$,currentLocation:X,expectedLocation:C,distance:i,ignoreLocation:l}),Q<=g)){if(g=Q,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,Q)};if(S){const $=Xt(w,a);$.length?u&&(ie.indices=$):ie.isMatch=!1}return ie}function Zt(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:Zt(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 w=C-le;E(this.pattern.substr(w),w)}}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:w,startIndex:T})=>{const{isMatch:j,score:Q,indices:W}=qt(e,S,w,{location:c+T,distance:o,threshold:a,findAllMatches:u,minMatchCharLength:l,includeMatches:i,ignoreLocation:h});j&&(g=!0),C+=Q,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 Ze(e,this.multiRegex)}static isSingleMatch(e){return Ze(e,this.singleRegex)}search(){}}function Ze(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 De=[es,ht,ss,ns,is,rs,ts,lt],et=De.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=De[l];let E=h.isMultiMatch(a);E&&(i.push(new h(E,e)),u=!0)}if(!u)for(l=-1;++l<et;){const h=De[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:w,score:T}=p.search(e);if(S){if(o+=1,u+=T,r){const j=p.constructor.type;us.has(j)?a=[...a,...w]:a.push(w)}}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 ke=[];function hs(...t){ke.push(...t)}function Re(t,e){for(let n=0,r=ke.length;n<r;n+=1){let i=ke[n];if(i.condition(t,e))return new i(t,e)}return new ut(t,e)}const Me={AND:"$and",OR:"$or"},be={PATH:"$path",PATTERN:"$val"},Te=t=>!!(t[Me.AND]||t[Me.OR]),ds=t=>!!t[be.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[be.PATH]:c[0],l=o?i[be.PATTERN]:i[u];if(!Z(l))throw new Error(Nt(u));const h={keyId:_e(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=[],G(n)&&n.forEach(r=>{if(!G(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 q{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){G(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=Z(e)?Z(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(!G(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(G(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(!G(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(!G(n))return[];let i=[];if(re(n))n.forEach(({v:c,i:o,n:a})=>{if(!G(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}}q.version="7.1.0";q.createIndex=at;q.parseIndex=Jt;q.config=y;q.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 Fs({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=Ft(),S=wt(),w=d.useRef(e);w.current=e;const T=d.useRef(n);T.current=n;const j=d.useRef(r);j.current=r;const Q=d.useRef(i);Q.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[D,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=D.trim();if(s.length<xs){O([]);return}let m=!1;const F=setTimeout(()=>{ys(s).then(x=>{m||O(x)}).catch(()=>{m||O([])})},250);return()=>{m=!0,clearTimeout(F)}},[t,D]);const we=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),F=fe[(m+s+fe.length)%fe.length];we(F)},[we]);d.useEffect(()=>{B(0)},[M]);const Se=V.getShortcuts(),ge=d.useMemo(()=>t?vt():{},[t]),me=d.useMemo(()=>{if(!t)return[];const s=window.matchMedia("(pointer: coarse)").matches,m=Se.find(x=>x.id==="spawn-agent"),F=Se.find(x=>x.id==="toggle-commander");return[{id:"cmd-spawn",type:"command",title:"Spawn New Agent",subtitle:s?"":m?Ve(m):"Alt+N",icon:f.jsx(ne,{name:"plus",size:16}),action:()=>{w.current(),T.current()}},{id:"cmd-commander",type:"command",title:"Commander View",subtitle:s?"":F!=null&&F.key?Ve(F):"Tab",icon:f.jsx(ne,{name:"dashboard",size:16}),action:()=>{w.current(),j.current()}},{id:"cmd-settings",type:"command",title:"Settings & Tools",subtitle:"Configure Tide Commander",icon:f.jsx(ne,{name:"gear",size:16}),action:()=>{w.current(),Q.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;w.current(),(x=N.current)==null||x.call(N)}}]},[t,Se]),he=d.useMemo(()=>t?Array.from(h.values()).map(s=>{const m=(g||[]).filter(Y=>Y.agentId===s.id).map(Y=>Y.filePath),F=[...new Set(m)],x=F.map(Y=>Y.split("/").pop()||Y),v=[];s.lastAssignedTask&&v.push(s.lastAssignedTask);const L=`${s.class} • ${s.cwd}`;let k=`${s.name} ${s.class} ${s.status} ${s.cwd}`;s.taskLabel&&(k+=` ${s.taskLabel}`),x.length>0&&(k+=` ${x.join(" ")} ${F.join(" ")}`),v.length>0&&(k+=` ${v.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(_t,{agent:s,size:20}),_searchText:k,_modifiedFiles:F,_userQueries:v,_agentId:s.id,_lastActivity:s.lastActivity,_taskLabel:s.taskLabel,_status:s.status,action:()=>{w.current(),It(s.id),V.selectAgent(s.id),V.getState().viewMode!=="flat"&&V.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:()=>{w.current(),V.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 F=V.getAreaForAgent(m.id);if(!F||F.archived)continue;const x=s.get(F.id);x?x.push(m):s.set(F.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=D.trim().toLowerCase(),m=Dt({sortMode:Ms(),agentsWithUnseenOutput:S,getLatestToolTimestamp:v=>Pe.get(v)}),F=Array.from(E.values()).filter(v=>!v.archived).filter(v=>s?v.name.toLowerCase().includes(s):!0).sort((v,L)=>v.name.localeCompare(L.name,void 0,{sensitivity:"base"})),x=[];for(const v of F){const k=(Ne.get(v.id)||[]).slice().sort(m).map(P=>je.get(P.id)).filter(P=>!!P);!s&&k.length===0||x.push({areaId:v.id,areaName:v.name,areaColor:v.color,agents:k})}return x},[t,D,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,Y,ue,ee;const m=s.status==="running"?"#4ade80":s.status==="stopped"?"#f87171":"#facc15",F=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 v=`${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];v+=` • ${z.engine} @ ${z.host}`}else s.type==="tests"&&s.folderPath?v=`${x} • ${s.folderPath}`:s.cwd&&(v+=` • ${s.cwd}`);const L=((Y=s.pm2Status)==null?void 0:Y.ports)||[];let k=`${s.name} ${s.type} ${s.status} ${s.cwd||""} ${((ue=s.pm2)==null?void 0:ue.name)||""}`;if(s.type==="tests"&&(k+=` ${s.folderPath||""} tests junit maven`),L.length>0&&(k+=` ${L.join(" ")}`),s.type==="database"&&((ee=s.database)!=null&&ee.connections))for(const z of s.database.connections)k+=` ${z.name} ${z.engine} ${z.host} ${z.database||""} mysql postgresql sql`;return{id:`building-${s.id}`,type:"building",title:s.name,subtitle:v,_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:F,size:16})]}),_searchText:k,action:()=>{var z;w.current(),s.type==="boss"?ie.current(s.id):s.type==="database"?$.current(s.id):s.type==="tests"?V.openTestsBuilding(s.id):s.type==="http"?V.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,F=[];for(const x of s){if(m.has(x.filePath))continue;m.add(x.filePath);const v=x.filePath.split("/").pop()||x.filePath,L=x.action==="created"?"Created":x.action==="modified"?"Modified":x.action==="deleted"?"Deleted":"Read";if(F.push({id:`modified-${x.filePath}-${x.timestamp}`,type:"modified-file",title:v,subtitle:`${L} by ${x.agentName} • ${x.filePath}`,matchedText:x.filePath,icon:x.action==="deleted"?f.jsx(ne,{name:"trash",size:16}):kt(x.filePath),action:()=>{w.current();const k=Array.from(V.getState().areas.values());for(const P of k)for(const U of P.directories||[])if(x.filePath.startsWith(U)){V.setFileViewerPath(x.filePath),W.current(P.id);return}V.selectAgent(x.agentId)}}),F.length>=50)break}return F},[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:()=>{w.current(),V.openFileExplorer(s.path)}}}):[],[t,X]),ze=d.useMemo(()=>new q(he,{keys:["title","subtitle","_searchText","lastUserInput"],threshold:.4,ignoreLocation:!0,includeScore:!0,includeMatches:!0}),[he]),Ge=d.useMemo(()=>new q(me,{keys:["title","subtitle"],threshold:.4,includeScore:!0,includeMatches:!0}),[me]),Qe=d.useMemo(()=>new q(Ae,{keys:["title","subtitle"],threshold:.4,includeScore:!0,includeMatches:!0}),[Ae]),We=d.useMemo(()=>new q(Ke,{keys:["title","subtitle","matchedText"],threshold:.4,ignoreLocation:!0,includeScore:!0,includeMatches:!0}),[Ke]),He=d.useMemo(()=>new q(ye,{keys:["title","subtitle","_searchText"],threshold:.4,ignoreLocation:!0,includeScore:!0,includeMatches:!0}),[ye]),de=d.useMemo(()=>{if(!D.trim()){const A=[];A.push(...ye);const I=[...he].sort((b,K)=>{const te=Ee(b._agentId,b._lastActivity,ge);return Ee(K._agentId,K._lastActivity,ge)-te});A.push(...I),A.push(...me.slice(0,2)),A.push(...Ae.slice(0,2));const _={};return Es.forEach((b,K)=>{_[b]=K}),A.sort((b,K)=>(_[b.type]??999)-(_[K.type]??999)),A}const s=D.trim().toLowerCase(),m=ze.search(D).slice(0,8),F=Ge.search(D).slice(0,3),x=Qe.search(D).slice(0,2),v=We.search(D).slice(0,3),L=Oe.slice(0,8),k=He.search(D).filter(A=>{const I=A.score??1;return`${A.item.title} ${A.item.subtitle||""} ${A.item._searchText||""}`.toLowerCase().includes(s)||I<=.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 I=A.title.toLowerCase();return I===s?6:I.startsWith(s)?5:I.split(/[^a-z0-9]+/i).includes(s)?4:I.includes(s)?3:`${A.subtitle||""} ${A._searchText||""} ${A.matchedText||""}`.toLowerCase().includes(s)?2:1},Y=(A,I)=>{const _=(1-Math.min(1,I??1))*4;return U(A)*100+(P[A.type]??0)*5+_},ue=new Map,ee=(A,I)=>{const _=ue.get(A.type),b={item:A,score:Y(A,I)};_?_.push(b):ue.set(A.type,[b])};for(const A of m){const I={...A.item};if(I._modifiedFiles&&I._modifiedFiles.length>0){const _=I._modifiedFiles.filter(b=>{var se;const K=((se=b.split("/").pop())==null?void 0:se.toLowerCase())||"",te=b.toLowerCase();return K.includes(s)||te.includes(s)});_.length>0&&(I.matchedFiles=_)}if(I._userQueries&&I._userQueries.length>0){const _=I._userQueries.find(b=>b.toLowerCase().includes(s));if(_)if(_.length>200){const K=_.toLowerCase().indexOf(s),te=Math.max(0,K-60),se=Math.min(_.length,K+s.length+100);I.matchedQuery=(te>0?"...":"")+_.slice(te,se)+(se<_.length?"...":"")}else I.matchedQuery=_}ee(I,A.score)}for(const A of k)ee(A.item,A.score);for(const A of F)ee(A.item,A.score);for(const A of x)ee(A.item,A.score);for(const A of v)ee(A.item,A.score);for(const A of L)ee(A,void 0);for(const[A,I]of ue)A==="agent"?I.sort((_,b)=>{const K=U(_.item),te=U(b.item);if(te!==K)return te-K;const se=Ee(_.item._agentId,_.item._lastActivity,ge),Ye=Ee(b.item._agentId,b.item._lastActivity,ge);return Ye!==se?Ye-se:b.score-_.score}):I.sort((_,b)=>b.score-_.score);const z=A=>A.reduce((I,_)=>Math.max(I,_.score),-1),Ue=[];return Array.from(ue.values()).sort((A,I)=>z(I)-z(A)).forEach(A=>{for(const I of A)Ue.push(I.item)}),Ue},[D,ze,Ge,Qe,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"?F=>F>0?F-1:J.length-1:F=>F<J.length-1?F+1:0);return}switch(s.key){case"Escape":s.preventDefault(),w.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 F=s.toLowerCase(),x=m.toLowerCase(),v=[];let L=0,k=F.indexOf(x),P=0;for(;k!==-1;)k>L&&v.push(s.slice(L,k)),v.push(ve.createElement("mark",{key:P++,className:"spotlight-highlight"},s.slice(k,k+m.length))),L=k+m.length,k=F.indexOf(x,L);return L<s.length&&v.push(s.slice(L)),v.length>0?ve.createElement(ve.Fragment,null,...v):s},[]);return{query:D,setQuery:ft,selectedIndex:H,setSelectedIndex:B,results:J,activeTab:M,setActiveTab:we,cycleTab:gt,areaSections:Be,handleKeyDown:pt,highlightMatch:mt}}const ws=d.forwardRef(function({query:e,onQueryChange:n,onKeyDown:r,onResetSelection:i},c){const{t:o}=Fe(["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}=Fe(["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}=Fe(["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((w,T)=>{w.type!==p&&(p!==null&&S.length>0&&g.push([p,S]),p=w.type,S=[]),S.push({result:w,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 w=g++;return f.jsx(Je,{result:S,isSelected:w===n,query:r,highlightMatch:o,onClick:()=>S.action(),onMouseEnter:()=>{h.current&&a(w)}},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:w})=>f.jsx(Je,{result:S,isSelected:w===n,query:r,highlightMatch:o,onClick:()=>S.action(),onMouseEnter:()=>{h.current&&a(w)}},S.id))]},g))})}),vs=d.memo(function(){const{t:e}=Fe(["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")]})})]})}),Is=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:w,setSelectedIndex:T,results:j,activeTab:Q,setActiveTab:W,cycleTab:oe,areaSections:ie,handleKeyDown:$,highlightMatch:N}=Fs({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=d.useRef(oe);D.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>Is)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(),D.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(ws,{ref:h,query:p,onQueryChange:S,onKeyDown:$,onResetSelection:H}),f.jsx(Ss,{activeTab:Q,onSelect:W}),f.jsx(Bs,{ref:C,results:j,selectedIndex:w,query:p,activeTab:Q,areaSections:ie,highlightMatch:N,onSelectIndex:T}),f.jsx(vs,{})]})}):null}export{Ls as FILE_ICON_NAMES,Rs as Spotlight,vs as SpotlightFooter,ws as SpotlightInput,Je as SpotlightItem,Bs as SpotlightResults,$s as formatDuration,js as formatRelativeTime,Ns as getAgentIcon,kt as getFileIconFromPath,Ps as getTypeLabel,Fs as useSpotlightSearch};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{r as s,H as Sa,J as Qt,K as ua,L as ma,j as e,M as pa,N as Aa,u as Yt,O as Ea,P as Ma,U as Ia,V as Ta,W as La,X as Pa,Y as Ra,Z as fa,_ as ea,S as A,$ as ta,a0 as qt,a1 as aa,a2 as Et,a3 as be,a4 as Da,s as g,a5 as ha,m as ga,a6 as $a,z as na,B as sa,I as d,a7 as za,q as Oa,a8 as Ba,a9 as xa,aa as ba,ab as _a,ac as wa,ad as Fa,ae as Wa,af as Ha,ag as Ua,ah as Ga,ai as Va,aj as Xa,ak as qa,al as Ya,am as Ka,an as Za,ao as Ja,ap as ia,C as Qa,aq as en,ar as la,as as tn,at as an,au as nn,av as sn,aw as ln,ax as rn,ay as on,az as cn,aA as dn,aB as un,aC as mn,aD as pn,aE as fn,aF as hn,aG as gn,aH as nt,aI as xn,aJ as bn,aK as _n,aL as wn,aM as ft,aN as vn,aO as jn,aP as Cn,aQ as kn,aR as Nn,aS as ra,aT as yn}from"./main-Btdl34Y5.js";import{g as Sn}from"./area-logos-CbdG7b49.js";import"./vendor-react--Eh9ivFN.js";import"./vendor-three-Chj50gSY.js";function An(c){const r=s.useRef(c);r.current=c,s.useEffect(()=>{if(!Sa())return;let p=null,x=!1;return Qt.addListener("backButton",()=>{r.current()==="exit"&&Qt.exitApp()}).then(C=>{x?C.remove():p=C}),()=>{x=!0,p&&(p.remove(),p=null)}},[])}async function En(c){const r=ua(),p=await fetch(`${ma()}/api/agents/${c}/terminal`,{method:"POST",headers:{Authorization:`Bearer ${r}`}});if(!p.ok){const x=await p.json().catch(()=>({}));throw new Error((x==null?void 0:x.error)||`Failed to start terminal (${p.status})`)}return p.json()}async function Mn(c){const r=ua();await fetch(`${ma()}/api/agents/${c}/terminal`,{method:"DELETE",headers:{Authorization:`Bearer ${r}`}})}const ht=new Map;function In({agentId:c}){const[r,p]=s.useState(null),[x,C]=s.useState(null);return s.useEffect(()=>{let T=!1;const S=ht.get(c);return S&&(clearTimeout(S),ht.delete(c)),p(null),C(null),En(c).then(N=>{T||p(N.url)}).catch(N=>{T||C(N instanceof Error?N.message:"Failed to start terminal")}),()=>{T=!0;const N=ht.get(c);N&&clearTimeout(N),ht.set(c,setTimeout(()=>{ht.delete(c),Mn(c)},2500))}},[c]),x?e.jsx("div",{className:"flat-classic-terminal flat-classic-terminal--message",children:e.jsx("span",{children:x})}):r?e.jsx("div",{className:"flat-classic-terminal",children:e.jsx(pa,{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 Ut=new Map,Tn=6e4;function oa(c){return Number.isFinite(c)?Math.abs(c)>=1e3?c.toLocaleString(void 0,{maximumFractionDigits:0}):c.toLocaleString(void 0,{maximumFractionDigits:2}):String(c)}function Ln(c,r){var C,T,S;const p=[];if(!c.rateLimits)return p;if(c.provider==="claude"){const N=c,J=[{key:"fiveHour",label:r("terminal:usage.currentSession"),window:N.rateLimits.fiveHour},{key:"sevenDay",label:r("terminal:usage.currentWeekAll"),window:N.rateLimits.sevenDay},{key:"sevenDayOpus",label:r("terminal:usage.currentWeekOpus"),window:N.rateLimits.sevenDayOpus},{key:"sevenDaySonnet",label:r("terminal:usage.currentWeekSonnet"),window:N.rateLimits.sevenDaySonnet}];for(const w of J)w.window&&p.push({...w,window:w.window});return p}const x=c;return(C=x.rateLimits)!=null&&C.weekly&&p.push({key:"weekly",label:r("terminal:usage.weeklyLimit"),window:x.rateLimits.weekly}),(T=x.rateLimits)!=null&&T.monthly&&p.push({key:"monthly",label:r("terminal:usage.monthlyLimit"),window:x.rateLimits.monthly}),(S=x.rateLimits)!=null&&S.onDemand&&p.push({key:"onDemand",label:r("terminal:usage.onDemandLimit"),window:x.rateLimits.onDemand}),p}function Pn({agentId:c,contextSummary:r}){const{t:p}=Yt(["terminal","common"]),[x,C]=s.useState(()=>{var z;return((z=Ut.get(c))==null?void 0:z.snapshot)??null}),[T,S]=s.useState(!1),[N,J]=s.useState(null),w=s.useRef(0);s.useEffect(()=>{const z=Ut.get(c);if(z&&Date.now()-z.fetchedAt<Tn){C(z.snapshot);return}const le=++w.current;S(!0),J(null),Ea(c).then(R=>{le===w.current&&(Ut.set(c,{snapshot:R,fetchedAt:Date.now()}),C(R),S(!1))}).catch(R=>{le===w.current&&(J(R.message||"Failed to load plan limits"),S(!1))})},[c]);const U=x?Ln(x,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")}),T&&!x&&e.jsxs("div",{className:"plan-limits-tooltip__muted",children:[p("common:status.loading"),"…"]}),!T&&N&&!x&&e.jsx("div",{className:"plan-limits-tooltip__muted",children:p("terminal:usage.limitsError",{message:N})}),U.length>0?e.jsx("div",{className:"plan-limits-tooltip__gauges",children:U.map(({key:z,label:le,window:R})=>{const Se=Math.max(0,Math.min(100,R.utilization)),re=Ia(Se),oe=typeof R.used=="number"&&typeof R.limit=="number"&&Number.isFinite(R.used)&&Number.isFinite(R.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:le}),e.jsx("span",{className:"plan-limits-tooltip__gauge-percent",style:{color:re},children:p("terminal:usage.percentUsed",{percent:Math.round(Se)})})]}),e.jsx("div",{className:"plan-limits-tooltip__bar",children:e.jsx("div",{className:"plan-limits-tooltip__bar-fill",style:{width:`${Se}%`,background:re}})}),e.jsxs("div",{className:"plan-limits-tooltip__reset",children:[p("terminal:usage.resets",{time:Ma(R.resetsAt)}),oe&&e.jsx("span",{style:{marginLeft:8},children:p("terminal:usage.creditsUsed",{used:oa(R.used),limit:oa(R.limit)})})]})]},z)})}):x&&!T&&e.jsx("div",{className:"plan-limits-tooltip__muted",children:x.rateLimitsError?p("terminal:usage.limitsError",{message:x.rateLimitsError}):x.cliHint})]})}function Rn({agentId:c,disabled:r,contextSummary:p,children:x}){return e.jsx(Aa,{position:"top",maxWidth:320,disabled:r,className:"plan-limits-tooltip-wrapper",triggerStyle:{display:"inline-flex",alignItems:"center"},content:e.jsx(Pn,{agentId:c,contextSummary:p}),children:x})}const Dn=s.memo(function({className:r=""}){const{t:p}=Yt(["common"]),[x,C]=Ta(),T=s.useRef(null),[S,N]=s.useState(null);s.useLayoutEffect(()=>{const w=T.current;if(!w)return;const U=w.querySelector(".view-mode-toggle__btn--active");U&&N({left:U.offsetLeft,width:U.offsetWidth})},[x]);const J=s.useCallback(w=>{if(w!==x){if(typeof window<"u"&&window.dispatchEvent(new CustomEvent("tide:viewmode-switch-pressed",{detail:{mode:w}})),w==="3d"){requestAnimationFrame(()=>C(w));return}C(w)}},[x,C]);return e.jsxs("div",{className:`view-mode-toggle ${r}`,ref:T,children:[S&&e.jsx("div",{className:"view-mode-toggle__indicator",style:{left:S.left,width:S.width}}),La.map(w=>e.jsxs("button",{className:`view-mode-toggle__btn ${x===w?"view-mode-toggle__btn--active":""}`,onClick:()=>J(w),title:p(`common:viewMode.descriptions.${w}`),children:[e.jsxs("span",{className:"view-mode-toggle__icon",children:[w==="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"})]}),w==="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"})]}),w==="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"})]}),w==="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.${w}`)})]},w))]})}),Mt=3,It=280,ca=320,Gt=240,da=64,$n=["simple","chat","advanced"],zn={simple:"Simple",chat:"Chat",advanced:"Advanced"},On={simple:"○",chat:"◐",advanced:"◉"},Bn={simple:"Simple view — clean messages only",chat:"Chat view — assistant replies (no tool calls)",advanced:"Advanced view — everything including tools"},Vt="flat-clear-context",va="tide:flat-embedded-panels";function ja(){try{const c=localStorage.getItem(va),r=c?JSON.parse(c):{};return r&&typeof r=="object"?r:{}}catch{return{}}}function Xt(c,r){try{const p=ja();r?p[c]=r:delete p[c],localStorage.setItem(va,JSON.stringify(p))}catch{}}function Fn(c){const r=c.split("/").filter(Boolean);return r.length===0?c:r.slice(-2).join("/")}function Wn(c){if(c.provider==="codex"){const T=c.codexModel||"gpt-5.6-luna",S=Nn[T];return{model:(S==null?void 0:S.label)||T}}if(c.provider==="opencode")return{model:c.opencodeModel||"opencode"};if(c.provider==="grok"){const T=c.grokModel||"grok-4.5",S=c.effort,N=S?ra[S]:void 0;return{model:T,effort:N==null?void 0:N.label}}const r=c.model||"sonnet",p=yn[r],x=c.effort,C=x?ra[x]:void 0;return{model:(p==null?void 0:p.label)||r,effort:C==null?void 0:C.label}}function Hn(c,r){if(r.type==="rectangle"&&r.width&&r.height){const p=r.width/2,x=r.height/2;return c.x>=r.center.x-p&&c.x<=r.center.x+p&&c.z>=r.center.z-x&&c.z<=r.center.z+x}if(r.type==="circle"&&r.radius){const p=c.x-r.center.x,x=c.z-r.center.z;return p*p+x*x<=r.radius*r.radius}return!1}const Un=en.memo(function({agentId:r,terminalViewMode:p,onTerminalViewModeChange:x,inspectorOpen:C,onToggleInspector:T,onShowTaskBoard:S,onImageClick:N,onFileClick:J,onBashClick:w,onViewMarkdown:U,onRequestClearSubordinates:z,keyboard:le,canNavigateBack:R,canNavigateForward:Se,onNavigateBack:re,onNavigateForward:oe,agentInfoOpen:$e,onToggleAgentInfo:gt,onHeaderContextMenu:_e,onBuildingContextMenu:we}){var Ct,kt;const f=la(r),O=ga(),Ae=tn(),Ee=s.useRef(null),Ye=s.useRef(null),{displayedAgentId:Me,fadingOut:Tt}=an(r),xt=la(Me),Ke=!!Ae.interactiveMode&&((f==null?void 0:f.provider)??"claude")==="claude"&&!!(f!=null&&f.sessionId),[ce,Ze]=s.useState(!1),[ze,de]=s.useState(!1),D=s.useCallback(()=>de(!1),[]);fa("flat-chat-actions",ze,D),s.useEffect(()=>{const a=()=>de(o=>!o);return window.addEventListener("tide:toggle-chat-actions",a),()=>window.removeEventListener("tide:toggle-chat-actions",a)},[]),s.useEffect(()=>{Ze(!1),de(!1)},[r]),s.useEffect(()=>{!Ke&&ce&&Ze(!1)},[Ke,ce]),s.useEffect(()=>{const a=Ye.current;if(!a)return;const o=u=>{u.button===3?(u.preventDefault(),u.stopPropagation(),re()):u.button===4&&(u.preventDefault(),u.stopPropagation(),oe())},i=u=>{(u.button===3||u.button===4)&&u.preventDefault()};return a.addEventListener("mouseup",o),a.addEventListener("mousedown",i),()=>{a.removeEventListener("mouseup",o),a.removeEventListener("mousedown",i)}},[re,oe]),s.useEffect(()=>{const a=Ye.current;if(!a)return;let o=0,i=0,u=0;const X=250,te=600,L=80,at=1.5,q=ne=>{let G=ne instanceof HTMLElement?ne:null;for(;G&&G!==a;){const Nt=window.getComputedStyle(G).overflowX;if((Nt==="auto"||Nt==="scroll")&&G.scrollWidth>G.clientWidth)return!0;G=G.parentElement}return!1},Xe=ne=>{const G=Date.now();if(G<u){ne.preventDefault();return}if(Math.abs(ne.deltaX)<=Math.abs(ne.deltaY)*at){o=0;return}if(q(ne.target)){o=0;return}G-i>X&&(o=0),i=G,o+=ne.deltaX,o<=-L?(o=0,u=G+te,ne.preventDefault(),re()):o>=L&&(o=0,u=G+te,ne.preventDefault(),oe())};return a.addEventListener("wheel",Xe,{passive:!1}),()=>a.removeEventListener("wheel",Xe)},[re,oe]);const ue=ha(),st=s.useMemo(()=>{if(!f)return null;const a=new Set,o=[];for(const i of ue.values())i.archived||i.directories.length===0||i.assignedAgentIds.includes(r)&&(a.add(i.id),o.push(i));for(const i of ue.values())i.archived||i.directories.length===0||a.has(i.id)||Hn({x:f.position.x,z:f.position.z},i)&&(a.add(i.id),o.push(i));return o.length===0?null:o.flatMap(i=>i.directories.filter(u=>u&&u.trim().length>0).map(u=>({areaId:i.id,areaName:i.name,dir:u})))},[f,r,ue]),{branches:bt,fetchRemote:Oe,fetchingDirs:Ie}=nn(st),me=s.useMemo(()=>{var i;const a=g.getAreaForAgent(r);if(!a)return[];const o=[];for(const u of O.values())u.type==="terminal"&&g.isPositionInArea(u.position,a)&&o.push({id:u.id,name:u.name,hasUrl:!!((i=u.terminalStatus)!=null&&i.url)});return o},[r,O]),ve=s.useMemo(()=>{var i;const a=g.getAreaForAgent(r);if(!a)return[];const o=[];for(const u of O.values())u.type==="server"&&((i=u.pm2)!=null&&i.enabled)&&g.isPositionInArea(u.position,a)&&o.push({id:u.id,name:u.name});return o},[r,O]),Q=s.useMemo(()=>{const a=g.getAreaForAgent(r);if(!a)return[];const o=[];for(const i of O.values())i.type==="database"&&i.database&&g.isPositionInArea(i.position,a)&&o.push({id:i.id,name:i.name});return o},[r,O]),Be=sn(),se=s.useMemo(()=>{const a=g.getAreaForAgent(r);if(!a)return[];const o=[];for(const i of O.values())if(i.type==="tests"&&g.isPositionInArea(i.position,a)){const u=!!i.folderPath&&Be.some(X=>ln(X,i.folderPath));o.push({id:i.id,name:i.name,working:u})}return o},[r,O,Be]),ie=s.useMemo(()=>{const a=g.getAreaForAgent(r);if(!a)return[];const o=[];for(const i of O.values())i.type==="http"&&g.isPositionInArea(i.position,a)&&o.push({id:i.id,name:i.name});return o},[r,O]),[,Lt]=s.useReducer(a=>a+1,0),je=((Ct=Ee.current)==null?void 0:Ct.search.searchMode)??!1,it=s.useCallback(()=>{var a;(a=Ee.current)==null||a.search.toggleSearch(),Lt()},[]),Te=rn(),Le=Te.isPending(Vt),[j,ae]=s.useState(null),ee=j?O.get(j.buildingId):null,[Fe,Pe]=s.useState(""),[We,Pt]=s.useState(()=>on()),B=s.useMemo(()=>{var a;return((a=g.getAreaForAgent(r))==null?void 0:a.id)??null},[r,O]),He=s.useCallback((a,o)=>{Pe(""),ae(i=>{const u=(i==null?void 0:i.buildingId)===o?null:{type:a,buildingId:o};return B&&Xt(B,u),u})},[B]),Ce=s.useCallback(()=>{Pe(""),ae(null),B&&Xt(B,null)},[B]);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}=cn(),{sidePanelWidth:$t,handleSidePanelResizeStart:lt}=dn(),[_,_t]=s.useState(()=>qt(A.GIT_PANEL_OPEN,!1)),[Re,pe]=s.useState(()=>qt(A.BUILDINGS_PANEL_OPEN,!1)),[F,Ue]=s.useState(!1),rt=s.useCallback(()=>{Ue(a=>{const o=!a;return o&&un.setEnabled(!0),o})},[]),zt=s.useCallback(()=>Ue(!1),[]),wt=s.useCallback(()=>{_t(a=>{const o=!a;return be(A.GIT_PANEL_OPEN,o),o})},[]),vt=s.useCallback(()=>{pe(a=>{const o=!a;return be(A.BUILDINGS_PANEL_OPEN,o),o})},[]),Ot=s.useCallback(()=>{_t(!1),be(A.GIT_PANEL_OPEN,!1)},[]),ot=s.useCallback(()=>{pe(!1),be(A.BUILDINGS_PANEL_OPEN,!1)},[]),Ge=mn(),fe=s.useMemo(()=>({terminal:me,"pm2-logs":ve,database:Q,tests:se,http:ie}),[me,ve,Q,se,ie]);s.useEffect(()=>{if(!j)return;fe[j.type].some(o=>o.id===j.buildingId)||(Pe(""),ae(null))},[j,fe]);const ke=s.useRef(void 0);s.useEffect(()=>{var o;if(ke.current===B)return;ke.current=B;const a=B?ja()[B]:void 0;Pe(""),a&&((o=fe[a.type])!=null&&o.some(i=>i.id===a.buildingId))?ae(a):ae(null)},[B,fe]),s.useEffect(()=>{const a=o=>{var X;const i=o.detail;if(!(i!=null&&i.buildingId)||!(i!=null&&i.type)||!((X=fe[i.type])!=null&&X.some(te=>te.id===i.buildingId)))return;i.handled=!0,Pe("");const u={type:i.type,buildingId:i.buildingId};ae(u),B&&Xt(B,u)};return window.addEventListener("tide:dock-building-flat",a),()=>window.removeEventListener("tide:dock-building-flat",a)},[fe,B]);const[Ve,W]=s.useState(!1),he=s.useRef(null);if(s.useEffect(()=>{if(!Ve)return;const a=o=>{he.current&&!he.current.contains(o.target)&&W(!1)};return document.addEventListener("mousedown",a),()=>document.removeEventListener("mousedown",a)},[Ve]),!f)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 Ne=f.contextStats,ct=!!Ne,Je=Ne?Ne.totalTokens:f.contextUsed||0,dt=Ne?Ne.contextWindow:f.contextLimit||(f.provider==="grok"?5e5:2e5),Bt=Ne?Ne.usedPercent:Math.round(Je/dt*100),De=Math.max(0,Math.min(100,Bt)),jt=Math.round(De*10)/10,ge=Math.round((100-De)*10)/10,Qe=De>=80?"#ff4a4a":De>=60?"#ff9e4a":De>=40?"#ffd700":"#4aff9e",et=(Je/1e3).toFixed(1),ut=(dt/1e3).toFixed(1),xe=f.cwd,mt=xe?Fn(xe):null,ye=((kt=f.subordinateIds)==null?void 0:kt.length)||0,tt=ye>0;return e.jsxs("div",{ref:Ye,className:`flat-terminal-wrapper ${_||Re||F?"flat-terminal-wrapper--with-side-panel":""} ${Tt?"pane-fading-out":""}`,style:{"--guake-side-panel-width":`min(${$t}px, 70%)`},children:[e.jsxs("div",{className:"flat-terminal-wrapper__header",children:[e.jsxs("button",{type:"button",className:`flat-terminal-wrapper__header-main ${$e?"flat-terminal-wrapper__header-main--active":""}`,onClick:gt,onContextMenu:a=>{a.preventDefault(),a.stopPropagation(),_e({x:a.clientX,y:a.clientY})},title:$e?"Hide agent info":"Show agent info","aria-pressed":$e,children:[e.jsx("span",{className:`flat-terminal-wrapper__header-avatar${f.status==="working"?" is-working":""}`,children:e.jsx(xa,{agent:f,size:28})}),e.jsxs("span",{className:"flat-terminal-wrapper__header-info",children:[e.jsx("span",{className:"flat-terminal-wrapper__header-name",children:f.name}),e.jsx("span",{className:"flat-terminal-wrapper__header-status",style:{color:wa(f.status)},children:f.status})]}),f.taskLabel&&e.jsxs("span",{className:"flat-terminal-wrapper__header-task",title:f.taskLabel,children:["📋 ",f.taskLabel]}),e.jsxs("span",{className:"flat-terminal-wrapper__header-model",children:[e.jsx("img",{src:_a(f.provider,"/"),alt:f.provider,className:"flat-terminal-wrapper__header-provider-icon",title:ba(f.provider)}),(()=>{const{model:a,effort:o}=Wn(f);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:[$n.map(a=>e.jsxs("button",{type:"button",className:`flat-terminal-wrapper__view-mode-btn ${!ce&&p===a?"flat-terminal-wrapper__view-mode-btn--active":""}`,onClick:()=>{Ze(!1),x(a)},title:Bn[a],"aria-pressed":!ce&&p===a,children:[e.jsx("span",{className:"flat-terminal-wrapper__view-mode-icon","aria-hidden":"true",children:On[a]}),e.jsx("span",{className:"flat-terminal-wrapper__view-mode-label",children:zn[a]})]},a)),Ke&&e.jsxs("button",{type:"button",className:`flat-terminal-wrapper__view-mode-btn ${ce?"flat-terminal-wrapper__view-mode-btn--active":""}`,onClick:()=>Ze(a=>!a),title:"Classic TUI — attach to the live interactive claude session in a terminal","aria-pressed":ce,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:re,disabled:!R,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:oe,disabled:!Se,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 ${je?"flat-terminal-wrapper__action-btn--active":""}`,onClick:it,title:je?"Close search":"Search messages","aria-pressed":je,children:e.jsx(d,{name:je?"cross":"search",size:14})}),e.jsx("button",{type:"button",className:`flat-terminal-wrapper__action-btn flat-terminal-wrapper__action-btn--danger ${Le?"flat-terminal-wrapper__action-btn--confirm":""}`,onClick:()=>Te.handleClick(Vt,()=>{var a;g.clearContext(r),(a=Ee.current)==null||a.historyLoader.clearHistory()}),title:Le?"Click again to confirm clear context":"Clear context",children:e.jsx(d,{name:Le?"question":"clear",size:14})}),e.jsx("button",{type:"button",className:`flat-terminal-wrapper__action-btn ${_?"flat-terminal-wrapper__action-btn--active":""}`,onClick:wt,title:_?"Hide git panel":"Show git changes","aria-pressed":_,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:vt,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:he,children:[e.jsx("button",{type:"button",className:`flat-terminal-wrapper__action-btn ${Ve?"flat-terminal-wrapper__action-btn--active":""}`,onClick:()=>W(a=>!a),title:"More actions","aria-expanded":Ve,children:"⋮"}),Ve&&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 ${F?"flat-terminal-wrapper__more-item--active":""}`,onClick:()=>{rt(),W(!1)},title:F?"Hide Debug Panel":"Show Debug Panel",children:[e.jsx(d,{name:"bug",size:14}),e.jsx("span",{children:F?"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),W(!1)},disabled:f.status!=="idle",title:f.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"})]}),tt&&e.jsxs("button",{type:"button",role:"menuitem",className:"flat-terminal-wrapper__more-item flat-terminal-wrapper__more-item--danger",onClick:()=>{z(r,ye),W(!1)},children:[e.jsx(d,{name:"crown",size:14}),e.jsxs("span",{children:["Clear ",ye," subordinate",ye===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),W(!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 ${C?"flat-terminal-wrapper__inspector-toggle--active":""}`,onClick:T,title:C?"Hide inspector panel":"Show inspector panel","aria-label":C?"Hide inspector panel":"Show inspector panel","aria-pressed":C,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})})]})]}),ze&&e.jsxs("div",{className:"flat-chat-actions-sheet-root",role:"presentation",children:[e.jsx("div",{className:"flat-chat-actions-sheet__backdrop",onClick:D}),e.jsxs("div",{className:"flat-chat-actions-sheet",role:"menu","aria-label":"Chat actions",children:[e.jsx("div",{className:"flat-chat-actions-sheet__grabber","aria-hidden":"true"}),e.jsxs("div",{className:"flat-chat-actions-sheet__title-row",children:[e.jsx("span",{className:"flat-chat-actions-sheet__title",children:f.name}),e.jsx("button",{type:"button",className:"flat-chat-actions-sheet__done",onClick:D,children:"Done"})]}),e.jsxs("div",{className:"flat-chat-actions-sheet__grid",children:[e.jsxs("button",{type:"button",role:"menuitem",className:`flat-chat-actions-sheet__item ${je?"is-active":""}`,onClick:()=>{it(),D()},children:[e.jsx(d,{name:je?"cross":"search",size:20}),e.jsx("span",{children:je?"Close search":"Search"})]}),e.jsxs("button",{type:"button",role:"menuitem",className:`flat-chat-actions-sheet__item ${_?"is-active":""}`,onClick:()=>{wt(),D()},children:[e.jsx(d,{name:"git-branch",size:20}),e.jsx("span",{children:"Git changes"})]}),e.jsxs("button",{type:"button",role:"menuitem",className:`flat-chat-actions-sheet__item ${Re?"is-active":""}`,onClick:()=>{vt(),D()},children:[e.jsx(d,{name:"buildings",size:20}),e.jsx("span",{children:"Buildings"})]}),e.jsxs("button",{type:"button",role:"menuitem",className:`flat-chat-actions-sheet__item ${F?"is-active":""}`,onClick:()=>{rt(),D()},children:[e.jsx(d,{name:"bug",size:20}),e.jsx("span",{children:"Debug"})]})]}),e.jsxs("div",{className:"flat-chat-actions-sheet__list",children:[e.jsxs("button",{type:"button",role:"menuitem",className:`flat-chat-actions-sheet__row flat-chat-actions-sheet__row--danger ${Le?"is-armed":""}`,onClick:()=>Te.handleClick(Vt,()=>{var a;g.clearContext(r),(a=Ee.current)==null||a.historyLoader.clearHistory(),D()}),children:[e.jsx(d,{name:Le?"question":"clear",size:18}),e.jsx("span",{children:Le?"Tap again to confirm clear":"Clear context"})]}),e.jsxs("button",{type:"button",role:"menuitem",className:"flat-chat-actions-sheet__row",disabled:f.status!=="idle",onClick:()=>{g.collapseContext(r),D()},children:[e.jsx(d,{name:"package",size:18}),e.jsx("span",{children:"Collapse context"})]}),tt&&e.jsxs("button",{type:"button",role:"menuitem",className:"flat-chat-actions-sheet__row flat-chat-actions-sheet__row--danger",onClick:()=>{z(r,ye),D()},children:[e.jsx(d,{name:"crown",size:18}),e.jsxs("span",{children:["Clear ",ye," subordinate",ye===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),D()},children:[e.jsx(d,{name:"cross",size:18}),e.jsx("span",{children:"Remove agent"})]})]})]})]}),e.jsx(pn,{agent:f,onClick:S}),ce&&Ke?e.jsx(In,{agentId:r}):Me&&xt?e.jsx(fn,{ref:Ee,agentId:Me,agent:xt,viewMode:p,isOpen:!0,onImageClick:N,onFileClick:J,onBashClick:w,onViewMarkdown:U,keyboard:le,hasModalOpen:!1},Me):null,j&&ee&&(()=>{var X,te;const a=j.type,o={terminal:"terminal","pm2-logs":"scroll",database:"hard-drives",tests:"flask",http:"globe"},i=a==="terminal"&&!((X=ee.terminalStatus)!=null&&X.url),u=!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":`${ee.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:ee.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:Fe,onChange:L=>Pe(L.target.value),placeholder:"Filter logs","aria-label":`Filter logs for ${ee.name}`,spellCheck:!1}),e.jsx("select",{className:"guake-bottom-terminal-retention",value:We===null?"unlimited":String(We),onChange:L=>{const at=L.target.value==="unlimited"?null:Number(L.target.value);Pt(at),gn(at)},"aria-label":`Max log retention for ${ee.name}`,children:hn.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})})]}),u&&e.jsx("button",{type:"button",className:"flat-bottom-panel__close",onClick:()=>{Ce(),nt(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:Ce,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"?(te=ee.terminalStatus)!=null&&te.url?e.jsx(pa,{terminalUrl:ee.terminalStatus.url,visible:!0}):e.jsx("div",{className:"flat-bottom-panel__placeholder",children:"Starting terminal..."}):a==="pm2-logs"?e.jsx(xn,{buildingId:j.buildingId,filterText:Fe,maxRetention:We}):a==="database"?e.jsx(bn,{building:ee}):a==="tests"?e.jsx("div",{className:"tests-panel-host",children:e.jsx(_n,{building:ee,autoFocusSearch:!1})}):e.jsx("div",{className:"http-requests-panel-host",children:e.jsx(wn,{building:ee,autoFocusSearch:!1})})})]})]})})(),e.jsxs("div",{className:"flat-terminal-wrapper__statusbar",role:"contentinfo",children:[f.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"})]}),xe&&mt&&e.jsxs("span",{className:"flat-terminal-wrapper__cwd",title:`Open in file explorer: ${xe}`,"aria-label":`Open ${xe} in file explorer`,role:"button",tabIndex:0,onClick:()=>g.openFileExplorer(xe),onKeyDown:a=>{(a.key==="Enter"||a.key===" ")&&(a.preventDefault(),g.openFileExplorer(xe))},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:mt})]}),st&&st.map(({areaId:a,areaName:o,dir:i})=>{const u=bt.get(i),X=Ie.has(i),te=i.split("/").filter(Boolean).pop()||i;return e.jsxs("span",{className:"flat-terminal-wrapper__area-dir",title:`${o}: ${i}${u?` (${u.branch}${u.ahead?` ↑${u.ahead}`:""}${u.behind?` ↓${u.behind}`:""})`:""}`,onClick:()=>g.openFileExplorerForAreaFolder(a,i),children:[e.jsx(d,{name:"folder-open",size:12}),e.jsx("span",{className:"flat-terminal-wrapper__area-dir-name",children:te}),u&&e.jsxs(e.Fragment,{children:[e.jsxs("span",{className:"flat-terminal-wrapper__area-dir-branch",children:[e.jsx(d,{name:"git-branch",size:10})," ",u.branch]}),u.ahead>0&&e.jsxs("span",{className:"flat-terminal-wrapper__branch-ahead",title:`${u.ahead} ahead`,children:[e.jsx(d,{name:"arrow-up",size:9}),u.ahead]}),u.behind>0&&e.jsxs("span",{className:"flat-terminal-wrapper__branch-behind",title:`${u.behind} behind`,children:[e.jsx(d,{name:"arrow-down",size:9}),u.behind]}),e.jsx("span",{className:`flat-terminal-wrapper__area-fetch ${X?"flat-terminal-wrapper__area-fetch--fetching":""}`,title:"Git fetch",onClick:L=>{L.stopPropagation(),Oe(i)},children:e.jsx(d,{name:X?"hourglass":"download",size:12})})]})]},`${a}:${i}`)}),e.jsx(Rn,{agentId:r,disabled:((f==null?void 0:f.provider)??"claude")!=="claude"&&((f==null?void 0:f.provider)??"claude")!=="grok",contextSummary:ct?`Context: ${et}k / ${ut}k tokens (${jt}% 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:((f==null?void 0:f.provider)??"claude")!=="claude"&&((f==null?void 0:f.provider)??"claude")!=="grok"?ct?`Context usage: ${et}k / ${ut}k tokens (${jt}% 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:`${De}%`,backgroundColor:Qe}})}),e.jsxs("span",{className:"flat-terminal-wrapper__context-tokens",style:{color:Qe},children:[et,"k/",ut,"k"]}),e.jsxs("span",{className:"flat-terminal-wrapper__context-free",children:["(",ge,"% free)"]}),!ct&&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"}),me.length>0&&e.jsx("span",{className:"flat-terminal-wrapper__buildings",role:"group","aria-label":"Area terminals",children:me.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){Ce();return}if(a.hasUrl&&ft(a.id)==="modal"){nt(a.id);return}a.hasUrl||g.sendBuildingCommand(a.id,"start"),He("terminal",a.id)},onContextMenu:i=>{i.preventDefault(),i.stopPropagation(),we(a.id,{x:i.clientX,y:i.clientY})},children:e.jsx(d,{name:"terminal",size:14})},a.id)})}),ve.length>0&&e.jsx("span",{className:"flat-terminal-wrapper__buildings",role:"group","aria-label":"Area PM2 logs",children:ve.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?Ce():ft(a.id)==="modal"?nt(a.id):He("pm2-logs",a.id)},onContextMenu:i=>{i.preventDefault(),i.stopPropagation(),we(a.id,{x:i.clientX,y:i.clientY})},children:e.jsx(d,{name:"scroll",size:14})},a.id)})}),Q.length>0&&e.jsx("span",{className:"flat-terminal-wrapper__buildings",role:"group","aria-label":"Area databases",children:Q.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?Ce():ft(a.id)==="modal"?nt(a.id):He("database",a.id)},onContextMenu:i=>{i.preventDefault(),i.stopPropagation(),we(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?Ce():ft(a.id)==="modal"?nt(a.id):He("tests",a.id)},onContextMenu:i=>{i.preventDefault(),i.stopPropagation(),we(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?Ce():ft(a.id)==="modal"?nt(a.id):He("http",a.id)},onContextMenu:i=>{i.preventDefault(),i.stopPropagation(),we(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(vn,{})})]}),_&&e.jsx(jn,{agentId:r,agents:Ge,onClose:Ot,branchInfoMap:bt,fetchRemote:Oe,fetchingDirs:Ie,onResizeStart:a=>lt(a,"right")}),Re&&e.jsx(Cn,{agentId:r,onClose:ot}),F&&e.jsx(kn,{agentId:r,onClose:zt})]})}),Gn={groups:[],gridCols:1,gridRows:1,positions:new Map};function Kn({onAgentClick:c,onBuildingClick:r,onBuildingDoubleClick:p,onBuildingPopup:x,onAreaContextMenu:C,onOpenSpawnModal:T,onOpenBossSpawnModal:S,onOpenAreaModal:N}){const{t:J}=Yt(["common"]),w=Pa(),U=Ra(),[z,le]=s.useState(null),[R,Se]=s.useState(null),[re,oe]=s.useState(null);fa("flatview-image-modal",z!==null,()=>le(null));const[$e,gt]=s.useState(null),[_e,we]=s.useState(null),[f,O]=s.useState(null),[Ae,Ee]=s.useState(null),[Ye,Me]=s.useState(!1),Tt=s.useCallback(()=>{Me(t=>!t)},[]),xt=s.useCallback(()=>{Me(!1)},[]),[Ke,ce]=s.useState(()=>{const t=ea(A.VIEW_MODE);return t==="simple"||t==="chat"||t==="advanced"?t:"simple"}),Ze=s.useCallback(t=>{ce(t),ta(A.VIEW_MODE,t)},[]);s.useEffect(()=>{const t=n=>{if(n.key!==A.VIEW_MODE)return;const l=n.newValue;(l==="simple"||l==="chat"||l==="advanced")&&ce(l)};return window.addEventListener("storage",t),()=>window.removeEventListener("storage",t)},[]);const[ze,de]=s.useState(()=>qt(A.FLAT_INSPECTOR_OPEN,!1)),[D,ue]=s.useState(!1),st=s.useCallback(()=>ue(t=>!t),[]),bt=s.useCallback(()=>ue(!1),[]);s.useEffect(()=>{window.dispatchEvent(new CustomEvent("tide-flat-agents-drawer-state",{detail:{open:D}}))},[D]),s.useEffect(()=>{window.dispatchEvent(new CustomEvent("tide-flat-inspector-state",{detail:{open:ze}}))},[ze]),s.useEffect(()=>{const t=()=>ue(k=>!k),n=()=>{de(k=>{const E=!k;return be(A.FLAT_INSPECTOR_OPEN,E),E})},l=()=>{ue(!1),de(!1),be(A.FLAT_INSPECTOR_OPEN,!1)},h=()=>ue(!1),b=()=>{de(!1),be(A.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",h),window.addEventListener("tide-close-flat-inspector-only",b),()=>{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",h),window.removeEventListener("tide-close-flat-inspector-only",b)}},[]);const Oe=s.useRef(null),Ie=s.useRef(null),[me,ve]=s.useState(()=>{const t=aa(A.FLAT_MIDDLE_WIDTH,0);return t>=It?t:null}),[Q,Be]=s.useState(()=>{const t=aa(A.FLAT_INSPECTOR_WIDTH,0);return t>=Gt?t:null}),se=s.useCallback(t=>{if(typeof window>"u")return t;const n=Q!==null?Mt+Q:0,l=window.innerWidth-da-Mt-ca-n;return Math.max(It,Math.min(Math.max(l,It),t))},[Q]),ie=s.useCallback(t=>{var b;if(typeof window>"u")return t;const n=(b=Oe.current)==null?void 0:b.querySelector(".flat-middle"),l=(n==null?void 0:n.getBoundingClientRect().width)??It,h=window.innerWidth-da-l-Mt-ca-Mt;return Math.max(Gt,Math.min(Math.max(h,Gt),t))},[]);s.useEffect(()=>{if(me===null&&Q===null)return;const t=()=>{ve(n=>{if(n===null)return n;const l=se(n);return l===n?n:l}),Be(n=>{if(n===null)return n;const l=ie(n);return l===n?n:l})};return window.addEventListener("resize",t),()=>window.removeEventListener("resize",t)},[me,Q,se,ie]);const Lt=s.useCallback(t=>{var l;if(t.button!==0)return;const n=(l=Oe.current)==null?void 0:l.querySelector(".flat-middle");n&&(t.currentTarget.setPointerCapture(t.pointerId),Ie.current={kind:"middle",startX:t.clientX,startWidth:n.getBoundingClientRect().width,pointerId:t.pointerId},document.body.classList.add("flat-splitter-dragging"))},[]),je=s.useCallback(t=>{var l;if(t.button!==0)return;const n=(l=Oe.current)==null?void 0:l.querySelector(".flat-inspector");n&&(t.currentTarget.setPointerCapture(t.pointerId),Ie.current={kind:"inspector",startX:t.clientX,startWidth:n.getBoundingClientRect().width,pointerId:t.pointerId},document.body.classList.add("flat-splitter-dragging"))},[]),it=s.useCallback(t=>{const n=Ie.current;if(!n||t.pointerId!==n.pointerId)return;const l=t.clientX-n.startX;n.kind==="middle"?ve(se(n.startWidth+l)):Be(ie(n.startWidth-l))},[se,ie]),Te=s.useCallback(t=>{const n=Ie.current;if(!n||t.pointerId!==n.pointerId)return;try{t.currentTarget.releasePointerCapture(t.pointerId)}catch{}if(Ie.current=null,document.body.classList.remove("flat-splitter-dragging"),!(Math.abs(t.clientX-n.startX)>2))return;const h=t.clientX-n.startX;if(n.kind==="middle"){const b=se(n.startWidth+h);ve(b),Et(A.FLAT_MIDDLE_WIDTH,b)}else{const b=ie(n.startWidth-h);Be(b),Et(A.FLAT_INSPECTOR_WIDTH,b)}},[se,ie]),Le=s.useCallback(()=>{ve(null),Et(A.FLAT_MIDDLE_WIDTH,0)},[]),j=s.useCallback(()=>{Be(null),Et(A.FLAT_INSPECTOR_WIDTH,0)},[]),[ae,ee]=s.useState(()=>ea(A.FLAT_INSPECTOR_VIEW)==="tracking"?"tracking":"agent"),Fe=s.useCallback(t=>{ee(t),ta(A.FLAT_INSPECTOR_VIEW,t)},[]),Pe=s.useCallback(()=>{de(t=>{const n=!t;return be(A.FLAT_INSPECTOR_OPEN,n),n})},[]),We=s.useCallback(()=>{de(!1),be(A.FLAT_INSPECTOR_OPEN,!1)},[]),Pt=s.useCallback(()=>{Fe("tracking"),de(!0),be(A.FLAT_INSPECTOR_OPEN,!0)},[Fe]),B=Da(),He=s.useCallback((t,n)=>{le({url:t,name:n})},[]),Ce=s.useCallback((t,n)=>{Se({command:t,output:n,isLive:!1})},[]),Rt=s.useCallback((t,n)=>{var b;const l=U.size>0?Array.from(U)[0]:null,h=l?(b=g.getState().agents.get(l))==null?void 0:b.cwd:void 0;g.setFileViewerPath(t,n,h)},[U]),Dt=s.useCallback(t=>{oe(t)},[]),$t=s.useCallback((t,n)=>{gt({agentId:t,count:n})},[]),lt=s.useCallback(t=>{p?p(t):r(t)},[r,p]),_=s.useMemo(()=>U.size>0?Array.from(U)[0]:null,[U]),_t=s.useCallback(t=>{_&&we({agentId:_,position:t})},[_]),Re=s.useCallback((t,n)=>{O({buildingId:t,position:n})},[]);s.useEffect(()=>{Me(!1)},[_]);const pe=s.useRef([]),F=s.useRef(-1),Ue=s.useRef(!1),rt=s.useRef(null),[zt,wt]=s.useState(!1),[vt,Ot]=s.useState(!1),ot=s.useRef(!1),Ge=s.useRef(null),fe=s.useRef(!1),ke=s.useMemo(()=>new Set(w.map(t=>t.id)),[w]),Ve=s.useMemo(()=>{const t=new Map(w.map(l=>[l.id,l])),n=new Map;for(const l of w)if((l.isBoss||l.class==="boss")&&l.subordinateIds&&l.subordinateIds.length>0){const h=l.subordinateIds.map(b=>t.get(b)).filter(b=>b!==void 0);h.length>0&&n.set(l.id,h)}return n},[w]),W=s.useCallback(()=>{const t=pe.current,n=F.current;wt(n>0),Ot(n>=0&&n<t.length-1)},[]),he=s.useCallback(t=>{const n=pe.current;if(n.length===0)return;let l=F.current+t;for(;l>=0&&l<n.length;){const h=n[l];if(ke.has(h)){Ue.current=!0,F.current=l,W(),g.selectAgent(h);return}l+=t}},[ke,W]),Ne=s.useCallback(()=>he(-1),[he]),ct=s.useCallback(()=>he(1),[he]);An(s.useCallback(()=>{const t=pe.current,n=F.current;return t.length>0&&n>0?(he(-1),"handled"):"exit"},[he]));const Je=s.useCallback((t,n)=>{if(typeof window>"u")return;const l=window.history.state,b={...typeof l=="object"&&l!==null?l:{},__flatAgentNav:{agentId:t}};n==="replace"?window.history.replaceState(b,"",window.location.href):window.history.pushState(b,"",window.location.href)},[]);s.useEffect(()=>{if(!_){ot.current=!1,Ge.current=null;return}if(!ot.current){Je(_,"replace"),ot.current=!0,Ge.current=_;return}if(fe.current){fe.current=!1,Ge.current=_;return}Ge.current!==_&&(Je(_,"push"),Ge.current=_)},[_,Je]),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"||!ke.has(l)||l===_)return;fe.current=!0,Ue.current=!0;const h=pe.current,b=h.lastIndexOf(l);b>=0?F.current=b:(h.push(l),F.current=h.length-1),W(),g.selectAgent(l)};return window.addEventListener("popstate",t),()=>window.removeEventListener("popstate",t)},[ke,_,W]),s.useEffect(()=>{if(!_){pe.current=[],F.current=-1,W();return}if(rt.current=_,Ue.current){Ue.current=!1,W();return}const t=pe.current,n=F.current;if(n>=0&&t[n]===_){W();return}const l=n<t.length-1?t.slice(0,n+1):t.slice();l.push(_),l.length>100&&l.shift(),pe.current=l,F.current=l.length-1,W()},[_,W]);const dt=s.useCallback(t=>{c(t),ue(!1)},[c]),Bt=_??"",De=s.useCallback(()=>{},[]),jt=s.useCallback(t=>{dt(t)},[dt]),ge=ze,[Qe,et]=s.useState(ge),[ut,xe]=s.useState(ge);s.useEffect(()=>{if(ge){et(!0);return}xe(!1);const t=setTimeout(()=>et(!1),240);return()=>clearTimeout(t)},[ge]),s.useEffect(()=>{if(!Qe||!ge)return;let t=0;const n=requestAnimationFrame(()=>{t=requestAnimationFrame(()=>xe(!0))});return()=>{cancelAnimationFrame(n),cancelAnimationFrame(t)}},[Qe,ge]);const mt=s.useRef(null);s.useEffect(()=>{if(_)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 h=rt.current;!h||!ke.has(h)||(n.preventDefault(),g.selectAgent(h))};return document.addEventListener("keydown",t),()=>document.removeEventListener("keydown",t)},[_,ke]);const[ye,tt]=s.useState(new Set),Ct=s.useCallback(t=>{tt(n=>{const l=new Set(n);return l.has(t)?l.delete(t):l.add(t),l})},[]),kt=s.useCallback(t=>{tt(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,u]=s.useState(null),X=s.useCallback(t=>{u(n=>n===t?null:t)},[]),te=ha(),L=ga(),[at]=$a(),q=s.useMemo(()=>{if(_)return Gn;const t=new Map,n=[];for(const v of w){const I=g.getAreaForAgent(v.id);if(!na((I==null?void 0:I.id)??null))continue;if(!I||I.archived){n.push(v);continue}const P=t.get(I.id);P?P.push(v):t.set(I.id,[v])}const l=new Map,h=[];for(const v of L.values()){let I=!1;for(const P of te.values())if(!P.archived&&sa(P.id)&&g.isPositionInArea(v.position,P)){const Y=l.get(P.id);Y?Y.push(v):l.set(P.id,[v]),I=!0;break}!I&&na(null)&&h.push(v)}const b=[];for(const[,v]of te){if(v.archived||!sa(v.id))continue;const I=t.get(v.id),P=l.get(v.id)??[];(I&&I.length>0||P.length>0)&&b.push({area:v,agents:I??[],buildings:P})}(n.length>0||h.length>0)&&b.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:h});const k=b.filter(v=>v.area.id!=="__unassigned__"),E=b.filter(v=>v.area.id==="__unassigned__");let m=1,M=1;const V=new Map;if(k.length>1){let v=1/0,I=-1/0,P=1/0,Y=-1/0;for(const K of k)v=Math.min(v,K.area.center.x),I=Math.max(I,K.area.center.x),P=Math.min(P,K.area.center.z),Y=Math.max(Y,K.area.center.z);const yt=I-v||1,St=Y-P||1;if(k.length<=4){m=k.length,M=1;const K=[...k].sort((Z,Ft)=>Z.area.center.x-Ft.area.center.x);for(let Z=0;Z<K.length;Z++)V.set(K[Z].area.id,{row:1,col:Z+1})}else{const K=[...k].sort((y,H)=>y.area.center.x-H.area.center.x),Z=[];for(let y=1;y<K.length;y++)Z.push(K[y].area.center.x-K[y-1].area.center.x);const Ft=Z.reduce((y,H)=>y+H,0)/Z.length||1;let Kt=1;for(const y of Z)y>Ft*1.3&&Kt++;m=Math.max(2,Math.min(Kt,k.length));const Wt=[...k].sort((y,H)=>y.area.center.z-H.area.center.z),At=[];for(let y=1;y<Wt.length;y++)At.push(Wt[y].area.center.z-Wt[y-1].area.center.z);const Ca=At.reduce((y,H)=>y+H,0)/At.length||1;let Zt=1;for(const y of At)y>Ca*1.3&&Zt++;M=Math.max(2,Math.min(Zt,k.length)),m=Math.max(m,Math.ceil(k.length/M)),M=Math.max(M,Math.ceil(k.length/m));const ka=yt/m,Na=St/M,Ht=new Set;for(const y of k){let H=Math.min(m-1,Math.max(0,Math.floor((y.area.center.x-v)/ka))),qe=Math.min(M-1,Math.max(0,Math.floor((y.area.center.z-P)/Na))),pt=`${qe},${H}`,Jt=0;const ya=M*m;for(;Ht.has(pt)&&Jt<ya;)H++,H>=m&&(H=0,qe=(qe+1)%M),pt=`${qe},${H}`,Jt++;Ht.has(pt)&&(qe=M,H=0,pt=`${qe},${H}`,M++),Ht.add(pt),V.set(y.area.id,{row:qe+1,col:H+1})}}}const $=v=>{v.sort((I,P)=>{var yt,St,K,Z;const Y=(((yt=I.position)==null?void 0:yt.z)??0)-(((St=P.position)==null?void 0:St.z)??0);return Y!==0?Y:(((K=I.position)==null?void 0:K.x)??0)-(((Z=P.position)==null?void 0:Z.x)??0)})};for(const v of k)$(v.agents);for(const v of E)$(v.agents);return{groups:[...k,...E],gridCols:m,gridRows:M,positions:V}},[w,te,L,at,_]),Xe=s.useMemo(()=>{let t=0,n=0;for(const l of q.groups)t+=l.agents.length,n+=l.agents.filter(h=>h.status==="working").length;return{areaCount:q.groups.length,agentCount:t,workingCount:n}},[q]),ne=s.useMemo(()=>{if(!_e)return[];const t=w.find(n=>n.id===_e.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:()=>{Ee({agentId:t.id,name:t.name})}}]:[]},[_e,w,c]),G=s.useMemo(()=>{var k;if(!f)return[];const t=L.get(f.buildingId);if(!t)return[];const n=[],l=t.type==="server"||t.type==="docker"||t.type==="terminal",h=t.status==="running",b=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:()=>lt(t.id)}),l&&(h||n.push({id:"start",label:"Start",icon:e.jsx(d,{name:"play",size:14}),onClick:()=>g.sendBuildingCommand(t.id,"start")}),h&&(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")}))),b&&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},[f,L,lt]),Nt=s.useCallback(t=>{const n=new Set(q.groups.map(l=>l.area.id));n.delete(t),tt(n),requestAnimationFrame(()=>{const l=mt.current;if(!l)return;const h=l.querySelector(`[data-area-id="${t}"]`);if(!h)return;const b=l.getBoundingClientRect(),E=h.getBoundingClientRect().top-b.top+l.scrollTop-8;l.scrollTo({top:Math.max(0,E),behavior:"smooth"})})},[q]);return e.jsxs("div",{ref:Oe,className:`flat-view ${ge?"flat-view--with-inspector":""} ${_?"flat-view--has-chat":""} ${D?"flat-view--mobile-sidebar-open":""}`,style:(()=>{if(me===null&&Q===null)return;const t={};return me!==null&&(t["--flat-middle-width"]=`${me}px`),Q!==null&&(t["--flat-inspector-width"]=`${Q}px`),t})(),children:[D&&e.jsx("div",{className:"flat-mobile-sidebar-backdrop",onClick:bt,"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:T,title:"Create new agent",children:"+ Agent"}),e.jsx("button",{className:"flat-cta-btn flat-cta-btn--boss",onClick:S,title:"Create new boss agent",children:"+ Boss"}),e.jsx("button",{className:"flat-cta-btn flat-cta-btn--area",onClick:N,title:"Create new area",children:"+ Area"})]})}),e.jsx("div",{className:"flat-middle__content",children:e.jsx(za,{activeAgentId:Bt,onClose:De,onSelectAgent:jt,collapsedAreas:ye,onToggleArea:Ct,onCollapseAllAreas:kt,agentListRef:mt})})]}),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:Lt,onPointerMove:it,onPointerUp:Te,onPointerCancel:Te,onDoubleClick:Le}),e.jsxs("div",{className:"flat-right",children:[e.jsxs("button",{type:"button",className:"flat-mobile-sidebar-toggle","aria-label":D?"Close agents sidebar":"Open agents sidebar","aria-expanded":D,onClick:st,children:[e.jsx(d,{name:"list",size:18}),e.jsx("span",{className:"flat-mobile-sidebar-toggle__label",children:"Agents"})]}),_?e.jsx(Un,{agentId:_,terminalViewMode:Ke,onTerminalViewModeChange:Ze,inspectorOpen:ze,onToggleInspector:Pe,onShowTaskBoard:Pt,onImageClick:He,onFileClick:Rt,onBashClick:Ce,onViewMarkdown:Dt,onRequestClearSubordinates:$t,keyboard:B,canNavigateBack:zt,canNavigateForward:vt,onNavigateBack:Ne,onNavigateForward:ct,agentInfoOpen:Ye,onToggleAgentInfo:Tt,onHeaderContextMenu:_t,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:[Xe.areaCount," areas"]}),e.jsxs("span",{children:[Xe.agentCount," agents"]}),Xe.workingCount>0&&e.jsxs("span",{className:"flat-map__stats-working",children:[e.jsx("span",{className:"flat-map__stats-dot","aria-hidden":"true"}),Xe.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(${q.gridCols}, 1fr)`},children:q.groups.length===0?e.jsx("div",{className:"flat-map__empty",children:e.jsx("span",{children:"No areas or agents yet"})}):(a?[...q.groups].sort((n,l)=>{const h=q.positions.get(n.area.id),b=q.positions.get(l.area.id);return!h&&!b?0:h?b?h.row-b.row||h.col-b.col:-1:1}):q.groups).map(n=>{var E;const l=n.area.id,h=q.positions.get(l),b=a&&i!==l,k=a&&!b;return e.jsxs("div",{className:`flat-map-area-card${b?" flat-map-area-card--collapsed":""}${k?" flat-map-area-card--expanded":""}`,style:{"--area-color":n.area.color,gridRow:a||h==null?void 0:h.row,gridColumn:a||h==null?void 0:h.col},onContextMenu:m=>{C&&(m.preventDefault(),m.stopPropagation(),C(l,{x:m.clientX,y:m.clientY}))},children:[e.jsxs("button",{type:"button",className:"flat-map-area-card__header",onClick:()=>a?X(l):Nt(l),title:a?b?`Expand ${n.area.name}`:`Collapse ${n.area.name}`:`Focus ${n.area.name} in left panel`,"aria-expanded":a?!b:void 0,children:[e.jsx("span",{className:"flat-map-area-card__color",style:{background:n.area.color}}),((E=n.area.logo)==null?void 0:E.filename)&&e.jsx("img",{className:"flat-map-area-card__logo",src:Sn(n.area.logo.filename),alt:"","aria-hidden":"true",onError:m=>{m.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]}),a&&e.jsx(d,{name:b?"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(m=>{const M=m.isBoss||m.class==="boss",V=M?Ve.get(m.id):void 0,$=Oa(m),v=$.usedPercent>=80?"#ff4a4a":$.usedPercent>=60?"#ff9e4a":$.usedPercent>=40?"#ffd700":"#4aff9e",I=`Context: ${($.totalTokens/1e3).toFixed(1)}k / ${($.contextWindow/1e3).toFixed(1)}k (${$.usedPercent}% used, ${$.freePercent}% free)`,P=m.latestTodos&&m.latestTodos.length>0||V&&V.length>0;return e.jsx(Ba,{todos:m.latestTodos,subordinates:V,position:"top",children:e.jsxs("button",{type:"button",className:`flat-map-agent-chip ${m.status}`,onClick:()=>c(m.id),onContextMenu:Y=>{Y.preventDefault(),Y.stopPropagation(),we({agentId:m.id,position:{x:Y.clientX,y:Y.clientY}})},title:P?void 0:`${M?"Boss · ":""}Open chat with ${m.name}
|
|
1
|
+
import{r as s,H as Sa,J as Qt,K as ua,L as ma,j as e,M as pa,N as Aa,u as Yt,O as Ea,P as Ma,U as Ia,V as Ta,W as La,X as Pa,Y as Ra,Z as fa,_ as ea,S as A,$ as ta,a0 as qt,a1 as aa,a2 as Et,a3 as be,a4 as Da,s as g,a5 as ha,m as ga,a6 as $a,z as na,B as sa,I as d,a7 as za,q as Oa,a8 as Ba,a9 as xa,aa as ba,ab as _a,ac as wa,ad as Fa,ae as Wa,af as Ha,ag as Ua,ah as Ga,ai as Va,aj as Xa,ak as qa,al as Ya,am as Ka,an as Za,ao as Ja,ap as ia,C as Qa,aq as en,ar as la,as as tn,at as an,au as nn,av as sn,aw as ln,ax as rn,ay as on,az as cn,aA as dn,aB as un,aC as mn,aD as pn,aE as fn,aF as hn,aG as gn,aH as nt,aI as xn,aJ as bn,aK as _n,aL as wn,aM as ft,aN as vn,aO as jn,aP as Cn,aQ as kn,aR as Nn,aS as ra,aT as yn}from"./main-Cn0uJsZU.js";import{g as Sn}from"./area-logos-Baka5-sr.js";import"./vendor-react--Eh9ivFN.js";import"./vendor-three-Chj50gSY.js";function An(c){const r=s.useRef(c);r.current=c,s.useEffect(()=>{if(!Sa())return;let p=null,x=!1;return Qt.addListener("backButton",()=>{r.current()==="exit"&&Qt.exitApp()}).then(C=>{x?C.remove():p=C}),()=>{x=!0,p&&(p.remove(),p=null)}},[])}async function En(c){const r=ua(),p=await fetch(`${ma()}/api/agents/${c}/terminal`,{method:"POST",headers:{Authorization:`Bearer ${r}`}});if(!p.ok){const x=await p.json().catch(()=>({}));throw new Error((x==null?void 0:x.error)||`Failed to start terminal (${p.status})`)}return p.json()}async function Mn(c){const r=ua();await fetch(`${ma()}/api/agents/${c}/terminal`,{method:"DELETE",headers:{Authorization:`Bearer ${r}`}})}const ht=new Map;function In({agentId:c}){const[r,p]=s.useState(null),[x,C]=s.useState(null);return s.useEffect(()=>{let T=!1;const S=ht.get(c);return S&&(clearTimeout(S),ht.delete(c)),p(null),C(null),En(c).then(N=>{T||p(N.url)}).catch(N=>{T||C(N instanceof Error?N.message:"Failed to start terminal")}),()=>{T=!0;const N=ht.get(c);N&&clearTimeout(N),ht.set(c,setTimeout(()=>{ht.delete(c),Mn(c)},2500))}},[c]),x?e.jsx("div",{className:"flat-classic-terminal flat-classic-terminal--message",children:e.jsx("span",{children:x})}):r?e.jsx("div",{className:"flat-classic-terminal",children:e.jsx(pa,{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 Ut=new Map,Tn=6e4;function oa(c){return Number.isFinite(c)?Math.abs(c)>=1e3?c.toLocaleString(void 0,{maximumFractionDigits:0}):c.toLocaleString(void 0,{maximumFractionDigits:2}):String(c)}function Ln(c,r){var C,T,S;const p=[];if(!c.rateLimits)return p;if(c.provider==="claude"){const N=c,J=[{key:"fiveHour",label:r("terminal:usage.currentSession"),window:N.rateLimits.fiveHour},{key:"sevenDay",label:r("terminal:usage.currentWeekAll"),window:N.rateLimits.sevenDay},{key:"sevenDayOpus",label:r("terminal:usage.currentWeekOpus"),window:N.rateLimits.sevenDayOpus},{key:"sevenDaySonnet",label:r("terminal:usage.currentWeekSonnet"),window:N.rateLimits.sevenDaySonnet}];for(const w of J)w.window&&p.push({...w,window:w.window});return p}const x=c;return(C=x.rateLimits)!=null&&C.weekly&&p.push({key:"weekly",label:r("terminal:usage.weeklyLimit"),window:x.rateLimits.weekly}),(T=x.rateLimits)!=null&&T.monthly&&p.push({key:"monthly",label:r("terminal:usage.monthlyLimit"),window:x.rateLimits.monthly}),(S=x.rateLimits)!=null&&S.onDemand&&p.push({key:"onDemand",label:r("terminal:usage.onDemandLimit"),window:x.rateLimits.onDemand}),p}function Pn({agentId:c,contextSummary:r}){const{t:p}=Yt(["terminal","common"]),[x,C]=s.useState(()=>{var z;return((z=Ut.get(c))==null?void 0:z.snapshot)??null}),[T,S]=s.useState(!1),[N,J]=s.useState(null),w=s.useRef(0);s.useEffect(()=>{const z=Ut.get(c);if(z&&Date.now()-z.fetchedAt<Tn){C(z.snapshot);return}const le=++w.current;S(!0),J(null),Ea(c).then(R=>{le===w.current&&(Ut.set(c,{snapshot:R,fetchedAt:Date.now()}),C(R),S(!1))}).catch(R=>{le===w.current&&(J(R.message||"Failed to load plan limits"),S(!1))})},[c]);const U=x?Ln(x,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")}),T&&!x&&e.jsxs("div",{className:"plan-limits-tooltip__muted",children:[p("common:status.loading"),"…"]}),!T&&N&&!x&&e.jsx("div",{className:"plan-limits-tooltip__muted",children:p("terminal:usage.limitsError",{message:N})}),U.length>0?e.jsx("div",{className:"plan-limits-tooltip__gauges",children:U.map(({key:z,label:le,window:R})=>{const Se=Math.max(0,Math.min(100,R.utilization)),re=Ia(Se),oe=typeof R.used=="number"&&typeof R.limit=="number"&&Number.isFinite(R.used)&&Number.isFinite(R.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:le}),e.jsx("span",{className:"plan-limits-tooltip__gauge-percent",style:{color:re},children:p("terminal:usage.percentUsed",{percent:Math.round(Se)})})]}),e.jsx("div",{className:"plan-limits-tooltip__bar",children:e.jsx("div",{className:"plan-limits-tooltip__bar-fill",style:{width:`${Se}%`,background:re}})}),e.jsxs("div",{className:"plan-limits-tooltip__reset",children:[p("terminal:usage.resets",{time:Ma(R.resetsAt)}),oe&&e.jsx("span",{style:{marginLeft:8},children:p("terminal:usage.creditsUsed",{used:oa(R.used),limit:oa(R.limit)})})]})]},z)})}):x&&!T&&e.jsx("div",{className:"plan-limits-tooltip__muted",children:x.rateLimitsError?p("terminal:usage.limitsError",{message:x.rateLimitsError}):x.cliHint})]})}function Rn({agentId:c,disabled:r,contextSummary:p,children:x}){return e.jsx(Aa,{position:"top",maxWidth:320,disabled:r,className:"plan-limits-tooltip-wrapper",triggerStyle:{display:"inline-flex",alignItems:"center"},content:e.jsx(Pn,{agentId:c,contextSummary:p}),children:x})}const Dn=s.memo(function({className:r=""}){const{t:p}=Yt(["common"]),[x,C]=Ta(),T=s.useRef(null),[S,N]=s.useState(null);s.useLayoutEffect(()=>{const w=T.current;if(!w)return;const U=w.querySelector(".view-mode-toggle__btn--active");U&&N({left:U.offsetLeft,width:U.offsetWidth})},[x]);const J=s.useCallback(w=>{if(w!==x){if(typeof window<"u"&&window.dispatchEvent(new CustomEvent("tide:viewmode-switch-pressed",{detail:{mode:w}})),w==="3d"){requestAnimationFrame(()=>C(w));return}C(w)}},[x,C]);return e.jsxs("div",{className:`view-mode-toggle ${r}`,ref:T,children:[S&&e.jsx("div",{className:"view-mode-toggle__indicator",style:{left:S.left,width:S.width}}),La.map(w=>e.jsxs("button",{className:`view-mode-toggle__btn ${x===w?"view-mode-toggle__btn--active":""}`,onClick:()=>J(w),title:p(`common:viewMode.descriptions.${w}`),children:[e.jsxs("span",{className:"view-mode-toggle__icon",children:[w==="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"})]}),w==="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"})]}),w==="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"})]}),w==="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.${w}`)})]},w))]})}),Mt=3,It=280,ca=320,Gt=240,da=64,$n=["simple","chat","advanced"],zn={simple:"Simple",chat:"Chat",advanced:"Advanced"},On={simple:"○",chat:"◐",advanced:"◉"},Bn={simple:"Simple view — clean messages only",chat:"Chat view — assistant replies (no tool calls)",advanced:"Advanced view — everything including tools"},Vt="flat-clear-context",va="tide:flat-embedded-panels";function ja(){try{const c=localStorage.getItem(va),r=c?JSON.parse(c):{};return r&&typeof r=="object"?r:{}}catch{return{}}}function Xt(c,r){try{const p=ja();r?p[c]=r:delete p[c],localStorage.setItem(va,JSON.stringify(p))}catch{}}function Fn(c){const r=c.split("/").filter(Boolean);return r.length===0?c:r.slice(-2).join("/")}function Wn(c){if(c.provider==="codex"){const T=c.codexModel||"gpt-5.6-luna",S=Nn[T];return{model:(S==null?void 0:S.label)||T}}if(c.provider==="opencode")return{model:c.opencodeModel||"opencode"};if(c.provider==="grok"){const T=c.grokModel||"grok-4.5",S=c.effort,N=S?ra[S]:void 0;return{model:T,effort:N==null?void 0:N.label}}const r=c.model||"sonnet",p=yn[r],x=c.effort,C=x?ra[x]:void 0;return{model:(p==null?void 0:p.label)||r,effort:C==null?void 0:C.label}}function Hn(c,r){if(r.type==="rectangle"&&r.width&&r.height){const p=r.width/2,x=r.height/2;return c.x>=r.center.x-p&&c.x<=r.center.x+p&&c.z>=r.center.z-x&&c.z<=r.center.z+x}if(r.type==="circle"&&r.radius){const p=c.x-r.center.x,x=c.z-r.center.z;return p*p+x*x<=r.radius*r.radius}return!1}const Un=en.memo(function({agentId:r,terminalViewMode:p,onTerminalViewModeChange:x,inspectorOpen:C,onToggleInspector:T,onShowTaskBoard:S,onImageClick:N,onFileClick:J,onBashClick:w,onViewMarkdown:U,onRequestClearSubordinates:z,keyboard:le,canNavigateBack:R,canNavigateForward:Se,onNavigateBack:re,onNavigateForward:oe,agentInfoOpen:$e,onToggleAgentInfo:gt,onHeaderContextMenu:_e,onBuildingContextMenu:we}){var Ct,kt;const f=la(r),O=ga(),Ae=tn(),Ee=s.useRef(null),Ye=s.useRef(null),{displayedAgentId:Me,fadingOut:Tt}=an(r),xt=la(Me),Ke=!!Ae.interactiveMode&&((f==null?void 0:f.provider)??"claude")==="claude"&&!!(f!=null&&f.sessionId),[ce,Ze]=s.useState(!1),[ze,de]=s.useState(!1),D=s.useCallback(()=>de(!1),[]);fa("flat-chat-actions",ze,D),s.useEffect(()=>{const a=()=>de(o=>!o);return window.addEventListener("tide:toggle-chat-actions",a),()=>window.removeEventListener("tide:toggle-chat-actions",a)},[]),s.useEffect(()=>{Ze(!1),de(!1)},[r]),s.useEffect(()=>{!Ke&&ce&&Ze(!1)},[Ke,ce]),s.useEffect(()=>{const a=Ye.current;if(!a)return;const o=u=>{u.button===3?(u.preventDefault(),u.stopPropagation(),re()):u.button===4&&(u.preventDefault(),u.stopPropagation(),oe())},i=u=>{(u.button===3||u.button===4)&&u.preventDefault()};return a.addEventListener("mouseup",o),a.addEventListener("mousedown",i),()=>{a.removeEventListener("mouseup",o),a.removeEventListener("mousedown",i)}},[re,oe]),s.useEffect(()=>{const a=Ye.current;if(!a)return;let o=0,i=0,u=0;const X=250,te=600,L=80,at=1.5,q=ne=>{let G=ne instanceof HTMLElement?ne:null;for(;G&&G!==a;){const Nt=window.getComputedStyle(G).overflowX;if((Nt==="auto"||Nt==="scroll")&&G.scrollWidth>G.clientWidth)return!0;G=G.parentElement}return!1},Xe=ne=>{const G=Date.now();if(G<u){ne.preventDefault();return}if(Math.abs(ne.deltaX)<=Math.abs(ne.deltaY)*at){o=0;return}if(q(ne.target)){o=0;return}G-i>X&&(o=0),i=G,o+=ne.deltaX,o<=-L?(o=0,u=G+te,ne.preventDefault(),re()):o>=L&&(o=0,u=G+te,ne.preventDefault(),oe())};return a.addEventListener("wheel",Xe,{passive:!1}),()=>a.removeEventListener("wheel",Xe)},[re,oe]);const ue=ha(),st=s.useMemo(()=>{if(!f)return null;const a=new Set,o=[];for(const i of ue.values())i.archived||i.directories.length===0||i.assignedAgentIds.includes(r)&&(a.add(i.id),o.push(i));for(const i of ue.values())i.archived||i.directories.length===0||a.has(i.id)||Hn({x:f.position.x,z:f.position.z},i)&&(a.add(i.id),o.push(i));return o.length===0?null:o.flatMap(i=>i.directories.filter(u=>u&&u.trim().length>0).map(u=>({areaId:i.id,areaName:i.name,dir:u})))},[f,r,ue]),{branches:bt,fetchRemote:Oe,fetchingDirs:Ie}=nn(st),me=s.useMemo(()=>{var i;const a=g.getAreaForAgent(r);if(!a)return[];const o=[];for(const u of O.values())u.type==="terminal"&&g.isPositionInArea(u.position,a)&&o.push({id:u.id,name:u.name,hasUrl:!!((i=u.terminalStatus)!=null&&i.url)});return o},[r,O]),ve=s.useMemo(()=>{var i;const a=g.getAreaForAgent(r);if(!a)return[];const o=[];for(const u of O.values())u.type==="server"&&((i=u.pm2)!=null&&i.enabled)&&g.isPositionInArea(u.position,a)&&o.push({id:u.id,name:u.name});return o},[r,O]),Q=s.useMemo(()=>{const a=g.getAreaForAgent(r);if(!a)return[];const o=[];for(const i of O.values())i.type==="database"&&i.database&&g.isPositionInArea(i.position,a)&&o.push({id:i.id,name:i.name});return o},[r,O]),Be=sn(),se=s.useMemo(()=>{const a=g.getAreaForAgent(r);if(!a)return[];const o=[];for(const i of O.values())if(i.type==="tests"&&g.isPositionInArea(i.position,a)){const u=!!i.folderPath&&Be.some(X=>ln(X,i.folderPath));o.push({id:i.id,name:i.name,working:u})}return o},[r,O,Be]),ie=s.useMemo(()=>{const a=g.getAreaForAgent(r);if(!a)return[];const o=[];for(const i of O.values())i.type==="http"&&g.isPositionInArea(i.position,a)&&o.push({id:i.id,name:i.name});return o},[r,O]),[,Lt]=s.useReducer(a=>a+1,0),je=((Ct=Ee.current)==null?void 0:Ct.search.searchMode)??!1,it=s.useCallback(()=>{var a;(a=Ee.current)==null||a.search.toggleSearch(),Lt()},[]),Te=rn(),Le=Te.isPending(Vt),[j,ae]=s.useState(null),ee=j?O.get(j.buildingId):null,[Fe,Pe]=s.useState(""),[We,Pt]=s.useState(()=>on()),B=s.useMemo(()=>{var a;return((a=g.getAreaForAgent(r))==null?void 0:a.id)??null},[r,O]),He=s.useCallback((a,o)=>{Pe(""),ae(i=>{const u=(i==null?void 0:i.buildingId)===o?null:{type:a,buildingId:o};return B&&Xt(B,u),u})},[B]),Ce=s.useCallback(()=>{Pe(""),ae(null),B&&Xt(B,null)},[B]);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}=cn(),{sidePanelWidth:$t,handleSidePanelResizeStart:lt}=dn(),[_,_t]=s.useState(()=>qt(A.GIT_PANEL_OPEN,!1)),[Re,pe]=s.useState(()=>qt(A.BUILDINGS_PANEL_OPEN,!1)),[F,Ue]=s.useState(!1),rt=s.useCallback(()=>{Ue(a=>{const o=!a;return o&&un.setEnabled(!0),o})},[]),zt=s.useCallback(()=>Ue(!1),[]),wt=s.useCallback(()=>{_t(a=>{const o=!a;return be(A.GIT_PANEL_OPEN,o),o})},[]),vt=s.useCallback(()=>{pe(a=>{const o=!a;return be(A.BUILDINGS_PANEL_OPEN,o),o})},[]),Ot=s.useCallback(()=>{_t(!1),be(A.GIT_PANEL_OPEN,!1)},[]),ot=s.useCallback(()=>{pe(!1),be(A.BUILDINGS_PANEL_OPEN,!1)},[]),Ge=mn(),fe=s.useMemo(()=>({terminal:me,"pm2-logs":ve,database:Q,tests:se,http:ie}),[me,ve,Q,se,ie]);s.useEffect(()=>{if(!j)return;fe[j.type].some(o=>o.id===j.buildingId)||(Pe(""),ae(null))},[j,fe]);const ke=s.useRef(void 0);s.useEffect(()=>{var o;if(ke.current===B)return;ke.current=B;const a=B?ja()[B]:void 0;Pe(""),a&&((o=fe[a.type])!=null&&o.some(i=>i.id===a.buildingId))?ae(a):ae(null)},[B,fe]),s.useEffect(()=>{const a=o=>{var X;const i=o.detail;if(!(i!=null&&i.buildingId)||!(i!=null&&i.type)||!((X=fe[i.type])!=null&&X.some(te=>te.id===i.buildingId)))return;i.handled=!0,Pe("");const u={type:i.type,buildingId:i.buildingId};ae(u),B&&Xt(B,u)};return window.addEventListener("tide:dock-building-flat",a),()=>window.removeEventListener("tide:dock-building-flat",a)},[fe,B]);const[Ve,W]=s.useState(!1),he=s.useRef(null);if(s.useEffect(()=>{if(!Ve)return;const a=o=>{he.current&&!he.current.contains(o.target)&&W(!1)};return document.addEventListener("mousedown",a),()=>document.removeEventListener("mousedown",a)},[Ve]),!f)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 Ne=f.contextStats,ct=!!Ne,Je=Ne?Ne.totalTokens:f.contextUsed||0,dt=Ne?Ne.contextWindow:f.contextLimit||(f.provider==="grok"?5e5:2e5),Bt=Ne?Ne.usedPercent:Math.round(Je/dt*100),De=Math.max(0,Math.min(100,Bt)),jt=Math.round(De*10)/10,ge=Math.round((100-De)*10)/10,Qe=De>=80?"#ff4a4a":De>=60?"#ff9e4a":De>=40?"#ffd700":"#4aff9e",et=(Je/1e3).toFixed(1),ut=(dt/1e3).toFixed(1),xe=f.cwd,mt=xe?Fn(xe):null,ye=((kt=f.subordinateIds)==null?void 0:kt.length)||0,tt=ye>0;return e.jsxs("div",{ref:Ye,className:`flat-terminal-wrapper ${_||Re||F?"flat-terminal-wrapper--with-side-panel":""} ${Tt?"pane-fading-out":""}`,style:{"--guake-side-panel-width":`min(${$t}px, 70%)`},children:[e.jsxs("div",{className:"flat-terminal-wrapper__header",children:[e.jsxs("button",{type:"button",className:`flat-terminal-wrapper__header-main ${$e?"flat-terminal-wrapper__header-main--active":""}`,onClick:gt,onContextMenu:a=>{a.preventDefault(),a.stopPropagation(),_e({x:a.clientX,y:a.clientY})},title:$e?"Hide agent info":"Show agent info","aria-pressed":$e,children:[e.jsx("span",{className:`flat-terminal-wrapper__header-avatar${f.status==="working"?" is-working":""}`,children:e.jsx(xa,{agent:f,size:28})}),e.jsxs("span",{className:"flat-terminal-wrapper__header-info",children:[e.jsx("span",{className:"flat-terminal-wrapper__header-name",children:f.name}),e.jsx("span",{className:"flat-terminal-wrapper__header-status",style:{color:wa(f.status)},children:f.status})]}),f.taskLabel&&e.jsxs("span",{className:"flat-terminal-wrapper__header-task",title:f.taskLabel,children:["📋 ",f.taskLabel]}),e.jsxs("span",{className:"flat-terminal-wrapper__header-model",children:[e.jsx("img",{src:_a(f.provider,"/"),alt:f.provider,className:"flat-terminal-wrapper__header-provider-icon",title:ba(f.provider)}),(()=>{const{model:a,effort:o}=Wn(f);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:[$n.map(a=>e.jsxs("button",{type:"button",className:`flat-terminal-wrapper__view-mode-btn ${!ce&&p===a?"flat-terminal-wrapper__view-mode-btn--active":""}`,onClick:()=>{Ze(!1),x(a)},title:Bn[a],"aria-pressed":!ce&&p===a,children:[e.jsx("span",{className:"flat-terminal-wrapper__view-mode-icon","aria-hidden":"true",children:On[a]}),e.jsx("span",{className:"flat-terminal-wrapper__view-mode-label",children:zn[a]})]},a)),Ke&&e.jsxs("button",{type:"button",className:`flat-terminal-wrapper__view-mode-btn ${ce?"flat-terminal-wrapper__view-mode-btn--active":""}`,onClick:()=>Ze(a=>!a),title:"Classic TUI — attach to the live interactive claude session in a terminal","aria-pressed":ce,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:re,disabled:!R,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:oe,disabled:!Se,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 ${je?"flat-terminal-wrapper__action-btn--active":""}`,onClick:it,title:je?"Close search":"Search messages","aria-pressed":je,children:e.jsx(d,{name:je?"cross":"search",size:14})}),e.jsx("button",{type:"button",className:`flat-terminal-wrapper__action-btn flat-terminal-wrapper__action-btn--danger ${Le?"flat-terminal-wrapper__action-btn--confirm":""}`,onClick:()=>Te.handleClick(Vt,()=>{var a;g.clearContext(r),(a=Ee.current)==null||a.historyLoader.clearHistory()}),title:Le?"Click again to confirm clear context":"Clear context",children:e.jsx(d,{name:Le?"question":"clear",size:14})}),e.jsx("button",{type:"button",className:`flat-terminal-wrapper__action-btn ${_?"flat-terminal-wrapper__action-btn--active":""}`,onClick:wt,title:_?"Hide git panel":"Show git changes","aria-pressed":_,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:vt,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:he,children:[e.jsx("button",{type:"button",className:`flat-terminal-wrapper__action-btn ${Ve?"flat-terminal-wrapper__action-btn--active":""}`,onClick:()=>W(a=>!a),title:"More actions","aria-expanded":Ve,children:"⋮"}),Ve&&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 ${F?"flat-terminal-wrapper__more-item--active":""}`,onClick:()=>{rt(),W(!1)},title:F?"Hide Debug Panel":"Show Debug Panel",children:[e.jsx(d,{name:"bug",size:14}),e.jsx("span",{children:F?"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),W(!1)},disabled:f.status!=="idle",title:f.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"})]}),tt&&e.jsxs("button",{type:"button",role:"menuitem",className:"flat-terminal-wrapper__more-item flat-terminal-wrapper__more-item--danger",onClick:()=>{z(r,ye),W(!1)},children:[e.jsx(d,{name:"crown",size:14}),e.jsxs("span",{children:["Clear ",ye," subordinate",ye===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),W(!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 ${C?"flat-terminal-wrapper__inspector-toggle--active":""}`,onClick:T,title:C?"Hide inspector panel":"Show inspector panel","aria-label":C?"Hide inspector panel":"Show inspector panel","aria-pressed":C,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})})]})]}),ze&&e.jsxs("div",{className:"flat-chat-actions-sheet-root",role:"presentation",children:[e.jsx("div",{className:"flat-chat-actions-sheet__backdrop",onClick:D}),e.jsxs("div",{className:"flat-chat-actions-sheet",role:"menu","aria-label":"Chat actions",children:[e.jsx("div",{className:"flat-chat-actions-sheet__grabber","aria-hidden":"true"}),e.jsxs("div",{className:"flat-chat-actions-sheet__title-row",children:[e.jsx("span",{className:"flat-chat-actions-sheet__title",children:f.name}),e.jsx("button",{type:"button",className:"flat-chat-actions-sheet__done",onClick:D,children:"Done"})]}),e.jsxs("div",{className:"flat-chat-actions-sheet__grid",children:[e.jsxs("button",{type:"button",role:"menuitem",className:`flat-chat-actions-sheet__item ${je?"is-active":""}`,onClick:()=>{it(),D()},children:[e.jsx(d,{name:je?"cross":"search",size:20}),e.jsx("span",{children:je?"Close search":"Search"})]}),e.jsxs("button",{type:"button",role:"menuitem",className:`flat-chat-actions-sheet__item ${_?"is-active":""}`,onClick:()=>{wt(),D()},children:[e.jsx(d,{name:"git-branch",size:20}),e.jsx("span",{children:"Git changes"})]}),e.jsxs("button",{type:"button",role:"menuitem",className:`flat-chat-actions-sheet__item ${Re?"is-active":""}`,onClick:()=>{vt(),D()},children:[e.jsx(d,{name:"buildings",size:20}),e.jsx("span",{children:"Buildings"})]}),e.jsxs("button",{type:"button",role:"menuitem",className:`flat-chat-actions-sheet__item ${F?"is-active":""}`,onClick:()=>{rt(),D()},children:[e.jsx(d,{name:"bug",size:20}),e.jsx("span",{children:"Debug"})]})]}),e.jsxs("div",{className:"flat-chat-actions-sheet__list",children:[e.jsxs("button",{type:"button",role:"menuitem",className:`flat-chat-actions-sheet__row flat-chat-actions-sheet__row--danger ${Le?"is-armed":""}`,onClick:()=>Te.handleClick(Vt,()=>{var a;g.clearContext(r),(a=Ee.current)==null||a.historyLoader.clearHistory(),D()}),children:[e.jsx(d,{name:Le?"question":"clear",size:18}),e.jsx("span",{children:Le?"Tap again to confirm clear":"Clear context"})]}),e.jsxs("button",{type:"button",role:"menuitem",className:"flat-chat-actions-sheet__row",disabled:f.status!=="idle",onClick:()=>{g.collapseContext(r),D()},children:[e.jsx(d,{name:"package",size:18}),e.jsx("span",{children:"Collapse context"})]}),tt&&e.jsxs("button",{type:"button",role:"menuitem",className:"flat-chat-actions-sheet__row flat-chat-actions-sheet__row--danger",onClick:()=>{z(r,ye),D()},children:[e.jsx(d,{name:"crown",size:18}),e.jsxs("span",{children:["Clear ",ye," subordinate",ye===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),D()},children:[e.jsx(d,{name:"cross",size:18}),e.jsx("span",{children:"Remove agent"})]})]})]})]}),e.jsx(pn,{agent:f,onClick:S}),ce&&Ke?e.jsx(In,{agentId:r}):Me&&xt?e.jsx(fn,{ref:Ee,agentId:Me,agent:xt,viewMode:p,isOpen:!0,onImageClick:N,onFileClick:J,onBashClick:w,onViewMarkdown:U,keyboard:le,hasModalOpen:!1},Me):null,j&&ee&&(()=>{var X,te;const a=j.type,o={terminal:"terminal","pm2-logs":"scroll",database:"hard-drives",tests:"flask",http:"globe"},i=a==="terminal"&&!((X=ee.terminalStatus)!=null&&X.url),u=!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":`${ee.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:ee.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:Fe,onChange:L=>Pe(L.target.value),placeholder:"Filter logs","aria-label":`Filter logs for ${ee.name}`,spellCheck:!1}),e.jsx("select",{className:"guake-bottom-terminal-retention",value:We===null?"unlimited":String(We),onChange:L=>{const at=L.target.value==="unlimited"?null:Number(L.target.value);Pt(at),gn(at)},"aria-label":`Max log retention for ${ee.name}`,children:hn.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})})]}),u&&e.jsx("button",{type:"button",className:"flat-bottom-panel__close",onClick:()=>{Ce(),nt(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:Ce,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"?(te=ee.terminalStatus)!=null&&te.url?e.jsx(pa,{terminalUrl:ee.terminalStatus.url,visible:!0}):e.jsx("div",{className:"flat-bottom-panel__placeholder",children:"Starting terminal..."}):a==="pm2-logs"?e.jsx(xn,{buildingId:j.buildingId,filterText:Fe,maxRetention:We}):a==="database"?e.jsx(bn,{building:ee}):a==="tests"?e.jsx("div",{className:"tests-panel-host",children:e.jsx(_n,{building:ee,autoFocusSearch:!1})}):e.jsx("div",{className:"http-requests-panel-host",children:e.jsx(wn,{building:ee,autoFocusSearch:!1})})})]})]})})(),e.jsxs("div",{className:"flat-terminal-wrapper__statusbar",role:"contentinfo",children:[f.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"})]}),xe&&mt&&e.jsxs("span",{className:"flat-terminal-wrapper__cwd",title:`Open in file explorer: ${xe}`,"aria-label":`Open ${xe} in file explorer`,role:"button",tabIndex:0,onClick:()=>g.openFileExplorer(xe),onKeyDown:a=>{(a.key==="Enter"||a.key===" ")&&(a.preventDefault(),g.openFileExplorer(xe))},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:mt})]}),st&&st.map(({areaId:a,areaName:o,dir:i})=>{const u=bt.get(i),X=Ie.has(i),te=i.split("/").filter(Boolean).pop()||i;return e.jsxs("span",{className:"flat-terminal-wrapper__area-dir",title:`${o}: ${i}${u?` (${u.branch}${u.ahead?` ↑${u.ahead}`:""}${u.behind?` ↓${u.behind}`:""})`:""}`,onClick:()=>g.openFileExplorerForAreaFolder(a,i),children:[e.jsx(d,{name:"folder-open",size:12}),e.jsx("span",{className:"flat-terminal-wrapper__area-dir-name",children:te}),u&&e.jsxs(e.Fragment,{children:[e.jsxs("span",{className:"flat-terminal-wrapper__area-dir-branch",children:[e.jsx(d,{name:"git-branch",size:10})," ",u.branch]}),u.ahead>0&&e.jsxs("span",{className:"flat-terminal-wrapper__branch-ahead",title:`${u.ahead} ahead`,children:[e.jsx(d,{name:"arrow-up",size:9}),u.ahead]}),u.behind>0&&e.jsxs("span",{className:"flat-terminal-wrapper__branch-behind",title:`${u.behind} behind`,children:[e.jsx(d,{name:"arrow-down",size:9}),u.behind]}),e.jsx("span",{className:`flat-terminal-wrapper__area-fetch ${X?"flat-terminal-wrapper__area-fetch--fetching":""}`,title:"Git fetch",onClick:L=>{L.stopPropagation(),Oe(i)},children:e.jsx(d,{name:X?"hourglass":"download",size:12})})]})]},`${a}:${i}`)}),e.jsx(Rn,{agentId:r,disabled:((f==null?void 0:f.provider)??"claude")!=="claude"&&((f==null?void 0:f.provider)??"claude")!=="grok",contextSummary:ct?`Context: ${et}k / ${ut}k tokens (${jt}% 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:((f==null?void 0:f.provider)??"claude")!=="claude"&&((f==null?void 0:f.provider)??"claude")!=="grok"?ct?`Context usage: ${et}k / ${ut}k tokens (${jt}% 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:`${De}%`,backgroundColor:Qe}})}),e.jsxs("span",{className:"flat-terminal-wrapper__context-tokens",style:{color:Qe},children:[et,"k/",ut,"k"]}),e.jsxs("span",{className:"flat-terminal-wrapper__context-free",children:["(",ge,"% free)"]}),!ct&&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"}),me.length>0&&e.jsx("span",{className:"flat-terminal-wrapper__buildings",role:"group","aria-label":"Area terminals",children:me.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){Ce();return}if(a.hasUrl&&ft(a.id)==="modal"){nt(a.id);return}a.hasUrl||g.sendBuildingCommand(a.id,"start"),He("terminal",a.id)},onContextMenu:i=>{i.preventDefault(),i.stopPropagation(),we(a.id,{x:i.clientX,y:i.clientY})},children:e.jsx(d,{name:"terminal",size:14})},a.id)})}),ve.length>0&&e.jsx("span",{className:"flat-terminal-wrapper__buildings",role:"group","aria-label":"Area PM2 logs",children:ve.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?Ce():ft(a.id)==="modal"?nt(a.id):He("pm2-logs",a.id)},onContextMenu:i=>{i.preventDefault(),i.stopPropagation(),we(a.id,{x:i.clientX,y:i.clientY})},children:e.jsx(d,{name:"scroll",size:14})},a.id)})}),Q.length>0&&e.jsx("span",{className:"flat-terminal-wrapper__buildings",role:"group","aria-label":"Area databases",children:Q.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?Ce():ft(a.id)==="modal"?nt(a.id):He("database",a.id)},onContextMenu:i=>{i.preventDefault(),i.stopPropagation(),we(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?Ce():ft(a.id)==="modal"?nt(a.id):He("tests",a.id)},onContextMenu:i=>{i.preventDefault(),i.stopPropagation(),we(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?Ce():ft(a.id)==="modal"?nt(a.id):He("http",a.id)},onContextMenu:i=>{i.preventDefault(),i.stopPropagation(),we(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(vn,{})})]}),_&&e.jsx(jn,{agentId:r,agents:Ge,onClose:Ot,branchInfoMap:bt,fetchRemote:Oe,fetchingDirs:Ie,onResizeStart:a=>lt(a,"right")}),Re&&e.jsx(Cn,{agentId:r,onClose:ot}),F&&e.jsx(kn,{agentId:r,onClose:zt})]})}),Gn={groups:[],gridCols:1,gridRows:1,positions:new Map};function Kn({onAgentClick:c,onBuildingClick:r,onBuildingDoubleClick:p,onBuildingPopup:x,onAreaContextMenu:C,onOpenSpawnModal:T,onOpenBossSpawnModal:S,onOpenAreaModal:N}){const{t:J}=Yt(["common"]),w=Pa(),U=Ra(),[z,le]=s.useState(null),[R,Se]=s.useState(null),[re,oe]=s.useState(null);fa("flatview-image-modal",z!==null,()=>le(null));const[$e,gt]=s.useState(null),[_e,we]=s.useState(null),[f,O]=s.useState(null),[Ae,Ee]=s.useState(null),[Ye,Me]=s.useState(!1),Tt=s.useCallback(()=>{Me(t=>!t)},[]),xt=s.useCallback(()=>{Me(!1)},[]),[Ke,ce]=s.useState(()=>{const t=ea(A.VIEW_MODE);return t==="simple"||t==="chat"||t==="advanced"?t:"simple"}),Ze=s.useCallback(t=>{ce(t),ta(A.VIEW_MODE,t)},[]);s.useEffect(()=>{const t=n=>{if(n.key!==A.VIEW_MODE)return;const l=n.newValue;(l==="simple"||l==="chat"||l==="advanced")&&ce(l)};return window.addEventListener("storage",t),()=>window.removeEventListener("storage",t)},[]);const[ze,de]=s.useState(()=>qt(A.FLAT_INSPECTOR_OPEN,!1)),[D,ue]=s.useState(!1),st=s.useCallback(()=>ue(t=>!t),[]),bt=s.useCallback(()=>ue(!1),[]);s.useEffect(()=>{window.dispatchEvent(new CustomEvent("tide-flat-agents-drawer-state",{detail:{open:D}}))},[D]),s.useEffect(()=>{window.dispatchEvent(new CustomEvent("tide-flat-inspector-state",{detail:{open:ze}}))},[ze]),s.useEffect(()=>{const t=()=>ue(k=>!k),n=()=>{de(k=>{const E=!k;return be(A.FLAT_INSPECTOR_OPEN,E),E})},l=()=>{ue(!1),de(!1),be(A.FLAT_INSPECTOR_OPEN,!1)},h=()=>ue(!1),b=()=>{de(!1),be(A.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",h),window.addEventListener("tide-close-flat-inspector-only",b),()=>{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",h),window.removeEventListener("tide-close-flat-inspector-only",b)}},[]);const Oe=s.useRef(null),Ie=s.useRef(null),[me,ve]=s.useState(()=>{const t=aa(A.FLAT_MIDDLE_WIDTH,0);return t>=It?t:null}),[Q,Be]=s.useState(()=>{const t=aa(A.FLAT_INSPECTOR_WIDTH,0);return t>=Gt?t:null}),se=s.useCallback(t=>{if(typeof window>"u")return t;const n=Q!==null?Mt+Q:0,l=window.innerWidth-da-Mt-ca-n;return Math.max(It,Math.min(Math.max(l,It),t))},[Q]),ie=s.useCallback(t=>{var b;if(typeof window>"u")return t;const n=(b=Oe.current)==null?void 0:b.querySelector(".flat-middle"),l=(n==null?void 0:n.getBoundingClientRect().width)??It,h=window.innerWidth-da-l-Mt-ca-Mt;return Math.max(Gt,Math.min(Math.max(h,Gt),t))},[]);s.useEffect(()=>{if(me===null&&Q===null)return;const t=()=>{ve(n=>{if(n===null)return n;const l=se(n);return l===n?n:l}),Be(n=>{if(n===null)return n;const l=ie(n);return l===n?n:l})};return window.addEventListener("resize",t),()=>window.removeEventListener("resize",t)},[me,Q,se,ie]);const Lt=s.useCallback(t=>{var l;if(t.button!==0)return;const n=(l=Oe.current)==null?void 0:l.querySelector(".flat-middle");n&&(t.currentTarget.setPointerCapture(t.pointerId),Ie.current={kind:"middle",startX:t.clientX,startWidth:n.getBoundingClientRect().width,pointerId:t.pointerId},document.body.classList.add("flat-splitter-dragging"))},[]),je=s.useCallback(t=>{var l;if(t.button!==0)return;const n=(l=Oe.current)==null?void 0:l.querySelector(".flat-inspector");n&&(t.currentTarget.setPointerCapture(t.pointerId),Ie.current={kind:"inspector",startX:t.clientX,startWidth:n.getBoundingClientRect().width,pointerId:t.pointerId},document.body.classList.add("flat-splitter-dragging"))},[]),it=s.useCallback(t=>{const n=Ie.current;if(!n||t.pointerId!==n.pointerId)return;const l=t.clientX-n.startX;n.kind==="middle"?ve(se(n.startWidth+l)):Be(ie(n.startWidth-l))},[se,ie]),Te=s.useCallback(t=>{const n=Ie.current;if(!n||t.pointerId!==n.pointerId)return;try{t.currentTarget.releasePointerCapture(t.pointerId)}catch{}if(Ie.current=null,document.body.classList.remove("flat-splitter-dragging"),!(Math.abs(t.clientX-n.startX)>2))return;const h=t.clientX-n.startX;if(n.kind==="middle"){const b=se(n.startWidth+h);ve(b),Et(A.FLAT_MIDDLE_WIDTH,b)}else{const b=ie(n.startWidth-h);Be(b),Et(A.FLAT_INSPECTOR_WIDTH,b)}},[se,ie]),Le=s.useCallback(()=>{ve(null),Et(A.FLAT_MIDDLE_WIDTH,0)},[]),j=s.useCallback(()=>{Be(null),Et(A.FLAT_INSPECTOR_WIDTH,0)},[]),[ae,ee]=s.useState(()=>ea(A.FLAT_INSPECTOR_VIEW)==="tracking"?"tracking":"agent"),Fe=s.useCallback(t=>{ee(t),ta(A.FLAT_INSPECTOR_VIEW,t)},[]),Pe=s.useCallback(()=>{de(t=>{const n=!t;return be(A.FLAT_INSPECTOR_OPEN,n),n})},[]),We=s.useCallback(()=>{de(!1),be(A.FLAT_INSPECTOR_OPEN,!1)},[]),Pt=s.useCallback(()=>{Fe("tracking"),de(!0),be(A.FLAT_INSPECTOR_OPEN,!0)},[Fe]),B=Da(),He=s.useCallback((t,n)=>{le({url:t,name:n})},[]),Ce=s.useCallback((t,n)=>{Se({command:t,output:n,isLive:!1})},[]),Rt=s.useCallback((t,n)=>{var b;const l=U.size>0?Array.from(U)[0]:null,h=l?(b=g.getState().agents.get(l))==null?void 0:b.cwd:void 0;g.setFileViewerPath(t,n,h)},[U]),Dt=s.useCallback(t=>{oe(t)},[]),$t=s.useCallback((t,n)=>{gt({agentId:t,count:n})},[]),lt=s.useCallback(t=>{p?p(t):r(t)},[r,p]),_=s.useMemo(()=>U.size>0?Array.from(U)[0]:null,[U]),_t=s.useCallback(t=>{_&&we({agentId:_,position:t})},[_]),Re=s.useCallback((t,n)=>{O({buildingId:t,position:n})},[]);s.useEffect(()=>{Me(!1)},[_]);const pe=s.useRef([]),F=s.useRef(-1),Ue=s.useRef(!1),rt=s.useRef(null),[zt,wt]=s.useState(!1),[vt,Ot]=s.useState(!1),ot=s.useRef(!1),Ge=s.useRef(null),fe=s.useRef(!1),ke=s.useMemo(()=>new Set(w.map(t=>t.id)),[w]),Ve=s.useMemo(()=>{const t=new Map(w.map(l=>[l.id,l])),n=new Map;for(const l of w)if((l.isBoss||l.class==="boss")&&l.subordinateIds&&l.subordinateIds.length>0){const h=l.subordinateIds.map(b=>t.get(b)).filter(b=>b!==void 0);h.length>0&&n.set(l.id,h)}return n},[w]),W=s.useCallback(()=>{const t=pe.current,n=F.current;wt(n>0),Ot(n>=0&&n<t.length-1)},[]),he=s.useCallback(t=>{const n=pe.current;if(n.length===0)return;let l=F.current+t;for(;l>=0&&l<n.length;){const h=n[l];if(ke.has(h)){Ue.current=!0,F.current=l,W(),g.selectAgent(h);return}l+=t}},[ke,W]),Ne=s.useCallback(()=>he(-1),[he]),ct=s.useCallback(()=>he(1),[he]);An(s.useCallback(()=>{const t=pe.current,n=F.current;return t.length>0&&n>0?(he(-1),"handled"):"exit"},[he]));const Je=s.useCallback((t,n)=>{if(typeof window>"u")return;const l=window.history.state,b={...typeof l=="object"&&l!==null?l:{},__flatAgentNav:{agentId:t}};n==="replace"?window.history.replaceState(b,"",window.location.href):window.history.pushState(b,"",window.location.href)},[]);s.useEffect(()=>{if(!_){ot.current=!1,Ge.current=null;return}if(!ot.current){Je(_,"replace"),ot.current=!0,Ge.current=_;return}if(fe.current){fe.current=!1,Ge.current=_;return}Ge.current!==_&&(Je(_,"push"),Ge.current=_)},[_,Je]),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"||!ke.has(l)||l===_)return;fe.current=!0,Ue.current=!0;const h=pe.current,b=h.lastIndexOf(l);b>=0?F.current=b:(h.push(l),F.current=h.length-1),W(),g.selectAgent(l)};return window.addEventListener("popstate",t),()=>window.removeEventListener("popstate",t)},[ke,_,W]),s.useEffect(()=>{if(!_){pe.current=[],F.current=-1,W();return}if(rt.current=_,Ue.current){Ue.current=!1,W();return}const t=pe.current,n=F.current;if(n>=0&&t[n]===_){W();return}const l=n<t.length-1?t.slice(0,n+1):t.slice();l.push(_),l.length>100&&l.shift(),pe.current=l,F.current=l.length-1,W()},[_,W]);const dt=s.useCallback(t=>{c(t),ue(!1)},[c]),Bt=_??"",De=s.useCallback(()=>{},[]),jt=s.useCallback(t=>{dt(t)},[dt]),ge=ze,[Qe,et]=s.useState(ge),[ut,xe]=s.useState(ge);s.useEffect(()=>{if(ge){et(!0);return}xe(!1);const t=setTimeout(()=>et(!1),240);return()=>clearTimeout(t)},[ge]),s.useEffect(()=>{if(!Qe||!ge)return;let t=0;const n=requestAnimationFrame(()=>{t=requestAnimationFrame(()=>xe(!0))});return()=>{cancelAnimationFrame(n),cancelAnimationFrame(t)}},[Qe,ge]);const mt=s.useRef(null);s.useEffect(()=>{if(_)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 h=rt.current;!h||!ke.has(h)||(n.preventDefault(),g.selectAgent(h))};return document.addEventListener("keydown",t),()=>document.removeEventListener("keydown",t)},[_,ke]);const[ye,tt]=s.useState(new Set),Ct=s.useCallback(t=>{tt(n=>{const l=new Set(n);return l.has(t)?l.delete(t):l.add(t),l})},[]),kt=s.useCallback(t=>{tt(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,u]=s.useState(null),X=s.useCallback(t=>{u(n=>n===t?null:t)},[]),te=ha(),L=ga(),[at]=$a(),q=s.useMemo(()=>{if(_)return Gn;const t=new Map,n=[];for(const v of w){const I=g.getAreaForAgent(v.id);if(!na((I==null?void 0:I.id)??null))continue;if(!I||I.archived){n.push(v);continue}const P=t.get(I.id);P?P.push(v):t.set(I.id,[v])}const l=new Map,h=[];for(const v of L.values()){let I=!1;for(const P of te.values())if(!P.archived&&sa(P.id)&&g.isPositionInArea(v.position,P)){const Y=l.get(P.id);Y?Y.push(v):l.set(P.id,[v]),I=!0;break}!I&&na(null)&&h.push(v)}const b=[];for(const[,v]of te){if(v.archived||!sa(v.id))continue;const I=t.get(v.id),P=l.get(v.id)??[];(I&&I.length>0||P.length>0)&&b.push({area:v,agents:I??[],buildings:P})}(n.length>0||h.length>0)&&b.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:h});const k=b.filter(v=>v.area.id!=="__unassigned__"),E=b.filter(v=>v.area.id==="__unassigned__");let m=1,M=1;const V=new Map;if(k.length>1){let v=1/0,I=-1/0,P=1/0,Y=-1/0;for(const K of k)v=Math.min(v,K.area.center.x),I=Math.max(I,K.area.center.x),P=Math.min(P,K.area.center.z),Y=Math.max(Y,K.area.center.z);const yt=I-v||1,St=Y-P||1;if(k.length<=4){m=k.length,M=1;const K=[...k].sort((Z,Ft)=>Z.area.center.x-Ft.area.center.x);for(let Z=0;Z<K.length;Z++)V.set(K[Z].area.id,{row:1,col:Z+1})}else{const K=[...k].sort((y,H)=>y.area.center.x-H.area.center.x),Z=[];for(let y=1;y<K.length;y++)Z.push(K[y].area.center.x-K[y-1].area.center.x);const Ft=Z.reduce((y,H)=>y+H,0)/Z.length||1;let Kt=1;for(const y of Z)y>Ft*1.3&&Kt++;m=Math.max(2,Math.min(Kt,k.length));const Wt=[...k].sort((y,H)=>y.area.center.z-H.area.center.z),At=[];for(let y=1;y<Wt.length;y++)At.push(Wt[y].area.center.z-Wt[y-1].area.center.z);const Ca=At.reduce((y,H)=>y+H,0)/At.length||1;let Zt=1;for(const y of At)y>Ca*1.3&&Zt++;M=Math.max(2,Math.min(Zt,k.length)),m=Math.max(m,Math.ceil(k.length/M)),M=Math.max(M,Math.ceil(k.length/m));const ka=yt/m,Na=St/M,Ht=new Set;for(const y of k){let H=Math.min(m-1,Math.max(0,Math.floor((y.area.center.x-v)/ka))),qe=Math.min(M-1,Math.max(0,Math.floor((y.area.center.z-P)/Na))),pt=`${qe},${H}`,Jt=0;const ya=M*m;for(;Ht.has(pt)&&Jt<ya;)H++,H>=m&&(H=0,qe=(qe+1)%M),pt=`${qe},${H}`,Jt++;Ht.has(pt)&&(qe=M,H=0,pt=`${qe},${H}`,M++),Ht.add(pt),V.set(y.area.id,{row:qe+1,col:H+1})}}}const $=v=>{v.sort((I,P)=>{var yt,St,K,Z;const Y=(((yt=I.position)==null?void 0:yt.z)??0)-(((St=P.position)==null?void 0:St.z)??0);return Y!==0?Y:(((K=I.position)==null?void 0:K.x)??0)-(((Z=P.position)==null?void 0:Z.x)??0)})};for(const v of k)$(v.agents);for(const v of E)$(v.agents);return{groups:[...k,...E],gridCols:m,gridRows:M,positions:V}},[w,te,L,at,_]),Xe=s.useMemo(()=>{let t=0,n=0;for(const l of q.groups)t+=l.agents.length,n+=l.agents.filter(h=>h.status==="working").length;return{areaCount:q.groups.length,agentCount:t,workingCount:n}},[q]),ne=s.useMemo(()=>{if(!_e)return[];const t=w.find(n=>n.id===_e.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:()=>{Ee({agentId:t.id,name:t.name})}}]:[]},[_e,w,c]),G=s.useMemo(()=>{var k;if(!f)return[];const t=L.get(f.buildingId);if(!t)return[];const n=[],l=t.type==="server"||t.type==="docker"||t.type==="terminal",h=t.status==="running",b=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:()=>lt(t.id)}),l&&(h||n.push({id:"start",label:"Start",icon:e.jsx(d,{name:"play",size:14}),onClick:()=>g.sendBuildingCommand(t.id,"start")}),h&&(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")}))),b&&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},[f,L,lt]),Nt=s.useCallback(t=>{const n=new Set(q.groups.map(l=>l.area.id));n.delete(t),tt(n),requestAnimationFrame(()=>{const l=mt.current;if(!l)return;const h=l.querySelector(`[data-area-id="${t}"]`);if(!h)return;const b=l.getBoundingClientRect(),E=h.getBoundingClientRect().top-b.top+l.scrollTop-8;l.scrollTo({top:Math.max(0,E),behavior:"smooth"})})},[q]);return e.jsxs("div",{ref:Oe,className:`flat-view ${ge?"flat-view--with-inspector":""} ${_?"flat-view--has-chat":""} ${D?"flat-view--mobile-sidebar-open":""}`,style:(()=>{if(me===null&&Q===null)return;const t={};return me!==null&&(t["--flat-middle-width"]=`${me}px`),Q!==null&&(t["--flat-inspector-width"]=`${Q}px`),t})(),children:[D&&e.jsx("div",{className:"flat-mobile-sidebar-backdrop",onClick:bt,"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:T,title:"Create new agent",children:"+ Agent"}),e.jsx("button",{className:"flat-cta-btn flat-cta-btn--boss",onClick:S,title:"Create new boss agent",children:"+ Boss"}),e.jsx("button",{className:"flat-cta-btn flat-cta-btn--area",onClick:N,title:"Create new area",children:"+ Area"})]})}),e.jsx("div",{className:"flat-middle__content",children:e.jsx(za,{activeAgentId:Bt,onClose:De,onSelectAgent:jt,collapsedAreas:ye,onToggleArea:Ct,onCollapseAllAreas:kt,agentListRef:mt})})]}),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:Lt,onPointerMove:it,onPointerUp:Te,onPointerCancel:Te,onDoubleClick:Le}),e.jsxs("div",{className:"flat-right",children:[e.jsxs("button",{type:"button",className:"flat-mobile-sidebar-toggle","aria-label":D?"Close agents sidebar":"Open agents sidebar","aria-expanded":D,onClick:st,children:[e.jsx(d,{name:"list",size:18}),e.jsx("span",{className:"flat-mobile-sidebar-toggle__label",children:"Agents"})]}),_?e.jsx(Un,{agentId:_,terminalViewMode:Ke,onTerminalViewModeChange:Ze,inspectorOpen:ze,onToggleInspector:Pe,onShowTaskBoard:Pt,onImageClick:He,onFileClick:Rt,onBashClick:Ce,onViewMarkdown:Dt,onRequestClearSubordinates:$t,keyboard:B,canNavigateBack:zt,canNavigateForward:vt,onNavigateBack:Ne,onNavigateForward:ct,agentInfoOpen:Ye,onToggleAgentInfo:Tt,onHeaderContextMenu:_t,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:[Xe.areaCount," areas"]}),e.jsxs("span",{children:[Xe.agentCount," agents"]}),Xe.workingCount>0&&e.jsxs("span",{className:"flat-map__stats-working",children:[e.jsx("span",{className:"flat-map__stats-dot","aria-hidden":"true"}),Xe.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(${q.gridCols}, 1fr)`},children:q.groups.length===0?e.jsx("div",{className:"flat-map__empty",children:e.jsx("span",{children:"No areas or agents yet"})}):(a?[...q.groups].sort((n,l)=>{const h=q.positions.get(n.area.id),b=q.positions.get(l.area.id);return!h&&!b?0:h?b?h.row-b.row||h.col-b.col:-1:1}):q.groups).map(n=>{var E;const l=n.area.id,h=q.positions.get(l),b=a&&i!==l,k=a&&!b;return e.jsxs("div",{className:`flat-map-area-card${b?" flat-map-area-card--collapsed":""}${k?" flat-map-area-card--expanded":""}`,style:{"--area-color":n.area.color,gridRow:a||h==null?void 0:h.row,gridColumn:a||h==null?void 0:h.col},onContextMenu:m=>{C&&(m.preventDefault(),m.stopPropagation(),C(l,{x:m.clientX,y:m.clientY}))},children:[e.jsxs("button",{type:"button",className:"flat-map-area-card__header",onClick:()=>a?X(l):Nt(l),title:a?b?`Expand ${n.area.name}`:`Collapse ${n.area.name}`:`Focus ${n.area.name} in left panel`,"aria-expanded":a?!b:void 0,children:[e.jsx("span",{className:"flat-map-area-card__color",style:{background:n.area.color}}),((E=n.area.logo)==null?void 0:E.filename)&&e.jsx("img",{className:"flat-map-area-card__logo",src:Sn(n.area.logo.filename),alt:"","aria-hidden":"true",onError:m=>{m.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]}),a&&e.jsx(d,{name:b?"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(m=>{const M=m.isBoss||m.class==="boss",V=M?Ve.get(m.id):void 0,$=Oa(m),v=$.usedPercent>=80?"#ff4a4a":$.usedPercent>=60?"#ff9e4a":$.usedPercent>=40?"#ffd700":"#4aff9e",I=`Context: ${($.totalTokens/1e3).toFixed(1)}k / ${($.contextWindow/1e3).toFixed(1)}k (${$.usedPercent}% used, ${$.freePercent}% free)`,P=m.latestTodos&&m.latestTodos.length>0||V&&V.length>0;return e.jsx(Ba,{todos:m.latestTodos,subordinates:V,position:"top",children:e.jsxs("button",{type:"button",className:`flat-map-agent-chip ${m.status}`,onClick:()=>c(m.id),onContextMenu:Y=>{Y.preventDefault(),Y.stopPropagation(),we({agentId:m.id,position:{x:Y.clientX,y:Y.clientY}})},title:P?void 0:`${M?"Boss · ":""}Open chat with ${m.name}
|
|
2
2
|
${I}`,children:[e.jsx(xa,{agent:m,size:16}),M&&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:m.name}),e.jsx("img",{src:_a(m.provider,"/"),alt:m.provider,className:"flat-map-agent-chip__provider-icon",title:ba(m.provider)}),e.jsx("span",{className:"flat-map-agent-chip__dot",style:{backgroundColor:wa(m.status)}}),m.latestTodos&&m.latestTodos.length>0&&e.jsx(Fa,{todos:m.latestTodos,maxDots:6}),M&&V&&V.length>0&&e.jsx(Wa,{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:`${$.usedPercent}%`,backgroundColor:v}})})]})},m.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(m=>{const M=m.split("/").filter(Boolean).pop()||m;return e.jsxs("button",{type:"button",className:"flat-map-folder-chip",onClick:V=>{V.stopPropagation(),g.openFileExplorerForAreaFolder(l,m)},title:`Open in file explorer: ${m}`,children:[e.jsx(d,{name:"folder-open",size:12}),e.jsx("span",{className:"flat-map-folder-chip__name",children:M})]},m)})}),n.buildings.length>0&&e.jsx("div",{className:"flat-map-area-card__buildings",children:n.buildings.map(m=>{var V;const M=(V=Ha[m.type])==null?void 0:V.color;return e.jsxs("button",{type:"button",className:`flat-map-building-chip flat-map-building-chip--${m.status}`,style:M?{"--building-type-color":M}:void 0,onClick:$=>{if(x){const v=$.currentTarget.getBoundingClientRect();x(m.id,{x:v.right,y:v.top+v.height/2})}else lt(m.id)},onContextMenu:$=>{$.preventDefault(),$.stopPropagation(),O({buildingId:m.id,position:{x:$.clientX,y:$.clientY}})},title:`${m.name} · ${m.type} · ${m.status}`,children:[e.jsx(d,{name:Ua(m.type),size:12,color:M}),e.jsx("span",{className:"flat-map-building-chip__name",children:m.name}),e.jsx("span",{className:"flat-map-building-chip__dot",style:{backgroundColor:Ga(m.status)}})]},m.id)})})]},l)})})]})})]}),ge&&e.jsx("div",{className:"flat-splitter flat-splitter--inspector",role:"separator","aria-orientation":"vertical","aria-label":"Resize inspector panel",title:"Drag to resize · Double-click to reset",onPointerDown:je,onPointerMove:it,onPointerUp:Te,onPointerCancel:Te,onDoubleClick:j}),Qe&&e.jsxs("aside",{className:`flat-inspector ${ut?"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":ae==="agent",className:`flat-inspector__tab ${ae==="agent"?"flat-inspector__tab--active":""}`,onClick:()=>Fe("agent"),children:"Agent"}),e.jsx("button",{type:"button",role:"tab","aria-selected":ae==="tracking",className:`flat-inspector__tab ${ae==="tracking"?"flat-inspector__tab--active":""}`,onClick:()=>Fe("tracking"),children:"Tracking"})]}),e.jsx("button",{type:"button",className:"flat-inspector__close",onClick:We,title:"Close inspector","aria-label":"Close inspector",children:"✕"})]}),e.jsx("div",{className:"flat-inspector__body",children:ae==="tracking"?e.jsx(Va,{activeAgentId:_??"",onSelectAgent:t=>{c(t),window.innerWidth<=768&&We()}}):(()=>{if(!_)return e.jsx("div",{className:"flat-inspector__empty",children:e.jsx("span",{children:"Select an agent to inspect"})});const t=w.find(n=>n.id===_);return t?e.jsx(Xa,{agent:t,onFocusAgent:n=>{c(n),window.innerWidth<=768&&We()},onKillAgent:n=>g.killAgent(n)}):e.jsx("div",{className:"flat-inspector__empty",children:e.jsx("span",{children:"Agent not found"})})})()})]}),z&&e.jsx(qa,{url:z.url,name:z.name,onClose:()=>le(null)}),R&&e.jsx(Ya,{state:R,onClose:()=>Se(null)}),e.jsx(Ka,{agent:_?w.find(t=>t.id===_)??null:null,content:re,onClose:()=>oe(null)}),$e&&e.jsx(Za,{action:"clear-subordinates",selectedAgentId:$e.agentId,subordinateCount:$e.count,onClose:()=>gt(null),onClearHistory:()=>{}}),e.jsx(Ja,{agent:_?w.find(t=>t.id===_)??null:null,isOpen:Ye&&!!_,onClose:xt}),e.jsx(ia,{isOpen:_e!==null,position:(_e==null?void 0:_e.position)??{x:0,y:0},worldPosition:{x:0,z:0},actions:ne,onClose:()=>we(null)}),e.jsx(ia,{isOpen:f!==null,position:(f==null?void 0:f.position)??{x:0,y:0},worldPosition:{x:0,z:0},actions:G,onClose:()=>O(null)}),e.jsx(Qa,{isOpen:Ae!==null,title:J("common:confirm.removeAgentTitle"),message:J("common:confirm.removeAgentMessage",{name:(Ae==null?void 0:Ae.name)??""}),confirmLabel:J("common:buttons.remove"),cancelLabel:J("common:buttons.cancel"),variant:"danger",onConfirm:()=>{Ae&&g.removeAgentFromServer(Ae.agentId)},onClose:()=>Ee(null)})]})}export{Kn as FlatView};
|