@akasecurity/ai-tc-claude-code 0.9.12 → 0.9.13

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.
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aka",
3
- "version": "0.9.12",
3
+ "version": "0.9.13",
4
4
  "description": "AI Traffic Control — inspect and govern AI prompts in Claude Code. Detection runs locally; events are recorded to a local SQLite store on your machine.",
5
5
  "homepage": "https://github.com/akasecurity/ai-tc",
6
6
  "author": { "name": "AKA Security" }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@akasecurity/ai-tc-claude-code",
3
- "version": "0.9.12",
3
+ "version": "0.9.13",
4
4
  "description": "AI Traffic Control — inspect and govern AI prompts in Claude Code",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",
@@ -29,8 +29,8 @@
29
29
  "vitest": "^4.1.11",
30
30
  "zod": "^4.5.4",
31
31
  "@akasecurity/plugin-runtime": "0.8.0",
32
- "@akasecurity/eslint-config": "0.8.0",
33
32
  "@akasecurity/persistence": "0.8.0",
33
+ "@akasecurity/eslint-config": "0.8.0",
34
34
  "@akasecurity/plugin-sdk": "0.8.0",
35
35
  "@akasecurity/scanner": "0.8.0",
36
36
  "@akasecurity/schema": "0.8.0",
@@ -20482,7 +20482,17 @@ var UNPRICEABLE_PROVIDERS = Object.freeze([
20482
20482
  "gateway",
20483
20483
  "unknown",
20484
20484
  "cli",
20485
- "api"
20485
+ "api",
20486
+ // The browser extension's native host records these as `llm_call.provider`
20487
+ // for a web-chat turn — the web tool id, deliberately never the vendor id
20488
+ // (`openai`/`anthropic`) the session root carries. Subscription traffic
20489
+ // burns rate-limit budget, not dollar credits, and listing them here is
20490
+ // what keeps that true structurally: a later maintainer who wants to price
20491
+ // web-chat traffic at API rates has to delete this entry first, and meet
20492
+ // the reason on the way, rather than quietly adding one to
20493
+ // PROVIDER_PLATFORM.
20494
+ "chatgpt",
20495
+ "claude-ai"
20486
20496
  ]);
