@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
|
@@ -1,891 +1,14 @@
|
|
|
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 SLASH2 = "/";
|
|
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
|
-
SLASH2
|
|
293
|
-
],
|
|
294
|
-
// replace special metacharacter slash after the leading slash
|
|
295
|
-
[
|
|
296
|
-
/\//g,
|
|
297
|
-
() => "\\/",
|
|
298
|
-
SLASH2
|
|
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 === SLASH2 ? `${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] === SLASH2) {
|
|
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(SLASH2);
|
|
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
|
-
SLASH2,
|
|
559
|
-
path[end] === SLASH2 ? 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(SLASH2).filter(Boolean);
|
|
566
|
-
slices.pop();
|
|
567
|
-
return slices.length ? slices.join(SLASH2) + SLASH2 : EMPTY;
|
|
568
|
-
}
|
|
569
|
-
const end = path.length - 1;
|
|
570
|
-
const cut = path.lastIndexOf(
|
|
571
|
-
SLASH2,
|
|
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] === SLASH2 ? 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 basename7 = 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 ? basename7 : 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/apply-suppressions.ts
|
|
876
|
-
import { existsSync as
|
|
8
|
+
import { existsSync as existsSync9, readFileSync as readFileSync14 } from "fs";
|
|
877
9
|
import { userInfo } from "os";
|
|
878
|
-
import { dirname as
|
|
879
|
-
import { fileURLToPath as
|
|
880
|
-
|
|
881
|
-
// ../../packages/persistence/src/attached-derived.ts
|
|
882
|
-
import { rmSync } from "fs";
|
|
883
|
-
import { join } from "path";
|
|
884
|
-
var POLICY_CACHE_FILENAME = "policy-cache.json";
|
|
885
|
-
|
|
886
|
-
// ../../packages/persistence/src/control-plane-credential.ts
|
|
887
|
-
import { chmodSync as chmodSync2, lstatSync as lstatSync2, readFileSync, rmSync as rmSync3, statSync } from "fs";
|
|
888
|
-
import { join as join2 } from "path";
|
|
10
|
+
import { dirname as dirname6, join as join22 } from "path";
|
|
11
|
+
import { fileURLToPath as fileURLToPath3 } from "url";
|
|
889
12
|
|
|
890
13
|
// ../../packages/schema/src/drizzle/deferred-migrations.ts
|
|
891
14
|
var DEFERRED_MIGRATION_TAGS = [
|
|
@@ -1057,6 +180,12 @@ var HOUR_MS = 60 * MINUTE_MS;
|
|
|
1057
180
|
var MAX_TEMPORARY_MS = 24 * HOUR_MS;
|
|
1058
181
|
var ONCE_BACKSTOP_MS = 30 * MINUTE_MS;
|
|
1059
182
|
|
|
183
|
+
// ../../packages/schema/src/invisible-padding.ts
|
|
184
|
+
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;
|
|
185
|
+
function stripInvisiblePadding(text) {
|
|
186
|
+
return text.replace(INVISIBLE_PADDING, "");
|
|
187
|
+
}
|
|
188
|
+
|
|
1060
189
|
// ../../node_modules/.pnpm/zod@4.6.5/node_modules/zod/v4/classic/external.js
|
|
1061
190
|
var external_exports = {};
|
|
1062
191
|
__export(external_exports, {
|
|
@@ -3870,9 +2999,9 @@ var asciiTabOrNewline = /[\t\n\r]/g;
|
|
|
3870
2999
|
function stripTabAndNewline(value) {
|
|
3871
3000
|
return value.replace(asciiTabOrNewline, "");
|
|
3872
3001
|
}
|
|
3873
|
-
function urlHostnameOk(url2,
|
|
3874
|
-
|
|
3875
|
-
return
|
|
3002
|
+
function urlHostnameOk(url2, hostname4) {
|
|
3003
|
+
hostname4.lastIndex = 0;
|
|
3004
|
+
return hostname4.test(url2.hostname);
|
|
3876
3005
|
}
|
|
3877
3006
|
function urlProtocolOk(url2, protocol) {
|
|
3878
3007
|
protocol.lastIndex = 0;
|
|
@@ -20792,13 +19921,16 @@ function serviceTierMultiplier(tier) {
|
|
|
20792
19921
|
if (tier === void 0) return 1;
|
|
20793
19922
|
return SERVICE_TIER_MULTIPLIERS.get(tier) ?? 1;
|
|
20794
19923
|
}
|
|
19924
|
+
function promptTokensOf(usage) {
|
|
19925
|
+
return usage.promptTokens ?? (usage.inputTokens ?? 0) + (usage.cacheReadTokens ?? 0) + (usage.cacheWrite1hTokens ?? 0) + (usage.cacheWrite5mTokens ?? 0);
|
|
19926
|
+
}
|
|
20795
19927
|
function costOf(price, usage) {
|
|
20796
19928
|
const metered = [
|
|
20797
19929
|
[usage.cacheWrite1hTokens ?? 0, price.cacheWrite1h],
|
|
20798
19930
|
[usage.cacheWrite5mTokens ?? 0, price.cacheWrite5m],
|
|
20799
19931
|
[usage.cacheReadTokens ?? 0, price.cacheRead]
|
|
20800
19932
|
];
|
|
20801
|
-
const band = price.longContext !== null && (usage
|
|
19933
|
+
const band = price.longContext !== null && promptTokensOf(usage) > price.longContext.thresholdInputTokens ? price.longContext : null;
|
|
20802
19934
|
if (band !== null && (band.input === null || band.output === null)) return null;
|
|
20803
19935
|
const inputRate = band?.input ?? price.input;
|
|
20804
19936
|
const outputRate = band?.output ?? price.output;
|
|
@@ -20871,8 +20003,8 @@ var PLATFORM_HOSTING = /* @__PURE__ */ new Map([
|
|
|
20871
20003
|
["ollama", "local"],
|
|
20872
20004
|
["local", "local"]
|
|
20873
20005
|
]);
|
|
20874
|
-
function hostingFor(
|
|
20875
|
-
return PLATFORM_HOSTING.get(
|
|
20006
|
+
function hostingFor(platform) {
|
|
20007
|
+
return PLATFORM_HOSTING.get(platform) ?? "api";
|
|
20876
20008
|
}
|
|
20877
20009
|
var FIRST_PARTY = /* @__PURE__ */ new Map([
|
|
20878
20010
|
["anthropic", "anthropic"],
|
|
@@ -20886,8 +20018,8 @@ var FIRST_PARTY = /* @__PURE__ */ new Map([
|
|
|
20886
20018
|
function firstPartyPlatformFor(vendor2) {
|
|
20887
20019
|
return FIRST_PARTY.get(vendor2) ?? null;
|
|
20888
20020
|
}
|
|
20889
|
-
function isFirstParty(vendor2,
|
|
20890
|
-
return FIRST_PARTY.get(vendor2) ===
|
|
20021
|
+
function isFirstParty(vendor2, platform) {
|
|
20022
|
+
return FIRST_PARTY.get(vendor2) === platform;
|
|
20891
20023
|
}
|
|
20892
20024
|
var PLATFORM_NAMESPACES = Object.freeze([
|
|
20893
20025
|
"anthropic",
|
|
@@ -20948,14 +20080,14 @@ var ModelVendorBuilder = class {
|
|
|
20948
20080
|
);
|
|
20949
20081
|
}
|
|
20950
20082
|
for (const ref of spec.on ?? []) {
|
|
20951
|
-
const { platform
|
|
20952
|
-
const firstParty = isFirstParty(this.vendor,
|
|
20953
|
-
const hosting = hostingFor(
|
|
20083
|
+
const { platform, price, retention, region } = normalizeRef(ref);
|
|
20084
|
+
const firstParty = isFirstParty(this.vendor, platform);
|
|
20085
|
+
const hosting = hostingFor(platform);
|
|
20954
20086
|
const isSelfHosted = hosting === "local";
|
|
20955
20087
|
platforms.set(
|
|
20956
|
-
|
|
20088
|
+
platform,
|
|
20957
20089
|
Object.freeze({
|
|
20958
|
-
platform
|
|
20090
|
+
platform,
|
|
20959
20091
|
hosting,
|
|
20960
20092
|
firstParty,
|
|
20961
20093
|
price: price ?? (isSelfHosted ? ZERO_PRICE : firstParty ? spec.price ?? null : null),
|
|
@@ -21008,35 +20140,35 @@ var GATEWAY_VENDOR_SLASH_RE = /^[a-z0-9][\w.-]*\//iu;
|
|
|
21008
20140
|
var BEDROCK_VERSION_RE = /-v\d+:\d+$/u;
|
|
21009
20141
|
var BEDROCK_REVISION_RE = /:\d+$/u;
|
|
21010
20142
|
var VERTEX_VERSION_RE = /@[\w-]+$/u;
|
|
21011
|
-
var DATED_SUFFIX_RE =
|
|
20143
|
+
var DATED_SUFFIX_RE = /-(?:\d{8}|\d{4}-\d{2}-\d{2})$/u;
|
|
21012
20144
|
function stripPlatformDecorations(model) {
|
|
21013
20145
|
let id = model.trim();
|
|
21014
|
-
let
|
|
20146
|
+
let platform = null;
|
|
21015
20147
|
if (GEO_PREFIX_RE.test(id)) {
|
|
21016
20148
|
id = id.replace(GEO_PREFIX_RE, "");
|
|
21017
|
-
|
|
20149
|
+
platform = "bedrock";
|
|
21018
20150
|
}
|
|
21019
20151
|
if (NAMESPACE_DOT_RE.test(id)) {
|
|
21020
20152
|
id = id.replace(NAMESPACE_DOT_RE, "");
|
|
21021
|
-
|
|
20153
|
+
platform ??= "bedrock";
|
|
21022
20154
|
}
|
|
21023
20155
|
if (BEDROCK_VERSION_RE.test(id)) {
|
|
21024
20156
|
id = id.replace(BEDROCK_VERSION_RE, "");
|
|
21025
|
-
|
|
20157
|
+
platform ??= "bedrock";
|
|
21026
20158
|
} else if (BEDROCK_REVISION_RE.test(id)) {
|
|
21027
20159
|
id = id.replace(BEDROCK_REVISION_RE, "");
|
|
21028
|
-
|
|
20160
|
+
platform ??= "bedrock";
|
|
21029
20161
|
}
|
|
21030
20162
|
if (VERTEX_VERSION_RE.test(id)) {
|
|
21031
20163
|
id = id.replace(VERTEX_VERSION_RE, "");
|
|
21032
|
-
|
|
20164
|
+
platform ??= "vertex";
|
|
21033
20165
|
}
|
|
21034
20166
|
if (NAMESPACE_SLASH_RE.test(id)) {
|
|
21035
20167
|
id = id.replace(NAMESPACE_SLASH_RE, "");
|
|
21036
20168
|
} else if (GATEWAY_VENDOR_SLASH_RE.test(id)) {
|
|
21037
20169
|
id = id.replace(GATEWAY_VENDOR_SLASH_RE, "");
|
|
21038
20170
|
}
|
|
21039
|
-
return { id, platform
|
|
20171
|
+
return { id, platform };
|
|
21040
20172
|
}
|
|
21041
20173
|
function buildModelIndex(entries) {
|
|
21042
20174
|
const byId = /* @__PURE__ */ new Map();
|
|
@@ -21053,19 +20185,19 @@ function resolveModel(raw, index) {
|
|
|
21053
20185
|
if (exact !== void 0) {
|
|
21054
20186
|
return { entry: exact, canonicalId: raw, platform: null, raw };
|
|
21055
20187
|
}
|
|
21056
|
-
const { id, platform
|
|
20188
|
+
const { id, platform } = stripPlatformDecorations(raw);
|
|
21057
20189
|
const stripped = index.byId.get(id);
|
|
21058
20190
|
if (stripped !== void 0) {
|
|
21059
|
-
return { entry: stripped, canonicalId: id, platform
|
|
20191
|
+
return { entry: stripped, canonicalId: id, platform, raw };
|
|
21060
20192
|
}
|
|
21061
20193
|
if (DATED_SUFFIX_RE.test(id)) {
|
|
21062
20194
|
const undated = id.replace(DATED_SUFFIX_RE, "");
|
|
21063
20195
|
const byDate = index.byId.get(undated);
|
|
21064
20196
|
if (byDate !== void 0) {
|
|
21065
|
-
return { entry: byDate, canonicalId: undated, platform
|
|
20197
|
+
return { entry: byDate, canonicalId: undated, platform, raw };
|
|
21066
20198
|
}
|
|
21067
20199
|
}
|
|
21068
|
-
return { entry: null, canonicalId: raw, platform
|
|
20200
|
+
return { entry: null, canonicalId: raw, platform, raw };
|
|
21069
20201
|
}
|
|
21070
20202
|
|
|
21071
20203
|
// ../../packages/schema/src/model/catalog.ts
|
|
@@ -21158,7 +20290,7 @@ anthropic.model("claude-haiku-4-5", {
|
|
|
21158
20290
|
name: "Claude Haiku 4.5",
|
|
21159
20291
|
ctx: 2e5,
|
|
21160
20292
|
maxOut: 64e3,
|
|
21161
|
-
// Reviewed: fast/cheap tier,
|
|
20293
|
+
// Reviewed: fast/cheap general-purpose tier, not a reasoning or code model.
|
|
21162
20294
|
capability: null,
|
|
21163
20295
|
price: anthropicPrice(1, 5, 0.1),
|
|
21164
20296
|
// The vendor documents `claude-haiku-4-5-20251001` as the versioned id and
|
|
@@ -21289,6 +20421,11 @@ openai.model("gpt-4o", {
|
|
|
21289
20421
|
price: tokenPrice(2.5, 10, { cacheRead: 1.25 }),
|
|
21290
20422
|
on: [...OPENAI_RESELLERS]
|
|
21291
20423
|
});
|
|
20424
|
+
openai.model("gpt-4o-2024-05-13", {
|
|
20425
|
+
name: "GPT-4o (2024-05-13)",
|
|
20426
|
+
price: tokenPrice(5, 15),
|
|
20427
|
+
on: [...OPENAI_RESELLERS]
|
|
20428
|
+
});
|
|
21292
20429
|
openai.model("gpt-4o-mini", {
|
|
21293
20430
|
name: "GPT-4o mini",
|
|
21294
20431
|
price: tokenPrice(0.15, 0.6, { cacheRead: 0.075 }),
|
|
@@ -21308,6 +20445,24 @@ openai.model("o3", {
|
|
|
21308
20445
|
price: tokenPrice(2, 8, { cacheRead: 0.5 }),
|
|
21309
20446
|
on: [...OPENAI_RESELLERS]
|
|
21310
20447
|
});
|
|
20448
|
+
openai.model("text-embedding-3-small", {
|
|
20449
|
+
name: "text-embedding-3-small",
|
|
20450
|
+
capability: "embedding",
|
|
20451
|
+
price: tokenPrice(0.02, 0),
|
|
20452
|
+
on: [...OPENAI_RESELLERS]
|
|
20453
|
+
});
|
|
20454
|
+
openai.model("text-embedding-3-large", {
|
|
20455
|
+
name: "text-embedding-3-large",
|
|
20456
|
+
capability: "embedding",
|
|
20457
|
+
price: tokenPrice(0.13, 0),
|
|
20458
|
+
on: [...OPENAI_RESELLERS]
|
|
20459
|
+
});
|
|
20460
|
+
openai.model("text-embedding-ada-002", {
|
|
20461
|
+
name: "text-embedding-ada-002",
|
|
20462
|
+
capability: "embedding",
|
|
20463
|
+
price: tokenPrice(0.1, 0),
|
|
20464
|
+
on: [...OPENAI_RESELLERS]
|
|
20465
|
+
});
|
|
21311
20466
|
openai.model("gpt-oss-120b", {
|
|
21312
20467
|
name: "GPT-OSS 120B",
|
|
21313
20468
|
openWeights: true,
|
|
@@ -21594,10 +20749,21 @@ var MODEL_ENTRIES = Object.freeze([
|
|
|
21594
20749
|
...alibaba.models(),
|
|
21595
20750
|
...amazon.models()
|
|
21596
20751
|
]);
|
|
20752
|
+
var LONG_CONTEXT_THRESHOLDS = Object.freeze(
|
|
20753
|
+
[
|
|
20754
|
+
...new Set(
|
|
20755
|
+
MODEL_ENTRIES.flatMap(
|
|
20756
|
+
(entry) => [...entry.platforms.values()].flatMap(
|
|
20757
|
+
(offering) => offering.price?.longContext ? [offering.price.longContext.thresholdInputTokens] : []
|
|
20758
|
+
)
|
|
20759
|
+
)
|
|
20760
|
+
)
|
|
20761
|
+
].sort((a, b) => a - b)
|
|
20762
|
+
);
|
|
21597
20763
|
var MODEL_INDEX = buildModelIndex(MODEL_ENTRIES);
|
|
21598
20764
|
|
|
21599
20765
|
// ../../packages/schema/src/model/governance.ts
|
|
21600
|
-
var ModelCapability = external_exports.enum(["reasoning", "code"]);
|
|
20766
|
+
var ModelCapability = external_exports.enum(["reasoning", "code", "embedding"]);
|
|
21601
20767
|
var DataRetention = external_exports.enum([
|
|
21602
20768
|
"zero_retention",
|
|
21603
20769
|
"no_storage",
|
|
@@ -21693,16 +20859,16 @@ function platformForProvider(provider) {
|
|
|
21693
20859
|
return PROVIDER_PLATFORM.get(provider.trim().toLowerCase()) ?? null;
|
|
21694
20860
|
}
|
|
21695
20861
|
function isLocalProvider(provider) {
|
|
21696
|
-
const
|
|
21697
|
-
return
|
|
20862
|
+
const platform = platformForProvider(provider);
|
|
20863
|
+
return platform !== null && hostingFor(platform) === "local";
|
|
21698
20864
|
}
|
|
21699
20865
|
function priceFor(provider, model) {
|
|
21700
20866
|
if (isLocalProvider(provider)) return ZERO_PRICE;
|
|
21701
20867
|
const resolved = resolveModel(model, MODEL_INDEX);
|
|
21702
20868
|
if (resolved.entry === null) return null;
|
|
21703
|
-
const
|
|
21704
|
-
if (
|
|
21705
|
-
return resolved.entry.platforms.get(
|
|
20869
|
+
const platform = resolved.platform ?? platformForProvider(provider);
|
|
20870
|
+
if (platform === null) return null;
|
|
20871
|
+
return resolved.entry.platforms.get(platform)?.price ?? null;
|
|
21706
20872
|
}
|
|
21707
20873
|
var defaultCostModel = {
|
|
21708
20874
|
normalizeModelId(provider, model) {
|
|
@@ -21728,7 +20894,7 @@ var COMPACT = new Intl.NumberFormat("en-US", {
|
|
|
21728
20894
|
|
|
21729
20895
|
// ../../packages/schema/src/token/token-report.ts
|
|
21730
20896
|
var num = (value) => value ?? 0;
|
|
21731
|
-
function costUsageOf(a) {
|
|
20897
|
+
function costUsageOf(a, promptTokens) {
|
|
21732
20898
|
const usage = {
|
|
21733
20899
|
inputTokens: num(a.input_tokens),
|
|
21734
20900
|
outputTokens: num(a.output_tokens),
|
|
@@ -21738,11 +20904,12 @@ function costUsageOf(a) {
|
|
|
21738
20904
|
webSearchRequests: num(a.web_search_requests)
|
|
21739
20905
|
};
|
|
21740
20906
|
if (a.service_tier !== void 0) usage.serviceTier = a.service_tier;
|
|
20907
|
+
if (promptTokens !== void 0) usage.promptTokens = promptTokens;
|
|
21741
20908
|
return usage;
|
|
21742
20909
|
}
|
|
21743
20910
|
function buildTokenReports(leaves, costModel) {
|
|
21744
20911
|
const bySession = /* @__PURE__ */ new Map();
|
|
21745
|
-
for (const { sessionId, attributes } of leaves) {
|
|
20912
|
+
for (const { sessionId, attributes, promptTokens } of leaves) {
|
|
21746
20913
|
const provider = attributes.provider ?? "unknown";
|
|
21747
20914
|
const model = attributes.model ?? "unknown";
|
|
21748
20915
|
const key = `${provider} ${model}`;
|
|
@@ -21761,7 +20928,8 @@ function buildTokenReports(leaves, costModel) {
|
|
|
21761
20928
|
cacheCreation: 0,
|
|
21762
20929
|
cacheRead: 0,
|
|
21763
20930
|
costUsd: 0,
|
|
21764
|
-
priced: false
|
|
20931
|
+
priced: false,
|
|
20932
|
+
partial: false
|
|
21765
20933
|
};
|
|
21766
20934
|
rollups.set(key, acc);
|
|
21767
20935
|
}
|
|
@@ -21769,8 +20937,14 @@ function buildTokenReports(leaves, costModel) {
|
|
|
21769
20937
|
acc.output += num(attributes.output_tokens);
|
|
21770
20938
|
acc.cacheCreation += num(attributes.cache_creation_input_tokens);
|
|
21771
20939
|
acc.cacheRead += num(attributes.cache_read_input_tokens);
|
|
21772
|
-
const leafCost = costModel.costFor({
|
|
21773
|
-
|
|
20940
|
+
const leafCost = costModel.costFor({
|
|
20941
|
+
provider,
|
|
20942
|
+
model,
|
|
20943
|
+
usage: costUsageOf(attributes, promptTokens)
|
|
20944
|
+
});
|
|
20945
|
+
if (leafCost === null) {
|
|
20946
|
+
acc.partial = true;
|
|
20947
|
+
} else {
|
|
21774
20948
|
acc.costUsd += leafCost;
|
|
21775
20949
|
acc.priced = true;
|
|
21776
20950
|
}
|
|
@@ -21786,9 +20960,8 @@ function buildTokenReports(leaves, costModel) {
|
|
|
21786
20960
|
const rollupTotal = acc.input + acc.output + acc.cacheCreation + acc.cacheRead;
|
|
21787
20961
|
totalTokens += rollupTotal;
|
|
21788
20962
|
const estimatedCostUsd = acc.priced ? acc.costUsd : null;
|
|
21789
|
-
if (
|
|
21790
|
-
|
|
21791
|
-
} else {
|
|
20963
|
+
if (acc.partial) anyUnpriced = true;
|
|
20964
|
+
if (estimatedCostUsd !== null) {
|
|
21792
20965
|
anyPriced = true;
|
|
21793
20966
|
costUsd += estimatedCostUsd;
|
|
21794
20967
|
}
|
|
@@ -21811,7 +20984,7 @@ function buildTokenReports(leaves, costModel) {
|
|
|
21811
20984
|
totalTokens,
|
|
21812
20985
|
// Σ of the PRICED rollups; null when none had a known price.
|
|
21813
20986
|
estimatedCostUsd: anyPriced ? costUsd : null,
|
|
21814
|
-
// Any
|
|
20987
|
+
// Any call priced to null means the total understates real spend.
|
|
21815
20988
|
costIsPartial: anyUnpriced
|
|
21816
20989
|
});
|
|
21817
20990
|
}
|
|
@@ -22690,8 +21863,9 @@ var SessionTokenReport = external_exports.object({
|
|
|
22690
21863
|
totalTokens: external_exports.number().int().nonnegative(),
|
|
22691
21864
|
// Σ of the PRICED rollups only; null when no rollup had a known price.
|
|
22692
21865
|
estimatedCostUsd: external_exports.number().nullable(),
|
|
22693
|
-
// True whenever any
|
|
22694
|
-
//
|
|
21866
|
+
// True whenever any call priced to null (an unknown provider/model, or a call
|
|
21867
|
+
// over a long-context threshold whose rate is unpublished), so the total
|
|
21868
|
+
// understates real spend — the UI renders `≥ $X` instead of a falsely
|
|
22695
21869
|
// precise figure rather than silently dropping the unpriced calls.
|
|
22696
21870
|
costIsPartial: external_exports.boolean()
|
|
22697
21871
|
});
|
|
@@ -23540,7 +22714,15 @@ var StorePostureSnapshot = external_exports.object({
|
|
|
23540
22714
|
policyCounts: StorePosturePolicyCounts,
|
|
23541
22715
|
// OPTIONAL, not nullable: a reporter that predates this member keeps
|
|
23542
22716
|
// getting its 200 without a payload change.
|
|
23543
|
-
plugin: StorePosturePlugin.optional()
|
|
22717
|
+
plugin: StorePosturePlugin.optional(),
|
|
22718
|
+
// OPTIONAL, and sent only by a scoped attachment, always as `scoped`. A
|
|
22719
|
+
// machine attachment omits it, so its body is byte for byte the one it
|
|
22720
|
+
// sent before this member existed. Absent therefore means machine-wide OR
|
|
22721
|
+
// a reporter older than this member, never "scoped". Both values parse, so
|
|
22722
|
+
// a sender that one day spells `machine` breaks no receiver; any other
|
|
22723
|
+
// value fails the whole snapshot, which is why the reporter sends a
|
|
22724
|
+
// constant and never the raw mode.
|
|
22725
|
+
attachmentMode: AttachmentMode.optional()
|
|
23544
22726
|
}).meta({ id: "StorePostureSnapshot" });
|
|
23545
22727
|
var CAPTURE_VERSION_PREFIX = "capture/";
|
|
23546
22728
|
var RecordAuditEventRequest = AuditEventInput.extend({
|
|
@@ -23987,7 +23169,7 @@ var Rule = external_exports.strictObject({
|
|
|
23987
23169
|
postValidators: external_exports.array(PostValidatorRef).optional(),
|
|
23988
23170
|
requiresNearby: RequiresNearby.optional(),
|
|
23989
23171
|
examples: external_exports.array(external_exports.string()).optional(),
|
|
23990
|
-
// Whether the matched text is itself sensitive
|
|
23172
|
+
// Whether the matched text is itself sensitive (see RuleEvidence).
|
|
23991
23173
|
evidence: RuleEvidence.optional()
|
|
23992
23174
|
}).meta({ id: "Rule" });
|
|
23993
23175
|
var Author = external_exports.object({
|
|
@@ -24079,7 +23261,13 @@ var DetectionRule = external_exports.object({
|
|
|
24079
23261
|
// Representative matching strings the rule author shipped with the rule. The
|
|
24080
23262
|
// cheapest honest answer to "show me what this rule catches" — every bundled
|
|
24081
23263
|
// rule has them, and they are already in the stored snapshot.
|
|
24082
|
-
examples: external_exports.array(external_exports.string()).optional()
|
|
23264
|
+
examples: external_exports.array(external_exports.string()).optional(),
|
|
23265
|
+
// The rule's DECLARED evidence, as stored. Absent defers to the engine's
|
|
23266
|
+
// classification (ruleEvidence in @akasecurity/detections): a bundled
|
|
23267
|
+
// code-flaw rule reads as 'code' and anything else as 'value', and a rule
|
|
23268
|
+
// in a value category (secret/pii/financial/phi) is always 'value',
|
|
23269
|
+
// whatever it declares.
|
|
23270
|
+
evidence: RuleEvidence.optional()
|
|
24083
23271
|
}).meta({ id: "DetectionRule" });
|
|
24084
23272
|
var DetectionUpdate = external_exports.object({
|
|
24085
23273
|
available: external_exports.boolean(),
|
|
@@ -24147,8 +23335,10 @@ var ImportDetectionRequest = external_exports.object({
|
|
|
24147
23335
|
}).meta({ id: "ImportDetectionRequest" });
|
|
24148
23336
|
|
|
24149
23337
|
// ../../packages/schema/src/zod/detection-build.ts
|
|
24150
|
-
function optional2(key,
|
|
24151
|
-
if (raw === void 0
|
|
23338
|
+
function optional2(key, raw, parse4) {
|
|
23339
|
+
if (raw === void 0) return {};
|
|
23340
|
+
const parsed = parse4(raw);
|
|
23341
|
+
if (!parsed.success || parsed.data === void 0) return {};
|
|
24152
23342
|
return { [key]: parsed.data };
|
|
24153
23343
|
}
|
|
24154
23344
|
function isStringArray(value) {
|
|
@@ -24183,10 +23373,12 @@ function rowToDetectionDetail(row, findingsLast30d, update) {
|
|
|
24183
23373
|
category: r.category,
|
|
24184
23374
|
severity: r.severity,
|
|
24185
23375
|
matcher: parsed.data,
|
|
24186
|
-
//
|
|
24187
|
-
//
|
|
24188
|
-
//
|
|
24189
|
-
//
|
|
23376
|
+
// `appliesTo`, `postValidators` and `requiresNearby` are the rest of what
|
|
23377
|
+
// decides whether this rule fires. Carried so a consumer re-running the
|
|
23378
|
+
// rule (a preview, a tester) evaluates what the engine evaluates rather
|
|
23379
|
+
// than a matcher stripped of its guards — half the bundled catalog
|
|
23380
|
+
// carries at least one of these. `examples` and `evidence` describe the
|
|
23381
|
+
// rule and never gate a match.
|
|
24190
23382
|
//
|
|
24191
23383
|
// Enrichment is deliberately per-field and best-effort, NOT a whole-rule
|
|
24192
23384
|
// `Rule.safeParse`. Two reasons: `Rule` is a strict object pinned to
|
|
@@ -24196,18 +23388,19 @@ function rowToDetectionDetail(row, findingsLast30d, update) {
|
|
|
24196
23388
|
// test should stay exactly what it was, namely a renderable matcher. A
|
|
24197
23389
|
// field that fails validation is omitted, which reads as "not set" and is
|
|
24198
23390
|
// the same thing the consumer saw before this change.
|
|
24199
|
-
...optional2("appliesTo",
|
|
23391
|
+
...optional2("appliesTo", r.appliesTo, (v) => AppliesTo.safeParse(v)),
|
|
24200
23392
|
...optional2(
|
|
24201
23393
|
"postValidators",
|
|
24202
|
-
|
|
24203
|
-
|
|
23394
|
+
r.postValidators,
|
|
23395
|
+
(v) => PostValidatorRef.array().safeParse(v)
|
|
24204
23396
|
),
|
|
24205
|
-
...optional2("requiresNearby",
|
|
23397
|
+
...optional2("requiresNearby", r.requiresNearby, (v) => RequiresNearby.safeParse(v)),
|
|
24206
23398
|
...optional2(
|
|
24207
23399
|
"examples",
|
|
24208
|
-
|
|
24209
|
-
|
|
24210
|
-
)
|
|
23400
|
+
r.examples,
|
|
23401
|
+
(v) => isStringArray(v) ? { success: true, data: v } : { success: false }
|
|
23402
|
+
),
|
|
23403
|
+
...optional2("evidence", r.evidence, (v) => RuleEvidence.safeParse(v))
|
|
24211
23404
|
}
|
|
24212
23405
|
];
|
|
24213
23406
|
});
|
|
@@ -24900,11 +24093,14 @@ var PolicyBundle = external_exports.object({
|
|
|
24900
24093
|
ruleVersions: external_exports.record(external_exports.string(), external_exports.string()).optional(),
|
|
24901
24094
|
// Model ids (the raw `model` string a harness reports, e.g.
|
|
24902
24095
|
// `claude-opus-4-1`) the tenant has PROHIBITED. The plugin refuses to switch
|
|
24903
|
-
// a session onto one (PreModelSwitch)
|
|
24904
|
-
//
|
|
24905
|
-
//
|
|
24906
|
-
//
|
|
24907
|
-
//
|
|
24096
|
+
// a session onto one (PreModelSwitch), refuses a turn that would run on one
|
|
24097
|
+
// (UserPromptSubmit) and refuses a subagent spawn onto one (PreToolUse),
|
|
24098
|
+
// wherever the organization governs the event: everywhere on a
|
|
24099
|
+
// machine-wide attachment, and only in enrolled repositories on a scoped
|
|
24100
|
+
// one (the plugin runtime's `governanceApplies`).
|
|
24101
|
+
// Optional so an older backend — and an older on-disk cache — still
|
|
24102
|
+
// parses; consumers read `?? []`, which is the unenforced behaviour that
|
|
24103
|
+
// predates this field and the safe direction to default.
|
|
24908
24104
|
//
|
|
24909
24105
|
// Ids, not display names: the governance decision is keyed on the exact
|
|
24910
24106
|
// string the harness reports (`model_status_override.versionId` in the
|
|
@@ -25287,6 +24483,8 @@ var AttachmentScopeEntry = external_exports.object({
|
|
|
25287
24483
|
});
|
|
25288
24484
|
var AttachmentScope = external_exports.object({
|
|
25289
24485
|
endpoint: external_exports.string().min(1),
|
|
24486
|
+
tenantName: PluginWhoami.shape.tenantName.optional(),
|
|
24487
|
+
userEmail: PluginWhoami.shape.userEmail.optional(),
|
|
25290
24488
|
entries: external_exports.array(AttachmentScopeEntry)
|
|
25291
24489
|
});
|
|
25292
24490
|
var AttachmentScopeEnvelope = AttachmentScope.extend({ entries: external_exports.array(external_exports.unknown()) });
|
|
@@ -25619,6 +24817,27 @@ var ManagedSettings = external_exports.object({
|
|
|
25619
24817
|
};
|
|
25620
24818
|
}).meta({ id: "ManagedSettings" });
|
|
25621
24819
|
|
|
24820
|
+
// ../../packages/schema/src/zod/mod-policy-snapshot.ts
|
|
24821
|
+
var MOD_POLICY_SNAPSHOT_VERSION = 1;
|
|
24822
|
+
var MOD_POLICY_SNAPSHOT_MAX_BYTES = 4 * 1024 * 1024;
|
|
24823
|
+
var ModPolicySnapshot = external_exports.object({
|
|
24824
|
+
version: external_exports.literal(MOD_POLICY_SNAPSHOT_VERSION),
|
|
24825
|
+
generatedAt: external_exports.iso.datetime(),
|
|
24826
|
+
// The complete effective ruleset, as the hook's runtime scans with it: the
|
|
24827
|
+
// user's enabled installed packs (user-modified and custom packs included).
|
|
24828
|
+
// Absent means the store holds no authoritative snapshot, and the reader
|
|
24829
|
+
// scans with the packs it ships — the hook's own fallback.
|
|
24830
|
+
rules: external_exports.array(Rule).optional(),
|
|
24831
|
+
// Rule-targeted actions (first enabled policy per rule wins).
|
|
24832
|
+
ruleActions: external_exports.record(external_exports.string(), ActionTaken),
|
|
24833
|
+
// The resolved action per detection category.
|
|
24834
|
+
categoryActions: external_exports.record(external_exports.string(), ActionTaken),
|
|
24835
|
+
// Rules with an active exception grant. Honouring a grant means matching a
|
|
24836
|
+
// keyed fingerprint of the value and consuming a use, which only the hook can
|
|
24837
|
+
// do, so the mod leaves a finding of one of these rules for the hook to decide.
|
|
24838
|
+
exceptionRuleIds: external_exports.array(external_exports.string())
|
|
24839
|
+
}).meta({ id: "ModPolicySnapshot" });
|
|
24840
|
+
|
|
25622
24841
|
// ../../packages/schema/src/zod/project-files.ts
|
|
25623
24842
|
var ProjectFileInput = external_exports.object({
|
|
25624
24843
|
path: external_exports.string().min(1),
|
|
@@ -25939,7 +25158,16 @@ var AttachInput = external_exports.object({
|
|
|
25939
25158
|
// 200 matches the tenantName bound beside it in control-plane.ts; nothing
|
|
25940
25159
|
// renders a longer one usefully.
|
|
25941
25160
|
label: printable(200).optional(),
|
|
25942
|
-
accessKey: external_exports.string()
|
|
25161
|
+
accessKey: external_exports.string(),
|
|
25162
|
+
// How much of this machine the attachment is for: everything, or only the
|
|
25163
|
+
// repositories its user enrolls. Optional, so an input without it still
|
|
25164
|
+
// parses; what an absent mode means is for whatever reads it to decide, not
|
|
25165
|
+
// this shape. This member validates the VALUE rather than leaving that to the
|
|
25166
|
+
// call site, a deliberate exception to this module's shape-only rule: a shape
|
|
25167
|
+
// rejection names the field, so a value that is not a mode is refused as a bad
|
|
25168
|
+
// `mode` rather than stripped or passed on. The dashboard's attach action reads
|
|
25169
|
+
// it as the mode to attach in.
|
|
25170
|
+
mode: AttachmentMode.optional()
|
|
25943
25171
|
});
|
|
25944
25172
|
|
|
25945
25173
|
// ../../packages/schema/src/zod/triage.ts
|
|
@@ -26225,6 +25453,15 @@ function fromCaptureStatusAttributes(bag) {
|
|
|
26225
25453
|
return parsedStatus.success ? parsedStatus.data : null;
|
|
26226
25454
|
}
|
|
26227
25455
|
|
|
25456
|
+
// ../../packages/persistence/src/attached-derived.ts
|
|
25457
|
+
import { rmSync } from "fs";
|
|
25458
|
+
import { join } from "path";
|
|
25459
|
+
var POLICY_CACHE_FILENAME = "policy-cache.json";
|
|
25460
|
+
|
|
25461
|
+
// ../../packages/persistence/src/control-plane-credential.ts
|
|
25462
|
+
import { chmodSync as chmodSync2, lstatSync as lstatSync2, readFileSync, rmSync as rmSync3, statSync } from "fs";
|
|
25463
|
+
import { join as join2 } from "path";
|
|
25464
|
+
|
|
26228
25465
|
// ../../packages/persistence/src/paths.ts
|
|
26229
25466
|
import {
|
|
26230
25467
|
chmodSync,
|
|
@@ -26272,10 +25509,30 @@ function tightenFile(file2) {
|
|
|
26272
25509
|
function tightenPerms(file2) {
|
|
26273
25510
|
for (const path of [file2, ...dbSidecars(file2)]) chmodBestEffort(path, DATA_FILE_MODE);
|
|
26274
25511
|
}
|
|
25512
|
+
function writeExclusiveOwnerOnlySync(file2, data) {
|
|
25513
|
+
writeFileSync(file2, data, { mode: DATA_FILE_MODE, flag: "wx" });
|
|
25514
|
+
}
|
|
25515
|
+
function writeOwnerOnlyFileSync(file2, data) {
|
|
25516
|
+
const tmp = `${file2}.${String(process.pid)}.tmp`;
|
|
25517
|
+
try {
|
|
25518
|
+
rmSync2(tmp, { force: true });
|
|
25519
|
+
} catch {
|
|
25520
|
+
}
|
|
25521
|
+
try {
|
|
25522
|
+
writeExclusiveOwnerOnlySync(tmp, data);
|
|
25523
|
+
renameSync(tmp, file2);
|
|
25524
|
+
} finally {
|
|
25525
|
+
try {
|
|
25526
|
+
rmSync2(tmp, { force: true });
|
|
25527
|
+
} catch {
|
|
25528
|
+
}
|
|
25529
|
+
}
|
|
25530
|
+
tightenFile(file2);
|
|
25531
|
+
}
|
|
26275
25532
|
|
|
26276
25533
|
// ../../packages/persistence/src/database.ts
|
|
26277
25534
|
import { randomUUID as randomUUID11 } from "crypto";
|
|
26278
|
-
import { dirname as dirname2, join as
|
|
25535
|
+
import { dirname as dirname2, join as join8, sep } from "path";
|
|
26279
25536
|
import { DatabaseSync } from "node:sqlite";
|
|
26280
25537
|
|
|
26281
25538
|
// ../../packages/persistence/src/ids.ts
|
|
@@ -26308,6 +25565,7 @@ function captureId(sessionId, contentHash, filePath = null) {
|
|
|
26308
25565
|
canonicalIdentity(["capture", sessionId ?? NO_SESSION, contentHash, filePath ?? NO_PATH])
|
|
26309
25566
|
);
|
|
26310
25567
|
}
|
|
25568
|
+
var DOT = ".".charCodeAt(0);
|
|
26311
25569
|
|
|
26312
25570
|
// ../../packages/persistence/src/internal/snapshot.ts
|
|
26313
25571
|
import { randomUUID } from "crypto";
|
|
@@ -26635,6 +25893,25 @@ function scopeKeysParam(scopeKeys) {
|
|
|
26635
25893
|
var ROOT_SCOPE_KEY = `(SELECT session_root.scope_key
|
|
26636
25894
|
FROM audit_events AS session_root
|
|
26637
25895
|
WHERE session_root.id = COALESCE(audit_events.root_session_id, audit_events.id))`;
|
|
25896
|
+
var COUNTED_IN_SCOPE = `
|
|
25897
|
+
AND ${inScope("scope_key")}
|
|
25898
|
+
AND (event_type IN (${CAPTURE_TYPE_LIST}) OR ${inScope(ROOT_SCOPE_KEY)})`;
|
|
25899
|
+
var DRAIN_TOTALS = `SELECT
|
|
25900
|
+
SUM(CASE WHEN synced_at IS NULL AND started_at < :before THEN 1 ELSE 0 END) AS pending,
|
|
25901
|
+
SUM(CASE WHEN synced_at > 0 THEN 1 ELSE 0 END) AS sent,
|
|
25902
|
+
SUM(CASE WHEN synced_at = ${String(SKIPPED)}
|
|
25903
|
+
AND (sync_failure IS NULL OR sync_failure = 'payload_invalid')
|
|
25904
|
+
THEN 1 ELSE 0 END) AS skipped,
|
|
25905
|
+
SUM(CASE WHEN synced_at = ${String(SKIPPED)}
|
|
25906
|
+
AND sync_failure = 'deployment_refused' THEN 1 ELSE 0 END) AS refused,
|
|
25907
|
+
SUM(CASE WHEN synced_at = ${String(SKIPPED)}
|
|
25908
|
+
AND sync_failure = 'detached_undelivered' THEN 1 ELSE 0 END) AS detached
|
|
25909
|
+
FROM audit_events
|
|
25910
|
+
WHERE event_type IN (${TYPE_LIST})`;
|
|
25911
|
+
var CAPTURE_SKIPS = `SELECT COUNT(*) AS skipped
|
|
25912
|
+
FROM audit_events
|
|
25913
|
+
WHERE synced_at = ${String(SKIPPED)}
|
|
25914
|
+
AND event_type IN (${CAPTURE_TYPE_LIST})`;
|
|
26638
25915
|
var ROW_COLUMNS = `id,
|
|
26639
25916
|
parent_id AS parentId,
|
|
26640
25917
|
root_session_id AS rootSessionId,
|
|
@@ -26710,7 +25987,7 @@ var SqliteHistorySyncRepository = class {
|
|
|
26710
25987
|
);
|
|
26711
25988
|
this.scopedCaptureRowsStmt = db.prepare(
|
|
26712
25989
|
`SELECT ${ROW_COLUMNS}
|
|
26713
|
-
FROM audit_events
|
|
25990
|
+
FROM audit_events INDEXED BY idx_audit_scope_owed
|
|
26714
25991
|
WHERE synced_at IS NULL
|
|
26715
25992
|
AND sync_claimed_at IS NULL
|
|
26716
25993
|
AND outbox_owed = 1
|
|
@@ -26763,40 +26040,28 @@ var SqliteHistorySyncRepository = class {
|
|
|
26763
26040
|
);
|
|
26764
26041
|
this.partitionStmt = db.prepare(`SELECT${PARTITION_BUCKETS}
|
|
26765
26042
|
FROM audit_events${COUNTED_SCOPE}`);
|
|
26043
|
+
this.scopedPartitionStmt = db.prepare(`SELECT${PARTITION_BUCKETS}
|
|
26044
|
+
FROM audit_events${COUNTED_SCOPE}${COUNTED_IN_SCOPE}`);
|
|
26766
26045
|
this.partitionByKindStmt = db.prepare(
|
|
26767
26046
|
`SELECT event_type AS kind,${PARTITION_BUCKETS}
|
|
26768
26047
|
FROM audit_events INDEXED BY idx_audit_events_sync${COUNTED_SCOPE}
|
|
26769
26048
|
GROUP BY event_type`
|
|
26770
26049
|
);
|
|
26771
|
-
this.
|
|
26772
|
-
`SELECT
|
|
26773
|
-
|
|
26774
|
-
|
|
26775
|
-
SUM(CASE WHEN synced_at = ${String(SKIPPED)}
|
|
26776
|
-
AND (sync_failure IS NULL OR sync_failure = 'payload_invalid')
|
|
26777
|
-
THEN 1 ELSE 0 END) AS skipped,
|
|
26778
|
-
SUM(CASE WHEN synced_at = ${String(SKIPPED)}
|
|
26779
|
-
AND sync_failure = 'deployment_refused' THEN 1 ELSE 0 END) AS refused,
|
|
26780
|
-
SUM(CASE WHEN synced_at = ${String(SKIPPED)}
|
|
26781
|
-
AND sync_failure = 'detached_undelivered' THEN 1 ELSE 0 END) AS detached
|
|
26782
|
-
FROM audit_events
|
|
26783
|
-
WHERE event_type IN (${TYPE_LIST})`
|
|
26050
|
+
this.scopedPartitionByKindStmt = db.prepare(
|
|
26051
|
+
`SELECT event_type AS kind,${PARTITION_BUCKETS}
|
|
26052
|
+
FROM audit_events INDEXED BY idx_audit_events_sync${COUNTED_SCOPE}${COUNTED_IN_SCOPE}
|
|
26053
|
+
GROUP BY event_type`
|
|
26784
26054
|
);
|
|
26785
|
-
this.
|
|
26786
|
-
|
|
26787
|
-
|
|
26788
|
-
|
|
26789
|
-
|
|
26790
|
-
|
|
26791
|
-
|
|
26792
|
-
|
|
26793
|
-
|
|
26794
|
-
|
|
26795
|
-
// frees.
|
|
26796
|
-
`SELECT COUNT(*) AS skipped
|
|
26797
|
-
FROM audit_events
|
|
26798
|
-
WHERE synced_at = ${String(SKIPPED)}
|
|
26799
|
-
AND event_type IN (${CAPTURE_TYPE_LIST})`
|
|
26055
|
+
this.countsStmt = db.prepare(DRAIN_TOTALS);
|
|
26056
|
+
this.scopedCountsStmt = db.prepare(
|
|
26057
|
+
`${DRAIN_TOTALS}
|
|
26058
|
+
AND ${inScope("scope_key")}
|
|
26059
|
+
AND ${inScope(ROOT_SCOPE_KEY)}`
|
|
26060
|
+
);
|
|
26061
|
+
this.captureSkipCountStmt = db.prepare(CAPTURE_SKIPS);
|
|
26062
|
+
this.scopedCaptureSkipCountStmt = db.prepare(
|
|
26063
|
+
`${CAPTURE_SKIPS}
|
|
26064
|
+
AND ${inScope("scope_key")}`
|
|
26800
26065
|
);
|
|
26801
26066
|
this.fingerprintStmt = db.prepare(
|
|
26802
26067
|
`SELECT endpoint_fingerprint AS fingerprint, backlog_before AS backlogBefore
|
|
@@ -26910,6 +26175,10 @@ var SqliteHistorySyncRepository = class {
|
|
|
26910
26175
|
scopedCaptureRowsStmt;
|
|
26911
26176
|
scopedCaptureBacklogOwedStmt;
|
|
26912
26177
|
markScopeCapturesOwedStmt;
|
|
26178
|
+
scopedPartitionStmt;
|
|
26179
|
+
scopedPartitionByKindStmt;
|
|
26180
|
+
scopedCountsStmt;
|
|
26181
|
+
scopedCaptureSkipCountStmt;
|
|
26913
26182
|
/**
|
|
26914
26183
|
* The masked detections recorded against one tool call.
|
|
26915
26184
|
*
|
|
@@ -27131,7 +26400,29 @@ var SqliteHistorySyncRepository = class {
|
|
|
27131
26400
|
* in" — and a machine that has never attached has no boundary to pass, so
|
|
27132
26401
|
* requiring one would force a caller to invent one and report the whole store
|
|
27133
26402
|
* as queued.
|
|
26403
|
+
*
|
|
26404
|
+
* `scopeKeys` is a scoped attachment's filter: every bucket then counts only
|
|
26405
|
+
* the rows that pass the drain's reachability rule for that scope
|
|
26406
|
+
* (COUNTED_IN_SCOPE, which also names the one kind of row it counts that the
|
|
26407
|
+
* drain never offers), so a personal repository's rows are in none of them.
|
|
26408
|
+
* Omitted, this runs the machine statement, unchanged; an empty list counts
|
|
26409
|
+
* nothing.
|
|
27134
26410
|
*/
|
|
26411
|
+
partition(scopeKeys) {
|
|
26412
|
+
const row = getRow(
|
|
26413
|
+
scopeKeys === void 0 ? this.partitionStmt : this.scopedPartitionStmt,
|
|
26414
|
+
scopeKeys === void 0 ? {} : { scopeKeys: scopeKeysParam(scopeKeys) }
|
|
26415
|
+
);
|
|
26416
|
+
return {
|
|
26417
|
+
queued: row?.queued ?? 0,
|
|
26418
|
+
inProgress: row?.inProgress ?? 0,
|
|
26419
|
+
synced: row?.synced ?? 0,
|
|
26420
|
+
failed: row?.failed ?? 0,
|
|
26421
|
+
refused: row?.refused ?? 0,
|
|
26422
|
+
detached: row?.detached ?? 0,
|
|
26423
|
+
total: row?.total ?? 0
|
|
26424
|
+
};
|
|
26425
|
+
}
|
|
27135
26426
|
/**
|
|
27136
26427
|
* The same partition, one row per kind that a lane carries.
|
|
27137
26428
|
*
|
|
@@ -27141,11 +26432,14 @@ var SqliteHistorySyncRepository = class {
|
|
|
27141
26432
|
* rendering a fixed list of kinds must therefore treat a missing one as "no
|
|
27142
26433
|
* rows", never as "zero sent"; the two look identical in a bar and mean
|
|
27143
26434
|
* different things.
|
|
26435
|
+
*
|
|
26436
|
+
* `scopeKeys` scopes it with the clause `partition` uses, so the per-kind rows
|
|
26437
|
+
* still sum to the scoped aggregate. An empty list returns no rows.
|
|
27144
26438
|
*/
|
|
27145
|
-
partitionByKind() {
|
|
26439
|
+
partitionByKind(scopeKeys) {
|
|
27146
26440
|
return allRows(
|
|
27147
|
-
this.partitionByKindStmt,
|
|
27148
|
-
{}
|
|
26441
|
+
scopeKeys === void 0 ? this.partitionByKindStmt : this.scopedPartitionByKindStmt,
|
|
26442
|
+
scopeKeys === void 0 ? {} : { scopeKeys: scopeKeysParam(scopeKeys) }
|
|
27149
26443
|
).map((row) => ({
|
|
27150
26444
|
kind: row.kind,
|
|
27151
26445
|
queued: row.queued ?? 0,
|
|
@@ -27157,22 +26451,25 @@ var SqliteHistorySyncRepository = class {
|
|
|
27157
26451
|
total: row.total ?? 0
|
|
27158
26452
|
}));
|
|
27159
26453
|
}
|
|
27160
|
-
|
|
27161
|
-
|
|
27162
|
-
|
|
27163
|
-
|
|
27164
|
-
|
|
27165
|
-
|
|
27166
|
-
|
|
27167
|
-
|
|
27168
|
-
|
|
27169
|
-
|
|
27170
|
-
|
|
27171
|
-
|
|
27172
|
-
|
|
27173
|
-
|
|
27174
|
-
|
|
27175
|
-
|
|
26454
|
+
/**
|
|
26455
|
+
* The drain's totals. `pending` counts only what is inside the backlog; sent
|
|
26456
|
+
* and skipped are totals.
|
|
26457
|
+
*
|
|
26458
|
+
* `scopeKeys` is a scoped attachment's filter, and it scopes every figure,
|
|
26459
|
+
* `capturesSkipped` included: a structural row is counted only when its own
|
|
26460
|
+
* key and its session root's key are among them, a capture when its own key
|
|
26461
|
+
* is. So `pending` is exactly what pendingSessions and pendingRows page out
|
|
26462
|
+
* under the same keys and boundary. Omitted, this runs the machine
|
|
26463
|
+
* statements, unchanged; an empty list counts nothing.
|
|
26464
|
+
*/
|
|
26465
|
+
counts(before, scopeKeys) {
|
|
26466
|
+
const row = getRow(
|
|
26467
|
+
scopeKeys === void 0 ? this.countsStmt : this.scopedCountsStmt,
|
|
26468
|
+
scopeKeys === void 0 ? { before } : { before, scopeKeys: scopeKeysParam(scopeKeys) }
|
|
26469
|
+
);
|
|
26470
|
+
const captures = scopeKeys === void 0 ? getRow(this.captureSkipCountStmt) : getRow(this.scopedCaptureSkipCountStmt, {
|
|
26471
|
+
scopeKeys: scopeKeysParam(scopeKeys)
|
|
26472
|
+
});
|
|
27176
26473
|
return {
|
|
27177
26474
|
pending: row?.pending ?? 0,
|
|
27178
26475
|
sent: row?.sent ?? 0,
|
|
@@ -27424,6 +26721,7 @@ function applyMigrations(db, file2, options = {}) {
|
|
|
27424
26721
|
}
|
|
27425
26722
|
ensureSyncedAtColumn(db, "audit_events");
|
|
27426
26723
|
ensureScopeKeyColumn(db);
|
|
26724
|
+
ensureScopeOwedIndex(db);
|
|
27427
26725
|
ensureScanLedgerTable(db);
|
|
27428
26726
|
ensureHistorySyncTable(db);
|
|
27429
26727
|
ensureBlockedDetectionsTable(db);
|
|
@@ -27864,14 +27162,48 @@ function ensureScopeKeyColumn(db) {
|
|
|
27864
27162
|
function hasScopeKeyColumn(db) {
|
|
27865
27163
|
return columnNames(db, "audit_events", { includeGenerated: true }).includes("scope_key");
|
|
27866
27164
|
}
|
|
27165
|
+
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";
|
|
27166
|
+
function ensureScopeOwedIndex(db) {
|
|
27167
|
+
if (!schemaObjectExists(db, "table", "audit_events")) return;
|
|
27168
|
+
const columns = columnNames(db, "audit_events", { includeGenerated: true });
|
|
27169
|
+
const complete = ["scope_key", "outbox_owed", "synced_at"].every((c) => columns.includes(c));
|
|
27170
|
+
if (!complete) return;
|
|
27171
|
+
db.exec(SCOPE_OWED_INDEX_DDL);
|
|
27172
|
+
}
|
|
27867
27173
|
function ensureScanLedgerTable(db) {
|
|
27868
27174
|
db.exec(`CREATE TABLE IF NOT EXISTS scan_ledger (
|
|
27869
27175
|
path TEXT PRIMARY KEY,
|
|
27870
27176
|
mtime TEXT NOT NULL,
|
|
27871
27177
|
content_hash TEXT NOT NULL,
|
|
27872
27178
|
ruleset_hash TEXT NOT NULL,
|
|
27873
|
-
scanned_at INTEGER NOT NULL
|
|
27179
|
+
scanned_at INTEGER NOT NULL,
|
|
27180
|
+
scope_key TEXT,
|
|
27181
|
+
scope_root TEXT
|
|
27874
27182
|
)`);
|
|
27183
|
+
ensureScanLedgerScopeKeyColumn(db);
|
|
27184
|
+
ensureScanLedgerScopeRootColumn(db);
|
|
27185
|
+
}
|
|
27186
|
+
var SCAN_LEDGER_SCOPE_KEY_DDL = "ALTER TABLE scan_ledger ADD COLUMN scope_key TEXT";
|
|
27187
|
+
var SCAN_LEDGER_SCOPE_ROOT_DDL = "ALTER TABLE scan_ledger ADD COLUMN scope_root TEXT";
|
|
27188
|
+
function ensureScanLedgerScopeKeyColumn(db) {
|
|
27189
|
+
ensureScanLedgerColumn(db, "scope_key", SCAN_LEDGER_SCOPE_KEY_DDL);
|
|
27190
|
+
}
|
|
27191
|
+
function ensureScanLedgerScopeRootColumn(db) {
|
|
27192
|
+
ensureScanLedgerColumn(db, "scope_root", SCAN_LEDGER_SCOPE_ROOT_DDL);
|
|
27193
|
+
}
|
|
27194
|
+
function ensureScanLedgerColumn(db, column, ddl) {
|
|
27195
|
+
if (!schemaObjectExists(db, "table", "scan_ledger")) return;
|
|
27196
|
+
if (hasScanLedgerColumn(db, column)) return;
|
|
27197
|
+
withTransaction(
|
|
27198
|
+
db,
|
|
27199
|
+
() => {
|
|
27200
|
+
if (!hasScanLedgerColumn(db, column)) db.exec(ddl);
|
|
27201
|
+
},
|
|
27202
|
+
"IMMEDIATE"
|
|
27203
|
+
);
|
|
27204
|
+
}
|
|
27205
|
+
function hasScanLedgerColumn(db, column) {
|
|
27206
|
+
return columnNames(db, "scan_ledger").includes(column);
|
|
27875
27207
|
}
|
|
27876
27208
|
function ensureHistorySyncTable(db) {
|
|
27877
27209
|
db.exec(`CREATE TABLE IF NOT EXISTS history_sync (
|
|
@@ -27922,6 +27254,106 @@ function ensureRuleProbeCacheTable(db) {
|
|
|
27922
27254
|
)`);
|
|
27923
27255
|
}
|
|
27924
27256
|
|
|
27257
|
+
// ../../packages/persistence/src/mod-policy-snapshot.ts
|
|
27258
|
+
import { createHash as createHash2 } from "crypto";
|
|
27259
|
+
import { readFileSync as readFileSync2 } from "fs";
|
|
27260
|
+
import { join as join4 } from "path";
|
|
27261
|
+
var MOD_POLICY_SNAPSHOT_FILENAME = "mod-policy.json";
|
|
27262
|
+
function modPolicySnapshotPath(dataDir2) {
|
|
27263
|
+
return join4(dataDir2, MOD_POLICY_SNAPSHOT_FILENAME);
|
|
27264
|
+
}
|
|
27265
|
+
function buildModPolicySnapshot(input2, generatedAt = /* @__PURE__ */ new Date()) {
|
|
27266
|
+
const byRule = /* @__PURE__ */ new Map();
|
|
27267
|
+
const byCategory = /* @__PURE__ */ new Map();
|
|
27268
|
+
for (const policy of input2.policies) {
|
|
27269
|
+
if (!policy.enabled) continue;
|
|
27270
|
+
if ("ruleId" in policy.target) {
|
|
27271
|
+
if (!byRule.has(policy.target.ruleId)) byRule.set(policy.target.ruleId, policy.action);
|
|
27272
|
+
} else if (!byCategory.has(policy.target.category)) {
|
|
27273
|
+
byCategory.set(policy.target.category, policy.action);
|
|
27274
|
+
}
|
|
27275
|
+
}
|
|
27276
|
+
const categoryActions = {};
|
|
27277
|
+
for (const category of DetectionCategory.options) {
|
|
27278
|
+
categoryActions[category] = byCategory.get(category) ?? DEFAULT_ACTIONS[category];
|
|
27279
|
+
}
|
|
27280
|
+
return {
|
|
27281
|
+
version: MOD_POLICY_SNAPSHOT_VERSION,
|
|
27282
|
+
generatedAt: generatedAt.toISOString(),
|
|
27283
|
+
// `examples` is documentation the mod never reads, and a custom pack's are
|
|
27284
|
+
// whatever its author pasted in, so they stay behind.
|
|
27285
|
+
...input2.rules !== void 0 ? { rules: input2.rules.map(withoutExamples) } : {},
|
|
27286
|
+
ruleActions: Object.fromEntries(byRule),
|
|
27287
|
+
categoryActions,
|
|
27288
|
+
exceptionRuleIds: [...new Set(input2.exceptionRuleIds)].sort()
|
|
27289
|
+
};
|
|
27290
|
+
}
|
|
27291
|
+
function assignedRuleActionPolicies(installed) {
|
|
27292
|
+
const out = [];
|
|
27293
|
+
for (const [ruleId, action] of installed.ruleActions) {
|
|
27294
|
+
if (installed.assignedRules.has(ruleId))
|
|
27295
|
+
out.push({ target: { ruleId }, action, enabled: true });
|
|
27296
|
+
}
|
|
27297
|
+
return out;
|
|
27298
|
+
}
|
|
27299
|
+
function withoutExamples(rule) {
|
|
27300
|
+
const copy = { ...rule };
|
|
27301
|
+
delete copy.examples;
|
|
27302
|
+
return copy;
|
|
27303
|
+
}
|
|
27304
|
+
function sameContent(a, b) {
|
|
27305
|
+
return JSON.stringify({ ...a, generatedAt: "" }) === JSON.stringify({ ...b, generatedAt: "" });
|
|
27306
|
+
}
|
|
27307
|
+
function readModPolicySnapshot(dataDir2) {
|
|
27308
|
+
try {
|
|
27309
|
+
const text = readFileSync2(modPolicySnapshotPath(dataDir2), "utf8");
|
|
27310
|
+
if (text.length > MOD_POLICY_SNAPSHOT_MAX_BYTES) return null;
|
|
27311
|
+
const parsed = ModPolicySnapshot.safeParse(JSON.parse(text));
|
|
27312
|
+
return parsed.success ? parsed.data : null;
|
|
27313
|
+
} catch {
|
|
27314
|
+
return null;
|
|
27315
|
+
}
|
|
27316
|
+
}
|
|
27317
|
+
function writeModPolicySnapshot(dataDir2, snapshot) {
|
|
27318
|
+
const text = JSON.stringify(snapshot);
|
|
27319
|
+
if (Buffer.byteLength(text) > MOD_POLICY_SNAPSHOT_MAX_BYTES) return false;
|
|
27320
|
+
const existing = readModPolicySnapshot(dataDir2);
|
|
27321
|
+
if (existing !== null && sameContent(existing, snapshot)) return false;
|
|
27322
|
+
ensureDataDirSync(dataDir2);
|
|
27323
|
+
writeOwnerOnlyFileSync(modPolicySnapshotPath(dataDir2), text);
|
|
27324
|
+
return true;
|
|
27325
|
+
}
|
|
27326
|
+
function regexProbeKey(matcher) {
|
|
27327
|
+
return createHash2("sha256").update(`${matcher.pattern} ${matcher.flags}`).digest("hex");
|
|
27328
|
+
}
|
|
27329
|
+
function vetRulesForMod(rules, sources, previouslyVetted = /* @__PURE__ */ new Set()) {
|
|
27330
|
+
const bundled = new Set(sources.bundledRegexMatchers().map(regexProbeKey));
|
|
27331
|
+
return rules.filter((rule) => {
|
|
27332
|
+
if (rule.matcher.type !== "regex") return true;
|
|
27333
|
+
const key = regexProbeKey(rule.matcher);
|
|
27334
|
+
const verdict = sources.probeVerdict(key);
|
|
27335
|
+
if (verdict === "quarantined") return false;
|
|
27336
|
+
return verdict === "safe" || bundled.has(key) || previouslyVetted.has(key);
|
|
27337
|
+
});
|
|
27338
|
+
}
|
|
27339
|
+
function modPolicyInputFromStore(sources, previouslyVetted = /* @__PURE__ */ new Set()) {
|
|
27340
|
+
const policies = sources.readPolicies();
|
|
27341
|
+
const snapshot = sources.installedRuleset();
|
|
27342
|
+
const usable = snapshot.installedPacks > 0 && (snapshot.enabledPacks === 0 || snapshot.invalidRules === 0 && snapshot.rules.length > 0);
|
|
27343
|
+
const empty = snapshot.installedPacks > 0 && snapshot.enabledPacks === 0;
|
|
27344
|
+
return {
|
|
27345
|
+
...usable ? { rules: empty ? [] : vetRulesForMod(snapshot.rules, sources, previouslyVetted) } : {},
|
|
27346
|
+
policies: [...policies, ...usable && !empty ? assignedRuleActionPolicies(snapshot) : []],
|
|
27347
|
+
exceptionRuleIds: sources.activeExceptionRuleIds()
|
|
27348
|
+
};
|
|
27349
|
+
}
|
|
27350
|
+
function refreshModPolicySnapshot(dataDir2, sources) {
|
|
27351
|
+
try {
|
|
27352
|
+
writeModPolicySnapshot(dataDir2, buildModPolicySnapshot(modPolicyInputFromStore(sources)));
|
|
27353
|
+
} catch {
|
|
27354
|
+
}
|
|
27355
|
+
}
|
|
27356
|
+
|
|
27925
27357
|
// ../../packages/persistence/src/internal/json.ts
|
|
27926
27358
|
function safeJson(s, fallback) {
|
|
27927
27359
|
if (s == null) return fallback;
|
|
@@ -28096,6 +27528,11 @@ var TIMELINE_COLUMNS = `
|
|
|
28096
27528
|
json_extract(attributes, '$.targetId') AS target_id,
|
|
28097
27529
|
json_extract(attributes, '$.internal') AS internal,
|
|
28098
27530
|
json_extract(attributes, '$.flagged') AS flagged`;
|
|
27531
|
+
var CALL_PROMPT_TOKENS = `(coalesce(input_tokens, 0) + coalesce(cache_read_input_tokens, 0)
|
|
27532
|
+
+ coalesce(ephemeral_1h_input_tokens, 0) + coalesce(ephemeral_5m_input_tokens, 0))`;
|
|
27533
|
+
var CALL_BAND = LONG_CONTEXT_THRESHOLDS.length === 0 ? "0" : LONG_CONTEXT_THRESHOLDS.map((t) => `(${CALL_PROMPT_TOKENS} > ${String(Math.trunc(t))})`).join(
|
|
27534
|
+
" + "
|
|
27535
|
+
);
|
|
28099
27536
|
var LLM_USAGE_SELECT = `
|
|
28100
27537
|
SELECT root_session_id AS sessionId,
|
|
28101
27538
|
provider,
|
|
@@ -28107,9 +27544,10 @@ var LLM_USAGE_SELECT = `
|
|
|
28107
27544
|
coalesce(sum(cache_read_input_tokens), 0) AS cacheReadTokens,
|
|
28108
27545
|
coalesce(sum(ephemeral_1h_input_tokens), 0) AS ephemeral1hTokens,
|
|
28109
27546
|
coalesce(sum(ephemeral_5m_input_tokens), 0) AS ephemeral5mTokens,
|
|
28110
|
-
coalesce(sum(web_search_requests), 0) AS webSearchRequests
|
|
27547
|
+
coalesce(sum(web_search_requests), 0) AS webSearchRequests,
|
|
27548
|
+
coalesce(max(${CALL_PROMPT_TOKENS}), 0) AS promptTokens`;
|
|
28111
27549
|
var LLM_USAGE_SCOPE = `event_type = 'llm_call' AND attributes IS NOT NULL AND root_session_id IS NOT NULL`;
|
|
28112
|
-
var LLM_USAGE_GROUP = `GROUP BY root_session_id, provider, model, service_tier`;
|
|
27550
|
+
var LLM_USAGE_GROUP = `GROUP BY root_session_id, provider, model, service_tier, ${CALL_BAND}`;
|
|
28113
27551
|
function usageLeaves(rows) {
|
|
28114
27552
|
return rows.map((row) => {
|
|
28115
27553
|
const attributes = {
|
|
@@ -28124,7 +27562,7 @@ function usageLeaves(rows) {
|
|
|
28124
27562
|
if (row.provider !== null) attributes.provider = row.provider;
|
|
28125
27563
|
if (row.model !== null) attributes.model = row.model;
|
|
28126
27564
|
if (row.serviceTier !== null) attributes.service_tier = row.serviceTier;
|
|
28127
|
-
return { sessionId: row.sessionId, attributes };
|
|
27565
|
+
return { sessionId: row.sessionId, attributes, promptTokens: row.promptTokens };
|
|
28128
27566
|
});
|
|
28129
27567
|
}
|
|
28130
27568
|
var SESSION_ROOT = `event_type = 'session'`;
|
|
@@ -29458,9 +28896,10 @@ var ACTIVE_REVEAL_GRANT_PREDICATE = `capability = 'reveal_to_model'
|
|
|
29458
28896
|
AND conditions IS NULL
|
|
29459
28897
|
AND ${ACTIVE_PREDICATE}`;
|
|
29460
28898
|
var SqliteExceptionsRepository = class {
|
|
29461
|
-
constructor(db, now = () => Date.now()) {
|
|
28899
|
+
constructor(db, now = () => Date.now(), onChange = () => void 0) {
|
|
29462
28900
|
this.db = db;
|
|
29463
28901
|
this.now = now;
|
|
28902
|
+
this.onChange = onChange;
|
|
29464
28903
|
this.consumeStmt = db.prepare(
|
|
29465
28904
|
`UPDATE exceptions
|
|
29466
28905
|
SET use_count = use_count + 1, last_used_at = :now, updated_at = :now
|
|
@@ -29479,6 +28918,7 @@ var SqliteExceptionsRepository = class {
|
|
|
29479
28918
|
}
|
|
29480
28919
|
db;
|
|
29481
28920
|
now;
|
|
28921
|
+
onChange;
|
|
29482
28922
|
consumeStmt;
|
|
29483
28923
|
insertBlockedStmt;
|
|
29484
28924
|
sweepBlockedStmt;
|
|
@@ -29494,7 +28934,9 @@ var SqliteExceptionsRepository = class {
|
|
|
29494
28934
|
*/
|
|
29495
28935
|
create(input2) {
|
|
29496
28936
|
try {
|
|
29497
|
-
|
|
28937
|
+
const created = this.createSync(input2);
|
|
28938
|
+
this.onChange();
|
|
28939
|
+
return Promise.resolve(created);
|
|
29498
28940
|
} catch (err) {
|
|
29499
28941
|
return Promise.reject(err instanceof Error ? err : new Error(String(err)));
|
|
29500
28942
|
}
|
|
@@ -29625,6 +29067,7 @@ var SqliteExceptionsRepository = class {
|
|
|
29625
29067
|
SET revoked_at = :now, revoked_by = :revokedBy, revoke_reason = :reason, updated_at = :now
|
|
29626
29068
|
WHERE id = :id AND revoked_at IS NULL`
|
|
29627
29069
|
).run({ id, revokedBy, reason: reason ?? null, now });
|
|
29070
|
+
if (Number(result.changes) === 1) this.onChange();
|
|
29628
29071
|
return Promise.resolve(Number(result.changes) === 1);
|
|
29629
29072
|
}
|
|
29630
29073
|
/**
|
|
@@ -29637,6 +29080,15 @@ var SqliteExceptionsRepository = class {
|
|
|
29637
29080
|
const result = this.consumeStmt.run({ id, now });
|
|
29638
29081
|
return Promise.resolve(Number(result.changes) === 1);
|
|
29639
29082
|
}
|
|
29083
|
+
/** The rule ids with at least one active grant, under any key version. */
|
|
29084
|
+
activeRuleIds(now = this.now()) {
|
|
29085
|
+
return allRows(
|
|
29086
|
+
this.db.prepare(
|
|
29087
|
+
`SELECT DISTINCT rule_id AS ruleId FROM exceptions WHERE ${ACTIVE_PREDICATE}`
|
|
29088
|
+
),
|
|
29089
|
+
{ now }
|
|
29090
|
+
).map((row) => row.ruleId);
|
|
29091
|
+
}
|
|
29640
29092
|
/**
|
|
29641
29093
|
* The evaluation subset of every active grant under one fingerprint key
|
|
29642
29094
|
* version — what rides the policy bundle to the hook. Grants written under
|
|
@@ -30760,28 +30212,28 @@ var SqliteInspectionFindingsRepository = class {
|
|
|
30760
30212
|
};
|
|
30761
30213
|
|
|
30762
30214
|
// ../../packages/persistence/src/repositories/installed-packs.ts
|
|
30763
|
-
import { createHash as
|
|
30215
|
+
import { createHash as createHash3, randomUUID as randomUUID4 } from "crypto";
|
|
30764
30216
|
|
|
30765
30217
|
// ../../packages/persistence/src/policy-floor.ts
|
|
30766
|
-
import { readFileSync as
|
|
30767
|
-
import { join as
|
|
30218
|
+
import { readFileSync as readFileSync6 } from "fs";
|
|
30219
|
+
import { join as join7 } from "path";
|
|
30768
30220
|
|
|
30769
30221
|
// ../../packages/persistence/src/local-layout.ts
|
|
30770
30222
|
import { renameSync as renameSync3 } from "fs";
|
|
30771
30223
|
import { mkdir } from "fs/promises";
|
|
30772
30224
|
import { homedir } from "os";
|
|
30773
|
-
import { join as
|
|
30225
|
+
import { join as join5 } from "path";
|
|
30774
30226
|
function defaultDataDir() {
|
|
30775
|
-
return
|
|
30227
|
+
return join5(homedir(), ".aka");
|
|
30776
30228
|
}
|
|
30777
30229
|
function settingsDir(base = defaultDataDir()) {
|
|
30778
|
-
return
|
|
30230
|
+
return join5(base, "settings");
|
|
30779
30231
|
}
|
|
30780
30232
|
function dataDir(base = defaultDataDir()) {
|
|
30781
|
-
return
|
|
30233
|
+
return join5(base, "data");
|
|
30782
30234
|
}
|
|
30783
30235
|
function dbPath(base = defaultDataDir()) {
|
|
30784
|
-
return
|
|
30236
|
+
return join5(dataDir(base), "aka.db");
|
|
30785
30237
|
}
|
|
30786
30238
|
function ensureLayoutDirSync(dir = defaultDataDir()) {
|
|
30787
30239
|
ensureDataDirSync(dir);
|
|
@@ -30794,8 +30246,8 @@ function migrateLegacyLayout(base = defaultDataDir()) {
|
|
|
30794
30246
|
for (const { name, dest } of moves) {
|
|
30795
30247
|
try {
|
|
30796
30248
|
ensureDataDirSync(dest);
|
|
30797
|
-
const moved =
|
|
30798
|
-
renameSync3(
|
|
30249
|
+
const moved = join5(dest, name);
|
|
30250
|
+
renameSync3(join5(base, name), moved);
|
|
30799
30251
|
tightenFile(moved);
|
|
30800
30252
|
} catch {
|
|
30801
30253
|
}
|
|
@@ -30803,8 +30255,8 @@ function migrateLegacyLayout(base = defaultDataDir()) {
|
|
|
30803
30255
|
}
|
|
30804
30256
|
|
|
30805
30257
|
// ../../packages/persistence/src/settings.ts
|
|
30806
|
-
import { readFileSync as
|
|
30807
|
-
import { join as
|
|
30258
|
+
import { readFileSync as readFileSync5 } from "fs";
|
|
30259
|
+
import { join as join6 } from "path";
|
|
30808
30260
|
|
|
30809
30261
|
// ../../packages/persistence/src/file-lock.ts
|
|
30810
30262
|
import { randomUUID as randomUUID3 } from "crypto";
|
|
@@ -30812,7 +30264,7 @@ import {
|
|
|
30812
30264
|
closeSync,
|
|
30813
30265
|
existsSync as existsSync2,
|
|
30814
30266
|
openSync,
|
|
30815
|
-
readFileSync as
|
|
30267
|
+
readFileSync as readFileSync3,
|
|
30816
30268
|
rmSync as rmSync5,
|
|
30817
30269
|
statSync as statSync3,
|
|
30818
30270
|
writeFileSync as writeFileSync2
|
|
@@ -30821,16 +30273,16 @@ import { hostname as hostname3 } from "os";
|
|
|
30821
30273
|
var PARK = new Int32Array(new SharedArrayBuffer(4));
|
|
30822
30274
|
|
|
30823
30275
|
// ../../packages/persistence/src/managed-settings.ts
|
|
30824
|
-
import { readFileSync as
|
|
30276
|
+
import { readFileSync as readFileSync4 } from "fs";
|
|
30825
30277
|
import { posix, win32 } from "path";
|
|
30826
|
-
function managedSettingsPaths(
|
|
30827
|
-
if (
|
|
30278
|
+
function managedSettingsPaths(platform = process.platform) {
|
|
30279
|
+
if (platform === "darwin") {
|
|
30828
30280
|
return [
|
|
30829
30281
|
posix.join("/Library", "Application Support", "AKASecurity", MANAGED_SETTINGS_FILENAME),
|
|
30830
30282
|
posix.join("/Library", "Managed Preferences", MANAGED_SETTINGS_FILENAME)
|
|
30831
30283
|
];
|
|
30832
30284
|
}
|
|
30833
|
-
if (
|
|
30285
|
+
if (platform === "win32") {
|
|
30834
30286
|
return [win32.join("C:\\", "ProgramData", "AKASecurity", MANAGED_SETTINGS_FILENAME)];
|
|
30835
30287
|
}
|
|
30836
30288
|
return [posix.join("/etc", "aka", MANAGED_SETTINGS_FILENAME)];
|
|
@@ -30840,7 +30292,7 @@ function readManagedSettings(paths = testOnlyManagedPaths ?? managedSettingsPath
|
|
|
30840
30292
|
for (const path of paths) {
|
|
30841
30293
|
let text;
|
|
30842
30294
|
try {
|
|
30843
|
-
text =
|
|
30295
|
+
text = readFileSync4(path, "utf8");
|
|
30844
30296
|
} catch {
|
|
30845
30297
|
continue;
|
|
30846
30298
|
}
|
|
@@ -30894,7 +30346,7 @@ function readWorkspaceSettings(base = defaultDataDir()) {
|
|
|
30894
30346
|
return overlayManagedSettings(readUserSettings(base), readManagedSettings());
|
|
30895
30347
|
}
|
|
30896
30348
|
function readUserSettings(base) {
|
|
30897
|
-
const record2 = readJson(
|
|
30349
|
+
const record2 = readJson(join6(settingsDir(base), SETTINGS_FILENAME));
|
|
30898
30350
|
if (!record2) return defaultWorkspaceSettings();
|
|
30899
30351
|
try {
|
|
30900
30352
|
return WorkspaceSettings.parse(record2);
|
|
@@ -30905,7 +30357,7 @@ function readUserSettings(base) {
|
|
|
30905
30357
|
function readJson(file2) {
|
|
30906
30358
|
let text;
|
|
30907
30359
|
try {
|
|
30908
|
-
text =
|
|
30360
|
+
text = readFileSync5(file2, "utf8");
|
|
30909
30361
|
} catch {
|
|
30910
30362
|
return null;
|
|
30911
30363
|
}
|
|
@@ -30945,7 +30397,7 @@ var PolicyFloorError = class extends Error {
|
|
|
30945
30397
|
};
|
|
30946
30398
|
function readCachedPolicyBundle(base = defaultDataDir()) {
|
|
30947
30399
|
try {
|
|
30948
|
-
const raw =
|
|
30400
|
+
const raw = readFileSync6(join7(dataDir(base), POLICY_CACHE_FILENAME), "utf8");
|
|
30949
30401
|
const parsed = JSON.parse(raw);
|
|
30950
30402
|
if (typeof parsed !== "object" || parsed === null) return null;
|
|
30951
30403
|
return PolicyBundle.parse(parsed.bundle);
|
|
@@ -31069,7 +30521,7 @@ function inventorySignature(packs2) {
|
|
|
31069
30521
|
return packs2.map((p) => `${p.namespace}/${p.packId}@${p.version}#${hashRules(p.rulesJson)}`).sort().join(",");
|
|
31070
30522
|
}
|
|
31071
30523
|
function hashRules(rulesJson) {
|
|
31072
|
-
return
|
|
30524
|
+
return createHash3("sha256").update(rulesJson).digest("hex");
|
|
31073
30525
|
}
|
|
31074
30526
|
function parseVersion(v) {
|
|
31075
30527
|
const m = /^(\d+)\.(\d+)\.(\d+)/.exec(v);
|
|
@@ -31111,9 +30563,10 @@ var SqliteInstalledPacksRepository = class {
|
|
|
31111
30563
|
* from `openLocalDatabase`, which is the single construction site that owns a
|
|
31112
30564
|
* real `~/.aka`.
|
|
31113
30565
|
*/
|
|
31114
|
-
constructor(db, baseDir) {
|
|
30566
|
+
constructor(db, baseDir, onChange = () => void 0) {
|
|
31115
30567
|
this.db = db;
|
|
31116
30568
|
this.baseDir = baseDir;
|
|
30569
|
+
this.onChange = onChange;
|
|
31117
30570
|
this.insertMissingStmt = db.prepare(
|
|
31118
30571
|
`INSERT INTO installed_packs (id, namespace, pack_id, version, name, rules_json, enabled, policy_id, created_at, updated_at)
|
|
31119
30572
|
VALUES (:id, :namespace, :packId, :version, :name, :rulesJson, 1, :policyId, :now, :now)
|
|
@@ -31142,6 +30595,7 @@ var SqliteInstalledPacksRepository = class {
|
|
|
31142
30595
|
}
|
|
31143
30596
|
db;
|
|
31144
30597
|
baseDir;
|
|
30598
|
+
onChange;
|
|
31145
30599
|
insertMissingStmt;
|
|
31146
30600
|
upsertAvailableStmt;
|
|
31147
30601
|
signatureStmt;
|
|
@@ -31214,6 +30668,7 @@ var SqliteInstalledPacksRepository = class {
|
|
|
31214
30668
|
},
|
|
31215
30669
|
"IMMEDIATE"
|
|
31216
30670
|
);
|
|
30671
|
+
this.onChange();
|
|
31217
30672
|
} catch {
|
|
31218
30673
|
}
|
|
31219
30674
|
}
|
|
@@ -31288,6 +30743,7 @@ var SqliteInstalledPacksRepository = class {
|
|
|
31288
30743
|
},
|
|
31289
30744
|
"IMMEDIATE"
|
|
31290
30745
|
);
|
|
30746
|
+
if (changed) this.onChange();
|
|
31291
30747
|
return changed;
|
|
31292
30748
|
}
|
|
31293
30749
|
/**
|
|
@@ -31529,6 +30985,7 @@ var SqliteInstalledPacksRepository = class {
|
|
|
31529
30985
|
`UPDATE installed_packs SET policy_id = :policyId, updated_at = :now
|
|
31530
30986
|
WHERE namespace = :namespace AND pack_id = :packId`
|
|
31531
30987
|
).run({ policyId, now: Date.now(), namespace, packId });
|
|
30988
|
+
if (Number(res.changes) > 0) this.onChange();
|
|
31532
30989
|
return Number(res.changes) > 0;
|
|
31533
30990
|
}
|
|
31534
30991
|
/**
|
|
@@ -31553,6 +31010,7 @@ var SqliteInstalledPacksRepository = class {
|
|
|
31553
31010
|
`UPDATE installed_packs SET enabled = :enabled, updated_at = :now
|
|
31554
31011
|
WHERE namespace = :namespace AND pack_id = :packId`
|
|
31555
31012
|
).run({ enabled: boolToInt(enabled), now: Date.now(), namespace, packId });
|
|
31013
|
+
if (Number(res.changes) > 0) this.onChange();
|
|
31556
31014
|
return Number(res.changes) > 0;
|
|
31557
31015
|
}
|
|
31558
31016
|
// Fingerprint of the recorded available mirror — compared against the
|
|
@@ -32450,13 +31908,19 @@ var SqliteInventoryAssetsRepository = class {
|
|
|
32450
31908
|
import { randomUUID as randomUUID6 } from "crypto";
|
|
32451
31909
|
var SEED_BATCH_WINDOW_MS = 6e4;
|
|
32452
31910
|
var SqlitePoliciesRepository = class {
|
|
32453
|
-
constructor(db) {
|
|
31911
|
+
constructor(db, onChange = () => void 0) {
|
|
32454
31912
|
this.db = db;
|
|
31913
|
+
this.onChange = onChange;
|
|
32455
31914
|
}
|
|
32456
31915
|
db;
|
|
31916
|
+
onChange;
|
|
32457
31917
|
readPolicies() {
|
|
31918
|
+
return Promise.resolve(this.listPolicies());
|
|
31919
|
+
}
|
|
31920
|
+
/** The synchronous read behind {@link readPolicies}. */
|
|
31921
|
+
listPolicies() {
|
|
32458
31922
|
const rows = allRows(this.db.prepare("SELECT * FROM policies"));
|
|
32459
|
-
|
|
31923
|
+
return mapRowsTolerant(rows, (row) => {
|
|
32460
31924
|
const target = JSON.parse(row.target);
|
|
32461
31925
|
const customKeywords = row.custom_keywords ? JSON.parse(row.custom_keywords) : void 0;
|
|
32462
31926
|
return Policy.parse({
|
|
@@ -32468,7 +31932,6 @@ var SqlitePoliciesRepository = class {
|
|
|
32468
31932
|
customKeywords
|
|
32469
31933
|
});
|
|
32470
31934
|
});
|
|
32471
|
-
return Promise.resolve(policies);
|
|
32472
31935
|
}
|
|
32473
31936
|
// Seed one policy per bundled category at Monitor so the detection-type config
|
|
32474
31937
|
// exists from first run. An unassigned pack's rules follow these rows, so
|
|
@@ -32479,7 +31942,7 @@ var SqlitePoliciesRepository = class {
|
|
|
32479
31942
|
const count = countScalar(this.db, "SELECT count(*) AS n FROM policies");
|
|
32480
31943
|
if (count > 0) {
|
|
32481
31944
|
this.markEarlierChoices();
|
|
32482
|
-
this.monitorUntouchedSeeds();
|
|
31945
|
+
if (this.monitorUntouchedSeeds()) this.onChange();
|
|
32483
31946
|
return;
|
|
32484
31947
|
}
|
|
32485
31948
|
const stmt = this.db.prepare(
|
|
@@ -32496,6 +31959,7 @@ var SqlitePoliciesRepository = class {
|
|
|
32496
31959
|
});
|
|
32497
31960
|
}
|
|
32498
31961
|
});
|
|
31962
|
+
this.onChange();
|
|
32499
31963
|
}
|
|
32500
31964
|
// Before this build, upsertCategoryAction INSERTed a new row with updated_at
|
|
32501
31965
|
// equal to created_at, so a choice made for a category that had no row yet
|
|
@@ -32561,7 +32025,7 @@ var SqlitePoliciesRepository = class {
|
|
|
32561
32025
|
).filter(
|
|
32562
32026
|
(row) => DEFAULT_ACTIONS[row.category] === row.action
|
|
32563
32027
|
);
|
|
32564
|
-
if (untouched.length === 0) return;
|
|
32028
|
+
if (untouched.length === 0) return false;
|
|
32565
32029
|
const stmt = this.db.prepare(
|
|
32566
32030
|
`UPDATE policies SET action = 'log'
|
|
32567
32031
|
WHERE scope = 'global' AND json_extract(target, '$.category') = :category
|
|
@@ -32572,6 +32036,7 @@ var SqlitePoliciesRepository = class {
|
|
|
32572
32036
|
stmt.run({ category: row.category, seeded: row.action });
|
|
32573
32037
|
}
|
|
32574
32038
|
});
|
|
32039
|
+
return true;
|
|
32575
32040
|
}
|
|
32576
32041
|
// Insert-or-update the single global per-category policy row, keyed on the
|
|
32577
32042
|
// existing uq_policies_scope_target unique index (scope, target). `action`
|
|
@@ -32588,6 +32053,7 @@ var SqlitePoliciesRepository = class {
|
|
|
32588
32053
|
ON CONFLICT(scope, target) DO UPDATE SET action = excluded.action, enabled = 1,
|
|
32589
32054
|
updated_at = MAX(excluded.updated_at, policies.created_at + 1)`
|
|
32590
32055
|
).run({ id: randomUUID6(), target: JSON.stringify({ category }), action, now });
|
|
32056
|
+
this.onChange();
|
|
32591
32057
|
}
|
|
32592
32058
|
// Caps every global per-category policy currently set to block/redact down
|
|
32593
32059
|
// to warn (see warn-era-cap.ts). Rule-targeted policies are untouched.
|
|
@@ -32598,6 +32064,7 @@ var SqlitePoliciesRepository = class {
|
|
|
32598
32064
|
WHERE scope='global' AND action IN ('block','redact')
|
|
32599
32065
|
AND json_extract(target,'$.category') IS NOT NULL`
|
|
32600
32066
|
).run({ now: Date.now() });
|
|
32067
|
+
if (Number(info.changes) > 0) this.onChange();
|
|
32601
32068
|
return Number(info.changes);
|
|
32602
32069
|
}
|
|
32603
32070
|
// Whether the category's row was ever written after it was created — by the
|
|
@@ -32917,31 +32384,45 @@ var SqliteScanLedgerRepository = class {
|
|
|
32917
32384
|
constructor(db) {
|
|
32918
32385
|
this.db = db;
|
|
32919
32386
|
this.upsertStmt = db.prepare(
|
|
32920
|
-
`INSERT INTO scan_ledger
|
|
32921
|
-
|
|
32387
|
+
`INSERT INTO scan_ledger
|
|
32388
|
+
(path, mtime, content_hash, ruleset_hash, scope_key, scope_root, scanned_at)
|
|
32389
|
+
VALUES (:path, :mtime, :contentHash, :rulesetHash, :scopeKey, :scopeRoot, :scannedAt)
|
|
32922
32390
|
ON CONFLICT (path) DO UPDATE SET
|
|
32923
32391
|
mtime = excluded.mtime,
|
|
32924
32392
|
content_hash = excluded.content_hash,
|
|
32925
32393
|
ruleset_hash = excluded.ruleset_hash,
|
|
32394
|
+
scope_key = excluded.scope_key,
|
|
32395
|
+
scope_root = excluded.scope_root,
|
|
32926
32396
|
scanned_at = excluded.scanned_at`
|
|
32927
32397
|
);
|
|
32928
32398
|
this.readStmt = db.prepare(
|
|
32929
|
-
`SELECT path, mtime, content_hash AS contentHash
|
|
32399
|
+
`SELECT path, mtime, content_hash AS contentHash, scope_key AS scopeKey,
|
|
32400
|
+
scope_root AS scopeRoot
|
|
32930
32401
|
FROM scan_ledger WHERE ruleset_hash = :rulesetHash`
|
|
32931
32402
|
);
|
|
32932
32403
|
this.pathsStmt = db.prepare(`SELECT path FROM scan_ledger`);
|
|
32404
|
+
this.pathKeysStmt = db.prepare(`SELECT path, scope_key AS scopeKey FROM scan_ledger`);
|
|
32933
32405
|
}
|
|
32934
32406
|
db;
|
|
32935
32407
|
upsertStmt;
|
|
32936
32408
|
readStmt;
|
|
32937
32409
|
pathsStmt;
|
|
32410
|
+
pathKeysStmt;
|
|
32938
32411
|
// Previously scanned files under THIS ruleset, keyed by path. Rows from an
|
|
32939
32412
|
// older ruleset are simply absent, which reads as "never scanned".
|
|
32940
32413
|
entriesForRuleset(rulesetHash) {
|
|
32941
|
-
const rows = allRows(this.readStmt, {
|
|
32942
|
-
|
|
32943
|
-
|
|
32944
|
-
|
|
32414
|
+
const rows = allRows(this.readStmt, { rulesetHash });
|
|
32415
|
+
return new Map(
|
|
32416
|
+
rows.map((r) => [
|
|
32417
|
+
r.path,
|
|
32418
|
+
{
|
|
32419
|
+
mtime: r.mtime,
|
|
32420
|
+
contentHash: r.contentHash,
|
|
32421
|
+
...r.scopeKey !== null ? { scopeKey: r.scopeKey } : {},
|
|
32422
|
+
...r.scopeRoot !== null ? { scopeRoot: r.scopeRoot } : {}
|
|
32423
|
+
}
|
|
32424
|
+
])
|
|
32425
|
+
);
|
|
32945
32426
|
}
|
|
32946
32427
|
// Every ledgered path, whatever ruleset it was scanned under — the set a
|
|
32947
32428
|
// deletion sweep checks against disk. A file deleted before a ruleset change
|
|
@@ -32950,6 +32431,14 @@ var SqliteScanLedgerRepository = class {
|
|
|
32950
32431
|
allPaths() {
|
|
32951
32432
|
return allRows(this.pathsStmt).map((r) => r.path);
|
|
32952
32433
|
}
|
|
32434
|
+
// Every ledgered path with the repository it was in when it was last read,
|
|
32435
|
+
// whatever ruleset it was scanned under: what a deletion sweep needs to say
|
|
32436
|
+
// which repository a vanished file belonged to. `undefined` for a row with no
|
|
32437
|
+
// key, which is every row written before the column existed.
|
|
32438
|
+
pathKeys() {
|
|
32439
|
+
const rows = allRows(this.pathKeysStmt);
|
|
32440
|
+
return new Map(rows.map((r) => [r.path, r.scopeKey ?? void 0]));
|
|
32441
|
+
}
|
|
32953
32442
|
upsertEntries(entries) {
|
|
32954
32443
|
if (entries.length === 0) return;
|
|
32955
32444
|
const scannedAt = Date.now();
|
|
@@ -32960,6 +32449,8 @@ var SqliteScanLedgerRepository = class {
|
|
|
32960
32449
|
mtime: entry.mtime,
|
|
32961
32450
|
contentHash: entry.contentHash,
|
|
32962
32451
|
rulesetHash: entry.rulesetHash,
|
|
32452
|
+
scopeKey: entry.scopeKey ?? null,
|
|
32453
|
+
scopeRoot: entry.scopeRoot ?? null,
|
|
32963
32454
|
scannedAt
|
|
32964
32455
|
});
|
|
32965
32456
|
}
|
|
@@ -34047,6 +33538,11 @@ function withoutDroppedFiles(reconcile, droppedFiles) {
|
|
|
34047
33538
|
deletedFiles: reconcile.deletedFiles.filter((file2) => !dropped.has(file2))
|
|
34048
33539
|
};
|
|
34049
33540
|
}
|
|
33541
|
+
function withoutTrailingSlashes(path) {
|
|
33542
|
+
let end = path.length;
|
|
33543
|
+
while (end > 0 && path.charCodeAt(end - 1) === 47) end--;
|
|
33544
|
+
return path.slice(0, end);
|
|
33545
|
+
}
|
|
34050
33546
|
function toEndpointSummary(row) {
|
|
34051
33547
|
return {
|
|
34052
33548
|
id: row.id,
|
|
@@ -34334,7 +33830,7 @@ var SqliteSharesRepository = class {
|
|
|
34334
33830
|
*/
|
|
34335
33831
|
reconcileCallSites(projectKey, reconcile) {
|
|
34336
33832
|
if (reconcile.mode === "walk") {
|
|
34337
|
-
const prefix = reconcile.walkedPrefix
|
|
33833
|
+
const prefix = withoutTrailingSlashes(reconcile.walkedPrefix);
|
|
34338
33834
|
this.db.prepare(
|
|
34339
33835
|
`DELETE FROM share_call_site
|
|
34340
33836
|
WHERE project_key = :key
|
|
@@ -34902,7 +34398,7 @@ function backupLegacyStore(db, file2) {
|
|
|
34902
34398
|
discardStore(file2, backup);
|
|
34903
34399
|
return backup;
|
|
34904
34400
|
}
|
|
34905
|
-
function openAndInitialize(file2, base, skipTags) {
|
|
34401
|
+
function openAndInitialize(file2, base, skipTags, shippedRegexMatchers2) {
|
|
34906
34402
|
let db = openWithPragmas(file2);
|
|
34907
34403
|
try {
|
|
34908
34404
|
if (isForeignSqliteLineage(db)) {
|
|
@@ -34914,8 +34410,15 @@ function openAndInitialize(file2, base, skipTags) {
|
|
|
34914
34410
|
}
|
|
34915
34411
|
applyMigrations(db, file2, { skipTags });
|
|
34916
34412
|
tightenPerms(file2);
|
|
34917
|
-
const
|
|
34918
|
-
const
|
|
34413
|
+
const modPolicy = {};
|
|
34414
|
+
const onPolicyStateChange = () => {
|
|
34415
|
+
if (modPolicy.current !== void 0)
|
|
34416
|
+
refreshModPolicySnapshot(dirname2(file2), modPolicy.current);
|
|
34417
|
+
};
|
|
34418
|
+
const policies = new SqlitePoliciesRepository(db, onPolicyStateChange);
|
|
34419
|
+
const installedPacks = new SqliteInstalledPacksRepository(db, base, onPolicyStateChange);
|
|
34420
|
+
const ruleProbeCache = new SqliteRuleProbeCacheRepository(db);
|
|
34421
|
+
const exceptions = new SqliteExceptionsRepository(db, void 0, onPolicyStateChange);
|
|
34919
34422
|
const repositories = {
|
|
34920
34423
|
events: new SqliteEventsRepository(db),
|
|
34921
34424
|
findings: new SqliteFindingsRepository(db),
|
|
@@ -34924,9 +34427,9 @@ function openAndInitialize(file2, base, skipTags) {
|
|
|
34924
34427
|
scanLedger: new SqliteScanLedgerRepository(db),
|
|
34925
34428
|
historySync: new SqliteHistorySyncRepository(db),
|
|
34926
34429
|
secretVault: new SqliteSecretVaultRepository(db),
|
|
34927
|
-
exceptions
|
|
34430
|
+
exceptions,
|
|
34928
34431
|
resolutions: new SqliteResolutionsRepository(db),
|
|
34929
|
-
ruleProbeCache
|
|
34432
|
+
ruleProbeCache,
|
|
34930
34433
|
bodyRetention: new SqliteBodyRetentionRepository(db),
|
|
34931
34434
|
security: new SqliteSecurityRepository(db),
|
|
34932
34435
|
detections: new SqliteDetectionsRepository(db),
|
|
@@ -34944,6 +34447,13 @@ function openAndInitialize(file2, base, skipTags) {
|
|
|
34944
34447
|
inspectionFindings: new SqliteInspectionFindingsRepository(db),
|
|
34945
34448
|
configInventory: new SqliteConfigInventoryRepository(db)
|
|
34946
34449
|
};
|
|
34450
|
+
modPolicy.current = {
|
|
34451
|
+
installedRuleset: () => installedPacks.installedRuleset(),
|
|
34452
|
+
readPolicies: () => policies.listPolicies(),
|
|
34453
|
+
activeExceptionRuleIds: () => exceptions.activeRuleIds(),
|
|
34454
|
+
probeVerdict: (key) => ruleProbeCache.getVerdict(key)?.verdict,
|
|
34455
|
+
bundledRegexMatchers: () => shippedRegexMatchers2
|
|
34456
|
+
};
|
|
34947
34457
|
policies.seedDefaults();
|
|
34948
34458
|
return { db, ...repositories };
|
|
34949
34459
|
} catch (err) {
|
|
@@ -34955,7 +34465,7 @@ function openAndInitialize(file2, base, skipTags) {
|
|
|
34955
34465
|
var DEFERRED_TAGS = new Set(DEFERRED_MIGRATION_TAGS);
|
|
34956
34466
|
function openLocalDatabase(dir, options = {}) {
|
|
34957
34467
|
ensureDataDirSync(dir);
|
|
34958
|
-
const file2 =
|
|
34468
|
+
const file2 = join8(dir, DB_FILENAME);
|
|
34959
34469
|
reapStalePartials(file2);
|
|
34960
34470
|
const {
|
|
34961
34471
|
db,
|
|
@@ -34991,7 +34501,8 @@ function openLocalDatabase(dir, options = {}) {
|
|
|
34991
34501
|
// `dataDir()` — so its parent is the `~/.aka` base the layout splits into
|
|
34992
34502
|
// settings/ and data/, and the pack-policy floor needs both halves.
|
|
34993
34503
|
dirname2(dir),
|
|
34994
|
-
options.applyDeferredMigrations === true ? void 0 : DEFERRED_TAGS
|
|
34504
|
+
options.applyDeferredMigrations === true ? void 0 : DEFERRED_TAGS,
|
|
34505
|
+
options.shippedRegexMatchers ?? []
|
|
34995
34506
|
);
|
|
34996
34507
|
function captureRowId(event) {
|
|
34997
34508
|
return captureId(
|
|
@@ -35256,39 +34767,39 @@ function openLocalDatabase(dir, options = {}) {
|
|
|
35256
34767
|
}
|
|
35257
34768
|
|
|
35258
34769
|
// ../../packages/persistence/src/egress-wire.ts
|
|
35259
|
-
import { createHash as
|
|
34770
|
+
import { createHash as createHash4 } from "crypto";
|
|
35260
34771
|
var SLASH = "/".charCodeAt(0);
|
|
35261
34772
|
var SCOPE_KEY = printable(ATTACHMENT_SCOPE_IDENTITY_MAX_LENGTH);
|
|
35262
34773
|
|
|
35263
34774
|
// ../../packages/persistence/src/finding-key.ts
|
|
35264
|
-
import { createHash as
|
|
34775
|
+
import { createHash as createHash5 } from "crypto";
|
|
35265
34776
|
|
|
35266
34777
|
// ../../packages/persistence/src/fingerprint.ts
|
|
35267
34778
|
import { createHmac, randomBytes } from "crypto";
|
|
35268
|
-
import { existsSync as existsSync3, readFileSync as
|
|
35269
|
-
import { join as
|
|
35270
|
-
import { DatabaseSync as DatabaseSync2 } from "node:sqlite";
|
|
34779
|
+
import { existsSync as existsSync3, readFileSync as readFileSync7 } from "fs";
|
|
34780
|
+
import { join as join9 } from "path";
|
|
35271
34781
|
|
|
35272
34782
|
// ../../packages/persistence/src/forward-health.ts
|
|
35273
|
-
import { readFileSync as
|
|
35274
|
-
import { join as
|
|
34783
|
+
import { readFileSync as readFileSync8 } from "fs";
|
|
34784
|
+
import { join as join10 } from "path";
|
|
35275
34785
|
|
|
35276
34786
|
// ../../packages/persistence/src/history-backfill.ts
|
|
35277
34787
|
import { existsSync as existsSync4 } from "fs";
|
|
35278
|
-
import { join as
|
|
34788
|
+
import { join as join11 } from "path";
|
|
35279
34789
|
|
|
35280
34790
|
// ../../packages/persistence/src/history-preview.ts
|
|
35281
34791
|
import { existsSync as existsSync5 } from "fs";
|
|
35282
|
-
import { join as
|
|
35283
|
-
import { DatabaseSync as
|
|
34792
|
+
import { join as join12 } from "path";
|
|
34793
|
+
import { DatabaseSync as DatabaseSync2 } from "node:sqlite";
|
|
35284
34794
|
|
|
35285
34795
|
// ../../packages/persistence/src/history-sync-state.ts
|
|
35286
|
-
import { readFileSync as
|
|
35287
|
-
import { join as
|
|
34796
|
+
import { readFileSync as readFileSync9 } from "fs";
|
|
34797
|
+
import { join as join13 } from "path";
|
|
34798
|
+
var COUNTS_SCOPES = new Set(AttachmentMode.options);
|
|
35288
34799
|
|
|
35289
34800
|
// ../../packages/persistence/src/store-symlinks.ts
|
|
35290
34801
|
import { existsSync as existsSync6, lstatSync as lstatSync3, readlinkSync, realpathSync, statSync as statSync4 } from "fs";
|
|
35291
|
-
import { dirname as dirname3, join as
|
|
34802
|
+
import { dirname as dirname3, join as join14, resolve } from "path";
|
|
35292
34803
|
|
|
35293
34804
|
// ../../packages/persistence/src/vault/crypto.ts
|
|
35294
34805
|
import {
|
|
@@ -35302,19 +34813,19 @@ import {
|
|
|
35302
34813
|
// ../../packages/persistence/src/vault/key-provider.ts
|
|
35303
34814
|
import { execFileSync } from "child_process";
|
|
35304
34815
|
import { randomBytes as randomBytes2 } from "crypto";
|
|
35305
|
-
import { chmodSync as chmodSync3, readFileSync as
|
|
35306
|
-
import { join as
|
|
34816
|
+
import { chmodSync as chmodSync3, readFileSync as readFileSync10, renameSync as renameSync4, rmSync as rmSync6, statSync as statSync5, writeFileSync as writeFileSync3 } from "fs";
|
|
34817
|
+
import { join as join15 } from "path";
|
|
35307
34818
|
|
|
35308
34819
|
// ../../packages/persistence/src/vault/vault.ts
|
|
35309
34820
|
import { randomBytes as randomBytes3, randomUUID as randomUUID12 } from "crypto";
|
|
35310
34821
|
|
|
35311
34822
|
// ../../packages/persistence/src/warn-era-cap.ts
|
|
35312
34823
|
import { existsSync as existsSync7, writeFileSync as writeFileSync4 } from "fs";
|
|
35313
|
-
import { join as
|
|
34824
|
+
import { join as join16 } from "path";
|
|
35314
34825
|
|
|
35315
34826
|
// ../../packages/plugin-sdk/src/config.ts
|
|
35316
34827
|
import { existsSync as existsSync8 } from "fs";
|
|
35317
|
-
import { join as
|
|
34828
|
+
import { join as join17 } from "path";
|
|
35318
34829
|
|
|
35319
34830
|
// ../../packages/plugin-sdk/src/provider-env.ts
|
|
35320
34831
|
var DEFAULT_ANTHROPIC_HOST = "api.anthropic.com";
|
|
@@ -35368,7 +34879,7 @@ function resolveProvider() {
|
|
|
35368
34879
|
function loadConfig(base = defaultDataDir(), resolveProviderFn = resolveProvider) {
|
|
35369
34880
|
try {
|
|
35370
34881
|
ensureLayoutDirSync(base);
|
|
35371
|
-
const settingsFile =
|
|
34882
|
+
const settingsFile = join17(settingsDir(base), "settings.json");
|
|
35372
34883
|
if (existsSync8(settingsFile)) tightenFile(settingsFile);
|
|
35373
34884
|
} catch {
|
|
35374
34885
|
}
|
|
@@ -35391,11 +34902,6 @@ function resolveProviderSafe(resolveProviderFn) {
|
|
|
35391
34902
|
}
|
|
35392
34903
|
}
|
|
35393
34904
|
|
|
35394
|
-
// ../../packages/plugin-sdk/src/config-inventory.ts
|
|
35395
|
-
import { readdirSync as readdirSync2, readFileSync as readFileSync11, realpathSync as realpathSync2, statSync as statSync7 } from "fs";
|
|
35396
|
-
import { homedir as homedir2 } from "os";
|
|
35397
|
-
import { basename as basename3, join as join18 } from "path";
|
|
35398
|
-
|
|
35399
34905
|
// ../../packages/detections/src/egress/registry.ts
|
|
35400
34906
|
var EXTRACTOR_VERSION = "3";
|
|
35401
34907
|
var PROVIDER_REGISTRY = [
|
|
@@ -36506,17 +36012,18 @@ function ruleEvidence(rule) {
|
|
|
36506
36012
|
|
|
36507
36013
|
// ../../packages/detections/src/mask.ts
|
|
36508
36014
|
function maskMatch(raw) {
|
|
36509
|
-
|
|
36510
|
-
|
|
36511
|
-
|
|
36512
|
-
|
|
36015
|
+
const visible = stripInvisiblePadding(raw);
|
|
36016
|
+
if (visible.length <= 5) return "***";
|
|
36017
|
+
const atIndex = visible.indexOf("@");
|
|
36018
|
+
if (atIndex > 0 && atIndex < visible.length - 1) {
|
|
36019
|
+
const domain2 = visible.slice(atIndex + 1);
|
|
36513
36020
|
if (domain2.includes(".")) {
|
|
36514
|
-
const local =
|
|
36021
|
+
const local = visible.slice(0, atIndex);
|
|
36515
36022
|
const maskedLocal = local.length <= 1 ? local : local.charAt(0) + "*".repeat(local.length - 1);
|
|
36516
36023
|
return `${maskedLocal}@${domain2}`;
|
|
36517
36024
|
}
|
|
36518
36025
|
}
|
|
36519
|
-
return `${
|
|
36026
|
+
return `${visible.charAt(0)}${"*".repeat(6)}${visible.charAt(visible.length - 1)}`;
|
|
36520
36027
|
}
|
|
36521
36028
|
|
|
36522
36029
|
// ../../packages/detections/src/pointer-shield.ts
|
|
@@ -36691,7 +36198,12 @@ var MIN_RAW_LEN = 4;
|
|
|
36691
36198
|
var RAW_RUN_LEN = 8;
|
|
36692
36199
|
function carriesRawRun(text, rawValues) {
|
|
36693
36200
|
let windows = null;
|
|
36694
|
-
|
|
36201
|
+
const values = /* @__PURE__ */ new Set();
|
|
36202
|
+
for (const raw of rawValues) {
|
|
36203
|
+
values.add(raw);
|
|
36204
|
+
values.add(stripInvisiblePadding(raw));
|
|
36205
|
+
}
|
|
36206
|
+
for (const raw of values) {
|
|
36695
36207
|
if (raw.length < MIN_RAW_LEN) continue;
|
|
36696
36208
|
if (raw.length < RAW_RUN_LEN) {
|
|
36697
36209
|
if (text.includes(raw)) return true;
|
|
@@ -36765,11 +36277,16 @@ function maskContextSlice(slice, sliceStart, hits) {
|
|
|
36765
36277
|
return masked;
|
|
36766
36278
|
}
|
|
36767
36279
|
function safeMaskedMatch(rawMatch) {
|
|
36768
|
-
const
|
|
36769
|
-
|
|
36770
|
-
|
|
36280
|
+
const visible = stripInvisiblePadding(rawMatch);
|
|
36281
|
+
const masked = maskMatch(visible);
|
|
36282
|
+
const reveals = (preview) => preview === visible || visible.length >= MIN_RAW_LEN && preview.includes(visible);
|
|
36283
|
+
if (!reveals(masked)) return masked;
|
|
36284
|
+
const atIndex = masked.indexOf("@");
|
|
36285
|
+
if (atIndex > 0 && atIndex < masked.length - 1) {
|
|
36286
|
+
const emailFallback = `*${masked.slice(atIndex)}`;
|
|
36287
|
+
if (!reveals(emailFallback)) return emailFallback;
|
|
36771
36288
|
}
|
|
36772
|
-
return
|
|
36289
|
+
return "***";
|
|
36773
36290
|
}
|
|
36774
36291
|
function assertRawFree(text, rawValues) {
|
|
36775
36292
|
if (carriesRawRun(text, rawValues)) {
|
|
@@ -39191,6 +38708,7 @@ var BUNDLED_PACKS = [
|
|
|
39191
38708
|
];
|
|
39192
38709
|
|
|
39193
38710
|
// ../../packages/plugin-sdk/src/rule-packs.ts
|
|
38711
|
+
var BUNDLED_NAMESPACE = "aka";
|
|
39194
38712
|
function registerRulePack(packId, rawRules) {
|
|
39195
38713
|
const rules = rawRules.map((raw) => Rule.parse(raw));
|
|
39196
38714
|
registerPack({ id: packId, rules });
|
|
@@ -39198,6 +38716,23 @@ function registerRulePack(packId, rawRules) {
|
|
|
39198
38716
|
function registerBundledPacks() {
|
|
39199
38717
|
for (const pack of BUNDLED_PACKS) registerRulePack(pack.packId, pack.rawRules);
|
|
39200
38718
|
}
|
|
38719
|
+
var cachedDetections;
|
|
38720
|
+
function bundledDetections() {
|
|
38721
|
+
cachedDetections ??= BUNDLED_PACKS.map((pack) => ({
|
|
38722
|
+
namespace: BUNDLED_NAMESPACE,
|
|
38723
|
+
packId: pack.packId,
|
|
38724
|
+
version: pack.version,
|
|
38725
|
+
name: pack.name,
|
|
38726
|
+
rules: pack.rawRules.map((raw) => Rule.parse(raw)),
|
|
38727
|
+
defaultPolicyId: pack.defaultPolicy
|
|
38728
|
+
}));
|
|
38729
|
+
return cachedDetections;
|
|
38730
|
+
}
|
|
38731
|
+
function shippedRegexMatchers() {
|
|
38732
|
+
return bundledDetections().flatMap((pack) => pack.rules).flatMap(
|
|
38733
|
+
(rule) => rule.matcher.type === "regex" ? [{ pattern: rule.matcher.pattern, flags: rule.matcher.flags }] : []
|
|
38734
|
+
);
|
|
38735
|
+
}
|
|
39201
38736
|
|
|
39202
38737
|
// ../../packages/plugin-sdk/src/mask.ts
|
|
39203
38738
|
var packsReady = false;
|
|
@@ -39252,87 +38787,6 @@ function maskText(text) {
|
|
|
39252
38787
|
return scanText(text).masked;
|
|
39253
38788
|
}
|
|
39254
38789
|
|
|
39255
|
-
// ../../packages/plugin-sdk/src/repo.ts
|
|
39256
|
-
import { existsSync as existsSync9, readFileSync as readFileSync10, statSync as statSync6 } from "fs";
|
|
39257
|
-
import { basename as basename2, dirname as dirname4, isAbsolute, join as join17, sep as sep2 } from "path";
|
|
39258
|
-
var NO_ATTRIBUTION = Object.freeze({});
|
|
39259
|
-
|
|
39260
|
-
// ../../packages/plugin-sdk/src/events.ts
|
|
39261
|
-
import { createHash as createHash5, randomUUID as randomUUID13 } from "crypto";
|
|
39262
|
-
|
|
39263
|
-
// ../../packages/plugin-sdk/src/isolated-scan.ts
|
|
39264
|
-
import { existsSync as existsSync10 } from "fs";
|
|
39265
|
-
import { fileURLToPath } from "url";
|
|
39266
|
-
import { Worker } from "worker_threads";
|
|
39267
|
-
|
|
39268
|
-
// ../../packages/plugin-sdk/src/hook-fail-opens.ts
|
|
39269
|
-
import { readFileSync as readFileSync12 } from "fs";
|
|
39270
|
-
import { join as join19 } from "path";
|
|
39271
|
-
|
|
39272
|
-
// ../../packages/plugin-sdk/src/host-floor.ts
|
|
39273
|
-
import { readFileSync as readFileSync14 } from "fs";
|
|
39274
|
-
import { join as join21 } from "path";
|
|
39275
|
-
|
|
39276
|
-
// ../../packages/plugin-sdk/src/model-governance.ts
|
|
39277
|
-
import {
|
|
39278
|
-
closeSync as closeSync2,
|
|
39279
|
-
fstatSync,
|
|
39280
|
-
mkdirSync as mkdirSync2,
|
|
39281
|
-
openSync as openSync2,
|
|
39282
|
-
readFileSync as readFileSync13,
|
|
39283
|
-
readSync,
|
|
39284
|
-
writeFileSync as writeFileSync5
|
|
39285
|
-
} from "fs";
|
|
39286
|
-
import { join as join20 } from "path";
|
|
39287
|
-
var TAIL_BYTES = 256 * 1024;
|
|
39288
|
-
|
|
39289
|
-
// ../../packages/plugin-sdk/src/host-floor.ts
|
|
39290
|
-
var HOST_FEATURE = {
|
|
39291
|
-
ModelSwitch: "model-switch",
|
|
39292
|
-
VaultPointerDisplay: "vault-pointer-display"
|
|
39293
|
-
};
|
|
39294
|
-
var HOST_FLOORS = {
|
|
39295
|
-
[HOST_FEATURE.ModelSwitch]: {
|
|
39296
|
-
label: "model-switch protection",
|
|
39297
|
-
hookEvents: ["PreModelSwitch", "PostModelSwitch"],
|
|
39298
|
-
since: "2.1.251"
|
|
39299
|
-
},
|
|
39300
|
-
[HOST_FEATURE.VaultPointerDisplay]: {
|
|
39301
|
-
label: "vault pointer display",
|
|
39302
|
-
hookEvents: ["MessageDisplay"],
|
|
39303
|
-
since: "2.1.152"
|
|
39304
|
-
}
|
|
39305
|
-
};
|
|
39306
|
-
var ANTIGRAVITY_HOST_FEATURE = {
|
|
39307
|
-
EndOfTurnCapture: "end-of-turn-capture"
|
|
39308
|
-
};
|
|
39309
|
-
var ANTIGRAVITY_HOST_FLOORS = {
|
|
39310
|
-
[ANTIGRAVITY_HOST_FEATURE.EndOfTurnCapture]: {
|
|
39311
|
-
label: "end-of-turn history capture",
|
|
39312
|
-
hookEvents: ["Stop"],
|
|
39313
|
-
since: "1.1.10"
|
|
39314
|
-
}
|
|
39315
|
-
};
|
|
39316
|
-
|
|
39317
|
-
// ../../packages/plugin-sdk/src/ignore-layers.ts
|
|
39318
|
-
var import_ignore = __toESM(require_ignore(), 1);
|
|
39319
|
-
import { readFileSync as readFileSync15 } from "fs";
|
|
39320
|
-
import { join as join22 } from "path";
|
|
39321
|
-
|
|
39322
|
-
// ../../packages/plugin-sdk/src/inventory-resolver.ts
|
|
39323
|
-
import { arch, hostname as hostname4, platform, release } from "os";
|
|
39324
|
-
|
|
39325
|
-
// ../../packages/plugin-sdk/src/nudge.ts
|
|
39326
|
-
import { mkdirSync as mkdirSync3, readFileSync as readFileSync16, writeFileSync as writeFileSync6 } from "fs";
|
|
39327
|
-
import { join as join23 } from "path";
|
|
39328
|
-
|
|
39329
|
-
// ../../packages/plugin-sdk/src/paths.ts
|
|
39330
|
-
import { readdirSync as readdirSync3, realpathSync as realpathSync3 } from "fs";
|
|
39331
|
-
import { basename as basename4, dirname as dirname5, sep as sep3 } from "path";
|
|
39332
|
-
|
|
39333
|
-
// ../../packages/plugin-sdk/src/policy-resolver.ts
|
|
39334
|
-
import { randomUUID as randomUUID14 } from "crypto";
|
|
39335
|
-
|
|
39336
38790
|
// ../../packages/plugin-sdk/src/posture.ts
|
|
39337
38791
|
function applyCategoryPosture(posture, repo, mode = "fill-gaps") {
|
|
39338
38792
|
for (const category of Object.keys(posture)) {
|
|
@@ -39346,43 +38800,6 @@ function applyCategoryPosture(posture, repo, mode = "fill-gaps") {
|
|
|
39346
38800
|
}
|
|
39347
38801
|
}
|
|
39348
38802
|
|
|
39349
|
-
// ../../packages/plugin-sdk/src/project-files.ts
|
|
39350
|
-
import { existsSync as existsSync11, readdirSync as readdirSync4 } from "fs";
|
|
39351
|
-
import { basename as basename5, join as join24 } from "path";
|
|
39352
|
-
|
|
39353
|
-
// ../../packages/plugin-sdk/src/provider-env-antigravity.ts
|
|
39354
|
-
var optionalBaseUrl2 = external_exports.preprocess((v) => {
|
|
39355
|
-
if (typeof v === "string" && v.trim() === "") return void 0;
|
|
39356
|
-
return v;
|
|
39357
|
-
}, external_exports.string().optional()).catch(void 0);
|
|
39358
|
-
var optionalFlag = external_exports.preprocess((v) => {
|
|
39359
|
-
if (typeof v !== "string") return false;
|
|
39360
|
-
const normalized = v.trim().toLowerCase();
|
|
39361
|
-
return normalized !== "" && normalized !== "0" && normalized !== "false";
|
|
39362
|
-
}, external_exports.boolean()).catch(false);
|
|
39363
|
-
var antigravityProviderEnvShape = {
|
|
39364
|
-
GOOGLE_GENAI_USE_VERTEXAI: optionalFlag,
|
|
39365
|
-
GOOGLE_GEMINI_BASE_URL: optionalBaseUrl2
|
|
39366
|
-
};
|
|
39367
|
-
var AntigravityProviderEnvSchema = external_exports.object(antigravityProviderEnvShape);
|
|
39368
|
-
|
|
39369
|
-
// ../../packages/plugin-sdk/src/provider-env-codex.ts
|
|
39370
|
-
var optionalBaseUrl3 = external_exports.preprocess((v) => {
|
|
39371
|
-
if (typeof v === "string" && v.trim() === "") return void 0;
|
|
39372
|
-
return v;
|
|
39373
|
-
}, external_exports.string().optional()).catch(void 0);
|
|
39374
|
-
var codexProviderEnvShape = {
|
|
39375
|
-
OPENAI_BASE_URL: optionalBaseUrl3
|
|
39376
|
-
};
|
|
39377
|
-
var CodexProviderEnvSchema = external_exports.object(codexProviderEnvShape);
|
|
39378
|
-
|
|
39379
|
-
// ../../packages/plugin-sdk/src/runtime.ts
|
|
39380
|
-
import { randomUUID as randomUUID15 } from "crypto";
|
|
39381
|
-
|
|
39382
|
-
// ../../packages/plugin-sdk/src/scope-key.ts
|
|
39383
|
-
import { existsSync as existsSync12 } from "fs";
|
|
39384
|
-
import { dirname as dirname6, isAbsolute as isAbsolute2, join as join25, normalize } from "path";
|
|
39385
|
-
|
|
39386
38803
|
// ../../packages/plugin-sdk/src/suppressions.ts
|
|
39387
38804
|
var THIRTY_DAYS_MS = 30 * 24 * 60 * 60 * 1e3;
|
|
39388
38805
|
function isDuplicateActive(err) {
|
|
@@ -39420,13 +38837,9 @@ async function applySetupTriageSuppressions(entries, writer, opts) {
|
|
|
39420
38837
|
return { written, skippedDuplicate };
|
|
39421
38838
|
}
|
|
39422
38839
|
|
|
39423
|
-
// ../../packages/plugin-sdk/src/throttle.ts
|
|
39424
|
-
import { mkdirSync as mkdirSync4, statSync as statSync8, writeFileSync as writeFileSync7 } from "fs";
|
|
39425
|
-
import { join as join26 } from "path";
|
|
39426
|
-
|
|
39427
38840
|
// ../../packages/setup-wizard/src/remediation/rotation-checklist.ts
|
|
39428
|
-
import { writeFileSync as
|
|
39429
|
-
import { join as
|
|
38841
|
+
import { writeFileSync as writeFileSync5 } from "fs";
|
|
38842
|
+
import { join as join18 } from "path";
|
|
39430
38843
|
|
|
39431
38844
|
// ../../packages/setup-wizard/src/triage/dedupe.ts
|
|
39432
38845
|
function dedupeKey(hit) {
|
|
@@ -39481,12 +38894,12 @@ function deriveFalsePositivePatterns(hits, rec, plan) {
|
|
|
39481
38894
|
}
|
|
39482
38895
|
|
|
39483
38896
|
// ../../packages/setup-wizard/src/triage/gate-display.ts
|
|
39484
|
-
function findContext(entry,
|
|
39485
|
-
const byFingerprint =
|
|
38897
|
+
function findContext(entry, join23) {
|
|
38898
|
+
const byFingerprint = join23.find(
|
|
39486
38899
|
(j) => j.valueFingerprint !== void 0 && j.valueFingerprint === entry.valueFingerprint
|
|
39487
38900
|
);
|
|
39488
38901
|
if (byFingerprint) return byFingerprint.maskedContext;
|
|
39489
|
-
const byRuleAndMask =
|
|
38902
|
+
const byRuleAndMask = join23.find(
|
|
39490
38903
|
(j) => j.ruleId === entry.ruleId && j.maskedMatch === entry.maskedValue
|
|
39491
38904
|
);
|
|
39492
38905
|
return byRuleAndMask?.maskedContext;
|
|
@@ -39557,13 +38970,13 @@ function renderShowcase(showcase) {
|
|
|
39557
38970
|
|
|
39558
38971
|
${blocks.join("\n\n")}`;
|
|
39559
38972
|
}
|
|
39560
|
-
function renderSuppressionGate(entries,
|
|
38973
|
+
function renderSuppressionGate(entries, join23) {
|
|
39561
38974
|
if (entries.length === 0) {
|
|
39562
38975
|
return "No false-positive suppressions to confirm \u2014 nothing will be written.";
|
|
39563
38976
|
}
|
|
39564
38977
|
const header = entries.length === 1 ? "This looks like a false positive \u2014 take a look before I suppress it:" : `These ${String(entries.length)} look like false positives \u2014 take a look before I suppress them:`;
|
|
39565
38978
|
const blocks = entries.map((entry, i) => {
|
|
39566
|
-
const context = findContext(entry,
|
|
38979
|
+
const context = findContext(entry, join23);
|
|
39567
38980
|
const lines = [
|
|
39568
38981
|
`${String(i + 1)}. ${entry.ruleId} [${entry.category}]`,
|
|
39569
38982
|
` value: ${entry.maskedValue}`,
|
|
@@ -39649,9 +39062,9 @@ function mergeRecommendations(verdicts) {
|
|
|
39649
39062
|
}
|
|
39650
39063
|
|
|
39651
39064
|
// ../../packages/setup-wizard/src/triage/plan-file.ts
|
|
39652
|
-
import { mkdtempSync, readFileSync as
|
|
39065
|
+
import { mkdtempSync, readFileSync as readFileSync11, rmdirSync, rmSync as rmSync7, writeFileSync as writeFileSync6 } from "fs";
|
|
39653
39066
|
import { tmpdir } from "os";
|
|
39654
|
-
import { basename as
|
|
39067
|
+
import { basename as basename2, dirname as dirname4, join as join19 } from "path";
|
|
39655
39068
|
var SuppressionEntrySchema = external_exports.object({
|
|
39656
39069
|
ruleId: external_exports.string(),
|
|
39657
39070
|
category: DetectionCategory,
|
|
@@ -39706,20 +39119,20 @@ function serializePlan(plan, current) {
|
|
|
39706
39119
|
function writePlanFile(plan, current, rawValues, deps = {}) {
|
|
39707
39120
|
const serialized = serializePlan(plan, current);
|
|
39708
39121
|
assertRawFree(serialized, rawValues);
|
|
39709
|
-
const dir = (deps.mkTempDir ?? (() => mkdtempSync(
|
|
39710
|
-
const path =
|
|
39711
|
-
|
|
39122
|
+
const dir = (deps.mkTempDir ?? (() => mkdtempSync(join19(tmpdir(), "aka-plan-"))))();
|
|
39123
|
+
const path = join19(dir, "setup-plan.json");
|
|
39124
|
+
writeFileSync6(path, serialized, { encoding: "utf8", mode: 384 });
|
|
39712
39125
|
return path;
|
|
39713
39126
|
}
|
|
39714
39127
|
function readPlanFile(path) {
|
|
39715
|
-
const text =
|
|
39128
|
+
const text = readFileSync11(path, "utf8");
|
|
39716
39129
|
const json2 = JSON.parse(text);
|
|
39717
39130
|
return PersistedPlanSchema.parse(json2);
|
|
39718
39131
|
}
|
|
39719
39132
|
function deletePlanFile(path) {
|
|
39720
39133
|
rmSync7(path, { force: true });
|
|
39721
|
-
const dir =
|
|
39722
|
-
if (!
|
|
39134
|
+
const dir = dirname4(path);
|
|
39135
|
+
if (!basename2(dir).startsWith("aka-plan-")) return;
|
|
39723
39136
|
try {
|
|
39724
39137
|
rmdirSync(dir);
|
|
39725
39138
|
} catch {
|
|
@@ -39787,8 +39200,8 @@ function buildJoinEntries(hits) {
|
|
|
39787
39200
|
}
|
|
39788
39201
|
|
|
39789
39202
|
// ../../packages/setup-wizard/src/triage/resolve.ts
|
|
39790
|
-
function resolveSuppressions(rec,
|
|
39791
|
-
const byId = new Map(
|
|
39203
|
+
function resolveSuppressions(rec, join23) {
|
|
39204
|
+
const byId = new Map(join23.map((e) => [e.id, e]));
|
|
39792
39205
|
const entries = [];
|
|
39793
39206
|
const skipped = [];
|
|
39794
39207
|
for (const cat of rec.perCategory) {
|
|
@@ -39890,7 +39303,7 @@ function parseTriageStream(text) {
|
|
|
39890
39303
|
return { hits, status: "complete" };
|
|
39891
39304
|
}
|
|
39892
39305
|
function planTriageWriteback(hits, rec) {
|
|
39893
|
-
const
|
|
39306
|
+
const join23 = buildJoinEntries(hits);
|
|
39894
39307
|
const rawValues = hits.map((h) => h.rawMatch);
|
|
39895
39308
|
const skipped = [];
|
|
39896
39309
|
const posture = {};
|
|
@@ -39930,7 +39343,7 @@ function planTriageWriteback(hits, rec) {
|
|
|
39930
39343
|
}
|
|
39931
39344
|
const { entries, skipped: resolveSkips } = resolveSuppressions(
|
|
39932
39345
|
{ perCategory: safeCategories, notes: rec.notes },
|
|
39933
|
-
|
|
39346
|
+
join23
|
|
39934
39347
|
);
|
|
39935
39348
|
skipped.push(...resolveSkips);
|
|
39936
39349
|
let notes = rec.notes;
|
|
@@ -39940,7 +39353,7 @@ function planTriageWriteback(hits, rec) {
|
|
|
39940
39353
|
if (err instanceof RawEgressError) notes = SCRUBBED_NOTES;
|
|
39941
39354
|
else throw err;
|
|
39942
39355
|
}
|
|
39943
|
-
return { entries, posture, showcase, join:
|
|
39356
|
+
return { entries, posture, showcase, join: join23, notes, skipped };
|
|
39944
39357
|
}
|
|
39945
39358
|
function recommendedPosture(evidence) {
|
|
39946
39359
|
return { ...severityFloorPosture(), ...evidence };
|
|
@@ -40199,24 +39612,35 @@ async function runConfirm(deps, planIO) {
|
|
|
40199
39612
|
}
|
|
40200
39613
|
|
|
40201
39614
|
// ../../packages/setup-wizard/src/triage/parse-verdict.ts
|
|
40202
|
-
var
|
|
39615
|
+
var FENCE_OPEN = "```json";
|
|
39616
|
+
var FENCE_CLOSE = "```";
|
|
40203
39617
|
function parseRecommendation(text) {
|
|
40204
|
-
const
|
|
40205
|
-
const lastFence = fences.at(-1);
|
|
40206
|
-
const raw = lastFence?.[1] ?? text;
|
|
39618
|
+
const raw = lastFenceBody(text) ?? text;
|
|
40207
39619
|
return TriageRecommendation.parse(JSON.parse(raw.trim()));
|
|
40208
39620
|
}
|
|
39621
|
+
function lastFenceBody(text) {
|
|
39622
|
+
let body;
|
|
39623
|
+
let open3 = text.indexOf(FENCE_OPEN);
|
|
39624
|
+
while (open3 !== -1) {
|
|
39625
|
+
const start = open3 + FENCE_OPEN.length;
|
|
39626
|
+
const close = text.indexOf(FENCE_CLOSE, start);
|
|
39627
|
+
if (close === -1) break;
|
|
39628
|
+
body = text.slice(start, close);
|
|
39629
|
+
open3 = text.indexOf(FENCE_OPEN, close + FENCE_CLOSE.length);
|
|
39630
|
+
}
|
|
39631
|
+
return body;
|
|
39632
|
+
}
|
|
40209
39633
|
|
|
40210
39634
|
// src/triage/judge.ts
|
|
40211
39635
|
import { execFileSync as execFileSync2 } from "child_process";
|
|
40212
|
-
import { mkdtempSync as mkdtempSync2, readFileSync as
|
|
39636
|
+
import { mkdtempSync as mkdtempSync2, readFileSync as readFileSync12, rmSync as rmSync8 } from "fs";
|
|
40213
39637
|
import { tmpdir as tmpdir2 } from "os";
|
|
40214
|
-
import { dirname as
|
|
40215
|
-
import { fileURLToPath
|
|
39638
|
+
import { dirname as dirname5, join as join20 } from "path";
|
|
39639
|
+
import { fileURLToPath } from "url";
|
|
40216
39640
|
|
|
40217
39641
|
// ../../packages/plugin-sdk/src/bare-command.ts
|
|
40218
39642
|
import { spawnSync } from "child_process";
|
|
40219
|
-
import { homedir as
|
|
39643
|
+
import { homedir as homedir2 } from "os";
|
|
40220
39644
|
import { win32 as win322 } from "path";
|
|
40221
39645
|
var CMD_LINE_MAX = 8191;
|
|
40222
39646
|
var CMD_WRAPPER_ALLOWANCE = 64;
|
|
@@ -40297,11 +39721,11 @@ function isDirectlyExecutable(file2) {
|
|
|
40297
39721
|
return DIRECT_EXTENSIONS.has(win322.extname(file2).toLowerCase());
|
|
40298
39722
|
}
|
|
40299
39723
|
function planBareCommand(command, args, deps = {}) {
|
|
40300
|
-
const
|
|
40301
|
-
if (
|
|
39724
|
+
const platform = deps.platform ?? process.platform;
|
|
39725
|
+
if (platform !== "win32") {
|
|
40302
39726
|
return { file: command, args, options: {}, viaShell: false, resolved: void 0 };
|
|
40303
39727
|
}
|
|
40304
|
-
const home = deps.home ??
|
|
39728
|
+
const home = deps.home ?? homedir2();
|
|
40305
39729
|
const resolve2 = deps.resolve ?? resolveWindowsCommand;
|
|
40306
39730
|
const resolved = resolve2(command, deps.env, home);
|
|
40307
39731
|
if (resolved !== void 0 && isDirectlyExecutable(resolved)) {
|
|
@@ -40322,8 +39746,8 @@ function planBareCommand(command, args, deps = {}) {
|
|
|
40322
39746
|
}
|
|
40323
39747
|
|
|
40324
39748
|
// src/triage/judge.ts
|
|
40325
|
-
var TRIAGE_DIR =
|
|
40326
|
-
var DEFAULT_RUBRIC_PATH =
|
|
39749
|
+
var TRIAGE_DIR = dirname5(fileURLToPath(import.meta.url));
|
|
39750
|
+
var DEFAULT_RUBRIC_PATH = join20(
|
|
40327
39751
|
TRIAGE_DIR,
|
|
40328
39752
|
"..",
|
|
40329
39753
|
"..",
|
|
@@ -40379,7 +39803,7 @@ function runJudge(hits, deps) {
|
|
|
40379
39803
|
if (typeof deps.spawn !== "function") {
|
|
40380
39804
|
throw new TypeError("runJudge requires deps.spawn \u2014 there is no live-spawn fallback");
|
|
40381
39805
|
}
|
|
40382
|
-
const rubric = deps.loadRubric?.() ??
|
|
39806
|
+
const rubric = deps.loadRubric?.() ?? readFileSync12(DEFAULT_RUBRIC_PATH, "utf8");
|
|
40383
39807
|
const hitsJsonl = hits.map((h) => JSON.stringify(toJudgePayload(h))).join("\n");
|
|
40384
39808
|
const fullPrompt = `${rubric}
|
|
40385
39809
|
|
|
@@ -40389,8 +39813,8 @@ function runJudge(hits, deps) {
|
|
|
40389
39813
|
${hitsJsonl}
|
|
40390
39814
|
\`\`\`
|
|
40391
39815
|
`;
|
|
40392
|
-
const outDir = mkdtempSync2(
|
|
40393
|
-
const outFile =
|
|
39816
|
+
const outDir = mkdtempSync2(join20(tmpdir2(), "aka-judge-"));
|
|
39817
|
+
const outFile = join20(outDir, "last-message.txt");
|
|
40394
39818
|
const argv = [
|
|
40395
39819
|
"exec",
|
|
40396
39820
|
"--ephemeral",
|
|
@@ -40407,7 +39831,7 @@ ${hitsJsonl}
|
|
|
40407
39831
|
}
|
|
40408
39832
|
let lastMessage;
|
|
40409
39833
|
try {
|
|
40410
|
-
lastMessage =
|
|
39834
|
+
lastMessage = readFileSync12(outFile, "utf8");
|
|
40411
39835
|
} catch {
|
|
40412
39836
|
throw new Error("codex exec wrote no last-message file");
|
|
40413
39837
|
}
|
|
@@ -40488,8 +39912,8 @@ function table(headers, rows, opts = {}) {
|
|
|
40488
39912
|
const widths = headers.map(
|
|
40489
39913
|
(h, i) => Math.max(visibleLength(h), ...rows.map((r) => visibleLength(r[i] ?? "")))
|
|
40490
39914
|
);
|
|
40491
|
-
const
|
|
40492
|
-
const fmt = (cells) => cells.map((cell, i) => padEnd(cell, widths[i] ?? 0)).join(
|
|
39915
|
+
const sep2 = " ".repeat(gap);
|
|
39916
|
+
const fmt = (cells) => cells.map((cell, i) => padEnd(cell, widths[i] ?? 0)).join(sep2);
|
|
40493
39917
|
const headerLine = fmt(headers.map((h) => h.toUpperCase()));
|
|
40494
39918
|
if (opts.rowSep === true) {
|
|
40495
39919
|
const fullWidth = widths.reduce((n, w) => n + w, 0) + gap * Math.max(0, widths.length - 1);
|
|
@@ -40501,7 +39925,7 @@ function table(headers, rows, opts = {}) {
|
|
|
40501
39925
|
});
|
|
40502
39926
|
return [headerLine, rule, ...body].join("\n");
|
|
40503
39927
|
}
|
|
40504
|
-
const ruleLine = widths.map((w) => "\u2500".repeat(w)).join(
|
|
39928
|
+
const ruleLine = widths.map((w) => "\u2500".repeat(w)).join(sep2);
|
|
40505
39929
|
return [headerLine, ruleLine, ...rows.map(fmt)].join("\n");
|
|
40506
39930
|
}
|
|
40507
39931
|
function fenced(body) {
|
|
@@ -40514,10 +39938,10 @@ function show(body) {
|
|
|
40514
39938
|
}
|
|
40515
39939
|
|
|
40516
39940
|
// src/skills-registry.ts
|
|
40517
|
-
import { readdirSync as
|
|
40518
|
-
import { join as
|
|
40519
|
-
import { fileURLToPath as
|
|
40520
|
-
var SKILLS_DIR =
|
|
39941
|
+
import { readdirSync as readdirSync2, readFileSync as readFileSync13 } from "fs";
|
|
39942
|
+
import { join as join21 } from "path";
|
|
39943
|
+
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
39944
|
+
var SKILLS_DIR = fileURLToPath2(new URL("../skills", import.meta.url));
|
|
40521
39945
|
function frontmatterName(content) {
|
|
40522
39946
|
const block = /^---\n([\s\S]*?)\n---/.exec(content);
|
|
40523
39947
|
if (block === null) return void 0;
|
|
@@ -40525,10 +39949,10 @@ function frontmatterName(content) {
|
|
|
40525
39949
|
return name?.[1];
|
|
40526
39950
|
}
|
|
40527
39951
|
function readRegisteredSkills() {
|
|
40528
|
-
return
|
|
39952
|
+
return readdirSync2(SKILLS_DIR, { withFileTypes: true }).filter((entry) => entry.isDirectory()).flatMap((entry) => {
|
|
40529
39953
|
let content;
|
|
40530
39954
|
try {
|
|
40531
|
-
content =
|
|
39955
|
+
content = readFileSync13(join21(SKILLS_DIR, entry.name, "SKILL.md"), "utf8");
|
|
40532
39956
|
} catch {
|
|
40533
39957
|
return [];
|
|
40534
39958
|
}
|
|
@@ -40679,11 +40103,11 @@ function resolveCreatedBy() {
|
|
|
40679
40103
|
}
|
|
40680
40104
|
}
|
|
40681
40105
|
function loadRubric() {
|
|
40682
|
-
const here =
|
|
40683
|
-
const shipped =
|
|
40684
|
-
if (
|
|
40685
|
-
return
|
|
40686
|
-
|
|
40106
|
+
const here = dirname6(fileURLToPath3(import.meta.url));
|
|
40107
|
+
const shipped = join22(here, "triage-rubric.md");
|
|
40108
|
+
if (existsSync9(shipped)) return readFileSync14(shipped, "utf8");
|
|
40109
|
+
return readFileSync14(
|
|
40110
|
+
join22(here, "..", "..", "..", "packages", "setup-wizard", "assets", "triage-rubric.md"),
|
|
40687
40111
|
"utf8"
|
|
40688
40112
|
);
|
|
40689
40113
|
}
|
|
@@ -40693,10 +40117,12 @@ async function main() {
|
|
|
40693
40117
|
argv,
|
|
40694
40118
|
// fd 0 = stdin; the wizard pipes `backfill.js --triage` into this on preview.
|
|
40695
40119
|
// Called only on the preview path — the confirm path never reads a stream.
|
|
40696
|
-
readStream: (streamPath) => streamPath !== void 0 ?
|
|
40120
|
+
readStream: (streamPath) => streamPath !== void 0 ? readFileSync14(streamPath, "utf8") : readFileSync14(0, "utf8"),
|
|
40697
40121
|
runJudge: (hits) => runJudge(hits, { spawn: spawnCodex, loadRubric }),
|
|
40698
40122
|
openDb: () => {
|
|
40699
|
-
const db = openLocalDatabase(loadConfig().dataDir
|
|
40123
|
+
const db = openLocalDatabase(loadConfig().dataDir, {
|
|
40124
|
+
shippedRegexMatchers: shippedRegexMatchers()
|
|
40125
|
+
});
|
|
40700
40126
|
return {
|
|
40701
40127
|
policies: db.policies,
|
|
40702
40128
|
exceptions: db.exceptions,
|