@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
|
@@ -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,
|
|
@@ -38684,8 +38979,8 @@ function createIsolatedScanner(data, opts = {}) {
|
|
|
38684
38979
|
}
|
|
38685
38980
|
function enqueue(spec) {
|
|
38686
38981
|
const next = chain.then(
|
|
38687
|
-
() => new Promise((
|
|
38688
|
-
spec(
|
|
38982
|
+
() => new Promise((resolve3) => {
|
|
38983
|
+
spec(resolve3);
|
|
38689
38984
|
})
|
|
38690
38985
|
);
|
|
38691
38986
|
chain = next.then(
|
|
@@ -38696,7 +38991,7 @@ function createIsolatedScanner(data, opts = {}) {
|
|
|
38696
38991
|
}
|
|
38697
38992
|
return {
|
|
38698
38993
|
scan(text, context, scanOpts) {
|
|
38699
|
-
return enqueue((
|
|
38994
|
+
return enqueue((resolve3) => {
|
|
38700
38995
|
runOne(
|
|
38701
38996
|
{
|
|
38702
38997
|
budgetMs,
|
|
@@ -38709,23 +39004,23 @@ function createIsolatedScanner(data, opts = {}) {
|
|
|
38709
39004
|
}),
|
|
38710
39005
|
reply: (message) => {
|
|
38711
39006
|
if (message.kind !== "result") return false;
|
|
38712
|
-
|
|
39007
|
+
resolve3({ status: "ok", findings: message.findings });
|
|
38713
39008
|
return true;
|
|
38714
39009
|
}
|
|
38715
39010
|
},
|
|
38716
|
-
|
|
39011
|
+
resolve3
|
|
38717
39012
|
);
|
|
38718
39013
|
});
|
|
38719
39014
|
},
|
|
38720
39015
|
probe(rule) {
|
|
38721
|
-
return enqueue((
|
|
39016
|
+
return enqueue((resolve3) => {
|
|
38722
39017
|
runOne(
|
|
38723
39018
|
{
|
|
38724
39019
|
budgetMs: probeBudgetMs,
|
|
38725
39020
|
build: (id) => ({ kind: "probe", id, rule }),
|
|
38726
39021
|
reply: (message) => {
|
|
38727
39022
|
if (message.kind !== "probed") return false;
|
|
38728
|
-
|
|
39023
|
+
resolve3({
|
|
38729
39024
|
status: "ok",
|
|
38730
39025
|
verdict: message.verdict,
|
|
38731
39026
|
worstMs: message.worstMs,
|
|
@@ -38734,7 +39029,7 @@ function createIsolatedScanner(data, opts = {}) {
|
|
|
38734
39029
|
return true;
|
|
38735
39030
|
}
|
|
38736
39031
|
},
|
|
38737
|
-
|
|
39032
|
+
resolve3
|
|
38738
39033
|
);
|
|
38739
39034
|
});
|
|
38740
39035
|
},
|
|
@@ -38965,6 +39260,40 @@ function createGuardedScanner(partition, gateway, opts) {
|
|
|
38965
39260
|
// ../../packages/plugin-sdk/src/hook-fail-opens.ts
|
|
38966
39261
|
import { readFileSync as readFileSync12 } from "fs";
|
|
38967
39262
|
import { join as join19 } from "path";
|
|
39263
|
+
var HOOK_FAIL_OPENS_FILENAME = "hook-fail-opens.json";
|
|
39264
|
+
function hookFailOpensPath(dataDir2) {
|
|
39265
|
+
return join19(dataDir2, HOOK_FAIL_OPENS_FILENAME);
|
|
39266
|
+
}
|
|
39267
|
+
function recordHookFailOpen(dataDir2, nowMs) {
|
|
39268
|
+
try {
|
|
39269
|
+
ensureDataDirSync(dataDir2);
|
|
39270
|
+
const previous = readHookFailOpens(dataDir2);
|
|
39271
|
+
const next = {
|
|
39272
|
+
// Saturates at the largest count the reader accepts: one past it would
|
|
39273
|
+
// read back as nothing recorded and restart the tally from one.
|
|
39274
|
+
failOpens: Math.min((previous?.failOpens ?? 0) + 1, Number.MAX_SAFE_INTEGER),
|
|
39275
|
+
lastAtMs: nowMs
|
|
39276
|
+
};
|
|
39277
|
+
writeOwnerOnlyFileSync(hookFailOpensPath(dataDir2), `${JSON.stringify(next)}
|
|
39278
|
+
`);
|
|
39279
|
+
} catch {
|
|
39280
|
+
}
|
|
39281
|
+
}
|
|
39282
|
+
function readHookFailOpens(dataDir2) {
|
|
39283
|
+
try {
|
|
39284
|
+
const parsed2 = JSON.parse(readFileSync12(hookFailOpensPath(dataDir2), "utf8"));
|
|
39285
|
+
if (typeof parsed2 !== "object" || parsed2 === null) return null;
|
|
39286
|
+
const record2 = parsed2;
|
|
39287
|
+
if (!isPositiveSafeInteger(record2.failOpens)) return null;
|
|
39288
|
+
if (!isPositiveSafeInteger(record2.lastAtMs)) return null;
|
|
39289
|
+
return { failOpens: record2.failOpens, lastAtMs: record2.lastAtMs };
|
|
39290
|
+
} catch {
|
|
39291
|
+
return null;
|
|
39292
|
+
}
|
|
39293
|
+
}
|
|
39294
|
+
function isPositiveSafeInteger(value) {
|
|
39295
|
+
return typeof value === "number" && Number.isSafeInteger(value) && value > 0;
|
|
39296
|
+
}
|
|
38968
39297
|
|
|
38969
39298
|
// ../../packages/plugin-sdk/src/host-floor.ts
|
|
38970
39299
|
import { readFileSync as readFileSync14 } from "fs";
|
|
@@ -39703,7 +40032,7 @@ async function handleProhibitedTurn(gateway, dataDir2, sessionId, transcriptPath
|
|
|
39703
40032
|
|
|
39704
40033
|
// src/hooks/shared.ts
|
|
39705
40034
|
async function readStdin() {
|
|
39706
|
-
return new Promise((
|
|
40035
|
+
return new Promise((resolve3) => {
|
|
39707
40036
|
let data = "";
|
|
39708
40037
|
let settled = false;
|
|
39709
40038
|
const finish = () => {
|
|
@@ -39712,7 +40041,7 @@ async function readStdin() {
|
|
|
39712
40041
|
clearTimeout(timer);
|
|
39713
40042
|
process.stdin.removeListener("data", onData);
|
|
39714
40043
|
process.stdin.removeListener("end", finish);
|
|
39715
|
-
|
|
40044
|
+
resolve3(data);
|
|
39716
40045
|
};
|
|
39717
40046
|
const onData = (chunk) => {
|
|
39718
40047
|
data += chunk;
|
|
@@ -39737,12 +40066,12 @@ function getString(record2, key) {
|
|
|
39737
40066
|
return typeof value === "string" ? value : void 0;
|
|
39738
40067
|
}
|
|
39739
40068
|
function emit(output2) {
|
|
39740
|
-
return new Promise((
|
|
40069
|
+
return new Promise((resolve3) => {
|
|
39741
40070
|
let settled = false;
|
|
39742
40071
|
const finish = () => {
|
|
39743
40072
|
if (settled) return;
|
|
39744
40073
|
settled = true;
|
|
39745
|
-
|
|
40074
|
+
resolve3();
|
|
39746
40075
|
};
|
|
39747
40076
|
process.stdout.on("error", finish);
|
|
39748
40077
|
process.stdout.write(JSON.stringify(output2), finish);
|
|
@@ -39756,10 +40085,16 @@ function baseMetadata(input2) {
|
|
|
39756
40085
|
if (repo) metadata.repo = repo;
|
|
39757
40086
|
return Object.keys(metadata).length > 0 ? metadata : void 0;
|
|
39758
40087
|
}
|
|
40088
|
+
function countFailOpen(base) {
|
|
40089
|
+
try {
|
|
40090
|
+
recordHookFailOpen(dataDir(base), Date.now());
|
|
40091
|
+
} catch {
|
|
40092
|
+
}
|
|
40093
|
+
}
|
|
39759
40094
|
|
|
39760
40095
|
// src/hooks/store-health.ts
|
|
39761
40096
|
import { mkdirSync as mkdirSync5, readFileSync as readFileSync21, writeFileSync as writeFileSync8 } from "fs";
|
|
39762
|
-
import { dirname as
|
|
40097
|
+
import { dirname as dirname7, join as join33 } from "path";
|
|
39763
40098
|
|
|
39764
40099
|
// ../../packages/remote/src/http.ts
|
|
39765
40100
|
import { request as httpRequest } from "http";
|
|
@@ -39855,7 +40190,7 @@ async function send(options) {
|
|
|
39855
40190
|
}
|
|
39856
40191
|
}
|
|
39857
40192
|
};
|
|
39858
|
-
return new Promise((
|
|
40193
|
+
return new Promise((resolve3, reject) => {
|
|
39859
40194
|
let settled = false;
|
|
39860
40195
|
const fail = (reason, status) => {
|
|
39861
40196
|
if (settled) return;
|
|
@@ -39881,7 +40216,7 @@ async function send(options) {
|
|
|
39881
40216
|
res.on("end", () => {
|
|
39882
40217
|
if (settled) return;
|
|
39883
40218
|
settled = true;
|
|
39884
|
-
|
|
40219
|
+
resolve3({
|
|
39885
40220
|
status: res.statusCode ?? 0,
|
|
39886
40221
|
headers: res.headers,
|
|
39887
40222
|
body: Buffer.concat(chunks).toString("utf8")
|
|
@@ -40877,10 +41212,55 @@ import { spawn } from "child_process";
|
|
|
40877
41212
|
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
40878
41213
|
var HISTORY_SYNC_THROTTLE_MS = 5 * 60 * 1e3;
|
|
40879
41214
|
|
|
41215
|
+
// ../../packages/plugin-runtime/src/attached/install-record.ts
|
|
41216
|
+
import { readFile as readFile2, stat } from "fs/promises";
|
|
41217
|
+
import { basename as basename6, dirname as dirname6, join as join28, resolve as resolve2 } from "path";
|
|
41218
|
+
async function readInstalledVersion(installRoot) {
|
|
41219
|
+
try {
|
|
41220
|
+
const versionDir = resolve2(installRoot);
|
|
41221
|
+
const pluginDir = dirname6(versionDir);
|
|
41222
|
+
const marketplaceDir = dirname6(pluginDir);
|
|
41223
|
+
const cacheDir = dirname6(marketplaceDir);
|
|
41224
|
+
if (basename6(cacheDir) !== "cache") return null;
|
|
41225
|
+
const key = `${basename6(pluginDir)}@${basename6(marketplaceDir)}`;
|
|
41226
|
+
const record2 = JSON.parse(
|
|
41227
|
+
await readFile2(join28(dirname6(cacheDir), "installed_plugins.json"), "utf8")
|
|
41228
|
+
);
|
|
41229
|
+
const plugins = record2?.plugins;
|
|
41230
|
+
if (typeof plugins !== "object" || plugins === null || !Object.hasOwn(plugins, key)) {
|
|
41231
|
+
return null;
|
|
41232
|
+
}
|
|
41233
|
+
const entries = plugins[key];
|
|
41234
|
+
if (!Array.isArray(entries)) return null;
|
|
41235
|
+
let newest = null;
|
|
41236
|
+
for (const entry of entries) {
|
|
41237
|
+
const { version: version2, installPath } = entry ?? {};
|
|
41238
|
+
if (typeof version2 !== "string" || !isParseableBinaryVersion(version2)) continue;
|
|
41239
|
+
if (!StorePosturePlugin.shape.installedVersion.safeParse(version2).success) continue;
|
|
41240
|
+
if (newest !== null && compareBinaryVersions(version2, newest) <= 0) continue;
|
|
41241
|
+
if (typeof installPath === "string" && !await exists(installPath)) continue;
|
|
41242
|
+
newest = version2;
|
|
41243
|
+
}
|
|
41244
|
+
return newest;
|
|
41245
|
+
} catch {
|
|
41246
|
+
return null;
|
|
41247
|
+
}
|
|
41248
|
+
}
|
|
41249
|
+
async function exists(path) {
|
|
41250
|
+
try {
|
|
41251
|
+
await stat(path);
|
|
41252
|
+
return true;
|
|
41253
|
+
} catch {
|
|
41254
|
+
return false;
|
|
41255
|
+
}
|
|
41256
|
+
}
|
|
41257
|
+
|
|
40880
41258
|
// ../../packages/plugin-runtime/src/attached/plugin-block.ts
|
|
40881
41259
|
import { readFileSync as readFileSync18 } from "fs";
|
|
41260
|
+
var INSTALL_RECORD_READ_TIMEOUT_MS = REQUEST_TIMEOUT_MS / 2;
|
|
40882
41261
|
function createPluginBlock(build, policyStore) {
|
|
40883
41262
|
return async () => {
|
|
41263
|
+
const installed = build.installRoot === void 0 ? void 0 : readInstalledVersionBounded(build.installRoot);
|
|
40884
41264
|
const cached2 = await policyStore.read();
|
|
40885
41265
|
const fetchedAtMs = cached2?.fetchedAtMs;
|
|
40886
41266
|
const block = {
|
|
@@ -40888,16 +41268,25 @@ function createPluginBlock(build, policyStore) {
|
|
|
40888
41268
|
version: build.version,
|
|
40889
41269
|
ossVersion: build.ossVersion ?? null,
|
|
40890
41270
|
policyBundleVersion: cached2 !== null && StorePosturePlugin.shape.policyBundleVersion.safeParse(cached2.bundle.version).success ? cached2.bundle.version : null,
|
|
40891
|
-
policyFetchedAt: fetchedAtMs !== void 0 && fetchedAtMs > 0 && StorePosturePlugin.shape.policyFetchedAt.safeParse(fetchedAtMs).success ? fetchedAtMs : null
|
|
41271
|
+
policyFetchedAt: fetchedAtMs !== void 0 && fetchedAtMs > 0 && StorePosturePlugin.shape.policyFetchedAt.safeParse(fetchedAtMs).success ? fetchedAtMs : null,
|
|
41272
|
+
...installed === void 0 ? {} : { installedVersion: await installed },
|
|
41273
|
+
buildSchemaVersion: SQLITE_MIGRATIONS.length
|
|
40892
41274
|
};
|
|
40893
41275
|
return StorePosturePlugin.safeParse(block).success ? block : void 0;
|
|
40894
41276
|
};
|
|
40895
41277
|
}
|
|
41278
|
+
async function readInstalledVersionBounded(installRoot) {
|
|
41279
|
+
try {
|
|
41280
|
+
return await withTimeout(readInstalledVersion(installRoot), INSTALL_RECORD_READ_TIMEOUT_MS);
|
|
41281
|
+
} catch {
|
|
41282
|
+
return null;
|
|
41283
|
+
}
|
|
41284
|
+
}
|
|
40896
41285
|
|
|
40897
41286
|
// ../../packages/plugin-runtime/src/attached/policy-store.ts
|
|
40898
41287
|
import { randomUUID as randomUUID17 } from "crypto";
|
|
40899
|
-
import { readFile as
|
|
40900
|
-
import { join as
|
|
41288
|
+
import { readFile as readFile3, rm, writeFile as writeFile2 } from "fs/promises";
|
|
41289
|
+
import { join as join29 } from "path";
|
|
40901
41290
|
|
|
40902
41291
|
// ../../packages/plugin-runtime/src/attached/atomic-publish.ts
|
|
40903
41292
|
import { rename as rename2 } from "fs/promises";
|
|
@@ -40905,11 +41294,11 @@ var RETRYABLE = /* @__PURE__ */ new Set(["EPERM", "EACCES", "EBUSY"]);
|
|
|
40905
41294
|
var IMMEDIATE_RETRIES = 8;
|
|
40906
41295
|
var TIMED_RETRIES = 4;
|
|
40907
41296
|
var ATTEMPTS = 1 + IMMEDIATE_RETRIES + TIMED_RETRIES;
|
|
40908
|
-
var delay = (ms) => new Promise((
|
|
40909
|
-
setTimeout(
|
|
41297
|
+
var delay = (ms) => new Promise((resolve3) => {
|
|
41298
|
+
setTimeout(resolve3, ms);
|
|
40910
41299
|
});
|
|
40911
|
-
var yieldToLoop = () => new Promise((
|
|
40912
|
-
setImmediate(
|
|
41300
|
+
var yieldToLoop = () => new Promise((resolve3) => {
|
|
41301
|
+
setImmediate(resolve3);
|
|
40913
41302
|
});
|
|
40914
41303
|
async function publishByRename(tmp, file2, move = rename2) {
|
|
40915
41304
|
for (let attempt = 1; ; attempt += 1) {
|
|
@@ -40926,10 +41315,10 @@ async function publishByRename(tmp, file2, move = rename2) {
|
|
|
40926
41315
|
|
|
40927
41316
|
// ../../packages/plugin-runtime/src/attached/policy-store.ts
|
|
40928
41317
|
function createPolicyStore(dir = dataDir()) {
|
|
40929
|
-
const file2 =
|
|
41318
|
+
const file2 = join29(dir, "policy-cache.json");
|
|
40930
41319
|
async function read() {
|
|
40931
41320
|
try {
|
|
40932
|
-
const raw = await
|
|
41321
|
+
const raw = await readFile3(file2, "utf8");
|
|
40933
41322
|
const parsed2 = JSON.parse(raw);
|
|
40934
41323
|
if (typeof parsed2 !== "object" || parsed2 === null) return null;
|
|
40935
41324
|
const record2 = parsed2;
|
|
@@ -40951,7 +41340,7 @@ function createPolicyStore(dir = dataDir()) {
|
|
|
40951
41340
|
}
|
|
40952
41341
|
async function priorRecord() {
|
|
40953
41342
|
try {
|
|
40954
|
-
const parsed2 = JSON.parse(await
|
|
41343
|
+
const parsed2 = JSON.parse(await readFile3(file2, "utf8"));
|
|
40955
41344
|
return typeof parsed2 === "object" && parsed2 !== null ? parsed2 : null;
|
|
40956
41345
|
} catch {
|
|
40957
41346
|
return null;
|
|
@@ -40997,7 +41386,7 @@ function createPolicyStore(dir = dataDir()) {
|
|
|
40997
41386
|
|
|
40998
41387
|
// ../../packages/plugin-runtime/src/attached/posture-report-state.ts
|
|
40999
41388
|
import { readFileSync as readFileSync19 } from "fs";
|
|
41000
|
-
import { join as
|
|
41389
|
+
import { join as join30 } from "path";
|
|
41001
41390
|
var POSTURE_REPORT_STATE_FILENAME = ATTACHED_POSTURE_REPORT_FILENAME;
|
|
41002
41391
|
var OUTCOME_KEYS = {
|
|
41003
41392
|
ok: true,
|
|
@@ -41011,7 +41400,7 @@ var OUTCOME_KEYS = {
|
|
|
41011
41400
|
};
|
|
41012
41401
|
var OUTCOMES = new Set(Object.keys(OUTCOME_KEYS));
|
|
41013
41402
|
function postureReportStatePath(dataDir2) {
|
|
41014
|
-
return
|
|
41403
|
+
return join30(dataDir2, POSTURE_REPORT_STATE_FILENAME);
|
|
41015
41404
|
}
|
|
41016
41405
|
function writePostureReportState(dataDir2, state) {
|
|
41017
41406
|
try {
|
|
@@ -41190,12 +41579,12 @@ function readStorePosture(dbPath2) {
|
|
|
41190
41579
|
|
|
41191
41580
|
// ../../packages/plugin-runtime/src/attached/posture-store.ts
|
|
41192
41581
|
import { randomUUID as randomUUID18 } from "crypto";
|
|
41193
|
-
import { readFile as
|
|
41194
|
-
import { join as
|
|
41582
|
+
import { readFile as readFile4, rm as rm2, writeFile as writeFile3 } from "fs/promises";
|
|
41583
|
+
import { join as join31 } from "path";
|
|
41195
41584
|
var UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/;
|
|
41196
41585
|
function createPostureStore(dir = settingsDir(), legacyDir) {
|
|
41197
|
-
const file2 =
|
|
41198
|
-
const legacyFile = legacyDir === void 0 ? null :
|
|
41586
|
+
const file2 = join31(dir, "posture-state.json");
|
|
41587
|
+
const legacyFile = legacyDir === void 0 ? null : join31(legacyDir, "posture-state.json");
|
|
41199
41588
|
async function persist(state) {
|
|
41200
41589
|
await ensureDataDir(dir);
|
|
41201
41590
|
const tmp = `${file2}.${randomUUID18()}.tmp`;
|
|
@@ -41210,7 +41599,7 @@ function createPostureStore(dir = settingsDir(), legacyDir) {
|
|
|
41210
41599
|
async function readFrom(path) {
|
|
41211
41600
|
let raw;
|
|
41212
41601
|
try {
|
|
41213
|
-
raw = await
|
|
41602
|
+
raw = await readFile4(path, "utf8");
|
|
41214
41603
|
} catch (err) {
|
|
41215
41604
|
const code = err.code;
|
|
41216
41605
|
if (code === "ENOENT" || code === "ENOTDIR") return null;
|
|
@@ -41264,7 +41653,7 @@ function createPostureStore(dir = settingsDir(), legacyDir) {
|
|
|
41264
41653
|
|
|
41265
41654
|
// ../../packages/plugin-runtime/src/attached/sync-state.ts
|
|
41266
41655
|
import { readFileSync as readFileSync20 } from "fs";
|
|
41267
|
-
import { join as
|
|
41656
|
+
import { join as join32 } from "path";
|
|
41268
41657
|
|
|
41269
41658
|
// ../../packages/plugin-runtime/src/attached/status.ts
|
|
41270
41659
|
var REFUSAL_LINES = {
|
|
@@ -41341,12 +41730,12 @@ var StandaloneDataGateway = class {
|
|
|
41341
41730
|
// reconciler drops the whole pass and recovers it idempotently on the next read.
|
|
41342
41731
|
recordLlmCalls(inputs) {
|
|
41343
41732
|
if (inputs.length === 0) return Promise.resolve();
|
|
41344
|
-
return new Promise((
|
|
41733
|
+
return new Promise((resolve3, reject) => {
|
|
41345
41734
|
try {
|
|
41346
41735
|
this.db.auditEvents.runInTransaction(() => {
|
|
41347
41736
|
for (const input2 of inputs) this.db.auditEvents.insertLlmCall(input2);
|
|
41348
41737
|
});
|
|
41349
|
-
|
|
41738
|
+
resolve3();
|
|
41350
41739
|
} catch (err) {
|
|
41351
41740
|
reject(err instanceof Error ? err : new Error(String(err)));
|
|
41352
41741
|
}
|
|
@@ -41358,12 +41747,12 @@ var StandaloneDataGateway = class {
|
|
|
41358
41747
|
// drops the whole pass and recovers it idempotently next time.
|
|
41359
41748
|
recordToolCalls(inputs) {
|
|
41360
41749
|
if (inputs.length === 0) return Promise.resolve();
|
|
41361
|
-
return new Promise((
|
|
41750
|
+
return new Promise((resolve3, reject) => {
|
|
41362
41751
|
try {
|
|
41363
41752
|
this.db.auditEvents.runInTransaction(() => {
|
|
41364
41753
|
for (const input2 of inputs) this.writeToolCall(input2);
|
|
41365
41754
|
});
|
|
41366
|
-
|
|
41755
|
+
resolve3();
|
|
41367
41756
|
} catch (err) {
|
|
41368
41757
|
reject(err instanceof Error ? err : new Error(String(err)));
|
|
41369
41758
|
}
|
|
@@ -41784,12 +42173,12 @@ function claimStoreUnavailableWarning(dataDir2, sessionId) {
|
|
|
41784
42173
|
return true;
|
|
41785
42174
|
}
|
|
41786
42175
|
function markerDirs(dataDir2) {
|
|
41787
|
-
return [dataDir2,
|
|
42176
|
+
return [dataDir2, dirname7(dataDir2)];
|
|
41788
42177
|
}
|
|
41789
42178
|
function alreadyClaimed(dirs, marker, sessionId) {
|
|
41790
42179
|
return dirs.some((dir) => {
|
|
41791
42180
|
try {
|
|
41792
|
-
return readFileSync21(
|
|
42181
|
+
return readFileSync21(join33(dir, marker), "utf8") === sessionId;
|
|
41793
42182
|
} catch {
|
|
41794
42183
|
return false;
|
|
41795
42184
|
}
|
|
@@ -41799,7 +42188,7 @@ function recordClaim(dirs, marker, sessionId) {
|
|
|
41799
42188
|
for (const dir of dirs) {
|
|
41800
42189
|
try {
|
|
41801
42190
|
mkdirSync5(dir, { recursive: true, mode: DATA_DIR_MODE });
|
|
41802
|
-
writeFileSync8(
|
|
42191
|
+
writeFileSync8(join33(dir, marker), sessionId, { mode: DATA_FILE_MODE });
|
|
41803
42192
|
return;
|
|
41804
42193
|
} catch {
|
|
41805
42194
|
}
|
|
@@ -41824,7 +42213,7 @@ function formatMode(mode) {
|
|
|
41824
42213
|
}
|
|
41825
42214
|
function warnIfStoreRedirected(config2, sessionId, write = (message) => void process.stderr.write(message)) {
|
|
41826
42215
|
try {
|
|
41827
|
-
const paths = symlinkedStorePaths(
|
|
42216
|
+
const paths = symlinkedStorePaths(dirname7(config2.dataDir));
|
|
41828
42217
|
if (paths.length === 0) return;
|
|
41829
42218
|
if (!sessionId) {
|
|
41830
42219
|
write(storeRedirectedMessage(paths));
|
|
@@ -41902,5 +42291,6 @@ async function main() {
|
|
|
41902
42291
|
try {
|
|
41903
42292
|
await main();
|
|
41904
42293
|
} catch {
|
|
42294
|
+
countFailOpen();
|
|
41905
42295
|
}
|
|
41906
42296
|
process.exit(0);
|