@akasecurity/ai-tc-codex 0.9.16 → 0.9.17
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/.codex-plugin/plugin.json +1 -1
- package/package.json +6 -6
- package/scripts/apply-suppressions.js +739 -1263
- package/scripts/backfill.js +1040 -1291
- package/scripts/content-retention.js +781 -2074
- package/scripts/filescan.js +1266 -497
- package/scripts/firstrun.js +1277 -1701
- package/scripts/history-sync.js +777 -2107
- package/scripts/intro.js +141 -2190
- package/scripts/onboard.js +2806 -1186
- package/scripts/post-tool-use.js +1512 -1728
- package/scripts/pre-tool-use.js +1094 -1319
- package/scripts/query.js +1277 -1701
- package/scripts/reconcile.js +897 -1288
- package/scripts/remediate.js +1081 -1341
- package/scripts/scan-worker.js +147 -14
- package/scripts/session-start.js +1895 -827
- package/scripts/start-light.js +176 -1360
- package/scripts/stop.js +322 -1113
- package/scripts/sync.js +1818 -1029
- package/scripts/user-prompt-submit.js +1295 -1489
package/scripts/query.js
CHANGED
|
@@ -1,888 +1,8 @@
|
|
|
1
|
-
var __create = Object.create;
|
|
2
1
|
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
-
var __commonJS = (cb, mod) => function __require() {
|
|
8
|
-
try {
|
|
9
|
-
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
10
|
-
} catch (e) {
|
|
11
|
-
throw mod = 0, e;
|
|
12
|
-
}
|
|
13
|
-
};
|
|
14
2
|
var __export = (target, all) => {
|
|
15
3
|
for (var name in all)
|
|
16
4
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
17
5
|
};
|
|
18
|
-
var __copyProps = (to, from, except, desc) => {
|
|
19
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
20
|
-
for (let key of __getOwnPropNames(from))
|
|
21
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
22
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
23
|
-
}
|
|
24
|
-
return to;
|
|
25
|
-
};
|
|
26
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
27
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
28
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
29
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
30
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
31
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
32
|
-
mod
|
|
33
|
-
));
|
|
34
|
-
|
|
35
|
-
// ../../node_modules/.pnpm/ignore@7.0.11/node_modules/ignore/index.js
|
|
36
|
-
var require_ignore = __commonJS({
|
|
37
|
-
"../../node_modules/.pnpm/ignore@7.0.11/node_modules/ignore/index.js"(exports, module) {
|
|
38
|
-
"use strict";
|
|
39
|
-
function makeArray(subject) {
|
|
40
|
-
return Array.isArray(subject) ? subject : [subject];
|
|
41
|
-
}
|
|
42
|
-
var UNDEFINED = void 0;
|
|
43
|
-
var EMPTY = "";
|
|
44
|
-
var SPACE = " ";
|
|
45
|
-
var ESCAPE = "\\";
|
|
46
|
-
var REGEX_LITERAL_SPECIAL = /[.*+?()[\]{}^$|\\/]/;
|
|
47
|
-
var REGEX_TEST_BLANK_LINE = /^\uFEFF? *$/;
|
|
48
|
-
var REGEX_INVALID_TRAILING_BACKSLASH = /(?:[^\\]|^)\\$/;
|
|
49
|
-
var REGEX_REPLACE_LEADING_EXCAPED_EXCLAMATION = /^\\!/;
|
|
50
|
-
var REGEX_REPLACE_LEADING_EXCAPED_HASH = /^\\#/;
|
|
51
|
-
var REGEX_SPLITALL_CRLF = /\r?\n/g;
|
|
52
|
-
var DOUBLE_SLASH = "//";
|
|
53
|
-
var SLASH_CODE = 47;
|
|
54
|
-
var DOT_CODE = 46;
|
|
55
|
-
var SLASH3 = "/";
|
|
56
|
-
var TMP_KEY_IGNORE = "node-ignore";
|
|
57
|
-
if (typeof Symbol !== "undefined") {
|
|
58
|
-
TMP_KEY_IGNORE = /* @__PURE__ */ Symbol.for("node-ignore");
|
|
59
|
-
}
|
|
60
|
-
var KEY_IGNORE = TMP_KEY_IGNORE;
|
|
61
|
-
var define = (object2, key, value) => {
|
|
62
|
-
Object.defineProperty(object2, key, { value });
|
|
63
|
-
return value;
|
|
64
|
-
};
|
|
65
|
-
var RETURN_FALSE = () => false;
|
|
66
|
-
var cleanRangeBackSlash = (slashes) => {
|
|
67
|
-
const { length } = slashes;
|
|
68
|
-
return slashes.slice(0, length - length % 2);
|
|
69
|
-
};
|
|
70
|
-
var POSIX_CLASSES = {
|
|
71
|
-
alnum: "0-9A-Za-z",
|
|
72
|
-
alpha: "A-Za-z",
|
|
73
|
-
blank: " \\t",
|
|
74
|
-
cntrl: "\\x00-\\x1f\\x7f",
|
|
75
|
-
digit: "0-9",
|
|
76
|
-
graph: "!-.0-~",
|
|
77
|
-
lower: "a-z",
|
|
78
|
-
print: " -.0-~",
|
|
79
|
-
punct: "!-.:-@\\[-`{-~",
|
|
80
|
-
// git's `sane-ctype.h` classifies \v and \f as control, not space,
|
|
81
|
-
// unlike C's `isspace`
|
|
82
|
-
space: " \\t\\n\\r",
|
|
83
|
-
upper: "A-Z",
|
|
84
|
-
xdigit: "0-9A-Fa-f"
|
|
85
|
-
};
|
|
86
|
-
var CLASS_MEMBERS_TO_ESCAPE = "\\]^-[";
|
|
87
|
-
var escapeMember = (char) => CLASS_MEMBERS_TO_ESCAPE.indexOf(char) < 0 ? char : ESCAPE + char;
|
|
88
|
-
var NON_SLASH = "(?!\\/)";
|
|
89
|
-
var classSource = (negated, body) => {
|
|
90
|
-
if (negated) {
|
|
91
|
-
return `[^\\/${body}]`;
|
|
92
|
-
}
|
|
93
|
-
const source = `[${body}]`;
|
|
94
|
-
return new RegExp(source).test("/") ? NON_SLASH + source : source;
|
|
95
|
-
};
|
|
96
|
-
var scanBracket = (pattern, start) => {
|
|
97
|
-
const { length } = pattern;
|
|
98
|
-
let index = start + 1;
|
|
99
|
-
let negated = EMPTY;
|
|
100
|
-
const lead = pattern[index];
|
|
101
|
-
if (lead === "!" || lead === "^") {
|
|
102
|
-
negated = "^";
|
|
103
|
-
index++;
|
|
104
|
-
}
|
|
105
|
-
let body = EMPTY;
|
|
106
|
-
let prev = EMPTY;
|
|
107
|
-
for (; ; ) {
|
|
108
|
-
const char = pattern[index];
|
|
109
|
-
if (char === UNDEFINED) {
|
|
110
|
-
return null;
|
|
111
|
-
}
|
|
112
|
-
if (char === ESCAPE) {
|
|
113
|
-
const escaped = pattern[index + 1];
|
|
114
|
-
if (escaped === UNDEFINED) {
|
|
115
|
-
return null;
|
|
116
|
-
}
|
|
117
|
-
body += escapeMember(escaped);
|
|
118
|
-
prev = escaped;
|
|
119
|
-
index++;
|
|
120
|
-
} else if (char === "-" && prev && index + 1 < length && pattern[index + 1] !== "]") {
|
|
121
|
-
index++;
|
|
122
|
-
let to = pattern[index];
|
|
123
|
-
if (to === ESCAPE) {
|
|
124
|
-
to = pattern[index += 1];
|
|
125
|
-
}
|
|
126
|
-
if (prev <= to) {
|
|
127
|
-
body += `-${escapeMember(to)}`;
|
|
128
|
-
}
|
|
129
|
-
prev = EMPTY;
|
|
130
|
-
} else if (char === "[" && pattern[index + 1] === ":") {
|
|
131
|
-
const nameStart = index + 2;
|
|
132
|
-
let end = nameStart;
|
|
133
|
-
while (end < length && pattern[end] !== "]") {
|
|
134
|
-
end++;
|
|
135
|
-
}
|
|
136
|
-
if (end === length) {
|
|
137
|
-
return null;
|
|
138
|
-
}
|
|
139
|
-
if (end > nameStart && pattern[end - 1] === ":") {
|
|
140
|
-
const expanded = POSIX_CLASSES[pattern.slice(nameStart, end - 1)];
|
|
141
|
-
if (expanded === UNDEFINED) {
|
|
142
|
-
return null;
|
|
143
|
-
}
|
|
144
|
-
body += expanded;
|
|
145
|
-
prev = EMPTY;
|
|
146
|
-
index = end;
|
|
147
|
-
} else {
|
|
148
|
-
body += escapeMember("[");
|
|
149
|
-
prev = "[";
|
|
150
|
-
index = nameStart - 2;
|
|
151
|
-
}
|
|
152
|
-
} else {
|
|
153
|
-
body += escapeMember(char);
|
|
154
|
-
prev = char;
|
|
155
|
-
}
|
|
156
|
-
index++;
|
|
157
|
-
if (pattern[index] === "]") {
|
|
158
|
-
return {
|
|
159
|
-
end: index,
|
|
160
|
-
source: classSource(negated, body)
|
|
161
|
-
};
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
};
|
|
165
|
-
var NEVER_MATCH = "[]";
|
|
166
|
-
var PLACEHOLDER = "\0";
|
|
167
|
-
var REGEX_RESTORE_PLACEHOLDER = new RegExp(
|
|
168
|
-
`${PLACEHOLDER}(\\d+)${PLACEHOLDER}`,
|
|
169
|
-
"g"
|
|
170
|
-
);
|
|
171
|
-
var TRAILING_WILDCARD = "\uE000";
|
|
172
|
-
var TRAILING_DOUBLESTAR = "\uE001";
|
|
173
|
-
var extractBrackets = (pattern) => {
|
|
174
|
-
const sources = [];
|
|
175
|
-
const hold = (source) => `${PLACEHOLDER}${sources.push(source) - 1}${PLACEHOLDER}`;
|
|
176
|
-
const { length } = pattern;
|
|
177
|
-
let out = EMPTY;
|
|
178
|
-
let index = 0;
|
|
179
|
-
while (index < length) {
|
|
180
|
-
const char = pattern[index];
|
|
181
|
-
if (char === ESCAPE) {
|
|
182
|
-
const escaped = pattern[index + 1];
|
|
183
|
-
if (escaped === "*" || escaped === "[" || escaped === SPACE || escaped === ESCAPE) {
|
|
184
|
-
out += pattern.slice(index, index + 2);
|
|
185
|
-
} else {
|
|
186
|
-
out += hold(
|
|
187
|
-
REGEX_LITERAL_SPECIAL.test(escaped) ? ESCAPE + escaped : escaped
|
|
188
|
-
);
|
|
189
|
-
}
|
|
190
|
-
index += 2;
|
|
191
|
-
} else if (char === PLACEHOLDER) {
|
|
192
|
-
out += hold(`[${PLACEHOLDER}]`);
|
|
193
|
-
index++;
|
|
194
|
-
} else if (char === "[") {
|
|
195
|
-
const scanned = scanBracket(pattern, index);
|
|
196
|
-
if (scanned === null) {
|
|
197
|
-
out += hold(NEVER_MATCH);
|
|
198
|
-
index = length;
|
|
199
|
-
} else {
|
|
200
|
-
out += hold(scanned.source);
|
|
201
|
-
index = scanned.end + 1;
|
|
202
|
-
}
|
|
203
|
-
} else {
|
|
204
|
-
out += char;
|
|
205
|
-
index++;
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
return {
|
|
209
|
-
source: out,
|
|
210
|
-
sources
|
|
211
|
-
};
|
|
212
|
-
};
|
|
213
|
-
var DIRECT = null;
|
|
214
|
-
var REGEX_INNER_SLASH = /\/(?!$)/;
|
|
215
|
-
var REPLACERS = [
|
|
216
|
-
[
|
|
217
|
-
// Remove BOM
|
|
218
|
-
// TODO:
|
|
219
|
-
// Other similar zero-width characters?
|
|
220
|
-
/^\uFEFF/,
|
|
221
|
-
() => EMPTY,
|
|
222
|
-
"\uFEFF"
|
|
223
|
-
],
|
|
224
|
-
[
|
|
225
|
-
// A trailing line terminator, left on when a whole file's contents are
|
|
226
|
-
// added as one pattern rather than split into lines. git never sees one
|
|
227
|
-
// -- it reads a `.gitignore` line by line -- so it is not part of the
|
|
228
|
-
// pattern and is dropped here, apart from the trailing-space trimming,
|
|
229
|
-
// which follows git in touching spaces and nothing else.
|
|
230
|
-
/[\r\n]+$/,
|
|
231
|
-
() => EMPTY
|
|
232
|
-
],
|
|
233
|
-
// > Trailing spaces are ignored unless they are quoted with backslash ("\")
|
|
234
|
-
[
|
|
235
|
-
// Only spaces, never tabs or other whitespace: git trims a trailing run
|
|
236
|
-
// of `' '` and nothing else (dir.c, `trim_trailing_spaces`, a single
|
|
237
|
-
// `case ' '`), so a pattern ending in a tab keeps it as a literal.
|
|
238
|
-
// (a\ ) -> (a )
|
|
239
|
-
// (a ) -> (a)
|
|
240
|
-
// (a ) -> (a)
|
|
241
|
-
// (a \ ) -> (a )
|
|
242
|
-
/((?:\\\\)*?)(\\? +)$/,
|
|
243
|
-
(_, m1, m2) => m1 + (m2.indexOf("\\") === 0 ? SPACE : EMPTY)
|
|
244
|
-
],
|
|
245
|
-
// Replace (\ ) with ' '
|
|
246
|
-
// Only a space: an escaped tab or other whitespace is already a literal by
|
|
247
|
-
// the time it reaches here, and a bare tab must be left as one, not turned
|
|
248
|
-
// into a space.
|
|
249
|
-
// (\ ) -> ' '
|
|
250
|
-
// (\\ ) -> '\\ '
|
|
251
|
-
// (\\\ ) -> '\\ '
|
|
252
|
-
[
|
|
253
|
-
/(\\+?) /g,
|
|
254
|
-
(_, m1) => {
|
|
255
|
-
const { length } = m1;
|
|
256
|
-
return m1.slice(0, length - length % 2) + SPACE;
|
|
257
|
-
}
|
|
258
|
-
],
|
|
259
|
-
// Escape metacharacters
|
|
260
|
-
// which is written down by users but means special for regular expressions.
|
|
261
|
-
// > There are 12 characters with special meanings:
|
|
262
|
-
// > - the backslash \,
|
|
263
|
-
// > - the caret ^,
|
|
264
|
-
// > - the dollar sign $,
|
|
265
|
-
// > - the period or dot .,
|
|
266
|
-
// > - the vertical bar or pipe symbol |,
|
|
267
|
-
// > - the question mark ?,
|
|
268
|
-
// > - the asterisk or star *,
|
|
269
|
-
// > - the plus sign +,
|
|
270
|
-
// > - the opening parenthesis (,
|
|
271
|
-
// > - the closing parenthesis ),
|
|
272
|
-
// > - and the opening square bracket [,
|
|
273
|
-
// > - the opening curly brace {,
|
|
274
|
-
// > These special characters are often called "metacharacters".
|
|
275
|
-
[
|
|
276
|
-
/[\\$.|*+(){^]/g,
|
|
277
|
-
(match) => `\\${match}`
|
|
278
|
-
],
|
|
279
|
-
[
|
|
280
|
-
// > a question mark (?) matches a single character
|
|
281
|
-
/(?!\\)\?/g,
|
|
282
|
-
() => "[^/]",
|
|
283
|
-
"?"
|
|
284
|
-
],
|
|
285
|
-
// leading slash
|
|
286
|
-
[
|
|
287
|
-
// > A leading slash matches the beginning of the pathname.
|
|
288
|
-
// > For example, "/*.c" matches "cat-file.c" but not "mozilla-sha1/sha1.c".
|
|
289
|
-
// A leading slash matches the beginning of the pathname
|
|
290
|
-
/^\//,
|
|
291
|
-
() => "^",
|
|
292
|
-
SLASH3
|
|
293
|
-
],
|
|
294
|
-
// replace special metacharacter slash after the leading slash
|
|
295
|
-
[
|
|
296
|
-
/\//g,
|
|
297
|
-
() => "\\/",
|
|
298
|
-
SLASH3
|
|
299
|
-
],
|
|
300
|
-
[
|
|
301
|
-
// > A leading "**" followed by a slash means match in all directories.
|
|
302
|
-
// > For example, "**/foo" matches file or directory "foo" anywhere,
|
|
303
|
-
// > the same as pattern "foo".
|
|
304
|
-
// > "**/foo/bar" matches file or directory "bar" anywhere that is directly
|
|
305
|
-
// > under directory "foo".
|
|
306
|
-
// Notice that the '*'s have been replaced as '\\*'
|
|
307
|
-
/^\^*(?:\\\*\\\*\\\/)+/,
|
|
308
|
-
// '**/foo' <-> 'foo'
|
|
309
|
-
() => "^(?:.*\\/)?",
|
|
310
|
-
"*"
|
|
311
|
-
],
|
|
312
|
-
// starting
|
|
313
|
-
[
|
|
314
|
-
// there will be no leading '/'
|
|
315
|
-
// (which has been replaced by section "leading slash")
|
|
316
|
-
// If starts with '**', adding a '^' to the regular expression also works
|
|
317
|
-
DIRECT,
|
|
318
|
-
(source, pattern) => {
|
|
319
|
-
if (!source || source[0] === "^") {
|
|
320
|
-
return source;
|
|
321
|
-
}
|
|
322
|
-
const anchor2 = !REGEX_INNER_SLASH.test(pattern) ? "(?:^|\\/)" : "^";
|
|
323
|
-
return anchor2 + source;
|
|
324
|
-
}
|
|
325
|
-
],
|
|
326
|
-
// two globstars
|
|
327
|
-
[
|
|
328
|
-
// Use lookahead assertions so that we could match more than one `'/**'`
|
|
329
|
-
/\\\/\\\*\\\*(?=\\\/|$)/g,
|
|
330
|
-
// Zero, one or several directories
|
|
331
|
-
// should not use '*', or it will be replaced by the next replacer
|
|
332
|
-
// Check if it is not the last `'/**'`
|
|
333
|
-
(_, index, str2) => index + 6 < str2.length ? str2.slice(index + 6) === "\\/" ? "(?:\\/[^\\/]+)+" : "(?:\\/[^\\/]+)*" : `\\/${TRAILING_DOUBLESTAR}`,
|
|
334
|
-
"*"
|
|
335
|
-
],
|
|
336
|
-
// normal intermediate wildcards
|
|
337
|
-
[
|
|
338
|
-
// Never replace escaped '*'
|
|
339
|
-
// ignore rule '\*' will match the path '*'
|
|
340
|
-
// 'abc.*/' -> go
|
|
341
|
-
// 'abc.*' -> skip this rule,
|
|
342
|
-
// coz trailing single wildcard will be handed by [trailing wildcard]
|
|
343
|
-
/(^|[^\\]+)(\\\*)+(?=.+)/g,
|
|
344
|
-
// '*.js' matches '.js'
|
|
345
|
-
// '*.js' doesn't match 'abc'
|
|
346
|
-
(_, p1, p2) => {
|
|
347
|
-
const unescaped = p2.replace(/\\\*/g, "[^\\/]*");
|
|
348
|
-
return p1 + unescaped;
|
|
349
|
-
},
|
|
350
|
-
"*"
|
|
351
|
-
],
|
|
352
|
-
// trailing wildcard, held apart from a literal star
|
|
353
|
-
[
|
|
354
|
-
// The step above leaves a trailing `*` alone, so a single `\*` is all that
|
|
355
|
-
// can be left at the end here. Whether it is a wildcard or a literal
|
|
356
|
-
// turns on the backslashes the user put in front of it: the escaper has
|
|
357
|
-
// since doubled every one, so what stands here is those `2N` doubled
|
|
358
|
-
// backslashes and then the star's own escape. An even number of the
|
|
359
|
-
// original `N` leaves the star unescaped -- a wildcard -- and an odd
|
|
360
|
-
// number escapes it -- a literal. This runs while the two are still
|
|
361
|
-
// distinct, before the unescape steps below collapse the literal onto
|
|
362
|
-
// the very `\*` a wildcard leaves behind.
|
|
363
|
-
/(^|[^\\])((?:\\\\)*)\\\*$/,
|
|
364
|
-
(match, p1, p2) => (
|
|
365
|
-
// `p2` holds the doubled user backslashes; half of them is `N`.
|
|
366
|
-
p2.length / 2 % 2 === 0 ? p1 + p2 + TRAILING_WILDCARD : match
|
|
367
|
-
),
|
|
368
|
-
"*"
|
|
369
|
-
],
|
|
370
|
-
[
|
|
371
|
-
// unescape, revert step 3 except for back slash
|
|
372
|
-
// For example, if a user escape a '\\*',
|
|
373
|
-
// after step 3, the result will be '\\\\\\*'
|
|
374
|
-
/\\\\\\(?=[$.|*+(){^])/g,
|
|
375
|
-
() => ESCAPE,
|
|
376
|
-
ESCAPE + ESCAPE
|
|
377
|
-
],
|
|
378
|
-
[
|
|
379
|
-
// '\\\\' -> '\\'
|
|
380
|
-
/\\\\/g,
|
|
381
|
-
() => ESCAPE,
|
|
382
|
-
ESCAPE + ESCAPE
|
|
383
|
-
],
|
|
384
|
-
[
|
|
385
|
-
// Every real bracket expression -- POSIX classes included -- has already
|
|
386
|
-
// been held aside by `extractBrackets`, so the only `[` left in the
|
|
387
|
-
// pattern is an escaped, literal one.
|
|
388
|
-
// `\` is escaped by step 3
|
|
389
|
-
/\\\[([^\]/]*?)(\\*)($|\])/g,
|
|
390
|
-
// '\\[bar]' -> '\\\\[bar\\]'
|
|
391
|
-
(match, range, endEscape, close) => `\\[${range}${cleanRangeBackSlash(endEscape)}${close}`,
|
|
392
|
-
"["
|
|
393
|
-
],
|
|
394
|
-
// ending
|
|
395
|
-
[
|
|
396
|
-
// 'js' will not match 'js.'
|
|
397
|
-
// 'ab' will not match 'abc'
|
|
398
|
-
DIRECT,
|
|
399
|
-
// WTF!
|
|
400
|
-
// https://git-scm.com/docs/gitignore
|
|
401
|
-
// changes in [2.22.1](https://git-scm.com/docs/gitignore/2.22.1)
|
|
402
|
-
// which re-fixes #24, #38
|
|
403
|
-
// > If there is a separator at the end of the pattern then the pattern
|
|
404
|
-
// > will only match directories, otherwise the pattern can match both
|
|
405
|
-
// > files and directories.
|
|
406
|
-
// 'js*' will not match 'a.js'
|
|
407
|
-
// 'js/' will not match 'a.js'
|
|
408
|
-
// 'js' will match 'a.js' and 'a.js/'
|
|
409
|
-
(source) => {
|
|
410
|
-
const last = source[source.length - 1];
|
|
411
|
-
if (!last || last === TRAILING_WILDCARD || last === TRAILING_DOUBLESTAR) {
|
|
412
|
-
return source;
|
|
413
|
-
}
|
|
414
|
-
return last === SLASH3 ? `${source}$` : `${source}(?=$|\\/$)`;
|
|
415
|
-
}
|
|
416
|
-
]
|
|
417
|
-
];
|
|
418
|
-
var REGEX_REPLACE_TRAILING_WILDCARD = /(^|\\\/)?\uE000$/;
|
|
419
|
-
var MODE_IGNORE = "regex";
|
|
420
|
-
var MODE_CHECK_IGNORE = "checkRegex";
|
|
421
|
-
var UNDERSCORE = "_";
|
|
422
|
-
var replaceTrailingWildcard = (_, p1) => {
|
|
423
|
-
const prefix = p1 ? `${p1}[^/]+` : "[^/]*";
|
|
424
|
-
return `${prefix}(?=$|\\/$)`;
|
|
425
|
-
};
|
|
426
|
-
var REGEX_REPLACE_TRAILING_DOUBLESTAR = /\uE001$/;
|
|
427
|
-
var replaceTrailingDoublestar = () => ".+(?=$|\\/$)";
|
|
428
|
-
var WILDCARD = "[^\\/]*";
|
|
429
|
-
var separatorAfter = (run, at) => {
|
|
430
|
-
let separator = EMPTY;
|
|
431
|
-
for (let index = at + 1; index < run.length && !run[index].wildcard; index++) {
|
|
432
|
-
separator += run[index].single;
|
|
433
|
-
}
|
|
434
|
-
return separator;
|
|
435
|
-
};
|
|
436
|
-
var pinWildcards = (source) => {
|
|
437
|
-
if (source.indexOf(WILDCARD) < 0) {
|
|
438
|
-
return source;
|
|
439
|
-
}
|
|
440
|
-
const tokens = [];
|
|
441
|
-
const { length } = source;
|
|
442
|
-
let index = 0;
|
|
443
|
-
while (index < length) {
|
|
444
|
-
const char = source[index];
|
|
445
|
-
if (source.startsWith(WILDCARD, index)) {
|
|
446
|
-
tokens.push({ wildcard: true });
|
|
447
|
-
index += WILDCARD.length;
|
|
448
|
-
} else if (char === "[") {
|
|
449
|
-
let end = index + 1;
|
|
450
|
-
if (source[end] === "^") {
|
|
451
|
-
end++;
|
|
452
|
-
}
|
|
453
|
-
if (source[end] === "]") {
|
|
454
|
-
end++;
|
|
455
|
-
}
|
|
456
|
-
while (end < length && source[end] !== "]") {
|
|
457
|
-
end += source[end] === ESCAPE ? 2 : 1;
|
|
458
|
-
}
|
|
459
|
-
end++;
|
|
460
|
-
tokens.push({ single: source.slice(index, end) });
|
|
461
|
-
index = end;
|
|
462
|
-
} else if (char === ESCAPE) {
|
|
463
|
-
tokens.push({ single: source.slice(index, index + 2) });
|
|
464
|
-
index += 2;
|
|
465
|
-
} else if (char === "(") {
|
|
466
|
-
let depth = 0;
|
|
467
|
-
let end = index;
|
|
468
|
-
do {
|
|
469
|
-
if (source[end] === ESCAPE) {
|
|
470
|
-
end++;
|
|
471
|
-
} else if (source[end] === "(") {
|
|
472
|
-
depth++;
|
|
473
|
-
} else if (source[end] === ")") {
|
|
474
|
-
depth--;
|
|
475
|
-
}
|
|
476
|
-
end++;
|
|
477
|
-
} while (end < length && depth > 0);
|
|
478
|
-
if ("*+?".indexOf(source[end]) >= 0) {
|
|
479
|
-
end++;
|
|
480
|
-
}
|
|
481
|
-
tokens.push({ boundary: source.slice(index, end) });
|
|
482
|
-
index = end;
|
|
483
|
-
} else if (char === "^" || char === "$") {
|
|
484
|
-
tokens.push({ boundary: char });
|
|
485
|
-
index++;
|
|
486
|
-
} else {
|
|
487
|
-
tokens.push({ single: char });
|
|
488
|
-
index++;
|
|
489
|
-
}
|
|
490
|
-
}
|
|
491
|
-
let out = EMPTY;
|
|
492
|
-
let run = [];
|
|
493
|
-
const flush = () => {
|
|
494
|
-
let lastWildcard;
|
|
495
|
-
run.forEach((token, at) => {
|
|
496
|
-
if (token.wildcard) {
|
|
497
|
-
lastWildcard = at;
|
|
498
|
-
}
|
|
499
|
-
});
|
|
500
|
-
run.forEach((token, at) => {
|
|
501
|
-
if (!token.wildcard) {
|
|
502
|
-
out += token.single;
|
|
503
|
-
return;
|
|
504
|
-
}
|
|
505
|
-
out += at === lastWildcard ? WILDCARD : `(?:(?!${separatorAfter(run, at)})[^\\/])*`;
|
|
506
|
-
});
|
|
507
|
-
run = [];
|
|
508
|
-
};
|
|
509
|
-
tokens.forEach((token) => {
|
|
510
|
-
if (token.boundary === void 0) {
|
|
511
|
-
run.push(token);
|
|
512
|
-
return;
|
|
513
|
-
}
|
|
514
|
-
flush();
|
|
515
|
-
out += token.boundary;
|
|
516
|
-
});
|
|
517
|
-
flush();
|
|
518
|
-
return out;
|
|
519
|
-
};
|
|
520
|
-
var makeRegexPrefix = (pattern) => {
|
|
521
|
-
const { source, sources } = extractBrackets(pattern);
|
|
522
|
-
const replaced = REPLACERS.reduce(
|
|
523
|
-
// A pass whose matcher finds nothing hands back the very string it was
|
|
524
|
-
// given, so asking first costs a search and saves a rewrite. Ten of the
|
|
525
|
-
// fifteen passes never fire for a typical .gitignore line, and between
|
|
526
|
-
// them they were 45% of this chain.
|
|
527
|
-
(prev, [matcher, replacer, required2]) => {
|
|
528
|
-
if (matcher === DIRECT) {
|
|
529
|
-
return replacer(prev, pattern);
|
|
530
|
-
}
|
|
531
|
-
if (required2 !== UNDEFINED && prev.indexOf(required2) < 0) {
|
|
532
|
-
return prev;
|
|
533
|
-
}
|
|
534
|
-
return matcher.test(prev) ? prev.replace(matcher, replacer.bind(pattern)) : prev;
|
|
535
|
-
},
|
|
536
|
-
source
|
|
537
|
-
);
|
|
538
|
-
return sources.length ? replaced.replace(
|
|
539
|
-
REGEX_RESTORE_PLACEHOLDER,
|
|
540
|
-
(match, index) => sources[index]
|
|
541
|
-
) : replaced;
|
|
542
|
-
};
|
|
543
|
-
var checkSourceOf = (body, prefix) => {
|
|
544
|
-
if (body[body.length - 1] === SLASH3) {
|
|
545
|
-
prefix = makeRegexPrefix(body.slice(0, -1));
|
|
546
|
-
}
|
|
547
|
-
const head = prefix.slice(0, -1);
|
|
548
|
-
const last = prefix[prefix.length - 1];
|
|
549
|
-
return last === TRAILING_WILDCARD ? `${head}$` : last === TRAILING_DOUBLESTAR ? `${head}.*$` : NEVER_MATCH;
|
|
550
|
-
};
|
|
551
|
-
var matchesBasename = (body) => {
|
|
552
|
-
const index = body.indexOf(SLASH3);
|
|
553
|
-
return index < 0 || index === body.length - 1;
|
|
554
|
-
};
|
|
555
|
-
var basenameOf = (path) => {
|
|
556
|
-
const end = path.length - 1;
|
|
557
|
-
const index = path.lastIndexOf(
|
|
558
|
-
SLASH3,
|
|
559
|
-
path[end] === SLASH3 ? end - 1 : end
|
|
560
|
-
);
|
|
561
|
-
return index < 0 ? path : path.slice(index + 1);
|
|
562
|
-
};
|
|
563
|
-
var parentOf = (path) => {
|
|
564
|
-
if (path.charCodeAt(0) === SLASH_CODE || path.indexOf(DOUBLE_SLASH) >= 0) {
|
|
565
|
-
const slices = path.split(SLASH3).filter(Boolean);
|
|
566
|
-
slices.pop();
|
|
567
|
-
return slices.length ? slices.join(SLASH3) + SLASH3 : EMPTY;
|
|
568
|
-
}
|
|
569
|
-
const end = path.length - 1;
|
|
570
|
-
const cut = path.lastIndexOf(
|
|
571
|
-
SLASH3,
|
|
572
|
-
path.charCodeAt(end) === SLASH_CODE ? end - 1 : end
|
|
573
|
-
);
|
|
574
|
-
return cut < 0 ? EMPTY : path.slice(0, cut + 1);
|
|
575
|
-
};
|
|
576
|
-
var isString = (subject) => typeof subject === "string";
|
|
577
|
-
var checkPattern = (pattern) => pattern && isString(pattern) && !REGEX_TEST_BLANK_LINE.test(pattern) && !REGEX_INVALID_TRAILING_BACKSLASH.test(pattern) && pattern.indexOf("#") !== 0;
|
|
578
|
-
var splitPattern = (pattern) => pattern.split(REGEX_SPLITALL_CRLF).filter(Boolean);
|
|
579
|
-
var IgnoreRule = class {
|
|
580
|
-
constructor(pattern, mark, body, ignoreCase, negative, prefix) {
|
|
581
|
-
this.pattern = pattern;
|
|
582
|
-
this.mark = mark;
|
|
583
|
-
this.negative = negative;
|
|
584
|
-
define(this, "body", body);
|
|
585
|
-
define(this, "ignoreCase", ignoreCase);
|
|
586
|
-
define(this, "regexPrefix", prefix);
|
|
587
|
-
}
|
|
588
|
-
// Worked out on first use and kept behind an own property, the way `regex`
|
|
589
|
-
// caches itself in `_regex`. Deciding it in the constructor instead would
|
|
590
|
-
// add a fourth `defineProperty` to every rule ever built, which cost 4% of
|
|
591
|
-
// every compile -- including the compiles of rules that are never matched
|
|
592
|
-
// against anything.
|
|
593
|
-
get _basenameOnly() {
|
|
594
|
-
return define(this, "_basenameOnly", matchesBasename(this.body));
|
|
595
|
-
}
|
|
596
|
-
get regex() {
|
|
597
|
-
const key = UNDERSCORE + MODE_IGNORE;
|
|
598
|
-
if (this[key]) {
|
|
599
|
-
return this[key];
|
|
600
|
-
}
|
|
601
|
-
return this._make(MODE_IGNORE, key);
|
|
602
|
-
}
|
|
603
|
-
get checkRegex() {
|
|
604
|
-
const key = UNDERSCORE + MODE_CHECK_IGNORE;
|
|
605
|
-
if (this[key]) {
|
|
606
|
-
return this[key];
|
|
607
|
-
}
|
|
608
|
-
return this._make(MODE_CHECK_IGNORE, key);
|
|
609
|
-
}
|
|
610
|
-
_make(mode, key) {
|
|
611
|
-
const str2 = pinWildcards(
|
|
612
|
-
mode === MODE_IGNORE ? this.regexPrefix.replace(REGEX_REPLACE_TRAILING_WILDCARD, replaceTrailingWildcard).replace(REGEX_REPLACE_TRAILING_DOUBLESTAR, replaceTrailingDoublestar) : checkSourceOf(this.body, this.regexPrefix)
|
|
613
|
-
);
|
|
614
|
-
const regex = this.ignoreCase ? new RegExp(str2, "i") : new RegExp(str2);
|
|
615
|
-
return define(this, key, regex);
|
|
616
|
-
}
|
|
617
|
-
};
|
|
618
|
-
var createRule = ({
|
|
619
|
-
pattern,
|
|
620
|
-
mark
|
|
621
|
-
}, ignoreCase) => {
|
|
622
|
-
let negative = false;
|
|
623
|
-
let body = pattern;
|
|
624
|
-
if (body.indexOf("!") === 0) {
|
|
625
|
-
negative = true;
|
|
626
|
-
body = body.substr(1);
|
|
627
|
-
}
|
|
628
|
-
body = body.replace(REGEX_REPLACE_LEADING_EXCAPED_EXCLAMATION, "!").replace(REGEX_REPLACE_LEADING_EXCAPED_HASH, "#");
|
|
629
|
-
const regexPrefix = makeRegexPrefix(body);
|
|
630
|
-
return new IgnoreRule(
|
|
631
|
-
pattern,
|
|
632
|
-
mark,
|
|
633
|
-
body,
|
|
634
|
-
ignoreCase,
|
|
635
|
-
negative,
|
|
636
|
-
regexPrefix
|
|
637
|
-
);
|
|
638
|
-
};
|
|
639
|
-
var RuleManager = class {
|
|
640
|
-
constructor(ignoreCase) {
|
|
641
|
-
this._ignoreCase = ignoreCase;
|
|
642
|
-
this._rules = [];
|
|
643
|
-
this._basenameCount = 0;
|
|
644
|
-
}
|
|
645
|
-
_add(pattern) {
|
|
646
|
-
if (pattern && pattern[KEY_IGNORE]) {
|
|
647
|
-
this._rules = this._rules.concat(pattern._rules._rules);
|
|
648
|
-
this._basenameCount += pattern._rules._basenameCount;
|
|
649
|
-
this._added = true;
|
|
650
|
-
return;
|
|
651
|
-
}
|
|
652
|
-
if (isString(pattern)) {
|
|
653
|
-
pattern = {
|
|
654
|
-
pattern
|
|
655
|
-
};
|
|
656
|
-
}
|
|
657
|
-
if (checkPattern(pattern.pattern)) {
|
|
658
|
-
const rule = createRule(pattern, this._ignoreCase);
|
|
659
|
-
this._added = true;
|
|
660
|
-
this._rules.push(rule);
|
|
661
|
-
if (matchesBasename(rule.body)) {
|
|
662
|
-
this._basenameCount++;
|
|
663
|
-
}
|
|
664
|
-
}
|
|
665
|
-
}
|
|
666
|
-
// @param {Array<string> | string | Ignore} pattern
|
|
667
|
-
add(pattern) {
|
|
668
|
-
this._added = false;
|
|
669
|
-
makeArray(
|
|
670
|
-
isString(pattern) ? splitPattern(pattern) : pattern
|
|
671
|
-
).forEach(this._add, this);
|
|
672
|
-
if (this._added) {
|
|
673
|
-
this._literalRules = UNDEFINED;
|
|
674
|
-
}
|
|
675
|
-
return this._added;
|
|
676
|
-
}
|
|
677
|
-
// Match the literal 'abc/' for `checkIgnore`, last rule wins. Only a rule
|
|
678
|
-
// ending in a wildcard can match it (see `checkSourceOf`), so the rest
|
|
679
|
-
// are left out once, rather than tested or compiled for every path.
|
|
680
|
-
testLiteral(path) {
|
|
681
|
-
const rules = this._literalRules || (this._literalRules = this._rules.filter(
|
|
682
|
-
({ body }) => body[body.length - (body[body.length - 1] === SLASH3 ? 2 : 1)] === "*"
|
|
683
|
-
));
|
|
684
|
-
let ignored = false;
|
|
685
|
-
let unignored = false;
|
|
686
|
-
let matchedRule;
|
|
687
|
-
for (let index = rules.length - 1; index >= 0; index--) {
|
|
688
|
-
const rule = rules[index];
|
|
689
|
-
if (rule.checkRegex.test(path)) {
|
|
690
|
-
ignored = !rule.negative;
|
|
691
|
-
unignored = rule.negative;
|
|
692
|
-
matchedRule = rule.negative ? UNDEFINED : rule;
|
|
693
|
-
break;
|
|
694
|
-
}
|
|
695
|
-
}
|
|
696
|
-
const ret = {
|
|
697
|
-
ignored,
|
|
698
|
-
unignored
|
|
699
|
-
};
|
|
700
|
-
if (matchedRule) {
|
|
701
|
-
ret.rule = matchedRule;
|
|
702
|
-
}
|
|
703
|
-
return ret;
|
|
704
|
-
}
|
|
705
|
-
// Test one single path without recursively checking parent directories
|
|
706
|
-
//
|
|
707
|
-
// - checkUnignored `boolean` whether should check if the path is unignored,
|
|
708
|
-
// setting `checkUnignored` to `false` could reduce additional
|
|
709
|
-
// path matching.
|
|
710
|
-
// - check `string` either `MODE_IGNORE` or `MODE_CHECK_IGNORE`
|
|
711
|
-
// @returns {TestResult} true if a file is ignored
|
|
712
|
-
test(path, checkUnignored, mode) {
|
|
713
|
-
let ignored = false;
|
|
714
|
-
let unignored = false;
|
|
715
|
-
let matchedRule;
|
|
716
|
-
const rules = this._rules;
|
|
717
|
-
const { length } = rules;
|
|
718
|
-
const shortcut = this._basenameCount * 2 >= length;
|
|
719
|
-
const basename8 = shortcut ? basenameOf(path) : path;
|
|
720
|
-
for (let index = 0; index < length; index++) {
|
|
721
|
-
const rule = rules[index];
|
|
722
|
-
const { negative } = rule;
|
|
723
|
-
const skip = unignored === negative && ignored !== unignored || negative && !ignored && !unignored && !checkUnignored;
|
|
724
|
-
if (!skip && rule[mode].test(
|
|
725
|
-
shortcut && rule._basenameOnly ? basename8 : path
|
|
726
|
-
)) {
|
|
727
|
-
ignored = !negative;
|
|
728
|
-
unignored = negative;
|
|
729
|
-
matchedRule = negative ? UNDEFINED : rule;
|
|
730
|
-
}
|
|
731
|
-
}
|
|
732
|
-
const ret = {
|
|
733
|
-
ignored,
|
|
734
|
-
unignored
|
|
735
|
-
};
|
|
736
|
-
if (matchedRule) {
|
|
737
|
-
ret.rule = matchedRule;
|
|
738
|
-
}
|
|
739
|
-
return ret;
|
|
740
|
-
}
|
|
741
|
-
};
|
|
742
|
-
var throwError = (message, Ctor) => {
|
|
743
|
-
throw new Ctor(message);
|
|
744
|
-
};
|
|
745
|
-
var checkPath = (path, originalPath, doThrow) => {
|
|
746
|
-
if (!isString(path)) {
|
|
747
|
-
return doThrow(
|
|
748
|
-
`path must be a string, but got \`${originalPath}\``,
|
|
749
|
-
TypeError
|
|
750
|
-
);
|
|
751
|
-
}
|
|
752
|
-
if (!path) {
|
|
753
|
-
return doThrow(`path must not be empty`, TypeError);
|
|
754
|
-
}
|
|
755
|
-
if (checkPath.isNotRelative(path)) {
|
|
756
|
-
const r = "`path.relative()`d";
|
|
757
|
-
return doThrow(
|
|
758
|
-
`path should be a ${r} string, but got "${originalPath}"`,
|
|
759
|
-
RangeError
|
|
760
|
-
);
|
|
761
|
-
}
|
|
762
|
-
return true;
|
|
763
|
-
};
|
|
764
|
-
var isNotRelative = (path) => {
|
|
765
|
-
const first = path.charCodeAt(0);
|
|
766
|
-
if (first === SLASH_CODE) {
|
|
767
|
-
return true;
|
|
768
|
-
}
|
|
769
|
-
if (first !== DOT_CODE) {
|
|
770
|
-
return false;
|
|
771
|
-
}
|
|
772
|
-
if (path.length === 1) {
|
|
773
|
-
return true;
|
|
774
|
-
}
|
|
775
|
-
const second = path.charCodeAt(1);
|
|
776
|
-
if (second === SLASH_CODE) {
|
|
777
|
-
return true;
|
|
778
|
-
}
|
|
779
|
-
if (second !== DOT_CODE) {
|
|
780
|
-
return false;
|
|
781
|
-
}
|
|
782
|
-
return path.length === 2 || path.charCodeAt(2) === SLASH_CODE;
|
|
783
|
-
};
|
|
784
|
-
checkPath.isNotRelative = isNotRelative;
|
|
785
|
-
checkPath.convert = (p) => p;
|
|
786
|
-
var Ignore = class {
|
|
787
|
-
constructor({
|
|
788
|
-
ignorecase = true,
|
|
789
|
-
ignoreCase = ignorecase,
|
|
790
|
-
allowRelativePaths = false
|
|
791
|
-
} = {}) {
|
|
792
|
-
define(this, KEY_IGNORE, true);
|
|
793
|
-
this._rules = new RuleManager(ignoreCase);
|
|
794
|
-
this._strictPathCheck = !allowRelativePaths;
|
|
795
|
-
this._initCache();
|
|
796
|
-
}
|
|
797
|
-
_initCache() {
|
|
798
|
-
this._ignoreCache = /* @__PURE__ */ Object.create(null);
|
|
799
|
-
this._testCache = /* @__PURE__ */ Object.create(null);
|
|
800
|
-
}
|
|
801
|
-
add(pattern) {
|
|
802
|
-
if (this._rules.add(pattern)) {
|
|
803
|
-
this._initCache();
|
|
804
|
-
}
|
|
805
|
-
return this;
|
|
806
|
-
}
|
|
807
|
-
// legacy
|
|
808
|
-
addPattern(pattern) {
|
|
809
|
-
return this.add(pattern);
|
|
810
|
-
}
|
|
811
|
-
// @returns {TestResult}
|
|
812
|
-
_test(originalPath, cache, checkUnignored) {
|
|
813
|
-
const path = originalPath && checkPath.convert(originalPath);
|
|
814
|
-
checkPath(
|
|
815
|
-
path,
|
|
816
|
-
originalPath,
|
|
817
|
-
this._strictPathCheck ? throwError : RETURN_FALSE
|
|
818
|
-
);
|
|
819
|
-
return this._t(path, cache, checkUnignored);
|
|
820
|
-
}
|
|
821
|
-
checkIgnore(path) {
|
|
822
|
-
if (path.charCodeAt(path.length - 1) !== SLASH_CODE) {
|
|
823
|
-
return this.test(path);
|
|
824
|
-
}
|
|
825
|
-
const dir = this._t(path, this._testCache, true);
|
|
826
|
-
if (dir.ignored) {
|
|
827
|
-
return dir;
|
|
828
|
-
}
|
|
829
|
-
const literal2 = this._rules.testLiteral(path);
|
|
830
|
-
return literal2.ignored || literal2.unignored ? literal2 : dir;
|
|
831
|
-
}
|
|
832
|
-
_t(path, cache, checkUnignored) {
|
|
833
|
-
if (path in cache) {
|
|
834
|
-
return cache[path];
|
|
835
|
-
}
|
|
836
|
-
const parentPath = parentOf(path);
|
|
837
|
-
const parent = parentPath ? this._t(parentPath, cache, checkUnignored) : UNDEFINED;
|
|
838
|
-
return cache[path] = parent && parent.ignored ? parent : this._rules.test(path, checkUnignored, MODE_IGNORE);
|
|
839
|
-
}
|
|
840
|
-
ignores(path) {
|
|
841
|
-
return this._test(path, this._ignoreCache, false).ignored;
|
|
842
|
-
}
|
|
843
|
-
createFilter() {
|
|
844
|
-
return (path) => !this.ignores(path);
|
|
845
|
-
}
|
|
846
|
-
filter(paths) {
|
|
847
|
-
return makeArray(paths).filter(this.createFilter());
|
|
848
|
-
}
|
|
849
|
-
// @returns {TestResult}
|
|
850
|
-
test(path) {
|
|
851
|
-
return this._test(path, this._testCache, true);
|
|
852
|
-
}
|
|
853
|
-
};
|
|
854
|
-
var factory = (options) => new Ignore(options);
|
|
855
|
-
var isPathValid = (path) => checkPath(path && checkPath.convert(path), path, RETURN_FALSE);
|
|
856
|
-
var setupWindows = () => {
|
|
857
|
-
const makePosix = (str2) => /^\\\\\?\\/.test(str2) || /["<>|\u0000-\u001F]+/u.test(str2) ? str2 : str2.replace(/\\/g, "/");
|
|
858
|
-
checkPath.convert = makePosix;
|
|
859
|
-
const REGEX_TEST_WINDOWS_PATH_ABSOLUTE = /^[a-z]:\//i;
|
|
860
|
-
checkPath.isNotRelative = (path) => REGEX_TEST_WINDOWS_PATH_ABSOLUTE.test(path) || isNotRelative(path);
|
|
861
|
-
};
|
|
862
|
-
if (
|
|
863
|
-
// Detect `process` so that it can run in browsers.
|
|
864
|
-
typeof process !== "undefined" && process.platform === "win32"
|
|
865
|
-
) {
|
|
866
|
-
setupWindows();
|
|
867
|
-
}
|
|
868
|
-
module.exports = factory;
|
|
869
|
-
factory.default = factory;
|
|
870
|
-
module.exports.isPathValid = isPathValid;
|
|
871
|
-
define(module.exports, /* @__PURE__ */ Symbol.for("setupWindows"), setupWindows);
|
|
872
|
-
}
|
|
873
|
-
});
|
|
874
|
-
|
|
875
|
-
// ../../packages/persistence/src/attached-derived.ts
|
|
876
|
-
import { rmSync } from "fs";
|
|
877
|
-
import { join } from "path";
|
|
878
|
-
var POLICY_CACHE_FILENAME = "policy-cache.json";
|
|
879
|
-
var ATTACHED_FORWARD_STATE_FILENAME = "attached-state.json";
|
|
880
|
-
var ATTACHED_FORWARD_DROPS_FILENAME = "attached-forward-drops.json";
|
|
881
|
-
var ATTACHED_POSTURE_REPORT_FILENAME = "attached-posture-report.json";
|
|
882
|
-
|
|
883
|
-
// ../../packages/persistence/src/control-plane-credential.ts
|
|
884
|
-
import { chmodSync as chmodSync2, lstatSync as lstatSync2, readFileSync, rmSync as rmSync3, statSync } from "fs";
|
|
885
|
-
import { join as join2 } from "path";
|
|
886
6
|
|
|
887
7
|
// ../../packages/schema/src/drizzle/deferred-migrations.ts
|
|
888
8
|
var DEFERRED_MIGRATION_TAGS = [
|
|
@@ -3867,9 +2987,9 @@ var asciiTabOrNewline = /[\t\n\r]/g;
|
|
|
3867
2987
|
function stripTabAndNewline(value) {
|
|
3868
2988
|
return value.replace(asciiTabOrNewline, "");
|
|
3869
2989
|
}
|
|
3870
|
-
function urlHostnameOk(url2,
|
|
3871
|
-
|
|
3872
|
-
return
|
|
2990
|
+
function urlHostnameOk(url2, hostname6) {
|
|
2991
|
+
hostname6.lastIndex = 0;
|
|
2992
|
+
return hostname6.test(url2.hostname);
|
|
3873
2993
|
}
|
|
3874
2994
|
function urlProtocolOk(url2, protocol) {
|
|
3875
2995
|
protocol.lastIndex = 0;
|
|
@@ -20789,13 +19909,16 @@ function serviceTierMultiplier(tier) {
|
|
|
20789
19909
|
if (tier === void 0) return 1;
|
|
20790
19910
|
return SERVICE_TIER_MULTIPLIERS.get(tier) ?? 1;
|
|
20791
19911
|
}
|
|
19912
|
+
function promptTokensOf(usage) {
|
|
19913
|
+
return usage.promptTokens ?? (usage.inputTokens ?? 0) + (usage.cacheReadTokens ?? 0) + (usage.cacheWrite1hTokens ?? 0) + (usage.cacheWrite5mTokens ?? 0);
|
|
19914
|
+
}
|
|
20792
19915
|
function costOf(price, usage) {
|
|
20793
19916
|
const metered = [
|
|
20794
19917
|
[usage.cacheWrite1hTokens ?? 0, price.cacheWrite1h],
|
|
20795
19918
|
[usage.cacheWrite5mTokens ?? 0, price.cacheWrite5m],
|
|
20796
19919
|
[usage.cacheReadTokens ?? 0, price.cacheRead]
|
|
20797
19920
|
];
|
|
20798
|
-
const band = price.longContext !== null && (usage
|
|
19921
|
+
const band = price.longContext !== null && promptTokensOf(usage) > price.longContext.thresholdInputTokens ? price.longContext : null;
|
|
20799
19922
|
if (band !== null && (band.input === null || band.output === null)) return null;
|
|
20800
19923
|
const inputRate = band?.input ?? price.input;
|
|
20801
19924
|
const outputRate = band?.output ?? price.output;
|
|
@@ -20868,8 +19991,8 @@ var PLATFORM_HOSTING = /* @__PURE__ */ new Map([
|
|
|
20868
19991
|
["ollama", "local"],
|
|
20869
19992
|
["local", "local"]
|
|
20870
19993
|
]);
|
|
20871
|
-
function hostingFor(
|
|
20872
|
-
return PLATFORM_HOSTING.get(
|
|
19994
|
+
function hostingFor(platform) {
|
|
19995
|
+
return PLATFORM_HOSTING.get(platform) ?? "api";
|
|
20873
19996
|
}
|
|
20874
19997
|
var FIRST_PARTY = /* @__PURE__ */ new Map([
|
|
20875
19998
|
["anthropic", "anthropic"],
|
|
@@ -20883,8 +20006,8 @@ var FIRST_PARTY = /* @__PURE__ */ new Map([
|
|
|
20883
20006
|
function firstPartyPlatformFor(vendor2) {
|
|
20884
20007
|
return FIRST_PARTY.get(vendor2) ?? null;
|
|
20885
20008
|
}
|
|
20886
|
-
function isFirstParty(vendor2,
|
|
20887
|
-
return FIRST_PARTY.get(vendor2) ===
|
|
20009
|
+
function isFirstParty(vendor2, platform) {
|
|
20010
|
+
return FIRST_PARTY.get(vendor2) === platform;
|
|
20888
20011
|
}
|
|
20889
20012
|
var PLATFORM_NAMESPACES = Object.freeze([
|
|
20890
20013
|
"anthropic",
|
|
@@ -20945,14 +20068,14 @@ var ModelVendorBuilder = class {
|
|
|
20945
20068
|
);
|
|
20946
20069
|
}
|
|
20947
20070
|
for (const ref of spec.on ?? []) {
|
|
20948
|
-
const { platform
|
|
20949
|
-
const firstParty = isFirstParty(this.vendor,
|
|
20950
|
-
const hosting = hostingFor(
|
|
20071
|
+
const { platform, price, retention, region } = normalizeRef(ref);
|
|
20072
|
+
const firstParty = isFirstParty(this.vendor, platform);
|
|
20073
|
+
const hosting = hostingFor(platform);
|
|
20951
20074
|
const isSelfHosted = hosting === "local";
|
|
20952
20075
|
platforms.set(
|
|
20953
|
-
|
|
20076
|
+
platform,
|
|
20954
20077
|
Object.freeze({
|
|
20955
|
-
platform
|
|
20078
|
+
platform,
|
|
20956
20079
|
hosting,
|
|
20957
20080
|
firstParty,
|
|
20958
20081
|
price: price ?? (isSelfHosted ? ZERO_PRICE : firstParty ? spec.price ?? null : null),
|
|
@@ -21005,35 +20128,35 @@ var GATEWAY_VENDOR_SLASH_RE = /^[a-z0-9][\w.-]*\//iu;
|
|
|
21005
20128
|
var BEDROCK_VERSION_RE = /-v\d+:\d+$/u;
|
|
21006
20129
|
var BEDROCK_REVISION_RE = /:\d+$/u;
|
|
21007
20130
|
var VERTEX_VERSION_RE = /@[\w-]+$/u;
|
|
21008
|
-
var DATED_SUFFIX_RE =
|
|
20131
|
+
var DATED_SUFFIX_RE = /-(?:\d{8}|\d{4}-\d{2}-\d{2})$/u;
|
|
21009
20132
|
function stripPlatformDecorations(model) {
|
|
21010
20133
|
let id = model.trim();
|
|
21011
|
-
let
|
|
20134
|
+
let platform = null;
|
|
21012
20135
|
if (GEO_PREFIX_RE.test(id)) {
|
|
21013
20136
|
id = id.replace(GEO_PREFIX_RE, "");
|
|
21014
|
-
|
|
20137
|
+
platform = "bedrock";
|
|
21015
20138
|
}
|
|
21016
20139
|
if (NAMESPACE_DOT_RE.test(id)) {
|
|
21017
20140
|
id = id.replace(NAMESPACE_DOT_RE, "");
|
|
21018
|
-
|
|
20141
|
+
platform ??= "bedrock";
|
|
21019
20142
|
}
|
|
21020
20143
|
if (BEDROCK_VERSION_RE.test(id)) {
|
|
21021
20144
|
id = id.replace(BEDROCK_VERSION_RE, "");
|
|
21022
|
-
|
|
20145
|
+
platform ??= "bedrock";
|
|
21023
20146
|
} else if (BEDROCK_REVISION_RE.test(id)) {
|
|
21024
20147
|
id = id.replace(BEDROCK_REVISION_RE, "");
|
|
21025
|
-
|
|
20148
|
+
platform ??= "bedrock";
|
|
21026
20149
|
}
|
|
21027
20150
|
if (VERTEX_VERSION_RE.test(id)) {
|
|
21028
20151
|
id = id.replace(VERTEX_VERSION_RE, "");
|
|
21029
|
-
|
|
20152
|
+
platform ??= "vertex";
|
|
21030
20153
|
}
|
|
21031
20154
|
if (NAMESPACE_SLASH_RE.test(id)) {
|
|
21032
20155
|
id = id.replace(NAMESPACE_SLASH_RE, "");
|
|
21033
20156
|
} else if (GATEWAY_VENDOR_SLASH_RE.test(id)) {
|
|
21034
20157
|
id = id.replace(GATEWAY_VENDOR_SLASH_RE, "");
|
|
21035
20158
|
}
|
|
21036
|
-
return { id, platform
|
|
20159
|
+
return { id, platform };
|
|
21037
20160
|
}
|
|
21038
20161
|
function buildModelIndex(entries) {
|
|
21039
20162
|
const byId = /* @__PURE__ */ new Map();
|
|
@@ -21050,19 +20173,19 @@ function resolveModel(raw, index) {
|
|
|
21050
20173
|
if (exact !== void 0) {
|
|
21051
20174
|
return { entry: exact, canonicalId: raw, platform: null, raw };
|
|
21052
20175
|
}
|
|
21053
|
-
const { id, platform
|
|
20176
|
+
const { id, platform } = stripPlatformDecorations(raw);
|
|
21054
20177
|
const stripped = index.byId.get(id);
|
|
21055
20178
|
if (stripped !== void 0) {
|
|
21056
|
-
return { entry: stripped, canonicalId: id, platform
|
|
20179
|
+
return { entry: stripped, canonicalId: id, platform, raw };
|
|
21057
20180
|
}
|
|
21058
20181
|
if (DATED_SUFFIX_RE.test(id)) {
|
|
21059
20182
|
const undated = id.replace(DATED_SUFFIX_RE, "");
|
|
21060
20183
|
const byDate = index.byId.get(undated);
|
|
21061
20184
|
if (byDate !== void 0) {
|
|
21062
|
-
return { entry: byDate, canonicalId: undated, platform
|
|
20185
|
+
return { entry: byDate, canonicalId: undated, platform, raw };
|
|
21063
20186
|
}
|
|
21064
20187
|
}
|
|
21065
|
-
return { entry: null, canonicalId: raw, platform
|
|
20188
|
+
return { entry: null, canonicalId: raw, platform, raw };
|
|
21066
20189
|
}
|
|
21067
20190
|
|
|
21068
20191
|
// ../../packages/schema/src/model/catalog.ts
|
|
@@ -21155,7 +20278,7 @@ anthropic.model("claude-haiku-4-5", {
|
|
|
21155
20278
|
name: "Claude Haiku 4.5",
|
|
21156
20279
|
ctx: 2e5,
|
|
21157
20280
|
maxOut: 64e3,
|
|
21158
|
-
// Reviewed: fast/cheap tier,
|
|
20281
|
+
// Reviewed: fast/cheap general-purpose tier, not a reasoning or code model.
|
|
21159
20282
|
capability: null,
|
|
21160
20283
|
price: anthropicPrice(1, 5, 0.1),
|
|
21161
20284
|
// The vendor documents `claude-haiku-4-5-20251001` as the versioned id and
|
|
@@ -21286,6 +20409,11 @@ openai.model("gpt-4o", {
|
|
|
21286
20409
|
price: tokenPrice(2.5, 10, { cacheRead: 1.25 }),
|
|
21287
20410
|
on: [...OPENAI_RESELLERS]
|
|
21288
20411
|
});
|
|
20412
|
+
openai.model("gpt-4o-2024-05-13", {
|
|
20413
|
+
name: "GPT-4o (2024-05-13)",
|
|
20414
|
+
price: tokenPrice(5, 15),
|
|
20415
|
+
on: [...OPENAI_RESELLERS]
|
|
20416
|
+
});
|
|
21289
20417
|
openai.model("gpt-4o-mini", {
|
|
21290
20418
|
name: "GPT-4o mini",
|
|
21291
20419
|
price: tokenPrice(0.15, 0.6, { cacheRead: 0.075 }),
|
|
@@ -21305,6 +20433,24 @@ openai.model("o3", {
|
|
|
21305
20433
|
price: tokenPrice(2, 8, { cacheRead: 0.5 }),
|
|
21306
20434
|
on: [...OPENAI_RESELLERS]
|
|
21307
20435
|
});
|
|
20436
|
+
openai.model("text-embedding-3-small", {
|
|
20437
|
+
name: "text-embedding-3-small",
|
|
20438
|
+
capability: "embedding",
|
|
20439
|
+
price: tokenPrice(0.02, 0),
|
|
20440
|
+
on: [...OPENAI_RESELLERS]
|
|
20441
|
+
});
|
|
20442
|
+
openai.model("text-embedding-3-large", {
|
|
20443
|
+
name: "text-embedding-3-large",
|
|
20444
|
+
capability: "embedding",
|
|
20445
|
+
price: tokenPrice(0.13, 0),
|
|
20446
|
+
on: [...OPENAI_RESELLERS]
|
|
20447
|
+
});
|
|
20448
|
+
openai.model("text-embedding-ada-002", {
|
|
20449
|
+
name: "text-embedding-ada-002",
|
|
20450
|
+
capability: "embedding",
|
|
20451
|
+
price: tokenPrice(0.1, 0),
|
|
20452
|
+
on: [...OPENAI_RESELLERS]
|
|
20453
|
+
});
|
|
21308
20454
|
openai.model("gpt-oss-120b", {
|
|
21309
20455
|
name: "GPT-OSS 120B",
|
|
21310
20456
|
openWeights: true,
|
|
@@ -21591,10 +20737,21 @@ var MODEL_ENTRIES = Object.freeze([
|
|
|
21591
20737
|
...alibaba.models(),
|
|
21592
20738
|
...amazon.models()
|
|
21593
20739
|
]);
|
|
20740
|
+
var LONG_CONTEXT_THRESHOLDS = Object.freeze(
|
|
20741
|
+
[
|
|
20742
|
+
...new Set(
|
|
20743
|
+
MODEL_ENTRIES.flatMap(
|
|
20744
|
+
(entry) => [...entry.platforms.values()].flatMap(
|
|
20745
|
+
(offering) => offering.price?.longContext ? [offering.price.longContext.thresholdInputTokens] : []
|
|
20746
|
+
)
|
|
20747
|
+
)
|
|
20748
|
+
)
|
|
20749
|
+
].sort((a, b) => a - b)
|
|
20750
|
+
);
|
|
21594
20751
|
var MODEL_INDEX = buildModelIndex(MODEL_ENTRIES);
|
|
21595
20752
|
|
|
21596
20753
|
// ../../packages/schema/src/model/governance.ts
|
|
21597
|
-
var ModelCapability = external_exports.enum(["reasoning", "code"]);
|
|
20754
|
+
var ModelCapability = external_exports.enum(["reasoning", "code", "embedding"]);
|
|
21598
20755
|
var DataRetention = external_exports.enum([
|
|
21599
20756
|
"zero_retention",
|
|
21600
20757
|
"no_storage",
|
|
@@ -21784,16 +20941,16 @@ function platformForProvider(provider) {
|
|
|
21784
20941
|
return PROVIDER_PLATFORM.get(provider.trim().toLowerCase()) ?? null;
|
|
21785
20942
|
}
|
|
21786
20943
|
function isLocalProvider(provider) {
|
|
21787
|
-
const
|
|
21788
|
-
return
|
|
20944
|
+
const platform = platformForProvider(provider);
|
|
20945
|
+
return platform !== null && hostingFor(platform) === "local";
|
|
21789
20946
|
}
|
|
21790
20947
|
function priceFor(provider, model) {
|
|
21791
20948
|
if (isLocalProvider(provider)) return ZERO_PRICE;
|
|
21792
20949
|
const resolved = resolveModel(model, MODEL_INDEX);
|
|
21793
20950
|
if (resolved.entry === null) return null;
|
|
21794
|
-
const
|
|
21795
|
-
if (
|
|
21796
|
-
return resolved.entry.platforms.get(
|
|
20951
|
+
const platform = resolved.platform ?? platformForProvider(provider);
|
|
20952
|
+
if (platform === null) return null;
|
|
20953
|
+
return resolved.entry.platforms.get(platform)?.price ?? null;
|
|
21797
20954
|
}
|
|
21798
20955
|
var defaultCostModel = {
|
|
21799
20956
|
normalizeModelId(provider, model) {
|
|
@@ -21825,7 +20982,7 @@ function formatCostTotal(estimatedCostUsd, costIsPartial) {
|
|
|
21825
20982
|
|
|
21826
20983
|
// ../../packages/schema/src/token/token-report.ts
|
|
21827
20984
|
var num = (value) => value ?? 0;
|
|
21828
|
-
function costUsageOf(a) {
|
|
20985
|
+
function costUsageOf(a, promptTokens) {
|
|
21829
20986
|
const usage = {
|
|
21830
20987
|
inputTokens: num(a.input_tokens),
|
|
21831
20988
|
outputTokens: num(a.output_tokens),
|
|
@@ -21835,11 +20992,12 @@ function costUsageOf(a) {
|
|
|
21835
20992
|
webSearchRequests: num(a.web_search_requests)
|
|
21836
20993
|
};
|
|
21837
20994
|
if (a.service_tier !== void 0) usage.serviceTier = a.service_tier;
|
|
20995
|
+
if (promptTokens !== void 0) usage.promptTokens = promptTokens;
|
|
21838
20996
|
return usage;
|
|
21839
20997
|
}
|
|
21840
20998
|
function buildTokenReports(leaves, costModel) {
|
|
21841
20999
|
const bySession = /* @__PURE__ */ new Map();
|
|
21842
|
-
for (const { sessionId, attributes } of leaves) {
|
|
21000
|
+
for (const { sessionId, attributes, promptTokens } of leaves) {
|
|
21843
21001
|
const provider = attributes.provider ?? "unknown";
|
|
21844
21002
|
const model = attributes.model ?? "unknown";
|
|
21845
21003
|
const key = `${provider} ${model}`;
|
|
@@ -21858,7 +21016,8 @@ function buildTokenReports(leaves, costModel) {
|
|
|
21858
21016
|
cacheCreation: 0,
|
|
21859
21017
|
cacheRead: 0,
|
|
21860
21018
|
costUsd: 0,
|
|
21861
|
-
priced: false
|
|
21019
|
+
priced: false,
|
|
21020
|
+
partial: false
|
|
21862
21021
|
};
|
|
21863
21022
|
rollups.set(key, acc);
|
|
21864
21023
|
}
|
|
@@ -21866,8 +21025,14 @@ function buildTokenReports(leaves, costModel) {
|
|
|
21866
21025
|
acc.output += num(attributes.output_tokens);
|
|
21867
21026
|
acc.cacheCreation += num(attributes.cache_creation_input_tokens);
|
|
21868
21027
|
acc.cacheRead += num(attributes.cache_read_input_tokens);
|
|
21869
|
-
const leafCost = costModel.costFor({
|
|
21870
|
-
|
|
21028
|
+
const leafCost = costModel.costFor({
|
|
21029
|
+
provider,
|
|
21030
|
+
model,
|
|
21031
|
+
usage: costUsageOf(attributes, promptTokens)
|
|
21032
|
+
});
|
|
21033
|
+
if (leafCost === null) {
|
|
21034
|
+
acc.partial = true;
|
|
21035
|
+
} else {
|
|
21871
21036
|
acc.costUsd += leafCost;
|
|
21872
21037
|
acc.priced = true;
|
|
21873
21038
|
}
|
|
@@ -21883,9 +21048,8 @@ function buildTokenReports(leaves, costModel) {
|
|
|
21883
21048
|
const rollupTotal = acc.input + acc.output + acc.cacheCreation + acc.cacheRead;
|
|
21884
21049
|
totalTokens += rollupTotal;
|
|
21885
21050
|
const estimatedCostUsd = acc.priced ? acc.costUsd : null;
|
|
21886
|
-
if (
|
|
21887
|
-
|
|
21888
|
-
} else {
|
|
21051
|
+
if (acc.partial) anyUnpriced = true;
|
|
21052
|
+
if (estimatedCostUsd !== null) {
|
|
21889
21053
|
anyPriced = true;
|
|
21890
21054
|
costUsd += estimatedCostUsd;
|
|
21891
21055
|
}
|
|
@@ -21908,7 +21072,7 @@ function buildTokenReports(leaves, costModel) {
|
|
|
21908
21072
|
totalTokens,
|
|
21909
21073
|
// Σ of the PRICED rollups; null when none had a known price.
|
|
21910
21074
|
estimatedCostUsd: anyPriced ? costUsd : null,
|
|
21911
|
-
// Any
|
|
21075
|
+
// Any call priced to null means the total understates real spend.
|
|
21912
21076
|
costIsPartial: anyUnpriced
|
|
21913
21077
|
});
|
|
21914
21078
|
}
|
|
@@ -22664,6 +21828,11 @@ var CaptureAttributes = external_exports.object({
|
|
|
22664
21828
|
// here too. The full statement is on EventMetadata.redactDegradedTo; it is
|
|
22665
21829
|
// repeated rather than referenced because a store reader opens this file.
|
|
22666
21830
|
redact_degraded_to: ActionTaken.optional(),
|
|
21831
|
+
// Why a capture has no content and no findings: its field was refused
|
|
21832
|
+
// because its bounded scan did not finish (see EventMetadata.scanIncomplete,
|
|
21833
|
+
// whose value this is). Absent on every capture that was scanned, so a
|
|
21834
|
+
// reader can tell a refused row from an empty clean one.
|
|
21835
|
+
scan_incomplete: external_exports.enum(["timeout", "unavailable"]).optional(),
|
|
22667
21836
|
// The scope key this capture was stamped with: the canonical repository
|
|
22668
21837
|
// (`host/owner/repo`) of the path the capture names (a relative path is read
|
|
22669
21838
|
// against its working directory), else of its own working directory, or a
|
|
@@ -22841,8 +22010,9 @@ var SessionTokenReport = external_exports.object({
|
|
|
22841
22010
|
totalTokens: external_exports.number().int().nonnegative(),
|
|
22842
22011
|
// Σ of the PRICED rollups only; null when no rollup had a known price.
|
|
22843
22012
|
estimatedCostUsd: external_exports.number().nullable(),
|
|
22844
|
-
// True whenever any
|
|
22845
|
-
//
|
|
22013
|
+
// True whenever any call priced to null (an unknown provider/model, or a call
|
|
22014
|
+
// over a long-context threshold whose rate is unpublished), so the total
|
|
22015
|
+
// understates real spend — the UI renders `≥ $X` instead of a falsely
|
|
22846
22016
|
// precise figure rather than silently dropping the unpriced calls.
|
|
22847
22017
|
costIsPartial: external_exports.boolean()
|
|
22848
22018
|
});
|
|
@@ -23719,7 +22889,15 @@ var StorePostureSnapshot = external_exports.object({
|
|
|
23719
22889
|
policyCounts: StorePosturePolicyCounts,
|
|
23720
22890
|
// OPTIONAL, not nullable: a reporter that predates this member keeps
|
|
23721
22891
|
// getting its 200 without a payload change.
|
|
23722
|
-
plugin: StorePosturePlugin.optional()
|
|
22892
|
+
plugin: StorePosturePlugin.optional(),
|
|
22893
|
+
// OPTIONAL, and sent only by a scoped attachment, always as `scoped`. A
|
|
22894
|
+
// machine attachment omits it, so its body is byte for byte the one it
|
|
22895
|
+
// sent before this member existed. Absent therefore means machine-wide OR
|
|
22896
|
+
// a reporter older than this member, never "scoped". Both values parse, so
|
|
22897
|
+
// a sender that one day spells `machine` breaks no receiver; any other
|
|
22898
|
+
// value fails the whole snapshot, which is why the reporter sends a
|
|
22899
|
+
// constant and never the raw mode.
|
|
22900
|
+
attachmentMode: AttachmentMode.optional()
|
|
23723
22901
|
}).meta({ id: "StorePostureSnapshot" });
|
|
23724
22902
|
var CAPTURE_VERSION_PREFIX = "capture/";
|
|
23725
22903
|
var RecordAuditEventRequest = AuditEventInput.extend({
|
|
@@ -23996,7 +23174,19 @@ var EventMetadata = external_exports.object({
|
|
|
23996
23174
|
// Both are pinned as behaviour in @akasecurity/plugin-sdk's runtime suite.
|
|
23997
23175
|
// Closing either means moving the reason onto the finding row, which
|
|
23998
23176
|
// already carries its own action.
|
|
23999
|
-
redactDegradedTo: ActionTaken.optional()
|
|
23177
|
+
redactDegradedTo: ActionTaken.optional(),
|
|
23178
|
+
// Set when this capture's field was REFUSED rather than scanned: a hook
|
|
23179
|
+
// bounds the scan of a large field (see `LargeInputScanOptions` in
|
|
23180
|
+
// @akasecurity/plugin-sdk), and a scan that did not finish blocks the
|
|
23181
|
+
// field instead of letting it through unscanned.
|
|
23182
|
+
//
|
|
23183
|
+
// - 'timeout': the bounded scan ran out of time.
|
|
23184
|
+
// - 'unavailable': no worker could run it.
|
|
23185
|
+
//
|
|
23186
|
+
// A refused row stores '' as its content and has no findings, which is
|
|
23187
|
+
// exactly what a clean, empty capture looks like — this marker is the only
|
|
23188
|
+
// thing that tells the two apart. Absent on every capture that was scanned.
|
|
23189
|
+
scanIncomplete: external_exports.enum(["timeout", "unavailable"]).optional()
|
|
24000
23190
|
}).meta({ id: "EventMetadata" });
|
|
24001
23191
|
var Event = external_exports.object({
|
|
24002
23192
|
id: external_exports.guid(),
|
|
@@ -24166,7 +23356,7 @@ var Rule = external_exports.strictObject({
|
|
|
24166
23356
|
postValidators: external_exports.array(PostValidatorRef).optional(),
|
|
24167
23357
|
requiresNearby: RequiresNearby.optional(),
|
|
24168
23358
|
examples: external_exports.array(external_exports.string()).optional(),
|
|
24169
|
-
// Whether the matched text is itself sensitive
|
|
23359
|
+
// Whether the matched text is itself sensitive (see RuleEvidence).
|
|
24170
23360
|
evidence: RuleEvidence.optional()
|
|
24171
23361
|
}).meta({ id: "Rule" });
|
|
24172
23362
|
var Author = external_exports.object({
|
|
@@ -24258,7 +23448,13 @@ var DetectionRule = external_exports.object({
|
|
|
24258
23448
|
// Representative matching strings the rule author shipped with the rule. The
|
|
24259
23449
|
// cheapest honest answer to "show me what this rule catches" — every bundled
|
|
24260
23450
|
// rule has them, and they are already in the stored snapshot.
|
|
24261
|
-
examples: external_exports.array(external_exports.string()).optional()
|
|
23451
|
+
examples: external_exports.array(external_exports.string()).optional(),
|
|
23452
|
+
// The rule's DECLARED evidence, as stored. Absent defers to the engine's
|
|
23453
|
+
// classification (ruleEvidence in @akasecurity/detections): a bundled
|
|
23454
|
+
// code-flaw rule reads as 'code' and anything else as 'value', and a rule
|
|
23455
|
+
// in a value category (secret/pii/financial/phi) is always 'value',
|
|
23456
|
+
// whatever it declares.
|
|
23457
|
+
evidence: RuleEvidence.optional()
|
|
24262
23458
|
}).meta({ id: "DetectionRule" });
|
|
24263
23459
|
var DetectionUpdate = external_exports.object({
|
|
24264
23460
|
available: external_exports.boolean(),
|
|
@@ -24326,8 +23522,10 @@ var ImportDetectionRequest = external_exports.object({
|
|
|
24326
23522
|
}).meta({ id: "ImportDetectionRequest" });
|
|
24327
23523
|
|
|
24328
23524
|
// ../../packages/schema/src/zod/detection-build.ts
|
|
24329
|
-
function optional2(key,
|
|
24330
|
-
if (raw === void 0
|
|
23525
|
+
function optional2(key, raw, parse4) {
|
|
23526
|
+
if (raw === void 0) return {};
|
|
23527
|
+
const parsed2 = parse4(raw);
|
|
23528
|
+
if (!parsed2.success || parsed2.data === void 0) return {};
|
|
24331
23529
|
return { [key]: parsed2.data };
|
|
24332
23530
|
}
|
|
24333
23531
|
function isStringArray(value) {
|
|
@@ -24362,10 +23560,12 @@ function rowToDetectionDetail(row, findingsLast30d, update) {
|
|
|
24362
23560
|
category: r.category,
|
|
24363
23561
|
severity: r.severity,
|
|
24364
23562
|
matcher: parsed2.data,
|
|
24365
|
-
//
|
|
24366
|
-
//
|
|
24367
|
-
//
|
|
24368
|
-
//
|
|
23563
|
+
// `appliesTo`, `postValidators` and `requiresNearby` are the rest of what
|
|
23564
|
+
// decides whether this rule fires. Carried so a consumer re-running the
|
|
23565
|
+
// rule (a preview, a tester) evaluates what the engine evaluates rather
|
|
23566
|
+
// than a matcher stripped of its guards — half the bundled catalog
|
|
23567
|
+
// carries at least one of these. `examples` and `evidence` describe the
|
|
23568
|
+
// rule and never gate a match.
|
|
24369
23569
|
//
|
|
24370
23570
|
// Enrichment is deliberately per-field and best-effort, NOT a whole-rule
|
|
24371
23571
|
// `Rule.safeParse`. Two reasons: `Rule` is a strict object pinned to
|
|
@@ -24375,18 +23575,19 @@ function rowToDetectionDetail(row, findingsLast30d, update) {
|
|
|
24375
23575
|
// test should stay exactly what it was, namely a renderable matcher. A
|
|
24376
23576
|
// field that fails validation is omitted, which reads as "not set" and is
|
|
24377
23577
|
// the same thing the consumer saw before this change.
|
|
24378
|
-
...optional2("appliesTo",
|
|
23578
|
+
...optional2("appliesTo", r.appliesTo, (v) => AppliesTo.safeParse(v)),
|
|
24379
23579
|
...optional2(
|
|
24380
23580
|
"postValidators",
|
|
24381
|
-
|
|
24382
|
-
|
|
23581
|
+
r.postValidators,
|
|
23582
|
+
(v) => PostValidatorRef.array().safeParse(v)
|
|
24383
23583
|
),
|
|
24384
|
-
...optional2("requiresNearby",
|
|
23584
|
+
...optional2("requiresNearby", r.requiresNearby, (v) => RequiresNearby.safeParse(v)),
|
|
24385
23585
|
...optional2(
|
|
24386
23586
|
"examples",
|
|
24387
|
-
|
|
24388
|
-
|
|
24389
|
-
)
|
|
23587
|
+
r.examples,
|
|
23588
|
+
(v) => isStringArray(v) ? { success: true, data: v } : { success: false }
|
|
23589
|
+
),
|
|
23590
|
+
...optional2("evidence", r.evidence, (v) => RuleEvidence.safeParse(v))
|
|
24390
23591
|
}
|
|
24391
23592
|
];
|
|
24392
23593
|
});
|
|
@@ -25079,11 +24280,14 @@ var PolicyBundle = external_exports.object({
|
|
|
25079
24280
|
ruleVersions: external_exports.record(external_exports.string(), external_exports.string()).optional(),
|
|
25080
24281
|
// Model ids (the raw `model` string a harness reports, e.g.
|
|
25081
24282
|
// `claude-opus-4-1`) the tenant has PROHIBITED. The plugin refuses to switch
|
|
25082
|
-
// a session onto one (PreModelSwitch)
|
|
25083
|
-
//
|
|
25084
|
-
//
|
|
25085
|
-
//
|
|
25086
|
-
//
|
|
24283
|
+
// a session onto one (PreModelSwitch), refuses a turn that would run on one
|
|
24284
|
+
// (UserPromptSubmit) and refuses a subagent spawn onto one (PreToolUse),
|
|
24285
|
+
// wherever the organization governs the event: everywhere on a
|
|
24286
|
+
// machine-wide attachment, and only in enrolled repositories on a scoped
|
|
24287
|
+
// one (the plugin runtime's `governanceApplies`).
|
|
24288
|
+
// Optional so an older backend — and an older on-disk cache — still
|
|
24289
|
+
// parses; consumers read `?? []`, which is the unenforced behaviour that
|
|
24290
|
+
// predates this field and the safe direction to default.
|
|
25087
24291
|
//
|
|
25088
24292
|
// Ids, not display names: the governance decision is keyed on the exact
|
|
25089
24293
|
// string the harness reports (`model_status_override.versionId` in the
|
|
@@ -25539,6 +24743,8 @@ var AttachmentScopeEntry = external_exports.object({
|
|
|
25539
24743
|
});
|
|
25540
24744
|
var AttachmentScope = external_exports.object({
|
|
25541
24745
|
endpoint: external_exports.string().min(1),
|
|
24746
|
+
tenantName: PluginWhoami.shape.tenantName.optional(),
|
|
24747
|
+
userEmail: PluginWhoami.shape.userEmail.optional(),
|
|
25542
24748
|
entries: external_exports.array(AttachmentScopeEntry)
|
|
25543
24749
|
});
|
|
25544
24750
|
var AttachmentScopeEnvelope = AttachmentScope.extend({ entries: external_exports.array(external_exports.unknown()) });
|
|
@@ -25551,7 +24757,13 @@ function parseAttachmentScope(raw) {
|
|
|
25551
24757
|
const entry = AttachmentScopeEntry.safeParse(candidate);
|
|
25552
24758
|
if (entry.success) entries.push(entry.data);
|
|
25553
24759
|
}
|
|
25554
|
-
|
|
24760
|
+
const { endpoint, tenantName, userEmail } = envelope.data;
|
|
24761
|
+
return {
|
|
24762
|
+
endpoint,
|
|
24763
|
+
...tenantName === void 0 ? {} : { tenantName },
|
|
24764
|
+
...userEmail === void 0 ? {} : { userEmail },
|
|
24765
|
+
entries
|
|
24766
|
+
};
|
|
25555
24767
|
} catch {
|
|
25556
24768
|
return void 0;
|
|
25557
24769
|
}
|
|
@@ -25795,6 +25007,7 @@ function toCaptureAttributes(event) {
|
|
|
25795
25007
|
...metadata?.exceptionIds !== void 0 ? { exception_ids: metadata.exceptionIds } : {},
|
|
25796
25008
|
...metadata?.inspectionMs !== void 0 ? { inspection_ms: metadata.inspectionMs } : {},
|
|
25797
25009
|
...metadata?.redactDegradedTo !== void 0 ? { redact_degraded_to: metadata.redactDegradedTo } : {},
|
|
25010
|
+
...metadata?.scanIncomplete !== void 0 ? { scan_incomplete: metadata.scanIncomplete } : {},
|
|
25798
25011
|
// `model`/`turnIndex` have no dedicated CaptureAttributes field (no writer
|
|
25799
25012
|
// has ever populated either), but every legacy metadata key still rides
|
|
25800
25013
|
// the bag rather than being silently dropped — CaptureAttributes'
|
|
@@ -25923,6 +25136,27 @@ var ManagedSettings = external_exports.object({
|
|
|
25923
25136
|
};
|
|
25924
25137
|
}).meta({ id: "ManagedSettings" });
|
|
25925
25138
|
|
|
25139
|
+
// ../../packages/schema/src/zod/mod-policy-snapshot.ts
|
|
25140
|
+
var MOD_POLICY_SNAPSHOT_VERSION = 1;
|
|
25141
|
+
var MOD_POLICY_SNAPSHOT_MAX_BYTES = 4 * 1024 * 1024;
|
|
25142
|
+
var ModPolicySnapshot = external_exports.object({
|
|
25143
|
+
version: external_exports.literal(MOD_POLICY_SNAPSHOT_VERSION),
|
|
25144
|
+
generatedAt: external_exports.iso.datetime(),
|
|
25145
|
+
// The complete effective ruleset, as the hook's runtime scans with it: the
|
|
25146
|
+
// user's enabled installed packs (user-modified and custom packs included).
|
|
25147
|
+
// Absent means the store holds no authoritative snapshot, and the reader
|
|
25148
|
+
// scans with the packs it ships — the hook's own fallback.
|
|
25149
|
+
rules: external_exports.array(Rule).optional(),
|
|
25150
|
+
// Rule-targeted actions (first enabled policy per rule wins).
|
|
25151
|
+
ruleActions: external_exports.record(external_exports.string(), ActionTaken),
|
|
25152
|
+
// The resolved action per detection category.
|
|
25153
|
+
categoryActions: external_exports.record(external_exports.string(), ActionTaken),
|
|
25154
|
+
// Rules with an active exception grant. Honouring a grant means matching a
|
|
25155
|
+
// keyed fingerprint of the value and consuming a use, which only the hook can
|
|
25156
|
+
// do, so the mod leaves a finding of one of these rules for the hook to decide.
|
|
25157
|
+
exceptionRuleIds: external_exports.array(external_exports.string())
|
|
25158
|
+
}).meta({ id: "ModPolicySnapshot" });
|
|
25159
|
+
|
|
25926
25160
|
// ../../packages/schema/src/zod/project-files.ts
|
|
25927
25161
|
var ProjectFileInput = external_exports.object({
|
|
25928
25162
|
path: external_exports.string().min(1),
|
|
@@ -26243,7 +25477,16 @@ var AttachInput = external_exports.object({
|
|
|
26243
25477
|
// 200 matches the tenantName bound beside it in control-plane.ts; nothing
|
|
26244
25478
|
// renders a longer one usefully.
|
|
26245
25479
|
label: printable(200).optional(),
|
|
26246
|
-
accessKey: external_exports.string()
|
|
25480
|
+
accessKey: external_exports.string(),
|
|
25481
|
+
// How much of this machine the attachment is for: everything, or only the
|
|
25482
|
+
// repositories its user enrolls. Optional, so an input without it still
|
|
25483
|
+
// parses; what an absent mode means is for whatever reads it to decide, not
|
|
25484
|
+
// this shape. This member validates the VALUE rather than leaving that to the
|
|
25485
|
+
// call site, a deliberate exception to this module's shape-only rule: a shape
|
|
25486
|
+
// rejection names the field, so a value that is not a mode is refused as a bad
|
|
25487
|
+
// `mode` rather than stripped or passed on. The dashboard's attach action reads
|
|
25488
|
+
// it as the mode to attach in.
|
|
25489
|
+
mode: AttachmentMode.optional()
|
|
26247
25490
|
});
|
|
26248
25491
|
|
|
26249
25492
|
// ../../packages/schema/src/zod/triage.ts
|
|
@@ -26529,6 +25772,18 @@ function fromCaptureStatusAttributes(bag) {
|
|
|
26529
25772
|
return parsedStatus.success ? parsedStatus.data : null;
|
|
26530
25773
|
}
|
|
26531
25774
|
|
|
25775
|
+
// ../../packages/persistence/src/attached-derived.ts
|
|
25776
|
+
import { rmSync } from "fs";
|
|
25777
|
+
import { join } from "path";
|
|
25778
|
+
var POLICY_CACHE_FILENAME = "policy-cache.json";
|
|
25779
|
+
var ATTACHED_FORWARD_STATE_FILENAME = "attached-state.json";
|
|
25780
|
+
var ATTACHED_FORWARD_DROPS_FILENAME = "attached-forward-drops.json";
|
|
25781
|
+
var ATTACHED_POSTURE_REPORT_FILENAME = "attached-posture-report.json";
|
|
25782
|
+
|
|
25783
|
+
// ../../packages/persistence/src/control-plane-credential.ts
|
|
25784
|
+
import { chmodSync as chmodSync2, lstatSync as lstatSync2, readFileSync, rmSync as rmSync3, statSync } from "fs";
|
|
25785
|
+
import { join as join2 } from "path";
|
|
25786
|
+
|
|
26532
25787
|
// ../../packages/persistence/src/paths.ts
|
|
26533
25788
|
import {
|
|
26534
25789
|
chmodSync,
|
|
@@ -26655,6 +25910,14 @@ function repairOrRefuseMode(file2) {
|
|
|
26655
25910
|
}
|
|
26656
25911
|
return "ok";
|
|
26657
25912
|
}
|
|
25913
|
+
function asReadableCredential(value) {
|
|
25914
|
+
const result = AttachedCredentialAny.safeParse(value);
|
|
25915
|
+
if (!result.success) return null;
|
|
25916
|
+
if (attachmentModeOf(result.data) === "machine" && typeof value === "object" && value !== null && Object.hasOwn(value, "mode")) {
|
|
25917
|
+
return null;
|
|
25918
|
+
}
|
|
25919
|
+
return result.data;
|
|
25920
|
+
}
|
|
26658
25921
|
function readControlPlaneCredentialFile(settingsDir2, connection) {
|
|
26659
25922
|
const file2 = controlPlaneCredentialPath(settingsDir2);
|
|
26660
25923
|
let raw;
|
|
@@ -26673,20 +25936,20 @@ function readControlPlaneCredentialFile(settingsDir2, connection) {
|
|
|
26673
25936
|
} catch {
|
|
26674
25937
|
return { usable: false, reason: "malformed" };
|
|
26675
25938
|
}
|
|
26676
|
-
const
|
|
26677
|
-
if (
|
|
26678
|
-
if (!isSafeEndpoint(
|
|
25939
|
+
const credential = asReadableCredential(parsed2);
|
|
25940
|
+
if (credential === null) return { usable: false, reason: "malformed" };
|
|
25941
|
+
if (!isSafeEndpoint(credential.endpoint)) {
|
|
26679
25942
|
return { usable: false, reason: "unsafe-endpoint" };
|
|
26680
25943
|
}
|
|
26681
|
-
if (connection !== void 0 && connection.endpoint !==
|
|
25944
|
+
if (connection !== void 0 && connection.endpoint !== credential.endpoint) {
|
|
26682
25945
|
return {
|
|
26683
25946
|
usable: false,
|
|
26684
25947
|
reason: "endpoint-mismatch",
|
|
26685
|
-
credentialEndpoint:
|
|
25948
|
+
credentialEndpoint: credential.endpoint,
|
|
26686
25949
|
settingsEndpoint: connection.endpoint
|
|
26687
25950
|
};
|
|
26688
25951
|
}
|
|
26689
|
-
return { usable: true, credential
|
|
25952
|
+
return { usable: true, credential };
|
|
26690
25953
|
}
|
|
26691
25954
|
function readControlPlaneCredential(settingsDir2, connection) {
|
|
26692
25955
|
const read = readControlPlaneCredentialFile(settingsDir2, connection);
|
|
@@ -26695,7 +25958,7 @@ function readControlPlaneCredential(settingsDir2, connection) {
|
|
|
26695
25958
|
|
|
26696
25959
|
// ../../packages/persistence/src/database.ts
|
|
26697
25960
|
import { randomUUID as randomUUID11 } from "crypto";
|
|
26698
|
-
import { dirname as dirname2, join as
|
|
25961
|
+
import { dirname as dirname2, join as join8, sep } from "path";
|
|
26699
25962
|
import { DatabaseSync } from "node:sqlite";
|
|
26700
25963
|
|
|
26701
25964
|
// ../../packages/persistence/src/ids.ts
|
|
@@ -26739,6 +26002,7 @@ function captureId(sessionId, contentHash, filePath = null) {
|
|
|
26739
26002
|
canonicalIdentity(["capture", sessionId ?? NO_SESSION, contentHash, filePath ?? NO_PATH])
|
|
26740
26003
|
);
|
|
26741
26004
|
}
|
|
26005
|
+
var DOT = ".".charCodeAt(0);
|
|
26742
26006
|
|
|
26743
26007
|
// ../../packages/persistence/src/internal/snapshot.ts
|
|
26744
26008
|
import { randomUUID } from "crypto";
|
|
@@ -27066,6 +26330,25 @@ function scopeKeysParam(scopeKeys) {
|
|
|
27066
26330
|
var ROOT_SCOPE_KEY = `(SELECT session_root.scope_key
|
|
27067
26331
|
FROM audit_events AS session_root
|
|
27068
26332
|
WHERE session_root.id = COALESCE(audit_events.root_session_id, audit_events.id))`;
|
|
26333
|
+
var COUNTED_IN_SCOPE = `
|
|
26334
|
+
AND ${inScope("scope_key")}
|
|
26335
|
+
AND (event_type IN (${CAPTURE_TYPE_LIST}) OR ${inScope(ROOT_SCOPE_KEY)})`;
|
|
26336
|
+
var DRAIN_TOTALS = `SELECT
|
|
26337
|
+
SUM(CASE WHEN synced_at IS NULL AND started_at < :before THEN 1 ELSE 0 END) AS pending,
|
|
26338
|
+
SUM(CASE WHEN synced_at > 0 THEN 1 ELSE 0 END) AS sent,
|
|
26339
|
+
SUM(CASE WHEN synced_at = ${String(SKIPPED)}
|
|
26340
|
+
AND (sync_failure IS NULL OR sync_failure = 'payload_invalid')
|
|
26341
|
+
THEN 1 ELSE 0 END) AS skipped,
|
|
26342
|
+
SUM(CASE WHEN synced_at = ${String(SKIPPED)}
|
|
26343
|
+
AND sync_failure = 'deployment_refused' THEN 1 ELSE 0 END) AS refused,
|
|
26344
|
+
SUM(CASE WHEN synced_at = ${String(SKIPPED)}
|
|
26345
|
+
AND sync_failure = 'detached_undelivered' THEN 1 ELSE 0 END) AS detached
|
|
26346
|
+
FROM audit_events
|
|
26347
|
+
WHERE event_type IN (${TYPE_LIST})`;
|
|
26348
|
+
var CAPTURE_SKIPS = `SELECT COUNT(*) AS skipped
|
|
26349
|
+
FROM audit_events
|
|
26350
|
+
WHERE synced_at = ${String(SKIPPED)}
|
|
26351
|
+
AND event_type IN (${CAPTURE_TYPE_LIST})`;
|
|
27069
26352
|
var ROW_COLUMNS = `id,
|
|
27070
26353
|
parent_id AS parentId,
|
|
27071
26354
|
root_session_id AS rootSessionId,
|
|
@@ -27141,7 +26424,7 @@ var SqliteHistorySyncRepository = class {
|
|
|
27141
26424
|
);
|
|
27142
26425
|
this.scopedCaptureRowsStmt = db.prepare(
|
|
27143
26426
|
`SELECT ${ROW_COLUMNS}
|
|
27144
|
-
FROM audit_events
|
|
26427
|
+
FROM audit_events INDEXED BY idx_audit_scope_owed
|
|
27145
26428
|
WHERE synced_at IS NULL
|
|
27146
26429
|
AND sync_claimed_at IS NULL
|
|
27147
26430
|
AND outbox_owed = 1
|
|
@@ -27194,40 +26477,28 @@ var SqliteHistorySyncRepository = class {
|
|
|
27194
26477
|
);
|
|
27195
26478
|
this.partitionStmt = db.prepare(`SELECT${PARTITION_BUCKETS}
|
|
27196
26479
|
FROM audit_events${COUNTED_SCOPE}`);
|
|
26480
|
+
this.scopedPartitionStmt = db.prepare(`SELECT${PARTITION_BUCKETS}
|
|
26481
|
+
FROM audit_events${COUNTED_SCOPE}${COUNTED_IN_SCOPE}`);
|
|
27197
26482
|
this.partitionByKindStmt = db.prepare(
|
|
27198
26483
|
`SELECT event_type AS kind,${PARTITION_BUCKETS}
|
|
27199
26484
|
FROM audit_events INDEXED BY idx_audit_events_sync${COUNTED_SCOPE}
|
|
27200
26485
|
GROUP BY event_type`
|
|
27201
26486
|
);
|
|
27202
|
-
this.
|
|
27203
|
-
`SELECT
|
|
27204
|
-
|
|
27205
|
-
|
|
27206
|
-
SUM(CASE WHEN synced_at = ${String(SKIPPED)}
|
|
27207
|
-
AND (sync_failure IS NULL OR sync_failure = 'payload_invalid')
|
|
27208
|
-
THEN 1 ELSE 0 END) AS skipped,
|
|
27209
|
-
SUM(CASE WHEN synced_at = ${String(SKIPPED)}
|
|
27210
|
-
AND sync_failure = 'deployment_refused' THEN 1 ELSE 0 END) AS refused,
|
|
27211
|
-
SUM(CASE WHEN synced_at = ${String(SKIPPED)}
|
|
27212
|
-
AND sync_failure = 'detached_undelivered' THEN 1 ELSE 0 END) AS detached
|
|
27213
|
-
FROM audit_events
|
|
27214
|
-
WHERE event_type IN (${TYPE_LIST})`
|
|
26487
|
+
this.scopedPartitionByKindStmt = db.prepare(
|
|
26488
|
+
`SELECT event_type AS kind,${PARTITION_BUCKETS}
|
|
26489
|
+
FROM audit_events INDEXED BY idx_audit_events_sync${COUNTED_SCOPE}${COUNTED_IN_SCOPE}
|
|
26490
|
+
GROUP BY event_type`
|
|
27215
26491
|
);
|
|
27216
|
-
this.
|
|
27217
|
-
|
|
27218
|
-
|
|
27219
|
-
|
|
27220
|
-
|
|
27221
|
-
|
|
27222
|
-
|
|
27223
|
-
|
|
27224
|
-
|
|
27225
|
-
|
|
27226
|
-
// frees.
|
|
27227
|
-
`SELECT COUNT(*) AS skipped
|
|
27228
|
-
FROM audit_events
|
|
27229
|
-
WHERE synced_at = ${String(SKIPPED)}
|
|
27230
|
-
AND event_type IN (${CAPTURE_TYPE_LIST})`
|
|
26492
|
+
this.countsStmt = db.prepare(DRAIN_TOTALS);
|
|
26493
|
+
this.scopedCountsStmt = db.prepare(
|
|
26494
|
+
`${DRAIN_TOTALS}
|
|
26495
|
+
AND ${inScope("scope_key")}
|
|
26496
|
+
AND ${inScope(ROOT_SCOPE_KEY)}`
|
|
26497
|
+
);
|
|
26498
|
+
this.captureSkipCountStmt = db.prepare(CAPTURE_SKIPS);
|
|
26499
|
+
this.scopedCaptureSkipCountStmt = db.prepare(
|
|
26500
|
+
`${CAPTURE_SKIPS}
|
|
26501
|
+
AND ${inScope("scope_key")}`
|
|
27231
26502
|
);
|
|
27232
26503
|
this.fingerprintStmt = db.prepare(
|
|
27233
26504
|
`SELECT endpoint_fingerprint AS fingerprint, backlog_before AS backlogBefore
|
|
@@ -27341,6 +26612,10 @@ var SqliteHistorySyncRepository = class {
|
|
|
27341
26612
|
scopedCaptureRowsStmt;
|
|
27342
26613
|
scopedCaptureBacklogOwedStmt;
|
|
27343
26614
|
markScopeCapturesOwedStmt;
|
|
26615
|
+
scopedPartitionStmt;
|
|
26616
|
+
scopedPartitionByKindStmt;
|
|
26617
|
+
scopedCountsStmt;
|
|
26618
|
+
scopedCaptureSkipCountStmt;
|
|
27344
26619
|
/**
|
|
27345
26620
|
* The masked detections recorded against one tool call.
|
|
27346
26621
|
*
|
|
@@ -27562,7 +26837,29 @@ var SqliteHistorySyncRepository = class {
|
|
|
27562
26837
|
* in" — and a machine that has never attached has no boundary to pass, so
|
|
27563
26838
|
* requiring one would force a caller to invent one and report the whole store
|
|
27564
26839
|
* as queued.
|
|
26840
|
+
*
|
|
26841
|
+
* `scopeKeys` is a scoped attachment's filter: every bucket then counts only
|
|
26842
|
+
* the rows that pass the drain's reachability rule for that scope
|
|
26843
|
+
* (COUNTED_IN_SCOPE, which also names the one kind of row it counts that the
|
|
26844
|
+
* drain never offers), so a personal repository's rows are in none of them.
|
|
26845
|
+
* Omitted, this runs the machine statement, unchanged; an empty list counts
|
|
26846
|
+
* nothing.
|
|
27565
26847
|
*/
|
|
26848
|
+
partition(scopeKeys) {
|
|
26849
|
+
const row = getRow(
|
|
26850
|
+
scopeKeys === void 0 ? this.partitionStmt : this.scopedPartitionStmt,
|
|
26851
|
+
scopeKeys === void 0 ? {} : { scopeKeys: scopeKeysParam(scopeKeys) }
|
|
26852
|
+
);
|
|
26853
|
+
return {
|
|
26854
|
+
queued: row?.queued ?? 0,
|
|
26855
|
+
inProgress: row?.inProgress ?? 0,
|
|
26856
|
+
synced: row?.synced ?? 0,
|
|
26857
|
+
failed: row?.failed ?? 0,
|
|
26858
|
+
refused: row?.refused ?? 0,
|
|
26859
|
+
detached: row?.detached ?? 0,
|
|
26860
|
+
total: row?.total ?? 0
|
|
26861
|
+
};
|
|
26862
|
+
}
|
|
27566
26863
|
/**
|
|
27567
26864
|
* The same partition, one row per kind that a lane carries.
|
|
27568
26865
|
*
|
|
@@ -27572,11 +26869,14 @@ var SqliteHistorySyncRepository = class {
|
|
|
27572
26869
|
* rendering a fixed list of kinds must therefore treat a missing one as "no
|
|
27573
26870
|
* rows", never as "zero sent"; the two look identical in a bar and mean
|
|
27574
26871
|
* different things.
|
|
26872
|
+
*
|
|
26873
|
+
* `scopeKeys` scopes it with the clause `partition` uses, so the per-kind rows
|
|
26874
|
+
* still sum to the scoped aggregate. An empty list returns no rows.
|
|
27575
26875
|
*/
|
|
27576
|
-
partitionByKind() {
|
|
26876
|
+
partitionByKind(scopeKeys) {
|
|
27577
26877
|
return allRows(
|
|
27578
|
-
this.partitionByKindStmt,
|
|
27579
|
-
{}
|
|
26878
|
+
scopeKeys === void 0 ? this.partitionByKindStmt : this.scopedPartitionByKindStmt,
|
|
26879
|
+
scopeKeys === void 0 ? {} : { scopeKeys: scopeKeysParam(scopeKeys) }
|
|
27580
26880
|
).map((row) => ({
|
|
27581
26881
|
kind: row.kind,
|
|
27582
26882
|
queued: row.queued ?? 0,
|
|
@@ -27588,22 +26888,25 @@ var SqliteHistorySyncRepository = class {
|
|
|
27588
26888
|
total: row.total ?? 0
|
|
27589
26889
|
}));
|
|
27590
26890
|
}
|
|
27591
|
-
|
|
27592
|
-
|
|
27593
|
-
|
|
27594
|
-
|
|
27595
|
-
|
|
27596
|
-
|
|
27597
|
-
|
|
27598
|
-
|
|
27599
|
-
|
|
27600
|
-
|
|
27601
|
-
|
|
27602
|
-
|
|
27603
|
-
|
|
27604
|
-
|
|
27605
|
-
|
|
27606
|
-
|
|
26891
|
+
/**
|
|
26892
|
+
* The drain's totals. `pending` counts only what is inside the backlog; sent
|
|
26893
|
+
* and skipped are totals.
|
|
26894
|
+
*
|
|
26895
|
+
* `scopeKeys` is a scoped attachment's filter, and it scopes every figure,
|
|
26896
|
+
* `capturesSkipped` included: a structural row is counted only when its own
|
|
26897
|
+
* key and its session root's key are among them, a capture when its own key
|
|
26898
|
+
* is. So `pending` is exactly what pendingSessions and pendingRows page out
|
|
26899
|
+
* under the same keys and boundary. Omitted, this runs the machine
|
|
26900
|
+
* statements, unchanged; an empty list counts nothing.
|
|
26901
|
+
*/
|
|
26902
|
+
counts(before, scopeKeys) {
|
|
26903
|
+
const row = getRow(
|
|
26904
|
+
scopeKeys === void 0 ? this.countsStmt : this.scopedCountsStmt,
|
|
26905
|
+
scopeKeys === void 0 ? { before } : { before, scopeKeys: scopeKeysParam(scopeKeys) }
|
|
26906
|
+
);
|
|
26907
|
+
const captures = scopeKeys === void 0 ? getRow(this.captureSkipCountStmt) : getRow(this.scopedCaptureSkipCountStmt, {
|
|
26908
|
+
scopeKeys: scopeKeysParam(scopeKeys)
|
|
26909
|
+
});
|
|
27607
26910
|
return {
|
|
27608
26911
|
pending: row?.pending ?? 0,
|
|
27609
26912
|
sent: row?.sent ?? 0,
|
|
@@ -27855,6 +27158,7 @@ function applyMigrations(db, file2, options = {}) {
|
|
|
27855
27158
|
}
|
|
27856
27159
|
ensureSyncedAtColumn(db, "audit_events");
|
|
27857
27160
|
ensureScopeKeyColumn(db);
|
|
27161
|
+
ensureScopeOwedIndex(db);
|
|
27858
27162
|
ensureScanLedgerTable(db);
|
|
27859
27163
|
ensureHistorySyncTable(db);
|
|
27860
27164
|
ensureBlockedDetectionsTable(db);
|
|
@@ -28295,14 +27599,48 @@ function ensureScopeKeyColumn(db) {
|
|
|
28295
27599
|
function hasScopeKeyColumn(db) {
|
|
28296
27600
|
return columnNames(db, "audit_events", { includeGenerated: true }).includes("scope_key");
|
|
28297
27601
|
}
|
|
27602
|
+
var SCOPE_OWED_INDEX_DDL = "CREATE INDEX IF NOT EXISTS idx_audit_scope_owed ON audit_events (scope_key, event_type, started_at) WHERE outbox_owed = 1 AND synced_at IS NULL";
|
|
27603
|
+
function ensureScopeOwedIndex(db) {
|
|
27604
|
+
if (!schemaObjectExists(db, "table", "audit_events")) return;
|
|
27605
|
+
const columns = columnNames(db, "audit_events", { includeGenerated: true });
|
|
27606
|
+
const complete = ["scope_key", "outbox_owed", "synced_at"].every((c) => columns.includes(c));
|
|
27607
|
+
if (!complete) return;
|
|
27608
|
+
db.exec(SCOPE_OWED_INDEX_DDL);
|
|
27609
|
+
}
|
|
28298
27610
|
function ensureScanLedgerTable(db) {
|
|
28299
27611
|
db.exec(`CREATE TABLE IF NOT EXISTS scan_ledger (
|
|
28300
27612
|
path TEXT PRIMARY KEY,
|
|
28301
27613
|
mtime TEXT NOT NULL,
|
|
28302
27614
|
content_hash TEXT NOT NULL,
|
|
28303
27615
|
ruleset_hash TEXT NOT NULL,
|
|
28304
|
-
scanned_at INTEGER NOT NULL
|
|
27616
|
+
scanned_at INTEGER NOT NULL,
|
|
27617
|
+
scope_key TEXT,
|
|
27618
|
+
scope_root TEXT
|
|
28305
27619
|
)`);
|
|
27620
|
+
ensureScanLedgerScopeKeyColumn(db);
|
|
27621
|
+
ensureScanLedgerScopeRootColumn(db);
|
|
27622
|
+
}
|
|
27623
|
+
var SCAN_LEDGER_SCOPE_KEY_DDL = "ALTER TABLE scan_ledger ADD COLUMN scope_key TEXT";
|
|
27624
|
+
var SCAN_LEDGER_SCOPE_ROOT_DDL = "ALTER TABLE scan_ledger ADD COLUMN scope_root TEXT";
|
|
27625
|
+
function ensureScanLedgerScopeKeyColumn(db) {
|
|
27626
|
+
ensureScanLedgerColumn(db, "scope_key", SCAN_LEDGER_SCOPE_KEY_DDL);
|
|
27627
|
+
}
|
|
27628
|
+
function ensureScanLedgerScopeRootColumn(db) {
|
|
27629
|
+
ensureScanLedgerColumn(db, "scope_root", SCAN_LEDGER_SCOPE_ROOT_DDL);
|
|
27630
|
+
}
|
|
27631
|
+
function ensureScanLedgerColumn(db, column, ddl) {
|
|
27632
|
+
if (!schemaObjectExists(db, "table", "scan_ledger")) return;
|
|
27633
|
+
if (hasScanLedgerColumn(db, column)) return;
|
|
27634
|
+
withTransaction(
|
|
27635
|
+
db,
|
|
27636
|
+
() => {
|
|
27637
|
+
if (!hasScanLedgerColumn(db, column)) db.exec(ddl);
|
|
27638
|
+
},
|
|
27639
|
+
"IMMEDIATE"
|
|
27640
|
+
);
|
|
27641
|
+
}
|
|
27642
|
+
function hasScanLedgerColumn(db, column) {
|
|
27643
|
+
return columnNames(db, "scan_ledger").includes(column);
|
|
28306
27644
|
}
|
|
28307
27645
|
function ensureHistorySyncTable(db) {
|
|
28308
27646
|
db.exec(`CREATE TABLE IF NOT EXISTS history_sync (
|
|
@@ -28353,6 +27691,106 @@ function ensureRuleProbeCacheTable(db) {
|
|
|
28353
27691
|
)`);
|
|
28354
27692
|
}
|
|
28355
27693
|
|
|
27694
|
+
// ../../packages/persistence/src/mod-policy-snapshot.ts
|
|
27695
|
+
import { createHash as createHash2 } from "crypto";
|
|
27696
|
+
import { readFileSync as readFileSync2 } from "fs";
|
|
27697
|
+
import { join as join4 } from "path";
|
|
27698
|
+
var MOD_POLICY_SNAPSHOT_FILENAME = "mod-policy.json";
|
|
27699
|
+
function modPolicySnapshotPath(dataDir2) {
|
|
27700
|
+
return join4(dataDir2, MOD_POLICY_SNAPSHOT_FILENAME);
|
|
27701
|
+
}
|
|
27702
|
+
function buildModPolicySnapshot(input2, generatedAt = /* @__PURE__ */ new Date()) {
|
|
27703
|
+
const byRule = /* @__PURE__ */ new Map();
|
|
27704
|
+
const byCategory = /* @__PURE__ */ new Map();
|
|
27705
|
+
for (const policy of input2.policies) {
|
|
27706
|
+
if (!policy.enabled) continue;
|
|
27707
|
+
if ("ruleId" in policy.target) {
|
|
27708
|
+
if (!byRule.has(policy.target.ruleId)) byRule.set(policy.target.ruleId, policy.action);
|
|
27709
|
+
} else if (!byCategory.has(policy.target.category)) {
|
|
27710
|
+
byCategory.set(policy.target.category, policy.action);
|
|
27711
|
+
}
|
|
27712
|
+
}
|
|
27713
|
+
const categoryActions = {};
|
|
27714
|
+
for (const category of DetectionCategory.options) {
|
|
27715
|
+
categoryActions[category] = byCategory.get(category) ?? DEFAULT_ACTIONS[category];
|
|
27716
|
+
}
|
|
27717
|
+
return {
|
|
27718
|
+
version: MOD_POLICY_SNAPSHOT_VERSION,
|
|
27719
|
+
generatedAt: generatedAt.toISOString(),
|
|
27720
|
+
// `examples` is documentation the mod never reads, and a custom pack's are
|
|
27721
|
+
// whatever its author pasted in, so they stay behind.
|
|
27722
|
+
...input2.rules !== void 0 ? { rules: input2.rules.map(withoutExamples) } : {},
|
|
27723
|
+
ruleActions: Object.fromEntries(byRule),
|
|
27724
|
+
categoryActions,
|
|
27725
|
+
exceptionRuleIds: [...new Set(input2.exceptionRuleIds)].sort()
|
|
27726
|
+
};
|
|
27727
|
+
}
|
|
27728
|
+
function assignedRuleActionPolicies(installed) {
|
|
27729
|
+
const out = [];
|
|
27730
|
+
for (const [ruleId, action] of installed.ruleActions) {
|
|
27731
|
+
if (installed.assignedRules.has(ruleId))
|
|
27732
|
+
out.push({ target: { ruleId }, action, enabled: true });
|
|
27733
|
+
}
|
|
27734
|
+
return out;
|
|
27735
|
+
}
|
|
27736
|
+
function withoutExamples(rule) {
|
|
27737
|
+
const copy = { ...rule };
|
|
27738
|
+
delete copy.examples;
|
|
27739
|
+
return copy;
|
|
27740
|
+
}
|
|
27741
|
+
function sameContent(a, b) {
|
|
27742
|
+
return JSON.stringify({ ...a, generatedAt: "" }) === JSON.stringify({ ...b, generatedAt: "" });
|
|
27743
|
+
}
|
|
27744
|
+
function readModPolicySnapshot(dataDir2) {
|
|
27745
|
+
try {
|
|
27746
|
+
const text = readFileSync2(modPolicySnapshotPath(dataDir2), "utf8");
|
|
27747
|
+
if (text.length > MOD_POLICY_SNAPSHOT_MAX_BYTES) return null;
|
|
27748
|
+
const parsed2 = ModPolicySnapshot.safeParse(JSON.parse(text));
|
|
27749
|
+
return parsed2.success ? parsed2.data : null;
|
|
27750
|
+
} catch {
|
|
27751
|
+
return null;
|
|
27752
|
+
}
|
|
27753
|
+
}
|
|
27754
|
+
function writeModPolicySnapshot(dataDir2, snapshot) {
|
|
27755
|
+
const text = JSON.stringify(snapshot);
|
|
27756
|
+
if (Buffer.byteLength(text) > MOD_POLICY_SNAPSHOT_MAX_BYTES) return false;
|
|
27757
|
+
const existing = readModPolicySnapshot(dataDir2);
|
|
27758
|
+
if (existing !== null && sameContent(existing, snapshot)) return false;
|
|
27759
|
+
ensureDataDirSync(dataDir2);
|
|
27760
|
+
writeOwnerOnlyFileSync(modPolicySnapshotPath(dataDir2), text);
|
|
27761
|
+
return true;
|
|
27762
|
+
}
|
|
27763
|
+
function regexProbeKey(matcher) {
|
|
27764
|
+
return createHash2("sha256").update(`${matcher.pattern} ${matcher.flags}`).digest("hex");
|
|
27765
|
+
}
|
|
27766
|
+
function vetRulesForMod(rules, sources, previouslyVetted = /* @__PURE__ */ new Set()) {
|
|
27767
|
+
const bundled = new Set(sources.bundledRegexMatchers().map(regexProbeKey));
|
|
27768
|
+
return rules.filter((rule) => {
|
|
27769
|
+
if (rule.matcher.type !== "regex") return true;
|
|
27770
|
+
const key = regexProbeKey(rule.matcher);
|
|
27771
|
+
const verdict = sources.probeVerdict(key);
|
|
27772
|
+
if (verdict === "quarantined") return false;
|
|
27773
|
+
return verdict === "safe" || bundled.has(key) || previouslyVetted.has(key);
|
|
27774
|
+
});
|
|
27775
|
+
}
|
|
27776
|
+
function modPolicyInputFromStore(sources, previouslyVetted = /* @__PURE__ */ new Set()) {
|
|
27777
|
+
const policies = sources.readPolicies();
|
|
27778
|
+
const snapshot = sources.installedRuleset();
|
|
27779
|
+
const usable = snapshot.installedPacks > 0 && (snapshot.enabledPacks === 0 || snapshot.invalidRules === 0 && snapshot.rules.length > 0);
|
|
27780
|
+
const empty2 = snapshot.installedPacks > 0 && snapshot.enabledPacks === 0;
|
|
27781
|
+
return {
|
|
27782
|
+
...usable ? { rules: empty2 ? [] : vetRulesForMod(snapshot.rules, sources, previouslyVetted) } : {},
|
|
27783
|
+
policies: [...policies, ...usable && !empty2 ? assignedRuleActionPolicies(snapshot) : []],
|
|
27784
|
+
exceptionRuleIds: sources.activeExceptionRuleIds()
|
|
27785
|
+
};
|
|
27786
|
+
}
|
|
27787
|
+
function refreshModPolicySnapshot(dataDir2, sources) {
|
|
27788
|
+
try {
|
|
27789
|
+
writeModPolicySnapshot(dataDir2, buildModPolicySnapshot(modPolicyInputFromStore(sources)));
|
|
27790
|
+
} catch {
|
|
27791
|
+
}
|
|
27792
|
+
}
|
|
27793
|
+
|
|
28356
27794
|
// ../../packages/persistence/src/internal/json.ts
|
|
28357
27795
|
function safeJson(s, fallback) {
|
|
28358
27796
|
if (s == null) return fallback;
|
|
@@ -28527,6 +27965,11 @@ var TIMELINE_COLUMNS = `
|
|
|
28527
27965
|
json_extract(attributes, '$.targetId') AS target_id,
|
|
28528
27966
|
json_extract(attributes, '$.internal') AS internal,
|
|
28529
27967
|
json_extract(attributes, '$.flagged') AS flagged`;
|
|
27968
|
+
var CALL_PROMPT_TOKENS = `(coalesce(input_tokens, 0) + coalesce(cache_read_input_tokens, 0)
|
|
27969
|
+
+ coalesce(ephemeral_1h_input_tokens, 0) + coalesce(ephemeral_5m_input_tokens, 0))`;
|
|
27970
|
+
var CALL_BAND = LONG_CONTEXT_THRESHOLDS.length === 0 ? "0" : LONG_CONTEXT_THRESHOLDS.map((t) => `(${CALL_PROMPT_TOKENS} > ${String(Math.trunc(t))})`).join(
|
|
27971
|
+
" + "
|
|
27972
|
+
);
|
|
28530
27973
|
var LLM_USAGE_SELECT = `
|
|
28531
27974
|
SELECT root_session_id AS sessionId,
|
|
28532
27975
|
provider,
|
|
@@ -28538,9 +27981,10 @@ var LLM_USAGE_SELECT = `
|
|
|
28538
27981
|
coalesce(sum(cache_read_input_tokens), 0) AS cacheReadTokens,
|
|
28539
27982
|
coalesce(sum(ephemeral_1h_input_tokens), 0) AS ephemeral1hTokens,
|
|
28540
27983
|
coalesce(sum(ephemeral_5m_input_tokens), 0) AS ephemeral5mTokens,
|
|
28541
|
-
coalesce(sum(web_search_requests), 0) AS webSearchRequests
|
|
27984
|
+
coalesce(sum(web_search_requests), 0) AS webSearchRequests,
|
|
27985
|
+
coalesce(max(${CALL_PROMPT_TOKENS}), 0) AS promptTokens`;
|
|
28542
27986
|
var LLM_USAGE_SCOPE = `event_type = 'llm_call' AND attributes IS NOT NULL AND root_session_id IS NOT NULL`;
|
|
28543
|
-
var LLM_USAGE_GROUP = `GROUP BY root_session_id, provider, model, service_tier`;
|
|
27987
|
+
var LLM_USAGE_GROUP = `GROUP BY root_session_id, provider, model, service_tier, ${CALL_BAND}`;
|
|
28544
27988
|
function usageLeaves(rows) {
|
|
28545
27989
|
return rows.map((row) => {
|
|
28546
27990
|
const attributes = {
|
|
@@ -28555,7 +27999,7 @@ function usageLeaves(rows) {
|
|
|
28555
27999
|
if (row.provider !== null) attributes.provider = row.provider;
|
|
28556
28000
|
if (row.model !== null) attributes.model = row.model;
|
|
28557
28001
|
if (row.serviceTier !== null) attributes.service_tier = row.serviceTier;
|
|
28558
|
-
return { sessionId: row.sessionId, attributes };
|
|
28002
|
+
return { sessionId: row.sessionId, attributes, promptTokens: row.promptTokens };
|
|
28559
28003
|
});
|
|
28560
28004
|
}
|
|
28561
28005
|
var SESSION_ROOT = `event_type = 'session'`;
|
|
@@ -29889,9 +29333,10 @@ var ACTIVE_REVEAL_GRANT_PREDICATE = `capability = 'reveal_to_model'
|
|
|
29889
29333
|
AND conditions IS NULL
|
|
29890
29334
|
AND ${ACTIVE_PREDICATE}`;
|
|
29891
29335
|
var SqliteExceptionsRepository = class {
|
|
29892
|
-
constructor(db, now = () => Date.now()) {
|
|
29336
|
+
constructor(db, now = () => Date.now(), onChange = () => void 0) {
|
|
29893
29337
|
this.db = db;
|
|
29894
29338
|
this.now = now;
|
|
29339
|
+
this.onChange = onChange;
|
|
29895
29340
|
this.consumeStmt = db.prepare(
|
|
29896
29341
|
`UPDATE exceptions
|
|
29897
29342
|
SET use_count = use_count + 1, last_used_at = :now, updated_at = :now
|
|
@@ -29910,6 +29355,7 @@ var SqliteExceptionsRepository = class {
|
|
|
29910
29355
|
}
|
|
29911
29356
|
db;
|
|
29912
29357
|
now;
|
|
29358
|
+
onChange;
|
|
29913
29359
|
consumeStmt;
|
|
29914
29360
|
insertBlockedStmt;
|
|
29915
29361
|
sweepBlockedStmt;
|
|
@@ -29925,7 +29371,9 @@ var SqliteExceptionsRepository = class {
|
|
|
29925
29371
|
*/
|
|
29926
29372
|
create(input2) {
|
|
29927
29373
|
try {
|
|
29928
|
-
|
|
29374
|
+
const created = this.createSync(input2);
|
|
29375
|
+
this.onChange();
|
|
29376
|
+
return Promise.resolve(created);
|
|
29929
29377
|
} catch (err) {
|
|
29930
29378
|
return Promise.reject(err instanceof Error ? err : new Error(String(err)));
|
|
29931
29379
|
}
|
|
@@ -30056,6 +29504,7 @@ var SqliteExceptionsRepository = class {
|
|
|
30056
29504
|
SET revoked_at = :now, revoked_by = :revokedBy, revoke_reason = :reason, updated_at = :now
|
|
30057
29505
|
WHERE id = :id AND revoked_at IS NULL`
|
|
30058
29506
|
).run({ id, revokedBy, reason: reason ?? null, now });
|
|
29507
|
+
if (Number(result.changes) === 1) this.onChange();
|
|
30059
29508
|
return Promise.resolve(Number(result.changes) === 1);
|
|
30060
29509
|
}
|
|
30061
29510
|
/**
|
|
@@ -30068,6 +29517,15 @@ var SqliteExceptionsRepository = class {
|
|
|
30068
29517
|
const result = this.consumeStmt.run({ id, now });
|
|
30069
29518
|
return Promise.resolve(Number(result.changes) === 1);
|
|
30070
29519
|
}
|
|
29520
|
+
/** The rule ids with at least one active grant, under any key version. */
|
|
29521
|
+
activeRuleIds(now = this.now()) {
|
|
29522
|
+
return allRows(
|
|
29523
|
+
this.db.prepare(
|
|
29524
|
+
`SELECT DISTINCT rule_id AS ruleId FROM exceptions WHERE ${ACTIVE_PREDICATE}`
|
|
29525
|
+
),
|
|
29526
|
+
{ now }
|
|
29527
|
+
).map((row) => row.ruleId);
|
|
29528
|
+
}
|
|
30071
29529
|
/**
|
|
30072
29530
|
* The evaluation subset of every active grant under one fingerprint key
|
|
30073
29531
|
* version — what rides the policy bundle to the hook. Grants written under
|
|
@@ -31191,28 +30649,28 @@ var SqliteInspectionFindingsRepository = class {
|
|
|
31191
30649
|
};
|
|
31192
30650
|
|
|
31193
30651
|
// ../../packages/persistence/src/repositories/installed-packs.ts
|
|
31194
|
-
import { createHash as
|
|
30652
|
+
import { createHash as createHash3, randomUUID as randomUUID4 } from "crypto";
|
|
31195
30653
|
|
|
31196
30654
|
// ../../packages/persistence/src/policy-floor.ts
|
|
31197
|
-
import { readFileSync as
|
|
31198
|
-
import { join as
|
|
30655
|
+
import { readFileSync as readFileSync6 } from "fs";
|
|
30656
|
+
import { join as join7 } from "path";
|
|
31199
30657
|
|
|
31200
30658
|
// ../../packages/persistence/src/local-layout.ts
|
|
31201
30659
|
import { renameSync as renameSync3 } from "fs";
|
|
31202
30660
|
import { mkdir } from "fs/promises";
|
|
31203
30661
|
import { homedir } from "os";
|
|
31204
|
-
import { join as
|
|
30662
|
+
import { join as join5 } from "path";
|
|
31205
30663
|
function defaultDataDir() {
|
|
31206
|
-
return
|
|
30664
|
+
return join5(homedir(), ".aka");
|
|
31207
30665
|
}
|
|
31208
30666
|
function settingsDir(base = defaultDataDir()) {
|
|
31209
|
-
return
|
|
30667
|
+
return join5(base, "settings");
|
|
31210
30668
|
}
|
|
31211
30669
|
function dataDir(base = defaultDataDir()) {
|
|
31212
|
-
return
|
|
30670
|
+
return join5(base, "data");
|
|
31213
30671
|
}
|
|
31214
30672
|
function dbPath(base = defaultDataDir()) {
|
|
31215
|
-
return
|
|
30673
|
+
return join5(dataDir(base), "aka.db");
|
|
31216
30674
|
}
|
|
31217
30675
|
async function ensureDataDir(dir = defaultDataDir()) {
|
|
31218
30676
|
await mkdir(dir, { recursive: true, mode: DATA_DIR_MODE });
|
|
@@ -31229,8 +30687,8 @@ function migrateLegacyLayout(base = defaultDataDir()) {
|
|
|
31229
30687
|
for (const { name, dest } of moves) {
|
|
31230
30688
|
try {
|
|
31231
30689
|
ensureDataDirSync(dest);
|
|
31232
|
-
const moved =
|
|
31233
|
-
renameSync3(
|
|
30690
|
+
const moved = join5(dest, name);
|
|
30691
|
+
renameSync3(join5(base, name), moved);
|
|
31234
30692
|
tightenFile(moved);
|
|
31235
30693
|
} catch {
|
|
31236
30694
|
}
|
|
@@ -31238,8 +30696,8 @@ function migrateLegacyLayout(base = defaultDataDir()) {
|
|
|
31238
30696
|
}
|
|
31239
30697
|
|
|
31240
30698
|
// ../../packages/persistence/src/settings.ts
|
|
31241
|
-
import { readFileSync as
|
|
31242
|
-
import { join as
|
|
30699
|
+
import { readFileSync as readFileSync5 } from "fs";
|
|
30700
|
+
import { join as join6 } from "path";
|
|
31243
30701
|
|
|
31244
30702
|
// ../../packages/persistence/src/file-lock.ts
|
|
31245
30703
|
import { randomUUID as randomUUID3 } from "crypto";
|
|
@@ -31247,7 +30705,7 @@ import {
|
|
|
31247
30705
|
closeSync,
|
|
31248
30706
|
existsSync as existsSync2,
|
|
31249
30707
|
openSync,
|
|
31250
|
-
readFileSync as
|
|
30708
|
+
readFileSync as readFileSync3,
|
|
31251
30709
|
rmSync as rmSync5,
|
|
31252
30710
|
statSync as statSync3,
|
|
31253
30711
|
writeFileSync as writeFileSync2
|
|
@@ -31256,16 +30714,16 @@ import { hostname as hostname3 } from "os";
|
|
|
31256
30714
|
var PARK = new Int32Array(new SharedArrayBuffer(4));
|
|
31257
30715
|
|
|
31258
30716
|
// ../../packages/persistence/src/managed-settings.ts
|
|
31259
|
-
import { readFileSync as
|
|
30717
|
+
import { readFileSync as readFileSync4 } from "fs";
|
|
31260
30718
|
import { posix, win32 } from "path";
|
|
31261
|
-
function managedSettingsPaths(
|
|
31262
|
-
if (
|
|
30719
|
+
function managedSettingsPaths(platform = process.platform) {
|
|
30720
|
+
if (platform === "darwin") {
|
|
31263
30721
|
return [
|
|
31264
30722
|
posix.join("/Library", "Application Support", "AKASecurity", MANAGED_SETTINGS_FILENAME),
|
|
31265
30723
|
posix.join("/Library", "Managed Preferences", MANAGED_SETTINGS_FILENAME)
|
|
31266
30724
|
];
|
|
31267
30725
|
}
|
|
31268
|
-
if (
|
|
30726
|
+
if (platform === "win32") {
|
|
31269
30727
|
return [win32.join("C:\\", "ProgramData", "AKASecurity", MANAGED_SETTINGS_FILENAME)];
|
|
31270
30728
|
}
|
|
31271
30729
|
return [posix.join("/etc", "aka", MANAGED_SETTINGS_FILENAME)];
|
|
@@ -31275,7 +30733,7 @@ function readManagedSettings(paths = testOnlyManagedPaths ?? managedSettingsPath
|
|
|
31275
30733
|
for (const path of paths) {
|
|
31276
30734
|
let text;
|
|
31277
30735
|
try {
|
|
31278
|
-
text =
|
|
30736
|
+
text = readFileSync4(path, "utf8");
|
|
31279
30737
|
} catch {
|
|
31280
30738
|
continue;
|
|
31281
30739
|
}
|
|
@@ -31329,7 +30787,7 @@ function readWorkspaceSettings(base = defaultDataDir()) {
|
|
|
31329
30787
|
return overlayManagedSettings(readUserSettings(base), readManagedSettings());
|
|
31330
30788
|
}
|
|
31331
30789
|
function readUserSettings(base) {
|
|
31332
|
-
const record2 = readJson(
|
|
30790
|
+
const record2 = readJson(join6(settingsDir(base), SETTINGS_FILENAME));
|
|
31333
30791
|
if (!record2) return defaultWorkspaceSettings();
|
|
31334
30792
|
try {
|
|
31335
30793
|
return WorkspaceSettings.parse(record2);
|
|
@@ -31340,7 +30798,7 @@ function readUserSettings(base) {
|
|
|
31340
30798
|
function readJson(file2) {
|
|
31341
30799
|
let text;
|
|
31342
30800
|
try {
|
|
31343
|
-
text =
|
|
30801
|
+
text = readFileSync5(file2, "utf8");
|
|
31344
30802
|
} catch {
|
|
31345
30803
|
return null;
|
|
31346
30804
|
}
|
|
@@ -31380,7 +30838,7 @@ var PolicyFloorError = class extends Error {
|
|
|
31380
30838
|
};
|
|
31381
30839
|
function readCachedPolicyBundle(base = defaultDataDir()) {
|
|
31382
30840
|
try {
|
|
31383
|
-
const raw =
|
|
30841
|
+
const raw = readFileSync6(join7(dataDir(base), POLICY_CACHE_FILENAME), "utf8");
|
|
31384
30842
|
const parsed2 = JSON.parse(raw);
|
|
31385
30843
|
if (typeof parsed2 !== "object" || parsed2 === null) return null;
|
|
31386
30844
|
return PolicyBundle.parse(parsed2.bundle);
|
|
@@ -31504,7 +30962,7 @@ function inventorySignature(packs) {
|
|
|
31504
30962
|
return packs.map((p) => `${p.namespace}/${p.packId}@${p.version}#${hashRules(p.rulesJson)}`).sort().join(",");
|
|
31505
30963
|
}
|
|
31506
30964
|
function hashRules(rulesJson) {
|
|
31507
|
-
return
|
|
30965
|
+
return createHash3("sha256").update(rulesJson).digest("hex");
|
|
31508
30966
|
}
|
|
31509
30967
|
function parseVersion(v) {
|
|
31510
30968
|
const m = /^(\d+)\.(\d+)\.(\d+)/.exec(v);
|
|
@@ -31546,9 +31004,10 @@ var SqliteInstalledPacksRepository = class {
|
|
|
31546
31004
|
* from `openLocalDatabase`, which is the single construction site that owns a
|
|
31547
31005
|
* real `~/.aka`.
|
|
31548
31006
|
*/
|
|
31549
|
-
constructor(db, baseDir) {
|
|
31007
|
+
constructor(db, baseDir, onChange = () => void 0) {
|
|
31550
31008
|
this.db = db;
|
|
31551
31009
|
this.baseDir = baseDir;
|
|
31010
|
+
this.onChange = onChange;
|
|
31552
31011
|
this.insertMissingStmt = db.prepare(
|
|
31553
31012
|
`INSERT INTO installed_packs (id, namespace, pack_id, version, name, rules_json, enabled, policy_id, created_at, updated_at)
|
|
31554
31013
|
VALUES (:id, :namespace, :packId, :version, :name, :rulesJson, 1, :policyId, :now, :now)
|
|
@@ -31577,6 +31036,7 @@ var SqliteInstalledPacksRepository = class {
|
|
|
31577
31036
|
}
|
|
31578
31037
|
db;
|
|
31579
31038
|
baseDir;
|
|
31039
|
+
onChange;
|
|
31580
31040
|
insertMissingStmt;
|
|
31581
31041
|
upsertAvailableStmt;
|
|
31582
31042
|
signatureStmt;
|
|
@@ -31649,6 +31109,7 @@ var SqliteInstalledPacksRepository = class {
|
|
|
31649
31109
|
},
|
|
31650
31110
|
"IMMEDIATE"
|
|
31651
31111
|
);
|
|
31112
|
+
this.onChange();
|
|
31652
31113
|
} catch {
|
|
31653
31114
|
}
|
|
31654
31115
|
}
|
|
@@ -31723,6 +31184,7 @@ var SqliteInstalledPacksRepository = class {
|
|
|
31723
31184
|
},
|
|
31724
31185
|
"IMMEDIATE"
|
|
31725
31186
|
);
|
|
31187
|
+
if (changed) this.onChange();
|
|
31726
31188
|
return changed;
|
|
31727
31189
|
}
|
|
31728
31190
|
/**
|
|
@@ -31964,6 +31426,7 @@ var SqliteInstalledPacksRepository = class {
|
|
|
31964
31426
|
`UPDATE installed_packs SET policy_id = :policyId, updated_at = :now
|
|
31965
31427
|
WHERE namespace = :namespace AND pack_id = :packId`
|
|
31966
31428
|
).run({ policyId, now: Date.now(), namespace, packId });
|
|
31429
|
+
if (Number(res.changes) > 0) this.onChange();
|
|
31967
31430
|
return Number(res.changes) > 0;
|
|
31968
31431
|
}
|
|
31969
31432
|
/**
|
|
@@ -31988,6 +31451,7 @@ var SqliteInstalledPacksRepository = class {
|
|
|
31988
31451
|
`UPDATE installed_packs SET enabled = :enabled, updated_at = :now
|
|
31989
31452
|
WHERE namespace = :namespace AND pack_id = :packId`
|
|
31990
31453
|
).run({ enabled: boolToInt(enabled), now: Date.now(), namespace, packId });
|
|
31454
|
+
if (Number(res.changes) > 0) this.onChange();
|
|
31991
31455
|
return Number(res.changes) > 0;
|
|
31992
31456
|
}
|
|
31993
31457
|
// Fingerprint of the recorded available mirror — compared against the
|
|
@@ -32885,13 +32349,19 @@ var SqliteInventoryAssetsRepository = class {
|
|
|
32885
32349
|
import { randomUUID as randomUUID6 } from "crypto";
|
|
32886
32350
|
var SEED_BATCH_WINDOW_MS = 6e4;
|
|
32887
32351
|
var SqlitePoliciesRepository = class {
|
|
32888
|
-
constructor(db) {
|
|
32352
|
+
constructor(db, onChange = () => void 0) {
|
|
32889
32353
|
this.db = db;
|
|
32354
|
+
this.onChange = onChange;
|
|
32890
32355
|
}
|
|
32891
32356
|
db;
|
|
32357
|
+
onChange;
|
|
32892
32358
|
readPolicies() {
|
|
32359
|
+
return Promise.resolve(this.listPolicies());
|
|
32360
|
+
}
|
|
32361
|
+
/** The synchronous read behind {@link readPolicies}. */
|
|
32362
|
+
listPolicies() {
|
|
32893
32363
|
const rows = allRows(this.db.prepare("SELECT * FROM policies"));
|
|
32894
|
-
|
|
32364
|
+
return mapRowsTolerant(rows, (row) => {
|
|
32895
32365
|
const target = JSON.parse(row.target);
|
|
32896
32366
|
const customKeywords = row.custom_keywords ? JSON.parse(row.custom_keywords) : void 0;
|
|
32897
32367
|
return Policy.parse({
|
|
@@ -32903,7 +32373,6 @@ var SqlitePoliciesRepository = class {
|
|
|
32903
32373
|
customKeywords
|
|
32904
32374
|
});
|
|
32905
32375
|
});
|
|
32906
|
-
return Promise.resolve(policies);
|
|
32907
32376
|
}
|
|
32908
32377
|
// Seed one policy per bundled category at Monitor so the detection-type config
|
|
32909
32378
|
// exists from first run. An unassigned pack's rules follow these rows, so
|
|
@@ -32914,7 +32383,7 @@ var SqlitePoliciesRepository = class {
|
|
|
32914
32383
|
const count = countScalar(this.db, "SELECT count(*) AS n FROM policies");
|
|
32915
32384
|
if (count > 0) {
|
|
32916
32385
|
this.markEarlierChoices();
|
|
32917
|
-
this.monitorUntouchedSeeds();
|
|
32386
|
+
if (this.monitorUntouchedSeeds()) this.onChange();
|
|
32918
32387
|
return;
|
|
32919
32388
|
}
|
|
32920
32389
|
const stmt = this.db.prepare(
|
|
@@ -32931,6 +32400,7 @@ var SqlitePoliciesRepository = class {
|
|
|
32931
32400
|
});
|
|
32932
32401
|
}
|
|
32933
32402
|
});
|
|
32403
|
+
this.onChange();
|
|
32934
32404
|
}
|
|
32935
32405
|
// Before this build, upsertCategoryAction INSERTed a new row with updated_at
|
|
32936
32406
|
// equal to created_at, so a choice made for a category that had no row yet
|
|
@@ -32996,7 +32466,7 @@ var SqlitePoliciesRepository = class {
|
|
|
32996
32466
|
).filter(
|
|
32997
32467
|
(row) => DEFAULT_ACTIONS[row.category] === row.action
|
|
32998
32468
|
);
|
|
32999
|
-
if (untouched.length === 0) return;
|
|
32469
|
+
if (untouched.length === 0) return false;
|
|
33000
32470
|
const stmt = this.db.prepare(
|
|
33001
32471
|
`UPDATE policies SET action = 'log'
|
|
33002
32472
|
WHERE scope = 'global' AND json_extract(target, '$.category') = :category
|
|
@@ -33007,6 +32477,7 @@ var SqlitePoliciesRepository = class {
|
|
|
33007
32477
|
stmt.run({ category: row.category, seeded: row.action });
|
|
33008
32478
|
}
|
|
33009
32479
|
});
|
|
32480
|
+
return true;
|
|
33010
32481
|
}
|
|
33011
32482
|
// Insert-or-update the single global per-category policy row, keyed on the
|
|
33012
32483
|
// existing uq_policies_scope_target unique index (scope, target). `action`
|
|
@@ -33023,6 +32494,7 @@ var SqlitePoliciesRepository = class {
|
|
|
33023
32494
|
ON CONFLICT(scope, target) DO UPDATE SET action = excluded.action, enabled = 1,
|
|
33024
32495
|
updated_at = MAX(excluded.updated_at, policies.created_at + 1)`
|
|
33025
32496
|
).run({ id: randomUUID6(), target: JSON.stringify({ category }), action, now });
|
|
32497
|
+
this.onChange();
|
|
33026
32498
|
}
|
|
33027
32499
|
// Caps every global per-category policy currently set to block/redact down
|
|
33028
32500
|
// to warn (see warn-era-cap.ts). Rule-targeted policies are untouched.
|
|
@@ -33033,6 +32505,7 @@ var SqlitePoliciesRepository = class {
|
|
|
33033
32505
|
WHERE scope='global' AND action IN ('block','redact')
|
|
33034
32506
|
AND json_extract(target,'$.category') IS NOT NULL`
|
|
33035
32507
|
).run({ now: Date.now() });
|
|
32508
|
+
if (Number(info.changes) > 0) this.onChange();
|
|
33036
32509
|
return Number(info.changes);
|
|
33037
32510
|
}
|
|
33038
32511
|
// Whether the category's row was ever written after it was created — by the
|
|
@@ -33352,31 +32825,45 @@ var SqliteScanLedgerRepository = class {
|
|
|
33352
32825
|
constructor(db) {
|
|
33353
32826
|
this.db = db;
|
|
33354
32827
|
this.upsertStmt = db.prepare(
|
|
33355
|
-
`INSERT INTO scan_ledger
|
|
33356
|
-
|
|
32828
|
+
`INSERT INTO scan_ledger
|
|
32829
|
+
(path, mtime, content_hash, ruleset_hash, scope_key, scope_root, scanned_at)
|
|
32830
|
+
VALUES (:path, :mtime, :contentHash, :rulesetHash, :scopeKey, :scopeRoot, :scannedAt)
|
|
33357
32831
|
ON CONFLICT (path) DO UPDATE SET
|
|
33358
32832
|
mtime = excluded.mtime,
|
|
33359
32833
|
content_hash = excluded.content_hash,
|
|
33360
32834
|
ruleset_hash = excluded.ruleset_hash,
|
|
32835
|
+
scope_key = excluded.scope_key,
|
|
32836
|
+
scope_root = excluded.scope_root,
|
|
33361
32837
|
scanned_at = excluded.scanned_at`
|
|
33362
32838
|
);
|
|
33363
32839
|
this.readStmt = db.prepare(
|
|
33364
|
-
`SELECT path, mtime, content_hash AS contentHash
|
|
32840
|
+
`SELECT path, mtime, content_hash AS contentHash, scope_key AS scopeKey,
|
|
32841
|
+
scope_root AS scopeRoot
|
|
33365
32842
|
FROM scan_ledger WHERE ruleset_hash = :rulesetHash`
|
|
33366
32843
|
);
|
|
33367
32844
|
this.pathsStmt = db.prepare(`SELECT path FROM scan_ledger`);
|
|
32845
|
+
this.pathKeysStmt = db.prepare(`SELECT path, scope_key AS scopeKey FROM scan_ledger`);
|
|
33368
32846
|
}
|
|
33369
32847
|
db;
|
|
33370
32848
|
upsertStmt;
|
|
33371
32849
|
readStmt;
|
|
33372
32850
|
pathsStmt;
|
|
32851
|
+
pathKeysStmt;
|
|
33373
32852
|
// Previously scanned files under THIS ruleset, keyed by path. Rows from an
|
|
33374
32853
|
// older ruleset are simply absent, which reads as "never scanned".
|
|
33375
32854
|
entriesForRuleset(rulesetHash) {
|
|
33376
|
-
const rows = allRows(this.readStmt, {
|
|
33377
|
-
|
|
33378
|
-
|
|
33379
|
-
|
|
32855
|
+
const rows = allRows(this.readStmt, { rulesetHash });
|
|
32856
|
+
return new Map(
|
|
32857
|
+
rows.map((r) => [
|
|
32858
|
+
r.path,
|
|
32859
|
+
{
|
|
32860
|
+
mtime: r.mtime,
|
|
32861
|
+
contentHash: r.contentHash,
|
|
32862
|
+
...r.scopeKey !== null ? { scopeKey: r.scopeKey } : {},
|
|
32863
|
+
...r.scopeRoot !== null ? { scopeRoot: r.scopeRoot } : {}
|
|
32864
|
+
}
|
|
32865
|
+
])
|
|
32866
|
+
);
|
|
33380
32867
|
}
|
|
33381
32868
|
// Every ledgered path, whatever ruleset it was scanned under — the set a
|
|
33382
32869
|
// deletion sweep checks against disk. A file deleted before a ruleset change
|
|
@@ -33385,6 +32872,14 @@ var SqliteScanLedgerRepository = class {
|
|
|
33385
32872
|
allPaths() {
|
|
33386
32873
|
return allRows(this.pathsStmt).map((r) => r.path);
|
|
33387
32874
|
}
|
|
32875
|
+
// Every ledgered path with the repository it was in when it was last read,
|
|
32876
|
+
// whatever ruleset it was scanned under: what a deletion sweep needs to say
|
|
32877
|
+
// which repository a vanished file belonged to. `undefined` for a row with no
|
|
32878
|
+
// key, which is every row written before the column existed.
|
|
32879
|
+
pathKeys() {
|
|
32880
|
+
const rows = allRows(this.pathKeysStmt);
|
|
32881
|
+
return new Map(rows.map((r) => [r.path, r.scopeKey ?? void 0]));
|
|
32882
|
+
}
|
|
33388
32883
|
upsertEntries(entries) {
|
|
33389
32884
|
if (entries.length === 0) return;
|
|
33390
32885
|
const scannedAt = Date.now();
|
|
@@ -33395,6 +32890,8 @@ var SqliteScanLedgerRepository = class {
|
|
|
33395
32890
|
mtime: entry.mtime,
|
|
33396
32891
|
contentHash: entry.contentHash,
|
|
33397
32892
|
rulesetHash: entry.rulesetHash,
|
|
32893
|
+
scopeKey: entry.scopeKey ?? null,
|
|
32894
|
+
scopeRoot: entry.scopeRoot ?? null,
|
|
33398
32895
|
scannedAt
|
|
33399
32896
|
});
|
|
33400
32897
|
}
|
|
@@ -34482,6 +33979,11 @@ function withoutDroppedFiles(reconcile, droppedFiles) {
|
|
|
34482
33979
|
deletedFiles: reconcile.deletedFiles.filter((file2) => !dropped.has(file2))
|
|
34483
33980
|
};
|
|
34484
33981
|
}
|
|
33982
|
+
function withoutTrailingSlashes(path) {
|
|
33983
|
+
let end = path.length;
|
|
33984
|
+
while (end > 0 && path.charCodeAt(end - 1) === 47) end--;
|
|
33985
|
+
return path.slice(0, end);
|
|
33986
|
+
}
|
|
34485
33987
|
function toEndpointSummary(row) {
|
|
34486
33988
|
return {
|
|
34487
33989
|
id: row.id,
|
|
@@ -34769,7 +34271,7 @@ var SqliteSharesRepository = class {
|
|
|
34769
34271
|
*/
|
|
34770
34272
|
reconcileCallSites(projectKey, reconcile) {
|
|
34771
34273
|
if (reconcile.mode === "walk") {
|
|
34772
|
-
const prefix = reconcile.walkedPrefix
|
|
34274
|
+
const prefix = withoutTrailingSlashes(reconcile.walkedPrefix);
|
|
34773
34275
|
this.db.prepare(
|
|
34774
34276
|
`DELETE FROM share_call_site
|
|
34775
34277
|
WHERE project_key = :key
|
|
@@ -35337,7 +34839,7 @@ function backupLegacyStore(db, file2) {
|
|
|
35337
34839
|
discardStore(file2, backup);
|
|
35338
34840
|
return backup;
|
|
35339
34841
|
}
|
|
35340
|
-
function openAndInitialize(file2, base, skipTags) {
|
|
34842
|
+
function openAndInitialize(file2, base, skipTags, shippedRegexMatchers2) {
|
|
35341
34843
|
let db = openWithPragmas(file2);
|
|
35342
34844
|
try {
|
|
35343
34845
|
if (isForeignSqliteLineage(db)) {
|
|
@@ -35349,8 +34851,15 @@ function openAndInitialize(file2, base, skipTags) {
|
|
|
35349
34851
|
}
|
|
35350
34852
|
applyMigrations(db, file2, { skipTags });
|
|
35351
34853
|
tightenPerms(file2);
|
|
35352
|
-
const
|
|
35353
|
-
const
|
|
34854
|
+
const modPolicy = {};
|
|
34855
|
+
const onPolicyStateChange = () => {
|
|
34856
|
+
if (modPolicy.current !== void 0)
|
|
34857
|
+
refreshModPolicySnapshot(dirname2(file2), modPolicy.current);
|
|
34858
|
+
};
|
|
34859
|
+
const policies = new SqlitePoliciesRepository(db, onPolicyStateChange);
|
|
34860
|
+
const installedPacks = new SqliteInstalledPacksRepository(db, base, onPolicyStateChange);
|
|
34861
|
+
const ruleProbeCache = new SqliteRuleProbeCacheRepository(db);
|
|
34862
|
+
const exceptions = new SqliteExceptionsRepository(db, void 0, onPolicyStateChange);
|
|
35354
34863
|
const repositories = {
|
|
35355
34864
|
events: new SqliteEventsRepository(db),
|
|
35356
34865
|
findings: new SqliteFindingsRepository(db),
|
|
@@ -35359,9 +34868,9 @@ function openAndInitialize(file2, base, skipTags) {
|
|
|
35359
34868
|
scanLedger: new SqliteScanLedgerRepository(db),
|
|
35360
34869
|
historySync: new SqliteHistorySyncRepository(db),
|
|
35361
34870
|
secretVault: new SqliteSecretVaultRepository(db),
|
|
35362
|
-
exceptions
|
|
34871
|
+
exceptions,
|
|
35363
34872
|
resolutions: new SqliteResolutionsRepository(db),
|
|
35364
|
-
ruleProbeCache
|
|
34873
|
+
ruleProbeCache,
|
|
35365
34874
|
bodyRetention: new SqliteBodyRetentionRepository(db),
|
|
35366
34875
|
security: new SqliteSecurityRepository(db),
|
|
35367
34876
|
detections: new SqliteDetectionsRepository(db),
|
|
@@ -35379,6 +34888,13 @@ function openAndInitialize(file2, base, skipTags) {
|
|
|
35379
34888
|
inspectionFindings: new SqliteInspectionFindingsRepository(db),
|
|
35380
34889
|
configInventory: new SqliteConfigInventoryRepository(db)
|
|
35381
34890
|
};
|
|
34891
|
+
modPolicy.current = {
|
|
34892
|
+
installedRuleset: () => installedPacks.installedRuleset(),
|
|
34893
|
+
readPolicies: () => policies.listPolicies(),
|
|
34894
|
+
activeExceptionRuleIds: () => exceptions.activeRuleIds(),
|
|
34895
|
+
probeVerdict: (key) => ruleProbeCache.getVerdict(key)?.verdict,
|
|
34896
|
+
bundledRegexMatchers: () => shippedRegexMatchers2
|
|
34897
|
+
};
|
|
35382
34898
|
policies.seedDefaults();
|
|
35383
34899
|
return { db, ...repositories };
|
|
35384
34900
|
} catch (err) {
|
|
@@ -35390,7 +34906,7 @@ function openAndInitialize(file2, base, skipTags) {
|
|
|
35390
34906
|
var DEFERRED_TAGS = new Set(DEFERRED_MIGRATION_TAGS);
|
|
35391
34907
|
function openLocalDatabase(dir, options = {}) {
|
|
35392
34908
|
ensureDataDirSync(dir);
|
|
35393
|
-
const file2 =
|
|
34909
|
+
const file2 = join8(dir, DB_FILENAME);
|
|
35394
34910
|
reapStalePartials(file2);
|
|
35395
34911
|
const {
|
|
35396
34912
|
db,
|
|
@@ -35426,7 +34942,8 @@ function openLocalDatabase(dir, options = {}) {
|
|
|
35426
34942
|
// `dataDir()` — so its parent is the `~/.aka` base the layout splits into
|
|
35427
34943
|
// settings/ and data/, and the pack-policy floor needs both halves.
|
|
35428
34944
|
dirname2(dir),
|
|
35429
|
-
options.applyDeferredMigrations === true ? void 0 : DEFERRED_TAGS
|
|
34945
|
+
options.applyDeferredMigrations === true ? void 0 : DEFERRED_TAGS,
|
|
34946
|
+
options.shippedRegexMatchers ?? []
|
|
35430
34947
|
);
|
|
35431
34948
|
function captureRowId(event) {
|
|
35432
34949
|
return captureId(
|
|
@@ -35691,7 +35208,7 @@ function openLocalDatabase(dir, options = {}) {
|
|
|
35691
35208
|
}
|
|
35692
35209
|
|
|
35693
35210
|
// ../../packages/persistence/src/egress-wire.ts
|
|
35694
|
-
import { createHash as
|
|
35211
|
+
import { createHash as createHash4 } from "crypto";
|
|
35695
35212
|
var PROJECT_KEY_DIGEST_VERSION = "v2";
|
|
35696
35213
|
var SCP_FORM = /^(?:[^@/]+@)?([^/:]+):(.+)$/;
|
|
35697
35214
|
var DOS_DRIVE = /^[A-Za-z]:[\\/]/;
|
|
@@ -35723,7 +35240,7 @@ function canonicalGitUrl(url2) {
|
|
|
35723
35240
|
}
|
|
35724
35241
|
function hashProjectKey(projectKey) {
|
|
35725
35242
|
const canonical = projectKey.startsWith("git:") ? `git:${canonicalGitUrl(projectKey.slice("git:".length))}` : projectKey;
|
|
35726
|
-
return
|
|
35243
|
+
return createHash4("sha256").update(`${PROJECT_KEY_DIGEST_VERSION}:${canonical}`, "utf8").digest("hex");
|
|
35727
35244
|
}
|
|
35728
35245
|
var SCOPE_KEY = printable(ATTACHMENT_SCOPE_IDENTITY_MAX_LENGTH);
|
|
35729
35246
|
var URL_SCHEME = /^[a-z][a-z0-9+.-]*:\/\//i;
|
|
@@ -35788,17 +35305,16 @@ function toEgressIngestRequest(input2) {
|
|
|
35788
35305
|
}
|
|
35789
35306
|
|
|
35790
35307
|
// ../../packages/persistence/src/finding-key.ts
|
|
35791
|
-
import { createHash as
|
|
35308
|
+
import { createHash as createHash5 } from "crypto";
|
|
35792
35309
|
|
|
35793
35310
|
// ../../packages/persistence/src/fingerprint.ts
|
|
35794
35311
|
import { createHmac, randomBytes } from "crypto";
|
|
35795
|
-
import { existsSync as existsSync3, readFileSync as
|
|
35796
|
-
import { join as
|
|
35797
|
-
import { DatabaseSync as DatabaseSync2 } from "node:sqlite";
|
|
35312
|
+
import { existsSync as existsSync3, readFileSync as readFileSync7 } from "fs";
|
|
35313
|
+
import { join as join9 } from "path";
|
|
35798
35314
|
var EXCEPTION_KEY_FILENAME = "exception.key";
|
|
35799
35315
|
var KEY_MATERIAL_BYTES = 32;
|
|
35800
35316
|
function keyFilePath(dataDir2) {
|
|
35801
|
-
return
|
|
35317
|
+
return join9(dataDir2, EXCEPTION_KEY_FILENAME);
|
|
35802
35318
|
}
|
|
35803
35319
|
function parseKeyFile(raw) {
|
|
35804
35320
|
const parsed2 = JSON.parse(raw);
|
|
@@ -35821,7 +35337,7 @@ function parseKeyFile(raw) {
|
|
|
35821
35337
|
function readFingerprintKey(dataDir2) {
|
|
35822
35338
|
let raw;
|
|
35823
35339
|
try {
|
|
35824
|
-
raw =
|
|
35340
|
+
raw = readFileSync7(keyFilePath(dataDir2), "utf8");
|
|
35825
35341
|
} catch (err) {
|
|
35826
35342
|
if (err.code === "ENOENT") return null;
|
|
35827
35343
|
throw err instanceof Error ? err : new Error(String(err));
|
|
@@ -35830,8 +35346,8 @@ function readFingerprintKey(dataDir2) {
|
|
|
35830
35346
|
}
|
|
35831
35347
|
|
|
35832
35348
|
// ../../packages/persistence/src/forward-health.ts
|
|
35833
|
-
import { readFileSync as
|
|
35834
|
-
import { join as
|
|
35349
|
+
import { readFileSync as readFileSync8 } from "fs";
|
|
35350
|
+
import { join as join10 } from "path";
|
|
35835
35351
|
var BREAKER_COOLDOWN_MS = 3e4;
|
|
35836
35352
|
function parseForwardHealth(raw, nowMs) {
|
|
35837
35353
|
try {
|
|
@@ -35855,20 +35371,21 @@ function isForwardPaused(health, nowMs) {
|
|
|
35855
35371
|
|
|
35856
35372
|
// ../../packages/persistence/src/history-backfill.ts
|
|
35857
35373
|
import { existsSync as existsSync4 } from "fs";
|
|
35858
|
-
import { join as
|
|
35374
|
+
import { join as join11 } from "path";
|
|
35859
35375
|
|
|
35860
35376
|
// ../../packages/persistence/src/history-preview.ts
|
|
35861
35377
|
import { existsSync as existsSync5 } from "fs";
|
|
35862
|
-
import { join as
|
|
35863
|
-
import { DatabaseSync as
|
|
35378
|
+
import { join as join12 } from "path";
|
|
35379
|
+
import { DatabaseSync as DatabaseSync2 } from "node:sqlite";
|
|
35864
35380
|
|
|
35865
35381
|
// ../../packages/persistence/src/history-sync-state.ts
|
|
35866
|
-
import { readFileSync as
|
|
35867
|
-
import { join as
|
|
35382
|
+
import { readFileSync as readFileSync9 } from "fs";
|
|
35383
|
+
import { join as join13 } from "path";
|
|
35384
|
+
var COUNTS_SCOPES = new Set(AttachmentMode.options);
|
|
35868
35385
|
|
|
35869
35386
|
// ../../packages/persistence/src/store-symlinks.ts
|
|
35870
35387
|
import { existsSync as existsSync6, lstatSync as lstatSync3, readlinkSync, realpathSync, statSync as statSync4 } from "fs";
|
|
35871
|
-
import { dirname as dirname3, join as
|
|
35388
|
+
import { dirname as dirname3, join as join14, resolve } from "path";
|
|
35872
35389
|
|
|
35873
35390
|
// ../../packages/persistence/src/vault/crypto.ts
|
|
35874
35391
|
import {
|
|
@@ -35882,19 +35399,19 @@ import {
|
|
|
35882
35399
|
// ../../packages/persistence/src/vault/key-provider.ts
|
|
35883
35400
|
import { execFileSync } from "child_process";
|
|
35884
35401
|
import { randomBytes as randomBytes2 } from "crypto";
|
|
35885
|
-
import { chmodSync as chmodSync3, readFileSync as
|
|
35886
|
-
import { join as
|
|
35402
|
+
import { chmodSync as chmodSync3, readFileSync as readFileSync10, renameSync as renameSync4, rmSync as rmSync6, statSync as statSync5, writeFileSync as writeFileSync3 } from "fs";
|
|
35403
|
+
import { join as join15 } from "path";
|
|
35887
35404
|
|
|
35888
35405
|
// ../../packages/persistence/src/vault/vault.ts
|
|
35889
35406
|
import { randomBytes as randomBytes3, randomUUID as randomUUID12 } from "crypto";
|
|
35890
35407
|
|
|
35891
35408
|
// ../../packages/persistence/src/warn-era-cap.ts
|
|
35892
35409
|
import { existsSync as existsSync7, writeFileSync as writeFileSync4 } from "fs";
|
|
35893
|
-
import { join as
|
|
35410
|
+
import { join as join16 } from "path";
|
|
35894
35411
|
var MARKER = "warn-era-capped";
|
|
35895
35412
|
function capWarnEraEnforcementOnce(db, policyMode, dataDir2) {
|
|
35896
35413
|
if (policyMode !== "warn") return { capped: 0, skipped: "not-warn" };
|
|
35897
|
-
const marker =
|
|
35414
|
+
const marker = join16(dataDir2, MARKER);
|
|
35898
35415
|
if (existsSync7(marker)) return { capped: 0, skipped: "already-run" };
|
|
35899
35416
|
const capped = db.policies.capCategoryActions();
|
|
35900
35417
|
writeFileSync4(marker, `${new Date(Date.now()).toISOString()}
|
|
@@ -35902,425 +35419,6 @@ function capWarnEraEnforcementOnce(db, policyMode, dataDir2) {
|
|
|
35902
35419
|
return { capped };
|
|
35903
35420
|
}
|
|
35904
35421
|
|
|
35905
|
-
// ../../packages/remote/src/http.ts
|
|
35906
|
-
import { request as httpRequest } from "http";
|
|
35907
|
-
import { request as httpsRequest } from "https";
|
|
35908
|
-
var DEFAULT_TIMEOUT_MS = 1e4;
|
|
35909
|
-
var MAX_RESPONSE_BYTES = 8 * 1024 * 1024;
|
|
35910
|
-
var RemoteRequestError = class extends Error {
|
|
35911
|
-
constructor(status) {
|
|
35912
|
-
super(`control-plane request failed with status ${String(status)}`);
|
|
35913
|
-
this.status = status;
|
|
35914
|
-
this.name = "RemoteRequestError";
|
|
35915
|
-
}
|
|
35916
|
-
status;
|
|
35917
|
-
};
|
|
35918
|
-
var RemoteRouteAbsent = class extends Error {
|
|
35919
|
-
constructor(route) {
|
|
35920
|
-
super(`control plane does not serve ${route}`);
|
|
35921
|
-
this.route = route;
|
|
35922
|
-
this.name = "RemoteRouteAbsent";
|
|
35923
|
-
}
|
|
35924
|
-
route;
|
|
35925
|
-
};
|
|
35926
|
-
var RemoteRequestInvalid = class extends Error {
|
|
35927
|
-
constructor(route, cause) {
|
|
35928
|
-
super(`refusing to send a malformed body to ${route}`);
|
|
35929
|
-
this.cause = cause;
|
|
35930
|
-
this.name = "RemoteRequestInvalid";
|
|
35931
|
-
}
|
|
35932
|
-
cause;
|
|
35933
|
-
};
|
|
35934
|
-
var RemoteEndpointRefused = class extends Error {
|
|
35935
|
-
constructor(endpoint) {
|
|
35936
|
-
super(`refusing to talk to an unsafe control-plane endpoint: ${originOnly(endpoint)}`);
|
|
35937
|
-
this.name = "RemoteEndpointRefused";
|
|
35938
|
-
}
|
|
35939
|
-
};
|
|
35940
|
-
var RemoteResponseInvalid = class extends Error {
|
|
35941
|
-
constructor(route, detail) {
|
|
35942
|
-
super(`control plane answered ${route} with ${detail}`);
|
|
35943
|
-
this.name = "RemoteResponseInvalid";
|
|
35944
|
-
}
|
|
35945
|
-
};
|
|
35946
|
-
var RemoteTransportError = class extends Error {
|
|
35947
|
-
/**
|
|
35948
|
-
* The status the peer sent, when headers arrived and only the BODY was
|
|
35949
|
-
* refused.
|
|
35950
|
-
*
|
|
35951
|
-
* Undefined for the ordinary case this class was written for — no answer at
|
|
35952
|
-
* all. It exists because two paths reject after a status has already been
|
|
35953
|
-
* delivered: an oversized body and an aborted response. Discarding it there
|
|
35954
|
-
* reported a deployment answering 401 with a verbose body as a network
|
|
35955
|
-
* outage, which sends the reader to look at their network instead of their
|
|
35956
|
-
* credential.
|
|
35957
|
-
*/
|
|
35958
|
-
constructor(reason, status) {
|
|
35959
|
-
super(`control-plane request did not complete: ${reason}`);
|
|
35960
|
-
this.status = status;
|
|
35961
|
-
this.name = "RemoteTransportError";
|
|
35962
|
-
}
|
|
35963
|
-
status;
|
|
35964
|
-
};
|
|
35965
|
-
async function send(options) {
|
|
35966
|
-
const url2 = new URL(options.url);
|
|
35967
|
-
const timeoutMs = options.timeoutMs ?? DEFAULT_TIMEOUT_MS;
|
|
35968
|
-
const send_ = url2.protocol === "http:" ? httpRequest : httpsRequest;
|
|
35969
|
-
const requestOptions = {
|
|
35970
|
-
method: options.method,
|
|
35971
|
-
headers: {
|
|
35972
|
-
// CALLER HEADERS FIRST, so this module's own are not overridable. Spread
|
|
35973
|
-
// last they win, and two of the values below are ones no caller may
|
|
35974
|
-
// replace: `x-api-key` is the credential, and `content-length` is the
|
|
35975
|
-
// byte count that stops a multi-byte body being truncated by the
|
|
35976
|
-
// receiver. `SendOptions.headers` is a free-form record on an exported
|
|
35977
|
-
// function, so "no caller does that today" is not the guarantee to rely
|
|
35978
|
-
// on. The one header any caller actually passes — `if-none-match` on the
|
|
35979
|
-
// conditional GET — is untouched by this order.
|
|
35980
|
-
...options.headers,
|
|
35981
|
-
// The credential. One header, matching what the deployment authenticates
|
|
35982
|
-
// on; a second copy in an `Authorization` header would be one more place
|
|
35983
|
-
// it can be logged by an intermediary for no gain.
|
|
35984
|
-
//
|
|
35985
|
-
// Spread conditionally rather than assigned as `undefined`: Node's header
|
|
35986
|
-
// handling and `content-length` bookkeeping treat a present-but-undefined
|
|
35987
|
-
// key differently from an absent one, and "the header is not there" is
|
|
35988
|
-
// the property the attach flow needs.
|
|
35989
|
-
...options.apiKey === void 0 ? {} : { "x-api-key": options.apiKey },
|
|
35990
|
-
accept: "application/json",
|
|
35991
|
-
...options.body === void 0 ? {} : {
|
|
35992
|
-
"content-type": "application/json",
|
|
35993
|
-
// Byte length, not string length: a multi-byte body sent with a
|
|
35994
|
-
// character count is truncated by the receiver.
|
|
35995
|
-
"content-length": String(Buffer.byteLength(options.body))
|
|
35996
|
-
}
|
|
35997
|
-
}
|
|
35998
|
-
};
|
|
35999
|
-
return new Promise((resolve3, reject) => {
|
|
36000
|
-
let settled = false;
|
|
36001
|
-
const fail = (reason, status) => {
|
|
36002
|
-
if (settled) return;
|
|
36003
|
-
settled = true;
|
|
36004
|
-
reject(new RemoteTransportError(reason, status));
|
|
36005
|
-
};
|
|
36006
|
-
const req = send_(url2, requestOptions, (res) => {
|
|
36007
|
-
const chunks = [];
|
|
36008
|
-
let size = 0;
|
|
36009
|
-
res.on("data", (chunk) => {
|
|
36010
|
-
size += chunk.length;
|
|
36011
|
-
if (size > MAX_RESPONSE_BYTES) {
|
|
36012
|
-
fail(`response exceeded ${String(MAX_RESPONSE_BYTES)} bytes`, res.statusCode);
|
|
36013
|
-
res.destroy();
|
|
36014
|
-
req.destroy();
|
|
36015
|
-
return;
|
|
36016
|
-
}
|
|
36017
|
-
chunks.push(chunk);
|
|
36018
|
-
});
|
|
36019
|
-
res.on("aborted", () => {
|
|
36020
|
-
fail("the response was aborted", res.statusCode);
|
|
36021
|
-
});
|
|
36022
|
-
res.on("end", () => {
|
|
36023
|
-
if (settled) return;
|
|
36024
|
-
settled = true;
|
|
36025
|
-
resolve3({
|
|
36026
|
-
status: res.statusCode ?? 0,
|
|
36027
|
-
headers: res.headers,
|
|
36028
|
-
body: Buffer.concat(chunks).toString("utf8")
|
|
36029
|
-
});
|
|
36030
|
-
});
|
|
36031
|
-
});
|
|
36032
|
-
const deadline = setTimeout(() => {
|
|
36033
|
-
fail(`no response within ${String(timeoutMs)}ms`);
|
|
36034
|
-
req.destroy();
|
|
36035
|
-
}, timeoutMs);
|
|
36036
|
-
deadline.unref();
|
|
36037
|
-
req.on("upgrade", (_res, socket) => {
|
|
36038
|
-
fail("the deployment answered with a protocol upgrade");
|
|
36039
|
-
socket.destroy();
|
|
36040
|
-
});
|
|
36041
|
-
req.on("close", () => {
|
|
36042
|
-
fail("the connection closed before a response was read");
|
|
36043
|
-
clearTimeout(deadline);
|
|
36044
|
-
});
|
|
36045
|
-
req.on("error", (err) => {
|
|
36046
|
-
fail(err.message);
|
|
36047
|
-
});
|
|
36048
|
-
if (options.body !== void 0) req.write(options.body);
|
|
36049
|
-
req.end();
|
|
36050
|
-
});
|
|
36051
|
-
}
|
|
36052
|
-
|
|
36053
|
-
// ../../packages/remote/src/client.ts
|
|
36054
|
-
var ROUTES = {
|
|
36055
|
-
events: "/v1/events",
|
|
36056
|
-
auditEvents: "/v1/audit-events",
|
|
36057
|
-
auditEventsBatch: "/v1/audit-events/batch",
|
|
36058
|
-
inventory: "/v1/inventory",
|
|
36059
|
-
storePosture: "/v1/store-posture",
|
|
36060
|
-
policyBundle: "/v1/policy-bundle",
|
|
36061
|
-
whoami: "/v1/plugin/whoami",
|
|
36062
|
-
shares: "/v1/shares",
|
|
36063
|
-
commands: "/v1/plugin/commands"
|
|
36064
|
-
};
|
|
36065
|
-
function ackRoute(id) {
|
|
36066
|
-
return `${ROUTES.commands}/${encodeURIComponent(id)}/ack`;
|
|
36067
|
-
}
|
|
36068
|
-
function headerValue(response, name) {
|
|
36069
|
-
const raw = response.headers[name];
|
|
36070
|
-
if (raw === void 0) return void 0;
|
|
36071
|
-
return Array.isArray(raw) ? raw[0] : raw;
|
|
36072
|
-
}
|
|
36073
|
-
function okBody(response) {
|
|
36074
|
-
if (response.status < 200 || response.status >= 300) {
|
|
36075
|
-
throw new RemoteRequestError(response.status);
|
|
36076
|
-
}
|
|
36077
|
-
return response.body;
|
|
36078
|
-
}
|
|
36079
|
-
function parsed(schema, body, route) {
|
|
36080
|
-
let json2;
|
|
36081
|
-
try {
|
|
36082
|
-
json2 = JSON.parse(body);
|
|
36083
|
-
} catch {
|
|
36084
|
-
throw new RemoteResponseInvalid(route, "a body that is not JSON");
|
|
36085
|
-
}
|
|
36086
|
-
const result = schema.safeParse(json2);
|
|
36087
|
-
if (!result.success) {
|
|
36088
|
-
throw new RemoteResponseInvalid(route, "a body this client cannot read");
|
|
36089
|
-
}
|
|
36090
|
-
return result.data;
|
|
36091
|
-
}
|
|
36092
|
-
function resolveBaseUrl(endpoint) {
|
|
36093
|
-
if (!isSafeEndpoint(endpoint)) throw new RemoteEndpointRefused(endpoint);
|
|
36094
|
-
let end = endpoint.length;
|
|
36095
|
-
while (end > 0 && endpoint.charCodeAt(end - 1) === SLASH2) end -= 1;
|
|
36096
|
-
return endpoint.slice(0, end);
|
|
36097
|
-
}
|
|
36098
|
-
var SLASH2 = "/".charCodeAt(0);
|
|
36099
|
-
function createRemoteClient(options) {
|
|
36100
|
-
const base = resolveBaseUrl(options.endpoint);
|
|
36101
|
-
const url2 = (route) => `${base}${route}`;
|
|
36102
|
-
const common = { apiKey: options.apiKey, timeoutMs: options.timeoutMs };
|
|
36103
|
-
const sendOne = async (event) => {
|
|
36104
|
-
const validated = RecordAuditEventRequest.safeParse(event);
|
|
36105
|
-
if (!validated.success) throw new RemoteRequestInvalid(ROUTES.auditEvents, validated.error);
|
|
36106
|
-
const response = await send({
|
|
36107
|
-
...common,
|
|
36108
|
-
method: "POST",
|
|
36109
|
-
url: url2(ROUTES.auditEvents),
|
|
36110
|
-
body: JSON.stringify(validated.data)
|
|
36111
|
-
});
|
|
36112
|
-
okBody(response);
|
|
36113
|
-
};
|
|
36114
|
-
return {
|
|
36115
|
-
async ingestEvents(batch) {
|
|
36116
|
-
const response = await send({
|
|
36117
|
-
...common,
|
|
36118
|
-
method: "POST",
|
|
36119
|
-
url: url2(ROUTES.events),
|
|
36120
|
-
body: JSON.stringify(batch)
|
|
36121
|
-
});
|
|
36122
|
-
return parsed(IngestAck, okBody(response), ROUTES.events);
|
|
36123
|
-
},
|
|
36124
|
-
async ingestInventory(context) {
|
|
36125
|
-
const response = await send({
|
|
36126
|
-
...common,
|
|
36127
|
-
method: "POST",
|
|
36128
|
-
url: url2(ROUTES.inventory),
|
|
36129
|
-
body: JSON.stringify(context)
|
|
36130
|
-
});
|
|
36131
|
-
return parsed(ResolvedInventory, okBody(response), ROUTES.inventory);
|
|
36132
|
-
},
|
|
36133
|
-
async recordAuditEvent(event) {
|
|
36134
|
-
await sendOne(event);
|
|
36135
|
-
},
|
|
36136
|
-
async recordAuditEvents(events, opts) {
|
|
36137
|
-
const validated = RecordAuditEventBatch.safeParse({ events });
|
|
36138
|
-
if (!validated.success) {
|
|
36139
|
-
throw new RemoteRequestInvalid(ROUTES.auditEventsBatch, validated.error);
|
|
36140
|
-
}
|
|
36141
|
-
const response = await send({
|
|
36142
|
-
...common,
|
|
36143
|
-
method: "POST",
|
|
36144
|
-
url: url2(ROUTES.auditEventsBatch),
|
|
36145
|
-
body: JSON.stringify(validated.data)
|
|
36146
|
-
});
|
|
36147
|
-
if (response.status === 404) {
|
|
36148
|
-
if (opts?.fallbackToSingleEvents !== true) {
|
|
36149
|
-
throw new RemoteRouteAbsent(ROUTES.auditEventsBatch);
|
|
36150
|
-
}
|
|
36151
|
-
for (const event of validated.data.events) await sendOne(event);
|
|
36152
|
-
return { accepted: validated.data.events.length };
|
|
36153
|
-
}
|
|
36154
|
-
return parsed(AuditEventBatchAck, okBody(response), ROUTES.auditEventsBatch);
|
|
36155
|
-
},
|
|
36156
|
-
async reportStorePosture(snapshot) {
|
|
36157
|
-
const response = await send({
|
|
36158
|
-
...common,
|
|
36159
|
-
method: "POST",
|
|
36160
|
-
url: url2(ROUTES.storePosture),
|
|
36161
|
-
body: JSON.stringify(snapshot)
|
|
36162
|
-
});
|
|
36163
|
-
okBody(response);
|
|
36164
|
-
},
|
|
36165
|
-
async getPolicyBundle(etag) {
|
|
36166
|
-
const response = await send({
|
|
36167
|
-
...common,
|
|
36168
|
-
method: "GET",
|
|
36169
|
-
url: url2(ROUTES.policyBundle),
|
|
36170
|
-
...etag === void 0 ? {} : { headers: { "if-none-match": etag } }
|
|
36171
|
-
});
|
|
36172
|
-
if (response.status === 304) {
|
|
36173
|
-
return { changed: false, etag: headerValue(response, "etag") ?? etag };
|
|
36174
|
-
}
|
|
36175
|
-
const bundle = parsed(PolicyBundle, okBody(response), ROUTES.policyBundle);
|
|
36176
|
-
return { changed: true, bundle, etag: headerValue(response, "etag") };
|
|
36177
|
-
},
|
|
36178
|
-
async whoami() {
|
|
36179
|
-
const response = await send({ ...common, method: "GET", url: url2(ROUTES.whoami) });
|
|
36180
|
-
return parsed(PluginWhoami, okBody(response), ROUTES.whoami);
|
|
36181
|
-
},
|
|
36182
|
-
async recordProjectEgress(request) {
|
|
36183
|
-
const validated = EgressIngestRequest.safeParse(request);
|
|
36184
|
-
if (!validated.success) throw new RemoteRequestInvalid(ROUTES.shares, validated.error);
|
|
36185
|
-
const response = await send({
|
|
36186
|
-
...common,
|
|
36187
|
-
method: "POST",
|
|
36188
|
-
url: url2(ROUTES.shares),
|
|
36189
|
-
body: JSON.stringify(validated.data)
|
|
36190
|
-
});
|
|
36191
|
-
if (response.status === 404) throw new RemoteRouteAbsent(ROUTES.shares);
|
|
36192
|
-
okBody(response);
|
|
36193
|
-
},
|
|
36194
|
-
async pollCommand() {
|
|
36195
|
-
const response = await send({ ...common, method: "GET", url: url2(ROUTES.commands) });
|
|
36196
|
-
if (response.status === 404) return null;
|
|
36197
|
-
return parsed(DeviceCommandPollResponse, okBody(response), ROUTES.commands).command;
|
|
36198
|
-
},
|
|
36199
|
-
async ackCommand(id, body) {
|
|
36200
|
-
const validated = DeviceCommandAckBody.safeParse(body);
|
|
36201
|
-
const route = ackRoute(id);
|
|
36202
|
-
if (!validated.success) throw new RemoteRequestInvalid(route, validated.error);
|
|
36203
|
-
const response = await send({
|
|
36204
|
-
...common,
|
|
36205
|
-
method: "POST",
|
|
36206
|
-
url: url2(route),
|
|
36207
|
-
body: JSON.stringify(validated.data)
|
|
36208
|
-
});
|
|
36209
|
-
okBody(response);
|
|
36210
|
-
}
|
|
36211
|
-
};
|
|
36212
|
-
}
|
|
36213
|
-
|
|
36214
|
-
// ../../packages/remote/src/failure-kind.ts
|
|
36215
|
-
function statusOf(err) {
|
|
36216
|
-
if (typeof err !== "object" || err === null || !("status" in err)) return null;
|
|
36217
|
-
const { status } = err;
|
|
36218
|
-
if (typeof status !== "number" || !Number.isInteger(status)) return null;
|
|
36219
|
-
return status >= 100 && status <= 599 ? status : null;
|
|
36220
|
-
}
|
|
36221
|
-
function nameOf(err) {
|
|
36222
|
-
if (typeof err !== "object" || err === null || !("name" in err)) return null;
|
|
36223
|
-
return typeof err.name === "string" ? err.name : null;
|
|
36224
|
-
}
|
|
36225
|
-
function classifyRemoteFailure(err) {
|
|
36226
|
-
switch (nameOf(err)) {
|
|
36227
|
-
case "RemoteRouteAbsent":
|
|
36228
|
-
return "route-absent";
|
|
36229
|
-
case "RemoteRequestInvalid":
|
|
36230
|
-
case "RemoteEndpointRefused":
|
|
36231
|
-
return "invalid-request";
|
|
36232
|
-
case "RemoteResponseInvalid":
|
|
36233
|
-
return "rejected";
|
|
36234
|
-
default:
|
|
36235
|
-
break;
|
|
36236
|
-
}
|
|
36237
|
-
const status = statusOf(err);
|
|
36238
|
-
if (status === null) return "unreachable";
|
|
36239
|
-
switch (status) {
|
|
36240
|
-
case 401:
|
|
36241
|
-
return "unauthorized";
|
|
36242
|
-
case 403:
|
|
36243
|
-
return "forbidden";
|
|
36244
|
-
case 429:
|
|
36245
|
-
return "unreachable";
|
|
36246
|
-
case 404:
|
|
36247
|
-
return "unreachable";
|
|
36248
|
-
default:
|
|
36249
|
-
return status >= 400 && status <= 499 ? "rejected" : "unreachable";
|
|
36250
|
-
}
|
|
36251
|
-
}
|
|
36252
|
-
|
|
36253
|
-
// ../../packages/plugin-runtime/src/attached/failure.ts
|
|
36254
|
-
function classifyFailure(err) {
|
|
36255
|
-
switch (classifyRemoteFailure(err)) {
|
|
36256
|
-
case "unauthorized":
|
|
36257
|
-
return "unauthorized";
|
|
36258
|
-
case "forbidden":
|
|
36259
|
-
return "forbidden";
|
|
36260
|
-
default:
|
|
36261
|
-
return "unreachable";
|
|
36262
|
-
}
|
|
36263
|
-
}
|
|
36264
|
-
|
|
36265
|
-
// ../../packages/plugin-runtime/src/attached/with-timeout.ts
|
|
36266
|
-
var REQUEST_TIMEOUT_MS = 2e3;
|
|
36267
|
-
function withTimeout(promise2, ms) {
|
|
36268
|
-
let timer;
|
|
36269
|
-
const timeout = new Promise((_, reject) => {
|
|
36270
|
-
timer = setTimeout(() => {
|
|
36271
|
-
reject(new Error("attached gateway request timed out"));
|
|
36272
|
-
}, ms);
|
|
36273
|
-
});
|
|
36274
|
-
promise2.catch(() => void 0);
|
|
36275
|
-
return Promise.race([promise2, timeout]).finally(() => {
|
|
36276
|
-
clearTimeout(timer);
|
|
36277
|
-
});
|
|
36278
|
-
}
|
|
36279
|
-
|
|
36280
|
-
// ../../packages/plugin-runtime/src/attached/forward-drops.ts
|
|
36281
|
-
import { readFileSync as readFileSync10 } from "fs";
|
|
36282
|
-
import { join as join16 } from "path";
|
|
36283
|
-
var FORWARD_DROPS_FILENAME = ATTACHED_FORWARD_DROPS_FILENAME;
|
|
36284
|
-
function forwardDropsPath(dataDir2) {
|
|
36285
|
-
return join16(dataDir2, FORWARD_DROPS_FILENAME);
|
|
36286
|
-
}
|
|
36287
|
-
function recordForwardDrops(dataDir2, count, nowMs) {
|
|
36288
|
-
if (count <= 0) return;
|
|
36289
|
-
try {
|
|
36290
|
-
ensureDataDirSync(dataDir2);
|
|
36291
|
-
const previous = readForwardDrops(dataDir2);
|
|
36292
|
-
const next = {
|
|
36293
|
-
droppedForwards: (previous?.droppedForwards ?? 0) + count,
|
|
36294
|
-
lastDropAtMs: nowMs
|
|
36295
|
-
};
|
|
36296
|
-
writeOwnerOnlyFileSync(forwardDropsPath(dataDir2), `${JSON.stringify(next)}
|
|
36297
|
-
`);
|
|
36298
|
-
} catch {
|
|
36299
|
-
}
|
|
36300
|
-
}
|
|
36301
|
-
function readForwardDrops(dataDir2) {
|
|
36302
|
-
try {
|
|
36303
|
-
const parsed2 = JSON.parse(readFileSync10(forwardDropsPath(dataDir2), "utf8"));
|
|
36304
|
-
if (typeof parsed2 !== "object" || parsed2 === null) return null;
|
|
36305
|
-
const record2 = parsed2;
|
|
36306
|
-
if (typeof record2.droppedForwards !== "number" || !Number.isFinite(record2.droppedForwards)) {
|
|
36307
|
-
return null;
|
|
36308
|
-
}
|
|
36309
|
-
if (record2.droppedForwards <= 0) return null;
|
|
36310
|
-
if (typeof record2.lastDropAtMs !== "number" || !Number.isFinite(record2.lastDropAtMs)) {
|
|
36311
|
-
return null;
|
|
36312
|
-
}
|
|
36313
|
-
return { droppedForwards: record2.droppedForwards, lastDropAtMs: record2.lastDropAtMs };
|
|
36314
|
-
} catch {
|
|
36315
|
-
return null;
|
|
36316
|
-
}
|
|
36317
|
-
}
|
|
36318
|
-
|
|
36319
|
-
// ../../packages/plugin-runtime/src/attached/forward-policy.ts
|
|
36320
|
-
import { randomUUID as randomUUID16 } from "crypto";
|
|
36321
|
-
import { readFile, rename, writeFile } from "fs/promises";
|
|
36322
|
-
import { join as join28 } from "path";
|
|
36323
|
-
|
|
36324
35422
|
// ../../packages/plugin-sdk/src/config.ts
|
|
36325
35423
|
import { existsSync as existsSync8 } from "fs";
|
|
36326
35424
|
import { join as join17 } from "path";
|
|
@@ -36400,11 +35498,6 @@ function resolveProviderSafe(resolveProviderFn) {
|
|
|
36400
35498
|
}
|
|
36401
35499
|
}
|
|
36402
35500
|
|
|
36403
|
-
// ../../packages/plugin-sdk/src/config-inventory.ts
|
|
36404
|
-
import { readdirSync as readdirSync2, readFileSync as readFileSync12, realpathSync as realpathSync2, statSync as statSync7 } from "fs";
|
|
36405
|
-
import { homedir as homedir2 } from "os";
|
|
36406
|
-
import { basename as basename3, join as join19 } from "path";
|
|
36407
|
-
|
|
36408
35501
|
// ../../packages/detections/src/egress/registry.ts
|
|
36409
35502
|
var EXTRACTOR_VERSION = "3";
|
|
36410
35503
|
var PROVIDER_REGISTRY = [
|
|
@@ -37079,12 +36172,12 @@ var RegexMatcher2 = class {
|
|
|
37079
36172
|
rule.matcher,
|
|
37080
36173
|
() => new RegExp(pattern, flags.includes("d") ? flags : `${flags}d`)
|
|
37081
36174
|
);
|
|
37082
|
-
const
|
|
36175
|
+
const scanText = text.length > MAX_REGEX_INPUT_LENGTH ? text.slice(0, MAX_REGEX_INPUT_LENGTH) : text;
|
|
37083
36176
|
const spans = [];
|
|
37084
36177
|
let m;
|
|
37085
|
-
const maxIterations =
|
|
36178
|
+
const maxIterations = scanText.length + 1;
|
|
37086
36179
|
let iterations = 0;
|
|
37087
|
-
while ((m = re.exec(
|
|
36180
|
+
while ((m = re.exec(scanText)) !== null) {
|
|
37088
36181
|
if (++iterations > maxIterations) break;
|
|
37089
36182
|
const group = captureGroup != null ? m[captureGroup] : m[0];
|
|
37090
36183
|
if (m[0].length === 0) re.lastIndex++;
|
|
@@ -37295,6 +36388,38 @@ var POLYNOMIAL_PROBES = ["abc-", "a.", "a ", "a=", "x", "0", "a@", "a/", "ab"].m
|
|
|
37295
36388
|
);
|
|
37296
36389
|
var CPU_CORROBORATION_SHARE = 0.2;
|
|
37297
36390
|
var CORROBORATION_FLOOR_MS = BUDGET_MS * CPU_CORROBORATION_SHARE;
|
|
36391
|
+
function repeatTo(unit, length) {
|
|
36392
|
+
return unit.repeat(Math.ceil(length / unit.length)).slice(0, length);
|
|
36393
|
+
}
|
|
36394
|
+
function joinTo(length, open3, close, item) {
|
|
36395
|
+
const parts = [];
|
|
36396
|
+
let size = open3.length;
|
|
36397
|
+
for (let i = 0; size < length; i++) {
|
|
36398
|
+
const next = (i === 0 ? "" : ",") + item(i);
|
|
36399
|
+
parts.push(next);
|
|
36400
|
+
size += next.length;
|
|
36401
|
+
}
|
|
36402
|
+
return (open3 + parts.join("") + close).slice(0, length);
|
|
36403
|
+
}
|
|
36404
|
+
var SQL_WORDS = ["select", "insert", "update", "delete", "drop", "where"];
|
|
36405
|
+
var GROWTH_CORPORA = [
|
|
36406
|
+
{
|
|
36407
|
+
name: "one-line JSON dictionary",
|
|
36408
|
+
build: (length) => joinTo(length, "{", "}", (i) => `"id-${String(i)}":"label ${String(i)}"`)
|
|
36409
|
+
},
|
|
36410
|
+
{
|
|
36411
|
+
name: "JSON array of quoted SQL keywords",
|
|
36412
|
+
build: (length) => joinTo(length, "[", "]", (i) => `"${SQL_WORDS[i % SQL_WORDS.length] ?? ""} ${String(i)}"`)
|
|
36413
|
+
},
|
|
36414
|
+
{ name: "single-quoted keyword run ('where)", build: (length) => repeatTo("'where", length) },
|
|
36415
|
+
{ name: "double-quote run", build: (length) => repeatTo('"', length) },
|
|
36416
|
+
{ name: "space run", build: (length) => repeatTo(" ", length) },
|
|
36417
|
+
{ name: "newline run", build: (length) => repeatTo("\n", length) },
|
|
36418
|
+
...["abc-", "a.", "a ", "a=", "x", "0", "a@", "a/", "ab"].map((unit) => ({
|
|
36419
|
+
name: `unit run ${JSON.stringify(unit)}`,
|
|
36420
|
+
build: (length) => repeatTo(unit, length)
|
|
36421
|
+
}))
|
|
36422
|
+
];
|
|
37298
36423
|
|
|
37299
36424
|
// ../../rules/code-flaws/auth-jwt-no-verify.json
|
|
37300
36425
|
var auth_jwt_no_verify_default = {
|
|
@@ -37305,7 +36430,7 @@ var auth_jwt_no_verify_default = {
|
|
|
37305
36430
|
severity: "critical",
|
|
37306
36431
|
matcher: {
|
|
37307
36432
|
type: "regex",
|
|
37308
|
-
pattern: "(verify\\s*=\\s*false|verify_signature
|
|
36433
|
+
pattern: "(verify\\s*=\\s*false|verify_signature(?:(?!verify_signature).)*false|algorithms\\s*=\\s*\\[\\])",
|
|
37309
36434
|
flags: "gi"
|
|
37310
36435
|
},
|
|
37311
36436
|
requiresNearby: {
|
|
@@ -37393,7 +36518,7 @@ var cmd_inject_shell_default = {
|
|
|
37393
36518
|
severity: "critical",
|
|
37394
36519
|
matcher: {
|
|
37395
36520
|
type: "regex",
|
|
37396
|
-
pattern: "subprocess\\.(run|Popen|call|check_output)\\s*\\([^)]*shell\\s*=\\s*True",
|
|
36521
|
+
pattern: "subprocess\\.(run|Popen|call|check_output)\\s*\\((?:(?!subprocess\\.(?:run|Popen|call|check_output)\\s*\\()[^)])*shell\\s*=\\s*True",
|
|
37397
36522
|
flags: "gi"
|
|
37398
36523
|
},
|
|
37399
36524
|
requiresNearby: {
|
|
@@ -37522,7 +36647,7 @@ var deser_yaml_unsafe_default = {
|
|
|
37522
36647
|
severity: "high",
|
|
37523
36648
|
matcher: {
|
|
37524
36649
|
type: "regex",
|
|
37525
|
-
pattern: "\\byaml\\.load\\s*\\((?![^)]
|
|
36650
|
+
pattern: "\\byaml\\.load\\s*\\((?!(?:(?!yaml\\.load\\s*\\()[^)])*?(?:SafeLoader|safe_load))",
|
|
37526
36651
|
flags: "gi"
|
|
37527
36652
|
},
|
|
37528
36653
|
examples: ["data = yaml.load(user_input)", "config = yaml.load(f)"],
|
|
@@ -37739,7 +36864,7 @@ var sql_inject_concat_dot_default = {
|
|
|
37739
36864
|
severity: "high",
|
|
37740
36865
|
matcher: {
|
|
37741
36866
|
type: "regex",
|
|
37742
|
-
pattern: `["'][
|
|
36867
|
+
pattern: `["'](?=([^"'\\n]*?(?:select|insert|update|delete|drop|where)))\\1(?:(?!["'][^"'\\n]*?(?:select|insert|update|delete|drop|where))[^\\n])*?["']\\s*\\.`,
|
|
37743
36868
|
flags: "gi"
|
|
37744
36869
|
},
|
|
37745
36870
|
appliesTo: {
|
|
@@ -37757,7 +36882,7 @@ var sql_inject_concat_default = {
|
|
|
37757
36882
|
severity: "high",
|
|
37758
36883
|
matcher: {
|
|
37759
36884
|
type: "regex",
|
|
37760
|
-
pattern: `["']\\s*(?:select\\b[^\\n]*?\\bfrom\\b|insert\\s+into\\b|update\\s+\\S+\\s+set\\b|delete\\s+from\\b|drop\\s+(?:table|database)\\b|where\\b[^\\n]*?=)[^\\n]*?["']\\s*\\+`,
|
|
36885
|
+
pattern: `(["'])\\s*(?=(select\\b(?:(?!\\1\\s*(?:select\\b|insert\\s+into\\b|update\\s+\\S+\\s+set\\b|delete\\s+from\\b|drop\\s+(?:table|database)\\b|where\\b))[^\\n])*?\\bfrom\\b|insert\\s+into\\b|update\\s+\\S+\\s+set\\b|delete\\s+from\\b|drop\\s+(?:table|database)\\b|where\\b(?:(?!\\1\\s*(?:select\\b|insert\\s+into\\b|update\\s+\\S+\\s+set\\b|delete\\s+from\\b|drop\\s+(?:table|database)\\b|where\\b))[^\\n])*?=))\\2(?:(?!\\1\\s*(?:select\\b|insert\\s+into\\b|update\\s+\\S+\\s+set\\b|delete\\s+from\\b|drop\\s+(?:table|database)\\b|where\\b))[^\\n])*?["']\\s*\\+`,
|
|
37761
36886
|
flags: "gi"
|
|
37762
36887
|
},
|
|
37763
36888
|
examples: ['"SELECT * FROM users WHERE id = " + userId']
|
|
@@ -37772,7 +36897,7 @@ var sql_inject_format_default = {
|
|
|
37772
36897
|
severity: "high",
|
|
37773
36898
|
matcher: {
|
|
37774
36899
|
type: "regex",
|
|
37775
|
-
pattern: "\\b(?:select\\b[^\\n]*?\\bfrom\\b|insert\\s+into\\b|update\\s+\\S+\\s+set\\b|delete\\s+from\\b|drop\\s+(?:table|database)\\b|where\\b[^\\n]*?=)[^\\n]*?(?:[%][sd]|\\{[^}]+\\})",
|
|
36900
|
+
pattern: "\\b(?=(select\\b(?:(?!\\b(?:select\\b|insert\\s+into\\b|update\\s+\\S+\\s+set\\b|delete\\s+from\\b|drop\\s+(?:table|database)\\b))[^\\n])*?\\bfrom\\b|insert\\s+into\\b|update\\s+\\S+\\s+set\\b|delete\\s+from\\b|drop\\s+(?:table|database)\\b))\\1(?:(?!\\b(?:select\\b|insert\\s+into\\b|update\\s+\\S+\\s+set\\b|delete\\s+from\\b|drop\\s+(?:table|database)\\b))[^\\n])*?(?:[%][sd]|\\{[^{}\\n]+\\})|\\b(?=(where\\b(?:(?!\\bwhere\\b)[^\\n])*?=))\\2(?:(?!\\bwhere\\b)[^\\n])*?(?:[%][sd]|\\{[^{}\\n]+\\})",
|
|
37776
36901
|
flags: "gi"
|
|
37777
36902
|
},
|
|
37778
36903
|
examples: [
|
|
@@ -37790,7 +36915,7 @@ var sql_inject_interp_default = {
|
|
|
37790
36915
|
severity: "high",
|
|
37791
36916
|
matcher: {
|
|
37792
36917
|
type: "regex",
|
|
37793
|
-
pattern: "(select|insert|update|delete|where)[^\\n]*?(#\\{|\\$[a-z_])",
|
|
36918
|
+
pattern: "(select|insert|update|delete|where)(?:(?!(?:select|insert|update|delete|where))[^\\n])*?(#\\{|\\$[a-z_])",
|
|
37794
36919
|
flags: "gi"
|
|
37795
36920
|
},
|
|
37796
36921
|
examples: [
|
|
@@ -38165,7 +37290,7 @@ var stack_trace_default = {
|
|
|
38165
37290
|
severity: "low",
|
|
38166
37291
|
matcher: {
|
|
38167
37292
|
type: "regex",
|
|
38168
|
-
pattern: "(
|
|
37293
|
+
pattern: "(?:^|(?<!\\s)\\s+)at\\s+[A-Za-z0-9._$<>]+\\.[A-Za-z0-9_$]+\\s*\\([A-Za-z0-9._\\-/:]+:\\d+:\\d+\\)",
|
|
38169
37294
|
flags: "g"
|
|
38170
37295
|
},
|
|
38171
37296
|
examples: ["at com.example.service.UserService.findUser(UserService.java:42:13)"]
|
|
@@ -39323,7 +38448,7 @@ var BUNDLED_PACKS = [
|
|
|
39323
38448
|
{
|
|
39324
38449
|
packId: "code-flaws",
|
|
39325
38450
|
name: "Code Security Flaws",
|
|
39326
|
-
version: "0.1.
|
|
38451
|
+
version: "0.1.1",
|
|
39327
38452
|
rawRules: [
|
|
39328
38453
|
sql_inject_concat_default,
|
|
39329
38454
|
sql_inject_concat_dot_default,
|
|
@@ -39373,7 +38498,7 @@ var BUNDLED_PACKS = [
|
|
|
39373
38498
|
{
|
|
39374
38499
|
packId: "core-code-context",
|
|
39375
38500
|
name: "Code Context",
|
|
39376
|
-
version: "0.2.
|
|
38501
|
+
version: "0.2.2",
|
|
39377
38502
|
rawRules: [
|
|
39378
38503
|
internal_ip_default,
|
|
39379
38504
|
localhost_ref_default,
|
|
@@ -39503,146 +38628,446 @@ function bundledDetections() {
|
|
|
39503
38628
|
}));
|
|
39504
38629
|
return cachedDetections;
|
|
39505
38630
|
}
|
|
39506
|
-
|
|
39507
|
-
|
|
39508
|
-
|
|
39509
|
-
|
|
39510
|
-
|
|
38631
|
+
function shippedRegexMatchers() {
|
|
38632
|
+
return bundledDetections().flatMap((pack) => pack.rules).flatMap(
|
|
38633
|
+
(rule) => rule.matcher.type === "regex" ? [{ pattern: rule.matcher.pattern, flags: rule.matcher.flags }] : []
|
|
38634
|
+
);
|
|
38635
|
+
}
|
|
39511
38636
|
|
|
39512
38637
|
// ../../packages/plugin-sdk/src/data-gateway.ts
|
|
39513
38638
|
function offersCaptureStatusReader(gateway) {
|
|
39514
38639
|
return typeof gateway.readCaptureStatuses === "function";
|
|
39515
38640
|
}
|
|
39516
38641
|
|
|
39517
|
-
// ../../packages/plugin-sdk/src/events.ts
|
|
39518
|
-
import { createHash as createHash5, randomUUID as randomUUID13 } from "crypto";
|
|
39519
|
-
|
|
39520
|
-
// ../../packages/plugin-sdk/src/isolated-scan.ts
|
|
39521
|
-
import { existsSync as existsSync10 } from "fs";
|
|
39522
|
-
import { fileURLToPath } from "url";
|
|
39523
|
-
import { Worker } from "worker_threads";
|
|
39524
|
-
|
|
39525
|
-
// ../../packages/plugin-sdk/src/hook-fail-opens.ts
|
|
39526
|
-
import { readFileSync as readFileSync13 } from "fs";
|
|
39527
|
-
import { join as join20 } from "path";
|
|
39528
|
-
|
|
39529
|
-
// ../../packages/plugin-sdk/src/host-floor.ts
|
|
39530
|
-
import { readFileSync as readFileSync15 } from "fs";
|
|
39531
|
-
import { join as join22 } from "path";
|
|
39532
|
-
|
|
39533
|
-
// ../../packages/plugin-sdk/src/model-governance.ts
|
|
39534
|
-
import {
|
|
39535
|
-
closeSync as closeSync2,
|
|
39536
|
-
fstatSync,
|
|
39537
|
-
mkdirSync as mkdirSync2,
|
|
39538
|
-
openSync as openSync2,
|
|
39539
|
-
readFileSync as readFileSync14,
|
|
39540
|
-
readSync,
|
|
39541
|
-
writeFileSync as writeFileSync5
|
|
39542
|
-
} from "fs";
|
|
39543
|
-
import { join as join21 } from "path";
|
|
39544
|
-
var TAIL_BYTES = 256 * 1024;
|
|
39545
|
-
|
|
39546
|
-
// ../../packages/plugin-sdk/src/host-floor.ts
|
|
39547
|
-
var HOST_FEATURE = {
|
|
39548
|
-
ModelSwitch: "model-switch",
|
|
39549
|
-
VaultPointerDisplay: "vault-pointer-display"
|
|
39550
|
-
};
|
|
39551
|
-
var HOST_FLOORS = {
|
|
39552
|
-
[HOST_FEATURE.ModelSwitch]: {
|
|
39553
|
-
label: "model-switch protection",
|
|
39554
|
-
hookEvents: ["PreModelSwitch", "PostModelSwitch"],
|
|
39555
|
-
since: "2.1.251"
|
|
39556
|
-
},
|
|
39557
|
-
[HOST_FEATURE.VaultPointerDisplay]: {
|
|
39558
|
-
label: "vault pointer display",
|
|
39559
|
-
hookEvents: ["MessageDisplay"],
|
|
39560
|
-
since: "2.1.152"
|
|
39561
|
-
}
|
|
39562
|
-
};
|
|
39563
|
-
var ANTIGRAVITY_HOST_FEATURE = {
|
|
39564
|
-
EndOfTurnCapture: "end-of-turn-capture"
|
|
39565
|
-
};
|
|
39566
|
-
var ANTIGRAVITY_HOST_FLOORS = {
|
|
39567
|
-
[ANTIGRAVITY_HOST_FEATURE.EndOfTurnCapture]: {
|
|
39568
|
-
label: "end-of-turn history capture",
|
|
39569
|
-
hookEvents: ["Stop"],
|
|
39570
|
-
since: "1.1.10"
|
|
39571
|
-
}
|
|
39572
|
-
};
|
|
39573
|
-
|
|
39574
|
-
// ../../packages/plugin-sdk/src/ignore-layers.ts
|
|
39575
|
-
var import_ignore = __toESM(require_ignore(), 1);
|
|
39576
|
-
import { readFileSync as readFileSync16 } from "fs";
|
|
39577
|
-
import { join as join23 } from "path";
|
|
39578
|
-
|
|
39579
|
-
// ../../packages/plugin-sdk/src/inventory-resolver.ts
|
|
39580
|
-
import { arch, hostname as hostname4, platform, release } from "os";
|
|
39581
|
-
|
|
39582
|
-
// ../../packages/plugin-sdk/src/nudge.ts
|
|
39583
|
-
import { mkdirSync as mkdirSync3, readFileSync as readFileSync17, writeFileSync as writeFileSync6 } from "fs";
|
|
39584
|
-
import { join as join24 } from "path";
|
|
39585
|
-
|
|
39586
|
-
// ../../packages/plugin-sdk/src/paths.ts
|
|
39587
|
-
import { readdirSync as readdirSync3, realpathSync as realpathSync3 } from "fs";
|
|
39588
|
-
import { basename as basename4, dirname as dirname5, sep as sep3 } from "path";
|
|
39589
|
-
|
|
39590
38642
|
// ../../packages/plugin-sdk/src/policy-resolver.ts
|
|
39591
|
-
import { randomUUID as
|
|
38643
|
+
import { randomUUID as randomUUID13 } from "crypto";
|
|
39592
38644
|
function assignedRulePolicies(installed) {
|
|
39593
38645
|
const out = [];
|
|
39594
38646
|
for (const [ruleId, action] of installed.ruleActions) {
|
|
39595
38647
|
if (installed.assignedRules && !installed.assignedRules.has(ruleId)) continue;
|
|
39596
|
-
out.push({ id:
|
|
38648
|
+
out.push({ id: randomUUID13(), scope: "global", target: { ruleId }, action, enabled: true });
|
|
39597
38649
|
}
|
|
39598
38650
|
return out;
|
|
39599
38651
|
}
|
|
39600
38652
|
|
|
39601
|
-
// ../../packages/
|
|
39602
|
-
import {
|
|
39603
|
-
import {
|
|
38653
|
+
// ../../packages/remote/src/http.ts
|
|
38654
|
+
import { request as httpRequest } from "http";
|
|
38655
|
+
import { request as httpsRequest } from "https";
|
|
38656
|
+
var DEFAULT_TIMEOUT_MS = 1e4;
|
|
38657
|
+
var MAX_RESPONSE_BYTES = 8 * 1024 * 1024;
|
|
38658
|
+
var RemoteRequestError = class extends Error {
|
|
38659
|
+
constructor(status) {
|
|
38660
|
+
super(`control-plane request failed with status ${String(status)}`);
|
|
38661
|
+
this.status = status;
|
|
38662
|
+
this.name = "RemoteRequestError";
|
|
38663
|
+
}
|
|
38664
|
+
status;
|
|
38665
|
+
};
|
|
38666
|
+
var RemoteRouteAbsent = class extends Error {
|
|
38667
|
+
constructor(route) {
|
|
38668
|
+
super(`control plane does not serve ${route}`);
|
|
38669
|
+
this.route = route;
|
|
38670
|
+
this.name = "RemoteRouteAbsent";
|
|
38671
|
+
}
|
|
38672
|
+
route;
|
|
38673
|
+
};
|
|
38674
|
+
var RemoteRequestInvalid = class extends Error {
|
|
38675
|
+
constructor(route, cause) {
|
|
38676
|
+
super(`refusing to send a malformed body to ${route}`);
|
|
38677
|
+
this.cause = cause;
|
|
38678
|
+
this.name = "RemoteRequestInvalid";
|
|
38679
|
+
}
|
|
38680
|
+
cause;
|
|
38681
|
+
};
|
|
38682
|
+
var RemoteEndpointRefused = class extends Error {
|
|
38683
|
+
constructor(endpoint) {
|
|
38684
|
+
super(`refusing to talk to an unsafe control-plane endpoint: ${originOnly(endpoint)}`);
|
|
38685
|
+
this.name = "RemoteEndpointRefused";
|
|
38686
|
+
}
|
|
38687
|
+
};
|
|
38688
|
+
var RemoteResponseInvalid = class extends Error {
|
|
38689
|
+
constructor(route, detail) {
|
|
38690
|
+
super(`control plane answered ${route} with ${detail}`);
|
|
38691
|
+
this.name = "RemoteResponseInvalid";
|
|
38692
|
+
}
|
|
38693
|
+
};
|
|
38694
|
+
var RemoteTransportError = class extends Error {
|
|
38695
|
+
/**
|
|
38696
|
+
* The status the peer sent, when headers arrived and only the BODY was
|
|
38697
|
+
* refused.
|
|
38698
|
+
*
|
|
38699
|
+
* Undefined for the ordinary case this class was written for — no answer at
|
|
38700
|
+
* all. It exists because two paths reject after a status has already been
|
|
38701
|
+
* delivered: an oversized body and an aborted response. Discarding it there
|
|
38702
|
+
* reported a deployment answering 401 with a verbose body as a network
|
|
38703
|
+
* outage, which sends the reader to look at their network instead of their
|
|
38704
|
+
* credential.
|
|
38705
|
+
*/
|
|
38706
|
+
constructor(reason, status) {
|
|
38707
|
+
super(`control-plane request did not complete: ${reason}`);
|
|
38708
|
+
this.status = status;
|
|
38709
|
+
this.name = "RemoteTransportError";
|
|
38710
|
+
}
|
|
38711
|
+
status;
|
|
38712
|
+
};
|
|
38713
|
+
async function send(options) {
|
|
38714
|
+
const url2 = new URL(options.url);
|
|
38715
|
+
const timeoutMs = options.timeoutMs ?? DEFAULT_TIMEOUT_MS;
|
|
38716
|
+
const send_ = url2.protocol === "http:" ? httpRequest : httpsRequest;
|
|
38717
|
+
const requestOptions = {
|
|
38718
|
+
method: options.method,
|
|
38719
|
+
headers: {
|
|
38720
|
+
// CALLER HEADERS FIRST, so this module's own are not overridable. Spread
|
|
38721
|
+
// last they win, and two of the values below are ones no caller may
|
|
38722
|
+
// replace: `x-api-key` is the credential, and `content-length` is the
|
|
38723
|
+
// byte count that stops a multi-byte body being truncated by the
|
|
38724
|
+
// receiver. `SendOptions.headers` is a free-form record on an exported
|
|
38725
|
+
// function, so "no caller does that today" is not the guarantee to rely
|
|
38726
|
+
// on. The one header any caller actually passes — `if-none-match` on the
|
|
38727
|
+
// conditional GET — is untouched by this order.
|
|
38728
|
+
...options.headers,
|
|
38729
|
+
// The credential. One header, matching what the deployment authenticates
|
|
38730
|
+
// on; a second copy in an `Authorization` header would be one more place
|
|
38731
|
+
// it can be logged by an intermediary for no gain.
|
|
38732
|
+
//
|
|
38733
|
+
// Spread conditionally rather than assigned as `undefined`: Node's header
|
|
38734
|
+
// handling and `content-length` bookkeeping treat a present-but-undefined
|
|
38735
|
+
// key differently from an absent one, and "the header is not there" is
|
|
38736
|
+
// the property the attach flow needs.
|
|
38737
|
+
...options.apiKey === void 0 ? {} : { "x-api-key": options.apiKey },
|
|
38738
|
+
accept: "application/json",
|
|
38739
|
+
...options.body === void 0 ? {} : {
|
|
38740
|
+
"content-type": "application/json",
|
|
38741
|
+
// Byte length, not string length: a multi-byte body sent with a
|
|
38742
|
+
// character count is truncated by the receiver.
|
|
38743
|
+
"content-length": String(Buffer.byteLength(options.body))
|
|
38744
|
+
}
|
|
38745
|
+
}
|
|
38746
|
+
};
|
|
38747
|
+
return new Promise((resolve3, reject) => {
|
|
38748
|
+
let settled = false;
|
|
38749
|
+
const fail = (reason, status) => {
|
|
38750
|
+
if (settled) return;
|
|
38751
|
+
settled = true;
|
|
38752
|
+
reject(new RemoteTransportError(reason, status));
|
|
38753
|
+
};
|
|
38754
|
+
const req = send_(url2, requestOptions, (res) => {
|
|
38755
|
+
const chunks = [];
|
|
38756
|
+
let size = 0;
|
|
38757
|
+
res.on("data", (chunk) => {
|
|
38758
|
+
size += chunk.length;
|
|
38759
|
+
if (size > MAX_RESPONSE_BYTES) {
|
|
38760
|
+
fail(`response exceeded ${String(MAX_RESPONSE_BYTES)} bytes`, res.statusCode);
|
|
38761
|
+
res.destroy();
|
|
38762
|
+
req.destroy();
|
|
38763
|
+
return;
|
|
38764
|
+
}
|
|
38765
|
+
chunks.push(chunk);
|
|
38766
|
+
});
|
|
38767
|
+
res.on("aborted", () => {
|
|
38768
|
+
fail("the response was aborted", res.statusCode);
|
|
38769
|
+
});
|
|
38770
|
+
res.on("end", () => {
|
|
38771
|
+
if (settled) return;
|
|
38772
|
+
settled = true;
|
|
38773
|
+
resolve3({
|
|
38774
|
+
status: res.statusCode ?? 0,
|
|
38775
|
+
headers: res.headers,
|
|
38776
|
+
body: Buffer.concat(chunks).toString("utf8")
|
|
38777
|
+
});
|
|
38778
|
+
});
|
|
38779
|
+
});
|
|
38780
|
+
const deadline = setTimeout(() => {
|
|
38781
|
+
fail(`no response within ${String(timeoutMs)}ms`);
|
|
38782
|
+
req.destroy();
|
|
38783
|
+
}, timeoutMs);
|
|
38784
|
+
deadline.unref();
|
|
38785
|
+
req.on("upgrade", (_res, socket) => {
|
|
38786
|
+
fail("the deployment answered with a protocol upgrade");
|
|
38787
|
+
socket.destroy();
|
|
38788
|
+
});
|
|
38789
|
+
req.on("close", () => {
|
|
38790
|
+
fail("the connection closed before a response was read");
|
|
38791
|
+
clearTimeout(deadline);
|
|
38792
|
+
});
|
|
38793
|
+
req.on("error", (err) => {
|
|
38794
|
+
fail(err.message);
|
|
38795
|
+
});
|
|
38796
|
+
if (options.body !== void 0) req.write(options.body);
|
|
38797
|
+
req.end();
|
|
38798
|
+
});
|
|
38799
|
+
}
|
|
39604
38800
|
|
|
39605
|
-
// ../../packages/
|
|
39606
|
-
var
|
|
39607
|
-
|
|
39608
|
-
|
|
39609
|
-
|
|
39610
|
-
|
|
39611
|
-
|
|
39612
|
-
|
|
39613
|
-
|
|
39614
|
-
|
|
39615
|
-
|
|
39616
|
-
GOOGLE_GENAI_USE_VERTEXAI: optionalFlag,
|
|
39617
|
-
GOOGLE_GEMINI_BASE_URL: optionalBaseUrl2
|
|
39618
|
-
};
|
|
39619
|
-
var AntigravityProviderEnvSchema = external_exports.object(antigravityProviderEnvShape);
|
|
39620
|
-
|
|
39621
|
-
// ../../packages/plugin-sdk/src/provider-env-codex.ts
|
|
39622
|
-
var optionalBaseUrl3 = external_exports.preprocess((v) => {
|
|
39623
|
-
if (typeof v === "string" && v.trim() === "") return void 0;
|
|
39624
|
-
return v;
|
|
39625
|
-
}, external_exports.string().optional()).catch(void 0);
|
|
39626
|
-
var codexProviderEnvShape = {
|
|
39627
|
-
OPENAI_BASE_URL: optionalBaseUrl3
|
|
38801
|
+
// ../../packages/remote/src/client.ts
|
|
38802
|
+
var ROUTES = {
|
|
38803
|
+
events: "/v1/events",
|
|
38804
|
+
auditEvents: "/v1/audit-events",
|
|
38805
|
+
auditEventsBatch: "/v1/audit-events/batch",
|
|
38806
|
+
inventory: "/v1/inventory",
|
|
38807
|
+
storePosture: "/v1/store-posture",
|
|
38808
|
+
policyBundle: "/v1/policy-bundle",
|
|
38809
|
+
whoami: "/v1/plugin/whoami",
|
|
38810
|
+
shares: "/v1/shares",
|
|
38811
|
+
commands: "/v1/plugin/commands"
|
|
39628
38812
|
};
|
|
39629
|
-
|
|
38813
|
+
function ackRoute(id) {
|
|
38814
|
+
return `${ROUTES.commands}/${encodeURIComponent(id)}/ack`;
|
|
38815
|
+
}
|
|
38816
|
+
function headerValue(response, name) {
|
|
38817
|
+
const raw = response.headers[name];
|
|
38818
|
+
if (raw === void 0) return void 0;
|
|
38819
|
+
return Array.isArray(raw) ? raw[0] : raw;
|
|
38820
|
+
}
|
|
38821
|
+
function okBody(response) {
|
|
38822
|
+
if (response.status < 200 || response.status >= 300) {
|
|
38823
|
+
throw new RemoteRequestError(response.status);
|
|
38824
|
+
}
|
|
38825
|
+
return response.body;
|
|
38826
|
+
}
|
|
38827
|
+
function parsed(schema, body, route) {
|
|
38828
|
+
let json2;
|
|
38829
|
+
try {
|
|
38830
|
+
json2 = JSON.parse(body);
|
|
38831
|
+
} catch {
|
|
38832
|
+
throw new RemoteResponseInvalid(route, "a body that is not JSON");
|
|
38833
|
+
}
|
|
38834
|
+
const result = schema.safeParse(json2);
|
|
38835
|
+
if (!result.success) {
|
|
38836
|
+
throw new RemoteResponseInvalid(route, "a body this client cannot read");
|
|
38837
|
+
}
|
|
38838
|
+
return result.data;
|
|
38839
|
+
}
|
|
38840
|
+
function resolveBaseUrl(endpoint) {
|
|
38841
|
+
if (!isSafeEndpoint(endpoint)) throw new RemoteEndpointRefused(endpoint);
|
|
38842
|
+
let end = endpoint.length;
|
|
38843
|
+
while (end > 0 && endpoint.charCodeAt(end - 1) === SLASH2) end -= 1;
|
|
38844
|
+
return endpoint.slice(0, end);
|
|
38845
|
+
}
|
|
38846
|
+
var SLASH2 = "/".charCodeAt(0);
|
|
38847
|
+
function createRemoteClient(options) {
|
|
38848
|
+
const base = resolveBaseUrl(options.endpoint);
|
|
38849
|
+
const url2 = (route) => `${base}${route}`;
|
|
38850
|
+
const common = { apiKey: options.apiKey, timeoutMs: options.timeoutMs };
|
|
38851
|
+
const sendOne = async (event) => {
|
|
38852
|
+
const validated = RecordAuditEventRequest.safeParse(event);
|
|
38853
|
+
if (!validated.success) throw new RemoteRequestInvalid(ROUTES.auditEvents, validated.error);
|
|
38854
|
+
const response = await send({
|
|
38855
|
+
...common,
|
|
38856
|
+
method: "POST",
|
|
38857
|
+
url: url2(ROUTES.auditEvents),
|
|
38858
|
+
body: JSON.stringify(validated.data)
|
|
38859
|
+
});
|
|
38860
|
+
okBody(response);
|
|
38861
|
+
};
|
|
38862
|
+
return {
|
|
38863
|
+
async ingestEvents(batch) {
|
|
38864
|
+
const response = await send({
|
|
38865
|
+
...common,
|
|
38866
|
+
method: "POST",
|
|
38867
|
+
url: url2(ROUTES.events),
|
|
38868
|
+
body: JSON.stringify(batch)
|
|
38869
|
+
});
|
|
38870
|
+
return parsed(IngestAck, okBody(response), ROUTES.events);
|
|
38871
|
+
},
|
|
38872
|
+
async ingestInventory(context) {
|
|
38873
|
+
const response = await send({
|
|
38874
|
+
...common,
|
|
38875
|
+
method: "POST",
|
|
38876
|
+
url: url2(ROUTES.inventory),
|
|
38877
|
+
body: JSON.stringify(context)
|
|
38878
|
+
});
|
|
38879
|
+
return parsed(ResolvedInventory, okBody(response), ROUTES.inventory);
|
|
38880
|
+
},
|
|
38881
|
+
async recordAuditEvent(event) {
|
|
38882
|
+
await sendOne(event);
|
|
38883
|
+
},
|
|
38884
|
+
async recordAuditEvents(events, opts) {
|
|
38885
|
+
const validated = RecordAuditEventBatch.safeParse({ events });
|
|
38886
|
+
if (!validated.success) {
|
|
38887
|
+
throw new RemoteRequestInvalid(ROUTES.auditEventsBatch, validated.error);
|
|
38888
|
+
}
|
|
38889
|
+
const response = await send({
|
|
38890
|
+
...common,
|
|
38891
|
+
method: "POST",
|
|
38892
|
+
url: url2(ROUTES.auditEventsBatch),
|
|
38893
|
+
body: JSON.stringify(validated.data)
|
|
38894
|
+
});
|
|
38895
|
+
if (response.status === 404) {
|
|
38896
|
+
if (opts?.fallbackToSingleEvents !== true) {
|
|
38897
|
+
throw new RemoteRouteAbsent(ROUTES.auditEventsBatch);
|
|
38898
|
+
}
|
|
38899
|
+
for (const event of validated.data.events) await sendOne(event);
|
|
38900
|
+
return { accepted: validated.data.events.length };
|
|
38901
|
+
}
|
|
38902
|
+
return parsed(AuditEventBatchAck, okBody(response), ROUTES.auditEventsBatch);
|
|
38903
|
+
},
|
|
38904
|
+
async reportStorePosture(snapshot) {
|
|
38905
|
+
const response = await send({
|
|
38906
|
+
...common,
|
|
38907
|
+
method: "POST",
|
|
38908
|
+
url: url2(ROUTES.storePosture),
|
|
38909
|
+
body: JSON.stringify(snapshot)
|
|
38910
|
+
});
|
|
38911
|
+
okBody(response);
|
|
38912
|
+
},
|
|
38913
|
+
async getPolicyBundle(etag) {
|
|
38914
|
+
const response = await send({
|
|
38915
|
+
...common,
|
|
38916
|
+
method: "GET",
|
|
38917
|
+
url: url2(ROUTES.policyBundle),
|
|
38918
|
+
...etag === void 0 ? {} : { headers: { "if-none-match": etag } }
|
|
38919
|
+
});
|
|
38920
|
+
if (response.status === 304) {
|
|
38921
|
+
return { changed: false, etag: headerValue(response, "etag") ?? etag };
|
|
38922
|
+
}
|
|
38923
|
+
const bundle = parsed(PolicyBundle, okBody(response), ROUTES.policyBundle);
|
|
38924
|
+
return { changed: true, bundle, etag: headerValue(response, "etag") };
|
|
38925
|
+
},
|
|
38926
|
+
async whoami() {
|
|
38927
|
+
const response = await send({ ...common, method: "GET", url: url2(ROUTES.whoami) });
|
|
38928
|
+
return parsed(PluginWhoami, okBody(response), ROUTES.whoami);
|
|
38929
|
+
},
|
|
38930
|
+
async recordProjectEgress(request) {
|
|
38931
|
+
const validated = EgressIngestRequest.safeParse(request);
|
|
38932
|
+
if (!validated.success) throw new RemoteRequestInvalid(ROUTES.shares, validated.error);
|
|
38933
|
+
const response = await send({
|
|
38934
|
+
...common,
|
|
38935
|
+
method: "POST",
|
|
38936
|
+
url: url2(ROUTES.shares),
|
|
38937
|
+
body: JSON.stringify(validated.data)
|
|
38938
|
+
});
|
|
38939
|
+
if (response.status === 404) throw new RemoteRouteAbsent(ROUTES.shares);
|
|
38940
|
+
okBody(response);
|
|
38941
|
+
},
|
|
38942
|
+
async pollCommand() {
|
|
38943
|
+
const response = await send({ ...common, method: "GET", url: url2(ROUTES.commands) });
|
|
38944
|
+
if (response.status === 404) return null;
|
|
38945
|
+
return parsed(DeviceCommandPollResponse, okBody(response), ROUTES.commands).command;
|
|
38946
|
+
},
|
|
38947
|
+
async ackCommand(id, body) {
|
|
38948
|
+
const validated = DeviceCommandAckBody.safeParse(body);
|
|
38949
|
+
const route = ackRoute(id);
|
|
38950
|
+
if (!validated.success) throw new RemoteRequestInvalid(route, validated.error);
|
|
38951
|
+
const response = await send({
|
|
38952
|
+
...common,
|
|
38953
|
+
method: "POST",
|
|
38954
|
+
url: url2(route),
|
|
38955
|
+
body: JSON.stringify(validated.data)
|
|
38956
|
+
});
|
|
38957
|
+
okBody(response);
|
|
38958
|
+
}
|
|
38959
|
+
};
|
|
38960
|
+
}
|
|
39630
38961
|
|
|
39631
|
-
// ../../packages/
|
|
39632
|
-
|
|
38962
|
+
// ../../packages/remote/src/failure-kind.ts
|
|
38963
|
+
function statusOf(err) {
|
|
38964
|
+
if (typeof err !== "object" || err === null || !("status" in err)) return null;
|
|
38965
|
+
const { status } = err;
|
|
38966
|
+
if (typeof status !== "number" || !Number.isInteger(status)) return null;
|
|
38967
|
+
return status >= 100 && status <= 599 ? status : null;
|
|
38968
|
+
}
|
|
38969
|
+
function nameOf(err) {
|
|
38970
|
+
if (typeof err !== "object" || err === null || !("name" in err)) return null;
|
|
38971
|
+
return typeof err.name === "string" ? err.name : null;
|
|
38972
|
+
}
|
|
38973
|
+
function classifyRemoteFailure(err) {
|
|
38974
|
+
switch (nameOf(err)) {
|
|
38975
|
+
case "RemoteRouteAbsent":
|
|
38976
|
+
return "route-absent";
|
|
38977
|
+
case "RemoteRequestInvalid":
|
|
38978
|
+
case "RemoteEndpointRefused":
|
|
38979
|
+
return "invalid-request";
|
|
38980
|
+
case "RemoteResponseInvalid":
|
|
38981
|
+
return "rejected";
|
|
38982
|
+
default:
|
|
38983
|
+
break;
|
|
38984
|
+
}
|
|
38985
|
+
const status = statusOf(err);
|
|
38986
|
+
if (status === null) return "unreachable";
|
|
38987
|
+
switch (status) {
|
|
38988
|
+
case 401:
|
|
38989
|
+
return "unauthorized";
|
|
38990
|
+
case 403:
|
|
38991
|
+
return "forbidden";
|
|
38992
|
+
case 429:
|
|
38993
|
+
return "unreachable";
|
|
38994
|
+
case 404:
|
|
38995
|
+
return "unreachable";
|
|
38996
|
+
default:
|
|
38997
|
+
return status >= 400 && status <= 499 ? "rejected" : "unreachable";
|
|
38998
|
+
}
|
|
38999
|
+
}
|
|
39633
39000
|
|
|
39634
|
-
// ../../packages/plugin-
|
|
39635
|
-
|
|
39636
|
-
|
|
39001
|
+
// ../../packages/plugin-runtime/src/attached/failure.ts
|
|
39002
|
+
function classifyFailure(err) {
|
|
39003
|
+
switch (classifyRemoteFailure(err)) {
|
|
39004
|
+
case "unauthorized":
|
|
39005
|
+
return "unauthorized";
|
|
39006
|
+
case "forbidden":
|
|
39007
|
+
return "forbidden";
|
|
39008
|
+
default:
|
|
39009
|
+
return "unreachable";
|
|
39010
|
+
}
|
|
39011
|
+
}
|
|
39637
39012
|
|
|
39638
|
-
// ../../packages/plugin-
|
|
39639
|
-
var
|
|
39013
|
+
// ../../packages/plugin-runtime/src/attached/with-timeout.ts
|
|
39014
|
+
var REQUEST_TIMEOUT_MS = 2e3;
|
|
39015
|
+
function withTimeout(promise2, ms) {
|
|
39016
|
+
let timer;
|
|
39017
|
+
const timeout = new Promise((_, reject) => {
|
|
39018
|
+
timer = setTimeout(() => {
|
|
39019
|
+
reject(new Error("attached gateway request timed out"));
|
|
39020
|
+
}, ms);
|
|
39021
|
+
});
|
|
39022
|
+
promise2.catch(() => void 0);
|
|
39023
|
+
return Promise.race([promise2, timeout]).finally(() => {
|
|
39024
|
+
clearTimeout(timer);
|
|
39025
|
+
});
|
|
39026
|
+
}
|
|
39640
39027
|
|
|
39641
|
-
// ../../packages/plugin-
|
|
39642
|
-
import {
|
|
39643
|
-
import { join as
|
|
39028
|
+
// ../../packages/plugin-runtime/src/attached/forward-drops.ts
|
|
39029
|
+
import { readFileSync as readFileSync11 } from "fs";
|
|
39030
|
+
import { join as join18 } from "path";
|
|
39031
|
+
var FORWARD_DROPS_FILENAME = ATTACHED_FORWARD_DROPS_FILENAME;
|
|
39032
|
+
function forwardDropsPath(dataDir2) {
|
|
39033
|
+
return join18(dataDir2, FORWARD_DROPS_FILENAME);
|
|
39034
|
+
}
|
|
39035
|
+
function recordForwardDrops(dataDir2, count, nowMs) {
|
|
39036
|
+
if (count <= 0) return;
|
|
39037
|
+
try {
|
|
39038
|
+
ensureDataDirSync(dataDir2);
|
|
39039
|
+
const previous = readForwardDrops(dataDir2);
|
|
39040
|
+
const next = {
|
|
39041
|
+
droppedForwards: (previous?.droppedForwards ?? 0) + count,
|
|
39042
|
+
lastDropAtMs: nowMs
|
|
39043
|
+
};
|
|
39044
|
+
writeOwnerOnlyFileSync(forwardDropsPath(dataDir2), `${JSON.stringify(next)}
|
|
39045
|
+
`);
|
|
39046
|
+
} catch {
|
|
39047
|
+
}
|
|
39048
|
+
}
|
|
39049
|
+
function readForwardDrops(dataDir2) {
|
|
39050
|
+
try {
|
|
39051
|
+
const parsed2 = JSON.parse(readFileSync11(forwardDropsPath(dataDir2), "utf8"));
|
|
39052
|
+
if (typeof parsed2 !== "object" || parsed2 === null) return null;
|
|
39053
|
+
const record2 = parsed2;
|
|
39054
|
+
if (typeof record2.droppedForwards !== "number" || !Number.isFinite(record2.droppedForwards)) {
|
|
39055
|
+
return null;
|
|
39056
|
+
}
|
|
39057
|
+
if (record2.droppedForwards <= 0) return null;
|
|
39058
|
+
if (typeof record2.lastDropAtMs !== "number" || !Number.isFinite(record2.lastDropAtMs)) {
|
|
39059
|
+
return null;
|
|
39060
|
+
}
|
|
39061
|
+
return { droppedForwards: record2.droppedForwards, lastDropAtMs: record2.lastDropAtMs };
|
|
39062
|
+
} catch {
|
|
39063
|
+
return null;
|
|
39064
|
+
}
|
|
39065
|
+
}
|
|
39644
39066
|
|
|
39645
39067
|
// ../../packages/plugin-runtime/src/attached/forward-policy.ts
|
|
39068
|
+
import { randomUUID as randomUUID14 } from "crypto";
|
|
39069
|
+
import { readFile, rename, writeFile } from "fs/promises";
|
|
39070
|
+
import { join as join19 } from "path";
|
|
39646
39071
|
function isInvalidRequest(err) {
|
|
39647
39072
|
return typeof err === "object" && err !== null && err.name === "RemoteRequestInvalid";
|
|
39648
39073
|
}
|
|
@@ -39661,7 +39086,7 @@ var FORWARD_STATE_FILENAME = ATTACHED_FORWARD_STATE_FILENAME;
|
|
|
39661
39086
|
var STATE_FILENAME = FORWARD_STATE_FILENAME;
|
|
39662
39087
|
function createForwardPolicy(deps) {
|
|
39663
39088
|
const now = deps.now ?? (() => Date.now());
|
|
39664
|
-
const file2 =
|
|
39089
|
+
const file2 = join19(deps.dir, STATE_FILENAME);
|
|
39665
39090
|
let state = null;
|
|
39666
39091
|
let loading = null;
|
|
39667
39092
|
async function readState() {
|
|
@@ -39686,7 +39111,7 @@ function createForwardPolicy(deps) {
|
|
|
39686
39111
|
state = next;
|
|
39687
39112
|
try {
|
|
39688
39113
|
await ensureDataDir(deps.dir);
|
|
39689
|
-
const tmp = `${file2}.${
|
|
39114
|
+
const tmp = `${file2}.${randomUUID14()}.tmp`;
|
|
39690
39115
|
await writeFile(tmp, JSON.stringify(next), { encoding: "utf8", mode: DATA_FILE_MODE });
|
|
39691
39116
|
await rename(tmp, file2);
|
|
39692
39117
|
} catch {
|
|
@@ -39827,6 +39252,9 @@ var AttachedDataGateway = class {
|
|
|
39827
39252
|
*
|
|
39828
39253
|
* Machine mode answers before any key is read, so a machine attachment pays
|
|
39829
39254
|
* nothing for scoping and forwards exactly what it always has.
|
|
39255
|
+
*
|
|
39256
|
+
* `governanceAppliesTo` answers from this same verdict, so it agrees with
|
|
39257
|
+
* forwarding key for key.
|
|
39830
39258
|
*/
|
|
39831
39259
|
verdictFor(keyOf) {
|
|
39832
39260
|
try {
|
|
@@ -39843,24 +39271,27 @@ var AttachedDataGateway = class {
|
|
|
39843
39271
|
* the key its row holds in the local store, recorded per root (see
|
|
39844
39272
|
* `rootVerdict`), not the key on the root event just handed in: roots are
|
|
39845
39273
|
* first-write-wins in the store, so when two producers record a root for one
|
|
39846
|
-
* session (the session-start hook, then a reconcile pass) the second leaves
|
|
39847
|
-
*
|
|
39848
|
-
*
|
|
39849
|
-
*
|
|
39850
|
-
*
|
|
39851
|
-
*
|
|
39852
|
-
*
|
|
39853
|
-
*
|
|
39854
|
-
*
|
|
39855
|
-
*
|
|
39856
|
-
*
|
|
39857
|
-
*
|
|
39858
|
-
*
|
|
39859
|
-
*
|
|
39860
|
-
*
|
|
39861
|
-
*
|
|
39862
|
-
*
|
|
39863
|
-
*
|
|
39274
|
+
* session (the session-start hook, then a reconcile pass) the second leaves the
|
|
39275
|
+
* stored row as it was. That stored row, not this event, is what a history
|
|
39276
|
+
* drain pass would decide, if the root started before the attach; the drain
|
|
39277
|
+
* never offers one that started after it (`started_at < backlogBefore`).
|
|
39278
|
+
* Whether this root EVENT is itself sent takes both keys: the stored one AND
|
|
39279
|
+
* its own. The event's attributes (cwd, project, repo) describe where it was
|
|
39280
|
+
* recorded from, so a root event keyed to a personal directory is never sent
|
|
39281
|
+
* under an enrolled stored root, though the enrolled leaves still forward under
|
|
39282
|
+
* it: the instance that wrote the stored root is expected to have forwarded it.
|
|
39283
|
+
* If it did not (the root was written while standalone or under another
|
|
39284
|
+
* attachment, or its forward failed), the plane refuses those leaves. A root
|
|
39285
|
+
* that started before the attach is shipped, ahead of its leaves, by the
|
|
39286
|
+
* history drain; one that started after it is never offered by the drain. Any
|
|
39287
|
+
* other row with a root reference (`rootSessionId`, else `parentId`) forwards
|
|
39288
|
+
* only when its own key is in scope AND this instance recorded an in-scope
|
|
39289
|
+
* verdict for that root. The audit-event route has real foreign keys on both
|
|
39290
|
+
* columns and stubs no missing root, so a leaf sent after its root was kept
|
|
39291
|
+
* local is refused there, and a refused forward counts toward the breaker that
|
|
39292
|
+
* guards every other one. A root this instance never recorded is therefore
|
|
39293
|
+
* `'local'`: the only answer that cannot orphan a row. A row with no root
|
|
39294
|
+
* reference at all has nothing to orphan, and is decided by its own key.
|
|
39864
39295
|
*
|
|
39865
39296
|
* What this costs is stated rather than discovered. A session whose stored
|
|
39866
39297
|
* root is not keyed to an enrolled repository keeps its token and tool
|
|
@@ -39931,6 +39362,87 @@ var AttachedDataGateway = class {
|
|
|
39931
39362
|
return [];
|
|
39932
39363
|
}
|
|
39933
39364
|
}
|
|
39365
|
+
/**
|
|
39366
|
+
* The verdict for the repositories nested in a scanned project, answered
|
|
39367
|
+
* TOTALLY: `'forward'` or `'local'`, never a throw.
|
|
39368
|
+
*
|
|
39369
|
+
* A walk descends into a nested clone or submodule and folds its files into
|
|
39370
|
+
* the project it is walking, so one register can carry several
|
|
39371
|
+
* repositories' call sites under one project key. Each of them must be in
|
|
39372
|
+
* scope for it to forward. One key out of scope, or a nested repository with
|
|
39373
|
+
* no remote (an `undefined` key), keeps the whole register local.
|
|
39374
|
+
*
|
|
39375
|
+
* An ABSENT list is `'local'` too. Only the code that walked the tree can say
|
|
39376
|
+
* what is nested in it, and every scan passes the list, empty when nothing
|
|
39377
|
+
* is nested. A register nobody vouched for is not one a scoped attachment
|
|
39378
|
+
* may send.
|
|
39379
|
+
*
|
|
39380
|
+
* Machine mode answers before reading the context, so a machine attachment
|
|
39381
|
+
* forwards exactly what it always has.
|
|
39382
|
+
*/
|
|
39383
|
+
nestedVerdict(context) {
|
|
39384
|
+
try {
|
|
39385
|
+
if (this.deps.attachment.mode === "machine") return "forward";
|
|
39386
|
+
const keys = context?.nestedScopeKeys;
|
|
39387
|
+
if (keys === void 0) return "local";
|
|
39388
|
+
for (const key of keys) {
|
|
39389
|
+
if (this.verdictFor(() => key) === "local") return "local";
|
|
39390
|
+
}
|
|
39391
|
+
return "forward";
|
|
39392
|
+
} catch {
|
|
39393
|
+
return "local";
|
|
39394
|
+
}
|
|
39395
|
+
}
|
|
39396
|
+
/**
|
|
39397
|
+
* The register a scoped attachment sends, once the project and the repositories
|
|
39398
|
+
* nested in it are in scope: the register itself, with `reconcile.deletedFiles`
|
|
39399
|
+
* cut to the deleted paths whose own repository is in scope. `undefined` sends
|
|
39400
|
+
* nothing. TOTAL, like `verdictFor`, and for its reasons.
|
|
39401
|
+
*
|
|
39402
|
+
* The deletion sweep takes its paths from the scan ledger, not from the walk,
|
|
39403
|
+
* and the ledger holds every file the scanner ever read under the root, nested
|
|
39404
|
+
* clones' included. So a clone that was removed, or one an ignore file now
|
|
39405
|
+
* hides, is in no walk and never reaches `nestedVerdict`, yet its ledgered
|
|
39406
|
+
* paths come back as deleted. The scan names the repository of each deleted
|
|
39407
|
+
* path (`context.deletedFileKeys`, one entry per path in the register's order)
|
|
39408
|
+
* and each is held to the same verdict as any other key. A path whose key is
|
|
39409
|
+
* absent, or out of scope, is not sent.
|
|
39410
|
+
*
|
|
39411
|
+
* The list is asked for here, and only here: it is an async read of the scan
|
|
39412
|
+
* ledger that the scan makes on being called, so a machine attachment, which
|
|
39413
|
+
* returns before this, and a register already kept local never cause it.
|
|
39414
|
+
*
|
|
39415
|
+
* Anything the scan did not vouch for sends no deleted path, and the register
|
|
39416
|
+
* itself still goes: no list, a list that throws or whose read is rejected, or a
|
|
39417
|
+
* list whose length is not the register's. Deleting is the only thing a dropped
|
|
39418
|
+
* path could have done on the server, so the cost of a refusal is a stored row
|
|
39419
|
+
* that stays, never a path that leaves.
|
|
39420
|
+
*
|
|
39421
|
+
* Machine mode returns `input` itself, the same object and unread, so a machine
|
|
39422
|
+
* attachment's request is exactly what it was. A register that lists no deleted
|
|
39423
|
+
* path, or that is not a ledger register, has nothing to cut and is returned
|
|
39424
|
+
* as it came, with the list unread.
|
|
39425
|
+
*/
|
|
39426
|
+
async registerForWire(input2, context) {
|
|
39427
|
+
try {
|
|
39428
|
+
if (this.deps.attachment.mode === "machine") return input2;
|
|
39429
|
+
const { reconcile } = input2;
|
|
39430
|
+
if (reconcile.mode !== "ledger" || reconcile.deletedFiles.length === 0) return input2;
|
|
39431
|
+
const deleted = reconcile.deletedFiles;
|
|
39432
|
+
let kept = [];
|
|
39433
|
+
try {
|
|
39434
|
+
const keys = await context?.deletedFileKeys?.();
|
|
39435
|
+
if (keys?.length === deleted.length) {
|
|
39436
|
+
kept = deleted.filter((_path, at) => this.verdictFor(() => keys[at]) === "forward");
|
|
39437
|
+
}
|
|
39438
|
+
} catch {
|
|
39439
|
+
kept = [];
|
|
39440
|
+
}
|
|
39441
|
+
return { ...input2, reconcile: { ...reconcile, deletedFiles: kept } };
|
|
39442
|
+
} catch {
|
|
39443
|
+
return void 0;
|
|
39444
|
+
}
|
|
39445
|
+
}
|
|
39934
39446
|
/**
|
|
39935
39447
|
* The event `recordCapture` sends for a capture the verdict let through, or
|
|
39936
39448
|
* `undefined` to send nothing. TOTAL, like `verdictFor`, and for its reasons.
|
|
@@ -40256,12 +39768,24 @@ var AttachedDataGateway = class {
|
|
|
40256
39768
|
* payload onto the wire-boundary-safe shape (no snippet, hashed
|
|
40257
39769
|
* projectKey), and its result is discarded: `forward.run` never throws or
|
|
40258
39770
|
* rejects, so there is nothing here to act on.
|
|
39771
|
+
*
|
|
39772
|
+
* `context.nestedScopeKeys` is what the scanner knows and the register does
|
|
39773
|
+
* not say: the key of every repository nested below the scan root, whose
|
|
39774
|
+
* files the walk folded into this register. On a scoped attachment the
|
|
39775
|
+
* register is forwarded only when the project's own key AND every one of
|
|
39776
|
+
* those is in scope (see `nestedVerdict`), and its deleted paths are cut to the
|
|
39777
|
+
* ones whose own repository is in scope (`context.deletedFileKeys`, see
|
|
39778
|
+
* `registerForWire`). Machine mode never reads either, and the local write
|
|
39779
|
+
* never receives the context and gets the register whole.
|
|
40259
39780
|
*/
|
|
40260
|
-
async recordProjectEgress(input2) {
|
|
39781
|
+
async recordProjectEgress(input2, context) {
|
|
40261
39782
|
const summary = await this.deps.local.recordProjectEgress(input2);
|
|
40262
39783
|
if (this.verdictFor(() => scopeKeyOfProjectKey(input2.projectKey)) === "local") return summary;
|
|
39784
|
+
if (this.nestedVerdict(context) === "local") return summary;
|
|
39785
|
+
const register = await this.registerForWire(input2, context);
|
|
39786
|
+
if (register === void 0) return summary;
|
|
40263
39787
|
await this.deps.forward.run(
|
|
40264
|
-
() => this.deps.client.recordProjectEgress(toEgressIngestRequest(
|
|
39788
|
+
() => this.deps.client.recordProjectEgress(toEgressIngestRequest(register))
|
|
40265
39789
|
);
|
|
40266
39790
|
return summary;
|
|
40267
39791
|
}
|
|
@@ -40315,6 +39839,11 @@ var AttachedDataGateway = class {
|
|
|
40315
39839
|
async scanLedgerPaths() {
|
|
40316
39840
|
return this.deps.local.scanLedgerPaths();
|
|
40317
39841
|
}
|
|
39842
|
+
// Delegated, like the path list. An inner gateway that cannot say answers an
|
|
39843
|
+
// empty map, which gives every deleted path no key.
|
|
39844
|
+
async scanLedgerPathKeys() {
|
|
39845
|
+
return await this.deps.local.scanLedgerPathKeys?.() ?? /* @__PURE__ */ new Map();
|
|
39846
|
+
}
|
|
40318
39847
|
async recordScanned(entries) {
|
|
40319
39848
|
return this.deps.local.recordScanned(entries);
|
|
40320
39849
|
}
|
|
@@ -40381,6 +39910,12 @@ var AttachedDataGateway = class {
|
|
|
40381
39910
|
// and the spread above would otherwise drop the field silently — which is
|
|
40382
39911
|
// exactly what it did, leaving the whole control inert on every device
|
|
40383
39912
|
// while every test around it stayed green.
|
|
39913
|
+
//
|
|
39914
|
+
// WHOLE ON EVERY ATTACHMENT. A scoped attachment does not narrow the list
|
|
39915
|
+
// here: the port's `getPolicyBundle()` takes no event, and the runtime
|
|
39916
|
+
// reads this bundle once to build detection, so the detections it carries
|
|
39917
|
+
// apply to every event on the machine. Where a prohibition applies is
|
|
39918
|
+
// answered per event by `governanceAppliesTo` below.
|
|
40384
39919
|
prohibitedModels: cached2.prohibitedModels,
|
|
40385
39920
|
// NAMED for the same reason as the line above, and it is the same defect
|
|
40386
39921
|
// if it is not: `...local` above spreads the DEVICE's bundle, so a field
|
|
@@ -40440,6 +39975,30 @@ var AttachedDataGateway = class {
|
|
|
40440
39975
|
};
|
|
40441
39976
|
}
|
|
40442
39977
|
// ---------------------------------------------------------------------
|
|
39978
|
+
// GovernanceScope — where the organization's model policy applies
|
|
39979
|
+
// ---------------------------------------------------------------------
|
|
39980
|
+
/**
|
|
39981
|
+
* Whether the organization's governance applies to an event keyed `scopeKey`:
|
|
39982
|
+
* the question a model-guard site asks once it has decided to refuse.
|
|
39983
|
+
*
|
|
39984
|
+
* THE FORWARD VERDICT, through `verdictFor`: the answer is whether a capture
|
|
39985
|
+
* with the same key would be forwarded. A machine-wide attachment governs
|
|
39986
|
+
* every event, keyless included, exactly as before. A scoped one governs an
|
|
39987
|
+
* event only when its key names an enrolled repository. An event in a
|
|
39988
|
+
* personal repository, in no repository, with an empty key, or met by a fault
|
|
39989
|
+
* is not governed.
|
|
39990
|
+
*
|
|
39991
|
+
* The event's OWN key, never its session root's. The root rule in
|
|
39992
|
+
* `auditVerdict` decides whether a row can be forwarded without orphaning it;
|
|
39993
|
+
* this decides whether a refusal applies, which is a question about where the
|
|
39994
|
+
* event happened.
|
|
39995
|
+
*
|
|
39996
|
+
* Answered from memory: no store read, no bundle read, nothing sent.
|
|
39997
|
+
*/
|
|
39998
|
+
governanceAppliesTo(scopeKey) {
|
|
39999
|
+
return this.verdictFor(() => scopeKey) === "forward";
|
|
40000
|
+
}
|
|
40001
|
+
// ---------------------------------------------------------------------
|
|
40443
40002
|
// LocalStoreMaintenance — by delegation (D3).
|
|
40444
40003
|
//
|
|
40445
40004
|
// Implementing these is what actually closes the skipped-local-maintenance
|
|
@@ -40549,35 +40108,36 @@ function toWireInspection(insp) {
|
|
|
40549
40108
|
|
|
40550
40109
|
// ../../packages/plugin-runtime/src/attached/history-sync.ts
|
|
40551
40110
|
import { createHash as createHash6 } from "crypto";
|
|
40552
|
-
import { hostname as
|
|
40111
|
+
import { hostname as hostname4 } from "os";
|
|
40553
40112
|
|
|
40554
40113
|
// ../../packages/plugin-runtime/src/attached/capture-rebuild.ts
|
|
40555
40114
|
var CORRELATION_ID = EventMetadata.shape.correlationId;
|
|
40556
40115
|
var TRACE_ID = EventMetadata.shape.traceId;
|
|
40557
40116
|
var EXCEPTION_ID = EventMetadata.shape.exceptionIds.unwrap().element;
|
|
40558
40117
|
var REDACT_DEGRADED_TO = EventMetadata.shape.redactDegradedTo.unwrap();
|
|
40118
|
+
var SCAN_INCOMPLETE = EventMetadata.shape.scanIncomplete.unwrap();
|
|
40559
40119
|
|
|
40560
40120
|
// ../../packages/plugin-runtime/src/attached/history-sync.ts
|
|
40561
40121
|
var CAPTURE_BATCH_BYTES = 1024 * 1024;
|
|
40562
40122
|
|
|
40563
40123
|
// ../../packages/plugin-runtime/src/attached/history-sync-trigger.ts
|
|
40564
40124
|
import { spawn } from "child_process";
|
|
40565
|
-
import { fileURLToPath
|
|
40125
|
+
import { fileURLToPath } from "url";
|
|
40566
40126
|
var HISTORY_SYNC_THROTTLE_MS = 5 * 60 * 1e3;
|
|
40567
40127
|
|
|
40568
40128
|
// ../../packages/plugin-runtime/src/attached/install-record.ts
|
|
40569
40129
|
import { readFile as readFile2, stat } from "fs/promises";
|
|
40570
|
-
import { basename as
|
|
40130
|
+
import { basename as basename2, dirname as dirname4, join as join20, resolve as resolve2 } from "path";
|
|
40571
40131
|
async function readInstalledVersion(installRoot) {
|
|
40572
40132
|
try {
|
|
40573
40133
|
const versionDir = resolve2(installRoot);
|
|
40574
|
-
const pluginDir =
|
|
40575
|
-
const marketplaceDir =
|
|
40576
|
-
const cacheDir =
|
|
40577
|
-
if (
|
|
40578
|
-
const key = `${
|
|
40134
|
+
const pluginDir = dirname4(versionDir);
|
|
40135
|
+
const marketplaceDir = dirname4(pluginDir);
|
|
40136
|
+
const cacheDir = dirname4(marketplaceDir);
|
|
40137
|
+
if (basename2(cacheDir) !== "cache") return null;
|
|
40138
|
+
const key = `${basename2(pluginDir)}@${basename2(marketplaceDir)}`;
|
|
40579
40139
|
const record2 = JSON.parse(
|
|
40580
|
-
await readFile2(
|
|
40140
|
+
await readFile2(join20(dirname4(cacheDir), "installed_plugins.json"), "utf8")
|
|
40581
40141
|
);
|
|
40582
40142
|
const plugins = record2?.plugins;
|
|
40583
40143
|
if (typeof plugins !== "object" || plugins === null || !Object.hasOwn(plugins, key)) {
|
|
@@ -40609,7 +40169,7 @@ async function exists(path) {
|
|
|
40609
40169
|
}
|
|
40610
40170
|
|
|
40611
40171
|
// ../../packages/plugin-runtime/src/attached/plugin-block.ts
|
|
40612
|
-
import { readFileSync as
|
|
40172
|
+
import { readFileSync as readFileSync12 } from "fs";
|
|
40613
40173
|
var INSTALL_RECORD_READ_TIMEOUT_MS = REQUEST_TIMEOUT_MS / 2;
|
|
40614
40174
|
function createPluginBlock(build, policyStore) {
|
|
40615
40175
|
return async () => {
|
|
@@ -40637,9 +40197,9 @@ async function readInstalledVersionBounded(installRoot) {
|
|
|
40637
40197
|
}
|
|
40638
40198
|
|
|
40639
40199
|
// ../../packages/plugin-runtime/src/attached/policy-store.ts
|
|
40640
|
-
import { randomUUID as
|
|
40200
|
+
import { randomUUID as randomUUID15 } from "crypto";
|
|
40641
40201
|
import { readFile as readFile3, rm, writeFile as writeFile2 } from "fs/promises";
|
|
40642
|
-
import { join as
|
|
40202
|
+
import { join as join21 } from "path";
|
|
40643
40203
|
|
|
40644
40204
|
// ../../packages/plugin-runtime/src/attached/atomic-publish.ts
|
|
40645
40205
|
import { rename as rename2 } from "fs/promises";
|
|
@@ -40668,7 +40228,7 @@ async function publishByRename(tmp, file2, move = rename2) {
|
|
|
40668
40228
|
|
|
40669
40229
|
// ../../packages/plugin-runtime/src/attached/policy-store.ts
|
|
40670
40230
|
function createPolicyStore(dir = dataDir()) {
|
|
40671
|
-
const file2 =
|
|
40231
|
+
const file2 = join21(dir, "policy-cache.json");
|
|
40672
40232
|
async function read() {
|
|
40673
40233
|
try {
|
|
40674
40234
|
const raw = await readFile3(file2, "utf8");
|
|
@@ -40700,7 +40260,7 @@ function createPolicyStore(dir = dataDir()) {
|
|
|
40700
40260
|
}
|
|
40701
40261
|
}
|
|
40702
40262
|
async function publishRecord(record2) {
|
|
40703
|
-
const tmp = `${file2}.${
|
|
40263
|
+
const tmp = `${file2}.${randomUUID15()}.tmp`;
|
|
40704
40264
|
try {
|
|
40705
40265
|
await writeFile2(tmp, JSON.stringify(record2), {
|
|
40706
40266
|
encoding: "utf8",
|
|
@@ -40738,8 +40298,8 @@ function createPolicyStore(dir = dataDir()) {
|
|
|
40738
40298
|
}
|
|
40739
40299
|
|
|
40740
40300
|
// ../../packages/plugin-runtime/src/attached/posture-report-state.ts
|
|
40741
|
-
import { readFileSync as
|
|
40742
|
-
import { join as
|
|
40301
|
+
import { readFileSync as readFileSync13 } from "fs";
|
|
40302
|
+
import { join as join22 } from "path";
|
|
40743
40303
|
var POSTURE_REPORT_STATE_FILENAME = ATTACHED_POSTURE_REPORT_FILENAME;
|
|
40744
40304
|
var OUTCOME_KEYS = {
|
|
40745
40305
|
ok: true,
|
|
@@ -40753,7 +40313,7 @@ var OUTCOME_KEYS = {
|
|
|
40753
40313
|
};
|
|
40754
40314
|
var OUTCOMES = new Set(Object.keys(OUTCOME_KEYS));
|
|
40755
40315
|
function postureReportStatePath(dataDir2) {
|
|
40756
|
-
return
|
|
40316
|
+
return join22(dataDir2, POSTURE_REPORT_STATE_FILENAME);
|
|
40757
40317
|
}
|
|
40758
40318
|
function writePostureReportState(dataDir2, state) {
|
|
40759
40319
|
try {
|
|
@@ -40794,10 +40354,19 @@ function createPostureReporter(deps) {
|
|
|
40794
40354
|
hostname: deps.hostname(),
|
|
40795
40355
|
capturedAt: nowMs,
|
|
40796
40356
|
...measurement,
|
|
40797
|
-
// Omit the key rather than spread an explicit `undefined
|
|
40798
|
-
//
|
|
40799
|
-
//
|
|
40800
|
-
|
|
40357
|
+
// Omit the key rather than spread an explicit `undefined`. The type
|
|
40358
|
+
// admits `undefined` here (the schema's optional member), and
|
|
40359
|
+
// JSON.stringify sends the same bytes either way. Omitting keeps the
|
|
40360
|
+
// in-memory object free of an explicit `undefined` member, which the
|
|
40361
|
+
// tests pin by key presence.
|
|
40362
|
+
...plugin === void 0 ? {} : { plugin },
|
|
40363
|
+
// LAST, and only for a scoped attachment. A machine attachment omits
|
|
40364
|
+
// the key the same way, so its body is byte for byte the one it sent
|
|
40365
|
+
// before the member existed. Anything but exactly `machine` reports the
|
|
40366
|
+
// constant `scoped`, never the raw value: that is resolveScope's own
|
|
40367
|
+
// fail direction, and a value outside the wire's vocabulary would fail
|
|
40368
|
+
// the whole snapshot at the receiver, the wipe signal with it.
|
|
40369
|
+
...deps.attachmentMode === "machine" ? {} : { attachmentMode: "scoped" }
|
|
40801
40370
|
};
|
|
40802
40371
|
} catch {
|
|
40803
40372
|
return null;
|
|
@@ -40820,8 +40389,8 @@ function createPostureReporter(deps) {
|
|
|
40820
40389
|
}
|
|
40821
40390
|
|
|
40822
40391
|
// ../../packages/plugin-runtime/src/attached/posture-snapshot.ts
|
|
40823
|
-
import { statSync as
|
|
40824
|
-
import { DatabaseSync as
|
|
40392
|
+
import { statSync as statSync6 } from "fs";
|
|
40393
|
+
import { DatabaseSync as DatabaseSync3 } from "node:sqlite";
|
|
40825
40394
|
|
|
40826
40395
|
// ../../packages/plugin-runtime/src/attached/action-counts.ts
|
|
40827
40396
|
function emptyActionCounts() {
|
|
@@ -40851,7 +40420,7 @@ function emptyReadout(readError = false) {
|
|
|
40851
40420
|
}
|
|
40852
40421
|
function readStorePosture(dbPath2) {
|
|
40853
40422
|
try {
|
|
40854
|
-
|
|
40423
|
+
statSync6(dbPath2);
|
|
40855
40424
|
} catch (err) {
|
|
40856
40425
|
const code = err.code;
|
|
40857
40426
|
if (code === "ENOENT" || code === "ENOTDIR") return emptyReadout();
|
|
@@ -40879,7 +40448,7 @@ function readStorePosture(dbPath2) {
|
|
|
40879
40448
|
readError: false
|
|
40880
40449
|
});
|
|
40881
40450
|
try {
|
|
40882
|
-
db = new
|
|
40451
|
+
db = new DatabaseSync3(dbPath2, { readOnly: true });
|
|
40883
40452
|
db.exec("PRAGMA busy_timeout = 2000");
|
|
40884
40453
|
version2 = db.prepare("PRAGMA user_version").get().user_version;
|
|
40885
40454
|
try {
|
|
@@ -40931,16 +40500,16 @@ function readStorePosture(dbPath2) {
|
|
|
40931
40500
|
}
|
|
40932
40501
|
|
|
40933
40502
|
// ../../packages/plugin-runtime/src/attached/posture-store.ts
|
|
40934
|
-
import { randomUUID as
|
|
40503
|
+
import { randomUUID as randomUUID16 } from "crypto";
|
|
40935
40504
|
import { readFile as readFile4, rm as rm2, writeFile as writeFile3 } from "fs/promises";
|
|
40936
|
-
import { join as
|
|
40505
|
+
import { join as join23 } from "path";
|
|
40937
40506
|
var UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/;
|
|
40938
40507
|
function createPostureStore(dir = settingsDir(), legacyDir) {
|
|
40939
|
-
const file2 =
|
|
40940
|
-
const legacyFile = legacyDir === void 0 ? null :
|
|
40508
|
+
const file2 = join23(dir, "posture-state.json");
|
|
40509
|
+
const legacyFile = legacyDir === void 0 ? null : join23(legacyDir, "posture-state.json");
|
|
40941
40510
|
async function persist(state) {
|
|
40942
40511
|
await ensureDataDir(dir);
|
|
40943
|
-
const tmp = `${file2}.${
|
|
40512
|
+
const tmp = `${file2}.${randomUUID16()}.tmp`;
|
|
40944
40513
|
try {
|
|
40945
40514
|
await writeFile3(tmp, JSON.stringify(state), { encoding: "utf8", mode: DATA_FILE_MODE });
|
|
40946
40515
|
await publishByRename(tmp, file2);
|
|
@@ -40982,7 +40551,7 @@ function createPostureStore(dir = settingsDir(), legacyDir) {
|
|
|
40982
40551
|
}
|
|
40983
40552
|
return legacy;
|
|
40984
40553
|
}
|
|
40985
|
-
const fresh = { deviceId:
|
|
40554
|
+
const fresh = { deviceId: randomUUID16(), lastAttemptedAtMs: 0 };
|
|
40986
40555
|
try {
|
|
40987
40556
|
await ensureDataDir(dir);
|
|
40988
40557
|
if (createOwnerOnlyFileSync(file2, JSON.stringify(fresh))) return fresh;
|
|
@@ -41005,8 +40574,8 @@ function createPostureStore(dir = settingsDir(), legacyDir) {
|
|
|
41005
40574
|
}
|
|
41006
40575
|
|
|
41007
40576
|
// ../../packages/plugin-runtime/src/attached/sync-state.ts
|
|
41008
|
-
import { readFileSync as
|
|
41009
|
-
import { join as
|
|
40577
|
+
import { readFileSync as readFileSync14 } from "fs";
|
|
40578
|
+
import { join as join24 } from "path";
|
|
41010
40579
|
|
|
41011
40580
|
// ../../packages/plugin-runtime/src/attached/status.ts
|
|
41012
40581
|
var REFUSAL_LINES = {
|
|
@@ -41024,7 +40593,7 @@ var OUTCOME_LINES = {
|
|
|
41024
40593
|
|
|
41025
40594
|
// ../../packages/plugin-runtime/src/attached/sync-trigger.ts
|
|
41026
40595
|
import { spawn as spawn2 } from "child_process";
|
|
41027
|
-
import { fileURLToPath as
|
|
40596
|
+
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
41028
40597
|
var SYNC_THROTTLE_MS = 15 * 60 * 1e3;
|
|
41029
40598
|
|
|
41030
40599
|
// ../../packages/plugin-runtime/src/content-retention-pass.ts
|
|
@@ -41032,11 +40601,11 @@ var MAX_ROWS_PER_SWEEP = 50 * 1e3;
|
|
|
41032
40601
|
|
|
41033
40602
|
// ../../packages/plugin-runtime/src/content-retention-trigger.ts
|
|
41034
40603
|
import { spawn as spawn3 } from "child_process";
|
|
41035
|
-
import { fileURLToPath as
|
|
40604
|
+
import { fileURLToPath as fileURLToPath3 } from "url";
|
|
41036
40605
|
var CONTENT_RETENTION_THROTTLE_MS = 60 * 60 * 1e3;
|
|
41037
40606
|
|
|
41038
40607
|
// ../../packages/plugin-runtime/src/attached/factory.ts
|
|
41039
|
-
import { hostname as
|
|
40608
|
+
import { hostname as hostname5 } from "os";
|
|
41040
40609
|
|
|
41041
40610
|
// ../../packages/plugin-runtime/src/recorder.ts
|
|
41042
40611
|
var PLUGIN_RECORDER_BINARY = "plugin";
|
|
@@ -41049,7 +40618,7 @@ var StandaloneDataGateway = class {
|
|
|
41049
40618
|
// One notice per gateway — see warnRulesetDiscarded.
|
|
41050
40619
|
warnedRulesetDiscarded = false;
|
|
41051
40620
|
constructor(dataDir2, detections = [], meta4) {
|
|
41052
|
-
this.db = openLocalDatabase(dataDir2);
|
|
40621
|
+
this.db = openLocalDatabase(dataDir2, { shippedRegexMatchers: shippedRegexMatchers() });
|
|
41053
40622
|
this.dataDir = dataDir2;
|
|
41054
40623
|
this.db.installedPacks.recordInventory(detections, meta4);
|
|
41055
40624
|
}
|
|
@@ -41398,6 +40967,9 @@ var StandaloneDataGateway = class {
|
|
|
41398
40967
|
scanLedgerPaths() {
|
|
41399
40968
|
return Promise.resolve(this.db.scanLedger.allPaths());
|
|
41400
40969
|
}
|
|
40970
|
+
scanLedgerPathKeys() {
|
|
40971
|
+
return Promise.resolve(this.db.scanLedger.pathKeys());
|
|
40972
|
+
}
|
|
41401
40973
|
recordScanned(entries) {
|
|
41402
40974
|
this.db.scanLedger.upsertEntries(entries);
|
|
41403
40975
|
return Promise.resolve();
|
|
@@ -41483,13 +41055,17 @@ function resolveGatewayForConfig(config2, meta4) {
|
|
|
41483
41055
|
},
|
|
41484
41056
|
store: postureStore,
|
|
41485
41057
|
readStore: () => readStorePosture(config2.dbPath),
|
|
41486
|
-
hostname: () =>
|
|
41058
|
+
hostname: () => hostname5(),
|
|
41487
41059
|
now: () => Date.now(),
|
|
41060
|
+
// The mode THIS gateway enforces, from the attachment resolved above,
|
|
41061
|
+
// so the report cannot name a mode the forward paths are not using.
|
|
41062
|
+
attachmentMode: attachment.mode,
|
|
41488
41063
|
// The reporting build's identity, when the caller knows it (the plugin
|
|
41489
41064
|
// adapters do; an embedder or a test may not). Composed with the SAME
|
|
41490
41065
|
// policy store the sync child writes, so the block names the bundle
|
|
41491
|
-
// actually in force.
|
|
41492
|
-
// reporter
|
|
41066
|
+
// actually in force. The dependency key is omitted when no build is
|
|
41067
|
+
// known, and the reporter's optional call (`deps.pluginBlock?.()`)
|
|
41068
|
+
// then adds no block.
|
|
41493
41069
|
...meta4?.pluginBuild === void 0 ? {} : { pluginBlock: createPluginBlock(meta4.pluginBuild, store) }
|
|
41494
41070
|
})
|
|
41495
41071
|
});
|
|
@@ -41506,7 +41082,7 @@ function resolveDataGateway(config2, meta4, gatewayFactory = defaultGatewayFacto
|
|
|
41506
41082
|
}
|
|
41507
41083
|
|
|
41508
41084
|
// ../../packages/plugin-runtime/src/handle-session-start.ts
|
|
41509
|
-
import { randomUUID as
|
|
41085
|
+
import { randomUUID as randomUUID17 } from "crypto";
|
|
41510
41086
|
var EXCEPTION_RETENTION_MS = 90 * 24 * 60 * 60 * 1e3;
|
|
41511
41087
|
|
|
41512
41088
|
// src/present.ts
|
|
@@ -41603,8 +41179,8 @@ function table(headers, rows, opts = {}) {
|
|
|
41603
41179
|
const widths = headers.map(
|
|
41604
41180
|
(h, i) => Math.max(visibleLength(h), ...rows.map((r) => visibleLength(r[i] ?? "")))
|
|
41605
41181
|
);
|
|
41606
|
-
const
|
|
41607
|
-
const fmt = (cells) => cells.map((cell, i) => padEnd(cell, widths[i] ?? 0)).join(
|
|
41182
|
+
const sep2 = " ".repeat(gap);
|
|
41183
|
+
const fmt = (cells) => cells.map((cell, i) => padEnd(cell, widths[i] ?? 0)).join(sep2);
|
|
41608
41184
|
const headerLine = fmt(headers.map((h) => h.toUpperCase()));
|
|
41609
41185
|
if (opts.rowSep === true) {
|
|
41610
41186
|
const fullWidth = widths.reduce((n, w) => n + w, 0) + gap * Math.max(0, widths.length - 1);
|
|
@@ -41616,7 +41192,7 @@ function table(headers, rows, opts = {}) {
|
|
|
41616
41192
|
});
|
|
41617
41193
|
return [headerLine, rule, ...body].join("\n");
|
|
41618
41194
|
}
|
|
41619
|
-
const ruleLine = widths.map((w) => "\u2500".repeat(w)).join(
|
|
41195
|
+
const ruleLine = widths.map((w) => "\u2500".repeat(w)).join(sep2);
|
|
41620
41196
|
return [headerLine, ruleLine, ...rows.map(fmt)].join("\n");
|
|
41621
41197
|
}
|
|
41622
41198
|
function fenced(body) {
|
|
@@ -41626,8 +41202,8 @@ function fenced(body) {
|
|
|
41626
41202
|
}
|
|
41627
41203
|
|
|
41628
41204
|
// ../../packages/setup-wizard/src/remediation/rotation-checklist.ts
|
|
41629
|
-
import { writeFileSync as
|
|
41630
|
-
import { join as
|
|
41205
|
+
import { writeFileSync as writeFileSync5 } from "fs";
|
|
41206
|
+
import { join as join25 } from "path";
|
|
41631
41207
|
|
|
41632
41208
|
// ../../packages/setup-wizard/src/triage/merge.ts
|
|
41633
41209
|
var RANK = Object.fromEntries(
|
|
@@ -41635,9 +41211,9 @@ var RANK = Object.fromEntries(
|
|
|
41635
41211
|
);
|
|
41636
41212
|
|
|
41637
41213
|
// ../../packages/setup-wizard/src/triage/plan-file.ts
|
|
41638
|
-
import { mkdtempSync, readFileSync as
|
|
41214
|
+
import { mkdtempSync, readFileSync as readFileSync15, rmdirSync, rmSync as rmSync7, writeFileSync as writeFileSync6 } from "fs";
|
|
41639
41215
|
import { tmpdir } from "os";
|
|
41640
|
-
import { basename as
|
|
41216
|
+
import { basename as basename3, dirname as dirname5, join as join26 } from "path";
|
|
41641
41217
|
var SuppressionEntrySchema = external_exports.object({
|
|
41642
41218
|
ruleId: external_exports.string(),
|
|
41643
41219
|
category: DetectionCategory,
|
|
@@ -41679,10 +41255,10 @@ var PersistedPlanSchema = external_exports.object({
|
|
|
41679
41255
|
});
|
|
41680
41256
|
|
|
41681
41257
|
// src/skills-registry.ts
|
|
41682
|
-
import { readdirSync as
|
|
41683
|
-
import { join as
|
|
41684
|
-
import { fileURLToPath as
|
|
41685
|
-
var SKILLS_DIR =
|
|
41258
|
+
import { readdirSync as readdirSync2, readFileSync as readFileSync16 } from "fs";
|
|
41259
|
+
import { join as join27 } from "path";
|
|
41260
|
+
import { fileURLToPath as fileURLToPath4 } from "url";
|
|
41261
|
+
var SKILLS_DIR = fileURLToPath4(new URL("../skills", import.meta.url));
|
|
41686
41262
|
|
|
41687
41263
|
// src/render.ts
|
|
41688
41264
|
var SEVERITY_GLYPH = {
|
|
@@ -41766,14 +41342,14 @@ function renderStatusBar(s, opts = {}) {
|
|
|
41766
41342
|
const unreviewed = `unreviewed ${SHADE.full}${String(u.critical)} ${SHADE.dark}${String(u.high)} ${SHADE.medium}${String(u.medium)} ${SHADE.light}${String(u.low)}`;
|
|
41767
41343
|
return `\u25B8\u25B8 AKA health ${String(s.score)}/100 ${unreviewed} \u2691 ${String(s.openFindings)} open findings`;
|
|
41768
41344
|
}
|
|
41769
|
-
const
|
|
41345
|
+
const sep2 = ` ${paint.dim("\u2502")} `;
|
|
41770
41346
|
const sq = "\u25A0";
|
|
41771
41347
|
const dot = s.score >= 80 ? paint.ok("\u25CF") : s.score >= 50 ? paint.high("\u25CF") : paint.critical("\u25CF");
|
|
41772
41348
|
const score = `${dot} health ${paint.bold(String(s.score))}${paint.dim("/100")}`;
|
|
41773
41349
|
const tally = `${paint.dim("unreviewed")} ${paint.critical(sq)}${String(u.critical)} ${paint.high(sq)}${String(u.high)} ${paint.medium(sq)}${String(u.medium)} ${paint.low(sq)}${String(u.low)}`;
|
|
41774
41350
|
const flag = s.openFindings > 0 ? paint.critical("\u2691") : paint.dim("\u2691");
|
|
41775
41351
|
const open3 = `${flag} ${String(s.openFindings)} open findings`;
|
|
41776
|
-
return `${paint.brand("\u25B8\u25B8 AKA")}${
|
|
41352
|
+
return `${paint.brand("\u25B8\u25B8 AKA")}${sep2}${score}${sep2}${tally}${sep2}${open3}`;
|
|
41777
41353
|
}
|
|
41778
41354
|
function renderHealth(r) {
|
|
41779
41355
|
const lines = [`\u25CF ${r.title}`, ""];
|