@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/pre-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;
|
|
@@ -1002,6 +1009,10 @@ var SQLITE_MIGRATIONS = [
|
|
|
1002
1009
|
{
|
|
1003
1010
|
tag: "0035_share_destination_provider_id",
|
|
1004
1011
|
sql: "ALTER TABLE `share_destination` ADD `provider_id` text;"
|
|
1012
|
+
},
|
|
1013
|
+
{
|
|
1014
|
+
tag: "0036_secret_vault_identity_fingerprint",
|
|
1015
|
+
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"
|
|
1005
1016
|
}
|
|
1006
1017
|
];
|
|
1007
1018
|
|
|
@@ -1011,6 +1022,12 @@ var HOUR_MS = 60 * MINUTE_MS;
|
|
|
1011
1022
|
var MAX_TEMPORARY_MS = 24 * HOUR_MS;
|
|
1012
1023
|
var ONCE_BACKSTOP_MS = 30 * MINUTE_MS;
|
|
1013
1024
|
|
|
1025
|
+
// ../../packages/schema/src/invisible-padding.ts
|
|
1026
|
+
var INVISIBLE_PADDING = /[\u00AD\u200B\u2060-\u2064\u202A-\u202E\u2066-\u2069\uFEFF\u{E0001}\u{E0020}-\u{E007F}]/gu;
|
|
1027
|
+
function stripInvisiblePadding(text) {
|
|
1028
|
+
return text.replace(INVISIBLE_PADDING, "");
|
|
1029
|
+
}
|
|
1030
|
+
|
|
1014
1031
|
// ../../node_modules/.pnpm/zod@4.6.5/node_modules/zod/v4/classic/external.js
|
|
1015
1032
|
var external_exports = {};
|
|
1016
1033
|
__export(external_exports, {
|
|
@@ -6037,7 +6054,7 @@ var recursive = /* @__PURE__ */ new WeakMap();
|
|
|
6037
6054
|
var NONE = 0;
|
|
6038
6055
|
var ASSUMED = 1;
|
|
6039
6056
|
var PROVEN = 2;
|
|
6040
|
-
function isRecursive(inst, stack,
|
|
6057
|
+
function isRecursive(inst, stack, resolve3) {
|
|
6041
6058
|
const cached2 = recursive.get(inst);
|
|
6042
6059
|
if (cached2 !== void 0)
|
|
6043
6060
|
return cached2 ? PROVEN : NONE;
|
|
@@ -6047,7 +6064,7 @@ function isRecursive(inst, stack, resolve2) {
|
|
|
6047
6064
|
let result = NONE;
|
|
6048
6065
|
const check2 = (child) => {
|
|
6049
6066
|
if (result !== PROVEN && child?._zod) {
|
|
6050
|
-
const answer = isRecursive(child, stack,
|
|
6067
|
+
const answer = isRecursive(child, stack, resolve3);
|
|
6051
6068
|
if (answer > result)
|
|
6052
6069
|
result = answer;
|
|
6053
6070
|
}
|
|
@@ -6058,7 +6075,7 @@ function isRecursive(inst, stack, resolve2) {
|
|
|
6058
6075
|
const desc = Object.getOwnPropertyDescriptor(sh, key);
|
|
6059
6076
|
if (spread && !desc.enumerable)
|
|
6060
6077
|
continue;
|
|
6061
|
-
const child = desc.get ? ASSUMED : desc.value?._zod ? isRecursive(desc.value, stack,
|
|
6078
|
+
const child = desc.get ? ASSUMED : desc.value?._zod ? isRecursive(desc.value, stack, resolve3) : NONE;
|
|
6062
6079
|
if (child > answer)
|
|
6063
6080
|
answer = child;
|
|
6064
6081
|
}
|
|
@@ -6122,7 +6139,7 @@ function isRecursive(inst, stack, resolve2) {
|
|
|
6122
6139
|
break;
|
|
6123
6140
|
// `$ZodLazy` caches its inner on the def, so a resolved edge is followed exactly
|
|
6124
6141
|
case "lazy": {
|
|
6125
|
-
const inner = def._cachedInner ?? (
|
|
6142
|
+
const inner = def._cachedInner ?? (resolve3 ? inst._zod.innerType : void 0);
|
|
6126
6143
|
merge2(inner ? isRecursive(inner, stack, false) : ASSUMED);
|
|
6127
6144
|
break;
|
|
6128
6145
|
}
|
|
@@ -23403,7 +23420,29 @@ var StorePosturePlugin = external_exports.object({
|
|
|
23403
23420
|
*/
|
|
23404
23421
|
policyBundleVersion: external_exports.string().max(200).nullable(),
|
|
23405
23422
|
/** Epoch millis, on the CLIENT clock, of that fetch. */
|
|
23406
|
-
policyFetchedAt: external_exports.number().int().min(0).max(MAX_DATE_MS).nullable()
|
|
23423
|
+
policyFetchedAt: external_exports.number().int().min(0).max(MAX_DATE_MS).nullable(),
|
|
23424
|
+
/**
|
|
23425
|
+
* The newest version the host's own install record holds for this plugin —
|
|
23426
|
+
* what is on disk. After an update it leads `version` (the running copy) by
|
|
23427
|
+
* one launch. Null when no usable version can be read: no install record
|
|
23428
|
+
* (a plugin run from a checkout), no entry with a valid version, or every
|
|
23429
|
+
* such entry names an `installPath` that no longer exists; OPTIONAL, not
|
|
23430
|
+
* required, so a build that predates the member keeps getting its 200.
|
|
23431
|
+
* Bounded like `version`.
|
|
23432
|
+
*/
|
|
23433
|
+
installedVersion: external_exports.string().max(64).nullable().optional(),
|
|
23434
|
+
/**
|
|
23435
|
+
* The local-store schema version this running build migrates a store to:
|
|
23436
|
+
* the number of store migrations it carries, the count it stamps into
|
|
23437
|
+
* `PRAGMA user_version`. A snapshot whose `schemaVersion` is above it
|
|
23438
|
+
* usually describes a store a newer build migrated. It is a hint, not a
|
|
23439
|
+
* verdict: the stamp is write-only, so a store whose count ran past this
|
|
23440
|
+
* build's while this build knows every migration in its ledger reads above
|
|
23441
|
+
* it too, which is why describeStoreSkew decides skew on ledger tags and
|
|
23442
|
+
* never on the count. OPTIONAL for the same reason as `installedVersion`;
|
|
23443
|
+
* bounded like `schemaVersion`.
|
|
23444
|
+
*/
|
|
23445
|
+
buildSchemaVersion: external_exports.number().int().min(0).max(MAX_INT4).optional()
|
|
23407
23446
|
}).meta({ id: "StorePosturePlugin" });
|
|
23408
23447
|
var StorePostureSnapshot = external_exports.object({
|
|
23409
23448
|
deviceId: external_exports.guid(),
|
|
@@ -25046,10 +25085,15 @@ var ParsedPointer = external_exports.object({
|
|
|
25046
25085
|
});
|
|
25047
25086
|
var VaultEntry = external_exports.object({
|
|
25048
25087
|
pointerId: external_exports.string(),
|
|
25049
|
-
// The keyed HMAC of the raw
|
|
25050
|
-
// derived under.
|
|
25051
|
-
// independently of the vault encryption
|
|
25088
|
+
// The keyed HMAC of the EXACT raw bytes under `exception.key`, and the epoch it
|
|
25089
|
+
// was derived under. The vault's own dedupe key: a value and its invisibly
|
|
25090
|
+
// padded twin are two rows. It rotates independently of the vault encryption
|
|
25091
|
+
// key below. Never matched against an exception or grant.
|
|
25052
25092
|
valueFingerprint: external_exports.string().regex(/^[0-9a-f]{64}$/),
|
|
25093
|
+
// The same HMAC over the raw with invisible padding removed: the identity a
|
|
25094
|
+
// reveal-to-model grant and every exception match on. Shared by a value and
|
|
25095
|
+
// its padded twin.
|
|
25096
|
+
valueIdentityFingerprint: external_exports.string().regex(/^[0-9a-f]{64}$/),
|
|
25053
25097
|
fingerprintKeyVersion: external_exports.number().int().positive(),
|
|
25054
25098
|
// The vault-key epoch this row's ciphertext was sealed under.
|
|
25055
25099
|
keyVersion: external_exports.number().int().positive(),
|
|
@@ -25622,10 +25666,18 @@ var SeveritySummaryItem = external_exports.object({
|
|
|
25622
25666
|
count: external_exports.number().int().nonnegative(),
|
|
25623
25667
|
// Resolution-aware breakdown (optional, additive). Populated once findings
|
|
25624
25668
|
// carry lifecycle state: `caught` = handled in-flight (enforced); `openAtRest`
|
|
25625
|
-
// = still open with no in-flight enforcement (needs remediation)
|
|
25626
|
-
//
|
|
25669
|
+
// = still open with no in-flight enforcement (needs remediation); `dismissed`
|
|
25670
|
+
// = closed by a human judgement rather than a fix — visible, but not counted as
|
|
25671
|
+
// needing remediation. The three are disjoint. Absent on the legacy count-only
|
|
25672
|
+
// response until the resolution feature lands.
|
|
25627
25673
|
caught: external_exports.number().int().nonnegative().optional(),
|
|
25628
|
-
openAtRest: external_exports.number().int().nonnegative().optional()
|
|
25674
|
+
openAtRest: external_exports.number().int().nonnegative().optional(),
|
|
25675
|
+
dismissed: external_exports.number().int().nonnegative().optional(),
|
|
25676
|
+
// The two halves of `caught`, for a reader that wants them apart: `handled` =
|
|
25677
|
+
// in-flight findings an enforcement action already contained; `resolved` =
|
|
25678
|
+
// at-rest findings closed out by fixing them. `handled + resolved === caught`.
|
|
25679
|
+
handled: external_exports.number().int().nonnegative().optional(),
|
|
25680
|
+
resolved: external_exports.number().int().nonnegative().optional()
|
|
25629
25681
|
}).meta({ id: "SeveritySummaryItem" });
|
|
25630
25682
|
var SeveritySummaryResponse = external_exports.object({
|
|
25631
25683
|
// Sum of bySeverity[].count.
|
|
@@ -25633,6 +25685,9 @@ var SeveritySummaryResponse = external_exports.object({
|
|
|
25633
25685
|
// Findings still open at rest (sum of bySeverity[].openAtRest). Optional and
|
|
25634
25686
|
// additive — absent on the legacy response until the resolution feature lands.
|
|
25635
25687
|
needsRemediation: external_exports.number().int().nonnegative().optional(),
|
|
25688
|
+
// Findings a user dismissed (sum of bySeverity[].dismissed). Excluded from
|
|
25689
|
+
// needsRemediation, and kept visible here so an accepted risk is not erased.
|
|
25690
|
+
dismissed: external_exports.number().int().nonnegative().optional(),
|
|
25636
25691
|
// All four severity levels are always present (count may be 0).
|
|
25637
25692
|
bySeverity: external_exports.array(SeveritySummaryItem)
|
|
25638
25693
|
}).meta({ id: "SeveritySummaryResponse" });
|
|
@@ -26250,11 +26305,11 @@ function repairOrRefuseMode(file2) {
|
|
|
26250
26305
|
const link = lstatSync2(file2, { throwIfNoEntry: false });
|
|
26251
26306
|
if (link === void 0) return "absent";
|
|
26252
26307
|
if (link.isSymbolicLink()) return "untrusted";
|
|
26253
|
-
const
|
|
26254
|
-
if (
|
|
26308
|
+
const stat2 = statSync(file2, { throwIfNoEntry: false });
|
|
26309
|
+
if (stat2 === void 0) return "absent";
|
|
26255
26310
|
const uid = process.getuid?.();
|
|
26256
|
-
if (uid !== void 0 &&
|
|
26257
|
-
if (process.platform !== "win32" && (
|
|
26311
|
+
if (uid !== void 0 && stat2.uid !== uid) return "untrusted";
|
|
26312
|
+
if (process.platform !== "win32" && (stat2.mode & 511) !== DATA_FILE_MODE) {
|
|
26258
26313
|
try {
|
|
26259
26314
|
chmodSync2(file2, DATA_FILE_MODE);
|
|
26260
26315
|
} catch {
|
|
@@ -26266,9 +26321,9 @@ function repairOrRefuseMode(file2) {
|
|
|
26266
26321
|
function readControlPlaneCredentialFile(settingsDir2, connection) {
|
|
26267
26322
|
const file2 = controlPlaneCredentialPath(settingsDir2);
|
|
26268
26323
|
let raw;
|
|
26269
|
-
const
|
|
26270
|
-
if (
|
|
26271
|
-
if (
|
|
26324
|
+
const gate2 = repairOrRefuseMode(file2);
|
|
26325
|
+
if (gate2 === "absent") return { usable: false, reason: "absent" };
|
|
26326
|
+
if (gate2 === "untrusted") return { usable: false, reason: "untrusted-file" };
|
|
26272
26327
|
try {
|
|
26273
26328
|
raw = readFileSync(file2, "utf8");
|
|
26274
26329
|
} catch (err) {
|
|
@@ -32416,7 +32471,10 @@ var SqliteResolutionsRepository = class {
|
|
|
32416
32471
|
* Insert many dispositions as ONE transaction — all of them or none.
|
|
32417
32472
|
*
|
|
32418
32473
|
* A dashboard dismissal closes every open finding of a rule, which is one
|
|
32419
|
-
* write per key
|
|
32474
|
+
* write per key. It reaches this through
|
|
32475
|
+
* `LocalDatabase.dismissOpenFindingsForRule`, which calls it inside the
|
|
32476
|
+
* transaction that selected the keys, so there it runs as a SAVEPOINT of
|
|
32477
|
+
* that transaction. Run loose, a fault partway leaves half a rule closed with
|
|
32420
32478
|
* nothing recording that the other half was meant to be. The caller then has
|
|
32421
32479
|
* no way to tell a partial run from a complete one, because the card it
|
|
32422
32480
|
* refreshes into just shows a smaller number either way.
|
|
@@ -32636,6 +32694,7 @@ function toSighting(row) {
|
|
|
32636
32694
|
var SELECT_COLUMNS = `
|
|
32637
32695
|
pointer_id AS pointerId,
|
|
32638
32696
|
value_fingerprint AS valueFingerprint,
|
|
32697
|
+
value_identity_fingerprint AS valueIdentityFingerprint,
|
|
32639
32698
|
fingerprint_key_version AS fingerprintKeyVersion,
|
|
32640
32699
|
key_version AS keyVersion,
|
|
32641
32700
|
format_version AS formatVersion,
|
|
@@ -32660,13 +32719,13 @@ var SqliteSecretVaultRepository = class {
|
|
|
32660
32719
|
this.db = db;
|
|
32661
32720
|
this.insertStmt = db.prepare(
|
|
32662
32721
|
`INSERT INTO secret_vault (
|
|
32663
|
-
pointer_id, value_fingerprint,
|
|
32664
|
-
format_version, category, rule_id, masked_match, provider,
|
|
32722
|
+
pointer_id, value_fingerprint, value_identity_fingerprint,
|
|
32723
|
+
fingerprint_key_version, key_version, format_version, category, rule_id, masked_match, provider,
|
|
32665
32724
|
ciphertext, nonce, auth_tag,
|
|
32666
32725
|
user_authorized, occurrence_count, first_seen, last_seen
|
|
32667
32726
|
) VALUES (
|
|
32668
|
-
:pointerId, :valueFingerprint, :
|
|
32669
|
-
:formatVersion, :category, :ruleId, :maskedMatch, :provider,
|
|
32727
|
+
:pointerId, :valueFingerprint, :valueIdentityFingerprint,
|
|
32728
|
+
:fingerprintKeyVersion, :keyVersion, :formatVersion, :category, :ruleId, :maskedMatch, :provider,
|
|
32670
32729
|
:ciphertext, :nonce, :authTag,
|
|
32671
32730
|
:userAuthorized, 1, :now, :now
|
|
32672
32731
|
)`
|
|
@@ -32691,7 +32750,13 @@ var SqliteSecretVaultRepository = class {
|
|
|
32691
32750
|
);
|
|
32692
32751
|
this.refreshFingerprintStmt = db.prepare(
|
|
32693
32752
|
`UPDATE secret_vault
|
|
32694
|
-
SET value_fingerprint = :valueFingerprint,
|
|
32753
|
+
SET value_fingerprint = :valueFingerprint,
|
|
32754
|
+
value_identity_fingerprint = :valueIdentityFingerprint,
|
|
32755
|
+
fingerprint_key_version = :fingerprintKeyVersion
|
|
32756
|
+
WHERE pointer_id = :pointerId`
|
|
32757
|
+
);
|
|
32758
|
+
this.setIdentityStmt = db.prepare(
|
|
32759
|
+
`UPDATE secret_vault SET value_identity_fingerprint = :valueIdentityFingerprint
|
|
32695
32760
|
WHERE pointer_id = :pointerId`
|
|
32696
32761
|
);
|
|
32697
32762
|
this.deleteByPointerStmt = db.prepare(`DELETE FROM secret_vault WHERE pointer_id = :pointerId`);
|
|
@@ -32708,6 +32773,7 @@ var SqliteSecretVaultRepository = class {
|
|
|
32708
32773
|
listStmt;
|
|
32709
32774
|
replaceCiphertextStmt;
|
|
32710
32775
|
refreshFingerprintStmt;
|
|
32776
|
+
setIdentityStmt;
|
|
32711
32777
|
deleteByPointerStmt;
|
|
32712
32778
|
derefStmt;
|
|
32713
32779
|
/**
|
|
@@ -32738,6 +32804,7 @@ var SqliteSecretVaultRepository = class {
|
|
|
32738
32804
|
bindParams({
|
|
32739
32805
|
pointerId: input2.pointerId,
|
|
32740
32806
|
valueFingerprint: input2.valueFingerprint,
|
|
32807
|
+
valueIdentityFingerprint: input2.valueIdentityFingerprint,
|
|
32741
32808
|
fingerprintKeyVersion: input2.fingerprintKeyVersion,
|
|
32742
32809
|
keyVersion: input2.keyVersion,
|
|
32743
32810
|
formatVersion: input2.formatVersion ?? POINTER_FORMAT_VERSION,
|
|
@@ -32799,7 +32866,15 @@ var SqliteSecretVaultRepository = class {
|
|
|
32799
32866
|
replaceCiphertext(pointerId, next) {
|
|
32800
32867
|
this.replaceCiphertextStmt.run({ pointerId, ...next });
|
|
32801
32868
|
}
|
|
32802
|
-
/**
|
|
32869
|
+
/**
|
|
32870
|
+
* Correct an entry's identity fingerprint in place, leaving its exact
|
|
32871
|
+
* fingerprint and key epoch alone. For a row whose identity column still holds
|
|
32872
|
+
* the exact value copied in by the migration that added it.
|
|
32873
|
+
*/
|
|
32874
|
+
setIdentityFingerprint(pointerId, valueIdentityFingerprint) {
|
|
32875
|
+
this.setIdentityStmt.run({ pointerId, valueIdentityFingerprint });
|
|
32876
|
+
}
|
|
32877
|
+
/** Re-derive an entry's fingerprints under a new fingerprint-key epoch. */
|
|
32803
32878
|
refreshFingerprint(pointerId, next) {
|
|
32804
32879
|
this.refreshFingerprintStmt.run({ pointerId, ...next });
|
|
32805
32880
|
}
|
|
@@ -32930,7 +33005,7 @@ var SqliteSecretVaultRepository = class {
|
|
|
32930
33005
|
`SELECT ${INVENTORY_COLUMNS},
|
|
32931
33006
|
(SELECT e.id FROM exceptions e
|
|
32932
33007
|
WHERE e.rule_id = v.rule_id
|
|
32933
|
-
AND e.value_fingerprint = v.
|
|
33008
|
+
AND e.value_fingerprint = v.value_identity_fingerprint
|
|
32934
33009
|
AND e.key_version = v.fingerprint_key_version
|
|
32935
33010
|
AND ${ACTIVE_REVEAL_GRANT_PREDICATE}
|
|
32936
33011
|
LIMIT 1) AS grant_id
|
|
@@ -32973,7 +33048,7 @@ var SqliteSecretVaultRepository = class {
|
|
|
32973
33048
|
`SELECT ${INVENTORY_COLUMNS},
|
|
32974
33049
|
(SELECT e.id FROM exceptions e
|
|
32975
33050
|
WHERE e.rule_id = v.rule_id
|
|
32976
|
-
AND e.value_fingerprint = v.
|
|
33051
|
+
AND e.value_fingerprint = v.value_identity_fingerprint
|
|
32977
33052
|
AND e.key_version = v.fingerprint_key_version
|
|
32978
33053
|
AND ${ACTIVE_REVEAL_GRANT_PREDICATE}
|
|
32979
33054
|
LIMIT 1) AS grant_id
|
|
@@ -33077,6 +33152,18 @@ var OPEN_AT_REST_FINDINGS_SQL = `FROM inspection_findings f
|
|
|
33077
33152
|
OR latest.status IS NULL
|
|
33078
33153
|
OR latest.status NOT IN ('resolved', 'dismissed')
|
|
33079
33154
|
)`;
|
|
33155
|
+
function selectOpenFindingKeysForRule(db, ruleId) {
|
|
33156
|
+
const rows = allRows(
|
|
33157
|
+
db.prepare(
|
|
33158
|
+
`SELECT DISTINCT f.finding_key AS finding_key
|
|
33159
|
+
${OPEN_AT_REST_FINDINGS_SQL}
|
|
33160
|
+
AND d.rule_id = :ruleId
|
|
33161
|
+
AND f.finding_key IS NOT NULL`
|
|
33162
|
+
),
|
|
33163
|
+
{ ruleId }
|
|
33164
|
+
);
|
|
33165
|
+
return rows.map((r) => r.finding_key);
|
|
33166
|
+
}
|
|
33080
33167
|
var SEVERITIES = ["critical", "high", "medium", "low"];
|
|
33081
33168
|
var ACTION_TO_KIND = {
|
|
33082
33169
|
block: "blocked",
|
|
@@ -33133,16 +33220,16 @@ var SqliteSecurityRepository = class {
|
|
|
33133
33220
|
// findings are caught only once their latest disposition is resolved,
|
|
33134
33221
|
// otherwise they are open-at-rest.
|
|
33135
33222
|
//
|
|
33136
|
-
//
|
|
33137
|
-
//
|
|
33138
|
-
//
|
|
33139
|
-
//
|
|
33140
|
-
// be bucketed as caught
|
|
33223
|
+
// Only latest status 'resolved' counts as caught above. 'dismissed' is its
|
|
33224
|
+
// own bucket: a judgement rather than a fix, so it is neither caught nor
|
|
33225
|
+
// needing remediation, and stays countable. A further manual disposition
|
|
33226
|
+
// (acknowledged, false-positive) must be placed deliberately — 'acknowledged'
|
|
33227
|
+
// is accepted risk, not a fix, and must NOT be bucketed as caught.
|
|
33141
33228
|
//
|
|
33142
33229
|
// Legacy at-rest findings from pre-branch scans carry finding_key = NULL —
|
|
33143
33230
|
// the resolution lifecycle is keyed by finding_key, so it can never attach a
|
|
33144
33231
|
// disposition to (or clear) one of these on re-scan. They are excluded from
|
|
33145
|
-
//
|
|
33232
|
+
// all three buckets (untracked, not "needs remediation forever"),
|
|
33146
33233
|
// but still counted in total/count below — this keeps this predicate
|
|
33147
33234
|
// consistent with SqliteResolutionsRepository.openAtRestKeysForPath, which
|
|
33148
33235
|
// already filters `finding_key IS NOT NULL`.
|
|
@@ -33165,12 +33252,25 @@ var SqliteSecurityRepository = class {
|
|
|
33165
33252
|
WHEN latest.status = 'resolved' THEN 1
|
|
33166
33253
|
ELSE 0
|
|
33167
33254
|
END) AS caught,
|
|
33255
|
+
SUM(CASE WHEN e.event_type != 'code_change' THEN 1 ELSE 0 END) AS handled,
|
|
33256
|
+
SUM(CASE
|
|
33257
|
+
WHEN e.event_type = 'code_change'
|
|
33258
|
+
AND f.finding_key IS NOT NULL
|
|
33259
|
+
AND latest.status = 'resolved' THEN 1
|
|
33260
|
+
ELSE 0
|
|
33261
|
+
END) AS resolved,
|
|
33168
33262
|
SUM(CASE
|
|
33169
33263
|
WHEN e.event_type = 'code_change'
|
|
33170
33264
|
AND f.finding_key IS NOT NULL
|
|
33171
|
-
AND (latest.status IS NULL
|
|
33265
|
+
AND (latest.status IS NULL
|
|
33266
|
+
OR latest.status NOT IN ('resolved', 'dismissed')) THEN 1
|
|
33172
33267
|
ELSE 0
|
|
33173
|
-
END) AS open_at_rest
|
|
33268
|
+
END) AS open_at_rest,
|
|
33269
|
+
SUM(CASE
|
|
33270
|
+
WHEN e.event_type = 'code_change'
|
|
33271
|
+
AND latest.status = 'dismissed' THEN 1
|
|
33272
|
+
ELSE 0
|
|
33273
|
+
END) AS dismissed
|
|
33174
33274
|
FROM inspection_findings f
|
|
33175
33275
|
JOIN audit_events e INDEXED BY idx_audit_capture_rollup ON e.id = f.audit_event_id
|
|
33176
33276
|
JOIN inspection_definitions d ON d.id = f.inspection_definition_id
|
|
@@ -33185,11 +33285,15 @@ var SqliteSecurityRepository = class {
|
|
|
33185
33285
|
severity,
|
|
33186
33286
|
count: byRow.get(severity)?.count ?? 0,
|
|
33187
33287
|
caught: byRow.get(severity)?.caught ?? 0,
|
|
33188
|
-
|
|
33288
|
+
handled: byRow.get(severity)?.handled ?? 0,
|
|
33289
|
+
resolved: byRow.get(severity)?.resolved ?? 0,
|
|
33290
|
+
openAtRest: byRow.get(severity)?.open_at_rest ?? 0,
|
|
33291
|
+
dismissed: byRow.get(severity)?.dismissed ?? 0
|
|
33189
33292
|
}));
|
|
33190
33293
|
const total = bySeverity.reduce((sum, s) => sum + s.count, 0);
|
|
33191
33294
|
const needsRemediation = bySeverity.reduce((sum, s) => sum + s.openAtRest, 0);
|
|
33192
|
-
|
|
33295
|
+
const dismissed = bySeverity.reduce((sum, s) => sum + s.dismissed, 0);
|
|
33296
|
+
return Promise.resolve({ total, needsRemediation, dismissed, bySeverity });
|
|
33193
33297
|
}
|
|
33194
33298
|
// Range is echoed but does not change the result today — coverage is a constant
|
|
33195
33299
|
// business fact (see SCAN_COVERAGE), not a measured per-window metric. Order
|
|
@@ -33506,10 +33610,10 @@ var SqliteSecurityRepository = class {
|
|
|
33506
33610
|
* machine, and the second reported "no recommendations" over live exposure.
|
|
33507
33611
|
*
|
|
33508
33612
|
* `open` mirrors `deriveFindingStatus` — at-rest, minus resolved and dismissed —
|
|
33509
|
-
* so a row's count is exactly what `?status=open&type=<rule>` returns.
|
|
33510
|
-
*
|
|
33511
|
-
*
|
|
33512
|
-
*
|
|
33613
|
+
* so a row's count is exactly what `?status=open&type=<rule>` returns. It
|
|
33614
|
+
* differs from `severitySummary`'s `openAtRest` only in including untracked
|
|
33615
|
+
* legacy rows, which that bucket leaves out; dismissed is excluded from both.
|
|
33616
|
+
* Only this one has to match a link.
|
|
33513
33617
|
*
|
|
33514
33618
|
* Aggregated in SQL: the result is O(distinct rule × category × severity), so a
|
|
33515
33619
|
* whole-store scope costs a grouped scan rather than a row per finding.
|
|
@@ -33537,6 +33641,8 @@ var SqliteSecurityRepository = class {
|
|
|
33537
33641
|
/**
|
|
33538
33642
|
* The distinct `finding_key`s behind ONE rule's {@link recommendationInputs}
|
|
33539
33643
|
* tally — what a dashboard dismissal of that row writes a disposition for.
|
|
33644
|
+
* The dismissal itself does not call this: it reads the same set through
|
|
33645
|
+
* {@link selectOpenFindingKeysForRule}, inside its own write transaction.
|
|
33540
33646
|
*
|
|
33541
33647
|
* It shares {@link OPEN_AT_REST_FINDINGS_SQL} with the count rather than
|
|
33542
33648
|
* restating the predicate, because a dismissal has to act on exactly the set
|
|
@@ -33553,16 +33659,7 @@ var SqliteSecurityRepository = class {
|
|
|
33553
33659
|
* this set SMALLER than the tally, never larger.
|
|
33554
33660
|
*/
|
|
33555
33661
|
openFindingKeysForRule(ruleId) {
|
|
33556
|
-
|
|
33557
|
-
this.db.prepare(
|
|
33558
|
-
`SELECT DISTINCT f.finding_key AS finding_key
|
|
33559
|
-
${OPEN_AT_REST_FINDINGS_SQL}
|
|
33560
|
-
AND d.rule_id = :ruleId
|
|
33561
|
-
AND f.finding_key IS NOT NULL`
|
|
33562
|
-
),
|
|
33563
|
-
{ ruleId }
|
|
33564
|
-
);
|
|
33565
|
-
return Promise.resolve(rows.map((r) => r.finding_key));
|
|
33662
|
+
return Promise.resolve(selectOpenFindingKeysForRule(this.db, ruleId));
|
|
33566
33663
|
}
|
|
33567
33664
|
// Findings whose parent event occurred in [fromMs, toMs), with the parent's
|
|
33568
33665
|
// epoch-millis timestamp. started_at is an INTEGER column, so the bounds stay
|
|
@@ -34608,6 +34705,31 @@ function openLocalDatabase(dir, options = {}) {
|
|
|
34608
34705
|
);
|
|
34609
34706
|
});
|
|
34610
34707
|
}
|
|
34708
|
+
function dismissOpenFindingsForRule(ruleId, disposition) {
|
|
34709
|
+
let dismissed = 0;
|
|
34710
|
+
withTransaction(
|
|
34711
|
+
db,
|
|
34712
|
+
() => {
|
|
34713
|
+
const keys = selectOpenFindingKeysForRule(db, ruleId);
|
|
34714
|
+
resolutions.insertResolutions(
|
|
34715
|
+
keys.map((findingKey) => ({
|
|
34716
|
+
findingKey,
|
|
34717
|
+
status: "dismissed",
|
|
34718
|
+
method: disposition.method,
|
|
34719
|
+
resolvedAt: disposition.resolvedAt,
|
|
34720
|
+
evidence: disposition.evidence
|
|
34721
|
+
}))
|
|
34722
|
+
);
|
|
34723
|
+
dismissed = keys.length;
|
|
34724
|
+
},
|
|
34725
|
+
// IMMEDIATE takes the write lock at BEGIN, before the select, which is
|
|
34726
|
+
// what keeps a concurrent resolve out of the gap. It also makes waiting
|
|
34727
|
+
// on a busy writer an ordinary busy_timeout wait rather than a
|
|
34728
|
+
// read-to-write upgrade SQLite refuses to retry.
|
|
34729
|
+
"IMMEDIATE"
|
|
34730
|
+
);
|
|
34731
|
+
return dismissed;
|
|
34732
|
+
}
|
|
34611
34733
|
function recordCapture(event, detected) {
|
|
34612
34734
|
failOpenTransaction(db, () => {
|
|
34613
34735
|
const sessionId = event.metadata?.sessionId;
|
|
@@ -34791,6 +34913,7 @@ function openLocalDatabase(dir, options = {}) {
|
|
|
34791
34913
|
inspectionDefinitions,
|
|
34792
34914
|
inspectionFindings,
|
|
34793
34915
|
recordCapture,
|
|
34916
|
+
dismissOpenFindingsForRule,
|
|
34794
34917
|
markCaptureDelivered,
|
|
34795
34918
|
markCaptureOwed,
|
|
34796
34919
|
markAuditEventsDelivered,
|
|
@@ -35007,6 +35130,9 @@ function loadOrCreateFingerprintKey(dataDir2) {
|
|
|
35007
35130
|
});
|
|
35008
35131
|
}
|
|
35009
35132
|
function fingerprintValue(key, raw) {
|
|
35133
|
+
return exactFingerprintValue(key, stripInvisiblePadding(raw));
|
|
35134
|
+
}
|
|
35135
|
+
function exactFingerprintValue(key, raw) {
|
|
35010
35136
|
return createHmac("sha256", key.material).update(raw, "utf8").digest("hex");
|
|
35011
35137
|
}
|
|
35012
35138
|
|
|
@@ -35806,6 +35932,82 @@ function escapeRegExp2(value) {
|
|
|
35806
35932
|
return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
35807
35933
|
}
|
|
35808
35934
|
|
|
35935
|
+
// ../../packages/detections/src/format-chars.ts
|
|
35936
|
+
var HAS_FORMAT_CHAR = new RegExp("\\p{Cf}", "u");
|
|
35937
|
+
var FORMAT_CHAR_GLOBAL = new RegExp("\\p{Cf}", "gu");
|
|
35938
|
+
function normalizeFormatChars(text) {
|
|
35939
|
+
if (!HAS_FORMAT_CHAR.test(text)) return void 0;
|
|
35940
|
+
const normalizedParts = [];
|
|
35941
|
+
const segments = [];
|
|
35942
|
+
let cursor = 0;
|
|
35943
|
+
let normLength = 0;
|
|
35944
|
+
for (const match of text.matchAll(FORMAT_CHAR_GLOBAL)) {
|
|
35945
|
+
const matchStart = match.index;
|
|
35946
|
+
if (matchStart > cursor) {
|
|
35947
|
+
const length = matchStart - cursor;
|
|
35948
|
+
normalizedParts.push(text.slice(cursor, matchStart));
|
|
35949
|
+
segments.push({ normStart: normLength, origStart: cursor, length });
|
|
35950
|
+
normLength += length;
|
|
35951
|
+
}
|
|
35952
|
+
cursor = matchStart + match[0].length;
|
|
35953
|
+
}
|
|
35954
|
+
if (cursor < text.length) {
|
|
35955
|
+
const length = text.length - cursor;
|
|
35956
|
+
normalizedParts.push(text.slice(cursor));
|
|
35957
|
+
segments.push({ normStart: normLength, origStart: cursor, length });
|
|
35958
|
+
}
|
|
35959
|
+
return { normalized: normalizedParts.join(""), segments };
|
|
35960
|
+
}
|
|
35961
|
+
function segmentAt(segments, normPos) {
|
|
35962
|
+
let lo = 0;
|
|
35963
|
+
let hi = segments.length - 1;
|
|
35964
|
+
while (lo < hi) {
|
|
35965
|
+
const mid = lo + hi >> 1;
|
|
35966
|
+
const segment = segments[mid];
|
|
35967
|
+
if (segment !== void 0 && normPos >= segment.normStart + segment.length) {
|
|
35968
|
+
lo = mid + 1;
|
|
35969
|
+
} else {
|
|
35970
|
+
hi = mid;
|
|
35971
|
+
}
|
|
35972
|
+
}
|
|
35973
|
+
const found = segments[lo];
|
|
35974
|
+
if (found === void 0) {
|
|
35975
|
+
throw new Error(`normPos ${String(normPos)} has no covering segment`);
|
|
35976
|
+
}
|
|
35977
|
+
return found;
|
|
35978
|
+
}
|
|
35979
|
+
function mapSpanToOriginal(span, normalization) {
|
|
35980
|
+
const { segments } = normalization;
|
|
35981
|
+
const startSegment = segmentAt(segments, span.start);
|
|
35982
|
+
const start = startSegment.origStart + (span.start - startSegment.normStart);
|
|
35983
|
+
const endSegment = segmentAt(segments, span.end - 1);
|
|
35984
|
+
const end = endSegment.origStart + (span.end - 1 - endSegment.normStart) + 1;
|
|
35985
|
+
return { start, end };
|
|
35986
|
+
}
|
|
35987
|
+
function normalizedOffset(origPos, segments) {
|
|
35988
|
+
let lo = 0;
|
|
35989
|
+
let hi = segments.length;
|
|
35990
|
+
while (lo < hi) {
|
|
35991
|
+
const mid = lo + hi >> 1;
|
|
35992
|
+
const segment = segments[mid];
|
|
35993
|
+
if (segment !== void 0 && segment.origStart + segment.length <= origPos) {
|
|
35994
|
+
lo = mid + 1;
|
|
35995
|
+
} else {
|
|
35996
|
+
hi = mid;
|
|
35997
|
+
}
|
|
35998
|
+
}
|
|
35999
|
+
const found = segments[Math.min(lo, segments.length - 1)];
|
|
36000
|
+
if (found === void 0) return 0;
|
|
36001
|
+
return found.normStart + Math.min(Math.max(0, origPos - found.origStart), found.length);
|
|
36002
|
+
}
|
|
36003
|
+
function mapSpanToNormalized(span, normalization) {
|
|
36004
|
+
const { segments } = normalization;
|
|
36005
|
+
return {
|
|
36006
|
+
start: normalizedOffset(span.start, segments),
|
|
36007
|
+
end: normalizedOffset(span.end, segments)
|
|
36008
|
+
};
|
|
36009
|
+
}
|
|
36010
|
+
|
|
35809
36011
|
// ../../packages/detections/src/regex-cache.ts
|
|
35810
36012
|
var singles = /* @__PURE__ */ new WeakMap();
|
|
35811
36013
|
var keywordLists = /* @__PURE__ */ new WeakMap();
|
|
@@ -35967,29 +36169,35 @@ function registerPack(pack) {
|
|
|
35967
36169
|
function getLoadedRules() {
|
|
35968
36170
|
return [...packs.values()].flatMap((p) => p.rules);
|
|
35969
36171
|
}
|
|
35970
|
-
function
|
|
36172
|
+
function spansOverlap(a, b) {
|
|
36173
|
+
return a.start < b.end && a.end > b.start;
|
|
36174
|
+
}
|
|
36175
|
+
function isCorroborated(candidate, candidates, text, normalization) {
|
|
35971
36176
|
const req = candidate.rule.requiresNearby;
|
|
35972
36177
|
if (!req) return true;
|
|
35973
36178
|
const halfWindow = req.windowChars;
|
|
35974
|
-
const
|
|
35975
|
-
const winStart = start - halfWindow;
|
|
35976
|
-
const winEnd = end + halfWindow;
|
|
36179
|
+
const ns = candidate.normSpan;
|
|
36180
|
+
const winStart = ns.start - halfWindow;
|
|
36181
|
+
const winEnd = ns.end + halfWindow;
|
|
35977
36182
|
const categories = req.categories;
|
|
35978
36183
|
const ruleIds = req.ruleIds;
|
|
35979
36184
|
if (categories?.length || ruleIds?.length) {
|
|
35980
36185
|
for (const other of candidates) {
|
|
35981
36186
|
if (other === candidate) continue;
|
|
35982
|
-
|
|
35983
|
-
|
|
35984
|
-
if (
|
|
35985
|
-
|
|
36187
|
+
if (other.normSpan.end < winStart || other.normSpan.start > winEnd) continue;
|
|
36188
|
+
const relevant = other.match.ruleId !== candidate.match.ruleId && categories?.includes(other.match.category) === true || ruleIds?.includes(other.match.ruleId) === true;
|
|
36189
|
+
if (!relevant) continue;
|
|
36190
|
+
if (other.match.ruleId === candidate.match.ruleId && spansOverlap(other.match.span, candidate.match.span)) {
|
|
36191
|
+
continue;
|
|
35986
36192
|
}
|
|
35987
|
-
|
|
36193
|
+
return true;
|
|
35988
36194
|
}
|
|
35989
36195
|
}
|
|
35990
36196
|
const labels = req.labels;
|
|
35991
36197
|
if (labels && labels.length > 0) {
|
|
35992
|
-
const
|
|
36198
|
+
const { start, end } = candidate.match.span;
|
|
36199
|
+
const haystack = text.slice(Math.max(0, start - halfWindow), end + halfWindow);
|
|
36200
|
+
const normalizedHaystack = normalization === void 0 ? void 0 : normalization.normalized.slice(Math.max(0, winStart), winEnd);
|
|
35993
36201
|
for (const re of memoizedRegExpList(
|
|
35994
36202
|
"label",
|
|
35995
36203
|
req,
|
|
@@ -35998,29 +36206,20 @@ function isCorroborated(candidate, candidates, text) {
|
|
|
35998
36206
|
return trimmed.length === 0 ? void 0 : new RegExp(`(?<![A-Za-z0-9])${escapeRegExp2(trimmed)}(?![A-Za-z0-9])`, "i");
|
|
35999
36207
|
})
|
|
36000
36208
|
)) {
|
|
36001
|
-
if (re
|
|
36209
|
+
if (!re) continue;
|
|
36210
|
+
if (re.test(haystack)) return true;
|
|
36211
|
+
if (normalizedHaystack !== void 0 && re.test(normalizedHaystack)) return true;
|
|
36002
36212
|
}
|
|
36003
36213
|
}
|
|
36004
36214
|
return false;
|
|
36005
36215
|
}
|
|
36006
|
-
function
|
|
36007
|
-
const base = filePath.slice(Math.max(filePath.lastIndexOf("/"), filePath.lastIndexOf("\\")) + 1);
|
|
36008
|
-
const dot = base.lastIndexOf(".");
|
|
36009
|
-
return dot > 0 ? base.slice(dot).toLowerCase() : void 0;
|
|
36010
|
-
}
|
|
36011
|
-
function ruleApplies(rule, extension) {
|
|
36012
|
-
if (!rule.appliesTo || extension === void 0) return true;
|
|
36013
|
-
return rule.appliesTo.extensions.some((e) => e.toLowerCase() === extension);
|
|
36014
|
-
}
|
|
36015
|
-
function scan(text, rules, context) {
|
|
36016
|
-
const ruleset = rules ?? getLoadedRules();
|
|
36017
|
-
const extension = context?.filePath ? extensionOf(context.filePath) : void 0;
|
|
36216
|
+
function buildCandidates(matchText, ruleset, extension) {
|
|
36018
36217
|
const candidates = [];
|
|
36019
36218
|
for (const rule of ruleset) {
|
|
36020
36219
|
if (!ruleApplies(rule, extension)) continue;
|
|
36021
|
-
const spans = MATCHERS[rule.matcher.type](
|
|
36220
|
+
const spans = MATCHERS[rule.matcher.type](matchText, rule);
|
|
36022
36221
|
for (const span of spans) {
|
|
36023
|
-
const rawMatch =
|
|
36222
|
+
const rawMatch = matchText.slice(span.start, span.end);
|
|
36024
36223
|
if (!passesPostValidators(rule, rawMatch)) continue;
|
|
36025
36224
|
candidates.push({
|
|
36026
36225
|
rule,
|
|
@@ -36031,10 +36230,31 @@ function scan(text, rules, context) {
|
|
|
36031
36230
|
span,
|
|
36032
36231
|
rawMatch,
|
|
36033
36232
|
confidence: 0.9
|
|
36034
|
-
}
|
|
36233
|
+
},
|
|
36234
|
+
// In `matchText`'s own coordinates, which is the normalized text for
|
|
36235
|
+
// a normalized-pass candidate and so already right; an original-pass
|
|
36236
|
+
// candidate on the slow path is re-derived by withNormalizedSpan.
|
|
36237
|
+
normSpan: span
|
|
36035
36238
|
});
|
|
36036
36239
|
}
|
|
36037
36240
|
}
|
|
36241
|
+
return candidates;
|
|
36242
|
+
}
|
|
36243
|
+
function mapCandidateToOriginal(candidate, normalization, text) {
|
|
36244
|
+
const span = mapSpanToOriginal(candidate.match.span, normalization);
|
|
36245
|
+
return {
|
|
36246
|
+
rule: candidate.rule,
|
|
36247
|
+
match: { ...candidate.match, span, rawMatch: text.slice(span.start, span.end) },
|
|
36248
|
+
// Deliberately NOT remapped: `normSpan` is the span the primitive match
|
|
36249
|
+
// was found at in the normalized text, which is exactly the coordinate
|
|
36250
|
+
// space windows are measured in. See the `Candidate` comment.
|
|
36251
|
+
normSpan: candidate.normSpan
|
|
36252
|
+
};
|
|
36253
|
+
}
|
|
36254
|
+
function withNormalizedSpan(candidate, normalization) {
|
|
36255
|
+
return { ...candidate, normSpan: mapSpanToNormalized(candidate.match.span, normalization) };
|
|
36256
|
+
}
|
|
36257
|
+
function gate(candidates, text, normalization) {
|
|
36038
36258
|
const findings = [];
|
|
36039
36259
|
for (const candidate of candidates) {
|
|
36040
36260
|
const req = candidate.rule.requiresNearby;
|
|
@@ -36042,7 +36262,7 @@ function scan(text, rules, context) {
|
|
|
36042
36262
|
findings.push(candidate.match);
|
|
36043
36263
|
continue;
|
|
36044
36264
|
}
|
|
36045
|
-
if (!isCorroborated(candidate, candidates, text)) continue;
|
|
36265
|
+
if (!isCorroborated(candidate, candidates, text, normalization)) continue;
|
|
36046
36266
|
const boost = req.confidenceBoost;
|
|
36047
36267
|
findings.push(
|
|
36048
36268
|
boost ? { ...candidate.match, confidence: Math.min(0.99, candidate.match.confidence + boost) } : candidate.match
|
|
@@ -36050,6 +36270,81 @@ function scan(text, rules, context) {
|
|
|
36050
36270
|
}
|
|
36051
36271
|
return findings;
|
|
36052
36272
|
}
|
|
36273
|
+
function closeRegion(open3, text) {
|
|
36274
|
+
const span = { start: open3.start, end: open3.end };
|
|
36275
|
+
return {
|
|
36276
|
+
ruleId: open3.ruleId,
|
|
36277
|
+
category: open3.category,
|
|
36278
|
+
severity: open3.severity,
|
|
36279
|
+
span,
|
|
36280
|
+
rawMatch: text.slice(span.start, span.end),
|
|
36281
|
+
confidence: open3.confidence
|
|
36282
|
+
};
|
|
36283
|
+
}
|
|
36284
|
+
function mergeOverlappingSameRule(findings, text) {
|
|
36285
|
+
if (findings.length === 0) return findings;
|
|
36286
|
+
const groups = /* @__PURE__ */ new Map();
|
|
36287
|
+
const ruleOrder = [];
|
|
36288
|
+
for (const finding of findings) {
|
|
36289
|
+
const group = groups.get(finding.ruleId);
|
|
36290
|
+
if (group) {
|
|
36291
|
+
group.push(finding);
|
|
36292
|
+
} else {
|
|
36293
|
+
groups.set(finding.ruleId, [finding]);
|
|
36294
|
+
ruleOrder.push(finding.ruleId);
|
|
36295
|
+
}
|
|
36296
|
+
}
|
|
36297
|
+
const merged = [];
|
|
36298
|
+
for (const ruleId of ruleOrder) {
|
|
36299
|
+
const group = groups.get(ruleId) ?? [];
|
|
36300
|
+
const sorted = [...group].sort(
|
|
36301
|
+
(a, b) => a.span.start - b.span.start || a.span.end - b.span.end
|
|
36302
|
+
);
|
|
36303
|
+
let open3;
|
|
36304
|
+
for (const finding of sorted) {
|
|
36305
|
+
if (open3 && finding.span.start < open3.end) {
|
|
36306
|
+
open3.end = Math.max(open3.end, finding.span.end);
|
|
36307
|
+
open3.confidence = Math.max(open3.confidence, finding.confidence);
|
|
36308
|
+
continue;
|
|
36309
|
+
}
|
|
36310
|
+
if (open3) merged.push(closeRegion(open3, text));
|
|
36311
|
+
open3 = {
|
|
36312
|
+
start: finding.span.start,
|
|
36313
|
+
end: finding.span.end,
|
|
36314
|
+
confidence: finding.confidence,
|
|
36315
|
+
ruleId: finding.ruleId,
|
|
36316
|
+
category: finding.category,
|
|
36317
|
+
severity: finding.severity
|
|
36318
|
+
};
|
|
36319
|
+
}
|
|
36320
|
+
if (open3) merged.push(closeRegion(open3, text));
|
|
36321
|
+
}
|
|
36322
|
+
return merged;
|
|
36323
|
+
}
|
|
36324
|
+
function extensionOf(filePath) {
|
|
36325
|
+
const base = filePath.slice(Math.max(filePath.lastIndexOf("/"), filePath.lastIndexOf("\\")) + 1);
|
|
36326
|
+
const dot = base.lastIndexOf(".");
|
|
36327
|
+
return dot > 0 ? base.slice(dot).toLowerCase() : void 0;
|
|
36328
|
+
}
|
|
36329
|
+
function ruleApplies(rule, extension) {
|
|
36330
|
+
if (!rule.appliesTo || extension === void 0) return true;
|
|
36331
|
+
return rule.appliesTo.extensions.some((e) => e.toLowerCase() === extension);
|
|
36332
|
+
}
|
|
36333
|
+
function scan(text, rules, context) {
|
|
36334
|
+
const ruleset = rules ?? getLoadedRules();
|
|
36335
|
+
const extension = context?.filePath ? extensionOf(context.filePath) : void 0;
|
|
36336
|
+
const normalization = normalizeFormatChars(text);
|
|
36337
|
+
const originalCandidates = buildCandidates(text, ruleset, extension);
|
|
36338
|
+
if (!normalization) return gate(originalCandidates, text, void 0);
|
|
36339
|
+
const pooledOriginal = originalCandidates.map(
|
|
36340
|
+
(candidate) => withNormalizedSpan(candidate, normalization)
|
|
36341
|
+
);
|
|
36342
|
+
const normalizedCandidates = buildCandidates(normalization.normalized, ruleset, extension).map(
|
|
36343
|
+
(candidate) => mapCandidateToOriginal(candidate, normalization, text)
|
|
36344
|
+
);
|
|
36345
|
+
const findings = gate([...pooledOriginal, ...normalizedCandidates], text, normalization);
|
|
36346
|
+
return mergeOverlappingSameRule(findings, text);
|
|
36347
|
+
}
|
|
36053
36348
|
var SEVERITY_RANK2 = {
|
|
36054
36349
|
critical: 3,
|
|
36055
36350
|
high: 2,
|
|
@@ -38681,8 +38976,8 @@ function createIsolatedScanner(data, opts = {}) {
|
|
|
38681
38976
|
}
|
|
38682
38977
|
function enqueue(spec) {
|
|
38683
38978
|
const next = chain.then(
|
|
38684
|
-
() => new Promise((
|
|
38685
|
-
spec(
|
|
38979
|
+
() => new Promise((resolve3) => {
|
|
38980
|
+
spec(resolve3);
|
|
38686
38981
|
})
|
|
38687
38982
|
);
|
|
38688
38983
|
chain = next.then(
|
|
@@ -38693,7 +38988,7 @@ function createIsolatedScanner(data, opts = {}) {
|
|
|
38693
38988
|
}
|
|
38694
38989
|
return {
|
|
38695
38990
|
scan(text, context, scanOpts) {
|
|
38696
|
-
return enqueue((
|
|
38991
|
+
return enqueue((resolve3) => {
|
|
38697
38992
|
runOne(
|
|
38698
38993
|
{
|
|
38699
38994
|
budgetMs,
|
|
@@ -38706,23 +39001,23 @@ function createIsolatedScanner(data, opts = {}) {
|
|
|
38706
39001
|
}),
|
|
38707
39002
|
reply: (message) => {
|
|
38708
39003
|
if (message.kind !== "result") return false;
|
|
38709
|
-
|
|
39004
|
+
resolve3({ status: "ok", findings: message.findings });
|
|
38710
39005
|
return true;
|
|
38711
39006
|
}
|
|
38712
39007
|
},
|
|
38713
|
-
|
|
39008
|
+
resolve3
|
|
38714
39009
|
);
|
|
38715
39010
|
});
|
|
38716
39011
|
},
|
|
38717
39012
|
probe(rule) {
|
|
38718
|
-
return enqueue((
|
|
39013
|
+
return enqueue((resolve3) => {
|
|
38719
39014
|
runOne(
|
|
38720
39015
|
{
|
|
38721
39016
|
budgetMs: probeBudgetMs,
|
|
38722
39017
|
build: (id) => ({ kind: "probe", id, rule }),
|
|
38723
39018
|
reply: (message) => {
|
|
38724
39019
|
if (message.kind !== "probed") return false;
|
|
38725
|
-
|
|
39020
|
+
resolve3({
|
|
38726
39021
|
status: "ok",
|
|
38727
39022
|
verdict: message.verdict,
|
|
38728
39023
|
worstMs: message.worstMs,
|
|
@@ -38731,7 +39026,7 @@ function createIsolatedScanner(data, opts = {}) {
|
|
|
38731
39026
|
return true;
|
|
38732
39027
|
}
|
|
38733
39028
|
},
|
|
38734
|
-
|
|
39029
|
+
resolve3
|
|
38735
39030
|
);
|
|
38736
39031
|
});
|
|
38737
39032
|
},
|
|
@@ -38962,6 +39257,40 @@ function createGuardedScanner(partition, gateway, opts) {
|
|
|
38962
39257
|
// ../../packages/plugin-sdk/src/hook-fail-opens.ts
|
|
38963
39258
|
import { readFileSync as readFileSync12 } from "fs";
|
|
38964
39259
|
import { join as join19 } from "path";
|
|
39260
|
+
var HOOK_FAIL_OPENS_FILENAME = "hook-fail-opens.json";
|
|
39261
|
+
function hookFailOpensPath(dataDir2) {
|
|
39262
|
+
return join19(dataDir2, HOOK_FAIL_OPENS_FILENAME);
|
|
39263
|
+
}
|
|
39264
|
+
function recordHookFailOpen(dataDir2, nowMs) {
|
|
39265
|
+
try {
|
|
39266
|
+
ensureDataDirSync(dataDir2);
|
|
39267
|
+
const previous = readHookFailOpens(dataDir2);
|
|
39268
|
+
const next = {
|
|
39269
|
+
// Saturates at the largest count the reader accepts: one past it would
|
|
39270
|
+
// read back as nothing recorded and restart the tally from one.
|
|
39271
|
+
failOpens: Math.min((previous?.failOpens ?? 0) + 1, Number.MAX_SAFE_INTEGER),
|
|
39272
|
+
lastAtMs: nowMs
|
|
39273
|
+
};
|
|
39274
|
+
writeOwnerOnlyFileSync(hookFailOpensPath(dataDir2), `${JSON.stringify(next)}
|
|
39275
|
+
`);
|
|
39276
|
+
} catch {
|
|
39277
|
+
}
|
|
39278
|
+
}
|
|
39279
|
+
function readHookFailOpens(dataDir2) {
|
|
39280
|
+
try {
|
|
39281
|
+
const parsed2 = JSON.parse(readFileSync12(hookFailOpensPath(dataDir2), "utf8"));
|
|
39282
|
+
if (typeof parsed2 !== "object" || parsed2 === null) return null;
|
|
39283
|
+
const record2 = parsed2;
|
|
39284
|
+
if (!isPositiveSafeInteger(record2.failOpens)) return null;
|
|
39285
|
+
if (!isPositiveSafeInteger(record2.lastAtMs)) return null;
|
|
39286
|
+
return { failOpens: record2.failOpens, lastAtMs: record2.lastAtMs };
|
|
39287
|
+
} catch {
|
|
39288
|
+
return null;
|
|
39289
|
+
}
|
|
39290
|
+
}
|
|
39291
|
+
function isPositiveSafeInteger(value) {
|
|
39292
|
+
return typeof value === "number" && Number.isSafeInteger(value) && value > 0;
|
|
39293
|
+
}
|
|
38965
39294
|
|
|
38966
39295
|
// ../../packages/plugin-sdk/src/host-floor.ts
|
|
38967
39296
|
import { readFileSync as readFileSync14 } from "fs";
|
|
@@ -39604,7 +39933,7 @@ function decidePreToolUse(toolName, toolInput, scanned) {
|
|
|
39604
39933
|
|
|
39605
39934
|
// src/hooks/shared.ts
|
|
39606
39935
|
async function readStdin() {
|
|
39607
|
-
return new Promise((
|
|
39936
|
+
return new Promise((resolve3) => {
|
|
39608
39937
|
let data = "";
|
|
39609
39938
|
let settled = false;
|
|
39610
39939
|
const finish = () => {
|
|
@@ -39613,7 +39942,7 @@ async function readStdin() {
|
|
|
39613
39942
|
clearTimeout(timer);
|
|
39614
39943
|
process.stdin.removeListener("data", onData);
|
|
39615
39944
|
process.stdin.removeListener("end", finish);
|
|
39616
|
-
|
|
39945
|
+
resolve3(data);
|
|
39617
39946
|
};
|
|
39618
39947
|
const onData = (chunk) => {
|
|
39619
39948
|
data += chunk;
|
|
@@ -39638,12 +39967,12 @@ function getString(record2, key) {
|
|
|
39638
39967
|
return typeof value === "string" ? value : void 0;
|
|
39639
39968
|
}
|
|
39640
39969
|
function emit(output2) {
|
|
39641
|
-
return new Promise((
|
|
39970
|
+
return new Promise((resolve3) => {
|
|
39642
39971
|
let settled = false;
|
|
39643
39972
|
const finish = () => {
|
|
39644
39973
|
if (settled) return;
|
|
39645
39974
|
settled = true;
|
|
39646
|
-
|
|
39975
|
+
resolve3();
|
|
39647
39976
|
};
|
|
39648
39977
|
process.stdout.on("error", finish);
|
|
39649
39978
|
process.stdout.write(JSON.stringify(output2), finish);
|
|
@@ -39657,10 +39986,16 @@ function baseMetadata(input2) {
|
|
|
39657
39986
|
if (repo) metadata.repo = repo;
|
|
39658
39987
|
return Object.keys(metadata).length > 0 ? metadata : void 0;
|
|
39659
39988
|
}
|
|
39989
|
+
function countFailOpen(base) {
|
|
39990
|
+
try {
|
|
39991
|
+
recordHookFailOpen(dataDir(base), Date.now());
|
|
39992
|
+
} catch {
|
|
39993
|
+
}
|
|
39994
|
+
}
|
|
39660
39995
|
|
|
39661
39996
|
// src/hooks/store-health.ts
|
|
39662
39997
|
import { mkdirSync as mkdirSync5, readFileSync as readFileSync21, writeFileSync as writeFileSync8 } from "fs";
|
|
39663
|
-
import { dirname as
|
|
39998
|
+
import { dirname as dirname7, join as join33 } from "path";
|
|
39664
39999
|
|
|
39665
40000
|
// ../../packages/remote/src/http.ts
|
|
39666
40001
|
import { request as httpRequest } from "http";
|
|
@@ -39756,7 +40091,7 @@ async function send(options) {
|
|
|
39756
40091
|
}
|
|
39757
40092
|
}
|
|
39758
40093
|
};
|
|
39759
|
-
return new Promise((
|
|
40094
|
+
return new Promise((resolve3, reject) => {
|
|
39760
40095
|
let settled = false;
|
|
39761
40096
|
const fail = (reason, status) => {
|
|
39762
40097
|
if (settled) return;
|
|
@@ -39782,7 +40117,7 @@ async function send(options) {
|
|
|
39782
40117
|
res.on("end", () => {
|
|
39783
40118
|
if (settled) return;
|
|
39784
40119
|
settled = true;
|
|
39785
|
-
|
|
40120
|
+
resolve3({
|
|
39786
40121
|
status: res.statusCode ?? 0,
|
|
39787
40122
|
headers: res.headers,
|
|
39788
40123
|
body: Buffer.concat(chunks).toString("utf8")
|
|
@@ -40778,10 +41113,55 @@ import { spawn } from "child_process";
|
|
|
40778
41113
|
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
40779
41114
|
var HISTORY_SYNC_THROTTLE_MS = 5 * 60 * 1e3;
|
|
40780
41115
|
|
|
41116
|
+
// ../../packages/plugin-runtime/src/attached/install-record.ts
|
|
41117
|
+
import { readFile as readFile2, stat } from "fs/promises";
|
|
41118
|
+
import { basename as basename6, dirname as dirname6, join as join28, resolve as resolve2 } from "path";
|
|
41119
|
+
async function readInstalledVersion(installRoot) {
|
|
41120
|
+
try {
|
|
41121
|
+
const versionDir = resolve2(installRoot);
|
|
41122
|
+
const pluginDir = dirname6(versionDir);
|
|
41123
|
+
const marketplaceDir = dirname6(pluginDir);
|
|
41124
|
+
const cacheDir = dirname6(marketplaceDir);
|
|
41125
|
+
if (basename6(cacheDir) !== "cache") return null;
|
|
41126
|
+
const key = `${basename6(pluginDir)}@${basename6(marketplaceDir)}`;
|
|
41127
|
+
const record2 = JSON.parse(
|
|
41128
|
+
await readFile2(join28(dirname6(cacheDir), "installed_plugins.json"), "utf8")
|
|
41129
|
+
);
|
|
41130
|
+
const plugins = record2?.plugins;
|
|
41131
|
+
if (typeof plugins !== "object" || plugins === null || !Object.hasOwn(plugins, key)) {
|
|
41132
|
+
return null;
|
|
41133
|
+
}
|
|
41134
|
+
const entries = plugins[key];
|
|
41135
|
+
if (!Array.isArray(entries)) return null;
|
|
41136
|
+
let newest = null;
|
|
41137
|
+
for (const entry of entries) {
|
|
41138
|
+
const { version: version2, installPath } = entry ?? {};
|
|
41139
|
+
if (typeof version2 !== "string" || !isParseableBinaryVersion(version2)) continue;
|
|
41140
|
+
if (!StorePosturePlugin.shape.installedVersion.safeParse(version2).success) continue;
|
|
41141
|
+
if (newest !== null && compareBinaryVersions(version2, newest) <= 0) continue;
|
|
41142
|
+
if (typeof installPath === "string" && !await exists(installPath)) continue;
|
|
41143
|
+
newest = version2;
|
|
41144
|
+
}
|
|
41145
|
+
return newest;
|
|
41146
|
+
} catch {
|
|
41147
|
+
return null;
|
|
41148
|
+
}
|
|
41149
|
+
}
|
|
41150
|
+
async function exists(path) {
|
|
41151
|
+
try {
|
|
41152
|
+
await stat(path);
|
|
41153
|
+
return true;
|
|
41154
|
+
} catch {
|
|
41155
|
+
return false;
|
|
41156
|
+
}
|
|
41157
|
+
}
|
|
41158
|
+
|
|
40781
41159
|
// ../../packages/plugin-runtime/src/attached/plugin-block.ts
|
|
40782
41160
|
import { readFileSync as readFileSync18 } from "fs";
|
|
41161
|
+
var INSTALL_RECORD_READ_TIMEOUT_MS = REQUEST_TIMEOUT_MS / 2;
|
|
40783
41162
|
function createPluginBlock(build, policyStore) {
|
|
40784
41163
|
return async () => {
|
|
41164
|
+
const installed = build.installRoot === void 0 ? void 0 : readInstalledVersionBounded(build.installRoot);
|
|
40785
41165
|
const cached2 = await policyStore.read();
|
|
40786
41166
|
const fetchedAtMs = cached2?.fetchedAtMs;
|
|
40787
41167
|
const block = {
|
|
@@ -40789,16 +41169,25 @@ function createPluginBlock(build, policyStore) {
|
|
|
40789
41169
|
version: build.version,
|
|
40790
41170
|
ossVersion: build.ossVersion ?? null,
|
|
40791
41171
|
policyBundleVersion: cached2 !== null && StorePosturePlugin.shape.policyBundleVersion.safeParse(cached2.bundle.version).success ? cached2.bundle.version : null,
|
|
40792
|
-
policyFetchedAt: fetchedAtMs !== void 0 && fetchedAtMs > 0 && StorePosturePlugin.shape.policyFetchedAt.safeParse(fetchedAtMs).success ? fetchedAtMs : null
|
|
41172
|
+
policyFetchedAt: fetchedAtMs !== void 0 && fetchedAtMs > 0 && StorePosturePlugin.shape.policyFetchedAt.safeParse(fetchedAtMs).success ? fetchedAtMs : null,
|
|
41173
|
+
...installed === void 0 ? {} : { installedVersion: await installed },
|
|
41174
|
+
buildSchemaVersion: SQLITE_MIGRATIONS.length
|
|
40793
41175
|
};
|
|
40794
41176
|
return StorePosturePlugin.safeParse(block).success ? block : void 0;
|
|
40795
41177
|
};
|
|
40796
41178
|
}
|
|
41179
|
+
async function readInstalledVersionBounded(installRoot) {
|
|
41180
|
+
try {
|
|
41181
|
+
return await withTimeout(readInstalledVersion(installRoot), INSTALL_RECORD_READ_TIMEOUT_MS);
|
|
41182
|
+
} catch {
|
|
41183
|
+
return null;
|
|
41184
|
+
}
|
|
41185
|
+
}
|
|
40797
41186
|
|
|
40798
41187
|
// ../../packages/plugin-runtime/src/attached/policy-store.ts
|
|
40799
41188
|
import { randomUUID as randomUUID16 } from "crypto";
|
|
40800
|
-
import { readFile as
|
|
40801
|
-
import { join as
|
|
41189
|
+
import { readFile as readFile3, rm, writeFile as writeFile2 } from "fs/promises";
|
|
41190
|
+
import { join as join29 } from "path";
|
|
40802
41191
|
|
|
40803
41192
|
// ../../packages/plugin-runtime/src/attached/atomic-publish.ts
|
|
40804
41193
|
import { rename as rename2 } from "fs/promises";
|
|
@@ -40806,11 +41195,11 @@ var RETRYABLE = /* @__PURE__ */ new Set(["EPERM", "EACCES", "EBUSY"]);
|
|
|
40806
41195
|
var IMMEDIATE_RETRIES = 8;
|
|
40807
41196
|
var TIMED_RETRIES = 4;
|
|
40808
41197
|
var ATTEMPTS = 1 + IMMEDIATE_RETRIES + TIMED_RETRIES;
|
|
40809
|
-
var delay = (ms) => new Promise((
|
|
40810
|
-
setTimeout(
|
|
41198
|
+
var delay = (ms) => new Promise((resolve3) => {
|
|
41199
|
+
setTimeout(resolve3, ms);
|
|
40811
41200
|
});
|
|
40812
|
-
var yieldToLoop = () => new Promise((
|
|
40813
|
-
setImmediate(
|
|
41201
|
+
var yieldToLoop = () => new Promise((resolve3) => {
|
|
41202
|
+
setImmediate(resolve3);
|
|
40814
41203
|
});
|
|
40815
41204
|
async function publishByRename(tmp, file2, move = rename2) {
|
|
40816
41205
|
for (let attempt = 1; ; attempt += 1) {
|
|
@@ -40827,10 +41216,10 @@ async function publishByRename(tmp, file2, move = rename2) {
|
|
|
40827
41216
|
|
|
40828
41217
|
// ../../packages/plugin-runtime/src/attached/policy-store.ts
|
|
40829
41218
|
function createPolicyStore(dir = dataDir()) {
|
|
40830
|
-
const file2 =
|
|
41219
|
+
const file2 = join29(dir, "policy-cache.json");
|
|
40831
41220
|
async function read() {
|
|
40832
41221
|
try {
|
|
40833
|
-
const raw = await
|
|
41222
|
+
const raw = await readFile3(file2, "utf8");
|
|
40834
41223
|
const parsed2 = JSON.parse(raw);
|
|
40835
41224
|
if (typeof parsed2 !== "object" || parsed2 === null) return null;
|
|
40836
41225
|
const record2 = parsed2;
|
|
@@ -40852,7 +41241,7 @@ function createPolicyStore(dir = dataDir()) {
|
|
|
40852
41241
|
}
|
|
40853
41242
|
async function priorRecord() {
|
|
40854
41243
|
try {
|
|
40855
|
-
const parsed2 = JSON.parse(await
|
|
41244
|
+
const parsed2 = JSON.parse(await readFile3(file2, "utf8"));
|
|
40856
41245
|
return typeof parsed2 === "object" && parsed2 !== null ? parsed2 : null;
|
|
40857
41246
|
} catch {
|
|
40858
41247
|
return null;
|
|
@@ -40898,7 +41287,7 @@ function createPolicyStore(dir = dataDir()) {
|
|
|
40898
41287
|
|
|
40899
41288
|
// ../../packages/plugin-runtime/src/attached/posture-report-state.ts
|
|
40900
41289
|
import { readFileSync as readFileSync19 } from "fs";
|
|
40901
|
-
import { join as
|
|
41290
|
+
import { join as join30 } from "path";
|
|
40902
41291
|
var POSTURE_REPORT_STATE_FILENAME = ATTACHED_POSTURE_REPORT_FILENAME;
|
|
40903
41292
|
var OUTCOME_KEYS = {
|
|
40904
41293
|
ok: true,
|
|
@@ -40912,7 +41301,7 @@ var OUTCOME_KEYS = {
|
|
|
40912
41301
|
};
|
|
40913
41302
|
var OUTCOMES = new Set(Object.keys(OUTCOME_KEYS));
|
|
40914
41303
|
function postureReportStatePath(dataDir2) {
|
|
40915
|
-
return
|
|
41304
|
+
return join30(dataDir2, POSTURE_REPORT_STATE_FILENAME);
|
|
40916
41305
|
}
|
|
40917
41306
|
function writePostureReportState(dataDir2, state) {
|
|
40918
41307
|
try {
|
|
@@ -41091,12 +41480,12 @@ function readStorePosture(dbPath2) {
|
|
|
41091
41480
|
|
|
41092
41481
|
// ../../packages/plugin-runtime/src/attached/posture-store.ts
|
|
41093
41482
|
import { randomUUID as randomUUID17 } from "crypto";
|
|
41094
|
-
import { readFile as
|
|
41095
|
-
import { join as
|
|
41483
|
+
import { readFile as readFile4, rm as rm2, writeFile as writeFile3 } from "fs/promises";
|
|
41484
|
+
import { join as join31 } from "path";
|
|
41096
41485
|
var UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/;
|
|
41097
41486
|
function createPostureStore(dir = settingsDir(), legacyDir) {
|
|
41098
|
-
const file2 =
|
|
41099
|
-
const legacyFile = legacyDir === void 0 ? null :
|
|
41487
|
+
const file2 = join31(dir, "posture-state.json");
|
|
41488
|
+
const legacyFile = legacyDir === void 0 ? null : join31(legacyDir, "posture-state.json");
|
|
41100
41489
|
async function persist(state) {
|
|
41101
41490
|
await ensureDataDir(dir);
|
|
41102
41491
|
const tmp = `${file2}.${randomUUID17()}.tmp`;
|
|
@@ -41111,7 +41500,7 @@ function createPostureStore(dir = settingsDir(), legacyDir) {
|
|
|
41111
41500
|
async function readFrom(path) {
|
|
41112
41501
|
let raw;
|
|
41113
41502
|
try {
|
|
41114
|
-
raw = await
|
|
41503
|
+
raw = await readFile4(path, "utf8");
|
|
41115
41504
|
} catch (err) {
|
|
41116
41505
|
const code = err.code;
|
|
41117
41506
|
if (code === "ENOENT" || code === "ENOTDIR") return null;
|
|
@@ -41165,7 +41554,7 @@ function createPostureStore(dir = settingsDir(), legacyDir) {
|
|
|
41165
41554
|
|
|
41166
41555
|
// ../../packages/plugin-runtime/src/attached/sync-state.ts
|
|
41167
41556
|
import { readFileSync as readFileSync20 } from "fs";
|
|
41168
|
-
import { join as
|
|
41557
|
+
import { join as join32 } from "path";
|
|
41169
41558
|
|
|
41170
41559
|
// ../../packages/plugin-runtime/src/attached/status.ts
|
|
41171
41560
|
var REFUSAL_LINES = {
|
|
@@ -41242,12 +41631,12 @@ var StandaloneDataGateway = class {
|
|
|
41242
41631
|
// reconciler drops the whole pass and recovers it idempotently on the next read.
|
|
41243
41632
|
recordLlmCalls(inputs) {
|
|
41244
41633
|
if (inputs.length === 0) return Promise.resolve();
|
|
41245
|
-
return new Promise((
|
|
41634
|
+
return new Promise((resolve3, reject) => {
|
|
41246
41635
|
try {
|
|
41247
41636
|
this.db.auditEvents.runInTransaction(() => {
|
|
41248
41637
|
for (const input2 of inputs) this.db.auditEvents.insertLlmCall(input2);
|
|
41249
41638
|
});
|
|
41250
|
-
|
|
41639
|
+
resolve3();
|
|
41251
41640
|
} catch (err) {
|
|
41252
41641
|
reject(err instanceof Error ? err : new Error(String(err)));
|
|
41253
41642
|
}
|
|
@@ -41259,12 +41648,12 @@ var StandaloneDataGateway = class {
|
|
|
41259
41648
|
// drops the whole pass and recovers it idempotently next time.
|
|
41260
41649
|
recordToolCalls(inputs) {
|
|
41261
41650
|
if (inputs.length === 0) return Promise.resolve();
|
|
41262
|
-
return new Promise((
|
|
41651
|
+
return new Promise((resolve3, reject) => {
|
|
41263
41652
|
try {
|
|
41264
41653
|
this.db.auditEvents.runInTransaction(() => {
|
|
41265
41654
|
for (const input2 of inputs) this.writeToolCall(input2);
|
|
41266
41655
|
});
|
|
41267
|
-
|
|
41656
|
+
resolve3();
|
|
41268
41657
|
} catch (err) {
|
|
41269
41658
|
reject(err instanceof Error ? err : new Error(String(err)));
|
|
41270
41659
|
}
|
|
@@ -41685,12 +42074,12 @@ function claimStoreUnavailableWarning(dataDir2, sessionId) {
|
|
|
41685
42074
|
return true;
|
|
41686
42075
|
}
|
|
41687
42076
|
function markerDirs(dataDir2) {
|
|
41688
|
-
return [dataDir2,
|
|
42077
|
+
return [dataDir2, dirname7(dataDir2)];
|
|
41689
42078
|
}
|
|
41690
42079
|
function alreadyClaimed(dirs, marker, sessionId) {
|
|
41691
42080
|
return dirs.some((dir) => {
|
|
41692
42081
|
try {
|
|
41693
|
-
return readFileSync21(
|
|
42082
|
+
return readFileSync21(join33(dir, marker), "utf8") === sessionId;
|
|
41694
42083
|
} catch {
|
|
41695
42084
|
return false;
|
|
41696
42085
|
}
|
|
@@ -41700,7 +42089,7 @@ function recordClaim(dirs, marker, sessionId) {
|
|
|
41700
42089
|
for (const dir of dirs) {
|
|
41701
42090
|
try {
|
|
41702
42091
|
mkdirSync5(dir, { recursive: true, mode: DATA_DIR_MODE });
|
|
41703
|
-
writeFileSync8(
|
|
42092
|
+
writeFileSync8(join33(dir, marker), sessionId, { mode: DATA_FILE_MODE });
|
|
41704
42093
|
return;
|
|
41705
42094
|
} catch {
|
|
41706
42095
|
}
|
|
@@ -41725,7 +42114,7 @@ function formatMode(mode) {
|
|
|
41725
42114
|
}
|
|
41726
42115
|
function warnIfStoreRedirected(config2, sessionId, write = (message) => void process.stderr.write(message)) {
|
|
41727
42116
|
try {
|
|
41728
|
-
const paths = symlinkedStorePaths(
|
|
42117
|
+
const paths = symlinkedStorePaths(dirname7(config2.dataDir));
|
|
41729
42118
|
if (paths.length === 0) return;
|
|
41730
42119
|
if (!sessionId) {
|
|
41731
42120
|
write(storeRedirectedMessage(paths));
|
|
@@ -41801,5 +42190,6 @@ async function main() {
|
|
|
41801
42190
|
try {
|
|
41802
42191
|
await main();
|
|
41803
42192
|
} catch {
|
|
42193
|
+
countFailOpen();
|
|
41804
42194
|
}
|
|
41805
42195
|
process.exit(0);
|