@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.
@@ -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
  }
@@ -23486,7 +23497,29 @@ var StorePosturePlugin = external_exports.object({
23486
23497
  */
23487
23498
  policyBundleVersion: external_exports.string().max(200).nullable(),
23488
23499
  /** Epoch millis, on the CLIENT clock, of that fetch. */
23489
- policyFetchedAt: external_exports.number().int().min(0).max(MAX_DATE_MS).nullable()
23500
+ policyFetchedAt: external_exports.number().int().min(0).max(MAX_DATE_MS).nullable(),
23501
+ /**
23502
+ * The newest version the host's own install record holds for this plugin —
23503
+ * what is on disk. After an update it leads `version` (the running copy) by
23504
+ * one launch. Null when no usable version can be read: no install record
23505
+ * (a plugin run from a checkout), no entry with a valid version, or every
23506
+ * such entry names an `installPath` that no longer exists; OPTIONAL, not
23507
+ * required, so a build that predates the member keeps getting its 200.
23508
+ * Bounded like `version`.
23509
+ */
23510
+ installedVersion: external_exports.string().max(64).nullable().optional(),
23511
+ /**
23512
+ * The local-store schema version this running build migrates a store to:
23513
+ * the number of store migrations it carries, the count it stamps into
23514
+ * `PRAGMA user_version`. A snapshot whose `schemaVersion` is above it
23515
+ * usually describes a store a newer build migrated. It is a hint, not a
23516
+ * verdict: the stamp is write-only, so a store whose count ran past this
23517
+ * build's while this build knows every migration in its ledger reads above
23518
+ * it too, which is why describeStoreSkew decides skew on ledger tags and
23519
+ * never on the count. OPTIONAL for the same reason as `installedVersion`;
23520
+ * bounded like `schemaVersion`.
23521
+ */
23522
+ buildSchemaVersion: external_exports.number().int().min(0).max(MAX_INT4).optional()
23490
23523
  }).meta({ id: "StorePosturePlugin" });
