archal 0.9.7 → 0.9.9

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.
Files changed (39) hide show
  1. package/README.md +163 -93
  2. package/bin/archal.cjs +3 -3
  3. package/dist/index.cjs +82301 -0
  4. package/dist/index.d.cts +1 -0
  5. package/dist/seed/dynamic-generator.cjs +45640 -0
  6. package/dist/seed/dynamic-generator.d.cts +67 -0
  7. package/dist/vitest/chunk-RKYS44AS.js +2216 -0
  8. package/dist/vitest/chunk-YJICENME.js +1230 -0
  9. package/dist/vitest/chunk-YV6BH6DO.js +45974 -0
  10. package/dist/vitest/index.cjs +51963 -0
  11. package/dist/vitest/index.d.ts +398 -0
  12. package/dist/vitest/index.js +2669 -0
  13. package/dist/vitest/runtime/hosted-session-reaper.cjs +29349 -0
  14. package/dist/vitest/runtime/hosted-session-reaper.d.ts +2 -0
  15. package/dist/vitest/runtime/hosted-session-reaper.js +58 -0
  16. package/dist/vitest/runtime/setup-files.d.ts +2 -0
  17. package/dist/vitest/runtime/setup-files.js +27 -0
  18. package/dist/vitest/src-JGHX6UKK.js +94 -0
  19. package/package.json +19 -22
  20. package/twin-assets/discord/fidelity.json +113 -0
  21. package/twin-assets/discord/tools.json +1953 -0
  22. package/twin-assets/github/fidelity.json +13 -0
  23. package/twin-assets/github/tools.json +21818 -0
  24. package/twin-assets/google-workspace/fidelity.json +19 -0
  25. package/twin-assets/google-workspace/tools.json +10191 -0
  26. package/twin-assets/jira/fidelity.json +40 -0
  27. package/twin-assets/jira/tools.json +17387 -0
  28. package/twin-assets/linear/fidelity.json +18 -0
  29. package/twin-assets/linear/tools.json +6496 -0
  30. package/twin-assets/ramp/fidelity.json +22 -0
  31. package/twin-assets/ramp/tools.json +2610 -0
  32. package/twin-assets/slack/fidelity.json +20 -0
  33. package/twin-assets/slack/tools.json +7301 -0
  34. package/twin-assets/stripe/fidelity.json +22 -0
  35. package/twin-assets/stripe/tools.json +15284 -0
  36. package/twin-assets/supabase/fidelity.json +13 -0
  37. package/twin-assets/supabase/tools.json +2973 -0
  38. package/dist/vitest.d.ts +0 -1
  39. package/dist/vitest.js +0 -23
