@ulpi/cli 0.1.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.
- package/LICENSE +21 -0
- package/README.md +200 -0
- package/dist/auth-PN7TMQHV-2W4ICG64.js +15 -0
- package/dist/chunk-247GVVKK.js +2259 -0
- package/dist/chunk-2CLNOKPA.js +793 -0
- package/dist/chunk-2HEE5OKX.js +79 -0
- package/dist/chunk-2MZER6ND.js +415 -0
- package/dist/chunk-3SBPZRB5.js +772 -0
- package/dist/chunk-4VNS5WPM.js +42 -0
- package/dist/chunk-6JCMYYBT.js +1546 -0
- package/dist/chunk-6OCEY7JY.js +422 -0
- package/dist/chunk-74WVVWJ4.js +375 -0
- package/dist/chunk-7AL4DOEJ.js +131 -0
- package/dist/chunk-7LXY5UVC.js +330 -0
- package/dist/chunk-DBMUNBNB.js +3048 -0
- package/dist/chunk-JWUUVXIV.js +13694 -0
- package/dist/chunk-KIKPIH6N.js +4048 -0
- package/dist/chunk-KLEASXUR.js +70 -0
- package/dist/chunk-MIAQVCFW.js +39 -0
- package/dist/chunk-NNUWU6CV.js +1610 -0
- package/dist/chunk-PKD4ASEM.js +115 -0
- package/dist/chunk-Q4HIY43N.js +4230 -0
- package/dist/chunk-QJ5GSMEC.js +146 -0
- package/dist/chunk-SIAQVRKG.js +2163 -0
- package/dist/chunk-SPOI23SB.js +197 -0
- package/dist/chunk-YM2HV4IA.js +505 -0
- package/dist/codemap-RRJIDBQ5.js +636 -0
- package/dist/config-EGAXXCGL.js +127 -0
- package/dist/dist-6G7JC2RA.js +90 -0
- package/dist/dist-7LHZ65GC.js +418 -0
- package/dist/dist-LZKZFPVX.js +140 -0
- package/dist/dist-R5F4MX3I.js +107 -0
- package/dist/dist-R5ZJ4LX5.js +56 -0
- package/dist/dist-RJGCUS3L.js +87 -0
- package/dist/dist-RKOGLK7R.js +151 -0
- package/dist/dist-W7K4WPAF.js +597 -0
- package/dist/export-import-4A5MWLIA.js +53 -0
- package/dist/history-ATTUKOHO.js +934 -0
- package/dist/index.js +2120 -0
- package/dist/init-AY5C2ZAS.js +393 -0
- package/dist/launchd-LF2QMSKZ.js +148 -0
- package/dist/log-TVTUXAYD.js +75 -0
- package/dist/mcp-installer-NQCGKQ23.js +124 -0
- package/dist/memory-J3G24QHS.js +406 -0
- package/dist/ollama-3XCUZMZT-FYKHW4TZ.js +7 -0
- package/dist/openai-E7G2YAHU-UYY4ZWON.js +8 -0
- package/dist/projects-ATHDD3D6.js +271 -0
- package/dist/review-ADUPV3PN.js +152 -0
- package/dist/rules-E427DKYJ.js +134 -0
- package/dist/server-MOYPE4SM-N7SE2AN7.js +18 -0
- package/dist/server-X5P6WH2M-7K2RY34N.js +11 -0
- package/dist/skills/ulpi-generate-guardian/SKILL.md +511 -0
- package/dist/skills/ulpi-generate-guardian/references/framework-rules.md +692 -0
- package/dist/skills/ulpi-generate-guardian/references/language-rules.md +596 -0
- package/dist/skills-CX73O3IV.js +76 -0
- package/dist/status-4DFHDJMN.js +66 -0
- package/dist/templates/biome.yml +24 -0
- package/dist/templates/conventional-commits.yml +18 -0
- package/dist/templates/django.yml +30 -0
- package/dist/templates/docker.yml +30 -0
- package/dist/templates/eslint.yml +13 -0
- package/dist/templates/express.yml +20 -0
- package/dist/templates/fastapi.yml +23 -0
- package/dist/templates/git-flow.yml +26 -0
- package/dist/templates/github-flow.yml +27 -0
- package/dist/templates/go.yml +33 -0
- package/dist/templates/jest.yml +24 -0
- package/dist/templates/laravel.yml +30 -0
- package/dist/templates/monorepo.yml +26 -0
- package/dist/templates/nestjs.yml +21 -0
- package/dist/templates/nextjs.yml +31 -0
- package/dist/templates/nodejs.yml +33 -0
- package/dist/templates/npm.yml +15 -0
- package/dist/templates/php.yml +25 -0
- package/dist/templates/pnpm.yml +15 -0
- package/dist/templates/prettier.yml +23 -0
- package/dist/templates/prisma.yml +21 -0
- package/dist/templates/python.yml +33 -0
- package/dist/templates/quality-of-life.yml +111 -0
- package/dist/templates/ruby.yml +25 -0
- package/dist/templates/rust.yml +34 -0
- package/dist/templates/typescript.yml +14 -0
- package/dist/templates/vitest.yml +24 -0
- package/dist/templates/yarn.yml +15 -0
- package/dist/templates-U7T6MARD.js +156 -0
- package/dist/ui-L7UAWXDY.js +167 -0
- package/dist/ui.html +698 -0
- package/dist/ulpi-RMMCUAGP-JCJ273T6.js +161 -0
- package/dist/uninstall-6SW35IK4.js +25 -0
- package/dist/update-M2B4RLGH.js +61 -0
- package/dist/version-checker-ANCS3IHR.js +10 -0
- package/package.json +92 -0
|
@@ -0,0 +1,2163 @@
|
|
|
1
|
+
import {
|
|
2
|
+
external_exports
|
|
3
|
+
} from "./chunk-KIKPIH6N.js";
|
|
4
|
+
import {
|
|
5
|
+
__commonJS,
|
|
6
|
+
__toESM
|
|
7
|
+
} from "./chunk-4VNS5WPM.js";
|
|
8
|
+
|
|
9
|
+
// ../../node_modules/.pnpm/picomatch@4.0.3/node_modules/picomatch/lib/constants.js
|
|
10
|
+
var require_constants = __commonJS({
|
|
11
|
+
"../../node_modules/.pnpm/picomatch@4.0.3/node_modules/picomatch/lib/constants.js"(exports, module) {
|
|
12
|
+
"use strict";
|
|
13
|
+
var WIN_SLASH = "\\\\/";
|
|
14
|
+
var WIN_NO_SLASH = `[^${WIN_SLASH}]`;
|
|
15
|
+
var DOT_LITERAL = "\\.";
|
|
16
|
+
var PLUS_LITERAL = "\\+";
|
|
17
|
+
var QMARK_LITERAL = "\\?";
|
|
18
|
+
var SLASH_LITERAL = "\\/";
|
|
19
|
+
var ONE_CHAR = "(?=.)";
|
|
20
|
+
var QMARK = "[^/]";
|
|
21
|
+
var END_ANCHOR = `(?:${SLASH_LITERAL}|$)`;
|
|
22
|
+
var START_ANCHOR = `(?:^|${SLASH_LITERAL})`;
|
|
23
|
+
var DOTS_SLASH = `${DOT_LITERAL}{1,2}${END_ANCHOR}`;
|
|
24
|
+
var NO_DOT = `(?!${DOT_LITERAL})`;
|
|
25
|
+
var NO_DOTS = `(?!${START_ANCHOR}${DOTS_SLASH})`;
|
|
26
|
+
var NO_DOT_SLASH = `(?!${DOT_LITERAL}{0,1}${END_ANCHOR})`;
|
|
27
|
+
var NO_DOTS_SLASH = `(?!${DOTS_SLASH})`;
|
|
28
|
+
var QMARK_NO_DOT = `[^.${SLASH_LITERAL}]`;
|
|
29
|
+
var STAR = `${QMARK}*?`;
|
|
30
|
+
var SEP = "/";
|
|
31
|
+
var POSIX_CHARS = {
|
|
32
|
+
DOT_LITERAL,
|
|
33
|
+
PLUS_LITERAL,
|
|
34
|
+
QMARK_LITERAL,
|
|
35
|
+
SLASH_LITERAL,
|
|
36
|
+
ONE_CHAR,
|
|
37
|
+
QMARK,
|
|
38
|
+
END_ANCHOR,
|
|
39
|
+
DOTS_SLASH,
|
|
40
|
+
NO_DOT,
|
|
41
|
+
NO_DOTS,
|
|
42
|
+
NO_DOT_SLASH,
|
|
43
|
+
NO_DOTS_SLASH,
|
|
44
|
+
QMARK_NO_DOT,
|
|
45
|
+
STAR,
|
|
46
|
+
START_ANCHOR,
|
|
47
|
+
SEP
|
|
48
|
+
};
|
|
49
|
+
var WINDOWS_CHARS = {
|
|
50
|
+
...POSIX_CHARS,
|
|
51
|
+
SLASH_LITERAL: `[${WIN_SLASH}]`,
|
|
52
|
+
QMARK: WIN_NO_SLASH,
|
|
53
|
+
STAR: `${WIN_NO_SLASH}*?`,
|
|
54
|
+
DOTS_SLASH: `${DOT_LITERAL}{1,2}(?:[${WIN_SLASH}]|$)`,
|
|
55
|
+
NO_DOT: `(?!${DOT_LITERAL})`,
|
|
56
|
+
NO_DOTS: `(?!(?:^|[${WIN_SLASH}])${DOT_LITERAL}{1,2}(?:[${WIN_SLASH}]|$))`,
|
|
57
|
+
NO_DOT_SLASH: `(?!${DOT_LITERAL}{0,1}(?:[${WIN_SLASH}]|$))`,
|
|
58
|
+
NO_DOTS_SLASH: `(?!${DOT_LITERAL}{1,2}(?:[${WIN_SLASH}]|$))`,
|
|
59
|
+
QMARK_NO_DOT: `[^.${WIN_SLASH}]`,
|
|
60
|
+
START_ANCHOR: `(?:^|[${WIN_SLASH}])`,
|
|
61
|
+
END_ANCHOR: `(?:[${WIN_SLASH}]|$)`,
|
|
62
|
+
SEP: "\\"
|
|
63
|
+
};
|
|
64
|
+
var POSIX_REGEX_SOURCE = {
|
|
65
|
+
alnum: "a-zA-Z0-9",
|
|
66
|
+
alpha: "a-zA-Z",
|
|
67
|
+
ascii: "\\x00-\\x7F",
|
|
68
|
+
blank: " \\t",
|
|
69
|
+
cntrl: "\\x00-\\x1F\\x7F",
|
|
70
|
+
digit: "0-9",
|
|
71
|
+
graph: "\\x21-\\x7E",
|
|
72
|
+
lower: "a-z",
|
|
73
|
+
print: "\\x20-\\x7E ",
|
|
74
|
+
punct: "\\-!\"#$%&'()\\*+,./:;<=>?@[\\]^_`{|}~",
|
|
75
|
+
space: " \\t\\r\\n\\v\\f",
|
|
76
|
+
upper: "A-Z",
|
|
77
|
+
word: "A-Za-z0-9_",
|
|
78
|
+
xdigit: "A-Fa-f0-9"
|
|
79
|
+
};
|
|
80
|
+
module.exports = {
|
|
81
|
+
MAX_LENGTH: 1024 * 64,
|
|
82
|
+
POSIX_REGEX_SOURCE,
|
|
83
|
+
// regular expressions
|
|
84
|
+
REGEX_BACKSLASH: /\\(?![*+?^${}(|)[\]])/g,
|
|
85
|
+
REGEX_NON_SPECIAL_CHARS: /^[^@![\].,$*+?^{}()|\\/]+/,
|
|
86
|
+
REGEX_SPECIAL_CHARS: /[-*+?.^${}(|)[\]]/,
|
|
87
|
+
REGEX_SPECIAL_CHARS_BACKREF: /(\\?)((\W)(\3*))/g,
|
|
88
|
+
REGEX_SPECIAL_CHARS_GLOBAL: /([-*+?.^${}(|)[\]])/g,
|
|
89
|
+
REGEX_REMOVE_BACKSLASH: /(?:\[.*?[^\\]\]|\\(?=.))/g,
|
|
90
|
+
// Replace globs with equivalent patterns to reduce parsing time.
|
|
91
|
+
REPLACEMENTS: {
|
|
92
|
+
__proto__: null,
|
|
93
|
+
"***": "*",
|
|
94
|
+
"**/**": "**",
|
|
95
|
+
"**/**/**": "**"
|
|
96
|
+
},
|
|
97
|
+
// Digits
|
|
98
|
+
CHAR_0: 48,
|
|
99
|
+
/* 0 */
|
|
100
|
+
CHAR_9: 57,
|
|
101
|
+
/* 9 */
|
|
102
|
+
// Alphabet chars.
|
|
103
|
+
CHAR_UPPERCASE_A: 65,
|
|
104
|
+
/* A */
|
|
105
|
+
CHAR_LOWERCASE_A: 97,
|
|
106
|
+
/* a */
|
|
107
|
+
CHAR_UPPERCASE_Z: 90,
|
|
108
|
+
/* Z */
|
|
109
|
+
CHAR_LOWERCASE_Z: 122,
|
|
110
|
+
/* z */
|
|
111
|
+
CHAR_LEFT_PARENTHESES: 40,
|
|
112
|
+
/* ( */
|
|
113
|
+
CHAR_RIGHT_PARENTHESES: 41,
|
|
114
|
+
/* ) */
|
|
115
|
+
CHAR_ASTERISK: 42,
|
|
116
|
+
/* * */
|
|
117
|
+
// Non-alphabetic chars.
|
|
118
|
+
CHAR_AMPERSAND: 38,
|
|
119
|
+
/* & */
|
|
120
|
+
CHAR_AT: 64,
|
|
121
|
+
/* @ */
|
|
122
|
+
CHAR_BACKWARD_SLASH: 92,
|
|
123
|
+
/* \ */
|
|
124
|
+
CHAR_CARRIAGE_RETURN: 13,
|
|
125
|
+
/* \r */
|
|
126
|
+
CHAR_CIRCUMFLEX_ACCENT: 94,
|
|
127
|
+
/* ^ */
|
|
128
|
+
CHAR_COLON: 58,
|
|
129
|
+
/* : */
|
|
130
|
+
CHAR_COMMA: 44,
|
|
131
|
+
/* , */
|
|
132
|
+
CHAR_DOT: 46,
|
|
133
|
+
/* . */
|
|
134
|
+
CHAR_DOUBLE_QUOTE: 34,
|
|
135
|
+
/* " */
|
|
136
|
+
CHAR_EQUAL: 61,
|
|
137
|
+
/* = */
|
|
138
|
+
CHAR_EXCLAMATION_MARK: 33,
|
|
139
|
+
/* ! */
|
|
140
|
+
CHAR_FORM_FEED: 12,
|
|
141
|
+
/* \f */
|
|
142
|
+
CHAR_FORWARD_SLASH: 47,
|
|
143
|
+
/* / */
|
|
144
|
+
CHAR_GRAVE_ACCENT: 96,
|
|
145
|
+
/* ` */
|
|
146
|
+
CHAR_HASH: 35,
|
|
147
|
+
/* # */
|
|
148
|
+
CHAR_HYPHEN_MINUS: 45,
|
|
149
|
+
/* - */
|
|
150
|
+
CHAR_LEFT_ANGLE_BRACKET: 60,
|
|
151
|
+
/* < */
|
|
152
|
+
CHAR_LEFT_CURLY_BRACE: 123,
|
|
153
|
+
/* { */
|
|
154
|
+
CHAR_LEFT_SQUARE_BRACKET: 91,
|
|
155
|
+
/* [ */
|
|
156
|
+
CHAR_LINE_FEED: 10,
|
|
157
|
+
/* \n */
|
|
158
|
+
CHAR_NO_BREAK_SPACE: 160,
|
|
159
|
+
/* \u00A0 */
|
|
160
|
+
CHAR_PERCENT: 37,
|
|
161
|
+
/* % */
|
|
162
|
+
CHAR_PLUS: 43,
|
|
163
|
+
/* + */
|
|
164
|
+
CHAR_QUESTION_MARK: 63,
|
|
165
|
+
/* ? */
|
|
166
|
+
CHAR_RIGHT_ANGLE_BRACKET: 62,
|
|
167
|
+
/* > */
|
|
168
|
+
CHAR_RIGHT_CURLY_BRACE: 125,
|
|
169
|
+
/* } */
|
|
170
|
+
CHAR_RIGHT_SQUARE_BRACKET: 93,
|
|
171
|
+
/* ] */
|
|
172
|
+
CHAR_SEMICOLON: 59,
|
|
173
|
+
/* ; */
|
|
174
|
+
CHAR_SINGLE_QUOTE: 39,
|
|
175
|
+
/* ' */
|
|
176
|
+
CHAR_SPACE: 32,
|
|
177
|
+
/* */
|
|
178
|
+
CHAR_TAB: 9,
|
|
179
|
+
/* \t */
|
|
180
|
+
CHAR_UNDERSCORE: 95,
|
|
181
|
+
/* _ */
|
|
182
|
+
CHAR_VERTICAL_LINE: 124,
|
|
183
|
+
/* | */
|
|
184
|
+
CHAR_ZERO_WIDTH_NOBREAK_SPACE: 65279,
|
|
185
|
+
/* \uFEFF */
|
|
186
|
+
/**
|
|
187
|
+
* Create EXTGLOB_CHARS
|
|
188
|
+
*/
|
|
189
|
+
extglobChars(chars) {
|
|
190
|
+
return {
|
|
191
|
+
"!": { type: "negate", open: "(?:(?!(?:", close: `))${chars.STAR})` },
|
|
192
|
+
"?": { type: "qmark", open: "(?:", close: ")?" },
|
|
193
|
+
"+": { type: "plus", open: "(?:", close: ")+" },
|
|
194
|
+
"*": { type: "star", open: "(?:", close: ")*" },
|
|
195
|
+
"@": { type: "at", open: "(?:", close: ")" }
|
|
196
|
+
};
|
|
197
|
+
},
|
|
198
|
+
/**
|
|
199
|
+
* Create GLOB_CHARS
|
|
200
|
+
*/
|
|
201
|
+
globChars(win32) {
|
|
202
|
+
return win32 === true ? WINDOWS_CHARS : POSIX_CHARS;
|
|
203
|
+
}
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
// ../../node_modules/.pnpm/picomatch@4.0.3/node_modules/picomatch/lib/utils.js
|
|
209
|
+
var require_utils = __commonJS({
|
|
210
|
+
"../../node_modules/.pnpm/picomatch@4.0.3/node_modules/picomatch/lib/utils.js"(exports) {
|
|
211
|
+
"use strict";
|
|
212
|
+
var {
|
|
213
|
+
REGEX_BACKSLASH,
|
|
214
|
+
REGEX_REMOVE_BACKSLASH,
|
|
215
|
+
REGEX_SPECIAL_CHARS,
|
|
216
|
+
REGEX_SPECIAL_CHARS_GLOBAL
|
|
217
|
+
} = require_constants();
|
|
218
|
+
exports.isObject = (val) => val !== null && typeof val === "object" && !Array.isArray(val);
|
|
219
|
+
exports.hasRegexChars = (str) => REGEX_SPECIAL_CHARS.test(str);
|
|
220
|
+
exports.isRegexChar = (str) => str.length === 1 && exports.hasRegexChars(str);
|
|
221
|
+
exports.escapeRegex = (str) => str.replace(REGEX_SPECIAL_CHARS_GLOBAL, "\\$1");
|
|
222
|
+
exports.toPosixSlashes = (str) => str.replace(REGEX_BACKSLASH, "/");
|
|
223
|
+
exports.isWindows = () => {
|
|
224
|
+
if (typeof navigator !== "undefined" && navigator.platform) {
|
|
225
|
+
const platform = navigator.platform.toLowerCase();
|
|
226
|
+
return platform === "win32" || platform === "windows";
|
|
227
|
+
}
|
|
228
|
+
if (typeof process !== "undefined" && process.platform) {
|
|
229
|
+
return process.platform === "win32";
|
|
230
|
+
}
|
|
231
|
+
return false;
|
|
232
|
+
};
|
|
233
|
+
exports.removeBackslashes = (str) => {
|
|
234
|
+
return str.replace(REGEX_REMOVE_BACKSLASH, (match) => {
|
|
235
|
+
return match === "\\" ? "" : match;
|
|
236
|
+
});
|
|
237
|
+
};
|
|
238
|
+
exports.escapeLast = (input, char, lastIdx) => {
|
|
239
|
+
const idx = input.lastIndexOf(char, lastIdx);
|
|
240
|
+
if (idx === -1) return input;
|
|
241
|
+
if (input[idx - 1] === "\\") return exports.escapeLast(input, char, idx - 1);
|
|
242
|
+
return `${input.slice(0, idx)}\\${input.slice(idx)}`;
|
|
243
|
+
};
|
|
244
|
+
exports.removePrefix = (input, state = {}) => {
|
|
245
|
+
let output = input;
|
|
246
|
+
if (output.startsWith("./")) {
|
|
247
|
+
output = output.slice(2);
|
|
248
|
+
state.prefix = "./";
|
|
249
|
+
}
|
|
250
|
+
return output;
|
|
251
|
+
};
|
|
252
|
+
exports.wrapOutput = (input, state = {}, options = {}) => {
|
|
253
|
+
const prepend = options.contains ? "" : "^";
|
|
254
|
+
const append = options.contains ? "" : "$";
|
|
255
|
+
let output = `${prepend}(?:${input})${append}`;
|
|
256
|
+
if (state.negated === true) {
|
|
257
|
+
output = `(?:^(?!${output}).*$)`;
|
|
258
|
+
}
|
|
259
|
+
return output;
|
|
260
|
+
};
|
|
261
|
+
exports.basename = (path, { windows } = {}) => {
|
|
262
|
+
const segs = path.split(windows ? /[\\/]/ : "/");
|
|
263
|
+
const last = segs[segs.length - 1];
|
|
264
|
+
if (last === "") {
|
|
265
|
+
return segs[segs.length - 2];
|
|
266
|
+
}
|
|
267
|
+
return last;
|
|
268
|
+
};
|
|
269
|
+
}
|
|
270
|
+
});
|
|
271
|
+
|
|
272
|
+
// ../../node_modules/.pnpm/picomatch@4.0.3/node_modules/picomatch/lib/scan.js
|
|
273
|
+
var require_scan = __commonJS({
|
|
274
|
+
"../../node_modules/.pnpm/picomatch@4.0.3/node_modules/picomatch/lib/scan.js"(exports, module) {
|
|
275
|
+
"use strict";
|
|
276
|
+
var utils = require_utils();
|
|
277
|
+
var {
|
|
278
|
+
CHAR_ASTERISK,
|
|
279
|
+
/* * */
|
|
280
|
+
CHAR_AT,
|
|
281
|
+
/* @ */
|
|
282
|
+
CHAR_BACKWARD_SLASH,
|
|
283
|
+
/* \ */
|
|
284
|
+
CHAR_COMMA,
|
|
285
|
+
/* , */
|
|
286
|
+
CHAR_DOT,
|
|
287
|
+
/* . */
|
|
288
|
+
CHAR_EXCLAMATION_MARK,
|
|
289
|
+
/* ! */
|
|
290
|
+
CHAR_FORWARD_SLASH,
|
|
291
|
+
/* / */
|
|
292
|
+
CHAR_LEFT_CURLY_BRACE,
|
|
293
|
+
/* { */
|
|
294
|
+
CHAR_LEFT_PARENTHESES,
|
|
295
|
+
/* ( */
|
|
296
|
+
CHAR_LEFT_SQUARE_BRACKET,
|
|
297
|
+
/* [ */
|
|
298
|
+
CHAR_PLUS,
|
|
299
|
+
/* + */
|
|
300
|
+
CHAR_QUESTION_MARK,
|
|
301
|
+
/* ? */
|
|
302
|
+
CHAR_RIGHT_CURLY_BRACE,
|
|
303
|
+
/* } */
|
|
304
|
+
CHAR_RIGHT_PARENTHESES,
|
|
305
|
+
/* ) */
|
|
306
|
+
CHAR_RIGHT_SQUARE_BRACKET
|
|
307
|
+
/* ] */
|
|
308
|
+
} = require_constants();
|
|
309
|
+
var isPathSeparator = (code) => {
|
|
310
|
+
return code === CHAR_FORWARD_SLASH || code === CHAR_BACKWARD_SLASH;
|
|
311
|
+
};
|
|
312
|
+
var depth = (token) => {
|
|
313
|
+
if (token.isPrefix !== true) {
|
|
314
|
+
token.depth = token.isGlobstar ? Infinity : 1;
|
|
315
|
+
}
|
|
316
|
+
};
|
|
317
|
+
var scan = (input, options) => {
|
|
318
|
+
const opts = options || {};
|
|
319
|
+
const length = input.length - 1;
|
|
320
|
+
const scanToEnd = opts.parts === true || opts.scanToEnd === true;
|
|
321
|
+
const slashes = [];
|
|
322
|
+
const tokens = [];
|
|
323
|
+
const parts = [];
|
|
324
|
+
let str = input;
|
|
325
|
+
let index = -1;
|
|
326
|
+
let start = 0;
|
|
327
|
+
let lastIndex = 0;
|
|
328
|
+
let isBrace = false;
|
|
329
|
+
let isBracket = false;
|
|
330
|
+
let isGlob = false;
|
|
331
|
+
let isExtglob = false;
|
|
332
|
+
let isGlobstar = false;
|
|
333
|
+
let braceEscaped = false;
|
|
334
|
+
let backslashes = false;
|
|
335
|
+
let negated = false;
|
|
336
|
+
let negatedExtglob = false;
|
|
337
|
+
let finished = false;
|
|
338
|
+
let braces = 0;
|
|
339
|
+
let prev;
|
|
340
|
+
let code;
|
|
341
|
+
let token = { value: "", depth: 0, isGlob: false };
|
|
342
|
+
const eos = () => index >= length;
|
|
343
|
+
const peek = () => str.charCodeAt(index + 1);
|
|
344
|
+
const advance = () => {
|
|
345
|
+
prev = code;
|
|
346
|
+
return str.charCodeAt(++index);
|
|
347
|
+
};
|
|
348
|
+
while (index < length) {
|
|
349
|
+
code = advance();
|
|
350
|
+
let next;
|
|
351
|
+
if (code === CHAR_BACKWARD_SLASH) {
|
|
352
|
+
backslashes = token.backslashes = true;
|
|
353
|
+
code = advance();
|
|
354
|
+
if (code === CHAR_LEFT_CURLY_BRACE) {
|
|
355
|
+
braceEscaped = true;
|
|
356
|
+
}
|
|
357
|
+
continue;
|
|
358
|
+
}
|
|
359
|
+
if (braceEscaped === true || code === CHAR_LEFT_CURLY_BRACE) {
|
|
360
|
+
braces++;
|
|
361
|
+
while (eos() !== true && (code = advance())) {
|
|
362
|
+
if (code === CHAR_BACKWARD_SLASH) {
|
|
363
|
+
backslashes = token.backslashes = true;
|
|
364
|
+
advance();
|
|
365
|
+
continue;
|
|
366
|
+
}
|
|
367
|
+
if (code === CHAR_LEFT_CURLY_BRACE) {
|
|
368
|
+
braces++;
|
|
369
|
+
continue;
|
|
370
|
+
}
|
|
371
|
+
if (braceEscaped !== true && code === CHAR_DOT && (code = advance()) === CHAR_DOT) {
|
|
372
|
+
isBrace = token.isBrace = true;
|
|
373
|
+
isGlob = token.isGlob = true;
|
|
374
|
+
finished = true;
|
|
375
|
+
if (scanToEnd === true) {
|
|
376
|
+
continue;
|
|
377
|
+
}
|
|
378
|
+
break;
|
|
379
|
+
}
|
|
380
|
+
if (braceEscaped !== true && code === CHAR_COMMA) {
|
|
381
|
+
isBrace = token.isBrace = true;
|
|
382
|
+
isGlob = token.isGlob = true;
|
|
383
|
+
finished = true;
|
|
384
|
+
if (scanToEnd === true) {
|
|
385
|
+
continue;
|
|
386
|
+
}
|
|
387
|
+
break;
|
|
388
|
+
}
|
|
389
|
+
if (code === CHAR_RIGHT_CURLY_BRACE) {
|
|
390
|
+
braces--;
|
|
391
|
+
if (braces === 0) {
|
|
392
|
+
braceEscaped = false;
|
|
393
|
+
isBrace = token.isBrace = true;
|
|
394
|
+
finished = true;
|
|
395
|
+
break;
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
if (scanToEnd === true) {
|
|
400
|
+
continue;
|
|
401
|
+
}
|
|
402
|
+
break;
|
|
403
|
+
}
|
|
404
|
+
if (code === CHAR_FORWARD_SLASH) {
|
|
405
|
+
slashes.push(index);
|
|
406
|
+
tokens.push(token);
|
|
407
|
+
token = { value: "", depth: 0, isGlob: false };
|
|
408
|
+
if (finished === true) continue;
|
|
409
|
+
if (prev === CHAR_DOT && index === start + 1) {
|
|
410
|
+
start += 2;
|
|
411
|
+
continue;
|
|
412
|
+
}
|
|
413
|
+
lastIndex = index + 1;
|
|
414
|
+
continue;
|
|
415
|
+
}
|
|
416
|
+
if (opts.noext !== true) {
|
|
417
|
+
const isExtglobChar = code === CHAR_PLUS || code === CHAR_AT || code === CHAR_ASTERISK || code === CHAR_QUESTION_MARK || code === CHAR_EXCLAMATION_MARK;
|
|
418
|
+
if (isExtglobChar === true && peek() === CHAR_LEFT_PARENTHESES) {
|
|
419
|
+
isGlob = token.isGlob = true;
|
|
420
|
+
isExtglob = token.isExtglob = true;
|
|
421
|
+
finished = true;
|
|
422
|
+
if (code === CHAR_EXCLAMATION_MARK && index === start) {
|
|
423
|
+
negatedExtglob = true;
|
|
424
|
+
}
|
|
425
|
+
if (scanToEnd === true) {
|
|
426
|
+
while (eos() !== true && (code = advance())) {
|
|
427
|
+
if (code === CHAR_BACKWARD_SLASH) {
|
|
428
|
+
backslashes = token.backslashes = true;
|
|
429
|
+
code = advance();
|
|
430
|
+
continue;
|
|
431
|
+
}
|
|
432
|
+
if (code === CHAR_RIGHT_PARENTHESES) {
|
|
433
|
+
isGlob = token.isGlob = true;
|
|
434
|
+
finished = true;
|
|
435
|
+
break;
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
continue;
|
|
439
|
+
}
|
|
440
|
+
break;
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
if (code === CHAR_ASTERISK) {
|
|
444
|
+
if (prev === CHAR_ASTERISK) isGlobstar = token.isGlobstar = true;
|
|
445
|
+
isGlob = token.isGlob = true;
|
|
446
|
+
finished = true;
|
|
447
|
+
if (scanToEnd === true) {
|
|
448
|
+
continue;
|
|
449
|
+
}
|
|
450
|
+
break;
|
|
451
|
+
}
|
|
452
|
+
if (code === CHAR_QUESTION_MARK) {
|
|
453
|
+
isGlob = token.isGlob = true;
|
|
454
|
+
finished = true;
|
|
455
|
+
if (scanToEnd === true) {
|
|
456
|
+
continue;
|
|
457
|
+
}
|
|
458
|
+
break;
|
|
459
|
+
}
|
|
460
|
+
if (code === CHAR_LEFT_SQUARE_BRACKET) {
|
|
461
|
+
while (eos() !== true && (next = advance())) {
|
|
462
|
+
if (next === CHAR_BACKWARD_SLASH) {
|
|
463
|
+
backslashes = token.backslashes = true;
|
|
464
|
+
advance();
|
|
465
|
+
continue;
|
|
466
|
+
}
|
|
467
|
+
if (next === CHAR_RIGHT_SQUARE_BRACKET) {
|
|
468
|
+
isBracket = token.isBracket = true;
|
|
469
|
+
isGlob = token.isGlob = true;
|
|
470
|
+
finished = true;
|
|
471
|
+
break;
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
if (scanToEnd === true) {
|
|
475
|
+
continue;
|
|
476
|
+
}
|
|
477
|
+
break;
|
|
478
|
+
}
|
|
479
|
+
if (opts.nonegate !== true && code === CHAR_EXCLAMATION_MARK && index === start) {
|
|
480
|
+
negated = token.negated = true;
|
|
481
|
+
start++;
|
|
482
|
+
continue;
|
|
483
|
+
}
|
|
484
|
+
if (opts.noparen !== true && code === CHAR_LEFT_PARENTHESES) {
|
|
485
|
+
isGlob = token.isGlob = true;
|
|
486
|
+
if (scanToEnd === true) {
|
|
487
|
+
while (eos() !== true && (code = advance())) {
|
|
488
|
+
if (code === CHAR_LEFT_PARENTHESES) {
|
|
489
|
+
backslashes = token.backslashes = true;
|
|
490
|
+
code = advance();
|
|
491
|
+
continue;
|
|
492
|
+
}
|
|
493
|
+
if (code === CHAR_RIGHT_PARENTHESES) {
|
|
494
|
+
finished = true;
|
|
495
|
+
break;
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
continue;
|
|
499
|
+
}
|
|
500
|
+
break;
|
|
501
|
+
}
|
|
502
|
+
if (isGlob === true) {
|
|
503
|
+
finished = true;
|
|
504
|
+
if (scanToEnd === true) {
|
|
505
|
+
continue;
|
|
506
|
+
}
|
|
507
|
+
break;
|
|
508
|
+
}
|
|
509
|
+
}
|
|
510
|
+
if (opts.noext === true) {
|
|
511
|
+
isExtglob = false;
|
|
512
|
+
isGlob = false;
|
|
513
|
+
}
|
|
514
|
+
let base = str;
|
|
515
|
+
let prefix = "";
|
|
516
|
+
let glob = "";
|
|
517
|
+
if (start > 0) {
|
|
518
|
+
prefix = str.slice(0, start);
|
|
519
|
+
str = str.slice(start);
|
|
520
|
+
lastIndex -= start;
|
|
521
|
+
}
|
|
522
|
+
if (base && isGlob === true && lastIndex > 0) {
|
|
523
|
+
base = str.slice(0, lastIndex);
|
|
524
|
+
glob = str.slice(lastIndex);
|
|
525
|
+
} else if (isGlob === true) {
|
|
526
|
+
base = "";
|
|
527
|
+
glob = str;
|
|
528
|
+
} else {
|
|
529
|
+
base = str;
|
|
530
|
+
}
|
|
531
|
+
if (base && base !== "" && base !== "/" && base !== str) {
|
|
532
|
+
if (isPathSeparator(base.charCodeAt(base.length - 1))) {
|
|
533
|
+
base = base.slice(0, -1);
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
if (opts.unescape === true) {
|
|
537
|
+
if (glob) glob = utils.removeBackslashes(glob);
|
|
538
|
+
if (base && backslashes === true) {
|
|
539
|
+
base = utils.removeBackslashes(base);
|
|
540
|
+
}
|
|
541
|
+
}
|
|
542
|
+
const state = {
|
|
543
|
+
prefix,
|
|
544
|
+
input,
|
|
545
|
+
start,
|
|
546
|
+
base,
|
|
547
|
+
glob,
|
|
548
|
+
isBrace,
|
|
549
|
+
isBracket,
|
|
550
|
+
isGlob,
|
|
551
|
+
isExtglob,
|
|
552
|
+
isGlobstar,
|
|
553
|
+
negated,
|
|
554
|
+
negatedExtglob
|
|
555
|
+
};
|
|
556
|
+
if (opts.tokens === true) {
|
|
557
|
+
state.maxDepth = 0;
|
|
558
|
+
if (!isPathSeparator(code)) {
|
|
559
|
+
tokens.push(token);
|
|
560
|
+
}
|
|
561
|
+
state.tokens = tokens;
|
|
562
|
+
}
|
|
563
|
+
if (opts.parts === true || opts.tokens === true) {
|
|
564
|
+
let prevIndex;
|
|
565
|
+
for (let idx = 0; idx < slashes.length; idx++) {
|
|
566
|
+
const n = prevIndex ? prevIndex + 1 : start;
|
|
567
|
+
const i = slashes[idx];
|
|
568
|
+
const value = input.slice(n, i);
|
|
569
|
+
if (opts.tokens) {
|
|
570
|
+
if (idx === 0 && start !== 0) {
|
|
571
|
+
tokens[idx].isPrefix = true;
|
|
572
|
+
tokens[idx].value = prefix;
|
|
573
|
+
} else {
|
|
574
|
+
tokens[idx].value = value;
|
|
575
|
+
}
|
|
576
|
+
depth(tokens[idx]);
|
|
577
|
+
state.maxDepth += tokens[idx].depth;
|
|
578
|
+
}
|
|
579
|
+
if (idx !== 0 || value !== "") {
|
|
580
|
+
parts.push(value);
|
|
581
|
+
}
|
|
582
|
+
prevIndex = i;
|
|
583
|
+
}
|
|
584
|
+
if (prevIndex && prevIndex + 1 < input.length) {
|
|
585
|
+
const value = input.slice(prevIndex + 1);
|
|
586
|
+
parts.push(value);
|
|
587
|
+
if (opts.tokens) {
|
|
588
|
+
tokens[tokens.length - 1].value = value;
|
|
589
|
+
depth(tokens[tokens.length - 1]);
|
|
590
|
+
state.maxDepth += tokens[tokens.length - 1].depth;
|
|
591
|
+
}
|
|
592
|
+
}
|
|
593
|
+
state.slashes = slashes;
|
|
594
|
+
state.parts = parts;
|
|
595
|
+
}
|
|
596
|
+
return state;
|
|
597
|
+
};
|
|
598
|
+
module.exports = scan;
|
|
599
|
+
}
|
|
600
|
+
});
|
|
601
|
+
|
|
602
|
+
// ../../node_modules/.pnpm/picomatch@4.0.3/node_modules/picomatch/lib/parse.js
|
|
603
|
+
var require_parse = __commonJS({
|
|
604
|
+
"../../node_modules/.pnpm/picomatch@4.0.3/node_modules/picomatch/lib/parse.js"(exports, module) {
|
|
605
|
+
"use strict";
|
|
606
|
+
var constants = require_constants();
|
|
607
|
+
var utils = require_utils();
|
|
608
|
+
var {
|
|
609
|
+
MAX_LENGTH,
|
|
610
|
+
POSIX_REGEX_SOURCE,
|
|
611
|
+
REGEX_NON_SPECIAL_CHARS,
|
|
612
|
+
REGEX_SPECIAL_CHARS_BACKREF,
|
|
613
|
+
REPLACEMENTS
|
|
614
|
+
} = constants;
|
|
615
|
+
var expandRange = (args, options) => {
|
|
616
|
+
if (typeof options.expandRange === "function") {
|
|
617
|
+
return options.expandRange(...args, options);
|
|
618
|
+
}
|
|
619
|
+
args.sort();
|
|
620
|
+
const value = `[${args.join("-")}]`;
|
|
621
|
+
try {
|
|
622
|
+
new RegExp(value);
|
|
623
|
+
} catch (ex) {
|
|
624
|
+
return args.map((v) => utils.escapeRegex(v)).join("..");
|
|
625
|
+
}
|
|
626
|
+
return value;
|
|
627
|
+
};
|
|
628
|
+
var syntaxError = (type, char) => {
|
|
629
|
+
return `Missing ${type}: "${char}" - use "\\\\${char}" to match literal characters`;
|
|
630
|
+
};
|
|
631
|
+
var parse = (input, options) => {
|
|
632
|
+
if (typeof input !== "string") {
|
|
633
|
+
throw new TypeError("Expected a string");
|
|
634
|
+
}
|
|
635
|
+
input = REPLACEMENTS[input] || input;
|
|
636
|
+
const opts = { ...options };
|
|
637
|
+
const max = typeof opts.maxLength === "number" ? Math.min(MAX_LENGTH, opts.maxLength) : MAX_LENGTH;
|
|
638
|
+
let len = input.length;
|
|
639
|
+
if (len > max) {
|
|
640
|
+
throw new SyntaxError(`Input length: ${len}, exceeds maximum allowed length: ${max}`);
|
|
641
|
+
}
|
|
642
|
+
const bos = { type: "bos", value: "", output: opts.prepend || "" };
|
|
643
|
+
const tokens = [bos];
|
|
644
|
+
const capture = opts.capture ? "" : "?:";
|
|
645
|
+
const PLATFORM_CHARS = constants.globChars(opts.windows);
|
|
646
|
+
const EXTGLOB_CHARS = constants.extglobChars(PLATFORM_CHARS);
|
|
647
|
+
const {
|
|
648
|
+
DOT_LITERAL,
|
|
649
|
+
PLUS_LITERAL,
|
|
650
|
+
SLASH_LITERAL,
|
|
651
|
+
ONE_CHAR,
|
|
652
|
+
DOTS_SLASH,
|
|
653
|
+
NO_DOT,
|
|
654
|
+
NO_DOT_SLASH,
|
|
655
|
+
NO_DOTS_SLASH,
|
|
656
|
+
QMARK,
|
|
657
|
+
QMARK_NO_DOT,
|
|
658
|
+
STAR,
|
|
659
|
+
START_ANCHOR
|
|
660
|
+
} = PLATFORM_CHARS;
|
|
661
|
+
const globstar = (opts2) => {
|
|
662
|
+
return `(${capture}(?:(?!${START_ANCHOR}${opts2.dot ? DOTS_SLASH : DOT_LITERAL}).)*?)`;
|
|
663
|
+
};
|
|
664
|
+
const nodot = opts.dot ? "" : NO_DOT;
|
|
665
|
+
const qmarkNoDot = opts.dot ? QMARK : QMARK_NO_DOT;
|
|
666
|
+
let star = opts.bash === true ? globstar(opts) : STAR;
|
|
667
|
+
if (opts.capture) {
|
|
668
|
+
star = `(${star})`;
|
|
669
|
+
}
|
|
670
|
+
if (typeof opts.noext === "boolean") {
|
|
671
|
+
opts.noextglob = opts.noext;
|
|
672
|
+
}
|
|
673
|
+
const state = {
|
|
674
|
+
input,
|
|
675
|
+
index: -1,
|
|
676
|
+
start: 0,
|
|
677
|
+
dot: opts.dot === true,
|
|
678
|
+
consumed: "",
|
|
679
|
+
output: "",
|
|
680
|
+
prefix: "",
|
|
681
|
+
backtrack: false,
|
|
682
|
+
negated: false,
|
|
683
|
+
brackets: 0,
|
|
684
|
+
braces: 0,
|
|
685
|
+
parens: 0,
|
|
686
|
+
quotes: 0,
|
|
687
|
+
globstar: false,
|
|
688
|
+
tokens
|
|
689
|
+
};
|
|
690
|
+
input = utils.removePrefix(input, state);
|
|
691
|
+
len = input.length;
|
|
692
|
+
const extglobs = [];
|
|
693
|
+
const braces = [];
|
|
694
|
+
const stack = [];
|
|
695
|
+
let prev = bos;
|
|
696
|
+
let value;
|
|
697
|
+
const eos = () => state.index === len - 1;
|
|
698
|
+
const peek = state.peek = (n = 1) => input[state.index + n];
|
|
699
|
+
const advance = state.advance = () => input[++state.index] || "";
|
|
700
|
+
const remaining = () => input.slice(state.index + 1);
|
|
701
|
+
const consume = (value2 = "", num = 0) => {
|
|
702
|
+
state.consumed += value2;
|
|
703
|
+
state.index += num;
|
|
704
|
+
};
|
|
705
|
+
const append = (token) => {
|
|
706
|
+
state.output += token.output != null ? token.output : token.value;
|
|
707
|
+
consume(token.value);
|
|
708
|
+
};
|
|
709
|
+
const negate = () => {
|
|
710
|
+
let count = 1;
|
|
711
|
+
while (peek() === "!" && (peek(2) !== "(" || peek(3) === "?")) {
|
|
712
|
+
advance();
|
|
713
|
+
state.start++;
|
|
714
|
+
count++;
|
|
715
|
+
}
|
|
716
|
+
if (count % 2 === 0) {
|
|
717
|
+
return false;
|
|
718
|
+
}
|
|
719
|
+
state.negated = true;
|
|
720
|
+
state.start++;
|
|
721
|
+
return true;
|
|
722
|
+
};
|
|
723
|
+
const increment = (type) => {
|
|
724
|
+
state[type]++;
|
|
725
|
+
stack.push(type);
|
|
726
|
+
};
|
|
727
|
+
const decrement = (type) => {
|
|
728
|
+
state[type]--;
|
|
729
|
+
stack.pop();
|
|
730
|
+
};
|
|
731
|
+
const push = (tok) => {
|
|
732
|
+
if (prev.type === "globstar") {
|
|
733
|
+
const isBrace = state.braces > 0 && (tok.type === "comma" || tok.type === "brace");
|
|
734
|
+
const isExtglob = tok.extglob === true || extglobs.length && (tok.type === "pipe" || tok.type === "paren");
|
|
735
|
+
if (tok.type !== "slash" && tok.type !== "paren" && !isBrace && !isExtglob) {
|
|
736
|
+
state.output = state.output.slice(0, -prev.output.length);
|
|
737
|
+
prev.type = "star";
|
|
738
|
+
prev.value = "*";
|
|
739
|
+
prev.output = star;
|
|
740
|
+
state.output += prev.output;
|
|
741
|
+
}
|
|
742
|
+
}
|
|
743
|
+
if (extglobs.length && tok.type !== "paren") {
|
|
744
|
+
extglobs[extglobs.length - 1].inner += tok.value;
|
|
745
|
+
}
|
|
746
|
+
if (tok.value || tok.output) append(tok);
|
|
747
|
+
if (prev && prev.type === "text" && tok.type === "text") {
|
|
748
|
+
prev.output = (prev.output || prev.value) + tok.value;
|
|
749
|
+
prev.value += tok.value;
|
|
750
|
+
return;
|
|
751
|
+
}
|
|
752
|
+
tok.prev = prev;
|
|
753
|
+
tokens.push(tok);
|
|
754
|
+
prev = tok;
|
|
755
|
+
};
|
|
756
|
+
const extglobOpen = (type, value2) => {
|
|
757
|
+
const token = { ...EXTGLOB_CHARS[value2], conditions: 1, inner: "" };
|
|
758
|
+
token.prev = prev;
|
|
759
|
+
token.parens = state.parens;
|
|
760
|
+
token.output = state.output;
|
|
761
|
+
const output = (opts.capture ? "(" : "") + token.open;
|
|
762
|
+
increment("parens");
|
|
763
|
+
push({ type, value: value2, output: state.output ? "" : ONE_CHAR });
|
|
764
|
+
push({ type: "paren", extglob: true, value: advance(), output });
|
|
765
|
+
extglobs.push(token);
|
|
766
|
+
};
|
|
767
|
+
const extglobClose = (token) => {
|
|
768
|
+
let output = token.close + (opts.capture ? ")" : "");
|
|
769
|
+
let rest;
|
|
770
|
+
if (token.type === "negate") {
|
|
771
|
+
let extglobStar = star;
|
|
772
|
+
if (token.inner && token.inner.length > 1 && token.inner.includes("/")) {
|
|
773
|
+
extglobStar = globstar(opts);
|
|
774
|
+
}
|
|
775
|
+
if (extglobStar !== star || eos() || /^\)+$/.test(remaining())) {
|
|
776
|
+
output = token.close = `)$))${extglobStar}`;
|
|
777
|
+
}
|
|
778
|
+
if (token.inner.includes("*") && (rest = remaining()) && /^\.[^\\/.]+$/.test(rest)) {
|
|
779
|
+
const expression = parse(rest, { ...options, fastpaths: false }).output;
|
|
780
|
+
output = token.close = `)${expression})${extglobStar})`;
|
|
781
|
+
}
|
|
782
|
+
if (token.prev.type === "bos") {
|
|
783
|
+
state.negatedExtglob = true;
|
|
784
|
+
}
|
|
785
|
+
}
|
|
786
|
+
push({ type: "paren", extglob: true, value, output });
|
|
787
|
+
decrement("parens");
|
|
788
|
+
};
|
|
789
|
+
if (opts.fastpaths !== false && !/(^[*!]|[/()[\]{}"])/.test(input)) {
|
|
790
|
+
let backslashes = false;
|
|
791
|
+
let output = input.replace(REGEX_SPECIAL_CHARS_BACKREF, (m, esc, chars, first, rest, index) => {
|
|
792
|
+
if (first === "\\") {
|
|
793
|
+
backslashes = true;
|
|
794
|
+
return m;
|
|
795
|
+
}
|
|
796
|
+
if (first === "?") {
|
|
797
|
+
if (esc) {
|
|
798
|
+
return esc + first + (rest ? QMARK.repeat(rest.length) : "");
|
|
799
|
+
}
|
|
800
|
+
if (index === 0) {
|
|
801
|
+
return qmarkNoDot + (rest ? QMARK.repeat(rest.length) : "");
|
|
802
|
+
}
|
|
803
|
+
return QMARK.repeat(chars.length);
|
|
804
|
+
}
|
|
805
|
+
if (first === ".") {
|
|
806
|
+
return DOT_LITERAL.repeat(chars.length);
|
|
807
|
+
}
|
|
808
|
+
if (first === "*") {
|
|
809
|
+
if (esc) {
|
|
810
|
+
return esc + first + (rest ? star : "");
|
|
811
|
+
}
|
|
812
|
+
return star;
|
|
813
|
+
}
|
|
814
|
+
return esc ? m : `\\${m}`;
|
|
815
|
+
});
|
|
816
|
+
if (backslashes === true) {
|
|
817
|
+
if (opts.unescape === true) {
|
|
818
|
+
output = output.replace(/\\/g, "");
|
|
819
|
+
} else {
|
|
820
|
+
output = output.replace(/\\+/g, (m) => {
|
|
821
|
+
return m.length % 2 === 0 ? "\\\\" : m ? "\\" : "";
|
|
822
|
+
});
|
|
823
|
+
}
|
|
824
|
+
}
|
|
825
|
+
if (output === input && opts.contains === true) {
|
|
826
|
+
state.output = input;
|
|
827
|
+
return state;
|
|
828
|
+
}
|
|
829
|
+
state.output = utils.wrapOutput(output, state, options);
|
|
830
|
+
return state;
|
|
831
|
+
}
|
|
832
|
+
while (!eos()) {
|
|
833
|
+
value = advance();
|
|
834
|
+
if (value === "\0") {
|
|
835
|
+
continue;
|
|
836
|
+
}
|
|
837
|
+
if (value === "\\") {
|
|
838
|
+
const next = peek();
|
|
839
|
+
if (next === "/" && opts.bash !== true) {
|
|
840
|
+
continue;
|
|
841
|
+
}
|
|
842
|
+
if (next === "." || next === ";") {
|
|
843
|
+
continue;
|
|
844
|
+
}
|
|
845
|
+
if (!next) {
|
|
846
|
+
value += "\\";
|
|
847
|
+
push({ type: "text", value });
|
|
848
|
+
continue;
|
|
849
|
+
}
|
|
850
|
+
const match = /^\\+/.exec(remaining());
|
|
851
|
+
let slashes = 0;
|
|
852
|
+
if (match && match[0].length > 2) {
|
|
853
|
+
slashes = match[0].length;
|
|
854
|
+
state.index += slashes;
|
|
855
|
+
if (slashes % 2 !== 0) {
|
|
856
|
+
value += "\\";
|
|
857
|
+
}
|
|
858
|
+
}
|
|
859
|
+
if (opts.unescape === true) {
|
|
860
|
+
value = advance();
|
|
861
|
+
} else {
|
|
862
|
+
value += advance();
|
|
863
|
+
}
|
|
864
|
+
if (state.brackets === 0) {
|
|
865
|
+
push({ type: "text", value });
|
|
866
|
+
continue;
|
|
867
|
+
}
|
|
868
|
+
}
|
|
869
|
+
if (state.brackets > 0 && (value !== "]" || prev.value === "[" || prev.value === "[^")) {
|
|
870
|
+
if (opts.posix !== false && value === ":") {
|
|
871
|
+
const inner = prev.value.slice(1);
|
|
872
|
+
if (inner.includes("[")) {
|
|
873
|
+
prev.posix = true;
|
|
874
|
+
if (inner.includes(":")) {
|
|
875
|
+
const idx = prev.value.lastIndexOf("[");
|
|
876
|
+
const pre = prev.value.slice(0, idx);
|
|
877
|
+
const rest2 = prev.value.slice(idx + 2);
|
|
878
|
+
const posix = POSIX_REGEX_SOURCE[rest2];
|
|
879
|
+
if (posix) {
|
|
880
|
+
prev.value = pre + posix;
|
|
881
|
+
state.backtrack = true;
|
|
882
|
+
advance();
|
|
883
|
+
if (!bos.output && tokens.indexOf(prev) === 1) {
|
|
884
|
+
bos.output = ONE_CHAR;
|
|
885
|
+
}
|
|
886
|
+
continue;
|
|
887
|
+
}
|
|
888
|
+
}
|
|
889
|
+
}
|
|
890
|
+
}
|
|
891
|
+
if (value === "[" && peek() !== ":" || value === "-" && peek() === "]") {
|
|
892
|
+
value = `\\${value}`;
|
|
893
|
+
}
|
|
894
|
+
if (value === "]" && (prev.value === "[" || prev.value === "[^")) {
|
|
895
|
+
value = `\\${value}`;
|
|
896
|
+
}
|
|
897
|
+
if (opts.posix === true && value === "!" && prev.value === "[") {
|
|
898
|
+
value = "^";
|
|
899
|
+
}
|
|
900
|
+
prev.value += value;
|
|
901
|
+
append({ value });
|
|
902
|
+
continue;
|
|
903
|
+
}
|
|
904
|
+
if (state.quotes === 1 && value !== '"') {
|
|
905
|
+
value = utils.escapeRegex(value);
|
|
906
|
+
prev.value += value;
|
|
907
|
+
append({ value });
|
|
908
|
+
continue;
|
|
909
|
+
}
|
|
910
|
+
if (value === '"') {
|
|
911
|
+
state.quotes = state.quotes === 1 ? 0 : 1;
|
|
912
|
+
if (opts.keepQuotes === true) {
|
|
913
|
+
push({ type: "text", value });
|
|
914
|
+
}
|
|
915
|
+
continue;
|
|
916
|
+
}
|
|
917
|
+
if (value === "(") {
|
|
918
|
+
increment("parens");
|
|
919
|
+
push({ type: "paren", value });
|
|
920
|
+
continue;
|
|
921
|
+
}
|
|
922
|
+
if (value === ")") {
|
|
923
|
+
if (state.parens === 0 && opts.strictBrackets === true) {
|
|
924
|
+
throw new SyntaxError(syntaxError("opening", "("));
|
|
925
|
+
}
|
|
926
|
+
const extglob = extglobs[extglobs.length - 1];
|
|
927
|
+
if (extglob && state.parens === extglob.parens + 1) {
|
|
928
|
+
extglobClose(extglobs.pop());
|
|
929
|
+
continue;
|
|
930
|
+
}
|
|
931
|
+
push({ type: "paren", value, output: state.parens ? ")" : "\\)" });
|
|
932
|
+
decrement("parens");
|
|
933
|
+
continue;
|
|
934
|
+
}
|
|
935
|
+
if (value === "[") {
|
|
936
|
+
if (opts.nobracket === true || !remaining().includes("]")) {
|
|
937
|
+
if (opts.nobracket !== true && opts.strictBrackets === true) {
|
|
938
|
+
throw new SyntaxError(syntaxError("closing", "]"));
|
|
939
|
+
}
|
|
940
|
+
value = `\\${value}`;
|
|
941
|
+
} else {
|
|
942
|
+
increment("brackets");
|
|
943
|
+
}
|
|
944
|
+
push({ type: "bracket", value });
|
|
945
|
+
continue;
|
|
946
|
+
}
|
|
947
|
+
if (value === "]") {
|
|
948
|
+
if (opts.nobracket === true || prev && prev.type === "bracket" && prev.value.length === 1) {
|
|
949
|
+
push({ type: "text", value, output: `\\${value}` });
|
|
950
|
+
continue;
|
|
951
|
+
}
|
|
952
|
+
if (state.brackets === 0) {
|
|
953
|
+
if (opts.strictBrackets === true) {
|
|
954
|
+
throw new SyntaxError(syntaxError("opening", "["));
|
|
955
|
+
}
|
|
956
|
+
push({ type: "text", value, output: `\\${value}` });
|
|
957
|
+
continue;
|
|
958
|
+
}
|
|
959
|
+
decrement("brackets");
|
|
960
|
+
const prevValue = prev.value.slice(1);
|
|
961
|
+
if (prev.posix !== true && prevValue[0] === "^" && !prevValue.includes("/")) {
|
|
962
|
+
value = `/${value}`;
|
|
963
|
+
}
|
|
964
|
+
prev.value += value;
|
|
965
|
+
append({ value });
|
|
966
|
+
if (opts.literalBrackets === false || utils.hasRegexChars(prevValue)) {
|
|
967
|
+
continue;
|
|
968
|
+
}
|
|
969
|
+
const escaped = utils.escapeRegex(prev.value);
|
|
970
|
+
state.output = state.output.slice(0, -prev.value.length);
|
|
971
|
+
if (opts.literalBrackets === true) {
|
|
972
|
+
state.output += escaped;
|
|
973
|
+
prev.value = escaped;
|
|
974
|
+
continue;
|
|
975
|
+
}
|
|
976
|
+
prev.value = `(${capture}${escaped}|${prev.value})`;
|
|
977
|
+
state.output += prev.value;
|
|
978
|
+
continue;
|
|
979
|
+
}
|
|
980
|
+
if (value === "{" && opts.nobrace !== true) {
|
|
981
|
+
increment("braces");
|
|
982
|
+
const open = {
|
|
983
|
+
type: "brace",
|
|
984
|
+
value,
|
|
985
|
+
output: "(",
|
|
986
|
+
outputIndex: state.output.length,
|
|
987
|
+
tokensIndex: state.tokens.length
|
|
988
|
+
};
|
|
989
|
+
braces.push(open);
|
|
990
|
+
push(open);
|
|
991
|
+
continue;
|
|
992
|
+
}
|
|
993
|
+
if (value === "}") {
|
|
994
|
+
const brace = braces[braces.length - 1];
|
|
995
|
+
if (opts.nobrace === true || !brace) {
|
|
996
|
+
push({ type: "text", value, output: value });
|
|
997
|
+
continue;
|
|
998
|
+
}
|
|
999
|
+
let output = ")";
|
|
1000
|
+
if (brace.dots === true) {
|
|
1001
|
+
const arr = tokens.slice();
|
|
1002
|
+
const range = [];
|
|
1003
|
+
for (let i = arr.length - 1; i >= 0; i--) {
|
|
1004
|
+
tokens.pop();
|
|
1005
|
+
if (arr[i].type === "brace") {
|
|
1006
|
+
break;
|
|
1007
|
+
}
|
|
1008
|
+
if (arr[i].type !== "dots") {
|
|
1009
|
+
range.unshift(arr[i].value);
|
|
1010
|
+
}
|
|
1011
|
+
}
|
|
1012
|
+
output = expandRange(range, opts);
|
|
1013
|
+
state.backtrack = true;
|
|
1014
|
+
}
|
|
1015
|
+
if (brace.comma !== true && brace.dots !== true) {
|
|
1016
|
+
const out = state.output.slice(0, brace.outputIndex);
|
|
1017
|
+
const toks = state.tokens.slice(brace.tokensIndex);
|
|
1018
|
+
brace.value = brace.output = "\\{";
|
|
1019
|
+
value = output = "\\}";
|
|
1020
|
+
state.output = out;
|
|
1021
|
+
for (const t of toks) {
|
|
1022
|
+
state.output += t.output || t.value;
|
|
1023
|
+
}
|
|
1024
|
+
}
|
|
1025
|
+
push({ type: "brace", value, output });
|
|
1026
|
+
decrement("braces");
|
|
1027
|
+
braces.pop();
|
|
1028
|
+
continue;
|
|
1029
|
+
}
|
|
1030
|
+
if (value === "|") {
|
|
1031
|
+
if (extglobs.length > 0) {
|
|
1032
|
+
extglobs[extglobs.length - 1].conditions++;
|
|
1033
|
+
}
|
|
1034
|
+
push({ type: "text", value });
|
|
1035
|
+
continue;
|
|
1036
|
+
}
|
|
1037
|
+
if (value === ",") {
|
|
1038
|
+
let output = value;
|
|
1039
|
+
const brace = braces[braces.length - 1];
|
|
1040
|
+
if (brace && stack[stack.length - 1] === "braces") {
|
|
1041
|
+
brace.comma = true;
|
|
1042
|
+
output = "|";
|
|
1043
|
+
}
|
|
1044
|
+
push({ type: "comma", value, output });
|
|
1045
|
+
continue;
|
|
1046
|
+
}
|
|
1047
|
+
if (value === "/") {
|
|
1048
|
+
if (prev.type === "dot" && state.index === state.start + 1) {
|
|
1049
|
+
state.start = state.index + 1;
|
|
1050
|
+
state.consumed = "";
|
|
1051
|
+
state.output = "";
|
|
1052
|
+
tokens.pop();
|
|
1053
|
+
prev = bos;
|
|
1054
|
+
continue;
|
|
1055
|
+
}
|
|
1056
|
+
push({ type: "slash", value, output: SLASH_LITERAL });
|
|
1057
|
+
continue;
|
|
1058
|
+
}
|
|
1059
|
+
if (value === ".") {
|
|
1060
|
+
if (state.braces > 0 && prev.type === "dot") {
|
|
1061
|
+
if (prev.value === ".") prev.output = DOT_LITERAL;
|
|
1062
|
+
const brace = braces[braces.length - 1];
|
|
1063
|
+
prev.type = "dots";
|
|
1064
|
+
prev.output += value;
|
|
1065
|
+
prev.value += value;
|
|
1066
|
+
brace.dots = true;
|
|
1067
|
+
continue;
|
|
1068
|
+
}
|
|
1069
|
+
if (state.braces + state.parens === 0 && prev.type !== "bos" && prev.type !== "slash") {
|
|
1070
|
+
push({ type: "text", value, output: DOT_LITERAL });
|
|
1071
|
+
continue;
|
|
1072
|
+
}
|
|
1073
|
+
push({ type: "dot", value, output: DOT_LITERAL });
|
|
1074
|
+
continue;
|
|
1075
|
+
}
|
|
1076
|
+
if (value === "?") {
|
|
1077
|
+
const isGroup = prev && prev.value === "(";
|
|
1078
|
+
if (!isGroup && opts.noextglob !== true && peek() === "(" && peek(2) !== "?") {
|
|
1079
|
+
extglobOpen("qmark", value);
|
|
1080
|
+
continue;
|
|
1081
|
+
}
|
|
1082
|
+
if (prev && prev.type === "paren") {
|
|
1083
|
+
const next = peek();
|
|
1084
|
+
let output = value;
|
|
1085
|
+
if (prev.value === "(" && !/[!=<:]/.test(next) || next === "<" && !/<([!=]|\w+>)/.test(remaining())) {
|
|
1086
|
+
output = `\\${value}`;
|
|
1087
|
+
}
|
|
1088
|
+
push({ type: "text", value, output });
|
|
1089
|
+
continue;
|
|
1090
|
+
}
|
|
1091
|
+
if (opts.dot !== true && (prev.type === "slash" || prev.type === "bos")) {
|
|
1092
|
+
push({ type: "qmark", value, output: QMARK_NO_DOT });
|
|
1093
|
+
continue;
|
|
1094
|
+
}
|
|
1095
|
+
push({ type: "qmark", value, output: QMARK });
|
|
1096
|
+
continue;
|
|
1097
|
+
}
|
|
1098
|
+
if (value === "!") {
|
|
1099
|
+
if (opts.noextglob !== true && peek() === "(") {
|
|
1100
|
+
if (peek(2) !== "?" || !/[!=<:]/.test(peek(3))) {
|
|
1101
|
+
extglobOpen("negate", value);
|
|
1102
|
+
continue;
|
|
1103
|
+
}
|
|
1104
|
+
}
|
|
1105
|
+
if (opts.nonegate !== true && state.index === 0) {
|
|
1106
|
+
negate();
|
|
1107
|
+
continue;
|
|
1108
|
+
}
|
|
1109
|
+
}
|
|
1110
|
+
if (value === "+") {
|
|
1111
|
+
if (opts.noextglob !== true && peek() === "(" && peek(2) !== "?") {
|
|
1112
|
+
extglobOpen("plus", value);
|
|
1113
|
+
continue;
|
|
1114
|
+
}
|
|
1115
|
+
if (prev && prev.value === "(" || opts.regex === false) {
|
|
1116
|
+
push({ type: "plus", value, output: PLUS_LITERAL });
|
|
1117
|
+
continue;
|
|
1118
|
+
}
|
|
1119
|
+
if (prev && (prev.type === "bracket" || prev.type === "paren" || prev.type === "brace") || state.parens > 0) {
|
|
1120
|
+
push({ type: "plus", value });
|
|
1121
|
+
continue;
|
|
1122
|
+
}
|
|
1123
|
+
push({ type: "plus", value: PLUS_LITERAL });
|
|
1124
|
+
continue;
|
|
1125
|
+
}
|
|
1126
|
+
if (value === "@") {
|
|
1127
|
+
if (opts.noextglob !== true && peek() === "(" && peek(2) !== "?") {
|
|
1128
|
+
push({ type: "at", extglob: true, value, output: "" });
|
|
1129
|
+
continue;
|
|
1130
|
+
}
|
|
1131
|
+
push({ type: "text", value });
|
|
1132
|
+
continue;
|
|
1133
|
+
}
|
|
1134
|
+
if (value !== "*") {
|
|
1135
|
+
if (value === "$" || value === "^") {
|
|
1136
|
+
value = `\\${value}`;
|
|
1137
|
+
}
|
|
1138
|
+
const match = REGEX_NON_SPECIAL_CHARS.exec(remaining());
|
|
1139
|
+
if (match) {
|
|
1140
|
+
value += match[0];
|
|
1141
|
+
state.index += match[0].length;
|
|
1142
|
+
}
|
|
1143
|
+
push({ type: "text", value });
|
|
1144
|
+
continue;
|
|
1145
|
+
}
|
|
1146
|
+
if (prev && (prev.type === "globstar" || prev.star === true)) {
|
|
1147
|
+
prev.type = "star";
|
|
1148
|
+
prev.star = true;
|
|
1149
|
+
prev.value += value;
|
|
1150
|
+
prev.output = star;
|
|
1151
|
+
state.backtrack = true;
|
|
1152
|
+
state.globstar = true;
|
|
1153
|
+
consume(value);
|
|
1154
|
+
continue;
|
|
1155
|
+
}
|
|
1156
|
+
let rest = remaining();
|
|
1157
|
+
if (opts.noextglob !== true && /^\([^?]/.test(rest)) {
|
|
1158
|
+
extglobOpen("star", value);
|
|
1159
|
+
continue;
|
|
1160
|
+
}
|
|
1161
|
+
if (prev.type === "star") {
|
|
1162
|
+
if (opts.noglobstar === true) {
|
|
1163
|
+
consume(value);
|
|
1164
|
+
continue;
|
|
1165
|
+
}
|
|
1166
|
+
const prior = prev.prev;
|
|
1167
|
+
const before = prior.prev;
|
|
1168
|
+
const isStart = prior.type === "slash" || prior.type === "bos";
|
|
1169
|
+
const afterStar = before && (before.type === "star" || before.type === "globstar");
|
|
1170
|
+
if (opts.bash === true && (!isStart || rest[0] && rest[0] !== "/")) {
|
|
1171
|
+
push({ type: "star", value, output: "" });
|
|
1172
|
+
continue;
|
|
1173
|
+
}
|
|
1174
|
+
const isBrace = state.braces > 0 && (prior.type === "comma" || prior.type === "brace");
|
|
1175
|
+
const isExtglob = extglobs.length && (prior.type === "pipe" || prior.type === "paren");
|
|
1176
|
+
if (!isStart && prior.type !== "paren" && !isBrace && !isExtglob) {
|
|
1177
|
+
push({ type: "star", value, output: "" });
|
|
1178
|
+
continue;
|
|
1179
|
+
}
|
|
1180
|
+
while (rest.slice(0, 3) === "/**") {
|
|
1181
|
+
const after = input[state.index + 4];
|
|
1182
|
+
if (after && after !== "/") {
|
|
1183
|
+
break;
|
|
1184
|
+
}
|
|
1185
|
+
rest = rest.slice(3);
|
|
1186
|
+
consume("/**", 3);
|
|
1187
|
+
}
|
|
1188
|
+
if (prior.type === "bos" && eos()) {
|
|
1189
|
+
prev.type = "globstar";
|
|
1190
|
+
prev.value += value;
|
|
1191
|
+
prev.output = globstar(opts);
|
|
1192
|
+
state.output = prev.output;
|
|
1193
|
+
state.globstar = true;
|
|
1194
|
+
consume(value);
|
|
1195
|
+
continue;
|
|
1196
|
+
}
|
|
1197
|
+
if (prior.type === "slash" && prior.prev.type !== "bos" && !afterStar && eos()) {
|
|
1198
|
+
state.output = state.output.slice(0, -(prior.output + prev.output).length);
|
|
1199
|
+
prior.output = `(?:${prior.output}`;
|
|
1200
|
+
prev.type = "globstar";
|
|
1201
|
+
prev.output = globstar(opts) + (opts.strictSlashes ? ")" : "|$)");
|
|
1202
|
+
prev.value += value;
|
|
1203
|
+
state.globstar = true;
|
|
1204
|
+
state.output += prior.output + prev.output;
|
|
1205
|
+
consume(value);
|
|
1206
|
+
continue;
|
|
1207
|
+
}
|
|
1208
|
+
if (prior.type === "slash" && prior.prev.type !== "bos" && rest[0] === "/") {
|
|
1209
|
+
const end = rest[1] !== void 0 ? "|$" : "";
|
|
1210
|
+
state.output = state.output.slice(0, -(prior.output + prev.output).length);
|
|
1211
|
+
prior.output = `(?:${prior.output}`;
|
|
1212
|
+
prev.type = "globstar";
|
|
1213
|
+
prev.output = `${globstar(opts)}${SLASH_LITERAL}|${SLASH_LITERAL}${end})`;
|
|
1214
|
+
prev.value += value;
|
|
1215
|
+
state.output += prior.output + prev.output;
|
|
1216
|
+
state.globstar = true;
|
|
1217
|
+
consume(value + advance());
|
|
1218
|
+
push({ type: "slash", value: "/", output: "" });
|
|
1219
|
+
continue;
|
|
1220
|
+
}
|
|
1221
|
+
if (prior.type === "bos" && rest[0] === "/") {
|
|
1222
|
+
prev.type = "globstar";
|
|
1223
|
+
prev.value += value;
|
|
1224
|
+
prev.output = `(?:^|${SLASH_LITERAL}|${globstar(opts)}${SLASH_LITERAL})`;
|
|
1225
|
+
state.output = prev.output;
|
|
1226
|
+
state.globstar = true;
|
|
1227
|
+
consume(value + advance());
|
|
1228
|
+
push({ type: "slash", value: "/", output: "" });
|
|
1229
|
+
continue;
|
|
1230
|
+
}
|
|
1231
|
+
state.output = state.output.slice(0, -prev.output.length);
|
|
1232
|
+
prev.type = "globstar";
|
|
1233
|
+
prev.output = globstar(opts);
|
|
1234
|
+
prev.value += value;
|
|
1235
|
+
state.output += prev.output;
|
|
1236
|
+
state.globstar = true;
|
|
1237
|
+
consume(value);
|
|
1238
|
+
continue;
|
|
1239
|
+
}
|
|
1240
|
+
const token = { type: "star", value, output: star };
|
|
1241
|
+
if (opts.bash === true) {
|
|
1242
|
+
token.output = ".*?";
|
|
1243
|
+
if (prev.type === "bos" || prev.type === "slash") {
|
|
1244
|
+
token.output = nodot + token.output;
|
|
1245
|
+
}
|
|
1246
|
+
push(token);
|
|
1247
|
+
continue;
|
|
1248
|
+
}
|
|
1249
|
+
if (prev && (prev.type === "bracket" || prev.type === "paren") && opts.regex === true) {
|
|
1250
|
+
token.output = value;
|
|
1251
|
+
push(token);
|
|
1252
|
+
continue;
|
|
1253
|
+
}
|
|
1254
|
+
if (state.index === state.start || prev.type === "slash" || prev.type === "dot") {
|
|
1255
|
+
if (prev.type === "dot") {
|
|
1256
|
+
state.output += NO_DOT_SLASH;
|
|
1257
|
+
prev.output += NO_DOT_SLASH;
|
|
1258
|
+
} else if (opts.dot === true) {
|
|
1259
|
+
state.output += NO_DOTS_SLASH;
|
|
1260
|
+
prev.output += NO_DOTS_SLASH;
|
|
1261
|
+
} else {
|
|
1262
|
+
state.output += nodot;
|
|
1263
|
+
prev.output += nodot;
|
|
1264
|
+
}
|
|
1265
|
+
if (peek() !== "*") {
|
|
1266
|
+
state.output += ONE_CHAR;
|
|
1267
|
+
prev.output += ONE_CHAR;
|
|
1268
|
+
}
|
|
1269
|
+
}
|
|
1270
|
+
push(token);
|
|
1271
|
+
}
|
|
1272
|
+
while (state.brackets > 0) {
|
|
1273
|
+
if (opts.strictBrackets === true) throw new SyntaxError(syntaxError("closing", "]"));
|
|
1274
|
+
state.output = utils.escapeLast(state.output, "[");
|
|
1275
|
+
decrement("brackets");
|
|
1276
|
+
}
|
|
1277
|
+
while (state.parens > 0) {
|
|
1278
|
+
if (opts.strictBrackets === true) throw new SyntaxError(syntaxError("closing", ")"));
|
|
1279
|
+
state.output = utils.escapeLast(state.output, "(");
|
|
1280
|
+
decrement("parens");
|
|
1281
|
+
}
|
|
1282
|
+
while (state.braces > 0) {
|
|
1283
|
+
if (opts.strictBrackets === true) throw new SyntaxError(syntaxError("closing", "}"));
|
|
1284
|
+
state.output = utils.escapeLast(state.output, "{");
|
|
1285
|
+
decrement("braces");
|
|
1286
|
+
}
|
|
1287
|
+
if (opts.strictSlashes !== true && (prev.type === "star" || prev.type === "bracket")) {
|
|
1288
|
+
push({ type: "maybe_slash", value: "", output: `${SLASH_LITERAL}?` });
|
|
1289
|
+
}
|
|
1290
|
+
if (state.backtrack === true) {
|
|
1291
|
+
state.output = "";
|
|
1292
|
+
for (const token of state.tokens) {
|
|
1293
|
+
state.output += token.output != null ? token.output : token.value;
|
|
1294
|
+
if (token.suffix) {
|
|
1295
|
+
state.output += token.suffix;
|
|
1296
|
+
}
|
|
1297
|
+
}
|
|
1298
|
+
}
|
|
1299
|
+
return state;
|
|
1300
|
+
};
|
|
1301
|
+
parse.fastpaths = (input, options) => {
|
|
1302
|
+
const opts = { ...options };
|
|
1303
|
+
const max = typeof opts.maxLength === "number" ? Math.min(MAX_LENGTH, opts.maxLength) : MAX_LENGTH;
|
|
1304
|
+
const len = input.length;
|
|
1305
|
+
if (len > max) {
|
|
1306
|
+
throw new SyntaxError(`Input length: ${len}, exceeds maximum allowed length: ${max}`);
|
|
1307
|
+
}
|
|
1308
|
+
input = REPLACEMENTS[input] || input;
|
|
1309
|
+
const {
|
|
1310
|
+
DOT_LITERAL,
|
|
1311
|
+
SLASH_LITERAL,
|
|
1312
|
+
ONE_CHAR,
|
|
1313
|
+
DOTS_SLASH,
|
|
1314
|
+
NO_DOT,
|
|
1315
|
+
NO_DOTS,
|
|
1316
|
+
NO_DOTS_SLASH,
|
|
1317
|
+
STAR,
|
|
1318
|
+
START_ANCHOR
|
|
1319
|
+
} = constants.globChars(opts.windows);
|
|
1320
|
+
const nodot = opts.dot ? NO_DOTS : NO_DOT;
|
|
1321
|
+
const slashDot = opts.dot ? NO_DOTS_SLASH : NO_DOT;
|
|
1322
|
+
const capture = opts.capture ? "" : "?:";
|
|
1323
|
+
const state = { negated: false, prefix: "" };
|
|
1324
|
+
let star = opts.bash === true ? ".*?" : STAR;
|
|
1325
|
+
if (opts.capture) {
|
|
1326
|
+
star = `(${star})`;
|
|
1327
|
+
}
|
|
1328
|
+
const globstar = (opts2) => {
|
|
1329
|
+
if (opts2.noglobstar === true) return star;
|
|
1330
|
+
return `(${capture}(?:(?!${START_ANCHOR}${opts2.dot ? DOTS_SLASH : DOT_LITERAL}).)*?)`;
|
|
1331
|
+
};
|
|
1332
|
+
const create = (str) => {
|
|
1333
|
+
switch (str) {
|
|
1334
|
+
case "*":
|
|
1335
|
+
return `${nodot}${ONE_CHAR}${star}`;
|
|
1336
|
+
case ".*":
|
|
1337
|
+
return `${DOT_LITERAL}${ONE_CHAR}${star}`;
|
|
1338
|
+
case "*.*":
|
|
1339
|
+
return `${nodot}${star}${DOT_LITERAL}${ONE_CHAR}${star}`;
|
|
1340
|
+
case "*/*":
|
|
1341
|
+
return `${nodot}${star}${SLASH_LITERAL}${ONE_CHAR}${slashDot}${star}`;
|
|
1342
|
+
case "**":
|
|
1343
|
+
return nodot + globstar(opts);
|
|
1344
|
+
case "**/*":
|
|
1345
|
+
return `(?:${nodot}${globstar(opts)}${SLASH_LITERAL})?${slashDot}${ONE_CHAR}${star}`;
|
|
1346
|
+
case "**/*.*":
|
|
1347
|
+
return `(?:${nodot}${globstar(opts)}${SLASH_LITERAL})?${slashDot}${star}${DOT_LITERAL}${ONE_CHAR}${star}`;
|
|
1348
|
+
case "**/.*":
|
|
1349
|
+
return `(?:${nodot}${globstar(opts)}${SLASH_LITERAL})?${DOT_LITERAL}${ONE_CHAR}${star}`;
|
|
1350
|
+
default: {
|
|
1351
|
+
const match = /^(.*?)\.(\w+)$/.exec(str);
|
|
1352
|
+
if (!match) return;
|
|
1353
|
+
const source2 = create(match[1]);
|
|
1354
|
+
if (!source2) return;
|
|
1355
|
+
return source2 + DOT_LITERAL + match[2];
|
|
1356
|
+
}
|
|
1357
|
+
}
|
|
1358
|
+
};
|
|
1359
|
+
const output = utils.removePrefix(input, state);
|
|
1360
|
+
let source = create(output);
|
|
1361
|
+
if (source && opts.strictSlashes !== true) {
|
|
1362
|
+
source += `${SLASH_LITERAL}?`;
|
|
1363
|
+
}
|
|
1364
|
+
return source;
|
|
1365
|
+
};
|
|
1366
|
+
module.exports = parse;
|
|
1367
|
+
}
|
|
1368
|
+
});
|
|
1369
|
+
|
|
1370
|
+
// ../../node_modules/.pnpm/picomatch@4.0.3/node_modules/picomatch/lib/picomatch.js
|
|
1371
|
+
var require_picomatch = __commonJS({
|
|
1372
|
+
"../../node_modules/.pnpm/picomatch@4.0.3/node_modules/picomatch/lib/picomatch.js"(exports, module) {
|
|
1373
|
+
"use strict";
|
|
1374
|
+
var scan = require_scan();
|
|
1375
|
+
var parse = require_parse();
|
|
1376
|
+
var utils = require_utils();
|
|
1377
|
+
var constants = require_constants();
|
|
1378
|
+
var isObject = (val) => val && typeof val === "object" && !Array.isArray(val);
|
|
1379
|
+
var picomatch2 = (glob, options, returnState = false) => {
|
|
1380
|
+
if (Array.isArray(glob)) {
|
|
1381
|
+
const fns = glob.map((input) => picomatch2(input, options, returnState));
|
|
1382
|
+
const arrayMatcher = (str) => {
|
|
1383
|
+
for (const isMatch of fns) {
|
|
1384
|
+
const state2 = isMatch(str);
|
|
1385
|
+
if (state2) return state2;
|
|
1386
|
+
}
|
|
1387
|
+
return false;
|
|
1388
|
+
};
|
|
1389
|
+
return arrayMatcher;
|
|
1390
|
+
}
|
|
1391
|
+
const isState = isObject(glob) && glob.tokens && glob.input;
|
|
1392
|
+
if (glob === "" || typeof glob !== "string" && !isState) {
|
|
1393
|
+
throw new TypeError("Expected pattern to be a non-empty string");
|
|
1394
|
+
}
|
|
1395
|
+
const opts = options || {};
|
|
1396
|
+
const posix = opts.windows;
|
|
1397
|
+
const regex = isState ? picomatch2.compileRe(glob, options) : picomatch2.makeRe(glob, options, false, true);
|
|
1398
|
+
const state = regex.state;
|
|
1399
|
+
delete regex.state;
|
|
1400
|
+
let isIgnored = () => false;
|
|
1401
|
+
if (opts.ignore) {
|
|
1402
|
+
const ignoreOpts = { ...options, ignore: null, onMatch: null, onResult: null };
|
|
1403
|
+
isIgnored = picomatch2(opts.ignore, ignoreOpts, returnState);
|
|
1404
|
+
}
|
|
1405
|
+
const matcher = (input, returnObject = false) => {
|
|
1406
|
+
const { isMatch, match, output } = picomatch2.test(input, regex, options, { glob, posix });
|
|
1407
|
+
const result = { glob, state, regex, posix, input, output, match, isMatch };
|
|
1408
|
+
if (typeof opts.onResult === "function") {
|
|
1409
|
+
opts.onResult(result);
|
|
1410
|
+
}
|
|
1411
|
+
if (isMatch === false) {
|
|
1412
|
+
result.isMatch = false;
|
|
1413
|
+
return returnObject ? result : false;
|
|
1414
|
+
}
|
|
1415
|
+
if (isIgnored(input)) {
|
|
1416
|
+
if (typeof opts.onIgnore === "function") {
|
|
1417
|
+
opts.onIgnore(result);
|
|
1418
|
+
}
|
|
1419
|
+
result.isMatch = false;
|
|
1420
|
+
return returnObject ? result : false;
|
|
1421
|
+
}
|
|
1422
|
+
if (typeof opts.onMatch === "function") {
|
|
1423
|
+
opts.onMatch(result);
|
|
1424
|
+
}
|
|
1425
|
+
return returnObject ? result : true;
|
|
1426
|
+
};
|
|
1427
|
+
if (returnState) {
|
|
1428
|
+
matcher.state = state;
|
|
1429
|
+
}
|
|
1430
|
+
return matcher;
|
|
1431
|
+
};
|
|
1432
|
+
picomatch2.test = (input, regex, options, { glob, posix } = {}) => {
|
|
1433
|
+
if (typeof input !== "string") {
|
|
1434
|
+
throw new TypeError("Expected input to be a string");
|
|
1435
|
+
}
|
|
1436
|
+
if (input === "") {
|
|
1437
|
+
return { isMatch: false, output: "" };
|
|
1438
|
+
}
|
|
1439
|
+
const opts = options || {};
|
|
1440
|
+
const format = opts.format || (posix ? utils.toPosixSlashes : null);
|
|
1441
|
+
let match = input === glob;
|
|
1442
|
+
let output = match && format ? format(input) : input;
|
|
1443
|
+
if (match === false) {
|
|
1444
|
+
output = format ? format(input) : input;
|
|
1445
|
+
match = output === glob;
|
|
1446
|
+
}
|
|
1447
|
+
if (match === false || opts.capture === true) {
|
|
1448
|
+
if (opts.matchBase === true || opts.basename === true) {
|
|
1449
|
+
match = picomatch2.matchBase(input, regex, options, posix);
|
|
1450
|
+
} else {
|
|
1451
|
+
match = regex.exec(output);
|
|
1452
|
+
}
|
|
1453
|
+
}
|
|
1454
|
+
return { isMatch: Boolean(match), match, output };
|
|
1455
|
+
};
|
|
1456
|
+
picomatch2.matchBase = (input, glob, options) => {
|
|
1457
|
+
const regex = glob instanceof RegExp ? glob : picomatch2.makeRe(glob, options);
|
|
1458
|
+
return regex.test(utils.basename(input));
|
|
1459
|
+
};
|
|
1460
|
+
picomatch2.isMatch = (str, patterns, options) => picomatch2(patterns, options)(str);
|
|
1461
|
+
picomatch2.parse = (pattern, options) => {
|
|
1462
|
+
if (Array.isArray(pattern)) return pattern.map((p) => picomatch2.parse(p, options));
|
|
1463
|
+
return parse(pattern, { ...options, fastpaths: false });
|
|
1464
|
+
};
|
|
1465
|
+
picomatch2.scan = (input, options) => scan(input, options);
|
|
1466
|
+
picomatch2.compileRe = (state, options, returnOutput = false, returnState = false) => {
|
|
1467
|
+
if (returnOutput === true) {
|
|
1468
|
+
return state.output;
|
|
1469
|
+
}
|
|
1470
|
+
const opts = options || {};
|
|
1471
|
+
const prepend = opts.contains ? "" : "^";
|
|
1472
|
+
const append = opts.contains ? "" : "$";
|
|
1473
|
+
let source = `${prepend}(?:${state.output})${append}`;
|
|
1474
|
+
if (state && state.negated === true) {
|
|
1475
|
+
source = `^(?!${source}).*$`;
|
|
1476
|
+
}
|
|
1477
|
+
const regex = picomatch2.toRegex(source, options);
|
|
1478
|
+
if (returnState === true) {
|
|
1479
|
+
regex.state = state;
|
|
1480
|
+
}
|
|
1481
|
+
return regex;
|
|
1482
|
+
};
|
|
1483
|
+
picomatch2.makeRe = (input, options = {}, returnOutput = false, returnState = false) => {
|
|
1484
|
+
if (!input || typeof input !== "string") {
|
|
1485
|
+
throw new TypeError("Expected a non-empty string");
|
|
1486
|
+
}
|
|
1487
|
+
let parsed = { negated: false, fastpaths: true };
|
|
1488
|
+
if (options.fastpaths !== false && (input[0] === "." || input[0] === "*")) {
|
|
1489
|
+
parsed.output = parse.fastpaths(input, options);
|
|
1490
|
+
}
|
|
1491
|
+
if (!parsed.output) {
|
|
1492
|
+
parsed = parse(input, options);
|
|
1493
|
+
}
|
|
1494
|
+
return picomatch2.compileRe(parsed, options, returnOutput, returnState);
|
|
1495
|
+
};
|
|
1496
|
+
picomatch2.toRegex = (source, options) => {
|
|
1497
|
+
try {
|
|
1498
|
+
const opts = options || {};
|
|
1499
|
+
return new RegExp(source, opts.flags || (opts.nocase ? "i" : ""));
|
|
1500
|
+
} catch (err) {
|
|
1501
|
+
if (options && options.debug === true) throw err;
|
|
1502
|
+
return /$^/;
|
|
1503
|
+
}
|
|
1504
|
+
};
|
|
1505
|
+
picomatch2.constants = constants;
|
|
1506
|
+
module.exports = picomatch2;
|
|
1507
|
+
}
|
|
1508
|
+
});
|
|
1509
|
+
|
|
1510
|
+
// ../../node_modules/.pnpm/picomatch@4.0.3/node_modules/picomatch/index.js
|
|
1511
|
+
var require_picomatch2 = __commonJS({
|
|
1512
|
+
"../../node_modules/.pnpm/picomatch@4.0.3/node_modules/picomatch/index.js"(exports, module) {
|
|
1513
|
+
"use strict";
|
|
1514
|
+
var pico = require_picomatch();
|
|
1515
|
+
var utils = require_utils();
|
|
1516
|
+
function picomatch2(glob, options, returnState = false) {
|
|
1517
|
+
if (options && (options.windows === null || options.windows === void 0)) {
|
|
1518
|
+
options = { ...options, windows: utils.isWindows() };
|
|
1519
|
+
}
|
|
1520
|
+
return pico(glob, options, returnState);
|
|
1521
|
+
}
|
|
1522
|
+
Object.assign(picomatch2, pico);
|
|
1523
|
+
module.exports = picomatch2;
|
|
1524
|
+
}
|
|
1525
|
+
});
|
|
1526
|
+
|
|
1527
|
+
// ../../packages/guards-engine/dist/index.js
|
|
1528
|
+
import { parse as parseYaml } from "yaml";
|
|
1529
|
+
import { readFileSync, existsSync } from "fs";
|
|
1530
|
+
var import_picomatch = __toESM(require_picomatch2(), 1);
|
|
1531
|
+
import { resolve, relative, sep } from "path";
|
|
1532
|
+
import { existsSync as existsSync2 } from "fs";
|
|
1533
|
+
var HookEventSchema = external_exports.enum([
|
|
1534
|
+
"SessionStart",
|
|
1535
|
+
"UserPromptSubmit",
|
|
1536
|
+
"PreToolUse",
|
|
1537
|
+
"PostToolUse",
|
|
1538
|
+
"PostToolUseFailure",
|
|
1539
|
+
"PermissionRequest",
|
|
1540
|
+
"Notification",
|
|
1541
|
+
"Stop",
|
|
1542
|
+
"SubagentStop",
|
|
1543
|
+
"SubagentStart",
|
|
1544
|
+
"PreCompact",
|
|
1545
|
+
"SessionEnd"
|
|
1546
|
+
]);
|
|
1547
|
+
var SessionStateFlagSchema = external_exports.enum([
|
|
1548
|
+
"tests_run",
|
|
1549
|
+
"tests_passed",
|
|
1550
|
+
"lint_run",
|
|
1551
|
+
"lint_passed",
|
|
1552
|
+
"build_run",
|
|
1553
|
+
"build_passed",
|
|
1554
|
+
"formatter_run",
|
|
1555
|
+
"branch_created",
|
|
1556
|
+
"plan_approved"
|
|
1557
|
+
]);
|
|
1558
|
+
var RuleSourceSchema = external_exports.enum(["template", "user", "ai-scan"]);
|
|
1559
|
+
var PermissionDecisionSchema = external_exports.enum(["allow", "deny", "ask_user"]);
|
|
1560
|
+
var PipelineOnFailureSchema = external_exports.enum(["block", "warn", "continue"]);
|
|
1561
|
+
var StackConfigSchema = external_exports.object({
|
|
1562
|
+
name: external_exports.string().max(200),
|
|
1563
|
+
runtime: external_exports.string().max(100).default("unknown"),
|
|
1564
|
+
language: external_exports.string().max(100).optional(),
|
|
1565
|
+
framework: external_exports.string().max(100).optional(),
|
|
1566
|
+
package_manager: external_exports.string().max(100).optional(),
|
|
1567
|
+
test_command: external_exports.string().max(1e3).optional(),
|
|
1568
|
+
lint_command: external_exports.string().max(1e3).optional(),
|
|
1569
|
+
build_command: external_exports.string().max(1e3).optional(),
|
|
1570
|
+
format_command: external_exports.string().max(1e3).optional()
|
|
1571
|
+
});
|
|
1572
|
+
var PreconditionRuleInputSchema = external_exports.object({
|
|
1573
|
+
enabled: external_exports.boolean().default(true),
|
|
1574
|
+
trigger: HookEventSchema,
|
|
1575
|
+
matcher: external_exports.string().max(500),
|
|
1576
|
+
file_pattern: external_exports.string().max(500).optional(),
|
|
1577
|
+
command_pattern: external_exports.string().max(1e3).optional(),
|
|
1578
|
+
requires: external_exports.array(SessionStateFlagSchema).optional(),
|
|
1579
|
+
requires_read: external_exports.boolean().optional(),
|
|
1580
|
+
message: external_exports.string().max(5e3),
|
|
1581
|
+
skill: external_exports.string().max(500).optional(),
|
|
1582
|
+
locked: external_exports.boolean().default(false),
|
|
1583
|
+
source: RuleSourceSchema.optional(),
|
|
1584
|
+
priority: external_exports.number().int().nonnegative().default(100)
|
|
1585
|
+
});
|
|
1586
|
+
var PostconditionRuleInputSchema = external_exports.object({
|
|
1587
|
+
enabled: external_exports.boolean().default(true),
|
|
1588
|
+
trigger: HookEventSchema,
|
|
1589
|
+
matcher: external_exports.string().max(500),
|
|
1590
|
+
file_pattern: external_exports.string().max(500).optional(),
|
|
1591
|
+
command_pattern: external_exports.string().max(1e3).optional(),
|
|
1592
|
+
run: external_exports.string().max(2e3),
|
|
1593
|
+
timeout: external_exports.number().int().positive().optional(),
|
|
1594
|
+
block_on_failure: external_exports.boolean().optional(),
|
|
1595
|
+
skill: external_exports.string().max(500).optional(),
|
|
1596
|
+
locked: external_exports.boolean().default(false),
|
|
1597
|
+
source: RuleSourceSchema.optional(),
|
|
1598
|
+
priority: external_exports.number().int().nonnegative().default(100)
|
|
1599
|
+
});
|
|
1600
|
+
var PermissionRuleInputSchema = external_exports.object({
|
|
1601
|
+
enabled: external_exports.boolean().default(true),
|
|
1602
|
+
trigger: HookEventSchema,
|
|
1603
|
+
matcher: external_exports.string().max(500),
|
|
1604
|
+
file_pattern: external_exports.string().max(500).optional(),
|
|
1605
|
+
command_pattern: external_exports.string().max(1e3).optional(),
|
|
1606
|
+
decision: PermissionDecisionSchema,
|
|
1607
|
+
message: external_exports.string().max(5e3).optional(),
|
|
1608
|
+
skill: external_exports.string().max(500).optional(),
|
|
1609
|
+
locked: external_exports.boolean().default(false),
|
|
1610
|
+
source: RuleSourceSchema.optional(),
|
|
1611
|
+
priority: external_exports.number().int().nonnegative().default(100)
|
|
1612
|
+
});
|
|
1613
|
+
var PipelineStepSchema = external_exports.object({
|
|
1614
|
+
name: external_exports.string().max(200),
|
|
1615
|
+
run: external_exports.string().max(2e3).optional(),
|
|
1616
|
+
skill: external_exports.string().max(500).optional(),
|
|
1617
|
+
timeout: external_exports.number().int().positive().optional()
|
|
1618
|
+
});
|
|
1619
|
+
var PipelineRuleInputSchema = external_exports.object({
|
|
1620
|
+
enabled: external_exports.boolean().default(true),
|
|
1621
|
+
trigger: HookEventSchema,
|
|
1622
|
+
matcher: external_exports.string().max(500),
|
|
1623
|
+
file_pattern: external_exports.string().max(500).optional(),
|
|
1624
|
+
command_pattern: external_exports.string().max(1e3).optional(),
|
|
1625
|
+
steps: external_exports.array(PipelineStepSchema).min(1),
|
|
1626
|
+
on_failure: PipelineOnFailureSchema,
|
|
1627
|
+
skill: external_exports.string().max(500).optional(),
|
|
1628
|
+
locked: external_exports.boolean().default(false),
|
|
1629
|
+
source: RuleSourceSchema.optional(),
|
|
1630
|
+
priority: external_exports.number().int().nonnegative().default(100)
|
|
1631
|
+
});
|
|
1632
|
+
var NotifyChannelSchema = external_exports.object({
|
|
1633
|
+
type: external_exports.enum(["desktop", "webhook", "log", "terminal"]),
|
|
1634
|
+
sound: external_exports.boolean().optional(),
|
|
1635
|
+
sound_file: external_exports.string().optional(),
|
|
1636
|
+
url: external_exports.string().optional(),
|
|
1637
|
+
template: external_exports.string().optional(),
|
|
1638
|
+
path: external_exports.string().optional(),
|
|
1639
|
+
message: external_exports.string().optional()
|
|
1640
|
+
});
|
|
1641
|
+
var RateLimitSchema = external_exports.object({
|
|
1642
|
+
threshold: external_exports.number().int().positive(),
|
|
1643
|
+
window_seconds: external_exports.number().int().positive(),
|
|
1644
|
+
message: external_exports.string().optional()
|
|
1645
|
+
});
|
|
1646
|
+
var ActSchema = external_exports.object({
|
|
1647
|
+
inject_skill: external_exports.string().optional(),
|
|
1648
|
+
inject_skill_on_retry: external_exports.string().optional(),
|
|
1649
|
+
inject_skill_after_n_blocks: external_exports.number().int().positive().optional(),
|
|
1650
|
+
alert_after_n_blocks: external_exports.number().int().positive().optional(),
|
|
1651
|
+
alert_channels: external_exports.array(NotifyChannelSchema).optional(),
|
|
1652
|
+
rate_limit: RateLimitSchema.optional(),
|
|
1653
|
+
log_failure_details: external_exports.boolean().optional()
|
|
1654
|
+
});
|
|
1655
|
+
var EventResponseConfigSchema = external_exports.object({
|
|
1656
|
+
urgency: external_exports.enum(["critical", "high", "low"]).optional(),
|
|
1657
|
+
notify: external_exports.array(NotifyChannelSchema),
|
|
1658
|
+
repeat_interval_seconds: external_exports.number().int().positive().optional(),
|
|
1659
|
+
act: ActSchema.optional()
|
|
1660
|
+
});
|
|
1661
|
+
var ResponseConfigSchema = external_exports.object({
|
|
1662
|
+
dedup_window_seconds: external_exports.number().int().nonnegative(),
|
|
1663
|
+
permission_prompt: EventResponseConfigSchema.optional(),
|
|
1664
|
+
idle_prompt: EventResponseConfigSchema.optional(),
|
|
1665
|
+
task_complete: EventResponseConfigSchema.optional(),
|
|
1666
|
+
task_failed: EventResponseConfigSchema.optional(),
|
|
1667
|
+
rule_blocked: EventResponseConfigSchema.optional(),
|
|
1668
|
+
repeated_failures: EventResponseConfigSchema.extend({ threshold: external_exports.number().int().positive().optional() }).optional(),
|
|
1669
|
+
rapid_permission_requests: EventResponseConfigSchema.extend({
|
|
1670
|
+
threshold: external_exports.number().int().positive().optional(),
|
|
1671
|
+
window_seconds: external_exports.number().int().positive().optional()
|
|
1672
|
+
}).optional(),
|
|
1673
|
+
sensitive_path_access: EventResponseConfigSchema.extend({ file_patterns: external_exports.array(external_exports.string()).optional() }).optional()
|
|
1674
|
+
});
|
|
1675
|
+
var ReviewSettingsConfigSchema = external_exports.object({
|
|
1676
|
+
enabled: external_exports.boolean().optional(),
|
|
1677
|
+
plan_review: external_exports.boolean().optional(),
|
|
1678
|
+
code_review: external_exports.boolean().optional(),
|
|
1679
|
+
auto_open_browser: external_exports.boolean().optional()
|
|
1680
|
+
});
|
|
1681
|
+
var RulesConfigSchema = external_exports.object({
|
|
1682
|
+
project: StackConfigSchema,
|
|
1683
|
+
preconditions: external_exports.record(external_exports.string(), PreconditionRuleInputSchema).optional().default({}),
|
|
1684
|
+
postconditions: external_exports.record(external_exports.string(), PostconditionRuleInputSchema).optional().default({}),
|
|
1685
|
+
permissions: external_exports.record(external_exports.string(), PermissionRuleInputSchema).optional().default({}),
|
|
1686
|
+
pipelines: external_exports.record(external_exports.string(), PipelineRuleInputSchema).optional().default({}),
|
|
1687
|
+
responses: ResponseConfigSchema.optional(),
|
|
1688
|
+
review: ReviewSettingsConfigSchema.optional()
|
|
1689
|
+
});
|
|
1690
|
+
function injectRuleMeta(section, type) {
|
|
1691
|
+
if (!section) return {};
|
|
1692
|
+
const result = {};
|
|
1693
|
+
for (const [key, value] of Object.entries(section)) {
|
|
1694
|
+
result[key] = {
|
|
1695
|
+
...value,
|
|
1696
|
+
id: key,
|
|
1697
|
+
type
|
|
1698
|
+
};
|
|
1699
|
+
}
|
|
1700
|
+
return result;
|
|
1701
|
+
}
|
|
1702
|
+
function parseRules(yamlContent) {
|
|
1703
|
+
const raw = parseYaml(yamlContent);
|
|
1704
|
+
const validated = RulesConfigSchema.parse(raw);
|
|
1705
|
+
const preconditions = injectRuleMeta(
|
|
1706
|
+
validated.preconditions,
|
|
1707
|
+
"precondition"
|
|
1708
|
+
);
|
|
1709
|
+
const postconditions = injectRuleMeta(
|
|
1710
|
+
validated.postconditions,
|
|
1711
|
+
"postcondition"
|
|
1712
|
+
);
|
|
1713
|
+
const permissions = injectRuleMeta(
|
|
1714
|
+
validated.permissions,
|
|
1715
|
+
"permission"
|
|
1716
|
+
);
|
|
1717
|
+
const pipelines = injectRuleMeta(
|
|
1718
|
+
validated.pipelines,
|
|
1719
|
+
"pipeline"
|
|
1720
|
+
);
|
|
1721
|
+
return {
|
|
1722
|
+
project: validated.project,
|
|
1723
|
+
preconditions,
|
|
1724
|
+
postconditions,
|
|
1725
|
+
permissions,
|
|
1726
|
+
pipelines,
|
|
1727
|
+
responses: validated.responses
|
|
1728
|
+
};
|
|
1729
|
+
}
|
|
1730
|
+
function loadRulesSync(rulesPath) {
|
|
1731
|
+
try {
|
|
1732
|
+
if (!existsSync(rulesPath)) return null;
|
|
1733
|
+
const content = readFileSync(rulesPath, "utf-8");
|
|
1734
|
+
return parseRules(content);
|
|
1735
|
+
} catch (err) {
|
|
1736
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
1737
|
+
process.stderr.write(`[ulpi] Failed to load rules from ${rulesPath}: ${message}
|
|
1738
|
+
`);
|
|
1739
|
+
return null;
|
|
1740
|
+
}
|
|
1741
|
+
}
|
|
1742
|
+
function matchesTool(matcher, toolName) {
|
|
1743
|
+
if (matcher === "*") return true;
|
|
1744
|
+
const names = matcher.split("|");
|
|
1745
|
+
return names.some((name) => name.trim() === toolName);
|
|
1746
|
+
}
|
|
1747
|
+
function normalizePath(filePath, projectDir) {
|
|
1748
|
+
const abs = resolve(projectDir, filePath);
|
|
1749
|
+
const rel = relative(projectDir, abs);
|
|
1750
|
+
return rel.split(sep).join("/");
|
|
1751
|
+
}
|
|
1752
|
+
function matchesFilePattern(pattern, filePath, projectDir) {
|
|
1753
|
+
const normalised = normalizePath(filePath, projectDir);
|
|
1754
|
+
if (normalised.includes("..")) return false;
|
|
1755
|
+
const isMatch = (0, import_picomatch.default)(pattern, { dot: true });
|
|
1756
|
+
return isMatch(normalised);
|
|
1757
|
+
}
|
|
1758
|
+
function containsShellMetacharacters(str) {
|
|
1759
|
+
return /[;&|`]|\$\(/.test(str);
|
|
1760
|
+
}
|
|
1761
|
+
function matchesCommand(pattern, command) {
|
|
1762
|
+
const trimmedCmd = command.trimStart();
|
|
1763
|
+
const patterns = pattern.split("|");
|
|
1764
|
+
return patterns.some((pat) => {
|
|
1765
|
+
const trimmedPat = pat.trim();
|
|
1766
|
+
if (trimmedCmd === trimmedPat) return true;
|
|
1767
|
+
if (trimmedCmd.startsWith(trimmedPat) && (trimmedCmd[trimmedPat.length] === " " || trimmedCmd[trimmedPat.length] === " ")) {
|
|
1768
|
+
const remainder = trimmedCmd.slice(trimmedPat.length);
|
|
1769
|
+
if (containsShellMetacharacters(remainder)) {
|
|
1770
|
+
return false;
|
|
1771
|
+
}
|
|
1772
|
+
return true;
|
|
1773
|
+
}
|
|
1774
|
+
return false;
|
|
1775
|
+
});
|
|
1776
|
+
}
|
|
1777
|
+
var DANGEROUS_PATTERNS = [
|
|
1778
|
+
// rm -rf / (root) — but not rm -rf /tmp/foo
|
|
1779
|
+
{
|
|
1780
|
+
test: (cmd) => /\brm\s+.*-[a-zA-Z]*r[a-zA-Z]*f[a-zA-Z]*\s+\/\s*$/.test(cmd) || /\brm\s+.*-[a-zA-Z]*f[a-zA-Z]*r[a-zA-Z]*\s+\/\s*$/.test(cmd),
|
|
1781
|
+
reason: "Recursive forced deletion of root filesystem"
|
|
1782
|
+
},
|
|
1783
|
+
// sudo rm
|
|
1784
|
+
{
|
|
1785
|
+
test: (cmd) => /\bsudo\s+rm\b/.test(cmd),
|
|
1786
|
+
reason: "Privileged file deletion with sudo"
|
|
1787
|
+
},
|
|
1788
|
+
// chmod 777
|
|
1789
|
+
{
|
|
1790
|
+
test: (cmd) => /\bchmod\s+777\b/.test(cmd),
|
|
1791
|
+
reason: "Setting world-writable permissions (chmod 777)"
|
|
1792
|
+
},
|
|
1793
|
+
// Fork bomb (various whitespace variants)
|
|
1794
|
+
{
|
|
1795
|
+
test: (cmd) => /:\s*\(\s*\)\s*\{.*\|.*&\s*\}/.test(cmd) || /:\(\)\{.*\|.*&\}/.test(cmd) || cmd.includes(":(){ :|:& };:"),
|
|
1796
|
+
reason: "Fork bomb detected"
|
|
1797
|
+
},
|
|
1798
|
+
// dd to device (can destroy disks)
|
|
1799
|
+
{
|
|
1800
|
+
test: (cmd) => /\bdd\b.*\bof\s*=\s*\/dev\//.test(cmd),
|
|
1801
|
+
reason: "dd command writing to device \u2014 can destroy disk data"
|
|
1802
|
+
},
|
|
1803
|
+
// mkfs (format filesystem)
|
|
1804
|
+
{
|
|
1805
|
+
test: (cmd) => /\bmkfs\b/.test(cmd),
|
|
1806
|
+
reason: "mkfs formats a filesystem \u2014 all data on the target will be lost"
|
|
1807
|
+
},
|
|
1808
|
+
// git push --force (but not --force-with-lease)
|
|
1809
|
+
{
|
|
1810
|
+
test: (cmd) => /\bgit\s+push\b.*--force\b/.test(cmd) && !cmd.includes("--force-with-lease"),
|
|
1811
|
+
reason: "Force push without --force-with-lease can destroy remote history"
|
|
1812
|
+
},
|
|
1813
|
+
// git push to main/master
|
|
1814
|
+
{
|
|
1815
|
+
test: (cmd) => {
|
|
1816
|
+
if (!/\bgit\s+push\b/.test(cmd)) return false;
|
|
1817
|
+
return /\bgit\s+push\s+\S+\s+(main|master)\b/.test(cmd);
|
|
1818
|
+
},
|
|
1819
|
+
reason: "Direct push to main/master branch"
|
|
1820
|
+
},
|
|
1821
|
+
// prisma migrate reset
|
|
1822
|
+
{
|
|
1823
|
+
test: (cmd) => /\bprisma\s+migrate\s+reset\b/.test(cmd),
|
|
1824
|
+
reason: "Prisma migrate reset drops and recreates the database"
|
|
1825
|
+
},
|
|
1826
|
+
// artisan db:wipe
|
|
1827
|
+
{
|
|
1828
|
+
test: (cmd) => /\bartisan\s+db:wipe\b/.test(cmd),
|
|
1829
|
+
reason: "Laravel db:wipe drops all tables"
|
|
1830
|
+
},
|
|
1831
|
+
// rails db:drop
|
|
1832
|
+
{
|
|
1833
|
+
test: (cmd) => /\brails\s+db:drop\b/.test(cmd),
|
|
1834
|
+
reason: "Rails db:drop destroys the database"
|
|
1835
|
+
},
|
|
1836
|
+
// SQL DROP DATABASE / DROP TABLE (case-insensitive)
|
|
1837
|
+
{
|
|
1838
|
+
test: (cmd) => /\bDROP\s+(DATABASE|TABLE)\b/i.test(cmd),
|
|
1839
|
+
reason: "SQL DROP command detected"
|
|
1840
|
+
}
|
|
1841
|
+
];
|
|
1842
|
+
function isDangerousCommand(command) {
|
|
1843
|
+
for (const pattern of DANGEROUS_PATTERNS) {
|
|
1844
|
+
if (pattern.test(command)) {
|
|
1845
|
+
return { dangerous: true, reason: pattern.reason };
|
|
1846
|
+
}
|
|
1847
|
+
}
|
|
1848
|
+
const chainPattern = /[;&|`]|\$\(/;
|
|
1849
|
+
if (chainPattern.test(command)) {
|
|
1850
|
+
const parts = command.split(/\s*(?:;|&&|\|\||`|\$\()\s*/);
|
|
1851
|
+
for (const part of parts) {
|
|
1852
|
+
const trimmed = part.trim();
|
|
1853
|
+
if (!trimmed) continue;
|
|
1854
|
+
for (const pattern of DANGEROUS_PATTERNS) {
|
|
1855
|
+
if (pattern.test(trimmed)) {
|
|
1856
|
+
return { dangerous: true, reason: pattern.reason };
|
|
1857
|
+
}
|
|
1858
|
+
}
|
|
1859
|
+
}
|
|
1860
|
+
}
|
|
1861
|
+
return { dangerous: false };
|
|
1862
|
+
}
|
|
1863
|
+
var FLAG_MAP = {
|
|
1864
|
+
tests_run: (s) => s.testsRun,
|
|
1865
|
+
tests_passed: (s) => s.testsPassed === true,
|
|
1866
|
+
lint_run: (s) => s.lintRun,
|
|
1867
|
+
lint_passed: (s) => s.lintPassed === true,
|
|
1868
|
+
build_run: (s) => s.buildRun,
|
|
1869
|
+
build_passed: (s) => s.buildPassed === true,
|
|
1870
|
+
formatter_run: (s) => s.formatterRun,
|
|
1871
|
+
branch_created: (s) => s.branchCreated,
|
|
1872
|
+
plan_approved: (s) => s.planApproved
|
|
1873
|
+
};
|
|
1874
|
+
function checkPrecondition(rule, state, input, projectDir) {
|
|
1875
|
+
if (rule.requires_read && input.tool_input?.file_path) {
|
|
1876
|
+
const filePath = input.tool_input.file_path;
|
|
1877
|
+
if (filePath.includes(".claude/plans/")) {
|
|
1878
|
+
} else {
|
|
1879
|
+
const fileExists = existsSync2(filePath);
|
|
1880
|
+
if (fileExists) {
|
|
1881
|
+
const normalised = normalizePath(filePath, projectDir);
|
|
1882
|
+
const wasRead = state.filesRead.some(
|
|
1883
|
+
(f) => normalizePath(f, projectDir) === normalised
|
|
1884
|
+
);
|
|
1885
|
+
const wasWritten = state.filesWritten.some(
|
|
1886
|
+
(f) => normalizePath(f, projectDir) === normalised
|
|
1887
|
+
);
|
|
1888
|
+
if (!wasRead && !wasWritten) return false;
|
|
1889
|
+
}
|
|
1890
|
+
}
|
|
1891
|
+
}
|
|
1892
|
+
if (rule.requires && rule.requires.length > 0) {
|
|
1893
|
+
for (const flag of rule.requires) {
|
|
1894
|
+
const check = FLAG_MAP[flag];
|
|
1895
|
+
if (check && !check(state)) return false;
|
|
1896
|
+
}
|
|
1897
|
+
}
|
|
1898
|
+
return true;
|
|
1899
|
+
}
|
|
1900
|
+
function buildPermissionOutput(decision, reason, hookEventName = "PreToolUse") {
|
|
1901
|
+
if (hookEventName === "PermissionRequest") {
|
|
1902
|
+
return {
|
|
1903
|
+
hookSpecificOutput: {
|
|
1904
|
+
hookEventName: "PermissionRequest",
|
|
1905
|
+
decision: {
|
|
1906
|
+
behavior: decision,
|
|
1907
|
+
message: reason
|
|
1908
|
+
}
|
|
1909
|
+
}
|
|
1910
|
+
};
|
|
1911
|
+
}
|
|
1912
|
+
return {
|
|
1913
|
+
hookSpecificOutput: {
|
|
1914
|
+
hookEventName: "PreToolUse",
|
|
1915
|
+
permissionDecision: decision,
|
|
1916
|
+
permissionDecisionReason: reason
|
|
1917
|
+
}
|
|
1918
|
+
};
|
|
1919
|
+
}
|
|
1920
|
+
function collectPostconditions(input, rules, projectDir) {
|
|
1921
|
+
const results = [];
|
|
1922
|
+
const toolName = input.tool_name ?? "";
|
|
1923
|
+
for (const rule of Object.values(rules.postconditions)) {
|
|
1924
|
+
if (!rule.enabled) continue;
|
|
1925
|
+
if (rule.trigger !== input.hook_event_name) continue;
|
|
1926
|
+
if (!matchesTool(rule.matcher, toolName)) continue;
|
|
1927
|
+
if (rule.file_pattern && input.tool_input?.file_path) {
|
|
1928
|
+
if (!matchesFilePattern(rule.file_pattern, input.tool_input.file_path, projectDir)) {
|
|
1929
|
+
continue;
|
|
1930
|
+
}
|
|
1931
|
+
} else if (rule.file_pattern && !input.tool_input?.file_path) {
|
|
1932
|
+
continue;
|
|
1933
|
+
}
|
|
1934
|
+
if (rule.command_pattern && input.tool_input?.command) {
|
|
1935
|
+
if (!matchesCommand(rule.command_pattern, input.tool_input.command)) {
|
|
1936
|
+
continue;
|
|
1937
|
+
}
|
|
1938
|
+
} else if (rule.command_pattern && !input.tool_input?.command) {
|
|
1939
|
+
continue;
|
|
1940
|
+
}
|
|
1941
|
+
results.push({ rule, command: rule.run });
|
|
1942
|
+
}
|
|
1943
|
+
results.sort((a, b) => (a.rule.priority ?? 100) - (b.rule.priority ?? 100));
|
|
1944
|
+
return results;
|
|
1945
|
+
}
|
|
1946
|
+
function checkPipelinePrereqs(pipeline, state) {
|
|
1947
|
+
for (const step of pipeline.steps) {
|
|
1948
|
+
if (step.run) {
|
|
1949
|
+
const wasRun = state.commandsRun.some((cmd) => commandSatisfiesStep(cmd, step.run));
|
|
1950
|
+
if (!wasRun) return step.name;
|
|
1951
|
+
}
|
|
1952
|
+
if (step.skill && !step.run) {
|
|
1953
|
+
const skillMarker = `__skill__:${step.skill}`;
|
|
1954
|
+
const wasRun = state.commandsRun.includes(skillMarker);
|
|
1955
|
+
if (!wasRun) return step.name;
|
|
1956
|
+
}
|
|
1957
|
+
}
|
|
1958
|
+
return null;
|
|
1959
|
+
}
|
|
1960
|
+
function commandSatisfiesStep(recorded, stepCmd) {
|
|
1961
|
+
const trimRecorded = recorded.trimStart();
|
|
1962
|
+
const trimStep = stepCmd.trim();
|
|
1963
|
+
if (trimRecorded === trimStep) return true;
|
|
1964
|
+
if (trimRecorded.startsWith(trimStep) && (trimRecorded[trimStep.length] === " " || trimRecorded[trimStep.length] === " ")) {
|
|
1965
|
+
return true;
|
|
1966
|
+
}
|
|
1967
|
+
return false;
|
|
1968
|
+
}
|
|
1969
|
+
function ruleApplies(rule, input, projectDir) {
|
|
1970
|
+
if (!rule.enabled) return false;
|
|
1971
|
+
if (rule.trigger !== input.hook_event_name) return false;
|
|
1972
|
+
const toolName = input.tool_name ?? "";
|
|
1973
|
+
if (!matchesTool(rule.matcher, toolName)) return false;
|
|
1974
|
+
if (rule.file_pattern) {
|
|
1975
|
+
const filePath = input.tool_input?.file_path;
|
|
1976
|
+
if (!filePath) return false;
|
|
1977
|
+
if (!matchesFilePattern(rule.file_pattern, filePath, projectDir)) return false;
|
|
1978
|
+
}
|
|
1979
|
+
if (rule.command_pattern) {
|
|
1980
|
+
const command = input.tool_input?.command;
|
|
1981
|
+
if (!command) return false;
|
|
1982
|
+
if (!matchesCommand(rule.command_pattern, command)) return false;
|
|
1983
|
+
}
|
|
1984
|
+
return true;
|
|
1985
|
+
}
|
|
1986
|
+
function denyRuleCrossTriggers(rule, input, projectDir) {
|
|
1987
|
+
if (rule.decision !== "deny") return false;
|
|
1988
|
+
if (!rule.enabled) return false;
|
|
1989
|
+
if (rule.trigger !== "PermissionRequest") return false;
|
|
1990
|
+
if (input.hook_event_name !== "PreToolUse") return false;
|
|
1991
|
+
if (!matchesTool(rule.matcher, input.tool_name ?? "")) return false;
|
|
1992
|
+
if (rule.file_pattern) {
|
|
1993
|
+
const filePath = input.tool_input?.file_path;
|
|
1994
|
+
if (!filePath || !matchesFilePattern(rule.file_pattern, filePath, projectDir))
|
|
1995
|
+
return false;
|
|
1996
|
+
}
|
|
1997
|
+
if (rule.command_pattern) {
|
|
1998
|
+
const command = input.tool_input?.command;
|
|
1999
|
+
if (!command || !matchesCommand(rule.command_pattern, command)) return false;
|
|
2000
|
+
}
|
|
2001
|
+
return true;
|
|
2002
|
+
}
|
|
2003
|
+
function collectMatchingRules(input, rules, projectDir) {
|
|
2004
|
+
const all = [];
|
|
2005
|
+
for (const r of Object.values(rules.permissions)) {
|
|
2006
|
+
if (ruleApplies(r, input, projectDir) || denyRuleCrossTriggers(r, input, projectDir)) {
|
|
2007
|
+
all.push(r);
|
|
2008
|
+
}
|
|
2009
|
+
}
|
|
2010
|
+
for (const r of Object.values(rules.preconditions)) {
|
|
2011
|
+
if (ruleApplies(r, input, projectDir)) all.push(r);
|
|
2012
|
+
}
|
|
2013
|
+
for (const r of Object.values(rules.pipelines)) {
|
|
2014
|
+
if (ruleApplies(r, input, projectDir)) all.push(r);
|
|
2015
|
+
}
|
|
2016
|
+
for (const r of Object.values(rules.postconditions)) {
|
|
2017
|
+
if (ruleApplies(r, input, projectDir)) all.push(r);
|
|
2018
|
+
}
|
|
2019
|
+
all.sort((a, b) => (a.priority ?? 100) - (b.priority ?? 100));
|
|
2020
|
+
return all;
|
|
2021
|
+
}
|
|
2022
|
+
function allowResult(matchedRules, postcmds, postResults) {
|
|
2023
|
+
return {
|
|
2024
|
+
action: "allow",
|
|
2025
|
+
exitCode: 0,
|
|
2026
|
+
matchedRules,
|
|
2027
|
+
postconditionCommands: postcmds?.length ? postcmds : void 0,
|
|
2028
|
+
postconditionResults: postResults?.length ? postResults : void 0
|
|
2029
|
+
};
|
|
2030
|
+
}
|
|
2031
|
+
function blockResult(message, matchedRules, output) {
|
|
2032
|
+
return {
|
|
2033
|
+
action: "block",
|
|
2034
|
+
exitCode: 2,
|
|
2035
|
+
stderrMessage: message,
|
|
2036
|
+
stdoutJson: output,
|
|
2037
|
+
matchedRules
|
|
2038
|
+
};
|
|
2039
|
+
}
|
|
2040
|
+
function feedbackResult(message, matchedRules, output) {
|
|
2041
|
+
return {
|
|
2042
|
+
action: "feedback",
|
|
2043
|
+
exitCode: 2,
|
|
2044
|
+
stderrMessage: message,
|
|
2045
|
+
stdoutJson: output,
|
|
2046
|
+
matchedRules
|
|
2047
|
+
};
|
|
2048
|
+
}
|
|
2049
|
+
function evaluateRules(hookInput, rules, state, projectDir) {
|
|
2050
|
+
const matchedRules = [];
|
|
2051
|
+
const hookEventName = hookInput.hook_event_name === "PermissionRequest" ? "PermissionRequest" : "PreToolUse";
|
|
2052
|
+
if (hookInput.tool_name === "Bash" && hookInput.tool_input?.command && (hookInput.hook_event_name === "PreToolUse" || hookInput.hook_event_name === "PermissionRequest")) {
|
|
2053
|
+
const command = hookInput.tool_input.command;
|
|
2054
|
+
const danger = isDangerousCommand(command);
|
|
2055
|
+
if (danger.dangerous) {
|
|
2056
|
+
const message = `Dangerous command blocked: ${danger.reason}`;
|
|
2057
|
+
const output = buildPermissionOutput("deny", message, hookEventName);
|
|
2058
|
+
return blockResult(message, matchedRules, output);
|
|
2059
|
+
}
|
|
2060
|
+
const dangerRule = rules.permissions["block-dangerous-commands"];
|
|
2061
|
+
if (dangerRule?.enabled && dangerRule.command_pattern) {
|
|
2062
|
+
if (matchesCommand(dangerRule.command_pattern, command)) {
|
|
2063
|
+
const message = dangerRule.message || "Dangerous command blocked (custom pattern)";
|
|
2064
|
+
const output = buildPermissionOutput("deny", message, hookEventName);
|
|
2065
|
+
return blockResult(message, matchedRules, output);
|
|
2066
|
+
}
|
|
2067
|
+
}
|
|
2068
|
+
}
|
|
2069
|
+
const matching = collectMatchingRules(hookInput, rules, projectDir);
|
|
2070
|
+
const permRules = matching.filter(
|
|
2071
|
+
(r) => r.type === "permission"
|
|
2072
|
+
);
|
|
2073
|
+
for (const rule of permRules) {
|
|
2074
|
+
if (rule.decision === "deny") {
|
|
2075
|
+
matchedRules.push({ rule, outcome: "fail" });
|
|
2076
|
+
const output = buildPermissionOutput("deny", rule.message, hookEventName);
|
|
2077
|
+
return blockResult(
|
|
2078
|
+
rule.message ?? `Blocked by permission rule: ${rule.id}`,
|
|
2079
|
+
matchedRules,
|
|
2080
|
+
output
|
|
2081
|
+
);
|
|
2082
|
+
}
|
|
2083
|
+
}
|
|
2084
|
+
for (const rule of permRules) {
|
|
2085
|
+
if (rule.decision === "ask_user") {
|
|
2086
|
+
matchedRules.push({ rule, outcome: "pass" });
|
|
2087
|
+
const output = buildPermissionOutput("ask_user", rule.message, hookEventName);
|
|
2088
|
+
return feedbackResult(
|
|
2089
|
+
rule.message ?? `Permission required: ${rule.id}`,
|
|
2090
|
+
matchedRules,
|
|
2091
|
+
output
|
|
2092
|
+
);
|
|
2093
|
+
}
|
|
2094
|
+
}
|
|
2095
|
+
for (const rule of permRules) {
|
|
2096
|
+
if (rule.decision === "allow") {
|
|
2097
|
+
matchedRules.push({ rule, outcome: "pass" });
|
|
2098
|
+
}
|
|
2099
|
+
}
|
|
2100
|
+
const preRules = matching.filter(
|
|
2101
|
+
(r) => r.type === "precondition"
|
|
2102
|
+
);
|
|
2103
|
+
for (const rule of preRules) {
|
|
2104
|
+
const passed = checkPrecondition(rule, state, hookInput, projectDir);
|
|
2105
|
+
matchedRules.push({ rule, outcome: passed ? "pass" : "fail" });
|
|
2106
|
+
if (!passed) {
|
|
2107
|
+
const output = buildPermissionOutput("deny", rule.message, hookEventName);
|
|
2108
|
+
return blockResult(rule.message, matchedRules, output);
|
|
2109
|
+
}
|
|
2110
|
+
}
|
|
2111
|
+
const pipeRules = matching.filter(
|
|
2112
|
+
(r) => r.type === "pipeline"
|
|
2113
|
+
);
|
|
2114
|
+
for (const rule of pipeRules) {
|
|
2115
|
+
const unmetStep = checkPipelinePrereqs(rule, state);
|
|
2116
|
+
if (unmetStep !== null) {
|
|
2117
|
+
matchedRules.push({ rule, outcome: "fail" });
|
|
2118
|
+
if (rule.on_failure === "block") {
|
|
2119
|
+
const msg = `Pipeline "${rule.id}" requires step "${unmetStep}" to complete first`;
|
|
2120
|
+
const output = buildPermissionOutput("deny", msg, hookEventName);
|
|
2121
|
+
return blockResult(msg, matchedRules, output);
|
|
2122
|
+
}
|
|
2123
|
+
if (rule.on_failure === "warn") {
|
|
2124
|
+
matchedRules.push({ rule, outcome: "fail" });
|
|
2125
|
+
}
|
|
2126
|
+
} else {
|
|
2127
|
+
matchedRules.push({ rule, outcome: "pass" });
|
|
2128
|
+
}
|
|
2129
|
+
}
|
|
2130
|
+
let postconditionCommands;
|
|
2131
|
+
let postconditionResults;
|
|
2132
|
+
if (hookInput.hook_event_name === "PostToolUse") {
|
|
2133
|
+
const postResults = collectPostconditions(hookInput, rules, projectDir);
|
|
2134
|
+
if (postResults.length > 0) {
|
|
2135
|
+
postconditionCommands = postResults.map((r) => r.command);
|
|
2136
|
+
postconditionResults = postResults;
|
|
2137
|
+
for (const { rule } of postResults) {
|
|
2138
|
+
matchedRules.push({ rule, outcome: "executed" });
|
|
2139
|
+
}
|
|
2140
|
+
}
|
|
2141
|
+
}
|
|
2142
|
+
const firstAllow = permRules.find((r) => r.decision === "allow");
|
|
2143
|
+
if (firstAllow) {
|
|
2144
|
+
const output = buildPermissionOutput("allow", firstAllow.message, hookEventName);
|
|
2145
|
+
return {
|
|
2146
|
+
action: "allow",
|
|
2147
|
+
exitCode: 0,
|
|
2148
|
+
stdoutJson: output,
|
|
2149
|
+
matchedRules,
|
|
2150
|
+
postconditionCommands,
|
|
2151
|
+
postconditionResults
|
|
2152
|
+
};
|
|
2153
|
+
}
|
|
2154
|
+
return allowResult(matchedRules, postconditionCommands, postconditionResults);
|
|
2155
|
+
}
|
|
2156
|
+
|
|
2157
|
+
export {
|
|
2158
|
+
ResponseConfigSchema,
|
|
2159
|
+
parseRules,
|
|
2160
|
+
loadRulesSync,
|
|
2161
|
+
matchesFilePattern,
|
|
2162
|
+
evaluateRules
|
|
2163
|
+
};
|