@flemist/mcp-project-tools 3.0.14 → 3.0.16
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,56 +1,55 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { McpServer as
|
|
3
|
-
import { randomUUID as
|
|
1
|
+
import ne from "express";
|
|
2
|
+
import { McpServer as Gt } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
3
|
+
import { randomUUID as Jt } from "crypto";
|
|
4
4
|
import * as W from "fs";
|
|
5
|
-
import * as
|
|
6
|
-
import
|
|
7
|
-
import {
|
|
8
|
-
import { spawn as qt } from "child_process";
|
|
5
|
+
import * as R from "path";
|
|
6
|
+
import { StreamableHTTPServerTransport as jt } from "@modelcontextprotocol/sdk/server/streamableHttp.js";
|
|
7
|
+
import { spawn as Kt } from "child_process";
|
|
9
8
|
import { z as p } from "zod";
|
|
10
|
-
import
|
|
11
|
-
import { Pool as
|
|
12
|
-
import { priorityCreate as
|
|
13
|
-
import { useAbortController as
|
|
14
|
-
import
|
|
15
|
-
import
|
|
16
|
-
import { webkit as
|
|
17
|
-
function
|
|
18
|
-
const { authToken:
|
|
9
|
+
import pe from "tree-kill";
|
|
10
|
+
import { Pool as Wt, poolRunWait as V } from "@flemist/time-limits";
|
|
11
|
+
import { priorityCreate as Z } from "@flemist/priority-queue";
|
|
12
|
+
import { useAbortController as Ht, combineAbortSignals as Qt, Locker as Yt } from "@flemist/async-utils";
|
|
13
|
+
import Vt from "node:os";
|
|
14
|
+
import Zt from "picomatch";
|
|
15
|
+
import { webkit as Xt, firefox as er, chromium as tr } from "playwright";
|
|
16
|
+
function rr(t) {
|
|
17
|
+
const { authToken: r } = t;
|
|
19
18
|
return function(o, e, n) {
|
|
20
|
-
if ((o.query.token || o.headers.authorization?.replace("Bearer ", "")) !==
|
|
19
|
+
if ((o.query.token || o.headers.authorization?.replace("Bearer ", "")) !== r) {
|
|
21
20
|
e.status(401).json({ error: "Unauthorized" });
|
|
22
21
|
return;
|
|
23
22
|
}
|
|
24
23
|
n();
|
|
25
24
|
};
|
|
26
25
|
}
|
|
27
|
-
async function
|
|
28
|
-
const { logFilePath:
|
|
26
|
+
async function ie(t) {
|
|
27
|
+
const { logFilePath: r, message: s, data: o } = t;
|
|
29
28
|
try {
|
|
30
29
|
const e = (/* @__PURE__ */ new Date()).toISOString().replace(/[TZ]/g, " ").trim(), n = typeof o == "string" ? o : JSON.stringify(o, null, 2), a = `[${e}] ${s}
|
|
31
30
|
${n}
|
|
32
31
|
|
|
33
32
|
`;
|
|
34
|
-
await W.promises.mkdir(
|
|
33
|
+
await W.promises.mkdir(R.dirname(r), { recursive: !0 }), await W.promises.appendFile(r, a);
|
|
35
34
|
} catch (e) {
|
|
36
35
|
console.error(`Failed to log "${s}":`, e);
|
|
37
36
|
}
|
|
38
37
|
}
|
|
39
|
-
const
|
|
40
|
-
function
|
|
41
|
-
return
|
|
38
|
+
const ae = /* @__PURE__ */ new Map();
|
|
39
|
+
function sr(t) {
|
|
40
|
+
return t.headers["mcp-session-id"] || t.headers["x-session-id"] || t.query.token;
|
|
42
41
|
}
|
|
43
|
-
async function
|
|
44
|
-
const s =
|
|
45
|
-
sessionIdGenerator: () =>
|
|
42
|
+
async function or(t, r) {
|
|
43
|
+
const s = t.createMcpServer(), o = new jt({
|
|
44
|
+
sessionIdGenerator: () => r || Jt(),
|
|
46
45
|
onsessioninitialized: (n) => {
|
|
47
|
-
|
|
46
|
+
ae.set(n, o);
|
|
48
47
|
},
|
|
49
48
|
enableJsonResponse: !0
|
|
50
49
|
});
|
|
51
50
|
async function e() {
|
|
52
51
|
const n = o.sessionId;
|
|
53
|
-
n &&
|
|
52
|
+
n && ae.delete(n);
|
|
54
53
|
try {
|
|
55
54
|
await s.close();
|
|
56
55
|
} catch (a) {
|
|
@@ -64,28 +63,28 @@ async function Xt(r, t) {
|
|
|
64
63
|
throw await e(), n;
|
|
65
64
|
}
|
|
66
65
|
}
|
|
67
|
-
async function
|
|
68
|
-
await
|
|
66
|
+
async function nr(t, r, s, o) {
|
|
67
|
+
await ie({
|
|
69
68
|
logFilePath: s.logFilePath,
|
|
70
69
|
message: "REQUEST",
|
|
71
|
-
data:
|
|
70
|
+
data: t.body
|
|
72
71
|
});
|
|
73
|
-
let e = o ?
|
|
74
|
-
e || (e = await
|
|
72
|
+
let e = o ? ae.get(o) : null;
|
|
73
|
+
e || (e = await or(s, o)), await e.handleRequest(t, r, t.body);
|
|
75
74
|
}
|
|
76
|
-
async function
|
|
77
|
-
const o = s ?
|
|
75
|
+
async function ir(t, r, s) {
|
|
76
|
+
const o = s ? ae.get(s) : null;
|
|
78
77
|
if (!o) {
|
|
79
|
-
|
|
78
|
+
r.status(400).json({ error: "No valid session found" });
|
|
80
79
|
return;
|
|
81
80
|
}
|
|
82
|
-
await o.handleRequest(
|
|
81
|
+
await o.handleRequest(t, r);
|
|
83
82
|
}
|
|
84
|
-
function
|
|
83
|
+
function ar(t) {
|
|
85
84
|
return async function(s, o) {
|
|
86
85
|
try {
|
|
87
|
-
const e =
|
|
88
|
-
s.method === "POST" ? await
|
|
86
|
+
const e = sr(s);
|
|
87
|
+
s.method === "POST" ? await nr(s, o, t, e) : s.method === "GET" ? await ir(s, o, e) : o.status(405).json({ error: "Method not allowed" });
|
|
89
88
|
} catch (e) {
|
|
90
89
|
console.error("Unhandled error in streamableHttpHandler", e), o.status(500).json({
|
|
91
90
|
error: "Internal server error: " + (e instanceof Error ? e.message : "Unknown error")
|
|
@@ -93,14 +92,14 @@ function rr(r) {
|
|
|
93
92
|
}
|
|
94
93
|
};
|
|
95
94
|
}
|
|
96
|
-
const
|
|
97
|
-
let
|
|
98
|
-
const
|
|
99
|
-
function
|
|
100
|
-
const { commandLine:
|
|
95
|
+
const Y = /* @__PURE__ */ new Map();
|
|
96
|
+
let lr = 0;
|
|
97
|
+
const Ce = 10, cr = 1800 * 1e3, J = 1e4, Q = 2e3, ur = 5e3;
|
|
98
|
+
function dr(t) {
|
|
99
|
+
const { commandLine: r, commandLineRules: s } = t;
|
|
101
100
|
let o = !1;
|
|
102
101
|
for (const e of s)
|
|
103
|
-
if (new RegExp(e.regexp).test(
|
|
102
|
+
if (new RegExp(e.regexp).test(r))
|
|
104
103
|
switch (e.rule) {
|
|
105
104
|
case "allow":
|
|
106
105
|
o = !0;
|
|
@@ -113,135 +112,234 @@ function ar(r) {
|
|
|
113
112
|
}
|
|
114
113
|
return o;
|
|
115
114
|
}
|
|
116
|
-
function
|
|
117
|
-
return ++
|
|
115
|
+
function fr() {
|
|
116
|
+
return ++lr;
|
|
118
117
|
}
|
|
119
|
-
let
|
|
120
|
-
function
|
|
121
|
-
if (
|
|
118
|
+
let Ne = !1;
|
|
119
|
+
function hr() {
|
|
120
|
+
if (Ne)
|
|
122
121
|
return;
|
|
123
|
-
|
|
124
|
-
const
|
|
122
|
+
Ne = !0;
|
|
123
|
+
const t = () => {
|
|
125
124
|
console.log("Auto-killing all child processes...");
|
|
126
|
-
for (const [
|
|
125
|
+
for (const [r, s] of Array.from(Y.entries()))
|
|
127
126
|
if (s.isRunning && s.pid)
|
|
128
127
|
try {
|
|
129
|
-
|
|
128
|
+
pe(s.pid, "SIGKILL");
|
|
130
129
|
} catch (o) {
|
|
131
|
-
console.error(`Error killing process ${
|
|
130
|
+
console.error(`Error killing process ${r}:`, o);
|
|
132
131
|
}
|
|
133
132
|
process.exit(0);
|
|
134
133
|
};
|
|
135
|
-
process.on("SIGINT",
|
|
136
|
-
}
|
|
137
|
-
function
|
|
138
|
-
const
|
|
139
|
-
for (const [s, o] of Array.from(
|
|
140
|
-
!o.isRunning && o.endTime &&
|
|
141
|
-
for (const s of
|
|
142
|
-
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
134
|
+
process.on("SIGINT", t), process.on("SIGTERM", t);
|
|
135
|
+
}
|
|
136
|
+
function ge() {
|
|
137
|
+
const t = Date.now(), r = [];
|
|
138
|
+
for (const [s, o] of Array.from(Y.entries()))
|
|
139
|
+
!o.isRunning && o.endTime && t - o.endTime.getTime() > cr && r.push(s);
|
|
140
|
+
for (const s of r)
|
|
141
|
+
Y.delete(s);
|
|
142
|
+
}
|
|
143
|
+
const pr = 1800 * 1e3, ve = /* @__PURE__ */ new Map();
|
|
144
|
+
let mr = 0;
|
|
145
|
+
function gr() {
|
|
146
|
+
return ++mr;
|
|
147
|
+
}
|
|
148
|
+
function Xe(t) {
|
|
149
|
+
let r = ve.get(t);
|
|
150
|
+
return r == null && (r = {
|
|
151
|
+
storedOutputs: /* @__PURE__ */ new Map()
|
|
152
|
+
}, ve.set(t, r)), r;
|
|
153
|
+
}
|
|
154
|
+
function et(t) {
|
|
155
|
+
return typeof t == "function" ? t() : t;
|
|
156
|
+
}
|
|
157
|
+
function tt(t, r) {
|
|
158
|
+
return setTimeout(() => {
|
|
159
|
+
t.storedOutputs.delete(r);
|
|
160
|
+
}, pr);
|
|
161
|
+
}
|
|
162
|
+
function wr(t, r, s) {
|
|
163
|
+
clearTimeout(s.cleanupTimer), s.cleanupTimer = tt(t, r);
|
|
164
|
+
}
|
|
165
|
+
function yr(t) {
|
|
166
|
+
const { sessionId: r, source: s } = t, o = Xe(r), e = gr(), n = {
|
|
167
|
+
source: s,
|
|
168
|
+
cleanupTimer: tt(o, e)
|
|
169
|
+
};
|
|
170
|
+
return o.storedOutputs.set(e, n), e;
|
|
171
|
+
}
|
|
172
|
+
function rt(t) {
|
|
173
|
+
const { sessionId: r, outputId: s, range: o } = t, [e, n] = o, a = Xe(r), i = a.storedOutputs.get(s);
|
|
174
|
+
if (i == null)
|
|
175
|
+
return {
|
|
176
|
+
content: "",
|
|
177
|
+
total: 0,
|
|
178
|
+
range: [0, 0],
|
|
179
|
+
error: `Stored output with outputId=${s} not found or expired`
|
|
180
|
+
};
|
|
181
|
+
wr(a, s, i);
|
|
182
|
+
const c = et(i.source), l = c.length, u = Math.min(Math.max(e, 0), l), f = Math.min(Math.max(n, 0), l);
|
|
183
|
+
return { content: c.substring(u, f), total: l, range: [u, f] };
|
|
184
|
+
}
|
|
185
|
+
function we(t) {
|
|
186
|
+
const { sessionId: r, source: s, limit: o } = t, e = et(s);
|
|
187
|
+
if (e.length <= o)
|
|
188
|
+
return { content: e, outputId: null };
|
|
189
|
+
const n = yr({ sessionId: r, source: s }), a = rt({
|
|
190
|
+
sessionId: r,
|
|
191
|
+
outputId: n,
|
|
192
|
+
range: [0, o]
|
|
193
|
+
}), i = `
|
|
194
|
+
... [truncated] showing [0, ${a.content.length}) of ${a.total} chars. To view any range, use output-read with outputId=${n} range=[from, to]`;
|
|
195
|
+
return {
|
|
196
|
+
content: a.content + i,
|
|
197
|
+
outputId: n
|
|
198
|
+
};
|
|
158
199
|
}
|
|
159
|
-
function
|
|
160
|
-
|
|
161
|
-
if (r.length <= s) return r;
|
|
162
|
-
const e = `
|
|
163
|
-
... [${r.length - s} characters trimmed] ...
|
|
164
|
-
`, n = s - e.length;
|
|
165
|
-
if (n <= 0)
|
|
166
|
-
return r.substring(0, s);
|
|
167
|
-
const a = Math.floor(n / 2);
|
|
168
|
-
return r.substring(0, a) + e + r.substring(r.length - (n - a));
|
|
169
|
-
}
|
|
170
|
-
function B(r) {
|
|
171
|
-
return `Invalid arguments: ${r instanceof Error ? r.message : "Unknown error"}.
|
|
200
|
+
function F(t) {
|
|
201
|
+
return `Invalid arguments: ${t instanceof Error ? t.message : "Unknown error"}.
|
|
172
202
|
|
|
173
203
|
Provide valid parameters according to schema.`;
|
|
174
204
|
}
|
|
175
|
-
const
|
|
205
|
+
const st = p.object({
|
|
206
|
+
outputId: p.number().int().describe("Output ID from truncation message"),
|
|
207
|
+
range: p.tuple([p.number().int().min(0), p.number().int().min(0)]).describe(
|
|
208
|
+
`Character range [from, to) to retrieve. Maximum range size: ${J}.`
|
|
209
|
+
)
|
|
210
|
+
});
|
|
211
|
+
function br(t, r) {
|
|
212
|
+
let s;
|
|
213
|
+
try {
|
|
214
|
+
s = st.parse(t);
|
|
215
|
+
} catch (a) {
|
|
216
|
+
return {
|
|
217
|
+
error: F(a)
|
|
218
|
+
};
|
|
219
|
+
}
|
|
220
|
+
if (!r.sessionId)
|
|
221
|
+
return {
|
|
222
|
+
error: "Session ID is required"
|
|
223
|
+
};
|
|
224
|
+
const [o, e] = s.range;
|
|
225
|
+
if (e <= o)
|
|
226
|
+
return {
|
|
227
|
+
error: `Invalid range: to (${e}) must be greater than from (${o})`
|
|
228
|
+
};
|
|
229
|
+
if (e - o > J)
|
|
230
|
+
return {
|
|
231
|
+
error: `Range size ${e - o} exceeds maximum ${J}`
|
|
232
|
+
};
|
|
233
|
+
const n = rt({
|
|
234
|
+
sessionId: r.sessionId,
|
|
235
|
+
outputId: s.outputId,
|
|
236
|
+
range: s.range
|
|
237
|
+
});
|
|
238
|
+
return n.error != null ? { error: n.error } : { content: n.content, total: n.total, range: n.range };
|
|
239
|
+
}
|
|
240
|
+
function Sr(t) {
|
|
241
|
+
t(
|
|
242
|
+
"output-read",
|
|
243
|
+
{
|
|
244
|
+
title: "Read Stored Output Range",
|
|
245
|
+
description: "Read any range from stored output. Use outputId from truncation message and specify character range [from, to).",
|
|
246
|
+
inputSchema: st.shape
|
|
247
|
+
},
|
|
248
|
+
async (r, s) => {
|
|
249
|
+
const o = br(r, s);
|
|
250
|
+
if (o.error != null)
|
|
251
|
+
return `Method: output-read(${JSON.stringify(r)})
|
|
252
|
+
❌ Error: ${o.error}`;
|
|
253
|
+
const [e, n] = o.range, a = o.total;
|
|
254
|
+
let i = `Method: output-read(${JSON.stringify(r)})
|
|
255
|
+
showing [${e}, ${n}) of ${a} chars`;
|
|
256
|
+
return e >= a && (i += `
|
|
257
|
+
⚠️ Warning: requested range is beyond content (total: ${a} chars)`), i += `
|
|
258
|
+
|
|
259
|
+
${o.content}`, i;
|
|
260
|
+
}
|
|
261
|
+
);
|
|
262
|
+
}
|
|
263
|
+
function xr(t) {
|
|
264
|
+
Sr(t);
|
|
265
|
+
}
|
|
266
|
+
const ot = p.object({
|
|
176
267
|
id: p.number().describe(
|
|
177
268
|
"Process ID to get detailed status information for. Get process IDs using process-list. Works for both running and completed processes. Examples: 1, 42, 123"
|
|
178
269
|
),
|
|
179
|
-
outputLimit: p.number().max(
|
|
180
|
-
`Maximum
|
|
270
|
+
outputLimit: p.number().int().min(0).max(J).default(Q).describe(
|
|
271
|
+
`Maximum output characters to return. Truncated output can be retrieved via output-read tool using outputId from truncation message. Maximum: ${J}. Default: ${Q}`
|
|
181
272
|
)
|
|
182
273
|
});
|
|
183
|
-
async function
|
|
184
|
-
|
|
185
|
-
let
|
|
274
|
+
async function ye(t, r, s) {
|
|
275
|
+
ge();
|
|
276
|
+
let o;
|
|
186
277
|
try {
|
|
187
|
-
|
|
278
|
+
o = ot.parse(t);
|
|
188
279
|
} catch (c) {
|
|
189
280
|
return {
|
|
190
|
-
error:
|
|
281
|
+
error: F(c)
|
|
191
282
|
};
|
|
192
283
|
}
|
|
193
|
-
const { id:
|
|
194
|
-
if (!
|
|
284
|
+
const { id: e, outputLimit: n } = o, a = Y.get(e);
|
|
285
|
+
if (!a)
|
|
195
286
|
return {
|
|
196
|
-
error: `Process ${
|
|
287
|
+
error: `Process ${e} 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.`
|
|
197
288
|
};
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
289
|
+
if (!s.sessionId)
|
|
290
|
+
return {
|
|
291
|
+
error: "Session ID is required"
|
|
292
|
+
};
|
|
293
|
+
const i = we({
|
|
294
|
+
sessionId: s.sessionId,
|
|
295
|
+
source: () => a.output,
|
|
296
|
+
limit: n
|
|
297
|
+
}).content;
|
|
298
|
+
return {
|
|
299
|
+
id: a.id,
|
|
300
|
+
cwd: R.relative(r.workingDir || "", a.cwd),
|
|
301
|
+
commandLine: a.commandLine,
|
|
302
|
+
pid: a.pid,
|
|
303
|
+
startTime: a.startTime.toISOString().replace(/[TZ]/g, " ").trim(),
|
|
304
|
+
endTime: a.endTime?.toISOString().replace(/[TZ]/g, " ").trim(),
|
|
305
|
+
exitCode: a.exitCode,
|
|
306
|
+
isRunning: a.isRunning,
|
|
209
307
|
output: i,
|
|
210
|
-
error:
|
|
308
|
+
error: a.error
|
|
211
309
|
};
|
|
212
310
|
}
|
|
213
|
-
function
|
|
214
|
-
|
|
311
|
+
function $r(t, r) {
|
|
312
|
+
t(
|
|
215
313
|
"process-status",
|
|
216
314
|
{
|
|
217
315
|
title: "Get Host Machine Process Status",
|
|
218
|
-
description: "Get detailed status information about a process on the host machine. Use this to check if commands completed successfully, get their output, or monitor running processes
|
|
219
|
-
inputSchema:
|
|
316
|
+
description: "Get detailed status information about a process on the host machine. Use this to check if commands completed successfully, get their output, or monitor running processes",
|
|
317
|
+
inputSchema: ot.shape
|
|
220
318
|
},
|
|
221
|
-
async (s) => {
|
|
222
|
-
const
|
|
223
|
-
if (!("output" in
|
|
319
|
+
async (s, o) => {
|
|
320
|
+
const e = await ye(s, r, o);
|
|
321
|
+
if (!("output" in e))
|
|
224
322
|
return `Method: process-status(${JSON.stringify(s)})
|
|
225
|
-
❌ Error: ${
|
|
226
|
-
const
|
|
227
|
-
return delete
|
|
228
|
-
${JSON.stringify(
|
|
323
|
+
❌ Error: ${e.error}`;
|
|
324
|
+
const n = e.output || "";
|
|
325
|
+
return delete e.output, `Method: process-status(${JSON.stringify(s)})
|
|
326
|
+
${JSON.stringify(e, null, 2)}
|
|
229
327
|
|
|
230
328
|
Output:
|
|
231
|
-
${
|
|
329
|
+
${n.trim()}`;
|
|
232
330
|
}
|
|
233
331
|
);
|
|
234
332
|
}
|
|
235
|
-
function
|
|
236
|
-
|
|
237
|
-
|
|
333
|
+
function nt(t) {
|
|
334
|
+
pe(t, "SIGTERM", (r) => {
|
|
335
|
+
r && !r.message.includes("not found") && console.error(`Error sending SIGTERM to process ${t}:`, r);
|
|
238
336
|
}), setTimeout(() => {
|
|
239
|
-
|
|
240
|
-
|
|
337
|
+
pe(t, "SIGKILL", (r) => {
|
|
338
|
+
r && !r.message.includes("not found") && console.error(`Error sending SIGKILL to process ${t}:`, r);
|
|
241
339
|
});
|
|
242
|
-
},
|
|
340
|
+
}, ur);
|
|
243
341
|
}
|
|
244
|
-
const
|
|
342
|
+
const it = p.object({
|
|
245
343
|
id: p.number().describe(
|
|
246
344
|
"Process ID to wait for completion. Get process IDs using process-list. The process can be running or already completed. Examples: 1, 42, 123"
|
|
247
345
|
),
|
|
@@ -251,62 +349,62 @@ const et = p.object({
|
|
|
251
349
|
autoKill: p.boolean().default(!1).describe(
|
|
252
350
|
"Automatically terminate the process if waitTime expires and it is still running. Only applies when waitTime is specified. Default: false (let process continue running after timeout). Set to true for processes that should not run indefinitely"
|
|
253
351
|
),
|
|
254
|
-
outputLimit: p.number().max(
|
|
255
|
-
`Maximum
|
|
352
|
+
outputLimit: p.number().int().min(0).max(J).default(Q).describe(
|
|
353
|
+
`Maximum output characters to return. Truncated output can be retrieved via output-read tool using outputId from truncation message. Maximum: ${J}. Default: ${Q}`
|
|
256
354
|
)
|
|
257
355
|
});
|
|
258
|
-
async function
|
|
259
|
-
let
|
|
356
|
+
async function at(t, r, s) {
|
|
357
|
+
let o;
|
|
260
358
|
try {
|
|
261
|
-
|
|
262
|
-
} catch (
|
|
359
|
+
o = it.parse(t);
|
|
360
|
+
} catch (g) {
|
|
263
361
|
return {
|
|
264
|
-
error:
|
|
362
|
+
error: F(g)
|
|
265
363
|
};
|
|
266
364
|
}
|
|
267
|
-
const { id:
|
|
268
|
-
if (!
|
|
365
|
+
const { id: e, waitTime: n, autoKill: a, outputLimit: i } = o, c = Y.get(e);
|
|
366
|
+
if (!c)
|
|
269
367
|
return {
|
|
270
|
-
error: `Process ${
|
|
368
|
+
error: `Process ${e} 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.`
|
|
271
369
|
};
|
|
272
|
-
const
|
|
273
|
-
let
|
|
274
|
-
|
|
275
|
-
const
|
|
276
|
-
|
|
370
|
+
const l = Date.now();
|
|
371
|
+
let u = !1, f = !1;
|
|
372
|
+
n != null && await new Promise((m) => {
|
|
373
|
+
const y = setInterval(() => {
|
|
374
|
+
c.isRunning ? Date.now() - l >= n * 1e3 && (clearInterval(y), u = !0, a && c.pid && (nt(c.pid), f = !0), m()) : (clearInterval(y), m());
|
|
277
375
|
}, 100);
|
|
278
376
|
});
|
|
279
|
-
const d = (Date.now() -
|
|
377
|
+
const d = (Date.now() - l) / 1e3;
|
|
280
378
|
return {
|
|
281
|
-
...await
|
|
379
|
+
...await ye({ id: e, outputLimit: i }, r, s),
|
|
282
380
|
waitDuration: d,
|
|
283
|
-
waitTimeExceeded:
|
|
284
|
-
autoKillExecuted:
|
|
381
|
+
waitTimeExceeded: u,
|
|
382
|
+
autoKillExecuted: f
|
|
285
383
|
};
|
|
286
384
|
}
|
|
287
|
-
function
|
|
288
|
-
|
|
385
|
+
function Ir(t, r) {
|
|
386
|
+
t(
|
|
289
387
|
"process-wait",
|
|
290
388
|
{
|
|
291
389
|
title: "Wait for Host Machine Process",
|
|
292
390
|
description: "Wait for a host machine process to complete execution, with optional timeout and auto-kill functionality. Use this for long-running commands like builds, installs, or tests when you need final results",
|
|
293
|
-
inputSchema:
|
|
391
|
+
inputSchema: it.shape
|
|
294
392
|
},
|
|
295
|
-
async (s) => {
|
|
296
|
-
const
|
|
297
|
-
if (!("output" in
|
|
393
|
+
async (s, o) => {
|
|
394
|
+
const e = await at(s, r, o);
|
|
395
|
+
if (!("output" in e))
|
|
298
396
|
return `Method: process-wait(${JSON.stringify(s)})
|
|
299
|
-
❌ Error: ${
|
|
300
|
-
const
|
|
301
|
-
return delete
|
|
302
|
-
${JSON.stringify(
|
|
397
|
+
❌ Error: ${e.error}`;
|
|
398
|
+
const n = e.output || "";
|
|
399
|
+
return delete e.output, `Method: process-wait(${JSON.stringify(s)})
|
|
400
|
+
${JSON.stringify(e, null, 2)}
|
|
303
401
|
|
|
304
402
|
Output:
|
|
305
|
-
${
|
|
403
|
+
${n.trim()}`;
|
|
306
404
|
}
|
|
307
405
|
);
|
|
308
406
|
}
|
|
309
|
-
const
|
|
407
|
+
const lt = p.object({
|
|
310
408
|
cwd: p.string().optional().describe(
|
|
311
409
|
'Working directory for command execution, resolved relative to the current working directory. Leave empty to use current directory. Examples: "src" (run in src/ subdirectory), "../parent" (run in parent directory), "build/output" (run in nested subdirectory). Directory must exist'
|
|
312
410
|
),
|
|
@@ -319,108 +417,98 @@ const rt = p.object({
|
|
|
319
417
|
autoKill: p.boolean().default(!1).describe(
|
|
320
418
|
"Automatically kill the process if waitTime expires and it is still running. Only applies when waitTime is specified. Default: false (let process continue running). Set to true for commands that should not run indefinitely"
|
|
321
419
|
),
|
|
322
|
-
outputLimit: p.number().max(
|
|
323
|
-
`Maximum
|
|
420
|
+
outputLimit: p.number().int().min(0).max(J).default(Q).describe(
|
|
421
|
+
`Maximum output characters to return. Truncated output can be retrieved via output-read tool using outputId from truncation message. Maximum: ${J}. Default: ${Q}`
|
|
324
422
|
)
|
|
325
423
|
});
|
|
326
|
-
async function
|
|
327
|
-
|
|
328
|
-
let
|
|
424
|
+
async function Mr(t, r, s) {
|
|
425
|
+
ge();
|
|
426
|
+
let o;
|
|
329
427
|
try {
|
|
330
|
-
|
|
331
|
-
} catch (
|
|
428
|
+
o = lt.parse(t);
|
|
429
|
+
} catch (h) {
|
|
332
430
|
return {
|
|
333
|
-
error:
|
|
431
|
+
error: F(h)
|
|
334
432
|
};
|
|
335
433
|
}
|
|
336
|
-
const { commandLine:
|
|
337
|
-
if (!
|
|
338
|
-
const
|
|
339
|
-
(
|
|
434
|
+
const { commandLine: e, waitTime: n, autoKill: a, outputLimit: i } = o, { commandLineRules: c } = r, l = R.resolve(r.workingDir || "", o.cwd || "");
|
|
435
|
+
if (!dr({ commandLine: e, commandLineRules: c })) {
|
|
436
|
+
const h = c.map(
|
|
437
|
+
(g) => `${g.rule.toUpperCase()}: /${g.regexp}/ (${g.note})`
|
|
340
438
|
).join(`
|
|
341
439
|
`);
|
|
342
440
|
return {
|
|
343
|
-
error: `Command line not allowed: "${
|
|
344
|
-
${
|
|
441
|
+
error: `Command line not allowed: "${e}". For security, command lines are validated against configured rules in order. Command line was denied by the rule evaluation. Current command line rules:
|
|
442
|
+
${h}
|
|
345
443
|
|
|
346
444
|
To use this command line, ask the user to modify the command line rules in the configuration.`
|
|
347
445
|
};
|
|
348
446
|
}
|
|
349
|
-
if (Array.from(
|
|
350
|
-
(
|
|
351
|
-
).length >=
|
|
447
|
+
if (Array.from(Y.values()).filter(
|
|
448
|
+
(h) => h.isRunning
|
|
449
|
+
).length >= Ce)
|
|
352
450
|
return {
|
|
353
|
-
error: `Maximum concurrent process limit reached (${
|
|
451
|
+
error: `Maximum concurrent process limit reached (${Ce} processes). Cannot start new process until existing processes complete. Use process-list to see active processes, or process-kill to terminate unnecessary processes.`
|
|
354
452
|
};
|
|
355
|
-
const
|
|
356
|
-
id:
|
|
357
|
-
cwd:
|
|
358
|
-
commandLine:
|
|
453
|
+
const f = fr(), d = {
|
|
454
|
+
id: f,
|
|
455
|
+
cwd: l,
|
|
456
|
+
commandLine: e,
|
|
359
457
|
startTime: /* @__PURE__ */ new Date(),
|
|
360
458
|
isRunning: !0,
|
|
361
|
-
output: ""
|
|
362
|
-
localOutput: "",
|
|
363
|
-
lastOutputTime: /* @__PURE__ */ new Date()
|
|
459
|
+
output: ""
|
|
364
460
|
};
|
|
365
|
-
|
|
461
|
+
Y.set(f, d);
|
|
366
462
|
try {
|
|
367
|
-
const
|
|
463
|
+
const h = Kt(e, [], {
|
|
368
464
|
shell: !0,
|
|
369
|
-
cwd:
|
|
465
|
+
cwd: l,
|
|
370
466
|
stdio: ["pipe", "pipe", "pipe"]
|
|
371
467
|
});
|
|
372
|
-
d.pid =
|
|
373
|
-
const
|
|
374
|
-
const
|
|
375
|
-
d.
|
|
468
|
+
d.pid = h.pid;
|
|
469
|
+
const g = (m) => {
|
|
470
|
+
const y = m.toString();
|
|
471
|
+
d.output += y, console.log(y);
|
|
376
472
|
};
|
|
377
|
-
return
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
d.output = d.output.substring(0, R);
|
|
389
|
-
}
|
|
390
|
-
console.log(`Process ${u} (${o}) exited with code ${m}`);
|
|
391
|
-
}), f.on("error", (m) => {
|
|
392
|
-
d.isRunning = !1, d.endTime = /* @__PURE__ */ new Date(), d.error = m.message, console.error(`Process ${u} error:`, m.message);
|
|
393
|
-
}), e != null ? tt({ id: u, waitTime: e, autoKill: n, outputLimit: a }, t) : we({ id: u, outputLimit: a }, t);
|
|
394
|
-
} catch (f) {
|
|
395
|
-
return d.isRunning = !1, d.endTime = /* @__PURE__ */ new Date(), d.error = f instanceof Error ? f.message : "Unknown error", { error: d.error };
|
|
473
|
+
return h.stdout?.on("data", g), h.stderr?.on("data", g), h.on("close", (m) => {
|
|
474
|
+
d.isRunning = !1, d.endTime = /* @__PURE__ */ new Date(), d.exitCode = m !== null ? m : void 0, console.log(`Process ${f} (${e}) exited with code ${m}`);
|
|
475
|
+
}), h.on("error", (m) => {
|
|
476
|
+
d.isRunning = !1, d.endTime = /* @__PURE__ */ new Date(), d.error = m.message, console.error(`Process ${f} error:`, m.message);
|
|
477
|
+
}), n != null ? at(
|
|
478
|
+
{ id: f, waitTime: n, autoKill: a, outputLimit: i },
|
|
479
|
+
r,
|
|
480
|
+
s
|
|
481
|
+
) : ye({ id: f, outputLimit: i }, r, s);
|
|
482
|
+
} catch (h) {
|
|
483
|
+
return d.isRunning = !1, d.endTime = /* @__PURE__ */ new Date(), d.error = h instanceof Error ? h.message : "Unknown error", { error: d.error };
|
|
396
484
|
}
|
|
397
485
|
}
|
|
398
|
-
function
|
|
399
|
-
const s =
|
|
486
|
+
function Tr(t, r) {
|
|
487
|
+
const s = r.commandLineRules.map((o) => `${o.rule.toUpperCase()}: ${o.regexp} (${o.note})`).join(`
|
|
400
488
|
`);
|
|
401
|
-
|
|
489
|
+
t(
|
|
402
490
|
"process-run",
|
|
403
491
|
{
|
|
404
492
|
title: "Execute Command Line on Host Machine",
|
|
405
493
|
description: `Execute command lines on the host machine. Use this to build, test, lint, install packages, or run system commands. Prefer process-run with waitTime parameter if you need to immediately execute and wait for completion, instead of separate process-run and process-wait calls. Security: Command lines are validated against configured rules processed in order (later rules override earlier ones). Current command line rules:
|
|
406
494
|
${s}`,
|
|
407
|
-
inputSchema:
|
|
495
|
+
inputSchema: lt.shape
|
|
408
496
|
},
|
|
409
|
-
async (o) => {
|
|
410
|
-
const
|
|
411
|
-
if (!("output" in
|
|
497
|
+
async (o, e) => {
|
|
498
|
+
const n = await Mr(o, r, e);
|
|
499
|
+
if (!("output" in n))
|
|
412
500
|
return `Method: process-run(${JSON.stringify(o)})
|
|
413
|
-
❌ Error: ${
|
|
414
|
-
const
|
|
415
|
-
return delete
|
|
416
|
-
${JSON.stringify(
|
|
501
|
+
❌ Error: ${n.error}`;
|
|
502
|
+
const a = n.output || "";
|
|
503
|
+
return delete n.output, `Method: process-run(${JSON.stringify(o)})
|
|
504
|
+
${JSON.stringify(n, null, 2)}
|
|
417
505
|
|
|
418
506
|
Output:
|
|
419
|
-
${
|
|
507
|
+
${a.trim()}`;
|
|
420
508
|
}
|
|
421
509
|
);
|
|
422
510
|
}
|
|
423
|
-
const
|
|
511
|
+
const ct = p.object({
|
|
424
512
|
minOpenDateTime: p.string().optional().describe(
|
|
425
513
|
'Filter to processes started after this datetime. Accepts ISO format or space-separated format. Examples: "2024-01-15T10:30:00Z", "2024-01-15 10:30:00". Underscores and spaces are converted to standard ISO format internally'
|
|
426
514
|
),
|
|
@@ -431,21 +519,21 @@ const st = p.object({
|
|
|
431
519
|
"Show only currently running processes. Set to true to exclude completed processes, false to show all processes (running and completed). Default: false (show all)"
|
|
432
520
|
),
|
|
433
521
|
fields: p.array(p.string()).optional().describe(
|
|
434
|
-
'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'
|
|
522
|
+
'Specific process data fields to include in the response. If omitted, returns all available fields. Fields id, isRunning, and commandLine are always included. 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'
|
|
435
523
|
)
|
|
436
524
|
});
|
|
437
|
-
async function
|
|
438
|
-
|
|
525
|
+
async function Cr(t, r) {
|
|
526
|
+
ge();
|
|
439
527
|
let s;
|
|
440
528
|
try {
|
|
441
|
-
s =
|
|
529
|
+
s = ct.parse(t);
|
|
442
530
|
} catch (l) {
|
|
443
531
|
return {
|
|
444
|
-
error:
|
|
532
|
+
error: F(l)
|
|
445
533
|
};
|
|
446
534
|
}
|
|
447
535
|
const { minOpenDateTime: o, minCloseDateTime: e, activeOnly: n, fields: a } = s;
|
|
448
|
-
let i = Array.from(
|
|
536
|
+
let i = Array.from(Y.values());
|
|
449
537
|
if (o) {
|
|
450
538
|
const l = new Date(o.replace(/[_\s]/g, "T"));
|
|
451
539
|
i = i.filter((u) => u.startTime >= l);
|
|
@@ -455,38 +543,38 @@ async function mr(r, t) {
|
|
|
455
543
|
i = i.filter((u) => u.endTime && u.endTime >= l);
|
|
456
544
|
}
|
|
457
545
|
return n && (i = i.filter((l) => l.isRunning)), { processes: i.map((l) => {
|
|
458
|
-
ge({ process: l });
|
|
459
546
|
let u = {
|
|
460
547
|
id: l.id,
|
|
461
|
-
cwd:
|
|
548
|
+
cwd: R.relative(r.workingDir || "", l.cwd),
|
|
462
549
|
commandLine: l.commandLine,
|
|
463
550
|
pid: l.pid,
|
|
464
551
|
startTime: l.startTime.toISOString().replace(/[TZ]/g, " ").trim(),
|
|
465
552
|
endTime: l.endTime?.toISOString().replace(/[TZ]/g, " ").trim(),
|
|
466
553
|
exitCode: l.exitCode,
|
|
467
554
|
isRunning: l.isRunning,
|
|
468
|
-
output: l.output
|
|
555
|
+
output: l.output,
|
|
469
556
|
error: l.error
|
|
470
557
|
};
|
|
471
558
|
if (a) {
|
|
472
|
-
const
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
559
|
+
const f = {};
|
|
560
|
+
f.id = u.id, f.isRunning = u.isRunning, f.commandLine = u.commandLine;
|
|
561
|
+
for (const d of a)
|
|
562
|
+
d in u && (f[d] = u[d]);
|
|
563
|
+
u = f;
|
|
476
564
|
}
|
|
477
565
|
return u;
|
|
478
566
|
}) };
|
|
479
567
|
}
|
|
480
|
-
function
|
|
481
|
-
|
|
568
|
+
function Nr(t, r) {
|
|
569
|
+
t(
|
|
482
570
|
"process-list",
|
|
483
571
|
{
|
|
484
572
|
title: "List Host Machine Processes",
|
|
485
573
|
description: "List all processes that have been executed on the host machine. Use this to see running processes, check command history, or find process IDs for status/wait operations",
|
|
486
|
-
inputSchema:
|
|
574
|
+
inputSchema: ct.shape
|
|
487
575
|
},
|
|
488
576
|
async (s) => {
|
|
489
|
-
const o = await
|
|
577
|
+
const o = await Cr(s, r);
|
|
490
578
|
if (o.error != null)
|
|
491
579
|
return `Method: process-list(${JSON.stringify(s)})
|
|
492
580
|
❌ Error: ${o.error}`;
|
|
@@ -500,21 +588,21 @@ ${e}`;
|
|
|
500
588
|
}
|
|
501
589
|
);
|
|
502
590
|
}
|
|
503
|
-
const
|
|
591
|
+
const ut = p.object({
|
|
504
592
|
id: p.number().describe(
|
|
505
593
|
"Process ID of the process to terminate. Get process IDs using process-list. The process must be currently running. Examples: 1, 42, 123"
|
|
506
594
|
)
|
|
507
595
|
});
|
|
508
|
-
function
|
|
509
|
-
let
|
|
596
|
+
function vr(t) {
|
|
597
|
+
let r;
|
|
510
598
|
try {
|
|
511
|
-
|
|
599
|
+
r = ut.parse(t);
|
|
512
600
|
} catch (e) {
|
|
513
601
|
return {
|
|
514
|
-
error:
|
|
602
|
+
error: F(e)
|
|
515
603
|
};
|
|
516
604
|
}
|
|
517
|
-
const { id: s } =
|
|
605
|
+
const { id: s } = r, o = Y.get(s);
|
|
518
606
|
if (!o)
|
|
519
607
|
return {
|
|
520
608
|
error: `Process ${s} not found. The process may have already completed, been cleaned up after 30 minutes, or the ID may be incorrect. Use process-list to see available processes and their current status.`
|
|
@@ -528,54 +616,54 @@ function wr(r) {
|
|
|
528
616
|
error: `Process ${s} has no system process ID (PID). This indicates the process failed to start properly or the system was unable to assign a PID. Check process-status for error details.`
|
|
529
617
|
};
|
|
530
618
|
try {
|
|
531
|
-
return
|
|
619
|
+
return nt(o.pid), { success: !0, message: `Kill signal sent to process ${s}` };
|
|
532
620
|
} catch (e) {
|
|
533
621
|
return {
|
|
534
622
|
error: `Failed to terminate process ${s}: ${e instanceof Error ? e.message : "Unknown error"}. The process may have already exited, be protected by the system, or there may be insufficient permissions. Use process-status to check current process state.`
|
|
535
623
|
};
|
|
536
624
|
}
|
|
537
625
|
}
|
|
538
|
-
function
|
|
539
|
-
|
|
626
|
+
function Er(t, r) {
|
|
627
|
+
t(
|
|
540
628
|
"process-kill",
|
|
541
629
|
{
|
|
542
630
|
title: "Kill Host Machine Process",
|
|
543
631
|
description: "Forcibly terminate a running process on the host machine. Use this to stop runaway processes, hung commands, or long-running tasks that need to be cancelled",
|
|
544
|
-
inputSchema:
|
|
632
|
+
inputSchema: ut.shape
|
|
545
633
|
},
|
|
546
634
|
async (s) => {
|
|
547
|
-
const o =
|
|
635
|
+
const o = vr(s);
|
|
548
636
|
return o.error != null ? `Method: process-kill(${JSON.stringify(s)})
|
|
549
637
|
❌ Error: ${o.error}` : `Method: process-kill(${JSON.stringify(s)})
|
|
550
638
|
${JSON.stringify(o, null, 2)}`;
|
|
551
639
|
}
|
|
552
640
|
);
|
|
553
641
|
}
|
|
554
|
-
function
|
|
555
|
-
|
|
556
|
-
const s =
|
|
642
|
+
function kr(t, r) {
|
|
643
|
+
hr(), r.run && Tr(t, r), r.status && $r(t, r), r.wait && Ir(t, r), r.list && Nr(t, r), r.kill && Er(t);
|
|
644
|
+
const s = r.commandLineRules?.map(
|
|
557
645
|
(o) => `${o.rule.toUpperCase()}: ${o.regexp} (${o.note})`
|
|
558
646
|
) || [];
|
|
559
647
|
console.log(
|
|
560
648
|
`Process manager:
|
|
561
|
-
- Working directory: ${
|
|
562
|
-
- Command line rules: ${
|
|
649
|
+
- Working directory: ${R.resolve(r.workingDir || "")}
|
|
650
|
+
- Command line rules: ${r.commandLineRules?.length || 0} rules configured:
|
|
563
651
|
${s.map((o) => `- ${o}`).join(`
|
|
564
652
|
`)}
|
|
565
653
|
`
|
|
566
654
|
);
|
|
567
655
|
}
|
|
568
|
-
function
|
|
656
|
+
function Or(t, r) {
|
|
569
657
|
return function(o, e, n) {
|
|
570
658
|
const a = async (...i) => {
|
|
571
|
-
await
|
|
572
|
-
logFilePath:
|
|
659
|
+
await ie({
|
|
660
|
+
logFilePath: r.logFilePath,
|
|
573
661
|
message: "REQUEST",
|
|
574
662
|
data: { name: o, args: i }
|
|
575
663
|
});
|
|
576
664
|
const c = await n(...i);
|
|
577
|
-
return await
|
|
578
|
-
logFilePath:
|
|
665
|
+
return await ie({
|
|
666
|
+
logFilePath: r.logFilePath,
|
|
579
667
|
message: "RESPONSE",
|
|
580
668
|
data: c
|
|
581
669
|
}), {
|
|
@@ -587,35 +675,35 @@ function Sr(r, t) {
|
|
|
587
675
|
]
|
|
588
676
|
};
|
|
589
677
|
};
|
|
590
|
-
return
|
|
678
|
+
return t.registerTool(
|
|
591
679
|
o,
|
|
592
680
|
e,
|
|
593
681
|
a
|
|
594
682
|
);
|
|
595
683
|
};
|
|
596
684
|
}
|
|
597
|
-
function
|
|
598
|
-
return
|
|
685
|
+
function Dr(t) {
|
|
686
|
+
return t.match(/^[/\\]?[^/\\]+/)[0];
|
|
599
687
|
}
|
|
600
|
-
function
|
|
601
|
-
return
|
|
688
|
+
function Rr(t, r) {
|
|
689
|
+
return Dr(t) + "|" + r.ino;
|
|
602
690
|
}
|
|
603
|
-
function
|
|
604
|
-
return
|
|
691
|
+
function Fr(t) {
|
|
692
|
+
return t.endsWith(":") && (t += "/"), R.resolve(t);
|
|
605
693
|
}
|
|
606
|
-
const
|
|
607
|
-
function
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
),
|
|
694
|
+
const be = new Wt(Vt.cpus().length);
|
|
695
|
+
function Ee(t, r) {
|
|
696
|
+
t.totalSize += r.totalSize, t.maxFileDateModified = Math.max(
|
|
697
|
+
t.maxFileDateModified,
|
|
698
|
+
r.maxFileDateModified
|
|
699
|
+
), t.countFiles += r.countFiles, t.countDirs += r.countDirs, t.countLinks += r.countLinks;
|
|
612
700
|
}
|
|
613
|
-
const
|
|
614
|
-
return
|
|
701
|
+
const Br = function(r) {
|
|
702
|
+
return r.code === "ENOENT";
|
|
615
703
|
};
|
|
616
|
-
function
|
|
617
|
-
const
|
|
618
|
-
if (!
|
|
704
|
+
function dt(t) {
|
|
705
|
+
const r = t.paths;
|
|
706
|
+
if (!r || r.length === 0)
|
|
619
707
|
return Promise.resolve({
|
|
620
708
|
totalSize: 0,
|
|
621
709
|
maxFileDateModified: 0,
|
|
@@ -623,16 +711,16 @@ function nt(r) {
|
|
|
623
711
|
countDirs: 0,
|
|
624
712
|
countLinks: 0
|
|
625
713
|
});
|
|
626
|
-
const s =
|
|
627
|
-
async function
|
|
628
|
-
if (!(a && await a(
|
|
629
|
-
throw
|
|
714
|
+
const s = t.level ?? 0, o = t.walkedIds ?? /* @__PURE__ */ new Set(), e = t.abortSignal, n = t.pool ?? be, a = t.handleError, i = t.priority ?? Z(0), c = t.walkLinks ?? !1, l = t.log, u = t.handlePath, f = t.matchPath;
|
|
715
|
+
async function d(g) {
|
|
716
|
+
if (!(a && await a(g)) && !Br(g))
|
|
717
|
+
throw g;
|
|
630
718
|
}
|
|
631
|
-
function h(
|
|
632
|
-
return !(!l || l.minTotalContentSize != null &&
|
|
719
|
+
function h(g) {
|
|
720
|
+
return !(!l || l.minTotalContentSize != null && g < l.minTotalContentSize || l.maxNestedLevel != null && s > l.maxNestedLevel);
|
|
633
721
|
}
|
|
634
|
-
return
|
|
635
|
-
const
|
|
722
|
+
return Ht(async (g) => {
|
|
723
|
+
const m = Qt(e, g), y = {
|
|
636
724
|
totalSize: 0,
|
|
637
725
|
maxFileDateModified: 0,
|
|
638
726
|
countFiles: 0,
|
|
@@ -645,8 +733,8 @@ function nt(r) {
|
|
|
645
733
|
l?.handleLog ? l.handleLog(T) : console.log(T);
|
|
646
734
|
}
|
|
647
735
|
}
|
|
648
|
-
async function
|
|
649
|
-
return u ? await
|
|
736
|
+
async function I($, S, x, T) {
|
|
737
|
+
return u ? await V({
|
|
650
738
|
pool: n,
|
|
651
739
|
func: async () => {
|
|
652
740
|
try {
|
|
@@ -656,54 +744,54 @@ function nt(r) {
|
|
|
656
744
|
stat: S,
|
|
657
745
|
itemStat: x,
|
|
658
746
|
totalStat: y,
|
|
659
|
-
abortSignal:
|
|
747
|
+
abortSignal: m
|
|
660
748
|
});
|
|
661
|
-
} catch (
|
|
662
|
-
return await
|
|
749
|
+
} catch (N) {
|
|
750
|
+
return await d(N), !1;
|
|
663
751
|
}
|
|
664
752
|
},
|
|
665
753
|
count: 1,
|
|
666
754
|
priority: T,
|
|
667
|
-
abortSignal:
|
|
755
|
+
abortSignal: m
|
|
668
756
|
}) : !0;
|
|
669
757
|
}
|
|
670
|
-
async function
|
|
758
|
+
async function v($, S, x, T) {
|
|
671
759
|
T || (T = $);
|
|
672
|
-
const
|
|
760
|
+
const N = await V({
|
|
673
761
|
pool: n,
|
|
674
|
-
func: () => W.promises.lstat($).catch(
|
|
762
|
+
func: () => W.promises.lstat($).catch(d),
|
|
675
763
|
count: 1,
|
|
676
|
-
priority:
|
|
677
|
-
abortSignal:
|
|
764
|
+
priority: Z(S, Z(1, i)),
|
|
765
|
+
abortSignal: m
|
|
678
766
|
});
|
|
679
|
-
if (!
|
|
767
|
+
if (!N || !x && N.isFile())
|
|
680
768
|
return null;
|
|
681
|
-
const
|
|
682
|
-
if (o.has(
|
|
769
|
+
const B = Rr($, N);
|
|
770
|
+
if (o.has(B))
|
|
683
771
|
return null;
|
|
684
|
-
o.add(
|
|
772
|
+
o.add(B);
|
|
685
773
|
let k = {
|
|
686
|
-
totalSize:
|
|
687
|
-
maxFileDateModified:
|
|
774
|
+
totalSize: N.size,
|
|
775
|
+
maxFileDateModified: N.isDirectory() ? 0 : N.mtimeMs,
|
|
688
776
|
countFiles: 0,
|
|
689
777
|
countDirs: 0,
|
|
690
778
|
countLinks: 0
|
|
691
779
|
};
|
|
692
|
-
const
|
|
780
|
+
const M = Z(
|
|
693
781
|
S,
|
|
694
|
-
|
|
782
|
+
Z(N.isDirectory() ? 2 : 3, i)
|
|
695
783
|
);
|
|
696
|
-
if (
|
|
784
|
+
if (N.isSymbolicLink()) {
|
|
697
785
|
if (c) {
|
|
698
|
-
const C = await
|
|
786
|
+
const C = await V({
|
|
699
787
|
pool: n,
|
|
700
|
-
func: () => W.promises.readlink($).catch(
|
|
788
|
+
func: () => W.promises.readlink($).catch(d).then((E) => E ?? null),
|
|
701
789
|
count: 1,
|
|
702
|
-
priority:
|
|
703
|
-
abortSignal:
|
|
790
|
+
priority: M,
|
|
791
|
+
abortSignal: m
|
|
704
792
|
});
|
|
705
793
|
if (C) {
|
|
706
|
-
const E =
|
|
794
|
+
const E = R.isAbsolute(C) ? C : R.resolve(R.dirname(T), C), O = await v(
|
|
707
795
|
E,
|
|
708
796
|
S,
|
|
709
797
|
x,
|
|
@@ -712,105 +800,105 @@ function nt(r) {
|
|
|
712
800
|
O && (k = O);
|
|
713
801
|
}
|
|
714
802
|
}
|
|
715
|
-
return (x || k.countFiles + k.countDirs + k.countLinks >= 1) && (k.countLinks += 1, await
|
|
803
|
+
return (x || k.countFiles + k.countDirs + k.countLinks >= 1) && (k.countLinks += 1, await I(
|
|
716
804
|
T,
|
|
717
|
-
|
|
805
|
+
N,
|
|
718
806
|
k,
|
|
719
|
-
|
|
720
|
-
) && (
|
|
721
|
-
} else if (
|
|
722
|
-
const C = await
|
|
807
|
+
M
|
|
808
|
+
) && (Ee(y, k), w(T, k))), k;
|
|
809
|
+
} else if (N.isDirectory()) {
|
|
810
|
+
const C = await V({
|
|
723
811
|
pool: n,
|
|
724
|
-
func: () => W.promises.readdir($).catch(
|
|
812
|
+
func: () => W.promises.readdir($).catch(d),
|
|
725
813
|
count: 1,
|
|
726
814
|
priority: i,
|
|
727
|
-
abortSignal:
|
|
815
|
+
abortSignal: m
|
|
728
816
|
});
|
|
729
817
|
if (C) {
|
|
730
818
|
for (let E = 0, O = C.length; E < O; E++)
|
|
731
|
-
C[E] =
|
|
732
|
-
k = await
|
|
733
|
-
...
|
|
819
|
+
C[E] = R.join(T, C[E]);
|
|
820
|
+
k = await dt({
|
|
821
|
+
...t,
|
|
734
822
|
paths: C,
|
|
735
|
-
abortSignal:
|
|
736
|
-
priority:
|
|
823
|
+
abortSignal: m,
|
|
824
|
+
priority: M,
|
|
737
825
|
level: s + 1,
|
|
738
826
|
walkedIds: o
|
|
739
827
|
});
|
|
740
828
|
}
|
|
741
829
|
}
|
|
742
|
-
return (x || k.countFiles + k.countDirs + k.countLinks >= 1) && (
|
|
830
|
+
return (x || k.countFiles + k.countDirs + k.countLinks >= 1) && (N.isDirectory() ? k.countDirs += 1 : N.isFile() && (k.countFiles += 1), await I(
|
|
743
831
|
T,
|
|
744
|
-
|
|
832
|
+
N,
|
|
745
833
|
k,
|
|
746
|
-
|
|
747
|
-
) && (
|
|
834
|
+
M
|
|
835
|
+
) && (Ee(y, k), w(T, k))), k;
|
|
748
836
|
}
|
|
749
837
|
const b = [];
|
|
750
|
-
for (let $ = 0, S =
|
|
751
|
-
const x =
|
|
752
|
-
T !== !1 && b.push(
|
|
838
|
+
for (let $ = 0, S = r.length; $ < S; $++) {
|
|
839
|
+
const x = Fr(r[$]), T = f ? f(x) : !0;
|
|
840
|
+
T !== !1 && b.push(v(x, $, T));
|
|
753
841
|
}
|
|
754
842
|
return await Promise.all(b), y;
|
|
755
843
|
});
|
|
756
844
|
}
|
|
757
|
-
function
|
|
758
|
-
return
|
|
845
|
+
function ft(t) {
|
|
846
|
+
return dt(t);
|
|
759
847
|
}
|
|
760
|
-
function H(
|
|
761
|
-
return
|
|
848
|
+
function H(t) {
|
|
849
|
+
return t.replace(/\\/g, "/");
|
|
762
850
|
}
|
|
763
|
-
function
|
|
764
|
-
if (!
|
|
765
|
-
return
|
|
766
|
-
const s =
|
|
767
|
-
s && (
|
|
768
|
-
const o =
|
|
769
|
-
return o && (
|
|
851
|
+
function Lr(t, r) {
|
|
852
|
+
if (!r || r === ".")
|
|
853
|
+
return t;
|
|
854
|
+
const s = t.startsWith("^");
|
|
855
|
+
s && (t = t.substring(1));
|
|
856
|
+
const o = t.startsWith("!");
|
|
857
|
+
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 = H(R.normalize(t)), o && (t = "!" + t), s && (t = "^" + t), t;
|
|
770
858
|
}
|
|
771
|
-
function
|
|
772
|
-
const
|
|
773
|
-
return
|
|
859
|
+
function Pr(t) {
|
|
860
|
+
const r = t.startsWith("!");
|
|
861
|
+
return r && (t = t.substring(1)), t.startsWith("/") ? t = t.substring(1) : !t.startsWith("**") && !t.startsWith("../") && (t = `**/${t}`), r && (t = "!" + t), t;
|
|
774
862
|
}
|
|
775
|
-
function
|
|
776
|
-
return "^" +
|
|
863
|
+
function ke(t) {
|
|
864
|
+
return "^" + t;
|
|
777
865
|
}
|
|
778
|
-
async function
|
|
779
|
-
const s = (await W.promises.readFile(
|
|
866
|
+
async function Ar(t) {
|
|
867
|
+
const s = (await W.promises.readFile(t, "utf-8")).split(`
|
|
780
868
|
`), o = [];
|
|
781
869
|
return s.forEach((e) => {
|
|
782
870
|
e = e.trim(), !(!e || e.startsWith("#")) && o.push(e);
|
|
783
871
|
}), o;
|
|
784
872
|
}
|
|
785
|
-
async function
|
|
786
|
-
const
|
|
787
|
-
if (!
|
|
873
|
+
async function ht(t) {
|
|
874
|
+
const r = t.rootDir ?? ".", s = [];
|
|
875
|
+
if (!t.globs?.length)
|
|
788
876
|
return s;
|
|
789
877
|
const o = [];
|
|
790
|
-
return
|
|
791
|
-
e.value && (e.valueType === "file-contains-patterns" ? o.push(e) : e.valueType === "pattern" && s.push(e.exclude ?
|
|
878
|
+
return t.globs.forEach((e) => {
|
|
879
|
+
e.value && (e.valueType === "file-contains-patterns" ? o.push(e) : e.valueType === "pattern" && s.push(e.exclude ? ke(e.value) : e.value));
|
|
792
880
|
}), o.length && await Promise.all(
|
|
793
881
|
o.map(async (e) => {
|
|
794
|
-
await
|
|
795
|
-
pool:
|
|
882
|
+
await V({
|
|
883
|
+
pool: be,
|
|
796
884
|
count: 1,
|
|
797
885
|
func: async () => {
|
|
798
|
-
const n =
|
|
886
|
+
const n = R.resolve(r, e.value), a = await Ar(n), i = R.relative(r, R.dirname(n));
|
|
799
887
|
a.forEach((c) => {
|
|
800
|
-
c =
|
|
888
|
+
c = Pr(c), c = Lr(c, i), s.push(e.exclude ? ke(c) : c);
|
|
801
889
|
});
|
|
802
890
|
}
|
|
803
891
|
});
|
|
804
892
|
})
|
|
805
893
|
), s;
|
|
806
894
|
}
|
|
807
|
-
function
|
|
808
|
-
globs:
|
|
809
|
-
rootDir:
|
|
895
|
+
function pt({
|
|
896
|
+
globs: t,
|
|
897
|
+
rootDir: r,
|
|
810
898
|
noCase: s
|
|
811
899
|
}) {
|
|
812
900
|
const o = [];
|
|
813
|
-
return
|
|
901
|
+
return t.forEach((e) => {
|
|
814
902
|
e = H(e).trim();
|
|
815
903
|
const n = e.startsWith("^");
|
|
816
904
|
n && (e = e.substring(1).trim());
|
|
@@ -820,12 +908,12 @@ function lt({
|
|
|
820
908
|
`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.`
|
|
821
909
|
);
|
|
822
910
|
e.startsWith("/") && (e = "." + e);
|
|
823
|
-
const i = H(
|
|
911
|
+
const i = H(r ? R.resolve(r, e) : e);
|
|
824
912
|
if (!i)
|
|
825
913
|
return;
|
|
826
914
|
let c;
|
|
827
915
|
try {
|
|
828
|
-
c =
|
|
916
|
+
c = Zt(i, {
|
|
829
917
|
nocase: s ?? !1,
|
|
830
918
|
dot: !0,
|
|
831
919
|
strictBrackets: !0
|
|
@@ -852,61 +940,61 @@ function lt({
|
|
|
852
940
|
return i ? !1 : a;
|
|
853
941
|
};
|
|
854
942
|
}
|
|
855
|
-
async function
|
|
856
|
-
const
|
|
857
|
-
|
|
858
|
-
const e = await
|
|
859
|
-
rootDir:
|
|
860
|
-
globs:
|
|
943
|
+
async function zr(t) {
|
|
944
|
+
const r = t.rootDir ?? ".", s = [], o = {};
|
|
945
|
+
t.result.countFiles && (o.countFiles = 0), t.result.size && (o.size = 0);
|
|
946
|
+
const e = await ht({
|
|
947
|
+
rootDir: r,
|
|
948
|
+
globs: t.globs
|
|
861
949
|
});
|
|
862
|
-
return await
|
|
863
|
-
paths: [
|
|
950
|
+
return await ft({
|
|
951
|
+
paths: [r],
|
|
864
952
|
walkLinks: !0,
|
|
865
|
-
matchPath:
|
|
953
|
+
matchPath: pt({
|
|
866
954
|
globs: e,
|
|
867
|
-
rootDir:
|
|
955
|
+
rootDir: r,
|
|
868
956
|
noCase: !0
|
|
869
957
|
}),
|
|
870
958
|
handlePath: async ({ path: n, stat: a, itemStat: i }) => {
|
|
871
|
-
const c =
|
|
959
|
+
const c = R.relative(r, n), l = a.isDirectory(), u = a.isFile();
|
|
872
960
|
if (!l && !u)
|
|
873
961
|
return !0;
|
|
874
|
-
const
|
|
875
|
-
path:
|
|
876
|
-
type:
|
|
962
|
+
const f = H(c || "."), d = l ? "dir" : "file", h = l ? i.maxFileDateModified || null : a.mtimeMs, g = l ? i.totalSize : a.size, m = l ? i.countFiles : null, y = {
|
|
963
|
+
path: f,
|
|
964
|
+
type: d
|
|
877
965
|
};
|
|
878
|
-
if (
|
|
879
|
-
const [w,
|
|
880
|
-
if (w != null && h < w ||
|
|
966
|
+
if (t.result.dateModified && (y.dateModified = h), t.result.size && (y.size = g), t.result.countFiles && (y.countFiles = m), t.dateModified && h != null) {
|
|
967
|
+
const [w, I] = t.dateModified;
|
|
968
|
+
if (w != null && h < w || I != null && h > I)
|
|
881
969
|
return !1;
|
|
882
970
|
}
|
|
883
|
-
if (
|
|
884
|
-
const [w,
|
|
885
|
-
if (w != null &&
|
|
971
|
+
if (t.totalSize && g != null) {
|
|
972
|
+
const [w, I] = t.totalSize;
|
|
973
|
+
if (w != null && g < w || I != null && g > I)
|
|
886
974
|
return !1;
|
|
887
975
|
}
|
|
888
|
-
return
|
|
976
|
+
return d === "file" && (o.countFiles = (o.countFiles ?? 0) + 1), d === "file" && g != null && (o.size = (o.size ?? 0) + g), h != null && (o.dateModified == null || h > o.dateModified) && (o.dateModified = h), l && !t.result.dirs || u && !t.result.files || s.push(y), !0;
|
|
889
977
|
}
|
|
890
978
|
}), { items: s, totals: o };
|
|
891
979
|
}
|
|
892
|
-
const
|
|
893
|
-
function
|
|
894
|
-
if (
|
|
895
|
-
let
|
|
896
|
-
for (;
|
|
897
|
-
|
|
898
|
-
return `${s === 0 ?
|
|
980
|
+
const Oe = ["B", "KB", "MB", "GB", "TB"], De = 1024;
|
|
981
|
+
function Re(t) {
|
|
982
|
+
if (t == null) return "-";
|
|
983
|
+
let r = t ?? 0, s = 0;
|
|
984
|
+
for (; r >= De && s < Oe.length - 1; )
|
|
985
|
+
r /= De, s++;
|
|
986
|
+
return `${s === 0 ? r.toString() : r.toFixed(2)}${Oe[s]}`;
|
|
899
987
|
}
|
|
900
|
-
function
|
|
901
|
-
const s = Date.now() -
|
|
988
|
+
function Fe(t) {
|
|
989
|
+
const s = Date.now() - t;
|
|
902
990
|
if (s < 0) return "0s";
|
|
903
991
|
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), c = Math.floor(a / 30), l = Math.floor(a / 365);
|
|
904
992
|
return l > 0 ? `${l}Y` : c > 0 ? `${c}M` : i > 0 ? `${i}w` : a > 0 ? `${a}d` : n > 0 ? `${n}h` : e > 0 ? `${e}m` : `${o}s`;
|
|
905
993
|
}
|
|
906
|
-
function
|
|
907
|
-
return
|
|
908
|
-
for (let e = 0, n =
|
|
909
|
-
const a =
|
|
994
|
+
function Ur(t, r) {
|
|
995
|
+
return r?.length ? [...t].sort((s, o) => {
|
|
996
|
+
for (let e = 0, n = r.length; e < n; e++) {
|
|
997
|
+
const a = r[e];
|
|
910
998
|
let i, c;
|
|
911
999
|
switch (a.field) {
|
|
912
1000
|
case "type":
|
|
@@ -937,10 +1025,10 @@ function Er(r, t) {
|
|
|
937
1025
|
return a.desc ? -l : l;
|
|
938
1026
|
}
|
|
939
1027
|
return 0;
|
|
940
|
-
}) :
|
|
1028
|
+
}) : t;
|
|
941
1029
|
}
|
|
942
|
-
function
|
|
943
|
-
const s =
|
|
1030
|
+
function qr(t, r) {
|
|
1031
|
+
const s = Ur(t.items, r.sort ?? []), o = r.fields && r.fields.length > 0 ? r.fields : [];
|
|
944
1032
|
let e = "";
|
|
945
1033
|
if (s.length > 0 && o.length > 0) {
|
|
946
1034
|
for (let n = 0, a = o.length; n < a; n++) {
|
|
@@ -971,10 +1059,10 @@ function kr(r, t) {
|
|
|
971
1059
|
const u = o[c];
|
|
972
1060
|
switch (c > 0 && (e += " | "), u) {
|
|
973
1061
|
case "dateModified":
|
|
974
|
-
e += i.dateModified ?
|
|
1062
|
+
e += i.dateModified ? Fe(i.dateModified) : "-";
|
|
975
1063
|
break;
|
|
976
1064
|
case "size":
|
|
977
|
-
e +=
|
|
1065
|
+
e += Re(i.size);
|
|
978
1066
|
break;
|
|
979
1067
|
case "type":
|
|
980
1068
|
e += i.type;
|
|
@@ -993,24 +1081,24 @@ function kr(r, t) {
|
|
|
993
1081
|
e.length > 0 && (e += `
|
|
994
1082
|
---
|
|
995
1083
|
`);
|
|
996
|
-
const n =
|
|
997
|
-
e += `Totals: ${
|
|
1084
|
+
const n = Re(t.totals.size ?? 0), a = t.totals.dateModified ? `, last modified ${Fe(t.totals.dateModified)} ago` : "";
|
|
1085
|
+
e += `Totals: ${t.totals.countFiles ?? 0} files in dirs, ${n}${a}`;
|
|
998
1086
|
}
|
|
999
1087
|
return e;
|
|
1000
1088
|
}
|
|
1001
|
-
const
|
|
1002
|
-
version:
|
|
1003
|
-
},
|
|
1004
|
-
function
|
|
1005
|
-
const
|
|
1089
|
+
const _r = "3.0.16", Gr = {
|
|
1090
|
+
version: _r
|
|
1091
|
+
}, $o = "Project Tools", Io = "project-tools", Mo = Gr.version, To = "d00f70240703039df14c76176a055bce6b5484d2b552ba2c89820f03b8e5e60d", Be = 25e3;
|
|
1092
|
+
function Le(t) {
|
|
1093
|
+
const r = t.match(
|
|
1006
1094
|
/^\s*(\d+(?:\.\d+)?)\s*([smhdwMY]|sec(onds?)?|min(utes?)?|hours?|days?|weeks?|months?|years?)\s*$/i
|
|
1007
1095
|
);
|
|
1008
|
-
if (!
|
|
1096
|
+
if (!r)
|
|
1009
1097
|
throw new Error(
|
|
1010
|
-
`Invalid time ago format: "${
|
|
1098
|
+
`Invalid time ago format: "${t}". Must be a number followed by a time unit. Valid units: s/sec/seconds (seconds), m/min/minutes (minutes), h/hours (hours), d/days (days), w/weeks (weeks), M/months (months), Y/years (years). Examples: "30s", "0.5h", "1.5d", "7d", "3w", "6M", "1Y". Format is case-insensitive except M (months) must be uppercase to distinguish from m (minutes).`
|
|
1011
1099
|
);
|
|
1012
|
-
const s = parseFloat(
|
|
1013
|
-
let o =
|
|
1100
|
+
const s = parseFloat(r[1]);
|
|
1101
|
+
let o = r[2];
|
|
1014
1102
|
switch (o !== "M" && (o = o.toLowerCase(), o.startsWith("month") ? o = "M" : o.length > 1 && (o = o[0])), o) {
|
|
1015
1103
|
case "s":
|
|
1016
1104
|
return s * 1e3;
|
|
@@ -1032,13 +1120,13 @@ function Fe(r) {
|
|
|
1032
1120
|
);
|
|
1033
1121
|
}
|
|
1034
1122
|
}
|
|
1035
|
-
function
|
|
1036
|
-
const
|
|
1037
|
-
if (!
|
|
1123
|
+
function Pe(t) {
|
|
1124
|
+
const r = t.match(/^\s*(\d+(?:\.\d+)?)\s*(B|KB|MB|GB|TB)\s*$/i);
|
|
1125
|
+
if (!r)
|
|
1038
1126
|
throw new Error(
|
|
1039
|
-
`Invalid size format: "${
|
|
1127
|
+
`Invalid size format: "${t}". Must be a number (integer or decimal) followed by a size unit. Valid units: B (bytes), KB (kilobytes), MB (megabytes), GB (gigabytes), TB (terabytes). Uses binary units (1024-based). Examples: "1B", "2.5KB", "100MB", "1.2GB", "0.5TB". Units are case-insensitive.`
|
|
1040
1128
|
);
|
|
1041
|
-
const s = parseFloat(
|
|
1129
|
+
const s = parseFloat(r[1]), o = r[2].toUpperCase();
|
|
1042
1130
|
switch (o) {
|
|
1043
1131
|
case "B":
|
|
1044
1132
|
return s;
|
|
@@ -1056,7 +1144,7 @@ function Be(r) {
|
|
|
1056
1144
|
);
|
|
1057
1145
|
}
|
|
1058
1146
|
}
|
|
1059
|
-
const
|
|
1147
|
+
const mt = p.object({
|
|
1060
1148
|
rootDir: p.string().optional().describe(
|
|
1061
1149
|
'Root directory to list files from, resolved relative to the current working directory. Leave empty to use current directory. Examples: "src" (list src/ subdirectory), "../parent" (list parent directory), "docs/api" (list nested subdirectory). Path must exist and be accessible'
|
|
1062
1150
|
),
|
|
@@ -1095,13 +1183,13 @@ const ct = p.object({
|
|
|
1095
1183
|
'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'
|
|
1096
1184
|
)
|
|
1097
1185
|
});
|
|
1098
|
-
async function
|
|
1186
|
+
async function Jr(t, r) {
|
|
1099
1187
|
let s;
|
|
1100
1188
|
try {
|
|
1101
|
-
s =
|
|
1102
|
-
} catch (
|
|
1189
|
+
s = mt.parse(t);
|
|
1190
|
+
} catch (m) {
|
|
1103
1191
|
return {
|
|
1104
|
-
error:
|
|
1192
|
+
error: F(m)
|
|
1105
1193
|
};
|
|
1106
1194
|
}
|
|
1107
1195
|
const {
|
|
@@ -1118,46 +1206,46 @@ async function Rr(r, t) {
|
|
|
1118
1206
|
return {
|
|
1119
1207
|
error: 'Fields array must include "path" field when fields are specified. The "path" field is required to identify files and directories in the output'
|
|
1120
1208
|
};
|
|
1121
|
-
const
|
|
1122
|
-
let
|
|
1123
|
-
let y =
|
|
1209
|
+
const f = s.fields ? s.fields.map((m) => m === "totalCountFiles" ? "countFiles" : m === "lastModified" ? "dateModified" : m) : [];
|
|
1210
|
+
let d = a?.map((m) => {
|
|
1211
|
+
let y = m.field;
|
|
1124
1212
|
return y === "totalCountFiles" && (y = "countFiles"), y === "lastModified" && (y = "dateModified"), {
|
|
1125
1213
|
field: y,
|
|
1126
|
-
desc:
|
|
1214
|
+
desc: m.desc ?? !1
|
|
1127
1215
|
// Default to ascending if not specified
|
|
1128
1216
|
};
|
|
1129
1217
|
}) ?? null;
|
|
1130
|
-
(!
|
|
1131
|
-
const h =
|
|
1132
|
-
|
|
1218
|
+
(!d || d.length === 0) && (d = [{ field: "path", desc: !1 }]);
|
|
1219
|
+
const h = d?.map((m) => m.field) || [], g = R.resolve(
|
|
1220
|
+
r.workingDir || "",
|
|
1133
1221
|
s.rootDir || ""
|
|
1134
1222
|
);
|
|
1135
1223
|
try {
|
|
1136
1224
|
try {
|
|
1137
|
-
await W.promises.access(
|
|
1225
|
+
await W.promises.access(g, W.constants.F_OK);
|
|
1138
1226
|
} catch (x) {
|
|
1139
1227
|
if (x.code === "ENOENT")
|
|
1140
1228
|
return {
|
|
1141
|
-
error: `Directory does not exist: "${
|
|
1229
|
+
error: `Directory does not exist: "${g}". 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.`
|
|
1142
1230
|
};
|
|
1143
1231
|
throw x;
|
|
1144
1232
|
}
|
|
1145
|
-
const
|
|
1233
|
+
const m = o && o.length > 0 ? o.map((x) => ({
|
|
1146
1234
|
value: x,
|
|
1147
1235
|
valueType: "pattern",
|
|
1148
1236
|
exclude: !1
|
|
1149
|
-
})) : [{ value: "**", valueType: "pattern", exclude: !1 }], y =
|
|
1237
|
+
})) : [{ value: "**", valueType: "pattern", exclude: !1 }], y = r.globsExclude || [], w = [...m, ...y], I = {
|
|
1150
1238
|
files: e ?? !1,
|
|
1151
1239
|
dirs: n ?? !1,
|
|
1152
|
-
dateModified:
|
|
1153
|
-
size:
|
|
1154
|
-
countFiles:
|
|
1240
|
+
dateModified: f.includes("dateModified") || h.includes("dateModified"),
|
|
1241
|
+
size: f.includes("size") || h.includes("size"),
|
|
1242
|
+
countFiles: f.includes("countFiles") || h.includes("countFiles")
|
|
1155
1243
|
};
|
|
1156
|
-
let
|
|
1244
|
+
let v = null, b = null;
|
|
1157
1245
|
if (i || c)
|
|
1158
1246
|
try {
|
|
1159
|
-
const x = Date.now(), T = c ? x -
|
|
1160
|
-
|
|
1247
|
+
const x = Date.now(), T = c ? x - Le(c) : null, N = i ? x - Le(i) : null;
|
|
1248
|
+
v = [T, N];
|
|
1161
1249
|
} catch (x) {
|
|
1162
1250
|
return {
|
|
1163
1251
|
error: x instanceof Error ? x.message : "Unknown error parsing time ago filter"
|
|
@@ -1165,66 +1253,66 @@ async function Rr(r, t) {
|
|
|
1165
1253
|
}
|
|
1166
1254
|
if (l || u)
|
|
1167
1255
|
try {
|
|
1168
|
-
const x = l ?
|
|
1256
|
+
const x = l ? Pe(l) : null, T = u ? Pe(u) : null;
|
|
1169
1257
|
b = [x, T];
|
|
1170
1258
|
} catch (x) {
|
|
1171
1259
|
return {
|
|
1172
1260
|
error: x instanceof Error ? x.message : "Unknown error parsing size filter"
|
|
1173
1261
|
};
|
|
1174
1262
|
}
|
|
1175
|
-
const $ = await
|
|
1176
|
-
rootDir:
|
|
1263
|
+
const $ = await zr({
|
|
1264
|
+
rootDir: g || null,
|
|
1177
1265
|
globs: w,
|
|
1178
|
-
result:
|
|
1179
|
-
dateModified:
|
|
1266
|
+
result: I,
|
|
1267
|
+
dateModified: v,
|
|
1180
1268
|
totalSize: b
|
|
1181
1269
|
});
|
|
1182
|
-
return $.items.length >
|
|
1183
|
-
error: `Number of paths (${$.items.length}) exceeds maximum allowed (${
|
|
1270
|
+
return $.items.length > Be ? {
|
|
1271
|
+
error: `Number of paths (${$.items.length}) exceeds maximum allowed (${Be}). Consider using more specific glob patterns or filters to reduce the result set.`
|
|
1184
1272
|
} : {
|
|
1185
|
-
output:
|
|
1186
|
-
sort:
|
|
1187
|
-
fields:
|
|
1273
|
+
output: qr($, {
|
|
1274
|
+
sort: d,
|
|
1275
|
+
fields: f,
|
|
1188
1276
|
totals: !0
|
|
1189
1277
|
})
|
|
1190
1278
|
};
|
|
1191
|
-
} catch (
|
|
1192
|
-
return { error:
|
|
1279
|
+
} catch (m) {
|
|
1280
|
+
return { error: m instanceof Error ? m.message : "Unknown error" };
|
|
1193
1281
|
}
|
|
1194
1282
|
}
|
|
1195
|
-
function
|
|
1196
|
-
|
|
1283
|
+
function jr(t, r) {
|
|
1284
|
+
t(
|
|
1197
1285
|
"fs-list",
|
|
1198
1286
|
{
|
|
1199
1287
|
title: "List Files and Directories",
|
|
1200
1288
|
description: "List files and directories with advanced filtering, sorting and formatting options. Use this to analyze filesystem structure",
|
|
1201
|
-
inputSchema:
|
|
1289
|
+
inputSchema: mt.shape
|
|
1202
1290
|
},
|
|
1203
1291
|
async (s) => {
|
|
1204
|
-
const o = await
|
|
1292
|
+
const o = await Jr(s, r);
|
|
1205
1293
|
return o.error ? `Method: fs-list(${JSON.stringify(s)})
|
|
1206
1294
|
❌ Error: ${o.error}` : `Method: fs-list(${JSON.stringify(s)})
|
|
1207
1295
|
${o.output || JSON.stringify(o, null, 2)}`;
|
|
1208
1296
|
}
|
|
1209
1297
|
);
|
|
1210
1298
|
}
|
|
1211
|
-
const
|
|
1212
|
-
function
|
|
1213
|
-
return
|
|
1299
|
+
const ue = /* @__PURE__ */ new Map();
|
|
1300
|
+
function X(t) {
|
|
1301
|
+
return ue.has(t) || ue.set(t, {
|
|
1214
1302
|
fsSnapshotQueries: /* @__PURE__ */ new Map(),
|
|
1215
1303
|
fsSnapshots: /* @__PURE__ */ new Map()
|
|
1216
|
-
}),
|
|
1304
|
+
}), ue.get(t);
|
|
1217
1305
|
}
|
|
1218
|
-
function
|
|
1219
|
-
const
|
|
1306
|
+
function Ae(t) {
|
|
1307
|
+
const r = t.match(
|
|
1220
1308
|
/^\s*(\d+(?:\.\d+)?)\s*([smhdwMY]|sec(onds?)?|min(utes?)?|hours?|days?|weeks?|months?|years?)\s*$/i
|
|
1221
1309
|
);
|
|
1222
|
-
if (!
|
|
1310
|
+
if (!r)
|
|
1223
1311
|
throw new Error(
|
|
1224
|
-
`Invalid time ago format: "${
|
|
1312
|
+
`Invalid time ago format: "${t}". Must be a number followed by a time unit. Valid units: s/sec/seconds (seconds), m/min/minutes (minutes), h/hours (hours), d/days (days), w/weeks (weeks), M/months (months), Y/years (years). Examples: "30s", "0.5h", "1.5d", "7d", "3w", "6M", "1Y". Format is case-insensitive except M (months) must be uppercase to distinguish from m (minutes).`
|
|
1225
1313
|
);
|
|
1226
|
-
const s = parseFloat(
|
|
1227
|
-
let o =
|
|
1314
|
+
const s = parseFloat(r[1]);
|
|
1315
|
+
let o = r[2];
|
|
1228
1316
|
switch (o !== "M" && (o = o.toLowerCase(), o.startsWith("month") ? o = "M" : o.length > 1 && (o = o[0])), o) {
|
|
1229
1317
|
case "s":
|
|
1230
1318
|
return s * 1e3;
|
|
@@ -1246,13 +1334,13 @@ function Le(r) {
|
|
|
1246
1334
|
);
|
|
1247
1335
|
}
|
|
1248
1336
|
}
|
|
1249
|
-
function
|
|
1250
|
-
const
|
|
1251
|
-
if (!
|
|
1337
|
+
function ze(t) {
|
|
1338
|
+
const r = t.match(/^\s*(\d+(?:\.\d+)?)\s*(B|KB|MB|GB|TB)\s*$/i);
|
|
1339
|
+
if (!r)
|
|
1252
1340
|
throw new Error(
|
|
1253
|
-
`Invalid size format: "${
|
|
1341
|
+
`Invalid size format: "${t}". Must be a number (integer or decimal) followed by a size unit. Valid units: B (bytes), KB (kilobytes), MB (megabytes), GB (gigabytes), TB (terabytes). Uses binary units (1024-based). Examples: "1B", "2.5KB", "100MB", "1.2GB", "0.5TB". Units are case-insensitive.`
|
|
1254
1342
|
);
|
|
1255
|
-
const s = parseFloat(
|
|
1343
|
+
const s = parseFloat(r[1]), o = r[2].toUpperCase();
|
|
1256
1344
|
switch (o) {
|
|
1257
1345
|
case "B":
|
|
1258
1346
|
return s;
|
|
@@ -1270,7 +1358,7 @@ function Pe(r) {
|
|
|
1270
1358
|
);
|
|
1271
1359
|
}
|
|
1272
1360
|
}
|
|
1273
|
-
const
|
|
1361
|
+
const Se = p.object({
|
|
1274
1362
|
name: p.string().describe(
|
|
1275
1363
|
"Unique name for the filesystem snapshot query. Recommended format: kebab-case-1, kebab-case-2, ..."
|
|
1276
1364
|
),
|
|
@@ -1298,26 +1386,26 @@ const be = p.object({
|
|
|
1298
1386
|
maxTotalSize: p.string().optional().describe(
|
|
1299
1387
|
'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'
|
|
1300
1388
|
)
|
|
1301
|
-
}),
|
|
1389
|
+
}), Ue = new Map(
|
|
1302
1390
|
[
|
|
1303
1391
|
"name",
|
|
1304
1392
|
"type",
|
|
1305
1393
|
"countMatched",
|
|
1306
1394
|
"size",
|
|
1307
1395
|
"dateModified"
|
|
1308
|
-
].map((
|
|
1396
|
+
].map((t, r) => [t, r])
|
|
1309
1397
|
);
|
|
1310
|
-
function
|
|
1311
|
-
const s =
|
|
1398
|
+
function Kr(t, r) {
|
|
1399
|
+
const s = Ue.get(t) ?? 1 / 0, o = Ue.get(r) ?? 1 / 0;
|
|
1312
1400
|
return s > o ? 1 : s < o ? -1 : 0;
|
|
1313
1401
|
}
|
|
1314
|
-
async function
|
|
1402
|
+
async function gt(t, r, s) {
|
|
1315
1403
|
let o;
|
|
1316
1404
|
try {
|
|
1317
|
-
o =
|
|
1405
|
+
o = Se.parse(t);
|
|
1318
1406
|
} catch (h) {
|
|
1319
1407
|
return {
|
|
1320
|
-
error:
|
|
1408
|
+
error: F(h)
|
|
1321
1409
|
};
|
|
1322
1410
|
}
|
|
1323
1411
|
const {
|
|
@@ -1333,30 +1421,30 @@ async function ut(r, t, s) {
|
|
|
1333
1421
|
return {
|
|
1334
1422
|
error: "Session ID is required"
|
|
1335
1423
|
};
|
|
1336
|
-
const
|
|
1337
|
-
|
|
1424
|
+
const f = X(s.sessionId), d = H(
|
|
1425
|
+
R.resolve(r.workingDir || "", o.rootDir || "")
|
|
1338
1426
|
);
|
|
1339
1427
|
try {
|
|
1340
1428
|
try {
|
|
1341
|
-
await W.promises.access(
|
|
1429
|
+
await W.promises.access(d, W.constants.F_OK);
|
|
1342
1430
|
} catch (S) {
|
|
1343
1431
|
if (S.code === "ENOENT")
|
|
1344
1432
|
return {
|
|
1345
|
-
error: `Directory does not exist: "${
|
|
1433
|
+
error: `Directory does not exist: "${d}". 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.`
|
|
1346
1434
|
};
|
|
1347
1435
|
throw S;
|
|
1348
1436
|
}
|
|
1349
1437
|
const h = o.extraFields ? o.extraFields.map((S) => S === "lastModified" ? "dateModified" : S) : [];
|
|
1350
|
-
h.includes("name") || h.push("name"), h.sort(
|
|
1351
|
-
const
|
|
1438
|
+
h.includes("name") || h.push("name"), h.sort(Kr);
|
|
1439
|
+
const g = n && n.length > 0 ? n.map((S) => ({
|
|
1352
1440
|
value: S,
|
|
1353
1441
|
valueType: "pattern",
|
|
1354
1442
|
exclude: !1
|
|
1355
|
-
})) : [{ value: "**", valueType: "pattern", exclude: !1 }],
|
|
1356
|
-
let w = null,
|
|
1443
|
+
})) : [{ value: "**", valueType: "pattern", exclude: !1 }], m = r.globsExclude || [], y = [...g, ...m];
|
|
1444
|
+
let w = null, I = null;
|
|
1357
1445
|
if (i || c)
|
|
1358
1446
|
try {
|
|
1359
|
-
const S = Date.now(), x = c ? S -
|
|
1447
|
+
const S = Date.now(), x = c ? S - Ae(c) : null, T = i ? S - Ae(i) : null;
|
|
1360
1448
|
w = [x, T];
|
|
1361
1449
|
} catch (S) {
|
|
1362
1450
|
return {
|
|
@@ -1365,24 +1453,24 @@ async function ut(r, t, s) {
|
|
|
1365
1453
|
}
|
|
1366
1454
|
if (l || u)
|
|
1367
1455
|
try {
|
|
1368
|
-
const S = l ?
|
|
1369
|
-
|
|
1456
|
+
const S = l ? ze(l) : null, x = u ? ze(u) : null;
|
|
1457
|
+
I = [S, x];
|
|
1370
1458
|
} catch (S) {
|
|
1371
1459
|
return {
|
|
1372
1460
|
error: S instanceof Error ? S.message : "Unknown error parsing size filter"
|
|
1373
1461
|
};
|
|
1374
1462
|
}
|
|
1375
|
-
const
|
|
1463
|
+
const v = a ? a.includes("file") : !0, b = a ? a.includes("dir") : !0, $ = {
|
|
1376
1464
|
name: e,
|
|
1377
|
-
rootDir:
|
|
1465
|
+
rootDir: d,
|
|
1378
1466
|
globs: y,
|
|
1379
|
-
matchFiles:
|
|
1467
|
+
matchFiles: v,
|
|
1380
1468
|
matchDirs: b,
|
|
1381
1469
|
dateModified: w,
|
|
1382
|
-
totalSize:
|
|
1470
|
+
totalSize: I,
|
|
1383
1471
|
fields: h
|
|
1384
1472
|
};
|
|
1385
|
-
return
|
|
1473
|
+
return f.fsSnapshotQueries.set(e, $), {
|
|
1386
1474
|
snapshotQuery: $
|
|
1387
1475
|
};
|
|
1388
1476
|
} catch (h) {
|
|
@@ -1391,30 +1479,30 @@ async function ut(r, t, s) {
|
|
|
1391
1479
|
};
|
|
1392
1480
|
}
|
|
1393
1481
|
}
|
|
1394
|
-
function
|
|
1395
|
-
|
|
1482
|
+
function Wr(t, r) {
|
|
1483
|
+
t(
|
|
1396
1484
|
"fs-snapshot-query-create",
|
|
1397
1485
|
{
|
|
1398
1486
|
title: "Create Filesystem Snapshot Query",
|
|
1399
1487
|
description: "Create a filesystem snapshot query. Prefer fs-snapshot-browse if you need to immediately create a query, snapshot and browse it",
|
|
1400
|
-
inputSchema:
|
|
1488
|
+
inputSchema: Se.shape
|
|
1401
1489
|
},
|
|
1402
1490
|
async (s, o) => {
|
|
1403
|
-
const e = await
|
|
1491
|
+
const e = await gt(s, r, o);
|
|
1404
1492
|
return e.error != null ? `Method: fs-snapshot-query-create(${JSON.stringify(s)})
|
|
1405
1493
|
❌ Error: ${e.error}` : `Method: fs-snapshot-query-create(${JSON.stringify(s)})
|
|
1406
1494
|
✅ Filesystem snapshot query "${e.snapshotQuery.name}" created successfully`;
|
|
1407
1495
|
}
|
|
1408
1496
|
);
|
|
1409
1497
|
}
|
|
1410
|
-
function
|
|
1411
|
-
const { idToNode:
|
|
1498
|
+
function le(t) {
|
|
1499
|
+
const { idToNode: r, idToChildIds: s } = t, o = r.get(null);
|
|
1412
1500
|
if (o == null)
|
|
1413
1501
|
throw new Error(
|
|
1414
1502
|
"Impossible behavior: root node (id: null) not found in idToNode"
|
|
1415
1503
|
);
|
|
1416
1504
|
const e = /* @__PURE__ */ new Map();
|
|
1417
|
-
return
|
|
1505
|
+
return r.forEach((n, a) => {
|
|
1418
1506
|
if (n != null) {
|
|
1419
1507
|
if (e.has(n)) {
|
|
1420
1508
|
const i = e.get(n);
|
|
@@ -1426,18 +1514,18 @@ function ae(r) {
|
|
|
1426
1514
|
}
|
|
1427
1515
|
}), {
|
|
1428
1516
|
root: o,
|
|
1429
|
-
getNode: (n) =>
|
|
1517
|
+
getNode: (n) => r.get(n) ?? null,
|
|
1430
1518
|
getId: (n) => e.get(n) ?? null,
|
|
1431
1519
|
getChilds: (n) => {
|
|
1432
1520
|
let a = e.get(n);
|
|
1433
1521
|
if (a == null)
|
|
1434
|
-
if (n ===
|
|
1522
|
+
if (n === r.get(null))
|
|
1435
1523
|
a = null;
|
|
1436
1524
|
else
|
|
1437
1525
|
throw new Error("Impossible behavior: node not found in idToNode");
|
|
1438
1526
|
const i = s.get(a);
|
|
1439
1527
|
return i == null ? null : i.map((c) => {
|
|
1440
|
-
const l =
|
|
1528
|
+
const l = r.get(c);
|
|
1441
1529
|
if (l == null)
|
|
1442
1530
|
throw new Error(
|
|
1443
1531
|
`Child node with id '${c}' not found in idToNode`
|
|
@@ -1447,28 +1535,28 @@ function ae(r) {
|
|
|
1447
1535
|
}
|
|
1448
1536
|
};
|
|
1449
1537
|
}
|
|
1450
|
-
function
|
|
1538
|
+
function wt(t, r, s) {
|
|
1451
1539
|
let o = null;
|
|
1452
|
-
for (let e = 0, n =
|
|
1453
|
-
const a =
|
|
1540
|
+
for (let e = 0, n = r.length; e < n; e++) {
|
|
1541
|
+
const a = r[e], i = t(a), c = i == null ? null : wt(t, i, s), l = s(a, c);
|
|
1454
1542
|
l != null && (o == null && (o = []), o.push(l));
|
|
1455
1543
|
}
|
|
1456
1544
|
return o;
|
|
1457
1545
|
}
|
|
1458
|
-
function
|
|
1459
|
-
const { getId:
|
|
1546
|
+
function yt(t) {
|
|
1547
|
+
const { getId: r, getChilds: s, rootNodes: o, createSnapshotNode: e } = t, n = /* @__PURE__ */ new Map(), a = /* @__PURE__ */ new Map(), i = /* @__PURE__ */ new Map(), c = wt(
|
|
1460
1548
|
s,
|
|
1461
1549
|
o,
|
|
1462
|
-
(u,
|
|
1463
|
-
const
|
|
1464
|
-
if (u != null &&
|
|
1465
|
-
const h =
|
|
1466
|
-
n.set(h,
|
|
1550
|
+
(u, f) => {
|
|
1551
|
+
const d = e(u, f);
|
|
1552
|
+
if (u != null && d != null) {
|
|
1553
|
+
const h = r(u);
|
|
1554
|
+
n.set(h, d), a.set(d, h);
|
|
1467
1555
|
}
|
|
1468
|
-
return
|
|
1469
|
-
a.get(
|
|
1470
|
-
|
|
1471
|
-
),
|
|
1556
|
+
return d != null && f != null && i.set(
|
|
1557
|
+
a.get(d),
|
|
1558
|
+
f.map((h) => a.get(h))
|
|
1559
|
+
), d;
|
|
1472
1560
|
}
|
|
1473
1561
|
), l = e(null, c);
|
|
1474
1562
|
if (l == null)
|
|
@@ -1481,79 +1569,79 @@ function ft(r) {
|
|
|
1481
1569
|
idToChildIds: i
|
|
1482
1570
|
};
|
|
1483
1571
|
}
|
|
1484
|
-
function
|
|
1485
|
-
return
|
|
1572
|
+
function me(t) {
|
|
1573
|
+
return t = t != null ? H(t).replace(/\/$/, "") : null, !t || t === "." ? null : t;
|
|
1486
1574
|
}
|
|
1487
|
-
async function
|
|
1488
|
-
const
|
|
1575
|
+
async function Hr(t) {
|
|
1576
|
+
const r = /* @__PURE__ */ new Map(), s = /* @__PURE__ */ new Map(), o = R.resolve(t.rootDir || "."), n = {
|
|
1489
1577
|
path: ".",
|
|
1490
|
-
name:
|
|
1578
|
+
name: R.basename(o),
|
|
1491
1579
|
type: "dir",
|
|
1492
1580
|
isMatched: !1,
|
|
1493
1581
|
dateModified: null,
|
|
1494
1582
|
size: 0
|
|
1495
1583
|
};
|
|
1496
|
-
|
|
1497
|
-
const a = await
|
|
1584
|
+
r.set(null, n);
|
|
1585
|
+
const a = await ht({
|
|
1498
1586
|
rootDir: o,
|
|
1499
|
-
globs:
|
|
1587
|
+
globs: t.globs
|
|
1500
1588
|
});
|
|
1501
|
-
return await
|
|
1589
|
+
return await ft({
|
|
1502
1590
|
paths: [o],
|
|
1503
1591
|
walkLinks: !0,
|
|
1504
|
-
matchPath:
|
|
1592
|
+
matchPath: pt({
|
|
1505
1593
|
globs: a,
|
|
1506
1594
|
rootDir: o,
|
|
1507
1595
|
noCase: !0
|
|
1508
1596
|
}),
|
|
1509
1597
|
handlePath: async ({ path: i, stat: c, itemStat: l }) => {
|
|
1510
|
-
const u =
|
|
1511
|
-
if (!
|
|
1598
|
+
const u = R.relative(o, i), f = c.isDirectory(), d = c.isFile();
|
|
1599
|
+
if (!f && !d)
|
|
1512
1600
|
return !0;
|
|
1513
|
-
const h =
|
|
1601
|
+
const h = me(u || "."), g = f ? "dir" : "file", m = f ? null : c.mtimeMs, y = c.size;
|
|
1514
1602
|
let w = !0;
|
|
1515
|
-
if (
|
|
1516
|
-
const [$, S] =
|
|
1517
|
-
($ != null &&
|
|
1603
|
+
if (d && !t.matchFiles && (w = !1), f && !t.matchDirs && (w = !1), w && d && t.dateModified && m != null) {
|
|
1604
|
+
const [$, S] = t.dateModified;
|
|
1605
|
+
($ != null && m < $ || S != null && m > S) && (w = !1);
|
|
1518
1606
|
}
|
|
1519
|
-
if (w &&
|
|
1520
|
-
const [$, S] =
|
|
1607
|
+
if (w && d && t.totalSize && y != null) {
|
|
1608
|
+
const [$, S] = t.totalSize;
|
|
1521
1609
|
($ != null && y < $ || S != null && y > S) && (w = !1);
|
|
1522
1610
|
}
|
|
1523
|
-
if (
|
|
1611
|
+
if (f && !w) {
|
|
1524
1612
|
if (!(l.countFiles && l.countFiles > 0)) return !1;
|
|
1525
1613
|
} else if (!w)
|
|
1526
1614
|
return !1;
|
|
1527
|
-
const
|
|
1615
|
+
const I = {
|
|
1528
1616
|
path: h ?? ".",
|
|
1529
|
-
name:
|
|
1530
|
-
type:
|
|
1531
|
-
dateModified:
|
|
1617
|
+
name: R.basename(i),
|
|
1618
|
+
type: g,
|
|
1619
|
+
dateModified: m,
|
|
1532
1620
|
size: y,
|
|
1533
1621
|
isMatched: w
|
|
1534
1622
|
};
|
|
1535
1623
|
if (h == null)
|
|
1536
|
-
return n.dateModified =
|
|
1537
|
-
|
|
1538
|
-
const
|
|
1539
|
-
let b = s.get(
|
|
1540
|
-
return b || (b = [], s.set(
|
|
1624
|
+
return n.dateModified = m, n.size = y, n.isMatched = w, !0;
|
|
1625
|
+
r.set(h, I);
|
|
1626
|
+
const v = me(H(R.dirname(h)));
|
|
1627
|
+
let b = s.get(v);
|
|
1628
|
+
return b || (b = [], s.set(v, b)), b.push(h), !0;
|
|
1541
1629
|
}
|
|
1542
1630
|
}), {
|
|
1543
|
-
idToNode:
|
|
1631
|
+
idToNode: r,
|
|
1544
1632
|
idToChildIds: s
|
|
1545
1633
|
};
|
|
1546
1634
|
}
|
|
1547
|
-
const
|
|
1548
|
-
{ name: "[ ]", match: (
|
|
1549
|
-
{ name: "[\\t]", match: (
|
|
1550
|
-
{ name: "[\\n]", match: (
|
|
1551
|
-
{ name: "[-]", match: (
|
|
1552
|
-
{ name: "[=]", match: (
|
|
1553
|
-
{ name: "[_]", match: (
|
|
1554
|
-
{ name: "[*]", match: (
|
|
1555
|
-
{ name: "[.]", match: (
|
|
1556
|
-
{ name: "[0-9]", match: (
|
|
1635
|
+
const Qr = [
|
|
1636
|
+
{ name: "[ ]", match: (t) => t === 32, min: 2, max: 81 },
|
|
1637
|
+
{ name: "[\\t]", match: (t) => t === 9, min: 2, max: 20 },
|
|
1638
|
+
{ name: "[\\n]", match: (t) => t === 10, min: 2, max: 14 },
|
|
1639
|
+
{ name: "[-]", match: (t) => t === 45, min: 2, max: 16 },
|
|
1640
|
+
{ name: "[=]", match: (t) => t === 61, min: 2, max: 16 },
|
|
1641
|
+
{ name: "[_]", match: (t) => t === 95, min: 2, max: 16 },
|
|
1642
|
+
{ name: "[*]", match: (t) => t === 42, min: 2, max: 16 },
|
|
1643
|
+
{ name: "[.]", match: (t) => t === 46, min: 2, max: 16 },
|
|
1644
|
+
{ name: "[0-9]", match: (t) => t >= 48 && t <= 57, min: 2, max: 3 }
|
|
1557
1645
|
// { name: '[a-z]', match: c => c >= 97 && c <= 122, min: 2, max: 2 },
|
|
1558
1646
|
// { name: '[A-Z]', match: c => c >= 65 && c <= 90, min: 2, max: 2 },
|
|
1559
1647
|
// Other ASCII symbols
|
|
@@ -1567,21 +1655,21 @@ const Ar = [
|
|
|
1567
1655
|
// max: 2,
|
|
1568
1656
|
// },
|
|
1569
1657
|
];
|
|
1570
|
-
function
|
|
1571
|
-
const s =
|
|
1658
|
+
function qe(t, r = Qr) {
|
|
1659
|
+
const s = t.length;
|
|
1572
1660
|
if (s === 0) return 0;
|
|
1573
|
-
const o =
|
|
1661
|
+
const o = r.length;
|
|
1574
1662
|
if (o === 0)
|
|
1575
1663
|
return s;
|
|
1576
1664
|
let e = 0, n = 0;
|
|
1577
1665
|
for (; n < s; ) {
|
|
1578
|
-
const a =
|
|
1666
|
+
const a = t.charCodeAt(n);
|
|
1579
1667
|
let i = !1;
|
|
1580
1668
|
for (let c = 0; c < o; c++) {
|
|
1581
|
-
const l =
|
|
1669
|
+
const l = r[c];
|
|
1582
1670
|
if (l.match(a)) {
|
|
1583
1671
|
let u = 1;
|
|
1584
|
-
for (; ++n < s && l.match(
|
|
1672
|
+
for (; ++n < s && l.match(t.charCodeAt(n)) && u < l.max; )
|
|
1585
1673
|
u++;
|
|
1586
1674
|
if (u >= l.min) {
|
|
1587
1675
|
e++, i = !0;
|
|
@@ -1593,27 +1681,27 @@ function ze(r, t = Ar) {
|
|
|
1593
1681
|
}
|
|
1594
1682
|
return e;
|
|
1595
1683
|
}
|
|
1596
|
-
function
|
|
1597
|
-
let
|
|
1598
|
-
return
|
|
1684
|
+
function bt(t) {
|
|
1685
|
+
let r = 0;
|
|
1686
|
+
return r += qe(t.textOpen) + 1, t.textClose != null && (r += qe(t.textClose) + 1), t.indent && (r += 1), r;
|
|
1599
1687
|
}
|
|
1600
|
-
const
|
|
1601
|
-
function
|
|
1602
|
-
if (
|
|
1603
|
-
let
|
|
1604
|
-
for (;
|
|
1605
|
-
|
|
1606
|
-
return `${s === 0 ?
|
|
1688
|
+
const _e = ["B", "KB", "MB", "GB", "TB"], Ge = 1024;
|
|
1689
|
+
function Yr(t) {
|
|
1690
|
+
if (t == null) return "-";
|
|
1691
|
+
let r = t ?? 0, s = 0;
|
|
1692
|
+
for (; r >= Ge && s < _e.length - 1; )
|
|
1693
|
+
r /= Ge, s++;
|
|
1694
|
+
return `${s === 0 ? r.toString() : r.toFixed(2)}${_e[s]}`;
|
|
1607
1695
|
}
|
|
1608
|
-
function
|
|
1609
|
-
const s = Date.now() -
|
|
1696
|
+
function Vr(t) {
|
|
1697
|
+
const s = Date.now() - t;
|
|
1610
1698
|
if (s < 0) return "0s";
|
|
1611
1699
|
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), c = Math.floor(a / 30), l = Math.floor(a / 365);
|
|
1612
1700
|
return l > 0 ? `${l}Y` : c > 0 ? `${c}M` : i > 0 ? `${i}w` : a > 0 ? `${a}d` : n > 0 ? `${n}h` : e > 0 ? `${e}m` : `${o}s`;
|
|
1613
1701
|
}
|
|
1614
|
-
function
|
|
1702
|
+
function Zr(t) {
|
|
1615
1703
|
return function(s, o) {
|
|
1616
|
-
const e =
|
|
1704
|
+
const e = t.get(s), n = t.get(o);
|
|
1617
1705
|
if (e.type !== n.type)
|
|
1618
1706
|
return e.type === "file" ? -1 : 1;
|
|
1619
1707
|
if (e.type === "file")
|
|
@@ -1624,26 +1712,26 @@ function qr(r) {
|
|
|
1624
1712
|
}
|
|
1625
1713
|
};
|
|
1626
1714
|
}
|
|
1627
|
-
function
|
|
1628
|
-
const
|
|
1715
|
+
function Xr(t) {
|
|
1716
|
+
const r = t.fields ?? [];
|
|
1629
1717
|
return function(o, e) {
|
|
1630
1718
|
let n = "", a, i = 0;
|
|
1631
1719
|
const c = e ? e.length : 0;
|
|
1632
|
-
let l = 1, u,
|
|
1720
|
+
let l = 1, u, f = 0, d = 0, h = 0, g = 0, m = null, y, w, I;
|
|
1633
1721
|
if (e)
|
|
1634
1722
|
for (let b = 0; b < e.length; b++) {
|
|
1635
1723
|
const $ = e[b];
|
|
1636
|
-
i += $.countMatched, l += $.countTotal,
|
|
1724
|
+
i += $.countMatched, l += $.countTotal, f += $.tokens, d += $.tokensTotal, h += $.size, g += $.countFiles, $.dateModified != null && (m == null || $.dateModified > m) && (m = $.dateModified);
|
|
1637
1725
|
}
|
|
1638
|
-
o ? (y = o.type, w = o.name,
|
|
1639
|
-
for (let b = 0, $ =
|
|
1640
|
-
const S =
|
|
1726
|
+
o ? (y = o.type, w = o.name, I = o.path, a = o.isMatched, a && (i += 1), o.type === "file" ? (h = o.size || 0, g = 1, m = o.dateModified || null) : o.dateModified != null && (m == null || o.dateModified > m) && (m = o.dateModified)) : (y = "dir", w = "<root>", I = ".", a = !0);
|
|
1727
|
+
for (let b = 0, $ = r.length; b < $; b++) {
|
|
1728
|
+
const S = r[b];
|
|
1641
1729
|
switch (b > 0 && (n += " "), S) {
|
|
1642
1730
|
case "dateModified":
|
|
1643
|
-
n +=
|
|
1731
|
+
n += m ? Vr(m) : "-";
|
|
1644
1732
|
break;
|
|
1645
1733
|
case "size":
|
|
1646
|
-
n +=
|
|
1734
|
+
n += Yr(h);
|
|
1647
1735
|
break;
|
|
1648
1736
|
case "type":
|
|
1649
1737
|
n += y;
|
|
@@ -1656,31 +1744,31 @@ function _r(r) {
|
|
|
1656
1744
|
break;
|
|
1657
1745
|
}
|
|
1658
1746
|
}
|
|
1659
|
-
const
|
|
1747
|
+
const v = {
|
|
1660
1748
|
indent: !0,
|
|
1661
1749
|
textOpen: n,
|
|
1662
1750
|
textClose: null
|
|
1663
1751
|
};
|
|
1664
|
-
return u =
|
|
1752
|
+
return u = bt(v), d += u, {
|
|
1665
1753
|
type: y,
|
|
1666
1754
|
name: w,
|
|
1667
|
-
path:
|
|
1755
|
+
path: I,
|
|
1668
1756
|
isMatched: a,
|
|
1669
1757
|
countMatched: i,
|
|
1670
1758
|
countChilds: c,
|
|
1671
1759
|
countTotal: l,
|
|
1672
1760
|
tokens: u,
|
|
1673
|
-
tokensChilds:
|
|
1674
|
-
tokensTotal:
|
|
1675
|
-
text:
|
|
1761
|
+
tokensChilds: f,
|
|
1762
|
+
tokensTotal: d,
|
|
1763
|
+
text: v,
|
|
1676
1764
|
size: h,
|
|
1677
|
-
countFiles:
|
|
1678
|
-
dateModified:
|
|
1765
|
+
countFiles: g,
|
|
1766
|
+
dateModified: m
|
|
1679
1767
|
};
|
|
1680
1768
|
};
|
|
1681
1769
|
}
|
|
1682
|
-
async function
|
|
1683
|
-
const
|
|
1770
|
+
async function es(t) {
|
|
1771
|
+
const r = await Hr(t), s = le(r), o = s.getChilds(s.root), e = yt({
|
|
1684
1772
|
getId: (a) => {
|
|
1685
1773
|
const i = s.getId(a);
|
|
1686
1774
|
if (i == null)
|
|
@@ -1690,29 +1778,29 @@ async function Gr(r) {
|
|
|
1690
1778
|
return i;
|
|
1691
1779
|
},
|
|
1692
1780
|
getChilds: (a) => s.getChilds(a),
|
|
1693
|
-
createSnapshotNode:
|
|
1781
|
+
createSnapshotNode: Xr(t),
|
|
1694
1782
|
rootNodes: o ?? []
|
|
1695
|
-
}), n =
|
|
1783
|
+
}), n = Zr(e.idToNode);
|
|
1696
1784
|
return e.idToChildIds.forEach((a) => {
|
|
1697
1785
|
a.sort(n);
|
|
1698
|
-
}),
|
|
1786
|
+
}), le(e);
|
|
1699
1787
|
}
|
|
1700
|
-
const
|
|
1788
|
+
const ee = p.object({
|
|
1701
1789
|
queryName: p.string().optional().describe("Name of previously created filesystem snapshot query, to use"),
|
|
1702
|
-
query:
|
|
1790
|
+
query: Se.optional().describe(
|
|
1703
1791
|
"Filesystem snapshot query creation options JSON to automatically create query"
|
|
1704
1792
|
),
|
|
1705
1793
|
name: p.string().describe(
|
|
1706
1794
|
"Unique name for the filesystem snapshot. Recommended format: kebab-case-1, kebab-case-2, ..."
|
|
1707
1795
|
)
|
|
1708
1796
|
});
|
|
1709
|
-
async function
|
|
1797
|
+
async function ce(t, r, s) {
|
|
1710
1798
|
let o;
|
|
1711
1799
|
try {
|
|
1712
|
-
o =
|
|
1800
|
+
o = ee.parse(t);
|
|
1713
1801
|
} catch (u) {
|
|
1714
1802
|
return {
|
|
1715
|
-
error:
|
|
1803
|
+
error: F(u)
|
|
1716
1804
|
};
|
|
1717
1805
|
}
|
|
1718
1806
|
const { name: e, queryName: n, query: a } = o;
|
|
@@ -1720,7 +1808,7 @@ async function le(r, t, s) {
|
|
|
1720
1808
|
return {
|
|
1721
1809
|
error: "Session ID is required"
|
|
1722
1810
|
};
|
|
1723
|
-
const i =
|
|
1811
|
+
const i = X(s.sessionId);
|
|
1724
1812
|
if (n && a)
|
|
1725
1813
|
return {
|
|
1726
1814
|
error: "Either queryName or query must be provided, not both"
|
|
@@ -1734,9 +1822,9 @@ async function le(r, t, s) {
|
|
|
1734
1822
|
};
|
|
1735
1823
|
c = u;
|
|
1736
1824
|
} else if (a) {
|
|
1737
|
-
const u = await
|
|
1825
|
+
const u = await gt(
|
|
1738
1826
|
a,
|
|
1739
|
-
|
|
1827
|
+
r,
|
|
1740
1828
|
s
|
|
1741
1829
|
);
|
|
1742
1830
|
if (u.error != null)
|
|
@@ -1749,13 +1837,13 @@ async function le(r, t, s) {
|
|
|
1749
1837
|
error: "Either queryName or query must be provided"
|
|
1750
1838
|
};
|
|
1751
1839
|
try {
|
|
1752
|
-
const u = await
|
|
1840
|
+
const u = await es(c), f = {
|
|
1753
1841
|
name: e,
|
|
1754
1842
|
query: c,
|
|
1755
1843
|
tree: u
|
|
1756
1844
|
};
|
|
1757
|
-
return i.fsSnapshots.set(e,
|
|
1758
|
-
fsSnapshot:
|
|
1845
|
+
return i.fsSnapshots.set(e, f), {
|
|
1846
|
+
fsSnapshot: f,
|
|
1759
1847
|
queryCreated: l
|
|
1760
1848
|
};
|
|
1761
1849
|
} catch (u) {
|
|
@@ -1764,16 +1852,16 @@ async function le(r, t, s) {
|
|
|
1764
1852
|
};
|
|
1765
1853
|
}
|
|
1766
1854
|
}
|
|
1767
|
-
function
|
|
1768
|
-
|
|
1855
|
+
function ts(t, r) {
|
|
1856
|
+
t(
|
|
1769
1857
|
"fs-snapshot-create",
|
|
1770
1858
|
{
|
|
1771
1859
|
title: "Create Filesystem Snapshot",
|
|
1772
1860
|
description: "Create a filesystem snapshot. Use this to capture filesystem state for later browsing. Prefer fs-snapshot-browse if you need to immediately create and browse a snapshot",
|
|
1773
|
-
inputSchema:
|
|
1861
|
+
inputSchema: ee.shape
|
|
1774
1862
|
},
|
|
1775
1863
|
async (s, o) => {
|
|
1776
|
-
const e = await
|
|
1864
|
+
const e = await ce(s, r, o);
|
|
1777
1865
|
if (e.error != null)
|
|
1778
1866
|
return `Method: fs-snapshot-create(${JSON.stringify(s)})
|
|
1779
1867
|
❌ Error: ${e.error}`;
|
|
@@ -1784,18 +1872,18 @@ function Jr(r, t) {
|
|
|
1784
1872
|
}
|
|
1785
1873
|
);
|
|
1786
1874
|
}
|
|
1787
|
-
class
|
|
1875
|
+
class rs {
|
|
1788
1876
|
_first = null;
|
|
1789
1877
|
_last = null;
|
|
1790
1878
|
_size = 0;
|
|
1791
|
-
enqueue(
|
|
1792
|
-
const s = { item:
|
|
1879
|
+
enqueue(r) {
|
|
1880
|
+
const s = { item: r, next: null };
|
|
1793
1881
|
this._last ? this._last.next = s : this._first = s, this._last = s, this._size += 1;
|
|
1794
1882
|
}
|
|
1795
1883
|
dequeue() {
|
|
1796
1884
|
if (!this._first) return null;
|
|
1797
|
-
const
|
|
1798
|
-
return this._first = this._first.next, this._first || (this._last = null), this._size -= 1,
|
|
1885
|
+
const r = this._first.item;
|
|
1886
|
+
return this._first = this._first.next, this._first || (this._last = null), this._size -= 1, r;
|
|
1799
1887
|
}
|
|
1800
1888
|
peek() {
|
|
1801
1889
|
return this._first ? this._first.item : null;
|
|
@@ -1807,66 +1895,66 @@ class jr {
|
|
|
1807
1895
|
return this._size;
|
|
1808
1896
|
}
|
|
1809
1897
|
}
|
|
1810
|
-
function
|
|
1811
|
-
const
|
|
1898
|
+
function ss(t) {
|
|
1899
|
+
const r = new rs(), {
|
|
1812
1900
|
tree: s,
|
|
1813
1901
|
limits: { maxCountTotal: o, maxTokensTotal: e, maxCountGroup: n, maxTokensGroup: a },
|
|
1814
1902
|
indexRangeGroupStrategy: i
|
|
1815
|
-
} =
|
|
1816
|
-
c != null && c.length > 0 &&
|
|
1903
|
+
} = t, c = s.getChilds(s.root);
|
|
1904
|
+
c != null && c.length > 0 && r.enqueue({
|
|
1817
1905
|
reportNode: null,
|
|
1818
1906
|
node: s.root
|
|
1819
1907
|
});
|
|
1820
|
-
let l = null, u = 0,
|
|
1821
|
-
for (; !
|
|
1822
|
-
const { reportNode:
|
|
1823
|
-
if (
|
|
1908
|
+
let l = null, u = 0, f = 0;
|
|
1909
|
+
for (; !r.isEmpty(); ) {
|
|
1910
|
+
const { reportNode: d, node: h } = r.dequeue(), g = s.getChilds(h);
|
|
1911
|
+
if (g == null || h.countChilds === 0 || g.length !== h.countChilds)
|
|
1824
1912
|
throw new Error(
|
|
1825
1913
|
"Impossible behavior: nodeChilds is null or length mismatch"
|
|
1826
1914
|
);
|
|
1827
|
-
let
|
|
1828
|
-
for (let w = 0; w <
|
|
1829
|
-
|
|
1830
|
-
const y =
|
|
1831
|
-
if (o != null && u + h.countChilds +
|
|
1915
|
+
let m = r.size();
|
|
1916
|
+
for (let w = 0; w < g.length; w++)
|
|
1917
|
+
g[w].countChilds > 0 && (m += 1);
|
|
1918
|
+
const y = m * i.tokens;
|
|
1919
|
+
if (o != null && u + h.countChilds + m > o || e != null && f + h.tokensChilds + y > e) {
|
|
1832
1920
|
const w = [];
|
|
1833
|
-
let
|
|
1834
|
-
for (let $ = 0, S =
|
|
1835
|
-
const x =
|
|
1836
|
-
|
|
1837
|
-
!(o != null && u + 1 > o || e != null &&
|
|
1921
|
+
let I = null, v = 0;
|
|
1922
|
+
for (let $ = 0, S = g.length; $ < S; $++) {
|
|
1923
|
+
const x = g[$], T = v * i.tokens;
|
|
1924
|
+
I != null && // Если общий лимит превышен, то не создаем новую группу, а продолжаем текущую. В случае достижения лимитов, последняя группа может содержать больше элементов, чем указано в лимитах группы, и это допустимо. Главное - дать в отчете полную картину.
|
|
1925
|
+
!(o != null && u + 1 > o || e != null && f + i.tokens > e) && (n != null && I.countGrouped + 1 + v > n || a != null && I.tokensGrouped + x.tokens + T > a) && (w.push(I), u += 1, f += i.tokens, I = null, v = 0), I = i.add(I, x, $), x.countChilds > 0 && (v += 1);
|
|
1838
1926
|
}
|
|
1839
|
-
|
|
1927
|
+
I != null && (w.push(I), u += 1, f += i.tokens);
|
|
1840
1928
|
const b = w.map(($) => ({
|
|
1841
1929
|
text: i.getReportText($)
|
|
1842
1930
|
}));
|
|
1843
|
-
if (
|
|
1844
|
-
if (
|
|
1931
|
+
if (d != null) {
|
|
1932
|
+
if (d.childs != null)
|
|
1845
1933
|
throw new Error("Impossible behavior: reportNode.childs != null");
|
|
1846
|
-
|
|
1934
|
+
d.childs = b;
|
|
1847
1935
|
} else {
|
|
1848
1936
|
if (l != null)
|
|
1849
1937
|
throw new Error("Impossible behavior: reportRootNodes != null");
|
|
1850
1938
|
l = b;
|
|
1851
1939
|
}
|
|
1852
1940
|
} else {
|
|
1853
|
-
u += h.countChilds,
|
|
1941
|
+
u += h.countChilds, f += h.tokensChilds;
|
|
1854
1942
|
const w = [];
|
|
1855
|
-
for (let
|
|
1856
|
-
const
|
|
1857
|
-
text:
|
|
1943
|
+
for (let I = 0; I < g.length; I++) {
|
|
1944
|
+
const v = g[I], b = {
|
|
1945
|
+
text: v.text
|
|
1858
1946
|
};
|
|
1859
1947
|
w.push(b);
|
|
1860
|
-
const $ = s.getChilds(
|
|
1861
|
-
$ != null && $.length > 0 &&
|
|
1948
|
+
const $ = s.getChilds(v);
|
|
1949
|
+
$ != null && $.length > 0 && r.enqueue({
|
|
1862
1950
|
reportNode: b,
|
|
1863
|
-
node:
|
|
1951
|
+
node: v
|
|
1864
1952
|
});
|
|
1865
1953
|
}
|
|
1866
|
-
if (
|
|
1867
|
-
if (
|
|
1954
|
+
if (d != null) {
|
|
1955
|
+
if (d.childs != null)
|
|
1868
1956
|
throw new Error("Impossible behavior: reportNode.childs != null");
|
|
1869
|
-
|
|
1957
|
+
d.childs = w;
|
|
1870
1958
|
} else {
|
|
1871
1959
|
if (l != null)
|
|
1872
1960
|
throw new Error("Impossible behavior: reportRootNodes != null");
|
|
@@ -1876,59 +1964,59 @@ function Kr(r) {
|
|
|
1876
1964
|
}
|
|
1877
1965
|
return l ?? [];
|
|
1878
1966
|
}
|
|
1879
|
-
function
|
|
1967
|
+
function St(t) {
|
|
1880
1968
|
const {
|
|
1881
|
-
tree:
|
|
1969
|
+
tree: r,
|
|
1882
1970
|
request: { parentNodeId: s, childsIndexRange: o, limits: e },
|
|
1883
1971
|
indexRangeGroupStrategy: n,
|
|
1884
1972
|
...a
|
|
1885
|
-
} =
|
|
1973
|
+
} = t;
|
|
1886
1974
|
let i;
|
|
1887
1975
|
if (s != null) {
|
|
1888
|
-
const
|
|
1889
|
-
if (
|
|
1976
|
+
const d = r.getNode(s);
|
|
1977
|
+
if (d == null)
|
|
1890
1978
|
throw new Error(`Parent node "${s}" not found`);
|
|
1891
|
-
i =
|
|
1979
|
+
i = d;
|
|
1892
1980
|
} else
|
|
1893
|
-
i =
|
|
1894
|
-
let c, l =
|
|
1981
|
+
i = r.root;
|
|
1982
|
+
let c, l = r.getChilds(i) ?? [];
|
|
1895
1983
|
if (o != null) {
|
|
1896
|
-
const [
|
|
1897
|
-
if (
|
|
1984
|
+
const [d, h] = o;
|
|
1985
|
+
if (d < 0 || h <= d || h >= l.length)
|
|
1898
1986
|
throw new Error(
|
|
1899
|
-
`Invalid index range: ${
|
|
1987
|
+
`Invalid index range: ${d}-${h} for root nodes length ${l.length}`
|
|
1900
1988
|
);
|
|
1901
|
-
const
|
|
1902
|
-
let
|
|
1903
|
-
for (let y =
|
|
1989
|
+
const g = [];
|
|
1990
|
+
let m = null;
|
|
1991
|
+
for (let y = d; y <= h; y++) {
|
|
1904
1992
|
const w = l[y];
|
|
1905
|
-
|
|
1993
|
+
g.push(w), m = n.add(m, w, y);
|
|
1906
1994
|
}
|
|
1907
|
-
l =
|
|
1995
|
+
l = g, c = {
|
|
1908
1996
|
...i,
|
|
1909
|
-
text: n.getReportText(
|
|
1910
|
-
countChilds:
|
|
1911
|
-
tokensChilds:
|
|
1997
|
+
text: n.getReportText(m),
|
|
1998
|
+
countChilds: m.countGrouped,
|
|
1999
|
+
tokensChilds: m.tokensGrouped
|
|
1912
2000
|
};
|
|
1913
2001
|
} else
|
|
1914
2002
|
c = i;
|
|
1915
2003
|
const u = {
|
|
1916
2004
|
countChilds: 1,
|
|
1917
2005
|
tokensChilds: c.tokens
|
|
1918
|
-
},
|
|
1919
|
-
...
|
|
2006
|
+
}, f = {
|
|
2007
|
+
...r,
|
|
1920
2008
|
root: u,
|
|
1921
|
-
getChilds: (
|
|
2009
|
+
getChilds: (d) => d === u ? [c] : d === c ? l : r.getChilds(d)
|
|
1922
2010
|
};
|
|
1923
|
-
return
|
|
1924
|
-
tree:
|
|
2011
|
+
return ss({
|
|
2012
|
+
tree: f,
|
|
1925
2013
|
limits: e,
|
|
1926
2014
|
indexRangeGroupStrategy: n,
|
|
1927
2015
|
...a
|
|
1928
2016
|
});
|
|
1929
2017
|
}
|
|
1930
|
-
function
|
|
1931
|
-
if (
|
|
2018
|
+
function xt(t, r) {
|
|
2019
|
+
if (t == null || t.length === 0)
|
|
1932
2020
|
return "No results found";
|
|
1933
2021
|
let s = "";
|
|
1934
2022
|
function o(e, n) {
|
|
@@ -1942,26 +2030,26 @@ function mt(r, t) {
|
|
|
1942
2030
|
`);
|
|
1943
2031
|
}
|
|
1944
2032
|
}
|
|
1945
|
-
return o(
|
|
2033
|
+
return o(t, ""), s;
|
|
1946
2034
|
}
|
|
1947
|
-
class
|
|
2035
|
+
class os {
|
|
1948
2036
|
tokens = 16;
|
|
1949
2037
|
// +1 indent, +1 for line break
|
|
1950
|
-
getReportText = (
|
|
2038
|
+
getReportText = (r) => ({
|
|
1951
2039
|
indent: !0,
|
|
1952
|
-
textOpen: `[${
|
|
2040
|
+
textOpen: `[${r.indexRange[0]}-${r.indexRange[1]}] see more ${r.countMatched} matched ${r.tokensGrouped} tokens`,
|
|
1953
2041
|
textClose: null
|
|
1954
2042
|
});
|
|
1955
|
-
add = (
|
|
2043
|
+
add = (r, s, o) => r == null ? {
|
|
1956
2044
|
indexRange: [o, o],
|
|
1957
2045
|
countGrouped: 1,
|
|
1958
2046
|
countMatched: s.countMatched,
|
|
1959
2047
|
tokensGrouped: s.tokens
|
|
1960
|
-
} : (
|
|
2048
|
+
} : (r.indexRange[1] = o, r.countGrouped += 1, r.countMatched += s.countMatched, r.tokensGrouped += s.tokens, r);
|
|
1961
2049
|
}
|
|
1962
|
-
const
|
|
2050
|
+
const $t = p.object({
|
|
1963
2051
|
snapshotName: p.string().optional().describe("Name of previously created filesystem snapshot, to use"),
|
|
1964
|
-
snapshot:
|
|
2052
|
+
snapshot: ee.optional().describe(
|
|
1965
2053
|
"Filesystem snapshot creation options JSON to automatically create snapshot"
|
|
1966
2054
|
),
|
|
1967
2055
|
parentPath: p.string().optional().describe(
|
|
@@ -1981,13 +2069,13 @@ const gt = p.object({
|
|
|
1981
2069
|
// maxCountGroup: z.number().default(10).describe('Maximum items per group'),
|
|
1982
2070
|
// maxTokensGroup: z.number().default(1000).describe('Maximum tokens per group'),
|
|
1983
2071
|
});
|
|
1984
|
-
async function
|
|
2072
|
+
async function ns(t, r, s) {
|
|
1985
2073
|
let o;
|
|
1986
2074
|
try {
|
|
1987
|
-
o =
|
|
1988
|
-
} catch (
|
|
2075
|
+
o = $t.parse(t);
|
|
2076
|
+
} catch (m) {
|
|
1989
2077
|
return {
|
|
1990
|
-
error:
|
|
2078
|
+
error: F(m)
|
|
1991
2079
|
};
|
|
1992
2080
|
}
|
|
1993
2081
|
const {
|
|
@@ -2003,37 +2091,37 @@ async function Hr(r, t, s) {
|
|
|
2003
2091
|
return {
|
|
2004
2092
|
error: "Session ID is required"
|
|
2005
2093
|
};
|
|
2006
|
-
const
|
|
2094
|
+
const f = X(s.sessionId);
|
|
2007
2095
|
if (e && n)
|
|
2008
2096
|
return {
|
|
2009
2097
|
error: "Either snapshotName or snapshot must be provided, not both"
|
|
2010
2098
|
};
|
|
2011
|
-
let
|
|
2099
|
+
let d, h = !1, g = !1;
|
|
2012
2100
|
if (e) {
|
|
2013
|
-
if (
|
|
2101
|
+
if (d = f.fsSnapshots.get(e), d == null)
|
|
2014
2102
|
return {
|
|
2015
2103
|
error: `Filesystem snapshot "${e}" not found`
|
|
2016
2104
|
};
|
|
2017
2105
|
} else if (n) {
|
|
2018
|
-
const
|
|
2106
|
+
const m = await ce(
|
|
2019
2107
|
n,
|
|
2020
|
-
|
|
2108
|
+
r,
|
|
2021
2109
|
s
|
|
2022
2110
|
);
|
|
2023
|
-
if (
|
|
2111
|
+
if (m.error != null)
|
|
2024
2112
|
return {
|
|
2025
|
-
error:
|
|
2113
|
+
error: m.error
|
|
2026
2114
|
};
|
|
2027
|
-
|
|
2115
|
+
d = m.fsSnapshot, h = m.queryCreated, g = !0;
|
|
2028
2116
|
} else
|
|
2029
2117
|
return {
|
|
2030
2118
|
error: "Either snapshotName or snapshot must be provided"
|
|
2031
2119
|
};
|
|
2032
2120
|
try {
|
|
2033
|
-
const
|
|
2034
|
-
tree:
|
|
2121
|
+
const m = me(o.parentPath), y = St({
|
|
2122
|
+
tree: d.tree,
|
|
2035
2123
|
request: {
|
|
2036
|
-
parentNodeId:
|
|
2124
|
+
parentNodeId: m,
|
|
2037
2125
|
childsIndexRange: a,
|
|
2038
2126
|
limits: {
|
|
2039
2127
|
maxCountTotal: i,
|
|
@@ -2042,32 +2130,32 @@ async function Hr(r, t, s) {
|
|
|
2042
2130
|
maxTokensGroup: u
|
|
2043
2131
|
}
|
|
2044
2132
|
},
|
|
2045
|
-
indexRangeGroupStrategy: new
|
|
2046
|
-
}), w =
|
|
2133
|
+
indexRangeGroupStrategy: new os()
|
|
2134
|
+
}), w = xt(y);
|
|
2047
2135
|
return {
|
|
2048
|
-
fsSnapshot:
|
|
2136
|
+
fsSnapshot: d,
|
|
2049
2137
|
queryCreated: h,
|
|
2050
|
-
snapshotCreated:
|
|
2051
|
-
parentPath:
|
|
2138
|
+
snapshotCreated: g,
|
|
2139
|
+
parentPath: m,
|
|
2052
2140
|
childsIndexRange: a,
|
|
2053
2141
|
report: w
|
|
2054
2142
|
};
|
|
2055
|
-
} catch (
|
|
2143
|
+
} catch (m) {
|
|
2056
2144
|
return {
|
|
2057
|
-
error: `Failed to browse filesystem snapshot: ${
|
|
2145
|
+
error: `Failed to browse filesystem snapshot: ${m instanceof Error ? m.message : "Unknown error"}`
|
|
2058
2146
|
};
|
|
2059
2147
|
}
|
|
2060
2148
|
}
|
|
2061
|
-
function
|
|
2062
|
-
|
|
2149
|
+
function is(t, r) {
|
|
2150
|
+
t(
|
|
2063
2151
|
"fs-snapshot-browse",
|
|
2064
2152
|
{
|
|
2065
2153
|
title: "Browse Filesystem Snapshot",
|
|
2066
2154
|
description: "Browse and explore filesystem. Use this to efficiently browse, analyze, explore, inspect, etc directory and file structures",
|
|
2067
|
-
inputSchema:
|
|
2155
|
+
inputSchema: $t.shape
|
|
2068
2156
|
},
|
|
2069
2157
|
async (s, o) => {
|
|
2070
|
-
const e = await
|
|
2158
|
+
const e = await ns(s, r, o);
|
|
2071
2159
|
if (e.error != null)
|
|
2072
2160
|
return `Method: fs-snapshot-browse(${JSON.stringify(s)})
|
|
2073
2161
|
❌ Error: ${e.error}`;
|
|
@@ -2089,215 +2177,215 @@ ${e.report}`, n;
|
|
|
2089
2177
|
}
|
|
2090
2178
|
);
|
|
2091
2179
|
}
|
|
2092
|
-
function
|
|
2093
|
-
const
|
|
2180
|
+
function It(t) {
|
|
2181
|
+
const r = [], s = t.tree, o = t.query.rootDir ?? ".";
|
|
2094
2182
|
function e(n) {
|
|
2095
|
-
n.type === "file" && n.isMatched &&
|
|
2183
|
+
n.type === "file" && n.isMatched && r.push(o + "/" + n.path);
|
|
2096
2184
|
const a = s.getChilds(n);
|
|
2097
2185
|
if (a != null)
|
|
2098
2186
|
for (let i = 0; i < a.length; i++)
|
|
2099
2187
|
e(a[i]);
|
|
2100
2188
|
}
|
|
2101
|
-
return e(s.root),
|
|
2102
|
-
}
|
|
2103
|
-
const
|
|
2104
|
-
function
|
|
2105
|
-
const
|
|
2106
|
-
let s =
|
|
2107
|
-
return s == null && (s = new
|
|
2108
|
-
}
|
|
2109
|
-
async function
|
|
2110
|
-
const { filePath:
|
|
2111
|
-
return
|
|
2112
|
-
() =>
|
|
2113
|
-
pool:
|
|
2189
|
+
return e(s.root), r;
|
|
2190
|
+
}
|
|
2191
|
+
const Je = /* @__PURE__ */ new Map();
|
|
2192
|
+
function as(t) {
|
|
2193
|
+
const r = H(t);
|
|
2194
|
+
let s = Je.get(r);
|
|
2195
|
+
return s == null && (s = new Yt(), Je.set(r, s)), s;
|
|
2196
|
+
}
|
|
2197
|
+
async function ls(t) {
|
|
2198
|
+
const { filePath: r, func: s } = t;
|
|
2199
|
+
return as(r).lock(
|
|
2200
|
+
() => V({
|
|
2201
|
+
pool: be,
|
|
2114
2202
|
count: 1,
|
|
2115
2203
|
func: s
|
|
2116
2204
|
})
|
|
2117
2205
|
);
|
|
2118
2206
|
}
|
|
2119
|
-
const
|
|
2120
|
-
function
|
|
2121
|
-
const { content:
|
|
2207
|
+
const je = 10, re = 48, Ke = 57, de = 36, cs = 38, us = 39, ds = 60, fs = 62, hs = 96, se = 0, We = 1, He = 2, Qe = 3, Ye = 4, ps = 5;
|
|
2208
|
+
function ms(t) {
|
|
2209
|
+
const { content: r, pattern: s, replacement: o } = t, e = r.length, n = [0];
|
|
2122
2210
|
for (let b = 0; b < e; b++)
|
|
2123
|
-
|
|
2211
|
+
r.charCodeAt(b) === je && b + 1 < e && n.push(b + 1);
|
|
2124
2212
|
const a = n.length, i = [], c = [];
|
|
2125
|
-
let l = null, u = null,
|
|
2213
|
+
let l = null, u = null, f = null, d = 0;
|
|
2126
2214
|
if (o != null) {
|
|
2127
2215
|
const b = o.length;
|
|
2128
2216
|
let $ = !1;
|
|
2129
2217
|
for (let S = 0; S < b; S++)
|
|
2130
|
-
if (o.charCodeAt(S) ===
|
|
2218
|
+
if (o.charCodeAt(S) === de) {
|
|
2131
2219
|
$ = !0;
|
|
2132
2220
|
break;
|
|
2133
2221
|
}
|
|
2134
2222
|
if ($) {
|
|
2135
|
-
u = [],
|
|
2223
|
+
u = [], f = [];
|
|
2136
2224
|
let S = 0, x = 0;
|
|
2137
2225
|
for (; x < b; ) {
|
|
2138
|
-
if (o.charCodeAt(x) !==
|
|
2226
|
+
if (o.charCodeAt(x) !== de || x + 1 >= b) {
|
|
2139
2227
|
x++;
|
|
2140
2228
|
continue;
|
|
2141
2229
|
}
|
|
2142
2230
|
const T = o.charCodeAt(x + 1);
|
|
2143
|
-
let
|
|
2144
|
-
if (T ===
|
|
2145
|
-
|
|
2146
|
-
else if (T ===
|
|
2147
|
-
|
|
2148
|
-
else if (T ===
|
|
2149
|
-
|
|
2150
|
-
else if (T ===
|
|
2151
|
-
|
|
2152
|
-
else if (T >=
|
|
2153
|
-
let
|
|
2154
|
-
for (;
|
|
2155
|
-
const C = o.charCodeAt(
|
|
2156
|
-
if (C <
|
|
2157
|
-
|
|
2231
|
+
let N = -1, B = 0, k = 2;
|
|
2232
|
+
if (T === de)
|
|
2233
|
+
N = se, B = "$";
|
|
2234
|
+
else if (T === cs)
|
|
2235
|
+
N = We;
|
|
2236
|
+
else if (T === hs)
|
|
2237
|
+
N = He;
|
|
2238
|
+
else if (T === us)
|
|
2239
|
+
N = Qe;
|
|
2240
|
+
else if (T >= re && T <= Ke) {
|
|
2241
|
+
let M = x + 2;
|
|
2242
|
+
for (; M < b; ) {
|
|
2243
|
+
const C = o.charCodeAt(M);
|
|
2244
|
+
if (C < re || C > Ke) break;
|
|
2245
|
+
M++;
|
|
2158
2246
|
}
|
|
2159
|
-
|
|
2160
|
-
} else if (T ===
|
|
2161
|
-
let
|
|
2162
|
-
for (;
|
|
2163
|
-
|
|
2164
|
-
|
|
2247
|
+
N = Ye, B = o.substring(x + 1, M), k = M - x;
|
|
2248
|
+
} else if (T === ds) {
|
|
2249
|
+
let M = x + 2;
|
|
2250
|
+
for (; M < b && o.charCodeAt(M) !== fs; )
|
|
2251
|
+
M++;
|
|
2252
|
+
M < b && M > x + 2 && (N = ps, B = o.substring(x + 2, M), k = M + 1 - x);
|
|
2165
2253
|
}
|
|
2166
|
-
|
|
2254
|
+
N >= 0 ? (x > S && (u.push(se), f.push(o.substring(S, x))), u.push(N), f.push(B), x += k, S = x) : x++;
|
|
2167
2255
|
}
|
|
2168
|
-
S < b && (u.push(
|
|
2256
|
+
S < b && (u.push(se), f.push(o.substring(S))), d = u.length;
|
|
2169
2257
|
} else
|
|
2170
2258
|
l = o;
|
|
2171
2259
|
}
|
|
2172
|
-
let h = "",
|
|
2260
|
+
let h = "", g = 0, m = 0;
|
|
2173
2261
|
s.lastIndex = 0;
|
|
2174
2262
|
let y;
|
|
2175
|
-
for (; (y = s.exec(
|
|
2263
|
+
for (; (y = s.exec(r)) !== null; ) {
|
|
2176
2264
|
const b = y.index, $ = y[0], S = $.length, x = b + S;
|
|
2177
|
-
let T,
|
|
2265
|
+
let T, N, B, k;
|
|
2178
2266
|
if (a === 1)
|
|
2179
|
-
T = 0,
|
|
2267
|
+
T = 0, N = 1, B = 0, k = e;
|
|
2180
2268
|
else {
|
|
2181
|
-
let
|
|
2182
|
-
for (;
|
|
2183
|
-
const E =
|
|
2184
|
-
n[E] <= b ?
|
|
2269
|
+
let M = 0, C = a - 1;
|
|
2270
|
+
for (; M < C; ) {
|
|
2271
|
+
const E = M + C + 1 >> 1;
|
|
2272
|
+
n[E] <= b ? M = E : C = E - 1;
|
|
2185
2273
|
}
|
|
2186
|
-
if (T =
|
|
2274
|
+
if (T = M, S > 0) {
|
|
2187
2275
|
const E = x - 1;
|
|
2188
|
-
for (C = a - 1;
|
|
2189
|
-
const O =
|
|
2190
|
-
n[O] <= E ?
|
|
2276
|
+
for (C = a - 1; M < C; ) {
|
|
2277
|
+
const O = M + C + 1 >> 1;
|
|
2278
|
+
n[O] <= E ? M = O : C = O - 1;
|
|
2191
2279
|
}
|
|
2192
|
-
|
|
2280
|
+
N = M + 1;
|
|
2193
2281
|
} else
|
|
2194
|
-
|
|
2195
|
-
|
|
2282
|
+
N = T + 1;
|
|
2283
|
+
B = n[T], k = N < a ? n[N] : e;
|
|
2196
2284
|
}
|
|
2197
2285
|
if (i.push({
|
|
2198
2286
|
offset: [b, x],
|
|
2199
|
-
lines: [T,
|
|
2200
|
-
linesOffset: [
|
|
2287
|
+
lines: [T, N],
|
|
2288
|
+
linesOffset: [B, k]
|
|
2201
2289
|
}), o != null) {
|
|
2202
|
-
h +=
|
|
2203
|
-
let
|
|
2290
|
+
h += r.substring(g, b);
|
|
2291
|
+
let M;
|
|
2204
2292
|
if (l != null)
|
|
2205
|
-
|
|
2293
|
+
M = l;
|
|
2206
2294
|
else {
|
|
2207
|
-
|
|
2295
|
+
M = "";
|
|
2208
2296
|
const E = y.groups, O = y.length - 1;
|
|
2209
|
-
for (let K = 0; K <
|
|
2210
|
-
const
|
|
2211
|
-
switch (
|
|
2212
|
-
case
|
|
2213
|
-
|
|
2297
|
+
for (let K = 0; K < d; K++) {
|
|
2298
|
+
const q = u[K], P = f[K];
|
|
2299
|
+
switch (q) {
|
|
2300
|
+
case se:
|
|
2301
|
+
M += P;
|
|
2214
2302
|
break;
|
|
2215
|
-
case
|
|
2216
|
-
|
|
2303
|
+
case We:
|
|
2304
|
+
M += $;
|
|
2217
2305
|
break;
|
|
2218
|
-
case
|
|
2219
|
-
|
|
2306
|
+
case He:
|
|
2307
|
+
M += r.substring(0, b);
|
|
2220
2308
|
break;
|
|
2221
|
-
case
|
|
2222
|
-
|
|
2309
|
+
case Qe:
|
|
2310
|
+
M += r.substring(x);
|
|
2223
2311
|
break;
|
|
2224
|
-
case
|
|
2225
|
-
const
|
|
2226
|
-
if (
|
|
2227
|
-
const
|
|
2312
|
+
case Ye: {
|
|
2313
|
+
const L = P, z = L.length, A = L.charCodeAt(0) - re;
|
|
2314
|
+
if (z >= 2) {
|
|
2315
|
+
const _ = L.charCodeAt(1) - re, D = A * 10 + _;
|
|
2228
2316
|
if (D >= 1 && D <= O) {
|
|
2229
|
-
|
|
2317
|
+
M += y[D] ?? "", z > 2 && (M += L.substring(2));
|
|
2230
2318
|
break;
|
|
2231
2319
|
}
|
|
2232
2320
|
}
|
|
2233
|
-
|
|
2321
|
+
A >= 1 && A <= O ? (M += y[A] ?? "", z > 1 && (M += L.substring(1))) : M += "$" + L;
|
|
2234
2322
|
break;
|
|
2235
2323
|
}
|
|
2236
2324
|
default:
|
|
2237
|
-
E != null ?
|
|
2325
|
+
E != null ? M += E[P] ?? "" : M += "$<" + P + ">";
|
|
2238
2326
|
}
|
|
2239
2327
|
}
|
|
2240
2328
|
}
|
|
2241
|
-
h +=
|
|
2242
|
-
const C = b +
|
|
2329
|
+
h += M;
|
|
2330
|
+
const C = b + m;
|
|
2243
2331
|
c.push({
|
|
2244
|
-
offset: [C, C +
|
|
2332
|
+
offset: [C, C + M.length],
|
|
2245
2333
|
lines: [0, 0],
|
|
2246
2334
|
linesOffset: [0, 0]
|
|
2247
|
-
}),
|
|
2335
|
+
}), m += M.length - S, g = x;
|
|
2248
2336
|
}
|
|
2249
2337
|
if (S === 0 && s.lastIndex++, !s.global)
|
|
2250
2338
|
break;
|
|
2251
2339
|
}
|
|
2252
2340
|
if (s.lastIndex = 0, o == null)
|
|
2253
|
-
return { search: { content:
|
|
2254
|
-
h +=
|
|
2255
|
-
const w = h.length,
|
|
2341
|
+
return { search: { content: r, matches: i }, replace: null };
|
|
2342
|
+
h += r.substring(g);
|
|
2343
|
+
const w = h.length, I = [0];
|
|
2256
2344
|
for (let b = 0; b < w; b++)
|
|
2257
|
-
h.charCodeAt(b) ===
|
|
2258
|
-
const
|
|
2345
|
+
h.charCodeAt(b) === je && b + 1 < w && I.push(b + 1);
|
|
2346
|
+
const v = I.length;
|
|
2259
2347
|
for (let b = 0, $ = c.length; b < $; b++) {
|
|
2260
2348
|
const S = c[b], x = S.offset[0], T = S.offset[1];
|
|
2261
|
-
let
|
|
2262
|
-
if (
|
|
2263
|
-
|
|
2349
|
+
let N, B, k, M;
|
|
2350
|
+
if (v === 1)
|
|
2351
|
+
N = 0, B = 1, k = 0, M = w;
|
|
2264
2352
|
else {
|
|
2265
|
-
let C = 0, E =
|
|
2353
|
+
let C = 0, E = v - 1;
|
|
2266
2354
|
for (; C < E; ) {
|
|
2267
2355
|
const O = C + E + 1 >> 1;
|
|
2268
|
-
|
|
2356
|
+
I[O] <= x ? C = O : E = O - 1;
|
|
2269
2357
|
}
|
|
2270
|
-
if (
|
|
2358
|
+
if (N = C, T > x) {
|
|
2271
2359
|
const O = T - 1;
|
|
2272
|
-
for (E =
|
|
2360
|
+
for (E = v - 1; C < E; ) {
|
|
2273
2361
|
const K = C + E + 1 >> 1;
|
|
2274
|
-
|
|
2362
|
+
I[K] <= O ? C = K : E = K - 1;
|
|
2275
2363
|
}
|
|
2276
|
-
|
|
2364
|
+
B = C + 1;
|
|
2277
2365
|
} else
|
|
2278
|
-
|
|
2279
|
-
k =
|
|
2366
|
+
B = N + 1;
|
|
2367
|
+
k = I[N], M = B < v ? I[B] : w;
|
|
2280
2368
|
}
|
|
2281
|
-
S.lines[0] =
|
|
2369
|
+
S.lines[0] = N, S.lines[1] = B, S.linesOffset[0] = k, S.linesOffset[1] = M;
|
|
2282
2370
|
}
|
|
2283
2371
|
return {
|
|
2284
|
-
search: { content:
|
|
2372
|
+
search: { content: r, matches: i },
|
|
2285
2373
|
replace: { content: h, matches: c }
|
|
2286
2374
|
};
|
|
2287
2375
|
}
|
|
2288
|
-
function
|
|
2289
|
-
if (
|
|
2376
|
+
function Mt(t) {
|
|
2377
|
+
if (t.length === 0)
|
|
2290
2378
|
return [];
|
|
2291
|
-
const
|
|
2379
|
+
const r = [...t].sort((a, i) => {
|
|
2292
2380
|
const c = a.lines[0], l = i.lines[0];
|
|
2293
2381
|
if (c > l) return 1;
|
|
2294
2382
|
if (c < l) return -1;
|
|
2295
|
-
const u = a.lines[1],
|
|
2296
|
-
return u >
|
|
2383
|
+
const u = a.lines[1], f = i.lines[1];
|
|
2384
|
+
return u > f ? 1 : u < f ? -1 : 0;
|
|
2297
2385
|
}), s = [];
|
|
2298
|
-
let o = [...
|
|
2299
|
-
for (let a = 1; a <
|
|
2300
|
-
const i =
|
|
2386
|
+
let o = [...r[0].offset], e = [...r[0].lines], n = [...r[0].linesOffset];
|
|
2387
|
+
for (let a = 1; a < r.length; a++) {
|
|
2388
|
+
const i = r[a];
|
|
2301
2389
|
i.lines[0] <= e[1] ? (i.offset[0] < o[0] && (o[0] = i.offset[0]), i.offset[1] > o[1] && (o[1] = i.offset[1]), i.lines[1] > e[1] && (e[1] = i.lines[1], n[1] = i.linesOffset[1])) : (s.push({
|
|
2302
2390
|
offset: o,
|
|
2303
2391
|
lines: e,
|
|
@@ -2310,91 +2398,91 @@ function yt(r) {
|
|
|
2310
2398
|
linesOffset: n
|
|
2311
2399
|
}), s;
|
|
2312
2400
|
}
|
|
2313
|
-
function
|
|
2401
|
+
function oe(t, r, s, o) {
|
|
2314
2402
|
let e = 0, n = 0;
|
|
2315
2403
|
for (let u = 0; u < s; u++)
|
|
2316
|
-
|
|
2404
|
+
t.charCodeAt(u) === 10 && (n = u + 1, e++);
|
|
2317
2405
|
const a = e, i = n;
|
|
2318
2406
|
let c = s;
|
|
2319
2407
|
for (; c < o; c++)
|
|
2320
|
-
|
|
2408
|
+
t.charCodeAt(c) === 10 && e++;
|
|
2321
2409
|
const l = e + 1;
|
|
2322
|
-
for (; c <
|
|
2323
|
-
if (
|
|
2410
|
+
for (; c < r; c++)
|
|
2411
|
+
if (t.charCodeAt(c) === 10)
|
|
2324
2412
|
return { startLine: a, endLine: l, startLineOfs: i, endLineOfs: c + 1 };
|
|
2325
|
-
return { startLine: a, endLine: l, startLineOfs: i, endLineOfs:
|
|
2413
|
+
return { startLine: a, endLine: l, startLineOfs: i, endLineOfs: r };
|
|
2326
2414
|
}
|
|
2327
|
-
function
|
|
2328
|
-
if (
|
|
2329
|
-
const
|
|
2415
|
+
function gs(t, r) {
|
|
2416
|
+
if (t.replace == null && r.replace == null) {
|
|
2417
|
+
const U = [...t.search.matches, ...r.search.matches];
|
|
2330
2418
|
return {
|
|
2331
|
-
search: { content:
|
|
2419
|
+
search: { content: t.search.content, matches: Mt(U) },
|
|
2332
2420
|
replace: null
|
|
2333
2421
|
};
|
|
2334
2422
|
}
|
|
2335
|
-
const s =
|
|
2336
|
-
let y = 0, w = 0,
|
|
2337
|
-
for (; y <
|
|
2338
|
-
if (y <
|
|
2339
|
-
K = b < S ? b : S, T = $ > x ? $ : x,
|
|
2423
|
+
const s = t.replace ?? t.search, o = r.replace ?? r.search, e = t.search.content, n = o.content, a = e.length, i = n.length, c = t.search.matches, l = s.matches, u = r.search.matches, f = o.matches, d = l.length, h = u.length, g = [], m = [];
|
|
2424
|
+
let y = 0, w = 0, I = 0, v = 0, b = 0, $ = 0, S = 0, x = 0, T = 0, N = 0, B = 0, k = 0, M = 0, C = 0, E = 0, O = 0, K = 0, q = 0, P = 0, L = 0, z = 0, A = 0, _ = 0, D = 0;
|
|
2425
|
+
for (; y < d || w < h; )
|
|
2426
|
+
if (y < d && (b = l[y].offset[0], $ = l[y].offset[1]), w < h && (S = u[w].offset[0], x = u[w].offset[1]), y < d && w < h && b < x && S < $) {
|
|
2427
|
+
K = b < S ? b : S, T = $ > x ? $ : x, B = y, k = w, y++, w++;
|
|
2340
2428
|
do {
|
|
2341
|
-
for (
|
|
2429
|
+
for (N = T; y < d && l[y].offset[0] < T; )
|
|
2342
2430
|
$ = l[y].offset[1], $ > T && (T = $), y++;
|
|
2343
2431
|
for (; w < h && u[w].offset[0] < T; )
|
|
2344
2432
|
x = u[w].offset[1], x > T && (T = x), w++;
|
|
2345
|
-
} while (T !==
|
|
2346
|
-
|
|
2347
|
-
for (let
|
|
2348
|
-
|
|
2349
|
-
|
|
2350
|
-
for (let
|
|
2351
|
-
|
|
2352
|
-
|
|
2353
|
-
const
|
|
2354
|
-
m.push({
|
|
2355
|
-
offset: [I, C],
|
|
2356
|
-
lines: [q.startLine, q.endLine],
|
|
2357
|
-
linesOffset: [q.startLineOfs, q.endLineOfs]
|
|
2358
|
-
});
|
|
2359
|
-
const ee = se(n, i, E, O);
|
|
2433
|
+
} while (T !== N);
|
|
2434
|
+
M = 1 / 0, C = -1 / 0, q = K, P = I;
|
|
2435
|
+
for (let G = B; G < y; G++)
|
|
2436
|
+
L = c[G].offset[0], z = c[G].offset[1], A = l[G].offset[0], _ = l[G].offset[1], q < A && (D = q + P, D < M && (M = D), D = A + P, D > C && (C = D)), L < M && (M = L), z > C && (C = z), P += z - L - _ + A, q = _;
|
|
2437
|
+
q < T && (D = q + P, D < M && (M = D), D = T + P, D > C && (C = D)), I = P, E = 1 / 0, O = -1 / 0, q = K, P = v;
|
|
2438
|
+
for (let G = k; G < w; G++)
|
|
2439
|
+
L = u[G].offset[0], z = u[G].offset[1], A = f[G].offset[0], _ = f[G].offset[1], q < L && (D = q + P, D < E && (E = D), D = L + P, D > O && (O = D)), A < E && (E = A), _ > O && (O = _), P += _ - A - z + L, q = z;
|
|
2440
|
+
q < T && (D = q + P, D < E && (E = D), D = T + P, D > O && (O = D)), v = P;
|
|
2441
|
+
const U = oe(e, a, M, C);
|
|
2360
2442
|
g.push({
|
|
2443
|
+
offset: [M, C],
|
|
2444
|
+
lines: [U.startLine, U.endLine],
|
|
2445
|
+
linesOffset: [U.startLineOfs, U.endLineOfs]
|
|
2446
|
+
});
|
|
2447
|
+
const te = oe(n, i, E, O);
|
|
2448
|
+
m.push({
|
|
2361
2449
|
offset: [E, O],
|
|
2362
|
-
lines: [
|
|
2363
|
-
linesOffset: [
|
|
2450
|
+
lines: [te.startLine, te.endLine],
|
|
2451
|
+
linesOffset: [te.startLineOfs, te.endLineOfs]
|
|
2364
2452
|
});
|
|
2365
|
-
} else if (w >= h || y <
|
|
2366
|
-
|
|
2367
|
-
const
|
|
2368
|
-
|
|
2453
|
+
} else if (w >= h || y < d && b <= S) {
|
|
2454
|
+
L = c[y].offset[0], z = c[y].offset[1], A = l[y].offset[0], _ = l[y].offset[1], E = A + v, O = _ + v;
|
|
2455
|
+
const U = oe(n, i, E, O);
|
|
2456
|
+
g.push(c[y]), m.push({
|
|
2369
2457
|
offset: [E, O],
|
|
2370
|
-
lines: [
|
|
2371
|
-
linesOffset: [
|
|
2372
|
-
}),
|
|
2458
|
+
lines: [U.startLine, U.endLine],
|
|
2459
|
+
linesOffset: [U.startLineOfs, U.endLineOfs]
|
|
2460
|
+
}), I += z - L - _ + A, y++;
|
|
2373
2461
|
} else {
|
|
2374
|
-
|
|
2375
|
-
const
|
|
2376
|
-
|
|
2377
|
-
offset: [
|
|
2378
|
-
lines: [
|
|
2379
|
-
linesOffset: [
|
|
2380
|
-
}),
|
|
2462
|
+
L = u[w].offset[0], z = u[w].offset[1], A = f[w].offset[0], _ = f[w].offset[1], M = L + I, C = z + I;
|
|
2463
|
+
const U = oe(e, a, M, C);
|
|
2464
|
+
g.push({
|
|
2465
|
+
offset: [M, C],
|
|
2466
|
+
lines: [U.startLine, U.endLine],
|
|
2467
|
+
linesOffset: [U.startLineOfs, U.endLineOfs]
|
|
2468
|
+
}), m.push(f[w]), v += _ - A - z + L, w++;
|
|
2381
2469
|
}
|
|
2382
2470
|
return {
|
|
2383
|
-
search: { content: e, matches:
|
|
2384
|
-
replace: { content: n, matches:
|
|
2471
|
+
search: { content: e, matches: g },
|
|
2472
|
+
replace: { content: n, matches: m }
|
|
2385
2473
|
};
|
|
2386
2474
|
}
|
|
2387
|
-
async function
|
|
2388
|
-
const { filePath:
|
|
2389
|
-
return s.length === 0 ? { filePath:
|
|
2390
|
-
filePath:
|
|
2475
|
+
async function ws(t) {
|
|
2476
|
+
const { filePath: r, operations: s, dryRun: o } = t;
|
|
2477
|
+
return s.length === 0 ? { filePath: r, result: null } : ls({
|
|
2478
|
+
filePath: r,
|
|
2391
2479
|
func: async () => {
|
|
2392
2480
|
let e;
|
|
2393
2481
|
try {
|
|
2394
|
-
e = await W.promises.readFile(
|
|
2482
|
+
e = await W.promises.readFile(r, "utf-8");
|
|
2395
2483
|
} catch (i) {
|
|
2396
2484
|
return {
|
|
2397
|
-
filePath:
|
|
2485
|
+
filePath: r,
|
|
2398
2486
|
result: null,
|
|
2399
2487
|
error: `Failed to read file: ${i instanceof Error ? i.message : i + ""}`
|
|
2400
2488
|
};
|
|
@@ -2405,73 +2493,73 @@ async function is(r) {
|
|
|
2405
2493
|
let l;
|
|
2406
2494
|
try {
|
|
2407
2495
|
l = new RegExp(c.pattern, c.flags ?? "");
|
|
2408
|
-
} catch (
|
|
2496
|
+
} catch (d) {
|
|
2409
2497
|
return {
|
|
2410
|
-
filePath:
|
|
2498
|
+
filePath: r,
|
|
2411
2499
|
result: null,
|
|
2412
|
-
error: `Invalid RegExp pattern "${c.pattern}": ${
|
|
2500
|
+
error: `Invalid RegExp pattern "${c.pattern}": ${d instanceof Error ? d.message : d + ""}`
|
|
2413
2501
|
};
|
|
2414
2502
|
}
|
|
2415
|
-
const u = n?.replace?.content ?? e,
|
|
2503
|
+
const u = n?.replace?.content ?? e, f = ms({
|
|
2416
2504
|
content: u,
|
|
2417
2505
|
pattern: l,
|
|
2418
2506
|
replacement: c.replacement
|
|
2419
2507
|
});
|
|
2420
|
-
c.replacement != null && (a = !0), n == null ? n =
|
|
2508
|
+
c.replacement != null && (a = !0), n == null ? n = f : n = gs(n, f);
|
|
2421
2509
|
}
|
|
2422
2510
|
if (a && n?.replace != null && !o) {
|
|
2423
2511
|
const i = n.replace.content;
|
|
2424
2512
|
if (i !== e)
|
|
2425
2513
|
try {
|
|
2426
|
-
await W.promises.writeFile(
|
|
2514
|
+
await W.promises.writeFile(r, i, "utf-8");
|
|
2427
2515
|
} catch (c) {
|
|
2428
2516
|
return {
|
|
2429
|
-
filePath:
|
|
2517
|
+
filePath: r,
|
|
2430
2518
|
result: n,
|
|
2431
2519
|
error: `Failed to write file: ${c instanceof Error ? c.message : c + ""}`
|
|
2432
2520
|
};
|
|
2433
2521
|
}
|
|
2434
2522
|
}
|
|
2435
|
-
return { filePath:
|
|
2523
|
+
return { filePath: r, result: n };
|
|
2436
2524
|
}
|
|
2437
2525
|
});
|
|
2438
2526
|
}
|
|
2439
|
-
async function
|
|
2440
|
-
const { filePaths:
|
|
2527
|
+
async function Tt(t) {
|
|
2528
|
+
const { filePaths: r, operations: s, dryRun: o } = t;
|
|
2441
2529
|
return { results: await Promise.all(
|
|
2442
|
-
|
|
2443
|
-
(n) =>
|
|
2530
|
+
r.map(
|
|
2531
|
+
(n) => ws({ filePath: n, operations: s, dryRun: o })
|
|
2444
2532
|
)
|
|
2445
2533
|
) };
|
|
2446
2534
|
}
|
|
2447
|
-
const
|
|
2448
|
-
function
|
|
2449
|
-
const { content:
|
|
2535
|
+
const ys = 6;
|
|
2536
|
+
function bs(t) {
|
|
2537
|
+
const { content: r, startLine: s } = t, o = t.padWidth ?? ys;
|
|
2450
2538
|
let e = "", n = 0, a = 0;
|
|
2451
|
-
for (; n <
|
|
2452
|
-
const i =
|
|
2453
|
-
`, n), c = i === -1 ?
|
|
2454
|
-
e += String(s + a + 1).padStart(o) + "→" +
|
|
2539
|
+
for (; n < r.length; ) {
|
|
2540
|
+
const i = r.indexOf(`
|
|
2541
|
+
`, n), c = i === -1 ? r.length : i + 1;
|
|
2542
|
+
e += String(s + a + 1).padStart(o) + "→" + r.substring(n, c), n = c, a++;
|
|
2455
2543
|
}
|
|
2456
2544
|
return e.length > 0 && !e.endsWith(`
|
|
2457
2545
|
`) && (e += `
|
|
2458
2546
|
`), e;
|
|
2459
2547
|
}
|
|
2460
|
-
function
|
|
2461
|
-
const { content:
|
|
2548
|
+
function fe(t) {
|
|
2549
|
+
const { content: r, matches: s, outputLimit: o } = t;
|
|
2462
2550
|
if (s.length === 0)
|
|
2463
2551
|
return { output: "", truncated: !1 };
|
|
2464
|
-
const e =
|
|
2552
|
+
const e = Mt(s);
|
|
2465
2553
|
let n = "", a = !1;
|
|
2466
2554
|
for (let i = 0; i < e.length; i++) {
|
|
2467
|
-
const c = e[i], l =
|
|
2555
|
+
const c = e[i], l = r.substring(
|
|
2468
2556
|
c.linesOffset[0],
|
|
2469
2557
|
c.linesOffset[1]
|
|
2470
|
-
), u =
|
|
2558
|
+
), u = bs({
|
|
2471
2559
|
content: l,
|
|
2472
2560
|
startLine: c.lines[0]
|
|
2473
|
-
}),
|
|
2474
|
-
if (o != null && n.length +
|
|
2561
|
+
}), f = i > 0 ? 2 : 0;
|
|
2562
|
+
if (o != null && n.length + f + u.length > o) {
|
|
2475
2563
|
a = !0;
|
|
2476
2564
|
break;
|
|
2477
2565
|
}
|
|
@@ -2480,93 +2568,79 @@ function de(r) {
|
|
|
2480
2568
|
}
|
|
2481
2569
|
return { output: n, truncated: a };
|
|
2482
2570
|
}
|
|
2483
|
-
const
|
|
2484
|
-
function
|
|
2485
|
-
const { result:
|
|
2486
|
-
if (
|
|
2487
|
-
const
|
|
2488
|
-
content:
|
|
2489
|
-
matches:
|
|
2571
|
+
const Ve = "BEFORE", Ze = "AFTER";
|
|
2572
|
+
function Ss(t) {
|
|
2573
|
+
const { result: r, outputLimit: s } = t;
|
|
2574
|
+
if (r.replace == null) {
|
|
2575
|
+
const g = fe({
|
|
2576
|
+
content: r.search.content,
|
|
2577
|
+
matches: r.search.matches,
|
|
2490
2578
|
outputLimit: s
|
|
2491
2579
|
});
|
|
2492
|
-
return { output:
|
|
2580
|
+
return { output: g.output, truncated: g.truncated };
|
|
2493
2581
|
}
|
|
2494
|
-
const o = `<${
|
|
2495
|
-
`, e = `</${
|
|
2496
|
-
`, n = `<${
|
|
2497
|
-
`, a = `</${
|
|
2582
|
+
const o = `<${Ve}>
|
|
2583
|
+
`, e = `</${Ve}>
|
|
2584
|
+
`, n = `<${Ze}>
|
|
2585
|
+
`, a = `</${Ze}>
|
|
2498
2586
|
`, i = o.length + e.length + n.length + a.length;
|
|
2499
2587
|
if (s != null && s < i)
|
|
2500
2588
|
return { output: "", truncated: !0 };
|
|
2501
|
-
const c = s != null ? s - i : void 0, l = c != null ? Math.floor(c / 2) : void 0, u =
|
|
2502
|
-
content:
|
|
2503
|
-
matches:
|
|
2589
|
+
const c = s != null ? s - i : void 0, l = c != null ? Math.floor(c / 2) : void 0, u = fe({
|
|
2590
|
+
content: r.search.content,
|
|
2591
|
+
matches: r.search.matches,
|
|
2504
2592
|
outputLimit: l
|
|
2505
|
-
}),
|
|
2506
|
-
content:
|
|
2507
|
-
matches:
|
|
2508
|
-
outputLimit:
|
|
2593
|
+
}), f = c != null ? c - u.output.length : void 0, d = fe({
|
|
2594
|
+
content: r.replace.content,
|
|
2595
|
+
matches: r.replace.matches,
|
|
2596
|
+
outputLimit: f
|
|
2509
2597
|
});
|
|
2510
|
-
return { output: o + u.output + e + n +
|
|
2511
|
-
}
|
|
2512
|
-
|
|
2513
|
-
|
|
2514
|
-
|
|
2515
|
-
|
|
2516
|
-
|
|
2517
|
-
|
|
2518
|
-
|
|
2519
|
-
|
|
2520
|
-
if (c.error != null) {
|
|
2521
|
-
const h = l + `
|
|
2522
|
-
❌ ` + c.error + `
|
|
2598
|
+
return { output: o + u.output + e + n + d.output + a, truncated: u.truncated || d.truncated };
|
|
2599
|
+
}
|
|
2600
|
+
function Ct(t) {
|
|
2601
|
+
const { result: r, rootDir: s } = t;
|
|
2602
|
+
let o = "";
|
|
2603
|
+
for (let e = 0; e < r.results.length; e++) {
|
|
2604
|
+
const n = r.results[e], a = R.relative(s, n.filePath), i = o.length > 0 ? 1 : 0;
|
|
2605
|
+
if (n.error != null) {
|
|
2606
|
+
const l = a + `
|
|
2607
|
+
❌ ` + n.error + `
|
|
2523
2608
|
`;
|
|
2524
|
-
|
|
2525
|
-
|
|
2526
|
-
break;
|
|
2527
|
-
}
|
|
2528
|
-
u > 0 && (n += `
|
|
2529
|
-
`), n += h;
|
|
2609
|
+
i > 0 && (o += `
|
|
2610
|
+
`), o += l;
|
|
2530
2611
|
continue;
|
|
2531
2612
|
}
|
|
2532
|
-
if (
|
|
2613
|
+
if (n.result == null || n.result.search.matches.length === 0)
|
|
2533
2614
|
continue;
|
|
2534
|
-
const
|
|
2535
|
-
|
|
2536
|
-
a = !0;
|
|
2537
|
-
break;
|
|
2538
|
-
}
|
|
2539
|
-
const f = cs({
|
|
2540
|
-
result: c.result,
|
|
2541
|
-
outputLimit: d
|
|
2615
|
+
const c = Ss({
|
|
2616
|
+
result: n.result
|
|
2542
2617
|
});
|
|
2543
|
-
|
|
2544
|
-
`),
|
|
2545
|
-
` +
|
|
2546
|
-
break;
|
|
2618
|
+
c.output.length > 0 && (i > 0 && (o += `
|
|
2619
|
+
`), o += a + `
|
|
2620
|
+
` + c.output);
|
|
2547
2621
|
}
|
|
2548
|
-
return
|
|
2622
|
+
return o;
|
|
2549
2623
|
}
|
|
2550
|
-
const
|
|
2624
|
+
const xs = p.object({
|
|
2551
2625
|
pattern: p.string().describe("JS RegExp pattern"),
|
|
2552
2626
|
flags: p.string().optional().describe("JS RegExp flags")
|
|
2553
|
-
}),
|
|
2627
|
+
}), Nt = p.object({
|
|
2554
2628
|
snapshotName: p.string().optional().describe("Name of previously created filesystem snapshot, to use"),
|
|
2555
|
-
snapshot:
|
|
2629
|
+
snapshot: ee.optional().describe(
|
|
2556
2630
|
"Filesystem snapshot creation options JSON to automatically create snapshot"
|
|
2557
2631
|
),
|
|
2558
|
-
operations: p.array(
|
|
2559
|
-
outputLimit: p.number().max(
|
|
2560
|
-
`Maximum output characters. Output exceeding this limit will be truncated. Maximum: ${
|
|
2632
|
+
operations: p.array(xs).describe("Search operations to execute sequentially on each file"),
|
|
2633
|
+
outputLimit: p.number().int().min(0).max(J).default(Q).describe(
|
|
2634
|
+
`Maximum output characters. Output exceeding this limit will be truncated. Maximum: ${J}. Default: ${Q}`
|
|
2561
2635
|
)
|
|
2562
2636
|
});
|
|
2563
|
-
async function
|
|
2637
|
+
async function $s(t, r, s) {
|
|
2564
2638
|
let o;
|
|
2565
2639
|
try {
|
|
2566
|
-
o =
|
|
2567
|
-
} catch (
|
|
2640
|
+
o = Nt.parse(t);
|
|
2641
|
+
} catch (w) {
|
|
2568
2642
|
return {
|
|
2569
|
-
error:
|
|
2643
|
+
error: F(w)
|
|
2570
2644
|
};
|
|
2571
2645
|
}
|
|
2572
2646
|
const { snapshotName: e, snapshot: n, operations: a, outputLimit: i } = o;
|
|
@@ -2574,54 +2648,57 @@ async function ds(r, t, s) {
|
|
|
2574
2648
|
return {
|
|
2575
2649
|
error: "Session ID is required"
|
|
2576
2650
|
};
|
|
2577
|
-
const c =
|
|
2651
|
+
const c = X(s.sessionId);
|
|
2578
2652
|
if (e && n)
|
|
2579
2653
|
return {
|
|
2580
2654
|
error: "Either snapshotName or snapshot must be provided, not both"
|
|
2581
2655
|
};
|
|
2582
|
-
let l, u = !1,
|
|
2656
|
+
let l, u = !1, f = !1;
|
|
2583
2657
|
if (e) {
|
|
2584
2658
|
if (l = c.fsSnapshots.get(e), l == null)
|
|
2585
2659
|
return {
|
|
2586
2660
|
error: `Filesystem snapshot "${e}" not found`
|
|
2587
2661
|
};
|
|
2588
2662
|
} else if (n) {
|
|
2589
|
-
const
|
|
2663
|
+
const w = await ce(
|
|
2590
2664
|
n,
|
|
2591
|
-
|
|
2665
|
+
r,
|
|
2592
2666
|
s
|
|
2593
2667
|
);
|
|
2594
|
-
if (
|
|
2668
|
+
if (w.error != null)
|
|
2595
2669
|
return {
|
|
2596
|
-
error:
|
|
2670
|
+
error: w.error
|
|
2597
2671
|
};
|
|
2598
|
-
l =
|
|
2672
|
+
l = w.fsSnapshot, u = w.queryCreated, f = !0;
|
|
2599
2673
|
} else
|
|
2600
2674
|
return {
|
|
2601
2675
|
error: "Either snapshotName or snapshot must be provided"
|
|
2602
2676
|
};
|
|
2603
|
-
const
|
|
2604
|
-
filePaths:
|
|
2677
|
+
const d = It(l), h = l.query.rootDir ?? ".", g = await Tt({
|
|
2678
|
+
filePaths: d,
|
|
2605
2679
|
operations: a
|
|
2680
|
+
}), m = Ct({
|
|
2681
|
+
result: g,
|
|
2682
|
+
rootDir: h
|
|
2606
2683
|
});
|
|
2607
|
-
return { output:
|
|
2608
|
-
|
|
2609
|
-
|
|
2610
|
-
|
|
2611
|
-
}), rootDir: h, fsSnapshot: l, queryCreated: u, snapshotCreated:
|
|
2612
|
-
}
|
|
2613
|
-
function
|
|
2614
|
-
|
|
2684
|
+
return { output: we({
|
|
2685
|
+
sessionId: s.sessionId,
|
|
2686
|
+
source: m,
|
|
2687
|
+
limit: i
|
|
2688
|
+
}).content, rootDir: h, fsSnapshot: l, queryCreated: u, snapshotCreated: f };
|
|
2689
|
+
}
|
|
2690
|
+
function Is(t, r) {
|
|
2691
|
+
t(
|
|
2615
2692
|
"fs-snapshot-search",
|
|
2616
2693
|
{
|
|
2617
2694
|
title: "Search File Contents in Snapshot",
|
|
2618
2695
|
description: "Search file contents using JS RegExp. Use this to find text patterns across snapshot files. Combine all patterns into the `operations` array within one tool call; never split patterns across multiple tool calls",
|
|
2619
|
-
inputSchema:
|
|
2696
|
+
inputSchema: Nt.shape
|
|
2620
2697
|
},
|
|
2621
2698
|
async (s, o) => {
|
|
2622
|
-
const e = await
|
|
2699
|
+
const e = await $s(
|
|
2623
2700
|
s,
|
|
2624
|
-
|
|
2701
|
+
r,
|
|
2625
2702
|
o
|
|
2626
2703
|
);
|
|
2627
2704
|
if (e.error != null)
|
|
@@ -2638,30 +2715,30 @@ ${e.output}`, n += "\n\nReminder: combine all patterns into one `operations` arr
|
|
|
2638
2715
|
}
|
|
2639
2716
|
);
|
|
2640
2717
|
}
|
|
2641
|
-
const
|
|
2718
|
+
const Ms = p.object({
|
|
2642
2719
|
pattern: p.string().describe("JS RegExp pattern"),
|
|
2643
2720
|
flags: p.string().optional().describe("JS RegExp flags"),
|
|
2644
2721
|
replacement: p.string().describe("JS replacement pattern")
|
|
2645
|
-
}),
|
|
2722
|
+
}), vt = p.object({
|
|
2646
2723
|
snapshotName: p.string().optional().describe("Name of previously created filesystem snapshot, to use"),
|
|
2647
|
-
snapshot:
|
|
2724
|
+
snapshot: ee.optional().describe(
|
|
2648
2725
|
"Filesystem snapshot creation options JSON to automatically create snapshot"
|
|
2649
2726
|
),
|
|
2650
|
-
operations: p.array(
|
|
2651
|
-
outputLimit: p.number().max(
|
|
2652
|
-
`Maximum output characters. Output exceeding this limit will be truncated. Maximum: ${
|
|
2727
|
+
operations: p.array(Ms).describe("Replace operations to execute sequentially on each file"),
|
|
2728
|
+
outputLimit: p.number().int().min(0).max(J).default(Q).describe(
|
|
2729
|
+
`Maximum output characters. Output exceeding this limit will be truncated. Maximum: ${J}. Default: ${Q}`
|
|
2653
2730
|
),
|
|
2654
2731
|
dryRun: p.boolean().optional().describe(
|
|
2655
2732
|
"Preview changes without writing files. When true, shows what would be replaced but does not modify files"
|
|
2656
2733
|
)
|
|
2657
2734
|
});
|
|
2658
|
-
async function
|
|
2735
|
+
async function Ts(t, r, s) {
|
|
2659
2736
|
let o;
|
|
2660
2737
|
try {
|
|
2661
|
-
o =
|
|
2662
|
-
} catch (
|
|
2738
|
+
o = vt.parse(t);
|
|
2739
|
+
} catch (I) {
|
|
2663
2740
|
return {
|
|
2664
|
-
error:
|
|
2741
|
+
error: F(I)
|
|
2665
2742
|
};
|
|
2666
2743
|
}
|
|
2667
2744
|
const { snapshotName: e, snapshot: n, operations: a, outputLimit: i, dryRun: c } = o;
|
|
@@ -2669,55 +2746,58 @@ async function ps(r, t, s) {
|
|
|
2669
2746
|
return {
|
|
2670
2747
|
error: "Session ID is required"
|
|
2671
2748
|
};
|
|
2672
|
-
const l =
|
|
2749
|
+
const l = X(s.sessionId);
|
|
2673
2750
|
if (e && n)
|
|
2674
2751
|
return {
|
|
2675
2752
|
error: "Either snapshotName or snapshot must be provided, not both"
|
|
2676
2753
|
};
|
|
2677
|
-
let u,
|
|
2754
|
+
let u, f = !1, d = !1;
|
|
2678
2755
|
if (e) {
|
|
2679
2756
|
if (u = l.fsSnapshots.get(e), u == null)
|
|
2680
2757
|
return {
|
|
2681
2758
|
error: `Filesystem snapshot "${e}" not found`
|
|
2682
2759
|
};
|
|
2683
2760
|
} else if (n) {
|
|
2684
|
-
const
|
|
2761
|
+
const I = await ce(
|
|
2685
2762
|
n,
|
|
2686
|
-
|
|
2763
|
+
r,
|
|
2687
2764
|
s
|
|
2688
2765
|
);
|
|
2689
|
-
if (
|
|
2766
|
+
if (I.error != null)
|
|
2690
2767
|
return {
|
|
2691
|
-
error:
|
|
2768
|
+
error: I.error
|
|
2692
2769
|
};
|
|
2693
|
-
u =
|
|
2770
|
+
u = I.fsSnapshot, f = I.queryCreated, d = !0;
|
|
2694
2771
|
} else
|
|
2695
2772
|
return {
|
|
2696
2773
|
error: "Either snapshotName or snapshot must be provided"
|
|
2697
2774
|
};
|
|
2698
|
-
const h =
|
|
2775
|
+
const h = It(u), g = u.query.rootDir ?? ".", m = await Tt({
|
|
2699
2776
|
filePaths: h,
|
|
2700
2777
|
operations: a,
|
|
2701
2778
|
dryRun: c
|
|
2779
|
+
}), y = Ct({
|
|
2780
|
+
result: m,
|
|
2781
|
+
rootDir: g
|
|
2702
2782
|
});
|
|
2703
|
-
return { output:
|
|
2704
|
-
|
|
2705
|
-
|
|
2706
|
-
|
|
2707
|
-
}), rootDir:
|
|
2708
|
-
}
|
|
2709
|
-
function
|
|
2710
|
-
|
|
2783
|
+
return { output: we({
|
|
2784
|
+
sessionId: s.sessionId,
|
|
2785
|
+
source: y,
|
|
2786
|
+
limit: i
|
|
2787
|
+
}).content, rootDir: g, fsSnapshot: u, queryCreated: f, snapshotCreated: d };
|
|
2788
|
+
}
|
|
2789
|
+
function Cs(t, r) {
|
|
2790
|
+
t(
|
|
2711
2791
|
"fs-snapshot-replace",
|
|
2712
2792
|
{
|
|
2713
2793
|
title: "Replace File Contents in Snapshot",
|
|
2714
2794
|
description: "Replace file contents using JS RegExp. Use this to perform bulk replacements across snapshot files. Combine all patterns into the `operations` array within one tool call; never split patterns across multiple tool calls",
|
|
2715
|
-
inputSchema:
|
|
2795
|
+
inputSchema: vt.shape
|
|
2716
2796
|
},
|
|
2717
2797
|
async (s, o) => {
|
|
2718
|
-
const e = await
|
|
2798
|
+
const e = await Ts(
|
|
2719
2799
|
s,
|
|
2720
|
-
|
|
2800
|
+
r,
|
|
2721
2801
|
o
|
|
2722
2802
|
);
|
|
2723
2803
|
if (e.error != null)
|
|
@@ -2734,21 +2814,21 @@ ${e.output}`, n += "\n\nReminder: combine all patterns into one `operations` arr
|
|
|
2734
2814
|
}
|
|
2735
2815
|
);
|
|
2736
2816
|
}
|
|
2737
|
-
function
|
|
2738
|
-
|
|
2817
|
+
function Ns(t, r) {
|
|
2818
|
+
r.list && jr(t, r), r.snapshotQueryCreate && Wr(t, r), r.snapshotCreate && ts(t, r), r.snapshotBrowse && is(t, r), r.snapshotSearch && Is(t, r), r.snapshotReplace && Cs(t, r), console.log(
|
|
2739
2819
|
`File manager:
|
|
2740
|
-
- Working directory: ${
|
|
2820
|
+
- Working directory: ${R.resolve(r.workingDir || "")}
|
|
2741
2821
|
`
|
|
2742
2822
|
);
|
|
2743
2823
|
}
|
|
2744
|
-
const
|
|
2745
|
-
function j(
|
|
2746
|
-
return
|
|
2824
|
+
const he = /* @__PURE__ */ new Map();
|
|
2825
|
+
function j(t) {
|
|
2826
|
+
return he.has(t) || he.set(t, {
|
|
2747
2827
|
browsers: /* @__PURE__ */ new Map(),
|
|
2748
2828
|
domSnapshotQueries: /* @__PURE__ */ new Map()
|
|
2749
|
-
}),
|
|
2829
|
+
}), he.get(t);
|
|
2750
2830
|
}
|
|
2751
|
-
const
|
|
2831
|
+
const xe = p.object({
|
|
2752
2832
|
name: p.string().describe(
|
|
2753
2833
|
"Unique name for the browser. Recommended format: kebab-case-1, kebab-case-2, ..."
|
|
2754
2834
|
),
|
|
@@ -2756,13 +2836,13 @@ const Se = p.object({
|
|
|
2756
2836
|
muteAudio: p.boolean().optional().describe("Mute audio in the browser"),
|
|
2757
2837
|
devTools: p.boolean().optional().describe("Open browser with dev tools")
|
|
2758
2838
|
});
|
|
2759
|
-
async function
|
|
2839
|
+
async function Et(t, r, s) {
|
|
2760
2840
|
let o;
|
|
2761
2841
|
try {
|
|
2762
|
-
o =
|
|
2842
|
+
o = xe.parse(t);
|
|
2763
2843
|
} catch (l) {
|
|
2764
2844
|
return {
|
|
2765
|
-
error:
|
|
2845
|
+
error: F(l)
|
|
2766
2846
|
};
|
|
2767
2847
|
}
|
|
2768
2848
|
const { name: e, browserType: n, muteAudio: a, devTools: i } = o;
|
|
@@ -2773,49 +2853,49 @@ async function It(r, t, s) {
|
|
|
2773
2853
|
const c = j(s.sessionId);
|
|
2774
2854
|
try {
|
|
2775
2855
|
const u = await {
|
|
2776
|
-
chromium:
|
|
2777
|
-
firefox:
|
|
2778
|
-
webkit:
|
|
2856
|
+
chromium: tr,
|
|
2857
|
+
firefox: er,
|
|
2858
|
+
webkit: Xt
|
|
2779
2859
|
}[n].launch({
|
|
2780
2860
|
headless: !1,
|
|
2781
2861
|
devtools: i,
|
|
2782
2862
|
args: a ? ["--mute-audio"] : void 0
|
|
2783
|
-
}),
|
|
2863
|
+
}), f = {
|
|
2784
2864
|
name: e,
|
|
2785
2865
|
browserType: n,
|
|
2786
2866
|
browser: u,
|
|
2787
2867
|
contexts: /* @__PURE__ */ new Map()
|
|
2788
2868
|
};
|
|
2789
|
-
return c.browsers.set(e,
|
|
2869
|
+
return c.browsers.set(e, f), { browserInfo: f };
|
|
2790
2870
|
} catch (l) {
|
|
2791
2871
|
return {
|
|
2792
2872
|
error: `Failed to create browser: ${l instanceof Error ? l.message : "Unknown error"}`
|
|
2793
2873
|
};
|
|
2794
2874
|
}
|
|
2795
2875
|
}
|
|
2796
|
-
function
|
|
2797
|
-
|
|
2876
|
+
function vs(t, r) {
|
|
2877
|
+
t(
|
|
2798
2878
|
"playwright-browser-create",
|
|
2799
2879
|
{
|
|
2800
2880
|
title: "Create Browser",
|
|
2801
2881
|
description: "Create a new browser. Prefer page-goto if you need to immediately create a browser, context, page and navigate",
|
|
2802
|
-
inputSchema:
|
|
2882
|
+
inputSchema: xe.shape
|
|
2803
2883
|
},
|
|
2804
2884
|
async (s, o) => {
|
|
2805
|
-
const e = await
|
|
2885
|
+
const e = await Et(s, r, o);
|
|
2806
2886
|
return `Method: playwright-browser-create(${JSON.stringify(s)})
|
|
2807
2887
|
${e.error != null ? `❌ Error: ${e.error}` : `✅ Browser "${e.browserInfo.name}" (${e.browserInfo.browserType}) created successfully`}`;
|
|
2808
2888
|
}
|
|
2809
2889
|
);
|
|
2810
2890
|
}
|
|
2811
|
-
const
|
|
2812
|
-
async function
|
|
2891
|
+
const kt = p.object({});
|
|
2892
|
+
async function Es(t, r, s) {
|
|
2813
2893
|
let o;
|
|
2814
2894
|
try {
|
|
2815
|
-
o =
|
|
2895
|
+
o = kt.parse(t);
|
|
2816
2896
|
} catch (a) {
|
|
2817
2897
|
return {
|
|
2818
|
-
error:
|
|
2898
|
+
error: F(a)
|
|
2819
2899
|
};
|
|
2820
2900
|
}
|
|
2821
2901
|
if (!s.sessionId)
|
|
@@ -2827,16 +2907,16 @@ async function ys(r, t, s) {
|
|
|
2827
2907
|
browserInfos: Array.from(e.browsers.values())
|
|
2828
2908
|
};
|
|
2829
2909
|
}
|
|
2830
|
-
function
|
|
2831
|
-
|
|
2910
|
+
function ks(t, r) {
|
|
2911
|
+
t(
|
|
2832
2912
|
"playwright-browser-list",
|
|
2833
2913
|
{
|
|
2834
2914
|
title: "List Browsers",
|
|
2835
2915
|
description: "List active browser instances",
|
|
2836
|
-
inputSchema:
|
|
2916
|
+
inputSchema: kt.shape
|
|
2837
2917
|
},
|
|
2838
2918
|
async (s, o) => {
|
|
2839
|
-
const e = await
|
|
2919
|
+
const e = await Es(s, r, o);
|
|
2840
2920
|
if (e.error != null)
|
|
2841
2921
|
return `Method: playwright-browser-list(${JSON.stringify(s)})
|
|
2842
2922
|
❌ Error: ${e.error}`;
|
|
@@ -2848,18 +2928,18 @@ ${n.length === 0 ? "No browsers found" : `Browsers: ${n.join(", ")}`}`;
|
|
|
2848
2928
|
}
|
|
2849
2929
|
);
|
|
2850
2930
|
}
|
|
2851
|
-
const
|
|
2931
|
+
const Ot = p.object({
|
|
2852
2932
|
names: p.array(p.string()).optional().describe(
|
|
2853
2933
|
"Names of browsers to close. If not specified, closes all browsers"
|
|
2854
2934
|
)
|
|
2855
2935
|
});
|
|
2856
|
-
async function
|
|
2936
|
+
async function Os(t, r, s) {
|
|
2857
2937
|
let o;
|
|
2858
2938
|
try {
|
|
2859
|
-
o =
|
|
2939
|
+
o = Ot.parse(t);
|
|
2860
2940
|
} catch (l) {
|
|
2861
2941
|
return {
|
|
2862
|
-
error:
|
|
2942
|
+
error: F(l)
|
|
2863
2943
|
};
|
|
2864
2944
|
}
|
|
2865
2945
|
const { names: e } = o;
|
|
@@ -2887,16 +2967,16 @@ async function Ss(r, t, s) {
|
|
|
2887
2967
|
...i.length > 0 && { errors: i }
|
|
2888
2968
|
};
|
|
2889
2969
|
}
|
|
2890
|
-
function
|
|
2891
|
-
|
|
2970
|
+
function Ds(t, r) {
|
|
2971
|
+
t(
|
|
2892
2972
|
"playwright-browser-close",
|
|
2893
2973
|
{
|
|
2894
2974
|
title: "Close Browsers",
|
|
2895
2975
|
description: "Close browsers. Automatically closes all contexts and pages within the browsers",
|
|
2896
|
-
inputSchema:
|
|
2976
|
+
inputSchema: Ot.shape
|
|
2897
2977
|
},
|
|
2898
2978
|
async (s, o) => {
|
|
2899
|
-
const e = await
|
|
2979
|
+
const e = await Os(s, r, o);
|
|
2900
2980
|
if (e.error != null)
|
|
2901
2981
|
return `Method: playwright-browser-close(${JSON.stringify(s)})
|
|
2902
2982
|
❌ Error: ${e.error}`;
|
|
@@ -2913,9 +2993,9 @@ ${n.join(`
|
|
|
2913
2993
|
}
|
|
2914
2994
|
);
|
|
2915
2995
|
}
|
|
2916
|
-
const
|
|
2996
|
+
const $e = p.object({
|
|
2917
2997
|
browserName: p.string().optional().describe("Name of previously created browser, to use"),
|
|
2918
|
-
browser:
|
|
2998
|
+
browser: xe.optional().describe(
|
|
2919
2999
|
"Browser creation options JSON to automatically create browser"
|
|
2920
3000
|
),
|
|
2921
3001
|
name: p.string().describe(
|
|
@@ -2928,13 +3008,13 @@ const xe = p.object({
|
|
|
2928
3008
|
height: p.number()
|
|
2929
3009
|
}).optional().describe("Viewport size configuration")
|
|
2930
3010
|
});
|
|
2931
|
-
async function
|
|
3011
|
+
async function Dt(t, r, s) {
|
|
2932
3012
|
let o;
|
|
2933
3013
|
try {
|
|
2934
|
-
o =
|
|
3014
|
+
o = $e.parse(t);
|
|
2935
3015
|
} catch (h) {
|
|
2936
3016
|
return {
|
|
2937
|
-
error:
|
|
3017
|
+
error: F(h)
|
|
2938
3018
|
};
|
|
2939
3019
|
}
|
|
2940
3020
|
const { name: e, browserName: n, browser: a, isMobile: i, hasTouch: c, viewport: l } = o;
|
|
@@ -2947,55 +3027,55 @@ async function Ct(r, t, s) {
|
|
|
2947
3027
|
return {
|
|
2948
3028
|
error: "Either browserName or browser must be provided, not both"
|
|
2949
3029
|
};
|
|
2950
|
-
let
|
|
3030
|
+
let f = !1, d;
|
|
2951
3031
|
if (n) {
|
|
2952
|
-
if (
|
|
3032
|
+
if (d = u.browsers.get(n), !d)
|
|
2953
3033
|
return {
|
|
2954
3034
|
error: `Browser "${n}" not found`
|
|
2955
3035
|
};
|
|
2956
3036
|
} else if (a) {
|
|
2957
|
-
const h = await
|
|
3037
|
+
const h = await Et(a, r, s);
|
|
2958
3038
|
if (h.error != null)
|
|
2959
3039
|
return {
|
|
2960
3040
|
error: h.error
|
|
2961
3041
|
};
|
|
2962
|
-
|
|
3042
|
+
d = h.browserInfo, f = !0;
|
|
2963
3043
|
} else
|
|
2964
3044
|
return {
|
|
2965
3045
|
error: "Either browserName or browser must be provided"
|
|
2966
3046
|
};
|
|
2967
3047
|
try {
|
|
2968
|
-
const h = await
|
|
3048
|
+
const h = await d.browser.newContext({
|
|
2969
3049
|
isMobile: i,
|
|
2970
3050
|
hasTouch: c,
|
|
2971
3051
|
viewport: l
|
|
2972
|
-
}),
|
|
2973
|
-
browserInfo:
|
|
3052
|
+
}), g = {
|
|
3053
|
+
browserInfo: d,
|
|
2974
3054
|
name: e,
|
|
2975
3055
|
context: h,
|
|
2976
3056
|
pages: /* @__PURE__ */ new Map()
|
|
2977
3057
|
};
|
|
2978
|
-
return
|
|
2979
|
-
browserInfoCreated:
|
|
2980
|
-
browserInfo:
|
|
2981
|
-
contextInfo:
|
|
3058
|
+
return d.contexts.set(e, g), {
|
|
3059
|
+
browserInfoCreated: f,
|
|
3060
|
+
browserInfo: d,
|
|
3061
|
+
contextInfo: g
|
|
2982
3062
|
};
|
|
2983
3063
|
} catch (h) {
|
|
2984
3064
|
return {
|
|
2985
|
-
error: `Failed to create context: ${h instanceof Error ? h.message : "Unknown error"} in browser "${
|
|
3065
|
+
error: `Failed to create context: ${h instanceof Error ? h.message : "Unknown error"} in browser "${d.name}" (${d.browserType})`
|
|
2986
3066
|
};
|
|
2987
3067
|
}
|
|
2988
3068
|
}
|
|
2989
|
-
function
|
|
2990
|
-
|
|
3069
|
+
function Rs(t, r) {
|
|
3070
|
+
t(
|
|
2991
3071
|
"playwright-context-create",
|
|
2992
3072
|
{
|
|
2993
3073
|
title: "Create Browser Context",
|
|
2994
3074
|
description: "Create a new browser context. Prefer page-goto if you need to immediately create a context, page and navigate",
|
|
2995
|
-
inputSchema:
|
|
3075
|
+
inputSchema: $e.shape
|
|
2996
3076
|
},
|
|
2997
3077
|
async (s, o) => {
|
|
2998
|
-
const e = await
|
|
3078
|
+
const e = await Dt(s, r, o);
|
|
2999
3079
|
if (e.error != null)
|
|
3000
3080
|
return `Method: playwright-context-create(${JSON.stringify(s)})
|
|
3001
3081
|
❌ Error: ${e.error}`;
|
|
@@ -3006,18 +3086,18 @@ function $s(r, t) {
|
|
|
3006
3086
|
}
|
|
3007
3087
|
);
|
|
3008
3088
|
}
|
|
3009
|
-
const
|
|
3089
|
+
const Rt = p.object({
|
|
3010
3090
|
browserName: p.string().optional().describe(
|
|
3011
3091
|
"Name of browser to list contexts from. If not specified, lists contexts from all browsers"
|
|
3012
3092
|
)
|
|
3013
3093
|
});
|
|
3014
|
-
async function
|
|
3094
|
+
async function Fs(t, r, s) {
|
|
3015
3095
|
let o;
|
|
3016
3096
|
try {
|
|
3017
|
-
o =
|
|
3097
|
+
o = Rt.parse(t);
|
|
3018
3098
|
} catch (i) {
|
|
3019
3099
|
return {
|
|
3020
|
-
error:
|
|
3100
|
+
error: F(i)
|
|
3021
3101
|
};
|
|
3022
3102
|
}
|
|
3023
3103
|
const { browserName: e } = o;
|
|
@@ -3048,16 +3128,16 @@ async function Is(r, t, s) {
|
|
|
3048
3128
|
contextsByBrowser: a
|
|
3049
3129
|
};
|
|
3050
3130
|
}
|
|
3051
|
-
function
|
|
3052
|
-
|
|
3131
|
+
function Bs(t, r) {
|
|
3132
|
+
t(
|
|
3053
3133
|
"playwright-context-list",
|
|
3054
3134
|
{
|
|
3055
3135
|
title: "List Browser Contexts",
|
|
3056
3136
|
description: "List active browser contexts",
|
|
3057
|
-
inputSchema:
|
|
3137
|
+
inputSchema: Rt.shape
|
|
3058
3138
|
},
|
|
3059
3139
|
async (s, o) => {
|
|
3060
|
-
const e = await
|
|
3140
|
+
const e = await Fs(s, r, o);
|
|
3061
3141
|
if ("error" in e)
|
|
3062
3142
|
return `Method: playwright-context-list(${JSON.stringify(s)})
|
|
3063
3143
|
❌ Error: ${e.error}`;
|
|
@@ -3070,7 +3150,7 @@ function Ms(r, t) {
|
|
|
3070
3150
|
}
|
|
3071
3151
|
);
|
|
3072
3152
|
}
|
|
3073
|
-
const
|
|
3153
|
+
const Ft = p.object({
|
|
3074
3154
|
names: p.array(p.string()).optional().describe(
|
|
3075
3155
|
"Names of contexts to close. If not specified, closes all contexts"
|
|
3076
3156
|
),
|
|
@@ -3078,13 +3158,13 @@ const Nt = p.object({
|
|
|
3078
3158
|
"Name of browser to close contexts from. If not specified, searches all browsers"
|
|
3079
3159
|
)
|
|
3080
3160
|
});
|
|
3081
|
-
async function
|
|
3161
|
+
async function Ls(t, r, s) {
|
|
3082
3162
|
let o;
|
|
3083
3163
|
try {
|
|
3084
|
-
o =
|
|
3164
|
+
o = Ft.parse(t);
|
|
3085
3165
|
} catch (u) {
|
|
3086
3166
|
return {
|
|
3087
|
-
error:
|
|
3167
|
+
error: F(u)
|
|
3088
3168
|
};
|
|
3089
3169
|
}
|
|
3090
3170
|
const { names: e, browserName: n } = o;
|
|
@@ -3100,18 +3180,18 @@ async function Ts(r, t, s) {
|
|
|
3100
3180
|
return {
|
|
3101
3181
|
error: `Browser "${n}" not found`
|
|
3102
3182
|
};
|
|
3103
|
-
e ? e.forEach((
|
|
3104
|
-
const
|
|
3105
|
-
|
|
3106
|
-
`Context "${
|
|
3183
|
+
e ? e.forEach((f) => {
|
|
3184
|
+
const d = u.contexts.get(f);
|
|
3185
|
+
d ? l.push(d) : c.push(
|
|
3186
|
+
`Context "${f}" not found in browser "${u.name}" (${u.browserType})`
|
|
3107
3187
|
);
|
|
3108
3188
|
}) : l = Array.from(u.contexts.values());
|
|
3109
3189
|
} else if (e)
|
|
3110
3190
|
for (const u of a.browsers.values())
|
|
3111
|
-
e.forEach((
|
|
3112
|
-
const
|
|
3113
|
-
|
|
3114
|
-
`Context "${
|
|
3191
|
+
e.forEach((f) => {
|
|
3192
|
+
const d = u.contexts.get(f);
|
|
3193
|
+
d ? l.push(d) : c.push(
|
|
3194
|
+
`Context "${f}" not found in browser "${u.name}" (${u.browserType})`
|
|
3115
3195
|
);
|
|
3116
3196
|
});
|
|
3117
3197
|
else
|
|
@@ -3121,9 +3201,9 @@ async function Ts(r, t, s) {
|
|
|
3121
3201
|
l.map(async (u) => {
|
|
3122
3202
|
try {
|
|
3123
3203
|
await u.context.close(), u.browserInfo.contexts.delete(u.name), i.push(u);
|
|
3124
|
-
} catch (
|
|
3204
|
+
} catch (f) {
|
|
3125
3205
|
c.push(
|
|
3126
|
-
`Failed to close context "${u.name}" (${u.browserInfo.name}) (${u.browserInfo.browserType}): ${
|
|
3206
|
+
`Failed to close context "${u.name}" (${u.browserInfo.name}) (${u.browserInfo.browserType}): ${f instanceof Error ? f.message : "Unknown error"}`
|
|
3127
3207
|
);
|
|
3128
3208
|
}
|
|
3129
3209
|
})
|
|
@@ -3132,16 +3212,16 @@ async function Ts(r, t, s) {
|
|
|
3132
3212
|
...c.length > 0 && { errors: c }
|
|
3133
3213
|
};
|
|
3134
3214
|
}
|
|
3135
|
-
function
|
|
3136
|
-
|
|
3215
|
+
function Ps(t, r) {
|
|
3216
|
+
t(
|
|
3137
3217
|
"playwright-context-close",
|
|
3138
3218
|
{
|
|
3139
3219
|
title: "Close Browser Contexts",
|
|
3140
3220
|
description: "Close browser contexts. Automatically closes all pages within the contexts",
|
|
3141
|
-
inputSchema:
|
|
3221
|
+
inputSchema: Ft.shape
|
|
3142
3222
|
},
|
|
3143
3223
|
async (s, o) => {
|
|
3144
|
-
const e = await
|
|
3224
|
+
const e = await Ls(s, r, o);
|
|
3145
3225
|
if ("error" in e)
|
|
3146
3226
|
return `Method: playwright-context-close(${JSON.stringify(s)})
|
|
3147
3227
|
❌ Error: ${e.error}`;
|
|
@@ -3158,8 +3238,8 @@ ${n.join(`
|
|
|
3158
3238
|
}
|
|
3159
3239
|
);
|
|
3160
3240
|
}
|
|
3161
|
-
function
|
|
3162
|
-
class
|
|
3241
|
+
function As() {
|
|
3242
|
+
class t {
|
|
3163
3243
|
prevId = 0;
|
|
3164
3244
|
objectToId = /* @__PURE__ */ new WeakMap();
|
|
3165
3245
|
idToObject = /* @__PURE__ */ new Map();
|
|
@@ -3181,60 +3261,60 @@ function vs() {
|
|
|
3181
3261
|
return u ?? (this.idToObject.delete(c), null);
|
|
3182
3262
|
}
|
|
3183
3263
|
}
|
|
3184
|
-
function
|
|
3264
|
+
function r(i, c, l) {
|
|
3185
3265
|
let u = null;
|
|
3186
|
-
for (let
|
|
3187
|
-
const h = c[
|
|
3266
|
+
for (let f = 0, d = c.length; f < d; f++) {
|
|
3267
|
+
const h = c[f], g = i(h), m = g == null ? null : r(i, g, l), y = l(h, m);
|
|
3188
3268
|
y != null && (u == null && (u = []), u.push(y));
|
|
3189
3269
|
}
|
|
3190
3270
|
return u;
|
|
3191
3271
|
}
|
|
3192
3272
|
function s(i) {
|
|
3193
|
-
const { getId: c, getChilds: l, rootNodes: u, createSnapshotNode:
|
|
3273
|
+
const { getId: c, getChilds: l, rootNodes: u, createSnapshotNode: f } = i, d = /* @__PURE__ */ new Map(), h = /* @__PURE__ */ new Map(), g = /* @__PURE__ */ new Map(), m = r(
|
|
3194
3274
|
l,
|
|
3195
3275
|
u,
|
|
3196
|
-
(w,
|
|
3197
|
-
const
|
|
3198
|
-
if (w != null &&
|
|
3276
|
+
(w, I) => {
|
|
3277
|
+
const v = f(w, I);
|
|
3278
|
+
if (w != null && v != null) {
|
|
3199
3279
|
const b = c(w);
|
|
3200
|
-
|
|
3280
|
+
d.set(b, v), h.set(v, b);
|
|
3201
3281
|
}
|
|
3202
|
-
return
|
|
3203
|
-
h.get(
|
|
3204
|
-
|
|
3205
|
-
),
|
|
3282
|
+
return v != null && I != null && g.set(
|
|
3283
|
+
h.get(v),
|
|
3284
|
+
I.map((b) => h.get(b))
|
|
3285
|
+
), v;
|
|
3206
3286
|
}
|
|
3207
|
-
), y =
|
|
3287
|
+
), y = f(null, m);
|
|
3208
3288
|
if (y == null)
|
|
3209
3289
|
throw new Error("Impossible behavior: rootNode == null");
|
|
3210
|
-
return
|
|
3290
|
+
return d.set(null, y), m != null && g.set(
|
|
3211
3291
|
null,
|
|
3212
|
-
|
|
3292
|
+
m.map((w) => h.get(w))
|
|
3213
3293
|
), {
|
|
3214
|
-
idToNode:
|
|
3215
|
-
idToChildIds:
|
|
3294
|
+
idToNode: d,
|
|
3295
|
+
idToChildIds: g
|
|
3216
3296
|
};
|
|
3217
3297
|
}
|
|
3218
3298
|
const o = (i) => i instanceof HTMLElement ? i.childNodes : null;
|
|
3219
3299
|
function e(i) {
|
|
3220
3300
|
return function(l, u) {
|
|
3221
|
-
const
|
|
3222
|
-
let
|
|
3301
|
+
const f = u != null && u.length > 0;
|
|
3302
|
+
let d = !1, h = null, g = null;
|
|
3223
3303
|
if (l instanceof HTMLElement) {
|
|
3224
|
-
if (h = n.getOrCreateId(l),
|
|
3304
|
+
if (h = n.getOrCreateId(l), g = l.tagName.toLowerCase(), d = l.matches(i.cssSelector), !d && !f)
|
|
3225
3305
|
return null;
|
|
3226
3306
|
} else if (l == null)
|
|
3227
|
-
h = null,
|
|
3307
|
+
h = null, g = null, d = !1;
|
|
3228
3308
|
else
|
|
3229
3309
|
return null;
|
|
3230
3310
|
return {
|
|
3231
3311
|
uid: h,
|
|
3232
|
-
tagName:
|
|
3233
|
-
isMatched:
|
|
3312
|
+
tagName: g,
|
|
3313
|
+
isMatched: d
|
|
3234
3314
|
};
|
|
3235
3315
|
};
|
|
3236
3316
|
}
|
|
3237
|
-
const n = new
|
|
3317
|
+
const n = new t();
|
|
3238
3318
|
function a(i) {
|
|
3239
3319
|
const c = e(i);
|
|
3240
3320
|
return s({
|
|
@@ -3246,22 +3326,22 @@ function vs() {
|
|
|
3246
3326
|
}
|
|
3247
3327
|
window.__mcp_playwright_tool_tx4byhar35_createDomSnapshotTreeRawDom = a;
|
|
3248
3328
|
}
|
|
3249
|
-
const
|
|
3329
|
+
const zs = `(function (){function __name(fn){return fn};${As.toString()}; setupPageGlobals();})()`, Ie = p.object({
|
|
3250
3330
|
contextName: p.string().optional().describe("Name of previously created context, to use"),
|
|
3251
|
-
context:
|
|
3331
|
+
context: $e.optional().describe(
|
|
3252
3332
|
"Context creation options JSON to automatically create context"
|
|
3253
3333
|
),
|
|
3254
3334
|
name: p.string().describe(
|
|
3255
3335
|
"Unique name for the page. Recommended format: kebab-case-1, kebab-case-2, ..."
|
|
3256
3336
|
)
|
|
3257
3337
|
});
|
|
3258
|
-
async function
|
|
3338
|
+
async function Bt(t, r, s) {
|
|
3259
3339
|
let o;
|
|
3260
3340
|
try {
|
|
3261
|
-
o =
|
|
3262
|
-
} catch (
|
|
3341
|
+
o = Ie.parse(t);
|
|
3342
|
+
} catch (f) {
|
|
3263
3343
|
return {
|
|
3264
|
-
error:
|
|
3344
|
+
error: F(f)
|
|
3265
3345
|
};
|
|
3266
3346
|
}
|
|
3267
3347
|
const { name: e, contextName: n, context: a } = o;
|
|
@@ -3276,9 +3356,9 @@ async function Et(r, t, s) {
|
|
|
3276
3356
|
};
|
|
3277
3357
|
let c = !1, l = !1, u;
|
|
3278
3358
|
if (n) {
|
|
3279
|
-
for (const
|
|
3280
|
-
if (
|
|
3281
|
-
u =
|
|
3359
|
+
for (const f of i.browsers.values())
|
|
3360
|
+
if (f.contexts.has(n)) {
|
|
3361
|
+
u = f.contexts.get(n);
|
|
3282
3362
|
break;
|
|
3283
3363
|
}
|
|
3284
3364
|
if (!u)
|
|
@@ -3286,46 +3366,46 @@ async function Et(r, t, s) {
|
|
|
3286
3366
|
error: `Context "${n}" not found`
|
|
3287
3367
|
};
|
|
3288
3368
|
} else if (a) {
|
|
3289
|
-
const
|
|
3290
|
-
if (
|
|
3369
|
+
const f = await Dt(a, r, s);
|
|
3370
|
+
if (f.error != null)
|
|
3291
3371
|
return {
|
|
3292
|
-
error:
|
|
3372
|
+
error: f.error
|
|
3293
3373
|
};
|
|
3294
|
-
u =
|
|
3374
|
+
u = f.contextInfo, c = f.browserInfoCreated, l = !0;
|
|
3295
3375
|
} else
|
|
3296
3376
|
return {
|
|
3297
3377
|
error: "Either contextName or context must be provided"
|
|
3298
3378
|
};
|
|
3299
3379
|
try {
|
|
3300
|
-
const
|
|
3301
|
-
await
|
|
3302
|
-
const
|
|
3380
|
+
const f = await u.context.newPage();
|
|
3381
|
+
await f.addInitScript(zs), await f.goto("about:blank");
|
|
3382
|
+
const d = {
|
|
3303
3383
|
contextInfo: u,
|
|
3304
3384
|
name: e,
|
|
3305
|
-
page:
|
|
3385
|
+
page: f,
|
|
3306
3386
|
domSnapshots: /* @__PURE__ */ new Map()
|
|
3307
3387
|
};
|
|
3308
|
-
return u.pages.set(e,
|
|
3388
|
+
return u.pages.set(e, d), {
|
|
3309
3389
|
browserInfoCreated: c,
|
|
3310
3390
|
contextInfoCreated: l,
|
|
3311
|
-
pageInfo:
|
|
3391
|
+
pageInfo: d
|
|
3312
3392
|
};
|
|
3313
|
-
} catch (
|
|
3393
|
+
} catch (f) {
|
|
3314
3394
|
return {
|
|
3315
|
-
error: `Failed to create page: ${
|
|
3395
|
+
error: `Failed to create page: ${f instanceof Error ? f.message : "Unknown error"} in context "${u.name}" in browser "${u.browserInfo.name}" (${u.browserInfo.browserType})`
|
|
3316
3396
|
};
|
|
3317
3397
|
}
|
|
3318
3398
|
}
|
|
3319
|
-
function
|
|
3320
|
-
|
|
3399
|
+
function Us(t, r) {
|
|
3400
|
+
t(
|
|
3321
3401
|
"playwright-page-create",
|
|
3322
3402
|
{
|
|
3323
3403
|
title: "Create Page",
|
|
3324
3404
|
description: "Create a new page. Prefer page-goto if you need to immediately create a page and navigate",
|
|
3325
|
-
inputSchema:
|
|
3405
|
+
inputSchema: Ie.shape
|
|
3326
3406
|
},
|
|
3327
3407
|
async (s, o) => {
|
|
3328
|
-
const e = await
|
|
3408
|
+
const e = await Bt(s, r, o);
|
|
3329
3409
|
if (e.error != null)
|
|
3330
3410
|
return `Method: playwright-page-create(${JSON.stringify(s)})
|
|
3331
3411
|
❌ Error: ${e.error}`;
|
|
@@ -3337,7 +3417,7 @@ function Es(r, t) {
|
|
|
3337
3417
|
}
|
|
3338
3418
|
);
|
|
3339
3419
|
}
|
|
3340
|
-
const
|
|
3420
|
+
const Lt = p.object({
|
|
3341
3421
|
contextName: p.string().optional().describe(
|
|
3342
3422
|
"Name of context to list pages from. If not specified, lists pages from all contexts"
|
|
3343
3423
|
),
|
|
@@ -3345,13 +3425,13 @@ const kt = p.object({
|
|
|
3345
3425
|
"Name of browser to search in. If not specified, searches all browsers"
|
|
3346
3426
|
)
|
|
3347
3427
|
});
|
|
3348
|
-
async function
|
|
3428
|
+
async function qs(t, r, s) {
|
|
3349
3429
|
let o;
|
|
3350
3430
|
try {
|
|
3351
|
-
o =
|
|
3431
|
+
o = Lt.parse(t);
|
|
3352
3432
|
} catch (c) {
|
|
3353
3433
|
return {
|
|
3354
|
-
error:
|
|
3434
|
+
error: F(c)
|
|
3355
3435
|
};
|
|
3356
3436
|
}
|
|
3357
3437
|
const { contextName: e, browserName: n } = o;
|
|
@@ -3409,16 +3489,16 @@ async function ks(r, t, s) {
|
|
|
3409
3489
|
pagesByContext: i
|
|
3410
3490
|
};
|
|
3411
3491
|
}
|
|
3412
|
-
function
|
|
3413
|
-
|
|
3492
|
+
function _s(t, r) {
|
|
3493
|
+
t(
|
|
3414
3494
|
"playwright-page-list",
|
|
3415
3495
|
{
|
|
3416
3496
|
title: "List Pages",
|
|
3417
3497
|
description: "List active pages",
|
|
3418
|
-
inputSchema:
|
|
3498
|
+
inputSchema: Lt.shape
|
|
3419
3499
|
},
|
|
3420
3500
|
async (s, o) => {
|
|
3421
|
-
const e = await
|
|
3501
|
+
const e = await qs(s, r, o);
|
|
3422
3502
|
if ("error" in e)
|
|
3423
3503
|
return `Method: playwright-page-list(${JSON.stringify(s)})
|
|
3424
3504
|
❌ Error: ${e.error}`;
|
|
@@ -3431,7 +3511,7 @@ function Os(r, t) {
|
|
|
3431
3511
|
}
|
|
3432
3512
|
);
|
|
3433
3513
|
}
|
|
3434
|
-
const
|
|
3514
|
+
const Pt = p.object({
|
|
3435
3515
|
names: p.array(p.string()).optional().describe("Names of pages to close. If not specified, closes all pages"),
|
|
3436
3516
|
contextName: p.string().optional().describe(
|
|
3437
3517
|
"Name of context to close pages from. If not specified, searches all contexts"
|
|
@@ -3440,13 +3520,13 @@ const Ot = p.object({
|
|
|
3440
3520
|
"Name of browser to search in. If not specified, searches all browsers"
|
|
3441
3521
|
)
|
|
3442
3522
|
});
|
|
3443
|
-
async function
|
|
3523
|
+
async function Gs(t, r, s) {
|
|
3444
3524
|
let o;
|
|
3445
3525
|
try {
|
|
3446
|
-
o =
|
|
3447
|
-
} catch (
|
|
3526
|
+
o = Pt.parse(t);
|
|
3527
|
+
} catch (f) {
|
|
3448
3528
|
return {
|
|
3449
|
-
error:
|
|
3529
|
+
error: F(f)
|
|
3450
3530
|
};
|
|
3451
3531
|
}
|
|
3452
3532
|
const { names: e, contextName: n, browserName: a } = o;
|
|
@@ -3457,59 +3537,59 @@ async function Ds(r, t, s) {
|
|
|
3457
3537
|
const i = j(s.sessionId), c = [], l = [];
|
|
3458
3538
|
let u = [];
|
|
3459
3539
|
if (a) {
|
|
3460
|
-
const
|
|
3461
|
-
if (!
|
|
3540
|
+
const f = i.browsers.get(a);
|
|
3541
|
+
if (!f)
|
|
3462
3542
|
return {
|
|
3463
3543
|
error: `Browser "${a}" not found`
|
|
3464
3544
|
};
|
|
3465
3545
|
if (n) {
|
|
3466
|
-
const
|
|
3467
|
-
if (!
|
|
3546
|
+
const d = f.contexts.get(n);
|
|
3547
|
+
if (!d)
|
|
3468
3548
|
return {
|
|
3469
|
-
error: `Context "${n}" not found in browser "${
|
|
3549
|
+
error: `Context "${n}" not found in browser "${f.name}" (${f.browserType})`
|
|
3470
3550
|
};
|
|
3471
3551
|
e ? e.forEach((h) => {
|
|
3472
|
-
const
|
|
3473
|
-
|
|
3474
|
-
`Page "${h}" not found in context "${
|
|
3552
|
+
const g = d.pages.get(h);
|
|
3553
|
+
g ? u.push(g) : l.push(
|
|
3554
|
+
`Page "${h}" not found in context "${d.name}" in browser "${f.name}" (${f.browserType})`
|
|
3475
3555
|
);
|
|
3476
|
-
}) : u = Array.from(
|
|
3556
|
+
}) : u = Array.from(d.pages.values());
|
|
3477
3557
|
} else
|
|
3478
|
-
for (const
|
|
3558
|
+
for (const d of f.contexts.values())
|
|
3479
3559
|
e ? e.forEach((h) => {
|
|
3480
|
-
const
|
|
3481
|
-
|
|
3482
|
-
`Page "${h}" not found in context "${
|
|
3560
|
+
const g = d.pages.get(h);
|
|
3561
|
+
g ? u.push(g) : l.push(
|
|
3562
|
+
`Page "${h}" not found in context "${d.name}" in browser "${f.name}" (${f.browserType})`
|
|
3483
3563
|
);
|
|
3484
|
-
}) : u.push(...Array.from(
|
|
3564
|
+
}) : u.push(...Array.from(d.pages.values()));
|
|
3485
3565
|
} else if (n)
|
|
3486
|
-
for (const
|
|
3487
|
-
const
|
|
3488
|
-
|
|
3489
|
-
const
|
|
3490
|
-
|
|
3491
|
-
`Page "${h}" not found in context "${
|
|
3566
|
+
for (const f of i.browsers.values()) {
|
|
3567
|
+
const d = f.contexts.get(n);
|
|
3568
|
+
d && (e ? e.forEach((h) => {
|
|
3569
|
+
const g = d.pages.get(h);
|
|
3570
|
+
g ? u.push(g) : l.push(
|
|
3571
|
+
`Page "${h}" not found in context "${d.name}" in browser "${f.name}" (${f.browserType})`
|
|
3492
3572
|
);
|
|
3493
|
-
}) : u.push(...Array.from(
|
|
3573
|
+
}) : u.push(...Array.from(d.pages.values())));
|
|
3494
3574
|
}
|
|
3495
3575
|
else
|
|
3496
|
-
for (const
|
|
3497
|
-
for (const
|
|
3576
|
+
for (const f of i.browsers.values())
|
|
3577
|
+
for (const d of f.contexts.values())
|
|
3498
3578
|
e ? e.forEach((h) => {
|
|
3499
|
-
const
|
|
3500
|
-
|
|
3501
|
-
`Page "${h}" not found in context "${
|
|
3579
|
+
const g = d.pages.get(h);
|
|
3580
|
+
g ? u.push(g) : l.push(
|
|
3581
|
+
`Page "${h}" not found in context "${d.name}" in browser "${f.name}" (${f.browserType})`
|
|
3502
3582
|
);
|
|
3503
|
-
}) : u.push(...Array.from(
|
|
3583
|
+
}) : u.push(...Array.from(d.pages.values()));
|
|
3504
3584
|
return await Promise.all(
|
|
3505
|
-
u.map(async (
|
|
3585
|
+
u.map(async (f) => {
|
|
3506
3586
|
try {
|
|
3507
|
-
await
|
|
3508
|
-
`${
|
|
3587
|
+
await f.page.close(), f.contextInfo.pages.delete(f.name), c.push(
|
|
3588
|
+
`${f.name} (${f.contextInfo.name}) (${f.contextInfo.browserInfo.name}) (${f.contextInfo.browserInfo.browserType})`
|
|
3509
3589
|
);
|
|
3510
|
-
} catch (
|
|
3590
|
+
} catch (d) {
|
|
3511
3591
|
l.push(
|
|
3512
|
-
`Failed to close page "${
|
|
3592
|
+
`Failed to close page "${f.name}" (${f.contextInfo.name}) (${f.contextInfo.browserInfo.name}) (${f.contextInfo.browserInfo.browserType}): ${d instanceof Error ? d.message : "Unknown error"}`
|
|
3513
3593
|
);
|
|
3514
3594
|
}
|
|
3515
3595
|
})
|
|
@@ -3518,16 +3598,16 @@ async function Ds(r, t, s) {
|
|
|
3518
3598
|
...l.length > 0 && { errors: l }
|
|
3519
3599
|
};
|
|
3520
3600
|
}
|
|
3521
|
-
function
|
|
3522
|
-
|
|
3601
|
+
function Js(t, r) {
|
|
3602
|
+
t(
|
|
3523
3603
|
"playwright-page-close",
|
|
3524
3604
|
{
|
|
3525
3605
|
title: "Close Pages",
|
|
3526
3606
|
description: "Close pages",
|
|
3527
|
-
inputSchema:
|
|
3607
|
+
inputSchema: Pt.shape
|
|
3528
3608
|
},
|
|
3529
3609
|
async (s, o) => {
|
|
3530
|
-
const e = await
|
|
3610
|
+
const e = await Gs(s, r, o);
|
|
3531
3611
|
if ("error" in e)
|
|
3532
3612
|
return `Method: playwright-page-close(${JSON.stringify(s)})
|
|
3533
3613
|
❌ Error: ${e.error}`;
|
|
@@ -3538,9 +3618,9 @@ ${n.join(`
|
|
|
3538
3618
|
}
|
|
3539
3619
|
);
|
|
3540
3620
|
}
|
|
3541
|
-
const
|
|
3621
|
+
const At = p.object({
|
|
3542
3622
|
pageName: p.string().optional().describe("Name of previously created page to navigate"),
|
|
3543
|
-
page:
|
|
3623
|
+
page: Ie.optional().describe(
|
|
3544
3624
|
"Page creation options JSON to automatically create page"
|
|
3545
3625
|
),
|
|
3546
3626
|
url: p.string().describe("URL to navigate to"),
|
|
@@ -3553,13 +3633,13 @@ const Dt = p.object({
|
|
|
3553
3633
|
- 'commit': network response received and document started loading`
|
|
3554
3634
|
)
|
|
3555
3635
|
});
|
|
3556
|
-
async function
|
|
3636
|
+
async function js(t, r, s) {
|
|
3557
3637
|
let o;
|
|
3558
3638
|
try {
|
|
3559
|
-
o =
|
|
3560
|
-
} catch (
|
|
3639
|
+
o = At.parse(t);
|
|
3640
|
+
} catch (g) {
|
|
3561
3641
|
return {
|
|
3562
|
-
error:
|
|
3642
|
+
error: F(g)
|
|
3563
3643
|
};
|
|
3564
3644
|
}
|
|
3565
3645
|
const { pageName: e, page: n, url: a, timeout: i, waitUntil: c } = o;
|
|
@@ -3572,12 +3652,12 @@ async function Fs(r, t, s) {
|
|
|
3572
3652
|
return {
|
|
3573
3653
|
error: "Either pageName or page must be provided, not both"
|
|
3574
3654
|
};
|
|
3575
|
-
let u = !1,
|
|
3655
|
+
let u = !1, f = !1, d = !1, h;
|
|
3576
3656
|
if (e) {
|
|
3577
|
-
for (const
|
|
3578
|
-
for (const
|
|
3579
|
-
if (
|
|
3580
|
-
h =
|
|
3657
|
+
for (const g of l.browsers.values()) {
|
|
3658
|
+
for (const m of g.contexts.values())
|
|
3659
|
+
if (m.pages.has(e)) {
|
|
3660
|
+
h = m.pages.get(e);
|
|
3581
3661
|
break;
|
|
3582
3662
|
}
|
|
3583
3663
|
if (h) break;
|
|
@@ -3587,50 +3667,50 @@ async function Fs(r, t, s) {
|
|
|
3587
3667
|
error: `Page "${e}" not found`
|
|
3588
3668
|
};
|
|
3589
3669
|
} else if (n) {
|
|
3590
|
-
const
|
|
3591
|
-
if (
|
|
3670
|
+
const g = await Bt(n, r, s);
|
|
3671
|
+
if (g.error != null)
|
|
3592
3672
|
return {
|
|
3593
|
-
error:
|
|
3673
|
+
error: g.error
|
|
3594
3674
|
};
|
|
3595
|
-
h =
|
|
3675
|
+
h = g.pageInfo, u = g.browserInfoCreated, f = g.contextInfoCreated, d = !0;
|
|
3596
3676
|
} else
|
|
3597
3677
|
return {
|
|
3598
3678
|
error: "Either pageName or page must be provided"
|
|
3599
3679
|
};
|
|
3600
3680
|
try {
|
|
3601
|
-
const
|
|
3681
|
+
const g = await h.page.goto(a, {
|
|
3602
3682
|
timeout: i * 1e3,
|
|
3603
3683
|
waitUntil: c
|
|
3604
3684
|
});
|
|
3605
|
-
return
|
|
3685
|
+
return g ? {
|
|
3606
3686
|
browserInfoCreated: u,
|
|
3607
|
-
contextInfoCreated:
|
|
3608
|
-
pageInfoCreated:
|
|
3687
|
+
contextInfoCreated: f,
|
|
3688
|
+
pageInfoCreated: d,
|
|
3609
3689
|
pageInfo: h,
|
|
3610
|
-
status:
|
|
3690
|
+
status: g.status()
|
|
3611
3691
|
} : {
|
|
3612
3692
|
browserInfoCreated: u,
|
|
3613
|
-
contextInfoCreated:
|
|
3614
|
-
pageInfoCreated:
|
|
3693
|
+
contextInfoCreated: f,
|
|
3694
|
+
pageInfoCreated: d,
|
|
3615
3695
|
pageInfo: h,
|
|
3616
3696
|
status: 200
|
|
3617
3697
|
};
|
|
3618
|
-
} catch (
|
|
3698
|
+
} catch (g) {
|
|
3619
3699
|
return {
|
|
3620
|
-
error: `Failed to navigate to "${a}": ${
|
|
3700
|
+
error: `Failed to navigate to "${a}": ${g instanceof Error ? g.message : "Unknown error"}`
|
|
3621
3701
|
};
|
|
3622
3702
|
}
|
|
3623
3703
|
}
|
|
3624
|
-
function
|
|
3625
|
-
|
|
3704
|
+
function Ks(t, r) {
|
|
3705
|
+
t(
|
|
3626
3706
|
"playwright-page-goto",
|
|
3627
3707
|
{
|
|
3628
3708
|
title: "Navigate Page",
|
|
3629
3709
|
description: "Navigate page to URL. Use for manual browser interaction",
|
|
3630
|
-
inputSchema:
|
|
3710
|
+
inputSchema: At.shape
|
|
3631
3711
|
},
|
|
3632
3712
|
async (s, o) => {
|
|
3633
|
-
const e = await
|
|
3713
|
+
const e = await js(s, r, o);
|
|
3634
3714
|
if (e.error != null)
|
|
3635
3715
|
return `Method: playwright-page-goto(${JSON.stringify(s)})
|
|
3636
3716
|
❌ Error: ${e.error}`;
|
|
@@ -3643,19 +3723,19 @@ function Bs(r, t) {
|
|
|
3643
3723
|
}
|
|
3644
3724
|
);
|
|
3645
3725
|
}
|
|
3646
|
-
const
|
|
3726
|
+
const Me = p.object({
|
|
3647
3727
|
name: p.string().describe(
|
|
3648
3728
|
"Unique name for the DOM snapshot query. Recommended format: kebab-case-1, kebab-case-2, ..."
|
|
3649
3729
|
),
|
|
3650
3730
|
cssSelector: p.string().describe("CSS selector to capture page content")
|
|
3651
3731
|
});
|
|
3652
|
-
async function
|
|
3732
|
+
async function zt(t, r, s) {
|
|
3653
3733
|
let o;
|
|
3654
3734
|
try {
|
|
3655
|
-
o =
|
|
3735
|
+
o = Me.parse(t);
|
|
3656
3736
|
} catch (c) {
|
|
3657
3737
|
return {
|
|
3658
|
-
error:
|
|
3738
|
+
error: F(c)
|
|
3659
3739
|
};
|
|
3660
3740
|
}
|
|
3661
3741
|
const { name: e, cssSelector: n } = o;
|
|
@@ -3671,47 +3751,47 @@ async function Rt(r, t, s) {
|
|
|
3671
3751
|
snapshotQuery: i
|
|
3672
3752
|
};
|
|
3673
3753
|
}
|
|
3674
|
-
function
|
|
3675
|
-
|
|
3754
|
+
function Ws(t, r) {
|
|
3755
|
+
t(
|
|
3676
3756
|
"playwright-dom-snapshot-query-create",
|
|
3677
3757
|
{
|
|
3678
3758
|
title: "Create DOM Snapshot Query",
|
|
3679
3759
|
description: "Create a DOM snapshot query. Prefer dom-snapshot-browse if you need to immediately create a query and snapshot and browse it",
|
|
3680
|
-
inputSchema:
|
|
3760
|
+
inputSchema: Me.shape
|
|
3681
3761
|
},
|
|
3682
3762
|
async (s, o) => {
|
|
3683
|
-
const e = await
|
|
3763
|
+
const e = await zt(s, r, o);
|
|
3684
3764
|
return e.error != null ? `Method: playwright-dom-snapshot-query-create(${JSON.stringify(s)})
|
|
3685
3765
|
❌ Error: ${e.error}` : `Method: playwright-dom-snapshot-query-create(${JSON.stringify(s)})
|
|
3686
3766
|
✅ DOM snapshot query "${e.snapshotQuery.name}" created successfully`;
|
|
3687
3767
|
}
|
|
3688
3768
|
);
|
|
3689
3769
|
}
|
|
3690
|
-
function
|
|
3770
|
+
function Hs(t) {
|
|
3691
3771
|
return function(s, o) {
|
|
3692
3772
|
let e, n = 0;
|
|
3693
3773
|
const a = o ? o.length : 0;
|
|
3694
|
-
let i = 1, c = 0, l = 0, u,
|
|
3774
|
+
let i = 1, c = 0, l = 0, u, f;
|
|
3695
3775
|
if (o)
|
|
3696
|
-
for (let
|
|
3697
|
-
const
|
|
3698
|
-
n +=
|
|
3776
|
+
for (let g = 0; g < o.length; g++) {
|
|
3777
|
+
const m = o[g];
|
|
3778
|
+
n += m.countMatched, i += m.countTotal, c += m.tokens, l += m.tokensTotal;
|
|
3699
3779
|
}
|
|
3700
|
-
s ? (u = s.uid,
|
|
3701
|
-
let
|
|
3702
|
-
|
|
3780
|
+
s ? (u = s.uid, f = s.tagName, e = s.isMatched, e && (n += 1)) : (u = null, f = null, e = !1);
|
|
3781
|
+
let d;
|
|
3782
|
+
f ? d = {
|
|
3703
3783
|
indent: !0,
|
|
3704
|
-
textOpen: `<${
|
|
3705
|
-
textClose: `</${
|
|
3706
|
-
} :
|
|
3784
|
+
textOpen: `<${f} uid:${u}>`,
|
|
3785
|
+
textClose: `</${f}>`
|
|
3786
|
+
} : d = {
|
|
3707
3787
|
indent: !0,
|
|
3708
3788
|
textOpen: `<root uid:${u}>`,
|
|
3709
3789
|
textClose: "</root>"
|
|
3710
3790
|
};
|
|
3711
|
-
const h =
|
|
3791
|
+
const h = bt(d);
|
|
3712
3792
|
return l += h, {
|
|
3713
3793
|
uid: u,
|
|
3714
|
-
tagName:
|
|
3794
|
+
tagName: f,
|
|
3715
3795
|
isMatched: e,
|
|
3716
3796
|
countMatched: n,
|
|
3717
3797
|
countChilds: a,
|
|
@@ -3719,12 +3799,12 @@ function Ps(r) {
|
|
|
3719
3799
|
tokens: h,
|
|
3720
3800
|
tokensChilds: c,
|
|
3721
3801
|
tokensTotal: l,
|
|
3722
|
-
text:
|
|
3802
|
+
text: d
|
|
3723
3803
|
};
|
|
3724
3804
|
};
|
|
3725
3805
|
}
|
|
3726
|
-
function
|
|
3727
|
-
const s =
|
|
3806
|
+
function Qs(t, r) {
|
|
3807
|
+
const s = le(r), o = s.getChilds(s.root), e = yt({
|
|
3728
3808
|
getId: (n) => {
|
|
3729
3809
|
const a = s.getId(n);
|
|
3730
3810
|
if (a == null)
|
|
@@ -3734,28 +3814,28 @@ function As(r, t) {
|
|
|
3734
3814
|
return a;
|
|
3735
3815
|
},
|
|
3736
3816
|
getChilds: (n) => s.getChilds(n),
|
|
3737
|
-
createSnapshotNode:
|
|
3817
|
+
createSnapshotNode: Hs(),
|
|
3738
3818
|
rootNodes: o ?? []
|
|
3739
3819
|
});
|
|
3740
|
-
return
|
|
3820
|
+
return le(e);
|
|
3741
3821
|
}
|
|
3742
|
-
const
|
|
3822
|
+
const Te = p.object({
|
|
3743
3823
|
pageName: p.string().describe("Name of previously created page, to create snapshot from"),
|
|
3744
3824
|
queryName: p.string().optional().describe("Name of previously created DOM snapshot query, to use"),
|
|
3745
|
-
query:
|
|
3825
|
+
query: Me.optional().describe(
|
|
3746
3826
|
"DOM snapshot query creation options JSON to automatically create query"
|
|
3747
3827
|
),
|
|
3748
3828
|
name: p.string().describe(
|
|
3749
3829
|
"Unique name for the DOM snapshot. Recommended format: kebab-case-1, kebab-case-2, ..."
|
|
3750
3830
|
)
|
|
3751
3831
|
});
|
|
3752
|
-
async function
|
|
3832
|
+
async function Ut(t, r, s) {
|
|
3753
3833
|
let o;
|
|
3754
3834
|
try {
|
|
3755
|
-
o =
|
|
3756
|
-
} catch (
|
|
3835
|
+
o = Te.parse(t);
|
|
3836
|
+
} catch (d) {
|
|
3757
3837
|
return {
|
|
3758
|
-
error:
|
|
3838
|
+
error: F(d)
|
|
3759
3839
|
};
|
|
3760
3840
|
}
|
|
3761
3841
|
const { pageName: e, queryName: n, query: a, name: i } = o;
|
|
@@ -3765,8 +3845,8 @@ async function Ft(r, t, s) {
|
|
|
3765
3845
|
};
|
|
3766
3846
|
const c = j(s.sessionId);
|
|
3767
3847
|
let l;
|
|
3768
|
-
for (const
|
|
3769
|
-
for (const h of
|
|
3848
|
+
for (const d of c.browsers.values()) {
|
|
3849
|
+
for (const h of d.contexts.values())
|
|
3770
3850
|
if (h.pages.has(e)) {
|
|
3771
3851
|
l = h.pages.get(e);
|
|
3772
3852
|
break;
|
|
@@ -3781,70 +3861,70 @@ async function Ft(r, t, s) {
|
|
|
3781
3861
|
return {
|
|
3782
3862
|
error: "Either queryName or query must be provided, not both"
|
|
3783
3863
|
};
|
|
3784
|
-
let u,
|
|
3864
|
+
let u, f = !1;
|
|
3785
3865
|
if (n) {
|
|
3786
|
-
const
|
|
3787
|
-
if (!
|
|
3866
|
+
const d = c.domSnapshotQueries.get(n);
|
|
3867
|
+
if (!d)
|
|
3788
3868
|
return {
|
|
3789
3869
|
error: `DOM snapshot query "${n}" not found`
|
|
3790
3870
|
};
|
|
3791
|
-
u =
|
|
3871
|
+
u = d;
|
|
3792
3872
|
} else if (a) {
|
|
3793
|
-
const
|
|
3873
|
+
const d = await zt(
|
|
3794
3874
|
a,
|
|
3795
|
-
|
|
3875
|
+
r,
|
|
3796
3876
|
s
|
|
3797
3877
|
);
|
|
3798
|
-
if (
|
|
3878
|
+
if (d.error != null)
|
|
3799
3879
|
return {
|
|
3800
|
-
error:
|
|
3880
|
+
error: d.error
|
|
3801
3881
|
};
|
|
3802
|
-
u =
|
|
3882
|
+
u = d.snapshotQuery, f = !0;
|
|
3803
3883
|
} else
|
|
3804
3884
|
return {
|
|
3805
3885
|
error: "Either queryName or query must be provided"
|
|
3806
3886
|
};
|
|
3807
3887
|
try {
|
|
3808
|
-
const
|
|
3888
|
+
const d = await l.page.evaluate(
|
|
3809
3889
|
(y) => {
|
|
3810
3890
|
const w = window.__mcp_playwright_tool_tx4byhar35_createDomSnapshotTreeRawDom;
|
|
3811
3891
|
if (!w)
|
|
3812
3892
|
throw new Error("DOM snapshot global function not initialized");
|
|
3813
|
-
const
|
|
3893
|
+
const I = w(y);
|
|
3814
3894
|
return {
|
|
3815
|
-
idToNode: Array.from(
|
|
3816
|
-
idToChildIds: Array.from(
|
|
3895
|
+
idToNode: Array.from(I.idToNode.entries()),
|
|
3896
|
+
idToChildIds: Array.from(I.idToChildIds.entries())
|
|
3817
3897
|
};
|
|
3818
3898
|
},
|
|
3819
3899
|
u
|
|
3820
3900
|
), h = {
|
|
3821
|
-
idToNode: new Map(
|
|
3822
|
-
idToChildIds: new Map(
|
|
3823
|
-
},
|
|
3901
|
+
idToNode: new Map(d.idToNode),
|
|
3902
|
+
idToChildIds: new Map(d.idToChildIds)
|
|
3903
|
+
}, g = Qs(u, h), m = {
|
|
3824
3904
|
name: i,
|
|
3825
3905
|
query: u,
|
|
3826
|
-
tree:
|
|
3906
|
+
tree: g
|
|
3827
3907
|
};
|
|
3828
|
-
return l.domSnapshots.set(i,
|
|
3829
|
-
domSnapshot:
|
|
3830
|
-
queryCreated:
|
|
3908
|
+
return l.domSnapshots.set(i, m), {
|
|
3909
|
+
domSnapshot: m,
|
|
3910
|
+
queryCreated: f
|
|
3831
3911
|
};
|
|
3832
|
-
} catch (
|
|
3912
|
+
} catch (d) {
|
|
3833
3913
|
return {
|
|
3834
|
-
error: `Failed to create DOM snapshot: ${
|
|
3914
|
+
error: `Failed to create DOM snapshot: ${d instanceof Error ? d.message : "Unknown error"}`
|
|
3835
3915
|
};
|
|
3836
3916
|
}
|
|
3837
3917
|
}
|
|
3838
|
-
function
|
|
3839
|
-
|
|
3918
|
+
function Ys(t, r) {
|
|
3919
|
+
t(
|
|
3840
3920
|
"playwright-dom-snapshot-create",
|
|
3841
3921
|
{
|
|
3842
3922
|
title: "Create DOM Snapshot",
|
|
3843
3923
|
description: "Create a DOM snapshot of page. Use this to capture webpage state for later browsing. Prefer dom-snapshot-browse if you need to immediately create and browse a snapshot",
|
|
3844
|
-
inputSchema:
|
|
3924
|
+
inputSchema: Te.shape
|
|
3845
3925
|
},
|
|
3846
3926
|
async (s, o) => {
|
|
3847
|
-
const e = await
|
|
3927
|
+
const e = await Ut(s, r, o);
|
|
3848
3928
|
if (e.error != null)
|
|
3849
3929
|
return `Method: playwright-dom-snapshot-create(${JSON.stringify(s)})
|
|
3850
3930
|
❌ Error: ${e.error}`;
|
|
@@ -3855,23 +3935,23 @@ function zs(r, t) {
|
|
|
3855
3935
|
}
|
|
3856
3936
|
);
|
|
3857
3937
|
}
|
|
3858
|
-
class
|
|
3938
|
+
class Vs {
|
|
3859
3939
|
tokens = 20;
|
|
3860
|
-
getReportText = (
|
|
3940
|
+
getReportText = (r) => ({
|
|
3861
3941
|
indent: !0,
|
|
3862
|
-
textOpen: `[${
|
|
3942
|
+
textOpen: `[${r.indexRange[0]}-${r.indexRange[1]}] see more ${r.countMatched} matched ${r.tokensGrouped} tokens`,
|
|
3863
3943
|
textClose: null
|
|
3864
3944
|
});
|
|
3865
|
-
add = (
|
|
3945
|
+
add = (r, s, o) => r == null ? {
|
|
3866
3946
|
indexRange: [o, o],
|
|
3867
3947
|
countGrouped: 1,
|
|
3868
3948
|
countMatched: s.countMatched,
|
|
3869
3949
|
tokensGrouped: s.tokens
|
|
3870
|
-
} : (
|
|
3950
|
+
} : (r.indexRange[1] = o, r.countGrouped += 1, r.countMatched += s.countMatched, r.tokensGrouped += s.tokens, r);
|
|
3871
3951
|
}
|
|
3872
|
-
const
|
|
3952
|
+
const qt = p.object({
|
|
3873
3953
|
snapshotName: p.string().optional().describe("Name of previously created DOM snapshot, to use"),
|
|
3874
|
-
snapshot:
|
|
3954
|
+
snapshot: Te.optional().describe(
|
|
3875
3955
|
"DOM snapshot creation options JSON to automatically create snapshot"
|
|
3876
3956
|
),
|
|
3877
3957
|
parentUid: p.number().optional().describe("UID of parent node to browse. Omit to browse the root node"),
|
|
@@ -3889,13 +3969,13 @@ const Bt = p.object({
|
|
|
3889
3969
|
// maxCountGroup: z.number().default(10).describe('Maximum items per group'),
|
|
3890
3970
|
// maxTokensGroup: z.number().default(1000).describe('Maximum tokens per group'),
|
|
3891
3971
|
});
|
|
3892
|
-
async function
|
|
3972
|
+
async function Zs(t, r, s) {
|
|
3893
3973
|
let o;
|
|
3894
3974
|
try {
|
|
3895
|
-
o =
|
|
3896
|
-
} catch (
|
|
3975
|
+
o = qt.parse(t);
|
|
3976
|
+
} catch (m) {
|
|
3897
3977
|
return {
|
|
3898
|
-
error:
|
|
3978
|
+
error: F(m)
|
|
3899
3979
|
};
|
|
3900
3980
|
}
|
|
3901
3981
|
const {
|
|
@@ -3911,48 +3991,48 @@ async function qs(r, t, s) {
|
|
|
3911
3991
|
return {
|
|
3912
3992
|
error: "Session ID is required"
|
|
3913
3993
|
};
|
|
3914
|
-
const
|
|
3994
|
+
const f = j(s.sessionId);
|
|
3915
3995
|
if (e && n)
|
|
3916
3996
|
return {
|
|
3917
3997
|
error: "Either snapshotName or snapshot must be provided, not both"
|
|
3918
3998
|
};
|
|
3919
|
-
let
|
|
3999
|
+
let d, h = !1, g = !1;
|
|
3920
4000
|
if (e) {
|
|
3921
|
-
for (const
|
|
3922
|
-
for (const y of
|
|
4001
|
+
for (const m of f.browsers.values()) {
|
|
4002
|
+
for (const y of m.contexts.values()) {
|
|
3923
4003
|
for (const w of y.pages.values())
|
|
3924
4004
|
if (w.domSnapshots.has(e)) {
|
|
3925
|
-
|
|
4005
|
+
d = w.domSnapshots.get(e);
|
|
3926
4006
|
break;
|
|
3927
4007
|
}
|
|
3928
|
-
if (
|
|
4008
|
+
if (d != null) break;
|
|
3929
4009
|
}
|
|
3930
|
-
if (
|
|
4010
|
+
if (d != null) break;
|
|
3931
4011
|
}
|
|
3932
|
-
if (
|
|
4012
|
+
if (d == null)
|
|
3933
4013
|
return {
|
|
3934
4014
|
error: `DOM snapshot "${e}" not found`
|
|
3935
4015
|
};
|
|
3936
4016
|
} else if (n) {
|
|
3937
|
-
const
|
|
4017
|
+
const m = await Ut(
|
|
3938
4018
|
n,
|
|
3939
|
-
|
|
4019
|
+
r,
|
|
3940
4020
|
s
|
|
3941
4021
|
);
|
|
3942
|
-
if (
|
|
4022
|
+
if (m.error != null)
|
|
3943
4023
|
return {
|
|
3944
|
-
error:
|
|
4024
|
+
error: m.error
|
|
3945
4025
|
};
|
|
3946
|
-
|
|
4026
|
+
d = m.domSnapshot, h = m.queryCreated, g = !0;
|
|
3947
4027
|
} else
|
|
3948
4028
|
return {
|
|
3949
4029
|
error: "Either snapshotName or snapshot must be provided"
|
|
3950
4030
|
};
|
|
3951
4031
|
try {
|
|
3952
|
-
const
|
|
3953
|
-
tree:
|
|
4032
|
+
const m = o.parentUid, y = St({
|
|
4033
|
+
tree: d.tree,
|
|
3954
4034
|
request: {
|
|
3955
|
-
parentNodeId:
|
|
4035
|
+
parentNodeId: m,
|
|
3956
4036
|
childsIndexRange: a,
|
|
3957
4037
|
limits: {
|
|
3958
4038
|
maxCountTotal: i,
|
|
@@ -3961,32 +4041,32 @@ async function qs(r, t, s) {
|
|
|
3961
4041
|
maxTokensGroup: u
|
|
3962
4042
|
}
|
|
3963
4043
|
},
|
|
3964
|
-
indexRangeGroupStrategy: new
|
|
3965
|
-
}), w =
|
|
4044
|
+
indexRangeGroupStrategy: new Vs()
|
|
4045
|
+
}), w = xt(y);
|
|
3966
4046
|
return {
|
|
3967
|
-
domSnapshot:
|
|
4047
|
+
domSnapshot: d,
|
|
3968
4048
|
queryCreated: h,
|
|
3969
|
-
snapshotCreated:
|
|
3970
|
-
parentUid:
|
|
4049
|
+
snapshotCreated: g,
|
|
4050
|
+
parentUid: m,
|
|
3971
4051
|
childsIndexRange: a,
|
|
3972
4052
|
report: w
|
|
3973
4053
|
};
|
|
3974
|
-
} catch (
|
|
4054
|
+
} catch (m) {
|
|
3975
4055
|
return {
|
|
3976
|
-
error: `Failed to browse DOM snapshot: ${
|
|
4056
|
+
error: `Failed to browse DOM snapshot: ${m instanceof Error ? m.message : "Unknown error"}`
|
|
3977
4057
|
};
|
|
3978
4058
|
}
|
|
3979
4059
|
}
|
|
3980
|
-
function
|
|
3981
|
-
|
|
4060
|
+
function Xs(t, r) {
|
|
4061
|
+
t(
|
|
3982
4062
|
"playwright-dom-snapshot-browse",
|
|
3983
4063
|
{
|
|
3984
4064
|
title: "Browse DOM Snapshot",
|
|
3985
4065
|
description: "Browse and explore DOM. Use this to browse, analyze, explore, inspect, etc webpage structure and styles, find elements, or inspect page content",
|
|
3986
|
-
inputSchema:
|
|
4066
|
+
inputSchema: qt.shape
|
|
3987
4067
|
},
|
|
3988
4068
|
async (s, o) => {
|
|
3989
|
-
const e = await
|
|
4069
|
+
const e = await Zs(s, r, o);
|
|
3990
4070
|
if (e.error != null)
|
|
3991
4071
|
return `Method: playwright-dom-snapshot-browse(${JSON.stringify(s)})
|
|
3992
4072
|
❌ Error: ${e.error}`;
|
|
@@ -4007,14 +4087,14 @@ ${e.report}`, n;
|
|
|
4007
4087
|
}
|
|
4008
4088
|
);
|
|
4009
4089
|
}
|
|
4010
|
-
function
|
|
4011
|
-
|
|
4090
|
+
function eo(t, r) {
|
|
4091
|
+
r.browserCreate && vs(t, r), r.browserList && ks(t, r), r.browserClose && Ds(t, r), r.contextCreate && Rs(t, r), r.contextList && Bs(t, r), r.contextClose && Ps(t, r), r.pageCreate && Us(t, r), r.pageList && _s(t, r), r.pageClose && Js(t, r), r.pageGoto && Ks(t, r), r.domSnapshotQueryCreate && Ws(t, r), r.domSnapshotCreate && Ys(t, r), r.domSnapshotBrowse && Xs(t, r), console.log("Playwright manager");
|
|
4012
4092
|
}
|
|
4013
|
-
function
|
|
4014
|
-
const { logFilePath:
|
|
4093
|
+
function to(t) {
|
|
4094
|
+
const { logFilePath: r } = t;
|
|
4015
4095
|
return async function(o, e, n, a) {
|
|
4016
|
-
await
|
|
4017
|
-
logFilePath:
|
|
4096
|
+
await ie({
|
|
4097
|
+
logFilePath: r,
|
|
4018
4098
|
message: "ERROR",
|
|
4019
4099
|
data: {
|
|
4020
4100
|
request: {
|
|
@@ -4032,31 +4112,31 @@ function Js(r) {
|
|
|
4032
4112
|
});
|
|
4033
4113
|
};
|
|
4034
4114
|
}
|
|
4035
|
-
function
|
|
4115
|
+
function _t() {
|
|
4036
4116
|
return `mcp_${(/* @__PURE__ */ new Date()).toISOString().substring(0, 19).replace(/T/, "_").replace(/:/g, "-")}.log`;
|
|
4037
4117
|
}
|
|
4038
|
-
function
|
|
4039
|
-
const
|
|
4040
|
-
return
|
|
4118
|
+
function ro(t) {
|
|
4119
|
+
const r = ne(), s = so();
|
|
4120
|
+
return r.use(s), r;
|
|
4041
4121
|
}
|
|
4042
|
-
function
|
|
4043
|
-
const
|
|
4044
|
-
return
|
|
4122
|
+
function so(t) {
|
|
4123
|
+
const r = ne.Router();
|
|
4124
|
+
return r.use((s, o, e) => {
|
|
4045
4125
|
s.method === "OPTIONS" ? o.status(403).send("CORS forbidden") : e();
|
|
4046
|
-
}),
|
|
4126
|
+
}), r.use(ne.json()), r;
|
|
4047
4127
|
}
|
|
4048
|
-
function
|
|
4049
|
-
const
|
|
4050
|
-
return
|
|
4128
|
+
function oo(t) {
|
|
4129
|
+
const r = ne.Router();
|
|
4130
|
+
return r.use(rr({ authToken: t.authToken })), r.all("/mcp", ar(t)), r;
|
|
4051
4131
|
}
|
|
4052
|
-
function
|
|
4053
|
-
return
|
|
4132
|
+
function no(t, r) {
|
|
4133
|
+
return t.use(to({ logFilePath: r.logFilePath })), new Promise((s, o) => {
|
|
4054
4134
|
let e;
|
|
4055
4135
|
const n = () => {
|
|
4056
4136
|
s(e);
|
|
4057
4137
|
};
|
|
4058
4138
|
try {
|
|
4059
|
-
e =
|
|
4139
|
+
e = r.host ? t.listen(r.port ?? 0, r.host, n) : t.listen(r.port ?? 0, n), e.addListener("error", (a) => {
|
|
4060
4140
|
o(a);
|
|
4061
4141
|
});
|
|
4062
4142
|
} catch (a) {
|
|
@@ -4064,63 +4144,65 @@ function Hs(r, t) {
|
|
|
4064
4144
|
}
|
|
4065
4145
|
});
|
|
4066
4146
|
}
|
|
4067
|
-
function
|
|
4068
|
-
if (!
|
|
4069
|
-
throw new Error(
|
|
4070
|
-
|
|
4071
|
-
|
|
4147
|
+
function io(t, r) {
|
|
4148
|
+
if (!t.address())
|
|
4149
|
+
throw new Error(
|
|
4150
|
+
"Server address is not available. Check your DNS and host configuration."
|
|
4151
|
+
);
|
|
4152
|
+
const o = t.address().family, e = t.address().port;
|
|
4153
|
+
let n = t.address().address;
|
|
4072
4154
|
n === "::" ? n = "localhost" : o === "IPv6" && (n = `[${n}]`);
|
|
4073
4155
|
const a = `http://${o === "IPv6" ? `[${n}]` : n}:${e}`;
|
|
4074
4156
|
return `Project Tools - MCP Server Started
|
|
4075
4157
|
|
|
4076
|
-
Server Name: ${
|
|
4077
|
-
Server Version: ${
|
|
4158
|
+
Server Name: ${r.name}
|
|
4159
|
+
Server Version: ${r.version}
|
|
4078
4160
|
Server URL: ${a}/mcp
|
|
4079
4161
|
SSE Endpoint: ${a}/sse
|
|
4080
4162
|
|
|
4081
|
-
Log File: ${
|
|
4163
|
+
Log File: ${R.resolve(r.logFilePath)}`;
|
|
4082
4164
|
}
|
|
4083
|
-
function
|
|
4084
|
-
const s =
|
|
4165
|
+
function ao(t, r) {
|
|
4166
|
+
const s = R.join(r.logDir, _t()), o = Or(t, {
|
|
4085
4167
|
logFilePath: s
|
|
4086
4168
|
});
|
|
4087
|
-
|
|
4088
|
-
...
|
|
4089
|
-
});
|
|
4169
|
+
r.tools.processManager && kr(o, r.tools.processManager), r.tools.fsManager && Ns(o, r.tools.fsManager), r.tools.playwrightManager && eo(o, {
|
|
4170
|
+
...r.tools.playwrightManager
|
|
4171
|
+
}), xr(o);
|
|
4090
4172
|
}
|
|
4091
|
-
async function
|
|
4092
|
-
const
|
|
4093
|
-
...
|
|
4094
|
-
logFilePath:
|
|
4173
|
+
async function Co(t) {
|
|
4174
|
+
const r = R.join(t.logDir, _t()), s = ro(), o = oo({
|
|
4175
|
+
...t,
|
|
4176
|
+
logFilePath: r,
|
|
4095
4177
|
createMcpServer: () => {
|
|
4096
|
-
const n = new
|
|
4097
|
-
title:
|
|
4098
|
-
name:
|
|
4099
|
-
version:
|
|
4178
|
+
const n = new Gt({
|
|
4179
|
+
title: t.title,
|
|
4180
|
+
name: t.name,
|
|
4181
|
+
version: t.version
|
|
4100
4182
|
});
|
|
4101
|
-
return
|
|
4183
|
+
return ao(n, t), n;
|
|
4102
4184
|
}
|
|
4103
4185
|
});
|
|
4104
4186
|
s.use(o);
|
|
4105
|
-
const e = await
|
|
4106
|
-
host:
|
|
4107
|
-
port:
|
|
4108
|
-
logFilePath:
|
|
4187
|
+
const e = await no(s, {
|
|
4188
|
+
host: t.host,
|
|
4189
|
+
port: t.port,
|
|
4190
|
+
logFilePath: r
|
|
4109
4191
|
});
|
|
4110
4192
|
return console.log(
|
|
4111
|
-
|
|
4112
|
-
title:
|
|
4113
|
-
name:
|
|
4114
|
-
version:
|
|
4115
|
-
logFilePath:
|
|
4193
|
+
io(e, {
|
|
4194
|
+
title: t.title,
|
|
4195
|
+
name: t.name,
|
|
4196
|
+
version: t.version,
|
|
4197
|
+
logFilePath: r
|
|
4116
4198
|
})
|
|
4117
4199
|
), e;
|
|
4118
4200
|
}
|
|
4119
4201
|
export {
|
|
4120
|
-
|
|
4121
|
-
|
|
4122
|
-
|
|
4123
|
-
|
|
4124
|
-
|
|
4125
|
-
|
|
4202
|
+
To as A,
|
|
4203
|
+
Mo as S,
|
|
4204
|
+
Io as a,
|
|
4205
|
+
$o as b,
|
|
4206
|
+
Gr as p,
|
|
4207
|
+
Co as s
|
|
4126
4208
|
};
|