@akasecurity/ai-tc-codex 0.9.15 → 0.9.16
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/hooks/hooks.json +1 -1
- package/package.json +5 -5
- package/scripts/apply-suppressions.js +1472 -393
- package/scripts/backfill.js +1963 -424
- package/scripts/content-retention.js +825 -227
- package/scripts/filescan.js +1900 -361
- package/scripts/firstrun.js +1406 -301
- package/scripts/history-sync.js +841 -228
- package/scripts/intro.js +328 -170
- package/scripts/onboard.js +823 -219
- package/scripts/post-tool-use.js +1960 -343
- package/scripts/pre-tool-use.js +1864 -338
- package/scripts/query.js +1405 -300
- package/scripts/reconcile.js +1873 -329
- package/scripts/remediate.js +1838 -350
- package/scripts/scan-worker.js +281 -149
- package/scripts/session-start.js +1821 -331
- package/scripts/start-light.js +328 -170
- package/scripts/stop.js +346 -190
- package/scripts/sync.js +1898 -359
- package/scripts/user-prompt-submit.js +1906 -373
- package/skills/setup/SKILL.md +27 -12
package/scripts/onboard.js
CHANGED
|
@@ -32,9 +32,9 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
32
32
|
mod
|
|
33
33
|
));
|
|
34
34
|
|
|
35
|
-
// ../../node_modules/.pnpm/ignore@7.0.
|
|
35
|
+
// ../../node_modules/.pnpm/ignore@7.0.11/node_modules/ignore/index.js
|
|
36
36
|
var require_ignore = __commonJS({
|
|
37
|
-
"../../node_modules/.pnpm/ignore@7.0.
|
|
37
|
+
"../../node_modules/.pnpm/ignore@7.0.11/node_modules/ignore/index.js"(exports, module) {
|
|
38
38
|
"use strict";
|
|
39
39
|
function makeArray(subject) {
|
|
40
40
|
return Array.isArray(subject) ? subject : [subject];
|
|
@@ -169,6 +169,7 @@ var require_ignore = __commonJS({
|
|
|
169
169
|
"g"
|
|
170
170
|
);
|
|
171
171
|
var TRAILING_WILDCARD = "\uE000";
|
|
172
|
+
var TRAILING_DOUBLESTAR = "\uE001";
|
|
172
173
|
var extractBrackets = (pattern) => {
|
|
173
174
|
const sources = [];
|
|
174
175
|
const hold = (source) => `${PLACEHOLDER}${sources.push(source) - 1}${PLACEHOLDER}`;
|
|
@@ -329,7 +330,7 @@ var require_ignore = __commonJS({
|
|
|
329
330
|
// Zero, one or several directories
|
|
330
331
|
// should not use '*', or it will be replaced by the next replacer
|
|
331
332
|
// Check if it is not the last `'/**'`
|
|
332
|
-
(_, index, str2) => index + 6 < str2.length ? str2.slice(index + 6) === "\\/" ? "(?:\\/[^\\/]+)+" : "(?:\\/[^\\/]+)*" :
|
|
333
|
+
(_, index, str2) => index + 6 < str2.length ? str2.slice(index + 6) === "\\/" ? "(?:\\/[^\\/]+)+" : "(?:\\/[^\\/]+)*" : `\\/${TRAILING_DOUBLESTAR}`,
|
|
333
334
|
"*"
|
|
334
335
|
],
|
|
335
336
|
// normal intermediate wildcards
|
|
@@ -407,7 +408,7 @@ var require_ignore = __commonJS({
|
|
|
407
408
|
// 'js' will match 'a.js' and 'a.js/'
|
|
408
409
|
(source) => {
|
|
409
410
|
const last = source[source.length - 1];
|
|
410
|
-
if (!last || last === TRAILING_WILDCARD) {
|
|
411
|
+
if (!last || last === TRAILING_WILDCARD || last === TRAILING_DOUBLESTAR) {
|
|
411
412
|
return source;
|
|
412
413
|
}
|
|
413
414
|
return last === SLASH2 ? `${source}$` : `${source}(?=$|\\/$)`;
|
|
@@ -418,16 +419,12 @@ var require_ignore = __commonJS({
|
|
|
418
419
|
var MODE_IGNORE = "regex";
|
|
419
420
|
var MODE_CHECK_IGNORE = "checkRegex";
|
|
420
421
|
var UNDERSCORE = "_";
|
|
421
|
-
var
|
|
422
|
-
[
|
|
423
|
-
|
|
424
|
-
return `${prefix}(?=$|\\/$)`;
|
|
425
|
-
},
|
|
426
|
-
[MODE_CHECK_IGNORE](_, p1) {
|
|
427
|
-
const prefix = p1 ? `${p1}[^/]*` : "[^/]*";
|
|
428
|
-
return `${prefix}(?=$|\\/$)`;
|
|
429
|
-
}
|
|
422
|
+
var replaceTrailingWildcard = (_, p1) => {
|
|
423
|
+
const prefix = p1 ? `${p1}[^/]+` : "[^/]*";
|
|
424
|
+
return `${prefix}(?=$|\\/$)`;
|
|
430
425
|
};
|
|
426
|
+
var REGEX_REPLACE_TRAILING_DOUBLESTAR = /\uE001$/;
|
|
427
|
+
var replaceTrailingDoublestar = () => ".+(?=$|\\/$)";
|
|
431
428
|
var WILDCARD = "[^\\/]*";
|
|
432
429
|
var separatorAfter = (run, at) => {
|
|
433
430
|
let separator = EMPTY;
|
|
@@ -543,6 +540,14 @@ var require_ignore = __commonJS({
|
|
|
543
540
|
(match, index) => sources[index]
|
|
544
541
|
) : replaced;
|
|
545
542
|
};
|
|
543
|
+
var checkSourceOf = (body, prefix) => {
|
|
544
|
+
if (body[body.length - 1] === SLASH2) {
|
|
545
|
+
prefix = makeRegexPrefix(body.slice(0, -1));
|
|
546
|
+
}
|
|
547
|
+
const head = prefix.slice(0, -1);
|
|
548
|
+
const last = prefix[prefix.length - 1];
|
|
549
|
+
return last === TRAILING_WILDCARD ? `${head}$` : last === TRAILING_DOUBLESTAR ? `${head}.*$` : NEVER_MATCH;
|
|
550
|
+
};
|
|
546
551
|
var matchesBasename = (body) => {
|
|
547
552
|
const index = body.indexOf(SLASH2);
|
|
548
553
|
return index < 0 || index === body.length - 1;
|
|
@@ -603,11 +608,9 @@ var require_ignore = __commonJS({
|
|
|
603
608
|
return this._make(MODE_CHECK_IGNORE, key);
|
|
604
609
|
}
|
|
605
610
|
_make(mode, key) {
|
|
606
|
-
const str2 = pinWildcards(
|
|
607
|
-
REGEX_REPLACE_TRAILING_WILDCARD,
|
|
608
|
-
|
|
609
|
-
TRAILING_WILD_CARD_REPLACERS[mode]
|
|
610
|
-
));
|
|
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
|
+
);
|
|
611
614
|
const regex = this.ignoreCase ? new RegExp(str2, "i") : new RegExp(str2);
|
|
612
615
|
return define(this, key, regex);
|
|
613
616
|
}
|
|
@@ -666,8 +669,39 @@ var require_ignore = __commonJS({
|
|
|
666
669
|
makeArray(
|
|
667
670
|
isString(pattern) ? splitPattern(pattern) : pattern
|
|
668
671
|
).forEach(this._add, this);
|
|
672
|
+
if (this._added) {
|
|
673
|
+
this._literalRules = UNDEFINED;
|
|
674
|
+
}
|
|
669
675
|
return this._added;
|
|
670
676
|
}
|
|
677
|
+
// Match the literal 'abc/' for `checkIgnore`, last rule wins. Only a rule
|
|
678
|
+
// ending in a wildcard can match it (see `checkSourceOf`), so the rest
|
|
679
|
+
// are left out once, rather than tested or compiled for every path.
|
|
680
|
+
testLiteral(path) {
|
|
681
|
+
const rules = this._literalRules || (this._literalRules = this._rules.filter(
|
|
682
|
+
({ body }) => body[body.length - (body[body.length - 1] === SLASH2 ? 2 : 1)] === "*"
|
|
683
|
+
));
|
|
684
|
+
let ignored = false;
|
|
685
|
+
let unignored = false;
|
|
686
|
+
let matchedRule;
|
|
687
|
+
for (let index = rules.length - 1; index >= 0; index--) {
|
|
688
|
+
const rule = rules[index];
|
|
689
|
+
if (rule.checkRegex.test(path)) {
|
|
690
|
+
ignored = !rule.negative;
|
|
691
|
+
unignored = rule.negative;
|
|
692
|
+
matchedRule = rule.negative ? UNDEFINED : rule;
|
|
693
|
+
break;
|
|
694
|
+
}
|
|
695
|
+
}
|
|
696
|
+
const ret = {
|
|
697
|
+
ignored,
|
|
698
|
+
unignored
|
|
699
|
+
};
|
|
700
|
+
if (matchedRule) {
|
|
701
|
+
ret.rule = matchedRule;
|
|
702
|
+
}
|
|
703
|
+
return ret;
|
|
704
|
+
}
|
|
671
705
|
// Test one single path without recursively checking parent directories
|
|
672
706
|
//
|
|
673
707
|
// - checkUnignored `boolean` whether should check if the path is unignored,
|
|
@@ -788,14 +822,12 @@ var require_ignore = __commonJS({
|
|
|
788
822
|
if (path.charCodeAt(path.length - 1) !== SLASH_CODE) {
|
|
789
823
|
return this.test(path);
|
|
790
824
|
}
|
|
791
|
-
const
|
|
792
|
-
if (
|
|
793
|
-
|
|
794
|
-
if (parent.ignored) {
|
|
795
|
-
return parent;
|
|
796
|
-
}
|
|
825
|
+
const dir = this._t(path, this._testCache, true);
|
|
826
|
+
if (dir.ignored) {
|
|
827
|
+
return dir;
|
|
797
828
|
}
|
|
798
|
-
|
|
829
|
+
const literal2 = this._rules.testLiteral(path);
|
|
830
|
+
return literal2.ignored || literal2.unignored ? literal2 : dir;
|
|
799
831
|
}
|
|
800
832
|
_t(path, cache, checkUnignored) {
|
|
801
833
|
if (path in cache) {
|
|
@@ -1006,6 +1038,10 @@ var SQLITE_MIGRATIONS = [
|
|
|
1006
1038
|
{
|
|
1007
1039
|
tag: "0036_secret_vault_identity_fingerprint",
|
|
1008
1040
|
sql: "ALTER TABLE `secret_vault` ADD `value_identity_fingerprint` text DEFAULT '' NOT NULL;--> statement-breakpoint\nUPDATE `secret_vault` SET `value_identity_fingerprint` = `value_fingerprint`;\n"
|
|
1041
|
+
},
|
|
1042
|
+
{
|
|
1043
|
+
tag: "0037_finding_location",
|
|
1044
|
+
sql: "ALTER TABLE `inspection_findings` ADD `line` integer;--> statement-breakpoint\nALTER TABLE `inspection_findings` ADD `col` integer;--> statement-breakpoint\nALTER TABLE `inspection_findings` ADD `context` text;--> statement-breakpoint\nCREATE INDEX `idx_inspection_findings_context` ON `inspection_findings` (`first_detected_at`) WHERE context IS NOT NULL;"
|
|
1009
1045
|
}
|
|
1010
1046
|
];
|
|
1011
1047
|
|
|
@@ -21899,11 +21935,33 @@ var ResolutionMethod = external_exports.enum([
|
|
|
21899
21935
|
"false-positive",
|
|
21900
21936
|
"redetected"
|
|
21901
21937
|
]).meta({ id: "ResolutionMethod" });
|
|
21938
|
+
var FindingContextBasis = external_exports.enum(["file", "excerpt"]).meta({ id: "FindingContextBasis" });
|
|
21939
|
+
var FindingContext = external_exports.object({
|
|
21940
|
+
basis: FindingContextBasis,
|
|
21941
|
+
// 1-based line number of `lines[0]`.
|
|
21942
|
+
firstLine: external_exports.number().int().positive(),
|
|
21943
|
+
lines: external_exports.array(external_exports.string()).min(1).max(5),
|
|
21944
|
+
match: external_exports.object({
|
|
21945
|
+
// 1-based line number, within [firstLine, firstLine + lines.length).
|
|
21946
|
+
line: external_exports.number().int().positive(),
|
|
21947
|
+
// Offsets into that entry of `lines`, end exclusive.
|
|
21948
|
+
start: external_exports.number().int().nonnegative(),
|
|
21949
|
+
end: external_exports.number().int().nonnegative()
|
|
21950
|
+
}).nullable()
|
|
21951
|
+
}).meta({ id: "FindingContext" });
|
|
21952
|
+
var FindingLocation = external_exports.object({
|
|
21953
|
+
line: external_exports.number().int().positive(),
|
|
21954
|
+
col: external_exports.number().int().positive(),
|
|
21955
|
+
context: FindingContext.nullable()
|
|
21956
|
+
});
|
|
21902
21957
|
var FindingMatch = external_exports.object({
|
|
21903
21958
|
// Masked preview of the matched value. Never raw content.
|
|
21904
21959
|
maskedValue: external_exports.string(),
|
|
21905
|
-
//
|
|
21906
|
-
contextPrefix: external_exports.string()
|
|
21960
|
+
// Deprecated: always empty. Superseded by `context`.
|
|
21961
|
+
contextPrefix: external_exports.string(),
|
|
21962
|
+
// The masked lines around the match. Absent when the finding predates
|
|
21963
|
+
// context capture or none could be built safely.
|
|
21964
|
+
context: FindingContext.optional()
|
|
21907
21965
|
}).meta({ id: "FindingMatch" });
|
|
21908
21966
|
var FindingDetectionRef = external_exports.object({
|
|
21909
21967
|
id: external_exports.string(),
|
|
@@ -21923,6 +21981,11 @@ var FindingInstance = external_exports.object({
|
|
|
21923
21981
|
provider: FindingProvider,
|
|
21924
21982
|
repo: external_exports.string(),
|
|
21925
21983
|
file: external_exports.string(),
|
|
21984
|
+
// 1-based line and column of the match start in the scanned text (the
|
|
21985
|
+
// column in UTF-16 code units). Absent for findings that predate location
|
|
21986
|
+
// capture or have no source text.
|
|
21987
|
+
line: external_exports.number().int().positive().optional(),
|
|
21988
|
+
col: external_exports.number().int().positive().optional(),
|
|
21926
21989
|
// Who the capturing event is attributed to. Optional: a single-user store
|
|
21927
21990
|
// has no one to attribute a finding to and never sets it.
|
|
21928
21991
|
user: FindingUser.optional(),
|
|
@@ -21984,6 +22047,13 @@ var FindingStats = external_exports.object({
|
|
|
21984
22047
|
low: external_exports.number().int().nonnegative()
|
|
21985
22048
|
})
|
|
21986
22049
|
}).meta({ id: "FindingStats" });
|
|
22050
|
+
var FindingsOverview = external_exports.object({
|
|
22051
|
+
findings: external_exports.number().int().nonnegative(),
|
|
22052
|
+
open: external_exports.number().int().nonnegative(),
|
|
22053
|
+
handled: external_exports.number().int().nonnegative(),
|
|
22054
|
+
resolved: external_exports.number().int().nonnegative(),
|
|
22055
|
+
dismissed: external_exports.number().int().nonnegative()
|
|
22056
|
+
}).meta({ id: "FindingsOverview" });
|
|
21987
22057
|
var FindingFacetItem = external_exports.object({
|
|
21988
22058
|
value: external_exports.string(),
|
|
21989
22059
|
count: external_exports.number().int().nonnegative()
|
|
@@ -22103,6 +22173,7 @@ var FindingInstanceDetail = FindingInstance.extend({
|
|
|
22103
22173
|
}).meta({ id: "FindingInstanceDetail" });
|
|
22104
22174
|
var DEFAULT_FLAT_FINDINGS_LIMIT = 50;
|
|
22105
22175
|
var MAX_FLAT_FINDINGS_LIMIT = 200;
|
|
22176
|
+
var FindingContextQuery = external_exports.object({ id: external_exports.string().min(1).max(256) });
|
|
22106
22177
|
var ListFindingInstancesQuery = external_exports.object({
|
|
22107
22178
|
severity: external_exports.array(Severity).optional(),
|
|
22108
22179
|
// Rule ids, the same vocabulary the types list's `subtype` carries. Pinning
|
|
@@ -22435,7 +22506,23 @@ var CaptureAttributes = external_exports.object({
|
|
|
22435
22506
|
// capture denied by another finding's own Block policy carries `block`
|
|
22436
22507
|
// here too. The full statement is on EventMetadata.redactDegradedTo; it is
|
|
22437
22508
|
// repeated rather than referenced because a store reader opens this file.
|
|
22438
|
-
redact_degraded_to: ActionTaken.optional()
|
|
22509
|
+
redact_degraded_to: ActionTaken.optional(),
|
|
22510
|
+
// The scope key this capture was stamped with: the canonical repository
|
|
22511
|
+
// (`host/owner/repo`) of the path the capture names (a relative path is read
|
|
22512
|
+
// against its working directory), else of its own working directory, or a
|
|
22513
|
+
// chat account's identity. The store's local `scope_key` column reads it, so
|
|
22514
|
+
// a scoped attachment has a per-row key to work from. Absent when no key
|
|
22515
|
+
// could be derived.
|
|
22516
|
+
//
|
|
22517
|
+
// LOCAL ONLY. That is the contract for every path that sends a row. Producers
|
|
22518
|
+
// stamp it in every attachment mode, and the two structural choke points strip
|
|
22519
|
+
// it: the attached gateway's `reKeyForForward` on the live path, and the
|
|
22520
|
+
// history drain's `rebuildAuditEvent`, which drops it through `withoutScopeKey`.
|
|
22521
|
+
// A capture row's bag reaches the wire through `rebuildCapture`, which builds
|
|
22522
|
+
// the metadata from named keys and never names this one; `toCaptureAttributes`,
|
|
22523
|
+
// which builds the bag from a wire event, never emits it. What a scoped
|
|
22524
|
+
// attachment does with the key is not part of this shape's contract.
|
|
22525
|
+
scope_key: external_exports.string().optional()
|
|
22439
22526
|
}).catchall(external_exports.unknown());
|
|
22440
22527
|
var CaptureStatusAttributes = external_exports.object({
|
|
22441
22528
|
source_tool: external_exports.string().optional(),
|
|
@@ -22465,6 +22552,12 @@ var ToolCallInspection = external_exports.object({
|
|
|
22465
22552
|
actionTaken: ActionTaken,
|
|
22466
22553
|
confidence: external_exports.number().min(0).max(1)
|
|
22467
22554
|
});
|
|
22555
|
+
var findingLocationFields = {
|
|
22556
|
+
line: external_exports.number().int().positive().optional(),
|
|
22557
|
+
col: external_exports.number().int().positive().optional(),
|
|
22558
|
+
context: FindingContext.nullable().optional()
|
|
22559
|
+
};
|
|
22560
|
+
var ToolCallInspectionInput = ToolCallInspection.extend(findingLocationFields);
|
|
22468
22561
|
var ToolCallInput = external_exports.object({
|
|
22469
22562
|
sessionId: external_exports.string().min(1),
|
|
22470
22563
|
toolUseId: external_exports.string().min(1),
|
|
@@ -22474,7 +22567,7 @@ var ToolCallInput = external_exports.object({
|
|
|
22474
22567
|
attributes: ToolCallAttributes,
|
|
22475
22568
|
// Secrets detected in the tool's (masked) target — written as linked
|
|
22476
22569
|
// `inspection_findings`. Empty for a clean tool call.
|
|
22477
|
-
inspections: external_exports.array(
|
|
22570
|
+
inspections: external_exports.array(ToolCallInspectionInput).default([])
|
|
22478
22571
|
});
|
|
22479
22572
|
var InventoryInput = external_exports.object({
|
|
22480
22573
|
objectType: InventoryObjectType,
|
|
@@ -22548,7 +22641,8 @@ var InspectionFindingInput = external_exports.object({
|
|
|
22548
22641
|
// same findingKey — mirrors the legacy `findings.first_detected_at`.
|
|
22549
22642
|
// Optional: when omitted, the writer derives it from the referenced audit
|
|
22550
22643
|
// event's startedAt on first insert (see SqliteInspectionFindingsRepository).
|
|
22551
|
-
firstDetectedAt: external_exports.iso.datetime().optional()
|
|
22644
|
+
firstDetectedAt: external_exports.iso.datetime().optional(),
|
|
22645
|
+
...findingLocationFields
|
|
22552
22646
|
});
|
|
22553
22647
|
var InventoryContext = external_exports.object({
|
|
22554
22648
|
host: InventoryInput.optional(),
|
|
@@ -23326,6 +23420,17 @@ var AttachedCredential = external_exports.object({
|
|
|
23326
23420
|
keyPrefix: external_exports.string().min(1).max(16).optional(),
|
|
23327
23421
|
mintedAt: external_exports.iso.datetime().optional()
|
|
23328
23422
|
});
|
|
23423
|
+
var AttachmentMode = external_exports.enum(["machine", "scoped"]);
|
|
23424
|
+
var ATTACHED_CREDENTIAL_SCOPED_SPEC_VERSION = 2;
|
|
23425
|
+
var AttachedCredentialV1 = AttachedCredential;
|
|
23426
|
+
var AttachedCredentialV2 = AttachedCredential.extend({
|
|
23427
|
+
specVersion: external_exports.literal(ATTACHED_CREDENTIAL_SCOPED_SPEC_VERSION),
|
|
23428
|
+
mode: external_exports.literal("scoped")
|
|
23429
|
+
});
|
|
23430
|
+
var AttachedCredentialAny = external_exports.discriminatedUnion("specVersion", [
|
|
23431
|
+
AttachedCredentialV1,
|
|
23432
|
+
AttachedCredentialV2
|
|
23433
|
+
]);
|
|
23329
23434
|
var MAX_DATE_MS = 253402300799999;
|
|
23330
23435
|
var MAX_INT4 = 2147483647;
|
|
23331
23436
|
var StorePosturePack = external_exports.object({
|
|
@@ -23607,6 +23712,130 @@ var PackId = external_exports.string().regex(/^[a-z][a-z0-9-]*$/);
|
|
|
23607
23712
|
var SemVer = external_exports.string().regex(/^\d+\.\d+\.\d+(?:-[0-9A-Za-z-.]+)?$/);
|
|
23608
23713
|
var PublisherKind = external_exports.enum(["labs", "user", "org"]);
|
|
23609
23714
|
|
|
23715
|
+
// ../../packages/schema/src/zod/builtin-policy-id.ts
|
|
23716
|
+
var KNOWN_BUILTIN_IDS = ["monitor", "warn", "redact", "vault", "block"];
|
|
23717
|
+
var BuiltinPolicyId = external_exports.enum(KNOWN_BUILTIN_IDS).meta({ id: "BuiltinPolicyId" });
|
|
23718
|
+
|
|
23719
|
+
// ../../packages/schema/src/zod/event.ts
|
|
23720
|
+
var EventKind = external_exports.enum(["prompt", "response", "code_change", "tool_use"]).meta({ id: "EventKind" });
|
|
23721
|
+
var CAPTURE_EVENT_TYPES_SQL = EventKind.options.map((k) => `'${k}'`).join(",");
|
|
23722
|
+
var EventMetadata = external_exports.object({
|
|
23723
|
+
sessionId: external_exports.string().optional(),
|
|
23724
|
+
repo: external_exports.string().optional(),
|
|
23725
|
+
filePath: external_exports.string().optional(),
|
|
23726
|
+
// The host tool whose input/output was scanned (e.g. 'Bash', 'WebFetch'),
|
|
23727
|
+
// set by the tool-scanning hooks. The tool NAME only — never the tool's
|
|
23728
|
+
// arguments or output, which can carry the very value a finding masked
|
|
23729
|
+
// (metadata is stored unredacted). Gives findings on non-file captures a
|
|
23730
|
+
// display location ("via Bash") when no filePath exists.
|
|
23731
|
+
toolName: external_exports.string().optional(),
|
|
23732
|
+
// Set (true) by the worktree scanner when the file is excluded by the
|
|
23733
|
+
// repo's .gitignore. Gitignored files ARE still scanned — local scratch and
|
|
23734
|
+
// generated code can leak real secrets — but the provenance is recorded so
|
|
23735
|
+
// policy/dashboards can treat those findings as informational rather than
|
|
23736
|
+
// blocking. Omitted (not false) for tracked files and non-scan events.
|
|
23737
|
+
gitignored: external_exports.boolean().optional(),
|
|
23738
|
+
// Set (true) ONLY when the event's `content` is the COMPLETE file at
|
|
23739
|
+
// capture time (a worktree scan reading from disk). Hook-captured edits
|
|
23740
|
+
// (e.g. an Edit tool's new_string) are partial fragments and MUST NOT set
|
|
23741
|
+
// this. The resolver-on-ingest keys its fixed-at-source dropout
|
|
23742
|
+
// diff on this marker: only a whole-file snapshot can prove a previously
|
|
23743
|
+
// open finding is gone; a fragment's absence proves nothing (the secret
|
|
23744
|
+
// may live outside the hunk). Omitted (not false) for fragments and
|
|
23745
|
+
// non-scan events, so pre-marker clients safely default to the
|
|
23746
|
+
// non-authoritative path.
|
|
23747
|
+
wholeFile: external_exports.boolean().optional(),
|
|
23748
|
+
model: external_exports.string().optional(),
|
|
23749
|
+
turnIndex: external_exports.number().int().nonnegative().optional(),
|
|
23750
|
+
// Distributed-tracing correlation. `correlationId` ties a recorded event back
|
|
23751
|
+
// to the request that captured/ingested it (a UUID, generated independently of
|
|
23752
|
+
// the trace id); `traceId` is the W3C trace id (32 lowercase hex chars) of the
|
|
23753
|
+
// originating span when telemetry is enabled. Both optional + backward
|
|
23754
|
+
// compatible — populated by the plugin (see @akasecurity/plugin-sdk).
|
|
23755
|
+
correlationId: external_exports.uuid().optional(),
|
|
23756
|
+
traceId: external_exports.string().regex(/^[0-9a-f]{32}$/).optional(),
|
|
23757
|
+
// Ids of the detection exceptions that downgraded findings in this capture
|
|
23758
|
+
// to 'allow' — the enforcement audit trail's link back to the grant that
|
|
23759
|
+
// authorized the bypass. Absent on captures where no exception applied.
|
|
23760
|
+
exceptionIds: external_exports.array(external_exports.guid()).optional(),
|
|
23761
|
+
// The assistant message this capture belongs to, and the conversation it sits
|
|
23762
|
+
// in — set by the browser extension's network capture so a stored `response`
|
|
23763
|
+
// row can be joined to the `llm_call` leaf describing the same turn. Absent
|
|
23764
|
+
// on every other capture path, which has no such id.
|
|
23765
|
+
//
|
|
23766
|
+
// Non-empty for the reason WebExchange.messageId is: it is the join key, and
|
|
23767
|
+
// a blank one matches no `llm_call` leaf. That refusal reaches only the
|
|
23768
|
+
// places an event is PARSED; the local write path types the event and parses
|
|
23769
|
+
// nothing, which is why `toCaptureAttributes` omits a blank one separately.
|
|
23770
|
+
messageId: external_exports.string().min(1).optional(),
|
|
23771
|
+
conversationId: external_exports.string().optional(),
|
|
23772
|
+
// How long THIS capture's inspection blocked its caller, in whole
|
|
23773
|
+
// milliseconds — the plugin's own added latency, NOT the LLM call it sat in
|
|
23774
|
+
// front of. Measured inside `capture()` (@akasecurity/plugin-sdk) across
|
|
23775
|
+
// detection + redaction, the work the host session actually waits on.
|
|
23776
|
+
//
|
|
23777
|
+
// Stamped ONLY on live in-flight captures. A capture that carries its own
|
|
23778
|
+
// `occurredAt` is replaying past work (the transcript backfill, the worktree
|
|
23779
|
+
// scan), and its scan duration is not latency any host session experienced,
|
|
23780
|
+
// so those rows leave this ABSENT rather than reporting a misleading number.
|
|
23781
|
+
// Absent is also what every pre-measurement client writes, and what a
|
|
23782
|
+
// clock failure degrades to — a reader must treat absence as "not measured"
|
|
23783
|
+
// and never as a zero, which would read as "inspection is free".
|
|
23784
|
+
inspectionMs: external_exports.number().int().nonnegative().optional(),
|
|
23785
|
+
// What a `redact` this capture COULD NOT CARRY OUT became instead — the
|
|
23786
|
+
// workspace's `redactFallback`, applied because the field could not be
|
|
23787
|
+
// masked in place (a shell command, a URL, or any argument on a host whose
|
|
23788
|
+
// hook contract offers no rewrite channel).
|
|
23789
|
+
//
|
|
23790
|
+
// It exists because the action alone cannot say why. A finding recorded as
|
|
23791
|
+
// `warn` reads identically whether its detection was ASSIGNED Warn or was
|
|
23792
|
+
// assigned Redact on a field that could not take one — and those are
|
|
23793
|
+
// different facts about the same row: the first is a policy the user chose,
|
|
23794
|
+
// the second is a masking the host could not perform. Absent means no
|
|
23795
|
+
// degrade happened, which is every ordinary capture.
|
|
23796
|
+
//
|
|
23797
|
+
// TWO LIMITS a reader of a stored row has to know, because the grain here
|
|
23798
|
+
// is the CAPTURE while `actionTaken` is per FINDING:
|
|
23799
|
+
//
|
|
23800
|
+
// - It does not say WHICH finding degraded. A capture carrying a degraded
|
|
23801
|
+
// `redact` alongside a finding ASSIGNED the same action stores both
|
|
23802
|
+
// identically and one reason for the pair; attributing it to both
|
|
23803
|
+
// describes the assigned one wrongly, and to neither loses the degrade.
|
|
23804
|
+
// - PRESENCE IS NOT CAUSATION. The value is the action the lost redact
|
|
23805
|
+
// became, not the reason the capture ended as it did — a capture denied
|
|
23806
|
+
// by some other finding's own Block policy still carries `block` here,
|
|
23807
|
+
// and clearing the workspace's fallback would not have let it through.
|
|
23808
|
+
// Gate on the value against what a fallback can produce; never read the
|
|
23809
|
+
// field's presence as "this was the fallback's doing".
|
|
23810
|
+
//
|
|
23811
|
+
// Both are pinned as behaviour in @akasecurity/plugin-sdk's runtime suite.
|
|
23812
|
+
// Closing either means moving the reason onto the finding row, which
|
|
23813
|
+
// already carries its own action.
|
|
23814
|
+
redactDegradedTo: ActionTaken.optional()
|
|
23815
|
+
}).meta({ id: "EventMetadata" });
|
|
23816
|
+
var Event = external_exports.object({
|
|
23817
|
+
id: external_exports.guid(),
|
|
23818
|
+
sourceTool: SourceTool,
|
|
23819
|
+
kind: EventKind,
|
|
23820
|
+
occurredAt: external_exports.iso.datetime(),
|
|
23821
|
+
contentHash: external_exports.string(),
|
|
23822
|
+
content: external_exports.string(),
|
|
23823
|
+
metadata: EventMetadata.optional()
|
|
23824
|
+
}).meta({ id: "Event" });
|
|
23825
|
+
var IngestEvent = Event.meta({ id: "IngestEvent" });
|
|
23826
|
+
var INGEST_BATCH_MAX = 100;
|
|
23827
|
+
var IngestBatch = external_exports.object({
|
|
23828
|
+
events: external_exports.array(IngestEvent).min(1).max(INGEST_BATCH_MAX),
|
|
23829
|
+
// Dedup policy for this batch. Id-dedup ALWAYS applies. 'content-hash'
|
|
23830
|
+
// additionally rejects any event whose contentHash the store has already
|
|
23831
|
+
// recorded — for re-runnable bulk ingest (worktree scan, transcript
|
|
23832
|
+
// backfill), where a re-run mints fresh event ids for identical content and
|
|
23833
|
+
// would otherwise accumulate duplicates. Live hook traffic must NOT set it:
|
|
23834
|
+
// two genuinely separate prompts can be byte-identical and both belong on
|
|
23835
|
+
// the timeline.
|
|
23836
|
+
dedupe: external_exports.literal("content-hash").optional()
|
|
23837
|
+
}).meta({ id: "IngestBatch" });
|
|
23838
|
+
|
|
23610
23839
|
// ../../packages/schema/src/zod/rule.ts
|
|
23611
23840
|
var MatcherType = external_exports.enum(["keyword", "regex"]).meta({ id: "MatcherType" });
|
|
23612
23841
|
var RuleProbeVerdict = external_exports.enum(["safe", "quarantined"]).meta({ id: "RuleProbeVerdict" });
|
|
@@ -23675,7 +23904,10 @@ var Matcher = external_exports.discriminatedUnion("type", [KeywordMatcher, Regex
|
|
|
23675
23904
|
var MATCHER_TYPES = MatcherType.options;
|
|
23676
23905
|
var AppliesTo = external_exports.strictObject({
|
|
23677
23906
|
// Dot-prefixed, e.g. ".py" — matches the scanner's SOURCE_EXTENSIONS shape.
|
|
23678
|
-
extensions: external_exports.array(external_exports.string().regex(/^\.[A-Za-z0-9]+$/)).min(1)
|
|
23907
|
+
extensions: external_exports.array(external_exports.string().regex(/^\.[A-Za-z0-9]+$/)).min(1).optional(),
|
|
23908
|
+
eventKinds: external_exports.array(EventKind).min(1).optional()
|
|
23909
|
+
}).refine((v) => v.extensions !== void 0 || v.eventKinds !== void 0, {
|
|
23910
|
+
message: "appliesTo needs extensions, eventKinds, or both"
|
|
23679
23911
|
}).meta({ id: "AppliesTo" });
|
|
23680
23912
|
var PostValidatorName = external_exports.enum(["entropy", "luhn"]).meta({ id: "PostValidatorName" });
|
|
23681
23913
|
var PostValidatorRef = external_exports.union(
|
|
@@ -23698,6 +23930,7 @@ var PostValidatorRef = external_exports.union(
|
|
|
23698
23930
|
)}) or { "name": ..., "config": { ... } }. An unrecognized name would be a false-positive guard that never runs.`
|
|
23699
23931
|
}
|
|
23700
23932
|
).meta({ id: "PostValidatorRef" });
|
|
23933
|
+
var RuleEvidence = external_exports.enum(["code", "value"]).meta({ id: "RuleEvidence" });
|
|
23701
23934
|
var RequiresNearby = external_exports.strictObject({
|
|
23702
23935
|
// Each array, when present, must be non-empty and contain non-empty strings —
|
|
23703
23936
|
// an empty/blank criterion would either never fire or (for labels) match
|
|
@@ -23720,6 +23953,8 @@ var RuleFixture = external_exports.strictObject({
|
|
|
23720
23953
|
// Simulated file context for the scan, so fixtures can assert `appliesTo`
|
|
23721
23954
|
// gating (e.g. a Python-only pattern must NOT fire in a .ts file).
|
|
23722
23955
|
filePath: external_exports.string().optional(),
|
|
23956
|
+
// Simulated capture kind, so fixtures can assert `appliesTo.eventKinds`.
|
|
23957
|
+
eventKind: EventKind.optional(),
|
|
23723
23958
|
expectedSpans: external_exports.array(external_exports.strictObject({ start: external_exports.number(), end: external_exports.number() })).optional()
|
|
23724
23959
|
}).meta({ id: "RuleFixture" });
|
|
23725
23960
|
var Rule = external_exports.strictObject({
|
|
@@ -23745,7 +23980,9 @@ var Rule = external_exports.strictObject({
|
|
|
23745
23980
|
appliesTo: AppliesTo.optional(),
|
|
23746
23981
|
postValidators: external_exports.array(PostValidatorRef).optional(),
|
|
23747
23982
|
requiresNearby: RequiresNearby.optional(),
|
|
23748
|
-
examples: external_exports.array(external_exports.string()).optional()
|
|
23983
|
+
examples: external_exports.array(external_exports.string()).optional(),
|
|
23984
|
+
// Whether the matched text is itself sensitive. Absent means 'value'.
|
|
23985
|
+
evidence: RuleEvidence.optional()
|
|
23749
23986
|
}).meta({ id: "Rule" });
|
|
23750
23987
|
var Author = external_exports.object({
|
|
23751
23988
|
name: external_exports.string(),
|
|
@@ -23762,7 +23999,11 @@ var PackManifest = external_exports.object({
|
|
|
23762
23999
|
description: external_exports.string().optional(),
|
|
23763
24000
|
author: Author.optional(),
|
|
23764
24001
|
license: external_exports.string().optional(),
|
|
23765
|
-
sourceUrl: external_exports.url().optional()
|
|
24002
|
+
sourceUrl: external_exports.url().optional(),
|
|
24003
|
+
// The built-in policy a FIRST install of this pack assigns
|
|
24004
|
+
// (installed_packs.policy_id). Absent leaves the pack unassigned, so its
|
|
24005
|
+
// rules follow the category policies. An existing install never takes it.
|
|
24006
|
+
defaultPolicy: BuiltinPolicyId.optional()
|
|
23766
24007
|
}).meta({ id: "PackManifest" });
|
|
23767
24008
|
|
|
23768
24009
|
// ../../packages/schema/src/zod/detection.ts
|
|
@@ -23790,10 +24031,12 @@ var DetectionListItem = external_exports.object({
|
|
|
23790
24031
|
// Per-pack enforcement-policy assignment. Holds a BuiltinPolicyId ARCHETYPE
|
|
23791
24032
|
// (monitor|warn|redact|block) — NOT a policies-table Policy.id guid; a
|
|
23792
24033
|
// detection is a PACK, and its policy is the archetype applied to all its
|
|
23793
|
-
// rules. Absent == unassigned, which resolves to Monitor
|
|
23794
|
-
// (DEFAULT_PACK_POLICY_ID)
|
|
23795
|
-
//
|
|
23796
|
-
//
|
|
24034
|
+
// rules. Absent == unassigned, which resolves to Monitor by default
|
|
24035
|
+
// (DEFAULT_PACK_POLICY_ID); a host may resolve it to a policy of its own
|
|
24036
|
+
// (see the dashboard's `unassignedPolicy`). Every enforcement surface
|
|
24037
|
+
// expands it into per-rule policies (see policyIdToAction). Typed
|
|
24038
|
+
// z.string() (not the enum) to keep the OpenAPI response tolerant of a
|
|
24039
|
+
// future custom id.
|
|
23797
24040
|
policyId: external_exports.string().optional(),
|
|
23798
24041
|
// Set ONLY when a newer snapshot is available for this pack (OSS: the
|
|
23799
24042
|
// bundled inventory recorded in available_packs differs from the installed
|
|
@@ -23862,10 +24105,12 @@ var DetectionDetail = external_exports.object({
|
|
|
23862
24105
|
// Per-pack enforcement-policy assignment. Holds a BuiltinPolicyId ARCHETYPE
|
|
23863
24106
|
// (monitor|warn|redact|block) — NOT a policies-table Policy.id guid; a
|
|
23864
24107
|
// detection is a PACK, and its policy is the archetype applied to all its
|
|
23865
|
-
// rules. Absent == unassigned, which resolves to Monitor
|
|
23866
|
-
// (DEFAULT_PACK_POLICY_ID)
|
|
23867
|
-
//
|
|
23868
|
-
//
|
|
24108
|
+
// rules. Absent == unassigned, which resolves to Monitor by default
|
|
24109
|
+
// (DEFAULT_PACK_POLICY_ID); a host may resolve it to a policy of its own
|
|
24110
|
+
// (see the dashboard's `unassignedPolicy`). Every enforcement surface
|
|
24111
|
+
// expands it into per-rule policies (see policyIdToAction). Typed
|
|
24112
|
+
// z.string() (not the enum) to keep the OpenAPI response tolerant of a
|
|
24113
|
+
// future custom id.
|
|
23869
24114
|
policyId: external_exports.string().optional()
|
|
23870
24115
|
}).meta({ id: "DetectionDetail" });
|
|
23871
24116
|
var LibraryItem = external_exports.object({
|
|
@@ -24012,126 +24257,6 @@ function buildDetectionsList(summaries, query) {
|
|
|
24012
24257
|
return { counts, items: filtered.map(summaryToDetectionListItem) };
|
|
24013
24258
|
}
|
|
24014
24259
|
|
|
24015
|
-
// ../../packages/schema/src/zod/event.ts
|
|
24016
|
-
var EventKind = external_exports.enum(["prompt", "response", "code_change", "tool_use"]).meta({ id: "EventKind" });
|
|
24017
|
-
var CAPTURE_EVENT_TYPES_SQL = EventKind.options.map((k) => `'${k}'`).join(",");
|
|
24018
|
-
var EventMetadata = external_exports.object({
|
|
24019
|
-
sessionId: external_exports.string().optional(),
|
|
24020
|
-
repo: external_exports.string().optional(),
|
|
24021
|
-
filePath: external_exports.string().optional(),
|
|
24022
|
-
// The host tool whose input/output was scanned (e.g. 'Bash', 'WebFetch'),
|
|
24023
|
-
// set by the tool-scanning hooks. The tool NAME only — never the tool's
|
|
24024
|
-
// arguments or output, which can carry the very value a finding masked
|
|
24025
|
-
// (metadata is stored unredacted). Gives findings on non-file captures a
|
|
24026
|
-
// display location ("via Bash") when no filePath exists.
|
|
24027
|
-
toolName: external_exports.string().optional(),
|
|
24028
|
-
// Set (true) by the worktree scanner when the file is excluded by the
|
|
24029
|
-
// repo's .gitignore. Gitignored files ARE still scanned — local scratch and
|
|
24030
|
-
// generated code can leak real secrets — but the provenance is recorded so
|
|
24031
|
-
// policy/dashboards can treat those findings as informational rather than
|
|
24032
|
-
// blocking. Omitted (not false) for tracked files and non-scan events.
|
|
24033
|
-
gitignored: external_exports.boolean().optional(),
|
|
24034
|
-
// Set (true) ONLY when the event's `content` is the COMPLETE file at
|
|
24035
|
-
// capture time (a worktree scan reading from disk). Hook-captured edits
|
|
24036
|
-
// (e.g. an Edit tool's new_string) are partial fragments and MUST NOT set
|
|
24037
|
-
// this. The resolver-on-ingest keys its fixed-at-source dropout
|
|
24038
|
-
// diff on this marker: only a whole-file snapshot can prove a previously
|
|
24039
|
-
// open finding is gone; a fragment's absence proves nothing (the secret
|
|
24040
|
-
// may live outside the hunk). Omitted (not false) for fragments and
|
|
24041
|
-
// non-scan events, so pre-marker clients safely default to the
|
|
24042
|
-
// non-authoritative path.
|
|
24043
|
-
wholeFile: external_exports.boolean().optional(),
|
|
24044
|
-
model: external_exports.string().optional(),
|
|
24045
|
-
turnIndex: external_exports.number().int().nonnegative().optional(),
|
|
24046
|
-
// Distributed-tracing correlation. `correlationId` ties a recorded event back
|
|
24047
|
-
// to the request that captured/ingested it (a UUID, generated independently of
|
|
24048
|
-
// the trace id); `traceId` is the W3C trace id (32 lowercase hex chars) of the
|
|
24049
|
-
// originating span when telemetry is enabled. Both optional + backward
|
|
24050
|
-
// compatible — populated by the plugin (see @akasecurity/plugin-sdk).
|
|
24051
|
-
correlationId: external_exports.uuid().optional(),
|
|
24052
|
-
traceId: external_exports.string().regex(/^[0-9a-f]{32}$/).optional(),
|
|
24053
|
-
// Ids of the detection exceptions that downgraded findings in this capture
|
|
24054
|
-
// to 'allow' — the enforcement audit trail's link back to the grant that
|
|
24055
|
-
// authorized the bypass. Absent on captures where no exception applied.
|
|
24056
|
-
exceptionIds: external_exports.array(external_exports.guid()).optional(),
|
|
24057
|
-
// The assistant message this capture belongs to, and the conversation it sits
|
|
24058
|
-
// in — set by the browser extension's network capture so a stored `response`
|
|
24059
|
-
// row can be joined to the `llm_call` leaf describing the same turn. Absent
|
|
24060
|
-
// on every other capture path, which has no such id.
|
|
24061
|
-
//
|
|
24062
|
-
// Non-empty for the reason WebExchange.messageId is: it is the join key, and
|
|
24063
|
-
// a blank one matches no `llm_call` leaf. That refusal reaches only the
|
|
24064
|
-
// places an event is PARSED; the local write path types the event and parses
|
|
24065
|
-
// nothing, which is why `toCaptureAttributes` omits a blank one separately.
|
|
24066
|
-
messageId: external_exports.string().min(1).optional(),
|
|
24067
|
-
conversationId: external_exports.string().optional(),
|
|
24068
|
-
// How long THIS capture's inspection blocked its caller, in whole
|
|
24069
|
-
// milliseconds — the plugin's own added latency, NOT the LLM call it sat in
|
|
24070
|
-
// front of. Measured inside `capture()` (@akasecurity/plugin-sdk) across
|
|
24071
|
-
// detection + redaction, the work the host session actually waits on.
|
|
24072
|
-
//
|
|
24073
|
-
// Stamped ONLY on live in-flight captures. A capture that carries its own
|
|
24074
|
-
// `occurredAt` is replaying past work (the transcript backfill, the worktree
|
|
24075
|
-
// scan), and its scan duration is not latency any host session experienced,
|
|
24076
|
-
// so those rows leave this ABSENT rather than reporting a misleading number.
|
|
24077
|
-
// Absent is also what every pre-measurement client writes, and what a
|
|
24078
|
-
// clock failure degrades to — a reader must treat absence as "not measured"
|
|
24079
|
-
// and never as a zero, which would read as "inspection is free".
|
|
24080
|
-
inspectionMs: external_exports.number().int().nonnegative().optional(),
|
|
24081
|
-
// What a `redact` this capture COULD NOT CARRY OUT became instead — the
|
|
24082
|
-
// workspace's `redactFallback`, applied because the field could not be
|
|
24083
|
-
// masked in place (a shell command, a URL, or any argument on a host whose
|
|
24084
|
-
// hook contract offers no rewrite channel).
|
|
24085
|
-
//
|
|
24086
|
-
// It exists because the action alone cannot say why. A finding recorded as
|
|
24087
|
-
// `warn` reads identically whether its detection was ASSIGNED Warn or was
|
|
24088
|
-
// assigned Redact on a field that could not take one — and those are
|
|
24089
|
-
// different facts about the same row: the first is a policy the user chose,
|
|
24090
|
-
// the second is a masking the host could not perform. Absent means no
|
|
24091
|
-
// degrade happened, which is every ordinary capture.
|
|
24092
|
-
//
|
|
24093
|
-
// TWO LIMITS a reader of a stored row has to know, because the grain here
|
|
24094
|
-
// is the CAPTURE while `actionTaken` is per FINDING:
|
|
24095
|
-
//
|
|
24096
|
-
// - It does not say WHICH finding degraded. A capture carrying a degraded
|
|
24097
|
-
// `redact` alongside a finding ASSIGNED the same action stores both
|
|
24098
|
-
// identically and one reason for the pair; attributing it to both
|
|
24099
|
-
// describes the assigned one wrongly, and to neither loses the degrade.
|
|
24100
|
-
// - PRESENCE IS NOT CAUSATION. The value is the action the lost redact
|
|
24101
|
-
// became, not the reason the capture ended as it did — a capture denied
|
|
24102
|
-
// by some other finding's own Block policy still carries `block` here,
|
|
24103
|
-
// and clearing the workspace's fallback would not have let it through.
|
|
24104
|
-
// Gate on the value against what a fallback can produce; never read the
|
|
24105
|
-
// field's presence as "this was the fallback's doing".
|
|
24106
|
-
//
|
|
24107
|
-
// Both are pinned as behaviour in @akasecurity/plugin-sdk's runtime suite.
|
|
24108
|
-
// Closing either means moving the reason onto the finding row, which
|
|
24109
|
-
// already carries its own action.
|
|
24110
|
-
redactDegradedTo: ActionTaken.optional()
|
|
24111
|
-
}).meta({ id: "EventMetadata" });
|
|
24112
|
-
var Event = external_exports.object({
|
|
24113
|
-
id: external_exports.guid(),
|
|
24114
|
-
sourceTool: SourceTool,
|
|
24115
|
-
kind: EventKind,
|
|
24116
|
-
occurredAt: external_exports.iso.datetime(),
|
|
24117
|
-
contentHash: external_exports.string(),
|
|
24118
|
-
content: external_exports.string(),
|
|
24119
|
-
metadata: EventMetadata.optional()
|
|
24120
|
-
}).meta({ id: "Event" });
|
|
24121
|
-
var IngestEvent = Event.meta({ id: "IngestEvent" });
|
|
24122
|
-
var INGEST_BATCH_MAX = 100;
|
|
24123
|
-
var IngestBatch = external_exports.object({
|
|
24124
|
-
events: external_exports.array(IngestEvent).min(1).max(INGEST_BATCH_MAX),
|
|
24125
|
-
// Dedup policy for this batch. Id-dedup ALWAYS applies. 'content-hash'
|
|
24126
|
-
// additionally rejects any event whose contentHash the store has already
|
|
24127
|
-
// recorded — for re-runnable bulk ingest (worktree scan, transcript
|
|
24128
|
-
// backfill), where a re-run mints fresh event ids for identical content and
|
|
24129
|
-
// would otherwise accumulate duplicates. Live hook traffic must NOT set it:
|
|
24130
|
-
// two genuinely separate prompts can be byte-identical and both belong on
|
|
24131
|
-
// the timeline.
|
|
24132
|
-
dedupe: external_exports.literal("content-hash").optional()
|
|
24133
|
-
}).meta({ id: "IngestBatch" });
|
|
24134
|
-
|
|
24135
24260
|
// ../../packages/schema/src/zod/exception.ts
|
|
24136
24261
|
var ExceptionScope = external_exports.enum(["once", "temporary", "permanent"]);
|
|
24137
24262
|
var ExceptionConditions = external_exports.object({
|
|
@@ -24599,6 +24724,8 @@ function toInstanceDetail(row) {
|
|
|
24599
24724
|
provider: toApiProvider(row.sourceTool),
|
|
24600
24725
|
repo: row.repo,
|
|
24601
24726
|
file: row.file,
|
|
24727
|
+
...row.line === void 0 ? {} : { line: row.line },
|
|
24728
|
+
...row.col === void 0 ? {} : { col: row.col },
|
|
24602
24729
|
...row.toolName === void 0 ? {} : { toolName: row.toolName },
|
|
24603
24730
|
eventId: row.eventId,
|
|
24604
24731
|
...row.sessionId === void 0 ? {} : { sessionId: row.sessionId },
|
|
@@ -24612,7 +24739,11 @@ function toInstanceDetail(row) {
|
|
|
24612
24739
|
category,
|
|
24613
24740
|
subtype: row.ruleId,
|
|
24614
24741
|
severity: row.severity,
|
|
24615
|
-
match: {
|
|
24742
|
+
match: {
|
|
24743
|
+
maskedValue: row.maskedMatch,
|
|
24744
|
+
contextPrefix: "",
|
|
24745
|
+
...row.context === void 0 ? {} : { context: row.context }
|
|
24746
|
+
},
|
|
24616
24747
|
detection: { id: row.ruleId, name: null },
|
|
24617
24748
|
policy: { id: `category:${category}`, name: category }
|
|
24618
24749
|
};
|
|
@@ -24724,8 +24855,6 @@ var Policy = external_exports.object({
|
|
|
24724
24855
|
// test `prohibitedModels` passes and `reversibleRuleIds` fails.
|
|
24725
24856
|
provenance: PolicyProvenance.optional()
|
|
24726
24857
|
}).meta({ id: "Policy" });
|
|
24727
|
-
var KNOWN_BUILTIN_IDS = ["monitor", "warn", "redact", "vault", "block"];
|
|
24728
|
-
var BuiltinPolicyId = external_exports.enum(KNOWN_BUILTIN_IDS).meta({ id: "BuiltinPolicyId" });
|
|
24729
24858
|
var RedactFallback = BuiltinPolicyId.extract(["monitor", "warn", "block"]).meta({
|
|
24730
24859
|
id: "RedactFallback"
|
|
24731
24860
|
});
|
|
@@ -25120,7 +25249,7 @@ function isVaultConsentValid(consent) {
|
|
|
25120
25249
|
}
|
|
25121
25250
|
|
|
25122
25251
|
// ../../packages/schema/src/zod/local.ts
|
|
25123
|
-
var WORKSPACE_SETTINGS_SPEC_VERSION =
|
|
25252
|
+
var WORKSPACE_SETTINGS_SPEC_VERSION = 9;
|
|
25124
25253
|
var MODEL_JUDGE_PAYLOAD_VERSION = 1;
|
|
25125
25254
|
var RunMode = external_exports.enum(["standalone", "attached"]);
|
|
25126
25255
|
var ControlPlaneConnection = external_exports.object({
|
|
@@ -25143,6 +25272,18 @@ var HistorySyncConsent = external_exports.object({
|
|
|
25143
25272
|
payloadVersion: external_exports.number().int().positive(),
|
|
25144
25273
|
endpoint: external_exports.string()
|
|
25145
25274
|
});
|
|
25275
|
+
var ATTACHMENT_SCOPE_IDENTITY_MAX_LENGTH = 512;
|
|
25276
|
+
var AttachmentScopeEntry = external_exports.object({
|
|
25277
|
+
kind: external_exports.enum(["repo", "account"]),
|
|
25278
|
+
identity: printable(ATTACHMENT_SCOPE_IDENTITY_MAX_LENGTH).min(1),
|
|
25279
|
+
label: printable(80).optional(),
|
|
25280
|
+
enrolledAt: external_exports.iso.datetime()
|
|
25281
|
+
});
|
|
25282
|
+
var AttachmentScope = external_exports.object({
|
|
25283
|
+
endpoint: external_exports.string().min(1),
|
|
25284
|
+
entries: external_exports.array(AttachmentScopeEntry)
|
|
25285
|
+
});
|
|
25286
|
+
var AttachmentScopeEnvelope = AttachmentScope.extend({ entries: external_exports.array(external_exports.unknown()) });
|
|
25146
25287
|
var WebChatCaptureConsent = external_exports.object({
|
|
25147
25288
|
acknowledgedAt: external_exports.iso.datetime(),
|
|
25148
25289
|
version: external_exports.number().int().positive()
|
|
@@ -25213,6 +25354,23 @@ var WorkspaceSettings = external_exports.object({
|
|
|
25213
25354
|
// both widenings. Absent until granted, and a grant for a different endpoint
|
|
25214
25355
|
// or an older payload no longer counts.
|
|
25215
25356
|
historySyncConsent: HistorySyncConsent.optional(),
|
|
25357
|
+
// The identities a SCOPED attachment forwards and the deployment they were
|
|
25358
|
+
// enrolled for (see AttachmentScope). Absent until something is enrolled.
|
|
25359
|
+
//
|
|
25360
|
+
// `z.unknown()`, NOT `AttachmentScope`, and the difference is this field's
|
|
25361
|
+
// whole failure mode. A settings.json that fails this schema reads as the
|
|
25362
|
+
// unonboarded defaults (readUserSettings in @akasecurity/persistence), and the
|
|
25363
|
+
// next save writes those defaults back over it. Typed, one entry with an
|
|
25364
|
+
// unknown `kind`, a control character or a bad timestamp would cost the
|
|
25365
|
+
// attachment, every consent and onboardedAt, permanently. Untyped, the value
|
|
25366
|
+
// is kept exactly as found and validated where it is used: parseAttachmentScope
|
|
25367
|
+
// drops a bad entry by itself, and on a scoped attachment resolveScope reads a
|
|
25368
|
+
// bad envelope as no entries, which keeps every event local.
|
|
25369
|
+
//
|
|
25370
|
+
// No default: absent must stay absent, so defaultWorkspaceSettings() and a
|
|
25371
|
+
// fresh settings.json do not change. No `.meta({ id })`, like every field
|
|
25372
|
+
// here. Not a ManagedSettingKey.
|
|
25373
|
+
attachmentScope: external_exports.unknown().optional(),
|
|
25216
25374
|
// What the browser extension may record from a web chat, and the grant that
|
|
25217
25375
|
// authorizes it. Absent until the user answers: recording something that was
|
|
25218
25376
|
// never recorded before is never an assumed grant on upgrade, so the whole
|
|
@@ -25307,7 +25465,10 @@ function toInspectionFindingRow(input2) {
|
|
|
25307
25465
|
actionTaken: input2.actionTaken,
|
|
25308
25466
|
confidence: input2.confidence,
|
|
25309
25467
|
findingKey: input2.findingKey ?? null,
|
|
25310
|
-
firstDetectedAt: input2.firstDetectedAt ? isoToEpochMillis(input2.firstDetectedAt) : null
|
|
25468
|
+
firstDetectedAt: input2.firstDetectedAt ? isoToEpochMillis(input2.firstDetectedAt) : null,
|
|
25469
|
+
line: input2.line ?? null,
|
|
25470
|
+
col: input2.col ?? null,
|
|
25471
|
+
context: input2.context ? JSON.stringify(input2.context) : null
|
|
25311
25472
|
};
|
|
25312
25473
|
}
|
|
25313
25474
|
function toCaptureAttributes(event) {
|
|
@@ -26480,6 +26641,15 @@ var COUNTED_SCOPE = `
|
|
|
26480
26641
|
OR outbox_owed = 1
|
|
26481
26642
|
)`;
|
|
26482
26643
|
var SKIPPED = -1;
|
|
26644
|
+
function inScope(column) {
|
|
26645
|
+
return `${column} IN (SELECT value FROM json_each(:scopeKeys))`;
|
|
26646
|
+
}
|
|
26647
|
+
function scopeKeysParam(scopeKeys) {
|
|
26648
|
+
return JSON.stringify(scopeKeys);
|
|
26649
|
+
}
|
|
26650
|
+
var ROOT_SCOPE_KEY = `(SELECT session_root.scope_key
|
|
26651
|
+
FROM audit_events AS session_root
|
|
26652
|
+
WHERE session_root.id = COALESCE(audit_events.root_session_id, audit_events.id))`;
|
|
26483
26653
|
var ROW_COLUMNS = `id,
|
|
26484
26654
|
parent_id AS parentId,
|
|
26485
26655
|
root_session_id AS rootSessionId,
|
|
@@ -26508,6 +26678,18 @@ var SqliteHistorySyncRepository = class {
|
|
|
26508
26678
|
ORDER BY earliest
|
|
26509
26679
|
LIMIT :limit`
|
|
26510
26680
|
);
|
|
26681
|
+
this.scopedSessionsStmt = db.prepare(
|
|
26682
|
+
`SELECT COALESCE(root_session_id, id) AS sessionId, MIN(started_at) AS earliest
|
|
26683
|
+
FROM audit_events
|
|
26684
|
+
WHERE synced_at IS NULL
|
|
26685
|
+
AND event_type IN (${TYPE_LIST})
|
|
26686
|
+
AND started_at < :before
|
|
26687
|
+
AND ${inScope("scope_key")}
|
|
26688
|
+
AND ${inScope(ROOT_SCOPE_KEY)}
|
|
26689
|
+
GROUP BY sessionId
|
|
26690
|
+
ORDER BY earliest
|
|
26691
|
+
LIMIT :limit`
|
|
26692
|
+
);
|
|
26511
26693
|
this.rowsStmt = db.prepare(
|
|
26512
26694
|
`SELECT ${ROW_COLUMNS}
|
|
26513
26695
|
FROM audit_events
|
|
@@ -26518,6 +26700,18 @@ var SqliteHistorySyncRepository = class {
|
|
|
26518
26700
|
ORDER BY (event_type = 'session') DESC, started_at
|
|
26519
26701
|
LIMIT :limit`
|
|
26520
26702
|
);
|
|
26703
|
+
this.scopedRowsStmt = db.prepare(
|
|
26704
|
+
`SELECT ${ROW_COLUMNS}
|
|
26705
|
+
FROM audit_events
|
|
26706
|
+
WHERE synced_at IS NULL
|
|
26707
|
+
AND event_type IN (${TYPE_LIST})
|
|
26708
|
+
AND started_at < :before
|
|
26709
|
+
AND COALESCE(root_session_id, id) = :sessionId
|
|
26710
|
+
AND ${inScope("scope_key")}
|
|
26711
|
+
AND ${inScope(ROOT_SCOPE_KEY)}
|
|
26712
|
+
ORDER BY (event_type = 'session') DESC, started_at
|
|
26713
|
+
LIMIT :limit`
|
|
26714
|
+
);
|
|
26521
26715
|
this.captureRowsStmt = db.prepare(
|
|
26522
26716
|
`SELECT ${ROW_COLUMNS}
|
|
26523
26717
|
FROM audit_events
|
|
@@ -26529,6 +26723,18 @@ var SqliteHistorySyncRepository = class {
|
|
|
26529
26723
|
ORDER BY started_at
|
|
26530
26724
|
LIMIT :limit`
|
|
26531
26725
|
);
|
|
26726
|
+
this.scopedCaptureRowsStmt = db.prepare(
|
|
26727
|
+
`SELECT ${ROW_COLUMNS}
|
|
26728
|
+
FROM audit_events
|
|
26729
|
+
WHERE synced_at IS NULL
|
|
26730
|
+
AND sync_claimed_at IS NULL
|
|
26731
|
+
AND outbox_owed = 1
|
|
26732
|
+
AND event_type IN (${CAPTURE_TYPE_LIST})
|
|
26733
|
+
AND started_at < :before
|
|
26734
|
+
AND ${inScope("scope_key")}
|
|
26735
|
+
ORDER BY started_at
|
|
26736
|
+
LIMIT :limit`
|
|
26737
|
+
);
|
|
26532
26738
|
this.markOwedStmt = db.prepare(
|
|
26533
26739
|
`UPDATE audit_events SET outbox_owed = 1 WHERE id = :id AND synced_at IS NULL`
|
|
26534
26740
|
);
|
|
@@ -26538,6 +26744,20 @@ var SqliteHistorySyncRepository = class {
|
|
|
26538
26744
|
AND event_type IN (${CAPTURE_TYPE_LIST})
|
|
26539
26745
|
AND started_at < :before`
|
|
26540
26746
|
);
|
|
26747
|
+
this.scopedCaptureBacklogOwedStmt = db.prepare(
|
|
26748
|
+
`UPDATE audit_events SET outbox_owed = 1
|
|
26749
|
+
WHERE synced_at IS NULL
|
|
26750
|
+
AND event_type IN (${CAPTURE_TYPE_LIST})
|
|
26751
|
+
AND started_at < :before
|
|
26752
|
+
AND ${inScope("scope_key")}`
|
|
26753
|
+
);
|
|
26754
|
+
this.markScopeCapturesOwedStmt = db.prepare(
|
|
26755
|
+
`UPDATE audit_events SET outbox_owed = 1
|
|
26756
|
+
WHERE synced_at IS NULL
|
|
26757
|
+
AND outbox_owed IS NULL
|
|
26758
|
+
AND event_type IN (${CAPTURE_TYPE_LIST})
|
|
26759
|
+
AND ${inScope("scope_key")}`
|
|
26760
|
+
);
|
|
26541
26761
|
this.stampStmt = db.prepare(
|
|
26542
26762
|
`UPDATE audit_events
|
|
26543
26763
|
SET synced_at = :at,
|
|
@@ -26696,6 +26916,15 @@ var SqliteHistorySyncRepository = class {
|
|
|
26696
26916
|
claimRowStmt;
|
|
26697
26917
|
releaseRowStmt;
|
|
26698
26918
|
releaseStaleClaimsStmt;
|
|
26919
|
+
// The SCOPED twins, for a scoped attachment: the same reads and seeds with the
|
|
26920
|
+
// scope clause added, prepared once here beside the machine statements, so a
|
|
26921
|
+
// machine attachment's statements are untouched and neither form is compiled
|
|
26922
|
+
// per call.
|
|
26923
|
+
scopedSessionsStmt;
|
|
26924
|
+
scopedRowsStmt;
|
|
26925
|
+
scopedCaptureRowsStmt;
|
|
26926
|
+
scopedCaptureBacklogOwedStmt;
|
|
26927
|
+
markScopeCapturesOwedStmt;
|
|
26699
26928
|
/**
|
|
26700
26929
|
* The masked detections recorded against one tool call.
|
|
26701
26930
|
*
|
|
@@ -26715,15 +26944,33 @@ var SqliteHistorySyncRepository = class {
|
|
|
26715
26944
|
* path's to deliver; this drain exists for what was recorded before it, and a
|
|
26716
26945
|
* row both paths send is at best a duplicate request and at worst — for a
|
|
26717
26946
|
* session root — an overwrite of the inventory ids the live path resolved.
|
|
26947
|
+
*
|
|
26948
|
+
* `scopeKeys` is a scoped attachment's filter: a session is offered only while
|
|
26949
|
+
* its root's key is one of them AND at least one of its unsent rows' keys is
|
|
26950
|
+
* (see scopedSessionsStmt). Omitted, this runs the machine statement,
|
|
26951
|
+
* unchanged; an empty list offers nothing.
|
|
26718
26952
|
*/
|
|
26719
|
-
pendingSessions(limit, before) {
|
|
26720
|
-
|
|
26721
|
-
|
|
26722
|
-
|
|
26953
|
+
pendingSessions(limit, before, scopeKeys) {
|
|
26954
|
+
const rows = scopeKeys === void 0 ? allRows(this.sessionsStmt, { limit, before }) : allRows(this.scopedSessionsStmt, {
|
|
26955
|
+
limit,
|
|
26956
|
+
before,
|
|
26957
|
+
scopeKeys: scopeKeysParam(scopeKeys)
|
|
26958
|
+
});
|
|
26959
|
+
return rows.map((r) => r.sessionId);
|
|
26723
26960
|
}
|
|
26724
|
-
/**
|
|
26725
|
-
|
|
26726
|
-
|
|
26961
|
+
/**
|
|
26962
|
+
* One session's undelivered structural rows within the backlog, root first.
|
|
26963
|
+
*
|
|
26964
|
+
* With `scopeKeys`, only the rows whose own key AND whose session root's key
|
|
26965
|
+
* are among them, whichever session id is passed.
|
|
26966
|
+
*/
|
|
26967
|
+
pendingRows(sessionId, limit, before, scopeKeys) {
|
|
26968
|
+
return scopeKeys === void 0 ? allRows(this.rowsStmt, { sessionId, limit, before }) : allRows(this.scopedRowsStmt, {
|
|
26969
|
+
sessionId,
|
|
26970
|
+
limit,
|
|
26971
|
+
before,
|
|
26972
|
+
scopeKeys: scopeKeysParam(scopeKeys)
|
|
26973
|
+
});
|
|
26727
26974
|
}
|
|
26728
26975
|
/**
|
|
26729
26976
|
* Captures this machine still owes the deployment, oldest first.
|
|
@@ -26732,9 +26979,17 @@ var SqliteHistorySyncRepository = class {
|
|
|
26732
26979
|
* by a time window — see captureRowsStmt for why a window could not express
|
|
26733
26980
|
* this. `before` is the grace window that leaves a just-recorded capture to
|
|
26734
26981
|
* the live path.
|
|
26982
|
+
*
|
|
26983
|
+
* With `scopeKeys`, only captures stamped with one of them, decided per
|
|
26984
|
+
* capture: /v1/events stubs a missing root, so a capture never waits on its
|
|
26985
|
+
* session's scope. An empty list reads nothing.
|
|
26735
26986
|
*/
|
|
26736
|
-
pendingCaptureRows(limit, before) {
|
|
26737
|
-
return allRows(this.captureRowsStmt, { limit, before })
|
|
26987
|
+
pendingCaptureRows(limit, before, scopeKeys) {
|
|
26988
|
+
return scopeKeys === void 0 ? allRows(this.captureRowsStmt, { limit, before }) : allRows(this.scopedCaptureRowsStmt, {
|
|
26989
|
+
limit,
|
|
26990
|
+
before,
|
|
26991
|
+
scopeKeys: scopeKeysParam(scopeKeys)
|
|
26992
|
+
});
|
|
26738
26993
|
}
|
|
26739
26994
|
/**
|
|
26740
26995
|
* Record that a capture is OWED to the deployment.
|
|
@@ -26766,9 +27021,37 @@ var SqliteHistorySyncRepository = class {
|
|
|
26766
27021
|
* Returns how many rows matched, for the caller to log or test against. Not a
|
|
26767
27022
|
* count of NEWLY marked rows — a row still unsynced from an earlier call
|
|
26768
27023
|
* matches again and is counted again, the same as `UPDATE`'s own `changes`.
|
|
27024
|
+
*
|
|
27025
|
+
* `scopeKeys` scopes it for a scoped attachment: only captures stamped with one
|
|
27026
|
+
* of the keys are marked, and an empty list marks none. The scoped capture read
|
|
27027
|
+
* is what keeps a personal capture out of a batch; this keeps the marker to
|
|
27028
|
+
* what the grant covers. Omitted, it runs the machine statement, unchanged.
|
|
26769
27029
|
*/
|
|
26770
|
-
markCaptureBacklogOwed(before) {
|
|
26771
|
-
|
|
27030
|
+
markCaptureBacklogOwed(before, scopeKeys) {
|
|
27031
|
+
const result = scopeKeys === void 0 ? this.markCaptureBacklogOwedStmt.run({ before }) : this.scopedCaptureBacklogOwedStmt.run({ before, scopeKeys: scopeKeysParam(scopeKeys) });
|
|
27032
|
+
return Number(result.changes);
|
|
27033
|
+
}
|
|
27034
|
+
/**
|
|
27035
|
+
* Mark owed every unsent capture stamped with one of `scopeKeys`: the re-seed
|
|
27036
|
+
* an enrollment runs.
|
|
27037
|
+
*
|
|
27038
|
+
* This ASSUMES the contract a scoped caller keeps, and cannot check it: nothing
|
|
27039
|
+
* else marks an out-of-scope capture owed (the live forward must refuse it
|
|
27040
|
+
* before its owed branch, and the consent-time seed must be handed the key
|
|
27041
|
+
* list). Under that contract, an enrolled repository's unsent captures are
|
|
27042
|
+
* reachable only if this runs when the repository is enrolled. Like the
|
|
27043
|
+
* consent seed it is one explicit human action, never something a pass infers,
|
|
27044
|
+
* and its caller must know the history grant is in force: this method cannot
|
|
27045
|
+
* check consent and must not be called without it.
|
|
27046
|
+
*
|
|
27047
|
+
* No time bound. Delivered and skipped rows are never re-opened, and a row
|
|
27048
|
+
* already owed is not counted, so the return value is how many rows this call
|
|
27049
|
+
* newly marked. An empty list marks nothing.
|
|
27050
|
+
*/
|
|
27051
|
+
markScopeCapturesOwed(scopeKeys) {
|
|
27052
|
+
return Number(
|
|
27053
|
+
this.markScopeCapturesOwedStmt.run({ scopeKeys: scopeKeysParam(scopeKeys) }).changes
|
|
27054
|
+
);
|
|
26772
27055
|
}
|
|
26773
27056
|
/**
|
|
26774
27057
|
* Record delivery. Called only AFTER the far side has accepted the rows.
|
|
@@ -26973,8 +27256,12 @@ var SqliteHistorySyncRepository = class {
|
|
|
26973
27256
|
* disown from eating THIS SAME CALL's own re-mark is the order, not the
|
|
26974
27257
|
* bound — disown runs first, re-mark second, both inside the one
|
|
26975
27258
|
* transaction above.
|
|
27259
|
+
*
|
|
27260
|
+
* `scopeKeys` scopes the re-mark exactly as `markCaptureBacklogOwed` is scoped.
|
|
27261
|
+
* The disown before it is not scoped, and must not be: it clears the previous
|
|
27262
|
+
* deployment's markers whatever their scope.
|
|
26976
27263
|
*/
|
|
26977
|
-
rearmFor(fingerprint, backlogBefore, backfillCapturesBefore) {
|
|
27264
|
+
rearmFor(fingerprint, backlogBefore, backfillCapturesBefore, scopeKeys) {
|
|
26978
27265
|
this.ensureRowStmt.run();
|
|
26979
27266
|
withTransaction(
|
|
26980
27267
|
this.db,
|
|
@@ -26985,7 +27272,7 @@ var SqliteHistorySyncRepository = class {
|
|
|
26985
27272
|
this.disownCapturesStmt.run({ attachedAt: backlogBefore });
|
|
26986
27273
|
}
|
|
26987
27274
|
if (backfillCapturesBefore !== void 0) {
|
|
26988
|
-
this.
|
|
27275
|
+
this.markCaptureBacklogOwed(backfillCapturesBefore, scopeKeys);
|
|
26989
27276
|
}
|
|
26990
27277
|
this.setFingerprintStmt.run({ fingerprint, backlogBefore });
|
|
26991
27278
|
},
|
|
@@ -27151,6 +27438,7 @@ function applyMigrations(db, file2, options = {}) {
|
|
|
27151
27438
|
db.exec(`PRAGMA user_version = ${String(SQLITE_MIGRATIONS.length)}`);
|
|
27152
27439
|
}
|
|
27153
27440
|
ensureSyncedAtColumn(db, "audit_events");
|
|
27441
|
+
ensureScopeKeyColumn(db);
|
|
27154
27442
|
ensureScanLedgerTable(db);
|
|
27155
27443
|
ensureHistorySyncTable(db);
|
|
27156
27444
|
ensureBlockedDetectionsTable(db);
|
|
@@ -27576,6 +27864,21 @@ function ensureSyncedAtColumn(db, table2) {
|
|
|
27576
27864
|
ON audit_events (sync_claimed_at) WHERE sync_claimed_at IS NOT NULL`
|
|
27577
27865
|
);
|
|
27578
27866
|
}
|
|
27867
|
+
var SCOPE_KEY_COLUMN_DDL = "ALTER TABLE audit_events ADD COLUMN scope_key text GENERATED ALWAYS AS (CASE WHEN json_valid(attributes) THEN json_extract(attributes, '$.scope_key') END) VIRTUAL";
|
|
27868
|
+
function ensureScopeKeyColumn(db) {
|
|
27869
|
+
if (!schemaObjectExists(db, "table", "audit_events")) return;
|
|
27870
|
+
if (hasScopeKeyColumn(db)) return;
|
|
27871
|
+
withTransaction(
|
|
27872
|
+
db,
|
|
27873
|
+
() => {
|
|
27874
|
+
if (!hasScopeKeyColumn(db)) db.exec(SCOPE_KEY_COLUMN_DDL);
|
|
27875
|
+
},
|
|
27876
|
+
"IMMEDIATE"
|
|
27877
|
+
);
|
|
27878
|
+
}
|
|
27879
|
+
function hasScopeKeyColumn(db) {
|
|
27880
|
+
return columnNames(db, "audit_events", { includeGenerated: true }).includes("scope_key");
|
|
27881
|
+
}
|
|
27579
27882
|
function ensureScanLedgerTable(db) {
|
|
27580
27883
|
db.exec(`CREATE TABLE IF NOT EXISTS scan_ledger (
|
|
27581
27884
|
path TEXT PRIMARY KEY,
|
|
@@ -28453,6 +28756,19 @@ var SqliteAuditEventsRepository = class {
|
|
|
28453
28756
|
if (typeof provider === "string") return provider;
|
|
28454
28757
|
return void 0;
|
|
28455
28758
|
}
|
|
28759
|
+
// The `scope_key` stored on a session root's attributes: the key the history
|
|
28760
|
+
// drain decides that root by. It is NOT necessarily the key of the root event a
|
|
28761
|
+
// caller just wrote, because roots are first-write-wins (see the session-root
|
|
28762
|
+
// upsert above) and the root event that arrives second leaves the stored row as
|
|
28763
|
+
// it was. Returns undefined when the id is not a session root, when the root is
|
|
28764
|
+
// a stub or carries no key, and when the stored value is not a string, which is
|
|
28765
|
+
// what the drain's scoped reads would not match either.
|
|
28766
|
+
sessionScopeKey(sessionId) {
|
|
28767
|
+
const row = this.findById(sessionId);
|
|
28768
|
+
if (row?.event_type !== "session" || !row.attributes) return void 0;
|
|
28769
|
+
const key = parseJsonObject(row.attributes)?.scope_key;
|
|
28770
|
+
return typeof key === "string" ? key : void 0;
|
|
28771
|
+
}
|
|
28456
28772
|
// Every `llm_call` leaf's session id + raw attribute bag, for the read-time token
|
|
28457
28773
|
// rollups. The caller parses each bag and prices it via the
|
|
28458
28774
|
// cost model — we stay a thin reader here (no business logic, no cost). `root_session_id`
|
|
@@ -28473,6 +28789,8 @@ var SqliteAuditEventsRepository = class {
|
|
|
28473
28789
|
var DEFAULT_BATCH_SIZE = 500;
|
|
28474
28790
|
var DEFAULT_MAX_ROWS = 5e4;
|
|
28475
28791
|
var SYNC_LANE_TYPES_SQL = OUTBOX_CAPTURE_TYPE_LIST;
|
|
28792
|
+
var SWEEP = { kind: "sweep" };
|
|
28793
|
+
var HOLD_ALL = { kind: "hold-all" };
|
|
28476
28794
|
var SqliteBodyRetentionRepository = class {
|
|
28477
28795
|
constructor(db) {
|
|
28478
28796
|
this.db = db;
|
|
@@ -28489,6 +28807,14 @@ var SqliteBodyRetentionRepository = class {
|
|
|
28489
28807
|
this.candidatesSyncSafeStmt = this.db.prepare(
|
|
28490
28808
|
select(`AND (event_type NOT IN (${SYNC_LANE_TYPES_SQL}) OR synced_at IS NOT NULL)`)
|
|
28491
28809
|
);
|
|
28810
|
+
this.candidatesScopedStmt = this.db.prepare(
|
|
28811
|
+
select(
|
|
28812
|
+
`AND (event_type NOT IN (${SYNC_LANE_TYPES_SQL}) OR synced_at IS NOT NULL
|
|
28813
|
+
OR (outbox_owed IS NOT 1
|
|
28814
|
+
AND (scope_key IS NULL
|
|
28815
|
+
OR scope_key NOT IN (SELECT value FROM json_each(:scopeKeys)))))`
|
|
28816
|
+
)
|
|
28817
|
+
);
|
|
28492
28818
|
this.heldBySyncStmt = this.db.prepare(`
|
|
28493
28819
|
SELECT COUNT(*) AS n
|
|
28494
28820
|
FROM audit_events
|
|
@@ -28496,37 +28822,63 @@ var SqliteBodyRetentionRepository = class {
|
|
|
28496
28822
|
AND started_at < :cutoff
|
|
28497
28823
|
AND event_type IN (${SYNC_LANE_TYPES_SQL})
|
|
28498
28824
|
AND synced_at IS NULL`);
|
|
28825
|
+
this.heldByScopeStmt = this.db.prepare(`
|
|
28826
|
+
SELECT COUNT(*) AS n
|
|
28827
|
+
FROM audit_events
|
|
28828
|
+
WHERE content IS NOT NULL
|
|
28829
|
+
AND started_at < :cutoff
|
|
28830
|
+
AND event_type IN (${SYNC_LANE_TYPES_SQL})
|
|
28831
|
+
AND synced_at IS NULL
|
|
28832
|
+
AND (outbox_owed = 1
|
|
28833
|
+
OR scope_key IN (SELECT value FROM json_each(:scopeKeys)))`);
|
|
28499
28834
|
this.expireStmt = this.db.prepare(
|
|
28500
28835
|
`UPDATE audit_events SET content = NULL, content_expired_at = :now WHERE id = :id`
|
|
28501
28836
|
);
|
|
28837
|
+
this.expireContextsStmt = this.db.prepare(
|
|
28838
|
+
`UPDATE inspection_findings SET context = NULL
|
|
28839
|
+
WHERE id IN (
|
|
28840
|
+
SELECT f.id
|
|
28841
|
+
FROM inspection_findings f INDEXED BY idx_inspection_findings_context
|
|
28842
|
+
JOIN audit_events e ON e.id = f.audit_event_id
|
|
28843
|
+
WHERE f.context IS NOT NULL
|
|
28844
|
+
AND f.first_detected_at < :cutoff
|
|
28845
|
+
AND e.content IS NULL
|
|
28846
|
+
AND e.started_at < :cutoff
|
|
28847
|
+
LIMIT :limit)`
|
|
28848
|
+
);
|
|
28502
28849
|
}
|
|
28503
28850
|
db;
|
|
28504
28851
|
candidatesStmt;
|
|
28505
28852
|
candidatesSyncSafeStmt;
|
|
28853
|
+
candidatesScopedStmt;
|
|
28506
28854
|
heldBySyncStmt;
|
|
28855
|
+
heldByScopeStmt;
|
|
28507
28856
|
expireStmt;
|
|
28508
|
-
|
|
28857
|
+
expireContextsStmt;
|
|
28858
|
+
/**
|
|
28859
|
+
* How many body bytes a pass with these options would free, changing
|
|
28860
|
+
* nothing. Finding excerpts are not counted (see `bytesFreed`).
|
|
28861
|
+
*/
|
|
28509
28862
|
preview(opts) {
|
|
28510
|
-
const
|
|
28511
|
-
const
|
|
28512
|
-
const rows = stmt.all({ cutoff: opts.cutoff, limit });
|
|
28863
|
+
const lane = laneOf(opts.sweepSyncLane);
|
|
28864
|
+
const rows = this.candidates(lane, opts.cutoff, opts.maxRows ?? DEFAULT_MAX_ROWS);
|
|
28513
28865
|
return {
|
|
28514
28866
|
rowsExpired: rows.length,
|
|
28515
28867
|
bytesFreed: rows.reduce((sum, r) => sum + r.bytes, 0),
|
|
28516
|
-
rowsHeldBySync: this.countHeldBySync(opts)
|
|
28868
|
+
rowsHeldBySync: this.countHeldBySync(lane, opts.cutoff)
|
|
28517
28869
|
};
|
|
28518
28870
|
}
|
|
28519
28871
|
/** Clear eligible bodies, in bounded batches. */
|
|
28520
28872
|
expire(opts) {
|
|
28521
28873
|
const batchSize = opts.batchSize ?? DEFAULT_BATCH_SIZE;
|
|
28522
28874
|
const maxRows = opts.maxRows ?? DEFAULT_MAX_ROWS;
|
|
28523
|
-
const
|
|
28875
|
+
const lane = laneOf(opts.sweepSyncLane);
|
|
28524
28876
|
let rowsExpired = 0;
|
|
28525
28877
|
let bytesFreed = 0;
|
|
28526
28878
|
let done = true;
|
|
28527
28879
|
while (rowsExpired < maxRows) {
|
|
28528
28880
|
const remaining = Math.min(batchSize, maxRows - rowsExpired);
|
|
28529
|
-
const batch =
|
|
28881
|
+
const batch = this.candidates(lane, opts.cutoff, remaining);
|
|
28530
28882
|
if (batch.length === 0) break;
|
|
28531
28883
|
withTransaction(
|
|
28532
28884
|
this.db,
|
|
@@ -28539,17 +28891,60 @@ var SqliteBodyRetentionRepository = class {
|
|
|
28539
28891
|
bytesFreed += batch.reduce((sum, r) => sum + r.bytes, 0);
|
|
28540
28892
|
if (batch.length < remaining) break;
|
|
28541
28893
|
if (rowsExpired >= maxRows) {
|
|
28542
|
-
done =
|
|
28894
|
+
done = this.candidates(lane, opts.cutoff, 1).length === 0;
|
|
28543
28895
|
}
|
|
28544
28896
|
}
|
|
28545
|
-
|
|
28897
|
+
this.expireContexts(opts.cutoff, batchSize, maxRows);
|
|
28898
|
+
return {
|
|
28899
|
+
rowsExpired,
|
|
28900
|
+
bytesFreed,
|
|
28901
|
+
rowsHeldBySync: this.countHeldBySync(lane, opts.cutoff),
|
|
28902
|
+
done
|
|
28903
|
+
};
|
|
28546
28904
|
}
|
|
28547
|
-
|
|
28548
|
-
|
|
28549
|
-
|
|
28905
|
+
// Clear the excerpts that outlived their body, one bounded transaction per
|
|
28906
|
+
// batch for the same reason the body sweep batches, and at most `maxRows` of
|
|
28907
|
+
// them per pass under the same cap: the next pass picks up the rest.
|
|
28908
|
+
expireContexts(cutoff, batchSize, maxRows) {
|
|
28909
|
+
let total = 0;
|
|
28910
|
+
while (total < maxRows) {
|
|
28911
|
+
const limit = Math.min(batchSize, maxRows - total);
|
|
28912
|
+
let cleared = 0;
|
|
28913
|
+
withTransaction(
|
|
28914
|
+
this.db,
|
|
28915
|
+
() => {
|
|
28916
|
+
cleared = Number(this.expireContextsStmt.run({ cutoff, limit }).changes);
|
|
28917
|
+
},
|
|
28918
|
+
"IMMEDIATE"
|
|
28919
|
+
);
|
|
28920
|
+
total += cleared;
|
|
28921
|
+
if (cleared < limit) return;
|
|
28922
|
+
}
|
|
28923
|
+
}
|
|
28924
|
+
/**
|
|
28925
|
+
* One batch of candidates under `lane`, bound with exactly the parameters its
|
|
28926
|
+
* statement names — node:sqlite refuses a named parameter a statement does not
|
|
28927
|
+
* declare, so the key list goes to the scoped statements only.
|
|
28928
|
+
*
|
|
28929
|
+
* Anything that is not `sweep` or `hold-keys` takes the hold-all statement.
|
|
28930
|
+
* The type admits no fourth kind, but this decides what is destroyed, and the
|
|
28931
|
+
* direction an unforeseen value falls has to be holding.
|
|
28932
|
+
*/
|
|
28933
|
+
candidates(lane, cutoff, limit) {
|
|
28934
|
+
const rows = lane.kind === "sweep" ? this.candidatesStmt.all({ cutoff, limit }) : lane.kind === "hold-keys" ? this.candidatesScopedStmt.all({ cutoff, limit, scopeKeys: JSON.stringify(lane.keys) }) : this.candidatesSyncSafeStmt.all({ cutoff, limit });
|
|
28935
|
+
return rows;
|
|
28936
|
+
}
|
|
28937
|
+
countHeldBySync(lane, cutoff) {
|
|
28938
|
+
if (lane.kind === "sweep") return 0;
|
|
28939
|
+
const row = lane.kind === "hold-keys" ? this.heldByScopeStmt.get({ cutoff, scopeKeys: JSON.stringify(lane.keys) }) : this.heldBySyncStmt.get({ cutoff });
|
|
28550
28940
|
return row.n;
|
|
28551
28941
|
}
|
|
28552
28942
|
};
|
|
28943
|
+
function laneOf(gate) {
|
|
28944
|
+
if (gate === true) return SWEEP;
|
|
28945
|
+
if (gate === false) return HOLD_ALL;
|
|
28946
|
+
return gate;
|
|
28947
|
+
}
|
|
28553
28948
|
|
|
28554
28949
|
// ../../packages/persistence/src/repositories/capture-status.ts
|
|
28555
28950
|
var STATUS_LOOKBACK_ROWS = 128;
|
|
@@ -29458,6 +29853,8 @@ function toFlatFindingRow(r) {
|
|
|
29458
29853
|
repo: r.repo ?? "",
|
|
29459
29854
|
file: r.file ?? "",
|
|
29460
29855
|
...r.tool_name === null ? {} : { toolName: r.tool_name },
|
|
29856
|
+
...r.line === null ? {} : { line: r.line },
|
|
29857
|
+
...r.col === null ? {} : { col: r.col },
|
|
29461
29858
|
eventId: r.event_id,
|
|
29462
29859
|
...r.session_id === null ? {} : { sessionId: r.session_id },
|
|
29463
29860
|
status: deriveInstanceStatus(r),
|
|
@@ -29535,7 +29932,8 @@ var FINDING_ROW_COLUMNS_SQL = `f.id AS id, d.rule_id AS rule_id, d.category AS c
|
|
|
29535
29932
|
${latestResolutionStatusSql("f")} AS latest_status,
|
|
29536
29933
|
e.synced_at AS synced_at, e.sync_claimed_at AS sync_claimed_at,
|
|
29537
29934
|
e.sync_failed_at AS sync_failed_at, e.sync_failure AS sync_failure,
|
|
29538
|
-
e.outbox_owed AS outbox_owed
|
|
29935
|
+
e.outbox_owed AS outbox_owed,
|
|
29936
|
+
f.line AS line, f.col AS col`;
|
|
29539
29937
|
var DAY_MS3 = 864e5;
|
|
29540
29938
|
var SqliteFindingsRepository = class {
|
|
29541
29939
|
constructor(db) {
|
|
@@ -29958,6 +30356,27 @@ var SqliteFindingsRepository = class {
|
|
|
29958
30356
|
).get(id);
|
|
29959
30357
|
return Promise.resolve(row === void 0 ? null : toInstanceDetail(toFlatFindingRow(row)));
|
|
29960
30358
|
}
|
|
30359
|
+
/**
|
|
30360
|
+
* One finding's excerpt source (see FindingContextSource). A primary-key
|
|
30361
|
+
* seek, like `findingInstance`, and the only findings read that touches the
|
|
30362
|
+
* event's text — which is why the list never projects the excerpt and the
|
|
30363
|
+
* drawer asks for it here, one finding at a time.
|
|
30364
|
+
*/
|
|
30365
|
+
findingContextSource(id) {
|
|
30366
|
+
const row = this.db.prepare(
|
|
30367
|
+
`SELECT f.context AS context, e.content AS content,
|
|
30368
|
+
f.span_start AS spanStart, f.span_end AS spanEnd,
|
|
30369
|
+
d.rule_id AS ruleId, d.category AS category,
|
|
30370
|
+
json_extract(e.attributes, '$.whole_file') AS wholeFile,
|
|
30371
|
+
e.tool_name AS toolName, e.event_type AS eventType
|
|
30372
|
+
FROM inspection_findings f
|
|
30373
|
+
JOIN audit_events e ON e.id = f.audit_event_id
|
|
30374
|
+
JOIN inspection_definitions d ON d.id = f.inspection_definition_id
|
|
30375
|
+
WHERE f.id = ?`
|
|
30376
|
+
).get(id);
|
|
30377
|
+
if (row === void 0) return null;
|
|
30378
|
+
return { ...row, wholeFile: row.wholeFile === 1 };
|
|
30379
|
+
}
|
|
29961
30380
|
/**
|
|
29962
30381
|
* The one statement both instance-level scans run: every finding in scope,
|
|
29963
30382
|
* joined to its event and definition, newest first.
|
|
@@ -30094,6 +30513,61 @@ var SqliteFindingsRepository = class {
|
|
|
30094
30513
|
])
|
|
30095
30514
|
);
|
|
30096
30515
|
}
|
|
30516
|
+
/**
|
|
30517
|
+
* The Findings page's summary strip: whole-store counts over exactly the rows
|
|
30518
|
+
* the instance reads list (the four capture kinds), each equal to what
|
|
30519
|
+
* listFindingInstances totals for the same filters — see FindingsOverview.
|
|
30520
|
+
*
|
|
30521
|
+
* ONE grouped aggregate whose keys are the raw classifier inputs, not the
|
|
30522
|
+
* answers: the statement groups by the three inputs deriveFindingStatus
|
|
30523
|
+
* reads, and each group is then classified here by that same function. So
|
|
30524
|
+
* SQL never restates the status rule, and the strip cannot disagree with the
|
|
30525
|
+
* list about which status a finding has. The group count is bounded by a
|
|
30526
|
+
* handful of status inputs, not by the store, so only the scan grows with it
|
|
30527
|
+
* — the same linear cost every other unscoped read on the page already pays.
|
|
30528
|
+
*
|
|
30529
|
+
* The definitions join selects nothing. It is there because the list's scan
|
|
30530
|
+
* joins it too, so a finding whose definition row is missing is left out of
|
|
30531
|
+
* both rather than counted here and absent there.
|
|
30532
|
+
*
|
|
30533
|
+
* The latest-resolution join is the derived-table form, which
|
|
30534
|
+
* resolution-sql.ts recommends for an aggregate over many findings.
|
|
30535
|
+
*/
|
|
30536
|
+
findingsOverview() {
|
|
30537
|
+
const rows = allRows(
|
|
30538
|
+
this.db.prepare(
|
|
30539
|
+
`SELECT e.event_type AS kind, (f.finding_key IS NOT NULL) AS keyed,
|
|
30540
|
+
latest.status AS latest_status, count(*) AS c
|
|
30541
|
+
FROM inspection_findings f
|
|
30542
|
+
JOIN audit_events e ON e.id = f.audit_event_id
|
|
30543
|
+
JOIN inspection_definitions d ON d.id = f.inspection_definition_id
|
|
30544
|
+
LEFT JOIN ${LATEST_RESOLUTION_BY_KEY_SQL} latest
|
|
30545
|
+
ON latest.finding_key = f.finding_key
|
|
30546
|
+
WHERE e.event_type IN (${CAPTURE_EVENT_TYPES_SQL})
|
|
30547
|
+
GROUP BY e.event_type, keyed, latest.status`
|
|
30548
|
+
)
|
|
30549
|
+
);
|
|
30550
|
+
const byStatus = {
|
|
30551
|
+
open: 0,
|
|
30552
|
+
handled: 0,
|
|
30553
|
+
resolved: 0,
|
|
30554
|
+
dismissed: 0
|
|
30555
|
+
};
|
|
30556
|
+
let findings = 0;
|
|
30557
|
+
for (const row of rows) {
|
|
30558
|
+
const status = deriveFindingStatus({
|
|
30559
|
+
kind: row.kind,
|
|
30560
|
+
// The classifier only asks whether a key exists, never what it is. The
|
|
30561
|
+
// stand-in is non-empty so a truthiness test of the key reads it as
|
|
30562
|
+
// present, exactly as it would a real one.
|
|
30563
|
+
findingKey: row.keyed ? "keyed" : null,
|
|
30564
|
+
latestResolutionStatus: row.latest_status
|
|
30565
|
+
});
|
|
30566
|
+
findings += row.c;
|
|
30567
|
+
byStatus[status] += row.c;
|
|
30568
|
+
}
|
|
30569
|
+
return Promise.resolve({ findings, ...byStatus });
|
|
30570
|
+
}
|
|
30097
30571
|
healthSummary() {
|
|
30098
30572
|
const total = countScalar(
|
|
30099
30573
|
this.db,
|
|
@@ -30221,12 +30695,13 @@ var SqliteInspectionFindingsRepository = class {
|
|
|
30221
30695
|
`INSERT INTO inspection_findings
|
|
30222
30696
|
(id, audit_event_id, inspection_definition_id, classified_data_id,
|
|
30223
30697
|
span_start, span_end, masked_match, action_taken, confidence,
|
|
30224
|
-
finding_key, first_detected_at)
|
|
30698
|
+
finding_key, first_detected_at, line, col, context)
|
|
30225
30699
|
VALUES
|
|
30226
30700
|
(:id, :auditEventId, :inspectionDefinitionId, :classifiedDataId,
|
|
30227
30701
|
:spanStart, :spanEnd, :maskedMatch, :actionTaken, :confidence,
|
|
30228
30702
|
:findingKey,
|
|
30229
|
-
COALESCE(:firstDetectedAt, (SELECT started_at FROM audit_events WHERE id = :auditEventId))
|
|
30703
|
+
COALESCE(:firstDetectedAt, (SELECT started_at FROM audit_events WHERE id = :auditEventId)),
|
|
30704
|
+
:line, :col, :context)
|
|
30230
30705
|
ON CONFLICT(id) DO UPDATE SET
|
|
30231
30706
|
inspection_definition_id = excluded.inspection_definition_id
|
|
30232
30707
|
ON CONFLICT (finding_key) DO UPDATE SET
|
|
@@ -30237,7 +30712,10 @@ var SqliteInspectionFindingsRepository = class {
|
|
|
30237
30712
|
span_end = excluded.span_end,
|
|
30238
30713
|
masked_match = excluded.masked_match,
|
|
30239
30714
|
action_taken = excluded.action_taken,
|
|
30240
|
-
confidence = excluded.confidence
|
|
30715
|
+
confidence = excluded.confidence,
|
|
30716
|
+
line = excluded.line,
|
|
30717
|
+
col = excluded.col,
|
|
30718
|
+
context = excluded.context`
|
|
30241
30719
|
);
|
|
30242
30720
|
this.sessionDupStmt = db.prepare(
|
|
30243
30721
|
`SELECT 1 FROM inspection_findings f
|
|
@@ -30287,7 +30765,10 @@ var SqliteInspectionFindingsRepository = class {
|
|
|
30287
30765
|
actionTaken: row.actionTaken,
|
|
30288
30766
|
confidence: row.confidence,
|
|
30289
30767
|
findingKey: row.findingKey,
|
|
30290
|
-
firstDetectedAt: row.firstDetectedAt
|
|
30768
|
+
firstDetectedAt: row.firstDetectedAt,
|
|
30769
|
+
line: row.line,
|
|
30770
|
+
col: row.col,
|
|
30771
|
+
context: row.context
|
|
30291
30772
|
})
|
|
30292
30773
|
);
|
|
30293
30774
|
}
|
|
@@ -30967,8 +31448,8 @@ var SqliteInstalledPacksRepository = class {
|
|
|
30967
31448
|
this.db = db;
|
|
30968
31449
|
this.baseDir = baseDir;
|
|
30969
31450
|
this.insertMissingStmt = db.prepare(
|
|
30970
|
-
`INSERT INTO installed_packs (id, namespace, pack_id, version, name, rules_json, enabled, created_at, updated_at)
|
|
30971
|
-
VALUES (:id, :namespace, :packId, :version, :name, :rulesJson, 1, :now, :now)
|
|
31451
|
+
`INSERT INTO installed_packs (id, namespace, pack_id, version, name, rules_json, enabled, policy_id, created_at, updated_at)
|
|
31452
|
+
VALUES (:id, :namespace, :packId, :version, :name, :rulesJson, 1, :policyId, :now, :now)
|
|
30972
31453
|
ON CONFLICT (namespace, pack_id) DO NOTHING`
|
|
30973
31454
|
);
|
|
30974
31455
|
this.upsertAvailableStmt = db.prepare(
|
|
@@ -31028,7 +31509,10 @@ var SqliteInstalledPacksRepository = class {
|
|
|
31028
31509
|
version: pack.version,
|
|
31029
31510
|
name: pack.name,
|
|
31030
31511
|
rulesJson: JSON.stringify(pack.rules),
|
|
31031
|
-
ruleIds: new Set(pack.rules.map((r) => r.id))
|
|
31512
|
+
ruleIds: new Set(pack.rules.map((r) => r.id)),
|
|
31513
|
+
// Only a first install takes it: an existing row is never modified here,
|
|
31514
|
+
// so a policy the user chose (or cleared) is never overwritten.
|
|
31515
|
+
defaultPolicyId: pack.defaultPolicyId ?? null
|
|
31032
31516
|
}));
|
|
31033
31517
|
if (this.storedSignature() === inventorySignature(rows)) return;
|
|
31034
31518
|
const now = Date.now();
|
|
@@ -31057,7 +31541,7 @@ var SqliteInstalledPacksRepository = class {
|
|
|
31057
31541
|
} else {
|
|
31058
31542
|
behind = true;
|
|
31059
31543
|
}
|
|
31060
|
-
this.insertMissingStmt.run(params);
|
|
31544
|
+
this.insertMissingStmt.run({ ...params, policyId: row.defaultPolicyId });
|
|
31061
31545
|
}
|
|
31062
31546
|
if (!behind) this.pruneAvailable(rows.map((r) => `${r.namespace}/${r.packId}`));
|
|
31063
31547
|
},
|
|
@@ -31175,7 +31659,8 @@ var SqliteInstalledPacksRepository = class {
|
|
|
31175
31659
|
rejectedRules: [],
|
|
31176
31660
|
ruleActions: /* @__PURE__ */ new Map(),
|
|
31177
31661
|
ruleVersions: /* @__PURE__ */ new Map(),
|
|
31178
|
-
reversibleRules: /* @__PURE__ */ new Set()
|
|
31662
|
+
reversibleRules: /* @__PURE__ */ new Set(),
|
|
31663
|
+
assignedRules: /* @__PURE__ */ new Set()
|
|
31179
31664
|
};
|
|
31180
31665
|
const reject = (pack, ruleId, reason) => {
|
|
31181
31666
|
if (out.rejectedRules.length >= REJECTED_RULE_DETAIL_CAP) return;
|
|
@@ -31208,6 +31693,8 @@ var SqliteInstalledPacksRepository = class {
|
|
|
31208
31693
|
out.ruleVersions.set(parsed.data.id, row.version);
|
|
31209
31694
|
if (reversible) out.reversibleRules.add(parsed.data.id);
|
|
31210
31695
|
else out.reversibleRules.delete(parsed.data.id);
|
|
31696
|
+
if (row.policyId !== null) out.assignedRules.add(parsed.data.id);
|
|
31697
|
+
else out.assignedRules.delete(parsed.data.id);
|
|
31211
31698
|
} else {
|
|
31212
31699
|
out.invalidRules += 1;
|
|
31213
31700
|
reject(pack, printableRuleId(entry), firstIssueReason(parsed.error));
|
|
@@ -32294,6 +32781,7 @@ var SqliteInventoryAssetsRepository = class {
|
|
|
32294
32781
|
|
|
32295
32782
|
// ../../packages/persistence/src/repositories/policies.ts
|
|
32296
32783
|
import { randomUUID as randomUUID6 } from "crypto";
|
|
32784
|
+
var SEED_BATCH_WINDOW_MS = 6e4;
|
|
32297
32785
|
var SqlitePoliciesRepository = class {
|
|
32298
32786
|
constructor(db) {
|
|
32299
32787
|
this.db = db;
|
|
@@ -32315,39 +32803,123 @@ var SqlitePoliciesRepository = class {
|
|
|
32315
32803
|
});
|
|
32316
32804
|
return Promise.resolve(policies);
|
|
32317
32805
|
}
|
|
32318
|
-
// Seed one policy per bundled category
|
|
32319
|
-
//
|
|
32320
|
-
//
|
|
32806
|
+
// Seed one policy per bundled category at Monitor so the detection-type config
|
|
32807
|
+
// exists from first run. An unassigned pack's rules follow these rows, so
|
|
32808
|
+
// Monitor here is the posture of every pack that ships no defaultPolicy; a pack
|
|
32809
|
+
// that ships one carries its own assignment instead. Only when the
|
|
32810
|
+
// table is empty, so a user's edits are never clobbered.
|
|
32321
32811
|
seedDefaults() {
|
|
32322
32812
|
const count = countScalar(this.db, "SELECT count(*) AS n FROM policies");
|
|
32323
|
-
if (count > 0)
|
|
32813
|
+
if (count > 0) {
|
|
32814
|
+
this.markEarlierChoices();
|
|
32815
|
+
this.monitorUntouchedSeeds();
|
|
32816
|
+
return;
|
|
32817
|
+
}
|
|
32324
32818
|
const stmt = this.db.prepare(
|
|
32325
32819
|
`INSERT INTO policies (id, scope, target, action, enabled, created_at, updated_at)
|
|
32326
32820
|
VALUES (:id, 'global', :target, :action, 1, :now, :now)`
|
|
32327
32821
|
);
|
|
32328
32822
|
failOpenTransaction(this.db, () => {
|
|
32329
|
-
for (const
|
|
32823
|
+
for (const category of Object.keys(DEFAULT_ACTIONS)) {
|
|
32330
32824
|
stmt.run({
|
|
32331
32825
|
id: randomUUID6(),
|
|
32332
32826
|
target: JSON.stringify({ category }),
|
|
32333
|
-
action,
|
|
32827
|
+
action: "log",
|
|
32334
32828
|
now: Date.now()
|
|
32335
32829
|
});
|
|
32336
32830
|
}
|
|
32337
32831
|
});
|
|
32338
32832
|
}
|
|
32833
|
+
// Before this build, upsertCategoryAction INSERTed a new row with updated_at
|
|
32834
|
+
// equal to created_at, so a choice made for a category that had no row yet
|
|
32835
|
+
// (one added in a release after the store was seeded) looks exactly like a
|
|
32836
|
+
// seed. Left alone, fill-gaps would overwrite it and monitorUntouchedSeeds
|
|
32837
|
+
// could reset it. This pass marks such rows as chosen (updated_at =
|
|
32838
|
+
// created_at + 1) before either can read them. A row is an earlier build's
|
|
32839
|
+
// choice, not its seed, when either:
|
|
32840
|
+
// - its action is neither the old seed value (DEFAULT_ACTIONS) nor Monitor,
|
|
32841
|
+
// which no seed of any build ever wrote; or
|
|
32842
|
+
// - it was created well after the seed batch. Every build seeds all of its
|
|
32843
|
+
// categories in one transaction, and only into an empty table, so a row
|
|
32844
|
+
// created later came from upsertCategoryAction.
|
|
32845
|
+
// It needs no marker of its own: every row this build writes has updated_at >
|
|
32846
|
+
// created_at, and the seeds it leaves equal (fresh 'log' seeds, and seeds
|
|
32847
|
+
// moved to Monitor below, which keep their created_at) match neither test, so
|
|
32848
|
+
// after one pass it finds nothing and stays a read. What it cannot tell apart
|
|
32849
|
+
// is an earlier build's choice that equals the seed value AND was made within
|
|
32850
|
+
// the seed batch window; that row is read as a seed.
|
|
32851
|
+
markEarlierChoices() {
|
|
32852
|
+
const rows = allRows(
|
|
32853
|
+
this.db.prepare(
|
|
32854
|
+
`SELECT id, json_extract(target, '$.category') AS category, action,
|
|
32855
|
+
created_at AS c, updated_at AS u
|
|
32856
|
+
FROM policies
|
|
32857
|
+
WHERE scope = 'global' AND json_extract(target, '$.category') IS NOT NULL`
|
|
32858
|
+
)
|
|
32859
|
+
);
|
|
32860
|
+
if (rows.length === 0) return;
|
|
32861
|
+
const seedBatchStart = Math.min(...rows.map((row) => row.c));
|
|
32862
|
+
const seeded = DEFAULT_ACTIONS;
|
|
32863
|
+
const choices = rows.filter(
|
|
32864
|
+
(row) => row.u === row.c && (row.action !== "log" && row.action !== seeded[row.category] || row.c > seedBatchStart + SEED_BATCH_WINDOW_MS)
|
|
32865
|
+
);
|
|
32866
|
+
if (choices.length === 0) return;
|
|
32867
|
+
const stmt = this.db.prepare(
|
|
32868
|
+
`UPDATE policies SET updated_at = created_at + 1 WHERE id = :id AND updated_at = created_at`
|
|
32869
|
+
);
|
|
32870
|
+
failOpenTransaction(this.db, () => {
|
|
32871
|
+
for (const row of choices) stmt.run({ id: row.id });
|
|
32872
|
+
});
|
|
32873
|
+
}
|
|
32874
|
+
// Stores seeded by an earlier build hold DEFAULT_ACTIONS in their category
|
|
32875
|
+
// rows. Those rows used to be shadowed by the Monitor every unassigned pack
|
|
32876
|
+
// emitted; now that unassigned packs defer to them, an untouched one would
|
|
32877
|
+
// turn Monitor into Warn on upgrade with nobody having asked. So a row still
|
|
32878
|
+
// exactly as seeded — the seeded action, never updated since it was created —
|
|
32879
|
+
// is moved to Monitor. A row the user, the setup wizard or the warn-era cap
|
|
32880
|
+
// ever wrote has a later updated_at and is left alone. updated_at is NOT
|
|
32881
|
+
// advanced, so a moved row still reads as an untouched seed (see
|
|
32882
|
+
// isCategoryChosen); it never matches again because it is no longer off 'log'.
|
|
32883
|
+
// One knock-on: when the installed snapshot is unusable (corrupt rules_json)
|
|
32884
|
+
// the gateway falls back to the bundled packs with no per-rule policies, so
|
|
32885
|
+
// every rule follows these rows. On an upgraded store that fallback now
|
|
32886
|
+
// monitors where the earlier build warned.
|
|
32887
|
+
monitorUntouchedSeeds() {
|
|
32888
|
+
const untouched = allRows(
|
|
32889
|
+
this.db.prepare(
|
|
32890
|
+
`SELECT json_extract(target, '$.category') AS category, action FROM policies
|
|
32891
|
+
WHERE scope = 'global' AND json_extract(target, '$.category') IS NOT NULL
|
|
32892
|
+
AND action <> 'log' AND updated_at = created_at`
|
|
32893
|
+
)
|
|
32894
|
+
).filter(
|
|
32895
|
+
(row) => DEFAULT_ACTIONS[row.category] === row.action
|
|
32896
|
+
);
|
|
32897
|
+
if (untouched.length === 0) return;
|
|
32898
|
+
const stmt = this.db.prepare(
|
|
32899
|
+
`UPDATE policies SET action = 'log'
|
|
32900
|
+
WHERE scope = 'global' AND json_extract(target, '$.category') = :category
|
|
32901
|
+
AND action = :seeded AND action <> 'log' AND updated_at = created_at`
|
|
32902
|
+
);
|
|
32903
|
+
failOpenTransaction(this.db, () => {
|
|
32904
|
+
for (const row of untouched) {
|
|
32905
|
+
stmt.run({ category: row.category, seeded: row.action });
|
|
32906
|
+
}
|
|
32907
|
+
});
|
|
32908
|
+
}
|
|
32339
32909
|
// Insert-or-update the single global per-category policy row, keyed on the
|
|
32340
32910
|
// existing uq_policies_scope_target unique index (scope, target). `action`
|
|
32341
32911
|
// uses the SAME vocabulary seedDefaults writes (DEFAULT_ACTIONS' ActionTaken
|
|
32342
32912
|
// values), so the runtime's resolveAction reads rows written by either path
|
|
32343
32913
|
// identically. On conflict, `action`, `enabled`, and `updated_at` are updated;
|
|
32344
|
-
// `id` and `created_at` are left exactly as they were.
|
|
32914
|
+
// `id` and `created_at` are left exactly as they were. Either way updated_at
|
|
32915
|
+
// ends up later than created_at, which is what marks the row as chosen.
|
|
32345
32916
|
upsertCategoryAction(category, action) {
|
|
32346
32917
|
const now = Date.now();
|
|
32347
32918
|
this.db.prepare(
|
|
32348
32919
|
`INSERT INTO policies (id, scope, target, action, enabled, created_at, updated_at)
|
|
32349
|
-
VALUES (:id, 'global', :target, :action, 1, :now, :now)
|
|
32350
|
-
ON CONFLICT(scope, target) DO UPDATE SET action = excluded.action, enabled = 1,
|
|
32920
|
+
VALUES (:id, 'global', :target, :action, 1, :now, :now + 1)
|
|
32921
|
+
ON CONFLICT(scope, target) DO UPDATE SET action = excluded.action, enabled = 1,
|
|
32922
|
+
updated_at = MAX(excluded.updated_at, policies.created_at + 1)`
|
|
32351
32923
|
).run({ id: randomUUID6(), target: JSON.stringify({ category }), action, now });
|
|
32352
32924
|
}
|
|
32353
32925
|
// Caps every global per-category policy currently set to block/redact down
|
|
@@ -32361,6 +32933,16 @@ var SqlitePoliciesRepository = class {
|
|
|
32361
32933
|
).run({ now: Date.now() });
|
|
32362
32934
|
return Number(info.changes);
|
|
32363
32935
|
}
|
|
32936
|
+
// Whether the category's row was ever written after it was created — by the
|
|
32937
|
+
// user, the setup wizard or a cap. A row still as seeded (updated_at equal to
|
|
32938
|
+
// created_at) is not a choice, so a posture filling gaps may replace it.
|
|
32939
|
+
isCategoryChosen(category) {
|
|
32940
|
+
const row = this.db.prepare(
|
|
32941
|
+
`SELECT created_at AS c, updated_at AS u FROM policies
|
|
32942
|
+
WHERE scope='global' AND json_extract(target,'$.category') = :category`
|
|
32943
|
+
).get({ category });
|
|
32944
|
+
return row !== void 0 && row.u !== row.c;
|
|
32945
|
+
}
|
|
32364
32946
|
// Read the current action for a single global per-category policy row, mirroring
|
|
32365
32947
|
// upsertCategoryAction's category-lookup predicate. Returns undefined when no
|
|
32366
32948
|
// row exists yet, so callers can distinguish an unset category from a set one.
|
|
@@ -34606,6 +35188,11 @@ var UNSAFE_TEST_ONLY_RAW_HANDLE = /* @__PURE__ */ Symbol(
|
|
|
34606
35188
|
function linkHost(input2, hostId) {
|
|
34607
35189
|
return hostId ? { ...input2, hostId } : input2;
|
|
34608
35190
|
}
|
|
35191
|
+
function captureAttributesOf(event, scopeKey) {
|
|
35192
|
+
const attributes = toCaptureAttributes(event);
|
|
35193
|
+
if (scopeKey === void 0 || scopeKey === "") return attributes;
|
|
35194
|
+
return { ...attributes, scope_key: scopeKey };
|
|
35195
|
+
}
|
|
34609
35196
|
function closeQuietly(db) {
|
|
34610
35197
|
try {
|
|
34611
35198
|
db.close();
|
|
@@ -34791,7 +35378,7 @@ function openLocalDatabase(dir, options = {}) {
|
|
|
34791
35378
|
);
|
|
34792
35379
|
return dismissed;
|
|
34793
35380
|
}
|
|
34794
|
-
function recordCapture(event, detected) {
|
|
35381
|
+
function recordCapture(event, detected, scopeKey) {
|
|
34795
35382
|
failOpenTransaction(db, () => {
|
|
34796
35383
|
const sessionId = event.metadata?.sessionId;
|
|
34797
35384
|
if (sessionId) {
|
|
@@ -34806,7 +35393,7 @@ function openLocalDatabase(dir, options = {}) {
|
|
|
34806
35393
|
rootSessionId: sessionId,
|
|
34807
35394
|
content: event.content,
|
|
34808
35395
|
contentHash: event.contentHash,
|
|
34809
|
-
attributes:
|
|
35396
|
+
attributes: captureAttributesOf(event, scopeKey)
|
|
34810
35397
|
});
|
|
34811
35398
|
const definitionIds = /* @__PURE__ */ new Map();
|
|
34812
35399
|
for (const finding of detected) {
|
|
@@ -34836,7 +35423,12 @@ function openLocalDatabase(dir, options = {}) {
|
|
|
34836
35423
|
maskedMatch: finding.maskedMatch,
|
|
34837
35424
|
actionTaken: finding.actionTaken,
|
|
34838
35425
|
confidence: finding.confidence,
|
|
34839
|
-
findingKey: finding.findingKey ?? void 0
|
|
35426
|
+
findingKey: finding.findingKey ?? void 0,
|
|
35427
|
+
...finding.location === void 0 ? {} : {
|
|
35428
|
+
line: finding.location.line,
|
|
35429
|
+
col: finding.location.col,
|
|
35430
|
+
context: finding.location.context
|
|
35431
|
+
}
|
|
34840
35432
|
});
|
|
34841
35433
|
}
|
|
34842
35434
|
});
|
|
@@ -34999,6 +35591,7 @@ function openLocalDatabase(dir, options = {}) {
|
|
|
34999
35591
|
// ../../packages/persistence/src/egress-wire.ts
|
|
35000
35592
|
import { createHash as createHash3 } from "crypto";
|
|
35001
35593
|
var SLASH = "/".charCodeAt(0);
|
|
35594
|
+
var SCOPE_KEY = printable(ATTACHMENT_SCOPE_IDENTITY_MAX_LENGTH);
|
|
35002
35595
|
|
|
35003
35596
|
// ../../packages/persistence/src/finding-key.ts
|
|
35004
35597
|
import { createHash as createHash4 } from "crypto";
|
|
@@ -35982,6 +36575,7 @@ var CORROBORATION_FLOOR_MS = BUDGET_MS * CPU_CORROBORATION_SHARE;
|
|
|
35982
36575
|
// ../../packages/plugin-sdk/src/repo.ts
|
|
35983
36576
|
import { existsSync as existsSync9, readFileSync as readFileSync10, statSync as statSync6 } from "fs";
|
|
35984
36577
|
import { basename as basename2, dirname as dirname4, isAbsolute, join as join17, sep as sep2 } from "path";
|
|
36578
|
+
var NO_ATTRIBUTION = Object.freeze({});
|
|
35985
36579
|
|
|
35986
36580
|
// ../../packages/plugin-sdk/src/events.ts
|
|
35987
36581
|
import { createHash as createHash5, randomUUID as randomUUID13 } from "crypto";
|
|
@@ -36056,12 +36650,18 @@ import { join as join23 } from "path";
|
|
|
36056
36650
|
import { readdirSync as readdirSync3, realpathSync as realpathSync3 } from "fs";
|
|
36057
36651
|
import { basename as basename4, dirname as dirname5, sep as sep3 } from "path";
|
|
36058
36652
|
|
|
36653
|
+
// ../../packages/plugin-sdk/src/policy-resolver.ts
|
|
36654
|
+
import { randomUUID as randomUUID14 } from "crypto";
|
|
36655
|
+
|
|
36059
36656
|
// ../../packages/plugin-sdk/src/posture.ts
|
|
36060
36657
|
function applyCategoryPosture(posture, repo, mode = "fill-gaps") {
|
|
36061
36658
|
for (const category of Object.keys(posture)) {
|
|
36062
36659
|
const policyId = posture[category];
|
|
36063
36660
|
if (!policyId) continue;
|
|
36064
|
-
if (mode === "fill-gaps"
|
|
36661
|
+
if (mode === "fill-gaps") {
|
|
36662
|
+
const chosen = repo.isCategoryChosen ? repo.isCategoryChosen(category) : repo.getCategoryAction(category) !== void 0;
|
|
36663
|
+
if (chosen) continue;
|
|
36664
|
+
}
|
|
36065
36665
|
repo.upsertCategoryAction(category, builtinPolicyToAction(policyId));
|
|
36066
36666
|
}
|
|
36067
36667
|
}
|
|
@@ -36097,14 +36697,18 @@ var codexProviderEnvShape = {
|
|
|
36097
36697
|
var CodexProviderEnvSchema = external_exports.object(codexProviderEnvShape);
|
|
36098
36698
|
|
|
36099
36699
|
// ../../packages/plugin-sdk/src/runtime.ts
|
|
36100
|
-
import { randomUUID as
|
|
36700
|
+
import { randomUUID as randomUUID15 } from "crypto";
|
|
36701
|
+
|
|
36702
|
+
// ../../packages/plugin-sdk/src/scope-key.ts
|
|
36703
|
+
import { existsSync as existsSync12 } from "fs";
|
|
36704
|
+
import { dirname as dirname6, isAbsolute as isAbsolute2, join as join25, normalize } from "path";
|
|
36101
36705
|
|
|
36102
36706
|
// ../../packages/plugin-sdk/src/suppressions.ts
|
|
36103
36707
|
var THIRTY_DAYS_MS = 30 * 24 * 60 * 60 * 1e3;
|
|
36104
36708
|
|
|
36105
36709
|
// ../../packages/plugin-sdk/src/throttle.ts
|
|
36106
36710
|
import { mkdirSync as mkdirSync4, statSync as statSync8, writeFileSync as writeFileSync7 } from "fs";
|
|
36107
|
-
import { join as
|
|
36711
|
+
import { join as join26 } from "path";
|
|
36108
36712
|
|
|
36109
36713
|
// ../../packages/setup-wizard/src/onboard-posture.ts
|
|
36110
36714
|
function parsePosture(json2) {
|
|
@@ -36127,7 +36731,7 @@ function parsePosture(json2) {
|
|
|
36127
36731
|
|
|
36128
36732
|
// ../../packages/setup-wizard/src/remediation/rotation-checklist.ts
|
|
36129
36733
|
import { writeFileSync as writeFileSync8 } from "fs";
|
|
36130
|
-
import { join as
|
|
36734
|
+
import { join as join27 } from "path";
|
|
36131
36735
|
|
|
36132
36736
|
// ../../packages/setup-wizard/src/triage/merge.ts
|
|
36133
36737
|
var RANK = Object.fromEntries(
|
|
@@ -36137,7 +36741,7 @@ var RANK = Object.fromEntries(
|
|
|
36137
36741
|
// ../../packages/setup-wizard/src/triage/plan-file.ts
|
|
36138
36742
|
import { mkdtempSync, readFileSync as readFileSync17, rmdirSync, rmSync as rmSync7, writeFileSync as writeFileSync9 } from "fs";
|
|
36139
36743
|
import { tmpdir } from "os";
|
|
36140
|
-
import { basename as basename6, dirname as
|
|
36744
|
+
import { basename as basename6, dirname as dirname7, join as join28 } from "path";
|
|
36141
36745
|
var SuppressionEntrySchema = external_exports.object({
|
|
36142
36746
|
ruleId: external_exports.string(),
|
|
36143
36747
|
category: DetectionCategory,
|
|
@@ -36225,7 +36829,7 @@ function show(body) {
|
|
|
36225
36829
|
|
|
36226
36830
|
// src/skills-registry.ts
|
|
36227
36831
|
import { readdirSync as readdirSync5, readFileSync as readFileSync18 } from "fs";
|
|
36228
|
-
import { join as
|
|
36832
|
+
import { join as join29 } from "path";
|
|
36229
36833
|
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
36230
36834
|
var SKILLS_DIR = fileURLToPath2(new URL("../skills", import.meta.url));
|
|
36231
36835
|
|