@flemist/mcp-project-tools 3.0.3 → 3.0.4

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.
@@ -1,21 +1,21 @@
1
1
  import G from "express";
2
- import * as st from "cors";
3
- import { McpServer as ot } from "@modelcontextprotocol/sdk/server/mcp.js";
4
- import { randomBytes as nt } from "crypto";
5
- import { StreamableHTTPServerTransport as it } from "@modelcontextprotocol/sdk/server/streamableHttp.js";
6
- import * as F from "fs";
2
+ import * as ot from "cors";
3
+ import { McpServer as nt } from "@modelcontextprotocol/sdk/server/mcp.js";
4
+ import { randomBytes as it } from "crypto";
5
+ import { StreamableHTTPServerTransport as at } from "@modelcontextprotocol/sdk/server/streamableHttp.js";
6
+ import * as B from "fs";
7
7
  import * as T from "path";
8
- import at from "path";
9
- import { spawn as lt } from "child_process";
8
+ import lt from "path";
9
+ import { spawn as ct } from "child_process";
10
10
  import { z as p } from "zod";
11
11
  import K from "tree-kill";
12
- import { Pool as ct, poolRunWait as L } from "@flemist/time-limits";
13
- import { priorityCreate as P } from "@flemist/priority-queue";
14
- import { useAbortController as ut, combineAbortSignals as dt } from "@flemist/async-utils";
15
- import ft from "node:os";
12
+ import { Pool as ut, poolRunWait as L } from "@flemist/time-limits";
13
+ import { priorityCreate as z } from "@flemist/priority-queue";
14
+ import { useAbortController as dt, combineAbortSignals as ft } from "@flemist/async-utils";
15
+ import ht from "node:os";
16
16
  import mt from "picomatch";
