@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/query.js
CHANGED
|
@@ -1,888 +1,8 @@
|
|
|
1
|
-
var __create = Object.create;
|
|
2
1
|
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
-
var __commonJS = (cb, mod) => function __require() {
|
|
8
|
-
try {
|
|
9
|
-
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
10
|
-
} catch (e) {
|
|
11
|
-
throw mod = 0, e;
|
|
12
|
-
}
|
|
13
|
-
};
|
|
14
2
|
var __export = (target, all) => {
|
|
15
3
|
for (var name in all)
|
|
16
4
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
17
5
|
};
|
|
18
|
-
var __copyProps = (to, from, except, desc) => {
|
|
19
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
20
|
-
for (let key of __getOwnPropNames(from))
|
|
21
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
22
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
23
|
-
}
|
|
24
|
-
return to;
|
|
25
|
-
};
|
|
26
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
27
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
28
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
29
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
30
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
31
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
32
|
-
mod
|
|
33
|
-
));
|
|
34
|
-
|
|
35
|
-
// ../../node_modules/.pnpm/ignore@7.0.11/node_modules/ignore/index.js
|
|
36
|
-
var require_ignore = __commonJS({
|
|
37
|
-
"../../node_modules/.pnpm/ignore@7.0.11/node_modules/ignore/index.js"(exports, module) {
|
|
38
|
-
"use strict";
|
|
39
|
-
function makeArray(subject) {
|
|
40
|
-
return Array.isArray(subject) ? subject : [subject];
|
|
41
|
-
}
|
|
42
|
-
var UNDEFINED = void 0;
|
|
43
|
-
var EMPTY = "";
|
|
44
|
-
var SPACE = " ";
|
|
45
|
-
var ESCAPE = "\\";
|
|
46
|
-
var REGEX_LITERAL_SPECIAL = /[.*+?()[\]{}^$|\\/]/;
|
|
47
|
-
var REGEX_TEST_BLANK_LINE = /^\uFEFF? *$/;
|
|
48
|
-
var REGEX_INVALID_TRAILING_BACKSLASH = /(?:[^\\]|^)\\$/;
|
|
49
|
-
var REGEX_REPLACE_LEADING_EXCAPED_EXCLAMATION = /^\\!/;
|
|
50
|
-
var REGEX_REPLACE_LEADING_EXCAPED_HASH = /^\\#/;
|
|
51
|
-
var REGEX_SPLITALL_CRLF = /\r?\n/g;
|
|
52
|
-
var DOUBLE_SLASH = "//";
|
|
53
|
-
var SLASH_CODE = 47;
|
|
54
|
-
var DOT_CODE = 46;
|
|
55
|
-
var SLASH3 = "/";
|
|
56
|
-
var TMP_KEY_IGNORE = "node-ignore";
|
|
57
|
-
if (typeof Symbol !== "undefined") {
|
|
58
|
-
TMP_KEY_IGNORE = /* @__PURE__ */ Symbol.for("node-ignore");
|
|
59
|
-
}
|
|
60
|
-
var KEY_IGNORE = TMP_KEY_IGNORE;
|
|
61
|
-
var define = (object2, key, value) => {
|
|
62
|
-
Object.defineProperty(object2, key, { value });
|
|
63
|
-
return value;
|
|
64
|
-
};
|
|
65
|
-
var RETURN_FALSE = () => false;
|
|
66
|
-
var cleanRangeBackSlash = (slashes) => {
|
|
67
|
-
const { length } = slashes;
|
|
68
|
-
return slashes.slice(0, length - length % 2);
|
|
69
|
-
};
|
|
70
|
-
var POSIX_CLASSES = {
|
|
71
|
-
alnum: "0-9A-Za-z",
|
|
72
|
-
alpha: "A-Za-z",
|
|
73
|
-
blank: " \\t",
|
|
74
|
-
cntrl: "\\x00-\\x1f\\x7f",
|
|
75
|
-
digit: "0-9",
|
|
76
|
-
graph: "!-.0-~",
|
|
77
|
-
lower: "a-z",
|
|
78
|
-
print: " -.0-~",
|
|
79
|
-
punct: "!-.:-@\\[-`{-~",
|
|
80
|
-
// git's `sane-ctype.h` classifies \v and \f as control, not space,
|
|
81
|
-
// unlike C's `isspace`
|
|
82
|
-
space: " \\t\\n\\r",
|
|
83
|
-
upper: "A-Z",
|
|
84
|
-
xdigit: "0-9A-Fa-f"
|
|
85
|
-
};
|
|
86
|
-
var CLASS_MEMBERS_TO_ESCAPE = "\\]^-[";
|
|
87
|
-
var escapeMember = (char) => CLASS_MEMBERS_TO_ESCAPE.indexOf(char) < 0 ? char : ESCAPE + char;
|
|
88
|
-
var NON_SLASH = "(?!\\/)";
|
|
89
|
-
var classSource = (negated, body) => {
|
|
90
|
-
if (negated) {
|
|
91
|
-
return `[^\\/${body}]`;
|
|
92
|
-
}
|
|
93
|
-
const source = `[${body}]`;
|
|
94
|
-
return new RegExp(source).test("/") ? NON_SLASH + source : source;
|
|
95
|
-
};
|
|
96
|
-
var scanBracket = (pattern, start) => {
|
|
97
|
-
const { length } = pattern;
|
|
98
|
-
let index = start + 1;
|
|
99
|
-
let negated = EMPTY;
|
|
100
|
-
const lead = pattern[index];
|
|
101
|
-
if (lead === "!" || lead === "^") {
|
|
102
|
-
negated = "^";
|
|
103
|
-
index++;
|
|
104
|
-
}
|
|
105
|
-
let body = EMPTY;
|
|
106
|
-
let prev = EMPTY;
|
|
107
|
-
for (; ; ) {
|
|
108
|
-
const char = pattern[index];
|
|
109
|
-
if (char === UNDEFINED) {
|
|
110
|
-
return null;
|
|
111
|
-
}
|
|
112
|
-
if (char === ESCAPE) {
|
|
113
|
-
const escaped = pattern[index + 1];
|
|
114
|
-
if (escaped === UNDEFINED) {
|
|
115
|
-
return null;
|
|
116
|
-
}
|
|
117
|
-
body += escapeMember(escaped);
|
|
118
|
-
prev = escaped;
|
|
119
|
-
index++;
|
|
120
|
-
} else if (char === "-" && prev && index + 1 < length && pattern[index + 1] !== "]") {
|
|
121
|
-
index++;
|
|
122
|
-
let to = pattern[index];
|
|
123
|
-
if (to === ESCAPE) {
|
|
124
|
-
to = pattern[index += 1];
|
|
125
|
-
}
|
|
126
|
-
if (prev <= to) {
|
|
127
|
-
body += `-${escapeMember(to)}`;
|
|
128
|
-
}
|
|
129
|
-
prev = EMPTY;
|
|
130
|
-
} else if (char === "[" && pattern[index + 1] === ":") {
|
|
131
|
-
const nameStart = index + 2;
|
|
132
|
-
let end = nameStart;
|
|
133
|
-
while (end < length && pattern[end] !== "]") {
|
|
134
|
-
end++;
|
|
135
|
-
}
|
|
136
|
-
if (end === length) {
|
|
137
|
-
return null;
|
|
138
|
-
}
|
|
139
|
-
if (end > nameStart && pattern[end - 1] === ":") {
|
|
140
|
-
const expanded = POSIX_CLASSES[pattern.slice(nameStart, end - 1)];
|
|
141
|
-
if (expanded === UNDEFINED) {
|
|
142
|
-
return null;
|
|
143
|
-
}
|
|
144
|
-
body += expanded;
|
|
145
|
-
prev = EMPTY;
|
|
146
|
-
index = end;
|
|
147
|
-
} else {
|
|
148
|
-
body += escapeMember("[");
|
|
149
|
-
prev = "[";
|
|
150
|
-
index = nameStart - 2;
|
|
151
|
-
}
|
|
152
|
-
} else {
|
|
153
|
-
body += escapeMember(char);
|
|
154
|
-
prev = char;
|
|
155
|
-
}
|
|
156
|
-
index++;
|
|
157
|
-
if (pattern[index] === "]") {
|
|
158
|
-
return {
|
|
159
|
-
end: index,
|
|
160
|
-
source: classSource(negated, body)
|
|
161
|
-
};
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
};
|
|
165
|
-
var NEVER_MATCH = "[]";
|
|
166
|
-
var PLACEHOLDER = "\0";
|
|
167
|
-
var REGEX_RESTORE_PLACEHOLDER = new RegExp(
|
|
168
|
-
`${PLACEHOLDER}(\\d+)${PLACEHOLDER}`,
|
|
169
|
-
"g"
|
|
170
|
-
);
|
|
171
|
-
var TRAILING_WILDCARD = "\uE000";
|
|
172
|
-
var TRAILING_DOUBLESTAR = "\uE001";
|
|
173
|
-
var extractBrackets = (pattern) => {
|
|
174
|
-
const sources = [];
|
|
175
|
-
const hold = (source) => `${PLACEHOLDER}${sources.push(source) - 1}${PLACEHOLDER}`;
|
|
176
|
-
const { length } = pattern;
|
|
177
|
-
let out = EMPTY;
|
|
178
|
-
let index = 0;
|
|
179
|
-
while (index < length) {
|
|
180
|
-
const char = pattern[index];
|
|
181
|
-
if (char === ESCAPE) {
|
|
182
|
-
const escaped = pattern[index + 1];
|
|
183
|
-
if (escaped === "*" || escaped === "[" || escaped === SPACE || escaped === ESCAPE) {
|
|
184
|
-
out += pattern.slice(index, index + 2);
|
|
185
|
-
} else {
|
|
186
|
-
out += hold(
|
|
187
|
-
REGEX_LITERAL_SPECIAL.test(escaped) ? ESCAPE + escaped : escaped
|
|
188
|
-
);
|
|
189
|
-
}
|
|
190
|
-
index += 2;
|
|
191
|
-
} else if (char === PLACEHOLDER) {
|
|
192
|
-
out += hold(`[${PLACEHOLDER}]`);
|
|
193
|
-
index++;
|
|
194
|
-
} else if (char === "[") {
|
|
195
|
-
const scanned = scanBracket(pattern, index);
|
|
196
|
-
if (scanned === null) {
|
|
197
|
-
out += hold(NEVER_MATCH);
|
|
198
|
-
index = length;
|
|
199
|
-
} else {
|
|
200
|
-
out += hold(scanned.source);
|
|
201
|
-
index = scanned.end + 1;
|
|
202
|
-
}
|
|
203
|
-
} else {
|
|
204
|
-
out += char;
|
|
205
|
-
index++;
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
return {
|
|
209
|
-
source: out,
|
|
210
|
-
sources
|
|
211
|
-
};
|
|
212
|
-
};
|
|
213
|
-
var DIRECT = null;
|
|
214
|
-
var REGEX_INNER_SLASH = /\/(?!$)/;
|
|
215
|
-
var REPLACERS = [
|
|
216
|
-
[
|
|
217
|
-
// Remove BOM
|
|
218
|
-
// TODO:
|
|
219
|
-
// Other similar zero-width characters?
|
|
220
|
-
/^\uFEFF/,
|
|
221
|
-
() => EMPTY,
|
|
222
|
-
"\uFEFF"
|
|
223
|
-
],
|
|
224
|
-
[
|
|
225
|
-
// A trailing line terminator, left on when a whole file's contents are
|
|
226
|
-
// added as one pattern rather than split into lines. git never sees one
|
|
227
|
-
// -- it reads a `.gitignore` line by line -- so it is not part of the
|
|
228
|
-
// pattern and is dropped here, apart from the trailing-space trimming,
|
|
229
|
-
// which follows git in touching spaces and nothing else.
|
|
230
|
-
/[\r\n]+$/,
|
|
231
|
-
() => EMPTY
|
|
232
|
-
],
|
|
233
|
-
// > Trailing spaces are ignored unless they are quoted with backslash ("\")
|
|
234
|
-
[
|
|
235
|
-
// Only spaces, never tabs or other whitespace: git trims a trailing run
|
|
236
|
-
// of `' '` and nothing else (dir.c, `trim_trailing_spaces`, a single
|
|
237
|
-
// `case ' '`), so a pattern ending in a tab keeps it as a literal.
|
|
238
|
-
// (a\ ) -> (a )
|
|
239
|
-
// (a ) -> (a)
|
|
240
|
-
// (a ) -> (a)
|
|
241
|
-
// (a \ ) -> (a )
|
|
242
|
-
/((?:\\\\)*?)(\\? +)$/,
|
|
243
|
-
(_, m1, m2) => m1 + (m2.indexOf("\\") === 0 ? SPACE : EMPTY)
|
|
244
|
-
],
|
|
245
|
-
// Replace (\ ) with ' '
|
|
246
|
-
// Only a space: an escaped tab or other whitespace is already a literal by
|
|
247
|
-
// the time it reaches here, and a bare tab must be left as one, not turned
|
|
248
|
-
// into a space.
|
|
249
|
-
// (\ ) -> ' '
|
|
250
|
-
// (\\ ) -> '\\ '
|
|
251
|
-
// (\\\ ) -> '\\ '
|
|
252
|
-
[
|
|
253
|
-
/(\\+?) /g,
|
|
254
|
-
(_, m1) => {
|
|
255
|
-
const { length } = m1;
|
|
256
|
-
return m1.slice(0, length - length % 2) + SPACE;
|
|
257
|
-
}
|
|
258
|
-
],
|
|
259
|
-
// Escape metacharacters
|
|
260
|
-
// which is written down by users but means special for regular expressions.
|
|
261
|
-
// > There are 12 characters with special meanings:
|
|
262
|
-
// > - the backslash \,
|
|
263
|
-
// > - the caret ^,
|
|
264
|
-
// > - the dollar sign $,
|
|
265
|
-
// > - the period or dot .,
|
|
266
|
-
// > - the vertical bar or pipe symbol |,
|
|
267
|
-
// > - the question mark ?,
|
|
268
|
-
// > - the asterisk or star *,
|
|
269
|
-
// > - the plus sign +,
|
|
270
|
-
// > - the opening parenthesis (,
|
|
271
|
-
// > - the closing parenthesis ),
|
|
272
|
-
// > - and the opening square bracket [,
|
|
273
|
-
// > - the opening curly brace {,
|
|
274
|
-
// > These special characters are often called "metacharacters".
|
|
275
|
-
[
|
|
276
|
-
/[\\$.|*+(){^]/g,
|
|
277
|
-
(match) => `\\${match}`
|
|
278
|
-
],
|
|
279
|
-
[
|
|
280
|
-
// > a question mark (?) matches a single character
|
|
281
|
-
/(?!\\)\?/g,
|
|
282
|
-
() => "[^/]",
|
|
283
|
-
"?"
|
|
284
|
-
],
|
|
285
|
-
// leading slash
|
|
286
|
-
[
|
|
287
|
-
// > A leading slash matches the beginning of the pathname.
|
|
288
|
-
// > For example, "/*.c" matches "cat-file.c" but not "mozilla-sha1/sha1.c".
|
|
289
|
-
// A leading slash matches the beginning of the pathname
|
|
290
|
-
/^\//,
|
|
291
|
-
() => "^",
|
|
292
|
-
SLASH3
|
|
293
|
-
],
|
|
294
|
-
// replace special metacharacter slash after the leading slash
|
|
295
|
-
[
|
|
296
|
-
/\//g,
|
|
297
|
-
() => "\\/",
|
|
298
|
-
SLASH3
|
|
299
|
-
],
|
|
300
|
-
[
|
|
301
|
-
// > A leading "**" followed by a slash means match in all directories.
|
|
302
|
-
// > For example, "**/foo" matches file or directory "foo" anywhere,
|
|
303
|
-
// > the same as pattern "foo".
|
|
304
|
-
// > "**/foo/bar" matches file or directory "bar" anywhere that is directly
|
|
305
|
-
// > under directory "foo".
|
|
306
|
-
// Notice that the '*'s have been replaced as '\\*'
|
|
307
|
-
/^\^*(?:\\\*\\\*\\\/)+/,
|
|
308
|
-
// '**/foo' <-> 'foo'
|
|
309
|
-
() => "^(?:.*\\/)?",
|
|
310
|
-
"*"
|
|
311
|
-
],
|
|
312
|
-
// starting
|
|
313
|
-
[
|
|
314
|
-
// there will be no leading '/'
|
|
315
|
-
// (which has been replaced by section "leading slash")
|
|
316
|
-
// If starts with '**', adding a '^' to the regular expression also works
|
|
317
|
-
DIRECT,
|
|
318
|
-
(source, pattern) => {
|
|
319
|
-
if (!source || source[0] === "^") {
|
|
320
|
-
return source;
|
|
321
|
-
}
|
|
322
|
-
const anchor2 = !REGEX_INNER_SLASH.test(pattern) ? "(?:^|\\/)" : "^";
|
|
323
|
-
return anchor2 + source;
|
|
324
|
-
}
|
|
325
|
-
],
|
|
326
|
-
// two globstars
|
|
327
|
-
[
|
|
328
|
-
// Use lookahead assertions so that we could match more than one `'/**'`
|
|
329
|
-
/\\\/\\\*\\\*(?=\\\/|$)/g,
|
|
330
|
-
// Zero, one or several directories
|
|
331
|
-
// should not use '*', or it will be replaced by the next replacer
|
|
332
|
-
// Check if it is not the last `'/**'`
|
|
333
|
-
(_, index, str2) => index + 6 < str2.length ? str2.slice(index + 6) === "\\/" ? "(?:\\/[^\\/]+)+" : "(?:\\/[^\\/]+)*" : `\\/${TRAILING_DOUBLESTAR}`,
|
|
334
|
-
"*"
|
|
335
|
-
],
|
|
336
|
-
// normal intermediate wildcards
|
|
337
|
-
[
|
|
338
|
-
// Never replace escaped '*'
|
|
339
|
-
// ignore rule '\*' will match the path '*'
|
|
340
|
-
// 'abc.*/' -> go
|
|
341
|
-
// 'abc.*' -> skip this rule,
|
|
342
|
-
// coz trailing single wildcard will be handed by [trailing wildcard]
|
|
343
|
-
/(^|[^\\]+)(\\\*)+(?=.+)/g,
|
|
344
|
-
// '*.js' matches '.js'
|
|
345
|
-
// '*.js' doesn't match 'abc'
|
|
346
|
-
(_, p1, p2) => {
|
|
347
|
-
const unescaped = p2.replace(/\\\*/g, "[^\\/]*");
|
|
348
|
-
return p1 + unescaped;
|
|
349
|
-
},
|
|
350
|
-
"*"
|
|
351
|
-
],
|
|
352
|
-
// trailing wildcard, held apart from a literal star
|
|
353
|
-
[
|
|
354
|
-
// The step above leaves a trailing `*` alone, so a single `\*` is all that
|
|
355
|
-
// can be left at the end here. Whether it is a wildcard or a literal
|
|
356
|
-
// turns on the backslashes the user put in front of it: the escaper has
|
|
357
|
-
// since doubled every one, so what stands here is those `2N` doubled
|
|
358
|
-
// backslashes and then the star's own escape. An even number of the
|
|
359
|
-
// original `N` leaves the star unescaped -- a wildcard -- and an odd
|
|
360
|
-
// number escapes it -- a literal. This runs while the two are still
|
|
361
|
-
// distinct, before the unescape steps below collapse the literal onto
|
|
362
|
-
// the very `\*` a wildcard leaves behind.
|
|
363
|
-
/(^|[^\\])((?:\\\\)*)\\\*$/,
|
|
364
|
-
(match, p1, p2) => (
|
|
365
|
-
// `p2` holds the doubled user backslashes; half of them is `N`.
|
|
366
|
-
p2.length / 2 % 2 === 0 ? p1 + p2 + TRAILING_WILDCARD : match
|
|
367
|
-
),
|
|
368
|
-
"*"
|
|
369
|
-
],
|
|
370
|
-
[
|
|
371
|
-
// unescape, revert step 3 except for back slash
|
|
372
|
-
// For example, if a user escape a '\\*',
|
|
373
|
-
// after step 3, the result will be '\\\\\\*'
|
|
374
|
-
/\\\\\\(?=[$.|*+(){^])/g,
|
|
375
|
-
() => ESCAPE,
|
|
376
|
-
ESCAPE + ESCAPE
|
|
377
|
-
],
|
|
378
|
-
[
|
|
379
|
-
// '\\\\' -> '\\'
|
|
380
|
-
/\\\\/g,
|
|
381
|
-
() => ESCAPE,
|
|
382
|
-
ESCAPE + ESCAPE
|
|
383
|
-
],
|
|
384
|
-
[
|
|
385
|
-
// Every real bracket expression -- POSIX classes included -- has already
|
|
386
|
-
// been held aside by `extractBrackets`, so the only `[` left in the
|
|
387
|
-
// pattern is an escaped, literal one.
|
|
388
|
-
// `\` is escaped by step 3
|
|
389
|
-
/\\\[([^\]/]*?)(\\*)($|\])/g,
|
|
390
|
-
// '\\[bar]' -> '\\\\[bar\\]'
|
|
391
|
-
(match, range, endEscape, close) => `\\[${range}${cleanRangeBackSlash(endEscape)}${close}`,
|
|
392
|
-
"["
|
|
393
|
-
],
|
|
394
|
-
// ending
|
|
395
|
-
[
|
|
396
|
-
// 'js' will not match 'js.'
|
|
397
|
-
// 'ab' will not match 'abc'
|
|
398
|
-
DIRECT,
|
|
399
|
-
// WTF!
|
|
400
|
-
// https://git-scm.com/docs/gitignore
|
|
401
|
-
// changes in [2.22.1](https://git-scm.com/docs/gitignore/2.22.1)
|
|
402
|
-
// which re-fixes #24, #38
|
|
403
|
-
// > If there is a separator at the end of the pattern then the pattern
|
|
404
|
-
// > will only match directories, otherwise the pattern can match both
|
|
405
|
-
// > files and directories.
|
|
406
|
-
// 'js*' will not match 'a.js'
|
|
407
|
-
// 'js/' will not match 'a.js'
|
|
408
|
-
// 'js' will match 'a.js' and 'a.js/'
|
|
409
|
-
(source) => {
|
|
410
|
-
const last = source[source.length - 1];
|
|
411
|
-
if (!last || last === TRAILING_WILDCARD || last === TRAILING_DOUBLESTAR) {
|
|
412
|
-
return source;
|
|
413
|
-
}
|
|
414
|
-
return last === SLASH3 ? `${source}$` : `${source}(?=$|\\/$)`;
|
|
415
|
-
}
|
|
416
|
-
]
|
|
417
|
-
];
|
|
418
|
-
var REGEX_REPLACE_TRAILING_WILDCARD = /(^|\\\/)?\uE000$/;
|
|
419
|
-
var MODE_IGNORE = "regex";
|
|
420
|
-
var MODE_CHECK_IGNORE = "checkRegex";
|
|
421
|
-
var UNDERSCORE = "_";
|
|
422
|
-
var replaceTrailingWildcard = (_, p1) => {
|
|
423
|
-
const prefix = p1 ? `${p1}[^/]+` : "[^/]*";
|
|
424
|
-
return `${prefix}(?=$|\\/$)`;
|
|
425
|
-
};
|
|
426
|
-
var REGEX_REPLACE_TRAILING_DOUBLESTAR = /\uE001$/;
|
|
427
|
-
var replaceTrailingDoublestar = () => ".+(?=$|\\/$)";
|
|
428
|
-
var WILDCARD = "[^\\/]*";
|
|
429
|
-
var separatorAfter = (run, at) => {
|
|
430
|
-
let separator = EMPTY;
|
|
431
|
-
for (let index = at + 1; index < run.length && !run[index].wildcard; index++) {
|
|
432
|
-
separator += run[index].single;
|
|
433
|
-
}
|
|
434
|
-
return separator;
|
|
435
|
-
};
|
|
436
|
-
var pinWildcards = (source) => {
|
|
437
|
-
if (source.indexOf(WILDCARD) < 0) {
|
|
438
|
-
return source;
|
|
439
|
-
}
|
|
440
|
-
const tokens = [];
|
|
441
|
-
const { length } = source;
|
|
442
|
-
let index = 0;
|
|
443
|
-
while (index < length) {
|
|
444
|
-
const char = source[index];
|
|
445
|
-
if (source.startsWith(WILDCARD, index)) {
|
|
446
|
-
tokens.push({ wildcard: true });
|
|
447
|
-
index += WILDCARD.length;
|
|
448
|
-
} else if (char === "[") {
|
|
449
|
-
let end = index + 1;
|
|
450
|
-
if (source[end] === "^") {
|
|
451
|
-
end++;
|
|
452
|
-
}
|
|
453
|
-
if (source[end] === "]") {
|
|
454
|
-
end++;
|
|
455
|
-
}
|
|
456
|
-
while (end < length && source[end] !== "]") {
|
|
457
|
-
end += source[end] === ESCAPE ? 2 : 1;
|
|
458
|
-
}
|
|
459
|
-
end++;
|
|
460
|
-
tokens.push({ single: source.slice(index, end) });
|
|
461
|
-
index = end;
|
|
462
|
-
} else if (char === ESCAPE) {
|
|
463
|
-
tokens.push({ single: source.slice(index, index + 2) });
|
|
464
|
-
index += 2;
|
|
465
|
-
} else if (char === "(") {
|
|
466
|
-
let depth = 0;
|
|
467
|
-
let end = index;
|
|
468
|
-
do {
|
|
469
|
-
if (source[end] === ESCAPE) {
|
|
470
|
-
end++;
|
|
471
|
-
} else if (source[end] === "(") {
|
|
472
|
-
depth++;
|
|
473
|
-
} else if (source[end] === ")") {
|
|
474
|
-
depth--;
|
|
475
|
-
}
|
|
476
|
-
end++;
|
|
477
|
-
} while (end < length && depth > 0);
|
|
478
|
-
if ("*+?".indexOf(source[end]) >= 0) {
|
|
479
|
-
end++;
|
|
480
|
-
}
|
|
481
|
-
tokens.push({ boundary: source.slice(index, end) });
|
|
482
|
-
index = end;
|
|
483
|
-
} else if (char === "^" || char === "$") {
|
|
484
|
-
tokens.push({ boundary: char });
|
|
485
|
-
index++;
|
|
486
|
-
} else {
|
|
487
|
-
tokens.push({ single: char });
|
|
488
|
-
index++;
|
|
489
|
-
}
|
|
490
|
-
}
|
|
491
|
-
let out = EMPTY;
|
|
492
|
-
let run = [];
|
|
493
|
-
const flush = () => {
|
|
494
|
-
let lastWildcard;
|
|
495
|
-
run.forEach((token, at) => {
|
|
496
|
-
if (token.wildcard) {
|
|
497
|
-
lastWildcard = at;
|
|
498
|
-
}
|
|
499
|
-
});
|
|
500
|
-
run.forEach((token, at) => {
|
|
501
|
-
if (!token.wildcard) {
|
|
502
|
-
out += token.single;
|
|
503
|
-
return;
|
|
504
|
-
}
|
|
505
|
-
out += at === lastWildcard ? WILDCARD : `(?:(?!${separatorAfter(run, at)})[^\\/])*`;
|
|
506
|
-
});
|
|
507
|
-
run = [];
|
|
508
|
-
};
|
|
509
|
-
tokens.forEach((token) => {
|
|
510
|
-
if (token.boundary === void 0) {
|
|
511
|
-
run.push(token);
|
|
512
|
-
return;
|
|
513
|
-
}
|
|
514
|
-
flush();
|
|
515
|
-
out += token.boundary;
|
|
516
|
-
});
|
|
517
|
-
flush();
|
|
518
|
-
return out;
|
|
519
|
-
};
|
|
520
|
-
var makeRegexPrefix = (pattern) => {
|
|
521
|
-
const { source, sources } = extractBrackets(pattern);
|
|
522
|
-
const replaced = REPLACERS.reduce(
|
|
523
|
-
// A pass whose matcher finds nothing hands back the very string it was
|
|
524
|
-
// given, so asking first costs a search and saves a rewrite. Ten of the
|
|
525
|
-
// fifteen passes never fire for a typical .gitignore line, and between
|
|
526
|
-
// them they were 45% of this chain.
|
|
527
|
-
(prev, [matcher, replacer, required2]) => {
|
|
528
|
-
if (matcher === DIRECT) {
|
|
529
|
-
return replacer(prev, pattern);
|
|
530
|
-
}
|
|
531
|
-
if (required2 !== UNDEFINED && prev.indexOf(required2) < 0) {
|
|
532
|
-
return prev;
|
|
533
|
-
}
|
|
534
|
-
return matcher.test(prev) ? prev.replace(matcher, replacer.bind(pattern)) : prev;
|
|
535
|
-
},
|
|
536
|
-
source
|
|
537
|
-
);
|
|
538
|
-
return sources.length ? replaced.replace(
|
|
539
|
-
REGEX_RESTORE_PLACEHOLDER,
|
|
540
|
-
(match, index) => sources[index]
|
|
541
|
-
) : replaced;
|
|
542
|
-
};
|
|
543
|
-
var checkSourceOf = (body, prefix) => {
|
|
544
|
-
if (body[body.length - 1] === SLASH3) {
|
|
545
|
-
prefix = makeRegexPrefix(body.slice(0, -1));
|
|
546
|
-
}
|
|
547
|
-
const head = prefix.slice(0, -1);
|
|
548
|
-
const last = prefix[prefix.length - 1];
|
|
549
|
-
return last === TRAILING_WILDCARD ? `${head}$` : last === TRAILING_DOUBLESTAR ? `${head}.*$` : NEVER_MATCH;
|
|
550
|
-
};
|
|
551
|
-
var matchesBasename = (body) => {
|
|
552
|
-
const index = body.indexOf(SLASH3);
|
|
553
|
-
return index < 0 || index === body.length - 1;
|
|
554
|
-
};
|
|
555
|
-
var basenameOf = (path) => {
|
|
556
|
-
const end = path.length - 1;
|
|
557
|
-
const index = path.lastIndexOf(
|
|
558
|
-
SLASH3,
|
|
559
|
-
path[end] === SLASH3 ? end - 1 : end
|
|
560
|
-
);
|
|
561
|
-
return index < 0 ? path : path.slice(index + 1);
|
|
562
|
-
};
|
|
563
|
-
var parentOf = (path) => {
|
|
564
|
-
if (path.charCodeAt(0) === SLASH_CODE || path.indexOf(DOUBLE_SLASH) >= 0) {
|
|
565
|
-
const slices = path.split(SLASH3).filter(Boolean);
|
|
566
|
-
slices.pop();
|
|
567
|
-
return slices.length ? slices.join(SLASH3) + SLASH3 : EMPTY;
|
|
568
|
-
}
|
|
569
|
-
const end = path.length - 1;
|
|
570
|
-
const cut = path.lastIndexOf(
|
|
571
|
-
SLASH3,
|
|
572
|
-
path.charCodeAt(end) === SLASH_CODE ? end - 1 : end
|
|
573
|
-
);
|
|
574
|
-
return cut < 0 ? EMPTY : path.slice(0, cut + 1);
|
|
575
|
-
};
|
|
576
|
-
var isString = (subject) => typeof subject === "string";
|
|
577
|
-
var checkPattern = (pattern) => pattern && isString(pattern) && !REGEX_TEST_BLANK_LINE.test(pattern) && !REGEX_INVALID_TRAILING_BACKSLASH.test(pattern) && pattern.indexOf("#") !== 0;
|
|
578
|
-
var splitPattern = (pattern) => pattern.split(REGEX_SPLITALL_CRLF).filter(Boolean);
|
|
579
|
-
var IgnoreRule = class {
|
|
580
|
-
constructor(pattern, mark, body, ignoreCase, negative, prefix) {
|
|
581
|
-
this.pattern = pattern;
|
|
582
|
-
this.mark = mark;
|
|
583
|
-
this.negative = negative;
|
|
584
|
-
define(this, "body", body);
|
|
585
|
-
define(this, "ignoreCase", ignoreCase);
|
|
586
|
-
define(this, "regexPrefix", prefix);
|
|
587
|
-
}
|
|
588
|
-
// Worked out on first use and kept behind an own property, the way `regex`
|
|
589
|
-
// caches itself in `_regex`. Deciding it in the constructor instead would
|
|
590
|
-
// add a fourth `defineProperty` to every rule ever built, which cost 4% of
|
|
591
|
-
// every compile -- including the compiles of rules that are never matched
|
|
592
|
-
// against anything.
|
|
593
|
-
get _basenameOnly() {
|
|
594
|
-
return define(this, "_basenameOnly", matchesBasename(this.body));
|
|
595
|
-
}
|
|
596
|
-
get regex() {
|
|
597
|
-
const key = UNDERSCORE + MODE_IGNORE;
|
|
598
|
-
if (this[key]) {
|
|
599
|
-
return this[key];
|
|
600
|
-
}
|
|
601
|
-
return this._make(MODE_IGNORE, key);
|
|
602
|
-
}
|
|
603
|
-
get checkRegex() {
|
|
604
|
-
const key = UNDERSCORE + MODE_CHECK_IGNORE;
|
|
605
|
-
if (this[key]) {
|
|
606
|
-
return this[key];
|
|
607
|
-
}
|
|
608
|
-
return this._make(MODE_CHECK_IGNORE, key);
|
|
609
|
-
}
|
|
610
|
-
_make(mode, key) {
|
|
611
|
-
const str2 = pinWildcards(
|
|
612
|
-
mode === MODE_IGNORE ? this.regexPrefix.replace(REGEX_REPLACE_TRAILING_WILDCARD, replaceTrailingWildcard).replace(REGEX_REPLACE_TRAILING_DOUBLESTAR, replaceTrailingDoublestar) : checkSourceOf(this.body, this.regexPrefix)
|
|
613
|
-
);
|
|
614
|
-
const regex = this.ignoreCase ? new RegExp(str2, "i") : new RegExp(str2);
|
|
615
|
-
return define(this, key, regex);
|
|
616
|
-
}
|
|
617
|
-
};
|
|
618
|
-
var createRule = ({
|
|
619
|
-
pattern,
|
|
620
|
-
mark
|
|
621
|
-
}, ignoreCase) => {
|
|
622
|
-
let negative = false;
|
|
623
|
-
let body = pattern;
|
|
624
|
-
if (body.indexOf("!") === 0) {
|
|
625
|
-
negative = true;
|
|
626
|
-
body = body.substr(1);
|
|
627
|
-
}
|
|
628
|
-
body = body.replace(REGEX_REPLACE_LEADING_EXCAPED_EXCLAMATION, "!").replace(REGEX_REPLACE_LEADING_EXCAPED_HASH, "#");
|
|
629
|
-
const regexPrefix = makeRegexPrefix(body);
|
|
630
|
-
return new IgnoreRule(
|
|
631
|
-
pattern,
|
|
632
|
-
mark,
|
|
633
|
-
body,
|
|
634
|
-
ignoreCase,
|
|
635
|
-
negative,
|
|
636
|
-
regexPrefix
|
|
637
|
-
);
|
|
638
|
-
};
|
|
639
|
-
var RuleManager = class {
|
|
640
|
-
constructor(ignoreCase) {
|
|
641
|
-
this._ignoreCase = ignoreCase;
|
|
642
|
-
this._rules = [];
|
|
643
|
-
this._basenameCount = 0;
|
|
644
|
-
}
|
|
645
|
-
_add(pattern) {
|
|
646
|
-
if (pattern && pattern[KEY_IGNORE]) {
|
|
647
|
-
this._rules = this._rules.concat(pattern._rules._rules);
|
|
648
|
-
this._basenameCount += pattern._rules._basenameCount;
|
|
649
|
-
this._added = true;
|
|
650
|
-
return;
|
|
651
|
-
}
|
|
652
|
-
if (isString(pattern)) {
|
|
653
|
-
pattern = {
|
|
654
|
-
pattern
|
|
655
|
-
};
|
|
656
|
-
}
|
|
657
|
-
if (checkPattern(pattern.pattern)) {
|
|
658
|
-
const rule = createRule(pattern, this._ignoreCase);
|
|
659
|
-
this._added = true;
|
|
660
|
-
this._rules.push(rule);
|
|
661
|
-
if (matchesBasename(rule.body)) {
|
|
662
|
-
this._basenameCount++;
|
|
663
|
-
}
|
|
664
|
-
}
|
|
665
|
-
}
|
|
666
|
-
// @param {Array<string> | string | Ignore} pattern
|
|
667
|
-
add(pattern) {
|
|
668
|
-
this._added = false;
|
|
669
|
-
makeArray(
|
|
670
|
-
isString(pattern) ? splitPattern(pattern) : pattern
|
|
671
|
-
).forEach(this._add, this);
|
|
672
|
-
if (this._added) {
|
|
673
|
-
this._literalRules = UNDEFINED;
|
|
674
|
-
}
|
|
675
|
-
return this._added;
|
|
676
|
-
}
|
|
677
|
-
// Match the literal 'abc/' for `checkIgnore`, last rule wins. Only a rule
|
|
678
|
-
// ending in a wildcard can match it (see `checkSourceOf`), so the rest
|
|
679
|
-
// are left out once, rather than tested or compiled for every path.
|
|
680
|
-
testLiteral(path) {
|
|
681
|
-
const rules = this._literalRules || (this._literalRules = this._rules.filter(
|
|
682
|
-
({ body }) => body[body.length - (body[body.length - 1] === SLASH3 ? 2 : 1)] === "*"
|
|
683
|
-
));
|
|
684
|
-
let ignored = false;
|
|
685
|
-
let unignored = false;
|
|
686
|
-
let matchedRule;
|
|
687
|
-
for (let index = rules.length - 1; index >= 0; index--) {
|
|
688
|
-
const rule = rules[index];
|
|
689
|
-
if (rule.checkRegex.test(path)) {
|
|
690
|
-
ignored = !rule.negative;
|
|
691
|
-
unignored = rule.negative;
|
|
692
|
-
matchedRule = rule.negative ? UNDEFINED : rule;
|
|
693
|
-
break;
|
|
694
|
-
}
|
|
695
|
-
}
|
|
696
|
-
const ret = {
|
|
697
|
-
ignored,
|
|
698
|
-
unignored
|
|
699
|
-
};
|
|
700
|
-
if (matchedRule) {
|
|
701
|
-
ret.rule = matchedRule;
|
|
702
|
-
}
|
|
703
|
-
return ret;
|
|
704
|
-
}
|
|
705
|
-
// Test one single path without recursively checking parent directories
|
|
706
|
-
//
|
|
707
|
-
// - checkUnignored `boolean` whether should check if the path is unignored,
|
|
708
|
-
// setting `checkUnignored` to `false` could reduce additional
|
|
709
|
-
// path matching.
|
|
710
|
-
// - check `string` either `MODE_IGNORE` or `MODE_CHECK_IGNORE`
|
|
711
|
-
// @returns {TestResult} true if a file is ignored
|
|
712
|
-
test(path, checkUnignored, mode) {
|
|
713
|
-
let ignored = false;
|
|
714
|
-
let unignored = false;
|
|
715
|
-
let matchedRule;
|
|
716
|
-
const rules = this._rules;
|
|
717
|
-
const { length } = rules;
|
|
718
|
-
const shortcut = this._basenameCount * 2 >= length;
|
|
719
|
-
const basename8 = shortcut ? basenameOf(path) : path;
|
|
720
|
-
for (let index = 0; index < length; index++) {
|
|
721
|
-
const rule = rules[index];
|
|
722
|
-
const { negative } = rule;
|
|
723
|
-
const skip = unignored === negative && ignored !== unignored || negative && !ignored && !unignored && !checkUnignored;
|
|
724
|
-
if (!skip && rule[mode].test(
|
|
725
|
-
shortcut && rule._basenameOnly ? basename8 : path
|
|
726
|
-
)) {
|
|
727
|
-
ignored = !negative;
|
|
728
|
-
unignored = negative;
|
|
729
|
-
matchedRule = negative ? UNDEFINED : rule;
|
|
730
|
-
}
|
|
731
|
-
}
|
|
732
|
-
const ret = {
|
|
733
|
-
ignored,
|
|
734
|
-
unignored
|
|
735
|
-
};
|
|
736
|
-
if (matchedRule) {
|
|
737
|
-
ret.rule = matchedRule;
|
|
738
|
-
}
|
|
739
|
-
return ret;
|
|
740
|
-
}
|
|
741
|
-
};
|
|
742
|
-
var throwError = (message, Ctor) => {
|
|
743
|
-
throw new Ctor(message);
|
|
744
|
-
};
|
|
745
|
-
var checkPath = (path, originalPath, doThrow) => {
|
|
746
|
-
if (!isString(path)) {
|
|
747
|
-
return doThrow(
|
|
748
|
-
`path must be a string, but got \`${originalPath}\``,
|
|
749
|
-
TypeError
|
|
750
|
-
);
|
|
751
|
-
}
|
|
752
|
-
if (!path) {
|
|
753
|
-
return doThrow(`path must not be empty`, TypeError);
|
|
754
|
-
}
|
|
755
|
-
if (checkPath.isNotRelative(path)) {
|
|
756
|
-
const r = "`path.relative()`d";
|
|
757
|
-
return doThrow(
|
|
758
|
-
`path should be a ${r} string, but got "${originalPath}"`,
|
|
759
|
-
RangeError
|
|
760
|
-
);
|
|
761
|
-
}
|
|
762
|
-
return true;
|
|
763
|
-
};
|
|
764
|
-
var isNotRelative = (path) => {
|
|
765
|
-
const first = path.charCodeAt(0);
|
|
766
|
-
if (first === SLASH_CODE) {
|
|
767
|
-
return true;
|
|
768
|
-
}
|
|
769
|
-
if (first !== DOT_CODE) {
|
|
770
|
-
return false;
|
|
771
|
-
}
|
|
772
|
-
if (path.length === 1) {
|
|
773
|
-
return true;
|
|
774
|
-
}
|
|
775
|
-
const second = path.charCodeAt(1);
|
|
776
|
-
if (second === SLASH_CODE) {
|
|
777
|
-
return true;
|
|
778
|
-
}
|
|
779
|
-
if (second !== DOT_CODE) {
|
|
780
|
-
return false;
|
|
781
|
-
}
|
|
782
|
-
return path.length === 2 || path.charCodeAt(2) === SLASH_CODE;
|
|
783
|
-
};
|
|
784
|
-
checkPath.isNotRelative = isNotRelative;
|
|
785
|
-
checkPath.convert = (p) => p;
|
|
786
|
-
var Ignore = class {
|
|
787
|
-
constructor({
|
|
788
|
-
ignorecase = true,
|
|
789
|
-
ignoreCase = ignorecase,
|
|
790
|
-
allowRelativePaths = false
|
|
791
|
-
} = {}) {
|
|
792
|
-
define(this, KEY_IGNORE, true);
|
|
793
|
-
this._rules = new RuleManager(ignoreCase);
|
|
794
|
-
this._strictPathCheck = !allowRelativePaths;
|
|
795
|
-
this._initCache();
|
|
796
|
-
}
|
|
797
|
-
_initCache() {
|
|
798
|
-
this._ignoreCache = /* @__PURE__ */ Object.create(null);
|
|
799
|
-
this._testCache = /* @__PURE__ */ Object.create(null);
|
|
800
|
-
}
|
|
801
|
-
add(pattern) {
|
|
802
|
-
if (this._rules.add(pattern)) {
|
|
803
|
-
this._initCache();
|
|
804
|
-
}
|
|
805
|
-
return this;
|
|
806
|
-
}
|
|
807
|
-
// legacy
|
|
808
|
-
addPattern(pattern) {
|
|
809
|
-
return this.add(pattern);
|
|
810
|
-
}
|
|
811
|
-
// @returns {TestResult}
|
|
812
|
-
_test(originalPath, cache, checkUnignored) {
|
|
813
|
-
const path = originalPath && checkPath.convert(originalPath);
|
|
814
|
-
checkPath(
|
|
815
|
-
path,
|
|
816
|
-
originalPath,
|
|
817
|
-
this._strictPathCheck ? throwError : RETURN_FALSE
|
|
818
|
-
);
|
|
819
|
-
return this._t(path, cache, checkUnignored);
|
|
820
|
-
}
|
|
821
|
-
checkIgnore(path) {
|
|
822
|
-
if (path.charCodeAt(path.length - 1) !== SLASH_CODE) {
|
|
823
|
-
return this.test(path);
|
|
824
|
-
}
|
|
825
|
-
const dir = this._t(path, this._testCache, true);
|
|
826
|
-
if (dir.ignored) {
|
|
827
|
-
return dir;
|
|
828
|
-
}
|
|
829
|
-
const literal2 = this._rules.testLiteral(path);
|
|
830
|
-
return literal2.ignored || literal2.unignored ? literal2 : dir;
|
|
831
|
-
}
|
|
832
|
-
_t(path, cache, checkUnignored) {
|
|
833
|
-
if (path in cache) {
|
|
834
|
-
return cache[path];
|
|
835
|
-
}
|
|
836
|
-
const parentPath = parentOf(path);
|
|
837
|
-
const parent = parentPath ? this._t(parentPath, cache, checkUnignored) : UNDEFINED;
|
|
838
|
-
return cache[path] = parent && parent.ignored ? parent : this._rules.test(path, checkUnignored, MODE_IGNORE);
|
|
839
|
-
}
|
|
840
|
-
ignores(path) {
|
|
841
|
-
return this._test(path, this._ignoreCache, false).ignored;
|
|
842
|
-
}
|
|
843
|
-
createFilter() {
|
|
844
|
-
return (path) => !this.ignores(path);
|
|
845
|
-
}
|
|
846
|
-
filter(paths) {
|
|
847
|
-
return makeArray(paths).filter(this.createFilter());
|
|
848
|
-
}
|
|
849
|
-
// @returns {TestResult}
|
|
850
|
-
test(path) {
|
|
851
|
-
return this._test(path, this._testCache, true);
|
|
852
|
-
}
|
|
853
|
-
};
|
|
854
|
-
var factory = (options) => new Ignore(options);
|
|
855
|
-
var isPathValid = (path) => checkPath(path && checkPath.convert(path), path, RETURN_FALSE);
|
|
856
|
-
var setupWindows = () => {
|
|
857
|
-
const makePosix = (str2) => /^\\\\\?\\/.test(str2) || /["<>|\u0000-\u001F]+/u.test(str2) ? str2 : str2.replace(/\\/g, "/");
|
|
858
|
-
checkPath.convert = makePosix;
|
|
859
|
-
const REGEX_TEST_WINDOWS_PATH_ABSOLUTE = /^[a-z]:\//i;
|
|
860
|
-
checkPath.isNotRelative = (path) => REGEX_TEST_WINDOWS_PATH_ABSOLUTE.test(path) || isNotRelative(path);
|
|
861
|
-
};
|
|
862
|
-
if (
|
|
863
|
-
// Detect `process` so that it can run in browsers.
|
|
864
|
-
typeof process !== "undefined" && process.platform === "win32"
|
|
865
|
-
) {
|
|
866
|
-
setupWindows();
|
|
867
|
-
}
|
|
868
|
-
module.exports = factory;
|
|
869
|
-
factory.default = factory;
|
|
870
|
-
module.exports.isPathValid = isPathValid;
|
|
871
|
-
define(module.exports, /* @__PURE__ */ Symbol.for("setupWindows"), setupWindows);
|
|
872
|
-
}
|
|
873
|
-
});
|
|
874
|
-
|
|
875
|
-
// ../../packages/persistence/src/attached-derived.ts
|
|
876
|
-
import { rmSync } from "fs";
|
|
877
|
-
import { join } from "path";
|
|
878
|
-
var POLICY_CACHE_FILENAME = "policy-cache.json";
|
|
879
|
-
var ATTACHED_FORWARD_STATE_FILENAME = "attached-state.json";
|
|
880
|
-
var ATTACHED_FORWARD_DROPS_FILENAME = "attached-forward-drops.json";
|
|
881
|
-
var ATTACHED_POSTURE_REPORT_FILENAME = "attached-posture-report.json";
|
|
882
|
-
|
|
883
|
-
// ../../packages/persistence/src/control-plane-credential.ts
|
|
884
|
-
import { chmodSync as chmodSync2, lstatSync as lstatSync2, readFileSync, rmSync as rmSync3, statSync } from "fs";
|
|
885
|
-
import { join as join2 } from "path";
|
|
886
6
|
|
|
887
7
|
// ../../packages/schema/src/drizzle/deferred-migrations.ts
|
|
888
8
|
var DEFERRED_MIGRATION_TAGS = [
|
|
@@ -3867,9 +2987,9 @@ var asciiTabOrNewline = /[\t\n\r]/g;
|
|
|
3867
2987
|
function stripTabAndNewline(value) {
|
|
3868
2988
|
return value.replace(asciiTabOrNewline, "");
|
|
3869
2989
|
}
|
|
3870
|
-
function urlHostnameOk(url2,
|
|
3871
|
-
|
|
3872
|
-
return
|
|
2990
|
+
function urlHostnameOk(url2, hostname6) {
|
|
2991
|
+
hostname6.lastIndex = 0;
|
|
2992
|
+
return hostname6.test(url2.hostname);
|
|
3873
2993
|
}
|
|
3874
2994
|
function urlProtocolOk(url2, protocol) {
|
|
3875
2995
|
protocol.lastIndex = 0;
|
|
@@ -20789,13 +19909,16 @@ function serviceTierMultiplier(tier) {
|
|
|
20789
19909
|
if (tier === void 0) return 1;
|
|
20790
19910
|
return SERVICE_TIER_MULTIPLIERS.get(tier) ?? 1;
|
|
20791
19911
|
}
|
|
19912
|
+
function promptTokensOf(usage) {
|
|
19913
|
+
return usage.promptTokens ?? (usage.inputTokens ?? 0) + (usage.cacheReadTokens ?? 0) + (usage.cacheWrite1hTokens ?? 0) + (usage.cacheWrite5mTokens ?? 0);
|
|
19914
|
+
}
|
|
20792
19915
|
function costOf(price, usage) {
|
|
20793
19916
|
const metered = [
|
|
20794
19917
|
[usage.cacheWrite1hTokens ?? 0, price.cacheWrite1h],
|
|
20795
19918
|
[usage.cacheWrite5mTokens ?? 0, price.cacheWrite5m],
|
|
20796
19919
|
[usage.cacheReadTokens ?? 0, price.cacheRead]
|
|
20797
19920
|
];
|
|
20798
|
-
const band = price.longContext !== null && (usage
|
|
19921
|
+
const band = price.longContext !== null && promptTokensOf(usage) > price.longContext.thresholdInputTokens ? price.longContext : null;
|
|
20799
19922
|
if (band !== null && (band.input === null || band.output === null)) return null;
|
|
20800
19923
|
const inputRate = band?.input ?? price.input;
|
|
20801
19924
|
const outputRate = band?.output ?? price.output;
|
|
@@ -20868,8 +19991,8 @@ var PLATFORM_HOSTING = /* @__PURE__ */ new Map([
|
|
|
20868
19991
|
["ollama", "local"],
|
|
20869
19992
|
["local", "local"]
|
|
20870
19993
|
]);
|
|
20871
|
-
function hostingFor(
|
|
20872
|
-
return PLATFORM_HOSTING.get(
|
|
19994
|
+
function hostingFor(platform) {
|
|
19995
|
+
return PLATFORM_HOSTING.get(platform) ?? "api";
|
|
20873
19996
|
}
|
|
20874
19997
|
var FIRST_PARTY = /* @__PURE__ */ new Map([
|
|
20875
19998
|
["anthropic", "anthropic"],
|
|
@@ -20883,8 +20006,8 @@ var FIRST_PARTY = /* @__PURE__ */ new Map([
|
|
|
20883
20006
|
function firstPartyPlatformFor(vendor2) {
|
|
20884
20007
|
return FIRST_PARTY.get(vendor2) ?? null;
|
|
20885
20008
|
}
|
|
20886
|
-
function isFirstParty(vendor2,
|
|
20887
|
-
return FIRST_PARTY.get(vendor2) ===
|
|
20009
|
+
function isFirstParty(vendor2, platform) {
|
|
20010
|
+
return FIRST_PARTY.get(vendor2) === platform;
|
|
20888
20011
|
}
|
|
20889
20012
|
var PLATFORM_NAMESPACES = Object.freeze([
|
|
20890
20013
|
"anthropic",
|
|
@@ -20945,14 +20068,14 @@ var ModelVendorBuilder = class {
|
|
|
20945
20068
|
);
|
|
20946
20069
|
}
|
|
20947
20070
|
for (const ref of spec.on ?? []) {
|
|
20948
|
-
const { platform
|
|
20949
|
-
const firstParty = isFirstParty(this.vendor,
|
|
20950
|
-
const hosting = hostingFor(
|
|
20071
|
+
const { platform, price, retention, region } = normalizeRef(ref);
|
|
20072
|
+
const firstParty = isFirstParty(this.vendor, platform);
|
|
20073
|
+
const hosting = hostingFor(platform);
|
|
20951
20074
|
const isSelfHosted = hosting === "local";
|
|
20952
20075
|
platforms.set(
|
|
20953
|
-
|
|
20076
|
+
platform,
|
|
20954
20077
|
Object.freeze({
|
|
20955
|
-
platform
|
|
20078
|
+
platform,
|
|
20956
20079
|
hosting,
|
|
20957
20080
|
firstParty,
|
|
20958
20081
|
price: price ?? (isSelfHosted ? ZERO_PRICE : firstParty ? spec.price ?? null : null),
|
|
@@ -21005,35 +20128,35 @@ var GATEWAY_VENDOR_SLASH_RE = /^[a-z0-9][\w.-]*\//iu;
|
|
|
21005
20128
|
var BEDROCK_VERSION_RE = /-v\d+:\d+$/u;
|
|
21006
20129
|
var BEDROCK_REVISION_RE = /:\d+$/u;
|
|
21007
20130
|
var VERTEX_VERSION_RE = /@[\w-]+$/u;
|
|
21008
|
-
var DATED_SUFFIX_RE =
|
|
20131
|
+
var DATED_SUFFIX_RE = /-(?:\d{8}|\d{4}-\d{2}-\d{2})$/u;
|
|
21009
20132
|
function stripPlatformDecorations(model) {
|
|
21010
20133
|
let id = model.trim();
|
|
21011
|
-
let
|
|
20134
|
+
let platform = null;
|
|
21012
20135
|
if (GEO_PREFIX_RE.test(id)) {
|
|
21013
20136
|
id = id.replace(GEO_PREFIX_RE, "");
|
|
21014
|
-
|
|
20137
|
+
platform = "bedrock";
|
|
21015
20138
|
}
|
|
21016
20139
|
if (NAMESPACE_DOT_RE.test(id)) {
|
|
21017
20140
|
id = id.replace(NAMESPACE_DOT_RE, "");
|
|
21018
|
-
|
|
20141
|
+
platform ??= "bedrock";
|
|
21019
20142
|
}
|
|
21020
20143
|
if (BEDROCK_VERSION_RE.test(id)) {
|
|
21021
20144
|
id = id.replace(BEDROCK_VERSION_RE, "");
|
|
21022
|
-
|
|
20145
|
+
platform ??= "bedrock";
|
|
21023
20146
|
} else if (BEDROCK_REVISION_RE.test(id)) {
|
|
21024
20147
|
id = id.replace(BEDROCK_REVISION_RE, "");
|
|
21025
|
-
|
|
20148
|
+
platform ??= "bedrock";
|
|
21026
20149
|
}
|
|
21027
20150
|
if (VERTEX_VERSION_RE.test(id)) {
|
|
21028
20151
|
id = id.replace(VERTEX_VERSION_RE, "");
|
|
21029
|
-
|
|
20152
|
+
platform ??= "vertex";
|
|
21030
20153
|
}
|
|
21031
20154
|
if (NAMESPACE_SLASH_RE.test(id)) {
|
|
21032
20155
|
id = id.replace(NAMESPACE_SLASH_RE, "");
|
|
21033
20156
|
} else if (GATEWAY_VENDOR_SLASH_RE.test(id)) {
|
|
21034
20157
|
id = id.replace(GATEWAY_VENDOR_SLASH_RE, "");
|
|
21035
20158
|
}
|
|
21036
|
-
return { id, platform
|
|
20159
|
+
return { id, platform };
|
|
21037
20160
|
}
|
|
21038
20161
|
function buildModelIndex(entries) {
|
|
21039
20162
|
const byId = /* @__PURE__ */ new Map();
|
|
@@ -21050,19 +20173,19 @@ function resolveModel(raw, index) {
|
|
|
21050
20173
|
if (exact !== void 0) {
|
|
21051
20174
|
return { entry: exact, canonicalId: raw, platform: null, raw };
|
|
21052
20175
|
}
|
|
21053
|
-
const { id, platform
|
|
20176
|
+
const { id, platform } = stripPlatformDecorations(raw);
|
|
21054
20177
|
const stripped = index.byId.get(id);
|
|
21055
20178
|
if (stripped !== void 0) {
|
|
21056
|
-
return { entry: stripped, canonicalId: id, platform
|
|
20179
|
+
return { entry: stripped, canonicalId: id, platform, raw };
|
|
21057
20180
|
}
|
|
21058
20181
|
if (DATED_SUFFIX_RE.test(id)) {
|
|
21059
20182
|
const undated = id.replace(DATED_SUFFIX_RE, "");
|
|
21060
20183
|
const byDate = index.byId.get(undated);
|
|
21061
20184
|
if (byDate !== void 0) {
|
|
21062
|
-
return { entry: byDate, canonicalId: undated, platform
|
|
20185
|
+
return { entry: byDate, canonicalId: undated, platform, raw };
|
|
21063
20186
|
}
|
|
21064
20187
|
}
|
|
21065
|
-
return { entry: null, canonicalId: raw, platform
|
|
20188
|
+
return { entry: null, canonicalId: raw, platform, raw };
|
|
21066
20189
|
}
|
|
21067
20190
|
|
|
21068
20191
|
// ../../packages/schema/src/model/catalog.ts
|
|
@@ -21155,7 +20278,7 @@ anthropic.model("claude-haiku-4-5", {
|
|
|
21155
20278
|
name: "Claude Haiku 4.5",
|
|
21156
20279
|
ctx: 2e5,
|
|
21157
20280
|
maxOut: 64e3,
|
|
21158
|
-
// Reviewed: fast/cheap tier,
|
|
20281
|
+
// Reviewed: fast/cheap general-purpose tier, not a reasoning or code model.
|
|
21159
20282
|
capability: null,
|
|
21160
20283
|
price: anthropicPrice(1, 5, 0.1),
|
|
21161
20284
|
// The vendor documents `claude-haiku-4-5-20251001` as the versioned id and
|
|
@@ -21286,6 +20409,11 @@ openai.model("gpt-4o", {
|
|
|
21286
20409
|
price: tokenPrice(2.5, 10, { cacheRead: 1.25 }),
|
|
21287
20410
|
on: [...OPENAI_RESELLERS]
|
|
21288
20411
|
});
|
|
20412
|
+
openai.model("gpt-4o-2024-05-13", {
|
|
20413
|
+
name: "GPT-4o (2024-05-13)",
|
|
20414
|
+
price: tokenPrice(5, 15),
|
|
20415
|
+
on: [...OPENAI_RESELLERS]
|
|
20416
|
+
});
|
|
21289
20417
|
openai.model("gpt-4o-mini", {
|
|
21290
20418
|
name: "GPT-4o mini",
|
|
21291
20419
|
price: tokenPrice(0.15, 0.6, { cacheRead: 0.075 }),
|
|
@@ -21305,6 +20433,24 @@ openai.model("o3", {
|
|
|
21305
20433
|
price: tokenPrice(2, 8, { cacheRead: 0.5 }),
|
|
21306
20434
|
on: [...OPENAI_RESELLERS]
|
|
21307
20435
|
});
|
|
20436
|
+
openai.model("text-embedding-3-small", {
|
|
20437
|
+
name: "text-embedding-3-small",
|
|
20438
|
+
capability: "embedding",
|
|
20439
|
+
price: tokenPrice(0.02, 0),
|
|
20440
|
+
on: [...OPENAI_RESELLERS]
|
|
20441
|
+
});
|
|
20442
|
+
openai.model("text-embedding-3-large", {
|
|
20443
|
+
name: "text-embedding-3-large",
|
|
20444
|
+
capability: "embedding",
|
|
20445
|
+
price: tokenPrice(0.13, 0),
|
|
20446
|
+
on: [...OPENAI_RESELLERS]
|
|
20447
|
+
});
|
|
20448
|
+
openai.model("text-embedding-ada-002", {
|
|
20449
|
+
name: "text-embedding-ada-002",
|
|
20450
|
+
capability: "embedding",
|
|
20451
|
+
price: tokenPrice(0.1, 0),
|
|
20452
|
+
on: [...OPENAI_RESELLERS]
|
|
20453
|
+
});
|
|
21308
20454
|
openai.model("gpt-oss-120b", {
|
|
21309
20455
|
name: "GPT-OSS 120B",
|
|
21310
20456
|
openWeights: true,
|
|
@@ -21591,10 +20737,21 @@ var MODEL_ENTRIES = Object.freeze([
|
|
|
21591
20737
|
...alibaba.models(),
|
|
21592
20738
|
...amazon.models()
|
|
21593
20739
|
]);
|
|
20740
|
+
var LONG_CONTEXT_THRESHOLDS = Object.freeze(
|
|
20741
|
+
[
|
|
20742
|
+
...new Set(
|
|
20743
|
+
MODEL_ENTRIES.flatMap(
|
|
20744
|
+
(entry) => [...entry.platforms.values()].flatMap(
|
|
20745
|
+
(offering) => offering.price?.longContext ? [offering.price.longContext.thresholdInputTokens] : []
|
|
20746
|
+
)
|
|
20747
|
+
)
|
|
20748
|
+
)
|
|
20749
|
+
].sort((a, b) => a - b)
|
|
20750
|
+
);
|
|
21594
20751
|
var MODEL_INDEX = buildModelIndex(MODEL_ENTRIES);
|
|
21595
20752
|
|
|
21596
20753
|
// ../../packages/schema/src/model/governance.ts
|
|
21597
|
-
var ModelCapability = external_exports.enum(["reasoning", "code"]);
|
|
20754
|
+
var ModelCapability = external_exports.enum(["reasoning", "code", "embedding"]);
|
|
21598
20755
|
var DataRetention = external_exports.enum([
|
|
21599
20756
|
"zero_retention",
|
|
21600
20757
|
"no_storage",
|
|
@@ -21784,16 +20941,16 @@ function platformForProvider(provider) {
|
|
|
21784
20941
|
return PROVIDER_PLATFORM.get(provider.trim().toLowerCase()) ?? null;
|
|
21785
20942
|
}
|
|
21786
20943
|
function isLocalProvider(provider) {
|
|
21787
|
-
const
|
|
21788
|
-
return
|
|
20944
|
+
const platform = platformForProvider(provider);
|
|
20945
|
+
return platform !== null && hostingFor(platform) === "local";
|
|
21789
20946
|
}
|
|
21790
20947
|
function priceFor(provider, model) {
|
|
21791
20948
|
if (isLocalProvider(provider)) return ZERO_PRICE;
|
|
21792
20949
|
const resolved = resolveModel(model, MODEL_INDEX);
|
|
21793
20950
|
if (resolved.entry === null) return null;
|
|
21794
|
-
const
|
|
21795
|
-
if (
|
|
21796
|
-
return resolved.entry.platforms.get(
|
|
20951
|
+
const platform = resolved.platform ?? platformForProvider(provider);
|
|
20952
|
+
if (platform === null) return null;
|
|
20953
|
+
return resolved.entry.platforms.get(platform)?.price ?? null;
|
|
21797
20954
|
}
|
|
21798
20955
|
var defaultCostModel = {
|
|
21799
20956
|
normalizeModelId(provider, model) {
|
|
@@ -21825,7 +20982,7 @@ function formatCostTotal(estimatedCostUsd, costIsPartial) {
|
|
|
21825
20982
|
|
|
21826
20983
|
// ../../packages/schema/src/token/token-report.ts
|
|
21827
20984
|
var num = (value) => value ?? 0;
|
|
21828
|
-
function costUsageOf(a) {
|
|
20985
|
+
function costUsageOf(a, promptTokens) {
|
|
21829
20986
|
const usage = {
|
|
21830
20987
|
inputTokens: num(a.input_tokens),
|
|
21831
20988
|
outputTokens: num(a.output_tokens),
|
|
@@ -21835,11 +20992,12 @@ function costUsageOf(a) {
|
|
|
21835
20992
|
webSearchRequests: num(a.web_search_requests)
|
|
21836
20993
|
};
|
|
21837
20994
|
if (a.service_tier !== void 0) usage.serviceTier = a.service_tier;
|
|
20995
|
+
if (promptTokens !== void 0) usage.promptTokens = promptTokens;
|
|
21838
20996
|
return usage;
|
|
21839
20997
|
}
|
|
21840
20998
|
function buildTokenReports(leaves, costModel) {
|
|
21841
20999
|
const bySession = /* @__PURE__ */ new Map();
|
|
21842
|
-
for (const { sessionId, attributes } of leaves) {
|
|
21000
|
+
for (const { sessionId, attributes, promptTokens } of leaves) {
|
|
21843
21001
|
const provider = attributes.provider ?? "unknown";
|
|
21844
21002
|
const model = attributes.model ?? "unknown";
|
|
21845
21003
|
const key = `${provider} ${model}`;
|
|
@@ -21858,7 +21016,8 @@ function buildTokenReports(leaves, costModel) {
|
|
|
21858
21016
|
cacheCreation: 0,
|
|
21859
21017
|
cacheRead: 0,
|
|
21860
21018
|
costUsd: 0,
|
|
21861
|
-
priced: false
|
|
21019
|
+
priced: false,
|
|
21020
|
+
partial: false
|
|
21862
21021
|
};
|
|
21863
21022
|
rollups.set(key, acc);
|
|
21864
21023
|
}
|
|
@@ -21866,8 +21025,14 @@ function buildTokenReports(leaves, costModel) {
|
|
|
21866
21025
|
acc.output += num(attributes.output_tokens);
|
|
21867
21026
|
acc.cacheCreation += num(attributes.cache_creation_input_tokens);
|
|
21868
21027
|
acc.cacheRead += num(attributes.cache_read_input_tokens);
|
|
21869
|
-
const leafCost = costModel.costFor({
|
|
21870
|
-
|
|
21028
|
+
const leafCost = costModel.costFor({
|
|
21029
|
+
provider,
|
|
21030
|
+
model,
|
|
21031
|
+
usage: costUsageOf(attributes, promptTokens)
|
|
21032
|
+
});
|
|
21033
|
+
if (leafCost === null) {
|
|
21034
|
+
acc.partial = true;
|
|
21035
|
+
} else {
|
|
21871
21036
|
acc.costUsd += leafCost;
|
|
21872
21037
|
acc.priced = true;
|
|
21873
21038
|
}
|
|
@@ -21883,9 +21048,8 @@ function buildTokenReports(leaves, costModel) {
|
|
|
21883
21048
|
const rollupTotal = acc.input + acc.output + acc.cacheCreation + acc.cacheRead;
|
|
21884
21049
|
totalTokens += rollupTotal;
|
|
21885
21050
|
const estimatedCostUsd = acc.priced ? acc.costUsd : null;
|
|
21886
|
-
if (
|
|
21887
|
-
|
|
21888
|
-
} else {
|
|
21051
|
+
if (acc.partial) anyUnpriced = true;
|
|
21052
|
+
if (estimatedCostUsd !== null) {
|
|
21889
21053
|
anyPriced = true;
|
|
21890
21054
|
costUsd += estimatedCostUsd;
|
|
21891
21055
|
}
|
|
@@ -21908,7 +21072,7 @@ function buildTokenReports(leaves, costModel) {
|
|
|
21908
21072
|
totalTokens,
|
|
21909
21073
|
// Σ of the PRICED rollups; null when none had a known price.
|
|
21910
21074
|
estimatedCostUsd: anyPriced ? costUsd : null,
|
|
21911
|
-
// Any
|
|
21075
|
+
// Any call priced to null means the total understates real spend.
|
|
21912
21076
|
costIsPartial: anyUnpriced
|
|
21913
21077
|
});
|
|
21914
21078
|
}
|
|
@@ -22841,8 +22005,9 @@ var SessionTokenReport = external_exports.object({
|
|
|
22841
22005
|
totalTokens: external_exports.number().int().nonnegative(),
|
|
22842
22006
|
// Σ of the PRICED rollups only; null when no rollup had a known price.
|
|
22843
22007
|
estimatedCostUsd: external_exports.number().nullable(),
|
|
22844
|
-
// True whenever any
|
|
22845
|
-
//
|
|
22008
|
+
// True whenever any call priced to null (an unknown provider/model, or a call
|
|
22009
|
+
// over a long-context threshold whose rate is unpublished), so the total
|
|
22010
|
+
// understates real spend — the UI renders `≥ $X` instead of a falsely
|
|
22846
22011
|
// precise figure rather than silently dropping the unpriced calls.
|
|
22847
22012
|
costIsPartial: external_exports.boolean()
|
|
22848
22013
|
});
|
|
@@ -23719,7 +22884,15 @@ var StorePostureSnapshot = external_exports.object({
|
|
|
23719
22884
|
policyCounts: StorePosturePolicyCounts,
|
|
23720
22885
|
// OPTIONAL, not nullable: a reporter that predates this member keeps
|
|
23721
22886
|
// getting its 200 without a payload change.
|
|
23722
|
-
plugin: StorePosturePlugin.optional()
|
|
22887
|
+
plugin: StorePosturePlugin.optional(),
|
|
22888
|
+
// OPTIONAL, and sent only by a scoped attachment, always as `scoped`. A
|
|
22889
|
+
// machine attachment omits it, so its body is byte for byte the one it
|
|
22890
|
+
// sent before this member existed. Absent therefore means machine-wide OR
|
|
22891
|
+
// a reporter older than this member, never "scoped". Both values parse, so
|
|
22892
|
+
// a sender that one day spells `machine` breaks no receiver; any other
|
|
22893
|
+
// value fails the whole snapshot, which is why the reporter sends a
|
|
22894
|
+
// constant and never the raw mode.
|
|
22895
|
+
attachmentMode: AttachmentMode.optional()
|
|
23723
22896
|
}).meta({ id: "StorePostureSnapshot" });
|
|
23724
22897
|
var CAPTURE_VERSION_PREFIX = "capture/";
|
|
23725
22898
|
var RecordAuditEventRequest = AuditEventInput.extend({
|
|
@@ -24166,7 +23339,7 @@ var Rule = external_exports.strictObject({
|
|
|
24166
23339
|
postValidators: external_exports.array(PostValidatorRef).optional(),
|
|
24167
23340
|
requiresNearby: RequiresNearby.optional(),
|
|
24168
23341
|
examples: external_exports.array(external_exports.string()).optional(),
|
|
24169
|
-
// Whether the matched text is itself sensitive
|
|
23342
|
+
// Whether the matched text is itself sensitive (see RuleEvidence).
|
|
24170
23343
|
evidence: RuleEvidence.optional()
|
|
24171
23344
|
}).meta({ id: "Rule" });
|
|
24172
23345
|
var Author = external_exports.object({
|
|
@@ -24258,7 +23431,13 @@ var DetectionRule = external_exports.object({
|
|
|
24258
23431
|
// Representative matching strings the rule author shipped with the rule. The
|
|
24259
23432
|
// cheapest honest answer to "show me what this rule catches" — every bundled
|
|
24260
23433
|
// rule has them, and they are already in the stored snapshot.
|
|
24261
|
-
examples: external_exports.array(external_exports.string()).optional()
|
|
23434
|
+
examples: external_exports.array(external_exports.string()).optional(),
|
|
23435
|
+
// The rule's DECLARED evidence, as stored. Absent defers to the engine's
|
|
23436
|
+
// classification (ruleEvidence in @akasecurity/detections): a bundled
|
|
23437
|
+
// code-flaw rule reads as 'code' and anything else as 'value', and a rule
|
|
23438
|
+
// in a value category (secret/pii/financial/phi) is always 'value',
|
|
23439
|
+
// whatever it declares.
|
|
23440
|
+
evidence: RuleEvidence.optional()
|
|
24262
23441
|
}).meta({ id: "DetectionRule" });
|
|
24263
23442
|
var DetectionUpdate = external_exports.object({
|
|
24264
23443
|
available: external_exports.boolean(),
|
|
@@ -24326,8 +23505,10 @@ var ImportDetectionRequest = external_exports.object({
|
|
|
24326
23505
|
}).meta({ id: "ImportDetectionRequest" });
|
|
24327
23506
|
|
|
24328
23507
|
// ../../packages/schema/src/zod/detection-build.ts
|
|
24329
|
-
function optional2(key,
|
|
24330
|
-
if (raw === void 0
|
|
23508
|
+
function optional2(key, raw, parse4) {
|
|
23509
|
+
if (raw === void 0) return {};
|
|
23510
|
+
const parsed2 = parse4(raw);
|
|
23511
|
+
if (!parsed2.success || parsed2.data === void 0) return {};
|
|
24331
23512
|
return { [key]: parsed2.data };
|
|
24332
23513
|
}
|
|
24333
23514
|
function isStringArray(value) {
|
|
@@ -24362,10 +23543,12 @@ function rowToDetectionDetail(row, findingsLast30d, update) {
|
|
|
24362
23543
|
category: r.category,
|
|
24363
23544
|
severity: r.severity,
|
|
24364
23545
|
matcher: parsed2.data,
|
|
24365
|
-
//
|
|
24366
|
-
//
|
|
24367
|
-
//
|
|
24368
|
-
//
|
|
23546
|
+
// `appliesTo`, `postValidators` and `requiresNearby` are the rest of what
|
|
23547
|
+
// decides whether this rule fires. Carried so a consumer re-running the
|
|
23548
|
+
// rule (a preview, a tester) evaluates what the engine evaluates rather
|
|
23549
|
+
// than a matcher stripped of its guards — half the bundled catalog
|
|
23550
|
+
// carries at least one of these. `examples` and `evidence` describe the
|
|
23551
|
+
// rule and never gate a match.
|
|
24369
23552
|
//
|
|
24370
23553
|
// Enrichment is deliberately per-field and best-effort, NOT a whole-rule
|
|
24371
23554
|
// `Rule.safeParse`. Two reasons: `Rule` is a strict object pinned to
|
|
@@ -24375,18 +23558,19 @@ function rowToDetectionDetail(row, findingsLast30d, update) {
|
|
|
24375
23558
|
// test should stay exactly what it was, namely a renderable matcher. A
|
|
24376
23559
|
// field that fails validation is omitted, which reads as "not set" and is
|
|
24377
23560
|
// the same thing the consumer saw before this change.
|
|
24378
|
-
...optional2("appliesTo",
|
|
23561
|
+
...optional2("appliesTo", r.appliesTo, (v) => AppliesTo.safeParse(v)),
|
|
24379
23562
|
...optional2(
|
|
24380
23563
|
"postValidators",
|
|
24381
|
-
|
|
24382
|
-
|
|
23564
|
+
r.postValidators,
|
|
23565
|
+
(v) => PostValidatorRef.array().safeParse(v)
|
|
24383
23566
|
),
|
|
24384
|
-
...optional2("requiresNearby",
|
|
23567
|
+
...optional2("requiresNearby", r.requiresNearby, (v) => RequiresNearby.safeParse(v)),
|
|
24385
23568
|
...optional2(
|
|
24386
23569
|
"examples",
|
|
24387
|
-
|
|
24388
|
-
|
|
24389
|
-
)
|
|
23570
|
+
r.examples,
|
|
23571
|
+
(v) => isStringArray(v) ? { success: true, data: v } : { success: false }
|
|
23572
|
+
),
|
|
23573
|
+
...optional2("evidence", r.evidence, (v) => RuleEvidence.safeParse(v))
|
|
24390
23574
|
}
|
|
24391
23575
|
];
|
|
24392
23576
|
});
|
|
@@ -25079,11 +24263,14 @@ var PolicyBundle = external_exports.object({
|
|
|
25079
24263
|
ruleVersions: external_exports.record(external_exports.string(), external_exports.string()).optional(),
|
|
25080
24264
|
// Model ids (the raw `model` string a harness reports, e.g.
|
|
25081
24265
|
// `claude-opus-4-1`) the tenant has PROHIBITED. The plugin refuses to switch
|
|
25082
|
-
// a session onto one (PreModelSwitch)
|
|
25083
|
-
//
|
|
25084
|
-
//
|
|
25085
|
-
//
|
|
25086
|
-
//
|
|
24266
|
+
// a session onto one (PreModelSwitch), refuses a turn that would run on one
|
|
24267
|
+
// (UserPromptSubmit) and refuses a subagent spawn onto one (PreToolUse),
|
|
24268
|
+
// wherever the organization governs the event: everywhere on a
|
|
24269
|
+
// machine-wide attachment, and only in enrolled repositories on a scoped
|
|
24270
|
+
// one (the plugin runtime's `governanceApplies`).
|
|
24271
|
+
// Optional so an older backend — and an older on-disk cache — still
|
|
24272
|
+
// parses; consumers read `?? []`, which is the unenforced behaviour that
|
|
24273
|
+
// predates this field and the safe direction to default.
|
|
25087
24274
|
//
|
|
25088
24275
|
// Ids, not display names: the governance decision is keyed on the exact
|
|
25089
24276
|
// string the harness reports (`model_status_override.versionId` in the
|
|
@@ -25539,6 +24726,8 @@ var AttachmentScopeEntry = external_exports.object({
|
|
|
25539
24726
|
});
|
|
25540
24727
|
var AttachmentScope = external_exports.object({
|
|
25541
24728
|
endpoint: external_exports.string().min(1),
|
|
24729
|
+
tenantName: PluginWhoami.shape.tenantName.optional(),
|
|
24730
|
+
userEmail: PluginWhoami.shape.userEmail.optional(),
|
|
25542
24731
|
entries: external_exports.array(AttachmentScopeEntry)
|
|
25543
24732
|
});
|
|
25544
24733
|
var AttachmentScopeEnvelope = AttachmentScope.extend({ entries: external_exports.array(external_exports.unknown()) });
|
|
@@ -25551,7 +24740,13 @@ function parseAttachmentScope(raw) {
|
|
|
25551
24740
|
const entry = AttachmentScopeEntry.safeParse(candidate);
|
|
25552
24741
|
if (entry.success) entries.push(entry.data);
|
|
25553
24742
|
}
|
|
25554
|
-
|
|
24743
|
+
const { endpoint, tenantName, userEmail } = envelope.data;
|
|
24744
|
+
return {
|
|
24745
|
+
endpoint,
|
|
24746
|
+
...tenantName === void 0 ? {} : { tenantName },
|
|
24747
|
+
...userEmail === void 0 ? {} : { userEmail },
|
|
24748
|
+
entries
|
|
24749
|
+
};
|
|
25555
24750
|
} catch {
|
|
25556
24751
|
return void 0;
|
|
25557
24752
|
}
|
|
@@ -25923,6 +25118,27 @@ var ManagedSettings = external_exports.object({
|
|
|
25923
25118
|
};
|
|
25924
25119
|
}).meta({ id: "ManagedSettings" });
|
|
25925
25120
|
|
|
25121
|
+
// ../../packages/schema/src/zod/mod-policy-snapshot.ts
|
|
25122
|
+
var MOD_POLICY_SNAPSHOT_VERSION = 1;
|
|
25123
|
+
var MOD_POLICY_SNAPSHOT_MAX_BYTES = 4 * 1024 * 1024;
|
|
25124
|
+
var ModPolicySnapshot = external_exports.object({
|
|
25125
|
+
version: external_exports.literal(MOD_POLICY_SNAPSHOT_VERSION),
|
|
25126
|
+
generatedAt: external_exports.iso.datetime(),
|
|
25127
|
+
// The complete effective ruleset, as the hook's runtime scans with it: the
|
|
25128
|
+
// user's enabled installed packs (user-modified and custom packs included).
|
|
25129
|
+
// Absent means the store holds no authoritative snapshot, and the reader
|
|
25130
|
+
// scans with the packs it ships — the hook's own fallback.
|
|
25131
|
+
rules: external_exports.array(Rule).optional(),
|
|
25132
|
+
// Rule-targeted actions (first enabled policy per rule wins).
|
|
25133
|
+
ruleActions: external_exports.record(external_exports.string(), ActionTaken),
|
|
25134
|
+
// The resolved action per detection category.
|
|
25135
|
+
categoryActions: external_exports.record(external_exports.string(), ActionTaken),
|
|
25136
|
+
// Rules with an active exception grant. Honouring a grant means matching a
|
|
25137
|
+
// keyed fingerprint of the value and consuming a use, which only the hook can
|
|
25138
|
+
// do, so the mod leaves a finding of one of these rules for the hook to decide.
|
|
25139
|
+
exceptionRuleIds: external_exports.array(external_exports.string())
|
|
25140
|
+
}).meta({ id: "ModPolicySnapshot" });
|
|
25141
|
+
|
|
25926
25142
|
// ../../packages/schema/src/zod/project-files.ts
|
|
25927
25143
|
var ProjectFileInput = external_exports.object({
|
|
25928
25144
|
path: external_exports.string().min(1),
|
|
@@ -26243,7 +25459,16 @@ var AttachInput = external_exports.object({
|
|
|
26243
25459
|
// 200 matches the tenantName bound beside it in control-plane.ts; nothing
|
|
26244
25460
|
// renders a longer one usefully.
|
|
26245
25461
|
label: printable(200).optional(),
|
|
26246
|
-
accessKey: external_exports.string()
|
|
25462
|
+
accessKey: external_exports.string(),
|
|
25463
|
+
// How much of this machine the attachment is for: everything, or only the
|
|
25464
|
+
// repositories its user enrolls. Optional, so an input without it still
|
|
25465
|
+
// parses; what an absent mode means is for whatever reads it to decide, not
|
|
25466
|
+
// this shape. This member validates the VALUE rather than leaving that to the
|
|
25467
|
+
// call site, a deliberate exception to this module's shape-only rule: a shape
|
|
25468
|
+
// rejection names the field, so a value that is not a mode is refused as a bad
|
|
25469
|
+
// `mode` rather than stripped or passed on. The dashboard's attach action reads
|
|
25470
|
+
// it as the mode to attach in.
|
|
25471
|
+
mode: AttachmentMode.optional()
|
|
26247
25472
|
});
|
|
26248
25473
|
|
|
26249
25474
|
// ../../packages/schema/src/zod/triage.ts
|
|
@@ -26529,6 +25754,18 @@ function fromCaptureStatusAttributes(bag) {
|
|
|
26529
25754
|
return parsedStatus.success ? parsedStatus.data : null;
|
|
26530
25755
|
}
|
|
26531
25756
|
|
|
25757
|
+
// ../../packages/persistence/src/attached-derived.ts
|
|
25758
|
+
import { rmSync } from "fs";
|
|
25759
|
+
import { join } from "path";
|
|
25760
|
+
var POLICY_CACHE_FILENAME = "policy-cache.json";
|
|
25761
|
+
var ATTACHED_FORWARD_STATE_FILENAME = "attached-state.json";
|
|
25762
|
+
var ATTACHED_FORWARD_DROPS_FILENAME = "attached-forward-drops.json";
|
|
25763
|
+
var ATTACHED_POSTURE_REPORT_FILENAME = "attached-posture-report.json";
|
|
25764
|
+
|
|
25765
|
+
// ../../packages/persistence/src/control-plane-credential.ts
|
|
25766
|
+
import { chmodSync as chmodSync2, lstatSync as lstatSync2, readFileSync, rmSync as rmSync3, statSync } from "fs";
|
|
25767
|
+
import { join as join2 } from "path";
|
|
25768
|
+
|
|
26532
25769
|
// ../../packages/persistence/src/paths.ts
|
|
26533
25770
|
import {
|
|
26534
25771
|
chmodSync,
|
|
@@ -26655,6 +25892,14 @@ function repairOrRefuseMode(file2) {
|
|
|
26655
25892
|
}
|
|
26656
25893
|
return "ok";
|
|
26657
25894
|
}
|
|
25895
|
+
function asReadableCredential(value) {
|
|
25896
|
+
const result = AttachedCredentialAny.safeParse(value);
|
|
25897
|
+
if (!result.success) return null;
|
|
25898
|
+
if (attachmentModeOf(result.data) === "machine" && typeof value === "object" && value !== null && Object.hasOwn(value, "mode")) {
|
|
25899
|
+
return null;
|
|
25900
|
+
}
|
|
25901
|
+
return result.data;
|
|
25902
|
+
}
|
|
26658
25903
|
function readControlPlaneCredentialFile(settingsDir2, connection) {
|
|
26659
25904
|
const file2 = controlPlaneCredentialPath(settingsDir2);
|
|
26660
25905
|
let raw;
|
|
@@ -26673,20 +25918,20 @@ function readControlPlaneCredentialFile(settingsDir2, connection) {
|
|
|
26673
25918
|
} catch {
|
|
26674
25919
|
return { usable: false, reason: "malformed" };
|
|
26675
25920
|
}
|
|
26676
|
-
const
|
|
26677
|
-
if (
|
|
26678
|
-
if (!isSafeEndpoint(
|
|
25921
|
+
const credential = asReadableCredential(parsed2);
|
|
25922
|
+
if (credential === null) return { usable: false, reason: "malformed" };
|
|
25923
|
+
if (!isSafeEndpoint(credential.endpoint)) {
|
|
26679
25924
|
return { usable: false, reason: "unsafe-endpoint" };
|
|
26680
25925
|
}
|
|
26681
|
-
if (connection !== void 0 && connection.endpoint !==
|
|
25926
|
+
if (connection !== void 0 && connection.endpoint !== credential.endpoint) {
|
|
26682
25927
|
return {
|
|
26683
25928
|
usable: false,
|
|
26684
25929
|
reason: "endpoint-mismatch",
|
|
26685
|
-
credentialEndpoint:
|
|
25930
|
+
credentialEndpoint: credential.endpoint,
|
|
26686
25931
|
settingsEndpoint: connection.endpoint
|
|
26687
25932
|
};
|
|
26688
25933
|
}
|
|
26689
|
-
return { usable: true, credential
|
|
25934
|
+
return { usable: true, credential };
|
|
26690
25935
|
}
|
|
26691
25936
|
function readControlPlaneCredential(settingsDir2, connection) {
|
|
26692
25937
|
const read = readControlPlaneCredentialFile(settingsDir2, connection);
|
|
@@ -26695,7 +25940,7 @@ function readControlPlaneCredential(settingsDir2, connection) {
|
|
|
26695
25940
|
|
|
26696
25941
|
// ../../packages/persistence/src/database.ts
|
|
26697
25942
|
import { randomUUID as randomUUID11 } from "crypto";
|
|
26698
|
-
import { dirname as dirname2, join as
|
|
25943
|
+
import { dirname as dirname2, join as join8, sep } from "path";
|
|
26699
25944
|
import { DatabaseSync } from "node:sqlite";
|
|
26700
25945
|
|
|
26701
25946
|
// ../../packages/persistence/src/ids.ts
|
|
@@ -26739,6 +25984,7 @@ function captureId(sessionId, contentHash, filePath = null) {
|
|
|
26739
25984
|
canonicalIdentity(["capture", sessionId ?? NO_SESSION, contentHash, filePath ?? NO_PATH])
|
|
26740
25985
|
);
|
|
26741
25986
|
}
|
|
25987
|
+
var DOT = ".".charCodeAt(0);
|
|
26742
25988
|
|
|
26743
25989
|
// ../../packages/persistence/src/internal/snapshot.ts
|
|
26744
25990
|
import { randomUUID } from "crypto";
|
|
@@ -27066,6 +26312,25 @@ function scopeKeysParam(scopeKeys) {
|
|
|
27066
26312
|
var ROOT_SCOPE_KEY = `(SELECT session_root.scope_key
|
|
27067
26313
|
FROM audit_events AS session_root
|
|
27068
26314
|
WHERE session_root.id = COALESCE(audit_events.root_session_id, audit_events.id))`;
|
|
26315
|
+
var COUNTED_IN_SCOPE = `
|
|
26316
|
+
AND ${inScope("scope_key")}
|
|
26317
|
+
AND (event_type IN (${CAPTURE_TYPE_LIST}) OR ${inScope(ROOT_SCOPE_KEY)})`;
|
|
26318
|
+
var DRAIN_TOTALS = `SELECT
|
|
26319
|
+
SUM(CASE WHEN synced_at IS NULL AND started_at < :before THEN 1 ELSE 0 END) AS pending,
|
|
26320
|
+
SUM(CASE WHEN synced_at > 0 THEN 1 ELSE 0 END) AS sent,
|
|
26321
|
+
SUM(CASE WHEN synced_at = ${String(SKIPPED)}
|
|
26322
|
+
AND (sync_failure IS NULL OR sync_failure = 'payload_invalid')
|
|
26323
|
+
THEN 1 ELSE 0 END) AS skipped,
|
|
26324
|
+
SUM(CASE WHEN synced_at = ${String(SKIPPED)}
|
|
26325
|
+
AND sync_failure = 'deployment_refused' THEN 1 ELSE 0 END) AS refused,
|
|
26326
|
+
SUM(CASE WHEN synced_at = ${String(SKIPPED)}
|
|
26327
|
+
AND sync_failure = 'detached_undelivered' THEN 1 ELSE 0 END) AS detached
|
|
26328
|
+
FROM audit_events
|
|
26329
|
+
WHERE event_type IN (${TYPE_LIST})`;
|
|
26330
|
+
var CAPTURE_SKIPS = `SELECT COUNT(*) AS skipped
|
|
26331
|
+
FROM audit_events
|
|
26332
|
+
WHERE synced_at = ${String(SKIPPED)}
|
|
26333
|
+
AND event_type IN (${CAPTURE_TYPE_LIST})`;
|
|
27069
26334
|
var ROW_COLUMNS = `id,
|
|
27070
26335
|
parent_id AS parentId,
|
|
27071
26336
|
root_session_id AS rootSessionId,
|
|
@@ -27141,7 +26406,7 @@ var SqliteHistorySyncRepository = class {
|
|
|
27141
26406
|
);
|
|
27142
26407
|
this.scopedCaptureRowsStmt = db.prepare(
|
|
27143
26408
|
`SELECT ${ROW_COLUMNS}
|
|
27144
|
-
FROM audit_events
|
|
26409
|
+
FROM audit_events INDEXED BY idx_audit_scope_owed
|
|
27145
26410
|
WHERE synced_at IS NULL
|
|
27146
26411
|
AND sync_claimed_at IS NULL
|
|
27147
26412
|
AND outbox_owed = 1
|
|
@@ -27194,40 +26459,28 @@ var SqliteHistorySyncRepository = class {
|
|
|
27194
26459
|
);
|
|
27195
26460
|
this.partitionStmt = db.prepare(`SELECT${PARTITION_BUCKETS}
|
|
27196
26461
|
FROM audit_events${COUNTED_SCOPE}`);
|
|
26462
|
+
this.scopedPartitionStmt = db.prepare(`SELECT${PARTITION_BUCKETS}
|
|
26463
|
+
FROM audit_events${COUNTED_SCOPE}${COUNTED_IN_SCOPE}`);
|
|
27197
26464
|
this.partitionByKindStmt = db.prepare(
|
|
27198
26465
|
`SELECT event_type AS kind,${PARTITION_BUCKETS}
|
|
27199
26466
|
FROM audit_events INDEXED BY idx_audit_events_sync${COUNTED_SCOPE}
|
|
27200
26467
|
GROUP BY event_type`
|
|
27201
26468
|
);
|
|
27202
|
-
this.
|
|
27203
|
-
`SELECT
|
|
27204
|
-
|
|
27205
|
-
|
|
27206
|
-
SUM(CASE WHEN synced_at = ${String(SKIPPED)}
|
|
27207
|
-
AND (sync_failure IS NULL OR sync_failure = 'payload_invalid')
|
|
27208
|
-
THEN 1 ELSE 0 END) AS skipped,
|
|
27209
|
-
SUM(CASE WHEN synced_at = ${String(SKIPPED)}
|
|
27210
|
-
AND sync_failure = 'deployment_refused' THEN 1 ELSE 0 END) AS refused,
|
|
27211
|
-
SUM(CASE WHEN synced_at = ${String(SKIPPED)}
|
|
27212
|
-
AND sync_failure = 'detached_undelivered' THEN 1 ELSE 0 END) AS detached
|
|
27213
|
-
FROM audit_events
|
|
27214
|
-
WHERE event_type IN (${TYPE_LIST})`
|
|
26469
|
+
this.scopedPartitionByKindStmt = db.prepare(
|
|
26470
|
+
`SELECT event_type AS kind,${PARTITION_BUCKETS}
|
|
26471
|
+
FROM audit_events INDEXED BY idx_audit_events_sync${COUNTED_SCOPE}${COUNTED_IN_SCOPE}
|
|
26472
|
+
GROUP BY event_type`
|
|
27215
26473
|
);
|
|
27216
|
-
this.
|
|
27217
|
-
|
|
27218
|
-
|
|
27219
|
-
|
|
27220
|
-
|
|
27221
|
-
|
|
27222
|
-
|
|
27223
|
-
|
|
27224
|
-
|
|
27225
|
-
|
|
27226
|
-
// frees.
|
|
27227
|
-
`SELECT COUNT(*) AS skipped
|
|
27228
|
-
FROM audit_events
|
|
27229
|
-
WHERE synced_at = ${String(SKIPPED)}
|
|
27230
|
-
AND event_type IN (${CAPTURE_TYPE_LIST})`
|
|
26474
|
+
this.countsStmt = db.prepare(DRAIN_TOTALS);
|
|
26475
|
+
this.scopedCountsStmt = db.prepare(
|
|
26476
|
+
`${DRAIN_TOTALS}
|
|
26477
|
+
AND ${inScope("scope_key")}
|
|
26478
|
+
AND ${inScope(ROOT_SCOPE_KEY)}`
|
|
26479
|
+
);
|
|
26480
|
+
this.captureSkipCountStmt = db.prepare(CAPTURE_SKIPS);
|
|
26481
|
+
this.scopedCaptureSkipCountStmt = db.prepare(
|
|
26482
|
+
`${CAPTURE_SKIPS}
|
|
26483
|
+
AND ${inScope("scope_key")}`
|
|
27231
26484
|
);
|
|
27232
26485
|
this.fingerprintStmt = db.prepare(
|
|
27233
26486
|
`SELECT endpoint_fingerprint AS fingerprint, backlog_before AS backlogBefore
|
|
@@ -27341,6 +26594,10 @@ var SqliteHistorySyncRepository = class {
|
|
|
27341
26594
|
scopedCaptureRowsStmt;
|
|
27342
26595
|
scopedCaptureBacklogOwedStmt;
|
|
27343
26596
|
markScopeCapturesOwedStmt;
|
|
26597
|
+
scopedPartitionStmt;
|
|
26598
|
+
scopedPartitionByKindStmt;
|
|
26599
|
+
scopedCountsStmt;
|
|
26600
|
+
scopedCaptureSkipCountStmt;
|
|
27344
26601
|
/**
|
|
27345
26602
|
* The masked detections recorded against one tool call.
|
|
27346
26603
|
*
|
|
@@ -27562,7 +26819,29 @@ var SqliteHistorySyncRepository = class {
|
|
|
27562
26819
|
* in" — and a machine that has never attached has no boundary to pass, so
|
|
27563
26820
|
* requiring one would force a caller to invent one and report the whole store
|
|
27564
26821
|
* as queued.
|
|
26822
|
+
*
|
|
26823
|
+
* `scopeKeys` is a scoped attachment's filter: every bucket then counts only
|
|
26824
|
+
* the rows that pass the drain's reachability rule for that scope
|
|
26825
|
+
* (COUNTED_IN_SCOPE, which also names the one kind of row it counts that the
|
|
26826
|
+
* drain never offers), so a personal repository's rows are in none of them.
|
|
26827
|
+
* Omitted, this runs the machine statement, unchanged; an empty list counts
|
|
26828
|
+
* nothing.
|
|
27565
26829
|
*/
|
|
26830
|
+
partition(scopeKeys) {
|
|
26831
|
+
const row = getRow(
|
|
26832
|
+
scopeKeys === void 0 ? this.partitionStmt : this.scopedPartitionStmt,
|
|
26833
|
+
scopeKeys === void 0 ? {} : { scopeKeys: scopeKeysParam(scopeKeys) }
|
|
26834
|
+
);
|
|
26835
|
+
return {
|
|
26836
|
+
queued: row?.queued ?? 0,
|
|
26837
|
+
inProgress: row?.inProgress ?? 0,
|
|
26838
|
+
synced: row?.synced ?? 0,
|
|
26839
|
+
failed: row?.failed ?? 0,
|
|
26840
|
+
refused: row?.refused ?? 0,
|
|
26841
|
+
detached: row?.detached ?? 0,
|
|
26842
|
+
total: row?.total ?? 0
|
|
26843
|
+
};
|
|
26844
|
+
}
|
|
27566
26845
|
/**
|
|
27567
26846
|
* The same partition, one row per kind that a lane carries.
|
|
27568
26847
|
*
|
|
@@ -27572,11 +26851,14 @@ var SqliteHistorySyncRepository = class {
|
|
|
27572
26851
|
* rendering a fixed list of kinds must therefore treat a missing one as "no
|
|
27573
26852
|
* rows", never as "zero sent"; the two look identical in a bar and mean
|
|
27574
26853
|
* different things.
|
|
26854
|
+
*
|
|
26855
|
+
* `scopeKeys` scopes it with the clause `partition` uses, so the per-kind rows
|
|
26856
|
+
* still sum to the scoped aggregate. An empty list returns no rows.
|
|
27575
26857
|
*/
|
|
27576
|
-
partitionByKind() {
|
|
26858
|
+
partitionByKind(scopeKeys) {
|
|
27577
26859
|
return allRows(
|
|
27578
|
-
this.partitionByKindStmt,
|
|
27579
|
-
{}
|
|
26860
|
+
scopeKeys === void 0 ? this.partitionByKindStmt : this.scopedPartitionByKindStmt,
|
|
26861
|
+
scopeKeys === void 0 ? {} : { scopeKeys: scopeKeysParam(scopeKeys) }
|
|
27580
26862
|
).map((row) => ({
|
|
27581
26863
|
kind: row.kind,
|
|
27582
26864
|
queued: row.queued ?? 0,
|
|
@@ -27588,22 +26870,25 @@ var SqliteHistorySyncRepository = class {
|
|
|
27588
26870
|
total: row.total ?? 0
|
|
27589
26871
|
}));
|
|
27590
26872
|
}
|
|
27591
|
-
|
|
27592
|
-
|
|
27593
|
-
|
|
27594
|
-
|
|
27595
|
-
|
|
27596
|
-
|
|
27597
|
-
|
|
27598
|
-
|
|
27599
|
-
|
|
27600
|
-
|
|
27601
|
-
|
|
27602
|
-
|
|
27603
|
-
|
|
27604
|
-
|
|
27605
|
-
|
|
27606
|
-
|
|
26873
|
+
/**
|
|
26874
|
+
* The drain's totals. `pending` counts only what is inside the backlog; sent
|
|
26875
|
+
* and skipped are totals.
|
|
26876
|
+
*
|
|
26877
|
+
* `scopeKeys` is a scoped attachment's filter, and it scopes every figure,
|
|
26878
|
+
* `capturesSkipped` included: a structural row is counted only when its own
|
|
26879
|
+
* key and its session root's key are among them, a capture when its own key
|
|
26880
|
+
* is. So `pending` is exactly what pendingSessions and pendingRows page out
|
|
26881
|
+
* under the same keys and boundary. Omitted, this runs the machine
|
|
26882
|
+
* statements, unchanged; an empty list counts nothing.
|
|
26883
|
+
*/
|
|
26884
|
+
counts(before, scopeKeys) {
|
|
26885
|
+
const row = getRow(
|
|
26886
|
+
scopeKeys === void 0 ? this.countsStmt : this.scopedCountsStmt,
|
|
26887
|
+
scopeKeys === void 0 ? { before } : { before, scopeKeys: scopeKeysParam(scopeKeys) }
|
|
26888
|
+
);
|
|
26889
|
+
const captures = scopeKeys === void 0 ? getRow(this.captureSkipCountStmt) : getRow(this.scopedCaptureSkipCountStmt, {
|
|
26890
|
+
scopeKeys: scopeKeysParam(scopeKeys)
|
|
26891
|
+
});
|
|
27607
26892
|
return {
|
|
27608
26893
|
pending: row?.pending ?? 0,
|
|
27609
26894
|
sent: row?.sent ?? 0,
|
|
@@ -27855,6 +27140,7 @@ function applyMigrations(db, file2, options = {}) {
|
|
|
27855
27140
|
}
|
|
27856
27141
|
ensureSyncedAtColumn(db, "audit_events");
|
|
27857
27142
|
ensureScopeKeyColumn(db);
|
|
27143
|
+
ensureScopeOwedIndex(db);
|
|
27858
27144
|
ensureScanLedgerTable(db);
|
|
27859
27145
|
ensureHistorySyncTable(db);
|
|
27860
27146
|
ensureBlockedDetectionsTable(db);
|
|
@@ -28295,14 +27581,48 @@ function ensureScopeKeyColumn(db) {
|
|
|
28295
27581
|
function hasScopeKeyColumn(db) {
|
|
28296
27582
|
return columnNames(db, "audit_events", { includeGenerated: true }).includes("scope_key");
|
|
28297
27583
|
}
|
|
27584
|
+
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";
|
|
27585
|
+
function ensureScopeOwedIndex(db) {
|
|
27586
|
+
if (!schemaObjectExists(db, "table", "audit_events")) return;
|
|
27587
|
+
const columns = columnNames(db, "audit_events", { includeGenerated: true });
|
|
27588
|
+
const complete = ["scope_key", "outbox_owed", "synced_at"].every((c) => columns.includes(c));
|
|
27589
|
+
if (!complete) return;
|
|
27590
|
+
db.exec(SCOPE_OWED_INDEX_DDL);
|
|
27591
|
+
}
|
|
28298
27592
|
function ensureScanLedgerTable(db) {
|
|
28299
27593
|
db.exec(`CREATE TABLE IF NOT EXISTS scan_ledger (
|
|
28300
27594
|
path TEXT PRIMARY KEY,
|
|
28301
27595
|
mtime TEXT NOT NULL,
|
|
28302
27596
|
content_hash TEXT NOT NULL,
|
|
28303
27597
|
ruleset_hash TEXT NOT NULL,
|
|
28304
|
-
scanned_at INTEGER NOT NULL
|
|
27598
|
+
scanned_at INTEGER NOT NULL,
|
|
27599
|
+
scope_key TEXT,
|
|
27600
|
+
scope_root TEXT
|
|
28305
27601
|
)`);
|
|
27602
|
+
ensureScanLedgerScopeKeyColumn(db);
|
|
27603
|
+
ensureScanLedgerScopeRootColumn(db);
|
|
27604
|
+
}
|
|
27605
|
+
var SCAN_LEDGER_SCOPE_KEY_DDL = "ALTER TABLE scan_ledger ADD COLUMN scope_key TEXT";
|
|
27606
|
+
var SCAN_LEDGER_SCOPE_ROOT_DDL = "ALTER TABLE scan_ledger ADD COLUMN scope_root TEXT";
|
|
27607
|
+
function ensureScanLedgerScopeKeyColumn(db) {
|
|
27608
|
+
ensureScanLedgerColumn(db, "scope_key", SCAN_LEDGER_SCOPE_KEY_DDL);
|
|
27609
|
+
}
|
|
27610
|
+
function ensureScanLedgerScopeRootColumn(db) {
|
|
27611
|
+
ensureScanLedgerColumn(db, "scope_root", SCAN_LEDGER_SCOPE_ROOT_DDL);
|
|
27612
|
+
}
|
|
27613
|
+
function ensureScanLedgerColumn(db, column, ddl) {
|
|
27614
|
+
if (!schemaObjectExists(db, "table", "scan_ledger")) return;
|
|
27615
|
+
if (hasScanLedgerColumn(db, column)) return;
|
|
27616
|
+
withTransaction(
|
|
27617
|
+
db,
|
|
27618
|
+
() => {
|
|
27619
|
+
if (!hasScanLedgerColumn(db, column)) db.exec(ddl);
|
|
27620
|
+
},
|
|
27621
|
+
"IMMEDIATE"
|
|
27622
|
+
);
|
|
27623
|
+
}
|
|
27624
|
+
function hasScanLedgerColumn(db, column) {
|
|
27625
|
+
return columnNames(db, "scan_ledger").includes(column);
|
|
28306
27626
|
}
|
|
28307
27627
|
function ensureHistorySyncTable(db) {
|
|
28308
27628
|
db.exec(`CREATE TABLE IF NOT EXISTS history_sync (
|
|
@@ -28353,6 +27673,106 @@ function ensureRuleProbeCacheTable(db) {
|
|
|
28353
27673
|
)`);
|
|
28354
27674
|
}
|
|
28355
27675
|
|
|
27676
|
+
// ../../packages/persistence/src/mod-policy-snapshot.ts
|
|
27677
|
+
import { createHash as createHash2 } from "crypto";
|
|
27678
|
+
import { readFileSync as readFileSync2 } from "fs";
|
|
27679
|
+
import { join as join4 } from "path";
|
|
27680
|
+
var MOD_POLICY_SNAPSHOT_FILENAME = "mod-policy.json";
|
|
27681
|
+
function modPolicySnapshotPath(dataDir2) {
|
|
27682
|
+
return join4(dataDir2, MOD_POLICY_SNAPSHOT_FILENAME);
|
|
27683
|
+
}
|
|
27684
|
+
function buildModPolicySnapshot(input2, generatedAt = /* @__PURE__ */ new Date()) {
|
|
27685
|
+
const byRule = /* @__PURE__ */ new Map();
|
|
27686
|
+
const byCategory = /* @__PURE__ */ new Map();
|
|
27687
|
+
for (const policy of input2.policies) {
|
|
27688
|
+
if (!policy.enabled) continue;
|
|
27689
|
+
if ("ruleId" in policy.target) {
|
|
27690
|
+
if (!byRule.has(policy.target.ruleId)) byRule.set(policy.target.ruleId, policy.action);
|
|
27691
|
+
} else if (!byCategory.has(policy.target.category)) {
|
|
27692
|
+
byCategory.set(policy.target.category, policy.action);
|
|
27693
|
+
}
|
|
27694
|
+
}
|
|
27695
|
+
const categoryActions = {};
|
|
27696
|
+
for (const category of DetectionCategory.options) {
|
|
27697
|
+
categoryActions[category] = byCategory.get(category) ?? DEFAULT_ACTIONS[category];
|
|
27698
|
+
}
|
|
27699
|
+
return {
|
|
27700
|
+
version: MOD_POLICY_SNAPSHOT_VERSION,
|
|
27701
|
+
generatedAt: generatedAt.toISOString(),
|
|
27702
|
+
// `examples` is documentation the mod never reads, and a custom pack's are
|
|
27703
|
+
// whatever its author pasted in, so they stay behind.
|
|
27704
|
+
...input2.rules !== void 0 ? { rules: input2.rules.map(withoutExamples) } : {},
|
|
27705
|
+
ruleActions: Object.fromEntries(byRule),
|
|
27706
|
+
categoryActions,
|
|
27707
|
+
exceptionRuleIds: [...new Set(input2.exceptionRuleIds)].sort()
|
|
27708
|
+
};
|
|
27709
|
+
}
|
|
27710
|
+
function assignedRuleActionPolicies(installed) {
|
|
27711
|
+
const out = [];
|
|
27712
|
+
for (const [ruleId, action] of installed.ruleActions) {
|
|
27713
|
+
if (installed.assignedRules.has(ruleId))
|
|
27714
|
+
out.push({ target: { ruleId }, action, enabled: true });
|
|
27715
|
+
}
|
|
27716
|
+
return out;
|
|
27717
|
+
}
|
|
27718
|
+
function withoutExamples(rule) {
|
|
27719
|
+
const copy = { ...rule };
|
|
27720
|
+
delete copy.examples;
|
|
27721
|
+
return copy;
|
|
27722
|
+
}
|
|
27723
|
+
function sameContent(a, b) {
|
|
27724
|
+
return JSON.stringify({ ...a, generatedAt: "" }) === JSON.stringify({ ...b, generatedAt: "" });
|
|
27725
|
+
}
|
|
27726
|
+
function readModPolicySnapshot(dataDir2) {
|
|
27727
|
+
try {
|
|
27728
|
+
const text = readFileSync2(modPolicySnapshotPath(dataDir2), "utf8");
|
|
27729
|
+
if (text.length > MOD_POLICY_SNAPSHOT_MAX_BYTES) return null;
|
|
27730
|
+
const parsed2 = ModPolicySnapshot.safeParse(JSON.parse(text));
|
|
27731
|
+
return parsed2.success ? parsed2.data : null;
|
|
27732
|
+
} catch {
|
|
27733
|
+
return null;
|
|
27734
|
+
}
|
|
27735
|
+
}
|
|
27736
|
+
function writeModPolicySnapshot(dataDir2, snapshot) {
|
|
27737
|
+
const text = JSON.stringify(snapshot);
|
|
27738
|
+
if (Buffer.byteLength(text) > MOD_POLICY_SNAPSHOT_MAX_BYTES) return false;
|
|
27739
|
+
const existing = readModPolicySnapshot(dataDir2);
|
|
27740
|
+
if (existing !== null && sameContent(existing, snapshot)) return false;
|
|
27741
|
+
ensureDataDirSync(dataDir2);
|
|
27742
|
+
writeOwnerOnlyFileSync(modPolicySnapshotPath(dataDir2), text);
|
|
27743
|
+
return true;
|
|
27744
|
+
}
|
|
27745
|
+
function regexProbeKey(matcher) {
|
|
27746
|
+
return createHash2("sha256").update(`${matcher.pattern} ${matcher.flags}`).digest("hex");
|
|
27747
|
+
}
|
|
27748
|
+
function vetRulesForMod(rules, sources, previouslyVetted = /* @__PURE__ */ new Set()) {
|
|
27749
|
+
const bundled = new Set(sources.bundledRegexMatchers().map(regexProbeKey));
|
|
27750
|
+
return rules.filter((rule) => {
|
|
27751
|
+
if (rule.matcher.type !== "regex") return true;
|
|
27752
|
+
const key = regexProbeKey(rule.matcher);
|
|
27753
|
+
const verdict = sources.probeVerdict(key);
|
|
27754
|
+
if (verdict === "quarantined") return false;
|
|
27755
|
+
return verdict === "safe" || bundled.has(key) || previouslyVetted.has(key);
|
|
27756
|
+
});
|
|
27757
|
+
}
|
|
27758
|
+
function modPolicyInputFromStore(sources, previouslyVetted = /* @__PURE__ */ new Set()) {
|
|
27759
|
+
const policies = sources.readPolicies();
|
|
27760
|
+
const snapshot = sources.installedRuleset();
|
|
27761
|
+
const usable = snapshot.installedPacks > 0 && (snapshot.enabledPacks === 0 || snapshot.invalidRules === 0 && snapshot.rules.length > 0);
|
|
27762
|
+
const empty2 = snapshot.installedPacks > 0 && snapshot.enabledPacks === 0;
|
|
27763
|
+
return {
|
|
27764
|
+
...usable ? { rules: empty2 ? [] : vetRulesForMod(snapshot.rules, sources, previouslyVetted) } : {},
|
|
27765
|
+
policies: [...policies, ...usable && !empty2 ? assignedRuleActionPolicies(snapshot) : []],
|
|
27766
|
+
exceptionRuleIds: sources.activeExceptionRuleIds()
|
|
27767
|
+
};
|
|
27768
|
+
}
|
|
27769
|
+
function refreshModPolicySnapshot(dataDir2, sources) {
|
|
27770
|
+
try {
|
|
27771
|
+
writeModPolicySnapshot(dataDir2, buildModPolicySnapshot(modPolicyInputFromStore(sources)));
|
|
27772
|
+
} catch {
|
|
27773
|
+
}
|
|
27774
|
+
}
|
|
27775
|
+
|
|
28356
27776
|
// ../../packages/persistence/src/internal/json.ts
|
|
28357
27777
|
function safeJson(s, fallback) {
|
|
28358
27778
|
if (s == null) return fallback;
|
|
@@ -28527,6 +27947,11 @@ var TIMELINE_COLUMNS = `
|
|
|
28527
27947
|
json_extract(attributes, '$.targetId') AS target_id,
|
|
28528
27948
|
json_extract(attributes, '$.internal') AS internal,
|
|
28529
27949
|
json_extract(attributes, '$.flagged') AS flagged`;
|
|
27950
|
+
var CALL_PROMPT_TOKENS = `(coalesce(input_tokens, 0) + coalesce(cache_read_input_tokens, 0)
|
|
27951
|
+
+ coalesce(ephemeral_1h_input_tokens, 0) + coalesce(ephemeral_5m_input_tokens, 0))`;
|
|
27952
|
+
var CALL_BAND = LONG_CONTEXT_THRESHOLDS.length === 0 ? "0" : LONG_CONTEXT_THRESHOLDS.map((t) => `(${CALL_PROMPT_TOKENS} > ${String(Math.trunc(t))})`).join(
|
|
27953
|
+
" + "
|
|
27954
|
+
);
|
|
28530
27955
|
var LLM_USAGE_SELECT = `
|
|
28531
27956
|
SELECT root_session_id AS sessionId,
|
|
28532
27957
|
provider,
|
|
@@ -28538,9 +27963,10 @@ var LLM_USAGE_SELECT = `
|
|
|
28538
27963
|
coalesce(sum(cache_read_input_tokens), 0) AS cacheReadTokens,
|
|
28539
27964
|
coalesce(sum(ephemeral_1h_input_tokens), 0) AS ephemeral1hTokens,
|
|
28540
27965
|
coalesce(sum(ephemeral_5m_input_tokens), 0) AS ephemeral5mTokens,
|
|
28541
|
-
coalesce(sum(web_search_requests), 0) AS webSearchRequests
|
|
27966
|
+
coalesce(sum(web_search_requests), 0) AS webSearchRequests,
|
|
27967
|
+
coalesce(max(${CALL_PROMPT_TOKENS}), 0) AS promptTokens`;
|
|
28542
27968
|
var LLM_USAGE_SCOPE = `event_type = 'llm_call' AND attributes IS NOT NULL AND root_session_id IS NOT NULL`;
|
|
28543
|
-
var LLM_USAGE_GROUP = `GROUP BY root_session_id, provider, model, service_tier`;
|
|
27969
|
+
var LLM_USAGE_GROUP = `GROUP BY root_session_id, provider, model, service_tier, ${CALL_BAND}`;
|
|
28544
27970
|
function usageLeaves(rows) {
|
|
28545
27971
|
return rows.map((row) => {
|
|
28546
27972
|
const attributes = {
|
|
@@ -28555,7 +27981,7 @@ function usageLeaves(rows) {
|
|
|
28555
27981
|
if (row.provider !== null) attributes.provider = row.provider;
|
|
28556
27982
|
if (row.model !== null) attributes.model = row.model;
|
|
28557
27983
|
if (row.serviceTier !== null) attributes.service_tier = row.serviceTier;
|
|
28558
|
-
return { sessionId: row.sessionId, attributes };
|
|
27984
|
+
return { sessionId: row.sessionId, attributes, promptTokens: row.promptTokens };
|
|
28559
27985
|
});
|
|
28560
27986
|
}
|
|
28561
27987
|
var SESSION_ROOT = `event_type = 'session'`;
|
|
@@ -29889,9 +29315,10 @@ var ACTIVE_REVEAL_GRANT_PREDICATE = `capability = 'reveal_to_model'
|
|
|
29889
29315
|
AND conditions IS NULL
|
|
29890
29316
|
AND ${ACTIVE_PREDICATE}`;
|
|
29891
29317
|
var SqliteExceptionsRepository = class {
|
|
29892
|
-
constructor(db, now = () => Date.now()) {
|
|
29318
|
+
constructor(db, now = () => Date.now(), onChange = () => void 0) {
|
|
29893
29319
|
this.db = db;
|
|
29894
29320
|
this.now = now;
|
|
29321
|
+
this.onChange = onChange;
|
|
29895
29322
|
this.consumeStmt = db.prepare(
|
|
29896
29323
|
`UPDATE exceptions
|
|
29897
29324
|
SET use_count = use_count + 1, last_used_at = :now, updated_at = :now
|
|
@@ -29910,6 +29337,7 @@ var SqliteExceptionsRepository = class {
|
|
|
29910
29337
|
}
|
|
29911
29338
|
db;
|
|
29912
29339
|
now;
|
|
29340
|
+
onChange;
|
|
29913
29341
|
consumeStmt;
|
|
29914
29342
|
insertBlockedStmt;
|
|
29915
29343
|
sweepBlockedStmt;
|
|
@@ -29925,7 +29353,9 @@ var SqliteExceptionsRepository = class {
|
|
|
29925
29353
|
*/
|
|
29926
29354
|
create(input2) {
|
|
29927
29355
|
try {
|
|
29928
|
-
|
|
29356
|
+
const created = this.createSync(input2);
|
|
29357
|
+
this.onChange();
|
|
29358
|
+
return Promise.resolve(created);
|
|
29929
29359
|
} catch (err) {
|
|
29930
29360
|
return Promise.reject(err instanceof Error ? err : new Error(String(err)));
|
|
29931
29361
|
}
|
|
@@ -30056,6 +29486,7 @@ var SqliteExceptionsRepository = class {
|
|
|
30056
29486
|
SET revoked_at = :now, revoked_by = :revokedBy, revoke_reason = :reason, updated_at = :now
|
|
30057
29487
|
WHERE id = :id AND revoked_at IS NULL`
|
|
30058
29488
|
).run({ id, revokedBy, reason: reason ?? null, now });
|
|
29489
|
+
if (Number(result.changes) === 1) this.onChange();
|
|
30059
29490
|
return Promise.resolve(Number(result.changes) === 1);
|
|
30060
29491
|
}
|
|
30061
29492
|
/**
|
|
@@ -30068,6 +29499,15 @@ var SqliteExceptionsRepository = class {
|
|
|
30068
29499
|
const result = this.consumeStmt.run({ id, now });
|
|
30069
29500
|
return Promise.resolve(Number(result.changes) === 1);
|
|
30070
29501
|
}
|
|
29502
|
+
/** The rule ids with at least one active grant, under any key version. */
|
|
29503
|
+
activeRuleIds(now = this.now()) {
|
|
29504
|
+
return allRows(
|
|
29505
|
+
this.db.prepare(
|
|
29506
|
+
`SELECT DISTINCT rule_id AS ruleId FROM exceptions WHERE ${ACTIVE_PREDICATE}`
|
|
29507
|
+
),
|
|
29508
|
+
{ now }
|
|
29509
|
+
).map((row) => row.ruleId);
|
|
29510
|
+
}
|
|
30071
29511
|
/**
|
|
30072
29512
|
* The evaluation subset of every active grant under one fingerprint key
|
|
30073
29513
|
* version — what rides the policy bundle to the hook. Grants written under
|
|
@@ -31191,28 +30631,28 @@ var SqliteInspectionFindingsRepository = class {
|
|
|
31191
30631
|
};
|
|
31192
30632
|
|
|
31193
30633
|
// ../../packages/persistence/src/repositories/installed-packs.ts
|
|
31194
|
-
import { createHash as
|
|
30634
|
+
import { createHash as createHash3, randomUUID as randomUUID4 } from "crypto";
|
|
31195
30635
|
|
|
31196
30636
|
// ../../packages/persistence/src/policy-floor.ts
|
|
31197
|
-
import { readFileSync as
|
|
31198
|
-
import { join as
|
|
30637
|
+
import { readFileSync as readFileSync6 } from "fs";
|
|
30638
|
+
import { join as join7 } from "path";
|
|
31199
30639
|
|
|
31200
30640
|
// ../../packages/persistence/src/local-layout.ts
|
|
31201
30641
|
import { renameSync as renameSync3 } from "fs";
|
|
31202
30642
|
import { mkdir } from "fs/promises";
|
|
31203
30643
|
import { homedir } from "os";
|
|
31204
|
-
import { join as
|
|
30644
|
+
import { join as join5 } from "path";
|
|
31205
30645
|
function defaultDataDir() {
|
|
31206
|
-
return
|
|
30646
|
+
return join5(homedir(), ".aka");
|
|
31207
30647
|
}
|
|
31208
30648
|
function settingsDir(base = defaultDataDir()) {
|
|
31209
|
-
return
|
|
30649
|
+
return join5(base, "settings");
|
|
31210
30650
|
}
|
|
31211
30651
|
function dataDir(base = defaultDataDir()) {
|
|
31212
|
-
return
|
|
30652
|
+
return join5(base, "data");
|
|
31213
30653
|
}
|
|
31214
30654
|
function dbPath(base = defaultDataDir()) {
|
|
31215
|
-
return
|
|
30655
|
+
return join5(dataDir(base), "aka.db");
|
|
31216
30656
|
}
|
|
31217
30657
|
async function ensureDataDir(dir = defaultDataDir()) {
|
|
31218
30658
|
await mkdir(dir, { recursive: true, mode: DATA_DIR_MODE });
|
|
@@ -31229,8 +30669,8 @@ function migrateLegacyLayout(base = defaultDataDir()) {
|
|
|
31229
30669
|
for (const { name, dest } of moves) {
|
|
31230
30670
|
try {
|
|
31231
30671
|
ensureDataDirSync(dest);
|
|
31232
|
-
const moved =
|
|
31233
|
-
renameSync3(
|
|
30672
|
+
const moved = join5(dest, name);
|
|
30673
|
+
renameSync3(join5(base, name), moved);
|
|
31234
30674
|
tightenFile(moved);
|
|
31235
30675
|
} catch {
|
|
31236
30676
|
}
|
|
@@ -31238,8 +30678,8 @@ function migrateLegacyLayout(base = defaultDataDir()) {
|
|
|
31238
30678
|
}
|
|
31239
30679
|
|
|
31240
30680
|
// ../../packages/persistence/src/settings.ts
|
|
31241
|
-
import { readFileSync as
|
|
31242
|
-
import { join as
|
|
30681
|
+
import { readFileSync as readFileSync5 } from "fs";
|
|
30682
|
+
import { join as join6 } from "path";
|
|
31243
30683
|
|
|
31244
30684
|
// ../../packages/persistence/src/file-lock.ts
|
|
31245
30685
|
import { randomUUID as randomUUID3 } from "crypto";
|
|
@@ -31247,7 +30687,7 @@ import {
|
|
|
31247
30687
|
closeSync,
|
|
31248
30688
|
existsSync as existsSync2,
|
|
31249
30689
|
openSync,
|
|
31250
|
-
readFileSync as
|
|
30690
|
+
readFileSync as readFileSync3,
|
|
31251
30691
|
rmSync as rmSync5,
|
|
31252
30692
|
statSync as statSync3,
|
|
31253
30693
|
writeFileSync as writeFileSync2
|
|
@@ -31256,16 +30696,16 @@ import { hostname as hostname3 } from "os";
|
|
|
31256
30696
|
var PARK = new Int32Array(new SharedArrayBuffer(4));
|
|
31257
30697
|
|
|
31258
30698
|
// ../../packages/persistence/src/managed-settings.ts
|
|
31259
|
-
import { readFileSync as
|
|
30699
|
+
import { readFileSync as readFileSync4 } from "fs";
|
|
31260
30700
|
import { posix, win32 } from "path";
|
|
31261
|
-
function managedSettingsPaths(
|
|
31262
|
-
if (
|
|
30701
|
+
function managedSettingsPaths(platform = process.platform) {
|
|
30702
|
+
if (platform === "darwin") {
|
|
31263
30703
|
return [
|
|
31264
30704
|
posix.join("/Library", "Application Support", "AKASecurity", MANAGED_SETTINGS_FILENAME),
|
|
31265
30705
|
posix.join("/Library", "Managed Preferences", MANAGED_SETTINGS_FILENAME)
|
|
31266
30706
|
];
|
|
31267
30707
|
}
|
|
31268
|
-
if (
|
|
30708
|
+
if (platform === "win32") {
|
|
31269
30709
|
return [win32.join("C:\\", "ProgramData", "AKASecurity", MANAGED_SETTINGS_FILENAME)];
|
|
31270
30710
|
}
|
|
31271
30711
|
return [posix.join("/etc", "aka", MANAGED_SETTINGS_FILENAME)];
|
|
@@ -31275,7 +30715,7 @@ function readManagedSettings(paths = testOnlyManagedPaths ?? managedSettingsPath
|
|
|
31275
30715
|
for (const path of paths) {
|
|
31276
30716
|
let text;
|
|
31277
30717
|
try {
|
|
31278
|
-
text =
|
|
30718
|
+
text = readFileSync4(path, "utf8");
|
|
31279
30719
|
} catch {
|
|
31280
30720
|
continue;
|
|
31281
30721
|
}
|
|
@@ -31329,7 +30769,7 @@ function readWorkspaceSettings(base = defaultDataDir()) {
|
|
|
31329
30769
|
return overlayManagedSettings(readUserSettings(base), readManagedSettings());
|
|
31330
30770
|
}
|
|
31331
30771
|
function readUserSettings(base) {
|
|
31332
|
-
const record2 = readJson(
|
|
30772
|
+
const record2 = readJson(join6(settingsDir(base), SETTINGS_FILENAME));
|
|
31333
30773
|
if (!record2) return defaultWorkspaceSettings();
|
|
31334
30774
|
try {
|
|
31335
30775
|
return WorkspaceSettings.parse(record2);
|
|
@@ -31340,7 +30780,7 @@ function readUserSettings(base) {
|
|
|
31340
30780
|
function readJson(file2) {
|
|
31341
30781
|
let text;
|
|
31342
30782
|
try {
|
|
31343
|
-
text =
|
|
30783
|
+
text = readFileSync5(file2, "utf8");
|
|
31344
30784
|
} catch {
|
|
31345
30785
|
return null;
|
|
31346
30786
|
}
|
|
@@ -31380,7 +30820,7 @@ var PolicyFloorError = class extends Error {
|
|
|
31380
30820
|
};
|
|
31381
30821
|
function readCachedPolicyBundle(base = defaultDataDir()) {
|
|
31382
30822
|
try {
|
|
31383
|
-
const raw =
|
|
30823
|
+
const raw = readFileSync6(join7(dataDir(base), POLICY_CACHE_FILENAME), "utf8");
|
|
31384
30824
|
const parsed2 = JSON.parse(raw);
|
|
31385
30825
|
if (typeof parsed2 !== "object" || parsed2 === null) return null;
|
|
31386
30826
|
return PolicyBundle.parse(parsed2.bundle);
|
|
@@ -31504,7 +30944,7 @@ function inventorySignature(packs) {
|
|
|
31504
30944
|
return packs.map((p) => `${p.namespace}/${p.packId}@${p.version}#${hashRules(p.rulesJson)}`).sort().join(",");
|
|
31505
30945
|
}
|
|
31506
30946
|
function hashRules(rulesJson) {
|
|
31507
|
-
return
|
|
30947
|
+
return createHash3("sha256").update(rulesJson).digest("hex");
|
|
31508
30948
|
}
|
|
31509
30949
|
function parseVersion(v) {
|
|
31510
30950
|
const m = /^(\d+)\.(\d+)\.(\d+)/.exec(v);
|
|
@@ -31546,9 +30986,10 @@ var SqliteInstalledPacksRepository = class {
|
|
|
31546
30986
|
* from `openLocalDatabase`, which is the single construction site that owns a
|
|
31547
30987
|
* real `~/.aka`.
|
|
31548
30988
|
*/
|
|
31549
|
-
constructor(db, baseDir) {
|
|
30989
|
+
constructor(db, baseDir, onChange = () => void 0) {
|
|
31550
30990
|
this.db = db;
|
|
31551
30991
|
this.baseDir = baseDir;
|
|
30992
|
+
this.onChange = onChange;
|
|
31552
30993
|
this.insertMissingStmt = db.prepare(
|
|
31553
30994
|
`INSERT INTO installed_packs (id, namespace, pack_id, version, name, rules_json, enabled, policy_id, created_at, updated_at)
|
|
31554
30995
|
VALUES (:id, :namespace, :packId, :version, :name, :rulesJson, 1, :policyId, :now, :now)
|
|
@@ -31577,6 +31018,7 @@ var SqliteInstalledPacksRepository = class {
|
|
|
31577
31018
|
}
|
|
31578
31019
|
db;
|
|
31579
31020
|
baseDir;
|
|
31021
|
+
onChange;
|
|
31580
31022
|
insertMissingStmt;
|
|
31581
31023
|
upsertAvailableStmt;
|
|
31582
31024
|
signatureStmt;
|
|
@@ -31649,6 +31091,7 @@ var SqliteInstalledPacksRepository = class {
|
|
|
31649
31091
|
},
|
|
31650
31092
|
"IMMEDIATE"
|
|
31651
31093
|
);
|
|
31094
|
+
this.onChange();
|
|
31652
31095
|
} catch {
|
|
31653
31096
|
}
|
|
31654
31097
|
}
|
|
@@ -31723,6 +31166,7 @@ var SqliteInstalledPacksRepository = class {
|
|
|
31723
31166
|
},
|
|
31724
31167
|
"IMMEDIATE"
|
|
31725
31168
|
);
|
|
31169
|
+
if (changed) this.onChange();
|
|
31726
31170
|
return changed;
|
|
31727
31171
|
}
|
|
31728
31172
|
/**
|
|
@@ -31964,6 +31408,7 @@ var SqliteInstalledPacksRepository = class {
|
|
|
31964
31408
|
`UPDATE installed_packs SET policy_id = :policyId, updated_at = :now
|
|
31965
31409
|
WHERE namespace = :namespace AND pack_id = :packId`
|
|
31966
31410
|
).run({ policyId, now: Date.now(), namespace, packId });
|
|
31411
|
+
if (Number(res.changes) > 0) this.onChange();
|
|
31967
31412
|
return Number(res.changes) > 0;
|
|
31968
31413
|
}
|
|
31969
31414
|
/**
|
|
@@ -31988,6 +31433,7 @@ var SqliteInstalledPacksRepository = class {
|
|
|
31988
31433
|
`UPDATE installed_packs SET enabled = :enabled, updated_at = :now
|
|
31989
31434
|
WHERE namespace = :namespace AND pack_id = :packId`
|
|
31990
31435
|
).run({ enabled: boolToInt(enabled), now: Date.now(), namespace, packId });
|
|
31436
|
+
if (Number(res.changes) > 0) this.onChange();
|
|
31991
31437
|
return Number(res.changes) > 0;
|
|
31992
31438
|
}
|
|
31993
31439
|
// Fingerprint of the recorded available mirror — compared against the
|
|
@@ -32885,13 +32331,19 @@ var SqliteInventoryAssetsRepository = class {
|
|
|
32885
32331
|
import { randomUUID as randomUUID6 } from "crypto";
|
|
32886
32332
|
var SEED_BATCH_WINDOW_MS = 6e4;
|
|
32887
32333
|
var SqlitePoliciesRepository = class {
|
|
32888
|
-
constructor(db) {
|
|
32334
|
+
constructor(db, onChange = () => void 0) {
|
|
32889
32335
|
this.db = db;
|
|
32336
|
+
this.onChange = onChange;
|
|
32890
32337
|
}
|
|
32891
32338
|
db;
|
|
32339
|
+
onChange;
|
|
32892
32340
|
readPolicies() {
|
|
32341
|
+
return Promise.resolve(this.listPolicies());
|
|
32342
|
+
}
|
|
32343
|
+
/** The synchronous read behind {@link readPolicies}. */
|
|
32344
|
+
listPolicies() {
|
|
32893
32345
|
const rows = allRows(this.db.prepare("SELECT * FROM policies"));
|
|
32894
|
-
|
|
32346
|
+
return mapRowsTolerant(rows, (row) => {
|
|
32895
32347
|
const target = JSON.parse(row.target);
|
|
32896
32348
|
const customKeywords = row.custom_keywords ? JSON.parse(row.custom_keywords) : void 0;
|
|
32897
32349
|
return Policy.parse({
|
|
@@ -32903,7 +32355,6 @@ var SqlitePoliciesRepository = class {
|
|
|
32903
32355
|
customKeywords
|
|
32904
32356
|
});
|
|
32905
32357
|
});
|
|
32906
|
-
return Promise.resolve(policies);
|
|
32907
32358
|
}
|
|
32908
32359
|
// Seed one policy per bundled category at Monitor so the detection-type config
|
|
32909
32360
|
// exists from first run. An unassigned pack's rules follow these rows, so
|
|
@@ -32914,7 +32365,7 @@ var SqlitePoliciesRepository = class {
|
|
|
32914
32365
|
const count = countScalar(this.db, "SELECT count(*) AS n FROM policies");
|
|
32915
32366
|
if (count > 0) {
|
|
32916
32367
|
this.markEarlierChoices();
|
|
32917
|
-
this.monitorUntouchedSeeds();
|
|
32368
|
+
if (this.monitorUntouchedSeeds()) this.onChange();
|
|
32918
32369
|
return;
|
|
32919
32370
|
}
|
|
32920
32371
|
const stmt = this.db.prepare(
|
|
@@ -32931,6 +32382,7 @@ var SqlitePoliciesRepository = class {
|
|
|
32931
32382
|
});
|
|
32932
32383
|
}
|
|
32933
32384
|
});
|
|
32385
|
+
this.onChange();
|
|
32934
32386
|
}
|
|
32935
32387
|
// Before this build, upsertCategoryAction INSERTed a new row with updated_at
|
|
32936
32388
|
// equal to created_at, so a choice made for a category that had no row yet
|
|
@@ -32996,7 +32448,7 @@ var SqlitePoliciesRepository = class {
|
|
|
32996
32448
|
).filter(
|
|
32997
32449
|
(row) => DEFAULT_ACTIONS[row.category] === row.action
|
|
32998
32450
|
);
|
|
32999
|
-
if (untouched.length === 0) return;
|
|
32451
|
+
if (untouched.length === 0) return false;
|
|
33000
32452
|
const stmt = this.db.prepare(
|
|
33001
32453
|
`UPDATE policies SET action = 'log'
|
|
33002
32454
|
WHERE scope = 'global' AND json_extract(target, '$.category') = :category
|
|
@@ -33007,6 +32459,7 @@ var SqlitePoliciesRepository = class {
|
|
|
33007
32459
|
stmt.run({ category: row.category, seeded: row.action });
|
|
33008
32460
|
}
|
|
33009
32461
|
});
|
|
32462
|
+
return true;
|
|
33010
32463
|
}
|
|
33011
32464
|
// Insert-or-update the single global per-category policy row, keyed on the
|
|
33012
32465
|
// existing uq_policies_scope_target unique index (scope, target). `action`
|
|
@@ -33023,6 +32476,7 @@ var SqlitePoliciesRepository = class {
|
|
|
33023
32476
|
ON CONFLICT(scope, target) DO UPDATE SET action = excluded.action, enabled = 1,
|
|
33024
32477
|
updated_at = MAX(excluded.updated_at, policies.created_at + 1)`
|
|
33025
32478
|
).run({ id: randomUUID6(), target: JSON.stringify({ category }), action, now });
|
|
32479
|
+
this.onChange();
|
|
33026
32480
|
}
|
|
33027
32481
|
// Caps every global per-category policy currently set to block/redact down
|
|
33028
32482
|
// to warn (see warn-era-cap.ts). Rule-targeted policies are untouched.
|
|
@@ -33033,6 +32487,7 @@ var SqlitePoliciesRepository = class {
|
|
|
33033
32487
|
WHERE scope='global' AND action IN ('block','redact')
|
|
33034
32488
|
AND json_extract(target,'$.category') IS NOT NULL`
|
|
33035
32489
|
).run({ now: Date.now() });
|
|
32490
|
+
if (Number(info.changes) > 0) this.onChange();
|
|
33036
32491
|
return Number(info.changes);
|
|
33037
32492
|
}
|
|
33038
32493
|
// Whether the category's row was ever written after it was created — by the
|
|
@@ -33352,31 +32807,45 @@ var SqliteScanLedgerRepository = class {
|
|
|
33352
32807
|
constructor(db) {
|
|
33353
32808
|
this.db = db;
|
|
33354
32809
|
this.upsertStmt = db.prepare(
|
|
33355
|
-
`INSERT INTO scan_ledger
|
|
33356
|
-
|
|
32810
|
+
`INSERT INTO scan_ledger
|
|
32811
|
+
(path, mtime, content_hash, ruleset_hash, scope_key, scope_root, scanned_at)
|
|
32812
|
+
VALUES (:path, :mtime, :contentHash, :rulesetHash, :scopeKey, :scopeRoot, :scannedAt)
|
|
33357
32813
|
ON CONFLICT (path) DO UPDATE SET
|
|
33358
32814
|
mtime = excluded.mtime,
|
|
33359
32815
|
content_hash = excluded.content_hash,
|
|
33360
32816
|
ruleset_hash = excluded.ruleset_hash,
|
|
32817
|
+
scope_key = excluded.scope_key,
|
|
32818
|
+
scope_root = excluded.scope_root,
|
|
33361
32819
|
scanned_at = excluded.scanned_at`
|
|
33362
32820
|
);
|
|
33363
32821
|
this.readStmt = db.prepare(
|
|
33364
|
-
`SELECT path, mtime, content_hash AS contentHash
|
|
32822
|
+
`SELECT path, mtime, content_hash AS contentHash, scope_key AS scopeKey,
|
|
32823
|
+
scope_root AS scopeRoot
|
|
33365
32824
|
FROM scan_ledger WHERE ruleset_hash = :rulesetHash`
|
|
33366
32825
|
);
|
|
33367
32826
|
this.pathsStmt = db.prepare(`SELECT path FROM scan_ledger`);
|
|
32827
|
+
this.pathKeysStmt = db.prepare(`SELECT path, scope_key AS scopeKey FROM scan_ledger`);
|
|
33368
32828
|
}
|
|
33369
32829
|
db;
|
|
33370
32830
|
upsertStmt;
|
|
33371
32831
|
readStmt;
|
|
33372
32832
|
pathsStmt;
|
|
32833
|
+
pathKeysStmt;
|
|
33373
32834
|
// Previously scanned files under THIS ruleset, keyed by path. Rows from an
|
|
33374
32835
|
// older ruleset are simply absent, which reads as "never scanned".
|
|
33375
32836
|
entriesForRuleset(rulesetHash) {
|
|
33376
|
-
const rows = allRows(this.readStmt, {
|
|
33377
|
-
|
|
33378
|
-
|
|
33379
|
-
|
|
32837
|
+
const rows = allRows(this.readStmt, { rulesetHash });
|
|
32838
|
+
return new Map(
|
|
32839
|
+
rows.map((r) => [
|
|
32840
|
+
r.path,
|
|
32841
|
+
{
|
|
32842
|
+
mtime: r.mtime,
|
|
32843
|
+
contentHash: r.contentHash,
|
|
32844
|
+
...r.scopeKey !== null ? { scopeKey: r.scopeKey } : {},
|
|
32845
|
+
...r.scopeRoot !== null ? { scopeRoot: r.scopeRoot } : {}
|
|
32846
|
+
}
|
|
32847
|
+
])
|
|
32848
|
+
);
|
|
33380
32849
|
}
|
|
33381
32850
|
// Every ledgered path, whatever ruleset it was scanned under — the set a
|
|
33382
32851
|
// deletion sweep checks against disk. A file deleted before a ruleset change
|
|
@@ -33385,6 +32854,14 @@ var SqliteScanLedgerRepository = class {
|
|
|
33385
32854
|
allPaths() {
|
|
33386
32855
|
return allRows(this.pathsStmt).map((r) => r.path);
|
|
33387
32856
|
}
|
|
32857
|
+
// Every ledgered path with the repository it was in when it was last read,
|
|
32858
|
+
// whatever ruleset it was scanned under: what a deletion sweep needs to say
|
|
32859
|
+
// which repository a vanished file belonged to. `undefined` for a row with no
|
|
32860
|
+
// key, which is every row written before the column existed.
|
|
32861
|
+
pathKeys() {
|
|
32862
|
+
const rows = allRows(this.pathKeysStmt);
|
|
32863
|
+
return new Map(rows.map((r) => [r.path, r.scopeKey ?? void 0]));
|
|
32864
|
+
}
|
|
33388
32865
|
upsertEntries(entries) {
|
|
33389
32866
|
if (entries.length === 0) return;
|
|
33390
32867
|
const scannedAt = Date.now();
|
|
@@ -33395,6 +32872,8 @@ var SqliteScanLedgerRepository = class {
|
|
|
33395
32872
|
mtime: entry.mtime,
|
|
33396
32873
|
contentHash: entry.contentHash,
|
|
33397
32874
|
rulesetHash: entry.rulesetHash,
|
|
32875
|
+
scopeKey: entry.scopeKey ?? null,
|
|
32876
|
+
scopeRoot: entry.scopeRoot ?? null,
|
|
33398
32877
|
scannedAt
|
|
33399
32878
|
});
|
|
33400
32879
|
}
|
|
@@ -34482,6 +33961,11 @@ function withoutDroppedFiles(reconcile, droppedFiles) {
|
|
|
34482
33961
|
deletedFiles: reconcile.deletedFiles.filter((file2) => !dropped.has(file2))
|
|
34483
33962
|
};
|
|
34484
33963
|
}
|
|
33964
|
+
function withoutTrailingSlashes(path) {
|
|
33965
|
+
let end = path.length;
|
|
33966
|
+
while (end > 0 && path.charCodeAt(end - 1) === 47) end--;
|
|
33967
|
+
return path.slice(0, end);
|
|
33968
|
+
}
|
|
34485
33969
|
function toEndpointSummary(row) {
|
|
34486
33970
|
return {
|
|
34487
33971
|
id: row.id,
|
|
@@ -34769,7 +34253,7 @@ var SqliteSharesRepository = class {
|
|
|
34769
34253
|
*/
|
|
34770
34254
|
reconcileCallSites(projectKey, reconcile) {
|
|
34771
34255
|
if (reconcile.mode === "walk") {
|
|
34772
|
-
const prefix = reconcile.walkedPrefix
|
|
34256
|
+
const prefix = withoutTrailingSlashes(reconcile.walkedPrefix);
|
|
34773
34257
|
this.db.prepare(
|
|
34774
34258
|
`DELETE FROM share_call_site
|
|
34775
34259
|
WHERE project_key = :key
|
|
@@ -35337,7 +34821,7 @@ function backupLegacyStore(db, file2) {
|
|
|
35337
34821
|
discardStore(file2, backup);
|
|
35338
34822
|
return backup;
|
|
35339
34823
|
}
|
|
35340
|
-
function openAndInitialize(file2, base, skipTags) {
|
|
34824
|
+
function openAndInitialize(file2, base, skipTags, shippedRegexMatchers2) {
|
|
35341
34825
|
let db = openWithPragmas(file2);
|
|
35342
34826
|
try {
|
|
35343
34827
|
if (isForeignSqliteLineage(db)) {
|
|
@@ -35349,8 +34833,15 @@ function openAndInitialize(file2, base, skipTags) {
|
|
|
35349
34833
|
}
|
|
35350
34834
|
applyMigrations(db, file2, { skipTags });
|
|
35351
34835
|
tightenPerms(file2);
|
|
35352
|
-
const
|
|
35353
|
-
const
|
|
34836
|
+
const modPolicy = {};
|
|
34837
|
+
const onPolicyStateChange = () => {
|
|
34838
|
+
if (modPolicy.current !== void 0)
|
|
34839
|
+
refreshModPolicySnapshot(dirname2(file2), modPolicy.current);
|
|
34840
|
+
};
|
|
34841
|
+
const policies = new SqlitePoliciesRepository(db, onPolicyStateChange);
|
|
34842
|
+
const installedPacks = new SqliteInstalledPacksRepository(db, base, onPolicyStateChange);
|
|
34843
|
+
const ruleProbeCache = new SqliteRuleProbeCacheRepository(db);
|
|
34844
|
+
const exceptions = new SqliteExceptionsRepository(db, void 0, onPolicyStateChange);
|
|
35354
34845
|
const repositories = {
|
|
35355
34846
|
events: new SqliteEventsRepository(db),
|
|
35356
34847
|
findings: new SqliteFindingsRepository(db),
|
|
@@ -35359,9 +34850,9 @@ function openAndInitialize(file2, base, skipTags) {
|
|
|
35359
34850
|
scanLedger: new SqliteScanLedgerRepository(db),
|
|
35360
34851
|
historySync: new SqliteHistorySyncRepository(db),
|
|
35361
34852
|
secretVault: new SqliteSecretVaultRepository(db),
|
|
35362
|
-
exceptions
|
|
34853
|
+
exceptions,
|
|
35363
34854
|
resolutions: new SqliteResolutionsRepository(db),
|
|
35364
|
-
ruleProbeCache
|
|
34855
|
+
ruleProbeCache,
|
|
35365
34856
|
bodyRetention: new SqliteBodyRetentionRepository(db),
|
|
35366
34857
|
security: new SqliteSecurityRepository(db),
|
|
35367
34858
|
detections: new SqliteDetectionsRepository(db),
|
|
@@ -35379,6 +34870,13 @@ function openAndInitialize(file2, base, skipTags) {
|
|
|
35379
34870
|
inspectionFindings: new SqliteInspectionFindingsRepository(db),
|
|
35380
34871
|
configInventory: new SqliteConfigInventoryRepository(db)
|
|
35381
34872
|
};
|
|
34873
|
+
modPolicy.current = {
|
|
34874
|
+
installedRuleset: () => installedPacks.installedRuleset(),
|
|
34875
|
+
readPolicies: () => policies.listPolicies(),
|
|
34876
|
+
activeExceptionRuleIds: () => exceptions.activeRuleIds(),
|
|
34877
|
+
probeVerdict: (key) => ruleProbeCache.getVerdict(key)?.verdict,
|
|
34878
|
+
bundledRegexMatchers: () => shippedRegexMatchers2
|
|
34879
|
+
};
|
|
35382
34880
|
policies.seedDefaults();
|
|
35383
34881
|
return { db, ...repositories };
|
|
35384
34882
|
} catch (err) {
|
|
@@ -35390,7 +34888,7 @@ function openAndInitialize(file2, base, skipTags) {
|
|
|
35390
34888
|
var DEFERRED_TAGS = new Set(DEFERRED_MIGRATION_TAGS);
|
|
35391
34889
|
function openLocalDatabase(dir, options = {}) {
|
|
35392
34890
|
ensureDataDirSync(dir);
|
|
35393
|
-
const file2 =
|
|
34891
|
+
const file2 = join8(dir, DB_FILENAME);
|
|
35394
34892
|
reapStalePartials(file2);
|
|
35395
34893
|
const {
|
|
35396
34894
|
db,
|
|
@@ -35426,7 +34924,8 @@ function openLocalDatabase(dir, options = {}) {
|
|
|
35426
34924
|
// `dataDir()` — so its parent is the `~/.aka` base the layout splits into
|
|
35427
34925
|
// settings/ and data/, and the pack-policy floor needs both halves.
|
|
35428
34926
|
dirname2(dir),
|
|
35429
|
-
options.applyDeferredMigrations === true ? void 0 : DEFERRED_TAGS
|
|
34927
|
+
options.applyDeferredMigrations === true ? void 0 : DEFERRED_TAGS,
|
|
34928
|
+
options.shippedRegexMatchers ?? []
|
|
35430
34929
|
);
|
|
35431
34930
|
function captureRowId(event) {
|
|
35432
34931
|
return captureId(
|
|
@@ -35691,7 +35190,7 @@ function openLocalDatabase(dir, options = {}) {
|
|
|
35691
35190
|
}
|
|
35692
35191
|
|
|
35693
35192
|
// ../../packages/persistence/src/egress-wire.ts
|
|
35694
|
-
import { createHash as
|
|
35193
|
+
import { createHash as createHash4 } from "crypto";
|
|
35695
35194
|
var PROJECT_KEY_DIGEST_VERSION = "v2";
|
|
35696
35195
|
var SCP_FORM = /^(?:[^@/]+@)?([^/:]+):(.+)$/;
|
|
35697
35196
|
var DOS_DRIVE = /^[A-Za-z]:[\\/]/;
|
|
@@ -35723,7 +35222,7 @@ function canonicalGitUrl(url2) {
|
|
|
35723
35222
|
}
|
|
35724
35223
|
function hashProjectKey(projectKey) {
|
|
35725
35224
|
const canonical = projectKey.startsWith("git:") ? `git:${canonicalGitUrl(projectKey.slice("git:".length))}` : projectKey;
|
|
35726
|
-
return
|
|
35225
|
+
return createHash4("sha256").update(`${PROJECT_KEY_DIGEST_VERSION}:${canonical}`, "utf8").digest("hex");
|
|
35727
35226
|
}
|
|
35728
35227
|
var SCOPE_KEY = printable(ATTACHMENT_SCOPE_IDENTITY_MAX_LENGTH);
|
|
35729
35228
|
var URL_SCHEME = /^[a-z][a-z0-9+.-]*:\/\//i;
|
|
@@ -35788,17 +35287,16 @@ function toEgressIngestRequest(input2) {
|
|
|
35788
35287
|
}
|
|
35789
35288
|
|
|
35790
35289
|
// ../../packages/persistence/src/finding-key.ts
|
|
35791
|
-
import { createHash as
|
|
35290
|
+
import { createHash as createHash5 } from "crypto";
|
|
35792
35291
|
|
|
35793
35292
|
// ../../packages/persistence/src/fingerprint.ts
|
|
35794
35293
|
import { createHmac, randomBytes } from "crypto";
|
|
35795
|
-
import { existsSync as existsSync3, readFileSync as
|
|
35796
|
-
import { join as
|
|
35797
|
-
import { DatabaseSync as DatabaseSync2 } from "node:sqlite";
|
|
35294
|
+
import { existsSync as existsSync3, readFileSync as readFileSync7 } from "fs";
|
|
35295
|
+
import { join as join9 } from "path";
|
|
35798
35296
|
var EXCEPTION_KEY_FILENAME = "exception.key";
|
|
35799
35297
|
var KEY_MATERIAL_BYTES = 32;
|
|
35800
35298
|
function keyFilePath(dataDir2) {
|
|
35801
|
-
return
|
|
35299
|
+
return join9(dataDir2, EXCEPTION_KEY_FILENAME);
|
|
35802
35300
|
}
|
|
35803
35301
|
function parseKeyFile(raw) {
|
|
35804
35302
|
const parsed2 = JSON.parse(raw);
|
|
@@ -35821,7 +35319,7 @@ function parseKeyFile(raw) {
|
|
|
35821
35319
|
function readFingerprintKey(dataDir2) {
|
|
35822
35320
|
let raw;
|
|
35823
35321
|
try {
|
|
35824
|
-
raw =
|
|
35322
|
+
raw = readFileSync7(keyFilePath(dataDir2), "utf8");
|
|
35825
35323
|
} catch (err) {
|
|
35826
35324
|
if (err.code === "ENOENT") return null;
|
|
35827
35325
|
throw err instanceof Error ? err : new Error(String(err));
|
|
@@ -35830,8 +35328,8 @@ function readFingerprintKey(dataDir2) {
|
|
|
35830
35328
|
}
|
|
35831
35329
|
|
|
35832
35330
|
// ../../packages/persistence/src/forward-health.ts
|
|
35833
|
-
import { readFileSync as
|
|
35834
|
-
import { join as
|
|
35331
|
+
import { readFileSync as readFileSync8 } from "fs";
|
|
35332
|
+
import { join as join10 } from "path";
|
|
35835
35333
|
var BREAKER_COOLDOWN_MS = 3e4;
|
|
35836
35334
|
function parseForwardHealth(raw, nowMs) {
|
|
35837
35335
|
try {
|
|
@@ -35855,20 +35353,21 @@ function isForwardPaused(health, nowMs) {
|
|
|
35855
35353
|
|
|
35856
35354
|
// ../../packages/persistence/src/history-backfill.ts
|
|
35857
35355
|
import { existsSync as existsSync4 } from "fs";
|
|
35858
|
-
import { join as
|
|
35356
|
+
import { join as join11 } from "path";
|
|
35859
35357
|
|
|
35860
35358
|
// ../../packages/persistence/src/history-preview.ts
|
|
35861
35359
|
import { existsSync as existsSync5 } from "fs";
|
|
35862
|
-
import { join as
|
|
35863
|
-
import { DatabaseSync as
|
|
35360
|
+
import { join as join12 } from "path";
|
|
35361
|
+
import { DatabaseSync as DatabaseSync2 } from "node:sqlite";
|
|
35864
35362
|
|
|
35865
35363
|
// ../../packages/persistence/src/history-sync-state.ts
|
|
35866
|
-
import { readFileSync as
|
|
35867
|
-
import { join as
|
|
35364
|
+
import { readFileSync as readFileSync9 } from "fs";
|
|
35365
|
+
import { join as join13 } from "path";
|
|
35366
|
+
var COUNTS_SCOPES = new Set(AttachmentMode.options);
|
|
35868
35367
|
|
|
35869
35368
|
// ../../packages/persistence/src/store-symlinks.ts
|
|
35870
35369
|
import { existsSync as existsSync6, lstatSync as lstatSync3, readlinkSync, realpathSync, statSync as statSync4 } from "fs";
|
|
35871
|
-
import { dirname as dirname3, join as
|
|
35370
|
+
import { dirname as dirname3, join as join14, resolve } from "path";
|
|
35872
35371
|
|
|
35873
35372
|
// ../../packages/persistence/src/vault/crypto.ts
|
|
35874
35373
|
import {
|
|
@@ -35882,19 +35381,19 @@ import {
|
|
|
35882
35381
|
// ../../packages/persistence/src/vault/key-provider.ts
|
|
35883
35382
|
import { execFileSync } from "child_process";
|
|
35884
35383
|
import { randomBytes as randomBytes2 } from "crypto";
|
|
35885
|
-
import { chmodSync as chmodSync3, readFileSync as
|
|
35886
|
-
import { join as
|
|
35384
|
+
import { chmodSync as chmodSync3, readFileSync as readFileSync10, renameSync as renameSync4, rmSync as rmSync6, statSync as statSync5, writeFileSync as writeFileSync3 } from "fs";
|
|
35385
|
+
import { join as join15 } from "path";
|
|
35887
35386
|
|
|
35888
35387
|
// ../../packages/persistence/src/vault/vault.ts
|
|
35889
35388
|
import { randomBytes as randomBytes3, randomUUID as randomUUID12 } from "crypto";
|
|
35890
35389
|
|
|
35891
35390
|
// ../../packages/persistence/src/warn-era-cap.ts
|
|
35892
35391
|
import { existsSync as existsSync7, writeFileSync as writeFileSync4 } from "fs";
|
|
35893
|
-
import { join as
|
|
35392
|
+
import { join as join16 } from "path";
|
|
35894
35393
|
var MARKER = "warn-era-capped";
|
|
35895
35394
|
function capWarnEraEnforcementOnce(db, policyMode, dataDir2) {
|
|
35896
35395
|
if (policyMode !== "warn") return { capped: 0, skipped: "not-warn" };
|
|
35897
|
-
const marker =
|
|
35396
|
+
const marker = join16(dataDir2, MARKER);
|
|
35898
35397
|
if (existsSync7(marker)) return { capped: 0, skipped: "already-run" };
|
|
35899
35398
|
const capped = db.policies.capCategoryActions();
|
|
35900
35399
|
writeFileSync4(marker, `${new Date(Date.now()).toISOString()}
|
|
@@ -35902,425 +35401,6 @@ function capWarnEraEnforcementOnce(db, policyMode, dataDir2) {
|
|
|
35902
35401
|
return { capped };
|
|
35903
35402
|
}
|
|
35904
35403
|
|
|
35905
|
-
// ../../packages/remote/src/http.ts
|
|
35906
|
-
import { request as httpRequest } from "http";
|
|
35907
|
-
import { request as httpsRequest } from "https";
|
|
35908
|
-
var DEFAULT_TIMEOUT_MS = 1e4;
|
|
35909
|
-
var MAX_RESPONSE_BYTES = 8 * 1024 * 1024;
|
|
35910
|
-
var RemoteRequestError = class extends Error {
|
|
35911
|
-
constructor(status) {
|
|
35912
|
-
super(`control-plane request failed with status ${String(status)}`);
|
|
35913
|
-
this.status = status;
|
|
35914
|
-
this.name = "RemoteRequestError";
|
|
35915
|
-
}
|
|
35916
|
-
status;
|
|
35917
|
-
};
|
|
35918
|
-
var RemoteRouteAbsent = class extends Error {
|
|
35919
|
-
constructor(route) {
|
|
35920
|
-
super(`control plane does not serve ${route}`);
|
|
35921
|
-
this.route = route;
|
|
35922
|
-
this.name = "RemoteRouteAbsent";
|
|
35923
|
-
}
|
|
35924
|
-
route;
|
|
35925
|
-
};
|
|
35926
|
-
var RemoteRequestInvalid = class extends Error {
|
|
35927
|
-
constructor(route, cause) {
|
|
35928
|
-
super(`refusing to send a malformed body to ${route}`);
|
|
35929
|
-
this.cause = cause;
|
|
35930
|
-
this.name = "RemoteRequestInvalid";
|
|
35931
|
-
}
|
|
35932
|
-
cause;
|
|
35933
|
-
};
|
|
35934
|
-
var RemoteEndpointRefused = class extends Error {
|
|
35935
|
-
constructor(endpoint) {
|
|
35936
|
-
super(`refusing to talk to an unsafe control-plane endpoint: ${originOnly(endpoint)}`);
|
|
35937
|
-
this.name = "RemoteEndpointRefused";
|
|
35938
|
-
}
|
|
35939
|
-
};
|
|
35940
|
-
var RemoteResponseInvalid = class extends Error {
|
|
35941
|
-
constructor(route, detail) {
|
|
35942
|
-
super(`control plane answered ${route} with ${detail}`);
|
|
35943
|
-
this.name = "RemoteResponseInvalid";
|
|
35944
|
-
}
|
|
35945
|
-
};
|
|
35946
|
-
var RemoteTransportError = class extends Error {
|
|
35947
|
-
/**
|
|
35948
|
-
* The status the peer sent, when headers arrived and only the BODY was
|
|
35949
|
-
* refused.
|
|
35950
|
-
*
|
|
35951
|
-
* Undefined for the ordinary case this class was written for — no answer at
|
|
35952
|
-
* all. It exists because two paths reject after a status has already been
|
|
35953
|
-
* delivered: an oversized body and an aborted response. Discarding it there
|
|
35954
|
-
* reported a deployment answering 401 with a verbose body as a network
|
|
35955
|
-
* outage, which sends the reader to look at their network instead of their
|
|
35956
|
-
* credential.
|
|
35957
|
-
*/
|
|
35958
|
-
constructor(reason, status) {
|
|
35959
|
-
super(`control-plane request did not complete: ${reason}`);
|
|
35960
|
-
this.status = status;
|
|
35961
|
-
this.name = "RemoteTransportError";
|
|
35962
|
-
}
|
|
35963
|
-
status;
|
|
35964
|
-
};
|
|
35965
|
-
async function send(options) {
|
|
35966
|
-
const url2 = new URL(options.url);
|
|
35967
|
-
const timeoutMs = options.timeoutMs ?? DEFAULT_TIMEOUT_MS;
|
|
35968
|
-
const send_ = url2.protocol === "http:" ? httpRequest : httpsRequest;
|
|
35969
|
-
const requestOptions = {
|
|
35970
|
-
method: options.method,
|
|
35971
|
-
headers: {
|
|
35972
|
-
// CALLER HEADERS FIRST, so this module's own are not overridable. Spread
|
|
35973
|
-
// last they win, and two of the values below are ones no caller may
|
|
35974
|
-
// replace: `x-api-key` is the credential, and `content-length` is the
|
|
35975
|
-
// byte count that stops a multi-byte body being truncated by the
|
|
35976
|
-
// receiver. `SendOptions.headers` is a free-form record on an exported
|
|
35977
|
-
// function, so "no caller does that today" is not the guarantee to rely
|
|
35978
|
-
// on. The one header any caller actually passes — `if-none-match` on the
|
|
35979
|
-
// conditional GET — is untouched by this order.
|
|
35980
|
-
...options.headers,
|
|
35981
|
-
// The credential. One header, matching what the deployment authenticates
|
|
35982
|
-
// on; a second copy in an `Authorization` header would be one more place
|
|
35983
|
-
// it can be logged by an intermediary for no gain.
|
|
35984
|
-
//
|
|
35985
|
-
// Spread conditionally rather than assigned as `undefined`: Node's header
|
|
35986
|
-
// handling and `content-length` bookkeeping treat a present-but-undefined
|
|
35987
|
-
// key differently from an absent one, and "the header is not there" is
|
|
35988
|
-
// the property the attach flow needs.
|
|
35989
|
-
...options.apiKey === void 0 ? {} : { "x-api-key": options.apiKey },
|
|
35990
|
-
accept: "application/json",
|
|
35991
|
-
...options.body === void 0 ? {} : {
|
|
35992
|
-
"content-type": "application/json",
|
|
35993
|
-
// Byte length, not string length: a multi-byte body sent with a
|
|
35994
|
-
// character count is truncated by the receiver.
|
|
35995
|
-
"content-length": String(Buffer.byteLength(options.body))
|
|
35996
|
-
}
|
|
35997
|
-
}
|
|
35998
|
-
};
|
|
35999
|
-
return new Promise((resolve3, reject) => {
|
|
36000
|
-
let settled = false;
|
|
36001
|
-
const fail = (reason, status) => {
|
|
36002
|
-
if (settled) return;
|
|
36003
|
-
settled = true;
|
|
36004
|
-
reject(new RemoteTransportError(reason, status));
|
|
36005
|
-
};
|
|
36006
|
-
const req = send_(url2, requestOptions, (res) => {
|
|
36007
|
-
const chunks = [];
|
|
36008
|
-
let size = 0;
|
|
36009
|
-
res.on("data", (chunk) => {
|
|
36010
|
-
size += chunk.length;
|
|
36011
|
-
if (size > MAX_RESPONSE_BYTES) {
|
|
36012
|
-
fail(`response exceeded ${String(MAX_RESPONSE_BYTES)} bytes`, res.statusCode);
|
|
36013
|
-
res.destroy();
|
|
36014
|
-
req.destroy();
|
|
36015
|
-
return;
|
|
36016
|
-
}
|
|
36017
|
-
chunks.push(chunk);
|
|
36018
|
-
});
|
|
36019
|
-
res.on("aborted", () => {
|
|
36020
|
-
fail("the response was aborted", res.statusCode);
|
|
36021
|
-
});
|
|
36022
|
-
res.on("end", () => {
|
|
36023
|
-
if (settled) return;
|
|
36024
|
-
settled = true;
|
|
36025
|
-
resolve3({
|
|
36026
|
-
status: res.statusCode ?? 0,
|
|
36027
|
-
headers: res.headers,
|
|
36028
|
-
body: Buffer.concat(chunks).toString("utf8")
|
|
36029
|
-
});
|
|
36030
|
-
});
|
|
36031
|
-
});
|
|
36032
|
-
const deadline = setTimeout(() => {
|
|
36033
|
-
fail(`no response within ${String(timeoutMs)}ms`);
|
|
36034
|
-
req.destroy();
|
|
36035
|
-
}, timeoutMs);
|
|
36036
|
-
deadline.unref();
|
|
36037
|
-
req.on("upgrade", (_res, socket) => {
|
|
36038
|
-
fail("the deployment answered with a protocol upgrade");
|
|
36039
|
-
socket.destroy();
|
|
36040
|
-
});
|
|
36041
|
-
req.on("close", () => {
|
|
36042
|
-
fail("the connection closed before a response was read");
|
|
36043
|
-
clearTimeout(deadline);
|
|
36044
|
-
});
|
|
36045
|
-
req.on("error", (err) => {
|
|
36046
|
-
fail(err.message);
|
|
36047
|
-
});
|
|
36048
|
-
if (options.body !== void 0) req.write(options.body);
|
|
36049
|
-
req.end();
|
|
36050
|
-
});
|
|
36051
|
-
}
|
|
36052
|
-
|
|
36053
|
-
// ../../packages/remote/src/client.ts
|
|
36054
|
-
var ROUTES = {
|
|
36055
|
-
events: "/v1/events",
|
|
36056
|
-
auditEvents: "/v1/audit-events",
|
|
36057
|
-
auditEventsBatch: "/v1/audit-events/batch",
|
|
36058
|
-
inventory: "/v1/inventory",
|
|
36059
|
-
storePosture: "/v1/store-posture",
|
|
36060
|
-
policyBundle: "/v1/policy-bundle",
|
|
36061
|
-
whoami: "/v1/plugin/whoami",
|
|
36062
|
-
shares: "/v1/shares",
|
|
36063
|
-
commands: "/v1/plugin/commands"
|
|
36064
|
-
};
|
|
36065
|
-
function ackRoute(id) {
|
|
36066
|
-
return `${ROUTES.commands}/${encodeURIComponent(id)}/ack`;
|
|
36067
|
-
}
|
|
36068
|
-
function headerValue(response, name) {
|
|
36069
|
-
const raw = response.headers[name];
|
|
36070
|
-
if (raw === void 0) return void 0;
|
|
36071
|
-
return Array.isArray(raw) ? raw[0] : raw;
|
|
36072
|
-
}
|
|
36073
|
-
function okBody(response) {
|
|
36074
|
-
if (response.status < 200 || response.status >= 300) {
|
|
36075
|
-
throw new RemoteRequestError(response.status);
|
|
36076
|
-
}
|
|
36077
|
-
return response.body;
|
|
36078
|
-
}
|
|
36079
|
-
function parsed(schema, body, route) {
|
|
36080
|
-
let json2;
|
|
36081
|
-
try {
|
|
36082
|
-
json2 = JSON.parse(body);
|
|
36083
|
-
} catch {
|
|
36084
|
-
throw new RemoteResponseInvalid(route, "a body that is not JSON");
|
|
36085
|
-
}
|
|
36086
|
-
const result = schema.safeParse(json2);
|
|
36087
|
-
if (!result.success) {
|
|
36088
|
-
throw new RemoteResponseInvalid(route, "a body this client cannot read");
|
|
36089
|
-
}
|
|
36090
|
-
return result.data;
|
|
36091
|
-
}
|
|
36092
|
-
function resolveBaseUrl(endpoint) {
|
|
36093
|
-
if (!isSafeEndpoint(endpoint)) throw new RemoteEndpointRefused(endpoint);
|
|
36094
|
-
let end = endpoint.length;
|
|
36095
|
-
while (end > 0 && endpoint.charCodeAt(end - 1) === SLASH2) end -= 1;
|
|
36096
|
-
return endpoint.slice(0, end);
|
|
36097
|
-
}
|
|
36098
|
-
var SLASH2 = "/".charCodeAt(0);
|
|
36099
|
-
function createRemoteClient(options) {
|
|
36100
|
-
const base = resolveBaseUrl(options.endpoint);
|
|
36101
|
-
const url2 = (route) => `${base}${route}`;
|
|
36102
|
-
const common = { apiKey: options.apiKey, timeoutMs: options.timeoutMs };
|
|
36103
|
-
const sendOne = async (event) => {
|
|
36104
|
-
const validated = RecordAuditEventRequest.safeParse(event);
|
|
36105
|
-
if (!validated.success) throw new RemoteRequestInvalid(ROUTES.auditEvents, validated.error);
|
|
36106
|
-
const response = await send({
|
|
36107
|
-
...common,
|
|
36108
|
-
method: "POST",
|
|
36109
|
-
url: url2(ROUTES.auditEvents),
|
|
36110
|
-
body: JSON.stringify(validated.data)
|
|
36111
|
-
});
|
|
36112
|
-
okBody(response);
|
|
36113
|
-
};
|
|
36114
|
-
return {
|
|
36115
|
-
async ingestEvents(batch) {
|
|
36116
|
-
const response = await send({
|
|
36117
|
-
...common,
|
|
36118
|
-
method: "POST",
|
|
36119
|
-
url: url2(ROUTES.events),
|
|
36120
|
-
body: JSON.stringify(batch)
|
|
36121
|
-
});
|
|
36122
|
-
return parsed(IngestAck, okBody(response), ROUTES.events);
|
|
36123
|
-
},
|
|
36124
|
-
async ingestInventory(context) {
|
|
36125
|
-
const response = await send({
|
|
36126
|
-
...common,
|
|
36127
|
-
method: "POST",
|
|
36128
|
-
url: url2(ROUTES.inventory),
|
|
36129
|
-
body: JSON.stringify(context)
|
|
36130
|
-
});
|
|
36131
|
-
return parsed(ResolvedInventory, okBody(response), ROUTES.inventory);
|
|
36132
|
-
},
|
|
36133
|
-
async recordAuditEvent(event) {
|
|
36134
|
-
await sendOne(event);
|
|
36135
|
-
},
|
|
36136
|
-
async recordAuditEvents(events, opts) {
|
|
36137
|
-
const validated = RecordAuditEventBatch.safeParse({ events });
|
|
36138
|
-
if (!validated.success) {
|
|
36139
|
-
throw new RemoteRequestInvalid(ROUTES.auditEventsBatch, validated.error);
|
|
36140
|
-
}
|
|
36141
|
-
const response = await send({
|
|
36142
|
-
...common,
|
|
36143
|
-
method: "POST",
|
|
36144
|
-
url: url2(ROUTES.auditEventsBatch),
|
|
36145
|
-
body: JSON.stringify(validated.data)
|
|
36146
|
-
});
|
|
36147
|
-
if (response.status === 404) {
|
|
36148
|
-
if (opts?.fallbackToSingleEvents !== true) {
|
|
36149
|
-
throw new RemoteRouteAbsent(ROUTES.auditEventsBatch);
|
|
36150
|
-
}
|
|
36151
|
-
for (const event of validated.data.events) await sendOne(event);
|
|
36152
|
-
return { accepted: validated.data.events.length };
|
|
36153
|
-
}
|
|
36154
|
-
return parsed(AuditEventBatchAck, okBody(response), ROUTES.auditEventsBatch);
|
|
36155
|
-
},
|
|
36156
|
-
async reportStorePosture(snapshot) {
|
|
36157
|
-
const response = await send({
|
|
36158
|
-
...common,
|
|
36159
|
-
method: "POST",
|
|
36160
|
-
url: url2(ROUTES.storePosture),
|
|
36161
|
-
body: JSON.stringify(snapshot)
|
|
36162
|
-
});
|
|
36163
|
-
okBody(response);
|
|
36164
|
-
},
|
|
36165
|
-
async getPolicyBundle(etag) {
|
|
36166
|
-
const response = await send({
|
|
36167
|
-
...common,
|
|
36168
|
-
method: "GET",
|
|
36169
|
-
url: url2(ROUTES.policyBundle),
|
|
36170
|
-
...etag === void 0 ? {} : { headers: { "if-none-match": etag } }
|
|
36171
|
-
});
|
|
36172
|
-
if (response.status === 304) {
|
|
36173
|
-
return { changed: false, etag: headerValue(response, "etag") ?? etag };
|
|
36174
|
-
}
|
|
36175
|
-
const bundle = parsed(PolicyBundle, okBody(response), ROUTES.policyBundle);
|
|
36176
|
-
return { changed: true, bundle, etag: headerValue(response, "etag") };
|
|
36177
|
-
},
|
|
36178
|
-
async whoami() {
|
|
36179
|
-
const response = await send({ ...common, method: "GET", url: url2(ROUTES.whoami) });
|
|
36180
|
-
return parsed(PluginWhoami, okBody(response), ROUTES.whoami);
|
|
36181
|
-
},
|
|
36182
|
-
async recordProjectEgress(request) {
|
|
36183
|
-
const validated = EgressIngestRequest.safeParse(request);
|
|
36184
|
-
if (!validated.success) throw new RemoteRequestInvalid(ROUTES.shares, validated.error);
|
|
36185
|
-
const response = await send({
|
|
36186
|
-
...common,
|
|
36187
|
-
method: "POST",
|
|
36188
|
-
url: url2(ROUTES.shares),
|
|
36189
|
-
body: JSON.stringify(validated.data)
|
|
36190
|
-
});
|
|
36191
|
-
if (response.status === 404) throw new RemoteRouteAbsent(ROUTES.shares);
|
|
36192
|
-
okBody(response);
|
|
36193
|
-
},
|
|
36194
|
-
async pollCommand() {
|
|
36195
|
-
const response = await send({ ...common, method: "GET", url: url2(ROUTES.commands) });
|
|
36196
|
-
if (response.status === 404) return null;
|
|
36197
|
-
return parsed(DeviceCommandPollResponse, okBody(response), ROUTES.commands).command;
|
|
36198
|
-
},
|
|
36199
|
-
async ackCommand(id, body) {
|
|
36200
|
-
const validated = DeviceCommandAckBody.safeParse(body);
|
|
36201
|
-
const route = ackRoute(id);
|
|
36202
|
-
if (!validated.success) throw new RemoteRequestInvalid(route, validated.error);
|
|
36203
|
-
const response = await send({
|
|
36204
|
-
...common,
|
|
36205
|
-
method: "POST",
|
|
36206
|
-
url: url2(route),
|
|
36207
|
-
body: JSON.stringify(validated.data)
|
|
36208
|
-
});
|
|
36209
|
-
okBody(response);
|
|
36210
|
-
}
|
|
36211
|
-
};
|
|
36212
|
-
}
|
|
36213
|
-
|
|
36214
|
-
// ../../packages/remote/src/failure-kind.ts
|
|
36215
|
-
function statusOf(err) {
|
|
36216
|
-
if (typeof err !== "object" || err === null || !("status" in err)) return null;
|
|
36217
|
-
const { status } = err;
|
|
36218
|
-
if (typeof status !== "number" || !Number.isInteger(status)) return null;
|
|
36219
|
-
return status >= 100 && status <= 599 ? status : null;
|
|
36220
|
-
}
|
|
36221
|
-
function nameOf(err) {
|
|
36222
|
-
if (typeof err !== "object" || err === null || !("name" in err)) return null;
|
|
36223
|
-
return typeof err.name === "string" ? err.name : null;
|
|
36224
|
-
}
|
|
36225
|
-
function classifyRemoteFailure(err) {
|
|
36226
|
-
switch (nameOf(err)) {
|
|
36227
|
-
case "RemoteRouteAbsent":
|
|
36228
|
-
return "route-absent";
|
|
36229
|
-
case "RemoteRequestInvalid":
|
|
36230
|
-
case "RemoteEndpointRefused":
|
|
36231
|
-
return "invalid-request";
|
|
36232
|
-
case "RemoteResponseInvalid":
|
|
36233
|
-
return "rejected";
|
|
36234
|
-
default:
|
|
36235
|
-
break;
|
|
36236
|
-
}
|
|
36237
|
-
const status = statusOf(err);
|
|
36238
|
-
if (status === null) return "unreachable";
|
|
36239
|
-
switch (status) {
|
|
36240
|
-
case 401:
|
|
36241
|
-
return "unauthorized";
|
|
36242
|
-
case 403:
|
|
36243
|
-
return "forbidden";
|
|
36244
|
-
case 429:
|
|
36245
|
-
return "unreachable";
|
|
36246
|
-
case 404:
|
|
36247
|
-
return "unreachable";
|
|
36248
|
-
default:
|
|
36249
|
-
return status >= 400 && status <= 499 ? "rejected" : "unreachable";
|
|
36250
|
-
}
|
|
36251
|
-
}
|
|
36252
|
-
|
|
36253
|
-
// ../../packages/plugin-runtime/src/attached/failure.ts
|
|
36254
|
-
function classifyFailure(err) {
|
|
36255
|
-
switch (classifyRemoteFailure(err)) {
|
|
36256
|
-
case "unauthorized":
|
|
36257
|
-
return "unauthorized";
|
|
36258
|
-
case "forbidden":
|
|
36259
|
-
return "forbidden";
|
|
36260
|
-
default:
|
|
36261
|
-
return "unreachable";
|
|
36262
|
-
}
|
|
36263
|
-
}
|
|
36264
|
-
|
|
36265
|
-
// ../../packages/plugin-runtime/src/attached/with-timeout.ts
|
|
36266
|
-
var REQUEST_TIMEOUT_MS = 2e3;
|
|
36267
|
-
function withTimeout(promise2, ms) {
|
|
36268
|
-
let timer;
|
|
36269
|
-
const timeout = new Promise((_, reject) => {
|
|
36270
|
-
timer = setTimeout(() => {
|
|
36271
|
-
reject(new Error("attached gateway request timed out"));
|
|
36272
|
-
}, ms);
|
|
36273
|
-
});
|
|
36274
|
-
promise2.catch(() => void 0);
|
|
36275
|
-
return Promise.race([promise2, timeout]).finally(() => {
|
|
36276
|
-
clearTimeout(timer);
|
|
36277
|
-
});
|
|
36278
|
-
}
|
|
36279
|
-
|
|
36280
|
-
// ../../packages/plugin-runtime/src/attached/forward-drops.ts
|
|
36281
|
-
import { readFileSync as readFileSync10 } from "fs";
|
|
36282
|
-
import { join as join16 } from "path";
|
|
36283
|
-
var FORWARD_DROPS_FILENAME = ATTACHED_FORWARD_DROPS_FILENAME;
|
|
36284
|
-
function forwardDropsPath(dataDir2) {
|
|
36285
|
-
return join16(dataDir2, FORWARD_DROPS_FILENAME);
|
|
36286
|
-
}
|
|
36287
|
-
function recordForwardDrops(dataDir2, count, nowMs) {
|
|
36288
|
-
if (count <= 0) return;
|
|
36289
|
-
try {
|
|
36290
|
-
ensureDataDirSync(dataDir2);
|
|
36291
|
-
const previous = readForwardDrops(dataDir2);
|
|
36292
|
-
const next = {
|
|
36293
|
-
droppedForwards: (previous?.droppedForwards ?? 0) + count,
|
|
36294
|
-
lastDropAtMs: nowMs
|
|
36295
|
-
};
|
|
36296
|
-
writeOwnerOnlyFileSync(forwardDropsPath(dataDir2), `${JSON.stringify(next)}
|
|
36297
|
-
`);
|
|
36298
|
-
} catch {
|
|
36299
|
-
}
|
|
36300
|
-
}
|
|
36301
|
-
function readForwardDrops(dataDir2) {
|
|
36302
|
-
try {
|
|
36303
|
-
const parsed2 = JSON.parse(readFileSync10(forwardDropsPath(dataDir2), "utf8"));
|
|
36304
|
-
if (typeof parsed2 !== "object" || parsed2 === null) return null;
|
|
36305
|
-
const record2 = parsed2;
|
|
36306
|
-
if (typeof record2.droppedForwards !== "number" || !Number.isFinite(record2.droppedForwards)) {
|
|
36307
|
-
return null;
|
|
36308
|
-
}
|
|
36309
|
-
if (record2.droppedForwards <= 0) return null;
|
|
36310
|
-
if (typeof record2.lastDropAtMs !== "number" || !Number.isFinite(record2.lastDropAtMs)) {
|
|
36311
|
-
return null;
|
|
36312
|
-
}
|
|
36313
|
-
return { droppedForwards: record2.droppedForwards, lastDropAtMs: record2.lastDropAtMs };
|
|
36314
|
-
} catch {
|
|
36315
|
-
return null;
|
|
36316
|
-
}
|
|
36317
|
-
}
|
|
36318
|
-
|
|
36319
|
-
// ../../packages/plugin-runtime/src/attached/forward-policy.ts
|
|
36320
|
-
import { randomUUID as randomUUID16 } from "crypto";
|
|
36321
|
-
import { readFile, rename, writeFile } from "fs/promises";
|
|
36322
|
-
import { join as join28 } from "path";
|
|
36323
|
-
|
|
36324
35404
|
// ../../packages/plugin-sdk/src/config.ts
|
|
36325
35405
|
import { existsSync as existsSync8 } from "fs";
|
|
36326
35406
|
import { join as join17 } from "path";
|
|
@@ -36400,11 +35480,6 @@ function resolveProviderSafe(resolveProviderFn) {
|
|
|
36400
35480
|
}
|
|
36401
35481
|
}
|
|
36402
35482
|
|
|
36403
|
-
// ../../packages/plugin-sdk/src/config-inventory.ts
|
|
36404
|
-
import { readdirSync as readdirSync2, readFileSync as readFileSync12, realpathSync as realpathSync2, statSync as statSync7 } from "fs";
|
|
36405
|
-
import { homedir as homedir2 } from "os";
|
|
36406
|
-
import { basename as basename3, join as join19 } from "path";
|
|
36407
|
-
|
|
36408
35483
|
// ../../packages/detections/src/egress/registry.ts
|
|
36409
35484
|
var EXTRACTOR_VERSION = "3";
|
|
36410
35485
|
var PROVIDER_REGISTRY = [
|
|
@@ -37079,12 +36154,12 @@ var RegexMatcher2 = class {
|
|
|
37079
36154
|
rule.matcher,
|
|
37080
36155
|
() => new RegExp(pattern, flags.includes("d") ? flags : `${flags}d`)
|
|
37081
36156
|
);
|
|
37082
|
-
const
|
|
36157
|
+
const scanText = text.length > MAX_REGEX_INPUT_LENGTH ? text.slice(0, MAX_REGEX_INPUT_LENGTH) : text;
|
|
37083
36158
|
const spans = [];
|
|
37084
36159
|
let m;
|
|
37085
|
-
const maxIterations =
|
|
36160
|
+
const maxIterations = scanText.length + 1;
|
|
37086
36161
|
let iterations = 0;
|
|
37087
|
-
while ((m = re.exec(
|
|
36162
|
+
while ((m = re.exec(scanText)) !== null) {
|
|
37088
36163
|
if (++iterations > maxIterations) break;
|
|
37089
36164
|
const group = captureGroup != null ? m[captureGroup] : m[0];
|
|
37090
36165
|
if (m[0].length === 0) re.lastIndex++;
|
|
@@ -39503,146 +38578,446 @@ function bundledDetections() {
|
|
|
39503
38578
|
}));
|
|
39504
38579
|
return cachedDetections;
|
|
39505
38580
|
}
|
|
39506
|
-
|
|
39507
|
-
|
|
39508
|
-
|
|
39509
|
-
|
|
39510
|
-
|
|
38581
|
+
function shippedRegexMatchers() {
|
|
38582
|
+
return bundledDetections().flatMap((pack) => pack.rules).flatMap(
|
|
38583
|
+
(rule) => rule.matcher.type === "regex" ? [{ pattern: rule.matcher.pattern, flags: rule.matcher.flags }] : []
|
|
38584
|
+
);
|
|
38585
|
+
}
|
|
39511
38586
|
|
|
39512
38587
|
// ../../packages/plugin-sdk/src/data-gateway.ts
|
|
39513
38588
|
function offersCaptureStatusReader(gateway) {
|
|
39514
38589
|
return typeof gateway.readCaptureStatuses === "function";
|
|
39515
38590
|
}
|
|
39516
38591
|
|
|
39517
|
-
// ../../packages/plugin-sdk/src/events.ts
|
|
39518
|
-
import { createHash as createHash5, randomUUID as randomUUID13 } from "crypto";
|
|
39519
|
-
|
|
39520
|
-
// ../../packages/plugin-sdk/src/isolated-scan.ts
|
|
39521
|
-
import { existsSync as existsSync10 } from "fs";
|
|
39522
|
-
import { fileURLToPath } from "url";
|
|
39523
|
-
import { Worker } from "worker_threads";
|
|
39524
|
-
|
|
39525
|
-
// ../../packages/plugin-sdk/src/hook-fail-opens.ts
|
|
39526
|
-
import { readFileSync as readFileSync13 } from "fs";
|
|
39527
|
-
import { join as join20 } from "path";
|
|
39528
|
-
|
|
39529
|
-
// ../../packages/plugin-sdk/src/host-floor.ts
|
|
39530
|
-
import { readFileSync as readFileSync15 } from "fs";
|
|
39531
|
-
import { join as join22 } from "path";
|
|
39532
|
-
|
|
39533
|
-
// ../../packages/plugin-sdk/src/model-governance.ts
|
|
39534
|
-
import {
|
|
39535
|
-
closeSync as closeSync2,
|
|
39536
|
-
fstatSync,
|
|
39537
|
-
mkdirSync as mkdirSync2,
|
|
39538
|
-
openSync as openSync2,
|
|
39539
|
-
readFileSync as readFileSync14,
|
|
39540
|
-
readSync,
|
|
39541
|
-
writeFileSync as writeFileSync5
|
|
39542
|
-
} from "fs";
|
|
39543
|
-
import { join as join21 } from "path";
|
|
39544
|
-
var TAIL_BYTES = 256 * 1024;
|
|
39545
|
-
|
|
39546
|
-
// ../../packages/plugin-sdk/src/host-floor.ts
|
|
39547
|
-
var HOST_FEATURE = {
|
|
39548
|
-
ModelSwitch: "model-switch",
|
|
39549
|
-
VaultPointerDisplay: "vault-pointer-display"
|
|
39550
|
-
};
|
|
39551
|
-
var HOST_FLOORS = {
|
|
39552
|
-
[HOST_FEATURE.ModelSwitch]: {
|
|
39553
|
-
label: "model-switch protection",
|
|
39554
|
-
hookEvents: ["PreModelSwitch", "PostModelSwitch"],
|
|
39555
|
-
since: "2.1.251"
|
|
39556
|
-
},
|
|
39557
|
-
[HOST_FEATURE.VaultPointerDisplay]: {
|
|
39558
|
-
label: "vault pointer display",
|
|
39559
|
-
hookEvents: ["MessageDisplay"],
|
|
39560
|
-
since: "2.1.152"
|
|
39561
|
-
}
|
|
39562
|
-
};
|
|
39563
|
-
var ANTIGRAVITY_HOST_FEATURE = {
|
|
39564
|
-
EndOfTurnCapture: "end-of-turn-capture"
|
|
39565
|
-
};
|
|
39566
|
-
var ANTIGRAVITY_HOST_FLOORS = {
|
|
39567
|
-
[ANTIGRAVITY_HOST_FEATURE.EndOfTurnCapture]: {
|
|
39568
|
-
label: "end-of-turn history capture",
|
|
39569
|
-
hookEvents: ["Stop"],
|
|
39570
|
-
since: "1.1.10"
|
|
39571
|
-
}
|
|
39572
|
-
};
|
|
39573
|
-
|
|
39574
|
-
// ../../packages/plugin-sdk/src/ignore-layers.ts
|
|
39575
|
-
var import_ignore = __toESM(require_ignore(), 1);
|
|
39576
|
-
import { readFileSync as readFileSync16 } from "fs";
|
|
39577
|
-
import { join as join23 } from "path";
|
|
39578
|
-
|
|
39579
|
-
// ../../packages/plugin-sdk/src/inventory-resolver.ts
|
|
39580
|
-
import { arch, hostname as hostname4, platform, release } from "os";
|
|
39581
|
-
|
|
39582
|
-
// ../../packages/plugin-sdk/src/nudge.ts
|
|
39583
|
-
import { mkdirSync as mkdirSync3, readFileSync as readFileSync17, writeFileSync as writeFileSync6 } from "fs";
|
|
39584
|
-
import { join as join24 } from "path";
|
|
39585
|
-
|
|
39586
|
-
// ../../packages/plugin-sdk/src/paths.ts
|
|
39587
|
-
import { readdirSync as readdirSync3, realpathSync as realpathSync3 } from "fs";
|
|
39588
|
-
import { basename as basename4, dirname as dirname5, sep as sep3 } from "path";
|
|
39589
|
-
|
|
39590
38592
|
// ../../packages/plugin-sdk/src/policy-resolver.ts
|
|
39591
|
-
import { randomUUID as
|
|
38593
|
+
import { randomUUID as randomUUID13 } from "crypto";
|
|
39592
38594
|
function assignedRulePolicies(installed) {
|
|
39593
38595
|
const out = [];
|
|
39594
38596
|
for (const [ruleId, action] of installed.ruleActions) {
|
|
39595
38597
|
if (installed.assignedRules && !installed.assignedRules.has(ruleId)) continue;
|
|
39596
|
-
out.push({ id:
|
|
38598
|
+
out.push({ id: randomUUID13(), scope: "global", target: { ruleId }, action, enabled: true });
|
|
39597
38599
|
}
|
|
39598
38600
|
return out;
|
|
39599
38601
|
}
|
|
39600
38602
|
|
|
39601
|
-
// ../../packages/
|
|
39602
|
-
import {
|
|
39603
|
-
import {
|
|
38603
|
+
// ../../packages/remote/src/http.ts
|
|
38604
|
+
import { request as httpRequest } from "http";
|
|
38605
|
+
import { request as httpsRequest } from "https";
|
|
38606
|
+
var DEFAULT_TIMEOUT_MS = 1e4;
|
|
38607
|
+
var MAX_RESPONSE_BYTES = 8 * 1024 * 1024;
|
|
38608
|
+
var RemoteRequestError = class extends Error {
|
|
38609
|
+
constructor(status) {
|
|
38610
|
+
super(`control-plane request failed with status ${String(status)}`);
|
|
38611
|
+
this.status = status;
|
|
38612
|
+
this.name = "RemoteRequestError";
|
|
38613
|
+
}
|
|
38614
|
+
status;
|
|
38615
|
+
};
|
|
38616
|
+
var RemoteRouteAbsent = class extends Error {
|
|
38617
|
+
constructor(route) {
|
|
38618
|
+
super(`control plane does not serve ${route}`);
|
|
38619
|
+
this.route = route;
|
|
38620
|
+
this.name = "RemoteRouteAbsent";
|
|
38621
|
+
}
|
|
38622
|
+
route;
|
|
38623
|
+
};
|
|
38624
|
+
var RemoteRequestInvalid = class extends Error {
|
|
38625
|
+
constructor(route, cause) {
|
|
38626
|
+
super(`refusing to send a malformed body to ${route}`);
|
|
38627
|
+
this.cause = cause;
|
|
38628
|
+
this.name = "RemoteRequestInvalid";
|
|
38629
|
+
}
|
|
38630
|
+
cause;
|
|
38631
|
+
};
|
|
38632
|
+
var RemoteEndpointRefused = class extends Error {
|
|
38633
|
+
constructor(endpoint) {
|
|
38634
|
+
super(`refusing to talk to an unsafe control-plane endpoint: ${originOnly(endpoint)}`);
|
|
38635
|
+
this.name = "RemoteEndpointRefused";
|
|
38636
|
+
}
|
|
38637
|
+
};
|
|
38638
|
+
var RemoteResponseInvalid = class extends Error {
|
|
38639
|
+
constructor(route, detail) {
|
|
38640
|
+
super(`control plane answered ${route} with ${detail}`);
|
|
38641
|
+
this.name = "RemoteResponseInvalid";
|
|
38642
|
+
}
|
|
38643
|
+
};
|
|
38644
|
+
var RemoteTransportError = class extends Error {
|
|
38645
|
+
/**
|
|
38646
|
+
* The status the peer sent, when headers arrived and only the BODY was
|
|
38647
|
+
* refused.
|
|
38648
|
+
*
|
|
38649
|
+
* Undefined for the ordinary case this class was written for — no answer at
|
|
38650
|
+
* all. It exists because two paths reject after a status has already been
|
|
38651
|
+
* delivered: an oversized body and an aborted response. Discarding it there
|
|
38652
|
+
* reported a deployment answering 401 with a verbose body as a network
|
|
38653
|
+
* outage, which sends the reader to look at their network instead of their
|
|
38654
|
+
* credential.
|
|
38655
|
+
*/
|
|
38656
|
+
constructor(reason, status) {
|
|
38657
|
+
super(`control-plane request did not complete: ${reason}`);
|
|
38658
|
+
this.status = status;
|
|
38659
|
+
this.name = "RemoteTransportError";
|
|
38660
|
+
}
|
|
38661
|
+
status;
|
|
38662
|
+
};
|
|
38663
|
+
async function send(options) {
|
|
38664
|
+
const url2 = new URL(options.url);
|
|
38665
|
+
const timeoutMs = options.timeoutMs ?? DEFAULT_TIMEOUT_MS;
|
|
38666
|
+
const send_ = url2.protocol === "http:" ? httpRequest : httpsRequest;
|
|
38667
|
+
const requestOptions = {
|
|
38668
|
+
method: options.method,
|
|
38669
|
+
headers: {
|
|
38670
|
+
// CALLER HEADERS FIRST, so this module's own are not overridable. Spread
|
|
38671
|
+
// last they win, and two of the values below are ones no caller may
|
|
38672
|
+
// replace: `x-api-key` is the credential, and `content-length` is the
|
|
38673
|
+
// byte count that stops a multi-byte body being truncated by the
|
|
38674
|
+
// receiver. `SendOptions.headers` is a free-form record on an exported
|
|
38675
|
+
// function, so "no caller does that today" is not the guarantee to rely
|
|
38676
|
+
// on. The one header any caller actually passes — `if-none-match` on the
|
|
38677
|
+
// conditional GET — is untouched by this order.
|
|
38678
|
+
...options.headers,
|
|
38679
|
+
// The credential. One header, matching what the deployment authenticates
|
|
38680
|
+
// on; a second copy in an `Authorization` header would be one more place
|
|
38681
|
+
// it can be logged by an intermediary for no gain.
|
|
38682
|
+
//
|
|
38683
|
+
// Spread conditionally rather than assigned as `undefined`: Node's header
|
|
38684
|
+
// handling and `content-length` bookkeeping treat a present-but-undefined
|
|
38685
|
+
// key differently from an absent one, and "the header is not there" is
|
|
38686
|
+
// the property the attach flow needs.
|
|
38687
|
+
...options.apiKey === void 0 ? {} : { "x-api-key": options.apiKey },
|
|
38688
|
+
accept: "application/json",
|
|
38689
|
+
...options.body === void 0 ? {} : {
|
|
38690
|
+
"content-type": "application/json",
|
|
38691
|
+
// Byte length, not string length: a multi-byte body sent with a
|
|
38692
|
+
// character count is truncated by the receiver.
|
|
38693
|
+
"content-length": String(Buffer.byteLength(options.body))
|
|
38694
|
+
}
|
|
38695
|
+
}
|
|
38696
|
+
};
|
|
38697
|
+
return new Promise((resolve3, reject) => {
|
|
38698
|
+
let settled = false;
|
|
38699
|
+
const fail = (reason, status) => {
|
|
38700
|
+
if (settled) return;
|
|
38701
|
+
settled = true;
|
|
38702
|
+
reject(new RemoteTransportError(reason, status));
|
|
38703
|
+
};
|
|
38704
|
+
const req = send_(url2, requestOptions, (res) => {
|
|
38705
|
+
const chunks = [];
|
|
38706
|
+
let size = 0;
|
|
38707
|
+
res.on("data", (chunk) => {
|
|
38708
|
+
size += chunk.length;
|
|
38709
|
+
if (size > MAX_RESPONSE_BYTES) {
|
|
38710
|
+
fail(`response exceeded ${String(MAX_RESPONSE_BYTES)} bytes`, res.statusCode);
|
|
38711
|
+
res.destroy();
|
|
38712
|
+
req.destroy();
|
|
38713
|
+
return;
|
|
38714
|
+
}
|
|
38715
|
+
chunks.push(chunk);
|
|
38716
|
+
});
|
|
38717
|
+
res.on("aborted", () => {
|
|
38718
|
+
fail("the response was aborted", res.statusCode);
|
|
38719
|
+
});
|
|
38720
|
+
res.on("end", () => {
|
|
38721
|
+
if (settled) return;
|
|
38722
|
+
settled = true;
|
|
38723
|
+
resolve3({
|
|
38724
|
+
status: res.statusCode ?? 0,
|
|
38725
|
+
headers: res.headers,
|
|
38726
|
+
body: Buffer.concat(chunks).toString("utf8")
|
|
38727
|
+
});
|
|
38728
|
+
});
|
|
38729
|
+
});
|
|
38730
|
+
const deadline = setTimeout(() => {
|
|
38731
|
+
fail(`no response within ${String(timeoutMs)}ms`);
|
|
38732
|
+
req.destroy();
|
|
38733
|
+
}, timeoutMs);
|
|
38734
|
+
deadline.unref();
|
|
38735
|
+
req.on("upgrade", (_res, socket) => {
|
|
38736
|
+
fail("the deployment answered with a protocol upgrade");
|
|
38737
|
+
socket.destroy();
|
|
38738
|
+
});
|
|
38739
|
+
req.on("close", () => {
|
|
38740
|
+
fail("the connection closed before a response was read");
|
|
38741
|
+
clearTimeout(deadline);
|
|
38742
|
+
});
|
|
38743
|
+
req.on("error", (err) => {
|
|
38744
|
+
fail(err.message);
|
|
38745
|
+
});
|
|
38746
|
+
if (options.body !== void 0) req.write(options.body);
|
|
38747
|
+
req.end();
|
|
38748
|
+
});
|
|
38749
|
+
}
|
|
39604
38750
|
|
|
39605
|
-
// ../../packages/
|
|
39606
|
-
var
|
|
39607
|
-
|
|
39608
|
-
|
|
39609
|
-
|
|
39610
|
-
|
|
39611
|
-
|
|
39612
|
-
|
|
39613
|
-
|
|
39614
|
-
|
|
39615
|
-
|
|
39616
|
-
GOOGLE_GENAI_USE_VERTEXAI: optionalFlag,
|
|
39617
|
-
GOOGLE_GEMINI_BASE_URL: optionalBaseUrl2
|
|
39618
|
-
};
|
|
39619
|
-
var AntigravityProviderEnvSchema = external_exports.object(antigravityProviderEnvShape);
|
|
39620
|
-
|
|
39621
|
-
// ../../packages/plugin-sdk/src/provider-env-codex.ts
|
|
39622
|
-
var optionalBaseUrl3 = external_exports.preprocess((v) => {
|
|
39623
|
-
if (typeof v === "string" && v.trim() === "") return void 0;
|
|
39624
|
-
return v;
|
|
39625
|
-
}, external_exports.string().optional()).catch(void 0);
|
|
39626
|
-
var codexProviderEnvShape = {
|
|
39627
|
-
OPENAI_BASE_URL: optionalBaseUrl3
|
|
38751
|
+
// ../../packages/remote/src/client.ts
|
|
38752
|
+
var ROUTES = {
|
|
38753
|
+
events: "/v1/events",
|
|
38754
|
+
auditEvents: "/v1/audit-events",
|
|
38755
|
+
auditEventsBatch: "/v1/audit-events/batch",
|
|
38756
|
+
inventory: "/v1/inventory",
|
|
38757
|
+
storePosture: "/v1/store-posture",
|
|
38758
|
+
policyBundle: "/v1/policy-bundle",
|
|
38759
|
+
whoami: "/v1/plugin/whoami",
|
|
38760
|
+
shares: "/v1/shares",
|
|
38761
|
+
commands: "/v1/plugin/commands"
|
|
39628
38762
|
};
|
|
39629
|
-
|
|
38763
|
+
function ackRoute(id) {
|
|
38764
|
+
return `${ROUTES.commands}/${encodeURIComponent(id)}/ack`;
|
|
38765
|
+
}
|
|
38766
|
+
function headerValue(response, name) {
|
|
38767
|
+
const raw = response.headers[name];
|
|
38768
|
+
if (raw === void 0) return void 0;
|
|
38769
|
+
return Array.isArray(raw) ? raw[0] : raw;
|
|
38770
|
+
}
|
|
38771
|
+
function okBody(response) {
|
|
38772
|
+
if (response.status < 200 || response.status >= 300) {
|
|
38773
|
+
throw new RemoteRequestError(response.status);
|
|
38774
|
+
}
|
|
38775
|
+
return response.body;
|
|
38776
|
+
}
|
|
38777
|
+
function parsed(schema, body, route) {
|
|
38778
|
+
let json2;
|
|
38779
|
+
try {
|
|
38780
|
+
json2 = JSON.parse(body);
|
|
38781
|
+
} catch {
|
|
38782
|
+
throw new RemoteResponseInvalid(route, "a body that is not JSON");
|
|
38783
|
+
}
|
|
38784
|
+
const result = schema.safeParse(json2);
|
|
38785
|
+
if (!result.success) {
|
|
38786
|
+
throw new RemoteResponseInvalid(route, "a body this client cannot read");
|
|
38787
|
+
}
|
|
38788
|
+
return result.data;
|
|
38789
|
+
}
|
|
38790
|
+
function resolveBaseUrl(endpoint) {
|
|
38791
|
+
if (!isSafeEndpoint(endpoint)) throw new RemoteEndpointRefused(endpoint);
|
|
38792
|
+
let end = endpoint.length;
|
|
38793
|
+
while (end > 0 && endpoint.charCodeAt(end - 1) === SLASH2) end -= 1;
|
|
38794
|
+
return endpoint.slice(0, end);
|
|
38795
|
+
}
|
|
38796
|
+
var SLASH2 = "/".charCodeAt(0);
|
|
38797
|
+
function createRemoteClient(options) {
|
|
38798
|
+
const base = resolveBaseUrl(options.endpoint);
|
|
38799
|
+
const url2 = (route) => `${base}${route}`;
|
|
38800
|
+
const common = { apiKey: options.apiKey, timeoutMs: options.timeoutMs };
|
|
38801
|
+
const sendOne = async (event) => {
|
|
38802
|
+
const validated = RecordAuditEventRequest.safeParse(event);
|
|
38803
|
+
if (!validated.success) throw new RemoteRequestInvalid(ROUTES.auditEvents, validated.error);
|
|
38804
|
+
const response = await send({
|
|
38805
|
+
...common,
|
|
38806
|
+
method: "POST",
|
|
38807
|
+
url: url2(ROUTES.auditEvents),
|
|
38808
|
+
body: JSON.stringify(validated.data)
|
|
38809
|
+
});
|
|
38810
|
+
okBody(response);
|
|
38811
|
+
};
|
|
38812
|
+
return {
|
|
38813
|
+
async ingestEvents(batch) {
|
|
38814
|
+
const response = await send({
|
|
38815
|
+
...common,
|
|
38816
|
+
method: "POST",
|
|
38817
|
+
url: url2(ROUTES.events),
|
|
38818
|
+
body: JSON.stringify(batch)
|
|
38819
|
+
});
|
|
38820
|
+
return parsed(IngestAck, okBody(response), ROUTES.events);
|
|
38821
|
+
},
|
|
38822
|
+
async ingestInventory(context) {
|
|
38823
|
+
const response = await send({
|
|
38824
|
+
...common,
|
|
38825
|
+
method: "POST",
|
|
38826
|
+
url: url2(ROUTES.inventory),
|
|
38827
|
+
body: JSON.stringify(context)
|
|
38828
|
+
});
|
|
38829
|
+
return parsed(ResolvedInventory, okBody(response), ROUTES.inventory);
|
|
38830
|
+
},
|
|
38831
|
+
async recordAuditEvent(event) {
|
|
38832
|
+
await sendOne(event);
|
|
38833
|
+
},
|
|
38834
|
+
async recordAuditEvents(events, opts) {
|
|
38835
|
+
const validated = RecordAuditEventBatch.safeParse({ events });
|
|
38836
|
+
if (!validated.success) {
|
|
38837
|
+
throw new RemoteRequestInvalid(ROUTES.auditEventsBatch, validated.error);
|
|
38838
|
+
}
|
|
38839
|
+
const response = await send({
|
|
38840
|
+
...common,
|
|
38841
|
+
method: "POST",
|
|
38842
|
+
url: url2(ROUTES.auditEventsBatch),
|
|
38843
|
+
body: JSON.stringify(validated.data)
|
|
38844
|
+
});
|
|
38845
|
+
if (response.status === 404) {
|
|
38846
|
+
if (opts?.fallbackToSingleEvents !== true) {
|
|
38847
|
+
throw new RemoteRouteAbsent(ROUTES.auditEventsBatch);
|
|
38848
|
+
}
|
|
38849
|
+
for (const event of validated.data.events) await sendOne(event);
|
|
38850
|
+
return { accepted: validated.data.events.length };
|
|
38851
|
+
}
|
|
38852
|
+
return parsed(AuditEventBatchAck, okBody(response), ROUTES.auditEventsBatch);
|
|
38853
|
+
},
|
|
38854
|
+
async reportStorePosture(snapshot) {
|
|
38855
|
+
const response = await send({
|
|
38856
|
+
...common,
|
|
38857
|
+
method: "POST",
|
|
38858
|
+
url: url2(ROUTES.storePosture),
|
|
38859
|
+
body: JSON.stringify(snapshot)
|
|
38860
|
+
});
|
|
38861
|
+
okBody(response);
|
|
38862
|
+
},
|
|
38863
|
+
async getPolicyBundle(etag) {
|
|
38864
|
+
const response = await send({
|
|
38865
|
+
...common,
|
|
38866
|
+
method: "GET",
|
|
38867
|
+
url: url2(ROUTES.policyBundle),
|
|
38868
|
+
...etag === void 0 ? {} : { headers: { "if-none-match": etag } }
|
|
38869
|
+
});
|
|
38870
|
+
if (response.status === 304) {
|
|
38871
|
+
return { changed: false, etag: headerValue(response, "etag") ?? etag };
|
|
38872
|
+
}
|
|
38873
|
+
const bundle = parsed(PolicyBundle, okBody(response), ROUTES.policyBundle);
|
|
38874
|
+
return { changed: true, bundle, etag: headerValue(response, "etag") };
|
|
38875
|
+
},
|
|
38876
|
+
async whoami() {
|
|
38877
|
+
const response = await send({ ...common, method: "GET", url: url2(ROUTES.whoami) });
|
|
38878
|
+
return parsed(PluginWhoami, okBody(response), ROUTES.whoami);
|
|
38879
|
+
},
|
|
38880
|
+
async recordProjectEgress(request) {
|
|
38881
|
+
const validated = EgressIngestRequest.safeParse(request);
|
|
38882
|
+
if (!validated.success) throw new RemoteRequestInvalid(ROUTES.shares, validated.error);
|
|
38883
|
+
const response = await send({
|
|
38884
|
+
...common,
|
|
38885
|
+
method: "POST",
|
|
38886
|
+
url: url2(ROUTES.shares),
|
|
38887
|
+
body: JSON.stringify(validated.data)
|
|
38888
|
+
});
|
|
38889
|
+
if (response.status === 404) throw new RemoteRouteAbsent(ROUTES.shares);
|
|
38890
|
+
okBody(response);
|
|
38891
|
+
},
|
|
38892
|
+
async pollCommand() {
|
|
38893
|
+
const response = await send({ ...common, method: "GET", url: url2(ROUTES.commands) });
|
|
38894
|
+
if (response.status === 404) return null;
|
|
38895
|
+
return parsed(DeviceCommandPollResponse, okBody(response), ROUTES.commands).command;
|
|
38896
|
+
},
|
|
38897
|
+
async ackCommand(id, body) {
|
|
38898
|
+
const validated = DeviceCommandAckBody.safeParse(body);
|
|
38899
|
+
const route = ackRoute(id);
|
|
38900
|
+
if (!validated.success) throw new RemoteRequestInvalid(route, validated.error);
|
|
38901
|
+
const response = await send({
|
|
38902
|
+
...common,
|
|
38903
|
+
method: "POST",
|
|
38904
|
+
url: url2(route),
|
|
38905
|
+
body: JSON.stringify(validated.data)
|
|
38906
|
+
});
|
|
38907
|
+
okBody(response);
|
|
38908
|
+
}
|
|
38909
|
+
};
|
|
38910
|
+
}
|
|
39630
38911
|
|
|
39631
|
-
// ../../packages/
|
|
39632
|
-
|
|
38912
|
+
// ../../packages/remote/src/failure-kind.ts
|
|
38913
|
+
function statusOf(err) {
|
|
38914
|
+
if (typeof err !== "object" || err === null || !("status" in err)) return null;
|
|
38915
|
+
const { status } = err;
|
|
38916
|
+
if (typeof status !== "number" || !Number.isInteger(status)) return null;
|
|
38917
|
+
return status >= 100 && status <= 599 ? status : null;
|
|
38918
|
+
}
|
|
38919
|
+
function nameOf(err) {
|
|
38920
|
+
if (typeof err !== "object" || err === null || !("name" in err)) return null;
|
|
38921
|
+
return typeof err.name === "string" ? err.name : null;
|
|
38922
|
+
}
|
|
38923
|
+
function classifyRemoteFailure(err) {
|
|
38924
|
+
switch (nameOf(err)) {
|
|
38925
|
+
case "RemoteRouteAbsent":
|
|
38926
|
+
return "route-absent";
|
|
38927
|
+
case "RemoteRequestInvalid":
|
|
38928
|
+
case "RemoteEndpointRefused":
|
|
38929
|
+
return "invalid-request";
|
|
38930
|
+
case "RemoteResponseInvalid":
|
|
38931
|
+
return "rejected";
|
|
38932
|
+
default:
|
|
38933
|
+
break;
|
|
38934
|
+
}
|
|
38935
|
+
const status = statusOf(err);
|
|
38936
|
+
if (status === null) return "unreachable";
|
|
38937
|
+
switch (status) {
|
|
38938
|
+
case 401:
|
|
38939
|
+
return "unauthorized";
|
|
38940
|
+
case 403:
|
|
38941
|
+
return "forbidden";
|
|
38942
|
+
case 429:
|
|
38943
|
+
return "unreachable";
|
|
38944
|
+
case 404:
|
|
38945
|
+
return "unreachable";
|
|
38946
|
+
default:
|
|
38947
|
+
return status >= 400 && status <= 499 ? "rejected" : "unreachable";
|
|
38948
|
+
}
|
|
38949
|
+
}
|
|
39633
38950
|
|
|
39634
|
-
// ../../packages/plugin-
|
|
39635
|
-
|
|
39636
|
-
|
|
38951
|
+
// ../../packages/plugin-runtime/src/attached/failure.ts
|
|
38952
|
+
function classifyFailure(err) {
|
|
38953
|
+
switch (classifyRemoteFailure(err)) {
|
|
38954
|
+
case "unauthorized":
|
|
38955
|
+
return "unauthorized";
|
|
38956
|
+
case "forbidden":
|
|
38957
|
+
return "forbidden";
|
|
38958
|
+
default:
|
|
38959
|
+
return "unreachable";
|
|
38960
|
+
}
|
|
38961
|
+
}
|
|
39637
38962
|
|
|
39638
|
-
// ../../packages/plugin-
|
|
39639
|
-
var
|
|
38963
|
+
// ../../packages/plugin-runtime/src/attached/with-timeout.ts
|
|
38964
|
+
var REQUEST_TIMEOUT_MS = 2e3;
|
|
38965
|
+
function withTimeout(promise2, ms) {
|
|
38966
|
+
let timer;
|
|
38967
|
+
const timeout = new Promise((_, reject) => {
|
|
38968
|
+
timer = setTimeout(() => {
|
|
38969
|
+
reject(new Error("attached gateway request timed out"));
|
|
38970
|
+
}, ms);
|
|
38971
|
+
});
|
|
38972
|
+
promise2.catch(() => void 0);
|
|
38973
|
+
return Promise.race([promise2, timeout]).finally(() => {
|
|
38974
|
+
clearTimeout(timer);
|
|
38975
|
+
});
|
|
38976
|
+
}
|
|
39640
38977
|
|
|
39641
|
-
// ../../packages/plugin-
|
|
39642
|
-
import {
|
|
39643
|
-
import { join as
|
|
38978
|
+
// ../../packages/plugin-runtime/src/attached/forward-drops.ts
|
|
38979
|
+
import { readFileSync as readFileSync11 } from "fs";
|
|
38980
|
+
import { join as join18 } from "path";
|
|
38981
|
+
var FORWARD_DROPS_FILENAME = ATTACHED_FORWARD_DROPS_FILENAME;
|
|
38982
|
+
function forwardDropsPath(dataDir2) {
|
|
38983
|
+
return join18(dataDir2, FORWARD_DROPS_FILENAME);
|
|
38984
|
+
}
|
|
38985
|
+
function recordForwardDrops(dataDir2, count, nowMs) {
|
|
38986
|
+
if (count <= 0) return;
|
|
38987
|
+
try {
|
|
38988
|
+
ensureDataDirSync(dataDir2);
|
|
38989
|
+
const previous = readForwardDrops(dataDir2);
|
|
38990
|
+
const next = {
|
|
38991
|
+
droppedForwards: (previous?.droppedForwards ?? 0) + count,
|
|
38992
|
+
lastDropAtMs: nowMs
|
|
38993
|
+
};
|
|
38994
|
+
writeOwnerOnlyFileSync(forwardDropsPath(dataDir2), `${JSON.stringify(next)}
|
|
38995
|
+
`);
|
|
38996
|
+
} catch {
|
|
38997
|
+
}
|
|
38998
|
+
}
|
|
38999
|
+
function readForwardDrops(dataDir2) {
|
|
39000
|
+
try {
|
|
39001
|
+
const parsed2 = JSON.parse(readFileSync11(forwardDropsPath(dataDir2), "utf8"));
|
|
39002
|
+
if (typeof parsed2 !== "object" || parsed2 === null) return null;
|
|
39003
|
+
const record2 = parsed2;
|
|
39004
|
+
if (typeof record2.droppedForwards !== "number" || !Number.isFinite(record2.droppedForwards)) {
|
|
39005
|
+
return null;
|
|
39006
|
+
}
|
|
39007
|
+
if (record2.droppedForwards <= 0) return null;
|
|
39008
|
+
if (typeof record2.lastDropAtMs !== "number" || !Number.isFinite(record2.lastDropAtMs)) {
|
|
39009
|
+
return null;
|
|
39010
|
+
}
|
|
39011
|
+
return { droppedForwards: record2.droppedForwards, lastDropAtMs: record2.lastDropAtMs };
|
|
39012
|
+
} catch {
|
|
39013
|
+
return null;
|
|
39014
|
+
}
|
|
39015
|
+
}
|
|
39644
39016
|
|
|
39645
39017
|
// ../../packages/plugin-runtime/src/attached/forward-policy.ts
|
|
39018
|
+
import { randomUUID as randomUUID14 } from "crypto";
|
|
39019
|
+
import { readFile, rename, writeFile } from "fs/promises";
|
|
39020
|
+
import { join as join19 } from "path";
|
|
39646
39021
|
function isInvalidRequest(err) {
|
|
39647
39022
|
return typeof err === "object" && err !== null && err.name === "RemoteRequestInvalid";
|
|
39648
39023
|
}
|
|
@@ -39661,7 +39036,7 @@ var FORWARD_STATE_FILENAME = ATTACHED_FORWARD_STATE_FILENAME;
|
|
|
39661
39036
|
var STATE_FILENAME = FORWARD_STATE_FILENAME;
|
|
39662
39037
|
function createForwardPolicy(deps) {
|
|
39663
39038
|
const now = deps.now ?? (() => Date.now());
|
|
39664
|
-
const file2 =
|
|
39039
|
+
const file2 = join19(deps.dir, STATE_FILENAME);
|
|
39665
39040
|
let state = null;
|
|
39666
39041
|
let loading = null;
|
|
39667
39042
|
async function readState() {
|
|
@@ -39686,7 +39061,7 @@ function createForwardPolicy(deps) {
|
|
|
39686
39061
|
state = next;
|
|
39687
39062
|
try {
|
|
39688
39063
|
await ensureDataDir(deps.dir);
|
|
39689
|
-
const tmp = `${file2}.${
|
|
39064
|
+
const tmp = `${file2}.${randomUUID14()}.tmp`;
|
|
39690
39065
|
await writeFile(tmp, JSON.stringify(next), { encoding: "utf8", mode: DATA_FILE_MODE });
|
|
39691
39066
|
await rename(tmp, file2);
|
|
39692
39067
|
} catch {
|
|
@@ -39827,6 +39202,9 @@ var AttachedDataGateway = class {
|
|
|
39827
39202
|
*
|
|
39828
39203
|
* Machine mode answers before any key is read, so a machine attachment pays
|
|
39829
39204
|
* nothing for scoping and forwards exactly what it always has.
|
|
39205
|
+
*
|
|
39206
|
+
* `governanceAppliesTo` answers from this same verdict, so it agrees with
|
|
39207
|
+
* forwarding key for key.
|
|
39830
39208
|
*/
|
|
39831
39209
|
verdictFor(keyOf) {
|
|
39832
39210
|
try {
|
|
@@ -39843,24 +39221,27 @@ var AttachedDataGateway = class {
|
|
|
39843
39221
|
* the key its row holds in the local store, recorded per root (see
|
|
39844
39222
|
* `rootVerdict`), not the key on the root event just handed in: roots are
|
|
39845
39223
|
* first-write-wins in the store, so when two producers record a root for one
|
|
39846
|
-
* session (the session-start hook, then a reconcile pass) the second leaves
|
|
39847
|
-
*
|
|
39848
|
-
*
|
|
39849
|
-
*
|
|
39850
|
-
*
|
|
39851
|
-
*
|
|
39852
|
-
*
|
|
39853
|
-
*
|
|
39854
|
-
*
|
|
39855
|
-
*
|
|
39856
|
-
*
|
|
39857
|
-
*
|
|
39858
|
-
*
|
|
39859
|
-
*
|
|
39860
|
-
*
|
|
39861
|
-
*
|
|
39862
|
-
*
|
|
39863
|
-
*
|
|
39224
|
+
* session (the session-start hook, then a reconcile pass) the second leaves the
|
|
39225
|
+
* stored row as it was. That stored row, not this event, is what a history
|
|
39226
|
+
* drain pass would decide, if the root started before the attach; the drain
|
|
39227
|
+
* never offers one that started after it (`started_at < backlogBefore`).
|
|
39228
|
+
* Whether this root EVENT is itself sent takes both keys: the stored one AND
|
|
39229
|
+
* its own. The event's attributes (cwd, project, repo) describe where it was
|
|
39230
|
+
* recorded from, so a root event keyed to a personal directory is never sent
|
|
39231
|
+
* under an enrolled stored root, though the enrolled leaves still forward under
|
|
39232
|
+
* it: the instance that wrote the stored root is expected to have forwarded it.
|
|
39233
|
+
* If it did not (the root was written while standalone or under another
|
|
39234
|
+
* attachment, or its forward failed), the plane refuses those leaves. A root
|
|
39235
|
+
* that started before the attach is shipped, ahead of its leaves, by the
|
|
39236
|
+
* history drain; one that started after it is never offered by the drain. Any
|
|
39237
|
+
* other row with a root reference (`rootSessionId`, else `parentId`) forwards
|
|
39238
|
+
* only when its own key is in scope AND this instance recorded an in-scope
|
|
39239
|
+
* verdict for that root. The audit-event route has real foreign keys on both
|
|
39240
|
+
* columns and stubs no missing root, so a leaf sent after its root was kept
|
|
39241
|
+
* local is refused there, and a refused forward counts toward the breaker that
|
|
39242
|
+
* guards every other one. A root this instance never recorded is therefore
|
|
39243
|
+
* `'local'`: the only answer that cannot orphan a row. A row with no root
|
|
39244
|
+
* reference at all has nothing to orphan, and is decided by its own key.
|
|
39864
39245
|
*
|
|
39865
39246
|
* What this costs is stated rather than discovered. A session whose stored
|
|
39866
39247
|
* root is not keyed to an enrolled repository keeps its token and tool
|
|
@@ -39931,6 +39312,87 @@ var AttachedDataGateway = class {
|
|
|
39931
39312
|
return [];
|
|
39932
39313
|
}
|
|
39933
39314
|
}
|
|
39315
|
+
/**
|
|
39316
|
+
* The verdict for the repositories nested in a scanned project, answered
|
|
39317
|
+
* TOTALLY: `'forward'` or `'local'`, never a throw.
|
|
39318
|
+
*
|
|
39319
|
+
* A walk descends into a nested clone or submodule and folds its files into
|
|
39320
|
+
* the project it is walking, so one register can carry several
|
|
39321
|
+
* repositories' call sites under one project key. Each of them must be in
|
|
39322
|
+
* scope for it to forward. One key out of scope, or a nested repository with
|
|
39323
|
+
* no remote (an `undefined` key), keeps the whole register local.
|
|
39324
|
+
*
|
|
39325
|
+
* An ABSENT list is `'local'` too. Only the code that walked the tree can say
|
|
39326
|
+
* what is nested in it, and every scan passes the list, empty when nothing
|
|
39327
|
+
* is nested. A register nobody vouched for is not one a scoped attachment
|
|
39328
|
+
* may send.
|
|
39329
|
+
*
|
|
39330
|
+
* Machine mode answers before reading the context, so a machine attachment
|
|
39331
|
+
* forwards exactly what it always has.
|
|
39332
|
+
*/
|
|
39333
|
+
nestedVerdict(context) {
|
|
39334
|
+
try {
|
|
39335
|
+
if (this.deps.attachment.mode === "machine") return "forward";
|
|
39336
|
+
const keys = context?.nestedScopeKeys;
|
|
39337
|
+
if (keys === void 0) return "local";
|
|
39338
|
+
for (const key of keys) {
|
|
39339
|
+
if (this.verdictFor(() => key) === "local") return "local";
|
|
39340
|
+
}
|
|
39341
|
+
return "forward";
|
|
39342
|
+
} catch {
|
|
39343
|
+
return "local";
|
|
39344
|
+
}
|
|
39345
|
+
}
|
|
39346
|
+
/**
|
|
39347
|
+
* The register a scoped attachment sends, once the project and the repositories
|
|
39348
|
+
* nested in it are in scope: the register itself, with `reconcile.deletedFiles`
|
|
39349
|
+
* cut to the deleted paths whose own repository is in scope. `undefined` sends
|
|
39350
|
+
* nothing. TOTAL, like `verdictFor`, and for its reasons.
|
|
39351
|
+
*
|
|
39352
|
+
* The deletion sweep takes its paths from the scan ledger, not from the walk,
|
|
39353
|
+
* and the ledger holds every file the scanner ever read under the root, nested
|
|
39354
|
+
* clones' included. So a clone that was removed, or one an ignore file now
|
|
39355
|
+
* hides, is in no walk and never reaches `nestedVerdict`, yet its ledgered
|
|
39356
|
+
* paths come back as deleted. The scan names the repository of each deleted
|
|
39357
|
+
* path (`context.deletedFileKeys`, one entry per path in the register's order)
|
|
39358
|
+
* and each is held to the same verdict as any other key. A path whose key is
|
|
39359
|
+
* absent, or out of scope, is not sent.
|
|
39360
|
+
*
|
|
39361
|
+
* The list is asked for here, and only here: it is an async read of the scan
|
|
39362
|
+
* ledger that the scan makes on being called, so a machine attachment, which
|
|
39363
|
+
* returns before this, and a register already kept local never cause it.
|
|
39364
|
+
*
|
|
39365
|
+
* Anything the scan did not vouch for sends no deleted path, and the register
|
|
39366
|
+
* itself still goes: no list, a list that throws or whose read is rejected, or a
|
|
39367
|
+
* list whose length is not the register's. Deleting is the only thing a dropped
|
|
39368
|
+
* path could have done on the server, so the cost of a refusal is a stored row
|
|
39369
|
+
* that stays, never a path that leaves.
|
|
39370
|
+
*
|
|
39371
|
+
* Machine mode returns `input` itself, the same object and unread, so a machine
|
|
39372
|
+
* attachment's request is exactly what it was. A register that lists no deleted
|
|
39373
|
+
* path, or that is not a ledger register, has nothing to cut and is returned
|
|
39374
|
+
* as it came, with the list unread.
|
|
39375
|
+
*/
|
|
39376
|
+
async registerForWire(input2, context) {
|
|
39377
|
+
try {
|
|
39378
|
+
if (this.deps.attachment.mode === "machine") return input2;
|
|
39379
|
+
const { reconcile } = input2;
|
|
39380
|
+
if (reconcile.mode !== "ledger" || reconcile.deletedFiles.length === 0) return input2;
|
|
39381
|
+
const deleted = reconcile.deletedFiles;
|
|
39382
|
+
let kept = [];
|
|
39383
|
+
try {
|
|
39384
|
+
const keys = await context?.deletedFileKeys?.();
|
|
39385
|
+
if (keys?.length === deleted.length) {
|
|
39386
|
+
kept = deleted.filter((_path, at) => this.verdictFor(() => keys[at]) === "forward");
|
|
39387
|
+
}
|
|
39388
|
+
} catch {
|
|
39389
|
+
kept = [];
|
|
39390
|
+
}
|
|
39391
|
+
return { ...input2, reconcile: { ...reconcile, deletedFiles: kept } };
|
|
39392
|
+
} catch {
|
|
39393
|
+
return void 0;
|
|
39394
|
+
}
|
|
39395
|
+
}
|
|
39934
39396
|
/**
|
|
39935
39397
|
* The event `recordCapture` sends for a capture the verdict let through, or
|
|
39936
39398
|
* `undefined` to send nothing. TOTAL, like `verdictFor`, and for its reasons.
|
|
@@ -40256,12 +39718,24 @@ var AttachedDataGateway = class {
|
|
|
40256
39718
|
* payload onto the wire-boundary-safe shape (no snippet, hashed
|
|
40257
39719
|
* projectKey), and its result is discarded: `forward.run` never throws or
|
|
40258
39720
|
* rejects, so there is nothing here to act on.
|
|
39721
|
+
*
|
|
39722
|
+
* `context.nestedScopeKeys` is what the scanner knows and the register does
|
|
39723
|
+
* not say: the key of every repository nested below the scan root, whose
|
|
39724
|
+
* files the walk folded into this register. On a scoped attachment the
|
|
39725
|
+
* register is forwarded only when the project's own key AND every one of
|
|
39726
|
+
* those is in scope (see `nestedVerdict`), and its deleted paths are cut to the
|
|
39727
|
+
* ones whose own repository is in scope (`context.deletedFileKeys`, see
|
|
39728
|
+
* `registerForWire`). Machine mode never reads either, and the local write
|
|
39729
|
+
* never receives the context and gets the register whole.
|
|
40259
39730
|
*/
|
|
40260
|
-
async recordProjectEgress(input2) {
|
|
39731
|
+
async recordProjectEgress(input2, context) {
|
|
40261
39732
|
const summary = await this.deps.local.recordProjectEgress(input2);
|
|
40262
39733
|
if (this.verdictFor(() => scopeKeyOfProjectKey(input2.projectKey)) === "local") return summary;
|
|
39734
|
+
if (this.nestedVerdict(context) === "local") return summary;
|
|
39735
|
+
const register = await this.registerForWire(input2, context);
|
|
39736
|
+
if (register === void 0) return summary;
|
|
40263
39737
|
await this.deps.forward.run(
|
|
40264
|
-
() => this.deps.client.recordProjectEgress(toEgressIngestRequest(
|
|
39738
|
+
() => this.deps.client.recordProjectEgress(toEgressIngestRequest(register))
|
|
40265
39739
|
);
|
|
40266
39740
|
return summary;
|
|
40267
39741
|
}
|
|
@@ -40315,6 +39789,11 @@ var AttachedDataGateway = class {
|
|
|
40315
39789
|
async scanLedgerPaths() {
|
|
40316
39790
|
return this.deps.local.scanLedgerPaths();
|
|
40317
39791
|
}
|
|
39792
|
+
// Delegated, like the path list. An inner gateway that cannot say answers an
|
|
39793
|
+
// empty map, which gives every deleted path no key.
|
|
39794
|
+
async scanLedgerPathKeys() {
|
|
39795
|
+
return await this.deps.local.scanLedgerPathKeys?.() ?? /* @__PURE__ */ new Map();
|
|
39796
|
+
}
|
|
40318
39797
|
async recordScanned(entries) {
|
|
40319
39798
|
return this.deps.local.recordScanned(entries);
|
|
40320
39799
|
}
|
|
@@ -40381,6 +39860,12 @@ var AttachedDataGateway = class {
|
|
|
40381
39860
|
// and the spread above would otherwise drop the field silently — which is
|
|
40382
39861
|
// exactly what it did, leaving the whole control inert on every device
|
|
40383
39862
|
// while every test around it stayed green.
|
|
39863
|
+
//
|
|
39864
|
+
// WHOLE ON EVERY ATTACHMENT. A scoped attachment does not narrow the list
|
|
39865
|
+
// here: the port's `getPolicyBundle()` takes no event, and the runtime
|
|
39866
|
+
// reads this bundle once to build detection, so the detections it carries
|
|
39867
|
+
// apply to every event on the machine. Where a prohibition applies is
|
|
39868
|
+
// answered per event by `governanceAppliesTo` below.
|
|
40384
39869
|
prohibitedModels: cached2.prohibitedModels,
|
|
40385
39870
|
// NAMED for the same reason as the line above, and it is the same defect
|
|
40386
39871
|
// if it is not: `...local` above spreads the DEVICE's bundle, so a field
|
|
@@ -40440,6 +39925,30 @@ var AttachedDataGateway = class {
|
|
|
40440
39925
|
};
|
|
40441
39926
|
}
|
|
40442
39927
|
// ---------------------------------------------------------------------
|
|
39928
|
+
// GovernanceScope — where the organization's model policy applies
|
|
39929
|
+
// ---------------------------------------------------------------------
|
|
39930
|
+
/**
|
|
39931
|
+
* Whether the organization's governance applies to an event keyed `scopeKey`:
|
|
39932
|
+
* the question a model-guard site asks once it has decided to refuse.
|
|
39933
|
+
*
|
|
39934
|
+
* THE FORWARD VERDICT, through `verdictFor`: the answer is whether a capture
|
|
39935
|
+
* with the same key would be forwarded. A machine-wide attachment governs
|
|
39936
|
+
* every event, keyless included, exactly as before. A scoped one governs an
|
|
39937
|
+
* event only when its key names an enrolled repository. An event in a
|
|
39938
|
+
* personal repository, in no repository, with an empty key, or met by a fault
|
|
39939
|
+
* is not governed.
|
|
39940
|
+
*
|
|
39941
|
+
* The event's OWN key, never its session root's. The root rule in
|
|
39942
|
+
* `auditVerdict` decides whether a row can be forwarded without orphaning it;
|
|
39943
|
+
* this decides whether a refusal applies, which is a question about where the
|
|
39944
|
+
* event happened.
|
|
39945
|
+
*
|
|
39946
|
+
* Answered from memory: no store read, no bundle read, nothing sent.
|
|
39947
|
+
*/
|
|
39948
|
+
governanceAppliesTo(scopeKey) {
|
|
39949
|
+
return this.verdictFor(() => scopeKey) === "forward";
|
|
39950
|
+
}
|
|
39951
|
+
// ---------------------------------------------------------------------
|
|
40443
39952
|
// LocalStoreMaintenance — by delegation (D3).
|
|
40444
39953
|
//
|
|
40445
39954
|
// Implementing these is what actually closes the skipped-local-maintenance
|
|
@@ -40549,7 +40058,7 @@ function toWireInspection(insp) {
|
|
|
40549
40058
|
|
|
40550
40059
|
// ../../packages/plugin-runtime/src/attached/history-sync.ts
|
|
40551
40060
|
import { createHash as createHash6 } from "crypto";
|
|
40552
|
-
import { hostname as
|
|
40061
|
+
import { hostname as hostname4 } from "os";
|
|
40553
40062
|
|
|
40554
40063
|
// ../../packages/plugin-runtime/src/attached/capture-rebuild.ts
|
|
40555
40064
|
var CORRELATION_ID = EventMetadata.shape.correlationId;
|
|
@@ -40562,22 +40071,22 @@ var CAPTURE_BATCH_BYTES = 1024 * 1024;
|
|
|
40562
40071
|
|
|
40563
40072
|
// ../../packages/plugin-runtime/src/attached/history-sync-trigger.ts
|
|
40564
40073
|
import { spawn } from "child_process";
|
|
40565
|
-
import { fileURLToPath
|
|
40074
|
+
import { fileURLToPath } from "url";
|
|
40566
40075
|
var HISTORY_SYNC_THROTTLE_MS = 5 * 60 * 1e3;
|
|
40567
40076
|
|
|
40568
40077
|
// ../../packages/plugin-runtime/src/attached/install-record.ts
|
|
40569
40078
|
import { readFile as readFile2, stat } from "fs/promises";
|
|
40570
|
-
import { basename as
|
|
40079
|
+
import { basename as basename2, dirname as dirname4, join as join20, resolve as resolve2 } from "path";
|
|
40571
40080
|
async function readInstalledVersion(installRoot) {
|
|
40572
40081
|
try {
|
|
40573
40082
|
const versionDir = resolve2(installRoot);
|
|
40574
|
-
const pluginDir =
|
|
40575
|
-
const marketplaceDir =
|
|
40576
|
-
const cacheDir =
|
|
40577
|
-
if (
|
|
40578
|
-
const key = `${
|
|
40083
|
+
const pluginDir = dirname4(versionDir);
|
|
40084
|
+
const marketplaceDir = dirname4(pluginDir);
|
|
40085
|
+
const cacheDir = dirname4(marketplaceDir);
|
|
40086
|
+
if (basename2(cacheDir) !== "cache") return null;
|
|
40087
|
+
const key = `${basename2(pluginDir)}@${basename2(marketplaceDir)}`;
|
|
40579
40088
|
const record2 = JSON.parse(
|
|
40580
|
-
await readFile2(
|
|
40089
|
+
await readFile2(join20(dirname4(cacheDir), "installed_plugins.json"), "utf8")
|
|
40581
40090
|
);
|
|
40582
40091
|
const plugins = record2?.plugins;
|
|
40583
40092
|
if (typeof plugins !== "object" || plugins === null || !Object.hasOwn(plugins, key)) {
|
|
@@ -40609,7 +40118,7 @@ async function exists(path) {
|
|
|
40609
40118
|
}
|
|
40610
40119
|
|
|
40611
40120
|
// ../../packages/plugin-runtime/src/attached/plugin-block.ts
|
|
40612
|
-
import { readFileSync as
|
|
40121
|
+
import { readFileSync as readFileSync12 } from "fs";
|
|
40613
40122
|
var INSTALL_RECORD_READ_TIMEOUT_MS = REQUEST_TIMEOUT_MS / 2;
|
|
40614
40123
|
function createPluginBlock(build, policyStore) {
|
|
40615
40124
|
return async () => {
|
|
@@ -40637,9 +40146,9 @@ async function readInstalledVersionBounded(installRoot) {
|
|
|
40637
40146
|
}
|
|
40638
40147
|
|
|
40639
40148
|
// ../../packages/plugin-runtime/src/attached/policy-store.ts
|
|
40640
|
-
import { randomUUID as
|
|
40149
|
+
import { randomUUID as randomUUID15 } from "crypto";
|
|
40641
40150
|
import { readFile as readFile3, rm, writeFile as writeFile2 } from "fs/promises";
|
|
40642
|
-
import { join as
|
|
40151
|
+
import { join as join21 } from "path";
|
|
40643
40152
|
|
|
40644
40153
|
// ../../packages/plugin-runtime/src/attached/atomic-publish.ts
|
|
40645
40154
|
import { rename as rename2 } from "fs/promises";
|
|
@@ -40668,7 +40177,7 @@ async function publishByRename(tmp, file2, move = rename2) {
|
|
|
40668
40177
|
|
|
40669
40178
|
// ../../packages/plugin-runtime/src/attached/policy-store.ts
|
|
40670
40179
|
function createPolicyStore(dir = dataDir()) {
|
|
40671
|
-
const file2 =
|
|
40180
|
+
const file2 = join21(dir, "policy-cache.json");
|
|
40672
40181
|
async function read() {
|
|
40673
40182
|
try {
|
|
40674
40183
|
const raw = await readFile3(file2, "utf8");
|
|
@@ -40700,7 +40209,7 @@ function createPolicyStore(dir = dataDir()) {
|
|
|
40700
40209
|
}
|
|
40701
40210
|
}
|
|
40702
40211
|
async function publishRecord(record2) {
|
|
40703
|
-
const tmp = `${file2}.${
|
|
40212
|
+
const tmp = `${file2}.${randomUUID15()}.tmp`;
|
|
40704
40213
|
try {
|
|
40705
40214
|
await writeFile2(tmp, JSON.stringify(record2), {
|
|
40706
40215
|
encoding: "utf8",
|
|
@@ -40738,8 +40247,8 @@ function createPolicyStore(dir = dataDir()) {
|
|
|
40738
40247
|
}
|
|
40739
40248
|
|
|
40740
40249
|
// ../../packages/plugin-runtime/src/attached/posture-report-state.ts
|
|
40741
|
-
import { readFileSync as
|
|
40742
|
-
import { join as
|
|
40250
|
+
import { readFileSync as readFileSync13 } from "fs";
|
|
40251
|
+
import { join as join22 } from "path";
|
|
40743
40252
|
var POSTURE_REPORT_STATE_FILENAME = ATTACHED_POSTURE_REPORT_FILENAME;
|
|
40744
40253
|
var OUTCOME_KEYS = {
|
|
40745
40254
|
ok: true,
|
|
@@ -40753,7 +40262,7 @@ var OUTCOME_KEYS = {
|
|
|
40753
40262
|
};
|
|
40754
40263
|
var OUTCOMES = new Set(Object.keys(OUTCOME_KEYS));
|
|
40755
40264
|
function postureReportStatePath(dataDir2) {
|
|
40756
|
-
return
|
|
40265
|
+
return join22(dataDir2, POSTURE_REPORT_STATE_FILENAME);
|
|
40757
40266
|
}
|
|
40758
40267
|
function writePostureReportState(dataDir2, state) {
|
|
40759
40268
|
try {
|
|
@@ -40794,10 +40303,19 @@ function createPostureReporter(deps) {
|
|
|
40794
40303
|
hostname: deps.hostname(),
|
|
40795
40304
|
capturedAt: nowMs,
|
|
40796
40305
|
...measurement,
|
|
40797
|
-
// Omit the key rather than spread an explicit `undefined
|
|
40798
|
-
//
|
|
40799
|
-
//
|
|
40800
|
-
|
|
40306
|
+
// Omit the key rather than spread an explicit `undefined`. The type
|
|
40307
|
+
// admits `undefined` here (the schema's optional member), and
|
|
40308
|
+
// JSON.stringify sends the same bytes either way. Omitting keeps the
|
|
40309
|
+
// in-memory object free of an explicit `undefined` member, which the
|
|
40310
|
+
// tests pin by key presence.
|
|
40311
|
+
...plugin === void 0 ? {} : { plugin },
|
|
40312
|
+
// LAST, and only for a scoped attachment. A machine attachment omits
|
|
40313
|
+
// the key the same way, so its body is byte for byte the one it sent
|
|
40314
|
+
// before the member existed. Anything but exactly `machine` reports the
|
|
40315
|
+
// constant `scoped`, never the raw value: that is resolveScope's own
|
|
40316
|
+
// fail direction, and a value outside the wire's vocabulary would fail
|
|
40317
|
+
// the whole snapshot at the receiver, the wipe signal with it.
|
|
40318
|
+
...deps.attachmentMode === "machine" ? {} : { attachmentMode: "scoped" }
|
|
40801
40319
|
};
|
|
40802
40320
|
} catch {
|
|
40803
40321
|
return null;
|
|
@@ -40820,8 +40338,8 @@ function createPostureReporter(deps) {
|
|
|
40820
40338
|
}
|
|
40821
40339
|
|
|
40822
40340
|
// ../../packages/plugin-runtime/src/attached/posture-snapshot.ts
|
|
40823
|
-
import { statSync as
|
|
40824
|
-
import { DatabaseSync as
|
|
40341
|
+
import { statSync as statSync6 } from "fs";
|
|
40342
|
+
import { DatabaseSync as DatabaseSync3 } from "node:sqlite";
|
|
40825
40343
|
|
|
40826
40344
|
// ../../packages/plugin-runtime/src/attached/action-counts.ts
|
|
40827
40345
|
function emptyActionCounts() {
|
|
@@ -40851,7 +40369,7 @@ function emptyReadout(readError = false) {
|
|
|
40851
40369
|
}
|
|
40852
40370
|
function readStorePosture(dbPath2) {
|
|
40853
40371
|
try {
|
|
40854
|
-
|
|
40372
|
+
statSync6(dbPath2);
|
|
40855
40373
|
} catch (err) {
|
|
40856
40374
|
const code = err.code;
|
|
40857
40375
|
if (code === "ENOENT" || code === "ENOTDIR") return emptyReadout();
|
|
@@ -40879,7 +40397,7 @@ function readStorePosture(dbPath2) {
|
|
|
40879
40397
|
readError: false
|
|
40880
40398
|
});
|
|
40881
40399
|
try {
|
|
40882
|
-
db = new
|
|
40400
|
+
db = new DatabaseSync3(dbPath2, { readOnly: true });
|
|
40883
40401
|
db.exec("PRAGMA busy_timeout = 2000");
|
|
40884
40402
|
version2 = db.prepare("PRAGMA user_version").get().user_version;
|
|
40885
40403
|
try {
|
|
@@ -40931,16 +40449,16 @@ function readStorePosture(dbPath2) {
|
|
|
40931
40449
|
}
|
|
40932
40450
|
|
|
40933
40451
|
// ../../packages/plugin-runtime/src/attached/posture-store.ts
|
|
40934
|
-
import { randomUUID as
|
|
40452
|
+
import { randomUUID as randomUUID16 } from "crypto";
|
|
40935
40453
|
import { readFile as readFile4, rm as rm2, writeFile as writeFile3 } from "fs/promises";
|
|
40936
|
-
import { join as
|
|
40454
|
+
import { join as join23 } from "path";
|
|
40937
40455
|
var UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/;
|
|
40938
40456
|
function createPostureStore(dir = settingsDir(), legacyDir) {
|
|
40939
|
-
const file2 =
|
|
40940
|
-
const legacyFile = legacyDir === void 0 ? null :
|
|
40457
|
+
const file2 = join23(dir, "posture-state.json");
|
|
40458
|
+
const legacyFile = legacyDir === void 0 ? null : join23(legacyDir, "posture-state.json");
|
|
40941
40459
|
async function persist(state) {
|
|
40942
40460
|
await ensureDataDir(dir);
|
|
40943
|
-
const tmp = `${file2}.${
|
|
40461
|
+
const tmp = `${file2}.${randomUUID16()}.tmp`;
|
|
40944
40462
|
try {
|
|
40945
40463
|
await writeFile3(tmp, JSON.stringify(state), { encoding: "utf8", mode: DATA_FILE_MODE });
|
|
40946
40464
|
await publishByRename(tmp, file2);
|
|
@@ -40982,7 +40500,7 @@ function createPostureStore(dir = settingsDir(), legacyDir) {
|
|
|
40982
40500
|
}
|
|
40983
40501
|
return legacy;
|
|
40984
40502
|
}
|
|
40985
|
-
const fresh = { deviceId:
|
|
40503
|
+
const fresh = { deviceId: randomUUID16(), lastAttemptedAtMs: 0 };
|
|
40986
40504
|
try {
|
|
40987
40505
|
await ensureDataDir(dir);
|
|
40988
40506
|
if (createOwnerOnlyFileSync(file2, JSON.stringify(fresh))) return fresh;
|
|
@@ -41005,8 +40523,8 @@ function createPostureStore(dir = settingsDir(), legacyDir) {
|
|
|
41005
40523
|
}
|
|
41006
40524
|
|
|
41007
40525
|
// ../../packages/plugin-runtime/src/attached/sync-state.ts
|
|
41008
|
-
import { readFileSync as
|
|
41009
|
-
import { join as
|
|
40526
|
+
import { readFileSync as readFileSync14 } from "fs";
|
|
40527
|
+
import { join as join24 } from "path";
|
|
41010
40528
|
|
|
41011
40529
|
// ../../packages/plugin-runtime/src/attached/status.ts
|
|
41012
40530
|
var REFUSAL_LINES = {
|
|
@@ -41024,7 +40542,7 @@ var OUTCOME_LINES = {
|
|
|
41024
40542
|
|
|
41025
40543
|
// ../../packages/plugin-runtime/src/attached/sync-trigger.ts
|
|
41026
40544
|
import { spawn as spawn2 } from "child_process";
|
|
41027
|
-
import { fileURLToPath as
|
|
40545
|
+
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
41028
40546
|
var SYNC_THROTTLE_MS = 15 * 60 * 1e3;
|
|
41029
40547
|
|
|
41030
40548
|
// ../../packages/plugin-runtime/src/content-retention-pass.ts
|
|
@@ -41032,11 +40550,11 @@ var MAX_ROWS_PER_SWEEP = 50 * 1e3;
|
|
|
41032
40550
|
|
|
41033
40551
|
// ../../packages/plugin-runtime/src/content-retention-trigger.ts
|
|
41034
40552
|
import { spawn as spawn3 } from "child_process";
|
|
41035
|
-
import { fileURLToPath as
|
|
40553
|
+
import { fileURLToPath as fileURLToPath3 } from "url";
|
|
41036
40554
|
var CONTENT_RETENTION_THROTTLE_MS = 60 * 60 * 1e3;
|
|
41037
40555
|
|
|
41038
40556
|
// ../../packages/plugin-runtime/src/attached/factory.ts
|
|
41039
|
-
import { hostname as
|
|
40557
|
+
import { hostname as hostname5 } from "os";
|
|
41040
40558
|
|
|
41041
40559
|
// ../../packages/plugin-runtime/src/recorder.ts
|
|
41042
40560
|
var PLUGIN_RECORDER_BINARY = "plugin";
|
|
@@ -41049,7 +40567,7 @@ var StandaloneDataGateway = class {
|
|
|
41049
40567
|
// One notice per gateway — see warnRulesetDiscarded.
|
|
41050
40568
|
warnedRulesetDiscarded = false;
|
|
41051
40569
|
constructor(dataDir2, detections = [], meta4) {
|
|
41052
|
-
this.db = openLocalDatabase(dataDir2);
|
|
40570
|
+
this.db = openLocalDatabase(dataDir2, { shippedRegexMatchers: shippedRegexMatchers() });
|
|
41053
40571
|
this.dataDir = dataDir2;
|
|
41054
40572
|
this.db.installedPacks.recordInventory(detections, meta4);
|
|
41055
40573
|
}
|
|
@@ -41398,6 +40916,9 @@ var StandaloneDataGateway = class {
|
|
|
41398
40916
|
scanLedgerPaths() {
|
|
41399
40917
|
return Promise.resolve(this.db.scanLedger.allPaths());
|
|
41400
40918
|
}
|
|
40919
|
+
scanLedgerPathKeys() {
|
|
40920
|
+
return Promise.resolve(this.db.scanLedger.pathKeys());
|
|
40921
|
+
}
|
|
41401
40922
|
recordScanned(entries) {
|
|
41402
40923
|
this.db.scanLedger.upsertEntries(entries);
|
|
41403
40924
|
return Promise.resolve();
|
|
@@ -41483,13 +41004,17 @@ function resolveGatewayForConfig(config2, meta4) {
|
|
|
41483
41004
|
},
|
|
41484
41005
|
store: postureStore,
|
|
41485
41006
|
readStore: () => readStorePosture(config2.dbPath),
|
|
41486
|
-
hostname: () =>
|
|
41007
|
+
hostname: () => hostname5(),
|
|
41487
41008
|
now: () => Date.now(),
|
|
41009
|
+
// The mode THIS gateway enforces, from the attachment resolved above,
|
|
41010
|
+
// so the report cannot name a mode the forward paths are not using.
|
|
41011
|
+
attachmentMode: attachment.mode,
|
|
41488
41012
|
// The reporting build's identity, when the caller knows it (the plugin
|
|
41489
41013
|
// adapters do; an embedder or a test may not). Composed with the SAME
|
|
41490
41014
|
// policy store the sync child writes, so the block names the bundle
|
|
41491
|
-
// actually in force.
|
|
41492
|
-
// reporter
|
|
41015
|
+
// actually in force. The dependency key is omitted when no build is
|
|
41016
|
+
// known, and the reporter's optional call (`deps.pluginBlock?.()`)
|
|
41017
|
+
// then adds no block.
|
|
41493
41018
|
...meta4?.pluginBuild === void 0 ? {} : { pluginBlock: createPluginBlock(meta4.pluginBuild, store) }
|
|
41494
41019
|
})
|
|
41495
41020
|
});
|
|
@@ -41506,7 +41031,7 @@ function resolveDataGateway(config2, meta4, gatewayFactory = defaultGatewayFacto
|
|
|
41506
41031
|
}
|
|
41507
41032
|
|
|
41508
41033
|
// ../../packages/plugin-runtime/src/handle-session-start.ts
|
|
41509
|
-
import { randomUUID as
|
|
41034
|
+
import { randomUUID as randomUUID17 } from "crypto";
|
|
41510
41035
|
var EXCEPTION_RETENTION_MS = 90 * 24 * 60 * 60 * 1e3;
|
|
41511
41036
|
|
|
41512
41037
|
// src/present.ts
|
|
@@ -41603,8 +41128,8 @@ function table(headers, rows, opts = {}) {
|
|
|
41603
41128
|
const widths = headers.map(
|
|
41604
41129
|
(h, i) => Math.max(visibleLength(h), ...rows.map((r) => visibleLength(r[i] ?? "")))
|
|
41605
41130
|
);
|
|
41606
|
-
const
|
|
41607
|
-
const fmt = (cells) => cells.map((cell, i) => padEnd(cell, widths[i] ?? 0)).join(
|
|
41131
|
+
const sep2 = " ".repeat(gap);
|
|
41132
|
+
const fmt = (cells) => cells.map((cell, i) => padEnd(cell, widths[i] ?? 0)).join(sep2);
|
|
41608
41133
|
const headerLine = fmt(headers.map((h) => h.toUpperCase()));
|
|
41609
41134
|
if (opts.rowSep === true) {
|
|
41610
41135
|
const fullWidth = widths.reduce((n, w) => n + w, 0) + gap * Math.max(0, widths.length - 1);
|
|
@@ -41616,7 +41141,7 @@ function table(headers, rows, opts = {}) {
|
|
|
41616
41141
|
});
|
|
41617
41142
|
return [headerLine, rule, ...body].join("\n");
|
|
41618
41143
|
}
|
|
41619
|
-
const ruleLine = widths.map((w) => "\u2500".repeat(w)).join(
|
|
41144
|
+
const ruleLine = widths.map((w) => "\u2500".repeat(w)).join(sep2);
|
|
41620
41145
|
return [headerLine, ruleLine, ...rows.map(fmt)].join("\n");
|
|
41621
41146
|
}
|
|
41622
41147
|
function fenced(body) {
|
|
@@ -41626,8 +41151,8 @@ function fenced(body) {
|
|
|
41626
41151
|
}
|
|
41627
41152
|
|
|
41628
41153
|
// ../../packages/setup-wizard/src/remediation/rotation-checklist.ts
|
|
41629
|
-
import { writeFileSync as
|
|
41630
|
-
import { join as
|
|
41154
|
+
import { writeFileSync as writeFileSync5 } from "fs";
|
|
41155
|
+
import { join as join25 } from "path";
|
|
41631
41156
|
|
|
41632
41157
|
// ../../packages/setup-wizard/src/triage/merge.ts
|
|
41633
41158
|
var RANK = Object.fromEntries(
|
|
@@ -41635,9 +41160,9 @@ var RANK = Object.fromEntries(
|
|
|
41635
41160
|
);
|
|
41636
41161
|
|
|
41637
41162
|
// ../../packages/setup-wizard/src/triage/plan-file.ts
|
|
41638
|
-
import { mkdtempSync, readFileSync as
|
|
41163
|
+
import { mkdtempSync, readFileSync as readFileSync15, rmdirSync, rmSync as rmSync7, writeFileSync as writeFileSync6 } from "fs";
|
|
41639
41164
|
import { tmpdir } from "os";
|
|
41640
|
-
import { basename as
|
|
41165
|
+
import { basename as basename3, dirname as dirname5, join as join26 } from "path";
|
|
41641
41166
|
var SuppressionEntrySchema = external_exports.object({
|
|
41642
41167
|
ruleId: external_exports.string(),
|
|
41643
41168
|
category: DetectionCategory,
|
|
@@ -41679,10 +41204,10 @@ var PersistedPlanSchema = external_exports.object({
|
|
|
41679
41204
|
});
|
|
41680
41205
|
|
|
41681
41206
|
// src/skills-registry.ts
|
|
41682
|
-
import { readdirSync as
|
|
41683
|
-
import { join as
|
|
41684
|
-
import { fileURLToPath as
|
|
41685
|
-
var SKILLS_DIR =
|
|
41207
|
+
import { readdirSync as readdirSync2, readFileSync as readFileSync16 } from "fs";
|
|
41208
|
+
import { join as join27 } from "path";
|
|
41209
|
+
import { fileURLToPath as fileURLToPath4 } from "url";
|
|
41210
|
+
var SKILLS_DIR = fileURLToPath4(new URL("../skills", import.meta.url));
|
|
41686
41211
|
|
|
41687
41212
|
// src/render.ts
|
|
41688
41213
|
var SEVERITY_GLYPH = {
|
|
@@ -41766,14 +41291,14 @@ function renderStatusBar(s, opts = {}) {
|
|
|
41766
41291
|
const unreviewed = `unreviewed ${SHADE.full}${String(u.critical)} ${SHADE.dark}${String(u.high)} ${SHADE.medium}${String(u.medium)} ${SHADE.light}${String(u.low)}`;
|
|
41767
41292
|
return `\u25B8\u25B8 AKA health ${String(s.score)}/100 ${unreviewed} \u2691 ${String(s.openFindings)} open findings`;
|
|
41768
41293
|
}
|
|
41769
|
-
const
|
|
41294
|
+
const sep2 = ` ${paint.dim("\u2502")} `;
|
|
41770
41295
|
const sq = "\u25A0";
|
|
41771
41296
|
const dot = s.score >= 80 ? paint.ok("\u25CF") : s.score >= 50 ? paint.high("\u25CF") : paint.critical("\u25CF");
|
|
41772
41297
|
const score = `${dot} health ${paint.bold(String(s.score))}${paint.dim("/100")}`;
|
|
41773
41298
|
const tally = `${paint.dim("unreviewed")} ${paint.critical(sq)}${String(u.critical)} ${paint.high(sq)}${String(u.high)} ${paint.medium(sq)}${String(u.medium)} ${paint.low(sq)}${String(u.low)}`;
|
|
41774
41299
|
const flag = s.openFindings > 0 ? paint.critical("\u2691") : paint.dim("\u2691");
|
|
41775
41300
|
const open3 = `${flag} ${String(s.openFindings)} open findings`;
|
|
41776
|
-
return `${paint.brand("\u25B8\u25B8 AKA")}${
|
|
41301
|
+
return `${paint.brand("\u25B8\u25B8 AKA")}${sep2}${score}${sep2}${tally}${sep2}${open3}`;
|
|
41777
41302
|
}
|
|
41778
41303
|
function renderHealth(r) {
|
|
41779
41304
|
const lines = [`\u25CF ${r.title}`, ""];
|