@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/scripts/query.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.9/node_modules/ignore/index.js
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.9/node_modules/ignore/index.js"(exports, module) {
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[at + 1].single})[^\\/])*`;
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 basename7 = shortcut ? basenameOf(path) : path;
685
+ const basename8 = 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 ? basename7 : path
691
+ shortcut && rule._basenameOnly ? basename8 : path
685
692
  )) {
686
693
  ignored = !negative;
687
694
  unignored = negative;
@@ -998,6 +1005,10 @@ var SQLITE_MIGRATIONS = [
998
1005
  {
999
1006
  tag: "0035_share_destination_provider_id",
1000
1007
  sql: "ALTER TABLE `share_destination` ADD `provider_id` text;"
1008
+ },
1009
+ {
1010
+ tag: "0036_secret_vault_identity_fingerprint",
1011
+ sql: "ALTER TABLE `secret_vault` ADD `value_identity_fingerprint` text DEFAULT '' NOT NULL;--> statement-breakpoint\nUPDATE `secret_vault` SET `value_identity_fingerprint` = `value_fingerprint`;\n"
1001
1012
  }
1002
1013
  ];
1003
1014
 
@@ -6033,7 +6044,7 @@ var recursive = /* @__PURE__ */ new WeakMap();
6033
6044
  var NONE = 0;
6034
6045
  var ASSUMED = 1;
6035
6046
  var PROVEN = 2;
6036
- function isRecursive(inst, stack, resolve2) {
6047
+ function isRecursive(inst, stack, resolve3) {
6037
6048
  const cached2 = recursive.get(inst);
6038
6049
  if (cached2 !== void 0)
6039
6050
  return cached2 ? PROVEN : NONE;
@@ -6043,7 +6054,7 @@ function isRecursive(inst, stack, resolve2) {
6043
6054
  let result = NONE;
6044
6055
  const check2 = (child) => {
6045
6056
  if (result !== PROVEN && child?._zod) {
6046
- const answer = isRecursive(child, stack, resolve2);
6057
+ const answer = isRecursive(child, stack, resolve3);
6047
6058
  if (answer > result)
6048
6059
  result = answer;
6049
6060
  }
@@ -6054,7 +6065,7 @@ function isRecursive(inst, stack, resolve2) {
6054
6065
  const desc = Object.getOwnPropertyDescriptor(sh, key);
6055
6066
  if (spread && !desc.enumerable)
6056
6067
  continue;
6057
- const child = desc.get ? ASSUMED : desc.value?._zod ? isRecursive(desc.value, stack, resolve2) : NONE;
6068
+ const child = desc.get ? ASSUMED : desc.value?._zod ? isRecursive(desc.value, stack, resolve3) : NONE;
6058
6069
  if (child > answer)
6059
6070
  answer = child;
6060
6071
  }
@@ -6118,7 +6129,7 @@ function isRecursive(inst, stack, resolve2) {
6118
6129
  break;
6119
6130
  // `$ZodLazy` caches its inner on the def, so a resolved edge is followed exactly
6120
6131
  case "lazy": {
6121
- const inner = def._cachedInner ?? (resolve2 ? inst._zod.innerType : void 0);
6132
+ const inner = def._cachedInner ?? (resolve3 ? inst._zod.innerType : void 0);
6122
6133
  merge2(inner ? isRecursive(inner, stack, false) : ASSUMED);
6123
6134
  break;
6124
6135
  }
@@ -23553,7 +23564,29 @@ var StorePosturePlugin = external_exports.object({
23553
23564
  */
23554
23565
  policyBundleVersion: external_exports.string().max(200).nullable(),
23555
23566
  /** Epoch millis, on the CLIENT clock, of that fetch. */
23556
- policyFetchedAt: external_exports.number().int().min(0).max(MAX_DATE_MS).nullable()
23567
+ policyFetchedAt: external_exports.number().int().min(0).max(MAX_DATE_MS).nullable(),
23568
+ /**
23569
+ * The newest version the host's own install record holds for this plugin —
23570
+ * what is on disk. After an update it leads `version` (the running copy) by
23571
+ * one launch. Null when no usable version can be read: no install record
23572
+ * (a plugin run from a checkout), no entry with a valid version, or every
23573
+ * such entry names an `installPath` that no longer exists; OPTIONAL, not
23574
+ * required, so a build that predates the member keeps getting its 200.
23575
+ * Bounded like `version`.
23576
+ */
23577
+ installedVersion: external_exports.string().max(64).nullable().optional(),
23578
+ /**
23579
+ * The local-store schema version this running build migrates a store to:
23580
+ * the number of store migrations it carries, the count it stamps into
23581
+ * `PRAGMA user_version`. A snapshot whose `schemaVersion` is above it
23582
+ * usually describes a store a newer build migrated. It is a hint, not a
23583
+ * verdict: the stamp is write-only, so a store whose count ran past this
23584
+ * build's while this build knows every migration in its ledger reads above
23585
+ * it too, which is why describeStoreSkew decides skew on ledger tags and
23586
+ * never on the count. OPTIONAL for the same reason as `installedVersion`;
23587
+ * bounded like `schemaVersion`.
23588
+ */
23589
+ buildSchemaVersion: external_exports.number().int().min(0).max(MAX_INT4).optional()
23557
23590
  }).meta({ id: "StorePosturePlugin" });
23558
23591
  var StorePostureSnapshot = external_exports.object({
23559
23592
  deviceId: external_exports.guid(),
@@ -25193,10 +25226,15 @@ var ParsedPointer = external_exports.object({
25193
25226
  });
25194
25227
  var VaultEntry = external_exports.object({
25195
25228
  pointerId: external_exports.string(),
25196
- // The keyed HMAC of the raw value under `exception.key`, and the epoch it was
25197
- // derived under. This is what a reveal-to-model grant matches on, and it rotates
25198
- // independently of the vault encryption key below.
25229
+ // The keyed HMAC of the EXACT raw bytes under `exception.key`, and the epoch it
25230
+ // was derived under. The vault's own dedupe key: a value and its invisibly
25231
+ // padded twin are two rows. It rotates independently of the vault encryption
25232
+ // key below. Never matched against an exception or grant.
25199
25233
  valueFingerprint: external_exports.string().regex(/^[0-9a-f]{64}$/),
25234
+ // The same HMAC over the raw with invisible padding removed: the identity a
25235
+ // reveal-to-model grant and every exception match on. Shared by a value and
25236
+ // its padded twin.
25237
+ valueIdentityFingerprint: external_exports.string().regex(/^[0-9a-f]{64}$/),
25200
25238
  fingerprintKeyVersion: external_exports.number().int().positive(),
25201
25239
  // The vault-key epoch this row's ciphertext was sealed under.
25202
25240
  keyVersion: external_exports.number().int().positive(),
@@ -25776,10 +25814,18 @@ var SeveritySummaryItem = external_exports.object({
25776
25814
  count: external_exports.number().int().nonnegative(),
25777
25815
  // Resolution-aware breakdown (optional, additive). Populated once findings
25778
25816
  // carry lifecycle state: `caught` = handled in-flight (enforced); `openAtRest`
25779
- // = still open with no in-flight enforcement (needs remediation). Absent on the
25780
- // legacy count-only response until the resolution feature lands.
25817
+ // = still open with no in-flight enforcement (needs remediation); `dismissed`
25818
+ // = closed by a human judgement rather than a fix — visible, but not counted as
25819
+ // needing remediation. The three are disjoint. Absent on the legacy count-only
25820
+ // response until the resolution feature lands.
25781
25821
  caught: external_exports.number().int().nonnegative().optional(),
25782
- openAtRest: external_exports.number().int().nonnegative().optional()
25822
+ openAtRest: external_exports.number().int().nonnegative().optional(),
25823
+ dismissed: external_exports.number().int().nonnegative().optional(),
25824
+ // The two halves of `caught`, for a reader that wants them apart: `handled` =
25825
+ // in-flight findings an enforcement action already contained; `resolved` =
25826
+ // at-rest findings closed out by fixing them. `handled + resolved === caught`.
25827
+ handled: external_exports.number().int().nonnegative().optional(),
25828
+ resolved: external_exports.number().int().nonnegative().optional()
25783
25829
  }).meta({ id: "SeveritySummaryItem" });
25784
25830
  var SeveritySummaryResponse = external_exports.object({
25785
25831
  // Sum of bySeverity[].count.
@@ -25787,6 +25833,9 @@ var SeveritySummaryResponse = external_exports.object({
25787
25833
  // Findings still open at rest (sum of bySeverity[].openAtRest). Optional and
25788
25834
  // additive — absent on the legacy response until the resolution feature lands.
25789
25835
  needsRemediation: external_exports.number().int().nonnegative().optional(),
25836
+ // Findings a user dismissed (sum of bySeverity[].dismissed). Excluded from
25837
+ // needsRemediation, and kept visible here so an accepted risk is not erased.
25838
+ dismissed: external_exports.number().int().nonnegative().optional(),
25790
25839
  // All four severity levels are always present (count may be 0).
25791
25840
  bySeverity: external_exports.array(SeveritySummaryItem)
25792
25841
  }).meta({ id: "SeveritySummaryResponse" });
@@ -26384,11 +26433,11 @@ function repairOrRefuseMode(file2) {
26384
26433
  const link = lstatSync2(file2, { throwIfNoEntry: false });
26385
26434
  if (link === void 0) return "absent";
26386
26435
  if (link.isSymbolicLink()) return "untrusted";
26387
- const stat = statSync(file2, { throwIfNoEntry: false });
26388
- if (stat === void 0) return "absent";
26436
+ const stat2 = statSync(file2, { throwIfNoEntry: false });
26437
+ if (stat2 === void 0) return "absent";
26389
26438
  const uid = process.getuid?.();
26390
- if (uid !== void 0 && stat.uid !== uid) return "untrusted";
26391
- if (process.platform !== "win32" && (stat.mode & 511) !== DATA_FILE_MODE) {
26439
+ if (uid !== void 0 && stat2.uid !== uid) return "untrusted";
26440
+ if (process.platform !== "win32" && (stat2.mode & 511) !== DATA_FILE_MODE) {
26392
26441
  try {
26393
26442
  chmodSync2(file2, DATA_FILE_MODE);
26394
26443
  } catch {
@@ -32537,7 +32586,10 @@ var SqliteResolutionsRepository = class {
32537
32586
  * Insert many dispositions as ONE transaction — all of them or none.
32538
32587
  *
32539
32588
  * A dashboard dismissal closes every open finding of a rule, which is one
32540
- * write per key; run loose, a fault partway leaves half a rule closed with
32589
+ * write per key. It reaches this through
32590
+ * `LocalDatabase.dismissOpenFindingsForRule`, which calls it inside the
32591
+ * transaction that selected the keys, so there it runs as a SAVEPOINT of
32592
+ * that transaction. Run loose, a fault partway leaves half a rule closed with
32541
32593
  * nothing recording that the other half was meant to be. The caller then has
32542
32594
  * no way to tell a partial run from a complete one, because the card it
32543
32595
  * refreshes into just shows a smaller number either way.
@@ -32757,6 +32809,7 @@ function toSighting(row) {
32757
32809
  var SELECT_COLUMNS = `