@@ -0,0 +1,2669 @@
1
+ import {
2
+ ARCHAL_VITEST_CONFIG_ENV,
3
+ assertSupportedArchalVitestServices,
4
+ bootstrapArchalVitestRouting,
5
+ fetchArchalTwin,
6
+ getInstalledArchalVitestRuntime,
7
+ getInstalledArchalVitestSession,
8
+ readArchalVitestConfig,
9
+ resetArchalTwins,
10
+ resolveRuntimeModule
11
+ } from "./chunk-RKYS44AS.js";
12
+ import {
13
+ encodeConfig,
14
+ getSessionIdFilePath
15
+ } from "./chunk-YV6BH6DO.js";
16
+ import {
17
+ __commonJS,
18
+ __toESM
19
+ } from "./chunk-YJICENME.js";
20
+
21
+ // ../../node_modules/.pnpm/picomatch@4.0.4/node_modules/picomatch/lib/constants.js
22
+ var require_constants = __commonJS({
23
+ "../../node_modules/.pnpm/picomatch@4.0.4/node_modules/picomatch/lib/constants.js"(exports, module) {
24
+ "use strict";
25
+ var WIN_SLASH = "\\\\/";
26
+ var WIN_NO_SLASH = `[^${WIN_SLASH}]`;
27
+ var DEFAULT_MAX_EXTGLOB_RECURSION = 0;
28
+ var DOT_LITERAL = "\\.";
29
+ var PLUS_LITERAL = "\\+";
30
+ var QMARK_LITERAL = "\\?";
31
+ var SLASH_LITERAL = "\\/";
32
+ var ONE_CHAR = "(?=.)";
33
+ var QMARK = "[^/]";
34
+ var END_ANCHOR = `(?:${SLASH_LITERAL}|$)`;
35
+ var START_ANCHOR = `(?:^|${SLASH_LITERAL})`;
36
+ var DOTS_SLASH = `${DOT_LITERAL}{1,2}${END_ANCHOR}`;
37
+ var NO_DOT = `(?!${DOT_LITERAL})`;
38
+ var NO_DOTS = `(?!${START_ANCHOR}${DOTS_SLASH})`;
39
+ var NO_DOT_SLASH = `(?!${DOT_LITERAL}{0,1}${END_ANCHOR})`;
40
+ var NO_DOTS_SLASH = `(?!${DOTS_SLASH})`;
41
+ var QMARK_NO_DOT = `[^.${SLASH_LITERAL}]`;
42
+ var STAR = `${QMARK}*?`;
43
+ var SEP = "/";
44
+ var POSIX_CHARS = {
45
+ DOT_LITERAL,
46
+ PLUS_LITERAL,
47
+ QMARK_LITERAL,
48
+ SLASH_LITERAL,
49
+ ONE_CHAR,
50
+ QMARK,
51
+ END_ANCHOR,
52
+ DOTS_SLASH,
53
+ NO_DOT,
54
+ NO_DOTS,
55
+ NO_DOT_SLASH,
56
+ NO_DOTS_SLASH,
57
+ QMARK_NO_DOT,
58
+ STAR,
59
+ START_ANCHOR,
60
+ SEP
61
+ };
62
+ var WINDOWS_CHARS = {
63
+ ...POSIX_CHARS,
64
+ SLASH_LITERAL: `[${WIN_SLASH}]`,
65
+ QMARK: WIN_NO_SLASH,
66
+ STAR: `${WIN_NO_SLASH}*?`,
67
+ DOTS_SLASH: `${DOT_LITERAL}{1,2}(?:[${WIN_SLASH}]|$)`,
68
+ NO_DOT: `(?!${DOT_LITERAL})`,
69
+ NO_DOTS: `(?!(?:^|[${WIN_SLASH}])${DOT_LITERAL}{1,2}(?:[${WIN_SLASH}]|$))`,
70
+ NO_DOT_SLASH: `(?!${DOT_LITERAL}{0,1}(?:[${WIN_SLASH}]|$))`,
71
+ NO_DOTS_SLASH: `(?!${DOT_LITERAL}{1,2}(?:[${WIN_SLASH}]|$))`,
72
+ QMARK_NO_DOT: `[^.${WIN_SLASH}]`,
73
+ START_ANCHOR: `(?:^|[${WIN_SLASH}])`,
74
+ END_ANCHOR: `(?:[${WIN_SLASH}]|$)`,
75
+ SEP: "\\"
76
+ };
77
+ var POSIX_REGEX_SOURCE = {
78
+ __proto__: null,
79
+ alnum: "a-zA-Z0-9",
80
+ alpha: "a-zA-Z",
81
+ ascii: "\\x00-\\x7F",
82
+ blank: " \\t",
83
+ cntrl: "\\x00-\\x1F\\x7F",
84
+ digit: "0-9",
85
+ graph: "\\x21-\\x7E",
86
+ lower: "a-z",
87
+ print: "\\x20-\\x7E ",
88
+ punct: "\\-!\"#$%&'()\\*+,./:;<=>?@[\\]^_`{|}~",
89
+ space: " \\t\\r\\n\\v\\f",
90
+ upper: "A-Z",
91
+ word: "A-Za-z0-9_",
92
+ xdigit: "A-Fa-f0-9"
93
+ };
94
+ module.exports = {
95
+ DEFAULT_MAX_EXTGLOB_RECURSION,
96
+ MAX_LENGTH: 1024 * 64,
97
+ POSIX_REGEX_SOURCE,
98
+ // regular expressions
99
+ REGEX_BACKSLASH: /\\(?![*+?^${}(|)[\]])/g,
100
+ REGEX_NON_SPECIAL_CHARS: /^[^@![\].,$*+?^{}()|\\/]+/,
101
+ REGEX_SPECIAL_CHARS: /[-*+?.^${}(|)[\]]/,
102
+ REGEX_SPECIAL_CHARS_BACKREF: /(\\?)((\W)(\3*))/g,
103
+ REGEX_SPECIAL_CHARS_GLOBAL: /([-*+?.^${}(|)[\]])/g,
104
+ REGEX_REMOVE_BACKSLASH: /(?:\[.*?[^\\]\]|\\(?=.))/g,
105
+ // Replace globs with equivalent patterns to reduce parsing time.
106
+ REPLACEMENTS: {
107
+ __proto__: null,
108
+ "***": "*",
109
+ "**/**": "**",
110
+ "**/**/**": "**"
111
+ },
112
+ // Digits
113
+ CHAR_0: 48,
114
+ /* 0 */
115
+ CHAR_9: 57,
116
+ /* 9 */
117
+ // Alphabet chars.
118
+ CHAR_UPPERCASE_A: 65,
119
+ /* A */
120
+ CHAR_LOWERCASE_A: 97,
121
+ /* a */
122
+ CHAR_UPPERCASE_Z: 90,
123
+ /* Z */
124
+ CHAR_LOWERCASE_Z: 122,
125
+ /* z */
126
+ CHAR_LEFT_PARENTHESES: 40,
127
+ /* ( */
128
+ CHAR_RIGHT_PARENTHESES: 41,
129
+ /* ) */
130
+ CHAR_ASTERISK: 42,
131
+ /* * */
132
+ // Non-alphabetic chars.
133
+ CHAR_AMPERSAND: 38,
134
+ /* & */
135
+ CHAR_AT: 64,
136
+ /* @ */
137
+ CHAR_BACKWARD_SLASH: 92,
138
+ /* \ */
139
+ CHAR_CARRIAGE_RETURN: 13,
140
+ /* \r */
141
+ CHAR_CIRCUMFLEX_ACCENT: 94,
142
+ /* ^ */
143
+ CHAR_COLON: 58,
144
+ /* : */
145
+ CHAR_COMMA: 44,
146
+ /* , */
147
+ CHAR_DOT: 46,
148
+ /* . */
149
+ CHAR_DOUBLE_QUOTE: 34,
150
+ /* " */
151
+ CHAR_EQUAL: 61,
152
+ /* = */
153
+ CHAR_EXCLAMATION_MARK: 33,
154
+ /* ! */
155
+ CHAR_FORM_FEED: 12,
156
+ /* \f */
157
+ CHAR_FORWARD_SLASH: 47,
158
+ /* / */
159
+ CHAR_GRAVE_ACCENT: 96,
160
+ /* ` */
161
+ CHAR_HASH: 35,
162
+ /* # */
163
+ CHAR_HYPHEN_MINUS: 45,
164
+ /* - */
165
+ CHAR_LEFT_ANGLE_BRACKET: 60,
166
+ /* < */
167
+ CHAR_LEFT_CURLY_BRACE: 123,
168
+ /* { */
169
+ CHAR_LEFT_SQUARE_BRACKET: 91,
170
+ /* [ */
171
+ CHAR_LINE_FEED: 10,
172
+ /* \n */
173
+ CHAR_NO_BREAK_SPACE: 160,
174
+ /* \u00A0 */
175
+ CHAR_PERCENT: 37,
176
+ /* % */
177
+ CHAR_PLUS: 43,
178
+ /* + */
179
+ CHAR_QUESTION_MARK: 63,
180
+ /* ? */
181
+ CHAR_RIGHT_ANGLE_BRACKET: 62,
182
+ /* > */
183
+ CHAR_RIGHT_CURLY_BRACE: 125,
184
+ /* } */
185
+ CHAR_RIGHT_SQUARE_BRACKET: 93,
186
+ /* ] */
187
+ CHAR_SEMICOLON: 59,
188
+ /* ; */
189
+ CHAR_SINGLE_QUOTE: 39,
190
+ /* ' */
191
+ CHAR_SPACE: 32,
192
+ /* */
193
+ CHAR_TAB: 9,
194
+ /* \t */
195
+ CHAR_UNDERSCORE: 95,
196
+ /* _ */
197
+ CHAR_VERTICAL_LINE: 124,
198
+ /* | */
199
+ CHAR_ZERO_WIDTH_NOBREAK_SPACE: 65279,
200
+ /* \uFEFF */
201
+ /**
202
+ * Create EXTGLOB_CHARS
203
+ */
204
+ extglobChars(chars) {
205
+ return {
206
+ "!": { type: "negate", open: "(?:(?!(?:", close: `))${chars.STAR})` },
207
+ "?": { type: "qmark", open: "(?:", close: ")?" },
208
+ "+": { type: "plus", open: "(?:", close: ")+" },
209
+ "*": { type: "star", open: "(?:", close: ")*" },
210
+ "@": { type: "at", open: "(?:", close: ")" }
211
+ };
212
+ },
213
+ /**
214
+ * Create GLOB_CHARS
215
+ */
216
+ globChars(win32) {
217
+ return win32 === true ? WINDOWS_CHARS : POSIX_CHARS;
218
+ }
219
+ };
220
+ }
221
+ });
222
+
223
+ // ../../node_modules/.pnpm/picomatch@4.0.4/node_modules/picomatch/lib/utils.js
224
+ var require_utils = __commonJS({
225
+ "../../node_modules/.pnpm/picomatch@4.0.4/node_modules/picomatch/lib/utils.js"(exports) {
226
+ "use strict";
227
+ var {
228
+ REGEX_BACKSLASH,
229
+ REGEX_REMOVE_BACKSLASH,
230
+ REGEX_SPECIAL_CHARS,
231
+ REGEX_SPECIAL_CHARS_GLOBAL
232
+ } = require_constants();
233
+ exports.isObject = (val) => val !== null && typeof val === "object" && !Array.isArray(val);
234
+ exports.hasRegexChars = (str) => REGEX_SPECIAL_CHARS.test(str);
235
+ exports.isRegexChar = (str) => str.length === 1 && exports.hasRegexChars(str);
236
+ exports.escapeRegex = (str) => str.replace(REGEX_SPECIAL_CHARS_GLOBAL, "\\$1");
237
+ exports.toPosixSlashes = (str) => str.replace(REGEX_BACKSLASH, "/");
238
+ exports.isWindows = () => {
239
+ if (typeof navigator !== "undefined" && navigator.platform) {
240
+ const platform = navigator.platform.toLowerCase();
241
+ return platform === "win32" || platform === "windows";
242
+ }
243
+ if (typeof process !== "undefined" && process.platform) {
244
+ return process.platform === "win32";
245
+ }
246
+ return false;
247
+ };
248
+ exports.removeBackslashes = (str) => {
249
+ return str.replace(REGEX_REMOVE_BACKSLASH, (match) => {
250
+ return match === "\\" ? "" : match;
251
+ });
252
+ };
253
+ exports.escapeLast = (input, char, lastIdx) => {
254
+ const idx = input.lastIndexOf(char, lastIdx);
255
+ if (idx === -1) return input;
256
+ if (input[idx - 1] === "\\") return exports.escapeLast(input, char, idx - 1);
257
+ return `${input.slice(0, idx)}\\${input.slice(idx)}`;
258
+ };
259
+ exports.removePrefix = (input, state = {}) => {
260
+ let output = input;
261
+ if (output.startsWith("./")) {
262
+ output = output.slice(2);
263
+ state.prefix = "./";
264
+ }
265
+ return output;
266
+ };
267
+ exports.wrapOutput = (input, state = {}, options = {}) => {
268
+ const prepend = options.contains ? "" : "^";
269
+ const append = options.contains ? "" : "$";
270
+ let output = `${prepend}(?:${input})${append}`;
271
+ if (state.negated === true) {
272
+ output = `(?:^(?!${output}).*$)`;
273
+ }
274
+ return output;
275
+ };
276
+ exports.basename = (path, { windows } = {}) => {
277
+ const segs = path.split(windows ? /[\\/]/ : "/");
278
+ const last = segs[segs.length - 1];
279
+ if (last === "") {
280
+ return segs[segs.length - 2];
281
+ }
282
+ return last;
283
+ };
284
+ }
285
+ });
286
+
287
+ // ../../node_modules/.pnpm/picomatch@4.0.4/node_modules/picomatch/lib/scan.js
288
+ var require_scan = __commonJS({
289
+ "../../node_modules/.pnpm/picomatch@4.0.4/node_modules/picomatch/lib/scan.js"(exports, module) {
290
+ "use strict";
291
+ var utils = require_utils();
292
+ var {
293
+ CHAR_ASTERISK,
294
+ /* * */
295
+ CHAR_AT,
296
+ /* @ */
297
+ CHAR_BACKWARD_SLASH,
298
+ /* \ */
299
+ CHAR_COMMA,
300
+ /* , */
301
+ CHAR_DOT,
302
+ /* . */
303
+ CHAR_EXCLAMATION_MARK,
304
+ /* ! */
305
+ CHAR_FORWARD_SLASH,
306
+ /* / */
307
+ CHAR_LEFT_CURLY_BRACE,
308
+ /* { */
309
+ CHAR_LEFT_PARENTHESES,
310
+ /* ( */
311
+ CHAR_LEFT_SQUARE_BRACKET,
312
+ /* [ */
313
+ CHAR_PLUS,
314
+ /* + */
315
+ CHAR_QUESTION_MARK,
316
+ /* ? */
317
+ CHAR_RIGHT_CURLY_BRACE,
318
+ /* } */
319
+ CHAR_RIGHT_PARENTHESES,
320
+ /* ) */
321
+ CHAR_RIGHT_SQUARE_BRACKET
322
+ /* ] */
323
+ } = require_constants();
324
+ var isPathSeparator = (code) => {
325
+ return code === CHAR_FORWARD_SLASH || code === CHAR_BACKWARD_SLASH;
326
+ };
327
+ var depth = (token) => {
328
+ if (token.isPrefix !== true) {
329
+ token.depth = token.isGlobstar ? Infinity : 1;
330
+ }
331
+ };
332
+ var scan = (input, options) => {
333
+ const opts = options || {};
334
+ const length = input.length - 1;
335
+ const scanToEnd = opts.parts === true || opts.scanToEnd === true;
336
+ const slashes = [];
337
+ const tokens = [];
338
+ const parts = [];
339
+ let str = input;
340
+ let index = -1;
341
+ let start = 0;
342
+ let lastIndex = 0;
343
+ let isBrace = false;
344
+ let isBracket = false;
345
+ let isGlob = false;
346
+ let isExtglob = false;
347
+ let isGlobstar = false;
348
+ let braceEscaped = false;
349
+ let backslashes = false;
350
+ let negated = false;
351
+ let negatedExtglob = false;
352
+ let finished = false;
353
+ let braces = 0;
354
+ let prev;
355
+ let code;
356
+ let token = { value: "", depth: 0, isGlob: false };
357
+ const eos = () => index >= length;
358
+ const peek = () => str.charCodeAt(index + 1);
359
+ const advance = () => {
360
+ prev = code;
361
+ return str.charCodeAt(++index);
362
+ };
363
+ while (index < length) {
364
+ code = advance();
365
+ let next;
366
+ if (code === CHAR_BACKWARD_SLASH) {
367
+ backslashes = token.backslashes = true;
368
+ code = advance();
369
+ if (code === CHAR_LEFT_CURLY_BRACE) {
370
+ braceEscaped = true;
371
+ }
372
+ continue;
373
+ }
374
+ if (braceEscaped === true || code === CHAR_LEFT_CURLY_BRACE) {
375
+ braces++;
376
+ while (eos() !== true && (code = advance())) {
377
+ if (code === CHAR_BACKWARD_SLASH) {
378
+ backslashes = token.backslashes = true;
379
+ advance();
380
+ continue;
381
+ }
382
+ if (code === CHAR_LEFT_CURLY_BRACE) {
383
+ braces++;
384
+ continue;
385
+ }
386
+ if (braceEscaped !== true && code === CHAR_DOT && (code = advance()) === CHAR_DOT) {
387
+ isBrace = token.isBrace = true;
388
+ isGlob = token.isGlob = true;
389
+ finished = true;
390
+ if (scanToEnd === true) {
391
+ continue;
392
+ }
393
+ break;
394
+ }
395
+ if (braceEscaped !== true && code === CHAR_COMMA) {
396
+ isBrace = token.isBrace = true;
397
+ isGlob = token.isGlob = true;
398
+ finished = true;
399
+ if (scanToEnd === true) {
400
+ continue;
401
+ }
402
+ break;
403
+ }
404
+ if (code === CHAR_RIGHT_CURLY_BRACE) {
405
+ braces--;
406
+ if (braces === 0) {
407
+ braceEscaped = false;
408
+ isBrace = token.isBrace = true;
409
+ finished = true;
410
+ break;
411
+ }
412
+ }
413
+ }
414
+ if (scanToEnd === true) {
415
+ continue;
416
+ }
417
+ break;
418
+ }
419
+ if (code === CHAR_FORWARD_SLASH) {
420
+ slashes.push(index);
421
+ tokens.push(token);
422
+ token = { value: "", depth: 0, isGlob: false };
423
+ if (finished === true) continue;
424
+ if (prev === CHAR_DOT && index === start + 1) {
425
+ start += 2;
426
+ continue;
427
+ }
428
+ lastIndex = index + 1;
429
+ continue;
430
+ }
431
+ if (opts.noext !== true) {
432
+ const isExtglobChar = code === CHAR_PLUS || code === CHAR_AT || code === CHAR_ASTERISK || code === CHAR_QUESTION_MARK || code === CHAR_EXCLAMATION_MARK;
433
+ if (isExtglobChar === true && peek() === CHAR_LEFT_PARENTHESES) {
434
+ isGlob = token.isGlob = true;
435
+ isExtglob = token.isExtglob = true;
436
+ finished = true;
437
+ if (code === CHAR_EXCLAMATION_MARK && index === start) {
438
+ negatedExtglob = true;
439
+ }
440
+ if (scanToEnd === true) {
441
+ while (eos() !== true && (code = advance())) {
442
+ if (code === CHAR_BACKWARD_SLASH) {
443
+ backslashes = token.backslashes = true;
444
+ code = advance();
445
+ continue;
446
+ }
447
+ if (code === CHAR_RIGHT_PARENTHESES) {
448
+ isGlob = token.isGlob = true;
449
+ finished = true;
450
+ break;
451
+ }
452
+ }
453
+ continue;
454
+ }
455
+ break;
456
+ }
457
+ }
458
+ if (code === CHAR_ASTERISK) {
459
+ if (prev === CHAR_ASTERISK) isGlobstar = token.isGlobstar = true;
460
+ isGlob = token.isGlob = true;
461
+ finished = true;
462
+ if (scanToEnd === true) {
463
+ continue;
464
+ }
465
+ break;
466
+ }
467
+ if (code === CHAR_QUESTION_MARK) {
468
+ isGlob = token.isGlob = true;
469
+ finished = true;
470
+ if (scanToEnd === true) {
471
+ continue;
472
+ }
473
+ break;
474
+ }
475
+ if (code === CHAR_LEFT_SQUARE_BRACKET) {
476
+ while (eos() !== true && (next = advance())) {
477
+ if (next === CHAR_BACKWARD_SLASH) {
478
+ backslashes = token.backslashes = true;
479
+ advance();
480
+ continue;
481
+ }
482
+ if (next === CHAR_RIGHT_SQUARE_BRACKET) {
483
+ isBracket = token.isBracket = true;
484
+ isGlob = token.isGlob = true;
485
+ finished = true;
486
+ break;
487
+ }
488
+ }
489
+ if (scanToEnd === true) {
490
+ continue;
491
+ }
492
+ break;
493
+ }
494
+ if (opts.nonegate !== true && code === CHAR_EXCLAMATION_MARK && index === start) {
495
+ negated = token.negated = true;
496
+ start++;
497
+ continue;
498
+ }
499
+ if (opts.noparen !== true && code === CHAR_LEFT_PARENTHESES) {
500
+ isGlob = token.isGlob = true;
501
+ if (scanToEnd === true) {
502
+ while (eos() !== true && (code = advance())) {
503
+ if (code === CHAR_LEFT_PARENTHESES) {
504
+ backslashes = token.backslashes = true;
505
+ code = advance();
506
+ continue;
507
+ }
508
+ if (code === CHAR_RIGHT_PARENTHESES) {
509
+ finished = true;
510
+ break;
511
+ }
512
+ }
513
+ continue;
514
+ }
515
+ break;
516
+ }
517
+ if (isGlob === true) {
518
+ finished = true;
519
+ if (scanToEnd === true) {
520
+ continue;
521
+ }
522
+ break;
523
+ }
524
+ }
525
+ if (opts.noext === true) {
526
+ isExtglob = false;
527
+ isGlob = false;
528
+ }
529
+ let base = str;
530
+ let prefix = "";
531
+ let glob = "";
532
+ if (start > 0) {
533
+ prefix = str.slice(0, start);
534
+ str = str.slice(start);
535
+ lastIndex -= start;
536
+ }
537
+ if (base && isGlob === true && lastIndex > 0) {
538
+ base = str.slice(0, lastIndex);
539
+ glob = str.slice(lastIndex);
540
+ } else if (isGlob === true) {
541
+ base = "";
542
+ glob = str;
543
+ } else {
544
+ base = str;
545
+ }
546
+ if (base && base !== "" && base !== "/" && base !== str) {
547
+ if (isPathSeparator(base.charCodeAt(base.length - 1))) {
548
+ base = base.slice(0, -1);
549
+ }
550
+ }
551
+ if (opts.unescape === true) {
552
+ if (glob) glob = utils.removeBackslashes(glob);
553
+ if (base && backslashes === true) {
554
+ base = utils.removeBackslashes(base);
555
+ }
556
+ }
557
+ const state = {
558
+ prefix,
559
+ input,
560
+ start,
561
+ base,
562
+ glob,
563
+ isBrace,
564
+ isBracket,
565
+ isGlob,
566
+ isExtglob,
567
+ isGlobstar,
568
+ negated,
569
+ negatedExtglob
570
+ };
571
+ if (opts.tokens === true) {
572
+ state.maxDepth = 0;
573
+ if (!isPathSeparator(code)) {
574
+ tokens.push(token);
575
+ }
576
+ state.tokens = tokens;
577
+ }
578
+ if (opts.parts === true || opts.tokens === true) {
579
+ let prevIndex;
580
+ for (let idx = 0; idx < slashes.length; idx++) {
581
+ const n = prevIndex ? prevIndex + 1 : start;
582
+ const i = slashes[idx];
583
+ const value = input.slice(n, i);
584
+ if (opts.tokens) {
585
+ if (idx === 0 && start !== 0) {
586
+ tokens[idx].isPrefix = true;
587
+ tokens[idx].value = prefix;
588
+ } else {
589
+ tokens[idx].value = value;
590
+ }
591
+ depth(tokens[idx]);
592
+ state.maxDepth += tokens[idx].depth;
593
+ }
594
+ if (idx !== 0 || value !== "") {
595
+ parts.push(value);
596
+ }
597
+ prevIndex = i;
598
+ }
599
+ if (prevIndex && prevIndex + 1 < input.length) {
600
+ const value = input.slice(prevIndex + 1);
601
+ parts.push(value);
602
+ if (opts.tokens) {
603
+ tokens[tokens.length - 1].value = value;
604
+ depth(tokens[tokens.length - 1]);
605
+ state.maxDepth += tokens[tokens.length - 1].depth;
606
+ }
607
+ }
608
+ state.slashes = slashes;
609
+ state.parts = parts;
610
+ }
611
+ return state;
612
+ };
613
+ module.exports = scan;
614
+ }
615
+ });
616
+
617
+ // ../../node_modules/.pnpm/picomatch@4.0.4/node_modules/picomatch/lib/parse.js
618
+ var require_parse = __commonJS({
619
+ "../../node_modules/.pnpm/picomatch@4.0.4/node_modules/picomatch/lib/parse.js"(exports, module) {
620
+ "use strict";
621
+ var constants = require_constants();
622
+ var utils = require_utils();
623
+ var {
624
+ MAX_LENGTH,
625
+ POSIX_REGEX_SOURCE,
626
+ REGEX_NON_SPECIAL_CHARS,
627
+ REGEX_SPECIAL_CHARS_BACKREF,
628
+ REPLACEMENTS
629
+ } = constants;
630
+ var expandRange = (args, options) => {
631
+ if (typeof options.expandRange === "function") {
632
+ return options.expandRange(...args, options);
633
+ }
634
+ args.sort();
635
+ const value = `[${args.join("-")}]`;
636
+ try {
637
+ new RegExp(value);
638
+ } catch (ex) {
639
+ return args.map((v) => utils.escapeRegex(v)).join("..");
640
+ }
641
+ return value;
642
+ };
643
+ var syntaxError = (type, char) => {
644
+ return `Missing ${type}: "${char}" - use "\\\\${char}" to match literal characters`;
645
+ };
646
+ var splitTopLevel = (input) => {
647
+ const parts = [];
648
+ let bracket = 0;
649
+ let paren = 0;
650
+ let quote = 0;
651
+ let value = "";
652
+ let escaped = false;
653
+ for (const ch of input) {
654
+ if (escaped === true) {
655
+ value += ch;
656
+ escaped = false;
657
+ continue;
658
+ }
659
+ if (ch === "\\") {
660
+ value += ch;
661
+ escaped = true;
662
+ continue;
663
+ }
664
+ if (ch === '"') {
665
+ quote = quote === 1 ? 0 : 1;
666
+ value += ch;
667
+ continue;
668
+ }
669
+ if (quote === 0) {
670
+ if (ch === "[") {
671
+ bracket++;
672
+ } else if (ch === "]" && bracket > 0) {
673
+ bracket--;
674
+ } else if (bracket === 0) {
675
+ if (ch === "(") {
676
+ paren++;
677
+ } else if (ch === ")" && paren > 0) {
678
+ paren--;
679
+ } else if (ch === "|" && paren === 0) {
680
+ parts.push(value);
681
+ value = "";
682
+ continue;
683
+ }
684
+ }
685
+ }
686
+ value += ch;
687
+ }
688
+ parts.push(value);
689
+ return parts;
690
+ };
691
+ var isPlainBranch = (branch) => {
692
+ let escaped = false;
693
+ for (const ch of branch) {
694
+ if (escaped === true) {
695
+ escaped = false;
696
+ continue;
697
+ }
698
+ if (ch === "\\") {
699
+ escaped = true;
700
+ continue;
701
+ }
702
+ if (/[?*+@!()[\]{}]/.test(ch)) {
703
+ return false;
704
+ }
705
+ }
706
+ return true;
707
+ };
708
+ var normalizeSimpleBranch = (branch) => {
709
+ let value = branch.trim();
710
+ let changed = true;
711
+ while (changed === true) {
712
+ changed = false;
713
+ if (/^@\([^\\()[\]{}|]+\)$/.test(value)) {
714
+ value = value.slice(2, -1);
715
+ changed = true;
716
+ }
717
+ }
718
+ if (!isPlainBranch(value)) {
719
+ return;
720
+ }
721
+ return value.replace(/\\(.)/g, "$1");
722
+ };
723
+ var hasRepeatedCharPrefixOverlap = (branches) => {
724
+ const values = branches.map(normalizeSimpleBranch).filter(Boolean);
725
+ for (let i = 0; i < values.length; i++) {
726
+ for (let j = i + 1; j < values.length; j++) {
727
+ const a = values[i];
728
+ const b = values[j];
729
+ const char = a[0];
730
+ if (!char || a !== char.repeat(a.length) || b !== char.repeat(b.length)) {
731
+ continue;
732
+ }
733
+ if (a === b || a.startsWith(b) || b.startsWith(a)) {
734
+ return true;
735
+ }
736
+ }
737
+ }
738
+ return false;
739
+ };
740
+ var parseRepeatedExtglob = (pattern, requireEnd = true) => {
741
+ if (pattern[0] !== "+" && pattern[0] !== "*" || pattern[1] !== "(") {
742
+ return;
743
+ }
744
+ let bracket = 0;
745
+ let paren = 0;
746
+ let quote = 0;
747
+ let escaped = false;
748
+ for (let i = 1; i < pattern.length; i++) {
749
+ const ch = pattern[i];
750
+ if (escaped === true) {
751
+ escaped = false;
752
+ continue;
753
+ }
754
+ if (ch === "\\") {
755
+ escaped = true;
756
+ continue;
757
+ }
758
+ if (ch === '"') {
759
+ quote = quote === 1 ? 0 : 1;
760
+ continue;
761
+ }
762
+ if (quote === 1) {
763
+ continue;
764
+ }
765
+ if (ch === "[") {
766
+ bracket++;
767
+ continue;
768
+ }
769
+ if (ch === "]" && bracket > 0) {
770
+ bracket--;
771
+ continue;
772
+ }
773
+ if (bracket > 0) {
774
+ continue;
775
+ }
776
+ if (ch === "(") {
777
+ paren++;
778
+ continue;
779
+ }
780
+ if (ch === ")") {
781
+ paren--;
782
+ if (paren === 0) {
783
+ if (requireEnd === true && i !== pattern.length - 1) {
784
+ return;
785
+ }
786
+ return {
787
+ type: pattern[0],
788
+ body: pattern.slice(2, i),
789
+ end: i
790
+ };
791
+ }
792
+ }
793
+ }
794
+ };
795
+ var getStarExtglobSequenceOutput = (pattern) => {
796
+ let index = 0;
797
+ const chars = [];
798
+ while (index < pattern.length) {
799
+ const match = parseRepeatedExtglob(pattern.slice(index), false);
800
+ if (!match || match.type !== "*") {
801
+ return;
802
+ }
803
+ const branches = splitTopLevel(match.body).map((branch2) => branch2.trim());
804
+ if (branches.length !== 1) {
805
+ return;
806
+ }
807
+ const branch = normalizeSimpleBranch(branches[0]);
808
+ if (!branch || branch.length !== 1) {
809
+ return;
810
+ }
811
+ chars.push(branch);
812
+ index += match.end + 1;
813
+ }
814
+ if (chars.length < 1) {
815
+ return;
816
+ }
817
+ const source = chars.length === 1 ? utils.escapeRegex(chars[0]) : `[${chars.map((ch) => utils.escapeRegex(ch)).join("")}]`;
818
+ return `${source}*`;
819
+ };
820
+ var repeatedExtglobRecursion = (pattern) => {
821
+ let depth = 0;
822
+ let value = pattern.trim();
823
+ let match = parseRepeatedExtglob(value);
824
+ while (match) {
825
+ depth++;
826
+ value = match.body.trim();
827
+ match = parseRepeatedExtglob(value);
828
+ }
829
+ return depth;
830
+ };
831
+ var analyzeRepeatedExtglob = (body, options) => {
832
+ if (options.maxExtglobRecursion === false) {
833
+ return { risky: false };
834
+ }
835
+ const max = typeof options.maxExtglobRecursion === "number" ? options.maxExtglobRecursion : constants.DEFAULT_MAX_EXTGLOB_RECURSION;
836
+ const branches = splitTopLevel(body).map((branch) => branch.trim());
837
+ if (branches.length > 1) {
838
+ if (branches.some((branch) => branch === "") || branches.some((branch) => /^[*?]+$/.test(branch)) || hasRepeatedCharPrefixOverlap(branches)) {
839
+ return { risky: true };
840
+ }
841
+ }
842
+ for (const branch of branches) {
843
+ const safeOutput = getStarExtglobSequenceOutput(branch);
844
+ if (safeOutput) {
845
+ return { risky: true, safeOutput };
846
+ }
847
+ if (repeatedExtglobRecursion(branch) > max) {
848
+ return { risky: true };
849
+ }
850
+ }
851
+ return { risky: false };
852
+ };
853
+ var parse = (input, options) => {
854
+ if (typeof input !== "string") {
855
+ throw new TypeError("Expected a string");
856
+ }
857
+ input = REPLACEMENTS[input] || input;
858
+ const opts = { ...options };
859
+ const max = typeof opts.maxLength === "number" ? Math.min(MAX_LENGTH, opts.maxLength) : MAX_LENGTH;
860
+ let len = input.length;
861
+ if (len > max) {
862
+ throw new SyntaxError(`Input length: ${len}, exceeds maximum allowed length: ${max}`);
863
+ }
864
+ const bos = { type: "bos", value: "", output: opts.prepend || "" };
865
+ const tokens = [bos];
866
+ const capture = opts.capture ? "" : "?:";
867
+ const PLATFORM_CHARS = constants.globChars(opts.windows);
868
+ const EXTGLOB_CHARS = constants.extglobChars(PLATFORM_CHARS);
869
+ const {
870
+ DOT_LITERAL,
871
+ PLUS_LITERAL,
872
+ SLASH_LITERAL,
873
+ ONE_CHAR,
874
+ DOTS_SLASH,
875
+ NO_DOT,
876
+ NO_DOT_SLASH,
877
+ NO_DOTS_SLASH,
878
+ QMARK,
879
+ QMARK_NO_DOT,
880
+ STAR,
881
+ START_ANCHOR
882
+ } = PLATFORM_CHARS;
883
+ const globstar = (opts2) => {
884
+ return `(${capture}(?:(?!${START_ANCHOR}${opts2.dot ? DOTS_SLASH : DOT_LITERAL}).)*?)`;
885
+ };
886
+ const nodot = opts.dot ? "" : NO_DOT;
887
+ const qmarkNoDot = opts.dot ? QMARK : QMARK_NO_DOT;
888
+ let star = opts.bash === true ? globstar(opts) : STAR;
889
+ if (opts.capture) {
890
+ star = `(${star})`;
891
+ }
892
+ if (typeof opts.noext === "boolean") {
893
+ opts.noextglob = opts.noext;
894
+ }
895
+ const state = {
896
+ input,
897
+ index: -1,
898
+ start: 0,
899
+ dot: opts.dot === true,
900
+ consumed: "",
901
+ output: "",
902
+ prefix: "",
903
+ backtrack: false,
904
+ negated: false,
905
+ brackets: 0,
906
+ braces: 0,
907
+ parens: 0,
908
+ quotes: 0,
909
+ globstar: false,
910
+ tokens
911
+ };
912
+ input = utils.removePrefix(input, state);
913
+ len = input.length;
914
+ const extglobs = [];
915
+ const braces = [];
916
+ const stack = [];
917
+ let prev = bos;
918
+ let value;
919
+ const eos = () => state.index === len - 1;
920
+ const peek = state.peek = (n = 1) => input[state.index + n];
921
+ const advance = state.advance = () => input[++state.index] || "";
922
+ const remaining = () => input.slice(state.index + 1);
923
+ const consume = (value2 = "", num = 0) => {
924
+ state.consumed += value2;
925
+ state.index += num;
926
+ };
927
+ const append = (token) => {
928
+ state.output += token.output != null ? token.output : token.value;
929
+ consume(token.value);
930
+ };
931
+ const negate = () => {
932
+ let count = 1;
933
+ while (peek() === "!" && (peek(2) !== "(" || peek(3) === "?")) {
934
+ advance();
935
+ state.start++;
936
+ count++;
937
+ }
938
+ if (count % 2 === 0) {
939
+ return false;
940
+ }
941
+ state.negated = true;
942
+ state.start++;
943
+ return true;
944
+ };
945
+ const increment = (type) => {
946
+ state[type]++;
947
+ stack.push(type);
948
+ };
949
+ const decrement = (type) => {
950
+ state[type]--;
951
+ stack.pop();
952
+ };
953
+ const push = (tok) => {
954
+ if (prev.type === "globstar") {
955
+ const isBrace = state.braces > 0 && (tok.type === "comma" || tok.type === "brace");
956
+ const isExtglob = tok.extglob === true || extglobs.length && (tok.type === "pipe" || tok.type === "paren");
957
+ if (tok.type !== "slash" && tok.type !== "paren" && !isBrace && !isExtglob) {
958
+ state.output = state.output.slice(0, -prev.output.length);
959
+ prev.type = "star";
960
+ prev.value = "*";
961
+ prev.output = star;
962
+ state.output += prev.output;
963
+ }
964
+ }
965
+ if (extglobs.length && tok.type !== "paren") {
966
+ extglobs[extglobs.length - 1].inner += tok.value;
967
+ }
968
+ if (tok.value || tok.output) append(tok);
969
+ if (prev && prev.type === "text" && tok.type === "text") {
970
+ prev.output = (prev.output || prev.value) + tok.value;
971
+ prev.value += tok.value;
972
+ return;
973
+ }
974
+ tok.prev = prev;
975
+ tokens.push(tok);
976
+ prev = tok;
977
+ };
978
+ const extglobOpen = (type, value2) => {
979
+ const token = { ...EXTGLOB_CHARS[value2], conditions: 1, inner: "" };
980
+ token.prev = prev;
981
+ token.parens = state.parens;
982
+ token.output = state.output;
983
+ token.startIndex = state.index;
984
+ token.tokensIndex = tokens.length;
985
+ const output = (opts.capture ? "(" : "") + token.open;
986
+ increment("parens");
987
+ push({ type, value: value2, output: state.output ? "" : ONE_CHAR });
988
+ push({ type: "paren", extglob: true, value: advance(), output });
989
+ extglobs.push(token);
990
+ };
991
+ const extglobClose = (token) => {
992
+ const literal = input.slice(token.startIndex, state.index + 1);
993
+ const body = input.slice(token.startIndex + 2, state.index);
994
+ const analysis = analyzeRepeatedExtglob(body, opts);
995
+ if ((token.type === "plus" || token.type === "star") && analysis.risky) {
996
+ const safeOutput = analysis.safeOutput ? (token.output ? "" : ONE_CHAR) + (opts.capture ? `(${analysis.safeOutput})` : analysis.safeOutput) : void 0;
997
+ const open = tokens[token.tokensIndex];
998
+ open.type = "text";
999
+ open.value = literal;
1000
+ open.output = safeOutput || utils.escapeRegex(literal);
1001
+ for (let i = token.tokensIndex + 1; i < tokens.length; i++) {
1002
+ tokens[i].value = "";
1003
+ tokens[i].output = "";
1004
+ delete tokens[i].suffix;
1005
+ }
1006
+ state.output = token.output + open.output;
1007
+ state.backtrack = true;
1008
+ push({ type: "paren", extglob: true, value, output: "" });
1009
+ decrement("parens");
1010
+ return;
1011
+ }
1012
+ let output = token.close + (opts.capture ? ")" : "");
1013
+ let rest;
1014
+ if (token.type === "negate") {
1015
+ let extglobStar = star;
1016
+ if (token.inner && token.inner.length > 1 && token.inner.includes("/")) {
1017
+ extglobStar = globstar(opts);
1018
+ }
1019
+ if (extglobStar !== star || eos() || /^\)+$/.test(remaining())) {
1020
+ output = token.close = `)$))${extglobStar}`;
1021
+ }
1022
+ if (token.inner.includes("*") && (rest = remaining()) && /^\.[^\\/.]+$/.test(rest)) {
1023
+ const expression = parse(rest, { ...options, fastpaths: false }).output;
1024
+ output = token.close = `)${expression})${extglobStar})`;
1025
+ }
1026
+ if (token.prev.type === "bos") {
1027
+ state.negatedExtglob = true;
1028
+ }
1029
+ }
1030
+ push({ type: "paren", extglob: true, value, output });
1031
+ decrement("parens");
1032
+ };
1033
+ if (opts.fastpaths !== false && !/(^[*!]|[/()[\]{}"])/.test(input)) {
1034
+ let backslashes = false;
1035
+ let output = input.replace(REGEX_SPECIAL_CHARS_BACKREF, (m, esc, chars, first, rest, index) => {
1036
+ if (first === "\\") {
1037
+ backslashes = true;
1038
+ return m;
1039
+ }
1040
+ if (first === "?") {
1041
+ if (esc) {
1042
+ return esc + first + (rest ? QMARK.repeat(rest.length) : "");
1043
+ }
1044
+ if (index === 0) {
1045
+ return qmarkNoDot + (rest ? QMARK.repeat(rest.length) : "");
1046
+ }
1047
+ return QMARK.repeat(chars.length);
1048
+ }
1049
+ if (first === ".") {
1050
+ return DOT_LITERAL.repeat(chars.length);
1051
+ }
1052
+ if (first === "*") {
1053
+ if (esc) {
1054
+ return esc + first + (rest ? star : "");
1055
+ }
1056
+ return star;
1057
+ }
1058
+ return esc ? m : `\\${m}`;
1059
+ });
1060
+ if (backslashes === true) {
1061
+ if (opts.unescape === true) {
1062
+ output = output.replace(/\\/g, "");
1063
+ } else {
1064
+ output = output.replace(/\\+/g, (m) => {
1065
+ return m.length % 2 === 0 ? "\\\\" : m ? "\\" : "";
1066
+ });
1067
+ }
1068
+ }
1069
+ if (output === input && opts.contains === true) {
1070
+ state.output = input;
1071
+ return state;
1072
+ }
1073
+ state.output = utils.wrapOutput(output, state, options);
1074
+ return state;
1075
+ }
1076
+ while (!eos()) {
1077
+ value = advance();
1078
+ if (value === "\0") {
1079
+ continue;
1080
+ }
1081
+ if (value === "\\") {
1082
+ const next = peek();
1083
+ if (next === "/" && opts.bash !== true) {
1084
+ continue;
1085
+ }
1086
+ if (next === "." || next === ";") {
1087
+ continue;
1088
+ }
1089
+ if (!next) {
1090
+ value += "\\";
1091
+ push({ type: "text", value });
1092
+ continue;
1093
+ }
1094
+ const match = /^\\+/.exec(remaining());
1095
+ let slashes = 0;
1096
+ if (match && match[0].length > 2) {
1097
+ slashes = match[0].length;
1098
+ state.index += slashes;
1099
+ if (slashes % 2 !== 0) {
1100
+ value += "\\";
1101
+ }
1102
+ }
1103
+ if (opts.unescape === true) {
1104
+ value = advance();
1105
+ } else {
1106
+ value += advance();
1107
+ }
1108
+ if (state.brackets === 0) {
1109
+ push({ type: "text", value });
1110
+ continue;
1111
+ }
1112
+ }
1113
+ if (state.brackets > 0 && (value !== "]" || prev.value === "[" || prev.value === "[^")) {
1114
+ if (opts.posix !== false && value === ":") {
1115
+ const inner = prev.value.slice(1);
1116
+ if (inner.includes("[")) {
1117
+ prev.posix = true;
1118
+ if (inner.includes(":")) {
1119
+ const idx = prev.value.lastIndexOf("[");
1120
+ const pre = prev.value.slice(0, idx);
1121
+ const rest2 = prev.value.slice(idx + 2);
1122
+ const posix = POSIX_REGEX_SOURCE[rest2];
1123
+ if (posix) {
1124
+ prev.value = pre + posix;
1125
+ state.backtrack = true;
1126
+ advance();
1127
+ if (!bos.output && tokens.indexOf(prev) === 1) {
1128
+ bos.output = ONE_CHAR;
1129
+ }
1130
+ continue;
1131
+ }
1132
+ }
1133
+ }
1134
+ }
1135
+ if (value === "[" && peek() !== ":" || value === "-" && peek() === "]") {
1136
+ value = `\\${value}`;
1137
+ }
1138
+ if (value === "]" && (prev.value === "[" || prev.value === "[^")) {
1139
+ value = `\\${value}`;
1140
+ }
1141
+ if (opts.posix === true && value === "!" && prev.value === "[") {
1142
+ value = "^";
1143
+ }
1144
+ prev.value += value;
1145
+ append({ value });
1146
+ continue;
1147
+ }
1148
+ if (state.quotes === 1 && value !== '"') {
1149
+ value = utils.escapeRegex(value);
1150
+ prev.value += value;
1151
+ append({ value });
1152
+ continue;
1153
+ }
1154
+ if (value === '"') {
1155
+ state.quotes = state.quotes === 1 ? 0 : 1;
1156
+ if (opts.keepQuotes === true) {
1157
+ push({ type: "text", value });
1158
+ }
1159
+ continue;
1160
+ }
1161
+ if (value === "(") {
1162
+ increment("parens");
1163
+ push({ type: "paren", value });
1164
+ continue;
1165
+ }
1166
+ if (value === ")") {
1167
+ if (state.parens === 0 && opts.strictBrackets === true) {
1168
+ throw new SyntaxError(syntaxError("opening", "("));
1169
+ }
1170
+ const extglob = extglobs[extglobs.length - 1];
1171
+ if (extglob && state.parens === extglob.parens + 1) {
1172
+ extglobClose(extglobs.pop());
1173
+ continue;
1174
+ }
1175
+ push({ type: "paren", value, output: state.parens ? ")" : "\\)" });
1176
+ decrement("parens");
1177
+ continue;
1178
+ }
1179
+ if (value === "[") {
1180
+ if (opts.nobracket === true || !remaining().includes("]")) {
1181
+ if (opts.nobracket !== true && opts.strictBrackets === true) {
1182
+ throw new SyntaxError(syntaxError("closing", "]"));
1183
+ }
1184
+ value = `\\${value}`;
1185
+ } else {
1186
+ increment("brackets");
1187
+ }
1188
+ push({ type: "bracket", value });
1189
+ continue;
1190
+ }
1191
+ if (value === "]") {
1192
+ if (opts.nobracket === true || prev && prev.type === "bracket" && prev.value.length === 1) {
1193
+ push({ type: "text", value, output: `\\${value}` });
1194
+ continue;
1195
+ }
1196
+ if (state.brackets === 0) {
1197
+ if (opts.strictBrackets === true) {
1198
+ throw new SyntaxError(syntaxError("opening", "["));
1199
+ }
1200
+ push({ type: "text", value, output: `\\${value}` });
1201
+ continue;
1202
+ }
1203
+ decrement("brackets");
1204
+ const prevValue = prev.value.slice(1);
1205
+ if (prev.posix !== true && prevValue[0] === "^" && !prevValue.includes("/")) {
1206
+ value = `/${value}`;
1207
+ }
1208
+ prev.value += value;
1209
+ append({ value });
1210
+ if (opts.literalBrackets === false || utils.hasRegexChars(prevValue)) {
1211
+ continue;
1212
+ }
1213
+ const escaped = utils.escapeRegex(prev.value);
1214
+ state.output = state.output.slice(0, -prev.value.length);
1215
+ if (opts.literalBrackets === true) {
1216
+ state.output += escaped;
1217
+ prev.value = escaped;
1218
+ continue;
1219
+ }
1220
+ prev.value = `(${capture}${escaped}|${prev.value})`;
1221
+ state.output += prev.value;
1222
+ continue;
1223
+ }
1224
+ if (value === "{" && opts.nobrace !== true) {
1225
+ increment("braces");
1226
+ const open = {
1227
+ type: "brace",
1228
+ value,
1229
+ output: "(",
1230
+ outputIndex: state.output.length,
1231
+ tokensIndex: state.tokens.length
1232
+ };
1233
+ braces.push(open);
1234
+ push(open);
1235
+ continue;
1236
+ }
1237
+ if (value === "}") {
1238
+ const brace = braces[braces.length - 1];
1239
+ if (opts.nobrace === true || !brace) {
1240
+ push({ type: "text", value, output: value });
1241
+ continue;
1242
+ }
1243
+ let output = ")";
1244
+ if (brace.dots === true) {
1245
+ const arr = tokens.slice();
1246
+ const range = [];
1247
+ for (let i = arr.length - 1; i >= 0; i--) {
1248
+ tokens.pop();
1249
+ if (arr[i].type === "brace") {
1250
+ break;
1251
+ }
1252
+ if (arr[i].type !== "dots") {
1253
+ range.unshift(arr[i].value);
1254
+ }
1255
+ }
1256
+ output = expandRange(range, opts);
1257
+ state.backtrack = true;
1258
+ }
1259
+ if (brace.comma !== true && brace.dots !== true) {
1260
+ const out = state.output.slice(0, brace.outputIndex);
1261
+ const toks = state.tokens.slice(brace.tokensIndex);
1262
+ brace.value = brace.output = "\\{";
1263
+ value = output = "\\}";
1264
+ state.output = out;
1265
+ for (const t of toks) {
1266
+ state.output += t.output || t.value;
1267
+ }
1268
+ }
1269
+ push({ type: "brace", value, output });
1270
+ decrement("braces");
1271
+ braces.pop();
1272
+ continue;
1273
+ }
1274
+ if (value === "|") {
1275
+ if (extglobs.length > 0) {
1276
+ extglobs[extglobs.length - 1].conditions++;
1277
+ }
1278
+ push({ type: "text", value });
1279
+ continue;
1280
+ }
1281
+ if (value === ",") {
1282
+ let output = value;
1283
+ const brace = braces[braces.length - 1];
1284
+ if (brace && stack[stack.length - 1] === "braces") {
1285
+ brace.comma = true;
1286
+ output = "|";
1287
+ }
1288
+ push({ type: "comma", value, output });
1289
+ continue;
1290
+ }
1291
+ if (value === "/") {
1292
+ if (prev.type === "dot" && state.index === state.start + 1) {
1293
+ state.start = state.index + 1;
1294
+ state.consumed = "";
1295
+ state.output = "";
1296
+ tokens.pop();
1297
+ prev = bos;
1298
+ continue;
1299
+ }
1300
+ push({ type: "slash", value, output: SLASH_LITERAL });
1301
+ continue;
1302
+ }
1303
+ if (value === ".") {
1304
+ if (state.braces > 0 && prev.type === "dot") {
1305
+ if (prev.value === ".") prev.output = DOT_LITERAL;
1306
+ const brace = braces[braces.length - 1];
1307
+ prev.type = "dots";
1308
+ prev.output += value;
1309
+ prev.value += value;
1310
+ brace.dots = true;
1311
+ continue;
1312
+ }
1313
+ if (state.braces + state.parens === 0 && prev.type !== "bos" && prev.type !== "slash") {
1314
+ push({ type: "text", value, output: DOT_LITERAL });
1315
+ continue;
1316
+ }
1317
+ push({ type: "dot", value, output: DOT_LITERAL });
1318
+ continue;
1319
+ }
1320
+ if (value === "?") {
1321
+ const isGroup = prev && prev.value === "(";
1322
+ if (!isGroup && opts.noextglob !== true && peek() === "(" && peek(2) !== "?") {
1323
+ extglobOpen("qmark", value);
1324
+ continue;
1325
+ }
1326
+ if (prev && prev.type === "paren") {
1327
+ const next = peek();
1328
+ let output = value;
1329
+ if (prev.value === "(" && !/[!=<:]/.test(next) || next === "<" && !/<([!=]|\w+>)/.test(remaining())) {
1330
+ output = `\\${value}`;
1331
+ }
1332
+ push({ type: "text", value, output });
1333
+ continue;
1334
+ }
1335
+ if (opts.dot !== true && (prev.type === "slash" || prev.type === "bos")) {
1336
+ push({ type: "qmark", value, output: QMARK_NO_DOT });
1337
+ continue;
1338
+ }
1339
+ push({ type: "qmark", value, output: QMARK });
1340
+ continue;
1341
+ }
1342
+ if (value === "!") {
1343
+ if (opts.noextglob !== true && peek() === "(") {
1344
+ if (peek(2) !== "?" || !/[!=<:]/.test(peek(3))) {
1345
+ extglobOpen("negate", value);
1346
+ continue;
1347
+ }
1348
+ }
1349
+ if (opts.nonegate !== true && state.index === 0) {
1350
+ negate();
1351
+ continue;
1352
+ }
1353
+ }
1354
+ if (value === "+") {
1355
+ if (opts.noextglob !== true && peek() === "(" && peek(2) !== "?") {
1356
+ extglobOpen("plus", value);
1357
+ continue;
1358
+ }
1359
+ if (prev && prev.value === "(" || opts.regex === false) {
1360
+ push({ type: "plus", value, output: PLUS_LITERAL });
1361
+ continue;
1362
+ }
1363
+ if (prev && (prev.type === "bracket" || prev.type === "paren" || prev.type === "brace") || state.parens > 0) {
1364
+ push({ type: "plus", value });
1365
+ continue;
1366
+ }
1367
+ push({ type: "plus", value: PLUS_LITERAL });
1368
+ continue;
1369
+ }
1370
+ if (value === "@") {
1371
+ if (opts.noextglob !== true && peek() === "(" && peek(2) !== "?") {
1372
+ push({ type: "at", extglob: true, value, output: "" });
1373
+ continue;
1374
+ }
1375
+ push({ type: "text", value });
1376
+ continue;
1377
+ }
1378
+ if (value !== "*") {
1379
+ if (value === "$" || value === "^") {
1380
+ value = `\\${value}`;
1381
+ }
1382
+ const match = REGEX_NON_SPECIAL_CHARS.exec(remaining());
1383
+ if (match) {
1384
+ value += match[0];
1385
+ state.index += match[0].length;
1386
+ }
1387
+ push({ type: "text", value });
1388
+ continue;
1389
+ }
1390
+ if (prev && (prev.type === "globstar" || prev.star === true)) {
1391
+ prev.type = "star";
1392
+ prev.star = true;
1393
+ prev.value += value;
1394
+ prev.output = star;
1395
+ state.backtrack = true;
1396
+ state.globstar = true;
1397
+ consume(value);
1398
+ continue;
1399
+ }
1400
+ let rest = remaining();
1401
+ if (opts.noextglob !== true && /^\([^?]/.test(rest)) {
1402
+ extglobOpen("star", value);
1403
+ continue;
1404
+ }
1405
+ if (prev.type === "star") {
1406
+ if (opts.noglobstar === true) {
1407
+ consume(value);
1408
+ continue;
1409
+ }
1410
+ const prior = prev.prev;
1411
+ const before = prior.prev;
1412
+ const isStart = prior.type === "slash" || prior.type === "bos";
1413
+ const afterStar = before && (before.type === "star" || before.type === "globstar");
1414
+ if (opts.bash === true && (!isStart || rest[0] && rest[0] !== "/")) {
1415
+ push({ type: "star", value, output: "" });
1416
+ continue;
1417
+ }
1418
+ const isBrace = state.braces > 0 && (prior.type === "comma" || prior.type === "brace");
1419
+ const isExtglob = extglobs.length && (prior.type === "pipe" || prior.type === "paren");
1420
+ if (!isStart && prior.type !== "paren" && !isBrace && !isExtglob) {
1421
+ push({ type: "star", value, output: "" });
1422
+ continue;
1423
+ }
1424
+ while (rest.slice(0, 3) === "/**") {
1425
+ const after = input[state.index + 4];
1426
+ if (after && after !== "/") {
1427
+ break;
1428
+ }
1429
+ rest = rest.slice(3);
1430
+ consume("/**", 3);
1431
+ }
1432
+ if (prior.type === "bos" && eos()) {
1433
+ prev.type = "globstar";
1434
+ prev.value += value;
1435
+ prev.output = globstar(opts);
1436
+ state.output = prev.output;
1437
+ state.globstar = true;
1438
+ consume(value);
1439
+ continue;
1440
+ }
1441
+ if (prior.type === "slash" && prior.prev.type !== "bos" && !afterStar && eos()) {
1442
+ state.output = state.output.slice(0, -(prior.output + prev.output).length);
1443
+ prior.output = `(?:${prior.output}`;
1444
+ prev.type = "globstar";
1445
+ prev.output = globstar(opts) + (opts.strictSlashes ? ")" : "|$)");
1446
+ prev.value += value;
1447
+ state.globstar = true;
1448
+ state.output += prior.output + prev.output;
1449
+ consume(value);
1450
+ continue;
1451
+ }
1452
+ if (prior.type === "slash" && prior.prev.type !== "bos" && rest[0] === "/") {
1453
+ const end = rest[1] !== void 0 ? "|$" : "";
1454
+ state.output = state.output.slice(0, -(prior.output + prev.output).length);
1455
+ prior.output = `(?:${prior.output}`;
1456
+ prev.type = "globstar";
1457
+ prev.output = `${globstar(opts)}${SLASH_LITERAL}|${SLASH_LITERAL}${end})`;
1458
+ prev.value += value;
1459
+ state.output += prior.output + prev.output;
1460
+ state.globstar = true;
1461
+ consume(value + advance());
1462
+ push({ type: "slash", value: "/", output: "" });
1463
+ continue;
1464
+ }
1465
+ if (prior.type === "bos" && rest[0] === "/") {
1466
+ prev.type = "globstar";
1467
+ prev.value += value;
1468
+ prev.output = `(?:^|${SLASH_LITERAL}|${globstar(opts)}${SLASH_LITERAL})`;
1469
+ state.output = prev.output;
1470
+ state.globstar = true;
1471
+ consume(value + advance());
1472
+ push({ type: "slash", value: "/", output: "" });
1473
+ continue;
1474
+ }
1475
+ state.output = state.output.slice(0, -prev.output.length);
1476
+ prev.type = "globstar";
1477
+ prev.output = globstar(opts);
1478
+ prev.value += value;
1479
+ state.output += prev.output;
1480
+ state.globstar = true;
1481
+ consume(value);
1482
+ continue;
1483
+ }
1484
+ const token = { type: "star", value, output: star };
1485
+ if (opts.bash === true) {
1486
+ token.output = ".*?";
1487
+ if (prev.type === "bos" || prev.type === "slash") {
1488
+ token.output = nodot + token.output;
1489
+ }
1490
+ push(token);
1491
+ continue;
1492
+ }
1493
+ if (prev && (prev.type === "bracket" || prev.type === "paren") && opts.regex === true) {
1494
+ token.output = value;
1495
+ push(token);
1496
+ continue;
1497
+ }
1498
+ if (state.index === state.start || prev.type === "slash" || prev.type === "dot") {
1499
+ if (prev.type === "dot") {
1500
+ state.output += NO_DOT_SLASH;
1501
+ prev.output += NO_DOT_SLASH;
1502
+ } else if (opts.dot === true) {
1503
+ state.output += NO_DOTS_SLASH;
1504
+ prev.output += NO_DOTS_SLASH;
1505
+ } else {
1506
+ state.output += nodot;
1507
+ prev.output += nodot;
1508
+ }
1509
+ if (peek() !== "*") {
1510
+ state.output += ONE_CHAR;
1511
+ prev.output += ONE_CHAR;
1512
+ }
1513
+ }
1514
+ push(token);
1515
+ }
1516
+ while (state.brackets > 0) {
1517
+ if (opts.strictBrackets === true) throw new SyntaxError(syntaxError("closing", "]"));
1518
+ state.output = utils.escapeLast(state.output, "[");
1519
+ decrement("brackets");
1520
+ }
1521
+ while (state.parens > 0) {
1522
+ if (opts.strictBrackets === true) throw new SyntaxError(syntaxError("closing", ")"));
1523
+ state.output = utils.escapeLast(state.output, "(");
1524
+ decrement("parens");
1525
+ }
1526
+ while (state.braces > 0) {
1527
+ if (opts.strictBrackets === true) throw new SyntaxError(syntaxError("closing", "}"));
1528
+ state.output = utils.escapeLast(state.output, "{");
1529
+ decrement("braces");
1530
+ }
1531
+ if (opts.strictSlashes !== true && (prev.type === "star" || prev.type === "bracket")) {
1532
+ push({ type: "maybe_slash", value: "", output: `${SLASH_LITERAL}?` });
1533
+ }
1534
+ if (state.backtrack === true) {
1535
+ state.output = "";
1536
+ for (const token of state.tokens) {
1537
+ state.output += token.output != null ? token.output : token.value;
1538
+ if (token.suffix) {
1539
+ state.output += token.suffix;
1540
+ }
1541
+ }
1542
+ }
1543
+ return state;
1544
+ };
1545
+ parse.fastpaths = (input, options) => {
1546
+ const opts = { ...options };
1547
+ const max = typeof opts.maxLength === "number" ? Math.min(MAX_LENGTH, opts.maxLength) : MAX_LENGTH;
1548
+ const len = input.length;
1549
+ if (len > max) {
1550
+ throw new SyntaxError(`Input length: ${len}, exceeds maximum allowed length: ${max}`);
1551
+ }
1552
+ input = REPLACEMENTS[input] || input;
1553
+ const {
1554
+ DOT_LITERAL,
1555
+ SLASH_LITERAL,
1556
+ ONE_CHAR,
1557
+ DOTS_SLASH,
1558
+ NO_DOT,
1559
+ NO_DOTS,
1560
+ NO_DOTS_SLASH,
1561
+ STAR,
1562
+ START_ANCHOR
1563
+ } = constants.globChars(opts.windows);
1564
+ const nodot = opts.dot ? NO_DOTS : NO_DOT;
1565
+ const slashDot = opts.dot ? NO_DOTS_SLASH : NO_DOT;
1566
+ const capture = opts.capture ? "" : "?:";
1567
+ const state = { negated: false, prefix: "" };
1568
+ let star = opts.bash === true ? ".*?" : STAR;
1569
+ if (opts.capture) {
1570
+ star = `(${star})`;
1571
+ }
1572
+ const globstar = (opts2) => {
1573
+ if (opts2.noglobstar === true) return star;
1574
+ return `(${capture}(?:(?!${START_ANCHOR}${opts2.dot ? DOTS_SLASH : DOT_LITERAL}).)*?)`;
1575
+ };
1576
+ const create = (str) => {
1577
+ switch (str) {
1578
+ case "*":
1579
+ return `${nodot}${ONE_CHAR}${star}`;
1580
+ case ".*":
1581
+ return `${DOT_LITERAL}${ONE_CHAR}${star}`;
1582
+ case "*.*":
1583
+ return `${nodot}${star}${DOT_LITERAL}${ONE_CHAR}${star}`;
1584
+ case "*/*":
1585
+ return `${nodot}${star}${SLASH_LITERAL}${ONE_CHAR}${slashDot}${star}`;
1586
+ case "**":
1587
+ return nodot + globstar(opts);
1588
+ case "**/*":
1589
+ return `(?:${nodot}${globstar(opts)}${SLASH_LITERAL})?${slashDot}${ONE_CHAR}${star}`;
1590
+ case "**/*.*":
1591
+ return `(?:${nodot}${globstar(opts)}${SLASH_LITERAL})?${slashDot}${star}${DOT_LITERAL}${ONE_CHAR}${star}`;
1592
+ case "**/.*":
1593
+ return `(?:${nodot}${globstar(opts)}${SLASH_LITERAL})?${DOT_LITERAL}${ONE_CHAR}${star}`;
1594
+ default: {
1595
+ const match = /^(.*?)\.(\w+)$/.exec(str);
1596
+ if (!match) return;
1597
+ const source2 = create(match[1]);
1598
+ if (!source2) return;
1599
+ return source2 + DOT_LITERAL + match[2];
1600
+ }
1601
+ }
1602
+ };
1603
+ const output = utils.removePrefix(input, state);
1604
+ let source = create(output);
1605
+ if (source && opts.strictSlashes !== true) {
1606
+ source += `${SLASH_LITERAL}?`;
1607
+ }
1608
+ return source;
1609
+ };
1610
+ module.exports = parse;
1611
+ }
1612
+ });
1613
+
1614
+ // ../../node_modules/.pnpm/picomatch@4.0.4/node_modules/picomatch/lib/picomatch.js
1615
+ var require_picomatch = __commonJS({
1616
+ "../../node_modules/.pnpm/picomatch@4.0.4/node_modules/picomatch/lib/picomatch.js"(exports, module) {
1617
+ "use strict";
1618
+ var scan = require_scan();
1619
+ var parse = require_parse();
1620
+ var utils = require_utils();
1621
+ var constants = require_constants();
1622
+ var isObject = (val) => val && typeof val === "object" && !Array.isArray(val);
1623
+ var picomatch2 = (glob, options, returnState = false) => {
1624
+ if (Array.isArray(glob)) {
1625
+ const fns = glob.map((input) => picomatch2(input, options, returnState));
1626
+ const arrayMatcher = (str) => {
1627
+ for (const isMatch of fns) {
1628
+ const state2 = isMatch(str);
1629
+ if (state2) return state2;
1630
+ }
1631
+ return false;
1632
+ };
1633
+ return arrayMatcher;
1634
+ }
1635
+ const isState = isObject(glob) && glob.tokens && glob.input;
1636
+ if (glob === "" || typeof glob !== "string" && !isState) {
1637
+ throw new TypeError("Expected pattern to be a non-empty string");
1638
+ }
1639
+ const opts = options || {};
1640
+ const posix = opts.windows;
1641
+ const regex = isState ? picomatch2.compileRe(glob, options) : picomatch2.makeRe(glob, options, false, true);
1642
+ const state = regex.state;
1643
+ delete regex.state;
1644
+ let isIgnored = () => false;
1645
+ if (opts.ignore) {
1646
+ const ignoreOpts = { ...options, ignore: null, onMatch: null, onResult: null };
1647
+ isIgnored = picomatch2(opts.ignore, ignoreOpts, returnState);
1648
+ }
1649
+ const matcher = (input, returnObject = false) => {
1650
+ const { isMatch, match, output } = picomatch2.test(input, regex, options, { glob, posix });
1651
+ const result = { glob, state, regex, posix, input, output, match, isMatch };
1652
+ if (typeof opts.onResult === "function") {
1653
+ opts.onResult(result);
1654
+ }
1655
+ if (isMatch === false) {
1656
+ result.isMatch = false;
1657
+ return returnObject ? result : false;
1658
+ }
1659
+ if (isIgnored(input)) {
1660
+ if (typeof opts.onIgnore === "function") {
1661
+ opts.onIgnore(result);
1662
+ }
1663
+ result.isMatch = false;
1664
+ return returnObject ? result : false;
1665
+ }
1666
+ if (typeof opts.onMatch === "function") {
1667
+ opts.onMatch(result);
1668
+ }
1669
+ return returnObject ? result : true;
1670
+ };
1671
+ if (returnState) {
1672
+ matcher.state = state;
1673
+ }
1674
+ return matcher;
1675
+ };
1676
+ picomatch2.test = (input, regex, options, { glob, posix } = {}) => {
1677
+ if (typeof input !== "string") {
1678
+ throw new TypeError("Expected input to be a string");
1679
+ }
1680
+ if (input === "") {
1681
+ return { isMatch: false, output: "" };
1682
+ }
1683
+ const opts = options || {};
1684
+ const format = opts.format || (posix ? utils.toPosixSlashes : null);
1685
+ let match = input === glob;
1686
+ let output = match && format ? format(input) : input;
1687
+ if (match === false) {
1688
+ output = format ? format(input) : input;
1689
+ match = output === glob;
1690
+ }
1691
+ if (match === false || opts.capture === true) {
1692
+ if (opts.matchBase === true || opts.basename === true) {
1693
+ match = picomatch2.matchBase(input, regex, options, posix);
1694
+ } else {
1695
+ match = regex.exec(output);
1696
+ }
1697
+ }
1698
+ return { isMatch: Boolean(match), match, output };
1699
+ };
1700
+ picomatch2.matchBase = (input, glob, options) => {
1701
+ const regex = glob instanceof RegExp ? glob : picomatch2.makeRe(glob, options);
1702
+ return regex.test(utils.basename(input));
1703
+ };
1704
+ picomatch2.isMatch = (str, patterns, options) => picomatch2(patterns, options)(str);
1705
+ picomatch2.parse = (pattern, options) => {
1706
+ if (Array.isArray(pattern)) return pattern.map((p) => picomatch2.parse(p, options));
1707
+ return parse(pattern, { ...options, fastpaths: false });
1708
+ };
1709
+ picomatch2.scan = (input, options) => scan(input, options);
1710
+ picomatch2.compileRe = (state, options, returnOutput = false, returnState = false) => {
1711
+ if (returnOutput === true) {
1712
+ return state.output;
1713
+ }
1714
+ const opts = options || {};
1715
+ const prepend = opts.contains ? "" : "^";
1716
+ const append = opts.contains ? "" : "$";
1717
+ let source = `${prepend}(?:${state.output})${append}`;
1718
+ if (state && state.negated === true) {
1719
+ source = `^(?!${source}).*$`;
1720
+ }
1721
+ const regex = picomatch2.toRegex(source, options);
1722
+ if (returnState === true) {
1723
+ regex.state = state;
1724
+ }
1725
+ return regex;
1726
+ };
1727
+ picomatch2.makeRe = (input, options = {}, returnOutput = false, returnState = false) => {
1728
+ if (!input || typeof input !== "string") {
1729
+ throw new TypeError("Expected a non-empty string");
1730
+ }
1731
+ let parsed = { negated: false, fastpaths: true };
1732
+ if (options.fastpaths !== false && (input[0] === "." || input[0] === "*")) {
1733
+ parsed.output = parse.fastpaths(input, options);
1734
+ }
1735
+ if (!parsed.output) {
1736
+ parsed = parse(input, options);
1737
+ }
1738
+ return picomatch2.compileRe(parsed, options, returnOutput, returnState);
1739
+ };
1740
+ picomatch2.toRegex = (source, options) => {
1741
+ try {
1742
+ const opts = options || {};
1743
+ return new RegExp(source, opts.flags || (opts.nocase ? "i" : ""));
1744
+ } catch (err) {
1745
+ if (options && options.debug === true) throw err;
1746
+ return /$^/;
1747
+ }
1748
+ };
1749
+ picomatch2.constants = constants;
1750
+ module.exports = picomatch2;
1751
+ }
1752
+ });
1753
+
1754
+ // ../../node_modules/.pnpm/picomatch@4.0.4/node_modules/picomatch/index.js
1755
+ var require_picomatch2 = __commonJS({
1756
+ "../../node_modules/.pnpm/picomatch@4.0.4/node_modules/picomatch/index.js"(exports, module) {
1757
+ "use strict";
1758
+ var pico = require_picomatch();
1759
+ var utils = require_utils();
1760
+ function picomatch2(glob, options, returnState = false) {
1761
+ if (options && (options.windows === null || options.windows === void 0)) {
1762
+ options = { ...options, windows: utils.isWindows() };
1763
+ }
1764
+ return pico(glob, options, returnState);
1765
+ }
1766
+ Object.assign(picomatch2, pico);
1767
+ module.exports = picomatch2;
1768
+ }
1769
+ });
1770
+
1771
+ // src/index.ts
1772
+ import { createHash as createHash2 } from "crypto";
1773
+ import { dirname, resolve as resolve2 } from "path";
1774
+ import { fileURLToPath } from "url";
1775
+ import { defineProject, defineWorkspace } from "vitest/config";
1776
+
1777
+ // src/misuse-detector.ts
1778
+ import { existsSync, mkdirSync, rmSync, writeFileSync } from "fs";
1779
+ import { tmpdir } from "os";
1780
+ import { join } from "path";
1781
+ function parseSelectedProjectNames(argv) {
1782
+ const selected = /* @__PURE__ */ new Set();
1783
+ for (let index = 0; index < argv.length; index += 1) {
1784
+ const arg = argv[index];
1785
+ if (!arg) {
1786
+ continue;
1787
+ }
1788
+ if (arg === "--project" || arg === "-p") {
1789
+ const next = argv[index + 1];
1790
+ if (!next || next.startsWith("-")) {
1791
+ continue;
1792
+ }
1793
+ selected.add(next);
1794
+ index += 1;
1795
+ continue;
1796
+ }
1797
+ if (arg.startsWith("--project=")) {
1798
+ const value = arg.slice("--project=".length);
1799
+ if (value.length > 0) {
1800
+ selected.add(value);
1801
+ }
1802
+ continue;
1803
+ }
1804
+ if (arg.startsWith("-p=")) {
1805
+ const value = arg.slice("-p=".length);
1806
+ if (value.length > 0) {
1807
+ selected.add(value);
1808
+ }
1809
+ }
1810
+ }
1811
+ return selected;
1812
+ }
1813
+ function shouldInstallMisuseDetector(projectName, argv = process.argv) {
1814
+ const selectedProjects = parseSelectedProjectNames(argv);
1815
+ if (selectedProjects.size === 0) {
1816
+ return true;
1817
+ }
1818
+ return selectedProjects.has(projectName);
1819
+ }
1820
+ var WIRING_MARKER_DIR = join(tmpdir(), "archal-vitest-wiring");
1821
+ var wiringMarkers = /* @__PURE__ */ new Set();
1822
+ var wiringCheckInstalled = false;
1823
+ var REPORTER_MARKER_DIR = join(tmpdir(), "archal-vitest-reporter-lifecycle");
1824
+ var reporterMarkers = /* @__PURE__ */ new Set();
1825
+ var reporterCheckInstalled = false;
1826
+ var WORKSPACE_REPORTER_MARKER_DIR = join(tmpdir(), "archal-vitest-workspace-reporter");
1827
+ var workspaceReporterMarkers = /* @__PURE__ */ new Set();
1828
+ var workspaceReporterCheckInstalled = false;
1829
+ var reporterMarkerSeq = 0;
1830
+ var workspaceReporterMarkerSeq = 0;
1831
+ function installMisuseDetector(projectName) {
1832
+ if (!shouldInstallMisuseDetector(projectName)) {
1833
+ return "";
1834
+ }
1835
+ if (!existsSync(WIRING_MARKER_DIR)) {
1836
+ try {
1837
+ mkdirSync(WIRING_MARKER_DIR, { recursive: true, mode: 448 });
1838
+ } catch {
1839
+ }
1840
+ }
1841
+ const markerPath = join(
1842
+ WIRING_MARKER_DIR,
1843
+ `${process.pid}-${projectName}-${Date.now()}.marker`
1844
+ );
1845
+ try {
1846
+ writeFileSync(markerPath, projectName, { mode: 384 });
1847
+ } catch {
1848
+ }
1849
+ wiringMarkers.add(markerPath);
1850
+ if (!wiringCheckInstalled) {
1851
+ wiringCheckInstalled = true;
1852
+ const warnIfUnwired = () => {
1853
+ const survivors = [...wiringMarkers].filter((path) => existsSync(path));
1854
+ if (survivors.length === 0) {
1855
+ return;
1856
+ }
1857
+ process.stderr.write(
1858
+ "\n\x1B[33m\x1B[1m\u2500\u2500\u2500 Archal Vitest: route-mode was not installed \u2500\u2500\u2500\n\x1B[0m\x1B[33mYour vitest config called archalVitestProject() but vitest didn't\nwire its setup files. Requests to hosted twin services probably\nleaked to real SaaS APIs.\n\nFix: either use withArchal() for a single vitest.config.ts:\n\n import { defineConfig } from 'vitest/config';\n import { withArchal } from 'archal/vitest';\n export default defineConfig({\n test: withArchal({}, { services: { ... } }),\n });\n\nOr move archalVitestProject() into vitest.workspace.ts:\n\n import { archalVitestProject } from 'archal/vitest';\n export default [archalVitestProject({ services: { ... } })];\n\x1B[0m\n"
1859
+ );
1860
+ for (const survivor of survivors) {
1861
+ try {
1862
+ rmSync(survivor);
1863
+ } catch {
1864
+ }
1865
+ }
1866
+ };
1867
+ process.on("beforeExit", warnIfUnwired);
1868
+ process.on("SIGINT", () => {
1869
+ warnIfUnwired();
1870
+ setImmediate(() => process.exit(130));
1871
+ });
1872
+ process.on("SIGTERM", () => {
1873
+ warnIfUnwired();
1874
+ setImmediate(() => process.exit(143));
1875
+ });
1876
+ }
1877
+ return markerPath;
1878
+ }
1879
+ function installReporterLifecycleCheck(projectName) {
1880
+ if (!existsSync(REPORTER_MARKER_DIR)) {
1881
+ try {
1882
+ mkdirSync(REPORTER_MARKER_DIR, { recursive: true, mode: 448 });
1883
+ } catch {
1884
+ }
1885
+ }
1886
+ reporterMarkerSeq += 1;
1887
+ const markerPath = join(
1888
+ REPORTER_MARKER_DIR,
1889
+ `${process.pid}-${projectName}-${Date.now()}-${reporterMarkerSeq}.marker`
1890
+ );
1891
+ try {
1892
+ writeFileSync(markerPath, projectName, { mode: 384 });
1893
+ } catch {
1894
+ }
1895
+ reporterMarkers.add(markerPath);
1896
+ if (!reporterCheckInstalled) {
1897
+ reporterCheckInstalled = true;
1898
+ const warnIfReporterNeverFired = () => {
1899
+ const survivors = [...reporterMarkers].filter((path) => existsSync(path));
1900
+ if (survivors.length === 0) {
1901
+ return;
1902
+ }
1903
+ process.stderr.write(
1904
+ '\n\x1B[33m\x1B[1m\u2500\u2500\u2500 Archal Vitest: reporter end-of-run hook never fired \u2500\u2500\u2500\n\x1B[0m\x1B[33mArchalReporter.onInit ran, but its end-of-run hook (onFinished / onTestRunEnd) never fired, so dashboard upload was\nsilently skipped. Test results will NOT appear on /dashboard/tests.\n\nCommon causes:\n - A Vitest upgrade changed per-project reporter lifecycle timing.\n - A consumer config filtered out reporters (look for reporter overrides).\n - The ArchalReporter threw before reaching collectAndReport.\n\nWhat to check:\n 1. Grep stderr for "[archal/reporter]" \u2014 if any line appears, the\n reporter did run and this warning is a false positive.\n 2. If no [archal/reporter] lines exist at all, the reporter was\n installed but never called. Verify your vitest config wires it\n at the level Vitest actually honors (workspace root vs project).\n'
1905
+ );
1906
+ process.stderr.write("\x1B[0m\n");
1907
+ for (const survivor of survivors) {
1908
+ try {
1909
+ rmSync(survivor);
1910
+ } catch {
1911
+ }
1912
+ }
1913
+ };
1914
+ process.on("beforeExit", warnIfReporterNeverFired);
1915
+ process.on("SIGINT", () => {
1916
+ warnIfReporterNeverFired();
1917
+ setImmediate(() => process.exit(130));
1918
+ });
1919
+ process.on("SIGTERM", () => {
1920
+ warnIfReporterNeverFired();
1921
+ setImmediate(() => process.exit(143));
1922
+ });
1923
+ }
1924
+ return markerPath;
1925
+ }
1926
+ function installWorkspaceReporterCheck(projectNames) {
1927
+ if (!existsSync(WORKSPACE_REPORTER_MARKER_DIR)) {
1928
+ try {
1929
+ mkdirSync(WORKSPACE_REPORTER_MARKER_DIR, { recursive: true, mode: 448 });
1930
+ } catch {
1931
+ }
1932
+ }
1933
+ workspaceReporterMarkerSeq += 1;
1934
+ const normalizedNames = projectNames.length > 0 ? [...projectNames].sort().join(",") : "archal";
1935
+ const markerPath = join(
1936
+ WORKSPACE_REPORTER_MARKER_DIR,
1937
+ `${process.pid}-${Date.now()}-${workspaceReporterMarkerSeq}.marker`
1938
+ );
1939
+ try {
1940
+ writeFileSync(markerPath, normalizedNames, { mode: 384 });
1941
+ } catch {
1942
+ }
1943
+ workspaceReporterMarkers.add(markerPath);
1944
+ if (!workspaceReporterCheckInstalled) {
1945
+ workspaceReporterCheckInstalled = true;
1946
+ const warnIfWorkspaceReporterMissing = () => {
1947
+ const survivors = [...workspaceReporterMarkers].filter((path) => existsSync(path));
1948
+ if (survivors.length === 0) {
1949
+ return;
1950
+ }
1951
+ process.stderr.write(
1952
+ "\n\x1B[33m\x1B[1m\u2500\u2500\u2500 Archal Vitest: workspace projects ran without the dashboard reporter \u2500\u2500\u2500\n\x1B[0m\x1B[33marchalVitestWorkspace() configured hosted route-mode projects, but no\nroot-level Archal reporter was registered. Requests were routed to the\nhosted twins, yet /dashboard/tests upload was skipped.\n\nFix: add a root vitest.config.ts alongside vitest.workspace.ts:\n\n import { defineConfig } from 'vitest/config';\n import { archalVitestRootConfig } from 'archal/vitest';\n\n export default defineConfig(archalVitestRootConfig());\n\nIf you do not need workspace mode, use withArchal() instead.\n\x1B[0m\n"
1953
+ );
1954
+ for (const survivor of survivors) {
1955
+ try {
1956
+ rmSync(survivor);
1957
+ } catch {
1958
+ }
1959
+ }
1960
+ };
1961
+ process.on("beforeExit", warnIfWorkspaceReporterMissing);
1962
+ process.on("SIGINT", () => {
1963
+ warnIfWorkspaceReporterMissing();
1964
+ setImmediate(() => process.exit(130));
1965
+ });
1966
+ process.on("SIGTERM", () => {
1967
+ warnIfWorkspaceReporterMissing();
1968
+ setImmediate(() => process.exit(143));
1969
+ });
1970
+ }
1971
+ return markerPath;
1972
+ }
1973
+ function markReporterFired(markerPath) {
1974
+ if (!markerPath) return;
1975
+ reporterMarkers.delete(markerPath);
1976
+ try {
1977
+ rmSync(markerPath);
1978
+ } catch {
1979
+ }
1980
+ }
1981
+ function markWorkspaceReporterInstalled(markerPath) {
1982
+ if (!markerPath) return;
1983
+ workspaceReporterMarkers.delete(markerPath);
1984
+ try {
1985
+ rmSync(markerPath);
1986
+ } catch {
1987
+ }
1988
+ }
1989
+
1990
+ // src/reporter.ts
1991
+ var import_picomatch = __toESM(require_picomatch2(), 1);
1992
+ var LOG_PREFIX = "[archal/reporter]";
1993
+ var STRICT_ENV = "ARCHAL_REPORTER_STRICT";
1994
+ var REPORTER_TOKEN_ENV = "ARCHAL_REPORTER_TOKEN";
1995
+ var REPORTER_AUTH_URL_ENV = "ARCHAL_REPORTER_AUTH_URL";
1996
+ var REPORTER_AUTH_BASE_URL_ENV = "ARCHAL_REPORTER_AUTH_BASE_URL";
1997
+ var REPORTER_BYPASS_SECRET_ENV = "ARCHAL_REPORTER_VERCEL_AUTOMATION_BYPASS_SECRET";
1998
+ var WORKSPACE_REPORTER_MARKER_ENV = "ARCHAL_VITEST_WORKSPACE_REPORTER_MARKER";
1999
+ function isStrict() {
2000
+ return process.env[STRICT_ENV] === "1";
2001
+ }
2002
+ function warn(message) {
2003
+ const line = `${LOG_PREFIX} ${message}
2004
+ `;
2005
+ if (isStrict()) {
2006
+ throw new Error(line.trimEnd());
2007
+ }
2008
+ process.stderr.write(line);
2009
+ }
2010
+ function info(message) {
2011
+ process.stderr.write(`${LOG_PREFIX} ${message}
2012
+ `);
2013
+ }
2014
+ async function resolveReporterToken() {
2015
+ const explicitReporterToken = process.env[REPORTER_TOKEN_ENV]?.trim();
2016
+ if (explicitReporterToken) {
2017
+ return explicitReporterToken;
2018
+ }
2019
+ try {
2020
+ const { getCredentials } = await import("./src-JGHX6UKK.js");
2021
+ const creds = getCredentials();
2022
+ return creds?.token ?? process.env["ARCHAL_TOKEN"]?.trim();
2023
+ } catch (authErr) {
2024
+ warn(`auth resolution failed: ${authErr instanceof Error ? authErr.message : String(authErr)}`);
2025
+ return void 0;
2026
+ }
2027
+ }
2028
+ function resolveReporterBaseUrl() {
2029
+ return (process.env[REPORTER_AUTH_URL_ENV]?.trim() || process.env[REPORTER_AUTH_BASE_URL_ENV]?.trim() || process.env["ARCHAL_AUTH_URL"]?.trim() || process.env["ARCHAL_AUTH_BASE_URL"]?.trim() || "https://www.archal.ai").replace(/\/+$/, "");
2030
+ }
2031
+ function buildReporterHeaders(token) {
2032
+ const headers = new Headers({
2033
+ "content-type": "application/json",
2034
+ authorization: `Bearer ${token}`
2035
+ });
2036
+ const bypassSecret = process.env[REPORTER_BYPASS_SECRET_ENV]?.trim();
2037
+ if (bypassSecret) {
2038
+ headers.set("x-vercel-protection-bypass", bypassSecret);
2039
+ }
2040
+ return headers;
2041
+ }
2042
+ function normalizePathForMatch(path) {
2043
+ return path.replaceAll("\\", "/");
2044
+ }
2045
+ function buildIncludeMatcher(pattern) {
2046
+ const normalizedPattern = normalizePathForMatch(pattern).replace(/^\.?\//, "");
2047
+ const patterns = normalizedPattern.startsWith("**/") ? [normalizedPattern] : [normalizedPattern, `**/${normalizedPattern}`];
2048
+ const matchers = patterns.map((candidate) => (0, import_picomatch.default)(candidate, { dot: true }));
2049
+ return (filePath) => {
2050
+ const normalizedFile = normalizePathForMatch(filePath);
2051
+ return matchers.some((matcher) => matcher(normalizedFile));
2052
+ };
2053
+ }
2054
+ function readEncodedConfigFromTarget(target) {
2055
+ const env = target?.config?.env;
2056
+ return env?.[ARCHAL_VITEST_CONFIG_ENV];
2057
+ }
2058
+ function readProjectIncludePatterns(project) {
2059
+ const config = project?.config;
2060
+ const include = Array.isArray(config?.include) ? config.include : Array.isArray(config?.test?.include) ? config.test.include : [];
2061
+ return include.filter((pattern) => typeof pattern === "string" && pattern.length > 0);
2062
+ }
2063
+ var ArchalReporter = class {
2064
+ startTime = 0;
2065
+ ctx = null;
2066
+ lifecycleMarkerPath = "";
2067
+ workspaceReporterMarkerPath = "";
2068
+ projects = [];
2069
+ onInit(ctx) {
2070
+ this.startTime = Date.now();
2071
+ this.ctx = ctx;
2072
+ this.projects = this.resolveProjects();
2073
+ const projectName = this.projects[0]?.config.projectName ?? "vitest";
2074
+ this.lifecycleMarkerPath = installReporterLifecycleCheck(projectName);
2075
+ this.workspaceReporterMarkerPath = process.env[WORKSPACE_REPORTER_MARKER_ENV] ?? "";
2076
+ markWorkspaceReporterInstalled(this.workspaceReporterMarkerPath);
2077
+ this.workspaceReporterMarkerPath = "";
2078
+ }
2079
+ decodeConfig(encoded) {
2080
+ try {
2081
+ return readArchalVitestConfig(encoded);
2082
+ } catch {
2083
+ return null;
2084
+ }
2085
+ }
2086
+ buildProjectContext(config, includePatterns) {
2087
+ return {
2088
+ config,
2089
+ includePatterns,
2090
+ includeMatchers: includePatterns.map(buildIncludeMatcher)
2091
+ };
2092
+ }
2093
+ resolveProjects() {
2094
+ const resolvedProjects = (this.ctx?.projects ?? []).map((project) => {
2095
+ const config = this.decodeConfig(readEncodedConfigFromTarget(project));
2096
+ return config ? this.buildProjectContext(config, readProjectIncludePatterns(project)) : null;
2097
+ }).filter((project) => project !== null);
2098
+ if (resolvedProjects.length > 0) {
2099
+ return resolvedProjects;
2100
+ }
2101
+ const rootConfig = this.decodeConfig(
2102
+ readEncodedConfigFromTarget(this.ctx) ?? process.env[ARCHAL_VITEST_CONFIG_ENV]
2103
+ );
2104
+ return rootConfig ? [this.buildProjectContext(rootConfig, [])] : [];
2105
+ }
2106
+ /**
2107
+ * vitest v2 calls onFinished with an array of File objects (from @vitest/runner).
2108
+ * Each File extends Suite which has `tasks: Task[]`, and each Task has
2109
+ * `.type` ('test' | 'suite'), `.name`, `.result?.state`, `.result?.duration`.
2110
+ */
2111
+ async onFinished(files, _errors) {
2112
+ await this.collectAndReport(files ?? [], "v2");
2113
+ }
2114
+ /**
2115
+ * vitest v4 calls onTestRunEnd (not onFinished) for custom reporters.
2116
+ * The argument is an array of test modules, each with nested children.
2117
+ */
2118
+ async onTestRunEnd(testModules) {
2119
+ await this.collectAndReport(testModules ?? [], "v4");
2120
+ }
2121
+ async collectAndReport(items, version) {
2122
+ markReporterFired(this.lifecycleMarkerPath);
2123
+ this.lifecycleMarkerPath = "";
2124
+ if (this.projects.length === 0) {
2125
+ this.projects = this.resolveProjects();
2126
+ }
2127
+ if (this.projects.length === 0) {
2128
+ warn(
2129
+ "Archal vitest config could not be decoded from the env \u2014 falling back to default project name. If this persists, make sure withArchal() or archalVitestProject() wraps your test config."
2130
+ );
2131
+ this.projects = [
2132
+ this.buildProjectContext({
2133
+ projectName: "vitest",
2134
+ services: {}
2135
+ }, [])
2136
+ ];
2137
+ }
2138
+ if (items.length === 0) {
2139
+ warn(`no ${version === "v2" ? "files" : "test modules"} received \u2014 nothing to upload.`);
2140
+ return;
2141
+ }
2142
+ const results = version === "v2" ? this.collectV2Files(items) : this.collectV4Modules(items);
2143
+ if (results.length === 0) {
2144
+ warn("collected 0 tests after walking the test tree \u2014 nothing to upload.");
2145
+ return;
2146
+ }
2147
+ const buckets = this.partitionResults(results);
2148
+ if (buckets.length === 0) {
2149
+ warn("collected tests but could not map them to an Archal Vitest project.");
2150
+ return;
2151
+ }
2152
+ try {
2153
+ for (const bucket of buckets) {
2154
+ await this.sendResults(bucket.project, bucket.results);
2155
+ }
2156
+ } catch (err) {
2157
+ warn(
2158
+ `failed to upload test results: ${err instanceof Error ? err.message : String(err)}`
2159
+ );
2160
+ }
2161
+ }
2162
+ /**
2163
+ * vitest v2: File extends Suite { tasks: Task[] }.
2164
+ * Task.type is 'test' | 'suite' | 'custom'. Suite tasks recurse.
2165
+ */
2166
+ collectV2Files(files) {
2167
+ const results = [];
2168
+ const collectTasks = (tasks, fileName) => {
2169
+ for (const task of tasks) {
2170
+ if (task.type === "test" || task.type === "custom") {
2171
+ const state = task.result?.state;
2172
+ results.push({
2173
+ name: task.name ?? "unnamed",
2174
+ file: fileName,
2175
+ status: state === "pass" ? "passed" : state === "fail" ? "failed" : "skipped",
2176
+ duration: task.result?.duration ?? 0,
2177
+ error: state === "fail" && task.result?.errors?.[0] ? task.result.errors[0].message ?? String(task.result.errors[0]) : void 0
2178
+ });
2179
+ } else if (task.type === "suite" && Array.isArray(task.tasks)) {
2180
+ collectTasks(task.tasks, fileName);
2181
+ }
2182
+ }
2183
+ };
2184
+ for (const file of files) {
2185
+ const f = file;
2186
+ const fileName = f.filepath ?? f.name ?? "unknown";
2187
+ if (Array.isArray(f.tasks)) {
2188
+ collectTasks(f.tasks, fileName);
2189
+ }
2190
+ }
2191
+ return results;
2192
+ }
2193
+ /**
2194
+ * vitest v4: TestModule.children() → TestSuite[].children() → TestCase[]
2195
+ * All accessors are methods (not properties) in v4.
2196
+ */
2197
+ collectV4Modules(testModules) {
2198
+ const results = [];
2199
+ const collectTests = (node, fileName) => {
2200
+ const children = typeof node.children === "function" ? node.children() : node.children ?? [];
2201
+ for (const child of children) {
2202
+ if (child.type === "test") {
2203
+ const result = typeof child.result === "function" ? child.result() : child.result;
2204
+ const diag = typeof child.diagnostic === "function" ? child.diagnostic() : child.diagnostic;
2205
+ const state = result?.state;
2206
+ results.push({
2207
+ name: child.name ?? "unnamed",
2208
+ file: fileName,
2209
+ status: state === "passed" ? "passed" : state === "failed" ? "failed" : "skipped",
2210
+ duration: diag?.duration ?? result?.duration ?? 0,
2211
+ error: state === "failed" && result?.errors?.[0] ? result.errors[0].message ?? String(result.errors[0]) : void 0
2212
+ });
2213
+ } else {
2214
+ collectTests(child, fileName);
2215
+ }
2216
+ }
2217
+ };
2218
+ for (const mod of testModules) {
2219
+ const m = mod;
2220
+ const fileName = m.moduleId ?? m.id ?? "unknown";
2221
+ collectTests(m, fileName);
2222
+ }
2223
+ return results;
2224
+ }
2225
+ resolveProjectForFile(fileName) {
2226
+ const normalizedFile = normalizePathForMatch(fileName);
2227
+ const onlyProject = this.projects[0] ?? null;
2228
+ if (this.projects.length === 1) {
2229
+ if (!onlyProject) {
2230
+ return null;
2231
+ }
2232
+ if (onlyProject.includeMatchers.length === 0) {
2233
+ return onlyProject;
2234
+ }
2235
+ return onlyProject.includeMatchers.some((matcher) => matcher(normalizedFile)) ? onlyProject : null;
2236
+ }
2237
+ let bestMatch = null;
2238
+ let bestSpecificity = -1;
2239
+ for (const project of this.projects) {
2240
+ for (const [index, matcher] of project.includeMatchers.entries()) {
2241
+ if (!matcher(normalizedFile)) {
2242
+ continue;
2243
+ }
2244
+ const specificity = project.includePatterns[index]?.length ?? 0;
2245
+ if (specificity > bestSpecificity) {
2246
+ bestMatch = project;
2247
+ bestSpecificity = specificity;
2248
+ }
2249
+ }
2250
+ }
2251
+ return bestMatch;
2252
+ }
2253
+ partitionResults(results) {
2254
+ const buckets = /* @__PURE__ */ new Map();
2255
+ for (const result of results) {
2256
+ const project = this.resolveProjectForFile(result.file);
2257
+ if (!project) {
2258
+ warn(
2259
+ `could not map ${result.file} to a Vitest project config \u2014 skipping reporter upload for that file.`
2260
+ );
2261
+ continue;
2262
+ }
2263
+ const key = project.config.projectName;
2264
+ const bucket = buckets.get(key);
2265
+ if (bucket) {
2266
+ bucket.results.push(result);
2267
+ continue;
2268
+ }
2269
+ buckets.set(key, {
2270
+ project,
2271
+ results: [result]
2272
+ });
2273
+ }
2274
+ return [...buckets.values()];
2275
+ }
2276
+ async sendResults(project, results) {
2277
+ const summary = {
2278
+ total: results.length,
2279
+ passed: results.filter((result) => result.status === "passed").length,
2280
+ failed: results.filter((result) => result.status === "failed").length,
2281
+ skipped: results.filter((result) => result.status === "skipped").length,
2282
+ duration: Date.now() - this.startTime
2283
+ };
2284
+ const token = await resolveReporterToken();
2285
+ if (!token) {
2286
+ warn(
2287
+ `skipped upload (no auth token found). Set ${REPORTER_TOKEN_ENV} or ARCHAL_TOKEN, or run \`archal login\` to populate ~/.archal/credentials.json.`
2288
+ );
2289
+ return;
2290
+ }
2291
+ const baseUrl = resolveReporterBaseUrl();
2292
+ const sessionId = await this.readSessionId(project.config.sessionKey);
2293
+ const payload = {
2294
+ sessionId,
2295
+ projectName: project.config.projectName,
2296
+ services: Object.keys(project.config.services),
2297
+ results,
2298
+ summary,
2299
+ timestamp: (/* @__PURE__ */ new Date()).toISOString()
2300
+ };
2301
+ const res = await fetch(`${baseUrl}/api/test-results`, {
2302
+ method: "POST",
2303
+ headers: buildReporterHeaders(token),
2304
+ body: JSON.stringify(payload)
2305
+ });
2306
+ if (res.ok) {
2307
+ info(
2308
+ `uploaded ${summary.passed}/${summary.total} tests (project=${project.config.projectName}, sessionId=${sessionId ?? "none"})`
2309
+ );
2310
+ if (sessionId) {
2311
+ try {
2312
+ const syncRes = await fetch(`${baseUrl}/api/sessions/sync`, {
2313
+ method: "POST",
2314
+ headers: buildReporterHeaders(token),
2315
+ body: JSON.stringify({
2316
+ sessionId,
2317
+ twinIds: Object.keys(project.config.services),
2318
+ status: summary.failed > 0 ? "failed" : "ended",
2319
+ endedAt: (/* @__PURE__ */ new Date()).toISOString(),
2320
+ runtimeStartedAt: new Date(Date.now() - summary.duration).toISOString(),
2321
+ source: "test",
2322
+ evidence: {
2323
+ reportSummary: {
2324
+ scenarioTitle: project.config.projectName,
2325
+ satisfactionScore: summary.total > 0 ? Math.round(summary.passed / summary.total * 100) : null,
2326
+ runCount: 1
2327
+ }
2328
+ }
2329
+ })
2330
+ });
2331
+ if (!syncRes.ok) {
2332
+ const body = await syncRes.text().catch(() => "");
2333
+ warn(`session sync failed (${syncRes.status}): ${body.slice(0, 200)}`);
2334
+ }
2335
+ } catch (syncErr) {
2336
+ warn(
2337
+ `session sync failed: ${syncErr instanceof Error ? syncErr.message : String(syncErr)}`
2338
+ );
2339
+ }
2340
+ } else {
2341
+ warn(
2342
+ "uploaded test results without a sessionId \u2014 the Activity row will not get scenarioTitle/endedAt/satisfactionScore. Usually this means the bootstrap session-id temp file was missing."
2343
+ );
2344
+ }
2345
+ } else {
2346
+ const body = await res.text().catch(() => "");
2347
+ warn(`upload failed (${res.status}): ${body.slice(0, 200)}`);
2348
+ }
2349
+ }
2350
+ async readSessionId(sessionKey) {
2351
+ const { readFileSync: readFileSync2, readdirSync, statSync } = await import("fs");
2352
+ const { dirname: dirname2, join: join2 } = await import("path");
2353
+ if (sessionKey?.trim()) {
2354
+ try {
2355
+ const keyed = readFileSync2(
2356
+ getSessionIdFilePath(sessionKey),
2357
+ "utf-8"
2358
+ ).trim();
2359
+ if (keyed) return keyed;
2360
+ } catch {
2361
+ }
2362
+ }
2363
+ if (sessionKey?.trim()) {
2364
+ return void 0;
2365
+ }
2366
+ try {
2367
+ const sessionsDir = dirname2(getSessionIdFilePath("any"));
2368
+ const entries = readdirSync(sessionsDir);
2369
+ let newest;
2370
+ for (const name of entries) {
2371
+ if (!name.endsWith(".session-id")) continue;
2372
+ const path = join2(sessionsDir, name);
2373
+ try {
2374
+ const st = statSync(path);
2375
+ if (!newest || st.mtimeMs > newest.mtimeMs) {
2376
+ newest = { path, mtimeMs: st.mtimeMs };
2377
+ }
2378
+ } catch {
2379
+ }
2380
+ }
2381
+ if (newest) {
2382
+ const content = readFileSync2(newest.path, "utf-8").trim();
2383
+ if (content) return content;
2384
+ }
2385
+ } catch {
2386
+ }
2387
+ return void 0;
2388
+ }
2389
+ };
2390
+
2391
+ // src/seed-files.ts
2392
+ import { createHash } from "crypto";
2393
+ import { existsSync as existsSync2, readFileSync } from "fs";
2394
+ import { extname, resolve } from "path";
2395
+ var MAX_SEED_FILE_BYTES = 256 * 1024;
2396
+ function classifySeed(value) {
2397
+ const trimmed = value.trim();
2398
+ if (trimmed.startsWith("./") || trimmed.startsWith("../") || trimmed.startsWith("/")) {
2399
+ const ext = extname(trimmed).toLowerCase();
2400
+ if (ext === ".json") return { type: "file", path: trimmed, format: "json" };
2401
+ if (ext === ".md") return { type: "file", path: trimmed, format: "markdown" };
2402
+ throw new Error(
2403
+ `Seed file must be .json or .md, got "${ext || "(no extension)"}": ${trimmed}
2404
+ .json \u2192 exact twin state loaded directly
2405
+ .md \u2192 plain-English description, Archal generates the state`
2406
+ );
2407
+ }
2408
+ if (trimmed.endsWith(".json") || trimmed.endsWith(".md")) {
2409
+ const ext = extname(trimmed).toLowerCase();
2410
+ const format = ext === ".json" ? "json" : "markdown";
2411
+ return { type: "file", path: trimmed, format };
2412
+ }
2413
+ return { type: "named", name: trimmed };
2414
+ }
2415
+ function readSeedFile(seedPath, serviceName) {
2416
+ const resolved = resolve(seedPath);
2417
+ if (!existsSync2(resolved)) {
2418
+ throw new Error(
2419
+ `Seed file not found for ${serviceName}: ${resolved}
2420
+ Check the path relative to your project root.`
2421
+ );
2422
+ }
2423
+ const content = readFileSync(resolved, "utf-8");
2424
+ if (Buffer.byteLength(content, "utf-8") > MAX_SEED_FILE_BYTES) {
2425
+ throw new Error(
2426
+ `Seed file for ${serviceName} exceeds ${MAX_SEED_FILE_BYTES / 1024}KB limit: ${resolved}`
2427
+ );
2428
+ }
2429
+ return content;
2430
+ }
2431
+ function computeStableSessionKey(projectName, services, fileSeedContents, fileSeedFormats) {
2432
+ const sortedServices = Object.keys(services).sort().map((name) => {
2433
+ const svc = services[name];
2434
+ const fileContent = fileSeedContents?.[name];
2435
+ const format = fileSeedFormats?.[name];
2436
+ return {
2437
+ name,
2438
+ mode: svc?.mode,
2439
+ seed: fileContent ? createHash("sha256").update(fileContent).digest("hex").slice(0, 16) : svc?.seed ?? null,
2440
+ ...format ? { seedFormat: format } : {}
2441
+ };
2442
+ });
2443
+ const payload = JSON.stringify({ projectName, services: sortedServices });
2444
+ return createHash("sha256").update(payload).digest("hex").slice(0, 16);
2445
+ }
2446
+
2447
+ // src/webhooks.ts
2448
+ function normalizeMatcher(matcher, options) {
2449
+ const merged = typeof matcher === "string" ? { eventType: matcher, ...options } : { ...options, ...matcher };
2450
+ return {
2451
+ ...merged,
2452
+ timeout: merged.timeout ?? 2e3,
2453
+ consume: merged.consume ?? false
2454
+ };
2455
+ }
2456
+ function wrapDelivery(serviceName, raw) {
2457
+ return {
2458
+ service: serviceName,
2459
+ eventType: raw.eventType,
2460
+ payload: raw.payload,
2461
+ body: raw.body,
2462
+ headers: raw.headers,
2463
+ url: raw.url,
2464
+ queuedAt: raw.queuedAt
2465
+ };
2466
+ }
2467
+ async function listArchalWebhooks(serviceName) {
2468
+ const res = await fetchArchalTwin(serviceName, "/webhooks/pending");
2469
+ if (res.status === 404) return [];
2470
+ if (!res.ok) {
2471
+ throw new Error(
2472
+ `Failed to list pending webhooks for "${serviceName}": ${res.status} ${res.statusText}`
2473
+ );
2474
+ }
2475
+ const raw = await res.json();
2476
+ return raw.map((d) => wrapDelivery(serviceName, d));
2477
+ }
2478
+ async function clearArchalWebhooks(serviceName) {
2479
+ const res = await fetchArchalTwin(serviceName, "/webhooks/pending", { method: "DELETE" });
2480
+ if (res.status === 404) return;
2481
+ if (!res.ok) {
2482
+ throw new Error(
2483
+ `Failed to clear pending webhooks for "${serviceName}": ${res.status} ${res.statusText}`
2484
+ );
2485
+ }
2486
+ }
2487
+ async function waitForArchalWebhook(serviceName, matcher, options = {}) {
2488
+ const opts = normalizeMatcher(matcher, options);
2489
+ const startTime = Date.now();
2490
+ const deadline = startTime + opts.timeout;
2491
+ let interval = 50;
2492
+ let lastSeen = [];
2493
+ while (true) {
2494
+ const pending = await listArchalWebhooks(serviceName);
2495
+ lastSeen = pending;
2496
+ const match = pending.find(
2497
+ (d) => (!opts.eventType || d.eventType === opts.eventType) && (!opts.where || opts.where(d))
2498
+ );
2499
+ if (match) {
2500
+ if (opts.consume) await clearArchalWebhooks(serviceName);
2501
+ return match;
2502
+ }
2503
+ if (Date.now() + interval >= deadline) break;
2504
+ await new Promise((resolve3) => setTimeout(resolve3, interval));
2505
+ interval = Math.min(250, Math.round(interval * 1.5));
2506
+ }
2507
+ const elapsed = Date.now() - startTime;
2508
+ const lines = lastSeen.length === 0 ? " (none)" : lastSeen.map((d) => ` - ${d.eventType} \u2192 ${d.url}`).join("\n");
2509
+ const filterDesc = opts.eventType ? `eventType: "${opts.eventType}"${opts.where ? " + custom predicate" : ""}` : opts.where ? "custom predicate" : "(any event)";
2510
+ throw new Error(
2511
+ `waitForArchalWebhook timed out after ${elapsed}ms (limit: ${opts.timeout}ms).
2512
+ service: ${serviceName}
2513
+ matcher: ${filterDesc}
2514
+ queued during wait (${lastSeen.length}):
2515
+ ${lines}`
2516
+ );
2517
+ }
2518
+
2519
+ // src/index.ts
2520
+ var DEFAULT_ARCHAL_HOOK_TIMEOUT_MS = 12e4;
2521
+ var DEFAULT_ARCHAL_TEST_TIMEOUT_MS = 12e4;
2522
+ var DEFAULT_EXCLUDE_PATTERNS = [
2523
+ "**/node_modules/**",
2524
+ "**/dist/**",
2525
+ "**/cypress/**",
2526
+ "**/.{idea,git,cache,output,temp}/**"
2527
+ ];
2528
+ var ARCHAL_VITEST_WIRING_MARKER_ENV = "ARCHAL_VITEST_WIRING_MARKER";
2529
+ var ARCHAL_VITEST_WORKSPACE_REPORTER_MARKER_ENV = "ARCHAL_VITEST_WORKSPACE_REPORTER_MARKER";
2530
+ var ARCHAL_TEST_SANDBOX_ID_ENV = "ARCHAL_TEST_SANDBOX_ID";
2531
+ var SHARED_AUTH_SANDBOX_ID = `archal-vitest-${process.pid}-${createHash2("sha256").update(`${process.pid}-${process.cwd()}`).digest("hex").slice(0, 8)}`;
2532
+ var currentModuleFile = typeof __filename === "string" ? __filename : fileURLToPath(import.meta.url);
2533
+ var reporterEntryModule = resolve2(dirname(currentModuleFile), "../reporter-entry.js");
2534
+ function buildTestConfig(options, testOptions) {
2535
+ assertSupportedArchalVitestServices(options.services);
2536
+ const projectName = options.name ?? "archal";
2537
+ const markerPath = installMisuseDetector(projectName);
2538
+ const fileSeedContents = {};
2539
+ const fileSeedFormats = {};
2540
+ for (const [serviceName, svcConfig] of Object.entries(options.services)) {
2541
+ if (!svcConfig?.seed) continue;
2542
+ const classified = classifySeed(svcConfig.seed);
2543
+ if (classified.type === "file") {
2544
+ const content = readSeedFile(classified.path, serviceName);
2545
+ fileSeedContents[serviceName] = content;
2546
+ fileSeedFormats[serviceName] = classified.format;
2547
+ }
2548
+ }
2549
+ const hasFileSeeds = Object.keys(fileSeedContents).length > 0;
2550
+ const encodedConfig = encodeConfig({
2551
+ projectName,
2552
+ services: options.services,
2553
+ sessionKey: computeStableSessionKey(
2554
+ projectName,
2555
+ options.services,
2556
+ hasFileSeeds ? fileSeedContents : void 0,
2557
+ hasFileSeeds ? fileSeedFormats : void 0
2558
+ ),
2559
+ runnerPid: process.pid,
2560
+ ...hasFileSeeds ? { fileSeedContents, fileSeedFormats } : {}
2561
+ });
2562
+ const exclude = testOptions.exclude ?? DEFAULT_EXCLUDE_PATTERNS;
2563
+ const built = {
2564
+ name: projectName,
2565
+ exclude,
2566
+ hookTimeout: testOptions.hookTimeout ?? DEFAULT_ARCHAL_HOOK_TIMEOUT_MS,
2567
+ testTimeout: testOptions.testTimeout ?? DEFAULT_ARCHAL_TEST_TIMEOUT_MS,
2568
+ env: {
2569
+ ...testOptions.env ?? {},
2570
+ [ARCHAL_VITEST_CONFIG_ENV]: encodedConfig,
2571
+ [ARCHAL_TEST_SANDBOX_ID_ENV]: testOptions.env?.[ARCHAL_TEST_SANDBOX_ID_ENV] ?? process.env[ARCHAL_TEST_SANDBOX_ID_ENV] ?? SHARED_AUTH_SANDBOX_ID
2572
+ },
2573
+ setupFiles: [
2574
+ resolveRuntimeModule("./runtime/setup-files.js", ".js")
2575
+ ]
2576
+ };
2577
+ if (testOptions.include !== void 0) built.include = testOptions.include;
2578
+ if (testOptions.globals !== void 0) built.globals = testOptions.globals;
2579
+ if (testOptions.pool !== void 0) built.pool = testOptions.pool;
2580
+ if (markerPath.length > 0) built.env[ARCHAL_VITEST_WIRING_MARKER_ENV] = markerPath;
2581
+ if (options.testIsolation === "serial") {
2582
+ built.maxWorkers = 1;
2583
+ built.fileParallelism = false;
2584
+ }
2585
+ if (testOptions.maxWorkers !== void 0) built.maxWorkers = testOptions.maxWorkers;
2586
+ if (testOptions.fileParallelism !== void 0) built.fileParallelism = testOptions.fileParallelism;
2587
+ return built;
2588
+ }
2589
+ function archalVitestProject(options, testOptions = {}) {
2590
+ const test = buildTestConfig(options, testOptions);
2591
+ return defineProject({ test });
2592
+ }
2593
+ function archalVitestConfig(options, testOptions = {}) {
2594
+ const built = buildTestConfig(options, testOptions);
2595
+ built.reporters = ["default", new ArchalReporter()];
2596
+ return built;
2597
+ }
2598
+ function archalVitestRootConfig() {
2599
+ return {
2600
+ test: {
2601
+ reporters: ["default", reporterEntryModule]
2602
+ }
2603
+ };
2604
+ }
2605
+ function withArchal(existingTest, options) {
2606
+ const passthrough = {};
2607
+ if (existingTest["include"] !== void 0) passthrough.include = existingTest["include"];
2608
+ if (existingTest["exclude"] !== void 0) passthrough.exclude = existingTest["exclude"];
2609
+ if (existingTest["env"] !== void 0) passthrough.env = existingTest["env"];
2610
+ if (existingTest["globals"] !== void 0) passthrough.globals = existingTest["globals"];
2611
+ if (existingTest["pool"] !== void 0) passthrough.pool = existingTest["pool"];
2612
+ if (existingTest["hookTimeout"] !== void 0) passthrough.hookTimeout = existingTest["hookTimeout"];
2613
+ if (existingTest["testTimeout"] !== void 0) passthrough.testTimeout = existingTest["testTimeout"];
2614
+ if (existingTest["maxWorkers"] !== void 0) passthrough.maxWorkers = existingTest["maxWorkers"];
2615
+ if (existingTest["fileParallelism"] !== void 0) passthrough.fileParallelism = existingTest["fileParallelism"];
2616
+ const effectiveOptions = {
2617
+ ...options,
2618
+ name: options.name ?? (typeof existingTest["name"] === "string" ? existingTest["name"] : void 0)
2619
+ };
2620
+ const archal = buildTestConfig(effectiveOptions, passthrough);
2621
+ const existingSetupFiles = toArray(existingTest["setupFiles"]);
2622
+ const existingReporters = toArray(existingTest["reporters"]);
2623
+ const hasArchalReporter = existingReporters.some(
2624
+ (entry) => entry instanceof ArchalReporter
2625
+ );
2626
+ const mergedReporters = existingReporters.length > 0 ? hasArchalReporter ? existingReporters : [...existingReporters, new ArchalReporter()] : ["default", new ArchalReporter()];
2627
+ return {
2628
+ ...existingTest,
2629
+ ...archal,
2630
+ setupFiles: [...existingSetupFiles, ...archal.setupFiles],
2631
+ reporters: mergedReporters
2632
+ };
2633
+ }
2634
+ function toArray(value) {
2635
+ if (value === void 0) return [];
2636
+ return Array.isArray(value) ? value : [value];
2637
+ }
2638
+ function archalVitestWorkspace(projects) {
2639
+ const archalProjectNames = Array.isArray(projects) ? projects.flatMap((project) => {
2640
+ if (!project || typeof project !== "object" || !("test" in project)) {
2641
+ return [];
2642
+ }
2643
+ const test = project.test;
2644
+ if (!test?.env?.[ARCHAL_VITEST_CONFIG_ENV]) {
2645
+ return [];
2646
+ }
2647
+ return [test.name?.trim() || "archal"];
2648
+ }) : [];
2649
+ if (archalProjectNames.length > 0) {
2650
+ process.env[ARCHAL_VITEST_WORKSPACE_REPORTER_MARKER_ENV] = installWorkspaceReporterCheck(archalProjectNames);
2651
+ }
2652
+ return defineWorkspace(projects);
2653
+ }
2654
+ export {
2655
+ ArchalReporter,
2656
+ archalVitestConfig,
2657
+ archalVitestProject,
2658
+ archalVitestRootConfig,
2659
+ archalVitestWorkspace,
2660
+ bootstrapArchalVitestRouting,
2661
+ classifySeed,
2662
+ clearArchalWebhooks,
2663
+ getInstalledArchalVitestRuntime,
2664
+ getInstalledArchalVitestSession,
2665
+ listArchalWebhooks,
2666
+ resetArchalTwins,
2667
+ waitForArchalWebhook,
2668
+ withArchal
2669
+ };