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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/scripts/stop.js CHANGED
@@ -50,7 +50,7 @@ var require_ignore = __commonJS({
50
50
  var REGEX_SPLITALL_CRLF = /\r?\n/g;
51
51
  var REGEX_TEST_INVALID_PATH = /^\.{0,2}\/|^\.{1,2}$/;
52
52
  var REGEX_TEST_TRAILING_SLASH = /\/$/;
53
- var SLASH2 = "/";
53
+ var SLASH3 = "/";
54
54
  var TMP_KEY_IGNORE = "node-ignore";
55
55
  if (typeof Symbol !== "undefined") {
56
56
  TMP_KEY_IGNORE = /* @__PURE__ */ Symbol.for("node-ignore");
@@ -422,11 +422,11 @@ var require_ignore = __commonJS({
422
422
  if (!REGEX_TEST_TRAILING_SLASH.test(path)) {
423
423
  return this.test(path);
424
424
  }
425
- const slices = path.split(SLASH2).filter(Boolean);
425
+ const slices = path.split(SLASH3).filter(Boolean);
426
426
  slices.pop();
427
427
  if (slices.length) {
428
428
  const parent = this._t(
429
- slices.join(SLASH2) + SLASH2,
429
+ slices.join(SLASH3) + SLASH3,
430
430
  this._testCache,
431
431
  true,
432
432
  slices
@@ -442,14 +442,14 @@ var require_ignore = __commonJS({
442
442
  return cache[path];
443
443
  }
444
444
  if (!slices) {
445
- slices = path.split(SLASH2).filter(Boolean);
445
+ slices = path.split(SLASH3).filter(Boolean);
446
446
  }
447
447
  slices.pop();
448
448
  if (!slices.length) {
449
449
  return cache[path] = this._rules.test(path, checkUnignored, MODE_IGNORE);
450
450
  }
451
451
  const parent = this._t(
452
- slices.join(SLASH2) + SLASH2,
452
+ slices.join(SLASH3) + SLASH3,
453
453
  cache,
454
454
  checkUnignored,
455
455
  slices
@@ -492,8 +492,8 @@ var require_ignore = __commonJS({
492
492
  });
493
493
 
494
494
  // ../../packages/plugin-sdk/src/config.ts
495
- import { existsSync as existsSync7 } from "fs";
496
- import { join as join13 } from "path";
495
+ import { existsSync as existsSync8 } from "fs";
496
+ import { join as join16 } from "path";
497
497
 
498
498
  // ../../packages/persistence/src/attached-derived.ts
499
499
  import { rmSync } from "fs";
@@ -503,6 +503,14 @@ import { join } from "path";
503
503
  import { chmodSync as chmodSync2, lstatSync as lstatSync2, readFileSync, rmSync as rmSync3, statSync } from "fs";
504
504
  import { join as join2 } from "path";
505
505
 
506
+ // ../../packages/schema/src/drizzle/deferred-migrations.ts
507
+ var DEFERRED_MIGRATION_TAGS = [
508
+ "0031_audit_capture_by_time_index",
509
+ "0032_audit_capture_by_id_index",
510
+ "0033_audit_capture_location_index",
511
+ "0034_findings_read_indexes"
512
+ ];
513
+
506
514
  // ../../packages/schema/src/exception-scope.ts
507
515
  var MINUTE_MS = 6e4;
508
516
  var HOUR_MS = 60 * MINUTE_MS;
@@ -2320,18 +2328,18 @@ var validateAsync = async (schema, value, _ctx) => {
2320
2328
  return result.issues.length === 0;
2321
2329
  };
2322
2330
  var _encode = (_Err) => {
2323
- const parse3 = _parse(_Err);
2331
+ const parse4 = _parse(_Err);
2324
2332
  const fn = (schema, value, _ctx, _params) => {
2325
2333
  const ctx = _ctx ? { ..._ctx, direction: "backward" } : { direction: "backward" };
2326
- return parse3(schema, value, ctx, finalizeParams(fn, _params));
2334
+ return parse4(schema, value, ctx, finalizeParams(fn, _params));
2327
2335
  };
2328
2336
  return fn;
2329
2337
  };
2330
2338
  var encode = /* @__PURE__ */ _encode($ZodRealError);
2331
2339
  var _decode = (_Err) => {
2332
- const parse3 = _parse(_Err);
2340
+ const parse4 = _parse(_Err);
2333
2341
  const fn = (schema, value, _ctx, _params) => {
2334
- return parse3(schema, value, _ctx, finalizeParams(fn, _params));
2342
+ return parse4(schema, value, _ctx, finalizeParams(fn, _params));
2335
2343
  };
2336
2344
  return fn;
2337
2345
  };
@@ -20312,6 +20320,15 @@ var FindingCategory = external_exports.enum([
20312
20320
  ]).meta({ id: "FindingCategory" });
20313
20321
  var FindingOrigin = external_exports.enum(["in-flight", "at-rest"]).meta({ id: "FindingOrigin" });
20314
20322
  var FindingStatus = external_exports.enum(["open", "handled", "resolved", "dismissed"]).meta({ id: "FindingStatus" });
20323
+ var SyncFailureReason = external_exports.enum(["deployment_refused", "payload_invalid", "detached_undelivered"]).meta({ id: "SyncFailureReason" });
20324
+ var FindingDeliveryState = external_exports.enum(["sent", "queued", "not_sent", "never_offered", "local_scan"]).meta({ id: "FindingDeliveryState" });
20325
+ var FindingDelivery = external_exports.object({
20326
+ state: FindingDeliveryState,
20327
+ // The delivery time for `sent`; the failure time for `not_sent` when recorded.
20328
+ at: external_exports.iso.datetime().optional(),
20329
+ // Only on `not_sent`, and only when a known reason was recorded.
20330
+ reason: SyncFailureReason.optional()
20331
+ }).meta({ id: "FindingDelivery" });
20315
20332
  var ResolutionMethod = external_exports.enum([
20316
20333
  "enforced-in-flight",
20317
20334
  "fixed-at-source",
@@ -20368,7 +20385,10 @@ var FindingInstance = external_exports.object({
20368
20385
  // The session that event belongs to, when it has one — the seam a
20369
20386
  // per-instance "view session" link needs. Absent for events captured
20370
20387
  // outside a session.
20371
- sessionId: external_exports.string().optional()
20388
+ sessionId: external_exports.string().optional(),
20389
+ // The delivery state of the event above (see FindingDelivery). Optional so
20390
+ // readers that do not project it stay valid.
20391
+ delivery: FindingDelivery.optional()
20372
20392
  }).meta({ id: "FindingInstance" });
20373
20393
  var FindingGroup = external_exports.object({
20374
20394
  id: external_exports.string(),
@@ -20385,13 +20405,11 @@ var FindingGroup = external_exports.object({
20385
20405
  latestDetectedAt: external_exports.iso.datetime(),
20386
20406
  instances: external_exports.array(FindingInstance),
20387
20407
  // Derived from instances' statuses with open-dominates precedence (see
20388
- // buildFindingGroups). Undefined only when no instance carries a status.
20408
+ // foldGroupStatus). Undefined only when no instance carries a status.
20389
20409
  status: FindingStatus.optional(),
20390
- // The distinct people across the WHOLE group, not just the `instances`
20391
- // preview — from the store's whole-group aggregate when it supplies one,
20392
- // else folded from the rows (see buildFindingGroups). Undefined when no
20393
- // instance carries a user, or when the store supplied whole-group folds
20394
- // without one.
20410
+ // The distinct people across the WHOLE group, not just the instances
20411
+ // carried here. Undefined when no instance carries a user, or when the
20412
+ // store supplied whole-group folds without one.
20395
20413
  users: external_exports.array(FindingUser).optional()
20396
20414
  }).meta({ id: "FindingGroup" });
20397
20415
  var FindingStats = external_exports.object({
@@ -20420,20 +20438,33 @@ var FindingFacets = external_exports.object({
20420
20438
  // counted under no value.
20421
20439
  status: external_exports.array(FindingFacetItem),
20422
20440
  // Host tool (attributes.tool_name). Present only on the instance-level
20423
- // reads, which can filter by it; the grouped read omits the dimension
20441
+ // reads, which can filter by it; the type-level read omits the dimension
20424
20442
  // because a group spans tools.
20425
- tool: external_exports.array(FindingFacetItem).optional()
20443
+ tool: external_exports.array(FindingFacetItem).optional(),
20444
+ // Delivery states (FindingDeliveryState). Present only on the
20445
+ // instance-level reads, like `tool`.
20446
+ deployment: external_exports.array(FindingFacetItem).optional()
20426
20447
  }).meta({ id: "FindingFacets" });
20427
- var ListGroupedFindingsQuery = external_exports.object({
20448
+ var FindingTypeSummary = FindingGroup.omit({ instances: true, match: true }).meta({
20449
+ id: "FindingTypeSummary"
20450
+ });
20451
+ var MAX_FINDING_TYPES_LIMIT = 100;
20452
+ var ListFindingTypesQuery = external_exports.object({
20428
20453
  // NOTE: severity filters by Severity (critical/high/medium/low), not by
20429
- // FindingAction.
20454
+ // FindingAction. It narrows TYPES: a type's severity is the one its newest
20455
+ // firing version carries, and this list pages types.
20456
+ //
20457
+ // That is NOT a claim the findings of a type share it. A rule can hold several
20458
+ // definition versions at different severities, so a type kept by this filter
20459
+ // can hold findings that individually do not match — see totals.findings on
20460
+ // ListFindingTypesResponse, which counts them all.
20430
20461
  severity: external_exports.array(Severity).optional(),
20431
20462
  subtype: external_exports.array(external_exports.string()).optional(),
20432
20463
  provider: external_exports.array(FindingProvider).optional(),
20433
20464
  action: external_exports.array(FindingAction).optional(),
20434
- // Matches a group's DERIVED status (see FindingGroup.status), not its
20435
- // individual instances' — so a filtered group's Status column always reads
20436
- // one of the requested values.
20465
+ // Matches a type's DERIVED status (see FindingGroup.status), not its
20466
+ // individual findings' — so a filtered row's status always reads one of the
20467
+ // requested values.
20437
20468
  status: external_exports.array(FindingStatus).optional(),
20438
20469
  q: external_exports.string().optional(),
20439
20470
  // Scope to findings whose event carries this session id (the Activity page's
@@ -20443,23 +20474,37 @@ var ListGroupedFindingsQuery = external_exports.object({
20443
20474
  // from a time-scoped page (Activity's range) can carry that scope. Absent
20444
20475
  // means all time — this list has no default window.
20445
20476
  from: external_exports.iso.datetime().optional(),
20446
- // A group or instance id that must appear in the page even when the cursor
20447
- // has already advanced past its sort position. This is what keeps the
20448
- // Findings page's one-shot ?finding= deep link resolving once the list
20449
- // paginates: the target group is appended out of sort order rather than
20450
- // scanning forward for it. Never affects totals, facets or the cursor.
20477
+ // A RULE id that must appear in the page even when the cursor has already
20478
+ // advanced past its sort position. This is what keeps the selected type
20479
+ // visible in the list once it paginates: the target is appended out of sort
20480
+ // order rather than scanned forward for. Never affects totals, facets or the
20481
+ // cursor. Unlike the grouped read this replaces, it names a rule only — an
20482
+ // instance id is resolved by `findingInstance`, which is a primary-key seek
20483
+ // and so is not bounded by what any page happens to hold.
20451
20484
  includeId: external_exports.string().optional(),
20452
- groupBy: external_exports.literal("type").optional(),
20453
- limit: external_exports.coerce.number().int().min(1).max(100).optional(),
20485
+ limit: external_exports.coerce.number().int().min(1).max(MAX_FINDING_TYPES_LIMIT).optional(),
20454
20486
  cursor: external_exports.string().optional()
20455
20487
  });
20456
- var ListGroupedFindingsResponse = external_exports.object({
20488
+ var ListFindingTypesResponse = external_exports.object({
20457
20489
  totals: external_exports.object({
20490
+ // Findings belonging to the matching TYPES — not findings that each match
20491
+ // the filters. The filters here select types, so a type that survives
20492
+ // contributes its whole instanceCount.
20493
+ //
20494
+ // `status` is the one exception, narrowed per finding via
20495
+ // countInstancesByStatus. `severity`, `provider` and `action` are not, so
20496
+ // this can exceed what the instance read reports for the same filters: a
20497
+ // rule whose severity moved between versions is kept on its newest and
20498
+ // still counts its older findings. Narrowing the other three needs
20499
+ // per-dimension counts the aggregate does not carry today.
20458
20500
  findings: external_exports.number().int().nonnegative(),
20459
- groups: external_exports.number().int().nonnegative()
20501
+ // Counts TYPES, which is the unit this read pages. The instance read's
20502
+ // own totals count findings; the two deliberately answer different
20503
+ // questions and are never summed.
20504
+ types: external_exports.number().int().nonnegative()
20460
20505
  }),
20461
20506
  facets: FindingFacets,
20462
- items: external_exports.array(FindingGroup),
20507
+ items: external_exports.array(FindingTypeSummary),
20463
20508
  nextCursor: external_exports.string().nullable(),
20464
20509
  // Present only on session-scoped queries (`sessionId` set): per ruleId, how
20465
20510
  // many times that rule fired in the session's persisted transcript. Findings
@@ -20467,7 +20512,7 @@ var ListGroupedFindingsResponse = external_exports.object({
20467
20512
  // every firing, so the two numbers legitimately differ — this map lets a
20468
20513
  // session-scoped view show both.
20469
20514
  sessionFirings: external_exports.record(external_exports.string(), external_exports.number().int().nonnegative()).optional()
20470
- }).meta({ id: "ListGroupedFindingsResponse" });
20515
+ }).meta({ id: "ListFindingTypesResponse" });
20471
20516
  var ApplyFindingActionRequest = external_exports.object({
20472
20517
  // 'quarantined' is system-assigned (see FindingAction) — clients may not set
20473
20518
  // it, so it is excluded from the request contract. The mapping helper
@@ -20496,16 +20541,19 @@ var FindingInstanceDetail = FindingInstance.extend({
20496
20541
  var MAX_FLAT_FINDINGS_LIMIT = 200;
20497
20542
  var ListFindingInstancesQuery = external_exports.object({
20498
20543
  severity: external_exports.array(Severity).optional(),
20499
- // Rule ids, the same vocabulary the grouped list's `subtype` carries.
20544
+ // Rule ids, the same vocabulary the types list's `subtype` carries. Pinning
20545
+ // ONE of them is how the master/detail view scopes its right-hand panel.
20500
20546
  subtype: external_exports.array(external_exports.string()).optional(),
20501
20547
  provider: external_exports.array(FindingProvider).optional(),
20502
20548
  action: external_exports.array(FindingAction).optional(),
20503
20549
  // Matches each instance's OWN derived status (deriveFindingStatus), unlike
20504
- // the grouped query's group-level fold.
20550
+ // the types query's type-level fold.
20505
20551
  status: external_exports.array(FindingStatus).optional(),
20506
20552
  // Exact host-tool names (attributes.tool_name, e.g. 'Bash'). A real filter,
20507
20553
  // where the free-text `q` can only match the rendered "via Bash" label.
20508
20554
  tool: external_exports.array(external_exports.string()).optional(),
20555
+ // The delivery state of each finding's event (see FindingDelivery).
20556
+ deployment: external_exports.array(FindingDeliveryState).optional(),
20509
20557
  // Exact repository / file-path matches, for the drill-down out of the
20510
20558
  // locations view. A row whose event carries no repo/file matches neither.
20511
20559
  repo: external_exports.string().optional(),
@@ -20518,37 +20566,50 @@ var ListFindingInstancesQuery = external_exports.object({
20518
20566
  });
20519
20567
  var ListFindingInstancesResponse = external_exports.object({
20520
20568
  // Instances matching the filters across the whole scope, not just this
20521
- // page — cursor-independent, like the grouped list's totals.
20569
+ // page — cursor-independent, like the types list's totals.
20522
20570
  totals: external_exports.object({ findings: external_exports.number().int().nonnegative() }),
20523
- // Counts in INSTANCES here, where the grouped response counts groups. Each
20571
+ // Counts in INSTANCES here, where the types response counts types. Each
20524
20572
  // dimension still excludes its own filter.
20525
20573
  facets: FindingFacets,
20526
20574
  items: external_exports.array(FindingInstanceDetail),
20527
20575
  nextCursor: external_exports.string().nullable()
20528
20576
  }).meta({ id: "ListFindingInstancesResponse" });
20529
- var FindingLocationFile = external_exports.object({
20530
- // Empty when the instances carried no file path (a prompt or a tool call
20531
- // with no file attribution).
20532
- file: external_exports.string(),
20533
- instanceCount: external_exports.number().int().nonnegative(),
20534
- maxSeverity: Severity,
20535
- latestDetectedAt: external_exports.iso.datetime(),
20536
- // Folded from the instances' derived statuses with the same
20537
- // open-dominates precedence a group uses.
20538
- status: FindingStatus.optional(),
20539
- // Distinct rules seen at this location, capped — the row shows them as
20540
- // chips, and the count is what conveys scale.
20541
- ruleIds: external_exports.array(external_exports.string())
20542
- }).meta({ id: "FindingLocationFile" });
20543
- var FindingLocationRepo = external_exports.object({
20577
+ var ListFindingInstancesPage = external_exports.object({
20578
+ items: external_exports.array(FindingInstanceDetail),
20579
+ nextCursor: external_exports.string().nullable()
20580
+ }).meta({ id: "ListFindingInstancesPage" });
20581
+ var FindingLocationSummary = external_exports.object({
20582
+ // Opaque, stable, minted from the pair by encodeLocationId. It exists
20583
+ // because a location's identity is two values and a URL param carries one:
20584
+ // `?loc=` names a location the way `?rule=` names a type. Only ever compared
20585
+ // for EQUALITY — the page's selection check, this read's `includeId`, the
20586
+ // client's page dedupe — never decoded, and never a sort key.
20587
+ id: external_exports.string(),
20544
20588
  /** Empty when the instances carried no repo attribute. */
20545
20589
  repo: external_exports.string(),
20590
+ // Empty when the instances carried no file path (a prompt, or a tool call
20591
+ // with no file attribution). Both halves empty is a real location — usually
20592
+ // the largest one in a store — and is selectable like any other.
20593
+ file: external_exports.string(),
20546
20594
  instanceCount: external_exports.number().int().nonnegative(),
20595
+ // The WORST severity present, not the first row's. It is this list's primary
20596
+ // sort key, so it is also what explains why a row is where it is, and it is
20597
+ // how a reader decides what to open without opening everything.
20547
20598
  maxSeverity: Severity,
20548
20599
  latestDetectedAt: external_exports.iso.datetime(),
20600
+ // Folded from the instances' derived statuses with the same open-dominates
20601
+ // precedence a group uses, so it answers "is anything left to do here" and
20602
+ // not much more: a location holding 1 open among 40 resolved reads like one
20603
+ // holding 40 open. That loss is accepted — the panel beside this list
20604
+ // carries each finding's own status, and instanceCount sits next to the
20605
+ // badge.
20549
20606
  status: FindingStatus.optional(),
20550
- files: external_exports.array(FindingLocationFile)
20551
- }).meta({ id: "FindingLocationRepo" });
20607
+ // Every distinct rule seen at this location, UNCAPPED — so the length is a
20608
+ // tally rather than a sample and a row can say how many there are. Bounded
20609
+ // by the ruleset, not by the store. The view bounds what it DISPLAYS.
20610
+ ruleIds: external_exports.array(external_exports.string())
20611
+ }).meta({ id: "FindingLocationSummary" });
20612
+ var MAX_FINDING_LOCATIONS_LIMIT = 100;
20552
20613
  var ListFindingLocationsQuery = external_exports.object({
20553
20614
  severity: external_exports.array(Severity).optional(),
20554
20615
  subtype: external_exports.array(external_exports.string()).optional(),
@@ -20558,21 +20619,47 @@ var ListFindingLocationsQuery = external_exports.object({
20558
20619
  // instances that match, and folds its status from those.
20559
20620
  status: external_exports.array(FindingStatus).optional(),
20560
20621
  tool: external_exports.array(external_exports.string()).optional(),
20622
+ // The delivery state of each finding's event (see FindingDelivery).
20623
+ deployment: external_exports.array(FindingDeliveryState).optional(),
20561
20624
  q: external_exports.string().optional(),
20562
20625
  sessionId: external_exports.string().optional(),
20563
20626
  from: external_exports.iso.datetime().optional(),
20564
- limit: external_exports.coerce.number().int().min(1).max(500).optional()
20627
+ // A LOCATION id (see FindingLocationSummary.id) that must appear in the page
20628
+ // even when the cursor has already advanced past its sort position — the
20629
+ // counterpart of ListFindingTypesQuery.includeId, and needed far more often
20630
+ // here. Selecting a row pushes the URL, which re-renders the server and resets
20631
+ // the client's page cache to page 0; with distinct (repo, file) pairs running
20632
+ // into the thousands, a selection sitting off page 0 is the ordinary case
20633
+ // rather than a deep-link corner. Never affects totals, facets or the cursor.
20634
+ includeId: external_exports.string().optional(),
20635
+ limit: external_exports.coerce.number().int().min(1).max(MAX_FINDING_LOCATIONS_LIMIT).optional(),
20636
+ cursor: external_exports.string().optional()
20565
20637
  });
20566
20638
  var ListFindingLocationsResponse = external_exports.object({
20567
20639
  totals: external_exports.object({
20640
+ // Findings matching the filters across the whole scope. Unlike the types
20641
+ // read's same-named field this needs no caveat: the filters here narrow
20642
+ // per finding, so this is the sum of every row's instanceCount.
20568
20643
  findings: external_exports.number().int().nonnegative(),
20569
- repos: external_exports.number().int().nonnegative(),
20570
- files: external_exports.number().int().nonnegative()
20644
+ // Counts LOCATIONS, the unit this read pages — the number the paginator
20645
+ // states. The facets beside it count FINDINGS (see below); a surface
20646
+ // showing both says which is which.
20647
+ locations: external_exports.number().int().nonnegative()
20571
20648
  }),
20572
- /** Sorted by max severity, then most recent. */
20573
- items: external_exports.array(FindingLocationRepo),
20574
- /** Whether `limit` truncated the repo list. */
20575
- hasMore: external_exports.boolean()
20649
+ // Counts in FINDINGS, where the types response counts types, each dimension
20650
+ // still excluding its own filter. Deliberately not locations: counting those
20651
+ // needs a set of location keys per dimension per value — memory tracking the
20652
+ // store times the vocabulary, in a read whose scan promises flat memory —
20653
+ // and the cheap per-location version is not an approximation but WRONG. A
20654
+ // location holding {claudecode, block} and {codex, warn} would survive
20655
+ // provider=claudecode AND action=warn, under which no single finding
20656
+ // matches, so the facet would contradict the instanceCount this whole view
20657
+ // rests on. Findings also keep the toolbar in the same unit as the page
20658
+ // tally and the panel it sits above.
20659
+ facets: FindingFacets,
20660
+ /** Sorted by max severity, then most recent, then (repo, file). */
20661
+ items: external_exports.array(FindingLocationSummary),
20662
+ nextCursor: external_exports.string().nullable()
20576
20663
  }).meta({ id: "ListFindingLocationsResponse" });
20577
20664
 
20578
20665
  // ../../packages/schema/src/zod/meta.ts
@@ -20736,6 +20823,10 @@ var CaptureAttributes = external_exports.object({
20736
20823
  // to 'allow' — the enforcement audit trail's link back to the grant that
20737
20824
  // authorized the bypass.
20738
20825
  exception_ids: external_exports.array(external_exports.guid()).optional(),
20826
+ // The persisted spellings of EventMetadata's messageId/conversationId — the
20827
+ // join back to the `llm_call` leaf for the same assistant turn.
20828
+ message_id: external_exports.string().optional(),
20829
+ conversation_id: external_exports.string().optional(),
20739
20830
  // Whole milliseconds this capture's inspection blocked its caller — the
20740
20831
  // plugin's own added latency (see EventMetadata.inspectionMs, whose value
20741
20832
  // this is). Promoted to the `inspection_ms` generated column so the facet is
@@ -20744,7 +20835,19 @@ var CaptureAttributes = external_exports.object({
20744
20835
  // inline json_extract and is not itself an optimization.
20745
20836
  // ABSENT on replayed captures (backfill / worktree scan) and on rows written
20746
20837
  // before the measurement shipped — never present as a placeholder 0.
20747
- inspection_ms: external_exports.number().int().nonnegative().optional()
20838
+ inspection_ms: external_exports.number().int().nonnegative().optional(),
20839
+ // What a `redact` this capture could not carry out became instead (see
20840
+ // EventMetadata.redactDegradedTo, whose value this is). Present only when a
20841
+ // degrade actually happened, so absence is the ordinary case rather than a
20842
+ // reader having to distinguish it from a zero.
20843
+ //
20844
+ // PER CAPTURE, while `inspection_findings.action_taken` is per finding —
20845
+ // so on a multi-finding row this does not say which finding degraded, and
20846
+ // its presence does not mean the fallback decided the capture's action. A
20847
+ // capture denied by another finding's own Block policy carries `block`
20848
+ // here too. The full statement is on EventMetadata.redactDegradedTo; it is
20849
+ // repeated rather than referenced because a store reader opens this file.
20850
+ redact_degraded_to: ActionTaken.optional()
20748
20851
  }).catchall(external_exports.unknown());
20749
20852
  var ToolCallInspection = external_exports.object({
20750
20853
  ruleId: external_exports.string().min(1),
@@ -20940,7 +21043,17 @@ var AuditEvent = external_exports.object({
20940
21043
  /** `share` to a first-party/internal destination. */
20941
21044
  internal: external_exports.boolean(),
20942
21045
  /** Event needs review (e.g. unverified egress). */
20943
- flagged: external_exports.boolean()
21046
+ flagged: external_exports.boolean(),
21047
+ /**
21048
+ * The body this event's `title` is drawn from was cleared by local body
21049
+ * expiry, so an EMPTY title here means "gone", not "never had one".
21050
+ *
21051
+ * A separate flag rather than a sentinel written into `title`: the title is
21052
+ * rendered text, and a store-layer module that invented display copy for it
21053
+ * would be choosing words the view is supposed to choose. Additive and
21054
+ * defaulted, so an older producer still validates.
21055
+ */
21056
+ bodyExpired: external_exports.boolean().default(false)
20944
21057
  }).meta({ id: "ActivityAuditEvent" });
20945
21058
  var ActivitySessionSummary = external_exports.object({
20946
21059
  id: external_exports.string(),
@@ -21737,6 +21850,14 @@ var ControlPlaneErrorBody = external_exports.object({
21737
21850
  message: external_exports.string().optional()
21738
21851
  }).optional()
21739
21852
  });
21853
+ var RemoteFailureKind = external_exports.enum([
21854
+ "unauthorized",
21855
+ "forbidden",
21856
+ "route-absent",
21857
+ "invalid-request",
21858
+ "rejected",
21859
+ "unreachable"
21860
+ ]);
21740
21861
  var AttachDeviceRequest = external_exports.object({
21741
21862
  // This machine's own continuity id, so re-attaching ROTATES the credential
21742
21863
  // on one machine record instead of producing a second one. Client-minted
@@ -22155,6 +22276,12 @@ var EventMetadata = external_exports.object({
22155
22276
  // to 'allow' — the enforcement audit trail's link back to the grant that
22156
22277
  // authorized the bypass. Absent on captures where no exception applied.
22157
22278
  exceptionIds: external_exports.array(external_exports.guid()).optional(),
22279
+ // The assistant message this capture belongs to, and the conversation it sits
22280
+ // in — set by the browser extension's network capture so a stored `response`
22281
+ // row can be joined to the `llm_call` leaf describing the same turn. Absent
22282
+ // on every other capture path, which has no such id.
22283
+ messageId: external_exports.string().optional(),
22284
+ conversationId: external_exports.string().optional(),
22158
22285
  // How long THIS capture's inspection blocked its caller, in whole
22159
22286
  // milliseconds — the plugin's own added latency, NOT the LLM call it sat in
22160
22287
  // front of. Measured inside `capture()` (@akasecurity/plugin-sdk) across
@@ -22167,7 +22294,37 @@ var EventMetadata = external_exports.object({
22167
22294
  // Absent is also what every pre-measurement client writes, and what a
22168
22295
  // clock failure degrades to — a reader must treat absence as "not measured"
22169
22296
  // and never as a zero, which would read as "inspection is free".
22170
- inspectionMs: external_exports.number().int().nonnegative().optional()
22297
+ inspectionMs: external_exports.number().int().nonnegative().optional(),
22298
+ // What a `redact` this capture COULD NOT CARRY OUT became instead — the
22299
+ // workspace's `redactFallback`, applied because the field could not be
22300
+ // masked in place (a shell command, a URL, or any argument on a host whose
22301
+ // hook contract offers no rewrite channel).
22302
+ //
22303
+ // It exists because the action alone cannot say why. A finding recorded as
22304
+ // `warn` reads identically whether its detection was ASSIGNED Warn or was
22305
+ // assigned Redact on a field that could not take one — and those are
22306
+ // different facts about the same row: the first is a policy the user chose,
22307
+ // the second is a masking the host could not perform. Absent means no
22308
+ // degrade happened, which is every ordinary capture.
22309
+ //
22310
+ // TWO LIMITS a reader of a stored row has to know, because the grain here
22311
+ // is the CAPTURE while `actionTaken` is per FINDING:
22312
+ //
22313
+ // - It does not say WHICH finding degraded. A capture carrying a degraded
22314
+ // `redact` alongside a finding ASSIGNED the same action stores both
22315
+ // identically and one reason for the pair; attributing it to both
22316
+ // describes the assigned one wrongly, and to neither loses the degrade.
22317
+ // - PRESENCE IS NOT CAUSATION. The value is the action the lost redact
22318
+ // became, not the reason the capture ended as it did — a capture denied
22319
+ // by some other finding's own Block policy still carries `block` here,
22320
+ // and clearing the workspace's fallback would not have let it through.
22321
+ // Gate on the value against what a fallback can produce; never read the
22322
+ // field's presence as "this was the fallback's doing".
22323
+ //
22324
+ // Both are pinned as behaviour in @akasecurity/plugin-sdk's runtime suite.
22325
+ // Closing either means moving the reason onto the finding row, which
22326
+ // already carries its own action.
22327
+ redactDegradedTo: ActionTaken.optional()
22171
22328
  }).meta({ id: "EventMetadata" });
22172
22329
  var Event = external_exports.object({
22173
22330
  id: external_exports.guid(),
@@ -22277,6 +22434,15 @@ var RotateKeyInput = external_exports.object({
22277
22434
  confirmation: external_exports.string()
22278
22435
  });
22279
22436
 
22437
+ // ../../packages/schema/src/zod/finding-delivery.ts
22438
+ var KNOWN_REASONS = SyncFailureReason.options;
22439
+
22440
+ // ../../packages/schema/src/zod/findings-group-build.ts
22441
+ function rankByOrder(members2) {
22442
+ return Object.fromEntries(members2.map((member, index) => [member, index]));
22443
+ }
22444
+ var SEVERITY_RANK = rankByOrder(Severity.options);
22445
+
22280
22446
  // ../../packages/schema/src/zod/installed-pack.ts
22281
22447
  var InstalledPack = external_exports.object({
22282
22448
  id: external_exports.guid(),
@@ -22343,6 +22509,11 @@ var Policy = external_exports.object({
22343
22509
  // test `prohibitedModels` passes and `reversibleRuleIds` fails.
22344
22510
  provenance: PolicyProvenance.optional()
22345
22511
  }).meta({ id: "Policy" });
22512
+ var KNOWN_BUILTIN_IDS = ["monitor", "warn", "redact", "vault", "block"];
22513
+ var BuiltinPolicyId = external_exports.enum(KNOWN_BUILTIN_IDS).meta({ id: "BuiltinPolicyId" });
22514
+ var RedactFallback = BuiltinPolicyId.extract(["monitor", "warn", "block"]).meta({
22515
+ id: "RedactFallback"
22516
+ });
22346
22517
  var PolicyBundle = external_exports.object({
22347
22518
  version: external_exports.string(),
22348
22519
  policies: external_exports.array(Policy),
@@ -22390,6 +22561,16 @@ var PolicyBundle = external_exports.object({
22390
22561
  // control plane), so no name resolution stands between the decision and the
22391
22562
  // comparison.
22392
22563
  prohibitedModels: external_exports.array(external_exports.string()).optional(),
22564
+ // What a resolved `redact` becomes on a field the host cannot rewrite, as
22565
+ // the ORGANIZATION would have it. Merged raise-only against the device's own
22566
+ // `WorkspaceSettings.redactFallback` (see strongerRedactFallback below), so
22567
+ // a control plane can tighten a machine and never loosen one — the same
22568
+ // direction `mergeRaiseOnly` enforces for policies.
22569
+ //
22570
+ // Optional so an older backend, and an older on-disk cache, still parses;
22571
+ // absent leaves the device's own setting in force, which is the behaviour
22572
+ // that predates the field and the safe direction to default.
22573
+ redactFallback: RedactFallback.optional(),
22393
22574
  customKeywords: external_exports.array(external_exports.string()),
22394
22575
  fetchedAt: external_exports.iso.datetime()
22395
22576
  }).meta({ id: "PolicyBundle" });
@@ -22419,11 +22600,6 @@ function severityFloorPolicy(category) {
22419
22600
  const peak = CATEGORY_PEAK_SEVERITY[category];
22420
22601
  return peak === "critical" || peak === "high" ? "warn" : "monitor";
22421
22602
  }
22422
- var KNOWN_BUILTIN_IDS = ["monitor", "warn", "redact", "vault", "block"];
22423
- var BuiltinPolicyId = external_exports.enum(KNOWN_BUILTIN_IDS).meta({ id: "BuiltinPolicyId" });
22424
- var RedactFallback = BuiltinPolicyId.extract(["monitor", "warn", "block"]).meta({
22425
- id: "RedactFallback"
22426
- });
22427
22603
  var BUILTIN_POLICY_SPECS = {
22428
22604
  monitor: {
22429
22605
  name: "Monitor",
@@ -22686,7 +22862,7 @@ var VaultConsent = external_exports.object({
22686
22862
  });
22687
22863
 
22688
22864
  // ../../packages/schema/src/zod/local.ts
22689
- var WORKSPACE_SETTINGS_SPEC_VERSION = 7;
22865
+ var WORKSPACE_SETTINGS_SPEC_VERSION = 8;
22690
22866
  var MODEL_JUDGE_PAYLOAD_VERSION = 1;
22691
22867
  var RunMode = external_exports.enum(["standalone", "attached"]);
22692
22868
  var ControlPlaneConnection = external_exports.object({
@@ -22706,6 +22882,15 @@ var HistorySyncConsent = external_exports.object({
22706
22882
  payloadVersion: external_exports.number().int().positive(),
22707
22883
  endpoint: external_exports.string()
22708
22884
  });
22885
+ var BODY_RETENTION_DEFAULT_DAYS = 30;
22886
+ var BodyRetention = external_exports.object({
22887
+ enabled: external_exports.boolean().default(false),
22888
+ // Never 0, and the ceiling is a fat-finger guard rather than a policy
22889
+ // limit — `enabled` is the real gate. A low value cannot reach a row the
22890
+ // sync ledger still owes: the sweep's age filter only ever NARROWS a
22891
+ // candidate set that is already bounded by "delivered, or never owed".
22892
+ retainDays: external_exports.number().int().min(1).max(3650).default(BODY_RETENTION_DEFAULT_DAYS)
22893
+ }).meta({ id: "BodyRetention" });
22709
22894
  var WorkspaceSettings = external_exports.object({
22710
22895
  specVersion: external_exports.number().int().positive().default(WORKSPACE_SETTINGS_SPEC_VERSION),
22711
22896
  runMode: RunMode.default("standalone"),
@@ -22749,12 +22934,18 @@ var WorkspaceSettings = external_exports.object({
22749
22934
  // covers the current payload and must be re-granted.
22750
22935
  modelJudgeConsent: ModelJudgeConsent.optional(),
22751
22936
  // Records that the user consented to the DEFERRED send — the outbox — along
22752
- // with the payload shape and the endpoint they agreed to. Since payload v2
22753
- // that covers both the pre-attach backlog and undelivered captures (which
22754
- // carry prompt/reply text in `content`); the key name predates the widening.
22755
- // Absent until granted, and a grant for a different endpoint or an older
22756
- // payload no longer counts.
22757
- historySyncConsent: HistorySyncConsent.optional()
22937
+ // with the payload shape and the endpoint they agreed to. Since payload v3
22938
+ // that covers the pre-attach backlog AND undelivered captures alike, and both
22939
+ // carry prompt/reply/tool-output text in `content`; the key name predates
22940
+ // both widenings. Absent until granted, and a grant for a different endpoint
22941
+ // or an older payload no longer counts.
22942
+ historySyncConsent: HistorySyncConsent.optional(),
22943
+ // Local body expiry (see BodyRetention). Off until switched on; expiring a
22944
+ // body never removes the row or its findings.
22945
+ bodyRetention: BodyRetention.default({
22946
+ enabled: false,
22947
+ retainDays: BODY_RETENTION_DEFAULT_DAYS
22948
+ })
22758
22949
  });
22759
22950
  function defaultWorkspaceSettings() {
22760
22951
  return WorkspaceSettings.parse({});
@@ -22771,10 +22962,22 @@ var ManagedSettingKey = external_exports.enum([
22771
22962
  "vaultInlineReveal",
22772
22963
  "modelJudgeConsent",
22773
22964
  "dataSharesInPlace",
22774
- "redactFallback"
22965
+ "redactFallback",
22966
+ // Pins the toggle and the day count together — see BodyRetention on why the
22967
+ // two are one unit. An administrator mandating a window wants the count
22968
+ // enforced with it, not one a user can widen while the toggle stays on.
22969
+ "bodyRetention"
22775
22970
  ]).meta({ id: "ManagedSettingKey" });
22971
+ function isManagedSettingKey(value) {
22972
+ return ManagedSettingKey.safeParse(value).success;
22973
+ }
22776
22974
  var ManagedSettingsValues = external_exports.object({
22777
22975
  runMode: external_exports.enum(["standalone", "attached"]).optional(),
22976
+ // `controlPlane` and `bodyRetention` are the two nested values, and both are
22977
+ // plain, non-strict objects: a key under either that this build does not know
22978
+ // is stripped and nothing reports it. The unknown-value split in
22979
+ // ManagedSettings below classifies top-level names only, so it stops at
22980
+ // these boundaries.
22778
22981
  controlPlane: external_exports.object({
22779
22982
  endpoint: external_exports.string().min(1),
22780
22983
  label: external_exports.string().min(1).optional()
@@ -22785,7 +22988,8 @@ var ManagedSettingsValues = external_exports.object({
22785
22988
  vaultInlineReveal: external_exports.enum(["masked", "full", "off"]).optional(),
22786
22989
  modelJudgeConsent: external_exports.boolean().optional(),
22787
22990
  dataSharesInPlace: external_exports.boolean().optional(),
22788
- redactFallback: RedactFallback.optional()
22991
+ redactFallback: RedactFallback.optional(),
22992
+ bodyRetention: BodyRetention.optional()
22789
22993
  }).meta({ id: "ManagedSettingsValues" });
22790
22994
  var ManagedSettings = external_exports.object({
22791
22995
  specVersion: external_exports.number().int().positive().default(MANAGED_SETTINGS_SPEC_VERSION),
@@ -22793,11 +22997,59 @@ var ManagedSettings = external_exports.object({
22793
22997
  // decision from a bug. Absent renders as a generic "your organization".
22794
22998
  organization: external_exports.string().min(1).optional(),
22795
22999
  // What the administrator pinned.
22796
- values: ManagedSettingsValues.default({}),
23000
+ //
23001
+ // Parsed as a RECORD rather than as the nested schema, and split below for
23002
+ // the same reason `lockedFields` is parsed as names: a plain `z.object`
23003
+ // drops an unrecognised key and succeeds, so a pin this build does not know
23004
+ // vanished and nothing anywhere said so. A pin with no lock is a supported
23005
+ // shape — it is a DEFAULT the user may still change — so that silence hit
23006
+ // exactly the file an administrator is most likely to write while a fleet
23007
+ // is mid-upgrade.
23008
+ //
23009
+ // Splitting here rather than calling `.strict()`: strict would REFUSE the
23010
+ // file, which is the outcome the lock half already rejected — an older
23011
+ // build then runs entirely unmanaged, every pin and lock gone. A bad KNOWN
23012
+ // value still fails, because the nested schema is re-run over the known
23013
+ // subset and its issues are re-raised on this parse.
23014
+ values: external_exports.record(external_exports.string(), external_exports.unknown()).default({}),
22797
23015
  // Which of those the user may not change. A key here with no matching value
22798
23016
  // freezes whatever the user last chose; a value with no lock is a DEFAULT
22799
23017
  // the user may still override. The two are separable on purpose.
22800
- lockedFields: external_exports.array(ManagedSettingKey).default([])
23018
+ //
23019
+ // Parsed as NAMES rather than as the enum, and split below: a name this
23020
+ // build does not know is dropped from the locked set and reported, never a
23021
+ // reason to refuse the file. The same shape reaches an older build whenever
23022
+ // an administrator locks a key a newer build added, and refusing it there
23023
+ // ran that build entirely unmanaged — every pin and lock gone — on exactly
23024
+ // the fleets most likely to carry a version skew. A name outside the enum
23025
+ // is still never HONOURED: the lockable set stays explicit above.
23026
+ lockedFields: external_exports.array(external_exports.string()).default([])
23027
+ }).transform(({ lockedFields, values, ...rest }, ctx) => {
23028
+ const known = [];
23029
+ const unknown2 = [];
23030
+ for (const name of lockedFields) {
23031
+ if (isManagedSettingKey(name)) known.push(name);
23032
+ else unknown2.push(name);
23033
+ }
23034
+ const knownValues = /* @__PURE__ */ Object.create(null);
23035
+ const unknownValues = [];
23036
+ for (const [name, value] of Object.entries(values)) {
23037
+ if (Object.hasOwn(ManagedSettingsValues.shape, name)) knownValues[name] = value;
23038
+ else unknownValues.push(name);
23039
+ }
23040
+ const pinned = ManagedSettingsValues.safeParse(knownValues);
23041
+ if (!pinned.success) {
23042
+ for (const issue2 of pinned.error.issues)
23043
+ ctx.addIssue({ ...issue2, path: ["values", ...issue2.path] });
23044
+ return external_exports.NEVER;
23045
+ }
23046
+ return {
23047
+ ...rest,
23048
+ values: pinned.data,
23049
+ lockedFields: known,
23050
+ ...unknown2.length > 0 ? { unknownLockedFields: unknown2 } : {},
23051
+ ...unknownValues.length > 0 ? { unknownValueFields: unknownValues } : {}
23052
+ };
22801
23053
  }).meta({ id: "ManagedSettings" });
22802
23054
 
22803
23055
  // ../../packages/schema/src/zod/project-files.ts
@@ -22915,7 +23167,11 @@ var FindingsTimeseriesPoint = external_exports.object({
22915
23167
  timestamp: external_exports.iso.date(),
22916
23168
  critical: external_exports.number().int().nonnegative(),
22917
23169
  high: external_exports.number().int().nonnegative(),
22918
- medium: external_exports.number().int().nonnegative()
23170
+ medium: external_exports.number().int().nonnegative(),
23171
+ // Optional and additive, so a producer written against the earlier
23172
+ // three-series contract keeps validating. A consumer plotting it resolves the
23173
+ // absent case itself — the chart point requires a number.
23174
+ low: external_exports.number().int().nonnegative().optional()
22919
23175
  }).meta({ id: "FindingsTimeseriesPoint" });
22920
23176
  var FindingsTimeseriesResponse = external_exports.object({
22921
23177
  range: TimeRange,
@@ -22941,6 +23197,10 @@ var ResolvedFeedItem = external_exports.object({
22941
23197
  findingKey: external_exports.string(),
22942
23198
  ruleId: external_exports.string(),
22943
23199
  severity: Severity,
23200
+ // Repository slug, and the file path RELATIVE to it. The pair is what
23201
+ // identifies the file: a bare path matches the same name in every repo.
23202
+ // Optional and additive; empty when the event carried no repo.
23203
+ repo: external_exports.string().optional(),
22944
23204
  path: external_exports.string(),
22945
23205
  // ISO-8601 datetime (matches FindingInstance.detectedAt / the rest of the
22946
23206
  // findings domain). The reader `.toISOString()`s the DB epoch-ms values.
@@ -23046,7 +23306,23 @@ var SaveSettingsInput = external_exports.object({
23046
23306
  modelJudgeConsent: ModelJudgeConsentChoice,
23047
23307
  historySyncConsent: HistorySyncConsentChoice,
23048
23308
  vaultConsent: external_exports.string(),
23049
- vaultInlineReveal: external_exports.string()
23309
+ vaultInlineReveal: external_exports.string(),
23310
+ // Widened to `string` like its neighbours rather than typed as
23311
+ // `RedactFallback`, on this module's own layering rule: shape here, VALUE at
23312
+ // the call site, so the domain check receives the type it was written for.
23313
+ //
23314
+ // NOT because a narrower schema would reject differently. `parseActionInput`
23315
+ // is a `safeParse` wrapper and throws for no field schema, so either spelling
23316
+ // reaches a recoverable `{ ok: false }` and there is no rejected promise to
23317
+ // trade against. The real cost runs the other way and is the part worth
23318
+ // knowing: a value this schema admits and the domain enum then rejects lands
23319
+ // on the action's shared refusal, which names NO field, where a shape
23320
+ // rejection reaches `malformedInput` and names the schema key.
23321
+ redactFallback: external_exports.string(),
23322
+ // Shape only, the way the enum fields above are strings only: the RANGE is
23323
+ // `BodyRetention`'s and the action checks it there, so there is one place
23324
+ // that decides what a legal horizon is rather than two that can drift.
23325
+ bodyRetention: external_exports.object({ enabled: external_exports.boolean(), retainDays: external_exports.number() })
23050
23326
  });
23051
23327
  var AttachInput = external_exports.object({
23052
23328
  endpoint: external_exports.string(),
@@ -23172,6 +23448,52 @@ var SetupHandoffOffer = external_exports.object({
23172
23448
  path: ["liveKeys"]
23173
23449
  });
23174
23450
 
23451
+ // ../../packages/schema/src/zod/web-capture.ts
23452
+ var WebUsageSource = external_exports.enum(["site", "estimated", "none"]);
23453
+ var WebUsage = external_exports.object({
23454
+ inputTokens: external_exports.number().int().nonnegative().optional(),
23455
+ outputTokens: external_exports.number().int().nonnegative().optional(),
23456
+ cacheReadInputTokens: external_exports.number().int().nonnegative().optional(),
23457
+ cacheCreationInputTokens: external_exports.number().int().nonnegative().optional()
23458
+ });
23459
+ var WebToolCall = external_exports.object({
23460
+ toolUseId: external_exports.string().min(1),
23461
+ toolName: external_exports.string().min(1),
23462
+ target: external_exports.string().optional(),
23463
+ isError: external_exports.boolean().optional(),
23464
+ inputSize: external_exports.number().int().nonnegative().optional(),
23465
+ outputSize: external_exports.number().int().nonnegative().optional()
23466
+ });
23467
+ var WebExchange = external_exports.object({
23468
+ messageId: external_exports.string().min(1),
23469
+ startedAt: external_exports.iso.datetime(),
23470
+ model: external_exports.string().optional(),
23471
+ usage: WebUsage.optional(),
23472
+ usageSource: WebUsageSource,
23473
+ stopReason: external_exports.string().optional(),
23474
+ conversationId: external_exports.string().optional(),
23475
+ turnIndex: external_exports.number().int().nonnegative().optional(),
23476
+ toolCalls: external_exports.array(WebToolCall).default([]),
23477
+ // Absent when the adapter recovered no text. Capped by the caller at
23478
+ // RESPONSE_TEXT_MAX_BYTES; `truncated` records that the cap was reached, so a
23479
+ // short capture is never mistaken for a short reply.
23480
+ responseText: external_exports.string().optional(),
23481
+ truncated: external_exports.boolean().default(false)
23482
+ });
23483
+ var RESPONSE_TEXT_MAX_BYTES = 2 * 1024 * 1024;
23484
+ var WebCaptureStatus = external_exports.object({
23485
+ patched: external_exports.boolean(),
23486
+ live: external_exports.boolean(),
23487
+ blind: external_exports.boolean(),
23488
+ sendsSeenDom: external_exports.number().int().nonnegative(),
23489
+ exchangesSeenNet: external_exports.number().int().nonnegative(),
23490
+ parseFailures: external_exports.number().int().nonnegative(),
23491
+ unparsedBodies: external_exports.number().int().nonnegative(),
23492
+ // The adapter-declared JSON key paths that were absent from a real payload —
23493
+ // the earliest signal that a site's contract moved.
23494
+ shapeMisses: external_exports.array(external_exports.string()).default([])
23495
+ });
23496
+
23175
23497
  // ../../packages/persistence/src/paths.ts
23176
23498
  import {
23177
23499
  chmodSync,
@@ -23212,6 +23534,26 @@ function ensureDataDirSync(dir) {
23212
23534
  function tightenFile(file2) {
23213
23535
  chmodBestEffort(file2, DATA_FILE_MODE);
23214
23536
  }
23537
+ function writeExclusiveOwnerOnlySync(file2, data) {
23538
+ writeFileSync(file2, data, { mode: DATA_FILE_MODE, flag: "wx" });
23539
+ }
23540
+ function writeOwnerOnlyFileSync(file2, data) {
23541
+ const tmp = `${file2}.${String(process.pid)}.tmp`;
23542
+ try {
23543
+ rmSync2(tmp, { force: true });
23544
+ } catch {
23545
+ }
23546
+ try {
23547
+ writeExclusiveOwnerOnlySync(tmp, data);
23548
+ renameSync(tmp, file2);
23549
+ } finally {
23550
+ try {
23551
+ rmSync2(tmp, { force: true });
23552
+ } catch {
23553
+ }
23554
+ }
23555
+ tightenFile(file2);
23556
+ }
23215
23557
 
23216
23558
  // ../../packages/persistence/src/database.ts
23217
23559
  import { randomUUID as randomUUID11 } from "crypto";
@@ -23229,6 +23571,32 @@ var STALE_PARTIAL_MS = 5 * 6e4;
23229
23571
  var SNAPSHOT_STAGING_SUFFIX = ".partial";
23230
23572
  var STAGED_NAME_SUFFIX = `.bak${SNAPSHOT_STAGING_SUFFIX}`;
23231
23573
 
23574
+ // ../../packages/persistence/src/internal/sql-functions.ts
23575
+ var utf8 = new TextDecoder();
23576
+
23577
+ // ../../packages/persistence/src/internal/outbox-lane.ts
23578
+ var OUTBOX_CAPTURE_EVENT_TYPES = ["prompt", "response", "tool_use"];
23579
+ var OUTBOX_CAPTURE_TYPE_LIST = OUTBOX_CAPTURE_EVENT_TYPES.map((t) => `'${t}'`).join(", ");
23580
+
23581
+ // ../../packages/persistence/src/sync-failure.ts
23582
+ var SYNC_FAILURE_REASONS = SyncFailureReason.options;
23583
+
23584
+ // ../../packages/persistence/src/repositories/history-sync.ts
23585
+ var STRUCTURAL_EVENT_TYPES = ["session", "llm_call", "tool_call"];
23586
+ var TYPE_LIST = STRUCTURAL_EVENT_TYPES.map((t) => `'${t}'`).join(", ");
23587
+ var COUNTED_EVENT_TYPES = [
23588
+ ...STRUCTURAL_EVENT_TYPES,
23589
+ ...OUTBOX_CAPTURE_EVENT_TYPES
23590
+ ];
23591
+ var COUNTED_TYPE_LIST = COUNTED_EVENT_TYPES.map((t) => `'${t}'`).join(", ");
23592
+ var COUNTED_SCOPE = `
23593
+ WHERE event_type IN (${COUNTED_TYPE_LIST})
23594
+ AND (
23595
+ event_type IN (${TYPE_LIST})
23596
+ OR synced_at IS NOT NULL
23597
+ OR outbox_owed = 1
23598
+ )`;
23599
+
23232
23600
  // ../../packages/persistence/src/internal/json.ts
23233
23601
  function parseJsonObject(s) {
23234
23602
  if (s == null) return void 0;
@@ -23269,11 +23637,34 @@ var ACTIVE_REVEAL_GRANT_PREDICATE = `capability = 'reveal_to_model'
23269
23637
  AND conditions IS NULL
23270
23638
  AND ${ACTIVE_PREDICATE}`;
23271
23639
 
23272
- // ../../packages/persistence/src/repositories/history-sync.ts
23273
- var STRUCTURAL_EVENT_TYPES = ["session", "llm_call", "tool_call"];
23274
- var TYPE_LIST = STRUCTURAL_EVENT_TYPES.map((t) => `'${t}'`).join(", ");
23275
- var OUTBOX_CAPTURE_EVENT_TYPES = ["prompt", "response", "tool_use"];
23276
- var CAPTURE_TYPE_LIST = OUTBOX_CAPTURE_EVENT_TYPES.map((t) => `'${t}'`).join(", ");
23640
+ // ../../packages/persistence/src/repositories/resolution-sql.ts
23641
+ function latestResolutionColumnSql(column, findingsAlias) {
23642
+ return `(
23643
+ SELECT fr.${column} FROM finding_resolution fr
23644
+ WHERE fr.finding_key = ${findingsAlias}.finding_key
23645
+ ORDER BY fr.created_at DESC, fr.rowid DESC
23646
+ LIMIT 1
23647
+ )`;
23648
+ }
23649
+ function latestResolutionStatusSql(findingsAlias) {
23650
+ return latestResolutionColumnSql("status", findingsAlias);
23651
+ }
23652
+
23653
+ // ../../packages/persistence/src/repositories/findings.ts
23654
+ var FINDING_ROW_COLUMNS_SQL = `f.id AS id, d.rule_id AS rule_id, d.category AS category,
23655
+ d.severity AS severity, f.masked_match AS masked_match,
23656
+ f.action_taken AS action_taken, f.confidence AS confidence,
23657
+ e.started_at AS occurred_at,
23658
+ e.source_tool AS source_tool,
23659
+ e.repo AS repo,
23660
+ e.file_path AS file,
23661
+ e.tool_name AS tool_name,
23662
+ f.audit_event_id AS event_id, e.root_session_id AS session_id,
23663
+ e.event_type AS kind, f.finding_key AS finding_key,
23664
+ ${latestResolutionStatusSql("f")} AS latest_status,
23665
+ e.synced_at AS synced_at, e.sync_claimed_at AS sync_claimed_at,
23666
+ e.sync_failed_at AS sync_failed_at, e.sync_failure AS sync_failure,
23667
+ e.outbox_owed AS outbox_owed`;
23277
23668
 
23278
23669
  // ../../packages/persistence/src/repositories/installed-packs.ts
23279
23670
  import { createHash as createHash2, randomUUID as randomUUID4 } from "crypto";
@@ -23354,7 +23745,8 @@ function managedSettingsPaths(platform2 = process.platform) {
23354
23745
  }
23355
23746
  return [posix.join("/etc", "aka", MANAGED_SETTINGS_FILENAME)];
23356
23747
  }
23357
- function readManagedSettings(paths = managedSettingsPaths()) {
23748
+ var testOnlyManagedPaths = null;
23749
+ function readManagedSettings(paths = testOnlyManagedPaths ?? managedSettingsPaths()) {
23358
23750
  for (const path of paths) {
23359
23751
  let text;
23360
23752
  try {
@@ -23389,6 +23781,7 @@ function overlayManagedSettings(settings, managed, now = () => /* @__PURE__ */ n
23389
23781
  if (values.vaultInlineReveal !== void 0) merged.vaultInlineReveal = values.vaultInlineReveal;
23390
23782
  if (values.dataSharesInPlace !== void 0) merged.dataSharesInPlace = values.dataSharesInPlace;
23391
23783
  if (values.redactFallback !== void 0) merged.redactFallback = values.redactFallback;
23784
+ if (values.bodyRetention !== void 0) merged.bodyRetention = values.bodyRetention;
23392
23785
  if (values.vaultConsent !== void 0) {
23393
23786
  merged.vaultConsent = values.vaultConsent ? (
23394
23787
  // Keep an existing valid grant so its acknowledgedAt survives; mint one
@@ -23429,6 +23822,48 @@ function readJson(file2) {
23429
23822
  return parseJsonObject(text) ?? null;
23430
23823
  }
23431
23824
 
23825
+ // ../../packages/persistence/src/semver.ts
23826
+ function parse3(version2) {
23827
+ const match = /^(\d+)\.(\d+)\.(\d+)(?:-([0-9A-Za-z-.]+))?$/.exec(version2.trim());
23828
+ if (!match) return null;
23829
+ return {
23830
+ core: [Number(match[1]), Number(match[2]), Number(match[3])],
23831
+ pre: match[4] ? match[4].split(".") : []
23832
+ };
23833
+ }
23834
+ function comparePre(a, b) {
23835
+ if (a.length === 0 && b.length === 0) return 0;
23836
+ if (a.length === 0) return 1;
23837
+ if (b.length === 0) return -1;
23838
+ const len = Math.min(a.length, b.length);
23839
+ for (let i = 0; i < len; i++) {
23840
+ const ai = a[i] ?? "";
23841
+ const bi = b[i] ?? "";
23842
+ if (ai === bi) continue;
23843
+ const an = /^\d+$/.test(ai);
23844
+ const bn = /^\d+$/.test(bi);
23845
+ if (an && !bn) return -1;
23846
+ if (!an && bn) return 1;
23847
+ if (an && bn) return Number(ai) < Number(bi) ? -1 : 1;
23848
+ return ai < bi ? -1 : 1;
23849
+ }
23850
+ return a.length === b.length ? 0 : a.length < b.length ? -1 : 1;
23851
+ }
23852
+ function compareBinaryVersions(a, b) {
23853
+ const pa = parse3(a);
23854
+ const pb = parse3(b);
23855
+ if (!pa || !pb) return 0;
23856
+ for (let i = 0; i < 3; i++) {
23857
+ const av = pa.core[i] ?? 0;
23858
+ const bv = pb.core[i] ?? 0;
23859
+ if (av !== bv) return av < bv ? -1 : 1;
23860
+ }
23861
+ return comparePre(pa.pre, pb.pre);
23862
+ }
23863
+ function isParseableBinaryVersion(version2) {
23864
+ return parse3(version2) !== null;
23865
+ }
23866
+
23432
23867
  // ../../packages/persistence/src/repositories/inventory-assets.ts
23433
23868
  import { randomUUID as randomUUID5 } from "crypto";
23434
23869
  var VALID_HARNESS_IDS = new Set(HarnessId.options);
@@ -23476,9 +23911,14 @@ import { randomUUID as randomUUID10 } from "crypto";
23476
23911
 
23477
23912
  // ../../packages/persistence/src/database.ts
23478
23913
  var CAPTURE_GRAIN = new Set(EventKind.options);
23914
+ var DEFERRED_TAGS = new Set(DEFERRED_MIGRATION_TAGS);
23479
23915
 
23480
- // ../../packages/persistence/src/finding-key.ts
23916
+ // ../../packages/persistence/src/egress-wire.ts
23481
23917
  import { createHash as createHash3 } from "crypto";
23918
+ var SLASH = "/".charCodeAt(0);
23919
+
23920
+ // ../../packages/persistence/src/finding-key.ts
23921
+ import { createHash as createHash4 } from "crypto";
23482
23922
 
23483
23923
  // ../../packages/persistence/src/fingerprint.ts
23484
23924
  import { createHmac, randomBytes } from "crypto";
@@ -23486,14 +23926,26 @@ import { existsSync as existsSync3, readFileSync as readFileSync6 } from "fs";
23486
23926
  import { join as join8 } from "path";
23487
23927
  import { DatabaseSync as DatabaseSync2 } from "node:sqlite";
23488
23928
 
23489
- // ../../packages/persistence/src/history-preview.ts
23490
- import { existsSync as existsSync4 } from "fs";
23929
+ // ../../packages/persistence/src/forward-health.ts
23930
+ import { readFileSync as readFileSync7 } from "fs";
23491
23931
  import { join as join9 } from "path";
23932
+
23933
+ // ../../packages/persistence/src/history-backfill.ts
23934
+ import { existsSync as existsSync4 } from "fs";
23935
+ import { join as join10 } from "path";
23936
+
23937
+ // ../../packages/persistence/src/history-preview.ts
23938
+ import { existsSync as existsSync5 } from "fs";
23939
+ import { join as join11 } from "path";
23492
23940
  import { DatabaseSync as DatabaseSync3 } from "node:sqlite";
23493
23941
 
23942
+ // ../../packages/persistence/src/history-sync-state.ts
23943
+ import { readFileSync as readFileSync8 } from "fs";
23944
+ import { join as join12 } from "path";
23945
+
23494
23946
  // ../../packages/persistence/src/store-symlinks.ts
23495
- import { existsSync as existsSync5, lstatSync as lstatSync3, readlinkSync, realpathSync, statSync as statSync4 } from "fs";
23496
- import { dirname as dirname3, join as join10, resolve } from "path";
23947
+ import { existsSync as existsSync6, lstatSync as lstatSync3, readlinkSync, realpathSync, statSync as statSync4 } from "fs";
23948
+ import { dirname as dirname3, join as join13, resolve } from "path";
23497
23949
  var STORE_DB = "the store database (including the prompt corpus)";
23498
23950
  var STORE_SETTINGS = "your settings file";
23499
23951
  function storeContents(home) {
@@ -23502,7 +23954,7 @@ function storeContents(home) {
23502
23954
  [settingsDir(home), STORE_SETTINGS],
23503
23955
  [dataDir(home), STORE_DB],
23504
23956
  [keysDir(home), "the vault key"],
23505
- [join10(settingsDir(home), "settings.json"), STORE_SETTINGS],
23957
+ [join13(settingsDir(home), "settings.json"), STORE_SETTINGS],
23506
23958
  [dbPath(home), STORE_DB]
23507
23959
  ]);
23508
23960
  }
@@ -23517,7 +23969,7 @@ function symlinkedStorePaths(home, platform2 = process.platform) {
23517
23969
  holds,
23518
23970
  // existsSync follows the link, so a target that is gone reads as
23519
23971
  // absent here while lstat above still sees the link itself.
23520
- missing: !existsSync5(path),
23972
+ missing: !existsSync6(path),
23521
23973
  mode: targetMode(path, platform2)
23522
23974
  }
23523
23975
  ];
@@ -23554,15 +24006,15 @@ import {
23554
24006
  // ../../packages/persistence/src/vault/key-provider.ts
23555
24007
  import { execFileSync } from "child_process";
23556
24008
  import { randomBytes as randomBytes2 } from "crypto";
23557
- import { chmodSync as chmodSync3, readFileSync as readFileSync7, renameSync as renameSync4, rmSync as rmSync6, statSync as statSync5, writeFileSync as writeFileSync3 } from "fs";
23558
- import { join as join11 } from "path";
24009
+ import { chmodSync as chmodSync3, readFileSync as readFileSync9, renameSync as renameSync4, rmSync as rmSync6, statSync as statSync5, writeFileSync as writeFileSync3 } from "fs";
24010
+ import { join as join14 } from "path";
23559
24011
 
23560
24012
  // ../../packages/persistence/src/vault/vault.ts
23561
24013
  import { randomBytes as randomBytes3, randomUUID as randomUUID12 } from "crypto";
23562
24014
 
23563
24015
  // ../../packages/persistence/src/warn-era-cap.ts
23564
- import { existsSync as existsSync6, writeFileSync as writeFileSync4 } from "fs";
23565
- import { join as join12 } from "path";
24016
+ import { existsSync as existsSync7, writeFileSync as writeFileSync4 } from "fs";
24017
+ import { join as join15 } from "path";
23566
24018
 
23567
24019
  // ../../packages/plugin-sdk/src/provider-env.ts
23568
24020
  var DEFAULT_ANTHROPIC_HOST = "api.anthropic.com";
@@ -23616,8 +24068,8 @@ function resolveProvider() {
23616
24068
  function loadConfig(base = defaultDataDir(), resolveProviderFn = resolveProvider) {
23617
24069
  try {
23618
24070
  ensureLayoutDirSync(base);
23619
- const settingsFile = join13(settingsDir(base), "settings.json");
23620
- if (existsSync7(settingsFile)) tightenFile(settingsFile);
24071
+ const settingsFile = join16(settingsDir(base), "settings.json");
24072
+ if (existsSync8(settingsFile)) tightenFile(settingsFile);
23621
24073
  } catch {
23622
24074
  }
23623
24075
  migrateLegacyLayout(base);
@@ -23640,9 +24092,9 @@ function resolveProviderSafe(resolveProviderFn) {
23640
24092
  }
23641
24093
 
23642
24094
  // ../../packages/plugin-sdk/src/config-inventory.ts
23643
- import { readdirSync as readdirSync2, readFileSync as readFileSync9, realpathSync as realpathSync2, statSync as statSync7 } from "fs";
24095
+ import { readdirSync as readdirSync2, readFileSync as readFileSync11, realpathSync as realpathSync2, statSync as statSync7 } from "fs";
23644
24096
  import { homedir as homedir2 } from "os";
23645
- import { basename as basename3, join as join15 } from "path";
24097
+ import { basename as basename3, join as join18 } from "path";
23646
24098
 
23647
24099
  // ../../packages/detections/src/egress/registry.ts
23648
24100
  var EXTRACTOR_VERSION = "1";
@@ -24400,24 +24852,20 @@ var CPU_CORROBORATION_SHARE = 0.2;
24400
24852
  var CORROBORATION_FLOOR_MS = BUDGET_MS * CPU_CORROBORATION_SHARE;
24401
24853
 
24402
24854
  // ../../packages/plugin-sdk/src/repo.ts
24403
- import { existsSync as existsSync8, readFileSync as readFileSync8, statSync as statSync6 } from "fs";
24404
- import { basename as basename2, dirname as dirname4, isAbsolute, join as join14, sep as sep2 } from "path";
24855
+ import { existsSync as existsSync9, readFileSync as readFileSync10, statSync as statSync6 } from "fs";
24856
+ import { basename as basename2, dirname as dirname4, isAbsolute, join as join17, sep as sep2 } from "path";
24405
24857
 
24406
24858
  // ../../packages/plugin-sdk/src/events.ts
24407
- import { createHash as createHash4, randomUUID as randomUUID13 } from "crypto";
24859
+ import { createHash as createHash5, randomUUID as randomUUID13 } from "crypto";
24408
24860
 
24409
24861
  // ../../packages/plugin-sdk/src/isolated-scan.ts
24410
- import { existsSync as existsSync9 } from "fs";
24862
+ import { existsSync as existsSync10 } from "fs";
24411
24863
  import { fileURLToPath } from "url";
24412
24864
  import { Worker } from "worker_threads";
24413
24865
 
24414
- // ../../packages/plugin-sdk/src/ignore-layers.ts
24415
- var import_ignore = __toESM(require_ignore(), 1);
24416
- import { readFileSync as readFileSync10 } from "fs";
24417
- import { join as join16 } from "path";
24418
-
24419
- // ../../packages/plugin-sdk/src/inventory-resolver.ts
24420
- import { arch, hostname as hostname4, platform, release } from "os";
24866
+ // ../../packages/plugin-sdk/src/host-floor.ts
24867
+ import { readFileSync as readFileSync13 } from "fs";
24868
+ import { join as join20 } from "path";
24421
24869
 
24422
24870
  // ../../packages/plugin-sdk/src/model-governance.ts
24423
24871
  import {
@@ -24425,24 +24873,146 @@ import {
24425
24873
  fstatSync,
24426
24874
  mkdirSync as mkdirSync2,
24427
24875
  openSync as openSync2,
24428
- readFileSync as readFileSync11,
24876
+ readFileSync as readFileSync12,
24429
24877
  readSync,
24430
24878
  writeFileSync as writeFileSync5
24431
24879
  } from "fs";
24432
- import { join as join17 } from "path";
24880
+ import { join as join19 } from "path";
24433
24881
  var TAIL_BYTES = 256 * 1024;
24882
+ function readTail(path) {
24883
+ const fd = openSync2(path, "r");
24884
+ try {
24885
+ const { size } = fstatSync(fd);
24886
+ if (size <= TAIL_BYTES) return { text: readFileSync12(fd, "utf8"), truncated: false };
24887
+ const buffer = Buffer.allocUnsafe(TAIL_BYTES);
24888
+ let filled = 0;
24889
+ while (filled < TAIL_BYTES) {
24890
+ const n = readSync(fd, buffer, filled, TAIL_BYTES - filled, size - TAIL_BYTES + filled);
24891
+ if (n === 0) break;
24892
+ filled += n;
24893
+ }
24894
+ return { text: buffer.subarray(0, filled).toString("utf8"), truncated: true };
24895
+ } finally {
24896
+ closeSync2(fd);
24897
+ }
24898
+ }
24899
+ function modelFromTranscriptTail(transcriptPath, fromRecord) {
24900
+ if (transcriptPath === void 0 || transcriptPath === "") return void 0;
24901
+ try {
24902
+ const { text: slice, truncated } = readTail(transcriptPath);
24903
+ const lines = slice.split("\n");
24904
+ if (truncated) lines.shift();
24905
+ for (let i = lines.length - 1; i >= 0; i--) {
24906
+ const line = lines[i];
24907
+ if (line === void 0 || line === "") continue;
24908
+ let parsed;
24909
+ try {
24910
+ parsed = JSON.parse(line);
24911
+ } catch {
24912
+ continue;
24913
+ }
24914
+ const model = fromRecord(parsed);
24915
+ if (model !== void 0 && model !== "") return model;
24916
+ }
24917
+ return void 0;
24918
+ } catch {
24919
+ return void 0;
24920
+ }
24921
+ }
24922
+
24923
+ // ../../packages/plugin-sdk/src/host-floor.ts
24924
+ var HOST_FEATURE = {
24925
+ ModelSwitch: "model-switch",
24926
+ VaultPointerDisplay: "vault-pointer-display"
24927
+ };
24928
+ var HOST_FLOORS = {
24929
+ [HOST_FEATURE.ModelSwitch]: {
24930
+ label: "model-switch protection",
24931
+ hookEvents: ["PreModelSwitch", "PostModelSwitch"],
24932
+ since: "2.1.251"
24933
+ },
24934
+ [HOST_FEATURE.VaultPointerDisplay]: {
24935
+ label: "vault pointer display",
24936
+ hookEvents: ["MessageDisplay"],
24937
+ since: "2.1.152"
24938
+ }
24939
+ };
24940
+ var hostVersionFromRecord = (record2) => {
24941
+ if (typeof record2 !== "object" || record2 === null) return void 0;
24942
+ const { version: version2 } = record2;
24943
+ return typeof version2 === "string" && version2 !== "" ? version2 : void 0;
24944
+ };
24945
+ function hostVersionFromTranscript(transcriptPath) {
24946
+ return modelFromTranscriptTail(transcriptPath, hostVersionFromRecord);
24947
+ }
24948
+ function hostFloorGaps(hostVersion) {
24949
+ if (hostVersion === void 0) return [];
24950
+ const gaps = [];
24951
+ for (const [feature, row] of Object.entries(HOST_FLOORS)) {
24952
+ if (compareBinaryVersions(hostVersion, row.since) < 0) {
24953
+ gaps.push({ feature, label: row.label, since: row.since });
24954
+ }
24955
+ }
24956
+ return gaps;
24957
+ }
24958
+ function requiredHostVersion(gaps) {
24959
+ let highest;
24960
+ for (const gap of gaps) {
24961
+ if (highest === void 0 || compareBinaryVersions(gap.since, highest) > 0) highest = gap.since;
24962
+ }
24963
+ return highest;
24964
+ }
24965
+ function hostFloorNotice(hostVersion) {
24966
+ if (hostVersion === void 0) return null;
24967
+ const gaps = hostFloorGaps(hostVersion);
24968
+ const required2 = requiredHostVersion(gaps);
24969
+ if (required2 === void 0) return null;
24970
+ return `This Claude Code (${hostVersion}) is older than AKA needs \u2014 some of AKA's protections are inactive in this session. Update Claude Code to ${required2} or newer to turn them on. Everything else AKA does is working normally. Run \`aka status\` for detail.`;
24971
+ }
24972
+ var HOST_VERSION_MARKER = "host-version.json";
24973
+ function recordHostVersion(dataDir2, version2) {
24974
+ if (version2 === void 0 || !isParseableBinaryVersion(version2)) return;
24975
+ try {
24976
+ const current = readHostVersionCache(dataDir2);
24977
+ if (current !== null && compareBinaryVersions(version2, current.version) <= 0) return;
24978
+ const cache = { version: version2, observedAt: Date.now() };
24979
+ ensureDataDirSync(dataDir2);
24980
+ writeOwnerOnlyFileSync(join20(dataDir2, HOST_VERSION_MARKER), JSON.stringify(cache));
24981
+ } catch {
24982
+ }
24983
+ }
24984
+ function readHostVersionCache(dataDir2) {
24985
+ try {
24986
+ const parsed = JSON.parse(readFileSync13(join20(dataDir2, HOST_VERSION_MARKER), "utf8"));
24987
+ if (typeof parsed !== "object" || parsed === null) return null;
24988
+ const { version: version2, observedAt } = parsed;
24989
+ if (typeof version2 !== "string" || !isParseableBinaryVersion(version2)) return null;
24990
+ if (typeof observedAt !== "number" || !Number.isFinite(observedAt)) return null;
24991
+ return { version: version2, observedAt };
24992
+ } catch {
24993
+ return null;
24994
+ }
24995
+ }
24996
+
24997
+ // ../../packages/plugin-sdk/src/ignore-layers.ts
24998
+ var import_ignore = __toESM(require_ignore(), 1);
24999
+ import { readFileSync as readFileSync14 } from "fs";
25000
+ import { join as join21 } from "path";
25001
+
25002
+ // ../../packages/plugin-sdk/src/inventory-resolver.ts
25003
+ import { arch, hostname as hostname4, platform, release } from "os";
24434
25004
 
24435
25005
  // ../../packages/plugin-sdk/src/nudge.ts
24436
- import { mkdirSync as mkdirSync3, readFileSync as readFileSync12, writeFileSync as writeFileSync6 } from "fs";
24437
- import { join as join18 } from "path";
25006
+ import { mkdirSync as mkdirSync3, readFileSync as readFileSync15, writeFileSync as writeFileSync6 } from "fs";
25007
+ import { join as join22 } from "path";
24438
25008
 
24439
25009
  // ../../packages/plugin-sdk/src/paths.ts
24440
25010
  import { readdirSync as readdirSync3, realpathSync as realpathSync3 } from "fs";
24441
25011
  import { basename as basename4, dirname as dirname5, sep as sep3 } from "path";
24442
25012
 
24443
25013
  // ../../packages/plugin-sdk/src/project-files.ts
24444
- import { existsSync as existsSync10, readdirSync as readdirSync4 } from "fs";
24445
- import { basename as basename5, join as join19 } from "path";
25014
+ import { existsSync as existsSync11, readdirSync as readdirSync4 } from "fs";
25015
+ import { basename as basename5, join as join23 } from "path";
24446
25016
 
24447
25017
  // ../../packages/plugin-sdk/src/provider-env-antigravity.ts
24448
25018
  var optionalBaseUrl2 = external_exports.preprocess((v) => {
@@ -24478,9 +25048,9 @@ var THIRTY_DAYS_MS = 30 * 24 * 60 * 60 * 1e3;
24478
25048
 
24479
25049
  // ../../packages/plugin-sdk/src/throttle.ts
24480
25050
  import { mkdirSync as mkdirSync4, statSync as statSync8, writeFileSync as writeFileSync7 } from "fs";
24481
- import { join as join20 } from "path";
25051
+ import { join as join24 } from "path";
24482
25052
  function throttled(dataDir2, markerName, windowMs) {
24483
- const marker = join20(dataDir2, markerName);
25053
+ const marker = join24(dataDir2, markerName);
24484
25054
  try {
24485
25055
  if (Date.now() - statSync8(marker).mtimeMs < windowMs) return true;
24486
25056
  } catch {
@@ -24495,27 +25065,27 @@ function throttled(dataDir2, markerName, windowMs) {
24495
25065
 
24496
25066
  // src/history/reconcile-trigger.ts
24497
25067
  import { spawn } from "child_process";
24498
- import { dirname as dirname6, join as join22 } from "path";
25068
+ import { dirname as dirname6, join as join26 } from "path";
24499
25069
  import { fileURLToPath as fileURLToPath2 } from "url";
24500
25070
 
24501
25071
  // src/history/tail.ts
24502
- import { createHash as createHash5 } from "crypto";
25072
+ import { createHash as createHash6 } from "crypto";
24503
25073
  import {
24504
25074
  closeSync as closeSync3,
24505
25075
  fstatSync as fstatSync2,
24506
25076
  mkdirSync as mkdirSync5,
24507
25077
  openSync as openSync3,
24508
- readFileSync as readFileSync13,
25078
+ readFileSync as readFileSync16,
24509
25079
  readSync as readSync2,
24510
25080
  writeFileSync as writeFileSync8
24511
25081
  } from "fs";
24512
- import { join as join21 } from "path";
25082
+ import { join as join25 } from "path";
24513
25083
  var SAFE_SESSION_ID = /^[A-Za-z0-9._-]+$/;
24514
25084
  function safeSessionId(sessionId) {
24515
25085
  if (SAFE_SESSION_ID.test(sessionId) && sessionId !== "." && sessionId !== "..") {
24516
25086
  return sessionId;
24517
25087
  }
24518
- return createHash5("sha256").update(sessionId).digest("hex");
25088
+ return createHash6("sha256").update(sessionId).digest("hex");
24519
25089
  }
24520
25090
 
24521
25091
  // src/history/reconcile-trigger.ts
@@ -24526,7 +25096,7 @@ function triggerReconcile(dataDir2, sessionId, transcriptPath) {
24526
25096
  const marker = `${RECONCILE_MARKER_PREFIX}-${safeSessionId(sessionId)}`;
24527
25097
  if (throttled(dataDir2, marker, RECONCILE_THROTTLE_MS)) return;
24528
25098
  const here = dirname6(fileURLToPath2(import.meta.url));
24529
- const child = spawn(process.execPath, [join22(here, "reconcile.js"), sessionId, transcriptPath], {
25099
+ const child = spawn(process.execPath, [join26(here, "reconcile.js"), sessionId, transcriptPath], {
24530
25100
  detached: true,
24531
25101
  stdio: "ignore"
24532
25102
  });
@@ -24535,6 +25105,68 @@ function triggerReconcile(dataDir2, sessionId, transcriptPath) {
24535
25105
  }
24536
25106
  }
24537
25107
 
25108
+ // src/hooks/host-floor-notice.ts
25109
+ import { mkdirSync as mkdirSync6, readdirSync as readdirSync5, rmSync as rmSync7, statSync as statSync9, writeFileSync as writeFileSync9 } from "fs";
25110
+ import { join as join27 } from "path";
25111
+ var CLAIM_DIR = "host-floor-claims";
25112
+ var CLAIM_TTL_MS = 12 * 60 * 60 * 1e3;
25113
+ var CLAIM_SWEEP_MS = 7 * 24 * 60 * 60 * 1e3;
25114
+ function sweep(dir) {
25115
+ try {
25116
+ for (const name of readdirSync5(dir)) {
25117
+ const path = join27(dir, name);
25118
+ try {
25119
+ if (Date.now() - statSync9(path).mtimeMs > CLAIM_SWEEP_MS) rmSync7(path, { force: true });
25120
+ } catch {
25121
+ }
25122
+ }
25123
+ } catch {
25124
+ }
25125
+ }
25126
+ function tryClaim(dataDir2, sessionId) {
25127
+ if (sessionId === void 0 || sessionId === "") return () => void 0;
25128
+ const dir = join27(dataDir2, CLAIM_DIR);
25129
+ const path = join27(dir, encodeURIComponent(sessionId));
25130
+ try {
25131
+ if (Date.now() - statSync9(path).mtimeMs < CLAIM_TTL_MS) return null;
25132
+ rmSync7(path, { force: true });
25133
+ } catch {
25134
+ }
25135
+ try {
25136
+ mkdirSync6(dir, { recursive: true, mode: DATA_DIR_MODE });
25137
+ writeFileSync9(path, String(Date.now()), { flag: "wx", mode: DATA_FILE_MODE });
25138
+ } catch (err) {
25139
+ if (err.code === "EEXIST") return null;
25140
+ return () => void 0;
25141
+ }
25142
+ sweep(dir);
25143
+ return () => {
25144
+ try {
25145
+ rmSync7(path, { force: true });
25146
+ } catch {
25147
+ }
25148
+ };
25149
+ }
25150
+ function warnIfHostBelowFloor(config2, sessionId, transcriptPath, write = (message) => void process.stderr.write(message)) {
25151
+ try {
25152
+ const release2 = tryClaim(config2.dataDir, sessionId);
25153
+ if (release2 === null) return;
25154
+ let settled = false;
25155
+ try {
25156
+ const version2 = hostVersionFromTranscript(transcriptPath);
25157
+ if (version2 === void 0) return;
25158
+ recordHostVersion(config2.dataDir, version2);
25159
+ const notice = hostFloorNotice(version2);
25160
+ if (notice !== null) write(`[aka] ${notice}
25161
+ `);
25162
+ settled = true;
25163
+ } finally {
25164
+ if (!settled) release2();
25165
+ }
25166
+ } catch {
25167
+ }
25168
+ }
25169
+
24538
25170
  // src/hooks/shared.ts
24539
25171
  async function readStdin() {
24540
25172
  return new Promise((resolve2) => {
@@ -24581,11 +25213,8 @@ function parseStopPayload(input2) {
24581
25213
  }
24582
25214
 
24583
25215
  // src/hooks/store-health.ts
24584
- import { mkdirSync as mkdirSync6, readFileSync as readFileSync19, writeFileSync as writeFileSync9 } from "fs";
24585
- import { dirname as dirname7, join as join29 } from "path";
24586
-
24587
- // ../../packages/plugin-runtime/src/attached/egress-wire.ts
24588
- import { createHash as createHash6 } from "crypto";
25216
+ import { mkdirSync as mkdirSync7, readFileSync as readFileSync20, writeFileSync as writeFileSync10 } from "fs";
25217
+ import { dirname as dirname7, join as join33 } from "path";
24589
25218
 
24590
25219
  // ../../packages/remote/src/http.ts
24591
25220
  import { request as httpRequest } from "http";
@@ -24593,21 +25222,16 @@ import { request as httpsRequest } from "https";
24593
25222
  var MAX_RESPONSE_BYTES = 8 * 1024 * 1024;
24594
25223
 
24595
25224
  // ../../packages/remote/src/client.ts
24596
- var SLASH = "/".charCodeAt(0);
25225
+ var SLASH2 = "/".charCodeAt(0);
24597
25226
 
24598
25227
  // ../../packages/plugin-runtime/src/attached/forward-drops.ts
24599
- import { readFileSync as readFileSync14 } from "fs";
24600
- import { join as join23 } from "path";
25228
+ import { readFileSync as readFileSync17 } from "fs";
25229
+ import { join as join28 } from "path";
24601
25230
 
24602
25231
  // ../../packages/plugin-runtime/src/attached/forward-policy.ts
24603
25232
  import { randomUUID as randomUUID15 } from "crypto";
24604
- import { readFileSync as readFileSync15 } from "fs";
24605
25233
  import { readFile, rename, writeFile } from "fs/promises";
24606
- import { join as join24 } from "path";
24607
-
24608
- // ../../packages/plugin-runtime/src/attached/history-state.ts
24609
- import { readFileSync as readFileSync16 } from "fs";
24610
- import { join as join25 } from "path";
25234
+ import { join as join29 } from "path";
24611
25235
 
24612
25236
  // ../../packages/plugin-runtime/src/attached/history-sync.ts
24613
25237
  import { createHash as createHash7 } from "crypto";
@@ -24617,6 +25241,10 @@ import { hostname as hostname5 } from "os";
24617
25241
  var CORRELATION_ID = EventMetadata.shape.correlationId;
24618
25242
  var TRACE_ID = EventMetadata.shape.traceId;
24619
25243
  var EXCEPTION_ID = EventMetadata.shape.exceptionIds.unwrap().element;
25244
+ var REDACT_DEGRADED_TO = EventMetadata.shape.redactDegradedTo.unwrap();
25245
+
25246
+ // ../../packages/plugin-runtime/src/attached/history-sync.ts
25247
+ var CAPTURE_BATCH_BYTES = 1024 * 1024;
24620
25248
 
24621
25249
  // ../../packages/plugin-runtime/src/attached/history-sync-trigger.ts
24622
25250
  import { spawn as spawn2 } from "child_process";
@@ -24624,12 +25252,12 @@ import { fileURLToPath as fileURLToPath3 } from "url";
24624
25252
  var HISTORY_SYNC_THROTTLE_MS = 5 * 60 * 1e3;
24625
25253
 
24626
25254
  // ../../packages/plugin-runtime/src/attached/plugin-block.ts
24627
- import { readFileSync as readFileSync17 } from "fs";
25255
+ import { readFileSync as readFileSync18 } from "fs";
24628
25256
 
24629
25257
  // ../../packages/plugin-runtime/src/attached/policy-store.ts
24630
25258
  import { randomUUID as randomUUID16 } from "crypto";
24631
25259
  import { readFile as readFile2, rm, writeFile as writeFile2 } from "fs/promises";
24632
- import { join as join26 } from "path";
25260
+ import { join as join30 } from "path";
24633
25261
 
24634
25262
  // ../../packages/plugin-runtime/src/attached/atomic-publish.ts
24635
25263
  import { rename as rename2 } from "fs/promises";
@@ -24638,17 +25266,17 @@ import { rename as rename2 } from "fs/promises";
24638
25266
  var POSTURE_REPORT_INTERVAL_MS = 60 * 60 * 1e3;
24639
25267
 
24640
25268
  // ../../packages/plugin-runtime/src/attached/posture-snapshot.ts
24641
- import { statSync as statSync9 } from "fs";
25269
+ import { statSync as statSync10 } from "fs";
24642
25270
  import { DatabaseSync as DatabaseSync4 } from "node:sqlite";
24643
25271
 
24644
25272
  // ../../packages/plugin-runtime/src/attached/posture-store.ts
24645
25273
  import { randomUUID as randomUUID17 } from "crypto";
24646
25274
  import { readFile as readFile3, rm as rm2, writeFile as writeFile3 } from "fs/promises";
24647
- import { join as join27 } from "path";
25275
+ import { join as join31 } from "path";
24648
25276
 
24649
25277
  // ../../packages/plugin-runtime/src/attached/sync-state.ts
24650
- import { readFileSync as readFileSync18 } from "fs";
24651
- import { join as join28 } from "path";
25278
+ import { readFileSync as readFileSync19 } from "fs";
25279
+ import { join as join32 } from "path";
24652
25280
 
24653
25281
  // ../../packages/plugin-runtime/src/attached/status.ts
24654
25282
  var REFUSAL_LINES = {
@@ -24669,6 +25297,14 @@ import { spawn as spawn3 } from "child_process";
24669
25297
  import { fileURLToPath as fileURLToPath4 } from "url";
24670
25298
  var SYNC_THROTTLE_MS = 15 * 60 * 1e3;
24671
25299
 
25300
+ // ../../packages/plugin-runtime/src/content-retention-pass.ts
25301
+ var MAX_ROWS_PER_SWEEP = 50 * 1e3;
25302
+
25303
+ // ../../packages/plugin-runtime/src/content-retention-trigger.ts
25304
+ import { spawn as spawn4 } from "child_process";
25305
+ import { fileURLToPath as fileURLToPath5 } from "url";
25306
+ var CONTENT_RETENTION_THROTTLE_MS = 60 * 60 * 1e3;
25307
+
24672
25308
  // ../../packages/plugin-runtime/src/attached/factory.ts
24673
25309
  import { hostname as hostname6 } from "os";
24674
25310
 
@@ -24687,7 +25323,7 @@ function markerDirs(dataDir2) {
24687
25323
  function alreadyClaimed(dirs, marker, sessionId) {
24688
25324
  return dirs.some((dir) => {
24689
25325
  try {
24690
- return readFileSync19(join29(dir, marker), "utf8") === sessionId;
25326
+ return readFileSync20(join33(dir, marker), "utf8") === sessionId;
24691
25327
  } catch {
24692
25328
  return false;
24693
25329
  }
@@ -24696,8 +25332,8 @@ function alreadyClaimed(dirs, marker, sessionId) {
24696
25332
  function recordClaim(dirs, marker, sessionId) {
24697
25333
  for (const dir of dirs) {
24698
25334
  try {
24699
- mkdirSync6(dir, { recursive: true, mode: DATA_DIR_MODE });
24700
- writeFileSync9(join29(dir, marker), sessionId, { mode: DATA_FILE_MODE });
25335
+ mkdirSync7(dir, { recursive: true, mode: DATA_DIR_MODE });
25336
+ writeFileSync10(join33(dir, marker), sessionId, { mode: DATA_FILE_MODE });
24701
25337
  return;
24702
25338
  } catch {
24703
25339
  }
@@ -24742,6 +25378,7 @@ async function main() {
24742
25378
  if (trigger === void 0) return;
24743
25379
  const config2 = loadConfig();
24744
25380
  warnIfStoreRedirected(config2, trigger.sessionId);
25381
+ warnIfHostBelowFloor(config2, trigger.sessionId, trigger.transcriptPath);
24745
25382
  triggerReconcile(config2.dataDir, trigger.sessionId, trigger.transcriptPath);
24746
25383
  }
24747
25384
  try {