@intentius/behold 0.32.0 → 0.33.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,2820 @@
1
+ import {
2
+ __commonJS
3
+ } from "./chunk-7DQDWJI5.js";
4
+
5
+ // node_modules/picomatch/lib/constants.js
6
+ var require_constants = __commonJS({
7
+ "node_modules/picomatch/lib/constants.js"(exports, module) {
8
+ "use strict";
9
+ var WIN_SLASH = "\\\\/";
10
+ var WIN_NO_SLASH = `[^${WIN_SLASH}]`;
11
+ var DEFAULT_MAX_EXTGLOB_RECURSION = 0;
12
+ var DOT_LITERAL = "\\.";
13
+ var PLUS_LITERAL = "\\+";
14
+ var QMARK_LITERAL = "\\?";
15
+ var SLASH_LITERAL = "\\/";
16
+ var ONE_CHAR = "(?=.)";
17
+ var QMARK = "[^/]";
18
+ var END_ANCHOR = `(?:${SLASH_LITERAL}|$)`;
19
+ var START_ANCHOR = `(?:^|${SLASH_LITERAL})`;
20
+ var DOTS_SLASH = `${DOT_LITERAL}{1,2}${END_ANCHOR}`;
21
+ var NO_DOT = `(?!${DOT_LITERAL})`;
22
+ var NO_DOTS = `(?!${START_ANCHOR}${DOTS_SLASH})`;
23
+ var NO_DOT_SLASH = `(?!${DOT_LITERAL}{0,1}${END_ANCHOR})`;
24
+ var NO_DOTS_SLASH = `(?!${DOTS_SLASH})`;
25
+ var QMARK_NO_DOT = `[^.${SLASH_LITERAL}]`;
26
+ var STAR = `${QMARK}*?`;
27
+ var SEP = "/";
28
+ var POSIX_CHARS = {
29
+ DOT_LITERAL,
30
+ PLUS_LITERAL,
31
+ QMARK_LITERAL,
32
+ SLASH_LITERAL,
33
+ ONE_CHAR,
34
+ QMARK,
35
+ END_ANCHOR,
36
+ DOTS_SLASH,
37
+ NO_DOT,
38
+ NO_DOTS,
39
+ NO_DOT_SLASH,
40
+ NO_DOTS_SLASH,
41
+ QMARK_NO_DOT,
42
+ STAR,
43
+ START_ANCHOR,
44
+ SEP
45
+ };
46
+ var WINDOWS_CHARS = {
47
+ ...POSIX_CHARS,
48
+ SLASH_LITERAL: `[${WIN_SLASH}]`,
49
+ QMARK: WIN_NO_SLASH,
50
+ STAR: `${WIN_NO_SLASH}*?`,
51
+ DOTS_SLASH: `${DOT_LITERAL}{1,2}(?:[${WIN_SLASH}]|$)`,
52
+ NO_DOT: `(?!${DOT_LITERAL})`,
53
+ NO_DOTS: `(?!(?:^|[${WIN_SLASH}])${DOT_LITERAL}{1,2}(?:[${WIN_SLASH}]|$))`,
54
+ NO_DOT_SLASH: `(?!${DOT_LITERAL}{0,1}(?:[${WIN_SLASH}]|$))`,
55
+ NO_DOTS_SLASH: `(?!${DOT_LITERAL}{1,2}(?:[${WIN_SLASH}]|$))`,
56
+ QMARK_NO_DOT: `[^.${WIN_SLASH}]`,
57
+ START_ANCHOR: `(?:^|[${WIN_SLASH}])`,
58
+ END_ANCHOR: `(?:[${WIN_SLASH}]|$)`,
59
+ SEP: "\\"
60
+ };
61
+ var POSIX_REGEX_SOURCE = {
62
+ __proto__: null,
63
+ alnum: "a-zA-Z0-9",
64
+ alpha: "a-zA-Z",
65
+ ascii: "\\x00-\\x7F",
66
+ blank: " \\t",
67
+ cntrl: "\\x00-\\x1F\\x7F",
68
+ digit: "0-9",
69
+ graph: "\\x21-\\x7E",
70
+ lower: "a-z",
71
+ print: "\\x20-\\x7E ",
72
+ punct: "\\-!\"#$%&'()\\*+,./:;<=>?@[\\]^_`{|}~",
73
+ space: " \\t\\r\\n\\v\\f",
74
+ upper: "A-Z",
75
+ word: "A-Za-z0-9_",
76
+ xdigit: "A-Fa-f0-9"
77
+ };
78
+ module.exports = {
79
+ DEFAULT_MAX_EXTGLOB_RECURSION,
80
+ MAX_LENGTH: 1024 * 64,
81
+ POSIX_REGEX_SOURCE,
82
+ // regular expressions
83
+ REGEX_BACKSLASH: /\\(?![*+?^${}(|)[\]])/g,
84
+ REGEX_NON_SPECIAL_CHARS: /^[^@![\].,$*+?^{}()|\\/]+/,
85
+ REGEX_SPECIAL_CHARS: /[-*+?.^${}(|)[\]]/,
86
+ REGEX_SPECIAL_CHARS_BACKREF: /(\\?)((\W)(\3*))/g,
87
+ REGEX_SPECIAL_CHARS_GLOBAL: /([-*+?.^${}(|)[\]])/g,
88
+ REGEX_REMOVE_BACKSLASH: /(?:\[.*?[^\\]\]|\\(?=.))/g,
89
+ // Replace globs with equivalent patterns to reduce parsing time.
90
+ REPLACEMENTS: {
91
+ __proto__: null,
92
+ "***": "*",
93
+ "**/**": "**",
94
+ "**/**/**": "**"
95
+ },
96
+ // Digits
97
+ CHAR_0: 48,
98
+ /* 0 */
99
+ CHAR_9: 57,
100
+ /* 9 */
101
+ // Alphabet chars.
102
+ CHAR_UPPERCASE_A: 65,
103
+ /* A */
104
+ CHAR_LOWERCASE_A: 97,
105
+ /* a */
106
+ CHAR_UPPERCASE_Z: 90,
107
+ /* Z */
108
+ CHAR_LOWERCASE_Z: 122,
109
+ /* z */
110
+ CHAR_LEFT_PARENTHESES: 40,
111
+ /* ( */
112
+ CHAR_RIGHT_PARENTHESES: 41,
113
+ /* ) */
114
+ CHAR_ASTERISK: 42,
115
+ /* * */
116
+ // Non-alphabetic chars.
117
+ CHAR_AMPERSAND: 38,
118
+ /* & */
119
+ CHAR_AT: 64,
120
+ /* @ */
121
+ CHAR_BACKWARD_SLASH: 92,
122
+ /* \ */
123
+ CHAR_CARRIAGE_RETURN: 13,
124
+ /* \r */
125
+ CHAR_CIRCUMFLEX_ACCENT: 94,
126
+ /* ^ */
127
+ CHAR_COLON: 58,
128
+ /* : */
129
+ CHAR_COMMA: 44,
130
+ /* , */
131
+ CHAR_DOT: 46,
132
+ /* . */
133
+ CHAR_DOUBLE_QUOTE: 34,
134
+ /* " */
135
+ CHAR_EQUAL: 61,
136
+ /* = */
137
+ CHAR_EXCLAMATION_MARK: 33,
138
+ /* ! */
139
+ CHAR_FORM_FEED: 12,
140
+ /* \f */
141
+ CHAR_FORWARD_SLASH: 47,
142
+ /* / */
143
+ CHAR_GRAVE_ACCENT: 96,
144
+ /* ` */
145
+ CHAR_HASH: 35,
146
+ /* # */
147
+ CHAR_HYPHEN_MINUS: 45,
148
+ /* - */
149
+ CHAR_LEFT_ANGLE_BRACKET: 60,
150
+ /* < */
151
+ CHAR_LEFT_CURLY_BRACE: 123,
152
+ /* { */
153
+ CHAR_LEFT_SQUARE_BRACKET: 91,
154
+ /* [ */
155
+ CHAR_LINE_FEED: 10,
156
+ /* \n */
157
+ CHAR_NO_BREAK_SPACE: 160,
158
+ /* \u00A0 */
159
+ CHAR_PERCENT: 37,
160
+ /* % */
161
+ CHAR_PLUS: 43,
162
+ /* + */
163
+ CHAR_QUESTION_MARK: 63,
164
+ /* ? */
165
+ CHAR_RIGHT_ANGLE_BRACKET: 62,
166
+ /* > */
167
+ CHAR_RIGHT_CURLY_BRACE: 125,
168
+ /* } */
169
+ CHAR_RIGHT_SQUARE_BRACKET: 93,
170
+ /* ] */
171
+ CHAR_SEMICOLON: 59,
172
+ /* ; */
173
+ CHAR_SINGLE_QUOTE: 39,
174
+ /* ' */
175
+ CHAR_SPACE: 32,
176
+ /* */
177
+ CHAR_TAB: 9,
178
+ /* \t */
179
+ CHAR_UNDERSCORE: 95,
180
+ /* _ */
181
+ CHAR_VERTICAL_LINE: 124,
182
+ /* | */
183
+ CHAR_ZERO_WIDTH_NOBREAK_SPACE: 65279,
184
+ /* \uFEFF */
185
+ /**
186
+ * Create EXTGLOB_CHARS
187
+ */
188
+ extglobChars(chars) {
189
+ return {
190
+ "!": { type: "negate", open: "(?:(?!(?:", close: `))${chars.STAR})` },
191
+ "?": { type: "qmark", open: "(?:", close: ")?" },
192
+ "+": { type: "plus", open: "(?:", close: ")+" },
193
+ "*": { type: "star", open: "(?:", close: ")*" },
194
+ "@": { type: "at", open: "(?:", close: ")" }
195
+ };
196
+ },
197
+ /**
198
+ * Create GLOB_CHARS
199
+ */
200
+ globChars(win32) {
201
+ return win32 === true ? WINDOWS_CHARS : POSIX_CHARS;
202
+ }
203
+ };
204
+ }
205
+ });
206
+
207
+ // node_modules/picomatch/lib/utils.js
208
+ var require_utils = __commonJS({
209
+ "node_modules/picomatch/lib/utils.js"(exports) {
210
+ "use strict";
211
+ var {
212
+ REGEX_BACKSLASH,
213
+ REGEX_REMOVE_BACKSLASH,
214
+ REGEX_SPECIAL_CHARS,
215
+ REGEX_SPECIAL_CHARS_GLOBAL
216
+ } = require_constants();
217
+ exports.isObject = (val) => val !== null && typeof val === "object" && !Array.isArray(val);
218
+ exports.hasRegexChars = (str) => REGEX_SPECIAL_CHARS.test(str);
219
+ exports.isRegexChar = (str) => str.length === 1 && exports.hasRegexChars(str);
220
+ exports.escapeRegex = (str) => str.replace(REGEX_SPECIAL_CHARS_GLOBAL, "\\$1");
221
+ exports.toPosixSlashes = (str) => str.replace(REGEX_BACKSLASH, "/");
222
+ exports.isWindows = () => {
223
+ if (typeof navigator !== "undefined" && navigator.platform) {
224
+ const platform = navigator.platform.toLowerCase();
225
+ return platform === "win32" || platform === "windows";
226
+ }
227
+ if (typeof process !== "undefined" && process.platform) {
228
+ return process.platform === "win32";
229
+ }
230
+ return false;
231
+ };
232
+ exports.removeBackslashes = (str) => {
233
+ return str.replace(REGEX_REMOVE_BACKSLASH, (match) => {
234
+ return match === "\\" ? "" : match;
235
+ });
236
+ };
237
+ exports.escapeLast = (input, char, lastIdx) => {
238
+ const idx = input.lastIndexOf(char, lastIdx);
239
+ if (idx === -1) return input;
240
+ if (input[idx - 1] === "\\") return exports.escapeLast(input, char, idx - 1);
241
+ return `${input.slice(0, idx)}\\${input.slice(idx)}`;
242
+ };
243
+ exports.removePrefix = (input, state = {}) => {
244
+ let output = input;
245
+ if (output.startsWith("./")) {
246
+ output = output.slice(2);
247
+ state.prefix = "./";
248
+ }
249
+ return output;
250
+ };
251
+ exports.wrapOutput = (input, state = {}, options = {}) => {
252
+ const prepend = options.contains ? "" : "^";
253
+ const append = options.contains ? "" : "$";
254
+ let output = `${prepend}(?:${input})${append}`;
255
+ if (state.negated === true) {
256
+ output = `(?:^(?!${output}).*$)`;
257
+ }
258
+ return output;
259
+ };
260
+ exports.basename = (path, { windows } = {}) => {
261
+ const segs = path.split(windows ? /[\\/]/ : "/");
262
+ const last = segs[segs.length - 1];
263
+ if (last === "") {
264
+ return segs[segs.length - 2];
265
+ }
266
+ return last;
267
+ };
268
+ }
269
+ });
270
+
271
+ // node_modules/picomatch/lib/scan.js
272
+ var require_scan = __commonJS({
273
+ "node_modules/picomatch/lib/scan.js"(exports, module) {
274
+ "use strict";
275
+ var utils = require_utils();
276
+ var {
277
+ CHAR_ASTERISK,
278
+ /* * */
279
+ CHAR_AT,
280
+ /* @ */
281
+ CHAR_BACKWARD_SLASH,
282
+ /* \ */
283
+ CHAR_COMMA,
284
+ /* , */
285
+ CHAR_DOT,
286
+ /* . */
287
+ CHAR_EXCLAMATION_MARK,
288
+ /* ! */
289
+ CHAR_FORWARD_SLASH,
290
+ /* / */
291
+ CHAR_LEFT_CURLY_BRACE,
292
+ /* { */
293
+ CHAR_LEFT_PARENTHESES,
294
+ /* ( */
295
+ CHAR_LEFT_SQUARE_BRACKET,
296
+ /* [ */
297
+ CHAR_PLUS,
298
+ /* + */
299
+ CHAR_QUESTION_MARK,
300
+ /* ? */
301
+ CHAR_RIGHT_CURLY_BRACE,
302
+ /* } */
303
+ CHAR_RIGHT_PARENTHESES,
304
+ /* ) */
305
+ CHAR_RIGHT_SQUARE_BRACKET
306
+ /* ] */
307
+ } = require_constants();
308
+ var isPathSeparator = (code) => {
309
+ return code === CHAR_FORWARD_SLASH || code === CHAR_BACKWARD_SLASH;
310
+ };
311
+ var depth = (token) => {
312
+ if (token.isPrefix !== true) {
313
+ token.depth = token.isGlobstar ? Infinity : 1;
314
+ }
315
+ };
316
+ var scan = (input, options) => {
317
+ const opts = options || {};
318
+ const length = input.length - 1;
319
+ const scanToEnd = opts.parts === true || opts.scanToEnd === true;
320
+ const slashes = [];
321
+ const tokens = [];
322
+ const parts = [];
323
+ let str = input;
324
+ let index = -1;
325
+ let start = 0;
326
+ let lastIndex = 0;
327
+ let isBrace = false;
328
+ let isBracket = false;
329
+ let isGlob = false;
330
+ let isExtglob = false;
331
+ let isGlobstar = false;
332
+ let braceEscaped = false;
333
+ let backslashes = false;
334
+ let negated = false;
335
+ let negatedExtglob = false;
336
+ let finished = false;
337
+ let braces = 0;
338
+ let prev;
339
+ let code;
340
+ let token = { value: "", depth: 0, isGlob: false };
341
+ const eos = () => index >= length;
342
+ const peek = () => str.charCodeAt(index + 1);
343
+ const advance = () => {
344
+ prev = code;
345
+ return str.charCodeAt(++index);
346
+ };
347
+ while (index < length) {
348
+ code = advance();
349
+ let next;
350
+ if (code === CHAR_BACKWARD_SLASH) {
351
+ backslashes = token.backslashes = true;
352
+ code = advance();
353
+ if (code === CHAR_LEFT_CURLY_BRACE) {
354
+ braceEscaped = true;
355
+ }
356
+ continue;
357
+ }
358
+ if (braceEscaped === true || code === CHAR_LEFT_CURLY_BRACE) {
359
+ braces++;
360
+ while (eos() !== true && (code = advance())) {
361
+ if (code === CHAR_BACKWARD_SLASH) {
362
+ backslashes = token.backslashes = true;
363
+ advance();
364
+ continue;
365
+ }
366
+ if (code === CHAR_LEFT_CURLY_BRACE) {
367
+ braces++;
368
+ continue;
369
+ }
370
+ if (braceEscaped !== true && code === CHAR_DOT && (code = advance()) === CHAR_DOT) {
371
+ isBrace = token.isBrace = true;
372
+ isGlob = token.isGlob = true;
373
+ finished = true;
374
+ if (scanToEnd === true) {
375
+ continue;
376
+ }
377
+ break;
378
+ }
379
+ if (braceEscaped !== true && code === CHAR_COMMA) {
380
+ isBrace = token.isBrace = true;
381
+ isGlob = token.isGlob = true;
382
+ finished = true;
383
+ if (scanToEnd === true) {
384
+ continue;
385
+ }
386
+ break;
387
+ }
388
+ if (code === CHAR_RIGHT_CURLY_BRACE) {
389
+ braces--;
390
+ if (braces === 0) {
391
+ braceEscaped = false;
392
+ isBrace = token.isBrace = true;
393
+ finished = true;
394
+ break;
395
+ }
396
+ }
397
+ }
398
+ if (scanToEnd === true) {
399
+ continue;
400
+ }
401
+ break;
402
+ }
403
+ if (code === CHAR_FORWARD_SLASH) {
404
+ slashes.push(index);
405
+ tokens.push(token);
406
+ token = { value: "", depth: 0, isGlob: false };
407
+ if (finished === true) continue;
408
+ if (prev === CHAR_DOT && index === start + 1) {
409
+ start += 2;
410
+ continue;
411
+ }
412
+ lastIndex = index + 1;
413
+ continue;
414
+ }
415
+ if (opts.noext !== true) {
416
+ const isExtglobChar = code === CHAR_PLUS || code === CHAR_AT || code === CHAR_ASTERISK || code === CHAR_QUESTION_MARK || code === CHAR_EXCLAMATION_MARK;
417
+ if (isExtglobChar === true && peek() === CHAR_LEFT_PARENTHESES) {
418
+ isGlob = token.isGlob = true;
419
+ isExtglob = token.isExtglob = true;
420
+ finished = true;
421
+ if (code === CHAR_EXCLAMATION_MARK && index === start) {
422
+ negatedExtglob = true;
423
+ }
424
+ if (scanToEnd === true) {
425
+ while (eos() !== true && (code = advance())) {
426
+ if (code === CHAR_BACKWARD_SLASH) {
427
+ backslashes = token.backslashes = true;
428
+ code = advance();
429
+ continue;
430
+ }
431
+ if (code === CHAR_RIGHT_PARENTHESES) {
432
+ isGlob = token.isGlob = true;
433
+ finished = true;
434
+ break;
435
+ }
436
+ }
437
+ continue;
438
+ }
439
+ break;
440
+ }
441
+ }
442
+ if (code === CHAR_ASTERISK) {
443
+ if (prev === CHAR_ASTERISK) isGlobstar = token.isGlobstar = true;
444
+ isGlob = token.isGlob = true;
445
+ finished = true;
446
+ if (scanToEnd === true) {
447
+ continue;
448
+ }
449
+ break;
450
+ }
451
+ if (code === CHAR_QUESTION_MARK) {
452
+ isGlob = token.isGlob = true;
453
+ finished = true;
454
+ if (scanToEnd === true) {
455
+ continue;
456
+ }
457
+ break;
458
+ }
459
+ if (code === CHAR_LEFT_SQUARE_BRACKET) {
460
+ while (eos() !== true && (next = advance())) {
461
+ if (next === CHAR_BACKWARD_SLASH) {
462
+ backslashes = token.backslashes = true;
463
+ advance();
464
+ continue;
465
+ }
466
+ if (next === CHAR_RIGHT_SQUARE_BRACKET) {
467
+ isBracket = token.isBracket = true;
468
+ isGlob = token.isGlob = true;
469
+ finished = true;
470
+ break;
471
+ }
472
+ }
473
+ if (scanToEnd === true) {
474
+ continue;
475
+ }
476
+ break;
477
+ }
478
+ if (opts.nonegate !== true && code === CHAR_EXCLAMATION_MARK && index === start) {
479
+ negated = token.negated = true;
480
+ start++;
481
+ continue;
482
+ }
483
+ if (opts.noparen !== true && code === CHAR_LEFT_PARENTHESES) {
484
+ isGlob = token.isGlob = true;
485
+ if (scanToEnd === true) {
486
+ while (eos() !== true && (code = advance())) {
487
+ if (code === CHAR_LEFT_PARENTHESES) {
488
+ backslashes = token.backslashes = true;
489
+ code = advance();
490
+ continue;
491
+ }
492
+ if (code === CHAR_RIGHT_PARENTHESES) {
493
+ finished = true;
494
+ break;
495
+ }
496
+ }
497
+ continue;
498
+ }
499
+ break;
500
+ }
501
+ if (isGlob === true) {
502
+ finished = true;
503
+ if (scanToEnd === true) {
504
+ continue;
505
+ }
506
+ break;
507
+ }
508
+ }
509
+ if (opts.noext === true) {
510
+ isExtglob = false;
511
+ isGlob = false;
512
+ }
513
+ let base = str;
514
+ let prefix = "";
515
+ let glob = "";
516
+ if (start > 0) {
517
+ prefix = str.slice(0, start);
518
+ str = str.slice(start);
519
+ lastIndex -= start;
520
+ }
521
+ if (base && isGlob === true && lastIndex > 0) {
522
+ base = str.slice(0, lastIndex);
523
+ glob = str.slice(lastIndex);
524
+ } else if (isGlob === true) {
525
+ base = "";
526
+ glob = str;
527
+ } else {
528
+ base = str;
529
+ }
530
+ if (base && base !== "" && base !== "/" && base !== str) {
531
+ if (isPathSeparator(base.charCodeAt(base.length - 1))) {
532
+ base = base.slice(0, -1);
533
+ }
534
+ }
535
+ if (opts.unescape === true) {
536
+ if (glob) glob = utils.removeBackslashes(glob);
537
+ if (base && backslashes === true) {
538
+ base = utils.removeBackslashes(base);
539
+ }
540
+ }
541
+ const state = {
542
+ prefix,
543
+ input,
544
+ start,
545
+ base,
546
+ glob,
547
+ isBrace,
548
+ isBracket,
549
+ isGlob,
550
+ isExtglob,
551
+ isGlobstar,
552
+ negated,
553
+ negatedExtglob
554
+ };
555
+ if (opts.tokens === true) {
556
+ state.maxDepth = 0;
557
+ if (!isPathSeparator(code)) {
558
+ tokens.push(token);
559
+ }
560
+ state.tokens = tokens;
561
+ }
562
+ if (opts.parts === true || opts.tokens === true) {
563
+ let prevIndex;
564
+ for (let idx = 0; idx < slashes.length; idx++) {
565
+ const n = prevIndex ? prevIndex + 1 : start;
566
+ const i = slashes[idx];
567
+ const value = input.slice(n, i);
568
+ if (opts.tokens) {
569
+ if (idx === 0 && start !== 0) {
570
+ tokens[idx].isPrefix = true;
571
+ tokens[idx].value = prefix;
572
+ } else {
573
+ tokens[idx].value = value;
574
+ }
575
+ depth(tokens[idx]);
576
+ state.maxDepth += tokens[idx].depth;
577
+ }
578
+ if (idx !== 0 || value !== "") {
579
+ parts.push(value);
580
+ }
581
+ prevIndex = i;
582
+ }
583
+ if (prevIndex && prevIndex + 1 < input.length) {
584
+ const value = input.slice(prevIndex + 1);
585
+ parts.push(value);
586
+ if (opts.tokens) {
587
+ tokens[tokens.length - 1].value = value;
588
+ depth(tokens[tokens.length - 1]);
589
+ state.maxDepth += tokens[tokens.length - 1].depth;
590
+ }
591
+ }
592
+ state.slashes = slashes;
593
+ state.parts = parts;
594
+ }
595
+ return state;
596
+ };
597
+ module.exports = scan;
598
+ }
599
+ });
600
+
601
+ // node_modules/picomatch/lib/parse.js
602
+ var require_parse = __commonJS({
603
+ "node_modules/picomatch/lib/parse.js"(exports, module) {
604
+ "use strict";
605
+ var constants = require_constants();
606
+ var utils = require_utils();
607
+ var {
608
+ MAX_LENGTH,
609
+ POSIX_REGEX_SOURCE,
610
+ REGEX_NON_SPECIAL_CHARS,
611
+ REGEX_SPECIAL_CHARS_BACKREF,
612
+ REPLACEMENTS
613
+ } = constants;
614
+ var expandRange = (args, options) => {
615
+ if (typeof options.expandRange === "function") {
616
+ return options.expandRange(...args, options);
617
+ }
618
+ args.sort();
619
+ const value = `[${args.join("-")}]`;
620
+ try {
621
+ new RegExp(value);
622
+ } catch (ex) {
623
+ return args.map((v) => utils.escapeRegex(v)).join("..");
624
+ }
625
+ return value;
626
+ };
627
+ var syntaxError = (type, char) => {
628
+ return `Missing ${type}: "${char}" - use "\\\\${char}" to match literal characters`;
629
+ };
630
+ var splitTopLevel = (input) => {
631
+ const parts = [];
632
+ let bracket = 0;
633
+ let paren = 0;
634
+ let quote = 0;
635
+ let value = "";
636
+ let escaped = false;
637
+ for (const ch of input) {
638
+ if (escaped === true) {
639
+ value += ch;
640
+ escaped = false;
641
+ continue;
642
+ }
643
+ if (ch === "\\") {
644
+ value += ch;
645
+ escaped = true;
646
+ continue;
647
+ }
648
+ if (ch === '"') {
649
+ quote = quote === 1 ? 0 : 1;
650
+ value += ch;
651
+ continue;
652
+ }
653
+ if (quote === 0) {
654
+ if (ch === "[") {
655
+ bracket++;
656
+ } else if (ch === "]" && bracket > 0) {
657
+ bracket--;
658
+ } else if (bracket === 0) {
659
+ if (ch === "(") {
660
+ paren++;
661
+ } else if (ch === ")" && paren > 0) {
662
+ paren--;
663
+ } else if (ch === "|" && paren === 0) {
664
+ parts.push(value);
665
+ value = "";
666
+ continue;
667
+ }
668
+ }
669
+ }
670
+ value += ch;
671
+ }
672
+ parts.push(value);
673
+ return parts;
674
+ };
675
+ var isPlainBranch = (branch) => {
676
+ let escaped = false;
677
+ for (const ch of branch) {
678
+ if (escaped === true) {
679
+ escaped = false;
680
+ continue;
681
+ }
682
+ if (ch === "\\") {
683
+ escaped = true;
684
+ continue;
685
+ }
686
+ if (/[?*+@!()[\]{}]/.test(ch)) {
687
+ return false;
688
+ }
689
+ }
690
+ return true;
691
+ };
692
+ var normalizeSimpleBranch = (branch) => {
693
+ let value = branch.trim();
694
+ let changed = true;
695
+ while (changed === true) {
696
+ changed = false;
697
+ if (/^@\([^\\()[\]{}|]+\)$/.test(value)) {
698
+ value = value.slice(2, -1);
699
+ changed = true;
700
+ }
701
+ }
702
+ if (!isPlainBranch(value)) {
703
+ return;
704
+ }
705
+ return value.replace(/\\(.)/g, "$1");
706
+ };
707
+ var hasRepeatedCharPrefixOverlap = (branches) => {
708
+ const values = branches.map(normalizeSimpleBranch).filter(Boolean);
709
+ for (let i = 0; i < values.length; i++) {
710
+ for (let j = i + 1; j < values.length; j++) {
711
+ const a = values[i];
712
+ const b = values[j];
713
+ const char = a[0];
714
+ if (!char || a !== char.repeat(a.length) || b !== char.repeat(b.length)) {
715
+ continue;
716
+ }
717
+ if (a === b || a.startsWith(b) || b.startsWith(a)) {
718
+ return true;
719
+ }
720
+ }
721
+ }
722
+ return false;
723
+ };
724
+ var parseRepeatedExtglob = (pattern, requireEnd = true) => {
725
+ if (pattern[0] !== "+" && pattern[0] !== "*" || pattern[1] !== "(") {
726
+ return;
727
+ }
728
+ let bracket = 0;
729
+ let paren = 0;
730
+ let quote = 0;
731
+ let escaped = false;
732
+ for (let i = 1; i < pattern.length; i++) {
733
+ const ch = pattern[i];
734
+ if (escaped === true) {
735
+ escaped = false;
736
+ continue;
737
+ }
738
+ if (ch === "\\") {
739
+ escaped = true;
740
+ continue;
741
+ }
742
+ if (ch === '"') {
743
+ quote = quote === 1 ? 0 : 1;
744
+ continue;
745
+ }
746
+ if (quote === 1) {
747
+ continue;
748
+ }
749
+ if (ch === "[") {
750
+ bracket++;
751
+ continue;
752
+ }
753
+ if (ch === "]" && bracket > 0) {
754
+ bracket--;
755
+ continue;
756
+ }
757
+ if (bracket > 0) {
758
+ continue;
759
+ }
760
+ if (ch === "(") {
761
+ paren++;
762
+ continue;
763
+ }
764
+ if (ch === ")") {
765
+ paren--;
766
+ if (paren === 0) {
767
+ if (requireEnd === true && i !== pattern.length - 1) {
768
+ return;
769
+ }
770
+ return {
771
+ type: pattern[0],
772
+ body: pattern.slice(2, i),
773
+ end: i
774
+ };
775
+ }
776
+ }
777
+ }
778
+ };
779
+ var buildCharClassStar = (chars) => {
780
+ const source = chars.length === 1 ? utils.escapeRegex(chars[0]) : `[${chars.map((ch) => utils.escapeRegex(ch)).join("")}]`;
781
+ return `${source}*`;
782
+ };
783
+ var getStarExtglobSequenceChars = (pattern) => {
784
+ let index = 0;
785
+ const chars = [];
786
+ while (index < pattern.length) {
787
+ const match = parseRepeatedExtglob(pattern.slice(index), false);
788
+ if (!match || match.type !== "*") {
789
+ return;
790
+ }
791
+ const branches = splitTopLevel(match.body).map((branch2) => branch2.trim());
792
+ if (branches.length !== 1) {
793
+ return;
794
+ }
795
+ const branch = normalizeSimpleBranch(branches[0]);
796
+ if (!branch || branch.length !== 1) {
797
+ return;
798
+ }
799
+ chars.push(branch);
800
+ index += match.end + 1;
801
+ }
802
+ if (chars.length < 1) {
803
+ return;
804
+ }
805
+ return chars;
806
+ };
807
+ var repeatedExtglobRecursion = (pattern) => {
808
+ let depth = 0;
809
+ let value = pattern.trim();
810
+ let match = parseRepeatedExtglob(value);
811
+ while (match) {
812
+ depth++;
813
+ value = match.body.trim();
814
+ match = parseRepeatedExtglob(value);
815
+ }
816
+ return depth;
817
+ };
818
+ var analyzeRepeatedExtglob = (body, options) => {
819
+ if (options.maxExtglobRecursion === false) {
820
+ return { risky: false };
821
+ }
822
+ const max = typeof options.maxExtglobRecursion === "number" ? options.maxExtglobRecursion : constants.DEFAULT_MAX_EXTGLOB_RECURSION;
823
+ const branches = splitTopLevel(body).map((branch) => branch.trim());
824
+ if (branches.length > 1) {
825
+ if (branches.some((branch) => branch === "") || branches.some((branch) => /^[*?]+$/.test(branch)) || hasRepeatedCharPrefixOverlap(branches)) {
826
+ return { risky: true };
827
+ }
828
+ }
829
+ const safeChars = [];
830
+ let sawStarSequence = false;
831
+ let combinable = true;
832
+ for (const branch of branches) {
833
+ const chars = getStarExtglobSequenceChars(branch);
834
+ if (chars) {
835
+ sawStarSequence = true;
836
+ safeChars.push(...chars);
837
+ continue;
838
+ }
839
+ const literal = normalizeSimpleBranch(branch);
840
+ if (literal && literal.length === 1) {
841
+ safeChars.push(literal);
842
+ continue;
843
+ }
844
+ combinable = false;
845
+ if (repeatedExtglobRecursion(branch) > max) {
846
+ return { risky: true };
847
+ }
848
+ }
849
+ if (sawStarSequence) {
850
+ return combinable ? { risky: true, safeOutput: buildCharClassStar([...new Set(safeChars)]) } : { risky: true };
851
+ }
852
+ return { risky: false };
853
+ };
854
+ var parse = (input, options) => {
855
+ if (typeof input !== "string") {
856
+ throw new TypeError("Expected a string");
857
+ }
858
+ input = REPLACEMENTS[input] || input;
859
+ const opts = { ...options };
860
+ const max = typeof opts.maxLength === "number" ? Math.min(MAX_LENGTH, opts.maxLength) : MAX_LENGTH;
861
+ let len = input.length;
862
+ if (len > max) {
863
+ throw new SyntaxError(`Input length: ${len}, exceeds maximum allowed length: ${max}`);
864
+ }
865
+ const bos = { type: "bos", value: "", output: opts.prepend || "" };
866
+ const tokens = [bos];
867
+ const capture = opts.capture ? "" : "?:";
868
+ const PLATFORM_CHARS = constants.globChars(opts.windows);
869
+ const EXTGLOB_CHARS = constants.extglobChars(PLATFORM_CHARS);
870
+ const {
871
+ DOT_LITERAL,
872
+ PLUS_LITERAL,
873
+ SLASH_LITERAL,
874
+ ONE_CHAR,
875
+ DOTS_SLASH,
876
+ NO_DOT,
877
+ NO_DOT_SLASH,
878
+ NO_DOTS_SLASH,
879
+ QMARK,
880
+ QMARK_NO_DOT,
881
+ STAR,
882
+ START_ANCHOR
883
+ } = PLATFORM_CHARS;
884
+ const globstar = (opts2) => {
885
+ return `(${capture}(?:(?!${START_ANCHOR}${opts2.dot ? DOTS_SLASH : DOT_LITERAL}).)*?)`;
886
+ };
887
+ const nodot = opts.dot ? "" : NO_DOT;
888
+ const qmarkNoDot = opts.dot ? QMARK : QMARK_NO_DOT;
889
+ let star = opts.bash === true ? globstar(opts) : STAR;
890
+ if (opts.capture) {
891
+ star = `(${star})`;
892
+ }
893
+ if (typeof opts.noext === "boolean") {
894
+ opts.noextglob = opts.noext;
895
+ }
896
+ const state = {
897
+ input,
898
+ index: -1,
899
+ start: 0,
900
+ dot: opts.dot === true,
901
+ consumed: "",
902
+ output: "",
903
+ prefix: "",
904
+ backtrack: false,
905
+ negated: false,
906
+ brackets: 0,
907
+ braces: 0,
908
+ parens: 0,
909
+ quotes: 0,
910
+ globstar: false,
911
+ tokens
912
+ };
913
+ input = utils.removePrefix(input, state);
914
+ len = input.length;
915
+ const extglobs = [];
916
+ const braces = [];
917
+ const stack = [];
918
+ let prev = bos;
919
+ let value;
920
+ const eos = () => state.index === len - 1;
921
+ const peek = state.peek = (n = 1) => input[state.index + n];
922
+ const advance = state.advance = () => input[++state.index] || "";
923
+ const remaining = () => input.slice(state.index + 1);
924
+ const consume = (value2 = "", num = 0) => {
925
+ state.consumed += value2;
926
+ state.index += num;
927
+ };
928
+ const append = (token) => {
929
+ state.output += token.output != null ? token.output : token.value;
930
+ consume(token.value);
931
+ };
932
+ const negate = () => {
933
+ let count = 1;
934
+ while (peek() === "!" && (peek(2) !== "(" || peek(3) === "?")) {
935
+ advance();
936
+ state.start++;
937
+ count++;
938
+ }
939
+ if (count % 2 === 0) {
940
+ return false;
941
+ }
942
+ state.negated = true;
943
+ state.start++;
944
+ return true;
945
+ };
946
+ const increment = (type) => {
947
+ state[type]++;
948
+ stack.push(type);
949
+ };
950
+ const decrement = (type) => {
951
+ state[type]--;
952
+ stack.pop();
953
+ };
954
+ const push = (tok) => {
955
+ if (prev.type === "globstar") {
956
+ const isBrace = state.braces > 0 && (tok.type === "comma" || tok.type === "brace");
957
+ const isExtglob = tok.extglob === true || extglobs.length && (tok.type === "pipe" || tok.type === "paren");
958
+ if (tok.type !== "slash" && tok.type !== "paren" && !isBrace && !isExtglob) {
959
+ state.output = state.output.slice(0, -prev.output.length);
960
+ prev.type = "star";
961
+ prev.value = "*";
962
+ prev.output = star;
963
+ state.output += prev.output;
964
+ }
965
+ }
966
+ if (extglobs.length && tok.type !== "paren") {
967
+ extglobs[extglobs.length - 1].inner += tok.value;
968
+ }
969
+ if (tok.value || tok.output) append(tok);
970
+ if (prev && prev.type === "text" && tok.type === "text") {
971
+ prev.output = (prev.output || prev.value) + tok.value;
972
+ prev.value += tok.value;
973
+ return;
974
+ }
975
+ tok.prev = prev;
976
+ tokens.push(tok);
977
+ prev = tok;
978
+ };
979
+ const extglobOpen = (type, value2) => {
980
+ const token = { ...EXTGLOB_CHARS[value2], conditions: 1, inner: "" };
981
+ token.prev = prev;
982
+ token.parens = state.parens;
983
+ token.output = state.output;
984
+ token.startIndex = state.index;
985
+ token.tokensIndex = tokens.length;
986
+ const output = (opts.capture ? "(" : "") + token.open;
987
+ increment("parens");
988
+ push({ type, value: value2, output: state.output ? "" : ONE_CHAR });
989
+ push({ type: "paren", extglob: true, value: advance(), output });
990
+ extglobs.push(token);
991
+ };
992
+ const extglobClose = (token) => {
993
+ const literal = input.slice(token.startIndex, state.index + 1);
994
+ const body = input.slice(token.startIndex + 2, state.index);
995
+ const analysis = analyzeRepeatedExtglob(body, opts);
996
+ if ((token.type === "plus" || token.type === "star") && analysis.risky) {
997
+ const safeOutput = analysis.safeOutput ? (token.output ? "" : ONE_CHAR) + (opts.capture ? `(${analysis.safeOutput})` : analysis.safeOutput) : void 0;
998
+ const open = tokens[token.tokensIndex];
999
+ open.type = "text";
1000
+ open.value = literal;
1001
+ open.output = safeOutput || utils.escapeRegex(literal);
1002
+ for (let i = token.tokensIndex + 1; i < tokens.length; i++) {
1003
+ tokens[i].value = "";
1004
+ tokens[i].output = "";
1005
+ delete tokens[i].suffix;
1006
+ }
1007
+ state.output = token.output + open.output;
1008
+ state.backtrack = true;
1009
+ push({ type: "paren", extglob: true, value, output: "" });
1010
+ decrement("parens");
1011
+ return;
1012
+ }
1013
+ let output = token.close + (opts.capture ? ")" : "");
1014
+ let rest;
1015
+ if (token.type === "negate") {
1016
+ let extglobStar = star;
1017
+ if (token.inner && token.inner.length > 1 && token.inner.includes("/")) {
1018
+ extglobStar = globstar(opts);
1019
+ }
1020
+ if (extglobStar !== star || eos() || /^\)+$/.test(remaining())) {
1021
+ output = token.close = `)$))${extglobStar}`;
1022
+ }
1023
+ if (token.inner.includes("*") && (rest = remaining()) && /^\.[^\\/.]+$/.test(rest)) {
1024
+ const expression = parse(rest, { ...options, fastpaths: false }).output;
1025
+ output = token.close = `)${expression})${extglobStar})`;
1026
+ }
1027
+ if (token.prev.type === "bos") {
1028
+ state.negatedExtglob = true;
1029
+ }
1030
+ }
1031
+ push({ type: "paren", extglob: true, value, output });
1032
+ decrement("parens");
1033
+ };
1034
+ if (opts.fastpaths !== false && !/(^[*!]|[/()[\]{}"])/.test(input)) {
1035
+ let backslashes = false;
1036
+ let output = input.replace(REGEX_SPECIAL_CHARS_BACKREF, (m, esc, chars, first, rest, index) => {
1037
+ if (first === "\\") {
1038
+ backslashes = true;
1039
+ return m;
1040
+ }
1041
+ if (first === "?") {
1042
+ if (esc) {
1043
+ return esc + first + (rest ? QMARK.repeat(rest.length) : "");
1044
+ }
1045
+ if (index === 0) {
1046
+ return qmarkNoDot + (rest ? QMARK.repeat(rest.length) : "");
1047
+ }
1048
+ return QMARK.repeat(chars.length);
1049
+ }
1050
+ if (first === ".") {
1051
+ return DOT_LITERAL.repeat(chars.length);
1052
+ }
1053
+ if (first === "*") {
1054
+ if (esc) {
1055
+ return esc + first + (rest ? star : "");
1056
+ }
1057
+ return star;
1058
+ }
1059
+ return esc ? m : `\\${m}`;
1060
+ });
1061
+ if (backslashes === true) {
1062
+ if (opts.unescape === true) {
1063
+ output = output.replace(/\\/g, "");
1064
+ } else {
1065
+ output = output.replace(/\\+/g, (m) => {
1066
+ return m.length % 2 === 0 ? "\\\\" : m ? "\\" : "";
1067
+ });
1068
+ }
1069
+ }
1070
+ if (output === input && opts.contains === true) {
1071
+ state.output = input;
1072
+ return state;
1073
+ }
1074
+ state.output = utils.wrapOutput(output, state, options);
1075
+ return state;
1076
+ }
1077
+ while (!eos()) {
1078
+ value = advance();
1079
+ if (value === "\0") {
1080
+ continue;
1081
+ }
1082
+ if (value === "\\") {
1083
+ const next = peek();
1084
+ if (next === "/" && opts.bash !== true) {
1085
+ continue;
1086
+ }
1087
+ if (next === "." || next === ";") {
1088
+ continue;
1089
+ }
1090
+ if (!next) {
1091
+ value += "\\";
1092
+ push({ type: "text", value });
1093
+ continue;
1094
+ }
1095
+ const match = /^\\+/.exec(remaining());
1096
+ let slashes = 0;
1097
+ if (match && match[0].length > 2) {
1098
+ slashes = match[0].length;
1099
+ state.index += slashes;
1100
+ if (slashes % 2 !== 0) {
1101
+ value += "\\";
1102
+ }
1103
+ }
1104
+ if (opts.unescape === true) {
1105
+ value = advance();
1106
+ } else {
1107
+ value += advance();
1108
+ }
1109
+ if (state.brackets === 0) {
1110
+ push({ type: "text", value });
1111
+ continue;
1112
+ }
1113
+ }
1114
+ if (state.brackets > 0 && (value !== "]" || prev.value === "[" || prev.value === "[^")) {
1115
+ if (opts.posix !== false && value === ":") {
1116
+ const inner = prev.value.slice(1);
1117
+ if (inner.includes("[")) {
1118
+ prev.posix = true;
1119
+ if (inner.includes(":")) {
1120
+ const idx = prev.value.lastIndexOf("[");
1121
+ const pre = prev.value.slice(0, idx);
1122
+ const rest2 = prev.value.slice(idx + 2);
1123
+ const posix2 = POSIX_REGEX_SOURCE[rest2];
1124
+ if (posix2) {
1125
+ prev.value = pre + posix2;
1126
+ state.backtrack = true;
1127
+ advance();
1128
+ if (!bos.output && tokens.indexOf(prev) === 1) {
1129
+ bos.output = ONE_CHAR;
1130
+ }
1131
+ continue;
1132
+ }
1133
+ }
1134
+ }
1135
+ }
1136
+ if (value === "[" && peek() !== ":" || value === "-" && peek() === "]") {
1137
+ value = `\\${value}`;
1138
+ }
1139
+ if (value === "]" && (prev.value === "[" || prev.value === "[^")) {
1140
+ value = `\\${value}`;
1141
+ }
1142
+ if (opts.posix === true && value === "!" && prev.value === "[") {
1143
+ value = "^";
1144
+ }
1145
+ prev.value += value;
1146
+ append({ value });
1147
+ continue;
1148
+ }
1149
+ if (state.quotes === 1 && value !== '"') {
1150
+ value = utils.escapeRegex(value);
1151
+ prev.value += value;
1152
+ append({ value });
1153
+ continue;
1154
+ }
1155
+ if (value === '"') {
1156
+ state.quotes = state.quotes === 1 ? 0 : 1;
1157
+ if (opts.keepQuotes === true) {
1158
+ push({ type: "text", value });
1159
+ }
1160
+ continue;
1161
+ }
1162
+ if (value === "(") {
1163
+ increment("parens");
1164
+ push({ type: "paren", value });
1165
+ continue;
1166
+ }
1167
+ if (value === ")") {
1168
+ if (state.parens === 0 && opts.strictBrackets === true) {
1169
+ throw new SyntaxError(syntaxError("opening", "("));
1170
+ }
1171
+ const extglob = extglobs[extglobs.length - 1];
1172
+ if (extglob && state.parens === extglob.parens + 1) {
1173
+ extglobClose(extglobs.pop());
1174
+ continue;
1175
+ }
1176
+ push({ type: "paren", value, output: state.parens ? ")" : "\\)" });
1177
+ decrement("parens");
1178
+ continue;
1179
+ }
1180
+ if (value === "[") {
1181
+ if (opts.nobracket === true || !remaining().includes("]")) {
1182
+ if (opts.nobracket !== true && opts.strictBrackets === true) {
1183
+ throw new SyntaxError(syntaxError("closing", "]"));
1184
+ }
1185
+ value = `\\${value}`;
1186
+ } else {
1187
+ increment("brackets");
1188
+ }
1189
+ push({ type: "bracket", value });
1190
+ continue;
1191
+ }
1192
+ if (value === "]") {
1193
+ if (opts.nobracket === true || prev && prev.type === "bracket" && prev.value.length === 1) {
1194
+ push({ type: "text", value, output: `\\${value}` });
1195
+ continue;
1196
+ }
1197
+ if (state.brackets === 0) {
1198
+ if (opts.strictBrackets === true) {
1199
+ throw new SyntaxError(syntaxError("opening", "["));
1200
+ }
1201
+ push({ type: "text", value, output: `\\${value}` });
1202
+ continue;
1203
+ }
1204
+ decrement("brackets");
1205
+ const prevValue = prev.value.slice(1);
1206
+ if (prev.posix !== true && prevValue[0] === "^" && !prevValue.includes("/")) {
1207
+ value = `/${value}`;
1208
+ }
1209
+ prev.value += value;
1210
+ append({ value });
1211
+ if (opts.literalBrackets === false || utils.hasRegexChars(prevValue)) {
1212
+ continue;
1213
+ }
1214
+ const escaped = utils.escapeRegex(prev.value);
1215
+ state.output = state.output.slice(0, -prev.value.length);
1216
+ if (opts.literalBrackets === true) {
1217
+ state.output += escaped;
1218
+ prev.value = escaped;
1219
+ continue;
1220
+ }
1221
+ prev.value = `(${capture}${escaped}|${prev.value})`;
1222
+ state.output += prev.value;
1223
+ continue;
1224
+ }
1225
+ if (value === "{" && opts.nobrace !== true) {
1226
+ increment("braces");
1227
+ const open = {
1228
+ type: "brace",
1229
+ value,
1230
+ output: "(",
1231
+ outputIndex: state.output.length,
1232
+ tokensIndex: state.tokens.length
1233
+ };
1234
+ braces.push(open);
1235
+ push(open);
1236
+ continue;
1237
+ }
1238
+ if (value === "}") {
1239
+ const brace = braces[braces.length - 1];
1240
+ if (opts.nobrace === true || !brace) {
1241
+ push({ type: "text", value, output: value });
1242
+ continue;
1243
+ }
1244
+ let output = ")";
1245
+ if (brace.dots === true) {
1246
+ const arr = tokens.slice();
1247
+ const range = [];
1248
+ for (let i = arr.length - 1; i >= 0; i--) {
1249
+ tokens.pop();
1250
+ if (arr[i].type === "brace") {
1251
+ break;
1252
+ }
1253
+ if (arr[i].type !== "dots") {
1254
+ range.unshift(arr[i].value);
1255
+ }
1256
+ }
1257
+ output = expandRange(range, opts);
1258
+ state.backtrack = true;
1259
+ }
1260
+ if (brace.comma !== true && brace.dots !== true) {
1261
+ const out = state.output.slice(0, brace.outputIndex);
1262
+ const toks = state.tokens.slice(brace.tokensIndex);
1263
+ brace.value = brace.output = "\\{";
1264
+ value = output = "\\}";
1265
+ state.output = out;
1266
+ for (const t of toks) {
1267
+ state.output += t.output || t.value;
1268
+ }
1269
+ }
1270
+ push({ type: "brace", value, output });
1271
+ decrement("braces");
1272
+ braces.pop();
1273
+ continue;
1274
+ }
1275
+ if (value === "|") {
1276
+ if (extglobs.length > 0) {
1277
+ extglobs[extglobs.length - 1].conditions++;
1278
+ }
1279
+ push({ type: "text", value });
1280
+ continue;
1281
+ }
1282
+ if (value === ",") {
1283
+ let output = value;
1284
+ const brace = braces[braces.length - 1];
1285
+ if (brace && stack[stack.length - 1] === "braces") {
1286
+ brace.comma = true;
1287
+ output = "|";
1288
+ }
1289
+ push({ type: "comma", value, output });
1290
+ continue;
1291
+ }
1292
+ if (value === "/") {
1293
+ if (prev.type === "dot" && state.index === state.start + 1) {
1294
+ state.start = state.index + 1;
1295
+ state.consumed = "";
1296
+ state.output = "";
1297
+ tokens.pop();
1298
+ prev = bos;
1299
+ continue;
1300
+ }
1301
+ push({ type: "slash", value, output: SLASH_LITERAL });
1302
+ continue;
1303
+ }
1304
+ if (value === ".") {
1305
+ if (state.braces > 0 && prev.type === "dot") {
1306
+ if (prev.value === ".") prev.output = DOT_LITERAL;
1307
+ const brace = braces[braces.length - 1];
1308
+ prev.type = "dots";
1309
+ prev.output += value;
1310
+ prev.value += value;
1311
+ brace.dots = true;
1312
+ continue;
1313
+ }
1314
+ if (state.braces + state.parens === 0 && prev.type !== "bos" && prev.type !== "slash") {
1315
+ push({ type: "text", value, output: DOT_LITERAL });
1316
+ continue;
1317
+ }
1318
+ push({ type: "dot", value, output: DOT_LITERAL });
1319
+ continue;
1320
+ }
1321
+ if (value === "?") {
1322
+ const isGroup = prev && prev.value === "(";
1323
+ if (!isGroup && opts.noextglob !== true && peek() === "(" && peek(2) !== "?") {
1324
+ extglobOpen("qmark", value);
1325
+ continue;
1326
+ }
1327
+ if (prev && prev.type === "paren") {
1328
+ const next = peek();
1329
+ let output = value;
1330
+ if (prev.value === "(" && !/[!=<:]/.test(next) || next === "<" && !/<([!=]|\w+>)/.test(remaining())) {
1331
+ output = `\\${value}`;
1332
+ }
1333
+ push({ type: "text", value, output });
1334
+ continue;
1335
+ }
1336
+ if (opts.dot !== true && (prev.type === "slash" || prev.type === "bos")) {
1337
+ push({ type: "qmark", value, output: QMARK_NO_DOT });
1338
+ continue;
1339
+ }
1340
+ push({ type: "qmark", value, output: QMARK });
1341
+ continue;
1342
+ }
1343
+ if (value === "!") {
1344
+ if (opts.noextglob !== true && peek() === "(") {
1345
+ if (peek(2) !== "?" || !/[!=<:]/.test(peek(3))) {
1346
+ extglobOpen("negate", value);
1347
+ continue;
1348
+ }
1349
+ }
1350
+ if (opts.nonegate !== true && state.index === 0) {
1351
+ negate();
1352
+ continue;
1353
+ }
1354
+ }
1355
+ if (value === "+") {
1356
+ if (opts.noextglob !== true && peek() === "(" && peek(2) !== "?") {
1357
+ extglobOpen("plus", value);
1358
+ continue;
1359
+ }
1360
+ if (prev && prev.value === "(" || opts.regex === false) {
1361
+ push({ type: "plus", value, output: PLUS_LITERAL });
1362
+ continue;
1363
+ }
1364
+ if (prev && (prev.type === "bracket" || prev.type === "paren" || prev.type === "brace") || state.parens > 0) {
1365
+ push({ type: "plus", value });
1366
+ continue;
1367
+ }
1368
+ push({ type: "plus", value: PLUS_LITERAL });
1369
+ continue;
1370
+ }
1371
+ if (value === "@") {
1372
+ if (opts.noextglob !== true && peek() === "(" && peek(2) !== "?") {
1373
+ push({ type: "at", extglob: true, value, output: "" });
1374
+ continue;
1375
+ }
1376
+ push({ type: "text", value });
1377
+ continue;
1378
+ }
1379
+ if (value !== "*") {
1380
+ if (value === "$" || value === "^") {
1381
+ value = `\\${value}`;
1382
+ }
1383
+ const match = REGEX_NON_SPECIAL_CHARS.exec(remaining());
1384
+ if (match) {
1385
+ value += match[0];
1386
+ state.index += match[0].length;
1387
+ }
1388
+ push({ type: "text", value });
1389
+ continue;
1390
+ }
1391
+ if (prev && (prev.type === "globstar" || prev.star === true)) {
1392
+ prev.type = "star";
1393
+ prev.star = true;
1394
+ prev.value += value;
1395
+ prev.output = star;
1396
+ state.backtrack = true;
1397
+ state.globstar = true;
1398
+ consume(value);
1399
+ continue;
1400
+ }
1401
+ let rest = remaining();
1402
+ if (opts.noextglob !== true && /^\([^?]/.test(rest)) {
1403
+ extglobOpen("star", value);
1404
+ continue;
1405
+ }
1406
+ if (prev.type === "star") {
1407
+ if (opts.noglobstar === true) {
1408
+ consume(value);
1409
+ continue;
1410
+ }
1411
+ const prior = prev.prev;
1412
+ const before = prior.prev;
1413
+ const isStart = prior.type === "slash" || prior.type === "bos";
1414
+ const afterStar = before && (before.type === "star" || before.type === "globstar");
1415
+ if (opts.bash === true && (!isStart || rest[0] && rest[0] !== "/")) {
1416
+ push({ type: "star", value, output: "" });
1417
+ continue;
1418
+ }
1419
+ const isBrace = state.braces > 0 && (prior.type === "comma" || prior.type === "brace");
1420
+ const isExtglob = extglobs.length && (prior.type === "pipe" || prior.type === "paren");
1421
+ if (!isStart && prior.type !== "paren" && !isBrace && !isExtglob) {
1422
+ push({ type: "star", value, output: "" });
1423
+ continue;
1424
+ }
1425
+ while (rest.slice(0, 3) === "/**") {
1426
+ const after = input[state.index + 4];
1427
+ if (after && after !== "/") {
1428
+ break;
1429
+ }
1430
+ rest = rest.slice(3);
1431
+ consume("/**", 3);
1432
+ }
1433
+ if (prior.type === "bos" && eos()) {
1434
+ prev.type = "globstar";
1435
+ prev.value += value;
1436
+ prev.output = globstar(opts);
1437
+ state.output = prev.output;
1438
+ state.globstar = true;
1439
+ consume(value);
1440
+ continue;
1441
+ }
1442
+ if (prior.type === "slash" && prior.prev.type !== "bos" && !afterStar && eos()) {
1443
+ state.output = state.output.slice(0, -(prior.output + prev.output).length);
1444
+ prior.output = `(?:${prior.output}`;
1445
+ prev.type = "globstar";
1446
+ prev.output = globstar(opts) + (opts.strictSlashes ? ")" : "|$)");
1447
+ prev.value += value;
1448
+ state.globstar = true;
1449
+ state.output += prior.output + prev.output;
1450
+ consume(value);
1451
+ continue;
1452
+ }
1453
+ if (prior.type === "slash" && prior.prev.type !== "bos" && rest[0] === "/") {
1454
+ const end = rest[1] !== void 0 ? "|$" : "";
1455
+ state.output = state.output.slice(0, -(prior.output + prev.output).length);
1456
+ prior.output = `(?:${prior.output}`;
1457
+ prev.type = "globstar";
1458
+ prev.output = `${globstar(opts)}${SLASH_LITERAL}|${SLASH_LITERAL}${end})`;
1459
+ prev.value += value;
1460
+ state.output += prior.output + prev.output;
1461
+ state.globstar = true;
1462
+ consume(value + advance());
1463
+ push({ type: "slash", value: "/", output: "" });
1464
+ continue;
1465
+ }
1466
+ if (prior.type === "bos" && rest[0] === "/") {
1467
+ prev.type = "globstar";
1468
+ prev.value += value;
1469
+ prev.output = `(?:^|${SLASH_LITERAL}|${globstar(opts)}${SLASH_LITERAL})`;
1470
+ state.output = prev.output;
1471
+ state.globstar = true;
1472
+ consume(value + advance());
1473
+ push({ type: "slash", value: "/", output: "" });
1474
+ continue;
1475
+ }
1476
+ state.output = state.output.slice(0, -prev.output.length);
1477
+ prev.type = "globstar";
1478
+ prev.output = globstar(opts);
1479
+ prev.value += value;
1480
+ state.output += prev.output;
1481
+ state.globstar = true;
1482
+ consume(value);
1483
+ continue;
1484
+ }
1485
+ const token = { type: "star", value, output: star };
1486
+ if (opts.bash === true) {
1487
+ token.output = ".*?";
1488
+ if (prev.type === "bos" || prev.type === "slash") {
1489
+ token.output = nodot + token.output;
1490
+ }
1491
+ push(token);
1492
+ continue;
1493
+ }
1494
+ if (prev && (prev.type === "bracket" || prev.type === "paren") && opts.regex === true) {
1495
+ token.output = value;
1496
+ push(token);
1497
+ continue;
1498
+ }
1499
+ if (state.index === state.start || prev.type === "slash" || prev.type === "dot") {
1500
+ if (prev.type === "dot") {
1501
+ state.output += NO_DOT_SLASH;
1502
+ prev.output += NO_DOT_SLASH;
1503
+ } else if (opts.dot === true) {
1504
+ state.output += NO_DOTS_SLASH;
1505
+ prev.output += NO_DOTS_SLASH;
1506
+ } else {
1507
+ state.output += nodot;
1508
+ prev.output += nodot;
1509
+ }
1510
+ if (peek() !== "*") {
1511
+ state.output += ONE_CHAR;
1512
+ prev.output += ONE_CHAR;
1513
+ }
1514
+ }
1515
+ push(token);
1516
+ }
1517
+ while (state.brackets > 0) {
1518
+ if (opts.strictBrackets === true) throw new SyntaxError(syntaxError("closing", "]"));
1519
+ state.output = utils.escapeLast(state.output, "[");
1520
+ decrement("brackets");
1521
+ }
1522
+ while (state.parens > 0) {
1523
+ if (opts.strictBrackets === true) throw new SyntaxError(syntaxError("closing", ")"));
1524
+ state.output = utils.escapeLast(state.output, "(");
1525
+ decrement("parens");
1526
+ }
1527
+ while (state.braces > 0) {
1528
+ if (opts.strictBrackets === true) throw new SyntaxError(syntaxError("closing", "}"));
1529
+ state.output = utils.escapeLast(state.output, "{");
1530
+ decrement("braces");
1531
+ }
1532
+ if (opts.strictSlashes !== true && (prev.type === "star" || prev.type === "bracket")) {
1533
+ push({ type: "maybe_slash", value: "", output: `${SLASH_LITERAL}?` });
1534
+ }
1535
+ if (state.backtrack === true) {
1536
+ state.output = "";
1537
+ for (const token of state.tokens) {
1538
+ state.output += token.output != null ? token.output : token.value;
1539
+ if (token.suffix) {
1540
+ state.output += token.suffix;
1541
+ }
1542
+ }
1543
+ }
1544
+ return state;
1545
+ };
1546
+ parse.fastpaths = (input, options) => {
1547
+ const opts = { ...options };
1548
+ const max = typeof opts.maxLength === "number" ? Math.min(MAX_LENGTH, opts.maxLength) : MAX_LENGTH;
1549
+ const len = input.length;
1550
+ if (len > max) {
1551
+ throw new SyntaxError(`Input length: ${len}, exceeds maximum allowed length: ${max}`);
1552
+ }
1553
+ input = REPLACEMENTS[input] || input;
1554
+ const {
1555
+ DOT_LITERAL,
1556
+ SLASH_LITERAL,
1557
+ ONE_CHAR,
1558
+ DOTS_SLASH,
1559
+ NO_DOT,
1560
+ NO_DOTS,
1561
+ NO_DOTS_SLASH,
1562
+ STAR,
1563
+ START_ANCHOR
1564
+ } = constants.globChars(opts.windows);
1565
+ const nodot = opts.dot ? NO_DOTS : NO_DOT;
1566
+ const slashDot = opts.dot ? NO_DOTS_SLASH : NO_DOT;
1567
+ const capture = opts.capture ? "" : "?:";
1568
+ const state = { negated: false, prefix: "" };
1569
+ let star = opts.bash === true ? ".*?" : STAR;
1570
+ if (opts.capture) {
1571
+ star = `(${star})`;
1572
+ }
1573
+ const globstar = (opts2) => {
1574
+ if (opts2.noglobstar === true) return star;
1575
+ return `(${capture}(?:(?!${START_ANCHOR}${opts2.dot ? DOTS_SLASH : DOT_LITERAL}).)*?)`;
1576
+ };
1577
+ const create = (str) => {
1578
+ switch (str) {
1579
+ case "*":
1580
+ return `${nodot}${ONE_CHAR}${star}`;
1581
+ case ".*":
1582
+ return `${DOT_LITERAL}${ONE_CHAR}${star}`;
1583
+ case "*.*":
1584
+ return `${nodot}${star}${DOT_LITERAL}${ONE_CHAR}${star}`;
1585
+ case "*/*":
1586
+ return `${nodot}${star}${SLASH_LITERAL}${ONE_CHAR}${slashDot}${star}`;
1587
+ case "**":
1588
+ return nodot + globstar(opts);
1589
+ case "**/*":
1590
+ return `(?:${nodot}${globstar(opts)}${SLASH_LITERAL})?${slashDot}${ONE_CHAR}${star}`;
1591
+ case "**/*.*":
1592
+ return `(?:${nodot}${globstar(opts)}${SLASH_LITERAL})?${slashDot}${star}${DOT_LITERAL}${ONE_CHAR}${star}`;
1593
+ case "**/.*":
1594
+ return `(?:${nodot}${globstar(opts)}${SLASH_LITERAL})?${DOT_LITERAL}${ONE_CHAR}${star}`;
1595
+ default: {
1596
+ const match = /^(.*?)\.(\w+)$/.exec(str);
1597
+ if (!match) return;
1598
+ const source2 = create(match[1]);
1599
+ if (!source2) return;
1600
+ return source2 + DOT_LITERAL + match[2];
1601
+ }
1602
+ }
1603
+ };
1604
+ const output = utils.removePrefix(input, state);
1605
+ let source = create(output);
1606
+ if (source && opts.strictSlashes !== true) {
1607
+ source += `${SLASH_LITERAL}?`;
1608
+ }
1609
+ return source;
1610
+ };
1611
+ module.exports = parse;
1612
+ }
1613
+ });
1614
+
1615
+ // node_modules/picomatch/lib/picomatch.js
1616
+ var require_picomatch = __commonJS({
1617
+ "node_modules/picomatch/lib/picomatch.js"(exports, module) {
1618
+ "use strict";
1619
+ var scan = require_scan();
1620
+ var parse = require_parse();
1621
+ var utils = require_utils();
1622
+ var constants = require_constants();
1623
+ var isObject2 = (val) => val && typeof val === "object" && !Array.isArray(val);
1624
+ var picomatch = (glob, options, returnState = false) => {
1625
+ if (Array.isArray(glob)) {
1626
+ const fns = glob.map((input) => picomatch(input, options, returnState));
1627
+ const arrayMatcher = (str) => {
1628
+ for (const isMatch of fns) {
1629
+ const state2 = isMatch(str);
1630
+ if (state2) return state2;
1631
+ }
1632
+ return false;
1633
+ };
1634
+ return arrayMatcher;
1635
+ }
1636
+ const isState = isObject2(glob) && glob.tokens && glob.input;
1637
+ if (glob === "" || typeof glob !== "string" && !isState) {
1638
+ throw new TypeError("Expected pattern to be a non-empty string");
1639
+ }
1640
+ const opts = options || {};
1641
+ const posix2 = opts.windows;
1642
+ const regex = isState ? picomatch.compileRe(glob, options) : picomatch.makeRe(glob, options, false, true);
1643
+ const state = regex.state;
1644
+ delete regex.state;
1645
+ let isIgnored = () => false;
1646
+ if (opts.ignore) {
1647
+ const ignoreOpts = { ...options, ignore: null, onMatch: null, onResult: null };
1648
+ isIgnored = picomatch(opts.ignore, ignoreOpts, returnState);
1649
+ }
1650
+ const matcher = (input, returnObject = false) => {
1651
+ const { isMatch, match, output } = picomatch.test(input, regex, options, { glob, posix: posix2 });
1652
+ const result = { glob, state, regex, posix: posix2, input, output, match, isMatch };
1653
+ if (typeof opts.onResult === "function") {
1654
+ opts.onResult(result);
1655
+ }
1656
+ if (isMatch === false) {
1657
+ result.isMatch = false;
1658
+ return returnObject ? result : false;
1659
+ }
1660
+ if (isIgnored(input)) {
1661
+ if (typeof opts.onIgnore === "function") {
1662
+ opts.onIgnore(result);
1663
+ }
1664
+ result.isMatch = false;
1665
+ return returnObject ? result : false;
1666
+ }
1667
+ if (typeof opts.onMatch === "function") {
1668
+ opts.onMatch(result);
1669
+ }
1670
+ return returnObject ? result : true;
1671
+ };
1672
+ if (returnState) {
1673
+ matcher.state = state;
1674
+ }
1675
+ return matcher;
1676
+ };
1677
+ picomatch.test = (input, regex, options, { glob, posix: posix2 } = {}) => {
1678
+ if (typeof input !== "string") {
1679
+ throw new TypeError("Expected input to be a string");
1680
+ }
1681
+ if (input === "") {
1682
+ return { isMatch: false, output: "" };
1683
+ }
1684
+ const opts = options || {};
1685
+ const format = opts.format || (posix2 ? utils.toPosixSlashes : null);
1686
+ let match = input === glob;
1687
+ let output = match && format ? format(input) : input;
1688
+ if (match === false) {
1689
+ output = format ? format(input) : input;
1690
+ match = output === glob;
1691
+ }
1692
+ if (match === false || opts.capture === true) {
1693
+ if (opts.matchBase === true || opts.basename === true) {
1694
+ match = picomatch.matchBase(input, regex, options, posix2);
1695
+ } else {
1696
+ match = regex.exec(output);
1697
+ }
1698
+ }
1699
+ return { isMatch: Boolean(match), match, output };
1700
+ };
1701
+ picomatch.matchBase = (input, glob, options, posix2 = options && options.windows) => {
1702
+ const regex = glob instanceof RegExp ? glob : picomatch.makeRe(glob, options);
1703
+ return regex.test(utils.basename(input, { windows: posix2 }));
1704
+ };
1705
+ picomatch.isMatch = (str, patterns, options) => picomatch(patterns, options)(str);
1706
+ picomatch.parse = (pattern, options) => {
1707
+ if (Array.isArray(pattern)) return pattern.map((p) => picomatch.parse(p, options));
1708
+ return parse(pattern, { ...options, fastpaths: false });
1709
+ };
1710
+ picomatch.scan = (input, options) => scan(input, options);
1711
+ picomatch.compileRe = (state, options, returnOutput = false, returnState = false) => {
1712
+ if (returnOutput === true) {
1713
+ return state.output;
1714
+ }
1715
+ const opts = options || {};
1716
+ const prepend = opts.contains ? "" : "^";
1717
+ const append = opts.contains ? "" : "$";
1718
+ let source = `${prepend}(?:${state.output})${append}`;
1719
+ if (state && state.negated === true) {
1720
+ source = `^(?!${source}).*$`;
1721
+ }
1722
+ const regex = picomatch.toRegex(source, options);
1723
+ if (returnState === true) {
1724
+ regex.state = state;
1725
+ }
1726
+ return regex;
1727
+ };
1728
+ picomatch.makeRe = (input, options = {}, returnOutput = false, returnState = false) => {
1729
+ if (!input || typeof input !== "string") {
1730
+ throw new TypeError("Expected a non-empty string");
1731
+ }
1732
+ let parsed = { negated: false, fastpaths: true };
1733
+ if (options.fastpaths !== false && (input[0] === "." || input[0] === "*")) {
1734
+ parsed.output = parse.fastpaths(input, options);
1735
+ }
1736
+ if (!parsed.output) {
1737
+ parsed = parse(input, options);
1738
+ }
1739
+ return picomatch.compileRe(parsed, options, returnOutput, returnState);
1740
+ };
1741
+ picomatch.toRegex = (source, options) => {
1742
+ try {
1743
+ const opts = options || {};
1744
+ return new RegExp(source, opts.flags || (opts.nocase ? "i" : ""));
1745
+ } catch (err) {
1746
+ if (options && options.debug === true) throw err;
1747
+ return /$^/;
1748
+ }
1749
+ };
1750
+ picomatch.constants = constants;
1751
+ module.exports = picomatch;
1752
+ }
1753
+ });
1754
+
1755
+ // node_modules/picomatch/index.js
1756
+ var require_picomatch2 = __commonJS({
1757
+ "node_modules/picomatch/index.js"(exports, module) {
1758
+ "use strict";
1759
+ var pico = require_picomatch();
1760
+ var utils = require_utils();
1761
+ function picomatch(glob, options, returnState = false) {
1762
+ if (options && (options.windows === null || options.windows === void 0)) {
1763
+ options = { ...options, windows: utils.isWindows() };
1764
+ }
1765
+ return pico(glob, options, returnState);
1766
+ }
1767
+ Object.assign(picomatch, pico);
1768
+ module.exports = picomatch;
1769
+ }
1770
+ });
1771
+
1772
+ // node_modules/@intentius/chant/dist/workspace/jsonc.js
1773
+ var JsonSyntaxError = class extends Error {
1774
+ constructor(message, offset) {
1775
+ super(message);
1776
+ this.offset = offset;
1777
+ }
1778
+ };
1779
+ function pointerToken(token) {
1780
+ return String(token).replace(/~/g, "~0").replace(/\//g, "~1");
1781
+ }
1782
+ function parseJsonText(text, options) {
1783
+ const lineStarts = [0];
1784
+ for (let i2 = 0; i2 < text.length; i2++)
1785
+ if (text.charCodeAt(i2) === 10)
1786
+ lineStarts.push(i2 + 1);
1787
+ const toLocation = (offset) => {
1788
+ let lo = 0;
1789
+ let hi = lineStarts.length - 1;
1790
+ while (lo < hi) {
1791
+ const mid = lo + hi + 1 >> 1;
1792
+ if (lineStarts[mid] <= offset)
1793
+ lo = mid;
1794
+ else
1795
+ hi = mid - 1;
1796
+ }
1797
+ return { line: lo + 1, column: offset - lineStarts[lo] + 1 };
1798
+ };
1799
+ const values = /* @__PURE__ */ new Map();
1800
+ const ends = /* @__PURE__ */ new Map();
1801
+ const keys = /* @__PURE__ */ new Map();
1802
+ let i = text.charCodeAt(0) === 65279 ? 1 : 0;
1803
+ const fail = (message, offset = i) => {
1804
+ throw new JsonSyntaxError(message, offset);
1805
+ };
1806
+ const describe = (offset) => offset >= text.length ? "the end of the file" : `${JSON.stringify(text[offset])}`;
1807
+ function skip() {
1808
+ for (; ; ) {
1809
+ const c = text[i];
1810
+ if (c === " " || c === " " || c === "\n" || c === "\r") {
1811
+ i++;
1812
+ } else if (c === "/" && (text[i + 1] === "/" || text[i + 1] === "*")) {
1813
+ if (!options.jsonc)
1814
+ fail("comments are only allowed in chant.workspace.jsonc");
1815
+ if (text[i + 1] === "/") {
1816
+ while (i < text.length && text[i] !== "\n")
1817
+ i++;
1818
+ } else {
1819
+ const end = text.indexOf("*/", i + 2);
1820
+ if (end < 0)
1821
+ fail("unterminated /* comment");
1822
+ i = end + 2;
1823
+ }
1824
+ } else {
1825
+ return;
1826
+ }
1827
+ }
1828
+ }
1829
+ function parseString() {
1830
+ const start = i;
1831
+ i++;
1832
+ for (; ; ) {
1833
+ if (i >= text.length)
1834
+ fail("unterminated string", start);
1835
+ const c = text.charCodeAt(i);
1836
+ if (c === 34)
1837
+ break;
1838
+ if (c < 32)
1839
+ fail("control character in a string; escape it", i);
1840
+ i += c === 92 ? 2 : 1;
1841
+ }
1842
+ i++;
1843
+ try {
1844
+ return JSON.parse(text.slice(start, i));
1845
+ } catch {
1846
+ return fail("invalid escape in a string", start);
1847
+ }
1848
+ }
1849
+ function parseValue(pointer) {
1850
+ skip();
1851
+ values.set(pointer, i);
1852
+ const value = parseAt(pointer);
1853
+ ends.set(pointer, i);
1854
+ return value;
1855
+ }
1856
+ function parseAt(pointer) {
1857
+ const c = text[i];
1858
+ if (c === "{")
1859
+ return parseObject(pointer);
1860
+ if (c === "[")
1861
+ return parseArray(pointer);
1862
+ if (c === '"')
1863
+ return parseString();
1864
+ for (const [word, value] of [
1865
+ ["true", true],
1866
+ ["false", false],
1867
+ ["null", null]
1868
+ ]) {
1869
+ if (text.startsWith(word, i)) {
1870
+ i += word.length;
1871
+ return value;
1872
+ }
1873
+ }
1874
+ const m = /^-?(?:0|[1-9]\d*)(?:\.\d+)?(?:[eE][+-]?\d+)?/.exec(text.slice(i, i + 64));
1875
+ if (m) {
1876
+ i += m[0].length;
1877
+ return Number(m[0]);
1878
+ }
1879
+ return fail(`expected a value, found ${describe(i)}`);
1880
+ }
1881
+ function parseObject(pointer) {
1882
+ const obj = {};
1883
+ const seen = /* @__PURE__ */ new Set();
1884
+ i++;
1885
+ skip();
1886
+ if (text[i] === "}") {
1887
+ i++;
1888
+ return obj;
1889
+ }
1890
+ for (; ; ) {
1891
+ skip();
1892
+ if (text[i] !== '"')
1893
+ fail(`expected a quoted key, found ${describe(i)}`);
1894
+ const keyAt = i;
1895
+ const key = parseString();
1896
+ if (seen.has(key))
1897
+ fail(`duplicate key ${JSON.stringify(key)}`, keyAt);
1898
+ seen.add(key);
1899
+ const child = `${pointer}/${pointerToken(key)}`;
1900
+ keys.set(child, keyAt);
1901
+ skip();
1902
+ if (text[i] !== ":")
1903
+ fail(`expected ":" after key ${JSON.stringify(key)}, found ${describe(i)}`);
1904
+ i++;
1905
+ Object.defineProperty(obj, key, { value: parseValue(child), enumerable: true, writable: true, configurable: true });
1906
+ skip();
1907
+ if (text[i] === ",") {
1908
+ i++;
1909
+ skip();
1910
+ if (text[i] === "}") {
1911
+ if (!options.jsonc)
1912
+ fail("trailing comma; only chant.workspace.jsonc allows one");
1913
+ i++;
1914
+ return obj;
1915
+ }
1916
+ continue;
1917
+ }
1918
+ if (text[i] === "}") {
1919
+ i++;
1920
+ return obj;
1921
+ }
1922
+ fail(`expected "," or "}", found ${describe(i)}`);
1923
+ }
1924
+ }
1925
+ function parseArray(pointer) {
1926
+ const arr = [];
1927
+ i++;
1928
+ skip();
1929
+ if (text[i] === "]") {
1930
+ i++;
1931
+ return arr;
1932
+ }
1933
+ for (; ; ) {
1934
+ arr.push(parseValue(`${pointer}/${arr.length}`));
1935
+ skip();
1936
+ if (text[i] === ",") {
1937
+ i++;
1938
+ skip();
1939
+ if (text[i] === "]") {
1940
+ if (!options.jsonc)
1941
+ fail("trailing comma; only chant.workspace.jsonc allows one");
1942
+ i++;
1943
+ return arr;
1944
+ }
1945
+ continue;
1946
+ }
1947
+ if (text[i] === "]") {
1948
+ i++;
1949
+ return arr;
1950
+ }
1951
+ fail(`expected "," or "]", found ${describe(i)}`);
1952
+ }
1953
+ }
1954
+ try {
1955
+ skip();
1956
+ if (i >= text.length)
1957
+ fail("the file is empty");
1958
+ const value = parseValue("");
1959
+ skip();
1960
+ if (i < text.length)
1961
+ fail(`unexpected ${describe(i)} after the value`);
1962
+ return {
1963
+ ok: true,
1964
+ value,
1965
+ locate(pointer, key) {
1966
+ if (key && keys.has(pointer))
1967
+ return toLocation(keys.get(pointer));
1968
+ for (let p = pointer; ; p = p.slice(0, p.lastIndexOf("/"))) {
1969
+ const at = values.get(p);
1970
+ if (at !== void 0)
1971
+ return toLocation(at);
1972
+ if (p === "")
1973
+ return toLocation(0);
1974
+ }
1975
+ },
1976
+ span(pointer) {
1977
+ const start = values.get(pointer);
1978
+ const end = ends.get(pointer);
1979
+ if (start === void 0 || end === void 0)
1980
+ return void 0;
1981
+ return { key: keys.get(pointer) ?? null, start, end };
1982
+ }
1983
+ };
1984
+ } catch (err) {
1985
+ if (!(err instanceof JsonSyntaxError))
1986
+ throw err;
1987
+ return { ok: false, message: err.message, location: toLocation(err.offset) };
1988
+ }
1989
+ }
1990
+
1991
+ // node_modules/@intentius/chant/dist/lifecycle/gate-seal.js
1992
+ import { createHash as createHash2, createPublicKey as createPublicKey2, verify as verify2 } from "node:crypto";
1993
+
1994
+ // node_modules/@intentius/chant/dist/lifecycle/gate-webauthn.js
1995
+ import { createHash, createPublicKey, verify } from "node:crypto";
1996
+ function webAuthnChallenge(statement) {
1997
+ return createHash("sha256").update(statement).digest("base64url");
1998
+ }
1999
+ function passkeyPublicKey(publicKey2) {
2000
+ let key;
2001
+ try {
2002
+ key = createPublicKey({ key: Buffer.from(publicKey2, "base64url"), format: "der", type: "spki" });
2003
+ } catch (err) {
2004
+ return { problem: `the public key is not a DER SubjectPublicKeyInfo: ${err instanceof Error ? err.message : String(err)}` };
2005
+ }
2006
+ if (key.asymmetricKeyType === "ed25519")
2007
+ return { key, alg: "EdDSA" };
2008
+ if (key.asymmetricKeyType === "ec" && key.asymmetricKeyDetails?.namedCurve === "prime256v1")
2009
+ return { key, alg: "ES256" };
2010
+ if (key.asymmetricKeyType === "rsa")
2011
+ return { key, alg: "RS256" };
2012
+ return { problem: `a ${key.asymmetricKeyType}${key.asymmetricKeyDetails?.namedCurve ? ` ${key.asymmetricKeyDetails.namedCurve}` : ""} key; a passkey is Ed25519, P-256 or RSA` };
2013
+ }
2014
+ var sameId = (a, b) => a.replace(/=+$/, "") === b.replace(/=+$/, "");
2015
+ function verifyWebAuthnAssertion(assertion, statement, passkeys) {
2016
+ try {
2017
+ const pk = passkeys.find((p) => sameId(p.id, assertion.id));
2018
+ if (!pk)
2019
+ return { ok: false, reason: `signed by passkey ${assertion.id}, which the policy at base does not list for the approver` };
2020
+ const clientData = Buffer.from(assertion.clientDataJSON, "base64url");
2021
+ let cd;
2022
+ try {
2023
+ cd = JSON.parse(clientData.toString("utf-8"));
2024
+ } catch {
2025
+ return { ok: false, reason: "its clientDataJSON is not JSON" };
2026
+ }
2027
+ if (cd.type !== "webauthn.get")
2028
+ return { ok: false, reason: `its client data is a ${JSON.stringify(cd.type)} ceremony, not webauthn.get` };
2029
+ if (cd.challenge !== webAuthnChallenge(statement))
2030
+ return { ok: false, reason: "its challenge is not this approval's statement digest" };
2031
+ if (typeof cd.origin !== "string" || !pk.origins.includes(cd.origin)) {
2032
+ return { ok: false, reason: `it comes from origin ${JSON.stringify(cd.origin)}, and the passkey allows ${pk.origins.join(", ")}` };
2033
+ }
2034
+ if (cd.crossOrigin === true)
2035
+ return { ok: false, reason: "it was made in a cross-origin frame" };
2036
+ const authData = Buffer.from(assertion.authenticatorData, "base64url");
2037
+ if (authData.length < 37)
2038
+ return { ok: false, reason: "its authenticatorData is shorter than 37 bytes" };
2039
+ if (!authData.subarray(0, 32).equals(createHash("sha256").update(pk.rpId, "utf-8").digest())) {
2040
+ return { ok: false, reason: `its rpIdHash is not SHA-256 of ${pk.rpId}` };
2041
+ }
2042
+ const flags = authData[32];
2043
+ if (!(flags & 1))
2044
+ return { ok: false, reason: "the user-present flag is unset" };
2045
+ if (!(flags & 4))
2046
+ return { ok: false, reason: "the user-verified flag is unset" };
2047
+ const key = passkeyPublicKey(pk.publicKey);
2048
+ if ("problem" in key)
2049
+ return { ok: false, reason: `passkey ${pk.id}: ${key.problem}` };
2050
+ const signed = Buffer.concat([authData, createHash("sha256").update(clientData).digest()]);
2051
+ const signature = Buffer.from(assertion.signature, "base64url");
2052
+ const ok = verify(key.alg === "EdDSA" ? null : "sha256", signed, key.key, signature);
2053
+ return ok ? { ok: true, key: pk.id } : { ok: false, reason: "the signature does not match the signed fields" };
2054
+ } catch (err) {
2055
+ return { ok: false, reason: err instanceof Error ? err.message : String(err) };
2056
+ }
2057
+ }
2058
+
2059
+ // node_modules/@intentius/chant/dist/lifecycle/gate-seal.js
2060
+ var GATE_SEAL_NAMESPACE = "chant-gate";
2061
+ function sealedFieldsOf(a) {
2062
+ const from = a.carriedFrom;
2063
+ if (from === void 0)
2064
+ return a;
2065
+ const { carriedFrom: _from, checkpointDigest: _checkpoint, ...rest } = a;
2066
+ return {
2067
+ ...rest,
2068
+ op: from.op,
2069
+ gate: from.gate,
2070
+ timestamp: from.timestamp,
2071
+ ...from.checkpointDigest !== void 0 ? { checkpointDigest: from.checkpointDigest } : {}
2072
+ };
2073
+ }
2074
+ function gateSealPayload(approval) {
2075
+ const a = sealedFieldsOf(approval);
2076
+ const relay = a.relayedBy !== void 0 ? `
2077
+ relayed-by ${a.relayedBy}` : "";
2078
+ const checkpoint = a.checkpointDigest !== void 0 ? `
2079
+ checkpoint ${a.checkpointDigest}` : "";
2080
+ const binding = a.binding !== void 0 ? `
2081
+ binding ${a.binding}` : "";
2082
+ return Buffer.from(`${a.op}
2083
+ ${a.gate}
2084
+ ${a.environment ?? ""}
2085
+ ${a.planDigest ?? ""}
2086
+ ${a.resolvedBy}
2087
+ ${a.timestamp}${relay}${checkpoint}${binding}`, "utf-8");
2088
+ }
2089
+ function reader(buf) {
2090
+ let at = 0;
2091
+ const take = (n) => {
2092
+ const len = n ?? take(4).readUInt32BE(0);
2093
+ if (at + len > buf.length)
2094
+ throw new Error("the signature is truncated");
2095
+ return buf.subarray(at, at += len);
2096
+ };
2097
+ return take;
2098
+ }
2099
+ var wire = (b) => {
2100
+ const v = Buffer.from(b);
2101
+ const n = Buffer.alloc(4);
2102
+ n.writeUInt32BE(v.length);
2103
+ return Buffer.concat([n, v]);
2104
+ };
2105
+ var hash = (alg, b) => createHash2(alg).update(b).digest();
2106
+ var b64url = (b) => b.toString("base64url");
2107
+ var unsigned = (b, size) => {
2108
+ let v = b;
2109
+ while (v.length > 1 && v[0] === 0)
2110
+ v = v.subarray(1);
2111
+ return size === void 0 || v.length >= size ? v : Buffer.concat([Buffer.alloc(size - v.length), v]);
2112
+ };
2113
+ function sshKeyFingerprint(blob) {
2114
+ return `SHA256:${hash("sha256", blob).toString("base64").replace(/=+$/, "")}`;
2115
+ }
2116
+ var CURVES = {
2117
+ nistp256: { crv: "P-256", size: 32, hash: "sha256" },
2118
+ nistp384: { crv: "P-384", size: 48, hash: "sha384" },
2119
+ nistp521: { crv: "P-521", size: 66, hash: "sha512" }
2120
+ };
2121
+ function publicKey(blob) {
2122
+ const take = reader(blob);
2123
+ const type = take().toString();
2124
+ if (type === "ssh-ed25519" || type === "sk-ssh-ed25519@openssh.com") {
2125
+ const key = createPublicKey2({ key: { kty: "OKP", crv: "Ed25519", x: b64url(take()) }, format: "jwk" });
2126
+ return { type, key, ...type.startsWith("sk-") ? { application: take() } : {} };
2127
+ }
2128
+ if (type.startsWith("ecdsa-sha2-") || type === "sk-ecdsa-sha2-nistp256@openssh.com") {
2129
+ const curve = CURVES[take().toString()];
2130
+ if (!curve)
2131
+ throw new Error(`unsupported curve in ${type}`);
2132
+ const q = take();
2133
+ if (q[0] !== 4 || q.length !== 1 + 2 * curve.size)
2134
+ throw new Error("the ECDSA key is not an uncompressed point");
2135
+ const key = createPublicKey2({
2136
+ key: { kty: "EC", crv: curve.crv, x: b64url(q.subarray(1, 1 + curve.size)), y: b64url(q.subarray(1 + curve.size)) },
2137
+ format: "jwk"
2138
+ });
2139
+ return { type, key, ecdsa: curve, ...type.startsWith("sk-") ? { application: take() } : {} };
2140
+ }
2141
+ if (type === "ssh-rsa") {
2142
+ const e = unsigned(take());
2143
+ const n = unsigned(take());
2144
+ return { type, key: createPublicKey2({ key: { kty: "RSA", e: b64url(e), n: b64url(n) }, format: "jwk" }) };
2145
+ }
2146
+ throw new Error(`unsupported key type ${type}`);
2147
+ }
2148
+ function verifySshSignatureWith(armored, message, namespace, keys) {
2149
+ try {
2150
+ const body = /-----BEGIN SSH SIGNATURE-----([^-]*)-----END SSH SIGNATURE-----/.exec(armored)?.[1];
2151
+ if (body === void 0)
2152
+ return { ok: false, reason: "it is not an armored ssh signature" };
2153
+ const take = reader(Buffer.from(body.replace(/\s+/g, ""), "base64"));
2154
+ if (take(6).toString() !== "SSHSIG" || take(4).readUInt32BE(0) !== 1)
2155
+ return { ok: false, reason: "it is not an SSHSIG, version 1" };
2156
+ const pk = take();
2157
+ const ns = take();
2158
+ const reserved = take();
2159
+ const alg = take().toString();
2160
+ const sigWire = take();
2161
+ if (ns.toString() !== namespace)
2162
+ return { ok: false, reason: `it is signed in the ${ns.toString()} namespace, not ${namespace}` };
2163
+ if (alg !== "sha256" && alg !== "sha512")
2164
+ return { ok: false, reason: `it hashes with ${alg}, and only sha256 and sha512 are accepted` };
2165
+ if (!keys.some((k) => k.equals(pk)))
2166
+ return { ok: false, reason: "signed by a key the policy at base does not list for the approver" };
2167
+ let data = Buffer.concat([Buffer.from("SSHSIG"), wire(ns), wire(reserved), wire(alg), wire(hash(alg, message))]);
2168
+ const { type, key, ecdsa, application } = publicKey(pk);
2169
+ const sig = reader(sigWire);
2170
+ const sigType = sig().toString();
2171
+ const raw = sig();
2172
+ const fingerprint = sshKeyFingerprint(pk);
2173
+ const answer = (ok) => ok ? { ok: true, key: fingerprint } : { ok: false, reason: "the signature does not match the signed fields" };
2174
+ if (type === "ssh-rsa") {
2175
+ if (sigType !== "rsa-sha2-256" && sigType !== "rsa-sha2-512")
2176
+ return { ok: false, reason: `an RSA signature of type ${sigType} is not accepted` };
2177
+ return answer(verify2(`sha${sigType.slice(9)}`, data, key, raw));
2178
+ }
2179
+ if (sigType !== type)
2180
+ return { ok: false, reason: `a ${sigType} signature from a ${type} key` };
2181
+ if (application !== void 0) {
2182
+ const flags = sig(1);
2183
+ if (!(flags[0] & 1))
2184
+ return { ok: false, reason: "the security key was not touched (the user-presence flag is unset)" };
2185
+ data = Buffer.concat([hash("sha256", application), flags, sig(4), hash("sha256", data)]);
2186
+ }
2187
+ if (ecdsa) {
2188
+ const rs = reader(raw);
2189
+ const r = unsigned(rs(), ecdsa.size);
2190
+ const s = unsigned(rs(), ecdsa.size);
2191
+ return answer(verify2(application !== void 0 ? "sha256" : ecdsa.hash, data, { key, dsaEncoding: "ieee-p1363" }, Buffer.concat([r, s])));
2192
+ }
2193
+ return answer(verify2(null, data, key, raw));
2194
+ } catch (err) {
2195
+ return { ok: false, reason: err instanceof Error ? err.message : String(err) };
2196
+ }
2197
+ }
2198
+ var normalise = (name) => name.normalize("NFKC").trim().toLowerCase();
2199
+ function namespaceAllowed(list, namespace) {
2200
+ if (list === void 0)
2201
+ return true;
2202
+ let allowed = false;
2203
+ for (const raw of list.split(",")) {
2204
+ const negated = raw.startsWith("!");
2205
+ const pattern = negated ? raw.slice(1) : raw;
2206
+ const re = new RegExp(`^${pattern.replace(/[.+^${}()|[\]\\]/g, "\\$&").replace(/\*/g, ".*").replace(/\?/g, ".")}$`);
2207
+ if (!re.test(namespace))
2208
+ continue;
2209
+ if (negated)
2210
+ return false;
2211
+ allowed = true;
2212
+ }
2213
+ return allowed;
2214
+ }
2215
+ var WEBAUTHN_SEAL_KIND = "webauthn";
2216
+ function checkGateSignature(keys, principal, seal, payload) {
2217
+ const name = normalise(principal);
2218
+ if (seal.kind === WEBAUTHN_SEAL_KIND) {
2219
+ const passkeys = (keys.passkeys ?? []).filter((p) => normalise(p.principal) === name);
2220
+ if (passkeys.length === 0)
2221
+ return { ok: false, unlisted: true, reason: `${principal} has no passkey in .chant/trust.json at base` };
2222
+ const assertion = { id: seal.key, clientDataJSON: seal.clientDataJSON, authenticatorData: seal.authenticatorData, signature: seal.signature };
2223
+ if (typeof assertion.id !== "string" || typeof assertion.clientDataJSON !== "string" || typeof assertion.authenticatorData !== "string") {
2224
+ return { ok: false, unlisted: false, reason: "a webauthn seal needs key (the credential id), clientDataJSON and authenticatorData" };
2225
+ }
2226
+ const r2 = verifyWebAuthnAssertion(assertion, payload, passkeys);
2227
+ return r2.ok ? r2 : { ok: false, unlisted: false, reason: r2.reason };
2228
+ }
2229
+ if (seal.kind !== void 0)
2230
+ return { ok: false, unlisted: false, reason: `a seal of kind ${JSON.stringify(seal.kind)} is not one this chant reads` };
2231
+ const listed = keys.signers.filter((s) => normalise(s.principal) === name);
2232
+ if (listed.length === 0)
2233
+ return { ok: false, unlisted: true, reason: `${principal} has no key in the signers file at base` };
2234
+ const blobs = listed.filter((s) => namespaceAllowed(s.namespaces, GATE_SEAL_NAMESPACE)).map((s) => Buffer.from(s.key.split(" ")[1] ?? "", "base64"));
2235
+ const r = verifySshSignatureWith(seal.signature, payload, GATE_SEAL_NAMESPACE, blobs);
2236
+ return r.ok ? r : { ok: false, unlisted: false, reason: r.reason };
2237
+ }
2238
+ function gateSealRefusal(signers, a) {
2239
+ const where = `${signers.signersPath} at base`;
2240
+ if (!signers.active) {
2241
+ const why = signers.problems.length > 0 ? `: ${signers.problems.join("; ")}` : "";
2242
+ return `the gate is sealed, and there is no signers file (${signers.signersPath}) at base ${signers.base?.slice(0, 12) ?? ""}`.trim() + why;
2243
+ }
2244
+ const what = `the approval of gate ${a.gate} by ${a.resolvedBy}`;
2245
+ if (a.seal === void 0 || a.seal === null)
2246
+ return `${what} carries no seal`;
2247
+ const seal = a.seal;
2248
+ if (typeof seal !== "object" || Array.isArray(seal) || typeof seal.signer !== "string" || typeof seal.signature !== "string") {
2249
+ return `the seal on ${what} is malformed: it needs signer and signature`;
2250
+ }
2251
+ if (normalise(seal.signer) !== normalise(a.resolvedBy))
2252
+ return `the seal on ${what} is by ${seal.signer}, and its approver is ${a.resolvedBy || "empty"}`;
2253
+ const r = checkGateSignature(signers, a.resolvedBy, seal, gateSealPayload(a));
2254
+ if (r.ok)
2255
+ return null;
2256
+ return r.unlisted ? `${a.resolvedBy} has no ${unlistedWhat(seal)} in ${unlistedWhere(seal, where)}, so the seal can't count` : `the seal does not verify for ${a.resolvedBy} against ${where}: ${r.reason}`;
2257
+ }
2258
+ function unlistedWhat(seal) {
2259
+ return seal.kind === WEBAUTHN_SEAL_KIND ? "passkey" : "key";
2260
+ }
2261
+ function unlistedWhere(seal, signersWhere) {
2262
+ return seal.kind === WEBAUTHN_SEAL_KIND ? ".chant/trust.json at base" : signersWhere;
2263
+ }
2264
+
2265
+ // node_modules/@intentius/chant/dist/op/gate-quorum.js
2266
+ function quorumProblems(value, where, opts) {
2267
+ const list = Array.isArray(value) ? value : [value];
2268
+ const problems = [];
2269
+ if (Array.isArray(value) && value.length === 0)
2270
+ problems.push(`\`${where}\` must name at least one rule`);
2271
+ list.forEach((rule, i) => {
2272
+ const at = Array.isArray(value) ? `${where}[${i}]` : where;
2273
+ if (typeof rule !== "object" || rule === null || Array.isArray(rule)) {
2274
+ problems.push(`\`${at}\` must be an object`);
2275
+ return;
2276
+ }
2277
+ const q = rule;
2278
+ if (typeof q.count !== "number" || !Number.isInteger(q.count) || q.count < 1)
2279
+ problems.push(`\`${at}.count\` must be an integer of at least 1`);
2280
+ if (q.roles !== void 0 && (!Array.isArray(q.roles) || q.roles.length === 0 || q.roles.some((r) => typeof r !== "string" || r === ""))) {
2281
+ problems.push(`\`${at}.roles\` must be a non-empty list of role names`);
2282
+ }
2283
+ if (q.targets !== void 0 && (!Array.isArray(q.targets) || q.targets.length === 0 || q.targets.some((t) => typeof t !== "string" || t === ""))) {
2284
+ problems.push(`\`${at}.targets\` must be a non-empty list of globs`);
2285
+ }
2286
+ if (q.notAuthor !== void 0 && typeof q.notAuthor !== "boolean")
2287
+ problems.push(`\`${at}.notAuthor\` must be true or false`);
2288
+ if (q.notAuthor === true && !opts.notAuthor) {
2289
+ problems.push(`\`${at}.notAuthor\` is not read here: an Op gate has no author to judge by. An Op waves spec's \`approvals.quorum\` reads it from the merged pull request`);
2290
+ }
2291
+ const known = /* @__PURE__ */ new Set(["targets", "count", "roles", "notAuthor"]);
2292
+ for (const key of Object.keys(q))
2293
+ if (!known.has(key))
2294
+ problems.push(`\`${at}.${key}\` is not a quorum field; use targets, count, roles or notAuthor`);
2295
+ });
2296
+ return problems;
2297
+ }
2298
+
2299
+ // node_modules/@intentius/chant/dist/op/gate-approval-base.js
2300
+ import { createHash as createHash3 } from "node:crypto";
2301
+
2302
+ // node_modules/@intentius/chant/dist/op/gate-plan-context.js
2303
+ var GATE_PLAN_CONTEXT_KEY = "plan";
2304
+
2305
+ // node_modules/@intentius/chant/dist/op/gate-approval-base.js
2306
+ var GATE_APPROVAL_MODES = ["log-only", "enforce"];
2307
+ var STEP_OUTPUT_REF_BRAND = /* @__PURE__ */ Symbol.for("chant.op.stepOutputRef");
2308
+ function isStepOutputRef(value) {
2309
+ return typeof value === "object" && value !== null && value[STEP_OUTPUT_REF_BRAND] === true;
2310
+ }
2311
+ function gatePolicyVersion(text) {
2312
+ return `sha256:${createHash3("sha256").update(text).digest("hex")}`;
2313
+ }
2314
+ function isGatePolicyRef(value) {
2315
+ if (typeof value !== "object" || value === null)
2316
+ return false;
2317
+ const v = value;
2318
+ return v.kind === "gate-policy" && typeof v.lexicon === "string" && v.lexicon !== "" && typeof v.name === "string" && v.name !== "" && typeof v.version === "string" && v.version !== "" && typeof v.text === "string" && v.text.trim() !== "";
2319
+ }
2320
+ function gateBaseApprovalProblems(entry, at) {
2321
+ const problems = [];
2322
+ if (entry.policy !== void 0) {
2323
+ if (!isGatePolicyRef(entry.policy))
2324
+ problems.push(`\`${at}.policy\` does not resolve to a gate policy set: it needs kind "gate-policy", lexicon, name, version and text`);
2325
+ else if (entry.policy.version !== gatePolicyVersion(entry.policy.text))
2326
+ problems.push(`\`${at}.policy\` "${entry.policy.name}" has a version that is not the digest of its text`);
2327
+ }
2328
+ if (entry.mode !== void 0 && !GATE_APPROVAL_MODES.includes(entry.mode)) {
2329
+ problems.push(`\`${at}.mode\` must be one of ${GATE_APPROVAL_MODES.map((m) => `"${m}"`).join(", ")}`);
2330
+ }
2331
+ if (entry.context !== void 0) {
2332
+ if (typeof entry.context !== "object" || entry.context === null || Array.isArray(entry.context))
2333
+ problems.push(`\`${at}.context\` must be an object of plan attributes`);
2334
+ else {
2335
+ for (const [key, value] of Object.entries(entry.context)) {
2336
+ if (key === GATE_PLAN_CONTEXT_KEY)
2337
+ problems.push(`\`${at}.context.${key}\` is reserved: the run fills it with the plan's change-set summary (#3182)`);
2338
+ else if (isStepOutputRef(value) || !isContextValue(value))
2339
+ problems.push(`\`${at}.context.${key}\` must be a string, number, boolean or list of strings`);
2340
+ }
2341
+ }
2342
+ }
2343
+ return problems;
2344
+ }
2345
+ function isContextValue(value) {
2346
+ if (typeof value === "string" || typeof value === "boolean")
2347
+ return true;
2348
+ if (typeof value === "number")
2349
+ return Number.isFinite(value);
2350
+ if (Array.isArray(value))
2351
+ return value.every((v) => typeof v === "string");
2352
+ return isStepOutputRef(value);
2353
+ }
2354
+
2355
+ // node_modules/@intentius/chant/dist/notify.js
2356
+ var NOTIFY_EVENTS = ["waiting", "refused", "failed", "drift", "ci.red", "ci.culprit", "ci.green", "ci.quarantine-passed", "ci.stale"];
2357
+ var DEFAULT_RELAY_MAX_AGE_SECONDS = 24 * 60 * 60;
2358
+ var VARIABLE = /^[A-Za-z_][A-Za-z0-9_]*$/;
2359
+ var SETTINGS = ["webhook", "key", "slack", "teams", "events", "relay", "relayName"];
2360
+ function notifyConfigProblem(value, where = "notify") {
2361
+ if (typeof value !== "object" || value === null || Array.isArray(value))
2362
+ return `${where}: expected { webhook, key, slack, teams, events }`;
2363
+ const v = value;
2364
+ for (const k of Object.keys(v))
2365
+ if (!SETTINGS.includes(k))
2366
+ return `${where}.${k}: unknown setting (expected ${SETTINGS.join(", ")})`;
2367
+ for (const k of ["webhook", "key", "slack", "teams", "relay"]) {
2368
+ const n = v[k];
2369
+ if (n === void 0)
2370
+ continue;
2371
+ if (typeof n !== "string" || !VARIABLE.test(n)) {
2372
+ const what = k === "key" ? "signing key" : k === "relay" ? "relay key" : "URL";
2373
+ return `${where}.${k}: the name of the environment variable that holds the ${what}, never the ${k === "key" || k === "relay" ? "key" : "URL"} itself`;
2374
+ }
2375
+ }
2376
+ if (v.webhook !== void 0 && v.key === void 0)
2377
+ return `${where}.key: a webhook needs a signing key; name the variable that holds it`;
2378
+ if (v.key !== void 0 && v.webhook === void 0)
2379
+ return `${where}.webhook: a key is for a webhook; name the variable that holds its URL`;
2380
+ if (v.relayName !== void 0 && (typeof v.relayName !== "string" || !/^[^\s@<>][^\r\n@<>]{0,79}$/.test(v.relayName) || v.relayName.trim() !== v.relayName)) {
2381
+ return `${where}.relayName: the relay's name as Teams mentions it, one line of at most 80 characters without @, < or >`;
2382
+ }
2383
+ if (v.webhook === void 0 && v.slack === void 0 && v.teams === void 0)
2384
+ return `${where}: name a webhook (with its key), a slack or a teams URL variable`;
2385
+ if (v.events !== void 0 && !(Array.isArray(v.events) && v.events.every((e) => NOTIFY_EVENTS.includes(e)))) {
2386
+ return `${where}.events: a list of ${NOTIFY_EVENTS.join(", ")}`;
2387
+ }
2388
+ return void 0;
2389
+ }
2390
+
2391
+ // node_modules/@intentius/chant/dist/ci-product-words.js
2392
+ var CHANT_NOTIFY_WAVE_TEMPLATE = "wave {k} ({name}) of {spec}";
2393
+ var CHANT_APPROVE_TEMPLATE = "chant approve {op} {gate} --plan {digest} --approver {approver} {sign}";
2394
+ var CHANT_OVERRIDE_TEMPLATE = 'chant approve {op} {target} --rule {rule} --reason "<why>" {sign}';
2395
+ var CHANT_WORDS = Object.freeze({
2396
+ product: "chant",
2397
+ stages: { plan: "plan", apply: "apply", record: "record", check: "check", drift: "drift", lock: "lock", approval: "approval", control: "control" },
2398
+ verbs: { plan: ["plan", "planned"], apply: ["apply", "applied"] },
2399
+ noun: ["member", "members"],
2400
+ commands: { apply: "apply" },
2401
+ aliases: [],
2402
+ approve: CHANT_APPROVE_TEMPLATE,
2403
+ override: CHANT_OVERRIDE_TEMPLATE,
2404
+ gateName: "{gate}-wave-{k}",
2405
+ prGate: "pr-apply",
2406
+ approval: "pull-request",
2407
+ applyMode: "release",
2408
+ adoptMarkers: [],
2409
+ notify: { source: "chant", wave: CHANT_NOTIFY_WAVE_TEMPLATE, headers: "x-chant" }
2410
+ });
2411
+ var active = CHANT_WORDS;
2412
+ function activeProductWords() {
2413
+ return active;
2414
+ }
2415
+ function isChantWords(words) {
2416
+ return words.product === CHANT_WORDS.product;
2417
+ }
2418
+ var fill = (template, values) => template.replace(/\{([a-z]+)\}/g, (_, k) => values[k] ?? "").split(/[ \t]+/).filter((w) => w !== "").join(" ");
2419
+ function overrideLine(words, input) {
2420
+ return fill(words.override, {
2421
+ op: input.op,
2422
+ gate: input.gate ?? "",
2423
+ rule: [...new Set(input.rules)].sort().join(" --rule "),
2424
+ reason: input.reason ?? "<text>",
2425
+ target: input.target ?? "",
2426
+ digest: input.digest ?? "",
2427
+ approver: "<you>",
2428
+ sign: input.sign ? "--sign" : ""
2429
+ });
2430
+ }
2431
+
2432
+ // node_modules/@intentius/chant/dist/op/op-waves.js
2433
+ var GATE_APPROVAL_SOURCES = ["ledger", "pr-review", "sealed", "pull-request"];
2434
+ var OP_WAVE_HOOK_FAILURES = ["fail", "approve"];
2435
+ var OP_WAVE_APPLY_HOOKS_RUNNERS = ["chant", "apply"];
2436
+ function assertArgv(where, field, argv) {
2437
+ if (!Array.isArray(argv) || argv.length === 0 || !argv.every((part) => typeof part === "string") || argv[0] === "") {
2438
+ throw new Error(`${where}: \`${field}\` must be a command as argv, a non-empty array of strings.`);
2439
+ }
2440
+ }
2441
+ function assertOpWaveHooks(where, hooks) {
2442
+ if (hooks === void 0)
2443
+ return;
2444
+ if (hooks === null || typeof hooks !== "object" || Array.isArray(hooks)) {
2445
+ throw new Error(`${where}: \`hooks\` must be { "before"?: { "observe"?, "plan"?, "apply"? }, "after"?: { "plan"?, "gate"?, "apply"? } }.`);
2446
+ }
2447
+ for (const [side, stages] of Object.entries(hooks)) {
2448
+ if (side === "apply") {
2449
+ const runBy = stages?.runBy;
2450
+ if (stages === null || typeof stages !== "object" || Array.isArray(stages) || Object.keys(stages).some((key) => key !== "runBy")) {
2451
+ throw new Error(`${where}: hooks.apply must be { "runBy"?: "chant" | "apply" }.`);
2452
+ }
2453
+ if (runBy !== void 0 && !OP_WAVE_APPLY_HOOKS_RUNNERS.includes(runBy)) {
2454
+ throw new Error(`${where}: hooks.apply.runBy is ${JSON.stringify(runBy)}; use ${OP_WAVE_APPLY_HOOKS_RUNNERS.map((r) => `"${r}"`).join(" or ")}.`);
2455
+ }
2456
+ continue;
2457
+ }
2458
+ if (side === "check")
2459
+ throw new Error(`${where}: hooks.check runs in a product's check job, so it belongs in ci.hooks of the workspace declaration, not in an Op waves spec.`);
2460
+ if (side !== "before" && side !== "after")
2461
+ throw new Error(`${where}: hooks.${side} is not a moment; use hooks.before or hooks.after (or hooks.apply.runBy).`);
2462
+ if (stages === null || typeof stages !== "object" || Array.isArray(stages))
2463
+ throw new Error(`${where}: hooks.${side} must be { "plan"?: [...], "apply"?: [...] }.`);
2464
+ for (const [stage, list] of Object.entries(stages)) {
2465
+ const at = `hooks.${side}.${stage}`;
2466
+ if (stage === "gate" && side === "before")
2467
+ throw new Error(`${where}: ${at} is not a moment; a hook runs after the gate (hooks.after.gate), or before the plan or the apply.`);
2468
+ if (stage === "observe" && side === "after")
2469
+ throw new Error(`${where}: ${at} is not a moment; a hook runs before the observe (hooks.before.observe), or after the plan, which reads what the observe saw.`);
2470
+ if (stage !== "observe" && stage !== "plan" && stage !== "apply" && stage !== "gate")
2471
+ throw new Error(`${where}: ${at} is not a stage; a hook runs before the observe, before or after plan or apply, or after the gate.`);
2472
+ if (!Array.isArray(list))
2473
+ throw new Error(`${where}: ${at} must be a list of hooks.`);
2474
+ list.forEach((hook, i) => {
2475
+ const which = `${at}[${i}]${hook && typeof hook === "object" && typeof hook.name === "string" ? ` (${hook.name})` : ""}`;
2476
+ if (!hook || typeof hook !== "object")
2477
+ throw new Error(`${where}: ${which} must be { "command": [...], "onFailure"?, "perRun"? }.`);
2478
+ assertArgv(where, `${which}.command`, hook.command);
2479
+ if (hook.onFailure !== void 0 && !OP_WAVE_HOOK_FAILURES.includes(hook.onFailure)) {
2480
+ throw new Error(`${where}: ${which} has onFailure "${hook.onFailure}"; use ${OP_WAVE_HOOK_FAILURES.join(" or ")}.`);
2481
+ }
2482
+ if (hook.onFailure === "approve" && side === "after" && stage === "apply") {
2483
+ throw new Error(`${where}: ${which} has onFailure "approve", but after the apply there is nothing left to hold. Use "fail".`);
2484
+ }
2485
+ if (hook.onFailure === "approve" && stage === "gate") {
2486
+ throw new Error(`${where}: ${which} has onFailure "approve", but the gate has already decided when it runs. Use "fail", or hold the wave from an after.plan hook.`);
2487
+ }
2488
+ if (hook.perRun !== void 0 && typeof hook.perRun !== "boolean")
2489
+ throw new Error(`${where}: ${which}.perRun must be true or false.`);
2490
+ if (hook.targets !== void 0 && (!Array.isArray(hook.targets) || hook.targets.length === 0 || !hook.targets.every((t) => typeof t === "string" && t !== ""))) {
2491
+ throw new Error(`${where}: ${which}.targets must be a non-empty list of targets or patterns, such as ["prod/*"].`);
2492
+ }
2493
+ if (!hook.perRun) {
2494
+ const named = hook.command.find((part) => part.includes("{target}") || part.includes("{plan}") || part.includes("{planJson}"));
2495
+ if (named)
2496
+ throw new Error(`${where}: ${which} runs once for the wave, so it has no {target}, {plan} or {planJson} ("${named}"). Set "perRun": true, or read the runs from {runs}.`);
2497
+ } else if (side === "before" && (stage === "plan" || stage === "observe") && hook.command.some((part) => part.includes("{plan}") || part.includes("{planJson}"))) {
2498
+ throw new Error(`${where}: ${which} runs before the plan, so it has no {plan} yet.`);
2499
+ }
2500
+ });
2501
+ }
2502
+ }
2503
+ }
2504
+ function assertPrLoopHooks(where, hooks) {
2505
+ if (hooks !== void 0 && hooks !== null && typeof hooks === "object" && !Array.isArray(hooks) && "check" in hooks) {
2506
+ const { check, ...rest } = hooks;
2507
+ assertCheckHooks(where, check);
2508
+ assertOpWaveHooks(where, rest);
2509
+ } else {
2510
+ assertOpWaveHooks(where, hooks);
2511
+ }
2512
+ if (hooks?.apply !== void 0)
2513
+ throw new Error(`${where}: hooks.apply.runBy is for an Op waves spec; chant runs a pull request's apply, so it runs the apply-stage hooks itself.`);
2514
+ }
2515
+ function assertCheckHooks(where, list) {
2516
+ if (!Array.isArray(list))
2517
+ throw new Error(`${where}: hooks.check must be a list of hooks.`);
2518
+ list.forEach((hook, i) => {
2519
+ const which = `hooks.check[${i}]${hook && typeof hook === "object" && typeof hook.name === "string" ? ` (${hook.name})` : ""}`;
2520
+ if (!hook || typeof hook !== "object")
2521
+ throw new Error(`${where}: ${which} must be { "command": [...], "name"?, "onFailure"?, "perRun"?, "targets"? }.`);
2522
+ assertArgv(where, `${which}.command`, hook.command);
2523
+ if (hook.onFailure === "approve")
2524
+ throw new Error(`${where}: ${which} has onFailure "approve", but the check runs before any plan, so there is nothing to approve. Use "fail".`);
2525
+ if (hook.onFailure !== void 0 && hook.onFailure !== "fail")
2526
+ throw new Error(`${where}: ${which} has onFailure "${hook.onFailure}"; use "fail".`);
2527
+ if (hook.perRun !== void 0 && typeof hook.perRun !== "boolean")
2528
+ throw new Error(`${where}: ${which}.perRun must be true or false.`);
2529
+ if (hook.targets !== void 0 && (!Array.isArray(hook.targets) || hook.targets.length === 0 || !hook.targets.every((t) => typeof t === "string" && t !== ""))) {
2530
+ throw new Error(`${where}: ${which}.targets must be a non-empty list of targets or patterns, such as ["prod/*"].`);
2531
+ }
2532
+ const plan = hook.command.find((part) => part.includes("{plan}"));
2533
+ if (plan)
2534
+ throw new Error(`${where}: ${which} runs before any plan, so it has no {plan} ("${plan}").`);
2535
+ if (!hook.perRun) {
2536
+ const target = hook.command.find((part) => part.includes("{target}"));
2537
+ if (target)
2538
+ throw new Error(`${where}: ${which} runs once for the check, so it has no {target} ("${target}"). Set "perRun": true.`);
2539
+ }
2540
+ });
2541
+ }
2542
+
2543
+ // node_modules/@intentius/chant/dist/workspace/ajv2020.js
2544
+ import { createRequire } from "node:module";
2545
+ function loadAjv2020() {
2546
+ const require2 = createRequire(import.meta.url);
2547
+ const mod = require2("ajv/dist/2020");
2548
+ return mod.default ?? mod;
2549
+ }
2550
+
2551
+ // node_modules/@intentius/chant/dist/workspace/class-data.js
2552
+ import { existsSync, readFileSync, statSync } from "node:fs";
2553
+ import { dirname, join, posix, resolve } from "node:path";
2554
+ import { fileURLToPath } from "node:url";
2555
+
2556
+ // node_modules/@intentius/chant/dist/workspace/identity-gate-rule.js
2557
+ var CORE_PRINCIPAL_CLASSES = ["human", "agent", "runner", "service"];
2558
+ var CORE_CLASSES = [
2559
+ { name: "human", description: "a principal holding none of the roles of another class", role: null, source: "core" },
2560
+ { name: "agent", description: "a principal holding the agent role, or a write naming an agent session", role: "agent", source: "core" },
2561
+ { name: "runner", description: "a principal holding the runner role, such as a CI job's signing identity", role: "runner", source: "core" },
2562
+ { name: "service", description: "a principal holding the service role", role: "service", source: "core" }
2563
+ ];
2564
+ var normalise2 = (name) => name.normalize("NFKC").trim().toLowerCase();
2565
+ function grantedClasses(classes, roles, principal) {
2566
+ if (principal === null)
2567
+ return [];
2568
+ const name = normalise2(principal);
2569
+ return classes.filter((c) => c.role !== null && (roles[c.role] ?? []).some((p) => normalise2(p) === name)).map((c) => c.name);
2570
+ }
2571
+ function admitApprover(rule, a) {
2572
+ const { gate, signers } = rule;
2573
+ const unknown = unknownClassRefusal(rule, "approval");
2574
+ if (unknown !== null)
2575
+ return unknown;
2576
+ if (!signers.active)
2577
+ return `gate ${gate} needs a signed approval, and there is no signers file (${signers.signersPath}) at base to check one against`;
2578
+ const seal = sealRefusal(gate, signers, a);
2579
+ if (seal !== null)
2580
+ return seal;
2581
+ return classRefusal(rule, a.resolvedBy);
2582
+ }
2583
+ function unknownClassRefusal(rule, what) {
2584
+ const want = rule.class;
2585
+ if (want === null || rule.classes.some((c) => c.name === want))
2586
+ return null;
2587
+ return `identity.gates.${rule.gate} names the class ${want}, which ${rule.unknownClass ?? "no pinned package supplies"}, so no ${what} can show it is in that class (known classes: ${rule.classes.map((c) => c.name).join(", ")})`;
2588
+ }
2589
+ function classRefusal(rule, principal) {
2590
+ const want = rule.class;
2591
+ if (want === null)
2592
+ return null;
2593
+ const granted = grantedClasses(rule.classes, rule.roles, principal);
2594
+ const inClass = want === "human" ? granted.length === 0 : granted.includes(want);
2595
+ return inClass ? null : `${principal} is not in the class ${want} that gate ${rule.gate} needs: no role grant at base puts them there`;
2596
+ }
2597
+ function sealRefusal(gate, signers, a) {
2598
+ const what = `the approval of gate ${a.gate} by ${a.resolvedBy}`;
2599
+ if (a.seal === void 0 || a.seal === null)
2600
+ return `the approval by ${a.resolvedBy} is not signed; gate ${gate} needs chant approve --sign`;
2601
+ const seal = a.seal;
2602
+ if (typeof seal !== "object" || Array.isArray(seal) || typeof seal.signer !== "string" || typeof seal.signature !== "string") {
2603
+ return `the seal on ${what} is malformed: it needs signer and signature`;
2604
+ }
2605
+ if (normalise2(seal.signer) !== normalise2(a.resolvedBy))
2606
+ return `the seal on ${what} is by ${seal.signer}, and its approver is ${a.resolvedBy || "empty"}`;
2607
+ const where = `${signers.signersPath} at base`;
2608
+ const r = checkGateSignature(signers, a.resolvedBy, seal, gateSealPayload(a));
2609
+ if (r.ok)
2610
+ return null;
2611
+ return r.unlisted ? `${a.resolvedBy} has no ${unlistedWhat(seal)} in ${unlistedWhere(seal, where)}, so the seal can't count` : `the seal does not verify for ${a.resolvedBy} against ${where}: ${r.reason}`;
2612
+ }
2613
+
2614
+ // node_modules/@intentius/chant/dist/workspace/class-data.js
2615
+ var PRINCIPALS_SUBPATH = "./workspace-principals";
2616
+ function diskFiles(dir) {
2617
+ return (path) => {
2618
+ try {
2619
+ return readFileSync(join(dir, ...path.split("/")), "utf-8");
2620
+ } catch {
2621
+ return void 0;
2622
+ }
2623
+ };
2624
+ }
2625
+ var CHANT_INSTALL = dirname(fileURLToPath(import.meta.url));
2626
+ function findInstalledPackage(name, fromDir) {
2627
+ for (let dir = resolve(fromDir); ; dir = dirname(dir)) {
2628
+ const candidate = join(dir, "node_modules", ...name.split("/"));
2629
+ try {
2630
+ if (statSync(candidate).isDirectory() && existsSync(join(candidate, "package.json")))
2631
+ return candidate;
2632
+ } catch {
2633
+ }
2634
+ if (dirname(dir) === dir)
2635
+ return void 0;
2636
+ }
2637
+ }
2638
+ function dataExportTarget(pkg, subpath) {
2639
+ const exports = pkg.exports;
2640
+ if (!exports || typeof exports !== "object" || Array.isArray(exports))
2641
+ return void 0;
2642
+ const entry = exports[subpath];
2643
+ if (entry === void 0)
2644
+ return void 0;
2645
+ let target = entry;
2646
+ if (target && typeof target === "object" && !Array.isArray(target)) {
2647
+ const conditions = target;
2648
+ target = conditions.default ?? conditions.import ?? conditions.require;
2649
+ }
2650
+ if (typeof target !== "string") {
2651
+ return { problem: `exports["${subpath}"] must name one file, as a string or a "default" condition` };
2652
+ }
2653
+ if (!target.startsWith("./") || !target.endsWith(".json")) {
2654
+ return { problem: `exports["${subpath}"] is ${target}; it must name a .json file inside the package, since chant reads plugin data as data and never runs a package's code` };
2655
+ }
2656
+ return target;
2657
+ }
2658
+ var NAME = /^(?!x-)[a-z][a-z0-9-]{0,39}$/u;
2659
+ var ROLE = /^[a-z][a-z0-9-]*$/u;
2660
+ var isObject = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
2661
+ var extra = (key, known) => !known.includes(key) && !key.startsWith("x-");
2662
+ function classDataShapeProblems(raw, source) {
2663
+ const p = [];
2664
+ const say = (where, what) => p.push(`${source}: ${where || "the principals file"} ${what}`);
2665
+ if (!isObject(raw)) {
2666
+ say("", "must be object");
2667
+ return p;
2668
+ }
2669
+ for (const key of Object.keys(raw))
2670
+ if (extra(key, ["$schema", "$comment", "schema", "classes"]))
2671
+ say("", `must NOT have additional property ${key}`);
2672
+ for (const key of ["$schema", "$comment"])
2673
+ if (key in raw && typeof raw[key] !== "string")
2674
+ say(`/${key}`, "must be string");
2675
+ if (!("schema" in raw))
2676
+ say("", "must have required property 'schema'");
2677
+ else if (raw.schema !== 1)
2678
+ say("/schema", "must be equal to constant 1");
2679
+ if (!("classes" in raw))
2680
+ say("", "must have required property 'classes'");
2681
+ else if (!Array.isArray(raw.classes))
2682
+ say("/classes", "must be array");
2683
+ else {
2684
+ if (raw.classes.length < 1)
2685
+ say("/classes", "must NOT have fewer than 1 items");
2686
+ raw.classes.forEach((c, i) => {
2687
+ const at = `/classes/${i}`;
2688
+ if (!isObject(c))
2689
+ return say(at, "must be object");
2690
+ for (const key of Object.keys(c))
2691
+ if (extra(key, ["name", "description", "role"]))
2692
+ say(at, `must NOT have additional property ${key}`);
2693
+ for (const key of ["name", "description", "role"])
2694
+ if (!(key in c))
2695
+ say(at, `must have required property '${key}'`);
2696
+ if ("name" in c && (typeof c.name !== "string" || !NAME.test(c.name)))
2697
+ say(`${at}/name`, "must be a class name");
2698
+ if ("description" in c && (typeof c.description !== "string" || [...c.description].length < 1))
2699
+ say(`${at}/description`, "must be a non-empty string");
2700
+ if ("role" in c && (typeof c.role !== "string" || !ROLE.test(c.role)))
2701
+ say(`${at}/role`, "must be a role name");
2702
+ });
2703
+ }
2704
+ return [...new Set(p)];
2705
+ }
2706
+ var CORE_ROLES = new Set(CORE_CLASSES.map((c) => c.role).filter((r) => r !== null));
2707
+ function checkClassData(valid, source) {
2708
+ const problems = [];
2709
+ const classes = [];
2710
+ const names = /* @__PURE__ */ new Set();
2711
+ const roles = /* @__PURE__ */ new Set();
2712
+ for (const c of valid.classes) {
2713
+ if (CORE_PRINCIPAL_CLASSES.includes(c.name)) {
2714
+ problems.push(`${source}: class ${c.name} is a core class and can't be supplied by a package`);
2715
+ continue;
2716
+ }
2717
+ if (CORE_ROLES.has(c.role)) {
2718
+ problems.push(`${source}: class ${c.name} names the role ${c.role}, which puts a principal in the core ${c.role} class`);
2719
+ continue;
2720
+ }
2721
+ if (names.has(c.name)) {
2722
+ problems.push(`${source}: class ${c.name} is listed twice`);
2723
+ continue;
2724
+ }
2725
+ if (roles.has(c.role)) {
2726
+ problems.push(`${source}: class ${c.name} names the role ${c.role}, which another class in the file names; a role puts a principal in one class`);
2727
+ continue;
2728
+ }
2729
+ names.add(c.name);
2730
+ roles.add(c.role);
2731
+ classes.push({ name: c.name, description: c.description, role: c.role, source });
2732
+ }
2733
+ return { classes, problems };
2734
+ }
2735
+ function parseClassDataByHand(text, source) {
2736
+ let raw;
2737
+ try {
2738
+ raw = JSON.parse(text);
2739
+ } catch (err) {
2740
+ return { classes: [], problems: [`${source}: the principals file is not JSON (${err.message})`] };
2741
+ }
2742
+ const problems = classDataShapeProblems(raw, source);
2743
+ return problems.length > 0 ? { classes: [], problems } : checkClassData(raw, source);
2744
+ }
2745
+ function readClassFiles(files, source, parse) {
2746
+ const manifest = files("package.json");
2747
+ if (manifest === void 0)
2748
+ return { classes: [], problems: [`${source}: no readable package.json`] };
2749
+ let pkg;
2750
+ try {
2751
+ pkg = JSON.parse(manifest);
2752
+ } catch {
2753
+ return { classes: [], problems: [`${source}: package.json is not JSON`] };
2754
+ }
2755
+ const target = dataExportTarget(pkg, PRINCIPALS_SUBPATH);
2756
+ if (target === void 0)
2757
+ return { classes: [], problems: [] };
2758
+ if (typeof target !== "string")
2759
+ return { classes: [], problems: [`${source}: ${target.problem}`] };
2760
+ const inside = posix.normalize(target.slice(2));
2761
+ if (inside.startsWith("../") || inside === "..")
2762
+ return { classes: [], problems: [`${source}: exports["${PRINCIPALS_SUBPATH}"] points outside the package`] };
2763
+ const text = files(inside);
2764
+ if (text === void 0)
2765
+ return { classes: [], problems: [`${source}: exports["${PRINCIPALS_SUBPATH}"] names ${target}, which does not exist`] };
2766
+ return parse(text, source);
2767
+ }
2768
+ function mergePinClasses(reads) {
2769
+ const problems = [];
2770
+ const extra2 = [];
2771
+ const byName = /* @__PURE__ */ new Map();
2772
+ const byRole = /* @__PURE__ */ new Map();
2773
+ const clashing = /* @__PURE__ */ new Set();
2774
+ for (const { pin: i, source, read } of reads) {
2775
+ for (const p of read.problems)
2776
+ problems.push({ pin: i, message: p });
2777
+ for (const c of read.classes) {
2778
+ const named = byName.get(c.name);
2779
+ const roled = byRole.get(c.role);
2780
+ if (named !== void 0 || roled !== void 0) {
2781
+ clashing.add(c.name);
2782
+ if (named !== void 0) {
2783
+ problems.push({ pin: i, message: `class ${c.name} is supplied by both ${named} and ${source}; a class name has one source` });
2784
+ } else {
2785
+ const other = extra2.find((e) => e.role === c.role);
2786
+ clashing.add(other.name);
2787
+ problems.push({ pin: i, message: `class ${c.name} (${source}) names the role ${c.role}, which class ${other.name} (${roled}) names; a role puts a principal in one class` });
2788
+ }
2789
+ continue;
2790
+ }
2791
+ byName.set(c.name, source);
2792
+ byRole.set(c.role, source);
2793
+ extra2.push(c);
2794
+ }
2795
+ }
2796
+ return { classes: extra2.filter((c) => !clashing.has(c.name)), problems };
2797
+ }
2798
+
2799
+ export {
2800
+ gateSealRefusal,
2801
+ pointerToken,
2802
+ parseJsonText,
2803
+ CORE_CLASSES,
2804
+ admitApprover,
2805
+ diskFiles,
2806
+ findInstalledPackage,
2807
+ parseClassDataByHand,
2808
+ readClassFiles,
2809
+ mergePinClasses,
2810
+ quorumProblems,
2811
+ gateBaseApprovalProblems,
2812
+ notifyConfigProblem,
2813
+ activeProductWords,
2814
+ isChantWords,
2815
+ overrideLine,
2816
+ GATE_APPROVAL_SOURCES,
2817
+ assertPrLoopHooks,
2818
+ require_picomatch2 as require_picomatch,
2819
+ loadAjv2020
2820
+ };