32758
32810
  pointer_id AS pointerId,
32759
32811
  value_fingerprint AS valueFingerprint,
32812
+ value_identity_fingerprint AS valueIdentityFingerprint,
32760
32813
  fingerprint_key_version AS fingerprintKeyVersion,
32761
32814
  key_version AS keyVersion,
32762
32815
  format_version AS formatVersion,
@@ -32781,13 +32834,13 @@ var SqliteSecretVaultRepository = class {
32781
32834
  this.db = db;
32782
32835
  this.insertStmt = db.prepare(
32783
32836
  `INSERT INTO secret_vault (
32784
- pointer_id, value_fingerprint, fingerprint_key_version, key_version,
32785
- format_version, category, rule_id, masked_match, provider,
32837
+ pointer_id, value_fingerprint, value_identity_fingerprint,
32838
+ fingerprint_key_version, key_version, format_version, category, rule_id, masked_match, provider,
32786
32839
  ciphertext, nonce, auth_tag,
32787
32840
  user_authorized, occurrence_count, first_seen, last_seen
32788
32841
  ) VALUES (
32789
- :pointerId, :valueFingerprint, :fingerprintKeyVersion, :keyVersion,
32790
- :formatVersion, :category, :ruleId, :maskedMatch, :provider,
32842
+ :pointerId, :valueFingerprint, :valueIdentityFingerprint,
32843
+ :fingerprintKeyVersion, :keyVersion, :formatVersion, :category, :ruleId, :maskedMatch, :provider,
32791
32844
  :ciphertext, :nonce, :authTag,
32792
32845
  :userAuthorized, 1, :now, :now
32793
32846
  )`
@@ -32812,7 +32865,13 @@ var SqliteSecretVaultRepository = class {
32812
32865
  );
32813
32866
  this.refreshFingerprintStmt = db.prepare(
32814
32867
  `UPDATE secret_vault
32815
- SET value_fingerprint = :valueFingerprint, fingerprint_key_version = :fingerprintKeyVersion
32868
+ SET value_fingerprint = :valueFingerprint,
32869
+ value_identity_fingerprint = :valueIdentityFingerprint,
32870
+ fingerprint_key_version = :fingerprintKeyVersion
32871
+ WHERE pointer_id = :pointerId`
32872
+ );
32873
+ this.setIdentityStmt = db.prepare(
32874
+ `UPDATE secret_vault SET value_identity_fingerprint = :valueIdentityFingerprint
32816
32875
  WHERE pointer_id = :pointerId`
32817
32876
  );
32818
32877
  this.deleteByPointerStmt = db.prepare(`DELETE FROM secret_vault WHERE pointer_id = :pointerId`);
@@ -32829,6 +32888,7 @@ var SqliteSecretVaultRepository = class {
32829
32888
  listStmt;
32830
32889
  replaceCiphertextStmt;
32831
32890
  refreshFingerprintStmt;
32891
+ setIdentityStmt;
32832
32892
  deleteByPointerStmt;
32833
32893
  derefStmt;
32834
32894
  /**
@@ -32859,6 +32919,7 @@ var SqliteSecretVaultRepository = class {
32859
32919
  bindParams({
32860
32920
  pointerId: input2.pointerId,
32861
32921
  valueFingerprint: input2.valueFingerprint,
32922
+ valueIdentityFingerprint: input2.valueIdentityFingerprint,
32862
32923
  fingerprintKeyVersion: input2.fingerprintKeyVersion,
32863
32924
  keyVersion: input2.keyVersion,
32864
32925
  formatVersion: input2.formatVersion ?? POINTER_FORMAT_VERSION,
@@ -32920,7 +32981,15 @@ var SqliteSecretVaultRepository = class {
32920
32981
  replaceCiphertext(pointerId, next) {
32921
32982
  this.replaceCiphertextStmt.run({ pointerId, ...next });
32922
32983
  }
32923
- /** Re-derive an entry's fingerprint under a new fingerprint-key epoch. */
32984
+ /**
32985
+ * Correct an entry's identity fingerprint in place, leaving its exact
32986
+ * fingerprint and key epoch alone. For a row whose identity column still holds
32987
+ * the exact value copied in by the migration that added it.
32988
+ */
32989
+ setIdentityFingerprint(pointerId, valueIdentityFingerprint) {
32990
+ this.setIdentityStmt.run({ pointerId, valueIdentityFingerprint });
32991
+ }
32992
+ /** Re-derive an entry's fingerprints under a new fingerprint-key epoch. */
32924
32993
  refreshFingerprint(pointerId, next) {
32925
32994
  this.refreshFingerprintStmt.run({ pointerId, ...next });
32926
32995
  }
@@ -33051,7 +33120,7 @@ var SqliteSecretVaultRepository = class {
33051
33120
  `SELECT ${INVENTORY_COLUMNS},
33052
33121
  (SELECT e.id FROM exceptions e
33053
33122
  WHERE e.rule_id = v.rule_id
33054
- AND e.value_fingerprint = v.value_fingerprint
33123
+ AND e.value_fingerprint = v.value_identity_fingerprint
33055
33124
  AND e.key_version = v.fingerprint_key_version
33056
33125
  AND ${ACTIVE_REVEAL_GRANT_PREDICATE}
33057
33126
  LIMIT 1) AS grant_id
@@ -33094,7 +33163,7 @@ var SqliteSecretVaultRepository = class {
33094
33163
  `SELECT ${INVENTORY_COLUMNS},
33095
33164
  (SELECT e.id FROM exceptions e
33096
33165
  WHERE e.rule_id = v.rule_id
33097
- AND e.value_fingerprint = v.value_fingerprint
33166
+ AND e.value_fingerprint = v.value_identity_fingerprint
33098
33167
  AND e.key_version = v.fingerprint_key_version
33099
33168
  AND ${ACTIVE_REVEAL_GRANT_PREDICATE}
33100
33169
  LIMIT 1) AS grant_id
@@ -33198,6 +33267,18 @@ var OPEN_AT_REST_FINDINGS_SQL = `FROM inspection_findings f
33198
33267
  OR latest.status IS NULL
33199
33268
  OR latest.status NOT IN ('resolved', 'dismissed')
33200
33269
  )`;
33270
+ function selectOpenFindingKeysForRule(db, ruleId) {
33271
+ const rows = allRows(
33272
+ db.prepare(
33273
+ `SELECT DISTINCT f.finding_key AS finding_key
33274
+ ${OPEN_AT_REST_FINDINGS_SQL}
33275
+ AND d.rule_id = :ruleId
33276
+ AND f.finding_key IS NOT NULL`
33277
+ ),
33278
+ { ruleId }
33279
+ );
33280
+ return rows.map((r) => r.finding_key);
33281
+ }
33201
33282
  var SEVERITIES = ["critical", "high", "medium", "low"];
33202
33283
  var ACTION_TO_KIND = {
33203
33284
  block: "blocked",
@@ -33254,16 +33335,16 @@ var SqliteSecurityRepository = class {
33254
33335
  // findings are caught only once their latest disposition is resolved,
33255
33336
  // otherwise they are open-at-rest.
33256
33337
  //
33257
- // NOTE for future manual-resolution writers: only latest status
33258
- // 'resolved' counts as caught above. When acknowledged/dismissed/
33259
- // false-positive manual dispositions land, this must keep filtering by
33260
- // status/method — 'acknowledged' is accepted risk, not a fix, and must NOT
33261
- // be bucketed as caught alongside 'resolved'.
33338
+ // Only latest status 'resolved' counts as caught above. 'dismissed' is its
33339
+ // own bucket: a judgement rather than a fix, so it is neither caught nor
33340
+ // needing remediation, and stays countable. A further manual disposition
33341
+ // (acknowledged, false-positive) must be placed deliberately — 'acknowledged'
33342
+ // is accepted risk, not a fix, and must NOT be bucketed as caught.
33262
33343
  //
33263
33344
  // Legacy at-rest findings from pre-branch scans carry finding_key = NULL —
33264
33345
  // the resolution lifecycle is keyed by finding_key, so it can never attach a
33265
33346
  // disposition to (or clear) one of these on re-scan. They are excluded from
33266
- // both caught and openAtRest (untracked, not "needs remediation forever"),
33347
+ // all three buckets (untracked, not "needs remediation forever"),
33267
33348
  // but still counted in total/count below — this keeps this predicate
33268
33349
  // consistent with SqliteResolutionsRepository.openAtRestKeysForPath, which
33269
33350
  // already filters `finding_key IS NOT NULL`.
@@ -33286,12 +33367,25 @@ var SqliteSecurityRepository = class {
33286
33367
  WHEN latest.status = 'resolved' THEN 1
33287
33368
  ELSE 0
33288
33369
  END) AS caught,
33370
+ SUM(CASE WHEN e.event_type != 'code_change' THEN 1 ELSE 0 END) AS handled,
33289
33371
  SUM(CASE
33290
33372
  WHEN e.event_type = 'code_change'
33291
33373
  AND f.finding_key IS NOT NULL
33292
- AND (latest.status IS NULL OR latest.status != 'resolved') THEN 1
33374
+ AND latest.status = 'resolved' THEN 1
33293
33375
  ELSE 0
33294
- END) AS open_at_rest
33376
+ END) AS resolved,
33377
+ SUM(CASE
33378
+ WHEN e.event_type = 'code_change'
33379
+ AND f.finding_key IS NOT NULL
33380
+ AND (latest.status IS NULL
33381
+ OR latest.status NOT IN ('resolved', 'dismissed')) THEN 1
33382
+ ELSE 0
33383
+ END) AS open_at_rest,
33384
+ SUM(CASE
33385
+ WHEN e.event_type = 'code_change'
33386
+ AND latest.status = 'dismissed' THEN 1
33387
+ ELSE 0
33388
+ END) AS dismissed
33295
33389
  FROM inspection_findings f
33296
33390
  JOIN audit_events e INDEXED BY idx_audit_capture_rollup ON e.id = f.audit_event_id
33297
33391
  JOIN inspection_definitions d ON d.id = f.inspection_definition_id
@@ -33306,11 +33400,15 @@ var SqliteSecurityRepository = class {
33306
33400
  severity,
33307
33401
  count: byRow.get(severity)?.count ?? 0,
33308
33402
  caught: byRow.get(severity)?.caught ?? 0,
33309
- openAtRest: byRow.get(severity)?.open_at_rest ?? 0
33403
+ handled: byRow.get(severity)?.handled ?? 0,
33404
+ resolved: byRow.get(severity)?.resolved ?? 0,
33405
+ openAtRest: byRow.get(severity)?.open_at_rest ?? 0,
33406
+ dismissed: byRow.get(severity)?.dismissed ?? 0
33310
33407
  }));
33311
33408
  const total = bySeverity.reduce((sum, s) => sum + s.count, 0);
33312
33409
  const needsRemediation = bySeverity.reduce((sum, s) => sum + s.openAtRest, 0);
33313
- return Promise.resolve({ total, needsRemediation, bySeverity });
33410
+ const dismissed = bySeverity.reduce((sum, s) => sum + s.dismissed, 0);
33411
+ return Promise.resolve({ total, needsRemediation, dismissed, bySeverity });
33314
33412
  }
33315
33413
  // Range is echoed but does not change the result today — coverage is a constant
33316
33414
  // business fact (see SCAN_COVERAGE), not a measured per-window metric. Order
@@ -33627,10 +33725,10 @@ var SqliteSecurityRepository = class {
33627
33725
  * machine, and the second reported "no recommendations" over live exposure.
33628
33726
  *
33629
33727
  * `open` mirrors `deriveFindingStatus` — at-rest, minus resolved and dismissed —
33630
- * so a row's count is exactly what `?status=open&type=<rule>` returns. Note that
33631
- * is NOT `severitySummary`'s `openAtRest`, which keeps dismissed findings (a
33632
- * dismissal is a judgement, not a remediation) and drops untracked legacy rows.
33633
- * The two answer different questions and only this one has to match a link.
33728
+ * so a row's count is exactly what `?status=open&type=<rule>` returns. It
33729
+ * differs from `severitySummary`'s `openAtRest` only in including untracked
33730
+ * legacy rows, which that bucket leaves out; dismissed is excluded from both.
33731
+ * Only this one has to match a link.
33634
33732
  *
33635
33733
  * Aggregated in SQL: the result is O(distinct rule × category × severity), so a
33636
33734
  * whole-store scope costs a grouped scan rather than a row per finding.
@@ -33658,6 +33756,8 @@ var SqliteSecurityRepository = class {
33658
33756
  /**
33659
33757
  * The distinct `finding_key`s behind ONE rule's {@link recommendationInputs}
33660
33758
  * tally — what a dashboard dismissal of that row writes a disposition for.
33759
+ * The dismissal itself does not call this: it reads the same set through
33760
+ * {@link selectOpenFindingKeysForRule}, inside its own write transaction.
33661
33761
  *
33662
33762
  * It shares {@link OPEN_AT_REST_FINDINGS_SQL} with the count rather than
33663
33763
  * restating the predicate, because a dismissal has to act on exactly the set
@@ -33674,16 +33774,7 @@ var SqliteSecurityRepository = class {
33674
33774
  * this set SMALLER than the tally, never larger.
33675
33775
  */
33676
33776
  openFindingKeysForRule(ruleId) {
33677
- const rows = allRows(
33678
- this.db.prepare(
33679
- `SELECT DISTINCT f.finding_key AS finding_key
33680
- ${OPEN_AT_REST_FINDINGS_SQL}
33681
- AND d.rule_id = :ruleId
33682
- AND f.finding_key IS NOT NULL`
33683
- ),
33684
- { ruleId }
33685
- );
33686
- return Promise.resolve(rows.map((r) => r.finding_key));
33777
+ return Promise.resolve(selectOpenFindingKeysForRule(this.db, ruleId));
33687
33778
  }
33688
33779
  // Findings whose parent event occurred in [fromMs, toMs), with the parent's
33689
33780
  // epoch-millis timestamp. started_at is an INTEGER column, so the bounds stay
@@ -34729,6 +34820,31 @@ function openLocalDatabase(dir, options = {}) {
34729
34820
  );
34730
34821
  });
34731
34822
  }
