opencode-swarm 7.82.2 → 7.84.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.
Files changed (58) hide show
  1. package/README.md +3 -1
  2. package/dist/cli/capability-probe-jevmgwmf.js +18 -0
  3. package/dist/cli/config-doctor-4tcdd9vt.js +35 -0
  4. package/dist/cli/dispatch-k86d928w.js +477 -0
  5. package/dist/cli/evidence-summary-service-g2znnd33.js +320 -0
  6. package/dist/cli/explorer-gz70sm9b.js +16 -0
  7. package/dist/cli/gate-evidence-y8zn7fe2.js +29 -0
  8. package/dist/cli/guardrail-explain-tcamcdfy.js +30 -0
  9. package/dist/cli/guardrail-log-fd14n96q.js +15 -0
  10. package/dist/cli/index-293f68mj.js +13538 -0
  11. package/dist/cli/index-8ra2qpk8.js +29027 -0
  12. package/dist/cli/index-a76rekgs.js +67 -0
  13. package/dist/cli/index-a82d6d87.js +1241 -0
  14. package/dist/cli/index-b9v501fr.js +371 -0
  15. package/dist/cli/index-bcp79s17.js +1673 -0
  16. package/dist/cli/index-ckntc5gf.js +91 -0
  17. package/dist/cli/index-d9fbxaqd.js +2314 -0
  18. package/dist/cli/index-e7h9bb6v.js +233 -0
  19. package/dist/cli/index-e8pk68cc.js +540 -0
  20. package/dist/cli/index-eb85wtx9.js +242 -0
  21. package/dist/cli/index-f8r50m3h.js +14505 -0
  22. package/dist/cli/index-fjwwrwr5.js +37 -0
  23. package/dist/cli/index-hz59hg4h.js +452 -0
  24. package/dist/cli/index-j710h2ge.js +412 -0
  25. package/dist/cli/index-jfgr5gye.js +110 -0
  26. package/dist/cli/index-jtqkh8jf.js +119 -0
  27. package/dist/cli/index-p0arc26j.js +28 -0
  28. package/dist/cli/index-p0ye10nd.js +222 -0
  29. package/dist/cli/index-pv2xmc9k.js +2391 -0
  30. package/dist/cli/index-red8fm8p.js +2914 -0
  31. package/dist/cli/index-wg3r6acj.js +2042 -0
  32. package/dist/cli/index-xw0bcy0v.js +583 -0
  33. package/dist/cli/index-yhsmmv2z.js +339 -0
  34. package/dist/cli/index-yx44zd0p.js +40 -0
  35. package/dist/cli/index-zfsbaaqh.js +29 -0
  36. package/dist/cli/index.js +73 -69703
  37. package/dist/cli/knowledge-store-n4x6zyk7.js +73 -0
  38. package/dist/cli/pending-delegations-pz61mrsz.js +255 -0
  39. package/dist/cli/pr-subscriptions-y1nn36e5.js +33 -0
  40. package/dist/cli/schema-c2dbzhm8.js +168 -0
  41. package/dist/cli/skill-generator-a5ehggyg.js +55 -0
  42. package/dist/cli/task-envelope-qn0qtnh0.js +90 -0
  43. package/dist/cli/telemetry-9bbyxrvn.js +20 -0
  44. package/dist/cli/workspace-snapshot-w58jr2ga.js +90 -0
  45. package/dist/commands/guardrail-explain.d.ts +1 -0
  46. package/dist/commands/guardrail-log.d.ts +1 -0
  47. package/dist/commands/index.d.ts +2 -0
  48. package/dist/commands/registry.d.ts +14 -0
  49. package/dist/config/index.d.ts +2 -2
  50. package/dist/config/schema.d.ts +7 -0
  51. package/dist/hooks/guardrails/audit-log.d.ts +114 -0
  52. package/dist/hooks/repo-graph-builder.d.ts +4 -1
  53. package/dist/index.js +3615 -2378
  54. package/dist/services/diagnose-service.d.ts +5 -0
  55. package/dist/services/guardrail-explain-service.d.ts +42 -0
  56. package/dist/services/guardrail-log-service.d.ts +10 -0
  57. package/dist/tools/repo-graph/types.d.ts +6 -0
  58. package/package.json +2 -2
