@cybedefend/vibedefend 1.4.2 → 1.4.3
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/README.md +3 -1
- package/dist/clients/claude-code.js +4 -1
- package/dist/clients/claude-code.js.map +1 -1
- package/dist/clients/codex.js +4 -2
- package/dist/clients/codex.js.map +1 -1
- package/dist/hook-runner.js +938 -672
- package/dist/hooks/runtime/emit.js +25 -12
- package/dist/hooks/runtime/emit.js.map +1 -1
- package/dist/hooks/runtime/fetch-rules.js +38 -12
- package/dist/hooks/runtime/fetch-rules.js.map +1 -1
- package/dist/hooks/runtime/session-start.js +5 -1
- package/dist/hooks/runtime/session-start.js.map +1 -1
- package/dist/hooks/runtime/shell-writes.js +311 -0
- package/dist/hooks/runtime/shell-writes.js.map +1 -0
- package/dist/hooks/runtime/sniff.js +84 -5
- package/dist/hooks/runtime/sniff.js.map +1 -1
- package/package.json +2 -2
package/dist/hook-runner.js
CHANGED
|
@@ -39,6 +39,411 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
39
39
|
mod
|
|
40
40
|
));
|
|
41
41
|
|
|
42
|
+
// node_modules/.pnpm/shell-quote@1.10.0/node_modules/shell-quote/quote.js
|
|
43
|
+
var require_quote = __commonJS({
|
|
44
|
+
"node_modules/.pnpm/shell-quote@1.10.0/node_modules/shell-quote/quote.js"(exports, module) {
|
|
45
|
+
"use strict";
|
|
46
|
+
var OPS = (
|
|
47
|
+
/** @type {const} */
|
|
48
|
+
[
|
|
49
|
+
"||",
|
|
50
|
+
"&&",
|
|
51
|
+
";;",
|
|
52
|
+
"|&",
|
|
53
|
+
"<(",
|
|
54
|
+
"<<<",
|
|
55
|
+
">>",
|
|
56
|
+
">&",
|
|
57
|
+
"<&",
|
|
58
|
+
"&",
|
|
59
|
+
";",
|
|
60
|
+
"(",
|
|
61
|
+
")",
|
|
62
|
+
"|",
|
|
63
|
+
"<",
|
|
64
|
+
">"
|
|
65
|
+
]
|
|
66
|
+
);
|
|
67
|
+
var LINE_TERMINATORS = /[\n\r\u2028\u2029]/;
|
|
68
|
+
var GLOB_SHELL_SPECIAL = /[\s#!"$&'():;<=>@\\^`|]/g;
|
|
69
|
+
module.exports = function quote(xs) {
|
|
70
|
+
return xs.map(function(s) {
|
|
71
|
+
if (s === "") {
|
|
72
|
+
return (
|
|
73
|
+
/** @type {const} */
|
|
74
|
+
"''"
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
if (s && typeof s === "object") {
|
|
78
|
+
if ("op" in s && s.op === "glob") {
|
|
79
|
+
if (typeof s.pattern !== "string") {
|
|
80
|
+
throw new TypeError("glob token requires a string `pattern`");
|
|
81
|
+
}
|
|
82
|
+
if (LINE_TERMINATORS.test(s.pattern)) {
|
|
83
|
+
throw new TypeError("glob `pattern` must not contain line terminators");
|
|
84
|
+
}
|
|
85
|
+
return s.pattern.replace(GLOB_SHELL_SPECIAL, "\\$&");
|
|
86
|
+
}
|
|
87
|
+
if ("op" in s && typeof s.op === "string") {
|
|
88
|
+
if (OPS.indexOf(s.op) < 0) {
|
|
89
|
+
throw new TypeError("invalid `op` value: " + JSON.stringify(s.op));
|
|
90
|
+
}
|
|
91
|
+
return s.op.replace(/[\s\S]/g, "\\$&");
|
|
92
|
+
}
|
|
93
|
+
if ("comment" in s && typeof s.comment === "string") {
|
|
94
|
+
if (LINE_TERMINATORS.test(s.comment)) {
|
|
95
|
+
throw new TypeError("`comment` must not contain line terminators");
|
|
96
|
+
}
|
|
97
|
+
return "#" + s.comment;
|
|
98
|
+
}
|
|
99
|
+
throw new TypeError("unrecognized object token shape");
|
|
100
|
+
}
|
|
101
|
+
if (/["\s\\]/.test(s) && !/'/.test(s)) {
|
|
102
|
+
return "'" + s.replace(/(['])/g, "\\$1") + "'";
|
|
103
|
+
}
|
|
104
|
+
if (/["'\s]/.test(s)) {
|
|
105
|
+
return '"' + s.replace(/(["\\$`!])/g, "\\$1") + '"';
|
|
106
|
+
}
|
|
107
|
+
return String(s).replace(/([A-Za-z]:)?([#!"$&'()*,:;<=>?@[\\\]^`{|}~])/g, "$1\\$2");
|
|
108
|
+
}).join(" ");
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
// node_modules/.pnpm/shell-quote@1.10.0/node_modules/shell-quote/parse.js
|
|
114
|
+
var require_parse = __commonJS({
|
|
115
|
+
"node_modules/.pnpm/shell-quote@1.10.0/node_modules/shell-quote/parse.js"(exports, module) {
|
|
116
|
+
"use strict";
|
|
117
|
+
var CONTROL = (
|
|
118
|
+
/** @type {const} */
|
|
119
|
+
"(?:" + /** @type {const} */
|
|
120
|
+
[
|
|
121
|
+
"\\|\\|",
|
|
122
|
+
"\\&\\&",
|
|
123
|
+
";;",
|
|
124
|
+
"\\|\\&",
|
|
125
|
+
"\\<\\(",
|
|
126
|
+
"\\<\\<\\<",
|
|
127
|
+
">>",
|
|
128
|
+
">\\&",
|
|
129
|
+
"<\\&",
|
|
130
|
+
"[&;()|<>]"
|
|
131
|
+
].join(
|
|
132
|
+
/** @type {const} */
|
|
133
|
+
"|"
|
|
134
|
+
) + /** @type {const} */
|
|
135
|
+
")"
|
|
136
|
+
);
|
|
137
|
+
var controlRE = new RegExp("^" + CONTROL + "$");
|
|
138
|
+
var META = (
|
|
139
|
+
/** @type {const} */
|
|
140
|
+
"|&;()<> \\t"
|
|
141
|
+
);
|
|
142
|
+
var SINGLE_QUOTE = (
|
|
143
|
+
/** @type {const} */
|
|
144
|
+
"'([^']*?)'"
|
|
145
|
+
);
|
|
146
|
+
var DOUBLE_QUOTE = (
|
|
147
|
+
/** @type {const} */
|
|
148
|
+
'"((\\\\"|[^"])*?)"'
|
|
149
|
+
);
|
|
150
|
+
var hash = /^#$/;
|
|
151
|
+
var SQ = (
|
|
152
|
+
/** @type {const} */
|
|
153
|
+
"'"
|
|
154
|
+
);
|
|
155
|
+
var DQ = (
|
|
156
|
+
/** @type {const} */
|
|
157
|
+
'"'
|
|
158
|
+
);
|
|
159
|
+
var DS = (
|
|
160
|
+
/** @type {const} */
|
|
161
|
+
"$"
|
|
162
|
+
);
|
|
163
|
+
var TOKEN = "";
|
|
164
|
+
var mult = (
|
|
165
|
+
/** @type {const} */
|
|
166
|
+
4294967296
|
|
167
|
+
);
|
|
168
|
+
for (i = 0; i < 4; i++) {
|
|
169
|
+
TOKEN += (mult * Math.random()).toString(16);
|
|
170
|
+
}
|
|
171
|
+
var i;
|
|
172
|
+
var startsWithToken = new RegExp("^" + TOKEN);
|
|
173
|
+
function matchAll(s, r) {
|
|
174
|
+
var origIndex = r.lastIndex;
|
|
175
|
+
var matches = [];
|
|
176
|
+
var matchObj;
|
|
177
|
+
while (matchObj = r.exec(s)) {
|
|
178
|
+
matches[matches.length] = matchObj;
|
|
179
|
+
if (r.lastIndex === matchObj.index) {
|
|
180
|
+
r.lastIndex += 1;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
r.lastIndex = origIndex;
|
|
184
|
+
return matches;
|
|
185
|
+
}
|
|
186
|
+
function getVar(env, pre, key) {
|
|
187
|
+
var r = typeof env === "function" ? env(key) : env[key];
|
|
188
|
+
if (typeof r === "undefined" && key != "") {
|
|
189
|
+
r = "";
|
|
190
|
+
} else if (typeof r === "undefined") {
|
|
191
|
+
r = "$";
|
|
192
|
+
}
|
|
193
|
+
if (typeof r === "object") {
|
|
194
|
+
return pre + TOKEN + JSON.stringify(r) + TOKEN;
|
|
195
|
+
}
|
|
196
|
+
return pre + r;
|
|
197
|
+
}
|
|
198
|
+
function parseInternal(string, env, opts) {
|
|
199
|
+
if (!opts) {
|
|
200
|
+
opts = {};
|
|
201
|
+
}
|
|
202
|
+
var BS = opts.escape || "\\";
|
|
203
|
+
var ifs = opts.splitUnquoted === true ? " \n" : typeof opts.splitUnquoted === "string" ? opts.splitUnquoted : "";
|
|
204
|
+
var BAREWORD = "(\\" + BS + `['"` + META + `]|[^\\s'"` + META + "])+";
|
|
205
|
+
var chunker = new RegExp([
|
|
206
|
+
"(" + CONTROL + ")",
|
|
207
|
+
// control chars
|
|
208
|
+
"(" + BAREWORD + "|" + DOUBLE_QUOTE + "|" + SINGLE_QUOTE + ")+"
|
|
209
|
+
].join("|"), "g");
|
|
210
|
+
var matches = matchAll(string, chunker);
|
|
211
|
+
if (matches.length === 0) {
|
|
212
|
+
return [];
|
|
213
|
+
}
|
|
214
|
+
if (!env) {
|
|
215
|
+
env = {};
|
|
216
|
+
}
|
|
217
|
+
var commented = false;
|
|
218
|
+
return matches.map(function(match) {
|
|
219
|
+
var s = match[0];
|
|
220
|
+
if (!s || commented) {
|
|
221
|
+
return void 0;
|
|
222
|
+
}
|
|
223
|
+
if (controlRE.test(s)) {
|
|
224
|
+
return (
|
|
225
|
+
/** @type {ControlOperator} */
|
|
226
|
+
{ op: s }
|
|
227
|
+
);
|
|
228
|
+
}
|
|
229
|
+
var quote = false;
|
|
230
|
+
var esc = false;
|
|
231
|
+
var out = "";
|
|
232
|
+
var words = [];
|
|
233
|
+
var sawQuote = false;
|
|
234
|
+
var pendingNw = null;
|
|
235
|
+
var isGlob = false;
|
|
236
|
+
var i2;
|
|
237
|
+
function parseEnvVar() {
|
|
238
|
+
i2 += 1;
|
|
239
|
+
var varend;
|
|
240
|
+
var varname;
|
|
241
|
+
var char = s.charAt(i2);
|
|
242
|
+
if (char === "{") {
|
|
243
|
+
i2 += 1;
|
|
244
|
+
if (s.charAt(i2) === "}") {
|
|
245
|
+
throw new Error("Bad substitution: " + s.slice(i2 - 2, i2 + 1));
|
|
246
|
+
}
|
|
247
|
+
var depth = 1;
|
|
248
|
+
varend = i2;
|
|
249
|
+
while (depth > 0 && varend < s.length) {
|
|
250
|
+
if (s.charAt(varend) === "{" && s.charAt(varend - 1) === "$") {
|
|
251
|
+
depth += 1;
|
|
252
|
+
} else if (s.charAt(varend) === "}") {
|
|
253
|
+
depth -= 1;
|
|
254
|
+
}
|
|
255
|
+
varend += 1;
|
|
256
|
+
}
|
|
257
|
+
if (depth !== 0) {
|
|
258
|
+
throw new Error("Bad substitution: " + s.slice(i2));
|
|
259
|
+
}
|
|
260
|
+
varend -= 1;
|
|
261
|
+
varname = s.slice(i2, varend);
|
|
262
|
+
i2 = varend;
|
|
263
|
+
} else if (/[*@#?$!_-]/.test(char)) {
|
|
264
|
+
varname = char;
|
|
265
|
+
i2 += 1;
|
|
266
|
+
} else {
|
|
267
|
+
var slicedFromI = s.slice(i2);
|
|
268
|
+
varend = slicedFromI.match(/[^\w\d_]/);
|
|
269
|
+
if (!varend) {
|
|
270
|
+
varname = slicedFromI;
|
|
271
|
+
i2 = s.length;
|
|
272
|
+
} else {
|
|
273
|
+
varname = slicedFromI.slice(0, varend.index);
|
|
274
|
+
i2 += /** @type {number} */
|
|
275
|
+
varend.index - 1;
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
return getVar(
|
|
279
|
+
/** @type {NonNullable<typeof env>} */
|
|
280
|
+
env,
|
|
281
|
+
"",
|
|
282
|
+
varname
|
|
283
|
+
);
|
|
284
|
+
}
|
|
285
|
+
function flushRun() {
|
|
286
|
+
if (pendingNw === null) {
|
|
287
|
+
return;
|
|
288
|
+
}
|
|
289
|
+
if (pendingNw === 0) {
|
|
290
|
+
if (out !== "") {
|
|
291
|
+
words[words.length] = out;
|
|
292
|
+
out = "";
|
|
293
|
+
}
|
|
294
|
+
} else {
|
|
295
|
+
words[words.length] = out;
|
|
296
|
+
out = "";
|
|
297
|
+
for (var fe = 1; fe < pendingNw; fe += 1) {
|
|
298
|
+
words[words.length] = "";
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
pendingNw = null;
|
|
302
|
+
}
|
|
303
|
+
for (i2 = 0; i2 < s.length; i2++) {
|
|
304
|
+
var c = s.charAt(i2);
|
|
305
|
+
if (ifs && c !== DS) {
|
|
306
|
+
flushRun();
|
|
307
|
+
}
|
|
308
|
+
isGlob = isGlob || !quote && (c === "*" || c === "?");
|
|
309
|
+
if (esc) {
|
|
310
|
+
out += c;
|
|
311
|
+
esc = false;
|
|
312
|
+
} else if (quote) {
|
|
313
|
+
if (c === quote) {
|
|
314
|
+
quote = false;
|
|
315
|
+
} else if (quote == SQ) {
|
|
316
|
+
out += c;
|
|
317
|
+
} else {
|
|
318
|
+
if (c === BS) {
|
|
319
|
+
i2 += 1;
|
|
320
|
+
c = s.charAt(i2);
|
|
321
|
+
if (c === DQ || c === BS || c === DS) {
|
|
322
|
+
out += c;
|
|
323
|
+
} else {
|
|
324
|
+
out += BS + c;
|
|
325
|
+
}
|
|
326
|
+
} else if (c === DS) {
|
|
327
|
+
out += parseEnvVar();
|
|
328
|
+
} else {
|
|
329
|
+
out += c;
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
} else if (c === DQ || c === SQ) {
|
|
333
|
+
quote = c;
|
|
334
|
+
sawQuote = true;
|
|
335
|
+
} else if (controlRE.test(c)) {
|
|
336
|
+
return (
|
|
337
|
+
/** @type {ControlOperator} */
|
|
338
|
+
{ op: s }
|
|
339
|
+
);
|
|
340
|
+
} else if (hash.test(c)) {
|
|
341
|
+
commented = true;
|
|
342
|
+
var commentObj = { comment: string.slice(match.index + i2 + 1) };
|
|
343
|
+
if (out.length) {
|
|
344
|
+
return (
|
|
345
|
+
/** @type {const} */
|
|
346
|
+
[out, commentObj]
|
|
347
|
+
);
|
|
348
|
+
}
|
|
349
|
+
return (
|
|
350
|
+
/** @type {const} */
|
|
351
|
+
[commentObj]
|
|
352
|
+
);
|
|
353
|
+
} else if (c === BS) {
|
|
354
|
+
esc = true;
|
|
355
|
+
} else if (c === DS) {
|
|
356
|
+
var value = parseEnvVar();
|
|
357
|
+
if (!ifs) {
|
|
358
|
+
out += value;
|
|
359
|
+
} else {
|
|
360
|
+
for (var vi = 0; vi < value.length; vi += 1) {
|
|
361
|
+
var vc = value.charAt(vi);
|
|
362
|
+
if (ifs.indexOf(vc) < 0) {
|
|
363
|
+
flushRun();
|
|
364
|
+
out += vc;
|
|
365
|
+
} else if (pendingNw === null) {
|
|
366
|
+
pendingNw = vc === " " || vc === " " || vc === "\n" ? 0 : 1;
|
|
367
|
+
} else if (vc !== " " && vc !== " " && vc !== "\n") {
|
|
368
|
+
pendingNw += 1;
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
} else {
|
|
373
|
+
out += c;
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
if (isGlob) {
|
|
377
|
+
return (
|
|
378
|
+
/** @type {GlobPattern} */
|
|
379
|
+
{ op: "glob", pattern: out }
|
|
380
|
+
);
|
|
381
|
+
}
|
|
382
|
+
if (ifs) {
|
|
383
|
+
if (pendingNw !== null && pendingNw > 0) {
|
|
384
|
+
words[words.length] = out;
|
|
385
|
+
out = "";
|
|
386
|
+
for (var te = 1; te < pendingNw; te += 1) {
|
|
387
|
+
words[words.length] = "";
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
if (out !== "" || sawQuote && words.length === 0) {
|
|
391
|
+
words[words.length] = out;
|
|
392
|
+
}
|
|
393
|
+
return words;
|
|
394
|
+
}
|
|
395
|
+
return out;
|
|
396
|
+
}).reduce(
|
|
397
|
+
function(prev, arg) {
|
|
398
|
+
if (typeof arg === "undefined") {
|
|
399
|
+
return prev;
|
|
400
|
+
}
|
|
401
|
+
[].concat(arg).forEach(function(entry) {
|
|
402
|
+
prev[prev.length] = entry;
|
|
403
|
+
});
|
|
404
|
+
return prev;
|
|
405
|
+
},
|
|
406
|
+
/** @type {ParseEntry[]} */
|
|
407
|
+
[]
|
|
408
|
+
);
|
|
409
|
+
}
|
|
410
|
+
module.exports = function parse(s, env, opts) {
|
|
411
|
+
var mapped = parseInternal(s, env, opts);
|
|
412
|
+
if (typeof env !== "function") {
|
|
413
|
+
return mapped;
|
|
414
|
+
}
|
|
415
|
+
return mapped.reduce(
|
|
416
|
+
function(acc, s2) {
|
|
417
|
+
if (typeof s2 === "object") {
|
|
418
|
+
acc[acc.length] = s2;
|
|
419
|
+
return acc;
|
|
420
|
+
}
|
|
421
|
+
var xs = s2.split(RegExp("(" + TOKEN + ".*?" + TOKEN + ")", "g"));
|
|
422
|
+
if (xs.length === 1) {
|
|
423
|
+
acc[acc.length] = xs[0];
|
|
424
|
+
return acc;
|
|
425
|
+
}
|
|
426
|
+
xs.filter(Boolean).forEach(function(x) {
|
|
427
|
+
acc[acc.length] = startsWithToken.test(x) ? JSON.parse(x.split(TOKEN)[1]) : x;
|
|
428
|
+
});
|
|
429
|
+
return acc;
|
|
430
|
+
},
|
|
431
|
+
/** @type {ParseEntry[]} */
|
|
432
|
+
[]
|
|
433
|
+
);
|
|
434
|
+
};
|
|
435
|
+
}
|
|
436
|
+
});
|
|
437
|
+
|
|
438
|
+
// node_modules/.pnpm/shell-quote@1.10.0/node_modules/shell-quote/index.js
|
|
439
|
+
var require_shell_quote = __commonJS({
|
|
440
|
+
"node_modules/.pnpm/shell-quote@1.10.0/node_modules/shell-quote/index.js"(exports) {
|
|
441
|
+
"use strict";
|
|
442
|
+
exports.quote = require_quote();
|
|
443
|
+
exports.parse = require_parse();
|
|
444
|
+
}
|
|
445
|
+
});
|
|
446
|
+
|
|
42
447
|
// node_modules/.pnpm/re2-wasm@1.0.2/node_modules/re2-wasm/build/wasm/re2.js
|
|
43
448
|
var require_re2 = __commonJS({
|
|
44
449
|
"node_modules/.pnpm/re2-wasm@1.0.2/node_modules/re2-wasm/build/wasm/re2.js"(exports, module) {
|
|
@@ -3890,676 +4295,499 @@ var require_re22 = __commonJS({
|
|
|
3890
4295
|
get unicode() {
|
|
3891
4296
|
return this._unicode;
|
|
3892
4297
|
}
|
|
3893
|
-
get sticky() {
|
|
3894
|
-
return this._sticky;
|
|
3895
|
-
}
|
|
3896
|
-
toString() {
|
|
3897
|
-
return `/${this.pattern}/${this.flags}`;
|
|
3898
|
-
}
|
|
3899
|
-
getMaybeStickyIndex() {
|
|
3900
|
-
if (this._global || this._sticky) {
|
|
3901
|
-
return this.lastIndex;
|
|
3902
|
-
} else {
|
|
3903
|
-
return 0;
|
|
3904
|
-
}
|
|
3905
|
-
}
|
|
3906
|
-
isMatchSuccessful(match, searchStart) {
|
|
3907
|
-
return match.index === searchStart || !this._sticky && match.index >= 0;
|
|
3908
|
-
}
|
|
3909
|
-
maybeUpdateLastIndex(match, start) {
|
|
3910
|
-
if (this._global || this._sticky) {
|
|
3911
|
-
if (this.isMatchSuccessful(match, start)) {
|
|
3912
|
-
this.lastIndex = match.index + match.match.length;
|
|
3913
|
-
} else {
|
|
3914
|
-
this.lastIndex = 0;
|
|
3915
|
-
}
|
|
3916
|
-
}
|
|
3917
|
-
}
|
|
3918
|
-
getNamedGroups(match) {
|
|
3919
|
-
const groups = {};
|
|
3920
|
-
for (const [groupName, groupNum] of Object.entries(this.namedGroups)) {
|
|
3921
|
-
if (match.groups[groupNum - 1] !== void 0) {
|
|
3922
|
-
groups[groupName] = match.groups[groupNum - 1];
|
|
3923
|
-
}
|
|
3924
|
-
}
|
|
3925
|
-
return groups;
|
|
3926
|
-
}
|
|
3927
|
-
exec(input) {
|
|
3928
|
-
if (typeof input !== "string") {
|
|
3929
|
-
input = input + "";
|
|
3930
|
-
}
|
|
3931
|
-
const startIndex = this.getMaybeStickyIndex();
|
|
3932
|
-
const match = this.wrapper.match(input, startIndex, true);
|
|
3933
|
-
this.maybeUpdateLastIndex(match, startIndex);
|
|
3934
|
-
if (!this.isMatchSuccessful(match, startIndex)) {
|
|
3935
|
-
return null;
|
|
3936
|
-
}
|
|
3937
|
-
const result = [match.match, ...match.groups];
|
|
3938
|
-
result.index = match.index;
|
|
3939
|
-
result.input = input;
|
|
3940
|
-
const groups = this.getNamedGroups(match);
|
|
3941
|
-
if (Object.keys(groups).length > 0) {
|
|
3942
|
-
result.groups = groups;
|
|
3943
|
-
}
|
|
3944
|
-
return result;
|
|
3945
|
-
}
|
|
3946
|
-
test(input) {
|
|
3947
|
-
if (typeof input !== "string") {
|
|
3948
|
-
input = input + "";
|
|
3949
|
-
}
|
|
3950
|
-
const startIndex = this.getMaybeStickyIndex();
|
|
3951
|
-
const match = this.wrapper.match(input, this.getMaybeStickyIndex(), false);
|
|
3952
|
-
this.maybeUpdateLastIndex(match, startIndex);
|
|
3953
|
-
return this.isMatchSuccessful(match, startIndex);
|
|
3954
|
-
}
|
|
3955
|
-
compile() {
|
|
3956
|
-
throw new Error("Deprecated RegExp method compile is not implemented in RE2.");
|
|
3957
|
-
}
|
|
3958
|
-
[Symbol.match](input) {
|
|
3959
|
-
if (typeof input !== "string") {
|
|
3960
|
-
input = input + "";
|
|
3961
|
-
}
|
|
3962
|
-
if (this._global) {
|
|
3963
|
-
const result = [];
|
|
3964
|
-
let nextIndex = 0;
|
|
3965
|
-
let success;
|
|
3966
|
-
do {
|
|
3967
|
-
const match = this.wrapper.match(input, nextIndex, false);
|
|
3968
|
-
success = match.index === nextIndex || !this._sticky && match.index >= 0;
|
|
3969
|
-
if (success) {
|
|
3970
|
-
result.push(match.match);
|
|
3971
|
-
nextIndex = match.index + match.match.length;
|
|
3972
|
-
}
|
|
3973
|
-
} while (success);
|
|
3974
|
-
if (result.length === 0) {
|
|
3975
|
-
return null;
|
|
3976
|
-
} else {
|
|
3977
|
-
return result;
|
|
3978
|
-
}
|
|
3979
|
-
} else {
|
|
3980
|
-
const startIndex = this.getMaybeStickyIndex();
|
|
3981
|
-
const match = this.wrapper.match(input, startIndex, true);
|
|
3982
|
-
this.maybeUpdateLastIndex(match, startIndex);
|
|
3983
|
-
if (!this.isMatchSuccessful(match, startIndex)) {
|
|
3984
|
-
return null;
|
|
3985
|
-
}
|
|
3986
|
-
const result = [match.match, ...match.groups];
|
|
3987
|
-
result.index = match.index;
|
|
3988
|
-
result.input = input;
|
|
3989
|
-
const groups = this.getNamedGroups(match);
|
|
3990
|
-
if (Object.keys(groups).length > 0) {
|
|
3991
|
-
result.groups = groups;
|
|
3992
|
-
}
|
|
3993
|
-
return result;
|
|
3994
|
-
}
|
|
3995
|
-
}
|
|
3996
|
-
match(input) {
|
|
3997
|
-
return this[Symbol.match](input);
|
|
3998
|
-
}
|
|
3999
|
-
/**
|
|
4000
|
-
* Outputs the replacement for the matched part of the string
|
|
4001
|
-
* @param input
|
|
4002
|
-
* @param match
|
|
4003
|
-
* @param replacer
|
|
4004
|
-
*/
|
|
4005
|
-
replaceMatch(input, match, replacer) {
|
|
4006
|
-
var _a, _b;
|
|
4007
|
-
if (typeof replacer === "string") {
|
|
4008
|
-
let result = "";
|
|
4009
|
-
for (let i = 0; i < replacer.length; i++) {
|
|
4010
|
-
if (replacer[i] === "$") {
|
|
4011
|
-
switch (replacer[i + 1]) {
|
|
4012
|
-
case "$":
|
|
4013
|
-
result += "$";
|
|
4014
|
-
i++;
|
|
4015
|
-
break;
|
|
4016
|
-
case "&":
|
|
4017
|
-
result += match.match;
|
|
4018
|
-
i++;
|
|
4019
|
-
break;
|
|
4020
|
-
case "`":
|
|
4021
|
-
result += input.substring(0, match.index);
|
|
4022
|
-
i++;
|
|
4023
|
-
break;
|
|
4024
|
-
case "'":
|
|
4025
|
-
result += input.substring(match.index + match.match.length);
|
|
4026
|
-
i++;
|
|
4027
|
-
break;
|
|
4028
|
-
case "<": {
|
|
4029
|
-
const endCaret = replacer.indexOf(">", i);
|
|
4030
|
-
if (endCaret < 0) {
|
|
4031
|
-
throw new Error("Invalid named group replacement");
|
|
4032
|
-
}
|
|
4033
|
-
const groupName = replacer.substring(i + 2, endCaret);
|
|
4034
|
-
if (groupName in this.namedGroups) {
|
|
4035
|
-
result += (_a = match.groups[this.namedGroups[groupName] - 1]) !== null && _a !== void 0 ? _a : "";
|
|
4036
|
-
}
|
|
4037
|
-
i = endCaret;
|
|
4038
|
-
break;
|
|
4039
|
-
}
|
|
4040
|
-
default: {
|
|
4041
|
-
let groupNum;
|
|
4042
|
-
if ("123456789".includes(replacer[i + 1])) {
|
|
4043
|
-
if ("0123456789".includes(replacer[i + 2])) {
|
|
4044
|
-
groupNum = Number.parseInt(replacer.substring(i + 1, i + 3)) - 1;
|
|
4045
|
-
i += 2;
|
|
4046
|
-
} else {
|
|
4047
|
-
groupNum = Number.parseInt(replacer[i + 1]) - 1;
|
|
4048
|
-
i++;
|
|
4049
|
-
}
|
|
4050
|
-
} else {
|
|
4051
|
-
throw new Error("Invalid replacement string");
|
|
4052
|
-
}
|
|
4053
|
-
if (groupNum < match.groups.length) {
|
|
4054
|
-
result += (_b = match.groups[groupNum]) !== null && _b !== void 0 ? _b : "";
|
|
4055
|
-
} else {
|
|
4056
|
-
result += "$" + groupNum;
|
|
4057
|
-
}
|
|
4058
|
-
}
|
|
4059
|
-
}
|
|
4060
|
-
} else {
|
|
4061
|
-
result += replacer[i];
|
|
4062
|
-
}
|
|
4063
|
-
}
|
|
4064
|
-
return result;
|
|
4065
|
-
} else {
|
|
4066
|
-
return replacer(match.match, ...match.groups, match.index, input, this.getNamedGroups(match));
|
|
4067
|
-
}
|
|
4068
|
-
}
|
|
4069
|
-
[Symbol.replace](input, replacer) {
|
|
4070
|
-
if (typeof input !== "string") {
|
|
4071
|
-
input = input + "";
|
|
4072
|
-
}
|
|
4073
|
-
if (typeof replacer !== "function") {
|
|
4074
|
-
replacer = replacer + "";
|
|
4075
|
-
}
|
|
4076
|
-
if (this._global) {
|
|
4077
|
-
let result = "";
|
|
4078
|
-
let nextIndex = 0;
|
|
4079
|
-
let success;
|
|
4080
|
-
do {
|
|
4081
|
-
const match = this.wrapper.match(input, nextIndex, true);
|
|
4082
|
-
success = match.index === nextIndex || !this._sticky && match.index >= 0;
|
|
4083
|
-
if (success) {
|
|
4084
|
-
result += input.substring(nextIndex, match.index) + this.replaceMatch(input, match, replacer);
|
|
4085
|
-
nextIndex = match.index + match.match.length;
|
|
4086
|
-
}
|
|
4087
|
-
} while (success);
|
|
4088
|
-
result += input.substring(nextIndex);
|
|
4089
|
-
this.lastIndex = 0;
|
|
4090
|
-
return result;
|
|
4091
|
-
} else {
|
|
4092
|
-
const startIndex = this.getMaybeStickyIndex();
|
|
4093
|
-
const match = this.wrapper.match(input, startIndex, true);
|
|
4094
|
-
this.maybeUpdateLastIndex(match, startIndex);
|
|
4095
|
-
if (this.isMatchSuccessful(match, startIndex)) {
|
|
4096
|
-
return input.substring(0, match.index) + this.replaceMatch(input, match, replacer) + input.substring(match.index + match.match.length);
|
|
4097
|
-
} else {
|
|
4098
|
-
return input;
|
|
4099
|
-
}
|
|
4100
|
-
}
|
|
4101
|
-
}
|
|
4102
|
-
replace(input, replacer) {
|
|
4103
|
-
return this[Symbol.replace](input, replacer);
|
|
4298
|
+
get sticky() {
|
|
4299
|
+
return this._sticky;
|
|
4104
4300
|
}
|
|
4105
|
-
|
|
4106
|
-
|
|
4107
|
-
|
|
4108
|
-
|
|
4109
|
-
|
|
4110
|
-
|
|
4111
|
-
return -1;
|
|
4301
|
+
toString() {
|
|
4302
|
+
return `/${this.pattern}/${this.flags}`;
|
|
4303
|
+
}
|
|
4304
|
+
getMaybeStickyIndex() {
|
|
4305
|
+
if (this._global || this._sticky) {
|
|
4306
|
+
return this.lastIndex;
|
|
4112
4307
|
} else {
|
|
4113
|
-
return
|
|
4308
|
+
return 0;
|
|
4114
4309
|
}
|
|
4115
4310
|
}
|
|
4116
|
-
|
|
4117
|
-
return this
|
|
4311
|
+
isMatchSuccessful(match, searchStart) {
|
|
4312
|
+
return match.index === searchStart || !this._sticky && match.index >= 0;
|
|
4118
4313
|
}
|
|
4119
|
-
|
|
4120
|
-
if (
|
|
4121
|
-
|
|
4122
|
-
|
|
4123
|
-
const output = [];
|
|
4124
|
-
let nextIndex = 0;
|
|
4125
|
-
limit = limit !== null && limit !== void 0 ? limit : Infinity;
|
|
4126
|
-
while (output.length < limit) {
|
|
4127
|
-
const nextMatch = this.wrapper.match(input, nextIndex, true);
|
|
4128
|
-
if (nextMatch.index >= 0) {
|
|
4129
|
-
if (nextMatch.match.length === 0) {
|
|
4130
|
-
output.push(input.substring(nextIndex, nextIndex + 1));
|
|
4131
|
-
nextIndex = nextIndex + 1;
|
|
4132
|
-
} else {
|
|
4133
|
-
output.push(input.substring(nextIndex, nextMatch.index));
|
|
4134
|
-
nextIndex = nextMatch.index + nextMatch.match.length;
|
|
4135
|
-
}
|
|
4136
|
-
for (const group of nextMatch.groups) {
|
|
4137
|
-
if (output.length >= limit) {
|
|
4138
|
-
break;
|
|
4139
|
-
}
|
|
4140
|
-
output.push(group);
|
|
4141
|
-
}
|
|
4314
|
+
maybeUpdateLastIndex(match, start) {
|
|
4315
|
+
if (this._global || this._sticky) {
|
|
4316
|
+
if (this.isMatchSuccessful(match, start)) {
|
|
4317
|
+
this.lastIndex = match.index + match.match.length;
|
|
4142
4318
|
} else {
|
|
4143
|
-
|
|
4144
|
-
break;
|
|
4319
|
+
this.lastIndex = 0;
|
|
4145
4320
|
}
|
|
4146
4321
|
}
|
|
4147
|
-
return output;
|
|
4148
|
-
}
|
|
4149
|
-
split(input, limit) {
|
|
4150
|
-
return this[Symbol.split](input, limit);
|
|
4151
4322
|
}
|
|
4152
|
-
|
|
4153
|
-
|
|
4154
|
-
|
|
4155
|
-
|
|
4156
|
-
|
|
4157
|
-
// node_modules/.pnpm/shell-quote@1.10.0/node_modules/shell-quote/quote.js
|
|
4158
|
-
var require_quote = __commonJS({
|
|
4159
|
-
"node_modules/.pnpm/shell-quote@1.10.0/node_modules/shell-quote/quote.js"(exports, module) {
|
|
4160
|
-
"use strict";
|
|
4161
|
-
var OPS = (
|
|
4162
|
-
/** @type {const} */
|
|
4163
|
-
[
|
|
4164
|
-
"||",
|
|
4165
|
-
"&&",
|
|
4166
|
-
";;",
|
|
4167
|
-
"|&",
|
|
4168
|
-
"<(",
|
|
4169
|
-
"<<<",
|
|
4170
|
-
">>",
|
|
4171
|
-
">&",
|
|
4172
|
-
"<&",
|
|
4173
|
-
"&",
|
|
4174
|
-
";",
|
|
4175
|
-
"(",
|
|
4176
|
-
")",
|
|
4177
|
-
"|",
|
|
4178
|
-
"<",
|
|
4179
|
-
">"
|
|
4180
|
-
]
|
|
4181
|
-
);
|
|
4182
|
-
var LINE_TERMINATORS = /[\n\r\u2028\u2029]/;
|
|
4183
|
-
var GLOB_SHELL_SPECIAL = /[\s#!"$&'():;<=>@\\^`|]/g;
|
|
4184
|
-
module.exports = function quote(xs) {
|
|
4185
|
-
return xs.map(function(s) {
|
|
4186
|
-
if (s === "") {
|
|
4187
|
-
return (
|
|
4188
|
-
/** @type {const} */
|
|
4189
|
-
"''"
|
|
4190
|
-
);
|
|
4191
|
-
}
|
|
4192
|
-
if (s && typeof s === "object") {
|
|
4193
|
-
if ("op" in s && s.op === "glob") {
|
|
4194
|
-
if (typeof s.pattern !== "string") {
|
|
4195
|
-
throw new TypeError("glob token requires a string `pattern`");
|
|
4196
|
-
}
|
|
4197
|
-
if (LINE_TERMINATORS.test(s.pattern)) {
|
|
4198
|
-
throw new TypeError("glob `pattern` must not contain line terminators");
|
|
4199
|
-
}
|
|
4200
|
-
return s.pattern.replace(GLOB_SHELL_SPECIAL, "\\$&");
|
|
4201
|
-
}
|
|
4202
|
-
if ("op" in s && typeof s.op === "string") {
|
|
4203
|
-
if (OPS.indexOf(s.op) < 0) {
|
|
4204
|
-
throw new TypeError("invalid `op` value: " + JSON.stringify(s.op));
|
|
4205
|
-
}
|
|
4206
|
-
return s.op.replace(/[\s\S]/g, "\\$&");
|
|
4207
|
-
}
|
|
4208
|
-
if ("comment" in s && typeof s.comment === "string") {
|
|
4209
|
-
if (LINE_TERMINATORS.test(s.comment)) {
|
|
4210
|
-
throw new TypeError("`comment` must not contain line terminators");
|
|
4211
|
-
}
|
|
4212
|
-
return "#" + s.comment;
|
|
4323
|
+
getNamedGroups(match) {
|
|
4324
|
+
const groups = {};
|
|
4325
|
+
for (const [groupName, groupNum] of Object.entries(this.namedGroups)) {
|
|
4326
|
+
if (match.groups[groupNum - 1] !== void 0) {
|
|
4327
|
+
groups[groupName] = match.groups[groupNum - 1];
|
|
4213
4328
|
}
|
|
4214
|
-
throw new TypeError("unrecognized object token shape");
|
|
4215
4329
|
}
|
|
4216
|
-
|
|
4217
|
-
|
|
4330
|
+
return groups;
|
|
4331
|
+
}
|
|
4332
|
+
exec(input) {
|
|
4333
|
+
if (typeof input !== "string") {
|
|
4334
|
+
input = input + "";
|
|
4218
4335
|
}
|
|
4219
|
-
|
|
4220
|
-
|
|
4336
|
+
const startIndex = this.getMaybeStickyIndex();
|
|
4337
|
+
const match = this.wrapper.match(input, startIndex, true);
|
|
4338
|
+
this.maybeUpdateLastIndex(match, startIndex);
|
|
4339
|
+
if (!this.isMatchSuccessful(match, startIndex)) {
|
|
4340
|
+
return null;
|
|
4221
4341
|
}
|
|
4222
|
-
|
|
4223
|
-
|
|
4224
|
-
|
|
4225
|
-
|
|
4226
|
-
|
|
4227
|
-
|
|
4228
|
-
// node_modules/.pnpm/shell-quote@1.10.0/node_modules/shell-quote/parse.js
|
|
4229
|
-
var require_parse = __commonJS({
|
|
4230
|
-
"node_modules/.pnpm/shell-quote@1.10.0/node_modules/shell-quote/parse.js"(exports, module) {
|
|
4231
|
-
"use strict";
|
|
4232
|
-
var CONTROL = (
|
|
4233
|
-
/** @type {const} */
|
|
4234
|
-
"(?:" + /** @type {const} */
|
|
4235
|
-
[
|
|
4236
|
-
"\\|\\|",
|
|
4237
|
-
"\\&\\&",
|
|
4238
|
-
";;",
|
|
4239
|
-
"\\|\\&",
|
|
4240
|
-
"\\<\\(",
|
|
4241
|
-
"\\<\\<\\<",
|
|
4242
|
-
">>",
|
|
4243
|
-
">\\&",
|
|
4244
|
-
"<\\&",
|
|
4245
|
-
"[&;()|<>]"
|
|
4246
|
-
].join(
|
|
4247
|
-
/** @type {const} */
|
|
4248
|
-
"|"
|
|
4249
|
-
) + /** @type {const} */
|
|
4250
|
-
")"
|
|
4251
|
-
);
|
|
4252
|
-
var controlRE = new RegExp("^" + CONTROL + "$");
|
|
4253
|
-
var META = (
|
|
4254
|
-
/** @type {const} */
|
|
4255
|
-
"|&;()<> \\t"
|
|
4256
|
-
);
|
|
4257
|
-
var SINGLE_QUOTE = (
|
|
4258
|
-
/** @type {const} */
|
|
4259
|
-
"'([^']*?)'"
|
|
4260
|
-
);
|
|
4261
|
-
var DOUBLE_QUOTE = (
|
|
4262
|
-
/** @type {const} */
|
|
4263
|
-
'"((\\\\"|[^"])*?)"'
|
|
4264
|
-
);
|
|
4265
|
-
var hash = /^#$/;
|
|
4266
|
-
var SQ = (
|
|
4267
|
-
/** @type {const} */
|
|
4268
|
-
"'"
|
|
4269
|
-
);
|
|
4270
|
-
var DQ = (
|
|
4271
|
-
/** @type {const} */
|
|
4272
|
-
'"'
|
|
4273
|
-
);
|
|
4274
|
-
var DS = (
|
|
4275
|
-
/** @type {const} */
|
|
4276
|
-
"$"
|
|
4277
|
-
);
|
|
4278
|
-
var TOKEN = "";
|
|
4279
|
-
var mult = (
|
|
4280
|
-
/** @type {const} */
|
|
4281
|
-
4294967296
|
|
4282
|
-
);
|
|
4283
|
-
for (i = 0; i < 4; i++) {
|
|
4284
|
-
TOKEN += (mult * Math.random()).toString(16);
|
|
4285
|
-
}
|
|
4286
|
-
var i;
|
|
4287
|
-
var startsWithToken = new RegExp("^" + TOKEN);
|
|
4288
|
-
function matchAll(s, r) {
|
|
4289
|
-
var origIndex = r.lastIndex;
|
|
4290
|
-
var matches = [];
|
|
4291
|
-
var matchObj;
|
|
4292
|
-
while (matchObj = r.exec(s)) {
|
|
4293
|
-
matches[matches.length] = matchObj;
|
|
4294
|
-
if (r.lastIndex === matchObj.index) {
|
|
4295
|
-
r.lastIndex += 1;
|
|
4342
|
+
const result = [match.match, ...match.groups];
|
|
4343
|
+
result.index = match.index;
|
|
4344
|
+
result.input = input;
|
|
4345
|
+
const groups = this.getNamedGroups(match);
|
|
4346
|
+
if (Object.keys(groups).length > 0) {
|
|
4347
|
+
result.groups = groups;
|
|
4296
4348
|
}
|
|
4349
|
+
return result;
|
|
4297
4350
|
}
|
|
4298
|
-
|
|
4299
|
-
|
|
4300
|
-
|
|
4301
|
-
|
|
4302
|
-
|
|
4303
|
-
|
|
4304
|
-
|
|
4305
|
-
|
|
4306
|
-
r = "$";
|
|
4307
|
-
}
|
|
4308
|
-
if (typeof r === "object") {
|
|
4309
|
-
return pre + TOKEN + JSON.stringify(r) + TOKEN;
|
|
4310
|
-
}
|
|
4311
|
-
return pre + r;
|
|
4312
|
-
}
|
|
4313
|
-
function parseInternal(string, env, opts) {
|
|
4314
|
-
if (!opts) {
|
|
4315
|
-
opts = {};
|
|
4316
|
-
}
|
|
4317
|
-
var BS = opts.escape || "\\";
|
|
4318
|
-
var ifs = opts.splitUnquoted === true ? " \n" : typeof opts.splitUnquoted === "string" ? opts.splitUnquoted : "";
|
|
4319
|
-
var BAREWORD = "(\\" + BS + `['"` + META + `]|[^\\s'"` + META + "])+";
|
|
4320
|
-
var chunker = new RegExp([
|
|
4321
|
-
"(" + CONTROL + ")",
|
|
4322
|
-
// control chars
|
|
4323
|
-
"(" + BAREWORD + "|" + DOUBLE_QUOTE + "|" + SINGLE_QUOTE + ")+"
|
|
4324
|
-
].join("|"), "g");
|
|
4325
|
-
var matches = matchAll(string, chunker);
|
|
4326
|
-
if (matches.length === 0) {
|
|
4327
|
-
return [];
|
|
4351
|
+
test(input) {
|
|
4352
|
+
if (typeof input !== "string") {
|
|
4353
|
+
input = input + "";
|
|
4354
|
+
}
|
|
4355
|
+
const startIndex = this.getMaybeStickyIndex();
|
|
4356
|
+
const match = this.wrapper.match(input, this.getMaybeStickyIndex(), false);
|
|
4357
|
+
this.maybeUpdateLastIndex(match, startIndex);
|
|
4358
|
+
return this.isMatchSuccessful(match, startIndex);
|
|
4328
4359
|
}
|
|
4329
|
-
|
|
4330
|
-
|
|
4360
|
+
compile() {
|
|
4361
|
+
throw new Error("Deprecated RegExp method compile is not implemented in RE2.");
|
|
4331
4362
|
}
|
|
4332
|
-
|
|
4333
|
-
|
|
4334
|
-
|
|
4335
|
-
if (!s || commented) {
|
|
4336
|
-
return void 0;
|
|
4337
|
-
}
|
|
4338
|
-
if (controlRE.test(s)) {
|
|
4339
|
-
return (
|
|
4340
|
-
/** @type {ControlOperator} */
|
|
4341
|
-
{ op: s }
|
|
4342
|
-
);
|
|
4363
|
+
[Symbol.match](input) {
|
|
4364
|
+
if (typeof input !== "string") {
|
|
4365
|
+
input = input + "";
|
|
4343
4366
|
}
|
|
4344
|
-
|
|
4345
|
-
|
|
4346
|
-
|
|
4347
|
-
|
|
4348
|
-
|
|
4349
|
-
|
|
4350
|
-
|
|
4351
|
-
|
|
4352
|
-
|
|
4353
|
-
|
|
4354
|
-
var varend;
|
|
4355
|
-
var varname;
|
|
4356
|
-
var char = s.charAt(i2);
|
|
4357
|
-
if (char === "{") {
|
|
4358
|
-
i2 += 1;
|
|
4359
|
-
if (s.charAt(i2) === "}") {
|
|
4360
|
-
throw new Error("Bad substitution: " + s.slice(i2 - 2, i2 + 1));
|
|
4361
|
-
}
|
|
4362
|
-
var depth = 1;
|
|
4363
|
-
varend = i2;
|
|
4364
|
-
while (depth > 0 && varend < s.length) {
|
|
4365
|
-
if (s.charAt(varend) === "{" && s.charAt(varend - 1) === "$") {
|
|
4366
|
-
depth += 1;
|
|
4367
|
-
} else if (s.charAt(varend) === "}") {
|
|
4368
|
-
depth -= 1;
|
|
4369
|
-
}
|
|
4370
|
-
varend += 1;
|
|
4371
|
-
}
|
|
4372
|
-
if (depth !== 0) {
|
|
4373
|
-
throw new Error("Bad substitution: " + s.slice(i2));
|
|
4367
|
+
if (this._global) {
|
|
4368
|
+
const result = [];
|
|
4369
|
+
let nextIndex = 0;
|
|
4370
|
+
let success;
|
|
4371
|
+
do {
|
|
4372
|
+
const match = this.wrapper.match(input, nextIndex, false);
|
|
4373
|
+
success = match.index === nextIndex || !this._sticky && match.index >= 0;
|
|
4374
|
+
if (success) {
|
|
4375
|
+
result.push(match.match);
|
|
4376
|
+
nextIndex = match.index + match.match.length;
|
|
4374
4377
|
}
|
|
4375
|
-
|
|
4376
|
-
|
|
4377
|
-
|
|
4378
|
-
} else if (/[*@#?$!_-]/.test(char)) {
|
|
4379
|
-
varname = char;
|
|
4380
|
-
i2 += 1;
|
|
4378
|
+
} while (success);
|
|
4379
|
+
if (result.length === 0) {
|
|
4380
|
+
return null;
|
|
4381
4381
|
} else {
|
|
4382
|
-
|
|
4383
|
-
varend = slicedFromI.match(/[^\w\d_]/);
|
|
4384
|
-
if (!varend) {
|
|
4385
|
-
varname = slicedFromI;
|
|
4386
|
-
i2 = s.length;
|
|
4387
|
-
} else {
|
|
4388
|
-
varname = slicedFromI.slice(0, varend.index);
|
|
4389
|
-
i2 += /** @type {number} */
|
|
4390
|
-
varend.index - 1;
|
|
4391
|
-
}
|
|
4382
|
+
return result;
|
|
4392
4383
|
}
|
|
4393
|
-
|
|
4394
|
-
|
|
4395
|
-
|
|
4396
|
-
|
|
4397
|
-
|
|
4398
|
-
|
|
4399
|
-
}
|
|
4400
|
-
function flushRun() {
|
|
4401
|
-
if (pendingNw === null) {
|
|
4402
|
-
return;
|
|
4384
|
+
} else {
|
|
4385
|
+
const startIndex = this.getMaybeStickyIndex();
|
|
4386
|
+
const match = this.wrapper.match(input, startIndex, true);
|
|
4387
|
+
this.maybeUpdateLastIndex(match, startIndex);
|
|
4388
|
+
if (!this.isMatchSuccessful(match, startIndex)) {
|
|
4389
|
+
return null;
|
|
4403
4390
|
}
|
|
4404
|
-
|
|
4405
|
-
|
|
4406
|
-
|
|
4407
|
-
|
|
4408
|
-
|
|
4409
|
-
|
|
4410
|
-
words[words.length] = out;
|
|
4411
|
-
out = "";
|
|
4412
|
-
for (var fe = 1; fe < pendingNw; fe += 1) {
|
|
4413
|
-
words[words.length] = "";
|
|
4414
|
-
}
|
|
4391
|
+
const result = [match.match, ...match.groups];
|
|
4392
|
+
result.index = match.index;
|
|
4393
|
+
result.input = input;
|
|
4394
|
+
const groups = this.getNamedGroups(match);
|
|
4395
|
+
if (Object.keys(groups).length > 0) {
|
|
4396
|
+
result.groups = groups;
|
|
4415
4397
|
}
|
|
4416
|
-
|
|
4398
|
+
return result;
|
|
4417
4399
|
}
|
|
4418
|
-
|
|
4419
|
-
|
|
4420
|
-
|
|
4421
|
-
|
|
4422
|
-
|
|
4423
|
-
|
|
4424
|
-
|
|
4425
|
-
|
|
4426
|
-
|
|
4427
|
-
|
|
4428
|
-
|
|
4429
|
-
|
|
4430
|
-
|
|
4431
|
-
|
|
4432
|
-
|
|
4433
|
-
|
|
4434
|
-
|
|
4435
|
-
|
|
4436
|
-
|
|
4437
|
-
|
|
4438
|
-
|
|
4439
|
-
|
|
4400
|
+
}
|
|
4401
|
+
match(input) {
|
|
4402
|
+
return this[Symbol.match](input);
|
|
4403
|
+
}
|
|
4404
|
+
/**
|
|
4405
|
+
* Outputs the replacement for the matched part of the string
|
|
4406
|
+
* @param input
|
|
4407
|
+
* @param match
|
|
4408
|
+
* @param replacer
|
|
4409
|
+
*/
|
|
4410
|
+
replaceMatch(input, match, replacer) {
|
|
4411
|
+
var _a, _b;
|
|
4412
|
+
if (typeof replacer === "string") {
|
|
4413
|
+
let result = "";
|
|
4414
|
+
for (let i = 0; i < replacer.length; i++) {
|
|
4415
|
+
if (replacer[i] === "$") {
|
|
4416
|
+
switch (replacer[i + 1]) {
|
|
4417
|
+
case "$":
|
|
4418
|
+
result += "$";
|
|
4419
|
+
i++;
|
|
4420
|
+
break;
|
|
4421
|
+
case "&":
|
|
4422
|
+
result += match.match;
|
|
4423
|
+
i++;
|
|
4424
|
+
break;
|
|
4425
|
+
case "`":
|
|
4426
|
+
result += input.substring(0, match.index);
|
|
4427
|
+
i++;
|
|
4428
|
+
break;
|
|
4429
|
+
case "'":
|
|
4430
|
+
result += input.substring(match.index + match.match.length);
|
|
4431
|
+
i++;
|
|
4432
|
+
break;
|
|
4433
|
+
case "<": {
|
|
4434
|
+
const endCaret = replacer.indexOf(">", i);
|
|
4435
|
+
if (endCaret < 0) {
|
|
4436
|
+
throw new Error("Invalid named group replacement");
|
|
4437
|
+
}
|
|
4438
|
+
const groupName = replacer.substring(i + 2, endCaret);
|
|
4439
|
+
if (groupName in this.namedGroups) {
|
|
4440
|
+
result += (_a = match.groups[this.namedGroups[groupName] - 1]) !== null && _a !== void 0 ? _a : "";
|
|
4441
|
+
}
|
|
4442
|
+
i = endCaret;
|
|
4443
|
+
break;
|
|
4440
4444
|
}
|
|
4441
|
-
|
|
4442
|
-
|
|
4443
|
-
|
|
4444
|
-
|
|
4445
|
-
|
|
4446
|
-
|
|
4447
|
-
|
|
4448
|
-
|
|
4449
|
-
|
|
4450
|
-
|
|
4451
|
-
|
|
4452
|
-
|
|
4453
|
-
|
|
4454
|
-
|
|
4455
|
-
|
|
4456
|
-
|
|
4457
|
-
|
|
4458
|
-
|
|
4459
|
-
return (
|
|
4460
|
-
/** @type {const} */
|
|
4461
|
-
[out, commentObj]
|
|
4462
|
-
);
|
|
4463
|
-
}
|
|
4464
|
-
return (
|
|
4465
|
-
/** @type {const} */
|
|
4466
|
-
[commentObj]
|
|
4467
|
-
);
|
|
4468
|
-
} else if (c === BS) {
|
|
4469
|
-
esc = true;
|
|
4470
|
-
} else if (c === DS) {
|
|
4471
|
-
var value = parseEnvVar();
|
|
4472
|
-
if (!ifs) {
|
|
4473
|
-
out += value;
|
|
4474
|
-
} else {
|
|
4475
|
-
for (var vi = 0; vi < value.length; vi += 1) {
|
|
4476
|
-
var vc = value.charAt(vi);
|
|
4477
|
-
if (ifs.indexOf(vc) < 0) {
|
|
4478
|
-
flushRun();
|
|
4479
|
-
out += vc;
|
|
4480
|
-
} else if (pendingNw === null) {
|
|
4481
|
-
pendingNw = vc === " " || vc === " " || vc === "\n" ? 0 : 1;
|
|
4482
|
-
} else if (vc !== " " && vc !== " " && vc !== "\n") {
|
|
4483
|
-
pendingNw += 1;
|
|
4445
|
+
default: {
|
|
4446
|
+
let groupNum;
|
|
4447
|
+
if ("123456789".includes(replacer[i + 1])) {
|
|
4448
|
+
if ("0123456789".includes(replacer[i + 2])) {
|
|
4449
|
+
groupNum = Number.parseInt(replacer.substring(i + 1, i + 3)) - 1;
|
|
4450
|
+
i += 2;
|
|
4451
|
+
} else {
|
|
4452
|
+
groupNum = Number.parseInt(replacer[i + 1]) - 1;
|
|
4453
|
+
i++;
|
|
4454
|
+
}
|
|
4455
|
+
} else {
|
|
4456
|
+
throw new Error("Invalid replacement string");
|
|
4457
|
+
}
|
|
4458
|
+
if (groupNum < match.groups.length) {
|
|
4459
|
+
result += (_b = match.groups[groupNum]) !== null && _b !== void 0 ? _b : "";
|
|
4460
|
+
} else {
|
|
4461
|
+
result += "$" + groupNum;
|
|
4462
|
+
}
|
|
4484
4463
|
}
|
|
4485
4464
|
}
|
|
4465
|
+
} else {
|
|
4466
|
+
result += replacer[i];
|
|
4467
|
+
}
|
|
4468
|
+
}
|
|
4469
|
+
return result;
|
|
4470
|
+
} else {
|
|
4471
|
+
return replacer(match.match, ...match.groups, match.index, input, this.getNamedGroups(match));
|
|
4472
|
+
}
|
|
4473
|
+
}
|
|
4474
|
+
[Symbol.replace](input, replacer) {
|
|
4475
|
+
if (typeof input !== "string") {
|
|
4476
|
+
input = input + "";
|
|
4477
|
+
}
|
|
4478
|
+
if (typeof replacer !== "function") {
|
|
4479
|
+
replacer = replacer + "";
|
|
4480
|
+
}
|
|
4481
|
+
if (this._global) {
|
|
4482
|
+
let result = "";
|
|
4483
|
+
let nextIndex = 0;
|
|
4484
|
+
let success;
|
|
4485
|
+
do {
|
|
4486
|
+
const match = this.wrapper.match(input, nextIndex, true);
|
|
4487
|
+
success = match.index === nextIndex || !this._sticky && match.index >= 0;
|
|
4488
|
+
if (success) {
|
|
4489
|
+
result += input.substring(nextIndex, match.index) + this.replaceMatch(input, match, replacer);
|
|
4490
|
+
nextIndex = match.index + match.match.length;
|
|
4486
4491
|
}
|
|
4492
|
+
} while (success);
|
|
4493
|
+
result += input.substring(nextIndex);
|
|
4494
|
+
this.lastIndex = 0;
|
|
4495
|
+
return result;
|
|
4496
|
+
} else {
|
|
4497
|
+
const startIndex = this.getMaybeStickyIndex();
|
|
4498
|
+
const match = this.wrapper.match(input, startIndex, true);
|
|
4499
|
+
this.maybeUpdateLastIndex(match, startIndex);
|
|
4500
|
+
if (this.isMatchSuccessful(match, startIndex)) {
|
|
4501
|
+
return input.substring(0, match.index) + this.replaceMatch(input, match, replacer) + input.substring(match.index + match.match.length);
|
|
4487
4502
|
} else {
|
|
4488
|
-
|
|
4503
|
+
return input;
|
|
4489
4504
|
}
|
|
4490
4505
|
}
|
|
4491
|
-
|
|
4492
|
-
|
|
4493
|
-
|
|
4494
|
-
|
|
4495
|
-
|
|
4506
|
+
}
|
|
4507
|
+
replace(input, replacer) {
|
|
4508
|
+
return this[Symbol.replace](input, replacer);
|
|
4509
|
+
}
|
|
4510
|
+
[Symbol.search](input) {
|
|
4511
|
+
if (typeof input !== "string") {
|
|
4512
|
+
input = input + "";
|
|
4496
4513
|
}
|
|
4497
|
-
|
|
4498
|
-
|
|
4499
|
-
|
|
4500
|
-
|
|
4501
|
-
|
|
4502
|
-
|
|
4514
|
+
const result = this.wrapper.match(input, 0, false).index;
|
|
4515
|
+
if (this._sticky && result !== 0) {
|
|
4516
|
+
return -1;
|
|
4517
|
+
} else {
|
|
4518
|
+
return result;
|
|
4519
|
+
}
|
|
4520
|
+
}
|
|
4521
|
+
search(input) {
|
|
4522
|
+
return this[Symbol.search](input);
|
|
4523
|
+
}
|
|
4524
|
+
[Symbol.split](input, limit) {
|
|
4525
|
+
if (typeof input !== "string") {
|
|
4526
|
+
input = input + "";
|
|
4527
|
+
}
|
|
4528
|
+
const output = [];
|
|
4529
|
+
let nextIndex = 0;
|
|
4530
|
+
limit = limit !== null && limit !== void 0 ? limit : Infinity;
|
|
4531
|
+
while (output.length < limit) {
|
|
4532
|
+
const nextMatch = this.wrapper.match(input, nextIndex, true);
|
|
4533
|
+
if (nextMatch.index >= 0) {
|
|
4534
|
+
if (nextMatch.match.length === 0) {
|
|
4535
|
+
output.push(input.substring(nextIndex, nextIndex + 1));
|
|
4536
|
+
nextIndex = nextIndex + 1;
|
|
4537
|
+
} else {
|
|
4538
|
+
output.push(input.substring(nextIndex, nextMatch.index));
|
|
4539
|
+
nextIndex = nextMatch.index + nextMatch.match.length;
|
|
4503
4540
|
}
|
|
4541
|
+
for (const group of nextMatch.groups) {
|
|
4542
|
+
if (output.length >= limit) {
|
|
4543
|
+
break;
|
|
4544
|
+
}
|
|
4545
|
+
output.push(group);
|
|
4546
|
+
}
|
|
4547
|
+
} else {
|
|
4548
|
+
output.push(input.substring(nextIndex));
|
|
4549
|
+
break;
|
|
4504
4550
|
}
|
|
4505
|
-
if (out !== "" || sawQuote && words.length === 0) {
|
|
4506
|
-
words[words.length] = out;
|
|
4507
|
-
}
|
|
4508
|
-
return words;
|
|
4509
4551
|
}
|
|
4510
|
-
return
|
|
4511
|
-
}
|
|
4512
|
-
|
|
4513
|
-
|
|
4514
|
-
return prev;
|
|
4515
|
-
}
|
|
4516
|
-
[].concat(arg).forEach(function(entry) {
|
|
4517
|
-
prev[prev.length] = entry;
|
|
4518
|
-
});
|
|
4519
|
-
return prev;
|
|
4520
|
-
},
|
|
4521
|
-
/** @type {ParseEntry[]} */
|
|
4522
|
-
[]
|
|
4523
|
-
);
|
|
4524
|
-
}
|
|
4525
|
-
module.exports = function parse(s, env, opts) {
|
|
4526
|
-
var mapped = parseInternal(s, env, opts);
|
|
4527
|
-
if (typeof env !== "function") {
|
|
4528
|
-
return mapped;
|
|
4552
|
+
return output;
|
|
4553
|
+
}
|
|
4554
|
+
split(input, limit) {
|
|
4555
|
+
return this[Symbol.split](input, limit);
|
|
4529
4556
|
}
|
|
4530
|
-
return mapped.reduce(
|
|
4531
|
-
function(acc, s2) {
|
|
4532
|
-
if (typeof s2 === "object") {
|
|
4533
|
-
acc[acc.length] = s2;
|
|
4534
|
-
return acc;
|
|
4535
|
-
}
|
|
4536
|
-
var xs = s2.split(RegExp("(" + TOKEN + ".*?" + TOKEN + ")", "g"));
|
|
4537
|
-
if (xs.length === 1) {
|
|
4538
|
-
acc[acc.length] = xs[0];
|
|
4539
|
-
return acc;
|
|
4540
|
-
}
|
|
4541
|
-
xs.filter(Boolean).forEach(function(x) {
|
|
4542
|
-
acc[acc.length] = startsWithToken.test(x) ? JSON.parse(x.split(TOKEN)[1]) : x;
|
|
4543
|
-
});
|
|
4544
|
-
return acc;
|
|
4545
|
-
},
|
|
4546
|
-
/** @type {ParseEntry[]} */
|
|
4547
|
-
[]
|
|
4548
|
-
);
|
|
4549
4557
|
};
|
|
4558
|
+
exports.RE2 = RE2;
|
|
4550
4559
|
}
|
|
4551
4560
|
});
|
|
4552
4561
|
|
|
4553
|
-
//
|
|
4554
|
-
|
|
4555
|
-
|
|
4556
|
-
|
|
4557
|
-
|
|
4558
|
-
|
|
4562
|
+
// src/hooks/runtime/sniff.ts
|
|
4563
|
+
import { homedir } from "node:os";
|
|
4564
|
+
import { isAbsolute, resolve as resolvePath } from "node:path";
|
|
4565
|
+
|
|
4566
|
+
// src/hooks/runtime/shell-writes.ts
|
|
4567
|
+
var import_shell_quote = __toESM(require_shell_quote(), 1);
|
|
4568
|
+
var SEGMENT_OPS = /* @__PURE__ */ new Set([";", "&&", "||", "|", "|&", "&", "(", ")"]);
|
|
4569
|
+
var SHELL_INTERPRETERS = /* @__PURE__ */ new Set(["bash", "sh", "zsh", "dash", "ksh"]);
|
|
4570
|
+
var TRANSPARENT_PREFIXES = /* @__PURE__ */ new Set(["sudo", "doas", "nohup", "command", "time", "nice", "env"]);
|
|
4571
|
+
var HEREDOC_OPEN = /<<-?\s*(['"]?)([A-Za-z_][A-Za-z0-9_]*)\1/;
|
|
4572
|
+
function isOp(tok, op) {
|
|
4573
|
+
return typeof tok === "object" && "op" in tok && (op === void 0 || tok.op === op);
|
|
4574
|
+
}
|
|
4575
|
+
function tokenText(tok) {
|
|
4576
|
+
if (typeof tok === "string") return tok;
|
|
4577
|
+
if (typeof tok === "object" && "pattern" in tok) return tok.pattern;
|
|
4578
|
+
return null;
|
|
4579
|
+
}
|
|
4580
|
+
function stripHeredocBodies(command) {
|
|
4581
|
+
const lines = command.split("\n");
|
|
4582
|
+
const out = [];
|
|
4583
|
+
let i = 0;
|
|
4584
|
+
while (i < lines.length) {
|
|
4585
|
+
const line = lines[i];
|
|
4586
|
+
out.push(line);
|
|
4587
|
+
const m = HEREDOC_OPEN.exec(line);
|
|
4588
|
+
i++;
|
|
4589
|
+
if (!m) continue;
|
|
4590
|
+
const delimiter = m[2];
|
|
4591
|
+
while (i < lines.length) {
|
|
4592
|
+
const body = lines[i];
|
|
4593
|
+
i++;
|
|
4594
|
+
if (body.trim() === delimiter) break;
|
|
4595
|
+
}
|
|
4559
4596
|
}
|
|
4560
|
-
|
|
4597
|
+
return out.join("\n");
|
|
4598
|
+
}
|
|
4599
|
+
function isNoiseTarget(target) {
|
|
4600
|
+
if (target.length === 0) return true;
|
|
4601
|
+
if (target === "-") return true;
|
|
4602
|
+
if (target.startsWith("/dev/")) return true;
|
|
4603
|
+
if (/^&?\d+$/.test(target)) return true;
|
|
4604
|
+
return false;
|
|
4605
|
+
}
|
|
4606
|
+
function targetsFromArgv(argv, depth) {
|
|
4607
|
+
let i = 0;
|
|
4608
|
+
while (i < argv.length) {
|
|
4609
|
+
const tok = argv[i];
|
|
4610
|
+
if (/^[A-Za-z_][A-Za-z0-9_]*=/.test(tok)) {
|
|
4611
|
+
i++;
|
|
4612
|
+
continue;
|
|
4613
|
+
}
|
|
4614
|
+
if (TRANSPARENT_PREFIXES.has(tok)) {
|
|
4615
|
+
i++;
|
|
4616
|
+
if (tok === "env") {
|
|
4617
|
+
while (i < argv.length && (argv[i].startsWith("-") || /^[A-Za-z_][A-Za-z0-9_]*=/.test(argv[i]))) {
|
|
4618
|
+
if (argv[i] === "-u" || argv[i] === "--unset") i++;
|
|
4619
|
+
i++;
|
|
4620
|
+
}
|
|
4621
|
+
}
|
|
4622
|
+
continue;
|
|
4623
|
+
}
|
|
4624
|
+
break;
|
|
4625
|
+
}
|
|
4626
|
+
const cmd = argv[i] ?? "";
|
|
4627
|
+
const args = argv.slice(i + 1);
|
|
4628
|
+
const base = cmd.split("/").pop() ?? cmd;
|
|
4629
|
+
if (SHELL_INTERPRETERS.has(base)) {
|
|
4630
|
+
const c = args.indexOf("-c");
|
|
4631
|
+
if (c >= 0 && typeof args[c + 1] === "string" && depth < 1) {
|
|
4632
|
+
return extractShellWriteTargetsAt(args[c + 1], depth + 1);
|
|
4633
|
+
}
|
|
4634
|
+
return [];
|
|
4635
|
+
}
|
|
4636
|
+
if (base === "tee") {
|
|
4637
|
+
return args.filter((a) => !a.startsWith("-") && !isNoiseTarget(a));
|
|
4638
|
+
}
|
|
4639
|
+
if (base === "sed" || base === "gsed") {
|
|
4640
|
+
return sedTargets(args);
|
|
4641
|
+
}
|
|
4642
|
+
if (base === "perl") {
|
|
4643
|
+
return perlTargets(args);
|
|
4644
|
+
}
|
|
4645
|
+
if (base === "cp" || base === "mv" || base === "install") {
|
|
4646
|
+
const positional = args.filter((a) => !a.startsWith("-") || a === "-");
|
|
4647
|
+
if (positional.length >= 2) {
|
|
4648
|
+
const tFlag = args.findIndex((a) => a === "-t" || a === "--target-directory");
|
|
4649
|
+
if (tFlag >= 0 && args[tFlag + 1]) return [args[tFlag + 1]];
|
|
4650
|
+
return [positional[positional.length - 1]];
|
|
4651
|
+
}
|
|
4652
|
+
return [];
|
|
4653
|
+
}
|
|
4654
|
+
if (base === "dd") {
|
|
4655
|
+
return args.filter((a) => a.startsWith("of=")).map((a) => a.slice(3)).filter((a) => !isNoiseTarget(a));
|
|
4656
|
+
}
|
|
4657
|
+
return [];
|
|
4658
|
+
}
|
|
4659
|
+
function sedTargets(args) {
|
|
4660
|
+
let inPlace = false;
|
|
4661
|
+
let scriptGiven = false;
|
|
4662
|
+
const files = [];
|
|
4663
|
+
let i = 0;
|
|
4664
|
+
while (i < args.length) {
|
|
4665
|
+
const a = args[i];
|
|
4666
|
+
if (a === "--") {
|
|
4667
|
+
files.push(...args.slice(i + 1).filter((f) => f.length > 0));
|
|
4668
|
+
break;
|
|
4669
|
+
}
|
|
4670
|
+
if (a === "-i" || a === "--in-place") {
|
|
4671
|
+
inPlace = true;
|
|
4672
|
+
const next = args[i + 1];
|
|
4673
|
+
if (typeof next === "string" && (next === "" || /^\.[A-Za-z0-9_-]+$/.test(next))) i++;
|
|
4674
|
+
i++;
|
|
4675
|
+
continue;
|
|
4676
|
+
}
|
|
4677
|
+
if (/^-i/.test(a) || a.startsWith("--in-place=")) {
|
|
4678
|
+
inPlace = true;
|
|
4679
|
+
i++;
|
|
4680
|
+
continue;
|
|
4681
|
+
}
|
|
4682
|
+
if (a === "-e" || a === "--expression" || a === "-f" || a === "--file") {
|
|
4683
|
+
scriptGiven = true;
|
|
4684
|
+
i += 2;
|
|
4685
|
+
continue;
|
|
4686
|
+
}
|
|
4687
|
+
if (a.startsWith("--expression=") || a.startsWith("--file=")) {
|
|
4688
|
+
scriptGiven = true;
|
|
4689
|
+
i++;
|
|
4690
|
+
continue;
|
|
4691
|
+
}
|
|
4692
|
+
if (a.startsWith("-") && a.length > 1) {
|
|
4693
|
+
if (/^-[A-Za-z]*i/.test(a)) inPlace = true;
|
|
4694
|
+
i++;
|
|
4695
|
+
continue;
|
|
4696
|
+
}
|
|
4697
|
+
if (!scriptGiven) {
|
|
4698
|
+
scriptGiven = true;
|
|
4699
|
+
i++;
|
|
4700
|
+
continue;
|
|
4701
|
+
}
|
|
4702
|
+
if (a.length > 0) files.push(a);
|
|
4703
|
+
i++;
|
|
4704
|
+
}
|
|
4705
|
+
return inPlace ? files : [];
|
|
4706
|
+
}
|
|
4707
|
+
function perlTargets(args) {
|
|
4708
|
+
let inPlace = false;
|
|
4709
|
+
const files = [];
|
|
4710
|
+
let i = 0;
|
|
4711
|
+
while (i < args.length) {
|
|
4712
|
+
const a = args[i];
|
|
4713
|
+
if (a === "-e" || a === "-E") {
|
|
4714
|
+
i += 2;
|
|
4715
|
+
continue;
|
|
4716
|
+
}
|
|
4717
|
+
if (a.startsWith("-")) {
|
|
4718
|
+
if (/^-[A-Za-z0-9]*i/.test(a)) inPlace = true;
|
|
4719
|
+
if (/e$/.test(a) && !/^-i/.test(a)) i++;
|
|
4720
|
+
i++;
|
|
4721
|
+
continue;
|
|
4722
|
+
}
|
|
4723
|
+
files.push(a);
|
|
4724
|
+
i++;
|
|
4725
|
+
}
|
|
4726
|
+
return inPlace ? files : [];
|
|
4727
|
+
}
|
|
4728
|
+
function extractShellWriteTargetsAt(command, depth) {
|
|
4729
|
+
let tokens;
|
|
4730
|
+
try {
|
|
4731
|
+
tokens = (0, import_shell_quote.parse)(stripHeredocBodies(command), (key) => `$${key}`);
|
|
4732
|
+
} catch {
|
|
4733
|
+
return [];
|
|
4734
|
+
}
|
|
4735
|
+
const targets = [];
|
|
4736
|
+
let argv = [];
|
|
4737
|
+
const flush = () => {
|
|
4738
|
+
if (argv.length > 0) targets.push(...targetsFromArgv(argv, depth));
|
|
4739
|
+
argv = [];
|
|
4740
|
+
};
|
|
4741
|
+
for (let i = 0; i < tokens.length; i++) {
|
|
4742
|
+
const tok = tokens[i];
|
|
4743
|
+
if (isOp(tok)) {
|
|
4744
|
+
if (tok.op === "&" && isOp(tokens[i + 1], ">")) continue;
|
|
4745
|
+
if (tok.op === ">" || tok.op === ">>") {
|
|
4746
|
+
const next = tokens[i + 1];
|
|
4747
|
+
const text2 = next === void 0 ? null : tokenText(next);
|
|
4748
|
+
if (text2 !== null) {
|
|
4749
|
+
if (!isNoiseTarget(text2)) targets.push(text2);
|
|
4750
|
+
i++;
|
|
4751
|
+
}
|
|
4752
|
+
if (/^\d+$/.test(argv[argv.length - 1] ?? "")) argv.pop();
|
|
4753
|
+
continue;
|
|
4754
|
+
}
|
|
4755
|
+
if (tok.op === ">&") {
|
|
4756
|
+
i++;
|
|
4757
|
+
if (/^\d+$/.test(argv[argv.length - 1] ?? "")) argv.pop();
|
|
4758
|
+
continue;
|
|
4759
|
+
}
|
|
4760
|
+
if (tok.op === "<") {
|
|
4761
|
+
const next = tokens[i + 1];
|
|
4762
|
+
if (!isOp(next, "<") && !isOp(tokens[i - 1], "<")) i++;
|
|
4763
|
+
else if (isOp(tokens[i - 1], "<")) i++;
|
|
4764
|
+
continue;
|
|
4765
|
+
}
|
|
4766
|
+
if (SEGMENT_OPS.has(tok.op)) {
|
|
4767
|
+
flush();
|
|
4768
|
+
continue;
|
|
4769
|
+
}
|
|
4770
|
+
continue;
|
|
4771
|
+
}
|
|
4772
|
+
const text = tokenText(tok);
|
|
4773
|
+
if (text !== null) argv.push(text);
|
|
4774
|
+
}
|
|
4775
|
+
flush();
|
|
4776
|
+
return Array.from(new Set(targets));
|
|
4777
|
+
}
|
|
4778
|
+
function extractShellWriteTargets(command) {
|
|
4779
|
+
if (typeof command !== "string" || command.trim().length === 0) return [];
|
|
4780
|
+
return extractShellWriteTargetsAt(command, 0);
|
|
4781
|
+
}
|
|
4561
4782
|
|
|
4562
4783
|
// src/hooks/runtime/sniff.ts
|
|
4784
|
+
function resolveWriteTarget(cwd, target) {
|
|
4785
|
+
if (target.includes("$")) return target;
|
|
4786
|
+
if (target === "~" || target.startsWith("~/")) {
|
|
4787
|
+
return resolvePath(homedir(), target.slice(2));
|
|
4788
|
+
}
|
|
4789
|
+
return isAbsolute(target) ? resolvePath(target) : resolvePath(cwd, target);
|
|
4790
|
+
}
|
|
4563
4791
|
function filePathFromPatch(patch) {
|
|
4564
4792
|
const lines = patch.split("\n");
|
|
4565
4793
|
for (const line of lines) {
|
|
@@ -4591,7 +4819,14 @@ function sniff(input) {
|
|
|
4591
4819
|
} else if (action === "pre_read_code" || action === "post_read_code") {
|
|
4592
4820
|
toolName = "Read";
|
|
4593
4821
|
}
|
|
4594
|
-
return {
|
|
4822
|
+
return {
|
|
4823
|
+
client: "windsurf",
|
|
4824
|
+
toolName,
|
|
4825
|
+
filePath,
|
|
4826
|
+
filePaths: filePath ? [filePath] : [],
|
|
4827
|
+
newContent,
|
|
4828
|
+
raw: input
|
|
4829
|
+
};
|
|
4595
4830
|
}
|
|
4596
4831
|
if ("hookEventName" in input) {
|
|
4597
4832
|
return extractToolInputShape(input, "vscode");
|
|
@@ -4603,7 +4838,7 @@ function sniff(input) {
|
|
|
4603
4838
|
client = "cursor";
|
|
4604
4839
|
} else {
|
|
4605
4840
|
const toolName = typeof input.tool_name === "string" ? input.tool_name : "";
|
|
4606
|
-
client = toolName === "apply_patch" ? "codex" : "claude-code";
|
|
4841
|
+
client = toolName === "apply_patch" || "turn_id" in input ? "codex" : "claude-code";
|
|
4607
4842
|
}
|
|
4608
4843
|
return extractToolInputShape(input, client);
|
|
4609
4844
|
}
|
|
@@ -4611,6 +4846,7 @@ function sniff(input) {
|
|
|
4611
4846
|
client: "unknown",
|
|
4612
4847
|
toolName: "",
|
|
4613
4848
|
filePath: "",
|
|
4849
|
+
filePaths: [],
|
|
4614
4850
|
newContent: "",
|
|
4615
4851
|
raw: input
|
|
4616
4852
|
};
|
|
@@ -4619,8 +4855,19 @@ function extractToolInputShape(input, client) {
|
|
|
4619
4855
|
const toolName = typeof input.tool_name === "string" ? input.tool_name : "";
|
|
4620
4856
|
const toolInput = input.tool_input ?? {};
|
|
4621
4857
|
let filePath = typeof toolInput.file_path === "string" ? toolInput.file_path : "";
|
|
4858
|
+
let filePaths = [];
|
|
4622
4859
|
let newContent = "";
|
|
4623
4860
|
switch (toolName) {
|
|
4861
|
+
case "Bash": {
|
|
4862
|
+
const command = typeof toolInput.command === "string" ? toolInput.command : "";
|
|
4863
|
+
newContent = command;
|
|
4864
|
+
const cwd = typeof input.cwd === "string" && input.cwd.length > 0 ? input.cwd : process.cwd();
|
|
4865
|
+
filePaths = extractShellWriteTargets(command).map(
|
|
4866
|
+
(t) => resolveWriteTarget(cwd, t)
|
|
4867
|
+
);
|
|
4868
|
+
filePath = filePaths[0] ?? "";
|
|
4869
|
+
break;
|
|
4870
|
+
}
|
|
4624
4871
|
case "Write":
|
|
4625
4872
|
newContent = typeof toolInput.content === "string" ? toolInput.content : "";
|
|
4626
4873
|
break;
|
|
@@ -4633,13 +4880,18 @@ function extractToolInputShape(input, client) {
|
|
|
4633
4880
|
);
|
|
4634
4881
|
break;
|
|
4635
4882
|
case "apply_patch": {
|
|
4636
|
-
const patch = typeof toolInput.patch === "string" ? toolInput.patch : "";
|
|
4883
|
+
const patch = typeof toolInput.patch === "string" ? toolInput.patch : typeof toolInput.command === "string" ? toolInput.command : "";
|
|
4637
4884
|
newContent = patch;
|
|
4638
4885
|
if (!filePath) filePath = filePathFromPatch(patch);
|
|
4639
4886
|
break;
|
|
4640
4887
|
}
|
|
4641
4888
|
}
|
|
4642
|
-
|
|
4889
|
+
if (typeof input.cwd === "string" && input.cwd.length > 0) {
|
|
4890
|
+
if (filePath) filePath = resolveWriteTarget(input.cwd, filePath);
|
|
4891
|
+
filePaths = filePaths.map((f) => resolveWriteTarget(input.cwd, f));
|
|
4892
|
+
}
|
|
4893
|
+
if (filePaths.length === 0 && filePath) filePaths = [filePath];
|
|
4894
|
+
return { client, toolName, filePath, filePaths, newContent, raw: input };
|
|
4643
4895
|
}
|
|
4644
4896
|
|
|
4645
4897
|
// src/hooks/runtime/resolve.ts
|
|
@@ -4648,7 +4900,7 @@ import { existsSync as existsSync6, readFileSync as readFileSync6 } from "node:f
|
|
|
4648
4900
|
|
|
4649
4901
|
// src/auth/auth-store.ts
|
|
4650
4902
|
import { execFileSync } from "node:child_process";
|
|
4651
|
-
import { homedir } from "node:os";
|
|
4903
|
+
import { homedir as homedir2 } from "node:os";
|
|
4652
4904
|
import { join } from "node:path";
|
|
4653
4905
|
import {
|
|
4654
4906
|
existsSync,
|
|
@@ -4764,10 +5016,10 @@ function readMacOSKeychain(mcpName) {
|
|
|
4764
5016
|
}
|
|
4765
5017
|
}
|
|
4766
5018
|
function fileFallbackPath() {
|
|
4767
|
-
return join(
|
|
5019
|
+
return join(homedir2(), ".cybedefend", "auth.json");
|
|
4768
5020
|
}
|
|
4769
5021
|
function storeFileFallback(blob) {
|
|
4770
|
-
const dir = join(
|
|
5022
|
+
const dir = join(homedir2(), ".cybedefend");
|
|
4771
5023
|
mkdirSync(dir, { recursive: true });
|
|
4772
5024
|
const p = fileFallbackPath();
|
|
4773
5025
|
writeFileSync(p, blob, { mode: 384 });
|
|
@@ -4995,7 +5247,7 @@ import { dirname as dirname2 } from "node:path";
|
|
|
4995
5247
|
// src/utils.ts
|
|
4996
5248
|
import { existsSync as existsSync2, mkdirSync as mkdirSync2, readFileSync as readFileSync2, writeFileSync as writeFileSync2 } from "node:fs";
|
|
4997
5249
|
import { dirname, join as join2 } from "node:path";
|
|
4998
|
-
import { homedir as
|
|
5250
|
+
import { homedir as homedir3, platform } from "node:os";
|
|
4999
5251
|
|
|
5000
5252
|
// node_modules/.pnpm/kleur@4.1.5/node_modules/kleur/index.mjs
|
|
5001
5253
|
var FORCE_COLOR;
|
|
@@ -5098,7 +5350,7 @@ function init(open, close) {
|
|
|
5098
5350
|
|
|
5099
5351
|
// src/utils.ts
|
|
5100
5352
|
function home(...parts) {
|
|
5101
|
-
return join2(
|
|
5353
|
+
return join2(homedir3(), ...parts);
|
|
5102
5354
|
}
|
|
5103
5355
|
function ensureDirFor(filePath) {
|
|
5104
5356
|
const dir = dirname(filePath);
|
|
@@ -5173,10 +5425,10 @@ function writeCachedRepoLink(key, entry, deps = {}) {
|
|
|
5173
5425
|
|
|
5174
5426
|
// src/hooks/runtime/config.ts
|
|
5175
5427
|
import { existsSync as existsSync4, readFileSync as readFileSync4 } from "node:fs";
|
|
5176
|
-
import { homedir as
|
|
5428
|
+
import { homedir as homedir4 } from "node:os";
|
|
5177
5429
|
import { join as join3 } from "node:path";
|
|
5178
5430
|
function runtimeConfigPath() {
|
|
5179
|
-
return join3(
|
|
5431
|
+
return join3(homedir4(), ".cybedefend", "runtime-config.json");
|
|
5180
5432
|
}
|
|
5181
5433
|
function loadRuntimeConfig(path) {
|
|
5182
5434
|
const p = path ?? runtimeConfigPath();
|
|
@@ -5205,7 +5457,7 @@ async function readStdinJson() {
|
|
|
5205
5457
|
|
|
5206
5458
|
// src/hooks/runtime/trusted-api-base.ts
|
|
5207
5459
|
import { existsSync as existsSync5, readFileSync as readFileSync5 } from "node:fs";
|
|
5208
|
-
import { homedir as
|
|
5460
|
+
import { homedir as homedir5 } from "node:os";
|
|
5209
5461
|
import { join as join4 } from "node:path";
|
|
5210
5462
|
|
|
5211
5463
|
// src/config.ts
|
|
@@ -5234,7 +5486,7 @@ var REGIONS = [
|
|
|
5234
5486
|
|
|
5235
5487
|
// src/hooks/runtime/trusted-api-base.ts
|
|
5236
5488
|
function userRegionsPath() {
|
|
5237
|
-
return join4(
|
|
5489
|
+
return join4(homedir5(), ".cybedefend", "regions.json");
|
|
5238
5490
|
}
|
|
5239
5491
|
function normalizeOrigin(candidate) {
|
|
5240
5492
|
if (typeof candidate !== "string") return null;
|
|
@@ -5584,6 +5836,10 @@ async function fetchProposalsCount(opts) {
|
|
|
5584
5836
|
}
|
|
5585
5837
|
|
|
5586
5838
|
// src/hooks/runtime/emit.ts
|
|
5839
|
+
var ENVELOPE_CLIENTS = {
|
|
5840
|
+
SessionStart: /* @__PURE__ */ new Set(["codex"]),
|
|
5841
|
+
PreToolUse: /* @__PURE__ */ new Set(["claude-code", "codex"])
|
|
5842
|
+
};
|
|
5587
5843
|
function emit(body, client) {
|
|
5588
5844
|
if (!body) return;
|
|
5589
5845
|
if (client === "cursor") {
|
|
@@ -5597,16 +5853,16 @@ function emit(body, client) {
|
|
|
5597
5853
|
process.stdout.write(body);
|
|
5598
5854
|
if (!body.endsWith("\n")) process.stdout.write("\n");
|
|
5599
5855
|
}
|
|
5600
|
-
function emitContext(body, client) {
|
|
5856
|
+
function emitContext(body, client, hookEventName) {
|
|
5601
5857
|
if (!body) return;
|
|
5602
|
-
if (client
|
|
5858
|
+
if (ENVELOPE_CLIENTS[hookEventName].has(client)) {
|
|
5603
5859
|
const payload = JSON.stringify({
|
|
5604
5860
|
hookSpecificOutput: {
|
|
5605
|
-
hookEventName
|
|
5861
|
+
hookEventName,
|
|
5606
5862
|
additionalContext: body
|
|
5607
5863
|
}
|
|
5608
5864
|
});
|
|
5609
|
-
process.stdout.write(payload);
|
|
5865
|
+
process.stdout.write(payload + "\n");
|
|
5610
5866
|
return;
|
|
5611
5867
|
}
|
|
5612
5868
|
emit(body, client);
|
|
@@ -5626,11 +5882,15 @@ function emitStop(body, client, reason) {
|
|
|
5626
5882
|
}
|
|
5627
5883
|
|
|
5628
5884
|
// src/hooks/runtime/fetch-rules.ts
|
|
5885
|
+
function emitPreToolUseContext(body, client) {
|
|
5886
|
+
emitContext(body, client, "PreToolUse");
|
|
5887
|
+
}
|
|
5629
5888
|
var INTERESTED_TOOLS = /* @__PURE__ */ new Set([
|
|
5630
5889
|
"Edit",
|
|
5631
5890
|
"Write",
|
|
5632
5891
|
"MultiEdit",
|
|
5633
|
-
"apply_patch"
|
|
5892
|
+
"apply_patch",
|
|
5893
|
+
"Bash"
|
|
5634
5894
|
]);
|
|
5635
5895
|
async function fetchRulesHook(deps = {}) {
|
|
5636
5896
|
const readStdin = deps.readStdin ?? readStdinJson;
|
|
@@ -5639,7 +5899,7 @@ async function fetchRulesHook(deps = {}) {
|
|
|
5639
5899
|
const resolveTok = deps.resolveTokenFn ?? resolveToken;
|
|
5640
5900
|
const fetchRules = deps.fetchRulesFn ?? fetchBusinessRules;
|
|
5641
5901
|
const fetchSecRules = deps.fetchSecurityRulesFn ?? fetchSecurityRules;
|
|
5642
|
-
const emitFn = deps.emitFn ??
|
|
5902
|
+
const emitFn = deps.emitFn ?? emitPreToolUseContext;
|
|
5643
5903
|
const stdin = await readStdin();
|
|
5644
5904
|
const event = sniff(stdin);
|
|
5645
5905
|
if (!INTERESTED_TOOLS.has(event.toolName)) return;
|
|
@@ -5652,11 +5912,13 @@ async function fetchRulesHook(deps = {}) {
|
|
|
5652
5912
|
const token = resolveTok(config.region.mcpName);
|
|
5653
5913
|
if (!token) return;
|
|
5654
5914
|
const intent = buildIntent(event);
|
|
5915
|
+
const files = event.filePaths.length > 0 ? event.filePaths : [event.filePath];
|
|
5916
|
+
const fileLabel = files.join(", ");
|
|
5655
5917
|
const fetchOpts = {
|
|
5656
5918
|
apiBase,
|
|
5657
5919
|
projectId,
|
|
5658
5920
|
token,
|
|
5659
|
-
files
|
|
5921
|
+
files,
|
|
5660
5922
|
intent,
|
|
5661
5923
|
topK: 5
|
|
5662
5924
|
};
|
|
@@ -5664,24 +5926,25 @@ async function fetchRulesHook(deps = {}) {
|
|
|
5664
5926
|
fetchRules(fetchOpts),
|
|
5665
5927
|
fetchSecRules(fetchOpts)
|
|
5666
5928
|
]);
|
|
5929
|
+
const blocks = [];
|
|
5667
5930
|
if (businessResult) {
|
|
5668
5931
|
const body = composeBody(
|
|
5669
5932
|
businessResult.markdown,
|
|
5670
5933
|
businessResult.total,
|
|
5671
|
-
|
|
5934
|
+
fileLabel
|
|
5672
5935
|
);
|
|
5673
|
-
if (body)
|
|
5936
|
+
if (body) blocks.push(body);
|
|
5674
5937
|
}
|
|
5675
5938
|
if (securityResult && securityResult.total > 0 && securityResult.markdown && securityResult.markdown.length > 0) {
|
|
5676
|
-
|
|
5939
|
+
blocks.push(
|
|
5677
5940
|
composeSecurityBody(
|
|
5678
5941
|
securityResult.markdown,
|
|
5679
5942
|
securityResult.total,
|
|
5680
|
-
|
|
5681
|
-
)
|
|
5682
|
-
event.client
|
|
5943
|
+
fileLabel
|
|
5944
|
+
)
|
|
5683
5945
|
);
|
|
5684
5946
|
}
|
|
5947
|
+
if (blocks.length > 0) emitFn(blocks.join("\n"), event.client);
|
|
5685
5948
|
}
|
|
5686
5949
|
function buildIntent(event) {
|
|
5687
5950
|
const limit = parseInt(process.env.CYBEDEFEND_INTENT_BYTES ?? "800", 10);
|
|
@@ -5693,7 +5956,7 @@ function visibleCalloutTemplate(kind, total, filePath) {
|
|
|
5693
5956
|
return [
|
|
5694
5957
|
"---",
|
|
5695
5958
|
"",
|
|
5696
|
-
`**\u{1F6E1}\uFE0F REQUIRED USER-VISIBLE MARKER** \u2014 you MUST include this exact block as the FIRST paragraph of your next assistant reply, BEFORE the
|
|
5959
|
+
`**\u{1F6E1}\uFE0F REQUIRED USER-VISIBLE MARKER** \u2014 you MUST include this exact block as the FIRST paragraph of your next assistant reply, BEFORE the tool call that writes the file. Do not paraphrase, do not skip \u2014 without it, the user cannot see CybeDefend is influencing the change.`,
|
|
5697
5960
|
"",
|
|
5698
5961
|
`> \u{1F6E1}\uFE0F **CybeDefend ${kind} Rules** \u2014 ${total} rule${total === 1 ? "" : "s"} for \`${filePath}\``,
|
|
5699
5962
|
`> - **<rule-title>** [<severity> \xB7 <category>] \u2014 applies because <one-sentence reason>`,
|
|
@@ -5740,7 +6003,7 @@ function composeSecurityBody(markdown, total, filePath) {
|
|
|
5740
6003
|
// src/hooks/runtime/self-update-check.ts
|
|
5741
6004
|
import { spawn } from "node:child_process";
|
|
5742
6005
|
import { existsSync as existsSync8, readFileSync as readFileSync7, rmSync, writeFileSync as writeFileSync4 } from "node:fs";
|
|
5743
|
-
import { homedir as
|
|
6006
|
+
import { homedir as homedir6 } from "node:os";
|
|
5744
6007
|
import { join as join5 } from "node:path";
|
|
5745
6008
|
|
|
5746
6009
|
// src/hooks/runtime/semver.ts
|
|
@@ -5818,7 +6081,7 @@ function isValidRegistryVersion(value) {
|
|
|
5818
6081
|
}
|
|
5819
6082
|
async function selfUpdateCheck(deps) {
|
|
5820
6083
|
const now = deps.now ?? (() => Date.now());
|
|
5821
|
-
const dir = deps.cybeDir ?? join5(process.env.CYBEDEFEND_HOME ??
|
|
6084
|
+
const dir = deps.cybeDir ?? join5(process.env.CYBEDEFEND_HOME ?? homedir6(), ".cybedefend");
|
|
5822
6085
|
const throttlePath = join5(dir, "update-check.json");
|
|
5823
6086
|
const logPath = join5(dir, "last-update.log");
|
|
5824
6087
|
const installMode = deps.installMode ?? (deps.runnerSource ? detectInstallMode(deps.runnerSource) : detectInstallMode(resolveScriptPath()));
|
|
@@ -5967,10 +6230,13 @@ function readPackageMeta(opts = {}) {
|
|
|
5967
6230
|
}
|
|
5968
6231
|
}
|
|
5969
6232
|
var pkg = readPackageMeta({
|
|
5970
|
-
bakedVersion: true ? "1.4.
|
|
6233
|
+
bakedVersion: true ? "1.4.3" : void 0
|
|
5971
6234
|
});
|
|
5972
6235
|
|
|
5973
6236
|
// src/hooks/runtime/session-start.ts
|
|
6237
|
+
function emitSessionStartContext(body, client) {
|
|
6238
|
+
emitContext(body, client, "SessionStart");
|
|
6239
|
+
}
|
|
5974
6240
|
async function sessionStartHook(deps = {}) {
|
|
5975
6241
|
const readStdin = deps.readStdin ?? readStdinJson;
|
|
5976
6242
|
const loadConfig = deps.loadConfig ?? loadRuntimeConfig;
|
|
@@ -5978,7 +6244,7 @@ async function sessionStartHook(deps = {}) {
|
|
|
5978
6244
|
const resolveTok = deps.resolveTokenFn ?? resolveToken;
|
|
5979
6245
|
const fetchProposals = deps.fetchProposalsFn ?? fetchProposalsCount;
|
|
5980
6246
|
const selfUpdateCheckFn = deps.selfUpdateCheckFn ?? selfUpdateCheck;
|
|
5981
|
-
const emitFn = deps.emitFn ??
|
|
6247
|
+
const emitFn = deps.emitFn ?? emitSessionStartContext;
|
|
5982
6248
|
const stdin = await readStdin();
|
|
5983
6249
|
const event = sniff(stdin);
|
|
5984
6250
|
const config = loadConfig();
|
|
@@ -6408,11 +6674,11 @@ async function preCompactHook(deps = {}) {
|
|
|
6408
6674
|
|
|
6409
6675
|
// src/hooks/runtime/user-prompt-submit.ts
|
|
6410
6676
|
import { existsSync as existsSync10, mkdirSync as mkdirSync4, readFileSync as readFileSync10, writeFileSync as writeFileSync5 } from "node:fs";
|
|
6411
|
-
import { homedir as
|
|
6677
|
+
import { homedir as homedir7 } from "node:os";
|
|
6412
6678
|
import { join as join7 } from "node:path";
|
|
6413
6679
|
var SESSIONS_CAP = 100;
|
|
6414
6680
|
function defaultSessionsFile() {
|
|
6415
|
-
const dir = process.env.CYBEDEFEND_BASELINE_DIR ?? join7(
|
|
6681
|
+
const dir = process.env.CYBEDEFEND_BASELINE_DIR ?? join7(homedir7(), ".cybedefend");
|
|
6416
6682
|
return join7(dir, "user-prompt-seen-sessions.json");
|
|
6417
6683
|
}
|
|
6418
6684
|
function defaultSessionTracker(file = defaultSessionsFile()) {
|
|
@@ -6719,7 +6985,7 @@ function bucketRules(rules) {
|
|
|
6719
6985
|
}
|
|
6720
6986
|
|
|
6721
6987
|
// src/guards-evaluator/preprocess.ts
|
|
6722
|
-
var
|
|
6988
|
+
var import_shell_quote2 = __toESM(require_shell_quote(), 1);
|
|
6723
6989
|
var PLACEHOLDER = "<DATA>";
|
|
6724
6990
|
var DATA_BEARING_CONTEXTS = {
|
|
6725
6991
|
git: /* @__PURE__ */ new Set(["commit", "tag", "notes", "stash", "merge", "cherry-pick", "revert"]),
|
|
@@ -6738,7 +7004,7 @@ var DATA_FLAGS_VALUE = /* @__PURE__ */ new Set([
|
|
|
6738
7004
|
]);
|
|
6739
7005
|
var DATA_FLAGS_EQUAL = ["--message=", "--file=", "--body=", "--body-file="];
|
|
6740
7006
|
var SHELL_OPS = /* @__PURE__ */ new Set([";", "&&", "||", "|", "|&", "&", ">", ">>", "<", "(", ")"]);
|
|
6741
|
-
var
|
|
7007
|
+
var HEREDOC_OPEN2 = /^<<-?\s*(['"]?)([A-Za-z_][A-Za-z0-9_]*)\1/;
|
|
6742
7008
|
function isExecutableValue(tok) {
|
|
6743
7009
|
return tok.startsWith("$(") || tok.startsWith("<(") || tok.startsWith(">(") || tok.includes("`");
|
|
6744
7010
|
}
|
|
@@ -6751,7 +7017,7 @@ function stripDataArgs(command) {
|
|
|
6751
7017
|
tokens = command.slice();
|
|
6752
7018
|
} else {
|
|
6753
7019
|
try {
|
|
6754
|
-
tokens = (0,
|
|
7020
|
+
tokens = (0, import_shell_quote2.parse)(command, (key) => "$" + key);
|
|
6755
7021
|
} catch {
|
|
6756
7022
|
return command;
|
|
6757
7023
|
}
|
|
@@ -6792,7 +7058,7 @@ function stripDataArgs(command) {
|
|
|
6792
7058
|
const contextSubcommands = segmentTopCmd ? DATA_BEARING_CONTEXTS[segmentTopCmd] : void 0;
|
|
6793
7059
|
const inDataBearingContext = contextSubcommands === null || contextSubcommands !== void 0 && segmentSubCmd !== null && contextSubcommands.has(segmentSubCmd);
|
|
6794
7060
|
if (inDataBearingContext) {
|
|
6795
|
-
const heredoc =
|
|
7061
|
+
const heredoc = HEREDOC_OPEN2.exec(tok);
|
|
6796
7062
|
if (heredoc) {
|
|
6797
7063
|
const delim = heredoc[2];
|
|
6798
7064
|
const closes = (t) => t === delim || t.endsWith("\n" + delim);
|
|
@@ -7502,7 +7768,7 @@ function nearMiss(req, rule) {
|
|
|
7502
7768
|
// src/hooks/runtime/guard-rules-cache.ts
|
|
7503
7769
|
import { readFileSync as readFileSync11, writeFileSync as writeFileSync6, existsSync as existsSync11, mkdirSync as mkdirSync5 } from "node:fs";
|
|
7504
7770
|
import { dirname as dirname4 } from "node:path";
|
|
7505
|
-
import { homedir as
|
|
7771
|
+
import { homedir as homedir8 } from "node:os";
|
|
7506
7772
|
import { join as join8 } from "node:path";
|
|
7507
7773
|
|
|
7508
7774
|
// node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/external.js
|
|
@@ -11616,7 +11882,7 @@ function parseRuleFields(raw) {
|
|
|
11616
11882
|
|
|
11617
11883
|
// src/hooks/runtime/guard-rules-cache.ts
|
|
11618
11884
|
var DEFAULT_CACHE_FILE = join8(
|
|
11619
|
-
|
|
11885
|
+
homedir8(),
|
|
11620
11886
|
".cybedefend",
|
|
11621
11887
|
"guards-cache.json"
|
|
11622
11888
|
);
|
|
@@ -11885,9 +12151,9 @@ function detectPromptInjection(text) {
|
|
|
11885
12151
|
// src/hooks/runtime/judge-cache.ts
|
|
11886
12152
|
import { readFileSync as readFileSync12, writeFileSync as writeFileSync7, existsSync as existsSync12, mkdirSync as mkdirSync6 } from "node:fs";
|
|
11887
12153
|
import { dirname as dirname5, join as join9 } from "node:path";
|
|
11888
|
-
import { homedir as
|
|
12154
|
+
import { homedir as homedir9 } from "node:os";
|
|
11889
12155
|
var DEFAULT_JUDGE_CACHE_FILE = join9(
|
|
11890
|
-
|
|
12156
|
+
homedir9(),
|
|
11891
12157
|
".cybedefend",
|
|
11892
12158
|
"guards-judge-cache.json"
|
|
11893
12159
|
);
|
|
@@ -11933,7 +12199,7 @@ function ensureDirFor3(filePath) {
|
|
|
11933
12199
|
}
|
|
11934
12200
|
|
|
11935
12201
|
// src/hooks/runtime/guard-check.ts
|
|
11936
|
-
import { homedir as
|
|
12202
|
+
import { homedir as homedir11 } from "node:os";
|
|
11937
12203
|
import { join as join11 } from "node:path";
|
|
11938
12204
|
|
|
11939
12205
|
// src/hooks/runtime/guard-violations-buffer.ts
|
|
@@ -11945,10 +12211,10 @@ import {
|
|
|
11945
12211
|
mkdirSync as mkdirSync7
|
|
11946
12212
|
} from "node:fs";
|
|
11947
12213
|
import { dirname as dirname6 } from "node:path";
|
|
11948
|
-
import { homedir as
|
|
12214
|
+
import { homedir as homedir10 } from "node:os";
|
|
11949
12215
|
import { join as join10 } from "node:path";
|
|
11950
12216
|
var DEFAULT_BUFFER_FILE = join10(
|
|
11951
|
-
|
|
12217
|
+
homedir10(),
|
|
11952
12218
|
".cybedefend",
|
|
11953
12219
|
"guards-violations-buffer.jsonl"
|
|
11954
12220
|
);
|
|
@@ -12578,7 +12844,7 @@ function emitAgentMessage(verdict, message) {
|
|
|
12578
12844
|
}
|
|
12579
12845
|
function makeProductionJudgeDeps() {
|
|
12580
12846
|
const cache = makeJudgeCache();
|
|
12581
|
-
const warnDir = process.env.CYBEDEFEND_BASELINE_DIR ?? join11(
|
|
12847
|
+
const warnDir = process.env.CYBEDEFEND_BASELINE_DIR ?? join11(homedir11(), ".cybedefend");
|
|
12582
12848
|
const warnTracker = defaultSessionTracker(
|
|
12583
12849
|
join11(warnDir, "guards-judge-warned-sessions.json")
|
|
12584
12850
|
);
|