20487
20497
  function platformForProvider(provider) {
20488
20498
  return PROVIDER_PLATFORM.get(provider.trim().toLowerCase()) ?? null;
@@ -20625,7 +20635,12 @@ var HARNESS = {
20625
20635
  ClaudeDesktop: "claudedesktop",
20626
20636
  ChatGpt: "chatgpt",
20627
20637
  ClaudeAi: "claudeai",
20628
- Api: "api"
20638
+ Api: "api",
20639
+ // Not a coding assistant a person drives — an in-process SDK embedded in an
20640
+ // application, so it has no IDE/CLI/desktop/web surface of its own. Carries
20641
+ // the same id as its SOURCE_TOOL counterpart, unlike every capture-side tool
20642
+ // whose wire spelling differs from its display spelling.
20643
+ AiTcSdk: "ai-tc-sdk"
20629
20644
  };
20630
20645
  var Harness = external_exports.enum(HARNESS).meta({ id: "Harness" });
20631
20646
  var SOURCE_TOOL = {
@@ -20641,9 +20656,15 @@ var SOURCE_TOOL = {
20641
20656
  // whose tool could not be identified both render through the read side's
20642
20657
  // miss path rather than as a harness of their own.
20643
20658
  Cli: "cli",
20644
- Unknown: "unknown"
20659
+ Unknown: "unknown",
20660
+ // The wire id an in-process, request-path SDK stamps on its own structural
20661
+ // rows (`request_decision`) — never a capture of prompt/response/tool text,
20662
+ // since the SDK sits in front of a model call rather than inside a coding
20663
+ // assistant's own hook contract.
20664
+ AiTcSdk: "ai-tc-sdk"
20645
20665
  };
20646
20666
  var SourceTool = external_exports.enum(SOURCE_TOOL).meta({ id: "SourceTool" });
20667
+ var WebSourceTool = SourceTool.extract(["ChatGpt", "ClaudeAi"]);
20647
20668
  var TOOL_TO_HARNESS = {
20648
20669
  [SOURCE_TOOL.ClaudeCode]: HARNESS.ClaudeCode,
20649
20670
  [SOURCE_TOOL.ClaudeDesktop]: HARNESS.ClaudeDesktop,
@@ -20652,7 +20673,12 @@ var TOOL_TO_HARNESS = {
20652
20673
  [SOURCE_TOOL.ChatGpt]: HARNESS.ChatGpt,
20653
20674
  [SOURCE_TOOL.Codex]: HARNESS.Codex,
20654
20675
  [SOURCE_TOOL.Antigravity]: HARNESS.Antigravity,
20655
- [SOURCE_TOOL.ClaudeAi]: HARNESS.ClaudeAi
20676
+ [SOURCE_TOOL.ClaudeAi]: HARNESS.ClaudeAi,
20677
+ // Wire and display id are the same string here, but the row still belongs:
20678
+ // both vocabularies carry the `AiTcSdk` member, and the join is exactly
20679
+ // their intersection — leaving a shared member out would read as an
20680
+ // uninstrumented tool on both surfaces, which this one is not.
20681
+ [SOURCE_TOOL.AiTcSdk]: HARNESS.AiTcSdk
20656
20682
  };
20657
20683
 
20658
20684
  // ../../packages/schema/src/zod/finding.ts
@@ -20686,7 +20712,8 @@ var FindingProvider = Harness.extract([
20686
20712
  "ClaudeAi",
20687
20713
  "Codex",
20688
20714
  "Antigravity",
20689
- "Api"
20715
+ "Api",
20716
+ "AiTcSdk"
20690
20717
  ]).meta({ id: "FindingProvider" });
20691
20718
  var FindingCategory = external_exports.enum([
20692
20719
  "secret",
@@ -21063,18 +21090,41 @@ var AuditEventType = external_exports.enum([
21063
21090
  // 'tool_call' is the reconciler's structural row for every call, while
21064
21091
  // 'tool_use' exists only where a hook enforced against the arguments.
21065
21092
  "tool_use",
21066
- // One row per model REFUSAL: a switch onto a prohibited model that was
21067
- // denied, or a turn refused because the session was already running on one.
21068
- // A structural row like the ones above rather than a capture — it carries
21069
- // the model that was refused and nothing the user typed, because what is
21070
- // worth recording about a governance decision is the decision, and prompt
21071
- // text is the thing this product exists to keep from travelling.
21093
+ // One row per model REFUSAL, across all four seams a prohibited model can be
21094
+ // stopped at: a switch onto it, a turn already running on it, a subagent
21095
+ // spawn asking for it, or a request-path refusal an embedded request-path
21096
+ // SDK makes in-process before the call leaves the application. Which seam
21097
+ // rides `attributes.refusal_seam`, never this member name. A structural row
21098
+ // like the ones above rather than a capture it carries the model that was
21099
+ // refused and nothing the user typed, because what is worth recording about
21100
+ // a governance decision is the decision, and prompt text is the thing this
21101
+ // product exists to keep from travelling.
21072
21102
  "model_refusal",
21103
+ // One row per request-path DECISION: a policy check an embedded request-path
21104
+ // SDK performs in-process before a model call leaves the application, or
21105
+ // against that call's non-streamed response. A structural row like
21106
+ // 'model_refusal' rather than a capture — content-free in the same way:
21107
+ // which side, which seam, what action and which field are decided rides
21108
+ // `attributes`, never this member name, and the matched text itself never
21109
+ // travels.
21110
+ //
21111
+ // A prohibited-model refusal on the request path is deliberately NOT this
21112
+ // member: it stays 'model_refusal' with `refusal_seam: 'request'`, so it
21113
+ // shares one bucket with the plugin's switch/turn/spawn refusals rather
21114
+ // than splitting one governance concept across two event types. This
21115
+ // member carries every OTHER request-path decision.
21116
+ "request_decision",
21073
21117
  // One row per config-inventory scan, hung off the session root. It is the
21074
21118
  // fact the posture inspection findings reference (findings require an
21075
21119
  // audit_event_id), and its started_at is the "scanned Nm ago" the read
21076
21120
  // surface renders.
21077
- "config_scan"
21121
+ "config_scan",
21122
+ // One row per reported browser-extension capture status, hung off the web
21123
+ // session root. The durable home of what one tab's network interception
21124
+ // is doing — a write-through of the native host's in-memory tracker, so a
21125
+ // second process (aka extension status) and a restarted host both have
21126
+ // somewhere to read it back from.
21127
+ "capture_status"
21078
21128
  ]).meta({ id: "AuditEventType" });
21079
21129
  var AttributeBag = external_exports.record(external_exports.string(), external_exports.unknown());
21080
21130
  var HostAttributes = external_exports.object({
@@ -21234,6 +21284,20 @@ var CaptureAttributes = external_exports.object({
21234
21284
  // repeated rather than referenced because a store reader opens this file.
21235
21285
  redact_degraded_to: ActionTaken.optional()
21236
21286
  }).catchall(external_exports.unknown());
21287
+ var CaptureStatusAttributes = external_exports.object({
21288
+ source_tool: external_exports.string().optional(),
21289
+ patched: external_exports.boolean().optional(),
21290
+ live: external_exports.boolean().optional(),
21291
+ blind: external_exports.boolean().optional(),
21292
+ sends_seen_dom: external_exports.number().int().nonnegative().optional(),
21293
+ exchanges_seen_net: external_exports.number().int().nonnegative().optional(),
21294
+ parse_failures: external_exports.number().int().nonnegative().optional(),
21295
+ unparsed_bodies: external_exports.number().int().nonnegative().optional(),
21296
+ shape_misses: external_exports.array(external_exports.string()).optional(),
21297
+ conversation_endpoints: external_exports.number().int().nonnegative().optional(),
21298
+ closed: external_exports.boolean().optional(),
21299
+ enforcement: external_exports.string().optional()
21300
+ }).catchall(external_exports.unknown());
21237
21301
  var ToolCallInspection = external_exports.object({
21238
21302
  ruleId: external_exports.string().min(1),
21239
21303
  ruleName: external_exports.string(),
@@ -22246,6 +22310,11 @@ var RemoteFailureKind = external_exports.enum([
22246
22310
  "rejected",
22247
22311
  "unreachable"
22248
22312
  ]);
22313
+ var ControlPlaneFailure = RemoteFailureKind.extract([
22314
+ "unauthorized",
22315
+ "forbidden",
22316
+ "unreachable"
22317
+ ]);
22249
22318
  var AttachDeviceRequest = external_exports.object({
22250
22319
  // This machine's own continuity id, so re-attaching ROTATES the credential
22251
22320
  // on one machine record instead of producing a second one. Client-minted
@@ -22785,7 +22854,12 @@ var EventMetadata = external_exports.object({
22785
22854
  // in — set by the browser extension's network capture so a stored `response`
22786
22855
  // row can be joined to the `llm_call` leaf describing the same turn. Absent
22787
22856
  // on every other capture path, which has no such id.
22788
- messageId: external_exports.string().optional(),
22857
+ //
22858
+ // Non-empty for the reason WebExchange.messageId is: it is the join key, and
22859
+ // a blank one matches no `llm_call` leaf. That refusal reaches only the
22860
+ // places an event is PARSED; the local write path types the event and parses
22861
+ // nothing, which is why `toCaptureAttributes` omits a blank one separately.
22862
+ messageId: external_exports.string().min(1).optional(),
22789
22863
  conversationId: external_exports.string().optional(),
22790
22864
  // How long THIS capture's inspection blocked its caller, in whole
22791
22865
  // milliseconds — the plugin's own added latency, NOT the LLM call it sat in
@@ -23860,6 +23934,18 @@ var HistorySyncConsent = external_exports.object({
23860
23934
  payloadVersion: external_exports.number().int().positive(),
23861
23935
  endpoint: external_exports.string()
23862
23936
  });
23937
+ var WebChatCaptureConsent = external_exports.object({
23938
+ acknowledgedAt: external_exports.iso.datetime(),
23939
+ version: external_exports.number().int().positive()
23940
+ });
23941
+ var WebChatResponseCapture = external_exports.enum(["with-findings", "always", "never"]);
23942
+ var WebChatCapture = external_exports.object({
23943
+ responses: WebChatResponseCapture.default("with-findings"),
23944
+ account: external_exports.boolean().default(false),
23945
+ // Absent until granted. Presence alone does not authorize anything — see
23946
+ // isWebChatCaptureConsentValid.
23947
+ consent: WebChatCaptureConsent.optional()
23948
+ });
23863
23949
  var BODY_RETENTION_DEFAULT_DAYS = 30;
23864
23950
  var BodyRetention = external_exports.object({
23865
23951
  enabled: external_exports.boolean().default(false),
@@ -23918,6 +24004,16 @@ var WorkspaceSettings = external_exports.object({
23918
24004
  // both widenings. Absent until granted, and a grant for a different endpoint
23919
24005
  // or an older payload no longer counts.
23920
24006
  historySyncConsent: HistorySyncConsent.optional(),
24007
+ // What the browser extension may record from a web chat, and the grant that
24008
+ // authorizes it. Absent until the user answers: recording something that was
24009
+ // never recorded before is never an assumed grant on upgrade, so the whole
24010
+ // block is optional rather than defaulted in. What an absent block means is
24011
+ // webChatCaptureOf's answer, in one place.
24012
+ //
24013
+ // Enforcement is NOT gated on this. A machine that has never answered still
24014
+ // blocks, redacts and warns on what a user sends; the grant covers what is
24015
+ // written down.
24016
+ webChatCapture: WebChatCapture.optional(),
23921
24017
  // Local body expiry (see BodyRetention). Off until switched on; expiring a
23922
24018
  // body never removes the row or its findings.
23923
24019
  bodyRetention: BodyRetention.default({
@@ -24025,7 +24121,10 @@ function toCaptureAttributes(event) {
24025
24121
  // `.catchall(z.unknown())` carries the long tail.
24026
24122
  ...metadata?.model !== void 0 ? { model: metadata.model } : {},
24027
24123
  ...metadata?.turnIndex !== void 0 ? { turn_index: metadata.turnIndex } : {},
24028
- ...metadata?.messageId !== void 0 ? { message_id: metadata.messageId } : {},
24124
+ // A blank id is omitted rather than stored: it is a join key and `''` joins
24125
+ // nothing. This runs on the local write path, which types the event but
24126
+ // never parses it, so EventMetadata's own `.min(1)` does not reach here.
24127
+ ...metadata?.messageId !== void 0 && metadata.messageId !== "" ? { message_id: metadata.messageId } : {},
24029
24128
  ...metadata?.conversationId !== void 0 ? { conversation_id: metadata.conversationId } : {}
24030
24129
  };
24031
24130
  }
@@ -24399,12 +24498,14 @@ var RecommendedActionIdParam = external_exports.object({ id: external_exports.st
24399
24498
  // ../../packages/schema/src/zod/settings-action.ts
24400
24499
  var HistorySyncConsentChoice = external_exports.enum(["granted", "revoked", "unchanged"]).meta({ id: "HistorySyncConsentChoice" });
24401
24500
  var ModelJudgeConsentChoice = external_exports.enum(["granted", "revoked", "unchanged"]).meta({ id: "ModelJudgeConsentChoice" });
24501
+ var WebChatCaptureConsentChoice = external_exports.enum(["granted", "revoked", "unchanged"]).meta({ id: "WebChatCaptureConsentChoice" });
24402
24502
  var SaveSettingsInput = external_exports.object({
24403
24503
  historicalAccess: external_exports.string(),
24404
24504
  modelJudgeConsent: ModelJudgeConsentChoice,
24405
24505
  historySyncConsent: HistorySyncConsentChoice,
24406
24506
  vaultConsent: external_exports.string(),
24407
24507
  vaultInlineReveal: external_exports.string(),
24508
+ webChatCaptureConsent: WebChatCaptureConsentChoice,
24408
24509
  // Widened to `string` like its neighbours rather than typed as
24409
24510
  // `RedactFallback`, on this module's own layering rule: shape here, VALUE at
24410
24511
  // the call site, so the domain check receives the type it was written for.
@@ -24619,11 +24720,24 @@ var WebExchange = external_exports.object({
24619
24720
  turnIndex: external_exports.number().int().nonnegative().optional(),
24620
24721
  toolCalls: external_exports.array(WebToolCall).default([]),
24621
24722
  // Absent when the adapter recovered no text. Capped by the caller at
24622
- // RESPONSE_TEXT_MAX_BYTES; `truncated` records that the cap was reached, so a
24623
- // short capture is never mistaken for a short reply.
24723
+ // RESPONSE_TEXT_MAX_BYTES, so a short capture is never mistaken for a short
24724
+ // reply.
24624
24725
  responseText: external_exports.string().optional(),
24726
+ // The stored text is short of the reply. It does NOT say which of the two
24727
+ // ceilings on this path cut it: the caller applies its own cap on the raw
24728
+ // bytes it reads off the wire, which can be reached by a stream whose
24729
+ // recovered text stays well under RESPONSE_TEXT_MAX_BYTES, and applies that
24730
+ // one to the text. A reader cannot tell them apart, and nothing downstream
24731
+ // should branch as though it could.
24625
24732
  truncated: external_exports.boolean().default(false)
24626
24733
  });
24734
+ var WebEnforcementState = external_exports.enum([
24735
+ "watching",
24736
+ "composer-only",
24737
+ "button-only",
24738
+ "unattached",
24739
+ "unknown"
24740
+ ]);
24627
24741
  var RESPONSE_TEXT_MAX_BYTES = 2 * 1024 * 1024;
24628
24742
  var WebCaptureStatus = external_exports.object({
24629
24743
  patched: external_exports.boolean(),
@@ -24635,8 +24749,66 @@ var WebCaptureStatus = external_exports.object({
24635
24749
  unparsedBodies: external_exports.number().int().nonnegative(),
24636
24750
  // The adapter-declared JSON key paths that were absent from a real payload —
24637
24751
  // the earliest signal that a site's contract moved.
24638
- shapeMisses: external_exports.array(external_exports.string()).default([])
24639
- });
24752
+ shapeMisses: external_exports.array(external_exports.string()).default([]),
24753
+ // How many `kind: 'conversation'` endpoints the reporting tab's adapter
24754
+ // compiled. Zero means this build declares none for the site, so observing
24755
+ // nothing is the design rather than a fault — the one fact that separates a
24756
+ // site nobody has surveyed yet from one whose contract moved. Defaulted so a
24757
+ // build predating the field is read as declaring nothing rather than refused.
24758
+ conversationEndpoints: external_exports.number().int().nonnegative().default(0),
24759
+ // The document that sent this report is going away. The bridge sets it on
24760
+ // its `pagehide` report and nowhere else.
24761
+ //
24762
+ // A property of the REPORT rather than of capture health, which is why
24763
+ // nothing in `deriveWebCaptureState` reads it and why it stays out of the
24764
+ // bridge's own report signature — a closing tab's last word must not be
24765
+ // suppressed for carrying the same health as the report before it. What
24766
+ // reads it is the per-site fold: a document that said it was unloading stops
24767
+ // voting on the site's state, so the reload the `blind` remediation asks for
24768
+ // can actually clear the verdict it was shown. A document that dies without
24769
+ // sending one is covered by CAPTURE_STATUS_DOCUMENT_QUIET_MS instead.
24770
+ //
24771
+ // Defaulted so a build predating the field reads as a document that never
24772
+ // said it was closing — which keeps it voting, the same as every report that
24773
+ // is not a final one.
24774
+ closed: external_exports.boolean().default(false),
24775
+ // What the DOM enforcement path is doing, which none of the counters above
24776
+ // can say: `sendsSeenDom` rises only once a send has COMPLETED, so a tab
24777
+ // whose watcher never bound reports zero exactly like a tab nobody typed in.
24778
+ // Defaulted to 'unknown' rather than 'watching' so a status from a build
24779
+ // predating the field is not read as reporting a healthy one.
24780
+ enforcement: WebEnforcementState.default("unknown")
24781
+ });
24782
+ function webCaptureStatusObservedTurnPath(status) {
24783
+ if (!status.patched) return true;
24784
+ if (status.conversationEndpoints === 0) return true;
24785
+ return status.blind || status.shapeMisses.length > 0 || status.parseFailures > 0 || status.unparsedBodies > 0 || status.exchangesSeenNet > 0;
24786
+ }
24787
+ function pickReportedCaptureStatus(candidates) {
24788
+ return candidates.find((c) => webCaptureStatusObservedTurnPath(c.status)) ?? candidates[0];
24789
+ }
24790
+ var CAPTURE_STATUS_RECENCY_MS = 30 * 24 * 60 * 60 * 1e3;
24791
+ var CAPTURE_STATUS_RECENCY_DAYS = CAPTURE_STATUS_RECENCY_MS / (24 * 60 * 60 * 1e3);
24792
+ var CAPTURE_STATUS_DOCUMENT_QUIET_MS = 12 * 60 * 60 * 1e3;
24793
+ function fromCaptureStatusAttributes(bag) {
24794
+ const parsedBag = CaptureStatusAttributes.safeParse(bag);
24795
+ if (!parsedBag.success) return null;
24796
+ const b = parsedBag.data;
24797
+ const parsedStatus = WebCaptureStatus.safeParse({
24798
+ patched: b.patched,
24799
+ live: b.live,
24800
+ blind: b.blind,
24801
+ sendsSeenDom: b.sends_seen_dom,
24802
+ exchangesSeenNet: b.exchanges_seen_net,
24803
+ parseFailures: b.parse_failures,
24804
+ unparsedBodies: b.unparsed_bodies,
24805
+ shapeMisses: b.shape_misses,
24806
+ conversationEndpoints: b.conversation_endpoints,
24807
+ closed: b.closed,
24808
+ enforcement: b.enforcement
24809
+ });
24810
+ return parsedStatus.success ? parsedStatus.data : null;
24811
+ }
24640
24812
 
24641
24813
  // ../../packages/persistence/src/paths.ts
24642
24814
  import {
@@ -26402,7 +26574,7 @@ var SESSION_ROOT = `event_type = 'session'`;
26402
26574
  var HAS_ACTIVITY = `EXISTS (
26403
26575
  SELECT 1 FROM audit_events c
26404
26576
  WHERE c.root_session_id = audit_events.id
26405
- AND c.event_type NOT IN ('hook', 'config_scan'))`;
26577
+ AND c.event_type NOT IN ('hook', 'config_scan', 'capture_status'))`;
26406
26578
  var SqliteActivityRepository = class {
26407
26579
  constructor(db, now = () => Date.now()) {
26408
26580
  this.db = db;
@@ -26429,10 +26601,10 @@ var SqliteActivityRepository = class {
26429
26601
  SELECT id FROM audit_events WHERE event_type = 'session' AND started_at >= ?
26430
26602
  UNION
26431
26603
  SELECT root_session_id FROM audit_events INDEXED BY idx_audit_started_at
26432
- WHERE started_at >= ?
26604
+ WHERE started_at >= ? AND event_type <> 'capture_status'
26433
26605
  UNION
26434
26606
  SELECT root_session_id FROM audit_events INDEXED BY idx_audit_ended_at
26435
- WHERE ended_at >= ?)`,
26607
+ WHERE ended_at >= ? AND event_type <> 'capture_status')`,
26436
26608
  [liveThreshold, liveThreshold, liveThreshold]
26437
26609
  );
26438
26610
  const toolCallsToday = countScalar(
@@ -26839,7 +27011,10 @@ var SqliteAuditEventsRepository = class {
26839
27011
  attributes = excluded.attributes,
26840
27012
  ended_at = excluded.ended_at
26841
27013
  WHERE COALESCE(json_extract(excluded.attributes, '$.output_tokens'), 0)
26842
- > COALESCE(json_extract(audit_events.attributes, '$.output_tokens'), 0)`
27014
+ > COALESCE(json_extract(audit_events.attributes, '$.output_tokens'), 0)
27015
+ OR (json_extract(excluded.attributes, '$.usage_source') IS NOT NULL
27016
+ AND json_extract(excluded.attributes, '$.output_tokens') IS NULL
27017
+ AND excluded.attributes <> audit_events.attributes)`
26843
27018
  );
26844
27019
  this.upsertSessionRootStmt = db.prepare(
26845
27020
  `INSERT OR IGNORE INTO audit_events
@@ -27107,6 +27282,87 @@ var SqliteBodyRetentionRepository = class {
27107
27282
  }
27108
27283
  };
27109
27284
 
27285
+ // ../../packages/persistence/src/repositories/capture-status.ts
27286
+ var STATUS_LOOKBACK_ROWS = 128;
27287
+ var SqliteCaptureStatusRepository = class {
27288
+ constructor(db) {
27289
+ this.db = db;
27290
+ this.recentStmt = db.prepare(
27291
+ `SELECT a.started_at AS startedAt,
27292
+ a.attributes AS attributes,
27293
+ a.root_session_id AS rootSessionId
27294
+ FROM audit_events a
27295
+ WHERE a.event_type = 'capture_status'
27296
+ AND a.source_tool = ?
27297
+ AND a.started_at >= ?
27298
+ ORDER BY a.started_at DESC, a.id DESC
27299
+ LIMIT ?`
27300
+ );
27301
+ }
27302
+ db;
27303
+ recentStmt;
27304
+ /**
27305
+ * Every document that reported for a site, in registry order by site, from
27306
+ * the last `CAPTURE_STATUS_RECENCY_MS`.
27307
+ *
27308
+ * SEVERAL per site, not one: a browser is many documents and each reports
27309
+ * for itself, so one row per site is a choice about which of them a user
27310
+ * sees — and the newest is the wrong one, since a healthy tab writing a
27311
+ * fresh report would hide a drifting tab's verdict, which is the whole
27312
+ * reason these rows exist. The pick WITHIN a document is made here (the
27313
+ * unchanged `pickReportedCaptureStatus`, over that document's own rows);
27314
+ * choosing between documents belongs where the state semantics live, and
27315
+ * that is `reportedCaptureDocumentForSite` in `@akasecurity/detections` —
27316
+ * this package may not import it.
27317
+ *
27318
+ * `now` is a required argument rather than a `Date.now()` read, so a caller
27319
+ * that already holds a render instant passes THAT one and a test can drive
27320
+ * the window without moving the wall clock.
27321
+ *
27322
+ * A site whose reports have all aged out contributes nothing, so it derives
27323
+ * to `unreported`. That is the point: nothing but the browser extension ever
27324
+ * writes these rows, so an uninstalled extension's last verdict would
27325
+ * otherwise stand as a live claim for ever with no later report able to
27326
+ * clear it.
27327
+ */
27328
+ latest(now) {
27329
+ const since = now - CAPTURE_STATUS_RECENCY_MS;
27330
+ const documents = [];
27331
+ for (const tool of WebSourceTool.options) {
27332
+ const rows = /* @__PURE__ */ new Map();
27333
+ const lastWord = /* @__PURE__ */ new Map();
27334
+ for (const row of allRows(this.recentStmt, [
27335
+ tool,
27336
+ since,
27337
+ STATUS_LOOKBACK_ROWS
27338
+ ])) {
27339
+ const status = fromCaptureStatusAttributes(parseJsonObject(row.attributes));
27340
+ if (status === null) continue;
27341
+ const record2 = { tool, observedAt: epochMillisToIso(row.startedAt), status };
27342
+ const group = rows.get(row.rootSessionId);
27343
+ if (group === void 0) {
27344
+ rows.set(row.rootSessionId, [record2]);
27345
+ lastWord.set(row.rootSessionId, { at: record2.observedAt, closed: status.closed });
27346
+ } else {
27347
+ group.push(record2);
27348
+ }
27349
+ }
27350
+ for (const [root, candidates] of rows) {
27351
+ const picked = pickReportedCaptureStatus(candidates);
27352
+ const last = lastWord.get(root);
27353
+ if (picked === void 0 || last === void 0) continue;
27354
+ documents.push({
27355
+ ...picked,
27356
+ ...root === null ? {} : { rootSessionId: root },
27357
+ lastReportAt: last.at,
27358
+ closed: last.closed
27359
+ });
27360
+ }
27361
+ }
27362
+ return documents;
27363
+ }
27364
+ };
27365
+
27110
27366
  // ../../packages/persistence/src/repositories/classified-data.ts
27111
27367
  var SqliteClassifiedDataRepository = class {
27112
27368
  constructor(db) {
@@ -32680,6 +32936,7 @@ function openAndInitialize(file2, base, skipTags) {
32680
32936
  activity: new SqliteActivityRepository(db),
32681
32937
  sourceProject: new SqliteSourceProjectRepository(db),
32682
32938
  auditEvents: new SqliteAuditEventsRepository(db),
32939
+ captureStatus: new SqliteCaptureStatusRepository(db),
32683
32940
  classifiedData: new SqliteClassifiedDataRepository(db),
32684
32941
  inspectionDefinitions: new SqliteInspectionDefinitionsRepository(db),
32685
32942
  inspectionFindings: new SqliteInspectionFindingsRepository(db),
@@ -32720,6 +32977,7 @@ function openLocalDatabase(dir, options = {}) {
32720
32977
  activity,
32721
32978
  sourceProject,
32722
32979
  auditEvents,
32980
+ captureStatus,
32723
32981
  classifiedData,
32724
32982
  inspectionDefinitions,
32725
32983
  inspectionFindings,
@@ -32937,6 +33195,7 @@ function openLocalDatabase(dir, options = {}) {
32937
33195
  activity,
32938
33196
  sourceProject,
32939
33197
  auditEvents,
33198
+ captureStatus,
32940
33199
  classifiedData,
32941
33200
  inspectionDefinitions,
32942
33201
  inspectionFindings,
@@ -34041,6 +34300,56 @@ var CONFIG_POSTURE_RULES = [
34041
34300
  }
34042
34301
  ];
34043
34302
 
34303
+ // ../../packages/detections/src/posture/web-capture-posture.ts
34304
+ var RULE_VERSION2 = "1";
34305
+ var DRIFT_MIN_PARSE_FAILURES = 2;
34306
+ var WEB_CAPTURE_DRIFT_STATES = /* @__PURE__ */ new Set([
34307
+ "blind",
34308
+ "degraded"
34309
+ ]);
34310
+ var WEB_CAPTURE_DRIFT_RULE = {
34311
+ ruleId: "web-capture-drift",
34312
+ version: RULE_VERSION2,
34313
+ name: "Web chat capture is not reading the site",
34314
+ category: "config",
34315
+ severity: "medium",
34316
+ definition: JSON.stringify({
34317
+ kind: "web-capture-drift",
34318
+ states: [...WEB_CAPTURE_DRIFT_STATES],
34319
+ minParseFailures: DRIFT_MIN_PARSE_FAILURES
34320
+ })
34321
+ };
34322
+ var STATIC_COPY = {
34323
+ active: { headline: "turns are being observed on this site" },
34324
+ unreported: {
34325
+ // Says "recently" rather than "yet": the store read is bounded to
34326
+ // CAPTURE_STATUS_RECENCY_MS, so this state covers a site nothing has ever
34327
+ // reported for AND one whose last report has aged out. The two are the
34328
+ // same fact to a reader — nobody has confirmed anything lately — and the
34329
+ // copy may not claim the stronger of them.
34330
+ headline: `no report in the last ${String(CAPTURE_STATUS_RECENCY_DAYS)} days \u2014 open the site in Chrome with the extension loaded`
34331
+ },
34332
+ standby: {
34333
+ headline: "this build declares no endpoints for the site, so nothing is observed yet"
34334
+ },
34335
+ unpatched: {
34336
+ // Says what the flags say and no more. `patched` is false both for a tap
34337
+ // that installed and hooked neither transport and for one that never ran
34338
+ // at all — a page reports the same status either way, so the copy may not
34339
+ // assert one of them.
34340
+ headline: "the page tap captured neither fetch nor XHR \u2014 it may not have installed; reload the extension at chrome://extensions"
34341
+ },
34342
+ idle: { headline: "watching; no turn has been observed yet" },
34343
+ blind: {
34344
+ headline: "messages were sent in the page that the network capture never saw",
34345
+ remediation: "reload the tab. If it persists after `aka update` and reloading the extension at chrome://extensions, the site's send path has changed and needs a new extension build."
34346
+ },
34347
+ degraded: {
34348
+ headline: "the site's payloads no longer carry the fields the extension reads",
34349
+ remediation: "run `aka update`, then reload the extension at chrome://extensions. If it stays degraded after an update, the site's contract has changed and needs a new extension build."
34350
+ }
34351
+ };
34352
+
34044
34353
  // ../../packages/detections/src/security/redos-probe.ts
34045
34354
  var BUDGET_MS = 100;
34046
34355
  var EXPONENTIAL_UNITS = [