@akasecurity/ai-tc-claude-code 0.9.2 → 0.9.4

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.
@@ -492,7 +492,7 @@ var require_ignore = __commonJS({
492
492
  });
493
493
 
494
494
  // ../../packages/persistence/src/database.ts
495
- import { randomUUID as randomUUID8 } from "crypto";
495
+ import { randomUUID as randomUUID9 } from "crypto";
496
496
  import { existsSync, renameSync as renameSync2, rmSync as rmSync2 } from "fs";
497
497
  import { join, sep } from "path";
498
498
  import { DatabaseSync } from "node:sqlite";
@@ -558,6 +558,22 @@ var SQLITE_MIGRATIONS = [
558
558
  {
559
559
  tag: "0014_drop_legacy_events_findings",
560
560
  sql: "-- Custom migration: drops the frozen legacy `events`/`findings` tables\n-- (superseded by audit_events/inspection_definitions/inspection_findings) and\n-- replaces them with read-only views of the same name.\n--\n-- persistence's migrations.ts applies this migration ONLY once the batched\n-- history backfill (see runLegacyHistoryBackfill) has fully drained both\n-- tables, and only after copying the live file aside \u2014 see\n-- backupBeforeLegacyDrop in packages/persistence/src/migrations.ts. A store\n-- still mid-copy keeps its real tables and this migration stays pending.\n--\n-- The views exist for skew: the `aka` CLI and the Claude Code plugin update\n-- independently against one shared store, so an older, already-installed\n-- binary can open a store a newer binary already dropped these tables on.\n-- Every already-shipped repository constructor prepares its SQL eagerly at\n-- open time, so a bare \"table not found\" would fail the WHOLE open, not just\n-- a findings-specific read \u2014 these views keep `prepare()` succeeding so an\n-- old binary's unrelated features keep working; its own reads stay truthful,\n-- and its rare (already fail-open) writes fail at run time instead.\n--\n-- The 0009/0010 expression indexes existed only over the legacy `events`\n-- table; DROP TABLE below would remove them implicitly, but they are\n-- dropped explicitly first so the intent reads clearly. IF EXISTS so a store\n-- that reached here with an index missing out of band (an adopted-tag store\n-- whose physical index was never built) does not throw a deterministic \"no\n-- such index\" out of the fail-open drop path.\nDROP INDEX IF EXISTS `idx_events_code_change_path`;\n--> statement-breakpoint\nDROP INDEX IF EXISTS `idx_events_session_id`;\n--> statement-breakpoint\n-- `findings.event_id` references `events.id` \u2014 drop the child first.\nDROP TABLE `findings`;\n--> statement-breakpoint\nDROP TABLE `events`;\n--> statement-breakpoint\n-- Legacy `events` shape, projected from audit_events: `kind`/`occurred_at`/\n-- `source_tool` become real columns again (source_tool round-trips through\n-- the attributes bag, the only place a capture-typed audit row keeps it);\n-- `metadata` is reconstructed as the old camelCase JSON object from the new\n-- snake_case attributes bag, with `root_session_id` folded back in as\n-- `sessionId` (the one legacy metadata key that became a column, never an\n-- attribute, on the new table). Constrained to the four capture kinds so\n-- structural rows (session/run/tool_call/llm_call/source_lookup/config_scan)\n-- never leak into a legacy reader's result set \u2014 the old `events` table\n-- never held them either.\nCREATE VIEW `events` AS\nSELECT\n id,\n json_extract(attributes, '$.source_tool') AS source_tool,\n event_type AS kind,\n started_at AS occurred_at,\n content_hash,\n content,\n -- Plugin-local bookkeeping column that `ensureSyncedAtColumn` adds to the\n -- real `events` table at open time. A pre-cutover binary runs that probe on\n -- EVERY open; without this projection its `columnNames('events')` check\n -- misses `synced_at` and issues `ALTER TABLE events ADD COLUMN` against this\n -- view, which SQLite rejects (\"Cannot add a column to a view\") \u2014 a hard,\n -- non-fail-open crash of the whole open, the exact skew failure these views\n -- exist to prevent. Projecting it (always NULL; no reader consumes it)\n -- short-circuits that ALTER.\n NULL AS synced_at,\n json_object(\n 'sessionId', root_session_id,\n 'repo', json_extract(attributes, '$.repo'),\n 'filePath', json_extract(attributes, '$.file_path'),\n 'toolName', json_extract(attributes, '$.tool_name'),\n 'gitignored', json_extract(attributes, '$.gitignored'),\n 'wholeFile', json_extract(attributes, '$.whole_file'),\n 'model', json_extract(attributes, '$.model'),\n 'turnIndex', json_extract(attributes, '$.turn_index'),\n 'correlationId', json_extract(attributes, '$.correlation_id'),\n 'traceId', json_extract(attributes, '$.trace_id'),\n 'exceptionIds', json_extract(attributes, '$.exception_ids')\n ) AS metadata\nFROM audit_events\nWHERE event_type IN ('prompt', 'response', 'code_change', 'tool_use');\n--> statement-breakpoint\n-- A plain single-row INSERT (the old writer's shape \u2014 no ON CONFLICT) is\n-- accepted by prepare() against a view once an INSTEAD OF INSERT trigger\n-- exists, so it fails at run time instead of at open \u2014 landing in the same\n-- fail-open path the caller already wraps its write in.\nCREATE TRIGGER `trg_events_ro`\nINSTEAD OF INSERT ON `events`\nBEGIN SELECT RAISE(ABORT, 'events is read-only; write to audit_events instead'); END;\n--> statement-breakpoint\n-- Legacy `findings` shape: rule_id/category/severity come from the joined\n-- inspection_definitions row (the legacy table inlined them per-row; the\n-- generalized schema normalizes them out into the shared definition). A view\n-- has no rowid of its own, so the underlying table's rowid is re-exposed\n-- explicitly under that name \u2014 a legacy reader ordering by `f.rowid` would\n-- otherwise fail to resolve the column at all. Joined to audit_events for the\n-- same four-capture-kind constraint as the events view above (a finding\n-- attached to a tool_call/config_scan row never existed in the legacy table\n-- either \u2014 see the persistence findings repository's identical predicate).\nCREATE VIEW `findings` AS\nSELECT\n f.id AS id,\n f.rowid AS rowid,\n f.audit_event_id AS event_id,\n d.rule_id AS rule_id,\n d.category AS category,\n d.severity AS severity,\n f.span_start AS span_start,\n f.span_end AS span_end,\n f.masked_match AS masked_match,\n f.action_taken AS action_taken,\n f.confidence AS confidence,\n f.finding_key AS finding_key,\n f.first_detected_at AS first_detected_at\nFROM inspection_findings f\nJOIN audit_events e ON e.id = f.audit_event_id\nJOIN inspection_definitions d ON d.id = f.inspection_definition_id\nWHERE e.event_type IN ('prompt', 'response', 'code_change', 'tool_use');\n--> statement-breakpoint\n-- Defense in depth only: SQLite refuses to plan ANY upsert against a view\n-- (\"cannot UPSERT a view\") no matter what trigger exists, so this can never\n-- rescue the real legacy writer, which always used\n-- `ON CONFLICT (finding_key) DO UPDATE` \u2014 that statement still fails at\n-- prepare() on an old binary, same as it would with no trigger at all. This\n-- only covers a plain-INSERT shape, should one ever exist.\nCREATE TRIGGER `trg_findings_ro`\nINSTEAD OF INSERT ON `findings`\nBEGIN SELECT RAISE(ABORT, 'findings is read-only; write to inspection_findings instead'); END;\n"
561
+ },
562
+ {
563
+ tag: "0015_busy_vengeance",
564
+ sql: "CREATE TABLE `secret_vault` (\n `pointer_id` text PRIMARY KEY NOT NULL,\n `value_fingerprint` text NOT NULL,\n `fingerprint_key_version` integer NOT NULL,\n `key_version` integer NOT NULL,\n `category` text NOT NULL,\n `rule_id` text NOT NULL,\n `masked_match` text NOT NULL,\n `provider` text,\n `ciphertext` text NOT NULL,\n `nonce` text NOT NULL,\n `auth_tag` text NOT NULL,\n `occurrence_count` integer DEFAULT 1 NOT NULL,\n `first_seen` integer NOT NULL,\n `last_seen` integer NOT NULL\n);\n--> statement-breakpoint\nCREATE UNIQUE INDEX `uq_secret_vault_value` ON `secret_vault` (`value_fingerprint`);--> statement-breakpoint\nCREATE TABLE `secret_vault_deref` (\n `id` text PRIMARY KEY NOT NULL,\n `pointer_id` text NOT NULL,\n `at` integer NOT NULL,\n `target` text NOT NULL,\n `reason` text NOT NULL,\n `outcome` text NOT NULL,\n `grant_id` text,\n `pointer_count` integer DEFAULT 1 NOT NULL\n);\n--> statement-breakpoint\nCREATE INDEX `idx_secret_vault_deref_pointer` ON `secret_vault_deref` (`pointer_id`);--> statement-breakpoint\nCREATE INDEX `idx_secret_vault_deref_reason_at` ON `secret_vault_deref` (`reason`,`at`);"
565
+ },
566
+ {
567
+ tag: "0016_breezy_zodiak",
568
+ sql: "ALTER TABLE `exceptions` ADD `capability` text DEFAULT 'suppress' NOT NULL;"
569
+ },
570
+ {
571
+ tag: "0017_rainy_kat_farrell",
572
+ sql: "CREATE TABLE `secret_vault_sighting` (\n `id` text PRIMARY KEY NOT NULL,\n `pointer_id` text NOT NULL,\n `location` text NOT NULL,\n `kind` text NOT NULL,\n `first_seen` integer NOT NULL,\n `last_seen` integer NOT NULL\n);\n--> statement-breakpoint\nCREATE UNIQUE INDEX `uq_secret_vault_sighting` ON `secret_vault_sighting` (`pointer_id`,`location`);"
573
+ },
574
+ {
575
+ tag: "0018_serious_tana_nile",
576
+ sql: "ALTER TABLE `secret_vault` ADD `format_version` integer DEFAULT 2 NOT NULL;"
561
577
  }
562
578
  ];
