@akasecurity/ai-tc-codex 0.9.14 → 0.9.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.codex-plugin/plugin.json +1 -1
- package/package.json +4 -4
- package/scripts/apply-suppressions.js +366 -80
- package/scripts/backfill.js +470 -121
- package/scripts/content-retention.js +184 -55
- package/scripts/filescan.js +470 -121
- package/scripts/firstrun.js +256 -81
- package/scripts/history-sync.js +190 -61
- package/scripts/intro.js +59 -10
- package/scripts/onboard.js +164 -43
- package/scripts/post-tool-use.js +514 -124
- package/scripts/pre-tool-use.js +514 -124
- package/scripts/query.js +255 -80
- package/scripts/reconcile.js +451 -111
- package/scripts/remediate.js +471 -122
- package/scripts/scan-worker.js +241 -34
- package/scripts/session-start.js +507 -126
- package/scripts/start-light.js +59 -10
- package/scripts/stop.js +147 -29
- package/scripts/sync.js +473 -124
- package/scripts/user-prompt-submit.js +514 -124
package/scripts/post-tool-use.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.10/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.10/node_modules/ignore/index.js"(exports, module) {
|
|
38
38
|
"use strict";
|
|
39
39
|
function makeArray(subject) {
|
|
40
40
|
return Array.isArray(subject) ? subject : [subject];
|
|
@@ -429,6 +429,13 @@ var require_ignore = __commonJS({
|
|
|
429
429
|
}
|
|
430
430
|
};
|
|
431
431
|
var WILDCARD = "[^\\/]*";
|
|
432
|
+
var separatorAfter = (run, at) => {
|
|
433
|
+
let separator = EMPTY;
|
|
434
|
+
for (let index = at + 1; index < run.length && !run[index].wildcard; index++) {
|
|
435
|
+
separator += run[index].single;
|
|
436
|
+
}
|
|
437
|
+
return separator;
|
|
438
|
+
};
|
|
432
439
|
var pinWildcards = (source) => {
|
|
433
440
|
if (source.indexOf(WILDCARD) < 0) {
|
|
434
441
|
return source;
|
|
@@ -498,7 +505,7 @@ var require_ignore = __commonJS({
|
|
|
498
505
|
out += token.single;
|
|
499
506
|
return;
|
|
500
507
|
}
|
|
501
|
-
out += at === lastWildcard ? WILDCARD : `(?:(?!${run
|
|
508
|
+
out += at === lastWildcard ? WILDCARD : `(?:(?!${separatorAfter(run, at)})[^\\/])*`;
|
|
502
509
|
});
|
|
503
510
|
run = [];
|
|
504
511
|
};
|
|
@@ -675,13 +682,13 @@ var require_ignore = __commonJS({
|
|
|
675
682
|
const rules = this._rules;
|
|
676
683
|
const { length } = rules;
|
|
677
684
|
const shortcut = this._basenameCount * 2 >= length;
|
|
678
|
-
const
|
|
685
|
+
const basename7 = shortcut ? basenameOf(path) : path;
|
|
679
686
|
for (let index = 0; index < length; index++) {
|
|
680
687
|
const rule = rules[index];
|
|
681
688
|
const { negative } = rule;
|
|
682
689
|
const skip = unignored === negative && ignored !== unignored || negative && !ignored && !unignored && !checkUnignored;
|
|
683
690
|
if (!skip && rule[mode].test(
|
|
684
|
-
shortcut && rule._basenameOnly ?
|
|
691
|
+
shortcut && rule._basenameOnly ? basename7 : path
|
|
685
692
|
)) {
|
|
686
693
|
ignored = !negative;
|
|
687
694
|
unignored = negative;
|
|
@@ -998,6 +1005,10 @@ var SQLITE_MIGRATIONS = [
|
|
|
998
1005
|
{
|
|
999
1006
|
tag: "0035_share_destination_provider_id",
|
|
1000
1007
|
sql: "ALTER TABLE `share_destination` ADD `provider_id` text;"
|
|
1008
|
+
},
|
|
1009
|
+
{
|
|
1010
|
+
tag: "0036_secret_vault_identity_fingerprint",
|
|
1011
|
+
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"
|
|
1001
1012
|
}
|
|
1002
1013
|
];
|
|
1003
1014
|
|
|
@@ -1007,6 +1018,12 @@ var HOUR_MS = 60 * MINUTE_MS;
|
|
|
1007
1018
|
var MAX_TEMPORARY_MS = 24 * HOUR_MS;
|
|
1008
1019
|
var ONCE_BACKSTOP_MS = 30 * MINUTE_MS;
|
|
1009
1020
|
|
|
1021
|
+
// ../../packages/schema/src/invisible-padding.ts
|
|
1022
|
+
var INVISIBLE_PADDING = /[\u00AD\u200B\u2060-\u2064\u202A-\u202E\u2066-\u2069\uFEFF\u{E0001}\u{E0020}-\u{E007F}]/gu;
|
|
1023
|
+
function stripInvisiblePadding(text) {
|
|
1024
|
+
return text.replace(INVISIBLE_PADDING, "");
|
|
1025
|
+
}
|
|
1026
|
+
|
|
1010
1027
|
// ../../node_modules/.pnpm/zod@4.6.5/node_modules/zod/v4/classic/external.js
|
|
1011
1028
|
var external_exports = {};
|
|
1012
1029
|
__export(external_exports, {
|
|
@@ -6033,7 +6050,7 @@ var recursive = /* @__PURE__ */ new WeakMap();
|
|
|
6033
6050
|
var NONE = 0;
|
|
6034
6051
|
var ASSUMED = 1;
|
|
6035
6052
|
var PROVEN = 2;
|
|
6036
|
-
function isRecursive(inst, stack,
|
|
6053
|
+
function isRecursive(inst, stack, resolve3) {
|
|
6037
6054
|
const cached2 = recursive.get(inst);
|
|
6038
6055
|
if (cached2 !== void 0)
|
|
6039
6056
|
return cached2 ? PROVEN : NONE;
|
|
@@ -6043,7 +6060,7 @@ function isRecursive(inst, stack, resolve2) {
|
|
|
6043
6060
|
let result = NONE;
|
|
6044
6061
|
const check2 = (child) => {
|
|
6045
6062
|
if (result !== PROVEN && child?._zod) {
|
|
6046
|
-
const answer = isRecursive(child, stack,
|
|
6063
|
+
const answer = isRecursive(child, stack, resolve3);
|
|
6047
6064
|
if (answer > result)
|
|
6048
6065
|
result = answer;
|
|
6049
6066
|
}
|
|
@@ -6054,7 +6071,7 @@ function isRecursive(inst, stack, resolve2) {
|
|
|
6054
6071
|
const desc = Object.getOwnPropertyDescriptor(sh, key);
|
|
6055
6072
|
if (spread && !desc.enumerable)
|
|
6056
6073
|
continue;
|
|
6057
|
-
const child = desc.get ? ASSUMED : desc.value?._zod ? isRecursive(desc.value, stack,
|
|
6074
|
+
const child = desc.get ? ASSUMED : desc.value?._zod ? isRecursive(desc.value, stack, resolve3) : NONE;
|
|
6058
6075
|
if (child > answer)
|
|
6059
6076
|
answer = child;
|
|
6060
6077
|
}
|
|
@@ -6118,7 +6135,7 @@ function isRecursive(inst, stack, resolve2) {
|
|
|
6118
6135
|
break;
|
|
6119
6136
|
// `$ZodLazy` caches its inner on the def, so a resolved edge is followed exactly
|
|
6120
6137
|
case "lazy": {
|
|
6121
|
-
const inner = def._cachedInner ?? (
|
|
6138
|
+
const inner = def._cachedInner ?? (resolve3 ? inst._zod.innerType : void 0);
|
|
6122
6139
|
merge2(inner ? isRecursive(inner, stack, false) : ASSUMED);
|
|
6123
6140
|
break;
|
|
6124
6141
|
}
|
|
@@ -23399,7 +23416,29 @@ var StorePosturePlugin = external_exports.object({
|
|
|
23399
23416
|
*/
|
|
23400
23417
|
policyBundleVersion: external_exports.string().max(200).nullable(),
|
|
23401
23418
|
/** Epoch millis, on the CLIENT clock, of that fetch. */
|
|
23402
|
-
policyFetchedAt: external_exports.number().int().min(0).max(MAX_DATE_MS).nullable()
|
|
23419
|
+
policyFetchedAt: external_exports.number().int().min(0).max(MAX_DATE_MS).nullable(),
|
|
23420
|
+
/**
|
|
23421
|
+
* The newest version the host's own install record holds for this plugin —
|
|
23422
|
+
* what is on disk. After an update it leads `version` (the running copy) by
|
|
23423
|
+
* one launch. Null when no usable version can be read: no install record
|
|
23424
|
+
* (a plugin run from a checkout), no entry with a valid version, or every
|
|
23425
|
+
* such entry names an `installPath` that no longer exists; OPTIONAL, not
|
|
23426
|
+
* required, so a build that predates the member keeps getting its 200.
|
|
23427
|
+
* Bounded like `version`.
|
|
23428
|
+
*/
|
|
23429
|
+
installedVersion: external_exports.string().max(64).nullable().optional(),
|
|
23430
|
+
/**
|
|
23431
|
+
* The local-store schema version this running build migrates a store to:
|
|
23432
|
+
* the number of store migrations it carries, the count it stamps into
|
|
23433
|
+
* `PRAGMA user_version`. A snapshot whose `schemaVersion` is above it
|
|
23434
|
+
* usually describes a store a newer build migrated. It is a hint, not a
|
|
23435
|
+
* verdict: the stamp is write-only, so a store whose count ran past this
|
|
23436
|
+
* build's while this build knows every migration in its ledger reads above
|
|
23437
|
+
* it too, which is why describeStoreSkew decides skew on ledger tags and
|
|
23438
|
+
* never on the count. OPTIONAL for the same reason as `installedVersion`;
|
|
23439
|
+
* bounded like `schemaVersion`.
|
|
23440
|
+
*/
|
|
23441
|
+
buildSchemaVersion: external_exports.number().int().min(0).max(MAX_INT4).optional()
|
|
23403
23442
|
}).meta({ id: "StorePosturePlugin" });
|
|
23404
23443
|
var StorePostureSnapshot = external_exports.object({
|
|
23405
23444
|
deviceId: external_exports.guid(),
|
|
@@ -25042,10 +25081,15 @@ var ParsedPointer = external_exports.object({
|
|
|
25042
25081
|
});
|
|
25043
25082
|
var VaultEntry = external_exports.object({
|
|
25044
25083
|
pointerId: external_exports.string(),
|
|
25045
|
-
// The keyed HMAC of the raw
|
|
25046
|
-
// derived under.
|
|
25047
|
-
// independently of the vault encryption
|
|
25084
|
+
// The keyed HMAC of the EXACT raw bytes under `exception.key`, and the epoch it
|
|
25085
|
+
// was derived under. The vault's own dedupe key: a value and its invisibly
|
|
25086
|
+
// padded twin are two rows. It rotates independently of the vault encryption
|
|
25087
|
+
// key below. Never matched against an exception or grant.
|
|
25048
25088
|
valueFingerprint: external_exports.string().regex(/^[0-9a-f]{64}$/),
|
|
25089
|
+
// The same HMAC over the raw with invisible padding removed: the identity a
|
|
25090
|
+
// reveal-to-model grant and every exception match on. Shared by a value and
|
|
25091
|
+
// its padded twin.
|
|
25092
|
+
valueIdentityFingerprint: external_exports.string().regex(/^[0-9a-f]{64}$/),
|
|
25049
25093
|
fingerprintKeyVersion: external_exports.number().int().positive(),
|
|
25050
25094
|
// The vault-key epoch this row's ciphertext was sealed under.
|
|
25051
25095
|
keyVersion: external_exports.number().int().positive(),
|
|
@@ -25618,10 +25662,18 @@ var SeveritySummaryItem = external_exports.object({
|
|
|
25618
25662
|
count: external_exports.number().int().nonnegative(),
|
|
25619
25663
|
// Resolution-aware breakdown (optional, additive). Populated once findings
|
|
25620
25664
|
// carry lifecycle state: `caught` = handled in-flight (enforced); `openAtRest`
|
|
25621
|
-
// = still open with no in-flight enforcement (needs remediation)
|
|
25622
|
-
//
|
|
25665
|
+
// = still open with no in-flight enforcement (needs remediation); `dismissed`
|
|
25666
|
+
// = closed by a human judgement rather than a fix — visible, but not counted as
|
|
25667
|
+
// needing remediation. The three are disjoint. Absent on the legacy count-only
|
|
25668
|
+
// response until the resolution feature lands.
|
|
25623
25669
|
caught: external_exports.number().int().nonnegative().optional(),
|
|
25624
|
-
openAtRest: external_exports.number().int().nonnegative().optional()
|
|
25670
|
+
openAtRest: external_exports.number().int().nonnegative().optional(),
|
|
25671
|
+
dismissed: external_exports.number().int().nonnegative().optional(),
|
|
25672
|
+
// The two halves of `caught`, for a reader that wants them apart: `handled` =
|
|
25673
|
+
// in-flight findings an enforcement action already contained; `resolved` =
|
|
25674
|
+
// at-rest findings closed out by fixing them. `handled + resolved === caught`.
|
|
25675
|
+
handled: external_exports.number().int().nonnegative().optional(),
|
|
25676
|
+
resolved: external_exports.number().int().nonnegative().optional()
|
|
25625
25677
|
}).meta({ id: "SeveritySummaryItem" });
|
|
25626
25678
|
var SeveritySummaryResponse = external_exports.object({
|
|
25627
25679
|
// Sum of bySeverity[].count.
|
|
@@ -25629,6 +25681,9 @@ var SeveritySummaryResponse = external_exports.object({
|
|
|
25629
25681
|
// Findings still open at rest (sum of bySeverity[].openAtRest). Optional and
|
|
25630
25682
|
// additive — absent on the legacy response until the resolution feature lands.
|
|
25631
25683
|
needsRemediation: external_exports.number().int().nonnegative().optional(),
|
|
25684
|
+
// Findings a user dismissed (sum of bySeverity[].dismissed). Excluded from
|
|
25685
|
+
// needsRemediation, and kept visible here so an accepted risk is not erased.
|
|
25686
|
+
dismissed: external_exports.number().int().nonnegative().optional(),
|
|
25632
25687
|
// All four severity levels are always present (count may be 0).
|
|
25633
25688
|
bySeverity: external_exports.array(SeveritySummaryItem)
|
|
25634
25689
|
}).meta({ id: "SeveritySummaryResponse" });
|
|
@@ -26246,11 +26301,11 @@ function repairOrRefuseMode(file2) {
|
|
|
26246
26301
|
const link = lstatSync2(file2, { throwIfNoEntry: false });
|
|
26247
26302
|
if (link === void 0) return "absent";
|
|
26248
26303
|
if (link.isSymbolicLink()) return "untrusted";
|
|
26249
|
-
const
|
|
26250
|
-
if (
|
|
26304
|
+
const stat2 = statSync(file2, { throwIfNoEntry: false });
|
|
26305
|
+
if (stat2 === void 0) return "absent";
|
|
26251
26306
|
const uid = process.getuid?.();
|
|
26252
|
-
if (uid !== void 0 &&
|
|
26253
|
-
if (process.platform !== "win32" && (
|
|
26307
|
+
if (uid !== void 0 && stat2.uid !== uid) return "untrusted";
|
|
26308
|
+
if (process.platform !== "win32" && (stat2.mode & 511) !== DATA_FILE_MODE) {
|
|
26254
26309
|
try {
|
|
26255
26310
|
chmodSync2(file2, DATA_FILE_MODE);
|
|
26256
26311
|
} catch {
|
|
@@ -26262,9 +26317,9 @@ function repairOrRefuseMode(file2) {
|
|
|
26262
26317
|
function readControlPlaneCredentialFile(settingsDir2, connection) {
|
|
26263
26318
|
const file2 = controlPlaneCredentialPath(settingsDir2);
|
|
26264
26319
|
let raw;
|
|
26265
|
-
const
|
|
26266
|
-
if (
|
|
26267
|
-
if (
|
|
26320
|
+
const gate2 = repairOrRefuseMode(file2);
|
|
26321
|
+
if (gate2 === "absent") return { usable: false, reason: "absent" };
|
|
26322
|
+
if (gate2 === "untrusted") return { usable: false, reason: "untrusted-file" };
|
|
26268
26323
|
try {
|
|
26269
26324
|
raw = readFileSync(file2, "utf8");
|
|
26270
26325
|
} catch (err) {
|
|
@@ -32412,7 +32467,10 @@ var SqliteResolutionsRepository = class {
|
|
|
32412
32467
|
* Insert many dispositions as ONE transaction — all of them or none.
|
|
32413
32468
|
*
|
|
32414
32469
|
* A dashboard dismissal closes every open finding of a rule, which is one
|
|
32415
|
-
* write per key
|
|
32470
|
+
* write per key. It reaches this through
|
|
32471
|
+
* `LocalDatabase.dismissOpenFindingsForRule`, which calls it inside the
|
|
32472
|
+
* transaction that selected the keys, so there it runs as a SAVEPOINT of
|
|
32473
|
+
* that transaction. Run loose, a fault partway leaves half a rule closed with
|
|
32416
32474
|
* nothing recording that the other half was meant to be. The caller then has
|
|
32417
32475
|
* no way to tell a partial run from a complete one, because the card it
|
|
32418
32476
|
* refreshes into just shows a smaller number either way.
|
|
@@ -32632,6 +32690,7 @@ function toSighting(row) {
|
|
|
32632
32690
|
var SELECT_COLUMNS = `
|
|
32633
32691
|
pointer_id AS pointerId,
|
|
32634
32692
|
value_fingerprint AS valueFingerprint,
|
|
32693
|
+
value_identity_fingerprint AS valueIdentityFingerprint,
|
|
32635
32694
|
fingerprint_key_version AS fingerprintKeyVersion,
|
|
32636
32695
|
key_version AS keyVersion,
|
|
32637
32696
|
format_version AS formatVersion,
|
|
@@ -32656,13 +32715,13 @@ var SqliteSecretVaultRepository = class {
|
|
|
32656
32715
|
this.db = db;
|
|
32657
32716
|
this.insertStmt = db.prepare(
|
|
32658
32717
|
`INSERT INTO secret_vault (
|
|
32659
|
-
pointer_id, value_fingerprint,
|
|
32660
|
-
format_version, category, rule_id, masked_match, provider,
|
|
32718
|
+
pointer_id, value_fingerprint, value_identity_fingerprint,
|
|
32719
|
+
fingerprint_key_version, key_version, format_version, category, rule_id, masked_match, provider,
|
|
32661
32720
|
ciphertext, nonce, auth_tag,
|
|
32662
32721
|
user_authorized, occurrence_count, first_seen, last_seen
|
|
32663
32722
|
) VALUES (
|
|
32664
|
-
:pointerId, :valueFingerprint, :
|
|
32665
|
-
:formatVersion, :category, :ruleId, :maskedMatch, :provider,
|
|
32723
|
+
:pointerId, :valueFingerprint, :valueIdentityFingerprint,
|
|
32724
|
+
:fingerprintKeyVersion, :keyVersion, :formatVersion, :category, :ruleId, :maskedMatch, :provider,
|
|
32666
32725
|
:ciphertext, :nonce, :authTag,
|
|
32667
32726
|
:userAuthorized, 1, :now, :now
|
|
32668
32727
|
)`
|
|
@@ -32687,7 +32746,13 @@ var SqliteSecretVaultRepository = class {
|
|
|
32687
32746
|
);
|
|
32688
32747
|
this.refreshFingerprintStmt = db.prepare(
|
|
32689
32748
|
`UPDATE secret_vault
|
|
32690
|
-
SET value_fingerprint = :valueFingerprint,
|
|
32749
|
+
SET value_fingerprint = :valueFingerprint,
|
|
32750
|
+
value_identity_fingerprint = :valueIdentityFingerprint,
|
|
32751
|
+
fingerprint_key_version = :fingerprintKeyVersion
|
|
32752
|
+
WHERE pointer_id = :pointerId`
|
|
32753
|
+
);
|
|
32754
|
+
this.setIdentityStmt = db.prepare(
|
|
32755
|
+
`UPDATE secret_vault SET value_identity_fingerprint = :valueIdentityFingerprint
|
|
32691
32756
|
WHERE pointer_id = :pointerId`
|
|
32692
32757
|
);
|
|
32693
32758
|
this.deleteByPointerStmt = db.prepare(`DELETE FROM secret_vault WHERE pointer_id = :pointerId`);
|
|
@@ -32704,6 +32769,7 @@ var SqliteSecretVaultRepository = class {
|
|
|
32704
32769
|
listStmt;
|
|
32705
32770
|
replaceCiphertextStmt;
|
|
32706
32771
|
refreshFingerprintStmt;
|
|
32772
|
+
setIdentityStmt;
|
|
32707
32773
|
deleteByPointerStmt;
|
|
32708
32774
|
derefStmt;
|
|
32709
32775
|
/**
|
|
@@ -32734,6 +32800,7 @@ var SqliteSecretVaultRepository = class {
|
|
|
32734
32800
|
bindParams({
|
|
32735
32801
|
pointerId: input2.pointerId,
|
|
32736
32802
|
valueFingerprint: input2.valueFingerprint,
|
|
32803
|
+
valueIdentityFingerprint: input2.valueIdentityFingerprint,
|
|
32737
32804
|
fingerprintKeyVersion: input2.fingerprintKeyVersion,
|
|
32738
32805
|
keyVersion: input2.keyVersion,
|
|
32739
32806
|
formatVersion: input2.formatVersion ?? POINTER_FORMAT_VERSION,
|
|
@@ -32795,7 +32862,15 @@ var SqliteSecretVaultRepository = class {
|
|
|
32795
32862
|
replaceCiphertext(pointerId, next) {
|
|
32796
32863
|
this.replaceCiphertextStmt.run({ pointerId, ...next });
|
|
32797
32864
|
}
|
|
32798
|
-
/**
|
|
32865
|
+
/**
|
|
32866
|
+
* Correct an entry's identity fingerprint in place, leaving its exact
|
|
32867
|
+
* fingerprint and key epoch alone. For a row whose identity column still holds
|
|
32868
|
+
* the exact value copied in by the migration that added it.
|
|
32869
|
+
*/
|
|
32870
|
+
setIdentityFingerprint(pointerId, valueIdentityFingerprint) {
|
|
32871
|
+
this.setIdentityStmt.run({ pointerId, valueIdentityFingerprint });
|
|
32872
|
+
}
|
|
32873
|
+
/** Re-derive an entry's fingerprints under a new fingerprint-key epoch. */
|
|
32799
32874
|
refreshFingerprint(pointerId, next) {
|
|
32800
32875
|
this.refreshFingerprintStmt.run({ pointerId, ...next });
|
|
32801
32876
|
}
|
|
@@ -32926,7 +33001,7 @@ var SqliteSecretVaultRepository = class {
|
|
|
32926
33001
|
`SELECT ${INVENTORY_COLUMNS},
|
|
32927
33002
|
(SELECT e.id FROM exceptions e
|
|
32928
33003
|
WHERE e.rule_id = v.rule_id
|
|
32929
|
-
AND e.value_fingerprint = v.
|
|
33004
|
+
AND e.value_fingerprint = v.value_identity_fingerprint
|
|
32930
33005
|
AND e.key_version = v.fingerprint_key_version
|
|
32931
33006
|
AND ${ACTIVE_REVEAL_GRANT_PREDICATE}
|
|
32932
33007
|
LIMIT 1) AS grant_id
|
|
@@ -32969,7 +33044,7 @@ var SqliteSecretVaultRepository = class {
|
|
|
32969
33044
|
`SELECT ${INVENTORY_COLUMNS},
|
|
32970
33045
|
(SELECT e.id FROM exceptions e
|
|
32971
33046
|
WHERE e.rule_id = v.rule_id
|
|
32972
|
-
AND e.value_fingerprint = v.
|
|
33047
|
+
AND e.value_fingerprint = v.value_identity_fingerprint
|
|
32973
33048
|
AND e.key_version = v.fingerprint_key_version
|
|
32974
33049
|
AND ${ACTIVE_REVEAL_GRANT_PREDICATE}
|
|
32975
33050
|
LIMIT 1) AS grant_id
|
|
@@ -33073,6 +33148,18 @@ var OPEN_AT_REST_FINDINGS_SQL = `FROM inspection_findings f
|
|
|
33073
33148
|
OR latest.status IS NULL
|
|
33074
33149
|
OR latest.status NOT IN ('resolved', 'dismissed')
|
|
33075
33150
|
)`;
|
|
33151
|
+
function selectOpenFindingKeysForRule(db, ruleId) {
|
|
33152
|
+
const rows = allRows(
|
|
33153
|
+
db.prepare(
|
|
33154
|
+
`SELECT DISTINCT f.finding_key AS finding_key
|
|
33155
|
+
${OPEN_AT_REST_FINDINGS_SQL}
|
|
33156
|
+
AND d.rule_id = :ruleId
|
|
33157
|
+
AND f.finding_key IS NOT NULL`
|
|
33158
|
+
),
|
|
33159
|
+
{ ruleId }
|
|
33160
|
+
);
|
|
33161
|
+
return rows.map((r) => r.finding_key);
|
|
33162
|
+
}
|
|
33076
33163
|
var SEVERITIES = ["critical", "high", "medium", "low"];
|
|
33077
33164
|
var ACTION_TO_KIND = {
|
|
33078
33165
|
block: "blocked",
|
|
@@ -33129,16 +33216,16 @@ var SqliteSecurityRepository = class {
|
|
|
33129
33216
|
// findings are caught only once their latest disposition is resolved,
|
|
33130
33217
|
// otherwise they are open-at-rest.
|
|
33131
33218
|
//
|
|
33132
|
-
//
|
|
33133
|
-
//
|
|
33134
|
-
//
|
|
33135
|
-
//
|
|
33136
|
-
// be bucketed as caught
|
|
33219
|
+
// Only latest status 'resolved' counts as caught above. 'dismissed' is its
|
|
33220
|
+
// own bucket: a judgement rather than a fix, so it is neither caught nor
|
|
33221
|
+
// needing remediation, and stays countable. A further manual disposition
|
|
33222
|
+
// (acknowledged, false-positive) must be placed deliberately — 'acknowledged'
|
|
33223
|
+
// is accepted risk, not a fix, and must NOT be bucketed as caught.
|
|
33137
33224
|
//
|
|
33138
33225
|
// Legacy at-rest findings from pre-branch scans carry finding_key = NULL —
|
|
33139
33226
|
// the resolution lifecycle is keyed by finding_key, so it can never attach a
|
|
33140
33227
|
// disposition to (or clear) one of these on re-scan. They are excluded from
|
|
33141
|
-
//
|
|
33228
|
+
// all three buckets (untracked, not "needs remediation forever"),
|
|
33142
33229
|
// but still counted in total/count below — this keeps this predicate
|
|
33143
33230
|
// consistent with SqliteResolutionsRepository.openAtRestKeysForPath, which
|
|
33144
33231
|
// already filters `finding_key IS NOT NULL`.
|
|
@@ -33161,12 +33248,25 @@ var SqliteSecurityRepository = class {
|
|
|
33161
33248
|
WHEN latest.status = 'resolved' THEN 1
|
|
33162
33249
|
ELSE 0
|
|
33163
33250
|
END) AS caught,
|
|
33251
|
+
SUM(CASE WHEN e.event_type != 'code_change' THEN 1 ELSE 0 END) AS handled,
|
|
33252
|
+
SUM(CASE
|
|
33253
|
+
WHEN e.event_type = 'code_change'
|
|
33254
|
+
AND f.finding_key IS NOT NULL
|
|
33255
|
+
AND latest.status = 'resolved' THEN 1
|
|
33256
|
+
ELSE 0
|
|
33257
|
+
END) AS resolved,
|
|
33164
33258
|
SUM(CASE
|
|
33165
33259
|
WHEN e.event_type = 'code_change'
|
|
33166
33260
|
AND f.finding_key IS NOT NULL
|
|
33167
|
-
AND (latest.status IS NULL
|
|
33261
|
+
AND (latest.status IS NULL
|
|
33262
|
+
OR latest.status NOT IN ('resolved', 'dismissed')) THEN 1
|
|
33168
33263
|
ELSE 0
|
|
33169
|
-
END) AS open_at_rest
|
|
33264
|
+
END) AS open_at_rest,
|
|
33265
|
+
SUM(CASE
|
|
33266
|
+
WHEN e.event_type = 'code_change'
|
|
33267
|
+
AND latest.status = 'dismissed' THEN 1
|
|
33268
|
+
ELSE 0
|
|
33269
|
+
END) AS dismissed
|
|
33170
33270
|
FROM inspection_findings f
|
|
33171
33271
|
JOIN audit_events e INDEXED BY idx_audit_capture_rollup ON e.id = f.audit_event_id
|
|
33172
33272
|
JOIN inspection_definitions d ON d.id = f.inspection_definition_id
|
|
@@ -33181,11 +33281,15 @@ var SqliteSecurityRepository = class {
|
|
|
33181
33281
|
severity,
|
|
33182
33282
|
count: byRow.get(severity)?.count ?? 0,
|
|
33183
33283
|
caught: byRow.get(severity)?.caught ?? 0,
|
|
33184
|
-
|
|
33284
|
+
handled: byRow.get(severity)?.handled ?? 0,
|
|
33285
|
+
resolved: byRow.get(severity)?.resolved ?? 0,
|
|
33286
|
+
openAtRest: byRow.get(severity)?.open_at_rest ?? 0,
|
|
33287
|
+
dismissed: byRow.get(severity)?.dismissed ?? 0
|
|
33185
33288
|
}));
|
|
33186
33289
|
const total = bySeverity.reduce((sum, s) => sum + s.count, 0);
|
|
33187
33290
|
const needsRemediation = bySeverity.reduce((sum, s) => sum + s.openAtRest, 0);
|
|
33188
|
-
|
|
33291
|
+
const dismissed = bySeverity.reduce((sum, s) => sum + s.dismissed, 0);
|
|
33292
|
+
return Promise.resolve({ total, needsRemediation, dismissed, bySeverity });
|
|
33189
33293
|
}
|
|
33190
33294
|
// Range is echoed but does not change the result today — coverage is a constant
|
|
33191
33295
|
// business fact (see SCAN_COVERAGE), not a measured per-window metric. Order
|
|
@@ -33502,10 +33606,10 @@ var SqliteSecurityRepository = class {
|
|
|
33502
33606
|
* machine, and the second reported "no recommendations" over live exposure.
|
|
33503
33607
|
*
|
|
33504
33608
|
* `open` mirrors `deriveFindingStatus` — at-rest, minus resolved and dismissed —
|
|
33505
|
-
* so a row's count is exactly what `?status=open&type=<rule>` returns.
|
|
33506
|
-
*
|
|
33507
|
-
*
|
|
33508
|
-
*
|
|
33609
|
+
* so a row's count is exactly what `?status=open&type=<rule>` returns. It
|
|
33610
|
+
* differs from `severitySummary`'s `openAtRest` only in including untracked
|
|
33611
|
+
* legacy rows, which that bucket leaves out; dismissed is excluded from both.
|
|
33612
|
+
* Only this one has to match a link.
|
|
33509
33613
|
*
|
|
33510
33614
|
* Aggregated in SQL: the result is O(distinct rule × category × severity), so a
|
|
33511
33615
|
* whole-store scope costs a grouped scan rather than a row per finding.
|
|
@@ -33533,6 +33637,8 @@ var SqliteSecurityRepository = class {
|
|
|
33533
33637
|
/**
|
|
33534
33638
|
* The distinct `finding_key`s behind ONE rule's {@link recommendationInputs}
|
|
33535
33639
|
* tally — what a dashboard dismissal of that row writes a disposition for.
|
|
33640
|
+
* The dismissal itself does not call this: it reads the same set through
|
|
33641
|
+
* {@link selectOpenFindingKeysForRule}, inside its own write transaction.
|
|
33536
33642
|
*
|
|
33537
33643
|
* It shares {@link OPEN_AT_REST_FINDINGS_SQL} with the count rather than
|
|
33538
33644
|
* restating the predicate, because a dismissal has to act on exactly the set
|
|
@@ -33549,16 +33655,7 @@ var SqliteSecurityRepository = class {
|
|
|
33549
33655
|
* this set SMALLER than the tally, never larger.
|
|
33550
33656
|
*/
|
|
33551
33657
|
openFindingKeysForRule(ruleId) {
|
|
33552
|
-
|
|
33553
|
-
this.db.prepare(
|
|
33554
|
-
`SELECT DISTINCT f.finding_key AS finding_key
|
|
33555
|
-
${OPEN_AT_REST_FINDINGS_SQL}
|
|
33556
|
-
AND d.rule_id = :ruleId
|
|
33557
|
-
AND f.finding_key IS NOT NULL`
|
|
33558
|
-
),
|
|
33559
|
-
{ ruleId }
|
|
33560
|
-
);
|
|
33561
|
-
return Promise.resolve(rows.map((r) => r.finding_key));
|
|
33658
|
+
return Promise.resolve(selectOpenFindingKeysForRule(this.db, ruleId));
|
|
33562
33659
|
}
|
|
33563
33660
|
// Findings whose parent event occurred in [fromMs, toMs), with the parent's
|
|
33564
33661
|
// epoch-millis timestamp. started_at is an INTEGER column, so the bounds stay
|
|
@@ -34604,6 +34701,31 @@ function openLocalDatabase(dir, options = {}) {
|
|
|
34604
34701
|
);
|
|
34605
34702
|
});
|
|
34606
34703
|
}
|
|
34704
|
+
function dismissOpenFindingsForRule(ruleId, disposition) {
|
|
34705
|
+
let dismissed = 0;
|
|
34706
|
+
withTransaction(
|
|
34707
|
+
db,
|
|
34708
|
+
() => {
|
|
34709
|
+
const keys = selectOpenFindingKeysForRule(db, ruleId);
|
|
34710
|
+
resolutions.insertResolutions(
|
|
34711
|
+
keys.map((findingKey) => ({
|
|
34712
|
+
findingKey,
|
|
34713
|
+
status: "dismissed",
|
|
34714
|
+
method: disposition.method,
|
|
34715
|
+
resolvedAt: disposition.resolvedAt,
|
|
34716
|
+
evidence: disposition.evidence
|
|
34717
|
+
}))
|
|
34718
|
+
);
|
|
34719
|
+
dismissed = keys.length;
|
|
34720
|
+
},
|
|
34721
|
+
// IMMEDIATE takes the write lock at BEGIN, before the select, which is
|
|
34722
|
+
// what keeps a concurrent resolve out of the gap. It also makes waiting
|
|
34723
|
+
// on a busy writer an ordinary busy_timeout wait rather than a
|
|
34724
|
+
// read-to-write upgrade SQLite refuses to retry.
|
|
34725
|
+
"IMMEDIATE"
|
|
34726
|
+
);
|
|
34727
|
+
return dismissed;
|
|
34728
|
+
}
|
|
34607
34729
|
function recordCapture(event, detected) {
|
|
34608
34730
|
failOpenTransaction(db, () => {
|
|
34609
34731
|
const sessionId = event.metadata?.sessionId;
|
|
@@ -34787,6 +34909,7 @@ function openLocalDatabase(dir, options = {}) {
|
|
|
34787
34909
|
inspectionDefinitions,
|
|
34788
34910
|
inspectionFindings,
|
|
34789
34911
|
recordCapture,
|
|
34912
|
+
dismissOpenFindingsForRule,
|
|
34790
34913
|
markCaptureDelivered,
|
|
34791
34914
|
markCaptureOwed,
|
|
34792
34915
|
markAuditEventsDelivered,
|
|
@@ -35003,6 +35126,9 @@ function loadOrCreateFingerprintKey(dataDir2) {
|
|
|
35003
35126
|
});
|
|
35004
35127
|
}
|
|
35005
35128
|
function fingerprintValue(key, raw) {
|
|
35129
|
+
return exactFingerprintValue(key, stripInvisiblePadding(raw));
|
|
35130
|
+
}
|
|
35131
|
+
function exactFingerprintValue(key, raw) {
|
|
35006
35132
|
return createHmac("sha256", key.material).update(raw, "utf8").digest("hex");
|
|
35007
35133
|
}
|
|
35008
35134
|
|
|
@@ -35220,7 +35346,7 @@ async function send(options) {
|
|
|
35220
35346
|
}
|
|
35221
35347
|
}
|
|
35222
35348
|
};
|
|
35223
|
-
return new Promise((
|
|
35349
|
+
return new Promise((resolve3, reject) => {
|
|
35224
35350
|
let settled = false;
|
|
35225
35351
|
const fail = (reason, status) => {
|
|
35226
35352
|
if (settled) return;
|
|
@@ -35246,7 +35372,7 @@ async function send(options) {
|
|
|
35246
35372
|
res.on("end", () => {
|
|
35247
35373
|
if (settled) return;
|
|
35248
35374
|
settled = true;
|
|
35249
|
-
|
|
35375
|
+
resolve3({
|
|
35250
35376
|
status: res.statusCode ?? 0,
|
|
35251
35377
|
headers: res.headers,
|
|
35252
35378
|
body: Buffer.concat(chunks).toString("utf8")
|
|
@@ -36225,6 +36351,82 @@ function escapeRegExp2(value) {
|
|
|
36225
36351
|
return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
36226
36352
|
}
|
|
36227
36353
|
|
|
36354
|
+
// ../../packages/detections/src/format-chars.ts
|
|
36355
|
+
var HAS_FORMAT_CHAR = new RegExp("\\p{Cf}", "u");
|
|
36356
|
+
var FORMAT_CHAR_GLOBAL = new RegExp("\\p{Cf}", "gu");
|
|
36357
|
+
function normalizeFormatChars(text) {
|
|
36358
|
+
if (!HAS_FORMAT_CHAR.test(text)) return void 0;
|
|
36359
|
+
const normalizedParts = [];
|
|
36360
|
+
const segments = [];
|
|
36361
|
+
let cursor = 0;
|
|
36362
|
+
let normLength = 0;
|
|
36363
|
+
for (const match of text.matchAll(FORMAT_CHAR_GLOBAL)) {
|
|
36364
|
+
const matchStart = match.index;
|
|
36365
|
+
if (matchStart > cursor) {
|
|
36366
|
+
const length = matchStart - cursor;
|
|
36367
|
+
normalizedParts.push(text.slice(cursor, matchStart));
|
|
36368
|
+
segments.push({ normStart: normLength, origStart: cursor, length });
|
|
36369
|
+
normLength += length;
|
|
36370
|
+
}
|
|
36371
|
+
cursor = matchStart + match[0].length;
|
|
36372
|
+
}
|
|
36373
|
+
if (cursor < text.length) {
|
|
36374
|
+
const length = text.length - cursor;
|
|
36375
|
+
normalizedParts.push(text.slice(cursor));
|
|
36376
|
+
segments.push({ normStart: normLength, origStart: cursor, length });
|
|
36377
|
+
}
|
|
36378
|
+
return { normalized: normalizedParts.join(""), segments };
|
|
36379
|
+
}
|
|
36380
|
+
function segmentAt(segments, normPos) {
|
|
36381
|
+
let lo = 0;
|
|
36382
|
+
let hi = segments.length - 1;
|
|
36383
|
+
while (lo < hi) {
|
|
36384
|
+
const mid = lo + hi >> 1;
|
|
36385
|
+
const segment = segments[mid];
|
|
36386
|
+
if (segment !== void 0 && normPos >= segment.normStart + segment.length) {
|
|
36387
|
+
lo = mid + 1;
|
|
36388
|
+
} else {
|
|
36389
|
+
hi = mid;
|
|
36390
|
+
}
|
|
36391
|
+
}
|
|
36392
|
+
const found = segments[lo];
|
|
36393
|
+
if (found === void 0) {
|
|
36394
|
+
throw new Error(`normPos ${String(normPos)} has no covering segment`);
|
|
36395
|
+
}
|
|
36396
|
+
return found;
|
|
36397
|
+
}
|
|
36398
|
+
function mapSpanToOriginal(span, normalization) {
|
|
36399
|
+
const { segments } = normalization;
|
|
36400
|
+
const startSegment = segmentAt(segments, span.start);
|
|
36401
|
+
const start = startSegment.origStart + (span.start - startSegment.normStart);
|
|
36402
|
+
const endSegment = segmentAt(segments, span.end - 1);
|
|
36403
|
+
const end = endSegment.origStart + (span.end - 1 - endSegment.normStart) + 1;
|
|
36404
|
+
return { start, end };
|
|
36405
|
+
}
|
|
36406
|
+
function normalizedOffset(origPos, segments) {
|
|
36407
|
+
let lo = 0;
|
|
36408
|
+
let hi = segments.length;
|
|
36409
|
+
while (lo < hi) {
|
|
36410
|
+
const mid = lo + hi >> 1;
|
|
36411
|
+
const segment = segments[mid];
|
|
36412
|
+
if (segment !== void 0 && segment.origStart + segment.length <= origPos) {
|
|
36413
|
+
lo = mid + 1;
|
|
36414
|
+
} else {
|
|
36415
|
+
hi = mid;
|
|
36416
|
+
}
|
|
36417
|
+
}
|
|
36418
|
+
const found = segments[Math.min(lo, segments.length - 1)];
|
|
36419
|
+
if (found === void 0) return 0;
|
|
36420
|
+
return found.normStart + Math.min(Math.max(0, origPos - found.origStart), found.length);
|
|
36421
|
+
}
|
|
36422
|
+
function mapSpanToNormalized(span, normalization) {
|
|
36423
|
+
const { segments } = normalization;
|
|
36424
|
+
return {
|
|
36425
|
+
start: normalizedOffset(span.start, segments),
|
|
36426
|
+
end: normalizedOffset(span.end, segments)
|
|
36427
|
+
};
|
|
36428
|
+
}
|
|
36429
|
+
|
|
36228
36430
|
// ../../packages/detections/src/regex-cache.ts
|
|
36229
36431
|
var singles = /* @__PURE__ */ new WeakMap();
|
|
36230
36432
|
var keywordLists = /* @__PURE__ */ new WeakMap();
|
|
@@ -36386,29 +36588,35 @@ function registerPack(pack) {
|
|
|
36386
36588
|
function getLoadedRules() {
|
|
36387
36589
|
return [...packs.values()].flatMap((p) => p.rules);
|
|
36388
36590
|
}
|
|
36389
|
-
function
|
|
36591
|
+
function spansOverlap(a, b) {
|
|
36592
|
+
return a.start < b.end && a.end > b.start;
|
|
36593
|
+
}
|
|
36594
|
+
function isCorroborated(candidate, candidates, text, normalization) {
|
|
36390
36595
|
const req = candidate.rule.requiresNearby;
|
|
36391
36596
|
if (!req) return true;
|
|
36392
36597
|
const halfWindow = req.windowChars;
|
|
36393
|
-
const
|
|
36394
|
-
const winStart = start - halfWindow;
|
|
36395
|
-
const winEnd = end + halfWindow;
|
|
36598
|
+
const ns = candidate.normSpan;
|
|
36599
|
+
const winStart = ns.start - halfWindow;
|
|
36600
|
+
const winEnd = ns.end + halfWindow;
|
|
36396
36601
|
const categories = req.categories;
|
|
36397
36602
|
const ruleIds = req.ruleIds;
|
|
36398
36603
|
if (categories?.length || ruleIds?.length) {
|
|
36399
36604
|
for (const other of candidates) {
|
|
36400
36605
|
if (other === candidate) continue;
|
|
36401
|
-
|
|
36402
|
-
|
|
36403
|
-
if (
|
|
36404
|
-
|
|
36606
|
+
if (other.normSpan.end < winStart || other.normSpan.start > winEnd) continue;
|
|
36607
|
+
const relevant = other.match.ruleId !== candidate.match.ruleId && categories?.includes(other.match.category) === true || ruleIds?.includes(other.match.ruleId) === true;
|
|
36608
|
+
if (!relevant) continue;
|
|
36609
|
+
if (other.match.ruleId === candidate.match.ruleId && spansOverlap(other.match.span, candidate.match.span)) {
|
|
36610
|
+
continue;
|
|
36405
36611
|
}
|
|
36406
|
-
|
|
36612
|
+
return true;
|
|
36407
36613
|
}
|
|
36408
36614
|
}
|
|
36409
36615
|
const labels = req.labels;
|
|
36410
36616
|
if (labels && labels.length > 0) {
|
|
36411
|
-
const
|
|
36617
|
+
const { start, end } = candidate.match.span;
|
|
36618
|
+
const haystack = text.slice(Math.max(0, start - halfWindow), end + halfWindow);
|
|
36619
|
+
const normalizedHaystack = normalization === void 0 ? void 0 : normalization.normalized.slice(Math.max(0, winStart), winEnd);
|
|
36412
36620
|
for (const re of memoizedRegExpList(
|
|
36413
36621
|
"label",
|
|
36414
36622
|
req,
|
|
@@ -36417,29 +36625,20 @@ function isCorroborated(candidate, candidates, text) {
|
|
|
36417
36625
|
return trimmed.length === 0 ? void 0 : new RegExp(`(?<![A-Za-z0-9])${escapeRegExp2(trimmed)}(?![A-Za-z0-9])`, "i");
|
|
36418
36626
|
})
|
|
36419
36627
|
)) {
|
|
36420
|
-
if (re
|
|
36628
|
+
if (!re) continue;
|
|
36629
|
+
if (re.test(haystack)) return true;
|
|
36630
|
+
if (normalizedHaystack !== void 0 && re.test(normalizedHaystack)) return true;
|
|
36421
36631
|
}
|
|
36422
36632
|
}
|
|
36423
36633
|
return false;
|
|
36424
36634
|
}
|
|
36425
|
-
function
|
|
36426
|
-
const base = filePath.slice(Math.max(filePath.lastIndexOf("/"), filePath.lastIndexOf("\\")) + 1);
|
|
36427
|
-
const dot = base.lastIndexOf(".");
|
|
36428
|
-
return dot > 0 ? base.slice(dot).toLowerCase() : void 0;
|
|
36429
|
-
}
|
|
36430
|
-
function ruleApplies(rule, extension) {
|
|
36431
|
-
if (!rule.appliesTo || extension === void 0) return true;
|
|
36432
|
-
return rule.appliesTo.extensions.some((e) => e.toLowerCase() === extension);
|
|
36433
|
-
}
|
|
36434
|
-
function scan(text, rules, context) {
|
|
36435
|
-
const ruleset = rules ?? getLoadedRules();
|
|
36436
|
-
const extension = context?.filePath ? extensionOf(context.filePath) : void 0;
|
|
36635
|
+
function buildCandidates(matchText, ruleset, extension) {
|
|
36437
36636
|
const candidates = [];
|
|
36438
36637
|
for (const rule of ruleset) {
|
|
36439
36638
|
if (!ruleApplies(rule, extension)) continue;
|
|
36440
|
-
const spans = MATCHERS[rule.matcher.type](
|
|
36639
|
+
const spans = MATCHERS[rule.matcher.type](matchText, rule);
|
|
36441
36640
|
for (const span of spans) {
|
|
36442
|
-
const rawMatch =
|
|
36641
|
+
const rawMatch = matchText.slice(span.start, span.end);
|
|
36443
36642
|
if (!passesPostValidators(rule, rawMatch)) continue;
|
|
36444
36643
|
candidates.push({
|
|
36445
36644
|
rule,
|
|
@@ -36450,10 +36649,31 @@ function scan(text, rules, context) {
|
|
|
36450
36649
|
span,
|
|
36451
36650
|
rawMatch,
|
|
36452
36651
|
confidence: 0.9
|
|
36453
|
-
}
|
|
36652
|
+
},
|
|
36653
|
+
// In `matchText`'s own coordinates, which is the normalized text for
|
|
36654
|
+
// a normalized-pass candidate and so already right; an original-pass
|
|
36655
|
+
// candidate on the slow path is re-derived by withNormalizedSpan.
|
|
36656
|
+
normSpan: span
|
|
36454
36657
|
});
|
|
36455
36658
|
}
|
|
36456
36659
|
}
|
|
36660
|
+
return candidates;
|
|
36661
|
+
}
|
|
36662
|
+
function mapCandidateToOriginal(candidate, normalization, text) {
|
|
36663
|
+
const span = mapSpanToOriginal(candidate.match.span, normalization);
|
|
36664
|
+
return {
|
|
36665
|
+
rule: candidate.rule,
|
|
36666
|
+
match: { ...candidate.match, span, rawMatch: text.slice(span.start, span.end) },
|
|
36667
|
+
// Deliberately NOT remapped: `normSpan` is the span the primitive match
|
|
36668
|
+
// was found at in the normalized text, which is exactly the coordinate
|
|
36669
|
+
// space windows are measured in. See the `Candidate` comment.
|
|
36670
|
+
normSpan: candidate.normSpan
|
|
36671
|
+
};
|
|
36672
|
+
}
|
|
36673
|
+
function withNormalizedSpan(candidate, normalization) {
|
|
36674
|
+
return { ...candidate, normSpan: mapSpanToNormalized(candidate.match.span, normalization) };
|
|
36675
|
+
}
|
|
36676
|
+
function gate(candidates, text, normalization) {
|
|
36457
36677
|
const findings = [];
|
|
36458
36678
|
for (const candidate of candidates) {
|
|
36459
36679
|
const req = candidate.rule.requiresNearby;
|
|
@@ -36461,7 +36681,7 @@ function scan(text, rules, context) {
|
|
|
36461
36681
|
findings.push(candidate.match);
|
|
36462
36682
|
continue;
|
|
36463
36683
|
}
|
|
36464
|
-
if (!isCorroborated(candidate, candidates, text)) continue;
|
|
36684
|
+
if (!isCorroborated(candidate, candidates, text, normalization)) continue;
|
|
36465
36685
|
const boost = req.confidenceBoost;
|
|
36466
36686
|
findings.push(
|
|
36467
36687
|
boost ? { ...candidate.match, confidence: Math.min(0.99, candidate.match.confidence + boost) } : candidate.match
|
|
@@ -36469,6 +36689,81 @@ function scan(text, rules, context) {
|
|
|
36469
36689
|
}
|
|
36470
36690
|
return findings;
|
|
36471
36691
|
}
|
|
36692
|
+
function closeRegion(open3, text) {
|
|
36693
|
+
const span = { start: open3.start, end: open3.end };
|
|
36694
|
+
return {
|
|
36695
|
+
ruleId: open3.ruleId,
|
|
36696
|
+
category: open3.category,
|
|
36697
|
+
severity: open3.severity,
|
|
36698
|
+
span,
|
|
36699
|
+
rawMatch: text.slice(span.start, span.end),
|
|
36700
|
+
confidence: open3.confidence
|
|
36701
|
+
};
|
|
36702
|
+
}
|
|
36703
|
+
function mergeOverlappingSameRule(findings, text) {
|
|
36704
|
+
if (findings.length === 0) return findings;
|
|
36705
|
+
const groups = /* @__PURE__ */ new Map();
|
|
36706
|
+
const ruleOrder = [];
|
|
36707
|
+
for (const finding of findings) {
|
|
36708
|
+
const group = groups.get(finding.ruleId);
|
|
36709
|
+
if (group) {
|
|
36710
|
+
group.push(finding);
|
|
36711
|
+
} else {
|
|
36712
|
+
groups.set(finding.ruleId, [finding]);
|
|
36713
|
+
ruleOrder.push(finding.ruleId);
|
|
36714
|
+
}
|
|
36715
|
+
}
|
|
36716
|
+
const merged = [];
|
|
36717
|
+
for (const ruleId of ruleOrder) {
|
|
36718
|
+
const group = groups.get(ruleId) ?? [];
|
|
36719
|
+
const sorted = [...group].sort(
|
|
36720
|
+
(a, b) => a.span.start - b.span.start || a.span.end - b.span.end
|
|
36721
|
+
);
|
|
36722
|
+
let open3;
|
|
36723
|
+
for (const finding of sorted) {
|
|
36724
|
+
if (open3 && finding.span.start < open3.end) {
|
|
36725
|
+
open3.end = Math.max(open3.end, finding.span.end);
|
|
36726
|
+
open3.confidence = Math.max(open3.confidence, finding.confidence);
|
|
36727
|
+
continue;
|
|
36728
|
+
}
|
|
36729
|
+
if (open3) merged.push(closeRegion(open3, text));
|
|
36730
|
+
open3 = {
|
|
36731
|
+
start: finding.span.start,
|
|
36732
|
+
end: finding.span.end,
|
|
36733
|
+
confidence: finding.confidence,
|
|
36734
|
+
ruleId: finding.ruleId,
|
|
36735
|
+
category: finding.category,
|
|
36736
|
+
severity: finding.severity
|
|
36737
|
+
};
|
|
36738
|
+
}
|
|
36739
|
+
if (open3) merged.push(closeRegion(open3, text));
|
|
36740
|
+
}
|
|
36741
|
+
return merged;
|
|
36742
|
+
}
|
|
36743
|
+
function extensionOf(filePath) {
|
|
36744
|
+
const base = filePath.slice(Math.max(filePath.lastIndexOf("/"), filePath.lastIndexOf("\\")) + 1);
|
|
36745
|
+
const dot = base.lastIndexOf(".");
|
|
36746
|
+
return dot > 0 ? base.slice(dot).toLowerCase() : void 0;
|
|
36747
|
+
}
|
|
36748
|
+
function ruleApplies(rule, extension) {
|
|
36749
|
+
if (!rule.appliesTo || extension === void 0) return true;
|
|
36750
|
+
return rule.appliesTo.extensions.some((e) => e.toLowerCase() === extension);
|
|
36751
|
+
}
|
|
36752
|
+
function scan(text, rules, context) {
|
|
36753
|
+
const ruleset = rules ?? getLoadedRules();
|
|
36754
|
+
const extension = context?.filePath ? extensionOf(context.filePath) : void 0;
|
|
36755
|
+
const normalization = normalizeFormatChars(text);
|
|
36756
|
+
const originalCandidates = buildCandidates(text, ruleset, extension);
|
|
36757
|
+
if (!normalization) return gate(originalCandidates, text, void 0);
|
|
36758
|
+
const pooledOriginal = originalCandidates.map(
|
|
36759
|
+
(candidate) => withNormalizedSpan(candidate, normalization)
|
|
36760
|
+
);
|
|
36761
|
+
const normalizedCandidates = buildCandidates(normalization.normalized, ruleset, extension).map(
|
|
36762
|
+
(candidate) => mapCandidateToOriginal(candidate, normalization, text)
|
|
36763
|
+
);
|
|
36764
|
+
const findings = gate([...pooledOriginal, ...normalizedCandidates], text, normalization);
|
|
36765
|
+
return mergeOverlappingSameRule(findings, text);
|
|
36766
|
+
}
|
|
36472
36767
|
var SEVERITY_RANK2 = {
|
|
36473
36768
|
critical: 3,
|
|
36474
36769
|
high: 2,
|
|
@@ -39103,8 +39398,8 @@ function createIsolatedScanner(data, opts = {}) {
|
|
|
39103
39398
|
}
|
|
39104
39399
|
function enqueue(spec) {
|
|
39105
39400
|
const next = chain.then(
|
|
39106
|
-
() => new Promise((
|
|
39107
|
-
spec(
|
|
39401
|
+
() => new Promise((resolve3) => {
|
|
39402
|
+
spec(resolve3);
|
|
39108
39403
|
})
|
|
39109
39404
|
);
|
|
39110
39405
|
chain = next.then(
|
|
@@ -39115,7 +39410,7 @@ function createIsolatedScanner(data, opts = {}) {
|
|
|
39115
39410
|
}
|
|
39116
39411
|
return {
|
|
39117
39412
|
scan(text, context, scanOpts) {
|
|
39118
|
-
return enqueue((
|
|
39413
|
+
return enqueue((resolve3) => {
|
|
39119
39414
|
runOne(
|
|
39120
39415
|
{
|
|
39121
39416
|
budgetMs,
|
|
@@ -39128,23 +39423,23 @@ function createIsolatedScanner(data, opts = {}) {
|
|
|
39128
39423
|
}),
|
|
39129
39424
|
reply: (message) => {
|
|
39130
39425
|
if (message.kind !== "result") return false;
|
|
39131
|
-
|
|
39426
|
+
resolve3({ status: "ok", findings: message.findings });
|
|
39132
39427
|
return true;
|
|
39133
39428
|
}
|
|
39134
39429
|
},
|
|
39135
|
-
|
|
39430
|
+
resolve3
|
|
39136
39431
|
);
|
|
39137
39432
|
});
|
|
39138
39433
|
},
|
|
39139
39434
|
probe(rule) {
|
|
39140
|
-
return enqueue((
|
|
39435
|
+
return enqueue((resolve3) => {
|
|
39141
39436
|
runOne(
|
|
39142
39437
|
{
|
|
39143
39438
|
budgetMs: probeBudgetMs,
|
|
39144
39439
|
build: (id) => ({ kind: "probe", id, rule }),
|
|
39145
39440
|
reply: (message) => {
|
|
39146
39441
|
if (message.kind !== "probed") return false;
|
|
39147
|
-
|
|
39442
|
+
resolve3({
|
|
39148
39443
|
status: "ok",
|
|
39149
39444
|
verdict: message.verdict,
|
|
39150
39445
|
worstMs: message.worstMs,
|
|
@@ -39153,7 +39448,7 @@ function createIsolatedScanner(data, opts = {}) {
|
|
|
39153
39448
|
return true;
|
|
39154
39449
|
}
|
|
39155
39450
|
},
|
|
39156
|
-
|
|
39451
|
+
resolve3
|
|
39157
39452
|
);
|
|
39158
39453
|
});
|
|
39159
39454
|
},
|
|
@@ -39384,6 +39679,40 @@ function createGuardedScanner(partition, gateway, opts) {
|
|
|
39384
39679
|
// ../../packages/plugin-sdk/src/hook-fail-opens.ts
|
|
39385
39680
|
import { readFileSync as readFileSync13 } from "fs";
|
|
39386
39681
|
import { join as join20 } from "path";
|
|
39682
|
+
var HOOK_FAIL_OPENS_FILENAME = "hook-fail-opens.json";
|
|
39683
|
+
function hookFailOpensPath(dataDir2) {
|
|
39684
|
+
return join20(dataDir2, HOOK_FAIL_OPENS_FILENAME);
|
|
39685
|
+
}
|
|
39686
|
+
function recordHookFailOpen(dataDir2, nowMs) {
|
|
39687
|
+
try {
|
|
39688
|
+
ensureDataDirSync(dataDir2);
|
|
39689
|
+
const previous = readHookFailOpens(dataDir2);
|
|
39690
|
+
const next = {
|
|
39691
|
+
// Saturates at the largest count the reader accepts: one past it would
|
|
39692
|
+
// read back as nothing recorded and restart the tally from one.
|
|
39693
|
+
failOpens: Math.min((previous?.failOpens ?? 0) + 1, Number.MAX_SAFE_INTEGER),
|
|
39694
|
+
lastAtMs: nowMs
|
|
39695
|
+
};
|
|
39696
|
+
writeOwnerOnlyFileSync(hookFailOpensPath(dataDir2), `${JSON.stringify(next)}
|
|
39697
|
+
`);
|
|
39698
|
+
} catch {
|
|
39699
|
+
}
|
|
39700
|
+
}
|
|
39701
|
+
function readHookFailOpens(dataDir2) {
|
|
39702
|
+
try {
|
|
39703
|
+
const parsed2 = JSON.parse(readFileSync13(hookFailOpensPath(dataDir2), "utf8"));
|
|
39704
|
+
if (typeof parsed2 !== "object" || parsed2 === null) return null;
|
|
39705
|
+
const record2 = parsed2;
|
|
39706
|
+
if (!isPositiveSafeInteger(record2.failOpens)) return null;
|
|
39707
|
+
if (!isPositiveSafeInteger(record2.lastAtMs)) return null;
|
|
39708
|
+
return { failOpens: record2.failOpens, lastAtMs: record2.lastAtMs };
|
|
39709
|
+
} catch {
|
|
39710
|
+
return null;
|
|
39711
|
+
}
|
|
39712
|
+
}
|
|
39713
|
+
function isPositiveSafeInteger(value) {
|
|
39714
|
+
return typeof value === "number" && Number.isSafeInteger(value) && value > 0;
|
|
39715
|
+
}
|
|
39387
39716
|
|
|
39388
39717
|
// ../../packages/plugin-sdk/src/host-floor.ts
|
|
39389
39718
|
import { readFileSync as readFileSync15 } from "fs";
|
|
@@ -40594,10 +40923,55 @@ import { spawn } from "child_process";
|
|
|
40594
40923
|
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
40595
40924
|
var HISTORY_SYNC_THROTTLE_MS = 5 * 60 * 1e3;
|
|
40596
40925
|
|
|
40926
|
+
// ../../packages/plugin-runtime/src/attached/install-record.ts
|
|
40927
|
+
import { readFile as readFile2, stat } from "fs/promises";
|
|
40928
|
+
import { basename as basename6, dirname as dirname6, join as join28, resolve as resolve2 } from "path";
|
|
40929
|
+
async function readInstalledVersion(installRoot) {
|
|
40930
|
+
try {
|
|
40931
|
+
const versionDir = resolve2(installRoot);
|
|
40932
|
+
const pluginDir = dirname6(versionDir);
|
|
40933
|
+
const marketplaceDir = dirname6(pluginDir);
|
|
40934
|
+
const cacheDir = dirname6(marketplaceDir);
|
|
40935
|
+
if (basename6(cacheDir) !== "cache") return null;
|
|
40936
|
+
const key = `${basename6(pluginDir)}@${basename6(marketplaceDir)}`;
|
|
40937
|
+
const record2 = JSON.parse(
|
|
40938
|
+
await readFile2(join28(dirname6(cacheDir), "installed_plugins.json"), "utf8")
|
|
40939
|
+
);
|
|
40940
|
+
const plugins = record2?.plugins;
|
|
40941
|
+
if (typeof plugins !== "object" || plugins === null || !Object.hasOwn(plugins, key)) {
|
|
40942
|
+
return null;
|
|
40943
|
+
}
|
|
40944
|
+
const entries = plugins[key];
|
|
40945
|
+
if (!Array.isArray(entries)) return null;
|
|
40946
|
+
let newest = null;
|
|
40947
|
+
for (const entry of entries) {
|
|
40948
|
+
const { version: version2, installPath } = entry ?? {};
|
|
40949
|
+
if (typeof version2 !== "string" || !isParseableBinaryVersion(version2)) continue;
|
|
40950
|
+
if (!StorePosturePlugin.shape.installedVersion.safeParse(version2).success) continue;
|
|
40951
|
+
if (newest !== null && compareBinaryVersions(version2, newest) <= 0) continue;
|
|
40952
|
+
if (typeof installPath === "string" && !await exists(installPath)) continue;
|
|
40953
|
+
newest = version2;
|
|
40954
|
+
}
|
|
40955
|
+
return newest;
|
|
40956
|
+
} catch {
|
|
40957
|
+
return null;
|
|
40958
|
+
}
|
|
40959
|
+
}
|
|
40960
|
+
async function exists(path) {
|
|
40961
|
+
try {
|
|
40962
|
+
await stat(path);
|
|
40963
|
+
return true;
|
|
40964
|
+
} catch {
|
|
40965
|
+
return false;
|
|
40966
|
+
}
|
|
40967
|
+
}
|
|
40968
|
+
|
|
40597
40969
|
// ../../packages/plugin-runtime/src/attached/plugin-block.ts
|
|
40598
40970
|
import { readFileSync as readFileSync18 } from "fs";
|
|
40971
|
+
var INSTALL_RECORD_READ_TIMEOUT_MS = REQUEST_TIMEOUT_MS / 2;
|
|
40599
40972
|
function createPluginBlock(build, policyStore) {
|
|
40600
40973
|
return async () => {
|
|
40974
|
+
const installed = build.installRoot === void 0 ? void 0 : readInstalledVersionBounded(build.installRoot);
|
|
40601
40975
|
const cached2 = await policyStore.read();
|
|
40602
40976
|
const fetchedAtMs = cached2?.fetchedAtMs;
|
|
40603
40977
|
const block = {
|
|
@@ -40605,16 +40979,25 @@ function createPluginBlock(build, policyStore) {
|
|
|
40605
40979
|
version: build.version,
|
|
40606
40980
|
ossVersion: build.ossVersion ?? null,
|
|
40607
40981
|
policyBundleVersion: cached2 !== null && StorePosturePlugin.shape.policyBundleVersion.safeParse(cached2.bundle.version).success ? cached2.bundle.version : null,
|
|
40608
|
-
policyFetchedAt: fetchedAtMs !== void 0 && fetchedAtMs > 0 && StorePosturePlugin.shape.policyFetchedAt.safeParse(fetchedAtMs).success ? fetchedAtMs : null
|
|
40982
|
+
policyFetchedAt: fetchedAtMs !== void 0 && fetchedAtMs > 0 && StorePosturePlugin.shape.policyFetchedAt.safeParse(fetchedAtMs).success ? fetchedAtMs : null,
|
|
40983
|
+
...installed === void 0 ? {} : { installedVersion: await installed },
|
|
40984
|
+
buildSchemaVersion: SQLITE_MIGRATIONS.length
|
|
40609
40985
|
};
|
|
40610
40986
|
return StorePosturePlugin.safeParse(block).success ? block : void 0;
|
|
40611
40987
|
};
|
|
40612
40988
|
}
|
|
40989
|
+
async function readInstalledVersionBounded(installRoot) {
|
|
40990
|
+
try {
|
|
40991
|
+
return await withTimeout(readInstalledVersion(installRoot), INSTALL_RECORD_READ_TIMEOUT_MS);
|
|
40992
|
+
} catch {
|
|
40993
|
+
return null;
|
|
40994
|
+
}
|
|
40995
|
+
}
|
|
40613
40996
|
|
|
40614
40997
|
// ../../packages/plugin-runtime/src/attached/policy-store.ts
|
|
40615
40998
|
import { randomUUID as randomUUID16 } from "crypto";
|
|
40616
|
-
import { readFile as
|
|
40617
|
-
import { join as
|
|
40999
|
+
import { readFile as readFile3, rm, writeFile as writeFile2 } from "fs/promises";
|
|
41000
|
+
import { join as join29 } from "path";
|
|
40618
41001
|
|
|
40619
41002
|
// ../../packages/plugin-runtime/src/attached/atomic-publish.ts
|
|
40620
41003
|
import { rename as rename2 } from "fs/promises";
|
|
@@ -40622,11 +41005,11 @@ var RETRYABLE = /* @__PURE__ */ new Set(["EPERM", "EACCES", "EBUSY"]);
|
|
|
40622
41005
|
var IMMEDIATE_RETRIES = 8;
|
|
40623
41006
|
var TIMED_RETRIES = 4;
|
|
40624
41007
|
var ATTEMPTS = 1 + IMMEDIATE_RETRIES + TIMED_RETRIES;
|
|
40625
|
-
var delay = (ms) => new Promise((
|
|
40626
|
-
setTimeout(
|
|
41008
|
+
var delay = (ms) => new Promise((resolve3) => {
|
|
41009
|
+
setTimeout(resolve3, ms);
|
|
40627
41010
|
});
|
|
40628
|
-
var yieldToLoop = () => new Promise((
|
|
40629
|
-
setImmediate(
|
|
41011
|
+
var yieldToLoop = () => new Promise((resolve3) => {
|
|
41012
|
+
setImmediate(resolve3);
|
|
40630
41013
|
});
|
|
40631
41014
|
async function publishByRename(tmp, file2, move = rename2) {
|
|
40632
41015
|
for (let attempt = 1; ; attempt += 1) {
|
|
@@ -40643,10 +41026,10 @@ async function publishByRename(tmp, file2, move = rename2) {
|
|
|
40643
41026
|
|
|
40644
41027
|
// ../../packages/plugin-runtime/src/attached/policy-store.ts
|
|
40645
41028
|
function createPolicyStore(dir = dataDir()) {
|
|
40646
|
-
const file2 =
|
|
41029
|
+
const file2 = join29(dir, "policy-cache.json");
|
|
40647
41030
|
async function read() {
|
|
40648
41031
|
try {
|
|
40649
|
-
const raw = await
|
|
41032
|
+
const raw = await readFile3(file2, "utf8");
|
|
40650
41033
|
const parsed2 = JSON.parse(raw);
|
|
40651
41034
|
if (typeof parsed2 !== "object" || parsed2 === null) return null;
|
|
40652
41035
|
const record2 = parsed2;
|
|
@@ -40668,7 +41051,7 @@ function createPolicyStore(dir = dataDir()) {
|
|
|
40668
41051
|
}
|
|
40669
41052
|
async function priorRecord() {
|
|
40670
41053
|
try {
|
|
40671
|
-
const parsed2 = JSON.parse(await
|
|
41054
|
+
const parsed2 = JSON.parse(await readFile3(file2, "utf8"));
|
|
40672
41055
|
return typeof parsed2 === "object" && parsed2 !== null ? parsed2 : null;
|
|
40673
41056
|
} catch {
|
|
40674
41057
|
return null;
|
|
@@ -40714,7 +41097,7 @@ function createPolicyStore(dir = dataDir()) {
|
|
|
40714
41097
|
|
|
40715
41098
|
// ../../packages/plugin-runtime/src/attached/posture-report-state.ts
|
|
40716
41099
|
import { readFileSync as readFileSync19 } from "fs";
|
|
40717
|
-
import { join as
|
|
41100
|
+
import { join as join30 } from "path";
|
|
40718
41101
|
var POSTURE_REPORT_STATE_FILENAME = ATTACHED_POSTURE_REPORT_FILENAME;
|
|
40719
41102
|
var OUTCOME_KEYS = {
|
|
40720
41103
|
ok: true,
|
|
@@ -40728,7 +41111,7 @@ var OUTCOME_KEYS = {
|
|
|
40728
41111
|
};
|
|
40729
41112
|
var OUTCOMES = new Set(Object.keys(OUTCOME_KEYS));
|
|
40730
41113
|
function postureReportStatePath(dataDir2) {
|
|
40731
|
-
return
|
|
41114
|
+
return join30(dataDir2, POSTURE_REPORT_STATE_FILENAME);
|
|
40732
41115
|
}
|
|
40733
41116
|
function writePostureReportState(dataDir2, state) {
|
|
40734
41117
|
try {
|
|
@@ -40907,12 +41290,12 @@ function readStorePosture(dbPath2) {
|
|
|
40907
41290
|
|
|
40908
41291
|
// ../../packages/plugin-runtime/src/attached/posture-store.ts
|
|
40909
41292
|
import { randomUUID as randomUUID17 } from "crypto";
|
|
40910
|
-
import { readFile as
|
|
40911
|
-
import { join as
|
|
41293
|
+
import { readFile as readFile4, rm as rm2, writeFile as writeFile3 } from "fs/promises";
|
|
41294
|
+
import { join as join31 } from "path";
|
|
40912
41295
|
var UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/;
|
|
40913
41296
|
function createPostureStore(dir = settingsDir(), legacyDir) {
|
|
40914
|
-
const file2 =
|
|
40915
|
-
const legacyFile = legacyDir === void 0 ? null :
|
|
41297
|
+
const file2 = join31(dir, "posture-state.json");
|
|
41298
|
+
const legacyFile = legacyDir === void 0 ? null : join31(legacyDir, "posture-state.json");
|
|
40916
41299
|
async function persist(state) {
|
|
40917
41300
|
await ensureDataDir(dir);
|
|
40918
41301
|
const tmp = `${file2}.${randomUUID17()}.tmp`;
|
|
@@ -40927,7 +41310,7 @@ function createPostureStore(dir = settingsDir(), legacyDir) {
|
|
|
40927
41310
|
async function readFrom(path) {
|
|
40928
41311
|
let raw;
|
|
40929
41312
|
try {
|
|
40930
|
-
raw = await
|
|
41313
|
+
raw = await readFile4(path, "utf8");
|
|
40931
41314
|
} catch (err) {
|
|
40932
41315
|
const code = err.code;
|
|
40933
41316
|
if (code === "ENOENT" || code === "ENOTDIR") return null;
|
|
@@ -40981,7 +41364,7 @@ function createPostureStore(dir = settingsDir(), legacyDir) {
|
|
|
40981
41364
|
|
|
40982
41365
|
// ../../packages/plugin-runtime/src/attached/sync-state.ts
|
|
40983
41366
|
import { readFileSync as readFileSync20 } from "fs";
|
|
40984
|
-
import { join as
|
|
41367
|
+
import { join as join32 } from "path";
|
|
40985
41368
|
|
|
40986
41369
|
// ../../packages/plugin-runtime/src/attached/status.ts
|
|
40987
41370
|
var REFUSAL_LINES = {
|
|
@@ -41058,12 +41441,12 @@ var StandaloneDataGateway = class {
|
|
|
41058
41441
|
// reconciler drops the whole pass and recovers it idempotently on the next read.
|
|
41059
41442
|
recordLlmCalls(inputs) {
|
|
41060
41443
|
if (inputs.length === 0) return Promise.resolve();
|
|
41061
|
-
return new Promise((
|
|
41444
|
+
return new Promise((resolve3, reject) => {
|
|
41062
41445
|
try {
|
|
41063
41446
|
this.db.auditEvents.runInTransaction(() => {
|
|
41064
41447
|
for (const input2 of inputs) this.db.auditEvents.insertLlmCall(input2);
|
|
41065
41448
|
});
|
|
41066
|
-
|
|
41449
|
+
resolve3();
|
|
41067
41450
|
} catch (err) {
|
|
41068
41451
|
reject(err instanceof Error ? err : new Error(String(err)));
|
|
41069
41452
|
}
|
|
@@ -41075,12 +41458,12 @@ var StandaloneDataGateway = class {
|
|
|
41075
41458
|
// drops the whole pass and recovers it idempotently next time.
|
|
41076
41459
|
recordToolCalls(inputs) {
|
|
41077
41460
|
if (inputs.length === 0) return Promise.resolve();
|
|
41078
|
-
return new Promise((
|
|
41461
|
+
return new Promise((resolve3, reject) => {
|
|
41079
41462
|
try {
|
|
41080
41463
|
this.db.auditEvents.runInTransaction(() => {
|
|
41081
41464
|
for (const input2 of inputs) this.writeToolCall(input2);
|
|
41082
41465
|
});
|
|
41083
|
-
|
|
41466
|
+
resolve3();
|
|
41084
41467
|
} catch (err) {
|
|
41085
41468
|
reject(err instanceof Error ? err : new Error(String(err)));
|
|
41086
41469
|
}
|
|
@@ -41581,7 +41964,7 @@ function responseEmitPayload(outcome) {
|
|
|
41581
41964
|
|
|
41582
41965
|
// src/hooks/shared.ts
|
|
41583
41966
|
async function readStdin() {
|
|
41584
|
-
return new Promise((
|
|
41967
|
+
return new Promise((resolve3) => {
|
|
41585
41968
|
let data = "";
|
|
41586
41969
|
let settled = false;
|
|
41587
41970
|
const finish = () => {
|
|
@@ -41590,7 +41973,7 @@ async function readStdin() {
|
|
|
41590
41973
|
clearTimeout(timer);
|
|
41591
41974
|
process.stdin.removeListener("data", onData);
|
|
41592
41975
|
process.stdin.removeListener("end", finish);
|
|
41593
|
-
|
|
41976
|
+
resolve3(data);
|
|
41594
41977
|
};
|
|
41595
41978
|
const onData = (chunk) => {
|
|
41596
41979
|
data += chunk;
|
|
@@ -41615,12 +41998,12 @@ function getString(record2, key) {
|
|
|
41615
41998
|
return typeof value === "string" ? value : void 0;
|
|
41616
41999
|
}
|
|
41617
42000
|
function emit(output2) {
|
|
41618
|
-
return new Promise((
|
|
42001
|
+
return new Promise((resolve3) => {
|
|
41619
42002
|
let settled = false;
|
|
41620
42003
|
const finish = () => {
|
|
41621
42004
|
if (settled) return;
|
|
41622
42005
|
settled = true;
|
|
41623
|
-
|
|
42006
|
+
resolve3();
|
|
41624
42007
|
};
|
|
41625
42008
|
process.stdout.on("error", finish);
|
|
41626
42009
|
process.stdout.write(JSON.stringify(output2), finish);
|
|
@@ -41634,18 +42017,24 @@ function baseMetadata(input2) {
|
|
|
41634
42017
|
if (repo) metadata.repo = repo;
|
|
41635
42018
|
return Object.keys(metadata).length > 0 ? metadata : void 0;
|
|
41636
42019
|
}
|
|
42020
|
+
function countFailOpen(base) {
|
|
42021
|
+
try {
|
|
42022
|
+
recordHookFailOpen(dataDir(base), Date.now());
|
|
42023
|
+
} catch {
|
|
42024
|
+
}
|
|
42025
|
+
}
|
|
41637
42026
|
|
|
41638
42027
|
// src/hooks/store-health.ts
|
|
41639
42028
|
import { mkdirSync as mkdirSync5, readFileSync as readFileSync21, writeFileSync as writeFileSync8 } from "fs";
|
|
41640
|
-
import { dirname as
|
|
42029
|
+
import { dirname as dirname7, join as join33 } from "path";
|
|
41641
42030
|
var STORE_REDIRECT_MARKER = "store-redirect-last-session";
|
|
41642
42031
|
function markerDirs(dataDir2) {
|
|
41643
|
-
return [dataDir2,
|
|
42032
|
+
return [dataDir2, dirname7(dataDir2)];
|
|
41644
42033
|
}
|
|
41645
42034
|
function alreadyClaimed(dirs, marker, sessionId) {
|
|
41646
42035
|
return dirs.some((dir) => {
|
|
41647
42036
|
try {
|
|
41648
|
-
return readFileSync21(
|
|
42037
|
+
return readFileSync21(join33(dir, marker), "utf8") === sessionId;
|
|
41649
42038
|
} catch {
|
|
41650
42039
|
return false;
|
|
41651
42040
|
}
|
|
@@ -41655,7 +42044,7 @@ function recordClaim(dirs, marker, sessionId) {
|
|
|
41655
42044
|
for (const dir of dirs) {
|
|
41656
42045
|
try {
|
|
41657
42046
|
mkdirSync5(dir, { recursive: true, mode: DATA_DIR_MODE });
|
|
41658
|
-
writeFileSync8(
|
|
42047
|
+
writeFileSync8(join33(dir, marker), sessionId, { mode: DATA_FILE_MODE });
|
|
41659
42048
|
return;
|
|
41660
42049
|
} catch {
|
|
41661
42050
|
}
|
|
@@ -41680,7 +42069,7 @@ function formatMode(mode) {
|
|
|
41680
42069
|
}
|
|
41681
42070
|
function warnIfStoreRedirected(config2, sessionId, write = (message) => void process.stderr.write(message)) {
|
|
41682
42071
|
try {
|
|
41683
|
-
const paths = symlinkedStorePaths(
|
|
42072
|
+
const paths = symlinkedStorePaths(dirname7(config2.dataDir));
|
|
41684
42073
|
if (paths.length === 0) return;
|
|
41685
42074
|
if (!sessionId) {
|
|
41686
42075
|
write(storeRedirectedMessage(paths));
|
|
@@ -41756,5 +42145,6 @@ async function main() {
|
|
|
41756
42145
|
try {
|
|
41757
42146
|
await main();
|
|
41758
42147
|
} catch {
|
|
42148
|
+
countFailOpen();
|
|
41759
42149
|
}
|
|
41760
42150
|
process.exit(0);
|