@akasecurity/ai-tc-codex 0.9.16 → 0.9.17-beta.1
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 +5 -5
- package/scripts/apply-suppressions.js +678 -1252
- package/scripts/backfill.js +879 -1267
- package/scripts/content-retention.js +761 -2073
- package/scripts/filescan.js +1105 -473
- package/scripts/firstrun.js +1215 -1690
- package/scripts/history-sync.js +750 -2106
- package/scripts/intro.js +123 -2189
- package/scripts/onboard.js +2755 -1185
- package/scripts/post-tool-use.js +1302 -1696
- package/scripts/pre-tool-use.js +903 -1295
- package/scripts/query.js +1215 -1690
- package/scripts/reconcile.js +835 -1277
- package/scripts/remediate.js +920 -1317
- package/scripts/scan-worker.js +97 -13
- package/scripts/session-start.js +1819 -816
- package/scripts/start-light.js +127 -1360
- package/scripts/stop.js +271 -1112
- package/scripts/sync.js +1657 -1005
- package/scripts/user-prompt-submit.js +1042 -1404
package/scripts/firstrun.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",
|
|
@@ -21777,16 +20934,16 @@ function platformForProvider(provider) {
|
|
|
21777
20934
|
return PROVIDER_PLATFORM.get(provider.trim().toLowerCase()) ?? null;
|
|
21778
20935
|
}
|
|
21779
20936
|
function isLocalProvider(provider) {
|
|
21780
|
-
const
|
|
21781
|
-
return
|
|
20937
|
+
const platform = platformForProvider(provider);
|
|
20938
|
+
return platform !== null && hostingFor(platform) === "local";
|
|
21782
20939
|
}
|
|
21783
20940
|
function priceFor(provider, model) {
|
|
21784
20941
|
if (isLocalProvider(provider)) return ZERO_PRICE;
|
|
21785
20942
|
const resolved = resolveModel(model, MODEL_INDEX);
|
|
21786
20943
|
if (resolved.entry === null) return null;
|
|
21787
|
-
const
|
|
21788
|
-
if (
|
|
21789
|
-
return resolved.entry.platforms.get(
|
|
20944
|
+
const platform = resolved.platform ?? platformForProvider(provider);
|
|
20945
|
+
if (platform === null) return null;
|
|
20946
|
+
return resolved.entry.platforms.get(platform)?.price ?? null;
|
|
21790
20947
|
}
|
|
21791
20948
|
var defaultCostModel = {
|
|
21792
20949
|
normalizeModelId(provider, model) {
|
|
@@ -21812,7 +20969,7 @@ var COMPACT = new Intl.NumberFormat("en-US", {
|
|
|
21812
20969
|
|
|
21813
20970
|
// ../../packages/schema/src/token/token-report.ts
|
|
21814
20971
|
var num = (value) => value ?? 0;
|
|
21815
|
-
function costUsageOf(a) {
|
|
20972
|
+
function costUsageOf(a, promptTokens) {
|
|
21816
20973
|
const usage = {
|
|
21817
20974
|
inputTokens: num(a.input_tokens),
|
|
21818
20975
|
outputTokens: num(a.output_tokens),
|
|
@@ -21822,11 +20979,12 @@ function costUsageOf(a) {
|
|
|
21822
20979
|
webSearchRequests: num(a.web_search_requests)
|
|
21823
20980
|
};
|
|
21824
20981
|
if (a.service_tier !== void 0) usage.serviceTier = a.service_tier;
|
|
20982
|
+
if (promptTokens !== void 0) usage.promptTokens = promptTokens;
|
|
21825
20983
|
return usage;
|
|
21826
20984
|
}
|
|
21827
20985
|
function buildTokenReports(leaves, costModel) {
|
|
21828
20986
|
const bySession = /* @__PURE__ */ new Map();
|
|
21829
|
-
for (const { sessionId, attributes } of leaves) {
|
|
20987
|
+
for (const { sessionId, attributes, promptTokens } of leaves) {
|
|
21830
20988
|
const provider = attributes.provider ?? "unknown";
|
|
21831
20989
|
const model = attributes.model ?? "unknown";
|
|
21832
20990
|
const key = `${provider} ${model}`;
|
|
@@ -21845,7 +21003,8 @@ function buildTokenReports(leaves, costModel) {
|
|
|
21845
21003
|
cacheCreation: 0,
|
|
21846
21004
|
cacheRead: 0,
|
|
21847
21005
|
costUsd: 0,
|
|
21848
|
-
priced: false
|
|
21006
|
+
priced: false,
|
|
21007
|
+
partial: false
|
|
21849
21008
|
};
|
|
21850
21009
|
rollups.set(key, acc);
|
|
21851
21010
|
}
|
|
@@ -21853,8 +21012,14 @@ function buildTokenReports(leaves, costModel) {
|
|
|
21853
21012
|
acc.output += num(attributes.output_tokens);
|
|
21854
21013
|
acc.cacheCreation += num(attributes.cache_creation_input_tokens);
|
|
21855
21014
|
acc.cacheRead += num(attributes.cache_read_input_tokens);
|
|
21856
|
-
const leafCost = costModel.costFor({
|
|
21857
|
-
|
|
21015
|
+
const leafCost = costModel.costFor({
|
|
21016
|
+
provider,
|
|
21017
|
+
model,
|
|
21018
|
+
usage: costUsageOf(attributes, promptTokens)
|
|
21019
|
+
});
|
|
21020
|
+
if (leafCost === null) {
|
|
21021
|
+
acc.partial = true;
|
|
21022
|
+
} else {
|
|
21858
21023
|
acc.costUsd += leafCost;
|
|
21859
21024
|
acc.priced = true;
|
|
21860
21025
|
}
|
|
@@ -21870,9 +21035,8 @@ function buildTokenReports(leaves, costModel) {
|
|
|
21870
21035
|
const rollupTotal = acc.input + acc.output + acc.cacheCreation + acc.cacheRead;
|
|
21871
21036
|
totalTokens += rollupTotal;
|
|
21872
21037
|
const estimatedCostUsd = acc.priced ? acc.costUsd : null;
|
|
21873
|
-
if (
|
|
21874
|
-
|
|
21875
|
-
} else {
|
|
21038
|
+
if (acc.partial) anyUnpriced = true;
|
|
21039
|
+
if (estimatedCostUsd !== null) {
|
|
21876
21040
|
anyPriced = true;
|
|
21877
21041
|
costUsd += estimatedCostUsd;
|
|
21878
21042
|
}
|
|
@@ -21895,7 +21059,7 @@ function buildTokenReports(leaves, costModel) {
|
|
|
21895
21059
|
totalTokens,
|
|
21896
21060
|
// Σ of the PRICED rollups; null when none had a known price.
|
|
21897
21061
|
estimatedCostUsd: anyPriced ? costUsd : null,
|
|
21898
|
-
// Any
|
|
21062
|
+
// Any call priced to null means the total understates real spend.
|
|
21899
21063
|
costIsPartial: anyUnpriced
|
|
21900
21064
|
});
|
|
21901
21065
|
}
|
|
@@ -22774,8 +21938,9 @@ var SessionTokenReport = external_exports.object({
|
|
|
22774
21938
|
totalTokens: external_exports.number().int().nonnegative(),
|
|
22775
21939
|
// Σ of the PRICED rollups only; null when no rollup had a known price.
|
|
22776
21940
|
estimatedCostUsd: external_exports.number().nullable(),
|
|
22777
|
-
// True whenever any
|
|
22778
|
-
//
|
|
21941
|
+
// True whenever any call priced to null (an unknown provider/model, or a call
|
|
21942
|
+
// over a long-context threshold whose rate is unpublished), so the total
|
|
21943
|
+
// understates real spend — the UI renders `≥ $X` instead of a falsely
|
|
22779
21944
|
// precise figure rather than silently dropping the unpriced calls.
|
|
22780
21945
|
costIsPartial: external_exports.boolean()
|
|
22781
21946
|
});
|
|
@@ -23652,7 +22817,15 @@ var StorePostureSnapshot = external_exports.object({
|
|
|
23652
22817
|
policyCounts: StorePosturePolicyCounts,
|
|
23653
22818
|
// OPTIONAL, not nullable: a reporter that predates this member keeps
|
|
23654
22819
|
// getting its 200 without a payload change.
|
|
23655
|
-
plugin: StorePosturePlugin.optional()
|
|
22820
|
+
plugin: StorePosturePlugin.optional(),
|
|
22821
|
+
// OPTIONAL, and sent only by a scoped attachment, always as `scoped`. A
|
|
22822
|
+
// machine attachment omits it, so its body is byte for byte the one it
|
|
22823
|
+
// sent before this member existed. Absent therefore means machine-wide OR
|
|
22824
|
+
// a reporter older than this member, never "scoped". Both values parse, so
|
|
22825
|
+
// a sender that one day spells `machine` breaks no receiver; any other
|
|
22826
|
+
// value fails the whole snapshot, which is why the reporter sends a
|
|
22827
|
+
// constant and never the raw mode.
|
|
22828
|
+
attachmentMode: AttachmentMode.optional()
|
|
23656
22829
|
}).meta({ id: "StorePostureSnapshot" });
|
|
23657
22830
|
var CAPTURE_VERSION_PREFIX = "capture/";
|
|
23658
22831
|
var RecordAuditEventRequest = AuditEventInput.extend({
|
|
@@ -24099,7 +23272,7 @@ var Rule = external_exports.strictObject({
|
|
|
24099
23272
|
postValidators: external_exports.array(PostValidatorRef).optional(),
|
|
24100
23273
|
requiresNearby: RequiresNearby.optional(),
|
|
24101
23274
|
examples: external_exports.array(external_exports.string()).optional(),
|
|
24102
|
-
// Whether the matched text is itself sensitive
|
|
23275
|
+
// Whether the matched text is itself sensitive (see RuleEvidence).
|
|
24103
23276
|
evidence: RuleEvidence.optional()
|
|
24104
23277
|
}).meta({ id: "Rule" });
|
|
24105
23278
|
var Author = external_exports.object({
|
|
@@ -24191,7 +23364,13 @@ var DetectionRule = external_exports.object({
|
|
|
24191
23364
|
// Representative matching strings the rule author shipped with the rule. The
|
|
24192
23365
|
// cheapest honest answer to "show me what this rule catches" — every bundled
|
|
24193
23366
|
// rule has them, and they are already in the stored snapshot.
|
|
24194
|
-
examples: external_exports.array(external_exports.string()).optional()
|
|
23367
|
+
examples: external_exports.array(external_exports.string()).optional(),
|
|
23368
|
+
// The rule's DECLARED evidence, as stored. Absent defers to the engine's
|
|
23369
|
+
// classification (ruleEvidence in @akasecurity/detections): a bundled
|
|
23370
|
+
// code-flaw rule reads as 'code' and anything else as 'value', and a rule
|
|
23371
|
+
// in a value category (secret/pii/financial/phi) is always 'value',
|
|
23372
|
+
// whatever it declares.
|
|
23373
|
+
evidence: RuleEvidence.optional()
|
|
24195
23374
|
}).meta({ id: "DetectionRule" });
|
|
24196
23375
|
var DetectionUpdate = external_exports.object({
|
|
24197
23376
|
available: external_exports.boolean(),
|
|
@@ -24259,8 +23438,10 @@ var ImportDetectionRequest = external_exports.object({
|
|
|
24259
23438
|
}).meta({ id: "ImportDetectionRequest" });
|
|
24260
23439
|
|
|
24261
23440
|
// ../../packages/schema/src/zod/detection-build.ts
|
|
24262
|
-
function optional2(key,
|
|
24263
|
-
if (raw === void 0
|
|
23441
|
+
function optional2(key, raw, parse4) {
|
|
23442
|
+
if (raw === void 0) return {};
|
|
23443
|
+
const parsed2 = parse4(raw);
|
|
23444
|
+
if (!parsed2.success || parsed2.data === void 0) return {};
|
|
24264
23445
|
return { [key]: parsed2.data };
|
|
24265
23446
|
}
|
|
24266
23447
|
function isStringArray(value) {
|
|
@@ -24295,10 +23476,12 @@ function rowToDetectionDetail(row, findingsLast30d, update) {
|
|
|
24295
23476
|
category: r.category,
|
|
24296
23477
|
severity: r.severity,
|
|
24297
23478
|
matcher: parsed2.data,
|
|
24298
|
-
//
|
|
24299
|
-
//
|
|
24300
|
-
//
|
|
24301
|
-
//
|
|
23479
|
+
// `appliesTo`, `postValidators` and `requiresNearby` are the rest of what
|
|
23480
|
+
// decides whether this rule fires. Carried so a consumer re-running the
|
|
23481
|
+
// rule (a preview, a tester) evaluates what the engine evaluates rather
|
|
23482
|
+
// than a matcher stripped of its guards — half the bundled catalog
|
|
23483
|
+
// carries at least one of these. `examples` and `evidence` describe the
|
|
23484
|
+
// rule and never gate a match.
|
|
24302
23485
|
//
|
|
24303
23486
|
// Enrichment is deliberately per-field and best-effort, NOT a whole-rule
|
|
24304
23487
|
// `Rule.safeParse`. Two reasons: `Rule` is a strict object pinned to
|
|
@@ -24308,18 +23491,19 @@ function rowToDetectionDetail(row, findingsLast30d, update) {
|
|
|
24308
23491
|
// test should stay exactly what it was, namely a renderable matcher. A
|
|
24309
23492
|
// field that fails validation is omitted, which reads as "not set" and is
|
|
24310
23493
|
// the same thing the consumer saw before this change.
|
|
24311
|
-
...optional2("appliesTo",
|
|
23494
|
+
...optional2("appliesTo", r.appliesTo, (v) => AppliesTo.safeParse(v)),
|
|
24312
23495
|
...optional2(
|
|
24313
23496
|
"postValidators",
|
|
24314
|
-
|
|
24315
|
-
|
|
23497
|
+
r.postValidators,
|
|
23498
|
+
(v) => PostValidatorRef.array().safeParse(v)
|
|
24316
23499
|
),
|
|
24317
|
-
...optional2("requiresNearby",
|
|
23500
|
+
...optional2("requiresNearby", r.requiresNearby, (v) => RequiresNearby.safeParse(v)),
|
|
24318
23501
|
...optional2(
|
|
24319
23502
|
"examples",
|
|
24320
|
-
|
|
24321
|
-
|
|
24322
|
-
)
|
|
23503
|
+
r.examples,
|
|
23504
|
+
(v) => isStringArray(v) ? { success: true, data: v } : { success: false }
|
|
23505
|
+
),
|
|
23506
|
+
...optional2("evidence", r.evidence, (v) => RuleEvidence.safeParse(v))
|
|
24323
23507
|
}
|
|
24324
23508
|
];
|
|
24325
23509
|
});
|
|
@@ -25012,11 +24196,14 @@ var PolicyBundle = external_exports.object({
|
|
|
25012
24196
|
ruleVersions: external_exports.record(external_exports.string(), external_exports.string()).optional(),
|
|
25013
24197
|
// Model ids (the raw `model` string a harness reports, e.g.
|
|
25014
24198
|
// `claude-opus-4-1`) the tenant has PROHIBITED. The plugin refuses to switch
|
|
25015
|
-
// a session onto one (PreModelSwitch)
|
|
25016
|
-
//
|
|
25017
|
-
//
|
|
25018
|
-
//
|
|
25019
|
-
//
|
|
24199
|
+
// a session onto one (PreModelSwitch), refuses a turn that would run on one
|
|
24200
|
+
// (UserPromptSubmit) and refuses a subagent spawn onto one (PreToolUse),
|
|
24201
|
+
// wherever the organization governs the event: everywhere on a
|
|
24202
|
+
// machine-wide attachment, and only in enrolled repositories on a scoped
|
|
24203
|
+
// one (the plugin runtime's `governanceApplies`).
|
|
24204
|
+
// Optional so an older backend — and an older on-disk cache — still
|
|
24205
|
+
// parses; consumers read `?? []`, which is the unenforced behaviour that
|
|
24206
|
+
// predates this field and the safe direction to default.
|
|
25020
24207
|
//
|
|
25021
24208
|
// Ids, not display names: the governance decision is keyed on the exact
|
|
25022
24209
|
// string the harness reports (`model_status_override.versionId` in the
|
|
@@ -25467,6 +24654,8 @@ var AttachmentScopeEntry = external_exports.object({
|
|
|
25467
24654
|
});
|
|
25468
24655
|
var AttachmentScope = external_exports.object({
|
|
25469
24656
|
endpoint: external_exports.string().min(1),
|
|
24657
|
+
tenantName: PluginWhoami.shape.tenantName.optional(),
|
|
24658
|
+
userEmail: PluginWhoami.shape.userEmail.optional(),
|
|
25470
24659
|
entries: external_exports.array(AttachmentScopeEntry)
|
|
25471
24660
|
});
|
|
25472
24661
|
var AttachmentScopeEnvelope = AttachmentScope.extend({ entries: external_exports.array(external_exports.unknown()) });
|
|
@@ -25479,7 +24668,13 @@ function parseAttachmentScope(raw) {
|
|
|
25479
24668
|
const entry = AttachmentScopeEntry.safeParse(candidate);
|
|
25480
24669
|
if (entry.success) entries.push(entry.data);
|
|
25481
24670
|
}
|
|
25482
|
-
|
|
24671
|
+
const { endpoint, tenantName, userEmail } = envelope.data;
|
|
24672
|
+
return {
|
|
24673
|
+
endpoint,
|
|
24674
|
+
...tenantName === void 0 ? {} : { tenantName },
|
|
24675
|
+
...userEmail === void 0 ? {} : { userEmail },
|
|
24676
|
+
entries
|
|
24677
|
+
};
|
|
25483
24678
|
} catch {
|
|
25484
24679
|
return void 0;
|
|
25485
24680
|
}
|
|
@@ -25844,6 +25039,27 @@ var ManagedSettings = external_exports.object({
|
|
|
25844
25039
|
};
|
|
25845
25040
|
}).meta({ id: "ManagedSettings" });
|
|
25846
25041
|
|
|
25042
|
+
// ../../packages/schema/src/zod/mod-policy-snapshot.ts
|
|
25043
|
+
var MOD_POLICY_SNAPSHOT_VERSION = 1;
|
|
25044
|
+
var MOD_POLICY_SNAPSHOT_MAX_BYTES = 4 * 1024 * 1024;
|
|
25045
|
+
var ModPolicySnapshot = external_exports.object({
|
|
25046
|
+
version: external_exports.literal(MOD_POLICY_SNAPSHOT_VERSION),
|
|
25047
|
+
generatedAt: external_exports.iso.datetime(),
|
|
25048
|
+
// The complete effective ruleset, as the hook's runtime scans with it: the
|
|
25049
|
+
// user's enabled installed packs (user-modified and custom packs included).
|
|
25050
|
+
// Absent means the store holds no authoritative snapshot, and the reader
|
|
25051
|
+
// scans with the packs it ships — the hook's own fallback.
|
|
25052
|
+
rules: external_exports.array(Rule).optional(),
|
|
25053
|
+
// Rule-targeted actions (first enabled policy per rule wins).
|
|
25054
|
+
ruleActions: external_exports.record(external_exports.string(), ActionTaken),
|
|
25055
|
+
// The resolved action per detection category.
|
|
25056
|
+
categoryActions: external_exports.record(external_exports.string(), ActionTaken),
|
|
25057
|
+
// Rules with an active exception grant. Honouring a grant means matching a
|
|
25058
|
+
// keyed fingerprint of the value and consuming a use, which only the hook can
|
|
25059
|
+
// do, so the mod leaves a finding of one of these rules for the hook to decide.
|
|
25060
|
+
exceptionRuleIds: external_exports.array(external_exports.string())
|
|
25061
|
+
}).meta({ id: "ModPolicySnapshot" });
|
|
25062
|
+
|
|
25847
25063
|
// ../../packages/schema/src/zod/project-files.ts
|
|
25848
25064
|
var ProjectFileInput = external_exports.object({
|
|
25849
25065
|
path: external_exports.string().min(1),
|
|
@@ -26164,7 +25380,16 @@ var AttachInput = external_exports.object({
|
|
|
26164
25380
|
// 200 matches the tenantName bound beside it in control-plane.ts; nothing
|
|
26165
25381
|
// renders a longer one usefully.
|
|
26166
25382
|
label: printable(200).optional(),
|
|
26167
|
-
accessKey: external_exports.string()
|
|
25383
|
+
accessKey: external_exports.string(),
|
|
25384
|
+
// How much of this machine the attachment is for: everything, or only the
|
|
25385
|
+
// repositories its user enrolls. Optional, so an input without it still
|
|
25386
|
+
// parses; what an absent mode means is for whatever reads it to decide, not
|
|
25387
|
+
// this shape. This member validates the VALUE rather than leaving that to the
|
|
25388
|
+
// call site, a deliberate exception to this module's shape-only rule: a shape
|
|
25389
|
+
// rejection names the field, so a value that is not a mode is refused as a bad
|
|
25390
|
+
// `mode` rather than stripped or passed on. The dashboard's attach action reads
|
|
25391
|
+
// it as the mode to attach in.
|
|
25392
|
+
mode: AttachmentMode.optional()
|
|
26168
25393
|
});
|
|
26169
25394
|
|
|
26170
25395
|
// ../../packages/schema/src/zod/triage.ts
|
|
@@ -26450,6 +25675,18 @@ function fromCaptureStatusAttributes(bag) {
|
|
|
26450
25675
|
return parsedStatus.success ? parsedStatus.data : null;
|
|
26451
25676
|
}
|
|
26452
25677
|
|
|
25678
|
+
// ../../packages/persistence/src/attached-derived.ts
|
|
25679
|
+
import { rmSync } from "fs";
|
|
25680
|
+
import { join } from "path";
|
|
25681
|
+
var POLICY_CACHE_FILENAME = "policy-cache.json";
|
|
25682
|
+
var ATTACHED_FORWARD_STATE_FILENAME = "attached-state.json";
|
|
25683
|
+
var ATTACHED_FORWARD_DROPS_FILENAME = "attached-forward-drops.json";
|
|
25684
|
+
var ATTACHED_POSTURE_REPORT_FILENAME = "attached-posture-report.json";
|
|
25685
|
+
|
|
25686
|
+
// ../../packages/persistence/src/control-plane-credential.ts
|
|
25687
|
+
import { chmodSync as chmodSync2, lstatSync as lstatSync2, readFileSync, rmSync as rmSync3, statSync } from "fs";
|
|
25688
|
+
import { join as join2 } from "path";
|
|
25689
|
+
|
|
26453
25690
|
// ../../packages/persistence/src/paths.ts
|
|
26454
25691
|
import {
|
|
26455
25692
|
chmodSync,
|
|
@@ -26576,6 +25813,14 @@ function repairOrRefuseMode(file2) {
|
|
|
26576
25813
|
}
|
|
26577
25814
|
return "ok";
|
|
26578
25815
|
}
|
|
25816
|
+
function asReadableCredential(value) {
|
|
25817
|
+
const result = AttachedCredentialAny.safeParse(value);
|
|
25818
|
+
if (!result.success) return null;
|
|
25819
|
+
if (attachmentModeOf(result.data) === "machine" && typeof value === "object" && value !== null && Object.hasOwn(value, "mode")) {
|
|
25820
|
+
return null;
|
|
25821
|
+
}
|
|
25822
|
+
return result.data;
|
|
25823
|
+
}
|
|
26579
25824
|
function readControlPlaneCredentialFile(settingsDir2, connection) {
|
|
26580
25825
|
const file2 = controlPlaneCredentialPath(settingsDir2);
|
|
26581
25826
|
let raw;
|
|
@@ -26594,20 +25839,20 @@ function readControlPlaneCredentialFile(settingsDir2, connection) {
|
|
|
26594
25839
|
} catch {
|
|
26595
25840
|
return { usable: false, reason: "malformed" };
|
|
26596
25841
|
}
|
|
26597
|
-
const
|
|
26598
|
-
if (
|
|
26599
|
-
if (!isSafeEndpoint(
|
|
25842
|
+
const credential = asReadableCredential(parsed2);
|
|
25843
|
+
if (credential === null) return { usable: false, reason: "malformed" };
|
|
25844
|
+
if (!isSafeEndpoint(credential.endpoint)) {
|
|
26600
25845
|
return { usable: false, reason: "unsafe-endpoint" };
|
|
26601
25846
|
}
|
|
26602
|
-
if (connection !== void 0 && connection.endpoint !==
|
|
25847
|
+
if (connection !== void 0 && connection.endpoint !== credential.endpoint) {
|
|
26603
25848
|
return {
|
|
26604
25849
|
usable: false,
|
|
26605
25850
|
reason: "endpoint-mismatch",
|
|
26606
|
-
credentialEndpoint:
|
|
25851
|
+
credentialEndpoint: credential.endpoint,
|
|
26607
25852
|
settingsEndpoint: connection.endpoint
|
|
26608
25853
|
};
|
|
26609
25854
|
}
|
|
26610
|
-
return { usable: true, credential
|
|
25855
|
+
return { usable: true, credential };
|
|
26611
25856
|
}
|
|
26612
25857
|
function readControlPlaneCredential(settingsDir2, connection) {
|
|
26613
25858
|
const read = readControlPlaneCredentialFile(settingsDir2, connection);
|
|
@@ -26616,7 +25861,7 @@ function readControlPlaneCredential(settingsDir2, connection) {
|
|
|
26616
25861
|
|
|
26617
25862
|
// ../../packages/persistence/src/database.ts
|
|
26618
25863
|
import { randomUUID as randomUUID11 } from "crypto";
|
|
26619
|
-
import { dirname as dirname2, join as
|
|
25864
|
+
import { dirname as dirname2, join as join8, sep } from "path";
|
|
26620
25865
|
import { DatabaseSync } from "node:sqlite";
|
|
26621
25866
|
|
|
26622
25867
|
// ../../packages/persistence/src/ids.ts
|
|
@@ -26660,6 +25905,7 @@ function captureId(sessionId, contentHash, filePath = null) {
|
|
|
26660
25905
|
canonicalIdentity(["capture", sessionId ?? NO_SESSION, contentHash, filePath ?? NO_PATH])
|
|
26661
25906
|
);
|
|
26662
25907
|
}
|
|
25908
|
+
var DOT = ".".charCodeAt(0);
|
|
26663
25909
|
|
|
26664
25910
|
// ../../packages/persistence/src/internal/snapshot.ts
|
|
26665
25911
|
import { randomUUID } from "crypto";
|
|
@@ -26987,6 +26233,25 @@ function scopeKeysParam(scopeKeys) {
|
|
|
26987
26233
|
var ROOT_SCOPE_KEY = `(SELECT session_root.scope_key
|
|
26988
26234
|
FROM audit_events AS session_root
|
|
26989
26235
|
WHERE session_root.id = COALESCE(audit_events.root_session_id, audit_events.id))`;
|
|
26236
|
+
var COUNTED_IN_SCOPE = `
|
|
26237
|
+
AND ${inScope("scope_key")}
|
|
26238
|
+
AND (event_type IN (${CAPTURE_TYPE_LIST}) OR ${inScope(ROOT_SCOPE_KEY)})`;
|
|
26239
|
+
var DRAIN_TOTALS = `SELECT
|
|
26240
|
+
SUM(CASE WHEN synced_at IS NULL AND started_at < :before THEN 1 ELSE 0 END) AS pending,
|
|
26241
|
+
SUM(CASE WHEN synced_at > 0 THEN 1 ELSE 0 END) AS sent,
|
|
26242
|
+
SUM(CASE WHEN synced_at = ${String(SKIPPED)}
|
|
26243
|
+
AND (sync_failure IS NULL OR sync_failure = 'payload_invalid')
|
|
26244
|
+
THEN 1 ELSE 0 END) AS skipped,
|
|
26245
|
+
SUM(CASE WHEN synced_at = ${String(SKIPPED)}
|
|
26246
|
+
AND sync_failure = 'deployment_refused' THEN 1 ELSE 0 END) AS refused,
|
|
26247
|
+
SUM(CASE WHEN synced_at = ${String(SKIPPED)}
|
|
26248
|
+
AND sync_failure = 'detached_undelivered' THEN 1 ELSE 0 END) AS detached
|
|
26249
|
+
FROM audit_events
|
|
26250
|
+
WHERE event_type IN (${TYPE_LIST})`;
|
|
26251
|
+
var CAPTURE_SKIPS = `SELECT COUNT(*) AS skipped
|
|
26252
|
+
FROM audit_events
|
|
26253
|
+
WHERE synced_at = ${String(SKIPPED)}
|
|
26254
|
+
AND event_type IN (${CAPTURE_TYPE_LIST})`;
|
|
26990
26255
|
var ROW_COLUMNS = `id,
|
|
26991
26256
|
parent_id AS parentId,
|
|
26992
26257
|
root_session_id AS rootSessionId,
|
|
@@ -27062,7 +26327,7 @@ var SqliteHistorySyncRepository = class {
|
|
|
27062
26327
|
);
|
|
27063
26328
|
this.scopedCaptureRowsStmt = db.prepare(
|
|
27064
26329
|
`SELECT ${ROW_COLUMNS}
|
|
27065
|
-
FROM audit_events
|
|
26330
|
+
FROM audit_events INDEXED BY idx_audit_scope_owed
|
|
27066
26331
|
WHERE synced_at IS NULL
|
|
27067
26332
|
AND sync_claimed_at IS NULL
|
|
27068
26333
|
AND outbox_owed = 1
|
|
@@ -27115,40 +26380,28 @@ var SqliteHistorySyncRepository = class {
|
|
|
27115
26380
|
);
|
|
27116
26381
|
this.partitionStmt = db.prepare(`SELECT${PARTITION_BUCKETS}
|
|
27117
26382
|
FROM audit_events${COUNTED_SCOPE}`);
|
|
26383
|
+
this.scopedPartitionStmt = db.prepare(`SELECT${PARTITION_BUCKETS}
|
|
26384
|
+
FROM audit_events${COUNTED_SCOPE}${COUNTED_IN_SCOPE}`);
|
|
27118
26385
|
this.partitionByKindStmt = db.prepare(
|
|
27119
26386
|
`SELECT event_type AS kind,${PARTITION_BUCKETS}
|
|
27120
26387
|
FROM audit_events INDEXED BY idx_audit_events_sync${COUNTED_SCOPE}
|
|
27121
26388
|
GROUP BY event_type`
|
|
27122
26389
|
);
|
|
27123
|
-
this.
|
|
27124
|
-
`SELECT
|
|
27125
|
-
|
|
27126
|
-
|
|
27127
|
-
SUM(CASE WHEN synced_at = ${String(SKIPPED)}
|
|
27128
|
-
AND (sync_failure IS NULL OR sync_failure = 'payload_invalid')
|
|
27129
|
-
THEN 1 ELSE 0 END) AS skipped,
|
|
27130
|
-
SUM(CASE WHEN synced_at = ${String(SKIPPED)}
|
|
27131
|
-
AND sync_failure = 'deployment_refused' THEN 1 ELSE 0 END) AS refused,
|
|
27132
|
-
SUM(CASE WHEN synced_at = ${String(SKIPPED)}
|
|
27133
|
-
AND sync_failure = 'detached_undelivered' THEN 1 ELSE 0 END) AS detached
|
|
27134
|
-
FROM audit_events
|
|
27135
|
-
WHERE event_type IN (${TYPE_LIST})`
|
|
26390
|
+
this.scopedPartitionByKindStmt = db.prepare(
|
|
26391
|
+
`SELECT event_type AS kind,${PARTITION_BUCKETS}
|
|
26392
|
+
FROM audit_events INDEXED BY idx_audit_events_sync${COUNTED_SCOPE}${COUNTED_IN_SCOPE}
|
|
26393
|
+
GROUP BY event_type`
|
|
27136
26394
|
);
|
|
27137
|
-
this.
|
|
27138
|
-
|
|
27139
|
-
|
|
27140
|
-
|
|
27141
|
-
|
|
27142
|
-
|
|
27143
|
-
|
|
27144
|
-
|
|
27145
|
-
|
|
27146
|
-
|
|
27147
|
-
// frees.
|
|
27148
|
-
`SELECT COUNT(*) AS skipped
|
|
27149
|
-
FROM audit_events
|
|
27150
|
-
WHERE synced_at = ${String(SKIPPED)}
|
|
27151
|
-
AND event_type IN (${CAPTURE_TYPE_LIST})`
|
|
26395
|
+
this.countsStmt = db.prepare(DRAIN_TOTALS);
|
|
26396
|
+
this.scopedCountsStmt = db.prepare(
|
|
26397
|
+
`${DRAIN_TOTALS}
|
|
26398
|
+
AND ${inScope("scope_key")}
|
|
26399
|
+
AND ${inScope(ROOT_SCOPE_KEY)}`
|
|
26400
|
+
);
|
|
26401
|
+
this.captureSkipCountStmt = db.prepare(CAPTURE_SKIPS);
|
|
26402
|
+
this.scopedCaptureSkipCountStmt = db.prepare(
|
|
26403
|
+
`${CAPTURE_SKIPS}
|
|
26404
|
+
AND ${inScope("scope_key")}`
|
|
27152
26405
|
);
|
|
27153
26406
|
this.fingerprintStmt = db.prepare(
|
|
27154
26407
|
`SELECT endpoint_fingerprint AS fingerprint, backlog_before AS backlogBefore
|
|
@@ -27262,6 +26515,10 @@ var SqliteHistorySyncRepository = class {
|
|
|
27262
26515
|
scopedCaptureRowsStmt;
|
|
27263
26516
|
scopedCaptureBacklogOwedStmt;
|
|
27264
26517
|
markScopeCapturesOwedStmt;
|
|
26518
|
+
scopedPartitionStmt;
|
|
26519
|
+
scopedPartitionByKindStmt;
|
|
26520
|
+
scopedCountsStmt;
|
|
26521
|
+
scopedCaptureSkipCountStmt;
|
|
27265
26522
|
/**
|
|
27266
26523
|
* The masked detections recorded against one tool call.
|
|
27267
26524
|
*
|
|
@@ -27483,7 +26740,29 @@ var SqliteHistorySyncRepository = class {
|
|
|
27483
26740
|
* in" — and a machine that has never attached has no boundary to pass, so
|
|
27484
26741
|
* requiring one would force a caller to invent one and report the whole store
|
|
27485
26742
|
* as queued.
|
|
26743
|
+
*
|
|
26744
|
+
* `scopeKeys` is a scoped attachment's filter: every bucket then counts only
|
|
26745
|
+
* the rows that pass the drain's reachability rule for that scope
|
|
26746
|
+
* (COUNTED_IN_SCOPE, which also names the one kind of row it counts that the
|
|
26747
|
+
* drain never offers), so a personal repository's rows are in none of them.
|
|
26748
|
+
* Omitted, this runs the machine statement, unchanged; an empty list counts
|
|
26749
|
+
* nothing.
|
|
27486
26750
|
*/
|
|
26751
|
+
partition(scopeKeys) {
|
|
26752
|
+
const row = getRow(
|
|
26753
|
+
scopeKeys === void 0 ? this.partitionStmt : this.scopedPartitionStmt,
|
|
26754
|
+
scopeKeys === void 0 ? {} : { scopeKeys: scopeKeysParam(scopeKeys) }
|
|
26755
|
+
);
|
|
26756
|
+
return {
|
|
26757
|
+
queued: row?.queued ?? 0,
|
|
26758
|
+
inProgress: row?.inProgress ?? 0,
|
|
26759
|
+
synced: row?.synced ?? 0,
|
|
26760
|
+
failed: row?.failed ?? 0,
|
|
26761
|
+
refused: row?.refused ?? 0,
|
|
26762
|
+
detached: row?.detached ?? 0,
|
|
26763
|
+
total: row?.total ?? 0
|
|
26764
|
+
};
|
|
26765
|
+
}
|
|
27487
26766
|
/**
|
|
27488
26767
|
* The same partition, one row per kind that a lane carries.
|
|
27489
26768
|
*
|
|
@@ -27493,11 +26772,14 @@ var SqliteHistorySyncRepository = class {
|
|
|
27493
26772
|
* rendering a fixed list of kinds must therefore treat a missing one as "no
|
|
27494
26773
|
* rows", never as "zero sent"; the two look identical in a bar and mean
|
|
27495
26774
|
* different things.
|
|
26775
|
+
*
|
|
26776
|
+
* `scopeKeys` scopes it with the clause `partition` uses, so the per-kind rows
|
|
26777
|
+
* still sum to the scoped aggregate. An empty list returns no rows.
|
|
27496
26778
|
*/
|
|
27497
|
-
partitionByKind() {
|
|
26779
|
+
partitionByKind(scopeKeys) {
|
|
27498
26780
|
return allRows(
|
|
27499
|
-
this.partitionByKindStmt,
|
|
27500
|
-
{}
|
|
26781
|
+
scopeKeys === void 0 ? this.partitionByKindStmt : this.scopedPartitionByKindStmt,
|
|
26782
|
+
scopeKeys === void 0 ? {} : { scopeKeys: scopeKeysParam(scopeKeys) }
|
|
27501
26783
|
).map((row) => ({
|
|
27502
26784
|
kind: row.kind,
|
|
27503
26785
|
queued: row.queued ?? 0,
|
|
@@ -27509,22 +26791,25 @@ var SqliteHistorySyncRepository = class {
|
|
|
27509
26791
|
total: row.total ?? 0
|
|
27510
26792
|
}));
|
|
27511
26793
|
}
|
|
27512
|
-
|
|
27513
|
-
|
|
27514
|
-
|
|
27515
|
-
|
|
27516
|
-
|
|
27517
|
-
|
|
27518
|
-
|
|
27519
|
-
|
|
27520
|
-
|
|
27521
|
-
|
|
27522
|
-
|
|
27523
|
-
|
|
27524
|
-
|
|
27525
|
-
|
|
27526
|
-
|
|
27527
|
-
|
|
26794
|
+
/**
|
|
26795
|
+
* The drain's totals. `pending` counts only what is inside the backlog; sent
|
|
26796
|
+
* and skipped are totals.
|
|
26797
|
+
*
|
|
26798
|
+
* `scopeKeys` is a scoped attachment's filter, and it scopes every figure,
|
|
26799
|
+
* `capturesSkipped` included: a structural row is counted only when its own
|
|
26800
|
+
* key and its session root's key are among them, a capture when its own key
|
|
26801
|
+
* is. So `pending` is exactly what pendingSessions and pendingRows page out
|
|
26802
|
+
* under the same keys and boundary. Omitted, this runs the machine
|
|
26803
|
+
* statements, unchanged; an empty list counts nothing.
|
|
26804
|
+
*/
|
|
26805
|
+
counts(before, scopeKeys) {
|
|
26806
|
+
const row = getRow(
|
|
26807
|
+
scopeKeys === void 0 ? this.countsStmt : this.scopedCountsStmt,
|
|
26808
|
+
scopeKeys === void 0 ? { before } : { before, scopeKeys: scopeKeysParam(scopeKeys) }
|
|
26809
|
+
);
|
|
26810
|
+
const captures = scopeKeys === void 0 ? getRow(this.captureSkipCountStmt) : getRow(this.scopedCaptureSkipCountStmt, {
|
|
26811
|
+
scopeKeys: scopeKeysParam(scopeKeys)
|
|
26812
|
+
});
|
|
27528
26813
|
return {
|
|
27529
26814
|
pending: row?.pending ?? 0,
|
|
27530
26815
|
sent: row?.sent ?? 0,
|
|
@@ -27776,6 +27061,7 @@ function applyMigrations(db, file2, options = {}) {
|
|
|
27776
27061
|
}
|
|
27777
27062
|
ensureSyncedAtColumn(db, "audit_events");
|
|
27778
27063
|
ensureScopeKeyColumn(db);
|
|
27064
|
+
ensureScopeOwedIndex(db);
|
|
27779
27065
|
ensureScanLedgerTable(db);
|
|
27780
27066
|
ensureHistorySyncTable(db);
|
|
27781
27067
|
ensureBlockedDetectionsTable(db);
|
|
@@ -28216,14 +27502,48 @@ function ensureScopeKeyColumn(db) {
|
|
|
28216
27502
|
function hasScopeKeyColumn(db) {
|
|
28217
27503
|
return columnNames(db, "audit_events", { includeGenerated: true }).includes("scope_key");
|
|
28218
27504
|
}
|
|
27505
|
+
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";
|
|
27506
|
+
function ensureScopeOwedIndex(db) {
|
|
27507
|
+
if (!schemaObjectExists(db, "table", "audit_events")) return;
|
|
27508
|
+
const columns = columnNames(db, "audit_events", { includeGenerated: true });
|
|
27509
|
+
const complete = ["scope_key", "outbox_owed", "synced_at"].every((c) => columns.includes(c));
|
|
27510
|
+
if (!complete) return;
|
|
27511
|
+
db.exec(SCOPE_OWED_INDEX_DDL);
|
|
27512
|
+
}
|
|
28219
27513
|
function ensureScanLedgerTable(db) {
|
|
28220
27514
|
db.exec(`CREATE TABLE IF NOT EXISTS scan_ledger (
|
|
28221
27515
|
path TEXT PRIMARY KEY,
|
|
28222
27516
|
mtime TEXT NOT NULL,
|
|
28223
27517
|
content_hash TEXT NOT NULL,
|
|
28224
27518
|
ruleset_hash TEXT NOT NULL,
|
|
28225
|
-
scanned_at INTEGER NOT NULL
|
|
27519
|
+
scanned_at INTEGER NOT NULL,
|
|
27520
|
+
scope_key TEXT,
|
|
27521
|
+
scope_root TEXT
|
|
28226
27522
|
)`);
|
|
27523
|
+
ensureScanLedgerScopeKeyColumn(db);
|
|
27524
|
+
ensureScanLedgerScopeRootColumn(db);
|
|
27525
|
+
}
|
|
27526
|
+
var SCAN_LEDGER_SCOPE_KEY_DDL = "ALTER TABLE scan_ledger ADD COLUMN scope_key TEXT";
|
|
27527
|
+
var SCAN_LEDGER_SCOPE_ROOT_DDL = "ALTER TABLE scan_ledger ADD COLUMN scope_root TEXT";
|
|
27528
|
+
function ensureScanLedgerScopeKeyColumn(db) {
|
|
27529
|
+
ensureScanLedgerColumn(db, "scope_key", SCAN_LEDGER_SCOPE_KEY_DDL);
|
|
27530
|
+
}
|
|
27531
|
+
function ensureScanLedgerScopeRootColumn(db) {
|
|
27532
|
+
ensureScanLedgerColumn(db, "scope_root", SCAN_LEDGER_SCOPE_ROOT_DDL);
|
|
27533
|
+
}
|
|
27534
|
+
function ensureScanLedgerColumn(db, column, ddl) {
|
|
27535
|
+
if (!schemaObjectExists(db, "table", "scan_ledger")) return;
|
|
27536
|
+
if (hasScanLedgerColumn(db, column)) return;
|
|
27537
|
+
withTransaction(
|
|
27538
|
+
db,
|
|
27539
|
+
() => {
|
|
27540
|
+
if (!hasScanLedgerColumn(db, column)) db.exec(ddl);
|
|
27541
|
+
},
|
|
27542
|
+
"IMMEDIATE"
|
|
27543
|
+
);
|
|
27544
|
+
}
|
|
27545
|
+
function hasScanLedgerColumn(db, column) {
|
|
27546
|
+
return columnNames(db, "scan_ledger").includes(column);
|
|
28227
27547
|
}
|
|
28228
27548
|
function ensureHistorySyncTable(db) {
|
|
28229
27549
|
db.exec(`CREATE TABLE IF NOT EXISTS history_sync (
|
|
@@ -28274,6 +27594,106 @@ function ensureRuleProbeCacheTable(db) {
|
|
|
28274
27594
|
)`);
|
|
28275
27595
|
}
|
|
28276
27596
|
|
|
27597
|
+
// ../../packages/persistence/src/mod-policy-snapshot.ts
|
|
27598
|
+
import { createHash as createHash2 } from "crypto";
|
|
27599
|
+
import { readFileSync as readFileSync2 } from "fs";
|
|
27600
|
+
import { join as join4 } from "path";
|
|
27601
|
+
var MOD_POLICY_SNAPSHOT_FILENAME = "mod-policy.json";
|
|
27602
|
+
function modPolicySnapshotPath(dataDir2) {
|
|
27603
|
+
return join4(dataDir2, MOD_POLICY_SNAPSHOT_FILENAME);
|
|
27604
|
+
}
|
|
27605
|
+
function buildModPolicySnapshot(input2, generatedAt = /* @__PURE__ */ new Date()) {
|
|
27606
|
+
const byRule = /* @__PURE__ */ new Map();
|
|
27607
|
+
const byCategory = /* @__PURE__ */ new Map();
|
|
27608
|
+
for (const policy of input2.policies) {
|
|
27609
|
+
if (!policy.enabled) continue;
|
|
27610
|
+
if ("ruleId" in policy.target) {
|
|
27611
|
+
if (!byRule.has(policy.target.ruleId)) byRule.set(policy.target.ruleId, policy.action);
|
|
27612
|
+
} else if (!byCategory.has(policy.target.category)) {
|
|
27613
|
+
byCategory.set(policy.target.category, policy.action);
|
|
27614
|
+
}
|
|
27615
|
+
}
|
|
27616
|
+
const categoryActions = {};
|
|
27617
|
+
for (const category of DetectionCategory.options) {
|
|
27618
|
+
categoryActions[category] = byCategory.get(category) ?? DEFAULT_ACTIONS[category];
|
|
27619
|
+
}
|
|
27620
|
+
return {
|
|
27621
|
+
version: MOD_POLICY_SNAPSHOT_VERSION,
|
|
27622
|
+
generatedAt: generatedAt.toISOString(),
|
|
27623
|
+
// `examples` is documentation the mod never reads, and a custom pack's are
|
|
27624
|
+
// whatever its author pasted in, so they stay behind.
|
|
27625
|
+
...input2.rules !== void 0 ? { rules: input2.rules.map(withoutExamples) } : {},
|
|
27626
|
+
ruleActions: Object.fromEntries(byRule),
|
|
27627
|
+
categoryActions,
|
|
27628
|
+
exceptionRuleIds: [...new Set(input2.exceptionRuleIds)].sort()
|
|
27629
|
+
};
|
|
27630
|
+
}
|
|
27631
|
+
function assignedRuleActionPolicies(installed) {
|
|
27632
|
+
const out = [];
|
|
27633
|
+
for (const [ruleId, action] of installed.ruleActions) {
|
|
27634
|
+
if (installed.assignedRules.has(ruleId))
|
|
27635
|
+
out.push({ target: { ruleId }, action, enabled: true });
|
|
27636
|
+
}
|
|
27637
|
+
return out;
|
|
27638
|
+
}
|
|
27639
|
+
function withoutExamples(rule) {
|
|
27640
|
+
const copy = { ...rule };
|
|
27641
|
+
delete copy.examples;
|
|
27642
|
+
return copy;
|
|
27643
|
+
}
|
|
27644
|
+
function sameContent(a, b) {
|
|
27645
|
+
return JSON.stringify({ ...a, generatedAt: "" }) === JSON.stringify({ ...b, generatedAt: "" });
|
|
27646
|
+
}
|
|
27647
|
+
function readModPolicySnapshot(dataDir2) {
|
|
27648
|
+
try {
|
|
27649
|
+
const text = readFileSync2(modPolicySnapshotPath(dataDir2), "utf8");
|
|
27650
|
+
if (text.length > MOD_POLICY_SNAPSHOT_MAX_BYTES) return null;
|
|
27651
|
+
const parsed2 = ModPolicySnapshot.safeParse(JSON.parse(text));
|
|
27652
|
+
return parsed2.success ? parsed2.data : null;
|
|
27653
|
+
} catch {
|
|
27654
|
+
return null;
|
|
27655
|
+
}
|
|
27656
|
+
}
|
|
27657
|
+
function writeModPolicySnapshot(dataDir2, snapshot) {
|
|
27658
|
+
const text = JSON.stringify(snapshot);
|
|
27659
|
+
if (Buffer.byteLength(text) > MOD_POLICY_SNAPSHOT_MAX_BYTES) return false;
|
|
27660
|
+
const existing = readModPolicySnapshot(dataDir2);
|
|
27661
|
+
if (existing !== null && sameContent(existing, snapshot)) return false;
|
|
27662
|
+
ensureDataDirSync(dataDir2);
|
|
27663
|
+
writeOwnerOnlyFileSync(modPolicySnapshotPath(dataDir2), text);
|
|
27664
|
+
return true;
|
|
27665
|
+
}
|
|
27666
|
+
function regexProbeKey(matcher) {
|
|
27667
|
+
return createHash2("sha256").update(`${matcher.pattern} ${matcher.flags}`).digest("hex");
|
|
27668
|
+
}
|
|
27669
|
+
function vetRulesForMod(rules, sources, previouslyVetted = /* @__PURE__ */ new Set()) {
|
|
27670
|
+
const bundled = new Set(sources.bundledRegexMatchers().map(regexProbeKey));
|
|
27671
|
+
return rules.filter((rule) => {
|
|
27672
|
+
if (rule.matcher.type !== "regex") return true;
|
|
27673
|
+
const key = regexProbeKey(rule.matcher);
|
|
27674
|
+
const verdict = sources.probeVerdict(key);
|
|
27675
|
+
if (verdict === "quarantined") return false;
|
|
27676
|
+
return verdict === "safe" || bundled.has(key) || previouslyVetted.has(key);
|
|
27677
|
+
});
|
|
27678
|
+
}
|
|
27679
|
+
function modPolicyInputFromStore(sources, previouslyVetted = /* @__PURE__ */ new Set()) {
|
|
27680
|
+
const policies = sources.readPolicies();
|
|
27681
|
+
const snapshot = sources.installedRuleset();
|
|
27682
|
+
const usable = snapshot.installedPacks > 0 && (snapshot.enabledPacks === 0 || snapshot.invalidRules === 0 && snapshot.rules.length > 0);
|
|
27683
|
+
const empty = snapshot.installedPacks > 0 && snapshot.enabledPacks === 0;
|
|
27684
|
+
return {
|
|
27685
|
+
...usable ? { rules: empty ? [] : vetRulesForMod(snapshot.rules, sources, previouslyVetted) } : {},
|
|
27686
|
+
policies: [...policies, ...usable && !empty ? assignedRuleActionPolicies(snapshot) : []],
|
|
27687
|
+
exceptionRuleIds: sources.activeExceptionRuleIds()
|
|
27688
|
+
};
|
|
27689
|
+
}
|
|
27690
|
+
function refreshModPolicySnapshot(dataDir2, sources) {
|
|
27691
|
+
try {
|
|
27692
|
+
writeModPolicySnapshot(dataDir2, buildModPolicySnapshot(modPolicyInputFromStore(sources)));
|
|
27693
|
+
} catch {
|
|
27694
|
+
}
|
|
27695
|
+
}
|
|
27696
|
+
|
|
28277
27697
|
// ../../packages/persistence/src/internal/json.ts
|
|
28278
27698
|
function safeJson(s, fallback) {
|
|
28279
27699
|
if (s == null) return fallback;
|
|
@@ -28448,6 +27868,11 @@ var TIMELINE_COLUMNS = `
|
|
|
28448
27868
|
json_extract(attributes, '$.targetId') AS target_id,
|
|
28449
27869
|
json_extract(attributes, '$.internal') AS internal,
|
|
28450
27870
|
json_extract(attributes, '$.flagged') AS flagged`;
|
|
27871
|
+
var CALL_PROMPT_TOKENS = `(coalesce(input_tokens, 0) + coalesce(cache_read_input_tokens, 0)
|
|
27872
|
+
+ coalesce(ephemeral_1h_input_tokens, 0) + coalesce(ephemeral_5m_input_tokens, 0))`;
|
|
27873
|
+
var CALL_BAND = LONG_CONTEXT_THRESHOLDS.length === 0 ? "0" : LONG_CONTEXT_THRESHOLDS.map((t) => `(${CALL_PROMPT_TOKENS} > ${String(Math.trunc(t))})`).join(
|
|
27874
|
+
" + "
|
|
27875
|
+
);
|
|
28451
27876
|
var LLM_USAGE_SELECT = `
|
|
28452
27877
|
SELECT root_session_id AS sessionId,
|
|
28453
27878
|
provider,
|
|
@@ -28459,9 +27884,10 @@ var LLM_USAGE_SELECT = `
|
|
|
28459
27884
|
coalesce(sum(cache_read_input_tokens), 0) AS cacheReadTokens,
|
|
28460
27885
|
coalesce(sum(ephemeral_1h_input_tokens), 0) AS ephemeral1hTokens,
|
|
28461
27886
|
coalesce(sum(ephemeral_5m_input_tokens), 0) AS ephemeral5mTokens,
|
|
28462
|
-
coalesce(sum(web_search_requests), 0) AS webSearchRequests
|
|
27887
|
+
coalesce(sum(web_search_requests), 0) AS webSearchRequests,
|
|
27888
|
+
coalesce(max(${CALL_PROMPT_TOKENS}), 0) AS promptTokens`;
|
|
28463
27889
|
var LLM_USAGE_SCOPE = `event_type = 'llm_call' AND attributes IS NOT NULL AND root_session_id IS NOT NULL`;
|
|
28464
|
-
var LLM_USAGE_GROUP = `GROUP BY root_session_id, provider, model, service_tier`;
|
|
27890
|
+
var LLM_USAGE_GROUP = `GROUP BY root_session_id, provider, model, service_tier, ${CALL_BAND}`;
|
|
28465
27891
|
function usageLeaves(rows) {
|
|
28466
27892
|
return rows.map((row) => {
|
|
28467
27893
|
const attributes = {
|
|
@@ -28476,7 +27902,7 @@ function usageLeaves(rows) {
|
|
|
28476
27902
|
if (row.provider !== null) attributes.provider = row.provider;
|
|
28477
27903
|
if (row.model !== null) attributes.model = row.model;
|
|
28478
27904
|
if (row.serviceTier !== null) attributes.service_tier = row.serviceTier;
|
|
28479
|
-
return { sessionId: row.sessionId, attributes };
|
|
27905
|
+
return { sessionId: row.sessionId, attributes, promptTokens: row.promptTokens };
|
|
28480
27906
|
});
|
|
28481
27907
|
}
|
|
28482
27908
|
var SESSION_ROOT = `event_type = 'session'`;
|
|
@@ -29810,9 +29236,10 @@ var ACTIVE_REVEAL_GRANT_PREDICATE = `capability = 'reveal_to_model'
|
|
|
29810
29236
|
AND conditions IS NULL
|
|
29811
29237
|
AND ${ACTIVE_PREDICATE}`;
|
|
29812
29238
|
var SqliteExceptionsRepository = class {
|
|
29813
|
-
constructor(db, now = () => Date.now()) {
|
|
29239
|
+
constructor(db, now = () => Date.now(), onChange = () => void 0) {
|
|
29814
29240
|
this.db = db;
|
|
29815
29241
|
this.now = now;
|
|
29242
|
+
this.onChange = onChange;
|
|
29816
29243
|
this.consumeStmt = db.prepare(
|
|
29817
29244
|
`UPDATE exceptions
|
|
29818
29245
|
SET use_count = use_count + 1, last_used_at = :now, updated_at = :now
|
|
@@ -29831,6 +29258,7 @@ var SqliteExceptionsRepository = class {
|
|
|
29831
29258
|
}
|
|
29832
29259
|
db;
|
|
29833
29260
|
now;
|
|
29261
|
+
onChange;
|
|
29834
29262
|
consumeStmt;
|
|
29835
29263
|
insertBlockedStmt;
|
|
29836
29264
|
sweepBlockedStmt;
|
|
@@ -29846,7 +29274,9 @@ var SqliteExceptionsRepository = class {
|
|
|
29846
29274
|
*/
|
|
29847
29275
|
create(input2) {
|
|
29848
29276
|
try {
|
|
29849
|
-
|
|
29277
|
+
const created = this.createSync(input2);
|
|
29278
|
+
this.onChange();
|
|
29279
|
+
return Promise.resolve(created);
|
|
29850
29280
|
} catch (err) {
|
|
29851
29281
|
return Promise.reject(err instanceof Error ? err : new Error(String(err)));
|
|
29852
29282
|
}
|
|
@@ -29977,6 +29407,7 @@ var SqliteExceptionsRepository = class {
|
|
|
29977
29407
|
SET revoked_at = :now, revoked_by = :revokedBy, revoke_reason = :reason, updated_at = :now
|
|
29978
29408
|
WHERE id = :id AND revoked_at IS NULL`
|
|
29979
29409
|
).run({ id, revokedBy, reason: reason ?? null, now });
|
|
29410
|
+
if (Number(result.changes) === 1) this.onChange();
|
|
29980
29411
|
return Promise.resolve(Number(result.changes) === 1);
|
|
29981
29412
|
}
|
|
29982
29413
|
/**
|
|
@@ -29989,6 +29420,15 @@ var SqliteExceptionsRepository = class {
|
|
|
29989
29420
|
const result = this.consumeStmt.run({ id, now });
|
|
29990
29421
|
return Promise.resolve(Number(result.changes) === 1);
|
|
29991
29422
|
}
|
|
29423
|
+
/** The rule ids with at least one active grant, under any key version. */
|
|
29424
|
+
activeRuleIds(now = this.now()) {
|
|
29425
|
+
return allRows(
|
|
29426
|
+
this.db.prepare(
|
|
29427
|
+
`SELECT DISTINCT rule_id AS ruleId FROM exceptions WHERE ${ACTIVE_PREDICATE}`
|
|
29428
|
+
),
|
|
29429
|
+
{ now }
|
|
29430
|
+
).map((row) => row.ruleId);
|
|
29431
|
+
}
|
|
29992
29432
|
/**
|
|
29993
29433
|
* The evaluation subset of every active grant under one fingerprint key
|
|
29994
29434
|
* version — what rides the policy bundle to the hook. Grants written under
|
|
@@ -31112,28 +30552,28 @@ var SqliteInspectionFindingsRepository = class {
|
|
|
31112
30552
|
};
|
|
31113
30553
|
|
|
31114
30554
|
// ../../packages/persistence/src/repositories/installed-packs.ts
|
|
31115
|
-
import { createHash as
|
|
30555
|
+
import { createHash as createHash3, randomUUID as randomUUID4 } from "crypto";
|
|
31116
30556
|
|
|
31117
30557
|
// ../../packages/persistence/src/policy-floor.ts
|
|
31118
|
-
import { readFileSync as
|
|
31119
|
-
import { join as
|
|
30558
|
+
import { readFileSync as readFileSync6 } from "fs";
|
|
30559
|
+
import { join as join7 } from "path";
|
|
31120
30560
|
|
|
31121
30561
|
// ../../packages/persistence/src/local-layout.ts
|
|
31122
30562
|
import { renameSync as renameSync3 } from "fs";
|
|
31123
30563
|
import { mkdir } from "fs/promises";
|
|
31124
30564
|
import { homedir } from "os";
|
|
31125
|
-
import { join as
|
|
30565
|
+
import { join as join5 } from "path";
|
|
31126
30566
|
function defaultDataDir() {
|
|
31127
|
-
return
|
|
30567
|
+
return join5(homedir(), ".aka");
|
|
31128
30568
|
}
|
|
31129
30569
|
function settingsDir(base = defaultDataDir()) {
|
|
31130
|
-
return
|
|
30570
|
+
return join5(base, "settings");
|
|
31131
30571
|
}
|
|
31132
30572
|
function dataDir(base = defaultDataDir()) {
|
|
31133
|
-
return
|
|
30573
|
+
return join5(base, "data");
|
|
31134
30574
|
}
|
|
31135
30575
|
function dbPath(base = defaultDataDir()) {
|
|
31136
|
-
return
|
|
30576
|
+
return join5(dataDir(base), "aka.db");
|
|
31137
30577
|
}
|
|
31138
30578
|
async function ensureDataDir(dir = defaultDataDir()) {
|
|
31139
30579
|
await mkdir(dir, { recursive: true, mode: DATA_DIR_MODE });
|
|
@@ -31150,8 +30590,8 @@ function migrateLegacyLayout(base = defaultDataDir()) {
|
|
|
31150
30590
|
for (const { name, dest } of moves) {
|
|
31151
30591
|
try {
|
|
31152
30592
|
ensureDataDirSync(dest);
|
|
31153
|
-
const moved =
|
|
31154
|
-
renameSync3(
|
|
30593
|
+
const moved = join5(dest, name);
|
|
30594
|
+
renameSync3(join5(base, name), moved);
|
|
31155
30595
|
tightenFile(moved);
|
|
31156
30596
|
} catch {
|
|
31157
30597
|
}
|
|
@@ -31159,8 +30599,8 @@ function migrateLegacyLayout(base = defaultDataDir()) {
|
|
|
31159
30599
|
}
|
|
31160
30600
|
|
|
31161
30601
|
// ../../packages/persistence/src/settings.ts
|
|
31162
|
-
import { readFileSync as
|
|
31163
|
-
import { join as
|
|
30602
|
+
import { readFileSync as readFileSync5 } from "fs";
|
|
30603
|
+
import { join as join6 } from "path";
|
|
31164
30604
|
|
|
31165
30605
|
// ../../packages/persistence/src/file-lock.ts
|
|
31166
30606
|
import { randomUUID as randomUUID3 } from "crypto";
|
|
@@ -31168,7 +30608,7 @@ import {
|
|
|
31168
30608
|
closeSync,
|
|
31169
30609
|
existsSync as existsSync2,
|
|
31170
30610
|
openSync,
|
|
31171
|
-
readFileSync as
|
|
30611
|
+
readFileSync as readFileSync3,
|
|
31172
30612
|
rmSync as rmSync5,
|
|
31173
30613
|
statSync as statSync3,
|
|
31174
30614
|
writeFileSync as writeFileSync2
|
|
@@ -31177,16 +30617,16 @@ import { hostname as hostname3 } from "os";
|
|
|
31177
30617
|
var PARK = new Int32Array(new SharedArrayBuffer(4));
|
|
31178
30618
|
|
|
31179
30619
|
// ../../packages/persistence/src/managed-settings.ts
|
|
31180
|
-
import { readFileSync as
|
|
30620
|
+
import { readFileSync as readFileSync4 } from "fs";
|
|
31181
30621
|
import { posix, win32 } from "path";
|
|
31182
|
-
function managedSettingsPaths(
|
|
31183
|
-
if (
|
|
30622
|
+
function managedSettingsPaths(platform = process.platform) {
|
|
30623
|
+
if (platform === "darwin") {
|
|
31184
30624
|
return [
|
|
31185
30625
|
posix.join("/Library", "Application Support", "AKASecurity", MANAGED_SETTINGS_FILENAME),
|
|
31186
30626
|
posix.join("/Library", "Managed Preferences", MANAGED_SETTINGS_FILENAME)
|
|
31187
30627
|
];
|
|
31188
30628
|
}
|
|
31189
|
-
if (
|
|
30629
|
+
if (platform === "win32") {
|
|
31190
30630
|
return [win32.join("C:\\", "ProgramData", "AKASecurity", MANAGED_SETTINGS_FILENAME)];
|
|
31191
30631
|
}
|
|
31192
30632
|
return [posix.join("/etc", "aka", MANAGED_SETTINGS_FILENAME)];
|
|
@@ -31196,7 +30636,7 @@ function readManagedSettings(paths = testOnlyManagedPaths ?? managedSettingsPath
|
|
|
31196
30636
|
for (const path of paths) {
|
|
31197
30637
|
let text;
|
|
31198
30638
|
try {
|
|
31199
|
-
text =
|
|
30639
|
+
text = readFileSync4(path, "utf8");
|
|
31200
30640
|
} catch {
|
|
31201
30641
|
continue;
|
|
31202
30642
|
}
|
|
@@ -31250,7 +30690,7 @@ function readWorkspaceSettings(base = defaultDataDir()) {
|
|
|
31250
30690
|
return overlayManagedSettings(readUserSettings(base), readManagedSettings());
|
|
31251
30691
|
}
|
|
31252
30692
|
function readUserSettings(base) {
|
|
31253
|
-
const record2 = readJson(
|
|
30693
|
+
const record2 = readJson(join6(settingsDir(base), SETTINGS_FILENAME));
|
|
31254
30694
|
if (!record2) return defaultWorkspaceSettings();
|
|
31255
30695
|
try {
|
|
31256
30696
|
return WorkspaceSettings.parse(record2);
|
|
@@ -31261,7 +30701,7 @@ function readUserSettings(base) {
|
|
|
31261
30701
|
function readJson(file2) {
|
|
31262
30702
|
let text;
|
|
31263
30703
|
try {
|
|
31264
|
-
text =
|
|
30704
|
+
text = readFileSync5(file2, "utf8");
|
|
31265
30705
|
} catch {
|
|
31266
30706
|
return null;
|
|
31267
30707
|
}
|
|
@@ -31301,7 +30741,7 @@ var PolicyFloorError = class extends Error {
|
|
|
31301
30741
|
};
|
|
31302
30742
|
function readCachedPolicyBundle(base = defaultDataDir()) {
|
|
31303
30743
|
try {
|
|
31304
|
-
const raw =
|
|
30744
|
+
const raw = readFileSync6(join7(dataDir(base), POLICY_CACHE_FILENAME), "utf8");
|
|
31305
30745
|
const parsed2 = JSON.parse(raw);
|
|
31306
30746
|
if (typeof parsed2 !== "object" || parsed2 === null) return null;
|
|
31307
30747
|
return PolicyBundle.parse(parsed2.bundle);
|
|
@@ -31425,7 +30865,7 @@ function inventorySignature(packs) {
|
|
|
31425
30865
|
return packs.map((p) => `${p.namespace}/${p.packId}@${p.version}#${hashRules(p.rulesJson)}`).sort().join(",");
|
|
31426
30866
|
}
|
|
31427
30867
|
function hashRules(rulesJson) {
|
|
31428
|
-
return
|
|
30868
|
+
return createHash3("sha256").update(rulesJson).digest("hex");
|
|
31429
30869
|
}
|
|
31430
30870
|
function parseVersion(v) {
|
|
31431
30871
|
const m = /^(\d+)\.(\d+)\.(\d+)/.exec(v);
|
|
@@ -31467,9 +30907,10 @@ var SqliteInstalledPacksRepository = class {
|
|
|
31467
30907
|
* from `openLocalDatabase`, which is the single construction site that owns a
|
|
31468
30908
|
* real `~/.aka`.
|
|
31469
30909
|
*/
|
|
31470
|
-
constructor(db, baseDir) {
|
|
30910
|
+
constructor(db, baseDir, onChange = () => void 0) {
|
|
31471
30911
|
this.db = db;
|
|
31472
30912
|
this.baseDir = baseDir;
|
|
30913
|
+
this.onChange = onChange;
|
|
31473
30914
|
this.insertMissingStmt = db.prepare(
|
|
31474
30915
|
`INSERT INTO installed_packs (id, namespace, pack_id, version, name, rules_json, enabled, policy_id, created_at, updated_at)
|
|
31475
30916
|
VALUES (:id, :namespace, :packId, :version, :name, :rulesJson, 1, :policyId, :now, :now)
|
|
@@ -31498,6 +30939,7 @@ var SqliteInstalledPacksRepository = class {
|
|
|
31498
30939
|
}
|
|
31499
30940
|
db;
|
|
31500
30941
|
baseDir;
|
|
30942
|
+
onChange;
|
|
31501
30943
|
insertMissingStmt;
|
|
31502
30944
|
upsertAvailableStmt;
|
|
31503
30945
|
signatureStmt;
|
|
@@ -31570,6 +31012,7 @@ var SqliteInstalledPacksRepository = class {
|
|
|
31570
31012
|
},
|
|
31571
31013
|
"IMMEDIATE"
|
|
31572
31014
|
);
|
|
31015
|
+
this.onChange();
|
|
31573
31016
|
} catch {
|
|
31574
31017
|
}
|
|
31575
31018
|
}
|
|
@@ -31644,6 +31087,7 @@ var SqliteInstalledPacksRepository = class {
|
|
|
31644
31087
|
},
|
|
31645
31088
|
"IMMEDIATE"
|
|
31646
31089
|
);
|
|
31090
|
+
if (changed) this.onChange();
|
|
31647
31091
|
return changed;
|
|
31648
31092
|
}
|
|
31649
31093
|
/**
|
|
@@ -31885,6 +31329,7 @@ var SqliteInstalledPacksRepository = class {
|
|
|
31885
31329
|
`UPDATE installed_packs SET policy_id = :policyId, updated_at = :now
|
|
31886
31330
|
WHERE namespace = :namespace AND pack_id = :packId`
|
|
31887
31331
|
).run({ policyId, now: Date.now(), namespace, packId });
|
|
31332
|
+
if (Number(res.changes) > 0) this.onChange();
|
|
31888
31333
|
return Number(res.changes) > 0;
|
|
31889
31334
|
}
|
|
31890
31335
|
/**
|
|
@@ -31909,6 +31354,7 @@ var SqliteInstalledPacksRepository = class {
|
|
|
31909
31354
|
`UPDATE installed_packs SET enabled = :enabled, updated_at = :now
|
|
31910
31355
|
WHERE namespace = :namespace AND pack_id = :packId`
|
|
31911
31356
|
).run({ enabled: boolToInt(enabled), now: Date.now(), namespace, packId });
|
|
31357
|
+
if (Number(res.changes) > 0) this.onChange();
|
|
31912
31358
|
return Number(res.changes) > 0;
|
|
31913
31359
|
}
|
|
31914
31360
|
// Fingerprint of the recorded available mirror — compared against the
|
|
@@ -32806,13 +32252,19 @@ var SqliteInventoryAssetsRepository = class {
|
|
|
32806
32252
|
import { randomUUID as randomUUID6 } from "crypto";
|
|
32807
32253
|
var SEED_BATCH_WINDOW_MS = 6e4;
|
|
32808
32254
|
var SqlitePoliciesRepository = class {
|
|
32809
|
-
constructor(db) {
|
|
32255
|
+
constructor(db, onChange = () => void 0) {
|
|
32810
32256
|
this.db = db;
|
|
32257
|
+
this.onChange = onChange;
|
|
32811
32258
|
}
|
|
32812
32259
|
db;
|
|
32260
|
+
onChange;
|
|
32813
32261
|
readPolicies() {
|
|
32262
|
+
return Promise.resolve(this.listPolicies());
|
|
32263
|
+
}
|
|
32264
|
+
/** The synchronous read behind {@link readPolicies}. */
|
|
32265
|
+
listPolicies() {
|
|
32814
32266
|
const rows = allRows(this.db.prepare("SELECT * FROM policies"));
|
|
32815
|
-
|
|
32267
|
+
return mapRowsTolerant(rows, (row) => {
|
|
32816
32268
|
const target = JSON.parse(row.target);
|
|
32817
32269
|
const customKeywords = row.custom_keywords ? JSON.parse(row.custom_keywords) : void 0;
|
|
32818
32270
|
return Policy.parse({
|
|
@@ -32824,7 +32276,6 @@ var SqlitePoliciesRepository = class {
|
|
|
32824
32276
|
customKeywords
|
|
32825
32277
|
});
|
|
32826
32278
|
});
|
|
32827
|
-
return Promise.resolve(policies);
|
|
32828
32279
|
}
|
|
32829
32280
|
// Seed one policy per bundled category at Monitor so the detection-type config
|
|
32830
32281
|
// exists from first run. An unassigned pack's rules follow these rows, so
|
|
@@ -32835,7 +32286,7 @@ var SqlitePoliciesRepository = class {
|
|
|
32835
32286
|
const count = countScalar(this.db, "SELECT count(*) AS n FROM policies");
|
|
32836
32287
|
if (count > 0) {
|
|
32837
32288
|
this.markEarlierChoices();
|
|
32838
|
-
this.monitorUntouchedSeeds();
|
|
32289
|
+
if (this.monitorUntouchedSeeds()) this.onChange();
|
|
32839
32290
|
return;
|
|
32840
32291
|
}
|
|
32841
32292
|
const stmt = this.db.prepare(
|
|
@@ -32852,6 +32303,7 @@ var SqlitePoliciesRepository = class {
|
|
|
32852
32303
|
});
|
|
32853
32304
|
}
|
|
32854
32305
|
});
|
|
32306
|
+
this.onChange();
|
|
32855
32307
|
}
|
|
32856
32308
|
// Before this build, upsertCategoryAction INSERTed a new row with updated_at
|
|
32857
32309
|
// equal to created_at, so a choice made for a category that had no row yet
|
|
@@ -32917,7 +32369,7 @@ var SqlitePoliciesRepository = class {
|
|
|
32917
32369
|
).filter(
|
|
32918
32370
|
(row) => DEFAULT_ACTIONS[row.category] === row.action
|
|
32919
32371
|
);
|
|
32920
|
-
if (untouched.length === 0) return;
|
|
32372
|
+
if (untouched.length === 0) return false;
|
|
32921
32373
|
const stmt = this.db.prepare(
|
|
32922
32374
|
`UPDATE policies SET action = 'log'
|
|
32923
32375
|
WHERE scope = 'global' AND json_extract(target, '$.category') = :category
|
|
@@ -32928,6 +32380,7 @@ var SqlitePoliciesRepository = class {
|
|
|
32928
32380
|
stmt.run({ category: row.category, seeded: row.action });
|
|
32929
32381
|
}
|
|
32930
32382
|
});
|
|
32383
|
+
return true;
|
|
32931
32384
|
}
|
|
32932
32385
|
// Insert-or-update the single global per-category policy row, keyed on the
|
|
32933
32386
|
// existing uq_policies_scope_target unique index (scope, target). `action`
|
|
@@ -32944,6 +32397,7 @@ var SqlitePoliciesRepository = class {
|
|
|
32944
32397
|
ON CONFLICT(scope, target) DO UPDATE SET action = excluded.action, enabled = 1,
|
|
32945
32398
|
updated_at = MAX(excluded.updated_at, policies.created_at + 1)`
|
|
32946
32399
|
).run({ id: randomUUID6(), target: JSON.stringify({ category }), action, now });
|
|
32400
|
+
this.onChange();
|
|
32947
32401
|
}
|
|
32948
32402
|
// Caps every global per-category policy currently set to block/redact down
|
|
32949
32403
|
// to warn (see warn-era-cap.ts). Rule-targeted policies are untouched.
|
|
@@ -32954,6 +32408,7 @@ var SqlitePoliciesRepository = class {
|
|
|
32954
32408
|
WHERE scope='global' AND action IN ('block','redact')
|
|
32955
32409
|
AND json_extract(target,'$.category') IS NOT NULL`
|
|
32956
32410
|
).run({ now: Date.now() });
|
|
32411
|
+
if (Number(info.changes) > 0) this.onChange();
|
|
32957
32412
|
return Number(info.changes);
|
|
32958
32413
|
}
|
|
32959
32414
|
// Whether the category's row was ever written after it was created — by the
|
|
@@ -33273,31 +32728,45 @@ var SqliteScanLedgerRepository = class {
|
|
|
33273
32728
|
constructor(db) {
|
|
33274
32729
|
this.db = db;
|
|
33275
32730
|
this.upsertStmt = db.prepare(
|
|
33276
|
-
`INSERT INTO scan_ledger
|
|
33277
|
-
|
|
32731
|
+
`INSERT INTO scan_ledger
|
|
32732
|
+
(path, mtime, content_hash, ruleset_hash, scope_key, scope_root, scanned_at)
|
|
32733
|
+
VALUES (:path, :mtime, :contentHash, :rulesetHash, :scopeKey, :scopeRoot, :scannedAt)
|
|
33278
32734
|
ON CONFLICT (path) DO UPDATE SET
|
|
33279
32735
|
mtime = excluded.mtime,
|
|
33280
32736
|
content_hash = excluded.content_hash,
|
|
33281
32737
|
ruleset_hash = excluded.ruleset_hash,
|
|
32738
|
+
scope_key = excluded.scope_key,
|
|
32739
|
+
scope_root = excluded.scope_root,
|
|
33282
32740
|
scanned_at = excluded.scanned_at`
|
|
33283
32741
|
);
|
|
33284
32742
|
this.readStmt = db.prepare(
|
|
33285
|
-
`SELECT path, mtime, content_hash AS contentHash
|
|
32743
|
+
`SELECT path, mtime, content_hash AS contentHash, scope_key AS scopeKey,
|
|
32744
|
+
scope_root AS scopeRoot
|
|
33286
32745
|
FROM scan_ledger WHERE ruleset_hash = :rulesetHash`
|
|
33287
32746
|
);
|
|
33288
32747
|
this.pathsStmt = db.prepare(`SELECT path FROM scan_ledger`);
|
|
32748
|
+
this.pathKeysStmt = db.prepare(`SELECT path, scope_key AS scopeKey FROM scan_ledger`);
|
|
33289
32749
|
}
|
|
33290
32750
|
db;
|
|
33291
32751
|
upsertStmt;
|
|
33292
32752
|
readStmt;
|
|
33293
32753
|
pathsStmt;
|
|
32754
|
+
pathKeysStmt;
|
|
33294
32755
|
// Previously scanned files under THIS ruleset, keyed by path. Rows from an
|
|
33295
32756
|
// older ruleset are simply absent, which reads as "never scanned".
|
|
33296
32757
|
entriesForRuleset(rulesetHash) {
|
|
33297
|
-
const rows = allRows(this.readStmt, {
|
|
33298
|
-
|
|
33299
|
-
|
|
33300
|
-
|
|
32758
|
+
const rows = allRows(this.readStmt, { rulesetHash });
|
|
32759
|
+
return new Map(
|
|
32760
|
+
rows.map((r) => [
|
|
32761
|
+
r.path,
|
|
32762
|
+
{
|
|
32763
|
+
mtime: r.mtime,
|
|
32764
|
+
contentHash: r.contentHash,
|
|
32765
|
+
...r.scopeKey !== null ? { scopeKey: r.scopeKey } : {},
|
|
32766
|
+
...r.scopeRoot !== null ? { scopeRoot: r.scopeRoot } : {}
|
|
32767
|
+
}
|
|
32768
|
+
])
|
|
32769
|
+
);
|
|
33301
32770
|
}
|
|
33302
32771
|
// Every ledgered path, whatever ruleset it was scanned under — the set a
|
|
33303
32772
|
// deletion sweep checks against disk. A file deleted before a ruleset change
|
|
@@ -33306,6 +32775,14 @@ var SqliteScanLedgerRepository = class {
|
|
|
33306
32775
|
allPaths() {
|
|
33307
32776
|
return allRows(this.pathsStmt).map((r) => r.path);
|
|
33308
32777
|
}
|
|
32778
|
+
// Every ledgered path with the repository it was in when it was last read,
|
|
32779
|
+
// whatever ruleset it was scanned under: what a deletion sweep needs to say
|
|
32780
|
+
// which repository a vanished file belonged to. `undefined` for a row with no
|
|
32781
|
+
// key, which is every row written before the column existed.
|
|
32782
|
+
pathKeys() {
|
|
32783
|
+
const rows = allRows(this.pathKeysStmt);
|
|
32784
|
+
return new Map(rows.map((r) => [r.path, r.scopeKey ?? void 0]));
|
|
32785
|
+
}
|
|
33309
32786
|
upsertEntries(entries) {
|
|
33310
32787
|
if (entries.length === 0) return;
|
|
33311
32788
|
const scannedAt = Date.now();
|
|
@@ -33316,6 +32793,8 @@ var SqliteScanLedgerRepository = class {
|
|
|
33316
32793
|
mtime: entry.mtime,
|
|
33317
32794
|
contentHash: entry.contentHash,
|
|
33318
32795
|
rulesetHash: entry.rulesetHash,
|
|
32796
|
+
scopeKey: entry.scopeKey ?? null,
|
|
32797
|
+
scopeRoot: entry.scopeRoot ?? null,
|
|
33319
32798
|
scannedAt
|
|
33320
32799
|
});
|
|
33321
32800
|
}
|
|
@@ -34403,6 +33882,11 @@ function withoutDroppedFiles(reconcile, droppedFiles) {
|
|
|
34403
33882
|
deletedFiles: reconcile.deletedFiles.filter((file2) => !dropped.has(file2))
|
|
34404
33883
|
};
|
|
34405
33884
|
}
|
|
33885
|
+
function withoutTrailingSlashes(path) {
|
|
33886
|
+
let end = path.length;
|
|
33887
|
+
while (end > 0 && path.charCodeAt(end - 1) === 47) end--;
|
|
33888
|
+
return path.slice(0, end);
|
|
33889
|
+
}
|
|
34406
33890
|
function toEndpointSummary(row) {
|
|
34407
33891
|
return {
|
|
34408
33892
|
id: row.id,
|
|
@@ -34690,7 +34174,7 @@ var SqliteSharesRepository = class {
|
|
|
34690
34174
|
*/
|
|
34691
34175
|
reconcileCallSites(projectKey, reconcile) {
|
|
34692
34176
|
if (reconcile.mode === "walk") {
|
|
34693
|
-
const prefix = reconcile.walkedPrefix
|
|
34177
|
+
const prefix = withoutTrailingSlashes(reconcile.walkedPrefix);
|
|
34694
34178
|
this.db.prepare(
|
|
34695
34179
|
`DELETE FROM share_call_site
|
|
34696
34180
|
WHERE project_key = :key
|
|
@@ -35258,7 +34742,7 @@ function backupLegacyStore(db, file2) {
|
|
|
35258
34742
|
discardStore(file2, backup);
|
|
35259
34743
|
return backup;
|
|
35260
34744
|
}
|
|
35261
|
-
function openAndInitialize(file2, base, skipTags) {
|
|
34745
|
+
function openAndInitialize(file2, base, skipTags, shippedRegexMatchers2) {
|
|
35262
34746
|
let db = openWithPragmas(file2);
|
|
35263
34747
|
try {
|
|
35264
34748
|
if (isForeignSqliteLineage(db)) {
|
|
@@ -35270,8 +34754,15 @@ function openAndInitialize(file2, base, skipTags) {
|
|
|
35270
34754
|
}
|
|
35271
34755
|
applyMigrations(db, file2, { skipTags });
|
|
35272
34756
|
tightenPerms(file2);
|
|
35273
|
-
const
|
|
35274
|
-
const
|
|
34757
|
+
const modPolicy = {};
|
|
34758
|
+
const onPolicyStateChange = () => {
|
|
34759
|
+
if (modPolicy.current !== void 0)
|
|
34760
|
+
refreshModPolicySnapshot(dirname2(file2), modPolicy.current);
|
|
34761
|
+
};
|
|
34762
|
+
const policies = new SqlitePoliciesRepository(db, onPolicyStateChange);
|
|
34763
|
+
const installedPacks = new SqliteInstalledPacksRepository(db, base, onPolicyStateChange);
|
|
34764
|
+
const ruleProbeCache = new SqliteRuleProbeCacheRepository(db);
|
|
34765
|
+
const exceptions = new SqliteExceptionsRepository(db, void 0, onPolicyStateChange);
|
|
35275
34766
|
const repositories = {
|
|
35276
34767
|
events: new SqliteEventsRepository(db),
|
|
35277
34768
|
findings: new SqliteFindingsRepository(db),
|
|
@@ -35280,9 +34771,9 @@ function openAndInitialize(file2, base, skipTags) {
|
|
|
35280
34771
|
scanLedger: new SqliteScanLedgerRepository(db),
|
|
35281
34772
|
historySync: new SqliteHistorySyncRepository(db),
|
|
35282
34773
|
secretVault: new SqliteSecretVaultRepository(db),
|
|
35283
|
-
exceptions
|
|
34774
|
+
exceptions,
|
|
35284
34775
|
resolutions: new SqliteResolutionsRepository(db),
|
|
35285
|
-
ruleProbeCache
|
|
34776
|
+
ruleProbeCache,
|
|
35286
34777
|
bodyRetention: new SqliteBodyRetentionRepository(db),
|
|
35287
34778
|
security: new SqliteSecurityRepository(db),
|
|
35288
34779
|
detections: new SqliteDetectionsRepository(db),
|
|
@@ -35300,6 +34791,13 @@ function openAndInitialize(file2, base, skipTags) {
|
|
|
35300
34791
|
inspectionFindings: new SqliteInspectionFindingsRepository(db),
|
|
35301
34792
|
configInventory: new SqliteConfigInventoryRepository(db)
|
|
35302
34793
|
};
|
|
34794
|
+
modPolicy.current = {
|
|
34795
|
+
installedRuleset: () => installedPacks.installedRuleset(),
|
|
34796
|
+
readPolicies: () => policies.listPolicies(),
|
|
34797
|
+
activeExceptionRuleIds: () => exceptions.activeRuleIds(),
|
|
34798
|
+
probeVerdict: (key) => ruleProbeCache.getVerdict(key)?.verdict,
|
|
34799
|
+
bundledRegexMatchers: () => shippedRegexMatchers2
|
|
34800
|
+
};
|
|
35303
34801
|
policies.seedDefaults();
|
|
35304
34802
|
return { db, ...repositories };
|
|
35305
34803
|
} catch (err) {
|
|
@@ -35311,7 +34809,7 @@ function openAndInitialize(file2, base, skipTags) {
|
|
|
35311
34809
|
var DEFERRED_TAGS = new Set(DEFERRED_MIGRATION_TAGS);
|
|
35312
34810
|
function openLocalDatabase(dir, options = {}) {
|
|
35313
34811
|
ensureDataDirSync(dir);
|
|
35314
|
-
const file2 =
|
|
34812
|
+
const file2 = join8(dir, DB_FILENAME);
|
|
35315
34813
|
reapStalePartials(file2);
|
|
35316
34814
|
const {
|
|
35317
34815
|
db,
|
|
@@ -35347,7 +34845,8 @@ function openLocalDatabase(dir, options = {}) {
|
|
|
35347
34845
|
// `dataDir()` — so its parent is the `~/.aka` base the layout splits into
|
|
35348
34846
|
// settings/ and data/, and the pack-policy floor needs both halves.
|
|
35349
34847
|
dirname2(dir),
|
|
35350
|
-
options.applyDeferredMigrations === true ? void 0 : DEFERRED_TAGS
|
|
34848
|
+
options.applyDeferredMigrations === true ? void 0 : DEFERRED_TAGS,
|
|
34849
|
+
options.shippedRegexMatchers ?? []
|
|
35351
34850
|
);
|
|
35352
34851
|
function captureRowId(event) {
|
|
35353
34852
|
return captureId(
|
|
@@ -35612,7 +35111,7 @@ function openLocalDatabase(dir, options = {}) {
|
|
|
35612
35111
|
}
|
|
35613
35112
|
|
|
35614
35113
|
// ../../packages/persistence/src/egress-wire.ts
|
|
35615
|
-
import { createHash as
|
|
35114
|
+
import { createHash as createHash4 } from "crypto";
|
|
35616
35115
|
var PROJECT_KEY_DIGEST_VERSION = "v2";
|
|
35617
35116
|
var SCP_FORM = /^(?:[^@/]+@)?([^/:]+):(.+)$/;
|
|
35618
35117
|
var DOS_DRIVE = /^[A-Za-z]:[\\/]/;
|
|
@@ -35644,7 +35143,7 @@ function canonicalGitUrl(url2) {
|
|
|
35644
35143
|
}
|
|
35645
35144
|
function hashProjectKey(projectKey) {
|
|
35646
35145
|
const canonical = projectKey.startsWith("git:") ? `git:${canonicalGitUrl(projectKey.slice("git:".length))}` : projectKey;
|
|
35647
|
-
return
|
|
35146
|
+
return createHash4("sha256").update(`${PROJECT_KEY_DIGEST_VERSION}:${canonical}`, "utf8").digest("hex");
|
|
35648
35147
|
}
|
|
35649
35148
|
var SCOPE_KEY = printable(ATTACHMENT_SCOPE_IDENTITY_MAX_LENGTH);
|
|
35650
35149
|
var URL_SCHEME = /^[a-z][a-z0-9+.-]*:\/\//i;
|
|
@@ -35709,17 +35208,16 @@ function toEgressIngestRequest(input2) {
|
|
|
35709
35208
|
}
|
|
35710
35209
|
|
|
35711
35210
|
// ../../packages/persistence/src/finding-key.ts
|
|
35712
|
-
import { createHash as
|
|
35211
|
+
import { createHash as createHash5 } from "crypto";
|
|
35713
35212
|
|
|
35714
35213
|
// ../../packages/persistence/src/fingerprint.ts
|
|
35715
35214
|
import { createHmac, randomBytes } from "crypto";
|
|
35716
|
-
import { existsSync as existsSync3, readFileSync as
|
|
35717
|
-
import { join as
|
|
35718
|
-
import { DatabaseSync as DatabaseSync2 } from "node:sqlite";
|
|
35215
|
+
import { existsSync as existsSync3, readFileSync as readFileSync7 } from "fs";
|
|
35216
|
+
import { join as join9 } from "path";
|
|
35719
35217
|
var EXCEPTION_KEY_FILENAME = "exception.key";
|
|
35720
35218
|
var KEY_MATERIAL_BYTES = 32;
|
|
35721
35219
|
function keyFilePath(dataDir2) {
|
|
35722
|
-
return
|
|
35220
|
+
return join9(dataDir2, EXCEPTION_KEY_FILENAME);
|
|
35723
35221
|
}
|
|
35724
35222
|
function parseKeyFile(raw) {
|
|
35725
35223
|
const parsed2 = JSON.parse(raw);
|
|
@@ -35742,7 +35240,7 @@ function parseKeyFile(raw) {
|
|
|
35742
35240
|
function readFingerprintKey(dataDir2) {
|
|
35743
35241
|
let raw;
|
|
35744
35242
|
try {
|
|
35745
|
-
raw =
|
|
35243
|
+
raw = readFileSync7(keyFilePath(dataDir2), "utf8");
|
|
35746
35244
|
} catch (err) {
|
|
35747
35245
|
if (err.code === "ENOENT") return null;
|
|
35748
35246
|
throw err instanceof Error ? err : new Error(String(err));
|
|
@@ -35751,8 +35249,8 @@ function readFingerprintKey(dataDir2) {
|
|
|
35751
35249
|
}
|
|
35752
35250
|
|
|
35753
35251
|
// ../../packages/persistence/src/forward-health.ts
|
|
35754
|
-
import { readFileSync as
|
|
35755
|
-
import { join as
|
|
35252
|
+
import { readFileSync as readFileSync8 } from "fs";
|
|
35253
|
+
import { join as join10 } from "path";
|
|
35756
35254
|
var BREAKER_COOLDOWN_MS = 3e4;
|
|
35757
35255
|
function parseForwardHealth(raw, nowMs) {
|
|
35758
35256
|
try {
|
|
@@ -35776,20 +35274,21 @@ function isForwardPaused(health, nowMs) {
|
|
|
35776
35274
|
|
|
35777
35275
|
// ../../packages/persistence/src/history-backfill.ts
|
|
35778
35276
|
import { existsSync as existsSync4 } from "fs";
|
|
35779
|
-
import { join as
|
|
35277
|
+
import { join as join11 } from "path";
|
|
35780
35278
|
|
|
35781
35279
|
// ../../packages/persistence/src/history-preview.ts
|
|
35782
35280
|
import { existsSync as existsSync5 } from "fs";
|
|
35783
|
-
import { join as
|
|
35784
|
-
import { DatabaseSync as
|
|
35281
|
+
import { join as join12 } from "path";
|
|
35282
|
+
import { DatabaseSync as DatabaseSync2 } from "node:sqlite";
|
|
35785
35283
|
|
|
35786
35284
|
// ../../packages/persistence/src/history-sync-state.ts
|
|
35787
|
-
import { readFileSync as
|
|
35788
|
-
import { join as
|
|
35285
|
+
import { readFileSync as readFileSync9 } from "fs";
|
|
35286
|
+
import { join as join13 } from "path";
|
|
35287
|
+
var COUNTS_SCOPES = new Set(AttachmentMode.options);
|
|
35789
35288
|
|
|
35790
35289
|
// ../../packages/persistence/src/store-symlinks.ts
|
|
35791
35290
|
import { existsSync as existsSync6, lstatSync as lstatSync3, readlinkSync, realpathSync, statSync as statSync4 } from "fs";
|
|
35792
|
-
import { dirname as dirname3, join as
|
|
35291
|
+
import { dirname as dirname3, join as join14, resolve } from "path";
|
|
35793
35292
|
|
|
35794
35293
|
// ../../packages/persistence/src/vault/crypto.ts
|
|
35795
35294
|
import {
|
|
@@ -35803,19 +35302,19 @@ import {
|
|
|
35803
35302
|
// ../../packages/persistence/src/vault/key-provider.ts
|
|
35804
35303
|
import { execFileSync } from "child_process";
|
|
35805
35304
|
import { randomBytes as randomBytes2 } from "crypto";
|
|
35806
|
-
import { chmodSync as chmodSync3, readFileSync as
|
|
35807
|
-
import { join as
|
|
35305
|
+
import { chmodSync as chmodSync3, readFileSync as readFileSync10, renameSync as renameSync4, rmSync as rmSync6, statSync as statSync5, writeFileSync as writeFileSync3 } from "fs";
|
|
35306
|
+
import { join as join15 } from "path";
|
|
35808
35307
|
|
|
35809
35308
|
// ../../packages/persistence/src/vault/vault.ts
|
|
35810
35309
|
import { randomBytes as randomBytes3, randomUUID as randomUUID12 } from "crypto";
|
|
35811
35310
|
|
|
35812
35311
|
// ../../packages/persistence/src/warn-era-cap.ts
|
|
35813
35312
|
import { existsSync as existsSync7, writeFileSync as writeFileSync4 } from "fs";
|
|
35814
|
-
import { join as
|
|
35313
|
+
import { join as join16 } from "path";
|
|
35815
35314
|
var MARKER = "warn-era-capped";
|
|
35816
35315
|
function capWarnEraEnforcementOnce(db, policyMode, dataDir2) {
|
|
35817
35316
|
if (policyMode !== "warn") return { capped: 0, skipped: "not-warn" };
|
|
35818
|
-
const marker =
|
|
35317
|
+
const marker = join16(dataDir2, MARKER);
|
|
35819
35318
|
if (existsSync7(marker)) return { capped: 0, skipped: "already-run" };
|
|
35820
35319
|
const capped = db.policies.capCategoryActions();
|
|
35821
35320
|
writeFileSync4(marker, `${new Date(Date.now()).toISOString()}
|
|
@@ -35823,425 +35322,6 @@ function capWarnEraEnforcementOnce(db, policyMode, dataDir2) {
|
|
|
35823
35322
|
return { capped };
|
|
35824
35323
|
}
|
|
35825
35324
|
|
|
35826
|
-
// ../../packages/remote/src/http.ts
|
|
35827
|
-
import { request as httpRequest } from "http";
|
|
35828
|
-
import { request as httpsRequest } from "https";
|
|
35829
|
-
var DEFAULT_TIMEOUT_MS = 1e4;
|
|
35830
|
-
var MAX_RESPONSE_BYTES = 8 * 1024 * 1024;
|
|
35831
|
-
var RemoteRequestError = class extends Error {
|
|
35832
|
-
constructor(status) {
|
|
35833
|
-
super(`control-plane request failed with status ${String(status)}`);
|
|
35834
|
-
this.status = status;
|
|
35835
|
-
this.name = "RemoteRequestError";
|
|
35836
|
-
}
|
|
35837
|
-
status;
|
|
35838
|
-
};
|
|
35839
|
-
var RemoteRouteAbsent = class extends Error {
|
|
35840
|
-
constructor(route) {
|
|
35841
|
-
super(`control plane does not serve ${route}`);
|
|
35842
|
-
this.route = route;
|
|
35843
|
-
this.name = "RemoteRouteAbsent";
|
|
35844
|
-
}
|
|
35845
|
-
route;
|
|
35846
|
-
};
|
|
35847
|
-
var RemoteRequestInvalid = class extends Error {
|
|
35848
|
-
constructor(route, cause) {
|
|
35849
|
-
super(`refusing to send a malformed body to ${route}`);
|
|
35850
|
-
this.cause = cause;
|
|
35851
|
-
this.name = "RemoteRequestInvalid";
|
|
35852
|
-
}
|
|
35853
|
-
cause;
|
|
35854
|
-
};
|
|
35855
|
-
var RemoteEndpointRefused = class extends Error {
|
|
35856
|
-
constructor(endpoint) {
|
|
35857
|
-
super(`refusing to talk to an unsafe control-plane endpoint: ${originOnly(endpoint)}`);
|
|
35858
|
-
this.name = "RemoteEndpointRefused";
|
|
35859
|
-
}
|
|
35860
|
-
};
|
|
35861
|
-
var RemoteResponseInvalid = class extends Error {
|
|
35862
|
-
constructor(route, detail) {
|
|
35863
|
-
super(`control plane answered ${route} with ${detail}`);
|
|
35864
|
-
this.name = "RemoteResponseInvalid";
|
|
35865
|
-
}
|
|
35866
|
-
};
|
|
35867
|
-
var RemoteTransportError = class extends Error {
|
|
35868
|
-
/**
|
|
35869
|
-
* The status the peer sent, when headers arrived and only the BODY was
|
|
35870
|
-
* refused.
|
|
35871
|
-
*
|
|
35872
|
-
* Undefined for the ordinary case this class was written for — no answer at
|
|
35873
|
-
* all. It exists because two paths reject after a status has already been
|
|
35874
|
-
* delivered: an oversized body and an aborted response. Discarding it there
|
|
35875
|
-
* reported a deployment answering 401 with a verbose body as a network
|
|
35876
|
-
* outage, which sends the reader to look at their network instead of their
|
|
35877
|
-
* credential.
|
|
35878
|
-
*/
|
|
35879
|
-
constructor(reason, status) {
|
|
35880
|
-
super(`control-plane request did not complete: ${reason}`);
|
|
35881
|
-
this.status = status;
|
|
35882
|
-
this.name = "RemoteTransportError";
|
|
35883
|
-
}
|
|
35884
|
-
status;
|
|
35885
|
-
};
|
|
35886
|
-
async function send(options) {
|
|
35887
|
-
const url2 = new URL(options.url);
|
|
35888
|
-
const timeoutMs = options.timeoutMs ?? DEFAULT_TIMEOUT_MS;
|
|
35889
|
-
const send_ = url2.protocol === "http:" ? httpRequest : httpsRequest;
|
|
35890
|
-
const requestOptions = {
|
|
35891
|
-
method: options.method,
|
|
35892
|
-
headers: {
|
|
35893
|
-
// CALLER HEADERS FIRST, so this module's own are not overridable. Spread
|
|
35894
|
-
// last they win, and two of the values below are ones no caller may
|
|
35895
|
-
// replace: `x-api-key` is the credential, and `content-length` is the
|
|
35896
|
-
// byte count that stops a multi-byte body being truncated by the
|
|
35897
|
-
// receiver. `SendOptions.headers` is a free-form record on an exported
|
|
35898
|
-
// function, so "no caller does that today" is not the guarantee to rely
|
|
35899
|
-
// on. The one header any caller actually passes — `if-none-match` on the
|
|
35900
|
-
// conditional GET — is untouched by this order.
|
|
35901
|
-
...options.headers,
|
|
35902
|
-
// The credential. One header, matching what the deployment authenticates
|
|
35903
|
-
// on; a second copy in an `Authorization` header would be one more place
|
|
35904
|
-
// it can be logged by an intermediary for no gain.
|
|
35905
|
-
//
|
|
35906
|
-
// Spread conditionally rather than assigned as `undefined`: Node's header
|
|
35907
|
-
// handling and `content-length` bookkeeping treat a present-but-undefined
|
|
35908
|
-
// key differently from an absent one, and "the header is not there" is
|
|
35909
|
-
// the property the attach flow needs.
|
|
35910
|
-
...options.apiKey === void 0 ? {} : { "x-api-key": options.apiKey },
|
|
35911
|
-
accept: "application/json",
|
|
35912
|
-
...options.body === void 0 ? {} : {
|
|
35913
|
-
"content-type": "application/json",
|
|
35914
|
-
// Byte length, not string length: a multi-byte body sent with a
|
|
35915
|
-
// character count is truncated by the receiver.
|
|
35916
|
-
"content-length": String(Buffer.byteLength(options.body))
|
|
35917
|
-
}
|
|
35918
|
-
}
|
|
35919
|
-
};
|
|
35920
|
-
return new Promise((resolve3, reject) => {
|
|
35921
|
-
let settled = false;
|
|
35922
|
-
const fail = (reason, status) => {
|
|
35923
|
-
if (settled) return;
|
|
35924
|
-
settled = true;
|
|
35925
|
-
reject(new RemoteTransportError(reason, status));
|
|
35926
|
-
};
|
|
35927
|
-
const req = send_(url2, requestOptions, (res) => {
|
|
35928
|
-
const chunks = [];
|
|
35929
|
-
let size = 0;
|
|
35930
|
-
res.on("data", (chunk) => {
|
|
35931
|
-
size += chunk.length;
|
|
35932
|
-
if (size > MAX_RESPONSE_BYTES) {
|
|
35933
|
-
fail(`response exceeded ${String(MAX_RESPONSE_BYTES)} bytes`, res.statusCode);
|
|
35934
|
-
res.destroy();
|
|
35935
|
-
req.destroy();
|
|
35936
|
-
return;
|
|
35937
|
-
}
|
|
35938
|
-
chunks.push(chunk);
|
|
35939
|
-
});
|
|
35940
|
-
res.on("aborted", () => {
|
|
35941
|
-
fail("the response was aborted", res.statusCode);
|
|
35942
|
-
});
|
|
35943
|
-
res.on("end", () => {
|
|
35944
|
-
if (settled) return;
|
|
35945
|
-
settled = true;
|
|
35946
|
-
resolve3({
|
|
35947
|
-
status: res.statusCode ?? 0,
|
|
35948
|
-
headers: res.headers,
|
|
35949
|
-
body: Buffer.concat(chunks).toString("utf8")
|
|
35950
|
-
});
|
|
35951
|
-
});
|
|
35952
|
-
});
|
|
35953
|
-
const deadline = setTimeout(() => {
|
|
35954
|
-
fail(`no response within ${String(timeoutMs)}ms`);
|
|
35955
|
-
req.destroy();
|
|
35956
|
-
}, timeoutMs);
|
|
35957
|
-
deadline.unref();
|
|
35958
|
-
req.on("upgrade", (_res, socket) => {
|
|
35959
|
-
fail("the deployment answered with a protocol upgrade");
|
|
35960
|
-
socket.destroy();
|
|
35961
|
-
});
|
|
35962
|
-
req.on("close", () => {
|
|
35963
|
-
fail("the connection closed before a response was read");
|
|
35964
|
-
clearTimeout(deadline);
|
|
35965
|
-
});
|
|
35966
|
-
req.on("error", (err) => {
|
|
35967
|
-
fail(err.message);
|
|
35968
|
-
});
|
|
35969
|
-
if (options.body !== void 0) req.write(options.body);
|
|
35970
|
-
req.end();
|
|
35971
|
-
});
|
|
35972
|
-
}
|
|
35973
|
-
|
|
35974
|
-
// ../../packages/remote/src/client.ts
|
|
35975
|
-
var ROUTES = {
|
|
35976
|
-
events: "/v1/events",
|
|
35977
|
-
auditEvents: "/v1/audit-events",
|
|
35978
|
-
auditEventsBatch: "/v1/audit-events/batch",
|
|
35979
|
-
inventory: "/v1/inventory",
|
|
35980
|
-
storePosture: "/v1/store-posture",
|
|
35981
|
-
policyBundle: "/v1/policy-bundle",
|
|
35982
|
-
whoami: "/v1/plugin/whoami",
|
|
35983
|
-
shares: "/v1/shares",
|
|
35984
|
-
commands: "/v1/plugin/commands"
|
|
35985
|
-
};
|
|
35986
|
-
function ackRoute(id) {
|
|
35987
|
-
return `${ROUTES.commands}/${encodeURIComponent(id)}/ack`;
|
|
35988
|
-
}
|
|
35989
|
-
function headerValue(response, name) {
|
|
35990
|
-
const raw = response.headers[name];
|
|
35991
|
-
if (raw === void 0) return void 0;
|
|
35992
|
-
return Array.isArray(raw) ? raw[0] : raw;
|
|
35993
|
-
}
|
|
35994
|
-
function okBody(response) {
|
|
35995
|
-
if (response.status < 200 || response.status >= 300) {
|
|
35996
|
-
throw new RemoteRequestError(response.status);
|
|
35997
|
-
}
|
|
35998
|
-
return response.body;
|
|
35999
|
-
}
|
|
36000
|
-
function parsed(schema, body, route) {
|
|
36001
|
-
let json2;
|
|
36002
|
-
try {
|
|
36003
|
-
json2 = JSON.parse(body);
|
|
36004
|
-
} catch {
|
|
36005
|
-
throw new RemoteResponseInvalid(route, "a body that is not JSON");
|
|
36006
|
-
}
|
|
36007
|
-
const result = schema.safeParse(json2);
|
|
36008
|
-
if (!result.success) {
|
|
36009
|
-
throw new RemoteResponseInvalid(route, "a body this client cannot read");
|
|
36010
|
-
}
|
|
36011
|
-
return result.data;
|
|
36012
|
-
}
|
|
36013
|
-
function resolveBaseUrl(endpoint) {
|
|
36014
|
-
if (!isSafeEndpoint(endpoint)) throw new RemoteEndpointRefused(endpoint);
|
|
36015
|
-
let end = endpoint.length;
|
|
36016
|
-
while (end > 0 && endpoint.charCodeAt(end - 1) === SLASH2) end -= 1;
|
|
36017
|
-
return endpoint.slice(0, end);
|
|
36018
|
-
}
|
|
36019
|
-
var SLASH2 = "/".charCodeAt(0);
|
|
36020
|
-
function createRemoteClient(options) {
|
|
36021
|
-
const base = resolveBaseUrl(options.endpoint);
|
|
36022
|
-
const url2 = (route) => `${base}${route}`;
|
|
36023
|
-
const common = { apiKey: options.apiKey, timeoutMs: options.timeoutMs };
|
|
36024
|
-
const sendOne = async (event) => {
|
|
36025
|
-
const validated = RecordAuditEventRequest.safeParse(event);
|
|
36026
|
-
if (!validated.success) throw new RemoteRequestInvalid(ROUTES.auditEvents, validated.error);
|
|
36027
|
-
const response = await send({
|
|
36028
|
-
...common,
|
|
36029
|
-
method: "POST",
|
|
36030
|
-
url: url2(ROUTES.auditEvents),
|
|
36031
|
-
body: JSON.stringify(validated.data)
|
|
36032
|
-
});
|
|
36033
|
-
okBody(response);
|
|
36034
|
-
};
|
|
36035
|
-
return {
|
|
36036
|
-
async ingestEvents(batch) {
|
|
36037
|
-
const response = await send({
|
|
36038
|
-
...common,
|
|
36039
|
-
method: "POST",
|
|
36040
|
-
url: url2(ROUTES.events),
|
|
36041
|
-
body: JSON.stringify(batch)
|
|
36042
|
-
});
|
|
36043
|
-
return parsed(IngestAck, okBody(response), ROUTES.events);
|
|
36044
|
-
},
|
|
36045
|
-
async ingestInventory(context) {
|
|
36046
|
-
const response = await send({
|
|
36047
|
-
...common,
|
|
36048
|
-
method: "POST",
|
|
36049
|
-
url: url2(ROUTES.inventory),
|
|
36050
|
-
body: JSON.stringify(context)
|
|
36051
|
-
});
|
|
36052
|
-
return parsed(ResolvedInventory, okBody(response), ROUTES.inventory);
|
|
36053
|
-
},
|
|
36054
|
-
async recordAuditEvent(event) {
|
|
36055
|
-
await sendOne(event);
|
|
36056
|
-
},
|
|
36057
|
-
async recordAuditEvents(events, opts) {
|
|
36058
|
-
const validated = RecordAuditEventBatch.safeParse({ events });
|
|
36059
|
-
if (!validated.success) {
|
|
36060
|
-
throw new RemoteRequestInvalid(ROUTES.auditEventsBatch, validated.error);
|
|
36061
|
-
}
|
|
36062
|
-
const response = await send({
|
|
36063
|
-
...common,
|
|
36064
|
-
method: "POST",
|
|
36065
|
-
url: url2(ROUTES.auditEventsBatch),
|
|
36066
|
-
body: JSON.stringify(validated.data)
|
|
36067
|
-
});
|
|
36068
|
-
if (response.status === 404) {
|
|
36069
|
-
if (opts?.fallbackToSingleEvents !== true) {
|
|
36070
|
-
throw new RemoteRouteAbsent(ROUTES.auditEventsBatch);
|
|
36071
|
-
}
|
|
36072
|
-
for (const event of validated.data.events) await sendOne(event);
|
|
36073
|
-
return { accepted: validated.data.events.length };
|
|
36074
|
-
}
|
|
36075
|
-
return parsed(AuditEventBatchAck, okBody(response), ROUTES.auditEventsBatch);
|
|
36076
|
-
},
|
|
36077
|
-
async reportStorePosture(snapshot) {
|
|
36078
|
-
const response = await send({
|
|
36079
|
-
...common,
|
|
36080
|
-
method: "POST",
|
|
36081
|
-
url: url2(ROUTES.storePosture),
|
|
36082
|
-
body: JSON.stringify(snapshot)
|
|
36083
|
-
});
|
|
36084
|
-
okBody(response);
|
|
36085
|
-
},
|
|
36086
|
-
async getPolicyBundle(etag) {
|
|
36087
|
-
const response = await send({
|
|
36088
|
-
...common,
|
|
36089
|
-
method: "GET",
|
|
36090
|
-
url: url2(ROUTES.policyBundle),
|
|
36091
|
-
...etag === void 0 ? {} : { headers: { "if-none-match": etag } }
|
|
36092
|
-
});
|
|
36093
|
-
if (response.status === 304) {
|
|
36094
|
-
return { changed: false, etag: headerValue(response, "etag") ?? etag };
|
|
36095
|
-
}
|
|
36096
|
-
const bundle = parsed(PolicyBundle, okBody(response), ROUTES.policyBundle);
|
|
36097
|
-
return { changed: true, bundle, etag: headerValue(response, "etag") };
|
|
36098
|
-
},
|
|
36099
|
-
async whoami() {
|
|
36100
|
-
const response = await send({ ...common, method: "GET", url: url2(ROUTES.whoami) });
|
|
36101
|
-
return parsed(PluginWhoami, okBody(response), ROUTES.whoami);
|
|
36102
|
-
},
|
|
36103
|
-
async recordProjectEgress(request) {
|
|
36104
|
-
const validated = EgressIngestRequest.safeParse(request);
|
|
36105
|
-
if (!validated.success) throw new RemoteRequestInvalid(ROUTES.shares, validated.error);
|
|
36106
|
-
const response = await send({
|
|
36107
|
-
...common,
|
|
36108
|
-
method: "POST",
|
|
36109
|
-
url: url2(ROUTES.shares),
|
|
36110
|
-
body: JSON.stringify(validated.data)
|
|
36111
|
-
});
|
|
36112
|
-
if (response.status === 404) throw new RemoteRouteAbsent(ROUTES.shares);
|
|
36113
|
-
okBody(response);
|
|
36114
|
-
},
|
|
36115
|
-
async pollCommand() {
|
|
36116
|
-
const response = await send({ ...common, method: "GET", url: url2(ROUTES.commands) });
|
|
36117
|
-
if (response.status === 404) return null;
|
|
36118
|
-
return parsed(DeviceCommandPollResponse, okBody(response), ROUTES.commands).command;
|
|
36119
|
-
},
|
|
36120
|
-
async ackCommand(id, body) {
|
|
36121
|
-
const validated = DeviceCommandAckBody.safeParse(body);
|
|
36122
|
-
const route = ackRoute(id);
|
|
36123
|
-
if (!validated.success) throw new RemoteRequestInvalid(route, validated.error);
|
|
36124
|
-
const response = await send({
|
|
36125
|
-
...common,
|
|
36126
|
-
method: "POST",
|
|
36127
|
-
url: url2(route),
|
|
36128
|
-
body: JSON.stringify(validated.data)
|
|
36129
|
-
});
|
|
36130
|
-
okBody(response);
|
|
36131
|
-
}
|
|
36132
|
-
};
|
|
36133
|
-
}
|
|
36134
|
-
|
|
36135
|
-
// ../../packages/remote/src/failure-kind.ts
|
|
36136
|
-
function statusOf(err) {
|
|
36137
|
-
if (typeof err !== "object" || err === null || !("status" in err)) return null;
|
|
36138
|
-
const { status } = err;
|
|
36139
|
-
if (typeof status !== "number" || !Number.isInteger(status)) return null;
|
|
36140
|
-
return status >= 100 && status <= 599 ? status : null;
|
|
36141
|
-
}
|
|
36142
|
-
function nameOf(err) {
|
|
36143
|
-
if (typeof err !== "object" || err === null || !("name" in err)) return null;
|
|
36144
|
-
return typeof err.name === "string" ? err.name : null;
|
|
36145
|
-
}
|
|
36146
|
-
function classifyRemoteFailure(err) {
|
|
36147
|
-
switch (nameOf(err)) {
|
|
36148
|
-
case "RemoteRouteAbsent":
|
|
36149
|
-
return "route-absent";
|
|
36150
|
-
case "RemoteRequestInvalid":
|
|
36151
|
-
case "RemoteEndpointRefused":
|
|
36152
|
-
return "invalid-request";
|
|
36153
|
-
case "RemoteResponseInvalid":
|
|
36154
|
-
return "rejected";
|
|
36155
|
-
default:
|
|
36156
|
-
break;
|
|
36157
|
-
}
|
|
36158
|
-
const status = statusOf(err);
|
|
36159
|
-
if (status === null) return "unreachable";
|
|
36160
|
-
switch (status) {
|
|
36161
|
-
case 401:
|
|
36162
|
-
return "unauthorized";
|
|
36163
|
-
case 403:
|
|
36164
|
-
return "forbidden";
|
|
36165
|
-
case 429:
|
|
36166
|
-
return "unreachable";
|
|
36167
|
-
case 404:
|
|
36168
|
-
return "unreachable";
|
|
36169
|
-
default:
|
|
36170
|
-
return status >= 400 && status <= 499 ? "rejected" : "unreachable";
|
|
36171
|
-
}
|
|
36172
|
-
}
|
|
36173
|
-
|
|
36174
|
-
// ../../packages/plugin-runtime/src/attached/failure.ts
|
|
36175
|
-
function classifyFailure(err) {
|
|
36176
|
-
switch (classifyRemoteFailure(err)) {
|
|
36177
|
-
case "unauthorized":
|
|
36178
|
-
return "unauthorized";
|
|
36179
|
-
case "forbidden":
|
|
36180
|
-
return "forbidden";
|
|
36181
|
-
default:
|
|
36182
|
-
return "unreachable";
|
|
36183
|
-
}
|
|
36184
|
-
}
|
|
36185
|
-
|
|
36186
|
-
// ../../packages/plugin-runtime/src/attached/with-timeout.ts
|
|
36187
|
-
var REQUEST_TIMEOUT_MS = 2e3;
|
|
36188
|
-
function withTimeout(promise2, ms) {
|
|
36189
|
-
let timer;
|
|
36190
|
-
const timeout = new Promise((_, reject) => {
|
|
36191
|
-
timer = setTimeout(() => {
|
|
36192
|
-
reject(new Error("attached gateway request timed out"));
|
|
36193
|
-
}, ms);
|
|
36194
|
-
});
|
|
36195
|
-
promise2.catch(() => void 0);
|
|
36196
|
-
return Promise.race([promise2, timeout]).finally(() => {
|
|
36197
|
-
clearTimeout(timer);
|
|
36198
|
-
});
|
|
36199
|
-
}
|
|
36200
|
-
|
|
36201
|
-
// ../../packages/plugin-runtime/src/attached/forward-drops.ts
|
|
36202
|
-
import { readFileSync as readFileSync10 } from "fs";
|
|
36203
|
-
import { join as join16 } from "path";
|
|
36204
|
-
var FORWARD_DROPS_FILENAME = ATTACHED_FORWARD_DROPS_FILENAME;
|
|
36205
|
-
function forwardDropsPath(dataDir2) {
|
|
36206
|
-
return join16(dataDir2, FORWARD_DROPS_FILENAME);
|
|
36207
|
-
}
|
|
36208
|
-
function recordForwardDrops(dataDir2, count, nowMs) {
|
|
36209
|
-
if (count <= 0) return;
|
|
36210
|
-
try {
|
|
36211
|
-
ensureDataDirSync(dataDir2);
|
|
36212
|
-
const previous = readForwardDrops(dataDir2);
|
|
36213
|
-
const next = {
|
|
36214
|
-
droppedForwards: (previous?.droppedForwards ?? 0) + count,
|
|
36215
|
-
lastDropAtMs: nowMs
|
|
36216
|
-
};
|
|
36217
|
-
writeOwnerOnlyFileSync(forwardDropsPath(dataDir2), `${JSON.stringify(next)}
|
|
36218
|
-
`);
|
|
36219
|
-
} catch {
|
|
36220
|
-
}
|
|
36221
|
-
}
|
|
36222
|
-
function readForwardDrops(dataDir2) {
|
|
36223
|
-
try {
|
|
36224
|
-
const parsed2 = JSON.parse(readFileSync10(forwardDropsPath(dataDir2), "utf8"));
|
|
36225
|
-
if (typeof parsed2 !== "object" || parsed2 === null) return null;
|
|
36226
|
-
const record2 = parsed2;
|
|
36227
|
-
if (typeof record2.droppedForwards !== "number" || !Number.isFinite(record2.droppedForwards)) {
|
|
36228
|
-
return null;
|
|
36229
|
-
}
|
|
36230
|
-
if (record2.droppedForwards <= 0) return null;
|
|
36231
|
-
if (typeof record2.lastDropAtMs !== "number" || !Number.isFinite(record2.lastDropAtMs)) {
|
|
36232
|
-
return null;
|
|
36233
|
-
}
|
|
36234
|
-
return { droppedForwards: record2.droppedForwards, lastDropAtMs: record2.lastDropAtMs };
|
|
36235
|
-
} catch {
|
|
36236
|
-
return null;
|
|
36237
|
-
}
|
|
36238
|
-
}
|
|
36239
|
-
|
|
36240
|
-
// ../../packages/plugin-runtime/src/attached/forward-policy.ts
|
|
36241
|
-
import { randomUUID as randomUUID16 } from "crypto";
|
|
36242
|
-
import { readFile, rename, writeFile } from "fs/promises";
|
|
36243
|
-
import { join as join28 } from "path";
|
|
36244
|
-
|
|
36245
35325
|
// ../../packages/plugin-sdk/src/config.ts
|
|
36246
35326
|
import { existsSync as existsSync8 } from "fs";
|
|
36247
35327
|
import { join as join17 } from "path";
|
|
@@ -36321,11 +35401,6 @@ function resolveProviderSafe(resolveProviderFn) {
|
|
|
36321
35401
|
}
|
|
36322
35402
|
}
|
|
36323
35403
|
|
|
36324
|
-
// ../../packages/plugin-sdk/src/config-inventory.ts
|
|
36325
|
-
import { readdirSync as readdirSync2, readFileSync as readFileSync12, realpathSync as realpathSync2, statSync as statSync7 } from "fs";
|
|
36326
|
-
import { homedir as homedir2 } from "os";
|
|
36327
|
-
import { basename as basename3, join as join19 } from "path";
|
|
36328
|
-
|
|
36329
35404
|
// ../../packages/detections/src/egress/registry.ts
|
|
36330
35405
|
var EXTRACTOR_VERSION = "3";
|
|
36331
35406
|
var PROVIDER_REGISTRY = [
|
|
@@ -37000,12 +36075,12 @@ var RegexMatcher2 = class {
|
|
|
37000
36075
|
rule.matcher,
|
|
37001
36076
|
() => new RegExp(pattern, flags.includes("d") ? flags : `${flags}d`)
|
|
37002
36077
|
);
|
|
37003
|
-
const
|
|
36078
|
+
const scanText = text.length > MAX_REGEX_INPUT_LENGTH ? text.slice(0, MAX_REGEX_INPUT_LENGTH) : text;
|
|
37004
36079
|
const spans = [];
|
|
37005
36080
|
let m;
|
|
37006
|
-
const maxIterations =
|
|
36081
|
+
const maxIterations = scanText.length + 1;
|
|
37007
36082
|
let iterations = 0;
|
|
37008
|
-
while ((m = re.exec(
|
|
36083
|
+
while ((m = re.exec(scanText)) !== null) {
|
|
37009
36084
|
if (++iterations > maxIterations) break;
|
|
37010
36085
|
const group = captureGroup != null ? m[captureGroup] : m[0];
|
|
37011
36086
|
if (m[0].length === 0) re.lastIndex++;
|
|
@@ -39366,141 +38441,441 @@ function bundledDetections() {
|
|
|
39366
38441
|
}));
|
|
39367
38442
|
return cachedDetections;
|
|
39368
38443
|
}
|
|
39369
|
-
|
|
39370
|
-
|
|
39371
|
-
|
|
39372
|
-
|
|
39373
|
-
|
|
39374
|
-
|
|
39375
|
-
// ../../packages/plugin-sdk/src/events.ts
|
|
39376
|
-
import { createHash as createHash5, randomUUID as randomUUID13 } from "crypto";
|
|
39377
|
-
|
|
39378
|
-
// ../../packages/plugin-sdk/src/isolated-scan.ts
|
|
39379
|
-
import { existsSync as existsSync10 } from "fs";
|
|
39380
|
-
import { fileURLToPath } from "url";
|
|
39381
|
-
import { Worker } from "worker_threads";
|
|
39382
|
-
|
|
39383
|
-
// ../../packages/plugin-sdk/src/hook-fail-opens.ts
|
|
39384
|
-
import { readFileSync as readFileSync13 } from "fs";
|
|
39385
|
-
import { join as join20 } from "path";
|
|
39386
|
-
|
|
39387
|
-
// ../../packages/plugin-sdk/src/host-floor.ts
|
|
39388
|
-
import { readFileSync as readFileSync15 } from "fs";
|
|
39389
|
-
import { join as join22 } from "path";
|
|
39390
|
-
|
|
39391
|
-
// ../../packages/plugin-sdk/src/model-governance.ts
|
|
39392
|
-
import {
|
|
39393
|
-
closeSync as closeSync2,
|
|
39394
|
-
fstatSync,
|
|
39395
|
-
mkdirSync as mkdirSync2,
|
|
39396
|
-
openSync as openSync2,
|
|
39397
|
-
readFileSync as readFileSync14,
|
|
39398
|
-
readSync,
|
|
39399
|
-
writeFileSync as writeFileSync5
|
|
39400
|
-
} from "fs";
|
|
39401
|
-
import { join as join21 } from "path";
|
|
39402
|
-
var TAIL_BYTES = 256 * 1024;
|
|
39403
|
-
|
|
39404
|
-
// ../../packages/plugin-sdk/src/host-floor.ts
|
|
39405
|
-
var HOST_FEATURE = {
|
|
39406
|
-
ModelSwitch: "model-switch",
|
|
39407
|
-
VaultPointerDisplay: "vault-pointer-display"
|
|
39408
|
-
};
|
|
39409
|
-
var HOST_FLOORS = {
|
|
39410
|
-
[HOST_FEATURE.ModelSwitch]: {
|
|
39411
|
-
label: "model-switch protection",
|
|
39412
|
-
hookEvents: ["PreModelSwitch", "PostModelSwitch"],
|
|
39413
|
-
since: "2.1.251"
|
|
39414
|
-
},
|
|
39415
|
-
[HOST_FEATURE.VaultPointerDisplay]: {
|
|
39416
|
-
label: "vault pointer display",
|
|
39417
|
-
hookEvents: ["MessageDisplay"],
|
|
39418
|
-
since: "2.1.152"
|
|
39419
|
-
}
|
|
39420
|
-
};
|
|
39421
|
-
var ANTIGRAVITY_HOST_FEATURE = {
|
|
39422
|
-
EndOfTurnCapture: "end-of-turn-capture"
|
|
39423
|
-
};
|
|
39424
|
-
var ANTIGRAVITY_HOST_FLOORS = {
|
|
39425
|
-
[ANTIGRAVITY_HOST_FEATURE.EndOfTurnCapture]: {
|
|
39426
|
-
label: "end-of-turn history capture",
|
|
39427
|
-
hookEvents: ["Stop"],
|
|
39428
|
-
since: "1.1.10"
|
|
39429
|
-
}
|
|
39430
|
-
};
|
|
39431
|
-
|
|
39432
|
-
// ../../packages/plugin-sdk/src/ignore-layers.ts
|
|
39433
|
-
var import_ignore = __toESM(require_ignore(), 1);
|
|
39434
|
-
import { readFileSync as readFileSync16 } from "fs";
|
|
39435
|
-
import { join as join23 } from "path";
|
|
39436
|
-
|
|
39437
|
-
// ../../packages/plugin-sdk/src/inventory-resolver.ts
|
|
39438
|
-
import { arch, hostname as hostname4, platform, release } from "os";
|
|
39439
|
-
|
|
39440
|
-
// ../../packages/plugin-sdk/src/nudge.ts
|
|
39441
|
-
import { mkdirSync as mkdirSync3, readFileSync as readFileSync17, writeFileSync as writeFileSync6 } from "fs";
|
|
39442
|
-
import { join as join24 } from "path";
|
|
39443
|
-
|
|
39444
|
-
// ../../packages/plugin-sdk/src/paths.ts
|
|
39445
|
-
import { readdirSync as readdirSync3, realpathSync as realpathSync3 } from "fs";
|
|
39446
|
-
import { basename as basename4, dirname as dirname5, sep as sep3 } from "path";
|
|
38444
|
+
function shippedRegexMatchers() {
|
|
38445
|
+
return bundledDetections().flatMap((pack) => pack.rules).flatMap(
|
|
38446
|
+
(rule) => rule.matcher.type === "regex" ? [{ pattern: rule.matcher.pattern, flags: rule.matcher.flags }] : []
|
|
38447
|
+
);
|
|
38448
|
+
}
|
|
39447
38449
|
|
|
39448
38450
|
// ../../packages/plugin-sdk/src/policy-resolver.ts
|
|
39449
|
-
import { randomUUID as
|
|
38451
|
+
import { randomUUID as randomUUID13 } from "crypto";
|
|
39450
38452
|
function assignedRulePolicies(installed) {
|
|
39451
38453
|
const out = [];
|
|
39452
38454
|
for (const [ruleId, action] of installed.ruleActions) {
|
|
39453
38455
|
if (installed.assignedRules && !installed.assignedRules.has(ruleId)) continue;
|
|
39454
|
-
out.push({ id:
|
|
38456
|
+
out.push({ id: randomUUID13(), scope: "global", target: { ruleId }, action, enabled: true });
|
|
39455
38457
|
}
|
|
39456
38458
|
return out;
|
|
39457
38459
|
}
|
|
39458
38460
|
|
|
39459
|
-
// ../../packages/
|
|
39460
|
-
import {
|
|
39461
|
-
import {
|
|
38461
|
+
// ../../packages/remote/src/http.ts
|
|
38462
|
+
import { request as httpRequest } from "http";
|
|
38463
|
+
import { request as httpsRequest } from "https";
|
|
38464
|
+
var DEFAULT_TIMEOUT_MS = 1e4;
|
|
38465
|
+
var MAX_RESPONSE_BYTES = 8 * 1024 * 1024;
|
|
38466
|
+
var RemoteRequestError = class extends Error {
|
|
38467
|
+
constructor(status) {
|
|
38468
|
+
super(`control-plane request failed with status ${String(status)}`);
|
|
38469
|
+
this.status = status;
|
|
38470
|
+
this.name = "RemoteRequestError";
|
|
38471
|
+
}
|
|
38472
|
+
status;
|
|
38473
|
+
};
|
|
38474
|
+
var RemoteRouteAbsent = class extends Error {
|
|
38475
|
+
constructor(route) {
|
|
38476
|
+
super(`control plane does not serve ${route}`);
|
|
38477
|
+
this.route = route;
|
|
38478
|
+
this.name = "RemoteRouteAbsent";
|
|
38479
|
+
}
|
|
38480
|
+
route;
|
|
38481
|
+
};
|
|
38482
|
+
var RemoteRequestInvalid = class extends Error {
|
|
38483
|
+
constructor(route, cause) {
|
|
38484
|
+
super(`refusing to send a malformed body to ${route}`);
|
|
38485
|
+
this.cause = cause;
|
|
38486
|
+
this.name = "RemoteRequestInvalid";
|
|
38487
|
+
}
|
|
38488
|
+
cause;
|
|
38489
|
+
};
|
|
38490
|
+
var RemoteEndpointRefused = class extends Error {
|
|
38491
|
+
constructor(endpoint) {
|
|
38492
|
+
super(`refusing to talk to an unsafe control-plane endpoint: ${originOnly(endpoint)}`);
|
|
38493
|
+
this.name = "RemoteEndpointRefused";
|
|
38494
|
+
}
|
|
38495
|
+
};
|
|
38496
|
+
var RemoteResponseInvalid = class extends Error {
|
|
38497
|
+
constructor(route, detail) {
|
|
38498
|
+
super(`control plane answered ${route} with ${detail}`);
|
|
38499
|
+
this.name = "RemoteResponseInvalid";
|
|
38500
|
+
}
|
|
38501
|
+
};
|
|
38502
|
+
var RemoteTransportError = class extends Error {
|
|
38503
|
+
/**
|
|
38504
|
+
* The status the peer sent, when headers arrived and only the BODY was
|
|
38505
|
+
* refused.
|
|
38506
|
+
*
|
|
38507
|
+
* Undefined for the ordinary case this class was written for — no answer at
|
|
38508
|
+
* all. It exists because two paths reject after a status has already been
|
|
38509
|
+
* delivered: an oversized body and an aborted response. Discarding it there
|
|
38510
|
+
* reported a deployment answering 401 with a verbose body as a network
|
|
38511
|
+
* outage, which sends the reader to look at their network instead of their
|
|
38512
|
+
* credential.
|
|
38513
|
+
*/
|
|
38514
|
+
constructor(reason, status) {
|
|
38515
|
+
super(`control-plane request did not complete: ${reason}`);
|
|
38516
|
+
this.status = status;
|
|
38517
|
+
this.name = "RemoteTransportError";
|
|
38518
|
+
}
|
|
38519
|
+
status;
|
|
38520
|
+
};
|
|
38521
|
+
async function send(options) {
|
|
38522
|
+
const url2 = new URL(options.url);
|
|
38523
|
+
const timeoutMs = options.timeoutMs ?? DEFAULT_TIMEOUT_MS;
|
|
38524
|
+
const send_ = url2.protocol === "http:" ? httpRequest : httpsRequest;
|
|
38525
|
+
const requestOptions = {
|
|
38526
|
+
method: options.method,
|
|
38527
|
+
headers: {
|
|
38528
|
+
// CALLER HEADERS FIRST, so this module's own are not overridable. Spread
|
|
38529
|
+
// last they win, and two of the values below are ones no caller may
|
|
38530
|
+
// replace: `x-api-key` is the credential, and `content-length` is the
|
|
38531
|
+
// byte count that stops a multi-byte body being truncated by the
|
|
38532
|
+
// receiver. `SendOptions.headers` is a free-form record on an exported
|
|
38533
|
+
// function, so "no caller does that today" is not the guarantee to rely
|
|
38534
|
+
// on. The one header any caller actually passes — `if-none-match` on the
|
|
38535
|
+
// conditional GET — is untouched by this order.
|
|
38536
|
+
...options.headers,
|
|
38537
|
+
// The credential. One header, matching what the deployment authenticates
|
|
38538
|
+
// on; a second copy in an `Authorization` header would be one more place
|
|
38539
|
+
// it can be logged by an intermediary for no gain.
|
|
38540
|
+
//
|
|
38541
|
+
// Spread conditionally rather than assigned as `undefined`: Node's header
|
|
38542
|
+
// handling and `content-length` bookkeeping treat a present-but-undefined
|
|
38543
|
+
// key differently from an absent one, and "the header is not there" is
|
|
38544
|
+
// the property the attach flow needs.
|
|
38545
|
+
...options.apiKey === void 0 ? {} : { "x-api-key": options.apiKey },
|
|
38546
|
+
accept: "application/json",
|
|
38547
|
+
...options.body === void 0 ? {} : {
|
|
38548
|
+
"content-type": "application/json",
|
|
38549
|
+
// Byte length, not string length: a multi-byte body sent with a
|
|
38550
|
+
// character count is truncated by the receiver.
|
|
38551
|
+
"content-length": String(Buffer.byteLength(options.body))
|
|
38552
|
+
}
|
|
38553
|
+
}
|
|
38554
|
+
};
|
|
38555
|
+
return new Promise((resolve3, reject) => {
|
|
38556
|
+
let settled = false;
|
|
38557
|
+
const fail = (reason, status) => {
|
|
38558
|
+
if (settled) return;
|
|
38559
|
+
settled = true;
|
|
38560
|
+
reject(new RemoteTransportError(reason, status));
|
|
38561
|
+
};
|
|
38562
|
+
const req = send_(url2, requestOptions, (res) => {
|
|
38563
|
+
const chunks = [];
|
|
38564
|
+
let size = 0;
|
|
38565
|
+
res.on("data", (chunk) => {
|
|
38566
|
+
size += chunk.length;
|
|
38567
|
+
if (size > MAX_RESPONSE_BYTES) {
|
|
38568
|
+
fail(`response exceeded ${String(MAX_RESPONSE_BYTES)} bytes`, res.statusCode);
|
|
38569
|
+
res.destroy();
|
|
38570
|
+
req.destroy();
|
|
38571
|
+
return;
|
|
38572
|
+
}
|
|
38573
|
+
chunks.push(chunk);
|
|
38574
|
+
});
|
|
38575
|
+
res.on("aborted", () => {
|
|
38576
|
+
fail("the response was aborted", res.statusCode);
|
|
38577
|
+
});
|
|
38578
|
+
res.on("end", () => {
|
|
38579
|
+
if (settled) return;
|
|
38580
|
+
settled = true;
|
|
38581
|
+
resolve3({
|
|
38582
|
+
status: res.statusCode ?? 0,
|
|
38583
|
+
headers: res.headers,
|
|
38584
|
+
body: Buffer.concat(chunks).toString("utf8")
|
|
38585
|
+
});
|
|
38586
|
+
});
|
|
38587
|
+
});
|
|
38588
|
+
const deadline = setTimeout(() => {
|
|
38589
|
+
fail(`no response within ${String(timeoutMs)}ms`);
|
|
38590
|
+
req.destroy();
|
|
38591
|
+
}, timeoutMs);
|
|
38592
|
+
deadline.unref();
|
|
38593
|
+
req.on("upgrade", (_res, socket) => {
|
|
38594
|
+
fail("the deployment answered with a protocol upgrade");
|
|
38595
|
+
socket.destroy();
|
|
38596
|
+
});
|
|
38597
|
+
req.on("close", () => {
|
|
38598
|
+
fail("the connection closed before a response was read");
|
|
38599
|
+
clearTimeout(deadline);
|
|
38600
|
+
});
|
|
38601
|
+
req.on("error", (err) => {
|
|
38602
|
+
fail(err.message);
|
|
38603
|
+
});
|
|
38604
|
+
if (options.body !== void 0) req.write(options.body);
|
|
38605
|
+
req.end();
|
|
38606
|
+
});
|
|
38607
|
+
}
|
|
39462
38608
|
|
|
39463
|
-
// ../../packages/
|
|
39464
|
-
var
|
|
39465
|
-
|
|
39466
|
-
|
|
39467
|
-
|
|
39468
|
-
|
|
39469
|
-
|
|
39470
|
-
|
|
39471
|
-
|
|
39472
|
-
|
|
39473
|
-
|
|
39474
|
-
GOOGLE_GENAI_USE_VERTEXAI: optionalFlag,
|
|
39475
|
-
GOOGLE_GEMINI_BASE_URL: optionalBaseUrl2
|
|
39476
|
-
};
|
|
39477
|
-
var AntigravityProviderEnvSchema = external_exports.object(antigravityProviderEnvShape);
|
|
39478
|
-
|
|
39479
|
-
// ../../packages/plugin-sdk/src/provider-env-codex.ts
|
|
39480
|
-
var optionalBaseUrl3 = external_exports.preprocess((v) => {
|
|
39481
|
-
if (typeof v === "string" && v.trim() === "") return void 0;
|
|
39482
|
-
return v;
|
|
39483
|
-
}, external_exports.string().optional()).catch(void 0);
|
|
39484
|
-
var codexProviderEnvShape = {
|
|
39485
|
-
OPENAI_BASE_URL: optionalBaseUrl3
|
|
38609
|
+
// ../../packages/remote/src/client.ts
|
|
38610
|
+
var ROUTES = {
|
|
38611
|
+
events: "/v1/events",
|
|
38612
|
+
auditEvents: "/v1/audit-events",
|
|
38613
|
+
auditEventsBatch: "/v1/audit-events/batch",
|
|
38614
|
+
inventory: "/v1/inventory",
|
|
38615
|
+
storePosture: "/v1/store-posture",
|
|
38616
|
+
policyBundle: "/v1/policy-bundle",
|
|
38617
|
+
whoami: "/v1/plugin/whoami",
|
|
38618
|
+
shares: "/v1/shares",
|
|
38619
|
+
commands: "/v1/plugin/commands"
|
|
39486
38620
|
};
|
|
39487
|
-
|
|
38621
|
+
function ackRoute(id) {
|
|
38622
|
+
return `${ROUTES.commands}/${encodeURIComponent(id)}/ack`;
|
|
38623
|
+
}
|
|
38624
|
+
function headerValue(response, name) {
|
|
38625
|
+
const raw = response.headers[name];
|
|
38626
|
+
if (raw === void 0) return void 0;
|
|
38627
|
+
return Array.isArray(raw) ? raw[0] : raw;
|
|
38628
|
+
}
|
|
38629
|
+
function okBody(response) {
|
|
38630
|
+
if (response.status < 200 || response.status >= 300) {
|
|
38631
|
+
throw new RemoteRequestError(response.status);
|
|
38632
|
+
}
|
|
38633
|
+
return response.body;
|
|
38634
|
+
}
|
|
38635
|
+
function parsed(schema, body, route) {
|
|
38636
|
+
let json2;
|
|
38637
|
+
try {
|
|
38638
|
+
json2 = JSON.parse(body);
|
|
38639
|
+
} catch {
|
|
38640
|
+
throw new RemoteResponseInvalid(route, "a body that is not JSON");
|
|
38641
|
+
}
|
|
38642
|
+
const result = schema.safeParse(json2);
|
|
38643
|
+
if (!result.success) {
|
|
38644
|
+
throw new RemoteResponseInvalid(route, "a body this client cannot read");
|
|
38645
|
+
}
|
|
38646
|
+
return result.data;
|
|
38647
|
+
}
|
|
38648
|
+
function resolveBaseUrl(endpoint) {
|
|
38649
|
+
if (!isSafeEndpoint(endpoint)) throw new RemoteEndpointRefused(endpoint);
|
|
38650
|
+
let end = endpoint.length;
|
|
38651
|
+
while (end > 0 && endpoint.charCodeAt(end - 1) === SLASH2) end -= 1;
|
|
38652
|
+
return endpoint.slice(0, end);
|
|
38653
|
+
}
|
|
38654
|
+
var SLASH2 = "/".charCodeAt(0);
|
|
38655
|
+
function createRemoteClient(options) {
|
|
38656
|
+
const base = resolveBaseUrl(options.endpoint);
|
|
38657
|
+
const url2 = (route) => `${base}${route}`;
|
|
38658
|
+
const common = { apiKey: options.apiKey, timeoutMs: options.timeoutMs };
|
|
38659
|
+
const sendOne = async (event) => {
|
|
38660
|
+
const validated = RecordAuditEventRequest.safeParse(event);
|
|
38661
|
+
if (!validated.success) throw new RemoteRequestInvalid(ROUTES.auditEvents, validated.error);
|
|
38662
|
+
const response = await send({
|
|
38663
|
+
...common,
|
|
38664
|
+
method: "POST",
|
|
38665
|
+
url: url2(ROUTES.auditEvents),
|
|
38666
|
+
body: JSON.stringify(validated.data)
|
|
38667
|
+
});
|
|
38668
|
+
okBody(response);
|
|
38669
|
+
};
|
|
38670
|
+
return {
|
|
38671
|
+
async ingestEvents(batch) {
|
|
38672
|
+
const response = await send({
|
|
38673
|
+
...common,
|
|
38674
|
+
method: "POST",
|
|
38675
|
+
url: url2(ROUTES.events),
|
|
38676
|
+
body: JSON.stringify(batch)
|
|
38677
|
+
});
|
|
38678
|
+
return parsed(IngestAck, okBody(response), ROUTES.events);
|
|
38679
|
+
},
|
|
38680
|
+
async ingestInventory(context) {
|
|
38681
|
+
const response = await send({
|
|
38682
|
+
...common,
|
|
38683
|
+
method: "POST",
|
|
38684
|
+
url: url2(ROUTES.inventory),
|
|
38685
|
+
body: JSON.stringify(context)
|
|
38686
|
+
});
|
|
38687
|
+
return parsed(ResolvedInventory, okBody(response), ROUTES.inventory);
|
|
38688
|
+
},
|
|
38689
|
+
async recordAuditEvent(event) {
|
|
38690
|
+
await sendOne(event);
|
|
38691
|
+
},
|
|
38692
|
+
async recordAuditEvents(events, opts) {
|
|
38693
|
+
const validated = RecordAuditEventBatch.safeParse({ events });
|
|
38694
|
+
if (!validated.success) {
|
|
38695
|
+
throw new RemoteRequestInvalid(ROUTES.auditEventsBatch, validated.error);
|
|
38696
|
+
}
|
|
38697
|
+
const response = await send({
|
|
38698
|
+
...common,
|
|
38699
|
+
method: "POST",
|
|
38700
|
+
url: url2(ROUTES.auditEventsBatch),
|
|
38701
|
+
body: JSON.stringify(validated.data)
|
|
38702
|
+
});
|
|
38703
|
+
if (response.status === 404) {
|
|
38704
|
+
if (opts?.fallbackToSingleEvents !== true) {
|
|
38705
|
+
throw new RemoteRouteAbsent(ROUTES.auditEventsBatch);
|
|
38706
|
+
}
|
|
38707
|
+
for (const event of validated.data.events) await sendOne(event);
|
|
38708
|
+
return { accepted: validated.data.events.length };
|
|
38709
|
+
}
|
|
38710
|
+
return parsed(AuditEventBatchAck, okBody(response), ROUTES.auditEventsBatch);
|
|
38711
|
+
},
|
|
38712
|
+
async reportStorePosture(snapshot) {
|
|
38713
|
+
const response = await send({
|
|
38714
|
+
...common,
|
|
38715
|
+
method: "POST",
|
|
38716
|
+
url: url2(ROUTES.storePosture),
|
|
38717
|
+
body: JSON.stringify(snapshot)
|
|
38718
|
+
});
|
|
38719
|
+
okBody(response);
|
|
38720
|
+
},
|
|
38721
|
+
async getPolicyBundle(etag) {
|
|
38722
|
+
const response = await send({
|
|
38723
|
+
...common,
|
|
38724
|
+
method: "GET",
|
|
38725
|
+
url: url2(ROUTES.policyBundle),
|
|
38726
|
+
...etag === void 0 ? {} : { headers: { "if-none-match": etag } }
|
|
38727
|
+
});
|
|
38728
|
+
if (response.status === 304) {
|
|
38729
|
+
return { changed: false, etag: headerValue(response, "etag") ?? etag };
|
|
38730
|
+
}
|
|
38731
|
+
const bundle = parsed(PolicyBundle, okBody(response), ROUTES.policyBundle);
|
|
38732
|
+
return { changed: true, bundle, etag: headerValue(response, "etag") };
|
|
38733
|
+
},
|
|
38734
|
+
async whoami() {
|
|
38735
|
+
const response = await send({ ...common, method: "GET", url: url2(ROUTES.whoami) });
|
|
38736
|
+
return parsed(PluginWhoami, okBody(response), ROUTES.whoami);
|
|
38737
|
+
},
|
|
38738
|
+
async recordProjectEgress(request) {
|
|
38739
|
+
const validated = EgressIngestRequest.safeParse(request);
|
|
38740
|
+
if (!validated.success) throw new RemoteRequestInvalid(ROUTES.shares, validated.error);
|
|
38741
|
+
const response = await send({
|
|
38742
|
+
...common,
|
|
38743
|
+
method: "POST",
|
|
38744
|
+
url: url2(ROUTES.shares),
|
|
38745
|
+
body: JSON.stringify(validated.data)
|
|
38746
|
+
});
|
|
38747
|
+
if (response.status === 404) throw new RemoteRouteAbsent(ROUTES.shares);
|
|
38748
|
+
okBody(response);
|
|
38749
|
+
},
|
|
38750
|
+
async pollCommand() {
|
|
38751
|
+
const response = await send({ ...common, method: "GET", url: url2(ROUTES.commands) });
|
|
38752
|
+
if (response.status === 404) return null;
|
|
38753
|
+
return parsed(DeviceCommandPollResponse, okBody(response), ROUTES.commands).command;
|
|
38754
|
+
},
|
|
38755
|
+
async ackCommand(id, body) {
|
|
38756
|
+
const validated = DeviceCommandAckBody.safeParse(body);
|
|
38757
|
+
const route = ackRoute(id);
|
|
38758
|
+
if (!validated.success) throw new RemoteRequestInvalid(route, validated.error);
|
|
38759
|
+
const response = await send({
|
|
38760
|
+
...common,
|
|
38761
|
+
method: "POST",
|
|
38762
|
+
url: url2(route),
|
|
38763
|
+
body: JSON.stringify(validated.data)
|
|
38764
|
+
});
|
|
38765
|
+
okBody(response);
|
|
38766
|
+
}
|
|
38767
|
+
};
|
|
38768
|
+
}
|
|
39488
38769
|
|
|
39489
|
-
// ../../packages/
|
|
39490
|
-
|
|
38770
|
+
// ../../packages/remote/src/failure-kind.ts
|
|
38771
|
+
function statusOf(err) {
|
|
38772
|
+
if (typeof err !== "object" || err === null || !("status" in err)) return null;
|
|
38773
|
+
const { status } = err;
|
|
38774
|
+
if (typeof status !== "number" || !Number.isInteger(status)) return null;
|
|
38775
|
+
return status >= 100 && status <= 599 ? status : null;
|
|
38776
|
+
}
|
|
38777
|
+
function nameOf(err) {
|
|
38778
|
+
if (typeof err !== "object" || err === null || !("name" in err)) return null;
|
|
38779
|
+
return typeof err.name === "string" ? err.name : null;
|
|
38780
|
+
}
|
|
38781
|
+
function classifyRemoteFailure(err) {
|
|
38782
|
+
switch (nameOf(err)) {
|
|
38783
|
+
case "RemoteRouteAbsent":
|
|
38784
|
+
return "route-absent";
|
|
38785
|
+
case "RemoteRequestInvalid":
|
|
38786
|
+
case "RemoteEndpointRefused":
|
|
38787
|
+
return "invalid-request";
|
|
38788
|
+
case "RemoteResponseInvalid":
|
|
38789
|
+
return "rejected";
|
|
38790
|
+
default:
|
|
38791
|
+
break;
|
|
38792
|
+
}
|
|
38793
|
+
const status = statusOf(err);
|
|
38794
|
+
if (status === null) return "unreachable";
|
|
38795
|
+
switch (status) {
|
|
38796
|
+
case 401:
|
|
38797
|
+
return "unauthorized";
|
|
38798
|
+
case 403:
|
|
38799
|
+
return "forbidden";
|
|
38800
|
+
case 429:
|
|
38801
|
+
return "unreachable";
|
|
38802
|
+
case 404:
|
|
38803
|
+
return "unreachable";
|
|
38804
|
+
default:
|
|
38805
|
+
return status >= 400 && status <= 499 ? "rejected" : "unreachable";
|
|
38806
|
+
}
|
|
38807
|
+
}
|
|
39491
38808
|
|
|
39492
|
-
// ../../packages/plugin-
|
|
39493
|
-
|
|
39494
|
-
|
|
38809
|
+
// ../../packages/plugin-runtime/src/attached/failure.ts
|
|
38810
|
+
function classifyFailure(err) {
|
|
38811
|
+
switch (classifyRemoteFailure(err)) {
|
|
38812
|
+
case "unauthorized":
|
|
38813
|
+
return "unauthorized";
|
|
38814
|
+
case "forbidden":
|
|
38815
|
+
return "forbidden";
|
|
38816
|
+
default:
|
|
38817
|
+
return "unreachable";
|
|
38818
|
+
}
|
|
38819
|
+
}
|
|
39495
38820
|
|
|
39496
|
-
// ../../packages/plugin-
|
|
39497
|
-
var
|
|
38821
|
+
// ../../packages/plugin-runtime/src/attached/with-timeout.ts
|
|
38822
|
+
var REQUEST_TIMEOUT_MS = 2e3;
|
|
38823
|
+
function withTimeout(promise2, ms) {
|
|
38824
|
+
let timer;
|
|
38825
|
+
const timeout = new Promise((_, reject) => {
|
|
38826
|
+
timer = setTimeout(() => {
|
|
38827
|
+
reject(new Error("attached gateway request timed out"));
|
|
38828
|
+
}, ms);
|
|
38829
|
+
});
|
|
38830
|
+
promise2.catch(() => void 0);
|
|
38831
|
+
return Promise.race([promise2, timeout]).finally(() => {
|
|
38832
|
+
clearTimeout(timer);
|
|
38833
|
+
});
|
|
38834
|
+
}
|
|
39498
38835
|
|
|
39499
|
-
// ../../packages/plugin-
|
|
39500
|
-
import {
|
|
39501
|
-
import { join as
|
|
38836
|
+
// ../../packages/plugin-runtime/src/attached/forward-drops.ts
|
|
38837
|
+
import { readFileSync as readFileSync11 } from "fs";
|
|
38838
|
+
import { join as join18 } from "path";
|
|
38839
|
+
var FORWARD_DROPS_FILENAME = ATTACHED_FORWARD_DROPS_FILENAME;
|
|
38840
|
+
function forwardDropsPath(dataDir2) {
|
|
38841
|
+
return join18(dataDir2, FORWARD_DROPS_FILENAME);
|
|
38842
|
+
}
|
|
38843
|
+
function recordForwardDrops(dataDir2, count, nowMs) {
|
|
38844
|
+
if (count <= 0) return;
|
|
38845
|
+
try {
|
|
38846
|
+
ensureDataDirSync(dataDir2);
|
|
38847
|
+
const previous = readForwardDrops(dataDir2);
|
|
38848
|
+
const next = {
|
|
38849
|
+
droppedForwards: (previous?.droppedForwards ?? 0) + count,
|
|
38850
|
+
lastDropAtMs: nowMs
|
|
38851
|
+
};
|
|
38852
|
+
writeOwnerOnlyFileSync(forwardDropsPath(dataDir2), `${JSON.stringify(next)}
|
|
38853
|
+
`);
|
|
38854
|
+
} catch {
|
|
38855
|
+
}
|
|
38856
|
+
}
|
|
38857
|
+
function readForwardDrops(dataDir2) {
|
|
38858
|
+
try {
|
|
38859
|
+
const parsed2 = JSON.parse(readFileSync11(forwardDropsPath(dataDir2), "utf8"));
|
|
38860
|
+
if (typeof parsed2 !== "object" || parsed2 === null) return null;
|
|
38861
|
+
const record2 = parsed2;
|
|
38862
|
+
if (typeof record2.droppedForwards !== "number" || !Number.isFinite(record2.droppedForwards)) {
|
|
38863
|
+
return null;
|
|
38864
|
+
}
|
|
38865
|
+
if (record2.droppedForwards <= 0) return null;
|
|
38866
|
+
if (typeof record2.lastDropAtMs !== "number" || !Number.isFinite(record2.lastDropAtMs)) {
|
|
38867
|
+
return null;
|
|
38868
|
+
}
|
|
38869
|
+
return { droppedForwards: record2.droppedForwards, lastDropAtMs: record2.lastDropAtMs };
|
|
38870
|
+
} catch {
|
|
38871
|
+
return null;
|
|
38872
|
+
}
|
|
38873
|
+
}
|
|
39502
38874
|
|
|
39503
38875
|
// ../../packages/plugin-runtime/src/attached/forward-policy.ts
|
|
38876
|
+
import { randomUUID as randomUUID14 } from "crypto";
|
|
38877
|
+
import { readFile, rename, writeFile } from "fs/promises";
|
|
38878
|
+
import { join as join19 } from "path";
|
|
39504
38879
|
function isInvalidRequest(err) {
|
|
39505
38880
|
return typeof err === "object" && err !== null && err.name === "RemoteRequestInvalid";
|
|
39506
38881
|
}
|
|
@@ -39519,7 +38894,7 @@ var FORWARD_STATE_FILENAME = ATTACHED_FORWARD_STATE_FILENAME;
|
|
|
39519
38894
|
var STATE_FILENAME = FORWARD_STATE_FILENAME;
|
|
39520
38895
|
function createForwardPolicy(deps) {
|
|
39521
38896
|
const now = deps.now ?? (() => Date.now());
|
|
39522
|
-
const file2 =
|
|
38897
|
+
const file2 = join19(deps.dir, STATE_FILENAME);
|
|
39523
38898
|
let state = null;
|
|
39524
38899
|
let loading = null;
|
|
39525
38900
|
async function readState() {
|
|
@@ -39544,7 +38919,7 @@ function createForwardPolicy(deps) {
|
|
|
39544
38919
|
state = next;
|
|
39545
38920
|
try {
|
|
39546
38921
|
await ensureDataDir(deps.dir);
|
|
39547
|
-
const tmp = `${file2}.${
|
|
38922
|
+
const tmp = `${file2}.${randomUUID14()}.tmp`;
|
|
39548
38923
|
await writeFile(tmp, JSON.stringify(next), { encoding: "utf8", mode: DATA_FILE_MODE });
|
|
39549
38924
|
await rename(tmp, file2);
|
|
39550
38925
|
} catch {
|
|
@@ -39685,6 +39060,9 @@ var AttachedDataGateway = class {
|
|
|
39685
39060
|
*
|
|
39686
39061
|
* Machine mode answers before any key is read, so a machine attachment pays
|
|
39687
39062
|
* nothing for scoping and forwards exactly what it always has.
|
|
39063
|
+
*
|
|
39064
|
+
* `governanceAppliesTo` answers from this same verdict, so it agrees with
|
|
39065
|
+
* forwarding key for key.
|
|
39688
39066
|
*/
|
|
39689
39067
|
verdictFor(keyOf) {
|
|
39690
39068
|
try {
|
|
@@ -39701,24 +39079,27 @@ var AttachedDataGateway = class {
|
|
|
39701
39079
|
* the key its row holds in the local store, recorded per root (see
|
|
39702
39080
|
* `rootVerdict`), not the key on the root event just handed in: roots are
|
|
39703
39081
|
* first-write-wins in the store, so when two producers record a root for one
|
|
39704
|
-
* session (the session-start hook, then a reconcile pass) the second leaves
|
|
39705
|
-
*
|
|
39706
|
-
*
|
|
39707
|
-
*
|
|
39708
|
-
*
|
|
39709
|
-
*
|
|
39710
|
-
*
|
|
39711
|
-
*
|
|
39712
|
-
*
|
|
39713
|
-
*
|
|
39714
|
-
*
|
|
39715
|
-
*
|
|
39716
|
-
*
|
|
39717
|
-
*
|
|
39718
|
-
*
|
|
39719
|
-
*
|
|
39720
|
-
*
|
|
39721
|
-
*
|
|
39082
|
+
* session (the session-start hook, then a reconcile pass) the second leaves the
|
|
39083
|
+
* stored row as it was. That stored row, not this event, is what a history
|
|
39084
|
+
* drain pass would decide, if the root started before the attach; the drain
|
|
39085
|
+
* never offers one that started after it (`started_at < backlogBefore`).
|
|
39086
|
+
* Whether this root EVENT is itself sent takes both keys: the stored one AND
|
|
39087
|
+
* its own. The event's attributes (cwd, project, repo) describe where it was
|
|
39088
|
+
* recorded from, so a root event keyed to a personal directory is never sent
|
|
39089
|
+
* under an enrolled stored root, though the enrolled leaves still forward under
|
|
39090
|
+
* it: the instance that wrote the stored root is expected to have forwarded it.
|
|
39091
|
+
* If it did not (the root was written while standalone or under another
|
|
39092
|
+
* attachment, or its forward failed), the plane refuses those leaves. A root
|
|
39093
|
+
* that started before the attach is shipped, ahead of its leaves, by the
|
|
39094
|
+
* history drain; one that started after it is never offered by the drain. Any
|
|
39095
|
+
* other row with a root reference (`rootSessionId`, else `parentId`) forwards
|
|
39096
|
+
* only when its own key is in scope AND this instance recorded an in-scope
|
|
39097
|
+
* verdict for that root. The audit-event route has real foreign keys on both
|
|
39098
|
+
* columns and stubs no missing root, so a leaf sent after its root was kept
|
|
39099
|
+
* local is refused there, and a refused forward counts toward the breaker that
|
|
39100
|
+
* guards every other one. A root this instance never recorded is therefore
|
|
39101
|
+
* `'local'`: the only answer that cannot orphan a row. A row with no root
|
|
39102
|
+
* reference at all has nothing to orphan, and is decided by its own key.
|
|
39722
39103
|
*
|
|
39723
39104
|
* What this costs is stated rather than discovered. A session whose stored
|
|
39724
39105
|
* root is not keyed to an enrolled repository keeps its token and tool
|
|
@@ -39789,6 +39170,87 @@ var AttachedDataGateway = class {
|
|
|
39789
39170
|
return [];
|
|
39790
39171
|
}
|
|
39791
39172
|
}
|
|
39173
|
+
/**
|
|
39174
|
+
* The verdict for the repositories nested in a scanned project, answered
|
|
39175
|
+
* TOTALLY: `'forward'` or `'local'`, never a throw.
|
|
39176
|
+
*
|
|
39177
|
+
* A walk descends into a nested clone or submodule and folds its files into
|
|
39178
|
+
* the project it is walking, so one register can carry several
|
|
39179
|
+
* repositories' call sites under one project key. Each of them must be in
|
|
39180
|
+
* scope for it to forward. One key out of scope, or a nested repository with
|
|
39181
|
+
* no remote (an `undefined` key), keeps the whole register local.
|
|
39182
|
+
*
|
|
39183
|
+
* An ABSENT list is `'local'` too. Only the code that walked the tree can say
|
|
39184
|
+
* what is nested in it, and every scan passes the list, empty when nothing
|
|
39185
|
+
* is nested. A register nobody vouched for is not one a scoped attachment
|
|
39186
|
+
* may send.
|
|
39187
|
+
*
|
|
39188
|
+
* Machine mode answers before reading the context, so a machine attachment
|
|
39189
|
+
* forwards exactly what it always has.
|
|
39190
|
+
*/
|
|
39191
|
+
nestedVerdict(context) {
|
|
39192
|
+
try {
|
|
39193
|
+
if (this.deps.attachment.mode === "machine") return "forward";
|
|
39194
|
+
const keys = context?.nestedScopeKeys;
|
|
39195
|
+
if (keys === void 0) return "local";
|
|
39196
|
+
for (const key of keys) {
|
|
39197
|
+
if (this.verdictFor(() => key) === "local") return "local";
|
|
39198
|
+
}
|
|
39199
|
+
return "forward";
|
|
39200
|
+
} catch {
|
|
39201
|
+
return "local";
|
|
39202
|
+
}
|
|
39203
|
+
}
|
|
39204
|
+
/**
|
|
39205
|
+
* The register a scoped attachment sends, once the project and the repositories
|
|
39206
|
+
* nested in it are in scope: the register itself, with `reconcile.deletedFiles`
|
|
39207
|
+
* cut to the deleted paths whose own repository is in scope. `undefined` sends
|
|
39208
|
+
* nothing. TOTAL, like `verdictFor`, and for its reasons.
|
|
39209
|
+
*
|
|
39210
|
+
* The deletion sweep takes its paths from the scan ledger, not from the walk,
|
|
39211
|
+
* and the ledger holds every file the scanner ever read under the root, nested
|
|
39212
|
+
* clones' included. So a clone that was removed, or one an ignore file now
|
|
39213
|
+
* hides, is in no walk and never reaches `nestedVerdict`, yet its ledgered
|
|
39214
|
+
* paths come back as deleted. The scan names the repository of each deleted
|
|
39215
|
+
* path (`context.deletedFileKeys`, one entry per path in the register's order)
|
|
39216
|
+
* and each is held to the same verdict as any other key. A path whose key is
|
|
39217
|
+
* absent, or out of scope, is not sent.
|
|
39218
|
+
*
|
|
39219
|
+
* The list is asked for here, and only here: it is an async read of the scan
|
|
39220
|
+
* ledger that the scan makes on being called, so a machine attachment, which
|
|
39221
|
+
* returns before this, and a register already kept local never cause it.
|
|
39222
|
+
*
|
|
39223
|
+
* Anything the scan did not vouch for sends no deleted path, and the register
|
|
39224
|
+
* itself still goes: no list, a list that throws or whose read is rejected, or a
|
|
39225
|
+
* list whose length is not the register's. Deleting is the only thing a dropped
|
|
39226
|
+
* path could have done on the server, so the cost of a refusal is a stored row
|
|
39227
|
+
* that stays, never a path that leaves.
|
|
39228
|
+
*
|
|
39229
|
+
* Machine mode returns `input` itself, the same object and unread, so a machine
|
|
39230
|
+
* attachment's request is exactly what it was. A register that lists no deleted
|
|
39231
|
+
* path, or that is not a ledger register, has nothing to cut and is returned
|
|
39232
|
+
* as it came, with the list unread.
|
|
39233
|
+
*/
|
|
39234
|
+
async registerForWire(input2, context) {
|
|
39235
|
+
try {
|
|
39236
|
+
if (this.deps.attachment.mode === "machine") return input2;
|
|
39237
|
+
const { reconcile } = input2;
|
|
39238
|
+
if (reconcile.mode !== "ledger" || reconcile.deletedFiles.length === 0) return input2;
|
|
39239
|
+
const deleted = reconcile.deletedFiles;
|
|
39240
|
+
let kept = [];
|
|
39241
|
+
try {
|
|
39242
|
+
const keys = await context?.deletedFileKeys?.();
|
|
39243
|
+
if (keys?.length === deleted.length) {
|
|
39244
|
+
kept = deleted.filter((_path, at) => this.verdictFor(() => keys[at]) === "forward");
|
|
39245
|
+
}
|
|
39246
|
+
} catch {
|
|
39247
|
+
kept = [];
|
|
39248
|
+
}
|
|
39249
|
+
return { ...input2, reconcile: { ...reconcile, deletedFiles: kept } };
|
|
39250
|
+
} catch {
|
|
39251
|
+
return void 0;
|
|
39252
|
+
}
|
|
39253
|
+
}
|
|
39792
39254
|
/**
|
|
39793
39255
|
* The event `recordCapture` sends for a capture the verdict let through, or
|
|
39794
39256
|
* `undefined` to send nothing. TOTAL, like `verdictFor`, and for its reasons.
|
|
@@ -40114,12 +39576,24 @@ var AttachedDataGateway = class {
|
|
|
40114
39576
|
* payload onto the wire-boundary-safe shape (no snippet, hashed
|
|
40115
39577
|
* projectKey), and its result is discarded: `forward.run` never throws or
|
|
40116
39578
|
* rejects, so there is nothing here to act on.
|
|
39579
|
+
*
|
|
39580
|
+
* `context.nestedScopeKeys` is what the scanner knows and the register does
|
|
39581
|
+
* not say: the key of every repository nested below the scan root, whose
|
|
39582
|
+
* files the walk folded into this register. On a scoped attachment the
|
|
39583
|
+
* register is forwarded only when the project's own key AND every one of
|
|
39584
|
+
* those is in scope (see `nestedVerdict`), and its deleted paths are cut to the
|
|
39585
|
+
* ones whose own repository is in scope (`context.deletedFileKeys`, see
|
|
39586
|
+
* `registerForWire`). Machine mode never reads either, and the local write
|
|
39587
|
+
* never receives the context and gets the register whole.
|
|
40117
39588
|
*/
|
|
40118
|
-
async recordProjectEgress(input2) {
|
|
39589
|
+
async recordProjectEgress(input2, context) {
|
|
40119
39590
|
const summary = await this.deps.local.recordProjectEgress(input2);
|
|
40120
39591
|
if (this.verdictFor(() => scopeKeyOfProjectKey(input2.projectKey)) === "local") return summary;
|
|
39592
|
+
if (this.nestedVerdict(context) === "local") return summary;
|
|
39593
|
+
const register = await this.registerForWire(input2, context);
|
|
39594
|
+
if (register === void 0) return summary;
|
|
40121
39595
|
await this.deps.forward.run(
|
|
40122
|
-
() => this.deps.client.recordProjectEgress(toEgressIngestRequest(
|
|
39596
|
+
() => this.deps.client.recordProjectEgress(toEgressIngestRequest(register))
|
|
40123
39597
|
);
|
|
40124
39598
|
return summary;
|
|
40125
39599
|
}
|
|
@@ -40173,6 +39647,11 @@ var AttachedDataGateway = class {
|
|
|
40173
39647
|
async scanLedgerPaths() {
|
|
40174
39648
|
return this.deps.local.scanLedgerPaths();
|
|
40175
39649
|
}
|
|
39650
|
+
// Delegated, like the path list. An inner gateway that cannot say answers an
|
|
39651
|
+
// empty map, which gives every deleted path no key.
|
|
39652
|
+
async scanLedgerPathKeys() {
|
|
39653
|
+
return await this.deps.local.scanLedgerPathKeys?.() ?? /* @__PURE__ */ new Map();
|
|
39654
|
+
}
|
|
40176
39655
|
async recordScanned(entries) {
|
|
40177
39656
|
return this.deps.local.recordScanned(entries);
|
|
40178
39657
|
}
|
|
@@ -40239,6 +39718,12 @@ var AttachedDataGateway = class {
|
|
|
40239
39718
|
// and the spread above would otherwise drop the field silently — which is
|
|
40240
39719
|
// exactly what it did, leaving the whole control inert on every device
|
|
40241
39720
|
// while every test around it stayed green.
|
|
39721
|
+
//
|
|
39722
|
+
// WHOLE ON EVERY ATTACHMENT. A scoped attachment does not narrow the list
|
|
39723
|
+
// here: the port's `getPolicyBundle()` takes no event, and the runtime
|
|
39724
|
+
// reads this bundle once to build detection, so the detections it carries
|
|
39725
|
+
// apply to every event on the machine. Where a prohibition applies is
|
|
39726
|
+
// answered per event by `governanceAppliesTo` below.
|
|
40242
39727
|
prohibitedModels: cached2.prohibitedModels,
|
|
40243
39728
|
// NAMED for the same reason as the line above, and it is the same defect
|
|
40244
39729
|
// if it is not: `...local` above spreads the DEVICE's bundle, so a field
|
|
@@ -40298,6 +39783,30 @@ var AttachedDataGateway = class {
|
|
|
40298
39783
|
};
|
|
40299
39784
|
}
|
|
40300
39785
|
// ---------------------------------------------------------------------
|
|
39786
|
+
// GovernanceScope — where the organization's model policy applies
|
|
39787
|
+
// ---------------------------------------------------------------------
|
|
39788
|
+
/**
|
|
39789
|
+
* Whether the organization's governance applies to an event keyed `scopeKey`:
|
|
39790
|
+
* the question a model-guard site asks once it has decided to refuse.
|
|
39791
|
+
*
|
|
39792
|
+
* THE FORWARD VERDICT, through `verdictFor`: the answer is whether a capture
|
|
39793
|
+
* with the same key would be forwarded. A machine-wide attachment governs
|
|
39794
|
+
* every event, keyless included, exactly as before. A scoped one governs an
|
|
39795
|
+
* event only when its key names an enrolled repository. An event in a
|
|
39796
|
+
* personal repository, in no repository, with an empty key, or met by a fault
|
|
39797
|
+
* is not governed.
|
|
39798
|
+
*
|
|
39799
|
+
* The event's OWN key, never its session root's. The root rule in
|
|
39800
|
+
* `auditVerdict` decides whether a row can be forwarded without orphaning it;
|
|
39801
|
+
* this decides whether a refusal applies, which is a question about where the
|
|
39802
|
+
* event happened.
|
|
39803
|
+
*
|
|
39804
|
+
* Answered from memory: no store read, no bundle read, nothing sent.
|
|
39805
|
+
*/
|
|
39806
|
+
governanceAppliesTo(scopeKey) {
|
|
39807
|
+
return this.verdictFor(() => scopeKey) === "forward";
|
|
39808
|
+
}
|
|
39809
|
+
// ---------------------------------------------------------------------
|
|
40301
39810
|
// LocalStoreMaintenance — by delegation (D3).
|
|
40302
39811
|
//
|
|
40303
39812
|
// Implementing these is what actually closes the skipped-local-maintenance
|
|
@@ -40407,7 +39916,7 @@ function toWireInspection(insp) {
|
|
|
40407
39916
|
|
|
40408
39917
|
// ../../packages/plugin-runtime/src/attached/history-sync.ts
|
|
40409
39918
|
import { createHash as createHash6 } from "crypto";
|
|
40410
|
-
import { hostname as
|
|
39919
|
+
import { hostname as hostname4 } from "os";
|
|
40411
39920
|
|
|
40412
39921
|
// ../../packages/plugin-runtime/src/attached/capture-rebuild.ts
|
|
40413
39922
|
var CORRELATION_ID = EventMetadata.shape.correlationId;
|
|
@@ -40420,22 +39929,22 @@ var CAPTURE_BATCH_BYTES = 1024 * 1024;
|
|
|
40420
39929
|
|
|
40421
39930
|
// ../../packages/plugin-runtime/src/attached/history-sync-trigger.ts
|
|
40422
39931
|
import { spawn } from "child_process";
|
|
40423
|
-
import { fileURLToPath
|
|
39932
|
+
import { fileURLToPath } from "url";
|
|
40424
39933
|
var HISTORY_SYNC_THROTTLE_MS = 5 * 60 * 1e3;
|
|
40425
39934
|
|
|
40426
39935
|
// ../../packages/plugin-runtime/src/attached/install-record.ts
|
|
40427
39936
|
import { readFile as readFile2, stat } from "fs/promises";
|
|
40428
|
-
import { basename as
|
|
39937
|
+
import { basename as basename2, dirname as dirname4, join as join20, resolve as resolve2 } from "path";
|
|
40429
39938
|
async function readInstalledVersion(installRoot) {
|
|
40430
39939
|
try {
|
|
40431
39940
|
const versionDir = resolve2(installRoot);
|
|
40432
|
-
const pluginDir =
|
|
40433
|
-
const marketplaceDir =
|
|
40434
|
-
const cacheDir =
|
|
40435
|
-
if (
|
|
40436
|
-
const key = `${
|
|
39941
|
+
const pluginDir = dirname4(versionDir);
|
|
39942
|
+
const marketplaceDir = dirname4(pluginDir);
|
|
39943
|
+
const cacheDir = dirname4(marketplaceDir);
|
|
39944
|
+
if (basename2(cacheDir) !== "cache") return null;
|
|
39945
|
+
const key = `${basename2(pluginDir)}@${basename2(marketplaceDir)}`;
|
|
40437
39946
|
const record2 = JSON.parse(
|
|
40438
|
-
await readFile2(
|
|
39947
|
+
await readFile2(join20(dirname4(cacheDir), "installed_plugins.json"), "utf8")
|
|
40439
39948
|
);
|
|
40440
39949
|
const plugins = record2?.plugins;
|
|
40441
39950
|
if (typeof plugins !== "object" || plugins === null || !Object.hasOwn(plugins, key)) {
|
|
@@ -40467,7 +39976,7 @@ async function exists(path) {
|
|
|
40467
39976
|
}
|
|
40468
39977
|
|
|
40469
39978
|
// ../../packages/plugin-runtime/src/attached/plugin-block.ts
|
|
40470
|
-
import { readFileSync as
|
|
39979
|
+
import { readFileSync as readFileSync12 } from "fs";
|
|
40471
39980
|
var INSTALL_RECORD_READ_TIMEOUT_MS = REQUEST_TIMEOUT_MS / 2;
|
|
40472
39981
|
function createPluginBlock(build, policyStore) {
|
|
40473
39982
|
return async () => {
|
|
@@ -40495,9 +40004,9 @@ async function readInstalledVersionBounded(installRoot) {
|
|
|
40495
40004
|
}
|
|
40496
40005
|
|
|
40497
40006
|
// ../../packages/plugin-runtime/src/attached/policy-store.ts
|
|
40498
|
-
import { randomUUID as
|
|
40007
|
+
import { randomUUID as randomUUID15 } from "crypto";
|
|
40499
40008
|
import { readFile as readFile3, rm, writeFile as writeFile2 } from "fs/promises";
|
|
40500
|
-
import { join as
|
|
40009
|
+
import { join as join21 } from "path";
|
|
40501
40010
|
|
|
40502
40011
|
// ../../packages/plugin-runtime/src/attached/atomic-publish.ts
|
|
40503
40012
|
import { rename as rename2 } from "fs/promises";
|
|
@@ -40526,7 +40035,7 @@ async function publishByRename(tmp, file2, move = rename2) {
|
|
|
40526
40035
|
|
|
40527
40036
|
// ../../packages/plugin-runtime/src/attached/policy-store.ts
|
|
40528
40037
|
function createPolicyStore(dir = dataDir()) {
|
|
40529
|
-
const file2 =
|
|
40038
|
+
const file2 = join21(dir, "policy-cache.json");
|
|
40530
40039
|
async function read() {
|
|
40531
40040
|
try {
|
|
40532
40041
|
const raw = await readFile3(file2, "utf8");
|
|
@@ -40558,7 +40067,7 @@ function createPolicyStore(dir = dataDir()) {
|
|
|
40558
40067
|
}
|
|
40559
40068
|
}
|
|
40560
40069
|
async function publishRecord(record2) {
|
|
40561
|
-
const tmp = `${file2}.${
|
|
40070
|
+
const tmp = `${file2}.${randomUUID15()}.tmp`;
|
|
40562
40071
|
try {
|
|
40563
40072
|
await writeFile2(tmp, JSON.stringify(record2), {
|
|
40564
40073
|
encoding: "utf8",
|
|
@@ -40596,8 +40105,8 @@ function createPolicyStore(dir = dataDir()) {
|
|
|
40596
40105
|
}
|
|
40597
40106
|
|
|
40598
40107
|
// ../../packages/plugin-runtime/src/attached/posture-report-state.ts
|
|
40599
|
-
import { readFileSync as
|
|
40600
|
-
import { join as
|
|
40108
|
+
import { readFileSync as readFileSync13 } from "fs";
|
|
40109
|
+
import { join as join22 } from "path";
|
|
40601
40110
|
var POSTURE_REPORT_STATE_FILENAME = ATTACHED_POSTURE_REPORT_FILENAME;
|
|
40602
40111
|
var OUTCOME_KEYS = {
|
|
40603
40112
|
ok: true,
|
|
@@ -40611,7 +40120,7 @@ var OUTCOME_KEYS = {
|
|
|
40611
40120
|
};
|
|
40612
40121
|
var OUTCOMES = new Set(Object.keys(OUTCOME_KEYS));
|
|
40613
40122
|
function postureReportStatePath(dataDir2) {
|
|
40614
|
-
return
|
|
40123
|
+
return join22(dataDir2, POSTURE_REPORT_STATE_FILENAME);
|
|
40615
40124
|
}
|
|
40616
40125
|
function writePostureReportState(dataDir2, state) {
|
|
40617
40126
|
try {
|
|
@@ -40652,10 +40161,19 @@ function createPostureReporter(deps) {
|
|
|
40652
40161
|
hostname: deps.hostname(),
|
|
40653
40162
|
capturedAt: nowMs,
|
|
40654
40163
|
...measurement,
|
|
40655
|
-
// Omit the key rather than spread an explicit `undefined
|
|
40656
|
-
//
|
|
40657
|
-
//
|
|
40658
|
-
|
|
40164
|
+
// Omit the key rather than spread an explicit `undefined`. The type
|
|
40165
|
+
// admits `undefined` here (the schema's optional member), and
|
|
40166
|
+
// JSON.stringify sends the same bytes either way. Omitting keeps the
|
|
40167
|
+
// in-memory object free of an explicit `undefined` member, which the
|
|
40168
|
+
// tests pin by key presence.
|
|
40169
|
+
...plugin === void 0 ? {} : { plugin },
|
|
40170
|
+
// LAST, and only for a scoped attachment. A machine attachment omits
|
|
40171
|
+
// the key the same way, so its body is byte for byte the one it sent
|
|
40172
|
+
// before the member existed. Anything but exactly `machine` reports the
|
|
40173
|
+
// constant `scoped`, never the raw value: that is resolveScope's own
|
|
40174
|
+
// fail direction, and a value outside the wire's vocabulary would fail
|
|
40175
|
+
// the whole snapshot at the receiver, the wipe signal with it.
|
|
40176
|
+
...deps.attachmentMode === "machine" ? {} : { attachmentMode: "scoped" }
|
|
40659
40177
|
};
|
|
40660
40178
|
} catch {
|
|
40661
40179
|
return null;
|
|
@@ -40678,8 +40196,8 @@ function createPostureReporter(deps) {
|
|
|
40678
40196
|
}
|
|
40679
40197
|
|
|
40680
40198
|
// ../../packages/plugin-runtime/src/attached/posture-snapshot.ts
|
|
40681
|
-
import { statSync as
|
|
40682
|
-
import { DatabaseSync as
|
|
40199
|
+
import { statSync as statSync6 } from "fs";
|
|
40200
|
+
import { DatabaseSync as DatabaseSync3 } from "node:sqlite";
|
|
40683
40201
|
|
|
40684
40202
|
// ../../packages/plugin-runtime/src/attached/action-counts.ts
|
|
40685
40203
|
function emptyActionCounts() {
|
|
@@ -40709,7 +40227,7 @@ function emptyReadout(readError = false) {
|
|
|
40709
40227
|
}
|
|
40710
40228
|
function readStorePosture(dbPath2) {
|
|
40711
40229
|
try {
|
|
40712
|
-
|
|
40230
|
+
statSync6(dbPath2);
|
|
40713
40231
|
} catch (err) {
|
|
40714
40232
|
const code = err.code;
|
|
40715
40233
|
if (code === "ENOENT" || code === "ENOTDIR") return emptyReadout();
|
|
@@ -40737,7 +40255,7 @@ function readStorePosture(dbPath2) {
|
|
|
40737
40255
|
readError: false
|
|
40738
40256
|
});
|
|
40739
40257
|
try {
|
|
40740
|
-
db = new
|
|
40258
|
+
db = new DatabaseSync3(dbPath2, { readOnly: true });
|
|
40741
40259
|
db.exec("PRAGMA busy_timeout = 2000");
|
|
40742
40260
|
version2 = db.prepare("PRAGMA user_version").get().user_version;
|
|
40743
40261
|
try {
|
|
@@ -40789,16 +40307,16 @@ function readStorePosture(dbPath2) {
|
|
|
40789
40307
|
}
|
|
40790
40308
|
|
|
40791
40309
|
// ../../packages/plugin-runtime/src/attached/posture-store.ts
|
|
40792
|
-
import { randomUUID as
|
|
40310
|
+
import { randomUUID as randomUUID16 } from "crypto";
|
|
40793
40311
|
import { readFile as readFile4, rm as rm2, writeFile as writeFile3 } from "fs/promises";
|
|
40794
|
-
import { join as
|
|
40312
|
+
import { join as join23 } from "path";
|
|
40795
40313
|
var UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/;
|
|
40796
40314
|
function createPostureStore(dir = settingsDir(), legacyDir) {
|
|
40797
|
-
const file2 =
|
|
40798
|
-
const legacyFile = legacyDir === void 0 ? null :
|
|
40315
|
+
const file2 = join23(dir, "posture-state.json");
|
|
40316
|
+
const legacyFile = legacyDir === void 0 ? null : join23(legacyDir, "posture-state.json");
|
|
40799
40317
|
async function persist(state) {
|
|
40800
40318
|
await ensureDataDir(dir);
|
|
40801
|
-
const tmp = `${file2}.${
|
|
40319
|
+
const tmp = `${file2}.${randomUUID16()}.tmp`;
|
|
40802
40320
|
try {
|
|
40803
40321
|
await writeFile3(tmp, JSON.stringify(state), { encoding: "utf8", mode: DATA_FILE_MODE });
|
|
40804
40322
|
await publishByRename(tmp, file2);
|
|
@@ -40840,7 +40358,7 @@ function createPostureStore(dir = settingsDir(), legacyDir) {
|
|
|
40840
40358
|
}
|
|
40841
40359
|
return legacy;
|
|
40842
40360
|
}
|
|
40843
|
-
const fresh = { deviceId:
|
|
40361
|
+
const fresh = { deviceId: randomUUID16(), lastAttemptedAtMs: 0 };
|
|
40844
40362
|
try {
|
|
40845
40363
|
await ensureDataDir(dir);
|
|
40846
40364
|
if (createOwnerOnlyFileSync(file2, JSON.stringify(fresh))) return fresh;
|
|
@@ -40863,8 +40381,8 @@ function createPostureStore(dir = settingsDir(), legacyDir) {
|
|
|
40863
40381
|
}
|
|
40864
40382
|
|
|
40865
40383
|
// ../../packages/plugin-runtime/src/attached/sync-state.ts
|
|
40866
|
-
import { readFileSync as
|
|
40867
|
-
import { join as
|
|
40384
|
+
import { readFileSync as readFileSync14 } from "fs";
|
|
40385
|
+
import { join as join24 } from "path";
|
|
40868
40386
|
|
|
40869
40387
|
// ../../packages/plugin-runtime/src/attached/status.ts
|
|
40870
40388
|
var REFUSAL_LINES = {
|
|
@@ -40882,7 +40400,7 @@ var OUTCOME_LINES = {
|
|
|
40882
40400
|
|
|
40883
40401
|
// ../../packages/plugin-runtime/src/attached/sync-trigger.ts
|
|
40884
40402
|
import { spawn as spawn2 } from "child_process";
|
|
40885
|
-
import { fileURLToPath as
|
|
40403
|
+
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
40886
40404
|
var SYNC_THROTTLE_MS = 15 * 60 * 1e3;
|
|
40887
40405
|
|
|
40888
40406
|
// ../../packages/plugin-runtime/src/content-retention-pass.ts
|
|
@@ -40890,11 +40408,11 @@ var MAX_ROWS_PER_SWEEP = 50 * 1e3;
|
|
|
40890
40408
|
|
|
40891
40409
|
// ../../packages/plugin-runtime/src/content-retention-trigger.ts
|
|
40892
40410
|
import { spawn as spawn3 } from "child_process";
|
|
40893
|
-
import { fileURLToPath as
|
|
40411
|
+
import { fileURLToPath as fileURLToPath3 } from "url";
|
|
40894
40412
|
var CONTENT_RETENTION_THROTTLE_MS = 60 * 60 * 1e3;
|
|
40895
40413
|
|
|
40896
40414
|
// ../../packages/plugin-runtime/src/attached/factory.ts
|
|
40897
|
-
import { hostname as
|
|
40415
|
+
import { hostname as hostname5 } from "os";
|
|
40898
40416
|
|
|
40899
40417
|
// ../../packages/plugin-runtime/src/recorder.ts
|
|
40900
40418
|
var PLUGIN_RECORDER_BINARY = "plugin";
|
|
@@ -40907,7 +40425,7 @@ var StandaloneDataGateway = class {
|
|
|
40907
40425
|
// One notice per gateway — see warnRulesetDiscarded.
|
|
40908
40426
|
warnedRulesetDiscarded = false;
|
|
40909
40427
|
constructor(dataDir2, detections = [], meta4) {
|
|
40910
|
-
this.db = openLocalDatabase(dataDir2);
|
|
40428
|
+
this.db = openLocalDatabase(dataDir2, { shippedRegexMatchers: shippedRegexMatchers() });
|
|
40911
40429
|
this.dataDir = dataDir2;
|
|
40912
40430
|
this.db.installedPacks.recordInventory(detections, meta4);
|
|
40913
40431
|
}
|
|
@@ -41256,6 +40774,9 @@ var StandaloneDataGateway = class {
|
|
|
41256
40774
|
scanLedgerPaths() {
|
|
41257
40775
|
return Promise.resolve(this.db.scanLedger.allPaths());
|
|
41258
40776
|
}
|
|
40777
|
+
scanLedgerPathKeys() {
|
|
40778
|
+
return Promise.resolve(this.db.scanLedger.pathKeys());
|
|
40779
|
+
}
|
|
41259
40780
|
recordScanned(entries) {
|
|
41260
40781
|
this.db.scanLedger.upsertEntries(entries);
|
|
41261
40782
|
return Promise.resolve();
|
|
@@ -41341,13 +40862,17 @@ function resolveGatewayForConfig(config2, meta4) {
|
|
|
41341
40862
|
},
|
|
41342
40863
|
store: postureStore,
|
|
41343
40864
|
readStore: () => readStorePosture(config2.dbPath),
|
|
41344
|
-
hostname: () =>
|
|
40865
|
+
hostname: () => hostname5(),
|
|
41345
40866
|
now: () => Date.now(),
|
|
40867
|
+
// The mode THIS gateway enforces, from the attachment resolved above,
|
|
40868
|
+
// so the report cannot name a mode the forward paths are not using.
|
|
40869
|
+
attachmentMode: attachment.mode,
|
|
41346
40870
|
// The reporting build's identity, when the caller knows it (the plugin
|
|
41347
40871
|
// adapters do; an embedder or a test may not). Composed with the SAME
|
|
41348
40872
|
// policy store the sync child writes, so the block names the bundle
|
|
41349
|
-
// actually in force.
|
|
41350
|
-
// reporter
|
|
40873
|
+
// actually in force. The dependency key is omitted when no build is
|
|
40874
|
+
// known, and the reporter's optional call (`deps.pluginBlock?.()`)
|
|
40875
|
+
// then adds no block.
|
|
41351
40876
|
...meta4?.pluginBuild === void 0 ? {} : { pluginBlock: createPluginBlock(meta4.pluginBuild, store) }
|
|
41352
40877
|
})
|
|
41353
40878
|
});
|
|
@@ -41364,7 +40889,7 @@ function resolveDataGateway(config2, meta4, gatewayFactory = defaultGatewayFacto
|
|
|
41364
40889
|
}
|
|
41365
40890
|
|
|
41366
40891
|
// ../../packages/plugin-runtime/src/handle-session-start.ts
|
|
41367
|
-
import { randomUUID as
|
|
40892
|
+
import { randomUUID as randomUUID17 } from "crypto";
|
|
41368
40893
|
var EXCEPTION_RETENTION_MS = 90 * 24 * 60 * 60 * 1e3;
|
|
41369
40894
|
|
|
41370
40895
|
// src/setup-frame-json.ts
|
|
@@ -41435,8 +40960,8 @@ function table(headers, rows, opts = {}) {
|
|
|
41435
40960
|
const widths = headers.map(
|
|
41436
40961
|
(h, i) => Math.max(visibleLength(h), ...rows.map((r) => visibleLength(r[i] ?? "")))
|
|
41437
40962
|
);
|
|
41438
|
-
const
|
|
41439
|
-
const fmt = (cells) => cells.map((cell, i) => padEnd(cell, widths[i] ?? 0)).join(
|
|
40963
|
+
const sep2 = " ".repeat(gap);
|
|
40964
|
+
const fmt = (cells) => cells.map((cell, i) => padEnd(cell, widths[i] ?? 0)).join(sep2);
|
|
41440
40965
|
const headerLine = fmt(headers.map((h) => h.toUpperCase()));
|
|
41441
40966
|
if (opts.rowSep === true) {
|
|
41442
40967
|
const fullWidth = widths.reduce((n, w) => n + w, 0) + gap * Math.max(0, widths.length - 1);
|
|
@@ -41448,7 +40973,7 @@ function table(headers, rows, opts = {}) {
|
|
|
41448
40973
|
});
|
|
41449
40974
|
return [headerLine, rule, ...body].join("\n");
|
|
41450
40975
|
}
|
|
41451
|
-
const ruleLine = widths.map((w) => "\u2500".repeat(w)).join(
|
|
40976
|
+
const ruleLine = widths.map((w) => "\u2500".repeat(w)).join(sep2);
|
|
41452
40977
|
return [headerLine, ruleLine, ...rows.map(fmt)].join("\n");
|
|
41453
40978
|
}
|
|
41454
40979
|
function fenced(body) {
|
|
@@ -41461,8 +40986,8 @@ function show(body) {
|
|
|
41461
40986
|
}
|
|
41462
40987
|
|
|
41463
40988
|
// ../../packages/setup-wizard/src/remediation/rotation-checklist.ts
|
|
41464
|
-
import { writeFileSync as
|
|
41465
|
-
import { join as
|
|
40989
|
+
import { writeFileSync as writeFileSync5 } from "fs";
|
|
40990
|
+
import { join as join25 } from "path";
|
|
41466
40991
|
|
|
41467
40992
|
// ../../packages/setup-wizard/src/triage/merge.ts
|
|
41468
40993
|
var RANK = Object.fromEntries(
|
|
@@ -41470,9 +40995,9 @@ var RANK = Object.fromEntries(
|
|
|
41470
40995
|
);
|
|
41471
40996
|
|
|
41472
40997
|
// ../../packages/setup-wizard/src/triage/plan-file.ts
|
|
41473
|
-
import { mkdtempSync, readFileSync as
|
|
40998
|
+
import { mkdtempSync, readFileSync as readFileSync15, rmdirSync, rmSync as rmSync7, writeFileSync as writeFileSync6 } from "fs";
|
|
41474
40999
|
import { tmpdir } from "os";
|
|
41475
|
-
import { basename as
|
|
41000
|
+
import { basename as basename3, dirname as dirname5, join as join26 } from "path";
|
|
41476
41001
|
var SuppressionEntrySchema = external_exports.object({
|
|
41477
41002
|
ruleId: external_exports.string(),
|
|
41478
41003
|
category: DetectionCategory,
|
|
@@ -41514,10 +41039,10 @@ var PersistedPlanSchema = external_exports.object({
|
|
|
41514
41039
|
});
|
|
41515
41040
|
|
|
41516
41041
|
// src/skills-registry.ts
|
|
41517
|
-
import { readdirSync as
|
|
41518
|
-
import { join as
|
|
41519
|
-
import { fileURLToPath as
|
|
41520
|
-
var SKILLS_DIR =
|
|
41042
|
+
import { readdirSync as readdirSync2, readFileSync as readFileSync16 } from "fs";
|
|
41043
|
+
import { join as join27 } from "path";
|
|
41044
|
+
import { fileURLToPath as fileURLToPath4 } from "url";
|
|
41045
|
+
var SKILLS_DIR = fileURLToPath4(new URL("../skills", import.meta.url));
|
|
41521
41046
|
function frontmatterName(content) {
|
|
41522
41047
|
const block = /^---\n([\s\S]*?)\n---/.exec(content);
|
|
41523
41048
|
if (block === null) return void 0;
|
|
@@ -41525,10 +41050,10 @@ function frontmatterName(content) {
|
|
|
41525
41050
|
return name?.[1];
|
|
41526
41051
|
}
|
|
41527
41052
|
function readRegisteredSkills() {
|
|
41528
|
-
return
|
|
41053
|
+
return readdirSync2(SKILLS_DIR, { withFileTypes: true }).filter((entry) => entry.isDirectory()).flatMap((entry) => {
|
|
41529
41054
|
let content;
|
|
41530
41055
|
try {
|
|
41531
|
-
content =
|
|
41056
|
+
content = readFileSync16(join27(SKILLS_DIR, entry.name, "SKILL.md"), "utf8");
|
|
41532
41057
|
} catch {
|
|
41533
41058
|
return [];
|
|
41534
41059
|
}
|