tide-commander 1.158.1 → 1.159.1
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 +22 -0
- package/dist/assets/{BossLogsModal-B93nAi6w.js → BossLogsModal-CL5C40v7.js} +1 -1
- package/dist/assets/{BossSpawnModal-BZfkBIUP.js → BossSpawnModal-QRrIVSsE.js} +1 -1
- package/dist/assets/{ControlsModal-CokH7-Ch.js → ControlsModal-_cw1dgUl.js} +1 -1
- package/dist/assets/{DockerLogsModal-CE7voebe.js → DockerLogsModal-BMzpUMYF.js} +1 -1
- package/dist/assets/{EmbeddedEditor-2SZUK5kL.js → EmbeddedEditor-DqY3hqbU.js} +1 -1
- package/dist/assets/{GmailOAuthSetup-loIWx7N6.js → GmailOAuthSetup-Bc9srJE4.js} +1 -1
- package/dist/assets/{GoogleOAuthSetup-vJXIANe_.js → GoogleOAuthSetup-DeaxWPCd.js} +1 -1
- package/dist/assets/{IframeModal-Ckvn_Lzf.js → IframeModal-3uoqeRAN.js} +1 -1
- package/dist/assets/{IntegrationsPanel-B3zzS9Nh.js → IntegrationsPanel-DL9VTiWv.js} +2 -2
- package/dist/assets/{LogViewerModal-D0XO9IMx.js → LogViewerModal-Bp80nuou.js} +1 -1
- package/dist/assets/{MonitoringModal-Chl__aV6.js → MonitoringModal-p_ucVk30.js} +1 -1
- package/dist/assets/{PM2LogsModal-BIrvZOaj.js → PM2LogsModal-Bk060m4u.js} +1 -1
- package/dist/assets/{RestoreArchivedAreaModal-CWLku6hW.js → RestoreArchivedAreaModal-DgYKagxt.js} +1 -1
- package/dist/assets/{Scene2DCanvas-7cZb2Lf_.js → Scene2DCanvas-C7Xc_5Dz.js} +1 -1
- package/dist/assets/{SceneManager-Bjr_vL-G.js → SceneManager-D1HZULQL.js} +1 -1
- package/dist/assets/{SkillsPanel-B4xujErO.js → SkillsPanel-DR0YQBuD.js} +1 -1
- package/dist/assets/{SlackMultiInstanceSetup-CHtPdLjB.js → SlackMultiInstanceSetup-W9boSb9T.js} +1 -1
- package/dist/assets/{SpawnModal-CMo1ONqI.js → SpawnModal-CN0uPU2H.js} +1 -1
- package/dist/assets/{StatisticsModal-CFmf5imp.js → StatisticsModal-Bs8WGrk8.js} +1 -1
- package/dist/assets/{SubordinateAssignmentModal-lHpc0gZ6.js → SubordinateAssignmentModal-CppZw5TE.js} +1 -1
- package/dist/assets/{TriggerManagerPanel-DnlJPZPN.js → TriggerManagerPanel-BZeMe-9r.js} +1 -1
- package/dist/assets/{WorkflowEditorPanel-BGlj99Mc.js → WorkflowEditorPanel-BH5HqvN2.js} +1 -1
- package/dist/assets/{area-logos-B6vGTcNz.js → area-logos-B6CrA1uD.js} +1 -1
- package/dist/assets/{index-Bhuukfvi.js → index-B_RzzK2X.js} +3 -3
- package/dist/assets/{index-DjcG_URX.js → index-BtnAoK73.js} +1 -1
- package/dist/assets/index-CN1Rq7ZV.js +2 -0
- package/dist/assets/{index-BzfQHwRj.js → index-Cmhnprql.js} +1 -1
- package/dist/assets/{index-CMBYmIwC.js → index-D3ivqCnn.js} +2 -2
- package/dist/assets/{index-CTGjGlWc.js → index-DHio1aFH.js} +1 -1
- package/dist/assets/{index-B283Ampa.js → index-DI8A9Ggk.js} +1 -1
- package/dist/assets/{index-E5gXqQz2.js → index-DnOc4jz6.js} +1 -1
- package/dist/assets/{index-CZGcOnhI.js → index-ZZxeSHEQ.js} +1 -1
- package/dist/assets/main-BZcOdtO_.css +1 -0
- package/dist/assets/main-BbNRp516.js +297 -0
- package/dist/assets/{web-BGYTb0Uy.js → web-BCXtfjWo.js} +1 -1
- package/dist/assets/{web-CtMcJxQ0.js → web-C24Z_D9n.js} +1 -1
- package/dist/assets/{web-DWhg3yLF.js → web-CC__8ncF.js} +1 -1
- package/dist/build-info.json +1 -1
- package/dist/index.html +2 -2
- package/dist/src/packages/server/cli.js +22 -1
- package/dist/src/packages/server/data/builtin-skills/computer-use.js +102 -0
- package/dist/src/packages/server/data/builtin-skills/index.js +2 -0
- package/package.json +1 -1
- package/dist/assets/index-BBDS1FfV.js +0 -2
- package/dist/assets/main-B9woGcB4.css +0 -1
- package/dist/assets/main-FwlHcqGj.js +0 -300
|
@@ -1 +1 @@
|
|
|
1
|
-
import{df as a}from"./main-
|
|
1
|
+
import{df as a}from"./main-BbNRp516.js";import{ImpactStyle as i,NotificationType as r}from"./index-D3ivqCnn.js";import"./vendor-react--Eh9ivFN.js";import"./vendor-three-Chj50gSY.js";class h extends a{constructor(){super(...arguments),this.selectionStarted=!1}async impact(t){const e=this.patternForImpact(t==null?void 0:t.style);this.vibrateWithPattern(e)}async notification(t){const e=this.patternForNotification(t==null?void 0:t.type);this.vibrateWithPattern(e)}async vibrate(t){const e=(t==null?void 0:t.duration)||300;this.vibrateWithPattern([e])}async selectionStart(){this.selectionStarted=!0}async selectionChanged(){this.selectionStarted&&this.vibrateWithPattern([70])}async selectionEnd(){this.selectionStarted=!1}patternForImpact(t=i.Heavy){return t===i.Medium?[43]:t===i.Light?[20]:[61]}patternForNotification(t=r.Success){return t===r.Warning?[30,40,30,50,60]:t===r.Error?[27,45,50]:[35,65,21]}vibrateWithPattern(t){if(navigator.vibrate)navigator.vibrate(t);else throw this.unavailable("Browser does not support the vibrate API")}}export{h as HapticsWeb};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{df as s}from"./main-
|
|
1
|
+
import{df as s}from"./main-BbNRp516.js";import"./vendor-react--Eh9ivFN.js";import"./vendor-three-Chj50gSY.js";class l extends s{constructor(){super(...arguments),this.pending=[],this.deliveredNotifications=[],this.hasNotificationSupport=()=>{if(!("Notification"in window)||!Notification.requestPermission)return!1;if(Notification.permission!=="granted")try{new Notification("")}catch(i){if(i instanceof Error&&i.name==="TypeError")return!1}return!0}}async getDeliveredNotifications(){const i=[];for(const t of this.deliveredNotifications){const e={title:t.title,id:parseInt(t.tag),body:t.body};i.push(e)}return{notifications:i}}async removeDeliveredNotifications(i){for(const t of i.notifications){const e=this.deliveredNotifications.find(n=>n.tag===String(t.id));e==null||e.close(),this.deliveredNotifications=this.deliveredNotifications.filter(()=>!e)}}async removeAllDeliveredNotifications(){for(const i of this.deliveredNotifications)i.close();this.deliveredNotifications=[]}async createChannel(){throw this.unimplemented("Not implemented on web.")}async deleteChannel(){throw this.unimplemented("Not implemented on web.")}async listChannels(){throw this.unimplemented("Not implemented on web.")}async schedule(i){if(!this.hasNotificationSupport())throw this.unavailable("Notifications not supported in this browser.");for(const t of i.notifications)this.sendNotification(t);return{notifications:i.notifications.map(t=>({id:t.id}))}}async getPending(){return{notifications:this.pending}}async registerActionTypes(){throw this.unimplemented("Not implemented on web.")}async cancel(i){this.pending=this.pending.filter(t=>!i.notifications.find(e=>e.id===t.id))}async areEnabled(){const{display:i}=await this.checkPermissions();return{value:i==="granted"}}async changeExactNotificationSetting(){throw this.unimplemented("Not implemented on web.")}async checkExactNotificationSetting(){throw this.unimplemented("Not implemented on web.")}async requestPermissions(){if(!this.hasNotificationSupport())throw this.unavailable("Notifications not supported in this browser.");return{display:this.transformNotificationPermission(await Notification.requestPermission())}}async checkPermissions(){if(!this.hasNotificationSupport())throw this.unavailable("Notifications not supported in this browser.");return{display:this.transformNotificationPermission(Notification.permission)}}transformNotificationPermission(i){switch(i){case"granted":return"granted";case"denied":return"denied";default:return"prompt"}}sendPending(){var i;const t=[],e=new Date().getTime();for(const n of this.pending)!((i=n.schedule)===null||i===void 0)&&i.at&&n.schedule.at.getTime()<=e&&(this.buildNotification(n),t.push(n));this.pending=this.pending.filter(n=>!t.find(o=>o===n))}sendNotification(i){var t;if(!((t=i.schedule)===null||t===void 0)&&t.at){const e=i.schedule.at.getTime()-new Date().getTime();this.pending.push(i),setTimeout(()=>{this.sendPending()},e);return}this.buildNotification(i)}buildNotification(i){const t=new Notification(i.title,{body:i.body,tag:String(i.id)});return t.addEventListener("click",this.onClick.bind(this,i),!1),t.addEventListener("show",this.onShow.bind(this,i),!1),t.addEventListener("close",()=>{this.deliveredNotifications=this.deliveredNotifications.filter(()=>!this)},!1),this.deliveredNotifications.push(t),t}onClick(i){const t={actionId:"tap",notification:i};this.notifyListeners("localNotificationActionPerformed",t)}onShow(i){this.notifyListeners("localNotificationReceived",i)}}export{l as LocalNotificationsWeb};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{df as t}from"./main-
|
|
1
|
+
import{df as t}from"./main-BbNRp516.js";import"./vendor-react--Eh9ivFN.js";import"./vendor-three-Chj50gSY.js";class o extends t{constructor(){super(),this.handleVisibilityChange=()=>{const e={isActive:document.hidden!==!0};this.notifyListeners("appStateChange",e),document.hidden?this.notifyListeners("pause",null):this.notifyListeners("resume",null)},document.addEventListener("visibilitychange",this.handleVisibilityChange,!1)}exitApp(){throw this.unimplemented("Not implemented on web.")}async getInfo(){throw this.unimplemented("Not implemented on web.")}async getLaunchUrl(){return{url:""}}async getState(){return{isActive:document.hidden!==!0}}async minimizeApp(){throw this.unimplemented("Not implemented on web.")}async toggleBackButtonHandler(){throw this.unimplemented("Not implemented on web.")}async getAppLanguage(){return{value:navigator.language.split("-")[0].toLowerCase()}}}export{o as AppWeb};
|
package/dist/build-info.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":"1.
|
|
1
|
+
{"version":"1.159.1"}
|
package/dist/index.html
CHANGED
|
@@ -22,10 +22,10 @@
|
|
|
22
22
|
<link rel="icon" type="image/png" sizes="16x16" href="/assets/icons/favicon-16x16.png" />
|
|
23
23
|
<link rel="apple-touch-icon" sizes="180x180" href="/assets/icons/apple-touch-icon.png" />
|
|
24
24
|
<title>Tide Commander</title>
|
|
25
|
-
<script type="module" crossorigin src="/assets/main-
|
|
25
|
+
<script type="module" crossorigin src="/assets/main-BbNRp516.js"></script>
|
|
26
26
|
<link rel="modulepreload" crossorigin href="/assets/vendor-react--Eh9ivFN.js">
|
|
27
27
|
<link rel="modulepreload" crossorigin href="/assets/vendor-three-Chj50gSY.js">
|
|
28
|
-
<link rel="stylesheet" crossorigin href="/assets/main-
|
|
28
|
+
<link rel="stylesheet" crossorigin href="/assets/main-BZcOdtO_.css">
|
|
29
29
|
</head>
|
|
30
30
|
<body>
|
|
31
31
|
<div id="app"></div>
|
|
@@ -318,14 +318,35 @@ function readPidFile() {
|
|
|
318
318
|
return null;
|
|
319
319
|
}
|
|
320
320
|
}
|
|
321
|
+
/**
|
|
322
|
+
* True only if `pid` is a *live* process. A bare `kill(pid, 0)` probe is not
|
|
323
|
+
* enough: on Linux a zombie (State: Z — exited but not yet reaped by its parent)
|
|
324
|
+
* still occupies the process table, so the probe succeeds for it too. In
|
|
325
|
+
* containers whose PID 1 doesn't reap children, an unreaped launcher would then
|
|
326
|
+
* be mistaken for a running server — the startup guard waits on it forever, the
|
|
327
|
+
* follow-up SIGKILL no-ops, and the launch crash-loops. Treat zombies as dead by
|
|
328
|
+
* inspecting /proc/<pid>/stat; if /proc is unavailable (non-Linux) or the read
|
|
329
|
+
* races, fall back to trusting the signal probe.
|
|
330
|
+
*/
|
|
321
331
|
function isRunning(pid) {
|
|
322
332
|
try {
|
|
323
333
|
process.kill(pid, 0);
|
|
324
|
-
return true;
|
|
325
334
|
}
|
|
326
335
|
catch {
|
|
327
336
|
return false;
|
|
328
337
|
}
|
|
338
|
+
try {
|
|
339
|
+
const stat = fs.readFileSync(`/proc/${pid}/stat`, 'utf8');
|
|
340
|
+
// Format: "pid (comm) state ...". comm may contain spaces or ')', so key off
|
|
341
|
+
// the final ')' to locate the single-char state field that follows it.
|
|
342
|
+
const state = stat.slice(stat.lastIndexOf(')') + 1).trim()[0];
|
|
343
|
+
if (state === 'Z')
|
|
344
|
+
return false;
|
|
345
|
+
}
|
|
346
|
+
catch {
|
|
347
|
+
// /proc missing (non-Linux) or the process vanished mid-read — trust kill(0).
|
|
348
|
+
}
|
|
349
|
+
return true;
|
|
329
350
|
}
|
|
330
351
|
async function waitForProcessExit(pid, timeoutMs = 8000) {
|
|
331
352
|
const started = Date.now();
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
export const computerUse = {
|
|
2
|
+
slug: 'computer-use',
|
|
3
|
+
name: 'Computer Use',
|
|
4
|
+
description: 'Observe and control the local Linux desktop through the Tide Computer Use CLI: inspect apps, accessibility trees and windows; capture screenshots; focus, click, drag, type, press keys, and manage windows.',
|
|
5
|
+
allowedTools: ['Bash(tide-computer-use-linux:*)', 'Read'],
|
|
6
|
+
// Live desktop control is powerful and potentially destructive. Enable it per agent/class.
|
|
7
|
+
assignedAgentClasses: [],
|
|
8
|
+
content: `# Computer Use
|
|
9
|
+
|
|
10
|
+
Use the **tide-computer-use-linux** CLI to observe and control the user's real Linux desktop. Every mutation affects live applications and may change files or external state.
|
|
11
|
+
|
|
12
|
+
## Prerequisite
|
|
13
|
+
|
|
14
|
+
Run **tide-computer-use-linux doctor** first. If the command is missing, stop and tell the user to install **@tide-commander/computer-use-linux**; do not substitute xdotool, shell file operations, or the Rust reference binary. Continue only when readiness has no blockers.
|
|
15
|
+
|
|
16
|
+
## Required workflow
|
|
17
|
+
|
|
18
|
+
1. **Inspect:** use windows, focused-window, apps, tree, or screenshot.
|
|
19
|
+
2. **Target:** select a unique window ID, accessibility object reference, or visible coordinate from fresh state. Never guess from stale coordinates.
|
|
20
|
+
3. **Act once:** issue the smallest requested mutation.
|
|
21
|
+
4. **Verify:** re-read the tree/window state, capture a screenshot, or verify the requested external effect. An ok response confirms event emission, not that the application accepted it.
|
|
22
|
+
5. If verification fails, inspect again before retrying. Never repeat blind clicks, drags, typing, or submissions.
|
|
23
|
+
|
|
24
|
+
## Batch actions
|
|
25
|
+
|
|
26
|
+
Use one batch when the user requests an ordered desktop sequence. Batches run sequentially, preserve the window selected by a focus step for later semantic click/drag steps, stop on the first failure by default, and return one timed result per attempted step.
|
|
27
|
+
|
|
28
|
+
~~~bash
|
|
29
|
+
tide-computer-use-linux batch '[
|
|
30
|
+
{"action":"focusWindow","title":"Tabby"},
|
|
31
|
+
"wait 500ms",
|
|
32
|
+
{"action":"click","x":600,"y":400},
|
|
33
|
+
{"action":"type","text":"echo hello"}
|
|
34
|
+
]'
|
|
35
|
+
~~~
|
|
36
|
+
|
|
37
|
+
Prefer structured objects for generated workflows. Shorthand supports focus NAME, click NAME, drag NAME to NAME, wait 10s, move X Y, key ctrl+l, type TEXT, scroll down 3, and screenshot. Use semantic click/drag names only after a unique focusWindow step or include an app selector in the structured action.
|
|
38
|
+
|
|
39
|
+
- Maximum 50 actions, 30 seconds per wait, and 120 seconds of total waiting.
|
|
40
|
+
- Use --continue only when later steps are genuinely independent of an earlier failure. Never continue a dependent UI flow after a failed focus, click, drag, or type.
|
|
41
|
+
- Inspect the returned steps array. Overall ok is true only when every requested action completed.
|
|
42
|
+
- Batch execution does not weaken confirmation rules: stop before irreversible final actions unless already explicitly authorized.
|
|
43
|
+
|
|
44
|
+
## Read-only commands
|
|
45
|
+
|
|
46
|
+
~~~bash
|
|
47
|
+
tide-computer-use-linux doctor
|
|
48
|
+
tide-computer-use-linux windows
|
|
49
|
+
tide-computer-use-linux focused-window
|
|
50
|
+
tide-computer-use-linux apps
|
|
51
|
+
tide-computer-use-linux tree "APP_OR_PID" 300
|
|
52
|
+
tide-computer-use-linux screenshot /tmp/desktop.png
|
|
53
|
+
tide-computer-use-linux pointer
|
|
54
|
+
~~~
|
|
55
|
+
|
|
56
|
+
Use Read on a screenshot path when visual inspection materially helps. Window titles and accessibility trees may expose private content; return only details relevant to the task.
|
|
57
|
+
|
|
58
|
+
## Window control
|
|
59
|
+
|
|
60
|
+
~~~bash
|
|
61
|
+
tide-computer-use-linux activate WINDOW_ID
|
|
62
|
+
tide-computer-use-linux move-window WINDOW_ID X Y
|
|
63
|
+
tide-computer-use-linux resize-window WINDOW_ID WIDTH HEIGHT
|
|
64
|
+
~~~
|
|
65
|
+
|
|
66
|
+
Resolve WINDOW_ID immediately before acting. Prefer exact appId, PID, or title matches; if several windows match, inspect and disambiguate.
|
|
67
|
+
|
|
68
|
+
## Semantic accessibility
|
|
69
|
+
|
|
70
|
+
Prefer semantic actions over pixel input when the element exposes an action or editable-text interface:
|
|
71
|
+
|
|
72
|
+
~~~bash
|
|
73
|
+
tide-computer-use-linux action OBJECT_REF Press
|
|
74
|
+
tide-computer-use-linux set-text OBJECT_REF "literal text"
|
|
75
|
+
~~~
|
|
76
|
+
|
|
77
|
+
Use the exact objectRef and action name from a fresh tree response. Accessibility references are session-local and can become stale after UI changes.
|
|
78
|
+
|
|
79
|
+
## Pointer and keyboard
|
|
80
|
+
|
|
81
|
+
~~~bash
|
|
82
|
+
tide-computer-use-linux move X Y
|
|
83
|
+
tide-computer-use-linux click X Y
|
|
84
|
+
tide-computer-use-linux drag X1 Y1 X2 Y2
|
|
85
|
+
tide-computer-use-linux key ctrl+l
|
|
86
|
+
tide-computer-use-linux type 'literal text'
|
|
87
|
+
~~~
|
|
88
|
+
|
|
89
|
+
- Activate the target window first. For terminal/canvas surfaces, click a safe point inside the client area before typing so the widget—not merely its window—owns keyboard focus.
|
|
90
|
+
- Do not append Enter unless the user asked to execute or submit.
|
|
91
|
+
- Coordinate actions require fresh window bounds or screenshots. Accessibility bounds can cover a whole row while only its icon/label accepts a drag; verify visually when precision matters.
|
|
92
|
+
- Text typing uses a US-layout native keyboard mapping. For non-ASCII text or non-US layouts, prefer set-text on an editable accessibility element.
|
|
93
|
+
- A failed UI drag remains a failed UI drag. Do not silently replace it with mv, database changes, API calls, or other non-UI mutations; explain the failure and ask before changing approach.
|
|
94
|
+
|
|
95
|
+
## Safety
|
|
96
|
+
|
|
97
|
+
- Read-only inspection is allowed when needed for the user's request.
|
|
98
|
+
- Treat the user's explicit request to click, drag, type, focus, or move something as authorization for that scoped action only.
|
|
99
|
+
- Before an irreversible or outward-facing final action—send, purchase, transfer, delete, publish, overwrite, or confirm—show the exact pending action and obtain explicit confirmation unless the user already explicitly requested that exact final action with the actual data.
|
|
100
|
+
- Never expose the local control server beyond loopback or reveal its bearer token.
|
|
101
|
+
- Stop after the requested outcome is verified; do not explore unrelated windows or content.`,
|
|
102
|
+
};
|
|
@@ -30,6 +30,7 @@ import { backupRestore } from './backup-restore.js';
|
|
|
30
30
|
import { browserControl } from './browser-control.js';
|
|
31
31
|
import { runTests } from './run-tests.js';
|
|
32
32
|
import { httpRequests } from './http-requests.js';
|
|
33
|
+
import { computerUse } from './computer-use.js';
|
|
33
34
|
/**
|
|
34
35
|
* All built-in skills that ship with Tide Commander
|
|
35
36
|
*/
|
|
@@ -59,6 +60,7 @@ export const BUILTIN_SKILLS = [
|
|
|
59
60
|
browserControl,
|
|
60
61
|
runTests,
|
|
61
62
|
httpRequests,
|
|
63
|
+
computerUse,
|
|
62
64
|
];
|
|
63
65
|
/**
|
|
64
66
|
* Get the ID for a built-in skill based on its slug
|
package/package.json
CHANGED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import{r as s,H as ya,J as Jt,K as da,L as ua,j as e,M as ma,N as Sa,u as qt,O as Aa,P as Ea,U as Ma,V as Ia,W as Ta,X as La,Y as Pa,Z as pa,_ as Qt,S as A,$ as ea,a0 as Xt,a1 as ta,a2 as At,a3 as _e,a4 as Ra,s as g,a5 as fa,m as ha,a6 as Da,z as aa,B as na,I as d,a7 as $a,q as za,a8 as Oa,a9 as ga,aa as xa,ab as ba,ac as _a,ad as Ba,ae as Fa,af as Wa,ag as Ha,ah as Ua,ai as Ga,aj as Va,ak as Xa,al as qa,am as Ya,an as Ka,ao as Za,ap as sa,C as Ja,aq as Qa,ar as ia,as as en,at as tn,au as an,av as nn,aw as sn,ax as ln,ay as rn,az as on,aA as cn,aB as dn,aC as un,aD as mn,aE as pn,aF as fn,aG as hn,aH as at,aI as gn,aJ as xn,aK as bn,aL as _n,aM as ft,aN as wn,aO as vn,aP as jn,aQ as Cn,aR as kn,aS as la,aT as Nn}from"./main-FwlHcqGj.js";import{g as yn}from"./area-logos-B6vGTcNz.js";import"./vendor-react--Eh9ivFN.js";import"./vendor-three-Chj50gSY.js";function Sn(c){const r=s.useRef(c);r.current=c,s.useEffect(()=>{if(!ya())return;let p=null,x=!1;return Jt.addListener("backButton",()=>{r.current()==="exit"&&Jt.exitApp()}).then(C=>{x?C.remove():p=C}),()=>{x=!0,p&&(p.remove(),p=null)}},[])}async function An(c){const r=da(),p=await fetch(`${ua()}/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 En(c){const r=da();await fetch(`${ua()}/api/agents/${c}/terminal`,{method:"DELETE",headers:{Authorization:`Bearer ${r}`}})}const ht=new Map;function Mn({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),An(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),En(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(ma,{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 Ht=new Map,In=6e4;function ra(c){return Number.isFinite(c)?Math.abs(c)>=1e3?c.toLocaleString(void 0,{maximumFractionDigits:0}):c.toLocaleString(void 0,{maximumFractionDigits:2}):String(c)}function Tn(c,r){var C,T,S;const p=[];if(!c.rateLimits)return p;if(c.provider==="claude"){const N=c,Q=[{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 Q)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 Ln({agentId:c,contextSummary:r}){const{t:p}=qt(["terminal","common"]),[x,C]=s.useState(()=>{var O;return((O=Ht.get(c))==null?void 0:O.snapshot)??null}),[T,S]=s.useState(!1),[N,Q]=s.useState(null),w=s.useRef(0);s.useEffect(()=>{const O=Ht.get(c);if(O&&Date.now()-O.fetchedAt<In){C(O.snapshot);return}const re=++w.current;S(!0),Q(null),Aa(c).then(P=>{re===w.current&&(Ht.set(c,{snapshot:P,fetchedAt:Date.now()}),C(P),S(!1))}).catch(P=>{re===w.current&&(Q(P.message||"Failed to load plan limits"),S(!1))})},[c]);const V=x?Tn(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})}),V.length>0?e.jsx("div",{className:"plan-limits-tooltip__gauges",children:V.map(({key:O,label:re,window:P})=>{const Ae=Math.max(0,Math.min(100,P.utilization)),oe=Ma(Ae),ce=typeof P.used=="number"&&typeof P.limit=="number"&&Number.isFinite(P.used)&&Number.isFinite(P.limit);return e.jsxs("div",{className:"plan-limits-tooltip__gauge",children:[e.jsxs("div",{className:"plan-limits-tooltip__gauge-head",children:[e.jsx("span",{className:"plan-limits-tooltip__gauge-label",children:re}),e.jsx("span",{className:"plan-limits-tooltip__gauge-percent",style:{color:oe},children:p("terminal:usage.percentUsed",{percent:Math.round(Ae)})})]}),e.jsx("div",{className:"plan-limits-tooltip__bar",children:e.jsx("div",{className:"plan-limits-tooltip__bar-fill",style:{width:`${Ae}%`,background:oe}})}),e.jsxs("div",{className:"plan-limits-tooltip__reset",children:[p("terminal:usage.resets",{time:Ea(P.resetsAt)}),ce&&e.jsx("span",{style:{marginLeft:8},children:p("terminal:usage.creditsUsed",{used:ra(P.used),limit:ra(P.limit)})})]})]},O)})}):x&&!T&&e.jsx("div",{className:"plan-limits-tooltip__muted",children:x.rateLimitsError?p("terminal:usage.limitsError",{message:x.rateLimitsError}):x.cliHint})]})}function Pn({agentId:c,disabled:r,contextSummary:p,children:x}){return e.jsx(Sa,{position:"top",maxWidth:320,disabled:r,className:"plan-limits-tooltip-wrapper",triggerStyle:{display:"inline-flex",alignItems:"center"},content:e.jsx(Ln,{agentId:c,contextSummary:p}),children:x})}const Rn=s.memo(function({className:r=""}){const{t:p}=qt(["common"]),[x,C]=Ia(),T=s.useRef(null),[S,N]=s.useState(null);s.useLayoutEffect(()=>{const w=T.current;if(!w)return;const V=w.querySelector(".view-mode-toggle__btn--active");V&&N({left:V.offsetLeft,width:V.offsetWidth})},[x]);const Q=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}}),Ta.map(w=>e.jsxs("button",{className:`view-mode-toggle__btn ${x===w?"view-mode-toggle__btn--active":""}`,onClick:()=>Q(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))]})}),Et=3,Mt=280,oa=320,Ut=240,ca=64,Dn=["simple","chat","advanced"],$n={simple:"Simple",chat:"Chat",advanced:"Advanced"},zn={simple:"○",chat:"◐",advanced:"◉"},On={simple:"Simple view — clean messages only",chat:"Chat view — assistant replies (no tool calls)",advanced:"Advanced view — everything including tools"},Gt="flat-clear-context",wa="tide:flat-embedded-panels";function va(){try{const c=localStorage.getItem(wa),r=c?JSON.parse(c):{};return r&&typeof r=="object"?r:{}}catch{return{}}}function Vt(c,r){try{const p=va();r?p[c]=r:delete p[c],localStorage.setItem(wa,JSON.stringify(p))}catch{}}function Bn(c){const r=c.split("/").filter(Boolean);return r.length===0?c:r.slice(-2).join("/")}function Fn(c){if(c.provider==="codex"){const T=c.codexModel||"gpt-5.6-luna",S=kn[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?la[S]:void 0;return{model:T,effort:N==null?void 0:N.label}}const r=c.model||"sonnet",p=Nn[r],x=c.effort,C=x?la[x]:void 0;return{model:(p==null?void 0:p.label)||r,effort:C==null?void 0:C.label}}function Wn(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 Hn=Qa.memo(function({agentId:r,terminalViewMode:p,onTerminalViewModeChange:x,inspectorOpen:C,onToggleInspector:T,onShowTaskBoard:S,onImageClick:N,onFileClick:Q,onBashClick:w,onViewMarkdown:V,onRequestClearSubordinates:O,keyboard:re,canNavigateBack:P,canNavigateForward:Ae,onNavigateBack:oe,onNavigateForward:ce,agentInfoOpen:ze,onToggleAgentInfo:gt,onHeaderContextMenu:we,onBuildingContextMenu:ve}){var Ct,ae;const f=ia(r),B=ha(),Ee=en(),Me=s.useRef(null),Ye=s.useRef(null),{displayedAgentId:Ie,fadingOut:It}=tn(r),xt=ia(Ie),Ke=!!Ee.interactiveMode&&((f==null?void 0:f.provider)??"claude")==="claude"&&!!(f!=null&&f.sessionId),[de,Ze]=s.useState(!1),[Oe,ue]=s.useState(!1),R=s.useCallback(()=>ue(!1),[]);pa("flat-chat-actions",Oe,R),s.useEffect(()=>{const a=()=>ue(o=>!o);return window.addEventListener("tide:toggle-chat-actions",a),()=>window.removeEventListener("tide:toggle-chat-actions",a)},[]),s.useEffect(()=>{Ze(!1),ue(!1)},[r]),s.useEffect(()=>{!Ke&&de&&Ze(!1)},[Ke,de]),s.useEffect(()=>{const a=Ye.current;if(!a)return;const o=u=>{u.button===3?(u.preventDefault(),u.stopPropagation(),oe()):u.button===4&&(u.preventDefault(),u.stopPropagation(),ce())},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)}},[oe,ce]),s.useEffect(()=>{const a=Ye.current;if(!a)return;let o=0,i=0,u=0;const U=250,Y=600,D=80,z=1.5,tt=se=>{let X=se instanceof HTMLElement?se:null;for(;X&&X!==a;){const t=window.getComputedStyle(X).overflowX;if((t==="auto"||t==="scroll")&&X.scrollWidth>X.clientWidth)return!0;X=X.parentElement}return!1},kt=se=>{const X=Date.now();if(X<u){se.preventDefault();return}if(Math.abs(se.deltaX)<=Math.abs(se.deltaY)*z){o=0;return}if(tt(se.target)){o=0;return}X-i>U&&(o=0),i=X,o+=se.deltaX,o<=-D?(o=0,u=X+Y,se.preventDefault(),oe()):o>=D&&(o=0,u=X+Y,se.preventDefault(),ce())};return a.addEventListener("wheel",kt,{passive:!1}),()=>a.removeEventListener("wheel",kt)},[oe,ce]);const me=fa(),nt=s.useMemo(()=>{if(!f)return null;const a=new Set,o=[];for(const i of me.values())i.archived||i.directories.length===0||i.assignedAgentIds.includes(r)&&(a.add(i.id),o.push(i));for(const i of me.values())i.archived||i.directories.length===0||a.has(i.id)||Wn({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,me]),{branches:bt,fetchRemote:Be,fetchingDirs:Te}=an(nt),pe=s.useMemo(()=>{var i;const a=g.getAreaForAgent(r);if(!a)return[];const o=[];for(const u of B.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,B]),je=s.useMemo(()=>{var i;const a=g.getAreaForAgent(r);if(!a)return[];const o=[];for(const u of B.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,B]),ee=s.useMemo(()=>{const a=g.getAreaForAgent(r);if(!a)return[];const o=[];for(const i of B.values())i.type==="database"&&i.database&&g.isPositionInArea(i.position,a)&&o.push({id:i.id,name:i.name});return o},[r,B]),Fe=nn(),ie=s.useMemo(()=>{const a=g.getAreaForAgent(r);if(!a)return[];const o=[];for(const i of B.values())if(i.type==="tests"&&g.isPositionInArea(i.position,a)){const u=!!i.folderPath&&Fe.some(U=>sn(U,i.folderPath));o.push({id:i.id,name:i.name,working:u})}return o},[r,B,Fe]),le=s.useMemo(()=>{const a=g.getAreaForAgent(r);if(!a)return[];const o=[];for(const i of B.values())i.type==="http"&&g.isPositionInArea(i.position,a)&&o.push({id:i.id,name:i.name});return o},[r,B]),[,Tt]=s.useReducer(a=>a+1,0),Ce=((Ct=Me.current)==null?void 0:Ct.search.searchMode)??!1,st=s.useCallback(()=>{var a;(a=Me.current)==null||a.search.toggleSearch(),Tt()},[]),Le=ln(),Pe=Le.isPending(Gt),[j,ne]=s.useState(null),te=j?B.get(j.buildingId):null,[We,Re]=s.useState(""),[He,Lt]=s.useState(()=>rn()),F=s.useMemo(()=>{var a;return((a=g.getAreaForAgent(r))==null?void 0:a.id)??null},[r,B]),Ue=s.useCallback((a,o)=>{Re(""),ne(i=>{const u=(i==null?void 0:i.buildingId)===o?null:{type:a,buildingId:o};return F&&Vt(F,u),u})},[F]),ke=s.useCallback(()=>{Re(""),ne(null),F&&Vt(F,null)},[F]);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:Pt,onResizeStart:Rt}=on(),{sidePanelWidth:Dt,handleSidePanelResizeStart:it}=cn(),[_,_t]=s.useState(()=>Xt(A.GIT_PANEL_OPEN,!1)),[De,fe]=s.useState(()=>Xt(A.BUILDINGS_PANEL_OPEN,!1)),[W,Ge]=s.useState(!1),lt=s.useCallback(()=>{Ge(a=>{const o=!a;return o&&dn.setEnabled(!0),o})},[]),$t=s.useCallback(()=>Ge(!1),[]),wt=s.useCallback(()=>{_t(a=>{const o=!a;return _e(A.GIT_PANEL_OPEN,o),o})},[]),vt=s.useCallback(()=>{fe(a=>{const o=!a;return _e(A.BUILDINGS_PANEL_OPEN,o),o})},[]),zt=s.useCallback(()=>{_t(!1),_e(A.GIT_PANEL_OPEN,!1)},[]),rt=s.useCallback(()=>{fe(!1),_e(A.BUILDINGS_PANEL_OPEN,!1)},[]),Ve=un(),he=s.useMemo(()=>({terminal:pe,"pm2-logs":je,database:ee,tests:ie,http:le}),[pe,je,ee,ie,le]);s.useEffect(()=>{if(!j)return;he[j.type].some(o=>o.id===j.buildingId)||(Re(""),ne(null))},[j,he]);const Ne=s.useRef(void 0);s.useEffect(()=>{var o;if(Ne.current===F)return;Ne.current=F;const a=F?va()[F]:void 0;Re(""),a&&((o=he[a.type])!=null&&o.some(i=>i.id===a.buildingId))?ne(a):ne(null)},[F,he]),s.useEffect(()=>{const a=o=>{var U;const i=o.detail;if(!(i!=null&&i.buildingId)||!(i!=null&&i.type)||!((U=he[i.type])!=null&&U.some(Y=>Y.id===i.buildingId)))return;i.handled=!0,Re("");const u={type:i.type,buildingId:i.buildingId};ne(u),F&&Vt(F,u)};return window.addEventListener("tide:dock-building-flat",a),()=>window.removeEventListener("tide:dock-building-flat",a)},[he,F]);const[Xe,H]=s.useState(!1),ge=s.useRef(null);if(s.useEffect(()=>{if(!Xe)return;const a=o=>{ge.current&&!ge.current.contains(o.target)&&H(!1)};return document.addEventListener("mousedown",a),()=>document.removeEventListener("mousedown",a)},[Xe]),!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 ye=f.contextStats,ot=!!ye,Je=ye?ye.totalTokens:f.contextUsed||0,ct=ye?ye.contextWindow:f.contextLimit||(f.provider==="grok"?5e5:2e5),Ot=ye?ye.usedPercent:Math.round(Je/ct*100),$e=Math.max(0,Math.min(100,Ot)),jt=Math.round($e*10)/10,xe=Math.round((100-$e)*10)/10,Qe=$e>=80?"#ff4a4a":$e>=60?"#ff9e4a":$e>=40?"#ffd700":"#4aff9e",et=(Je/1e3).toFixed(1),dt=(ct/1e3).toFixed(1),be=f.cwd,ut=be?Bn(be):null,Se=((ae=f.subordinateIds)==null?void 0:ae.length)||0,mt=Se>0;return e.jsxs("div",{ref:Ye,className:`flat-terminal-wrapper ${_||De||W?"flat-terminal-wrapper--with-side-panel":""} ${It?"pane-fading-out":""}`,style:{"--guake-side-panel-width":`min(${Dt}px, 70%)`},children:[e.jsxs("div",{className:"flat-terminal-wrapper__header",children:[e.jsxs("button",{type:"button",className:`flat-terminal-wrapper__header-main ${ze?"flat-terminal-wrapper__header-main--active":""}`,onClick:gt,onContextMenu:a=>{a.preventDefault(),a.stopPropagation(),we({x:a.clientX,y:a.clientY})},title:ze?"Hide agent info":"Show agent info","aria-pressed":ze,children:[e.jsx("span",{className:`flat-terminal-wrapper__header-avatar${f.status==="working"?" is-working":""}`,children:e.jsx(ga,{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:_a(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:ba(f.provider,"/"),alt:f.provider,className:"flat-terminal-wrapper__header-provider-icon",title:xa(f.provider)}),(()=>{const{model:a,effort:o}=Fn(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:[Dn.map(a=>e.jsxs("button",{type:"button",className:`flat-terminal-wrapper__view-mode-btn ${!de&&p===a?"flat-terminal-wrapper__view-mode-btn--active":""}`,onClick:()=>{Ze(!1),x(a)},title:On[a],"aria-pressed":!de&&p===a,children:[e.jsx("span",{className:"flat-terminal-wrapper__view-mode-icon","aria-hidden":"true",children:zn[a]}),e.jsx("span",{className:"flat-terminal-wrapper__view-mode-label",children:$n[a]})]},a)),Ke&&e.jsxs("button",{type:"button",className:`flat-terminal-wrapper__view-mode-btn ${de?"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":de,children:[e.jsx("span",{className:"flat-terminal-wrapper__view-mode-icon","aria-hidden":"true",children:e.jsx(d,{name:"terminal",size:13})}),e.jsx("span",{className:"flat-terminal-wrapper__view-mode-label",children:"Classic TUI"})]})]}),e.jsxs("div",{className:"flat-terminal-wrapper__actions",role:"group","aria-label":"Terminal actions",children:[e.jsx("button",{type:"button",className:"flat-terminal-wrapper__action-btn",onClick:oe,disabled:!P,title:"Back to previous agent","aria-label":"Back to previous agent",children:e.jsx(d,{name:"arrow-left",size:14})}),e.jsx("button",{type:"button",className:"flat-terminal-wrapper__action-btn",onClick:ce,disabled:!Ae,title:"Forward to next agent","aria-label":"Forward to next agent",children:e.jsx(d,{name:"arrow-right",size:14})}),e.jsx("button",{type:"button",className:`flat-terminal-wrapper__action-btn ${Ce?"flat-terminal-wrapper__action-btn--active":""}`,onClick:st,title:Ce?"Close search":"Search messages","aria-pressed":Ce,children:e.jsx(d,{name:Ce?"cross":"search",size:14})}),e.jsx("button",{type:"button",className:`flat-terminal-wrapper__action-btn flat-terminal-wrapper__action-btn--danger ${Pe?"flat-terminal-wrapper__action-btn--confirm":""}`,onClick:()=>Le.handleClick(Gt,()=>{var a;g.clearContext(r),(a=Me.current)==null||a.historyLoader.clearHistory()}),title:Pe?"Click again to confirm clear context":"Clear context",children:e.jsx(d,{name:Pe?"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 ${De?"flat-terminal-wrapper__action-btn--active":""}`,onClick:vt,title:De?"Hide buildings panel":"Show area buildings","aria-pressed":De,children:e.jsx(d,{name:"buildings",size:14})}),e.jsxs("div",{className:"flat-terminal-wrapper__more",ref:ge,children:[e.jsx("button",{type:"button",className:`flat-terminal-wrapper__action-btn ${Xe?"flat-terminal-wrapper__action-btn--active":""}`,onClick:()=>H(a=>!a),title:"More actions","aria-expanded":Xe,children:"⋮"}),Xe&&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 ${W?"flat-terminal-wrapper__more-item--active":""}`,onClick:()=>{lt(),H(!1)},title:W?"Hide Debug Panel":"Show Debug Panel",children:[e.jsx(d,{name:"bug",size:14}),e.jsx("span",{children:W?"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),H(!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"})]}),mt&&e.jsxs("button",{type:"button",role:"menuitem",className:"flat-terminal-wrapper__more-item flat-terminal-wrapper__more-item--danger",onClick:()=>{O(r,Se),H(!1)},children:[e.jsx(d,{name:"crown",size:14}),e.jsxs("span",{children:["Clear ",Se," subordinate",Se===1?"":"s"]})]}),e.jsx("div",{className:"flat-terminal-wrapper__more-divider"}),e.jsxs("button",{type:"button",role:"menuitem",className:"flat-terminal-wrapper__more-item flat-terminal-wrapper__more-item--danger",onClick:()=>{g.killAgent(r),H(!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})})]})]}),Oe&&e.jsxs("div",{className:"flat-chat-actions-sheet-root",role:"presentation",children:[e.jsx("div",{className:"flat-chat-actions-sheet__backdrop",onClick:R}),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:R,children:"Done"})]}),e.jsxs("div",{className:"flat-chat-actions-sheet__grid",children:[e.jsxs("button",{type:"button",role:"menuitem",className:`flat-chat-actions-sheet__item ${Ce?"is-active":""}`,onClick:()=>{st(),R()},children:[e.jsx(d,{name:Ce?"cross":"search",size:20}),e.jsx("span",{children:Ce?"Close search":"Search"})]}),e.jsxs("button",{type:"button",role:"menuitem",className:`flat-chat-actions-sheet__item ${_?"is-active":""}`,onClick:()=>{wt(),R()},children:[e.jsx(d,{name:"git-branch",size:20}),e.jsx("span",{children:"Git changes"})]}),e.jsxs("button",{type:"button",role:"menuitem",className:`flat-chat-actions-sheet__item ${De?"is-active":""}`,onClick:()=>{vt(),R()},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 ${W?"is-active":""}`,onClick:()=>{lt(),R()},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 ${Pe?"is-armed":""}`,onClick:()=>Le.handleClick(Gt,()=>{var a;g.clearContext(r),(a=Me.current)==null||a.historyLoader.clearHistory(),R()}),children:[e.jsx(d,{name:Pe?"question":"clear",size:18}),e.jsx("span",{children:Pe?"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),R()},children:[e.jsx(d,{name:"package",size:18}),e.jsx("span",{children:"Collapse context"})]}),mt&&e.jsxs("button",{type:"button",role:"menuitem",className:"flat-chat-actions-sheet__row flat-chat-actions-sheet__row--danger",onClick:()=>{O(r,Se),R()},children:[e.jsx(d,{name:"crown",size:18}),e.jsxs("span",{children:["Clear ",Se," subordinate",Se===1?"":"s"]})]}),e.jsxs("button",{type:"button",role:"menuitem",className:"flat-chat-actions-sheet__row flat-chat-actions-sheet__row--danger",onClick:()=>{g.killAgent(r),R()},children:[e.jsx(d,{name:"cross",size:18}),e.jsx("span",{children:"Remove agent"})]})]})]})]}),e.jsx(mn,{agent:f,onClick:S}),de&&Ke?e.jsx(Mn,{agentId:r}):Ie&&xt?e.jsx(pn,{ref:Me,agentId:Ie,agent:xt,viewMode:p,isOpen:!0,onImageClick:N,onFileClick:Q,onBashClick:w,onViewMarkdown:V,keyboard:re,hasModalOpen:!1},Ie):null,j&&te&&(()=>{var U,Y;const a=j.type,o={terminal:"terminal","pm2-logs":"scroll",database:"hard-drives",tests:"flask",http:"globe"},i=a==="terminal"&&!((U=te.terminalStatus)!=null&&U.url),u=!i;return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"guake-bottom-terminal-resize",onMouseDown:Rt,role:"separator","aria-orientation":"horizontal","aria-label":"Resize embedded panel"}),e.jsxs("div",{className:"flat-bottom-panel",role:"region","aria-label":`${te.name} panel`,style:{height:Pt},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:te.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:We,onChange:D=>Re(D.target.value),placeholder:"Filter logs","aria-label":`Filter logs for ${te.name}`,spellCheck:!1}),e.jsx("select",{className:"guake-bottom-terminal-retention",value:He===null?"unlimited":String(He),onChange:D=>{const z=D.target.value==="unlimited"?null:Number(D.target.value);Lt(z),hn(z)},"aria-label":`Max log retention for ${te.name}`,children:fn.map(D=>e.jsx("option",{value:D===null?"unlimited":String(D),children:D===null?"Unlimited":`${D.toLocaleString()} lines`},D===null?"unlimited":D))}),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:()=>{ke(),at(j.buildingId)},title:"Maximize — open as modal","aria-label":"Open as modal",children:e.jsx(d,{name:"fullscreen",size:12})}),e.jsx("button",{type:"button",className:"flat-bottom-panel__close",onClick:ke,title:"Close panel","aria-label":"Close panel",children:e.jsx(d,{name:"cross",size:12})})]})]}),e.jsx("div",{className:"flat-bottom-panel__body",children:a==="terminal"?(Y=te.terminalStatus)!=null&&Y.url?e.jsx(ma,{terminalUrl:te.terminalStatus.url,visible:!0}):e.jsx("div",{className:"flat-bottom-panel__placeholder",children:"Starting terminal..."}):a==="pm2-logs"?e.jsx(gn,{buildingId:j.buildingId,filterText:We,maxRetention:He}):a==="database"?e.jsx(xn,{building:te}):a==="tests"?e.jsx("div",{className:"tests-panel-host",children:e.jsx(bn,{building:te,autoFocusSearch:!1})}):e.jsx("div",{className:"http-requests-panel-host",children:e.jsx(_n,{building:te,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"})]}),be&&ut&&e.jsxs("span",{className:"flat-terminal-wrapper__cwd",title:`Open in file explorer: ${be}`,"aria-label":`Open ${be} in file explorer`,role:"button",tabIndex:0,onClick:()=>g.openFileExplorer(be),onKeyDown:a=>{(a.key==="Enter"||a.key===" ")&&(a.preventDefault(),g.openFileExplorer(be))},children:[e.jsx("span",{className:"flat-terminal-wrapper__cwd-icon",children:e.jsx(d,{name:"folder",size:12})}),e.jsx("span",{className:"flat-terminal-wrapper__cwd-text",children:ut})]}),nt&&nt.map(({areaId:a,areaName:o,dir:i})=>{const u=bt.get(i),U=Te.has(i),Y=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:Y}),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 ${U?"flat-terminal-wrapper__area-fetch--fetching":""}`,title:"Git fetch",onClick:D=>{D.stopPropagation(),Be(i)},children:e.jsx(d,{name:U?"hourglass":"download",size:12})})]})]},`${a}:${i}`)}),e.jsx(Pn,{agentId:r,disabled:((f==null?void 0:f.provider)??"claude")!=="claude"&&((f==null?void 0:f.provider)??"claude")!=="grok",contextSummary:ot?`Context: ${et}k / ${dt}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"?ot?`Context usage: ${et}k / ${dt}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:`${$e}%`,backgroundColor:Qe}})}),e.jsxs("span",{className:"flat-terminal-wrapper__context-tokens",style:{color:Qe},children:[et,"k/",dt,"k"]}),e.jsxs("span",{className:"flat-terminal-wrapper__context-free",children:["(",xe,"% free)"]}),!ot&&e.jsx("span",{className:"flat-terminal-wrapper__context-warning",title:"No context stats yet",children:e.jsx(d,{name:"warn",size:12})})]})}),e.jsx("div",{className:"flat-terminal-wrapper__statusbar-spacer","aria-hidden":"true"}),pe.length>0&&e.jsx("span",{className:"flat-terminal-wrapper__buildings",role:"group","aria-label":"Area terminals",children:pe.map(a=>{const o=(j==null?void 0:j.buildingId)===a.id;return e.jsx("button",{type:"button",className:`flat-terminal-wrapper__building-btn ${o?"flat-terminal-wrapper__building-btn--active":""} ${a.hasUrl?"":"flat-terminal-wrapper__building-btn--offline"}`,title:`${o?"Hide":"Show"} terminal: ${a.name}${a.hasUrl?"":" (starting...)"}`,onClick:()=>{if(o){ke();return}if(a.hasUrl&&ft(a.id)==="modal"){at(a.id);return}a.hasUrl||g.sendBuildingCommand(a.id,"start"),Ue("terminal",a.id)},onContextMenu:i=>{i.preventDefault(),i.stopPropagation(),ve(a.id,{x:i.clientX,y:i.clientY})},children:e.jsx(d,{name:"terminal",size:14})},a.id)})}),je.length>0&&e.jsx("span",{className:"flat-terminal-wrapper__buildings",role:"group","aria-label":"Area PM2 logs",children:je.map(a=>{const o=(j==null?void 0:j.buildingId)===a.id;return e.jsx("button",{type:"button",className:`flat-terminal-wrapper__building-btn ${o?"flat-terminal-wrapper__building-btn--active":""}`,title:`${o?"Hide":"Show"} logs: ${a.name}`,onClick:()=>{o?ke():ft(a.id)==="modal"?at(a.id):Ue("pm2-logs",a.id)},onContextMenu:i=>{i.preventDefault(),i.stopPropagation(),ve(a.id,{x:i.clientX,y:i.clientY})},children:e.jsx(d,{name:"scroll",size:14})},a.id)})}),ee.length>0&&e.jsx("span",{className:"flat-terminal-wrapper__buildings",role:"group","aria-label":"Area databases",children:ee.map(a=>{const o=(j==null?void 0:j.buildingId)===a.id;return e.jsx("button",{type:"button",className:`flat-terminal-wrapper__building-btn ${o?"flat-terminal-wrapper__building-btn--active":""}`,title:`${o?"Hide":"Show"} database: ${a.name}`,onClick:()=>{o?ke():ft(a.id)==="modal"?at(a.id):Ue("database",a.id)},onContextMenu:i=>{i.preventDefault(),i.stopPropagation(),ve(a.id,{x:i.clientX,y:i.clientY})},children:e.jsx(d,{name:"hard-drives",size:14})},a.id)})}),ie.length>0&&e.jsx("span",{className:"flat-terminal-wrapper__buildings",role:"group","aria-label":"Area tests",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":""} ${a.working?"flat-terminal-wrapper__building-btn--tests-working":""}`,title:a.working?`Running tests: ${a.name}`:`${o?"Hide":"Show"} tests: ${a.name}`,onClick:()=>{o?ke():ft(a.id)==="modal"?at(a.id):Ue("tests",a.id)},onContextMenu:i=>{i.preventDefault(),i.stopPropagation(),ve(a.id,{x:i.clientX,y:i.clientY})},children:e.jsx(d,{name:"flask",size:14})},a.id)})}),le.length>0&&e.jsx("span",{className:"flat-terminal-wrapper__buildings",role:"group","aria-label":"Area HTTP requests",children:le.map(a=>{const o=(j==null?void 0:j.buildingId)===a.id;return e.jsx("button",{type:"button",className:`flat-terminal-wrapper__building-btn ${o?"flat-terminal-wrapper__building-btn--active":""}`,title:`${o?"Hide":"Show"} HTTP requests: ${a.name}`,onClick:()=>{o?ke():ft(a.id)==="modal"?at(a.id):Ue("http",a.id)},onContextMenu:i=>{i.preventDefault(),i.stopPropagation(),ve(a.id,{x:i.clientX,y:i.clientY})},children:e.jsx(d,{name:"globe",size:14})},a.id)})}),e.jsx("div",{className:"flat-terminal-wrapper__theme",children:e.jsx(wn,{})})]}),_&&e.jsx(vn,{agentId:r,agents:Ve,onClose:zt,branchInfoMap:bt,fetchRemote:Be,fetchingDirs:Te,onResizeStart:a=>it(a,"right")}),De&&e.jsx(jn,{agentId:r,onClose:rt}),W&&e.jsx(Cn,{agentId:r,onClose:$t})]})}),Un={groups:[],gridCols:1,gridRows:1,positions:new Map};function Yn({onAgentClick:c,onBuildingClick:r,onBuildingDoubleClick:p,onBuildingPopup:x,onAreaContextMenu:C,onOpenSpawnModal:T,onOpenBossSpawnModal:S,onOpenAreaModal:N}){const{t:Q}=qt(["common"]),w=La(),V=Pa(),[O,re]=s.useState(null),[P,Ae]=s.useState(null),[oe,ce]=s.useState(null);pa("flatview-image-modal",O!==null,()=>re(null));const[ze,gt]=s.useState(null),[we,ve]=s.useState(null),[f,B]=s.useState(null),[Ee,Me]=s.useState(null),[Ye,Ie]=s.useState(!1),It=s.useCallback(()=>{Ie(t=>!t)},[]),xt=s.useCallback(()=>{Ie(!1)},[]),[Ke,de]=s.useState(()=>{const t=Qt(A.VIEW_MODE);return t==="simple"||t==="chat"||t==="advanced"?t:"simple"}),Ze=s.useCallback(t=>{de(t),ea(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")&&de(l)};return window.addEventListener("storage",t),()=>window.removeEventListener("storage",t)},[]);const[Oe,ue]=s.useState(()=>Xt(A.FLAT_INSPECTOR_OPEN,!1)),[R,me]=s.useState(!1),nt=s.useCallback(()=>me(t=>!t),[]),bt=s.useCallback(()=>me(!1),[]);s.useEffect(()=>{window.dispatchEvent(new CustomEvent("tide-flat-agents-drawer-state",{detail:{open:R}}))},[R]),s.useEffect(()=>{window.dispatchEvent(new CustomEvent("tide-flat-inspector-state",{detail:{open:Oe}}))},[Oe]),s.useEffect(()=>{const t=()=>me(k=>!k),n=()=>{ue(k=>{const E=!k;return _e(A.FLAT_INSPECTOR_OPEN,E),E})},l=()=>{me(!1),ue(!1),_e(A.FLAT_INSPECTOR_OPEN,!1)},h=()=>me(!1),b=()=>{ue(!1),_e(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 Be=s.useRef(null),Te=s.useRef(null),[pe,je]=s.useState(()=>{const t=ta(A.FLAT_MIDDLE_WIDTH,0);return t>=Mt?t:null}),[ee,Fe]=s.useState(()=>{const t=ta(A.FLAT_INSPECTOR_WIDTH,0);return t>=Ut?t:null}),ie=s.useCallback(t=>{if(typeof window>"u")return t;const n=ee!==null?Et+ee:0,l=window.innerWidth-ca-Et-oa-n;return Math.max(Mt,Math.min(Math.max(l,Mt),t))},[ee]),le=s.useCallback(t=>{var b;if(typeof window>"u")return t;const n=(b=Be.current)==null?void 0:b.querySelector(".flat-middle"),l=(n==null?void 0:n.getBoundingClientRect().width)??Mt,h=window.innerWidth-ca-l-Et-oa-Et;return Math.max(Ut,Math.min(Math.max(h,Ut),t))},[]);s.useEffect(()=>{if(pe===null&&ee===null)return;const t=()=>{je(n=>{if(n===null)return n;const l=ie(n);return l===n?n:l}),Fe(n=>{if(n===null)return n;const l=le(n);return l===n?n:l})};return window.addEventListener("resize",t),()=>window.removeEventListener("resize",t)},[pe,ee,ie,le]);const Tt=s.useCallback(t=>{var l;if(t.button!==0)return;const n=(l=Be.current)==null?void 0:l.querySelector(".flat-middle");n&&(t.currentTarget.setPointerCapture(t.pointerId),Te.current={kind:"middle",startX:t.clientX,startWidth:n.getBoundingClientRect().width,pointerId:t.pointerId},document.body.classList.add("flat-splitter-dragging"))},[]),Ce=s.useCallback(t=>{var l;if(t.button!==0)return;const n=(l=Be.current)==null?void 0:l.querySelector(".flat-inspector");n&&(t.currentTarget.setPointerCapture(t.pointerId),Te.current={kind:"inspector",startX:t.clientX,startWidth:n.getBoundingClientRect().width,pointerId:t.pointerId},document.body.classList.add("flat-splitter-dragging"))},[]),st=s.useCallback(t=>{const n=Te.current;if(!n||t.pointerId!==n.pointerId)return;const l=t.clientX-n.startX;n.kind==="middle"?je(ie(n.startWidth+l)):Fe(le(n.startWidth-l))},[ie,le]),Le=s.useCallback(t=>{const n=Te.current;if(!n||t.pointerId!==n.pointerId)return;try{t.currentTarget.releasePointerCapture(t.pointerId)}catch{}if(Te.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=ie(n.startWidth+h);je(b),At(A.FLAT_MIDDLE_WIDTH,b)}else{const b=le(n.startWidth-h);Fe(b),At(A.FLAT_INSPECTOR_WIDTH,b)}},[ie,le]),Pe=s.useCallback(()=>{je(null),At(A.FLAT_MIDDLE_WIDTH,0)},[]),j=s.useCallback(()=>{Fe(null),At(A.FLAT_INSPECTOR_WIDTH,0)},[]),[ne,te]=s.useState(()=>Qt(A.FLAT_INSPECTOR_VIEW)==="tracking"?"tracking":"agent"),We=s.useCallback(t=>{te(t),ea(A.FLAT_INSPECTOR_VIEW,t)},[]),Re=s.useCallback(()=>{ue(t=>{const n=!t;return _e(A.FLAT_INSPECTOR_OPEN,n),n})},[]),He=s.useCallback(()=>{ue(!1),_e(A.FLAT_INSPECTOR_OPEN,!1)},[]),Lt=s.useCallback(()=>{We("tracking"),ue(!0),_e(A.FLAT_INSPECTOR_OPEN,!0)},[We]),F=Ra(),Ue=s.useCallback((t,n)=>{re({url:t,name:n})},[]),ke=s.useCallback((t,n)=>{Ae({command:t,output:n,isLive:!1})},[]),Pt=s.useCallback((t,n)=>{var b;const l=V.size>0?Array.from(V)[0]:null,h=l?(b=g.getState().agents.get(l))==null?void 0:b.cwd:void 0;g.setFileViewerPath(t,n,h)},[V]),Rt=s.useCallback(t=>{ce(t)},[]),Dt=s.useCallback((t,n)=>{gt({agentId:t,count:n})},[]),it=s.useCallback(t=>{p?p(t):r(t)},[r,p]),_=s.useMemo(()=>V.size>0?Array.from(V)[0]:null,[V]),_t=s.useCallback(t=>{_&&ve({agentId:_,position:t})},[_]),De=s.useCallback((t,n)=>{B({buildingId:t,position:n})},[]);s.useEffect(()=>{Ie(!1)},[_]);const fe=s.useRef([]),W=s.useRef(-1),Ge=s.useRef(!1),lt=s.useRef(null),[$t,wt]=s.useState(!1),[vt,zt]=s.useState(!1),rt=s.useRef(!1),Ve=s.useRef(null),he=s.useRef(!1),Ne=s.useMemo(()=>new Set(w.map(t=>t.id)),[w]),Xe=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]),H=s.useCallback(()=>{const t=fe.current,n=W.current;wt(n>0),zt(n>=0&&n<t.length-1)},[]),ge=s.useCallback(t=>{const n=fe.current;if(n.length===0)return;let l=W.current+t;for(;l>=0&&l<n.length;){const h=n[l];if(Ne.has(h)){Ge.current=!0,W.current=l,H(),g.selectAgent(h);return}l+=t}},[Ne,H]),ye=s.useCallback(()=>ge(-1),[ge]),ot=s.useCallback(()=>ge(1),[ge]);Sn(s.useCallback(()=>{const t=fe.current,n=W.current;return t.length>0&&n>0?(ge(-1),"handled"):"exit"},[ge]));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(!_){rt.current=!1,Ve.current=null;return}if(!rt.current){Je(_,"replace"),rt.current=!0,Ve.current=_;return}if(he.current){he.current=!1,Ve.current=_;return}Ve.current!==_&&(Je(_,"push"),Ve.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"||!Ne.has(l)||l===_)return;he.current=!0,Ge.current=!0;const h=fe.current,b=h.lastIndexOf(l);b>=0?W.current=b:(h.push(l),W.current=h.length-1),H(),g.selectAgent(l)};return window.addEventListener("popstate",t),()=>window.removeEventListener("popstate",t)},[Ne,_,H]),s.useEffect(()=>{if(!_){fe.current=[],W.current=-1,H();return}if(lt.current=_,Ge.current){Ge.current=!1,H();return}const t=fe.current,n=W.current;if(n>=0&&t[n]===_){H();return}const l=n<t.length-1?t.slice(0,n+1):t.slice();l.push(_),l.length>100&&l.shift(),fe.current=l,W.current=l.length-1,H()},[_,H]);const ct=s.useCallback(t=>{c(t),me(!1)},[c]),Ot=_??"",$e=s.useCallback(()=>{},[]),jt=s.useCallback(t=>{ct(t)},[ct]),xe=Oe,[Qe,et]=s.useState(xe),[dt,be]=s.useState(xe);s.useEffect(()=>{if(xe){et(!0);return}be(!1);const t=setTimeout(()=>et(!1),240);return()=>clearTimeout(t)},[xe]),s.useEffect(()=>{if(!Qe||!xe)return;let t=0;const n=requestAnimationFrame(()=>{t=requestAnimationFrame(()=>be(!0))});return()=>{cancelAnimationFrame(n),cancelAnimationFrame(t)}},[Qe,xe]);const ut=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=lt.current;!h||!Ne.has(h)||(n.preventDefault(),g.selectAgent(h))};return document.addEventListener("keydown",t),()=>document.removeEventListener("keydown",t)},[_,Ne]);const[Se,mt]=s.useState(new Set),Ct=s.useCallback(t=>{mt(n=>{const l=new Set(n);return l.has(t)?l.delete(t):l.add(t),l})},[]),[ae,a]=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=>a(l.matches);return t.addEventListener("change",n),()=>t.removeEventListener("change",n)},[]);const[o,i]=s.useState(null),u=s.useCallback(t=>{i(n=>n===t?null:t)},[]),U=fa(),Y=ha(),[D]=Da(),z=s.useMemo(()=>{if(_)return Un;const t=new Map,n=[];for(const v of w){const I=g.getAreaForAgent(v.id);if(!aa((I==null?void 0:I.id)??null))continue;if(!I||I.archived){n.push(v);continue}const L=t.get(I.id);L?L.push(v):t.set(I.id,[v])}const l=new Map,h=[];for(const v of Y.values()){let I=!1;for(const L of U.values())if(!L.archived&&na(L.id)&&g.isPositionInArea(v.position,L)){const K=l.get(L.id);K?K.push(v):l.set(L.id,[v]),I=!0;break}!I&&aa(null)&&h.push(v)}const b=[];for(const[,v]of U){if(v.archived||!na(v.id))continue;const I=t.get(v.id),L=l.get(v.id)??[];(I&&I.length>0||L.length>0)&&b.push({area:v,agents:I??[],buildings:L})}(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 q=new Map;if(k.length>1){let v=1/0,I=-1/0,L=1/0,K=-1/0;for(const Z of k)v=Math.min(v,Z.area.center.x),I=Math.max(I,Z.area.center.x),L=Math.min(L,Z.area.center.z),K=Math.max(K,Z.area.center.z);const Nt=I-v||1,yt=K-L||1;if(k.length<=4){m=k.length,M=1;const Z=[...k].sort((J,Bt)=>J.area.center.x-Bt.area.center.x);for(let J=0;J<Z.length;J++)q.set(Z[J].area.id,{row:1,col:J+1})}else{const Z=[...k].sort((y,G)=>y.area.center.x-G.area.center.x),J=[];for(let y=1;y<Z.length;y++)J.push(Z[y].area.center.x-Z[y-1].area.center.x);const Bt=J.reduce((y,G)=>y+G,0)/J.length||1;let Yt=1;for(const y of J)y>Bt*1.3&&Yt++;m=Math.max(2,Math.min(Yt,k.length));const Ft=[...k].sort((y,G)=>y.area.center.z-G.area.center.z),St=[];for(let y=1;y<Ft.length;y++)St.push(Ft[y].area.center.z-Ft[y-1].area.center.z);const ja=St.reduce((y,G)=>y+G,0)/St.length||1;let Kt=1;for(const y of St)y>ja*1.3&&Kt++;M=Math.max(2,Math.min(Kt,k.length)),m=Math.max(m,Math.ceil(k.length/M)),M=Math.max(M,Math.ceil(k.length/m));const Ca=Nt/m,ka=yt/M,Wt=new Set;for(const y of k){let G=Math.min(m-1,Math.max(0,Math.floor((y.area.center.x-v)/Ca))),qe=Math.min(M-1,Math.max(0,Math.floor((y.area.center.z-L)/ka))),pt=`${qe},${G}`,Zt=0;const Na=M*m;for(;Wt.has(pt)&&Zt<Na;)G++,G>=m&&(G=0,qe=(qe+1)%M),pt=`${qe},${G}`,Zt++;Wt.has(pt)&&(qe=M,G=0,pt=`${qe},${G}`,M++),Wt.add(pt),q.set(y.area.id,{row:qe+1,col:G+1})}}}const $=v=>{v.sort((I,L)=>{var Nt,yt,Z,J;const K=(((Nt=I.position)==null?void 0:Nt.z)??0)-(((yt=L.position)==null?void 0:yt.z)??0);return K!==0?K:(((Z=I.position)==null?void 0:Z.x)??0)-(((J=L.position)==null?void 0:J.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:q}},[w,U,Y,D,_]),tt=s.useMemo(()=>{let t=0,n=0;for(const l of z.groups)t+=l.agents.length,n+=l.agents.filter(h=>h.status==="working").length;return{areaCount:z.groups.length,agentCount:t,workingCount:n}},[z]),kt=s.useMemo(()=>{if(!we)return[];const t=w.find(n=>n.id===we.agentId);return t?[{id:"edit-agent",label:"Edit Agent",icon:e.jsx(d,{name:"edit",size:14}),onClick:()=>{window.dispatchEvent(new CustomEvent("tide:open-agent-edit",{detail:{agentId:t.id}}))}},{id:"open-chat",label:"Open Chat",icon:e.jsx(d,{name:"chat",size:14}),onClick:()=>c(t.id)},{id:"clone-agent",label:"Clone Agent",icon:e.jsx(d,{name:"clipboard",size:14}),onClick:()=>g.cloneAgent(t.id)},{id:"fork-agent",label:"Fork Agent (with history)",icon:e.jsx(d,{name:"git-branch",size:14}),onClick:()=>g.forkAgent(t.id)},{id:"delete-agent",label:"Delete Agent",icon:e.jsx(d,{name:"trash",size:14}),danger:!0,onClick:()=>{Me({agentId:t.id,name:t.name})}}]:[]},[we,w,c]),se=s.useMemo(()=>{var k;if(!f)return[];const t=Y.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:()=>it(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,Y,it]),X=s.useCallback(t=>{const n=new Set(z.groups.map(l=>l.area.id));n.delete(t),mt(n),requestAnimationFrame(()=>{const l=ut.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"})})},[z]);return e.jsxs("div",{ref:Be,className:`flat-view ${xe?"flat-view--with-inspector":""} ${_?"flat-view--has-chat":""} ${R?"flat-view--mobile-sidebar-open":""}`,style:(()=>{if(pe===null&&ee===null)return;const t={};return pe!==null&&(t["--flat-middle-width"]=`${pe}px`),ee!==null&&(t["--flat-inspector-width"]=`${ee}px`),t})(),children:[R&&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($a,{activeAgentId:Ot,onClose:$e,onSelectAgent:jt,collapsedAreas:Se,onToggleArea:Ct,agentListRef:ut})})]}),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:Tt,onPointerMove:st,onPointerUp:Le,onPointerCancel:Le,onDoubleClick:Pe}),e.jsxs("div",{className:"flat-right",children:[e.jsxs("button",{type:"button",className:"flat-mobile-sidebar-toggle","aria-label":R?"Close agents sidebar":"Open agents sidebar","aria-expanded":R,onClick:nt,children:[e.jsx(d,{name:"list",size:18}),e.jsx("span",{className:"flat-mobile-sidebar-toggle__label",children:"Agents"})]}),_?e.jsx(Hn,{agentId:_,terminalViewMode:Ke,onTerminalViewModeChange:Ze,inspectorOpen:Oe,onToggleInspector:Re,onShowTaskBoard:Lt,onImageClick:Ue,onFileClick:Pt,onBashClick:ke,onViewMarkdown:Rt,onRequestClearSubordinates:Dt,keyboard:F,canNavigateBack:$t,canNavigateForward:vt,onNavigateBack:ye,onNavigateForward:ot,agentInfoOpen:Ye,onToggleAgentInfo:It,onHeaderContextMenu:_t,onBuildingContextMenu:De}):e.jsx("div",{className:"flat-chat flat-chat--empty",children:e.jsxs("div",{className:"flat-map",children:[e.jsxs("div",{className:"flat-map__header",children:[e.jsx("span",{className:"flat-map__title",children:"🗺️ Areas"}),e.jsx("span",{className:"flat-map__hint",children:"Click an area to focus it, or an agent to chat"}),e.jsxs("span",{className:"flat-map__stats",children:[e.jsxs("span",{children:[tt.areaCount," areas"]}),e.jsxs("span",{children:[tt.agentCount," agents"]}),tt.workingCount>0&&e.jsxs("span",{className:"flat-map__stats-working",children:[e.jsx("span",{className:"flat-map__stats-dot","aria-hidden":"true"}),tt.workingCount," working"]})]}),e.jsx(Rn,{className:"flat-map__view-mode"})]}),e.jsx("div",{className:"flat-map__grid",style:{gridTemplateColumns:ae?"repeat(2, minmax(0, 1fr))":`repeat(${z.gridCols}, 1fr)`},children:z.groups.length===0?e.jsx("div",{className:"flat-map__empty",children:e.jsx("span",{children:"No areas or agents yet"})}):(ae?[...z.groups].sort((n,l)=>{const h=z.positions.get(n.area.id),b=z.positions.get(l.area.id);return!h&&!b?0:h?b?h.row-b.row||h.col-b.col:-1:1}):z.groups).map(n=>{var E;const l=n.area.id,h=z.positions.get(l),b=ae&&o!==l,k=ae&&!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:ae||h==null?void 0:h.row,gridColumn:ae||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:()=>ae?u(l):X(l),title:ae?b?`Expand ${n.area.name}`:`Collapse ${n.area.name}`:`Focus ${n.area.name} in left panel`,"aria-expanded":ae?!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:yn(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]}),ae&&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",q=M?Xe.get(m.id):void 0,$=za(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)`,L=m.latestTodos&&m.latestTodos.length>0||q&&q.length>0;return e.jsx(Oa,{todos:m.latestTodos,subordinates:q,position:"top",children:e.jsxs("button",{type:"button",className:`flat-map-agent-chip ${m.status}`,onClick:()=>c(m.id),onContextMenu:K=>{K.preventDefault(),K.stopPropagation(),ve({agentId:m.id,position:{x:K.clientX,y:K.clientY}})},title:L?void 0:`${M?"Boss · ":""}Open chat with ${m.name}
|
|
2
|
-
${I}`,children:[e.jsx(ga,{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:ba(m.provider,"/"),alt:m.provider,className:"flat-map-agent-chip__provider-icon",title:xa(m.provider)}),e.jsx("span",{className:"flat-map-agent-chip__dot",style:{backgroundColor:_a(m.status)}}),m.latestTodos&&m.latestTodos.length>0&&e.jsx(Ba,{todos:m.latestTodos,maxDots:6}),M&&q&&q.length>0&&e.jsx(Fa,{subordinates:q,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:q=>{q.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 q;const M=(q=Wa[m.type])==null?void 0:q.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 it(m.id)},onContextMenu:$=>{$.preventDefault(),$.stopPropagation(),B({buildingId:m.id,position:{x:$.clientX,y:$.clientY}})},title:`${m.name} · ${m.type} · ${m.status}`,children:[e.jsx(d,{name:Ha(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:Ua(m.status)}})]},m.id)})})]},l)})})]})})]}),xe&&e.jsx("div",{className:"flat-splitter flat-splitter--inspector",role:"separator","aria-orientation":"vertical","aria-label":"Resize inspector panel",title:"Drag to resize · Double-click to reset",onPointerDown:Ce,onPointerMove:st,onPointerUp:Le,onPointerCancel:Le,onDoubleClick:j}),Qe&&e.jsxs("aside",{className:`flat-inspector ${dt?"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":ne==="agent",className:`flat-inspector__tab ${ne==="agent"?"flat-inspector__tab--active":""}`,onClick:()=>We("agent"),children:"Agent"}),e.jsx("button",{type:"button",role:"tab","aria-selected":ne==="tracking",className:`flat-inspector__tab ${ne==="tracking"?"flat-inspector__tab--active":""}`,onClick:()=>We("tracking"),children:"Tracking"})]}),e.jsx("button",{type:"button",className:"flat-inspector__close",onClick:He,title:"Close inspector","aria-label":"Close inspector",children:"✕"})]}),e.jsx("div",{className:"flat-inspector__body",children:ne==="tracking"?e.jsx(Ga,{activeAgentId:_??"",onSelectAgent:t=>{c(t),window.innerWidth<=768&&He()}}):(()=>{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(Va,{agent:t,onFocusAgent:n=>{c(n),window.innerWidth<=768&&He()},onKillAgent:n=>g.killAgent(n)}):e.jsx("div",{className:"flat-inspector__empty",children:e.jsx("span",{children:"Agent not found"})})})()})]}),O&&e.jsx(Xa,{url:O.url,name:O.name,onClose:()=>re(null)}),P&&e.jsx(qa,{state:P,onClose:()=>Ae(null)}),e.jsx(Ya,{agent:_?w.find(t=>t.id===_)??null:null,content:oe,onClose:()=>ce(null)}),ze&&e.jsx(Ka,{action:"clear-subordinates",selectedAgentId:ze.agentId,subordinateCount:ze.count,onClose:()=>gt(null),onClearHistory:()=>{}}),e.jsx(Za,{agent:_?w.find(t=>t.id===_)??null:null,isOpen:Ye&&!!_,onClose:xt}),e.jsx(sa,{isOpen:we!==null,position:(we==null?void 0:we.position)??{x:0,y:0},worldPosition:{x:0,z:0},actions:kt,onClose:()=>ve(null)}),e.jsx(sa,{isOpen:f!==null,position:(f==null?void 0:f.position)??{x:0,y:0},worldPosition:{x:0,z:0},actions:se,onClose:()=>B(null)}),e.jsx(Ja,{isOpen:Ee!==null,title:Q("common:confirm.removeAgentTitle"),message:Q("common:confirm.removeAgentMessage",{name:(Ee==null?void 0:Ee.name)??""}),confirmLabel:Q("common:buttons.remove"),cancelLabel:Q("common:buttons.cancel"),variant:"danger",onConfirm:()=>{Ee&&g.removeAgentFromServer(Ee.agentId)},onClose:()=>Me(null)})]})}export{Yn as FlatView};
|