@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/remediate.js
CHANGED
|
@@ -1,893 +1,13 @@
|
|
|
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 basename9 = 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 ? basename9 : 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
6
|
|
|
875
7
|
// src/remediation/entry.ts
|
|
876
|
-
import { readFileSync as
|
|
8
|
+
import { readFileSync as readFileSync21 } from "fs";
|
|
877
9
|
import { fileURLToPath as fileURLToPath6 } from "url";
|
|
878
10
|
|
|
879
|
-
// ../../packages/persistence/src/attached-derived.ts
|
|
880
|
-
import { rmSync } from "fs";
|
|
881
|
-
import { join } from "path";
|
|
882
|
-
var POLICY_CACHE_FILENAME = "policy-cache.json";
|
|
883
|
-
var ATTACHED_FORWARD_STATE_FILENAME = "attached-state.json";
|
|
884
|
-
var ATTACHED_FORWARD_DROPS_FILENAME = "attached-forward-drops.json";
|
|
885
|
-
var ATTACHED_POSTURE_REPORT_FILENAME = "attached-posture-report.json";
|
|
886
|
-
|
|
887
|
-
// ../../packages/persistence/src/control-plane-credential.ts
|
|
888
|
-
import { chmodSync as chmodSync2, lstatSync as lstatSync2, readFileSync, rmSync as rmSync3, statSync } from "fs";
|
|
889
|
-
import { join as join2 } from "path";
|
|
890
|
-
|
|
891
11
|
// ../../packages/schema/src/drizzle/deferred-migrations.ts
|
|
892
12
|
var DEFERRED_MIGRATION_TAGS = [
|
|
893
13
|
"0031_audit_capture_by_time_index",
|
|
@@ -1059,7 +179,7 @@ var MAX_TEMPORARY_MS = 24 * HOUR_MS;
|
|
|
1059
179
|
var ONCE_BACKSTOP_MS = 30 * MINUTE_MS;
|
|
1060
180
|
|
|
1061
181
|
// ../../packages/schema/src/invisible-padding.ts
|
|
1062
|
-
var INVISIBLE_PADDING = /[\u00AD\u200B\u2060-\u2064\u202A-\u202E\u2066-\u2069\uFEFF\u{E0001}\u{E0020}-\u{E007F}]/gu;
|
|
182
|
+
var INVISIBLE_PADDING = /[\u00AD\u061C\u180E\u200B\u200E\u200F\u2060-\u2064\u202A-\u202E\u2066-\u2069\uFEFF\uFFF9-\uFFFB\u{E0001}\u{E0020}-\u{E007F}]/gu;
|
|
1063
183
|
function stripInvisiblePadding(text) {
|
|
1064
184
|
return text.replace(INVISIBLE_PADDING, "");
|
|
1065
185
|
}
|
|
@@ -3877,9 +2997,9 @@ var asciiTabOrNewline = /[\t\n\r]/g;
|
|
|
3877
2997
|
function stripTabAndNewline(value) {
|
|
3878
2998
|
return value.replace(asciiTabOrNewline, "");
|
|
3879
2999
|
}
|
|
3880
|
-
function urlHostnameOk(url2,
|
|
3881
|
-
|
|
3882
|
-
return
|
|
3000
|
+
function urlHostnameOk(url2, hostname6) {
|
|
3001
|
+
hostname6.lastIndex = 0;
|
|
3002
|
+
return hostname6.test(url2.hostname);
|
|
3883
3003
|
}
|
|
3884
3004
|
function urlProtocolOk(url2, protocol) {
|
|
3885
3005
|
protocol.lastIndex = 0;
|
|
@@ -20799,13 +19919,16 @@ function serviceTierMultiplier(tier) {
|
|
|
20799
19919
|
if (tier === void 0) return 1;
|
|
20800
19920
|
return SERVICE_TIER_MULTIPLIERS.get(tier) ?? 1;
|
|
20801
19921
|
}
|
|
19922
|
+
function promptTokensOf(usage) {
|
|
19923
|
+
return usage.promptTokens ?? (usage.inputTokens ?? 0) + (usage.cacheReadTokens ?? 0) + (usage.cacheWrite1hTokens ?? 0) + (usage.cacheWrite5mTokens ?? 0);
|
|
19924
|
+
}
|
|
20802
19925
|
function costOf(price, usage) {
|
|
20803
19926
|
const metered = [
|
|
20804
19927
|
[usage.cacheWrite1hTokens ?? 0, price.cacheWrite1h],
|
|
20805
19928
|
[usage.cacheWrite5mTokens ?? 0, price.cacheWrite5m],
|
|
20806
19929
|
[usage.cacheReadTokens ?? 0, price.cacheRead]
|
|
20807
19930
|
];
|
|
20808
|
-
const band = price.longContext !== null && (usage
|
|
19931
|
+
const band = price.longContext !== null && promptTokensOf(usage) > price.longContext.thresholdInputTokens ? price.longContext : null;
|
|
20809
19932
|
if (band !== null && (band.input === null || band.output === null)) return null;
|
|
20810
19933
|
const inputRate = band?.input ?? price.input;
|
|
20811
19934
|
const outputRate = band?.output ?? price.output;
|
|
@@ -20878,8 +20001,8 @@ var PLATFORM_HOSTING = /* @__PURE__ */ new Map([
|
|
|
20878
20001
|
["ollama", "local"],
|
|
20879
20002
|
["local", "local"]
|
|
20880
20003
|
]);
|
|
20881
|
-
function hostingFor(
|
|
20882
|
-
return PLATFORM_HOSTING.get(
|
|
20004
|
+
function hostingFor(platform) {
|
|
20005
|
+
return PLATFORM_HOSTING.get(platform) ?? "api";
|
|
20883
20006
|
}
|
|
20884
20007
|
var FIRST_PARTY = /* @__PURE__ */ new Map([
|
|
20885
20008
|
["anthropic", "anthropic"],
|
|
@@ -20893,8 +20016,8 @@ var FIRST_PARTY = /* @__PURE__ */ new Map([
|
|
|
20893
20016
|
function firstPartyPlatformFor(vendor2) {
|
|
20894
20017
|
return FIRST_PARTY.get(vendor2) ?? null;
|
|
20895
20018
|
}
|
|
20896
|
-
function isFirstParty(vendor2,
|
|
20897
|
-
return FIRST_PARTY.get(vendor2) ===
|
|
20019
|
+
function isFirstParty(vendor2, platform) {
|
|
20020
|
+
return FIRST_PARTY.get(vendor2) === platform;
|
|
20898
20021
|
}
|
|
20899
20022
|
var PLATFORM_NAMESPACES = Object.freeze([
|
|
20900
20023
|
"anthropic",
|
|
@@ -20955,14 +20078,14 @@ var ModelVendorBuilder = class {
|
|
|
20955
20078
|
);
|
|
20956
20079
|
}
|
|
20957
20080
|
for (const ref of spec.on ?? []) {
|
|
20958
|
-
const { platform
|
|
20959
|
-
const firstParty = isFirstParty(this.vendor,
|
|
20960
|
-
const hosting = hostingFor(
|
|
20081
|
+
const { platform, price, retention, region } = normalizeRef(ref);
|
|
20082
|
+
const firstParty = isFirstParty(this.vendor, platform);
|
|
20083
|
+
const hosting = hostingFor(platform);
|
|
20961
20084
|
const isSelfHosted = hosting === "local";
|
|
20962
20085
|
platforms.set(
|
|
20963
|
-
|
|
20086
|
+
platform,
|
|
20964
20087
|
Object.freeze({
|
|
20965
|
-
platform
|
|
20088
|
+
platform,
|
|
20966
20089
|
hosting,
|
|
20967
20090
|
firstParty,
|
|
20968
20091
|
price: price ?? (isSelfHosted ? ZERO_PRICE : firstParty ? spec.price ?? null : null),
|
|
@@ -21015,35 +20138,35 @@ var GATEWAY_VENDOR_SLASH_RE = /^[a-z0-9][\w.-]*\//iu;
|
|
|
21015
20138
|
var BEDROCK_VERSION_RE = /-v\d+:\d+$/u;
|
|
21016
20139
|
var BEDROCK_REVISION_RE = /:\d+$/u;
|
|
21017
20140
|
var VERTEX_VERSION_RE = /@[\w-]+$/u;
|
|
21018
|
-
var DATED_SUFFIX_RE =
|
|
20141
|
+
var DATED_SUFFIX_RE = /-(?:\d{8}|\d{4}-\d{2}-\d{2})$/u;
|
|
21019
20142
|
function stripPlatformDecorations(model) {
|
|
21020
20143
|
let id = model.trim();
|
|
21021
|
-
let
|
|
20144
|
+
let platform = null;
|
|
21022
20145
|
if (GEO_PREFIX_RE.test(id)) {
|
|
21023
20146
|
id = id.replace(GEO_PREFIX_RE, "");
|
|
21024
|
-
|
|
20147
|
+
platform = "bedrock";
|
|
21025
20148
|
}
|
|
21026
20149
|
if (NAMESPACE_DOT_RE.test(id)) {
|
|
21027
20150
|
id = id.replace(NAMESPACE_DOT_RE, "");
|
|
21028
|
-
|
|
20151
|
+
platform ??= "bedrock";
|
|
21029
20152
|
}
|
|
21030
20153
|
if (BEDROCK_VERSION_RE.test(id)) {
|
|
21031
20154
|
id = id.replace(BEDROCK_VERSION_RE, "");
|
|
21032
|
-
|
|
20155
|
+
platform ??= "bedrock";
|
|
21033
20156
|
} else if (BEDROCK_REVISION_RE.test(id)) {
|
|
21034
20157
|
id = id.replace(BEDROCK_REVISION_RE, "");
|
|
21035
|
-
|
|
20158
|
+
platform ??= "bedrock";
|
|
21036
20159
|
}
|
|
21037
20160
|
if (VERTEX_VERSION_RE.test(id)) {
|
|
21038
20161
|
id = id.replace(VERTEX_VERSION_RE, "");
|
|
21039
|
-
|
|
20162
|
+
platform ??= "vertex";
|
|
21040
20163
|
}
|
|
21041
20164
|
if (NAMESPACE_SLASH_RE.test(id)) {
|
|
21042
20165
|
id = id.replace(NAMESPACE_SLASH_RE, "");
|
|
21043
20166
|
} else if (GATEWAY_VENDOR_SLASH_RE.test(id)) {
|
|
21044
20167
|
id = id.replace(GATEWAY_VENDOR_SLASH_RE, "");
|
|
21045
20168
|
}
|
|
21046
|
-
return { id, platform
|
|
20169
|
+
return { id, platform };
|
|
21047
20170
|
}
|
|
21048
20171
|
function buildModelIndex(entries) {
|
|
21049
20172
|
const byId = /* @__PURE__ */ new Map();
|
|
@@ -21060,19 +20183,19 @@ function resolveModel(raw, index) {
|
|
|
21060
20183
|
if (exact !== void 0) {
|
|
21061
20184
|
return { entry: exact, canonicalId: raw, platform: null, raw };
|
|
21062
20185
|
}
|
|
21063
|
-
const { id, platform
|
|
20186
|
+
const { id, platform } = stripPlatformDecorations(raw);
|
|
21064
20187
|
const stripped = index.byId.get(id);
|
|
21065
20188
|
if (stripped !== void 0) {
|
|
21066
|
-
return { entry: stripped, canonicalId: id, platform
|
|
20189
|
+
return { entry: stripped, canonicalId: id, platform, raw };
|
|
21067
20190
|
}
|
|
21068
20191
|
if (DATED_SUFFIX_RE.test(id)) {
|
|
21069
20192
|
const undated = id.replace(DATED_SUFFIX_RE, "");
|
|
21070
20193
|
const byDate = index.byId.get(undated);
|
|
21071
20194
|
if (byDate !== void 0) {
|
|
21072
|
-
return { entry: byDate, canonicalId: undated, platform
|
|
20195
|
+
return { entry: byDate, canonicalId: undated, platform, raw };
|
|
21073
20196
|
}
|
|
21074
20197
|
}
|
|
21075
|
-
return { entry: null, canonicalId: raw, platform
|
|
20198
|
+
return { entry: null, canonicalId: raw, platform, raw };
|
|
21076
20199
|
}
|
|
21077
20200
|
|
|
21078
20201
|
// ../../packages/schema/src/model/catalog.ts
|
|
@@ -21165,7 +20288,7 @@ anthropic.model("claude-haiku-4-5", {
|
|
|
21165
20288
|
name: "Claude Haiku 4.5",
|
|
21166
20289
|
ctx: 2e5,
|
|
21167
20290
|
maxOut: 64e3,
|
|
21168
|
-
// Reviewed: fast/cheap tier,
|
|
20291
|
+
// Reviewed: fast/cheap general-purpose tier, not a reasoning or code model.
|
|
21169
20292
|
capability: null,
|
|
21170
20293
|
price: anthropicPrice(1, 5, 0.1),
|
|
21171
20294
|
// The vendor documents `claude-haiku-4-5-20251001` as the versioned id and
|
|
@@ -21296,6 +20419,11 @@ openai.model("gpt-4o", {
|
|
|
21296
20419
|
price: tokenPrice(2.5, 10, { cacheRead: 1.25 }),
|
|
21297
20420
|
on: [...OPENAI_RESELLERS]
|
|
21298
20421
|
});
|
|
20422
|
+
openai.model("gpt-4o-2024-05-13", {
|
|
20423
|
+
name: "GPT-4o (2024-05-13)",
|
|
20424
|
+
price: tokenPrice(5, 15),
|
|
20425
|
+
on: [...OPENAI_RESELLERS]
|
|
20426
|
+
});
|
|
21299
20427
|
openai.model("gpt-4o-mini", {
|
|
21300
20428
|
name: "GPT-4o mini",
|
|
21301
20429
|
price: tokenPrice(0.15, 0.6, { cacheRead: 0.075 }),
|
|
@@ -21315,6 +20443,24 @@ openai.model("o3", {
|
|
|
21315
20443
|
price: tokenPrice(2, 8, { cacheRead: 0.5 }),
|
|
21316
20444
|
on: [...OPENAI_RESELLERS]
|
|
21317
20445
|
});
|
|
20446
|
+
openai.model("text-embedding-3-small", {
|
|
20447
|
+
name: "text-embedding-3-small",
|
|
20448
|
+
capability: "embedding",
|
|
20449
|
+
price: tokenPrice(0.02, 0),
|
|
20450
|
+
on: [...OPENAI_RESELLERS]
|
|
20451
|
+
});
|
|
20452
|
+
openai.model("text-embedding-3-large", {
|
|
20453
|
+
name: "text-embedding-3-large",
|
|
20454
|
+
capability: "embedding",
|
|
20455
|
+
price: tokenPrice(0.13, 0),
|
|
20456
|
+
on: [...OPENAI_RESELLERS]
|
|
20457
|
+
});
|
|
20458
|
+
openai.model("text-embedding-ada-002", {
|
|
20459
|
+
name: "text-embedding-ada-002",
|
|
20460
|
+
capability: "embedding",
|
|
20461
|
+
price: tokenPrice(0.1, 0),
|
|
20462
|
+
on: [...OPENAI_RESELLERS]
|
|
20463
|
+
});
|
|
21318
20464
|
openai.model("gpt-oss-120b", {
|
|
21319
20465
|
name: "GPT-OSS 120B",
|
|
21320
20466
|
openWeights: true,
|
|
@@ -21601,10 +20747,21 @@ var MODEL_ENTRIES = Object.freeze([
|
|
|
21601
20747
|
...alibaba.models(),
|
|
21602
20748
|
...amazon.models()
|
|
21603
20749
|
]);
|
|
20750
|
+
var LONG_CONTEXT_THRESHOLDS = Object.freeze(
|
|
20751
|
+
[
|
|
20752
|
+
...new Set(
|
|
20753
|
+
MODEL_ENTRIES.flatMap(
|
|
20754
|
+
(entry) => [...entry.platforms.values()].flatMap(
|
|
20755
|
+
(offering) => offering.price?.longContext ? [offering.price.longContext.thresholdInputTokens] : []
|
|
20756
|
+
)
|
|
20757
|
+
)
|
|
20758
|
+
)
|
|
20759
|
+
].sort((a, b) => a - b)
|
|
20760
|
+
);
|
|
21604
20761
|
var MODEL_INDEX = buildModelIndex(MODEL_ENTRIES);
|
|
21605
20762
|
|
|
21606
20763
|
// ../../packages/schema/src/model/governance.ts
|
|
21607
|
-
var ModelCapability = external_exports.enum(["reasoning", "code"]);
|
|
20764
|
+
var ModelCapability = external_exports.enum(["reasoning", "code", "embedding"]);
|
|
21608
20765
|
var DataRetention = external_exports.enum([
|
|
21609
20766
|
"zero_retention",
|
|
21610
20767
|
"no_storage",
|
|
@@ -21700,16 +20857,16 @@ function platformForProvider(provider) {
|
|
|
21700
20857
|
return PROVIDER_PLATFORM.get(provider.trim().toLowerCase()) ?? null;
|
|
21701
20858
|
}
|
|
21702
20859
|
function isLocalProvider(provider) {
|
|
21703
|
-
const
|
|
21704
|
-
return
|
|
20860
|
+
const platform = platformForProvider(provider);
|
|
20861
|
+
return platform !== null && hostingFor(platform) === "local";
|
|
21705
20862
|
}
|
|
21706
20863
|
function priceFor(provider, model) {
|
|
21707
20864
|
if (isLocalProvider(provider)) return ZERO_PRICE;
|
|
21708
20865
|
const resolved = resolveModel(model, MODEL_INDEX);
|
|
21709
20866
|
if (resolved.entry === null) return null;
|
|
21710
|
-
const
|
|
21711
|
-
if (
|
|
21712
|
-
return resolved.entry.platforms.get(
|
|
20867
|
+
const platform = resolved.platform ?? platformForProvider(provider);
|
|
20868
|
+
if (platform === null) return null;
|
|
20869
|
+
return resolved.entry.platforms.get(platform)?.price ?? null;
|
|
21713
20870
|
}
|
|
21714
20871
|
var defaultCostModel = {
|
|
21715
20872
|
normalizeModelId(provider, model) {
|
|
@@ -21735,7 +20892,7 @@ var COMPACT = new Intl.NumberFormat("en-US", {
|
|
|
21735
20892
|
|
|
21736
20893
|
// ../../packages/schema/src/token/token-report.ts
|
|
21737
20894
|
var num = (value) => value ?? 0;
|
|
21738
|
-
function costUsageOf(a) {
|
|
20895
|
+
function costUsageOf(a, promptTokens) {
|
|
21739
20896
|
const usage = {
|
|
21740
20897
|
inputTokens: num(a.input_tokens),
|
|
21741
20898
|
outputTokens: num(a.output_tokens),
|
|
@@ -21745,11 +20902,12 @@ function costUsageOf(a) {
|
|
|
21745
20902
|
webSearchRequests: num(a.web_search_requests)
|
|
21746
20903
|
};
|
|
21747
20904
|
if (a.service_tier !== void 0) usage.serviceTier = a.service_tier;
|
|
20905
|
+
if (promptTokens !== void 0) usage.promptTokens = promptTokens;
|
|
21748
20906
|
return usage;
|
|
21749
20907
|
}
|
|
21750
20908
|
function buildTokenReports(leaves, costModel) {
|
|
21751
20909
|
const bySession = /* @__PURE__ */ new Map();
|
|
21752
|
-
for (const { sessionId, attributes } of leaves) {
|
|
20910
|
+
for (const { sessionId, attributes, promptTokens } of leaves) {
|
|
21753
20911
|
const provider = attributes.provider ?? "unknown";
|
|
21754
20912
|
const model = attributes.model ?? "unknown";
|
|
21755
20913
|
const key = `${provider} ${model}`;
|
|
@@ -21768,7 +20926,8 @@ function buildTokenReports(leaves, costModel) {
|
|
|
21768
20926
|
cacheCreation: 0,
|
|
21769
20927
|
cacheRead: 0,
|
|
21770
20928
|
costUsd: 0,
|
|
21771
|
-
priced: false
|
|
20929
|
+
priced: false,
|
|
20930
|
+
partial: false
|
|
21772
20931
|
};
|
|
21773
20932
|
rollups.set(key, acc);
|
|
21774
20933
|
}
|
|
@@ -21776,8 +20935,14 @@ function buildTokenReports(leaves, costModel) {
|
|
|
21776
20935
|
acc.output += num(attributes.output_tokens);
|
|
21777
20936
|
acc.cacheCreation += num(attributes.cache_creation_input_tokens);
|
|
21778
20937
|
acc.cacheRead += num(attributes.cache_read_input_tokens);
|
|
21779
|
-
const leafCost = costModel.costFor({
|
|
21780
|
-
|
|
20938
|
+
const leafCost = costModel.costFor({
|
|
20939
|
+
provider,
|
|
20940
|
+
model,
|
|
20941
|
+
usage: costUsageOf(attributes, promptTokens)
|
|
20942
|
+
});
|
|
20943
|
+
if (leafCost === null) {
|
|
20944
|
+
acc.partial = true;
|
|
20945
|
+
} else {
|
|
21781
20946
|
acc.costUsd += leafCost;
|
|
21782
20947
|
acc.priced = true;
|
|
21783
20948
|
}
|
|
@@ -21793,9 +20958,8 @@ function buildTokenReports(leaves, costModel) {
|
|
|
21793
20958
|
const rollupTotal = acc.input + acc.output + acc.cacheCreation + acc.cacheRead;
|
|
21794
20959
|
totalTokens += rollupTotal;
|
|
21795
20960
|
const estimatedCostUsd = acc.priced ? acc.costUsd : null;
|
|
21796
|
-
if (
|
|
21797
|
-
|
|
21798
|
-
} else {
|
|
20961
|
+
if (acc.partial) anyUnpriced = true;
|
|
20962
|
+
if (estimatedCostUsd !== null) {
|
|
21799
20963
|
anyPriced = true;
|
|
21800
20964
|
costUsd += estimatedCostUsd;
|
|
21801
20965
|
}
|
|
@@ -21818,7 +20982,7 @@ function buildTokenReports(leaves, costModel) {
|
|
|
21818
20982
|
totalTokens,
|
|
21819
20983
|
// Σ of the PRICED rollups; null when none had a known price.
|
|
21820
20984
|
estimatedCostUsd: anyPriced ? costUsd : null,
|
|
21821
|
-
// Any
|
|
20985
|
+
// Any call priced to null means the total understates real spend.
|
|
21822
20986
|
costIsPartial: anyUnpriced
|
|
21823
20987
|
});
|
|
21824
20988
|
}
|
|
@@ -22697,8 +21861,9 @@ var SessionTokenReport = external_exports.object({
|
|
|
22697
21861
|
totalTokens: external_exports.number().int().nonnegative(),
|
|
22698
21862
|
// Σ of the PRICED rollups only; null when no rollup had a known price.
|
|
22699
21863
|
estimatedCostUsd: external_exports.number().nullable(),
|
|
22700
|
-
// True whenever any
|
|
22701
|
-
//
|
|
21864
|
+
// True whenever any call priced to null (an unknown provider/model, or a call
|
|
21865
|
+
// over a long-context threshold whose rate is unpublished), so the total
|
|
21866
|
+
// understates real spend — the UI renders `≥ $X` instead of a falsely
|
|
22702
21867
|
// precise figure rather than silently dropping the unpriced calls.
|
|
22703
21868
|
costIsPartial: external_exports.boolean()
|
|
22704
21869
|
});
|
|
@@ -23575,7 +22740,15 @@ var StorePostureSnapshot = external_exports.object({
|
|
|
23575
22740
|
policyCounts: StorePosturePolicyCounts,
|
|
23576
22741
|
// OPTIONAL, not nullable: a reporter that predates this member keeps
|
|
23577
22742
|
// getting its 200 without a payload change.
|
|
23578
|
-
plugin: StorePosturePlugin.optional()
|
|
22743
|
+
plugin: StorePosturePlugin.optional(),
|
|
22744
|
+
// OPTIONAL, and sent only by a scoped attachment, always as `scoped`. A
|
|
22745
|
+
// machine attachment omits it, so its body is byte for byte the one it
|
|
22746
|
+
// sent before this member existed. Absent therefore means machine-wide OR
|
|
22747
|
+
// a reporter older than this member, never "scoped". Both values parse, so
|
|
22748
|
+
// a sender that one day spells `machine` breaks no receiver; any other
|
|
22749
|
+
// value fails the whole snapshot, which is why the reporter sends a
|
|
22750
|
+
// constant and never the raw mode.
|
|
22751
|
+
attachmentMode: AttachmentMode.optional()
|
|
23579
22752
|
}).meta({ id: "StorePostureSnapshot" });
|
|
23580
22753
|
var CAPTURE_VERSION_PREFIX = "capture/";
|
|
23581
22754
|
var RecordAuditEventRequest = AuditEventInput.extend({
|
|
@@ -24022,7 +23195,7 @@ var Rule = external_exports.strictObject({
|
|
|
24022
23195
|
postValidators: external_exports.array(PostValidatorRef).optional(),
|
|
24023
23196
|
requiresNearby: RequiresNearby.optional(),
|
|
24024
23197
|
examples: external_exports.array(external_exports.string()).optional(),
|
|
24025
|
-
// Whether the matched text is itself sensitive
|
|
23198
|
+
// Whether the matched text is itself sensitive (see RuleEvidence).
|
|
24026
23199
|
evidence: RuleEvidence.optional()
|
|
24027
23200
|
}).meta({ id: "Rule" });
|
|
24028
23201
|
var Author = external_exports.object({
|
|
@@ -24114,7 +23287,13 @@ var DetectionRule = external_exports.object({
|
|
|
24114
23287
|
// Representative matching strings the rule author shipped with the rule. The
|
|
24115
23288
|
// cheapest honest answer to "show me what this rule catches" — every bundled
|
|
24116
23289
|
// rule has them, and they are already in the stored snapshot.
|
|
24117
|
-
examples: external_exports.array(external_exports.string()).optional()
|
|
23290
|
+
examples: external_exports.array(external_exports.string()).optional(),
|
|
23291
|
+
// The rule's DECLARED evidence, as stored. Absent defers to the engine's
|
|
23292
|
+
// classification (ruleEvidence in @akasecurity/detections): a bundled
|
|
23293
|
+
// code-flaw rule reads as 'code' and anything else as 'value', and a rule
|
|
23294
|
+
// in a value category (secret/pii/financial/phi) is always 'value',
|
|
23295
|
+
// whatever it declares.
|
|
23296
|
+
evidence: RuleEvidence.optional()
|
|
24118
23297
|
}).meta({ id: "DetectionRule" });
|
|
24119
23298
|
var DetectionUpdate = external_exports.object({
|
|
24120
23299
|
available: external_exports.boolean(),
|
|
@@ -24182,8 +23361,10 @@ var ImportDetectionRequest = external_exports.object({
|
|
|
24182
23361
|
}).meta({ id: "ImportDetectionRequest" });
|
|
24183
23362
|
|
|
24184
23363
|
// ../../packages/schema/src/zod/detection-build.ts
|
|
24185
|
-
function optional2(key,
|
|
24186
|
-
if (raw === void 0
|
|
23364
|
+
function optional2(key, raw, parse4) {
|
|
23365
|
+
if (raw === void 0) return {};
|
|
23366
|
+
const parsed2 = parse4(raw);
|
|
23367
|
+
if (!parsed2.success || parsed2.data === void 0) return {};
|
|
24187
23368
|
return { [key]: parsed2.data };
|
|
24188
23369
|
}
|
|
24189
23370
|
function isStringArray(value) {
|
|
@@ -24218,10 +23399,12 @@ function rowToDetectionDetail(row, findingsLast30d, update) {
|
|
|
24218
23399
|
category: r.category,
|
|
24219
23400
|
severity: r.severity,
|
|
24220
23401
|
matcher: parsed2.data,
|
|
24221
|
-
//
|
|
24222
|
-
//
|
|
24223
|
-
//
|
|
24224
|
-
//
|
|
23402
|
+
// `appliesTo`, `postValidators` and `requiresNearby` are the rest of what
|
|
23403
|
+
// decides whether this rule fires. Carried so a consumer re-running the
|
|
23404
|
+
// rule (a preview, a tester) evaluates what the engine evaluates rather
|
|
23405
|
+
// than a matcher stripped of its guards — half the bundled catalog
|
|
23406
|
+
// carries at least one of these. `examples` and `evidence` describe the
|
|
23407
|
+
// rule and never gate a match.
|
|
24225
23408
|
//
|
|
24226
23409
|
// Enrichment is deliberately per-field and best-effort, NOT a whole-rule
|
|
24227
23410
|
// `Rule.safeParse`. Two reasons: `Rule` is a strict object pinned to
|
|
@@ -24231,18 +23414,19 @@ function rowToDetectionDetail(row, findingsLast30d, update) {
|
|
|
24231
23414
|
// test should stay exactly what it was, namely a renderable matcher. A
|
|
24232
23415
|
// field that fails validation is omitted, which reads as "not set" and is
|
|
24233
23416
|
// the same thing the consumer saw before this change.
|
|
24234
|
-
...optional2("appliesTo",
|
|
23417
|
+
...optional2("appliesTo", r.appliesTo, (v) => AppliesTo.safeParse(v)),
|
|
24235
23418
|
...optional2(
|
|
24236
23419
|
"postValidators",
|
|
24237
|
-
|
|
24238
|
-
|
|
23420
|
+
r.postValidators,
|
|
23421
|
+
(v) => PostValidatorRef.array().safeParse(v)
|
|
24239
23422
|
),
|
|
24240
|
-
...optional2("requiresNearby",
|
|
23423
|
+
...optional2("requiresNearby", r.requiresNearby, (v) => RequiresNearby.safeParse(v)),
|
|
24241
23424
|
...optional2(
|
|
24242
23425
|
"examples",
|
|
24243
|
-
|
|
24244
|
-
|
|
24245
|
-
)
|
|
23426
|
+
r.examples,
|
|
23427
|
+
(v) => isStringArray(v) ? { success: true, data: v } : { success: false }
|
|
23428
|
+
),
|
|
23429
|
+
...optional2("evidence", r.evidence, (v) => RuleEvidence.safeParse(v))
|
|
24246
23430
|
}
|
|
24247
23431
|
];
|
|
24248
23432
|
});
|
|
@@ -24935,11 +24119,14 @@ var PolicyBundle = external_exports.object({
|
|
|
24935
24119
|
ruleVersions: external_exports.record(external_exports.string(), external_exports.string()).optional(),
|
|
24936
24120
|
// Model ids (the raw `model` string a harness reports, e.g.
|
|
24937
24121
|
// `claude-opus-4-1`) the tenant has PROHIBITED. The plugin refuses to switch
|
|
24938
|
-
// a session onto one (PreModelSwitch)
|
|
24939
|
-
//
|
|
24940
|
-
//
|
|
24941
|
-
//
|
|
24942
|
-
//
|
|
24122
|
+
// a session onto one (PreModelSwitch), refuses a turn that would run on one
|
|
24123
|
+
// (UserPromptSubmit) and refuses a subagent spawn onto one (PreToolUse),
|
|
24124
|
+
// wherever the organization governs the event: everywhere on a
|
|
24125
|
+
// machine-wide attachment, and only in enrolled repositories on a scoped
|
|
24126
|
+
// one (the plugin runtime's `governanceApplies`).
|
|
24127
|
+
// Optional so an older backend — and an older on-disk cache — still
|
|
24128
|
+
// parses; consumers read `?? []`, which is the unenforced behaviour that
|
|
24129
|
+
// predates this field and the safe direction to default.
|
|
24943
24130
|
//
|
|
24944
24131
|
// Ids, not display names: the governance decision is keyed on the exact
|
|
24945
24132
|
// string the harness reports (`model_status_override.versionId` in the
|
|
@@ -25398,6 +24585,8 @@ var AttachmentScopeEntry = external_exports.object({
|
|
|
25398
24585
|
});
|
|
25399
24586
|
var AttachmentScope = external_exports.object({
|
|
25400
24587
|
endpoint: external_exports.string().min(1),
|
|
24588
|
+
tenantName: PluginWhoami.shape.tenantName.optional(),
|
|
24589
|
+
userEmail: PluginWhoami.shape.userEmail.optional(),
|
|
25401
24590
|
entries: external_exports.array(AttachmentScopeEntry)
|
|
25402
24591
|
});
|
|
25403
24592
|
var AttachmentScopeEnvelope = AttachmentScope.extend({ entries: external_exports.array(external_exports.unknown()) });
|
|
@@ -25410,7 +24599,13 @@ function parseAttachmentScope(raw) {
|
|
|
25410
24599
|
const entry = AttachmentScopeEntry.safeParse(candidate);
|
|
25411
24600
|
if (entry.success) entries.push(entry.data);
|
|
25412
24601
|
}
|
|
25413
|
-
|
|
24602
|
+
const { endpoint, tenantName, userEmail } = envelope.data;
|
|
24603
|
+
return {
|
|
24604
|
+
endpoint,
|
|
24605
|
+
...tenantName === void 0 ? {} : { tenantName },
|
|
24606
|
+
...userEmail === void 0 ? {} : { userEmail },
|
|
24607
|
+
entries
|
|
24608
|
+
};
|
|
25414
24609
|
} catch {
|
|
25415
24610
|
return void 0;
|
|
25416
24611
|
}
|
|
@@ -25775,6 +24970,27 @@ var ManagedSettings = external_exports.object({
|
|
|
25775
24970
|
};
|
|
25776
24971
|
}).meta({ id: "ManagedSettings" });
|
|
25777
24972
|
|
|
24973
|
+
// ../../packages/schema/src/zod/mod-policy-snapshot.ts
|
|
24974
|
+
var MOD_POLICY_SNAPSHOT_VERSION = 1;
|
|
24975
|
+
var MOD_POLICY_SNAPSHOT_MAX_BYTES = 4 * 1024 * 1024;
|
|
24976
|
+
var ModPolicySnapshot = external_exports.object({
|
|
24977
|
+
version: external_exports.literal(MOD_POLICY_SNAPSHOT_VERSION),
|
|
24978
|
+
generatedAt: external_exports.iso.datetime(),
|
|
24979
|
+
// The complete effective ruleset, as the hook's runtime scans with it: the
|
|
24980
|
+
// user's enabled installed packs (user-modified and custom packs included).
|
|
24981
|
+
// Absent means the store holds no authoritative snapshot, and the reader
|
|
24982
|
+
// scans with the packs it ships — the hook's own fallback.
|
|
24983
|
+
rules: external_exports.array(Rule).optional(),
|
|
24984
|
+
// Rule-targeted actions (first enabled policy per rule wins).
|
|
24985
|
+
ruleActions: external_exports.record(external_exports.string(), ActionTaken),
|
|
24986
|
+
// The resolved action per detection category.
|
|
24987
|
+
categoryActions: external_exports.record(external_exports.string(), ActionTaken),
|
|
24988
|
+
// Rules with an active exception grant. Honouring a grant means matching a
|
|
24989
|
+
// keyed fingerprint of the value and consuming a use, which only the hook can
|
|
24990
|
+
// do, so the mod leaves a finding of one of these rules for the hook to decide.
|
|
24991
|
+
exceptionRuleIds: external_exports.array(external_exports.string())
|
|
24992
|
+
}).meta({ id: "ModPolicySnapshot" });
|
|
24993
|
+
|
|
25778
24994
|
// ../../packages/schema/src/zod/project-files.ts
|
|
25779
24995
|
var ProjectFileInput = external_exports.object({
|
|
25780
24996
|
path: external_exports.string().min(1),
|
|
@@ -26095,7 +25311,16 @@ var AttachInput = external_exports.object({
|
|
|
26095
25311
|
// 200 matches the tenantName bound beside it in control-plane.ts; nothing
|
|
26096
25312
|
// renders a longer one usefully.
|
|
26097
25313
|
label: printable(200).optional(),
|
|
26098
|
-
accessKey: external_exports.string()
|
|
25314
|
+
accessKey: external_exports.string(),
|
|
25315
|
+
// How much of this machine the attachment is for: everything, or only the
|
|
25316
|
+
// repositories its user enrolls. Optional, so an input without it still
|
|
25317
|
+
// parses; what an absent mode means is for whatever reads it to decide, not
|
|
25318
|
+
// this shape. This member validates the VALUE rather than leaving that to the
|
|
25319
|
+
// call site, a deliberate exception to this module's shape-only rule: a shape
|
|
25320
|
+
// rejection names the field, so a value that is not a mode is refused as a bad
|
|
25321
|
+
// `mode` rather than stripped or passed on. The dashboard's attach action reads
|
|
25322
|
+
// it as the mode to attach in.
|
|
25323
|
+
mode: AttachmentMode.optional()
|
|
26099
25324
|
});
|
|
26100
25325
|
|
|
26101
25326
|
// ../../packages/schema/src/zod/triage.ts
|
|
@@ -26381,6 +25606,18 @@ function fromCaptureStatusAttributes(bag) {
|
|
|
26381
25606
|
return parsedStatus.success ? parsedStatus.data : null;
|
|
26382
25607
|
}
|
|
26383
25608
|
|
|
25609
|
+
// ../../packages/persistence/src/attached-derived.ts
|
|
25610
|
+
import { rmSync } from "fs";
|
|
25611
|
+
import { join } from "path";
|
|
25612
|
+
var POLICY_CACHE_FILENAME = "policy-cache.json";
|
|
25613
|
+
var ATTACHED_FORWARD_STATE_FILENAME = "attached-state.json";
|
|
25614
|
+
var ATTACHED_FORWARD_DROPS_FILENAME = "attached-forward-drops.json";
|
|
25615
|
+
var ATTACHED_POSTURE_REPORT_FILENAME = "attached-posture-report.json";
|
|
25616
|
+
|
|
25617
|
+
// ../../packages/persistence/src/control-plane-credential.ts
|
|
25618
|
+
import { chmodSync as chmodSync2, lstatSync as lstatSync2, readFileSync, rmSync as rmSync3, statSync } from "fs";
|
|
25619
|
+
import { join as join2 } from "path";
|
|
25620
|
+
|
|
26384
25621
|
// ../../packages/persistence/src/paths.ts
|
|
26385
25622
|
import {
|
|
26386
25623
|
chmodSync,
|
|
@@ -26527,6 +25764,14 @@ function repairOrRefuseMode(file2) {
|
|
|
26527
25764
|
}
|
|
26528
25765
|
return "ok";
|
|
26529
25766
|
}
|
|
25767
|
+
function asReadableCredential(value) {
|
|
25768
|
+
const result = AttachedCredentialAny.safeParse(value);
|
|
25769
|
+
if (!result.success) return null;
|
|
25770
|
+
if (attachmentModeOf(result.data) === "machine" && typeof value === "object" && value !== null && Object.hasOwn(value, "mode")) {
|
|
25771
|
+
return null;
|
|
25772
|
+
}
|
|
25773
|
+
return result.data;
|
|
25774
|
+
}
|
|
26530
25775
|
function readControlPlaneCredentialFile(settingsDir2, connection) {
|
|
26531
25776
|
const file2 = controlPlaneCredentialPath(settingsDir2);
|
|
26532
25777
|
let raw;
|
|
@@ -26545,20 +25790,20 @@ function readControlPlaneCredentialFile(settingsDir2, connection) {
|
|
|
26545
25790
|
} catch {
|
|
26546
25791
|
return { usable: false, reason: "malformed" };
|
|
26547
25792
|
}
|
|
26548
|
-
const
|
|
26549
|
-
if (
|
|
26550
|
-
if (!isSafeEndpoint(
|
|
25793
|
+
const credential = asReadableCredential(parsed2);
|
|
25794
|
+
if (credential === null) return { usable: false, reason: "malformed" };
|
|
25795
|
+
if (!isSafeEndpoint(credential.endpoint)) {
|
|
26551
25796
|
return { usable: false, reason: "unsafe-endpoint" };
|
|
26552
25797
|
}
|
|
26553
|
-
if (connection !== void 0 && connection.endpoint !==
|
|
25798
|
+
if (connection !== void 0 && connection.endpoint !== credential.endpoint) {
|
|
26554
25799
|
return {
|
|
26555
25800
|
usable: false,
|
|
26556
25801
|
reason: "endpoint-mismatch",
|
|
26557
|
-
credentialEndpoint:
|
|
25802
|
+
credentialEndpoint: credential.endpoint,
|
|
26558
25803
|
settingsEndpoint: connection.endpoint
|
|
26559
25804
|
};
|
|
26560
25805
|
}
|
|
26561
|
-
return { usable: true, credential
|
|
25806
|
+
return { usable: true, credential };
|
|
26562
25807
|
}
|
|
26563
25808
|
function readControlPlaneCredential(settingsDir2, connection) {
|
|
26564
25809
|
const read = readControlPlaneCredentialFile(settingsDir2, connection);
|
|
@@ -26567,7 +25812,7 @@ function readControlPlaneCredential(settingsDir2, connection) {
|
|
|
26567
25812
|
|
|
26568
25813
|
// ../../packages/persistence/src/database.ts
|
|
26569
25814
|
import { randomUUID as randomUUID11 } from "crypto";
|
|
26570
|
-
import { dirname as dirname2, join as
|
|
25815
|
+
import { dirname as dirname2, join as join8, sep } from "path";
|
|
26571
25816
|
import { DatabaseSync } from "node:sqlite";
|
|
26572
25817
|
|
|
26573
25818
|
// ../../packages/persistence/src/ids.ts
|
|
@@ -26621,6 +25866,7 @@ function uuidFromDigest(digest) {
|
|
|
26621
25866
|
function captureWireId(sessionId, contentHash, filePath = null) {
|
|
26622
25867
|
return uuidFromDigest(captureId(sessionId, contentHash, filePath));
|
|
26623
25868
|
}
|
|
25869
|
+
var DOT = ".".charCodeAt(0);
|
|
26624
25870
|
|
|
26625
25871
|
// ../../packages/persistence/src/internal/snapshot.ts
|
|
26626
25872
|
import { randomUUID } from "crypto";
|
|
@@ -26948,6 +26194,25 @@ function scopeKeysParam(scopeKeys) {
|
|
|
26948
26194
|
var ROOT_SCOPE_KEY = `(SELECT session_root.scope_key
|
|
26949
26195
|
FROM audit_events AS session_root
|
|
26950
26196
|
WHERE session_root.id = COALESCE(audit_events.root_session_id, audit_events.id))`;
|
|
26197
|
+
var COUNTED_IN_SCOPE = `
|
|
26198
|
+
AND ${inScope("scope_key")}
|
|
26199
|
+
AND (event_type IN (${CAPTURE_TYPE_LIST}) OR ${inScope(ROOT_SCOPE_KEY)})`;
|
|
26200
|
+
var DRAIN_TOTALS = `SELECT
|
|
26201
|
+
SUM(CASE WHEN synced_at IS NULL AND started_at < :before THEN 1 ELSE 0 END) AS pending,
|
|
26202
|
+
SUM(CASE WHEN synced_at > 0 THEN 1 ELSE 0 END) AS sent,
|
|
26203
|
+
SUM(CASE WHEN synced_at = ${String(SKIPPED)}
|
|
26204
|
+
AND (sync_failure IS NULL OR sync_failure = 'payload_invalid')
|
|
26205
|
+
THEN 1 ELSE 0 END) AS skipped,
|
|
26206
|
+
SUM(CASE WHEN synced_at = ${String(SKIPPED)}
|
|
26207
|
+
AND sync_failure = 'deployment_refused' THEN 1 ELSE 0 END) AS refused,
|
|
26208
|
+
SUM(CASE WHEN synced_at = ${String(SKIPPED)}
|
|
26209
|
+
AND sync_failure = 'detached_undelivered' THEN 1 ELSE 0 END) AS detached
|
|
26210
|
+
FROM audit_events
|
|
26211
|
+
WHERE event_type IN (${TYPE_LIST})`;
|
|
26212
|
+
var CAPTURE_SKIPS = `SELECT COUNT(*) AS skipped
|
|
26213
|
+
FROM audit_events
|
|
26214
|
+
WHERE synced_at = ${String(SKIPPED)}
|
|
26215
|
+
AND event_type IN (${CAPTURE_TYPE_LIST})`;
|
|
26951
26216
|
var ROW_COLUMNS = `id,
|
|
26952
26217
|
parent_id AS parentId,
|
|
26953
26218
|
root_session_id AS rootSessionId,
|
|
@@ -27023,7 +26288,7 @@ var SqliteHistorySyncRepository = class {
|
|
|
27023
26288
|
);
|
|
27024
26289
|
this.scopedCaptureRowsStmt = db.prepare(
|
|
27025
26290
|
`SELECT ${ROW_COLUMNS}
|
|
27026
|
-
FROM audit_events
|
|
26291
|
+
FROM audit_events INDEXED BY idx_audit_scope_owed
|
|
27027
26292
|
WHERE synced_at IS NULL
|
|
27028
26293
|
AND sync_claimed_at IS NULL
|
|
27029
26294
|
AND outbox_owed = 1
|
|
@@ -27076,40 +26341,28 @@ var SqliteHistorySyncRepository = class {
|
|
|
27076
26341
|
);
|
|
27077
26342
|
this.partitionStmt = db.prepare(`SELECT${PARTITION_BUCKETS}
|
|
27078
26343
|
FROM audit_events${COUNTED_SCOPE}`);
|
|
26344
|
+
this.scopedPartitionStmt = db.prepare(`SELECT${PARTITION_BUCKETS}
|
|
26345
|
+
FROM audit_events${COUNTED_SCOPE}${COUNTED_IN_SCOPE}`);
|
|
27079
26346
|
this.partitionByKindStmt = db.prepare(
|
|
27080
26347
|
`SELECT event_type AS kind,${PARTITION_BUCKETS}
|
|
27081
26348
|
FROM audit_events INDEXED BY idx_audit_events_sync${COUNTED_SCOPE}
|
|
27082
26349
|
GROUP BY event_type`
|
|
27083
26350
|
);
|
|
27084
|
-
this.
|
|
27085
|
-
`SELECT
|
|
27086
|
-
|
|
27087
|
-
|
|
27088
|
-
|
|
27089
|
-
|
|
27090
|
-
|
|
27091
|
-
|
|
27092
|
-
|
|
27093
|
-
|
|
27094
|
-
|
|
27095
|
-
|
|
27096
|
-
|
|
27097
|
-
|
|
27098
|
-
|
|
27099
|
-
// EVERY sentinel capture, whatever the reason — deliberately NOT split the
|
|
27100
|
-
// way the structural totals are. The split exists because a refusal is
|
|
27101
|
-
// terminal only against the deployment that gave it, and the structural
|
|
27102
|
-
// re-arm frees it on a change of deployment. The capture lane has no such
|
|
27103
|
-
// escape: re-arming a capture would offer one deployment's undelivered
|
|
27104
|
-
// prompts, with their text, to a deployment that never saw them, which is
|
|
27105
|
-
// exactly what disownCapturesStmt exists to prevent. So on this lane both
|
|
27106
|
-
// reasons mean the same thing — this row will not be sent — and splitting
|
|
27107
|
-
// them would put refused captures in a bucket nothing reads and nothing
|
|
27108
|
-
// frees.
|
|
27109
|
-
`SELECT COUNT(*) AS skipped
|
|
27110
|
-
FROM audit_events
|
|
27111
|
-
WHERE synced_at = ${String(SKIPPED)}
|
|
27112
|
-
AND event_type IN (${CAPTURE_TYPE_LIST})`
|
|
26351
|
+
this.scopedPartitionByKindStmt = db.prepare(
|
|
26352
|
+
`SELECT event_type AS kind,${PARTITION_BUCKETS}
|
|
26353
|
+
FROM audit_events INDEXED BY idx_audit_events_sync${COUNTED_SCOPE}${COUNTED_IN_SCOPE}
|
|
26354
|
+
GROUP BY event_type`
|
|
26355
|
+
);
|
|
26356
|
+
this.countsStmt = db.prepare(DRAIN_TOTALS);
|
|
26357
|
+
this.scopedCountsStmt = db.prepare(
|
|
26358
|
+
`${DRAIN_TOTALS}
|
|
26359
|
+
AND ${inScope("scope_key")}
|
|
26360
|
+
AND ${inScope(ROOT_SCOPE_KEY)}`
|
|
26361
|
+
);
|
|
26362
|
+
this.captureSkipCountStmt = db.prepare(CAPTURE_SKIPS);
|
|
26363
|
+
this.scopedCaptureSkipCountStmt = db.prepare(
|
|
26364
|
+
`${CAPTURE_SKIPS}
|
|
26365
|
+
AND ${inScope("scope_key")}`
|
|
27113
26366
|
);
|
|
27114
26367
|
this.fingerprintStmt = db.prepare(
|
|
27115
26368
|
`SELECT endpoint_fingerprint AS fingerprint, backlog_before AS backlogBefore
|
|
@@ -27223,6 +26476,10 @@ var SqliteHistorySyncRepository = class {
|
|
|
27223
26476
|
scopedCaptureRowsStmt;
|
|
27224
26477
|
scopedCaptureBacklogOwedStmt;
|
|
27225
26478
|
markScopeCapturesOwedStmt;
|
|
26479
|
+
scopedPartitionStmt;
|
|
26480
|
+
scopedPartitionByKindStmt;
|
|
26481
|
+
scopedCountsStmt;
|
|
26482
|
+
scopedCaptureSkipCountStmt;
|
|
27226
26483
|
/**
|
|
27227
26484
|
* The masked detections recorded against one tool call.
|
|
27228
26485
|
*
|
|
@@ -27444,7 +26701,29 @@ var SqliteHistorySyncRepository = class {
|
|
|
27444
26701
|
* in" — and a machine that has never attached has no boundary to pass, so
|
|
27445
26702
|
* requiring one would force a caller to invent one and report the whole store
|
|
27446
26703
|
* as queued.
|
|
26704
|
+
*
|
|
26705
|
+
* `scopeKeys` is a scoped attachment's filter: every bucket then counts only
|
|
26706
|
+
* the rows that pass the drain's reachability rule for that scope
|
|
26707
|
+
* (COUNTED_IN_SCOPE, which also names the one kind of row it counts that the
|
|
26708
|
+
* drain never offers), so a personal repository's rows are in none of them.
|
|
26709
|
+
* Omitted, this runs the machine statement, unchanged; an empty list counts
|
|
26710
|
+
* nothing.
|
|
27447
26711
|
*/
|
|
26712
|
+
partition(scopeKeys) {
|
|
26713
|
+
const row = getRow(
|
|
26714
|
+
scopeKeys === void 0 ? this.partitionStmt : this.scopedPartitionStmt,
|
|
26715
|
+
scopeKeys === void 0 ? {} : { scopeKeys: scopeKeysParam(scopeKeys) }
|
|
26716
|
+
);
|
|
26717
|
+
return {
|
|
26718
|
+
queued: row?.queued ?? 0,
|
|
26719
|
+
inProgress: row?.inProgress ?? 0,
|
|
26720
|
+
synced: row?.synced ?? 0,
|
|
26721
|
+
failed: row?.failed ?? 0,
|
|
26722
|
+
refused: row?.refused ?? 0,
|
|
26723
|
+
detached: row?.detached ?? 0,
|
|
26724
|
+
total: row?.total ?? 0
|
|
26725
|
+
};
|
|
26726
|
+
}
|
|
27448
26727
|
/**
|
|
27449
26728
|
* The same partition, one row per kind that a lane carries.
|
|
27450
26729
|
*
|
|
@@ -27454,11 +26733,14 @@ var SqliteHistorySyncRepository = class {
|
|
|
27454
26733
|
* rendering a fixed list of kinds must therefore treat a missing one as "no
|
|
27455
26734
|
* rows", never as "zero sent"; the two look identical in a bar and mean
|
|
27456
26735
|
* different things.
|
|
26736
|
+
*
|
|
26737
|
+
* `scopeKeys` scopes it with the clause `partition` uses, so the per-kind rows
|
|
26738
|
+
* still sum to the scoped aggregate. An empty list returns no rows.
|
|
27457
26739
|
*/
|
|
27458
|
-
partitionByKind() {
|
|
26740
|
+
partitionByKind(scopeKeys) {
|
|
27459
26741
|
return allRows(
|
|
27460
|
-
this.partitionByKindStmt,
|
|
27461
|
-
{}
|
|
26742
|
+
scopeKeys === void 0 ? this.partitionByKindStmt : this.scopedPartitionByKindStmt,
|
|
26743
|
+
scopeKeys === void 0 ? {} : { scopeKeys: scopeKeysParam(scopeKeys) }
|
|
27462
26744
|
).map((row) => ({
|
|
27463
26745
|
kind: row.kind,
|
|
27464
26746
|
queued: row.queued ?? 0,
|
|
@@ -27470,22 +26752,25 @@ var SqliteHistorySyncRepository = class {
|
|
|
27470
26752
|
total: row.total ?? 0
|
|
27471
26753
|
}));
|
|
27472
26754
|
}
|
|
27473
|
-
|
|
27474
|
-
|
|
27475
|
-
|
|
27476
|
-
|
|
27477
|
-
|
|
27478
|
-
|
|
27479
|
-
|
|
27480
|
-
|
|
27481
|
-
|
|
27482
|
-
|
|
27483
|
-
|
|
27484
|
-
|
|
27485
|
-
|
|
27486
|
-
|
|
27487
|
-
|
|
27488
|
-
|
|
26755
|
+
/**
|
|
26756
|
+
* The drain's totals. `pending` counts only what is inside the backlog; sent
|
|
26757
|
+
* and skipped are totals.
|
|
26758
|
+
*
|
|
26759
|
+
* `scopeKeys` is a scoped attachment's filter, and it scopes every figure,
|
|
26760
|
+
* `capturesSkipped` included: a structural row is counted only when its own
|
|
26761
|
+
* key and its session root's key are among them, a capture when its own key
|
|
26762
|
+
* is. So `pending` is exactly what pendingSessions and pendingRows page out
|
|
26763
|
+
* under the same keys and boundary. Omitted, this runs the machine
|
|
26764
|
+
* statements, unchanged; an empty list counts nothing.
|
|
26765
|
+
*/
|
|
26766
|
+
counts(before, scopeKeys) {
|
|
26767
|
+
const row = getRow(
|
|
26768
|
+
scopeKeys === void 0 ? this.countsStmt : this.scopedCountsStmt,
|
|
26769
|
+
scopeKeys === void 0 ? { before } : { before, scopeKeys: scopeKeysParam(scopeKeys) }
|
|
26770
|
+
);
|
|
26771
|
+
const captures = scopeKeys === void 0 ? getRow(this.captureSkipCountStmt) : getRow(this.scopedCaptureSkipCountStmt, {
|
|
26772
|
+
scopeKeys: scopeKeysParam(scopeKeys)
|
|
26773
|
+
});
|
|
27489
26774
|
return {
|
|
27490
26775
|
pending: row?.pending ?? 0,
|
|
27491
26776
|
sent: row?.sent ?? 0,
|
|
@@ -27737,6 +27022,7 @@ function applyMigrations(db, file2, options = {}) {
|
|
|
27737
27022
|
}
|
|
27738
27023
|
ensureSyncedAtColumn(db, "audit_events");
|
|
27739
27024
|
ensureScopeKeyColumn(db);
|
|
27025
|
+
ensureScopeOwedIndex(db);
|
|
27740
27026
|
ensureScanLedgerTable(db);
|
|
27741
27027
|
ensureHistorySyncTable(db);
|
|
27742
27028
|
ensureBlockedDetectionsTable(db);
|
|
@@ -28177,14 +27463,48 @@ function ensureScopeKeyColumn(db) {
|
|
|
28177
27463
|
function hasScopeKeyColumn(db) {
|
|
28178
27464
|
return columnNames(db, "audit_events", { includeGenerated: true }).includes("scope_key");
|
|
28179
27465
|
}
|
|
27466
|
+
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";
|
|
27467
|
+
function ensureScopeOwedIndex(db) {
|
|
27468
|
+
if (!schemaObjectExists(db, "table", "audit_events")) return;
|
|
27469
|
+
const columns = columnNames(db, "audit_events", { includeGenerated: true });
|
|
27470
|
+
const complete = ["scope_key", "outbox_owed", "synced_at"].every((c) => columns.includes(c));
|
|
27471
|
+
if (!complete) return;
|
|
27472
|
+
db.exec(SCOPE_OWED_INDEX_DDL);
|
|
27473
|
+
}
|
|
28180
27474
|
function ensureScanLedgerTable(db) {
|
|
28181
27475
|
db.exec(`CREATE TABLE IF NOT EXISTS scan_ledger (
|
|
28182
27476
|
path TEXT PRIMARY KEY,
|
|
28183
27477
|
mtime TEXT NOT NULL,
|
|
28184
27478
|
content_hash TEXT NOT NULL,
|
|
28185
27479
|
ruleset_hash TEXT NOT NULL,
|
|
28186
|
-
scanned_at INTEGER NOT NULL
|
|
27480
|
+
scanned_at INTEGER NOT NULL,
|
|
27481
|
+
scope_key TEXT,
|
|
27482
|
+
scope_root TEXT
|
|
28187
27483
|
)`);
|
|
27484
|
+
ensureScanLedgerScopeKeyColumn(db);
|
|
27485
|
+
ensureScanLedgerScopeRootColumn(db);
|
|
27486
|
+
}
|
|
27487
|
+
var SCAN_LEDGER_SCOPE_KEY_DDL = "ALTER TABLE scan_ledger ADD COLUMN scope_key TEXT";
|
|
27488
|
+
var SCAN_LEDGER_SCOPE_ROOT_DDL = "ALTER TABLE scan_ledger ADD COLUMN scope_root TEXT";
|
|
27489
|
+
function ensureScanLedgerScopeKeyColumn(db) {
|
|
27490
|
+
ensureScanLedgerColumn(db, "scope_key", SCAN_LEDGER_SCOPE_KEY_DDL);
|
|
27491
|
+
}
|
|
27492
|
+
function ensureScanLedgerScopeRootColumn(db) {
|
|
27493
|
+
ensureScanLedgerColumn(db, "scope_root", SCAN_LEDGER_SCOPE_ROOT_DDL);
|
|
27494
|
+
}
|
|
27495
|
+
function ensureScanLedgerColumn(db, column, ddl) {
|
|
27496
|
+
if (!schemaObjectExists(db, "table", "scan_ledger")) return;
|
|
27497
|
+
if (hasScanLedgerColumn(db, column)) return;
|
|
27498
|
+
withTransaction(
|
|
27499
|
+
db,
|
|
27500
|
+
() => {
|
|
27501
|
+
if (!hasScanLedgerColumn(db, column)) db.exec(ddl);
|
|
27502
|
+
},
|
|
27503
|
+
"IMMEDIATE"
|
|
27504
|
+
);
|
|
27505
|
+
}
|
|
27506
|
+
function hasScanLedgerColumn(db, column) {
|
|
27507
|
+
return columnNames(db, "scan_ledger").includes(column);
|
|
28188
27508
|
}
|
|
28189
27509
|
function ensureHistorySyncTable(db) {
|
|
28190
27510
|
db.exec(`CREATE TABLE IF NOT EXISTS history_sync (
|
|
@@ -28235,6 +27555,106 @@ function ensureRuleProbeCacheTable(db) {
|
|
|
28235
27555
|
)`);
|
|
28236
27556
|
}
|
|
28237
27557
|
|
|
27558
|
+
// ../../packages/persistence/src/mod-policy-snapshot.ts
|
|
27559
|
+
import { createHash as createHash2 } from "crypto";
|
|
27560
|
+
import { readFileSync as readFileSync2 } from "fs";
|
|
27561
|
+
import { join as join4 } from "path";
|
|
27562
|
+
var MOD_POLICY_SNAPSHOT_FILENAME = "mod-policy.json";
|
|
27563
|
+
function modPolicySnapshotPath(dataDir2) {
|
|
27564
|
+
return join4(dataDir2, MOD_POLICY_SNAPSHOT_FILENAME);
|
|
27565
|
+
}
|
|
27566
|
+
function buildModPolicySnapshot(input2, generatedAt = /* @__PURE__ */ new Date()) {
|
|
27567
|
+
const byRule = /* @__PURE__ */ new Map();
|
|
27568
|
+
const byCategory = /* @__PURE__ */ new Map();
|
|
27569
|
+
for (const policy of input2.policies) {
|
|
27570
|
+
if (!policy.enabled) continue;
|
|
27571
|
+
if ("ruleId" in policy.target) {
|
|
27572
|
+
if (!byRule.has(policy.target.ruleId)) byRule.set(policy.target.ruleId, policy.action);
|
|
27573
|
+
} else if (!byCategory.has(policy.target.category)) {
|
|
27574
|
+
byCategory.set(policy.target.category, policy.action);
|
|
27575
|
+
}
|
|
27576
|
+
}
|
|
27577
|
+
const categoryActions = {};
|
|
27578
|
+
for (const category of DetectionCategory.options) {
|
|
27579
|
+
categoryActions[category] = byCategory.get(category) ?? DEFAULT_ACTIONS[category];
|
|
27580
|
+
}
|
|
27581
|
+
return {
|
|
27582
|
+
version: MOD_POLICY_SNAPSHOT_VERSION,
|
|
27583
|
+
generatedAt: generatedAt.toISOString(),
|
|
27584
|
+
// `examples` is documentation the mod never reads, and a custom pack's are
|
|
27585
|
+
// whatever its author pasted in, so they stay behind.
|
|
27586
|
+
...input2.rules !== void 0 ? { rules: input2.rules.map(withoutExamples) } : {},
|
|
27587
|
+
ruleActions: Object.fromEntries(byRule),
|
|
27588
|
+
categoryActions,
|
|
27589
|
+
exceptionRuleIds: [...new Set(input2.exceptionRuleIds)].sort()
|
|
27590
|
+
};
|
|
27591
|
+
}
|
|
27592
|
+
function assignedRuleActionPolicies(installed) {
|
|
27593
|
+
const out = [];
|
|
27594
|
+
for (const [ruleId, action] of installed.ruleActions) {
|
|
27595
|
+
if (installed.assignedRules.has(ruleId))
|
|
27596
|
+
out.push({ target: { ruleId }, action, enabled: true });
|
|
27597
|
+
}
|
|
27598
|
+
return out;
|
|
27599
|
+
}
|
|
27600
|
+
function withoutExamples(rule) {
|
|
27601
|
+
const copy = { ...rule };
|
|
27602
|
+
delete copy.examples;
|
|
27603
|
+
return copy;
|
|
27604
|
+
}
|
|
27605
|
+
function sameContent(a, b) {
|
|
27606
|
+
return JSON.stringify({ ...a, generatedAt: "" }) === JSON.stringify({ ...b, generatedAt: "" });
|
|
27607
|
+
}
|
|
27608
|
+
function readModPolicySnapshot(dataDir2) {
|
|
27609
|
+
try {
|
|
27610
|
+
const text = readFileSync2(modPolicySnapshotPath(dataDir2), "utf8");
|
|
27611
|
+
if (text.length > MOD_POLICY_SNAPSHOT_MAX_BYTES) return null;
|
|
27612
|
+
const parsed2 = ModPolicySnapshot.safeParse(JSON.parse(text));
|
|
27613
|
+
return parsed2.success ? parsed2.data : null;
|
|
27614
|
+
} catch {
|
|
27615
|
+
return null;
|
|
27616
|
+
}
|
|
27617
|
+
}
|
|
27618
|
+
function writeModPolicySnapshot(dataDir2, snapshot) {
|
|
27619
|
+
const text = JSON.stringify(snapshot);
|
|
27620
|
+
if (Buffer.byteLength(text) > MOD_POLICY_SNAPSHOT_MAX_BYTES) return false;
|
|
27621
|
+
const existing = readModPolicySnapshot(dataDir2);
|
|
27622
|
+
if (existing !== null && sameContent(existing, snapshot)) return false;
|
|
27623
|
+
ensureDataDirSync(dataDir2);
|
|
27624
|
+
writeOwnerOnlyFileSync(modPolicySnapshotPath(dataDir2), text);
|
|
27625
|
+
return true;
|
|
27626
|
+
}
|
|
27627
|
+
function regexProbeKey(matcher) {
|
|
27628
|
+
return createHash2("sha256").update(`${matcher.pattern} ${matcher.flags}`).digest("hex");
|
|
27629
|
+
}
|
|
27630
|
+
function vetRulesForMod(rules, sources, previouslyVetted = /* @__PURE__ */ new Set()) {
|
|
27631
|
+
const bundled = new Set(sources.bundledRegexMatchers().map(regexProbeKey));
|
|
27632
|
+
return rules.filter((rule) => {
|
|
27633
|
+
if (rule.matcher.type !== "regex") return true;
|
|
27634
|
+
const key = regexProbeKey(rule.matcher);
|
|
27635
|
+
const verdict = sources.probeVerdict(key);
|
|
27636
|
+
if (verdict === "quarantined") return false;
|
|
27637
|
+
return verdict === "safe" || bundled.has(key) || previouslyVetted.has(key);
|
|
27638
|
+
});
|
|
27639
|
+
}
|
|
27640
|
+
function modPolicyInputFromStore(sources, previouslyVetted = /* @__PURE__ */ new Set()) {
|
|
27641
|
+
const policies = sources.readPolicies();
|
|
27642
|
+
const snapshot = sources.installedRuleset();
|
|
27643
|
+
const usable = snapshot.installedPacks > 0 && (snapshot.enabledPacks === 0 || snapshot.invalidRules === 0 && snapshot.rules.length > 0);
|
|
27644
|
+
const empty = snapshot.installedPacks > 0 && snapshot.enabledPacks === 0;
|
|
27645
|
+
return {
|
|
27646
|
+
...usable ? { rules: empty ? [] : vetRulesForMod(snapshot.rules, sources, previouslyVetted) } : {},
|
|
27647
|
+
policies: [...policies, ...usable && !empty ? assignedRuleActionPolicies(snapshot) : []],
|
|
27648
|
+
exceptionRuleIds: sources.activeExceptionRuleIds()
|
|
27649
|
+
};
|
|
27650
|
+
}
|
|
27651
|
+
function refreshModPolicySnapshot(dataDir2, sources) {
|
|
27652
|
+
try {
|
|
27653
|
+
writeModPolicySnapshot(dataDir2, buildModPolicySnapshot(modPolicyInputFromStore(sources)));
|
|
27654
|
+
} catch {
|
|
27655
|
+
}
|
|
27656
|
+
}
|
|
27657
|
+
|
|
28238
27658
|
// ../../packages/persistence/src/internal/json.ts
|
|
28239
27659
|
function safeJson(s, fallback) {
|
|
28240
27660
|
if (s == null) return fallback;
|
|
@@ -28409,6 +27829,11 @@ var TIMELINE_COLUMNS = `
|
|
|
28409
27829
|
json_extract(attributes, '$.targetId') AS target_id,
|
|
28410
27830
|
json_extract(attributes, '$.internal') AS internal,
|
|
28411
27831
|
json_extract(attributes, '$.flagged') AS flagged`;
|
|
27832
|
+
var CALL_PROMPT_TOKENS = `(coalesce(input_tokens, 0) + coalesce(cache_read_input_tokens, 0)
|
|
27833
|
+
+ coalesce(ephemeral_1h_input_tokens, 0) + coalesce(ephemeral_5m_input_tokens, 0))`;
|
|
27834
|
+
var CALL_BAND = LONG_CONTEXT_THRESHOLDS.length === 0 ? "0" : LONG_CONTEXT_THRESHOLDS.map((t) => `(${CALL_PROMPT_TOKENS} > ${String(Math.trunc(t))})`).join(
|
|
27835
|
+
" + "
|
|
27836
|
+
);
|
|
28412
27837
|
var LLM_USAGE_SELECT = `
|
|
28413
27838
|
SELECT root_session_id AS sessionId,
|
|
28414
27839
|
provider,
|
|
@@ -28420,9 +27845,10 @@ var LLM_USAGE_SELECT = `
|
|
|
28420
27845
|
coalesce(sum(cache_read_input_tokens), 0) AS cacheReadTokens,
|
|
28421
27846
|
coalesce(sum(ephemeral_1h_input_tokens), 0) AS ephemeral1hTokens,
|
|
28422
27847
|
coalesce(sum(ephemeral_5m_input_tokens), 0) AS ephemeral5mTokens,
|
|
28423
|
-
coalesce(sum(web_search_requests), 0) AS webSearchRequests
|
|
27848
|
+
coalesce(sum(web_search_requests), 0) AS webSearchRequests,
|
|
27849
|
+
coalesce(max(${CALL_PROMPT_TOKENS}), 0) AS promptTokens`;
|
|
28424
27850
|
var LLM_USAGE_SCOPE = `event_type = 'llm_call' AND attributes IS NOT NULL AND root_session_id IS NOT NULL`;
|
|
28425
|
-
var LLM_USAGE_GROUP = `GROUP BY root_session_id, provider, model, service_tier`;
|
|
27851
|
+
var LLM_USAGE_GROUP = `GROUP BY root_session_id, provider, model, service_tier, ${CALL_BAND}`;
|
|
28426
27852
|
function usageLeaves(rows) {
|
|
28427
27853
|
return rows.map((row) => {
|
|
28428
27854
|
const attributes = {
|
|
@@ -28437,7 +27863,7 @@ function usageLeaves(rows) {
|
|
|
28437
27863
|
if (row.provider !== null) attributes.provider = row.provider;
|
|
28438
27864
|
if (row.model !== null) attributes.model = row.model;
|
|
28439
27865
|
if (row.serviceTier !== null) attributes.service_tier = row.serviceTier;
|
|
28440
|
-
return { sessionId: row.sessionId, attributes };
|
|
27866
|
+
return { sessionId: row.sessionId, attributes, promptTokens: row.promptTokens };
|
|
28441
27867
|
});
|
|
28442
27868
|
}
|
|
28443
27869
|
var SESSION_ROOT = `event_type = 'session'`;
|
|
@@ -29771,9 +29197,10 @@ var ACTIVE_REVEAL_GRANT_PREDICATE = `capability = 'reveal_to_model'
|
|
|
29771
29197
|
AND conditions IS NULL
|
|
29772
29198
|
AND ${ACTIVE_PREDICATE}`;
|
|
29773
29199
|
var SqliteExceptionsRepository = class {
|
|
29774
|
-
constructor(db, now = () => Date.now()) {
|
|
29200
|
+
constructor(db, now = () => Date.now(), onChange = () => void 0) {
|
|
29775
29201
|
this.db = db;
|
|
29776
29202
|
this.now = now;
|
|
29203
|
+
this.onChange = onChange;
|
|
29777
29204
|
this.consumeStmt = db.prepare(
|
|
29778
29205
|
`UPDATE exceptions
|
|
29779
29206
|
SET use_count = use_count + 1, last_used_at = :now, updated_at = :now
|
|
@@ -29792,6 +29219,7 @@ var SqliteExceptionsRepository = class {
|
|
|
29792
29219
|
}
|
|
29793
29220
|
db;
|
|
29794
29221
|
now;
|
|
29222
|
+
onChange;
|
|
29795
29223
|
consumeStmt;
|
|
29796
29224
|
insertBlockedStmt;
|
|
29797
29225
|
sweepBlockedStmt;
|
|
@@ -29807,7 +29235,9 @@ var SqliteExceptionsRepository = class {
|
|
|
29807
29235
|
*/
|
|
29808
29236
|
create(input2) {
|
|
29809
29237
|
try {
|
|
29810
|
-
|
|
29238
|
+
const created = this.createSync(input2);
|
|
29239
|
+
this.onChange();
|
|
29240
|
+
return Promise.resolve(created);
|
|
29811
29241
|
} catch (err) {
|
|
29812
29242
|
return Promise.reject(err instanceof Error ? err : new Error(String(err)));
|
|
29813
29243
|
}
|
|
@@ -29938,6 +29368,7 @@ var SqliteExceptionsRepository = class {
|
|
|
29938
29368
|
SET revoked_at = :now, revoked_by = :revokedBy, revoke_reason = :reason, updated_at = :now
|
|
29939
29369
|
WHERE id = :id AND revoked_at IS NULL`
|
|
29940
29370
|
).run({ id, revokedBy, reason: reason ?? null, now });
|
|
29371
|
+
if (Number(result.changes) === 1) this.onChange();
|
|
29941
29372
|
return Promise.resolve(Number(result.changes) === 1);
|
|
29942
29373
|
}
|
|
29943
29374
|
/**
|
|
@@ -29950,6 +29381,15 @@ var SqliteExceptionsRepository = class {
|
|
|
29950
29381
|
const result = this.consumeStmt.run({ id, now });
|
|
29951
29382
|
return Promise.resolve(Number(result.changes) === 1);
|
|
29952
29383
|
}
|
|
29384
|
+
/** The rule ids with at least one active grant, under any key version. */
|
|
29385
|
+
activeRuleIds(now = this.now()) {
|
|
29386
|
+
return allRows(
|
|
29387
|
+
this.db.prepare(
|
|
29388
|
+
`SELECT DISTINCT rule_id AS ruleId FROM exceptions WHERE ${ACTIVE_PREDICATE}`
|
|
29389
|
+
),
|
|
29390
|
+
{ now }
|
|
29391
|
+
).map((row) => row.ruleId);
|
|
29392
|
+
}
|
|
29953
29393
|
/**
|
|
29954
29394
|
* The evaluation subset of every active grant under one fingerprint key
|
|
29955
29395
|
* version — what rides the policy bundle to the hook. Grants written under
|
|
@@ -31073,28 +30513,28 @@ var SqliteInspectionFindingsRepository = class {
|
|
|
31073
30513
|
};
|
|
31074
30514
|
|
|
31075
30515
|
// ../../packages/persistence/src/repositories/installed-packs.ts
|
|
31076
|
-
import { createHash as
|
|
30516
|
+
import { createHash as createHash3, randomUUID as randomUUID4 } from "crypto";
|
|
31077
30517
|
|
|
31078
30518
|
// ../../packages/persistence/src/policy-floor.ts
|
|
31079
|
-
import { readFileSync as
|
|
31080
|
-
import { join as
|
|
30519
|
+
import { readFileSync as readFileSync6 } from "fs";
|
|
30520
|
+
import { join as join7 } from "path";
|
|
31081
30521
|
|
|
31082
30522
|
// ../../packages/persistence/src/local-layout.ts
|
|
31083
30523
|
import { renameSync as renameSync3 } from "fs";
|
|
31084
30524
|
import { mkdir } from "fs/promises";
|
|
31085
30525
|
import { homedir } from "os";
|
|
31086
|
-
import { join as
|
|
30526
|
+
import { join as join5 } from "path";
|
|
31087
30527
|
function defaultDataDir() {
|
|
31088
|
-
return
|
|
30528
|
+
return join5(homedir(), ".aka");
|
|
31089
30529
|
}
|
|
31090
30530
|
function settingsDir(base = defaultDataDir()) {
|
|
31091
|
-
return
|
|
30531
|
+
return join5(base, "settings");
|
|
31092
30532
|
}
|
|
31093
30533
|
function dataDir(base = defaultDataDir()) {
|
|
31094
|
-
return
|
|
30534
|
+
return join5(base, "data");
|
|
31095
30535
|
}
|
|
31096
30536
|
function dbPath(base = defaultDataDir()) {
|
|
31097
|
-
return
|
|
30537
|
+
return join5(dataDir(base), "aka.db");
|
|
31098
30538
|
}
|
|
31099
30539
|
async function ensureDataDir(dir = defaultDataDir()) {
|
|
31100
30540
|
await mkdir(dir, { recursive: true, mode: DATA_DIR_MODE });
|
|
@@ -31111,8 +30551,8 @@ function migrateLegacyLayout(base = defaultDataDir()) {
|
|
|
31111
30551
|
for (const { name, dest } of moves) {
|
|
31112
30552
|
try {
|
|
31113
30553
|
ensureDataDirSync(dest);
|
|
31114
|
-
const moved =
|
|
31115
|
-
renameSync3(
|
|
30554
|
+
const moved = join5(dest, name);
|
|
30555
|
+
renameSync3(join5(base, name), moved);
|
|
31116
30556
|
tightenFile(moved);
|
|
31117
30557
|
} catch {
|
|
31118
30558
|
}
|
|
@@ -31120,8 +30560,8 @@ function migrateLegacyLayout(base = defaultDataDir()) {
|
|
|
31120
30560
|
}
|
|
31121
30561
|
|
|
31122
30562
|
// ../../packages/persistence/src/settings.ts
|
|
31123
|
-
import { readFileSync as
|
|
31124
|
-
import { join as
|
|
30563
|
+
import { readFileSync as readFileSync5 } from "fs";
|
|
30564
|
+
import { join as join6 } from "path";
|
|
31125
30565
|
|
|
31126
30566
|
// ../../packages/persistence/src/file-lock.ts
|
|
31127
30567
|
import { randomUUID as randomUUID3 } from "crypto";
|
|
@@ -31129,7 +30569,7 @@ import {
|
|
|
31129
30569
|
closeSync,
|
|
31130
30570
|
existsSync as existsSync2,
|
|
31131
30571
|
openSync,
|
|
31132
|
-
readFileSync as
|
|
30572
|
+
readFileSync as readFileSync3,
|
|
31133
30573
|
rmSync as rmSync5,
|
|
31134
30574
|
statSync as statSync3,
|
|
31135
30575
|
writeFileSync as writeFileSync2
|
|
@@ -31138,16 +30578,16 @@ import { hostname as hostname3 } from "os";
|
|
|
31138
30578
|
var PARK = new Int32Array(new SharedArrayBuffer(4));
|
|
31139
30579
|
|
|
31140
30580
|
// ../../packages/persistence/src/managed-settings.ts
|
|
31141
|
-
import { readFileSync as
|
|
30581
|
+
import { readFileSync as readFileSync4 } from "fs";
|
|
31142
30582
|
import { posix, win32 } from "path";
|
|
31143
|
-
function managedSettingsPaths(
|
|
31144
|
-
if (
|
|
30583
|
+
function managedSettingsPaths(platform = process.platform) {
|
|
30584
|
+
if (platform === "darwin") {
|
|
31145
30585
|
return [
|
|
31146
30586
|
posix.join("/Library", "Application Support", "AKASecurity", MANAGED_SETTINGS_FILENAME),
|
|
31147
30587
|
posix.join("/Library", "Managed Preferences", MANAGED_SETTINGS_FILENAME)
|
|
31148
30588
|
];
|
|
31149
30589
|
}
|
|
31150
|
-
if (
|
|
30590
|
+
if (platform === "win32") {
|
|
31151
30591
|
return [win32.join("C:\\", "ProgramData", "AKASecurity", MANAGED_SETTINGS_FILENAME)];
|
|
31152
30592
|
}
|
|
31153
30593
|
return [posix.join("/etc", "aka", MANAGED_SETTINGS_FILENAME)];
|
|
@@ -31157,7 +30597,7 @@ function readManagedSettings(paths = testOnlyManagedPaths ?? managedSettingsPath
|
|
|
31157
30597
|
for (const path of paths) {
|
|
31158
30598
|
let text;
|
|
31159
30599
|
try {
|
|
31160
|
-
text =
|
|
30600
|
+
text = readFileSync4(path, "utf8");
|
|
31161
30601
|
} catch {
|
|
31162
30602
|
continue;
|
|
31163
30603
|
}
|
|
@@ -31211,7 +30651,7 @@ function readWorkspaceSettings(base = defaultDataDir()) {
|
|
|
31211
30651
|
return overlayManagedSettings(readUserSettings(base), readManagedSettings());
|
|
31212
30652
|
}
|
|
31213
30653
|
function readUserSettings(base) {
|
|
31214
|
-
const record2 = readJson(
|
|
30654
|
+
const record2 = readJson(join6(settingsDir(base), SETTINGS_FILENAME));
|
|
31215
30655
|
if (!record2) return defaultWorkspaceSettings();
|
|
31216
30656
|
try {
|
|
31217
30657
|
return WorkspaceSettings.parse(record2);
|
|
@@ -31222,7 +30662,7 @@ function readUserSettings(base) {
|
|
|
31222
30662
|
function readJson(file2) {
|
|
31223
30663
|
let text;
|
|
31224
30664
|
try {
|
|
31225
|
-
text =
|
|
30665
|
+
text = readFileSync5(file2, "utf8");
|
|
31226
30666
|
} catch {
|
|
31227
30667
|
return null;
|
|
31228
30668
|
}
|
|
@@ -31262,7 +30702,7 @@ var PolicyFloorError = class extends Error {
|
|
|
31262
30702
|
};
|
|
31263
30703
|
function readCachedPolicyBundle(base = defaultDataDir()) {
|
|
31264
30704
|
try {
|
|
31265
|
-
const raw =
|
|
30705
|
+
const raw = readFileSync6(join7(dataDir(base), POLICY_CACHE_FILENAME), "utf8");
|
|
31266
30706
|
const parsed2 = JSON.parse(raw);
|
|
31267
30707
|
if (typeof parsed2 !== "object" || parsed2 === null) return null;
|
|
31268
30708
|
return PolicyBundle.parse(parsed2.bundle);
|
|
@@ -31386,7 +30826,7 @@ function inventorySignature(packs2) {
|
|
|
31386
30826
|
return packs2.map((p) => `${p.namespace}/${p.packId}@${p.version}#${hashRules(p.rulesJson)}`).sort().join(",");
|
|
31387
30827
|
}
|
|
31388
30828
|
function hashRules(rulesJson) {
|
|
31389
|
-
return
|
|
30829
|
+
return createHash3("sha256").update(rulesJson).digest("hex");
|
|
31390
30830
|
}
|
|
31391
30831
|
function parseVersion(v) {
|
|
31392
30832
|
const m = /^(\d+)\.(\d+)\.(\d+)/.exec(v);
|
|
@@ -31428,9 +30868,10 @@ var SqliteInstalledPacksRepository = class {
|
|
|
31428
30868
|
* from `openLocalDatabase`, which is the single construction site that owns a
|
|
31429
30869
|
* real `~/.aka`.
|
|
31430
30870
|
*/
|
|
31431
|
-
constructor(db, baseDir) {
|
|
30871
|
+
constructor(db, baseDir, onChange = () => void 0) {
|
|
31432
30872
|
this.db = db;
|
|
31433
30873
|
this.baseDir = baseDir;
|
|
30874
|
+
this.onChange = onChange;
|
|
31434
30875
|
this.insertMissingStmt = db.prepare(
|
|
31435
30876
|
`INSERT INTO installed_packs (id, namespace, pack_id, version, name, rules_json, enabled, policy_id, created_at, updated_at)
|
|
31436
30877
|
VALUES (:id, :namespace, :packId, :version, :name, :rulesJson, 1, :policyId, :now, :now)
|
|
@@ -31459,6 +30900,7 @@ var SqliteInstalledPacksRepository = class {
|
|
|
31459
30900
|
}
|
|
31460
30901
|
db;
|
|
31461
30902
|
baseDir;
|
|
30903
|
+
onChange;
|
|
31462
30904
|
insertMissingStmt;
|
|
31463
30905
|
upsertAvailableStmt;
|
|
31464
30906
|
signatureStmt;
|
|
@@ -31531,6 +30973,7 @@ var SqliteInstalledPacksRepository = class {
|
|
|
31531
30973
|
},
|
|
31532
30974
|
"IMMEDIATE"
|
|
31533
30975
|
);
|
|
30976
|
+
this.onChange();
|
|
31534
30977
|
} catch {
|
|
31535
30978
|
}
|
|
31536
30979
|
}
|
|
@@ -31605,6 +31048,7 @@ var SqliteInstalledPacksRepository = class {
|
|
|
31605
31048
|
},
|
|
31606
31049
|
"IMMEDIATE"
|
|
31607
31050
|
);
|
|
31051
|
+
if (changed) this.onChange();
|
|
31608
31052
|
return changed;
|
|
31609
31053
|
}
|
|
31610
31054
|
/**
|
|
@@ -31846,6 +31290,7 @@ var SqliteInstalledPacksRepository = class {
|
|
|
31846
31290
|
`UPDATE installed_packs SET policy_id = :policyId, updated_at = :now
|
|
31847
31291
|
WHERE namespace = :namespace AND pack_id = :packId`
|
|
31848
31292
|
).run({ policyId, now: Date.now(), namespace, packId });
|
|
31293
|
+
if (Number(res.changes) > 0) this.onChange();
|
|
31849
31294
|
return Number(res.changes) > 0;
|
|
31850
31295
|
}
|
|
31851
31296
|
/**
|
|
@@ -31870,6 +31315,7 @@ var SqliteInstalledPacksRepository = class {
|
|
|
31870
31315
|
`UPDATE installed_packs SET enabled = :enabled, updated_at = :now
|
|
31871
31316
|
WHERE namespace = :namespace AND pack_id = :packId`
|
|
31872
31317
|
).run({ enabled: boolToInt(enabled), now: Date.now(), namespace, packId });
|
|
31318
|
+
if (Number(res.changes) > 0) this.onChange();
|
|
31873
31319
|
return Number(res.changes) > 0;
|
|
31874
31320
|
}
|
|
31875
31321
|
// Fingerprint of the recorded available mirror — compared against the
|
|
@@ -32767,13 +32213,19 @@ var SqliteInventoryAssetsRepository = class {
|
|
|
32767
32213
|
import { randomUUID as randomUUID6 } from "crypto";
|
|
32768
32214
|
var SEED_BATCH_WINDOW_MS = 6e4;
|
|
32769
32215
|
var SqlitePoliciesRepository = class {
|
|
32770
|
-
constructor(db) {
|
|
32216
|
+
constructor(db, onChange = () => void 0) {
|
|
32771
32217
|
this.db = db;
|
|
32218
|
+
this.onChange = onChange;
|
|
32772
32219
|
}
|
|
32773
32220
|
db;
|
|
32221
|
+
onChange;
|
|
32774
32222
|
readPolicies() {
|
|
32223
|
+
return Promise.resolve(this.listPolicies());
|
|
32224
|
+
}
|
|
32225
|
+
/** The synchronous read behind {@link readPolicies}. */
|
|
32226
|
+
listPolicies() {
|
|
32775
32227
|
const rows = allRows(this.db.prepare("SELECT * FROM policies"));
|
|
32776
|
-
|
|
32228
|
+
return mapRowsTolerant(rows, (row) => {
|
|
32777
32229
|
const target = JSON.parse(row.target);
|
|
32778
32230
|
const customKeywords = row.custom_keywords ? JSON.parse(row.custom_keywords) : void 0;
|
|
32779
32231
|
return Policy.parse({
|
|
@@ -32785,7 +32237,6 @@ var SqlitePoliciesRepository = class {
|
|
|
32785
32237
|
customKeywords
|
|
32786
32238
|
});
|
|
32787
32239
|
});
|
|
32788
|
-
return Promise.resolve(policies);
|
|
32789
32240
|
}
|
|
32790
32241
|
// Seed one policy per bundled category at Monitor so the detection-type config
|
|
32791
32242
|
// exists from first run. An unassigned pack's rules follow these rows, so
|
|
@@ -32796,7 +32247,7 @@ var SqlitePoliciesRepository = class {
|
|
|
32796
32247
|
const count = countScalar(this.db, "SELECT count(*) AS n FROM policies");
|
|
32797
32248
|
if (count > 0) {
|
|
32798
32249
|
this.markEarlierChoices();
|
|
32799
|
-
this.monitorUntouchedSeeds();
|
|
32250
|
+
if (this.monitorUntouchedSeeds()) this.onChange();
|
|
32800
32251
|
return;
|
|
32801
32252
|
}
|
|
32802
32253
|
const stmt = this.db.prepare(
|
|
@@ -32813,6 +32264,7 @@ var SqlitePoliciesRepository = class {
|
|
|
32813
32264
|
});
|
|
32814
32265
|
}
|
|
32815
32266
|
});
|
|
32267
|
+
this.onChange();
|
|
32816
32268
|
}
|
|
32817
32269
|
// Before this build, upsertCategoryAction INSERTed a new row with updated_at
|
|
32818
32270
|
// equal to created_at, so a choice made for a category that had no row yet
|
|
@@ -32878,7 +32330,7 @@ var SqlitePoliciesRepository = class {
|
|
|
32878
32330
|
).filter(
|
|
32879
32331
|
(row) => DEFAULT_ACTIONS[row.category] === row.action
|
|
32880
32332
|
);
|
|
32881
|
-
if (untouched.length === 0) return;
|
|
32333
|
+
if (untouched.length === 0) return false;
|
|
32882
32334
|
const stmt = this.db.prepare(
|
|
32883
32335
|
`UPDATE policies SET action = 'log'
|
|
32884
32336
|
WHERE scope = 'global' AND json_extract(target, '$.category') = :category
|
|
@@ -32889,6 +32341,7 @@ var SqlitePoliciesRepository = class {
|
|
|
32889
32341
|
stmt.run({ category: row.category, seeded: row.action });
|
|
32890
32342
|
}
|
|
32891
32343
|
});
|
|
32344
|
+
return true;
|
|
32892
32345
|
}
|
|
32893
32346
|
// Insert-or-update the single global per-category policy row, keyed on the
|
|
32894
32347
|
// existing uq_policies_scope_target unique index (scope, target). `action`
|
|
@@ -32905,6 +32358,7 @@ var SqlitePoliciesRepository = class {
|
|
|
32905
32358
|
ON CONFLICT(scope, target) DO UPDATE SET action = excluded.action, enabled = 1,
|
|
32906
32359
|
updated_at = MAX(excluded.updated_at, policies.created_at + 1)`
|
|
32907
32360
|
).run({ id: randomUUID6(), target: JSON.stringify({ category }), action, now });
|
|
32361
|
+
this.onChange();
|
|
32908
32362
|
}
|
|
32909
32363
|
// Caps every global per-category policy currently set to block/redact down
|
|
32910
32364
|
// to warn (see warn-era-cap.ts). Rule-targeted policies are untouched.
|
|
@@ -32915,6 +32369,7 @@ var SqlitePoliciesRepository = class {
|
|
|
32915
32369
|
WHERE scope='global' AND action IN ('block','redact')
|
|
32916
32370
|
AND json_extract(target,'$.category') IS NOT NULL`
|
|
32917
32371
|
).run({ now: Date.now() });
|
|
32372
|
+
if (Number(info.changes) > 0) this.onChange();
|
|
32918
32373
|
return Number(info.changes);
|
|
32919
32374
|
}
|
|
32920
32375
|
// Whether the category's row was ever written after it was created — by the
|
|
@@ -33234,31 +32689,45 @@ var SqliteScanLedgerRepository = class {
|
|
|
33234
32689
|
constructor(db) {
|
|
33235
32690
|
this.db = db;
|
|
33236
32691
|
this.upsertStmt = db.prepare(
|
|
33237
|
-
`INSERT INTO scan_ledger
|
|
33238
|
-
|
|
32692
|
+
`INSERT INTO scan_ledger
|
|
32693
|
+
(path, mtime, content_hash, ruleset_hash, scope_key, scope_root, scanned_at)
|
|
32694
|
+
VALUES (:path, :mtime, :contentHash, :rulesetHash, :scopeKey, :scopeRoot, :scannedAt)
|
|
33239
32695
|
ON CONFLICT (path) DO UPDATE SET
|
|
33240
32696
|
mtime = excluded.mtime,
|
|
33241
32697
|
content_hash = excluded.content_hash,
|
|
33242
32698
|
ruleset_hash = excluded.ruleset_hash,
|
|
32699
|
+
scope_key = excluded.scope_key,
|
|
32700
|
+
scope_root = excluded.scope_root,
|
|
33243
32701
|
scanned_at = excluded.scanned_at`
|
|
33244
32702
|
);
|
|
33245
32703
|
this.readStmt = db.prepare(
|
|
33246
|
-
`SELECT path, mtime, content_hash AS contentHash
|
|
32704
|
+
`SELECT path, mtime, content_hash AS contentHash, scope_key AS scopeKey,
|
|
32705
|
+
scope_root AS scopeRoot
|
|
33247
32706
|
FROM scan_ledger WHERE ruleset_hash = :rulesetHash`
|
|
33248
32707
|
);
|
|
33249
32708
|
this.pathsStmt = db.prepare(`SELECT path FROM scan_ledger`);
|
|
32709
|
+
this.pathKeysStmt = db.prepare(`SELECT path, scope_key AS scopeKey FROM scan_ledger`);
|
|
33250
32710
|
}
|
|
33251
32711
|
db;
|
|
33252
32712
|
upsertStmt;
|
|
33253
32713
|
readStmt;
|
|
33254
32714
|
pathsStmt;
|
|
32715
|
+
pathKeysStmt;
|
|
33255
32716
|
// Previously scanned files under THIS ruleset, keyed by path. Rows from an
|
|
33256
32717
|
// older ruleset are simply absent, which reads as "never scanned".
|
|
33257
32718
|
entriesForRuleset(rulesetHash) {
|
|
33258
|
-
const rows = allRows(this.readStmt, {
|
|
33259
|
-
|
|
33260
|
-
|
|
33261
|
-
|
|
32719
|
+
const rows = allRows(this.readStmt, { rulesetHash });
|
|
32720
|
+
return new Map(
|
|
32721
|
+
rows.map((r) => [
|
|
32722
|
+
r.path,
|
|
32723
|
+
{
|
|
32724
|
+
mtime: r.mtime,
|
|
32725
|
+
contentHash: r.contentHash,
|
|
32726
|
+
...r.scopeKey !== null ? { scopeKey: r.scopeKey } : {},
|
|
32727
|
+
...r.scopeRoot !== null ? { scopeRoot: r.scopeRoot } : {}
|
|
32728
|
+
}
|
|
32729
|
+
])
|
|
32730
|
+
);
|
|
33262
32731
|
}
|
|
33263
32732
|
// Every ledgered path, whatever ruleset it was scanned under — the set a
|
|
33264
32733
|
// deletion sweep checks against disk. A file deleted before a ruleset change
|
|
@@ -33267,6 +32736,14 @@ var SqliteScanLedgerRepository = class {
|
|
|
33267
32736
|
allPaths() {
|
|
33268
32737
|
return allRows(this.pathsStmt).map((r) => r.path);
|
|
33269
32738
|
}
|
|
32739
|
+
// Every ledgered path with the repository it was in when it was last read,
|
|
32740
|
+
// whatever ruleset it was scanned under: what a deletion sweep needs to say
|
|
32741
|
+
// which repository a vanished file belonged to. `undefined` for a row with no
|
|
32742
|
+
// key, which is every row written before the column existed.
|
|
32743
|
+
pathKeys() {
|
|
32744
|
+
const rows = allRows(this.pathKeysStmt);
|
|
32745
|
+
return new Map(rows.map((r) => [r.path, r.scopeKey ?? void 0]));
|
|
32746
|
+
}
|
|
33270
32747
|
upsertEntries(entries) {
|
|
33271
32748
|
if (entries.length === 0) return;
|
|
33272
32749
|
const scannedAt = Date.now();
|
|
@@ -33277,6 +32754,8 @@ var SqliteScanLedgerRepository = class {
|
|
|
33277
32754
|
mtime: entry.mtime,
|
|
33278
32755
|
contentHash: entry.contentHash,
|
|
33279
32756
|
rulesetHash: entry.rulesetHash,
|
|
32757
|
+
scopeKey: entry.scopeKey ?? null,
|
|
32758
|
+
scopeRoot: entry.scopeRoot ?? null,
|
|
33280
32759
|
scannedAt
|
|
33281
32760
|
});
|
|
33282
32761
|
}
|
|
@@ -34364,6 +33843,11 @@ function withoutDroppedFiles(reconcile, droppedFiles) {
|
|
|
34364
33843
|
deletedFiles: reconcile.deletedFiles.filter((file2) => !dropped.has(file2))
|
|
34365
33844
|
};
|
|
34366
33845
|
}
|
|
33846
|
+
function withoutTrailingSlashes(path) {
|
|
33847
|
+
let end = path.length;
|
|
33848
|
+
while (end > 0 && path.charCodeAt(end - 1) === 47) end--;
|
|
33849
|
+
return path.slice(0, end);
|
|
33850
|
+
}
|
|
34367
33851
|
function toEndpointSummary(row) {
|
|
34368
33852
|
return {
|
|
34369
33853
|
id: row.id,
|
|
@@ -34651,7 +34135,7 @@ var SqliteSharesRepository = class {
|
|
|
34651
34135
|
*/
|
|
34652
34136
|
reconcileCallSites(projectKey, reconcile) {
|
|
34653
34137
|
if (reconcile.mode === "walk") {
|
|
34654
|
-
const prefix = reconcile.walkedPrefix
|
|
34138
|
+
const prefix = withoutTrailingSlashes(reconcile.walkedPrefix);
|
|
34655
34139
|
this.db.prepare(
|
|
34656
34140
|
`DELETE FROM share_call_site
|
|
34657
34141
|
WHERE project_key = :key
|
|
@@ -35219,7 +34703,7 @@ function backupLegacyStore(db, file2) {
|
|
|
35219
34703
|
discardStore(file2, backup);
|
|
35220
34704
|
return backup;
|
|
35221
34705
|
}
|
|
35222
|
-
function openAndInitialize(file2, base, skipTags) {
|
|
34706
|
+
function openAndInitialize(file2, base, skipTags, shippedRegexMatchers2) {
|
|
35223
34707
|
let db = openWithPragmas(file2);
|
|
35224
34708
|
try {
|
|
35225
34709
|
if (isForeignSqliteLineage(db)) {
|
|
@@ -35231,8 +34715,15 @@ function openAndInitialize(file2, base, skipTags) {
|
|
|
35231
34715
|
}
|
|
35232
34716
|
applyMigrations(db, file2, { skipTags });
|
|
35233
34717
|
tightenPerms(file2);
|
|
35234
|
-
const
|
|
35235
|
-
const
|
|
34718
|
+
const modPolicy = {};
|
|
34719
|
+
const onPolicyStateChange = () => {
|
|
34720
|
+
if (modPolicy.current !== void 0)
|
|
34721
|
+
refreshModPolicySnapshot(dirname2(file2), modPolicy.current);
|
|
34722
|
+
};
|
|
34723
|
+
const policies = new SqlitePoliciesRepository(db, onPolicyStateChange);
|
|
34724
|
+
const installedPacks = new SqliteInstalledPacksRepository(db, base, onPolicyStateChange);
|
|
34725
|
+
const ruleProbeCache = new SqliteRuleProbeCacheRepository(db);
|
|
34726
|
+
const exceptions = new SqliteExceptionsRepository(db, void 0, onPolicyStateChange);
|
|
35236
34727
|
const repositories = {
|
|
35237
34728
|
events: new SqliteEventsRepository(db),
|
|
35238
34729
|
findings: new SqliteFindingsRepository(db),
|
|
@@ -35241,9 +34732,9 @@ function openAndInitialize(file2, base, skipTags) {
|
|
|
35241
34732
|
scanLedger: new SqliteScanLedgerRepository(db),
|
|
35242
34733
|
historySync: new SqliteHistorySyncRepository(db),
|
|
35243
34734
|
secretVault: new SqliteSecretVaultRepository(db),
|
|
35244
|
-
exceptions
|
|
34735
|
+
exceptions,
|
|
35245
34736
|
resolutions: new SqliteResolutionsRepository(db),
|
|
35246
|
-
ruleProbeCache
|
|
34737
|
+
ruleProbeCache,
|
|
35247
34738
|
bodyRetention: new SqliteBodyRetentionRepository(db),
|
|
35248
34739
|
security: new SqliteSecurityRepository(db),
|
|
35249
34740
|
detections: new SqliteDetectionsRepository(db),
|
|
@@ -35261,6 +34752,13 @@ function openAndInitialize(file2, base, skipTags) {
|
|
|
35261
34752
|
inspectionFindings: new SqliteInspectionFindingsRepository(db),
|
|
35262
34753
|
configInventory: new SqliteConfigInventoryRepository(db)
|
|
35263
34754
|
};
|
|
34755
|
+
modPolicy.current = {
|
|
34756
|
+
installedRuleset: () => installedPacks.installedRuleset(),
|
|
34757
|
+
readPolicies: () => policies.listPolicies(),
|
|
34758
|
+
activeExceptionRuleIds: () => exceptions.activeRuleIds(),
|
|
34759
|
+
probeVerdict: (key) => ruleProbeCache.getVerdict(key)?.verdict,
|
|
34760
|
+
bundledRegexMatchers: () => shippedRegexMatchers2
|
|
34761
|
+
};
|
|
35264
34762
|
policies.seedDefaults();
|
|
35265
34763
|
return { db, ...repositories };
|
|
35266
34764
|
} catch (err) {
|
|
@@ -35272,7 +34770,7 @@ function openAndInitialize(file2, base, skipTags) {
|
|
|
35272
34770
|
var DEFERRED_TAGS = new Set(DEFERRED_MIGRATION_TAGS);
|
|
35273
34771
|
function openLocalDatabase(dir, options = {}) {
|
|
35274
34772
|
ensureDataDirSync(dir);
|
|
35275
|
-
const file2 =
|
|
34773
|
+
const file2 = join8(dir, DB_FILENAME);
|
|
35276
34774
|
reapStalePartials(file2);
|
|
35277
34775
|
const {
|
|
35278
34776
|
db,
|
|
@@ -35308,7 +34806,8 @@ function openLocalDatabase(dir, options = {}) {
|
|
|
35308
34806
|
// `dataDir()` — so its parent is the `~/.aka` base the layout splits into
|
|
35309
34807
|
// settings/ and data/, and the pack-policy floor needs both halves.
|
|
35310
34808
|
dirname2(dir),
|
|
35311
|
-
options.applyDeferredMigrations === true ? void 0 : DEFERRED_TAGS
|
|
34809
|
+
options.applyDeferredMigrations === true ? void 0 : DEFERRED_TAGS,
|
|
34810
|
+
options.shippedRegexMatchers ?? []
|
|
35312
34811
|
);
|
|
35313
34812
|
function captureRowId(event) {
|
|
35314
34813
|
return captureId(
|
|
@@ -35573,7 +35072,7 @@ function openLocalDatabase(dir, options = {}) {
|
|
|
35573
35072
|
}
|
|
35574
35073
|
|
|
35575
35074
|
// ../../packages/persistence/src/egress-wire.ts
|
|
35576
|
-
import { createHash as
|
|
35075
|
+
import { createHash as createHash4 } from "crypto";
|
|
35577
35076
|
var PROJECT_KEY_DIGEST_VERSION = "v2";
|
|
35578
35077
|
var SCP_FORM = /^(?:[^@/]+@)?([^/:]+):(.+)$/;
|
|
35579
35078
|
var DOS_DRIVE = /^[A-Za-z]:[\\/]/;
|
|
@@ -35605,7 +35104,7 @@ function canonicalGitUrl(url2) {
|
|
|
35605
35104
|
}
|
|
35606
35105
|
function hashProjectKey(projectKey) {
|
|
35607
35106
|
const canonical = projectKey.startsWith("git:") ? `git:${canonicalGitUrl(projectKey.slice("git:".length))}` : projectKey;
|
|
35608
|
-
return
|
|
35107
|
+
return createHash4("sha256").update(`${PROJECT_KEY_DIGEST_VERSION}:${canonical}`, "utf8").digest("hex");
|
|
35609
35108
|
}
|
|
35610
35109
|
var SCOPE_KEY = printable(ATTACHMENT_SCOPE_IDENTITY_MAX_LENGTH);
|
|
35611
35110
|
var URL_SCHEME = /^[a-z][a-z0-9+.-]*:\/\//i;
|
|
@@ -35670,24 +35169,23 @@ function toEgressIngestRequest(input2) {
|
|
|
35670
35169
|
}
|
|
35671
35170
|
|
|
35672
35171
|
// ../../packages/persistence/src/finding-key.ts
|
|
35673
|
-
import { createHash as
|
|
35172
|
+
import { createHash as createHash5 } from "crypto";
|
|
35674
35173
|
function normalizeFilePath(filePath) {
|
|
35675
35174
|
return filePath.replaceAll("\\", "/");
|
|
35676
35175
|
}
|
|
35677
35176
|
function computeFindingKey(input2) {
|
|
35678
35177
|
const normalizedPath = normalizeFilePath(input2.filePath);
|
|
35679
|
-
return
|
|
35178
|
+
return createHash5("sha256").update(`${input2.ruleId}\0${normalizedPath}\0${input2.valueFingerprint}`).digest("hex");
|
|
35680
35179
|
}
|
|
35681
35180
|
|
|
35682
35181
|
// ../../packages/persistence/src/fingerprint.ts
|
|
35683
35182
|
import { createHmac, randomBytes } from "crypto";
|
|
35684
|
-
import { existsSync as existsSync3, readFileSync as
|
|
35685
|
-
import { join as
|
|
35686
|
-
import { DatabaseSync as DatabaseSync2 } from "node:sqlite";
|
|
35183
|
+
import { existsSync as existsSync3, readFileSync as readFileSync7 } from "fs";
|
|
35184
|
+
import { join as join9 } from "path";
|
|
35687
35185
|
var EXCEPTION_KEY_FILENAME = "exception.key";
|
|
35688
35186
|
var KEY_MATERIAL_BYTES = 32;
|
|
35689
35187
|
function keyFilePath(dataDir2) {
|
|
35690
|
-
return
|
|
35188
|
+
return join9(dataDir2, EXCEPTION_KEY_FILENAME);
|
|
35691
35189
|
}
|
|
35692
35190
|
function parseKeyFile(raw) {
|
|
35693
35191
|
const parsed2 = JSON.parse(raw);
|
|
@@ -35714,6 +35212,12 @@ var KEY_VERSION_COLUMNS = {
|
|
|
35714
35212
|
};
|
|
35715
35213
|
var SQLITE_ERROR2 = 1;
|
|
35716
35214
|
var FLOOR_BUSY_TIMEOUT_MS = 250;
|
|
35215
|
+
function openReadOnly(file2) {
|
|
35216
|
+
const host = process;
|
|
35217
|
+
const sqlite = host.getBuiltinModule?.("node:sqlite");
|
|
35218
|
+
if (sqlite === void 0) throw new Error("this Node runtime cannot load node:sqlite");
|
|
35219
|
+
return new sqlite.DatabaseSync(file2, { readOnly: true });
|
|
35220
|
+
}
|
|
35717
35221
|
var FloorUnreadableError = class extends Error {
|
|
35718
35222
|
code = "floor-unreadable";
|
|
35719
35223
|
constructor(cause) {
|
|
@@ -35725,11 +35229,11 @@ var FloorUnreadableError = class extends Error {
|
|
|
35725
35229
|
}
|
|
35726
35230
|
};
|
|
35727
35231
|
function storedKeyVersionFloor(dataDir2) {
|
|
35728
|
-
const file2 =
|
|
35232
|
+
const file2 = join9(dataDir2, DB_FILENAME);
|
|
35729
35233
|
if (!existsSync3(file2)) return 0;
|
|
35730
35234
|
let db;
|
|
35731
35235
|
try {
|
|
35732
|
-
db =
|
|
35236
|
+
db = openReadOnly(file2);
|
|
35733
35237
|
db.exec(`PRAGMA busy_timeout = ${String(FLOOR_BUSY_TIMEOUT_MS)}`);
|
|
35734
35238
|
let floor = 0;
|
|
35735
35239
|
for (const [table2, column] of Object.entries(KEY_VERSION_COLUMNS)) {
|
|
@@ -35780,7 +35284,7 @@ function occupantMessage(file2, kind) {
|
|
|
35780
35284
|
function readFingerprintKey(dataDir2) {
|
|
35781
35285
|
let raw;
|
|
35782
35286
|
try {
|
|
35783
|
-
raw =
|
|
35287
|
+
raw = readFileSync7(keyFilePath(dataDir2), "utf8");
|
|
35784
35288
|
} catch (err) {
|
|
35785
35289
|
if (err.code === "ENOENT") return null;
|
|
35786
35290
|
throw err instanceof Error ? err : new Error(String(err));
|
|
@@ -35806,8 +35310,8 @@ function exactFingerprintValue(key, raw) {
|
|
|
35806
35310
|
}
|
|
35807
35311
|
|
|
35808
35312
|
// ../../packages/persistence/src/forward-health.ts
|
|
35809
|
-
import { readFileSync as
|
|
35810
|
-
import { join as
|
|
35313
|
+
import { readFileSync as readFileSync8 } from "fs";
|
|
35314
|
+
import { join as join10 } from "path";
|
|
35811
35315
|
var BREAKER_COOLDOWN_MS = 3e4;
|
|
35812
35316
|
function parseForwardHealth(raw, nowMs) {
|
|
35813
35317
|
try {
|
|
@@ -35831,20 +35335,21 @@ function isForwardPaused(health, nowMs) {
|
|
|
35831
35335
|
|
|
35832
35336
|
// ../../packages/persistence/src/history-backfill.ts
|
|
35833
35337
|
import { existsSync as existsSync4 } from "fs";
|
|
35834
|
-
import { join as
|
|
35338
|
+
import { join as join11 } from "path";
|
|
35835
35339
|
|
|
35836
35340
|
// ../../packages/persistence/src/history-preview.ts
|
|
35837
35341
|
import { existsSync as existsSync5 } from "fs";
|
|
35838
|
-
import { join as
|
|
35839
|
-
import { DatabaseSync as
|
|
35342
|
+
import { join as join12 } from "path";
|
|
35343
|
+
import { DatabaseSync as DatabaseSync2 } from "node:sqlite";
|
|
35840
35344
|
|
|
35841
35345
|
// ../../packages/persistence/src/history-sync-state.ts
|
|
35842
|
-
import { readFileSync as
|
|
35843
|
-
import { join as
|
|
35346
|
+
import { readFileSync as readFileSync9 } from "fs";
|
|
35347
|
+
import { join as join13 } from "path";
|
|
35348
|
+
var COUNTS_SCOPES = new Set(AttachmentMode.options);
|
|
35844
35349
|
|
|
35845
35350
|
// ../../packages/persistence/src/store-symlinks.ts
|
|
35846
35351
|
import { existsSync as existsSync6, lstatSync as lstatSync3, readlinkSync, realpathSync, statSync as statSync4 } from "fs";
|
|
35847
|
-
import { dirname as dirname3, join as
|
|
35352
|
+
import { dirname as dirname3, join as join14, resolve } from "path";
|
|
35848
35353
|
|
|
35849
35354
|
// ../../packages/persistence/src/vault/crypto.ts
|
|
35850
35355
|
import {
|
|
@@ -35858,19 +35363,19 @@ import {
|
|
|
35858
35363
|
// ../../packages/persistence/src/vault/key-provider.ts
|
|
35859
35364
|
import { execFileSync } from "child_process";
|
|
35860
35365
|
import { randomBytes as randomBytes2 } from "crypto";
|
|
35861
|
-
import { chmodSync as chmodSync3, readFileSync as
|
|
35862
|
-
import { join as
|
|
35366
|
+
import { chmodSync as chmodSync3, readFileSync as readFileSync10, renameSync as renameSync4, rmSync as rmSync6, statSync as statSync5, writeFileSync as writeFileSync3 } from "fs";
|
|
35367
|
+
import { join as join15 } from "path";
|
|
35863
35368
|
|
|
35864
35369
|
// ../../packages/persistence/src/vault/vault.ts
|
|
35865
35370
|
import { randomBytes as randomBytes3, randomUUID as randomUUID12 } from "crypto";
|
|
35866
35371
|
|
|
35867
35372
|
// ../../packages/persistence/src/warn-era-cap.ts
|
|
35868
35373
|
import { existsSync as existsSync7, writeFileSync as writeFileSync4 } from "fs";
|
|
35869
|
-
import { join as
|
|
35374
|
+
import { join as join16 } from "path";
|
|
35870
35375
|
var MARKER = "warn-era-capped";
|
|
35871
35376
|
function capWarnEraEnforcementOnce(db, policyMode, dataDir2) {
|
|
35872
35377
|
if (policyMode !== "warn") return { capped: 0, skipped: "not-warn" };
|
|
35873
|
-
const marker =
|
|
35378
|
+
const marker = join16(dataDir2, MARKER);
|
|
35874
35379
|
if (existsSync7(marker)) return { capped: 0, skipped: "already-run" };
|
|
35875
35380
|
const capped = db.policies.capCategoryActions();
|
|
35876
35381
|
writeFileSync4(marker, `${new Date(Date.now()).toISOString()}
|
|
@@ -35880,7 +35385,7 @@ function capWarnEraEnforcementOnce(db, policyMode, dataDir2) {
|
|
|
35880
35385
|
|
|
35881
35386
|
// ../../packages/plugin-sdk/src/config.ts
|
|
35882
35387
|
import { existsSync as existsSync8 } from "fs";
|
|
35883
|
-
import { join as
|
|
35388
|
+
import { join as join17 } from "path";
|
|
35884
35389
|
|
|
35885
35390
|
// ../../packages/plugin-sdk/src/provider-env.ts
|
|
35886
35391
|
var DEFAULT_ANTHROPIC_HOST = "api.anthropic.com";
|
|
@@ -35934,7 +35439,7 @@ function resolveProvider() {
|
|
|
35934
35439
|
function loadConfig(base = defaultDataDir(), resolveProviderFn = resolveProvider) {
|
|
35935
35440
|
try {
|
|
35936
35441
|
ensureLayoutDirSync(base);
|
|
35937
|
-
const settingsFile =
|
|
35442
|
+
const settingsFile = join17(settingsDir(base), "settings.json");
|
|
35938
35443
|
if (existsSync8(settingsFile)) tightenFile(settingsFile);
|
|
35939
35444
|
} catch {
|
|
35940
35445
|
}
|
|
@@ -35957,11 +35462,6 @@ function resolveProviderSafe(resolveProviderFn) {
|
|
|
35957
35462
|
}
|
|
35958
35463
|
}
|
|
35959
35464
|
|
|
35960
|
-
// ../../packages/plugin-sdk/src/config-inventory.ts
|
|
35961
|
-
import { readdirSync as readdirSync2, readFileSync as readFileSync11, realpathSync as realpathSync2, statSync as statSync7 } from "fs";
|
|
35962
|
-
import { homedir as homedir2 } from "os";
|
|
35963
|
-
import { basename as basename3, join as join18 } from "path";
|
|
35964
|
-
|
|
35965
35465
|
// ../../packages/detections/src/egress/registry.ts
|
|
35966
35466
|
var EXTRACTOR_VERSION = "3";
|
|
35967
35467
|
var PROVIDER_REGISTRY = [
|
|
@@ -36725,12 +36225,12 @@ var RegexMatcher2 = class {
|
|
|
36725
36225
|
rule.matcher,
|
|
36726
36226
|
() => new RegExp(pattern, flags.includes("d") ? flags : `${flags}d`)
|
|
36727
36227
|
);
|
|
36728
|
-
const
|
|
36228
|
+
const scanText = text.length > MAX_REGEX_INPUT_LENGTH ? text.slice(0, MAX_REGEX_INPUT_LENGTH) : text;
|
|
36729
36229
|
const spans = [];
|
|
36730
36230
|
let m;
|
|
36731
|
-
const maxIterations =
|
|
36231
|
+
const maxIterations = scanText.length + 1;
|
|
36732
36232
|
let iterations = 0;
|
|
36733
|
-
while ((m = re.exec(
|
|
36233
|
+
while ((m = re.exec(scanText)) !== null) {
|
|
36734
36234
|
if (++iterations > maxIterations) break;
|
|
36735
36235
|
const group = captureGroup != null ? m[captureGroup] : m[0];
|
|
36736
36236
|
if (m[0].length === 0) re.lastIndex++;
|
|
@@ -37072,17 +36572,18 @@ function ruleEvidence(rule) {
|
|
|
37072
36572
|
|
|
37073
36573
|
// ../../packages/detections/src/mask.ts
|
|
37074
36574
|
function maskMatch(raw) {
|
|
37075
|
-
|
|
37076
|
-
|
|
37077
|
-
|
|
37078
|
-
|
|
36575
|
+
const visible = stripInvisiblePadding(raw);
|
|
36576
|
+
if (visible.length <= 5) return "***";
|
|
36577
|
+
const atIndex = visible.indexOf("@");
|
|
36578
|
+
if (atIndex > 0 && atIndex < visible.length - 1) {
|
|
36579
|
+
const domain2 = visible.slice(atIndex + 1);
|
|
37079
36580
|
if (domain2.includes(".")) {
|
|
37080
|
-
const local =
|
|
36581
|
+
const local = visible.slice(0, atIndex);
|
|
37081
36582
|
const maskedLocal = local.length <= 1 ? local : local.charAt(0) + "*".repeat(local.length - 1);
|
|
37082
36583
|
return `${maskedLocal}@${domain2}`;
|
|
37083
36584
|
}
|
|
37084
36585
|
}
|
|
37085
|
-
return `${
|
|
36586
|
+
return `${visible.charAt(0)}${"*".repeat(6)}${visible.charAt(visible.length - 1)}`;
|
|
37086
36587
|
}
|
|
37087
36588
|
|
|
37088
36589
|
// ../../packages/detections/src/pointer-shield.ts
|
|
@@ -37344,7 +36845,12 @@ var MIN_RAW_LEN = 4;
|
|
|
37344
36845
|
var RAW_RUN_LEN = 8;
|
|
37345
36846
|
function carriesRawRun(text, rawValues) {
|
|
37346
36847
|
let windows = null;
|
|
37347
|
-
|
|
36848
|
+
const values = /* @__PURE__ */ new Set();
|
|
36849
|
+
for (const raw of rawValues) {
|
|
36850
|
+
values.add(raw);
|
|
36851
|
+
values.add(stripInvisiblePadding(raw));
|
|
36852
|
+
}
|
|
36853
|
+
for (const raw of values) {
|
|
37348
36854
|
if (raw.length < MIN_RAW_LEN) continue;
|
|
37349
36855
|
if (raw.length < RAW_RUN_LEN) {
|
|
37350
36856
|
if (text.includes(raw)) return true;
|
|
@@ -37368,11 +36874,16 @@ function carriesRawRun(text, rawValues) {
|
|
|
37368
36874
|
return false;
|
|
37369
36875
|
}
|
|
37370
36876
|
function safeMaskedMatch(rawMatch) {
|
|
37371
|
-
const
|
|
37372
|
-
|
|
37373
|
-
|
|
36877
|
+
const visible = stripInvisiblePadding(rawMatch);
|
|
36878
|
+
const masked = maskMatch(visible);
|
|
36879
|
+
const reveals = (preview) => preview === visible || visible.length >= MIN_RAW_LEN && preview.includes(visible);
|
|
36880
|
+
if (!reveals(masked)) return masked;
|
|
36881
|
+
const atIndex = masked.indexOf("@");
|
|
36882
|
+
if (atIndex > 0 && atIndex < masked.length - 1) {
|
|
36883
|
+
const emailFallback = `*${masked.slice(atIndex)}`;
|
|
36884
|
+
if (!reveals(emailFallback)) return emailFallback;
|
|
37374
36885
|
}
|
|
37375
|
-
return
|
|
36886
|
+
return "***";
|
|
37376
36887
|
}
|
|
37377
36888
|
function assertRawFree(text, rawValues) {
|
|
37378
36889
|
if (carriesRawRun(text, rawValues)) {
|
|
@@ -39814,6 +39325,11 @@ function bundledDetections() {
|
|
|
39814
39325
|
}));
|
|
39815
39326
|
return cachedDetections;
|
|
39816
39327
|
}
|
|
39328
|
+
function shippedRegexMatchers() {
|
|
39329
|
+
return bundledDetections().flatMap((pack) => pack.rules).flatMap(
|
|
39330
|
+
(rule) => rule.matcher.type === "regex" ? [{ pattern: rule.matcher.pattern, flags: rule.matcher.flags }] : []
|
|
39331
|
+
);
|
|
39332
|
+
}
|
|
39817
39333
|
|
|
39818
39334
|
// ../../packages/plugin-sdk/src/mask.ts
|
|
39819
39335
|
var packsReady = false;
|
|
@@ -39835,8 +39351,8 @@ function bundledMaskingRules() {
|
|
|
39835
39351
|
}
|
|
39836
39352
|
|
|
39837
39353
|
// ../../packages/plugin-sdk/src/repo.ts
|
|
39838
|
-
import { existsSync as existsSync9, readFileSync as
|
|
39839
|
-
import { basename as basename2, dirname as dirname4, isAbsolute, join as
|
|
39354
|
+
import { existsSync as existsSync9, readFileSync as readFileSync11, statSync as statSync6 } from "fs";
|
|
39355
|
+
import { basename as basename2, dirname as dirname4, isAbsolute, join as join18, sep as sep2 } from "path";
|
|
39840
39356
|
function resolveRepo(cwd) {
|
|
39841
39357
|
try {
|
|
39842
39358
|
const location = locateRepo(cwd);
|
|
@@ -39856,36 +39372,36 @@ function resolveWorktreeRoot(cwd) {
|
|
|
39856
39372
|
function findGitRoot(start) {
|
|
39857
39373
|
let dir = start;
|
|
39858
39374
|
for (; ; ) {
|
|
39859
|
-
if (existsSync9(
|
|
39375
|
+
if (existsSync9(join18(dir, ".git"))) return dir;
|
|
39860
39376
|
const parent = dirname4(dir);
|
|
39861
39377
|
if (parent === dir) return void 0;
|
|
39862
39378
|
dir = parent;
|
|
39863
39379
|
}
|
|
39864
39380
|
}
|
|
39865
39381
|
function resolveGitContext(root) {
|
|
39866
|
-
const dotGit =
|
|
39382
|
+
const dotGit = join18(root, ".git");
|
|
39867
39383
|
try {
|
|
39868
39384
|
if (statSync6(dotGit).isDirectory()) {
|
|
39869
|
-
return { configPath:
|
|
39385
|
+
return { configPath: join18(dotGit, "config"), headRoot: root };
|
|
39870
39386
|
}
|
|
39871
39387
|
} catch {
|
|
39872
39388
|
return void 0;
|
|
39873
39389
|
}
|
|
39874
39390
|
const target = /^gitdir:\s*(.+?)\s*$/m.exec(safeRead(dotGit) ?? "")?.[1];
|
|
39875
39391
|
if (!target) return void 0;
|
|
39876
|
-
const gitdir = isAbsolute(target) ? target :
|
|
39877
|
-
if (existsSync9(
|
|
39878
|
-
return { configPath:
|
|
39392
|
+
const gitdir = isAbsolute(target) ? target : join18(root, target);
|
|
39393
|
+
if (existsSync9(join18(gitdir, "config"))) {
|
|
39394
|
+
return { configPath: join18(gitdir, "config"), headRoot: root };
|
|
39879
39395
|
}
|
|
39880
|
-
const commonRaw = safeRead(
|
|
39396
|
+
const commonRaw = safeRead(join18(gitdir, "commondir"))?.trim();
|
|
39881
39397
|
if (!commonRaw) return void 0;
|
|
39882
|
-
const commonGitDir = isAbsolute(commonRaw) ? commonRaw :
|
|
39398
|
+
const commonGitDir = isAbsolute(commonRaw) ? commonRaw : join18(gitdir, commonRaw);
|
|
39883
39399
|
const headRoot = basename2(commonGitDir) === ".git" ? dirname4(commonGitDir) : root;
|
|
39884
|
-
return { configPath:
|
|
39400
|
+
return { configPath: join18(commonGitDir, "config"), headRoot };
|
|
39885
39401
|
}
|
|
39886
39402
|
function safeRead(path) {
|
|
39887
39403
|
try {
|
|
39888
|
-
return
|
|
39404
|
+
return readFileSync11(path, "utf8");
|
|
39889
39405
|
} catch {
|
|
39890
39406
|
return void 0;
|
|
39891
39407
|
}
|
|
@@ -39932,9 +39448,9 @@ function slugFromUrl(url2) {
|
|
|
39932
39448
|
}
|
|
39933
39449
|
|
|
39934
39450
|
// ../../packages/plugin-sdk/src/events.ts
|
|
39935
|
-
import { createHash as
|
|
39451
|
+
import { createHash as createHash6, randomUUID as randomUUID13 } from "crypto";
|
|
39936
39452
|
function contentHashOf(text) {
|
|
39937
|
-
return
|
|
39453
|
+
return createHash6("sha256").update(text).digest("hex");
|
|
39938
39454
|
}
|
|
39939
39455
|
function buildIngestEvent(input2) {
|
|
39940
39456
|
const contentHash = input2.contentHash ?? contentHashOf(input2.content);
|
|
@@ -40447,71 +39963,6 @@ function createGuardedScanner(partition, gateway, opts) {
|
|
|
40447
39963
|
};
|
|
40448
39964
|
}
|
|
40449
39965
|
|
|
40450
|
-
// ../../packages/plugin-sdk/src/hook-fail-opens.ts
|
|
40451
|
-
import { readFileSync as readFileSync12 } from "fs";
|
|
40452
|
-
import { join as join19 } from "path";
|
|
40453
|
-
|
|
40454
|
-
// ../../packages/plugin-sdk/src/host-floor.ts
|
|
40455
|
-
import { readFileSync as readFileSync14 } from "fs";
|
|
40456
|
-
import { join as join21 } from "path";
|
|
40457
|
-
|
|
40458
|
-
// ../../packages/plugin-sdk/src/model-governance.ts
|
|
40459
|
-
import {
|
|
40460
|
-
closeSync as closeSync2,
|
|
40461
|
-
fstatSync,
|
|
40462
|
-
mkdirSync as mkdirSync2,
|
|
40463
|
-
openSync as openSync2,
|
|
40464
|
-
readFileSync as readFileSync13,
|
|
40465
|
-
readSync,
|
|
40466
|
-
writeFileSync as writeFileSync5
|
|
40467
|
-
} from "fs";
|
|
40468
|
-
import { join as join20 } from "path";
|
|
40469
|
-
var TAIL_BYTES = 256 * 1024;
|
|
40470
|
-
|
|
40471
|
-
// ../../packages/plugin-sdk/src/host-floor.ts
|
|
40472
|
-
var HOST_FEATURE = {
|
|
40473
|
-
ModelSwitch: "model-switch",
|
|
40474
|
-
VaultPointerDisplay: "vault-pointer-display"
|
|
40475
|
-
};
|
|
40476
|
-
var HOST_FLOORS = {
|
|
40477
|
-
[HOST_FEATURE.ModelSwitch]: {
|
|
40478
|
-
label: "model-switch protection",
|
|
40479
|
-
hookEvents: ["PreModelSwitch", "PostModelSwitch"],
|
|
40480
|
-
since: "2.1.251"
|
|
40481
|
-
},
|
|
40482
|
-
[HOST_FEATURE.VaultPointerDisplay]: {
|
|
40483
|
-
label: "vault pointer display",
|
|
40484
|
-
hookEvents: ["MessageDisplay"],
|
|
40485
|
-
since: "2.1.152"
|
|
40486
|
-
}
|
|
40487
|
-
};
|
|
40488
|
-
var ANTIGRAVITY_HOST_FEATURE = {
|
|
40489
|
-
EndOfTurnCapture: "end-of-turn-capture"
|
|
40490
|
-
};
|
|
40491
|
-
var ANTIGRAVITY_HOST_FLOORS = {
|
|
40492
|
-
[ANTIGRAVITY_HOST_FEATURE.EndOfTurnCapture]: {
|
|
40493
|
-
label: "end-of-turn history capture",
|
|
40494
|
-
hookEvents: ["Stop"],
|
|
40495
|
-
since: "1.1.10"
|
|
40496
|
-
}
|
|
40497
|
-
};
|
|
40498
|
-
|
|
40499
|
-
// ../../packages/plugin-sdk/src/ignore-layers.ts
|
|
40500
|
-
var import_ignore = __toESM(require_ignore(), 1);
|
|
40501
|
-
import { readFileSync as readFileSync15 } from "fs";
|
|
40502
|
-
import { join as join22 } from "path";
|
|
40503
|
-
|
|
40504
|
-
// ../../packages/plugin-sdk/src/inventory-resolver.ts
|
|
40505
|
-
import { arch, hostname as hostname4, platform, release } from "os";
|
|
40506
|
-
|
|
40507
|
-
// ../../packages/plugin-sdk/src/nudge.ts
|
|
40508
|
-
import { mkdirSync as mkdirSync3, readFileSync as readFileSync16, writeFileSync as writeFileSync6 } from "fs";
|
|
40509
|
-
import { join as join23 } from "path";
|
|
40510
|
-
|
|
40511
|
-
// ../../packages/plugin-sdk/src/paths.ts
|
|
40512
|
-
import { readdirSync as readdirSync3, realpathSync as realpathSync3 } from "fs";
|
|
40513
|
-
import { basename as basename4, dirname as dirname5, sep as sep3 } from "path";
|
|
40514
|
-
|
|
40515
39966
|
// ../../packages/plugin-sdk/src/policy-resolver.ts
|
|
40516
39967
|
import { randomUUID as randomUUID14 } from "crypto";
|
|
40517
39968
|
function createPolicyResolver(bundle) {
|
|
@@ -40569,36 +40020,6 @@ function applyCategoryPosture(posture, repo, mode = "fill-gaps") {
|
|
|
40569
40020
|
}
|
|
40570
40021
|
}
|
|
40571
40022
|
|
|
40572
|
-
// ../../packages/plugin-sdk/src/project-files.ts
|
|
40573
|
-
import { existsSync as existsSync11, readdirSync as readdirSync4 } from "fs";
|
|
40574
|
-
import { basename as basename5, join as join24 } from "path";
|
|
40575
|
-
|
|
40576
|
-
// ../../packages/plugin-sdk/src/provider-env-antigravity.ts
|
|
40577
|
-
var optionalBaseUrl2 = external_exports.preprocess((v) => {
|
|
40578
|
-
if (typeof v === "string" && v.trim() === "") return void 0;
|
|
40579
|
-
return v;
|
|
40580
|
-
}, external_exports.string().optional()).catch(void 0);
|
|
40581
|
-
var optionalFlag = external_exports.preprocess((v) => {
|
|
40582
|
-
if (typeof v !== "string") return false;
|
|
40583
|
-
const normalized = v.trim().toLowerCase();
|
|
40584
|
-
return normalized !== "" && normalized !== "0" && normalized !== "false";
|
|
40585
|
-
}, external_exports.boolean()).catch(false);
|
|
40586
|
-
var antigravityProviderEnvShape = {
|
|
40587
|
-
GOOGLE_GENAI_USE_VERTEXAI: optionalFlag,
|
|
40588
|
-
GOOGLE_GEMINI_BASE_URL: optionalBaseUrl2
|
|
40589
|
-
};
|
|
40590
|
-
var AntigravityProviderEnvSchema = external_exports.object(antigravityProviderEnvShape);
|
|
40591
|
-
|
|
40592
|
-
// ../../packages/plugin-sdk/src/provider-env-codex.ts
|
|
40593
|
-
var optionalBaseUrl3 = external_exports.preprocess((v) => {
|
|
40594
|
-
if (typeof v === "string" && v.trim() === "") return void 0;
|
|
40595
|
-
return v;
|
|
40596
|
-
}, external_exports.string().optional()).catch(void 0);
|
|
40597
|
-
var codexProviderEnvShape = {
|
|
40598
|
-
OPENAI_BASE_URL: optionalBaseUrl3
|
|
40599
|
-
};
|
|
40600
|
-
var CodexProviderEnvSchema = external_exports.object(codexProviderEnvShape);
|
|
40601
|
-
|
|
40602
40023
|
// ../../packages/plugin-sdk/src/runtime.ts
|
|
40603
40024
|
import { randomUUID as randomUUID15 } from "crypto";
|
|
40604
40025
|
var ENFORCEMENT_CEILING_ENABLED = false;
|
|
@@ -40885,12 +40306,11 @@ function createPluginRuntime(gateway, settings, opts) {
|
|
|
40885
40306
|
async function processText(text, context, opts2 = {}) {
|
|
40886
40307
|
return (await evaluate(text, context, {}, opts2.rewritable)).decision;
|
|
40887
40308
|
}
|
|
40888
|
-
async function
|
|
40309
|
+
async function evaluateCapture(input2, opts2) {
|
|
40889
40310
|
const timingStartedAt = input2.occurredAt === void 0 ? startTiming() : void 0;
|
|
40890
|
-
const filePath = input2.metadata?.filePath;
|
|
40891
40311
|
const { decision, excepted, exceptionIds } = await evaluate(
|
|
40892
40312
|
input2.text,
|
|
40893
|
-
{ filePath, eventKind: input2.kind },
|
|
40313
|
+
{ filePath: input2.metadata?.filePath, eventKind: input2.kind },
|
|
40894
40314
|
{
|
|
40895
40315
|
sourceTool: input2.sourceTool,
|
|
40896
40316
|
metadata: input2.metadata,
|
|
@@ -40898,7 +40318,11 @@ function createPluginRuntime(gateway, settings, opts) {
|
|
|
40898
40318
|
},
|
|
40899
40319
|
opts2.rewritable
|
|
40900
40320
|
);
|
|
40901
|
-
|
|
40321
|
+
return { decision, excepted, exceptionIds, timingStartedAt };
|
|
40322
|
+
}
|
|
40323
|
+
async function persistCapture(input2, opts2, { decision, excepted, exceptionIds, timingStartedAt }) {
|
|
40324
|
+
const filePath = input2.metadata?.filePath;
|
|
40325
|
+
if (opts2.persist === "with-findings" && decision.findings.length === 0) return;
|
|
40902
40326
|
try {
|
|
40903
40327
|
const contentHash = contentHashOf(input2.text);
|
|
40904
40328
|
const maskedFindings = decision.findings.filter(
|
|
@@ -40941,6 +40365,8 @@ function createPluginRuntime(gateway, settings, opts) {
|
|
|
40941
40365
|
// exceptions/blocked_detections when a key is available;
|
|
40942
40366
|
// falls back to the masked match so at-rest findings still get
|
|
40943
40367
|
// a stable (if weaker) identity on a workspace with no dataDir.
|
|
40368
|
+
// Both ignore the same invisible padding, so a clean and a
|
|
40369
|
+
// padded occurrence of one secret key alike on either path.
|
|
40944
40370
|
valueFingerprint: findingKeyFingerprintKey ? fingerprintOf(findingKeyFingerprintKey, match, findingKeyFpCache) : maskedMatch
|
|
40945
40371
|
}) : void 0;
|
|
40946
40372
|
return {
|
|
@@ -40968,7 +40394,37 @@ function createPluginRuntime(gateway, settings, opts) {
|
|
|
40968
40394
|
}
|
|
40969
40395
|
} catch {
|
|
40970
40396
|
}
|
|
40971
|
-
|
|
40397
|
+
}
|
|
40398
|
+
async function enforcedIn(text, context) {
|
|
40399
|
+
try {
|
|
40400
|
+
await ensureInitialized();
|
|
40401
|
+
if (!scanner) return [];
|
|
40402
|
+
const shielded = shieldPointers(text);
|
|
40403
|
+
const matched = await scanner.scan(shielded.text, context);
|
|
40404
|
+
return dropShieldedFindings(matched, shielded.spans).filter((finding) => {
|
|
40405
|
+
const action = resolveAction(finding.ruleId, finding.category);
|
|
40406
|
+
return action === "block" || action === "redact";
|
|
40407
|
+
});
|
|
40408
|
+
} catch {
|
|
40409
|
+
return [];
|
|
40410
|
+
}
|
|
40411
|
+
}
|
|
40412
|
+
async function capture(input2, opts2 = {}) {
|
|
40413
|
+
const evaluated = await evaluateCapture(input2, opts2);
|
|
40414
|
+
await persistCapture(input2, opts2, evaluated);
|
|
40415
|
+
return evaluated.decision;
|
|
40416
|
+
}
|
|
40417
|
+
async function captureDeferred(input2, opts2 = {}) {
|
|
40418
|
+
const evaluated = await evaluateCapture(input2, opts2);
|
|
40419
|
+
let recorded = false;
|
|
40420
|
+
return {
|
|
40421
|
+
result: evaluated.decision,
|
|
40422
|
+
record: async () => {
|
|
40423
|
+
if (recorded) return;
|
|
40424
|
+
recorded = true;
|
|
40425
|
+
await persistCapture(input2, opts2, evaluated);
|
|
40426
|
+
}
|
|
40427
|
+
};
|
|
40972
40428
|
}
|
|
40973
40429
|
async function rulesetFingerprint() {
|
|
40974
40430
|
try {
|
|
@@ -40989,20 +40445,17 @@ function createPluginRuntime(gateway, settings, opts) {
|
|
|
40989
40445
|
}
|
|
40990
40446
|
await gateway.close();
|
|
40991
40447
|
}
|
|
40992
|
-
return {
|
|
40448
|
+
return {
|
|
40449
|
+
processText,
|
|
40450
|
+
capture,
|
|
40451
|
+
captureDeferred,
|
|
40452
|
+
enforcedIn,
|
|
40453
|
+
rulesetFingerprint,
|
|
40454
|
+
scanIsolationDegraded,
|
|
40455
|
+
close
|
|
40456
|
+
};
|
|
40993
40457
|
}
|
|
40994
40458
|
|
|
40995
|
-
// ../../packages/plugin-sdk/src/scope-key.ts
|
|
40996
|
-
import { existsSync as existsSync12 } from "fs";
|
|
40997
|
-
import { dirname as dirname6, isAbsolute as isAbsolute2, join as join25, normalize } from "path";
|
|
40998
|
-
|
|
40999
|
-
// ../../packages/plugin-sdk/src/suppressions.ts
|
|
41000
|
-
var THIRTY_DAYS_MS = 30 * 24 * 60 * 60 * 1e3;
|
|
41001
|
-
|
|
41002
|
-
// ../../packages/plugin-sdk/src/throttle.ts
|
|
41003
|
-
import { mkdirSync as mkdirSync4, statSync as statSync8, writeFileSync as writeFileSync7 } from "fs";
|
|
41004
|
-
import { join as join26 } from "path";
|
|
41005
|
-
|
|
41006
40459
|
// ../../packages/setup-wizard/src/remediation/chain.ts
|
|
41007
40460
|
var REMEDIATION_OPTIONS = [
|
|
41008
40461
|
{ id: "redact-rotation-checklist", label: "Redact + rotation checklist" },
|
|
@@ -41043,8 +40496,8 @@ function routeRemediationOption(option, handlers) {
|
|
|
41043
40496
|
}
|
|
41044
40497
|
|
|
41045
40498
|
// ../../packages/setup-wizard/src/remediation/rotation-checklist.ts
|
|
41046
|
-
import { writeFileSync as
|
|
41047
|
-
import { join as
|
|
40499
|
+
import { writeFileSync as writeFileSync5 } from "fs";
|
|
40500
|
+
import { join as join19 } from "path";
|
|
41048
40501
|
var GENERIC_CONSOLE_PATH = "rotate via the provider's own console";
|
|
41049
40502
|
var CONSOLE_PATHS = {
|
|
41050
40503
|
anthropic: "console.anthropic.com \u2192 Settings \u2192 API keys",
|
|
@@ -41129,7 +40582,7 @@ function renderRotationChecklistResolvedLine(location) {
|
|
|
41129
40582
|
return `\u2713 I drafted a rotation checklist for you (${location}).`;
|
|
41130
40583
|
}
|
|
41131
40584
|
function writeRotationChecklist(entries, targetDirectory) {
|
|
41132
|
-
|
|
40585
|
+
writeFileSync5(
|
|
41133
40586
|
`${targetDirectory}/rotation-checklist.md`,
|
|
41134
40587
|
renderChecklistMarkdown(entries),
|
|
41135
40588
|
"utf8"
|
|
@@ -41144,7 +40597,7 @@ function generateRotationChecklist(input2) {
|
|
|
41144
40597
|
try {
|
|
41145
40598
|
const target = resolveRotationChecklistTarget(input2.cwd);
|
|
41146
40599
|
targetDirectory = target.directory;
|
|
41147
|
-
const filePath =
|
|
40600
|
+
const filePath = join19(target.directory, "rotation-checklist.md");
|
|
41148
40601
|
writeRotationChecklist(input2.entries, target.directory);
|
|
41149
40602
|
return {
|
|
41150
40603
|
status: "written",
|
|
@@ -41255,9 +40708,9 @@ var RANK = Object.fromEntries(
|
|
|
41255
40708
|
);
|
|
41256
40709
|
|
|
41257
40710
|
// ../../packages/setup-wizard/src/triage/plan-file.ts
|
|
41258
|
-
import { mkdtempSync, readFileSync as
|
|
40711
|
+
import { mkdtempSync, readFileSync as readFileSync12, rmdirSync, rmSync as rmSync7, writeFileSync as writeFileSync6 } from "fs";
|
|
41259
40712
|
import { tmpdir } from "os";
|
|
41260
|
-
import { basename as
|
|
40713
|
+
import { basename as basename3, dirname as dirname5, join as join20 } from "path";
|
|
41261
40714
|
var SuppressionEntrySchema = external_exports.object({
|
|
41262
40715
|
ruleId: external_exports.string(),
|
|
41263
40716
|
category: DetectionCategory,
|
|
@@ -41375,8 +40828,8 @@ function table(headers, rows, opts = {}) {
|
|
|
41375
40828
|
const widths = headers.map(
|
|
41376
40829
|
(h, i) => Math.max(visibleLength(h), ...rows.map((r) => visibleLength(r[i] ?? "")))
|
|
41377
40830
|
);
|
|
41378
|
-
const
|
|
41379
|
-
const fmt = (cells) => cells.map((cell, i) => padEnd(cell, widths[i] ?? 0)).join(
|
|
40831
|
+
const sep3 = " ".repeat(gap);
|
|
40832
|
+
const fmt = (cells) => cells.map((cell, i) => padEnd(cell, widths[i] ?? 0)).join(sep3);
|
|
41380
40833
|
const headerLine = fmt(headers.map((h) => h.toUpperCase()));
|
|
41381
40834
|
if (opts.rowSep === true) {
|
|
41382
40835
|
const fullWidth = widths.reduce((n, w) => n + w, 0) + gap * Math.max(0, widths.length - 1);
|
|
@@ -41388,7 +40841,7 @@ function table(headers, rows, opts = {}) {
|
|
|
41388
40841
|
});
|
|
41389
40842
|
return [headerLine, rule, ...body].join("\n");
|
|
41390
40843
|
}
|
|
41391
|
-
const ruleLine = widths.map((w) => "\u2500".repeat(w)).join(
|
|
40844
|
+
const ruleLine = widths.map((w) => "\u2500".repeat(w)).join(sep3);
|
|
41392
40845
|
return [headerLine, ruleLine, ...rows.map(fmt)].join("\n");
|
|
41393
40846
|
}
|
|
41394
40847
|
function fenced(body) {
|
|
@@ -41401,8 +40854,8 @@ function show(body) {
|
|
|
41401
40854
|
}
|
|
41402
40855
|
|
|
41403
40856
|
// src/skills-registry.ts
|
|
41404
|
-
import { readdirSync as
|
|
41405
|
-
import { join as
|
|
40857
|
+
import { readdirSync as readdirSync2, readFileSync as readFileSync13 } from "fs";
|
|
40858
|
+
import { join as join21 } from "path";
|
|
41406
40859
|
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
41407
40860
|
var SKILLS_DIR = fileURLToPath2(new URL("../skills", import.meta.url));
|
|
41408
40861
|
function frontmatterName(content) {
|
|
@@ -41412,10 +40865,10 @@ function frontmatterName(content) {
|
|
|
41412
40865
|
return name?.[1];
|
|
41413
40866
|
}
|
|
41414
40867
|
function readRegisteredSkills() {
|
|
41415
|
-
return
|
|
40868
|
+
return readdirSync2(SKILLS_DIR, { withFileTypes: true }).filter((entry) => entry.isDirectory()).flatMap((entry) => {
|
|
41416
40869
|
let content;
|
|
41417
40870
|
try {
|
|
41418
|
-
content =
|
|
40871
|
+
content = readFileSync13(join21(SKILLS_DIR, entry.name, "SKILL.md"), "utf8");
|
|
41419
40872
|
} catch {
|
|
41420
40873
|
return [];
|
|
41421
40874
|
}
|
|
@@ -41476,7 +40929,7 @@ function renderRemediationDecision(findings, moreCount, registry2) {
|
|
|
41476
40929
|
}
|
|
41477
40930
|
|
|
41478
40931
|
// src/remediation/surfaced-redact.ts
|
|
41479
|
-
import { readFileSync as
|
|
40932
|
+
import { readFileSync as readFileSync20 } from "fs";
|
|
41480
40933
|
|
|
41481
40934
|
// ../../packages/remote/src/http.ts
|
|
41482
40935
|
import { request as httpRequest } from "http";
|
|
@@ -41854,11 +41307,11 @@ function withTimeout(promise2, ms) {
|
|
|
41854
41307
|
}
|
|
41855
41308
|
|
|
41856
41309
|
// ../../packages/plugin-runtime/src/attached/forward-drops.ts
|
|
41857
|
-
import { readFileSync as
|
|
41858
|
-
import { join as
|
|
41310
|
+
import { readFileSync as readFileSync14 } from "fs";
|
|
41311
|
+
import { join as join22 } from "path";
|
|
41859
41312
|
var FORWARD_DROPS_FILENAME = ATTACHED_FORWARD_DROPS_FILENAME;
|
|
41860
41313
|
function forwardDropsPath(dataDir2) {
|
|
41861
|
-
return
|
|
41314
|
+
return join22(dataDir2, FORWARD_DROPS_FILENAME);
|
|
41862
41315
|
}
|
|
41863
41316
|
function recordForwardDrops(dataDir2, count, nowMs) {
|
|
41864
41317
|
if (count <= 0) return;
|
|
@@ -41876,7 +41329,7 @@ function recordForwardDrops(dataDir2, count, nowMs) {
|
|
|
41876
41329
|
}
|
|
41877
41330
|
function readForwardDrops(dataDir2) {
|
|
41878
41331
|
try {
|
|
41879
|
-
const parsed2 = JSON.parse(
|
|
41332
|
+
const parsed2 = JSON.parse(readFileSync14(forwardDropsPath(dataDir2), "utf8"));
|
|
41880
41333
|
if (typeof parsed2 !== "object" || parsed2 === null) return null;
|
|
41881
41334
|
const record2 = parsed2;
|
|
41882
41335
|
if (typeof record2.droppedForwards !== "number" || !Number.isFinite(record2.droppedForwards)) {
|
|
@@ -41895,7 +41348,7 @@ function readForwardDrops(dataDir2) {
|
|
|
41895
41348
|
// ../../packages/plugin-runtime/src/attached/forward-policy.ts
|
|
41896
41349
|
import { randomUUID as randomUUID16 } from "crypto";
|
|
41897
41350
|
import { readFile, rename, writeFile } from "fs/promises";
|
|
41898
|
-
import { join as
|
|
41351
|
+
import { join as join23 } from "path";
|
|
41899
41352
|
function isInvalidRequest(err) {
|
|
41900
41353
|
return typeof err === "object" && err !== null && err.name === "RemoteRequestInvalid";
|
|
41901
41354
|
}
|
|
@@ -41914,7 +41367,7 @@ var FORWARD_STATE_FILENAME = ATTACHED_FORWARD_STATE_FILENAME;
|
|
|
41914
41367
|
var STATE_FILENAME = FORWARD_STATE_FILENAME;
|
|
41915
41368
|
function createForwardPolicy(deps) {
|
|
41916
41369
|
const now = deps.now ?? (() => Date.now());
|
|
41917
|
-
const file2 =
|
|
41370
|
+
const file2 = join23(deps.dir, STATE_FILENAME);
|
|
41918
41371
|
let state = null;
|
|
41919
41372
|
let loading = null;
|
|
41920
41373
|
async function readState() {
|
|
@@ -42080,6 +41533,9 @@ var AttachedDataGateway = class {
|
|
|
42080
41533
|
*
|
|
42081
41534
|
* Machine mode answers before any key is read, so a machine attachment pays
|
|
42082
41535
|
* nothing for scoping and forwards exactly what it always has.
|
|
41536
|
+
*
|
|
41537
|
+
* `governanceAppliesTo` answers from this same verdict, so it agrees with
|
|
41538
|
+
* forwarding key for key.
|
|
42083
41539
|
*/
|
|
42084
41540
|
verdictFor(keyOf) {
|
|
42085
41541
|
try {
|
|
@@ -42096,24 +41552,27 @@ var AttachedDataGateway = class {
|
|
|
42096
41552
|
* the key its row holds in the local store, recorded per root (see
|
|
42097
41553
|
* `rootVerdict`), not the key on the root event just handed in: roots are
|
|
42098
41554
|
* first-write-wins in the store, so when two producers record a root for one
|
|
42099
|
-
* session (the session-start hook, then a reconcile pass) the second leaves
|
|
42100
|
-
*
|
|
42101
|
-
*
|
|
42102
|
-
*
|
|
42103
|
-
*
|
|
42104
|
-
*
|
|
42105
|
-
*
|
|
42106
|
-
*
|
|
42107
|
-
*
|
|
42108
|
-
*
|
|
42109
|
-
*
|
|
42110
|
-
*
|
|
42111
|
-
*
|
|
42112
|
-
*
|
|
42113
|
-
*
|
|
42114
|
-
*
|
|
42115
|
-
*
|
|
42116
|
-
*
|
|
41555
|
+
* session (the session-start hook, then a reconcile pass) the second leaves the
|
|
41556
|
+
* stored row as it was. That stored row, not this event, is what a history
|
|
41557
|
+
* drain pass would decide, if the root started before the attach; the drain
|
|
41558
|
+
* never offers one that started after it (`started_at < backlogBefore`).
|
|
41559
|
+
* Whether this root EVENT is itself sent takes both keys: the stored one AND
|
|
41560
|
+
* its own. The event's attributes (cwd, project, repo) describe where it was
|
|
41561
|
+
* recorded from, so a root event keyed to a personal directory is never sent
|
|
41562
|
+
* under an enrolled stored root, though the enrolled leaves still forward under
|
|
41563
|
+
* it: the instance that wrote the stored root is expected to have forwarded it.
|
|
41564
|
+
* If it did not (the root was written while standalone or under another
|
|
41565
|
+
* attachment, or its forward failed), the plane refuses those leaves. A root
|
|
41566
|
+
* that started before the attach is shipped, ahead of its leaves, by the
|
|
41567
|
+
* history drain; one that started after it is never offered by the drain. Any
|
|
41568
|
+
* other row with a root reference (`rootSessionId`, else `parentId`) forwards
|
|
41569
|
+
* only when its own key is in scope AND this instance recorded an in-scope
|
|
41570
|
+
* verdict for that root. The audit-event route has real foreign keys on both
|
|
41571
|
+
* columns and stubs no missing root, so a leaf sent after its root was kept
|
|
41572
|
+
* local is refused there, and a refused forward counts toward the breaker that
|
|
41573
|
+
* guards every other one. A root this instance never recorded is therefore
|
|
41574
|
+
* `'local'`: the only answer that cannot orphan a row. A row with no root
|
|
41575
|
+
* reference at all has nothing to orphan, and is decided by its own key.
|
|
42117
41576
|
*
|
|
42118
41577
|
* What this costs is stated rather than discovered. A session whose stored
|
|
42119
41578
|
* root is not keyed to an enrolled repository keeps its token and tool
|
|
@@ -42184,6 +41643,87 @@ var AttachedDataGateway = class {
|
|
|
42184
41643
|
return [];
|
|
42185
41644
|
}
|
|
42186
41645
|
}
|
|
41646
|
+
/**
|
|
41647
|
+
* The verdict for the repositories nested in a scanned project, answered
|
|
41648
|
+
* TOTALLY: `'forward'` or `'local'`, never a throw.
|
|
41649
|
+
*
|
|
41650
|
+
* A walk descends into a nested clone or submodule and folds its files into
|
|
41651
|
+
* the project it is walking, so one register can carry several
|
|
41652
|
+
* repositories' call sites under one project key. Each of them must be in
|
|
41653
|
+
* scope for it to forward. One key out of scope, or a nested repository with
|
|
41654
|
+
* no remote (an `undefined` key), keeps the whole register local.
|
|
41655
|
+
*
|
|
41656
|
+
* An ABSENT list is `'local'` too. Only the code that walked the tree can say
|
|
41657
|
+
* what is nested in it, and every scan passes the list, empty when nothing
|
|
41658
|
+
* is nested. A register nobody vouched for is not one a scoped attachment
|
|
41659
|
+
* may send.
|
|
41660
|
+
*
|
|
41661
|
+
* Machine mode answers before reading the context, so a machine attachment
|
|
41662
|
+
* forwards exactly what it always has.
|
|
41663
|
+
*/
|
|
41664
|
+
nestedVerdict(context) {
|
|
41665
|
+
try {
|
|
41666
|
+
if (this.deps.attachment.mode === "machine") return "forward";
|
|
41667
|
+
const keys = context?.nestedScopeKeys;
|
|
41668
|
+
if (keys === void 0) return "local";
|
|
41669
|
+
for (const key of keys) {
|
|
41670
|
+
if (this.verdictFor(() => key) === "local") return "local";
|
|
41671
|
+
}
|
|
41672
|
+
return "forward";
|
|
41673
|
+
} catch {
|
|
41674
|
+
return "local";
|
|
41675
|
+
}
|
|
41676
|
+
}
|
|
41677
|
+
/**
|
|
41678
|
+
* The register a scoped attachment sends, once the project and the repositories
|
|
41679
|
+
* nested in it are in scope: the register itself, with `reconcile.deletedFiles`
|
|
41680
|
+
* cut to the deleted paths whose own repository is in scope. `undefined` sends
|
|
41681
|
+
* nothing. TOTAL, like `verdictFor`, and for its reasons.
|
|
41682
|
+
*
|
|
41683
|
+
* The deletion sweep takes its paths from the scan ledger, not from the walk,
|
|
41684
|
+
* and the ledger holds every file the scanner ever read under the root, nested
|
|
41685
|
+
* clones' included. So a clone that was removed, or one an ignore file now
|
|
41686
|
+
* hides, is in no walk and never reaches `nestedVerdict`, yet its ledgered
|
|
41687
|
+
* paths come back as deleted. The scan names the repository of each deleted
|
|
41688
|
+
* path (`context.deletedFileKeys`, one entry per path in the register's order)
|
|
41689
|
+
* and each is held to the same verdict as any other key. A path whose key is
|
|
41690
|
+
* absent, or out of scope, is not sent.
|
|
41691
|
+
*
|
|
41692
|
+
* The list is asked for here, and only here: it is an async read of the scan
|
|
41693
|
+
* ledger that the scan makes on being called, so a machine attachment, which
|
|
41694
|
+
* returns before this, and a register already kept local never cause it.
|
|
41695
|
+
*
|
|
41696
|
+
* Anything the scan did not vouch for sends no deleted path, and the register
|
|
41697
|
+
* itself still goes: no list, a list that throws or whose read is rejected, or a
|
|
41698
|
+
* list whose length is not the register's. Deleting is the only thing a dropped
|
|
41699
|
+
* path could have done on the server, so the cost of a refusal is a stored row
|
|
41700
|
+
* that stays, never a path that leaves.
|
|
41701
|
+
*
|
|
41702
|
+
* Machine mode returns `input` itself, the same object and unread, so a machine
|
|
41703
|
+
* attachment's request is exactly what it was. A register that lists no deleted
|
|
41704
|
+
* path, or that is not a ledger register, has nothing to cut and is returned
|
|
41705
|
+
* as it came, with the list unread.
|
|
41706
|
+
*/
|
|
41707
|
+
async registerForWire(input2, context) {
|
|
41708
|
+
try {
|
|
41709
|
+
if (this.deps.attachment.mode === "machine") return input2;
|
|
41710
|
+
const { reconcile } = input2;
|
|
41711
|
+
if (reconcile.mode !== "ledger" || reconcile.deletedFiles.length === 0) return input2;
|
|
41712
|
+
const deleted = reconcile.deletedFiles;
|
|
41713
|
+
let kept = [];
|
|
41714
|
+
try {
|
|
41715
|
+
const keys = await context?.deletedFileKeys?.();
|
|
41716
|
+
if (keys?.length === deleted.length) {
|
|
41717
|
+
kept = deleted.filter((_path, at) => this.verdictFor(() => keys[at]) === "forward");
|
|
41718
|
+
}
|
|
41719
|
+
} catch {
|
|
41720
|
+
kept = [];
|
|
41721
|
+
}
|
|
41722
|
+
return { ...input2, reconcile: { ...reconcile, deletedFiles: kept } };
|
|
41723
|
+
} catch {
|
|
41724
|
+
return void 0;
|
|
41725
|
+
}
|
|
41726
|
+
}
|
|
42187
41727
|
/**
|
|
42188
41728
|
* The event `recordCapture` sends for a capture the verdict let through, or
|
|
42189
41729
|
* `undefined` to send nothing. TOTAL, like `verdictFor`, and for its reasons.
|
|
@@ -42509,12 +42049,24 @@ var AttachedDataGateway = class {
|
|
|
42509
42049
|
* payload onto the wire-boundary-safe shape (no snippet, hashed
|
|
42510
42050
|
* projectKey), and its result is discarded: `forward.run` never throws or
|
|
42511
42051
|
* rejects, so there is nothing here to act on.
|
|
42052
|
+
*
|
|
42053
|
+
* `context.nestedScopeKeys` is what the scanner knows and the register does
|
|
42054
|
+
* not say: the key of every repository nested below the scan root, whose
|
|
42055
|
+
* files the walk folded into this register. On a scoped attachment the
|
|
42056
|
+
* register is forwarded only when the project's own key AND every one of
|
|
42057
|
+
* those is in scope (see `nestedVerdict`), and its deleted paths are cut to the
|
|
42058
|
+
* ones whose own repository is in scope (`context.deletedFileKeys`, see
|
|
42059
|
+
* `registerForWire`). Machine mode never reads either, and the local write
|
|
42060
|
+
* never receives the context and gets the register whole.
|
|
42512
42061
|
*/
|
|
42513
|
-
async recordProjectEgress(input2) {
|
|
42062
|
+
async recordProjectEgress(input2, context) {
|
|
42514
42063
|
const summary = await this.deps.local.recordProjectEgress(input2);
|
|
42515
42064
|
if (this.verdictFor(() => scopeKeyOfProjectKey(input2.projectKey)) === "local") return summary;
|
|
42065
|
+
if (this.nestedVerdict(context) === "local") return summary;
|
|
42066
|
+
const register = await this.registerForWire(input2, context);
|
|
42067
|
+
if (register === void 0) return summary;
|
|
42516
42068
|
await this.deps.forward.run(
|
|
42517
|
-
() => this.deps.client.recordProjectEgress(toEgressIngestRequest(
|
|
42069
|
+
() => this.deps.client.recordProjectEgress(toEgressIngestRequest(register))
|
|
42518
42070
|
);
|
|
42519
42071
|
return summary;
|
|
42520
42072
|
}
|
|
@@ -42568,6 +42120,11 @@ var AttachedDataGateway = class {
|
|
|
42568
42120
|
async scanLedgerPaths() {
|
|
42569
42121
|
return this.deps.local.scanLedgerPaths();
|
|
42570
42122
|
}
|
|
42123
|
+
// Delegated, like the path list. An inner gateway that cannot say answers an
|
|
42124
|
+
// empty map, which gives every deleted path no key.
|
|
42125
|
+
async scanLedgerPathKeys() {
|
|
42126
|
+
return await this.deps.local.scanLedgerPathKeys?.() ?? /* @__PURE__ */ new Map();
|
|
42127
|
+
}
|
|
42571
42128
|
async recordScanned(entries) {
|
|
42572
42129
|
return this.deps.local.recordScanned(entries);
|
|
42573
42130
|
}
|
|
@@ -42634,6 +42191,12 @@ var AttachedDataGateway = class {
|
|
|
42634
42191
|
// and the spread above would otherwise drop the field silently — which is
|
|
42635
42192
|
// exactly what it did, leaving the whole control inert on every device
|
|
42636
42193
|
// while every test around it stayed green.
|
|
42194
|
+
//
|
|
42195
|
+
// WHOLE ON EVERY ATTACHMENT. A scoped attachment does not narrow the list
|
|
42196
|
+
// here: the port's `getPolicyBundle()` takes no event, and the runtime
|
|
42197
|
+
// reads this bundle once to build detection, so the detections it carries
|
|
42198
|
+
// apply to every event on the machine. Where a prohibition applies is
|
|
42199
|
+
// answered per event by `governanceAppliesTo` below.
|
|
42637
42200
|
prohibitedModels: cached2.prohibitedModels,
|
|
42638
42201
|
// NAMED for the same reason as the line above, and it is the same defect
|
|
42639
42202
|
// if it is not: `...local` above spreads the DEVICE's bundle, so a field
|
|
@@ -42693,6 +42256,30 @@ var AttachedDataGateway = class {
|
|
|
42693
42256
|
};
|
|
42694
42257
|
}
|
|
42695
42258
|
// ---------------------------------------------------------------------
|
|
42259
|
+
// GovernanceScope — where the organization's model policy applies
|
|
42260
|
+
// ---------------------------------------------------------------------
|
|
42261
|
+
/**
|
|
42262
|
+
* Whether the organization's governance applies to an event keyed `scopeKey`:
|
|
42263
|
+
* the question a model-guard site asks once it has decided to refuse.
|
|
42264
|
+
*
|
|
42265
|
+
* THE FORWARD VERDICT, through `verdictFor`: the answer is whether a capture
|
|
42266
|
+
* with the same key would be forwarded. A machine-wide attachment governs
|
|
42267
|
+
* every event, keyless included, exactly as before. A scoped one governs an
|
|
42268
|
+
* event only when its key names an enrolled repository. An event in a
|
|
42269
|
+
* personal repository, in no repository, with an empty key, or met by a fault
|
|
42270
|
+
* is not governed.
|
|
42271
|
+
*
|
|
42272
|
+
* The event's OWN key, never its session root's. The root rule in
|
|
42273
|
+
* `auditVerdict` decides whether a row can be forwarded without orphaning it;
|
|
42274
|
+
* this decides whether a refusal applies, which is a question about where the
|
|
42275
|
+
* event happened.
|
|
42276
|
+
*
|
|
42277
|
+
* Answered from memory: no store read, no bundle read, nothing sent.
|
|
42278
|
+
*/
|
|
42279
|
+
governanceAppliesTo(scopeKey) {
|
|
42280
|
+
return this.verdictFor(() => scopeKey) === "forward";
|
|
42281
|
+
}
|
|
42282
|
+
// ---------------------------------------------------------------------
|
|
42696
42283
|
// LocalStoreMaintenance — by delegation (D3).
|
|
42697
42284
|
//
|
|
42698
42285
|
// Implementing these is what actually closes the skipped-local-maintenance
|
|
@@ -42801,8 +42388,8 @@ function toWireInspection(insp) {
|
|
|
42801
42388
|
}
|
|
42802
42389
|
|
|
42803
42390
|
// ../../packages/plugin-runtime/src/attached/history-sync.ts
|
|
42804
|
-
import { createHash as
|
|
42805
|
-
import { hostname as
|
|
42391
|
+
import { createHash as createHash7 } from "crypto";
|
|
42392
|
+
import { hostname as hostname4 } from "os";
|
|
42806
42393
|
|
|
42807
42394
|
// ../../packages/plugin-runtime/src/attached/capture-rebuild.ts
|
|
42808
42395
|
var CORRELATION_ID = EventMetadata.shape.correlationId;
|
|
@@ -42820,17 +42407,17 @@ var HISTORY_SYNC_THROTTLE_MS = 5 * 60 * 1e3;
|
|
|
42820
42407
|
|
|
42821
42408
|
// ../../packages/plugin-runtime/src/attached/install-record.ts
|
|
42822
42409
|
import { readFile as readFile2, stat } from "fs/promises";
|
|
42823
|
-
import { basename as
|
|
42410
|
+
import { basename as basename4, dirname as dirname6, join as join24, resolve as resolve2 } from "path";
|
|
42824
42411
|
async function readInstalledVersion(installRoot) {
|
|
42825
42412
|
try {
|
|
42826
42413
|
const versionDir = resolve2(installRoot);
|
|
42827
|
-
const pluginDir =
|
|
42828
|
-
const marketplaceDir =
|
|
42829
|
-
const cacheDir =
|
|
42830
|
-
if (
|
|
42831
|
-
const key = `${
|
|
42414
|
+
const pluginDir = dirname6(versionDir);
|
|
42415
|
+
const marketplaceDir = dirname6(pluginDir);
|
|
42416
|
+
const cacheDir = dirname6(marketplaceDir);
|
|
42417
|
+
if (basename4(cacheDir) !== "cache") return null;
|
|
42418
|
+
const key = `${basename4(pluginDir)}@${basename4(marketplaceDir)}`;
|
|
42832
42419
|
const record2 = JSON.parse(
|
|
42833
|
-
await readFile2(
|
|
42420
|
+
await readFile2(join24(dirname6(cacheDir), "installed_plugins.json"), "utf8")
|
|
42834
42421
|
);
|
|
42835
42422
|
const plugins = record2?.plugins;
|
|
42836
42423
|
if (typeof plugins !== "object" || plugins === null || !Object.hasOwn(plugins, key)) {
|
|
@@ -42862,7 +42449,7 @@ async function exists(path) {
|
|
|
42862
42449
|
}
|
|
42863
42450
|
|
|
42864
42451
|
// ../../packages/plugin-runtime/src/attached/plugin-block.ts
|
|
42865
|
-
import { readFileSync as
|
|
42452
|
+
import { readFileSync as readFileSync15 } from "fs";
|
|
42866
42453
|
var INSTALL_RECORD_READ_TIMEOUT_MS = REQUEST_TIMEOUT_MS / 2;
|
|
42867
42454
|
function createPluginBlock(build, policyStore) {
|
|
42868
42455
|
return async () => {
|
|
@@ -42892,7 +42479,7 @@ async function readInstalledVersionBounded(installRoot) {
|
|
|
42892
42479
|
// ../../packages/plugin-runtime/src/attached/policy-store.ts
|
|
42893
42480
|
import { randomUUID as randomUUID17 } from "crypto";
|
|
42894
42481
|
import { readFile as readFile3, rm, writeFile as writeFile2 } from "fs/promises";
|
|
42895
|
-
import { join as
|
|
42482
|
+
import { join as join25 } from "path";
|
|
42896
42483
|
|
|
42897
42484
|
// ../../packages/plugin-runtime/src/attached/atomic-publish.ts
|
|
42898
42485
|
import { rename as rename2 } from "fs/promises";
|
|
@@ -42921,7 +42508,7 @@ async function publishByRename(tmp, file2, move = rename2) {
|
|
|
42921
42508
|
|
|
42922
42509
|
// ../../packages/plugin-runtime/src/attached/policy-store.ts
|
|
42923
42510
|
function createPolicyStore(dir = dataDir()) {
|
|
42924
|
-
const file2 =
|
|
42511
|
+
const file2 = join25(dir, "policy-cache.json");
|
|
42925
42512
|
async function read() {
|
|
42926
42513
|
try {
|
|
42927
42514
|
const raw = await readFile3(file2, "utf8");
|
|
@@ -42991,8 +42578,8 @@ function createPolicyStore(dir = dataDir()) {
|
|
|
42991
42578
|
}
|
|
42992
42579
|
|
|
42993
42580
|
// ../../packages/plugin-runtime/src/attached/posture-report-state.ts
|
|
42994
|
-
import { readFileSync as
|
|
42995
|
-
import { join as
|
|
42581
|
+
import { readFileSync as readFileSync16 } from "fs";
|
|
42582
|
+
import { join as join26 } from "path";
|
|
42996
42583
|
var POSTURE_REPORT_STATE_FILENAME = ATTACHED_POSTURE_REPORT_FILENAME;
|
|
42997
42584
|
var OUTCOME_KEYS = {
|
|
42998
42585
|
ok: true,
|
|
@@ -43006,7 +42593,7 @@ var OUTCOME_KEYS = {
|
|
|
43006
42593
|
};
|
|
43007
42594
|
var OUTCOMES = new Set(Object.keys(OUTCOME_KEYS));
|
|
43008
42595
|
function postureReportStatePath(dataDir2) {
|
|
43009
|
-
return
|
|
42596
|
+
return join26(dataDir2, POSTURE_REPORT_STATE_FILENAME);
|
|
43010
42597
|
}
|
|
43011
42598
|
function writePostureReportState(dataDir2, state) {
|
|
43012
42599
|
try {
|
|
@@ -43047,10 +42634,19 @@ function createPostureReporter(deps) {
|
|
|
43047
42634
|
hostname: deps.hostname(),
|
|
43048
42635
|
capturedAt: nowMs,
|
|
43049
42636
|
...measurement,
|
|
43050
|
-
// Omit the key rather than spread an explicit `undefined
|
|
43051
|
-
//
|
|
43052
|
-
//
|
|
43053
|
-
|
|
42637
|
+
// Omit the key rather than spread an explicit `undefined`. The type
|
|
42638
|
+
// admits `undefined` here (the schema's optional member), and
|
|
42639
|
+
// JSON.stringify sends the same bytes either way. Omitting keeps the
|
|
42640
|
+
// in-memory object free of an explicit `undefined` member, which the
|
|
42641
|
+
// tests pin by key presence.
|
|
42642
|
+
...plugin === void 0 ? {} : { plugin },
|
|
42643
|
+
// LAST, and only for a scoped attachment. A machine attachment omits
|
|
42644
|
+
// the key the same way, so its body is byte for byte the one it sent
|
|
42645
|
+
// before the member existed. Anything but exactly `machine` reports the
|
|
42646
|
+
// constant `scoped`, never the raw value: that is resolveScope's own
|
|
42647
|
+
// fail direction, and a value outside the wire's vocabulary would fail
|
|
42648
|
+
// the whole snapshot at the receiver, the wipe signal with it.
|
|
42649
|
+
...deps.attachmentMode === "machine" ? {} : { attachmentMode: "scoped" }
|
|
43054
42650
|
};
|
|
43055
42651
|
} catch {
|
|
43056
42652
|
return null;
|
|
@@ -43073,8 +42669,8 @@ function createPostureReporter(deps) {
|
|
|
43073
42669
|
}
|
|
43074
42670
|
|
|
43075
42671
|
// ../../packages/plugin-runtime/src/attached/posture-snapshot.ts
|
|
43076
|
-
import { statSync as
|
|
43077
|
-
import { DatabaseSync as
|
|
42672
|
+
import { statSync as statSync7 } from "fs";
|
|
42673
|
+
import { DatabaseSync as DatabaseSync3 } from "node:sqlite";
|
|
43078
42674
|
|
|
43079
42675
|
// ../../packages/plugin-runtime/src/attached/action-counts.ts
|
|
43080
42676
|
function emptyActionCounts() {
|
|
@@ -43104,7 +42700,7 @@ function emptyReadout(readError = false) {
|
|
|
43104
42700
|
}
|
|
43105
42701
|
function readStorePosture(dbPath2) {
|
|
43106
42702
|
try {
|
|
43107
|
-
|
|
42703
|
+
statSync7(dbPath2);
|
|
43108
42704
|
} catch (err) {
|
|
43109
42705
|
const code = err.code;
|
|
43110
42706
|
if (code === "ENOENT" || code === "ENOTDIR") return emptyReadout();
|
|
@@ -43132,7 +42728,7 @@ function readStorePosture(dbPath2) {
|
|
|
43132
42728
|
readError: false
|
|
43133
42729
|
});
|
|
43134
42730
|
try {
|
|
43135
|
-
db = new
|
|
42731
|
+
db = new DatabaseSync3(dbPath2, { readOnly: true });
|
|
43136
42732
|
db.exec("PRAGMA busy_timeout = 2000");
|
|
43137
42733
|
version2 = db.prepare("PRAGMA user_version").get().user_version;
|
|
43138
42734
|
try {
|
|
@@ -43186,11 +42782,11 @@ function readStorePosture(dbPath2) {
|
|
|
43186
42782
|
// ../../packages/plugin-runtime/src/attached/posture-store.ts
|
|
43187
42783
|
import { randomUUID as randomUUID18 } from "crypto";
|
|
43188
42784
|
import { readFile as readFile4, rm as rm2, writeFile as writeFile3 } from "fs/promises";
|
|
43189
|
-
import { join as
|
|
42785
|
+
import { join as join27 } from "path";
|
|
43190
42786
|
var UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/;
|
|
43191
42787
|
function createPostureStore(dir = settingsDir(), legacyDir) {
|
|
43192
|
-
const file2 =
|
|
43193
|
-
const legacyFile = legacyDir === void 0 ? null :
|
|
42788
|
+
const file2 = join27(dir, "posture-state.json");
|
|
42789
|
+
const legacyFile = legacyDir === void 0 ? null : join27(legacyDir, "posture-state.json");
|
|
43194
42790
|
async function persist(state) {
|
|
43195
42791
|
await ensureDataDir(dir);
|
|
43196
42792
|
const tmp = `${file2}.${randomUUID18()}.tmp`;
|
|
@@ -43258,8 +42854,8 @@ function createPostureStore(dir = settingsDir(), legacyDir) {
|
|
|
43258
42854
|
}
|
|
43259
42855
|
|
|
43260
42856
|
// ../../packages/plugin-runtime/src/attached/sync-state.ts
|
|
43261
|
-
import { readFileSync as
|
|
43262
|
-
import { join as
|
|
42857
|
+
import { readFileSync as readFileSync17 } from "fs";
|
|
42858
|
+
import { join as join28 } from "path";
|
|
43263
42859
|
|
|
43264
42860
|
// ../../packages/plugin-runtime/src/attached/status.ts
|
|
43265
42861
|
var REFUSAL_LINES = {
|
|
@@ -43289,7 +42885,7 @@ import { fileURLToPath as fileURLToPath5 } from "url";
|
|
|
43289
42885
|
var CONTENT_RETENTION_THROTTLE_MS = 60 * 60 * 1e3;
|
|
43290
42886
|
|
|
43291
42887
|
// ../../packages/plugin-runtime/src/attached/factory.ts
|
|
43292
|
-
import { hostname as
|
|
42888
|
+
import { hostname as hostname5 } from "os";
|
|
43293
42889
|
|
|
43294
42890
|
// ../../packages/plugin-runtime/src/recorder.ts
|
|
43295
42891
|
var PLUGIN_RECORDER_BINARY = "plugin";
|
|
@@ -43302,7 +42898,7 @@ var StandaloneDataGateway = class {
|
|
|
43302
42898
|
// One notice per gateway — see warnRulesetDiscarded.
|
|
43303
42899
|
warnedRulesetDiscarded = false;
|
|
43304
42900
|
constructor(dataDir2, detections = [], meta4) {
|
|
43305
|
-
this.db = openLocalDatabase(dataDir2);
|
|
42901
|
+
this.db = openLocalDatabase(dataDir2, { shippedRegexMatchers: shippedRegexMatchers() });
|
|
43306
42902
|
this.dataDir = dataDir2;
|
|
43307
42903
|
this.db.installedPacks.recordInventory(detections, meta4);
|
|
43308
42904
|
}
|
|
@@ -43651,6 +43247,9 @@ var StandaloneDataGateway = class {
|
|
|
43651
43247
|
scanLedgerPaths() {
|
|
43652
43248
|
return Promise.resolve(this.db.scanLedger.allPaths());
|
|
43653
43249
|
}
|
|
43250
|
+
scanLedgerPathKeys() {
|
|
43251
|
+
return Promise.resolve(this.db.scanLedger.pathKeys());
|
|
43252
|
+
}
|
|
43654
43253
|
recordScanned(entries) {
|
|
43655
43254
|
this.db.scanLedger.upsertEntries(entries);
|
|
43656
43255
|
return Promise.resolve();
|
|
@@ -43736,13 +43335,17 @@ function resolveGatewayForConfig(config2, meta4) {
|
|
|
43736
43335
|
},
|
|
43737
43336
|
store: postureStore,
|
|
43738
43337
|
readStore: () => readStorePosture(config2.dbPath),
|
|
43739
|
-
hostname: () =>
|
|
43338
|
+
hostname: () => hostname5(),
|
|
43740
43339
|
now: () => Date.now(),
|
|
43340
|
+
// The mode THIS gateway enforces, from the attachment resolved above,
|
|
43341
|
+
// so the report cannot name a mode the forward paths are not using.
|
|
43342
|
+
attachmentMode: attachment.mode,
|
|
43741
43343
|
// The reporting build's identity, when the caller knows it (the plugin
|
|
43742
43344
|
// adapters do; an embedder or a test may not). Composed with the SAME
|
|
43743
43345
|
// policy store the sync child writes, so the block names the bundle
|
|
43744
|
-
// actually in force.
|
|
43745
|
-
// reporter
|
|
43346
|
+
// actually in force. The dependency key is omitted when no build is
|
|
43347
|
+
// known, and the reporter's optional call (`deps.pluginBlock?.()`)
|
|
43348
|
+
// then adds no block.
|
|
43746
43349
|
...meta4?.pluginBuild === void 0 ? {} : { pluginBlock: createPluginBlock(meta4.pluginBuild, store) }
|
|
43747
43350
|
})
|
|
43748
43351
|
});
|
|
@@ -43763,33 +43366,33 @@ import { randomUUID as randomUUID19 } from "crypto";
|
|
|
43763
43366
|
var EXCEPTION_RETENTION_MS = 90 * 24 * 60 * 60 * 1e3;
|
|
43764
43367
|
|
|
43765
43368
|
// src/history/transcripts.ts
|
|
43766
|
-
import { closeSync as
|
|
43767
|
-
import { homedir as
|
|
43768
|
-
import { join as
|
|
43369
|
+
import { closeSync as closeSync2, openSync as openSync2, readdirSync as readdirSync3, readFileSync as readFileSync18, readSync, statSync as statSync8 } from "fs";
|
|
43370
|
+
import { homedir as homedir2 } from "os";
|
|
43371
|
+
import { join as join29 } from "path";
|
|
43769
43372
|
function transcriptsDir(home) {
|
|
43770
|
-
return
|
|
43373
|
+
return join29(home ?? homedir2(), ".codex", "sessions");
|
|
43771
43374
|
}
|
|
43772
43375
|
var DAY_MS5 = 24 * 60 * 60 * 1e3;
|
|
43773
43376
|
|
|
43774
43377
|
// src/remediation/redact.ts
|
|
43775
43378
|
import {
|
|
43776
43379
|
lstatSync as lstatSync4,
|
|
43777
|
-
readdirSync as
|
|
43778
|
-
readFileSync as
|
|
43779
|
-
realpathSync as
|
|
43380
|
+
readdirSync as readdirSync4,
|
|
43381
|
+
readFileSync as readFileSync19,
|
|
43382
|
+
realpathSync as realpathSync2,
|
|
43780
43383
|
renameSync as renameSync5,
|
|
43781
43384
|
rmSync as rmSync8,
|
|
43782
|
-
statSync as
|
|
43783
|
-
writeFileSync as
|
|
43385
|
+
statSync as statSync9,
|
|
43386
|
+
writeFileSync as writeFileSync7
|
|
43784
43387
|
} from "fs";
|
|
43785
|
-
import { basename as
|
|
43388
|
+
import { basename as basename5, dirname as dirname7, isAbsolute as isAbsolute2, join as join30, relative, resolve as resolve3 } from "path";
|
|
43786
43389
|
var REDACTED_PLACEHOLDER = "[REDACTED:SECRET]";
|
|
43787
43390
|
function platformRedactionScope(home) {
|
|
43788
43391
|
return { artifactRoots: [transcriptsDir(home)] };
|
|
43789
43392
|
}
|
|
43790
43393
|
function realPathOrNull(path) {
|
|
43791
43394
|
try {
|
|
43792
|
-
return
|
|
43395
|
+
return realpathSync2(path);
|
|
43793
43396
|
} catch {
|
|
43794
43397
|
return null;
|
|
43795
43398
|
}
|
|
@@ -43798,7 +43401,7 @@ function isWithinRoot(realTarget, root) {
|
|
|
43798
43401
|
const realRoot = realPathOrNull(root);
|
|
43799
43402
|
if (realRoot === null) return false;
|
|
43800
43403
|
const rel = relative(realRoot, realTarget);
|
|
43801
|
-
return rel !== "" && !rel.startsWith("..") && !
|
|
43404
|
+
return rel !== "" && !rel.startsWith("..") && !isAbsolute2(rel);
|
|
43802
43405
|
}
|
|
43803
43406
|
function resolveRedactableArtifact(filePath, scope) {
|
|
43804
43407
|
const realTarget = realPathOrNull(resolve3(filePath));
|
|
@@ -43818,11 +43421,11 @@ function isProcessAlive(pid) {
|
|
|
43818
43421
|
}
|
|
43819
43422
|
}
|
|
43820
43423
|
function sweepStrandedTemps(realPath) {
|
|
43821
|
-
const dir =
|
|
43822
|
-
const prefix = `${
|
|
43424
|
+
const dir = dirname7(realPath);
|
|
43425
|
+
const prefix = `${basename5(realPath)}.`;
|
|
43823
43426
|
let names;
|
|
43824
43427
|
try {
|
|
43825
|
-
names =
|
|
43428
|
+
names = readdirSync4(dir);
|
|
43826
43429
|
} catch {
|
|
43827
43430
|
return;
|
|
43828
43431
|
}
|
|
@@ -43833,7 +43436,7 @@ function sweepStrandedTemps(realPath) {
|
|
|
43833
43436
|
const pid = Number(pidPart);
|
|
43834
43437
|
if (pid !== process.pid && isProcessAlive(pid)) continue;
|
|
43835
43438
|
try {
|
|
43836
|
-
const stranded =
|
|
43439
|
+
const stranded = join30(dir, name);
|
|
43837
43440
|
if (!lstatSync4(stranded).isFile()) continue;
|
|
43838
43441
|
rmSync8(stranded, { force: true });
|
|
43839
43442
|
} catch {
|
|
@@ -43856,8 +43459,8 @@ function redactLeakedKeysDetailed(targets, scope = platformRedactionScope()) {
|
|
|
43856
43459
|
let content;
|
|
43857
43460
|
let mode;
|
|
43858
43461
|
try {
|
|
43859
|
-
mode =
|
|
43860
|
-
content =
|
|
43462
|
+
mode = statSync9(filePath).mode & 511;
|
|
43463
|
+
content = readFileSync19(filePath, "utf8");
|
|
43861
43464
|
} catch {
|
|
43862
43465
|
continue;
|
|
43863
43466
|
}
|
|
@@ -43877,7 +43480,7 @@ function redactLeakedKeysDetailed(targets, scope = platformRedactionScope()) {
|
|
|
43877
43480
|
if (struckHere.length === 0) continue;
|
|
43878
43481
|
const tmpPath = tempPathFor(filePath);
|
|
43879
43482
|
try {
|
|
43880
|
-
|
|
43483
|
+
writeFileSync7(tmpPath, content, { mode, flag: "wx" });
|
|
43881
43484
|
renameSync5(tmpPath, filePath);
|
|
43882
43485
|
} catch {
|
|
43883
43486
|
try {
|
|
@@ -43934,7 +43537,7 @@ async function redactSurfacedSecrets(findings, overrides = {}) {
|
|
|
43934
43537
|
for (const [filePath, fileFindings] of byFile) {
|
|
43935
43538
|
let content;
|
|
43936
43539
|
try {
|
|
43937
|
-
content =
|
|
43540
|
+
content = readFileSync20(filePath, "utf8");
|
|
43938
43541
|
} catch {
|
|
43939
43542
|
unrecovered.push(...fileFindings);
|
|
43940
43543
|
continue;
|
|
@@ -44092,7 +43695,7 @@ if (process.argv[1] && fileURLToPath6(import.meta.url) === process.argv[1]) {
|
|
|
44092
43695
|
try {
|
|
44093
43696
|
const argv = process.argv.slice(2);
|
|
44094
43697
|
const optionIndex = argv.indexOf("--option");
|
|
44095
|
-
const frameText =
|
|
43698
|
+
const frameText = readFileSync21(0, "utf8");
|
|
44096
43699
|
if (optionIndex === -1) {
|
|
44097
43700
|
present(frameText);
|
|
44098
43701
|
} else {
|