anycodex 0.0.23 → 0.0.25

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,16 +1,576 @@
1
1
  #!/usr/bin/env node
2
- import {
3
- Glob
4
- } from "./chunk-H3TAXRCT.js";
5
2
  import {
6
3
  Schema_exports,
4
+ __callDispose,
5
+ __using,
7
6
  withStatics,
8
7
  zod_default
9
- } from "./chunk-3KUWIT4H.js";
10
- import {
11
- __callDispose,
12
- __using
13
- } from "./chunk-XXVDY7BO.js";
8
+ } from "./chunk-M6C7CWX3.js";
9
+
10
+ // ../utils/dist/index.js
11
+ import fs from "fs/promises";
12
+ import { existsSync, statSync, readdirSync } from "fs";
13
+ import path from "path";
14
+ import { spawn } from "child_process";
15
+ import { spawn as spawn2 } from "child_process";
16
+ import fs2 from "fs/promises";
17
+ import path2 from "path";
18
+ import fs3 from "fs";
19
+ import nodePath from "path";
20
+ var consoleLogger = {
21
+ debug: console.debug.bind(console),
22
+ info: console.info.bind(console),
23
+ warn: console.warn.bind(console),
24
+ error: console.error.bind(console)
25
+ };
26
+ var SqliteNoSqlDb = class {
27
+ constructor(raw) {
28
+ this.raw = raw;
29
+ }
30
+ insert(table, row) {
31
+ const cols = Object.keys(row);
32
+ const placeholders = cols.map(() => "?").join(", ");
33
+ const sql2 = `INSERT INTO "${table}" (${cols.map((c) => `"${c}"`).join(", ")}) VALUES (${placeholders})`;
34
+ this.raw.run(sql2, cols.map((c) => serialize(row[c])));
35
+ }
36
+ upsert(table, row, conflictKeys, updateFields) {
37
+ const cols = Object.keys(row);
38
+ const placeholders = cols.map(() => "?").join(", ");
39
+ const conflict = conflictKeys.map((k) => `"${k}"`).join(", ");
40
+ const updates = Object.keys(updateFields).map((k) => `"${k}" = ?`).join(", ");
41
+ const sql2 = `INSERT INTO "${table}" (${cols.map((c) => `"${c}"`).join(", ")}) VALUES (${placeholders}) ON CONFLICT (${conflict}) DO UPDATE SET ${updates}`;
42
+ const params = [
43
+ ...cols.map((c) => serialize(row[c])),
44
+ ...Object.keys(updateFields).map((k) => serialize(updateFields[k]))
45
+ ];
46
+ this.raw.run(sql2, params);
47
+ }
48
+ findOne(table, filter2, options) {
49
+ const fields = options?.select?.map((f) => `"${f}"`).join(", ") ?? "*";
50
+ const { clause, params } = filter2 ? buildWhere(filter2) : { clause: "", params: [] };
51
+ const where = clause ? ` WHERE ${clause}` : "";
52
+ const sql2 = `SELECT ${fields} FROM "${table}"${where} LIMIT 1`;
53
+ const row = this.raw.get(sql2, params);
54
+ return row ? deserializeRow(row) : void 0;
55
+ }
56
+ findMany(table, options) {
57
+ const fields = options?.select?.map((f) => `"${f}"`).join(", ") ?? "*";
58
+ const { clause, params } = options?.filter ? buildWhere(options.filter) : { clause: "", params: [] };
59
+ const where = clause ? ` WHERE ${clause}` : "";
60
+ let orderClause = "";
61
+ if (options?.orderBy?.length) {
62
+ const parts = options.orderBy.map(
63
+ (o) => `"${o.field}" ${o.direction === "desc" ? "DESC" : "ASC"}`
64
+ );
65
+ orderClause = ` ORDER BY ${parts.join(", ")}`;
66
+ }
67
+ const limitClause = options?.limit != null ? ` LIMIT ${options.limit}` : "";
68
+ const sql2 = `SELECT ${fields} FROM "${table}"${where}${orderClause}${limitClause}`;
69
+ return this.raw.all(sql2, params).map(deserializeRow);
70
+ }
71
+ update(table, filter2, set) {
72
+ const setCols = Object.keys(set);
73
+ const setClause = setCols.map((k) => `"${k}" = ?`).join(", ");
74
+ const { clause, params } = buildWhere(filter2);
75
+ const sql2 = `UPDATE "${table}" SET ${setClause} WHERE ${clause} RETURNING *`;
76
+ const setParams = setCols.map((k) => serialize(set[k]));
77
+ const row = this.raw.get(sql2, [...setParams, ...params]);
78
+ return row ? deserializeRow(row) : void 0;
79
+ }
80
+ remove(table, filter2) {
81
+ const { clause, params } = buildWhere(filter2);
82
+ this.raw.run(`DELETE FROM "${table}" WHERE ${clause}`, params);
83
+ }
84
+ transaction(fn) {
85
+ this.raw.transaction(() => {
86
+ fn(this);
87
+ });
88
+ }
89
+ };
90
+ function buildWhere(filter2) {
91
+ switch (filter2.op) {
92
+ case "eq":
93
+ return { clause: `"${filter2.field}" = ?`, params: [serialize(filter2.value)] };
94
+ case "ne":
95
+ return { clause: `"${filter2.field}" != ?`, params: [serialize(filter2.value)] };
96
+ case "gt":
97
+ return { clause: `"${filter2.field}" > ?`, params: [serialize(filter2.value)] };
98
+ case "gte":
99
+ return { clause: `"${filter2.field}" >= ?`, params: [serialize(filter2.value)] };
100
+ case "lt":
101
+ return { clause: `"${filter2.field}" < ?`, params: [serialize(filter2.value)] };
102
+ case "like":
103
+ return { clause: `"${filter2.field}" LIKE ?`, params: [filter2.value] };
104
+ case "isNull":
105
+ return { clause: `"${filter2.field}" IS NULL`, params: [] };
106
+ case "in": {
107
+ const placeholders = filter2.values.map(() => "?").join(", ");
108
+ return { clause: `"${filter2.field}" IN (${placeholders})`, params: filter2.values.map(serialize) };
109
+ }
110
+ case "and": {
111
+ const parts = filter2.conditions.map(buildWhere);
112
+ return {
113
+ clause: parts.map((p) => `(${p.clause})`).join(" AND "),
114
+ params: parts.flatMap((p) => p.params)
115
+ };
116
+ }
117
+ case "or": {
118
+ const parts = filter2.conditions.map(buildWhere);
119
+ return {
120
+ clause: parts.map((p) => `(${p.clause})`).join(" OR "),
121
+ params: parts.flatMap((p) => p.params)
122
+ };
123
+ }
124
+ }
125
+ }
126
+ function serialize(value) {
127
+ if (value === void 0) return null;
128
+ if (value === null) return null;
129
+ if (typeof value === "object" && !(value instanceof Buffer) && !(value instanceof Uint8Array)) {
130
+ return JSON.stringify(value);
131
+ }
132
+ return value;
133
+ }
134
+ function deserializeRow(row) {
135
+ const result = {};
136
+ for (const [key, value] of Object.entries(row)) {
137
+ if (typeof value === "string" && (value.startsWith("{") || value.startsWith("["))) {
138
+ try {
139
+ result[key] = JSON.parse(value);
140
+ } catch {
141
+ result[key] = value;
142
+ }
143
+ } else {
144
+ result[key] = value;
145
+ }
146
+ }
147
+ return result;
148
+ }
149
+ var NodeFS = class {
150
+ async exists(p) {
151
+ return existsSync(p);
152
+ }
153
+ async stat(p) {
154
+ try {
155
+ const s = statSync(p);
156
+ return {
157
+ size: typeof s.size === "bigint" ? Number(s.size) : s.size,
158
+ isDirectory: s.isDirectory(),
159
+ isFile: s.isFile(),
160
+ mtimeMs: s.mtimeMs
161
+ };
162
+ } catch {
163
+ return void 0;
164
+ }
165
+ }
166
+ async isDir(p) {
167
+ const s = await this.stat(p);
168
+ return s?.isDirectory ?? false;
169
+ }
170
+ async readText(p) {
171
+ return fs.readFile(p, "utf-8");
172
+ }
173
+ async readBytes(p) {
174
+ return fs.readFile(p);
175
+ }
176
+ async readJson(p) {
177
+ return JSON.parse(await this.readText(p));
178
+ }
179
+ async readDir(p) {
180
+ const entries = readdirSync(p, { withFileTypes: true });
181
+ return entries.map((e) => ({
182
+ name: e.name,
183
+ isDirectory: e.isDirectory(),
184
+ isFile: e.isFile()
185
+ }));
186
+ }
187
+ async write(p, content) {
188
+ try {
189
+ await fs.writeFile(p, content);
190
+ } catch (e) {
191
+ if (e?.code === "ENOENT") {
192
+ await fs.mkdir(path.dirname(p), { recursive: true });
193
+ await fs.writeFile(p, content);
194
+ return;
195
+ }
196
+ throw e;
197
+ }
198
+ }
199
+ async writeJson(p, data) {
200
+ await this.write(p, JSON.stringify(data, null, 2));
201
+ }
202
+ async mkdir(p) {
203
+ await fs.mkdir(p, { recursive: true });
204
+ }
205
+ async remove(p) {
206
+ await fs.unlink(p).catch(() => {
207
+ });
208
+ }
209
+ async grep(pattern, searchPath, options) {
210
+ return new Promise((resolve2) => {
211
+ const args = [
212
+ "--json",
213
+ "--line-number",
214
+ "--column",
215
+ "--no-heading",
216
+ ...options?.maxResults ? ["--max-count", String(options.maxResults)] : [],
217
+ ...options?.include?.flatMap((g) => ["--glob", g]) ?? [],
218
+ pattern,
219
+ searchPath
220
+ ];
221
+ const rg = spawn("rg", args, { stdio: ["ignore", "pipe", "pipe"] });
222
+ let output = "";
223
+ rg.stdout.on("data", (data) => {
224
+ output += data.toString();
225
+ });
226
+ rg.on("close", () => {
227
+ const results = [];
228
+ for (const line of output.split("\n")) {
229
+ if (!line.trim()) continue;
230
+ try {
231
+ const parsed = JSON.parse(line);
232
+ if (parsed.type === "match") {
233
+ results.push({
234
+ file: parsed.data.path.text,
235
+ line: parsed.data.line_number,
236
+ column: parsed.data.submatches?.[0]?.start ?? 0,
237
+ content: parsed.data.lines.text.trimEnd()
238
+ });
239
+ }
240
+ } catch {
241
+ }
242
+ }
243
+ resolve2(results);
244
+ });
245
+ rg.on("error", () => resolve2([]));
246
+ });
247
+ }
248
+ async glob(pattern, options = {}) {
249
+ const searchPath = options.cwd ?? process.cwd();
250
+ const { glob: fsGlob } = await import("fs/promises").catch(() => ({ glob: void 0 }));
251
+ if (fsGlob) {
252
+ try {
253
+ const results = [];
254
+ for await (const entry of fsGlob(pattern, { cwd: searchPath })) {
255
+ if (options.absolute) {
256
+ results.push(path.resolve(searchPath, entry));
257
+ } else {
258
+ results.push(entry);
259
+ }
260
+ }
261
+ return results;
262
+ } catch {
263
+ }
264
+ }
265
+ return new Promise((resolve2) => {
266
+ const rg = spawn("rg", ["--files", "--glob", pattern, searchPath], {
267
+ stdio: ["ignore", "pipe", "pipe"]
268
+ });
269
+ let output = "";
270
+ rg.stdout.on("data", (data) => {
271
+ output += data.toString();
272
+ });
273
+ rg.on("close", () => {
274
+ resolve2(
275
+ output.split("\n").map((l) => l.trim()).filter(Boolean)
276
+ );
277
+ });
278
+ rg.on("error", () => resolve2([]));
279
+ });
280
+ }
281
+ };
282
+ var NodeSearchProvider = class {
283
+ async grep(options) {
284
+ options.signal?.throwIfAborted();
285
+ return new Promise((resolve2, reject) => {
286
+ const args = ["-rnH", "--color=never"];
287
+ if (options.include) {
288
+ args.push(`--include=${options.include}`);
289
+ }
290
+ args.push("--exclude-dir=.git");
291
+ args.push("-E");
292
+ args.push("--", options.pattern, options.path);
293
+ const proc = spawn2("grep", args, {
294
+ stdio: ["ignore", "pipe", "pipe"],
295
+ signal: options.signal
296
+ });
297
+ let output = "";
298
+ proc.stdout.on("data", (data) => {
299
+ output += data.toString();
300
+ });
301
+ proc.on("close", () => {
302
+ const results = [];
303
+ for (const line of output.split("\n")) {
304
+ if (!line.trim()) continue;
305
+ const match2 = line.match(/^(.+?):(\d+):(.*)$/);
306
+ if (match2) {
307
+ let content = match2[3];
308
+ if (options.maxLineLength !== void 0 && content.length > options.maxLineLength) {
309
+ content = content.slice(0, options.maxLineLength) + "...";
310
+ }
311
+ results.push({
312
+ file: match2[1],
313
+ line: parseInt(match2[2], 10),
314
+ column: 0,
315
+ content
316
+ });
317
+ }
318
+ }
319
+ resolve2(results);
320
+ });
321
+ proc.on("error", (error) => {
322
+ reject(error);
323
+ });
324
+ });
325
+ }
326
+ async listFiles(options) {
327
+ options.signal?.throwIfAborted();
328
+ const showHidden = options.hidden === true;
329
+ const results = [];
330
+ const limit = options.limit ?? Infinity;
331
+ const excludePatterns = [".git"];
332
+ const includePatterns = [];
333
+ for (const g of options.glob ?? []) {
334
+ if (g.startsWith("!")) {
335
+ excludePatterns.push(g.slice(1).replace(/[/*]+$/, ""));
336
+ } else {
337
+ includePatterns.push(g);
338
+ }
339
+ }
340
+ const walk = async (dir, depth) => {
341
+ if (results.length >= limit) return;
342
+ if (options.maxDepth !== void 0 && depth > options.maxDepth) return;
343
+ options.signal?.throwIfAborted();
344
+ let entries;
345
+ try {
346
+ entries = await fs2.readdir(dir, { withFileTypes: true });
347
+ } catch {
348
+ return;
349
+ }
350
+ for (const entry of entries) {
351
+ if (results.length >= limit) return;
352
+ const name = entry.name;
353
+ if (!showHidden && name.startsWith(".")) continue;
354
+ const fullPath = path2.join(dir, name);
355
+ const relativePath = path2.relative(options.cwd, fullPath);
356
+ if (excludePatterns.some((p) => relativePath.startsWith(p) || name === p)) continue;
357
+ const isDir = entry.isDirectory() || options.follow && entry.isSymbolicLink();
358
+ if (isDir) {
359
+ await walk(fullPath, depth + 1);
360
+ } else if (entry.isFile()) {
361
+ if (includePatterns.length > 0) {
362
+ const matches = includePatterns.some((p) => simpleGlobMatch(name, p));
363
+ if (!matches) continue;
364
+ }
365
+ results.push(relativePath);
366
+ }
367
+ }
368
+ };
369
+ await walk(options.cwd, 0);
370
+ return results;
371
+ }
372
+ async tree(options) {
373
+ const limit = options.limit ?? 50;
374
+ const files = await this.listFiles({ cwd: options.cwd, signal: options.signal });
375
+ function dir(node, name) {
376
+ const existing = node.children.get(name);
377
+ if (existing) return existing;
378
+ const next = { name, children: /* @__PURE__ */ new Map() };
379
+ node.children.set(name, next);
380
+ return next;
381
+ }
382
+ const root = { name: "", children: /* @__PURE__ */ new Map() };
383
+ for (const file of files) {
384
+ if (file.includes(".opencode")) continue;
385
+ const parts = file.split(/[\/\\]/);
386
+ if (parts.length < 2) continue;
387
+ let node = root;
388
+ for (const part of parts.slice(0, -1)) {
389
+ node = dir(node, part);
390
+ }
391
+ }
392
+ function count(node) {
393
+ let total2 = 0;
394
+ for (const child of node.children.values()) {
395
+ total2 += 1 + count(child);
396
+ }
397
+ return total2;
398
+ }
399
+ const total = count(root);
400
+ const lines = [];
401
+ const queue = [];
402
+ for (const child of Array.from(root.children.values()).sort((a, b) => a.name.localeCompare(b.name))) {
403
+ queue.push({ node: child, path: child.name });
404
+ }
405
+ let used = 0;
406
+ for (let i = 0; i < queue.length && used < limit; i++) {
407
+ const { node, path: p } = queue[i];
408
+ lines.push(p);
409
+ used++;
410
+ for (const child of Array.from(node.children.values()).sort((a, b) => a.name.localeCompare(b.name))) {
411
+ queue.push({ node: child, path: `${p}/${child.name}` });
412
+ }
413
+ }
414
+ if (total > used) lines.push(`[${total - used} truncated]`);
415
+ return lines.join("\n");
416
+ }
417
+ };
418
+ function simpleGlobMatch(filename, pattern) {
419
+ if (pattern === "*") return true;
420
+ if (pattern.startsWith("*.")) {
421
+ const ext2 = pattern.slice(1);
422
+ if (ext2.startsWith(".{") && ext2.endsWith("}")) {
423
+ const exts = ext2.slice(2, -1).split(",");
424
+ return exts.some((e) => filename.endsWith(`.${e}`));
425
+ }
426
+ return filename.endsWith(ext2);
427
+ }
428
+ return filename === pattern;
429
+ }
430
+ var SqlJsStorage = class {
431
+ db = null;
432
+ noSqlDb = null;
433
+ dbPath;
434
+ flushTimer = null;
435
+ constructor(dbPath) {
436
+ this.dbPath = dbPath ?? null;
437
+ }
438
+ async connect(migrations) {
439
+ if (this.noSqlDb) return this.noSqlDb;
440
+ const initSqlJs = (await import("sql.js")).default;
441
+ const SQL3 = await initSqlJs();
442
+ if (this.dbPath && fs3.existsSync(this.dbPath)) {
443
+ const buffer = fs3.readFileSync(this.dbPath);
444
+ this.db = new SQL3.Database(new Uint8Array(buffer));
445
+ } else {
446
+ this.db = new SQL3.Database();
447
+ }
448
+ this.db.run("PRAGMA foreign_keys = ON");
449
+ this.applyMigrations(migrations);
450
+ this.flushSync();
451
+ const raw = this.createRawDb();
452
+ this.noSqlDb = new SqliteNoSqlDb(raw);
453
+ return this.noSqlDb;
454
+ }
455
+ // ── Flush to disk ──────────────────────────────────────────────
456
+ /** Schedule an async flush (debounced 100ms). */
457
+ scheduleFlush() {
458
+ if (!this.dbPath) return;
459
+ if (this.flushTimer) return;
460
+ this.flushTimer = setTimeout(() => {
461
+ this.flushTimer = null;
462
+ this.flushSync();
463
+ }, 100);
464
+ }
465
+ /** Synchronously write the entire database to disk. */
466
+ flushSync() {
467
+ if (!this.dbPath || !this.db) return;
468
+ const dir = nodePath.dirname(this.dbPath);
469
+ fs3.mkdirSync(dir, { recursive: true });
470
+ const data = this.db.export();
471
+ fs3.writeFileSync(this.dbPath, Buffer.from(data));
472
+ }
473
+ // ── RawSqliteDb wrapper ────────────────────────────────────────
474
+ createRawDb() {
475
+ const db = this.db;
476
+ const self = this;
477
+ return {
478
+ run(sql2, params) {
479
+ db.run(sql2, params);
480
+ self.scheduleFlush();
481
+ },
482
+ get(sql2, params) {
483
+ const stmt = db.prepare(sql2);
484
+ if (params) stmt.bind(params);
485
+ if (!stmt.step()) {
486
+ stmt.free();
487
+ return void 0;
488
+ }
489
+ const result = stmt.getAsObject();
490
+ stmt.free();
491
+ return result;
492
+ },
493
+ all(sql2, params) {
494
+ const stmt = db.prepare(sql2);
495
+ if (params) stmt.bind(params);
496
+ const results = [];
497
+ while (stmt.step()) {
498
+ results.push(stmt.getAsObject());
499
+ }
500
+ stmt.free();
501
+ return results;
502
+ },
503
+ transaction(fn) {
504
+ db.run("BEGIN TRANSACTION");
505
+ try {
506
+ fn();
507
+ db.run("COMMIT");
508
+ self.scheduleFlush();
509
+ } catch (e) {
510
+ db.run("ROLLBACK");
511
+ throw e;
512
+ }
513
+ }
514
+ };
515
+ }
516
+ // ── Migrations ─────────────────────────────────────────────────
517
+ applyMigrations(entries) {
518
+ if (!this.db) throw new Error("SqlJsStorage: db not initialized");
519
+ this.db.run(`
520
+ CREATE TABLE IF NOT EXISTS "__drizzle_migrations" (
521
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
522
+ hash TEXT NOT NULL,
523
+ created_at INTEGER
524
+ )
525
+ `);
526
+ const applied = /* @__PURE__ */ new Set();
527
+ const rows = this.db.exec(`SELECT hash FROM "__drizzle_migrations"`);
528
+ if (rows.length > 0) {
529
+ for (const row of rows[0].values) {
530
+ applied.add(row[0]);
531
+ }
532
+ }
533
+ for (const entry of entries) {
534
+ const hash = entry.name;
535
+ if (applied.has(hash)) continue;
536
+ this.db.run(entry.sql);
537
+ this.db.run(
538
+ `INSERT INTO "__drizzle_migrations" (hash, created_at) VALUES (?, ?)`,
539
+ [hash, entry.timestamp]
540
+ );
541
+ }
542
+ }
543
+ /** Run raw SQL (for server-specific DDL like extra tables). */
544
+ exec(sql2) {
545
+ if (!this.db) throw new Error("SqlJsStorage: db not initialized");
546
+ this.db.run(sql2);
547
+ this.scheduleFlush();
548
+ }
549
+ /** Run a SELECT query and return rows as objects. */
550
+ query(sql2, params) {
551
+ if (!this.db) throw new Error("SqlJsStorage: db not initialized");
552
+ const stmt = this.db.prepare(sql2);
553
+ if (params) stmt.bind(params);
554
+ const results = [];
555
+ while (stmt.step()) {
556
+ results.push(stmt.getAsObject());
557
+ }
558
+ stmt.free();
559
+ return results;
560
+ }
561
+ close() {
562
+ if (this.flushTimer) {
563
+ clearTimeout(this.flushTimer);
564
+ this.flushTimer = null;
565
+ }
566
+ this.flushSync();
567
+ if (this.db) {
568
+ this.db.close();
569
+ this.db = null;
570
+ }
571
+ this.noSqlDb = null;
572
+ }
573
+ };
14
574
 
15
575
  // ../../node_modules/.pnpm/drizzle-orm@1.0.0-beta.16-ea816b6_@opentelemetry+api@1.9.0_@types+better-sqlite3@7.6.13_0f21266a0de314c39cfb891f27e2ae25/node_modules/drizzle-orm/column-common.js
16
576
  var OriginalColumn = /* @__PURE__ */ Symbol.for("drizzle:OriginalColumn");
@@ -1307,40 +1867,1580 @@ var PrimaryKey = class {
1307
1867
  }
1308
1868
  };
1309
1869
 
1310
- // ../agent/dist/chunk-KXKREECS.js
1311
- import fs from "fs/promises";
1312
- var sep = "/";
1313
- function join(...parts) {
1314
- const joined = parts.filter(Boolean).join("/");
1315
- return normalize(joined);
1870
+ // ../../node_modules/.pnpm/@isaacs+balanced-match@4.0.1/node_modules/@isaacs/balanced-match/dist/esm/index.js
1871
+ var balanced = (a, b, str) => {
1872
+ const ma = a instanceof RegExp ? maybeMatch(a, str) : a;
1873
+ const mb = b instanceof RegExp ? maybeMatch(b, str) : b;
1874
+ const r = ma !== null && mb != null && range(ma, mb, str);
1875
+ return r && {
1876
+ start: r[0],
1877
+ end: r[1],
1878
+ pre: str.slice(0, r[0]),
1879
+ body: str.slice(r[0] + ma.length, r[1]),
1880
+ post: str.slice(r[1] + mb.length)
1881
+ };
1882
+ };
1883
+ var maybeMatch = (reg, str) => {
1884
+ const m = str.match(reg);
1885
+ return m ? m[0] : null;
1886
+ };
1887
+ var range = (a, b, str) => {
1888
+ let begs, beg, left, right = void 0, result;
1889
+ let ai = str.indexOf(a);
1890
+ let bi = str.indexOf(b, ai + 1);
1891
+ let i = ai;
1892
+ if (ai >= 0 && bi > 0) {
1893
+ if (a === b) {
1894
+ return [ai, bi];
1895
+ }
1896
+ begs = [];
1897
+ left = str.length;
1898
+ while (i >= 0 && !result) {
1899
+ if (i === ai) {
1900
+ begs.push(i);
1901
+ ai = str.indexOf(a, i + 1);
1902
+ } else if (begs.length === 1) {
1903
+ const r = begs.pop();
1904
+ if (r !== void 0)
1905
+ result = [r, bi];
1906
+ } else {
1907
+ beg = begs.pop();
1908
+ if (beg !== void 0 && beg < left) {
1909
+ left = beg;
1910
+ right = bi;
1911
+ }
1912
+ bi = str.indexOf(b, i + 1);
1913
+ }
1914
+ i = ai < bi && ai >= 0 ? ai : bi;
1915
+ }
1916
+ if (begs.length && right !== void 0) {
1917
+ result = [left, right];
1918
+ }
1919
+ }
1920
+ return result;
1921
+ };
1922
+
1923
+ // ../../node_modules/.pnpm/@isaacs+brace-expansion@5.0.1/node_modules/@isaacs/brace-expansion/dist/esm/index.js
1924
+ var escSlash = "\0SLASH" + Math.random() + "\0";
1925
+ var escOpen = "\0OPEN" + Math.random() + "\0";
1926
+ var escClose = "\0CLOSE" + Math.random() + "\0";
1927
+ var escComma = "\0COMMA" + Math.random() + "\0";
1928
+ var escPeriod = "\0PERIOD" + Math.random() + "\0";
1929
+ var escSlashPattern = new RegExp(escSlash, "g");
1930
+ var escOpenPattern = new RegExp(escOpen, "g");
1931
+ var escClosePattern = new RegExp(escClose, "g");
1932
+ var escCommaPattern = new RegExp(escComma, "g");
1933
+ var escPeriodPattern = new RegExp(escPeriod, "g");
1934
+ var slashPattern = /\\\\/g;
1935
+ var openPattern = /\\{/g;
1936
+ var closePattern = /\\}/g;
1937
+ var commaPattern = /\\,/g;
1938
+ var periodPattern = /\\./g;
1939
+ var EXPANSION_MAX = 1e5;
1940
+ function numeric2(str) {
1941
+ return !isNaN(str) ? parseInt(str, 10) : str.charCodeAt(0);
1316
1942
  }
1317
- function dirname(p) {
1318
- if (!p) return ".";
1319
- const i = p.lastIndexOf("/");
1320
- if (i < 0) return ".";
1321
- if (i === 0) return "/";
1322
- return p.slice(0, i);
1943
+ function escapeBraces(str) {
1944
+ return str.replace(slashPattern, escSlash).replace(openPattern, escOpen).replace(closePattern, escClose).replace(commaPattern, escComma).replace(periodPattern, escPeriod);
1323
1945
  }
1324
- function basename(p, ext) {
1325
- if (p.endsWith("/")) p = p.slice(0, -1);
1326
- const i = p.lastIndexOf("/");
1327
- const base = i < 0 ? p : p.slice(i + 1);
1328
- if (ext && base.endsWith(ext)) return base.slice(0, -ext.length);
1329
- return base;
1946
+ function unescapeBraces(str) {
1947
+ return str.replace(escSlashPattern, "\\").replace(escOpenPattern, "{").replace(escClosePattern, "}").replace(escCommaPattern, ",").replace(escPeriodPattern, ".");
1330
1948
  }
1331
- function extname(p) {
1332
- const base = basename(p);
1333
- const i = base.lastIndexOf(".");
1334
- if (i <= 0) return "";
1335
- return base.slice(i);
1949
+ function parseCommaParts(str) {
1950
+ if (!str) {
1951
+ return [""];
1952
+ }
1953
+ const parts = [];
1954
+ const m = balanced("{", "}", str);
1955
+ if (!m) {
1956
+ return str.split(",");
1957
+ }
1958
+ const { pre, body, post } = m;
1959
+ const p = pre.split(",");
1960
+ p[p.length - 1] += "{" + body + "}";
1961
+ const postParts = parseCommaParts(post);
1962
+ if (post.length) {
1963
+ ;
1964
+ p[p.length - 1] += postParts.shift();
1965
+ p.push.apply(p, postParts);
1966
+ }
1967
+ parts.push.apply(parts, p);
1968
+ return parts;
1336
1969
  }
1337
- function isAbsolute(p) {
1338
- return p.startsWith("/");
1970
+ function expand(str, options = {}) {
1971
+ if (!str) {
1972
+ return [];
1973
+ }
1974
+ const { max = EXPANSION_MAX } = options;
1975
+ if (str.slice(0, 2) === "{}") {
1976
+ str = "\\{\\}" + str.slice(2);
1977
+ }
1978
+ return expand_(escapeBraces(str), max, true).map(unescapeBraces);
1339
1979
  }
1340
- function normalize(p) {
1341
- if (!p) return ".";
1342
- const isAbs = p.startsWith("/");
1343
- const segments = p.split("/");
1980
+ function embrace(str) {
1981
+ return "{" + str + "}";
1982
+ }
1983
+ function isPadded(el) {
1984
+ return /^-?0\d/.test(el);
1985
+ }
1986
+ function lte(i, y) {
1987
+ return i <= y;
1988
+ }
1989
+ function gte(i, y) {
1990
+ return i >= y;
1991
+ }
1992
+ function expand_(str, max, isTop) {
1993
+ const expansions = [];
1994
+ const m = balanced("{", "}", str);
1995
+ if (!m)
1996
+ return [str];
1997
+ const pre = m.pre;
1998
+ const post = m.post.length ? expand_(m.post, max, false) : [""];
1999
+ if (/\$$/.test(m.pre)) {
2000
+ for (let k = 0; k < post.length && k < max; k++) {
2001
+ const expansion = pre + "{" + m.body + "}" + post[k];
2002
+ expansions.push(expansion);
2003
+ }
2004
+ } else {
2005
+ const isNumericSequence = /^-?\d+\.\.-?\d+(?:\.\.-?\d+)?$/.test(m.body);
2006
+ const isAlphaSequence = /^[a-zA-Z]\.\.[a-zA-Z](?:\.\.-?\d+)?$/.test(m.body);
2007
+ const isSequence = isNumericSequence || isAlphaSequence;
2008
+ const isOptions = m.body.indexOf(",") >= 0;
2009
+ if (!isSequence && !isOptions) {
2010
+ if (m.post.match(/,(?!,).*\}/)) {
2011
+ str = m.pre + "{" + m.body + escClose + m.post;
2012
+ return expand_(str, max, true);
2013
+ }
2014
+ return [str];
2015
+ }
2016
+ let n;
2017
+ if (isSequence) {
2018
+ n = m.body.split(/\.\./);
2019
+ } else {
2020
+ n = parseCommaParts(m.body);
2021
+ if (n.length === 1 && n[0] !== void 0) {
2022
+ n = expand_(n[0], max, false).map(embrace);
2023
+ if (n.length === 1) {
2024
+ return post.map((p) => m.pre + n[0] + p);
2025
+ }
2026
+ }
2027
+ }
2028
+ let N;
2029
+ if (isSequence && n[0] !== void 0 && n[1] !== void 0) {
2030
+ const x = numeric2(n[0]);
2031
+ const y = numeric2(n[1]);
2032
+ const width = Math.max(n[0].length, n[1].length);
2033
+ let incr = n.length === 3 && n[2] !== void 0 ? Math.abs(numeric2(n[2])) : 1;
2034
+ let test = lte;
2035
+ const reverse = y < x;
2036
+ if (reverse) {
2037
+ incr *= -1;
2038
+ test = gte;
2039
+ }
2040
+ const pad = n.some(isPadded);
2041
+ N = [];
2042
+ for (let i = x; test(i, y); i += incr) {
2043
+ let c;
2044
+ if (isAlphaSequence) {
2045
+ c = String.fromCharCode(i);
2046
+ if (c === "\\") {
2047
+ c = "";
2048
+ }
2049
+ } else {
2050
+ c = String(i);
2051
+ if (pad) {
2052
+ const need = width - c.length;
2053
+ if (need > 0) {
2054
+ const z = new Array(need + 1).join("0");
2055
+ if (i < 0) {
2056
+ c = "-" + z + c.slice(1);
2057
+ } else {
2058
+ c = z + c;
2059
+ }
2060
+ }
2061
+ }
2062
+ }
2063
+ N.push(c);
2064
+ }
2065
+ } else {
2066
+ N = [];
2067
+ for (let j = 0; j < n.length; j++) {
2068
+ N.push.apply(N, expand_(n[j], max, false));
2069
+ }
2070
+ }
2071
+ for (let j = 0; j < N.length; j++) {
2072
+ for (let k = 0; k < post.length && expansions.length < max; k++) {
2073
+ const expansion = pre + N[j] + post[k];
2074
+ if (!isTop || isSequence || expansion) {
2075
+ expansions.push(expansion);
2076
+ }
2077
+ }
2078
+ }
2079
+ }
2080
+ return expansions;
2081
+ }
2082
+
2083
+ // ../../node_modules/.pnpm/minimatch@10.0.3/node_modules/minimatch/dist/esm/assert-valid-pattern.js
2084
+ var MAX_PATTERN_LENGTH = 1024 * 64;
2085
+ var assertValidPattern = (pattern) => {
2086
+ if (typeof pattern !== "string") {
2087
+ throw new TypeError("invalid pattern");
2088
+ }
2089
+ if (pattern.length > MAX_PATTERN_LENGTH) {
2090
+ throw new TypeError("pattern is too long");
2091
+ }
2092
+ };
2093
+
2094
+ // ../../node_modules/.pnpm/minimatch@10.0.3/node_modules/minimatch/dist/esm/brace-expressions.js
2095
+ var posixClasses = {
2096
+ "[:alnum:]": ["\\p{L}\\p{Nl}\\p{Nd}", true],
2097
+ "[:alpha:]": ["\\p{L}\\p{Nl}", true],
2098
+ "[:ascii:]": ["\\x00-\\x7f", false],
2099
+ "[:blank:]": ["\\p{Zs}\\t", true],
2100
+ "[:cntrl:]": ["\\p{Cc}", true],
2101
+ "[:digit:]": ["\\p{Nd}", true],
2102
+ "[:graph:]": ["\\p{Z}\\p{C}", true, true],
2103
+ "[:lower:]": ["\\p{Ll}", true],
2104
+ "[:print:]": ["\\p{C}", true],
2105
+ "[:punct:]": ["\\p{P}", true],
2106
+ "[:space:]": ["\\p{Z}\\t\\r\\n\\v\\f", true],
2107
+ "[:upper:]": ["\\p{Lu}", true],
2108
+ "[:word:]": ["\\p{L}\\p{Nl}\\p{Nd}\\p{Pc}", true],
2109
+ "[:xdigit:]": ["A-Fa-f0-9", false]
2110
+ };
2111
+ var braceEscape = (s) => s.replace(/[[\]\\-]/g, "\\$&");
2112
+ var regexpEscape = (s) => s.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
2113
+ var rangesToString = (ranges) => ranges.join("");
2114
+ var parseClass = (glob, position) => {
2115
+ const pos = position;
2116
+ if (glob.charAt(pos) !== "[") {
2117
+ throw new Error("not in a brace expression");
2118
+ }
2119
+ const ranges = [];
2120
+ const negs = [];
2121
+ let i = pos + 1;
2122
+ let sawStart = false;
2123
+ let uflag = false;
2124
+ let escaping = false;
2125
+ let negate = false;
2126
+ let endPos = pos;
2127
+ let rangeStart = "";
2128
+ WHILE: while (i < glob.length) {
2129
+ const c = glob.charAt(i);
2130
+ if ((c === "!" || c === "^") && i === pos + 1) {
2131
+ negate = true;
2132
+ i++;
2133
+ continue;
2134
+ }
2135
+ if (c === "]" && sawStart && !escaping) {
2136
+ endPos = i + 1;
2137
+ break;
2138
+ }
2139
+ sawStart = true;
2140
+ if (c === "\\") {
2141
+ if (!escaping) {
2142
+ escaping = true;
2143
+ i++;
2144
+ continue;
2145
+ }
2146
+ }
2147
+ if (c === "[" && !escaping) {
2148
+ for (const [cls, [unip, u, neg]] of Object.entries(posixClasses)) {
2149
+ if (glob.startsWith(cls, i)) {
2150
+ if (rangeStart) {
2151
+ return ["$.", false, glob.length - pos, true];
2152
+ }
2153
+ i += cls.length;
2154
+ if (neg)
2155
+ negs.push(unip);
2156
+ else
2157
+ ranges.push(unip);
2158
+ uflag = uflag || u;
2159
+ continue WHILE;
2160
+ }
2161
+ }
2162
+ }
2163
+ escaping = false;
2164
+ if (rangeStart) {
2165
+ if (c > rangeStart) {
2166
+ ranges.push(braceEscape(rangeStart) + "-" + braceEscape(c));
2167
+ } else if (c === rangeStart) {
2168
+ ranges.push(braceEscape(c));
2169
+ }
2170
+ rangeStart = "";
2171
+ i++;
2172
+ continue;
2173
+ }
2174
+ if (glob.startsWith("-]", i + 1)) {
2175
+ ranges.push(braceEscape(c + "-"));
2176
+ i += 2;
2177
+ continue;
2178
+ }
2179
+ if (glob.startsWith("-", i + 1)) {
2180
+ rangeStart = c;
2181
+ i += 2;
2182
+ continue;
2183
+ }
2184
+ ranges.push(braceEscape(c));
2185
+ i++;
2186
+ }
2187
+ if (endPos < i) {
2188
+ return ["", false, 0, false];
2189
+ }
2190
+ if (!ranges.length && !negs.length) {
2191
+ return ["$.", false, glob.length - pos, true];
2192
+ }
2193
+ if (negs.length === 0 && ranges.length === 1 && /^\\?.$/.test(ranges[0]) && !negate) {
2194
+ const r = ranges[0].length === 2 ? ranges[0].slice(-1) : ranges[0];
2195
+ return [regexpEscape(r), false, endPos - pos, false];
2196
+ }
2197
+ const sranges = "[" + (negate ? "^" : "") + rangesToString(ranges) + "]";
2198
+ const snegs = "[" + (negate ? "" : "^") + rangesToString(negs) + "]";
2199
+ const comb = ranges.length && negs.length ? "(" + sranges + "|" + snegs + ")" : ranges.length ? sranges : snegs;
2200
+ return [comb, uflag, endPos - pos, true];
2201
+ };
2202
+
2203
+ // ../../node_modules/.pnpm/minimatch@10.0.3/node_modules/minimatch/dist/esm/unescape.js
2204
+ var unescape = (s, { windowsPathsNoEscape = false } = {}) => {
2205
+ return windowsPathsNoEscape ? s.replace(/\[([^\/\\])\]/g, "$1") : s.replace(/((?!\\).|^)\[([^\/\\])\]/g, "$1$2").replace(/\\([^\/])/g, "$1");
2206
+ };
2207
+
2208
+ // ../../node_modules/.pnpm/minimatch@10.0.3/node_modules/minimatch/dist/esm/ast.js
2209
+ var types = /* @__PURE__ */ new Set(["!", "?", "+", "*", "@"]);
2210
+ var isExtglobType = (c) => types.has(c);
2211
+ var startNoTraversal = "(?!(?:^|/)\\.\\.?(?:$|/))";
2212
+ var startNoDot = "(?!\\.)";
2213
+ var addPatternStart = /* @__PURE__ */ new Set(["[", "."]);
2214
+ var justDots = /* @__PURE__ */ new Set(["..", "."]);
2215
+ var reSpecials = new Set("().*{}+?[]^$\\!");
2216
+ var regExpEscape = (s) => s.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
2217
+ var qmark = "[^/]";
2218
+ var star = qmark + "*?";
2219
+ var starNoEmpty = qmark + "+?";
2220
+ var AST = class _AST {
2221
+ type;
2222
+ #root;
2223
+ #hasMagic;
2224
+ #uflag = false;
2225
+ #parts = [];
2226
+ #parent;
2227
+ #parentIndex;
2228
+ #negs;
2229
+ #filledNegs = false;
2230
+ #options;
2231
+ #toString;
2232
+ // set to true if it's an extglob with no children
2233
+ // (which really means one child of '')
2234
+ #emptyExt = false;
2235
+ constructor(type, parent, options = {}) {
2236
+ this.type = type;
2237
+ if (type)
2238
+ this.#hasMagic = true;
2239
+ this.#parent = parent;
2240
+ this.#root = this.#parent ? this.#parent.#root : this;
2241
+ this.#options = this.#root === this ? options : this.#root.#options;
2242
+ this.#negs = this.#root === this ? [] : this.#root.#negs;
2243
+ if (type === "!" && !this.#root.#filledNegs)
2244
+ this.#negs.push(this);
2245
+ this.#parentIndex = this.#parent ? this.#parent.#parts.length : 0;
2246
+ }
2247
+ get hasMagic() {
2248
+ if (this.#hasMagic !== void 0)
2249
+ return this.#hasMagic;
2250
+ for (const p of this.#parts) {
2251
+ if (typeof p === "string")
2252
+ continue;
2253
+ if (p.type || p.hasMagic)
2254
+ return this.#hasMagic = true;
2255
+ }
2256
+ return this.#hasMagic;
2257
+ }
2258
+ // reconstructs the pattern
2259
+ toString() {
2260
+ if (this.#toString !== void 0)
2261
+ return this.#toString;
2262
+ if (!this.type) {
2263
+ return this.#toString = this.#parts.map((p) => String(p)).join("");
2264
+ } else {
2265
+ return this.#toString = this.type + "(" + this.#parts.map((p) => String(p)).join("|") + ")";
2266
+ }
2267
+ }
2268
+ #fillNegs() {
2269
+ if (this !== this.#root)
2270
+ throw new Error("should only call on root");
2271
+ if (this.#filledNegs)
2272
+ return this;
2273
+ this.toString();
2274
+ this.#filledNegs = true;
2275
+ let n;
2276
+ while (n = this.#negs.pop()) {
2277
+ if (n.type !== "!")
2278
+ continue;
2279
+ let p = n;
2280
+ let pp = p.#parent;
2281
+ while (pp) {
2282
+ for (let i = p.#parentIndex + 1; !pp.type && i < pp.#parts.length; i++) {
2283
+ for (const part of n.#parts) {
2284
+ if (typeof part === "string") {
2285
+ throw new Error("string part in extglob AST??");
2286
+ }
2287
+ part.copyIn(pp.#parts[i]);
2288
+ }
2289
+ }
2290
+ p = pp;
2291
+ pp = p.#parent;
2292
+ }
2293
+ }
2294
+ return this;
2295
+ }
2296
+ push(...parts) {
2297
+ for (const p of parts) {
2298
+ if (p === "")
2299
+ continue;
2300
+ if (typeof p !== "string" && !(p instanceof _AST && p.#parent === this)) {
2301
+ throw new Error("invalid part: " + p);
2302
+ }
2303
+ this.#parts.push(p);
2304
+ }
2305
+ }
2306
+ toJSON() {
2307
+ const ret = this.type === null ? this.#parts.slice().map((p) => typeof p === "string" ? p : p.toJSON()) : [this.type, ...this.#parts.map((p) => p.toJSON())];
2308
+ if (this.isStart() && !this.type)
2309
+ ret.unshift([]);
2310
+ if (this.isEnd() && (this === this.#root || this.#root.#filledNegs && this.#parent?.type === "!")) {
2311
+ ret.push({});
2312
+ }
2313
+ return ret;
2314
+ }
2315
+ isStart() {
2316
+ if (this.#root === this)
2317
+ return true;
2318
+ if (!this.#parent?.isStart())
2319
+ return false;
2320
+ if (this.#parentIndex === 0)
2321
+ return true;
2322
+ const p = this.#parent;
2323
+ for (let i = 0; i < this.#parentIndex; i++) {
2324
+ const pp = p.#parts[i];
2325
+ if (!(pp instanceof _AST && pp.type === "!")) {
2326
+ return false;
2327
+ }
2328
+ }
2329
+ return true;
2330
+ }
2331
+ isEnd() {
2332
+ if (this.#root === this)
2333
+ return true;
2334
+ if (this.#parent?.type === "!")
2335
+ return true;
2336
+ if (!this.#parent?.isEnd())
2337
+ return false;
2338
+ if (!this.type)
2339
+ return this.#parent?.isEnd();
2340
+ const pl = this.#parent ? this.#parent.#parts.length : 0;
2341
+ return this.#parentIndex === pl - 1;
2342
+ }
2343
+ copyIn(part) {
2344
+ if (typeof part === "string")
2345
+ this.push(part);
2346
+ else
2347
+ this.push(part.clone(this));
2348
+ }
2349
+ clone(parent) {
2350
+ const c = new _AST(this.type, parent);
2351
+ for (const p of this.#parts) {
2352
+ c.copyIn(p);
2353
+ }
2354
+ return c;
2355
+ }
2356
+ static #parseAST(str, ast, pos, opt) {
2357
+ let escaping = false;
2358
+ let inBrace = false;
2359
+ let braceStart = -1;
2360
+ let braceNeg = false;
2361
+ if (ast.type === null) {
2362
+ let i2 = pos;
2363
+ let acc2 = "";
2364
+ while (i2 < str.length) {
2365
+ const c = str.charAt(i2++);
2366
+ if (escaping || c === "\\") {
2367
+ escaping = !escaping;
2368
+ acc2 += c;
2369
+ continue;
2370
+ }
2371
+ if (inBrace) {
2372
+ if (i2 === braceStart + 1) {
2373
+ if (c === "^" || c === "!") {
2374
+ braceNeg = true;
2375
+ }
2376
+ } else if (c === "]" && !(i2 === braceStart + 2 && braceNeg)) {
2377
+ inBrace = false;
2378
+ }
2379
+ acc2 += c;
2380
+ continue;
2381
+ } else if (c === "[") {
2382
+ inBrace = true;
2383
+ braceStart = i2;
2384
+ braceNeg = false;
2385
+ acc2 += c;
2386
+ continue;
2387
+ }
2388
+ if (!opt.noext && isExtglobType(c) && str.charAt(i2) === "(") {
2389
+ ast.push(acc2);
2390
+ acc2 = "";
2391
+ const ext2 = new _AST(c, ast);
2392
+ i2 = _AST.#parseAST(str, ext2, i2, opt);
2393
+ ast.push(ext2);
2394
+ continue;
2395
+ }
2396
+ acc2 += c;
2397
+ }
2398
+ ast.push(acc2);
2399
+ return i2;
2400
+ }
2401
+ let i = pos + 1;
2402
+ let part = new _AST(null, ast);
2403
+ const parts = [];
2404
+ let acc = "";
2405
+ while (i < str.length) {
2406
+ const c = str.charAt(i++);
2407
+ if (escaping || c === "\\") {
2408
+ escaping = !escaping;
2409
+ acc += c;
2410
+ continue;
2411
+ }
2412
+ if (inBrace) {
2413
+ if (i === braceStart + 1) {
2414
+ if (c === "^" || c === "!") {
2415
+ braceNeg = true;
2416
+ }
2417
+ } else if (c === "]" && !(i === braceStart + 2 && braceNeg)) {
2418
+ inBrace = false;
2419
+ }
2420
+ acc += c;
2421
+ continue;
2422
+ } else if (c === "[") {
2423
+ inBrace = true;
2424
+ braceStart = i;
2425
+ braceNeg = false;
2426
+ acc += c;
2427
+ continue;
2428
+ }
2429
+ if (isExtglobType(c) && str.charAt(i) === "(") {
2430
+ part.push(acc);
2431
+ acc = "";
2432
+ const ext2 = new _AST(c, part);
2433
+ part.push(ext2);
2434
+ i = _AST.#parseAST(str, ext2, i, opt);
2435
+ continue;
2436
+ }
2437
+ if (c === "|") {
2438
+ part.push(acc);
2439
+ acc = "";
2440
+ parts.push(part);
2441
+ part = new _AST(null, ast);
2442
+ continue;
2443
+ }
2444
+ if (c === ")") {
2445
+ if (acc === "" && ast.#parts.length === 0) {
2446
+ ast.#emptyExt = true;
2447
+ }
2448
+ part.push(acc);
2449
+ acc = "";
2450
+ ast.push(...parts, part);
2451
+ return i;
2452
+ }
2453
+ acc += c;
2454
+ }
2455
+ ast.type = null;
2456
+ ast.#hasMagic = void 0;
2457
+ ast.#parts = [str.substring(pos - 1)];
2458
+ return i;
2459
+ }
2460
+ static fromGlob(pattern, options = {}) {
2461
+ const ast = new _AST(null, void 0, options);
2462
+ _AST.#parseAST(pattern, ast, 0, options);
2463
+ return ast;
2464
+ }
2465
+ // returns the regular expression if there's magic, or the unescaped
2466
+ // string if not.
2467
+ toMMPattern() {
2468
+ if (this !== this.#root)
2469
+ return this.#root.toMMPattern();
2470
+ const glob = this.toString();
2471
+ const [re, body, hasMagic, uflag] = this.toRegExpSource();
2472
+ const anyMagic = hasMagic || this.#hasMagic || this.#options.nocase && !this.#options.nocaseMagicOnly && glob.toUpperCase() !== glob.toLowerCase();
2473
+ if (!anyMagic) {
2474
+ return body;
2475
+ }
2476
+ const flags = (this.#options.nocase ? "i" : "") + (uflag ? "u" : "");
2477
+ return Object.assign(new RegExp(`^${re}$`, flags), {
2478
+ _src: re,
2479
+ _glob: glob
2480
+ });
2481
+ }
2482
+ get options() {
2483
+ return this.#options;
2484
+ }
2485
+ // returns the string match, the regexp source, whether there's magic
2486
+ // in the regexp (so a regular expression is required) and whether or
2487
+ // not the uflag is needed for the regular expression (for posix classes)
2488
+ // TODO: instead of injecting the start/end at this point, just return
2489
+ // the BODY of the regexp, along with the start/end portions suitable
2490
+ // for binding the start/end in either a joined full-path makeRe context
2491
+ // (where we bind to (^|/), or a standalone matchPart context (where
2492
+ // we bind to ^, and not /). Otherwise slashes get duped!
2493
+ //
2494
+ // In part-matching mode, the start is:
2495
+ // - if not isStart: nothing
2496
+ // - if traversal possible, but not allowed: ^(?!\.\.?$)
2497
+ // - if dots allowed or not possible: ^
2498
+ // - if dots possible and not allowed: ^(?!\.)
2499
+ // end is:
2500
+ // - if not isEnd(): nothing
2501
+ // - else: $
2502
+ //
2503
+ // In full-path matching mode, we put the slash at the START of the
2504
+ // pattern, so start is:
2505
+ // - if first pattern: same as part-matching mode
2506
+ // - if not isStart(): nothing
2507
+ // - if traversal possible, but not allowed: /(?!\.\.?(?:$|/))
2508
+ // - if dots allowed or not possible: /
2509
+ // - if dots possible and not allowed: /(?!\.)
2510
+ // end is:
2511
+ // - if last pattern, same as part-matching mode
2512
+ // - else nothing
2513
+ //
2514
+ // Always put the (?:$|/) on negated tails, though, because that has to be
2515
+ // there to bind the end of the negated pattern portion, and it's easier to
2516
+ // just stick it in now rather than try to inject it later in the middle of
2517
+ // the pattern.
2518
+ //
2519
+ // We can just always return the same end, and leave it up to the caller
2520
+ // to know whether it's going to be used joined or in parts.
2521
+ // And, if the start is adjusted slightly, can do the same there:
2522
+ // - if not isStart: nothing
2523
+ // - if traversal possible, but not allowed: (?:/|^)(?!\.\.?$)
2524
+ // - if dots allowed or not possible: (?:/|^)
2525
+ // - if dots possible and not allowed: (?:/|^)(?!\.)
2526
+ //
2527
+ // But it's better to have a simpler binding without a conditional, for
2528
+ // performance, so probably better to return both start options.
2529
+ //
2530
+ // Then the caller just ignores the end if it's not the first pattern,
2531
+ // and the start always gets applied.
2532
+ //
2533
+ // But that's always going to be $ if it's the ending pattern, or nothing,
2534
+ // so the caller can just attach $ at the end of the pattern when building.
2535
+ //
2536
+ // So the todo is:
2537
+ // - better detect what kind of start is needed
2538
+ // - return both flavors of starting pattern
2539
+ // - attach $ at the end of the pattern when creating the actual RegExp
2540
+ //
2541
+ // Ah, but wait, no, that all only applies to the root when the first pattern
2542
+ // is not an extglob. If the first pattern IS an extglob, then we need all
2543
+ // that dot prevention biz to live in the extglob portions, because eg
2544
+ // +(*|.x*) can match .xy but not .yx.
2545
+ //
2546
+ // So, return the two flavors if it's #root and the first child is not an
2547
+ // AST, otherwise leave it to the child AST to handle it, and there,
2548
+ // use the (?:^|/) style of start binding.
2549
+ //
2550
+ // Even simplified further:
2551
+ // - Since the start for a join is eg /(?!\.) and the start for a part
2552
+ // is ^(?!\.), we can just prepend (?!\.) to the pattern (either root
2553
+ // or start or whatever) and prepend ^ or / at the Regexp construction.
2554
+ toRegExpSource(allowDot) {
2555
+ const dot = allowDot ?? !!this.#options.dot;
2556
+ if (this.#root === this)
2557
+ this.#fillNegs();
2558
+ if (!this.type) {
2559
+ const noEmpty = this.isStart() && this.isEnd();
2560
+ const src = this.#parts.map((p) => {
2561
+ const [re, _, hasMagic, uflag] = typeof p === "string" ? _AST.#parseGlob(p, this.#hasMagic, noEmpty) : p.toRegExpSource(allowDot);
2562
+ this.#hasMagic = this.#hasMagic || hasMagic;
2563
+ this.#uflag = this.#uflag || uflag;
2564
+ return re;
2565
+ }).join("");
2566
+ let start2 = "";
2567
+ if (this.isStart()) {
2568
+ if (typeof this.#parts[0] === "string") {
2569
+ const dotTravAllowed = this.#parts.length === 1 && justDots.has(this.#parts[0]);
2570
+ if (!dotTravAllowed) {
2571
+ const aps = addPatternStart;
2572
+ const needNoTrav = (
2573
+ // dots are allowed, and the pattern starts with [ or .
2574
+ dot && aps.has(src.charAt(0)) || // the pattern starts with \., and then [ or .
2575
+ src.startsWith("\\.") && aps.has(src.charAt(2)) || // the pattern starts with \.\., and then [ or .
2576
+ src.startsWith("\\.\\.") && aps.has(src.charAt(4))
2577
+ );
2578
+ const needNoDot = !dot && !allowDot && aps.has(src.charAt(0));
2579
+ start2 = needNoTrav ? startNoTraversal : needNoDot ? startNoDot : "";
2580
+ }
2581
+ }
2582
+ }
2583
+ let end = "";
2584
+ if (this.isEnd() && this.#root.#filledNegs && this.#parent?.type === "!") {
2585
+ end = "(?:$|\\/)";
2586
+ }
2587
+ const final2 = start2 + src + end;
2588
+ return [
2589
+ final2,
2590
+ unescape(src),
2591
+ this.#hasMagic = !!this.#hasMagic,
2592
+ this.#uflag
2593
+ ];
2594
+ }
2595
+ const repeated = this.type === "*" || this.type === "+";
2596
+ const start = this.type === "!" ? "(?:(?!(?:" : "(?:";
2597
+ let body = this.#partsToRegExp(dot);
2598
+ if (this.isStart() && this.isEnd() && !body && this.type !== "!") {
2599
+ const s = this.toString();
2600
+ this.#parts = [s];
2601
+ this.type = null;
2602
+ this.#hasMagic = void 0;
2603
+ return [s, unescape(this.toString()), false, false];
2604
+ }
2605
+ let bodyDotAllowed = !repeated || allowDot || dot || !startNoDot ? "" : this.#partsToRegExp(true);
2606
+ if (bodyDotAllowed === body) {
2607
+ bodyDotAllowed = "";
2608
+ }
2609
+ if (bodyDotAllowed) {
2610
+ body = `(?:${body})(?:${bodyDotAllowed})*?`;
2611
+ }
2612
+ let final = "";
2613
+ if (this.type === "!" && this.#emptyExt) {
2614
+ final = (this.isStart() && !dot ? startNoDot : "") + starNoEmpty;
2615
+ } else {
2616
+ const close = this.type === "!" ? (
2617
+ // !() must match something,but !(x) can match ''
2618
+ "))" + (this.isStart() && !dot && !allowDot ? startNoDot : "") + star + ")"
2619
+ ) : this.type === "@" ? ")" : this.type === "?" ? ")?" : this.type === "+" && bodyDotAllowed ? ")" : this.type === "*" && bodyDotAllowed ? `)?` : `)${this.type}`;
2620
+ final = start + body + close;
2621
+ }
2622
+ return [
2623
+ final,
2624
+ unescape(body),
2625
+ this.#hasMagic = !!this.#hasMagic,
2626
+ this.#uflag
2627
+ ];
2628
+ }
2629
+ #partsToRegExp(dot) {
2630
+ return this.#parts.map((p) => {
2631
+ if (typeof p === "string") {
2632
+ throw new Error("string type in extglob ast??");
2633
+ }
2634
+ const [re, _, _hasMagic, uflag] = p.toRegExpSource(dot);
2635
+ this.#uflag = this.#uflag || uflag;
2636
+ return re;
2637
+ }).filter((p) => !(this.isStart() && this.isEnd()) || !!p).join("|");
2638
+ }
2639
+ static #parseGlob(glob, hasMagic, noEmpty = false) {
2640
+ let escaping = false;
2641
+ let re = "";
2642
+ let uflag = false;
2643
+ for (let i = 0; i < glob.length; i++) {
2644
+ const c = glob.charAt(i);
2645
+ if (escaping) {
2646
+ escaping = false;
2647
+ re += (reSpecials.has(c) ? "\\" : "") + c;
2648
+ continue;
2649
+ }
2650
+ if (c === "\\") {
2651
+ if (i === glob.length - 1) {
2652
+ re += "\\\\";
2653
+ } else {
2654
+ escaping = true;
2655
+ }
2656
+ continue;
2657
+ }
2658
+ if (c === "[") {
2659
+ const [src, needUflag, consumed, magic] = parseClass(glob, i);
2660
+ if (consumed) {
2661
+ re += src;
2662
+ uflag = uflag || needUflag;
2663
+ i += consumed - 1;
2664
+ hasMagic = hasMagic || magic;
2665
+ continue;
2666
+ }
2667
+ }
2668
+ if (c === "*") {
2669
+ if (noEmpty && glob === "*")
2670
+ re += starNoEmpty;
2671
+ else
2672
+ re += star;
2673
+ hasMagic = true;
2674
+ continue;
2675
+ }
2676
+ if (c === "?") {
2677
+ re += qmark;
2678
+ hasMagic = true;
2679
+ continue;
2680
+ }
2681
+ re += regExpEscape(c);
2682
+ }
2683
+ return [re, unescape(glob), !!hasMagic, uflag];
2684
+ }
2685
+ };
2686
+
2687
+ // ../../node_modules/.pnpm/minimatch@10.0.3/node_modules/minimatch/dist/esm/escape.js
2688
+ var escape = (s, { windowsPathsNoEscape = false } = {}) => {
2689
+ return windowsPathsNoEscape ? s.replace(/[?*()[\]]/g, "[$&]") : s.replace(/[?*()[\]\\]/g, "\\$&");
2690
+ };
2691
+
2692
+ // ../../node_modules/.pnpm/minimatch@10.0.3/node_modules/minimatch/dist/esm/index.js
2693
+ var minimatch = (p, pattern, options = {}) => {
2694
+ assertValidPattern(pattern);
2695
+ if (!options.nocomment && pattern.charAt(0) === "#") {
2696
+ return false;
2697
+ }
2698
+ return new Minimatch(pattern, options).match(p);
2699
+ };
2700
+ var starDotExtRE = /^\*+([^+@!?\*\[\(]*)$/;
2701
+ var starDotExtTest = (ext2) => (f) => !f.startsWith(".") && f.endsWith(ext2);
2702
+ var starDotExtTestDot = (ext2) => (f) => f.endsWith(ext2);
2703
+ var starDotExtTestNocase = (ext2) => {
2704
+ ext2 = ext2.toLowerCase();
2705
+ return (f) => !f.startsWith(".") && f.toLowerCase().endsWith(ext2);
2706
+ };
2707
+ var starDotExtTestNocaseDot = (ext2) => {
2708
+ ext2 = ext2.toLowerCase();
2709
+ return (f) => f.toLowerCase().endsWith(ext2);
2710
+ };
2711
+ var starDotStarRE = /^\*+\.\*+$/;
2712
+ var starDotStarTest = (f) => !f.startsWith(".") && f.includes(".");
2713
+ var starDotStarTestDot = (f) => f !== "." && f !== ".." && f.includes(".");
2714
+ var dotStarRE = /^\.\*+$/;
2715
+ var dotStarTest = (f) => f !== "." && f !== ".." && f.startsWith(".");
2716
+ var starRE = /^\*+$/;
2717
+ var starTest = (f) => f.length !== 0 && !f.startsWith(".");
2718
+ var starTestDot = (f) => f.length !== 0 && f !== "." && f !== "..";
2719
+ var qmarksRE = /^\?+([^+@!?\*\[\(]*)?$/;
2720
+ var qmarksTestNocase = ([$0, ext2 = ""]) => {
2721
+ const noext = qmarksTestNoExt([$0]);
2722
+ if (!ext2)
2723
+ return noext;
2724
+ ext2 = ext2.toLowerCase();
2725
+ return (f) => noext(f) && f.toLowerCase().endsWith(ext2);
2726
+ };
2727
+ var qmarksTestNocaseDot = ([$0, ext2 = ""]) => {
2728
+ const noext = qmarksTestNoExtDot([$0]);
2729
+ if (!ext2)
2730
+ return noext;
2731
+ ext2 = ext2.toLowerCase();
2732
+ return (f) => noext(f) && f.toLowerCase().endsWith(ext2);
2733
+ };
2734
+ var qmarksTestDot = ([$0, ext2 = ""]) => {
2735
+ const noext = qmarksTestNoExtDot([$0]);
2736
+ return !ext2 ? noext : (f) => noext(f) && f.endsWith(ext2);
2737
+ };
2738
+ var qmarksTest = ([$0, ext2 = ""]) => {
2739
+ const noext = qmarksTestNoExt([$0]);
2740
+ return !ext2 ? noext : (f) => noext(f) && f.endsWith(ext2);
2741
+ };
2742
+ var qmarksTestNoExt = ([$0]) => {
2743
+ const len = $0.length;
2744
+ return (f) => f.length === len && !f.startsWith(".");
2745
+ };
2746
+ var qmarksTestNoExtDot = ([$0]) => {
2747
+ const len = $0.length;
2748
+ return (f) => f.length === len && f !== "." && f !== "..";
2749
+ };
2750
+ var defaultPlatform = typeof process === "object" && process ? typeof process.env === "object" && process.env && process.env.__MINIMATCH_TESTING_PLATFORM__ || process.platform : "posix";
2751
+ var path3 = {
2752
+ win32: { sep: "\\" },
2753
+ posix: { sep: "/" }
2754
+ };
2755
+ var sep = defaultPlatform === "win32" ? path3.win32.sep : path3.posix.sep;
2756
+ minimatch.sep = sep;
2757
+ var GLOBSTAR = /* @__PURE__ */ Symbol("globstar **");
2758
+ minimatch.GLOBSTAR = GLOBSTAR;
2759
+ var qmark2 = "[^/]";
2760
+ var star2 = qmark2 + "*?";
2761
+ var twoStarDot = "(?:(?!(?:\\/|^)(?:\\.{1,2})($|\\/)).)*?";
2762
+ var twoStarNoDot = "(?:(?!(?:\\/|^)\\.).)*?";
2763
+ var filter = (pattern, options = {}) => (p) => minimatch(p, pattern, options);
2764
+ minimatch.filter = filter;
2765
+ var ext = (a, b = {}) => Object.assign({}, a, b);
2766
+ var defaults = (def) => {
2767
+ if (!def || typeof def !== "object" || !Object.keys(def).length) {
2768
+ return minimatch;
2769
+ }
2770
+ const orig = minimatch;
2771
+ const m = (p, pattern, options = {}) => orig(p, pattern, ext(def, options));
2772
+ return Object.assign(m, {
2773
+ Minimatch: class Minimatch extends orig.Minimatch {
2774
+ constructor(pattern, options = {}) {
2775
+ super(pattern, ext(def, options));
2776
+ }
2777
+ static defaults(options) {
2778
+ return orig.defaults(ext(def, options)).Minimatch;
2779
+ }
2780
+ },
2781
+ AST: class AST extends orig.AST {
2782
+ /* c8 ignore start */
2783
+ constructor(type, parent, options = {}) {
2784
+ super(type, parent, ext(def, options));
2785
+ }
2786
+ /* c8 ignore stop */
2787
+ static fromGlob(pattern, options = {}) {
2788
+ return orig.AST.fromGlob(pattern, ext(def, options));
2789
+ }
2790
+ },
2791
+ unescape: (s, options = {}) => orig.unescape(s, ext(def, options)),
2792
+ escape: (s, options = {}) => orig.escape(s, ext(def, options)),
2793
+ filter: (pattern, options = {}) => orig.filter(pattern, ext(def, options)),
2794
+ defaults: (options) => orig.defaults(ext(def, options)),
2795
+ makeRe: (pattern, options = {}) => orig.makeRe(pattern, ext(def, options)),
2796
+ braceExpand: (pattern, options = {}) => orig.braceExpand(pattern, ext(def, options)),
2797
+ match: (list, pattern, options = {}) => orig.match(list, pattern, ext(def, options)),
2798
+ sep: orig.sep,
2799
+ GLOBSTAR
2800
+ });
2801
+ };
2802
+ minimatch.defaults = defaults;
2803
+ var braceExpand = (pattern, options = {}) => {
2804
+ assertValidPattern(pattern);
2805
+ if (options.nobrace || !/\{(?:(?!\{).)*\}/.test(pattern)) {
2806
+ return [pattern];
2807
+ }
2808
+ return expand(pattern);
2809
+ };
2810
+ minimatch.braceExpand = braceExpand;
2811
+ var makeRe = (pattern, options = {}) => new Minimatch(pattern, options).makeRe();
2812
+ minimatch.makeRe = makeRe;
2813
+ var match = (list, pattern, options = {}) => {
2814
+ const mm = new Minimatch(pattern, options);
2815
+ list = list.filter((f) => mm.match(f));
2816
+ if (mm.options.nonull && !list.length) {
2817
+ list.push(pattern);
2818
+ }
2819
+ return list;
2820
+ };
2821
+ minimatch.match = match;
2822
+ var globMagic = /[?*]|[+@!]\(.*?\)|\[|\]/;
2823
+ var regExpEscape2 = (s) => s.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
2824
+ var Minimatch = class {
2825
+ options;
2826
+ set;
2827
+ pattern;
2828
+ windowsPathsNoEscape;
2829
+ nonegate;
2830
+ negate;
2831
+ comment;
2832
+ empty;
2833
+ preserveMultipleSlashes;
2834
+ partial;
2835
+ globSet;
2836
+ globParts;
2837
+ nocase;
2838
+ isWindows;
2839
+ platform;
2840
+ windowsNoMagicRoot;
2841
+ regexp;
2842
+ constructor(pattern, options = {}) {
2843
+ assertValidPattern(pattern);
2844
+ options = options || {};
2845
+ this.options = options;
2846
+ this.pattern = pattern;
2847
+ this.platform = options.platform || defaultPlatform;
2848
+ this.isWindows = this.platform === "win32";
2849
+ this.windowsPathsNoEscape = !!options.windowsPathsNoEscape || options.allowWindowsEscape === false;
2850
+ if (this.windowsPathsNoEscape) {
2851
+ this.pattern = this.pattern.replace(/\\/g, "/");
2852
+ }
2853
+ this.preserveMultipleSlashes = !!options.preserveMultipleSlashes;
2854
+ this.regexp = null;
2855
+ this.negate = false;
2856
+ this.nonegate = !!options.nonegate;
2857
+ this.comment = false;
2858
+ this.empty = false;
2859
+ this.partial = !!options.partial;
2860
+ this.nocase = !!this.options.nocase;
2861
+ this.windowsNoMagicRoot = options.windowsNoMagicRoot !== void 0 ? options.windowsNoMagicRoot : !!(this.isWindows && this.nocase);
2862
+ this.globSet = [];
2863
+ this.globParts = [];
2864
+ this.set = [];
2865
+ this.make();
2866
+ }
2867
+ hasMagic() {
2868
+ if (this.options.magicalBraces && this.set.length > 1) {
2869
+ return true;
2870
+ }
2871
+ for (const pattern of this.set) {
2872
+ for (const part of pattern) {
2873
+ if (typeof part !== "string")
2874
+ return true;
2875
+ }
2876
+ }
2877
+ return false;
2878
+ }
2879
+ debug(..._) {
2880
+ }
2881
+ make() {
2882
+ const pattern = this.pattern;
2883
+ const options = this.options;
2884
+ if (!options.nocomment && pattern.charAt(0) === "#") {
2885
+ this.comment = true;
2886
+ return;
2887
+ }
2888
+ if (!pattern) {
2889
+ this.empty = true;
2890
+ return;
2891
+ }
2892
+ this.parseNegate();
2893
+ this.globSet = [...new Set(this.braceExpand())];
2894
+ if (options.debug) {
2895
+ this.debug = (...args) => console.error(...args);
2896
+ }
2897
+ this.debug(this.pattern, this.globSet);
2898
+ const rawGlobParts = this.globSet.map((s) => this.slashSplit(s));
2899
+ this.globParts = this.preprocess(rawGlobParts);
2900
+ this.debug(this.pattern, this.globParts);
2901
+ let set = this.globParts.map((s, _, __) => {
2902
+ if (this.isWindows && this.windowsNoMagicRoot) {
2903
+ const isUNC = s[0] === "" && s[1] === "" && (s[2] === "?" || !globMagic.test(s[2])) && !globMagic.test(s[3]);
2904
+ const isDrive = /^[a-z]:/i.test(s[0]);
2905
+ if (isUNC) {
2906
+ return [...s.slice(0, 4), ...s.slice(4).map((ss) => this.parse(ss))];
2907
+ } else if (isDrive) {
2908
+ return [s[0], ...s.slice(1).map((ss) => this.parse(ss))];
2909
+ }
2910
+ }
2911
+ return s.map((ss) => this.parse(ss));
2912
+ });
2913
+ this.debug(this.pattern, set);
2914
+ this.set = set.filter((s) => s.indexOf(false) === -1);
2915
+ if (this.isWindows) {
2916
+ for (let i = 0; i < this.set.length; i++) {
2917
+ const p = this.set[i];
2918
+ if (p[0] === "" && p[1] === "" && this.globParts[i][2] === "?" && typeof p[3] === "string" && /^[a-z]:$/i.test(p[3])) {
2919
+ p[2] = "?";
2920
+ }
2921
+ }
2922
+ }
2923
+ this.debug(this.pattern, this.set);
2924
+ }
2925
+ // various transforms to equivalent pattern sets that are
2926
+ // faster to process in a filesystem walk. The goal is to
2927
+ // eliminate what we can, and push all ** patterns as far
2928
+ // to the right as possible, even if it increases the number
2929
+ // of patterns that we have to process.
2930
+ preprocess(globParts) {
2931
+ if (this.options.noglobstar) {
2932
+ for (let i = 0; i < globParts.length; i++) {
2933
+ for (let j = 0; j < globParts[i].length; j++) {
2934
+ if (globParts[i][j] === "**") {
2935
+ globParts[i][j] = "*";
2936
+ }
2937
+ }
2938
+ }
2939
+ }
2940
+ const { optimizationLevel = 1 } = this.options;
2941
+ if (optimizationLevel >= 2) {
2942
+ globParts = this.firstPhasePreProcess(globParts);
2943
+ globParts = this.secondPhasePreProcess(globParts);
2944
+ } else if (optimizationLevel >= 1) {
2945
+ globParts = this.levelOneOptimize(globParts);
2946
+ } else {
2947
+ globParts = this.adjascentGlobstarOptimize(globParts);
2948
+ }
2949
+ return globParts;
2950
+ }
2951
+ // just get rid of adjascent ** portions
2952
+ adjascentGlobstarOptimize(globParts) {
2953
+ return globParts.map((parts) => {
2954
+ let gs = -1;
2955
+ while (-1 !== (gs = parts.indexOf("**", gs + 1))) {
2956
+ let i = gs;
2957
+ while (parts[i + 1] === "**") {
2958
+ i++;
2959
+ }
2960
+ if (i !== gs) {
2961
+ parts.splice(gs, i - gs);
2962
+ }
2963
+ }
2964
+ return parts;
2965
+ });
2966
+ }
2967
+ // get rid of adjascent ** and resolve .. portions
2968
+ levelOneOptimize(globParts) {
2969
+ return globParts.map((parts) => {
2970
+ parts = parts.reduce((set, part) => {
2971
+ const prev = set[set.length - 1];
2972
+ if (part === "**" && prev === "**") {
2973
+ return set;
2974
+ }
2975
+ if (part === "..") {
2976
+ if (prev && prev !== ".." && prev !== "." && prev !== "**") {
2977
+ set.pop();
2978
+ return set;
2979
+ }
2980
+ }
2981
+ set.push(part);
2982
+ return set;
2983
+ }, []);
2984
+ return parts.length === 0 ? [""] : parts;
2985
+ });
2986
+ }
2987
+ levelTwoFileOptimize(parts) {
2988
+ if (!Array.isArray(parts)) {
2989
+ parts = this.slashSplit(parts);
2990
+ }
2991
+ let didSomething = false;
2992
+ do {
2993
+ didSomething = false;
2994
+ if (!this.preserveMultipleSlashes) {
2995
+ for (let i = 1; i < parts.length - 1; i++) {
2996
+ const p = parts[i];
2997
+ if (i === 1 && p === "" && parts[0] === "")
2998
+ continue;
2999
+ if (p === "." || p === "") {
3000
+ didSomething = true;
3001
+ parts.splice(i, 1);
3002
+ i--;
3003
+ }
3004
+ }
3005
+ if (parts[0] === "." && parts.length === 2 && (parts[1] === "." || parts[1] === "")) {
3006
+ didSomething = true;
3007
+ parts.pop();
3008
+ }
3009
+ }
3010
+ let dd = 0;
3011
+ while (-1 !== (dd = parts.indexOf("..", dd + 1))) {
3012
+ const p = parts[dd - 1];
3013
+ if (p && p !== "." && p !== ".." && p !== "**") {
3014
+ didSomething = true;
3015
+ parts.splice(dd - 1, 2);
3016
+ dd -= 2;
3017
+ }
3018
+ }
3019
+ } while (didSomething);
3020
+ return parts.length === 0 ? [""] : parts;
3021
+ }
3022
+ // First phase: single-pattern processing
3023
+ // <pre> is 1 or more portions
3024
+ // <rest> is 1 or more portions
3025
+ // <p> is any portion other than ., .., '', or **
3026
+ // <e> is . or ''
3027
+ //
3028
+ // **/.. is *brutal* for filesystem walking performance, because
3029
+ // it effectively resets the recursive walk each time it occurs,
3030
+ // and ** cannot be reduced out by a .. pattern part like a regexp
3031
+ // or most strings (other than .., ., and '') can be.
3032
+ //
3033
+ // <pre>/**/../<p>/<p>/<rest> -> {<pre>/../<p>/<p>/<rest>,<pre>/**/<p>/<p>/<rest>}
3034
+ // <pre>/<e>/<rest> -> <pre>/<rest>
3035
+ // <pre>/<p>/../<rest> -> <pre>/<rest>
3036
+ // **/**/<rest> -> **/<rest>
3037
+ //
3038
+ // **/*/<rest> -> */**/<rest> <== not valid because ** doesn't follow
3039
+ // this WOULD be allowed if ** did follow symlinks, or * didn't
3040
+ firstPhasePreProcess(globParts) {
3041
+ let didSomething = false;
3042
+ do {
3043
+ didSomething = false;
3044
+ for (let parts of globParts) {
3045
+ let gs = -1;
3046
+ while (-1 !== (gs = parts.indexOf("**", gs + 1))) {
3047
+ let gss = gs;
3048
+ while (parts[gss + 1] === "**") {
3049
+ gss++;
3050
+ }
3051
+ if (gss > gs) {
3052
+ parts.splice(gs + 1, gss - gs);
3053
+ }
3054
+ let next = parts[gs + 1];
3055
+ const p = parts[gs + 2];
3056
+ const p2 = parts[gs + 3];
3057
+ if (next !== "..")
3058
+ continue;
3059
+ if (!p || p === "." || p === ".." || !p2 || p2 === "." || p2 === "..") {
3060
+ continue;
3061
+ }
3062
+ didSomething = true;
3063
+ parts.splice(gs, 1);
3064
+ const other = parts.slice(0);
3065
+ other[gs] = "**";
3066
+ globParts.push(other);
3067
+ gs--;
3068
+ }
3069
+ if (!this.preserveMultipleSlashes) {
3070
+ for (let i = 1; i < parts.length - 1; i++) {
3071
+ const p = parts[i];
3072
+ if (i === 1 && p === "" && parts[0] === "")
3073
+ continue;
3074
+ if (p === "." || p === "") {
3075
+ didSomething = true;
3076
+ parts.splice(i, 1);
3077
+ i--;
3078
+ }
3079
+ }
3080
+ if (parts[0] === "." && parts.length === 2 && (parts[1] === "." || parts[1] === "")) {
3081
+ didSomething = true;
3082
+ parts.pop();
3083
+ }
3084
+ }
3085
+ let dd = 0;
3086
+ while (-1 !== (dd = parts.indexOf("..", dd + 1))) {
3087
+ const p = parts[dd - 1];
3088
+ if (p && p !== "." && p !== ".." && p !== "**") {
3089
+ didSomething = true;
3090
+ const needDot = dd === 1 && parts[dd + 1] === "**";
3091
+ const splin = needDot ? ["."] : [];
3092
+ parts.splice(dd - 1, 2, ...splin);
3093
+ if (parts.length === 0)
3094
+ parts.push("");
3095
+ dd -= 2;
3096
+ }
3097
+ }
3098
+ }
3099
+ } while (didSomething);
3100
+ return globParts;
3101
+ }
3102
+ // second phase: multi-pattern dedupes
3103
+ // {<pre>/*/<rest>,<pre>/<p>/<rest>} -> <pre>/*/<rest>
3104
+ // {<pre>/<rest>,<pre>/<rest>} -> <pre>/<rest>
3105
+ // {<pre>/**/<rest>,<pre>/<rest>} -> <pre>/**/<rest>
3106
+ //
3107
+ // {<pre>/**/<rest>,<pre>/**/<p>/<rest>} -> <pre>/**/<rest>
3108
+ // ^-- not valid because ** doens't follow symlinks
3109
+ secondPhasePreProcess(globParts) {
3110
+ for (let i = 0; i < globParts.length - 1; i++) {
3111
+ for (let j = i + 1; j < globParts.length; j++) {
3112
+ const matched = this.partsMatch(globParts[i], globParts[j], !this.preserveMultipleSlashes);
3113
+ if (matched) {
3114
+ globParts[i] = [];
3115
+ globParts[j] = matched;
3116
+ break;
3117
+ }
3118
+ }
3119
+ }
3120
+ return globParts.filter((gs) => gs.length);
3121
+ }
3122
+ partsMatch(a, b, emptyGSMatch = false) {
3123
+ let ai = 0;
3124
+ let bi = 0;
3125
+ let result = [];
3126
+ let which = "";
3127
+ while (ai < a.length && bi < b.length) {
3128
+ if (a[ai] === b[bi]) {
3129
+ result.push(which === "b" ? b[bi] : a[ai]);
3130
+ ai++;
3131
+ bi++;
3132
+ } else if (emptyGSMatch && a[ai] === "**" && b[bi] === a[ai + 1]) {
3133
+ result.push(a[ai]);
3134
+ ai++;
3135
+ } else if (emptyGSMatch && b[bi] === "**" && a[ai] === b[bi + 1]) {
3136
+ result.push(b[bi]);
3137
+ bi++;
3138
+ } else if (a[ai] === "*" && b[bi] && (this.options.dot || !b[bi].startsWith(".")) && b[bi] !== "**") {
3139
+ if (which === "b")
3140
+ return false;
3141
+ which = "a";
3142
+ result.push(a[ai]);
3143
+ ai++;
3144
+ bi++;
3145
+ } else if (b[bi] === "*" && a[ai] && (this.options.dot || !a[ai].startsWith(".")) && a[ai] !== "**") {
3146
+ if (which === "a")
3147
+ return false;
3148
+ which = "b";
3149
+ result.push(b[bi]);
3150
+ ai++;
3151
+ bi++;
3152
+ } else {
3153
+ return false;
3154
+ }
3155
+ }
3156
+ return a.length === b.length && result;
3157
+ }
3158
+ parseNegate() {
3159
+ if (this.nonegate)
3160
+ return;
3161
+ const pattern = this.pattern;
3162
+ let negate = false;
3163
+ let negateOffset = 0;
3164
+ for (let i = 0; i < pattern.length && pattern.charAt(i) === "!"; i++) {
3165
+ negate = !negate;
3166
+ negateOffset++;
3167
+ }
3168
+ if (negateOffset)
3169
+ this.pattern = pattern.slice(negateOffset);
3170
+ this.negate = negate;
3171
+ }
3172
+ // set partial to true to test if, for example,
3173
+ // "/a/b" matches the start of "/*/b/*/d"
3174
+ // Partial means, if you run out of file before you run
3175
+ // out of pattern, then that's fine, as long as all
3176
+ // the parts match.
3177
+ matchOne(file, pattern, partial = false) {
3178
+ const options = this.options;
3179
+ if (this.isWindows) {
3180
+ const fileDrive = typeof file[0] === "string" && /^[a-z]:$/i.test(file[0]);
3181
+ const fileUNC = !fileDrive && file[0] === "" && file[1] === "" && file[2] === "?" && /^[a-z]:$/i.test(file[3]);
3182
+ const patternDrive = typeof pattern[0] === "string" && /^[a-z]:$/i.test(pattern[0]);
3183
+ const patternUNC = !patternDrive && pattern[0] === "" && pattern[1] === "" && pattern[2] === "?" && typeof pattern[3] === "string" && /^[a-z]:$/i.test(pattern[3]);
3184
+ const fdi = fileUNC ? 3 : fileDrive ? 0 : void 0;
3185
+ const pdi = patternUNC ? 3 : patternDrive ? 0 : void 0;
3186
+ if (typeof fdi === "number" && typeof pdi === "number") {
3187
+ const [fd, pd] = [file[fdi], pattern[pdi]];
3188
+ if (fd.toLowerCase() === pd.toLowerCase()) {
3189
+ pattern[pdi] = fd;
3190
+ if (pdi > fdi) {
3191
+ pattern = pattern.slice(pdi);
3192
+ } else if (fdi > pdi) {
3193
+ file = file.slice(fdi);
3194
+ }
3195
+ }
3196
+ }
3197
+ }
3198
+ const { optimizationLevel = 1 } = this.options;
3199
+ if (optimizationLevel >= 2) {
3200
+ file = this.levelTwoFileOptimize(file);
3201
+ }
3202
+ this.debug("matchOne", this, { file, pattern });
3203
+ this.debug("matchOne", file.length, pattern.length);
3204
+ for (var fi = 0, pi = 0, fl = file.length, pl = pattern.length; fi < fl && pi < pl; fi++, pi++) {
3205
+ this.debug("matchOne loop");
3206
+ var p = pattern[pi];
3207
+ var f = file[fi];
3208
+ this.debug(pattern, p, f);
3209
+ if (p === false) {
3210
+ return false;
3211
+ }
3212
+ if (p === GLOBSTAR) {
3213
+ this.debug("GLOBSTAR", [pattern, p, f]);
3214
+ var fr = fi;
3215
+ var pr = pi + 1;
3216
+ if (pr === pl) {
3217
+ this.debug("** at the end");
3218
+ for (; fi < fl; fi++) {
3219
+ if (file[fi] === "." || file[fi] === ".." || !options.dot && file[fi].charAt(0) === ".")
3220
+ return false;
3221
+ }
3222
+ return true;
3223
+ }
3224
+ while (fr < fl) {
3225
+ var swallowee = file[fr];
3226
+ this.debug("\nglobstar while", file, fr, pattern, pr, swallowee);
3227
+ if (this.matchOne(file.slice(fr), pattern.slice(pr), partial)) {
3228
+ this.debug("globstar found match!", fr, fl, swallowee);
3229
+ return true;
3230
+ } else {
3231
+ if (swallowee === "." || swallowee === ".." || !options.dot && swallowee.charAt(0) === ".") {
3232
+ this.debug("dot detected!", file, fr, pattern, pr);
3233
+ break;
3234
+ }
3235
+ this.debug("globstar swallow a segment, and continue");
3236
+ fr++;
3237
+ }
3238
+ }
3239
+ if (partial) {
3240
+ this.debug("\n>>> no match, partial?", file, fr, pattern, pr);
3241
+ if (fr === fl) {
3242
+ return true;
3243
+ }
3244
+ }
3245
+ return false;
3246
+ }
3247
+ let hit;
3248
+ if (typeof p === "string") {
3249
+ hit = f === p;
3250
+ this.debug("string match", p, f, hit);
3251
+ } else {
3252
+ hit = p.test(f);
3253
+ this.debug("pattern match", p, f, hit);
3254
+ }
3255
+ if (!hit)
3256
+ return false;
3257
+ }
3258
+ if (fi === fl && pi === pl) {
3259
+ return true;
3260
+ } else if (fi === fl) {
3261
+ return partial;
3262
+ } else if (pi === pl) {
3263
+ return fi === fl - 1 && file[fi] === "";
3264
+ } else {
3265
+ throw new Error("wtf?");
3266
+ }
3267
+ }
3268
+ braceExpand() {
3269
+ return braceExpand(this.pattern, this.options);
3270
+ }
3271
+ parse(pattern) {
3272
+ assertValidPattern(pattern);
3273
+ const options = this.options;
3274
+ if (pattern === "**")
3275
+ return GLOBSTAR;
3276
+ if (pattern === "")
3277
+ return "";
3278
+ let m;
3279
+ let fastTest = null;
3280
+ if (m = pattern.match(starRE)) {
3281
+ fastTest = options.dot ? starTestDot : starTest;
3282
+ } else if (m = pattern.match(starDotExtRE)) {
3283
+ fastTest = (options.nocase ? options.dot ? starDotExtTestNocaseDot : starDotExtTestNocase : options.dot ? starDotExtTestDot : starDotExtTest)(m[1]);
3284
+ } else if (m = pattern.match(qmarksRE)) {
3285
+ fastTest = (options.nocase ? options.dot ? qmarksTestNocaseDot : qmarksTestNocase : options.dot ? qmarksTestDot : qmarksTest)(m);
3286
+ } else if (m = pattern.match(starDotStarRE)) {
3287
+ fastTest = options.dot ? starDotStarTestDot : starDotStarTest;
3288
+ } else if (m = pattern.match(dotStarRE)) {
3289
+ fastTest = dotStarTest;
3290
+ }
3291
+ const re = AST.fromGlob(pattern, this.options).toMMPattern();
3292
+ if (fastTest && typeof re === "object") {
3293
+ Reflect.defineProperty(re, "test", { value: fastTest });
3294
+ }
3295
+ return re;
3296
+ }
3297
+ makeRe() {
3298
+ if (this.regexp || this.regexp === false)
3299
+ return this.regexp;
3300
+ const set = this.set;
3301
+ if (!set.length) {
3302
+ this.regexp = false;
3303
+ return this.regexp;
3304
+ }
3305
+ const options = this.options;
3306
+ const twoStar = options.noglobstar ? star2 : options.dot ? twoStarDot : twoStarNoDot;
3307
+ const flags = new Set(options.nocase ? ["i"] : []);
3308
+ let re = set.map((pattern) => {
3309
+ const pp = pattern.map((p) => {
3310
+ if (p instanceof RegExp) {
3311
+ for (const f of p.flags.split(""))
3312
+ flags.add(f);
3313
+ }
3314
+ return typeof p === "string" ? regExpEscape2(p) : p === GLOBSTAR ? GLOBSTAR : p._src;
3315
+ });
3316
+ pp.forEach((p, i) => {
3317
+ const next = pp[i + 1];
3318
+ const prev = pp[i - 1];
3319
+ if (p !== GLOBSTAR || prev === GLOBSTAR) {
3320
+ return;
3321
+ }
3322
+ if (prev === void 0) {
3323
+ if (next !== void 0 && next !== GLOBSTAR) {
3324
+ pp[i + 1] = "(?:\\/|" + twoStar + "\\/)?" + next;
3325
+ } else {
3326
+ pp[i] = twoStar;
3327
+ }
3328
+ } else if (next === void 0) {
3329
+ pp[i - 1] = prev + "(?:\\/|" + twoStar + ")?";
3330
+ } else if (next !== GLOBSTAR) {
3331
+ pp[i - 1] = prev + "(?:\\/|\\/" + twoStar + "\\/)" + next;
3332
+ pp[i + 1] = GLOBSTAR;
3333
+ }
3334
+ });
3335
+ return pp.filter((p) => p !== GLOBSTAR).join("/");
3336
+ }).join("|");
3337
+ const [open, close] = set.length > 1 ? ["(?:", ")"] : ["", ""];
3338
+ re = "^" + open + re + close + "$";
3339
+ if (this.negate)
3340
+ re = "^(?!" + re + ").+$";
3341
+ try {
3342
+ this.regexp = new RegExp(re, [...flags].join(""));
3343
+ } catch (ex) {
3344
+ this.regexp = false;
3345
+ }
3346
+ return this.regexp;
3347
+ }
3348
+ slashSplit(p) {
3349
+ if (this.preserveMultipleSlashes) {
3350
+ return p.split("/");
3351
+ } else if (this.isWindows && /^\/\/[^\/]+/.test(p)) {
3352
+ return ["", ...p.split(/\/+/)];
3353
+ } else {
3354
+ return p.split(/\/+/);
3355
+ }
3356
+ }
3357
+ match(f, partial = this.partial) {
3358
+ this.debug("match", f, this.pattern);
3359
+ if (this.comment) {
3360
+ return false;
3361
+ }
3362
+ if (this.empty) {
3363
+ return f === "";
3364
+ }
3365
+ if (f === "/" && partial) {
3366
+ return true;
3367
+ }
3368
+ const options = this.options;
3369
+ if (this.isWindows) {
3370
+ f = f.split("\\").join("/");
3371
+ }
3372
+ const ff = this.slashSplit(f);
3373
+ this.debug(this.pattern, "split", ff);
3374
+ const set = this.set;
3375
+ this.debug(this.pattern, "set", set);
3376
+ let filename = ff[ff.length - 1];
3377
+ if (!filename) {
3378
+ for (let i = ff.length - 2; !filename && i >= 0; i--) {
3379
+ filename = ff[i];
3380
+ }
3381
+ }
3382
+ for (let i = 0; i < set.length; i++) {
3383
+ const pattern = set[i];
3384
+ let file = ff;
3385
+ if (options.matchBase && pattern.length === 1) {
3386
+ file = [filename];
3387
+ }
3388
+ const hit = this.matchOne(file, pattern, partial);
3389
+ if (hit) {
3390
+ if (options.flipNegate) {
3391
+ return true;
3392
+ }
3393
+ return !this.negate;
3394
+ }
3395
+ }
3396
+ if (options.flipNegate) {
3397
+ return false;
3398
+ }
3399
+ return this.negate;
3400
+ }
3401
+ static defaults(def) {
3402
+ return minimatch.defaults(def).Minimatch;
3403
+ }
3404
+ };
3405
+ minimatch.AST = AST;
3406
+ minimatch.Minimatch = Minimatch;
3407
+ minimatch.escape = escape;
3408
+ minimatch.unescape = unescape;
3409
+
3410
+ // ../agent/dist/chunk-64ESYBKE.js
3411
+ import fs4 from "fs/promises";
3412
+ var sep2 = "/";
3413
+ function join(...parts) {
3414
+ const joined = parts.filter(Boolean).join("/");
3415
+ return normalize(joined);
3416
+ }
3417
+ function dirname(p) {
3418
+ if (!p) return ".";
3419
+ const i = p.lastIndexOf("/");
3420
+ if (i < 0) return ".";
3421
+ if (i === 0) return "/";
3422
+ return p.slice(0, i);
3423
+ }
3424
+ function basename(p, ext2) {
3425
+ if (p.endsWith("/")) p = p.slice(0, -1);
3426
+ const i = p.lastIndexOf("/");
3427
+ const base = i < 0 ? p : p.slice(i + 1);
3428
+ if (ext2 && base.endsWith(ext2)) return base.slice(0, -ext2.length);
3429
+ return base;
3430
+ }
3431
+ function extname(p) {
3432
+ const base = basename(p);
3433
+ const i = base.lastIndexOf(".");
3434
+ if (i <= 0) return "";
3435
+ return base.slice(i);
3436
+ }
3437
+ function isAbsolute(p) {
3438
+ return p.startsWith("/");
3439
+ }
3440
+ function normalize(p) {
3441
+ if (!p) return ".";
3442
+ const isAbs = p.startsWith("/");
3443
+ const segments = p.split("/");
1344
3444
  const out = [];
1345
3445
  for (const s of segments) {
1346
3446
  if (s === "" || s === ".") continue;
@@ -1383,282 +3483,6 @@ function resolve(...parts) {
1383
3483
  }
1384
3484
  return normalize(resolved);
1385
3485
  }
1386
- var Filesystem;
1387
- ((Filesystem2) => {
1388
- async function exists(context, p) {
1389
- return context.fs.exists(p);
1390
- }
1391
- Filesystem2.exists = exists;
1392
- async function isDir(context, p) {
1393
- const s = await context.fs.stat(p);
1394
- return s?.isDirectory ?? false;
1395
- }
1396
- Filesystem2.isDir = isDir;
1397
- async function stat(context, p) {
1398
- return context.fs.stat(p);
1399
- }
1400
- Filesystem2.stat = stat;
1401
- async function size(context, p) {
1402
- const s = await context.fs.stat(p);
1403
- return s?.size ?? 0;
1404
- }
1405
- Filesystem2.size = size;
1406
- async function readText(context, p) {
1407
- return context.fs.readText(p);
1408
- }
1409
- Filesystem2.readText = readText;
1410
- async function readJson(context, p) {
1411
- return JSON.parse(await readText(context, p));
1412
- }
1413
- Filesystem2.readJson = readJson;
1414
- async function readBytes(context, p) {
1415
- return context.fs.readBytes(p);
1416
- }
1417
- Filesystem2.readBytes = readBytes;
1418
- async function readArrayBuffer(context, p) {
1419
- const bytes = await readBytes(context, p);
1420
- return bytes.buffer;
1421
- }
1422
- Filesystem2.readArrayBuffer = readArrayBuffer;
1423
- async function write(context, p, content) {
1424
- return context.fs.write(p, content);
1425
- }
1426
- Filesystem2.write = write;
1427
- async function writeJson(context, p, data) {
1428
- return write(context, p, JSON.stringify(data, null, 2));
1429
- }
1430
- Filesystem2.writeJson = writeJson;
1431
- async function mkdir(context, p) {
1432
- return context.fs.mkdir(p);
1433
- }
1434
- Filesystem2.mkdir = mkdir;
1435
- async function remove(context, p) {
1436
- return context.fs.remove(p);
1437
- }
1438
- Filesystem2.remove = remove;
1439
- const MIME_MAP = {
1440
- ".html": "text/html",
1441
- ".css": "text/css",
1442
- ".js": "application/javascript",
1443
- ".mjs": "application/javascript",
1444
- ".json": "application/json",
1445
- ".ts": "text/typescript",
1446
- ".tsx": "text/typescript",
1447
- ".jsx": "text/javascript",
1448
- ".md": "text/markdown",
1449
- ".txt": "text/plain",
1450
- ".csv": "text/csv",
1451
- ".xml": "application/xml",
1452
- ".yaml": "text/yaml",
1453
- ".yml": "text/yaml",
1454
- ".toml": "text/plain",
1455
- ".svg": "image/svg+xml",
1456
- ".png": "image/png",
1457
- ".jpg": "image/jpeg",
1458
- ".jpeg": "image/jpeg",
1459
- ".gif": "image/gif",
1460
- ".webp": "image/webp",
1461
- ".ico": "image/x-icon",
1462
- ".pdf": "application/pdf",
1463
- ".zip": "application/zip",
1464
- ".gz": "application/gzip",
1465
- ".wasm": "application/wasm",
1466
- ".mp4": "video/mp4",
1467
- ".webm": "video/webm",
1468
- ".mp3": "audio/mpeg",
1469
- ".sh": "text/x-shellscript",
1470
- ".py": "text/x-python",
1471
- ".rb": "text/x-ruby",
1472
- ".go": "text/x-go",
1473
- ".rs": "text/x-rust",
1474
- ".java": "text/x-java",
1475
- ".c": "text/x-c",
1476
- ".cpp": "text/x-c++",
1477
- ".h": "text/x-c",
1478
- ".hpp": "text/x-c++"
1479
- };
1480
- function mimeType(p) {
1481
- return MIME_MAP[extname(p).toLowerCase()] || "application/octet-stream";
1482
- }
1483
- Filesystem2.mimeType = mimeType;
1484
- function resolve2(p) {
1485
- return resolve(p);
1486
- }
1487
- Filesystem2.resolve = resolve2;
1488
- function overlaps(a, b) {
1489
- const relA = relative(a, b);
1490
- const relB = relative(b, a);
1491
- return !relA || !relA.startsWith("..") || !relB || !relB.startsWith("..");
1492
- }
1493
- Filesystem2.overlaps = overlaps;
1494
- function contains(parent, child) {
1495
- return !relative(parent, child).startsWith("..");
1496
- }
1497
- Filesystem2.contains = contains;
1498
- async function findUp(context, target, start, stop) {
1499
- let current = start;
1500
- const result = [];
1501
- while (true) {
1502
- const search = join(current, target);
1503
- if (await exists(context, search)) result.push(search);
1504
- if (stop === current) break;
1505
- const parent = dirname(current);
1506
- if (parent === current) break;
1507
- current = parent;
1508
- }
1509
- return result;
1510
- }
1511
- Filesystem2.findUp = findUp;
1512
- async function* up(context, options) {
1513
- const { targets, start, stop } = options;
1514
- let current = start;
1515
- while (true) {
1516
- for (const target of targets) {
1517
- const search = join(current, target);
1518
- if (await exists(context, search)) yield search;
1519
- }
1520
- if (stop === current) break;
1521
- const parent = dirname(current);
1522
- if (parent === current) break;
1523
- current = parent;
1524
- }
1525
- }
1526
- Filesystem2.up = up;
1527
- async function globUp(context, pattern, start, stop) {
1528
- let current = start;
1529
- const result = [];
1530
- while (true) {
1531
- try {
1532
- const { Glob: Glob2 } = await import("./glob-RMMK6FVW-WWQVXLWS.js");
1533
- const matches = await Glob2.scan(context, pattern, {
1534
- cwd: current,
1535
- absolute: true,
1536
- include: "file",
1537
- dot: true
1538
- });
1539
- result.push(...matches);
1540
- } catch {
1541
- }
1542
- if (stop === current) break;
1543
- const parent = dirname(current);
1544
- if (parent === current) break;
1545
- current = parent;
1546
- }
1547
- return result;
1548
- }
1549
- Filesystem2.globUp = globUp;
1550
- })(Filesystem || (Filesystem = {}));
1551
- var Log;
1552
- ((Log2) => {
1553
- Log2.Level = zod_default.enum(["DEBUG", "INFO", "WARN", "ERROR"]).meta({ ref: "LogLevel", description: "Log level" });
1554
- const levelPriority = {
1555
- DEBUG: 0,
1556
- INFO: 1,
1557
- WARN: 2,
1558
- ERROR: 3
1559
- };
1560
- let level = "INFO";
1561
- function shouldLog(input) {
1562
- return levelPriority[input] >= levelPriority[level];
1563
- }
1564
- const loggers = /* @__PURE__ */ new Map();
1565
- Log2.Default = create({ service: "default" });
1566
- let write = (msg) => {
1567
- console.error(msg);
1568
- return msg.length;
1569
- };
1570
- async function init(options) {
1571
- if (options.level) level = options.level;
1572
- if (options.writer) {
1573
- write = (msg) => {
1574
- options.writer(msg);
1575
- return msg.length;
1576
- };
1577
- }
1578
- }
1579
- Log2.init = init;
1580
- function formatError(error, depth = 0) {
1581
- const result = error.message;
1582
- return error.cause instanceof Error && depth < 10 ? result + " Caused by: " + formatError(error.cause, depth + 1) : result;
1583
- }
1584
- let last = Date.now();
1585
- function create(tags) {
1586
- tags = tags || {};
1587
- const service = tags["service"];
1588
- if (service && typeof service === "string") {
1589
- const cached = loggers.get(service);
1590
- if (cached) {
1591
- return cached;
1592
- }
1593
- }
1594
- function build(message, extra) {
1595
- const prefix = Object.entries({
1596
- ...tags,
1597
- ...extra
1598
- }).filter(([_, value]) => value !== void 0 && value !== null).map(([key, value]) => {
1599
- const prefix2 = `${key}=`;
1600
- if (value instanceof Error) return prefix2 + formatError(value);
1601
- if (typeof value === "object") return prefix2 + JSON.stringify(value);
1602
- return prefix2 + value;
1603
- }).join(" ");
1604
- const next = /* @__PURE__ */ new Date();
1605
- const diff = next.getTime() - last;
1606
- last = next.getTime();
1607
- return [next.toISOString().split(".")[0], "+" + diff + "ms", prefix, message].filter(Boolean).join(" ") + "\n";
1608
- }
1609
- const result = {
1610
- debug(message, extra) {
1611
- if (shouldLog("DEBUG")) {
1612
- write("DEBUG " + build(message, extra));
1613
- }
1614
- },
1615
- info(message, extra) {
1616
- if (shouldLog("INFO")) {
1617
- write("INFO " + build(message, extra));
1618
- }
1619
- },
1620
- error(message, extra) {
1621
- if (shouldLog("ERROR")) {
1622
- write("ERROR " + build(message, extra));
1623
- }
1624
- },
1625
- warn(message, extra) {
1626
- if (shouldLog("WARN")) {
1627
- write("WARN " + build(message, extra));
1628
- }
1629
- },
1630
- tag(key, value) {
1631
- if (tags) tags[key] = value;
1632
- return result;
1633
- },
1634
- clone() {
1635
- return Log2.create({ ...tags });
1636
- },
1637
- time(message, extra) {
1638
- const now = Date.now();
1639
- result.info(message, { status: "started", ...extra });
1640
- function stop() {
1641
- result.info(message, {
1642
- status: "completed",
1643
- duration: Date.now() - now,
1644
- ...extra
1645
- });
1646
- }
1647
- return {
1648
- stop,
1649
- [Symbol.dispose]() {
1650
- stop();
1651
- }
1652
- };
1653
- }
1654
- };
1655
- if (service && typeof service === "string") {
1656
- loggers.set(service, result);
1657
- }
1658
- return result;
1659
- }
1660
- Log2.create = create;
1661
- })(Log || (Log = {}));
1662
3486
  var _env = {};
1663
3487
  function truthy(key) {
1664
3488
  const value = _env[key]?.toLowerCase();
@@ -1783,6 +3607,23 @@ Object.defineProperty(Flag, "OPENCODE_CLIENT", {
1783
3607
  enumerable: true,
1784
3608
  configurable: false
1785
3609
  });
3610
+ var Glob;
3611
+ ((Glob2) => {
3612
+ async function scan(context, pattern, options = {}) {
3613
+ return context.fs.glob(pattern, {
3614
+ cwd: options.cwd,
3615
+ absolute: options.absolute,
3616
+ dot: options.dot,
3617
+ follow: options.symlink ?? false,
3618
+ nodir: options.include !== "all"
3619
+ });
3620
+ }
3621
+ Glob2.scan = scan;
3622
+ function match2(pattern, filepath) {
3623
+ return minimatch(filepath, pattern, { dot: true });
3624
+ }
3625
+ Glob2.match = match2;
3626
+ })(Glob || (Glob = {}));
1786
3627
  var projectIdSchema = Schema_exports.String.pipe(Schema_exports.brand("ProjectID"));
1787
3628
  var ProjectID = projectIdSchema.pipe(
1788
3629
  withStatics((schema) => ({
@@ -1894,7 +3735,7 @@ var FileIgnore;
1894
3735
  "**/.nyc_output/**"
1895
3736
  ];
1896
3737
  FileIgnore2.PATTERNS = [...FILES, ...FOLDERS];
1897
- function match(filepath, opts) {
3738
+ function match2(filepath, opts) {
1898
3739
  for (const pattern of opts?.whitelist || []) {
1899
3740
  if (Glob.match(pattern, filepath)) return false;
1900
3741
  }
@@ -1908,14 +3749,12 @@ var FileIgnore;
1908
3749
  }
1909
3750
  return false;
1910
3751
  }
1911
- FileIgnore2.match = match;
3752
+ FileIgnore2.match = match2;
1912
3753
  })(FileIgnore || (FileIgnore = {}));
1913
3754
  var FileTimeService = class {
1914
- log = Log.create({ service: "file.time" });
1915
3755
  readTimes = {};
1916
3756
  locks = /* @__PURE__ */ new Map();
1917
3757
  read(sessionID, file) {
1918
- this.log.info("read", { sessionID, file });
1919
3758
  this.readTimes[sessionID] = this.readTimes[sessionID] || {};
1920
3759
  this.readTimes[sessionID][file] = /* @__PURE__ */ new Date();
1921
3760
  }
@@ -1926,7 +3765,7 @@ var FileTimeService = class {
1926
3765
  if (Flag.OPENCODE_DISABLE_FILETIME_CHECK === true) return;
1927
3766
  const time = this.get(sessionID, filepath);
1928
3767
  if (!time) throw new Error(`You must read file ${filepath} before overwriting it. Use the Read tool first`);
1929
- const s = await Filesystem.stat(context, filepath);
3768
+ const s = await context.fs.stat(filepath);
1930
3769
  const mtimeMs = s?.mtimeMs;
1931
3770
  if (mtimeMs && mtimeMs > time.getTime() + 50) {
1932
3771
  const mtime = new Date(mtimeMs);
@@ -1987,7 +3826,6 @@ var FileTime;
1987
3826
  })(FileTime || (FileTime = {}));
1988
3827
  var Project;
1989
3828
  ((Project2) => {
1990
- const log = Log.create({ service: "project" });
1991
3829
  Project2.Info = zod_default.object({
1992
3830
  id: ProjectID.zod,
1993
3831
  worktree: zod_default.string(),
@@ -2046,7 +3884,7 @@ var Project;
2046
3884
  const data = fromRow(row);
2047
3885
  const valid = [];
2048
3886
  for (const dir of data.sandboxes) {
2049
- const s = await Filesystem.stat(context, dir);
3887
+ const s = await context.fs.stat(dir);
2050
3888
  if (s?.isDirectory) valid.push(dir);
2051
3889
  }
2052
3890
  return valid;
@@ -2172,7 +4010,7 @@ var Lock;
2172
4010
  }
2173
4011
  return locks.get(key);
2174
4012
  }
2175
- function process(key) {
4013
+ function process2(key) {
2176
4014
  const lock = locks.get(key);
2177
4015
  if (!lock || lock.writer || lock.readers > 0) return;
2178
4016
  if (lock.waitingWriters.length > 0) {
@@ -2196,7 +4034,7 @@ var Lock;
2196
4034
  resolve2({
2197
4035
  [Symbol.dispose]: () => {
2198
4036
  lock.readers--;
2199
- process(key);
4037
+ process2(key);
2200
4038
  }
2201
4039
  });
2202
4040
  } else {
@@ -2205,7 +4043,7 @@ var Lock;
2205
4043
  resolve2({
2206
4044
  [Symbol.dispose]: () => {
2207
4045
  lock.readers--;
2208
- process(key);
4046
+ process2(key);
2209
4047
  }
2210
4048
  });
2211
4049
  });
@@ -2221,7 +4059,7 @@ var Lock;
2221
4059
  resolve2({
2222
4060
  [Symbol.dispose]: () => {
2223
4061
  lock.writer = false;
2224
- process(key);
4062
+ process2(key);
2225
4063
  }
2226
4064
  });
2227
4065
  } else {
@@ -2230,7 +4068,7 @@ var Lock;
2230
4068
  resolve2({
2231
4069
  [Symbol.dispose]: () => {
2232
4070
  lock.writer = false;
2233
- process(key);
4071
+ process2(key);
2234
4072
  }
2235
4073
  });
2236
4074
  });
@@ -2400,132 +4238,11 @@ CREATE TABLE IF NOT EXISTS "control_account" (
2400
4238
  }
2401
4239
  Database2.getMigrations = getMigrations;
2402
4240
  })(Database || (Database = {}));
2403
- var SqliteNoSqlDb = class {
2404
- constructor(raw) {
2405
- this.raw = raw;
2406
- }
2407
- insert(table, row) {
2408
- const cols = Object.keys(row);
2409
- const placeholders = cols.map(() => "?").join(", ");
2410
- const sql2 = `INSERT INTO "${table}" (${cols.map((c) => `"${c}"`).join(", ")}) VALUES (${placeholders})`;
2411
- this.raw.run(sql2, cols.map((c) => serialize(row[c])));
2412
- }
2413
- upsert(table, row, conflictKeys, updateFields) {
2414
- const cols = Object.keys(row);
2415
- const placeholders = cols.map(() => "?").join(", ");
2416
- const conflict = conflictKeys.map((k) => `"${k}"`).join(", ");
2417
- const updates = Object.keys(updateFields).map((k) => `"${k}" = ?`).join(", ");
2418
- const sql2 = `INSERT INTO "${table}" (${cols.map((c) => `"${c}"`).join(", ")}) VALUES (${placeholders}) ON CONFLICT (${conflict}) DO UPDATE SET ${updates}`;
2419
- const params = [
2420
- ...cols.map((c) => serialize(row[c])),
2421
- ...Object.keys(updateFields).map((k) => serialize(updateFields[k]))
2422
- ];
2423
- this.raw.run(sql2, params);
2424
- }
2425
- findOne(table, filter, options) {
2426
- const fields = options?.select?.map((f) => `"${f}"`).join(", ") ?? "*";
2427
- const { clause, params } = filter ? buildWhere(filter) : { clause: "", params: [] };
2428
- const where = clause ? ` WHERE ${clause}` : "";
2429
- const sql2 = `SELECT ${fields} FROM "${table}"${where} LIMIT 1`;
2430
- const row = this.raw.get(sql2, params);
2431
- return row ? deserializeRow(row) : void 0;
2432
- }
2433
- findMany(table, options) {
2434
- const fields = options?.select?.map((f) => `"${f}"`).join(", ") ?? "*";
2435
- const { clause, params } = options?.filter ? buildWhere(options.filter) : { clause: "", params: [] };
2436
- const where = clause ? ` WHERE ${clause}` : "";
2437
- let orderClause = "";
2438
- if (options?.orderBy?.length) {
2439
- const parts = options.orderBy.map(
2440
- (o) => `"${o.field}" ${o.direction === "desc" ? "DESC" : "ASC"}`
2441
- );
2442
- orderClause = ` ORDER BY ${parts.join(", ")}`;
2443
- }
2444
- const limitClause = options?.limit != null ? ` LIMIT ${options.limit}` : "";
2445
- const sql2 = `SELECT ${fields} FROM "${table}"${where}${orderClause}${limitClause}`;
2446
- return this.raw.all(sql2, params).map(deserializeRow);
2447
- }
2448
- update(table, filter, set) {
2449
- const setCols = Object.keys(set);
2450
- const setClause = setCols.map((k) => `"${k}" = ?`).join(", ");
2451
- const { clause, params } = buildWhere(filter);
2452
- const sql2 = `UPDATE "${table}" SET ${setClause} WHERE ${clause} RETURNING *`;
2453
- const setParams = setCols.map((k) => serialize(set[k]));
2454
- const row = this.raw.get(sql2, [...setParams, ...params]);
2455
- return row ? deserializeRow(row) : void 0;
2456
- }
2457
- remove(table, filter) {
2458
- const { clause, params } = buildWhere(filter);
2459
- this.raw.run(`DELETE FROM "${table}" WHERE ${clause}`, params);
2460
- }
2461
- transaction(fn) {
2462
- this.raw.transaction(() => {
2463
- fn(this);
2464
- });
2465
- }
2466
- };
2467
- function buildWhere(filter) {
2468
- switch (filter.op) {
2469
- case "eq":
2470
- return { clause: `"${filter.field}" = ?`, params: [serialize(filter.value)] };
2471
- case "ne":
2472
- return { clause: `"${filter.field}" != ?`, params: [serialize(filter.value)] };
2473
- case "gt":
2474
- return { clause: `"${filter.field}" > ?`, params: [serialize(filter.value)] };
2475
- case "gte":
2476
- return { clause: `"${filter.field}" >= ?`, params: [serialize(filter.value)] };
2477
- case "lt":
2478
- return { clause: `"${filter.field}" < ?`, params: [serialize(filter.value)] };
2479
- case "like":
2480
- return { clause: `"${filter.field}" LIKE ?`, params: [filter.value] };
2481
- case "isNull":
2482
- return { clause: `"${filter.field}" IS NULL`, params: [] };
2483
- case "in": {
2484
- const placeholders = filter.values.map(() => "?").join(", ");
2485
- return { clause: `"${filter.field}" IN (${placeholders})`, params: filter.values.map(serialize) };
2486
- }
2487
- case "and": {
2488
- const parts = filter.conditions.map(buildWhere);
2489
- return {
2490
- clause: parts.map((p) => `(${p.clause})`).join(" AND "),
2491
- params: parts.flatMap((p) => p.params)
2492
- };
2493
- }
2494
- case "or": {
2495
- const parts = filter.conditions.map(buildWhere);
2496
- return {
2497
- clause: parts.map((p) => `(${p.clause})`).join(" OR "),
2498
- params: parts.flatMap((p) => p.params)
2499
- };
2500
- }
2501
- }
2502
- }
2503
- function serialize(value) {
2504
- if (value === void 0) return null;
2505
- if (value === null) return null;
2506
- if (typeof value === "object" && !(value instanceof Buffer) && !(value instanceof Uint8Array)) {
2507
- return JSON.stringify(value);
2508
- }
2509
- return value;
2510
- }
2511
- function deserializeRow(row) {
2512
- const result = {};
2513
- for (const [key, value] of Object.entries(row)) {
2514
- if (typeof value === "string" && (value.startsWith("{") || value.startsWith("["))) {
2515
- try {
2516
- result[key] = JSON.parse(value);
2517
- } catch {
2518
- result[key] = value;
2519
- }
2520
- } else {
2521
- result[key] = value;
2522
- }
2523
- }
2524
- return result;
2525
- }
2526
4241
  var Storage;
2527
4242
  ((Storage2) => {
2528
- const log = Log.create({ service: "storage" });
4243
+ function getLog(context) {
4244
+ return context.log.create({ service: "storage" });
4245
+ }
2529
4246
  Storage2.NotFoundError = NamedError.create(
2530
4247
  "NotFoundError",
2531
4248
  zod_default.object({
@@ -2535,36 +4252,36 @@ var Storage;
2535
4252
  const MIGRATIONS = [
2536
4253
  async (context, dir) => {
2537
4254
  const project = resolve(dir, "../project");
2538
- if (!await Filesystem.isDir(context, project)) return;
2539
- const projectDirs = await Glob.scan(context, "*", {
4255
+ if (!await context.fs.isDir(project)) return;
4256
+ const projectDirs = await context.fs.glob("*", {
2540
4257
  cwd: project,
2541
- include: "all"
4258
+ nodir: false
2542
4259
  });
2543
4260
  for (const projectDir of projectDirs) {
2544
4261
  const fullPath = join(project, projectDir);
2545
- if (!await Filesystem.isDir(context, fullPath)) continue;
2546
- log.info(`migrating project ${projectDir}`);
4262
+ if (!await context.fs.isDir(fullPath)) continue;
4263
+ getLog(context).info(`migrating project ${projectDir}`);
2547
4264
  let projectID = projectDir;
2548
4265
  const fullProjectDir = join(project, projectDir);
2549
4266
  let worktree = "/";
2550
4267
  if (projectID !== "global") {
2551
- for (const msgFile of await Glob.scan(context, "storage/session/message/*/*.json", {
4268
+ for (const msgFile of await context.fs.glob("storage/session/message/*/*.json", {
2552
4269
  cwd: join(project, projectDir),
2553
4270
  absolute: true
2554
4271
  })) {
2555
- const json = await Filesystem.readJson(context, msgFile);
4272
+ const json = await context.fs.readJson(msgFile);
2556
4273
  worktree = json.path?.root;
2557
4274
  if (worktree) break;
2558
4275
  }
2559
4276
  if (!worktree) continue;
2560
- if (!await Filesystem.isDir(context, worktree)) continue;
4277
+ if (!await context.fs.isDir(worktree)) continue;
2561
4278
  const result = await context.git.run(["rev-list", "--max-parents=0", "--all"], {
2562
4279
  cwd: worktree
2563
4280
  });
2564
4281
  const [id] = result.text().split("\n").filter(Boolean).map((x) => x.trim()).toSorted();
2565
4282
  if (!id) continue;
2566
4283
  projectID = id;
2567
- await Filesystem.writeJson(context, join(dir, "project", projectID + ".json"), {
4284
+ await context.fs.writeJson(join(dir, "project", projectID + ".json"), {
2568
4285
  id,
2569
4286
  vcs: "git",
2570
4287
  worktree,
@@ -2573,42 +4290,42 @@ var Storage;
2573
4290
  initialized: Date.now()
2574
4291
  }
2575
4292
  });
2576
- log.info(`migrating sessions for project ${projectID}`);
2577
- for (const sessionFile of await Glob.scan(context, "storage/session/info/*.json", {
4293
+ getLog(context).info(`migrating sessions for project ${projectID}`);
4294
+ for (const sessionFile of await context.fs.glob("storage/session/info/*.json", {
2578
4295
  cwd: fullProjectDir,
2579
4296
  absolute: true
2580
4297
  })) {
2581
4298
  const dest = join(dir, "session", projectID, basename(sessionFile));
2582
- log.info("copying", {
4299
+ getLog(context).info("copying", {
2583
4300
  sessionFile,
2584
4301
  dest
2585
4302
  });
2586
- const session = await Filesystem.readJson(context, sessionFile);
2587
- await Filesystem.writeJson(context, dest, session);
2588
- log.info(`migrating messages for session ${session.id}`);
2589
- for (const msgFile of await Glob.scan(context, `storage/session/message/${session.id}/*.json`, {
4303
+ const session = await context.fs.readJson(sessionFile);
4304
+ await context.fs.writeJson(dest, session);
4305
+ getLog(context).info(`migrating messages for session ${session.id}`);
4306
+ for (const msgFile of await context.fs.glob(`storage/session/message/${session.id}/*.json`, {
2590
4307
  cwd: fullProjectDir,
2591
4308
  absolute: true
2592
4309
  })) {
2593
4310
  const dest2 = join(dir, "message", session.id, basename(msgFile));
2594
- log.info("copying", {
4311
+ getLog(context).info("copying", {
2595
4312
  msgFile,
2596
4313
  dest: dest2
2597
4314
  });
2598
- const message = await Filesystem.readJson(context, msgFile);
2599
- await Filesystem.writeJson(context, dest2, message);
2600
- log.info(`migrating parts for message ${message.id}`);
2601
- for (const partFile of await Glob.scan(context, `storage/session/part/${session.id}/${message.id}/*.json`, {
4315
+ const message = await context.fs.readJson(msgFile);
4316
+ await context.fs.writeJson(dest2, message);
4317
+ getLog(context).info(`migrating parts for message ${message.id}`);
4318
+ for (const partFile of await context.fs.glob(`storage/session/part/${session.id}/${message.id}/*.json`, {
2602
4319
  cwd: fullProjectDir,
2603
4320
  absolute: true
2604
4321
  })) {
2605
4322
  const dest3 = join(dir, "part", message.id, basename(partFile));
2606
- const part = await Filesystem.readJson(context, partFile);
2607
- log.info("copying", {
4323
+ const part = await context.fs.readJson(partFile);
4324
+ getLog(context).info("copying", {
2608
4325
  partFile,
2609
4326
  dest: dest3
2610
4327
  });
2611
- await Filesystem.writeJson(context, dest3, part);
4328
+ await context.fs.writeJson(dest3, part);
2612
4329
  }
2613
4330
  }
2614
4331
  }
@@ -2616,16 +4333,16 @@ var Storage;
2616
4333
  }
2617
4334
  },
2618
4335
  async (context, dir) => {
2619
- for (const item of await Glob.scan(context, "session/*/*.json", {
4336
+ for (const item of await context.fs.glob("session/*/*.json", {
2620
4337
  cwd: dir,
2621
4338
  absolute: true
2622
4339
  })) {
2623
- const session = await Filesystem.readJson(context, item);
4340
+ const session = await context.fs.readJson(item);
2624
4341
  if (!session.projectID) continue;
2625
4342
  if (!session.summary?.diffs) continue;
2626
4343
  const { diffs } = session.summary;
2627
- await Filesystem.write(context, join(dir, "session_diff", session.id + ".json"), JSON.stringify(diffs));
2628
- await Filesystem.writeJson(context, join(dir, "session", session.projectID, session.id + ".json"), {
4344
+ await context.fs.write(join(dir, "session_diff", session.id + ".json"), JSON.stringify(diffs));
4345
+ await context.fs.writeJson(join(dir, "session", session.projectID, session.id + ".json"), {
2629
4346
  ...session,
2630
4347
  summary: {
2631
4348
  additions: diffs.reduce((sum, x) => sum + x.additions, 0),
@@ -2637,12 +4354,12 @@ var Storage;
2637
4354
  ];
2638
4355
  async function getDir(context) {
2639
4356
  const dir = join(context.dataPath, "storage");
2640
- const migration = await Filesystem.readJson(context, join(dir, "migration")).then((x) => parseInt(x)).catch(() => 0);
4357
+ const migration = await context.fs.readJson(join(dir, "migration")).then((x) => parseInt(x)).catch(() => 0);
2641
4358
  for (let index2 = migration; index2 < MIGRATIONS.length; index2++) {
2642
- log.info("running migration", { index: index2 });
4359
+ getLog(context).info("running migration", { index: index2 });
2643
4360
  const migrationFn = MIGRATIONS[index2];
2644
- await migrationFn(context, dir).catch(() => log.error("failed to run migration", { index: index2 }));
2645
- await Filesystem.write(context, join(dir, "migration"), (index2 + 1).toString());
4361
+ await migrationFn(context, dir).catch(() => getLog(context).error("failed to run migration", { index: index2 }));
4362
+ await context.fs.write(join(dir, "migration"), (index2 + 1).toString());
2646
4363
  }
2647
4364
  return dir;
2648
4365
  }
@@ -2650,7 +4367,7 @@ var Storage;
2650
4367
  const dir = await getDir(context);
2651
4368
  const target = join(dir, ...key) + ".json";
2652
4369
  return withErrorHandling(async () => {
2653
- await fs.unlink(target).catch(() => {
4370
+ await fs4.unlink(target).catch(() => {
2654
4371
  });
2655
4372
  });
2656
4373
  }
@@ -2662,7 +4379,7 @@ var Storage;
2662
4379
  var _stack = [];
2663
4380
  try {
2664
4381
  const _ = __using(_stack, await Lock.read(target));
2665
- const result = await Filesystem.readJson(context, target);
4382
+ const result = await context.fs.readJson(target);
2666
4383
  return result;
2667
4384
  } catch (_2) {
2668
4385
  var _error = _2, _hasError = true;
@@ -2679,9 +4396,9 @@ var Storage;
2679
4396
  var _stack = [];
2680
4397
  try {
2681
4398
  const _ = __using(_stack, await Lock.write(target));
2682
- const content = await Filesystem.readJson(context, target);
4399
+ const content = await context.fs.readJson(target);
2683
4400
  fn(content);
2684
- await Filesystem.writeJson(context, target, content);
4401
+ await context.fs.writeJson(target, content);
2685
4402
  return content;
2686
4403
  } catch (_2) {
2687
4404
  var _error = _2, _hasError = true;
@@ -2698,7 +4415,7 @@ var Storage;
2698
4415
  var _stack = [];
2699
4416
  try {
2700
4417
  const _ = __using(_stack, await Lock.write(target));
2701
- await Filesystem.writeJson(context, target, content);
4418
+ await context.fs.writeJson(target, content);
2702
4419
  } catch (_2) {
2703
4420
  var _error = _2, _hasError = true;
2704
4421
  } finally {
@@ -2720,10 +4437,10 @@ var Storage;
2720
4437
  async function list(context, prefix) {
2721
4438
  const dir = await getDir(context);
2722
4439
  try {
2723
- const result = await Glob.scan(context, "**/*", {
4440
+ const result = await context.fs.glob("**/*", {
2724
4441
  cwd: join(dir, ...prefix),
2725
- include: "file"
2726
- }).then((results) => results.map((x) => [...prefix, ...x.slice(0, -5).split(sep)]));
4442
+ nodir: true
4443
+ }).then((results) => results.map((x) => [...prefix, ...x.slice(0, -5).split(sep2)]));
2727
4444
  result.sort();
2728
4445
  return result;
2729
4446
  } catch {
@@ -2734,6 +4451,11 @@ var Storage;
2734
4451
  })(Storage || (Storage = {}));
2735
4452
 
2736
4453
  export {
4454
+ consoleLogger,
4455
+ SqliteNoSqlDb,
4456
+ NodeFS,
4457
+ NodeSearchProvider,
4458
+ SqlJsStorage,
2737
4459
  join,
2738
4460
  dirname,
2739
4461
  basename,
@@ -2741,15 +4463,10 @@ export {
2741
4463
  isAbsolute,
2742
4464
  relative,
2743
4465
  resolve,
2744
- Filesystem,
2745
- Log,
2746
4466
  Flag,
2747
4467
  ProjectID,
2748
4468
  ProjectTable,
2749
- Protected,
2750
- FileIgnore,
2751
4469
  FileTimeService,
2752
- Project,
2753
4470
  SessionTable,
2754
4471
  MessageTable,
2755
4472
  PartTable,
@@ -2758,6 +4475,5 @@ export {
2758
4475
  Timestamps,
2759
4476
  NotFoundError,
2760
4477
  Database,
2761
- SqliteNoSqlDb,
2762
4478
  Storage
2763
4479
  };