@akasecurity/ai-tc-codex 0.9.15 → 0.9.16

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.
@@ -881,10 +881,10 @@ function isCorroborated(candidate, candidates, text, normalization) {
881
881
  }
882
882
  return false;
883
883
  }
884
- function buildCandidates(matchText, ruleset2, extension) {
884
+ function buildCandidates(matchText, ruleset2, extension, eventKind) {
885
885
  const candidates = [];
886
886
  for (const rule of ruleset2) {
887
- if (!ruleApplies(rule, extension)) continue;
887
+ if (!ruleApplies(rule, extension, eventKind)) continue;
888
888
  const spans = MATCHERS[rule.matcher.type](matchText, rule);
889
889
  for (const span of spans) {
890
890
  const rawMatch = matchText.slice(span.start, span.end);
@@ -994,22 +994,30 @@ function extensionOf(filePath) {
994
994
  const dot = base.lastIndexOf(".");
995
995
  return dot > 0 ? base.slice(dot).toLowerCase() : void 0;
996
996
  }
997
- function ruleApplies(rule, extension) {
998
- if (!rule.appliesTo || extension === void 0) return true;
999
- return rule.appliesTo.extensions.some((e) => e.toLowerCase() === extension);
997
+ function ruleApplies(rule, extension, eventKind) {
998
+ const scope = rule.appliesTo;
999
+ if (!scope) return true;
1000
+ if (scope.eventKinds && (eventKind === void 0 || !scope.eventKinds.some((k) => k === eventKind))) {
1001
+ return false;
1002
+ }
1003
+ if (!scope.extensions || extension === void 0) return true;
1004
+ return scope.extensions.some((e) => e.toLowerCase() === extension);
1000
1005
  }
1001
1006
  function scan(text, rules, context) {
1002
1007
  const ruleset2 = rules ?? getLoadedRules();
1003
1008
  const extension = context?.filePath ? extensionOf(context.filePath) : void 0;
1004
1009
  const normalization = normalizeFormatChars(text);
1005
- const originalCandidates = buildCandidates(text, ruleset2, extension);
1010
+ const originalCandidates = buildCandidates(text, ruleset2, extension, context?.eventKind);
1006
1011
  if (!normalization) return gate(originalCandidates, text, void 0);
1007
1012
  const pooledOriginal = originalCandidates.map(
1008
1013
  (candidate) => withNormalizedSpan(candidate, normalization)
1009
1014
  );
1010
- const normalizedCandidates = buildCandidates(normalization.normalized, ruleset2, extension).map(
1011
- (candidate) => mapCandidateToOriginal(candidate, normalization, text)
1012
- );
1015
+ const normalizedCandidates = buildCandidates(
1016
+ normalization.normalized,
1017
+ ruleset2,
1018
+ extension,
1019
+ context?.eventKind
1020
+ ).map((candidate) => mapCandidateToOriginal(candidate, normalization, text));
1013
1021
  const findings = gate([...pooledOriginal, ...normalizedCandidates], text, normalization);
1014
1022
  return mergeOverlappingSameRule(findings, text);
1015
1023
  }
@@ -21669,11 +21677,33 @@ var ResolutionMethod = external_exports.enum([
21669
21677
  "false-positive",
21670
21678
  "redetected"
21671
21679
  ]).meta({ id: "ResolutionMethod" });
21680
+ var FindingContextBasis = external_exports.enum(["file", "excerpt"]).meta({ id: "FindingContextBasis" });
21681
+ var FindingContext = external_exports.object({
21682
+ basis: FindingContextBasis,
21683
+ // 1-based line number of `lines[0]`.
21684
+ firstLine: external_exports.number().int().positive(),
21685
+ lines: external_exports.array(external_exports.string()).min(1).max(5),
21686
+ match: external_exports.object({
21687
+ // 1-based line number, within [firstLine, firstLine + lines.length).
21688
+ line: external_exports.number().int().positive(),
21689
+ // Offsets into that entry of `lines`, end exclusive.
21690
+ start: external_exports.number().int().nonnegative(),
21691
+ end: external_exports.number().int().nonnegative()
21692
+ }).nullable()
21693
+ }).meta({ id: "FindingContext" });
21694
+ var FindingLocation = external_exports.object({
21695
+ line: external_exports.number().int().positive(),
21696
+ col: external_exports.number().int().positive(),
21697
+ context: FindingContext.nullable()
21698
+ });
21672
21699
  var FindingMatch = external_exports.object({
21673
21700
  // Masked preview of the matched value. Never raw content.
21674
21701
  maskedValue: external_exports.string(),
21675
- // Redacted source-line prefix. Currently empty (pending privacy review).
21676
- contextPrefix: external_exports.string()
21702
+ // Deprecated: always empty. Superseded by `context`.
21703
+ contextPrefix: external_exports.string(),
21704
+ // The masked lines around the match. Absent when the finding predates
21705
+ // context capture or none could be built safely.
21706
+ context: FindingContext.optional()
21677
21707
  }).meta({ id: "FindingMatch" });
21678
21708
  var FindingDetectionRef = external_exports.object({
21679
21709
  id: external_exports.string(),
@@ -21693,6 +21723,11 @@ var FindingInstance = external_exports.object({
21693
21723
  provider: FindingProvider,
21694
21724
  repo: external_exports.string(),
21695
21725
  file: external_exports.string(),
21726
+ // 1-based line and column of the match start in the scanned text (the
21727
+ // column in UTF-16 code units). Absent for findings that predate location
21728
+ // capture or have no source text.
21729
+ line: external_exports.number().int().positive().optional(),
21730
+ col: external_exports.number().int().positive().optional(),
21696
21731
  // Who the capturing event is attributed to. Optional: a single-user store
21697
21732
  // has no one to attribute a finding to and never sets it.
21698
21733
  user: FindingUser.optional(),
@@ -21754,6 +21789,13 @@ var FindingStats = external_exports.object({
21754
21789
  low: external_exports.number().int().nonnegative()
21755
21790
  })
21756
21791
  }).meta({ id: "FindingStats" });
21792
+ var FindingsOverview = external_exports.object({
21793
+ findings: external_exports.number().int().nonnegative(),
21794
+ open: external_exports.number().int().nonnegative(),
21795
+ handled: external_exports.number().int().nonnegative(),
21796
+ resolved: external_exports.number().int().nonnegative(),
21797
+ dismissed: external_exports.number().int().nonnegative()
21798
+ }).meta({ id: "FindingsOverview" });
21757
21799
  var FindingFacetItem = external_exports.object({
21758
21800
  value: external_exports.string(),
21759
21801
  count: external_exports.number().int().nonnegative()
@@ -21871,6 +21913,7 @@ var FindingInstanceDetail = FindingInstance.extend({
21871
21913
  policy: FindingPolicyRef
21872
21914
  }).meta({ id: "FindingInstanceDetail" });
21873
21915
  var MAX_FLAT_FINDINGS_LIMIT = 200;
21916
+ var FindingContextQuery = external_exports.object({ id: external_exports.string().min(1).max(256) });
21874
21917
  var ListFindingInstancesQuery = external_exports.object({
21875
21918
  severity: external_exports.array(Severity).optional(),
21876
21919
  // Rule ids, the same vocabulary the types list's `subtype` carries. Pinning
@@ -22202,7 +22245,23 @@ var CaptureAttributes = external_exports.object({
22202
22245
  // capture denied by another finding's own Block policy carries `block`
22203
22246
  // here too. The full statement is on EventMetadata.redactDegradedTo; it is
22204
22247
  // repeated rather than referenced because a store reader opens this file.
22205
- redact_degraded_to: ActionTaken.optional()
22248
+ redact_degraded_to: ActionTaken.optional(),
22249
+ // The scope key this capture was stamped with: the canonical repository
22250
+ // (`host/owner/repo`) of the path the capture names (a relative path is read
22251
+ // against its working directory), else of its own working directory, or a
22252
+ // chat account's identity. The store's local `scope_key` column reads it, so
22253
+ // a scoped attachment has a per-row key to work from. Absent when no key
22254
+ // could be derived.
22255
+ //
22256
+ // LOCAL ONLY. That is the contract for every path that sends a row. Producers
22257
+ // stamp it in every attachment mode, and the two structural choke points strip
22258
+ // it: the attached gateway's `reKeyForForward` on the live path, and the
22259
+ // history drain's `rebuildAuditEvent`, which drops it through `withoutScopeKey`.
22260
+ // A capture row's bag reaches the wire through `rebuildCapture`, which builds
22261
+ // the metadata from named keys and never names this one; `toCaptureAttributes`,
22262
+ // which builds the bag from a wire event, never emits it. What a scoped
22263
+ // attachment does with the key is not part of this shape's contract.
22264
+ scope_key: external_exports.string().optional()
22206
22265
  }).catchall(external_exports.unknown());
22207
22266
  var CaptureStatusAttributes = external_exports.object({
22208
22267
  source_tool: external_exports.string().optional(),
@@ -22232,6 +22291,12 @@ var ToolCallInspection = external_exports.object({
22232
22291
  actionTaken: ActionTaken,
22233
22292
  confidence: external_exports.number().min(0).max(1)
22234
22293
  });
22294
+ var findingLocationFields = {
22295
+ line: external_exports.number().int().positive().optional(),
22296
+ col: external_exports.number().int().positive().optional(),
22297
+ context: FindingContext.nullable().optional()
22298
+ };
22299
+ var ToolCallInspectionInput = ToolCallInspection.extend(findingLocationFields);
22235
22300
  var ToolCallInput = external_exports.object({
22236
22301
  sessionId: external_exports.string().min(1),
22237
22302
  toolUseId: external_exports.string().min(1),
@@ -22241,7 +22306,7 @@ var ToolCallInput = external_exports.object({
22241
22306
  attributes: ToolCallAttributes,
22242
22307
  // Secrets detected in the tool's (masked) target — written as linked
22243
22308
  // `inspection_findings`. Empty for a clean tool call.
22244
- inspections: external_exports.array(ToolCallInspection).default([])
22309
+ inspections: external_exports.array(ToolCallInspectionInput).default([])
22245
22310
  });
22246
22311
  var InventoryInput = external_exports.object({
22247
22312
  objectType: InventoryObjectType,
@@ -22315,7 +22380,8 @@ var InspectionFindingInput = external_exports.object({
22315
22380
  // same findingKey — mirrors the legacy `findings.first_detected_at`.
22316
22381
  // Optional: when omitted, the writer derives it from the referenced audit
22317
22382
  // event's startedAt on first insert (see SqliteInspectionFindingsRepository).
22318
- firstDetectedAt: external_exports.iso.datetime().optional()
22383
+ firstDetectedAt: external_exports.iso.datetime().optional(),
22384
+ ...findingLocationFields
22319
22385
  });
22320
22386
  var InventoryContext = external_exports.object({
22321
22387
  host: InventoryInput.optional(),
@@ -23090,6 +23156,17 @@ var AttachedCredential = external_exports.object({
23090
23156
  keyPrefix: external_exports.string().min(1).max(16).optional(),
23091
23157
  mintedAt: external_exports.iso.datetime().optional()
23092
23158
  });
23159
+ var AttachmentMode = external_exports.enum(["machine", "scoped"]);
23160
+ var ATTACHED_CREDENTIAL_SCOPED_SPEC_VERSION = 2;
23161
+ var AttachedCredentialV1 = AttachedCredential;
23162
+ var AttachedCredentialV2 = AttachedCredential.extend({
23163
+ specVersion: external_exports.literal(ATTACHED_CREDENTIAL_SCOPED_SPEC_VERSION),
23164
+ mode: external_exports.literal("scoped")
23165
+ });
23166
+ var AttachedCredentialAny = external_exports.discriminatedUnion("specVersion", [
23167
+ AttachedCredentialV1,
23168
+ AttachedCredentialV2
23169
+ ]);
23093
23170
  var MAX_DATE_MS = 253402300799999;
23094
23171
  var MAX_INT4 = 2147483647;
23095
23172
  var StorePosturePack = external_exports.object({
@@ -23371,6 +23448,130 @@ var PackId = external_exports.string().regex(/^[a-z][a-z0-9-]*$/);
23371
23448
  var SemVer = external_exports.string().regex(/^\d+\.\d+\.\d+(?:-[0-9A-Za-z-.]+)?$/);
23372
23449
  var PublisherKind = external_exports.enum(["labs", "user", "org"]);
23373
23450
 
23451
+ // ../../packages/schema/src/zod/builtin-policy-id.ts
23452
+ var KNOWN_BUILTIN_IDS = ["monitor", "warn", "redact", "vault", "block"];
23453
+ var BuiltinPolicyId = external_exports.enum(KNOWN_BUILTIN_IDS).meta({ id: "BuiltinPolicyId" });
23454
+
23455
+ // ../../packages/schema/src/zod/event.ts
23456
+ var EventKind = external_exports.enum(["prompt", "response", "code_change", "tool_use"]).meta({ id: "EventKind" });
23457
+ var CAPTURE_EVENT_TYPES_SQL = EventKind.options.map((k) => `'${k}'`).join(",");
23458
+ var EventMetadata = external_exports.object({
23459
+ sessionId: external_exports.string().optional(),
23460
+ repo: external_exports.string().optional(),
23461
+ filePath: external_exports.string().optional(),
23462
+ // The host tool whose input/output was scanned (e.g. 'Bash', 'WebFetch'),
23463
+ // set by the tool-scanning hooks. The tool NAME only — never the tool's
23464
+ // arguments or output, which can carry the very value a finding masked
23465
+ // (metadata is stored unredacted). Gives findings on non-file captures a
23466
+ // display location ("via Bash") when no filePath exists.
23467
+ toolName: external_exports.string().optional(),
23468
+ // Set (true) by the worktree scanner when the file is excluded by the
23469
+ // repo's .gitignore. Gitignored files ARE still scanned — local scratch and
23470
+ // generated code can leak real secrets — but the provenance is recorded so
23471
+ // policy/dashboards can treat those findings as informational rather than
23472
+ // blocking. Omitted (not false) for tracked files and non-scan events.
23473
+ gitignored: external_exports.boolean().optional(),
23474
+ // Set (true) ONLY when the event's `content` is the COMPLETE file at
23475
+ // capture time (a worktree scan reading from disk). Hook-captured edits
23476
+ // (e.g. an Edit tool's new_string) are partial fragments and MUST NOT set
23477
+ // this. The resolver-on-ingest keys its fixed-at-source dropout
23478
+ // diff on this marker: only a whole-file snapshot can prove a previously
23479
+ // open finding is gone; a fragment's absence proves nothing (the secret
23480
+ // may live outside the hunk). Omitted (not false) for fragments and
23481
+ // non-scan events, so pre-marker clients safely default to the
23482
+ // non-authoritative path.
23483
+ wholeFile: external_exports.boolean().optional(),
23484
+ model: external_exports.string().optional(),
23485
+ turnIndex: external_exports.number().int().nonnegative().optional(),
23486
+ // Distributed-tracing correlation. `correlationId` ties a recorded event back
23487
+ // to the request that captured/ingested it (a UUID, generated independently of
23488
+ // the trace id); `traceId` is the W3C trace id (32 lowercase hex chars) of the
23489
+ // originating span when telemetry is enabled. Both optional + backward
23490
+ // compatible — populated by the plugin (see @akasecurity/plugin-sdk).
23491
+ correlationId: external_exports.uuid().optional(),
23492
+ traceId: external_exports.string().regex(/^[0-9a-f]{32}$/).optional(),
23493
+ // Ids of the detection exceptions that downgraded findings in this capture
23494
+ // to 'allow' — the enforcement audit trail's link back to the grant that
23495
+ // authorized the bypass. Absent on captures where no exception applied.
23496
+ exceptionIds: external_exports.array(external_exports.guid()).optional(),
23497
+ // The assistant message this capture belongs to, and the conversation it sits
23498
+ // in — set by the browser extension's network capture so a stored `response`
23499
+ // row can be joined to the `llm_call` leaf describing the same turn. Absent
23500
+ // on every other capture path, which has no such id.
23501
+ //
23502
+ // Non-empty for the reason WebExchange.messageId is: it is the join key, and
23503
+ // a blank one matches no `llm_call` leaf. That refusal reaches only the
23504
+ // places an event is PARSED; the local write path types the event and parses
23505
+ // nothing, which is why `toCaptureAttributes` omits a blank one separately.
23506
+ messageId: external_exports.string().min(1).optional(),
23507
+ conversationId: external_exports.string().optional(),
23508
+ // How long THIS capture's inspection blocked its caller, in whole
23509
+ // milliseconds — the plugin's own added latency, NOT the LLM call it sat in
23510
+ // front of. Measured inside `capture()` (@akasecurity/plugin-sdk) across
23511
+ // detection + redaction, the work the host session actually waits on.
23512
+ //
23513
+ // Stamped ONLY on live in-flight captures. A capture that carries its own
23514
+ // `occurredAt` is replaying past work (the transcript backfill, the worktree
23515
+ // scan), and its scan duration is not latency any host session experienced,
23516
+ // so those rows leave this ABSENT rather than reporting a misleading number.
23517
+ // Absent is also what every pre-measurement client writes, and what a
23518
+ // clock failure degrades to — a reader must treat absence as "not measured"
23519
+ // and never as a zero, which would read as "inspection is free".
23520
+ inspectionMs: external_exports.number().int().nonnegative().optional(),
23521
+ // What a `redact` this capture COULD NOT CARRY OUT became instead — the
23522
+ // workspace's `redactFallback`, applied because the field could not be
23523
+ // masked in place (a shell command, a URL, or any argument on a host whose
23524
+ // hook contract offers no rewrite channel).
23525
+ //
23526
+ // It exists because the action alone cannot say why. A finding recorded as
23527
+ // `warn` reads identically whether its detection was ASSIGNED Warn or was
23528
+ // assigned Redact on a field that could not take one — and those are
23529
+ // different facts about the same row: the first is a policy the user chose,
23530
+ // the second is a masking the host could not perform. Absent means no
23531
+ // degrade happened, which is every ordinary capture.
23532
+ //
23533
+ // TWO LIMITS a reader of a stored row has to know, because the grain here
23534
+ // is the CAPTURE while `actionTaken` is per FINDING:
23535
+ //
23536
+ // - It does not say WHICH finding degraded. A capture carrying a degraded
23537
+ // `redact` alongside a finding ASSIGNED the same action stores both
23538
+ // identically and one reason for the pair; attributing it to both
23539
+ // describes the assigned one wrongly, and to neither loses the degrade.
23540
+ // - PRESENCE IS NOT CAUSATION. The value is the action the lost redact
23541
+ // became, not the reason the capture ended as it did — a capture denied
23542
+ // by some other finding's own Block policy still carries `block` here,
23543
+ // and clearing the workspace's fallback would not have let it through.
23544
+ // Gate on the value against what a fallback can produce; never read the
23545
+ // field's presence as "this was the fallback's doing".
23546
+ //
23547
+ // Both are pinned as behaviour in @akasecurity/plugin-sdk's runtime suite.
23548
+ // Closing either means moving the reason onto the finding row, which
23549
+ // already carries its own action.
23550
+ redactDegradedTo: ActionTaken.optional()
23551
+ }).meta({ id: "EventMetadata" });
23552
+ var Event = external_exports.object({
23553
+ id: external_exports.guid(),
23554
+ sourceTool: SourceTool,
23555
+ kind: EventKind,
23556
+ occurredAt: external_exports.iso.datetime(),
23557
+ contentHash: external_exports.string(),
23558
+ content: external_exports.string(),
23559
+ metadata: EventMetadata.optional()
23560
+ }).meta({ id: "Event" });
23561
+ var IngestEvent = Event.meta({ id: "IngestEvent" });
23562
+ var INGEST_BATCH_MAX = 100;
23563
+ var IngestBatch = external_exports.object({
23564
+ events: external_exports.array(IngestEvent).min(1).max(INGEST_BATCH_MAX),
23565
+ // Dedup policy for this batch. Id-dedup ALWAYS applies. 'content-hash'
23566
+ // additionally rejects any event whose contentHash the store has already
23567
+ // recorded — for re-runnable bulk ingest (worktree scan, transcript
23568
+ // backfill), where a re-run mints fresh event ids for identical content and
23569
+ // would otherwise accumulate duplicates. Live hook traffic must NOT set it:
23570
+ // two genuinely separate prompts can be byte-identical and both belong on
23571
+ // the timeline.
23572
+ dedupe: external_exports.literal("content-hash").optional()
23573
+ }).meta({ id: "IngestBatch" });
23574
+
23374
23575
  // ../../packages/schema/src/zod/rule.ts
23375
23576
  var MatcherType = external_exports.enum(["keyword", "regex"]).meta({ id: "MatcherType" });
23376
23577
  var RuleProbeVerdict = external_exports.enum(["safe", "quarantined"]).meta({ id: "RuleProbeVerdict" });
@@ -23439,7 +23640,10 @@ var Matcher = external_exports.discriminatedUnion("type", [KeywordMatcher2, Rege
23439
23640
  var MATCHER_TYPES = MatcherType.options;
23440
23641
  var AppliesTo = external_exports.strictObject({
23441
23642
  // Dot-prefixed, e.g. ".py" — matches the scanner's SOURCE_EXTENSIONS shape.
23442
- extensions: external_exports.array(external_exports.string().regex(/^\.[A-Za-z0-9]+$/)).min(1)
23643
+ extensions: external_exports.array(external_exports.string().regex(/^\.[A-Za-z0-9]+$/)).min(1).optional(),
23644
+ eventKinds: external_exports.array(EventKind).min(1).optional()
23645
+ }).refine((v) => v.extensions !== void 0 || v.eventKinds !== void 0, {
23646
+ message: "appliesTo needs extensions, eventKinds, or both"
23443
23647
  }).meta({ id: "AppliesTo" });
23444
23648
  var PostValidatorName = external_exports.enum(["entropy", "luhn"]).meta({ id: "PostValidatorName" });
23445
23649
  var PostValidatorRef = external_exports.union(
@@ -23462,6 +23666,7 @@ var PostValidatorRef = external_exports.union(
23462
23666
  )}) or { "name": ..., "config": { ... } }. An unrecognized name would be a false-positive guard that never runs.`
23463
23667
  }
23464
23668
  ).meta({ id: "PostValidatorRef" });
23669
+ var RuleEvidence = external_exports.enum(["code", "value"]).meta({ id: "RuleEvidence" });
23465
23670
  var RequiresNearby = external_exports.strictObject({
23466
23671
  // Each array, when present, must be non-empty and contain non-empty strings —
23467
23672
  // an empty/blank criterion would either never fire or (for labels) match
@@ -23484,6 +23689,8 @@ var RuleFixture = external_exports.strictObject({
23484
23689
  // Simulated file context for the scan, so fixtures can assert `appliesTo`
23485
23690
  // gating (e.g. a Python-only pattern must NOT fire in a .ts file).
23486
23691
  filePath: external_exports.string().optional(),
23692
+ // Simulated capture kind, so fixtures can assert `appliesTo.eventKinds`.
23693
+ eventKind: EventKind.optional(),
23487
23694
  expectedSpans: external_exports.array(external_exports.strictObject({ start: external_exports.number(), end: external_exports.number() })).optional()
23488
23695
  }).meta({ id: "RuleFixture" });
23489
23696
  var Rule = external_exports.strictObject({
@@ -23509,7 +23716,9 @@ var Rule = external_exports.strictObject({
23509
23716
  appliesTo: AppliesTo.optional(),
23510
23717
  postValidators: external_exports.array(PostValidatorRef).optional(),
23511
23718
  requiresNearby: RequiresNearby.optional(),
23512
- examples: external_exports.array(external_exports.string()).optional()
23719
+ examples: external_exports.array(external_exports.string()).optional(),
23720
+ // Whether the matched text is itself sensitive. Absent means 'value'.
23721
+ evidence: RuleEvidence.optional()
23513
23722
  }).meta({ id: "Rule" });
23514
23723
  var Author = external_exports.object({
23515
23724
  name: external_exports.string(),
@@ -23526,7 +23735,11 @@ var PackManifest = external_exports.object({
23526
23735
  description: external_exports.string().optional(),
23527
23736
  author: Author.optional(),
23528
23737
  license: external_exports.string().optional(),
23529
- sourceUrl: external_exports.url().optional()
23738
+ sourceUrl: external_exports.url().optional(),
23739
+ // The built-in policy a FIRST install of this pack assigns
23740
+ // (installed_packs.policy_id). Absent leaves the pack unassigned, so its
23741
+ // rules follow the category policies. An existing install never takes it.
23742
+ defaultPolicy: BuiltinPolicyId.optional()
23530
23743
  }).meta({ id: "PackManifest" });
23531
23744
 
23532
23745
  // ../../packages/schema/src/zod/detection.ts
@@ -23554,10 +23767,12 @@ var DetectionListItem = external_exports.object({
23554
23767
  // Per-pack enforcement-policy assignment. Holds a BuiltinPolicyId ARCHETYPE
23555
23768
  // (monitor|warn|redact|block) — NOT a policies-table Policy.id guid; a
23556
23769
  // detection is a PACK, and its policy is the archetype applied to all its
23557
- // rules. Absent == unassigned, which resolves to Monitor everywhere
23558
- // (DEFAULT_PACK_POLICY_ID). Every enforcement surface expands it into
23559
- // per-rule policies (see policyIdToAction). Typed z.string() (not
23560
- // the enum) to keep the OpenAPI response tolerant of a future custom id.
23770
+ // rules. Absent == unassigned, which resolves to Monitor by default
23771
+ // (DEFAULT_PACK_POLICY_ID); a host may resolve it to a policy of its own
23772
+ // (see the dashboard's `unassignedPolicy`). Every enforcement surface
23773
+ // expands it into per-rule policies (see policyIdToAction). Typed
23774
+ // z.string() (not the enum) to keep the OpenAPI response tolerant of a
23775
+ // future custom id.
23561
23776
  policyId: external_exports.string().optional(),
23562
23777
  // Set ONLY when a newer snapshot is available for this pack (OSS: the
23563
23778
  // bundled inventory recorded in available_packs differs from the installed
@@ -23626,10 +23841,12 @@ var DetectionDetail = external_exports.object({
23626
23841
  // Per-pack enforcement-policy assignment. Holds a BuiltinPolicyId ARCHETYPE
23627
23842
  // (monitor|warn|redact|block) — NOT a policies-table Policy.id guid; a
23628
23843
  // detection is a PACK, and its policy is the archetype applied to all its
23629
- // rules. Absent == unassigned, which resolves to Monitor everywhere
23630
- // (DEFAULT_PACK_POLICY_ID). Every enforcement surface expands it into
23631
- // per-rule policies (see policyIdToAction). Typed z.string() (not
23632
- // the enum) to keep the OpenAPI response tolerant of a future custom id.
23844
+ // rules. Absent == unassigned, which resolves to Monitor by default
23845
+ // (DEFAULT_PACK_POLICY_ID); a host may resolve it to a policy of its own
23846
+ // (see the dashboard's `unassignedPolicy`). Every enforcement surface
23847
+ // expands it into per-rule policies (see policyIdToAction). Typed
23848
+ // z.string() (not the enum) to keep the OpenAPI response tolerant of a
23849
+ // future custom id.
23633
23850
  policyId: external_exports.string().optional()
23634
23851
  }).meta({ id: "DetectionDetail" });
23635
23852
  var LibraryItem = external_exports.object({
@@ -23659,126 +23876,6 @@ var ImportDetectionRequest = external_exports.object({
23659
23876
  })
23660
23877
  }).meta({ id: "ImportDetectionRequest" });
23661
23878
 
23662
- // ../../packages/schema/src/zod/event.ts
23663
- var EventKind = external_exports.enum(["prompt", "response", "code_change", "tool_use"]).meta({ id: "EventKind" });
23664
- var CAPTURE_EVENT_TYPES_SQL = EventKind.options.map((k) => `'${k}'`).join(",");
23665
- var EventMetadata = external_exports.object({
23666
- sessionId: external_exports.string().optional(),
23667
- repo: external_exports.string().optional(),
23668
- filePath: external_exports.string().optional(),
23669
- // The host tool whose input/output was scanned (e.g. 'Bash', 'WebFetch'),
23670
- // set by the tool-scanning hooks. The tool NAME only — never the tool's
23671
- // arguments or output, which can carry the very value a finding masked
23672
- // (metadata is stored unredacted). Gives findings on non-file captures a
23673
- // display location ("via Bash") when no filePath exists.
23674
- toolName: external_exports.string().optional(),
23675
- // Set (true) by the worktree scanner when the file is excluded by the
23676
- // repo's .gitignore. Gitignored files ARE still scanned — local scratch and
23677
- // generated code can leak real secrets — but the provenance is recorded so
23678
- // policy/dashboards can treat those findings as informational rather than
23679
- // blocking. Omitted (not false) for tracked files and non-scan events.
23680
- gitignored: external_exports.boolean().optional(),
23681
- // Set (true) ONLY when the event's `content` is the COMPLETE file at
23682
- // capture time (a worktree scan reading from disk). Hook-captured edits
23683
- // (e.g. an Edit tool's new_string) are partial fragments and MUST NOT set
23684
- // this. The resolver-on-ingest keys its fixed-at-source dropout
23685
- // diff on this marker: only a whole-file snapshot can prove a previously
23686
- // open finding is gone; a fragment's absence proves nothing (the secret
23687
- // may live outside the hunk). Omitted (not false) for fragments and
23688
- // non-scan events, so pre-marker clients safely default to the
23689
- // non-authoritative path.
23690
- wholeFile: external_exports.boolean().optional(),
23691
- model: external_exports.string().optional(),
23692
- turnIndex: external_exports.number().int().nonnegative().optional(),
23693
- // Distributed-tracing correlation. `correlationId` ties a recorded event back
23694
- // to the request that captured/ingested it (a UUID, generated independently of
23695
- // the trace id); `traceId` is the W3C trace id (32 lowercase hex chars) of the
23696
- // originating span when telemetry is enabled. Both optional + backward
23697
- // compatible — populated by the plugin (see @akasecurity/plugin-sdk).
23698
- correlationId: external_exports.uuid().optional(),
23699
- traceId: external_exports.string().regex(/^[0-9a-f]{32}$/).optional(),
23700
- // Ids of the detection exceptions that downgraded findings in this capture
23701
- // to 'allow' — the enforcement audit trail's link back to the grant that
23702
- // authorized the bypass. Absent on captures where no exception applied.
23703
- exceptionIds: external_exports.array(external_exports.guid()).optional(),
23704
- // The assistant message this capture belongs to, and the conversation it sits
23705
- // in — set by the browser extension's network capture so a stored `response`
23706
- // row can be joined to the `llm_call` leaf describing the same turn. Absent
23707
- // on every other capture path, which has no such id.
23708
- //
23709
- // Non-empty for the reason WebExchange.messageId is: it is the join key, and
23710
- // a blank one matches no `llm_call` leaf. That refusal reaches only the
23711
- // places an event is PARSED; the local write path types the event and parses
23712
- // nothing, which is why `toCaptureAttributes` omits a blank one separately.
23713
- messageId: external_exports.string().min(1).optional(),
23714
- conversationId: external_exports.string().optional(),
23715
- // How long THIS capture's inspection blocked its caller, in whole
23716
- // milliseconds — the plugin's own added latency, NOT the LLM call it sat in
23717
- // front of. Measured inside `capture()` (@akasecurity/plugin-sdk) across
23718
- // detection + redaction, the work the host session actually waits on.
23719
- //
23720
- // Stamped ONLY on live in-flight captures. A capture that carries its own
23721
- // `occurredAt` is replaying past work (the transcript backfill, the worktree
23722
- // scan), and its scan duration is not latency any host session experienced,
23723
- // so those rows leave this ABSENT rather than reporting a misleading number.
23724
- // Absent is also what every pre-measurement client writes, and what a
23725
- // clock failure degrades to — a reader must treat absence as "not measured"
23726
- // and never as a zero, which would read as "inspection is free".
23727
- inspectionMs: external_exports.number().int().nonnegative().optional(),
23728
- // What a `redact` this capture COULD NOT CARRY OUT became instead — the
23729
- // workspace's `redactFallback`, applied because the field could not be
23730
- // masked in place (a shell command, a URL, or any argument on a host whose
23731
- // hook contract offers no rewrite channel).
23732
- //
23733
- // It exists because the action alone cannot say why. A finding recorded as
23734
- // `warn` reads identically whether its detection was ASSIGNED Warn or was
23735
- // assigned Redact on a field that could not take one — and those are
23736
- // different facts about the same row: the first is a policy the user chose,
23737
- // the second is a masking the host could not perform. Absent means no
23738
- // degrade happened, which is every ordinary capture.
23739
- //
23740
- // TWO LIMITS a reader of a stored row has to know, because the grain here
23741
- // is the CAPTURE while `actionTaken` is per FINDING:
23742
- //
23743
- // - It does not say WHICH finding degraded. A capture carrying a degraded
23744
- // `redact` alongside a finding ASSIGNED the same action stores both
23745
- // identically and one reason for the pair; attributing it to both
23746
- // describes the assigned one wrongly, and to neither loses the degrade.
23747
- // - PRESENCE IS NOT CAUSATION. The value is the action the lost redact
23748
- // became, not the reason the capture ended as it did — a capture denied
23749
- // by some other finding's own Block policy still carries `block` here,
23750
- // and clearing the workspace's fallback would not have let it through.
23751
- // Gate on the value against what a fallback can produce; never read the
23752
- // field's presence as "this was the fallback's doing".
23753
- //
23754
- // Both are pinned as behaviour in @akasecurity/plugin-sdk's runtime suite.
23755
- // Closing either means moving the reason onto the finding row, which
23756
- // already carries its own action.
23757
- redactDegradedTo: ActionTaken.optional()
23758
- }).meta({ id: "EventMetadata" });
23759
- var Event = external_exports.object({
23760
- id: external_exports.guid(),
23761
- sourceTool: SourceTool,
23762
- kind: EventKind,
23763
- occurredAt: external_exports.iso.datetime(),
23764
- contentHash: external_exports.string(),
23765
- content: external_exports.string(),
23766
- metadata: EventMetadata.optional()
23767
- }).meta({ id: "Event" });
23768
- var IngestEvent = Event.meta({ id: "IngestEvent" });
23769
- var INGEST_BATCH_MAX = 100;
23770
- var IngestBatch = external_exports.object({
23771
- events: external_exports.array(IngestEvent).min(1).max(INGEST_BATCH_MAX),
23772
- // Dedup policy for this batch. Id-dedup ALWAYS applies. 'content-hash'
23773
- // additionally rejects any event whose contentHash the store has already
23774
- // recorded — for re-runnable bulk ingest (worktree scan, transcript
23775
- // backfill), where a re-run mints fresh event ids for identical content and
23776
- // would otherwise accumulate duplicates. Live hook traffic must NOT set it:
23777
- // two genuinely separate prompts can be byte-identical and both belong on
23778
- // the timeline.
23779
- dedupe: external_exports.literal("content-hash").optional()
23780
- }).meta({ id: "IngestBatch" });
23781
-
23782
23879
  // ../../packages/schema/src/zod/exception.ts
23783
23880
  var ExceptionScope = external_exports.enum(["once", "temporary", "permanent"]);
23784
23881
  var ExceptionConditions = external_exports.object({
@@ -23939,8 +24036,6 @@ var Policy = external_exports.object({
23939
24036
  // test `prohibitedModels` passes and `reversibleRuleIds` fails.
23940
24037
  provenance: PolicyProvenance.optional()
23941
24038
  }).meta({ id: "Policy" });
23942
- var KNOWN_BUILTIN_IDS = ["monitor", "warn", "redact", "vault", "block"];
23943
- var BuiltinPolicyId = external_exports.enum(KNOWN_BUILTIN_IDS).meta({ id: "BuiltinPolicyId" });
23944
24039
  var RedactFallback = BuiltinPolicyId.extract(["monitor", "warn", "block"]).meta({
23945
24040
  id: "RedactFallback"
23946
24041
  });
@@ -24296,7 +24391,7 @@ var VaultConsent = external_exports.object({
24296
24391
  });
24297
24392
 
24298
24393
  // ../../packages/schema/src/zod/local.ts
24299
- var WORKSPACE_SETTINGS_SPEC_VERSION = 8;
24394
+ var WORKSPACE_SETTINGS_SPEC_VERSION = 9;
24300
24395
  var RunMode = external_exports.enum(["standalone", "attached"]);
24301
24396
  var ControlPlaneConnection = external_exports.object({
24302
24397
  endpoint: external_exports.string().min(1),
@@ -24315,6 +24410,18 @@ var HistorySyncConsent = external_exports.object({
24315
24410
  payloadVersion: external_exports.number().int().positive(),
24316
24411
  endpoint: external_exports.string()
24317
24412
  });
24413
+ var ATTACHMENT_SCOPE_IDENTITY_MAX_LENGTH = 512;
24414
+ var AttachmentScopeEntry = external_exports.object({
24415
+ kind: external_exports.enum(["repo", "account"]),
24416
+ identity: printable(ATTACHMENT_SCOPE_IDENTITY_MAX_LENGTH).min(1),
24417
+ label: printable(80).optional(),
24418
+ enrolledAt: external_exports.iso.datetime()
24419
+ });
24420
+ var AttachmentScope = external_exports.object({
24421
+ endpoint: external_exports.string().min(1),
24422
+ entries: external_exports.array(AttachmentScopeEntry)
24423
+ });
24424
+ var AttachmentScopeEnvelope = AttachmentScope.extend({ entries: external_exports.array(external_exports.unknown()) });
24318
24425
  var WebChatCaptureConsent = external_exports.object({
24319
24426
  acknowledgedAt: external_exports.iso.datetime(),
24320
24427
  version: external_exports.number().int().positive()
@@ -24385,6 +24492,23 @@ var WorkspaceSettings = external_exports.object({
24385
24492
  // both widenings. Absent until granted, and a grant for a different endpoint
24386
24493
  // or an older payload no longer counts.
24387
24494
  historySyncConsent: HistorySyncConsent.optional(),
24495
+ // The identities a SCOPED attachment forwards and the deployment they were
24496
+ // enrolled for (see AttachmentScope). Absent until something is enrolled.
24497
+ //
24498
+ // `z.unknown()`, NOT `AttachmentScope`, and the difference is this field's
24499
+ // whole failure mode. A settings.json that fails this schema reads as the
24500
+ // unonboarded defaults (readUserSettings in @akasecurity/persistence), and the
24501
+ // next save writes those defaults back over it. Typed, one entry with an
24502
+ // unknown `kind`, a control character or a bad timestamp would cost the
24503
+ // attachment, every consent and onboardedAt, permanently. Untyped, the value
24504
+ // is kept exactly as found and validated where it is used: parseAttachmentScope
24505
+ // drops a bad entry by itself, and on a scoped attachment resolveScope reads a
24506
+ // bad envelope as no entries, which keeps every event local.
24507
+ //
24508
+ // No default: absent must stay absent, so defaultWorkspaceSettings() and a
24509
+ // fresh settings.json do not change. No `.meta({ id })`, like every field
24510
+ // here. Not a ManagedSettingKey.
24511
+ attachmentScope: external_exports.unknown().optional(),
24388
24512
  // What the browser extension may record from a web chat, and the grant that
24389
24513
  // authorizes it. Absent until the user answers: recording something that was
24390
24514
  // never recorded before is never an assumed grant on upgrade, so the whole
@@ -25273,7 +25397,15 @@ port.on("message", (job) => {
25273
25397
  post({ kind: "probed", id: job.id, verdict, worstMs, corroboratedMs });
25274
25398
  return;
25275
25399
  }
25276
- const context = job.filePath === void 0 ? void 0 : { filePath: job.filePath };
25400
+ if (job.eventKind !== void 0 && !EventKind.safeParse(job.eventKind).success) {
25401
+ post({
25402
+ kind: "failed",
25403
+ id: job.id,
25404
+ message: `unknown event kind ${JSON.stringify(job.eventKind)}`
25405
+ });
25406
+ return;
25407
+ }
25408
+ const context = job.filePath === void 0 && job.eventKind === void 0 ? void 0 : { filePath: job.filePath, eventKind: job.eventKind };
25277
25409
  if (job.attribute) {
25278
25410
  for (const [index, rule] of unverified.entries()) {
25279
25411
  post({ kind: "progress", index });