17
- import { webkit as ht, firefox as pt, chromium as gt } from "playwright";
18
- function wt(t) {
17
+ import { webkit as pt, firefox as gt, chromium as wt } from "playwright";
18
+ function yt(t) {
19
19
  const { authToken: r } = t;
20
20
  return function(o, e, n) {
21
21
  if ((o.query.token || o.headers.authorization?.replace("Bearer ", "")) !== r) {
@@ -28,39 +28,57 @@ function wt(t) {
28
28
  async function q(t) {
29
29
  const { logFilePath: r, message: s, data: o } = t;
30
30
  try {
31
- const e = (/* @__PURE__ */ new Date()).toISOString().replace(/[TZ]/g, " ").trim(), n = typeof o == "string" ? o : JSON.stringify(o, null, 2), i = `[${e}] ${s}
31
+ const e = (/* @__PURE__ */ new Date()).toISOString().replace(/[TZ]/g, " ").trim(), n = typeof o == "string" ? o : JSON.stringify(o, null, 2), a = `[${e}] ${s}
32
32
  ${n}
33
33
 
34
34
  `;
35
- await F.promises.mkdir(T.dirname(r), { recursive: !0 }), await F.promises.appendFile(r, i);
35
+ await B.promises.mkdir(T.dirname(r), { recursive: !0 }), await B.promises.appendFile(r, a);
36
36
  } catch (e) {
37
37
  console.error(`Failed to log "${s}":`, e);
38
38
  }
39
39
  }
40
- const z = /* @__PURE__ */ new Map();
41
- function yt(t, r) {
42
- return async function(o, e) {
43
- const n = o.headers["mcp-session-id"] || o.headers["x-session-id"] || o.query.token;
44
- let i;
45
- o.method === "POST" ? (await q({
46
- logFilePath: r.logFilePath,
47
- message: "REQUEST",
48
- data: o.body
49
- }), n && z.has(n) ? i = z.get(n) : (i = new it({
50
- sessionIdGenerator: () => n || nt(16).toString("hex"),
51
- onsessioninitialized: (a) => {
52
- z.set(a, i), console.log(`Session initialized: ${a}`);
53
- },
54
- enableJsonResponse: r.enableJsonResponse || !1
55
- }), i.onclose = () => {
56
- i.sessionId && (z.delete(i.sessionId), console.log(`Session closed: ${i.sessionId}`));
57
- }, await t.connect(i), n && z.set(n, i)), await i.handleRequest(o, e, o.body)) : o.method === "GET" ? n && z.has(n) ? (i = z.get(n), await i.handleRequest(o, e)) : e.status(400).json({ error: "No valid session" }) : e.status(405).json({ error: "Method not allowed" });
40
+ const P = /* @__PURE__ */ new Map();
41
+ function bt(t) {
42
+ return async function(s, o) {
43
+ const e = s.headers["mcp-session-id"] || s.headers["x-session-id"] || s.query.token;
44
+ if (s.method === "POST") {
45
+ await q({
46
+ logFilePath: t.logFilePath,
47
+ message: "REQUEST",
48
+ data: s.body
49
+ });
50
+ let n = e ? P.get(e) : null;
51
+ if (!n) {
52
+ const a = new at({
53
+ sessionIdGenerator: () => e || it(16).toString("hex"),
54
+ onsessioninitialized: (u) => {
55
+ const l = {
56
+ transport: a,
57
+ server: i
58
+ };
59
+ P.set(u, l), console.log(`Session initialized: ${u}`);
60
+ },
61
+ enableJsonResponse: !0
62
+ }), i = t.createMcpServer();
63
+ n = {
64
+ transport: a,
65
+ server: i
66
+ }, a.onclose = () => {
67
+ a.sessionId && (P.delete(a.sessionId), console.log(`Session closed: ${a.sessionId}`));
68
+ }, await i.connect(a), e && P.set(e, n);
69
+ }
70
+ await n.transport.handleRequest(s, o, s.body);
71
+ } else if (s.method === "GET") {
72
+ const n = e ? P.get(e) : null;
73
+ n ? await n.transport.handleRequest(s, o) : o.status(400).json({ error: "No valid session" });
74
+ } else
75
+ o.status(405).json({ error: "Method not allowed" });
58
76
  };
59
77
  }
60
78
  const O = /* @__PURE__ */ new Map();
61
- let bt = 0;
62
- const ie = 10, xt = 1800 * 1e3, k = 2e3, St = 500, $t = 5e3;
63
- function It(t) {
79
+ let xt = 0;
80
+ const ie = 10, St = 1800 * 1e3, k = 2e3, $t = 500, It = 5e3;
81
+ function Mt(t) {
64
82
  const { commandLine: r, commandLineRules: s } = t;
65
83
  let o = !1;
66
84
  for (const e of s)
@@ -77,11 +95,11 @@ function It(t) {
77
95
  }
78
96
  return o;
79
97
  }
80
- function Mt() {
81
- return ++bt;
98
+ function Tt() {
99
+ return ++xt;
82
100
  }
83
101
  let ae = !1;
84
- function Tt() {
102
+ function vt() {
85
103
  if (ae)
86
104
  return;
87
105
  ae = !0;
@@ -101,26 +119,26 @@ function Tt() {
101
119
  function Q() {
102
120
  const t = Date.now(), r = [];
103
121
  for (const [s, o] of Array.from(O.entries()))
104
- !o.isRunning && o.endTime && t - o.endTime.getTime() > xt && r.push(s);
122
+ !o.isRunning && o.endTime && t - o.endTime.getTime() > St && r.push(s);
105
123
  for (const s of r)
106
124
  O.delete(s);
107
125
  }
108
126
  function H(t) {
109
127
  const { process: r } = t, s = Date.now();
110
- if (s - r.lastOutputTime.getTime() >= St && (r.output += r.localOutput, r.localOutput = "", r.lastOutputTime = new Date(s), r.output.length > k)) {
128
+ if (s - r.lastOutputTime.getTime() >= $t && (r.output += r.localOutput, r.localOutput = "", r.lastOutputTime = new Date(s), r.output.length > k)) {
111
129
  const n = `
112
130
  ... [${r.output.length - k} characters trimmed] ...
113
- `, i = k - n.length;
114
- if (i > 0) {
115
- const a = Math.floor(i / 2);
116
- r.output = r.output.substring(0, a) + n + r.output.substring(
117
- r.output.length - (i - a)
131
+ `, a = k - n.length;
132
+ if (a > 0) {
133
+ const i = Math.floor(a / 2);
134
+ r.output = r.output.substring(0, i) + n + r.output.substring(
135
+ r.output.length - (a - i)
118
136
  );
119
137
  } else
120
138
  r.output = r.output.substring(0, k);
121
139
  }
122
140
  }
123
- function vt(t, r) {
141
+ function Ct(t, r) {
124
142
  const s = r.limit;
125
143
  if (t.length <= s) return t;
126
144
  const e = `
@@ -128,8 +146,8 @@ function vt(t, r) {
128
146
  `, n = s - e.length;
129
147
  if (n <= 0)
130
148
  return t.substring(0, s);
131
- const i = Math.floor(n / 2);
132
- return t.substring(0, i) + e + t.substring(t.length - (n - i));
149
+ const a = Math.floor(n / 2);
150
+ return t.substring(0, a) + e + t.substring(t.length - (n - a));
133
151
  }
134
152
  function C(t) {
135
153
  return `Invalid arguments: ${t instanceof Error ? t.message : "Unknown error"}.
@@ -160,7 +178,7 @@ async function Y(t, r) {
160
178
  error: `Process ${o} not found. The process may have already completed and been cleaned up after 30 minutes, or the ID may be incorrect. Use process-list to see available processes and their current status.`
161
179
  };
162
180
  H({ process: n });
163
- const i = n.output + n.localOutput, a = vt(i, { limit: e });
181
+ const a = n.output + n.localOutput, i = Ct(a, { limit: e });
164
182
  return n.output = "", n.localOutput = "", {
165
183
  id: n.id,
166
184
  cwd: T.relative(r.workingDir || "", n.cwd),
@@ -170,11 +188,11 @@ async function Y(t, r) {
170
188
  endTime: n.endTime?.toISOString().replace(/[TZ]/g, " ").trim(),
171
189
  exitCode: n.exitCode,
172
190
  isRunning: n.isRunning,
173
- output: a,
191
+ output: i,
174
192
  error: n.error
175
193
  };
176
194
  }
177
- function Ct(t, r) {
195
+ function kt(t, r) {
178
196
  t(
179
197
  "process-status",
180
198
  {
@@ -203,7 +221,7 @@ function Me(t) {
203
221
  K(t, "SIGKILL", (r) => {
204
222
  r && !r.message.includes("not found") && console.error(`Error sending SIGKILL to process ${t}:`, r);
205
223
  });
206
- }, $t);
224
+ }, It);
207
225
  }
208
226
  const Te = p.object({
209
227
  id: p.number().describe(
@@ -223,32 +241,32 @@ async function ve(t, r) {
223
241
  let s;
224
242
  try {
225
243
  s = Te.parse(t);
226
- } catch (m) {
244
+ } catch (h) {
227
245
  return {
228
- error: C(m)
246
+ error: C(h)
229
247
  };
230
248
  }
231
- const { id: o, waitTime: e, autoKill: n, outputLimit: i } = s, a = O.get(o);
232
- if (!a)
249
+ const { id: o, waitTime: e, autoKill: n, outputLimit: a } = s, i = O.get(o);
250
+ if (!i)
233
251
  return {
234
252
  error: `Process ${o} not found. The process may have already completed and been cleaned up after 30 minutes, or the ID may be incorrect. Use process-list to see available processes and their current status.`
235
253
  };
236
254
  const u = Date.now();
237
255
  let l = !1, c = !1;
238
- e != null && await new Promise((h) => {
256
+ e != null && await new Promise((m) => {
239
257
  const g = setInterval(() => {
240
- a.isRunning ? Date.now() - u >= e * 1e3 && (clearInterval(g), l = !0, n && a.pid && (Me(a.pid), c = !0), h()) : (clearInterval(g), h());
258
+ i.isRunning ? Date.now() - u >= e * 1e3 && (clearInterval(g), l = !0, n && i.pid && (Me(i.pid), c = !0), m()) : (clearInterval(g), m());
241
259
  }, 100);
242
260
  });
243
261
  const f = (Date.now() - u) / 1e3;
244
262
  return {
245
- ...await Y({ id: o, outputLimit: i }, r),
263
+ ...await Y({ id: o, outputLimit: a }, r),
246
264
  waitDuration: f,
247
265
  waitTimeExceeded: l,
248
266
  autoKillExecuted: c
249
267
  };
250
268
  }
251
- function kt(t, r) {
269
+ function Nt(t, r) {
252
270
  t(
253
271
  "process-wait",
254
272
  {
@@ -287,7 +305,7 @@ const Ce = p.object({
287
305
  `Maximum number of output characters to capture and return from the process. Output exceeding this limit will be truncated with beginning/end preserved and middle removed. Maximum: ${k} characters. Default: ${k}.`
288
306
  )
289
307
  });
290
- async function Nt(t, r) {
308
+ async function Dt(t, r) {
291
309
  Q();
292
310
  let s;
293
311
  try {
@@ -297,10 +315,10 @@ async function Nt(t, r) {
297
315
  error: C(d)
298
316
  };
299
317
  }
300
- const { commandLine: o, waitTime: e, autoKill: n, outputLimit: i } = s, { commandLineRules: a } = r, u = T.resolve(r.workingDir || "", s.cwd || "");
301
- if (!It({ commandLine: o, commandLineRules: a })) {
302
- const d = a.map(
303
- (m) => `${m.rule.toUpperCase()}: /${m.regexp}/ (${m.note})`
318
+ const { commandLine: o, waitTime: e, autoKill: n, outputLimit: a } = s, { commandLineRules: i } = r, u = T.resolve(r.workingDir || "", s.cwd || "");
319
+ if (!Mt({ commandLine: o, commandLineRules: i })) {
320
+ const d = i.map(
321
+ (h) => `${h.rule.toUpperCase()}: /${h.regexp}/ (${h.note})`
304
322
  ).join(`
305
323
  `);
306
324
  return {
@@ -316,7 +334,7 @@ To use this command line, ask the user to modify the command line rules in the c
316
334
  return {
317
335
  error: `Maximum concurrent process limit reached (${ie} processes). Cannot start new process until existing processes complete. Use process-list to see active processes, or process-kill to terminate unnecessary processes.`
318
336
  };
319
- const c = Mt(), f = {
337
+ const c = Tt(), f = {
320
338
  id: c,
321
339
  cwd: u,
322
340
  commandLine: o,
@@ -328,18 +346,18 @@ To use this command line, ask the user to modify the command line rules in the c
328
346
  };
329
347
  O.set(c, f);
330
348
  try {
331
- const d = lt(o, [], {
349
+ const d = ct(o, [], {
332
350
  shell: !0,
333
351
  cwd: u,
334
352
  stdio: ["pipe", "pipe", "pipe"]
335
353
  });
336
354
  f.pid = d.pid;
337
- const m = (h) => {
338
- const g = h.toString();
355
+ const h = (m) => {
356
+ const g = m.toString();
339
357
  f.localOutput += g, H({ process: f }), console.log(g);
340
358
  };
341
- return d.stdout?.on("data", m), d.stderr?.on("data", m), d.on("close", (h) => {
342
- if (f.isRunning = !1, f.endTime = /* @__PURE__ */ new Date(), f.exitCode = h !== null ? h : void 0, f.output += f.localOutput, f.localOutput = "", f.output.length > k) {
359
+ return d.stdout?.on("data", h), d.stderr?.on("data", h), d.on("close", (m) => {
360
+ if (f.isRunning = !1, f.endTime = /* @__PURE__ */ new Date(), f.exitCode = m !== null ? m : void 0, f.output += f.localOutput, f.localOutput = "", f.output.length > k) {
343
361
  const b = `
344
362
  ... [${f.output.length - k} characters trimmed] ...
345
363
  `, y = k - b.length;
@@ -351,15 +369,15 @@ To use this command line, ask the user to modify the command line rules in the c
351
369
  } else
352
370
  f.output = f.output.substring(0, k);
353
371
  }
354
- console.log(`Process ${c} (${o}) exited with code ${h}`);
355
- }), d.on("error", (h) => {
356
- f.isRunning = !1, f.endTime = /* @__PURE__ */ new Date(), f.error = h.message, console.error(`Process ${c} error:`, h.message);
357
- }), e != null ? ve({ id: c, waitTime: e, autoKill: n, outputLimit: i }, r) : Y({ id: c, outputLimit: i }, r);
372
+ console.log(`Process ${c} (${o}) exited with code ${m}`);
373
+ }), d.on("error", (m) => {
374
+ f.isRunning = !1, f.endTime = /* @__PURE__ */ new Date(), f.error = m.message, console.error(`Process ${c} error:`, m.message);
375
+ }), e != null ? ve({ id: c, waitTime: e, autoKill: n, outputLimit: a }, r) : Y({ id: c, outputLimit: a }, r);
358
376
  } catch (d) {
359
377
  return f.isRunning = !1, f.endTime = /* @__PURE__ */ new Date(), f.error = d instanceof Error ? d.message : "Unknown error", { error: f.error };
360
378
  }
361
379
  }
362
- function Dt(t, r) {
380
+ function Et(t, r) {
363
381
  const s = r.commandLineRules.map((o) => `${o.rule.toUpperCase()}: ${o.regexp} (${o.note})`).join(`
364
382
  `);
365
383
  t(
@@ -371,7 +389,7 @@ ${s}`,
371
389
  inputSchema: Ce.shape
372
390
  },
373
391
  async (o) => {
374
- const e = await Nt(o, r);
392
+ const e = await Dt(o, r);
375
393
  if (!("output" in e))
376
394
  return `Method: process-run(${JSON.stringify(o)})
377
395
  ❌ Error: ${e.error}`;
@@ -398,7 +416,7 @@ const ke = p.object({
398
416
  'Specific process data fields to include in the response. If omitted, returns all available fields. Available fields: id, cwd, commandLine, pid, startTime, endTime, exitCode, isRunning, output, error. Examples: ["id", "commandLine", "isRunning"] for minimal info, ["id", "output", "exitCode"] for execution results'
399
417
  )
400
418
  });
401
- async function Et(t, r) {
419
+ async function Ft(t, r) {
402
420
  Q();
403
421
  let s;
404
422
  try {
@@ -408,21 +426,21 @@ async function Et(t, r) {
408
426
  error: C(l)
409
427
  };
410
428
  }
411
- const { minOpenDateTime: o, minCloseDateTime: e, activeOnly: n, fields: i } = s;
412
- let a = Array.from(O.values());
429
+ const { minOpenDateTime: o, minCloseDateTime: e, activeOnly: n, fields: a } = s;
430
+ let i = Array.from(O.values());
413
431
  if (o) {
414
432
  const l = new Date(o.replace(/[_\s]/g, "T"));
415
- a = a.filter((c) => c.startTime >= l);
433
+ i = i.filter((c) => c.startTime >= l);
416
434
  }
417
435
  if (e) {
418
436
  const l = new Date(e.replace(/[_\s]/g, "T"));
419
- a = a.filter((c) => c.endTime && c.endTime >= l);
437
+ i = i.filter((c) => c.endTime && c.endTime >= l);
420
438
  }
421
- return n && (a = a.filter((l) => l.isRunning)), { processes: a.map((l) => {
439
+ return n && (i = i.filter((l) => l.isRunning)), { processes: i.map((l) => {
422
440
  H({ process: l });
423
441
  let c = {
424
442
  id: l.id,
425
- cwd: at.relative(r.workingDir || "", l.cwd),
443
+ cwd: lt.relative(r.workingDir || "", l.cwd),
426
444
  commandLine: l.commandLine,
427
445
  pid: l.pid,
428
446
  startTime: l.startTime.toISOString().replace(/[TZ]/g, " ").trim(),
@@ -432,9 +450,9 @@ async function Et(t, r) {
432
450
  output: l.output + l.localOutput,
433
451
  error: l.error
434
452
  };
435
- if (i) {
453
+ if (a) {
436
454
  const f = {};
437
- for (const d of i)
455
+ for (const d of a)
438
456
  d in c && (f[d] = c[d]);
439
457
  c = f;
440
458
  }
@@ -450,7 +468,7 @@ function Bt(t, r) {
450
468
  inputSchema: ke.shape
451
469
  },
452
470
  async (s) => {
453
- const o = await Et(s, r);
471
+ const o = await Ft(s, r);
454
472
  if (o.error != null)
455
473
  return `Method: process-list(${JSON.stringify(s)})
456
474
  ❌ Error: ${o.error}`;
@@ -469,7 +487,7 @@ const Ne = p.object({
469
487
  "Process ID of the process to terminate. Get process IDs using process-list. The process must be currently running. Examples: 1, 42, 123"
470
488
  )
471
489
  });
472
- function Ft(t) {
490
+ function Ot(t) {
473
491
  let r;
474
492
  try {
475
493
  r = Ne.parse(t);
@@ -499,7 +517,7 @@ function Ft(t) {
499
517
  };
500
518
  }
501
519
  }
502
- function Ot(t, r) {
520
+ function Rt(t, r) {
503
521
  t(
504
522
  "process-kill",
505
523
  {
@@ -508,15 +526,15 @@ function Ot(t, r) {
508
526
  inputSchema: Ne.shape
509
527
  },
510
528
  async (s) => {
511
- const o = Ft(s);
529
+ const o = Ot(s);
512
530
  return o.error != null ? `Method: process-kill(${JSON.stringify(s)})
513
531
  ❌ Error: ${o.error}` : `Method: process-kill(${JSON.stringify(s)})
514
532
  ${JSON.stringify(o, null, 2)}`;
515
533
  }
516
534
  );
517
535
  }
518
- function Rt(t, r) {
519
- Tt(), r.run && Dt(t, r), r.status && Ct(t, r), r.wait && kt(t, r), r.list && Bt(t, r), r.kill && Ot(t);
536
+ function zt(t, r) {
537
+ vt(), r.run && Et(t, r), r.status && kt(t, r), r.wait && Nt(t, r), r.list && Bt(t, r), r.kill && Rt(t);
520
538
  const s = r.commandLineRules?.map(
521
539
  (o) => `${o.rule.toUpperCase()}: ${o.regexp} (${o.note})`
522
540
  ) || [];
@@ -529,15 +547,15 @@ ${s.map((o) => `- ${o}`).join(`
529
547
  `
530
548
  );
531
549
  }
532
- function zt(t, r) {
550
+ function Pt(t, r) {
533
551
  return function(o, e, n) {
534
- const i = async (...a) => {
552
+ const a = async (...i) => {
535
553
  await q({
536
554
  logFilePath: r.logFilePath,
537
555
  message: "REQUEST",
538
- data: { name: o, args: a }
556
+ data: { name: o, args: i }
539
557
  });
540
- const u = await n(...a);
558
+ const u = await n(...i);
541
559
  return await q({
542
560
  logFilePath: r.logFilePath,
543
561
  message: "RESPONSE",
@@ -554,27 +572,27 @@ function zt(t, r) {
554
572
  return t.registerTool(
555
573
  o,
556
574
  e,
557
- i
575
+ a
558
576
  );
559
577
  };
560
578
  }
561
- function Pt(t) {
579
+ function Lt(t) {
562
580
  return t.match(/^[/\\]?[^/\\]+/)[0];
563
581
  }
564
- function Lt(t, r) {
565
- return Pt(t) + "|" + r.ino;
582
+ function Ut(t, r) {
583
+ return Lt(t) + "|" + r.ino;
566
584
  }
567
- function Ut(t) {
585
+ function At(t) {
568
586
  return t.endsWith(":") && (t += "/"), T.resolve(t);
569
587
  }
570
- const De = new ct(ft.cpus().length);
588
+ const De = new ut(ht.cpus().length);
571
589
  function le(t, r) {
572
590
  t.totalSize += r.totalSize, t.maxFileDateModified = Math.max(
573
591
  t.maxFileDateModified,
574
592
  r.maxFileDateModified
575
593
  ), t.countFiles += r.countFiles, t.countDirs += r.countDirs, t.countLinks += r.countLinks;
576
594
  }
577
- const At = function(r) {
595
+ const Gt = function(r) {
578
596
  return r.code === "ENOENT";
579
597
  };
580
598
  function Ee(t) {
@@ -587,16 +605,16 @@ function Ee(t) {
587
605
  countDirs: 0,
588
606
  countLinks: 0
589
607
  });
590
- const s = t.level ?? 0, o = t.walkedIds ?? /* @__PURE__ */ new Set(), e = t.abortSignal, n = t.pool ?? De, i = t.handleError, a = t.priority ?? P(0), u = t.walkLinks ?? !1, l = t.log, c = t.handlePath, f = t.matchPath;
591
- async function d(h) {
592
- if (!(i && await i(h)) && !At(h))
593
- throw h;
608
+ const s = t.level ?? 0, o = t.walkedIds ?? /* @__PURE__ */ new Set(), e = t.abortSignal, n = t.pool ?? De, a = t.handleError, i = t.priority ?? z(0), u = t.walkLinks ?? !1, l = t.log, c = t.handlePath, f = t.matchPath;
609
+ async function d(m) {
610
+ if (!(a && await a(m)) && !Gt(m))
611
+ throw m;
594
612
  }
595
- function m(h) {
596
- return !(!l || l.minTotalContentSize != null && h < l.minTotalContentSize || l.maxNestedLevel != null && s > l.maxNestedLevel);
613
+ function h(m) {
614
+ return !(!l || l.minTotalContentSize != null && m < l.minTotalContentSize || l.maxNestedLevel != null && s > l.maxNestedLevel);
597
615
  }
598
- return ut(async (h) => {
599
- const g = dt(e, h), b = {
616
+ return dt(async (m) => {
617
+ const g = ft(e, m), b = {
600
618
  totalSize: 0,
601
619
  maxFileDateModified: 0,
602
620
  countFiles: 0,
@@ -604,7 +622,7 @@ function Ee(t) {
604
622
  countLinks: 0
605
623
  };
606
624
  function y(w, M) {
607
- if (m(M.totalSize)) {
625
+ if (h(M.totalSize)) {
608
626
  const v = `${M.totalSize.toLocaleString("en-US").replace(/,/g, " ").padStart(19)}: ${w}`;
609
627
  l?.handleLog ? l.handleLog(v) : console.log(v);
610
628
  }
@@ -635,14 +653,14 @@ function Ee(t) {
635
653
  v || (v = w);
636
654
  const D = await L({
637
655
  pool: n,
638
- func: () => F.promises.lstat(w).catch(d),
656
+ func: () => B.promises.lstat(w).catch(d),
639
657
  count: 1,
640
- priority: P(M, P(1, a)),
658
+ priority: z(M, z(1, i)),
641
659
  abortSignal: g
642
660
  });
643
661
  if (!D || !$ && D.isFile())
644
662
  return null;
645
- const ne = Lt(w, D);
663
+ const ne = Ut(w, D);
646
664
  if (o.has(ne))
647
665
  return null;
648
666
  o.add(ne);
@@ -653,21 +671,21 @@ function Ee(t) {
653
671
  countDirs: 0,
654
672
  countLinks: 0
655
673
  };
656
- const U = P(
674
+ const U = z(
657
675
  M,
658
- P(D.isDirectory() ? 2 : 3, a)
676
+ z(D.isDirectory() ? 2 : 3, i)
659
677
  );
660
678
  if (D.isSymbolicLink()) {
661
679
  if (u) {
662
- const B = await L({
680
+ const F = await L({
663
681
  pool: n,
664
- func: () => F.promises.readlink(w).catch(d).then((R) => R ?? null),
682
+ func: () => B.promises.readlink(w).catch(d).then((R) => R ?? null),
665
683
  count: 1,
666
684
  priority: U,
667
685
  abortSignal: g
668
686
  });
669
- if (B) {
670
- const R = T.isAbsolute(B) ? B : T.resolve(T.dirname(v), B), A = await I(
687
+ if (F) {
688
+ const R = T.isAbsolute(F) ? F : T.resolve(T.dirname(v), F), A = await I(
671
689
  R,
672
690
  M,
673
691
  $,
@@ -683,19 +701,19 @@ function Ee(t) {
683
701
  U
684
702
  ) && (le(b, N), y(v, N))), N;
685
703
  } else if (D.isDirectory()) {
686
- const B = await L({
704
+ const F = await L({
687
705
  pool: n,
688
- func: () => F.promises.readdir(w).catch(d),
706
+ func: () => B.promises.readdir(w).catch(d),
689
707
  count: 1,
690
- priority: a,
708
+ priority: i,
691
709
  abortSignal: g
692
710
  });
693
- if (B) {
694
- for (let R = 0, A = B.length; R < A; R++)
695
- B[R] = T.join(v, B[R]);
711
+ if (F) {
712
+ for (let R = 0, A = F.length; R < A; R++)
713
+ F[R] = T.join(v, F[R]);
696
714
  N = await Ee({
697
715
  ...t,
698
- paths: B,
716
+ paths: F,
699
717
  abortSignal: g,
700
718
  priority: U,
701
719
  level: s + 1,
@@ -712,16 +730,16 @@ function Ee(t) {
712
730
  }
713
731
  const S = [];
714
732
  for (let w = 0, M = r.length; w < M; w++) {
715
- const $ = Ut(r[w]), v = f ? f($) : !0;
733
+ const $ = At(r[w]), v = f ? f($) : !0;
716
734
  v !== !1 && S.push(I($, w, v));
717
735
  }
718
736
  return await Promise.all(S), b;
719
737
  });
720
738
  }
721
- function Be(t) {
739
+ function Fe(t) {
722
740
  return Ee(t);
723
741
  }
724
- function Gt(t, r) {
742
+ function qt(t, r) {
725
743
  if (!r || r === ".")
726
744
  return t;
727
745
  const s = t.startsWith("^");
@@ -729,21 +747,21 @@ function Gt(t, r) {
729
747
  const o = t.startsWith("!");
730
748
  return o && (t = t.substring(1)), t.startsWith("/") ? (r.endsWith("/") && (r = r.substring(0, r.length - 1)), t = r + t) : (r.endsWith("/") || (r += "/"), t.startsWith("./") ? t = r + t.substring(2) : t.startsWith("../") ? t = r + t : (r.startsWith("..") && (r = ""), t.startsWith("**") ? t = r + t : t = r + "**/" + t)), t = T.normalize(t).replace(/\\/g, "/"), o && (t = "!" + t), s && (t = "^" + t), t;
731
749
  }
732
- function qt(t) {
750
+ function _t(t) {
733
751
  const r = t.startsWith("!");
734
752
  return r && (t = t.substring(1)), t.startsWith("/") ? t = t.substring(1) : !t.startsWith("**") && !t.startsWith("../") && (t = `**/${t}`), r && (t = "!" + t), t;
735
753
  }
736
754
  function ce(t) {
737
755
  return "^" + t;
738
756
  }
739
- async function _t(t) {
740
- const s = (await F.promises.readFile(t, "utf-8")).split(`
757
+ async function jt(t) {
758
+ const s = (await B.promises.readFile(t, "utf-8")).split(`
741
759
  `), o = [];
742
760
  return s.forEach((e) => {
743
761
  e = e.trim(), !(!e || e.startsWith("#")) && o.push(e);
744
762
  }), o;
745
763
  }
746
- async function Fe(t) {
764
+ async function Be(t) {
747
765
  const r = t.rootDir ?? ".", s = [];
748
766
  if (!t.globs?.length)
749
767
  return s;
@@ -756,9 +774,9 @@ async function Fe(t) {
756
774
  pool: De,
757
775
  count: 1,
758
776
  func: async () => {
759
- const n = T.resolve(r, e.value), i = await _t(n), a = T.relative(r, T.dirname(n));
760
- i.forEach((u) => {
761
- u = qt(u), u = Gt(u, a), s.push(e.exclude ? ce(u) : u);
777
+ const n = T.resolve(r, e.value), a = await jt(n), i = T.relative(r, T.dirname(n));
778
+ a.forEach((u) => {
779
+ u = _t(u), u = qt(u, i), s.push(e.exclude ? ce(u) : u);
762
780
  });
763
781
  }
764
782
  });
@@ -775,18 +793,18 @@ function Oe({
775
793
  e = e.replace(/\\/g, "/").trim();
776
794
  const n = e.startsWith("^");
777
795
  n && (e = e.substring(1).trim());
778
- const i = e.startsWith("!");
779
- if (i && (e = e.substring(1).trim()), e.startsWith("!") || e.startsWith("^"))
796
+ const a = e.startsWith("!");
797
+ if (a && (e = e.substring(1).trim()), e.startsWith("!") || e.startsWith("^"))
780
798
  throw new Error(
781
799
  `Invalid glob pattern: "${e}". The syntax '${e.substring(0, 2)}' is not supported. Valid glob patterns use: * (match any characters), ** (match any directories), ? (match single character), [abc] (character class), ! (negate pattern), ^ (exclude if included). Examples of valid patterns: "*.js", "src/**/*.ts", "!node_modules", "^dist". Avoid starting with '!' after '^' or multiple special prefixes.`
782
800
  );
783
801
  e.startsWith("/") && (e = "." + e);
784
- const a = r ? T.resolve(r, e).replace(/\\/g, "/") : e;
785
- if (!a)
802
+ const i = r ? T.resolve(r, e).replace(/\\/g, "/") : e;
803
+ if (!i)
786
804
  return;
787
805
  let u;
788
806
  try {
789
- u = mt(a, {
807
+ u = mt(i, {
790
808
  nocase: s ?? !1,
791
809
  dot: !0,
792
810
  strictBrackets: !0
@@ -799,28 +817,28 @@ function Oe({
799
817
  }
800
818
  o.push({
801
819
  exclude: n,
802
- negative: i,
803
- debugInfo: a,
820
+ negative: a,
821
+ debugInfo: i,
804
822
  match: u
805
823
  });
806
824
  }), function(n) {
807
825
  n = n.replace(/\\/g, "/");
808
- let i = null, a = !1;
826
+ let a = null, i = !1;
809
827
  for (let u = 0, l = o.length; u < l; u++) {
810
828
  const c = o[u];
811
- c.match(n) && (c.exclude ? a = !c.negative : (i = !c.negative, a = !1));
829
+ c.match(n) && (c.exclude ? i = !c.negative : (a = !c.negative, i = !1));
812
830
  }
813
- return a ? !1 : i;
831
+ return i ? !1 : a;
814
832
  };
815
833
  }
816
- async function jt(t) {
834
+ async function Jt(t) {
817
835
  const r = t.rootDir ?? ".", s = [], o = {};
818
836
  t.result.countFiles && (o.countFiles = 0), t.result.size && (o.size = 0);
819
- const e = await Fe({
837
+ const e = await Be({
820
838
  rootDir: r,
821
839
  globs: t.globs
822
840
  });
823
- return await Be({
841
+ return await Fe({
824
842
  paths: [r],
825
843
  walkLinks: !0,
826
844
  matchPath: Oe({
@@ -828,25 +846,25 @@ async function jt(t) {
828
846
  rootDir: r,
829
847
  noCase: !0
830
848
  }),
831
- handlePath: async ({ path: n, stat: i, itemStat: a }) => {
832
- const u = T.relative(r, n), l = i.isDirectory(), c = i.isFile();
849
+ handlePath: async ({ path: n, stat: a, itemStat: i }) => {
850
+ const u = T.relative(r, n), l = a.isDirectory(), c = a.isFile();
833
851
  if (!l && !c)
834
852
  return !0;
835
- const f = (u || ".").replace(/\\/g, "/"), d = l ? "dir" : "file", m = l ? a.maxFileDateModified || null : i.mtimeMs, h = l ? a.totalSize : i.size, g = l ? a.countFiles : null, b = {
853
+ const f = (u || ".").replace(/\\/g, "/"), d = l ? "dir" : "file", h = l ? i.maxFileDateModified || null : a.mtimeMs, m = l ? i.totalSize : a.size, g = l ? i.countFiles : null, b = {
836
854
  path: f,
837
855
  type: d
838
856
  };
839
- if (t.result.dateModified && (b.dateModified = m), t.result.size && (b.size = h), t.result.countFiles && (b.countFiles = g), t.dateModified && m != null) {
857
+ if (t.result.dateModified && (b.dateModified = h), t.result.size && (b.size = m), t.result.countFiles && (b.countFiles = g), t.dateModified && h != null) {
840
858
  const [y, x] = t.dateModified;
841
- if (y != null && m < y || x != null && m > x)
859
+ if (y != null && h < y || x != null && h > x)
842
860
  return !1;
843
861
  }
844
- if (t.totalSize && h != null) {
862
+ if (t.totalSize && m != null) {
845
863
  const [y, x] = t.totalSize;
846
- if (y != null && h < y || x != null && h > x)
864
+ if (y != null && m < y || x != null && m > x)
847
865
  return !1;
848
866
  }
849
- return d === "file" && (o.countFiles = (o.countFiles ?? 0) + 1), d === "file" && h != null && (o.size = (o.size ?? 0) + h), m != null && (o.dateModified == null || m > o.dateModified) && (o.dateModified = m), l && !t.result.dirs || c && !t.result.files || s.push(b), !0;
867
+ return d === "file" && (o.countFiles = (o.countFiles ?? 0) + 1), d === "file" && m != null && (o.size = (o.size ?? 0) + m), h != null && (o.dateModified == null || h > o.dateModified) && (o.dateModified = h), l && !t.result.dirs || c && !t.result.files || s.push(b), !0;
850
868
  }
851
869
  }), { items: s, totals: o };
852
870
  }
@@ -858,55 +876,55 @@ function fe(t) {
858
876
  r /= de, s++;
859
877
  return `${s === 0 ? r.toString() : r.toFixed(2)}${ue[s]}`;
860
878
  }
861
- function me(t) {
879
+ function he(t) {
862
880
  const s = Date.now() - t;
863
881
  if (s < 0) return "0s";
864
- const o = Math.floor(s / 1e3), e = Math.floor(o / 60), n = Math.floor(e / 60), i = Math.floor(n / 24), a = Math.floor(i / 7), u = Math.floor(i / 30), l = Math.floor(i / 365);
865
- return l > 0 ? `${l}Y` : u > 0 ? `${u}M` : a > 0 ? `${a}w` : i > 0 ? `${i}d` : n > 0 ? `${n}h` : e > 0 ? `${e}m` : `${o}s`;
882
+ const o = Math.floor(s / 1e3), e = Math.floor(o / 60), n = Math.floor(e / 60), a = Math.floor(n / 24), i = Math.floor(a / 7), u = Math.floor(a / 30), l = Math.floor(a / 365);
883
+ return l > 0 ? `${l}Y` : u > 0 ? `${u}M` : i > 0 ? `${i}w` : a > 0 ? `${a}d` : n > 0 ? `${n}h` : e > 0 ? `${e}m` : `${o}s`;
866
884
  }
867
- function Jt(t, r) {
885
+ function Kt(t, r) {
868
886
  return r?.length ? [...t].sort((s, o) => {
869
887
  for (let e = 0, n = r.length; e < n; e++) {
870
- const i = r[e];
871
- let a, u;
872
- switch (i.field) {
888
+ const a = r[e];
889
+ let i, u;
890
+ switch (a.field) {
873
891
  case "type":
874
- a = s.type, u = o.type;
892
+ i = s.type, u = o.type;
875
893
  break;
876
894
  case "path":
877
- a = s.path, u = o.path;
895
+ i = s.path, u = o.path;
878
896
  break;
879
897
  case "dateModified":
880
- a = s.dateModified, u = o.dateModified;
898
+ i = s.dateModified, u = o.dateModified;
881
899
  break;
882
900
  case "size":
883
- a = s.size, u = o.size;
901
+ i = s.size, u = o.size;
884
902
  break;
885
903
  case "countFiles":
886
- a = s.countFiles, u = o.countFiles;
904
+ i = s.countFiles, u = o.countFiles;
887
905
  break;
888
906
  }
889
- if (a == null) {
907
+ if (i == null) {
890
908
  if (u == null)
891
909
  continue;
892
910
  return 1;
893
911
  }
894
912
  if (u == null)
895
913
  return -1;
896
- const l = a > u ? 1 : a < u ? -1 : 0;
914
+ const l = i > u ? 1 : i < u ? -1 : 0;
897
915
  if (l !== 0)
898
- return i.desc ? -l : l;
916
+ return a.desc ? -l : l;
899
917
  }
900
918
  return 0;
901
919
  }) : t;
902
920
  }
903
- function Kt(t, r) {
904
- const s = Jt(t.items, r.sort ?? []), o = r.fields && r.fields.length > 0 ? r.fields : [];
921
+ function Wt(t, r) {
922
+ const s = Kt(t.items, r.sort ?? []), o = r.fields && r.fields.length > 0 ? r.fields : [];
905
923
  let e = "";
906
924
  if (s.length > 0 && o.length > 0) {
907
- for (let n = 0, i = o.length; n < i; n++) {
908
- const a = o[n];
909
- switch (n > 0 && (e += " | "), a) {
925
+ for (let n = 0, a = o.length; n < a; n++) {
926
+ const i = o[n];
927
+ switch (n > 0 && (e += " | "), i) {
910
928
  case "dateModified":
911
929
  e += "Time ago (s/m/h/d/w/M/Y)";
912
930
  break;
@@ -924,27 +942,27 @@ function Kt(t, r) {
924
942
  break;
925
943
  }
926
944
  }
927
- for (let n = 0, i = s.length; n < i; n++) {
928
- const a = s[n];
945
+ for (let n = 0, a = s.length; n < a; n++) {
946
+ const i = s[n];
929
947
  e += `
930
948
  `;
931
949
  for (let u = 0, l = o.length; u < l; u++) {
932
950
  const c = o[u];
933
951
  switch (u > 0 && (e += " | "), c) {
934
952
  case "dateModified":
935
- e += a.dateModified ? me(a.dateModified) : "-";
953
+ e += i.dateModified ? he(i.dateModified) : "-";
936
954
  break;
937
955
  case "size":
938
- e += fe(a.size);
956
+ e += fe(i.size);
939
957
  break;
940
958
  case "type":
941
- e += a.type;
959
+ e += i.type;
942
960
  break;
943
961
  case "path":
944
- e += a.type === "dir" ? `${a.path}/` : a.path;
962
+ e += i.type === "dir" ? `${i.path}/` : i.path;
945
963
  break;
946
964
  case "countFiles":
947
- a.type === "dir" ? e += a.countFiles != null ? a.countFiles.toString() : "-" : e += "-";
965
+ i.type === "dir" ? e += i.countFiles != null ? i.countFiles.toString() : "-" : e += "-";
948
966
  break;
949
967
  }
950
968
  }
@@ -954,12 +972,12 @@ function Kt(t, r) {
954
972
  e.length > 0 && (e += `
955
973
  ---
956
974
  `);
957
- const n = fe(t.totals.size ?? 0), i = t.totals.dateModified ? `, last modified ${me(t.totals.dateModified)} ago` : "";
958
- e += `Totals: ${t.totals.countFiles ?? 0} files in dirs, ${n}${i}`;
975
+ const n = fe(t.totals.size ?? 0), a = t.totals.dateModified ? `, last modified ${he(t.totals.dateModified)} ago` : "";
976
+ e += `Totals: ${t.totals.countFiles ?? 0} files in dirs, ${n}${a}`;
959
977
  }
960
978
  return e;
961
979
  }
962
- const is = "project-tools", as = "1.0.0", ls = "d00f70240703039df14c76176a055bce6b5484d2b552ba2c89820f03b8e5e60d", he = 25e3;
980
+ const is = "project-tools", as = "1.0.0", ls = "d00f70240703039df14c76176a055bce6b5484d2b552ba2c89820f03b8e5e60d", me = 25e3;
963
981
  function pe(t) {
964
982
  const r = t.match(
965
983
  /^\s*(\d+(?:\.\d+)?)\s*([smhdwMY]|sec(onds?)?|min(utes?)?|hours?|days?|weeks?|months?|years?)\s*$/i
@@ -1054,7 +1072,7 @@ const Re = p.object({
1054
1072
  'Filter files/directories with total size at most this large. Only items with size <= this value will be included. For directories, uses total size of all contents. Format: number + unit (B/KB/MB/GB/TB). Examples: "1MB" (up to 1 megabyte), "500KB" (up to 500 kilobytes), "10GB" (up to 10 gigabytes). Combine with minTotalSize for size ranges'
1055
1073
  )
1056
1074
  });
1057
- async function Wt(t, r) {
1075
+ async function Qt(t, r) {
1058
1076
  let s;
1059
1077
  try {
1060
1078
  s = Re.parse(t);
@@ -1067,8 +1085,8 @@ async function Wt(t, r) {
1067
1085
  globs: o,
1068
1086
  showFiles: e,
1069
1087
  showDirs: n,
1070
- sortBy: i,
1071
- minTimeAgo: a,
1088
+ sortBy: a,
1089
+ minTimeAgo: i,
1072
1090
  maxTimeAgo: u,
1073
1091
  minTotalSize: l,
1074
1092
  maxTotalSize: c
@@ -1078,7 +1096,7 @@ async function Wt(t, r) {
1078
1096
  error: 'Fields array must include "path" field when fields are specified. The "path" field is required to identify files and directories in the output'
1079
1097
  };
1080
1098
  const f = s.fields ? s.fields.map((g) => g === "totalCountFiles" ? "countFiles" : g === "lastModified" ? "dateModified" : g) : [];
1081
- let d = i?.map((g) => {
1099
+ let d = a?.map((g) => {
1082
1100
  let b = g.field;
1083
1101
  return b === "totalCountFiles" && (b = "countFiles"), b === "lastModified" && (b = "dateModified"), {
1084
1102
  field: b,
@@ -1087,17 +1105,17 @@ async function Wt(t, r) {
1087
1105
  };
1088
1106
  }) ?? null;
1089
1107
  (!d || d.length === 0) && (d = [{ field: "path", desc: !1 }]);
1090
- const m = d?.map((g) => g.field) || [], h = T.resolve(
1108
+ const h = d?.map((g) => g.field) || [], m = T.resolve(
1091
1109
  r.workingDir || "",
1092
1110
  s.rootDir || ""
1093
1111
  );
1094
1112
  try {
1095
1113
  try {
1096
- await F.promises.access(h, F.constants.F_OK);
1114
+ await B.promises.access(m, B.constants.F_OK);
1097
1115
  } catch ($) {
1098
1116
  if ($.code === "ENOENT")
1099
1117
  return {
1100
- error: `Directory does not exist: "${h}". Verify the path is correct and accessible. If using rootDir parameter, ensure it exists relative to the current working directory. Use fs-list without rootDir to list the current directory, or check parent directories first.`
1118
+ error: `Directory does not exist: "${m}". Verify the path is correct and accessible. If using rootDir parameter, ensure it exists relative to the current working directory. Use fs-list without rootDir to list the current directory, or check parent directories first.`
1101
1119
  };
1102
1120
  throw $;
1103
1121
  }
@@ -1108,14 +1126,14 @@ async function Wt(t, r) {
1108
1126
  })) : [{ value: "**", valueType: "pattern", exclude: !1 }], b = r.globsExclude || [], y = [...g, ...b], x = {
1109
1127
  files: e ?? !1,
1110
1128
  dirs: n ?? !1,
1111
- dateModified: f.includes("dateModified") || m.includes("dateModified"),
1112
- size: f.includes("size") || m.includes("size"),
1113
- countFiles: f.includes("countFiles") || m.includes("countFiles")
1129
+ dateModified: f.includes("dateModified") || h.includes("dateModified"),
1130
+ size: f.includes("size") || h.includes("size"),
1131
+ countFiles: f.includes("countFiles") || h.includes("countFiles")
1114
1132
  };
1115
1133
  let I = null, S = null;
1116
- if (a || u)
1134
+ if (i || u)
1117
1135
  try {
1118
- const $ = Date.now(), v = u ? $ - pe(u) : null, D = a ? $ - pe(a) : null;
1136
+ const $ = Date.now(), v = u ? $ - pe(u) : null, D = i ? $ - pe(i) : null;
1119
1137
  I = [v, D];
1120
1138
  } catch ($) {
1121
1139
  return {
@@ -1131,17 +1149,17 @@ async function Wt(t, r) {
1131
1149
  error: $ instanceof Error ? $.message : "Unknown error parsing size filter"
1132
1150
  };
1133
1151
  }
1134
- const w = await jt({
1135
- rootDir: h || null,
1152
+ const w = await Jt({
1153
+ rootDir: m || null,
1136
1154
  globs: y,
1137
1155
  result: x,
1138
1156
  dateModified: I,
1139
1157
  totalSize: S
1140
1158
  });
1141
- return w.items.length > he ? {
1142
- error: `Number of paths (${w.items.length}) exceeds maximum allowed (${he}). Consider using more specific glob patterns or filters to reduce the result set.`
1159
+ return w.items.length > me ? {
1160
+ error: `Number of paths (${w.items.length}) exceeds maximum allowed (${me}). Consider using more specific glob patterns or filters to reduce the result set.`
1143
1161
  } : {
1144
- output: Kt(w, {
1162
+ output: Wt(w, {
1145
1163
  sort: d,
1146
1164
  fields: f,
1147
1165
  totals: !0
@@ -1151,7 +1169,7 @@ async function Wt(t, r) {
1151
1169
  return { error: g instanceof Error ? g.message : "Unknown error" };
1152
1170
  }
1153
1171
  }
1154
- function Qt(t, r) {
1172
+ function Ht(t, r) {
1155
1173
  t(
1156
1174
  "fs-list",
1157
1175
  {
@@ -1160,7 +1178,7 @@ function Qt(t, r) {
1160
1178
  inputSchema: Re.shape
1161
1179
  },
1162
1180
  async (s) => {
1163
- const o = await Wt(s, r);
1181
+ const o = await Qt(s, r);
1164
1182
  return o.error ? `Method: fs-list(${JSON.stringify(s)})
1165
1183
  ❌ Error: ${o.error}` : `Method: fs-list(${JSON.stringify(s)})
1166
1184
  ${o.output || JSON.stringify(o, null, 2)}`;
@@ -1269,7 +1287,7 @@ const Z = p.object({
1269
1287
  "dateModified"
1270
1288
  ].map((t, r) => [t, r])
1271
1289
  );
1272
- function Ht(t, r) {
1290
+ function Yt(t, r) {
1273
1291
  const s = be.get(t) ?? 1 / 0, o = be.get(r) ?? 1 / 0;
1274
1292
  return s > o ? 1 : s < o ? -1 : 0;
1275
1293
  }
@@ -1277,16 +1295,16 @@ async function ze(t, r, s) {
1277
1295
  let o;
1278
1296
  try {
1279
1297
  o = Z.parse(t);
1280
- } catch (h) {
1298
+ } catch (m) {
1281
1299
  return {
1282
- error: C(h)
1300
+ error: C(m)
1283
1301
  };
1284
1302
  }
1285
1303
  const {
1286
1304
  name: e,
1287
1305
  globs: n,
1288
- matchFiles: i,
1289
- matchDirs: a,
1306
+ matchFiles: a,
1307
+ matchDirs: i,
1290
1308
  minTimeAgo: u,
1291
1309
  maxTimeAgo: l,
1292
1310
  minTotalSize: c,
@@ -1301,19 +1319,19 @@ async function ze(t, r, s) {
1301
1319
  return {
1302
1320
  error: `Filesystem snapshot query "${e}" already exists`
1303
1321
  };
1304
- const m = T.resolve(r.workingDir || "", o.rootDir || "").replace(/\\/g, "/");
1322
+ const h = T.resolve(r.workingDir || "", o.rootDir || "").replace(/\\/g, "/");
1305
1323
  try {
1306
1324
  try {
1307
- await F.promises.access(m, F.constants.F_OK);
1325
+ await B.promises.access(h, B.constants.F_OK);
1308
1326
  } catch (w) {
1309
1327
  if (w.code === "ENOENT")
1310
1328
  return {
1311
- error: `Directory does not exist: "${m}". Verify the path is correct and accessible. If using rootDir parameter, ensure it exists relative to the current working directory. Use fs-snapshot-query-create without rootDir to snapshot the current directory, or check parent directories first.`
1329
+ error: `Directory does not exist: "${h}". Verify the path is correct and accessible. If using rootDir parameter, ensure it exists relative to the current working directory. Use fs-snapshot-query-create without rootDir to snapshot the current directory, or check parent directories first.`
1312
1330
  };
1313
1331
  throw w;
1314
1332
  }
1315
- const h = o.extraFields ? o.extraFields.map((w) => w === "lastModified" ? "dateModified" : w) : [];
1316
- h.includes("name") || h.push("name"), h.sort(Ht);
1333
+ const m = o.extraFields ? o.extraFields.map((w) => w === "lastModified" ? "dateModified" : w) : [];
1334
+ m.includes("name") || m.push("name"), m.sort(Yt);
1317
1335
  const g = n && n.length > 0 ? n.map((w) => ({
1318
1336
  value: w,
1319
1337
  valueType: "pattern",
@@ -1340,24 +1358,24 @@ async function ze(t, r, s) {
1340
1358
  }
1341
1359
  const S = {
1342
1360
  name: e,
1343
- rootDir: m,
1361
+ rootDir: h,
1344
1362
  globs: y,
1345
- matchFiles: i ?? null,
1346
- matchDirs: a ?? null,
1363
+ matchFiles: a ?? null,
1364
+ matchDirs: i ?? null,
1347
1365
  dateModified: x,
1348
1366
  totalSize: I,
1349
- fields: h
1367
+ fields: m
1350
1368
  };
1351
1369
  return d.fsSnapshotQueries.set(e, S), {
1352
1370
  snapshotQuery: S
1353
1371
  };
1354
- } catch (h) {
1372
+ } catch (m) {
1355
1373
  return {
1356
- error: h instanceof Error ? h.message : "Unknown error"
1374
+ error: m instanceof Error ? m.message : "Unknown error"
1357
1375
  };
1358
1376
  }
1359
1377
  }
1360
- function Yt(t, r) {
1378
+ function Vt(t, r) {
1361
1379
  t(
1362
1380
  "fs-snapshot-query-create",
1363
1381
  {
@@ -1380,29 +1398,29 @@ function _(t) {
1380
1398
  "Impossible behavior: root node (id: null) not found in idToNode"
1381
1399
  );
1382
1400
  const e = /* @__PURE__ */ new Map();
1383
- return r.forEach((n, i) => {
1401
+ return r.forEach((n, a) => {
1384
1402
  if (n != null) {
1385
1403
  if (e.has(n)) {
1386
- const a = e.get(n);
1404
+ const i = e.get(n);
1387
1405
  throw new Error(
1388
- `Impossible behavior: node appears with multiple IDs (existing: ${a}, new: ${i})`
1406
+ `Impossible behavior: node appears with multiple IDs (existing: ${i}, new: ${a})`
1389
1407
  );
1390
1408
  }
1391
- e.set(n, i);
1409
+ e.set(n, a);
1392
1410
  }
1393
1411
  }), {
1394
1412
  root: o,
1395
1413
  getNode: (n) => r.get(n) ?? null,
1396
1414
  getId: (n) => e.get(n) ?? null,
1397
1415
  getChilds: (n) => {
1398
- let i = e.get(n);
1399
- if (i == null)
1416
+ let a = e.get(n);
1417
+ if (a == null)
1400
1418
  if (n === r.get(null))
1401
- i = null;
1419
+ a = null;
1402
1420
  else
1403
1421
  throw new Error("Impossible behavior: node not found in idToNode");
1404
- const a = s.get(i);
1405
- return a == null ? null : a.map((u) => {
1422
+ const i = s.get(a);
1423
+ return i == null ? null : i.map((u) => {
1406
1424
  const l = r.get(u);
1407
1425
  if (l == null)
1408
1426
  throw new Error(
@@ -1416,41 +1434,41 @@ function _(t) {
1416
1434
  function Pe(t, r, s) {
1417
1435
  let o = null;
1418
1436
  for (let e = 0, n = r.length; e < n; e++) {
1419
- const i = r[e], a = t(i), u = a == null ? null : Pe(t, a, s), l = s(i, u);
1437
+ const a = r[e], i = t(a), u = i == null ? null : Pe(t, i, s), l = s(a, u);
1420
1438
  l != null && (o == null && (o = []), o.push(l));
1421
1439
  }
1422
1440
  return o;
1423
1441
  }
1424
1442
  function Le(t) {
1425
- const { getId: r, getChilds: s, rootNodes: o, createSnapshotNode: e } = t, n = /* @__PURE__ */ new Map(), i = /* @__PURE__ */ new Map(), a = /* @__PURE__ */ new Map(), u = Pe(
1443
+ const { getId: r, getChilds: s, rootNodes: o, createSnapshotNode: e } = t, n = /* @__PURE__ */ new Map(), a = /* @__PURE__ */ new Map(), i = /* @__PURE__ */ new Map(), u = Pe(
1426
1444
  s,
1427
1445
  o,
1428
1446
  (c, f) => {
1429
1447
  const d = e(c, f);
1430
1448
  if (c != null && d != null) {
1431
- const m = r(c);
1432
- n.set(m, d), i.set(d, m);
1449
+ const h = r(c);
1450
+ n.set(h, d), a.set(d, h);
1433
1451
  }
1434
- return d != null && f != null && a.set(
1435
- i.get(d),
1436
- f.map((m) => i.get(m))
1452
+ return d != null && f != null && i.set(
1453
+ a.get(d),
1454
+ f.map((h) => a.get(h))
1437
1455
  ), d;
1438
1456
  }
1439
1457
  ), l = e(null, u);
1440
1458
  if (l == null)
1441
1459
  throw new Error("Impossible behavior: rootNode == null");
1442
- return n.set(null, l), u != null && a.set(
1460
+ return n.set(null, l), u != null && i.set(
1443
1461
  null,
1444
- u.map((c) => i.get(c))
1462
+ u.map((c) => a.get(c))
1445
1463
  ), {
1446
1464
  idToNode: n,
1447
- idToChildIds: a
1465
+ idToChildIds: i
1448
1466
  };
1449
1467
  }
1450
1468
  function W(t) {
1451
1469
  return t = t?.replace(/\\/g, "/").replace(/\/$/, ""), !t || t === "." ? null : t;
1452
1470
  }
1453
- async function Vt(t) {
1471
+ async function Zt(t) {
1454
1472
  const r = /* @__PURE__ */ new Map(), s = /* @__PURE__ */ new Map(), o = T.resolve(t.rootDir || "."), n = {
1455
1473
  path: ".",
1456
1474
  name: T.basename(o),
@@ -1460,23 +1478,23 @@ async function Vt(t) {
1460
1478
  size: 0
1461
1479
  };
1462
1480
  r.set(null, n);
1463
- const i = await Fe({
1481
+ const a = await Be({
1464
1482
  rootDir: o,
1465
1483
  globs: t.globs
1466
1484
  });
1467
- return await Be({
1485
+ return await Fe({
1468
1486
  paths: [o],
1469
1487
  walkLinks: !0,
1470
1488
  matchPath: Oe({
1471
- globs: i,
1489
+ globs: a,
1472
1490
  rootDir: o,
1473
1491
  noCase: !0
1474
1492
  }),
1475
- handlePath: async ({ path: a, stat: u, itemStat: l }) => {
1476
- const c = T.relative(o, a), f = u.isDirectory(), d = u.isFile();
1493
+ handlePath: async ({ path: i, stat: u, itemStat: l }) => {
1494
+ const c = T.relative(o, i), f = u.isDirectory(), d = u.isFile();
1477
1495
  if (!f && !d)
1478
1496
  return !0;
1479
- const m = W(c || "."), h = f ? "dir" : "file", g = f ? null : u.mtimeMs, b = u.size;
1497
+ const h = W(c || "."), m = f ? "dir" : "file", g = f ? null : u.mtimeMs, b = u.size;
1480
1498
  let y = !0;
1481
1499
  if (d && !t.matchFiles && (y = !1), f && !t.matchDirs && (y = !1), y && d && t.dateModified && g != null) {
1482
1500
  const [w, M] = t.dateModified;
@@ -1491,26 +1509,26 @@ async function Vt(t) {
1491
1509
  } else if (!y)
1492
1510
  return !1;
1493
1511
  const x = {
1494
- path: m ?? ".",
1495
- name: T.basename(a),
1496
- type: h,
1512
+ path: h ?? ".",
1513
+ name: T.basename(i),
1514
+ type: m,
1497
1515
  dateModified: g,
1498
1516
  size: b,
1499
1517
  isMatched: y
1500
1518
  };
1501
- if (m == null)
1519
+ if (h == null)
1502
1520
  return n.dateModified = g, n.size = b, n.isMatched = y, !0;
1503
- r.set(m, x);
1504
- const I = W(T.dirname(m).replace(/\\/g, "/"));
1521
+ r.set(h, x);
1522
+ const I = W(T.dirname(h).replace(/\\/g, "/"));
1505
1523
  let S = s.get(I);
1506
- return S || (S = [], s.set(I, S)), S.push(m), !0;
1524
+ return S || (S = [], s.set(I, S)), S.push(h), !0;
1507
1525
  }
1508
1526
  }), {
1509
1527
  idToNode: r,
1510
1528
  idToChildIds: s
1511
1529
  };
1512
1530
  }
1513
- const Zt = [
1531
+ const Xt = [
1514
1532
  { name: "[ ]", match: (t) => t === 32, min: 2, max: 81 },
1515
1533
  { name: "[\\t]", match: (t) => t === 9, min: 2, max: 20 },
1516
1534
  { name: "[\\n]", match: (t) => t === 10, min: 2, max: 14 },
@@ -1533,7 +1551,7 @@ const Zt = [
1533
1551
  // max: 2,
1534
1552
  // },
1535
1553
  ];
1536
- function xe(t, r = Zt) {
1554
+ function xe(t, r = Xt) {
1537
1555
  const s = t.length;
1538
1556
  if (s === 0) return 0;
1539
1557
  const o = r.length;
@@ -1541,21 +1559,21 @@ function xe(t, r = Zt) {
1541
1559
  return s;
1542
1560
  let e = 0, n = 0;
1543
1561
  for (; n < s; ) {
1544
- const i = t.charCodeAt(n);
1545
- let a = !1;
1562
+ const a = t.charCodeAt(n);
1563
+ let i = !1;
1546
1564
  for (let u = 0; u < o; u++) {
1547
1565
  const l = r[u];
1548
- if (l.match(i)) {
1566
+ if (l.match(a)) {
1549
1567
  let c = 1;
1550
1568
  for (; ++n < s && l.match(t.charCodeAt(n)) && c < l.max; )
1551
1569
  c++;
1552
1570
  if (c >= l.min) {
1553
- e++, a = !0;
1571
+ e++, i = !0;
1554
1572
  break;
1555
1573
  }
1556
1574
  }
1557
1575
  }
1558
- a || (n++, e++);
1576
+ i || (n++, e++);
1559
1577
  }
1560
1578
  return e;
1561
1579
  }
@@ -1564,20 +1582,20 @@ function Ue(t) {
1564
1582
  return r += xe(t.textOpen) + 1, t.textClose != null && (r += xe(t.textClose) + 1), t.indent && (r += 1), r;
1565
1583
  }
1566
1584
  const Se = ["B", "KB", "MB", "GB", "TB"], $e = 1024;
1567
- function Xt(t) {
1585
+ function er(t) {
1568
1586
  if (t == null) return "-";
1569
1587
  let r = t ?? 0, s = 0;
1570
1588
  for (; r >= $e && s < Se.length - 1; )
1571
1589
  r /= $e, s++;
1572
1590
  return `${s === 0 ? r.toString() : r.toFixed(2)}${Se[s]}`;
1573
1591
  }
1574
- function er(t) {
1592
+ function tr(t) {
1575
1593
  const s = Date.now() - t;
1576
1594
  if (s < 0) return "0s";
1577
- const o = Math.floor(s / 1e3), e = Math.floor(o / 60), n = Math.floor(e / 60), i = Math.floor(n / 24), a = Math.floor(i / 7), u = Math.floor(i / 30), l = Math.floor(i / 365);
1578
- return l > 0 ? `${l}Y` : u > 0 ? `${u}M` : a > 0 ? `${a}w` : i > 0 ? `${i}d` : n > 0 ? `${n}h` : e > 0 ? `${e}m` : `${o}s`;
1595
+ const o = Math.floor(s / 1e3), e = Math.floor(o / 60), n = Math.floor(e / 60), a = Math.floor(n / 24), i = Math.floor(a / 7), u = Math.floor(a / 30), l = Math.floor(a / 365);
1596
+ return l > 0 ? `${l}Y` : u > 0 ? `${u}M` : i > 0 ? `${i}w` : a > 0 ? `${a}d` : n > 0 ? `${n}h` : e > 0 ? `${e}m` : `${o}s`;
1579
1597
  }
1580
- function tr(t) {
1598
+ function rr(t) {
1581
1599
  return function(s, o) {
1582
1600
  const e = t.get(s), n = t.get(o);
1583
1601
  if (e.type !== n.type)
@@ -1585,31 +1603,31 @@ function tr(t) {
1585
1603
  if (e.type === "file")
1586
1604
  return e.name < n.name ? -1 : e.name > n.name ? 1 : 0;
1587
1605
  {
1588
- const i = e.countFiles || 0, a = n.countFiles || 0;
1589
- return i < a ? -1 : i > a ? 1 : e.name < n.name ? -1 : e.name > n.name ? 1 : 0;
1606
+ const a = e.countFiles || 0, i = n.countFiles || 0;
1607
+ return a < i ? -1 : a > i ? 1 : e.name < n.name ? -1 : e.name > n.name ? 1 : 0;
1590
1608
  }
1591
1609
  };
1592
1610
  }
1593
- function rr(t) {
1611
+ function sr(t) {
1594
1612
  const r = t.fields ?? [];
1595
1613
  return function(o, e) {
1596
- let n = "", i, a = 0;
1614
+ let n = "", a, i = 0;
1597
1615
  const u = e ? e.length : 0;
1598
- let l = 1, c, f = 0, d = 0, m = 0, h = 0, g = null, b, y, x;
1616
+ let l = 1, c, f = 0, d = 0, h = 0, m = 0, g = null, b, y, x;
1599
1617
  if (e)
1600
1618
  for (let S = 0; S < e.length; S++) {
1601
1619
  const w = e[S];
1602
- a += w.countMatched, l += w.countTotal, f += w.tokens, d += w.tokensTotal, m += w.size, h += w.countFiles, w.dateModified != null && (g == null || w.dateModified > g) && (g = w.dateModified);
1620
+ i += w.countMatched, l += w.countTotal, f += w.tokens, d += w.tokensTotal, h += w.size, m += w.countFiles, w.dateModified != null && (g == null || w.dateModified > g) && (g = w.dateModified);
1603
1621
  }
1604
- o ? (b = o.type, y = o.name, x = o.path, i = o.isMatched, i && (a += 1), o.type === "file" ? (m = o.size || 0, h = 1, g = o.dateModified || null) : o.dateModified != null && (g == null || o.dateModified > g) && (g = o.dateModified)) : (b = "dir", y = "<root>", x = ".", i = !0);
1622
+ o ? (b = o.type, y = o.name, x = o.path, a = o.isMatched, a && (i += 1), o.type === "file" ? (h = o.size || 0, m = 1, g = o.dateModified || null) : o.dateModified != null && (g == null || o.dateModified > g) && (g = o.dateModified)) : (b = "dir", y = "<root>", x = ".", a = !0);
1605
1623
  for (let S = 0, w = r.length; S < w; S++) {
1606
1624
  const M = r[S];
1607
1625
  switch (S > 0 && (n += " "), M) {
1608
1626
  case "dateModified":
1609
- n += g ? er(g) : "-";
1627
+ n += g ? tr(g) : "-";
1610
1628
  break;
1611
1629
  case "size":
1612
- n += Xt(m);
1630
+ n += er(h);
1613
1631
  break;
1614
1632
  case "type":
1615
1633
  n += b;
@@ -1618,7 +1636,7 @@ function rr(t) {
1618
1636
  n += b === "dir" ? `${y}/` : y;
1619
1637
  break;
1620
1638
  case "countMatched":
1621
- n += a.toString();
1639
+ n += i.toString();
1622
1640
  break;
1623
1641
  }
1624
1642
  }
@@ -1631,36 +1649,36 @@ function rr(t) {
1631
1649
  type: b,
1632
1650
  name: y,
1633
1651
  path: x,
1634
- isMatched: i,
1635
- countMatched: a,
1652
+ isMatched: a,
1653
+ countMatched: i,
1636
1654
  countChilds: u,
1637
1655
  countTotal: l,
1638
1656
  tokens: c,
1639
1657
  tokensChilds: f,
1640
1658
  tokensTotal: d,
1641
1659
  text: I,
1642
- size: m,
1643
- countFiles: h,
1660
+ size: h,
1661
+ countFiles: m,
1644
1662
  dateModified: g
1645
1663
  };
1646
1664
  };
1647
1665
  }
1648
- async function sr(t) {
1649
- const r = await Vt(t), s = _(r), o = s.getChilds(s.root), e = Le({
1650
- getId: (i) => {
1651
- const a = s.getId(i);
1652
- if (a == null)
1666
+ async function or(t) {
1667
+ const r = await Zt(t), s = _(r), o = s.getChilds(s.root), e = Le({
1668
+ getId: (a) => {
1669
+ const i = s.getId(a);
1670
+ if (i == null)
1653
1671
  throw new Error(
1654
- `Invalid tree structure: node ID is null for node ${JSON.stringify(i)}`
1672
+ `Invalid tree structure: node ID is null for node ${JSON.stringify(a)}`
1655
1673
  );
1656
- return a;
1674
+ return i;
1657
1675
  },
1658
- getChilds: (i) => s.getChilds(i),
1659
- createSnapshotNode: rr(t),
1676
+ getChilds: (a) => s.getChilds(a),
1677
+ createSnapshotNode: sr(t),
1660
1678
  rootNodes: o ?? []
1661
- }), n = tr(e.idToNode);
1662
- return e.idToChildIds.forEach((i) => {
1663
- i.sort(n);
1679
+ }), n = rr(e.idToNode);
1680
+ return e.idToChildIds.forEach((a) => {
1681
+ a.sort(n);
1664
1682
  }), _(e);
1665
1683
  }
1666
1684
  const X = p.object({
@@ -1681,31 +1699,31 @@ async function Ae(t, r, s) {
1681
1699
  error: C(c)
1682
1700
  };
1683
1701
  }
1684
- const { name: e, queryName: n, query: i } = o;
1702
+ const { name: e, queryName: n, query: a } = o;
1685
1703
  if (!s.sessionId)
1686
1704
  return {
1687
1705
  error: "Session ID is required"
1688
1706
  };
1689
- const a = V(s.sessionId);
1690
- if (a.fsSnapshots.has(e))
1707
+ const i = V(s.sessionId);
1708
+ if (i.fsSnapshots.has(e))
1691
1709
  return {
1692
1710
  error: `Filesystem snapshot "${e}" already exists`
1693
1711
  };
1694
- if (n && i)
1712
+ if (n && a)
1695
1713
  return {
1696
1714
  error: "Either queryName or query must be provided, not both"
1697
1715
  };
1698
1716
  let u, l = !1;
1699
1717
  if (n) {
1700
- const c = a.fsSnapshotQueries.get(n);
1718
+ const c = i.fsSnapshotQueries.get(n);
1701
1719
  if (!c)
1702
1720
  return {
1703
1721
  error: `Filesystem snapshot query "${n}" not found`
1704
1722
  };
1705
1723
  u = c;
1706
- } else if (i) {
1724
+ } else if (a) {
1707
1725
  const c = await ze(
1708
- i,
1726
+ a,
1709
1727
  r,
1710
1728
  s
1711
1729
  );
@@ -1719,12 +1737,12 @@ async function Ae(t, r, s) {
1719
1737
  error: "Either queryName or query must be provided"
1720
1738
  };
1721
1739
  try {
1722
- const c = await sr(u), f = {
1740
+ const c = await or(u), f = {
1723
1741
  name: e,
1724
1742
  query: u,
1725
1743
  tree: c
1726
1744
  };
1727
- return a.fsSnapshots.set(e, f), {
1745
+ return i.fsSnapshots.set(e, f), {
1728
1746
  fsSnapshot: f,
1729
1747
  queryCreated: l
1730
1748
  };
@@ -1734,7 +1752,7 @@ async function Ae(t, r, s) {
1734
1752
  };
1735
1753
  }
1736
1754
  }
1737
- function or(t, r) {
1755
+ function nr(t, r) {
1738
1756
  t(
1739
1757
  "fs-snapshot-create",
1740
1758
  {
@@ -1754,7 +1772,7 @@ function or(t, r) {
1754
1772
  }
1755
1773
  );
1756
1774
  }
1757
- class nr {
1775
+ class ir {
1758
1776
  _first = null;
1759
1777
  _last = null;
1760
1778
  _size = 0;
@@ -1777,11 +1795,11 @@ class nr {
1777
1795
  return this._size;
1778
1796
  }
1779
1797
  }
1780
- function ir(t) {
1781
- const r = new nr(), {
1798
+ function ar(t) {
1799
+ const r = new ir(), {
1782
1800
  tree: s,
1783
- limits: { maxCountTotal: o, maxTokensTotal: e, maxCountGroup: n, maxTokensGroup: i },
1784
- indexRangeGroupStrategy: a
1801
+ limits: { maxCountTotal: o, maxTokensTotal: e, maxCountGroup: n, maxTokensGroup: a },
1802
+ indexRangeGroupStrategy: i
1785
1803
  } = t, u = s.getChilds(s.root);
1786
1804
  u != null && u.length > 0 && r.enqueue({
1787
1805
  reportNode: null,
@@ -1789,26 +1807,26 @@ function ir(t) {
1789
1807
  });
1790
1808
  let l = null, c = 0, f = 0;
1791
1809
  for (; !r.isEmpty(); ) {
1792
- const { reportNode: d, node: m } = r.dequeue(), h = s.getChilds(m);
1793
- if (h == null || m.countChilds === 0 || h.length !== m.countChilds)
1810
+ const { reportNode: d, node: h } = r.dequeue(), m = s.getChilds(h);
1811
+ if (m == null || h.countChilds === 0 || m.length !== h.countChilds)
1794
1812
  throw new Error(
1795
1813
  "Impossible behavior: nodeChilds is null or length mismatch"
1796
1814
  );
1797
1815
  let g = r.size();
1798
- for (let y = 0; y < h.length; y++)
1799
- h[y].countChilds > 0 && (g += 1);
1800
- const b = g * a.tokens;
1801
- if (o != null && c + m.countChilds + g > o || e != null && f + m.tokensChilds + b > e) {
1816
+ for (let y = 0; y < m.length; y++)
1817
+ m[y].countChilds > 0 && (g += 1);
1818
+ const b = g * i.tokens;
1819
+ if (o != null && c + h.countChilds + g > o || e != null && f + h.tokensChilds + b > e) {
1802
1820
  const y = [];
1803
1821
  let x = null, I = 0;
1804
- for (let w = 0, M = h.length; w < M; w++) {
1805
- const $ = h[w], v = I * a.tokens;
1822
+ for (let w = 0, M = m.length; w < M; w++) {
1823
+ const $ = m[w], v = I * i.tokens;
1806
1824
  x != null && // Если общий лимит превышен, то не создаем новую группу, а продолжаем текущую. В случае достижения лимитов, последняя группа может содержать больше элементов, чем указано в лимитах группы, и это допустимо. Главное - дать в отчете полную картину.
1807
- !(o != null && c + 1 > o || e != null && f + a.tokens > e) && (n != null && x.countGrouped + 1 + I > n || i != null && x.tokensGrouped + $.tokens + v > i) && (y.push(x), c += 1, f += a.tokens, x = null, I = 0), x = a.add(x, $, w), $.countChilds > 0 && (I += 1);
1825
+ !(o != null && c + 1 > o || e != null && f + i.tokens > e) && (n != null && x.countGrouped + 1 + I > n || a != null && x.tokensGrouped + $.tokens + v > a) && (y.push(x), c += 1, f += i.tokens, x = null, I = 0), x = i.add(x, $, w), $.countChilds > 0 && (I += 1);
1808
1826
  }
1809
- x != null && (y.push(x), c += 1, f += a.tokens);
1827
+ x != null && (y.push(x), c += 1, f += i.tokens);
1810
1828
  const S = y.map((w) => ({
1811
- text: a.getReportText(w)
1829
+ text: i.getReportText(w)
1812
1830
  }));
1813
1831
  if (d != null) {
1814
1832
  if (d.childs != null)
@@ -1820,10 +1838,10 @@ function ir(t) {
1820
1838
  l = S;
1821
1839
  }
1822
1840
  } else {
1823
- c += m.countChilds, f += m.tokensChilds;
1841
+ c += h.countChilds, f += h.tokensChilds;
1824
1842
  const y = [];
1825
- for (let x = 0; x < h.length; x++) {
1826
- const I = h[x], S = {
1843
+ for (let x = 0; x < m.length; x++) {
1844
+ const I = m[x], S = {
1827
1845
  text: I.text
1828
1846
  };
1829
1847
  y.push(S);
@@ -1851,37 +1869,37 @@ function Ge(t) {
1851
1869
  tree: r,
1852
1870
  request: { parentNodeId: s, childsIndexRange: o, limits: e },
1853
1871
  indexRangeGroupStrategy: n,
1854
- ...i
1872
+ ...a
1855
1873
  } = t;
1856
- let a;
1874
+ let i;
1857
1875
  if (s != null) {
1858
1876
  const d = r.getNode(s);
1859
1877
  if (d == null)
1860
1878
  throw new Error(`Parent node "${s}" not found`);
1861
- a = d;
1879
+ i = d;
1862
1880
  } else
1863
- a = r.root;
1864
- let u, l = r.getChilds(a) ?? [];
1881
+ i = r.root;
1882
+ let u, l = r.getChilds(i) ?? [];
1865
1883
  if (o != null) {
1866
- const [d, m] = o;
1867
- if (d < 0 || m <= d || m >= l.length)
1884
+ const [d, h] = o;
1885
+ if (d < 0 || h <= d || h >= l.length)
1868
1886
  throw new Error(
1869
- `Invalid index range: ${d}-${m} for root nodes length ${l.length}`
1887
+ `Invalid index range: ${d}-${h} for root nodes length ${l.length}`
1870
1888
  );
1871
- const h = [];
1889
+ const m = [];
1872
1890
  let g = null;
1873
- for (let b = d; b <= m; b++) {
1891
+ for (let b = d; b <= h; b++) {
1874
1892
  const y = l[b];
1875
- h.push(y), g = n.add(g, y, b);
1893
+ m.push(y), g = n.add(g, y, b);
1876
1894
  }
1877
- l = h, u = {
1878
- ...a,
1895
+ l = m, u = {
1896
+ ...i,
1879
1897
  text: n.getReportText(g),
1880
1898
  countChilds: g.countGrouped,
1881
1899
  tokensChilds: g.tokensGrouped
1882
1900
  };
1883
1901
  } else
1884
- u = a;
1902
+ u = i;
1885
1903
  const c = {
1886
1904
  countChilds: 1,
1887
1905
  tokensChilds: u.tokens
@@ -1890,11 +1908,11 @@ function Ge(t) {
1890
1908
  root: c,
1891
1909
  getChilds: (d) => d === c ? [u] : d === u ? l : r.getChilds(d)
1892
1910
  };
1893
- return ir({
1911
+ return ar({
1894
1912
  tree: f,
1895
1913
  limits: e,
1896
1914
  indexRangeGroupStrategy: n,
1897
- ...i
1915
+ ...a
1898
1916
  });
1899
1917
  }
1900
1918
  function qe(t, r) {
@@ -1902,8 +1920,8 @@ function qe(t, r) {
1902
1920
  return "No results found";
1903
1921
  let s = "";
1904
1922
  function o(e, n) {
1905
- for (let i = 0, a = e.length; i < a; i++) {
1906
- const u = e[i];
1923
+ for (let a = 0, i = e.length; a < i; a++) {
1924
+ const u = e[a];
1907
1925
  s += n, s += u.text.textOpen + `
1908
1926
  `, u.childs != null && u.childs.length > 0 && o(
1909
1927
  u.childs,
@@ -1914,7 +1932,7 @@ function qe(t, r) {
1914
1932
  }
1915
1933
  return o(t, ""), s;
1916
1934
  }
1917
- class ar {
1935
+ class lr {
1918
1936
  tokens = 16;
1919
1937
  // +1 indent, +1 for line break
1920
1938
  getReportText = (r) => ({
@@ -1951,7 +1969,7 @@ const _e = p.object({
1951
1969
  // maxCountGroup: z.number().default(10).describe('Maximum items per group'),
1952
1970
  // maxTokensGroup: z.number().default(1000).describe('Maximum tokens per group'),
1953
1971
  });
1954
- async function lr(t, r, s) {
1972
+ async function cr(t, r, s) {
1955
1973
  let o;
1956
1974
  try {
1957
1975
  o = _e.parse(t);
@@ -1963,18 +1981,18 @@ async function lr(t, r, s) {
1963
1981
  const {
1964
1982
  snapshotName: e,
1965
1983
  snapshot: n,
1966
- childsIndexRange: i
1984
+ childsIndexRange: a
1967
1985
  // maxCountTotal,
1968
1986
  // maxTokensTotal,
1969
1987
  // maxCountGroup,
1970
1988
  // maxTokensGroup,
1971
- } = o, a = 60, u = 1e3, l = 25, c = 900;
1989
+ } = o, i = 60, u = 1e3, l = 25, c = 900;
1972
1990
  if (!s.sessionId)
1973
1991
  return {
1974
1992
  error: "Session ID is required"
1975
1993
  };
1976
1994
  const f = V(s.sessionId);
1977
- let d, m = !1, h = !1;
1995
+ let d, h = !1, m = !1;
1978
1996
  if (e && n)
1979
1997
  return {
1980
1998
  error: "Either snapshotName or snapshot must be provided, not both"
@@ -1994,7 +2012,7 @@ async function lr(t, r, s) {
1994
2012
  return {
1995
2013
  error: g.error
1996
2014
  };
1997
- d = g.fsSnapshot, m = g.queryCreated, h = !0;
2015
+ d = g.fsSnapshot, h = g.queryCreated, m = !0;
1998
2016
  } else
1999
2017
  return {
2000
2018
  error: "Either snapshotName or snapshot must be provided"
@@ -2004,22 +2022,22 @@ async function lr(t, r, s) {
2004
2022
  tree: d.tree,
2005
2023
  request: {
2006
2024
  parentNodeId: g,
2007
- childsIndexRange: i,
2025
+ childsIndexRange: a,
2008
2026
  limits: {
2009
- maxCountTotal: a,
2027
+ maxCountTotal: i,
2010
2028
  maxTokensTotal: u,
2011
2029
  maxCountGroup: l,
2012
2030
  maxTokensGroup: c
2013
2031
  }
2014
2032
  },
2015
- indexRangeGroupStrategy: new ar()
2033
+ indexRangeGroupStrategy: new lr()
2016
2034
  }), y = qe(b);
2017
2035
  return {
2018
2036
  fsSnapshot: d,
2019
- queryCreated: m,
2020
- snapshotCreated: h,
2037
+ queryCreated: h,
2038
+ snapshotCreated: m,
2021
2039
  parentPath: g,
2022
- childsIndexRange: i,
2040
+ childsIndexRange: a,
2023
2041
  report: y
2024
2042
  };
2025
2043
  } catch (g) {
@@ -2028,7 +2046,7 @@ async function lr(t, r, s) {
2028
2046
  };
2029
2047
  }
2030
2048
  }
2031
- function cr(t, r) {
2049
+ function ur(t, r) {
2032
2050
  t(
2033
2051
  "fs-snapshot-browse",
2034
2052
  {
@@ -2037,7 +2055,7 @@ function cr(t, r) {
2037
2055
  inputSchema: _e.shape
2038
2056
  },
2039
2057
  async (s, o) => {
2040
- const e = await lr(s, r, o);
2058
+ const e = await cr(s, r, o);
2041
2059
  if (e.error != null)
2042
2060
  return `Method: fs-snapshot-browse(${JSON.stringify(s)})
2043
2061
  ❌ Error: ${e.error}`;
@@ -2048,10 +2066,10 @@ function cr(t, r) {
2048
2066
  `), n += `✅ Browsing filesystem snapshot "${e.fsSnapshot.name}":
2049
2067
  `, n += `Root directory: ${e.fsSnapshot.query.rootDir || "./"}
2050
2068
  `, n += `Parent path: ${"./" + (e.parentPath ?? "")}
2051
- `, n += `Fields: ${e.fsSnapshot.query.fields.map((i) => i === "dateModified" ? "lastModified" : i).join(" ")}
2069
+ `, n += `Fields: ${e.fsSnapshot.query.fields.map((a) => a === "dateModified" ? "lastModified" : a).join(" ")}
2052
2070
  `, e.childsIndexRange) {
2053
- const [i, a] = e.childsIndexRange, l = (e.parentPath ? e.fsSnapshot.tree.getNode(e.parentPath) : e.fsSnapshot.tree.root).countChilds;
2054
- n += ` Showing indexes: ${i}-${a} of ${l}
2071
+ const [a, i] = e.childsIndexRange, l = (e.parentPath ? e.fsSnapshot.tree.getNode(e.parentPath) : e.fsSnapshot.tree.root).countChilds;
2072
+ n += ` Showing indexes: ${a}-${i} of ${l}
2055
2073
  `;
2056
2074
  }
2057
2075
  return n += `
@@ -2059,8 +2077,8 @@ ${e.report}`, n;
2059
2077
  }
2060
2078
  );
2061
2079
  }
2062
- function ur(t, r) {
2063
- r.list && Qt(t, r), r.snapshotQueryCreate && Yt(t, r), r.snapshotCreate && or(t, r), r.snapshotBrowse && cr(t, r), console.log(
2080
+ function dr(t, r) {
2081
+ r.list && Ht(t, r), r.snapshotQueryCreate && Vt(t, r), r.snapshotCreate && nr(t, r), r.snapshotBrowse && ur(t, r), console.log(
2064
2082
  `File manager:
2065
2083
  - Working directory: ${T.resolve(r.workingDir || "")}
2066
2084
  `
@@ -2090,7 +2108,7 @@ async function je(t, r, s) {
2090
2108
  error: C(c)
2091
2109
  };
2092
2110
  }
2093
- const { name: e, browserType: n, muteAudio: i, devTools: a } = o;
2111
+ const { name: e, browserType: n, muteAudio: a, devTools: i } = o;
2094
2112
  if (!s.sessionId)
2095
2113
  return {
2096
2114
  error: "Session ID is required"
@@ -2102,13 +2120,13 @@ async function je(t, r, s) {
2102
2120
  };
2103
2121
  try {
2104
2122
  const f = await {
2105
- chromium: gt,
2106
- firefox: pt,
2107
- webkit: ht
2123
+ chromium: wt,
2124
+ firefox: gt,
2125
+ webkit: pt
2108
2126
  }[n].launch({
2109
2127
  headless: !1,
2110
- devtools: a,
2111
- args: i ? ["--mute-audio"] : void 0
2128
+ devtools: i,
2129
+ args: a ? ["--mute-audio"] : void 0
2112
2130
  }), d = {
2113
2131
  name: e,
2114
2132
  browserType: n,
@@ -2122,7 +2140,7 @@ async function je(t, r, s) {
2122
2140
  };
2123
2141
  }
2124
2142
  }
2125
- function dr(t, r) {
2143
+ function fr(t, r) {
2126
2144
  t(
2127
2145
  "playwright-browser-create",
2128
2146
  {
@@ -2138,13 +2156,13 @@ ${e.error != null ? `❌ Error: ${e.error}` : `✅ Browser "${e.browserInfo.name
2138
2156
  );
2139
2157
  }
2140
2158
  const Je = p.object({});
2141
- async function fr(t, r, s) {
2159
+ async function hr(t, r, s) {
2142
2160
  let o;
2143
2161
  try {
2144
2162
  o = Je.parse(t);
2145
- } catch (i) {
2163
+ } catch (a) {
2146
2164
  return {
2147
- error: C(i)
2165
+ error: C(a)
2148
2166
  };
2149
2167
  }
2150
2168
  if (!s.sessionId)
@@ -2165,12 +2183,12 @@ function mr(t, r) {
2165
2183
  inputSchema: Je.shape
2166
2184
  },
2167
2185
  async (s, o) => {
2168
- const e = await fr(s, r, o);
2186
+ const e = await hr(s, r, o);
2169
2187
  if (e.error != null)
2170
2188
  return `Method: playwright-browser-list(${JSON.stringify(s)})
2171
2189
  ❌ Error: ${e.error}`;
2172
2190
  const n = e.browserInfos.map(
2173
- (i) => `${i.name} (${i.browserType})`
2191
+ (a) => `${a.name} (${a.browserType})`
2174
2192
  );
2175
2193
  return `Method: playwright-browser-list(${JSON.stringify(s)})
2176
2194
  ${n.length === 0 ? "No browsers found" : `Browsers: ${n.join(", ")}`}`;
@@ -2182,7 +2200,7 @@ const Ke = p.object({
2182
2200
  "Names of browsers to close. If not specified, closes all browsers"
2183
2201
  )
2184
2202
  });
2185
- async function hr(t, r, s) {
2203
+ async function pr(t, r, s) {
2186
2204
  let o;
2187
2205
  try {
2188
2206
  o = Ke.parse(t);
@@ -2196,27 +2214,27 @@ async function hr(t, r, s) {
2196
2214
  return {
2197
2215
  error: "Session ID is required"
2198
2216
  };
2199
- const n = E(s.sessionId), i = [], a = [];
2217
+ const n = E(s.sessionId), a = [], i = [];
2200
2218
  let u = [];
2201
2219
  return e ? e.forEach((l) => {
2202
2220
  const c = n.browsers.get(l);
2203
- c ? u.push(c) : a.push(`Browser "${l}" not found`);
2221
+ c ? u.push(c) : i.push(`Browser "${l}" not found`);
2204
2222
  }) : u = Array.from(n.browsers.values()), await Promise.all(
2205
2223
  u.map(async (l) => {
2206
2224
  try {
2207
- await l.browser.close(), n.browsers.delete(l.name), i.push(l);
2225
+ await l.browser.close(), n.browsers.delete(l.name), a.push(l);
2208
2226
  } catch (c) {
2209
- a.push(
2227
+ i.push(
2210
2228
  `Failed to close browser "${l.name}" (${l.browserType}): ${c instanceof Error ? c.message : "Unknown error"}`
2211
2229
  );
2212
2230
  }
2213
2231
  })
2214
2232
  ), {
2215
- closedBrowserInfos: i,
2216
- ...a.length > 0 && { errors: a }
2233
+ closedBrowserInfos: a,
2234
+ ...i.length > 0 && { errors: i }
2217
2235
  };
2218
2236
  }
2219
- function pr(t, r) {
2237
+ function gr(t, r) {
2220
2238
  t(
2221
2239
  "playwright-browser-close",
2222
2240
  {
@@ -2225,18 +2243,18 @@ function pr(t, r) {
2225
2243
  inputSchema: Ke.shape
2226
2244
  },
2227
2245
  async (s, o) => {
2228
- const e = await hr(s, r, o);
2246
+ const e = await pr(s, r, o);
2229
2247
  if (e.error != null)
2230
2248
  return `Method: playwright-browser-close(${JSON.stringify(s)})
2231
2249
  ❌ Error: ${e.error}`;
2232
2250
  const n = [];
2233
2251
  if (e.closedBrowserInfos.length > 0) {
2234
- const i = e.closedBrowserInfos.map(
2235
- (a) => `${a.name} (${a.browserType})`
2252
+ const a = e.closedBrowserInfos.map(
2253
+ (i) => `${i.name} (${i.browserType})`
2236
2254
  );
2237
- n.push(`✅ Closed browsers: ${i.join(", ")}`);
2255
+ n.push(`✅ Closed browsers: ${a.join(", ")}`);
2238
2256
  }
2239
- return e.errors && e.errors.length > 0 && (n.length > 0 && n.push(""), n.push("❌ Errors:"), e.errors.forEach((i) => n.push(i))), n.length === 0 && n.push("No browsers to close"), `Method: playwright-browser-close(${JSON.stringify(s)})
2257
+ return e.errors && e.errors.length > 0 && (n.length > 0 && n.push(""), n.push("❌ Errors:"), e.errors.forEach((a) => n.push(a))), n.length === 0 && n.push("No browsers to close"), `Method: playwright-browser-close(${JSON.stringify(s)})
2240
2258
  ${n.join(`
2241
2259
  `)}`;
2242
2260
  }
@@ -2261,18 +2279,18 @@ async function We(t, r, s) {
2261
2279
  let o;
2262
2280
  try {
2263
2281
  o = te.parse(t);
2264
- } catch (m) {
2282
+ } catch (h) {
2265
2283
  return {
2266
- error: C(m)
2284
+ error: C(h)
2267
2285
  };
2268
2286
  }
2269
- const { name: e, browserName: n, browser: i, isMobile: a, hasTouch: u, viewport: l } = o;
2287
+ const { name: e, browserName: n, browser: a, isMobile: i, hasTouch: u, viewport: l } = o;
2270
2288
  if (!s.sessionId)
2271
2289
  return {
2272
2290
  error: "Session ID is required"
2273
2291
  };
2274
2292
  const c = E(s.sessionId);
2275
- if (n && i)
2293
+ if (n && a)
2276
2294
  return {
2277
2295
  error: "Either browserName or browser must be provided, not both"
2278
2296
  };
@@ -2282,13 +2300,13 @@ async function We(t, r, s) {
2282
2300
  return {
2283
2301
  error: `Browser "${n}" not found`
2284
2302
  };
2285
- } else if (i) {
2286
- const m = await je(i, r, s);
2287
- if (m.error != null)
2303
+ } else if (a) {
2304
+ const h = await je(a, r, s);
2305
+ if (h.error != null)
2288
2306
  return {
2289
- error: m.error
2307
+ error: h.error
2290
2308
  };
2291
- d = m.browserInfo, f = !0;
2309
+ d = h.browserInfo, f = !0;
2292
2310
  } else
2293
2311
  return {
2294
2312
  error: "Either browserName or browser must be provided"
@@ -2298,28 +2316,28 @@ async function We(t, r, s) {
2298
2316
  error: `Context "${e}" already exists in browser "${d.name}" (${d.browserType})`
2299
2317
  };
2300
2318
  try {
2301
- const m = await d.browser.newContext({
2302
- isMobile: a,
2319
+ const h = await d.browser.newContext({
2320
+ isMobile: i,
2303
2321
  hasTouch: u,
2304
2322
  viewport: l
2305
- }), h = {
2323
+ }), m = {
2306
2324
  browserInfo: d,
2307
2325
  name: e,
2308
- context: m,
2326
+ context: h,
2309
2327
  pages: /* @__PURE__ */ new Map()
2310
2328
  };
2311
- return d.contexts.set(e, h), {
2329
+ return d.contexts.set(e, m), {
2312
2330
  browserInfoCreated: f,
2313
2331
  browserInfo: d,
2314
- contextInfo: h
2332
+ contextInfo: m
2315
2333
  };
2316
- } catch (m) {
2334
+ } catch (h) {
2317
2335
  return {
2318
- error: `Failed to create context: ${m instanceof Error ? m.message : "Unknown error"} in browser "${d.name}" (${d.browserType})`
2336
+ error: `Failed to create context: ${h instanceof Error ? h.message : "Unknown error"} in browser "${d.name}" (${d.browserType})`
2319
2337
  };
2320
2338
  }
2321
2339
  }
2322
- function gr(t, r) {
2340
+ function wr(t, r) {
2323
2341
  t(
2324
2342
  "playwright-context-create",
2325
2343
  {
@@ -2344,13 +2362,13 @@ const Qe = p.object({
2344
2362
  "Name of browser to list contexts from. If not specified, lists contexts from all browsers"
2345
2363
  )
2346
2364
  });
2347
- async function wr(t, r, s) {
2365
+ async function yr(t, r, s) {
2348
2366
  let o;
2349
2367
  try {
2350
2368
  o = Qe.parse(t);
2351
- } catch (a) {
2369
+ } catch (i) {
2352
2370
  return {
2353
- error: C(a)
2371
+ error: C(i)
2354
2372
  };
2355
2373
  }
2356
2374
  const { browserName: e } = o;
@@ -2358,30 +2376,30 @@ async function wr(t, r, s) {
2358
2376
  return {
2359
2377
  error: "Session ID is required"
2360
2378
  };
2361
- const n = E(s.sessionId), i = [];
2379
+ const n = E(s.sessionId), a = [];
2362
2380
  if (e) {
2363
- const a = n.browsers.get(e);
2364
- if (!a)
2381
+ const i = n.browsers.get(e);
2382
+ if (!i)
2365
2383
  return {
2366
2384
  error: `Browser "${e}" not found`
2367
2385
  };
2368
- Array.from(a.contexts.values()).length > 0 && i.push({
2369
- browserInfo: a,
2370
- contexts: Array.from(a.contexts.values())
2386
+ Array.from(i.contexts.values()).length > 0 && a.push({
2387
+ browserInfo: i,
2388
+ contexts: Array.from(i.contexts.values())
2371
2389
  });
2372
2390
  } else
2373
- for (const a of n.browsers.values()) {
2374
- const u = Array.from(a.contexts.values());
2375
- u.length > 0 && i.push({
2376
- browserInfo: a,
2391
+ for (const i of n.browsers.values()) {
2392
+ const u = Array.from(i.contexts.values());
2393
+ u.length > 0 && a.push({
2394
+ browserInfo: i,
2377
2395
  contexts: u
2378
2396
  });
2379
2397
  }
2380
2398
  return {
2381
- contextsByBrowser: i
2399
+ contextsByBrowser: a
2382
2400
  };
2383
2401
  }
2384
- function yr(t, r) {
2402
+ function br(t, r) {
2385
2403
  t(
2386
2404
  "playwright-context-list",
2387
2405
  {
@@ -2390,14 +2408,14 @@ function yr(t, r) {
2390
2408
  inputSchema: Qe.shape
2391
2409
  },
2392
2410
  async (s, o) => {
2393
- const e = await wr(s, r, o);
2411
+ const e = await yr(s, r, o);
2394
2412
  if ("error" in e)
2395
2413
  return `Method: playwright-context-list(${JSON.stringify(s)})
2396
2414
  ❌ Error: ${e.error}`;
2397
2415
  let n = `Method: playwright-context-list(${JSON.stringify(s)})
2398
2416
  `;
2399
2417
  return e.contextsByBrowser.length === 0 ? n += "No contexts found" : n += e.contextsByBrowser.map(
2400
- ({ browserInfo: i, contexts: a }) => `${i.name} (${i.browserType}): ${a.map((u) => u.name).join(", ")}`
2418
+ ({ browserInfo: a, contexts: i }) => `${a.name} (${a.browserType}): ${i.map((u) => u.name).join(", ")}`
2401
2419
  ).join(`
2402
2420
  `), n;
2403
2421
  }
@@ -2411,7 +2429,7 @@ const He = p.object({
2411
2429
  "Name of browser to close contexts from. If not specified, searches all browsers"
2412
2430
  )
2413
2431
  });
2414
- async function br(t, r, s) {
2432
+ async function xr(t, r, s) {
2415
2433
  let o;
2416
2434
  try {
2417
2435
  o = He.parse(t);
@@ -2425,10 +2443,10 @@ async function br(t, r, s) {
2425
2443
  return {
2426
2444
  error: "Session ID is required"
2427
2445
  };
2428
- const i = E(s.sessionId), a = [], u = [];
2446
+ const a = E(s.sessionId), i = [], u = [];
2429
2447
  let l = [];
2430
2448
  if (n) {
2431
- const c = i.browsers.get(n);
2449
+ const c = a.browsers.get(n);
2432
2450
  if (!c)
2433
2451
  return {
2434
2452
  error: `Browser "${n}" not found`
@@ -2440,7 +2458,7 @@ async function br(t, r, s) {
2440
2458
  );
2441
2459
  }) : l = Array.from(c.contexts.values());
2442
2460
  } else if (e)
2443
- for (const c of i.browsers.values())
2461
+ for (const c of a.browsers.values())
2444
2462
  e.forEach((f) => {
2445
2463
  const d = c.contexts.get(f);
2446
2464
  d ? l.push(d) : u.push(
@@ -2448,12 +2466,12 @@ async function br(t, r, s) {
2448
2466
  );
2449
2467
  });
2450
2468
  else
2451
- for (const c of i.browsers.values())
2469
+ for (const c of a.browsers.values())
2452
2470
  l.push(...Array.from(c.contexts.values()));
2453
2471
  return await Promise.all(
2454
2472
  l.map(async (c) => {
2455
2473
  try {
2456
- await c.context.close(), c.browserInfo.contexts.delete(c.name), a.push(c);
2474
+ await c.context.close(), c.browserInfo.contexts.delete(c.name), i.push(c);
2457
2475
  } catch (f) {
2458
2476
  u.push(
2459
2477
  `Failed to close context "${c.name}" (${c.browserInfo.name}) (${c.browserInfo.browserType}): ${f instanceof Error ? f.message : "Unknown error"}`
@@ -2461,11 +2479,11 @@ async function br(t, r, s) {
2461
2479
  }
2462
2480
  })
2463
2481
  ), {
2464
- closedContextInfos: a,
2482
+ closedContextInfos: i,
2465
2483
  ...u.length > 0 && { errors: u }
2466
2484
  };
2467
2485
  }
2468
- function xr(t, r) {
2486
+ function Sr(t, r) {
2469
2487
  t(
2470
2488
  "playwright-context-close",
2471
2489
  {
@@ -2474,24 +2492,24 @@ function xr(t, r) {
2474
2492
  inputSchema: He.shape
2475
2493
  },
2476
2494
  async (s, o) => {
2477
- const e = await br(s, r, o);
2495
+ const e = await xr(s, r, o);
2478
2496
  if ("error" in e)
2479
2497
  return `Method: playwright-context-close(${JSON.stringify(s)})
2480
2498
  ❌ Error: ${e.error}`;
2481
2499
  const n = [];
2482
2500
  if (e.closedContextInfos.length > 0) {
2483
- const i = e.closedContextInfos.map(
2484
- (a) => `${a.name} (${a.browserInfo.name}) (${a.browserInfo.browserType})`
2501
+ const a = e.closedContextInfos.map(
2502
+ (i) => `${i.name} (${i.browserInfo.name}) (${i.browserInfo.browserType})`
2485
2503
  );
2486
- n.push(`✅ Closed contexts: ${i.join(", ")}`);
2504
+ n.push(`✅ Closed contexts: ${a.join(", ")}`);
2487
2505
  }
2488
- return e.errors && e.errors.length > 0 && (n.length > 0 && n.push(""), n.push("❌ Errors:"), e.errors.forEach((i) => n.push(i))), n.length === 0 && n.push("No contexts to close"), `Method: playwright-context-close(${JSON.stringify(s)})
2506
+ return e.errors && e.errors.length > 0 && (n.length > 0 && n.push(""), n.push("❌ Errors:"), e.errors.forEach((a) => n.push(a))), n.length === 0 && n.push("No contexts to close"), `Method: playwright-context-close(${JSON.stringify(s)})
2489
2507
  ${n.join(`
2490
2508
  `)}`;
2491
2509
  }
2492
2510
  );
2493
2511
  }
2494
- function Sr() {
2512
+ function $r() {
2495
2513
  class t {
2496
2514
  prevId = 0;
2497
2515
  objectToId = /* @__PURE__ */ new WeakMap();
@@ -2514,62 +2532,62 @@ function Sr() {
2514
2532
  return c ?? (this.idToObject.delete(u), null);
2515
2533
  }
2516
2534
  }
2517
- function r(a, u, l) {
2535
+ function r(i, u, l) {
2518
2536
  let c = null;
2519
2537
  for (let f = 0, d = u.length; f < d; f++) {
2520
- const m = u[f], h = a(m), g = h == null ? null : r(a, h, l), b = l(m, g);
2538
+ const h = u[f], m = i(h), g = m == null ? null : r(i, m, l), b = l(h, g);
2521
2539
  b != null && (c == null && (c = []), c.push(b));
2522
2540
  }
2523
2541
  return c;
2524
2542
  }
2525
- function s(a) {
2526
- const { getId: u, getChilds: l, rootNodes: c, createSnapshotNode: f } = a, d = /* @__PURE__ */ new Map(), m = /* @__PURE__ */ new Map(), h = /* @__PURE__ */ new Map(), g = r(
2543
+ function s(i) {
2544
+ const { getId: u, getChilds: l, rootNodes: c, createSnapshotNode: f } = i, d = /* @__PURE__ */ new Map(), h = /* @__PURE__ */ new Map(), m = /* @__PURE__ */ new Map(), g = r(
2527
2545
  l,
2528
2546
  c,
2529
2547
  (y, x) => {
2530
2548
  const I = f(y, x);
2531
2549
  if (y != null && I != null) {
2532
2550
  const S = u(y);
2533
- d.set(S, I), m.set(I, S);
2551
+ d.set(S, I), h.set(I, S);
2534
2552
  }
2535
- return I != null && x != null && h.set(
2536
- m.get(I),
2537
- x.map((S) => m.get(S))
2553
+ return I != null && x != null && m.set(
2554
+ h.get(I),
2555
+ x.map((S) => h.get(S))
2538
2556
  ), I;
2539
2557
  }
2540
2558
  ), b = f(null, g);
2541
2559
  if (b == null)
2542
2560
  throw new Error("Impossible behavior: rootNode == null");
2543
- return d.set(null, b), g != null && h.set(
2561
+ return d.set(null, b), g != null && m.set(
2544
2562
  null,
2545
- g.map((y) => m.get(y))
2563
+ g.map((y) => h.get(y))
2546
2564
  ), {
2547
2565
  idToNode: d,
2548
- idToChildIds: h
2566
+ idToChildIds: m
2549
2567
  };
2550
2568
  }
2551
- const o = (a) => a instanceof HTMLElement ? a.childNodes : null;
2552
- function e(a) {
2569
+ const o = (i) => i instanceof HTMLElement ? i.childNodes : null;
2570
+ function e(i) {
2553
2571
  return function(l, c) {
2554
2572
  const f = c != null && c.length > 0;
2555
- let d = !1, m = null, h = null;
2573
+ let d = !1, h = null, m = null;
2556
2574
  if (l instanceof HTMLElement) {
2557
- if (m = n.getOrCreateId(l), h = l.tagName.toLowerCase(), d = l.matches(a.cssSelector), !d && !f)
2575
+ if (h = n.getOrCreateId(l), m = l.tagName.toLowerCase(), d = l.matches(i.cssSelector), !d && !f)
2558
2576
  return null;
2559
2577
  } else if (l == null)
2560
- m = null, h = null, d = !1;
2578
+ h = null, m = null, d = !1;
2561
2579
  else
2562
2580
  return null;
2563
2581
  return {
2564
- uid: m,
2565
- tagName: h,
2582
+ uid: h,
2583
+ tagName: m,
2566
2584
  isMatched: d
2567
2585
  };
2568
2586
  };
2569
2587
  }
2570
2588
  const n = new t();
2571
- function i(a) {
2572
- const u = e(a);
2589
+ function a(i) {
2590
+ const u = e(i);
2573
2591
  return s({
2574
2592
  getId: (l) => n.getOrCreateId(l),
2575
2593
  getChilds: o,
@@ -2577,9 +2595,9 @@ function Sr() {
2577
2595
  rootNodes: [window.document.documentElement]
2578
2596
  });
2579
2597
  }
2580
- window.__mcp_playwright_tool_tx4byhar35_createDomSnapshotTreeRawDom = i;
2598
+ window.__mcp_playwright_tool_tx4byhar35_createDomSnapshotTreeRawDom = a;
2581
2599
  }
2582
- const $r = `(function (){function __name(fn){return fn};${Sr.toString()}; setupPageGlobals();})()`, re = p.object({
2600
+ const Ir = `(function (){function __name(fn){return fn};${$r.toString()}; setupPageGlobals();})()`, re = p.object({
2583
2601
  contextName: p.string().optional().describe("Name of previously created context, to use"),
2584
2602
  context: te.optional().describe(
2585
2603
  "Context creation options JSON to automatically create context"
@@ -2597,19 +2615,19 @@ async function Ye(t, r, s) {
2597
2615
  error: C(f)
2598
2616
  };
2599
2617
  }
2600
- const { name: e, contextName: n, context: i } = o;
2618
+ const { name: e, contextName: n, context: a } = o;
2601
2619
  if (!s.sessionId)
2602
2620
  return {
2603
2621
  error: "Session ID is required"
2604
2622
  };
2605
- const a = E(s.sessionId);
2606
- if (n && i)
2623
+ const i = E(s.sessionId);
2624
+ if (n && a)
2607
2625
  return {
2608
2626
  error: "Either contextName or context must be provided, not both"
2609
2627
  };
2610
2628
  let u = !1, l = !1, c;
2611
2629
  if (n) {
2612
- for (const f of a.browsers.values())
2630
+ for (const f of i.browsers.values())
2613
2631
  if (f.contexts.has(n)) {
2614
2632
  c = f.contexts.get(n);
2615
2633
  break;
@@ -2618,8 +2636,8 @@ async function Ye(t, r, s) {
2618
2636
  return {
2619
2637
  error: `Context "${n}" not found`
2620
2638
  };
2621
- } else if (i) {
2622
- const f = await We(i, r, s);
2639
+ } else if (a) {
2640
+ const f = await We(a, r, s);
2623
2641
  if (f.error != null)
2624
2642
  return {
2625
2643
  error: f.error
@@ -2635,7 +2653,7 @@ async function Ye(t, r, s) {
2635
2653
  };
2636
2654
  try {
2637
2655
  const f = await c.context.newPage();
2638
- await f.addInitScript($r), await f.goto("about:blank");
2656
+ await f.addInitScript(Ir), await f.goto("about:blank");
2639
2657
  const d = {
2640
2658
  contextInfo: c,
2641
2659
  name: e,
@@ -2653,7 +2671,7 @@ async function Ye(t, r, s) {
2653
2671
  };
2654
2672
  }
2655
2673
  }
2656
- function Ir(t, r) {
2674
+ function Mr(t, r) {
2657
2675
  t(
2658
2676
  "playwright-page-create",
2659
2677
  {
@@ -2682,7 +2700,7 @@ const Ve = p.object({
2682
2700
  "Name of browser to search in. If not specified, searches all browsers"
2683
2701
  )
2684
2702
  });
2685
- async function Mr(t, r, s) {
2703
+ async function Tr(t, r, s) {
2686
2704
  let o;
2687
2705
  try {
2688
2706
  o = Ve.parse(t);
@@ -2696,9 +2714,9 @@ async function Mr(t, r, s) {
2696
2714
  return {
2697
2715
  error: "Session ID is required"
2698
2716
  };
2699
- const i = E(s.sessionId), a = [];
2717
+ const a = E(s.sessionId), i = [];
2700
2718
  if (n) {
2701
- const u = i.browsers.get(n);
2719
+ const u = a.browsers.get(n);
2702
2720
  if (!u)
2703
2721
  return {
2704
2722
  error: `Browser "${n}" not found`
@@ -2710,43 +2728,43 @@ async function Mr(t, r, s) {
2710
2728
  error: `Context "${e}" not found in browser "${u.name}" (${u.browserType})`
2711
2729
  };
2712
2730
  const c = Array.from(l.pages.values());
2713
- c.length > 0 && a.push({
2731
+ c.length > 0 && i.push({
2714
2732
  contextInfo: l,
2715
2733
  pages: c
2716
2734
  });
2717
2735
  } else
2718
2736
  for (const l of u.contexts.values()) {
2719
2737
  const c = Array.from(l.pages.values());
2720
- c.length > 0 && a.push({
2738
+ c.length > 0 && i.push({
2721
2739
  contextInfo: l,
2722
2740
  pages: c
2723
2741
  });
2724
2742
  }
2725
2743
  } else if (e)
2726
- for (const u of i.browsers.values()) {
2744
+ for (const u of a.browsers.values()) {
2727
2745
  const l = u.contexts.get(e);
2728
2746
  if (l) {
2729
2747
  const c = Array.from(l.pages.values());
2730
- c.length > 0 && a.push({
2748
+ c.length > 0 && i.push({
2731
2749
  contextInfo: l,
2732
2750
  pages: c
2733
2751
  });
2734
2752
  }
2735
2753
  }
2736
2754
  else
2737
- for (const u of i.browsers.values())
2755
+ for (const u of a.browsers.values())
2738
2756
  for (const l of u.contexts.values()) {
2739
2757
  const c = Array.from(l.pages.values());
2740
- c.length > 0 && a.push({
2758
+ c.length > 0 && i.push({
2741
2759
  contextInfo: l,
2742
2760
  pages: c
2743
2761
  });
2744
2762
  }
2745
2763
  return {
2746
- pagesByContext: a
2764
+ pagesByContext: i
2747
2765
  };
2748
2766
  }
2749
- function Tr(t, r) {
2767
+ function vr(t, r) {
2750
2768
  t(
2751
2769
  "playwright-page-list",
2752
2770
  {
@@ -2755,14 +2773,14 @@ function Tr(t, r) {
2755
2773
  inputSchema: Ve.shape
2756
2774
  },
2757
2775
  async (s, o) => {
2758
- const e = await Mr(s, r, o);
2776
+ const e = await Tr(s, r, o);
2759
2777
  if ("error" in e)
2760
2778
  return `Method: playwright-page-list(${JSON.stringify(s)})
2761
2779
  ❌ Error: ${e.error}`;
2762
2780
  let n = `Method: playwright-page-list(${JSON.stringify(s)})
2763
2781
  `;
2764
2782
  return e.pagesByContext.length === 0 ? n += "No pages found" : n += e.pagesByContext.map(
2765
- ({ contextInfo: i, pages: a }) => `${i.name} (${i.browserInfo.name}) (${i.browserInfo.browserType}): ${a.map((u) => u.name).join(", ")}`
2783
+ ({ contextInfo: a, pages: i }) => `${a.name} (${a.browserInfo.name}) (${a.browserInfo.browserType}): ${i.map((u) => u.name).join(", ")}`
2766
2784
  ).join(`
2767
2785
  `), n;
2768
2786
  }
@@ -2777,7 +2795,7 @@ const Ze = p.object({
2777
2795
  "Name of browser to search in. If not specified, searches all browsers"
2778
2796
  )
2779
2797
  });
2780
- async function vr(t, r, s) {
2798
+ async function Cr(t, r, s) {
2781
2799
  let o;
2782
2800
  try {
2783
2801
  o = Ze.parse(t);
@@ -2786,18 +2804,18 @@ async function vr(t, r, s) {
2786
2804
  error: C(f)
2787
2805
  };
2788
2806
  }
2789
- const { names: e, contextName: n, browserName: i } = o;
2807
+ const { names: e, contextName: n, browserName: a } = o;
2790
2808
  if (!s.sessionId)
2791
2809
  return {
2792
2810
  error: "Session ID is required"
2793
2811
  };
2794
- const a = E(s.sessionId), u = [], l = [];
2812
+ const i = E(s.sessionId), u = [], l = [];
2795
2813
  let c = [];
2796
- if (i) {
2797
- const f = a.browsers.get(i);
2814
+ if (a) {
2815
+ const f = i.browsers.get(a);
2798
2816
  if (!f)
2799
2817
  return {
2800
- error: `Browser "${i}" not found`
2818
+ error: `Browser "${a}" not found`
2801
2819
  };
2802
2820
  if (n) {
2803
2821
  const d = f.contexts.get(n);
@@ -2805,37 +2823,37 @@ async function vr(t, r, s) {
2805
2823
  return {
2806
2824
  error: `Context "${n}" not found in browser "${f.name}" (${f.browserType})`
2807
2825
  };
2808
- e ? e.forEach((m) => {
2809
- const h = d.pages.get(m);
2810
- h ? c.push(h) : l.push(
2811
- `Page "${m}" not found in context "${d.name}" in browser "${f.name}" (${f.browserType})`
2826
+ e ? e.forEach((h) => {
2827
+ const m = d.pages.get(h);
2828
+ m ? c.push(m) : l.push(
2829
+ `Page "${h}" not found in context "${d.name}" in browser "${f.name}" (${f.browserType})`
2812
2830
  );
2813
2831
  }) : c = Array.from(d.pages.values());
2814
2832
  } else
2815
2833
  for (const d of f.contexts.values())
2816
- e ? e.forEach((m) => {
2817
- const h = d.pages.get(m);
2818
- h ? c.push(h) : l.push(
2819
- `Page "${m}" not found in context "${d.name}" in browser "${f.name}" (${f.browserType})`
2834
+ e ? e.forEach((h) => {
2835
+ const m = d.pages.get(h);
2836
+ m ? c.push(m) : l.push(
2837
+ `Page "${h}" not found in context "${d.name}" in browser "${f.name}" (${f.browserType})`
2820
2838
  );
2821
2839
  }) : c.push(...Array.from(d.pages.values()));
2822
2840
  } else if (n)
2823
- for (const f of a.browsers.values()) {
2841
+ for (const f of i.browsers.values()) {
2824
2842
  const d = f.contexts.get(n);
2825
- d && (e ? e.forEach((m) => {
2826
- const h = d.pages.get(m);
2827
- h ? c.push(h) : l.push(
2828
- `Page "${m}" not found in context "${d.name}" in browser "${f.name}" (${f.browserType})`
2843
+ d && (e ? e.forEach((h) => {
2844
+ const m = d.pages.get(h);
2845
+ m ? c.push(m) : l.push(
2846
+ `Page "${h}" not found in context "${d.name}" in browser "${f.name}" (${f.browserType})`
2829
2847
  );
2830
2848
  }) : c.push(...Array.from(d.pages.values())));
2831
2849
  }
2832
2850
  else
2833
- for (const f of a.browsers.values())
2851
+ for (const f of i.browsers.values())
2834
2852
  for (const d of f.contexts.values())
2835
- e ? e.forEach((m) => {
2836
- const h = d.pages.get(m);
2837
- h ? c.push(h) : l.push(
2838
- `Page "${m}" not found in context "${d.name}" in browser "${f.name}" (${f.browserType})`
2853
+ e ? e.forEach((h) => {
2854
+ const m = d.pages.get(h);
2855
+ m ? c.push(m) : l.push(
2856
+ `Page "${h}" not found in context "${d.name}" in browser "${f.name}" (${f.browserType})`
2839
2857
  );
2840
2858
  }) : c.push(...Array.from(d.pages.values()));
2841
2859
  return await Promise.all(
@@ -2855,7 +2873,7 @@ async function vr(t, r, s) {
2855
2873
  ...l.length > 0 && { errors: l }
2856
2874
  };
2857
2875
  }
2858
- function Cr(t, r) {
2876
+ function kr(t, r) {
2859
2877
  t(
2860
2878
  "playwright-page-close",
2861
2879
  {
@@ -2864,12 +2882,12 @@ function Cr(t, r) {
2864
2882
  inputSchema: Ze.shape
2865
2883
  },
2866
2884
  async (s, o) => {
2867
- const e = await vr(s, r, o);
2885
+ const e = await Cr(s, r, o);
2868
2886
  if ("error" in e)
2869
2887
  return `Method: playwright-page-close(${JSON.stringify(s)})
2870
2888
  ❌ Error: ${e.error}`;
2871
2889
  const n = [];
2872
- return e.closedPages.length > 0 && n.push(`✅ Closed pages: ${e.closedPages.join(", ")}`), e.errors && e.errors.length > 0 && (n.length > 0 && n.push(""), n.push("❌ Errors:"), e.errors.forEach((i) => n.push(i))), n.length === 0 && n.push("No pages to close"), `Method: playwright-page-close(${JSON.stringify(s)})
2890
+ return e.closedPages.length > 0 && n.push(`✅ Closed pages: ${e.closedPages.join(", ")}`), e.errors && e.errors.length > 0 && (n.length > 0 && n.push(""), n.push("❌ Errors:"), e.errors.forEach((a) => n.push(a))), n.length === 0 && n.push("No pages to close"), `Method: playwright-page-close(${JSON.stringify(s)})
2873
2891
  ${n.join(`
2874
2892
  `)}`;
2875
2893
  }
@@ -2890,16 +2908,16 @@ const Xe = p.object({
2890
2908
  - 'commit': network response received and document started loading`
2891
2909
  )
2892
2910
  });
2893
- async function kr(t, r, s) {
2911
+ async function Nr(t, r, s) {
2894
2912
  let o;
2895
2913
  try {
2896
2914
  o = Xe.parse(t);
2897
- } catch (h) {
2915
+ } catch (m) {
2898
2916
  return {
2899
- error: C(h)
2917
+ error: C(m)
2900
2918
  };
2901
2919
  }
2902
- const { pageName: e, page: n, url: i, timeout: a, waitUntil: u } = o;
2920
+ const { pageName: e, page: n, url: a, timeout: i, waitUntil: u } = o;
2903
2921
  if (!s.sessionId)
2904
2922
  return {
2905
2923
  error: "Session ID is required"
@@ -2909,56 +2927,56 @@ async function kr(t, r, s) {
2909
2927
  return {
2910
2928
  error: "Either pageName or page must be provided, not both"
2911
2929
  };
2912
- let c = !1, f = !1, d = !1, m;
2930
+ let c = !1, f = !1, d = !1, h;
2913
2931
  if (e) {
2914
- for (const h of l.browsers.values()) {
2915
- for (const g of h.contexts.values())
2932
+ for (const m of l.browsers.values()) {
2933
+ for (const g of m.contexts.values())
2916
2934
  if (g.pages.has(e)) {
2917
- m = g.pages.get(e);
2935
+ h = g.pages.get(e);
2918
2936
  break;
2919
2937
  }
2920
- if (m) break;
2938
+ if (h) break;
2921
2939
  }
2922
- if (!m)
2940
+ if (!h)
2923
2941
  return {
2924
2942
  error: `Page "${e}" not found`
2925
2943
  };
2926
2944
  } else if (n) {
2927
- const h = await Ye(n, r, s);
2928
- if (h.error != null)
2945
+ const m = await Ye(n, r, s);
2946
+ if (m.error != null)
2929
2947
  return {
2930
- error: h.error
2948
+ error: m.error
2931
2949
  };
2932
- m = h.pageInfo, c = h.browserInfoCreated, f = h.contextInfoCreated, d = !0;
2950
+ h = m.pageInfo, c = m.browserInfoCreated, f = m.contextInfoCreated, d = !0;
2933
2951
  } else
2934
2952
  return {
2935
2953
  error: "Either pageName or page must be provided"
2936
2954
  };
2937
2955
  try {
2938
- const h = await m.page.goto(i, {
2939
- timeout: a * 1e3,
2956
+ const m = await h.page.goto(a, {
2957
+ timeout: i * 1e3,
2940
2958
  waitUntil: u
2941
2959
  });
2942
- return h ? {
2960
+ return m ? {
2943
2961
  browserInfoCreated: c,
2944
2962
  contextInfoCreated: f,
2945
2963
  pageInfoCreated: d,
2946
- pageInfo: m,
2947
- status: h.status()
2964
+ pageInfo: h,
2965
+ status: m.status()
2948
2966
  } : {
2949
2967
  browserInfoCreated: c,
2950
2968
  contextInfoCreated: f,
2951
2969
  pageInfoCreated: d,
2952
- pageInfo: m,
2970
+ pageInfo: h,
2953
2971
  status: 200
2954
2972
  };
2955
- } catch (h) {
2973
+ } catch (m) {
2956
2974
  return {
2957
- error: `Failed to navigate to "${i}": ${h instanceof Error ? h.message : "Unknown error"}`
2975
+ error: `Failed to navigate to "${a}": ${m instanceof Error ? m.message : "Unknown error"}`
2958
2976
  };
2959
2977
  }
2960
2978
  }
2961
- function Nr(t, r) {
2979
+ function Dr(t, r) {
2962
2980
  t(
2963
2981
  "playwright-page-goto",
2964
2982
  {
@@ -2967,7 +2985,7 @@ function Nr(t, r) {
2967
2985
  inputSchema: Xe.shape
2968
2986
  },
2969
2987
  async (s, o) => {
2970
- const e = await kr(s, r, o);
2988
+ const e = await Nr(s, r, o);
2971
2989
  if (e.error != null)
2972
2990
  return `Method: playwright-page-goto(${JSON.stringify(s)})
2973
2991
  ❌ Error: ${e.error}`;
@@ -3000,20 +3018,20 @@ async function et(t, r, s) {
3000
3018
  return {
3001
3019
  error: "Session ID is required"
3002
3020
  };
3003
- const i = E(s.sessionId);
3004
- if (i.domSnapshotQueries.has(e))
3021
+ const a = E(s.sessionId);
3022
+ if (a.domSnapshotQueries.has(e))
3005
3023
  return {
3006
3024
  error: `DOM snapshot query "${e}" already exists`
3007
3025
  };
3008
- const a = {
3026
+ const i = {
3009
3027
  name: e,
3010
3028
  cssSelector: n
3011
3029
  };
3012
- return i.domSnapshotQueries.set(e, a), {
3013
- snapshotQuery: a
3030
+ return a.domSnapshotQueries.set(e, i), {
3031
+ snapshotQuery: i
3014
3032
  };
3015
3033
  }
3016
- function Dr(t, r) {
3034
+ function Er(t, r) {
3017
3035
  t(
3018
3036
  "playwright-dom-snapshot-query-create",
3019
3037
  {
@@ -3029,15 +3047,15 @@ function Dr(t, r) {
3029
3047
  }
3030
3048
  );
3031
3049
  }
3032
- function Er(t) {
3050
+ function Fr(t) {
3033
3051
  return function(s, o) {
3034
3052
  let e, n = 0;
3035
- const i = o ? o.length : 0;
3036
- let a = 1, u = 0, l = 0, c, f;
3053
+ const a = o ? o.length : 0;
3054
+ let i = 1, u = 0, l = 0, c, f;
3037
3055
  if (o)
3038
- for (let h = 0; h < o.length; h++) {
3039
- const g = o[h];
3040
- n += g.countMatched, a += g.countTotal, u += g.tokens, l += g.tokensTotal;
3056
+ for (let m = 0; m < o.length; m++) {
3057
+ const g = o[m];
3058
+ n += g.countMatched, i += g.countTotal, u += g.tokens, l += g.tokensTotal;
3041
3059
  }
3042
3060
  s ? (c = s.uid, f = s.tagName, e = s.isMatched, e && (n += 1)) : (c = null, f = null, e = !1);
3043
3061
  let d;
@@ -3050,15 +3068,15 @@ function Er(t) {
3050
3068
  textOpen: `<root uid:${c}>`,
3051
3069
  textClose: "</root>"
3052
3070
  };
3053
- const m = Ue(d);
3054
- return l += m, {
3071
+ const h = Ue(d);
3072
+ return l += h, {
3055
3073
  uid: c,
3056
3074
  tagName: f,
3057
3075
  isMatched: e,
3058
3076
  countMatched: n,
3059
- countChilds: i,
3060
- countTotal: a,
3061
- tokens: m,
3077
+ countChilds: a,
3078
+ countTotal: i,
3079
+ tokens: h,
3062
3080
  tokensChilds: u,
3063
3081
  tokensTotal: l,
3064
3082
  text: d
@@ -3068,15 +3086,15 @@ function Er(t) {
3068
3086
  function Br(t, r) {
3069
3087
  const s = _(r), o = s.getChilds(s.root), e = Le({
3070
3088
  getId: (n) => {
3071
- const i = s.getId(n);
3072
- if (i == null)
3089
+ const a = s.getId(n);
3090
+ if (a == null)
3073
3091
  throw new Error(
3074
3092
  `Invalid tree structure: node ID is null for node ${JSON.stringify(n)}`
3075
3093
  );
3076
- return i;
3094
+ return a;
3077
3095
  },
3078
3096
  getChilds: (n) => s.getChilds(n),
3079
- createSnapshotNode: Er(),
3097
+ createSnapshotNode: Fr(),
3080
3098
  rootNodes: o ?? []
3081
3099
  });
3082
3100
  return _(e);
@@ -3100,7 +3118,7 @@ async function tt(t, r, s) {
3100
3118
  error: C(d)
3101
3119
  };
3102
3120
  }
3103
- const { pageName: e, queryName: n, query: i, name: a } = o;
3121
+ const { pageName: e, queryName: n, query: a, name: i } = o;
3104
3122
  if (!s.sessionId)
3105
3123
  return {
3106
3124
  error: "Session ID is required"
@@ -3108,9 +3126,9 @@ async function tt(t, r, s) {
3108
3126
  const u = E(s.sessionId);
3109
3127
  let l;
3110
3128
  for (const d of u.browsers.values()) {
3111
- for (const m of d.contexts.values())
3112
- if (m.pages.has(e)) {
3113
- l = m.pages.get(e);
3129
+ for (const h of d.contexts.values())
3130
+ if (h.pages.has(e)) {
3131
+ l = h.pages.get(e);
3114
3132
  break;
3115
3133
  }
3116
3134
  if (l) break;
@@ -3119,11 +3137,11 @@ async function tt(t, r, s) {
3119
3137
  return {
3120
3138
  error: `Page "${e}" not found`
3121
3139
  };
3122
- if (l.domSnapshots.has(a))
3140
+ if (l.domSnapshots.has(i))
3123
3141
  return {
3124
- error: `DOM snapshot "${a}" already exists in page "${e}"`
3142
+ error: `DOM snapshot "${i}" already exists in page "${e}"`
3125
3143
  };
3126
- if (n && i)
3144
+ if (n && a)
3127
3145
  return {
3128
3146
  error: "Either queryName or query must be provided, not both"
3129
3147
  };
@@ -3135,9 +3153,9 @@ async function tt(t, r, s) {
3135
3153
  error: `DOM snapshot query "${n}" not found`
3136
3154
  };
3137
3155
  c = d;
3138
- } else if (i) {
3156
+ } else if (a) {
3139
3157
  const d = await et(
3140
- i,
3158
+ a,
3141
3159
  r,
3142
3160
  s
3143
3161
  );
@@ -3163,15 +3181,15 @@ async function tt(t, r, s) {
3163
3181
  };
3164
3182
  },
3165
3183
  c
3166
- ), m = {
3184
+ ), h = {
3167
3185
  idToNode: new Map(d.idToNode),
3168
3186
  idToChildIds: new Map(d.idToChildIds)
3169
- }, h = Br(c, m), g = {
3170
- name: a,
3187
+ }, m = Br(c, h), g = {
3188
+ name: i,
3171
3189
  query: c,
3172
- tree: h
3190
+ tree: m
3173
3191
  };
3174
- return l.domSnapshots.set(a, g), {
3192
+ return l.domSnapshots.set(i, g), {
3175
3193
  domSnapshot: g,
3176
3194
  queryCreated: f
3177
3195
  };
@@ -3181,7 +3199,7 @@ async function tt(t, r, s) {
3181
3199
  };
3182
3200
  }
3183
3201
  }
3184
- function Fr(t, r) {
3202
+ function Or(t, r) {
3185
3203
  t(
3186
3204
  "playwright-dom-snapshot-create",
3187
3205
  {
@@ -3201,7 +3219,7 @@ function Fr(t, r) {
3201
3219
  }
3202
3220
  );
3203
3221
  }
3204
- class Or {
3222
+ class Rr {
3205
3223
  tokens = 16;
3206
3224
  getReportText = (r) => ({
3207
3225
  indent: !0,
@@ -3235,7 +3253,7 @@ const rt = p.object({
3235
3253
  // maxCountGroup: z.number().default(10).describe('Maximum items per group'),
3236
3254
  // maxTokensGroup: z.number().default(1000).describe('Maximum tokens per group'),
3237
3255
  });
3238
- async function Rr(t, r, s) {
3256
+ async function zr(t, r, s) {
3239
3257
  let o;
3240
3258
  try {
3241
3259
  o = rt.parse(t);
@@ -3247,12 +3265,12 @@ async function Rr(t, r, s) {
3247
3265
  const {
3248
3266
  snapshotName: e,
3249
3267
  snapshot: n,
3250
- childsIndexRange: i
3268
+ childsIndexRange: a
3251
3269
  // maxCountTotal,
3252
3270
  // maxTokensTotal,
3253
3271
  // maxCountGroup,
3254
3272
  // maxTokensGroup,
3255
- } = o, a = 60, u = 1e3, l = 25, c = 900;
3273
+ } = o, i = 60, u = 1e3, l = 25, c = 900;
3256
3274
  if (!s.sessionId)
3257
3275
  return {
3258
3276
  error: "Session ID is required"
@@ -3262,7 +3280,7 @@ async function Rr(t, r, s) {
3262
3280
  return {
3263
3281
  error: "Either snapshotName or snapshot must be provided, not both"
3264
3282
  };
3265
- let d, m = !1, h = !1;
3283
+ let d, h = !1, m = !1;
3266
3284
  if (e) {
3267
3285
  for (const g of f.browsers.values()) {
3268
3286
  for (const b of g.contexts.values()) {
@@ -3289,7 +3307,7 @@ async function Rr(t, r, s) {
3289
3307
  return {
3290
3308
  error: g.error
3291
3309
  };
3292
- d = g.domSnapshot, m = g.queryCreated, h = !0;
3310
+ d = g.domSnapshot, h = g.queryCreated, m = !0;
3293
3311
  } else
3294
3312
  return {
3295
3313
  error: "Either snapshotName or snapshot must be provided"
@@ -3299,22 +3317,22 @@ async function Rr(t, r, s) {
3299
3317
  tree: d.tree,
3300
3318
  request: {
3301
3319
  parentNodeId: g,
3302
- childsIndexRange: i,
3320
+ childsIndexRange: a,
3303
3321
  limits: {
3304
- maxCountTotal: a,
3322
+ maxCountTotal: i,
3305
3323
  maxTokensTotal: u,
3306
3324
  maxCountGroup: l,
3307
3325
  maxTokensGroup: c
3308
3326
  }
3309
3327
  },
3310
- indexRangeGroupStrategy: new Or()
3328
+ indexRangeGroupStrategy: new Rr()
3311
3329
  }), y = qe(b);
3312
3330
  return {
3313
3331
  domSnapshot: d,
3314
- queryCreated: m,
3315
- snapshotCreated: h,
3332
+ queryCreated: h,
3333
+ snapshotCreated: m,
3316
3334
  parentUid: g,
3317
- childsIndexRange: i,
3335
+ childsIndexRange: a,
3318
3336
  report: y
3319
3337
  };
3320
3338
  } catch (g) {
@@ -3323,7 +3341,7 @@ async function Rr(t, r, s) {
3323
3341
  };
3324
3342
  }
3325
3343
  }
3326
- function zr(t, r) {
3344
+ function Pr(t, r) {
3327
3345
  t(
3328
3346
  "playwright-dom-snapshot-browse",
3329
3347
  {
@@ -3332,7 +3350,7 @@ function zr(t, r) {
3332
3350
  inputSchema: rt.shape
3333
3351
  },
3334
3352
  async (s, o) => {
3335
- const e = await Rr(s, r, o);
3353
+ const e = await zr(s, r, o);
3336
3354
  if (e.error != null)
3337
3355
  return `Method: playwright-dom-snapshot-browse(${JSON.stringify(s)})
3338
3356
  ❌ Error: ${e.error}`;
@@ -3344,8 +3362,8 @@ function zr(t, r) {
3344
3362
  `, n += `CSS Selector: ${e.domSnapshot.query.cssSelector}
3345
3363
  `, n += `Parent UID: ${e.parentUid ?? "null (root node)"}
3346
3364
  `, e.childsIndexRange) {
3347
- const [i, a] = e.childsIndexRange, l = (e.parentUid ? e.domSnapshot.tree.getNode(e.parentUid) : e.domSnapshot.tree.root).countChilds;
3348
- n += ` Showing indexes: ${i}-${a} of ${l}
3365
+ const [a, i] = e.childsIndexRange, l = (e.parentUid ? e.domSnapshot.tree.getNode(e.parentUid) : e.domSnapshot.tree.root).countChilds;
3366
+ n += ` Showing indexes: ${a}-${i} of ${l}
3349
3367
  `;
3350
3368
  }
3351
3369
  return n += `
@@ -3353,12 +3371,12 @@ ${e.report}`, n;
3353
3371
  }
3354
3372
  );
3355
3373
  }
3356
- function Pr(t, r) {
3357
- r.browserCreate && dr(t, r), r.browserList && mr(t, r), r.browserClose && pr(t, r), r.contextCreate && gr(t, r), r.contextList && yr(t, r), r.contextClose && xr(t, r), r.pageCreate && Ir(t, r), r.pageList && Tr(t, r), r.pageClose && Cr(t, r), r.pageGoto && Nr(t, r), r.domSnapshotQueryCreate && Dr(t, r), r.domSnapshotCreate && Fr(t, r), r.domSnapshotBrowse && zr(t, r), console.log("Playwright manager");
3374
+ function Lr(t, r) {
3375
+ r.browserCreate && fr(t, r), r.browserList && mr(t, r), r.browserClose && gr(t, r), r.contextCreate && wr(t, r), r.contextList && br(t, r), r.contextClose && Sr(t, r), r.pageCreate && Mr(t, r), r.pageList && vr(t, r), r.pageClose && kr(t, r), r.pageGoto && Dr(t, r), r.domSnapshotQueryCreate && Er(t, r), r.domSnapshotCreate && Or(t, r), r.domSnapshotBrowse && Pr(t, r), console.log("Playwright manager");
3358
3376
  }
3359
- function Lr(t) {
3377
+ function Ur(t) {
3360
3378
  const { logFilePath: r } = t;
3361
- return async function(o, e, n, i) {
3379
+ return async function(o, e, n, a) {
3362
3380
  await q({
3363
3381
  logFilePath: r,
3364
3382
  message: "ERROR",
@@ -3378,28 +3396,17 @@ function Lr(t) {
3378
3396
  });
3379
3397
  };
3380
3398
  }
3381
- function Ur() {
3399
+ function st() {
3382
3400
  return `mcp_${(/* @__PURE__ */ new Date()).toISOString().substring(0, 19).replace(/T/, "_").replace(/:/g, "-")}.log`;
3383
3401
  }
3384
3402
  function Ar(t) {
3385
- const r = G(), s = qr();
3403
+ const r = G(), s = Gr();
3386
3404
  return r.use(s), r;
3387
3405
  }
3388
3406
  function Gr(t) {
3389
- const r = new ot({
3390
- name: t.name,
3391
- version: t.version,
3392
- title: "Project Tools"
3393
- }), s = _r(r, t);
3394
- return {
3395
- mcpServer: r,
3396
- mcpRouter: s
3397
- };
3398
- }
3399
- function qr(t) {
3400
3407
  const r = G.Router();
3401
3408
  return r.use(
3402
- st.default({
3409
+ ot.default({
3403
3410
  origin: "*",
3404
3411
  credentials: !0,
3405
3412
  allowedHeaders: [
@@ -3412,26 +3419,29 @@ function qr(t) {
3412
3419
  })
3413
3420
  ), r.use(G.json()), r;
3414
3421
  }
3415
- function _r(t, r) {
3416
- const s = G.Router();
3417
- return s.use(wt({ authToken: r.authToken })), s.all("/mcp", yt(t, r)), s;
3422
+ function qr(t) {
3423
+ const r = G.Router();
3424
+ return r.use(yt({ authToken: t.authToken })), r.all(
3425
+ "/mcp",
3426
+ bt(t)
3427
+ ), r;
3418
3428
  }
3419
- function jr(t, r) {
3420
- return t.use(Lr({ logFilePath: r.logFilePath })), new Promise((s, o) => {
3429
+ function _r(t, r) {
3430
+ return t.use(Ur({ logFilePath: r.logFilePath })), new Promise((s, o) => {
3421
3431
  let e;
3422
3432
  const n = () => {
3423
3433
  s(e);
3424
3434
  };
3425
3435
  try {
3426
- e = r.host ? t.listen(r.port ?? 0, r.host, n) : t.listen(r.port ?? 0, n), e.addListener("error", (i) => {
3427
- o(i);
3436
+ e = r.host ? t.listen(r.port ?? 0, r.host, n) : t.listen(r.port ?? 0, n), e.addListener("error", (a) => {
3437
+ o(a);
3428
3438
  });
3429
- } catch (i) {
3430
- o(i);
3439
+ } catch (a) {
3440
+ o(a);
3431
3441
  }
3432
3442
  });
3433
3443
  }
3434
- function Jr(t, r) {
3444
+ function jr(t, r) {
3435
3445
  const s = t.address().family, o = t.address().port;
3436
3446
  let e = t.address().address;
3437
3447
  e === "::" ? e = "localhost" : s === "IPv6" && (e = `[${e}]`);
@@ -3445,32 +3455,43 @@ SSE Endpoint: ${n}/sse
3445
3455
 
3446
3456
  Log File: ${T.resolve(r.logFilePath)}`;
3447
3457
  }
3448
- async function cs(t) {
3449
- const r = T.join(t.logDir, Ur()), s = Ar(), { mcpServer: o, mcpRouter: e } = Gr({
3450
- ...t,
3451
- logFilePath: r
3458
+ function Jr(t, r) {
3459
+ const s = T.join(r.logDir, st()), o = Pt(t, {
3460
+ logFilePath: s
3452
3461
  });
3453
- s.use(e);
3454
- const n = zt(o, {
3455
- logFilePath: r
3462
+ r.tools.processManager && zt(o, r.tools.processManager), r.tools.fsManager && dr(o, r.tools.fsManager), r.tools.playwrightManager && Lr(o, {
3463
+ ...r.tools.playwrightManager
3456
3464
  });
3457
- t.tools.processManager && Rt(n, t.tools?.processManager), t.tools.fsManager && ur(n, t.tools.fsManager), t.tools.playwrightManager && Pr(n, {
3458
- ...t.tools.playwrightManager
3465
+ }
3466
+ async function cs(t) {
3467
+ const r = T.join(t.logDir, st()), s = Ar(), o = qr({
3468
+ ...t,
3469
+ logFilePath: r,
3470
+ createMcpServer: () => {
3471
+ const n = new nt({
3472
+ title: t.name,
3473
+ name: t.name,
3474
+ version: t.version,
3475
+ authToken: t.authToken,
3476
+ enableJsonResponse: !0
3477
+ });
3478
+ return Jr(n, t), n;
3479
+ }
3459
3480
  });
3460
- const i = await jr(s, {
3481
+ s.use(o);
3482
+ const e = await _r(s, {
3461
3483
  host: t.host,
3462
3484
  port: t.port,
3463
3485
  logFilePath: r
3464
3486
  });
3465
3487
  return console.log(
3466
- Jr(i, {
3488
+ jr(e, {
3467
3489
  name: t.name,
3468
3490
  version: t.version,
3469
3491
  authToken: t.authToken,
3470
- logFilePath: r,
3471
- enableJsonResponse: t.enableJsonResponse
3492
+ logFilePath: r
3472
3493
  })
3473
- ), i;
3494
+ ), e;
3474
3495
  }
3475
3496
  export {
3476
3497
  ls as A,