@akasecurity/ai-tc-claude-code 0.9.11 → 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.
- package/.claude-plugin/plugin.json +1 -1
- package/commands/scan.md +1 -1
- package/commands/setup.md +31 -3
- package/package.json +2 -2
- package/scripts/apply-suppressions.js +1722 -791
- package/scripts/backfill.js +4428 -3403
- package/scripts/content-retention.js +34307 -0
- package/scripts/filescan.js +4615 -3458
- package/scripts/firstrun.js +4389 -3379
- package/scripts/history-sync.js +1916 -866
- package/scripts/intro.js +520 -68
- package/scripts/message-display.js +1704 -773
- package/scripts/onboard.js +1711 -772
- package/scripts/post-model-switch.js +546 -83
- package/scripts/post-tool-use.js +4433 -3408
- package/scripts/pre-model-switch.js +4412 -3380
- package/scripts/pre-tool-use.js +4464 -3412
- package/scripts/query.js +4497 -3375
- package/scripts/reconcile.js +4404 -3393
- package/scripts/remediate.js +4428 -3403
- package/scripts/scan-worker.js +441 -30
- package/scripts/session-start.js +4482 -3450
- package/scripts/start-light.js +518 -66
- package/scripts/statusline.js +4388 -3377
- package/scripts/stop.js +555 -92
- package/scripts/sync.js +4621 -3464
- package/scripts/user-prompt-submit.js +4452 -3406
|
@@ -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
|
|
53
|
+
var SLASH2 = "/";
|
|
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(
|
|
425
|
+
const slices = path.split(SLASH2).filter(Boolean);
|
|
426
426
|
slices.pop();
|
|
427
427
|
if (slices.length) {
|
|
428
428
|
const parent = this._t(
|
|
429
|
-
slices.join(
|
|
429
|
+
slices.join(SLASH2) + SLASH2,
|
|
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(
|
|
445
|
+
slices = path.split(SLASH2).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(
|
|
452
|
+
slices.join(SLASH2) + SLASH2,
|
|
453
453
|
cache,
|
|
454
454
|
checkUnignored,
|
|
455
455
|
slices
|
|
@@ -492,9 +492,9 @@ var require_ignore = __commonJS({
|
|
|
492
492
|
});
|
|
493
493
|
|
|
494
494
|
// src/apply-suppressions.ts
|
|
495
|
-
import { existsSync as existsSync12, readFileSync as
|
|
495
|
+
import { existsSync as existsSync12, readFileSync as readFileSync18 } from "fs";
|
|
496
496
|
import { userInfo } from "os";
|
|
497
|
-
import { dirname as dirname8, join as
|
|
497
|
+
import { dirname as dirname8, join as join28 } from "path";
|
|
498
498
|
import { fileURLToPath as fileURLToPath4 } from "url";
|
|
499
499
|
|
|
500
500
|
// ../../packages/persistence/src/attached-derived.ts
|
|
@@ -506,6 +506,14 @@ var POLICY_CACHE_FILENAME = "policy-cache.json";
|
|
|
506
506
|
import { chmodSync as chmodSync2, lstatSync as lstatSync2, readFileSync, rmSync as rmSync3, statSync } from "fs";
|
|
507
507
|
import { join as join2 } from "path";
|
|
508
508
|
|
|
509
|
+
// ../../packages/schema/src/drizzle/deferred-migrations.ts
|
|
510
|
+
var DEFERRED_MIGRATION_TAGS = [
|
|
511
|
+
"0031_audit_capture_by_time_index",
|
|
512
|
+
"0032_audit_capture_by_id_index",
|
|
513
|
+
"0033_audit_capture_location_index",
|
|
514
|
+
"0034_findings_read_indexes"
|
|
515
|
+
];
|
|
516
|
+
|
|
509
517
|
// ../../packages/schema/src/drizzle/sqlite-ddl.ts
|
|
510
518
|
var SQLITE_MIGRATIONS = [
|
|
511
519
|
{
|
|
@@ -623,6 +631,30 @@ var SQLITE_MIGRATIONS = [
|
|
|
623
631
|
{
|
|
624
632
|
tag: "0028_activity_session_probe_indexes",
|
|
625
633
|
sql: "CREATE INDEX `idx_audit_session_prompt` ON `audit_events` (`root_session_id`) WHERE event_type = 'prompt';--> statement-breakpoint\nCREATE INDEX `idx_audit_session_share` ON `audit_events` (`root_session_id`) WHERE event_type = 'share';--> statement-breakpoint\nCREATE INDEX `idx_audit_ended_at` ON `audit_events` (`ended_at`,`root_session_id`) WHERE ended_at IS NOT NULL;--> statement-breakpoint\nCREATE INDEX `idx_audit_session_ended` ON `audit_events` (`root_session_id`,`ended_at`) WHERE ended_at IS NOT NULL;--> statement-breakpoint\n-- Expression index for the activity list's turns rollup: a live-captured\n-- session's turns are the DISTINCT `run_key` across its `llm_call` leaves, and\n-- carrying the extracted key in the index answers that count from the index\n-- alone instead of parsing every leaf's attribute bag. Written by hand, as\n-- 0013's `idx_audit_code_change_path` was: drizzle-kit cannot emit an\n-- expression containing a comma, so this index is not declared in sqlite.ts.\nCREATE INDEX `idx_audit_session_run_key` ON `audit_events` (`root_session_id`, json_extract(`attributes`, '$.run_key')) WHERE `event_type` = 'llm_call';\n"
|
|
634
|
+
},
|
|
635
|
+
{
|
|
636
|
+
tag: "0029_audit_capture_rollup_index",
|
|
637
|
+
sql: "CREATE INDEX `idx_audit_capture_rollup` ON `audit_events` (`event_type`,`started_at`,`repo`,`id`) WHERE event_type IN ('prompt','response','code_change','tool_use');"
|
|
638
|
+
},
|
|
639
|
+
{
|
|
640
|
+
tag: "0030_audit_content_expiry",
|
|
641
|
+
sql: "ALTER TABLE `audit_events` ADD `content_expired_at` integer;--> statement-breakpoint\nCREATE INDEX `idx_audit_expirable_body` ON `audit_events` (`started_at`) WHERE content IS NOT NULL;"
|
|
642
|
+
},
|
|
643
|
+
{
|
|
644
|
+
tag: "0031_audit_capture_by_time_index",
|
|
645
|
+
sql: "CREATE INDEX `idx_audit_capture_by_time` ON `audit_events` (`started_at`,`id`,`event_type`,`root_session_id`,`source_tool`,`repo`,`file_path`,`tool_name`) WHERE event_type IN ('prompt','response','code_change','tool_use');"
|
|
646
|
+
},
|
|
647
|
+
{
|
|
648
|
+
tag: "0032_audit_capture_by_id_index",
|
|
649
|
+
sql: "CREATE INDEX `idx_audit_capture_by_id` ON `audit_events` (`id`,`started_at`,`event_type`,`root_session_id`,`source_tool`,`repo`,`file_path`,`tool_name`) WHERE event_type IN ('prompt','response','code_change','tool_use');"
|
|
650
|
+
},
|
|
651
|
+
{
|
|
652
|
+
tag: "0033_audit_capture_location_index",
|
|
653
|
+
sql: "CREATE INDEX `idx_audit_capture_location` ON `audit_events` (`repo`,`file_path`,`started_at`,`id`,`event_type`) WHERE event_type IN ('prompt','response','code_change','tool_use');"
|
|
654
|
+
},
|
|
655
|
+
{
|
|
656
|
+
tag: "0034_findings_read_indexes",
|
|
657
|
+
sql: "CREATE INDEX `idx_inspection_definitions_rule` ON `inspection_definitions` (`rule_id`,`severity`,`category`);--> statement-breakpoint\nCREATE INDEX `idx_inspection_findings_def` ON `inspection_findings` (`inspection_definition_id`,`audit_event_id`);--> statement-breakpoint\nCREATE INDEX `idx_inspection_findings_event_cover` ON `inspection_findings` (`audit_event_id`,`inspection_definition_id`,`action_taken`,`finding_key`,`id`);"
|
|
626
658
|
}
|
|
627
659
|
];
|
|
628
660
|
|
|
@@ -20450,7 +20482,17 @@ var UNPRICEABLE_PROVIDERS = Object.freeze([
|
|
|
20450
20482
|
"gateway",
|
|
20451
20483
|
"unknown",
|
|
20452
20484
|
"cli",
|
|
20453
|
-
"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"
|
|
20454
20496
|
]);
|
|
20455
20497
|
function platformForProvider(provider) {
|
|
20456
20498
|
return PROVIDER_PLATFORM.get(provider.trim().toLowerCase()) ?? null;
|
|
@@ -20593,7 +20635,12 @@ var HARNESS = {
|
|
|
20593
20635
|
ClaudeDesktop: "claudedesktop",
|
|
20594
20636
|
ChatGpt: "chatgpt",
|
|
20595
20637
|
ClaudeAi: "claudeai",
|
|
20596
|
-
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"
|
|
20597
20644
|
};
|
|
20598
20645
|
var Harness = external_exports.enum(HARNESS).meta({ id: "Harness" });
|
|
20599
20646
|
var SOURCE_TOOL = {
|
|
@@ -20609,9 +20656,15 @@ var SOURCE_TOOL = {
|
|
|
20609
20656
|
// whose tool could not be identified both render through the read side's
|
|
20610
20657
|
// miss path rather than as a harness of their own.
|
|
20611
20658
|
Cli: "cli",
|
|
20612
|
-
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"
|
|
20613
20665
|
};
|
|
20614
20666
|
var SourceTool = external_exports.enum(SOURCE_TOOL).meta({ id: "SourceTool" });
|
|
20667
|
+
var WebSourceTool = SourceTool.extract(["ChatGpt", "ClaudeAi"]);
|
|
20615
20668
|
var TOOL_TO_HARNESS = {
|
|
20616
20669
|
[SOURCE_TOOL.ClaudeCode]: HARNESS.ClaudeCode,
|
|
20617
20670
|
[SOURCE_TOOL.ClaudeDesktop]: HARNESS.ClaudeDesktop,
|
|
@@ -20620,7 +20673,12 @@ var TOOL_TO_HARNESS = {
|
|
|
20620
20673
|
[SOURCE_TOOL.ChatGpt]: HARNESS.ChatGpt,
|
|
20621
20674
|
[SOURCE_TOOL.Codex]: HARNESS.Codex,
|
|
20622
20675
|
[SOURCE_TOOL.Antigravity]: HARNESS.Antigravity,
|
|
20623
|
-
[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
|
|
20624
20682
|
};
|
|
20625
20683
|
|
|
20626
20684
|
// ../../packages/schema/src/zod/finding.ts
|
|
@@ -20654,7 +20712,8 @@ var FindingProvider = Harness.extract([
|
|
|
20654
20712
|
"ClaudeAi",
|
|
20655
20713
|
"Codex",
|
|
20656
20714
|
"Antigravity",
|
|
20657
|
-
"Api"
|
|
20715
|
+
"Api",
|
|
20716
|
+
"AiTcSdk"
|
|
20658
20717
|
]).meta({ id: "FindingProvider" });
|
|
20659
20718
|
var FindingCategory = external_exports.enum([
|
|
20660
20719
|
"secret",
|
|
@@ -20670,6 +20729,15 @@ var FindingCategory = external_exports.enum([
|
|
|
20670
20729
|
]).meta({ id: "FindingCategory" });
|
|
20671
20730
|
var FindingOrigin = external_exports.enum(["in-flight", "at-rest"]).meta({ id: "FindingOrigin" });
|
|
20672
20731
|
var FindingStatus = external_exports.enum(["open", "handled", "resolved", "dismissed"]).meta({ id: "FindingStatus" });
|
|
20732
|
+
var SyncFailureReason = external_exports.enum(["deployment_refused", "payload_invalid", "detached_undelivered"]).meta({ id: "SyncFailureReason" });
|
|
20733
|
+
var FindingDeliveryState = external_exports.enum(["sent", "queued", "not_sent", "never_offered", "local_scan"]).meta({ id: "FindingDeliveryState" });
|
|
20734
|
+
var FindingDelivery = external_exports.object({
|
|
20735
|
+
state: FindingDeliveryState,
|
|
20736
|
+
// The delivery time for `sent`; the failure time for `not_sent` when recorded.
|
|
20737
|
+
at: external_exports.iso.datetime().optional(),
|
|
20738
|
+
// Only on `not_sent`, and only when a known reason was recorded.
|
|
20739
|
+
reason: SyncFailureReason.optional()
|
|
20740
|
+
}).meta({ id: "FindingDelivery" });
|
|
20673
20741
|
var ResolutionMethod = external_exports.enum([
|
|
20674
20742
|
"enforced-in-flight",
|
|
20675
20743
|
"fixed-at-source",
|
|
@@ -20726,7 +20794,10 @@ var FindingInstance = external_exports.object({
|
|
|
20726
20794
|
// The session that event belongs to, when it has one — the seam a
|
|
20727
20795
|
// per-instance "view session" link needs. Absent for events captured
|
|
20728
20796
|
// outside a session.
|
|
20729
|
-
sessionId: external_exports.string().optional()
|
|
20797
|
+
sessionId: external_exports.string().optional(),
|
|
20798
|
+
// The delivery state of the event above (see FindingDelivery). Optional so
|
|
20799
|
+
// readers that do not project it stay valid.
|
|
20800
|
+
delivery: FindingDelivery.optional()
|
|
20730
20801
|
}).meta({ id: "FindingInstance" });
|
|
20731
20802
|
var FindingGroup = external_exports.object({
|
|
20732
20803
|
id: external_exports.string(),
|
|
@@ -20778,7 +20849,10 @@ var FindingFacets = external_exports.object({
|
|
|
20778
20849
|
// Host tool (attributes.tool_name). Present only on the instance-level
|
|
20779
20850
|
// reads, which can filter by it; the type-level read omits the dimension
|
|
20780
20851
|
// because a group spans tools.
|
|
20781
|
-
tool: external_exports.array(FindingFacetItem).optional()
|
|
20852
|
+
tool: external_exports.array(FindingFacetItem).optional(),
|
|
20853
|
+
// Delivery states (FindingDeliveryState). Present only on the
|
|
20854
|
+
// instance-level reads, like `tool`.
|
|
20855
|
+
deployment: external_exports.array(FindingFacetItem).optional()
|
|
20782
20856
|
}).meta({ id: "FindingFacets" });
|
|
20783
20857
|
var FindingTypeSummary = FindingGroup.omit({ instances: true, match: true }).meta({
|
|
20784
20858
|
id: "FindingTypeSummary"
|
|
@@ -20889,6 +20963,8 @@ var ListFindingInstancesQuery = external_exports.object({
|
|
|
20889
20963
|
// Exact host-tool names (attributes.tool_name, e.g. 'Bash'). A real filter,
|
|
20890
20964
|
// where the free-text `q` can only match the rendered "via Bash" label.
|
|
20891
20965
|
tool: external_exports.array(external_exports.string()).optional(),
|
|
20966
|
+
// The delivery state of each finding's event (see FindingDelivery).
|
|
20967
|
+
deployment: external_exports.array(FindingDeliveryState).optional(),
|
|
20892
20968
|
// Exact repository / file-path matches, for the drill-down out of the
|
|
20893
20969
|
// locations view. A row whose event carries no repo/file matches neither.
|
|
20894
20970
|
repo: external_exports.string().optional(),
|
|
@@ -20909,6 +20985,10 @@ var ListFindingInstancesResponse = external_exports.object({
|
|
|
20909
20985
|
items: external_exports.array(FindingInstanceDetail),
|
|
20910
20986
|
nextCursor: external_exports.string().nullable()
|
|
20911
20987
|
}).meta({ id: "ListFindingInstancesResponse" });
|
|
20988
|
+
var ListFindingInstancesPage = external_exports.object({
|
|
20989
|
+
items: external_exports.array(FindingInstanceDetail),
|
|
20990
|
+
nextCursor: external_exports.string().nullable()
|
|
20991
|
+
}).meta({ id: "ListFindingInstancesPage" });
|
|
20912
20992
|
var FindingLocationSummary = external_exports.object({
|
|
20913
20993
|
// Opaque, stable, minted from the pair by encodeLocationId. It exists
|
|
20914
20994
|
// because a location's identity is two values and a URL param carries one:
|
|
@@ -20951,6 +21031,8 @@ var ListFindingLocationsQuery = external_exports.object({
|
|
|
20951
21031
|
// instances that match, and folds its status from those.
|
|
20952
21032
|
status: external_exports.array(FindingStatus).optional(),
|
|
20953
21033
|
tool: external_exports.array(external_exports.string()).optional(),
|
|
21034
|
+
// The delivery state of each finding's event (see FindingDelivery).
|
|
21035
|
+
deployment: external_exports.array(FindingDeliveryState).optional(),
|
|
20954
21036
|
q: external_exports.string().optional(),
|
|
20955
21037
|
sessionId: external_exports.string().optional(),
|
|
20956
21038
|
from: external_exports.iso.datetime().optional(),
|
|
@@ -21008,18 +21090,41 @@ var AuditEventType = external_exports.enum([
|
|
|
21008
21090
|
// 'tool_call' is the reconciler's structural row for every call, while
|
|
21009
21091
|
// 'tool_use' exists only where a hook enforced against the arguments.
|
|
21010
21092
|
"tool_use",
|
|
21011
|
-
// One row per model REFUSAL
|
|
21012
|
-
//
|
|
21013
|
-
//
|
|
21014
|
-
//
|
|
21015
|
-
//
|
|
21016
|
-
//
|
|
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.
|
|
21017
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",
|
|
21018
21117
|
// One row per config-inventory scan, hung off the session root. It is the
|
|
21019
21118
|
// fact the posture inspection findings reference (findings require an
|
|
21020
21119
|
// audit_event_id), and its started_at is the "scanned Nm ago" the read
|
|
21021
21120
|
// surface renders.
|
|
21022
|
-
"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"
|
|
21023
21128
|
]).meta({ id: "AuditEventType" });
|
|
21024
21129
|
var AttributeBag = external_exports.record(external_exports.string(), external_exports.unknown());
|
|
21025
21130
|
var HostAttributes = external_exports.object({
|
|
@@ -21153,6 +21258,10 @@ var CaptureAttributes = external_exports.object({
|
|
|
21153
21258
|
// to 'allow' — the enforcement audit trail's link back to the grant that
|
|
21154
21259
|
// authorized the bypass.
|
|
21155
21260
|
exception_ids: external_exports.array(external_exports.guid()).optional(),
|
|
21261
|
+
// The persisted spellings of EventMetadata's messageId/conversationId — the
|
|
21262
|
+
// join back to the `llm_call` leaf for the same assistant turn.
|
|
21263
|
+
message_id: external_exports.string().optional(),
|
|
21264
|
+
conversation_id: external_exports.string().optional(),
|
|
21156
21265
|
// Whole milliseconds this capture's inspection blocked its caller — the
|
|
21157
21266
|
// plugin's own added latency (see EventMetadata.inspectionMs, whose value
|
|
21158
21267
|
// this is). Promoted to the `inspection_ms` generated column so the facet is
|
|
@@ -21161,7 +21270,33 @@ var CaptureAttributes = external_exports.object({
|
|
|
21161
21270
|
// inline json_extract and is not itself an optimization.
|
|
21162
21271
|
// ABSENT on replayed captures (backfill / worktree scan) and on rows written
|
|
21163
21272
|
// before the measurement shipped — never present as a placeholder 0.
|
|
21164
|
-
inspection_ms: external_exports.number().int().nonnegative().optional()
|
|
21273
|
+
inspection_ms: external_exports.number().int().nonnegative().optional(),
|
|
21274
|
+
// What a `redact` this capture could not carry out became instead (see
|
|
21275
|
+
// EventMetadata.redactDegradedTo, whose value this is). Present only when a
|
|
21276
|
+
// degrade actually happened, so absence is the ordinary case rather than a
|
|
21277
|
+
// reader having to distinguish it from a zero.
|
|
21278
|
+
//
|
|
21279
|
+
// PER CAPTURE, while `inspection_findings.action_taken` is per finding —
|
|
21280
|
+
// so on a multi-finding row this does not say which finding degraded, and
|
|
21281
|
+
// its presence does not mean the fallback decided the capture's action. A
|
|
21282
|
+
// capture denied by another finding's own Block policy carries `block`
|
|
21283
|
+
// here too. The full statement is on EventMetadata.redactDegradedTo; it is
|
|
21284
|
+
// repeated rather than referenced because a store reader opens this file.
|
|
21285
|
+
redact_degraded_to: ActionTaken.optional()
|
|
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()
|
|
21165
21300
|
}).catchall(external_exports.unknown());
|
|
21166
21301
|
var ToolCallInspection = external_exports.object({
|
|
21167
21302
|
ruleId: external_exports.string().min(1),
|
|
@@ -21360,7 +21495,17 @@ var AuditEvent = external_exports.object({
|
|
|
21360
21495
|
/** `share` to a first-party/internal destination. */
|
|
21361
21496
|
internal: external_exports.boolean(),
|
|
21362
21497
|
/** Event needs review (e.g. unverified egress). */
|
|
21363
|
-
flagged: external_exports.boolean()
|
|
21498
|
+
flagged: external_exports.boolean(),
|
|
21499
|
+
/**
|
|
21500
|
+
* The body this event's `title` is drawn from was cleared by local body
|
|
21501
|
+
* expiry, so an EMPTY title here means "gone", not "never had one".
|
|
21502
|
+
*
|
|
21503
|
+
* A separate flag rather than a sentinel written into `title`: the title is
|
|
21504
|
+
* rendered text, and a store-layer module that invented display copy for it
|
|
21505
|
+
* would be choosing words the view is supposed to choose. Additive and
|
|
21506
|
+
* defaulted, so an older producer still validates.
|
|
21507
|
+
*/
|
|
21508
|
+
bodyExpired: external_exports.boolean().default(false)
|
|
21364
21509
|
}).meta({ id: "ActivityAuditEvent" });
|
|
21365
21510
|
var ActivitySessionSummary = external_exports.object({
|
|
21366
21511
|
id: external_exports.string(),
|
|
@@ -22165,6 +22310,11 @@ var RemoteFailureKind = external_exports.enum([
|
|
|
22165
22310
|
"rejected",
|
|
22166
22311
|
"unreachable"
|
|
22167
22312
|
]);
|
|
22313
|
+
var ControlPlaneFailure = RemoteFailureKind.extract([
|
|
22314
|
+
"unauthorized",
|
|
22315
|
+
"forbidden",
|
|
22316
|
+
"unreachable"
|
|
22317
|
+
]);
|
|
22168
22318
|
var AttachDeviceRequest = external_exports.object({
|
|
22169
22319
|
// This machine's own continuity id, so re-attaching ROTATES the credential
|
|
22170
22320
|
// on one machine record instead of producing a second one. Client-minted
|
|
@@ -22700,6 +22850,17 @@ var EventMetadata = external_exports.object({
|
|
|
22700
22850
|
// to 'allow' — the enforcement audit trail's link back to the grant that
|
|
22701
22851
|
// authorized the bypass. Absent on captures where no exception applied.
|
|
22702
22852
|
exceptionIds: external_exports.array(external_exports.guid()).optional(),
|
|
22853
|
+
// The assistant message this capture belongs to, and the conversation it sits
|
|
22854
|
+
// in — set by the browser extension's network capture so a stored `response`
|
|
22855
|
+
// row can be joined to the `llm_call` leaf describing the same turn. Absent
|
|
22856
|
+
// on every other capture path, which has no such id.
|
|
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(),
|
|
22863
|
+
conversationId: external_exports.string().optional(),
|
|
22703
22864
|
// How long THIS capture's inspection blocked its caller, in whole
|
|
22704
22865
|
// milliseconds — the plugin's own added latency, NOT the LLM call it sat in
|
|
22705
22866
|
// front of. Measured inside `capture()` (@akasecurity/plugin-sdk) across
|
|
@@ -22712,7 +22873,37 @@ var EventMetadata = external_exports.object({
|
|
|
22712
22873
|
// Absent is also what every pre-measurement client writes, and what a
|
|
22713
22874
|
// clock failure degrades to — a reader must treat absence as "not measured"
|
|
22714
22875
|
// and never as a zero, which would read as "inspection is free".
|
|
22715
|
-
inspectionMs: external_exports.number().int().nonnegative().optional()
|
|
22876
|
+
inspectionMs: external_exports.number().int().nonnegative().optional(),
|
|
22877
|
+
// What a `redact` this capture COULD NOT CARRY OUT became instead — the
|
|
22878
|
+
// workspace's `redactFallback`, applied because the field could not be
|
|
22879
|
+
// masked in place (a shell command, a URL, or any argument on a host whose
|
|
22880
|
+
// hook contract offers no rewrite channel).
|
|
22881
|
+
//
|
|
22882
|
+
// It exists because the action alone cannot say why. A finding recorded as
|
|
22883
|
+
// `warn` reads identically whether its detection was ASSIGNED Warn or was
|
|
22884
|
+
// assigned Redact on a field that could not take one — and those are
|
|
22885
|
+
// different facts about the same row: the first is a policy the user chose,
|
|
22886
|
+
// the second is a masking the host could not perform. Absent means no
|
|
22887
|
+
// degrade happened, which is every ordinary capture.
|
|
22888
|
+
//
|
|
22889
|
+
// TWO LIMITS a reader of a stored row has to know, because the grain here
|
|
22890
|
+
// is the CAPTURE while `actionTaken` is per FINDING:
|
|
22891
|
+
//
|
|
22892
|
+
// - It does not say WHICH finding degraded. A capture carrying a degraded
|
|
22893
|
+
// `redact` alongside a finding ASSIGNED the same action stores both
|
|
22894
|
+
// identically and one reason for the pair; attributing it to both
|
|
22895
|
+
// describes the assigned one wrongly, and to neither loses the degrade.
|
|
22896
|
+
// - PRESENCE IS NOT CAUSATION. The value is the action the lost redact
|
|
22897
|
+
// became, not the reason the capture ended as it did — a capture denied
|
|
22898
|
+
// by some other finding's own Block policy still carries `block` here,
|
|
22899
|
+
// and clearing the workspace's fallback would not have let it through.
|
|
22900
|
+
// Gate on the value against what a fallback can produce; never read the
|
|
22901
|
+
// field's presence as "this was the fallback's doing".
|
|
22902
|
+
//
|
|
22903
|
+
// Both are pinned as behaviour in @akasecurity/plugin-sdk's runtime suite.
|
|
22904
|
+
// Closing either means moving the reason onto the finding row, which
|
|
22905
|
+
// already carries its own action.
|
|
22906
|
+
redactDegradedTo: ActionTaken.optional()
|
|
22716
22907
|
}).meta({ id: "EventMetadata" });
|
|
22717
22908
|
var Event = external_exports.object({
|
|
22718
22909
|
id: external_exports.guid(),
|
|
@@ -22822,7 +23013,32 @@ var RotateKeyInput = external_exports.object({
|
|
|
22822
23013
|
confirmation: external_exports.string()
|
|
22823
23014
|
});
|
|
22824
23015
|
|
|
23016
|
+
// ../../packages/schema/src/zod/finding-delivery.ts
|
|
23017
|
+
var KNOWN_REASONS = SyncFailureReason.options;
|
|
23018
|
+
function knownReason(value) {
|
|
23019
|
+
return value !== null && KNOWN_REASONS.includes(value) ? value : void 0;
|
|
23020
|
+
}
|
|
23021
|
+
function deriveFindingDelivery(row) {
|
|
23022
|
+
if (row.kind === "code_change") return { state: "local_scan" };
|
|
23023
|
+
if (row.syncedAt !== null && row.syncedAt > 0) {
|
|
23024
|
+
return { state: "sent", at: epochMillisToIso(row.syncedAt) };
|
|
23025
|
+
}
|
|
23026
|
+
if (row.syncedAt !== null) {
|
|
23027
|
+
const reason = knownReason(row.syncFailure);
|
|
23028
|
+
return {
|
|
23029
|
+
state: "not_sent",
|
|
23030
|
+
...row.syncFailedAt === null ? {} : { at: epochMillisToIso(row.syncFailedAt) },
|
|
23031
|
+
...reason === void 0 ? {} : { reason }
|
|
23032
|
+
};
|
|
23033
|
+
}
|
|
23034
|
+
if (row.outboxOwed === 1 || row.syncClaimedAt !== null) return { state: "queued" };
|
|
23035
|
+
return { state: "never_offered" };
|
|
23036
|
+
}
|
|
23037
|
+
|
|
22825
23038
|
// ../../packages/schema/src/zod/findings-group-build.ts
|
|
23039
|
+
function lookupOwn(map2, key) {
|
|
23040
|
+
return Object.hasOwn(map2, key) ? map2[key] : void 0;
|
|
23041
|
+
}
|
|
22826
23042
|
function toApiAction(dbVal) {
|
|
22827
23043
|
const map2 = {
|
|
22828
23044
|
log: "monitored",
|
|
@@ -22831,7 +23047,7 @@ function toApiAction(dbVal) {
|
|
|
22831
23047
|
warn: "warned",
|
|
22832
23048
|
allow: "allowed"
|
|
22833
23049
|
};
|
|
22834
|
-
return map2
|
|
23050
|
+
return lookupOwn(map2, dbVal) ?? "allowed";
|
|
22835
23051
|
}
|
|
22836
23052
|
function toApiCategory(dbVal) {
|
|
22837
23053
|
if (dbVal === "code_context") return "source_code";
|
|
@@ -22839,13 +23055,18 @@ function toApiCategory(dbVal) {
|
|
|
22839
23055
|
return parsed.success ? parsed.data : "custom";
|
|
22840
23056
|
}
|
|
22841
23057
|
function toApiProvider(sourceTool) {
|
|
22842
|
-
return TOOL_TO_HARNESS
|
|
23058
|
+
return lookupOwn(TOOL_TO_HARNESS, sourceTool) ?? HARNESS.Api;
|
|
22843
23059
|
}
|
|
22844
|
-
var
|
|
23060
|
+
var FINDING_STATUS_PRECEDENCE = [
|
|
23061
|
+
"open",
|
|
23062
|
+
"handled",
|
|
23063
|
+
"dismissed",
|
|
23064
|
+
"resolved"
|
|
23065
|
+
];
|
|
22845
23066
|
function foldGroupStatus(instanceStatuses) {
|
|
22846
23067
|
const statuses = new Set(instanceStatuses.filter((s) => s !== void 0));
|
|
22847
23068
|
if (statuses.size === 0) return void 0;
|
|
22848
|
-
for (const candidate of
|
|
23069
|
+
for (const candidate of FINDING_STATUS_PRECEDENCE) {
|
|
22849
23070
|
if (statuses.has(candidate)) return candidate;
|
|
22850
23071
|
}
|
|
22851
23072
|
return void 0;
|
|
@@ -22952,11 +23173,16 @@ function applyFindingFilters(types, opts) {
|
|
|
22952
23173
|
}
|
|
22953
23174
|
return filtered;
|
|
22954
23175
|
}
|
|
22955
|
-
|
|
22956
|
-
|
|
23176
|
+
function rankByOrder(members2) {
|
|
23177
|
+
return Object.fromEntries(members2.map((member, index) => [member, index]));
|
|
23178
|
+
}
|
|
23179
|
+
var SEVERITY_RANK = rankByOrder(Severity.options);
|
|
23180
|
+
function severityRank(severity) {
|
|
23181
|
+
return lookupOwn(SEVERITY_RANK, severity);
|
|
23182
|
+
}
|
|
22957
23183
|
function compareFindingGroupOrder(a, b) {
|
|
22958
|
-
const rankA =
|
|
22959
|
-
const rankB =
|
|
23184
|
+
const rankA = severityRank(a.severity) ?? -1;
|
|
23185
|
+
const rankB = severityRank(b.severity) ?? -1;
|
|
22960
23186
|
const severityDiff = rankA - rankB;
|
|
22961
23187
|
if (severityDiff !== 0) return severityDiff;
|
|
22962
23188
|
const recencyDiff = b.latestDetectedAt.localeCompare(a.latestDetectedAt);
|
|
@@ -23031,6 +23257,20 @@ function computeFindingFacets(allTypes, opts) {
|
|
|
23031
23257
|
}
|
|
23032
23258
|
|
|
23033
23259
|
// ../../packages/schema/src/zod/findings-flat-build.ts
|
|
23260
|
+
function compareCodePoints(a, b) {
|
|
23261
|
+
const aIter = a[Symbol.iterator]();
|
|
23262
|
+
const bIter = b[Symbol.iterator]();
|
|
23263
|
+
for (; ; ) {
|
|
23264
|
+
const aNext = aIter.next();
|
|
23265
|
+
const bNext = bIter.next();
|
|
23266
|
+
if (aNext.done && bNext.done) return 0;
|
|
23267
|
+
if (aNext.done) return -1;
|
|
23268
|
+
if (bNext.done) return 1;
|
|
23269
|
+
const aPoint = aNext.value.codePointAt(0) ?? 0;
|
|
23270
|
+
const bPoint = bNext.value.codePointAt(0) ?? 0;
|
|
23271
|
+
if (aPoint !== bPoint) return aPoint - bPoint;
|
|
23272
|
+
}
|
|
23273
|
+
}
|
|
23034
23274
|
function rowHaystack(row) {
|
|
23035
23275
|
return [
|
|
23036
23276
|
row.ruleId,
|
|
@@ -23055,6 +23295,8 @@ function matchesDimension(row, opts, dimension) {
|
|
|
23055
23295
|
return !opts.actions?.length || opts.actions.includes(toApiAction(row.actionTaken));
|
|
23056
23296
|
case "statuses":
|
|
23057
23297
|
return !opts.statuses?.length || row.status !== void 0 && opts.statuses.includes(row.status);
|
|
23298
|
+
case "deliveries":
|
|
23299
|
+
return !opts.deliveries?.length || row.delivery !== void 0 && opts.deliveries.includes(row.delivery.state);
|
|
23058
23300
|
case "tools":
|
|
23059
23301
|
return !opts.tools?.length || row.toolName !== void 0 && opts.tools.includes(row.toolName);
|
|
23060
23302
|
// An EMPTY value is a real filter here, not an absent one. The location
|
|
@@ -23081,6 +23323,7 @@ var DIMENSIONS = [
|
|
|
23081
23323
|
"providers",
|
|
23082
23324
|
"actions",
|
|
23083
23325
|
"statuses",
|
|
23326
|
+
"deliveries",
|
|
23084
23327
|
"tools",
|
|
23085
23328
|
"repo",
|
|
23086
23329
|
"file",
|
|
@@ -23094,10 +23337,19 @@ function matchesInstanceFilters(row, opts, except) {
|
|
|
23094
23337
|
return true;
|
|
23095
23338
|
}
|
|
23096
23339
|
function toItems(counts) {
|
|
23097
|
-
return [...counts.entries()].map(([value, count]) => ({ value, count })).sort(
|
|
23340
|
+
return [...counts.entries()].map(([value, count]) => ({ value, count })).sort(
|
|
23341
|
+
(a, b) => b.count - a.count || a.value.localeCompare(b.value) || // localeCompare reports canonically-equivalent strings (an NFC and an
|
|
23342
|
+
// NFD spelling of the same text) as equal, so a count tie between
|
|
23343
|
+
// them would otherwise be ordered by whichever the Map iteration
|
|
23344
|
+
// produced. compareCodePoints breaks that tie deterministically, which
|
|
23345
|
+
// makes this a TOTAL order — not one that agrees with SQL collation,
|
|
23346
|
+
// which it need not: foldFacetTuples runs this same sort over grouped
|
|
23347
|
+
// tuples, so both paths order facets identically by construction.
|
|
23348
|
+
compareCodePoints(a.value, b.value)
|
|
23349
|
+
);
|
|
23098
23350
|
}
|
|
23099
|
-
function bump(counts, value) {
|
|
23100
|
-
counts.set(value, (counts.get(value) ?? 0) +
|
|
23351
|
+
function bump(counts, value, by = 1) {
|
|
23352
|
+
counts.set(value, (counts.get(value) ?? 0) + by);
|
|
23101
23353
|
}
|
|
23102
23354
|
function createInstanceFacetAccumulator(opts) {
|
|
23103
23355
|
const severity = /* @__PURE__ */ new Map();
|
|
@@ -23106,6 +23358,7 @@ function createInstanceFacetAccumulator(opts) {
|
|
|
23106
23358
|
const action = /* @__PURE__ */ new Map();
|
|
23107
23359
|
const status = /* @__PURE__ */ new Map();
|
|
23108
23360
|
const tool = /* @__PURE__ */ new Map();
|
|
23361
|
+
const deployment = /* @__PURE__ */ new Map();
|
|
23109
23362
|
return {
|
|
23110
23363
|
add(row) {
|
|
23111
23364
|
if (matchesInstanceFilters(row, opts, "severity")) bump(severity, row.severity);
|
|
@@ -23120,6 +23373,9 @@ function createInstanceFacetAccumulator(opts) {
|
|
|
23120
23373
|
if (row.toolName !== void 0 && matchesInstanceFilters(row, opts, "tools")) {
|
|
23121
23374
|
bump(tool, row.toolName);
|
|
23122
23375
|
}
|
|
23376
|
+
if (row.delivery !== void 0 && matchesInstanceFilters(row, opts, "deliveries")) {
|
|
23377
|
+
bump(deployment, row.delivery.state);
|
|
23378
|
+
}
|
|
23123
23379
|
},
|
|
23124
23380
|
facets: () => ({
|
|
23125
23381
|
severity: toItems(severity),
|
|
@@ -23127,7 +23383,8 @@ function createInstanceFacetAccumulator(opts) {
|
|
|
23127
23383
|
provider: toItems(provider),
|
|
23128
23384
|
action: toItems(action),
|
|
23129
23385
|
status: toItems(status),
|
|
23130
|
-
tool: toItems(tool)
|
|
23386
|
+
tool: toItems(tool),
|
|
23387
|
+
deployment: toItems(deployment)
|
|
23131
23388
|
})
|
|
23132
23389
|
};
|
|
23133
23390
|
}
|
|
@@ -23141,6 +23398,7 @@ function toInstanceDetail(row) {
|
|
|
23141
23398
|
...row.toolName === void 0 ? {} : { toolName: row.toolName },
|
|
23142
23399
|
eventId: row.eventId,
|
|
23143
23400
|
...row.sessionId === void 0 ? {} : { sessionId: row.sessionId },
|
|
23401
|
+
...row.delivery === void 0 ? {} : { delivery: row.delivery },
|
|
23144
23402
|
...row.user === void 0 ? {} : { user: row.user },
|
|
23145
23403
|
action: toApiAction(row.actionTaken),
|
|
23146
23404
|
detectedAt: row.occurredAt,
|
|
@@ -23155,12 +23413,6 @@ function toInstanceDetail(row) {
|
|
|
23155
23413
|
policy: { id: `category:${category}`, name: category }
|
|
23156
23414
|
};
|
|
23157
23415
|
}
|
|
23158
|
-
var SEVERITY_ORDER2 = {
|
|
23159
|
-
critical: 0,
|
|
23160
|
-
high: 1,
|
|
23161
|
-
medium: 2,
|
|
23162
|
-
low: 3
|
|
23163
|
-
};
|
|
23164
23416
|
function newLocationAccumulator() {
|
|
23165
23417
|
return {
|
|
23166
23418
|
instanceCount: 0,
|
|
@@ -23175,7 +23427,7 @@ function newLocationAccumulator() {
|
|
|
23175
23427
|
}
|
|
23176
23428
|
function addToLocation(acc, row) {
|
|
23177
23429
|
acc.instanceCount += 1;
|
|
23178
|
-
const rank =
|
|
23430
|
+
const rank = severityRank(row.severity) ?? Number.MAX_SAFE_INTEGER - 1;
|
|
23179
23431
|
if (rank < acc.maxSeverityRank) {
|
|
23180
23432
|
acc.maxSeverityRank = rank;
|
|
23181
23433
|
acc.maxSeverity = row.severity;
|
|
@@ -23185,15 +23437,15 @@ function addToLocation(acc, row) {
|
|
|
23185
23437
|
acc.ruleIds.add(row.ruleId);
|
|
23186
23438
|
}
|
|
23187
23439
|
function compareLocationOrder(a, b) {
|
|
23188
|
-
const rankA =
|
|
23189
|
-
const rankB =
|
|
23440
|
+
const rankA = severityRank(a.maxSeverity) ?? -1;
|
|
23441
|
+
const rankB = severityRank(b.maxSeverity) ?? -1;
|
|
23190
23442
|
if (rankA !== rankB) return rankA - rankB;
|
|
23191
23443
|
if (a.latestDetectedAt !== b.latestDetectedAt) {
|
|
23192
23444
|
return a.latestDetectedAt < b.latestDetectedAt ? 1 : -1;
|
|
23193
23445
|
}
|
|
23194
|
-
|
|
23195
|
-
if (
|
|
23196
|
-
return
|
|
23446
|
+
const repoDiff = compareCodePoints(a.repo, b.repo);
|
|
23447
|
+
if (repoDiff !== 0) return repoDiff;
|
|
23448
|
+
return compareCodePoints(a.file, b.file);
|
|
23197
23449
|
}
|
|
23198
23450
|
function encodeLocationId(repo, file2) {
|
|
23199
23451
|
return `${encodePart(repo)}/${encodePart(file2)}`;
|
|
@@ -23268,6 +23520,11 @@ var Policy = external_exports.object({
|
|
|
23268
23520
|
// test `prohibitedModels` passes and `reversibleRuleIds` fails.
|
|
23269
23521
|
provenance: PolicyProvenance.optional()
|
|
23270
23522
|
}).meta({ id: "Policy" });
|
|
23523
|
+
var KNOWN_BUILTIN_IDS = ["monitor", "warn", "redact", "vault", "block"];
|
|
23524
|
+
var BuiltinPolicyId = external_exports.enum(KNOWN_BUILTIN_IDS).meta({ id: "BuiltinPolicyId" });
|
|
23525
|
+
var RedactFallback = BuiltinPolicyId.extract(["monitor", "warn", "block"]).meta({
|
|
23526
|
+
id: "RedactFallback"
|
|
23527
|
+
});
|
|
23271
23528
|
var PolicyBundle = external_exports.object({
|
|
23272
23529
|
version: external_exports.string(),
|
|
23273
23530
|
policies: external_exports.array(Policy),
|
|
@@ -23315,6 +23572,16 @@ var PolicyBundle = external_exports.object({
|
|
|
23315
23572
|
// control plane), so no name resolution stands between the decision and the
|
|
23316
23573
|
// comparison.
|
|
23317
23574
|
prohibitedModels: external_exports.array(external_exports.string()).optional(),
|
|
23575
|
+
// What a resolved `redact` becomes on a field the host cannot rewrite, as
|
|
23576
|
+
// the ORGANIZATION would have it. Merged raise-only against the device's own
|
|
23577
|
+
// `WorkspaceSettings.redactFallback` (see strongerRedactFallback below), so
|
|
23578
|
+
// a control plane can tighten a machine and never loosen one — the same
|
|
23579
|
+
// direction `mergeRaiseOnly` enforces for policies.
|
|
23580
|
+
//
|
|
23581
|
+
// Optional so an older backend, and an older on-disk cache, still parses;
|
|
23582
|
+
// absent leaves the device's own setting in force, which is the behaviour
|
|
23583
|
+
// that predates the field and the safe direction to default.
|
|
23584
|
+
redactFallback: RedactFallback.optional(),
|
|
23318
23585
|
customKeywords: external_exports.array(external_exports.string()),
|
|
23319
23586
|
fetchedAt: external_exports.iso.datetime()
|
|
23320
23587
|
}).meta({ id: "PolicyBundle" });
|
|
@@ -23349,11 +23616,6 @@ function severityFloorPosture() {
|
|
|
23349
23616
|
for (const c of DetectionCategory.options) out[c] = severityFloorPolicy(c);
|
|
23350
23617
|
return out;
|
|
23351
23618
|
}
|
|
23352
|
-
var KNOWN_BUILTIN_IDS = ["monitor", "warn", "redact", "vault", "block"];
|
|
23353
|
-
var BuiltinPolicyId = external_exports.enum(KNOWN_BUILTIN_IDS).meta({ id: "BuiltinPolicyId" });
|
|
23354
|
-
var RedactFallback = BuiltinPolicyId.extract(["monitor", "warn", "block"]).meta({
|
|
23355
|
-
id: "RedactFallback"
|
|
23356
|
-
});
|
|
23357
23619
|
var BUILTIN_ORDER = KNOWN_BUILTIN_IDS;
|
|
23358
23620
|
var BUILTIN_POLICY_SPECS = {
|
|
23359
23621
|
monitor: {
|
|
@@ -23649,7 +23911,7 @@ var VaultConsent = external_exports.object({
|
|
|
23649
23911
|
});
|
|
23650
23912
|
|
|
23651
23913
|
// ../../packages/schema/src/zod/local.ts
|
|
23652
|
-
var WORKSPACE_SETTINGS_SPEC_VERSION =
|
|
23914
|
+
var WORKSPACE_SETTINGS_SPEC_VERSION = 8;
|
|
23653
23915
|
var MODEL_JUDGE_PAYLOAD_VERSION = 1;
|
|
23654
23916
|
var RunMode = external_exports.enum(["standalone", "attached"]);
|
|
23655
23917
|
var ControlPlaneConnection = external_exports.object({
|
|
@@ -23672,6 +23934,27 @@ var HistorySyncConsent = external_exports.object({
|
|
|
23672
23934
|
payloadVersion: external_exports.number().int().positive(),
|
|
23673
23935
|
endpoint: external_exports.string()
|
|
23674
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
|
+
});
|
|
23949
|
+
var BODY_RETENTION_DEFAULT_DAYS = 30;
|
|
23950
|
+
var BodyRetention = external_exports.object({
|
|
23951
|
+
enabled: external_exports.boolean().default(false),
|
|
23952
|
+
// Never 0, and the ceiling is a fat-finger guard rather than a policy
|
|
23953
|
+
// limit — `enabled` is the real gate. A low value cannot reach a row the
|
|
23954
|
+
// sync ledger still owes: the sweep's age filter only ever NARROWS a
|
|
23955
|
+
// candidate set that is already bounded by "delivered, or never owed".
|
|
23956
|
+
retainDays: external_exports.number().int().min(1).max(3650).default(BODY_RETENTION_DEFAULT_DAYS)
|
|
23957
|
+
}).meta({ id: "BodyRetention" });
|
|
23675
23958
|
var WorkspaceSettings = external_exports.object({
|
|
23676
23959
|
specVersion: external_exports.number().int().positive().default(WORKSPACE_SETTINGS_SPEC_VERSION),
|
|
23677
23960
|
runMode: RunMode.default("standalone"),
|
|
@@ -23720,7 +24003,23 @@ var WorkspaceSettings = external_exports.object({
|
|
|
23720
24003
|
// carry prompt/reply/tool-output text in `content`; the key name predates
|
|
23721
24004
|
// both widenings. Absent until granted, and a grant for a different endpoint
|
|
23722
24005
|
// or an older payload no longer counts.
|
|
23723
|
-
historySyncConsent: HistorySyncConsent.optional()
|
|
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(),
|
|
24017
|
+
// Local body expiry (see BodyRetention). Off until switched on; expiring a
|
|
24018
|
+
// body never removes the row or its findings.
|
|
24019
|
+
bodyRetention: BodyRetention.default({
|
|
24020
|
+
enabled: false,
|
|
24021
|
+
retainDays: BODY_RETENTION_DEFAULT_DAYS
|
|
24022
|
+
})
|
|
23724
24023
|
});
|
|
23725
24024
|
function defaultWorkspaceSettings() {
|
|
23726
24025
|
return WorkspaceSettings.parse({});
|
|
@@ -23815,12 +24114,18 @@ function toCaptureAttributes(event) {
|
|
|
23815
24114
|
...metadata?.traceId !== void 0 ? { trace_id: metadata.traceId } : {},
|
|
23816
24115
|
...metadata?.exceptionIds !== void 0 ? { exception_ids: metadata.exceptionIds } : {},
|
|
23817
24116
|
...metadata?.inspectionMs !== void 0 ? { inspection_ms: metadata.inspectionMs } : {},
|
|
24117
|
+
...metadata?.redactDegradedTo !== void 0 ? { redact_degraded_to: metadata.redactDegradedTo } : {},
|
|
23818
24118
|
// `model`/`turnIndex` have no dedicated CaptureAttributes field (no writer
|
|
23819
24119
|
// has ever populated either), but every legacy metadata key still rides
|
|
23820
24120
|
// the bag rather than being silently dropped — CaptureAttributes'
|
|
23821
24121
|
// `.catchall(z.unknown())` carries the long tail.
|
|
23822
24122
|
...metadata?.model !== void 0 ? { model: metadata.model } : {},
|
|
23823
|
-
...metadata?.turnIndex !== void 0 ? { turn_index: metadata.turnIndex } : {}
|
|
24123
|
+
...metadata?.turnIndex !== void 0 ? { turn_index: metadata.turnIndex } : {},
|
|
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 } : {},
|
|
24128
|
+
...metadata?.conversationId !== void 0 ? { conversation_id: metadata.conversationId } : {}
|
|
23824
24129
|
};
|
|
23825
24130
|
}
|
|
23826
24131
|
function captureDefinitionVersion(finding) {
|
|
@@ -23848,13 +24153,22 @@ var ManagedSettingKey = external_exports.enum([
|
|
|
23848
24153
|
"vaultInlineReveal",
|
|
23849
24154
|
"modelJudgeConsent",
|
|
23850
24155
|
"dataSharesInPlace",
|
|
23851
|
-
"redactFallback"
|
|
24156
|
+
"redactFallback",
|
|
24157
|
+
// Pins the toggle and the day count together — see BodyRetention on why the
|
|
24158
|
+
// two are one unit. An administrator mandating a window wants the count
|
|
24159
|
+
// enforced with it, not one a user can widen while the toggle stays on.
|
|
24160
|
+
"bodyRetention"
|
|
23852
24161
|
]).meta({ id: "ManagedSettingKey" });
|
|
23853
24162
|
function isManagedSettingKey(value) {
|
|
23854
24163
|
return ManagedSettingKey.safeParse(value).success;
|
|
23855
24164
|
}
|
|
23856
24165
|
var ManagedSettingsValues = external_exports.object({
|
|
23857
24166
|
runMode: external_exports.enum(["standalone", "attached"]).optional(),
|
|
24167
|
+
// `controlPlane` and `bodyRetention` are the two nested values, and both are
|
|
24168
|
+
// plain, non-strict objects: a key under either that this build does not know
|
|
24169
|
+
// is stripped and nothing reports it. The unknown-value split in
|
|
24170
|
+
// ManagedSettings below classifies top-level names only, so it stops at
|
|
24171
|
+
// these boundaries.
|
|
23858
24172
|
controlPlane: external_exports.object({
|
|
23859
24173
|
endpoint: external_exports.string().min(1),
|
|
23860
24174
|
label: external_exports.string().min(1).optional()
|
|
@@ -23865,7 +24179,8 @@ var ManagedSettingsValues = external_exports.object({
|
|
|
23865
24179
|
vaultInlineReveal: external_exports.enum(["masked", "full", "off"]).optional(),
|
|
23866
24180
|
modelJudgeConsent: external_exports.boolean().optional(),
|
|
23867
24181
|
dataSharesInPlace: external_exports.boolean().optional(),
|
|
23868
|
-
redactFallback: RedactFallback.optional()
|
|
24182
|
+
redactFallback: RedactFallback.optional(),
|
|
24183
|
+
bodyRetention: BodyRetention.optional()
|
|
23869
24184
|
}).meta({ id: "ManagedSettingsValues" });
|
|
23870
24185
|
var ManagedSettings = external_exports.object({
|
|
23871
24186
|
specVersion: external_exports.number().int().positive().default(MANAGED_SETTINGS_SPEC_VERSION),
|
|
@@ -23873,7 +24188,21 @@ var ManagedSettings = external_exports.object({
|
|
|
23873
24188
|
// decision from a bug. Absent renders as a generic "your organization".
|
|
23874
24189
|
organization: external_exports.string().min(1).optional(),
|
|
23875
24190
|
// What the administrator pinned.
|
|
23876
|
-
|
|
24191
|
+
//
|
|
24192
|
+
// Parsed as a RECORD rather than as the nested schema, and split below for
|
|
24193
|
+
// the same reason `lockedFields` is parsed as names: a plain `z.object`
|
|
24194
|
+
// drops an unrecognised key and succeeds, so a pin this build does not know
|
|
24195
|
+
// vanished and nothing anywhere said so. A pin with no lock is a supported
|
|
24196
|
+
// shape — it is a DEFAULT the user may still change — so that silence hit
|
|
24197
|
+
// exactly the file an administrator is most likely to write while a fleet
|
|
24198
|
+
// is mid-upgrade.
|
|
24199
|
+
//
|
|
24200
|
+
// Splitting here rather than calling `.strict()`: strict would REFUSE the
|
|
24201
|
+
// file, which is the outcome the lock half already rejected — an older
|
|
24202
|
+
// build then runs entirely unmanaged, every pin and lock gone. A bad KNOWN
|
|
24203
|
+
// value still fails, because the nested schema is re-run over the known
|
|
24204
|
+
// subset and its issues are re-raised on this parse.
|
|
24205
|
+
values: external_exports.record(external_exports.string(), external_exports.unknown()).default({}),
|
|
23877
24206
|
// Which of those the user may not change. A key here with no matching value
|
|
23878
24207
|
// freezes whatever the user last chose; a value with no lock is a DEFAULT
|
|
23879
24208
|
// the user may still override. The two are separable on purpose.
|
|
@@ -23886,17 +24215,31 @@ var ManagedSettings = external_exports.object({
|
|
|
23886
24215
|
// the fleets most likely to carry a version skew. A name outside the enum
|
|
23887
24216
|
// is still never HONOURED: the lockable set stays explicit above.
|
|
23888
24217
|
lockedFields: external_exports.array(external_exports.string()).default([])
|
|
23889
|
-
}).transform(({ lockedFields, ...rest }) => {
|
|
24218
|
+
}).transform(({ lockedFields, values, ...rest }, ctx) => {
|
|
23890
24219
|
const known = [];
|
|
23891
24220
|
const unknown2 = [];
|
|
23892
24221
|
for (const name of lockedFields) {
|
|
23893
24222
|
if (isManagedSettingKey(name)) known.push(name);
|
|
23894
24223
|
else unknown2.push(name);
|
|
23895
24224
|
}
|
|
24225
|
+
const knownValues = /* @__PURE__ */ Object.create(null);
|
|
24226
|
+
const unknownValues = [];
|
|
24227
|
+
for (const [name, value] of Object.entries(values)) {
|
|
24228
|
+
if (Object.hasOwn(ManagedSettingsValues.shape, name)) knownValues[name] = value;
|
|
24229
|
+
else unknownValues.push(name);
|
|
24230
|
+
}
|
|
24231
|
+
const pinned = ManagedSettingsValues.safeParse(knownValues);
|
|
24232
|
+
if (!pinned.success) {
|
|
24233
|
+
for (const issue2 of pinned.error.issues)
|
|
24234
|
+
ctx.addIssue({ ...issue2, path: ["values", ...issue2.path] });
|
|
24235
|
+
return external_exports.NEVER;
|
|
24236
|
+
}
|
|
23896
24237
|
return {
|
|
23897
24238
|
...rest,
|
|
24239
|
+
values: pinned.data,
|
|
23898
24240
|
lockedFields: known,
|
|
23899
|
-
...unknown2.length > 0 ? { unknownLockedFields: unknown2 } : {}
|
|
24241
|
+
...unknown2.length > 0 ? { unknownLockedFields: unknown2 } : {},
|
|
24242
|
+
...unknownValues.length > 0 ? { unknownValueFields: unknownValues } : {}
|
|
23900
24243
|
};
|
|
23901
24244
|
}).meta({ id: "ManagedSettings" });
|
|
23902
24245
|
|
|
@@ -24155,12 +24498,30 @@ var RecommendedActionIdParam = external_exports.object({ id: external_exports.st
|
|
|
24155
24498
|
// ../../packages/schema/src/zod/settings-action.ts
|
|
24156
24499
|
var HistorySyncConsentChoice = external_exports.enum(["granted", "revoked", "unchanged"]).meta({ id: "HistorySyncConsentChoice" });
|
|
24157
24500
|
var ModelJudgeConsentChoice = external_exports.enum(["granted", "revoked", "unchanged"]).meta({ id: "ModelJudgeConsentChoice" });
|
|
24501
|
+
var WebChatCaptureConsentChoice = external_exports.enum(["granted", "revoked", "unchanged"]).meta({ id: "WebChatCaptureConsentChoice" });
|
|
24158
24502
|
var SaveSettingsInput = external_exports.object({
|
|
24159
24503
|
historicalAccess: external_exports.string(),
|
|
24160
24504
|
modelJudgeConsent: ModelJudgeConsentChoice,
|
|
24161
24505
|
historySyncConsent: HistorySyncConsentChoice,
|
|
24162
24506
|
vaultConsent: external_exports.string(),
|
|
24163
|
-
vaultInlineReveal: external_exports.string()
|
|
24507
|
+
vaultInlineReveal: external_exports.string(),
|
|
24508
|
+
webChatCaptureConsent: WebChatCaptureConsentChoice,
|
|
24509
|
+
// Widened to `string` like its neighbours rather than typed as
|
|
24510
|
+
// `RedactFallback`, on this module's own layering rule: shape here, VALUE at
|
|
24511
|
+
// the call site, so the domain check receives the type it was written for.
|
|
24512
|
+
//
|
|
24513
|
+
// NOT because a narrower schema would reject differently. `parseActionInput`
|
|
24514
|
+
// is a `safeParse` wrapper and throws for no field schema, so either spelling
|
|
24515
|
+
// reaches a recoverable `{ ok: false }` and there is no rejected promise to
|
|
24516
|
+
// trade against. The real cost runs the other way and is the part worth
|
|
24517
|
+
// knowing: a value this schema admits and the domain enum then rejects lands
|
|
24518
|
+
// on the action's shared refusal, which names NO field, where a shape
|
|
24519
|
+
// rejection reaches `malformedInput` and names the schema key.
|
|
24520
|
+
redactFallback: external_exports.string(),
|
|
24521
|
+
// Shape only, the way the enum fields above are strings only: the RANGE is
|
|
24522
|
+
// `BodyRetention`'s and the action checks it there, so there is one place
|
|
24523
|
+
// that decides what a legal horizon is rather than two that can drift.
|
|
24524
|
+
bodyRetention: external_exports.object({ enabled: external_exports.boolean(), retainDays: external_exports.number() })
|
|
24164
24525
|
});
|
|
24165
24526
|
var AttachInput = external_exports.object({
|
|
24166
24527
|
endpoint: external_exports.string(),
|
|
@@ -24332,6 +24693,123 @@ function reviewSeverityRank(reasons) {
|
|
|
24332
24693
|
return Math.min(...reasons.map((r) => REVIEW_SEVERITY_RANK[r]));
|
|
24333
24694
|
}
|
|
24334
24695
|
|
|
24696
|
+
// ../../packages/schema/src/zod/web-capture.ts
|
|
24697
|
+
var WebUsageSource = external_exports.enum(["site", "estimated", "none"]);
|
|
24698
|
+
var WebUsage = external_exports.object({
|
|
24699
|
+
inputTokens: external_exports.number().int().nonnegative().optional(),
|
|
24700
|
+
outputTokens: external_exports.number().int().nonnegative().optional(),
|
|
24701
|
+
cacheReadInputTokens: external_exports.number().int().nonnegative().optional(),
|
|
24702
|
+
cacheCreationInputTokens: external_exports.number().int().nonnegative().optional()
|
|
24703
|
+
});
|
|
24704
|
+
var WebToolCall = external_exports.object({
|
|
24705
|
+
toolUseId: external_exports.string().min(1),
|
|
24706
|
+
toolName: external_exports.string().min(1),
|
|
24707
|
+
target: external_exports.string().optional(),
|
|
24708
|
+
isError: external_exports.boolean().optional(),
|
|
24709
|
+
inputSize: external_exports.number().int().nonnegative().optional(),
|
|
24710
|
+
outputSize: external_exports.number().int().nonnegative().optional()
|
|
24711
|
+
});
|
|
24712
|
+
var WebExchange = external_exports.object({
|
|
24713
|
+
messageId: external_exports.string().min(1),
|
|
24714
|
+
startedAt: external_exports.iso.datetime(),
|
|
24715
|
+
model: external_exports.string().optional(),
|
|
24716
|
+
usage: WebUsage.optional(),
|
|
24717
|
+
usageSource: WebUsageSource,
|
|
24718
|
+
stopReason: external_exports.string().optional(),
|
|
24719
|
+
conversationId: external_exports.string().optional(),
|
|
24720
|
+
turnIndex: external_exports.number().int().nonnegative().optional(),
|
|
24721
|
+
toolCalls: external_exports.array(WebToolCall).default([]),
|
|
24722
|
+
// Absent when the adapter recovered no text. Capped by the caller at
|
|
24723
|
+
// RESPONSE_TEXT_MAX_BYTES, so a short capture is never mistaken for a short
|
|
24724
|
+
// reply.
|
|
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.
|
|
24732
|
+
truncated: external_exports.boolean().default(false)
|
|
24733
|
+
});
|
|
24734
|
+
var WebEnforcementState = external_exports.enum([
|
|
24735
|
+
"watching",
|
|
24736
|
+
"composer-only",
|
|
24737
|
+
"button-only",
|
|
24738
|
+
"unattached",
|
|
24739
|
+
"unknown"
|
|
24740
|
+
]);
|
|
24741
|
+
var RESPONSE_TEXT_MAX_BYTES = 2 * 1024 * 1024;
|
|
24742
|
+
var WebCaptureStatus = external_exports.object({
|
|
24743
|
+
patched: external_exports.boolean(),
|
|
24744
|
+
live: external_exports.boolean(),
|
|
24745
|
+
blind: external_exports.boolean(),
|
|
24746
|
+
sendsSeenDom: external_exports.number().int().nonnegative(),
|
|
24747
|
+
exchangesSeenNet: external_exports.number().int().nonnegative(),
|
|
24748
|
+
parseFailures: external_exports.number().int().nonnegative(),
|
|
24749
|
+
unparsedBodies: external_exports.number().int().nonnegative(),
|
|
24750
|
+
// The adapter-declared JSON key paths that were absent from a real payload —
|
|
24751
|
+
// the earliest signal that a site's contract moved.
|
|
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
|
+
}
|
|
24812
|
+
|
|
24335
24813
|
// ../../packages/persistence/src/paths.ts
|
|
24336
24814
|
import {
|
|
24337
24815
|
chmodSync,
|
|
@@ -24524,6 +25002,22 @@ function discardStore(file2, backup) {
|
|
|
24524
25002
|
}
|
|
24525
25003
|
}
|
|
24526
25004
|
|
|
25005
|
+
// ../../packages/persistence/src/internal/sql-functions.ts
|
|
25006
|
+
var utf8 = new TextDecoder();
|
|
25007
|
+
function akaLower(value) {
|
|
25008
|
+
if (value === null) return null;
|
|
25009
|
+
if (typeof value === "string") return value.toLowerCase();
|
|
25010
|
+
if (typeof value === "number" || typeof value === "bigint") return String(value).toLowerCase();
|
|
25011
|
+
return utf8.decode(value).toLowerCase();
|
|
25012
|
+
}
|
|
25013
|
+
function registerSqlFunctions(db) {
|
|
25014
|
+
db.function(
|
|
25015
|
+
"aka_lower",
|
|
25016
|
+
{ deterministic: true, directOnly: true, useBigIntArguments: true },
|
|
25017
|
+
akaLower
|
|
25018
|
+
);
|
|
25019
|
+
}
|
|
25020
|
+
|
|
24527
25021
|
// ../../packages/persistence/src/internal/sql-text.ts
|
|
24528
25022
|
function escapeLikePattern(s) {
|
|
24529
25023
|
return s.replace(/\\/g, "\\\\").replace(/%/g, "\\%").replace(/_/g, "\\_");
|
|
@@ -24608,6 +25102,11 @@ function schemaObjectExists(db, kind, name) {
|
|
|
24608
25102
|
function indexExists(db, name) {
|
|
24609
25103
|
return schemaObjectExists(db, "index", name);
|
|
24610
25104
|
}
|
|
25105
|
+
function indexColumns(db, name) {
|
|
25106
|
+
if (!indexExists(db, name)) return [];
|
|
25107
|
+
const columns = db.prepare(`PRAGMA index_info(${name})`).all();
|
|
25108
|
+
return columns.map((c) => c.name).filter((c) => c !== null);
|
|
25109
|
+
}
|
|
24611
25110
|
function columnNames(db, table2, opts) {
|
|
24612
25111
|
const pragma = opts?.includeGenerated ? "table_xinfo" : "table_info";
|
|
24613
25112
|
const columns = db.prepare(`PRAGMA ${pragma}(${table2})`).all();
|
|
@@ -24669,161 +25168,803 @@ function mapRowsTolerant(rows, map2) {
|
|
|
24669
25168
|
return out;
|
|
24670
25169
|
}
|
|
24671
25170
|
|
|
24672
|
-
// ../../packages/persistence/src/
|
|
24673
|
-
|
|
24674
|
-
|
|
24675
|
-
|
|
24676
|
-
|
|
24677
|
-
|
|
24678
|
-
|
|
24679
|
-
|
|
24680
|
-
|
|
24681
|
-
return /^CREATE (?:UNIQUE )?INDEX (?:IF NOT EXISTS )?`([^`]+)`/.exec(body)?.[1];
|
|
25171
|
+
// ../../packages/persistence/src/internal/outbox-lane.ts
|
|
25172
|
+
var OUTBOX_CAPTURE_EVENT_TYPES = ["prompt", "response", "tool_use"];
|
|
25173
|
+
var OUTBOX_CAPTURE_TYPE_LIST = OUTBOX_CAPTURE_EVENT_TYPES.map((t) => `'${t}'`).join(", ");
|
|
25174
|
+
|
|
25175
|
+
// ../../packages/persistence/src/sync-failure.ts
|
|
25176
|
+
var SYNC_FAILURE_REASONS = SyncFailureReason.options;
|
|
25177
|
+
function syncFailureRejectCondition(column = "sync_failure") {
|
|
25178
|
+
const members2 = SYNC_FAILURE_REASONS.map((r) => `'${r}'`).join(", ");
|
|
25179
|
+
return `NEW.${column} IS NOT NULL AND NEW.${column} NOT IN (${members2})`;
|
|
24682
25180
|
}
|
|
24683
|
-
|
|
24684
|
-
|
|
24685
|
-
|
|
24686
|
-
|
|
24687
|
-
|
|
24688
|
-
|
|
24689
|
-
|
|
24690
|
-
|
|
24691
|
-
|
|
24692
|
-
|
|
24693
|
-
|
|
24694
|
-
|
|
24695
|
-
|
|
24696
|
-
|
|
24697
|
-
|
|
24698
|
-
|
|
24699
|
-
|
|
24700
|
-
|
|
24701
|
-
|
|
24702
|
-
|
|
24703
|
-
|
|
24704
|
-
|
|
24705
|
-
|
|
24706
|
-
|
|
24707
|
-
|
|
24708
|
-
|
|
24709
|
-
|
|
24710
|
-
|
|
24711
|
-
|
|
24712
|
-
|
|
24713
|
-
|
|
24714
|
-
|
|
24715
|
-
|
|
24716
|
-
|
|
24717
|
-
|
|
24718
|
-
|
|
24719
|
-
|
|
24720
|
-
|
|
24721
|
-
|
|
24722
|
-
|
|
24723
|
-
|
|
24724
|
-
|
|
24725
|
-
|
|
24726
|
-
|
|
24727
|
-
|
|
24728
|
-
|
|
24729
|
-
|
|
24730
|
-
|
|
24731
|
-
|
|
24732
|
-
|
|
24733
|
-
|
|
24734
|
-
|
|
24735
|
-
)
|
|
24736
|
-
|
|
24737
|
-
|
|
24738
|
-
|
|
25181
|
+
|
|
25182
|
+
// ../../packages/persistence/src/repositories/history-sync.ts
|
|
25183
|
+
var STRUCTURAL_EVENT_TYPES = ["session", "llm_call", "tool_call"];
|
|
25184
|
+
var TYPE_LIST = STRUCTURAL_EVENT_TYPES.map((t) => `'${t}'`).join(", ");
|
|
25185
|
+
var CAPTURE_TYPE_LIST = OUTBOX_CAPTURE_TYPE_LIST;
|
|
25186
|
+
var COUNTED_EVENT_TYPES = [
|
|
25187
|
+
...STRUCTURAL_EVENT_TYPES,
|
|
25188
|
+
...OUTBOX_CAPTURE_EVENT_TYPES
|
|
25189
|
+
];
|
|
25190
|
+
var COUNTED_TYPE_LIST = COUNTED_EVENT_TYPES.map((t) => `'${t}'`).join(", ");
|
|
25191
|
+
var PARTITION_BUCKETS = `
|
|
25192
|
+
SUM(CASE WHEN synced_at IS NULL AND sync_claimed_at IS NULL THEN 1 ELSE 0 END) AS queued,
|
|
25193
|
+
SUM(CASE WHEN synced_at IS NULL AND sync_claimed_at IS NOT NULL THEN 1 ELSE 0 END) AS inProgress,
|
|
25194
|
+
SUM(CASE WHEN synced_at > 0 THEN 1 ELSE 0 END) AS synced,
|
|
25195
|
+
SUM(CASE WHEN synced_at IS NOT NULL AND synced_at <= 0
|
|
25196
|
+
AND sync_failure = 'deployment_refused' THEN 1 ELSE 0 END) AS refused,
|
|
25197
|
+
SUM(CASE WHEN synced_at IS NOT NULL AND synced_at <= 0
|
|
25198
|
+
AND sync_failure = 'detached_undelivered' THEN 1 ELSE 0 END) AS detached,
|
|
25199
|
+
-- Spelled as what it INCLUDES rather than what it excludes, so a reason
|
|
25200
|
+
-- added later lands in no bucket and fails the sum assertion, instead
|
|
25201
|
+
-- of silently joining this one.
|
|
25202
|
+
SUM(CASE WHEN synced_at IS NOT NULL AND synced_at <= 0
|
|
25203
|
+
AND (sync_failure IS NULL OR sync_failure = 'payload_invalid')
|
|
25204
|
+
THEN 1 ELSE 0 END) AS failed,
|
|
25205
|
+
COUNT(*) AS total`;
|
|
25206
|
+
var COUNTED_SCOPE = `
|
|
25207
|
+
WHERE event_type IN (${COUNTED_TYPE_LIST})
|
|
25208
|
+
AND (
|
|
25209
|
+
event_type IN (${TYPE_LIST})
|
|
25210
|
+
OR synced_at IS NOT NULL
|
|
25211
|
+
OR outbox_owed = 1
|
|
25212
|
+
)`;
|
|
25213
|
+
var SKIPPED = -1;
|
|
25214
|
+
var ROW_COLUMNS = `id,
|
|
25215
|
+
parent_id AS parentId,
|
|
25216
|
+
root_session_id AS rootSessionId,
|
|
25217
|
+
event_type AS eventType,
|
|
25218
|
+
host_id AS hostId,
|
|
25219
|
+
harness_id AS harnessId,
|
|
25220
|
+
source_project_id AS sourceProjectId,
|
|
25221
|
+
started_at AS startedAt,
|
|
25222
|
+
ended_at AS endedAt,
|
|
25223
|
+
severity,
|
|
25224
|
+
priority,
|
|
25225
|
+
content,
|
|
25226
|
+
content_hash AS contentHash,
|
|
25227
|
+
attributes`;
|
|
25228
|
+
var SqliteHistorySyncRepository = class {
|
|
25229
|
+
constructor(db) {
|
|
25230
|
+
this.db = db;
|
|
25231
|
+
this.ensureRowStmt = db.prepare(`INSERT OR IGNORE INTO history_sync (id) VALUES (1)`);
|
|
25232
|
+
this.sessionsStmt = db.prepare(
|
|
25233
|
+
`SELECT COALESCE(root_session_id, id) AS sessionId, MIN(started_at) AS earliest
|
|
25234
|
+
FROM audit_events
|
|
25235
|
+
WHERE synced_at IS NULL
|
|
25236
|
+
AND event_type IN (${TYPE_LIST})
|
|
25237
|
+
AND started_at < :before
|
|
25238
|
+
GROUP BY sessionId
|
|
25239
|
+
ORDER BY earliest
|
|
25240
|
+
LIMIT :limit`
|
|
25241
|
+
);
|
|
25242
|
+
this.rowsStmt = db.prepare(
|
|
25243
|
+
`SELECT ${ROW_COLUMNS}
|
|
25244
|
+
FROM audit_events
|
|
25245
|
+
WHERE synced_at IS NULL
|
|
25246
|
+
AND event_type IN (${TYPE_LIST})
|
|
25247
|
+
AND started_at < :before
|
|
25248
|
+
AND COALESCE(root_session_id, id) = :sessionId
|
|
25249
|
+
ORDER BY (event_type = 'session') DESC, started_at
|
|
25250
|
+
LIMIT :limit`
|
|
25251
|
+
);
|
|
25252
|
+
this.captureRowsStmt = db.prepare(
|
|
25253
|
+
`SELECT ${ROW_COLUMNS}
|
|
25254
|
+
FROM audit_events
|
|
25255
|
+
WHERE synced_at IS NULL
|
|
25256
|
+
AND sync_claimed_at IS NULL
|
|
25257
|
+
AND outbox_owed = 1
|
|
25258
|
+
AND event_type IN (${CAPTURE_TYPE_LIST})
|
|
25259
|
+
AND started_at < :before
|
|
25260
|
+
ORDER BY started_at
|
|
25261
|
+
LIMIT :limit`
|
|
25262
|
+
);
|
|
25263
|
+
this.markOwedStmt = db.prepare(
|
|
25264
|
+
`UPDATE audit_events SET outbox_owed = 1 WHERE id = :id AND synced_at IS NULL`
|
|
25265
|
+
);
|
|
25266
|
+
this.markCaptureBacklogOwedStmt = db.prepare(
|
|
25267
|
+
`UPDATE audit_events SET outbox_owed = 1
|
|
25268
|
+
WHERE synced_at IS NULL
|
|
25269
|
+
AND event_type IN (${CAPTURE_TYPE_LIST})
|
|
25270
|
+
AND started_at < :before`
|
|
25271
|
+
);
|
|
25272
|
+
this.stampStmt = db.prepare(
|
|
25273
|
+
`UPDATE audit_events
|
|
25274
|
+
SET synced_at = :at,
|
|
25275
|
+
sync_claimed_at = NULL,
|
|
25276
|
+
sync_failed_at = :failedAt,
|
|
25277
|
+
sync_failure = :failure
|
|
25278
|
+
WHERE id = :id`
|
|
25279
|
+
);
|
|
25280
|
+
this.claimRowStmt = db.prepare(
|
|
25281
|
+
`UPDATE audit_events SET sync_claimed_at = :at WHERE id = :id AND synced_at IS NULL`
|
|
25282
|
+
);
|
|
25283
|
+
this.releaseRowStmt = db.prepare(
|
|
25284
|
+
`UPDATE audit_events SET sync_claimed_at = NULL WHERE id = :id`
|
|
25285
|
+
);
|
|
25286
|
+
this.releaseStaleClaimsStmt = db.prepare(
|
|
25287
|
+
`UPDATE audit_events SET sync_claimed_at = NULL
|
|
25288
|
+
WHERE sync_claimed_at IS NOT NULL AND sync_claimed_at < :staleBefore`
|
|
25289
|
+
);
|
|
25290
|
+
this.partitionStmt = db.prepare(`SELECT${PARTITION_BUCKETS}
|
|
25291
|
+
FROM audit_events${COUNTED_SCOPE}`);
|
|
25292
|
+
this.partitionByKindStmt = db.prepare(
|
|
25293
|
+
`SELECT event_type AS kind,${PARTITION_BUCKETS}
|
|
25294
|
+
FROM audit_events INDEXED BY idx_audit_events_sync${COUNTED_SCOPE}
|
|
25295
|
+
GROUP BY event_type`
|
|
25296
|
+
);
|
|
25297
|
+
this.countsStmt = db.prepare(
|
|
25298
|
+
`SELECT
|
|
25299
|
+
SUM(CASE WHEN synced_at IS NULL AND started_at < :before THEN 1 ELSE 0 END) AS pending,
|
|
25300
|
+
SUM(CASE WHEN synced_at > 0 THEN 1 ELSE 0 END) AS sent,
|
|
25301
|
+
SUM(CASE WHEN synced_at = ${String(SKIPPED)}
|
|
25302
|
+
AND (sync_failure IS NULL OR sync_failure = 'payload_invalid')
|
|
25303
|
+
THEN 1 ELSE 0 END) AS skipped,
|
|
25304
|
+
SUM(CASE WHEN synced_at = ${String(SKIPPED)}
|
|
25305
|
+
AND sync_failure = 'deployment_refused' THEN 1 ELSE 0 END) AS refused,
|
|
25306
|
+
SUM(CASE WHEN synced_at = ${String(SKIPPED)}
|
|
25307
|
+
AND sync_failure = 'detached_undelivered' THEN 1 ELSE 0 END) AS detached
|
|
25308
|
+
FROM audit_events
|
|
25309
|
+
WHERE event_type IN (${TYPE_LIST})`
|
|
25310
|
+
);
|
|
25311
|
+
this.captureSkipCountStmt = db.prepare(
|
|
25312
|
+
// EVERY sentinel capture, whatever the reason — deliberately NOT split the
|
|
25313
|
+
// way the structural totals are. The split exists because a refusal is
|
|
25314
|
+
// terminal only against the deployment that gave it, and the structural
|
|
25315
|
+
// re-arm frees it on a change of deployment. The capture lane has no such
|
|
25316
|
+
// escape: re-arming a capture would offer one deployment's undelivered
|
|
25317
|
+
// prompts, with their text, to a deployment that never saw them, which is
|
|
25318
|
+
// exactly what disownCapturesStmt exists to prevent. So on this lane both
|
|
25319
|
+
// reasons mean the same thing — this row will not be sent — and splitting
|
|
25320
|
+
// them would put refused captures in a bucket nothing reads and nothing
|
|
25321
|
+
// frees.
|
|
25322
|
+
`SELECT COUNT(*) AS skipped
|
|
25323
|
+
FROM audit_events
|
|
25324
|
+
WHERE synced_at = ${String(SKIPPED)}
|
|
25325
|
+
AND event_type IN (${CAPTURE_TYPE_LIST})`
|
|
25326
|
+
);
|
|
25327
|
+
this.fingerprintStmt = db.prepare(
|
|
25328
|
+
`SELECT endpoint_fingerprint AS fingerprint, backlog_before AS backlogBefore
|
|
25329
|
+
FROM history_sync WHERE id = 1`
|
|
25330
|
+
);
|
|
25331
|
+
this.setFingerprintStmt = db.prepare(
|
|
25332
|
+
`UPDATE history_sync
|
|
25333
|
+
SET endpoint_fingerprint = :fingerprint, backlog_before = :backlogBefore
|
|
25334
|
+
WHERE id = 1`
|
|
25335
|
+
);
|
|
25336
|
+
this.disownCapturesStmt = db.prepare(
|
|
25337
|
+
`UPDATE audit_events SET outbox_owed = NULL
|
|
25338
|
+
WHERE outbox_owed IS NOT NULL
|
|
25339
|
+
AND event_type IN (${CAPTURE_TYPE_LIST})
|
|
25340
|
+
AND started_at < :attachedAt`
|
|
25341
|
+
);
|
|
25342
|
+
this.rearmStmt = db.prepare(
|
|
25343
|
+
`UPDATE audit_events
|
|
25344
|
+
SET synced_at = NULL, sync_failed_at = NULL, sync_failure = NULL
|
|
25345
|
+
WHERE (synced_at > 0
|
|
25346
|
+
OR sync_failure IN ('deployment_refused', 'detached_undelivered'))
|
|
25347
|
+
AND event_type IN (${TYPE_LIST})`
|
|
25348
|
+
);
|
|
25349
|
+
this.claimStmt = db.prepare(
|
|
25350
|
+
`UPDATE history_sync
|
|
25351
|
+
SET owner_pid = :pid, owner_host = :host, acquired_at = :now, heartbeat_at = :now
|
|
25352
|
+
WHERE id = 1
|
|
25353
|
+
AND (owner_pid IS NULL
|
|
25354
|
+
OR heartbeat_at IS NULL
|
|
25355
|
+
OR heartbeat_at < :staleBefore
|
|
25356
|
+
OR heartbeat_at > :now)`
|
|
25357
|
+
);
|
|
25358
|
+
this.heartbeatStmt = db.prepare(
|
|
25359
|
+
`UPDATE history_sync SET heartbeat_at = :now WHERE id = 1 AND owner_pid = :pid`
|
|
25360
|
+
);
|
|
25361
|
+
this.releaseStmt = db.prepare(
|
|
25362
|
+
`UPDATE history_sync
|
|
25363
|
+
SET owner_pid = NULL, owner_host = NULL, acquired_at = NULL, heartbeat_at = NULL
|
|
25364
|
+
WHERE id = 1 AND owner_pid = :pid`
|
|
25365
|
+
);
|
|
25366
|
+
this.closeWindowStmt = db.prepare(
|
|
25367
|
+
`UPDATE audit_events
|
|
25368
|
+
SET synced_at = ${String(SKIPPED)},
|
|
25369
|
+
sync_failed_at = :at,
|
|
25370
|
+
sync_failure = 'detached_undelivered'
|
|
25371
|
+
WHERE synced_at IS NULL
|
|
25372
|
+
AND event_type IN (${TYPE_LIST})
|
|
25373
|
+
AND started_at >= :attachedAt`
|
|
25374
|
+
);
|
|
25375
|
+
this.releaseBoundaryStmt = db.prepare(
|
|
25376
|
+
`UPDATE history_sync SET backlog_before = NULL WHERE id = 1`
|
|
25377
|
+
);
|
|
25378
|
+
this.freezeBoundaryStmt = db.prepare(
|
|
25379
|
+
`UPDATE history_sync SET backlog_before = :backlogBefore WHERE id = 1`
|
|
25380
|
+
);
|
|
25381
|
+
this.leaseStmt = db.prepare(
|
|
25382
|
+
`SELECT owner_pid AS ownerPid, owner_host AS ownerHost,
|
|
25383
|
+
acquired_at AS acquiredAt, heartbeat_at AS heartbeatAt
|
|
25384
|
+
FROM history_sync WHERE id = 1`
|
|
25385
|
+
);
|
|
25386
|
+
this.inspectionsStmt = db.prepare(
|
|
25387
|
+
`SELECT d.rule_id AS ruleId,
|
|
25388
|
+
d.name AS ruleName,
|
|
25389
|
+
d.version AS ruleVersion,
|
|
25390
|
+
d.category AS category,
|
|
25391
|
+
d.severity AS severity,
|
|
25392
|
+
f.span_start AS spanStart,
|
|
25393
|
+
f.span_end AS spanEnd,
|
|
25394
|
+
f.masked_match AS maskedMatch,
|
|
25395
|
+
f.action_taken AS actionTaken,
|
|
25396
|
+
f.confidence AS confidence
|
|
25397
|
+
FROM inspection_findings f
|
|
25398
|
+
JOIN inspection_definitions d ON d.id = f.inspection_definition_id
|
|
25399
|
+
WHERE f.audit_event_id = :auditEventId
|
|
25400
|
+
ORDER BY f.span_start, f.id`
|
|
25401
|
+
);
|
|
24739
25402
|
}
|
|
24740
|
-
|
|
24741
|
-
|
|
25403
|
+
db;
|
|
25404
|
+
ensureRowStmt;
|
|
25405
|
+
sessionsStmt;
|
|
25406
|
+
rowsStmt;
|
|
25407
|
+
stampStmt;
|
|
25408
|
+
countsStmt;
|
|
25409
|
+
fingerprintStmt;
|
|
25410
|
+
setFingerprintStmt;
|
|
25411
|
+
rearmStmt;
|
|
25412
|
+
claimStmt;
|
|
25413
|
+
heartbeatStmt;
|
|
25414
|
+
releaseStmt;
|
|
25415
|
+
leaseStmt;
|
|
25416
|
+
inspectionsStmt;
|
|
25417
|
+
closeWindowStmt;
|
|
25418
|
+
releaseBoundaryStmt;
|
|
25419
|
+
freezeBoundaryStmt;
|
|
25420
|
+
captureRowsStmt;
|
|
25421
|
+
markOwedStmt;
|
|
25422
|
+
markCaptureBacklogOwedStmt;
|
|
25423
|
+
captureSkipCountStmt;
|
|
25424
|
+
disownCapturesStmt;
|
|
25425
|
+
partitionStmt;
|
|
25426
|
+
partitionByKindStmt;
|
|
25427
|
+
claimRowStmt;
|
|
25428
|
+
releaseRowStmt;
|
|
25429
|
+
releaseStaleClaimsStmt;
|
|
25430
|
+
/**
|
|
25431
|
+
* The masked detections recorded against one tool call.
|
|
25432
|
+
*
|
|
25433
|
+
* These travel with the event because a tool call's target is not
|
|
25434
|
+
* re-inspectable from the event alone — unlike a capture, where the text
|
|
25435
|
+
* itself is re-scannable. What crosses is the masked match and the rule that
|
|
25436
|
+
* produced it, never the value.
|
|
25437
|
+
*/
|
|
25438
|
+
inspectionsFor(auditEventId) {
|
|
25439
|
+
return allRows(this.inspectionsStmt, { auditEventId });
|
|
24742
25440
|
}
|
|
24743
|
-
|
|
24744
|
-
|
|
24745
|
-
|
|
24746
|
-
|
|
24747
|
-
|
|
24748
|
-
|
|
24749
|
-
|
|
24750
|
-
|
|
24751
|
-
|
|
24752
|
-
|
|
24753
|
-
|
|
25441
|
+
/**
|
|
25442
|
+
* Sessions with structural rows still to send, oldest first.
|
|
25443
|
+
*
|
|
25444
|
+
* BOUNDED BY THE BACKLOG BOUNDARY, which is the whole correctness of this
|
|
25445
|
+
* read. Anything recorded after the machine attached is the live forward
|
|
25446
|
+
* path's to deliver; this drain exists for what was recorded before it, and a
|
|
25447
|
+
* row both paths send is at best a duplicate request and at worst — for a
|
|
25448
|
+
* session root — an overwrite of the inventory ids the live path resolved.
|
|
25449
|
+
*/
|
|
25450
|
+
pendingSessions(limit, before) {
|
|
25451
|
+
return allRows(this.sessionsStmt, { limit, before }).map(
|
|
25452
|
+
(r) => r.sessionId
|
|
25453
|
+
);
|
|
24754
25454
|
}
|
|
24755
|
-
|
|
24756
|
-
|
|
24757
|
-
|
|
24758
|
-
const marks = [];
|
|
24759
|
-
for (const table2 of ["events", "findings"]) {
|
|
24760
|
-
try {
|
|
24761
|
-
const row = db.prepare(`SELECT count(*) AS n, ifnull(max(rowid), -1) AS hi FROM ${table2}`).get();
|
|
24762
|
-
if (row === void 0) {
|
|
24763
|
-
holdsRows = true;
|
|
24764
|
-
marks.push(`${table2}:unreadable`);
|
|
24765
|
-
continue;
|
|
24766
|
-
}
|
|
24767
|
-
if (row.n > 0) holdsRows = true;
|
|
24768
|
-
marks.push(`${table2}:${String(row.n)}:${String(row.hi)}`);
|
|
24769
|
-
} catch {
|
|
24770
|
-
holdsRows = true;
|
|
24771
|
-
marks.push(`${table2}:unreadable`);
|
|
24772
|
-
}
|
|
25455
|
+
/** One session's undelivered structural rows within the backlog, root first. */
|
|
25456
|
+
pendingRows(sessionId, limit, before) {
|
|
25457
|
+
return allRows(this.rowsStmt, { sessionId, limit, before });
|
|
24773
25458
|
}
|
|
24774
|
-
|
|
24775
|
-
|
|
24776
|
-
|
|
24777
|
-
|
|
24778
|
-
|
|
24779
|
-
|
|
24780
|
-
|
|
24781
|
-
|
|
24782
|
-
|
|
24783
|
-
|
|
24784
|
-
akaWarn(`legacy events/findings backup failed; deferring the drop: ${String(error61)}`);
|
|
24785
|
-
return;
|
|
24786
|
-
}
|
|
25459
|
+
/**
|
|
25460
|
+
* Captures this machine still owes the deployment, oldest first.
|
|
25461
|
+
*
|
|
25462
|
+
* Selected by the `outbox_owed` marker the attached forward path writes, not
|
|
25463
|
+
* by a time window — see captureRowsStmt for why a window could not express
|
|
25464
|
+
* this. `before` is the grace window that leaves a just-recorded capture to
|
|
25465
|
+
* the live path.
|
|
25466
|
+
*/
|
|
25467
|
+
pendingCaptureRows(limit, before) {
|
|
25468
|
+
return allRows(this.captureRowsStmt, { limit, before });
|
|
24787
25469
|
}
|
|
24788
|
-
|
|
25470
|
+
/**
|
|
25471
|
+
* Record that a capture is OWED to the deployment.
|
|
25472
|
+
*
|
|
25473
|
+
* Written by the attached forward path when a live send did not confirm
|
|
25474
|
+
* delivery, and read by the drain as the whole of its eligibility test. It is
|
|
25475
|
+
* a fact rather than an inference: the machine was attached, the send did not
|
|
25476
|
+
* land, so the row is owed — which no time window can state, because the same
|
|
25477
|
+
* window that holds the rows a past attachment left owed also holds every
|
|
25478
|
+
* capture recorded while the machine was DETACHED, and those were never
|
|
25479
|
+
* offered to anyone.
|
|
25480
|
+
*
|
|
25481
|
+
* Idempotent, and never un-set: `markSynced` settling the row is what takes it
|
|
25482
|
+
* out of the drain's read.
|
|
25483
|
+
*/
|
|
25484
|
+
markCaptureOwed(id) {
|
|
25485
|
+
this.markOwedStmt.run({ id });
|
|
25486
|
+
}
|
|
25487
|
+
/**
|
|
25488
|
+
* Mark every capture already on disk as owed, as of `before`.
|
|
25489
|
+
*
|
|
25490
|
+
* The consent-time backfill, called once from `aka attach` when a human
|
|
25491
|
+
* grants existing-history consent — never from an ongoing drain pass, and
|
|
25492
|
+
* never inferred from a boundary that could later move. `before` is the
|
|
25493
|
+
* caller's own "now" at the moment consent was granted, so what this marks
|
|
25494
|
+
* is exactly the backlog the consent prompt already counted, not whatever a
|
|
25495
|
+
* later re-attach or key rotation might widen it to.
|
|
25496
|
+
*
|
|
25497
|
+
* Returns how many rows matched, for the caller to log or test against. Not a
|
|
25498
|
+
* count of NEWLY marked rows — a row still unsynced from an earlier call
|
|
25499
|
+
* matches again and is counted again, the same as `UPDATE`'s own `changes`.
|
|
25500
|
+
*/
|
|
25501
|
+
markCaptureBacklogOwed(before) {
|
|
25502
|
+
return Number(this.markCaptureBacklogOwedStmt.run({ before }).changes);
|
|
25503
|
+
}
|
|
25504
|
+
/**
|
|
25505
|
+
* Record delivery. Called only AFTER the far side has accepted the rows.
|
|
25506
|
+
*
|
|
25507
|
+
* CLEARS any failure reason in the same statement. A row that failed against
|
|
25508
|
+
* one deployment and then landed is delivered, and leaving the reason behind
|
|
25509
|
+
* would leave the store holding two contradictory answers about one row —
|
|
25510
|
+
* with the surface free to render either.
|
|
25511
|
+
*/
|
|
25512
|
+
markSynced(ids, atMs) {
|
|
25513
|
+
this.stampAll(ids, atMs, null);
|
|
25514
|
+
}
|
|
25515
|
+
/**
|
|
25516
|
+
* Record that THIS MACHINE cannot express the row on the wire.
|
|
25517
|
+
*
|
|
25518
|
+
* Reserved for a local defect — a row that cannot be rebuilt into a valid
|
|
25519
|
+
* payload, or a body the client itself refused to send. It fails identically
|
|
25520
|
+
* against every deployment, so it is terminal everywhere and the re-arm leaves
|
|
25521
|
+
* it alone. A row that merely failed to REACH the deployment stays NULL, so it
|
|
25522
|
+
* is retried; marking those would turn one outage into permanent data loss.
|
|
25523
|
+
*/
|
|
25524
|
+
markSkipped(ids, atMs) {
|
|
25525
|
+
this.stampAll(ids, SKIPPED, "payload_invalid", atMs);
|
|
25526
|
+
}
|
|
25527
|
+
/**
|
|
25528
|
+
* Record that THIS DEPLOYMENT refused the row.
|
|
25529
|
+
*
|
|
25530
|
+
* The same sentinel as `markSkipped`, and deliberately so: both stop the row
|
|
25531
|
+
* being re-offered on this lane, and `synced_at` goes on answering whether a
|
|
25532
|
+
* row is outstanding rather than why. What separates them is the reason, and
|
|
25533
|
+
* what the reason buys is the re-arm — a refusal is one deployment's verdict
|
|
25534
|
+
* on one body, so it is terminal only for as long as this machine points at
|
|
25535
|
+
* that deployment, and `rearmFor` clears it when the deployment changes.
|
|
25536
|
+
*
|
|
25537
|
+
* Leaving such a row NULL instead would be worse than the loss it replaces:
|
|
25538
|
+
* these reads carry no cursor, so an unstamped row the deployment refuses is
|
|
25539
|
+
* the head of every subsequent page, and the lane stalls behind it for ever.
|
|
25540
|
+
*/
|
|
25541
|
+
markRefused(ids, atMs) {
|
|
25542
|
+
this.stampAll(ids, SKIPPED, "deployment_refused", atMs);
|
|
25543
|
+
}
|
|
25544
|
+
eachInTransaction(ids, run) {
|
|
25545
|
+
if (ids.length === 0) return;
|
|
24789
25546
|
withTransaction(
|
|
24790
|
-
db,
|
|
25547
|
+
this.db,
|
|
24791
25548
|
() => {
|
|
24792
|
-
|
|
24793
|
-
if (alreadyDropped) return;
|
|
24794
|
-
if (before !== void 0 && readLegacyTables(db).mark !== before.mark) {
|
|
24795
|
-
akaWarn(
|
|
24796
|
-
"legacy events/findings rows changed after the pre-drop snapshot decision; deferring the drop so the next open can copy them first."
|
|
24797
|
-
);
|
|
24798
|
-
return;
|
|
24799
|
-
}
|
|
24800
|
-
for (const statement of splitStatements(migration.sql)) {
|
|
24801
|
-
db.exec(statement);
|
|
24802
|
-
}
|
|
24803
|
-
db.prepare("INSERT OR IGNORE INTO migration_ledger (tag, applied_at) VALUES (?, ?)").run(
|
|
24804
|
-
migration.tag,
|
|
24805
|
-
Date.now()
|
|
24806
|
-
);
|
|
25549
|
+
for (const id of ids) run(id);
|
|
24807
25550
|
},
|
|
24808
25551
|
"IMMEDIATE"
|
|
24809
25552
|
);
|
|
24810
|
-
} catch (error61) {
|
|
24811
|
-
akaWarn(`legacy events/findings drop failed; deferring: ${String(error61)}`);
|
|
24812
25553
|
}
|
|
24813
|
-
|
|
24814
|
-
|
|
24815
|
-
|
|
24816
|
-
|
|
24817
|
-
|
|
24818
|
-
|
|
24819
|
-
}
|
|
24820
|
-
|
|
24821
|
-
|
|
24822
|
-
|
|
24823
|
-
|
|
24824
|
-
|
|
24825
|
-
|
|
24826
|
-
|
|
25554
|
+
stampAll(ids, value, failure, failedAtMs) {
|
|
25555
|
+
if (ids.length === 0) return;
|
|
25556
|
+
const failedAt = failure === null ? null : failedAtMs ?? null;
|
|
25557
|
+
withTransaction(
|
|
25558
|
+
this.db,
|
|
25559
|
+
() => {
|
|
25560
|
+
for (const id of ids) this.stampStmt.run({ at: value, failedAt, failure, id });
|
|
25561
|
+
},
|
|
25562
|
+
"IMMEDIATE"
|
|
25563
|
+
);
|
|
25564
|
+
}
|
|
25565
|
+
/**
|
|
25566
|
+
* Claim rows as in-flight.
|
|
25567
|
+
*
|
|
25568
|
+
* Advisory in exactly the sense the lease is: it records that a send is in
|
|
25569
|
+
* progress so a surface can say so, and a lost claim costs a row showing as
|
|
25570
|
+
* queued while it is actually being sent. It is not exclusion — the far side
|
|
25571
|
+
* settles a duplicate on the row id.
|
|
25572
|
+
*/
|
|
25573
|
+
claimRows(ids, atMs) {
|
|
25574
|
+
this.eachInTransaction(ids, (id) => this.claimRowStmt.run({ at: atMs, id }));
|
|
25575
|
+
}
|
|
25576
|
+
/** Give back a claim without settling — the send failed, the row is queued again. */
|
|
25577
|
+
releaseRows(ids) {
|
|
25578
|
+
this.eachInTransaction(ids, (id) => this.releaseRowStmt.run({ id }));
|
|
25579
|
+
}
|
|
25580
|
+
/**
|
|
25581
|
+
* Clear claims older than `staleBefore`, and report how many were cleared.
|
|
25582
|
+
*
|
|
25583
|
+
* A process killed between claiming and settling leaves rows claimed with
|
|
25584
|
+
* nothing left to settle them. Without this they read as "sending" for ever.
|
|
25585
|
+
*/
|
|
25586
|
+
releaseStaleClaims(staleBefore) {
|
|
25587
|
+
return Number(this.releaseStaleClaimsStmt.run({ staleBefore }).changes);
|
|
25588
|
+
}
|
|
25589
|
+
/**
|
|
25590
|
+
* Every tracked row in exactly one delivery state.
|
|
25591
|
+
*
|
|
25592
|
+
* Takes no boundary on purpose. The boundary answers "what should the drain
|
|
25593
|
+
* pick up now", which is a different question from "what state is this row
|
|
25594
|
+
* in" — and a machine that has never attached has no boundary to pass, so
|
|
25595
|
+
* requiring one would force a caller to invent one and report the whole store
|
|
25596
|
+
* as queued.
|
|
25597
|
+
*/
|
|
25598
|
+
/**
|
|
25599
|
+
* The same partition, one row per kind that a lane carries.
|
|
25600
|
+
*
|
|
25601
|
+
* A kind with nothing to report is ABSENT rather than a row of zeros: the
|
|
25602
|
+
* scope decides which rows exist at all, so a kind that has never been
|
|
25603
|
+
* recorded — or whose captures nobody ever owed — produces no group. A caller
|
|
25604
|
+
* rendering a fixed list of kinds must therefore treat a missing one as "no
|
|
25605
|
+
* rows", never as "zero sent"; the two look identical in a bar and mean
|
|
25606
|
+
* different things.
|
|
25607
|
+
*/
|
|
25608
|
+
partitionByKind() {
|
|
25609
|
+
return allRows(
|
|
25610
|
+
this.partitionByKindStmt,
|
|
25611
|
+
{}
|
|
25612
|
+
).map((row) => ({
|
|
25613
|
+
kind: row.kind,
|
|
25614
|
+
queued: row.queued ?? 0,
|
|
25615
|
+
inProgress: row.inProgress ?? 0,
|
|
25616
|
+
synced: row.synced ?? 0,
|
|
25617
|
+
failed: row.failed ?? 0,
|
|
25618
|
+
refused: row.refused ?? 0,
|
|
25619
|
+
detached: row.detached ?? 0,
|
|
25620
|
+
total: row.total ?? 0
|
|
25621
|
+
}));
|
|
25622
|
+
}
|
|
25623
|
+
partition() {
|
|
25624
|
+
const row = getRow(this.partitionStmt, {});
|
|
25625
|
+
return {
|
|
25626
|
+
queued: row?.queued ?? 0,
|
|
25627
|
+
inProgress: row?.inProgress ?? 0,
|
|
25628
|
+
synced: row?.synced ?? 0,
|
|
25629
|
+
failed: row?.failed ?? 0,
|
|
25630
|
+
refused: row?.refused ?? 0,
|
|
25631
|
+
detached: row?.detached ?? 0,
|
|
25632
|
+
total: row?.total ?? 0
|
|
25633
|
+
};
|
|
25634
|
+
}
|
|
25635
|
+
/** `pending` counts only what is inside the backlog; sent and skipped are totals. */
|
|
25636
|
+
counts(before) {
|
|
25637
|
+
const row = getRow(this.countsStmt, { before });
|
|
25638
|
+
const captures = getRow(this.captureSkipCountStmt);
|
|
25639
|
+
return {
|
|
25640
|
+
pending: row?.pending ?? 0,
|
|
25641
|
+
sent: row?.sent ?? 0,
|
|
25642
|
+
skipped: row?.skipped ?? 0,
|
|
25643
|
+
refused: row?.refused ?? 0,
|
|
25644
|
+
detached: row?.detached ?? 0,
|
|
25645
|
+
capturesSkipped: captures?.skipped ?? 0
|
|
25646
|
+
};
|
|
25647
|
+
}
|
|
25648
|
+
/**
|
|
25649
|
+
* The deployment the current stamps were made against, and where its backlog
|
|
25650
|
+
* ends.
|
|
25651
|
+
*
|
|
25652
|
+
* READ-ONLY. An absent row reads as an absent deployment, which is what a
|
|
25653
|
+
* machine that has never drained is — and every writer below seeds the row
|
|
25654
|
+
* before it needs one, so nothing depends on this creating it. Keeping the
|
|
25655
|
+
* write off the gate path matters because the gate runs on every pass while a
|
|
25656
|
+
* write has to take the database's write lock.
|
|
25657
|
+
*/
|
|
25658
|
+
deployment() {
|
|
25659
|
+
const row = getRow(
|
|
25660
|
+
this.fingerprintStmt
|
|
25661
|
+
);
|
|
25662
|
+
return {
|
|
25663
|
+
fingerprint: row?.fingerprint ?? void 0,
|
|
25664
|
+
backlogBefore: row?.backlogBefore ?? void 0
|
|
25665
|
+
};
|
|
25666
|
+
}
|
|
25667
|
+
/**
|
|
25668
|
+
* Point the ledger at a different deployment, discarding what it recorded
|
|
25669
|
+
* about the previous one.
|
|
25670
|
+
*
|
|
25671
|
+
* Delivery is a fact about ONE recipient: rows sent to the deployment a
|
|
25672
|
+
* machine has just left are undelivered as far as the new one is concerned.
|
|
25673
|
+
* All four in one transaction, so a crash between them cannot leave stamps
|
|
25674
|
+
* attributed to the wrong deployment, a boundary that belongs to another, or
|
|
25675
|
+
* a disown with no re-mark to follow it.
|
|
25676
|
+
*
|
|
25677
|
+
* The boundary is written HERE and only here, which is what freezes it: a
|
|
25678
|
+
* re-attach to the SAME deployment (a key rotation) leaves the fingerprint
|
|
25679
|
+
* unchanged, so this never runs and the backlog does not widen back over rows
|
|
25680
|
+
* the live path has since delivered.
|
|
25681
|
+
*
|
|
25682
|
+
* `backfillCapturesBefore` is the caller's OWN "now" at the instant a human
|
|
25683
|
+
* granted existing-history consent for the deployment this call is arming —
|
|
25684
|
+
* a DIFFERENT instant from `backlogBefore`: the re-mark boundary is the GRANT
|
|
25685
|
+
* instant, `backlogBefore` is the ATTACH instant, and the two can be far
|
|
25686
|
+
* apart. Passed only when that grant is valid, since this method has no way
|
|
25687
|
+
* to check consent itself and must not mark a row owed for a machine that
|
|
25688
|
+
* never agreed to it. Applied AFTER the disown above, in the SAME
|
|
25689
|
+
* transaction: what the disown clears is every marker below `backlogBefore`,
|
|
25690
|
+
* which includes this deployment's OWN pre-attach rows — `aka attach` calls
|
|
25691
|
+
* `seedCaptureBacklogOwed` at the attach instant, so every row it marks sits
|
|
25692
|
+
* on the cleared side of that bound — and the re-mark in the same
|
|
25693
|
+
* transaction is what puts those rows back. A crash between the two cannot
|
|
25694
|
+
* strand the ledger disowned with nothing re-marked — the transaction either
|
|
25695
|
+
* lands whole or not at all, and a fingerprint mismatch that has not yet
|
|
25696
|
+
* committed re-enters this method on the very next pass. Omit it (the
|
|
25697
|
+
* structural-only tests do) to exercise the disown in isolation.
|
|
25698
|
+
*
|
|
25699
|
+
* The disown is bounded by `backlogBefore`, which is what keeps it from
|
|
25700
|
+
* touching a marker the NEW deployment's OWN live path has already set: B's
|
|
25701
|
+
* live path can mark a capture owed from the moment `aka attach` writes the
|
|
25702
|
+
* descriptor, before the drain's first pass ever reaches this method, and
|
|
25703
|
+
* such a row sits at or after the bound rather than below it. What keeps the
|
|
25704
|
+
* disown from eating THIS SAME CALL's own re-mark is the order, not the
|
|
25705
|
+
* bound — disown runs first, re-mark second, both inside the one
|
|
25706
|
+
* transaction above.
|
|
25707
|
+
*/
|
|
25708
|
+
rearmFor(fingerprint, backlogBefore, backfillCapturesBefore) {
|
|
25709
|
+
this.ensureRowStmt.run();
|
|
25710
|
+
withTransaction(
|
|
25711
|
+
this.db,
|
|
25712
|
+
() => {
|
|
25713
|
+
const previous = getRow(this.fingerprintStmt)?.fingerprint;
|
|
25714
|
+
this.rearmStmt.run();
|
|
25715
|
+
if (previous !== null && previous !== void 0 && previous !== fingerprint) {
|
|
25716
|
+
this.disownCapturesStmt.run({ attachedAt: backlogBefore });
|
|
25717
|
+
}
|
|
25718
|
+
if (backfillCapturesBefore !== void 0) {
|
|
25719
|
+
this.markCaptureBacklogOwedStmt.run({ before: backfillCapturesBefore });
|
|
25720
|
+
}
|
|
25721
|
+
this.setFingerprintStmt.run({ fingerprint, backlogBefore });
|
|
25722
|
+
},
|
|
25723
|
+
"IMMEDIATE"
|
|
25724
|
+
);
|
|
25725
|
+
}
|
|
25726
|
+
/**
|
|
25727
|
+
* End the attached period: hand its rows to the live path, and release the
|
|
25728
|
+
* boundary so the next attachment can freeze a new one.
|
|
25729
|
+
*
|
|
25730
|
+
* WITHOUT THIS, a detach and a re-attach to the same deployment leave a window
|
|
25731
|
+
* nothing delivers. The fingerprint is unchanged, so the boundary is never
|
|
25732
|
+
* re-frozen and stays at the FIRST attachment — while nothing forwards at all
|
|
25733
|
+
* during the detached period, because the machine is not attached. Rows
|
|
25734
|
+
* recorded in that window sit after the boundary and before the re-attach, so
|
|
25735
|
+
* neither path takes them, and the pending count reports none outstanding.
|
|
25736
|
+
*
|
|
25737
|
+
* WHAT IT RECORDS, and what it deliberately does not. These rows were the
|
|
25738
|
+
* closing attachment's to deliver and are no longer outstanding — that is what
|
|
25739
|
+
* lets the boundary move. It is NOT a claim that any of them arrived, and the
|
|
25740
|
+
* distinction is not academic: this used to write a delivery TIME, which every
|
|
25741
|
+
* read treats as delivery, so one detach turned a window of undelivered rows
|
|
25742
|
+
* into a window of delivered ones and no surface could tell. It writes the
|
|
25743
|
+
* skip sentinel and a reason of its own instead, so "no longer owed" and
|
|
25744
|
+
* "received" stop being the same fact.
|
|
25745
|
+
*
|
|
25746
|
+
* A change of deployment still frees them (see the re-arm), because the next
|
|
25747
|
+
* deployment has seen none of this machine's history — so the rows reach it
|
|
25748
|
+
* exactly as they did when this wrote a delivery time.
|
|
25749
|
+
*
|
|
25750
|
+
* ONE TRANSACTION, so a crash cannot release the boundary while leaving the
|
|
25751
|
+
* window unstamped — that half-state would re-send the whole attached period
|
|
25752
|
+
* on the next attach, which is the failure the boundary exists to prevent.
|
|
25753
|
+
*/
|
|
25754
|
+
closeAttachedWindow(attachedAtMs, atMs) {
|
|
25755
|
+
this.ensureRowStmt.run();
|
|
25756
|
+
withTransaction(
|
|
25757
|
+
this.db,
|
|
25758
|
+
() => {
|
|
25759
|
+
const row = getRow(this.fingerprintStmt);
|
|
25760
|
+
const from = row?.backlogBefore ?? attachedAtMs;
|
|
25761
|
+
this.closeWindowStmt.run({ at: atMs, attachedAt: from });
|
|
25762
|
+
this.releaseBoundaryStmt.run();
|
|
25763
|
+
},
|
|
25764
|
+
"IMMEDIATE"
|
|
25765
|
+
);
|
|
25766
|
+
}
|
|
25767
|
+
/**
|
|
25768
|
+
* Freeze a boundary for the deployment already on file, KEEPING the stamps.
|
|
25769
|
+
*
|
|
25770
|
+
* The re-attach half of the above. Distinct from `rearmFor`, which is for a
|
|
25771
|
+
* different deployment and therefore discards what was delivered to the old
|
|
25772
|
+
* one: here the recipient is the same, so everything already sent to it stays
|
|
25773
|
+
* sent.
|
|
25774
|
+
*/
|
|
25775
|
+
freezeBoundary(backlogBefore) {
|
|
25776
|
+
this.ensureRowStmt.run();
|
|
25777
|
+
this.freezeBoundaryStmt.run({ backlogBefore });
|
|
25778
|
+
}
|
|
25779
|
+
/** Take the claim, or report that someone live already holds it. */
|
|
25780
|
+
claim(pid, host, nowMs, staleAfterMs) {
|
|
25781
|
+
this.ensureRowStmt.run();
|
|
25782
|
+
let taken = false;
|
|
25783
|
+
withTransaction(
|
|
25784
|
+
this.db,
|
|
25785
|
+
() => {
|
|
25786
|
+
const result = this.claimStmt.run({
|
|
25787
|
+
pid,
|
|
25788
|
+
host,
|
|
25789
|
+
now: nowMs,
|
|
25790
|
+
staleBefore: nowMs - staleAfterMs
|
|
25791
|
+
});
|
|
25792
|
+
taken = result.changes === 1;
|
|
25793
|
+
},
|
|
25794
|
+
"IMMEDIATE"
|
|
25795
|
+
);
|
|
25796
|
+
return taken;
|
|
25797
|
+
}
|
|
25798
|
+
/** Say the holder is still alive. A no-op once the claim has moved on. */
|
|
25799
|
+
heartbeat(pid, nowMs) {
|
|
25800
|
+
this.heartbeatStmt.run({ now: nowMs, pid });
|
|
25801
|
+
}
|
|
25802
|
+
/** Give the claim up. Scoped to this holder, so a taken-over claim is left be. */
|
|
25803
|
+
release(pid) {
|
|
25804
|
+
this.releaseStmt.run({ pid });
|
|
25805
|
+
}
|
|
25806
|
+
/** Who holds the claim, if anyone. Read-only, for the same reason as above. */
|
|
25807
|
+
lease() {
|
|
25808
|
+
return getRow(this.leaseStmt);
|
|
25809
|
+
}
|
|
25810
|
+
};
|
|
25811
|
+
|
|
25812
|
+
// ../../packages/persistence/src/migrations.ts
|
|
25813
|
+
function describeObject(object2) {
|
|
25814
|
+
return object2.kind === "column" ? `column ${object2.table}.${object2.name}` : `table ${object2.name}`;
|
|
25815
|
+
}
|
|
25816
|
+
function splitStatements(sql) {
|
|
25817
|
+
return sql.split(/-->\s*statement-breakpoint/).map((s) => s.trim()).filter((s) => s.length > 0);
|
|
25818
|
+
}
|
|
25819
|
+
function createdIndexName(statement) {
|
|
25820
|
+
const body = statement.replace(/^(?:\s*--[^\n]*\n?)+/, "").trimStart();
|
|
25821
|
+
return /^CREATE (?:UNIQUE )?INDEX (?:IF NOT EXISTS )?`([^`]+)`/.exec(body)?.[1];
|
|
25822
|
+
}
|
|
25823
|
+
var LEGACY_DROP_MIGRATION_TAG = "0014_drop_legacy_events_findings";
|
|
25824
|
+
function applyMigrations(db, file2, options = {}) {
|
|
25825
|
+
const legacyCount = db.prepare("PRAGMA user_version").get().user_version;
|
|
25826
|
+
db.exec(
|
|
25827
|
+
"CREATE TABLE IF NOT EXISTS migration_ledger (tag TEXT PRIMARY KEY, applied_at INTEGER NOT NULL)"
|
|
25828
|
+
);
|
|
25829
|
+
const applied = new Set(
|
|
25830
|
+
db.prepare("SELECT tag FROM migration_ledger").all().map((r) => r.tag)
|
|
25831
|
+
);
|
|
25832
|
+
const preLedgerStore = applied.size === 0 && legacyCount > 0;
|
|
25833
|
+
const record2 = db.prepare(
|
|
25834
|
+
"INSERT OR IGNORE INTO migration_ledger (tag, applied_at) VALUES (?, ?)"
|
|
25835
|
+
);
|
|
25836
|
+
for (const [index, migration] of SQLITE_MIGRATIONS.entries()) {
|
|
25837
|
+
if (applied.has(migration.tag)) continue;
|
|
25838
|
+
if (options.skipTags?.has(migration.tag) === true) continue;
|
|
25839
|
+
if (migration.tag === LEGACY_DROP_MIGRATION_TAG) continue;
|
|
25840
|
+
const evidence = evidenceObjects(migration.sql);
|
|
25841
|
+
const present = evidence.filter((o) => evidenceExists(db, o));
|
|
25842
|
+
if (present.length > 0 && present.length < evidence.length) {
|
|
25843
|
+
const missing = evidence.filter((o) => !present.includes(o));
|
|
25844
|
+
const message = `sqlite migration ${migration.tag} has no ledger row, but the store already has ${present.map(describeObject).join(", ")} while missing ${missing.map(describeObject).join(", ")} \u2014 the schema diverged from the migration history; refusing to replay or skip.`;
|
|
25845
|
+
akaWarn(message);
|
|
25846
|
+
throw new Error(`[aka] ${message}`);
|
|
25847
|
+
}
|
|
25848
|
+
const alreadyApplied = evidence.length > 0 ? present.length === evidence.length : preLedgerStore && index < legacyCount;
|
|
25849
|
+
const wantsFkOff = /PRAGMA foreign_keys\s*=\s*OFF/i.test(migration.sql);
|
|
25850
|
+
const statements = splitStatements(migration.sql);
|
|
25851
|
+
if (wantsFkOff) db.exec("PRAGMA foreign_keys = OFF");
|
|
25852
|
+
try {
|
|
25853
|
+
withTransaction(
|
|
25854
|
+
db,
|
|
25855
|
+
() => {
|
|
25856
|
+
for (const statement of statements) {
|
|
25857
|
+
const indexName = createdIndexName(statement);
|
|
25858
|
+
if (indexName === void 0) {
|
|
25859
|
+
if (alreadyApplied) continue;
|
|
25860
|
+
} else if (indexExists(db, indexName)) {
|
|
25861
|
+
continue;
|
|
25862
|
+
}
|
|
25863
|
+
db.exec(statement);
|
|
25864
|
+
}
|
|
25865
|
+
if (wantsFkOff && !alreadyApplied) {
|
|
25866
|
+
const violations = db.prepare("PRAGMA foreign_key_check").all();
|
|
25867
|
+
if (violations.length > 0) {
|
|
25868
|
+
throw new Error(
|
|
25869
|
+
`[aka] sqlite migration ${migration.tag} left ${String(violations.length)} foreign-key violation(s); rolling back.`
|
|
25870
|
+
);
|
|
25871
|
+
}
|
|
25872
|
+
}
|
|
25873
|
+
record2.run(migration.tag, Date.now());
|
|
25874
|
+
},
|
|
25875
|
+
"IMMEDIATE"
|
|
25876
|
+
);
|
|
25877
|
+
} finally {
|
|
25878
|
+
if (wantsFkOff) db.exec("PRAGMA foreign_keys = ON");
|
|
25879
|
+
}
|
|
25880
|
+
}
|
|
25881
|
+
if (legacyCount < SQLITE_MIGRATIONS.length) {
|
|
25882
|
+
db.exec(`PRAGMA user_version = ${String(SQLITE_MIGRATIONS.length)}`);
|
|
25883
|
+
}
|
|
25884
|
+
ensureSyncedAtColumn(db, "audit_events");
|
|
25885
|
+
ensureScanLedgerTable(db);
|
|
25886
|
+
ensureHistorySyncTable(db);
|
|
25887
|
+
ensureBlockedDetectionsTable(db);
|
|
25888
|
+
ensureRuleProbeCacheTable(db);
|
|
25889
|
+
ensureWriteGateTrigger(db);
|
|
25890
|
+
ensureTokenUsageColumns(db);
|
|
25891
|
+
reconcileSourceProjectIds(db);
|
|
25892
|
+
if (!applied.has(LEGACY_DROP_MIGRATION_TAG)) {
|
|
25893
|
+
const drained = runLegacyHistoryBackfill(db);
|
|
25894
|
+
if (drained) applyLegacyDropMigration(db, file2);
|
|
25895
|
+
}
|
|
25896
|
+
}
|
|
25897
|
+
function readLegacyTables(db) {
|
|
25898
|
+
let holdsRows = false;
|
|
25899
|
+
const marks = [];
|
|
25900
|
+
for (const table2 of ["events", "findings"]) {
|
|
25901
|
+
try {
|
|
25902
|
+
const row = db.prepare(`SELECT count(*) AS n, ifnull(max(rowid), -1) AS hi FROM ${table2}`).get();
|
|
25903
|
+
if (row === void 0) {
|
|
25904
|
+
holdsRows = true;
|
|
25905
|
+
marks.push(`${table2}:unreadable`);
|
|
25906
|
+
continue;
|
|
25907
|
+
}
|
|
25908
|
+
if (row.n > 0) holdsRows = true;
|
|
25909
|
+
marks.push(`${table2}:${String(row.n)}:${String(row.hi)}`);
|
|
25910
|
+
} catch {
|
|
25911
|
+
holdsRows = true;
|
|
25912
|
+
marks.push(`${table2}:unreadable`);
|
|
25913
|
+
}
|
|
25914
|
+
}
|
|
25915
|
+
return { holdsRows, mark: marks.join("|") };
|
|
25916
|
+
}
|
|
25917
|
+
function applyLegacyDropMigration(db, file2) {
|
|
25918
|
+
const migration = SQLITE_MIGRATIONS.find((m) => m.tag === LEGACY_DROP_MIGRATION_TAG);
|
|
25919
|
+
if (!migration) return;
|
|
25920
|
+
const before = file2 === void 0 ? void 0 : readLegacyTables(db);
|
|
25921
|
+
if (file2 !== void 0 && before?.holdsRows === true) {
|
|
25922
|
+
try {
|
|
25923
|
+
backupBeforeLegacyDrop(db, file2);
|
|
25924
|
+
} catch (error61) {
|
|
25925
|
+
akaWarn(`legacy events/findings backup failed; deferring the drop: ${String(error61)}`);
|
|
25926
|
+
return;
|
|
25927
|
+
}
|
|
25928
|
+
}
|
|
25929
|
+
try {
|
|
25930
|
+
withTransaction(
|
|
25931
|
+
db,
|
|
25932
|
+
() => {
|
|
25933
|
+
const alreadyDropped = db.prepare("SELECT 1 FROM migration_ledger WHERE tag = ?").get(migration.tag);
|
|
25934
|
+
if (alreadyDropped) return;
|
|
25935
|
+
if (before !== void 0 && readLegacyTables(db).mark !== before.mark) {
|
|
25936
|
+
akaWarn(
|
|
25937
|
+
"legacy events/findings rows changed after the pre-drop snapshot decision; deferring the drop so the next open can copy them first."
|
|
25938
|
+
);
|
|
25939
|
+
return;
|
|
25940
|
+
}
|
|
25941
|
+
for (const statement of splitStatements(migration.sql)) {
|
|
25942
|
+
db.exec(statement);
|
|
25943
|
+
}
|
|
25944
|
+
db.prepare("INSERT OR IGNORE INTO migration_ledger (tag, applied_at) VALUES (?, ?)").run(
|
|
25945
|
+
migration.tag,
|
|
25946
|
+
Date.now()
|
|
25947
|
+
);
|
|
25948
|
+
},
|
|
25949
|
+
"IMMEDIATE"
|
|
25950
|
+
);
|
|
25951
|
+
} catch (error61) {
|
|
25952
|
+
akaWarn(`legacy events/findings drop failed; deferring: ${String(error61)}`);
|
|
25953
|
+
}
|
|
25954
|
+
}
|
|
25955
|
+
function backupBeforeLegacyDrop(db, file2) {
|
|
25956
|
+
reapStalePartials(file2);
|
|
25957
|
+
const backup = backupPath(file2, "pre-drop");
|
|
25958
|
+
snapshotStore(db, backup);
|
|
25959
|
+
return backup;
|
|
25960
|
+
}
|
|
25961
|
+
var TOKEN_USAGE_COLUMNS = [
|
|
25962
|
+
{
|
|
25963
|
+
name: "input_tokens",
|
|
25964
|
+
ddl: "ALTER TABLE audit_events ADD COLUMN input_tokens integer GENERATED ALWAYS AS (json_extract(attributes, '$.input_tokens')) VIRTUAL"
|
|
25965
|
+
},
|
|
25966
|
+
{
|
|
25967
|
+
name: "output_tokens",
|
|
24827
25968
|
ddl: "ALTER TABLE audit_events ADD COLUMN output_tokens integer GENERATED ALWAYS AS (json_extract(attributes, '$.output_tokens')) VIRTUAL"
|
|
24828
25969
|
},
|
|
24829
25970
|
{
|
|
@@ -25101,10 +26242,62 @@ function ensureSyncedAtColumn(db, table2) {
|
|
|
25101
26242
|
if (!columns.includes("outbox_owed")) {
|
|
25102
26243
|
db.exec(`ALTER TABLE ${table2} ADD COLUMN outbox_owed integer`);
|
|
25103
26244
|
}
|
|
26245
|
+
if (!columns.includes("sync_failed_at")) {
|
|
26246
|
+
db.exec(`ALTER TABLE ${table2} ADD COLUMN sync_failed_at integer`);
|
|
26247
|
+
}
|
|
26248
|
+
if (!columns.includes("sync_failure")) {
|
|
26249
|
+
withTransaction(
|
|
26250
|
+
db,
|
|
26251
|
+
() => {
|
|
26252
|
+
db.exec(`ALTER TABLE ${table2} ADD COLUMN sync_failure text`);
|
|
26253
|
+
db.exec(
|
|
26254
|
+
`UPDATE ${table2} SET synced_at = NULL
|
|
26255
|
+
WHERE synced_at = -1
|
|
26256
|
+
AND event_type IN (${COUNTED_EVENT_TYPES.map((t) => `'${t}'`).join(", ")})`
|
|
26257
|
+
);
|
|
26258
|
+
},
|
|
26259
|
+
"IMMEDIATE"
|
|
26260
|
+
);
|
|
26261
|
+
}
|
|
25104
26262
|
db.exec(
|
|
25105
|
-
`CREATE
|
|
25106
|
-
|
|
26263
|
+
`CREATE TRIGGER IF NOT EXISTS aka_sync_failure_guard
|
|
26264
|
+
BEFORE UPDATE OF sync_failure ON ${table2}
|
|
26265
|
+
WHEN ${syncFailureRejectCondition()}
|
|
26266
|
+
BEGIN SELECT RAISE(ABORT, 'sync_failure is not one of the recorded reasons'); END`
|
|
25107
26267
|
);
|
|
26268
|
+
const syncIndexColumns = [
|
|
26269
|
+
"event_type",
|
|
26270
|
+
"synced_at",
|
|
26271
|
+
"sync_claimed_at",
|
|
26272
|
+
"started_at",
|
|
26273
|
+
// Appended LAST on purpose. The delivery-state read now projects it, so it
|
|
26274
|
+
// has to be in the index for the read to stay covered — but putting it
|
|
26275
|
+
// ahead of `started_at` would reorder the prefix the structural drain's
|
|
26276
|
+
// reads match on.
|
|
26277
|
+
"sync_failure"
|
|
26278
|
+
// `outbox_owed` is DELIBERATELY ABSENT, and it was measured both ways.
|
|
26279
|
+
//
|
|
26280
|
+
// The delivery-state read tests it — a capture's state depends on whether a
|
|
26281
|
+
// live forward marked it owed — so carrying it here makes that read covering
|
|
26282
|
+
// rather than a row fetch per row: 16 ms against 40 ms on a real 6 GB store.
|
|
26283
|
+
// But a sixth column changes what the planner charges for this index, and
|
|
26284
|
+
// with no ANALYZE statistics it plans from schema shape alone: measured, it
|
|
26285
|
+
// then stops choosing the per-session index for the token rollup and walks
|
|
26286
|
+
// every `llm_call` in the store through the event-type index instead. That
|
|
26287
|
+
// read grows with the store; this one does not.
|
|
26288
|
+
//
|
|
26289
|
+
// 40 ms on the largest store measured, once per render, is a cost worth
|
|
26290
|
+
// paying to leave every other read's plan where it was.
|
|
26291
|
+
];
|
|
26292
|
+
const currentSyncIndex = indexColumns(db, "idx_audit_events_sync");
|
|
26293
|
+
const syncIndexMatches = currentSyncIndex.length === syncIndexColumns.length && currentSyncIndex.every((column, i) => column === syncIndexColumns[i]);
|
|
26294
|
+
if (!syncIndexMatches) {
|
|
26295
|
+
db.exec("DROP INDEX IF EXISTS idx_audit_events_sync");
|
|
26296
|
+
db.exec(
|
|
26297
|
+
`CREATE INDEX idx_audit_events_sync
|
|
26298
|
+
ON audit_events (${syncIndexColumns.join(", ")})`
|
|
26299
|
+
);
|
|
26300
|
+
}
|
|
25108
26301
|
db.exec(
|
|
25109
26302
|
`CREATE INDEX IF NOT EXISTS idx_audit_outbox_owed
|
|
25110
26303
|
ON audit_events (event_type, synced_at, sync_claimed_at, started_at) WHERE outbox_owed = 1`
|
|
@@ -25326,7 +26519,11 @@ function buildAuditEvent(row) {
|
|
|
25326
26519
|
link: linkParsed?.success ? linkParsed.data : null,
|
|
25327
26520
|
targetId: row.target_id,
|
|
25328
26521
|
internal: intToBool(row.internal),
|
|
25329
|
-
flagged: intToBool(row.flagged)
|
|
26522
|
+
flagged: intToBool(row.flagged),
|
|
26523
|
+
// Only meaningful when the title came out empty — a row whose body was
|
|
26524
|
+
// expired but whose title fell back to `tool_name` still has something to
|
|
26525
|
+
// render, and flagging it would make the view apologise for nothing.
|
|
26526
|
+
bodyExpired: row.content_expired_at !== null && (row.title ?? "") === ""
|
|
25330
26527
|
};
|
|
25331
26528
|
}
|
|
25332
26529
|
var TIMELINE_COLUMNS = `
|
|
@@ -25334,6 +26531,7 @@ var TIMELINE_COLUMNS = `
|
|
|
25334
26531
|
event_type,
|
|
25335
26532
|
started_at,
|
|
25336
26533
|
coalesce(content, json_extract(attributes, '$.tool_name')) AS title,
|
|
26534
|
+
content_expired_at,
|
|
25337
26535
|
coalesce(json_extract(attributes, '$.detail'), json_extract(attributes, '$.target')) AS detail,
|
|
25338
26536
|
coalesce(json_extract(attributes, '$.tool_name'), json_extract(attributes, '$.tool')) AS tool,
|
|
25339
26537
|
json_extract(attributes, '$.severity') AS severity,
|
|
@@ -25376,7 +26574,7 @@ var SESSION_ROOT = `event_type = 'session'`;
|
|
|
25376
26574
|
var HAS_ACTIVITY = `EXISTS (
|
|
25377
26575
|
SELECT 1 FROM audit_events c
|
|
25378
26576
|
WHERE c.root_session_id = audit_events.id
|
|
25379
|
-
AND c.event_type NOT IN ('hook', 'config_scan'))`;
|
|
26577
|
+
AND c.event_type NOT IN ('hook', 'config_scan', 'capture_status'))`;
|
|
25380
26578
|
var SqliteActivityRepository = class {
|
|
25381
26579
|
constructor(db, now = () => Date.now()) {
|
|
25382
26580
|
this.db = db;
|
|
@@ -25403,10 +26601,10 @@ var SqliteActivityRepository = class {
|
|
|
25403
26601
|
SELECT id FROM audit_events WHERE event_type = 'session' AND started_at >= ?
|
|
25404
26602
|
UNION
|
|
25405
26603
|
SELECT root_session_id FROM audit_events INDEXED BY idx_audit_started_at
|
|
25406
|
-
WHERE started_at >= ?
|
|
26604
|
+
WHERE started_at >= ? AND event_type <> 'capture_status'
|
|
25407
26605
|
UNION
|
|
25408
26606
|
SELECT root_session_id FROM audit_events INDEXED BY idx_audit_ended_at
|
|
25409
|
-
WHERE ended_at >= ?)`,
|
|
26607
|
+
WHERE ended_at >= ? AND event_type <> 'capture_status')`,
|
|
25410
26608
|
[liveThreshold, liveThreshold, liveThreshold]
|
|
25411
26609
|
);
|
|
25412
26610
|
const toolCallsToday = countScalar(
|
|
@@ -25813,7 +27011,10 @@ var SqliteAuditEventsRepository = class {
|
|
|
25813
27011
|
attributes = excluded.attributes,
|
|
25814
27012
|
ended_at = excluded.ended_at
|
|
25815
27013
|
WHERE COALESCE(json_extract(excluded.attributes, '$.output_tokens'), 0)
|
|
25816
|
-
> 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)`
|
|
25817
27018
|
);
|
|
25818
27019
|
this.upsertSessionRootStmt = db.prepare(
|
|
25819
27020
|
`INSERT OR IGNORE INTO audit_events
|
|
@@ -25999,6 +27200,169 @@ var SqliteAuditEventsRepository = class {
|
|
|
25999
27200
|
}
|
|
26000
27201
|
};
|
|
26001
27202
|
|
|
27203
|
+
// ../../packages/persistence/src/repositories/body-retention.ts
|
|
27204
|
+
var DEFAULT_BATCH_SIZE = 500;
|
|
27205
|
+
var DEFAULT_MAX_ROWS = 5e4;
|
|
27206
|
+
var SYNC_LANE_TYPES_SQL = OUTBOX_CAPTURE_TYPE_LIST;
|
|
27207
|
+
var SqliteBodyRetentionRepository = class {
|
|
27208
|
+
constructor(db) {
|
|
27209
|
+
this.db = db;
|
|
27210
|
+
const select = (laneClause) => `
|
|
27211
|
+
SELECT id, LENGTH(CAST(content AS BLOB)) AS bytes
|
|
27212
|
+
FROM audit_events
|
|
27213
|
+
WHERE content IS NOT NULL
|
|
27214
|
+
AND started_at < :cutoff
|
|
27215
|
+
AND event_type IN (${CAPTURE_EVENT_TYPES_SQL})
|
|
27216
|
+
${laneClause}
|
|
27217
|
+
ORDER BY started_at
|
|
27218
|
+
LIMIT :limit`;
|
|
27219
|
+
this.candidatesStmt = this.db.prepare(select(""));
|
|
27220
|
+
this.candidatesSyncSafeStmt = this.db.prepare(
|
|
27221
|
+
select(`AND (event_type NOT IN (${SYNC_LANE_TYPES_SQL}) OR synced_at IS NOT NULL)`)
|
|
27222
|
+
);
|
|
27223
|
+
this.heldBySyncStmt = this.db.prepare(`
|
|
27224
|
+
SELECT COUNT(*) AS n
|
|
27225
|
+
FROM audit_events
|
|
27226
|
+
WHERE content IS NOT NULL
|
|
27227
|
+
AND started_at < :cutoff
|
|
27228
|
+
AND event_type IN (${SYNC_LANE_TYPES_SQL})
|
|
27229
|
+
AND synced_at IS NULL`);
|
|
27230
|
+
this.expireStmt = this.db.prepare(
|
|
27231
|
+
`UPDATE audit_events SET content = NULL, content_expired_at = :now WHERE id = :id`
|
|
27232
|
+
);
|
|
27233
|
+
}
|
|
27234
|
+
db;
|
|
27235
|
+
candidatesStmt;
|
|
27236
|
+
candidatesSyncSafeStmt;
|
|
27237
|
+
heldBySyncStmt;
|
|
27238
|
+
expireStmt;
|
|
27239
|
+
/** How many bytes a pass with these options would free, changing nothing. */
|
|
27240
|
+
preview(opts) {
|
|
27241
|
+
const limit = opts.maxRows ?? DEFAULT_MAX_ROWS;
|
|
27242
|
+
const stmt = opts.sweepSyncLane ? this.candidatesStmt : this.candidatesSyncSafeStmt;
|
|
27243
|
+
const rows = stmt.all({ cutoff: opts.cutoff, limit });
|
|
27244
|
+
return {
|
|
27245
|
+
rowsExpired: rows.length,
|
|
27246
|
+
bytesFreed: rows.reduce((sum, r) => sum + r.bytes, 0),
|
|
27247
|
+
rowsHeldBySync: this.countHeldBySync(opts)
|
|
27248
|
+
};
|
|
27249
|
+
}
|
|
27250
|
+
/** Clear eligible bodies, in bounded batches. */
|
|
27251
|
+
expire(opts) {
|
|
27252
|
+
const batchSize = opts.batchSize ?? DEFAULT_BATCH_SIZE;
|
|
27253
|
+
const maxRows = opts.maxRows ?? DEFAULT_MAX_ROWS;
|
|
27254
|
+
const stmt = opts.sweepSyncLane ? this.candidatesStmt : this.candidatesSyncSafeStmt;
|
|
27255
|
+
let rowsExpired = 0;
|
|
27256
|
+
let bytesFreed = 0;
|
|
27257
|
+
let done = true;
|
|
27258
|
+
while (rowsExpired < maxRows) {
|
|
27259
|
+
const remaining = Math.min(batchSize, maxRows - rowsExpired);
|
|
27260
|
+
const batch = stmt.all({ cutoff: opts.cutoff, limit: remaining });
|
|
27261
|
+
if (batch.length === 0) break;
|
|
27262
|
+
withTransaction(
|
|
27263
|
+
this.db,
|
|
27264
|
+
() => {
|
|
27265
|
+
for (const row of batch) this.expireStmt.run({ id: row.id, now: opts.now });
|
|
27266
|
+
},
|
|
27267
|
+
"IMMEDIATE"
|
|
27268
|
+
);
|
|
27269
|
+
rowsExpired += batch.length;
|
|
27270
|
+
bytesFreed += batch.reduce((sum, r) => sum + r.bytes, 0);
|
|
27271
|
+
if (batch.length < remaining) break;
|
|
27272
|
+
if (rowsExpired >= maxRows) {
|
|
27273
|
+
done = stmt.all({ cutoff: opts.cutoff, limit: 1 }).length === 0;
|
|
27274
|
+
}
|
|
27275
|
+
}
|
|
27276
|
+
return { rowsExpired, bytesFreed, rowsHeldBySync: this.countHeldBySync(opts), done };
|
|
27277
|
+
}
|
|
27278
|
+
countHeldBySync(opts) {
|
|
27279
|
+
if (opts.sweepSyncLane) return 0;
|
|
27280
|
+
const row = this.heldBySyncStmt.get({ cutoff: opts.cutoff });
|
|
27281
|
+
return row.n;
|
|
27282
|
+
}
|
|
27283
|
+
};
|
|
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
|
+
|
|
26002
27366
|
// ../../packages/persistence/src/repositories/classified-data.ts
|
|
26003
27367
|
var SqliteClassifiedDataRepository = class {
|
|
26004
27368
|
constructor(db) {
|
|
@@ -26827,7 +28191,15 @@ function toFlatFindingRow(r) {
|
|
|
26827
28191
|
...r.tool_name === null ? {} : { toolName: r.tool_name },
|
|
26828
28192
|
eventId: r.event_id,
|
|
26829
28193
|
...r.session_id === null ? {} : { sessionId: r.session_id },
|
|
26830
|
-
status: deriveInstanceStatus(r)
|
|
28194
|
+
status: deriveInstanceStatus(r),
|
|
28195
|
+
delivery: deriveFindingDelivery({
|
|
28196
|
+
kind: r.kind,
|
|
28197
|
+
syncedAt: r.synced_at,
|
|
28198
|
+
syncClaimedAt: r.sync_claimed_at,
|
|
28199
|
+
syncFailedAt: r.sync_failed_at,
|
|
28200
|
+
syncFailure: r.sync_failure,
|
|
28201
|
+
outboxOwed: r.outbox_owed
|
|
28202
|
+
})
|
|
26831
28203
|
};
|
|
26832
28204
|
}
|
|
26833
28205
|
function encodeGroupCursor(group) {
|
|
@@ -26891,7 +28263,10 @@ var FINDING_ROW_COLUMNS_SQL = `f.id AS id, d.rule_id AS rule_id, d.category AS c
|
|
|
26891
28263
|
e.tool_name AS tool_name,
|
|
26892
28264
|
f.audit_event_id AS event_id, e.root_session_id AS session_id,
|
|
26893
28265
|
e.event_type AS kind, f.finding_key AS finding_key,
|
|
26894
|
-
${latestResolutionStatusSql("f")} AS latest_status
|
|
28266
|
+
${latestResolutionStatusSql("f")} AS latest_status,
|
|
28267
|
+
e.synced_at AS synced_at, e.sync_claimed_at AS sync_claimed_at,
|
|
28268
|
+
e.sync_failed_at AS sync_failed_at, e.sync_failure AS sync_failure,
|
|
28269
|
+
e.outbox_owed AS outbox_owed`;
|
|
26895
28270
|
var DAY_MS3 = 864e5;
|
|
26896
28271
|
var SqliteFindingsRepository = class {
|
|
26897
28272
|
constructor(db) {
|
|
@@ -27136,6 +28511,7 @@ var SqliteFindingsRepository = class {
|
|
|
27136
28511
|
providers: query.provider,
|
|
27137
28512
|
actions: query.action,
|
|
27138
28513
|
statuses: query.status,
|
|
28514
|
+
deliveries: query.deployment,
|
|
27139
28515
|
tools: query.tool,
|
|
27140
28516
|
repo: query.repo,
|
|
27141
28517
|
file: query.file,
|
|
@@ -27203,6 +28579,7 @@ var SqliteFindingsRepository = class {
|
|
|
27203
28579
|
providers: query.provider,
|
|
27204
28580
|
actions: query.action,
|
|
27205
28581
|
statuses: query.status,
|
|
28582
|
+
deliveries: query.deployment,
|
|
27206
28583
|
tools: query.tool,
|
|
27207
28584
|
q: query.q
|
|
27208
28585
|
};
|
|
@@ -27466,7 +28843,9 @@ var SqliteFindingsRepository = class {
|
|
|
27466
28843
|
)
|
|
27467
28844
|
);
|
|
27468
28845
|
for (const row of grouped) {
|
|
27469
|
-
if (
|
|
28846
|
+
if (Object.hasOwn(byAction, row.action_taken)) {
|
|
28847
|
+
byAction[row.action_taken] = row.c;
|
|
28848
|
+
}
|
|
27470
28849
|
}
|
|
27471
28850
|
const bySeverity = { critical: 0, high: 0, medium: 0, low: 0 };
|
|
27472
28851
|
const sevRows = allRows(
|
|
@@ -27483,7 +28862,9 @@ var SqliteFindingsRepository = class {
|
|
|
27483
28862
|
)
|
|
27484
28863
|
);
|
|
27485
28864
|
for (const row of sevRows) {
|
|
27486
|
-
if (
|
|
28865
|
+
if (Object.hasOwn(bySeverity, row.severity)) {
|
|
28866
|
+
bySeverity[row.severity] = row.c;
|
|
28867
|
+
}
|
|
27487
28868
|
}
|
|
27488
28869
|
const categories = ENFORCEABLE_CATEGORIES;
|
|
27489
28870
|
const enabledRows = allRows(
|
|
@@ -27532,525 +28913,6 @@ function isoDay(ms) {
|
|
|
27532
28913
|
return new Date(ms).toISOString().slice(0, 10);
|
|
27533
28914
|
}
|
|
27534
28915
|
|
|
27535
|
-
// ../../packages/persistence/src/repositories/history-sync.ts
|
|
27536
|
-
var STRUCTURAL_EVENT_TYPES = ["session", "llm_call", "tool_call"];
|
|
27537
|
-
var TYPE_LIST = STRUCTURAL_EVENT_TYPES.map((t) => `'${t}'`).join(", ");
|
|
27538
|
-
var OUTBOX_CAPTURE_EVENT_TYPES = ["prompt", "response", "tool_use"];
|
|
27539
|
-
var CAPTURE_TYPE_LIST = OUTBOX_CAPTURE_EVENT_TYPES.map((t) => `'${t}'`).join(", ");
|
|
27540
|
-
var SKIPPED = -1;
|
|
27541
|
-
var ROW_COLUMNS = `id,
|
|
27542
|
-
parent_id AS parentId,
|
|
27543
|
-
root_session_id AS rootSessionId,
|
|
27544
|
-
event_type AS eventType,
|
|
27545
|
-
host_id AS hostId,
|
|
27546
|
-
harness_id AS harnessId,
|
|
27547
|
-
source_project_id AS sourceProjectId,
|
|
27548
|
-
started_at AS startedAt,
|
|
27549
|
-
ended_at AS endedAt,
|
|
27550
|
-
severity,
|
|
27551
|
-
priority,
|
|
27552
|
-
content,
|
|
27553
|
-
content_hash AS contentHash,
|
|
27554
|
-
attributes`;
|
|
27555
|
-
var SqliteHistorySyncRepository = class {
|
|
27556
|
-
constructor(db) {
|
|
27557
|
-
this.db = db;
|
|
27558
|
-
this.ensureRowStmt = db.prepare(`INSERT OR IGNORE INTO history_sync (id) VALUES (1)`);
|
|
27559
|
-
this.sessionsStmt = db.prepare(
|
|
27560
|
-
`SELECT COALESCE(root_session_id, id) AS sessionId, MIN(started_at) AS earliest
|
|
27561
|
-
FROM audit_events
|
|
27562
|
-
WHERE synced_at IS NULL
|
|
27563
|
-
AND event_type IN (${TYPE_LIST})
|
|
27564
|
-
AND started_at < :before
|
|
27565
|
-
GROUP BY sessionId
|
|
27566
|
-
ORDER BY earliest
|
|
27567
|
-
LIMIT :limit`
|
|
27568
|
-
);
|
|
27569
|
-
this.rowsStmt = db.prepare(
|
|
27570
|
-
`SELECT ${ROW_COLUMNS}
|
|
27571
|
-
FROM audit_events
|
|
27572
|
-
WHERE synced_at IS NULL
|
|
27573
|
-
AND event_type IN (${TYPE_LIST})
|
|
27574
|
-
AND started_at < :before
|
|
27575
|
-
AND COALESCE(root_session_id, id) = :sessionId
|
|
27576
|
-
ORDER BY (event_type = 'session') DESC, started_at
|
|
27577
|
-
LIMIT :limit`
|
|
27578
|
-
);
|
|
27579
|
-
this.captureRowsStmt = db.prepare(
|
|
27580
|
-
`SELECT ${ROW_COLUMNS}
|
|
27581
|
-
FROM audit_events
|
|
27582
|
-
WHERE synced_at IS NULL
|
|
27583
|
-
AND sync_claimed_at IS NULL
|
|
27584
|
-
AND outbox_owed = 1
|
|
27585
|
-
AND event_type IN (${CAPTURE_TYPE_LIST})
|
|
27586
|
-
AND started_at < :before
|
|
27587
|
-
ORDER BY started_at
|
|
27588
|
-
LIMIT :limit`
|
|
27589
|
-
);
|
|
27590
|
-
this.markOwedStmt = db.prepare(
|
|
27591
|
-
`UPDATE audit_events SET outbox_owed = 1 WHERE id = :id AND synced_at IS NULL`
|
|
27592
|
-
);
|
|
27593
|
-
this.markCaptureBacklogOwedStmt = db.prepare(
|
|
27594
|
-
`UPDATE audit_events SET outbox_owed = 1
|
|
27595
|
-
WHERE synced_at IS NULL
|
|
27596
|
-
AND event_type IN (${CAPTURE_TYPE_LIST})
|
|
27597
|
-
AND started_at < :before`
|
|
27598
|
-
);
|
|
27599
|
-
this.stampStmt = db.prepare(
|
|
27600
|
-
`UPDATE audit_events SET synced_at = :at, sync_claimed_at = NULL WHERE id = :id`
|
|
27601
|
-
);
|
|
27602
|
-
this.claimRowStmt = db.prepare(
|
|
27603
|
-
`UPDATE audit_events SET sync_claimed_at = :at WHERE id = :id AND synced_at IS NULL`
|
|
27604
|
-
);
|
|
27605
|
-
this.releaseRowStmt = db.prepare(
|
|
27606
|
-
`UPDATE audit_events SET sync_claimed_at = NULL WHERE id = :id`
|
|
27607
|
-
);
|
|
27608
|
-
this.releaseStaleClaimsStmt = db.prepare(
|
|
27609
|
-
`UPDATE audit_events SET sync_claimed_at = NULL
|
|
27610
|
-
WHERE sync_claimed_at IS NOT NULL AND sync_claimed_at < :staleBefore`
|
|
27611
|
-
);
|
|
27612
|
-
this.partitionStmt = db.prepare(
|
|
27613
|
-
`SELECT
|
|
27614
|
-
SUM(CASE WHEN synced_at IS NULL AND sync_claimed_at IS NULL THEN 1 ELSE 0 END) AS queued,
|
|
27615
|
-
SUM(CASE WHEN synced_at IS NULL AND sync_claimed_at IS NOT NULL THEN 1 ELSE 0 END) AS inProgress,
|
|
27616
|
-
SUM(CASE WHEN synced_at > 0 THEN 1 ELSE 0 END) AS synced,
|
|
27617
|
-
SUM(CASE WHEN synced_at IS NOT NULL AND synced_at <= 0 THEN 1 ELSE 0 END) AS failed,
|
|
27618
|
-
COUNT(*) AS total
|
|
27619
|
-
FROM audit_events
|
|
27620
|
-
WHERE event_type IN (${TYPE_LIST})`
|
|
27621
|
-
);
|
|
27622
|
-
this.countsStmt = db.prepare(
|
|
27623
|
-
`SELECT
|
|
27624
|
-
SUM(CASE WHEN synced_at IS NULL AND started_at < :before THEN 1 ELSE 0 END) AS pending,
|
|
27625
|
-
SUM(CASE WHEN synced_at > 0 THEN 1 ELSE 0 END) AS sent,
|
|
27626
|
-
SUM(CASE WHEN synced_at = ${String(SKIPPED)} THEN 1 ELSE 0 END) AS skipped
|
|
27627
|
-
FROM audit_events
|
|
27628
|
-
WHERE event_type IN (${TYPE_LIST})`
|
|
27629
|
-
);
|
|
27630
|
-
this.captureSkipCountStmt = db.prepare(
|
|
27631
|
-
`SELECT COUNT(*) AS skipped
|
|
27632
|
-
FROM audit_events
|
|
27633
|
-
WHERE synced_at = ${String(SKIPPED)}
|
|
27634
|
-
AND event_type IN (${CAPTURE_TYPE_LIST})`
|
|
27635
|
-
);
|
|
27636
|
-
this.fingerprintStmt = db.prepare(
|
|
27637
|
-
`SELECT endpoint_fingerprint AS fingerprint, backlog_before AS backlogBefore
|
|
27638
|
-
FROM history_sync WHERE id = 1`
|
|
27639
|
-
);
|
|
27640
|
-
this.setFingerprintStmt = db.prepare(
|
|
27641
|
-
`UPDATE history_sync
|
|
27642
|
-
SET endpoint_fingerprint = :fingerprint, backlog_before = :backlogBefore
|
|
27643
|
-
WHERE id = 1`
|
|
27644
|
-
);
|
|
27645
|
-
this.disownCapturesStmt = db.prepare(
|
|
27646
|
-
`UPDATE audit_events SET outbox_owed = NULL
|
|
27647
|
-
WHERE outbox_owed IS NOT NULL
|
|
27648
|
-
AND event_type IN (${CAPTURE_TYPE_LIST})
|
|
27649
|
-
AND started_at < :attachedAt`
|
|
27650
|
-
);
|
|
27651
|
-
this.rearmStmt = db.prepare(
|
|
27652
|
-
`UPDATE audit_events SET synced_at = NULL
|
|
27653
|
-
WHERE synced_at > 0 AND event_type IN (${TYPE_LIST})`
|
|
27654
|
-
);
|
|
27655
|
-
this.claimStmt = db.prepare(
|
|
27656
|
-
`UPDATE history_sync
|
|
27657
|
-
SET owner_pid = :pid, owner_host = :host, acquired_at = :now, heartbeat_at = :now
|
|
27658
|
-
WHERE id = 1
|
|
27659
|
-
AND (owner_pid IS NULL
|
|
27660
|
-
OR heartbeat_at IS NULL
|
|
27661
|
-
OR heartbeat_at < :staleBefore
|
|
27662
|
-
OR heartbeat_at > :now)`
|
|
27663
|
-
);
|
|
27664
|
-
this.heartbeatStmt = db.prepare(
|
|
27665
|
-
`UPDATE history_sync SET heartbeat_at = :now WHERE id = 1 AND owner_pid = :pid`
|
|
27666
|
-
);
|
|
27667
|
-
this.releaseStmt = db.prepare(
|
|
27668
|
-
`UPDATE history_sync
|
|
27669
|
-
SET owner_pid = NULL, owner_host = NULL, acquired_at = NULL, heartbeat_at = NULL
|
|
27670
|
-
WHERE id = 1 AND owner_pid = :pid`
|
|
27671
|
-
);
|
|
27672
|
-
this.closeWindowStmt = db.prepare(
|
|
27673
|
-
`UPDATE audit_events SET synced_at = :at
|
|
27674
|
-
WHERE synced_at IS NULL
|
|
27675
|
-
AND event_type IN (${TYPE_LIST})
|
|
27676
|
-
AND started_at >= :attachedAt`
|
|
27677
|
-
);
|
|
27678
|
-
this.releaseBoundaryStmt = db.prepare(
|
|
27679
|
-
`UPDATE history_sync SET backlog_before = NULL WHERE id = 1`
|
|
27680
|
-
);
|
|
27681
|
-
this.freezeBoundaryStmt = db.prepare(
|
|
27682
|
-
`UPDATE history_sync SET backlog_before = :backlogBefore WHERE id = 1`
|
|
27683
|
-
);
|
|
27684
|
-
this.leaseStmt = db.prepare(
|
|
27685
|
-
`SELECT owner_pid AS ownerPid, owner_host AS ownerHost,
|
|
27686
|
-
acquired_at AS acquiredAt, heartbeat_at AS heartbeatAt
|
|
27687
|
-
FROM history_sync WHERE id = 1`
|
|
27688
|
-
);
|
|
27689
|
-
this.inspectionsStmt = db.prepare(
|
|
27690
|
-
`SELECT d.rule_id AS ruleId,
|
|
27691
|
-
d.name AS ruleName,
|
|
27692
|
-
d.version AS ruleVersion,
|
|
27693
|
-
d.category AS category,
|
|
27694
|
-
d.severity AS severity,
|
|
27695
|
-
f.span_start AS spanStart,
|
|
27696
|
-
f.span_end AS spanEnd,
|
|
27697
|
-
f.masked_match AS maskedMatch,
|
|
27698
|
-
f.action_taken AS actionTaken,
|
|
27699
|
-
f.confidence AS confidence
|
|
27700
|
-
FROM inspection_findings f
|
|
27701
|
-
JOIN inspection_definitions d ON d.id = f.inspection_definition_id
|
|
27702
|
-
WHERE f.audit_event_id = :auditEventId
|
|
27703
|
-
ORDER BY f.span_start, f.id`
|
|
27704
|
-
);
|
|
27705
|
-
}
|
|
27706
|
-
db;
|
|
27707
|
-
ensureRowStmt;
|
|
27708
|
-
sessionsStmt;
|
|
27709
|
-
rowsStmt;
|
|
27710
|
-
stampStmt;
|
|
27711
|
-
countsStmt;
|
|
27712
|
-
fingerprintStmt;
|
|
27713
|
-
setFingerprintStmt;
|
|
27714
|
-
rearmStmt;
|
|
27715
|
-
claimStmt;
|
|
27716
|
-
heartbeatStmt;
|
|
27717
|
-
releaseStmt;
|
|
27718
|
-
leaseStmt;
|
|
27719
|
-
inspectionsStmt;
|
|
27720
|
-
closeWindowStmt;
|
|
27721
|
-
releaseBoundaryStmt;
|
|
27722
|
-
freezeBoundaryStmt;
|
|
27723
|
-
captureRowsStmt;
|
|
27724
|
-
markOwedStmt;
|
|
27725
|
-
markCaptureBacklogOwedStmt;
|
|
27726
|
-
captureSkipCountStmt;
|
|
27727
|
-
disownCapturesStmt;
|
|
27728
|
-
partitionStmt;
|
|
27729
|
-
claimRowStmt;
|
|
27730
|
-
releaseRowStmt;
|
|
27731
|
-
releaseStaleClaimsStmt;
|
|
27732
|
-
/**
|
|
27733
|
-
* The masked detections recorded against one tool call.
|
|
27734
|
-
*
|
|
27735
|
-
* These travel with the event because a tool call's target is not
|
|
27736
|
-
* re-inspectable from the event alone — unlike a capture, where the text
|
|
27737
|
-
* itself is re-scannable. What crosses is the masked match and the rule that
|
|
27738
|
-
* produced it, never the value.
|
|
27739
|
-
*/
|
|
27740
|
-
inspectionsFor(auditEventId) {
|
|
27741
|
-
return allRows(this.inspectionsStmt, { auditEventId });
|
|
27742
|
-
}
|
|
27743
|
-
/**
|
|
27744
|
-
* Sessions with structural rows still to send, oldest first.
|
|
27745
|
-
*
|
|
27746
|
-
* BOUNDED BY THE BACKLOG BOUNDARY, which is the whole correctness of this
|
|
27747
|
-
* read. Anything recorded after the machine attached is the live forward
|
|
27748
|
-
* path's to deliver; this drain exists for what was recorded before it, and a
|
|
27749
|
-
* row both paths send is at best a duplicate request and at worst — for a
|
|
27750
|
-
* session root — an overwrite of the inventory ids the live path resolved.
|
|
27751
|
-
*/
|
|
27752
|
-
pendingSessions(limit, before) {
|
|
27753
|
-
return allRows(this.sessionsStmt, { limit, before }).map(
|
|
27754
|
-
(r) => r.sessionId
|
|
27755
|
-
);
|
|
27756
|
-
}
|
|
27757
|
-
/** One session's undelivered structural rows within the backlog, root first. */
|
|
27758
|
-
pendingRows(sessionId, limit, before) {
|
|
27759
|
-
return allRows(this.rowsStmt, { sessionId, limit, before });
|
|
27760
|
-
}
|
|
27761
|
-
/**
|
|
27762
|
-
* Captures this machine still owes the deployment, oldest first.
|
|
27763
|
-
*
|
|
27764
|
-
* Selected by the `outbox_owed` marker the attached forward path writes, not
|
|
27765
|
-
* by a time window — see captureRowsStmt for why a window could not express
|
|
27766
|
-
* this. `before` is the grace window that leaves a just-recorded capture to
|
|
27767
|
-
* the live path.
|
|
27768
|
-
*/
|
|
27769
|
-
pendingCaptureRows(limit, before) {
|
|
27770
|
-
return allRows(this.captureRowsStmt, { limit, before });
|
|
27771
|
-
}
|
|
27772
|
-
/**
|
|
27773
|
-
* Record that a capture is OWED to the deployment.
|
|
27774
|
-
*
|
|
27775
|
-
* Written by the attached forward path when a live send did not confirm
|
|
27776
|
-
* delivery, and read by the drain as the whole of its eligibility test. It is
|
|
27777
|
-
* a fact rather than an inference: the machine was attached, the send did not
|
|
27778
|
-
* land, so the row is owed — which no time window can state, because the same
|
|
27779
|
-
* window that holds the rows a past attachment left owed also holds every
|
|
27780
|
-
* capture recorded while the machine was DETACHED, and those were never
|
|
27781
|
-
* offered to anyone.
|
|
27782
|
-
*
|
|
27783
|
-
* Idempotent, and never un-set: `markSynced` settling the row is what takes it
|
|
27784
|
-
* out of the drain's read.
|
|
27785
|
-
*/
|
|
27786
|
-
markCaptureOwed(id) {
|
|
27787
|
-
this.markOwedStmt.run({ id });
|
|
27788
|
-
}
|
|
27789
|
-
/**
|
|
27790
|
-
* Mark every capture already on disk as owed, as of `before`.
|
|
27791
|
-
*
|
|
27792
|
-
* The consent-time backfill, called once from `aka attach` when a human
|
|
27793
|
-
* grants existing-history consent — never from an ongoing drain pass, and
|
|
27794
|
-
* never inferred from a boundary that could later move. `before` is the
|
|
27795
|
-
* caller's own "now" at the moment consent was granted, so what this marks
|
|
27796
|
-
* is exactly the backlog the consent prompt already counted, not whatever a
|
|
27797
|
-
* later re-attach or key rotation might widen it to.
|
|
27798
|
-
*
|
|
27799
|
-
* Returns how many rows matched, for the caller to log or test against. Not a
|
|
27800
|
-
* count of NEWLY marked rows — a row still unsynced from an earlier call
|
|
27801
|
-
* matches again and is counted again, the same as `UPDATE`'s own `changes`.
|
|
27802
|
-
*/
|
|
27803
|
-
markCaptureBacklogOwed(before) {
|
|
27804
|
-
return Number(this.markCaptureBacklogOwedStmt.run({ before }).changes);
|
|
27805
|
-
}
|
|
27806
|
-
/** Record delivery. Called only AFTER the far side has accepted the rows. */
|
|
27807
|
-
markSynced(ids, atMs) {
|
|
27808
|
-
this.stampAll(ids, atMs);
|
|
27809
|
-
}
|
|
27810
|
-
/**
|
|
27811
|
-
* Record that a row will never be sent.
|
|
27812
|
-
*
|
|
27813
|
-
* Reserved for a local defect — a row that cannot be rebuilt into a valid
|
|
27814
|
-
* payload. A row that merely failed to reach the deployment stays NULL, so it
|
|
27815
|
-
* is retried; marking those would turn one outage into permanent data loss.
|
|
27816
|
-
*/
|
|
27817
|
-
markSkipped(ids) {
|
|
27818
|
-
this.stampAll(ids, SKIPPED);
|
|
27819
|
-
}
|
|
27820
|
-
eachInTransaction(ids, run) {
|
|
27821
|
-
if (ids.length === 0) return;
|
|
27822
|
-
withTransaction(
|
|
27823
|
-
this.db,
|
|
27824
|
-
() => {
|
|
27825
|
-
for (const id of ids) run(id);
|
|
27826
|
-
},
|
|
27827
|
-
"IMMEDIATE"
|
|
27828
|
-
);
|
|
27829
|
-
}
|
|
27830
|
-
stampAll(ids, value) {
|
|
27831
|
-
if (ids.length === 0) return;
|
|
27832
|
-
withTransaction(
|
|
27833
|
-
this.db,
|
|
27834
|
-
() => {
|
|
27835
|
-
for (const id of ids) this.stampStmt.run({ at: value, id });
|
|
27836
|
-
},
|
|
27837
|
-
"IMMEDIATE"
|
|
27838
|
-
);
|
|
27839
|
-
}
|
|
27840
|
-
/**
|
|
27841
|
-
* Claim rows as in-flight.
|
|
27842
|
-
*
|
|
27843
|
-
* Advisory in exactly the sense the lease is: it records that a send is in
|
|
27844
|
-
* progress so a surface can say so, and a lost claim costs a row showing as
|
|
27845
|
-
* queued while it is actually being sent. It is not exclusion — the far side
|
|
27846
|
-
* settles a duplicate on the row id.
|
|
27847
|
-
*/
|
|
27848
|
-
claimRows(ids, atMs) {
|
|
27849
|
-
this.eachInTransaction(ids, (id) => this.claimRowStmt.run({ at: atMs, id }));
|
|
27850
|
-
}
|
|
27851
|
-
/** Give back a claim without settling — the send failed, the row is queued again. */
|
|
27852
|
-
releaseRows(ids) {
|
|
27853
|
-
this.eachInTransaction(ids, (id) => this.releaseRowStmt.run({ id }));
|
|
27854
|
-
}
|
|
27855
|
-
/**
|
|
27856
|
-
* Clear claims older than `staleBefore`, and report how many were cleared.
|
|
27857
|
-
*
|
|
27858
|
-
* A process killed between claiming and settling leaves rows claimed with
|
|
27859
|
-
* nothing left to settle them. Without this they read as "sending" for ever.
|
|
27860
|
-
*/
|
|
27861
|
-
releaseStaleClaims(staleBefore) {
|
|
27862
|
-
return Number(this.releaseStaleClaimsStmt.run({ staleBefore }).changes);
|
|
27863
|
-
}
|
|
27864
|
-
/**
|
|
27865
|
-
* Every tracked row in exactly one delivery state.
|
|
27866
|
-
*
|
|
27867
|
-
* Takes no boundary on purpose. The boundary answers "what should the drain
|
|
27868
|
-
* pick up now", which is a different question from "what state is this row
|
|
27869
|
-
* in" — and a machine that has never attached has no boundary to pass, so
|
|
27870
|
-
* requiring one would force a caller to invent one and report the whole store
|
|
27871
|
-
* as queued.
|
|
27872
|
-
*/
|
|
27873
|
-
partition() {
|
|
27874
|
-
const row = getRow(this.partitionStmt, {});
|
|
27875
|
-
return {
|
|
27876
|
-
queued: row?.queued ?? 0,
|
|
27877
|
-
inProgress: row?.inProgress ?? 0,
|
|
27878
|
-
synced: row?.synced ?? 0,
|
|
27879
|
-
failed: row?.failed ?? 0,
|
|
27880
|
-
total: row?.total ?? 0
|
|
27881
|
-
};
|
|
27882
|
-
}
|
|
27883
|
-
/** `pending` counts only what is inside the backlog; sent and skipped are totals. */
|
|
27884
|
-
counts(before) {
|
|
27885
|
-
const row = getRow(
|
|
27886
|
-
this.countsStmt,
|
|
27887
|
-
{ before }
|
|
27888
|
-
);
|
|
27889
|
-
const captures = getRow(this.captureSkipCountStmt);
|
|
27890
|
-
return {
|
|
27891
|
-
pending: row?.pending ?? 0,
|
|
27892
|
-
sent: row?.sent ?? 0,
|
|
27893
|
-
skipped: row?.skipped ?? 0,
|
|
27894
|
-
capturesSkipped: captures?.skipped ?? 0
|
|
27895
|
-
};
|
|
27896
|
-
}
|
|
27897
|
-
/**
|
|
27898
|
-
* The deployment the current stamps were made against, and where its backlog
|
|
27899
|
-
* ends.
|
|
27900
|
-
*
|
|
27901
|
-
* READ-ONLY. An absent row reads as an absent deployment, which is what a
|
|
27902
|
-
* machine that has never drained is — and every writer below seeds the row
|
|
27903
|
-
* before it needs one, so nothing depends on this creating it. Keeping the
|
|
27904
|
-
* write off the gate path matters because the gate runs on every pass while a
|
|
27905
|
-
* write has to take the database's write lock.
|
|
27906
|
-
*/
|
|
27907
|
-
deployment() {
|
|
27908
|
-
const row = getRow(
|
|
27909
|
-
this.fingerprintStmt
|
|
27910
|
-
);
|
|
27911
|
-
return {
|
|
27912
|
-
fingerprint: row?.fingerprint ?? void 0,
|
|
27913
|
-
backlogBefore: row?.backlogBefore ?? void 0
|
|
27914
|
-
};
|
|
27915
|
-
}
|
|
27916
|
-
/**
|
|
27917
|
-
* Point the ledger at a different deployment, discarding what it recorded
|
|
27918
|
-
* about the previous one.
|
|
27919
|
-
*
|
|
27920
|
-
* Delivery is a fact about ONE recipient: rows sent to the deployment a
|
|
27921
|
-
* machine has just left are undelivered as far as the new one is concerned.
|
|
27922
|
-
* All four in one transaction, so a crash between them cannot leave stamps
|
|
27923
|
-
* attributed to the wrong deployment, a boundary that belongs to another, or
|
|
27924
|
-
* a disown with no re-mark to follow it.
|
|
27925
|
-
*
|
|
27926
|
-
* The boundary is written HERE and only here, which is what freezes it: a
|
|
27927
|
-
* re-attach to the SAME deployment (a key rotation) leaves the fingerprint
|
|
27928
|
-
* unchanged, so this never runs and the backlog does not widen back over rows
|
|
27929
|
-
* the live path has since delivered.
|
|
27930
|
-
*
|
|
27931
|
-
* `backfillCapturesBefore` is the caller's OWN "now" at the instant a human
|
|
27932
|
-
* granted existing-history consent for the deployment this call is arming —
|
|
27933
|
-
* a DIFFERENT instant from `backlogBefore`: the re-mark boundary is the GRANT
|
|
27934
|
-
* instant, `backlogBefore` is the ATTACH instant, and the two can be far
|
|
27935
|
-
* apart. Passed only when that grant is valid, since this method has no way
|
|
27936
|
-
* to check consent itself and must not mark a row owed for a machine that
|
|
27937
|
-
* never agreed to it. Applied AFTER the disown above, in the SAME
|
|
27938
|
-
* transaction: what the disown clears is every marker below `backlogBefore`,
|
|
27939
|
-
* which includes this deployment's OWN pre-attach rows — `aka attach` calls
|
|
27940
|
-
* `seedCaptureBacklogOwed` at the attach instant, so every row it marks sits
|
|
27941
|
-
* on the cleared side of that bound — and the re-mark in the same
|
|
27942
|
-
* transaction is what puts those rows back. A crash between the two cannot
|
|
27943
|
-
* strand the ledger disowned with nothing re-marked — the transaction either
|
|
27944
|
-
* lands whole or not at all, and a fingerprint mismatch that has not yet
|
|
27945
|
-
* committed re-enters this method on the very next pass. Omit it (the
|
|
27946
|
-
* structural-only tests do) to exercise the disown in isolation.
|
|
27947
|
-
*
|
|
27948
|
-
* The disown is bounded by `backlogBefore`, which is what keeps it from
|
|
27949
|
-
* touching a marker the NEW deployment's OWN live path has already set: B's
|
|
27950
|
-
* live path can mark a capture owed from the moment `aka attach` writes the
|
|
27951
|
-
* descriptor, before the drain's first pass ever reaches this method, and
|
|
27952
|
-
* such a row sits at or after the bound rather than below it. What keeps the
|
|
27953
|
-
* disown from eating THIS SAME CALL's own re-mark is the order, not the
|
|
27954
|
-
* bound — disown runs first, re-mark second, both inside the one
|
|
27955
|
-
* transaction above.
|
|
27956
|
-
*/
|
|
27957
|
-
rearmFor(fingerprint, backlogBefore, backfillCapturesBefore) {
|
|
27958
|
-
this.ensureRowStmt.run();
|
|
27959
|
-
withTransaction(
|
|
27960
|
-
this.db,
|
|
27961
|
-
() => {
|
|
27962
|
-
const previous = getRow(this.fingerprintStmt)?.fingerprint;
|
|
27963
|
-
this.rearmStmt.run();
|
|
27964
|
-
if (previous !== null && previous !== void 0 && previous !== fingerprint) {
|
|
27965
|
-
this.disownCapturesStmt.run({ attachedAt: backlogBefore });
|
|
27966
|
-
}
|
|
27967
|
-
if (backfillCapturesBefore !== void 0) {
|
|
27968
|
-
this.markCaptureBacklogOwedStmt.run({ before: backfillCapturesBefore });
|
|
27969
|
-
}
|
|
27970
|
-
this.setFingerprintStmt.run({ fingerprint, backlogBefore });
|
|
27971
|
-
},
|
|
27972
|
-
"IMMEDIATE"
|
|
27973
|
-
);
|
|
27974
|
-
}
|
|
27975
|
-
/**
|
|
27976
|
-
* End the attached period: hand its rows to the live path, and release the
|
|
27977
|
-
* boundary so the next attachment can freeze a new one.
|
|
27978
|
-
*
|
|
27979
|
-
* WITHOUT THIS, a detach and a re-attach to the same deployment leave a window
|
|
27980
|
-
* nothing delivers. The fingerprint is unchanged, so the boundary is never
|
|
27981
|
-
* re-frozen and stays at the FIRST attachment — while nothing forwards at all
|
|
27982
|
-
* during the detached period, because the machine is not attached. Rows
|
|
27983
|
-
* recorded in that window sit after the boundary and before the re-attach, so
|
|
27984
|
-
* neither path takes them, and the pending count reports none outstanding.
|
|
27985
|
-
*
|
|
27986
|
-
* Stamping the attached window is not a claim that every one of those rows
|
|
27987
|
-
* reached the deployment — the live path drops on failure and says so
|
|
27988
|
-
* elsewhere. It records that they were ITS to deliver, which is exactly the
|
|
27989
|
-
* status quo: they sit outside the frozen boundary today and are equally never
|
|
27990
|
-
* re-sent. Making it explicit is what lets the boundary move.
|
|
27991
|
-
*
|
|
27992
|
-
* ONE TRANSACTION, so a crash cannot release the boundary while leaving the
|
|
27993
|
-
* window unstamped — that half-state would re-send the whole attached period
|
|
27994
|
-
* on the next attach, which is the failure the boundary exists to prevent.
|
|
27995
|
-
*/
|
|
27996
|
-
closeAttachedWindow(attachedAtMs, atMs) {
|
|
27997
|
-
this.ensureRowStmt.run();
|
|
27998
|
-
withTransaction(
|
|
27999
|
-
this.db,
|
|
28000
|
-
() => {
|
|
28001
|
-
const row = getRow(this.fingerprintStmt);
|
|
28002
|
-
const from = row?.backlogBefore ?? attachedAtMs;
|
|
28003
|
-
this.closeWindowStmt.run({ at: atMs, attachedAt: from });
|
|
28004
|
-
this.releaseBoundaryStmt.run();
|
|
28005
|
-
},
|
|
28006
|
-
"IMMEDIATE"
|
|
28007
|
-
);
|
|
28008
|
-
}
|
|
28009
|
-
/**
|
|
28010
|
-
* Freeze a boundary for the deployment already on file, KEEPING the stamps.
|
|
28011
|
-
*
|
|
28012
|
-
* The re-attach half of the above. Distinct from `rearmFor`, which is for a
|
|
28013
|
-
* different deployment and therefore discards what was delivered to the old
|
|
28014
|
-
* one: here the recipient is the same, so everything already sent to it stays
|
|
28015
|
-
* sent.
|
|
28016
|
-
*/
|
|
28017
|
-
freezeBoundary(backlogBefore) {
|
|
28018
|
-
this.ensureRowStmt.run();
|
|
28019
|
-
this.freezeBoundaryStmt.run({ backlogBefore });
|
|
28020
|
-
}
|
|
28021
|
-
/** Take the claim, or report that someone live already holds it. */
|
|
28022
|
-
claim(pid, host, nowMs, staleAfterMs) {
|
|
28023
|
-
this.ensureRowStmt.run();
|
|
28024
|
-
let taken = false;
|
|
28025
|
-
withTransaction(
|
|
28026
|
-
this.db,
|
|
28027
|
-
() => {
|
|
28028
|
-
const result = this.claimStmt.run({
|
|
28029
|
-
pid,
|
|
28030
|
-
host,
|
|
28031
|
-
now: nowMs,
|
|
28032
|
-
staleBefore: nowMs - staleAfterMs
|
|
28033
|
-
});
|
|
28034
|
-
taken = result.changes === 1;
|
|
28035
|
-
},
|
|
28036
|
-
"IMMEDIATE"
|
|
28037
|
-
);
|
|
28038
|
-
return taken;
|
|
28039
|
-
}
|
|
28040
|
-
/** Say the holder is still alive. A no-op once the claim has moved on. */
|
|
28041
|
-
heartbeat(pid, nowMs) {
|
|
28042
|
-
this.heartbeatStmt.run({ now: nowMs, pid });
|
|
28043
|
-
}
|
|
28044
|
-
/** Give the claim up. Scoped to this holder, so a taken-over claim is left be. */
|
|
28045
|
-
release(pid) {
|
|
28046
|
-
this.releaseStmt.run({ pid });
|
|
28047
|
-
}
|
|
28048
|
-
/** Who holds the claim, if anyone. Read-only, for the same reason as above. */
|
|
28049
|
-
lease() {
|
|
28050
|
-
return getRow(this.leaseStmt);
|
|
28051
|
-
}
|
|
28052
|
-
};
|
|
28053
|
-
|
|
28054
28916
|
// ../../packages/persistence/src/repositories/inspection-definitions.ts
|
|
28055
28917
|
var SqliteInspectionDefinitionsRepository = class {
|
|
28056
28918
|
constructor(db) {
|
|
@@ -28274,6 +29136,7 @@ function overlayManagedSettings(settings, managed, now = () => /* @__PURE__ */ n
|
|
|
28274
29136
|
if (values.vaultInlineReveal !== void 0) merged.vaultInlineReveal = values.vaultInlineReveal;
|
|
28275
29137
|
if (values.dataSharesInPlace !== void 0) merged.dataSharesInPlace = values.dataSharesInPlace;
|
|
28276
29138
|
if (values.redactFallback !== void 0) merged.redactFallback = values.redactFallback;
|
|
29139
|
+
if (values.bodyRetention !== void 0) merged.bodyRetention = values.bodyRetention;
|
|
28277
29140
|
if (values.vaultConsent !== void 0) {
|
|
28278
29141
|
merged.vaultConsent = values.vaultConsent ? (
|
|
28279
29142
|
// Keep an existing valid grant so its acknowledgedAt survives; mint one
|
|
@@ -30781,7 +31644,7 @@ var SqliteSecurityRepository = class {
|
|
|
30781
31644
|
ELSE 0
|
|
30782
31645
|
END) AS open_at_rest
|
|
30783
31646
|
FROM inspection_findings f
|
|
30784
|
-
JOIN audit_events e ON e.id = f.audit_event_id
|
|
31647
|
+
JOIN audit_events e INDEXED BY idx_audit_capture_rollup ON e.id = f.audit_event_id
|
|
30785
31648
|
JOIN inspection_definitions d ON d.id = f.inspection_definition_id
|
|
30786
31649
|
LEFT JOIN ${LATEST_RESOLUTION_BY_KEY_SQL} latest
|
|
30787
31650
|
ON latest.finding_key = f.finding_key
|
|
@@ -31007,7 +31870,7 @@ var SqliteSecurityRepository = class {
|
|
|
31007
31870
|
this.db.prepare(
|
|
31008
31871
|
`SELECT e.repo AS repo, count(*) AS c
|
|
31009
31872
|
FROM inspection_findings f
|
|
31010
|
-
JOIN audit_events e ON e.id = f.audit_event_id
|
|
31873
|
+
JOIN audit_events e INDEXED BY idx_audit_capture_rollup ON e.id = f.audit_event_id
|
|
31011
31874
|
WHERE e.started_at >= :from AND e.started_at < :to
|
|
31012
31875
|
AND e.event_type IN (${CAPTURE_EVENT_TYPES_SQL})
|
|
31013
31876
|
AND e.repo IS NOT NULL
|
|
@@ -31131,7 +31994,7 @@ var SqliteSecurityRepository = class {
|
|
|
31131
31994
|
d.severity AS severity,
|
|
31132
31995
|
COUNT(*) AS count
|
|
31133
31996
|
FROM inspection_findings f
|
|
31134
|
-
JOIN audit_events e ON e.id = f.audit_event_id
|
|
31997
|
+
JOIN audit_events e INDEXED BY idx_audit_capture_rollup ON e.id = f.audit_event_id
|
|
31135
31998
|
JOIN inspection_definitions d ON d.id = f.inspection_definition_id
|
|
31136
31999
|
LEFT JOIN ${LATEST_RESOLUTION_BY_KEY_SQL} latest
|
|
31137
32000
|
ON latest.finding_key = f.finding_key
|
|
@@ -31166,7 +32029,7 @@ var SqliteSecurityRepository = class {
|
|
|
31166
32029
|
`SELECT e.started_at AS occurred_at, d.severity AS severity, f.action_taken AS action_taken,
|
|
31167
32030
|
d.rule_id AS rule_id, d.category AS category
|
|
31168
32031
|
FROM inspection_findings f
|
|
31169
|
-
JOIN audit_events e ON e.id = f.audit_event_id
|
|
32032
|
+
JOIN audit_events e INDEXED BY idx_audit_capture_rollup ON e.id = f.audit_event_id
|
|
31170
32033
|
JOIN inspection_definitions d ON d.id = f.inspection_definition_id
|
|
31171
32034
|
WHERE e.started_at >= :from AND e.started_at < :to
|
|
31172
32035
|
AND e.event_type IN (${CAPTURE_EVENT_TYPES_SQL})
|
|
@@ -32007,6 +32870,7 @@ function openWithPragmas(file2) {
|
|
|
32007
32870
|
db.exec("PRAGMA journal_mode = WAL");
|
|
32008
32871
|
db.exec("PRAGMA busy_timeout = 2000");
|
|
32009
32872
|
db.exec("PRAGMA foreign_keys = ON");
|
|
32873
|
+
registerSqlFunctions(db);
|
|
32010
32874
|
} catch (err) {
|
|
32011
32875
|
closeQuietly(db);
|
|
32012
32876
|
throw err;
|
|
@@ -32036,7 +32900,7 @@ function backupLegacyStore(db, file2) {
|
|
|
32036
32900
|
discardStore(file2, backup);
|
|
32037
32901
|
return backup;
|
|
32038
32902
|
}
|
|
32039
|
-
function openAndInitialize(file2, base) {
|
|
32903
|
+
function openAndInitialize(file2, base, skipTags) {
|
|
32040
32904
|
let db = openWithPragmas(file2);
|
|
32041
32905
|
try {
|
|
32042
32906
|
if (isForeignSqliteLineage(db)) {
|
|
@@ -32046,7 +32910,7 @@ function openAndInitialize(file2, base) {
|
|
|
32046
32910
|
`Detected an older, incompatible (tenant-bearing) ${DB_FILENAME}; backed it up to ${backup} and created a fresh store.`
|
|
32047
32911
|
);
|
|
32048
32912
|
}
|
|
32049
|
-
applyMigrations(db, file2);
|
|
32913
|
+
applyMigrations(db, file2, { skipTags });
|
|
32050
32914
|
tightenPerms(file2);
|
|
32051
32915
|
const policies = new SqlitePoliciesRepository(db);
|
|
32052
32916
|
const installedPacks = new SqliteInstalledPacksRepository(db, base);
|
|
@@ -32061,6 +32925,7 @@ function openAndInitialize(file2, base) {
|
|
|
32061
32925
|
exceptions: new SqliteExceptionsRepository(db),
|
|
32062
32926
|
resolutions: new SqliteResolutionsRepository(db),
|
|
32063
32927
|
ruleProbeCache: new SqliteRuleProbeCacheRepository(db),
|
|
32928
|
+
bodyRetention: new SqliteBodyRetentionRepository(db),
|
|
32064
32929
|
security: new SqliteSecurityRepository(db),
|
|
32065
32930
|
detections: new SqliteDetectionsRepository(db),
|
|
32066
32931
|
shares: new SqliteSharesRepository(db),
|
|
@@ -32071,6 +32936,7 @@ function openAndInitialize(file2, base) {
|
|
|
32071
32936
|
activity: new SqliteActivityRepository(db),
|
|
32072
32937
|
sourceProject: new SqliteSourceProjectRepository(db),
|
|
32073
32938
|
auditEvents: new SqliteAuditEventsRepository(db),
|
|
32939
|
+
captureStatus: new SqliteCaptureStatusRepository(db),
|
|
32074
32940
|
classifiedData: new SqliteClassifiedDataRepository(db),
|
|
32075
32941
|
inspectionDefinitions: new SqliteInspectionDefinitionsRepository(db),
|
|
32076
32942
|
inspectionFindings: new SqliteInspectionFindingsRepository(db),
|
|
@@ -32083,7 +32949,8 @@ function openAndInitialize(file2, base) {
|
|
|
32083
32949
|
throw err;
|
|
32084
32950
|
}
|
|
32085
32951
|
}
|
|
32086
|
-
|
|
32952
|
+
var DEFERRED_TAGS = new Set(DEFERRED_MIGRATION_TAGS);
|
|
32953
|
+
function openLocalDatabase(dir, options = {}) {
|
|
32087
32954
|
ensureDataDirSync(dir);
|
|
32088
32955
|
const file2 = join7(dir, DB_FILENAME);
|
|
32089
32956
|
reapStalePartials(file2);
|
|
@@ -32095,6 +32962,7 @@ function openLocalDatabase(dir) {
|
|
|
32095
32962
|
installedPacks,
|
|
32096
32963
|
scanLedger,
|
|
32097
32964
|
historySync,
|
|
32965
|
+
bodyRetention,
|
|
32098
32966
|
secretVault,
|
|
32099
32967
|
exceptions,
|
|
32100
32968
|
resolutions,
|
|
@@ -32109,6 +32977,7 @@ function openLocalDatabase(dir) {
|
|
|
32109
32977
|
activity,
|
|
32110
32978
|
sourceProject,
|
|
32111
32979
|
auditEvents,
|
|
32980
|
+
captureStatus,
|
|
32112
32981
|
classifiedData,
|
|
32113
32982
|
inspectionDefinitions,
|
|
32114
32983
|
inspectionFindings,
|
|
@@ -32118,7 +32987,8 @@ function openLocalDatabase(dir) {
|
|
|
32118
32987
|
// `dir` is always `<base>/data` — every caller resolves it through
|
|
32119
32988
|
// `dataDir()` — so its parent is the `~/.aka` base the layout splits into
|
|
32120
32989
|
// settings/ and data/, and the pack-policy floor needs both halves.
|
|
32121
|
-
dirname2(dir)
|
|
32990
|
+
dirname2(dir),
|
|
32991
|
+
options.applyDeferredMigrations === true ? void 0 : DEFERRED_TAGS
|
|
32122
32992
|
);
|
|
32123
32993
|
function captureRowId(event) {
|
|
32124
32994
|
return captureId(
|
|
@@ -32311,6 +33181,7 @@ function openLocalDatabase(dir) {
|
|
|
32311
33181
|
installedPacks,
|
|
32312
33182
|
scanLedger,
|
|
32313
33183
|
historySync,
|
|
33184
|
+
bodyRetention,
|
|
32314
33185
|
secretVault,
|
|
32315
33186
|
exceptions,
|
|
32316
33187
|
resolutions,
|
|
@@ -32324,6 +33195,7 @@ function openLocalDatabase(dir) {
|
|
|
32324
33195
|
activity,
|
|
32325
33196
|
sourceProject,
|
|
32326
33197
|
auditEvents,
|
|
33198
|
+
captureStatus,
|
|
32327
33199
|
classifiedData,
|
|
32328
33200
|
inspectionDefinitions,
|
|
32329
33201
|
inspectionFindings,
|
|
@@ -32351,6 +33223,7 @@ function openLocalDatabase(dir) {
|
|
|
32351
33223
|
|
|
32352
33224
|
// ../../packages/persistence/src/egress-wire.ts
|
|
32353
33225
|
import { createHash as createHash3 } from "crypto";
|
|
33226
|
+
var SLASH = "/".charCodeAt(0);
|
|
32354
33227
|
|
|
32355
33228
|
// ../../packages/persistence/src/finding-key.ts
|
|
32356
33229
|
import { createHash as createHash4 } from "crypto";
|
|
@@ -32361,18 +33234,26 @@ import { existsSync as existsSync3, readFileSync as readFileSync6 } from "fs";
|
|
|
32361
33234
|
import { join as join8 } from "path";
|
|
32362
33235
|
import { DatabaseSync as DatabaseSync2 } from "node:sqlite";
|
|
32363
33236
|
|
|
33237
|
+
// ../../packages/persistence/src/forward-health.ts
|
|
33238
|
+
import { readFileSync as readFileSync7 } from "fs";
|
|
33239
|
+
import { join as join9 } from "path";
|
|
33240
|
+
|
|
32364
33241
|
// ../../packages/persistence/src/history-backfill.ts
|
|
32365
33242
|
import { existsSync as existsSync4 } from "fs";
|
|
32366
|
-
import { join as
|
|
33243
|
+
import { join as join10 } from "path";
|
|
32367
33244
|
|
|
32368
33245
|
// ../../packages/persistence/src/history-preview.ts
|
|
32369
33246
|
import { existsSync as existsSync5 } from "fs";
|
|
32370
|
-
import { join as
|
|
33247
|
+
import { join as join11 } from "path";
|
|
32371
33248
|
import { DatabaseSync as DatabaseSync3 } from "node:sqlite";
|
|
32372
33249
|
|
|
33250
|
+
// ../../packages/persistence/src/history-sync-state.ts
|
|
33251
|
+
import { readFileSync as readFileSync8 } from "fs";
|
|
33252
|
+
import { join as join12 } from "path";
|
|
33253
|
+
|
|
32373
33254
|
// ../../packages/persistence/src/store-symlinks.ts
|
|
32374
33255
|
import { existsSync as existsSync6, lstatSync as lstatSync3, readlinkSync, realpathSync, statSync as statSync4 } from "fs";
|
|
32375
|
-
import { dirname as dirname3, join as
|
|
33256
|
+
import { dirname as dirname3, join as join13, resolve } from "path";
|
|
32376
33257
|
|
|
32377
33258
|
// ../../packages/persistence/src/vault/crypto.ts
|
|
32378
33259
|
import {
|
|
@@ -32386,19 +33267,19 @@ import {
|
|
|
32386
33267
|
// ../../packages/persistence/src/vault/key-provider.ts
|
|
32387
33268
|
import { execFileSync } from "child_process";
|
|
32388
33269
|
import { randomBytes as randomBytes2 } from "crypto";
|
|
32389
|
-
import { chmodSync as chmodSync3, readFileSync as
|
|
32390
|
-
import { join as
|
|
33270
|
+
import { chmodSync as chmodSync3, readFileSync as readFileSync9, renameSync as renameSync4, rmSync as rmSync6, statSync as statSync5, writeFileSync as writeFileSync3 } from "fs";
|
|
33271
|
+
import { join as join14 } from "path";
|
|
32391
33272
|
|
|
32392
33273
|
// ../../packages/persistence/src/vault/vault.ts
|
|
32393
33274
|
import { randomBytes as randomBytes3, randomUUID as randomUUID12 } from "crypto";
|
|
32394
33275
|
|
|
32395
33276
|
// ../../packages/persistence/src/warn-era-cap.ts
|
|
32396
33277
|
import { existsSync as existsSync7, writeFileSync as writeFileSync4 } from "fs";
|
|
32397
|
-
import { join as
|
|
33278
|
+
import { join as join15 } from "path";
|
|
32398
33279
|
|
|
32399
33280
|
// ../../packages/plugin-sdk/src/config.ts
|
|
32400
33281
|
import { existsSync as existsSync8 } from "fs";
|
|
32401
|
-
import { join as
|
|
33282
|
+
import { join as join16 } from "path";
|
|
32402
33283
|
|
|
32403
33284
|
// ../../packages/plugin-sdk/src/provider-env.ts
|
|
32404
33285
|
var DEFAULT_ANTHROPIC_HOST = "api.anthropic.com";
|
|
@@ -32452,7 +33333,7 @@ function resolveProvider() {
|
|
|
32452
33333
|
function loadConfig(base = defaultDataDir(), resolveProviderFn = resolveProvider) {
|
|
32453
33334
|
try {
|
|
32454
33335
|
ensureLayoutDirSync(base);
|
|
32455
|
-
const settingsFile =
|
|
33336
|
+
const settingsFile = join16(settingsDir(base), "settings.json");
|
|
32456
33337
|
if (existsSync8(settingsFile)) tightenFile(settingsFile);
|
|
32457
33338
|
} catch {
|
|
32458
33339
|
}
|
|
@@ -32476,9 +33357,9 @@ function resolveProviderSafe(resolveProviderFn) {
|
|
|
32476
33357
|
}
|
|
32477
33358
|
|
|
32478
33359
|
// ../../packages/plugin-sdk/src/config-inventory.ts
|
|
32479
|
-
import { readdirSync as readdirSync2, readFileSync as
|
|
33360
|
+
import { readdirSync as readdirSync2, readFileSync as readFileSync11, realpathSync as realpathSync2, statSync as statSync7 } from "fs";
|
|
32480
33361
|
import { homedir as homedir2 } from "os";
|
|
32481
|
-
import { basename as basename3, join as
|
|
33362
|
+
import { basename as basename3, join as join18 } from "path";
|
|
32482
33363
|
|
|
32483
33364
|
// ../../packages/detections/src/egress/registry.ts
|
|
32484
33365
|
var EXTRACTOR_VERSION = "1";
|
|
@@ -33419,6 +34300,56 @@ var CONFIG_POSTURE_RULES = [
|
|
|
33419
34300
|
}
|
|
33420
34301
|
];
|
|
33421
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
|
+
|
|
33422
34353
|
// ../../packages/detections/src/security/redos-probe.ts
|
|
33423
34354
|
var BUDGET_MS = 100;
|
|
33424
34355
|
var EXPONENTIAL_UNITS = [
|
|
@@ -35513,8 +36444,8 @@ function maskText(text) {
|
|
|
35513
36444
|
}
|
|
35514
36445
|
|
|
35515
36446
|
// ../../packages/plugin-sdk/src/repo.ts
|
|
35516
|
-
import { existsSync as existsSync9, readFileSync as
|
|
35517
|
-
import { basename as basename2, dirname as dirname4, isAbsolute, join as
|
|
36447
|
+
import { existsSync as existsSync9, readFileSync as readFileSync10, statSync as statSync6 } from "fs";
|
|
36448
|
+
import { basename as basename2, dirname as dirname4, isAbsolute, join as join17, sep as sep2 } from "path";
|
|
35518
36449
|
|
|
35519
36450
|
// ../../packages/plugin-sdk/src/events.ts
|
|
35520
36451
|
import { createHash as createHash5, randomUUID as randomUUID13 } from "crypto";
|
|
@@ -35525,8 +36456,8 @@ import { fileURLToPath } from "url";
|
|
|
35525
36456
|
import { Worker } from "worker_threads";
|
|
35526
36457
|
|
|
35527
36458
|
// ../../packages/plugin-sdk/src/host-floor.ts
|
|
35528
|
-
import { readFileSync as
|
|
35529
|
-
import { join as
|
|
36459
|
+
import { readFileSync as readFileSync13 } from "fs";
|
|
36460
|
+
import { join as join20 } from "path";
|
|
35530
36461
|
|
|
35531
36462
|
// ../../packages/plugin-sdk/src/model-governance.ts
|
|
35532
36463
|
import {
|
|
@@ -35534,11 +36465,11 @@ import {
|
|
|
35534
36465
|
fstatSync,
|
|
35535
36466
|
mkdirSync as mkdirSync2,
|
|
35536
36467
|
openSync as openSync2,
|
|
35537
|
-
readFileSync as
|
|
36468
|
+
readFileSync as readFileSync12,
|
|
35538
36469
|
readSync,
|
|
35539
36470
|
writeFileSync as writeFileSync5
|
|
35540
36471
|
} from "fs";
|
|
35541
|
-
import { join as
|
|
36472
|
+
import { join as join19 } from "path";
|
|
35542
36473
|
var TAIL_BYTES = 256 * 1024;
|
|
35543
36474
|
|
|
35544
36475
|
// ../../packages/plugin-sdk/src/host-floor.ts
|
|
@@ -35561,15 +36492,15 @@ var HOST_FLOORS = {
|
|
|
35561
36492
|
|
|
35562
36493
|
// ../../packages/plugin-sdk/src/ignore-layers.ts
|
|
35563
36494
|
var import_ignore = __toESM(require_ignore(), 1);
|
|
35564
|
-
import { readFileSync as
|
|
35565
|
-
import { join as
|
|
36495
|
+
import { readFileSync as readFileSync14 } from "fs";
|
|
36496
|
+
import { join as join21 } from "path";
|
|
35566
36497
|
|
|
35567
36498
|
// ../../packages/plugin-sdk/src/inventory-resolver.ts
|
|
35568
36499
|
import { arch, hostname as hostname4, platform, release } from "os";
|
|
35569
36500
|
|
|
35570
36501
|
// ../../packages/plugin-sdk/src/nudge.ts
|
|
35571
|
-
import { mkdirSync as mkdirSync3, readFileSync as
|
|
35572
|
-
import { join as
|
|
36502
|
+
import { mkdirSync as mkdirSync3, readFileSync as readFileSync15, writeFileSync as writeFileSync6 } from "fs";
|
|
36503
|
+
import { join as join22 } from "path";
|
|
35573
36504
|
|
|
35574
36505
|
// ../../packages/plugin-sdk/src/paths.ts
|
|
35575
36506
|
import { readdirSync as readdirSync3, realpathSync as realpathSync3 } from "fs";
|
|
@@ -35587,7 +36518,7 @@ function applyCategoryPosture(posture, repo, mode = "fill-gaps") {
|
|
|
35587
36518
|
|
|
35588
36519
|
// ../../packages/plugin-sdk/src/project-files.ts
|
|
35589
36520
|
import { existsSync as existsSync11, readdirSync as readdirSync4 } from "fs";
|
|
35590
|
-
import { basename as basename5, join as
|
|
36521
|
+
import { basename as basename5, join as join23 } from "path";
|
|
35591
36522
|
|
|
35592
36523
|
// ../../packages/plugin-sdk/src/provider-env-antigravity.ts
|
|
35593
36524
|
var optionalBaseUrl2 = external_exports.preprocess((v) => {
|
|
@@ -35705,11 +36636,11 @@ async function applySetupTriageSuppressions(entries, writer, opts) {
|
|
|
35705
36636
|
|
|
35706
36637
|
// ../../packages/plugin-sdk/src/throttle.ts
|
|
35707
36638
|
import { mkdirSync as mkdirSync4, statSync as statSync8, writeFileSync as writeFileSync7 } from "fs";
|
|
35708
|
-
import { join as
|
|
36639
|
+
import { join as join24 } from "path";
|
|
35709
36640
|
|
|
35710
36641
|
// ../../packages/setup-wizard/src/remediation/rotation-checklist.ts
|
|
35711
36642
|
import { writeFileSync as writeFileSync8 } from "fs";
|
|
35712
|
-
import { join as
|
|
36643
|
+
import { join as join25 } from "path";
|
|
35713
36644
|
|
|
35714
36645
|
// ../../packages/setup-wizard/src/triage/dedupe.ts
|
|
35715
36646
|
function dedupeKey(hit) {
|
|
@@ -35764,12 +36695,12 @@ function deriveFalsePositivePatterns(hits, rec, plan) {
|
|
|
35764
36695
|
}
|
|
35765
36696
|
|
|
35766
36697
|
// ../../packages/setup-wizard/src/triage/gate-display.ts
|
|
35767
|
-
function findContext(entry,
|
|
35768
|
-
const byFingerprint =
|
|
36698
|
+
function findContext(entry, join29) {
|
|
36699
|
+
const byFingerprint = join29.find(
|
|
35769
36700
|
(j) => j.valueFingerprint !== void 0 && j.valueFingerprint === entry.valueFingerprint
|
|
35770
36701
|
);
|
|
35771
36702
|
if (byFingerprint) return byFingerprint.maskedContext;
|
|
35772
|
-
const byRuleAndMask =
|
|
36703
|
+
const byRuleAndMask = join29.find(
|
|
35773
36704
|
(j) => j.ruleId === entry.ruleId && j.maskedMatch === entry.maskedValue
|
|
35774
36705
|
);
|
|
35775
36706
|
return byRuleAndMask?.maskedContext;
|
|
@@ -35840,13 +36771,13 @@ function renderShowcase(showcase) {
|
|
|
35840
36771
|
|
|
35841
36772
|
${blocks.join("\n\n")}`;
|
|
35842
36773
|
}
|
|
35843
|
-
function renderSuppressionGate(entries,
|
|
36774
|
+
function renderSuppressionGate(entries, join29) {
|
|
35844
36775
|
if (entries.length === 0) {
|
|
35845
36776
|
return "No false-positive suppressions to confirm \u2014 nothing will be written.";
|
|
35846
36777
|
}
|
|
35847
36778
|
const header = entries.length === 1 ? "This looks like a false positive \u2014 take a look before I suppress it:" : `These ${String(entries.length)} look like false positives \u2014 take a look before I suppress them:`;
|
|
35848
36779
|
const blocks = entries.map((entry, i) => {
|
|
35849
|
-
const context = findContext(entry,
|
|
36780
|
+
const context = findContext(entry, join29);
|
|
35850
36781
|
const lines = [
|
|
35851
36782
|
`${String(i + 1)}. ${entry.ruleId} [${entry.category}]`,
|
|
35852
36783
|
` value: ${entry.maskedValue}`,
|
|
@@ -35932,9 +36863,9 @@ function mergeRecommendations(verdicts) {
|
|
|
35932
36863
|
}
|
|
35933
36864
|
|
|
35934
36865
|
// ../../packages/setup-wizard/src/triage/plan-file.ts
|
|
35935
|
-
import { mkdtempSync, readFileSync as
|
|
36866
|
+
import { mkdtempSync, readFileSync as readFileSync16, rmdirSync, rmSync as rmSync7, writeFileSync as writeFileSync9 } from "fs";
|
|
35936
36867
|
import { tmpdir } from "os";
|
|
35937
|
-
import { basename as basename6, dirname as dirname6, join as
|
|
36868
|
+
import { basename as basename6, dirname as dirname6, join as join26 } from "path";
|
|
35938
36869
|
var SuppressionEntrySchema = external_exports.object({
|
|
35939
36870
|
ruleId: external_exports.string(),
|
|
35940
36871
|
category: DetectionCategory,
|
|
@@ -35989,13 +36920,13 @@ function serializePlan(plan, current) {
|
|
|
35989
36920
|
function writePlanFile(plan, current, rawValues, deps = {}) {
|
|
35990
36921
|
const serialized = serializePlan(plan, current);
|
|
35991
36922
|
assertRawFree(serialized, rawValues);
|
|
35992
|
-
const dir = (deps.mkTempDir ?? (() => mkdtempSync(
|
|
35993
|
-
const path =
|
|
36923
|
+
const dir = (deps.mkTempDir ?? (() => mkdtempSync(join26(tmpdir(), "aka-plan-"))))();
|
|
36924
|
+
const path = join26(dir, "setup-plan.json");
|
|
35994
36925
|
writeFileSync9(path, serialized, { encoding: "utf8", mode: 384 });
|
|
35995
36926
|
return path;
|
|
35996
36927
|
}
|
|
35997
36928
|
function readPlanFile(path) {
|
|
35998
|
-
const text =
|
|
36929
|
+
const text = readFileSync16(path, "utf8");
|
|
35999
36930
|
const json2 = JSON.parse(text);
|
|
36000
36931
|
return PersistedPlanSchema.parse(json2);
|
|
36001
36932
|
}
|
|
@@ -36069,8 +37000,8 @@ function buildJoinEntries(hits) {
|
|
|
36069
37000
|
}
|
|
36070
37001
|
|
|
36071
37002
|
// ../../packages/setup-wizard/src/triage/resolve.ts
|
|
36072
|
-
function resolveSuppressions(rec,
|
|
36073
|
-
const byId = new Map(
|
|
37003
|
+
function resolveSuppressions(rec, join29) {
|
|
37004
|
+
const byId = new Map(join29.map((e) => [e.id, e]));
|
|
36074
37005
|
const entries = [];
|
|
36075
37006
|
const skipped = [];
|
|
36076
37007
|
for (const cat of rec.perCategory) {
|
|
@@ -36172,7 +37103,7 @@ function parseTriageStream(text) {
|
|
|
36172
37103
|
return { hits, status: "complete" };
|
|
36173
37104
|
}
|
|
36174
37105
|
function planTriageWriteback(hits, rec) {
|
|
36175
|
-
const
|
|
37106
|
+
const join29 = buildJoinEntries(hits);
|
|
36176
37107
|
const rawValues = hits.map((h) => h.rawMatch);
|
|
36177
37108
|
const skipped = [];
|
|
36178
37109
|
const posture = {};
|
|
@@ -36212,7 +37143,7 @@ function planTriageWriteback(hits, rec) {
|
|
|
36212
37143
|
}
|
|
36213
37144
|
const { entries, skipped: resolveSkips } = resolveSuppressions(
|
|
36214
37145
|
{ perCategory: safeCategories, notes: rec.notes },
|
|
36215
|
-
|
|
37146
|
+
join29
|
|
36216
37147
|
);
|
|
36217
37148
|
skipped.push(...resolveSkips);
|
|
36218
37149
|
let notes = rec.notes;
|
|
@@ -36222,7 +37153,7 @@ function planTriageWriteback(hits, rec) {
|
|
|
36222
37153
|
if (err instanceof RawEgressError) notes = SCRUBBED_NOTES;
|
|
36223
37154
|
else throw err;
|
|
36224
37155
|
}
|
|
36225
|
-
return { entries, posture, showcase, join:
|
|
37156
|
+
return { entries, posture, showcase, join: join29, notes, skipped };
|
|
36226
37157
|
}
|
|
36227
37158
|
function recommendedPosture(evidence) {
|
|
36228
37159
|
return { ...severityFloorPosture(), ...evidence };
|
|
@@ -36491,9 +37422,9 @@ function parseRecommendation(text) {
|
|
|
36491
37422
|
|
|
36492
37423
|
// src/triage/judge.ts
|
|
36493
37424
|
import { execFileSync as execFileSync2 } from "child_process";
|
|
36494
|
-
import { mkdtempSync as mkdtempSync2, readFileSync as
|
|
37425
|
+
import { mkdtempSync as mkdtempSync2, readFileSync as readFileSync17, rmSync as rmSync8 } from "fs";
|
|
36495
37426
|
import { tmpdir as tmpdir2 } from "os";
|
|
36496
|
-
import { dirname as dirname7, join as
|
|
37427
|
+
import { dirname as dirname7, join as join27 } from "path";
|
|
36497
37428
|
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
36498
37429
|
|
|
36499
37430
|
// ../../packages/plugin-sdk/src/bare-command.ts
|
|
@@ -36605,7 +37536,7 @@ function planBareCommand(command, args, deps = {}) {
|
|
|
36605
37536
|
|
|
36606
37537
|
// src/triage/judge.ts
|
|
36607
37538
|
var TRIAGE_DIR = dirname7(fileURLToPath2(import.meta.url));
|
|
36608
|
-
var DEFAULT_RUBRIC_PATH =
|
|
37539
|
+
var DEFAULT_RUBRIC_PATH = join27(
|
|
36609
37540
|
TRIAGE_DIR,
|
|
36610
37541
|
"..",
|
|
36611
37542
|
"..",
|
|
@@ -36642,7 +37573,7 @@ function judgeEnv(platform2 = process.platform) {
|
|
|
36642
37573
|
CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC: "1"
|
|
36643
37574
|
};
|
|
36644
37575
|
if (platform2 === "darwin") {
|
|
36645
|
-
env.CLAUDE_CONFIG_DIR = mkdtempSync2(
|
|
37576
|
+
env.CLAUDE_CONFIG_DIR = mkdtempSync2(join27(tmpdir2(), "aka-judge-cfg-"));
|
|
36646
37577
|
}
|
|
36647
37578
|
return env;
|
|
36648
37579
|
}
|
|
@@ -36677,7 +37608,7 @@ function runJudge(hits, deps) {
|
|
|
36677
37608
|
if (typeof deps.spawn !== "function") {
|
|
36678
37609
|
throw new TypeError("runJudge requires deps.spawn \u2014 there is no live-spawn fallback");
|
|
36679
37610
|
}
|
|
36680
|
-
const rubric = deps.loadRubric?.() ??
|
|
37611
|
+
const rubric = deps.loadRubric?.() ?? readFileSync17(DEFAULT_RUBRIC_PATH, "utf8");
|
|
36681
37612
|
const hitsJsonl = hits.map((h) => JSON.stringify(toJudgePayload(h))).join("\n");
|
|
36682
37613
|
const fullPrompt = `${rubric}
|
|
36683
37614
|
|
|
@@ -36947,10 +37878,10 @@ function resolveCreatedBy() {
|
|
|
36947
37878
|
}
|
|
36948
37879
|
function loadRubric() {
|
|
36949
37880
|
const here = dirname8(fileURLToPath4(import.meta.url));
|
|
36950
|
-
const shipped =
|
|
36951
|
-
if (existsSync12(shipped)) return
|
|
36952
|
-
return
|
|
36953
|
-
|
|
37881
|
+
const shipped = join28(here, "triage-rubric.md");
|
|
37882
|
+
if (existsSync12(shipped)) return readFileSync18(shipped, "utf8");
|
|
37883
|
+
return readFileSync18(
|
|
37884
|
+
join28(here, "..", "..", "..", "packages", "setup-wizard", "assets", "triage-rubric.md"),
|
|
36954
37885
|
"utf8"
|
|
36955
37886
|
);
|
|
36956
37887
|
}
|
|
@@ -36960,7 +37891,7 @@ async function main() {
|
|
|
36960
37891
|
argv,
|
|
36961
37892
|
// fd 0 = stdin; the wizard pipes `backfill.js --triage` into this on preview.
|
|
36962
37893
|
// Called only on the preview path — the confirm path never reads a stream.
|
|
36963
|
-
readStream: (streamPath) => streamPath !== void 0 ?
|
|
37894
|
+
readStream: (streamPath) => streamPath !== void 0 ? readFileSync18(streamPath, "utf8") : readFileSync18(0, "utf8"),
|
|
36964
37895
|
runJudge: (hits) => runJudge(hits, { spawn: spawnClaude, loadRubric }),
|
|
36965
37896
|
// The distinct model-judge egress consent, read from settings.json. When it
|
|
36966
37897
|
// is absent or stale the preview skips the judge instead of sending findings
|