@@ -0,0 +1,2391 @@
1
+ // @bun
2
+ import {
3
+ stripKnownSwarmPrefix
4
+ } from "./index-wg3r6acj.js";
5
+ import {
6
+ init_logger,
7
+ warn
8
+ } from "./index-yx44zd0p.js";
9
+ import {
10
+ __commonJS,
11
+ __toESM
12
+ } from "./index-a76rekgs.js";
13
+
14
+ // node_modules/picomatch/lib/constants.js
15
+ var require_constants = __commonJS((exports, module) => {
16
+ var WIN_SLASH = "\\\\/";
17
+ var WIN_NO_SLASH = `[^${WIN_SLASH}]`;
18
+ var DEFAULT_MAX_EXTGLOB_RECURSION = 0;
19
+ var DOT_LITERAL = "\\.";
20
+ var PLUS_LITERAL = "\\+";
21
+ var QMARK_LITERAL = "\\?";
22
+ var SLASH_LITERAL = "\\/";
23
+ var ONE_CHAR = "(?=.)";
24
+ var QMARK = "[^/]";
25
+ var END_ANCHOR = `(?:${SLASH_LITERAL}|$)`;
26
+ var START_ANCHOR = `(?:^|${SLASH_LITERAL})`;
27
+ var DOTS_SLASH = `${DOT_LITERAL}{1,2}${END_ANCHOR}`;
28
+ var NO_DOT = `(?!${DOT_LITERAL})`;
29
+ var NO_DOTS = `(?!${START_ANCHOR}${DOTS_SLASH})`;
30
+ var NO_DOT_SLASH = `(?!${DOT_LITERAL}{0,1}${END_ANCHOR})`;
31
+ var NO_DOTS_SLASH = `(?!${DOTS_SLASH})`;
32
+ var QMARK_NO_DOT = `[^.${SLASH_LITERAL}]`;
33
+ var STAR = `${QMARK}*?`;
34
+ var SEP = "/";
35
+ var POSIX_CHARS = {
36
+ DOT_LITERAL,
37
+ PLUS_LITERAL,
38
+ QMARK_LITERAL,
39
+ SLASH_LITERAL,
40
+ ONE_CHAR,
41
+ QMARK,
42
+ END_ANCHOR,
43
+ DOTS_SLASH,
44
+ NO_DOT,
45
+ NO_DOTS,
46
+ NO_DOT_SLASH,
47
+ NO_DOTS_SLASH,
48
+ QMARK_NO_DOT,
49
+ STAR,
50
+ START_ANCHOR,
51
+ SEP
52
+ };
53
+ var WINDOWS_CHARS = {
54
+ ...POSIX_CHARS,
55
+ SLASH_LITERAL: `[${WIN_SLASH}]`,
56
+ QMARK: WIN_NO_SLASH,
57
+ STAR: `${WIN_NO_SLASH}*?`,
58
+ DOTS_SLASH: `${DOT_LITERAL}{1,2}(?:[${WIN_SLASH}]|$)`,
59
+ NO_DOT: `(?!${DOT_LITERAL})`,
60
+ NO_DOTS: `(?!(?:^|[${WIN_SLASH}])${DOT_LITERAL}{1,2}(?:[${WIN_SLASH}]|$))`,
61
+ NO_DOT_SLASH: `(?!${DOT_LITERAL}{0,1}(?:[${WIN_SLASH}]|$))`,
62
+ NO_DOTS_SLASH: `(?!${DOT_LITERAL}{1,2}(?:[${WIN_SLASH}]|$))`,
63
+ QMARK_NO_DOT: `[^.${WIN_SLASH}]`,
64
+ START_ANCHOR: `(?:^|[${WIN_SLASH}])`,
65
+ END_ANCHOR: `(?:[${WIN_SLASH}]|$)`,
66
+ SEP: "\\"
67
+ };
68
+ var POSIX_REGEX_SOURCE = {
69
+ __proto__: null,
70
+ alnum: "a-zA-Z0-9",
71
+ alpha: "a-zA-Z",
72
+ ascii: "\\x00-\\x7F",
73
+ blank: " \\t",
74
+ cntrl: "\\x00-\\x1F\\x7F",
75
+ digit: "0-9",
76
+ graph: "\\x21-\\x7E",
77
+ lower: "a-z",
78
+ print: "\\x20-\\x7E ",
79
+ punct: "\\-!\"#$%&'()\\*+,./:;<=>?@[\\]^_`{|}~",
80
+ space: " \\t\\r\\n\\v\\f",
81
+ upper: "A-Z",
82
+ word: "A-Za-z0-9_",
83
+ xdigit: "A-Fa-f0-9"
84
+ };
85
+ module.exports = {
86
+ DEFAULT_MAX_EXTGLOB_RECURSION,
87
+ MAX_LENGTH: 1024 * 64,
88
+ POSIX_REGEX_SOURCE,
89
+ REGEX_BACKSLASH: /\\(?![*+?^${}(|)[\]])/g,
90
+ REGEX_NON_SPECIAL_CHARS: /^[^@![\].,$*+?^{}()|\\/]+/,
91
+ REGEX_SPECIAL_CHARS: /[-*+?.^${}(|)[\]]/,
92
+ REGEX_SPECIAL_CHARS_BACKREF: /(\\?)((\W)(\3*))/g,
93
+ REGEX_SPECIAL_CHARS_GLOBAL: /([-*+?.^${}(|)[\]])/g,
94
+ REGEX_REMOVE_BACKSLASH: /(?:\[.*?[^\\]\]|\\(?=.))/g,
95
+ REPLACEMENTS: {
96
+ __proto__: null,
97
+ "***": "*",
98
+ "**/**": "**",
99
+ "**/**/**": "**"
100
+ },
101
+ CHAR_0: 48,
102
+ CHAR_9: 57,
103
+ CHAR_UPPERCASE_A: 65,
104
+ CHAR_LOWERCASE_A: 97,
105
+ CHAR_UPPERCASE_Z: 90,
106
+ CHAR_LOWERCASE_Z: 122,
107
+ CHAR_LEFT_PARENTHESES: 40,
108
+ CHAR_RIGHT_PARENTHESES: 41,
109
+ CHAR_ASTERISK: 42,
110
+ CHAR_AMPERSAND: 38,
111
+ CHAR_AT: 64,
112
+ CHAR_BACKWARD_SLASH: 92,
113
+ CHAR_CARRIAGE_RETURN: 13,
114
+ CHAR_CIRCUMFLEX_ACCENT: 94,
115
+ CHAR_COLON: 58,
116
+ CHAR_COMMA: 44,
117
+ CHAR_DOT: 46,
118
+ CHAR_DOUBLE_QUOTE: 34,
119
+ CHAR_EQUAL: 61,
120
+ CHAR_EXCLAMATION_MARK: 33,
121
+ CHAR_FORM_FEED: 12,
122
+ CHAR_FORWARD_SLASH: 47,
123
+ CHAR_GRAVE_ACCENT: 96,
124
+ CHAR_HASH: 35,
125
+ CHAR_HYPHEN_MINUS: 45,
126
+ CHAR_LEFT_ANGLE_BRACKET: 60,
127
+ CHAR_LEFT_CURLY_BRACE: 123,
128
+ CHAR_LEFT_SQUARE_BRACKET: 91,
129
+ CHAR_LINE_FEED: 10,
130
+ CHAR_NO_BREAK_SPACE: 160,
131
+ CHAR_PERCENT: 37,
132
+ CHAR_PLUS: 43,
133
+ CHAR_QUESTION_MARK: 63,
134
+ CHAR_RIGHT_ANGLE_BRACKET: 62,
135
+ CHAR_RIGHT_CURLY_BRACE: 125,
136
+ CHAR_RIGHT_SQUARE_BRACKET: 93,
137
+ CHAR_SEMICOLON: 59,
138
+ CHAR_SINGLE_QUOTE: 39,
139
+ CHAR_SPACE: 32,
140
+ CHAR_TAB: 9,
141
+ CHAR_UNDERSCORE: 95,
142
+ CHAR_VERTICAL_LINE: 124,
143
+ CHAR_ZERO_WIDTH_NOBREAK_SPACE: 65279,
144
+ extglobChars(chars) {
145
+ return {
146
+ "!": { type: "negate", open: "(?:(?!(?:", close: `))${chars.STAR})` },
147
+ "?": { type: "qmark", open: "(?:", close: ")?" },
148
+ "+": { type: "plus", open: "(?:", close: ")+" },
149
+ "*": { type: "star", open: "(?:", close: ")*" },
150
+ "@": { type: "at", open: "(?:", close: ")" }
151
+ };
152
+ },
153
+ globChars(win32) {
154
+ return win32 === true ? WINDOWS_CHARS : POSIX_CHARS;
155
+ }
156
+ };
157
+ });
158
+
159
+ // node_modules/picomatch/lib/utils.js
160
+ var require_utils = __commonJS((exports) => {
161
+ var {
162
+ REGEX_BACKSLASH,
163
+ REGEX_REMOVE_BACKSLASH,
164
+ REGEX_SPECIAL_CHARS,
165
+ REGEX_SPECIAL_CHARS_GLOBAL
166
+ } = require_constants();
167
+ exports.isObject = (val) => val !== null && typeof val === "object" && !Array.isArray(val);
168
+ exports.hasRegexChars = (str) => REGEX_SPECIAL_CHARS.test(str);
169
+ exports.isRegexChar = (str) => str.length === 1 && exports.hasRegexChars(str);
170
+ exports.escapeRegex = (str) => str.replace(REGEX_SPECIAL_CHARS_GLOBAL, "\\$1");
171
+ exports.toPosixSlashes = (str) => str.replace(REGEX_BACKSLASH, "/");
172
+ exports.isWindows = () => {
173
+ if (typeof navigator !== "undefined" && navigator.platform) {
174
+ const platform = navigator.platform.toLowerCase();
175
+ return platform === "win32" || platform === "windows";
176
+ }
177
+ if (typeof process !== "undefined" && process.platform) {
178
+ return process.platform === "win32";
179
+ }
180
+ return false;
181
+ };
182
+ exports.removeBackslashes = (str) => {
183
+ return str.replace(REGEX_REMOVE_BACKSLASH, (match) => {
184
+ return match === "\\" ? "" : match;
185
+ });
186
+ };
187
+ exports.escapeLast = (input, char, lastIdx) => {
188
+ const idx = input.lastIndexOf(char, lastIdx);
189
+ if (idx === -1)
190
+ return input;
191
+ if (input[idx - 1] === "\\")
192
+ return exports.escapeLast(input, char, idx - 1);
193
+ return `${input.slice(0, idx)}\\${input.slice(idx)}`;
194
+ };
195
+ exports.removePrefix = (input, state = {}) => {
196
+ let output = input;
197
+ if (output.startsWith("./")) {
198
+ output = output.slice(2);
199
+ state.prefix = "./";
200
+ }
201
+ return output;
202
+ };
203
+ exports.wrapOutput = (input, state = {}, options = {}) => {
204
+ const prepend = options.contains ? "" : "^";
205
+ const append = options.contains ? "" : "$";
206
+ let output = `${prepend}(?:${input})${append}`;
207
+ if (state.negated === true) {
208
+ output = `(?:^(?!${output}).*$)`;
209
+ }
210
+ return output;
211
+ };
212
+ exports.basename = (path, { windows } = {}) => {
213
+ const segs = path.split(windows ? /[\\/]/ : "/");
214
+ const last = segs[segs.length - 1];
215
+ if (last === "") {
216
+ return segs[segs.length - 2];
217
+ }
218
+ return last;
219
+ };
220
+ });
221
+
222
+ // node_modules/picomatch/lib/scan.js
223
+ var require_scan = __commonJS((exports, module) => {
224
+ var utils = require_utils();
225
+ var {
226
+ CHAR_ASTERISK,
227
+ CHAR_AT,
228
+ CHAR_BACKWARD_SLASH,
229
+ CHAR_COMMA,
230
+ CHAR_DOT,
231
+ CHAR_EXCLAMATION_MARK,
232
+ CHAR_FORWARD_SLASH,
233
+ CHAR_LEFT_CURLY_BRACE,
234
+ CHAR_LEFT_PARENTHESES,
235
+ CHAR_LEFT_SQUARE_BRACKET,
236
+ CHAR_PLUS,
237
+ CHAR_QUESTION_MARK,
238
+ CHAR_RIGHT_CURLY_BRACE,
239
+ CHAR_RIGHT_PARENTHESES,
240
+ CHAR_RIGHT_SQUARE_BRACKET
241
+ } = require_constants();
242
+ var isPathSeparator = (code) => {
243
+ return code === CHAR_FORWARD_SLASH || code === CHAR_BACKWARD_SLASH;
244
+ };
245
+ var depth = (token) => {
246
+ if (token.isPrefix !== true) {
247
+ token.depth = token.isGlobstar ? Infinity : 1;
248
+ }
249
+ };
250
+ var scan = (input, options) => {
251
+ const opts = options || {};
252
+ const length = input.length - 1;
253
+ const scanToEnd = opts.parts === true || opts.scanToEnd === true;
254
+ const slashes = [];
255
+ const tokens = [];
256
+ const parts = [];
257
+ let str = input;
258
+ let index = -1;
259
+ let start = 0;
260
+ let lastIndex = 0;
261
+ let isBrace = false;
262
+ let isBracket = false;
263
+ let isGlob = false;
264
+ let isExtglob = false;
265
+ let isGlobstar = false;
266
+ let braceEscaped = false;
267
+ let backslashes = false;
268
+ let negated = false;
269
+ let negatedExtglob = false;
270
+ let finished = false;
271
+ let braces = 0;
272
+ let prev;
273
+ let code;
274
+ let token = { value: "", depth: 0, isGlob: false };
275
+ const eos = () => index >= length;
276
+ const peek = () => str.charCodeAt(index + 1);
277
+ const advance = () => {
278
+ prev = code;
279
+ return str.charCodeAt(++index);
280
+ };
281
+ while (index < length) {
282
+ code = advance();
283
+ let next;
284
+ if (code === CHAR_BACKWARD_SLASH) {
285
+ backslashes = token.backslashes = true;
286
+ code = advance();
287
+ if (code === CHAR_LEFT_CURLY_BRACE) {
288
+ braceEscaped = true;
289
+ }
290
+ continue;
291
+ }
292
+ if (braceEscaped === true || code === CHAR_LEFT_CURLY_BRACE) {
293
+ braces++;
294
+ while (eos() !== true && (code = advance())) {
295
+ if (code === CHAR_BACKWARD_SLASH) {
296
+ backslashes = token.backslashes = true;
297
+ advance();
298
+ continue;
299
+ }
300
+ if (code === CHAR_LEFT_CURLY_BRACE) {
301
+ braces++;
302
+ continue;
303
+ }
304
+ if (braceEscaped !== true && code === CHAR_DOT && (code = advance()) === CHAR_DOT) {
305
+ isBrace = token.isBrace = true;
306
+ isGlob = token.isGlob = true;
307
+ finished = true;
308
+ if (scanToEnd === true) {
309
+ continue;
310
+ }
311
+ break;
312
+ }
313
+ if (braceEscaped !== true && code === CHAR_COMMA) {
314
+ isBrace = token.isBrace = true;
315
+ isGlob = token.isGlob = true;
316
+ finished = true;
317
+ if (scanToEnd === true) {
318
+ continue;
319
+ }
320
+ break;
321
+ }
322
+ if (code === CHAR_RIGHT_CURLY_BRACE) {
323
+ braces--;
324
+ if (braces === 0) {
325
+ braceEscaped = false;
326
+ isBrace = token.isBrace = true;
327
+ finished = true;
328
+ break;
329
+ }
330
+ }
331
+ }
332
+ if (scanToEnd === true) {
333
+ continue;
334
+ }
335
+ break;
336
+ }
337
+ if (code === CHAR_FORWARD_SLASH) {
338
+ slashes.push(index);
339
+ tokens.push(token);
340
+ token = { value: "", depth: 0, isGlob: false };
341
+ if (finished === true)
342
+ continue;
343
+ if (prev === CHAR_DOT && index === start + 1) {
344
+ start += 2;
345
+ continue;
346
+ }
347
+ lastIndex = index + 1;
348
+ continue;
349
+ }
350
+ if (opts.noext !== true) {
351
+ const isExtglobChar = code === CHAR_PLUS || code === CHAR_AT || code === CHAR_ASTERISK || code === CHAR_QUESTION_MARK || code === CHAR_EXCLAMATION_MARK;
352
+ if (isExtglobChar === true && peek() === CHAR_LEFT_PARENTHESES) {
353
+ isGlob = token.isGlob = true;
354
+ isExtglob = token.isExtglob = true;
355
+ finished = true;
356
+ if (code === CHAR_EXCLAMATION_MARK && index === start) {
357
+ negatedExtglob = true;
358
+ }
359
+ if (scanToEnd === true) {
360
+ while (eos() !== true && (code = advance())) {
361
+ if (code === CHAR_BACKWARD_SLASH) {
362
+ backslashes = token.backslashes = true;
363
+ code = advance();
364
+ continue;
365
+ }
366
+ if (code === CHAR_RIGHT_PARENTHESES) {
367
+ isGlob = token.isGlob = true;
368
+ finished = true;
369
+ break;
370
+ }
371
+ }
372
+ continue;
373
+ }
374
+ break;
375
+ }
376
+ }
377
+ if (code === CHAR_ASTERISK) {
378
+ if (prev === CHAR_ASTERISK)
379
+ isGlobstar = token.isGlobstar = true;
380
+ isGlob = token.isGlob = true;
381
+ finished = true;
382
+ if (scanToEnd === true) {
383
+ continue;
384
+ }
385
+ break;
386
+ }
387
+ if (code === CHAR_QUESTION_MARK) {
388
+ isGlob = token.isGlob = true;
389
+ finished = true;
390
+ if (scanToEnd === true) {
391
+ continue;
392
+ }
393
+ break;
394
+ }
395
+ if (code === CHAR_LEFT_SQUARE_BRACKET) {
396
+ while (eos() !== true && (next = advance())) {
397
+ if (next === CHAR_BACKWARD_SLASH) {
398
+ backslashes = token.backslashes = true;
399
+ advance();
400
+ continue;
401
+ }
402
+ if (next === CHAR_RIGHT_SQUARE_BRACKET) {
403
+ isBracket = token.isBracket = true;
404
+ isGlob = token.isGlob = true;
405
+ finished = true;
406
+ break;
407
+ }
408
+ }
409
+ if (scanToEnd === true) {
410
+ continue;
411
+ }
412
+ break;
413
+ }
414
+ if (opts.nonegate !== true && code === CHAR_EXCLAMATION_MARK && index === start) {
415
+ negated = token.negated = true;
416
+ start++;
417
+ continue;
418
+ }
419
+ if (opts.noparen !== true && code === CHAR_LEFT_PARENTHESES) {
420
+ isGlob = token.isGlob = true;
421
+ if (scanToEnd === true) {
422
+ while (eos() !== true && (code = advance())) {
423
+ if (code === CHAR_LEFT_PARENTHESES) {
424
+ backslashes = token.backslashes = true;
425
+ code = advance();
426
+ continue;
427
+ }
428
+ if (code === CHAR_RIGHT_PARENTHESES) {
429
+ finished = true;
430
+ break;
431
+ }
432
+ }
433
+ continue;
434
+ }
435
+ break;
436
+ }
437
+ if (isGlob === true) {
438
+ finished = true;
439
+ if (scanToEnd === true) {
440
+ continue;
441
+ }
442
+ break;
443
+ }
444
+ }
445
+ if (opts.noext === true) {
446
+ isExtglob = false;
447
+ isGlob = false;
448
+ }
449
+ let base = str;
450
+ let prefix = "";
451
+ let glob = "";
452
+ if (start > 0) {
453
+ prefix = str.slice(0, start);
454
+ str = str.slice(start);
455
+ lastIndex -= start;
456
+ }
457
+ if (base && isGlob === true && lastIndex > 0) {
458
+ base = str.slice(0, lastIndex);
459
+ glob = str.slice(lastIndex);
460
+ } else if (isGlob === true) {
461
+ base = "";
462
+ glob = str;
463
+ } else {
464
+ base = str;
465
+ }
466
+ if (base && base !== "" && base !== "/" && base !== str) {
467
+ if (isPathSeparator(base.charCodeAt(base.length - 1))) {
468
+ base = base.slice(0, -1);
469
+ }
470
+ }
471
+ if (opts.unescape === true) {
472
+ if (glob)
473
+ glob = utils.removeBackslashes(glob);
474
+ if (base && backslashes === true) {
475
+ base = utils.removeBackslashes(base);
476
+ }
477
+ }
478
+ const state = {
479
+ prefix,
480
+ input,
481
+ start,
482
+ base,
483
+ glob,
484
+ isBrace,
485
+ isBracket,
486
+ isGlob,
487
+ isExtglob,
488
+ isGlobstar,
489
+ negated,
490
+ negatedExtglob
491
+ };
492
+ if (opts.tokens === true) {
493
+ state.maxDepth = 0;
494
+ if (!isPathSeparator(code)) {
495
+ tokens.push(token);
496
+ }
497
+ state.tokens = tokens;
498
+ }
499
+ if (opts.parts === true || opts.tokens === true) {
500
+ let prevIndex;
501
+ for (let idx = 0;idx < slashes.length; idx++) {
502
+ const n = prevIndex ? prevIndex + 1 : start;
503
+ const i = slashes[idx];
504
+ const value = input.slice(n, i);
505
+ if (opts.tokens) {
506
+ if (idx === 0 && start !== 0) {
507
+ tokens[idx].isPrefix = true;
508
+ tokens[idx].value = prefix;
509
+ } else {
510
+ tokens[idx].value = value;
511
+ }
512
+ depth(tokens[idx]);
513
+ state.maxDepth += tokens[idx].depth;
514
+ }
515
+ if (idx !== 0 || value !== "") {
516
+ parts.push(value);
517
+ }
518
+ prevIndex = i;
519
+ }
520
+ if (prevIndex && prevIndex + 1 < input.length) {
521
+ const value = input.slice(prevIndex + 1);
522
+ parts.push(value);
523
+ if (opts.tokens) {
524
+ tokens[tokens.length - 1].value = value;
525
+ depth(tokens[tokens.length - 1]);
526
+ state.maxDepth += tokens[tokens.length - 1].depth;
527
+ }
528
+ }
529
+ state.slashes = slashes;
530
+ state.parts = parts;
531
+ }
532
+ return state;
533
+ };
534
+ module.exports = scan;
535
+ });
536
+
537
+ // node_modules/picomatch/lib/parse.js
538
+ var require_parse = __commonJS((exports, module) => {
539
+ var constants = require_constants();
540
+ var utils = require_utils();
541
+ var {
542
+ MAX_LENGTH,
543
+ POSIX_REGEX_SOURCE,
544
+ REGEX_NON_SPECIAL_CHARS,
545
+ REGEX_SPECIAL_CHARS_BACKREF,
546
+ REPLACEMENTS
547
+ } = constants;
548
+ var expandRange = (args, options) => {
549
+ if (typeof options.expandRange === "function") {
550
+ return options.expandRange(...args, options);
551
+ }
552
+ args.sort();
553
+ const value = `[${args.join("-")}]`;
554
+ try {
555
+ new RegExp(value);
556
+ } catch (ex) {
557
+ return args.map((v) => utils.escapeRegex(v)).join("..");
558
+ }
559
+ return value;
560
+ };
561
+ var syntaxError = (type, char) => {
562
+ return `Missing ${type}: "${char}" - use "\\\\${char}" to match literal characters`;
563
+ };
564
+ var splitTopLevel = (input) => {
565
+ const parts = [];
566
+ let bracket = 0;
567
+ let paren = 0;
568
+ let quote = 0;
569
+ let value = "";
570
+ let escaped = false;
571
+ for (const ch of input) {
572
+ if (escaped === true) {
573
+ value += ch;
574
+ escaped = false;
575
+ continue;
576
+ }
577
+ if (ch === "\\") {
578
+ value += ch;
579
+ escaped = true;
580
+ continue;
581
+ }
582
+ if (ch === '"') {
583
+ quote = quote === 1 ? 0 : 1;
584
+ value += ch;
585
+ continue;
586
+ }
587
+ if (quote === 0) {
588
+ if (ch === "[") {
589
+ bracket++;
590
+ } else if (ch === "]" && bracket > 0) {
591
+ bracket--;
592
+ } else if (bracket === 0) {
593
+ if (ch === "(") {
594
+ paren++;
595
+ } else if (ch === ")" && paren > 0) {
596
+ paren--;
597
+ } else if (ch === "|" && paren === 0) {
598
+ parts.push(value);
599
+ value = "";
600
+ continue;
601
+ }
602
+ }
603
+ }
604
+ value += ch;
605
+ }
606
+ parts.push(value);
607
+ return parts;
608
+ };
609
+ var isPlainBranch = (branch) => {
610
+ let escaped = false;
611
+ for (const ch of branch) {
612
+ if (escaped === true) {
613
+ escaped = false;
614
+ continue;
615
+ }
616
+ if (ch === "\\") {
617
+ escaped = true;
618
+ continue;
619
+ }
620
+ if (/[?*+@!()[\]{}]/.test(ch)) {
621
+ return false;
622
+ }
623
+ }
624
+ return true;
625
+ };
626
+ var normalizeSimpleBranch = (branch) => {
627
+ let value = branch.trim();
628
+ let changed = true;
629
+ while (changed === true) {
630
+ changed = false;
631
+ if (/^@\([^\\()[\]{}|]+\)$/.test(value)) {
632
+ value = value.slice(2, -1);
633
+ changed = true;
634
+ }
635
+ }
636
+ if (!isPlainBranch(value)) {
637
+ return;
638
+ }
639
+ return value.replace(/\\(.)/g, "$1");
640
+ };
641
+ var hasRepeatedCharPrefixOverlap = (branches) => {
642
+ const values = branches.map(normalizeSimpleBranch).filter(Boolean);
643
+ for (let i = 0;i < values.length; i++) {
644
+ for (let j = i + 1;j < values.length; j++) {
645
+ const a = values[i];
646
+ const b = values[j];
647
+ const char = a[0];
648
+ if (!char || a !== char.repeat(a.length) || b !== char.repeat(b.length)) {
649
+ continue;
650
+ }
651
+ if (a === b || a.startsWith(b) || b.startsWith(a)) {
652
+ return true;
653
+ }
654
+ }
655
+ }
656
+ return false;
657
+ };
658
+ var parseRepeatedExtglob = (pattern, requireEnd = true) => {
659
+ if (pattern[0] !== "+" && pattern[0] !== "*" || pattern[1] !== "(") {
660
+ return;
661
+ }
662
+ let bracket = 0;
663
+ let paren = 0;
664
+ let quote = 0;
665
+ let escaped = false;
666
+ for (let i = 1;i < pattern.length; i++) {
667
+ const ch = pattern[i];
668
+ if (escaped === true) {
669
+ escaped = false;
670
+ continue;
671
+ }
672
+ if (ch === "\\") {
673
+ escaped = true;
674
+ continue;
675
+ }
676
+ if (ch === '"') {
677
+ quote = quote === 1 ? 0 : 1;
678
+ continue;
679
+ }
680
+ if (quote === 1) {
681
+ continue;
682
+ }
683
+ if (ch === "[") {
684
+ bracket++;
685
+ continue;
686
+ }
687
+ if (ch === "]" && bracket > 0) {
688
+ bracket--;
689
+ continue;
690
+ }
691
+ if (bracket > 0) {
692
+ continue;
693
+ }
694
+ if (ch === "(") {
695
+ paren++;
696
+ continue;
697
+ }
698
+ if (ch === ")") {
699
+ paren--;
700
+ if (paren === 0) {
701
+ if (requireEnd === true && i !== pattern.length - 1) {
702
+ return;
703
+ }
704
+ return {
705
+ type: pattern[0],
706
+ body: pattern.slice(2, i),
707
+ end: i
708
+ };
709
+ }
710
+ }
711
+ }
712
+ };
713
+ var getStarExtglobSequenceOutput = (pattern) => {
714
+ let index = 0;
715
+ const chars = [];
716
+ while (index < pattern.length) {
717
+ const match = parseRepeatedExtglob(pattern.slice(index), false);
718
+ if (!match || match.type !== "*") {
719
+ return;
720
+ }
721
+ const branches = splitTopLevel(match.body).map((branch2) => branch2.trim());
722
+ if (branches.length !== 1) {
723
+ return;
724
+ }
725
+ const branch = normalizeSimpleBranch(branches[0]);
726
+ if (!branch || branch.length !== 1) {
727
+ return;
728
+ }
729
+ chars.push(branch);
730
+ index += match.end + 1;
731
+ }
732
+ if (chars.length < 1) {
733
+ return;
734
+ }
735
+ const source = chars.length === 1 ? utils.escapeRegex(chars[0]) : `[${chars.map((ch) => utils.escapeRegex(ch)).join("")}]`;
736
+ return `${source}*`;
737
+ };
738
+ var repeatedExtglobRecursion = (pattern) => {
739
+ let depth = 0;
740
+ let value = pattern.trim();
741
+ let match = parseRepeatedExtglob(value);
742
+ while (match) {
743
+ depth++;
744
+ value = match.body.trim();
745
+ match = parseRepeatedExtglob(value);
746
+ }
747
+ return depth;
748
+ };
749
+ var analyzeRepeatedExtglob = (body, options) => {
750
+ if (options.maxExtglobRecursion === false) {
751
+ return { risky: false };
752
+ }
753
+ const max = typeof options.maxExtglobRecursion === "number" ? options.maxExtglobRecursion : constants.DEFAULT_MAX_EXTGLOB_RECURSION;
754
+ const branches = splitTopLevel(body).map((branch) => branch.trim());
755
+ if (branches.length > 1) {
756
+ if (branches.some((branch) => branch === "") || branches.some((branch) => /^[*?]+$/.test(branch)) || hasRepeatedCharPrefixOverlap(branches)) {
757
+ return { risky: true };
758
+ }
759
+ }
760
+ for (const branch of branches) {
761
+ const safeOutput = getStarExtglobSequenceOutput(branch);
762
+ if (safeOutput) {
763
+ return { risky: true, safeOutput };
764
+ }
765
+ if (repeatedExtglobRecursion(branch) > max) {
766
+ return { risky: true };
767
+ }
768
+ }
769
+ return { risky: false };
770
+ };
771
+ var parse = (input, options) => {
772
+ if (typeof input !== "string") {
773
+ throw new TypeError("Expected a string");
774
+ }
775
+ input = REPLACEMENTS[input] || input;
776
+ const opts = { ...options };
777
+ const max = typeof opts.maxLength === "number" ? Math.min(MAX_LENGTH, opts.maxLength) : MAX_LENGTH;
778
+ let len = input.length;
779
+ if (len > max) {
780
+ throw new SyntaxError(`Input length: ${len}, exceeds maximum allowed length: ${max}`);
781
+ }
782
+ const bos = { type: "bos", value: "", output: opts.prepend || "" };
783
+ const tokens = [bos];
784
+ const capture = opts.capture ? "" : "?:";
785
+ const PLATFORM_CHARS = constants.globChars(opts.windows);
786
+ const EXTGLOB_CHARS = constants.extglobChars(PLATFORM_CHARS);
787
+ const {
788
+ DOT_LITERAL,
789
+ PLUS_LITERAL,
790
+ SLASH_LITERAL,
791
+ ONE_CHAR,
792
+ DOTS_SLASH,
793
+ NO_DOT,
794
+ NO_DOT_SLASH,
795
+ NO_DOTS_SLASH,
796
+ QMARK,
797
+ QMARK_NO_DOT,
798
+ STAR,
799
+ START_ANCHOR
800
+ } = PLATFORM_CHARS;
801
+ const globstar = (opts2) => {
802
+ return `(${capture}(?:(?!${START_ANCHOR}${opts2.dot ? DOTS_SLASH : DOT_LITERAL}).)*?)`;
803
+ };
804
+ const nodot = opts.dot ? "" : NO_DOT;
805
+ const qmarkNoDot = opts.dot ? QMARK : QMARK_NO_DOT;
806
+ let star = opts.bash === true ? globstar(opts) : STAR;
807
+ if (opts.capture) {
808
+ star = `(${star})`;
809
+ }
810
+ if (typeof opts.noext === "boolean") {
811
+ opts.noextglob = opts.noext;
812
+ }
813
+ const state = {
814
+ input,
815
+ index: -1,
816
+ start: 0,
817
+ dot: opts.dot === true,
818
+ consumed: "",
819
+ output: "",
820
+ prefix: "",
821
+ backtrack: false,
822
+ negated: false,
823
+ brackets: 0,
824
+ braces: 0,
825
+ parens: 0,
826
+ quotes: 0,
827
+ globstar: false,
828
+ tokens
829
+ };
830
+ input = utils.removePrefix(input, state);
831
+ len = input.length;
832
+ const extglobs = [];
833
+ const braces = [];
834
+ const stack = [];
835
+ let prev = bos;
836
+ let value;
837
+ const eos = () => state.index === len - 1;
838
+ const peek = state.peek = (n = 1) => input[state.index + n];
839
+ const advance = state.advance = () => input[++state.index] || "";
840
+ const remaining = () => input.slice(state.index + 1);
841
+ const consume = (value2 = "", num = 0) => {
842
+ state.consumed += value2;
843
+ state.index += num;
844
+ };
845
+ const append = (token) => {
846
+ state.output += token.output != null ? token.output : token.value;
847
+ consume(token.value);
848
+ };
849
+ const negate = () => {
850
+ let count = 1;
851
+ while (peek() === "!" && (peek(2) !== "(" || peek(3) === "?")) {
852
+ advance();
853
+ state.start++;
854
+ count++;
855
+ }
856
+ if (count % 2 === 0) {
857
+ return false;
858
+ }
859
+ state.negated = true;
860
+ state.start++;
861
+ return true;
862
+ };
863
+ const increment = (type) => {
864
+ state[type]++;
865
+ stack.push(type);
866
+ };
867
+ const decrement = (type) => {
868
+ state[type]--;
869
+ stack.pop();
870
+ };
871
+ const push = (tok) => {
872
+ if (prev.type === "globstar") {
873
+ const isBrace = state.braces > 0 && (tok.type === "comma" || tok.type === "brace");
874
+ const isExtglob = tok.extglob === true || extglobs.length && (tok.type === "pipe" || tok.type === "paren");
875
+ if (tok.type !== "slash" && tok.type !== "paren" && !isBrace && !isExtglob) {
876
+ state.output = state.output.slice(0, -prev.output.length);
877
+ prev.type = "star";
878
+ prev.value = "*";
879
+ prev.output = star;
880
+ state.output += prev.output;
881
+ }
882
+ }
883
+ if (extglobs.length && tok.type !== "paren") {
884
+ extglobs[extglobs.length - 1].inner += tok.value;
885
+ }
886
+ if (tok.value || tok.output)
887
+ append(tok);
888
+ if (prev && prev.type === "text" && tok.type === "text") {
889
+ prev.output = (prev.output || prev.value) + tok.value;
890
+ prev.value += tok.value;
891
+ return;
892
+ }
893
+ tok.prev = prev;
894
+ tokens.push(tok);
895
+ prev = tok;
896
+ };
897
+ const extglobOpen = (type, value2) => {
898
+ const token = { ...EXTGLOB_CHARS[value2], conditions: 1, inner: "" };
899
+ token.prev = prev;
900
+ token.parens = state.parens;
901
+ token.output = state.output;
902
+ token.startIndex = state.index;
903
+ token.tokensIndex = tokens.length;
904
+ const output = (opts.capture ? "(" : "") + token.open;
905
+ increment("parens");
906
+ push({ type, value: value2, output: state.output ? "" : ONE_CHAR });
907
+ push({ type: "paren", extglob: true, value: advance(), output });
908
+ extglobs.push(token);
909
+ };
910
+ const extglobClose = (token) => {
911
+ const literal = input.slice(token.startIndex, state.index + 1);
912
+ const body = input.slice(token.startIndex + 2, state.index);
913
+ const analysis = analyzeRepeatedExtglob(body, opts);
914
+ if ((token.type === "plus" || token.type === "star") && analysis.risky) {
915
+ const safeOutput = analysis.safeOutput ? (token.output ? "" : ONE_CHAR) + (opts.capture ? `(${analysis.safeOutput})` : analysis.safeOutput) : undefined;
916
+ const open = tokens[token.tokensIndex];
917
+ open.type = "text";
918
+ open.value = literal;
919
+ open.output = safeOutput || utils.escapeRegex(literal);
920
+ for (let i = token.tokensIndex + 1;i < tokens.length; i++) {
921
+ tokens[i].value = "";
922
+ tokens[i].output = "";
923
+ delete tokens[i].suffix;
924
+ }
925
+ state.output = token.output + open.output;
926
+ state.backtrack = true;
927
+ push({ type: "paren", extglob: true, value, output: "" });
928
+ decrement("parens");
929
+ return;
930
+ }
931
+ let output = token.close + (opts.capture ? ")" : "");
932
+ let rest;
933
+ if (token.type === "negate") {
934
+ let extglobStar = star;
935
+ if (token.inner && token.inner.length > 1 && token.inner.includes("/")) {
936
+ extglobStar = globstar(opts);
937
+ }
938
+ if (extglobStar !== star || eos() || /^\)+$/.test(remaining())) {
939
+ output = token.close = `)$))${extglobStar}`;
940
+ }
941
+ if (token.inner.includes("*") && (rest = remaining()) && /^\.[^\\/.]+$/.test(rest)) {
942
+ const expression = parse(rest, { ...options, fastpaths: false }).output;
943
+ output = token.close = `)${expression})${extglobStar})`;
944
+ }
945
+ if (token.prev.type === "bos") {
946
+ state.negatedExtglob = true;
947
+ }
948
+ }
949
+ push({ type: "paren", extglob: true, value, output });
950
+ decrement("parens");
951
+ };
952
+ if (opts.fastpaths !== false && !/(^[*!]|[/()[\]{}"])/.test(input)) {
953
+ let backslashes = false;
954
+ let output = input.replace(REGEX_SPECIAL_CHARS_BACKREF, (m, esc, chars, first, rest, index) => {
955
+ if (first === "\\") {
956
+ backslashes = true;
957
+ return m;
958
+ }
959
+ if (first === "?") {
960
+ if (esc) {
961
+ return esc + first + (rest ? QMARK.repeat(rest.length) : "");
962
+ }
963
+ if (index === 0) {
964
+ return qmarkNoDot + (rest ? QMARK.repeat(rest.length) : "");
965
+ }
966
+ return QMARK.repeat(chars.length);
967
+ }
968
+ if (first === ".") {
969
+ return DOT_LITERAL.repeat(chars.length);
970
+ }
971
+ if (first === "*") {
972
+ if (esc) {
973
+ return esc + first + (rest ? star : "");
974
+ }
975
+ return star;
976
+ }
977
+ return esc ? m : `\\${m}`;
978
+ });
979
+ if (backslashes === true) {
980
+ if (opts.unescape === true) {
981
+ output = output.replace(/\\/g, "");
982
+ } else {
983
+ output = output.replace(/\\+/g, (m) => {
984
+ return m.length % 2 === 0 ? "\\\\" : m ? "\\" : "";
985
+ });
986
+ }
987
+ }
988
+ if (output === input && opts.contains === true) {
989
+ state.output = input;
990
+ return state;
991
+ }
992
+ state.output = utils.wrapOutput(output, state, options);
993
+ return state;
994
+ }
995
+ while (!eos()) {
996
+ value = advance();
997
+ if (value === "\x00") {
998
+ continue;
999
+ }
1000
+ if (value === "\\") {
1001
+ const next = peek();
1002
+ if (next === "/" && opts.bash !== true) {
1003
+ continue;
1004
+ }
1005
+ if (next === "." || next === ";") {
1006
+ continue;
1007
+ }
1008
+ if (!next) {
1009
+ value += "\\";
1010
+ push({ type: "text", value });
1011
+ continue;
1012
+ }
1013
+ const match = /^\\+/.exec(remaining());
1014
+ let slashes = 0;
1015
+ if (match && match[0].length > 2) {
1016
+ slashes = match[0].length;
1017
+ state.index += slashes;
1018
+ if (slashes % 2 !== 0) {
1019
+ value += "\\";
1020
+ }
1021
+ }
1022
+ if (opts.unescape === true) {
1023
+ value = advance();
1024
+ } else {
1025
+ value += advance();
1026
+ }
1027
+ if (state.brackets === 0) {
1028
+ push({ type: "text", value });
1029
+ continue;
1030
+ }
1031
+ }
1032
+ if (state.brackets > 0 && (value !== "]" || prev.value === "[" || prev.value === "[^")) {
1033
+ if (opts.posix !== false && value === ":") {
1034
+ const inner = prev.value.slice(1);
1035
+ if (inner.includes("[")) {
1036
+ prev.posix = true;
1037
+ if (inner.includes(":")) {
1038
+ const idx = prev.value.lastIndexOf("[");
1039
+ const pre = prev.value.slice(0, idx);
1040
+ const rest2 = prev.value.slice(idx + 2);
1041
+ const posix = POSIX_REGEX_SOURCE[rest2];
1042
+ if (posix) {
1043
+ prev.value = pre + posix;
1044
+ state.backtrack = true;
1045
+ advance();
1046
+ if (!bos.output && tokens.indexOf(prev) === 1) {
1047
+ bos.output = ONE_CHAR;
1048
+ }
1049
+ continue;
1050
+ }
1051
+ }
1052
+ }
1053
+ }
1054
+ if (value === "[" && peek() !== ":" || value === "-" && peek() === "]") {
1055
+ value = `\\${value}`;
1056
+ }
1057
+ if (value === "]" && (prev.value === "[" || prev.value === "[^")) {
1058
+ value = `\\${value}`;
1059
+ }
1060
+ if (opts.posix === true && value === "!" && prev.value === "[") {
1061
+ value = "^";
1062
+ }
1063
+ prev.value += value;
1064
+ append({ value });
1065
+ continue;
1066
+ }
1067
+ if (state.quotes === 1 && value !== '"') {
1068
+ value = utils.escapeRegex(value);
1069
+ prev.value += value;
1070
+ append({ value });
1071
+ continue;
1072
+ }
1073
+ if (value === '"') {
1074
+ state.quotes = state.quotes === 1 ? 0 : 1;
1075
+ if (opts.keepQuotes === true) {
1076
+ push({ type: "text", value });
1077
+ }
1078
+ continue;
1079
+ }
1080
+ if (value === "(") {
1081
+ increment("parens");
1082
+ push({ type: "paren", value });
1083
+ continue;
1084
+ }
1085
+ if (value === ")") {
1086
+ if (state.parens === 0 && opts.strictBrackets === true) {
1087
+ throw new SyntaxError(syntaxError("opening", "("));
1088
+ }
1089
+ const extglob = extglobs[extglobs.length - 1];
1090
+ if (extglob && state.parens === extglob.parens + 1) {
1091
+ extglobClose(extglobs.pop());
1092
+ continue;
1093
+ }
1094
+ push({ type: "paren", value, output: state.parens ? ")" : "\\)" });
1095
+ decrement("parens");
1096
+ continue;
1097
+ }
1098
+ if (value === "[") {
1099
+ if (opts.nobracket === true || !remaining().includes("]")) {
1100
+ if (opts.nobracket !== true && opts.strictBrackets === true) {
1101
+ throw new SyntaxError(syntaxError("closing", "]"));
1102
+ }
1103
+ value = `\\${value}`;
1104
+ } else {
1105
+ increment("brackets");
1106
+ }
1107
+ push({ type: "bracket", value });
1108
+ continue;
1109
+ }
1110
+ if (value === "]") {
1111
+ if (opts.nobracket === true || prev && prev.type === "bracket" && prev.value.length === 1) {
1112
+ push({ type: "text", value, output: `\\${value}` });
1113
+ continue;
1114
+ }
1115
+ if (state.brackets === 0) {
1116
+ if (opts.strictBrackets === true) {
1117
+ throw new SyntaxError(syntaxError("opening", "["));
1118
+ }
1119
+ push({ type: "text", value, output: `\\${value}` });
1120
+ continue;
1121
+ }
1122
+ decrement("brackets");
1123
+ const prevValue = prev.value.slice(1);
1124
+ if (prev.posix !== true && prevValue[0] === "^" && !prevValue.includes("/")) {
1125
+ value = `/${value}`;
1126
+ }
1127
+ prev.value += value;
1128
+ append({ value });
1129
+ if (opts.literalBrackets === false || utils.hasRegexChars(prevValue)) {
1130
+ continue;
1131
+ }
1132
+ const escaped = utils.escapeRegex(prev.value);
1133
+ state.output = state.output.slice(0, -prev.value.length);
1134
+ if (opts.literalBrackets === true) {
1135
+ state.output += escaped;
1136
+ prev.value = escaped;
1137
+ continue;
1138
+ }
1139
+ prev.value = `(${capture}${escaped}|${prev.value})`;
1140
+ state.output += prev.value;
1141
+ continue;
1142
+ }
1143
+ if (value === "{" && opts.nobrace !== true) {
1144
+ increment("braces");
1145
+ const open = {
1146
+ type: "brace",
1147
+ value,
1148
+ output: "(",
1149
+ outputIndex: state.output.length,
1150
+ tokensIndex: state.tokens.length
1151
+ };
1152
+ braces.push(open);
1153
+ push(open);
1154
+ continue;
1155
+ }
1156
+ if (value === "}") {
1157
+ const brace = braces[braces.length - 1];
1158
+ if (opts.nobrace === true || !brace) {
1159
+ push({ type: "text", value, output: value });
1160
+ continue;
1161
+ }
1162
+ let output = ")";
1163
+ if (brace.dots === true) {
1164
+ const arr = tokens.slice();
1165
+ const range = [];
1166
+ for (let i = arr.length - 1;i >= 0; i--) {
1167
+ tokens.pop();
1168
+ if (arr[i].type === "brace") {
1169
+ break;
1170
+ }
1171
+ if (arr[i].type !== "dots") {
1172
+ range.unshift(arr[i].value);
1173
+ }
1174
+ }
1175
+ output = expandRange(range, opts);
1176
+ state.backtrack = true;
1177
+ }
1178
+ if (brace.comma !== true && brace.dots !== true) {
1179
+ const out = state.output.slice(0, brace.outputIndex);
1180
+ const toks = state.tokens.slice(brace.tokensIndex);
1181
+ brace.value = brace.output = "\\{";
1182
+ value = output = "\\}";
1183
+ state.output = out;
1184
+ for (const t of toks) {
1185
+ state.output += t.output || t.value;
1186
+ }
1187
+ }
1188
+ push({ type: "brace", value, output });
1189
+ decrement("braces");
1190
+ braces.pop();
1191
+ continue;
1192
+ }
1193
+ if (value === "|") {
1194
+ if (extglobs.length > 0) {
1195
+ extglobs[extglobs.length - 1].conditions++;
1196
+ }
1197
+ push({ type: "text", value });
1198
+ continue;
1199
+ }
1200
+ if (value === ",") {
1201
+ let output = value;
1202
+ const brace = braces[braces.length - 1];
1203
+ if (brace && stack[stack.length - 1] === "braces") {
1204
+ brace.comma = true;
1205
+ output = "|";
1206
+ }
1207
+ push({ type: "comma", value, output });
1208
+ continue;
1209
+ }
1210
+ if (value === "/") {
1211
+ if (prev.type === "dot" && state.index === state.start + 1) {
1212
+ state.start = state.index + 1;
1213
+ state.consumed = "";
1214
+ state.output = "";
1215
+ tokens.pop();
1216
+ prev = bos;
1217
+ continue;
1218
+ }
1219
+ push({ type: "slash", value, output: SLASH_LITERAL });
1220
+ continue;
1221
+ }
1222
+ if (value === ".") {
1223
+ if (state.braces > 0 && prev.type === "dot") {
1224
+ if (prev.value === ".")
1225
+ prev.output = DOT_LITERAL;
1226
+ const brace = braces[braces.length - 1];
1227
+ prev.type = "dots";
1228
+ prev.output += value;
1229
+ prev.value += value;
1230
+ brace.dots = true;
1231
+ continue;
1232
+ }
1233
+ if (state.braces + state.parens === 0 && prev.type !== "bos" && prev.type !== "slash") {
1234
+ push({ type: "text", value, output: DOT_LITERAL });
1235
+ continue;
1236
+ }
1237
+ push({ type: "dot", value, output: DOT_LITERAL });
1238
+ continue;
1239
+ }
1240
+ if (value === "?") {
1241
+ const isGroup = prev && prev.value === "(";
1242
+ if (!isGroup && opts.noextglob !== true && peek() === "(" && peek(2) !== "?") {
1243
+ extglobOpen("qmark", value);
1244
+ continue;
1245
+ }
1246
+ if (prev && prev.type === "paren") {
1247
+ const next = peek();
1248
+ let output = value;
1249
+ if (prev.value === "(" && !/[!=<:]/.test(next) || next === "<" && !/<([!=]|\w+>)/.test(remaining())) {
1250
+ output = `\\${value}`;
1251
+ }
1252
+ push({ type: "text", value, output });
1253
+ continue;
1254
+ }
1255
+ if (opts.dot !== true && (prev.type === "slash" || prev.type === "bos")) {
1256
+ push({ type: "qmark", value, output: QMARK_NO_DOT });
1257
+ continue;
1258
+ }
1259
+ push({ type: "qmark", value, output: QMARK });
1260
+ continue;
1261
+ }
1262
+ if (value === "!") {
1263
+ if (opts.noextglob !== true && peek() === "(") {
1264
+ if (peek(2) !== "?" || !/[!=<:]/.test(peek(3))) {
1265
+ extglobOpen("negate", value);
1266
+ continue;
1267
+ }
1268
+ }
1269
+ if (opts.nonegate !== true && state.index === 0) {
1270
+ negate();
1271
+ continue;
1272
+ }
1273
+ }
1274
+ if (value === "+") {
1275
+ if (opts.noextglob !== true && peek() === "(" && peek(2) !== "?") {
1276
+ extglobOpen("plus", value);
1277
+ continue;
1278
+ }
1279
+ if (prev && prev.value === "(" || opts.regex === false) {
1280
+ push({ type: "plus", value, output: PLUS_LITERAL });
1281
+ continue;
1282
+ }
1283
+ if (prev && (prev.type === "bracket" || prev.type === "paren" || prev.type === "brace") || state.parens > 0) {
1284
+ push({ type: "plus", value });
1285
+ continue;
1286
+ }
1287
+ push({ type: "plus", value: PLUS_LITERAL });
1288
+ continue;
1289
+ }
1290
+ if (value === "@") {
1291
+ if (opts.noextglob !== true && peek() === "(" && peek(2) !== "?") {
1292
+ push({ type: "at", extglob: true, value, output: "" });
1293
+ continue;
1294
+ }
1295
+ push({ type: "text", value });
1296
+ continue;
1297
+ }
1298
+ if (value !== "*") {
1299
+ if (value === "$" || value === "^") {
1300
+ value = `\\${value}`;
1301
+ }
1302
+ const match = REGEX_NON_SPECIAL_CHARS.exec(remaining());
1303
+ if (match) {
1304
+ value += match[0];
1305
+ state.index += match[0].length;
1306
+ }
1307
+ push({ type: "text", value });
1308
+ continue;
1309
+ }
1310
+ if (prev && (prev.type === "globstar" || prev.star === true)) {
1311
+ prev.type = "star";
1312
+ prev.star = true;
1313
+ prev.value += value;
1314
+ prev.output = star;
1315
+ state.backtrack = true;
1316
+ state.globstar = true;
1317
+ consume(value);
1318
+ continue;
1319
+ }
1320
+ let rest = remaining();
1321
+ if (opts.noextglob !== true && /^\([^?]/.test(rest)) {
1322
+ extglobOpen("star", value);
1323
+ continue;
1324
+ }
1325
+ if (prev.type === "star") {
1326
+ if (opts.noglobstar === true) {
1327
+ consume(value);
1328
+ continue;
1329
+ }
1330
+ const prior = prev.prev;
1331
+ const before = prior.prev;
1332
+ const isStart = prior.type === "slash" || prior.type === "bos";
1333
+ const afterStar = before && (before.type === "star" || before.type === "globstar");
1334
+ if (opts.bash === true && (!isStart || rest[0] && rest[0] !== "/")) {
1335
+ push({ type: "star", value, output: "" });
1336
+ continue;
1337
+ }
1338
+ const isBrace = state.braces > 0 && (prior.type === "comma" || prior.type === "brace");
1339
+ const isExtglob = extglobs.length && (prior.type === "pipe" || prior.type === "paren");
1340
+ if (!isStart && prior.type !== "paren" && !isBrace && !isExtglob) {
1341
+ push({ type: "star", value, output: "" });
1342
+ continue;
1343
+ }
1344
+ while (rest.slice(0, 3) === "/**") {
1345
+ const after = input[state.index + 4];
1346
+ if (after && after !== "/") {
1347
+ break;
1348
+ }
1349
+ rest = rest.slice(3);
1350
+ consume("/**", 3);
1351
+ }
1352
+ if (prior.type === "bos" && eos()) {
1353
+ prev.type = "globstar";
1354
+ prev.value += value;
1355
+ prev.output = globstar(opts);
1356
+ state.output = prev.output;
1357
+ state.globstar = true;
1358
+ consume(value);
1359
+ continue;
1360
+ }
1361
+ if (prior.type === "slash" && prior.prev.type !== "bos" && !afterStar && eos()) {
1362
+ state.output = state.output.slice(0, -(prior.output + prev.output).length);
1363
+ prior.output = `(?:${prior.output}`;
1364
+ prev.type = "globstar";
1365
+ prev.output = globstar(opts) + (opts.strictSlashes ? ")" : "|$)");
1366
+ prev.value += value;
1367
+ state.globstar = true;
1368
+ state.output += prior.output + prev.output;
1369
+ consume(value);
1370
+ continue;
1371
+ }
1372
+ if (prior.type === "slash" && prior.prev.type !== "bos" && rest[0] === "/") {
1373
+ const end = rest[1] !== undefined ? "|$" : "";
1374
+ state.output = state.output.slice(0, -(prior.output + prev.output).length);
1375
+ prior.output = `(?:${prior.output}`;
1376
+ prev.type = "globstar";
1377
+ prev.output = `${globstar(opts)}${SLASH_LITERAL}|${SLASH_LITERAL}${end})`;
1378
+ prev.value += value;
1379
+ state.output += prior.output + prev.output;
1380
+ state.globstar = true;
1381
+ consume(value + advance());
1382
+ push({ type: "slash", value: "/", output: "" });
1383
+ continue;
1384
+ }
1385
+ if (prior.type === "bos" && rest[0] === "/") {
1386
+ prev.type = "globstar";
1387
+ prev.value += value;
1388
+ prev.output = `(?:^|${SLASH_LITERAL}|${globstar(opts)}${SLASH_LITERAL})`;
1389
+ state.output = prev.output;
1390
+ state.globstar = true;
1391
+ consume(value + advance());
1392
+ push({ type: "slash", value: "/", output: "" });
1393
+ continue;
1394
+ }
1395
+ state.output = state.output.slice(0, -prev.output.length);
1396
+ prev.type = "globstar";
1397
+ prev.output = globstar(opts);
1398
+ prev.value += value;
1399
+ state.output += prev.output;
1400
+ state.globstar = true;
1401
+ consume(value);
1402
+ continue;
1403
+ }
1404
+ const token = { type: "star", value, output: star };
1405
+ if (opts.bash === true) {
1406
+ token.output = ".*?";
1407
+ if (prev.type === "bos" || prev.type === "slash") {
1408
+ token.output = nodot + token.output;
1409
+ }
1410
+ push(token);
1411
+ continue;
1412
+ }
1413
+ if (prev && (prev.type === "bracket" || prev.type === "paren") && opts.regex === true) {
1414
+ token.output = value;
1415
+ push(token);
1416
+ continue;
1417
+ }
1418
+ if (state.index === state.start || prev.type === "slash" || prev.type === "dot") {
1419
+ if (prev.type === "dot") {
1420
+ state.output += NO_DOT_SLASH;
1421
+ prev.output += NO_DOT_SLASH;
1422
+ } else if (opts.dot === true) {
1423
+ state.output += NO_DOTS_SLASH;
1424
+ prev.output += NO_DOTS_SLASH;
1425
+ } else {
1426
+ state.output += nodot;
1427
+ prev.output += nodot;
1428
+ }
1429
+ if (peek() !== "*") {
1430
+ state.output += ONE_CHAR;
1431
+ prev.output += ONE_CHAR;
1432
+ }
1433
+ }
1434
+ push(token);
1435
+ }
1436
+ while (state.brackets > 0) {
1437
+ if (opts.strictBrackets === true)
1438
+ throw new SyntaxError(syntaxError("closing", "]"));
1439
+ state.output = utils.escapeLast(state.output, "[");
1440
+ decrement("brackets");
1441
+ }
1442
+ while (state.parens > 0) {
1443
+ if (opts.strictBrackets === true)
1444
+ throw new SyntaxError(syntaxError("closing", ")"));
1445
+ state.output = utils.escapeLast(state.output, "(");
1446
+ decrement("parens");
1447
+ }
1448
+ while (state.braces > 0) {
1449
+ if (opts.strictBrackets === true)
1450
+ throw new SyntaxError(syntaxError("closing", "}"));
1451
+ state.output = utils.escapeLast(state.output, "{");
1452
+ decrement("braces");
1453
+ }
1454
+ if (opts.strictSlashes !== true && (prev.type === "star" || prev.type === "bracket")) {
1455
+ push({ type: "maybe_slash", value: "", output: `${SLASH_LITERAL}?` });
1456
+ }
1457
+ if (state.backtrack === true) {
1458
+ state.output = "";
1459
+ for (const token of state.tokens) {
1460
+ state.output += token.output != null ? token.output : token.value;
1461
+ if (token.suffix) {
1462
+ state.output += token.suffix;
1463
+ }
1464
+ }
1465
+ }
1466
+ return state;
1467
+ };
1468
+ parse.fastpaths = (input, options) => {
1469
+ const opts = { ...options };
1470
+ const max = typeof opts.maxLength === "number" ? Math.min(MAX_LENGTH, opts.maxLength) : MAX_LENGTH;
1471
+ const len = input.length;
1472
+ if (len > max) {
1473
+ throw new SyntaxError(`Input length: ${len}, exceeds maximum allowed length: ${max}`);
1474
+ }
1475
+ input = REPLACEMENTS[input] || input;
1476
+ const {
1477
+ DOT_LITERAL,
1478
+ SLASH_LITERAL,
1479
+ ONE_CHAR,
1480
+ DOTS_SLASH,
1481
+ NO_DOT,
1482
+ NO_DOTS,
1483
+ NO_DOTS_SLASH,
1484
+ STAR,
1485
+ START_ANCHOR
1486
+ } = constants.globChars(opts.windows);
1487
+ const nodot = opts.dot ? NO_DOTS : NO_DOT;
1488
+ const slashDot = opts.dot ? NO_DOTS_SLASH : NO_DOT;
1489
+ const capture = opts.capture ? "" : "?:";
1490
+ const state = { negated: false, prefix: "" };
1491
+ let star = opts.bash === true ? ".*?" : STAR;
1492
+ if (opts.capture) {
1493
+ star = `(${star})`;
1494
+ }
1495
+ const globstar = (opts2) => {
1496
+ if (opts2.noglobstar === true)
1497
+ return star;
1498
+ return `(${capture}(?:(?!${START_ANCHOR}${opts2.dot ? DOTS_SLASH : DOT_LITERAL}).)*?)`;
1499
+ };
1500
+ const create = (str) => {
1501
+ switch (str) {
1502
+ case "*":
1503
+ return `${nodot}${ONE_CHAR}${star}`;
1504
+ case ".*":
1505
+ return `${DOT_LITERAL}${ONE_CHAR}${star}`;
1506
+ case "*.*":
1507
+ return `${nodot}${star}${DOT_LITERAL}${ONE_CHAR}${star}`;
1508
+ case "*/*":
1509
+ return `${nodot}${star}${SLASH_LITERAL}${ONE_CHAR}${slashDot}${star}`;
1510
+ case "**":
1511
+ return nodot + globstar(opts);
1512
+ case "**/*":
1513
+ return `(?:${nodot}${globstar(opts)}${SLASH_LITERAL})?${slashDot}${ONE_CHAR}${star}`;
1514
+ case "**/*.*":
1515
+ return `(?:${nodot}${globstar(opts)}${SLASH_LITERAL})?${slashDot}${star}${DOT_LITERAL}${ONE_CHAR}${star}`;
1516
+ case "**/.*":
1517
+ return `(?:${nodot}${globstar(opts)}${SLASH_LITERAL})?${DOT_LITERAL}${ONE_CHAR}${star}`;
1518
+ default: {
1519
+ const match = /^(.*?)\.(\w+)$/.exec(str);
1520
+ if (!match)
1521
+ return;
1522
+ const source2 = create(match[1]);
1523
+ if (!source2)
1524
+ return;
1525
+ return source2 + DOT_LITERAL + match[2];
1526
+ }
1527
+ }
1528
+ };
1529
+ const output = utils.removePrefix(input, state);
1530
+ let source = create(output);
1531
+ if (source && opts.strictSlashes !== true) {
1532
+ source += `${SLASH_LITERAL}?`;
1533
+ }
1534
+ return source;
1535
+ };
1536
+ module.exports = parse;
1537
+ });
1538
+
1539
+ // node_modules/picomatch/lib/picomatch.js
1540
+ var require_picomatch = __commonJS((exports, module) => {
1541
+ var scan = require_scan();
1542
+ var parse = require_parse();
1543
+ var utils = require_utils();
1544
+ var constants = require_constants();
1545
+ var isObject = (val) => val && typeof val === "object" && !Array.isArray(val);
1546
+ var picomatch = (glob, options, returnState = false) => {
1547
+ if (Array.isArray(glob)) {
1548
+ const fns = glob.map((input) => picomatch(input, options, returnState));
1549
+ const arrayMatcher = (str) => {
1550
+ for (const isMatch of fns) {
1551
+ const state2 = isMatch(str);
1552
+ if (state2)
1553
+ return state2;
1554
+ }
1555
+ return false;
1556
+ };
1557
+ return arrayMatcher;
1558
+ }
1559
+ const isState = isObject(glob) && glob.tokens && glob.input;
1560
+ if (glob === "" || typeof glob !== "string" && !isState) {
1561
+ throw new TypeError("Expected pattern to be a non-empty string");
1562
+ }
1563
+ const opts = options || {};
1564
+ const posix = opts.windows;
1565
+ const regex = isState ? picomatch.compileRe(glob, options) : picomatch.makeRe(glob, options, false, true);
1566
+ const state = regex.state;
1567
+ delete regex.state;
1568
+ let isIgnored = () => false;
1569
+ if (opts.ignore) {
1570
+ const ignoreOpts = { ...options, ignore: null, onMatch: null, onResult: null };
1571
+ isIgnored = picomatch(opts.ignore, ignoreOpts, returnState);
1572
+ }
1573
+ const matcher = (input, returnObject = false) => {
1574
+ const { isMatch, match, output } = picomatch.test(input, regex, options, { glob, posix });
1575
+ const result = { glob, state, regex, posix, input, output, match, isMatch };
1576
+ if (typeof opts.onResult === "function") {
1577
+ opts.onResult(result);
1578
+ }
1579
+ if (isMatch === false) {
1580
+ result.isMatch = false;
1581
+ return returnObject ? result : false;
1582
+ }
1583
+ if (isIgnored(input)) {
1584
+ if (typeof opts.onIgnore === "function") {
1585
+ opts.onIgnore(result);
1586
+ }
1587
+ result.isMatch = false;
1588
+ return returnObject ? result : false;
1589
+ }
1590
+ if (typeof opts.onMatch === "function") {
1591
+ opts.onMatch(result);
1592
+ }
1593
+ return returnObject ? result : true;
1594
+ };
1595
+ if (returnState) {
1596
+ matcher.state = state;
1597
+ }
1598
+ return matcher;
1599
+ };
1600
+ picomatch.test = (input, regex, options, { glob, posix } = {}) => {
1601
+ if (typeof input !== "string") {
1602
+ throw new TypeError("Expected input to be a string");
1603
+ }
1604
+ if (input === "") {
1605
+ return { isMatch: false, output: "" };
1606
+ }
1607
+ const opts = options || {};
1608
+ const format = opts.format || (posix ? utils.toPosixSlashes : null);
1609
+ let match = input === glob;
1610
+ let output = match && format ? format(input) : input;
1611
+ if (match === false) {
1612
+ output = format ? format(input) : input;
1613
+ match = output === glob;
1614
+ }
1615
+ if (match === false || opts.capture === true) {
1616
+ if (opts.matchBase === true || opts.basename === true) {
1617
+ match = picomatch.matchBase(input, regex, options, posix);
1618
+ } else {
1619
+ match = regex.exec(output);
1620
+ }
1621
+ }
1622
+ return { isMatch: Boolean(match), match, output };
1623
+ };
1624
+ picomatch.matchBase = (input, glob, options) => {
1625
+ const regex = glob instanceof RegExp ? glob : picomatch.makeRe(glob, options);
1626
+ return regex.test(utils.basename(input));
1627
+ };
1628
+ picomatch.isMatch = (str, patterns, options) => picomatch(patterns, options)(str);
1629
+ picomatch.parse = (pattern, options) => {
1630
+ if (Array.isArray(pattern))
1631
+ return pattern.map((p) => picomatch.parse(p, options));
1632
+ return parse(pattern, { ...options, fastpaths: false });
1633
+ };
1634
+ picomatch.scan = (input, options) => scan(input, options);
1635
+ picomatch.compileRe = (state, options, returnOutput = false, returnState = false) => {
1636
+ if (returnOutput === true) {
1637
+ return state.output;
1638
+ }
1639
+ const opts = options || {};
1640
+ const prepend = opts.contains ? "" : "^";
1641
+ const append = opts.contains ? "" : "$";
1642
+ let source = `${prepend}(?:${state.output})${append}`;
1643
+ if (state && state.negated === true) {
1644
+ source = `^(?!${source}).*$`;
1645
+ }
1646
+ const regex = picomatch.toRegex(source, options);
1647
+ if (returnState === true) {
1648
+ regex.state = state;
1649
+ }
1650
+ return regex;
1651
+ };
1652
+ picomatch.makeRe = (input, options = {}, returnOutput = false, returnState = false) => {
1653
+ if (!input || typeof input !== "string") {
1654
+ throw new TypeError("Expected a non-empty string");
1655
+ }
1656
+ let parsed = { negated: false, fastpaths: true };
1657
+ if (options.fastpaths !== false && (input[0] === "." || input[0] === "*")) {
1658
+ parsed.output = parse.fastpaths(input, options);
1659
+ }
1660
+ if (!parsed.output) {
1661
+ parsed = parse(input, options);
1662
+ }
1663
+ return picomatch.compileRe(parsed, options, returnOutput, returnState);
1664
+ };
1665
+ picomatch.toRegex = (source, options) => {
1666
+ try {
1667
+ const opts = options || {};
1668
+ return new RegExp(source, opts.flags || (opts.nocase ? "i" : ""));
1669
+ } catch (err) {
1670
+ if (options && options.debug === true)
1671
+ throw err;
1672
+ return /$^/;
1673
+ }
1674
+ };
1675
+ picomatch.constants = constants;
1676
+ module.exports = picomatch;
1677
+ });
1678
+
1679
+ // node_modules/picomatch/index.js
1680
+ var require_picomatch2 = __commonJS((exports, module) => {
1681
+ var pico = require_picomatch();
1682
+ var utils = require_utils();
1683
+ function picomatch(glob, options, returnState = false) {
1684
+ if (options && (options.windows === null || options.windows === undefined)) {
1685
+ options = { ...options, windows: utils.isWindows() };
1686
+ }
1687
+ return pico(glob, options, returnState);
1688
+ }
1689
+ Object.assign(picomatch, pico);
1690
+ module.exports = picomatch;
1691
+ });
1692
+
1693
+ // src/context/zone-classifier.ts
1694
+ function classifyFile(filePath) {
1695
+ const normalized = filePath.toLowerCase().replace(/\\/g, "/");
1696
+ if (normalized.endsWith(".wasm") || normalized.startsWith("dist/") || normalized.includes("/dist/") || normalized.startsWith("build/") || normalized.includes("/build/") || normalized.includes(".swarm/checkpoints/")) {
1697
+ return {
1698
+ filePath,
1699
+ zone: "generated",
1700
+ confidence: "high",
1701
+ reason: "path matches generated file patterns"
1702
+ };
1703
+ }
1704
+ if (normalized.includes("/test/") || normalized.includes("/tests/") || normalized.includes("/__tests__/") || normalized.includes(".test.") || normalized.includes(".spec.") || normalized.includes("/mocks/")) {
1705
+ return {
1706
+ filePath,
1707
+ zone: "test",
1708
+ confidence: "high",
1709
+ reason: "path matches test/**, tests/**, __tests__/**, *.test.*, *.spec.*, or **/mocks/**"
1710
+ };
1711
+ }
1712
+ if (normalized.includes("/scripts/") || normalized.includes("makefile") || normalized.includes("dockerfile") || normalized.includes(".github/")) {
1713
+ return {
1714
+ filePath,
1715
+ zone: "build",
1716
+ confidence: "high",
1717
+ reason: "path matches build scripts or CI configuration"
1718
+ };
1719
+ }
1720
+ if (normalized.endsWith(".json") && !normalized.includes(".github/") || normalized.endsWith(".yaml") && !normalized.includes(".github/") || normalized.endsWith(".yml") && !normalized.includes(".github/") || normalized.endsWith(".toml") || normalized.includes(".env") || normalized.endsWith("biome.json") || normalized.endsWith("tsconfig.json")) {
1721
+ return {
1722
+ filePath,
1723
+ zone: "config",
1724
+ confidence: "high",
1725
+ reason: "extension is config file type"
1726
+ };
1727
+ }
1728
+ if (normalized.includes("/docs/") || normalized.endsWith(".md") && !normalized.includes("/") || normalized.includes("readme") || normalized.includes("changelog") || normalized.includes("license")) {
1729
+ return {
1730
+ filePath,
1731
+ zone: "docs",
1732
+ confidence: "high",
1733
+ reason: "path matches docs/** or documentation files"
1734
+ };
1735
+ }
1736
+ if (normalized.includes("/src/") || normalized.includes("/lib/")) {
1737
+ return {
1738
+ filePath,
1739
+ zone: "production",
1740
+ confidence: "high",
1741
+ reason: "path matches src/** or lib/**"
1742
+ };
1743
+ }
1744
+ return {
1745
+ filePath,
1746
+ zone: "production",
1747
+ confidence: "medium",
1748
+ reason: "default classification"
1749
+ };
1750
+ }
1751
+
1752
+ // src/hooks/guardrails/file-authority.ts
1753
+ import * as fsSync from "fs";
1754
+ var import_picomatch = __toESM(require_picomatch2(), 1);
1755
+ import * as path from "path";
1756
+
1757
+ // node_modules/quick-lru/index.js
1758
+ class QuickLRU extends Map {
1759
+ #size = 0;
1760
+ #cache = new Map;
1761
+ #oldCache = new Map;
1762
+ #maxSize;
1763
+ #maxAge;
1764
+ #onEviction;
1765
+ constructor(options = {}) {
1766
+ super();
1767
+ if (!(options.maxSize && options.maxSize > 0)) {
1768
+ throw new TypeError("`maxSize` must be a number greater than 0");
1769
+ }
1770
+ if (typeof options.maxAge === "number" && options.maxAge === 0) {
1771
+ throw new TypeError("`maxAge` must be a number greater than 0");
1772
+ }
1773
+ this.#maxSize = options.maxSize;
1774
+ this.#maxAge = options.maxAge || Number.POSITIVE_INFINITY;
1775
+ this.#onEviction = options.onEviction;
1776
+ }
1777
+ get __oldCache() {
1778
+ return this.#oldCache;
1779
+ }
1780
+ #emitEvictions(cache) {
1781
+ if (typeof this.#onEviction !== "function") {
1782
+ return;
1783
+ }
1784
+ for (const [key, item] of cache) {
1785
+ this.#onEviction(key, item.value);
1786
+ }
1787
+ }
1788
+ #deleteIfExpired(key, item) {
1789
+ if (typeof item.expiry === "number" && item.expiry <= Date.now()) {
1790
+ if (typeof this.#onEviction === "function") {
1791
+ this.#onEviction(key, item.value);
1792
+ }
1793
+ return this.delete(key);
1794
+ }
1795
+ return false;
1796
+ }
1797
+ #getOrDeleteIfExpired(key, item) {
1798
+ const deleted = this.#deleteIfExpired(key, item);
1799
+ if (deleted === false) {
1800
+ return item.value;
1801
+ }
1802
+ }
1803
+ #getItemValue(key, item) {
1804
+ return item.expiry ? this.#getOrDeleteIfExpired(key, item) : item.value;
1805
+ }
1806
+ #peek(key, cache) {
1807
+ const item = cache.get(key);
1808
+ return this.#getItemValue(key, item);
1809
+ }
1810
+ #set(key, value) {
1811
+ this.#cache.set(key, value);
1812
+ this.#size++;
1813
+ if (this.#size >= this.#maxSize) {
1814
+ this.#size = 0;
1815
+ this.#emitEvictions(this.#oldCache);
1816
+ this.#oldCache = this.#cache;
1817
+ this.#cache = new Map;
1818
+ }
1819
+ }
1820
+ #moveToRecent(key, item) {
1821
+ this.#oldCache.delete(key);
1822
+ this.#set(key, item);
1823
+ }
1824
+ *#entriesAscending() {
1825
+ for (const item of this.#oldCache) {
1826
+ const [key, value] = item;
1827
+ if (!this.#cache.has(key)) {
1828
+ const deleted = this.#deleteIfExpired(key, value);
1829
+ if (deleted === false) {
1830
+ yield item;
1831
+ }
1832
+ }
1833
+ }
1834
+ for (const item of this.#cache) {
1835
+ const [key, value] = item;
1836
+ const deleted = this.#deleteIfExpired(key, value);
1837
+ if (deleted === false) {
1838
+ yield item;
1839
+ }
1840
+ }
1841
+ }
1842
+ get(key) {
1843
+ if (this.#cache.has(key)) {
1844
+ const item = this.#cache.get(key);
1845
+ return this.#getItemValue(key, item);
1846
+ }
1847
+ if (this.#oldCache.has(key)) {
1848
+ const item = this.#oldCache.get(key);
1849
+ if (this.#deleteIfExpired(key, item) === false) {
1850
+ this.#moveToRecent(key, item);
1851
+ return item.value;
1852
+ }
1853
+ }
1854
+ }
1855
+ set(key, value, { maxAge = this.#maxAge } = {}) {
1856
+ const expiry = typeof maxAge === "number" && maxAge !== Number.POSITIVE_INFINITY ? Date.now() + maxAge : undefined;
1857
+ if (this.#cache.has(key)) {
1858
+ this.#cache.set(key, {
1859
+ value,
1860
+ expiry
1861
+ });
1862
+ } else {
1863
+ this.#set(key, { value, expiry });
1864
+ }
1865
+ return this;
1866
+ }
1867
+ has(key) {
1868
+ if (this.#cache.has(key)) {
1869
+ return !this.#deleteIfExpired(key, this.#cache.get(key));
1870
+ }
1871
+ if (this.#oldCache.has(key)) {
1872
+ return !this.#deleteIfExpired(key, this.#oldCache.get(key));
1873
+ }
1874
+ return false;
1875
+ }
1876
+ peek(key) {
1877
+ if (this.#cache.has(key)) {
1878
+ return this.#peek(key, this.#cache);
1879
+ }
1880
+ if (this.#oldCache.has(key)) {
1881
+ return this.#peek(key, this.#oldCache);
1882
+ }
1883
+ }
1884
+ expiresIn(key) {
1885
+ const item = this.#cache.get(key) ?? this.#oldCache.get(key);
1886
+ if (item) {
1887
+ return item.expiry ? item.expiry - Date.now() : Number.POSITIVE_INFINITY;
1888
+ }
1889
+ }
1890
+ delete(key) {
1891
+ const deleted = this.#cache.delete(key);
1892
+ if (deleted) {
1893
+ this.#size--;
1894
+ }
1895
+ return this.#oldCache.delete(key) || deleted;
1896
+ }
1897
+ clear() {
1898
+ this.#cache.clear();
1899
+ this.#oldCache.clear();
1900
+ this.#size = 0;
1901
+ }
1902
+ resize(newSize) {
1903
+ if (!(newSize && newSize > 0)) {
1904
+ throw new TypeError("`maxSize` must be a number greater than 0");
1905
+ }
1906
+ const items = [...this.#entriesAscending()];
1907
+ const removeCount = items.length - newSize;
1908
+ if (removeCount < 0) {
1909
+ this.#cache = new Map(items);
1910
+ this.#oldCache = new Map;
1911
+ this.#size = items.length;
1912
+ } else {
1913
+ if (removeCount > 0) {
1914
+ this.#emitEvictions(items.slice(0, removeCount));
1915
+ }
1916
+ this.#oldCache = new Map(items.slice(removeCount));
1917
+ this.#cache = new Map;
1918
+ this.#size = 0;
1919
+ }
1920
+ this.#maxSize = newSize;
1921
+ }
1922
+ evict(count = 1) {
1923
+ const requested = Number(count);
1924
+ if (!requested || requested <= 0) {
1925
+ return;
1926
+ }
1927
+ const items = [...this.#entriesAscending()];
1928
+ const evictCount = Math.trunc(Math.min(requested, Math.max(items.length - 1, 0)));
1929
+ if (evictCount <= 0) {
1930
+ return;
1931
+ }
1932
+ this.#emitEvictions(items.slice(0, evictCount));
1933
+ this.#oldCache = new Map(items.slice(evictCount));
1934
+ this.#cache = new Map;
1935
+ this.#size = 0;
1936
+ }
1937
+ *keys() {
1938
+ for (const [key] of this) {
1939
+ yield key;
1940
+ }
1941
+ }
1942
+ *values() {
1943
+ for (const [, value] of this) {
1944
+ yield value;
1945
+ }
1946
+ }
1947
+ *[Symbol.iterator]() {
1948
+ for (const item of this.#cache) {
1949
+ const [key, value] = item;
1950
+ const deleted = this.#deleteIfExpired(key, value);
1951
+ if (deleted === false) {
1952
+ yield [key, value.value];
1953
+ }
1954
+ }
1955
+ for (const item of this.#oldCache) {
1956
+ const [key, value] = item;
1957
+ if (!this.#cache.has(key)) {
1958
+ const deleted = this.#deleteIfExpired(key, value);
1959
+ if (deleted === false) {
1960
+ yield [key, value.value];
1961
+ }
1962
+ }
1963
+ }
1964
+ }
1965
+ *entriesDescending() {
1966
+ let items = [...this.#cache];
1967
+ for (let i = items.length - 1;i >= 0; --i) {
1968
+ const item = items[i];
1969
+ const [key, value] = item;
1970
+ const deleted = this.#deleteIfExpired(key, value);
1971
+ if (deleted === false) {
1972
+ yield [key, value.value];
1973
+ }
1974
+ }
1975
+ items = [...this.#oldCache];
1976
+ for (let i = items.length - 1;i >= 0; --i) {
1977
+ const item = items[i];
1978
+ const [key, value] = item;
1979
+ if (!this.#cache.has(key)) {
1980
+ const deleted = this.#deleteIfExpired(key, value);
1981
+ if (deleted === false) {
1982
+ yield [key, value.value];
1983
+ }
1984
+ }
1985
+ }
1986
+ }
1987
+ *entriesAscending() {
1988
+ for (const [key, value] of this.#entriesAscending()) {
1989
+ yield [key, value.value];
1990
+ }
1991
+ }
1992
+ get size() {
1993
+ if (!this.#size) {
1994
+ return this.#oldCache.size;
1995
+ }
1996
+ let oldCacheSize = 0;
1997
+ for (const key of this.#oldCache.keys()) {
1998
+ if (!this.#cache.has(key)) {
1999
+ oldCacheSize++;
2000
+ }
2001
+ }
2002
+ return Math.min(this.#size + oldCacheSize, this.#maxSize);
2003
+ }
2004
+ get maxSize() {
2005
+ return this.#maxSize;
2006
+ }
2007
+ get maxAge() {
2008
+ return this.#maxAge;
2009
+ }
2010
+ entries() {
2011
+ return this.entriesAscending();
2012
+ }
2013
+ forEach(callbackFunction, thisArgument = this) {
2014
+ for (const [key, value] of this.entriesAscending()) {
2015
+ callbackFunction.call(thisArgument, value, key, this);
2016
+ }
2017
+ }
2018
+ get [Symbol.toStringTag]() {
2019
+ return "QuickLRU";
2020
+ }
2021
+ toString() {
2022
+ return `QuickLRU(${this.size}/${this.maxSize})`;
2023
+ }
2024
+ [Symbol.for("nodejs.util.inspect.custom")]() {
2025
+ return this.toString();
2026
+ }
2027
+ }
2028
+
2029
+ // src/hooks/guardrails/file-authority.ts
2030
+ var pathNormalizationCache = new QuickLRU({
2031
+ maxSize: 500
2032
+ });
2033
+ var globMatcherCache = new QuickLRU({
2034
+ maxSize: 200
2035
+ });
2036
+ function normalizePathWithCache(filePath, cwd) {
2037
+ const cacheKey = `${cwd}:${filePath}`;
2038
+ const cached = pathNormalizationCache.get(cacheKey);
2039
+ if (cached !== undefined) {
2040
+ return cached;
2041
+ }
2042
+ try {
2043
+ const absolutePath = path.isAbsolute(filePath) ? filePath : path.resolve(cwd, filePath);
2044
+ const normalized = fsSync.realpathSync(absolutePath);
2045
+ pathNormalizationCache.set(cacheKey, normalized);
2046
+ return normalized;
2047
+ } catch {
2048
+ const fallback = path.isAbsolute(filePath) ? filePath : path.resolve(cwd, filePath);
2049
+ pathNormalizationCache.set(cacheKey, fallback);
2050
+ return fallback;
2051
+ }
2052
+ }
2053
+ function getGlobMatcher(pattern, caseInsensitive = process.platform === "win32" || process.platform === "darwin") {
2054
+ const cacheKey = `${caseInsensitive ? "nocase" : "case"}\x00${pattern}`;
2055
+ const cached = globMatcherCache.get(cacheKey);
2056
+ if (cached !== undefined) {
2057
+ return cached;
2058
+ }
2059
+ try {
2060
+ const matcher = import_picomatch.default(pattern, {
2061
+ dot: true,
2062
+ nocase: caseInsensitive
2063
+ });
2064
+ globMatcherCache.set(cacheKey, matcher);
2065
+ return matcher;
2066
+ } catch (err) {
2067
+ warn(`picomatch error for pattern "${pattern}": ${err}`);
2068
+ return () => false;
2069
+ }
2070
+ }
2071
+ var DEFAULT_AGENT_AUTHORITY_RULES = {
2072
+ build: {},
2073
+ plan: {},
2074
+ general: {},
2075
+ explore: {},
2076
+ architect: {
2077
+ blockedExact: [".swarm/plan.md", ".swarm/plan.json"],
2078
+ blockedZones: ["generated", "config"],
2079
+ blockedGlobs: [
2080
+ "**/oxlintrc*",
2081
+ "**/.oxlintrc*",
2082
+ "**/.eslintrc*",
2083
+ "**/eslint.config.*",
2084
+ "**/.prettierrc*",
2085
+ "**/prettier.config.*",
2086
+ "**/biome.jsonc",
2087
+ "**/.secretscanignore",
2088
+ "**/.golangci*"
2089
+ ]
2090
+ },
2091
+ coder: {
2092
+ blockedPrefix: [".swarm/"],
2093
+ blockedZones: ["generated", "config"]
2094
+ },
2095
+ reviewer: {
2096
+ blockedExact: [".swarm/plan.md", ".swarm/plan.json"],
2097
+ blockedPrefix: ["src/"],
2098
+ allowedPrefix: [".swarm/evidence/", ".swarm/outputs/"],
2099
+ blockedZones: ["generated"]
2100
+ },
2101
+ explorer: {
2102
+ readOnly: true
2103
+ },
2104
+ sme: {
2105
+ readOnly: true
2106
+ },
2107
+ test_engineer: {
2108
+ blockedExact: [".swarm/plan.md", ".swarm/plan.json"],
2109
+ blockedPrefix: ["src/"],
2110
+ allowedPrefix: ["tests/", "test/", ".swarm/evidence/"],
2111
+ allowedGlobs: [
2112
+ "**/tests/**",
2113
+ "**/test/**",
2114
+ "**/__tests__/**",
2115
+ "**/*.test.*",
2116
+ "**/*.spec.*",
2117
+ "test_*.py",
2118
+ "**/test_*.py",
2119
+ "*_test.py",
2120
+ "**/*_test.py",
2121
+ "*_test.go",
2122
+ "**/*_test.go",
2123
+ "*_spec.rb",
2124
+ "**/*_spec.rb",
2125
+ "*.Tests.ps1",
2126
+ "**/*.Tests.ps1"
2127
+ ],
2128
+ allowedCaseSensitiveGlobs: [
2129
+ "*Test.java",
2130
+ "**/*Test.java",
2131
+ "*Test.kt",
2132
+ "**/*Test.kt",
2133
+ "*Tests.cs",
2134
+ "**/*Tests.cs"
2135
+ ],
2136
+ blockedZones: ["generated"]
2137
+ },
2138
+ docs: {
2139
+ allowedPrefix: ["docs/", ".swarm/outputs/"],
2140
+ allowedGlobs: ["**/docs/**", "**/*.md", "**/*.mdx", "**/*.rst"],
2141
+ blockedZones: ["generated"]
2142
+ },
2143
+ docs_design: {
2144
+ allowedPrefix: ["docs/", ".swarm/outputs/"],
2145
+ blockedGlobs: ["src/**", "lib/**"],
2146
+ allowedGlobs: [
2147
+ "**/docs/**",
2148
+ "**/*.md",
2149
+ "**/*.mdx",
2150
+ "**/*.rst",
2151
+ "**/reference/traceability.json"
2152
+ ],
2153
+ blockedZones: ["generated"]
2154
+ },
2155
+ designer: {
2156
+ allowedPrefix: ["docs/", ".swarm/outputs/"],
2157
+ allowedGlobs: ["**/docs/**", "**/*.md", "**/*.mdx", "**/*.rst"],
2158
+ blockedZones: ["generated"]
2159
+ },
2160
+ critic: {
2161
+ allowedPrefix: [".swarm/evidence/"],
2162
+ blockedZones: ["generated"]
2163
+ }
2164
+ };
2165
+ function buildEffectiveRules(authorityConfig) {
2166
+ if (authorityConfig?.enabled === false || !authorityConfig?.rules) {
2167
+ return { ...DEFAULT_AGENT_AUTHORITY_RULES };
2168
+ }
2169
+ const entries = Object.entries(authorityConfig.rules);
2170
+ if (entries.length === 0) {
2171
+ return { ...DEFAULT_AGENT_AUTHORITY_RULES };
2172
+ }
2173
+ const merged = {
2174
+ ...DEFAULT_AGENT_AUTHORITY_RULES
2175
+ };
2176
+ for (const [agent, userRule] of entries) {
2177
+ const normalizedRuleKey = agent.toLowerCase();
2178
+ const existing = merged[normalizedRuleKey] ?? {};
2179
+ merged[normalizedRuleKey] = {
2180
+ ...existing,
2181
+ ...userRule,
2182
+ readOnly: userRule.readOnly ?? existing.readOnly,
2183
+ blockedExact: userRule.blockedExact ?? existing.blockedExact,
2184
+ allowedExact: userRule.allowedExact ?? existing.allowedExact,
2185
+ blockedPrefix: userRule.blockedPrefix ?? existing.blockedPrefix,
2186
+ allowedPrefix: userRule.allowedPrefix ?? existing.allowedPrefix,
2187
+ blockedZones: userRule.blockedZones ?? existing.blockedZones,
2188
+ blockedGlobs: userRule.blockedGlobs ?? existing.blockedGlobs,
2189
+ allowedGlobs: userRule.allowedGlobs ?? existing.allowedGlobs,
2190
+ allowedCaseSensitiveGlobs: userRule.allowedCaseSensitiveGlobs ?? existing.allowedCaseSensitiveGlobs
2191
+ };
2192
+ }
2193
+ return merged;
2194
+ }
2195
+ function isOnDifferentFilesystemRoot(targetAbsolute, cwdAbsolute, pathLib = path) {
2196
+ return pathLib.parse(targetAbsolute).root !== pathLib.parse(cwdAbsolute).root;
2197
+ }
2198
+ function isInDeclaredScope(filePath, scopeEntries, cwd) {
2199
+ const dir = cwd ?? process.cwd();
2200
+ const caseInsensitive = process.platform === "win32";
2201
+ const resolvedFileRaw = path.resolve(dir, filePath);
2202
+ const resolvedFile = caseInsensitive ? resolvedFileRaw.toLowerCase() : resolvedFileRaw;
2203
+ return scopeEntries.some((scope) => {
2204
+ const resolvedScopeRaw = path.resolve(dir, scope);
2205
+ const resolvedScope = caseInsensitive ? resolvedScopeRaw.toLowerCase() : resolvedScopeRaw;
2206
+ if (resolvedFile === resolvedScope)
2207
+ return true;
2208
+ const rel = path.relative(resolvedScope, resolvedFile);
2209
+ return rel.length > 0 && !rel.startsWith("..") && !path.isAbsolute(rel);
2210
+ });
2211
+ }
2212
+ function checkFileAuthorityWithRules(agentName, filePath, cwd, effectiveRules, options) {
2213
+ const normalizedAgent = agentName.toLowerCase();
2214
+ const strippedAgent = stripKnownSwarmPrefix(agentName).toLowerCase();
2215
+ const dir = cwd || process.cwd();
2216
+ let normalizedPath;
2217
+ let resolvedTarget;
2218
+ try {
2219
+ const normalizedWithSymlinks = normalizePathWithCache(filePath, dir);
2220
+ resolvedTarget = path.resolve(dir, normalizedWithSymlinks);
2221
+ normalizedPath = path.relative(dir, resolvedTarget).replace(/\\/g, "/");
2222
+ } catch {
2223
+ resolvedTarget = path.resolve(dir, filePath);
2224
+ normalizedPath = path.relative(dir, resolvedTarget).replace(/\\/g, "/");
2225
+ }
2226
+ if (isOnDifferentFilesystemRoot(resolvedTarget, dir)) {
2227
+ return {
2228
+ allowed: false,
2229
+ reason: `Path blocked: ${filePath} is on a different drive/root than the working directory`
2230
+ };
2231
+ }
2232
+ if (normalizedPath === ".." || normalizedPath.startsWith("../")) {
2233
+ return {
2234
+ allowed: false,
2235
+ reason: `Path blocked: ${normalizedPath} resolves outside the working directory`
2236
+ };
2237
+ }
2238
+ const rules = effectiveRules[normalizedAgent] ?? effectiveRules[strippedAgent];
2239
+ if (!rules) {
2240
+ return { allowed: false, reason: `Unknown agent: ${agentName}` };
2241
+ }
2242
+ if (rules.readOnly) {
2243
+ return {
2244
+ allowed: false,
2245
+ reason: `Path blocked: ${normalizedPath} (agent ${normalizedAgent} is read-only)`
2246
+ };
2247
+ }
2248
+ if (rules.blockedExact) {
2249
+ for (const blocked of rules.blockedExact) {
2250
+ if (normalizedPath === blocked) {
2251
+ return {
2252
+ allowed: false,
2253
+ reason: `Path blocked (exact): ${normalizedPath}`
2254
+ };
2255
+ }
2256
+ }
2257
+ }
2258
+ if (rules.blockedGlobs && rules.blockedGlobs.length > 0) {
2259
+ for (const glob of rules.blockedGlobs) {
2260
+ const matcher = getGlobMatcher(glob);
2261
+ if (matcher(normalizedPath)) {
2262
+ return {
2263
+ allowed: false,
2264
+ reason: `Path blocked (glob ${glob}): ${normalizedPath}`
2265
+ };
2266
+ }
2267
+ }
2268
+ }
2269
+ if (rules.allowedExact && rules.allowedExact.length > 0) {
2270
+ const isExplicitlyAllowed = rules.allowedExact.some((allowed) => normalizedPath === allowed);
2271
+ if (isExplicitlyAllowed) {
2272
+ return { allowed: true };
2273
+ }
2274
+ }
2275
+ if (rules.blockedZones && rules.blockedZones.length > 0) {
2276
+ const { zone } = classifyFile(normalizedPath);
2277
+ if (rules.blockedZones.includes(zone)) {
2278
+ return {
2279
+ allowed: false,
2280
+ reason: `Path blocked: ${normalizedPath} is in ${zone} zone`,
2281
+ zone
2282
+ };
2283
+ }
2284
+ }
2285
+ if (rules.allowedGlobs && rules.allowedGlobs.length > 0) {
2286
+ const isGlobAllowed = rules.allowedGlobs.some((glob) => {
2287
+ const matcher = getGlobMatcher(glob);
2288
+ return matcher(normalizedPath);
2289
+ });
2290
+ if (isGlobAllowed) {
2291
+ return { allowed: true };
2292
+ }
2293
+ }
2294
+ if (rules.allowedCaseSensitiveGlobs && rules.allowedCaseSensitiveGlobs.length > 0) {
2295
+ const isCaseSensitiveGlobAllowed = rules.allowedCaseSensitiveGlobs.some((glob) => {
2296
+ const matcher = getGlobMatcher(glob, false);
2297
+ return matcher(normalizedPath);
2298
+ });
2299
+ if (isCaseSensitiveGlobAllowed) {
2300
+ return { allowed: true };
2301
+ }
2302
+ }
2303
+ if (rules.blockedPrefix && rules.blockedPrefix.length > 0) {
2304
+ for (const prefix of rules.blockedPrefix) {
2305
+ if (normalizedPath.startsWith(prefix)) {
2306
+ return {
2307
+ allowed: false,
2308
+ reason: `Path blocked: ${normalizedPath} is under ${prefix}`
2309
+ };
2310
+ }
2311
+ }
2312
+ }
2313
+ const isCoderAgent = normalizedAgent === "coder" || strippedAgent === "coder";
2314
+ const pathIsInDeclaredScope = isCoderAgent && options?.declaredScope != null && options.declaredScope.length > 0 && isInDeclaredScope(normalizedPath, options.declaredScope, dir);
2315
+ if (!pathIsInDeclaredScope) {
2316
+ if (rules.allowedPrefix != null && rules.allowedPrefix.length > 0) {
2317
+ const isAllowed = rules.allowedPrefix.some((prefix) => normalizedPath.startsWith(prefix));
2318
+ if (!isAllowed) {
2319
+ return {
2320
+ allowed: false,
2321
+ reason: `Path ${normalizedPath} not in allowed list for ${normalizedAgent}`
2322
+ };
2323
+ }
2324
+ } else if (rules.allowedPrefix != null && rules.allowedPrefix.length === 0) {
2325
+ return {
2326
+ allowed: false,
2327
+ reason: `Path ${normalizedPath} not in allowed list for ${normalizedAgent}`
2328
+ };
2329
+ }
2330
+ }
2331
+ return { allowed: true };
2332
+ }
2333
+ function checkFileAuthority(agentName, filePath, cwd, authorityConfig, options) {
2334
+ return checkFileAuthorityWithRules(agentName, filePath, cwd, buildEffectiveRules(authorityConfig), options);
2335
+ }
2336
+
2337
+ // src/hooks/guardrails/helpers.ts
2338
+ import * as path2 from "path";
2339
+ function isInDeclaredScope2(filePath, scopeEntries, cwd) {
2340
+ const dir = cwd ?? process.cwd();
2341
+ const caseInsensitive = process.platform === "win32";
2342
+ const resolvedFileRaw = path2.resolve(dir, filePath);
2343
+ const resolvedFile = caseInsensitive ? resolvedFileRaw.toLowerCase() : resolvedFileRaw;
2344
+ return scopeEntries.some((scope) => {
2345
+ const resolvedScopeRaw = path2.resolve(dir, scope);
2346
+ const resolvedScope = caseInsensitive ? resolvedScopeRaw.toLowerCase() : resolvedScopeRaw;
2347
+ if (resolvedFile === resolvedScope)
2348
+ return true;
2349
+ const rel = path2.relative(resolvedScope, resolvedFile);
2350
+ return rel.length > 0 && !rel.startsWith("..") && !path2.isAbsolute(rel);
2351
+ });
2352
+ }
2353
+ function redactShellCommand(cmd) {
2354
+ if (typeof cmd !== "string")
2355
+ return "";
2356
+ let out = cmd.replace(/\/home\/[^/\s"']+/g, "~").replace(/[A-Za-z]:\\Users\\[^\\\s"']+/g, "~").replace(/\/Users\/[^/\s"']+/g, "~");
2357
+ out = out.replace(/\b([A-Z_]*(?:TOKEN|SECRET|PASSWORD|PASSWD|API[_]?KEY|APIKEY|AUTH|CREDENTIAL|PRIVATE[_]?KEY|ACCESS[_]?KEY|_KEY)[A-Z_0-9]*)\s*=\s*(\S+)/gi, "$1=[REDACTED]");
2358
+ out = out.replace(/--([a-zA-Z-]*(?:token|secret|password|passwd|api[_-]?key|apikey|auth|credential|private[_-]?key|access[_-]?key)[a-zA-Z-]*)=(\S+)/gi, "--$1=[REDACTED]");
2359
+ out = out.replace(/(--[a-zA-Z-]*(?:token|secret|password|passwd|api[_-]?key|apikey|auth|credential|private[_-]?key|access[_-]?key)[a-zA-Z-]*)(\s+)(?!--)(\S+)/gi, "$1$2[REDACTED]");
2360
+ out = out.replace(/\b(Bearer|Basic)\s+[A-Za-z0-9+/=._-]{4,}/gi, "$1 [REDACTED]");
2361
+ out = out.replace(/(-H\s+['"]?(?:Authorization|X-API-Key|X-Auth-Token|[A-Za-z][A-Za-z-]*-(?:key|token|secret|auth|credential)):\s*)([^'">\s][^'">\n]*)(['"]?)/gi, "$1[REDACTED]$3");
2362
+ return out;
2363
+ }
2364
+
2365
+ // src/hooks/guardrails/audit-log.ts
2366
+ init_logger();
2367
+ import * as path3 from "path";
2368
+ function redactPath(filePath) {
2369
+ if (typeof filePath !== "string" || filePath.length === 0)
2370
+ return filePath;
2371
+ const rawPosixHomeMatch = filePath.match(/^(\/home\/[^/]+)(\/.*)$/);
2372
+ if (rawPosixHomeMatch) {
2373
+ return `~${rawPosixHomeMatch[2]}`;
2374
+ }
2375
+ const rawMacHomeMatch = filePath.match(/^(\/Users\/[^/]+)(\/.*)$/);
2376
+ if (rawMacHomeMatch) {
2377
+ return `~${rawMacHomeMatch[2]}`;
2378
+ }
2379
+ const normalized = path3.normalize(filePath);
2380
+ const windowsHomeMatch = normalized.match(/^([A-Za-z]:\\Users\\[^\\]+)(\\.*)$/);
2381
+ if (windowsHomeMatch) {
2382
+ return `~\\${windowsHomeMatch[2]}`;
2383
+ }
2384
+ const uncHomeMatch = normalized.match(/^\\\\[^\\]+\\([^\\]+)\\([^\\]+)(\\.*)$/);
2385
+ if (uncHomeMatch) {
2386
+ return `~\\${uncHomeMatch[1]}\\${uncHomeMatch[2]}${uncHomeMatch[3]}`;
2387
+ }
2388
+ return normalized;
2389
+ }
2390
+
2391
+ export { classifyFile, checkFileAuthority, isInDeclaredScope2 as isInDeclaredScope, redactShellCommand, redactPath };