tide-commander 1.223.0 → 1.224.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +22 -0
- package/dist/assets/{AudioPlayer-CjX0NnDG.js → AudioPlayer-CS32DiiF.js} +1 -1
- package/dist/assets/{BossLogsModal-neHd1jxq.js → BossLogsModal-CuiASPjO.js} +1 -1
- package/dist/assets/{BossSpawnModal-Bb5bU6M8.js → BossSpawnModal-BFG6WMHP.js} +1 -1
- package/dist/assets/{ControlsModal-BEKZK4fK.js → ControlsModal-suKdgBAJ.js} +1 -1
- package/dist/assets/{DockerLogsModal-C1ZIanzC.js → DockerLogsModal-CIY242F2.js} +1 -1
- package/dist/assets/{EmbeddedEditor-DWgHQwj1.js → EmbeddedEditor-Bu-NinV4.js} +1 -1
- package/dist/assets/{FcStdViewer-CvFBDWIv.js → FcStdViewer-B_ZUSI2J.js} +1 -1
- package/dist/assets/{GcodeViewer-CcVaZxR7.js → GcodeViewer-BUz7zxIl.js} +1 -1
- package/dist/assets/{GlbViewer-kF1-oHLk.js → GlbViewer-CNR1g2NS.js} +1 -1
- package/dist/assets/{GmailOAuthSetup-CeMu3b9k.js → GmailOAuthSetup-Dj81j7pf.js} +1 -1
- package/dist/assets/{GoogleOAuthSetup-CW7ov3JO.js → GoogleOAuthSetup-vbnnwez5.js} +1 -1
- package/dist/assets/{IframeModal-DhbsVRJn.js → IframeModal-BCC6ZdKx.js} +1 -1
- package/dist/assets/{IntegrationsPanel-DKMStfuq.js → IntegrationsPanel-CY3lUNI1.js} +2 -2
- package/dist/assets/{LogViewerModal-Dk3KmPRY.js → LogViewerModal-CW81dfO6.js} +1 -1
- package/dist/assets/{MonitoringModal-BSYKhukp.js → MonitoringModal-CwS3yQ7M.js} +1 -1
- package/dist/assets/{PM2LogsModal-CJ8Cn9t8.js → PM2LogsModal-MvDxO2TF.js} +1 -1
- package/dist/assets/{PluginsPanel-DQv9Xrsn.js → PluginsPanel-Br7cw4J1.js} +1 -1
- package/dist/assets/{RestoreArchivedAreaModal-wn8YPSY7.js → RestoreArchivedAreaModal-DEuz0Tmk.js} +1 -1
- package/dist/assets/{Scene2DCanvas-DBs2O0PC.js → Scene2DCanvas-46rDN8dN.js} +1 -1
- package/dist/assets/{SceneManager-WRjeyaRk.js → SceneManager-CDr5_lQH.js} +1 -1
- package/dist/assets/{SkillsPanel-DimvGKrN.js → SkillsPanel-DIeRNRtF.js} +1 -1
- package/dist/assets/{SlackMultiInstanceSetup-cTN3v2At.js → SlackMultiInstanceSetup-C8U0OpPi.js} +1 -1
- package/dist/assets/{SpawnModal-BgdP5LBE.js → SpawnModal-BMmCif0b.js} +1 -1
- package/dist/assets/{StatisticsModal-jyA2UpM-.js → StatisticsModal-BBcwwM9a.js} +1 -1
- package/dist/assets/{StlViewer-BTQCSdFg.js → StlViewer-Y6Q9LV4g.js} +1 -1
- package/dist/assets/{SubordinateAssignmentModal-BJCTarDM.js → SubordinateAssignmentModal-CxBrkrsy.js} +1 -1
- package/dist/assets/{ThreeAreaSelector-Bz_OPTco.js → ThreeAreaSelector-jdePYE0s.js} +1 -1
- package/dist/assets/{ThreeViewShortcuts-aC84L8xB.js → ThreeViewShortcuts-fQ1LZj-k.js} +1 -1
- package/dist/assets/{TriggerManagerPanel-CRy8hS_2.js → TriggerManagerPanel-DFijjhCA.js} +1 -1
- package/dist/assets/{VideoPlayer-BB4cSwPZ.js → VideoPlayer--W7gA51W.js} +1 -1
- package/dist/assets/{WorkflowEditorPanel-JG3EfQ-c.js → WorkflowEditorPanel-B5AhOJD7.js} +1 -1
- package/dist/assets/{abnfDiagram-VRR7QNED-BIymdJ82.js → abnfDiagram-VRR7QNED-BaTbSF7k.js} +1 -1
- package/dist/assets/{arc--DARpxJq.js → arc-BST2bg1n.js} +1 -1
- package/dist/assets/{architectureDiagram-ZJ3FMSHR-Ur0IHTuT.js → architectureDiagram-ZJ3FMSHR-Cg4xwkXg.js} +1 -1
- package/dist/assets/{area-logos-CVOcCaKt.js → area-logos-BFSIooyB.js} +1 -1
- package/dist/assets/{blockDiagram-677ZJIJ3-CmNjZc5F.js → blockDiagram-677ZJIJ3-Cv21hNY1.js} +1 -1
- package/dist/assets/{c4Diagram-LMCZKHZV-B4GHw6__.js → c4Diagram-LMCZKHZV-DRMk82uY.js} +1 -1
- package/dist/assets/channel-oEvwVeL5.js +1 -0
- package/dist/assets/{chunk-2Q5K7J3B-BBErXFBl.js → chunk-2Q5K7J3B-Cino9QTV.js} +1 -1
- package/dist/assets/{chunk-32BRIVSS-C2qUOlfT.js → chunk-32BRIVSS-K9CkGCF3.js} +1 -1
- package/dist/assets/{chunk-5VM5RSS4-r9xckJVE.js → chunk-5VM5RSS4-wSG2aCSB.js} +1 -1
- package/dist/assets/{chunk-EX3LRPZG-DYUFM6Kx.js → chunk-EX3LRPZG-DiP8GRRE.js} +1 -1
- package/dist/assets/{chunk-JWPE2WC7-BUC08AKL.js → chunk-JWPE2WC7-C2T4HdGo.js} +1 -1
- package/dist/assets/{chunk-MOJQB5TN-C0yNMKSS.js → chunk-MOJQB5TN-K6VUUce6.js} +1 -1
- package/dist/assets/{chunk-RYQCIY6F-DF0DipHM.js → chunk-RYQCIY6F-CwUKwfrO.js} +1 -1
- package/dist/assets/{chunk-V7JOEXUC-B48QcHmS.js → chunk-V7JOEXUC-Do7m7In-.js} +1 -1
- package/dist/assets/{chunk-VR4S4FIN-Cah567yW.js → chunk-VR4S4FIN-C3sjuCSc.js} +1 -1
- package/dist/assets/{chunk-XXDRQBXY-Cyo-LR80.js → chunk-XXDRQBXY-aWtL9GIN.js} +1 -1
- package/dist/assets/classDiagram-OUVF2IWQ-3O7V3aga.js +1 -0
- package/dist/assets/classDiagram-v2-EOCWNBFH-3O7V3aga.js +1 -0
- package/dist/assets/{cose-bilkent-JH36ORCC-BoyB947B.js → cose-bilkent-JH36ORCC-DPZ-w5xz.js} +1 -1
- package/dist/assets/{cynefin-VYW2F7L2-DFPaQ9Zf.js → cynefin-VYW2F7L2-BIsWEfjH.js} +1 -1
- package/dist/assets/{cynefinDiagram-TSTJHNR4-B2MZ8ySp.js → cynefinDiagram-TSTJHNR4-DQc1SjqU.js} +1 -1
- package/dist/assets/{dagre-VKFMJZFB-NwVkWGfv.js → dagre-VKFMJZFB-CSQALpAg.js} +1 -1
- package/dist/assets/{default-agent-skills-B6BhakPb.js → default-agent-skills-hW2YTtT1.js} +1 -1
- package/dist/assets/{diagram-FQU43EPY-5f6e6NP-.js → diagram-FQU43EPY-Co8RC7NC.js} +1 -1
- package/dist/assets/{diagram-G47NLZAW-C-OBe1ja.js → diagram-G47NLZAW-C1h1rqbG.js} +1 -1
- package/dist/assets/{diagram-NH7WQ7WH-GLMOuSN-.js → diagram-NH7WQ7WH-DzStYMvA.js} +1 -1
- package/dist/assets/{diagram-OA4YK3LP-BwhAYhbr.js → diagram-OA4YK3LP-Bnga2eI1.js} +1 -1
- package/dist/assets/{diagram-WEI45ONY-n4IRaNvB.js → diagram-WEI45ONY-DtML0qBL.js} +1 -1
- package/dist/assets/{ebnfDiagram-CCIWWBDH-BRSu16Iy.js → ebnfDiagram-CCIWWBDH-srK1jz3r.js} +1 -1
- package/dist/assets/{erDiagram-Q63AITRT-qsCMupOZ.js → erDiagram-Q63AITRT-BYnoRg9S.js} +1 -1
- package/dist/assets/{flowDiagram-23GEKE2U-C8Jfgc5Q.js → flowDiagram-23GEKE2U-COT9xZWU.js} +1 -1
- package/dist/assets/{ganttDiagram-NO4QXBWP-CT9Xx98f.js → ganttDiagram-NO4QXBWP-DNHD_H8t.js} +1 -1
- package/dist/assets/{gitGraphDiagram-IHSO6WYX-Coi5KukC.js → gitGraphDiagram-IHSO6WYX-BWLh25rZ.js} +1 -1
- package/dist/assets/{index-CZItdiJG.js → index-BDMDSPRK.js} +1 -1
- package/dist/assets/{index-BP5FFBEx.js → index-BlH_HQ25.js} +1 -1
- package/dist/assets/{index-vi6NXwpa.js → index-BxVyMj4V.js} +1 -1
- package/dist/assets/{index-XRPTKib1.js → index-C2-8cspl.js} +1 -1
- package/dist/assets/{index-CIu--mJr.js → index-DZ7ozYBG.js} +1 -1
- package/dist/assets/{index-Xt8XgRzK.js → index-Dvs3ntB2.js} +1 -1
- package/dist/assets/{index-DUDeXZ0I.js → index-FV2om2lX.js} +2 -2
- package/dist/assets/index-NEWtG02D.js +1 -0
- package/dist/assets/{index-GbqO5CFI.js → index-cGbqyuV8.js} +3 -3
- package/dist/assets/{infoDiagram-FWYZ7A6U-DwRsLIbg.js → infoDiagram-FWYZ7A6U-CwYFYRFg.js} +1 -1
- package/dist/assets/{ishikawaDiagram-FXEZZL3T-BJHzTkEA.js → ishikawaDiagram-FXEZZL3T-BwkPIKzg.js} +1 -1
- package/dist/assets/{journeyDiagram-5HDEW3XC-DSbYpqKW.js → journeyDiagram-5HDEW3XC-C9arAZ8y.js} +1 -1
- package/dist/assets/{kanban-definition-HUTT4EX6-095PTicj.js → kanban-definition-HUTT4EX6-6wTmayoj.js} +1 -1
- package/dist/assets/{linear-CfqVr0Ja.js → linear-Dj4zYq3h.js} +1 -1
- package/dist/assets/main-sBSI_4k0.js +372 -0
- package/dist/assets/{mermaid.core-Cd-X-VQG.js → mermaid.core-Bq0L11_-.js} +4 -4
- package/dist/assets/{mindmap-definition-LN4V7U3C-BKaq73lx.js → mindmap-definition-LN4V7U3C-CxIXLa8F.js} +1 -1
- package/dist/assets/{pegDiagram-2B236MQR-D8G4w9gD.js → pegDiagram-2B236MQR-CrPAdYQD.js} +1 -1
- package/dist/assets/{pieDiagram-ENE6RG2P-COmE0H9d.js → pieDiagram-ENE6RG2P-D3EP1YJI.js} +1 -1
- package/dist/assets/{quadrantDiagram-ABIIQ3AL-ZN6VYk1I.js → quadrantDiagram-ABIIQ3AL-CWkbCwdX.js} +1 -1
- package/dist/assets/{railroadDiagram-RFXS5EU6-BE9p17T6.js → railroadDiagram-RFXS5EU6-z0g5DBHp.js} +1 -1
- package/dist/assets/{requirementDiagram-TGXJPOKE-YeG4gM4-.js → requirementDiagram-TGXJPOKE-CiMiX_JJ.js} +1 -1
- package/dist/assets/{sankeyDiagram-HTMAVEWB-x0VZ9b3K.js → sankeyDiagram-HTMAVEWB-BmOS9QdD.js} +1 -1
- package/dist/assets/{sequenceDiagram-DBY2YBRQ-D1kkFLHj.js → sequenceDiagram-DBY2YBRQ-C7RoHZtD.js} +1 -1
- package/dist/assets/{sizeCapture-X5ZJPWSS-CCOED7Lw.js → sizeCapture-X5ZJPWSS-Caj9tBBH.js} +1 -1
- package/dist/assets/{stateDiagram-2N3HPSRC-BVqCnbwf.js → stateDiagram-2N3HPSRC-DWIQWBNS.js} +1 -1
- package/dist/assets/stateDiagram-v2-6OUMAXLB-Q7zbcB30.js +1 -0
- package/dist/assets/{swimlanes-5IMT3BWC-BASSCXvz.js → swimlanes-5IMT3BWC-Cb4faLOv.js} +2 -2
- package/dist/assets/swimlanesDiagram-G3AALYLV-DZKxmgt5.js +8 -0
- package/dist/assets/{timeline-definition-FHXFAJF6-uL1WYIPG.js → timeline-definition-FHXFAJF6-CVizZxxU.js} +1 -1
- package/dist/assets/{vennDiagram-L72KCM5P-DtbBUscM.js → vennDiagram-L72KCM5P-DadCc6f6.js} +1 -1
- package/dist/assets/{wardleyDiagram-EHGQE667-TvRREmtU.js → wardleyDiagram-EHGQE667-l7-xE64R.js} +1 -1
- package/dist/assets/{web-DEnNRcGv.js → web-CSVD8nk7.js} +1 -1
- package/dist/assets/{web-D7rM8t54.js → web-CnZQAYa5.js} +1 -1
- package/dist/assets/{web-DbGcg2p6.js → web-DIdAF8p4.js} +1 -1
- package/dist/assets/{xychartDiagram-FW5EYKEG-CdXxeP-q.js → xychartDiagram-FW5EYKEG-CFZA5bRS.js} +1 -1
- package/dist/build-info.json +1 -1
- package/dist/index.html +1 -1
- package/dist/src/packages/server/claude/backend.js +21 -0
- package/dist/src/packages/server/claude/interactive/interactive-backend-args.js +6 -0
- package/dist/src/packages/server/claude/runner.js +73 -6
- package/dist/src/packages/server/claude/session-recovery.js +56 -0
- package/dist/src/packages/server/data/builtin-skills/boss-instructions.js +1 -1
- package/dist/src/packages/server/routes/notifications.js +11 -53
- package/dist/src/packages/server/services/agent-notifications.js +67 -0
- package/dist/src/packages/server/services/llm-matcher-service.js +4 -1
- package/dist/src/packages/server/services/runtime-events.js +72 -0
- package/dist/src/packages/shared/agent-types.js +8 -2
- package/dist/src/packages/shared/model-freshness.js +9 -7
- package/package.json +1 -1
- package/dist/assets/channel-DE7sZiOX.js +0 -1
- package/dist/assets/classDiagram-OUVF2IWQ-DEZtwip7.js +0 -1
- package/dist/assets/classDiagram-v2-EOCWNBFH-DEZtwip7.js +0 -1
- package/dist/assets/index-dwe7nfIh.js +0 -1
- package/dist/assets/main-C661hDwF.js +0 -372
- package/dist/assets/stateDiagram-v2-6OUMAXLB-DKzYyGyb.js +0 -1
- package/dist/assets/swimlanesDiagram-G3AALYLV-1ocner1k.js +0 -8
|
@@ -4,23 +4,20 @@
|
|
|
4
4
|
*
|
|
5
5
|
* Agents can send notifications to users via HTTP POST requests.
|
|
6
6
|
* This allows agents to notify users of important events without
|
|
7
|
-
* requiring WebSocket communication.
|
|
7
|
+
* requiring WebSocket communication. The fan-out itself lives in
|
|
8
|
+
* services/agent-notifications.ts so the server can raise the same
|
|
9
|
+
* notifications on its own (lost sessions, crashes).
|
|
8
10
|
*/
|
|
9
11
|
import { Router } from 'express';
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import { publishNotification } from '../integrations/whatsapp/whatsapp-notification-publisher.js';
|
|
13
|
-
import { sendAgentPush } from '../services/push-service.js';
|
|
12
|
+
import { createLogger } from '../utils/index.js';
|
|
13
|
+
import { notifyAgent, setAgentNotificationBroadcast } from '../services/agent-notifications.js';
|
|
14
14
|
const log = createLogger('Notifications');
|
|
15
15
|
const router = Router();
|
|
16
|
-
// Store for broadcasting notifications via WebSocket
|
|
17
|
-
// This will be set by the WebSocket handler
|
|
18
|
-
let broadcastFn = null;
|
|
19
16
|
/**
|
|
20
17
|
* Set the broadcast function for sending notifications to all clients
|
|
21
18
|
*/
|
|
22
19
|
export function setBroadcast(fn) {
|
|
23
|
-
|
|
20
|
+
setAgentNotificationBroadcast(fn);
|
|
24
21
|
}
|
|
25
22
|
/**
|
|
26
23
|
* POST /api/notify - Send a notification from an agent
|
|
@@ -38,49 +35,20 @@ export function setBroadcast(fn) {
|
|
|
38
35
|
router.post('/', (req, res) => {
|
|
39
36
|
try {
|
|
40
37
|
const { agentId, title, message, iconUrl, imageUrl } = req.body;
|
|
41
|
-
// Validate required fields
|
|
42
38
|
if (!agentId || !title || !message) {
|
|
43
39
|
res.status(400).json({
|
|
44
40
|
error: 'Missing required fields: agentId, title, message'
|
|
45
41
|
});
|
|
46
42
|
return;
|
|
47
43
|
}
|
|
48
|
-
|
|
49
|
-
const agent = agentService.getAgent(agentId);
|
|
50
|
-
if (!agent) {
|
|
51
|
-
res.status(404).json({ error: `Agent not found: ${agentId}` });
|
|
52
|
-
return;
|
|
53
|
-
}
|
|
54
|
-
// Create the notification
|
|
55
|
-
const notification = {
|
|
56
|
-
id: generateId(),
|
|
57
|
-
agentId: agent.id,
|
|
58
|
-
agentName: agent.name,
|
|
59
|
-
agentClass: agent.class,
|
|
60
|
-
title,
|
|
61
|
-
message,
|
|
62
|
-
timestamp: Date.now(),
|
|
44
|
+
const notification = notifyAgent(agentId, title, message, {
|
|
63
45
|
...(typeof iconUrl === 'string' && iconUrl ? { iconUrl } : {}),
|
|
64
46
|
...(typeof imageUrl === 'string' && imageUrl ? { imageUrl } : {}),
|
|
65
|
-
};
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
// Broadcast to all connected clients
|
|
70
|
-
if (broadcastFn) {
|
|
71
|
-
broadcastFn({
|
|
72
|
-
type: 'agent_notification',
|
|
73
|
-
payload: notification,
|
|
74
|
-
});
|
|
75
|
-
}
|
|
76
|
-
else {
|
|
77
|
-
log.warn('Broadcast function not set - notification not sent to clients');
|
|
47
|
+
});
|
|
48
|
+
if (!notification) {
|
|
49
|
+
res.status(404).json({ error: `Agent not found: ${agentId}` });
|
|
50
|
+
return;
|
|
78
51
|
}
|
|
79
|
-
void publishNotification(classifyNotificationEventType(title), `${agent.name}: ${title}`, message).catch((err) => log.warn(`WhatsApp publish skipped: ${err}`));
|
|
80
|
-
// Native push: reaches phones whose app is closed (and whose battery-hungry
|
|
81
|
-
// WebSocket foreground service is therefore off). No-op until a Firebase
|
|
82
|
-
// service account is installed — see services/push-service.ts.
|
|
83
|
-
void sendAgentPush(notification).catch((err) => log.warn(`Push delivery skipped: ${err}`));
|
|
84
52
|
res.status(200).json({
|
|
85
53
|
success: true,
|
|
86
54
|
notification
|
|
@@ -91,14 +59,4 @@ router.post('/', (req, res) => {
|
|
|
91
59
|
res.status(500).json({ error: err.message });
|
|
92
60
|
}
|
|
93
61
|
});
|
|
94
|
-
function classifyNotificationEventType(title) {
|
|
95
|
-
const t = title.toLowerCase();
|
|
96
|
-
if (t.includes('plan ready') || t.includes('plan'))
|
|
97
|
-
return 'planReady';
|
|
98
|
-
if (t.includes('error') || t.includes('failed') || t.includes('blocked'))
|
|
99
|
-
return 'errors';
|
|
100
|
-
if (t.includes('task complete') || t.includes('completed') || t.includes('done'))
|
|
101
|
-
return 'taskComplete';
|
|
102
|
-
return 'messages';
|
|
103
|
-
}
|
|
104
62
|
export default router;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Agent notifications raised by the server itself (not by an agent's curl to
|
|
3
|
+
* POST /api/notify): same payload, same fan-out — WebSocket broadcast to every
|
|
4
|
+
* client, WhatsApp publisher, native push. The HTTP route delegates here so
|
|
5
|
+
* both paths stay identical.
|
|
6
|
+
*
|
|
7
|
+
* First server-side user (2026-10-27): a resumed Claude session whose
|
|
8
|
+
* transcript was deleted. Before that the agent went idle in silence.
|
|
9
|
+
*/
|
|
10
|
+
import * as agentService from './agent-service.js';
|
|
11
|
+
import { createLogger, generateId } from '../utils/index.js';
|
|
12
|
+
import { publishNotification } from '../integrations/whatsapp/whatsapp-notification-publisher.js';
|
|
13
|
+
import { sendAgentPush } from './push-service.js';
|
|
14
|
+
const log = createLogger('AgentNotifications');
|
|
15
|
+
let broadcastFn = null;
|
|
16
|
+
/** Set once by the websocket layer; until then notifications are only logged. */
|
|
17
|
+
export function setAgentNotificationBroadcast(fn) {
|
|
18
|
+
broadcastFn = fn;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Build, broadcast and fan out a notification on behalf of an agent. Returns
|
|
22
|
+
* null when the agent does not exist (nothing was sent).
|
|
23
|
+
*/
|
|
24
|
+
export function notifyAgent(agentId, title, message, opts = {}) {
|
|
25
|
+
const agent = agentService.getAgent(agentId);
|
|
26
|
+
if (!agent) {
|
|
27
|
+
log.warn(`Notification for unknown agent ${agentId} dropped: "${title}"`);
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
const notification = {
|
|
31
|
+
id: generateId(),
|
|
32
|
+
agentId: agent.id,
|
|
33
|
+
agentName: agent.name,
|
|
34
|
+
agentClass: agent.class,
|
|
35
|
+
title,
|
|
36
|
+
message,
|
|
37
|
+
timestamp: Date.now(),
|
|
38
|
+
...(opts.iconUrl ? { iconUrl: opts.iconUrl } : {}),
|
|
39
|
+
...(opts.imageUrl ? { imageUrl: opts.imageUrl } : {}),
|
|
40
|
+
};
|
|
41
|
+
log.log(`Notification from ${agent.name}: "${title}" - ${message}`);
|
|
42
|
+
if (broadcastFn) {
|
|
43
|
+
broadcastFn({
|
|
44
|
+
type: 'agent_notification',
|
|
45
|
+
payload: notification,
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
log.warn('Broadcast function not set - notification not sent to clients');
|
|
50
|
+
}
|
|
51
|
+
void publishNotification(classifyNotificationEventType(title), `${agent.name}: ${title}`, message).catch((err) => log.warn(`WhatsApp publish skipped: ${err}`));
|
|
52
|
+
// Native push: reaches phones whose app is closed (and whose battery-hungry
|
|
53
|
+
// WebSocket foreground service is therefore off). No-op until a Firebase
|
|
54
|
+
// service account is installed — see services/push-service.ts.
|
|
55
|
+
void sendAgentPush(notification).catch((err) => log.warn(`Push delivery skipped: ${err}`));
|
|
56
|
+
return notification;
|
|
57
|
+
}
|
|
58
|
+
export function classifyNotificationEventType(title) {
|
|
59
|
+
const t = title.toLowerCase();
|
|
60
|
+
if (t.includes('plan ready') || t.includes('plan'))
|
|
61
|
+
return 'planReady';
|
|
62
|
+
if (t.includes('error') || t.includes('failed') || t.includes('blocked') || t.includes('lost'))
|
|
63
|
+
return 'errors';
|
|
64
|
+
if (t.includes('task complete') || t.includes('completed') || t.includes('done'))
|
|
65
|
+
return 'taskComplete';
|
|
66
|
+
return 'messages';
|
|
67
|
+
}
|
|
@@ -32,7 +32,10 @@ const MODEL_MAP = {
|
|
|
32
32
|
opus5: 'claude-opus-5',
|
|
33
33
|
'claude-opus-5': 'claude-opus-5',
|
|
34
34
|
'claude-opus-5[1m]': 'claude-opus-5',
|
|
35
|
-
fable: 'claude-fable-5-
|
|
35
|
+
fable: 'claude-fable-5-2',
|
|
36
|
+
'fable-5-2': 'claude-fable-5-2',
|
|
37
|
+
fable52: 'claude-fable-5-2',
|
|
38
|
+
'claude-fable-5-2': 'claude-fable-5-2',
|
|
36
39
|
'fable-5-1': 'claude-fable-5-1',
|
|
37
40
|
fable51: 'claude-fable-5-1',
|
|
38
41
|
'claude-fable-5-1': 'claude-fable-5-1',
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { loadSession } from '../claude/session-loader.js';
|
|
2
|
+
import { buildLostSessionRetryPrompt, shortSessionId } from '../claude/session-recovery.js';
|
|
3
|
+
import { notifyAgent } from './agent-notifications.js';
|
|
2
4
|
import * as agentService from './agent-service.js';
|
|
3
5
|
import { clearPendingSilentContextRefresh, consumeStepCompleteReceived, markStepCompleteReceived, } from './runtime-watchdog.js';
|
|
4
6
|
import { addPendingBackgroundTask, clearPendingBackgroundTasks, getActiveSubagentByToolUseId, handleTaskToolResult, handleTaskToolStart, hasPendingBackgroundTasks, resolvePendingBackgroundTask, resolvePendingBackgroundTaskByTaskId, } from './runtime-subagents.js';
|
|
@@ -16,6 +18,8 @@ const CODEX_RECOVERABLE_RESUME_ERRORS = [
|
|
|
16
18
|
const CODEX_RECOVERY_HISTORY_LIMIT = 12;
|
|
17
19
|
const CODEX_RECOVERY_LINE_MAX_CHARS = 400;
|
|
18
20
|
const codexRecoveryState = new Map();
|
|
21
|
+
/** Lost Claude sessions already retried once (agentId → stale session signature). */
|
|
22
|
+
const lostSessionRecoveryState = new Map();
|
|
19
23
|
const codexContextGrowthHistory = new Map();
|
|
20
24
|
function detectRecoverableCodexResumeError(error) {
|
|
21
25
|
const normalizedError = String(error || '').toLowerCase();
|
|
@@ -559,6 +563,11 @@ export function createRuntimeEventHandlers(deps) {
|
|
|
559
563
|
clearPendingBackgroundTasks(agentId);
|
|
560
564
|
clearBackgroundTasks(agentId);
|
|
561
565
|
agentService.updateAgent(agentId, { status: 'error' });
|
|
566
|
+
// A run that died before its first turn (lost `--resume` transcript, expired
|
|
567
|
+
// credentials…) must never pass for a quiet end of turn: say it in the feed,
|
|
568
|
+
// notify, and for a lost session retry the same message once in a fresh one.
|
|
569
|
+
if (event.errorKind && !event.parentToolUseId)
|
|
570
|
+
handleZeroTurnError(agentId, agent, event);
|
|
562
571
|
break;
|
|
563
572
|
case 'context_stats':
|
|
564
573
|
break;
|
|
@@ -633,6 +642,69 @@ export function createRuntimeEventHandlers(deps) {
|
|
|
633
642
|
clearPendingSilentContextRefresh(agentId);
|
|
634
643
|
}
|
|
635
644
|
}
|
|
645
|
+
/**
|
|
646
|
+
* The CLI ended with a `result` of 0 turns (see claude/session-recovery.ts).
|
|
647
|
+
*
|
|
648
|
+
* `session_missing`: Claude Code deleted the transcript (`cleanupPeriodDays`),
|
|
649
|
+
* so `--resume` can never work again. Drop the session id, tell the feed and
|
|
650
|
+
* the notifications that the history is gone, and retry the SAME message once
|
|
651
|
+
* in a fresh session with a short notice up front. Once per stale session id:
|
|
652
|
+
* if the fresh run dies the same way, that is a different problem and it
|
|
653
|
+
* stays visible as an error instead of looping. (2026-10-27: Hoppip lost
|
|
654
|
+
* Ernesto's Slack message for three hours this way; 12 more agents idle for
|
|
655
|
+
* over a month were in the same state.)
|
|
656
|
+
*
|
|
657
|
+
* `zero_turn`: anything else that killed the CLI before it did a thing — make
|
|
658
|
+
* it loud (feed + notification) and leave the agent in `error`.
|
|
659
|
+
*/
|
|
660
|
+
function handleZeroTurnError(agentId, agent, event) {
|
|
661
|
+
const reason = event.errorMessage?.trim() || 'the CLI exited before its first turn';
|
|
662
|
+
const task = agent.lastAssignedTask?.trim() || '';
|
|
663
|
+
if (event.errorKind === 'session_missing') {
|
|
664
|
+
const staleSessionId = agent.sessionId ?? event.sessionId;
|
|
665
|
+
const signature = `session_missing:${staleSessionId ?? 'none'}`;
|
|
666
|
+
const previous = lostSessionRecoveryState.get(agentId);
|
|
667
|
+
const attempts = previous?.signature === signature ? previous.attempts : 0;
|
|
668
|
+
const short = shortSessionId(staleSessionId);
|
|
669
|
+
if (attempts >= 1 || !task) {
|
|
670
|
+
const why = !task
|
|
671
|
+
? 'there is no recorded message to retry'
|
|
672
|
+
: 'the fresh session failed the same way, so this is not just a deleted transcript';
|
|
673
|
+
log.error(`[Claude] Lost session ${staleSessionId} for ${agent.name} (${agentId}) and ${why}`);
|
|
674
|
+
agentService.updateAgent(agentId, { sessionId: undefined, lastError: reason });
|
|
675
|
+
emitOutput(agentId, `[System] Claude session ${short}… no longer exists (${reason}); ${why}. The agent stays in error until you send it a new message.`, false, undefined, 'system-session-lost');
|
|
676
|
+
notifyAgent(agentId, 'Session lost', `${agent.name} lost its Claude session (${short}…) and ${why}.`);
|
|
677
|
+
return;
|
|
678
|
+
}
|
|
679
|
+
lostSessionRecoveryState.set(agentId, { signature, attempts: attempts + 1 });
|
|
680
|
+
log.warn(`[Claude] Session ${staleSessionId} for ${agent.name} (${agentId}) no longer exists; clearing it and retrying the last message once in a fresh session`);
|
|
681
|
+
agentService.updateAgent(agentId, {
|
|
682
|
+
sessionId: undefined,
|
|
683
|
+
status: 'idle',
|
|
684
|
+
currentTask: undefined,
|
|
685
|
+
currentTool: undefined,
|
|
686
|
+
lastError: reason,
|
|
687
|
+
}, false);
|
|
688
|
+
emitOutput(agentId, `[System] Claude session ${short}… no longer exists on this machine (Claude Code deletes idle transcripts after cleanupPeriodDays). Its history is lost; retrying the same message in a fresh session.`, false, undefined, 'system-session-lost');
|
|
689
|
+
notifyAgent(agentId, 'Session lost', `${agent.name} lost its Claude session (${short}…). History is gone; retrying "${task.slice(0, 80)}" in a fresh session.`);
|
|
690
|
+
setTimeout(async () => {
|
|
691
|
+
try {
|
|
692
|
+
await executeCommand(agentId, buildLostSessionRetryPrompt(task, staleSessionId), undefined, true);
|
|
693
|
+
}
|
|
694
|
+
catch (retryErr) {
|
|
695
|
+
log.error(`[Claude] Fresh-session retry failed for ${agentId}:`, retryErr);
|
|
696
|
+
agentService.updateAgent(agentId, { status: 'error', currentTask: undefined, currentTool: undefined });
|
|
697
|
+
emitError(agentId, `Retry in a fresh session failed: ${String(retryErr)}`);
|
|
698
|
+
notifyAgent(agentId, 'Retry failed', `${agent.name}: retry in a fresh session failed: ${String(retryErr).slice(0, 160)}`);
|
|
699
|
+
}
|
|
700
|
+
}, 500);
|
|
701
|
+
return;
|
|
702
|
+
}
|
|
703
|
+
log.error(`[Claude] ${agent.name} (${agentId}) exited before its first turn: ${reason}`);
|
|
704
|
+
agentService.updateAgent(agentId, { lastError: reason });
|
|
705
|
+
emitOutput(agentId, `[System] The CLI exited with an error before doing anything: ${reason}${task ? ` — the message "${task.slice(0, 80)}" was NOT processed.` : ''}`, false, undefined, 'system-zero-turn');
|
|
706
|
+
notifyAgent(agentId, 'Agent error', `${agent.name} exited before doing anything: ${reason.slice(0, 160)}`);
|
|
707
|
+
}
|
|
636
708
|
function handleError(agentId, error) {
|
|
637
709
|
// Same as 'error' events: a failed run takes its background tasks with it.
|
|
638
710
|
clearPendingBackgroundTasks(agentId);
|
|
@@ -123,6 +123,11 @@ export const CODEX_MODELS = {
|
|
|
123
123
|
description: 'GPT-6.1 Sol — latest Sol, agentic workhorse for everyday coding (default)',
|
|
124
124
|
icon: '☀️',
|
|
125
125
|
},
|
|
126
|
+
'gpt-6.1-terra': {
|
|
127
|
+
label: 'GPT-6.1 Terra',
|
|
128
|
+
description: 'GPT-6.1 Terra — balanced coding model with a 500K context window',
|
|
129
|
+
icon: '🌍',
|
|
130
|
+
},
|
|
126
131
|
'gpt-6-luna': {
|
|
127
132
|
label: 'GPT-6 Luna',
|
|
128
133
|
description: 'GPT-6 Luna — fast and affordable agentic coding',
|
|
@@ -138,7 +143,7 @@ export const CODEX_MODELS = {
|
|
|
138
143
|
},
|
|
139
144
|
'gpt-5.6-terra': {
|
|
140
145
|
label: 'GPT-5.6 Terra',
|
|
141
|
-
description: 'Previous generation balanced coding model (
|
|
146
|
+
description: 'Previous generation balanced coding model (GPT-6.1 Terra preferred)',
|
|
142
147
|
icon: '🌍',
|
|
143
148
|
deprecated: true,
|
|
144
149
|
},
|
|
@@ -160,7 +165,7 @@ export function isDeprecatedCodexModel(model) {
|
|
|
160
165
|
return CODEX_MODELS[model]?.deprecated === true;
|
|
161
166
|
}
|
|
162
167
|
export const CLAUDE_MODELS = {
|
|
163
|
-
'claude-fable-5-
|
|
168
|
+
'claude-fable-5-2': { label: 'Fable 5.2 [1M]', description: 'Latest Fable — most capable Claude model for the hardest and longest-running tasks, native 1M token context window', icon: '🪄', contextWindow: 1000000 },
|
|
164
169
|
'claude-opus-5-5[1m]': { label: 'Opus 5.5 [1M]', description: 'Latest Opus with 1M token context window — for complex agentic coding and enterprise work (default)', icon: '🧠', contextWindow: 1000000 },
|
|
165
170
|
'claude-sonnet-5-5': { label: 'Sonnet 5.5 [1M]', description: 'Latest Sonnet — near-Opus intelligence at lower cost, native 1M token context window', icon: '⚡', contextWindow: 1000000 },
|
|
166
171
|
haiku: { label: 'Haiku', description: 'Fast and economical', icon: '🚀', contextWindow: 200000 },
|
|
@@ -168,6 +173,7 @@ export const CLAUDE_MODELS = {
|
|
|
168
173
|
// passthrough, but is hidden from the new/edit agent pickers: previous
|
|
169
174
|
// generations, legacy family aliases, and plain (200K) ids whose 1M variant
|
|
170
175
|
// is listed above.
|
|
176
|
+
'claude-fable-5-1': { label: 'Fable 5.1 [1M]', description: 'Previous Fable generation, native 1M token context window (Fable 5.2 preferred)', icon: '🪄', contextWindow: 1000000, deprecated: true },
|
|
171
177
|
'claude-fable-5[1m]': { label: 'Fable 5 [1M]', description: 'Previous Fable generation with 1M token context window', icon: '🪄', contextWindow: 1000000, deprecated: true },
|
|
172
178
|
'claude-opus-5[1m]': { label: 'Opus 5 [1M]', description: 'Previous Opus generation with 1M token context window', icon: '🧠', contextWindow: 1000000, deprecated: true },
|
|
173
179
|
'claude-sonnet-5[1m]': { label: 'Sonnet 5 [1M]', description: 'Previous Sonnet generation with 1M token context window', icon: '⚡', contextWindow: 1000000, deprecated: true },
|
|
@@ -11,7 +11,7 @@ import { CLAUDE_MODELS, CODEX_MODELS, DEFAULT_CODEX_MODEL, migrateRetiredCodexMo
|
|
|
11
11
|
// Newest model of each Claude family, as offered in the pickers.
|
|
12
12
|
const LATEST_CLAUDE = {
|
|
13
13
|
opus: 'claude-opus-5-5[1m]',
|
|
14
|
-
fable: 'claude-fable-5-
|
|
14
|
+
fable: 'claude-fable-5-2',
|
|
15
15
|
sonnet: 'claude-sonnet-5-5',
|
|
16
16
|
};
|
|
17
17
|
// Tide labels whose bare id doesn't say the version.
|
|
@@ -30,19 +30,21 @@ export function outdatedClaudeModel(model) {
|
|
|
30
30
|
return null;
|
|
31
31
|
return { newerModel: latest, newerLabel: CLAUDE_MODELS[latest].label };
|
|
32
32
|
}
|
|
33
|
-
//
|
|
34
|
-
|
|
33
|
+
// Superseded models whose successor is a newer release of the SAME line
|
|
34
|
+
// (6 Sol → 6.1 Sol, 5.6 Terra → 6.1 Terra), still registered but hidden.
|
|
35
|
+
const CODEX_LINE_SUCCESSORS = {
|
|
35
36
|
'gpt-6-sol': 'gpt-6.1-sol',
|
|
37
|
+
'gpt-5.6-terra': 'gpt-6.1-terra',
|
|
36
38
|
};
|
|
37
39
|
/** Notice for a Codex model id (bare or `openai-codex/…`). */
|
|
38
40
|
export function outdatedCodexModel(model) {
|
|
39
41
|
if (!model)
|
|
40
42
|
return null;
|
|
41
43
|
const id = model.trim().replace(/^openai-codex\//, '');
|
|
42
|
-
// A
|
|
43
|
-
const
|
|
44
|
-
if (
|
|
45
|
-
return { newerModel:
|
|
44
|
+
// A newer release of the model's own line (6 Sol → 6.1 Sol, 5.6 Terra → 6.1 Terra).
|
|
45
|
+
const lineSuccessor = CODEX_LINE_SUCCESSORS[id];
|
|
46
|
+
if (lineSuccessor)
|
|
47
|
+
return { newerModel: lineSuccessor, newerLabel: CODEX_MODELS[lineSuccessor].label };
|
|
46
48
|
if (!/^gpt-5(?:[.-]|$)/.test(id))
|
|
47
49
|
return null; // the rest of GPT-6 is current
|
|
48
50
|
// The retired model's own successor when it has one (5.6 Luna → 6 Luna),
|
package/package.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{U as a,C as n}from"./mermaid.core-Cd-X-VQG.js";const t=(r,o)=>a.lang.round(n.parse(r)[o]);export{t as c};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{s as a,c as s,a as e,C as t}from"./chunk-V7JOEXUC-B48QcHmS.js";import{_ as i}from"./mermaid.core-Cd-X-VQG.js";import"./chunk-5VM5RSS4-r9xckJVE.js";import"./chunk-XXDRQBXY-Cyo-LR80.js";import"./chunk-VR4S4FIN-Cah567yW.js";import"./chunk-32BRIVSS-C2qUOlfT.js";import"./main-C661hDwF.js";import"./vendor-react--Eh9ivFN.js";import"./vendor-three-GtkNAxzd.js";var b={parser:e,get db(){return new t},renderer:s,styles:a,init:i(r=>{r.class||(r.class={}),r.class.arrowMarkerAbsolute=r.arrowMarkerAbsolute},"init")};export{b as diagram};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{s as a,c as s,a as e,C as t}from"./chunk-V7JOEXUC-B48QcHmS.js";import{_ as i}from"./mermaid.core-Cd-X-VQG.js";import"./chunk-5VM5RSS4-r9xckJVE.js";import"./chunk-XXDRQBXY-Cyo-LR80.js";import"./chunk-VR4S4FIN-Cah567yW.js";import"./chunk-32BRIVSS-C2qUOlfT.js";import"./main-C661hDwF.js";import"./vendor-react--Eh9ivFN.js";import"./vendor-three-GtkNAxzd.js";var b={parser:e,get db(){return new t},renderer:s,styles:a,init:i(r=>{r.class||(r.class={}),r.class.arrowMarkerAbsolute=r.arrowMarkerAbsolute},"init")};export{b as diagram};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{c as dt,d as ft,T as us,a8 as hs,f as ds,bx as fs,ck as ms,ap as gs,r as l,R as ps,S as Fe,cl as at,cm as ys,cn as As,co as xs,aH as Es,cp as we,s as X,cq as Ms,j as c,I as G,a1 as Rt,cr as Lt,E as Dt,cs as Cs,ct as kt,cu as it,a0 as ct,m as Ss,aG as Wt,u as st,cv as Ft,aU as _s,cw as $t,cx as Is,cy as vs,cz as Ns,cA as bs,cB as js,cC as ws,cD as Ts}from"./main-C661hDwF.js";import{cE as er,cF as tr,cG as sr,cH as nr,cI as rr}from"./main-C661hDwF.js";import{s as Rs,S as Ls}from"./settingsSearch-Cv7ya9n1.js";import"./vendor-react--Eh9ivFN.js";import"./vendor-three-GtkNAxzd.js";function fe(t){return Array.isArray?Array.isArray(t):Vt(t)==="[object Array]"}function Ds(t){if(typeof t=="string")return t;let e=t+"";return e=="0"&&1/t==-1/0?"-0":e}function ks(t){return t==null?"":Ds(t)}function ue(t){return typeof t=="string"}function Yt(t){return typeof t=="number"}function Fs(t){return t===!0||t===!1||$s(t)&&Vt(t)=="[object Boolean]"}function qt(t){return typeof t=="object"}function $s(t){return qt(t)&&t!==null}function ne(t){return t!=null}function lt(t){return!t.trim().length}function Vt(t){return t==null?t===void 0?"[object Undefined]":"[object Null]":Object.prototype.toString.call(t)}const Bs="Incorrect 'index' type",Ps=t=>`Invalid value for key ${t}`,Qs=t=>`Pattern length exceeds max of ${t}.`,zs=t=>`Missing ${t} property in key`,Ks=t=>`Property 'weight' in key '${t}' must be a positive integer`,Bt=Object.prototype.hasOwnProperty;class Gs{constructor(e){this._keys=[],this._keyMap={};let n=0;e.forEach(r=>{let o=Xt(r);this._keys.push(o),this._keyMap[o.id]=o,n+=o.weight}),this._keys.forEach(r=>{r.weight/=n})}get(e){return this._keyMap[e]}keys(){return this._keys}toJSON(){return JSON.stringify(this._keys)}}function Xt(t){let e=null,n=null,r=null,o=1,i=null;if(ue(t)||fe(t))r=t,e=Pt(t),n=mt(t);else{if(!Bt.call(t,"name"))throw new Error(zs("name"));const u=t.name;if(r=u,Bt.call(t,"weight")&&(o=t.weight,o<=0))throw new Error(Ks(u));e=Pt(u),n=mt(u),i=t.getFn}return{path:e,id:n,weight:o,src:r,getFn:i}}function Pt(t){return fe(t)?t:t.split(".")}function mt(t){return fe(t)?t.join("."):t}function Os(t,e){let n=[],r=!1;const o=(i,u,d)=>{if(ne(i))if(!u[d])n.push(i);else{let h=u[d];const f=i[h];if(!ne(f))return;if(d===u.length-1&&(ue(f)||Yt(f)||Fs(f)))n.push(ks(f));else if(fe(f)){r=!0;for(let m=0,x=f.length;m<x;m+=1)o(f[m],u,d+1)}else u.length&&o(f,u,d+1)}};return o(t,ue(e)?e.split("."):e,0),r?n:n[0]}const Us={includeMatches:!1,findAllMatches:!1,minMatchCharLength:1},Hs={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},Ws={location:0,threshold:.6,distance:100},Ys={useExtendedSearch:!1,getFn:Os,ignoreLocation:!1,ignoreFieldNorm:!1,fieldNormWeight:1};var C={...Hs,...Us,...Ws,...Ys};const qs=/[^ ]+/g;function Vs(t=1,e=3){const n=new Map,r=Math.pow(10,e);return{get(o){const i=o.match(qs).length;if(n.has(i))return n.get(i);const u=1/Math.pow(i,.5*t),d=parseFloat(Math.round(u*r)/r);return n.set(i,d),d},clear(){n.clear()}}}class Et{constructor({getFn:e=C.getFn,fieldNormWeight:n=C.fieldNormWeight}={}){this.norm=Vs(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,ue(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();ue(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(!ne(e)||lt(e))return;let r={v:e,i:n,n:this.norm.get(e)};this.records.push(r)}_addObject(e,n){let r={i:n,$:{}};this.keys.forEach((o,i)=>{let u=o.getFn?o.getFn(e):this.getFn(e,o.path);if(ne(u)){if(fe(u)){let d=[];const h=[{nestedArrIndex:-1,value:u}];for(;h.length;){const{nestedArrIndex:f,value:m}=h.pop();if(ne(m))if(ue(m)&&!lt(m)){let x={v:m,i:f,n:this.norm.get(m)};d.push(x)}else fe(m)&&m.forEach((x,y)=>{h.push({nestedArrIndex:y,value:x})})}r.$[i]=d}else if(ue(u)&&!lt(u)){let d={v:u,n:this.norm.get(u)};r.$[i]=d}}}),this.records.push(r)}toJSON(){return{keys:this.keys,records:this.records}}}function Jt(t,e,{getFn:n=C.getFn,fieldNormWeight:r=C.fieldNormWeight}={}){const o=new Et({getFn:n,fieldNormWeight:r});return o.setKeys(t.map(Xt)),o.setSources(e),o.create(),o}function Xs(t,{getFn:e=C.getFn,fieldNormWeight:n=C.fieldNormWeight}={}){const{keys:r,records:o}=t,i=new Et({getFn:e,fieldNormWeight:n});return i.setKeys(r),i.setIndexRecords(o),i}function Je(t,{errors:e=0,currentLocation:n=0,expectedLocation:r=0,distance:o=C.distance,ignoreLocation:i=C.ignoreLocation}={}){const u=e/t.length;if(i)return u;const d=Math.abs(r-n);return o?u+d/o:d?1:u}function Js(t=[],e=C.minMatchCharLength){let n=[],r=-1,o=-1,i=0;for(let u=t.length;i<u;i+=1){let d=t[i];d&&r===-1?r=i:!d&&r!==-1&&(o=i-1,o-r+1>=e&&n.push([r,o]),r=-1)}return t[i-1]&&i-r>=e&&n.push([r,i-1]),n}const _e=32;function Zs(t,e,n,{location:r=C.location,distance:o=C.distance,threshold:i=C.threshold,findAllMatches:u=C.findAllMatches,minMatchCharLength:d=C.minMatchCharLength,includeMatches:h=C.includeMatches,ignoreLocation:f=C.ignoreLocation}={}){if(e.length>_e)throw new Error(Qs(_e));const m=e.length,x=t.length,y=Math.max(0,Math.min(r,x));let E=i,A=y;const M=d>1||h,N=M?Array(x):[];let D;for(;(D=t.indexOf(e,A))>-1;){let U=Je(e,{currentLocation:D,expectedLocation:y,distance:o,ignoreLocation:f});if(E=Math.min(U,E),A=D+m,M){let Y=0;for(;Y<m;)N[D+Y]=1,Y+=1}}A=-1;let b=[],L=1,O=m+x;const ce=1<<m-1;for(let U=0;U<m;U+=1){let Y=0,J=O;for(;Y<J;)Je(e,{errors:U,currentLocation:y+J,expectedLocation:y,distance:o,ignoreLocation:f})<=E?Y=J:O=J,J=Math.floor((O-Y)/2+Y);O=J;let oe=Math.max(1,y-J+1),le=u?x:Math.min(y+J,x)+m,Q=Array(le+2);Q[le+1]=(1<<U)-1;for(let q=le;q>=oe;q-=1){let V=q-1,ee=n[t.charAt(V)];if(M&&(N[V]=+!!ee),Q[q]=(Q[q+1]<<1|1)&ee,U&&(Q[q]|=(b[q+1]|b[q])<<1|1|b[q+1]),Q[q]&ce&&(L=Je(e,{errors:U,currentLocation:V,expectedLocation:y,distance:o,ignoreLocation:f}),L<=E)){if(E=L,A=V,A<=y)break;oe=Math.max(1,2*y-A)}}if(Je(e,{errors:U+1,currentLocation:y,expectedLocation:y,distance:o,ignoreLocation:f})>E)break;b=Q}const me={isMatch:A>=0,score:Math.max(.001,L)};if(M){const U=Js(N,d);U.length?h&&(me.indices=U):me.isMatch=!1}return me}function en(t){let e={};for(let n=0,r=t.length;n<r;n+=1){const o=t.charAt(n);e[o]=(e[o]||0)|1<<r-n-1}return e}const et=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 Zt{constructor(e,{location:n=C.location,threshold:r=C.threshold,distance:o=C.distance,includeMatches:i=C.includeMatches,findAllMatches:u=C.findAllMatches,minMatchCharLength:d=C.minMatchCharLength,isCaseSensitive:h=C.isCaseSensitive,ignoreDiacritics:f=C.ignoreDiacritics,ignoreLocation:m=C.ignoreLocation}={}){if(this.options={location:n,threshold:r,distance:o,includeMatches:i,findAllMatches:u,minMatchCharLength:d,isCaseSensitive:h,ignoreDiacritics:f,ignoreLocation:m},e=h?e:e.toLowerCase(),e=f?et(e):e,this.pattern=e,this.chunks=[],!this.pattern.length)return;const x=(E,A)=>{this.chunks.push({pattern:E,alphabet:en(E),startIndex:A})},y=this.pattern.length;if(y>_e){let E=0;const A=y%_e,M=y-A;for(;E<M;)x(this.pattern.substr(E,_e),E),E+=_e;if(A){const N=y-_e;x(this.pattern.substr(N),N)}}else x(this.pattern,0)}searchIn(e){const{isCaseSensitive:n,ignoreDiacritics:r,includeMatches:o}=this.options;if(e=n?e:e.toLowerCase(),e=r?et(e):e,this.pattern===e){let M={isMatch:!0,score:0};return o&&(M.indices=[[0,e.length-1]]),M}const{location:i,distance:u,threshold:d,findAllMatches:h,minMatchCharLength:f,ignoreLocation:m}=this.options;let x=[],y=0,E=!1;this.chunks.forEach(({pattern:M,alphabet:N,startIndex:D})=>{const{isMatch:b,score:L,indices:O}=Zs(e,M,N,{location:i+D,distance:u,threshold:d,findAllMatches:h,minMatchCharLength:f,includeMatches:o,ignoreLocation:m});b&&(E=!0),y+=L,b&&O&&(x=[...x,...O])});let A={isMatch:E,score:E?y/this.chunks.length:1};return E&&o&&(A.indices=x),A}}class Ae{constructor(e){this.pattern=e}static isMultiMatch(e){return Qt(e,this.multiRegex)}static isSingleMatch(e){return Qt(e,this.singleRegex)}search(){}}function Qt(t,e){const n=t.match(e);return n?n[1]:null}class tn extends Ae{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 sn extends Ae{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 nn extends Ae{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 rn extends Ae{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 on extends Ae{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 an extends Ae{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 es extends Ae{constructor(e,{location:n=C.location,threshold:r=C.threshold,distance:o=C.distance,includeMatches:i=C.includeMatches,findAllMatches:u=C.findAllMatches,minMatchCharLength:d=C.minMatchCharLength,isCaseSensitive:h=C.isCaseSensitive,ignoreDiacritics:f=C.ignoreDiacritics,ignoreLocation:m=C.ignoreLocation}={}){super(e),this._bitapSearch=new Zt(e,{location:n,threshold:r,distance:o,includeMatches:i,findAllMatches:u,minMatchCharLength:d,isCaseSensitive:h,ignoreDiacritics:f,ignoreLocation:m})}static get type(){return"fuzzy"}static get multiRegex(){return/^"(.*)"$/}static get singleRegex(){return/^(.*)$/}search(e){return this._bitapSearch.searchIn(e)}}class ts extends Ae{constructor(e){super(e)}static get type(){return"include"}static get multiRegex(){return/^'"(.*)"$/}static get singleRegex(){return/^'(.*)$/}search(e){let n=0,r;const o=[],i=this.pattern.length;for(;(r=e.indexOf(this.pattern,n))>-1;)n=r+i,o.push([r,n-1]);const u=!!o.length;return{isMatch:u,score:u?0:1,indices:o}}}const gt=[tn,ts,nn,rn,an,on,sn,es],zt=gt.length,cn=/ +(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)/,ln="|";function un(t,e={}){return t.split(ln).map(n=>{let r=n.trim().split(cn).filter(i=>i&&!!i.trim()),o=[];for(let i=0,u=r.length;i<u;i+=1){const d=r[i];let h=!1,f=-1;for(;!h&&++f<zt;){const m=gt[f];let x=m.isMultiMatch(d);x&&(o.push(new m(x,e)),h=!0)}if(!h)for(f=-1;++f<zt;){const m=gt[f];let x=m.isSingleMatch(d);if(x){o.push(new m(x,e));break}}}return o})}const hn=new Set([es.type,ts.type]);class dn{constructor(e,{isCaseSensitive:n=C.isCaseSensitive,ignoreDiacritics:r=C.ignoreDiacritics,includeMatches:o=C.includeMatches,minMatchCharLength:i=C.minMatchCharLength,ignoreLocation:u=C.ignoreLocation,findAllMatches:d=C.findAllMatches,location:h=C.location,threshold:f=C.threshold,distance:m=C.distance}={}){this.query=null,this.options={isCaseSensitive:n,ignoreDiacritics:r,includeMatches:o,minMatchCharLength:i,findAllMatches:d,ignoreLocation:u,location:h,threshold:f,distance:m},e=n?e:e.toLowerCase(),e=r?et(e):e,this.pattern=e,this.query=un(this.pattern,this.options)}static condition(e,n){return n.useExtendedSearch}searchIn(e){const n=this.query;if(!n)return{isMatch:!1,score:1};const{includeMatches:r,isCaseSensitive:o,ignoreDiacritics:i}=this.options;e=o?e:e.toLowerCase(),e=i?et(e):e;let u=0,d=[],h=0;for(let f=0,m=n.length;f<m;f+=1){const x=n[f];d.length=0,u=0;for(let y=0,E=x.length;y<E;y+=1){const A=x[y],{isMatch:M,indices:N,score:D}=A.search(e);if(M){if(u+=1,h+=D,r){const b=A.constructor.type;hn.has(b)?d=[...d,...N]:d.push(N)}}else{h=0,u=0,d.length=0;break}}if(u){let y={isMatch:!0,score:h/u};return r&&(y.indices=d),y}}return{isMatch:!1,score:1}}}const pt=[];function fn(...t){pt.push(...t)}function yt(t,e){for(let n=0,r=pt.length;n<r;n+=1){let o=pt[n];if(o.condition(t,e))return new o(t,e)}return new Zt(t,e)}const tt={AND:"$and",OR:"$or"},At={PATH:"$path",PATTERN:"$val"},xt=t=>!!(t[tt.AND]||t[tt.OR]),mn=t=>!!t[At.PATH],gn=t=>!fe(t)&&qt(t)&&!xt(t),Kt=t=>({[tt.AND]:Object.keys(t).map(e=>({[e]:t[e]}))});function ss(t,e,{auto:n=!0}={}){const r=o=>{let i=Object.keys(o);const u=mn(o);if(!u&&i.length>1&&!xt(o))return r(Kt(o));if(gn(o)){const h=u?o[At.PATH]:i[0],f=u?o[At.PATTERN]:o[h];if(!ue(f))throw new Error(Ps(h));const m={keyId:mt(h),pattern:f};return n&&(m.searcher=yt(f,e)),m}let d={children:[],operator:i[0]};return i.forEach(h=>{const f=o[h];fe(f)&&f.forEach(m=>{d.children.push(r(m))})}),d};return xt(t)||(t=Kt(t)),r(t)}function pn(t,{ignoreFieldNorm:e=C.ignoreFieldNorm}){t.forEach(n=>{let r=1;n.matches.forEach(({key:o,norm:i,score:u})=>{const d=o?o.weight:null;r*=Math.pow(u===0&&d?Number.EPSILON:u,(d||1)*(e?1:i))}),n.score=r})}function yn(t,e){const n=t.matches;e.matches=[],ne(n)&&n.forEach(r=>{if(!ne(r.indices)||!r.indices.length)return;const{indices:o,value:i}=r;let u={indices:o,value:i};r.key&&(u.key=r.key.src),r.idx>-1&&(u.refIndex=r.idx),e.matches.push(u)})}function An(t,e){e.score=t.score}function xn(t,e,{includeMatches:n=C.includeMatches,includeScore:r=C.includeScore}={}){const o=[];return n&&o.push(yn),r&&o.push(An),t.map(i=>{const{idx:u}=i,d={item:e[u],refIndex:u};return o.length&&o.forEach(h=>{h(i,d)}),d})}class de{constructor(e,n={},r){this.options={...C,...n},this.options.useExtendedSearch,this._keyStore=new Gs(this.options.keys),this.setCollection(e,r)}setCollection(e,n){if(this._docs=e,n&&!(n instanceof Et))throw new Error(Bs);this._myIndex=n||Jt(this.options.keys,this._docs,{getFn:this.options.getFn,fieldNormWeight:this.options.fieldNormWeight})}add(e){ne(e)&&(this._docs.push(e),this._myIndex.add(e))}remove(e=()=>!1){const n=[];for(let r=0,o=this._docs.length;r<o;r+=1){const i=this._docs[r];e(i,r)&&(this.removeAt(r),r-=1,o-=1,n.push(i))}return n}removeAt(e){this._docs.splice(e,1),this._myIndex.removeAt(e)}getIndex(){return this._myIndex}search(e,{limit:n=-1}={}){const{includeMatches:r,includeScore:o,shouldSort:i,sortFn:u,ignoreFieldNorm:d}=this.options;let h=ue(e)?ue(this._docs[0])?this._searchStringList(e):this._searchObjectList(e):this._searchLogical(e);return pn(h,{ignoreFieldNorm:d}),i&&h.sort(u),Yt(n)&&n>-1&&(h=h.slice(0,n)),xn(h,this._docs,{includeMatches:r,includeScore:o})}_searchStringList(e){const n=yt(e,this.options),{records:r}=this._myIndex,o=[];return r.forEach(({v:i,i:u,n:d})=>{if(!ne(i))return;const{isMatch:h,score:f,indices:m}=n.searchIn(i);h&&o.push({item:i,idx:u,matches:[{score:f,value:i,norm:d,indices:m}]})}),o}_searchLogical(e){const n=ss(e,this.options),r=(d,h,f)=>{if(!d.children){const{keyId:x,searcher:y}=d,E=this._findMatches({key:this._keyStore.get(x),value:this._myIndex.getValueForItemAtKeyId(h,x),searcher:y});return E&&E.length?[{idx:f,item:h,matches:E}]:[]}const m=[];for(let x=0,y=d.children.length;x<y;x+=1){const E=d.children[x],A=r(E,h,f);if(A.length)m.push(...A);else if(d.operator===tt.AND)return[]}return m},o=this._myIndex.records,i={},u=[];return o.forEach(({$:d,i:h})=>{if(ne(d)){let f=r(n,d,h);f.length&&(i[h]||(i[h]={idx:h,item:d,matches:[]},u.push(i[h])),f.forEach(({matches:m})=>{i[h].matches.push(...m)}))}}),u}_searchObjectList(e){const n=yt(e,this.options),{keys:r,records:o}=this._myIndex,i=[];return o.forEach(({$:u,i:d})=>{if(!ne(u))return;let h=[];r.forEach((f,m)=>{h.push(...this._findMatches({key:f,value:u[m],searcher:n}))}),h.length&&i.push({idx:d,item:u,matches:h})}),i}_findMatches({key:e,value:n,searcher:r}){if(!ne(n))return[];let o=[];if(fe(n))n.forEach(({v:i,i:u,n:d})=>{if(!ne(i))return;const{isMatch:h,score:f,indices:m}=r.searchIn(i);h&&o.push({score:f,key:e,value:i,idx:u,norm:d,indices:m})});else{const{v:i,n:u}=n,{isMatch:d,score:h,indices:f}=r.searchIn(i);d&&o.push({score:h,key:e,value:i,norm:u,indices:f})}return o}}de.version="7.1.0";de.createIndex=Jt;de.parseIndex=Xs;de.config=C;de.parseQuery=ss;fn(dn);function ke(t){return t.trim().toLowerCase().split(/\s+/).filter(Boolean)}function En(t){return t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function Ze(t,e){const n=e.trim(),r=ke(n);if(r.length<=1)return t.search(n);const[o,...i]=r.map(h=>t.search(h)),u=i.map(h=>{const f=new Map;for(const m of h)f.set(m.refIndex,m.score??1);return f}),d=[];for(const h of o){let f=h.score??1,m=!0;for(const x of u){const y=x.get(h.refIndex);if(y===void 0){m=!1;break}f+=y}m&&d.push({item:h.item,score:f/r.length})}return d.sort((h,f)=>(h.score??1)-(f.score??1)),d}function Gt(t,e,n){return e===t?6:e.startsWith(t)?5:e.split(/[^a-z0-9]+/i).includes(t)?4:e.includes(t)?3:n.includes(t)?2:1}function Mn(t,e,n){const r=ke(t);if(r.length===0)return 1;const o=e.toLowerCase(),i=n.toLowerCase(),u=Gt(r.join(" "),o,i);if(r.length===1)return u;let d=6;for(const h of r)d=Math.min(d,Gt(h,o,i));return Math.max(u,d)}const Cn=4;function Ot(t){return t.replace(/…|\.\.\./g," ").replace(/\s+/g," ").trim().toLowerCase()}const Sn=24;function _n(t,e){const n=Ot(t),r=Ot(e);return n===r?!0:Math.min(n.length,r.length)<Sn?!1:n.includes(r)||r.includes(n)}function In(t,e){const n=[],r=o=>{!o||!o.text.trim()||n.length>=Cn||n.some(i=>_n(i.text,o.text))||n.push(o)};t&&r({text:t,kind:"user"});for(const o of e??[])r(o);return n.length>0?n:void 0}async function vn(t){const e=new URLSearchParams({q:t}),n=await dt(ft(`/api/folders/search?${e.toString()}`));if(!n.ok){const o=await n.json().catch(()=>({}));throw new Error(o.error||`Failed to search folders: ${n.statusText}`)}const r=await n.json();return Array.isArray(r.folders)?r.folders:[]}const Ut=["agent","session","building","setting","file","file-content","folder","area"],Nn=2,bn=2,jn=50,wn=10,Tn=3,Rn=30,Ln=8,Dn=8,kn=3,Fn=15,ut=5,ht=5;function $n(){const t=Wt(Fe.SPOTLIGHT_TAB,"all");return we.includes(t)?t:"all"}function Ht(){return Ss(Fe.SPOTLIGHT_QUERY,"")}function Bn(){const t=Wt(Fe.AOP_CONFIG,{});return t.sortMode==="name"||t.sortMode==="status"||t.sortMode==="recent"?t.sortMode:"recent"}function Pn({isOpen:t,onClose:e,onOpenSpawnModal:n,onOpenCommanderView:r,onOpenToolbox:o,onOpenFileExplorer:i,onOpenPM2LogsModal:u,onOpenBossLogsModal:d,onOpenDatabasePanel:h,onOpenMonitoringModal:f,onOpenSessionFinder:m,onOpenFileDetail:x}){const y=us(),E=hs(),A=ds(),M=fs(),N=ms(),D=gs(),b=l.useRef(e);b.current=e;const L=l.useRef(n);L.current=n;const O=l.useRef(r);O.current=r;const ce=l.useRef(o);ce.current=o;const me=l.useRef(i);me.current=i;const U=l.useRef(u);U.current=u;const Y=l.useRef(d);Y.current=d;const J=l.useRef(h);J.current=h;const oe=l.useRef(f);oe.current=f;const le=l.useRef(m);le.current=m;const Q=l.useRef(x);Q.current=x;const[R,q]=l.useState(Ht),[V,ee]=l.useState(0),[ae,$e]=l.useState($n),[Be,ge]=l.useState([]),[Pe,pe]=l.useState([]),[Qe,te]=l.useState([]),[se,ye]=l.useState(!1),[Ie,xe]=l.useState(!1),[ze,ve]=l.useState(!1),[Ke,v]=l.useState(!1),[S,k]=l.useState({query:"",rows:[]}),[Ne,Te]=l.useState(!1),[Ee,Mt]=l.useState(!1);l.useEffect(()=>{Te(!1),Mt(!1)},[R,t]);const ns=l.useCallback(s=>{q(s),ps(Fe.SPOTLIGHT_QUERY,s)},[]);l.useEffect(()=>{t&&(q(Ht()),ee(0))},[t]),l.useEffect(()=>{if(!t){ge([]),ye(!1);return}const s=R.trim();if(s.length<Nn){ge([]),ye(!1);return}ge([]),ye(!0);let a=!1;const g=setTimeout(()=>{vn(s).then(I=>{a||ge(I)}).catch(()=>{a||ge([])}).finally(()=>{a||ye(!1)})},250);return()=>{a=!0,clearTimeout(g)}},[t,R]);const Ct=(M.fileSearchExcludeDirs??at).join(",");l.useEffect(()=>{if(!t){pe([]),xe(!1);return}const s=R.trim();if(s.length<bn){pe([]),xe(!1);return}pe([]),xe(!0);let a=!1;const g=setTimeout(()=>{ys(s,{exclude:M.fileSearchExcludeDirs??[...at],limit:jn}).then(I=>{a||pe(I)}).catch(()=>{a||pe([])}).finally(()=>{a||xe(!1)})},250);return()=>{a=!0,clearTimeout(g)}},[t,R,Ct,M.fileSearchExcludeDirs]),l.useEffect(()=>{if(!t){te([]),ve(!1);return}const s=R.trim();if(s.length<Tn){te([]),ve(!1);return}te([]),ve(!0);const a=new AbortController,g=setTimeout(()=>{As(s,{exclude:M.fileSearchExcludeDirs??[...at],limit:Rn,signal:a.signal}).then(I=>{a.signal.aborted||te(I)}).catch(()=>{a.signal.aborted||te([])}).finally(()=>{a.signal.aborted||ve(!1)})},300);return()=>{clearTimeout(g),a.abort()}},[t,R,Ct,M.fileSearchExcludeDirs]),l.useEffect(()=>{if(!t){k({query:"",rows:[]}),v(!1);return}const s=R.trim();if(s.length<kn){k({query:"",rows:[]}),v(!1);return}k({query:"",rows:[]}),v(!0);let a=!1;const g=setTimeout(()=>{xs(s,{limit:Fn}).then(I=>{a||k({query:s,rows:I})}).catch(()=>{a||k({query:"",rows:[]})}).finally(()=>{a||v(!1)})},250);return()=>{a=!0,clearTimeout(g)}},[t,R]);const nt=l.useCallback(s=>{$e(s),Es(Fe.SPOTLIGHT_TAB,s)},[]),St=l.useRef(ae);St.current=ae;const rs=l.useCallback(s=>{const a=we.indexOf(St.current),g=we[(a+s+we.length)%we.length];nt(g)},[nt]);l.useEffect(()=>{ee(0)},[ae]);const rt=X.getShortcuts(),Ge=l.useMemo(()=>t?Ms():{},[t]),Oe=l.useMemo(()=>{if(!t)return[];const s=window.matchMedia("(pointer: coarse)").matches,a=rt.find(I=>I.id==="spawn-agent"),g=rt.find(I=>I.id==="toggle-commander");return[{id:"cmd-spawn",type:"command",title:"Spawn New Agent",subtitle:s?"":a?Rt(a):"Alt+N",icon:c.jsx(G,{name:"plus",size:16}),action:()=>{b.current(),L.current()}},{id:"cmd-commander",type:"command",title:"Commander View",subtitle:s?"":g!=null&&g.key?Rt(g):"Tab",icon:c.jsx(G,{name:"dashboard",size:16}),action:()=>{b.current(),O.current()}},{id:"cmd-settings",type:"command",title:"Settings & Tools",subtitle:"Configure Tide Commander",icon:c.jsx(G,{name:"gear",size:16}),action:()=>{b.current(),ce.current()}},{id:"cmd-monitoring",type:"command",title:"Monitoring & Logs",subtitle:"Triggers, workflows, events",icon:c.jsx(G,{name:"chart-line",size:16}),action:()=>{var I;b.current(),(I=oe.current)==null||I.call(oe)}}]},[t,rt]),Ue=l.useMemo(()=>{if(!t)return[];const s=R.trim();return(s?Rs(s):Ls).map(g=>({id:`setting-${g.id}`,type:"setting",title:g.title,subtitle:s?`Settings section • ${s}`:"Settings section",icon:c.jsx(G,{name:"gear",size:16}),_searchText:`${g.title} ${g.keywords.join(" ")}`,action:()=>{b.current(),ce.current(s||g.title)}}))},[t,R]),He=l.useMemo(()=>{const s=new Map;if(!t)return s;const a=Array.from(E.values());for(const g of y.values())for(const I of a)if(X.isPositionInArea({x:g.position.x,z:g.position.z},I)){s.set(g.id,I);break}return s},[t,y,E]),be=l.useMemo(()=>t?Array.from(y.values()).map(s=>{const a=[];s.lastAssignedTask&&a.push(s.lastAssignedTask);const g=`${s.class} • ${s.cwd}`,I=He.get(s.id),B=(I==null?void 0:I.name)||"";let T=`${s.name} ${s.class} ${s.status} ${s.cwd}`;s.taskLabel&&(T+=` ${s.taskLabel}`),B&&(T+=` ${B}`),a.length>0&&(T+=` ${a.join(" ")}`);const K=Date.now()-s.lastActivity;let $;return s.lastAssignedTask&&(s.lastAssignedTask.length>150?$=s.lastAssignedTask.slice(0,150)+"...":$=s.lastAssignedTask),{id:`agent-${s.id}`,type:"agent",title:s.name,subtitle:g,lastUserInput:$,timeAway:K,icon:c.jsx(Dt,{agent:s,size:20}),_searchText:T,_userQueries:a,_agentId:s.id,_lastActivity:s.lastActivity,_taskLabel:s.taskLabel,_status:s.status,_provider:s.provider??"claude",_piModel:s.piModel,_piModelProvider:s.piModelProvider,_areaName:B||void 0,_areaColor:I==null?void 0:I.color,action:()=>{b.current(),Lt(s.id),X.selectAgent(s.id),X.getState().viewMode!=="flat"&&X.requestTerminalExpand()}}}):[],[t,y,He]),We=l.useMemo(()=>t?Array.from(E.values()).map(s=>{var a;return{id:`area-${s.id}`,type:"area",title:s.name,subtitle:`${s.assignedAgentIds.length} agents • ${((a=s.directories)==null?void 0:a.length)||0} folders`,icon:c.jsx(G,{name:"map",size:16}),action:()=>{b.current(),X.selectArea(s.id)}}}):[],[t,E]),Ye=l.useMemo(()=>{const s=new Map;for(const a of be)a._agentId&&s.set(a._agentId,a);return s},[be]),_t=l.useMemo(()=>{const s=new Map;if(!t)return s;for(const a of y.values()){const g=He.get(a.id);if(!g||g.archived)continue;const I=s.get(g.id);I?I.push(a):s.set(g.id,[a])}return s},[t,y,He]),It=l.useMemo(()=>{const s=new Map;for(const a of N)s.has(a.agentId)||s.set(a.agentId,a.timestamp);return s},[N]),ot=l.useMemo(()=>{if(!t)return[];const s=R.trim().toLowerCase(),a=ke(s),g=Cs({sortMode:Bn(),agentsWithUnseenOutput:D,getLatestToolTimestamp:T=>It.get(T)}),I=Array.from(E.values()).filter(T=>!T.archived).filter(T=>{if(a.length===0)return!0;const K=T.name.toLowerCase();return a.some($=>K.includes($))}).sort((T,K)=>T.name.localeCompare(K.name,void 0,{sensitivity:"base"})),B=[];for(const T of I){const K=T.name.toLowerCase(),$=a.filter(W=>!K.includes(W));let H=(_t.get(T.id)||[]).slice().sort(g).map(W=>Ye.get(W.id)).filter(W=>!!W);$.length>0&&(H=H.filter(W=>{const z=`${W.title} ${W.subtitle||""} ${W._searchText||""}`.toLowerCase();return $.every(F=>z.includes(F))}),H.length===0)||!s&&H.length===0||B.push({areaId:T.id,areaName:T.name,areaColor:T.color,agents:H})}return B},[t,R,E,_t,Ye,D,It]),qe=l.useMemo(()=>t?Array.from(A.values()).filter(s=>s.type==="server"||s.type==="boss"||s.type==="database"||s.type==="tests").map(s=>{var $,re,H,W,z;const a=s.status==="running"?"#4ade80":s.status==="stopped"?"#f87171":"#facc15",g=s.type==="boss"?"crown":s.type==="database"?"database":s.type==="tests"?"flask":"desktop",I=s.type==="boss"?"Boss":s.type==="database"?"Database":s.type==="tests"?"Tests":"Server";let B=`${I} • ${s.status}`;if(s.type==="database"&&((re=($=s.database)==null?void 0:$.connections)!=null&&re.length)){const F=s.database.connections[0];B+=` • ${F.engine} @ ${F.host}`}else s.type==="tests"&&s.folderPath?B=`${I} • ${s.folderPath}`:s.cwd&&(B+=` • ${s.cwd}`);const T=((H=s.pm2Status)==null?void 0:H.ports)||[];let K=`${s.name} ${s.type} ${s.status} ${s.cwd||""} ${((W=s.pm2)==null?void 0:W.name)||""}`;if(s.type==="tests"&&(K+=` ${s.folderPath||""} tests junit maven`),T.length>0&&(K+=` ${T.join(" ")}`),s.type==="database"&&((z=s.database)!=null&&z.connections))for(const F of s.database.connections)K+=` ${F.name} ${F.engine} ${F.host} ${F.database||""} mysql postgresql sql`;return{id:`building-${s.id}`,type:"building",title:s.name,subtitle:B,_ports:T,icon:c.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:4},children:[c.jsx(G,{name:"status-pending",size:10,weight:"fill",color:a}),c.jsx(G,{name:g,size:16})]}),_searchText:K,action:()=>{var F;b.current(),s.type==="boss"?Y.current(s.id):s.type==="database"?J.current(s.id):s.type==="tests"?X.openTestsBuilding(s.id):s.type==="http"?X.openHttpBuilding(s.id):(F=s.pm2)!=null&&F.enabled&&U.current(s.id)}}}):[],[t,A]),vt=l.useMemo(()=>t?Be.map(s=>{const a=s.isGitRepo&&s.gitBranch?`${s.path} • ${s.gitBranch}`:s.path;return{id:`folder-${s.path}`,type:"folder",title:s.name,subtitle:a,matchedText:s.path,icon:c.jsx(G,{name:s.isGitRepo?"git-branch":"folder",size:16}),_searchText:`${s.name} ${s.path}`,_isGitRepo:s.isGitRepo,_gitBranch:s.gitBranch,action:()=>{b.current(),X.openFileExplorer(s.path)}}}):[],[t,Be]),Ve=l.useMemo(()=>t?Pe.map(s=>{const a=s.areaName&&s.areaName!==s.projectName?`${s.projectName} · ${s.areaName}`:s.projectName;return{id:`file-${s.path}`,type:"file",title:s.name,subtitle:s.relativePath,matchedText:`${s.path} ${a}`,icon:kt(s.path),_searchText:`${s.name} ${s.relativePath} ${s.path} ${s.projectName} ${s.areaName}`,_projectName:s.projectName,_areaName:s.areaName,action:()=>{b.current(),Q.current({filePath:s.path,projectRoot:s.projectRoot,searchQuery:R.trim()})}}}):[],[t,Pe,R]),Xe=l.useMemo(()=>t?Qe.map(s=>{const a=s.matches[0],g=s.areaName&&s.areaName!==s.projectName?`${s.projectName} · ${s.areaName}`:s.projectName;return{id:`file-content-${s.path}`,type:"file-content",title:s.name,subtitle:`${s.relativePath}${a!=null&&a.line?`:${a.line}`:""}`,matchedQuery:a==null?void 0:a.content,matchedText:`${s.path} ${g}`,icon:kt(s.path),_projectName:s.projectName,_areaName:s.areaName,_lineNumber:a==null?void 0:a.line,action:()=>{b.current(),Q.current({filePath:s.path,projectRoot:s.projectRoot,targetLine:a==null?void 0:a.line,searchQuery:R.trim()})}}}):[],[t,Qe,R]),Me=l.useMemo(()=>{if(!t)return[];const s=a=>{const g=Date.now()-new Date(a).getTime();return!Number.isFinite(g)||g<0?"":g<36e5?`${Math.max(1,Math.floor(g/6e4))}m`:g<864e5?`${Math.floor(g/36e5)}h`:`${Math.floor(g/864e5)}d`};return S.rows.map(a=>{var W;const g=Array.from(y.values()).find(z=>z.sessionId===a.sessionId),I=g??(a.agentId?y.get(a.agentId):void 0),B=(a.firstPrompt||a.snippet||a.sessionId).slice(0,90),T=[a.projectPath||a.projectDir];I&&T.push(`→ ${I.name}${g?"":" (past session)"}`);const K=(W=a.extracts)==null?void 0:W.map(z=>z.timestamp?Date.parse(z.timestamp):Number.NaN).find(Number.isFinite),$=Date.parse(a.lastModified),re=K??(Number.isFinite($)?$:void 0),H=re===void 0?"":s(re);return H&&T.push(H),T.push(`${a.totalMatches}×`),{id:`session-${a.sessionId}`,type:"session",title:B,subtitle:T.join(" • "),matchedQuery:a.snippet||void 0,matchedExtracts:a.extracts&&a.extracts.length>0?a.extracts:void 0,_agentId:I==null?void 0:I.id,_sessionMatches:a.totalMatches,_sessionNearbyMatches:a.nearbyMatches,_matchedMessageAt:re,_provider:a.provider||"claude",icon:I?c.jsx(Dt,{agent:I,size:20}):c.jsx(G,{name:"history",size:16}),action:()=>{var F;b.current();const z=Array.from(X.getState().agents.values()).find(je=>je.sessionId===a.sessionId);z?(Lt(z.id),X.selectAgent(z.id),X.getState().viewMode!=="flat"&&X.requestTerminalExpand(),X.requestTerminalSearch(z.id,S.query)):(F=le.current)==null||F.call(le,{initialQuery:S.query,initialSessionKey:`${a.projectPath}::${a.sessionId}`})}}})},[t,S,y]),Nt=l.useMemo(()=>new de(be,{keys:["title","subtitle","_searchText","lastUserInput"],threshold:.4,ignoreLocation:!0,includeScore:!0,includeMatches:!0}),[be]),bt=l.useMemo(()=>new de(Oe,{keys:["title","subtitle"],threshold:.4,includeScore:!0,includeMatches:!0}),[Oe]),jt=l.useMemo(()=>new de(We,{keys:["title","subtitle"],threshold:.4,includeScore:!0,includeMatches:!0}),[We]),wt=l.useMemo(()=>new de(qe,{keys:["title","subtitle","_searchText"],threshold:.4,ignoreLocation:!0,includeScore:!0,includeMatches:!0}),[qe]),Re=l.useMemo(()=>{if(!R.trim()){const p=[];p.push(...qe);const _=[...be].sort((w,P)=>{const Z=it(w._agentId,w._lastActivity,Ge);return it(P._agentId,P._lastActivity,Ge)-Z});p.push(..._),p.push(...We.slice(0,2));const j={};return Ut.forEach((w,P)=>{j[w]=P}),p.sort((w,P)=>(j[w.type]??999)-(j[P.type]??999)),p}const s=R.trim().toLowerCase(),a=ke(s),g=Ze(Nt,R).slice(0,30),I=Ze(jt,R).slice(0,2),B=vt.slice(0,8),T=Ve.slice(0,wn),K=Ue.slice(0,Dn),$=Ze(wt,R).filter(p=>{const _=p.score??1,j=`${p.item.title} ${p.item.subtitle||""} ${p.item._searchText||""}`.toLowerCase();return a.every(w=>j.includes(w))||_<=.2}).slice(0,4),re={agent:6,building:5,folder:4,file:4,"file-content":4,setting:4,command:3,area:2,"modified-file":1,session:0},H=p=>Mn(s,p.title,`${p.subtitle||""} ${p._searchText||""} ${p.matchedText||""}`),W=(p,_)=>{const j=(1-Math.min(1,_??1))*4;return H(p)*100+(re[p.type]??0)*5+j},z=new Map,F=(p,_)=>{const j=z.get(p.type),w={item:p,score:W(p,_)};j?j.push(w):z.set(p.type,[w])},je=new Map;for(const p of Me)p._agentId&&!je.has(p._agentId)&&je.set(p._agentId,p);for(const p of g){const _={...p.item};if(_._userQueries&&_._userQueries.length>0){const w=_._userQueries.find(P=>a.some(Z=>P.toLowerCase().includes(Z)));if(w){const P=w.toLowerCase(),Z=P.includes(s)?s:a.find(he=>P.includes(he))??s;if(w.length>200){const he=P.indexOf(Z),Le=Math.max(0,he-60),De=Math.min(w.length,he+Z.length+100);_.matchedQuery=(Le>0?"...":"")+w.slice(Le,De)+(De<w.length?"...":"")}else _.matchedQuery=w}}const j=_._agentId?je.get(_._agentId):void 0;if(j){_.matchedQuery||(_.matchedQuery=j.matchedQuery);const w=_.matchedQuery,P=(w==null?void 0:w.toLowerCase())??"";_.matchedExtracts=In(w&&a.every(Z=>P.includes(Z))?w:void 0,j.matchedExtracts),_.action=j.action,_._sessionMatches=j._sessionMatches,_._sessionNearbyMatches=j._sessionNearbyMatches,_._matchedMessageAt=j._matchedMessageAt,_._searchText=`${_._searchText||""} ${j.matchedQuery||""} ${s}`}F(_,p.score)}for(const[p,_]of je){if(g.some(w=>w.item._agentId===p))continue;const j=Ye.get(p);j&&F({...j,matchedQuery:_.matchedQuery,matchedExtracts:_.matchedExtracts,action:_.action,_sessionMatches:_._sessionMatches,_sessionNearbyMatches:_._sessionNearbyMatches,_matchedMessageAt:_._matchedMessageAt,_searchText:`${j._searchText||""} ${_.matchedQuery||""} ${s}`},void 0)}for(const p of $)F(p.item,p.score);for(const p of I)F(p.item,p.score);for(const p of K)F(p,void 0);for(const p of B)F(p,void 0);for(const p of T)F(p,void 0);for(const p of Xe.slice(0,Ln))F(p,void 0);const cs=24*36e5,ls=Date.now(),Tt=p=>{const _=it(p.item._agentId,p.item._lastActivity,Ge),j=Math.exp(-Math.LN2*Math.max(0,ls-_)/cs),w=p.item._sessionMatches??0,P=Math.log2(1+w),Z=p.item._sessionNearbyMatches;return(Z===void 0?P:Z>0?8+Math.log2(1+Z)+P*.1:P*.2)+(p.item._matchedMessageAt===void 0?2*j:0)};for(const[p,_]of z)p==="agent"?_.sort((j,w)=>{const P=H(j.item),Z=H(w.item);if(Z!==P)return Z-P;const Se=j.item._matchedMessageAt,he=w.item._matchedMessageAt;if(Se!==void 0||he!==void 0){if(Se===void 0)return 1;if(he===void 0)return-1;if(he!==Se)return he-Se}const Le=Tt(j),De=Tt(w);return De!==Le?De-Le:w.score-j.score}):_.sort((j,w)=>w.score-j.score);const Ce=[];for(const p of Ut){if(p==="session"){!Ee&&Me.length>ut?(Ce.push(...Me.slice(0,ut)),Ce.push({id:"session-show-all",type:"session",title:`Show all conversations (${Me.length})`,subtitle:`${Me.length-ut} more matches`,icon:c.jsx(G,{name:"arrow-down",size:16}),action:()=>Mt(!0)})):Ce.push(...Me);continue}const _=z.get(p);if(_){if(p==="agent"&&!Ne&&_.length>ht){for(const j of _.slice(0,ht))Ce.push(j.item);Ce.push({id:"agent-show-all",type:"agent",title:`Show all agents (${_.length})`,subtitle:`${_.length-ht} more matches`,icon:c.jsx(G,{name:"arrow-down",size:16}),action:()=>Te(!0)});continue}for(const j of _)Ce.push(j.item)}}return Ce},[R,Nt,jt,wt,be,Ye,We,qe,Ue,vt,Ve,Xe,Me,Ge,Ne,Ee]),ie=l.useMemo(()=>{switch(ae){case"agents":return Re.filter(s=>s.type==="agent");case"buildings":return Re.filter(s=>s.type==="building");case"commands":return R.trim()?Ze(bt,R).slice(0,3).map(s=>s.item):Oe;case"folders":return Re.filter(s=>s.type==="folder");case"files":return Ve;case"contents":return Xe;case"settings":return Ue;case"areas":return ot.flatMap(s=>s.agents);case"all":default:return Re}},[ae,Re,ot,Ve,Xe,Ue,R,bt,Oe]),os=l.useMemo(()=>{const s=[];if(Ke&&s.push("session"),Ie&&s.push("file"),ze&&s.push("file-content"),se&&s.push("folder"),ae==="all")return s;const g={buildings:"building",folders:"folder",files:"file",contents:"file-content",agents:"agent",settings:"setting",commands:"command"}[ae];return g&&s.includes(g)?[g]:[]},[ae,Ke,Ie,ze,se]);l.useEffect(()=>{V>=ie.length&&ee(Math.max(0,ie.length-1))},[ie.length,V]);const as=l.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 a=s.key.toLowerCase();ee(a==="p"?g=>g>0?g-1:ie.length-1:g=>g<ie.length-1?g+1:0);return}switch(s.key){case"Escape":s.preventDefault(),b.current();break;case"ArrowUp":s.preventDefault(),ee(a=>a>0?a-1:ie.length-1);break;case"ArrowDown":s.preventDefault(),ee(a=>a<ie.length-1?a+1:0);break;case"Enter":s.preventDefault(),ie[V]&&ie[V].action();break}},[ie,V]),is=l.useCallback((s,a)=>{if(!a||!s)return s;const g=ke(a);if(g.length===0)return s;const I=new RegExp(g.map(En).sort((re,H)=>H.length-re.length).join("|"),"gi"),B=[];let T=0,K=0,$;for(;($=I.exec(s))!==null;)$.index>T&&B.push(s.slice(T,$.index)),B.push(ct.createElement("mark",{key:K++,className:"spotlight-highlight"},$[0])),T=$.index+$[0].length;return T<s.length&&B.push(s.slice(T)),B.length>0?ct.createElement(ct.Fragment,null,...B):s},[]);return{query:R,setQuery:ns,selectedIndex:V,setSelectedIndex:ee,results:ie,loadingTypes:os,activeTab:ae,setActiveTab:nt,cycleTab:rs,areaSections:ot,handleKeyDown:as,highlightMatch:is}}const Qn=l.forwardRef(function({query:e,onQueryChange:n,onKeyDown:r,onResetSelection:o,commandMode:i=!1,executingCommand:u=!1},d){const{t:h}=st(["common"]);return c.jsxs("div",{className:`spotlight-input-wrapper${i?" is-command-mode":""}`,children:[c.jsx("span",{className:"spotlight-search-icon",children:i?"›_":"⌘"}),c.jsx("input",{ref:d,type:"text",className:"spotlight-input",placeholder:h("common:search.spotlightPlaceholder"),value:e,onChange:f=>{n(f.target.value),o()},onKeyDown:r,autoFocus:!0,spellCheck:!1,disabled:u,"aria-label":i?"Plugin command":void 0}),c.jsxs("div",{className:"spotlight-input-hints",children:[c.jsx("span",{className:"spotlight-shortcut-hint",children:"↑↓"}),c.jsx("span",{className:"spotlight-shortcut-hint",children:"Enter"}),c.jsx("span",{className:"spotlight-shortcut-hint",children:"Esc"})]})]})}),zn=l.memo(function({activeTab:e,onSelect:n}){const{t:r}=st(["terminal"]);return c.jsxs("div",{className:"spotlight-tabs",role:"tablist","aria-label":r("terminal:spotlight.tabsLabel"),children:[we.map(o=>c.jsx("button",{type:"button",role:"tab","aria-selected":o===e,tabIndex:-1,className:`spotlight-tab${o===e?" active":""}`,onClick:()=>n(o),children:r(`terminal:spotlight.tabs.${o}`)},o)),c.jsx("span",{className:"spotlight-tabs-hint",children:c.jsx("kbd",{children:"Tab"})})]})}),Kn=l.forwardRef(function({results:e,loadingTypes:n,selectedIndex:r,query:o,activeTab:i,areaSections:u,highlightMatch:d,onSelectIndex:h},f){const{t:m}=st(["terminal"]),x=l.useRef(!1);l.useEffect(()=>{x.current=!1},[e]),l.useEffect(()=>{const A=typeof f=="function"?null:f==null?void 0:f.current;if(!A)return;const M=()=>{x.current=!0};return A.addEventListener("mousemove",M),()=>{A.removeEventListener("mousemove",M)}},[f,e]);const y={command:m("terminal:spotlight.categories.commands"),agent:m("terminal:spotlight.categories.agents"),building:m("terminal:spotlight.categories.infrastructure"),setting:m("terminal:spotlight.categories.settings"),area:m("terminal:spotlight.categories.areas"),folder:m("terminal:spotlight.categories.folders"),file:m("terminal:spotlight.categories.files"),"file-content":m("terminal:spotlight.categories.fileContents"),"modified-file":m("terminal:spotlight.categories.modifiedFiles"),session:m("terminal:spotlight.categories.sessions")},E=l.useMemo(()=>{const A=[];let M=null,N=[];e.forEach((b,L)=>{b.type!==M&&(M!==null&&N.length>0&&A.push([M,N]),M=b.type,N=[]),N.push({result:b,index:L})}),M!==null&&N.length>0&&A.push([M,N]);for(const b of n)A.some(([L])=>L===b)||A.push([b,[]]);const D=["agent","session","building","setting","file","file-content","folder","area","command"];return A.sort(([b],[L])=>D.indexOf(b)-D.indexOf(L)),A},[e,n]);if(l.useEffect(()=>{if(!f||typeof f=="function")return;const A=f.current;if(!A)return;const M=A.querySelector(".spotlight-item.selected");M&&M.scrollIntoView({block:"nearest",behavior:"smooth"})},[r,f]),i==="areas"){if(u.length===0)return c.jsx("div",{className:"spotlight-results",ref:f,children:c.jsx("div",{className:"spotlight-empty",children:m("terminal:spotlight.noResults")})});let A=0;return c.jsx("div",{className:"spotlight-results",ref:f,children:u.map(M=>c.jsxs("div",{children:[c.jsxs("div",{className:"spotlight-category-header spotlight-area-section-header",children:[c.jsx("span",{className:"spotlight-area-dot",style:{background:M.areaColor},"aria-hidden":"true"}),c.jsx("span",{className:"spotlight-area-name",children:M.areaName}),c.jsx("span",{className:"spotlight-area-count",children:M.agents.length})]}),M.agents.length===0?c.jsx("div",{className:"spotlight-area-empty",children:m("terminal:spotlight.noAgentsInArea")}):M.agents.map(N=>{const D=A++;return c.jsx(Ft,{result:N,isSelected:D===r,query:o,highlightMatch:d,onClick:()=>N.action(),onMouseEnter:()=>{x.current&&h(D)}},N.id)})]},M.areaId))})}return e.length===0&&n.length===0?c.jsx("div",{className:"spotlight-results",ref:f,children:c.jsx("div",{className:"spotlight-empty",children:m("terminal:spotlight.noResults")})}):c.jsx("div",{className:"spotlight-results",ref:f,children:E.map(([A,M])=>c.jsxs("div",{children:[(i==="all"||E.length>1)&&c.jsx("div",{className:"spotlight-category-header",children:y[A]||A}),n.includes(A)&&c.jsxs("div",{className:"spotlight-block-loading",role:"status",children:[c.jsx("span",{className:"spotlight-loading-spinner","aria-hidden":"true"}),m("terminal:spotlight.searching")]}),M.map(({result:N,index:D})=>c.jsx(Ft,{result:N,isSelected:D===r,query:o,highlightMatch:d,onClick:()=>N.action(),onMouseEnter:()=>{x.current&&h(D)}},N.id))]},A))})}),Gn=l.memo(function({commandMode:e=!1}){const{t:n}=st(["terminal"]);return c.jsxs("div",{className:"spotlight-footer",children:[c.jsxs("div",{className:"spotlight-footer-left",children:[c.jsxs("span",{className:"spotlight-footer-hint",children:[c.jsx("kbd",{children:"↑"}),c.jsx("kbd",{children:"↓"})," ",c.jsx("kbd",{children:"Alt+N"}),c.jsx("kbd",{children:"Alt+P"})," ",n("terminal:spotlight.navigate")]}),c.jsxs("span",{className:"spotlight-footer-hint",children:[c.jsx("kbd",{children:"Enter"})," ",e?"run command":n("terminal:spotlight.select")]}),c.jsxs("span",{className:"spotlight-footer-hint",children:[c.jsx("kbd",{children:"Tab"})," ",e?"complete command":n("terminal:spotlight.switchTabs")]})]}),c.jsx("div",{className:"spotlight-footer-right",children:c.jsxs("span",{className:"spotlight-footer-hint",children:[c.jsx("kbd",{children:"Esc"})," ",n("common:buttons.close")]})})]})});function On({detail:t,onClose:e}){const[n,r]=l.useState(null),[o,i]=l.useState(!0),[u,d]=l.useState(null);_s("spotlight-file-detail",!0,e),l.useEffect(()=>{const E=new AbortController;return i(!0),d(null),r(null),(async()=>{try{const M=await dt(ft(`/api/files/read?path=${encodeURIComponent(t.filePath)}`),{signal:E.signal}),N=await M.json();if(!M.ok)throw new Error(N.error||"Unable to read file");let D=null;if(!N.binary)try{const b=await dt(ft(`/api/files/git-original?path=${encodeURIComponent(t.filePath)}`),{signal:E.signal}),L=await b.json();b.ok&&!L.binary&&typeof L.content=="string"&&(D=L.content)}catch{}E.signal.aborted||r({filename:N.filename||t.filePath.split("/").pop()||t.filePath,content:typeof N.content=="string"?N.content:"",originalContent:D,binary:N.binary===!0})}catch(M){E.signal.aborted||d(M instanceof Error?M.message:"Unable to load file")}finally{E.signal.aborted||i(!1)}})(),()=>E.abort()},[t.filePath]),l.useEffect(()=>{const E=A=>{A.key==="Escape"&&(A.preventDefault(),A.stopImmediatePropagation(),e())};return document.addEventListener("keydown",E,!0),()=>document.removeEventListener("keydown",E,!0)},[e]);const h=()=>{X.revealFileInExplorer(t.filePath,t.projectRoot,t.targetLine),e()},f=(n==null?void 0:n.filename)||t.filePath,m=f.lastIndexOf(".")>=0?f.slice(f.lastIndexOf(".")):"",x=Is(m),y=(n==null?void 0:n.originalContent)!=null&&n.originalContent!==n.content;return c.jsx("div",{className:"guake-git-diff-modal-overlay",onClick:e,children:c.jsxs("div",{className:"guake-git-diff-modal",onClick:E=>E.stopPropagation(),children:[c.jsxs("div",{className:"guake-git-diff-modal-header",children:[c.jsxs("div",{className:"guake-git-diff-path spotlight-file-detail-path",title:t.filePath,children:[t.filePath,t.targetLine?c.jsxs("span",{className:"spotlight-file-detail-line",children:[":",t.targetLine]}):null]}),c.jsxs("button",{type:"button",className:"spotlight-file-detail-explorer",onClick:h,title:"Open in File Explorer",children:[c.jsx(G,{name:"folder-open",size:14}),"Open in File Explorer"]}),c.jsx("button",{className:"guake-git-close",onClick:e,title:"Close (Esc)",children:c.jsx(G,{name:"close",size:14})})]}),c.jsxs("div",{className:"guake-git-diff-content",children:[o&&c.jsx("div",{className:"guake-git-diff-loading-overlay",children:c.jsx("div",{className:"diff-image-spinner"})}),u&&c.jsx("div",{className:"spotlight-file-detail-message",children:u}),(n==null?void 0:n.binary)&&c.jsx("div",{className:"spotlight-file-detail-message",children:"Binary preview is available in the File Explorer."}),n&&!n.binary&&(y?c.jsx($t,{originalContent:n.originalContent||"",modifiedContent:n.content,filename:n.filename,filePath:t.filePath,language:x,searchQuery:t.searchQuery,targetLine:t.targetLine}):c.jsx($t,{originalContent:"",modifiedContent:n.content,filename:n.filename,filePath:t.filePath,language:x,initialModifiedOnly:!0,searchQuery:t.searchQuery,targetLine:t.targetLine,readOnly:!0}))]})]})})}const Un=l.forwardRef(function({commands:e,selectedIndex:n,executing:r,error:o,onSelectIndex:i,onExecute:u},d){return l.useEffect(()=>{var h,f;!d||typeof d=="function"||(f=(h=d.current)==null?void 0:h.querySelector(".spotlight-command-item.selected"))==null||f.scrollIntoView({block:"nearest"})},[d,n]),c.jsxs("div",{className:"spotlight-results spotlight-command-results",ref:d,children:[c.jsxs("div",{className:"spotlight-command-mode-banner",children:[c.jsx("span",{className:"spotlight-command-mode-icon",children:c.jsx(G,{name:"terminal",size:13})}),c.jsxs("div",{children:[c.jsx("strong",{children:"Plugin command mode"}),c.jsx("span",{children:"Runs locally without sending a prompt to an AI agent"})]})]}),o&&c.jsxs("div",{className:"spotlight-command-error",role:"alert",children:[c.jsx(G,{name:"warn",size:13}),c.jsx("span",{children:o})]}),e.length===0?c.jsxs("div",{className:"spotlight-empty spotlight-command-empty",children:[c.jsx(G,{name:"search",size:18}),c.jsx("strong",{children:"No matching plugin command"}),c.jsxs("span",{children:["Type ",c.jsx("code",{children:"/"})," to see enabled plugin commands."]})]}):e.map((h,f)=>c.jsxs("button",{type:"button",className:`spotlight-item spotlight-command-item${f===n?" selected":""}`,disabled:r,onMouseEnter:()=>i(f),onClick:()=>u(h),children:[c.jsx("span",{className:"spotlight-item-icon spotlight-command-item-icon",children:c.jsx(G,{name:"plug",size:16})}),c.jsxs("span",{className:"spotlight-item-content",children:[c.jsxs("span",{className:"spotlight-item-header",children:[c.jsx("code",{className:"spotlight-command-name",children:h.name}),h.name!==h.canonicalName&&c.jsxs("span",{className:"spotlight-command-alias",children:["alias of ",h.canonicalName]})]}),c.jsx("span",{className:"spotlight-item-subtitle",children:h.summary})]}),c.jsx("span",{className:"spotlight-command-plugin-badge",children:h.pluginName}),r&&f===n?c.jsx("span",{className:"spotlight-loading-spinner","aria-label":"Running command"}):c.jsx("span",{className:"spotlight-command-enter",children:"↵"})]},`${h.pluginId}:${h.name}`))]})}),Hn=768;function Xn({isOpen:t,onClose:e,onOpenSpawnModal:n,onOpenCommanderView:r,onOpenToolbox:o,onOpenFileExplorer:i,onOpenPM2LogsModal:u,onOpenBossLogsModal:d,onOpenDatabasePanel:h,onOpenMonitoringModal:f,onOpenSessionFinder:m}){const x=l.useRef(null),y=l.useRef(null),E=l.useRef(null),A=l.useRef(0),M=l.useRef(!1),N=l.useRef(()=>{}),[D,b]=l.useState(null),[L,O]=l.useState(0),[ce,me]=l.useState(!1),[U,Y]=l.useState(null),[J,oe]=l.useState(null),le=vs(),{query:Q,setQuery:R,selectedIndex:q,setSelectedIndex:V,results:ee,loadingTypes:ae,activeTab:$e,setActiveTab:Be,cycleTab:ge,areaSections:Pe,handleKeyDown:pe,highlightMatch:Qe}=Pn({isOpen:t,onClose:e,onOpenSpawnModal:n,onOpenCommanderView:r,onOpenToolbox:o,onOpenFileExplorer:i,onOpenPM2LogsModal:u,onOpenBossLogsModal:d,onOpenDatabasePanel:h,onOpenMonitoringModal:f,onOpenSessionFinder:m,onOpenFileDetail:b}),te=Q.startsWith("/"),se=l.useMemo(()=>Ns(Q,bs()),[Q,le]),ye=l.useCallback(()=>{const v=se[L];if(!v)return;const S=Q.trim().replace(/^\S+/,"");R(`${v.name}${S}`),O(0)},[se,L,Q,R]),Ie=l.useCallback(async v=>{me(!0),Y(null);try{const S=v.pluginId===js||v.requiresAgent?X.getState().selectedAgentIds.values().next().value:void 0,k=await ws(v,Q,{agentId:S});k.kind==="output"&&oe(k),e()}catch(S){Y(S instanceof Error?S.message:String(S))}finally{me(!1)}},[e,Q]);A.current=te?se.length:ee.length,M.current=te,N.current=ye;const xe=l.useRef(ge);xe.current=ge,l.useEffect(()=>{t&&(oe(null),Y(null),setTimeout(()=>{var v,S;(v=x.current)==null||v.focus(),(S=x.current)==null||S.select()},50))},[t]),l.useEffect(()=>{if(!t)return;const v=window.visualViewport;if(!v||window.innerWidth>Hn)return;const S=()=>{const k=y.current;k&&(k.style.height=`${v.height}px`,k.style.top=`${v.offsetTop}px`)};return S(),v.addEventListener("resize",S),v.addEventListener("scroll",S),()=>{v.removeEventListener("resize",S),v.removeEventListener("scroll",S);const k=y.current;k&&(k.style.height="",k.style.top="")}},[t]),l.useEffect(()=>{if(!t)return;const v=S=>{if(S.key==="Escape"){S.preventDefault(),S.stopPropagation(),S.stopImmediatePropagation(),e();return}if(S.key==="Tab"){S.preventDefault(),S.stopPropagation(),S.stopImmediatePropagation(),M.current?N.current():xe.current(S.shiftKey?-1:1);return}if(S.altKey&&!S.ctrlKey&&!S.metaKey&&(S.key==="n"||S.key==="p"||S.key==="N"||S.key==="P")){S.preventDefault(),S.stopPropagation(),S.stopImmediatePropagation();const k=S.key.toLowerCase(),Ne=A.current;if(Ne===0)return;const Te=Ee=>k==="p"?Ee>0?Ee-1:Ne-1:Ee<Ne-1?Ee+1:0;M.current?O(Te):V(Te);return}};return window.addEventListener("keydown",v,{capture:!0}),()=>{window.removeEventListener("keydown",v,{capture:!0})}},[t,e]);const ze=l.useCallback(v=>{v.target===v.currentTarget&&e()},[e]),ve=l.useCallback(()=>{V(0),O(0),Y(null)},[V]);l.useEffect(()=>{L>=se.length&&O(Math.max(0,se.length-1))},[se.length,L]);const Ke=l.useCallback(v=>{if(!te){pe(v);return}const S=se.length;if(v.key==="ArrowUp"||v.key==="ArrowDown"){if(v.preventDefault(),S===0)return;O(k=>v.key==="ArrowUp"?k>0?k-1:S-1:k<S-1?k+1:0);return}if(v.key==="Tab"){v.preventDefault(),ye();return}if(v.key==="Enter"){v.preventDefault();const k=se[L];k&&!ce&&Ie(k)}},[se,te,L,ye,Ie,ce,pe]);return t?c.jsx("div",{ref:y,className:"spotlight-overlay",onClick:ze,children:c.jsxs("div",{className:"spotlight-modal",children:[c.jsx(Qn,{ref:x,query:Q,onQueryChange:R,onKeyDown:Ke,onResetSelection:ve,commandMode:te,executingCommand:ce}),!te&&c.jsx(zn,{activeTab:$e,onSelect:Be}),te?c.jsx(Un,{ref:E,commands:se,selectedIndex:L,executing:ce,error:U,onSelectIndex:O,onExecute:v=>void Ie(v)}):c.jsx(Kn,{ref:E,results:ee,loadingTypes:ae,selectedIndex:q,query:Q,activeTab:$e,areaSections:Pe,highlightMatch:Qe,onSelectIndex:V}),c.jsx(Gn,{commandMode:te})]})}):J?c.jsx(Ts,{command:J.command,output:J.output,onClose:()=>oe(null)}):D?c.jsx(On,{detail:D,onClose:()=>b(null)}):null}export{er as FILE_ICON_NAMES,Xn as Spotlight,Gn as SpotlightFooter,Qn as SpotlightInput,Ft as SpotlightItem,Kn as SpotlightResults,tr as formatDuration,sr as formatRelativeTime,nr as getAgentIcon,kt as getFileIconFromPath,rr as getTypeLabel,Pn as useSpotlightSearch};
|