@akasecurity/ai-tc-codex 0.9.16 → 0.9.17-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.codex-plugin/plugin.json +1 -1
- package/package.json +5 -5
- package/scripts/apply-suppressions.js +678 -1252
- package/scripts/backfill.js +879 -1267
- package/scripts/content-retention.js +761 -2073
- package/scripts/filescan.js +1105 -473
- package/scripts/firstrun.js +1215 -1690
- package/scripts/history-sync.js +750 -2106
- package/scripts/intro.js +123 -2189
- package/scripts/onboard.js +2755 -1185
- package/scripts/post-tool-use.js +1302 -1696
- package/scripts/pre-tool-use.js +903 -1295
- package/scripts/query.js +1215 -1690
- package/scripts/reconcile.js +835 -1277
- package/scripts/remediate.js +920 -1317
- package/scripts/scan-worker.js +97 -13
- package/scripts/session-start.js +1819 -816
- package/scripts/start-light.js +127 -1360
- package/scripts/stop.js +271 -1112
- package/scripts/sync.js +1657 -1005
- package/scripts/user-prompt-submit.js +1042 -1404
package/scripts/reconcile.js
CHANGED
|
@@ -1,892 +1,12 @@
|
|
|
1
|
-
var __create = Object.create;
|
|
2
1
|
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
-
var __commonJS = (cb, mod) => function __require() {
|
|
8
|
-
try {
|
|
9
|
-
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
10
|
-
} catch (e) {
|
|
11
|
-
throw mod = 0, e;
|
|
12
|
-
}
|
|
13
|
-
};
|
|
14
2
|
var __export = (target, all) => {
|
|
15
3
|
for (var name in all)
|
|
16
4
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
17
5
|
};
|
|
18
|
-
var __copyProps = (to, from, except, desc) => {
|
|
19
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
20
|
-
for (let key of __getOwnPropNames(from))
|
|
21
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
22
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
23
|
-
}
|
|
24
|
-
return to;
|
|
25
|
-
};
|
|
26
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
27
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
28
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
29
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
30
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
31
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
32
|
-
mod
|
|
33
|
-
));
|
|
34
|
-
|
|
35
|
-
// ../../node_modules/.pnpm/ignore@7.0.11/node_modules/ignore/index.js
|
|
36
|
-
var require_ignore = __commonJS({
|
|
37
|
-
"../../node_modules/.pnpm/ignore@7.0.11/node_modules/ignore/index.js"(exports, module) {
|
|
38
|
-
"use strict";
|
|
39
|
-
function makeArray(subject) {
|
|
40
|
-
return Array.isArray(subject) ? subject : [subject];
|
|
41
|
-
}
|
|
42
|
-
var UNDEFINED = void 0;
|
|
43
|
-
var EMPTY = "";
|
|
44
|
-
var SPACE = " ";
|
|
45
|
-
var ESCAPE = "\\";
|
|
46
|
-
var REGEX_LITERAL_SPECIAL = /[.*+?()[\]{}^$|\\/]/;
|
|
47
|
-
var REGEX_TEST_BLANK_LINE = /^\uFEFF? *$/;
|
|
48
|
-
var REGEX_INVALID_TRAILING_BACKSLASH = /(?:[^\\]|^)\\$/;
|
|
49
|
-
var REGEX_REPLACE_LEADING_EXCAPED_EXCLAMATION = /^\\!/;
|
|
50
|
-
var REGEX_REPLACE_LEADING_EXCAPED_HASH = /^\\#/;
|
|
51
|
-
var REGEX_SPLITALL_CRLF = /\r?\n/g;
|
|
52
|
-
var DOUBLE_SLASH = "//";
|
|
53
|
-
var SLASH_CODE = 47;
|
|
54
|
-
var DOT_CODE = 46;
|
|
55
|
-
var SLASH3 = "/";
|
|
56
|
-
var TMP_KEY_IGNORE = "node-ignore";
|
|
57
|
-
if (typeof Symbol !== "undefined") {
|
|
58
|
-
TMP_KEY_IGNORE = /* @__PURE__ */ Symbol.for("node-ignore");
|
|
59
|
-
}
|
|
60
|
-
var KEY_IGNORE = TMP_KEY_IGNORE;
|
|
61
|
-
var define = (object2, key, value) => {
|
|
62
|
-
Object.defineProperty(object2, key, { value });
|
|
63
|
-
return value;
|
|
64
|
-
};
|
|
65
|
-
var RETURN_FALSE = () => false;
|
|
66
|
-
var cleanRangeBackSlash = (slashes) => {
|
|
67
|
-
const { length } = slashes;
|
|
68
|
-
return slashes.slice(0, length - length % 2);
|
|
69
|
-
};
|
|
70
|
-
var POSIX_CLASSES = {
|
|
71
|
-
alnum: "0-9A-Za-z",
|
|
72
|
-
alpha: "A-Za-z",
|
|
73
|
-
blank: " \\t",
|
|
74
|
-
cntrl: "\\x00-\\x1f\\x7f",
|
|
75
|
-
digit: "0-9",
|
|
76
|
-
graph: "!-.0-~",
|
|
77
|
-
lower: "a-z",
|
|
78
|
-
print: " -.0-~",
|
|
79
|
-
punct: "!-.:-@\\[-`{-~",
|
|
80
|
-
// git's `sane-ctype.h` classifies \v and \f as control, not space,
|
|
81
|
-
// unlike C's `isspace`
|
|
82
|
-
space: " \\t\\n\\r",
|
|
83
|
-
upper: "A-Z",
|
|
84
|
-
xdigit: "0-9A-Fa-f"
|
|
85
|
-
};
|
|
86
|
-
var CLASS_MEMBERS_TO_ESCAPE = "\\]^-[";
|
|
87
|
-
var escapeMember = (char) => CLASS_MEMBERS_TO_ESCAPE.indexOf(char) < 0 ? char : ESCAPE + char;
|
|
88
|
-
var NON_SLASH = "(?!\\/)";
|
|
89
|
-
var classSource = (negated, body) => {
|
|
90
|
-
if (negated) {
|
|
91
|
-
return `[^\\/${body}]`;
|
|
92
|
-
}
|
|
93
|
-
const source = `[${body}]`;
|
|
94
|
-
return new RegExp(source).test("/") ? NON_SLASH + source : source;
|
|
95
|
-
};
|
|
96
|
-
var scanBracket = (pattern, start) => {
|
|
97
|
-
const { length } = pattern;
|
|
98
|
-
let index = start + 1;
|
|
99
|
-
let negated = EMPTY;
|
|
100
|
-
const lead = pattern[index];
|
|
101
|
-
if (lead === "!" || lead === "^") {
|
|
102
|
-
negated = "^";
|
|
103
|
-
index++;
|
|
104
|
-
}
|
|
105
|
-
let body = EMPTY;
|
|
106
|
-
let prev = EMPTY;
|
|
107
|
-
for (; ; ) {
|
|
108
|
-
const char = pattern[index];
|
|
109
|
-
if (char === UNDEFINED) {
|
|
110
|
-
return null;
|
|
111
|
-
}
|
|
112
|
-
if (char === ESCAPE) {
|
|
113
|
-
const escaped = pattern[index + 1];
|
|
114
|
-
if (escaped === UNDEFINED) {
|
|
115
|
-
return null;
|
|
116
|
-
}
|
|
117
|
-
body += escapeMember(escaped);
|
|
118
|
-
prev = escaped;
|
|
119
|
-
index++;
|
|
120
|
-
} else if (char === "-" && prev && index + 1 < length && pattern[index + 1] !== "]") {
|
|
121
|
-
index++;
|
|
122
|
-
let to = pattern[index];
|
|
123
|
-
if (to === ESCAPE) {
|
|
124
|
-
to = pattern[index += 1];
|
|
125
|
-
}
|
|
126
|
-
if (prev <= to) {
|
|
127
|
-
body += `-${escapeMember(to)}`;
|
|
128
|
-
}
|
|
129
|
-
prev = EMPTY;
|
|
130
|
-
} else if (char === "[" && pattern[index + 1] === ":") {
|
|
131
|
-
const nameStart = index + 2;
|
|
132
|
-
let end = nameStart;
|
|
133
|
-
while (end < length && pattern[end] !== "]") {
|
|
134
|
-
end++;
|
|
135
|
-
}
|
|
136
|
-
if (end === length) {
|
|
137
|
-
return null;
|
|
138
|
-
}
|
|
139
|
-
if (end > nameStart && pattern[end - 1] === ":") {
|
|
140
|
-
const expanded = POSIX_CLASSES[pattern.slice(nameStart, end - 1)];
|
|
141
|
-
if (expanded === UNDEFINED) {
|
|
142
|
-
return null;
|
|
143
|
-
}
|
|
144
|
-
body += expanded;
|
|
145
|
-
prev = EMPTY;
|
|
146
|
-
index = end;
|
|
147
|
-
} else {
|
|
148
|
-
body += escapeMember("[");
|
|
149
|
-
prev = "[";
|
|
150
|
-
index = nameStart - 2;
|
|
151
|
-
}
|
|
152
|
-
} else {
|
|
153
|
-
body += escapeMember(char);
|
|
154
|
-
prev = char;
|
|
155
|
-
}
|
|
156
|
-
index++;
|
|
157
|
-
if (pattern[index] === "]") {
|
|
158
|
-
return {
|
|
159
|
-
end: index,
|
|
160
|
-
source: classSource(negated, body)
|
|
161
|
-
};
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
};
|
|
165
|
-
var NEVER_MATCH = "[]";
|
|
166
|
-
var PLACEHOLDER = "\0";
|
|
167
|
-
var REGEX_RESTORE_PLACEHOLDER = new RegExp(
|
|
168
|
-
`${PLACEHOLDER}(\\d+)${PLACEHOLDER}`,
|
|
169
|
-
"g"
|
|
170
|
-
);
|
|
171
|
-
var TRAILING_WILDCARD = "\uE000";
|
|
172
|
-
var TRAILING_DOUBLESTAR = "\uE001";
|
|
173
|
-
var extractBrackets = (pattern) => {
|
|
174
|
-
const sources = [];
|
|
175
|
-
const hold = (source) => `${PLACEHOLDER}${sources.push(source) - 1}${PLACEHOLDER}`;
|
|
176
|
-
const { length } = pattern;
|
|
177
|
-
let out = EMPTY;
|
|
178
|
-
let index = 0;
|
|
179
|
-
while (index < length) {
|
|
180
|
-
const char = pattern[index];
|
|
181
|
-
if (char === ESCAPE) {
|
|
182
|
-
const escaped = pattern[index + 1];
|
|
183
|
-
if (escaped === "*" || escaped === "[" || escaped === SPACE || escaped === ESCAPE) {
|
|
184
|
-
out += pattern.slice(index, index + 2);
|
|
185
|
-
} else {
|
|
186
|
-
out += hold(
|
|
187
|
-
REGEX_LITERAL_SPECIAL.test(escaped) ? ESCAPE + escaped : escaped
|
|
188
|
-
);
|
|
189
|
-
}
|
|
190
|
-
index += 2;
|
|
191
|
-
} else if (char === PLACEHOLDER) {
|
|
192
|
-
out += hold(`[${PLACEHOLDER}]`);
|
|
193
|
-
index++;
|
|
194
|
-
} else if (char === "[") {
|
|
195
|
-
const scanned = scanBracket(pattern, index);
|
|
196
|
-
if (scanned === null) {
|
|
197
|
-
out += hold(NEVER_MATCH);
|
|
198
|
-
index = length;
|
|
199
|
-
} else {
|
|
200
|
-
out += hold(scanned.source);
|
|
201
|
-
index = scanned.end + 1;
|
|
202
|
-
}
|
|
203
|
-
} else {
|
|
204
|
-
out += char;
|
|
205
|
-
index++;
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
return {
|
|
209
|
-
source: out,
|
|
210
|
-
sources
|
|
211
|
-
};
|
|
212
|
-
};
|
|
213
|
-
var DIRECT = null;
|
|
214
|
-
var REGEX_INNER_SLASH = /\/(?!$)/;
|
|
215
|
-
var REPLACERS = [
|
|
216
|
-
[
|
|
217
|
-
// Remove BOM
|
|
218
|
-
// TODO:
|
|
219
|
-
// Other similar zero-width characters?
|
|
220
|
-
/^\uFEFF/,
|
|
221
|
-
() => EMPTY,
|
|
222
|
-
"\uFEFF"
|
|
223
|
-
],
|
|
224
|
-
[
|
|
225
|
-
// A trailing line terminator, left on when a whole file's contents are
|
|
226
|
-
// added as one pattern rather than split into lines. git never sees one
|
|
227
|
-
// -- it reads a `.gitignore` line by line -- so it is not part of the
|
|
228
|
-
// pattern and is dropped here, apart from the trailing-space trimming,
|
|
229
|
-
// which follows git in touching spaces and nothing else.
|
|
230
|
-
/[\r\n]+$/,
|
|
231
|
-
() => EMPTY
|
|
232
|
-
],
|
|
233
|
-
// > Trailing spaces are ignored unless they are quoted with backslash ("\")
|
|
234
|
-
[
|
|
235
|
-
// Only spaces, never tabs or other whitespace: git trims a trailing run
|
|
236
|
-
// of `' '` and nothing else (dir.c, `trim_trailing_spaces`, a single
|
|
237
|
-
// `case ' '`), so a pattern ending in a tab keeps it as a literal.
|
|
238
|
-
// (a\ ) -> (a )
|
|
239
|
-
// (a ) -> (a)
|
|
240
|
-
// (a ) -> (a)
|
|
241
|
-
// (a \ ) -> (a )
|
|
242
|
-
/((?:\\\\)*?)(\\? +)$/,
|
|
243
|
-
(_, m1, m2) => m1 + (m2.indexOf("\\") === 0 ? SPACE : EMPTY)
|
|
244
|
-
],
|
|
245
|
-
// Replace (\ ) with ' '
|
|
246
|
-
// Only a space: an escaped tab or other whitespace is already a literal by
|
|
247
|
-
// the time it reaches here, and a bare tab must be left as one, not turned
|
|
248
|
-
// into a space.
|
|
249
|
-
// (\ ) -> ' '
|
|
250
|
-
// (\\ ) -> '\\ '
|
|
251
|
-
// (\\\ ) -> '\\ '
|
|
252
|
-
[
|
|
253
|
-
/(\\+?) /g,
|
|
254
|
-
(_, m1) => {
|
|
255
|
-
const { length } = m1;
|
|
256
|
-
return m1.slice(0, length - length % 2) + SPACE;
|
|
257
|
-
}
|
|
258
|
-
],
|
|
259
|
-
// Escape metacharacters
|
|
260
|
-
// which is written down by users but means special for regular expressions.
|
|
261
|
-
// > There are 12 characters with special meanings:
|
|
262
|
-
// > - the backslash \,
|
|
263
|
-
// > - the caret ^,
|
|
264
|
-
// > - the dollar sign $,
|
|
265
|
-
// > - the period or dot .,
|
|
266
|
-
// > - the vertical bar or pipe symbol |,
|
|
267
|
-
// > - the question mark ?,
|
|
268
|
-
// > - the asterisk or star *,
|
|
269
|
-
// > - the plus sign +,
|
|
270
|
-
// > - the opening parenthesis (,
|
|
271
|
-
// > - the closing parenthesis ),
|
|
272
|
-
// > - and the opening square bracket [,
|
|
273
|
-
// > - the opening curly brace {,
|
|
274
|
-
// > These special characters are often called "metacharacters".
|
|
275
|
-
[
|
|
276
|
-
/[\\$.|*+(){^]/g,
|
|
277
|
-
(match) => `\\${match}`
|
|
278
|
-
],
|
|
279
|
-
[
|
|
280
|
-
// > a question mark (?) matches a single character
|
|
281
|
-
/(?!\\)\?/g,
|
|
282
|
-
() => "[^/]",
|
|
283
|
-
"?"
|
|
284
|
-
],
|
|
285
|
-
// leading slash
|
|
286
|
-
[
|
|
287
|
-
// > A leading slash matches the beginning of the pathname.
|
|
288
|
-
// > For example, "/*.c" matches "cat-file.c" but not "mozilla-sha1/sha1.c".
|
|
289
|
-
// A leading slash matches the beginning of the pathname
|
|
290
|
-
/^\//,
|
|
291
|
-
() => "^",
|
|
292
|
-
SLASH3
|
|
293
|
-
],
|
|
294
|
-
// replace special metacharacter slash after the leading slash
|
|
295
|
-
[
|
|
296
|
-
/\//g,
|
|
297
|
-
() => "\\/",
|
|
298
|
-
SLASH3
|
|
299
|
-
],
|
|
300
|
-
[
|
|
301
|
-
// > A leading "**" followed by a slash means match in all directories.
|
|
302
|
-
// > For example, "**/foo" matches file or directory "foo" anywhere,
|
|
303
|
-
// > the same as pattern "foo".
|
|
304
|
-
// > "**/foo/bar" matches file or directory "bar" anywhere that is directly
|
|
305
|
-
// > under directory "foo".
|
|
306
|
-
// Notice that the '*'s have been replaced as '\\*'
|
|
307
|
-
/^\^*(?:\\\*\\\*\\\/)+/,
|
|
308
|
-
// '**/foo' <-> 'foo'
|
|
309
|
-
() => "^(?:.*\\/)?",
|
|
310
|
-
"*"
|
|
311
|
-
],
|
|
312
|
-
// starting
|
|
313
|
-
[
|
|
314
|
-
// there will be no leading '/'
|
|
315
|
-
// (which has been replaced by section "leading slash")
|
|
316
|
-
// If starts with '**', adding a '^' to the regular expression also works
|
|
317
|
-
DIRECT,
|
|
318
|
-
(source, pattern) => {
|
|
319
|
-
if (!source || source[0] === "^") {
|
|
320
|
-
return source;
|
|
321
|
-
}
|
|
322
|
-
const anchor2 = !REGEX_INNER_SLASH.test(pattern) ? "(?:^|\\/)" : "^";
|
|
323
|
-
return anchor2 + source;
|
|
324
|
-
}
|
|
325
|
-
],
|
|
326
|
-
// two globstars
|
|
327
|
-
[
|
|
328
|
-
// Use lookahead assertions so that we could match more than one `'/**'`
|
|
329
|
-
/\\\/\\\*\\\*(?=\\\/|$)/g,
|
|
330
|
-
// Zero, one or several directories
|
|
331
|
-
// should not use '*', or it will be replaced by the next replacer
|
|
332
|
-
// Check if it is not the last `'/**'`
|
|
333
|
-
(_, index, str2) => index + 6 < str2.length ? str2.slice(index + 6) === "\\/" ? "(?:\\/[^\\/]+)+" : "(?:\\/[^\\/]+)*" : `\\/${TRAILING_DOUBLESTAR}`,
|
|
334
|
-
"*"
|
|
335
|
-
],
|
|
336
|
-
// normal intermediate wildcards
|
|
337
|
-
[
|
|
338
|
-
// Never replace escaped '*'
|
|
339
|
-
// ignore rule '\*' will match the path '*'
|
|
340
|
-
// 'abc.*/' -> go
|
|
341
|
-
// 'abc.*' -> skip this rule,
|
|
342
|
-
// coz trailing single wildcard will be handed by [trailing wildcard]
|
|
343
|
-
/(^|[^\\]+)(\\\*)+(?=.+)/g,
|
|
344
|
-
// '*.js' matches '.js'
|
|
345
|
-
// '*.js' doesn't match 'abc'
|
|
346
|
-
(_, p1, p2) => {
|
|
347
|
-
const unescaped = p2.replace(/\\\*/g, "[^\\/]*");
|
|
348
|
-
return p1 + unescaped;
|
|
349
|
-
},
|
|
350
|
-
"*"
|
|
351
|
-
],
|
|
352
|
-
// trailing wildcard, held apart from a literal star
|
|
353
|
-
[
|
|
354
|
-
// The step above leaves a trailing `*` alone, so a single `\*` is all that
|
|
355
|
-
// can be left at the end here. Whether it is a wildcard or a literal
|
|
356
|
-
// turns on the backslashes the user put in front of it: the escaper has
|
|
357
|
-
// since doubled every one, so what stands here is those `2N` doubled
|
|
358
|
-
// backslashes and then the star's own escape. An even number of the
|
|
359
|
-
// original `N` leaves the star unescaped -- a wildcard -- and an odd
|
|
360
|
-
// number escapes it -- a literal. This runs while the two are still
|
|
361
|
-
// distinct, before the unescape steps below collapse the literal onto
|
|
362
|
-
// the very `\*` a wildcard leaves behind.
|
|
363
|
-
/(^|[^\\])((?:\\\\)*)\\\*$/,
|
|
364
|
-
(match, p1, p2) => (
|
|
365
|
-
// `p2` holds the doubled user backslashes; half of them is `N`.
|
|
366
|
-
p2.length / 2 % 2 === 0 ? p1 + p2 + TRAILING_WILDCARD : match
|
|
367
|
-
),
|
|
368
|
-
"*"
|
|
369
|
-
],
|
|
370
|
-
[
|
|
371
|
-
// unescape, revert step 3 except for back slash
|
|
372
|
-
// For example, if a user escape a '\\*',
|
|
373
|
-
// after step 3, the result will be '\\\\\\*'
|
|
374
|
-
/\\\\\\(?=[$.|*+(){^])/g,
|
|
375
|
-
() => ESCAPE,
|
|
376
|
-
ESCAPE + ESCAPE
|
|
377
|
-
],
|
|
378
|
-
[
|
|
379
|
-
// '\\\\' -> '\\'
|
|
380
|
-
/\\\\/g,
|
|
381
|
-
() => ESCAPE,
|
|
382
|
-
ESCAPE + ESCAPE
|
|
383
|
-
],
|
|
384
|
-
[
|
|
385
|
-
// Every real bracket expression -- POSIX classes included -- has already
|
|
386
|
-
// been held aside by `extractBrackets`, so the only `[` left in the
|
|
387
|
-
// pattern is an escaped, literal one.
|
|
388
|
-
// `\` is escaped by step 3
|
|
389
|
-
/\\\[([^\]/]*?)(\\*)($|\])/g,
|
|
390
|
-
// '\\[bar]' -> '\\\\[bar\\]'
|
|
391
|
-
(match, range, endEscape, close) => `\\[${range}${cleanRangeBackSlash(endEscape)}${close}`,
|
|
392
|
-
"["
|
|
393
|
-
],
|
|
394
|
-
// ending
|
|
395
|
-
[
|
|
396
|
-
// 'js' will not match 'js.'
|
|
397
|
-
// 'ab' will not match 'abc'
|
|
398
|
-
DIRECT,
|
|
399
|
-
// WTF!
|
|
400
|
-
// https://git-scm.com/docs/gitignore
|
|
401
|
-
// changes in [2.22.1](https://git-scm.com/docs/gitignore/2.22.1)
|
|
402
|
-
// which re-fixes #24, #38
|
|
403
|
-
// > If there is a separator at the end of the pattern then the pattern
|
|
404
|
-
// > will only match directories, otherwise the pattern can match both
|
|
405
|
-
// > files and directories.
|
|
406
|
-
// 'js*' will not match 'a.js'
|
|
407
|
-
// 'js/' will not match 'a.js'
|
|
408
|
-
// 'js' will match 'a.js' and 'a.js/'
|
|
409
|
-
(source) => {
|
|
410
|
-
const last = source[source.length - 1];
|
|
411
|
-
if (!last || last === TRAILING_WILDCARD || last === TRAILING_DOUBLESTAR) {
|
|
412
|
-
return source;
|
|
413
|
-
}
|
|
414
|
-
return last === SLASH3 ? `${source}$` : `${source}(?=$|\\/$)`;
|
|
415
|
-
}
|
|
416
|
-
]
|
|
417
|
-
];
|
|
418
|
-
var REGEX_REPLACE_TRAILING_WILDCARD = /(^|\\\/)?\uE000$/;
|
|
419
|
-
var MODE_IGNORE = "regex";
|
|
420
|
-
var MODE_CHECK_IGNORE = "checkRegex";
|
|
421
|
-
var UNDERSCORE = "_";
|
|
422
|
-
var replaceTrailingWildcard = (_, p1) => {
|
|
423
|
-
const prefix = p1 ? `${p1}[^/]+` : "[^/]*";
|
|
424
|
-
return `${prefix}(?=$|\\/$)`;
|
|
425
|
-
};
|
|
426
|
-
var REGEX_REPLACE_TRAILING_DOUBLESTAR = /\uE001$/;
|
|
427
|
-
var replaceTrailingDoublestar = () => ".+(?=$|\\/$)";
|
|
428
|
-
var WILDCARD = "[^\\/]*";
|
|
429
|
-
var separatorAfter = (run, at) => {
|
|
430
|
-
let separator = EMPTY;
|
|
431
|
-
for (let index = at + 1; index < run.length && !run[index].wildcard; index++) {
|
|
432
|
-
separator += run[index].single;
|
|
433
|
-
}
|
|
434
|
-
return separator;
|
|
435
|
-
};
|
|
436
|
-
var pinWildcards = (source) => {
|
|
437
|
-
if (source.indexOf(WILDCARD) < 0) {
|
|
438
|
-
return source;
|
|
439
|
-
}
|
|
440
|
-
const tokens = [];
|
|
441
|
-
const { length } = source;
|
|
442
|
-
let index = 0;
|
|
443
|
-
while (index < length) {
|
|
444
|
-
const char = source[index];
|
|
445
|
-
if (source.startsWith(WILDCARD, index)) {
|
|
446
|
-
tokens.push({ wildcard: true });
|
|
447
|
-
index += WILDCARD.length;
|
|
448
|
-
} else if (char === "[") {
|
|
449
|
-
let end = index + 1;
|
|
450
|
-
if (source[end] === "^") {
|
|
451
|
-
end++;
|
|
452
|
-
}
|
|
453
|
-
if (source[end] === "]") {
|
|
454
|
-
end++;
|
|
455
|
-
}
|
|
456
|
-
while (end < length && source[end] !== "]") {
|
|
457
|
-
end += source[end] === ESCAPE ? 2 : 1;
|
|
458
|
-
}
|
|
459
|
-
end++;
|
|
460
|
-
tokens.push({ single: source.slice(index, end) });
|
|
461
|
-
index = end;
|
|
462
|
-
} else if (char === ESCAPE) {
|
|
463
|
-
tokens.push({ single: source.slice(index, index + 2) });
|
|
464
|
-
index += 2;
|
|
465
|
-
} else if (char === "(") {
|
|
466
|
-
let depth = 0;
|
|
467
|
-
let end = index;
|
|
468
|
-
do {
|
|
469
|
-
if (source[end] === ESCAPE) {
|
|
470
|
-
end++;
|
|
471
|
-
} else if (source[end] === "(") {
|
|
472
|
-
depth++;
|
|
473
|
-
} else if (source[end] === ")") {
|
|
474
|
-
depth--;
|
|
475
|
-
}
|
|
476
|
-
end++;
|
|
477
|
-
} while (end < length && depth > 0);
|
|
478
|
-
if ("*+?".indexOf(source[end]) >= 0) {
|
|
479
|
-
end++;
|
|
480
|
-
}
|
|
481
|
-
tokens.push({ boundary: source.slice(index, end) });
|
|
482
|
-
index = end;
|
|
483
|
-
} else if (char === "^" || char === "$") {
|
|
484
|
-
tokens.push({ boundary: char });
|
|
485
|
-
index++;
|
|
486
|
-
} else {
|
|
487
|
-
tokens.push({ single: char });
|
|
488
|
-
index++;
|
|
489
|
-
}
|
|
490
|
-
}
|
|
491
|
-
let out = EMPTY;
|
|
492
|
-
let run = [];
|
|
493
|
-
const flush = () => {
|
|
494
|
-
let lastWildcard;
|
|
495
|
-
run.forEach((token, at) => {
|
|
496
|
-
if (token.wildcard) {
|
|
497
|
-
lastWildcard = at;
|
|
498
|
-
}
|
|
499
|
-
});
|
|
500
|
-
run.forEach((token, at) => {
|
|
501
|
-
if (!token.wildcard) {
|
|
502
|
-
out += token.single;
|
|
503
|
-
return;
|
|
504
|
-
}
|
|
505
|
-
out += at === lastWildcard ? WILDCARD : `(?:(?!${separatorAfter(run, at)})[^\\/])*`;
|
|
506
|
-
});
|
|
507
|
-
run = [];
|
|
508
|
-
};
|
|
509
|
-
tokens.forEach((token) => {
|
|
510
|
-
if (token.boundary === void 0) {
|
|
511
|
-
run.push(token);
|
|
512
|
-
return;
|
|
513
|
-
}
|
|
514
|
-
flush();
|
|
515
|
-
out += token.boundary;
|
|
516
|
-
});
|
|
517
|
-
flush();
|
|
518
|
-
return out;
|
|
519
|
-
};
|
|
520
|
-
var makeRegexPrefix = (pattern) => {
|
|
521
|
-
const { source, sources } = extractBrackets(pattern);
|
|
522
|
-
const replaced = REPLACERS.reduce(
|
|
523
|
-
// A pass whose matcher finds nothing hands back the very string it was
|
|
524
|
-
// given, so asking first costs a search and saves a rewrite. Ten of the
|
|
525
|
-
// fifteen passes never fire for a typical .gitignore line, and between
|
|
526
|
-
// them they were 45% of this chain.
|
|
527
|
-
(prev, [matcher, replacer, required2]) => {
|
|
528
|
-
if (matcher === DIRECT) {
|
|
529
|
-
return replacer(prev, pattern);
|
|
530
|
-
}
|
|
531
|
-
if (required2 !== UNDEFINED && prev.indexOf(required2) < 0) {
|
|
532
|
-
return prev;
|
|
533
|
-
}
|
|
534
|
-
return matcher.test(prev) ? prev.replace(matcher, replacer.bind(pattern)) : prev;
|
|
535
|
-
},
|
|
536
|
-
source
|
|
537
|
-
);
|
|
538
|
-
return sources.length ? replaced.replace(
|
|
539
|
-
REGEX_RESTORE_PLACEHOLDER,
|
|
540
|
-
(match, index) => sources[index]
|
|
541
|
-
) : replaced;
|
|
542
|
-
};
|
|
543
|
-
var checkSourceOf = (body, prefix) => {
|
|
544
|
-
if (body[body.length - 1] === SLASH3) {
|
|
545
|
-
prefix = makeRegexPrefix(body.slice(0, -1));
|
|
546
|
-
}
|
|
547
|
-
const head = prefix.slice(0, -1);
|
|
548
|
-
const last = prefix[prefix.length - 1];
|
|
549
|
-
return last === TRAILING_WILDCARD ? `${head}$` : last === TRAILING_DOUBLESTAR ? `${head}.*$` : NEVER_MATCH;
|
|
550
|
-
};
|
|
551
|
-
var matchesBasename = (body) => {
|
|
552
|
-
const index = body.indexOf(SLASH3);
|
|
553
|
-
return index < 0 || index === body.length - 1;
|
|
554
|
-
};
|
|
555
|
-
var basenameOf = (path) => {
|
|
556
|
-
const end = path.length - 1;
|
|
557
|
-
const index = path.lastIndexOf(
|
|
558
|
-
SLASH3,
|
|
559
|
-
path[end] === SLASH3 ? end - 1 : end
|
|
560
|
-
);
|
|
561
|
-
return index < 0 ? path : path.slice(index + 1);
|
|
562
|
-
};
|
|
563
|
-
var parentOf = (path) => {
|
|
564
|
-
if (path.charCodeAt(0) === SLASH_CODE || path.indexOf(DOUBLE_SLASH) >= 0) {
|
|
565
|
-
const slices = path.split(SLASH3).filter(Boolean);
|
|
566
|
-
slices.pop();
|
|
567
|
-
return slices.length ? slices.join(SLASH3) + SLASH3 : EMPTY;
|
|
568
|
-
}
|
|
569
|
-
const end = path.length - 1;
|
|
570
|
-
const cut = path.lastIndexOf(
|
|
571
|
-
SLASH3,
|
|
572
|
-
path.charCodeAt(end) === SLASH_CODE ? end - 1 : end
|
|
573
|
-
);
|
|
574
|
-
return cut < 0 ? EMPTY : path.slice(0, cut + 1);
|
|
575
|
-
};
|
|
576
|
-
var isString = (subject) => typeof subject === "string";
|
|
577
|
-
var checkPattern = (pattern) => pattern && isString(pattern) && !REGEX_TEST_BLANK_LINE.test(pattern) && !REGEX_INVALID_TRAILING_BACKSLASH.test(pattern) && pattern.indexOf("#") !== 0;
|
|
578
|
-
var splitPattern = (pattern) => pattern.split(REGEX_SPLITALL_CRLF).filter(Boolean);
|
|
579
|
-
var IgnoreRule = class {
|
|
580
|
-
constructor(pattern, mark, body, ignoreCase, negative, prefix) {
|
|
581
|
-
this.pattern = pattern;
|
|
582
|
-
this.mark = mark;
|
|
583
|
-
this.negative = negative;
|
|
584
|
-
define(this, "body", body);
|
|
585
|
-
define(this, "ignoreCase", ignoreCase);
|
|
586
|
-
define(this, "regexPrefix", prefix);
|
|
587
|
-
}
|
|
588
|
-
// Worked out on first use and kept behind an own property, the way `regex`
|
|
589
|
-
// caches itself in `_regex`. Deciding it in the constructor instead would
|
|
590
|
-
// add a fourth `defineProperty` to every rule ever built, which cost 4% of
|
|
591
|
-
// every compile -- including the compiles of rules that are never matched
|
|
592
|
-
// against anything.
|
|
593
|
-
get _basenameOnly() {
|
|
594
|
-
return define(this, "_basenameOnly", matchesBasename(this.body));
|
|
595
|
-
}
|
|
596
|
-
get regex() {
|
|
597
|
-
const key = UNDERSCORE + MODE_IGNORE;
|
|
598
|
-
if (this[key]) {
|
|
599
|
-
return this[key];
|
|
600
|
-
}
|
|
601
|
-
return this._make(MODE_IGNORE, key);
|
|
602
|
-
}
|
|
603
|
-
get checkRegex() {
|
|
604
|
-
const key = UNDERSCORE + MODE_CHECK_IGNORE;
|
|
605
|
-
if (this[key]) {
|
|
606
|
-
return this[key];
|
|
607
|
-
}
|
|
608
|
-
return this._make(MODE_CHECK_IGNORE, key);
|
|
609
|
-
}
|
|
610
|
-
_make(mode, key) {
|
|
611
|
-
const str2 = pinWildcards(
|
|
612
|
-
mode === MODE_IGNORE ? this.regexPrefix.replace(REGEX_REPLACE_TRAILING_WILDCARD, replaceTrailingWildcard).replace(REGEX_REPLACE_TRAILING_DOUBLESTAR, replaceTrailingDoublestar) : checkSourceOf(this.body, this.regexPrefix)
|
|
613
|
-
);
|
|
614
|
-
const regex = this.ignoreCase ? new RegExp(str2, "i") : new RegExp(str2);
|
|
615
|
-
return define(this, key, regex);
|
|
616
|
-
}
|
|
617
|
-
};
|
|
618
|
-
var createRule = ({
|
|
619
|
-
pattern,
|
|
620
|
-
mark
|
|
621
|
-
}, ignoreCase) => {
|
|
622
|
-
let negative = false;
|
|
623
|
-
let body = pattern;
|
|
624
|
-
if (body.indexOf("!") === 0) {
|
|
625
|
-
negative = true;
|
|
626
|
-
body = body.substr(1);
|
|
627
|
-
}
|
|
628
|
-
body = body.replace(REGEX_REPLACE_LEADING_EXCAPED_EXCLAMATION, "!").replace(REGEX_REPLACE_LEADING_EXCAPED_HASH, "#");
|
|
629
|
-
const regexPrefix = makeRegexPrefix(body);
|
|
630
|
-
return new IgnoreRule(
|
|
631
|
-
pattern,
|
|
632
|
-
mark,
|
|
633
|
-
body,
|
|
634
|
-
ignoreCase,
|
|
635
|
-
negative,
|
|
636
|
-
regexPrefix
|
|
637
|
-
);
|
|
638
|
-
};
|
|
639
|
-
var RuleManager = class {
|
|
640
|
-
constructor(ignoreCase) {
|
|
641
|
-
this._ignoreCase = ignoreCase;
|
|
642
|
-
this._rules = [];
|
|
643
|
-
this._basenameCount = 0;
|
|
644
|
-
}
|
|
645
|
-
_add(pattern) {
|
|
646
|
-
if (pattern && pattern[KEY_IGNORE]) {
|
|
647
|
-
this._rules = this._rules.concat(pattern._rules._rules);
|
|
648
|
-
this._basenameCount += pattern._rules._basenameCount;
|
|
649
|
-
this._added = true;
|
|
650
|
-
return;
|
|
651
|
-
}
|
|
652
|
-
if (isString(pattern)) {
|
|
653
|
-
pattern = {
|
|
654
|
-
pattern
|
|
655
|
-
};
|
|
656
|
-
}
|
|
657
|
-
if (checkPattern(pattern.pattern)) {
|
|
658
|
-
const rule = createRule(pattern, this._ignoreCase);
|
|
659
|
-
this._added = true;
|
|
660
|
-
this._rules.push(rule);
|
|
661
|
-
if (matchesBasename(rule.body)) {
|
|
662
|
-
this._basenameCount++;
|
|
663
|
-
}
|
|
664
|
-
}
|
|
665
|
-
}
|
|
666
|
-
// @param {Array<string> | string | Ignore} pattern
|
|
667
|
-
add(pattern) {
|
|
668
|
-
this._added = false;
|
|
669
|
-
makeArray(
|
|
670
|
-
isString(pattern) ? splitPattern(pattern) : pattern
|
|
671
|
-
).forEach(this._add, this);
|
|
672
|
-
if (this._added) {
|
|
673
|
-
this._literalRules = UNDEFINED;
|
|
674
|
-
}
|
|
675
|
-
return this._added;
|
|
676
|
-
}
|
|
677
|
-
// Match the literal 'abc/' for `checkIgnore`, last rule wins. Only a rule
|
|
678
|
-
// ending in a wildcard can match it (see `checkSourceOf`), so the rest
|
|
679
|
-
// are left out once, rather than tested or compiled for every path.
|
|
680
|
-
testLiteral(path) {
|
|
681
|
-
const rules = this._literalRules || (this._literalRules = this._rules.filter(
|
|
682
|
-
({ body }) => body[body.length - (body[body.length - 1] === SLASH3 ? 2 : 1)] === "*"
|
|
683
|
-
));
|
|
684
|
-
let ignored = false;
|
|
685
|
-
let unignored = false;
|
|
686
|
-
let matchedRule;
|
|
687
|
-
for (let index = rules.length - 1; index >= 0; index--) {
|
|
688
|
-
const rule = rules[index];
|
|
689
|
-
if (rule.checkRegex.test(path)) {
|
|
690
|
-
ignored = !rule.negative;
|
|
691
|
-
unignored = rule.negative;
|
|
692
|
-
matchedRule = rule.negative ? UNDEFINED : rule;
|
|
693
|
-
break;
|
|
694
|
-
}
|
|
695
|
-
}
|
|
696
|
-
const ret = {
|
|
697
|
-
ignored,
|
|
698
|
-
unignored
|
|
699
|
-
};
|
|
700
|
-
if (matchedRule) {
|
|
701
|
-
ret.rule = matchedRule;
|
|
702
|
-
}
|
|
703
|
-
return ret;
|
|
704
|
-
}
|
|
705
|
-
// Test one single path without recursively checking parent directories
|
|
706
|
-
//
|
|
707
|
-
// - checkUnignored `boolean` whether should check if the path is unignored,
|
|
708
|
-
// setting `checkUnignored` to `false` could reduce additional
|
|
709
|
-
// path matching.
|
|
710
|
-
// - check `string` either `MODE_IGNORE` or `MODE_CHECK_IGNORE`
|
|
711
|
-
// @returns {TestResult} true if a file is ignored
|
|
712
|
-
test(path, checkUnignored, mode) {
|
|
713
|
-
let ignored = false;
|
|
714
|
-
let unignored = false;
|
|
715
|
-
let matchedRule;
|
|
716
|
-
const rules = this._rules;
|
|
717
|
-
const { length } = rules;
|
|
718
|
-
const shortcut = this._basenameCount * 2 >= length;
|
|
719
|
-
const 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
|
// ../../packages/plugin-sdk/src/config.ts
|
|
876
8
|
import { existsSync as existsSync8 } from "fs";
|
|
877
|
-
import { join as
|
|
878
|
-
|
|
879
|
-
// ../../packages/persistence/src/attached-derived.ts
|
|
880
|
-
import { rmSync } from "fs";
|
|
881
|
-
import { join } from "path";
|
|
882
|
-
var POLICY_CACHE_FILENAME = "policy-cache.json";
|
|
883
|
-
var ATTACHED_FORWARD_STATE_FILENAME = "attached-state.json";
|
|
884
|
-
var ATTACHED_FORWARD_DROPS_FILENAME = "attached-forward-drops.json";
|
|
885
|
-
var ATTACHED_POSTURE_REPORT_FILENAME = "attached-posture-report.json";
|
|
886
|
-
|
|
887
|
-
// ../../packages/persistence/src/control-plane-credential.ts
|
|
888
|
-
import { chmodSync as chmodSync2, lstatSync as lstatSync2, readFileSync, rmSync as rmSync3, statSync } from "fs";
|
|
889
|
-
import { join as join2 } from "path";
|
|
9
|
+
import { join as join17 } from "path";
|
|
890
10
|
|
|
891
11
|
// ../../packages/schema/src/drizzle/deferred-migrations.ts
|
|
892
12
|
var DEFERRED_MIGRATION_TAGS = [
|
|
@@ -1058,6 +178,12 @@ var HOUR_MS = 60 * MINUTE_MS;
|
|
|
1058
178
|
var MAX_TEMPORARY_MS = 24 * HOUR_MS;
|
|
1059
179
|
var ONCE_BACKSTOP_MS = 30 * MINUTE_MS;
|
|
1060
180
|
|
|
181
|
+
// ../../packages/schema/src/invisible-padding.ts
|
|
182
|
+
var INVISIBLE_PADDING = /[\u00AD\u061C\u180E\u200B\u200E\u200F\u2060-\u2064\u202A-\u202E\u2066-\u2069\uFEFF\uFFF9-\uFFFB\u{E0001}\u{E0020}-\u{E007F}]/gu;
|
|
183
|
+
function stripInvisiblePadding(text) {
|
|
184
|
+
return text.replace(INVISIBLE_PADDING, "");
|
|
185
|
+
}
|
|
186
|
+
|
|
1061
187
|
// ../../node_modules/.pnpm/zod@4.6.5/node_modules/zod/v4/classic/external.js
|
|
1062
188
|
var external_exports = {};
|
|
1063
189
|
__export(external_exports, {
|
|
@@ -20793,13 +19919,16 @@ function serviceTierMultiplier(tier) {
|
|
|
20793
19919
|
if (tier === void 0) return 1;
|
|
20794
19920
|
return SERVICE_TIER_MULTIPLIERS.get(tier) ?? 1;
|
|
20795
19921
|
}
|
|
19922
|
+
function promptTokensOf(usage) {
|
|
19923
|
+
return usage.promptTokens ?? (usage.inputTokens ?? 0) + (usage.cacheReadTokens ?? 0) + (usage.cacheWrite1hTokens ?? 0) + (usage.cacheWrite5mTokens ?? 0);
|
|
19924
|
+
}
|
|
20796
19925
|
function costOf(price, usage) {
|
|
20797
19926
|
const metered = [
|
|
20798
19927
|
[usage.cacheWrite1hTokens ?? 0, price.cacheWrite1h],
|
|
20799
19928
|
[usage.cacheWrite5mTokens ?? 0, price.cacheWrite5m],
|
|
20800
19929
|
[usage.cacheReadTokens ?? 0, price.cacheRead]
|
|
20801
19930
|
];
|
|
20802
|
-
const band = price.longContext !== null && (usage
|
|
19931
|
+
const band = price.longContext !== null && promptTokensOf(usage) > price.longContext.thresholdInputTokens ? price.longContext : null;
|
|
20803
19932
|
if (band !== null && (band.input === null || band.output === null)) return null;
|
|
20804
19933
|
const inputRate = band?.input ?? price.input;
|
|
20805
19934
|
const outputRate = band?.output ?? price.output;
|
|
@@ -21009,7 +20138,7 @@ var GATEWAY_VENDOR_SLASH_RE = /^[a-z0-9][\w.-]*\//iu;
|
|
|
21009
20138
|
var BEDROCK_VERSION_RE = /-v\d+:\d+$/u;
|
|
21010
20139
|
var BEDROCK_REVISION_RE = /:\d+$/u;
|
|
21011
20140
|
var VERTEX_VERSION_RE = /@[\w-]+$/u;
|
|
21012
|
-
var DATED_SUFFIX_RE =
|
|
20141
|
+
var DATED_SUFFIX_RE = /-(?:\d{8}|\d{4}-\d{2}-\d{2})$/u;
|
|
21013
20142
|
function stripPlatformDecorations(model) {
|
|
21014
20143
|
let id = model.trim();
|
|
21015
20144
|
let platform2 = null;
|
|
@@ -21159,7 +20288,7 @@ anthropic.model("claude-haiku-4-5", {
|
|
|
21159
20288
|
name: "Claude Haiku 4.5",
|
|
21160
20289
|
ctx: 2e5,
|
|
21161
20290
|
maxOut: 64e3,
|
|
21162
|
-
// Reviewed: fast/cheap tier,
|
|
20291
|
+
// Reviewed: fast/cheap general-purpose tier, not a reasoning or code model.
|
|
21163
20292
|
capability: null,
|
|
21164
20293
|
price: anthropicPrice(1, 5, 0.1),
|
|
21165
20294
|
// The vendor documents `claude-haiku-4-5-20251001` as the versioned id and
|
|
@@ -21290,6 +20419,11 @@ openai.model("gpt-4o", {
|
|
|
21290
20419
|
price: tokenPrice(2.5, 10, { cacheRead: 1.25 }),
|
|
21291
20420
|
on: [...OPENAI_RESELLERS]
|
|
21292
20421
|
});
|
|
20422
|
+
openai.model("gpt-4o-2024-05-13", {
|
|
20423
|
+
name: "GPT-4o (2024-05-13)",
|
|
20424
|
+
price: tokenPrice(5, 15),
|
|
20425
|
+
on: [...OPENAI_RESELLERS]
|
|
20426
|
+
});
|
|
21293
20427
|
openai.model("gpt-4o-mini", {
|
|
21294
20428
|
name: "GPT-4o mini",
|
|
21295
20429
|
price: tokenPrice(0.15, 0.6, { cacheRead: 0.075 }),
|
|
@@ -21309,6 +20443,24 @@ openai.model("o3", {
|
|
|
21309
20443
|
price: tokenPrice(2, 8, { cacheRead: 0.5 }),
|
|
21310
20444
|
on: [...OPENAI_RESELLERS]
|
|
21311
20445
|
});
|
|
20446
|
+
openai.model("text-embedding-3-small", {
|
|
20447
|
+
name: "text-embedding-3-small",
|
|
20448
|
+
capability: "embedding",
|
|
20449
|
+
price: tokenPrice(0.02, 0),
|
|
20450
|
+
on: [...OPENAI_RESELLERS]
|
|
20451
|
+
});
|
|
20452
|
+
openai.model("text-embedding-3-large", {
|
|
20453
|
+
name: "text-embedding-3-large",
|
|
20454
|
+
capability: "embedding",
|
|
20455
|
+
price: tokenPrice(0.13, 0),
|
|
20456
|
+
on: [...OPENAI_RESELLERS]
|
|
20457
|
+
});
|
|
20458
|
+
openai.model("text-embedding-ada-002", {
|
|
20459
|
+
name: "text-embedding-ada-002",
|
|
20460
|
+
capability: "embedding",
|
|
20461
|
+
price: tokenPrice(0.1, 0),
|
|
20462
|
+
on: [...OPENAI_RESELLERS]
|
|
20463
|
+
});
|
|
21312
20464
|
openai.model("gpt-oss-120b", {
|
|
21313
20465
|
name: "GPT-OSS 120B",
|
|
21314
20466
|
openWeights: true,
|
|
@@ -21595,10 +20747,21 @@ var MODEL_ENTRIES = Object.freeze([
|
|
|
21595
20747
|
...alibaba.models(),
|
|
21596
20748
|
...amazon.models()
|
|
21597
20749
|
]);
|
|
20750
|
+
var LONG_CONTEXT_THRESHOLDS = Object.freeze(
|
|
20751
|
+
[
|
|
20752
|
+
...new Set(
|
|
20753
|
+
MODEL_ENTRIES.flatMap(
|
|
20754
|
+
(entry) => [...entry.platforms.values()].flatMap(
|
|
20755
|
+
(offering) => offering.price?.longContext ? [offering.price.longContext.thresholdInputTokens] : []
|
|
20756
|
+
)
|
|
20757
|
+
)
|
|
20758
|
+
)
|
|
20759
|
+
].sort((a, b) => a - b)
|
|
20760
|
+
);
|
|
21598
20761
|
var MODEL_INDEX = buildModelIndex(MODEL_ENTRIES);
|
|
21599
20762
|
|
|
21600
20763
|
// ../../packages/schema/src/model/governance.ts
|
|
21601
|
-
var ModelCapability = external_exports.enum(["reasoning", "code"]);
|
|
20764
|
+
var ModelCapability = external_exports.enum(["reasoning", "code", "embedding"]);
|
|
21602
20765
|
var DataRetention = external_exports.enum([
|
|
21603
20766
|
"zero_retention",
|
|
21604
20767
|
"no_storage",
|
|
@@ -21729,7 +20892,7 @@ var COMPACT = new Intl.NumberFormat("en-US", {
|
|
|
21729
20892
|
|
|
21730
20893
|
// ../../packages/schema/src/token/token-report.ts
|
|
21731
20894
|
var num = (value) => value ?? 0;
|
|
21732
|
-
function costUsageOf(a) {
|
|
20895
|
+
function costUsageOf(a, promptTokens) {
|
|
21733
20896
|
const usage = {
|
|
21734
20897
|
inputTokens: num(a.input_tokens),
|
|
21735
20898
|
outputTokens: num(a.output_tokens),
|
|
@@ -21739,11 +20902,12 @@ function costUsageOf(a) {
|
|
|
21739
20902
|
webSearchRequests: num(a.web_search_requests)
|
|
21740
20903
|
};
|
|
21741
20904
|
if (a.service_tier !== void 0) usage.serviceTier = a.service_tier;
|
|
20905
|
+
if (promptTokens !== void 0) usage.promptTokens = promptTokens;
|
|
21742
20906
|
return usage;
|
|
21743
20907
|
}
|
|
21744
20908
|
function buildTokenReports(leaves, costModel) {
|
|
21745
20909
|
const bySession = /* @__PURE__ */ new Map();
|
|
21746
|
-
for (const { sessionId, attributes } of leaves) {
|
|
20910
|
+
for (const { sessionId, attributes, promptTokens } of leaves) {
|
|
21747
20911
|
const provider = attributes.provider ?? "unknown";
|
|
21748
20912
|
const model = attributes.model ?? "unknown";
|
|
21749
20913
|
const key = `${provider} ${model}`;
|
|
@@ -21762,7 +20926,8 @@ function buildTokenReports(leaves, costModel) {
|
|
|
21762
20926
|
cacheCreation: 0,
|
|
21763
20927
|
cacheRead: 0,
|
|
21764
20928
|
costUsd: 0,
|
|
21765
|
-
priced: false
|
|
20929
|
+
priced: false,
|
|
20930
|
+
partial: false
|
|
21766
20931
|
};
|
|
21767
20932
|
rollups.set(key, acc);
|
|
21768
20933
|
}
|
|
@@ -21770,8 +20935,14 @@ function buildTokenReports(leaves, costModel) {
|
|
|
21770
20935
|
acc.output += num(attributes.output_tokens);
|
|
21771
20936
|
acc.cacheCreation += num(attributes.cache_creation_input_tokens);
|
|
21772
20937
|
acc.cacheRead += num(attributes.cache_read_input_tokens);
|
|
21773
|
-
const leafCost = costModel.costFor({
|
|
21774
|
-
|
|
20938
|
+
const leafCost = costModel.costFor({
|
|
20939
|
+
provider,
|
|
20940
|
+
model,
|
|
20941
|
+
usage: costUsageOf(attributes, promptTokens)
|
|
20942
|
+
});
|
|
20943
|
+
if (leafCost === null) {
|
|
20944
|
+
acc.partial = true;
|
|
20945
|
+
} else {
|
|
21775
20946
|
acc.costUsd += leafCost;
|
|
21776
20947
|
acc.priced = true;
|
|
21777
20948
|
}
|
|
@@ -21787,9 +20958,8 @@ function buildTokenReports(leaves, costModel) {
|
|
|
21787
20958
|
const rollupTotal = acc.input + acc.output + acc.cacheCreation + acc.cacheRead;
|
|
21788
20959
|
totalTokens += rollupTotal;
|
|
21789
20960
|
const estimatedCostUsd = acc.priced ? acc.costUsd : null;
|
|
21790
|
-
if (
|
|
21791
|
-
|
|
21792
|
-
} else {
|
|
20961
|
+
if (acc.partial) anyUnpriced = true;
|
|
20962
|
+
if (estimatedCostUsd !== null) {
|
|
21793
20963
|
anyPriced = true;
|
|
21794
20964
|
costUsd += estimatedCostUsd;
|
|
21795
20965
|
}
|
|
@@ -21812,7 +20982,7 @@ function buildTokenReports(leaves, costModel) {
|
|
|
21812
20982
|
totalTokens,
|
|
21813
20983
|
// Σ of the PRICED rollups; null when none had a known price.
|
|
21814
20984
|
estimatedCostUsd: anyPriced ? costUsd : null,
|
|
21815
|
-
// Any
|
|
20985
|
+
// Any call priced to null means the total understates real spend.
|
|
21816
20986
|
costIsPartial: anyUnpriced
|
|
21817
20987
|
});
|
|
21818
20988
|
}
|
|
@@ -22694,8 +21864,9 @@ var SessionTokenReport = external_exports.object({
|
|
|
22694
21864
|
totalTokens: external_exports.number().int().nonnegative(),
|
|
22695
21865
|
// Σ of the PRICED rollups only; null when no rollup had a known price.
|
|
22696
21866
|
estimatedCostUsd: external_exports.number().nullable(),
|
|
22697
|
-
// True whenever any
|
|
22698
|
-
//
|
|
21867
|
+
// True whenever any call priced to null (an unknown provider/model, or a call
|
|
21868
|
+
// over a long-context threshold whose rate is unpublished), so the total
|
|
21869
|
+
// understates real spend — the UI renders `≥ $X` instead of a falsely
|
|
22699
21870
|
// precise figure rather than silently dropping the unpriced calls.
|
|
22700
21871
|
costIsPartial: external_exports.boolean()
|
|
22701
21872
|
});
|
|
@@ -23572,7 +22743,15 @@ var StorePostureSnapshot = external_exports.object({
|
|
|
23572
22743
|
policyCounts: StorePosturePolicyCounts,
|
|
23573
22744
|
// OPTIONAL, not nullable: a reporter that predates this member keeps
|
|
23574
22745
|
// getting its 200 without a payload change.
|
|
23575
|
-
plugin: StorePosturePlugin.optional()
|
|
22746
|
+
plugin: StorePosturePlugin.optional(),
|
|
22747
|
+
// OPTIONAL, and sent only by a scoped attachment, always as `scoped`. A
|
|
22748
|
+
// machine attachment omits it, so its body is byte for byte the one it
|
|
22749
|
+
// sent before this member existed. Absent therefore means machine-wide OR
|
|
22750
|
+
// a reporter older than this member, never "scoped". Both values parse, so
|
|
22751
|
+
// a sender that one day spells `machine` breaks no receiver; any other
|
|
22752
|
+
// value fails the whole snapshot, which is why the reporter sends a
|
|
22753
|
+
// constant and never the raw mode.
|
|
22754
|
+
attachmentMode: AttachmentMode.optional()
|
|
23576
22755
|
}).meta({ id: "StorePostureSnapshot" });
|
|
23577
22756
|
var CAPTURE_VERSION_PREFIX = "capture/";
|
|
23578
22757
|
var RecordAuditEventRequest = AuditEventInput.extend({
|
|
@@ -24019,7 +23198,7 @@ var Rule = external_exports.strictObject({
|
|
|
24019
23198
|
postValidators: external_exports.array(PostValidatorRef).optional(),
|
|
24020
23199
|
requiresNearby: RequiresNearby.optional(),
|
|
24021
23200
|
examples: external_exports.array(external_exports.string()).optional(),
|
|
24022
|
-
// Whether the matched text is itself sensitive
|
|
23201
|
+
// Whether the matched text is itself sensitive (see RuleEvidence).
|
|
24023
23202
|
evidence: RuleEvidence.optional()
|
|
24024
23203
|
}).meta({ id: "Rule" });
|
|
24025
23204
|
var Author = external_exports.object({
|
|
@@ -24111,7 +23290,13 @@ var DetectionRule = external_exports.object({
|
|
|
24111
23290
|
// Representative matching strings the rule author shipped with the rule. The
|
|
24112
23291
|
// cheapest honest answer to "show me what this rule catches" — every bundled
|
|
24113
23292
|
// rule has them, and they are already in the stored snapshot.
|
|
24114
|
-
examples: external_exports.array(external_exports.string()).optional()
|
|
23293
|
+
examples: external_exports.array(external_exports.string()).optional(),
|
|
23294
|
+
// The rule's DECLARED evidence, as stored. Absent defers to the engine's
|
|
23295
|
+
// classification (ruleEvidence in @akasecurity/detections): a bundled
|
|
23296
|
+
// code-flaw rule reads as 'code' and anything else as 'value', and a rule
|
|
23297
|
+
// in a value category (secret/pii/financial/phi) is always 'value',
|
|
23298
|
+
// whatever it declares.
|
|
23299
|
+
evidence: RuleEvidence.optional()
|
|
24115
23300
|
}).meta({ id: "DetectionRule" });
|
|
24116
23301
|
var DetectionUpdate = external_exports.object({
|
|
24117
23302
|
available: external_exports.boolean(),
|
|
@@ -24179,8 +23364,10 @@ var ImportDetectionRequest = external_exports.object({
|
|
|
24179
23364
|
}).meta({ id: "ImportDetectionRequest" });
|
|
24180
23365
|
|
|
24181
23366
|
// ../../packages/schema/src/zod/detection-build.ts
|
|
24182
|
-
function optional2(key,
|
|
24183
|
-
if (raw === void 0
|
|
23367
|
+
function optional2(key, raw, parse4) {
|
|
23368
|
+
if (raw === void 0) return {};
|
|
23369
|
+
const parsed2 = parse4(raw);
|
|
23370
|
+
if (!parsed2.success || parsed2.data === void 0) return {};
|
|
24184
23371
|
return { [key]: parsed2.data };
|
|
24185
23372
|
}
|
|
24186
23373
|
function isStringArray(value) {
|
|
@@ -24215,10 +23402,12 @@ function rowToDetectionDetail(row, findingsLast30d, update) {
|
|
|
24215
23402
|
category: r.category,
|
|
24216
23403
|
severity: r.severity,
|
|
24217
23404
|
matcher: parsed2.data,
|
|
24218
|
-
//
|
|
24219
|
-
//
|
|
24220
|
-
//
|
|
24221
|
-
//
|
|
23405
|
+
// `appliesTo`, `postValidators` and `requiresNearby` are the rest of what
|
|
23406
|
+
// decides whether this rule fires. Carried so a consumer re-running the
|
|
23407
|
+
// rule (a preview, a tester) evaluates what the engine evaluates rather
|
|
23408
|
+
// than a matcher stripped of its guards — half the bundled catalog
|
|
23409
|
+
// carries at least one of these. `examples` and `evidence` describe the
|
|
23410
|
+
// rule and never gate a match.
|
|
24222
23411
|
//
|
|
24223
23412
|
// Enrichment is deliberately per-field and best-effort, NOT a whole-rule
|
|
24224
23413
|
// `Rule.safeParse`. Two reasons: `Rule` is a strict object pinned to
|
|
@@ -24228,18 +23417,19 @@ function rowToDetectionDetail(row, findingsLast30d, update) {
|
|
|
24228
23417
|
// test should stay exactly what it was, namely a renderable matcher. A
|
|
24229
23418
|
// field that fails validation is omitted, which reads as "not set" and is
|
|
24230
23419
|
// the same thing the consumer saw before this change.
|
|
24231
|
-
...optional2("appliesTo",
|
|
23420
|
+
...optional2("appliesTo", r.appliesTo, (v) => AppliesTo.safeParse(v)),
|
|
24232
23421
|
...optional2(
|
|
24233
23422
|
"postValidators",
|
|
24234
|
-
|
|
24235
|
-
|
|
23423
|
+
r.postValidators,
|
|
23424
|
+
(v) => PostValidatorRef.array().safeParse(v)
|
|
24236
23425
|
),
|
|
24237
|
-
...optional2("requiresNearby",
|
|
23426
|
+
...optional2("requiresNearby", r.requiresNearby, (v) => RequiresNearby.safeParse(v)),
|
|
24238
23427
|
...optional2(
|
|
24239
23428
|
"examples",
|
|
24240
|
-
|
|
24241
|
-
|
|
24242
|
-
)
|
|
23429
|
+
r.examples,
|
|
23430
|
+
(v) => isStringArray(v) ? { success: true, data: v } : { success: false }
|
|
23431
|
+
),
|
|
23432
|
+
...optional2("evidence", r.evidence, (v) => RuleEvidence.safeParse(v))
|
|
24243
23433
|
}
|
|
24244
23434
|
];
|
|
24245
23435
|
});
|
|
@@ -24932,11 +24122,14 @@ var PolicyBundle = external_exports.object({
|
|
|
24932
24122
|
ruleVersions: external_exports.record(external_exports.string(), external_exports.string()).optional(),
|
|
24933
24123
|
// Model ids (the raw `model` string a harness reports, e.g.
|
|
24934
24124
|
// `claude-opus-4-1`) the tenant has PROHIBITED. The plugin refuses to switch
|
|
24935
|
-
// a session onto one (PreModelSwitch)
|
|
24936
|
-
//
|
|
24937
|
-
//
|
|
24938
|
-
//
|
|
24939
|
-
//
|
|
24125
|
+
// a session onto one (PreModelSwitch), refuses a turn that would run on one
|
|
24126
|
+
// (UserPromptSubmit) and refuses a subagent spawn onto one (PreToolUse),
|
|
24127
|
+
// wherever the organization governs the event: everywhere on a
|
|
24128
|
+
// machine-wide attachment, and only in enrolled repositories on a scoped
|
|
24129
|
+
// one (the plugin runtime's `governanceApplies`).
|
|
24130
|
+
// Optional so an older backend — and an older on-disk cache — still
|
|
24131
|
+
// parses; consumers read `?? []`, which is the unenforced behaviour that
|
|
24132
|
+
// predates this field and the safe direction to default.
|
|
24940
24133
|
//
|
|
24941
24134
|
// Ids, not display names: the governance decision is keyed on the exact
|
|
24942
24135
|
// string the harness reports (`model_status_override.versionId` in the
|
|
@@ -25390,6 +24583,8 @@ var AttachmentScopeEntry = external_exports.object({
|
|
|
25390
24583
|
});
|
|
25391
24584
|
var AttachmentScope = external_exports.object({
|
|
25392
24585
|
endpoint: external_exports.string().min(1),
|
|
24586
|
+
tenantName: PluginWhoami.shape.tenantName.optional(),
|
|
24587
|
+
userEmail: PluginWhoami.shape.userEmail.optional(),
|
|
25393
24588
|
entries: external_exports.array(AttachmentScopeEntry)
|
|
25394
24589
|
});
|
|
25395
24590
|
var AttachmentScopeEnvelope = AttachmentScope.extend({ entries: external_exports.array(external_exports.unknown()) });
|
|
@@ -25402,7 +24597,13 @@ function parseAttachmentScope(raw) {
|
|
|
25402
24597
|
const entry = AttachmentScopeEntry.safeParse(candidate);
|
|
25403
24598
|
if (entry.success) entries.push(entry.data);
|
|
25404
24599
|
}
|
|
25405
|
-
|
|
24600
|
+
const { endpoint, tenantName, userEmail } = envelope.data;
|
|
24601
|
+
return {
|
|
24602
|
+
endpoint,
|
|
24603
|
+
...tenantName === void 0 ? {} : { tenantName },
|
|
24604
|
+
...userEmail === void 0 ? {} : { userEmail },
|
|
24605
|
+
entries
|
|
24606
|
+
};
|
|
25406
24607
|
} catch {
|
|
25407
24608
|
return void 0;
|
|
25408
24609
|
}
|
|
@@ -25767,6 +24968,27 @@ var ManagedSettings = external_exports.object({
|
|
|
25767
24968
|
};
|
|
25768
24969
|
}).meta({ id: "ManagedSettings" });
|
|
25769
24970
|
|
|
24971
|
+
// ../../packages/schema/src/zod/mod-policy-snapshot.ts
|
|
24972
|
+
var MOD_POLICY_SNAPSHOT_VERSION = 1;
|
|
24973
|
+
var MOD_POLICY_SNAPSHOT_MAX_BYTES = 4 * 1024 * 1024;
|
|
24974
|
+
var ModPolicySnapshot = external_exports.object({
|
|
24975
|
+
version: external_exports.literal(MOD_POLICY_SNAPSHOT_VERSION),
|
|
24976
|
+
generatedAt: external_exports.iso.datetime(),
|
|
24977
|
+
// The complete effective ruleset, as the hook's runtime scans with it: the
|
|
24978
|
+
// user's enabled installed packs (user-modified and custom packs included).
|
|
24979
|
+
// Absent means the store holds no authoritative snapshot, and the reader
|
|
24980
|
+
// scans with the packs it ships — the hook's own fallback.
|
|
24981
|
+
rules: external_exports.array(Rule).optional(),
|
|
24982
|
+
// Rule-targeted actions (first enabled policy per rule wins).
|
|
24983
|
+
ruleActions: external_exports.record(external_exports.string(), ActionTaken),
|
|
24984
|
+
// The resolved action per detection category.
|
|
24985
|
+
categoryActions: external_exports.record(external_exports.string(), ActionTaken),
|
|
24986
|
+
// Rules with an active exception grant. Honouring a grant means matching a
|
|
24987
|
+
// keyed fingerprint of the value and consuming a use, which only the hook can
|
|
24988
|
+
// do, so the mod leaves a finding of one of these rules for the hook to decide.
|
|
24989
|
+
exceptionRuleIds: external_exports.array(external_exports.string())
|
|
24990
|
+
}).meta({ id: "ModPolicySnapshot" });
|
|
24991
|
+
|
|
25770
24992
|
// ../../packages/schema/src/zod/project-files.ts
|
|
25771
24993
|
var ProjectFileInput = external_exports.object({
|
|
25772
24994
|
path: external_exports.string().min(1),
|
|
@@ -26087,7 +25309,16 @@ var AttachInput = external_exports.object({
|
|
|
26087
25309
|
// 200 matches the tenantName bound beside it in control-plane.ts; nothing
|
|
26088
25310
|
// renders a longer one usefully.
|
|
26089
25311
|
label: printable(200).optional(),
|
|
26090
|
-
accessKey: external_exports.string()
|
|
25312
|
+
accessKey: external_exports.string(),
|
|
25313
|
+
// How much of this machine the attachment is for: everything, or only the
|
|
25314
|
+
// repositories its user enrolls. Optional, so an input without it still
|
|
25315
|
+
// parses; what an absent mode means is for whatever reads it to decide, not
|
|
25316
|
+
// this shape. This member validates the VALUE rather than leaving that to the
|
|
25317
|
+
// call site, a deliberate exception to this module's shape-only rule: a shape
|
|
25318
|
+
// rejection names the field, so a value that is not a mode is refused as a bad
|
|
25319
|
+
// `mode` rather than stripped or passed on. The dashboard's attach action reads
|
|
25320
|
+
// it as the mode to attach in.
|
|
25321
|
+
mode: AttachmentMode.optional()
|
|
26091
25322
|
});
|
|
26092
25323
|
|
|
26093
25324
|
// ../../packages/schema/src/zod/triage.ts
|
|
@@ -26373,6 +25604,18 @@ function fromCaptureStatusAttributes(bag) {
|
|
|
26373
25604
|
return parsedStatus.success ? parsedStatus.data : null;
|
|
26374
25605
|
}
|
|
26375
25606
|
|
|
25607
|
+
// ../../packages/persistence/src/attached-derived.ts
|
|
25608
|
+
import { rmSync } from "fs";
|
|
25609
|
+
import { join } from "path";
|
|
25610
|
+
var POLICY_CACHE_FILENAME = "policy-cache.json";
|
|
25611
|
+
var ATTACHED_FORWARD_STATE_FILENAME = "attached-state.json";
|
|
25612
|
+
var ATTACHED_FORWARD_DROPS_FILENAME = "attached-forward-drops.json";
|
|
25613
|
+
var ATTACHED_POSTURE_REPORT_FILENAME = "attached-posture-report.json";
|
|
25614
|
+
|
|
25615
|
+
// ../../packages/persistence/src/control-plane-credential.ts
|
|
25616
|
+
import { chmodSync as chmodSync2, lstatSync as lstatSync2, readFileSync, rmSync as rmSync3, statSync } from "fs";
|
|
25617
|
+
import { join as join2 } from "path";
|
|
25618
|
+
|
|
26376
25619
|
// ../../packages/persistence/src/paths.ts
|
|
26377
25620
|
import {
|
|
26378
25621
|
chmodSync,
|
|
@@ -26499,6 +25742,14 @@ function repairOrRefuseMode(file2) {
|
|
|
26499
25742
|
}
|
|
26500
25743
|
return "ok";
|
|
26501
25744
|
}
|
|
25745
|
+
function asReadableCredential(value) {
|
|
25746
|
+
const result = AttachedCredentialAny.safeParse(value);
|
|
25747
|
+
if (!result.success) return null;
|
|
25748
|
+
if (attachmentModeOf(result.data) === "machine" && typeof value === "object" && value !== null && Object.hasOwn(value, "mode")) {
|
|
25749
|
+
return null;
|
|
25750
|
+
}
|
|
25751
|
+
return result.data;
|
|
25752
|
+
}
|
|
26502
25753
|
function readControlPlaneCredentialFile(settingsDir2, connection) {
|
|
26503
25754
|
const file2 = controlPlaneCredentialPath(settingsDir2);
|
|
26504
25755
|
let raw;
|
|
@@ -26517,20 +25768,20 @@ function readControlPlaneCredentialFile(settingsDir2, connection) {
|
|
|
26517
25768
|
} catch {
|
|
26518
25769
|
return { usable: false, reason: "malformed" };
|
|
26519
25770
|
}
|
|
26520
|
-
const
|
|
26521
|
-
if (
|
|
26522
|
-
if (!isSafeEndpoint(
|
|
25771
|
+
const credential = asReadableCredential(parsed2);
|
|
25772
|
+
if (credential === null) return { usable: false, reason: "malformed" };
|
|
25773
|
+
if (!isSafeEndpoint(credential.endpoint)) {
|
|
26523
25774
|
return { usable: false, reason: "unsafe-endpoint" };
|
|
26524
25775
|
}
|
|
26525
|
-
if (connection !== void 0 && connection.endpoint !==
|
|
25776
|
+
if (connection !== void 0 && connection.endpoint !== credential.endpoint) {
|
|
26526
25777
|
return {
|
|
26527
25778
|
usable: false,
|
|
26528
25779
|
reason: "endpoint-mismatch",
|
|
26529
|
-
credentialEndpoint:
|
|
25780
|
+
credentialEndpoint: credential.endpoint,
|
|
26530
25781
|
settingsEndpoint: connection.endpoint
|
|
26531
25782
|
};
|
|
26532
25783
|
}
|
|
26533
|
-
return { usable: true, credential
|
|
25784
|
+
return { usable: true, credential };
|
|
26534
25785
|
}
|
|
26535
25786
|
function readControlPlaneCredential(settingsDir2, connection) {
|
|
26536
25787
|
const read = readControlPlaneCredentialFile(settingsDir2, connection);
|
|
@@ -26539,7 +25790,7 @@ function readControlPlaneCredential(settingsDir2, connection) {
|
|
|
26539
25790
|
|
|
26540
25791
|
// ../../packages/persistence/src/database.ts
|
|
26541
25792
|
import { randomUUID as randomUUID11 } from "crypto";
|
|
26542
|
-
import { dirname as dirname2, join as
|
|
25793
|
+
import { dirname as dirname2, join as join8, sep } from "path";
|
|
26543
25794
|
import { DatabaseSync } from "node:sqlite";
|
|
26544
25795
|
|
|
26545
25796
|
// ../../packages/persistence/src/ids.ts
|
|
@@ -26583,6 +25834,7 @@ function captureId(sessionId, contentHash, filePath = null) {
|
|
|
26583
25834
|
canonicalIdentity(["capture", sessionId ?? NO_SESSION, contentHash, filePath ?? NO_PATH])
|
|
26584
25835
|
);
|
|
26585
25836
|
}
|
|
25837
|
+
var DOT = ".".charCodeAt(0);
|
|
26586
25838
|
|
|
26587
25839
|
// ../../packages/persistence/src/internal/snapshot.ts
|
|
26588
25840
|
import { randomUUID } from "crypto";
|
|
@@ -26910,6 +26162,25 @@ function scopeKeysParam(scopeKeys) {
|
|
|
26910
26162
|
var ROOT_SCOPE_KEY = `(SELECT session_root.scope_key
|
|
26911
26163
|
FROM audit_events AS session_root
|
|
26912
26164
|
WHERE session_root.id = COALESCE(audit_events.root_session_id, audit_events.id))`;
|
|
26165
|
+
var COUNTED_IN_SCOPE = `
|
|
26166
|
+
AND ${inScope("scope_key")}
|
|
26167
|
+
AND (event_type IN (${CAPTURE_TYPE_LIST}) OR ${inScope(ROOT_SCOPE_KEY)})`;
|
|
26168
|
+
var DRAIN_TOTALS = `SELECT
|
|
26169
|
+
SUM(CASE WHEN synced_at IS NULL AND started_at < :before THEN 1 ELSE 0 END) AS pending,
|
|
26170
|
+
SUM(CASE WHEN synced_at > 0 THEN 1 ELSE 0 END) AS sent,
|
|
26171
|
+
SUM(CASE WHEN synced_at = ${String(SKIPPED)}
|
|
26172
|
+
AND (sync_failure IS NULL OR sync_failure = 'payload_invalid')
|
|
26173
|
+
THEN 1 ELSE 0 END) AS skipped,
|
|
26174
|
+
SUM(CASE WHEN synced_at = ${String(SKIPPED)}
|
|
26175
|
+
AND sync_failure = 'deployment_refused' THEN 1 ELSE 0 END) AS refused,
|
|
26176
|
+
SUM(CASE WHEN synced_at = ${String(SKIPPED)}
|
|
26177
|
+
AND sync_failure = 'detached_undelivered' THEN 1 ELSE 0 END) AS detached
|
|
26178
|
+
FROM audit_events
|
|
26179
|
+
WHERE event_type IN (${TYPE_LIST})`;
|
|
26180
|
+
var CAPTURE_SKIPS = `SELECT COUNT(*) AS skipped
|
|
26181
|
+
FROM audit_events
|
|
26182
|
+
WHERE synced_at = ${String(SKIPPED)}
|
|
26183
|
+
AND event_type IN (${CAPTURE_TYPE_LIST})`;
|
|
26913
26184
|
var ROW_COLUMNS = `id,
|
|
26914
26185
|
parent_id AS parentId,
|
|
26915
26186
|
root_session_id AS rootSessionId,
|
|
@@ -26985,7 +26256,7 @@ var SqliteHistorySyncRepository = class {
|
|
|
26985
26256
|
);
|
|
26986
26257
|
this.scopedCaptureRowsStmt = db.prepare(
|
|
26987
26258
|
`SELECT ${ROW_COLUMNS}
|
|
26988
|
-
FROM audit_events
|
|
26259
|
+
FROM audit_events INDEXED BY idx_audit_scope_owed
|
|
26989
26260
|
WHERE synced_at IS NULL
|
|
26990
26261
|
AND sync_claimed_at IS NULL
|
|
26991
26262
|
AND outbox_owed = 1
|
|
@@ -27038,40 +26309,28 @@ var SqliteHistorySyncRepository = class {
|
|
|
27038
26309
|
);
|
|
27039
26310
|
this.partitionStmt = db.prepare(`SELECT${PARTITION_BUCKETS}
|
|
27040
26311
|
FROM audit_events${COUNTED_SCOPE}`);
|
|
26312
|
+
this.scopedPartitionStmt = db.prepare(`SELECT${PARTITION_BUCKETS}
|
|
26313
|
+
FROM audit_events${COUNTED_SCOPE}${COUNTED_IN_SCOPE}`);
|
|
27041
26314
|
this.partitionByKindStmt = db.prepare(
|
|
27042
26315
|
`SELECT event_type AS kind,${PARTITION_BUCKETS}
|
|
27043
26316
|
FROM audit_events INDEXED BY idx_audit_events_sync${COUNTED_SCOPE}
|
|
27044
26317
|
GROUP BY event_type`
|
|
27045
26318
|
);
|
|
27046
|
-
this.
|
|
27047
|
-
`SELECT
|
|
27048
|
-
|
|
27049
|
-
|
|
27050
|
-
SUM(CASE WHEN synced_at = ${String(SKIPPED)}
|
|
27051
|
-
AND (sync_failure IS NULL OR sync_failure = 'payload_invalid')
|
|
27052
|
-
THEN 1 ELSE 0 END) AS skipped,
|
|
27053
|
-
SUM(CASE WHEN synced_at = ${String(SKIPPED)}
|
|
27054
|
-
AND sync_failure = 'deployment_refused' THEN 1 ELSE 0 END) AS refused,
|
|
27055
|
-
SUM(CASE WHEN synced_at = ${String(SKIPPED)}
|
|
27056
|
-
AND sync_failure = 'detached_undelivered' THEN 1 ELSE 0 END) AS detached
|
|
27057
|
-
FROM audit_events
|
|
27058
|
-
WHERE event_type IN (${TYPE_LIST})`
|
|
26319
|
+
this.scopedPartitionByKindStmt = db.prepare(
|
|
26320
|
+
`SELECT event_type AS kind,${PARTITION_BUCKETS}
|
|
26321
|
+
FROM audit_events INDEXED BY idx_audit_events_sync${COUNTED_SCOPE}${COUNTED_IN_SCOPE}
|
|
26322
|
+
GROUP BY event_type`
|
|
27059
26323
|
);
|
|
27060
|
-
this.
|
|
27061
|
-
|
|
27062
|
-
|
|
27063
|
-
|
|
27064
|
-
|
|
27065
|
-
|
|
27066
|
-
|
|
27067
|
-
|
|
27068
|
-
|
|
27069
|
-
|
|
27070
|
-
// frees.
|
|
27071
|
-
`SELECT COUNT(*) AS skipped
|
|
27072
|
-
FROM audit_events
|
|
27073
|
-
WHERE synced_at = ${String(SKIPPED)}
|
|
27074
|
-
AND event_type IN (${CAPTURE_TYPE_LIST})`
|
|
26324
|
+
this.countsStmt = db.prepare(DRAIN_TOTALS);
|
|
26325
|
+
this.scopedCountsStmt = db.prepare(
|
|
26326
|
+
`${DRAIN_TOTALS}
|
|
26327
|
+
AND ${inScope("scope_key")}
|
|
26328
|
+
AND ${inScope(ROOT_SCOPE_KEY)}`
|
|
26329
|
+
);
|
|
26330
|
+
this.captureSkipCountStmt = db.prepare(CAPTURE_SKIPS);
|
|
26331
|
+
this.scopedCaptureSkipCountStmt = db.prepare(
|
|
26332
|
+
`${CAPTURE_SKIPS}
|
|
26333
|
+
AND ${inScope("scope_key")}`
|
|
27075
26334
|
);
|
|
27076
26335
|
this.fingerprintStmt = db.prepare(
|
|
27077
26336
|
`SELECT endpoint_fingerprint AS fingerprint, backlog_before AS backlogBefore
|
|
@@ -27185,6 +26444,10 @@ var SqliteHistorySyncRepository = class {
|
|
|
27185
26444
|
scopedCaptureRowsStmt;
|
|
27186
26445
|
scopedCaptureBacklogOwedStmt;
|
|
27187
26446
|
markScopeCapturesOwedStmt;
|
|
26447
|
+
scopedPartitionStmt;
|
|
26448
|
+
scopedPartitionByKindStmt;
|
|
26449
|
+
scopedCountsStmt;
|
|
26450
|
+
scopedCaptureSkipCountStmt;
|
|
27188
26451
|
/**
|
|
27189
26452
|
* The masked detections recorded against one tool call.
|
|
27190
26453
|
*
|
|
@@ -27406,7 +26669,29 @@ var SqliteHistorySyncRepository = class {
|
|
|
27406
26669
|
* in" — and a machine that has never attached has no boundary to pass, so
|
|
27407
26670
|
* requiring one would force a caller to invent one and report the whole store
|
|
27408
26671
|
* as queued.
|
|
26672
|
+
*
|
|
26673
|
+
* `scopeKeys` is a scoped attachment's filter: every bucket then counts only
|
|
26674
|
+
* the rows that pass the drain's reachability rule for that scope
|
|
26675
|
+
* (COUNTED_IN_SCOPE, which also names the one kind of row it counts that the
|
|
26676
|
+
* drain never offers), so a personal repository's rows are in none of them.
|
|
26677
|
+
* Omitted, this runs the machine statement, unchanged; an empty list counts
|
|
26678
|
+
* nothing.
|
|
27409
26679
|
*/
|
|
26680
|
+
partition(scopeKeys) {
|
|
26681
|
+
const row = getRow(
|
|
26682
|
+
scopeKeys === void 0 ? this.partitionStmt : this.scopedPartitionStmt,
|
|
26683
|
+
scopeKeys === void 0 ? {} : { scopeKeys: scopeKeysParam(scopeKeys) }
|
|
26684
|
+
);
|
|
26685
|
+
return {
|
|
26686
|
+
queued: row?.queued ?? 0,
|
|
26687
|
+
inProgress: row?.inProgress ?? 0,
|
|
26688
|
+
synced: row?.synced ?? 0,
|
|
26689
|
+
failed: row?.failed ?? 0,
|
|
26690
|
+
refused: row?.refused ?? 0,
|
|
26691
|
+
detached: row?.detached ?? 0,
|
|
26692
|
+
total: row?.total ?? 0
|
|
26693
|
+
};
|
|
26694
|
+
}
|
|
27410
26695
|
/**
|
|
27411
26696
|
* The same partition, one row per kind that a lane carries.
|
|
27412
26697
|
*
|
|
@@ -27416,11 +26701,14 @@ var SqliteHistorySyncRepository = class {
|
|
|
27416
26701
|
* rendering a fixed list of kinds must therefore treat a missing one as "no
|
|
27417
26702
|
* rows", never as "zero sent"; the two look identical in a bar and mean
|
|
27418
26703
|
* different things.
|
|
26704
|
+
*
|
|
26705
|
+
* `scopeKeys` scopes it with the clause `partition` uses, so the per-kind rows
|
|
26706
|
+
* still sum to the scoped aggregate. An empty list returns no rows.
|
|
27419
26707
|
*/
|
|
27420
|
-
partitionByKind() {
|
|
26708
|
+
partitionByKind(scopeKeys) {
|
|
27421
26709
|
return allRows(
|
|
27422
|
-
this.partitionByKindStmt,
|
|
27423
|
-
{}
|
|
26710
|
+
scopeKeys === void 0 ? this.partitionByKindStmt : this.scopedPartitionByKindStmt,
|
|
26711
|
+
scopeKeys === void 0 ? {} : { scopeKeys: scopeKeysParam(scopeKeys) }
|
|
27424
26712
|
).map((row) => ({
|
|
27425
26713
|
kind: row.kind,
|
|
27426
26714
|
queued: row.queued ?? 0,
|
|
@@ -27432,22 +26720,25 @@ var SqliteHistorySyncRepository = class {
|
|
|
27432
26720
|
total: row.total ?? 0
|
|
27433
26721
|
}));
|
|
27434
26722
|
}
|
|
27435
|
-
|
|
27436
|
-
|
|
27437
|
-
|
|
27438
|
-
|
|
27439
|
-
|
|
27440
|
-
|
|
27441
|
-
|
|
27442
|
-
|
|
27443
|
-
|
|
27444
|
-
|
|
27445
|
-
|
|
27446
|
-
|
|
27447
|
-
|
|
27448
|
-
|
|
27449
|
-
|
|
27450
|
-
|
|
26723
|
+
/**
|
|
26724
|
+
* The drain's totals. `pending` counts only what is inside the backlog; sent
|
|
26725
|
+
* and skipped are totals.
|
|
26726
|
+
*
|
|
26727
|
+
* `scopeKeys` is a scoped attachment's filter, and it scopes every figure,
|
|
26728
|
+
* `capturesSkipped` included: a structural row is counted only when its own
|
|
26729
|
+
* key and its session root's key are among them, a capture when its own key
|
|
26730
|
+
* is. So `pending` is exactly what pendingSessions and pendingRows page out
|
|
26731
|
+
* under the same keys and boundary. Omitted, this runs the machine
|
|
26732
|
+
* statements, unchanged; an empty list counts nothing.
|
|
26733
|
+
*/
|
|
26734
|
+
counts(before, scopeKeys) {
|
|
26735
|
+
const row = getRow(
|
|
26736
|
+
scopeKeys === void 0 ? this.countsStmt : this.scopedCountsStmt,
|
|
26737
|
+
scopeKeys === void 0 ? { before } : { before, scopeKeys: scopeKeysParam(scopeKeys) }
|
|
26738
|
+
);
|
|
26739
|
+
const captures = scopeKeys === void 0 ? getRow(this.captureSkipCountStmt) : getRow(this.scopedCaptureSkipCountStmt, {
|
|
26740
|
+
scopeKeys: scopeKeysParam(scopeKeys)
|
|
26741
|
+
});
|
|
27451
26742
|
return {
|
|
27452
26743
|
pending: row?.pending ?? 0,
|
|
27453
26744
|
sent: row?.sent ?? 0,
|
|
@@ -27699,6 +26990,7 @@ function applyMigrations(db, file2, options = {}) {
|
|
|
27699
26990
|
}
|
|
27700
26991
|
ensureSyncedAtColumn(db, "audit_events");
|
|
27701
26992
|
ensureScopeKeyColumn(db);
|
|
26993
|
+
ensureScopeOwedIndex(db);
|
|
27702
26994
|
ensureScanLedgerTable(db);
|
|
27703
26995
|
ensureHistorySyncTable(db);
|
|
27704
26996
|
ensureBlockedDetectionsTable(db);
|
|
@@ -28139,14 +27431,48 @@ function ensureScopeKeyColumn(db) {
|
|
|
28139
27431
|
function hasScopeKeyColumn(db) {
|
|
28140
27432
|
return columnNames(db, "audit_events", { includeGenerated: true }).includes("scope_key");
|
|
28141
27433
|
}
|
|
27434
|
+
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";
|
|
27435
|
+
function ensureScopeOwedIndex(db) {
|
|
27436
|
+
if (!schemaObjectExists(db, "table", "audit_events")) return;
|
|
27437
|
+
const columns = columnNames(db, "audit_events", { includeGenerated: true });
|
|
27438
|
+
const complete = ["scope_key", "outbox_owed", "synced_at"].every((c) => columns.includes(c));
|
|
27439
|
+
if (!complete) return;
|
|
27440
|
+
db.exec(SCOPE_OWED_INDEX_DDL);
|
|
27441
|
+
}
|
|
28142
27442
|
function ensureScanLedgerTable(db) {
|
|
28143
27443
|
db.exec(`CREATE TABLE IF NOT EXISTS scan_ledger (
|
|
28144
27444
|
path TEXT PRIMARY KEY,
|
|
28145
27445
|
mtime TEXT NOT NULL,
|
|
28146
27446
|
content_hash TEXT NOT NULL,
|
|
28147
27447
|
ruleset_hash TEXT NOT NULL,
|
|
28148
|
-
scanned_at INTEGER NOT NULL
|
|
27448
|
+
scanned_at INTEGER NOT NULL,
|
|
27449
|
+
scope_key TEXT,
|
|
27450
|
+
scope_root TEXT
|
|
28149
27451
|
)`);
|
|
27452
|
+
ensureScanLedgerScopeKeyColumn(db);
|
|
27453
|
+
ensureScanLedgerScopeRootColumn(db);
|
|
27454
|
+
}
|
|
27455
|
+
var SCAN_LEDGER_SCOPE_KEY_DDL = "ALTER TABLE scan_ledger ADD COLUMN scope_key TEXT";
|
|
27456
|
+
var SCAN_LEDGER_SCOPE_ROOT_DDL = "ALTER TABLE scan_ledger ADD COLUMN scope_root TEXT";
|
|
27457
|
+
function ensureScanLedgerScopeKeyColumn(db) {
|
|
27458
|
+
ensureScanLedgerColumn(db, "scope_key", SCAN_LEDGER_SCOPE_KEY_DDL);
|
|
27459
|
+
}
|
|
27460
|
+
function ensureScanLedgerScopeRootColumn(db) {
|
|
27461
|
+
ensureScanLedgerColumn(db, "scope_root", SCAN_LEDGER_SCOPE_ROOT_DDL);
|
|
27462
|
+
}
|
|
27463
|
+
function ensureScanLedgerColumn(db, column, ddl) {
|
|
27464
|
+
if (!schemaObjectExists(db, "table", "scan_ledger")) return;
|
|
27465
|
+
if (hasScanLedgerColumn(db, column)) return;
|
|
27466
|
+
withTransaction(
|
|
27467
|
+
db,
|
|
27468
|
+
() => {
|
|
27469
|
+
if (!hasScanLedgerColumn(db, column)) db.exec(ddl);
|
|
27470
|
+
},
|
|
27471
|
+
"IMMEDIATE"
|
|
27472
|
+
);
|
|
27473
|
+
}
|
|
27474
|
+
function hasScanLedgerColumn(db, column) {
|
|
27475
|
+
return columnNames(db, "scan_ledger").includes(column);
|
|
28150
27476
|
}
|
|
28151
27477
|
function ensureHistorySyncTable(db) {
|
|
28152
27478
|
db.exec(`CREATE TABLE IF NOT EXISTS history_sync (
|
|
@@ -28197,6 +27523,106 @@ function ensureRuleProbeCacheTable(db) {
|
|
|
28197
27523
|
)`);
|
|
28198
27524
|
}
|
|
28199
27525
|
|
|
27526
|
+
// ../../packages/persistence/src/mod-policy-snapshot.ts
|
|
27527
|
+
import { createHash as createHash2 } from "crypto";
|
|
27528
|
+
import { readFileSync as readFileSync2 } from "fs";
|
|
27529
|
+
import { join as join4 } from "path";
|
|
27530
|
+
var MOD_POLICY_SNAPSHOT_FILENAME = "mod-policy.json";
|
|
27531
|
+
function modPolicySnapshotPath(dataDir2) {
|
|
27532
|
+
return join4(dataDir2, MOD_POLICY_SNAPSHOT_FILENAME);
|
|
27533
|
+
}
|
|
27534
|
+
function buildModPolicySnapshot(input2, generatedAt = /* @__PURE__ */ new Date()) {
|
|
27535
|
+
const byRule = /* @__PURE__ */ new Map();
|
|
27536
|
+
const byCategory = /* @__PURE__ */ new Map();
|
|
27537
|
+
for (const policy of input2.policies) {
|
|
27538
|
+
if (!policy.enabled) continue;
|
|
27539
|
+
if ("ruleId" in policy.target) {
|
|
27540
|
+
if (!byRule.has(policy.target.ruleId)) byRule.set(policy.target.ruleId, policy.action);
|
|
27541
|
+
} else if (!byCategory.has(policy.target.category)) {
|
|
27542
|
+
byCategory.set(policy.target.category, policy.action);
|
|
27543
|
+
}
|
|
27544
|
+
}
|
|
27545
|
+
const categoryActions = {};
|
|
27546
|
+
for (const category of DetectionCategory.options) {
|
|
27547
|
+
categoryActions[category] = byCategory.get(category) ?? DEFAULT_ACTIONS[category];
|
|
27548
|
+
}
|
|
27549
|
+
return {
|
|
27550
|
+
version: MOD_POLICY_SNAPSHOT_VERSION,
|
|
27551
|
+
generatedAt: generatedAt.toISOString(),
|
|
27552
|
+
// `examples` is documentation the mod never reads, and a custom pack's are
|
|
27553
|
+
// whatever its author pasted in, so they stay behind.
|
|
27554
|
+
...input2.rules !== void 0 ? { rules: input2.rules.map(withoutExamples) } : {},
|
|
27555
|
+
ruleActions: Object.fromEntries(byRule),
|
|
27556
|
+
categoryActions,
|
|
27557
|
+
exceptionRuleIds: [...new Set(input2.exceptionRuleIds)].sort()
|
|
27558
|
+
};
|
|
27559
|
+
}
|
|
27560
|
+
function assignedRuleActionPolicies(installed) {
|
|
27561
|
+
const out = [];
|
|
27562
|
+
for (const [ruleId, action] of installed.ruleActions) {
|
|
27563
|
+
if (installed.assignedRules.has(ruleId))
|
|
27564
|
+
out.push({ target: { ruleId }, action, enabled: true });
|
|
27565
|
+
}
|
|
27566
|
+
return out;
|
|
27567
|
+
}
|
|
27568
|
+
function withoutExamples(rule) {
|
|
27569
|
+
const copy = { ...rule };
|
|
27570
|
+
delete copy.examples;
|
|
27571
|
+
return copy;
|
|
27572
|
+
}
|
|
27573
|
+
function sameContent(a, b) {
|
|
27574
|
+
return JSON.stringify({ ...a, generatedAt: "" }) === JSON.stringify({ ...b, generatedAt: "" });
|
|
27575
|
+
}
|
|
27576
|
+
function readModPolicySnapshot(dataDir2) {
|
|
27577
|
+
try {
|
|
27578
|
+
const text = readFileSync2(modPolicySnapshotPath(dataDir2), "utf8");
|
|
27579
|
+
if (text.length > MOD_POLICY_SNAPSHOT_MAX_BYTES) return null;
|
|
27580
|
+
const parsed2 = ModPolicySnapshot.safeParse(JSON.parse(text));
|
|
27581
|
+
return parsed2.success ? parsed2.data : null;
|
|
27582
|
+
} catch {
|
|
27583
|
+
return null;
|
|
27584
|
+
}
|
|
27585
|
+
}
|
|
27586
|
+
function writeModPolicySnapshot(dataDir2, snapshot) {
|
|
27587
|
+
const text = JSON.stringify(snapshot);
|
|
27588
|
+
if (Buffer.byteLength(text) > MOD_POLICY_SNAPSHOT_MAX_BYTES) return false;
|
|
27589
|
+
const existing = readModPolicySnapshot(dataDir2);
|
|
27590
|
+
if (existing !== null && sameContent(existing, snapshot)) return false;
|
|
27591
|
+
ensureDataDirSync(dataDir2);
|
|
27592
|
+
writeOwnerOnlyFileSync(modPolicySnapshotPath(dataDir2), text);
|
|
27593
|
+
return true;
|
|
27594
|
+
}
|
|
27595
|
+
function regexProbeKey(matcher) {
|
|
27596
|
+
return createHash2("sha256").update(`${matcher.pattern} ${matcher.flags}`).digest("hex");
|
|
27597
|
+
}
|
|
27598
|
+
function vetRulesForMod(rules, sources, previouslyVetted = /* @__PURE__ */ new Set()) {
|
|
27599
|
+
const bundled = new Set(sources.bundledRegexMatchers().map(regexProbeKey));
|
|
27600
|
+
return rules.filter((rule) => {
|
|
27601
|
+
if (rule.matcher.type !== "regex") return true;
|
|
27602
|
+
const key = regexProbeKey(rule.matcher);
|
|
27603
|
+
const verdict = sources.probeVerdict(key);
|
|
27604
|
+
if (verdict === "quarantined") return false;
|
|
27605
|
+
return verdict === "safe" || bundled.has(key) || previouslyVetted.has(key);
|
|
27606
|
+
});
|
|
27607
|
+
}
|
|
27608
|
+
function modPolicyInputFromStore(sources, previouslyVetted = /* @__PURE__ */ new Set()) {
|
|
27609
|
+
const policies = sources.readPolicies();
|
|
27610
|
+
const snapshot = sources.installedRuleset();
|
|
27611
|
+
const usable = snapshot.installedPacks > 0 && (snapshot.enabledPacks === 0 || snapshot.invalidRules === 0 && snapshot.rules.length > 0);
|
|
27612
|
+
const empty = snapshot.installedPacks > 0 && snapshot.enabledPacks === 0;
|
|
27613
|
+
return {
|
|
27614
|
+
...usable ? { rules: empty ? [] : vetRulesForMod(snapshot.rules, sources, previouslyVetted) } : {},
|
|
27615
|
+
policies: [...policies, ...usable && !empty ? assignedRuleActionPolicies(snapshot) : []],
|
|
27616
|
+
exceptionRuleIds: sources.activeExceptionRuleIds()
|
|
27617
|
+
};
|
|
27618
|
+
}
|
|
27619
|
+
function refreshModPolicySnapshot(dataDir2, sources) {
|
|
27620
|
+
try {
|
|
27621
|
+
writeModPolicySnapshot(dataDir2, buildModPolicySnapshot(modPolicyInputFromStore(sources)));
|
|
27622
|
+
} catch {
|
|
27623
|
+
}
|
|
27624
|
+
}
|
|
27625
|
+
|
|
28200
27626
|
// ../../packages/persistence/src/internal/json.ts
|
|
28201
27627
|
function safeJson(s, fallback) {
|
|
28202
27628
|
if (s == null) return fallback;
|
|
@@ -28371,6 +27797,11 @@ var TIMELINE_COLUMNS = `
|
|
|
28371
27797
|
json_extract(attributes, '$.targetId') AS target_id,
|
|
28372
27798
|
json_extract(attributes, '$.internal') AS internal,
|
|
28373
27799
|
json_extract(attributes, '$.flagged') AS flagged`;
|
|
27800
|
+
var CALL_PROMPT_TOKENS = `(coalesce(input_tokens, 0) + coalesce(cache_read_input_tokens, 0)
|
|
27801
|
+
+ coalesce(ephemeral_1h_input_tokens, 0) + coalesce(ephemeral_5m_input_tokens, 0))`;
|
|
27802
|
+
var CALL_BAND = LONG_CONTEXT_THRESHOLDS.length === 0 ? "0" : LONG_CONTEXT_THRESHOLDS.map((t) => `(${CALL_PROMPT_TOKENS} > ${String(Math.trunc(t))})`).join(
|
|
27803
|
+
" + "
|
|
27804
|
+
);
|
|
28374
27805
|
var LLM_USAGE_SELECT = `
|
|
28375
27806
|
SELECT root_session_id AS sessionId,
|
|
28376
27807
|
provider,
|
|
@@ -28382,9 +27813,10 @@ var LLM_USAGE_SELECT = `
|
|
|
28382
27813
|
coalesce(sum(cache_read_input_tokens), 0) AS cacheReadTokens,
|
|
28383
27814
|
coalesce(sum(ephemeral_1h_input_tokens), 0) AS ephemeral1hTokens,
|
|
28384
27815
|
coalesce(sum(ephemeral_5m_input_tokens), 0) AS ephemeral5mTokens,
|
|
28385
|
-
coalesce(sum(web_search_requests), 0) AS webSearchRequests
|
|
27816
|
+
coalesce(sum(web_search_requests), 0) AS webSearchRequests,
|
|
27817
|
+
coalesce(max(${CALL_PROMPT_TOKENS}), 0) AS promptTokens`;
|
|
28386
27818
|
var LLM_USAGE_SCOPE = `event_type = 'llm_call' AND attributes IS NOT NULL AND root_session_id IS NOT NULL`;
|
|
28387
|
-
var LLM_USAGE_GROUP = `GROUP BY root_session_id, provider, model, service_tier`;
|
|
27819
|
+
var LLM_USAGE_GROUP = `GROUP BY root_session_id, provider, model, service_tier, ${CALL_BAND}`;
|
|
28388
27820
|
function usageLeaves(rows) {
|
|
28389
27821
|
return rows.map((row) => {
|
|
28390
27822
|
const attributes = {
|
|
@@ -28399,7 +27831,7 @@ function usageLeaves(rows) {
|
|
|
28399
27831
|
if (row.provider !== null) attributes.provider = row.provider;
|
|
28400
27832
|
if (row.model !== null) attributes.model = row.model;
|
|
28401
27833
|
if (row.serviceTier !== null) attributes.service_tier = row.serviceTier;
|
|
28402
|
-
return { sessionId: row.sessionId, attributes };
|
|
27834
|
+
return { sessionId: row.sessionId, attributes, promptTokens: row.promptTokens };
|
|
28403
27835
|
});
|
|
28404
27836
|
}
|
|
28405
27837
|
var SESSION_ROOT = `event_type = 'session'`;
|
|
@@ -29733,9 +29165,10 @@ var ACTIVE_REVEAL_GRANT_PREDICATE = `capability = 'reveal_to_model'
|
|
|
29733
29165
|
AND conditions IS NULL
|
|
29734
29166
|
AND ${ACTIVE_PREDICATE}`;
|
|
29735
29167
|
var SqliteExceptionsRepository = class {
|
|
29736
|
-
constructor(db, now = () => Date.now()) {
|
|
29168
|
+
constructor(db, now = () => Date.now(), onChange = () => void 0) {
|
|
29737
29169
|
this.db = db;
|
|
29738
29170
|
this.now = now;
|
|
29171
|
+
this.onChange = onChange;
|
|
29739
29172
|
this.consumeStmt = db.prepare(
|
|
29740
29173
|
`UPDATE exceptions
|
|
29741
29174
|
SET use_count = use_count + 1, last_used_at = :now, updated_at = :now
|
|
@@ -29754,6 +29187,7 @@ var SqliteExceptionsRepository = class {
|
|
|
29754
29187
|
}
|
|
29755
29188
|
db;
|
|
29756
29189
|
now;
|
|
29190
|
+
onChange;
|
|
29757
29191
|
consumeStmt;
|
|
29758
29192
|
insertBlockedStmt;
|
|
29759
29193
|
sweepBlockedStmt;
|
|
@@ -29769,7 +29203,9 @@ var SqliteExceptionsRepository = class {
|
|
|
29769
29203
|
*/
|
|
29770
29204
|
create(input2) {
|
|
29771
29205
|
try {
|
|
29772
|
-
|
|
29206
|
+
const created = this.createSync(input2);
|
|
29207
|
+
this.onChange();
|
|
29208
|
+
return Promise.resolve(created);
|
|
29773
29209
|
} catch (err) {
|
|
29774
29210
|
return Promise.reject(err instanceof Error ? err : new Error(String(err)));
|
|
29775
29211
|
}
|
|
@@ -29900,6 +29336,7 @@ var SqliteExceptionsRepository = class {
|
|
|
29900
29336
|
SET revoked_at = :now, revoked_by = :revokedBy, revoke_reason = :reason, updated_at = :now
|
|
29901
29337
|
WHERE id = :id AND revoked_at IS NULL`
|
|
29902
29338
|
).run({ id, revokedBy, reason: reason ?? null, now });
|
|
29339
|
+
if (Number(result.changes) === 1) this.onChange();
|
|
29903
29340
|
return Promise.resolve(Number(result.changes) === 1);
|
|
29904
29341
|
}
|
|
29905
29342
|
/**
|
|
@@ -29912,6 +29349,15 @@ var SqliteExceptionsRepository = class {
|
|
|
29912
29349
|
const result = this.consumeStmt.run({ id, now });
|
|
29913
29350
|
return Promise.resolve(Number(result.changes) === 1);
|
|
29914
29351
|
}
|
|
29352
|
+
/** The rule ids with at least one active grant, under any key version. */
|
|
29353
|
+
activeRuleIds(now = this.now()) {
|
|
29354
|
+
return allRows(
|
|
29355
|
+
this.db.prepare(
|
|
29356
|
+
`SELECT DISTINCT rule_id AS ruleId FROM exceptions WHERE ${ACTIVE_PREDICATE}`
|
|
29357
|
+
),
|
|
29358
|
+
{ now }
|
|
29359
|
+
).map((row) => row.ruleId);
|
|
29360
|
+
}
|
|
29915
29361
|
/**
|
|
29916
29362
|
* The evaluation subset of every active grant under one fingerprint key
|
|
29917
29363
|
* version — what rides the policy bundle to the hook. Grants written under
|
|
@@ -31035,28 +30481,28 @@ var SqliteInspectionFindingsRepository = class {
|
|
|
31035
30481
|
};
|
|
31036
30482
|
|
|
31037
30483
|
// ../../packages/persistence/src/repositories/installed-packs.ts
|
|
31038
|
-
import { createHash as
|
|
30484
|
+
import { createHash as createHash3, randomUUID as randomUUID4 } from "crypto";
|
|
31039
30485
|
|
|
31040
30486
|
// ../../packages/persistence/src/policy-floor.ts
|
|
31041
|
-
import { readFileSync as
|
|
31042
|
-
import { join as
|
|
30487
|
+
import { readFileSync as readFileSync6 } from "fs";
|
|
30488
|
+
import { join as join7 } from "path";
|
|
31043
30489
|
|
|
31044
30490
|
// ../../packages/persistence/src/local-layout.ts
|
|
31045
30491
|
import { renameSync as renameSync3 } from "fs";
|
|
31046
30492
|
import { mkdir } from "fs/promises";
|
|
31047
30493
|
import { homedir } from "os";
|
|
31048
|
-
import { join as
|
|
30494
|
+
import { join as join5 } from "path";
|
|
31049
30495
|
function defaultDataDir() {
|
|
31050
|
-
return
|
|
30496
|
+
return join5(homedir(), ".aka");
|
|
31051
30497
|
}
|
|
31052
30498
|
function settingsDir(base = defaultDataDir()) {
|
|
31053
|
-
return
|
|
30499
|
+
return join5(base, "settings");
|
|
31054
30500
|
}
|
|
31055
30501
|
function dataDir(base = defaultDataDir()) {
|
|
31056
|
-
return
|
|
30502
|
+
return join5(base, "data");
|
|
31057
30503
|
}
|
|
31058
30504
|
function dbPath(base = defaultDataDir()) {
|
|
31059
|
-
return
|
|
30505
|
+
return join5(dataDir(base), "aka.db");
|
|
31060
30506
|
}
|
|
31061
30507
|
async function ensureDataDir(dir = defaultDataDir()) {
|
|
31062
30508
|
await mkdir(dir, { recursive: true, mode: DATA_DIR_MODE });
|
|
@@ -31073,8 +30519,8 @@ function migrateLegacyLayout(base = defaultDataDir()) {
|
|
|
31073
30519
|
for (const { name, dest } of moves) {
|
|
31074
30520
|
try {
|
|
31075
30521
|
ensureDataDirSync(dest);
|
|
31076
|
-
const moved =
|
|
31077
|
-
renameSync3(
|
|
30522
|
+
const moved = join5(dest, name);
|
|
30523
|
+
renameSync3(join5(base, name), moved);
|
|
31078
30524
|
tightenFile(moved);
|
|
31079
30525
|
} catch {
|
|
31080
30526
|
}
|
|
@@ -31082,8 +30528,8 @@ function migrateLegacyLayout(base = defaultDataDir()) {
|
|
|
31082
30528
|
}
|
|
31083
30529
|
|
|
31084
30530
|
// ../../packages/persistence/src/settings.ts
|
|
31085
|
-
import { readFileSync as
|
|
31086
|
-
import { join as
|
|
30531
|
+
import { readFileSync as readFileSync5 } from "fs";
|
|
30532
|
+
import { join as join6 } from "path";
|
|
31087
30533
|
|
|
31088
30534
|
// ../../packages/persistence/src/file-lock.ts
|
|
31089
30535
|
import { randomUUID as randomUUID3 } from "crypto";
|
|
@@ -31091,7 +30537,7 @@ import {
|
|
|
31091
30537
|
closeSync,
|
|
31092
30538
|
existsSync as existsSync2,
|
|
31093
30539
|
openSync,
|
|
31094
|
-
readFileSync as
|
|
30540
|
+
readFileSync as readFileSync3,
|
|
31095
30541
|
rmSync as rmSync5,
|
|
31096
30542
|
statSync as statSync3,
|
|
31097
30543
|
writeFileSync as writeFileSync2
|
|
@@ -31100,7 +30546,7 @@ import { hostname as hostname3 } from "os";
|
|
|
31100
30546
|
var PARK = new Int32Array(new SharedArrayBuffer(4));
|
|
31101
30547
|
|
|
31102
30548
|
// ../../packages/persistence/src/managed-settings.ts
|
|
31103
|
-
import { readFileSync as
|
|
30549
|
+
import { readFileSync as readFileSync4 } from "fs";
|
|
31104
30550
|
import { posix, win32 } from "path";
|
|
31105
30551
|
function managedSettingsPaths(platform2 = process.platform) {
|
|
31106
30552
|
if (platform2 === "darwin") {
|
|
@@ -31119,7 +30565,7 @@ function readManagedSettings(paths = testOnlyManagedPaths ?? managedSettingsPath
|
|
|
31119
30565
|
for (const path of paths) {
|
|
31120
30566
|
let text;
|
|
31121
30567
|
try {
|
|
31122
|
-
text =
|
|
30568
|
+
text = readFileSync4(path, "utf8");
|
|
31123
30569
|
} catch {
|
|
31124
30570
|
continue;
|
|
31125
30571
|
}
|
|
@@ -31173,7 +30619,7 @@ function readWorkspaceSettings(base = defaultDataDir()) {
|
|
|
31173
30619
|
return overlayManagedSettings(readUserSettings(base), readManagedSettings());
|
|
31174
30620
|
}
|
|
31175
30621
|
function readUserSettings(base) {
|
|
31176
|
-
const record2 = readJson(
|
|
30622
|
+
const record2 = readJson(join6(settingsDir(base), SETTINGS_FILENAME));
|
|
31177
30623
|
if (!record2) return defaultWorkspaceSettings();
|
|
31178
30624
|
try {
|
|
31179
30625
|
return WorkspaceSettings.parse(record2);
|
|
@@ -31184,7 +30630,7 @@ function readUserSettings(base) {
|
|
|
31184
30630
|
function readJson(file2) {
|
|
31185
30631
|
let text;
|
|
31186
30632
|
try {
|
|
31187
|
-
text =
|
|
30633
|
+
text = readFileSync5(file2, "utf8");
|
|
31188
30634
|
} catch {
|
|
31189
30635
|
return null;
|
|
31190
30636
|
}
|
|
@@ -31224,7 +30670,7 @@ var PolicyFloorError = class extends Error {
|
|
|
31224
30670
|
};
|
|
31225
30671
|
function readCachedPolicyBundle(base = defaultDataDir()) {
|
|
31226
30672
|
try {
|
|
31227
|
-
const raw =
|
|
30673
|
+
const raw = readFileSync6(join7(dataDir(base), POLICY_CACHE_FILENAME), "utf8");
|
|
31228
30674
|
const parsed2 = JSON.parse(raw);
|
|
31229
30675
|
if (typeof parsed2 !== "object" || parsed2 === null) return null;
|
|
31230
30676
|
return PolicyBundle.parse(parsed2.bundle);
|
|
@@ -31348,7 +30794,7 @@ function inventorySignature(packs2) {
|
|
|
31348
30794
|
return packs2.map((p) => `${p.namespace}/${p.packId}@${p.version}#${hashRules(p.rulesJson)}`).sort().join(",");
|
|
31349
30795
|
}
|
|
31350
30796
|
function hashRules(rulesJson) {
|
|
31351
|
-
return
|
|
30797
|
+
return createHash3("sha256").update(rulesJson).digest("hex");
|
|
31352
30798
|
}
|
|
31353
30799
|
function parseVersion(v) {
|
|
31354
30800
|
const m = /^(\d+)\.(\d+)\.(\d+)/.exec(v);
|
|
@@ -31390,9 +30836,10 @@ var SqliteInstalledPacksRepository = class {
|
|
|
31390
30836
|
* from `openLocalDatabase`, which is the single construction site that owns a
|
|
31391
30837
|
* real `~/.aka`.
|
|
31392
30838
|
*/
|
|
31393
|
-
constructor(db, baseDir) {
|
|
30839
|
+
constructor(db, baseDir, onChange = () => void 0) {
|
|
31394
30840
|
this.db = db;
|
|
31395
30841
|
this.baseDir = baseDir;
|
|
30842
|
+
this.onChange = onChange;
|
|
31396
30843
|
this.insertMissingStmt = db.prepare(
|
|
31397
30844
|
`INSERT INTO installed_packs (id, namespace, pack_id, version, name, rules_json, enabled, policy_id, created_at, updated_at)
|
|
31398
30845
|
VALUES (:id, :namespace, :packId, :version, :name, :rulesJson, 1, :policyId, :now, :now)
|
|
@@ -31421,6 +30868,7 @@ var SqliteInstalledPacksRepository = class {
|
|
|
31421
30868
|
}
|
|
31422
30869
|
db;
|
|
31423
30870
|
baseDir;
|
|
30871
|
+
onChange;
|
|
31424
30872
|
insertMissingStmt;
|
|
31425
30873
|
upsertAvailableStmt;
|
|
31426
30874
|
signatureStmt;
|
|
@@ -31493,6 +30941,7 @@ var SqliteInstalledPacksRepository = class {
|
|
|
31493
30941
|
},
|
|
31494
30942
|
"IMMEDIATE"
|
|
31495
30943
|
);
|
|
30944
|
+
this.onChange();
|
|
31496
30945
|
} catch {
|
|
31497
30946
|
}
|
|
31498
30947
|
}
|
|
@@ -31567,6 +31016,7 @@ var SqliteInstalledPacksRepository = class {
|
|
|
31567
31016
|
},
|
|
31568
31017
|
"IMMEDIATE"
|
|
31569
31018
|
);
|
|
31019
|
+
if (changed) this.onChange();
|
|
31570
31020
|
return changed;
|
|
31571
31021
|
}
|
|
31572
31022
|
/**
|
|
@@ -31808,6 +31258,7 @@ var SqliteInstalledPacksRepository = class {
|
|
|
31808
31258
|
`UPDATE installed_packs SET policy_id = :policyId, updated_at = :now
|
|
31809
31259
|
WHERE namespace = :namespace AND pack_id = :packId`
|
|
31810
31260
|
).run({ policyId, now: Date.now(), namespace, packId });
|
|
31261
|
+
if (Number(res.changes) > 0) this.onChange();
|
|
31811
31262
|
return Number(res.changes) > 0;
|
|
31812
31263
|
}
|
|
31813
31264
|
/**
|
|
@@ -31832,6 +31283,7 @@ var SqliteInstalledPacksRepository = class {
|
|
|
31832
31283
|
`UPDATE installed_packs SET enabled = :enabled, updated_at = :now
|
|
31833
31284
|
WHERE namespace = :namespace AND pack_id = :packId`
|
|
31834
31285
|
).run({ enabled: boolToInt(enabled), now: Date.now(), namespace, packId });
|
|
31286
|
+
if (Number(res.changes) > 0) this.onChange();
|
|
31835
31287
|
return Number(res.changes) > 0;
|
|
31836
31288
|
}
|
|
31837
31289
|
// Fingerprint of the recorded available mirror — compared against the
|
|
@@ -32729,13 +32181,19 @@ var SqliteInventoryAssetsRepository = class {
|
|
|
32729
32181
|
import { randomUUID as randomUUID6 } from "crypto";
|
|
32730
32182
|
var SEED_BATCH_WINDOW_MS = 6e4;
|
|
32731
32183
|
var SqlitePoliciesRepository = class {
|
|
32732
|
-
constructor(db) {
|
|
32184
|
+
constructor(db, onChange = () => void 0) {
|
|
32733
32185
|
this.db = db;
|
|
32186
|
+
this.onChange = onChange;
|
|
32734
32187
|
}
|
|
32735
32188
|
db;
|
|
32189
|
+
onChange;
|
|
32736
32190
|
readPolicies() {
|
|
32191
|
+
return Promise.resolve(this.listPolicies());
|
|
32192
|
+
}
|
|
32193
|
+
/** The synchronous read behind {@link readPolicies}. */
|
|
32194
|
+
listPolicies() {
|
|
32737
32195
|
const rows = allRows(this.db.prepare("SELECT * FROM policies"));
|
|
32738
|
-
|
|
32196
|
+
return mapRowsTolerant(rows, (row) => {
|
|
32739
32197
|
const target = JSON.parse(row.target);
|
|
32740
32198
|
const customKeywords = row.custom_keywords ? JSON.parse(row.custom_keywords) : void 0;
|
|
32741
32199
|
return Policy.parse({
|
|
@@ -32747,7 +32205,6 @@ var SqlitePoliciesRepository = class {
|
|
|
32747
32205
|
customKeywords
|
|
32748
32206
|
});
|
|
32749
32207
|
});
|
|
32750
|
-
return Promise.resolve(policies);
|
|
32751
32208
|
}
|
|
32752
32209
|
// Seed one policy per bundled category at Monitor so the detection-type config
|
|
32753
32210
|
// exists from first run. An unassigned pack's rules follow these rows, so
|
|
@@ -32758,7 +32215,7 @@ var SqlitePoliciesRepository = class {
|
|
|
32758
32215
|
const count = countScalar(this.db, "SELECT count(*) AS n FROM policies");
|
|
32759
32216
|
if (count > 0) {
|
|
32760
32217
|
this.markEarlierChoices();
|
|
32761
|
-
this.monitorUntouchedSeeds();
|
|
32218
|
+
if (this.monitorUntouchedSeeds()) this.onChange();
|
|
32762
32219
|
return;
|
|
32763
32220
|
}
|
|
32764
32221
|
const stmt = this.db.prepare(
|
|
@@ -32775,6 +32232,7 @@ var SqlitePoliciesRepository = class {
|
|
|
32775
32232
|
});
|
|
32776
32233
|
}
|
|
32777
32234
|
});
|
|
32235
|
+
this.onChange();
|
|
32778
32236
|
}
|
|
32779
32237
|
// Before this build, upsertCategoryAction INSERTed a new row with updated_at
|
|
32780
32238
|
// equal to created_at, so a choice made for a category that had no row yet
|
|
@@ -32840,7 +32298,7 @@ var SqlitePoliciesRepository = class {
|
|
|
32840
32298
|
).filter(
|
|
32841
32299
|
(row) => DEFAULT_ACTIONS[row.category] === row.action
|
|
32842
32300
|
);
|
|
32843
|
-
if (untouched.length === 0) return;
|
|
32301
|
+
if (untouched.length === 0) return false;
|
|
32844
32302
|
const stmt = this.db.prepare(
|
|
32845
32303
|
`UPDATE policies SET action = 'log'
|
|
32846
32304
|
WHERE scope = 'global' AND json_extract(target, '$.category') = :category
|
|
@@ -32851,6 +32309,7 @@ var SqlitePoliciesRepository = class {
|
|
|
32851
32309
|
stmt.run({ category: row.category, seeded: row.action });
|
|
32852
32310
|
}
|
|
32853
32311
|
});
|
|
32312
|
+
return true;
|
|
32854
32313
|
}
|
|
32855
32314
|
// Insert-or-update the single global per-category policy row, keyed on the
|
|
32856
32315
|
// existing uq_policies_scope_target unique index (scope, target). `action`
|
|
@@ -32867,6 +32326,7 @@ var SqlitePoliciesRepository = class {
|
|
|
32867
32326
|
ON CONFLICT(scope, target) DO UPDATE SET action = excluded.action, enabled = 1,
|
|
32868
32327
|
updated_at = MAX(excluded.updated_at, policies.created_at + 1)`
|
|
32869
32328
|
).run({ id: randomUUID6(), target: JSON.stringify({ category }), action, now });
|
|
32329
|
+
this.onChange();
|
|
32870
32330
|
}
|
|
32871
32331
|
// Caps every global per-category policy currently set to block/redact down
|
|
32872
32332
|
// to warn (see warn-era-cap.ts). Rule-targeted policies are untouched.
|
|
@@ -32877,6 +32337,7 @@ var SqlitePoliciesRepository = class {
|
|
|
32877
32337
|
WHERE scope='global' AND action IN ('block','redact')
|
|
32878
32338
|
AND json_extract(target,'$.category') IS NOT NULL`
|
|
32879
32339
|
).run({ now: Date.now() });
|
|
32340
|
+
if (Number(info.changes) > 0) this.onChange();
|
|
32880
32341
|
return Number(info.changes);
|
|
32881
32342
|
}
|
|
32882
32343
|
// Whether the category's row was ever written after it was created — by the
|
|
@@ -33196,31 +32657,45 @@ var SqliteScanLedgerRepository = class {
|
|
|
33196
32657
|
constructor(db) {
|
|
33197
32658
|
this.db = db;
|
|
33198
32659
|
this.upsertStmt = db.prepare(
|
|
33199
|
-
`INSERT INTO scan_ledger
|
|
33200
|
-
|
|
32660
|
+
`INSERT INTO scan_ledger
|
|
32661
|
+
(path, mtime, content_hash, ruleset_hash, scope_key, scope_root, scanned_at)
|
|
32662
|
+
VALUES (:path, :mtime, :contentHash, :rulesetHash, :scopeKey, :scopeRoot, :scannedAt)
|
|
33201
32663
|
ON CONFLICT (path) DO UPDATE SET
|
|
33202
32664
|
mtime = excluded.mtime,
|
|
33203
32665
|
content_hash = excluded.content_hash,
|
|
33204
32666
|
ruleset_hash = excluded.ruleset_hash,
|
|
32667
|
+
scope_key = excluded.scope_key,
|
|
32668
|
+
scope_root = excluded.scope_root,
|
|
33205
32669
|
scanned_at = excluded.scanned_at`
|
|
33206
32670
|
);
|
|
33207
32671
|
this.readStmt = db.prepare(
|
|
33208
|
-
`SELECT path, mtime, content_hash AS contentHash
|
|
32672
|
+
`SELECT path, mtime, content_hash AS contentHash, scope_key AS scopeKey,
|
|
32673
|
+
scope_root AS scopeRoot
|
|
33209
32674
|
FROM scan_ledger WHERE ruleset_hash = :rulesetHash`
|
|
33210
32675
|
);
|
|
33211
32676
|
this.pathsStmt = db.prepare(`SELECT path FROM scan_ledger`);
|
|
32677
|
+
this.pathKeysStmt = db.prepare(`SELECT path, scope_key AS scopeKey FROM scan_ledger`);
|
|
33212
32678
|
}
|
|
33213
32679
|
db;
|
|
33214
32680
|
upsertStmt;
|
|
33215
32681
|
readStmt;
|
|
33216
32682
|
pathsStmt;
|
|
32683
|
+
pathKeysStmt;
|
|
33217
32684
|
// Previously scanned files under THIS ruleset, keyed by path. Rows from an
|
|
33218
32685
|
// older ruleset are simply absent, which reads as "never scanned".
|
|
33219
32686
|
entriesForRuleset(rulesetHash) {
|
|
33220
|
-
const rows = allRows(this.readStmt, {
|
|
33221
|
-
|
|
33222
|
-
|
|
33223
|
-
|
|
32687
|
+
const rows = allRows(this.readStmt, { rulesetHash });
|
|
32688
|
+
return new Map(
|
|
32689
|
+
rows.map((r) => [
|
|
32690
|
+
r.path,
|
|
32691
|
+
{
|
|
32692
|
+
mtime: r.mtime,
|
|
32693
|
+
contentHash: r.contentHash,
|
|
32694
|
+
...r.scopeKey !== null ? { scopeKey: r.scopeKey } : {},
|
|
32695
|
+
...r.scopeRoot !== null ? { scopeRoot: r.scopeRoot } : {}
|
|
32696
|
+
}
|
|
32697
|
+
])
|
|
32698
|
+
);
|
|
33224
32699
|
}
|
|
33225
32700
|
// Every ledgered path, whatever ruleset it was scanned under — the set a
|
|
33226
32701
|
// deletion sweep checks against disk. A file deleted before a ruleset change
|
|
@@ -33229,6 +32704,14 @@ var SqliteScanLedgerRepository = class {
|
|
|
33229
32704
|
allPaths() {
|
|
33230
32705
|
return allRows(this.pathsStmt).map((r) => r.path);
|
|
33231
32706
|
}
|
|
32707
|
+
// Every ledgered path with the repository it was in when it was last read,
|
|
32708
|
+
// whatever ruleset it was scanned under: what a deletion sweep needs to say
|
|
32709
|
+
// which repository a vanished file belonged to. `undefined` for a row with no
|
|
32710
|
+
// key, which is every row written before the column existed.
|
|
32711
|
+
pathKeys() {
|
|
32712
|
+
const rows = allRows(this.pathKeysStmt);
|
|
32713
|
+
return new Map(rows.map((r) => [r.path, r.scopeKey ?? void 0]));
|
|
32714
|
+
}
|
|
33232
32715
|
upsertEntries(entries) {
|
|
33233
32716
|
if (entries.length === 0) return;
|
|
33234
32717
|
const scannedAt = Date.now();
|
|
@@ -33239,6 +32722,8 @@ var SqliteScanLedgerRepository = class {
|
|
|
33239
32722
|
mtime: entry.mtime,
|
|
33240
32723
|
contentHash: entry.contentHash,
|
|
33241
32724
|
rulesetHash: entry.rulesetHash,
|
|
32725
|
+
scopeKey: entry.scopeKey ?? null,
|
|
32726
|
+
scopeRoot: entry.scopeRoot ?? null,
|
|
33242
32727
|
scannedAt
|
|
33243
32728
|
});
|
|
33244
32729
|
}
|
|
@@ -34326,6 +33811,11 @@ function withoutDroppedFiles(reconcile, droppedFiles) {
|
|
|
34326
33811
|
deletedFiles: reconcile.deletedFiles.filter((file2) => !dropped.has(file2))
|
|
34327
33812
|
};
|
|
34328
33813
|
}
|
|
33814
|
+
function withoutTrailingSlashes(path) {
|
|
33815
|
+
let end = path.length;
|
|
33816
|
+
while (end > 0 && path.charCodeAt(end - 1) === 47) end--;
|
|
33817
|
+
return path.slice(0, end);
|
|
33818
|
+
}
|
|
34329
33819
|
function toEndpointSummary(row) {
|
|
34330
33820
|
return {
|
|
34331
33821
|
id: row.id,
|
|
@@ -34613,7 +34103,7 @@ var SqliteSharesRepository = class {
|
|
|
34613
34103
|
*/
|
|
34614
34104
|
reconcileCallSites(projectKey, reconcile) {
|
|
34615
34105
|
if (reconcile.mode === "walk") {
|
|
34616
|
-
const prefix = reconcile.walkedPrefix
|
|
34106
|
+
const prefix = withoutTrailingSlashes(reconcile.walkedPrefix);
|
|
34617
34107
|
this.db.prepare(
|
|
34618
34108
|
`DELETE FROM share_call_site
|
|
34619
34109
|
WHERE project_key = :key
|
|
@@ -35181,7 +34671,7 @@ function backupLegacyStore(db, file2) {
|
|
|
35181
34671
|
discardStore(file2, backup);
|
|
35182
34672
|
return backup;
|
|
35183
34673
|
}
|
|
35184
|
-
function openAndInitialize(file2, base, skipTags) {
|
|
34674
|
+
function openAndInitialize(file2, base, skipTags, shippedRegexMatchers2) {
|
|
35185
34675
|
let db = openWithPragmas(file2);
|
|
35186
34676
|
try {
|
|
35187
34677
|
if (isForeignSqliteLineage(db)) {
|
|
@@ -35193,8 +34683,15 @@ function openAndInitialize(file2, base, skipTags) {
|
|
|
35193
34683
|
}
|
|
35194
34684
|
applyMigrations(db, file2, { skipTags });
|
|
35195
34685
|
tightenPerms(file2);
|
|
35196
|
-
const
|
|
35197
|
-
const
|
|
34686
|
+
const modPolicy = {};
|
|
34687
|
+
const onPolicyStateChange = () => {
|
|
34688
|
+
if (modPolicy.current !== void 0)
|
|
34689
|
+
refreshModPolicySnapshot(dirname2(file2), modPolicy.current);
|
|
34690
|
+
};
|
|
34691
|
+
const policies = new SqlitePoliciesRepository(db, onPolicyStateChange);
|
|
34692
|
+
const installedPacks = new SqliteInstalledPacksRepository(db, base, onPolicyStateChange);
|
|
34693
|
+
const ruleProbeCache = new SqliteRuleProbeCacheRepository(db);
|
|
34694
|
+
const exceptions = new SqliteExceptionsRepository(db, void 0, onPolicyStateChange);
|
|
35198
34695
|
const repositories = {
|
|
35199
34696
|
events: new SqliteEventsRepository(db),
|
|
35200
34697
|
findings: new SqliteFindingsRepository(db),
|
|
@@ -35203,9 +34700,9 @@ function openAndInitialize(file2, base, skipTags) {
|
|
|
35203
34700
|
scanLedger: new SqliteScanLedgerRepository(db),
|
|
35204
34701
|
historySync: new SqliteHistorySyncRepository(db),
|
|
35205
34702
|
secretVault: new SqliteSecretVaultRepository(db),
|
|
35206
|
-
exceptions
|
|
34703
|
+
exceptions,
|
|
35207
34704
|
resolutions: new SqliteResolutionsRepository(db),
|
|
35208
|
-
ruleProbeCache
|
|
34705
|
+
ruleProbeCache,
|
|
35209
34706
|
bodyRetention: new SqliteBodyRetentionRepository(db),
|
|
35210
34707
|
security: new SqliteSecurityRepository(db),
|
|
35211
34708
|
detections: new SqliteDetectionsRepository(db),
|
|
@@ -35223,6 +34720,13 @@ function openAndInitialize(file2, base, skipTags) {
|
|
|
35223
34720
|
inspectionFindings: new SqliteInspectionFindingsRepository(db),
|
|
35224
34721
|
configInventory: new SqliteConfigInventoryRepository(db)
|
|
35225
34722
|
};
|
|
34723
|
+
modPolicy.current = {
|
|
34724
|
+
installedRuleset: () => installedPacks.installedRuleset(),
|
|
34725
|
+
readPolicies: () => policies.listPolicies(),
|
|
34726
|
+
activeExceptionRuleIds: () => exceptions.activeRuleIds(),
|
|
34727
|
+
probeVerdict: (key) => ruleProbeCache.getVerdict(key)?.verdict,
|
|
34728
|
+
bundledRegexMatchers: () => shippedRegexMatchers2
|
|
34729
|
+
};
|
|
35226
34730
|
policies.seedDefaults();
|
|
35227
34731
|
return { db, ...repositories };
|
|
35228
34732
|
} catch (err) {
|
|
@@ -35234,7 +34738,7 @@ function openAndInitialize(file2, base, skipTags) {
|
|
|
35234
34738
|
var DEFERRED_TAGS = new Set(DEFERRED_MIGRATION_TAGS);
|
|
35235
34739
|
function openLocalDatabase(dir, options = {}) {
|
|
35236
34740
|
ensureDataDirSync(dir);
|
|
35237
|
-
const file2 =
|
|
34741
|
+
const file2 = join8(dir, DB_FILENAME);
|
|
35238
34742
|
reapStalePartials(file2);
|
|
35239
34743
|
const {
|
|
35240
34744
|
db,
|
|
@@ -35270,7 +34774,8 @@ function openLocalDatabase(dir, options = {}) {
|
|
|
35270
34774
|
// `dataDir()` — so its parent is the `~/.aka` base the layout splits into
|
|
35271
34775
|
// settings/ and data/, and the pack-policy floor needs both halves.
|
|
35272
34776
|
dirname2(dir),
|
|
35273
|
-
options.applyDeferredMigrations === true ? void 0 : DEFERRED_TAGS
|
|
34777
|
+
options.applyDeferredMigrations === true ? void 0 : DEFERRED_TAGS,
|
|
34778
|
+
options.shippedRegexMatchers ?? []
|
|
35274
34779
|
);
|
|
35275
34780
|
function captureRowId(event) {
|
|
35276
34781
|
return captureId(
|
|
@@ -35535,7 +35040,7 @@ function openLocalDatabase(dir, options = {}) {
|
|
|
35535
35040
|
}
|
|
35536
35041
|
|
|
35537
35042
|
// ../../packages/persistence/src/egress-wire.ts
|
|
35538
|
-
import { createHash as
|
|
35043
|
+
import { createHash as createHash4 } from "crypto";
|
|
35539
35044
|
var PROJECT_KEY_DIGEST_VERSION = "v2";
|
|
35540
35045
|
var SCP_FORM = /^(?:[^@/]+@)?([^/:]+):(.+)$/;
|
|
35541
35046
|
var DOS_DRIVE = /^[A-Za-z]:[\\/]/;
|
|
@@ -35567,7 +35072,7 @@ function canonicalGitUrl(url2) {
|
|
|
35567
35072
|
}
|
|
35568
35073
|
function hashProjectKey(projectKey) {
|
|
35569
35074
|
const canonical = projectKey.startsWith("git:") ? `git:${canonicalGitUrl(projectKey.slice("git:".length))}` : projectKey;
|
|
35570
|
-
return
|
|
35075
|
+
return createHash4("sha256").update(`${PROJECT_KEY_DIGEST_VERSION}:${canonical}`, "utf8").digest("hex");
|
|
35571
35076
|
}
|
|
35572
35077
|
var SCOPE_KEY = printable(ATTACHMENT_SCOPE_IDENTITY_MAX_LENGTH);
|
|
35573
35078
|
var URL_SCHEME = /^[a-z][a-z0-9+.-]*:\/\//i;
|
|
@@ -35632,17 +35137,16 @@ function toEgressIngestRequest(input2) {
|
|
|
35632
35137
|
}
|
|
35633
35138
|
|
|
35634
35139
|
// ../../packages/persistence/src/finding-key.ts
|
|
35635
|
-
import { createHash as
|
|
35140
|
+
import { createHash as createHash5 } from "crypto";
|
|
35636
35141
|
|
|
35637
35142
|
// ../../packages/persistence/src/fingerprint.ts
|
|
35638
35143
|
import { createHmac, randomBytes } from "crypto";
|
|
35639
|
-
import { existsSync as existsSync3, readFileSync as
|
|
35640
|
-
import { join as
|
|
35641
|
-
import { DatabaseSync as DatabaseSync2 } from "node:sqlite";
|
|
35144
|
+
import { existsSync as existsSync3, readFileSync as readFileSync7 } from "fs";
|
|
35145
|
+
import { join as join9 } from "path";
|
|
35642
35146
|
var EXCEPTION_KEY_FILENAME = "exception.key";
|
|
35643
35147
|
var KEY_MATERIAL_BYTES = 32;
|
|
35644
35148
|
function keyFilePath(dataDir2) {
|
|
35645
|
-
return
|
|
35149
|
+
return join9(dataDir2, EXCEPTION_KEY_FILENAME);
|
|
35646
35150
|
}
|
|
35647
35151
|
function parseKeyFile(raw) {
|
|
35648
35152
|
const parsed2 = JSON.parse(raw);
|
|
@@ -35665,7 +35169,7 @@ function parseKeyFile(raw) {
|
|
|
35665
35169
|
function readFingerprintKey(dataDir2) {
|
|
35666
35170
|
let raw;
|
|
35667
35171
|
try {
|
|
35668
|
-
raw =
|
|
35172
|
+
raw = readFileSync7(keyFilePath(dataDir2), "utf8");
|
|
35669
35173
|
} catch (err) {
|
|
35670
35174
|
if (err.code === "ENOENT") return null;
|
|
35671
35175
|
throw err instanceof Error ? err : new Error(String(err));
|
|
@@ -35674,8 +35178,8 @@ function readFingerprintKey(dataDir2) {
|
|
|
35674
35178
|
}
|
|
35675
35179
|
|
|
35676
35180
|
// ../../packages/persistence/src/forward-health.ts
|
|
35677
|
-
import { readFileSync as
|
|
35678
|
-
import { join as
|
|
35181
|
+
import { readFileSync as readFileSync8 } from "fs";
|
|
35182
|
+
import { join as join10 } from "path";
|
|
35679
35183
|
var BREAKER_COOLDOWN_MS = 3e4;
|
|
35680
35184
|
function parseForwardHealth(raw, nowMs) {
|
|
35681
35185
|
try {
|
|
@@ -35699,20 +35203,21 @@ function isForwardPaused(health, nowMs) {
|
|
|
35699
35203
|
|
|
35700
35204
|
// ../../packages/persistence/src/history-backfill.ts
|
|
35701
35205
|
import { existsSync as existsSync4 } from "fs";
|
|
35702
|
-
import { join as
|
|
35206
|
+
import { join as join11 } from "path";
|
|
35703
35207
|
|
|
35704
35208
|
// ../../packages/persistence/src/history-preview.ts
|
|
35705
35209
|
import { existsSync as existsSync5 } from "fs";
|
|
35706
|
-
import { join as
|
|
35707
|
-
import { DatabaseSync as
|
|
35210
|
+
import { join as join12 } from "path";
|
|
35211
|
+
import { DatabaseSync as DatabaseSync2 } from "node:sqlite";
|
|
35708
35212
|
|
|
35709
35213
|
// ../../packages/persistence/src/history-sync-state.ts
|
|
35710
|
-
import { readFileSync as
|
|
35711
|
-
import { join as
|
|
35214
|
+
import { readFileSync as readFileSync9 } from "fs";
|
|
35215
|
+
import { join as join13 } from "path";
|
|
35216
|
+
var COUNTS_SCOPES = new Set(AttachmentMode.options);
|
|
35712
35217
|
|
|
35713
35218
|
// ../../packages/persistence/src/store-symlinks.ts
|
|
35714
35219
|
import { existsSync as existsSync6, lstatSync as lstatSync3, readlinkSync, realpathSync, statSync as statSync4 } from "fs";
|
|
35715
|
-
import { dirname as dirname3, join as
|
|
35220
|
+
import { dirname as dirname3, join as join14, resolve } from "path";
|
|
35716
35221
|
|
|
35717
35222
|
// ../../packages/persistence/src/vault/crypto.ts
|
|
35718
35223
|
import {
|
|
@@ -35726,19 +35231,19 @@ import {
|
|
|
35726
35231
|
// ../../packages/persistence/src/vault/key-provider.ts
|
|
35727
35232
|
import { execFileSync } from "child_process";
|
|
35728
35233
|
import { randomBytes as randomBytes2 } from "crypto";
|
|
35729
|
-
import { chmodSync as chmodSync3, readFileSync as
|
|
35730
|
-
import { join as
|
|
35234
|
+
import { chmodSync as chmodSync3, readFileSync as readFileSync10, renameSync as renameSync4, rmSync as rmSync6, statSync as statSync5, writeFileSync as writeFileSync3 } from "fs";
|
|
35235
|
+
import { join as join15 } from "path";
|
|
35731
35236
|
|
|
35732
35237
|
// ../../packages/persistence/src/vault/vault.ts
|
|
35733
35238
|
import { randomBytes as randomBytes3, randomUUID as randomUUID12 } from "crypto";
|
|
35734
35239
|
|
|
35735
35240
|
// ../../packages/persistence/src/warn-era-cap.ts
|
|
35736
35241
|
import { existsSync as existsSync7, writeFileSync as writeFileSync4 } from "fs";
|
|
35737
|
-
import { join as
|
|
35242
|
+
import { join as join16 } from "path";
|
|
35738
35243
|
var MARKER = "warn-era-capped";
|
|
35739
35244
|
function capWarnEraEnforcementOnce(db, policyMode, dataDir2) {
|
|
35740
35245
|
if (policyMode !== "warn") return { capped: 0, skipped: "not-warn" };
|
|
35741
|
-
const marker =
|
|
35246
|
+
const marker = join16(dataDir2, MARKER);
|
|
35742
35247
|
if (existsSync7(marker)) return { capped: 0, skipped: "already-run" };
|
|
35743
35248
|
const capped = db.policies.capCategoryActions();
|
|
35744
35249
|
writeFileSync4(marker, `${new Date(Date.now()).toISOString()}
|
|
@@ -35798,7 +35303,7 @@ function resolveProvider() {
|
|
|
35798
35303
|
function loadConfig(base = defaultDataDir(), resolveProviderFn = resolveProvider) {
|
|
35799
35304
|
try {
|
|
35800
35305
|
ensureLayoutDirSync(base);
|
|
35801
|
-
const settingsFile =
|
|
35306
|
+
const settingsFile = join17(settingsDir(base), "settings.json");
|
|
35802
35307
|
if (existsSync8(settingsFile)) tightenFile(settingsFile);
|
|
35803
35308
|
} catch {
|
|
35804
35309
|
}
|
|
@@ -35821,11 +35326,6 @@ function resolveProviderSafe(resolveProviderFn) {
|
|
|
35821
35326
|
}
|
|
35822
35327
|
}
|
|
35823
35328
|
|
|
35824
|
-
// ../../packages/plugin-sdk/src/config-inventory.ts
|
|
35825
|
-
import { readdirSync as readdirSync2, readFileSync as readFileSync11, realpathSync as realpathSync2, statSync as statSync7 } from "fs";
|
|
35826
|
-
import { homedir as homedir2 } from "os";
|
|
35827
|
-
import { basename as basename3, join as join18 } from "path";
|
|
35828
|
-
|
|
35829
35329
|
// ../../packages/detections/src/egress/registry.ts
|
|
35830
35330
|
var EXTRACTOR_VERSION = "3";
|
|
35831
35331
|
var PROVIDER_REGISTRY = [
|
|
@@ -36936,17 +36436,18 @@ function ruleEvidence(rule) {
|
|
|
36936
36436
|
|
|
36937
36437
|
// ../../packages/detections/src/mask.ts
|
|
36938
36438
|
function maskMatch(raw) {
|
|
36939
|
-
|
|
36940
|
-
|
|
36941
|
-
|
|
36942
|
-
|
|
36439
|
+
const visible = stripInvisiblePadding(raw);
|
|
36440
|
+
if (visible.length <= 5) return "***";
|
|
36441
|
+
const atIndex = visible.indexOf("@");
|
|
36442
|
+
if (atIndex > 0 && atIndex < visible.length - 1) {
|
|
36443
|
+
const domain2 = visible.slice(atIndex + 1);
|
|
36943
36444
|
if (domain2.includes(".")) {
|
|
36944
|
-
const local =
|
|
36445
|
+
const local = visible.slice(0, atIndex);
|
|
36945
36446
|
const maskedLocal = local.length <= 1 ? local : local.charAt(0) + "*".repeat(local.length - 1);
|
|
36946
36447
|
return `${maskedLocal}@${domain2}`;
|
|
36947
36448
|
}
|
|
36948
36449
|
}
|
|
36949
|
-
return `${
|
|
36450
|
+
return `${visible.charAt(0)}${"*".repeat(6)}${visible.charAt(visible.length - 1)}`;
|
|
36950
36451
|
}
|
|
36951
36452
|
|
|
36952
36453
|
// ../../packages/detections/src/pointer-shield.ts
|
|
@@ -37121,7 +36622,12 @@ var MIN_RAW_LEN = 4;
|
|
|
37121
36622
|
var RAW_RUN_LEN = 8;
|
|
37122
36623
|
function carriesRawRun(text, rawValues) {
|
|
37123
36624
|
let windows = null;
|
|
37124
|
-
|
|
36625
|
+
const values = /* @__PURE__ */ new Set();
|
|
36626
|
+
for (const raw of rawValues) {
|
|
36627
|
+
values.add(raw);
|
|
36628
|
+
values.add(stripInvisiblePadding(raw));
|
|
36629
|
+
}
|
|
36630
|
+
for (const raw of values) {
|
|
37125
36631
|
if (raw.length < MIN_RAW_LEN) continue;
|
|
37126
36632
|
if (raw.length < RAW_RUN_LEN) {
|
|
37127
36633
|
if (text.includes(raw)) return true;
|
|
@@ -37145,11 +36651,16 @@ function carriesRawRun(text, rawValues) {
|
|
|
37145
36651
|
return false;
|
|
37146
36652
|
}
|
|
37147
36653
|
function safeMaskedMatch(rawMatch) {
|
|
37148
|
-
const
|
|
37149
|
-
|
|
37150
|
-
|
|
36654
|
+
const visible = stripInvisiblePadding(rawMatch);
|
|
36655
|
+
const masked = maskMatch(visible);
|
|
36656
|
+
const reveals = (preview) => preview === visible || visible.length >= MIN_RAW_LEN && preview.includes(visible);
|
|
36657
|
+
if (!reveals(masked)) return masked;
|
|
36658
|
+
const atIndex = masked.indexOf("@");
|
|
36659
|
+
if (atIndex > 0 && atIndex < masked.length - 1) {
|
|
36660
|
+
const emailFallback = `*${masked.slice(atIndex)}`;
|
|
36661
|
+
if (!reveals(emailFallback)) return emailFallback;
|
|
37151
36662
|
}
|
|
37152
|
-
return
|
|
36663
|
+
return "***";
|
|
37153
36664
|
}
|
|
37154
36665
|
function assertRawFree(text, rawValues) {
|
|
37155
36666
|
if (carriesRawRun(text, rawValues)) {
|
|
@@ -39591,6 +39102,11 @@ function bundledDetections() {
|
|
|
39591
39102
|
}));
|
|
39592
39103
|
return cachedDetections;
|
|
39593
39104
|
}
|
|
39105
|
+
function shippedRegexMatchers() {
|
|
39106
|
+
return bundledDetections().flatMap((pack) => pack.rules).flatMap(
|
|
39107
|
+
(rule) => rule.matcher.type === "regex" ? [{ pattern: rule.matcher.pattern, flags: rule.matcher.flags }] : []
|
|
39108
|
+
);
|
|
39109
|
+
}
|
|
39594
39110
|
|
|
39595
39111
|
// ../../packages/plugin-sdk/src/mask.ts
|
|
39596
39112
|
var packsReady = false;
|
|
@@ -39643,8 +39159,8 @@ function scanText(text, ruleVersions, options = {}) {
|
|
|
39643
39159
|
}
|
|
39644
39160
|
|
|
39645
39161
|
// ../../packages/plugin-sdk/src/repo.ts
|
|
39646
|
-
import { existsSync as existsSync9, readFileSync as
|
|
39647
|
-
import { basename as basename2, dirname as dirname4, isAbsolute, join as
|
|
39162
|
+
import { existsSync as existsSync9, readFileSync as readFileSync11, statSync as statSync6 } from "fs";
|
|
39163
|
+
import { basename as basename2, dirname as dirname4, isAbsolute, join as join18, sep as sep2 } from "path";
|
|
39648
39164
|
function resolveRepoIdentity(cwd) {
|
|
39649
39165
|
try {
|
|
39650
39166
|
const location = locateRepo(cwd);
|
|
@@ -39663,8 +39179,9 @@ function resolveRepoIdentity(cwd) {
|
|
|
39663
39179
|
var ATTRIBUTION_MEMO_LIMIT = 64;
|
|
39664
39180
|
var attributionMemo = /* @__PURE__ */ new Map();
|
|
39665
39181
|
var NO_ATTRIBUTION = Object.freeze({});
|
|
39666
|
-
function resolveRepoAttribution(cwd) {
|
|
39182
|
+
function resolveRepoAttribution(cwd, options) {
|
|
39667
39183
|
try {
|
|
39184
|
+
if (options?.cache === false) return attributeRepo(cwd);
|
|
39668
39185
|
const remembered = attributionMemo.get(cwd);
|
|
39669
39186
|
if (remembered !== void 0) return remembered;
|
|
39670
39187
|
const attribution = attributeRepo(cwd);
|
|
@@ -39688,36 +39205,36 @@ function attributeRepo(cwd) {
|
|
|
39688
39205
|
function findGitRoot(start) {
|
|
39689
39206
|
let dir = start;
|
|
39690
39207
|
for (; ; ) {
|
|
39691
|
-
if (existsSync9(
|
|
39208
|
+
if (existsSync9(join18(dir, ".git"))) return dir;
|
|
39692
39209
|
const parent = dirname4(dir);
|
|
39693
39210
|
if (parent === dir) return void 0;
|
|
39694
39211
|
dir = parent;
|
|
39695
39212
|
}
|
|
39696
39213
|
}
|
|
39697
39214
|
function resolveGitContext(root) {
|
|
39698
|
-
const dotGit =
|
|
39215
|
+
const dotGit = join18(root, ".git");
|
|
39699
39216
|
try {
|
|
39700
39217
|
if (statSync6(dotGit).isDirectory()) {
|
|
39701
|
-
return { configPath:
|
|
39218
|
+
return { configPath: join18(dotGit, "config"), headRoot: root };
|
|
39702
39219
|
}
|
|
39703
39220
|
} catch {
|
|
39704
39221
|
return void 0;
|
|
39705
39222
|
}
|
|
39706
39223
|
const target = /^gitdir:\s*(.+?)\s*$/m.exec(safeRead(dotGit) ?? "")?.[1];
|
|
39707
39224
|
if (!target) return void 0;
|
|
39708
|
-
const gitdir = isAbsolute(target) ? target :
|
|
39709
|
-
if (existsSync9(
|
|
39710
|
-
return { configPath:
|
|
39225
|
+
const gitdir = isAbsolute(target) ? target : join18(root, target);
|
|
39226
|
+
if (existsSync9(join18(gitdir, "config"))) {
|
|
39227
|
+
return { configPath: join18(gitdir, "config"), headRoot: root };
|
|
39711
39228
|
}
|
|
39712
|
-
const commonRaw = safeRead(
|
|
39229
|
+
const commonRaw = safeRead(join18(gitdir, "commondir"))?.trim();
|
|
39713
39230
|
if (!commonRaw) return void 0;
|
|
39714
|
-
const commonGitDir = isAbsolute(commonRaw) ? commonRaw :
|
|
39231
|
+
const commonGitDir = isAbsolute(commonRaw) ? commonRaw : join18(gitdir, commonRaw);
|
|
39715
39232
|
const headRoot = basename2(commonGitDir) === ".git" ? dirname4(commonGitDir) : root;
|
|
39716
|
-
return { configPath:
|
|
39233
|
+
return { configPath: join18(commonGitDir, "config"), headRoot };
|
|
39717
39234
|
}
|
|
39718
39235
|
function safeRead(path) {
|
|
39719
39236
|
try {
|
|
39720
|
-
return
|
|
39237
|
+
return readFileSync11(path, "utf8");
|
|
39721
39238
|
} catch {
|
|
39722
39239
|
return void 0;
|
|
39723
39240
|
}
|
|
@@ -39763,68 +39280,6 @@ function slugFromUrl(url2) {
|
|
|
39763
39280
|
return segment && segment.length > 0 ? segment : void 0;
|
|
39764
39281
|
}
|
|
39765
39282
|
|
|
39766
|
-
// ../../packages/plugin-sdk/src/events.ts
|
|
39767
|
-
import { createHash as createHash5, randomUUID as randomUUID13 } from "crypto";
|
|
39768
|
-
|
|
39769
|
-
// ../../packages/plugin-sdk/src/isolated-scan.ts
|
|
39770
|
-
import { existsSync as existsSync10 } from "fs";
|
|
39771
|
-
import { fileURLToPath } from "url";
|
|
39772
|
-
import { Worker } from "worker_threads";
|
|
39773
|
-
|
|
39774
|
-
// ../../packages/plugin-sdk/src/hook-fail-opens.ts
|
|
39775
|
-
import { readFileSync as readFileSync12 } from "fs";
|
|
39776
|
-
import { join as join19 } from "path";
|
|
39777
|
-
|
|
39778
|
-
// ../../packages/plugin-sdk/src/host-floor.ts
|
|
39779
|
-
import { readFileSync as readFileSync14 } from "fs";
|
|
39780
|
-
import { join as join21 } from "path";
|
|
39781
|
-
|
|
39782
|
-
// ../../packages/plugin-sdk/src/model-governance.ts
|
|
39783
|
-
import {
|
|
39784
|
-
closeSync as closeSync2,
|
|
39785
|
-
fstatSync,
|
|
39786
|
-
mkdirSync as mkdirSync2,
|
|
39787
|
-
openSync as openSync2,
|
|
39788
|
-
readFileSync as readFileSync13,
|
|
39789
|
-
readSync,
|
|
39790
|
-
writeFileSync as writeFileSync5
|
|
39791
|
-
} from "fs";
|
|
39792
|
-
import { join as join20 } from "path";
|
|
39793
|
-
var TAIL_BYTES = 256 * 1024;
|
|
39794
|
-
|
|
39795
|
-
// ../../packages/plugin-sdk/src/host-floor.ts
|
|
39796
|
-
var HOST_FEATURE = {
|
|
39797
|
-
ModelSwitch: "model-switch",
|
|
39798
|
-
VaultPointerDisplay: "vault-pointer-display"
|
|
39799
|
-
};
|
|
39800
|
-
var HOST_FLOORS = {
|
|
39801
|
-
[HOST_FEATURE.ModelSwitch]: {
|
|
39802
|
-
label: "model-switch protection",
|
|
39803
|
-
hookEvents: ["PreModelSwitch", "PostModelSwitch"],
|
|
39804
|
-
since: "2.1.251"
|
|
39805
|
-
},
|
|
39806
|
-
[HOST_FEATURE.VaultPointerDisplay]: {
|
|
39807
|
-
label: "vault pointer display",
|
|
39808
|
-
hookEvents: ["MessageDisplay"],
|
|
39809
|
-
since: "2.1.152"
|
|
39810
|
-
}
|
|
39811
|
-
};
|
|
39812
|
-
var ANTIGRAVITY_HOST_FEATURE = {
|
|
39813
|
-
EndOfTurnCapture: "end-of-turn-capture"
|
|
39814
|
-
};
|
|
39815
|
-
var ANTIGRAVITY_HOST_FLOORS = {
|
|
39816
|
-
[ANTIGRAVITY_HOST_FEATURE.EndOfTurnCapture]: {
|
|
39817
|
-
label: "end-of-turn history capture",
|
|
39818
|
-
hookEvents: ["Stop"],
|
|
39819
|
-
since: "1.1.10"
|
|
39820
|
-
}
|
|
39821
|
-
};
|
|
39822
|
-
|
|
39823
|
-
// ../../packages/plugin-sdk/src/ignore-layers.ts
|
|
39824
|
-
var import_ignore = __toESM(require_ignore(), 1);
|
|
39825
|
-
import { readFileSync as readFileSync15 } from "fs";
|
|
39826
|
-
import { join as join22 } from "path";
|
|
39827
|
-
|
|
39828
39283
|
// ../../packages/plugin-sdk/src/inventory-resolver.ts
|
|
39829
39284
|
import { arch, hostname as hostname4, platform, release } from "os";
|
|
39830
39285
|
function resolveInventoryContext(input2) {
|
|
@@ -39854,55 +39309,17 @@ function resolveInventoryContext(input2) {
|
|
|
39854
39309
|
return ctx;
|
|
39855
39310
|
}
|
|
39856
39311
|
|
|
39857
|
-
// ../../packages/plugin-sdk/src/nudge.ts
|
|
39858
|
-
import { mkdirSync as mkdirSync3, readFileSync as readFileSync16, writeFileSync as writeFileSync6 } from "fs";
|
|
39859
|
-
import { join as join23 } from "path";
|
|
39860
|
-
|
|
39861
|
-
// ../../packages/plugin-sdk/src/paths.ts
|
|
39862
|
-
import { readdirSync as readdirSync3, realpathSync as realpathSync3 } from "fs";
|
|
39863
|
-
import { basename as basename4, dirname as dirname5, sep as sep3 } from "path";
|
|
39864
|
-
|
|
39865
39312
|
// ../../packages/plugin-sdk/src/policy-resolver.ts
|
|
39866
|
-
import { randomUUID as
|
|
39313
|
+
import { randomUUID as randomUUID13 } from "crypto";
|
|
39867
39314
|
function assignedRulePolicies(installed) {
|
|
39868
39315
|
const out = [];
|
|
39869
39316
|
for (const [ruleId, action] of installed.ruleActions) {
|
|
39870
39317
|
if (installed.assignedRules && !installed.assignedRules.has(ruleId)) continue;
|
|
39871
|
-
out.push({ id:
|
|
39318
|
+
out.push({ id: randomUUID13(), scope: "global", target: { ruleId }, action, enabled: true });
|
|
39872
39319
|
}
|
|
39873
39320
|
return out;
|
|
39874
39321
|
}
|
|
39875
39322
|
|
|
39876
|
-
// ../../packages/plugin-sdk/src/project-files.ts
|
|
39877
|
-
import { existsSync as existsSync11, readdirSync as readdirSync4 } from "fs";
|
|
39878
|
-
import { basename as basename5, join as join24 } from "path";
|
|
39879
|
-
|
|
39880
|
-
// ../../packages/plugin-sdk/src/provider-env-antigravity.ts
|
|
39881
|
-
var optionalBaseUrl2 = external_exports.preprocess((v) => {
|
|
39882
|
-
if (typeof v === "string" && v.trim() === "") return void 0;
|
|
39883
|
-
return v;
|
|
39884
|
-
}, external_exports.string().optional()).catch(void 0);
|
|
39885
|
-
var optionalFlag = external_exports.preprocess((v) => {
|
|
39886
|
-
if (typeof v !== "string") return false;
|
|
39887
|
-
const normalized = v.trim().toLowerCase();
|
|
39888
|
-
return normalized !== "" && normalized !== "0" && normalized !== "false";
|
|
39889
|
-
}, external_exports.boolean()).catch(false);
|
|
39890
|
-
var antigravityProviderEnvShape = {
|
|
39891
|
-
GOOGLE_GENAI_USE_VERTEXAI: optionalFlag,
|
|
39892
|
-
GOOGLE_GEMINI_BASE_URL: optionalBaseUrl2
|
|
39893
|
-
};
|
|
39894
|
-
var AntigravityProviderEnvSchema = external_exports.object(antigravityProviderEnvShape);
|
|
39895
|
-
|
|
39896
|
-
// ../../packages/plugin-sdk/src/provider-env-codex.ts
|
|
39897
|
-
var optionalBaseUrl3 = external_exports.preprocess((v) => {
|
|
39898
|
-
if (typeof v === "string" && v.trim() === "") return void 0;
|
|
39899
|
-
return v;
|
|
39900
|
-
}, external_exports.string().optional()).catch(void 0);
|
|
39901
|
-
var codexProviderEnvShape = {
|
|
39902
|
-
OPENAI_BASE_URL: optionalBaseUrl3
|
|
39903
|
-
};
|
|
39904
|
-
var CodexProviderEnvSchema = external_exports.object(codexProviderEnvShape);
|
|
39905
|
-
|
|
39906
39323
|
// ../../packages/plugin-sdk/src/provider-codex.ts
|
|
39907
39324
|
function codexProviderFromModelId(modelId) {
|
|
39908
39325
|
const id = modelId.trim();
|
|
@@ -39913,12 +39330,9 @@ function codexProviderFromModelId(modelId) {
|
|
|
39913
39330
|
return "unknown";
|
|
39914
39331
|
}
|
|
39915
39332
|
|
|
39916
|
-
// ../../packages/plugin-sdk/src/runtime.ts
|
|
39917
|
-
import { randomUUID as randomUUID15 } from "crypto";
|
|
39918
|
-
|
|
39919
39333
|
// ../../packages/plugin-sdk/src/scope-key.ts
|
|
39920
|
-
import { existsSync as
|
|
39921
|
-
import { dirname as
|
|
39334
|
+
import { existsSync as existsSync10 } from "fs";
|
|
39335
|
+
import { dirname as dirname5, isAbsolute as isAbsolute2, join as join19, normalize } from "path";
|
|
39922
39336
|
function scopeKeyMemo() {
|
|
39923
39337
|
const memo2 = /* @__PURE__ */ new Map();
|
|
39924
39338
|
return (cwd) => {
|
|
@@ -39935,8 +39349,8 @@ function sessionRootScopeKey(cwd) {
|
|
|
39935
39349
|
function toolCallScopeKey(tc, scopeKeyOf2) {
|
|
39936
39350
|
if (tc.keyless === true) return void 0;
|
|
39937
39351
|
if (tc.filePaths === void 0 && tc.searchRoot === void 0) return scopeKeyOf2(tc.cwd);
|
|
39938
|
-
const resolved = (path) => isAbsolute2(path) ? normalize(path) :
|
|
39939
|
-
const walkStart = (path) => isAbsolute2(path) &&
|
|
39352
|
+
const resolved = (path) => isAbsolute2(path) ? normalize(path) : join19(tc.cwd ?? "", path);
|
|
39353
|
+
const walkStart = (path) => isAbsolute2(path) && existsSync10(join19(path, ".git")) ? path : dirname5(path);
|
|
39940
39354
|
const locations = [
|
|
39941
39355
|
...(tc.filePaths ?? []).map((path) => walkStart(resolved(path))),
|
|
39942
39356
|
...tc.searchRoot === void 0 ? [] : [resolved(tc.searchRoot)]
|
|
@@ -39950,13 +39364,6 @@ function toolCallScopeKey(tc, scopeKeyOf2) {
|
|
|
39950
39364
|
return agreed;
|
|
39951
39365
|
}
|
|
39952
39366
|
|
|
39953
|
-
// ../../packages/plugin-sdk/src/suppressions.ts
|
|
39954
|
-
var THIRTY_DAYS_MS = 30 * 24 * 60 * 60 * 1e3;
|
|
39955
|
-
|
|
39956
|
-
// ../../packages/plugin-sdk/src/throttle.ts
|
|
39957
|
-
import { mkdirSync as mkdirSync4, statSync as statSync8, writeFileSync as writeFileSync7 } from "fs";
|
|
39958
|
-
import { join as join26 } from "path";
|
|
39959
|
-
|
|
39960
39367
|
// ../../packages/remote/src/http.ts
|
|
39961
39368
|
import { request as httpRequest } from "http";
|
|
39962
39369
|
import { request as httpsRequest } from "https";
|
|
@@ -40333,11 +39740,11 @@ function withTimeout(promise2, ms) {
|
|
|
40333
39740
|
}
|
|
40334
39741
|
|
|
40335
39742
|
// ../../packages/plugin-runtime/src/attached/forward-drops.ts
|
|
40336
|
-
import { readFileSync as
|
|
40337
|
-
import { join as
|
|
39743
|
+
import { readFileSync as readFileSync12 } from "fs";
|
|
39744
|
+
import { join as join20 } from "path";
|
|
40338
39745
|
var FORWARD_DROPS_FILENAME = ATTACHED_FORWARD_DROPS_FILENAME;
|
|
40339
39746
|
function forwardDropsPath(dataDir2) {
|
|
40340
|
-
return
|
|
39747
|
+
return join20(dataDir2, FORWARD_DROPS_FILENAME);
|
|
40341
39748
|
}
|
|
40342
39749
|
function recordForwardDrops(dataDir2, count, nowMs) {
|
|
40343
39750
|
if (count <= 0) return;
|
|
@@ -40355,7 +39762,7 @@ function recordForwardDrops(dataDir2, count, nowMs) {
|
|
|
40355
39762
|
}
|
|
40356
39763
|
function readForwardDrops(dataDir2) {
|
|
40357
39764
|
try {
|
|
40358
|
-
const parsed2 = JSON.parse(
|
|
39765
|
+
const parsed2 = JSON.parse(readFileSync12(forwardDropsPath(dataDir2), "utf8"));
|
|
40359
39766
|
if (typeof parsed2 !== "object" || parsed2 === null) return null;
|
|
40360
39767
|
const record2 = parsed2;
|
|
40361
39768
|
if (typeof record2.droppedForwards !== "number" || !Number.isFinite(record2.droppedForwards)) {
|
|
@@ -40372,9 +39779,9 @@ function readForwardDrops(dataDir2) {
|
|
|
40372
39779
|
}
|
|
40373
39780
|
|
|
40374
39781
|
// ../../packages/plugin-runtime/src/attached/forward-policy.ts
|
|
40375
|
-
import { randomUUID as
|
|
39782
|
+
import { randomUUID as randomUUID14 } from "crypto";
|
|
40376
39783
|
import { readFile, rename, writeFile } from "fs/promises";
|
|
40377
|
-
import { join as
|
|
39784
|
+
import { join as join21 } from "path";
|
|
40378
39785
|
function isInvalidRequest(err) {
|
|
40379
39786
|
return typeof err === "object" && err !== null && err.name === "RemoteRequestInvalid";
|
|
40380
39787
|
}
|
|
@@ -40393,7 +39800,7 @@ var FORWARD_STATE_FILENAME = ATTACHED_FORWARD_STATE_FILENAME;
|
|
|
40393
39800
|
var STATE_FILENAME = FORWARD_STATE_FILENAME;
|
|
40394
39801
|
function createForwardPolicy(deps) {
|
|
40395
39802
|
const now = deps.now ?? (() => Date.now());
|
|
40396
|
-
const file2 =
|
|
39803
|
+
const file2 = join21(deps.dir, STATE_FILENAME);
|
|
40397
39804
|
let state = null;
|
|
40398
39805
|
let loading = null;
|
|
40399
39806
|
async function readState() {
|
|
@@ -40418,7 +39825,7 @@ function createForwardPolicy(deps) {
|
|
|
40418
39825
|
state = next;
|
|
40419
39826
|
try {
|
|
40420
39827
|
await ensureDataDir(deps.dir);
|
|
40421
|
-
const tmp = `${file2}.${
|
|
39828
|
+
const tmp = `${file2}.${randomUUID14()}.tmp`;
|
|
40422
39829
|
await writeFile(tmp, JSON.stringify(next), { encoding: "utf8", mode: DATA_FILE_MODE });
|
|
40423
39830
|
await rename(tmp, file2);
|
|
40424
39831
|
} catch {
|
|
@@ -40559,6 +39966,9 @@ var AttachedDataGateway = class {
|
|
|
40559
39966
|
*
|
|
40560
39967
|
* Machine mode answers before any key is read, so a machine attachment pays
|
|
40561
39968
|
* nothing for scoping and forwards exactly what it always has.
|
|
39969
|
+
*
|
|
39970
|
+
* `governanceAppliesTo` answers from this same verdict, so it agrees with
|
|
39971
|
+
* forwarding key for key.
|
|
40562
39972
|
*/
|
|
40563
39973
|
verdictFor(keyOf) {
|
|
40564
39974
|
try {
|
|
@@ -40575,24 +39985,27 @@ var AttachedDataGateway = class {
|
|
|
40575
39985
|
* the key its row holds in the local store, recorded per root (see
|
|
40576
39986
|
* `rootVerdict`), not the key on the root event just handed in: roots are
|
|
40577
39987
|
* first-write-wins in the store, so when two producers record a root for one
|
|
40578
|
-
* session (the session-start hook, then a reconcile pass) the second leaves
|
|
40579
|
-
*
|
|
40580
|
-
*
|
|
40581
|
-
*
|
|
40582
|
-
*
|
|
40583
|
-
*
|
|
40584
|
-
*
|
|
40585
|
-
*
|
|
40586
|
-
*
|
|
40587
|
-
*
|
|
40588
|
-
*
|
|
40589
|
-
*
|
|
40590
|
-
*
|
|
40591
|
-
*
|
|
40592
|
-
*
|
|
40593
|
-
*
|
|
40594
|
-
*
|
|
40595
|
-
*
|
|
39988
|
+
* session (the session-start hook, then a reconcile pass) the second leaves the
|
|
39989
|
+
* stored row as it was. That stored row, not this event, is what a history
|
|
39990
|
+
* drain pass would decide, if the root started before the attach; the drain
|
|
39991
|
+
* never offers one that started after it (`started_at < backlogBefore`).
|
|
39992
|
+
* Whether this root EVENT is itself sent takes both keys: the stored one AND
|
|
39993
|
+
* its own. The event's attributes (cwd, project, repo) describe where it was
|
|
39994
|
+
* recorded from, so a root event keyed to a personal directory is never sent
|
|
39995
|
+
* under an enrolled stored root, though the enrolled leaves still forward under
|
|
39996
|
+
* it: the instance that wrote the stored root is expected to have forwarded it.
|
|
39997
|
+
* If it did not (the root was written while standalone or under another
|
|
39998
|
+
* attachment, or its forward failed), the plane refuses those leaves. A root
|
|
39999
|
+
* that started before the attach is shipped, ahead of its leaves, by the
|
|
40000
|
+
* history drain; one that started after it is never offered by the drain. Any
|
|
40001
|
+
* other row with a root reference (`rootSessionId`, else `parentId`) forwards
|
|
40002
|
+
* only when its own key is in scope AND this instance recorded an in-scope
|
|
40003
|
+
* verdict for that root. The audit-event route has real foreign keys on both
|
|
40004
|
+
* columns and stubs no missing root, so a leaf sent after its root was kept
|
|
40005
|
+
* local is refused there, and a refused forward counts toward the breaker that
|
|
40006
|
+
* guards every other one. A root this instance never recorded is therefore
|
|
40007
|
+
* `'local'`: the only answer that cannot orphan a row. A row with no root
|
|
40008
|
+
* reference at all has nothing to orphan, and is decided by its own key.
|
|
40596
40009
|
*
|
|
40597
40010
|
* What this costs is stated rather than discovered. A session whose stored
|
|
40598
40011
|
* root is not keyed to an enrolled repository keeps its token and tool
|
|
@@ -40663,6 +40076,87 @@ var AttachedDataGateway = class {
|
|
|
40663
40076
|
return [];
|
|
40664
40077
|
}
|
|
40665
40078
|
}
|
|
40079
|
+
/**
|
|
40080
|
+
* The verdict for the repositories nested in a scanned project, answered
|
|
40081
|
+
* TOTALLY: `'forward'` or `'local'`, never a throw.
|
|
40082
|
+
*
|
|
40083
|
+
* A walk descends into a nested clone or submodule and folds its files into
|
|
40084
|
+
* the project it is walking, so one register can carry several
|
|
40085
|
+
* repositories' call sites under one project key. Each of them must be in
|
|
40086
|
+
* scope for it to forward. One key out of scope, or a nested repository with
|
|
40087
|
+
* no remote (an `undefined` key), keeps the whole register local.
|
|
40088
|
+
*
|
|
40089
|
+
* An ABSENT list is `'local'` too. Only the code that walked the tree can say
|
|
40090
|
+
* what is nested in it, and every scan passes the list, empty when nothing
|
|
40091
|
+
* is nested. A register nobody vouched for is not one a scoped attachment
|
|
40092
|
+
* may send.
|
|
40093
|
+
*
|
|
40094
|
+
* Machine mode answers before reading the context, so a machine attachment
|
|
40095
|
+
* forwards exactly what it always has.
|
|
40096
|
+
*/
|
|
40097
|
+
nestedVerdict(context) {
|
|
40098
|
+
try {
|
|
40099
|
+
if (this.deps.attachment.mode === "machine") return "forward";
|
|
40100
|
+
const keys = context?.nestedScopeKeys;
|
|
40101
|
+
if (keys === void 0) return "local";
|
|
40102
|
+
for (const key of keys) {
|
|
40103
|
+
if (this.verdictFor(() => key) === "local") return "local";
|
|
40104
|
+
}
|
|
40105
|
+
return "forward";
|
|
40106
|
+
} catch {
|
|
40107
|
+
return "local";
|
|
40108
|
+
}
|
|
40109
|
+
}
|
|
40110
|
+
/**
|
|
40111
|
+
* The register a scoped attachment sends, once the project and the repositories
|
|
40112
|
+
* nested in it are in scope: the register itself, with `reconcile.deletedFiles`
|
|
40113
|
+
* cut to the deleted paths whose own repository is in scope. `undefined` sends
|
|
40114
|
+
* nothing. TOTAL, like `verdictFor`, and for its reasons.
|
|
40115
|
+
*
|
|
40116
|
+
* The deletion sweep takes its paths from the scan ledger, not from the walk,
|
|
40117
|
+
* and the ledger holds every file the scanner ever read under the root, nested
|
|
40118
|
+
* clones' included. So a clone that was removed, or one an ignore file now
|
|
40119
|
+
* hides, is in no walk and never reaches `nestedVerdict`, yet its ledgered
|
|
40120
|
+
* paths come back as deleted. The scan names the repository of each deleted
|
|
40121
|
+
* path (`context.deletedFileKeys`, one entry per path in the register's order)
|
|
40122
|
+
* and each is held to the same verdict as any other key. A path whose key is
|
|
40123
|
+
* absent, or out of scope, is not sent.
|
|
40124
|
+
*
|
|
40125
|
+
* The list is asked for here, and only here: it is an async read of the scan
|
|
40126
|
+
* ledger that the scan makes on being called, so a machine attachment, which
|
|
40127
|
+
* returns before this, and a register already kept local never cause it.
|
|
40128
|
+
*
|
|
40129
|
+
* Anything the scan did not vouch for sends no deleted path, and the register
|
|
40130
|
+
* itself still goes: no list, a list that throws or whose read is rejected, or a
|
|
40131
|
+
* list whose length is not the register's. Deleting is the only thing a dropped
|
|
40132
|
+
* path could have done on the server, so the cost of a refusal is a stored row
|
|
40133
|
+
* that stays, never a path that leaves.
|
|
40134
|
+
*
|
|
40135
|
+
* Machine mode returns `input` itself, the same object and unread, so a machine
|
|
40136
|
+
* attachment's request is exactly what it was. A register that lists no deleted
|
|
40137
|
+
* path, or that is not a ledger register, has nothing to cut and is returned
|
|
40138
|
+
* as it came, with the list unread.
|
|
40139
|
+
*/
|
|
40140
|
+
async registerForWire(input2, context) {
|
|
40141
|
+
try {
|
|
40142
|
+
if (this.deps.attachment.mode === "machine") return input2;
|
|
40143
|
+
const { reconcile } = input2;
|
|
40144
|
+
if (reconcile.mode !== "ledger" || reconcile.deletedFiles.length === 0) return input2;
|
|
40145
|
+
const deleted = reconcile.deletedFiles;
|
|
40146
|
+
let kept = [];
|
|
40147
|
+
try {
|
|
40148
|
+
const keys = await context?.deletedFileKeys?.();
|
|
40149
|
+
if (keys?.length === deleted.length) {
|
|
40150
|
+
kept = deleted.filter((_path, at) => this.verdictFor(() => keys[at]) === "forward");
|
|
40151
|
+
}
|
|
40152
|
+
} catch {
|
|
40153
|
+
kept = [];
|
|
40154
|
+
}
|
|
40155
|
+
return { ...input2, reconcile: { ...reconcile, deletedFiles: kept } };
|
|
40156
|
+
} catch {
|
|
40157
|
+
return void 0;
|
|
40158
|
+
}
|
|
40159
|
+
}
|
|
40666
40160
|
/**
|
|
40667
40161
|
* The event `recordCapture` sends for a capture the verdict let through, or
|
|
40668
40162
|
* `undefined` to send nothing. TOTAL, like `verdictFor`, and for its reasons.
|
|
@@ -40988,12 +40482,24 @@ var AttachedDataGateway = class {
|
|
|
40988
40482
|
* payload onto the wire-boundary-safe shape (no snippet, hashed
|
|
40989
40483
|
* projectKey), and its result is discarded: `forward.run` never throws or
|
|
40990
40484
|
* rejects, so there is nothing here to act on.
|
|
40485
|
+
*
|
|
40486
|
+
* `context.nestedScopeKeys` is what the scanner knows and the register does
|
|
40487
|
+
* not say: the key of every repository nested below the scan root, whose
|
|
40488
|
+
* files the walk folded into this register. On a scoped attachment the
|
|
40489
|
+
* register is forwarded only when the project's own key AND every one of
|
|
40490
|
+
* those is in scope (see `nestedVerdict`), and its deleted paths are cut to the
|
|
40491
|
+
* ones whose own repository is in scope (`context.deletedFileKeys`, see
|
|
40492
|
+
* `registerForWire`). Machine mode never reads either, and the local write
|
|
40493
|
+
* never receives the context and gets the register whole.
|
|
40991
40494
|
*/
|
|
40992
|
-
async recordProjectEgress(input2) {
|
|
40495
|
+
async recordProjectEgress(input2, context) {
|
|
40993
40496
|
const summary = await this.deps.local.recordProjectEgress(input2);
|
|
40994
40497
|
if (this.verdictFor(() => scopeKeyOfProjectKey(input2.projectKey)) === "local") return summary;
|
|
40498
|
+
if (this.nestedVerdict(context) === "local") return summary;
|
|
40499
|
+
const register = await this.registerForWire(input2, context);
|
|
40500
|
+
if (register === void 0) return summary;
|
|
40995
40501
|
await this.deps.forward.run(
|
|
40996
|
-
() => this.deps.client.recordProjectEgress(toEgressIngestRequest(
|
|
40502
|
+
() => this.deps.client.recordProjectEgress(toEgressIngestRequest(register))
|
|
40997
40503
|
);
|
|
40998
40504
|
return summary;
|
|
40999
40505
|
}
|
|
@@ -41047,6 +40553,11 @@ var AttachedDataGateway = class {
|
|
|
41047
40553
|
async scanLedgerPaths() {
|
|
41048
40554
|
return this.deps.local.scanLedgerPaths();
|
|
41049
40555
|
}
|
|
40556
|
+
// Delegated, like the path list. An inner gateway that cannot say answers an
|
|
40557
|
+
// empty map, which gives every deleted path no key.
|
|
40558
|
+
async scanLedgerPathKeys() {
|
|
40559
|
+
return await this.deps.local.scanLedgerPathKeys?.() ?? /* @__PURE__ */ new Map();
|
|
40560
|
+
}
|
|
41050
40561
|
async recordScanned(entries) {
|
|
41051
40562
|
return this.deps.local.recordScanned(entries);
|
|
41052
40563
|
}
|
|
@@ -41113,6 +40624,12 @@ var AttachedDataGateway = class {
|
|
|
41113
40624
|
// and the spread above would otherwise drop the field silently — which is
|
|
41114
40625
|
// exactly what it did, leaving the whole control inert on every device
|
|
41115
40626
|
// while every test around it stayed green.
|
|
40627
|
+
//
|
|
40628
|
+
// WHOLE ON EVERY ATTACHMENT. A scoped attachment does not narrow the list
|
|
40629
|
+
// here: the port's `getPolicyBundle()` takes no event, and the runtime
|
|
40630
|
+
// reads this bundle once to build detection, so the detections it carries
|
|
40631
|
+
// apply to every event on the machine. Where a prohibition applies is
|
|
40632
|
+
// answered per event by `governanceAppliesTo` below.
|
|
41116
40633
|
prohibitedModels: cached2.prohibitedModels,
|
|
41117
40634
|
// NAMED for the same reason as the line above, and it is the same defect
|
|
41118
40635
|
// if it is not: `...local` above spreads the DEVICE's bundle, so a field
|
|
@@ -41172,6 +40689,30 @@ var AttachedDataGateway = class {
|
|
|
41172
40689
|
};
|
|
41173
40690
|
}
|
|
41174
40691
|
// ---------------------------------------------------------------------
|
|
40692
|
+
// GovernanceScope — where the organization's model policy applies
|
|
40693
|
+
// ---------------------------------------------------------------------
|
|
40694
|
+
/**
|
|
40695
|
+
* Whether the organization's governance applies to an event keyed `scopeKey`:
|
|
40696
|
+
* the question a model-guard site asks once it has decided to refuse.
|
|
40697
|
+
*
|
|
40698
|
+
* THE FORWARD VERDICT, through `verdictFor`: the answer is whether a capture
|
|
40699
|
+
* with the same key would be forwarded. A machine-wide attachment governs
|
|
40700
|
+
* every event, keyless included, exactly as before. A scoped one governs an
|
|
40701
|
+
* event only when its key names an enrolled repository. An event in a
|
|
40702
|
+
* personal repository, in no repository, with an empty key, or met by a fault
|
|
40703
|
+
* is not governed.
|
|
40704
|
+
*
|
|
40705
|
+
* The event's OWN key, never its session root's. The root rule in
|
|
40706
|
+
* `auditVerdict` decides whether a row can be forwarded without orphaning it;
|
|
40707
|
+
* this decides whether a refusal applies, which is a question about where the
|
|
40708
|
+
* event happened.
|
|
40709
|
+
*
|
|
40710
|
+
* Answered from memory: no store read, no bundle read, nothing sent.
|
|
40711
|
+
*/
|
|
40712
|
+
governanceAppliesTo(scopeKey) {
|
|
40713
|
+
return this.verdictFor(() => scopeKey) === "forward";
|
|
40714
|
+
}
|
|
40715
|
+
// ---------------------------------------------------------------------
|
|
41175
40716
|
// LocalStoreMaintenance — by delegation (D3).
|
|
41176
40717
|
//
|
|
41177
40718
|
// Implementing these is what actually closes the skipped-local-maintenance
|
|
@@ -41294,22 +40835,22 @@ var CAPTURE_BATCH_BYTES = 1024 * 1024;
|
|
|
41294
40835
|
|
|
41295
40836
|
// ../../packages/plugin-runtime/src/attached/history-sync-trigger.ts
|
|
41296
40837
|
import { spawn } from "child_process";
|
|
41297
|
-
import { fileURLToPath
|
|
40838
|
+
import { fileURLToPath } from "url";
|
|
41298
40839
|
var HISTORY_SYNC_THROTTLE_MS = 5 * 60 * 1e3;
|
|
41299
40840
|
|
|
41300
40841
|
// ../../packages/plugin-runtime/src/attached/install-record.ts
|
|
41301
40842
|
import { readFile as readFile2, stat } from "fs/promises";
|
|
41302
|
-
import { basename as
|
|
40843
|
+
import { basename as basename3, dirname as dirname6, join as join22, resolve as resolve2 } from "path";
|
|
41303
40844
|
async function readInstalledVersion(installRoot) {
|
|
41304
40845
|
try {
|
|
41305
40846
|
const versionDir = resolve2(installRoot);
|
|
41306
|
-
const pluginDir =
|
|
41307
|
-
const marketplaceDir =
|
|
41308
|
-
const cacheDir =
|
|
41309
|
-
if (
|
|
41310
|
-
const key = `${
|
|
40847
|
+
const pluginDir = dirname6(versionDir);
|
|
40848
|
+
const marketplaceDir = dirname6(pluginDir);
|
|
40849
|
+
const cacheDir = dirname6(marketplaceDir);
|
|
40850
|
+
if (basename3(cacheDir) !== "cache") return null;
|
|
40851
|
+
const key = `${basename3(pluginDir)}@${basename3(marketplaceDir)}`;
|
|
41311
40852
|
const record2 = JSON.parse(
|
|
41312
|
-
await readFile2(
|
|
40853
|
+
await readFile2(join22(dirname6(cacheDir), "installed_plugins.json"), "utf8")
|
|
41313
40854
|
);
|
|
41314
40855
|
const plugins = record2?.plugins;
|
|
41315
40856
|
if (typeof plugins !== "object" || plugins === null || !Object.hasOwn(plugins, key)) {
|
|
@@ -41341,7 +40882,7 @@ async function exists(path) {
|
|
|
41341
40882
|
}
|
|
41342
40883
|
|
|
41343
40884
|
// ../../packages/plugin-runtime/src/attached/plugin-block.ts
|
|
41344
|
-
import { readFileSync as
|
|
40885
|
+
import { readFileSync as readFileSync13 } from "fs";
|
|
41345
40886
|
var INSTALL_RECORD_READ_TIMEOUT_MS = REQUEST_TIMEOUT_MS / 2;
|
|
41346
40887
|
var manifestBuildCache = /* @__PURE__ */ new Map();
|
|
41347
40888
|
function readManifestBuild(manifestUrl, packageName) {
|
|
@@ -41349,7 +40890,7 @@ function readManifestBuild(manifestUrl, packageName) {
|
|
|
41349
40890
|
if (!manifestBuildCache.has(key)) {
|
|
41350
40891
|
let build;
|
|
41351
40892
|
try {
|
|
41352
|
-
const manifest = JSON.parse(
|
|
40893
|
+
const manifest = JSON.parse(readFileSync13(manifestUrl, "utf8"));
|
|
41353
40894
|
build = typeof manifest.version === "string" && manifest.version.length > 0 ? { package: packageName, version: manifest.version } : void 0;
|
|
41354
40895
|
} catch {
|
|
41355
40896
|
build = void 0;
|
|
@@ -41384,9 +40925,9 @@ async function readInstalledVersionBounded(installRoot) {
|
|
|
41384
40925
|
}
|
|
41385
40926
|
|
|
41386
40927
|
// ../../packages/plugin-runtime/src/attached/policy-store.ts
|
|
41387
|
-
import { randomUUID as
|
|
40928
|
+
import { randomUUID as randomUUID15 } from "crypto";
|
|
41388
40929
|
import { readFile as readFile3, rm, writeFile as writeFile2 } from "fs/promises";
|
|
41389
|
-
import { join as
|
|
40930
|
+
import { join as join23 } from "path";
|
|
41390
40931
|
|
|
41391
40932
|
// ../../packages/plugin-runtime/src/attached/atomic-publish.ts
|
|
41392
40933
|
import { rename as rename2 } from "fs/promises";
|
|
@@ -41415,7 +40956,7 @@ async function publishByRename(tmp, file2, move = rename2) {
|
|
|
41415
40956
|
|
|
41416
40957
|
// ../../packages/plugin-runtime/src/attached/policy-store.ts
|
|
41417
40958
|
function createPolicyStore(dir = dataDir()) {
|
|
41418
|
-
const file2 =
|
|
40959
|
+
const file2 = join23(dir, "policy-cache.json");
|
|
41419
40960
|
async function read() {
|
|
41420
40961
|
try {
|
|
41421
40962
|
const raw = await readFile3(file2, "utf8");
|
|
@@ -41447,7 +40988,7 @@ function createPolicyStore(dir = dataDir()) {
|
|
|
41447
40988
|
}
|
|
41448
40989
|
}
|
|
41449
40990
|
async function publishRecord(record2) {
|
|
41450
|
-
const tmp = `${file2}.${
|
|
40991
|
+
const tmp = `${file2}.${randomUUID15()}.tmp`;
|
|
41451
40992
|
try {
|
|
41452
40993
|
await writeFile2(tmp, JSON.stringify(record2), {
|
|
41453
40994
|
encoding: "utf8",
|
|
@@ -41485,8 +41026,8 @@ function createPolicyStore(dir = dataDir()) {
|
|
|
41485
41026
|
}
|
|
41486
41027
|
|
|
41487
41028
|
// ../../packages/plugin-runtime/src/attached/posture-report-state.ts
|
|
41488
|
-
import { readFileSync as
|
|
41489
|
-
import { join as
|
|
41029
|
+
import { readFileSync as readFileSync14 } from "fs";
|
|
41030
|
+
import { join as join24 } from "path";
|
|
41490
41031
|
var POSTURE_REPORT_STATE_FILENAME = ATTACHED_POSTURE_REPORT_FILENAME;
|
|
41491
41032
|
var OUTCOME_KEYS = {
|
|
41492
41033
|
ok: true,
|
|
@@ -41500,7 +41041,7 @@ var OUTCOME_KEYS = {
|
|
|
41500
41041
|
};
|
|
41501
41042
|
var OUTCOMES = new Set(Object.keys(OUTCOME_KEYS));
|
|
41502
41043
|
function postureReportStatePath(dataDir2) {
|
|
41503
|
-
return
|
|
41044
|
+
return join24(dataDir2, POSTURE_REPORT_STATE_FILENAME);
|
|
41504
41045
|
}
|
|
41505
41046
|
function writePostureReportState(dataDir2, state) {
|
|
41506
41047
|
try {
|
|
@@ -41541,10 +41082,19 @@ function createPostureReporter(deps) {
|
|
|
41541
41082
|
hostname: deps.hostname(),
|
|
41542
41083
|
capturedAt: nowMs,
|
|
41543
41084
|
...measurement,
|
|
41544
|
-
// Omit the key rather than spread an explicit `undefined
|
|
41545
|
-
//
|
|
41546
|
-
//
|
|
41547
|
-
|
|
41085
|
+
// Omit the key rather than spread an explicit `undefined`. The type
|
|
41086
|
+
// admits `undefined` here (the schema's optional member), and
|
|
41087
|
+
// JSON.stringify sends the same bytes either way. Omitting keeps the
|
|
41088
|
+
// in-memory object free of an explicit `undefined` member, which the
|
|
41089
|
+
// tests pin by key presence.
|
|
41090
|
+
...plugin === void 0 ? {} : { plugin },
|
|
41091
|
+
// LAST, and only for a scoped attachment. A machine attachment omits
|
|
41092
|
+
// the key the same way, so its body is byte for byte the one it sent
|
|
41093
|
+
// before the member existed. Anything but exactly `machine` reports the
|
|
41094
|
+
// constant `scoped`, never the raw value: that is resolveScope's own
|
|
41095
|
+
// fail direction, and a value outside the wire's vocabulary would fail
|
|
41096
|
+
// the whole snapshot at the receiver, the wipe signal with it.
|
|
41097
|
+
...deps.attachmentMode === "machine" ? {} : { attachmentMode: "scoped" }
|
|
41548
41098
|
};
|
|
41549
41099
|
} catch {
|
|
41550
41100
|
return null;
|
|
@@ -41567,8 +41117,8 @@ function createPostureReporter(deps) {
|
|
|
41567
41117
|
}
|
|
41568
41118
|
|
|
41569
41119
|
// ../../packages/plugin-runtime/src/attached/posture-snapshot.ts
|
|
41570
|
-
import { statSync as
|
|
41571
|
-
import { DatabaseSync as
|
|
41120
|
+
import { statSync as statSync7 } from "fs";
|
|
41121
|
+
import { DatabaseSync as DatabaseSync3 } from "node:sqlite";
|
|
41572
41122
|
|
|
41573
41123
|
// ../../packages/plugin-runtime/src/attached/action-counts.ts
|
|
41574
41124
|
function emptyActionCounts() {
|
|
@@ -41598,7 +41148,7 @@ function emptyReadout(readError = false) {
|
|
|
41598
41148
|
}
|
|
41599
41149
|
function readStorePosture(dbPath2) {
|
|
41600
41150
|
try {
|
|
41601
|
-
|
|
41151
|
+
statSync7(dbPath2);
|
|
41602
41152
|
} catch (err) {
|
|
41603
41153
|
const code = err.code;
|
|
41604
41154
|
if (code === "ENOENT" || code === "ENOTDIR") return emptyReadout();
|
|
@@ -41626,7 +41176,7 @@ function readStorePosture(dbPath2) {
|
|
|
41626
41176
|
readError: false
|
|
41627
41177
|
});
|
|
41628
41178
|
try {
|
|
41629
|
-
db = new
|
|
41179
|
+
db = new DatabaseSync3(dbPath2, { readOnly: true });
|
|
41630
41180
|
db.exec("PRAGMA busy_timeout = 2000");
|
|
41631
41181
|
version2 = db.prepare("PRAGMA user_version").get().user_version;
|
|
41632
41182
|
try {
|
|
@@ -41678,16 +41228,16 @@ function readStorePosture(dbPath2) {
|
|
|
41678
41228
|
}
|
|
41679
41229
|
|
|
41680
41230
|
// ../../packages/plugin-runtime/src/attached/posture-store.ts
|
|
41681
|
-
import { randomUUID as
|
|
41231
|
+
import { randomUUID as randomUUID16 } from "crypto";
|
|
41682
41232
|
import { readFile as readFile4, rm as rm2, writeFile as writeFile3 } from "fs/promises";
|
|
41683
|
-
import { join as
|
|
41233
|
+
import { join as join25 } from "path";
|
|
41684
41234
|
var UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/;
|
|
41685
41235
|
function createPostureStore(dir = settingsDir(), legacyDir) {
|
|
41686
|
-
const file2 =
|
|
41687
|
-
const legacyFile = legacyDir === void 0 ? null :
|
|
41236
|
+
const file2 = join25(dir, "posture-state.json");
|
|
41237
|
+
const legacyFile = legacyDir === void 0 ? null : join25(legacyDir, "posture-state.json");
|
|
41688
41238
|
async function persist(state) {
|
|
41689
41239
|
await ensureDataDir(dir);
|
|
41690
|
-
const tmp = `${file2}.${
|
|
41240
|
+
const tmp = `${file2}.${randomUUID16()}.tmp`;
|
|
41691
41241
|
try {
|
|
41692
41242
|
await writeFile3(tmp, JSON.stringify(state), { encoding: "utf8", mode: DATA_FILE_MODE });
|
|
41693
41243
|
await publishByRename(tmp, file2);
|
|
@@ -41729,7 +41279,7 @@ function createPostureStore(dir = settingsDir(), legacyDir) {
|
|
|
41729
41279
|
}
|
|
41730
41280
|
return legacy;
|
|
41731
41281
|
}
|
|
41732
|
-
const fresh = { deviceId:
|
|
41282
|
+
const fresh = { deviceId: randomUUID16(), lastAttemptedAtMs: 0 };
|
|
41733
41283
|
try {
|
|
41734
41284
|
await ensureDataDir(dir);
|
|
41735
41285
|
if (createOwnerOnlyFileSync(file2, JSON.stringify(fresh))) return fresh;
|
|
@@ -41752,8 +41302,8 @@ function createPostureStore(dir = settingsDir(), legacyDir) {
|
|
|
41752
41302
|
}
|
|
41753
41303
|
|
|
41754
41304
|
// ../../packages/plugin-runtime/src/attached/sync-state.ts
|
|
41755
|
-
import { readFileSync as
|
|
41756
|
-
import { join as
|
|
41305
|
+
import { readFileSync as readFileSync15 } from "fs";
|
|
41306
|
+
import { join as join26 } from "path";
|
|
41757
41307
|
|
|
41758
41308
|
// ../../packages/plugin-runtime/src/attached/status.ts
|
|
41759
41309
|
var REFUSAL_LINES = {
|
|
@@ -41771,7 +41321,7 @@ var OUTCOME_LINES = {
|
|
|
41771
41321
|
|
|
41772
41322
|
// ../../packages/plugin-runtime/src/attached/sync-trigger.ts
|
|
41773
41323
|
import { spawn as spawn2 } from "child_process";
|
|
41774
|
-
import { fileURLToPath as
|
|
41324
|
+
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
41775
41325
|
var SYNC_THROTTLE_MS = 15 * 60 * 1e3;
|
|
41776
41326
|
|
|
41777
41327
|
// ../../packages/plugin-runtime/src/content-retention-pass.ts
|
|
@@ -41779,7 +41329,7 @@ var MAX_ROWS_PER_SWEEP = 50 * 1e3;
|
|
|
41779
41329
|
|
|
41780
41330
|
// ../../packages/plugin-runtime/src/content-retention-trigger.ts
|
|
41781
41331
|
import { spawn as spawn3 } from "child_process";
|
|
41782
|
-
import { fileURLToPath as
|
|
41332
|
+
import { fileURLToPath as fileURLToPath3 } from "url";
|
|
41783
41333
|
var CONTENT_RETENTION_THROTTLE_MS = 60 * 60 * 1e3;
|
|
41784
41334
|
|
|
41785
41335
|
// ../../packages/plugin-runtime/src/attached/factory.ts
|
|
@@ -41796,7 +41346,7 @@ var StandaloneDataGateway = class {
|
|
|
41796
41346
|
// One notice per gateway — see warnRulesetDiscarded.
|
|
41797
41347
|
warnedRulesetDiscarded = false;
|
|
41798
41348
|
constructor(dataDir2, detections = [], meta4) {
|
|
41799
|
-
this.db = openLocalDatabase(dataDir2);
|
|
41349
|
+
this.db = openLocalDatabase(dataDir2, { shippedRegexMatchers: shippedRegexMatchers() });
|
|
41800
41350
|
this.dataDir = dataDir2;
|
|
41801
41351
|
this.db.installedPacks.recordInventory(detections, meta4);
|
|
41802
41352
|
}
|
|
@@ -42145,6 +41695,9 @@ var StandaloneDataGateway = class {
|
|
|
42145
41695
|
scanLedgerPaths() {
|
|
42146
41696
|
return Promise.resolve(this.db.scanLedger.allPaths());
|
|
42147
41697
|
}
|
|
41698
|
+
scanLedgerPathKeys() {
|
|
41699
|
+
return Promise.resolve(this.db.scanLedger.pathKeys());
|
|
41700
|
+
}
|
|
42148
41701
|
recordScanned(entries) {
|
|
42149
41702
|
this.db.scanLedger.upsertEntries(entries);
|
|
42150
41703
|
return Promise.resolve();
|
|
@@ -42232,11 +41785,15 @@ function resolveGatewayForConfig(config2, meta4) {
|
|
|
42232
41785
|
readStore: () => readStorePosture(config2.dbPath),
|
|
42233
41786
|
hostname: () => hostname6(),
|
|
42234
41787
|
now: () => Date.now(),
|
|
41788
|
+
// The mode THIS gateway enforces, from the attachment resolved above,
|
|
41789
|
+
// so the report cannot name a mode the forward paths are not using.
|
|
41790
|
+
attachmentMode: attachment.mode,
|
|
42235
41791
|
// The reporting build's identity, when the caller knows it (the plugin
|
|
42236
41792
|
// adapters do; an embedder or a test may not). Composed with the SAME
|
|
42237
41793
|
// policy store the sync child writes, so the block names the bundle
|
|
42238
|
-
// actually in force.
|
|
42239
|
-
// reporter
|
|
41794
|
+
// actually in force. The dependency key is omitted when no build is
|
|
41795
|
+
// known, and the reporter's optional call (`deps.pluginBlock?.()`)
|
|
41796
|
+
// then adds no block.
|
|
42240
41797
|
...meta4?.pluginBuild === void 0 ? {} : { pluginBlock: createPluginBlock(meta4.pluginBuild, store) }
|
|
42241
41798
|
})
|
|
42242
41799
|
});
|
|
@@ -42253,7 +41810,7 @@ function resolveDataGateway(config2, meta4, gatewayFactory = defaultGatewayFacto
|
|
|
42253
41810
|
}
|
|
42254
41811
|
|
|
42255
41812
|
// ../../packages/plugin-runtime/src/handle-session-start.ts
|
|
42256
|
-
import { randomUUID as
|
|
41813
|
+
import { randomUUID as randomUUID17 } from "crypto";
|
|
42257
41814
|
var EXCEPTION_RETENTION_MS = 90 * 24 * 60 * 60 * 1e3;
|
|
42258
41815
|
|
|
42259
41816
|
// src/build-info.ts
|
|
@@ -42266,17 +41823,17 @@ function pluginBuild() {
|
|
|
42266
41823
|
// src/history/tail.ts
|
|
42267
41824
|
import { createHash as createHash7 } from "crypto";
|
|
42268
41825
|
import {
|
|
42269
|
-
closeSync as
|
|
42270
|
-
fstatSync
|
|
42271
|
-
mkdirSync as
|
|
42272
|
-
openSync as
|
|
42273
|
-
readFileSync as
|
|
42274
|
-
readSync
|
|
42275
|
-
writeFileSync as
|
|
41826
|
+
closeSync as closeSync2,
|
|
41827
|
+
fstatSync,
|
|
41828
|
+
mkdirSync as mkdirSync2,
|
|
41829
|
+
openSync as openSync2,
|
|
41830
|
+
readFileSync as readFileSync16,
|
|
41831
|
+
readSync,
|
|
41832
|
+
writeFileSync as writeFileSync5
|
|
42276
41833
|
} from "fs";
|
|
42277
|
-
import { join as
|
|
41834
|
+
import { join as join27 } from "path";
|
|
42278
41835
|
function offsetsDir(dataDir2) {
|
|
42279
|
-
return
|
|
41836
|
+
return join27(dataDir2, "usage-offsets");
|
|
42280
41837
|
}
|
|
42281
41838
|
var SAFE_SESSION_ID = /^[A-Za-z0-9._-]+$/;
|
|
42282
41839
|
function safeSessionId(sessionId) {
|
|
@@ -42286,11 +41843,11 @@ function safeSessionId(sessionId) {
|
|
|
42286
41843
|
return createHash7("sha256").update(sessionId).digest("hex");
|
|
42287
41844
|
}
|
|
42288
41845
|
function offsetPath(dataDir2, sessionId) {
|
|
42289
|
-
return
|
|
41846
|
+
return join27(offsetsDir(dataDir2), safeSessionId(sessionId));
|
|
42290
41847
|
}
|
|
42291
41848
|
function readOffset(dataDir2, sessionId) {
|
|
42292
41849
|
try {
|
|
42293
|
-
const raw =
|
|
41850
|
+
const raw = readFileSync16(offsetPath(dataDir2, sessionId), "utf8");
|
|
42294
41851
|
const parsed2 = JSON.parse(raw);
|
|
42295
41852
|
if (typeof parsed2 === "object" && parsed2 !== null) {
|
|
42296
41853
|
const rec = parsed2;
|
|
@@ -42304,9 +41861,9 @@ function readOffset(dataDir2, sessionId) {
|
|
|
42304
41861
|
}
|
|
42305
41862
|
function writeOffset(dataDir2, sessionId, value) {
|
|
42306
41863
|
try {
|
|
42307
|
-
|
|
41864
|
+
mkdirSync2(offsetsDir(dataDir2), { recursive: true, mode: DATA_DIR_MODE });
|
|
42308
41865
|
const payload = value.lastPromptId !== void 0 ? { offset: value.offset, lastPromptId: value.lastPromptId } : { offset: value.offset };
|
|
42309
|
-
|
|
41866
|
+
writeFileSync5(offsetPath(dataDir2, sessionId), JSON.stringify(payload), {
|
|
42310
41867
|
mode: DATA_FILE_MODE
|
|
42311
41868
|
});
|
|
42312
41869
|
} catch {
|
|
@@ -42315,19 +41872,19 @@ function writeOffset(dataDir2, sessionId, value) {
|
|
|
42315
41872
|
function readTail(transcriptPath, startOffset) {
|
|
42316
41873
|
let fd;
|
|
42317
41874
|
try {
|
|
42318
|
-
fd =
|
|
41875
|
+
fd = openSync2(transcriptPath, "r");
|
|
42319
41876
|
} catch {
|
|
42320
41877
|
return { chunk: "", nextOffset: startOffset };
|
|
42321
41878
|
}
|
|
42322
41879
|
try {
|
|
42323
|
-
const size =
|
|
41880
|
+
const size = fstatSync(fd).size;
|
|
42324
41881
|
const from = size < startOffset ? 0 : startOffset;
|
|
42325
41882
|
if (from >= size) return { chunk: "", nextOffset: from };
|
|
42326
41883
|
const length = size - from;
|
|
42327
41884
|
const buf = Buffer.allocUnsafe(length);
|
|
42328
41885
|
let filled = 0;
|
|
42329
41886
|
while (filled < length) {
|
|
42330
|
-
const bytesRead =
|
|
41887
|
+
const bytesRead = readSync(fd, buf, filled, length - filled, from + filled);
|
|
42331
41888
|
if (bytesRead === 0) break;
|
|
42332
41889
|
filled += bytesRead;
|
|
42333
41890
|
}
|
|
@@ -42341,16 +41898,16 @@ function readTail(transcriptPath, startOffset) {
|
|
|
42341
41898
|
return { chunk: "", nextOffset: startOffset };
|
|
42342
41899
|
} finally {
|
|
42343
41900
|
try {
|
|
42344
|
-
|
|
41901
|
+
closeSync2(fd);
|
|
42345
41902
|
} catch {
|
|
42346
41903
|
}
|
|
42347
41904
|
}
|
|
42348
41905
|
}
|
|
42349
41906
|
|
|
42350
41907
|
// src/history/transcripts.ts
|
|
42351
|
-
import { closeSync as
|
|
42352
|
-
import { homedir as
|
|
42353
|
-
import { join as
|
|
41908
|
+
import { closeSync as closeSync3, openSync as openSync3, readdirSync as readdirSync2, readFileSync as readFileSync17, readSync as readSync2, statSync as statSync8 } from "fs";
|
|
41909
|
+
import { homedir as homedir2 } from "os";
|
|
41910
|
+
import { join as join28 } from "path";
|
|
42354
41911
|
function isRecord(value) {
|
|
42355
41912
|
return typeof value === "object" && value !== null;
|
|
42356
41913
|
}
|
|
@@ -42412,11 +41969,12 @@ function parseTranscriptUsage(jsonl, sinceMs = 0, knownSessionId) {
|
|
|
42412
41969
|
const last = info.last_token_usage;
|
|
42413
41970
|
if (!isRecord(last)) continue;
|
|
42414
41971
|
const usage = {};
|
|
42415
|
-
|
|
42416
|
-
if (typeof last.
|
|
42417
|
-
|
|
42418
|
-
usage.cache_read_input_tokens = last.cached_input_tokens;
|
|
41972
|
+
const cached2 = typeof last.cached_input_tokens === "number" ? Math.max(0, last.cached_input_tokens) : 0;
|
|
41973
|
+
if (typeof last.input_tokens === "number") {
|
|
41974
|
+
usage.input_tokens = Math.max(0, last.input_tokens - cached2);
|
|
42419
41975
|
}
|
|
41976
|
+
if (typeof last.output_tokens === "number") usage.output_tokens = last.output_tokens;
|
|
41977
|
+
if (typeof last.cached_input_tokens === "number") usage.cache_read_input_tokens = cached2;
|
|
42420
41978
|
if (typeof last.reasoning_output_tokens === "number") {
|
|
42421
41979
|
usage.reasoning_output_tokens = last.reasoning_output_tokens;
|
|
42422
41980
|
}
|