23491
23524
  var StorePostureSnapshot = external_exports.object({
23492
23525
  deviceId: external_exports.guid(),
@@ -25121,10 +25154,15 @@ var ParsedPointer = external_exports.object({
25121
25154
  });
25122
25155
  var VaultEntry = external_exports.object({
25123
25156
  pointerId: external_exports.string(),
25124
- // The keyed HMAC of the raw value under `exception.key`, and the epoch it was
25125
- // derived under. This is what a reveal-to-model grant matches on, and it rotates
25126
- // independently of the vault encryption key below.
25157
+ // The keyed HMAC of the EXACT raw bytes under `exception.key`, and the epoch it
25158
+ // was derived under. The vault's own dedupe key: a value and its invisibly
25159
+ // padded twin are two rows. It rotates independently of the vault encryption
25160
+ // key below. Never matched against an exception or grant.
25127
25161
  valueFingerprint: external_exports.string().regex(/^[0-9a-f]{64}$/),
25162
+ // The same HMAC over the raw with invisible padding removed: the identity a
25163
+ // reveal-to-model grant and every exception match on. Shared by a value and
25164
+ // its padded twin.
25165
+ valueIdentityFingerprint: external_exports.string().regex(/^[0-9a-f]{64}$/),
25128
25166
  fingerprintKeyVersion: external_exports.number().int().positive(),
25129
25167
  // The vault-key epoch this row's ciphertext was sealed under.
25130
25168
  keyVersion: external_exports.number().int().positive(),
@@ -25697,10 +25735,18 @@ var SeveritySummaryItem = external_exports.object({
25697
25735
  count: external_exports.number().int().nonnegative(),
25698
25736
  // Resolution-aware breakdown (optional, additive). Populated once findings
25699
25737
  // carry lifecycle state: `caught` = handled in-flight (enforced); `openAtRest`
25700
- // = still open with no in-flight enforcement (needs remediation). Absent on the
25701
- // legacy count-only response until the resolution feature lands.
25738
+ // = still open with no in-flight enforcement (needs remediation); `dismissed`
25739
+ // = closed by a human judgement rather than a fix — visible, but not counted as
25740
+ // needing remediation. The three are disjoint. Absent on the legacy count-only
25741
+ // response until the resolution feature lands.
25702
25742
  caught: external_exports.number().int().nonnegative().optional(),
25703
- openAtRest: external_exports.number().int().nonnegative().optional()
25743
+ openAtRest: external_exports.number().int().nonnegative().optional(),
25744
+ dismissed: external_exports.number().int().nonnegative().optional(),
25745
+ // The two halves of `caught`, for a reader that wants them apart: `handled` =
25746
+ // in-flight findings an enforcement action already contained; `resolved` =
25747
+ // at-rest findings closed out by fixing them. `handled + resolved === caught`.
25748
+ handled: external_exports.number().int().nonnegative().optional(),
25749
+ resolved: external_exports.number().int().nonnegative().optional()
25704
25750
  }).meta({ id: "SeveritySummaryItem" });
25705
25751
  var SeveritySummaryResponse = external_exports.object({
25706
25752
  // Sum of bySeverity[].count.
@@ -25708,6 +25754,9 @@ var SeveritySummaryResponse = external_exports.object({
25708
25754
  // Findings still open at rest (sum of bySeverity[].openAtRest). Optional and
25709
25755
  // additive — absent on the legacy response until the resolution feature lands.
25710
25756
  needsRemediation: external_exports.number().int().nonnegative().optional(),
25757
+ // Findings a user dismissed (sum of bySeverity[].dismissed). Excluded from
25758
+ // needsRemediation, and kept visible here so an accepted risk is not erased.
25759
+ dismissed: external_exports.number().int().nonnegative().optional(),
25711
25760
  // All four severity levels are always present (count may be 0).
25712
25761
  bySeverity: external_exports.array(SeveritySummaryItem)
25713
25762
  }).meta({ id: "SeveritySummaryResponse" });
@@ -26305,11 +26354,11 @@ function repairOrRefuseMode(file2) {
26305
26354
  const link = lstatSync2(file2, { throwIfNoEntry: false });
26306
26355
  if (link === void 0) return "absent";
26307
26356
  if (link.isSymbolicLink()) return "untrusted";
26308
- const stat = statSync(file2, { throwIfNoEntry: false });
26309
- if (stat === void 0) return "absent";
26357
+ const stat2 = statSync(file2, { throwIfNoEntry: false });
26358
+ if (stat2 === void 0) return "absent";
26310
26359
  const uid = process.getuid?.();
26311
- if (uid !== void 0 && stat.uid !== uid) return "untrusted";
26312
- if (process.platform !== "win32" && (stat.mode & 511) !== DATA_FILE_MODE) {
26360
+ if (uid !== void 0 && stat2.uid !== uid) return "untrusted";
26361
+ if (process.platform !== "win32" && (stat2.mode & 511) !== DATA_FILE_MODE) {
26313
26362
  try {
26314
26363
  chmodSync2(file2, DATA_FILE_MODE);
26315
26364
  } catch {
@@ -32458,7 +32507,10 @@ var SqliteResolutionsRepository = class {
32458
32507
  * Insert many dispositions as ONE transaction — all of them or none.
32459
32508
  *
32460
32509
  * A dashboard dismissal closes every open finding of a rule, which is one
32461
- * write per key; run loose, a fault partway leaves half a rule closed with
32510
+ * write per key. It reaches this through
32511
+ * `LocalDatabase.dismissOpenFindingsForRule`, which calls it inside the
32512
+ * transaction that selected the keys, so there it runs as a SAVEPOINT of
32513
+ * that transaction. Run loose, a fault partway leaves half a rule closed with
32462
32514
  * nothing recording that the other half was meant to be. The caller then has
32463
32515
  * no way to tell a partial run from a complete one, because the card it
32464
32516
  * refreshes into just shows a smaller number either way.
@@ -32678,6 +32730,7 @@ function toSighting(row) {
32678
32730
  var SELECT_COLUMNS = `
32679
32731
  pointer_id AS pointerId,
32680
32732
  value_fingerprint AS valueFingerprint,
32733
+ value_identity_fingerprint AS valueIdentityFingerprint,
32681
32734
  fingerprint_key_version AS fingerprintKeyVersion,
32682
32735
  key_version AS keyVersion,
32683
32736
  format_version AS formatVersion,
@@ -32702,13 +32755,13 @@ var SqliteSecretVaultRepository = class {
32702
32755
  this.db = db;
32703
32756
  this.insertStmt = db.prepare(
32704
32757
  `INSERT INTO secret_vault (
32705
- pointer_id, value_fingerprint, fingerprint_key_version, key_version,
32706
- format_version, category, rule_id, masked_match, provider,
32758
+ pointer_id, value_fingerprint, value_identity_fingerprint,
32759
+ fingerprint_key_version, key_version, format_version, category, rule_id, masked_match, provider,
32707
32760
  ciphertext, nonce, auth_tag,
32708
32761
  user_authorized, occurrence_count, first_seen, last_seen
32709
32762
  ) VALUES (
32710
- :pointerId, :valueFingerprint, :fingerprintKeyVersion, :keyVersion,
32711
- :formatVersion, :category, :ruleId, :maskedMatch, :provider,
32763
+ :pointerId, :valueFingerprint, :valueIdentityFingerprint,
32764
+ :fingerprintKeyVersion, :keyVersion, :formatVersion, :category, :ruleId, :maskedMatch, :provider,
32712
32765
  :ciphertext, :nonce, :authTag,
32713
32766
  :userAuthorized, 1, :now, :now
32714
32767
  )`
@@ -32733,7 +32786,13 @@ var SqliteSecretVaultRepository = class {
32733
32786
  );
32734
32787
  this.refreshFingerprintStmt = db.prepare(
32735
32788
  `UPDATE secret_vault
32736
- SET value_fingerprint = :valueFingerprint, fingerprint_key_version = :fingerprintKeyVersion
32789
+ SET value_fingerprint = :valueFingerprint,
32790
+ value_identity_fingerprint = :valueIdentityFingerprint,
32791
+ fingerprint_key_version = :fingerprintKeyVersion
32792
+ WHERE pointer_id = :pointerId`
32793
+ );
32794
+ this.setIdentityStmt = db.prepare(
32795
+ `UPDATE secret_vault SET value_identity_fingerprint = :valueIdentityFingerprint
32737
32796
  WHERE pointer_id = :pointerId`
32738
32797
  );
32739
32798
  this.deleteByPointerStmt = db.prepare(`DELETE FROM secret_vault WHERE pointer_id = :pointerId`);
@@ -32750,6 +32809,7 @@ var SqliteSecretVaultRepository = class {
32750
32809
  listStmt;
32751
32810
  replaceCiphertextStmt;
32752
32811
  refreshFingerprintStmt;
32812
+ setIdentityStmt;
32753
32813
  deleteByPointerStmt;
32754
32814
  derefStmt;
32755
32815
  /**
@@ -32780,6 +32840,7 @@ var SqliteSecretVaultRepository = class {
32780
32840
  bindParams({
32781
32841
  pointerId: input2.pointerId,
32782
32842
  valueFingerprint: input2.valueFingerprint,
32843
+ valueIdentityFingerprint: input2.valueIdentityFingerprint,
32783
32844
  fingerprintKeyVersion: input2.fingerprintKeyVersion,
32784
32845
  keyVersion: input2.keyVersion,
32785
32846
  formatVersion: input2.formatVersion ?? POINTER_FORMAT_VERSION,
@@ -32841,7 +32902,15 @@ var SqliteSecretVaultRepository = class {
32841
32902
  replaceCiphertext(pointerId, next) {
32842
32903
  this.replaceCiphertextStmt.run({ pointerId, ...next });
32843
32904
  }
32844
- /** Re-derive an entry's fingerprint under a new fingerprint-key epoch. */
32905
+ /**
32906
+ * Correct an entry's identity fingerprint in place, leaving its exact
32907
+ * fingerprint and key epoch alone. For a row whose identity column still holds
32908
+ * the exact value copied in by the migration that added it.
32909
+ */
32910
+ setIdentityFingerprint(pointerId, valueIdentityFingerprint) {
32911
+ this.setIdentityStmt.run({ pointerId, valueIdentityFingerprint });
32912
+ }
32913
+ /** Re-derive an entry's fingerprints under a new fingerprint-key epoch. */
32845
32914
  refreshFingerprint(pointerId, next) {
32846
32915
  this.refreshFingerprintStmt.run({ pointerId, ...next });
32847
32916
  }
@@ -32972,7 +33041,7 @@ var SqliteSecretVaultRepository = class {
32972
33041
  `SELECT ${INVENTORY_COLUMNS},
32973
33042
  (SELECT e.id FROM exceptions e
32974
33043
  WHERE e.rule_id = v.rule_id
32975
- AND e.value_fingerprint = v.value_fingerprint
33044
+ AND e.value_fingerprint = v.value_identity_fingerprint
32976
33045
  AND e.key_version = v.fingerprint_key_version
32977
33046
  AND ${ACTIVE_REVEAL_GRANT_PREDICATE}
32978
33047
  LIMIT 1) AS grant_id
@@ -33015,7 +33084,7 @@ var SqliteSecretVaultRepository = class {
33015
33084
  `SELECT ${INVENTORY_COLUMNS},
33016
33085
  (SELECT e.id FROM exceptions e
33017
33086
  WHERE e.rule_id = v.rule_id
33018
- AND e.value_fingerprint = v.value_fingerprint
33087
+ AND e.value_fingerprint = v.value_identity_fingerprint
33019
33088
  AND e.key_version = v.fingerprint_key_version
33020
33089
  AND ${ACTIVE_REVEAL_GRANT_PREDICATE}
33021
33090
  LIMIT 1) AS grant_id
@@ -33119,6 +33188,18 @@ var OPEN_AT_REST_FINDINGS_SQL = `FROM inspection_findings f
33119
33188
  OR latest.status IS NULL
33120
33189
  OR latest.status NOT IN ('resolved', 'dismissed')
33121
33190
  )`;
33191
+ function selectOpenFindingKeysForRule(db, ruleId) {
33192
+ const rows = allRows(
33193
+ db.prepare(
33194
+ `SELECT DISTINCT f.finding_key AS finding_key
33195
+ ${OPEN_AT_REST_FINDINGS_SQL}
33196
+ AND d.rule_id = :ruleId
33197
+ AND f.finding_key IS NOT NULL`
33198
+ ),
33199
+ { ruleId }
33200
+ );
33201
+ return rows.map((r) => r.finding_key);
33202
+ }
33122
33203
  var SEVERITIES = ["critical", "high", "medium", "low"];
33123
33204
  var ACTION_TO_KIND = {
33124
33205
  block: "blocked",
@@ -33175,16 +33256,16 @@ var SqliteSecurityRepository = class {
33175
33256
  // findings are caught only once their latest disposition is resolved,
33176
33257
  // otherwise they are open-at-rest.
33177
33258
  //
33178
- // NOTE for future manual-resolution writers: only latest status
33179
- // 'resolved' counts as caught above. When acknowledged/dismissed/
33180
- // false-positive manual dispositions land, this must keep filtering by
33181
- // status/method — 'acknowledged' is accepted risk, not a fix, and must NOT
33182
- // be bucketed as caught alongside 'resolved'.
33259
+ // Only latest status 'resolved' counts as caught above. 'dismissed' is its
33260
+ // own bucket: a judgement rather than a fix, so it is neither caught nor
33261
+ // needing remediation, and stays countable. A further manual disposition
33262
+ // (acknowledged, false-positive) must be placed deliberately — 'acknowledged'
33263
+ // is accepted risk, not a fix, and must NOT be bucketed as caught.
33183
33264
  //
33184
33265
  // Legacy at-rest findings from pre-branch scans carry finding_key = NULL —
33185
33266
  // the resolution lifecycle is keyed by finding_key, so it can never attach a
33186
33267
  // disposition to (or clear) one of these on re-scan. They are excluded from
33187
- // both caught and openAtRest (untracked, not "needs remediation forever"),
33268
+ // all three buckets (untracked, not "needs remediation forever"),
33188
33269
  // but still counted in total/count below — this keeps this predicate
33189
33270
  // consistent with SqliteResolutionsRepository.openAtRestKeysForPath, which
33190
33271
  // already filters `finding_key IS NOT NULL`.
@@ -33207,12 +33288,25 @@ var SqliteSecurityRepository = class {
33207
33288
  WHEN latest.status = 'resolved' THEN 1
33208
33289
  ELSE 0
33209
33290
  END) AS caught,
33291
+ SUM(CASE WHEN e.event_type != 'code_change' THEN 1 ELSE 0 END) AS handled,
33210
33292
  SUM(CASE
33211
33293
  WHEN e.event_type = 'code_change'
33212
33294
  AND f.finding_key IS NOT NULL
33213
- AND (latest.status IS NULL OR latest.status != 'resolved') THEN 1
33295
+ AND latest.status = 'resolved' THEN 1
33214
33296
  ELSE 0
33215
- END) AS open_at_rest
33297
+ END) AS resolved,
33298
+ SUM(CASE
33299
+ WHEN e.event_type = 'code_change'
33300
+ AND f.finding_key IS NOT NULL
33301
+ AND (latest.status IS NULL
33302
+ OR latest.status NOT IN ('resolved', 'dismissed')) THEN 1
33303
+ ELSE 0
33304
+ END) AS open_at_rest,
33305
+ SUM(CASE
33306
+ WHEN e.event_type = 'code_change'
33307
+ AND latest.status = 'dismissed' THEN 1
33308
+ ELSE 0
33309
+ END) AS dismissed
33216
33310
  FROM inspection_findings f
33217
33311
  JOIN audit_events e INDEXED BY idx_audit_capture_rollup ON e.id = f.audit_event_id
33218
33312
  JOIN inspection_definitions d ON d.id = f.inspection_definition_id
@@ -33227,11 +33321,15 @@ var SqliteSecurityRepository = class {
33227
33321
  severity,
33228
33322
  count: byRow.get(severity)?.count ?? 0,
33229
33323
  caught: byRow.get(severity)?.caught ?? 0,
33230
- openAtRest: byRow.get(severity)?.open_at_rest ?? 0
33324
+ handled: byRow.get(severity)?.handled ?? 0,
33325
+ resolved: byRow.get(severity)?.resolved ?? 0,
33326
+ openAtRest: byRow.get(severity)?.open_at_rest ?? 0,
33327
+ dismissed: byRow.get(severity)?.dismissed ?? 0
33231
33328
  }));
33232
33329
  const total = bySeverity.reduce((sum, s) => sum + s.count, 0);
33233
33330
  const needsRemediation = bySeverity.reduce((sum, s) => sum + s.openAtRest, 0);
33234
- return Promise.resolve({ total, needsRemediation, bySeverity });
33331
+ const dismissed = bySeverity.reduce((sum, s) => sum + s.dismissed, 0);
33332
+ return Promise.resolve({ total, needsRemediation, dismissed, bySeverity });
33235
33333
  }
33236
33334
  // Range is echoed but does not change the result today — coverage is a constant
33237
33335
  // business fact (see SCAN_COVERAGE), not a measured per-window metric. Order
@@ -33548,10 +33646,10 @@ var SqliteSecurityRepository = class {
33548
33646
  * machine, and the second reported "no recommendations" over live exposure.
33549
33647
  *
33550
33648
  * `open` mirrors `deriveFindingStatus` — at-rest, minus resolved and dismissed —
33551
- * so a row's count is exactly what `?status=open&type=<rule>` returns. Note that
33552
- * is NOT `severitySummary`'s `openAtRest`, which keeps dismissed findings (a
33553
- * dismissal is a judgement, not a remediation) and drops untracked legacy rows.
33554
- * The two answer different questions and only this one has to match a link.
33649
+ * so a row's count is exactly what `?status=open&type=<rule>` returns. It
33650
+ * differs from `severitySummary`'s `openAtRest` only in including untracked
33651
+ * legacy rows, which that bucket leaves out; dismissed is excluded from both.
33652
+ * Only this one has to match a link.
33555
33653
  *
33556
33654
  * Aggregated in SQL: the result is O(distinct rule × category × severity), so a
33557
33655
  * whole-store scope costs a grouped scan rather than a row per finding.
@@ -33579,6 +33677,8 @@ var SqliteSecurityRepository = class {
33579
33677
  /**
33580
33678
  * The distinct `finding_key`s behind ONE rule's {@link recommendationInputs}
33581
33679
  * tally — what a dashboard dismissal of that row writes a disposition for.
33680
+ * The dismissal itself does not call this: it reads the same set through
33681
+ * {@link selectOpenFindingKeysForRule}, inside its own write transaction.
33582
33682
  *
33583
33683
  * It shares {@link OPEN_AT_REST_FINDINGS_SQL} with the count rather than
33584
33684
  * restating the predicate, because a dismissal has to act on exactly the set
@@ -33595,16 +33695,7 @@ var SqliteSecurityRepository = class {
33595
33695
  * this set SMALLER than the tally, never larger.
33596
33696
  */
33597
33697
  openFindingKeysForRule(ruleId) {
33598
- const rows = allRows(
33599
- this.db.prepare(
33600
- `SELECT DISTINCT f.finding_key AS finding_key
33601
- ${OPEN_AT_REST_FINDINGS_SQL}
33602
- AND d.rule_id = :ruleId
33603
- AND f.finding_key IS NOT NULL`
33604
- ),
33605
- { ruleId }
33606
- );
33607
- return Promise.resolve(rows.map((r) => r.finding_key));
33698
+ return Promise.resolve(selectOpenFindingKeysForRule(this.db, ruleId));
33608
33699
  }
33609
33700
  // Findings whose parent event occurred in [fromMs, toMs), with the parent's
33610
33701
  // epoch-millis timestamp. started_at is an INTEGER column, so the bounds stay
@@ -34650,6 +34741,31 @@ function openLocalDatabase(dir, options = {}) {
34650
34741
  );
34651
34742
  });
34652
34743
  }
34744
+ function dismissOpenFindingsForRule(ruleId, disposition) {
34745
+ let dismissed = 0;
34746
+ withTransaction(
34747
+ db,
34748
+ () => {
34749
+ const keys = selectOpenFindingKeysForRule(db, ruleId);
34750
+ resolutions.insertResolutions(
34751
+ keys.map((findingKey) => ({
34752
+ findingKey,
34753
+ status: "dismissed",
34754
+ method: disposition.method,
34755
+ resolvedAt: disposition.resolvedAt,
34756
+ evidence: disposition.evidence
34757
+ }))
34758
+ );
34759
+ dismissed = keys.length;
34760
+ },
34761
+ // IMMEDIATE takes the write lock at BEGIN, before the select, which is
34762
+ // what keeps a concurrent resolve out of the gap. It also makes waiting
34763
+ // on a busy writer an ordinary busy_timeout wait rather than a
34764
+ // read-to-write upgrade SQLite refuses to retry.
34765
+ "IMMEDIATE"
34766
+ );
34767
+ return dismissed;
34768
+ }
34653
34769
  function recordCapture(event, detected) {
34654
34770
  failOpenTransaction(db, () => {
34655
34771
  const sessionId = event.metadata?.sessionId;
@@ -34833,6 +34949,7 @@ function openLocalDatabase(dir, options = {}) {
34833
34949
  inspectionDefinitions,
34834
34950
  inspectionFindings,
34835
34951
  recordCapture,
34952
+ dismissOpenFindingsForRule,
34836
34953
  markCaptureDelivered,
34837
34954
  markCaptureOwed,
34838
34955
  markAuditEventsDelivered,
@@ -35128,7 +35245,7 @@ async function send(options) {
35128
35245
  }
35129
35246
  }
35130
35247
  };
35131
- return new Promise((resolve2, reject) => {
35248
+ return new Promise((resolve3, reject) => {
35132
35249
  let settled = false;
35133
35250
  const fail = (reason, status) => {
35134
35251
  if (settled) return;
@@ -35154,7 +35271,7 @@ async function send(options) {
35154
35271
  res.on("end", () => {
35155
35272
  if (settled) return;
35156
35273
  settled = true;
35157
- resolve2({
35274
+ resolve3({
35158
35275
  status: res.statusCode ?? 0,
35159
35276
  headers: res.headers,
35160
35277
  body: Buffer.concat(chunks).toString("utf8")
@@ -36133,6 +36250,10 @@ function escapeRegExp2(value) {
36133
36250
  return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
36134
36251
  }
36135
36252
 
36253
+ // ../../packages/detections/src/format-chars.ts
36254
+ var HAS_FORMAT_CHAR = new RegExp("\\p{Cf}", "u");
36255
+ var FORMAT_CHAR_GLOBAL = new RegExp("\\p{Cf}", "gu");
36256
+
36136
36257
  // ../../packages/detections/src/regex-cache.ts
36137
36258
  var singles = /* @__PURE__ */ new WeakMap();
36138
36259
  var keywordLists = /* @__PURE__ */ new WeakMap();
@@ -39207,10 +39328,55 @@ import { spawn } from "child_process";
39207
39328
  import { fileURLToPath as fileURLToPath2 } from "url";
39208
39329
  var HISTORY_SYNC_THROTTLE_MS = 5 * 60 * 1e3;
39209
39330
 
39331
+ // ../../packages/plugin-runtime/src/attached/install-record.ts
39332
+ import { readFile as readFile2, stat } from "fs/promises";
39333
+ import { basename as basename6, dirname as dirname6, join as join28, resolve as resolve2 } from "path";
39334
+ async function readInstalledVersion(installRoot) {
39335
+ try {
39336
+ const versionDir = resolve2(installRoot);
39337
+ const pluginDir = dirname6(versionDir);
39338
+ const marketplaceDir = dirname6(pluginDir);
39339
+ const cacheDir = dirname6(marketplaceDir);
39340
+ if (basename6(cacheDir) !== "cache") return null;
39341
+ const key = `${basename6(pluginDir)}@${basename6(marketplaceDir)}`;
39342
+ const record2 = JSON.parse(
39343
+ await readFile2(join28(dirname6(cacheDir), "installed_plugins.json"), "utf8")
39344
+ );
39345
+ const plugins = record2?.plugins;
39346
+ if (typeof plugins !== "object" || plugins === null || !Object.hasOwn(plugins, key)) {
39347
+ return null;
39348
+ }
39349
+ const entries = plugins[key];
39350
+ if (!Array.isArray(entries)) return null;
39351
+ let newest = null;
39352
+ for (const entry of entries) {
39353
+ const { version: version2, installPath } = entry ?? {};
39354
+ if (typeof version2 !== "string" || !isParseableBinaryVersion(version2)) continue;
39355
+ if (!StorePosturePlugin.shape.installedVersion.safeParse(version2).success) continue;
39356
+ if (newest !== null && compareBinaryVersions(version2, newest) <= 0) continue;
39357
+ if (typeof installPath === "string" && !await exists(installPath)) continue;
39358
+ newest = version2;
39359
+ }
39360
+ return newest;
39361
+ } catch {
39362
+ return null;
39363
+ }
39364
+ }
39365
+ async function exists(path) {
39366
+ try {
39367
+ await stat(path);
39368
+ return true;
39369
+ } catch {
39370
+ return false;
39371
+ }
39372
+ }
39373
+
39210
39374
  // ../../packages/plugin-runtime/src/attached/plugin-block.ts
39211
39375
  import { readFileSync as readFileSync18 } from "fs";
39376
+ var INSTALL_RECORD_READ_TIMEOUT_MS = REQUEST_TIMEOUT_MS / 2;
39212
39377
  function createPluginBlock(build, policyStore) {
39213
39378
  return async () => {
39379
+ const installed = build.installRoot === void 0 ? void 0 : readInstalledVersionBounded(build.installRoot);
39214
39380
  const cached2 = await policyStore.read();
39215
39381
  const fetchedAtMs = cached2?.fetchedAtMs;
39216
39382
  const block = {
@@ -39218,16 +39384,25 @@ function createPluginBlock(build, policyStore) {
39218
39384
  version: build.version,
39219
39385
  ossVersion: build.ossVersion ?? null,
39220
39386
  policyBundleVersion: cached2 !== null && StorePosturePlugin.shape.policyBundleVersion.safeParse(cached2.bundle.version).success ? cached2.bundle.version : null,
39221
- policyFetchedAt: fetchedAtMs !== void 0 && fetchedAtMs > 0 && StorePosturePlugin.shape.policyFetchedAt.safeParse(fetchedAtMs).success ? fetchedAtMs : null
39387
+ policyFetchedAt: fetchedAtMs !== void 0 && fetchedAtMs > 0 && StorePosturePlugin.shape.policyFetchedAt.safeParse(fetchedAtMs).success ? fetchedAtMs : null,
39388
+ ...installed === void 0 ? {} : { installedVersion: await installed },
39389
+ buildSchemaVersion: SQLITE_MIGRATIONS.length
39222
39390
  };
39223
39391
  return StorePosturePlugin.safeParse(block).success ? block : void 0;
39224
39392
  };
39225
39393
  }
39394
+ async function readInstalledVersionBounded(installRoot) {
39395
+ try {
39396
+ return await withTimeout(readInstalledVersion(installRoot), INSTALL_RECORD_READ_TIMEOUT_MS);
39397
+ } catch {
39398
+ return null;
39399
+ }
39400
+ }
39226
39401
 
39227
39402
  // ../../packages/plugin-runtime/src/attached/policy-store.ts
39228
39403
  import { randomUUID as randomUUID16 } from "crypto";
39229
- import { readFile as readFile2, rm, writeFile as writeFile2 } from "fs/promises";
39230
- import { join as join28 } from "path";
39404
+ import { readFile as readFile3, rm, writeFile as writeFile2 } from "fs/promises";
39405
+ import { join as join29 } from "path";
39231
39406
 
39232
39407
  // ../../packages/plugin-runtime/src/attached/atomic-publish.ts
39233
39408
  import { rename as rename2 } from "fs/promises";
@@ -39235,11 +39410,11 @@ var RETRYABLE = /* @__PURE__ */ new Set(["EPERM", "EACCES", "EBUSY"]);
39235
39410
  var IMMEDIATE_RETRIES = 8;
39236
39411
  var TIMED_RETRIES = 4;
39237
39412
  var ATTEMPTS = 1 + IMMEDIATE_RETRIES + TIMED_RETRIES;
39238
- var delay = (ms) => new Promise((resolve2) => {
39239
- setTimeout(resolve2, ms);
39413
+ var delay = (ms) => new Promise((resolve3) => {
39414
+ setTimeout(resolve3, ms);
39240
39415
  });
39241
- var yieldToLoop = () => new Promise((resolve2) => {
39242
- setImmediate(resolve2);
39416
+ var yieldToLoop = () => new Promise((resolve3) => {
39417
+ setImmediate(resolve3);
39243
39418
  });
39244
39419
  async function publishByRename(tmp, file2, move = rename2) {
39245
39420
  for (let attempt = 1; ; attempt += 1) {
@@ -39256,10 +39431,10 @@ async function publishByRename(tmp, file2, move = rename2) {
39256
39431
 
39257
39432
  // ../../packages/plugin-runtime/src/attached/policy-store.ts
39258
39433
  function createPolicyStore(dir = dataDir()) {
39259
- const file2 = join28(dir, "policy-cache.json");
39434
+ const file2 = join29(dir, "policy-cache.json");
39260
39435
  async function read() {
39261
39436
  try {
39262
- const raw = await readFile2(file2, "utf8");
39437
+ const raw = await readFile3(file2, "utf8");
39263
39438
  const parsed2 = JSON.parse(raw);
39264
39439
  if (typeof parsed2 !== "object" || parsed2 === null) return null;
39265
39440
  const record2 = parsed2;
@@ -39281,7 +39456,7 @@ function createPolicyStore(dir = dataDir()) {
39281
39456
  }
39282
39457
  async function priorRecord() {
39283
39458
  try {
39284
- const parsed2 = JSON.parse(await readFile2(file2, "utf8"));
39459
+ const parsed2 = JSON.parse(await readFile3(file2, "utf8"));
39285
39460
  return typeof parsed2 === "object" && parsed2 !== null ? parsed2 : null;
39286
39461
  } catch {
39287
39462
  return null;
@@ -39327,7 +39502,7 @@ function createPolicyStore(dir = dataDir()) {
39327
39502
 
39328
39503
  // ../../packages/plugin-runtime/src/attached/posture-report-state.ts
39329
39504
  import { readFileSync as readFileSync19 } from "fs";
39330
- import { join as join29 } from "path";
39505
+ import { join as join30 } from "path";
39331
39506
  var POSTURE_REPORT_STATE_FILENAME = ATTACHED_POSTURE_REPORT_FILENAME;
39332
39507
  var OUTCOME_KEYS = {
39333
39508
  ok: true,
@@ -39341,7 +39516,7 @@ var OUTCOME_KEYS = {
39341
39516
  };
39342
39517
  var OUTCOMES = new Set(Object.keys(OUTCOME_KEYS));
39343
39518
  function postureReportStatePath(dataDir2) {
39344
- return join29(dataDir2, POSTURE_REPORT_STATE_FILENAME);
39519
+ return join30(dataDir2, POSTURE_REPORT_STATE_FILENAME);
39345
39520
  }
39346
39521
  function writePostureReportState(dataDir2, state) {
39347
39522
  try {
@@ -39520,12 +39695,12 @@ function readStorePosture(dbPath2) {
39520
39695
 
39521
39696
  // ../../packages/plugin-runtime/src/attached/posture-store.ts
39522
39697
  import { randomUUID as randomUUID17 } from "crypto";
39523
- import { readFile as readFile3, rm as rm2, writeFile as writeFile3 } from "fs/promises";
39524
- import { join as join30 } from "path";
39698
+ import { readFile as readFile4, rm as rm2, writeFile as writeFile3 } from "fs/promises";
39699
+ import { join as join31 } from "path";
39525
39700
  var UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/;
39526
39701
  function createPostureStore(dir = settingsDir(), legacyDir) {
39527
- const file2 = join30(dir, "posture-state.json");
39528
- const legacyFile = legacyDir === void 0 ? null : join30(legacyDir, "posture-state.json");
39702
+ const file2 = join31(dir, "posture-state.json");
39703
+ const legacyFile = legacyDir === void 0 ? null : join31(legacyDir, "posture-state.json");
39529
39704
  async function persist(state) {
39530
39705
  await ensureDataDir(dir);
39531
39706
  const tmp = `${file2}.${randomUUID17()}.tmp`;
@@ -39540,7 +39715,7 @@ function createPostureStore(dir = settingsDir(), legacyDir) {
39540
39715
  async function readFrom(path) {
39541
39716
  let raw;
39542
39717
  try {
39543
- raw = await readFile3(path, "utf8");
39718
+ raw = await readFile4(path, "utf8");
39544
39719
  } catch (err) {
39545
39720
  const code = err.code;
39546
39721
  if (code === "ENOENT" || code === "ENOTDIR") return null;
@@ -39594,7 +39769,7 @@ function createPostureStore(dir = settingsDir(), legacyDir) {
39594
39769
 
39595
39770
  // ../../packages/plugin-runtime/src/attached/sync-state.ts
39596
39771
  import { readFileSync as readFileSync20 } from "fs";
39597
- import { join as join31 } from "path";
39772
+ import { join as join32 } from "path";
39598
39773
 
39599
39774
  // ../../packages/plugin-runtime/src/attached/status.ts
39600
39775
  var REFUSAL_LINES = {
@@ -39671,12 +39846,12 @@ var StandaloneDataGateway = class {
39671
39846
  // reconciler drops the whole pass and recovers it idempotently on the next read.
39672
39847
  recordLlmCalls(inputs) {
39673
39848
  if (inputs.length === 0) return Promise.resolve();
39674
- return new Promise((resolve2, reject) => {
39849
+ return new Promise((resolve3, reject) => {
39675
39850
  try {
39676
39851
  this.db.auditEvents.runInTransaction(() => {
39677
39852
  for (const input2 of inputs) this.db.auditEvents.insertLlmCall(input2);
39678
39853
  });
39679
- resolve2();
39854
+ resolve3();
39680
39855
  } catch (err) {
39681
39856
  reject(err instanceof Error ? err : new Error(String(err)));
39682
39857
  }
@@ -39688,12 +39863,12 @@ var StandaloneDataGateway = class {
39688
39863
  // drops the whole pass and recovers it idempotently next time.
39689
39864
  recordToolCalls(inputs) {
39690
39865
  if (inputs.length === 0) return Promise.resolve();
39691
- return new Promise((resolve2, reject) => {
39866
+ return new Promise((resolve3, reject) => {
39692
39867
  try {
39693
39868
  this.db.auditEvents.runInTransaction(() => {
39694
39869
  for (const input2 of inputs) this.writeToolCall(input2);
39695
39870
  });
39696
- resolve2();
39871
+ resolve3();
39697
39872
  } catch (err) {
39698
39873
  reject(err instanceof Error ? err : new Error(String(err)));
39699
39874
  }
@@ -40182,7 +40357,7 @@ function show(body) {
40182
40357
 
40183
40358
  // ../../packages/setup-wizard/src/remediation/rotation-checklist.ts
40184
40359
  import { writeFileSync as writeFileSync8 } from "fs";
40185
- import { join as join32 } from "path";
40360
+ import { join as join33 } from "path";
40186
40361
 
40187
40362
  // ../../packages/setup-wizard/src/triage/merge.ts
40188
40363
  var RANK = Object.fromEntries(
@@ -40192,7 +40367,7 @@ var RANK = Object.fromEntries(
40192
40367
  // ../../packages/setup-wizard/src/triage/plan-file.ts
40193
40368
  import { mkdtempSync, readFileSync as readFileSync21, rmdirSync, rmSync as rmSync7, writeFileSync as writeFileSync9 } from "fs";
40194
40369
  import { tmpdir } from "os";
40195
- import { basename as basename6, dirname as dirname6, join as join33 } from "path";
40370
+ import { basename as basename7, dirname as dirname7, join as join34 } from "path";
40196
40371
  var SuppressionEntrySchema = external_exports.object({
40197
40372
  ruleId: external_exports.string(),
40198
40373
  category: DetectionCategory,
@@ -40235,7 +40410,7 @@ var PersistedPlanSchema = external_exports.object({
40235
40410
 
40236
40411
  // src/skills-registry.ts
40237
40412
  import { readdirSync as readdirSync5, readFileSync as readFileSync22 } from "fs";
40238
- import { join as join34 } from "path";
40413
+ import { join as join35 } from "path";
40239
40414
  import { fileURLToPath as fileURLToPath5 } from "url";
40240
40415
  var SKILLS_DIR = fileURLToPath5(new URL("../skills", import.meta.url));
40241
40416
  function frontmatterName(content) {
@@ -40248,7 +40423,7 @@ function readRegisteredSkills() {
40248
40423
  return readdirSync5(SKILLS_DIR, { withFileTypes: true }).filter((entry) => entry.isDirectory()).flatMap((entry) => {
40249
40424
  let content;
40250
40425
  try {
40251
- content = readFileSync22(join34(SKILLS_DIR, entry.name, "SKILL.md"), "utf8");
40426
+ content = readFileSync22(join35(SKILLS_DIR, entry.name, "SKILL.md"), "utf8");
40252
40427
  } catch {
40253
40428
  return [];
40254
40429
  }