563
579
 
@@ -16214,6 +16230,7 @@ var ExceptionConditions = external_exports.object({
16214
16230
  sourceTool: external_exports.string().optional(),
16215
16231
  provider: external_exports.string().optional()
16216
16232
  }).strict();
16233
+ var ExceptionCapability = external_exports.enum(["suppress", "reveal_to_model"]);
16217
16234
  var DetectionException = external_exports.object({
16218
16235
  id: external_exports.guid(),
16219
16236
  ruleId: external_exports.string(),
@@ -16230,6 +16247,7 @@ var DetectionException = external_exports.object({
16230
16247
  keyVersion: external_exports.number().int().positive(),
16231
16248
  // maskMatch() preview of the approved value — never the raw value.
16232
16249
  maskedValue: external_exports.string(),
16250
+ capability: ExceptionCapability.default("suppress"),
16233
16251
  scope: ExceptionScope,
16234
16252
  expiresAt: external_exports.iso.datetime().nullable(),
16235
16253
  maxUses: external_exports.number().int().positive().nullable(),
@@ -16253,6 +16271,7 @@ var ExceptionBundleEntry = DetectionException.pick({
16253
16271
  ruleId: true,
16254
16272
  valueFingerprint: true,
16255
16273
  keyVersion: true,
16274
+ capability: true,
16256
16275
  expiresAt: true,
16257
16276
  maxUses: true,
16258
16277
  useCount: true,
@@ -17357,8 +17376,117 @@ var PatchInstalledPackRequest = external_exports.object({
17357
17376
  message: "At least one field must be provided"
17358
17377
  }).meta({ id: "PatchInstalledPackRequest" });
17359
17378
 
17379
+ // ../../packages/schema/src/zod/vault.ts
17380
+ var POINTER_FORMAT_VERSION = 2;
17381
+ var CATEGORY_ALTERNATION = DetectionCategory.options.join("|");
17382
+ var POINTER_TOKEN_PATTERN = new RegExp(
17383
+ `\\[\\[aka:(?:${CATEGORY_ALTERNATION}):[A-Z2-7]{2,7}\\.[A-Z2-7]{26}\\.[A-Z2-7]{16}\\]\\]`
17384
+ );
17385
+ var POINTER_TOKEN_ANCHORED = new RegExp(`^${POINTER_TOKEN_PATTERN.source}$`);
17386
+ var PointerToken = external_exports.string().regex(POINTER_TOKEN_ANCHORED);
17387
+ var ParsedPointer = external_exports.object({
17388
+ category: DetectionCategory,
17389
+ keyVersion: external_exports.number().int().positive(),
17390
+ pointerId: external_exports.string(),
17391
+ tag: external_exports.string()
17392
+ });
17393
+ var VaultEntry = external_exports.object({
17394
+ pointerId: external_exports.string(),
17395
+ // The keyed HMAC of the raw value under `exception.key`, and the epoch it was
17396
+ // derived under. This is what a reveal-to-model grant matches on, and it rotates
17397
+ // independently of the vault encryption key below.
17398
+ valueFingerprint: external_exports.string().regex(/^[0-9a-f]{64}$/),
17399
+ fingerprintKeyVersion: external_exports.number().int().positive(),
17400
+ // The vault-key epoch this row's ciphertext was sealed under.
17401
+ keyVersion: external_exports.number().int().positive(),
17402
+ // Fixed at first mint and never updated: the same value detected later under a
17403
+ // different rule's category keeps the category it was minted with, so one
17404
+ // value always produces exactly one wire token.
17405
+ category: DetectionCategory,
17406
+ ruleId: external_exports.string(),
17407
+ // Partial-reveal preview for badges and listings. Never the raw value.
17408
+ maskedMatch: external_exports.string(),
17409
+ provider: external_exports.string().optional(),
17410
+ ciphertext: external_exports.string(),
17411
+ nonce: external_exports.string(),
17412
+ authTag: external_exports.string(),
17413
+ // How many times this value has been detected on this machine — the reuse
17414
+ // signal the vault dashboard reads. Distinct from VaultDeref.pointerCount.
17415
+ occurrenceCount: external_exports.number().int().nonnegative(),
17416
+ firstSeen: external_exports.string(),
17417
+ lastSeen: external_exports.string()
17418
+ });
17419
+ var PointerDescriptor = external_exports.object({
17420
+ category: DetectionCategory,
17421
+ provider: external_exports.string().optional(),
17422
+ maskedMatch: external_exports.string(),
17423
+ occurrences: external_exports.number().int().nonnegative(),
17424
+ firstSeen: external_exports.string(),
17425
+ lastSeen: external_exports.string()
17426
+ });
17427
+ var PointerIdentity = external_exports.object({
17428
+ ruleId: external_exports.string(),
17429
+ valueFingerprint: external_exports.string().regex(/^[0-9a-f]{64}$/),
17430
+ fingerprintKeyVersion: external_exports.number().int().positive()
17431
+ });
17432
+ var DetokenizeTarget = external_exports.enum(["human", "model"]);
17433
+ var VaultDerefReason = external_exports.enum([
17434
+ "display",
17435
+ "explicit-reveal",
17436
+ "view-render",
17437
+ "model-input",
17438
+ "remediation",
17439
+ "purge"
17440
+ ]);
17441
+ var VaultDerefOutcome = external_exports.enum(["revealed", "refused", "unavailable"]);
17442
+ var VaultDeref = external_exports.object({
17443
+ id: external_exports.guid(),
17444
+ pointerId: external_exports.string(),
17445
+ at: external_exports.string(),
17446
+ target: DetokenizeTarget,
17447
+ reason: VaultDerefReason,
17448
+ outcome: VaultDerefOutcome,
17449
+ // Present only on a model-target crossing that a reveal grant authorized.
17450
+ grantId: external_exports.string().optional(),
17451
+ // How many pointers ONE batched render resolved. 1 for unbatched rows. Named
17452
+ // apart from VaultEntry.occurrenceCount, which counts detections of a value.
17453
+ pointerCount: external_exports.number().int().positive().default(1)
17454
+ });
17455
+ var VaultSightingKind = external_exports.enum([
17456
+ "prompt",
17457
+ "tool-input",
17458
+ "tool-output",
17459
+ "file",
17460
+ "transcript"
17461
+ ]);
17462
+ var VaultSighting = external_exports.object({
17463
+ location: external_exports.string(),
17464
+ kind: VaultSightingKind,
17465
+ firstSeen: external_exports.string(),
17466
+ lastSeen: external_exports.string()
17467
+ });
17468
+ var VaultInventoryEntry = external_exports.object({
17469
+ pointerId: external_exports.string(),
17470
+ category: DetectionCategory,
17471
+ provider: external_exports.string().optional(),
17472
+ maskedMatch: external_exports.string(),
17473
+ occurrences: external_exports.number().int().nonnegative(),
17474
+ firstSeen: external_exports.string(),
17475
+ lastSeen: external_exports.string(),
17476
+ // The active reveal-to-model grant covering this value, when one exists —
17477
+ // the inventory badges it, the row links to revocation.
17478
+ revealGrantId: external_exports.string().nullable(),
17479
+ sightings: external_exports.array(VaultSighting)
17480
+ });
17481
+ var VaultKeyCustody = external_exports.string();
17482
+ var VaultInlineReveal = external_exports.enum(["masked", "full", "off"]);
17483
+ var VaultConsent = external_exports.object({
17484
+ acknowledgedAt: external_exports.iso.datetime(),
17485
+ version: external_exports.number().int().positive()
17486
+ });
17487
+
17360
17488
  // ../../packages/schema/src/zod/local.ts
17361
- var WORKSPACE_SETTINGS_SPEC_VERSION = 4;
17489
+ var WORKSPACE_SETTINGS_SPEC_VERSION = 5;
17362
17490
  var RunMode = external_exports.enum(["standalone"]);
17363
17491
  var SimpleDetectionPolicy = external_exports.enum(["redact", "warn"]);
17364
17492
  var HistoricalAccess = external_exports.enum(["full", "session-only"]);
@@ -17380,6 +17508,16 @@ var WorkspaceSettings = external_exports.object({
17380
17508
  // In-place egress extraction on the scan paths; disable to stop all Data
17381
17509
  // Shares writes.
17382
17510
  dataSharesInPlace: external_exports.boolean().default(true),
17511
+ // Consent to keep a RECOVERABLE encrypted copy of detected values in the local
17512
+ // vault, instead of destroying them. Absent by default: this is a custody
17513
+ // change from one-way redaction, so it is never an assumed grant on upgrade.
17514
+ // Revoking stops future vaulting; it does not erase what is already stored —
17515
+ // purging the vault is the eraser.
17516
+ vaultConsent: VaultConsent.optional(),
17517
+ // Where the vault master key lives.
17518
+ vaultKeyCustody: VaultKeyCustody.default("file"),
17519
+ // How a pointer renders in assistant prose on screen (see VaultInlineReveal).
17520
+ vaultInlineReveal: VaultInlineReveal.default("masked"),
17383
17521
  // Absent until /aka:setup completes; its presence is what "onboarded" means.
17384
17522
  onboardedAt: external_exports.iso.datetime().optional(),
17385
17523
  // Records that the user consented to sending findings to the model API for
@@ -19777,6 +19915,9 @@ var AmbiguousExceptionIdError = class extends Error {
19777
19915
  var ACTIVE_PREDICATE = `revoked_at IS NULL
19778
19916
  AND (expires_at IS NULL OR expires_at > :now)
19779
19917
  AND (max_uses IS NULL OR use_count < max_uses)`;
19918
+ var ACTIVE_REVEAL_GRANT_PREDICATE = `capability = 'reveal_to_model'
19919
+ AND conditions IS NULL
19920
+ AND ${ACTIVE_PREDICATE}`;
19780
19921
  var SqliteExceptionsRepository = class {
19781
19922
  constructor(db) {
19782
19923
  this.db = db;
@@ -19868,11 +20009,11 @@ var SqliteExceptionsRepository = class {
19868
20009
  this.db.prepare(
19869
20010
  `INSERT INTO exceptions (
19870
20011
  id, rule_id, category, value_fingerprint, key_version, masked_value,
19871
- scope, expires_at, max_uses, use_count, last_used_at, justification,
19872
- conditions, created_by, created_via, created_at, updated_at
20012
+ capability, scope, expires_at, max_uses, use_count, last_used_at,
20013
+ justification, conditions, created_by, created_via, created_at, updated_at
19873
20014
  ) VALUES (
19874
20015
  :id, :ruleId, :category, :valueFingerprint, :keyVersion, :maskedValue,
19875
- :scope, :expiresAt, :maxUses, 0, NULL, :justification,
20016
+ :capability, :scope, :expiresAt, :maxUses, 0, NULL, :justification,
19876
20017
  :conditions, :createdBy, :createdVia, :now, :now
19877
20018
  )`
19878
20019
  ).run({
@@ -19882,6 +20023,7 @@ var SqliteExceptionsRepository = class {
19882
20023
  valueFingerprint: input.valueFingerprint,
19883
20024
  keyVersion: input.keyVersion,
19884
20025
  maskedValue: input.maskedValue,
20026
+ capability: input.capability ?? "suppress",
19885
20027
  scope: input.scope,
19886
20028
  expiresAt: input.expiresAt === null ? null : isoToEpochMillis(input.expiresAt),
19887
20029
  maxUses: input.maxUses,
@@ -19975,6 +20117,7 @@ var SqliteExceptionsRepository = class {
19975
20117
  ruleId: row.rule_id,
19976
20118
  valueFingerprint: row.value_fingerprint,
19977
20119
  keyVersion: row.key_version,
20120
+ capability: row.capability,
19978
20121
  expiresAt: row.expires_at === null ? null : epochMillisToIso(row.expires_at),
19979
20122
  maxUses: row.max_uses,
19980
20123
  useCount: row.use_count,
@@ -20029,6 +20172,35 @@ var SqliteExceptionsRepository = class {
20029
20172
  }))
20030
20173
  );
20031
20174
  }
20175
+ /**
20176
+ * The active reveal-to-model grant for a vaulted value's identity, or null.
20177
+ * Matching is exact on (ruleId, valueFingerprint, keyVersion) — the same key
20178
+ * suppression uses — plus the capability: a suppression grant must never
20179
+ * authorize a reveal. Read-only: the caller does NOT consume here, because a
20180
+ * revealed value re-enters the detection scan immediately afterward and the
20181
+ * suppression match there claims the use — one crossing, one use.
20182
+ *
20183
+ * A grant with `conditions` NEVER matches here: the reveal path does not yet
20184
+ * evaluate conditions, and a narrowing clause that is ignored would WIDEN the
20185
+ * grant instead. Fail closed until reveal-side condition evaluation exists.
20186
+ */
20187
+ activeRevealGrant(ruleId, valueFingerprint, keyVersion, now = Date.now()) {
20188
+ try {
20189
+ const row = getRow(
20190
+ this.db.prepare(
20191
+ `SELECT id FROM exceptions
20192
+ WHERE rule_id = :ruleId AND value_fingerprint = :valueFingerprint
20193
+ AND key_version = :keyVersion
20194
+ AND ${ACTIVE_REVEAL_GRANT_PREDICATE}
20195
+ LIMIT 1`
20196
+ ),
20197
+ { ruleId, valueFingerprint, keyVersion, now }
20198
+ );
20199
+ return Promise.resolve(row ?? null);
20200
+ } catch (err) {
20201
+ return Promise.reject(err instanceof Error ? err : new Error(String(err)));
20202
+ }
20203
+ }
20032
20204
  /**
20033
20205
  * Retention sweep: delete TERMINAL rows (revoked, expired, or use-budget
20034
20206
  * exhausted) whose last transition is older than the retention window.
@@ -20056,6 +20228,7 @@ function parseExceptionRow(row) {
20056
20228
  valueFingerprint: row.value_fingerprint,
20057
20229
  keyVersion: row.key_version,
20058
20230
  maskedValue: row.masked_value,
20231
+ capability: row.capability,
20059
20232
  scope: row.scope,
20060
20233
  expiresAt: row.expires_at === null ? null : epochMillisToIso(row.expires_at),
20061
20234
  maxUses: row.max_uses,
@@ -22221,6 +22394,287 @@ var SqliteScanLedgerRepository = class {
22221
22394
  }
22222
22395
  };
22223
22396
 
22397
+ // ../../packages/persistence/src/repositories/secret-vault.ts
22398
+ import { randomUUID as randomUUID7 } from "crypto";
22399
+ var SELECT_COLUMNS = `
22400
+ pointer_id AS pointerId,
22401
+ value_fingerprint AS valueFingerprint,
22402
+ fingerprint_key_version AS fingerprintKeyVersion,
22403
+ key_version AS keyVersion,
22404
+ format_version AS formatVersion,
22405
+ category,
22406
+ rule_id AS ruleId,
22407
+ masked_match AS maskedMatch,
22408
+ provider,
22409
+ ciphertext,
22410
+ nonce,
22411
+ auth_tag AS authTag,
22412
+ occurrence_count AS occurrenceCount,
22413
+ first_seen AS firstSeen,
22414
+ last_seen AS lastSeen`;
22415
+ function toRow(raw) {
22416
+ const { provider, ...rest } = raw;
22417
+ return provider === null ? rest : { ...rest, provider };
22418
+ }
22419
+ var SqliteSecretVaultRepository = class {
22420
+ constructor(db) {
22421
+ this.db = db;
22422
+ this.insertStmt = db.prepare(
22423
+ `INSERT INTO secret_vault (
22424
+ pointer_id, value_fingerprint, fingerprint_key_version, key_version,
22425
+ format_version, category, rule_id, masked_match, provider,
22426
+ ciphertext, nonce, auth_tag,
22427
+ occurrence_count, first_seen, last_seen
22428
+ ) VALUES (
22429
+ :pointerId, :valueFingerprint, :fingerprintKeyVersion, :keyVersion,
22430
+ :formatVersion, :category, :ruleId, :maskedMatch, :provider,
22431
+ :ciphertext, :nonce, :authTag,
22432
+ 1, :now, :now
22433
+ )`
22434
+ );
22435
+ this.bumpStmt = db.prepare(
22436
+ `UPDATE secret_vault
22437
+ SET occurrence_count = occurrence_count + 1, last_seen = :now
22438
+ WHERE value_fingerprint = :valueFingerprint`
22439
+ );
22440
+ this.byPointerStmt = db.prepare(
22441
+ `SELECT ${SELECT_COLUMNS} FROM secret_vault WHERE pointer_id = :pointerId`
22442
+ );
22443
+ this.byFingerprintStmt = db.prepare(
22444
+ `SELECT ${SELECT_COLUMNS} FROM secret_vault WHERE value_fingerprint = :valueFingerprint`
22445
+ );
22446
+ this.listStmt = db.prepare(`SELECT ${SELECT_COLUMNS} FROM secret_vault ORDER BY first_seen`);
22447
+ this.replaceCiphertextStmt = db.prepare(
22448
+ `UPDATE secret_vault
22449
+ SET key_version = :keyVersion, ciphertext = :ciphertext, nonce = :nonce, auth_tag = :authTag
22450
+ WHERE pointer_id = :pointerId`
22451
+ );
22452
+ this.refreshFingerprintStmt = db.prepare(
22453
+ `UPDATE secret_vault
22454
+ SET value_fingerprint = :valueFingerprint, fingerprint_key_version = :fingerprintKeyVersion
22455
+ WHERE pointer_id = :pointerId`
22456
+ );
22457
+ this.derefStmt = db.prepare(
22458
+ `INSERT INTO secret_vault_deref (id, pointer_id, at, target, reason, outcome, grant_id, pointer_count)
22459
+ VALUES (:id, :pointerId, :at, :target, :reason, :outcome, :grantId, :pointerCount)`
22460
+ );
22461
+ }
22462
+ db;
22463
+ insertStmt;
22464
+ bumpStmt;
22465
+ byPointerStmt;
22466
+ byFingerprintStmt;
22467
+ listStmt;
22468
+ replaceCiphertextStmt;
22469
+ refreshFingerprintStmt;
22470
+ derefStmt;
22471
+ /**
22472
+ * Vault a value, or record another sighting of one already vaulted. Keyed on
22473
+ * `valueFingerprint`, never on the caller's pointer id: a value seen again
22474
+ * bumps `occurrence_count` and `last_seen` and comes back with its ORIGINAL
22475
+ * pointer, category and ciphertext, so the same secret always resolves to one
22476
+ * wire token. `minted` is true only when this call created the row.
22477
+ *
22478
+ * The read-then-write runs in one IMMEDIATE transaction so two concurrent
22479
+ * writers cannot both decide they are minting.
22480
+ */
22481
+ upsert(input, now) {
22482
+ let minted = false;
22483
+ withTransaction(
22484
+ this.db,
22485
+ () => {
22486
+ const existing = getRow(this.byFingerprintStmt, {
22487
+ valueFingerprint: input.valueFingerprint
22488
+ });
22489
+ if (existing === void 0) {
22490
+ this.insertStmt.run(
22491
+ bindParams({
22492
+ pointerId: input.pointerId,
22493
+ valueFingerprint: input.valueFingerprint,
22494
+ fingerprintKeyVersion: input.fingerprintKeyVersion,
22495
+ keyVersion: input.keyVersion,
22496
+ formatVersion: input.formatVersion ?? POINTER_FORMAT_VERSION,
22497
+ category: input.category,
22498
+ ruleId: input.ruleId,
22499
+ maskedMatch: input.maskedMatch,
22500
+ provider: input.provider,
22501
+ ciphertext: input.ciphertext,
22502
+ nonce: input.nonce,
22503
+ authTag: input.authTag,
22504
+ now
22505
+ })
22506
+ );
22507
+ minted = true;
22508
+ return;
22509
+ }
22510
+ this.bumpStmt.run({ valueFingerprint: input.valueFingerprint, now });
22511
+ },
22512
+ "IMMEDIATE"
22513
+ );
22514
+ const row = getRow(this.byFingerprintStmt, {
22515
+ valueFingerprint: input.valueFingerprint
22516
+ });
22517
+ if (row === void 0) throw new Error("vault: row vanished immediately after write");
22518
+ return { row: toRow(row), minted };
22519
+ }
22520
+ byPointerId(pointerId) {
22521
+ const raw = getRow(this.byPointerStmt, { pointerId });
22522
+ return raw === void 0 ? null : toRow(raw);
22523
+ }
22524
+ byValueFingerprint(fingerprint) {
22525
+ const raw = getRow(this.byFingerprintStmt, { valueFingerprint: fingerprint });
22526
+ return raw === void 0 ? null : toRow(raw);
22527
+ }
22528
+ /** Append one audit row. Carries no raw value and no ciphertext, by shape. */
22529
+ recordDeref(entry) {
22530
+ this.derefStmt.run(
22531
+ bindParams({
22532
+ id: entry.id,
22533
+ pointerId: entry.pointerId,
22534
+ at: entry.at,
22535
+ target: entry.target,
22536
+ reason: entry.reason,
22537
+ outcome: entry.outcome,
22538
+ grantId: entry.grantId,
22539
+ pointerCount: entry.pointerCount ?? 1
22540
+ })
22541
+ );
22542
+ }
22543
+ listAll() {
22544
+ return allRows(this.listStmt).map(toRow);
22545
+ }
22546
+ /** Re-seal an entry under a new key epoch, leaving its identity untouched. */
22547
+ replaceCiphertext(pointerId, next) {
22548
+ this.replaceCiphertextStmt.run({ pointerId, ...next });
22549
+ }
22550
+ /** Re-derive an entry's fingerprint under a new fingerprint-key epoch. */
22551
+ refreshFingerprint(pointerId, next) {
22552
+ this.refreshFingerprintStmt.run({ pointerId, ...next });
22553
+ }
22554
+ /**
22555
+ * Destroy every vaulted value and report how many were destroyed. The deref
22556
+ * audit is left alone on purpose — see the table note above.
22557
+ */
22558
+ purgeAll() {
22559
+ let destroyed = 0;
22560
+ withTransaction(
22561
+ this.db,
22562
+ () => {
22563
+ destroyed = this.countEntries();
22564
+ this.db.exec("DELETE FROM secret_vault");
22565
+ },
22566
+ "IMMEDIATE"
22567
+ );
22568
+ return destroyed;
22569
+ }
22570
+ /**
22571
+ * Record (or re-stamp) one place a pointer has been written. One row per
22572
+ * (pointer, location); a re-sighting bumps last_seen. Best-effort bookkeeping
22573
+ * on hook paths — a failure must never affect the rewrite that triggered it,
22574
+ * so callers wrap this, not the other way around.
22575
+ */
22576
+ recordSighting(entry, now) {
22577
+ this.db.prepare(
22578
+ `INSERT INTO secret_vault_sighting (id, pointer_id, location, kind, first_seen, last_seen)
22579
+ VALUES (:id, :pointerId, :location, :kind, :now, :now)
22580
+ ON CONFLICT (pointer_id, location) DO UPDATE SET last_seen = :now`
22581
+ ).run({
22582
+ id: randomUUID7(),
22583
+ pointerId: entry.pointerId,
22584
+ location: entry.location,
22585
+ kind: entry.kind,
22586
+ now
22587
+ });
22588
+ }
22589
+ listSightings(pointerId) {
22590
+ const rows = allRows(
22591
+ this.db.prepare(
22592
+ `SELECT location, kind, first_seen, last_seen FROM secret_vault_sighting
22593
+ WHERE pointer_id = :pointerId ORDER BY last_seen DESC`
22594
+ ),
22595
+ { pointerId }
22596
+ );
22597
+ return rows.map((r) => ({
22598
+ location: r.location,
22599
+ kind: r.kind,
22600
+ firstSeen: new Date(r.first_seen).toISOString(),
22601
+ lastSeen: new Date(r.last_seen).toISOString()
22602
+ }));
22603
+ }
22604
+ /**
22605
+ * The dashboard inventory: every vaulted value's descriptor data joined with
22606
+ * its sightings and the active reveal-to-model grant when one exists.
22607
+ * Raw-free by construction — neither the fingerprint nor the ciphertext
22608
+ * columns are selected.
22609
+ */
22610
+ listInventory(now = Date.now()) {
22611
+ const rows = allRows(
22612
+ this.db.prepare(
22613
+ `SELECT v.pointer_id, v.category, v.rule_id, v.masked_match, v.provider,
22614
+ v.occurrence_count, v.first_seen, v.last_seen,
22615
+ (SELECT e.id FROM exceptions e
22616
+ WHERE e.rule_id = v.rule_id
22617
+ AND e.value_fingerprint = v.value_fingerprint
22618
+ AND e.key_version = v.fingerprint_key_version
22619
+ AND ${ACTIVE_REVEAL_GRANT_PREDICATE}
22620
+ LIMIT 1) AS grant_id
22621
+ FROM secret_vault v
22622
+ ORDER BY v.last_seen DESC`
22623
+ ),
22624
+ { now }
22625
+ );
22626
+ return rows.map((r) => ({
22627
+ pointerId: r.pointer_id,
22628
+ category: r.category,
22629
+ ...r.provider === null ? {} : { provider: r.provider },
22630
+ maskedMatch: r.masked_match,
22631
+ occurrences: r.occurrence_count,
22632
+ firstSeen: new Date(r.first_seen).toISOString(),
22633
+ lastSeen: new Date(r.last_seen).toISOString(),
22634
+ revealGrantId: r.grant_id,
22635
+ sightings: this.listSightings(r.pointer_id)
22636
+ }));
22637
+ }
22638
+ /**
22639
+ * The de-reference trail, newest first. By default the batched, high-volume
22640
+ * reasons (display, view-render) are hidden and counted instead — the rows
22641
+ * that matter as a signal are the model crossings, and burying them under
22642
+ * render noise would defeat the audit's purpose.
22643
+ */
22644
+ listDerefs(opts) {
22645
+ const limit = opts?.limit ?? 200;
22646
+ const where = opts?.includeBatched === true ? "" : `WHERE reason NOT IN ('display', 'view-render')`;
22647
+ const rows = allRows(
22648
+ this.db.prepare(
22649
+ `SELECT id, pointer_id, at, target, reason, outcome, grant_id, pointer_count
22650
+ FROM secret_vault_deref ${where}
22651
+ ORDER BY at DESC, rowid DESC LIMIT :limit`
22652
+ ),
22653
+ { limit }
22654
+ );
22655
+ const hiddenBatched = opts?.includeBatched === true ? 0 : countScalar(
22656
+ this.db,
22657
+ `SELECT count(*) AS n FROM secret_vault_deref WHERE reason IN ('display', 'view-render')`
22658
+ );
22659
+ return {
22660
+ rows: rows.map((r) => ({
22661
+ id: r.id,
22662
+ pointerId: r.pointer_id,
22663
+ at: new Date(r.at).toISOString(),
22664
+ target: r.target,
22665
+ reason: r.reason,
22666
+ outcome: r.outcome,
22667
+ ...r.grant_id === null ? {} : { grantId: r.grant_id },
22668
+ pointerCount: r.pointer_count
22669
+ })),
22670
+ hiddenBatched
22671
+ };
22672
+ }
22673
+ countEntries() {
22674
+ return countScalar(this.db, "SELECT COUNT(*) AS n FROM secret_vault");
22675
+ }
22676
+ };
22677
+
22224
22678
  // ../../packages/persistence/src/repositories/security.ts
22225
22679
  var DAY_MS4 = 864e5;
22226
22680
  var SEVERITIES = ["critical", "high", "medium", "low"];
@@ -22566,7 +23020,7 @@ var SqliteSecurityRepository = class {
22566
23020
  };
22567
23021
 
22568
23022
  // ../../packages/persistence/src/repositories/shares.ts
22569
- import { randomUUID as randomUUID7 } from "crypto";
23023
+ import { randomUUID as randomUUID8 } from "crypto";
22570
23024
  var MAX_EGRESS_CALL_SITES_PER_PROJECT = 5e3;
22571
23025
  var IN_CHUNK = 500;
22572
23026
  var KIND_ORDER = ["provider", "internal", "external", "ip"];
@@ -22822,7 +23276,7 @@ var SqliteSharesRepository = class {
22822
23276
  (id, destination_id, host, decision, created_at, updated_at)
22823
23277
  VALUES (:id, :destinationId, :host, :decision, :now, :now)`
22824
23278
  ).run({
22825
- id: randomUUID7(),
23279
+ id: randomUUID8(),
22826
23280
  destinationId,
22827
23281
  host: dest.host,
22828
23282
  decision,
@@ -22971,7 +23425,7 @@ var SqliteSharesRepository = class {
22971
23425
  let destinationId = destIds.get(hit.host);
22972
23426
  if (destinationId === void 0) {
22973
23427
  destStmt.run({
22974
- id: randomUUID7(),
23428
+ id: randomUUID8(),
22975
23429
  kind: hit.kind,
22976
23430
  name: hit.name,
22977
23431
  host: hit.host,
@@ -22987,7 +23441,7 @@ var SqliteSharesRepository = class {
22987
23441
  let endpointId = endpointIds.get(endpointKey);
22988
23442
  if (endpointId === void 0) {
22989
23443
  endpointStmt.run({
22990
- id: randomUUID7(),
23444
+ id: randomUUID8(),
22991
23445
  destinationId,
22992
23446
  method: hit.method,
22993
23447
  transport: hit.transport,
@@ -23000,7 +23454,7 @@ var SqliteSharesRepository = class {
23000
23454
  endpointIds.set(endpointKey, endpointId);
23001
23455
  }
23002
23456
  siteStmt.run({
23003
- id: randomUUID7(),
23457
+ id: randomUUID8(),
23004
23458
  endpointId,
23005
23459
  project: input.project,
23006
23460
  projectKey: input.projectKey,
@@ -23368,11 +23822,22 @@ function purgeSampleData(db) {
23368
23822
  function linkHost(input, hostId) {
23369
23823
  return hostId ? { ...input, hostId } : input;
23370
23824
  }
23825
+ function closeQuietly(db) {
23826
+ try {
23827
+ db.close();
23828
+ } catch {
23829
+ }
23830
+ }
23371
23831
  function openWithPragmas(file2) {
23372
23832
  const db = new DatabaseSync(file2);
23373
- db.exec("PRAGMA journal_mode = WAL");
23374
- db.exec("PRAGMA busy_timeout = 2000");
23375
- db.exec("PRAGMA foreign_keys = ON");
23833
+ try {
23834
+ db.exec("PRAGMA journal_mode = WAL");
23835
+ db.exec("PRAGMA busy_timeout = 2000");
23836
+ db.exec("PRAGMA foreign_keys = ON");
23837
+ } catch (err) {
23838
+ closeQuietly(db);
23839
+ throw err;
23840
+ }
23376
23841
  return db;
23377
23842
  }
23378
23843
  function backupLegacyStore(file2) {
@@ -23384,43 +23849,82 @@ function backupLegacyStore(file2) {
23384
23849
  }
23385
23850
  return backup;
23386
23851
  }
23852
+ function openAndInitialize(file2) {
23853
+ let db = openWithPragmas(file2);
23854
+ try {
23855
+ if (isForeignSqliteLineage(db)) {
23856
+ db.close();
23857
+ const backup = backupLegacyStore(file2);
23858
+ db = openWithPragmas(file2);
23859
+ akaWarn(
23860
+ `Detected an older, incompatible (tenant-bearing) ${DB_FILENAME}; backed it up to ${backup} and created a fresh store.`
23861
+ );
23862
+ }
23863
+ applyMigrations(db, file2);
23864
+ tightenPerms(file2);
23865
+ const policies = new SqlitePoliciesRepository(db);
23866
+ const installedPacks = new SqliteInstalledPacksRepository(db);
23867
+ const repositories = {
23868
+ events: new SqliteEventsRepository(db),
23869
+ findings: new SqliteFindingsRepository(db),
23870
+ policies,
23871
+ installedPacks,
23872
+ scanLedger: new SqliteScanLedgerRepository(db),
23873
+ secretVault: new SqliteSecretVaultRepository(db),
23874
+ exceptions: new SqliteExceptionsRepository(db),
23875
+ resolutions: new SqliteResolutionsRepository(db),
23876
+ ruleProbeCache: new SqliteRuleProbeCacheRepository(db),
23877
+ security: new SqliteSecurityRepository(db),
23878
+ detections: new SqliteDetectionsRepository(db),
23879
+ shares: new SqliteSharesRepository(db),
23880
+ policyCatalog: new SqlitePolicyCatalogRepository(installedPacks),
23881
+ inventory: new SqliteInventoryRepository(db),
23882
+ inventoryAssets: new SqliteInventoryAssetsRepository(db),
23883
+ projectFiles: new SqliteProjectFilesRepository(db),
23884
+ activity: new SqliteActivityRepository(db),
23885
+ sourceProject: new SqliteSourceProjectRepository(db),
23886
+ auditEvents: new SqliteAuditEventsRepository(db),
23887
+ classifiedData: new SqliteClassifiedDataRepository(db),
23888
+ inspectionDefinitions: new SqliteInspectionDefinitionsRepository(db),
23889
+ inspectionFindings: new SqliteInspectionFindingsRepository(db),
23890
+ configInventory: new SqliteConfigInventoryRepository(db)
23891
+ };
23892
+ policies.seedDefaults();
23893
+ return { db, ...repositories };
23894
+ } catch (err) {
23895
+ closeQuietly(db);
23896
+ throw err;
23897
+ }
23898
+ }
23387
23899
  function openLocalDatabase(dir) {
23388
23900
  ensureDataDirSync(dir);
23389
23901
  const file2 = join(dir, DB_FILENAME);
23390
- let db = openWithPragmas(file2);
23391
- if (isForeignSqliteLineage(db)) {
23392
- db.close();
23393
- const backup = backupLegacyStore(file2);
23394
- db = openWithPragmas(file2);
23395
- akaWarn(
23396
- `Detected an older, incompatible (tenant-bearing) ${DB_FILENAME}; backed it up to ${backup} and created a fresh store.`
23397
- );
23398
- }
23399
- applyMigrations(db, file2);
23400
- tightenPerms(file2);
23401
- const events = new SqliteEventsRepository(db);
23402
- const findings = new SqliteFindingsRepository(db);
23403
- const policies = new SqlitePoliciesRepository(db);
23404
- const installedPacks = new SqliteInstalledPacksRepository(db);
23405
- const scanLedger = new SqliteScanLedgerRepository(db);
23406
- const exceptions = new SqliteExceptionsRepository(db);
23407
- const resolutions = new SqliteResolutionsRepository(db);
23408
- const ruleProbeCache = new SqliteRuleProbeCacheRepository(db);
23409
- const security = new SqliteSecurityRepository(db);
23410
- const detections = new SqliteDetectionsRepository(db);
23411
- const shares = new SqliteSharesRepository(db);
23412
- const policyCatalog = new SqlitePolicyCatalogRepository(installedPacks);
23413
- const inventory = new SqliteInventoryRepository(db);
23414
- const inventoryAssets = new SqliteInventoryAssetsRepository(db);
23415
- const projectFiles = new SqliteProjectFilesRepository(db);
23416
- const activity = new SqliteActivityRepository(db);
23417
- const sourceProject = new SqliteSourceProjectRepository(db);
23418
- const auditEvents = new SqliteAuditEventsRepository(db);
23419
- const classifiedData = new SqliteClassifiedDataRepository(db);
23420
- const inspectionDefinitions = new SqliteInspectionDefinitionsRepository(db);
23421
- const inspectionFindings = new SqliteInspectionFindingsRepository(db);
23422
- const configInventory = new SqliteConfigInventoryRepository(db);
23423
- policies.seedDefaults();
23902
+ const {
23903
+ db,
23904
+ events,
23905
+ findings,
23906
+ policies,
23907
+ installedPacks,
23908
+ scanLedger,
23909
+ secretVault,
23910
+ exceptions,
23911
+ resolutions,
23912
+ ruleProbeCache,
23913
+ security,
23914
+ detections,
23915
+ shares,
23916
+ policyCatalog,
23917
+ inventory,
23918
+ inventoryAssets,
23919
+ projectFiles,
23920
+ activity,
23921
+ sourceProject,
23922
+ auditEvents,
23923
+ classifiedData,
23924
+ inspectionDefinitions,
23925
+ inspectionFindings,
23926
+ configInventory
23927
+ } = openAndInitialize(file2);
23424
23928
  function recordCapture(event, detected) {
23425
23929
  failOpenTransaction(db, () => {
23426
23930
  const sessionId = event.metadata?.sessionId;
@@ -23511,7 +24015,7 @@ function openLocalDatabase(dir) {
23511
24015
  const definitionId = definitionIds.get(`${finding.ruleId}@${finding.version}`);
23512
24016
  if (!definitionId) continue;
23513
24017
  inspectionFindings.insertFinding({
23514
- id: randomUUID8(),
24018
+ id: randomUUID9(),
23515
24019
  auditEventId: record2.scanEvent.id,
23516
24020
  inspectionDefinitionId: definitionId,
23517
24021
  span: finding.span,
@@ -23588,6 +24092,7 @@ function openLocalDatabase(dir) {
23588
24092
  policies,
23589
24093
  installedPacks,
23590
24094
  scanLedger,
24095
+ secretVault,
23591
24096
  exceptions,
23592
24097
  resolutions,
23593
24098
  ruleProbeCache,
@@ -23625,8 +24130,9 @@ import { createHash as createHash3 } from "crypto";
23625
24130
 
23626
24131
  // ../../packages/persistence/src/fingerprint.ts
23627
24132
  import { createHmac, randomBytes } from "crypto";
23628
- import { readFileSync } from "fs";
24133
+ import { existsSync as existsSync2, readFileSync } from "fs";
23629
24134
  import { join as join2 } from "path";
24135
+ import { DatabaseSync as DatabaseSync2 } from "node:sqlite";
23630
24136
  var KEY_FILENAME = "exception.key";
23631
24137
  var KEY_MATERIAL_BYTES = 32;
23632
24138
  function keyFilePath(dataDir2) {
@@ -23719,23 +24225,49 @@ function readJson(file2) {
23719
24225
  return parseJsonObject(text) ?? null;
23720
24226
  }
23721
24227
 
23722
- // ../../packages/persistence/src/warn-era-cap.ts
23723
- import { existsSync as existsSync2, writeFileSync as writeFileSync2 } from "fs";
24228
+ // ../../packages/persistence/src/vault/crypto.ts
24229
+ import {
24230
+ createCipheriv,
24231
+ createDecipheriv,
24232
+ createHmac as createHmac2,
24233
+ hkdfSync,
24234
+ timingSafeEqual
24235
+ } from "crypto";
24236
+
24237
+ // ../../packages/persistence/src/vault/key-provider.ts
24238
+ import { execFileSync } from "child_process";
24239
+ import { randomBytes as randomBytes2 } from "crypto";
24240
+ import {
24241
+ chmodSync as chmodSync2,
24242
+ mkdirSync as mkdirSync2,
24243
+ readFileSync as readFileSync3,
24244
+ renameSync as renameSync4,
24245
+ rmSync as rmSync3,
24246
+ statSync,
24247
+ writeFileSync as writeFileSync2
24248
+ } from "fs";
23724
24249
  import { join as join5 } from "path";
24250
+
24251
+ // ../../packages/persistence/src/vault/vault.ts
24252
+ import { randomBytes as randomBytes3, randomUUID as randomUUID10 } from "crypto";
24253
+
24254
+ // ../../packages/persistence/src/warn-era-cap.ts
24255
+ import { existsSync as existsSync3, writeFileSync as writeFileSync3 } from "fs";
24256
+ import { join as join6 } from "path";
23725
24257
  var MARKER = "warn-era-capped";
23726
24258
  function capWarnEraEnforcementOnce(db, policyMode, dataDir2) {
23727
24259
  if (policyMode !== "warn") return { capped: 0, skipped: "not-warn" };
23728
- const marker = join5(dataDir2, MARKER);
23729
- if (existsSync2(marker)) return { capped: 0, skipped: "already-run" };
24260
+ const marker = join6(dataDir2, MARKER);
24261
+ if (existsSync3(marker)) return { capped: 0, skipped: "already-run" };
23730
24262
  const capped = db.policies.capCategoryActions();
23731
- writeFileSync2(marker, `${new Date(Date.now()).toISOString()}
24263
+ writeFileSync3(marker, `${new Date(Date.now()).toISOString()}
23732
24264
  `, { mode: DATA_FILE_MODE });
23733
24265
  return { capped };
23734
24266
  }
23735
24267
 
23736
24268
  // ../../packages/plugin-sdk/src/config.ts
23737
- import { existsSync as existsSync3 } from "fs";
23738
- import { join as join6 } from "path";
24269
+ import { existsSync as existsSync4 } from "fs";
24270
+ import { join as join7 } from "path";
23739
24271
 
23740
24272
  // ../../packages/plugin-sdk/src/provider-env.ts
23741
24273
  var DEFAULT_ANTHROPIC_HOST = "api.anthropic.com";
@@ -23789,8 +24321,8 @@ function resolveProvider() {
23789
24321
  function loadConfig(base = defaultDataDir()) {
23790
24322
  try {
23791
24323
  ensureLayoutDirSync(base);
23792
- const settingsFile = join6(settingsDir(base), "settings.json");
23793
- if (existsSync3(settingsFile)) tightenFile(settingsFile);
24324
+ const settingsFile = join7(settingsDir(base), "settings.json");
24325
+ if (existsSync4(settingsFile)) tightenFile(settingsFile);
23794
24326
  } catch {
23795
24327
  }
23796
24328
  migrateLegacyLayout(base);
@@ -23813,9 +24345,9 @@ function resolveProviderSafe() {
23813
24345
  }
23814
24346
 
23815
24347
  // ../../packages/plugin-sdk/src/config-inventory.ts
23816
- import { readdirSync, readFileSync as readFileSync4, realpathSync, statSync as statSync2 } from "fs";
24348
+ import { readdirSync, readFileSync as readFileSync5, realpathSync, statSync as statSync3 } from "fs";
23817
24349
  import { homedir as homedir2 } from "os";
23818
- import { basename as basename2, join as join8 } from "path";
24350
+ import { basename as basename2, join as join9 } from "path";
23819
24351
 
23820
24352
  // ../../packages/detections/src/egress/registry.ts
23821
24353
  var EXTRACTOR_VERSION = "1";
@@ -26551,18 +27083,18 @@ function bundledDetections() {
26551
27083
  }
26552
27084
 
26553
27085
  // ../../packages/plugin-sdk/src/repo.ts
26554
- import { existsSync as existsSync4, readFileSync as readFileSync3, statSync } from "fs";
26555
- import { basename, dirname, isAbsolute, join as join7, sep as sep2 } from "path";
27086
+ import { existsSync as existsSync5, readFileSync as readFileSync4, statSync as statSync2 } from "fs";
27087
+ import { basename, dirname, isAbsolute, join as join8, sep as sep2 } from "path";
26556
27088
 
26557
27089
  // ../../packages/plugin-sdk/src/events.ts
26558
- import { createHash as createHash4, randomUUID as randomUUID9 } from "crypto";
27090
+ import { createHash as createHash4, randomUUID as randomUUID11 } from "crypto";
26559
27091
 
26560
27092
  // ../../packages/plugin-sdk/src/inventory-resolver.ts
26561
27093
  import { arch, hostname as hostname3, platform, release } from "os";
26562
27094
 
26563
27095
  // ../../packages/plugin-sdk/src/nudge.ts
26564
- import { mkdirSync as mkdirSync2, readFileSync as readFileSync5, writeFileSync as writeFileSync3 } from "fs";
26565
- import { join as join9 } from "path";
27096
+ import { mkdirSync as mkdirSync3, readFileSync as readFileSync6, writeFileSync as writeFileSync4 } from "fs";
27097
+ import { join as join10 } from "path";
26566
27098
 
26567
27099
  // ../../packages/plugin-sdk/src/paths.ts
26568
27100
  import { readdirSync as readdirSync2, realpathSync as realpathSync2 } from "fs";
@@ -26570,21 +27102,21 @@ import { basename as basename3, dirname as dirname2, sep as sep3 } from "path";
26570
27102
 
26571
27103
  // ../../packages/plugin-sdk/src/project-files.ts
26572
27104
  var import_ignore = __toESM(require_ignore(), 1);
26573
- import { existsSync as existsSync5, readdirSync as readdirSync3, readFileSync as readFileSync6 } from "fs";
26574
- import { basename as basename4, join as join10, relative, sep as sep4 } from "path";
27105
+ import { existsSync as existsSync6, readdirSync as readdirSync3, readFileSync as readFileSync7 } from "fs";
27106
+ import { basename as basename4, join as join11, relative, sep as sep4 } from "path";
26575
27107
 
26576
27108
  // ../../packages/plugin-sdk/src/runtime.ts
26577
- import { randomUUID as randomUUID10 } from "crypto";
27109
+ import { randomUUID as randomUUID12 } from "crypto";
26578
27110
 
26579
27111
  // ../../packages/plugin-sdk/src/suppressions.ts
26580
27112
  var THIRTY_DAYS_MS = 30 * 24 * 60 * 60 * 1e3;
26581
27113
 
26582
27114
  // ../../packages/plugin-sdk/src/throttle.ts
26583
- import { mkdirSync as mkdirSync3, statSync as statSync3, writeFileSync as writeFileSync4 } from "fs";
26584
- import { join as join11 } from "path";
27115
+ import { mkdirSync as mkdirSync4, statSync as statSync4, writeFileSync as writeFileSync5 } from "fs";
27116
+ import { join as join12 } from "path";
26585
27117
 
26586
27118
  // ../../packages/plugin-runtime/src/standalone-gateway.ts
26587
- import { randomUUID as randomUUID11 } from "crypto";
27119
+ import { randomUUID as randomUUID13 } from "crypto";
26588
27120
 
26589
27121
  // ../../packages/plugin-runtime/src/recorder.ts
26590
27122
  var PLUGIN_RECORDER_BINARY = "plugin";
@@ -26746,7 +27278,7 @@ var StandaloneDataGateway = class {
26746
27278
  const customKeywords = [...new Set(policies.flatMap((p) => p.customKeywords ?? []))];
26747
27279
  const installed = this.installedScanRules();
26748
27280
  const rulePolicies = installed ? [...installed.ruleActions].map(([ruleId, action]) => ({
26749
- id: randomUUID11(),
27281
+ id: randomUUID13(),
26750
27282
  scope: "global",
26751
27283
  target: { ruleId },
26752
27284
  action,
@@ -26899,7 +27431,7 @@ function resolveDataGateway(config2, meta3, gatewayFactory = standaloneGatewayFa
26899
27431
  }
26900
27432
 
26901
27433
  // ../../packages/plugin-runtime/src/handle-session-start.ts
26902
- import { randomUUID as randomUUID12 } from "crypto";
27434
+ import { randomUUID as randomUUID14 } from "crypto";
26903
27435
  var EXCEPTION_RETENTION_MS = 90 * 24 * 60 * 60 * 1e3;
26904
27436
 
26905
27437
  // src/command-registry.ts
@@ -27223,10 +27755,10 @@ async function runFirstRunFailOpen(deps) {
27223
27755
  }
27224
27756
 
27225
27757
  // src/posture.ts
27226
- async function readPostureBlock(open) {
27758
+ async function readPostureBlock(open2) {
27227
27759
  let db;
27228
27760
  try {
27229
- db = open();
27761
+ db = open2();
27230
27762
  const policies = await db.policies.readPolicies();
27231
27763
  return renderPosture(
27232
27764
  policies.map((p) => ({