34823
+ function dismissOpenFindingsForRule(ruleId, disposition) {
34824
+ let dismissed = 0;
34825
+ withTransaction(
34826
+ db,
34827
+ () => {
34828
+ const keys = selectOpenFindingKeysForRule(db, ruleId);
34829
+ resolutions.insertResolutions(
34830
+ keys.map((findingKey) => ({
34831
+ findingKey,
34832
+ status: "dismissed",
34833
+ method: disposition.method,
34834
+ resolvedAt: disposition.resolvedAt,
34835
+ evidence: disposition.evidence
34836
+ }))
34837
+ );
34838
+ dismissed = keys.length;
34839
+ },
34840
+ // IMMEDIATE takes the write lock at BEGIN, before the select, which is
34841
+ // what keeps a concurrent resolve out of the gap. It also makes waiting
34842
+ // on a busy writer an ordinary busy_timeout wait rather than a
34843
+ // read-to-write upgrade SQLite refuses to retry.
34844
+ "IMMEDIATE"
34845
+ );
34846
+ return dismissed;
34847
+ }
34732
34848
  function recordCapture(event, detected) {
34733
34849
  failOpenTransaction(db, () => {
34734
34850
  const sessionId = event.metadata?.sessionId;
@@ -34912,6 +35028,7 @@ function openLocalDatabase(dir, options = {}) {
34912
35028
  inspectionDefinitions,
34913
35029
  inspectionFindings,
34914
35030
  recordCapture,
35031
+ dismissOpenFindingsForRule,
34915
35032
  markCaptureDelivered,
34916
35033
  markCaptureOwed,
34917
35034
  markAuditEventsDelivered,
@@ -35207,7 +35324,7 @@ async function send(options) {
35207
35324
  }
35208
35325
  }
35209
35326
  };
35210
- return new Promise((resolve2, reject) => {
35327
+ return new Promise((resolve3, reject) => {
35211
35328
  let settled = false;
35212
35329
  const fail = (reason, status) => {
35213
35330
  if (settled) return;
@@ -35233,7 +35350,7 @@ async function send(options) {
35233
35350
  res.on("end", () => {
35234
35351
  if (settled) return;
35235
35352
  settled = true;
35236
- resolve2({
35353
+ resolve3({
35237
35354
  status: res.statusCode ?? 0,
35238
35355
  headers: res.headers,
35239
35356
  body: Buffer.concat(chunks).toString("utf8")
@@ -36212,6 +36329,10 @@ function escapeRegExp2(value) {
36212
36329
  return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
36213
36330
  }
36214
36331
 
36332
+ // ../../packages/detections/src/format-chars.ts
36333
+ var HAS_FORMAT_CHAR = new RegExp("\\p{Cf}", "u");
36334
+ var FORMAT_CHAR_GLOBAL = new RegExp("\\p{Cf}", "gu");
36335
+
36215
36336
  // ../../packages/detections/src/regex-cache.ts
36216
36337
  var singles = /* @__PURE__ */ new WeakMap();
36217
36338
  var keywordLists = /* @__PURE__ */ new WeakMap();
@@ -39349,10 +39470,55 @@ import { spawn } from "child_process";
39349
39470
  import { fileURLToPath as fileURLToPath2 } from "url";
39350
39471
  var HISTORY_SYNC_THROTTLE_MS = 5 * 60 * 1e3;
39351
39472
 
39473
+ // ../../packages/plugin-runtime/src/attached/install-record.ts
39474
+ import { readFile as readFile2, stat } from "fs/promises";
39475
+ import { basename as basename6, dirname as dirname6, join as join28, resolve as resolve2 } from "path";
39476
+ async function readInstalledVersion(installRoot) {
39477
+ try {
39478
+ const versionDir = resolve2(installRoot);
39479
+ const pluginDir = dirname6(versionDir);
39480
+ const marketplaceDir = dirname6(pluginDir);
39481
+ const cacheDir = dirname6(marketplaceDir);
39482
+ if (basename6(cacheDir) !== "cache") return null;
39483
+ const key = `${basename6(pluginDir)}@${basename6(marketplaceDir)}`;
39484
+ const record2 = JSON.parse(
39485
+ await readFile2(join28(dirname6(cacheDir), "installed_plugins.json"), "utf8")
39486
+ );
39487
+ const plugins = record2?.plugins;
39488
+ if (typeof plugins !== "object" || plugins === null || !Object.hasOwn(plugins, key)) {
39489
+ return null;
39490
+ }
39491
+ const entries = plugins[key];
39492
+ if (!Array.isArray(entries)) return null;
39493
+ let newest = null;
39494
+ for (const entry of entries) {
39495
+ const { version: version2, installPath } = entry ?? {};
39496
+ if (typeof version2 !== "string" || !isParseableBinaryVersion(version2)) continue;
39497
+ if (!StorePosturePlugin.shape.installedVersion.safeParse(version2).success) continue;
39498
+ if (newest !== null && compareBinaryVersions(version2, newest) <= 0) continue;
39499
+ if (typeof installPath === "string" && !await exists(installPath)) continue;
39500
+ newest = version2;
39501
+ }
39502
+ return newest;
39503
+ } catch {
39504
+ return null;
39505
+ }
39506
+ }
39507
+ async function exists(path) {
39508
+ try {
39509
+ await stat(path);
39510
+ return true;
39511
+ } catch {
39512
+ return false;
39513
+ }
39514
+ }
39515
+
39352
39516
  // ../../packages/plugin-runtime/src/attached/plugin-block.ts
39353
39517
  import { readFileSync as readFileSync18 } from "fs";
39518
+ var INSTALL_RECORD_READ_TIMEOUT_MS = REQUEST_TIMEOUT_MS / 2;
39354
39519
  function createPluginBlock(build, policyStore) {
39355
39520
  return async () => {
39521
+ const installed = build.installRoot === void 0 ? void 0 : readInstalledVersionBounded(build.installRoot);
39356
39522
  const cached2 = await policyStore.read();
39357
39523
  const fetchedAtMs = cached2?.fetchedAtMs;
39358
39524
  const block = {
@@ -39360,16 +39526,25 @@ function createPluginBlock(build, policyStore) {
39360
39526
  version: build.version,
39361
39527
  ossVersion: build.ossVersion ?? null,
39362
39528
  policyBundleVersion: cached2 !== null && StorePosturePlugin.shape.policyBundleVersion.safeParse(cached2.bundle.version).success ? cached2.bundle.version : null,
39363
- policyFetchedAt: fetchedAtMs !== void 0 && fetchedAtMs > 0 && StorePosturePlugin.shape.policyFetchedAt.safeParse(fetchedAtMs).success ? fetchedAtMs : null
39529
+ policyFetchedAt: fetchedAtMs !== void 0 && fetchedAtMs > 0 && StorePosturePlugin.shape.policyFetchedAt.safeParse(fetchedAtMs).success ? fetchedAtMs : null,
39530
+ ...installed === void 0 ? {} : { installedVersion: await installed },
39531
+ buildSchemaVersion: SQLITE_MIGRATIONS.length
39364
39532
  };
39365
39533
  return StorePosturePlugin.safeParse(block).success ? block : void 0;
39366
39534
  };
39367
39535
  }
39536
+ async function readInstalledVersionBounded(installRoot) {
39537
+ try {
39538
+ return await withTimeout(readInstalledVersion(installRoot), INSTALL_RECORD_READ_TIMEOUT_MS);
39539
+ } catch {
39540
+ return null;
39541
+ }
39542
+ }
39368
39543
 
39369
39544
  // ../../packages/plugin-runtime/src/attached/policy-store.ts
39370
39545
  import { randomUUID as randomUUID16 } from "crypto";
39371
- import { readFile as readFile2, rm, writeFile as writeFile2 } from "fs/promises";
39372
- import { join as join28 } from "path";
39546
+ import { readFile as readFile3, rm, writeFile as writeFile2 } from "fs/promises";
39547
+ import { join as join29 } from "path";
39373
39548
 
39374
39549
  // ../../packages/plugin-runtime/src/attached/atomic-publish.ts
39375
39550
  import { rename as rename2 } from "fs/promises";
@@ -39377,11 +39552,11 @@ var RETRYABLE = /* @__PURE__ */ new Set(["EPERM", "EACCES", "EBUSY"]);
39377
39552
  var IMMEDIATE_RETRIES = 8;
39378
39553
  var TIMED_RETRIES = 4;
39379
39554
  var ATTEMPTS = 1 + IMMEDIATE_RETRIES + TIMED_RETRIES;
39380
- var delay = (ms) => new Promise((resolve2) => {
39381
- setTimeout(resolve2, ms);
39555
+ var delay = (ms) => new Promise((resolve3) => {
39556
+ setTimeout(resolve3, ms);
39382
39557
  });
39383
- var yieldToLoop = () => new Promise((resolve2) => {
39384
- setImmediate(resolve2);
39558
+ var yieldToLoop = () => new Promise((resolve3) => {
39559
+ setImmediate(resolve3);
39385
39560
  });
39386
39561
  async function publishByRename(tmp, file2, move = rename2) {
39387
39562
  for (let attempt = 1; ; attempt += 1) {
@@ -39398,10 +39573,10 @@ async function publishByRename(tmp, file2, move = rename2) {
39398
39573
 
39399
39574
  // ../../packages/plugin-runtime/src/attached/policy-store.ts
39400
39575
  function createPolicyStore(dir = dataDir()) {
39401
- const file2 = join28(dir, "policy-cache.json");
39576
+ const file2 = join29(dir, "policy-cache.json");
39402
39577
  async function read() {
39403
39578
  try {
39404
- const raw = await readFile2(file2, "utf8");
39579
+ const raw = await readFile3(file2, "utf8");
39405
39580
  const parsed2 = JSON.parse(raw);
39406
39581
  if (typeof parsed2 !== "object" || parsed2 === null) return null;
39407
39582
  const record2 = parsed2;
@@ -39423,7 +39598,7 @@ function createPolicyStore(dir = dataDir()) {
39423
39598
  }
39424
39599
  async function priorRecord() {
39425
39600
  try {
39426
- const parsed2 = JSON.parse(await readFile2(file2, "utf8"));
39601
+ const parsed2 = JSON.parse(await readFile3(file2, "utf8"));
39427
39602
  return typeof parsed2 === "object" && parsed2 !== null ? parsed2 : null;
39428
39603
  } catch {
39429
39604
  return null;
@@ -39469,7 +39644,7 @@ function createPolicyStore(dir = dataDir()) {
39469
39644
 
39470
39645
  // ../../packages/plugin-runtime/src/attached/posture-report-state.ts
39471
39646
  import { readFileSync as readFileSync19 } from "fs";
39472
- import { join as join29 } from "path";
39647
+ import { join as join30 } from "path";
39473
39648
  var POSTURE_REPORT_STATE_FILENAME = ATTACHED_POSTURE_REPORT_FILENAME;
39474
39649
  var OUTCOME_KEYS = {
39475
39650
  ok: true,
@@ -39483,7 +39658,7 @@ var OUTCOME_KEYS = {
39483
39658
  };
39484
39659
  var OUTCOMES = new Set(Object.keys(OUTCOME_KEYS));
39485
39660
  function postureReportStatePath(dataDir2) {
39486
- return join29(dataDir2, POSTURE_REPORT_STATE_FILENAME);
39661
+ return join30(dataDir2, POSTURE_REPORT_STATE_FILENAME);
39487
39662
  }
39488
39663
  function writePostureReportState(dataDir2, state) {
39489
39664
  try {
@@ -39662,12 +39837,12 @@ function readStorePosture(dbPath2) {
39662
39837
 
39663
39838
  // ../../packages/plugin-runtime/src/attached/posture-store.ts
39664
39839
  import { randomUUID as randomUUID17 } from "crypto";
39665
- import { readFile as readFile3, rm as rm2, writeFile as writeFile3 } from "fs/promises";
39666
- import { join as join30 } from "path";
39840
+ import { readFile as readFile4, rm as rm2, writeFile as writeFile3 } from "fs/promises";
39841
+ import { join as join31 } from "path";
39667
39842
  var UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/;
39668
39843
  function createPostureStore(dir = settingsDir(), legacyDir) {
39669
- const file2 = join30(dir, "posture-state.json");
39670
- const legacyFile = legacyDir === void 0 ? null : join30(legacyDir, "posture-state.json");
39844
+ const file2 = join31(dir, "posture-state.json");
39845
+ const legacyFile = legacyDir === void 0 ? null : join31(legacyDir, "posture-state.json");
39671
39846
  async function persist(state) {
39672
39847
  await ensureDataDir(dir);
39673
39848
  const tmp = `${file2}.${randomUUID17()}.tmp`;
@@ -39682,7 +39857,7 @@ function createPostureStore(dir = settingsDir(), legacyDir) {
39682
39857
  async function readFrom(path) {
39683
39858
  let raw;
39684
39859
  try {
39685
- raw = await readFile3(path, "utf8");
39860
+ raw = await readFile4(path, "utf8");
39686
39861
  } catch (err) {
39687
39862
  const code = err.code;
39688
39863
  if (code === "ENOENT" || code === "ENOTDIR") return null;
@@ -39736,7 +39911,7 @@ function createPostureStore(dir = settingsDir(), legacyDir) {
39736
39911
 
39737
39912
  // ../../packages/plugin-runtime/src/attached/sync-state.ts
39738
39913
  import { readFileSync as readFileSync20 } from "fs";
39739
- import { join as join31 } from "path";
39914
+ import { join as join32 } from "path";
39740
39915
 
39741
39916
  // ../../packages/plugin-runtime/src/attached/status.ts
39742
39917
  var REFUSAL_LINES = {
@@ -39813,12 +39988,12 @@ var StandaloneDataGateway = class {
39813
39988
  // reconciler drops the whole pass and recovers it idempotently on the next read.
39814
39989
  recordLlmCalls(inputs) {
39815
39990
  if (inputs.length === 0) return Promise.resolve();
39816
- return new Promise((resolve2, reject) => {
39991
+ return new Promise((resolve3, reject) => {
39817
39992
  try {
39818
39993
  this.db.auditEvents.runInTransaction(() => {
39819
39994
  for (const input2 of inputs) this.db.auditEvents.insertLlmCall(input2);
39820
39995
  });
39821
- resolve2();
39996
+ resolve3();
39822
39997
  } catch (err) {
39823
39998
  reject(err instanceof Error ? err : new Error(String(err)));
39824
39999
  }
@@ -39830,12 +40005,12 @@ var StandaloneDataGateway = class {
39830
40005
  // drops the whole pass and recovers it idempotently next time.
39831
40006
  recordToolCalls(inputs) {
39832
40007
  if (inputs.length === 0) return Promise.resolve();
39833
- return new Promise((resolve2, reject) => {
40008
+ return new Promise((resolve3, reject) => {
39834
40009
  try {
39835
40010
  this.db.auditEvents.runInTransaction(() => {
39836
40011
  for (const input2 of inputs) this.writeToolCall(input2);
39837
40012
  });
39838
- resolve2();
40013
+ resolve3();
39839
40014
  } catch (err) {
39840
40015
  reject(err instanceof Error ? err : new Error(String(err)));
39841
40016
  }
@@ -40347,7 +40522,7 @@ function fenced(body) {
40347
40522
 
40348
40523
  // ../../packages/setup-wizard/src/remediation/rotation-checklist.ts
40349
40524
  import { writeFileSync as writeFileSync8 } from "fs";
40350
- import { join as join32 } from "path";
40525
+ import { join as join33 } from "path";
40351
40526
 
40352
40527
  // ../../packages/setup-wizard/src/triage/merge.ts
40353
40528
  var RANK = Object.fromEntries(
@@ -40357,7 +40532,7 @@ var RANK = Object.fromEntries(
40357
40532
  // ../../packages/setup-wizard/src/triage/plan-file.ts
40358
40533
  import { mkdtempSync, readFileSync as readFileSync21, rmdirSync, rmSync as rmSync7, writeFileSync as writeFileSync9 } from "fs";
40359
40534
  import { tmpdir } from "os";
40360
- import { basename as basename6, dirname as dirname6, join as join33 } from "path";
40535
+ import { basename as basename7, dirname as dirname7, join as join34 } from "path";
40361
40536
  var SuppressionEntrySchema = external_exports.object({
40362
40537
  ruleId: external_exports.string(),
40363
40538
  category: DetectionCategory,
@@ -40400,7 +40575,7 @@ var PersistedPlanSchema = external_exports.object({
40400
40575
 
40401
40576
  // src/skills-registry.ts
40402
40577
  import { readdirSync as readdirSync5, readFileSync as readFileSync22 } from "fs";
40403
- import { join as join34 } from "path";
40578
+ import { join as join35 } from "path";
40404
40579
  import { fileURLToPath as fileURLToPath5 } from "url";
40405
40580
  var SKILLS_DIR = fileURLToPath5(new URL("../skills", import.meta.url));
40406
40581