@akasecurity/ai-tc-claude-code 0.9.10 → 0.9.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/plugin.json +1 -1
- package/commands/scan.md +1 -1
- package/commands/setup.md +31 -3
- package/package.json +4 -4
- package/scripts/apply-suppressions.js +1761 -947
- package/scripts/backfill.js +2097 -1184
- package/scripts/content-retention.js +33995 -0
- package/scripts/filescan.js +2149 -1102
- package/scripts/firstrun.js +1989 -1063
- package/scripts/history-sync.js +1943 -1037
- package/scripts/intro.js +530 -120
- package/scripts/message-display.js +1744 -930
- package/scripts/onboard.js +1748 -925
- package/scripts/post-model-switch.js +560 -144
- package/scripts/post-tool-use.js +2119 -1047
- package/scripts/pre-model-switch.js +2035 -1142
- package/scripts/pre-tool-use.js +2101 -1180
- package/scripts/query.js +2066 -1075
- package/scripts/reconcile.js +2058 -1165
- package/scripts/remediate.js +2091 -1176
- package/scripts/scan-worker.js +388 -74
- package/scripts/session-start.js +2025 -1108
- package/scripts/start-light.js +528 -118
- package/scripts/statusline.js +2031 -1138
- package/scripts/stop.js +791 -154
- package/scripts/sync.js +2144 -1099
- package/scripts/user-prompt-submit.js +2089 -1174
package/scripts/filescan.js
CHANGED
|
@@ -50,7 +50,7 @@ var require_ignore = __commonJS({
|
|
|
50
50
|
var REGEX_SPLITALL_CRLF = /\r?\n/g;
|
|
51
51
|
var REGEX_TEST_INVALID_PATH = /^\.{0,2}\/|^\.{1,2}$/;
|
|
52
52
|
var REGEX_TEST_TRAILING_SLASH = /\/$/;
|
|
53
|
-
var
|
|
53
|
+
var SLASH3 = "/";
|
|
54
54
|
var TMP_KEY_IGNORE = "node-ignore";
|
|
55
55
|
if (typeof Symbol !== "undefined") {
|
|
56
56
|
TMP_KEY_IGNORE = /* @__PURE__ */ Symbol.for("node-ignore");
|
|
@@ -422,11 +422,11 @@ var require_ignore = __commonJS({
|
|
|
422
422
|
if (!REGEX_TEST_TRAILING_SLASH.test(path)) {
|
|
423
423
|
return this.test(path);
|
|
424
424
|
}
|
|
425
|
-
const slices = path.split(
|
|
425
|
+
const slices = path.split(SLASH3).filter(Boolean);
|
|
426
426
|
slices.pop();
|
|
427
427
|
if (slices.length) {
|
|
428
428
|
const parent = this._t(
|
|
429
|
-
slices.join(
|
|
429
|
+
slices.join(SLASH3) + SLASH3,
|
|
430
430
|
this._testCache,
|
|
431
431
|
true,
|
|
432
432
|
slices
|
|
@@ -442,14 +442,14 @@ var require_ignore = __commonJS({
|
|
|
442
442
|
return cache[path];
|
|
443
443
|
}
|
|
444
444
|
if (!slices) {
|
|
445
|
-
slices = path.split(
|
|
445
|
+
slices = path.split(SLASH3).filter(Boolean);
|
|
446
446
|
}
|
|
447
447
|
slices.pop();
|
|
448
448
|
if (!slices.length) {
|
|
449
449
|
return cache[path] = this._rules.test(path, checkUnignored, MODE_IGNORE);
|
|
450
450
|
}
|
|
451
451
|
const parent = this._t(
|
|
452
|
-
slices.join(
|
|
452
|
+
slices.join(SLASH3) + SLASH3,
|
|
453
453
|
cache,
|
|
454
454
|
checkUnignored,
|
|
455
455
|
slices
|
|
@@ -492,8 +492,8 @@ var require_ignore = __commonJS({
|
|
|
492
492
|
});
|
|
493
493
|
|
|
494
494
|
// ../../packages/plugin-sdk/src/config.ts
|
|
495
|
-
import { existsSync as
|
|
496
|
-
import { join as
|
|
495
|
+
import { existsSync as existsSync8 } from "fs";
|
|
496
|
+
import { join as join16 } from "path";
|
|
497
497
|
|
|
498
498
|
// ../../packages/persistence/src/attached-derived.ts
|
|
499
499
|
import { rmSync } from "fs";
|
|
@@ -506,6 +506,14 @@ var ATTACHED_FORWARD_DROPS_FILENAME = "attached-forward-drops.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
|
|
|
@@ -20670,6 +20702,15 @@ var FindingCategory = external_exports.enum([
|
|
|
20670
20702
|
]).meta({ id: "FindingCategory" });
|
|
20671
20703
|
var FindingOrigin = external_exports.enum(["in-flight", "at-rest"]).meta({ id: "FindingOrigin" });
|
|
20672
20704
|
var FindingStatus = external_exports.enum(["open", "handled", "resolved", "dismissed"]).meta({ id: "FindingStatus" });
|
|
20705
|
+
var SyncFailureReason = external_exports.enum(["deployment_refused", "payload_invalid", "detached_undelivered"]).meta({ id: "SyncFailureReason" });
|
|
20706
|
+
var FindingDeliveryState = external_exports.enum(["sent", "queued", "not_sent", "never_offered", "local_scan"]).meta({ id: "FindingDeliveryState" });
|
|
20707
|
+
var FindingDelivery = external_exports.object({
|
|
20708
|
+
state: FindingDeliveryState,
|
|
20709
|
+
// The delivery time for `sent`; the failure time for `not_sent` when recorded.
|
|
20710
|
+
at: external_exports.iso.datetime().optional(),
|
|
20711
|
+
// Only on `not_sent`, and only when a known reason was recorded.
|
|
20712
|
+
reason: SyncFailureReason.optional()
|
|
20713
|
+
}).meta({ id: "FindingDelivery" });
|
|
20673
20714
|
var ResolutionMethod = external_exports.enum([
|
|
20674
20715
|
"enforced-in-flight",
|
|
20675
20716
|
"fixed-at-source",
|
|
@@ -20726,7 +20767,10 @@ var FindingInstance = external_exports.object({
|
|
|
20726
20767
|
// The session that event belongs to, when it has one — the seam a
|
|
20727
20768
|
// per-instance "view session" link needs. Absent for events captured
|
|
20728
20769
|
// outside a session.
|
|
20729
|
-
sessionId: external_exports.string().optional()
|
|
20770
|
+
sessionId: external_exports.string().optional(),
|
|
20771
|
+
// The delivery state of the event above (see FindingDelivery). Optional so
|
|
20772
|
+
// readers that do not project it stay valid.
|
|
20773
|
+
delivery: FindingDelivery.optional()
|
|
20730
20774
|
}).meta({ id: "FindingInstance" });
|
|
20731
20775
|
var FindingGroup = external_exports.object({
|
|
20732
20776
|
id: external_exports.string(),
|
|
@@ -20743,13 +20787,11 @@ var FindingGroup = external_exports.object({
|
|
|
20743
20787
|
latestDetectedAt: external_exports.iso.datetime(),
|
|
20744
20788
|
instances: external_exports.array(FindingInstance),
|
|
20745
20789
|
// Derived from instances' statuses with open-dominates precedence (see
|
|
20746
|
-
//
|
|
20790
|
+
// foldGroupStatus). Undefined only when no instance carries a status.
|
|
20747
20791
|
status: FindingStatus.optional(),
|
|
20748
|
-
// The distinct people across the WHOLE group, not just the
|
|
20749
|
-
//
|
|
20750
|
-
//
|
|
20751
|
-
// instance carries a user, or when the store supplied whole-group folds
|
|
20752
|
-
// without one.
|
|
20792
|
+
// The distinct people across the WHOLE group, not just the instances
|
|
20793
|
+
// carried here. Undefined when no instance carries a user, or when the
|
|
20794
|
+
// store supplied whole-group folds without one.
|
|
20753
20795
|
users: external_exports.array(FindingUser).optional()
|
|
20754
20796
|
}).meta({ id: "FindingGroup" });
|
|
20755
20797
|
var FindingStats = external_exports.object({
|
|
@@ -20778,21 +20820,34 @@ var FindingFacets = external_exports.object({
|
|
|
20778
20820
|
// counted under no value.
|
|
20779
20821
|
status: external_exports.array(FindingFacetItem),
|
|
20780
20822
|
// Host tool (attributes.tool_name). Present only on the instance-level
|
|
20781
|
-
// reads, which can filter by it; the
|
|
20823
|
+
// reads, which can filter by it; the type-level read omits the dimension
|
|
20782
20824
|
// because a group spans tools.
|
|
20783
|
-
tool: external_exports.array(FindingFacetItem).optional()
|
|
20825
|
+
tool: external_exports.array(FindingFacetItem).optional(),
|
|
20826
|
+
// Delivery states (FindingDeliveryState). Present only on the
|
|
20827
|
+
// instance-level reads, like `tool`.
|
|
20828
|
+
deployment: external_exports.array(FindingFacetItem).optional()
|
|
20784
20829
|
}).meta({ id: "FindingFacets" });
|
|
20785
|
-
var
|
|
20786
|
-
|
|
20830
|
+
var FindingTypeSummary = FindingGroup.omit({ instances: true, match: true }).meta({
|
|
20831
|
+
id: "FindingTypeSummary"
|
|
20832
|
+
});
|
|
20833
|
+
var DEFAULT_FINDING_TYPES_LIMIT = 50;
|
|
20834
|
+
var MAX_FINDING_TYPES_LIMIT = 100;
|
|
20835
|
+
var ListFindingTypesQuery = external_exports.object({
|
|
20787
20836
|
// NOTE: severity filters by Severity (critical/high/medium/low), not by
|
|
20788
|
-
// FindingAction.
|
|
20837
|
+
// FindingAction. It narrows TYPES: a type's severity is the one its newest
|
|
20838
|
+
// firing version carries, and this list pages types.
|
|
20839
|
+
//
|
|
20840
|
+
// That is NOT a claim the findings of a type share it. A rule can hold several
|
|
20841
|
+
// definition versions at different severities, so a type kept by this filter
|
|
20842
|
+
// can hold findings that individually do not match — see totals.findings on
|
|
20843
|
+
// ListFindingTypesResponse, which counts them all.
|
|
20789
20844
|
severity: external_exports.array(Severity).optional(),
|
|
20790
20845
|
subtype: external_exports.array(external_exports.string()).optional(),
|
|
20791
20846
|
provider: external_exports.array(FindingProvider).optional(),
|
|
20792
20847
|
action: external_exports.array(FindingAction).optional(),
|
|
20793
|
-
// Matches a
|
|
20794
|
-
// individual
|
|
20795
|
-
//
|
|
20848
|
+
// Matches a type's DERIVED status (see FindingGroup.status), not its
|
|
20849
|
+
// individual findings' — so a filtered row's status always reads one of the
|
|
20850
|
+
// requested values.
|
|
20796
20851
|
status: external_exports.array(FindingStatus).optional(),
|
|
20797
20852
|
q: external_exports.string().optional(),
|
|
20798
20853
|
// Scope to findings whose event carries this session id (the Activity page's
|
|
@@ -20802,23 +20857,37 @@ var ListGroupedFindingsQuery = external_exports.object({
|
|
|
20802
20857
|
// from a time-scoped page (Activity's range) can carry that scope. Absent
|
|
20803
20858
|
// means all time — this list has no default window.
|
|
20804
20859
|
from: external_exports.iso.datetime().optional(),
|
|
20805
|
-
// A
|
|
20806
|
-
//
|
|
20807
|
-
//
|
|
20808
|
-
//
|
|
20809
|
-
//
|
|
20860
|
+
// A RULE id that must appear in the page even when the cursor has already
|
|
20861
|
+
// advanced past its sort position. This is what keeps the selected type
|
|
20862
|
+
// visible in the list once it paginates: the target is appended out of sort
|
|
20863
|
+
// order rather than scanned forward for. Never affects totals, facets or the
|
|
20864
|
+
// cursor. Unlike the grouped read this replaces, it names a rule only — an
|
|
20865
|
+
// instance id is resolved by `findingInstance`, which is a primary-key seek
|
|
20866
|
+
// and so is not bounded by what any page happens to hold.
|
|
20810
20867
|
includeId: external_exports.string().optional(),
|
|
20811
|
-
|
|
20812
|
-
limit: external_exports.coerce.number().int().min(1).max(100).optional(),
|
|
20868
|
+
limit: external_exports.coerce.number().int().min(1).max(MAX_FINDING_TYPES_LIMIT).optional(),
|
|
20813
20869
|
cursor: external_exports.string().optional()
|
|
20814
20870
|
});
|
|
20815
|
-
var
|
|
20871
|
+
var ListFindingTypesResponse = external_exports.object({
|
|
20816
20872
|
totals: external_exports.object({
|
|
20873
|
+
// Findings belonging to the matching TYPES — not findings that each match
|
|
20874
|
+
// the filters. The filters here select types, so a type that survives
|
|
20875
|
+
// contributes its whole instanceCount.
|
|
20876
|
+
//
|
|
20877
|
+
// `status` is the one exception, narrowed per finding via
|
|
20878
|
+
// countInstancesByStatus. `severity`, `provider` and `action` are not, so
|
|
20879
|
+
// this can exceed what the instance read reports for the same filters: a
|
|
20880
|
+
// rule whose severity moved between versions is kept on its newest and
|
|
20881
|
+
// still counts its older findings. Narrowing the other three needs
|
|
20882
|
+
// per-dimension counts the aggregate does not carry today.
|
|
20817
20883
|
findings: external_exports.number().int().nonnegative(),
|
|
20818
|
-
|
|
20884
|
+
// Counts TYPES, which is the unit this read pages. The instance read's
|
|
20885
|
+
// own totals count findings; the two deliberately answer different
|
|
20886
|
+
// questions and are never summed.
|
|
20887
|
+
types: external_exports.number().int().nonnegative()
|
|
20819
20888
|
}),
|
|
20820
20889
|
facets: FindingFacets,
|
|
20821
|
-
items: external_exports.array(
|
|
20890
|
+
items: external_exports.array(FindingTypeSummary),
|
|
20822
20891
|
nextCursor: external_exports.string().nullable(),
|
|
20823
20892
|
// Present only on session-scoped queries (`sessionId` set): per ruleId, how
|
|
20824
20893
|
// many times that rule fired in the session's persisted transcript. Findings
|
|
@@ -20826,7 +20895,7 @@ var ListGroupedFindingsResponse = external_exports.object({
|
|
|
20826
20895
|
// every firing, so the two numbers legitimately differ — this map lets a
|
|
20827
20896
|
// session-scoped view show both.
|
|
20828
20897
|
sessionFirings: external_exports.record(external_exports.string(), external_exports.number().int().nonnegative()).optional()
|
|
20829
|
-
}).meta({ id: "
|
|
20898
|
+
}).meta({ id: "ListFindingTypesResponse" });
|
|
20830
20899
|
var ApplyFindingActionRequest = external_exports.object({
|
|
20831
20900
|
// 'quarantined' is system-assigned (see FindingAction) — clients may not set
|
|
20832
20901
|
// it, so it is excluded from the request contract. The mapping helper
|
|
@@ -20856,16 +20925,19 @@ var DEFAULT_FLAT_FINDINGS_LIMIT = 50;
|
|
|
20856
20925
|
var MAX_FLAT_FINDINGS_LIMIT = 200;
|
|
20857
20926
|
var ListFindingInstancesQuery = external_exports.object({
|
|
20858
20927
|
severity: external_exports.array(Severity).optional(),
|
|
20859
|
-
// Rule ids, the same vocabulary the
|
|
20928
|
+
// Rule ids, the same vocabulary the types list's `subtype` carries. Pinning
|
|
20929
|
+
// ONE of them is how the master/detail view scopes its right-hand panel.
|
|
20860
20930
|
subtype: external_exports.array(external_exports.string()).optional(),
|
|
20861
20931
|
provider: external_exports.array(FindingProvider).optional(),
|
|
20862
20932
|
action: external_exports.array(FindingAction).optional(),
|
|
20863
20933
|
// Matches each instance's OWN derived status (deriveFindingStatus), unlike
|
|
20864
|
-
// the
|
|
20934
|
+
// the types query's type-level fold.
|
|
20865
20935
|
status: external_exports.array(FindingStatus).optional(),
|
|
20866
20936
|
// Exact host-tool names (attributes.tool_name, e.g. 'Bash'). A real filter,
|
|
20867
20937
|
// where the free-text `q` can only match the rendered "via Bash" label.
|
|
20868
20938
|
tool: external_exports.array(external_exports.string()).optional(),
|
|
20939
|
+
// The delivery state of each finding's event (see FindingDelivery).
|
|
20940
|
+
deployment: external_exports.array(FindingDeliveryState).optional(),
|
|
20869
20941
|
// Exact repository / file-path matches, for the drill-down out of the
|
|
20870
20942
|
// locations view. A row whose event carries no repo/file matches neither.
|
|
20871
20943
|
repo: external_exports.string().optional(),
|
|
@@ -20878,37 +20950,51 @@ var ListFindingInstancesQuery = external_exports.object({
|
|
|
20878
20950
|
});
|
|
20879
20951
|
var ListFindingInstancesResponse = external_exports.object({
|
|
20880
20952
|
// Instances matching the filters across the whole scope, not just this
|
|
20881
|
-
// page — cursor-independent, like the
|
|
20953
|
+
// page — cursor-independent, like the types list's totals.
|
|
20882
20954
|
totals: external_exports.object({ findings: external_exports.number().int().nonnegative() }),
|
|
20883
|
-
// Counts in INSTANCES here, where the
|
|
20955
|
+
// Counts in INSTANCES here, where the types response counts types. Each
|
|
20884
20956
|
// dimension still excludes its own filter.
|
|
20885
20957
|
facets: FindingFacets,
|
|
20886
20958
|
items: external_exports.array(FindingInstanceDetail),
|
|
20887
20959
|
nextCursor: external_exports.string().nullable()
|
|
20888
20960
|
}).meta({ id: "ListFindingInstancesResponse" });
|
|
20889
|
-
var
|
|
20890
|
-
|
|
20891
|
-
|
|
20892
|
-
|
|
20893
|
-
|
|
20894
|
-
|
|
20895
|
-
|
|
20896
|
-
//
|
|
20897
|
-
//
|
|
20898
|
-
|
|
20899
|
-
|
|
20900
|
-
// chips, and the count is what conveys scale.
|
|
20901
|
-
ruleIds: external_exports.array(external_exports.string())
|
|
20902
|
-
}).meta({ id: "FindingLocationFile" });
|
|
20903
|
-
var FindingLocationRepo = external_exports.object({
|
|
20961
|
+
var ListFindingInstancesPage = external_exports.object({
|
|
20962
|
+
items: external_exports.array(FindingInstanceDetail),
|
|
20963
|
+
nextCursor: external_exports.string().nullable()
|
|
20964
|
+
}).meta({ id: "ListFindingInstancesPage" });
|
|
20965
|
+
var FindingLocationSummary = external_exports.object({
|
|
20966
|
+
// Opaque, stable, minted from the pair by encodeLocationId. It exists
|
|
20967
|
+
// because a location's identity is two values and a URL param carries one:
|
|
20968
|
+
// `?loc=` names a location the way `?rule=` names a type. Only ever compared
|
|
20969
|
+
// for EQUALITY — the page's selection check, this read's `includeId`, the
|
|
20970
|
+
// client's page dedupe — never decoded, and never a sort key.
|
|
20971
|
+
id: external_exports.string(),
|
|
20904
20972
|
/** Empty when the instances carried no repo attribute. */
|
|
20905
20973
|
repo: external_exports.string(),
|
|
20974
|
+
// Empty when the instances carried no file path (a prompt, or a tool call
|
|
20975
|
+
// with no file attribution). Both halves empty is a real location — usually
|
|
20976
|
+
// the largest one in a store — and is selectable like any other.
|
|
20977
|
+
file: external_exports.string(),
|
|
20906
20978
|
instanceCount: external_exports.number().int().nonnegative(),
|
|
20979
|
+
// The WORST severity present, not the first row's. It is this list's primary
|
|
20980
|
+
// sort key, so it is also what explains why a row is where it is, and it is
|
|
20981
|
+
// how a reader decides what to open without opening everything.
|
|
20907
20982
|
maxSeverity: Severity,
|
|
20908
20983
|
latestDetectedAt: external_exports.iso.datetime(),
|
|
20984
|
+
// Folded from the instances' derived statuses with the same open-dominates
|
|
20985
|
+
// precedence a group uses, so it answers "is anything left to do here" and
|
|
20986
|
+
// not much more: a location holding 1 open among 40 resolved reads like one
|
|
20987
|
+
// holding 40 open. That loss is accepted — the panel beside this list
|
|
20988
|
+
// carries each finding's own status, and instanceCount sits next to the
|
|
20989
|
+
// badge.
|
|
20909
20990
|
status: FindingStatus.optional(),
|
|
20910
|
-
|
|
20911
|
-
|
|
20991
|
+
// Every distinct rule seen at this location, UNCAPPED — so the length is a
|
|
20992
|
+
// tally rather than a sample and a row can say how many there are. Bounded
|
|
20993
|
+
// by the ruleset, not by the store. The view bounds what it DISPLAYS.
|
|
20994
|
+
ruleIds: external_exports.array(external_exports.string())
|
|
20995
|
+
}).meta({ id: "FindingLocationSummary" });
|
|
20996
|
+
var DEFAULT_FINDING_LOCATIONS_LIMIT = 50;
|
|
20997
|
+
var MAX_FINDING_LOCATIONS_LIMIT = 100;
|
|
20912
20998
|
var ListFindingLocationsQuery = external_exports.object({
|
|
20913
20999
|
severity: external_exports.array(Severity).optional(),
|
|
20914
21000
|
subtype: external_exports.array(external_exports.string()).optional(),
|
|
@@ -20918,21 +21004,47 @@ var ListFindingLocationsQuery = external_exports.object({
|
|
|
20918
21004
|
// instances that match, and folds its status from those.
|
|
20919
21005
|
status: external_exports.array(FindingStatus).optional(),
|
|
20920
21006
|
tool: external_exports.array(external_exports.string()).optional(),
|
|
21007
|
+
// The delivery state of each finding's event (see FindingDelivery).
|
|
21008
|
+
deployment: external_exports.array(FindingDeliveryState).optional(),
|
|
20921
21009
|
q: external_exports.string().optional(),
|
|
20922
21010
|
sessionId: external_exports.string().optional(),
|
|
20923
21011
|
from: external_exports.iso.datetime().optional(),
|
|
20924
|
-
|
|
21012
|
+
// A LOCATION id (see FindingLocationSummary.id) that must appear in the page
|
|
21013
|
+
// even when the cursor has already advanced past its sort position — the
|
|
21014
|
+
// counterpart of ListFindingTypesQuery.includeId, and needed far more often
|
|
21015
|
+
// here. Selecting a row pushes the URL, which re-renders the server and resets
|
|
21016
|
+
// the client's page cache to page 0; with distinct (repo, file) pairs running
|
|
21017
|
+
// into the thousands, a selection sitting off page 0 is the ordinary case
|
|
21018
|
+
// rather than a deep-link corner. Never affects totals, facets or the cursor.
|
|
21019
|
+
includeId: external_exports.string().optional(),
|
|
21020
|
+
limit: external_exports.coerce.number().int().min(1).max(MAX_FINDING_LOCATIONS_LIMIT).optional(),
|
|
21021
|
+
cursor: external_exports.string().optional()
|
|
20925
21022
|
});
|
|
20926
21023
|
var ListFindingLocationsResponse = external_exports.object({
|
|
20927
21024
|
totals: external_exports.object({
|
|
21025
|
+
// Findings matching the filters across the whole scope. Unlike the types
|
|
21026
|
+
// read's same-named field this needs no caveat: the filters here narrow
|
|
21027
|
+
// per finding, so this is the sum of every row's instanceCount.
|
|
20928
21028
|
findings: external_exports.number().int().nonnegative(),
|
|
20929
|
-
|
|
20930
|
-
|
|
21029
|
+
// Counts LOCATIONS, the unit this read pages — the number the paginator
|
|
21030
|
+
// states. The facets beside it count FINDINGS (see below); a surface
|
|
21031
|
+
// showing both says which is which.
|
|
21032
|
+
locations: external_exports.number().int().nonnegative()
|
|
20931
21033
|
}),
|
|
20932
|
-
|
|
20933
|
-
|
|
20934
|
-
|
|
20935
|
-
|
|
21034
|
+
// Counts in FINDINGS, where the types response counts types, each dimension
|
|
21035
|
+
// still excluding its own filter. Deliberately not locations: counting those
|
|
21036
|
+
// needs a set of location keys per dimension per value — memory tracking the
|
|
21037
|
+
// store times the vocabulary, in a read whose scan promises flat memory —
|
|
21038
|
+
// and the cheap per-location version is not an approximation but WRONG. A
|
|
21039
|
+
// location holding {claudecode, block} and {codex, warn} would survive
|
|
21040
|
+
// provider=claudecode AND action=warn, under which no single finding
|
|
21041
|
+
// matches, so the facet would contradict the instanceCount this whole view
|
|
21042
|
+
// rests on. Findings also keep the toolbar in the same unit as the page
|
|
21043
|
+
// tally and the panel it sits above.
|
|
21044
|
+
facets: FindingFacets,
|
|
21045
|
+
/** Sorted by max severity, then most recent, then (repo, file). */
|
|
21046
|
+
items: external_exports.array(FindingLocationSummary),
|
|
21047
|
+
nextCursor: external_exports.string().nullable()
|
|
20936
21048
|
}).meta({ id: "ListFindingLocationsResponse" });
|
|
20937
21049
|
|
|
20938
21050
|
// ../../packages/schema/src/zod/meta.ts
|
|
@@ -21096,6 +21208,10 @@ var CaptureAttributes = external_exports.object({
|
|
|
21096
21208
|
// to 'allow' — the enforcement audit trail's link back to the grant that
|
|
21097
21209
|
// authorized the bypass.
|
|
21098
21210
|
exception_ids: external_exports.array(external_exports.guid()).optional(),
|
|
21211
|
+
// The persisted spellings of EventMetadata's messageId/conversationId — the
|
|
21212
|
+
// join back to the `llm_call` leaf for the same assistant turn.
|
|
21213
|
+
message_id: external_exports.string().optional(),
|
|
21214
|
+
conversation_id: external_exports.string().optional(),
|
|
21099
21215
|
// Whole milliseconds this capture's inspection blocked its caller — the
|
|
21100
21216
|
// plugin's own added latency (see EventMetadata.inspectionMs, whose value
|
|
21101
21217
|
// this is). Promoted to the `inspection_ms` generated column so the facet is
|
|
@@ -21104,7 +21220,19 @@ var CaptureAttributes = external_exports.object({
|
|
|
21104
21220
|
// inline json_extract and is not itself an optimization.
|
|
21105
21221
|
// ABSENT on replayed captures (backfill / worktree scan) and on rows written
|
|
21106
21222
|
// before the measurement shipped — never present as a placeholder 0.
|
|
21107
|
-
inspection_ms: external_exports.number().int().nonnegative().optional()
|
|
21223
|
+
inspection_ms: external_exports.number().int().nonnegative().optional(),
|
|
21224
|
+
// What a `redact` this capture could not carry out became instead (see
|
|
21225
|
+
// EventMetadata.redactDegradedTo, whose value this is). Present only when a
|
|
21226
|
+
// degrade actually happened, so absence is the ordinary case rather than a
|
|
21227
|
+
// reader having to distinguish it from a zero.
|
|
21228
|
+
//
|
|
21229
|
+
// PER CAPTURE, while `inspection_findings.action_taken` is per finding —
|
|
21230
|
+
// so on a multi-finding row this does not say which finding degraded, and
|
|
21231
|
+
// its presence does not mean the fallback decided the capture's action. A
|
|
21232
|
+
// capture denied by another finding's own Block policy carries `block`
|
|
21233
|
+
// here too. The full statement is on EventMetadata.redactDegradedTo; it is
|
|
21234
|
+
// repeated rather than referenced because a store reader opens this file.
|
|
21235
|
+
redact_degraded_to: ActionTaken.optional()
|
|
21108
21236
|
}).catchall(external_exports.unknown());
|
|
21109
21237
|
var ToolCallInspection = external_exports.object({
|
|
21110
21238
|
ruleId: external_exports.string().min(1),
|
|
@@ -21303,7 +21431,17 @@ var AuditEvent = external_exports.object({
|
|
|
21303
21431
|
/** `share` to a first-party/internal destination. */
|
|
21304
21432
|
internal: external_exports.boolean(),
|
|
21305
21433
|
/** Event needs review (e.g. unverified egress). */
|
|
21306
|
-
flagged: external_exports.boolean()
|
|
21434
|
+
flagged: external_exports.boolean(),
|
|
21435
|
+
/**
|
|
21436
|
+
* The body this event's `title` is drawn from was cleared by local body
|
|
21437
|
+
* expiry, so an EMPTY title here means "gone", not "never had one".
|
|
21438
|
+
*
|
|
21439
|
+
* A separate flag rather than a sentinel written into `title`: the title is
|
|
21440
|
+
* rendered text, and a store-layer module that invented display copy for it
|
|
21441
|
+
* would be choosing words the view is supposed to choose. Additive and
|
|
21442
|
+
* defaulted, so an older producer still validates.
|
|
21443
|
+
*/
|
|
21444
|
+
bodyExpired: external_exports.boolean().default(false)
|
|
21307
21445
|
}).meta({ id: "ActivityAuditEvent" });
|
|
21308
21446
|
var ActivitySessionSummary = external_exports.object({
|
|
21309
21447
|
id: external_exports.string(),
|
|
@@ -22101,6 +22239,14 @@ var ControlPlaneErrorBody = external_exports.object({
|
|
|
22101
22239
|
message: external_exports.string().optional()
|
|
22102
22240
|
}).optional()
|
|
22103
22241
|
});
|
|
22242
|
+
var RemoteFailureKind = external_exports.enum([
|
|
22243
|
+
"unauthorized",
|
|
22244
|
+
"forbidden",
|
|
22245
|
+
"route-absent",
|
|
22246
|
+
"invalid-request",
|
|
22247
|
+
"rejected",
|
|
22248
|
+
"unreachable"
|
|
22249
|
+
]);
|
|
22104
22250
|
var AttachDeviceRequest = external_exports.object({
|
|
22105
22251
|
// This machine's own continuity id, so re-attaching ROTATES the credential
|
|
22106
22252
|
// on one machine record instead of producing a second one. Client-minted
|
|
@@ -22636,6 +22782,12 @@ var EventMetadata = external_exports.object({
|
|
|
22636
22782
|
// to 'allow' — the enforcement audit trail's link back to the grant that
|
|
22637
22783
|
// authorized the bypass. Absent on captures where no exception applied.
|
|
22638
22784
|
exceptionIds: external_exports.array(external_exports.guid()).optional(),
|
|
22785
|
+
// The assistant message this capture belongs to, and the conversation it sits
|
|
22786
|
+
// in — set by the browser extension's network capture so a stored `response`
|
|
22787
|
+
// row can be joined to the `llm_call` leaf describing the same turn. Absent
|
|
22788
|
+
// on every other capture path, which has no such id.
|
|
22789
|
+
messageId: external_exports.string().optional(),
|
|
22790
|
+
conversationId: external_exports.string().optional(),
|
|
22639
22791
|
// How long THIS capture's inspection blocked its caller, in whole
|
|
22640
22792
|
// milliseconds — the plugin's own added latency, NOT the LLM call it sat in
|
|
22641
22793
|
// front of. Measured inside `capture()` (@akasecurity/plugin-sdk) across
|
|
@@ -22648,7 +22800,37 @@ var EventMetadata = external_exports.object({
|
|
|
22648
22800
|
// Absent is also what every pre-measurement client writes, and what a
|
|
22649
22801
|
// clock failure degrades to — a reader must treat absence as "not measured"
|
|
22650
22802
|
// and never as a zero, which would read as "inspection is free".
|
|
22651
|
-
inspectionMs: external_exports.number().int().nonnegative().optional()
|
|
22803
|
+
inspectionMs: external_exports.number().int().nonnegative().optional(),
|
|
22804
|
+
// What a `redact` this capture COULD NOT CARRY OUT became instead — the
|
|
22805
|
+
// workspace's `redactFallback`, applied because the field could not be
|
|
22806
|
+
// masked in place (a shell command, a URL, or any argument on a host whose
|
|
22807
|
+
// hook contract offers no rewrite channel).
|
|
22808
|
+
//
|
|
22809
|
+
// It exists because the action alone cannot say why. A finding recorded as
|
|
22810
|
+
// `warn` reads identically whether its detection was ASSIGNED Warn or was
|
|
22811
|
+
// assigned Redact on a field that could not take one — and those are
|
|
22812
|
+
// different facts about the same row: the first is a policy the user chose,
|
|
22813
|
+
// the second is a masking the host could not perform. Absent means no
|
|
22814
|
+
// degrade happened, which is every ordinary capture.
|
|
22815
|
+
//
|
|
22816
|
+
// TWO LIMITS a reader of a stored row has to know, because the grain here
|
|
22817
|
+
// is the CAPTURE while `actionTaken` is per FINDING:
|
|
22818
|
+
//
|
|
22819
|
+
// - It does not say WHICH finding degraded. A capture carrying a degraded
|
|
22820
|
+
// `redact` alongside a finding ASSIGNED the same action stores both
|
|
22821
|
+
// identically and one reason for the pair; attributing it to both
|
|
22822
|
+
// describes the assigned one wrongly, and to neither loses the degrade.
|
|
22823
|
+
// - PRESENCE IS NOT CAUSATION. The value is the action the lost redact
|
|
22824
|
+
// became, not the reason the capture ended as it did — a capture denied
|
|
22825
|
+
// by some other finding's own Block policy still carries `block` here,
|
|
22826
|
+
// and clearing the workspace's fallback would not have let it through.
|
|
22827
|
+
// Gate on the value against what a fallback can produce; never read the
|
|
22828
|
+
// field's presence as "this was the fallback's doing".
|
|
22829
|
+
//
|
|
22830
|
+
// Both are pinned as behaviour in @akasecurity/plugin-sdk's runtime suite.
|
|
22831
|
+
// Closing either means moving the reason onto the finding row, which
|
|
22832
|
+
// already carries its own action.
|
|
22833
|
+
redactDegradedTo: ActionTaken.optional()
|
|
22652
22834
|
}).meta({ id: "EventMetadata" });
|
|
22653
22835
|
var Event = external_exports.object({
|
|
22654
22836
|
id: external_exports.guid(),
|
|
@@ -22758,7 +22940,32 @@ var RotateKeyInput = external_exports.object({
|
|
|
22758
22940
|
confirmation: external_exports.string()
|
|
22759
22941
|
});
|
|
22760
22942
|
|
|
22943
|
+
// ../../packages/schema/src/zod/finding-delivery.ts
|
|
22944
|
+
var KNOWN_REASONS = SyncFailureReason.options;
|
|
22945
|
+
function knownReason(value) {
|
|
22946
|
+
return value !== null && KNOWN_REASONS.includes(value) ? value : void 0;
|
|
22947
|
+
}
|
|
22948
|
+
function deriveFindingDelivery(row) {
|
|
22949
|
+
if (row.kind === "code_change") return { state: "local_scan" };
|
|
22950
|
+
if (row.syncedAt !== null && row.syncedAt > 0) {
|
|
22951
|
+
return { state: "sent", at: epochMillisToIso(row.syncedAt) };
|
|
22952
|
+
}
|
|
22953
|
+
if (row.syncedAt !== null) {
|
|
22954
|
+
const reason = knownReason(row.syncFailure);
|
|
22955
|
+
return {
|
|
22956
|
+
state: "not_sent",
|
|
22957
|
+
...row.syncFailedAt === null ? {} : { at: epochMillisToIso(row.syncFailedAt) },
|
|
22958
|
+
...reason === void 0 ? {} : { reason }
|
|
22959
|
+
};
|
|
22960
|
+
}
|
|
22961
|
+
if (row.outboxOwed === 1 || row.syncClaimedAt !== null) return { state: "queued" };
|
|
22962
|
+
return { state: "never_offered" };
|
|
22963
|
+
}
|
|
22964
|
+
|
|
22761
22965
|
// ../../packages/schema/src/zod/findings-group-build.ts
|
|
22966
|
+
function lookupOwn(map2, key) {
|
|
22967
|
+
return Object.hasOwn(map2, key) ? map2[key] : void 0;
|
|
22968
|
+
}
|
|
22762
22969
|
function toApiAction(dbVal) {
|
|
22763
22970
|
const map2 = {
|
|
22764
22971
|
log: "monitored",
|
|
@@ -22767,7 +22974,7 @@ function toApiAction(dbVal) {
|
|
|
22767
22974
|
warn: "warned",
|
|
22768
22975
|
allow: "allowed"
|
|
22769
22976
|
};
|
|
22770
|
-
return map2
|
|
22977
|
+
return lookupOwn(map2, dbVal) ?? "allowed";
|
|
22771
22978
|
}
|
|
22772
22979
|
function toApiCategory(dbVal) {
|
|
22773
22980
|
if (dbVal === "code_context") return "source_code";
|
|
@@ -22775,13 +22982,18 @@ function toApiCategory(dbVal) {
|
|
|
22775
22982
|
return parsed2.success ? parsed2.data : "custom";
|
|
22776
22983
|
}
|
|
22777
22984
|
function toApiProvider(sourceTool) {
|
|
22778
|
-
return TOOL_TO_HARNESS
|
|
22985
|
+
return lookupOwn(TOOL_TO_HARNESS, sourceTool) ?? HARNESS.Api;
|
|
22779
22986
|
}
|
|
22780
|
-
var
|
|
22987
|
+
var FINDING_STATUS_PRECEDENCE = [
|
|
22988
|
+
"open",
|
|
22989
|
+
"handled",
|
|
22990
|
+
"dismissed",
|
|
22991
|
+
"resolved"
|
|
22992
|
+
];
|
|
22781
22993
|
function foldGroupStatus(instanceStatuses) {
|
|
22782
22994
|
const statuses = new Set(instanceStatuses.filter((s) => s !== void 0));
|
|
22783
22995
|
if (statuses.size === 0) return void 0;
|
|
22784
|
-
for (const candidate of
|
|
22996
|
+
for (const candidate of FINDING_STATUS_PRECEDENCE) {
|
|
22785
22997
|
if (statuses.has(candidate)) return candidate;
|
|
22786
22998
|
}
|
|
22787
22999
|
return void 0;
|
|
@@ -22794,139 +23006,62 @@ function deriveFindingStatus(row) {
|
|
|
22794
23006
|
if (row.latestResolutionStatus === "dismissed") return "dismissed";
|
|
22795
23007
|
return "open";
|
|
22796
23008
|
}
|
|
22797
|
-
function distinctUsers(instances) {
|
|
22798
|
-
const seen = /* @__PURE__ */ new Set();
|
|
22799
|
-
const users = [];
|
|
22800
|
-
for (const i of instances) {
|
|
22801
|
-
if (i.user === void 0 || seen.has(i.user.id)) continue;
|
|
22802
|
-
seen.add(i.user.id);
|
|
22803
|
-
users.push(i.user);
|
|
22804
|
-
}
|
|
22805
|
-
return users;
|
|
22806
|
-
}
|
|
22807
23009
|
function sortUsers(users) {
|
|
22808
23010
|
return [...users].sort((a, b) => a.name.localeCompare(b.name) || a.id.localeCompare(b.id));
|
|
22809
23011
|
}
|
|
22810
|
-
function
|
|
22811
|
-
const overrides = opts.overrides;
|
|
23012
|
+
function buildFindingTypes(aggregates, opts = {}) {
|
|
22812
23013
|
const packNames = opts.packNames;
|
|
22813
|
-
const
|
|
22814
|
-
const
|
|
22815
|
-
|
|
22816
|
-
const
|
|
22817
|
-
|
|
22818
|
-
else byRuleId.set(row.ruleId, [row]);
|
|
22819
|
-
}
|
|
22820
|
-
const groups = [];
|
|
22821
|
-
for (const [ruleId, ruleRows] of byRuleId) {
|
|
22822
|
-
const instances = ruleRows.map((r) => {
|
|
22823
|
-
const effectiveDbAction = overrides?.get(r.id) ?? r.actionTaken;
|
|
22824
|
-
return {
|
|
22825
|
-
id: r.id,
|
|
22826
|
-
provider: toApiProvider(r.sourceTool),
|
|
22827
|
-
repo: r.repo,
|
|
22828
|
-
file: r.file,
|
|
22829
|
-
...r.toolName === void 0 ? {} : { toolName: r.toolName },
|
|
22830
|
-
...r.eventId === void 0 ? {} : { eventId: r.eventId },
|
|
22831
|
-
...r.sessionId === void 0 ? {} : { sessionId: r.sessionId },
|
|
22832
|
-
...r.user === void 0 ? {} : { user: r.user },
|
|
22833
|
-
action: toApiAction(effectiveDbAction),
|
|
22834
|
-
detectedAt: r.occurredAt,
|
|
22835
|
-
confidence: r.confidence,
|
|
22836
|
-
status: r.status
|
|
22837
|
-
};
|
|
22838
|
-
});
|
|
22839
|
-
const agg = aggregates?.get(ruleId);
|
|
22840
|
-
const users = agg ? sortUsers(agg.users ?? []) : distinctUsers(instances);
|
|
22841
|
-
const latestDetectedAt = agg?.latestDetectedAt ?? ruleRows.reduce(
|
|
22842
|
-
(max, r) => r.occurredAt > max ? r.occurredAt : max,
|
|
22843
|
-
ruleRows[0]?.occurredAt ?? (/* @__PURE__ */ new Date(0)).toISOString()
|
|
22844
|
-
);
|
|
22845
|
-
const seenProviders = /* @__PURE__ */ new Set();
|
|
22846
|
-
const providers = (agg ? [...new Set(agg.sourceTools.map(toApiProvider))].sort() : instances.map((i) => i.provider)).filter((p) => {
|
|
22847
|
-
if (seenProviders.has(p)) return false;
|
|
22848
|
-
seenProviders.add(p);
|
|
22849
|
-
return true;
|
|
22850
|
-
});
|
|
22851
|
-
const actionSet = new Set(
|
|
22852
|
-
agg ? agg.actionsTaken.map(toApiAction) : instances.map((i) => i.action)
|
|
22853
|
-
);
|
|
23014
|
+
const types = [];
|
|
23015
|
+
for (const [ruleId, agg] of aggregates) {
|
|
23016
|
+
const users = sortUsers(agg.users ?? []);
|
|
23017
|
+
const providers = [...new Set(agg.sourceTools.map(toApiProvider))].sort();
|
|
23018
|
+
const actionSet = new Set(agg.actionsTaken.map(toApiAction));
|
|
22854
23019
|
const aggregateAction = actionSet.size === 1 ? [...actionSet][0] ?? null : null;
|
|
22855
|
-
const
|
|
22856
|
-
const
|
|
22857
|
-
id: ruleId,
|
|
22858
|
-
name: packNames?.get(ruleId) ?? null
|
|
22859
|
-
};
|
|
22860
|
-
const apiCategory = toApiCategory(ruleRows[0]?.category ?? "custom");
|
|
22861
|
-
const policy = { id: `category:${apiCategory}`, name: apiCategory };
|
|
22862
|
-
const match = {
|
|
22863
|
-
maskedValue: ruleRows[0]?.maskedMatch ?? "",
|
|
22864
|
-
contextPrefix: ""
|
|
22865
|
-
// empty (pending privacy review)
|
|
22866
|
-
};
|
|
22867
|
-
const status = foldGroupStatus(
|
|
22868
|
-
agg ? agg.statusInputs.map(deriveFindingStatus) : instances.map((i) => i.status)
|
|
22869
|
-
);
|
|
22870
|
-
const group = {
|
|
23020
|
+
const apiCategory = toApiCategory(agg.category ?? "custom");
|
|
23021
|
+
const type = {
|
|
22871
23022
|
id: ruleId,
|
|
22872
23023
|
category: apiCategory,
|
|
22873
23024
|
subtype: ruleId,
|
|
22874
23025
|
// human label comes with pack metadata later
|
|
22875
|
-
severity,
|
|
22876
|
-
|
|
22877
|
-
|
|
22878
|
-
|
|
22879
|
-
instanceCount: agg?.instanceCount ?? instances.length,
|
|
23026
|
+
severity: agg.severity ?? "low",
|
|
23027
|
+
detection: { id: ruleId, name: packNames?.get(ruleId) ?? null },
|
|
23028
|
+
policy: { id: `category:${apiCategory}`, name: apiCategory },
|
|
23029
|
+
instanceCount: agg.instanceCount,
|
|
22880
23030
|
providers,
|
|
22881
23031
|
aggregateAction,
|
|
22882
|
-
latestDetectedAt,
|
|
22883
|
-
|
|
22884
|
-
status,
|
|
23032
|
+
latestDetectedAt: agg.latestDetectedAt,
|
|
23033
|
+
status: foldGroupStatus(agg.statusInputs.map(deriveFindingStatus)),
|
|
22885
23034
|
...users.length > 0 ? { users } : {}
|
|
22886
23035
|
};
|
|
22887
|
-
|
|
22888
|
-
|
|
22889
|
-
|
|
22890
|
-
haystackCache.set(group, buildHaystack(group, agg.searchText));
|
|
22891
|
-
}
|
|
23036
|
+
actionsCache.set(type, [...actionSet]);
|
|
23037
|
+
if (agg.searchText !== void 0) {
|
|
23038
|
+
haystackCache.set(type, buildHaystack(type, agg.searchText));
|
|
22892
23039
|
}
|
|
22893
|
-
|
|
23040
|
+
types.push(type);
|
|
22894
23041
|
}
|
|
22895
|
-
return
|
|
23042
|
+
return types;
|
|
22896
23043
|
}
|
|
22897
23044
|
var haystackCache = /* @__PURE__ */ new WeakMap();
|
|
22898
|
-
function buildHaystack(
|
|
23045
|
+
function buildHaystack(t, extra) {
|
|
22899
23046
|
return [
|
|
22900
|
-
|
|
22901
|
-
|
|
22902
|
-
|
|
22903
|
-
|
|
22904
|
-
|
|
22905
|
-
...g.instances.map((i) => i.repo),
|
|
22906
|
-
...g.instances.map((i) => i.file),
|
|
22907
|
-
...g.instances.map((i) => i.toolName ? `via ${i.toolName}` : ""),
|
|
22908
|
-
...g.instances.map((i) => i.id),
|
|
22909
|
-
// The people: the whole group's list when the store folded one, plus the
|
|
22910
|
-
// preview's own — the two overlap, and a haystack does not mind.
|
|
22911
|
-
...(g.users ?? []).map((u) => u.name),
|
|
22912
|
-
...g.instances.map((i) => i.user?.name ?? ""),
|
|
23047
|
+
t.subtype,
|
|
23048
|
+
t.category,
|
|
23049
|
+
t.policy.name,
|
|
23050
|
+
t.id,
|
|
23051
|
+
...(t.users ?? []).map((u) => u.name),
|
|
22913
23052
|
...extra === void 0 ? [] : [extra]
|
|
22914
23053
|
].join(" ").toLowerCase();
|
|
22915
23054
|
}
|
|
22916
|
-
function
|
|
22917
|
-
const cached2 = haystackCache.get(
|
|
23055
|
+
function typeHaystack(t) {
|
|
23056
|
+
const cached2 = haystackCache.get(t);
|
|
22918
23057
|
if (cached2 !== void 0) return cached2;
|
|
22919
|
-
const haystack = buildHaystack(
|
|
22920
|
-
haystackCache.set(
|
|
23058
|
+
const haystack = buildHaystack(t);
|
|
23059
|
+
haystackCache.set(t, haystack);
|
|
22921
23060
|
return haystack;
|
|
22922
23061
|
}
|
|
22923
23062
|
var actionsCache = /* @__PURE__ */ new WeakMap();
|
|
22924
|
-
function
|
|
22925
|
-
|
|
22926
|
-
if (cached2 !== void 0) return cached2;
|
|
22927
|
-
const actions = [...new Set(g.instances.map((i) => i.action))];
|
|
22928
|
-
actionsCache.set(g, actions);
|
|
22929
|
-
return actions;
|
|
23063
|
+
function typeActions(t) {
|
|
23064
|
+
return actionsCache.get(t) ?? [];
|
|
22930
23065
|
}
|
|
22931
23066
|
function countInstancesByStatus(statusInputs, statuses) {
|
|
22932
23067
|
const statusSet = new Set(statuses);
|
|
@@ -22937,8 +23072,8 @@ function countInstancesByStatus(statusInputs, statuses) {
|
|
|
22937
23072
|
}
|
|
22938
23073
|
return sum;
|
|
22939
23074
|
}
|
|
22940
|
-
function applyFindingFilters(
|
|
22941
|
-
let filtered =
|
|
23075
|
+
function applyFindingFilters(types, opts) {
|
|
23076
|
+
let filtered = types;
|
|
22942
23077
|
if (opts.severity && opts.severity.length > 0) {
|
|
22943
23078
|
const sevSet = new Set(opts.severity);
|
|
22944
23079
|
filtered = filtered.filter((g) => sevSet.has(g.severity));
|
|
@@ -22949,7 +23084,7 @@ function applyFindingFilters(groups, opts) {
|
|
|
22949
23084
|
}
|
|
22950
23085
|
if (opts.actions && opts.actions.length > 0) {
|
|
22951
23086
|
const actionSet = new Set(opts.actions);
|
|
22952
|
-
filtered = filtered.filter((
|
|
23087
|
+
filtered = filtered.filter((t) => typeActions(t).some((a) => actionSet.has(a)));
|
|
22953
23088
|
}
|
|
22954
23089
|
if (opts.subtype && opts.subtype.length > 0) {
|
|
22955
23090
|
const subtypeSet = new Set(opts.subtype);
|
|
@@ -22961,26 +23096,31 @@ function applyFindingFilters(groups, opts) {
|
|
|
22961
23096
|
}
|
|
22962
23097
|
if (opts.q) {
|
|
22963
23098
|
const q = opts.q.toLowerCase();
|
|
22964
|
-
filtered = filtered.filter((
|
|
23099
|
+
filtered = filtered.filter((t) => typeHaystack(t).includes(q));
|
|
22965
23100
|
}
|
|
22966
23101
|
return filtered;
|
|
22967
23102
|
}
|
|
22968
|
-
|
|
22969
|
-
|
|
23103
|
+
function rankByOrder(members2) {
|
|
23104
|
+
return Object.fromEntries(members2.map((member, index) => [member, index]));
|
|
23105
|
+
}
|
|
23106
|
+
var SEVERITY_RANK = rankByOrder(Severity.options);
|
|
23107
|
+
function severityRank(severity) {
|
|
23108
|
+
return lookupOwn(SEVERITY_RANK, severity);
|
|
23109
|
+
}
|
|
22970
23110
|
function compareFindingGroupOrder(a, b) {
|
|
22971
|
-
const rankA =
|
|
22972
|
-
const rankB =
|
|
23111
|
+
const rankA = severityRank(a.severity) ?? -1;
|
|
23112
|
+
const rankB = severityRank(b.severity) ?? -1;
|
|
22973
23113
|
const severityDiff = rankA - rankB;
|
|
22974
23114
|
if (severityDiff !== 0) return severityDiff;
|
|
22975
23115
|
const recencyDiff = b.latestDetectedAt.localeCompare(a.latestDetectedAt);
|
|
22976
23116
|
if (recencyDiff !== 0) return recencyDiff;
|
|
22977
23117
|
return a.id.localeCompare(b.id);
|
|
22978
23118
|
}
|
|
22979
|
-
function
|
|
22980
|
-
return [...
|
|
23119
|
+
function sortFindingTypes(types) {
|
|
23120
|
+
return [...types].sort(compareFindingGroupOrder);
|
|
22981
23121
|
}
|
|
22982
|
-
function computeFindingFacets(
|
|
22983
|
-
const forSeverity = applyFindingFilters(
|
|
23122
|
+
function computeFindingFacets(allTypes, opts) {
|
|
23123
|
+
const forSeverity = applyFindingFilters(allTypes, {
|
|
22984
23124
|
providers: opts.providers,
|
|
22985
23125
|
actions: opts.actions,
|
|
22986
23126
|
statuses: opts.statuses,
|
|
@@ -22991,7 +23131,7 @@ function computeFindingFacets(allGroups, opts) {
|
|
|
22991
23131
|
for (const g of forSeverity) {
|
|
22992
23132
|
severityMap.set(g.severity, (severityMap.get(g.severity) ?? 0) + 1);
|
|
22993
23133
|
}
|
|
22994
|
-
const forProvider = applyFindingFilters(
|
|
23134
|
+
const forProvider = applyFindingFilters(allTypes, {
|
|
22995
23135
|
actions: opts.actions,
|
|
22996
23136
|
statuses: opts.statuses,
|
|
22997
23137
|
q: opts.q,
|
|
@@ -23002,7 +23142,7 @@ function computeFindingFacets(allGroups, opts) {
|
|
|
23002
23142
|
for (const g of forProvider) {
|
|
23003
23143
|
for (const p of g.providers) providerMap.set(p, (providerMap.get(p) ?? 0) + 1);
|
|
23004
23144
|
}
|
|
23005
|
-
const forAction = applyFindingFilters(
|
|
23145
|
+
const forAction = applyFindingFilters(allTypes, {
|
|
23006
23146
|
providers: opts.providers,
|
|
23007
23147
|
statuses: opts.statuses,
|
|
23008
23148
|
q: opts.q,
|
|
@@ -23011,9 +23151,9 @@ function computeFindingFacets(allGroups, opts) {
|
|
|
23011
23151
|
});
|
|
23012
23152
|
const actionMap = /* @__PURE__ */ new Map();
|
|
23013
23153
|
for (const g of forAction) {
|
|
23014
|
-
for (const a of
|
|
23154
|
+
for (const a of typeActions(g)) actionMap.set(a, (actionMap.get(a) ?? 0) + 1);
|
|
23015
23155
|
}
|
|
23016
|
-
const forSubtype = applyFindingFilters(
|
|
23156
|
+
const forSubtype = applyFindingFilters(allTypes, {
|
|
23017
23157
|
providers: opts.providers,
|
|
23018
23158
|
actions: opts.actions,
|
|
23019
23159
|
statuses: opts.statuses,
|
|
@@ -23022,7 +23162,7 @@ function computeFindingFacets(allGroups, opts) {
|
|
|
23022
23162
|
});
|
|
23023
23163
|
const subtypeMap = /* @__PURE__ */ new Map();
|
|
23024
23164
|
for (const g of forSubtype) subtypeMap.set(g.subtype, (subtypeMap.get(g.subtype) ?? 0) + 1);
|
|
23025
|
-
const forStatus = applyFindingFilters(
|
|
23165
|
+
const forStatus = applyFindingFilters(allTypes, {
|
|
23026
23166
|
providers: opts.providers,
|
|
23027
23167
|
actions: opts.actions,
|
|
23028
23168
|
q: opts.q,
|
|
@@ -23044,6 +23184,20 @@ function computeFindingFacets(allGroups, opts) {
|
|
|
23044
23184
|
}
|
|
23045
23185
|
|
|
23046
23186
|
// ../../packages/schema/src/zod/findings-flat-build.ts
|
|
23187
|
+
function compareCodePoints(a, b) {
|
|
23188
|
+
const aIter = a[Symbol.iterator]();
|
|
23189
|
+
const bIter = b[Symbol.iterator]();
|
|
23190
|
+
for (; ; ) {
|
|
23191
|
+
const aNext = aIter.next();
|
|
23192
|
+
const bNext = bIter.next();
|
|
23193
|
+
if (aNext.done && bNext.done) return 0;
|
|
23194
|
+
if (aNext.done) return -1;
|
|
23195
|
+
if (bNext.done) return 1;
|
|
23196
|
+
const aPoint = aNext.value.codePointAt(0) ?? 0;
|
|
23197
|
+
const bPoint = bNext.value.codePointAt(0) ?? 0;
|
|
23198
|
+
if (aPoint !== bPoint) return aPoint - bPoint;
|
|
23199
|
+
}
|
|
23200
|
+
}
|
|
23047
23201
|
function rowHaystack(row) {
|
|
23048
23202
|
return [
|
|
23049
23203
|
row.ruleId,
|
|
@@ -23068,12 +23222,24 @@ function matchesDimension(row, opts, dimension) {
|
|
|
23068
23222
|
return !opts.actions?.length || opts.actions.includes(toApiAction(row.actionTaken));
|
|
23069
23223
|
case "statuses":
|
|
23070
23224
|
return !opts.statuses?.length || row.status !== void 0 && opts.statuses.includes(row.status);
|
|
23225
|
+
case "deliveries":
|
|
23226
|
+
return !opts.deliveries?.length || row.delivery !== void 0 && opts.deliveries.includes(row.delivery.state);
|
|
23071
23227
|
case "tools":
|
|
23072
23228
|
return !opts.tools?.length || row.toolName !== void 0 && opts.tools.includes(row.toolName);
|
|
23229
|
+
// An EMPTY value is a real filter here, not an absent one. The location
|
|
23230
|
+
// list buckets a finding whose event recorded no repo — or no file — under
|
|
23231
|
+
// the empty string, and selecting that bucket has to narrow the panel to
|
|
23232
|
+
// exactly it. Only `undefined` means "no filter"; a caller that wants every
|
|
23233
|
+
// row omits the key, which every call site already does.
|
|
23234
|
+
//
|
|
23235
|
+
// Reading '' as unset is what this replaced, and it failed in the one place
|
|
23236
|
+
// it mattered: the no-repo/no-file bucket is often the largest in a real
|
|
23237
|
+
// store, and its panel dropped both predicates and returned the WHOLE scope
|
|
23238
|
+
// — a row reading 3 findings beside a panel listing every finding there is.
|
|
23073
23239
|
case "repo":
|
|
23074
|
-
return opts.repo === void 0 ||
|
|
23240
|
+
return opts.repo === void 0 || row.repo === opts.repo;
|
|
23075
23241
|
case "file":
|
|
23076
|
-
return opts.file === void 0 ||
|
|
23242
|
+
return opts.file === void 0 || row.file === opts.file;
|
|
23077
23243
|
case "q":
|
|
23078
23244
|
return !opts.q || rowHaystack(row).includes(opts.q.toLowerCase());
|
|
23079
23245
|
}
|
|
@@ -23084,6 +23250,7 @@ var DIMENSIONS = [
|
|
|
23084
23250
|
"providers",
|
|
23085
23251
|
"actions",
|
|
23086
23252
|
"statuses",
|
|
23253
|
+
"deliveries",
|
|
23087
23254
|
"tools",
|
|
23088
23255
|
"repo",
|
|
23089
23256
|
"file",
|
|
@@ -23097,10 +23264,19 @@ function matchesInstanceFilters(row, opts, except) {
|
|
|
23097
23264
|
return true;
|
|
23098
23265
|
}
|
|
23099
23266
|
function toItems(counts) {
|
|
23100
|
-
return [...counts.entries()].map(([value, count]) => ({ value, count })).sort(
|
|
23267
|
+
return [...counts.entries()].map(([value, count]) => ({ value, count })).sort(
|
|
23268
|
+
(a, b) => b.count - a.count || a.value.localeCompare(b.value) || // localeCompare reports canonically-equivalent strings (an NFC and an
|
|
23269
|
+
// NFD spelling of the same text) as equal, so a count tie between
|
|
23270
|
+
// them would otherwise be ordered by whichever the Map iteration
|
|
23271
|
+
// produced. compareCodePoints breaks that tie deterministically, which
|
|
23272
|
+
// makes this a TOTAL order — not one that agrees with SQL collation,
|
|
23273
|
+
// which it need not: foldFacetTuples runs this same sort over grouped
|
|
23274
|
+
// tuples, so both paths order facets identically by construction.
|
|
23275
|
+
compareCodePoints(a.value, b.value)
|
|
23276
|
+
);
|
|
23101
23277
|
}
|
|
23102
|
-
function bump(counts, value) {
|
|
23103
|
-
counts.set(value, (counts.get(value) ?? 0) +
|
|
23278
|
+
function bump(counts, value, by = 1) {
|
|
23279
|
+
counts.set(value, (counts.get(value) ?? 0) + by);
|
|
23104
23280
|
}
|
|
23105
23281
|
function createInstanceFacetAccumulator(opts) {
|
|
23106
23282
|
const severity = /* @__PURE__ */ new Map();
|
|
@@ -23109,6 +23285,7 @@ function createInstanceFacetAccumulator(opts) {
|
|
|
23109
23285
|
const action = /* @__PURE__ */ new Map();
|
|
23110
23286
|
const status = /* @__PURE__ */ new Map();
|
|
23111
23287
|
const tool = /* @__PURE__ */ new Map();
|
|
23288
|
+
const deployment = /* @__PURE__ */ new Map();
|
|
23112
23289
|
return {
|
|
23113
23290
|
add(row) {
|
|
23114
23291
|
if (matchesInstanceFilters(row, opts, "severity")) bump(severity, row.severity);
|
|
@@ -23123,6 +23300,9 @@ function createInstanceFacetAccumulator(opts) {
|
|
|
23123
23300
|
if (row.toolName !== void 0 && matchesInstanceFilters(row, opts, "tools")) {
|
|
23124
23301
|
bump(tool, row.toolName);
|
|
23125
23302
|
}
|
|
23303
|
+
if (row.delivery !== void 0 && matchesInstanceFilters(row, opts, "deliveries")) {
|
|
23304
|
+
bump(deployment, row.delivery.state);
|
|
23305
|
+
}
|
|
23126
23306
|
},
|
|
23127
23307
|
facets: () => ({
|
|
23128
23308
|
severity: toItems(severity),
|
|
@@ -23130,7 +23310,8 @@ function createInstanceFacetAccumulator(opts) {
|
|
|
23130
23310
|
provider: toItems(provider),
|
|
23131
23311
|
action: toItems(action),
|
|
23132
23312
|
status: toItems(status),
|
|
23133
|
-
tool: toItems(tool)
|
|
23313
|
+
tool: toItems(tool),
|
|
23314
|
+
deployment: toItems(deployment)
|
|
23134
23315
|
})
|
|
23135
23316
|
};
|
|
23136
23317
|
}
|
|
@@ -23144,6 +23325,7 @@ function toInstanceDetail(row) {
|
|
|
23144
23325
|
...row.toolName === void 0 ? {} : { toolName: row.toolName },
|
|
23145
23326
|
eventId: row.eventId,
|
|
23146
23327
|
...row.sessionId === void 0 ? {} : { sessionId: row.sessionId },
|
|
23328
|
+
...row.delivery === void 0 ? {} : { delivery: row.delivery },
|
|
23147
23329
|
...row.user === void 0 ? {} : { user: row.user },
|
|
23148
23330
|
action: toApiAction(row.actionTaken),
|
|
23149
23331
|
detectedAt: row.occurredAt,
|
|
@@ -23158,12 +23340,6 @@ function toInstanceDetail(row) {
|
|
|
23158
23340
|
policy: { id: `category:${category}`, name: category }
|
|
23159
23341
|
};
|
|
23160
23342
|
}
|
|
23161
|
-
var SEVERITY_ORDER2 = {
|
|
23162
|
-
critical: 0,
|
|
23163
|
-
high: 1,
|
|
23164
|
-
medium: 2,
|
|
23165
|
-
low: 3
|
|
23166
|
-
};
|
|
23167
23343
|
function newLocationAccumulator() {
|
|
23168
23344
|
return {
|
|
23169
23345
|
instanceCount: 0,
|
|
@@ -23178,7 +23354,7 @@ function newLocationAccumulator() {
|
|
|
23178
23354
|
}
|
|
23179
23355
|
function addToLocation(acc, row) {
|
|
23180
23356
|
acc.instanceCount += 1;
|
|
23181
|
-
const rank =
|
|
23357
|
+
const rank = severityRank(row.severity) ?? Number.MAX_SAFE_INTEGER - 1;
|
|
23182
23358
|
if (rank < acc.maxSeverityRank) {
|
|
23183
23359
|
acc.maxSeverityRank = rank;
|
|
23184
23360
|
acc.maxSeverity = row.severity;
|
|
@@ -23187,6 +23363,23 @@ function addToLocation(acc, row) {
|
|
|
23187
23363
|
acc.statuses.push(row.status);
|
|
23188
23364
|
acc.ruleIds.add(row.ruleId);
|
|
23189
23365
|
}
|
|
23366
|
+
function compareLocationOrder(a, b) {
|
|
23367
|
+
const rankA = severityRank(a.maxSeverity) ?? -1;
|
|
23368
|
+
const rankB = severityRank(b.maxSeverity) ?? -1;
|
|
23369
|
+
if (rankA !== rankB) return rankA - rankB;
|
|
23370
|
+
if (a.latestDetectedAt !== b.latestDetectedAt) {
|
|
23371
|
+
return a.latestDetectedAt < b.latestDetectedAt ? 1 : -1;
|
|
23372
|
+
}
|
|
23373
|
+
const repoDiff = compareCodePoints(a.repo, b.repo);
|
|
23374
|
+
if (repoDiff !== 0) return repoDiff;
|
|
23375
|
+
return compareCodePoints(a.file, b.file);
|
|
23376
|
+
}
|
|
23377
|
+
function encodeLocationId(repo, file2) {
|
|
23378
|
+
return `${encodePart(repo)}/${encodePart(file2)}`;
|
|
23379
|
+
}
|
|
23380
|
+
function encodePart(value) {
|
|
23381
|
+
return encodeURIComponent(value.replace(/[\uD800-\uDFFF]/gu, "\uFFFD"));
|
|
23382
|
+
}
|
|
23190
23383
|
|
|
23191
23384
|
// ../../packages/schema/src/zod/installed-pack.ts
|
|
23192
23385
|
var InstalledPack = external_exports.object({
|
|
@@ -23254,6 +23447,11 @@ var Policy = external_exports.object({
|
|
|
23254
23447
|
// test `prohibitedModels` passes and `reversibleRuleIds` fails.
|
|
23255
23448
|
provenance: PolicyProvenance.optional()
|
|
23256
23449
|
}).meta({ id: "Policy" });
|
|
23450
|
+
var KNOWN_BUILTIN_IDS = ["monitor", "warn", "redact", "vault", "block"];
|
|
23451
|
+
var BuiltinPolicyId = external_exports.enum(KNOWN_BUILTIN_IDS).meta({ id: "BuiltinPolicyId" });
|
|
23452
|
+
var RedactFallback = BuiltinPolicyId.extract(["monitor", "warn", "block"]).meta({
|
|
23453
|
+
id: "RedactFallback"
|
|
23454
|
+
});
|
|
23257
23455
|
var PolicyBundle = external_exports.object({
|
|
23258
23456
|
version: external_exports.string(),
|
|
23259
23457
|
policies: external_exports.array(Policy),
|
|
@@ -23301,6 +23499,16 @@ var PolicyBundle = external_exports.object({
|
|
|
23301
23499
|
// control plane), so no name resolution stands between the decision and the
|
|
23302
23500
|
// comparison.
|
|
23303
23501
|
prohibitedModels: external_exports.array(external_exports.string()).optional(),
|
|
23502
|
+
// What a resolved `redact` becomes on a field the host cannot rewrite, as
|
|
23503
|
+
// the ORGANIZATION would have it. Merged raise-only against the device's own
|
|
23504
|
+
// `WorkspaceSettings.redactFallback` (see strongerRedactFallback below), so
|
|
23505
|
+
// a control plane can tighten a machine and never loosen one — the same
|
|
23506
|
+
// direction `mergeRaiseOnly` enforces for policies.
|
|
23507
|
+
//
|
|
23508
|
+
// Optional so an older backend, and an older on-disk cache, still parses;
|
|
23509
|
+
// absent leaves the device's own setting in force, which is the behaviour
|
|
23510
|
+
// that predates the field and the safe direction to default.
|
|
23511
|
+
redactFallback: RedactFallback.optional(),
|
|
23304
23512
|
customKeywords: external_exports.array(external_exports.string()),
|
|
23305
23513
|
fetchedAt: external_exports.iso.datetime()
|
|
23306
23514
|
}).meta({ id: "PolicyBundle" });
|
|
@@ -23330,11 +23538,6 @@ function severityFloorPolicy(category) {
|
|
|
23330
23538
|
const peak = CATEGORY_PEAK_SEVERITY[category];
|
|
23331
23539
|
return peak === "critical" || peak === "high" ? "warn" : "monitor";
|
|
23332
23540
|
}
|
|
23333
|
-
var KNOWN_BUILTIN_IDS = ["monitor", "warn", "redact", "vault", "block"];
|
|
23334
|
-
var BuiltinPolicyId = external_exports.enum(KNOWN_BUILTIN_IDS).meta({ id: "BuiltinPolicyId" });
|
|
23335
|
-
var RedactFallback = BuiltinPolicyId.extract(["monitor", "warn", "block"]).meta({
|
|
23336
|
-
id: "RedactFallback"
|
|
23337
|
-
});
|
|
23338
23541
|
var BUILTIN_ORDER = KNOWN_BUILTIN_IDS;
|
|
23339
23542
|
var BUILTIN_POLICY_SPECS = {
|
|
23340
23543
|
monitor: {
|
|
@@ -23390,6 +23593,11 @@ function isActionAtLeast(action, floor) {
|
|
|
23390
23593
|
function strongerAction(a, b) {
|
|
23391
23594
|
return actionRank(a) >= actionRank(b) ? a : b;
|
|
23392
23595
|
}
|
|
23596
|
+
function strongerRedactFallback(local, remote) {
|
|
23597
|
+
if (remote === void 0) return local;
|
|
23598
|
+
const localAction = builtinPolicyToAction(local);
|
|
23599
|
+
return localAction === strongerAction(localAction, builtinPolicyToAction(remote)) ? local : remote;
|
|
23600
|
+
}
|
|
23393
23601
|
function weakestBuiltinAtLeast(floor) {
|
|
23394
23602
|
return KNOWN_BUILTIN_IDS.find((id) => isActionAtLeast(builtinPolicyToAction(id), floor)) ?? "block";
|
|
23395
23603
|
}
|
|
@@ -23630,7 +23838,7 @@ var VaultConsent = external_exports.object({
|
|
|
23630
23838
|
});
|
|
23631
23839
|
|
|
23632
23840
|
// ../../packages/schema/src/zod/local.ts
|
|
23633
|
-
var WORKSPACE_SETTINGS_SPEC_VERSION =
|
|
23841
|
+
var WORKSPACE_SETTINGS_SPEC_VERSION = 8;
|
|
23634
23842
|
var MODEL_JUDGE_PAYLOAD_VERSION = 1;
|
|
23635
23843
|
var RunMode = external_exports.enum(["standalone", "attached"]);
|
|
23636
23844
|
var ControlPlaneConnection = external_exports.object({
|
|
@@ -23650,6 +23858,15 @@ var HistorySyncConsent = external_exports.object({
|
|
|
23650
23858
|
payloadVersion: external_exports.number().int().positive(),
|
|
23651
23859
|
endpoint: external_exports.string()
|
|
23652
23860
|
});
|
|
23861
|
+
var BODY_RETENTION_DEFAULT_DAYS = 30;
|
|
23862
|
+
var BodyRetention = external_exports.object({
|
|
23863
|
+
enabled: external_exports.boolean().default(false),
|
|
23864
|
+
// Never 0, and the ceiling is a fat-finger guard rather than a policy
|
|
23865
|
+
// limit — `enabled` is the real gate. A low value cannot reach a row the
|
|
23866
|
+
// sync ledger still owes: the sweep's age filter only ever NARROWS a
|
|
23867
|
+
// candidate set that is already bounded by "delivered, or never owed".
|
|
23868
|
+
retainDays: external_exports.number().int().min(1).max(3650).default(BODY_RETENTION_DEFAULT_DAYS)
|
|
23869
|
+
}).meta({ id: "BodyRetention" });
|
|
23653
23870
|
var WorkspaceSettings = external_exports.object({
|
|
23654
23871
|
specVersion: external_exports.number().int().positive().default(WORKSPACE_SETTINGS_SPEC_VERSION),
|
|
23655
23872
|
runMode: RunMode.default("standalone"),
|
|
@@ -23693,12 +23910,18 @@ var WorkspaceSettings = external_exports.object({
|
|
|
23693
23910
|
// covers the current payload and must be re-granted.
|
|
23694
23911
|
modelJudgeConsent: ModelJudgeConsent.optional(),
|
|
23695
23912
|
// Records that the user consented to the DEFERRED send — the outbox — along
|
|
23696
|
-
// with the payload shape and the endpoint they agreed to. Since payload
|
|
23697
|
-
// that covers
|
|
23698
|
-
// carry prompt/reply text in `content
|
|
23699
|
-
// Absent until granted, and a grant for a different endpoint
|
|
23700
|
-
// payload no longer counts.
|
|
23701
|
-
historySyncConsent: HistorySyncConsent.optional()
|
|
23913
|
+
// with the payload shape and the endpoint they agreed to. Since payload v3
|
|
23914
|
+
// that covers the pre-attach backlog AND undelivered captures alike, and both
|
|
23915
|
+
// carry prompt/reply/tool-output text in `content`; the key name predates
|
|
23916
|
+
// both widenings. Absent until granted, and a grant for a different endpoint
|
|
23917
|
+
// or an older payload no longer counts.
|
|
23918
|
+
historySyncConsent: HistorySyncConsent.optional(),
|
|
23919
|
+
// Local body expiry (see BodyRetention). Off until switched on; expiring a
|
|
23920
|
+
// body never removes the row or its findings.
|
|
23921
|
+
bodyRetention: BodyRetention.default({
|
|
23922
|
+
enabled: false,
|
|
23923
|
+
retainDays: BODY_RETENTION_DEFAULT_DAYS
|
|
23924
|
+
})
|
|
23702
23925
|
});
|
|
23703
23926
|
function defaultWorkspaceSettings() {
|
|
23704
23927
|
return WorkspaceSettings.parse({});
|
|
@@ -23793,12 +24016,15 @@ function toCaptureAttributes(event) {
|
|
|
23793
24016
|
...metadata?.traceId !== void 0 ? { trace_id: metadata.traceId } : {},
|
|
23794
24017
|
...metadata?.exceptionIds !== void 0 ? { exception_ids: metadata.exceptionIds } : {},
|
|
23795
24018
|
...metadata?.inspectionMs !== void 0 ? { inspection_ms: metadata.inspectionMs } : {},
|
|
24019
|
+
...metadata?.redactDegradedTo !== void 0 ? { redact_degraded_to: metadata.redactDegradedTo } : {},
|
|
23796
24020
|
// `model`/`turnIndex` have no dedicated CaptureAttributes field (no writer
|
|
23797
24021
|
// has ever populated either), but every legacy metadata key still rides
|
|
23798
24022
|
// the bag rather than being silently dropped — CaptureAttributes'
|
|
23799
24023
|
// `.catchall(z.unknown())` carries the long tail.
|
|
23800
24024
|
...metadata?.model !== void 0 ? { model: metadata.model } : {},
|
|
23801
|
-
...metadata?.turnIndex !== void 0 ? { turn_index: metadata.turnIndex } : {}
|
|
24025
|
+
...metadata?.turnIndex !== void 0 ? { turn_index: metadata.turnIndex } : {},
|
|
24026
|
+
...metadata?.messageId !== void 0 ? { message_id: metadata.messageId } : {},
|
|
24027
|
+
...metadata?.conversationId !== void 0 ? { conversation_id: metadata.conversationId } : {}
|
|
23802
24028
|
};
|
|
23803
24029
|
}
|
|
23804
24030
|
function captureDefinitionVersion(finding) {
|
|
@@ -23826,10 +24052,22 @@ var ManagedSettingKey = external_exports.enum([
|
|
|
23826
24052
|
"vaultInlineReveal",
|
|
23827
24053
|
"modelJudgeConsent",
|
|
23828
24054
|
"dataSharesInPlace",
|
|
23829
|
-
"redactFallback"
|
|
24055
|
+
"redactFallback",
|
|
24056
|
+
// Pins the toggle and the day count together — see BodyRetention on why the
|
|
24057
|
+
// two are one unit. An administrator mandating a window wants the count
|
|
24058
|
+
// enforced with it, not one a user can widen while the toggle stays on.
|
|
24059
|
+
"bodyRetention"
|
|
23830
24060
|
]).meta({ id: "ManagedSettingKey" });
|
|
24061
|
+
function isManagedSettingKey(value) {
|
|
24062
|
+
return ManagedSettingKey.safeParse(value).success;
|
|
24063
|
+
}
|
|
23831
24064
|
var ManagedSettingsValues = external_exports.object({
|
|
23832
24065
|
runMode: external_exports.enum(["standalone", "attached"]).optional(),
|
|
24066
|
+
// `controlPlane` and `bodyRetention` are the two nested values, and both are
|
|
24067
|
+
// plain, non-strict objects: a key under either that this build does not know
|
|
24068
|
+
// is stripped and nothing reports it. The unknown-value split in
|
|
24069
|
+
// ManagedSettings below classifies top-level names only, so it stops at
|
|
24070
|
+
// these boundaries.
|
|
23833
24071
|
controlPlane: external_exports.object({
|
|
23834
24072
|
endpoint: external_exports.string().min(1),
|
|
23835
24073
|
label: external_exports.string().min(1).optional()
|
|
@@ -23840,7 +24078,8 @@ var ManagedSettingsValues = external_exports.object({
|
|
|
23840
24078
|
vaultInlineReveal: external_exports.enum(["masked", "full", "off"]).optional(),
|
|
23841
24079
|
modelJudgeConsent: external_exports.boolean().optional(),
|
|
23842
24080
|
dataSharesInPlace: external_exports.boolean().optional(),
|
|
23843
|
-
redactFallback: RedactFallback.optional()
|
|
24081
|
+
redactFallback: RedactFallback.optional(),
|
|
24082
|
+
bodyRetention: BodyRetention.optional()
|
|
23844
24083
|
}).meta({ id: "ManagedSettingsValues" });
|
|
23845
24084
|
var ManagedSettings = external_exports.object({
|
|
23846
24085
|
specVersion: external_exports.number().int().positive().default(MANAGED_SETTINGS_SPEC_VERSION),
|
|
@@ -23848,11 +24087,59 @@ var ManagedSettings = external_exports.object({
|
|
|
23848
24087
|
// decision from a bug. Absent renders as a generic "your organization".
|
|
23849
24088
|
organization: external_exports.string().min(1).optional(),
|
|
23850
24089
|
// What the administrator pinned.
|
|
23851
|
-
|
|
24090
|
+
//
|
|
24091
|
+
// Parsed as a RECORD rather than as the nested schema, and split below for
|
|
24092
|
+
// the same reason `lockedFields` is parsed as names: a plain `z.object`
|
|
24093
|
+
// drops an unrecognised key and succeeds, so a pin this build does not know
|
|
24094
|
+
// vanished and nothing anywhere said so. A pin with no lock is a supported
|
|
24095
|
+
// shape — it is a DEFAULT the user may still change — so that silence hit
|
|
24096
|
+
// exactly the file an administrator is most likely to write while a fleet
|
|
24097
|
+
// is mid-upgrade.
|
|
24098
|
+
//
|
|
24099
|
+
// Splitting here rather than calling `.strict()`: strict would REFUSE the
|
|
24100
|
+
// file, which is the outcome the lock half already rejected — an older
|
|
24101
|
+
// build then runs entirely unmanaged, every pin and lock gone. A bad KNOWN
|
|
24102
|
+
// value still fails, because the nested schema is re-run over the known
|
|
24103
|
+
// subset and its issues are re-raised on this parse.
|
|
24104
|
+
values: external_exports.record(external_exports.string(), external_exports.unknown()).default({}),
|
|
23852
24105
|
// Which of those the user may not change. A key here with no matching value
|
|
23853
24106
|
// freezes whatever the user last chose; a value with no lock is a DEFAULT
|
|
23854
24107
|
// the user may still override. The two are separable on purpose.
|
|
23855
|
-
|
|
24108
|
+
//
|
|
24109
|
+
// Parsed as NAMES rather than as the enum, and split below: a name this
|
|
24110
|
+
// build does not know is dropped from the locked set and reported, never a
|
|
24111
|
+
// reason to refuse the file. The same shape reaches an older build whenever
|
|
24112
|
+
// an administrator locks a key a newer build added, and refusing it there
|
|
24113
|
+
// ran that build entirely unmanaged — every pin and lock gone — on exactly
|
|
24114
|
+
// the fleets most likely to carry a version skew. A name outside the enum
|
|
24115
|
+
// is still never HONOURED: the lockable set stays explicit above.
|
|
24116
|
+
lockedFields: external_exports.array(external_exports.string()).default([])
|
|
24117
|
+
}).transform(({ lockedFields, values, ...rest }, ctx) => {
|
|
24118
|
+
const known = [];
|
|
24119
|
+
const unknown2 = [];
|
|
24120
|
+
for (const name of lockedFields) {
|
|
24121
|
+
if (isManagedSettingKey(name)) known.push(name);
|
|
24122
|
+
else unknown2.push(name);
|
|
24123
|
+
}
|
|
24124
|
+
const knownValues = /* @__PURE__ */ Object.create(null);
|
|
24125
|
+
const unknownValues = [];
|
|
24126
|
+
for (const [name, value] of Object.entries(values)) {
|
|
24127
|
+
if (Object.hasOwn(ManagedSettingsValues.shape, name)) knownValues[name] = value;
|
|
24128
|
+
else unknownValues.push(name);
|
|
24129
|
+
}
|
|
24130
|
+
const pinned = ManagedSettingsValues.safeParse(knownValues);
|
|
24131
|
+
if (!pinned.success) {
|
|
24132
|
+
for (const issue2 of pinned.error.issues)
|
|
24133
|
+
ctx.addIssue({ ...issue2, path: ["values", ...issue2.path] });
|
|
24134
|
+
return external_exports.NEVER;
|
|
24135
|
+
}
|
|
24136
|
+
return {
|
|
24137
|
+
...rest,
|
|
24138
|
+
values: pinned.data,
|
|
24139
|
+
lockedFields: known,
|
|
24140
|
+
...unknown2.length > 0 ? { unknownLockedFields: unknown2 } : {},
|
|
24141
|
+
...unknownValues.length > 0 ? { unknownValueFields: unknownValues } : {}
|
|
24142
|
+
};
|
|
23856
24143
|
}).meta({ id: "ManagedSettings" });
|
|
23857
24144
|
|
|
23858
24145
|
// ../../packages/schema/src/zod/project-files.ts
|
|
@@ -23976,7 +24263,11 @@ var FindingsTimeseriesPoint = external_exports.object({
|
|
|
23976
24263
|
timestamp: external_exports.iso.date(),
|
|
23977
24264
|
critical: external_exports.number().int().nonnegative(),
|
|
23978
24265
|
high: external_exports.number().int().nonnegative(),
|
|
23979
|
-
medium: external_exports.number().int().nonnegative()
|
|
24266
|
+
medium: external_exports.number().int().nonnegative(),
|
|
24267
|
+
// Optional and additive, so a producer written against the earlier
|
|
24268
|
+
// three-series contract keeps validating. A consumer plotting it resolves the
|
|
24269
|
+
// absent case itself — the chart point requires a number.
|
|
24270
|
+
low: external_exports.number().int().nonnegative().optional()
|
|
23980
24271
|
}).meta({ id: "FindingsTimeseriesPoint" });
|
|
23981
24272
|
var FindingsTimeseriesResponse = external_exports.object({
|
|
23982
24273
|
range: TimeRange,
|
|
@@ -24002,6 +24293,10 @@ var ResolvedFeedItem = external_exports.object({
|
|
|
24002
24293
|
findingKey: external_exports.string(),
|
|
24003
24294
|
ruleId: external_exports.string(),
|
|
24004
24295
|
severity: Severity,
|
|
24296
|
+
// Repository slug, and the file path RELATIVE to it. The pair is what
|
|
24297
|
+
// identifies the file: a bare path matches the same name in every repo.
|
|
24298
|
+
// Optional and additive; empty when the event carried no repo.
|
|
24299
|
+
repo: external_exports.string().optional(),
|
|
24005
24300
|
path: external_exports.string(),
|
|
24006
24301
|
// ISO-8601 datetime (matches FindingInstance.detectedAt / the rest of the
|
|
24007
24302
|
// findings domain). The reader `.toISOString()`s the DB epoch-ms values.
|
|
@@ -24107,7 +24402,23 @@ var SaveSettingsInput = external_exports.object({
|
|
|
24107
24402
|
modelJudgeConsent: ModelJudgeConsentChoice,
|
|
24108
24403
|
historySyncConsent: HistorySyncConsentChoice,
|
|
24109
24404
|
vaultConsent: external_exports.string(),
|
|
24110
|
-
vaultInlineReveal: external_exports.string()
|
|
24405
|
+
vaultInlineReveal: external_exports.string(),
|
|
24406
|
+
// Widened to `string` like its neighbours rather than typed as
|
|
24407
|
+
// `RedactFallback`, on this module's own layering rule: shape here, VALUE at
|
|
24408
|
+
// the call site, so the domain check receives the type it was written for.
|
|
24409
|
+
//
|
|
24410
|
+
// NOT because a narrower schema would reject differently. `parseActionInput`
|
|
24411
|
+
// is a `safeParse` wrapper and throws for no field schema, so either spelling
|
|
24412
|
+
// reaches a recoverable `{ ok: false }` and there is no rejected promise to
|
|
24413
|
+
// trade against. The real cost runs the other way and is the part worth
|
|
24414
|
+
// knowing: a value this schema admits and the domain enum then rejects lands
|
|
24415
|
+
// on the action's shared refusal, which names NO field, where a shape
|
|
24416
|
+
// rejection reaches `malformedInput` and names the schema key.
|
|
24417
|
+
redactFallback: external_exports.string(),
|
|
24418
|
+
// Shape only, the way the enum fields above are strings only: the RANGE is
|
|
24419
|
+
// `BodyRetention`'s and the action checks it there, so there is one place
|
|
24420
|
+
// that decides what a legal horizon is rather than two that can drift.
|
|
24421
|
+
bodyRetention: external_exports.object({ enabled: external_exports.boolean(), retainDays: external_exports.number() })
|
|
24111
24422
|
});
|
|
24112
24423
|
var AttachInput = external_exports.object({
|
|
24113
24424
|
endpoint: external_exports.string(),
|
|
@@ -24279,6 +24590,52 @@ function reviewSeverityRank(reasons) {
|
|
|
24279
24590
|
return Math.min(...reasons.map((r) => REVIEW_SEVERITY_RANK[r]));
|
|
24280
24591
|
}
|
|
24281
24592
|
|
|
24593
|
+
// ../../packages/schema/src/zod/web-capture.ts
|
|
24594
|
+
var WebUsageSource = external_exports.enum(["site", "estimated", "none"]);
|
|
24595
|
+
var WebUsage = external_exports.object({
|
|
24596
|
+
inputTokens: external_exports.number().int().nonnegative().optional(),
|
|
24597
|
+
outputTokens: external_exports.number().int().nonnegative().optional(),
|
|
24598
|
+
cacheReadInputTokens: external_exports.number().int().nonnegative().optional(),
|
|
24599
|
+
cacheCreationInputTokens: external_exports.number().int().nonnegative().optional()
|
|
24600
|
+
});
|
|
24601
|
+
var WebToolCall = external_exports.object({
|
|
24602
|
+
toolUseId: external_exports.string().min(1),
|
|
24603
|
+
toolName: external_exports.string().min(1),
|
|
24604
|
+
target: external_exports.string().optional(),
|
|
24605
|
+
isError: external_exports.boolean().optional(),
|
|
24606
|
+
inputSize: external_exports.number().int().nonnegative().optional(),
|
|
24607
|
+
outputSize: external_exports.number().int().nonnegative().optional()
|
|
24608
|
+
});
|
|
24609
|
+
var WebExchange = external_exports.object({
|
|
24610
|
+
messageId: external_exports.string().min(1),
|
|
24611
|
+
startedAt: external_exports.iso.datetime(),
|
|
24612
|
+
model: external_exports.string().optional(),
|
|
24613
|
+
usage: WebUsage.optional(),
|
|
24614
|
+
usageSource: WebUsageSource,
|
|
24615
|
+
stopReason: external_exports.string().optional(),
|
|
24616
|
+
conversationId: external_exports.string().optional(),
|
|
24617
|
+
turnIndex: external_exports.number().int().nonnegative().optional(),
|
|
24618
|
+
toolCalls: external_exports.array(WebToolCall).default([]),
|
|
24619
|
+
// Absent when the adapter recovered no text. Capped by the caller at
|
|
24620
|
+
// RESPONSE_TEXT_MAX_BYTES; `truncated` records that the cap was reached, so a
|
|
24621
|
+
// short capture is never mistaken for a short reply.
|
|
24622
|
+
responseText: external_exports.string().optional(),
|
|
24623
|
+
truncated: external_exports.boolean().default(false)
|
|
24624
|
+
});
|
|
24625
|
+
var RESPONSE_TEXT_MAX_BYTES = 2 * 1024 * 1024;
|
|
24626
|
+
var WebCaptureStatus = external_exports.object({
|
|
24627
|
+
patched: external_exports.boolean(),
|
|
24628
|
+
live: external_exports.boolean(),
|
|
24629
|
+
blind: external_exports.boolean(),
|
|
24630
|
+
sendsSeenDom: external_exports.number().int().nonnegative(),
|
|
24631
|
+
exchangesSeenNet: external_exports.number().int().nonnegative(),
|
|
24632
|
+
parseFailures: external_exports.number().int().nonnegative(),
|
|
24633
|
+
unparsedBodies: external_exports.number().int().nonnegative(),
|
|
24634
|
+
// The adapter-declared JSON key paths that were absent from a real payload —
|
|
24635
|
+
// the earliest signal that a site's contract moved.
|
|
24636
|
+
shapeMisses: external_exports.array(external_exports.string()).default([])
|
|
24637
|
+
});
|
|
24638
|
+
|
|
24282
24639
|
// ../../packages/persistence/src/paths.ts
|
|
24283
24640
|
import {
|
|
24284
24641
|
chmodSync,
|
|
@@ -24639,6 +24996,22 @@ function discardStore(file2, backup) {
|
|
|
24639
24996
|
}
|
|
24640
24997
|
}
|
|
24641
24998
|
|
|
24999
|
+
// ../../packages/persistence/src/internal/sql-functions.ts
|
|
25000
|
+
var utf8 = new TextDecoder();
|
|
25001
|
+
function akaLower(value) {
|
|
25002
|
+
if (value === null) return null;
|
|
25003
|
+
if (typeof value === "string") return value.toLowerCase();
|
|
25004
|
+
if (typeof value === "number" || typeof value === "bigint") return String(value).toLowerCase();
|
|
25005
|
+
return utf8.decode(value).toLowerCase();
|
|
25006
|
+
}
|
|
25007
|
+
function registerSqlFunctions(db) {
|
|
25008
|
+
db.function(
|
|
25009
|
+
"aka_lower",
|
|
25010
|
+
{ deterministic: true, directOnly: true, useBigIntArguments: true },
|
|
25011
|
+
akaLower
|
|
25012
|
+
);
|
|
25013
|
+
}
|
|
25014
|
+
|
|
24642
25015
|
// ../../packages/persistence/src/internal/sql-text.ts
|
|
24643
25016
|
function escapeLikePattern(s) {
|
|
24644
25017
|
return s.replace(/\\/g, "\\\\").replace(/%/g, "\\%").replace(/_/g, "\\_");
|
|
@@ -24723,6 +25096,11 @@ function schemaObjectExists(db, kind, name) {
|
|
|
24723
25096
|
function indexExists(db, name) {
|
|
24724
25097
|
return schemaObjectExists(db, "index", name);
|
|
24725
25098
|
}
|
|
25099
|
+
function indexColumns(db, name) {
|
|
25100
|
+
if (!indexExists(db, name)) return [];
|
|
25101
|
+
const columns = db.prepare(`PRAGMA index_info(${name})`).all();
|
|
25102
|
+
return columns.map((c) => c.name).filter((c) => c !== null);
|
|
25103
|
+
}
|
|
24726
25104
|
function columnNames(db, table2, opts) {
|
|
24727
25105
|
const pragma = opts?.includeGenerated ? "table_xinfo" : "table_info";
|
|
24728
25106
|
const columns = db.prepare(`PRAGMA ${pragma}(${table2})`).all();
|
|
@@ -24784,6 +25162,647 @@ function mapRowsTolerant(rows, map2) {
|
|
|
24784
25162
|
return out;
|
|
24785
25163
|
}
|
|
24786
25164
|
|
|
25165
|
+
// ../../packages/persistence/src/internal/outbox-lane.ts
|
|
25166
|
+
var OUTBOX_CAPTURE_EVENT_TYPES = ["prompt", "response", "tool_use"];
|
|
25167
|
+
var OUTBOX_CAPTURE_TYPE_LIST = OUTBOX_CAPTURE_EVENT_TYPES.map((t) => `'${t}'`).join(", ");
|
|
25168
|
+
|
|
25169
|
+
// ../../packages/persistence/src/sync-failure.ts
|
|
25170
|
+
var SYNC_FAILURE_REASONS = SyncFailureReason.options;
|
|
25171
|
+
function syncFailureRejectCondition(column = "sync_failure") {
|
|
25172
|
+
const members2 = SYNC_FAILURE_REASONS.map((r) => `'${r}'`).join(", ");
|
|
25173
|
+
return `NEW.${column} IS NOT NULL AND NEW.${column} NOT IN (${members2})`;
|
|
25174
|
+
}
|
|
25175
|
+
|
|
25176
|
+
// ../../packages/persistence/src/repositories/history-sync.ts
|
|
25177
|
+
var STRUCTURAL_EVENT_TYPES = ["session", "llm_call", "tool_call"];
|
|
25178
|
+
var TYPE_LIST = STRUCTURAL_EVENT_TYPES.map((t) => `'${t}'`).join(", ");
|
|
25179
|
+
var CAPTURE_TYPE_LIST = OUTBOX_CAPTURE_TYPE_LIST;
|
|
25180
|
+
var COUNTED_EVENT_TYPES = [
|
|
25181
|
+
...STRUCTURAL_EVENT_TYPES,
|
|
25182
|
+
...OUTBOX_CAPTURE_EVENT_TYPES
|
|
25183
|
+
];
|
|
25184
|
+
var COUNTED_TYPE_LIST = COUNTED_EVENT_TYPES.map((t) => `'${t}'`).join(", ");
|
|
25185
|
+
var PARTITION_BUCKETS = `
|
|
25186
|
+
SUM(CASE WHEN synced_at IS NULL AND sync_claimed_at IS NULL THEN 1 ELSE 0 END) AS queued,
|
|
25187
|
+
SUM(CASE WHEN synced_at IS NULL AND sync_claimed_at IS NOT NULL THEN 1 ELSE 0 END) AS inProgress,
|
|
25188
|
+
SUM(CASE WHEN synced_at > 0 THEN 1 ELSE 0 END) AS synced,
|
|
25189
|
+
SUM(CASE WHEN synced_at IS NOT NULL AND synced_at <= 0
|
|
25190
|
+
AND sync_failure = 'deployment_refused' THEN 1 ELSE 0 END) AS refused,
|
|
25191
|
+
SUM(CASE WHEN synced_at IS NOT NULL AND synced_at <= 0
|
|
25192
|
+
AND sync_failure = 'detached_undelivered' THEN 1 ELSE 0 END) AS detached,
|
|
25193
|
+
-- Spelled as what it INCLUDES rather than what it excludes, so a reason
|
|
25194
|
+
-- added later lands in no bucket and fails the sum assertion, instead
|
|
25195
|
+
-- of silently joining this one.
|
|
25196
|
+
SUM(CASE WHEN synced_at IS NOT NULL AND synced_at <= 0
|
|
25197
|
+
AND (sync_failure IS NULL OR sync_failure = 'payload_invalid')
|
|
25198
|
+
THEN 1 ELSE 0 END) AS failed,
|
|
25199
|
+
COUNT(*) AS total`;
|
|
25200
|
+
var COUNTED_SCOPE = `
|
|
25201
|
+
WHERE event_type IN (${COUNTED_TYPE_LIST})
|
|
25202
|
+
AND (
|
|
25203
|
+
event_type IN (${TYPE_LIST})
|
|
25204
|
+
OR synced_at IS NOT NULL
|
|
25205
|
+
OR outbox_owed = 1
|
|
25206
|
+
)`;
|
|
25207
|
+
var SKIPPED = -1;
|
|
25208
|
+
var ROW_COLUMNS = `id,
|
|
25209
|
+
parent_id AS parentId,
|
|
25210
|
+
root_session_id AS rootSessionId,
|
|
25211
|
+
event_type AS eventType,
|
|
25212
|
+
host_id AS hostId,
|
|
25213
|
+
harness_id AS harnessId,
|
|
25214
|
+
source_project_id AS sourceProjectId,
|
|
25215
|
+
started_at AS startedAt,
|
|
25216
|
+
ended_at AS endedAt,
|
|
25217
|
+
severity,
|
|
25218
|
+
priority,
|
|
25219
|
+
content,
|
|
25220
|
+
content_hash AS contentHash,
|
|
25221
|
+
attributes`;
|
|
25222
|
+
var SqliteHistorySyncRepository = class {
|
|
25223
|
+
constructor(db) {
|
|
25224
|
+
this.db = db;
|
|
25225
|
+
this.ensureRowStmt = db.prepare(`INSERT OR IGNORE INTO history_sync (id) VALUES (1)`);
|
|
25226
|
+
this.sessionsStmt = db.prepare(
|
|
25227
|
+
`SELECT COALESCE(root_session_id, id) AS sessionId, MIN(started_at) AS earliest
|
|
25228
|
+
FROM audit_events
|
|
25229
|
+
WHERE synced_at IS NULL
|
|
25230
|
+
AND event_type IN (${TYPE_LIST})
|
|
25231
|
+
AND started_at < :before
|
|
25232
|
+
GROUP BY sessionId
|
|
25233
|
+
ORDER BY earliest
|
|
25234
|
+
LIMIT :limit`
|
|
25235
|
+
);
|
|
25236
|
+
this.rowsStmt = db.prepare(
|
|
25237
|
+
`SELECT ${ROW_COLUMNS}
|
|
25238
|
+
FROM audit_events
|
|
25239
|
+
WHERE synced_at IS NULL
|
|
25240
|
+
AND event_type IN (${TYPE_LIST})
|
|
25241
|
+
AND started_at < :before
|
|
25242
|
+
AND COALESCE(root_session_id, id) = :sessionId
|
|
25243
|
+
ORDER BY (event_type = 'session') DESC, started_at
|
|
25244
|
+
LIMIT :limit`
|
|
25245
|
+
);
|
|
25246
|
+
this.captureRowsStmt = db.prepare(
|
|
25247
|
+
`SELECT ${ROW_COLUMNS}
|
|
25248
|
+
FROM audit_events
|
|
25249
|
+
WHERE synced_at IS NULL
|
|
25250
|
+
AND sync_claimed_at IS NULL
|
|
25251
|
+
AND outbox_owed = 1
|
|
25252
|
+
AND event_type IN (${CAPTURE_TYPE_LIST})
|
|
25253
|
+
AND started_at < :before
|
|
25254
|
+
ORDER BY started_at
|
|
25255
|
+
LIMIT :limit`
|
|
25256
|
+
);
|
|
25257
|
+
this.markOwedStmt = db.prepare(
|
|
25258
|
+
`UPDATE audit_events SET outbox_owed = 1 WHERE id = :id AND synced_at IS NULL`
|
|
25259
|
+
);
|
|
25260
|
+
this.markCaptureBacklogOwedStmt = db.prepare(
|
|
25261
|
+
`UPDATE audit_events SET outbox_owed = 1
|
|
25262
|
+
WHERE synced_at IS NULL
|
|
25263
|
+
AND event_type IN (${CAPTURE_TYPE_LIST})
|
|
25264
|
+
AND started_at < :before`
|
|
25265
|
+
);
|
|
25266
|
+
this.stampStmt = db.prepare(
|
|
25267
|
+
`UPDATE audit_events
|
|
25268
|
+
SET synced_at = :at,
|
|
25269
|
+
sync_claimed_at = NULL,
|
|
25270
|
+
sync_failed_at = :failedAt,
|
|
25271
|
+
sync_failure = :failure
|
|
25272
|
+
WHERE id = :id`
|
|
25273
|
+
);
|
|
25274
|
+
this.claimRowStmt = db.prepare(
|
|
25275
|
+
`UPDATE audit_events SET sync_claimed_at = :at WHERE id = :id AND synced_at IS NULL`
|
|
25276
|
+
);
|
|
25277
|
+
this.releaseRowStmt = db.prepare(
|
|
25278
|
+
`UPDATE audit_events SET sync_claimed_at = NULL WHERE id = :id`
|
|
25279
|
+
);
|
|
25280
|
+
this.releaseStaleClaimsStmt = db.prepare(
|
|
25281
|
+
`UPDATE audit_events SET sync_claimed_at = NULL
|
|
25282
|
+
WHERE sync_claimed_at IS NOT NULL AND sync_claimed_at < :staleBefore`
|
|
25283
|
+
);
|
|
25284
|
+
this.partitionStmt = db.prepare(`SELECT${PARTITION_BUCKETS}
|
|
25285
|
+
FROM audit_events${COUNTED_SCOPE}`);
|
|
25286
|
+
this.partitionByKindStmt = db.prepare(
|
|
25287
|
+
`SELECT event_type AS kind,${PARTITION_BUCKETS}
|
|
25288
|
+
FROM audit_events INDEXED BY idx_audit_events_sync${COUNTED_SCOPE}
|
|
25289
|
+
GROUP BY event_type`
|
|
25290
|
+
);
|
|
25291
|
+
this.countsStmt = db.prepare(
|
|
25292
|
+
`SELECT
|
|
25293
|
+
SUM(CASE WHEN synced_at IS NULL AND started_at < :before THEN 1 ELSE 0 END) AS pending,
|
|
25294
|
+
SUM(CASE WHEN synced_at > 0 THEN 1 ELSE 0 END) AS sent,
|
|
25295
|
+
SUM(CASE WHEN synced_at = ${String(SKIPPED)}
|
|
25296
|
+
AND (sync_failure IS NULL OR sync_failure = 'payload_invalid')
|
|
25297
|
+
THEN 1 ELSE 0 END) AS skipped,
|
|
25298
|
+
SUM(CASE WHEN synced_at = ${String(SKIPPED)}
|
|
25299
|
+
AND sync_failure = 'deployment_refused' THEN 1 ELSE 0 END) AS refused,
|
|
25300
|
+
SUM(CASE WHEN synced_at = ${String(SKIPPED)}
|
|
25301
|
+
AND sync_failure = 'detached_undelivered' THEN 1 ELSE 0 END) AS detached
|
|
25302
|
+
FROM audit_events
|
|
25303
|
+
WHERE event_type IN (${TYPE_LIST})`
|
|
25304
|
+
);
|
|
25305
|
+
this.captureSkipCountStmt = db.prepare(
|
|
25306
|
+
// EVERY sentinel capture, whatever the reason — deliberately NOT split the
|
|
25307
|
+
// way the structural totals are. The split exists because a refusal is
|
|
25308
|
+
// terminal only against the deployment that gave it, and the structural
|
|
25309
|
+
// re-arm frees it on a change of deployment. The capture lane has no such
|
|
25310
|
+
// escape: re-arming a capture would offer one deployment's undelivered
|
|
25311
|
+
// prompts, with their text, to a deployment that never saw them, which is
|
|
25312
|
+
// exactly what disownCapturesStmt exists to prevent. So on this lane both
|
|
25313
|
+
// reasons mean the same thing — this row will not be sent — and splitting
|
|
25314
|
+
// them would put refused captures in a bucket nothing reads and nothing
|
|
25315
|
+
// frees.
|
|
25316
|
+
`SELECT COUNT(*) AS skipped
|
|
25317
|
+
FROM audit_events
|
|
25318
|
+
WHERE synced_at = ${String(SKIPPED)}
|
|
25319
|
+
AND event_type IN (${CAPTURE_TYPE_LIST})`
|
|
25320
|
+
);
|
|
25321
|
+
this.fingerprintStmt = db.prepare(
|
|
25322
|
+
`SELECT endpoint_fingerprint AS fingerprint, backlog_before AS backlogBefore
|
|
25323
|
+
FROM history_sync WHERE id = 1`
|
|
25324
|
+
);
|
|
25325
|
+
this.setFingerprintStmt = db.prepare(
|
|
25326
|
+
`UPDATE history_sync
|
|
25327
|
+
SET endpoint_fingerprint = :fingerprint, backlog_before = :backlogBefore
|
|
25328
|
+
WHERE id = 1`
|
|
25329
|
+
);
|
|
25330
|
+
this.disownCapturesStmt = db.prepare(
|
|
25331
|
+
`UPDATE audit_events SET outbox_owed = NULL
|
|
25332
|
+
WHERE outbox_owed IS NOT NULL
|
|
25333
|
+
AND event_type IN (${CAPTURE_TYPE_LIST})
|
|
25334
|
+
AND started_at < :attachedAt`
|
|
25335
|
+
);
|
|
25336
|
+
this.rearmStmt = db.prepare(
|
|
25337
|
+
`UPDATE audit_events
|
|
25338
|
+
SET synced_at = NULL, sync_failed_at = NULL, sync_failure = NULL
|
|
25339
|
+
WHERE (synced_at > 0
|
|
25340
|
+
OR sync_failure IN ('deployment_refused', 'detached_undelivered'))
|
|
25341
|
+
AND event_type IN (${TYPE_LIST})`
|
|
25342
|
+
);
|
|
25343
|
+
this.claimStmt = db.prepare(
|
|
25344
|
+
`UPDATE history_sync
|
|
25345
|
+
SET owner_pid = :pid, owner_host = :host, acquired_at = :now, heartbeat_at = :now
|
|
25346
|
+
WHERE id = 1
|
|
25347
|
+
AND (owner_pid IS NULL
|
|
25348
|
+
OR heartbeat_at IS NULL
|
|
25349
|
+
OR heartbeat_at < :staleBefore
|
|
25350
|
+
OR heartbeat_at > :now)`
|
|
25351
|
+
);
|
|
25352
|
+
this.heartbeatStmt = db.prepare(
|
|
25353
|
+
`UPDATE history_sync SET heartbeat_at = :now WHERE id = 1 AND owner_pid = :pid`
|
|
25354
|
+
);
|
|
25355
|
+
this.releaseStmt = db.prepare(
|
|
25356
|
+
`UPDATE history_sync
|
|
25357
|
+
SET owner_pid = NULL, owner_host = NULL, acquired_at = NULL, heartbeat_at = NULL
|
|
25358
|
+
WHERE id = 1 AND owner_pid = :pid`
|
|
25359
|
+
);
|
|
25360
|
+
this.closeWindowStmt = db.prepare(
|
|
25361
|
+
`UPDATE audit_events
|
|
25362
|
+
SET synced_at = ${String(SKIPPED)},
|
|
25363
|
+
sync_failed_at = :at,
|
|
25364
|
+
sync_failure = 'detached_undelivered'
|
|
25365
|
+
WHERE synced_at IS NULL
|
|
25366
|
+
AND event_type IN (${TYPE_LIST})
|
|
25367
|
+
AND started_at >= :attachedAt`
|
|
25368
|
+
);
|
|
25369
|
+
this.releaseBoundaryStmt = db.prepare(
|
|
25370
|
+
`UPDATE history_sync SET backlog_before = NULL WHERE id = 1`
|
|
25371
|
+
);
|
|
25372
|
+
this.freezeBoundaryStmt = db.prepare(
|
|
25373
|
+
`UPDATE history_sync SET backlog_before = :backlogBefore WHERE id = 1`
|
|
25374
|
+
);
|
|
25375
|
+
this.leaseStmt = db.prepare(
|
|
25376
|
+
`SELECT owner_pid AS ownerPid, owner_host AS ownerHost,
|
|
25377
|
+
acquired_at AS acquiredAt, heartbeat_at AS heartbeatAt
|
|
25378
|
+
FROM history_sync WHERE id = 1`
|
|
25379
|
+
);
|
|
25380
|
+
this.inspectionsStmt = db.prepare(
|
|
25381
|
+
`SELECT d.rule_id AS ruleId,
|
|
25382
|
+
d.name AS ruleName,
|
|
25383
|
+
d.version AS ruleVersion,
|
|
25384
|
+
d.category AS category,
|
|
25385
|
+
d.severity AS severity,
|
|
25386
|
+
f.span_start AS spanStart,
|
|
25387
|
+
f.span_end AS spanEnd,
|
|
25388
|
+
f.masked_match AS maskedMatch,
|
|
25389
|
+
f.action_taken AS actionTaken,
|
|
25390
|
+
f.confidence AS confidence
|
|
25391
|
+
FROM inspection_findings f
|
|
25392
|
+
JOIN inspection_definitions d ON d.id = f.inspection_definition_id
|
|
25393
|
+
WHERE f.audit_event_id = :auditEventId
|
|
25394
|
+
ORDER BY f.span_start, f.id`
|
|
25395
|
+
);
|
|
25396
|
+
}
|
|
25397
|
+
db;
|
|
25398
|
+
ensureRowStmt;
|
|
25399
|
+
sessionsStmt;
|
|
25400
|
+
rowsStmt;
|
|
25401
|
+
stampStmt;
|
|
25402
|
+
countsStmt;
|
|
25403
|
+
fingerprintStmt;
|
|
25404
|
+
setFingerprintStmt;
|
|
25405
|
+
rearmStmt;
|
|
25406
|
+
claimStmt;
|
|
25407
|
+
heartbeatStmt;
|
|
25408
|
+
releaseStmt;
|
|
25409
|
+
leaseStmt;
|
|
25410
|
+
inspectionsStmt;
|
|
25411
|
+
closeWindowStmt;
|
|
25412
|
+
releaseBoundaryStmt;
|
|
25413
|
+
freezeBoundaryStmt;
|
|
25414
|
+
captureRowsStmt;
|
|
25415
|
+
markOwedStmt;
|
|
25416
|
+
markCaptureBacklogOwedStmt;
|
|
25417
|
+
captureSkipCountStmt;
|
|
25418
|
+
disownCapturesStmt;
|
|
25419
|
+
partitionStmt;
|
|
25420
|
+
partitionByKindStmt;
|
|
25421
|
+
claimRowStmt;
|
|
25422
|
+
releaseRowStmt;
|
|
25423
|
+
releaseStaleClaimsStmt;
|
|
25424
|
+
/**
|
|
25425
|
+
* The masked detections recorded against one tool call.
|
|
25426
|
+
*
|
|
25427
|
+
* These travel with the event because a tool call's target is not
|
|
25428
|
+
* re-inspectable from the event alone — unlike a capture, where the text
|
|
25429
|
+
* itself is re-scannable. What crosses is the masked match and the rule that
|
|
25430
|
+
* produced it, never the value.
|
|
25431
|
+
*/
|
|
25432
|
+
inspectionsFor(auditEventId) {
|
|
25433
|
+
return allRows(this.inspectionsStmt, { auditEventId });
|
|
25434
|
+
}
|
|
25435
|
+
/**
|
|
25436
|
+
* Sessions with structural rows still to send, oldest first.
|
|
25437
|
+
*
|
|
25438
|
+
* BOUNDED BY THE BACKLOG BOUNDARY, which is the whole correctness of this
|
|
25439
|
+
* read. Anything recorded after the machine attached is the live forward
|
|
25440
|
+
* path's to deliver; this drain exists for what was recorded before it, and a
|
|
25441
|
+
* row both paths send is at best a duplicate request and at worst — for a
|
|
25442
|
+
* session root — an overwrite of the inventory ids the live path resolved.
|
|
25443
|
+
*/
|
|
25444
|
+
pendingSessions(limit, before) {
|
|
25445
|
+
return allRows(this.sessionsStmt, { limit, before }).map(
|
|
25446
|
+
(r) => r.sessionId
|
|
25447
|
+
);
|
|
25448
|
+
}
|
|
25449
|
+
/** One session's undelivered structural rows within the backlog, root first. */
|
|
25450
|
+
pendingRows(sessionId, limit, before) {
|
|
25451
|
+
return allRows(this.rowsStmt, { sessionId, limit, before });
|
|
25452
|
+
}
|
|
25453
|
+
/**
|
|
25454
|
+
* Captures this machine still owes the deployment, oldest first.
|
|
25455
|
+
*
|
|
25456
|
+
* Selected by the `outbox_owed` marker the attached forward path writes, not
|
|
25457
|
+
* by a time window — see captureRowsStmt for why a window could not express
|
|
25458
|
+
* this. `before` is the grace window that leaves a just-recorded capture to
|
|
25459
|
+
* the live path.
|
|
25460
|
+
*/
|
|
25461
|
+
pendingCaptureRows(limit, before) {
|
|
25462
|
+
return allRows(this.captureRowsStmt, { limit, before });
|
|
25463
|
+
}
|
|
25464
|
+
/**
|
|
25465
|
+
* Record that a capture is OWED to the deployment.
|
|
25466
|
+
*
|
|
25467
|
+
* Written by the attached forward path when a live send did not confirm
|
|
25468
|
+
* delivery, and read by the drain as the whole of its eligibility test. It is
|
|
25469
|
+
* a fact rather than an inference: the machine was attached, the send did not
|
|
25470
|
+
* land, so the row is owed — which no time window can state, because the same
|
|
25471
|
+
* window that holds the rows a past attachment left owed also holds every
|
|
25472
|
+
* capture recorded while the machine was DETACHED, and those were never
|
|
25473
|
+
* offered to anyone.
|
|
25474
|
+
*
|
|
25475
|
+
* Idempotent, and never un-set: `markSynced` settling the row is what takes it
|
|
25476
|
+
* out of the drain's read.
|
|
25477
|
+
*/
|
|
25478
|
+
markCaptureOwed(id) {
|
|
25479
|
+
this.markOwedStmt.run({ id });
|
|
25480
|
+
}
|
|
25481
|
+
/**
|
|
25482
|
+
* Mark every capture already on disk as owed, as of `before`.
|
|
25483
|
+
*
|
|
25484
|
+
* The consent-time backfill, called once from `aka attach` when a human
|
|
25485
|
+
* grants existing-history consent — never from an ongoing drain pass, and
|
|
25486
|
+
* never inferred from a boundary that could later move. `before` is the
|
|
25487
|
+
* caller's own "now" at the moment consent was granted, so what this marks
|
|
25488
|
+
* is exactly the backlog the consent prompt already counted, not whatever a
|
|
25489
|
+
* later re-attach or key rotation might widen it to.
|
|
25490
|
+
*
|
|
25491
|
+
* Returns how many rows matched, for the caller to log or test against. Not a
|
|
25492
|
+
* count of NEWLY marked rows — a row still unsynced from an earlier call
|
|
25493
|
+
* matches again and is counted again, the same as `UPDATE`'s own `changes`.
|
|
25494
|
+
*/
|
|
25495
|
+
markCaptureBacklogOwed(before) {
|
|
25496
|
+
return Number(this.markCaptureBacklogOwedStmt.run({ before }).changes);
|
|
25497
|
+
}
|
|
25498
|
+
/**
|
|
25499
|
+
* Record delivery. Called only AFTER the far side has accepted the rows.
|
|
25500
|
+
*
|
|
25501
|
+
* CLEARS any failure reason in the same statement. A row that failed against
|
|
25502
|
+
* one deployment and then landed is delivered, and leaving the reason behind
|
|
25503
|
+
* would leave the store holding two contradictory answers about one row —
|
|
25504
|
+
* with the surface free to render either.
|
|
25505
|
+
*/
|
|
25506
|
+
markSynced(ids, atMs) {
|
|
25507
|
+
this.stampAll(ids, atMs, null);
|
|
25508
|
+
}
|
|
25509
|
+
/**
|
|
25510
|
+
* Record that THIS MACHINE cannot express the row on the wire.
|
|
25511
|
+
*
|
|
25512
|
+
* Reserved for a local defect — a row that cannot be rebuilt into a valid
|
|
25513
|
+
* payload, or a body the client itself refused to send. It fails identically
|
|
25514
|
+
* against every deployment, so it is terminal everywhere and the re-arm leaves
|
|
25515
|
+
* it alone. A row that merely failed to REACH the deployment stays NULL, so it
|
|
25516
|
+
* is retried; marking those would turn one outage into permanent data loss.
|
|
25517
|
+
*/
|
|
25518
|
+
markSkipped(ids, atMs) {
|
|
25519
|
+
this.stampAll(ids, SKIPPED, "payload_invalid", atMs);
|
|
25520
|
+
}
|
|
25521
|
+
/**
|
|
25522
|
+
* Record that THIS DEPLOYMENT refused the row.
|
|
25523
|
+
*
|
|
25524
|
+
* The same sentinel as `markSkipped`, and deliberately so: both stop the row
|
|
25525
|
+
* being re-offered on this lane, and `synced_at` goes on answering whether a
|
|
25526
|
+
* row is outstanding rather than why. What separates them is the reason, and
|
|
25527
|
+
* what the reason buys is the re-arm — a refusal is one deployment's verdict
|
|
25528
|
+
* on one body, so it is terminal only for as long as this machine points at
|
|
25529
|
+
* that deployment, and `rearmFor` clears it when the deployment changes.
|
|
25530
|
+
*
|
|
25531
|
+
* Leaving such a row NULL instead would be worse than the loss it replaces:
|
|
25532
|
+
* these reads carry no cursor, so an unstamped row the deployment refuses is
|
|
25533
|
+
* the head of every subsequent page, and the lane stalls behind it for ever.
|
|
25534
|
+
*/
|
|
25535
|
+
markRefused(ids, atMs) {
|
|
25536
|
+
this.stampAll(ids, SKIPPED, "deployment_refused", atMs);
|
|
25537
|
+
}
|
|
25538
|
+
eachInTransaction(ids, run) {
|
|
25539
|
+
if (ids.length === 0) return;
|
|
25540
|
+
withTransaction(
|
|
25541
|
+
this.db,
|
|
25542
|
+
() => {
|
|
25543
|
+
for (const id of ids) run(id);
|
|
25544
|
+
},
|
|
25545
|
+
"IMMEDIATE"
|
|
25546
|
+
);
|
|
25547
|
+
}
|
|
25548
|
+
stampAll(ids, value, failure, failedAtMs) {
|
|
25549
|
+
if (ids.length === 0) return;
|
|
25550
|
+
const failedAt = failure === null ? null : failedAtMs ?? null;
|
|
25551
|
+
withTransaction(
|
|
25552
|
+
this.db,
|
|
25553
|
+
() => {
|
|
25554
|
+
for (const id of ids) this.stampStmt.run({ at: value, failedAt, failure, id });
|
|
25555
|
+
},
|
|
25556
|
+
"IMMEDIATE"
|
|
25557
|
+
);
|
|
25558
|
+
}
|
|
25559
|
+
/**
|
|
25560
|
+
* Claim rows as in-flight.
|
|
25561
|
+
*
|
|
25562
|
+
* Advisory in exactly the sense the lease is: it records that a send is in
|
|
25563
|
+
* progress so a surface can say so, and a lost claim costs a row showing as
|
|
25564
|
+
* queued while it is actually being sent. It is not exclusion — the far side
|
|
25565
|
+
* settles a duplicate on the row id.
|
|
25566
|
+
*/
|
|
25567
|
+
claimRows(ids, atMs) {
|
|
25568
|
+
this.eachInTransaction(ids, (id) => this.claimRowStmt.run({ at: atMs, id }));
|
|
25569
|
+
}
|
|
25570
|
+
/** Give back a claim without settling — the send failed, the row is queued again. */
|
|
25571
|
+
releaseRows(ids) {
|
|
25572
|
+
this.eachInTransaction(ids, (id) => this.releaseRowStmt.run({ id }));
|
|
25573
|
+
}
|
|
25574
|
+
/**
|
|
25575
|
+
* Clear claims older than `staleBefore`, and report how many were cleared.
|
|
25576
|
+
*
|
|
25577
|
+
* A process killed between claiming and settling leaves rows claimed with
|
|
25578
|
+
* nothing left to settle them. Without this they read as "sending" for ever.
|
|
25579
|
+
*/
|
|
25580
|
+
releaseStaleClaims(staleBefore) {
|
|
25581
|
+
return Number(this.releaseStaleClaimsStmt.run({ staleBefore }).changes);
|
|
25582
|
+
}
|
|
25583
|
+
/**
|
|
25584
|
+
* Every tracked row in exactly one delivery state.
|
|
25585
|
+
*
|
|
25586
|
+
* Takes no boundary on purpose. The boundary answers "what should the drain
|
|
25587
|
+
* pick up now", which is a different question from "what state is this row
|
|
25588
|
+
* in" — and a machine that has never attached has no boundary to pass, so
|
|
25589
|
+
* requiring one would force a caller to invent one and report the whole store
|
|
25590
|
+
* as queued.
|
|
25591
|
+
*/
|
|
25592
|
+
/**
|
|
25593
|
+
* The same partition, one row per kind that a lane carries.
|
|
25594
|
+
*
|
|
25595
|
+
* A kind with nothing to report is ABSENT rather than a row of zeros: the
|
|
25596
|
+
* scope decides which rows exist at all, so a kind that has never been
|
|
25597
|
+
* recorded — or whose captures nobody ever owed — produces no group. A caller
|
|
25598
|
+
* rendering a fixed list of kinds must therefore treat a missing one as "no
|
|
25599
|
+
* rows", never as "zero sent"; the two look identical in a bar and mean
|
|
25600
|
+
* different things.
|
|
25601
|
+
*/
|
|
25602
|
+
partitionByKind() {
|
|
25603
|
+
return allRows(
|
|
25604
|
+
this.partitionByKindStmt,
|
|
25605
|
+
{}
|
|
25606
|
+
).map((row) => ({
|
|
25607
|
+
kind: row.kind,
|
|
25608
|
+
queued: row.queued ?? 0,
|
|
25609
|
+
inProgress: row.inProgress ?? 0,
|
|
25610
|
+
synced: row.synced ?? 0,
|
|
25611
|
+
failed: row.failed ?? 0,
|
|
25612
|
+
refused: row.refused ?? 0,
|
|
25613
|
+
detached: row.detached ?? 0,
|
|
25614
|
+
total: row.total ?? 0
|
|
25615
|
+
}));
|
|
25616
|
+
}
|
|
25617
|
+
partition() {
|
|
25618
|
+
const row = getRow(this.partitionStmt, {});
|
|
25619
|
+
return {
|
|
25620
|
+
queued: row?.queued ?? 0,
|
|
25621
|
+
inProgress: row?.inProgress ?? 0,
|
|
25622
|
+
synced: row?.synced ?? 0,
|
|
25623
|
+
failed: row?.failed ?? 0,
|
|
25624
|
+
refused: row?.refused ?? 0,
|
|
25625
|
+
detached: row?.detached ?? 0,
|
|
25626
|
+
total: row?.total ?? 0
|
|
25627
|
+
};
|
|
25628
|
+
}
|
|
25629
|
+
/** `pending` counts only what is inside the backlog; sent and skipped are totals. */
|
|
25630
|
+
counts(before) {
|
|
25631
|
+
const row = getRow(this.countsStmt, { before });
|
|
25632
|
+
const captures = getRow(this.captureSkipCountStmt);
|
|
25633
|
+
return {
|
|
25634
|
+
pending: row?.pending ?? 0,
|
|
25635
|
+
sent: row?.sent ?? 0,
|
|
25636
|
+
skipped: row?.skipped ?? 0,
|
|
25637
|
+
refused: row?.refused ?? 0,
|
|
25638
|
+
detached: row?.detached ?? 0,
|
|
25639
|
+
capturesSkipped: captures?.skipped ?? 0
|
|
25640
|
+
};
|
|
25641
|
+
}
|
|
25642
|
+
/**
|
|
25643
|
+
* The deployment the current stamps were made against, and where its backlog
|
|
25644
|
+
* ends.
|
|
25645
|
+
*
|
|
25646
|
+
* READ-ONLY. An absent row reads as an absent deployment, which is what a
|
|
25647
|
+
* machine that has never drained is — and every writer below seeds the row
|
|
25648
|
+
* before it needs one, so nothing depends on this creating it. Keeping the
|
|
25649
|
+
* write off the gate path matters because the gate runs on every pass while a
|
|
25650
|
+
* write has to take the database's write lock.
|
|
25651
|
+
*/
|
|
25652
|
+
deployment() {
|
|
25653
|
+
const row = getRow(
|
|
25654
|
+
this.fingerprintStmt
|
|
25655
|
+
);
|
|
25656
|
+
return {
|
|
25657
|
+
fingerprint: row?.fingerprint ?? void 0,
|
|
25658
|
+
backlogBefore: row?.backlogBefore ?? void 0
|
|
25659
|
+
};
|
|
25660
|
+
}
|
|
25661
|
+
/**
|
|
25662
|
+
* Point the ledger at a different deployment, discarding what it recorded
|
|
25663
|
+
* about the previous one.
|
|
25664
|
+
*
|
|
25665
|
+
* Delivery is a fact about ONE recipient: rows sent to the deployment a
|
|
25666
|
+
* machine has just left are undelivered as far as the new one is concerned.
|
|
25667
|
+
* All four in one transaction, so a crash between them cannot leave stamps
|
|
25668
|
+
* attributed to the wrong deployment, a boundary that belongs to another, or
|
|
25669
|
+
* a disown with no re-mark to follow it.
|
|
25670
|
+
*
|
|
25671
|
+
* The boundary is written HERE and only here, which is what freezes it: a
|
|
25672
|
+
* re-attach to the SAME deployment (a key rotation) leaves the fingerprint
|
|
25673
|
+
* unchanged, so this never runs and the backlog does not widen back over rows
|
|
25674
|
+
* the live path has since delivered.
|
|
25675
|
+
*
|
|
25676
|
+
* `backfillCapturesBefore` is the caller's OWN "now" at the instant a human
|
|
25677
|
+
* granted existing-history consent for the deployment this call is arming —
|
|
25678
|
+
* a DIFFERENT instant from `backlogBefore`: the re-mark boundary is the GRANT
|
|
25679
|
+
* instant, `backlogBefore` is the ATTACH instant, and the two can be far
|
|
25680
|
+
* apart. Passed only when that grant is valid, since this method has no way
|
|
25681
|
+
* to check consent itself and must not mark a row owed for a machine that
|
|
25682
|
+
* never agreed to it. Applied AFTER the disown above, in the SAME
|
|
25683
|
+
* transaction: what the disown clears is every marker below `backlogBefore`,
|
|
25684
|
+
* which includes this deployment's OWN pre-attach rows — `aka attach` calls
|
|
25685
|
+
* `seedCaptureBacklogOwed` at the attach instant, so every row it marks sits
|
|
25686
|
+
* on the cleared side of that bound — and the re-mark in the same
|
|
25687
|
+
* transaction is what puts those rows back. A crash between the two cannot
|
|
25688
|
+
* strand the ledger disowned with nothing re-marked — the transaction either
|
|
25689
|
+
* lands whole or not at all, and a fingerprint mismatch that has not yet
|
|
25690
|
+
* committed re-enters this method on the very next pass. Omit it (the
|
|
25691
|
+
* structural-only tests do) to exercise the disown in isolation.
|
|
25692
|
+
*
|
|
25693
|
+
* The disown is bounded by `backlogBefore`, which is what keeps it from
|
|
25694
|
+
* touching a marker the NEW deployment's OWN live path has already set: B's
|
|
25695
|
+
* live path can mark a capture owed from the moment `aka attach` writes the
|
|
25696
|
+
* descriptor, before the drain's first pass ever reaches this method, and
|
|
25697
|
+
* such a row sits at or after the bound rather than below it. What keeps the
|
|
25698
|
+
* disown from eating THIS SAME CALL's own re-mark is the order, not the
|
|
25699
|
+
* bound — disown runs first, re-mark second, both inside the one
|
|
25700
|
+
* transaction above.
|
|
25701
|
+
*/
|
|
25702
|
+
rearmFor(fingerprint, backlogBefore, backfillCapturesBefore) {
|
|
25703
|
+
this.ensureRowStmt.run();
|
|
25704
|
+
withTransaction(
|
|
25705
|
+
this.db,
|
|
25706
|
+
() => {
|
|
25707
|
+
const previous = getRow(this.fingerprintStmt)?.fingerprint;
|
|
25708
|
+
this.rearmStmt.run();
|
|
25709
|
+
if (previous !== null && previous !== void 0 && previous !== fingerprint) {
|
|
25710
|
+
this.disownCapturesStmt.run({ attachedAt: backlogBefore });
|
|
25711
|
+
}
|
|
25712
|
+
if (backfillCapturesBefore !== void 0) {
|
|
25713
|
+
this.markCaptureBacklogOwedStmt.run({ before: backfillCapturesBefore });
|
|
25714
|
+
}
|
|
25715
|
+
this.setFingerprintStmt.run({ fingerprint, backlogBefore });
|
|
25716
|
+
},
|
|
25717
|
+
"IMMEDIATE"
|
|
25718
|
+
);
|
|
25719
|
+
}
|
|
25720
|
+
/**
|
|
25721
|
+
* End the attached period: hand its rows to the live path, and release the
|
|
25722
|
+
* boundary so the next attachment can freeze a new one.
|
|
25723
|
+
*
|
|
25724
|
+
* WITHOUT THIS, a detach and a re-attach to the same deployment leave a window
|
|
25725
|
+
* nothing delivers. The fingerprint is unchanged, so the boundary is never
|
|
25726
|
+
* re-frozen and stays at the FIRST attachment — while nothing forwards at all
|
|
25727
|
+
* during the detached period, because the machine is not attached. Rows
|
|
25728
|
+
* recorded in that window sit after the boundary and before the re-attach, so
|
|
25729
|
+
* neither path takes them, and the pending count reports none outstanding.
|
|
25730
|
+
*
|
|
25731
|
+
* WHAT IT RECORDS, and what it deliberately does not. These rows were the
|
|
25732
|
+
* closing attachment's to deliver and are no longer outstanding — that is what
|
|
25733
|
+
* lets the boundary move. It is NOT a claim that any of them arrived, and the
|
|
25734
|
+
* distinction is not academic: this used to write a delivery TIME, which every
|
|
25735
|
+
* read treats as delivery, so one detach turned a window of undelivered rows
|
|
25736
|
+
* into a window of delivered ones and no surface could tell. It writes the
|
|
25737
|
+
* skip sentinel and a reason of its own instead, so "no longer owed" and
|
|
25738
|
+
* "received" stop being the same fact.
|
|
25739
|
+
*
|
|
25740
|
+
* A change of deployment still frees them (see the re-arm), because the next
|
|
25741
|
+
* deployment has seen none of this machine's history — so the rows reach it
|
|
25742
|
+
* exactly as they did when this wrote a delivery time.
|
|
25743
|
+
*
|
|
25744
|
+
* ONE TRANSACTION, so a crash cannot release the boundary while leaving the
|
|
25745
|
+
* window unstamped — that half-state would re-send the whole attached period
|
|
25746
|
+
* on the next attach, which is the failure the boundary exists to prevent.
|
|
25747
|
+
*/
|
|
25748
|
+
closeAttachedWindow(attachedAtMs, atMs) {
|
|
25749
|
+
this.ensureRowStmt.run();
|
|
25750
|
+
withTransaction(
|
|
25751
|
+
this.db,
|
|
25752
|
+
() => {
|
|
25753
|
+
const row = getRow(this.fingerprintStmt);
|
|
25754
|
+
const from = row?.backlogBefore ?? attachedAtMs;
|
|
25755
|
+
this.closeWindowStmt.run({ at: atMs, attachedAt: from });
|
|
25756
|
+
this.releaseBoundaryStmt.run();
|
|
25757
|
+
},
|
|
25758
|
+
"IMMEDIATE"
|
|
25759
|
+
);
|
|
25760
|
+
}
|
|
25761
|
+
/**
|
|
25762
|
+
* Freeze a boundary for the deployment already on file, KEEPING the stamps.
|
|
25763
|
+
*
|
|
25764
|
+
* The re-attach half of the above. Distinct from `rearmFor`, which is for a
|
|
25765
|
+
* different deployment and therefore discards what was delivered to the old
|
|
25766
|
+
* one: here the recipient is the same, so everything already sent to it stays
|
|
25767
|
+
* sent.
|
|
25768
|
+
*/
|
|
25769
|
+
freezeBoundary(backlogBefore) {
|
|
25770
|
+
this.ensureRowStmt.run();
|
|
25771
|
+
this.freezeBoundaryStmt.run({ backlogBefore });
|
|
25772
|
+
}
|
|
25773
|
+
/** Take the claim, or report that someone live already holds it. */
|
|
25774
|
+
claim(pid, host, nowMs, staleAfterMs) {
|
|
25775
|
+
this.ensureRowStmt.run();
|
|
25776
|
+
let taken = false;
|
|
25777
|
+
withTransaction(
|
|
25778
|
+
this.db,
|
|
25779
|
+
() => {
|
|
25780
|
+
const result = this.claimStmt.run({
|
|
25781
|
+
pid,
|
|
25782
|
+
host,
|
|
25783
|
+
now: nowMs,
|
|
25784
|
+
staleBefore: nowMs - staleAfterMs
|
|
25785
|
+
});
|
|
25786
|
+
taken = result.changes === 1;
|
|
25787
|
+
},
|
|
25788
|
+
"IMMEDIATE"
|
|
25789
|
+
);
|
|
25790
|
+
return taken;
|
|
25791
|
+
}
|
|
25792
|
+
/** Say the holder is still alive. A no-op once the claim has moved on. */
|
|
25793
|
+
heartbeat(pid, nowMs) {
|
|
25794
|
+
this.heartbeatStmt.run({ now: nowMs, pid });
|
|
25795
|
+
}
|
|
25796
|
+
/** Give the claim up. Scoped to this holder, so a taken-over claim is left be. */
|
|
25797
|
+
release(pid) {
|
|
25798
|
+
this.releaseStmt.run({ pid });
|
|
25799
|
+
}
|
|
25800
|
+
/** Who holds the claim, if anyone. Read-only, for the same reason as above. */
|
|
25801
|
+
lease() {
|
|
25802
|
+
return getRow(this.leaseStmt);
|
|
25803
|
+
}
|
|
25804
|
+
};
|
|
25805
|
+
|
|
24787
25806
|
// ../../packages/persistence/src/migrations.ts
|
|
24788
25807
|
function describeObject(object2) {
|
|
24789
25808
|
return object2.kind === "column" ? `column ${object2.table}.${object2.name}` : `table ${object2.name}`;
|
|
@@ -24796,7 +25815,7 @@ function createdIndexName(statement) {
|
|
|
24796
25815
|
return /^CREATE (?:UNIQUE )?INDEX (?:IF NOT EXISTS )?`([^`]+)`/.exec(body)?.[1];
|
|
24797
25816
|
}
|
|
24798
25817
|
var LEGACY_DROP_MIGRATION_TAG = "0014_drop_legacy_events_findings";
|
|
24799
|
-
function applyMigrations(db, file2) {
|
|
25818
|
+
function applyMigrations(db, file2, options = {}) {
|
|
24800
25819
|
const legacyCount = db.prepare("PRAGMA user_version").get().user_version;
|
|
24801
25820
|
db.exec(
|
|
24802
25821
|
"CREATE TABLE IF NOT EXISTS migration_ledger (tag TEXT PRIMARY KEY, applied_at INTEGER NOT NULL)"
|
|
@@ -24810,6 +25829,7 @@ function applyMigrations(db, file2) {
|
|
|
24810
25829
|
);
|
|
24811
25830
|
for (const [index, migration] of SQLITE_MIGRATIONS.entries()) {
|
|
24812
25831
|
if (applied.has(migration.tag)) continue;
|
|
25832
|
+
if (options.skipTags?.has(migration.tag) === true) continue;
|
|
24813
25833
|
if (migration.tag === LEGACY_DROP_MIGRATION_TAG) continue;
|
|
24814
25834
|
const evidence = evidenceObjects(migration.sql);
|
|
24815
25835
|
const present = evidence.filter((o) => evidenceExists(db, o));
|
|
@@ -25216,10 +26236,62 @@ function ensureSyncedAtColumn(db, table2) {
|
|
|
25216
26236
|
if (!columns.includes("outbox_owed")) {
|
|
25217
26237
|
db.exec(`ALTER TABLE ${table2} ADD COLUMN outbox_owed integer`);
|
|
25218
26238
|
}
|
|
26239
|
+
if (!columns.includes("sync_failed_at")) {
|
|
26240
|
+
db.exec(`ALTER TABLE ${table2} ADD COLUMN sync_failed_at integer`);
|
|
26241
|
+
}
|
|
26242
|
+
if (!columns.includes("sync_failure")) {
|
|
26243
|
+
withTransaction(
|
|
26244
|
+
db,
|
|
26245
|
+
() => {
|
|
26246
|
+
db.exec(`ALTER TABLE ${table2} ADD COLUMN sync_failure text`);
|
|
26247
|
+
db.exec(
|
|
26248
|
+
`UPDATE ${table2} SET synced_at = NULL
|
|
26249
|
+
WHERE synced_at = -1
|
|
26250
|
+
AND event_type IN (${COUNTED_EVENT_TYPES.map((t) => `'${t}'`).join(", ")})`
|
|
26251
|
+
);
|
|
26252
|
+
},
|
|
26253
|
+
"IMMEDIATE"
|
|
26254
|
+
);
|
|
26255
|
+
}
|
|
25219
26256
|
db.exec(
|
|
25220
|
-
`CREATE
|
|
25221
|
-
|
|
26257
|
+
`CREATE TRIGGER IF NOT EXISTS aka_sync_failure_guard
|
|
26258
|
+
BEFORE UPDATE OF sync_failure ON ${table2}
|
|
26259
|
+
WHEN ${syncFailureRejectCondition()}
|
|
26260
|
+
BEGIN SELECT RAISE(ABORT, 'sync_failure is not one of the recorded reasons'); END`
|
|
25222
26261
|
);
|
|
26262
|
+
const syncIndexColumns = [
|
|
26263
|
+
"event_type",
|
|
26264
|
+
"synced_at",
|
|
26265
|
+
"sync_claimed_at",
|
|
26266
|
+
"started_at",
|
|
26267
|
+
// Appended LAST on purpose. The delivery-state read now projects it, so it
|
|
26268
|
+
// has to be in the index for the read to stay covered — but putting it
|
|
26269
|
+
// ahead of `started_at` would reorder the prefix the structural drain's
|
|
26270
|
+
// reads match on.
|
|
26271
|
+
"sync_failure"
|
|
26272
|
+
// `outbox_owed` is DELIBERATELY ABSENT, and it was measured both ways.
|
|
26273
|
+
//
|
|
26274
|
+
// The delivery-state read tests it — a capture's state depends on whether a
|
|
26275
|
+
// live forward marked it owed — so carrying it here makes that read covering
|
|
26276
|
+
// rather than a row fetch per row: 16 ms against 40 ms on a real 6 GB store.
|
|
26277
|
+
// But a sixth column changes what the planner charges for this index, and
|
|
26278
|
+
// with no ANALYZE statistics it plans from schema shape alone: measured, it
|
|
26279
|
+
// then stops choosing the per-session index for the token rollup and walks
|
|
26280
|
+
// every `llm_call` in the store through the event-type index instead. That
|
|
26281
|
+
// read grows with the store; this one does not.
|
|
26282
|
+
//
|
|
26283
|
+
// 40 ms on the largest store measured, once per render, is a cost worth
|
|
26284
|
+
// paying to leave every other read's plan where it was.
|
|
26285
|
+
];
|
|
26286
|
+
const currentSyncIndex = indexColumns(db, "idx_audit_events_sync");
|
|
26287
|
+
const syncIndexMatches = currentSyncIndex.length === syncIndexColumns.length && currentSyncIndex.every((column, i) => column === syncIndexColumns[i]);
|
|
26288
|
+
if (!syncIndexMatches) {
|
|
26289
|
+
db.exec("DROP INDEX IF EXISTS idx_audit_events_sync");
|
|
26290
|
+
db.exec(
|
|
26291
|
+
`CREATE INDEX idx_audit_events_sync
|
|
26292
|
+
ON audit_events (${syncIndexColumns.join(", ")})`
|
|
26293
|
+
);
|
|
26294
|
+
}
|
|
25223
26295
|
db.exec(
|
|
25224
26296
|
`CREATE INDEX IF NOT EXISTS idx_audit_outbox_owed
|
|
25225
26297
|
ON audit_events (event_type, synced_at, sync_claimed_at, started_at) WHERE outbox_owed = 1`
|
|
@@ -25441,7 +26513,11 @@ function buildAuditEvent(row) {
|
|
|
25441
26513
|
link: linkParsed?.success ? linkParsed.data : null,
|
|
25442
26514
|
targetId: row.target_id,
|
|
25443
26515
|
internal: intToBool(row.internal),
|
|
25444
|
-
flagged: intToBool(row.flagged)
|
|
26516
|
+
flagged: intToBool(row.flagged),
|
|
26517
|
+
// Only meaningful when the title came out empty — a row whose body was
|
|
26518
|
+
// expired but whose title fell back to `tool_name` still has something to
|
|
26519
|
+
// render, and flagging it would make the view apologise for nothing.
|
|
26520
|
+
bodyExpired: row.content_expired_at !== null && (row.title ?? "") === ""
|
|
25445
26521
|
};
|
|
25446
26522
|
}
|
|
25447
26523
|
var TIMELINE_COLUMNS = `
|
|
@@ -25449,6 +26525,7 @@ var TIMELINE_COLUMNS = `
|
|
|
25449
26525
|
event_type,
|
|
25450
26526
|
started_at,
|
|
25451
26527
|
coalesce(content, json_extract(attributes, '$.tool_name')) AS title,
|
|
26528
|
+
content_expired_at,
|
|
25452
26529
|
coalesce(json_extract(attributes, '$.detail'), json_extract(attributes, '$.target')) AS detail,
|
|
25453
26530
|
coalesce(json_extract(attributes, '$.tool_name'), json_extract(attributes, '$.tool')) AS tool,
|
|
25454
26531
|
json_extract(attributes, '$.severity') AS severity,
|
|
@@ -25575,7 +26652,8 @@ var SqliteActivityRepository = class {
|
|
|
25575
26652
|
SELECT 1 FROM audit_events d
|
|
25576
26653
|
WHERE d.root_session_id = audit_events.id
|
|
25577
26654
|
AND (d.content LIKE ? ESCAPE '\\'
|
|
25578
|
-
OR json_extract(d.attributes, '$.detail')
|
|
26655
|
+
OR coalesce(json_extract(d.attributes, '$.detail'),
|
|
26656
|
+
json_extract(d.attributes, '$.target')) LIKE ? ESCAPE '\\')))`
|
|
25579
26657
|
);
|
|
25580
26658
|
params.push(pattern, pattern, pattern, pattern, pattern, pattern);
|
|
25581
26659
|
}
|
|
@@ -26113,6 +27191,88 @@ var SqliteAuditEventsRepository = class {
|
|
|
26113
27191
|
}
|
|
26114
27192
|
};
|
|
26115
27193
|
|
|
27194
|
+
// ../../packages/persistence/src/repositories/body-retention.ts
|
|
27195
|
+
var DEFAULT_BATCH_SIZE = 500;
|
|
27196
|
+
var DEFAULT_MAX_ROWS = 5e4;
|
|
27197
|
+
var SYNC_LANE_TYPES_SQL = OUTBOX_CAPTURE_TYPE_LIST;
|
|
27198
|
+
var SqliteBodyRetentionRepository = class {
|
|
27199
|
+
constructor(db) {
|
|
27200
|
+
this.db = db;
|
|
27201
|
+
const select = (laneClause) => `
|
|
27202
|
+
SELECT id, LENGTH(CAST(content AS BLOB)) AS bytes
|
|
27203
|
+
FROM audit_events
|
|
27204
|
+
WHERE content IS NOT NULL
|
|
27205
|
+
AND started_at < :cutoff
|
|
27206
|
+
AND event_type IN (${CAPTURE_EVENT_TYPES_SQL})
|
|
27207
|
+
${laneClause}
|
|
27208
|
+
ORDER BY started_at
|
|
27209
|
+
LIMIT :limit`;
|
|
27210
|
+
this.candidatesStmt = this.db.prepare(select(""));
|
|
27211
|
+
this.candidatesSyncSafeStmt = this.db.prepare(
|
|
27212
|
+
select(`AND (event_type NOT IN (${SYNC_LANE_TYPES_SQL}) OR synced_at IS NOT NULL)`)
|
|
27213
|
+
);
|
|
27214
|
+
this.heldBySyncStmt = this.db.prepare(`
|
|
27215
|
+
SELECT COUNT(*) AS n
|
|
27216
|
+
FROM audit_events
|
|
27217
|
+
WHERE content IS NOT NULL
|
|
27218
|
+
AND started_at < :cutoff
|
|
27219
|
+
AND event_type IN (${SYNC_LANE_TYPES_SQL})
|
|
27220
|
+
AND synced_at IS NULL`);
|
|
27221
|
+
this.expireStmt = this.db.prepare(
|
|
27222
|
+
`UPDATE audit_events SET content = NULL, content_expired_at = :now WHERE id = :id`
|
|
27223
|
+
);
|
|
27224
|
+
}
|
|
27225
|
+
db;
|
|
27226
|
+
candidatesStmt;
|
|
27227
|
+
candidatesSyncSafeStmt;
|
|
27228
|
+
heldBySyncStmt;
|
|
27229
|
+
expireStmt;
|
|
27230
|
+
/** How many bytes a pass with these options would free, changing nothing. */
|
|
27231
|
+
preview(opts) {
|
|
27232
|
+
const limit = opts.maxRows ?? DEFAULT_MAX_ROWS;
|
|
27233
|
+
const stmt = opts.sweepSyncLane ? this.candidatesStmt : this.candidatesSyncSafeStmt;
|
|
27234
|
+
const rows = stmt.all({ cutoff: opts.cutoff, limit });
|
|
27235
|
+
return {
|
|
27236
|
+
rowsExpired: rows.length,
|
|
27237
|
+
bytesFreed: rows.reduce((sum, r) => sum + r.bytes, 0),
|
|
27238
|
+
rowsHeldBySync: this.countHeldBySync(opts)
|
|
27239
|
+
};
|
|
27240
|
+
}
|
|
27241
|
+
/** Clear eligible bodies, in bounded batches. */
|
|
27242
|
+
expire(opts) {
|
|
27243
|
+
const batchSize = opts.batchSize ?? DEFAULT_BATCH_SIZE;
|
|
27244
|
+
const maxRows = opts.maxRows ?? DEFAULT_MAX_ROWS;
|
|
27245
|
+
const stmt = opts.sweepSyncLane ? this.candidatesStmt : this.candidatesSyncSafeStmt;
|
|
27246
|
+
let rowsExpired = 0;
|
|
27247
|
+
let bytesFreed = 0;
|
|
27248
|
+
let done = true;
|
|
27249
|
+
while (rowsExpired < maxRows) {
|
|
27250
|
+
const remaining = Math.min(batchSize, maxRows - rowsExpired);
|
|
27251
|
+
const batch = stmt.all({ cutoff: opts.cutoff, limit: remaining });
|
|
27252
|
+
if (batch.length === 0) break;
|
|
27253
|
+
withTransaction(
|
|
27254
|
+
this.db,
|
|
27255
|
+
() => {
|
|
27256
|
+
for (const row of batch) this.expireStmt.run({ id: row.id, now: opts.now });
|
|
27257
|
+
},
|
|
27258
|
+
"IMMEDIATE"
|
|
27259
|
+
);
|
|
27260
|
+
rowsExpired += batch.length;
|
|
27261
|
+
bytesFreed += batch.reduce((sum, r) => sum + r.bytes, 0);
|
|
27262
|
+
if (batch.length < remaining) break;
|
|
27263
|
+
if (rowsExpired >= maxRows) {
|
|
27264
|
+
done = stmt.all({ cutoff: opts.cutoff, limit: 1 }).length === 0;
|
|
27265
|
+
}
|
|
27266
|
+
}
|
|
27267
|
+
return { rowsExpired, bytesFreed, rowsHeldBySync: this.countHeldBySync(opts), done };
|
|
27268
|
+
}
|
|
27269
|
+
countHeldBySync(opts) {
|
|
27270
|
+
if (opts.sweepSyncLane) return 0;
|
|
27271
|
+
const row = this.heldBySyncStmt.get({ cutoff: opts.cutoff });
|
|
27272
|
+
return row.n;
|
|
27273
|
+
}
|
|
27274
|
+
};
|
|
27275
|
+
|
|
26116
27276
|
// ../../packages/persistence/src/repositories/classified-data.ts
|
|
26117
27277
|
var SqliteClassifiedDataRepository = class {
|
|
26118
27278
|
constructor(db) {
|
|
@@ -26913,23 +28073,6 @@ var LATEST_RESOLUTION_BY_KEY_SQL = `(
|
|
|
26913
28073
|
)`;
|
|
26914
28074
|
|
|
26915
28075
|
// ../../packages/persistence/src/repositories/findings.ts
|
|
26916
|
-
var PREVIEW_INSTANCES_PER_GROUP = 200;
|
|
26917
|
-
var DEFAULT_LOCATIONS_LIMIT = 100;
|
|
26918
|
-
var LOCATION_RULE_IDS_CAP = 20;
|
|
26919
|
-
function compareLocationOrder(a, b) {
|
|
26920
|
-
return compareFindingGroupOrder(
|
|
26921
|
-
{
|
|
26922
|
-
severity: a.maxSeverity,
|
|
26923
|
-
latestDetectedAt: a.latestDetectedAt,
|
|
26924
|
-
id: ""
|
|
26925
|
-
},
|
|
26926
|
-
{
|
|
26927
|
-
severity: b.maxSeverity,
|
|
26928
|
-
latestDetectedAt: b.latestDetectedAt,
|
|
26929
|
-
id: ""
|
|
26930
|
-
}
|
|
26931
|
-
);
|
|
26932
|
-
}
|
|
26933
28076
|
var CONCAT_SEP = ",";
|
|
26934
28077
|
var TUPLE_SEP = "|";
|
|
26935
28078
|
function splitConcat(value) {
|
|
@@ -26958,7 +28101,15 @@ function toFlatFindingRow(r) {
|
|
|
26958
28101
|
...r.tool_name === null ? {} : { toolName: r.tool_name },
|
|
26959
28102
|
eventId: r.event_id,
|
|
26960
28103
|
...r.session_id === null ? {} : { sessionId: r.session_id },
|
|
26961
|
-
status: deriveInstanceStatus(r)
|
|
28104
|
+
status: deriveInstanceStatus(r),
|
|
28105
|
+
delivery: deriveFindingDelivery({
|
|
28106
|
+
kind: r.kind,
|
|
28107
|
+
syncedAt: r.synced_at,
|
|
28108
|
+
syncClaimedAt: r.sync_claimed_at,
|
|
28109
|
+
syncFailedAt: r.sync_failed_at,
|
|
28110
|
+
syncFailure: r.sync_failure,
|
|
28111
|
+
outboxOwed: r.outbox_owed
|
|
28112
|
+
})
|
|
26962
28113
|
};
|
|
26963
28114
|
}
|
|
26964
28115
|
function encodeGroupCursor(group) {
|
|
@@ -26981,13 +28132,51 @@ function decodeGroupCursor(cursor) {
|
|
|
26981
28132
|
return null;
|
|
26982
28133
|
}
|
|
26983
28134
|
function firstAfter(sorted, cursor) {
|
|
26984
|
-
const index = sorted.findIndex((
|
|
28135
|
+
const index = sorted.findIndex((t) => compareFindingGroupOrder(t, cursor) > 0);
|
|
26985
28136
|
return index === -1 ? sorted.length : index;
|
|
26986
28137
|
}
|
|
26987
28138
|
function findDeepLinked(sorted, page, id) {
|
|
26988
|
-
if (page.some((
|
|
26989
|
-
return sorted.find((
|
|
28139
|
+
if (page.some((t) => t.id === id)) return void 0;
|
|
28140
|
+
return sorted.find((t) => t.id === id);
|
|
28141
|
+
}
|
|
28142
|
+
function encodeLocationCursor(location) {
|
|
28143
|
+
const payload = {
|
|
28144
|
+
sev: location.maxSeverity,
|
|
28145
|
+
t: location.latestDetectedAt,
|
|
28146
|
+
r: location.repo,
|
|
28147
|
+
f: location.file
|
|
28148
|
+
};
|
|
28149
|
+
return Buffer.from(JSON.stringify(payload)).toString("base64url");
|
|
28150
|
+
}
|
|
28151
|
+
function decodeLocationCursor(cursor) {
|
|
28152
|
+
const parsed2 = parseJsonObject(Buffer.from(cursor, "base64url").toString("utf8"));
|
|
28153
|
+
if (parsed2 !== void 0 && typeof parsed2.sev === "string" && typeof parsed2.t === "string" && typeof parsed2.r === "string" && typeof parsed2.f === "string") {
|
|
28154
|
+
return { maxSeverity: parsed2.sev, latestDetectedAt: parsed2.t, repo: parsed2.r, file: parsed2.f };
|
|
28155
|
+
}
|
|
28156
|
+
return null;
|
|
26990
28157
|
}
|
|
28158
|
+
function firstLocationAfter(sorted, cursor) {
|
|
28159
|
+
const index = sorted.findIndex((l) => compareLocationOrder(l, cursor) > 0);
|
|
28160
|
+
return index === -1 ? sorted.length : index;
|
|
28161
|
+
}
|
|
28162
|
+
function findDeepLinkedLocation(sorted, page, id) {
|
|
28163
|
+
if (page.some((l) => l.id === id)) return void 0;
|
|
28164
|
+
return sorted.find((l) => l.id === id);
|
|
28165
|
+
}
|
|
28166
|
+
var FINDING_ROW_COLUMNS_SQL = `f.id AS id, d.rule_id AS rule_id, d.category AS category,
|
|
28167
|
+
d.severity AS severity, f.masked_match AS masked_match,
|
|
28168
|
+
f.action_taken AS action_taken, f.confidence AS confidence,
|
|
28169
|
+
e.started_at AS occurred_at,
|
|
28170
|
+
e.source_tool AS source_tool,
|
|
28171
|
+
e.repo AS repo,
|
|
28172
|
+
e.file_path AS file,
|
|
28173
|
+
e.tool_name AS tool_name,
|
|
28174
|
+
f.audit_event_id AS event_id, e.root_session_id AS session_id,
|
|
28175
|
+
e.event_type AS kind, f.finding_key AS finding_key,
|
|
28176
|
+
${latestResolutionStatusSql("f")} AS latest_status,
|
|
28177
|
+
e.synced_at AS synced_at, e.sync_claimed_at AS sync_claimed_at,
|
|
28178
|
+
e.sync_failed_at AS sync_failed_at, e.sync_failure AS sync_failure,
|
|
28179
|
+
e.outbox_owed AS outbox_owed`;
|
|
26991
28180
|
var DAY_MS3 = 864e5;
|
|
26992
28181
|
var SqliteFindingsRepository = class {
|
|
26993
28182
|
constructor(db) {
|
|
@@ -27108,30 +28297,26 @@ var SqliteFindingsRepository = class {
|
|
|
27108
28297
|
);
|
|
27109
28298
|
}
|
|
27110
28299
|
/**
|
|
27111
|
-
*
|
|
27112
|
-
*
|
|
27113
|
-
*
|
|
27114
|
-
*
|
|
27115
|
-
*
|
|
27116
|
-
*
|
|
27117
|
-
*
|
|
27118
|
-
*
|
|
27119
|
-
*
|
|
27120
|
-
*
|
|
27121
|
-
*
|
|
27122
|
-
*
|
|
28300
|
+
* Finding TYPES for the dashboard — one row per rule, scoped to the four
|
|
28301
|
+
* capture kinds (audit_events also holds structural/reconciler/scan rows this
|
|
28302
|
+
* list must never surface), with per-filter-excluded facets, the requested
|
|
28303
|
+
* filters applied, and sorted by severity then recency. Filtering and faceting
|
|
28304
|
+
* run in JS via the shared @akasecurity/schema helpers. `totals` reflect the
|
|
28305
|
+
* full filtered set; `items` is the requested page (default 50), keyset-paged.
|
|
28306
|
+
* Under a `status` filter, `totals.findings` counts only findings whose
|
|
28307
|
+
* derived status was requested.
|
|
28308
|
+
*
|
|
28309
|
+
* ONE read, which materializes no findings: a single aggregate per rule_id,
|
|
28310
|
+
* folding EVERY finding into the numbers a type row and the filters need
|
|
28311
|
+
* (count, severity, category, providers, actions, statuses, latest, search
|
|
28312
|
+
* text). The findings OF a type come from listFindingInstances scoped to
|
|
28313
|
+
* `subtype`, so neither list bounds the other and no per-type cap exists.
|
|
27123
28314
|
*
|
|
27124
|
-
* Two reads, neither of which materializes a row per finding:
|
|
27125
|
-
* 1. one aggregate row per rule_id, folding EVERY instance into the numbers
|
|
27126
|
-
* the group and the filters need (count, providers, actions, statuses,
|
|
27127
|
-
* latest, search text);
|
|
27128
|
-
* 2. each group's newest PREVIEW_INSTANCES_PER_GROUP instances, which
|
|
27129
|
-
* populate `instances` for the table's expanded rows.
|
|
27130
28315
|
* The aggregates carry raw DB values and are translated by the same
|
|
27131
|
-
* @akasecurity/schema mappers
|
|
27132
|
-
* rule is ever restated in SQL.
|
|
28316
|
+
* @akasecurity/schema mappers every other path uses, so no enum mapping or
|
|
28317
|
+
* status rule is ever restated in SQL.
|
|
27133
28318
|
*/
|
|
27134
|
-
|
|
28319
|
+
listFindingTypes(query) {
|
|
27135
28320
|
const sessionPredicate = query.sessionId ? ` AND e.root_session_id = :sessionId` : "";
|
|
27136
28321
|
const fromMs = query.from === void 0 ? void 0 : isoToEpochMillis(query.from);
|
|
27137
28322
|
const fromPredicate = fromMs === void 0 ? "" : ` AND e.started_at >= :fromMs`;
|
|
@@ -27144,12 +28329,7 @@ var SqliteFindingsRepository = class {
|
|
|
27144
28329
|
predicate,
|
|
27145
28330
|
params: sessionParams
|
|
27146
28331
|
});
|
|
27147
|
-
const
|
|
27148
|
-
sessionId: query.sessionId,
|
|
27149
|
-
from: query.from
|
|
27150
|
-
});
|
|
27151
|
-
const groupable = rows.map(toFlatFindingRow);
|
|
27152
|
-
const allGroups = buildFindingGroups(groupable, { aggregates });
|
|
28332
|
+
const allTypes = buildFindingTypes(aggregates);
|
|
27153
28333
|
const filterOpts = {
|
|
27154
28334
|
severity: query.severity,
|
|
27155
28335
|
providers: query.provider,
|
|
@@ -27158,30 +28338,25 @@ var SqliteFindingsRepository = class {
|
|
|
27158
28338
|
subtype: query.subtype,
|
|
27159
28339
|
q: query.q
|
|
27160
28340
|
};
|
|
27161
|
-
const facets = computeFindingFacets(
|
|
27162
|
-
const sorted =
|
|
28341
|
+
const facets = computeFindingFacets(allTypes, filterOpts);
|
|
28342
|
+
const sorted = sortFindingTypes(applyFindingFilters(allTypes, filterOpts));
|
|
27163
28343
|
const statusFilter = query.status ?? [];
|
|
27164
28344
|
const totals = {
|
|
27165
|
-
findings: sorted.reduce((acc,
|
|
27166
|
-
if (statusFilter.length === 0) return acc +
|
|
27167
|
-
const agg = aggregates.get(
|
|
27168
|
-
return acc + (agg ? countInstancesByStatus(agg.statusInputs, statusFilter) ??
|
|
28345
|
+
findings: sorted.reduce((acc, t) => {
|
|
28346
|
+
if (statusFilter.length === 0) return acc + t.instanceCount;
|
|
28347
|
+
const agg = aggregates.get(t.id);
|
|
28348
|
+
return acc + (agg ? countInstancesByStatus(agg.statusInputs, statusFilter) ?? t.instanceCount : t.instanceCount);
|
|
27169
28349
|
}, 0),
|
|
27170
|
-
|
|
28350
|
+
types: sorted.length
|
|
27171
28351
|
};
|
|
27172
|
-
const limit = query.limit ??
|
|
28352
|
+
const limit = query.limit ?? DEFAULT_FINDING_TYPES_LIMIT;
|
|
27173
28353
|
const cursor = query.cursor === void 0 ? null : decodeGroupCursor(query.cursor);
|
|
27174
28354
|
const start = cursor === null ? 0 : firstAfter(sorted, cursor);
|
|
27175
28355
|
const page = sorted.slice(start, start + limit);
|
|
27176
28356
|
const lastOnPage = page.at(-1);
|
|
27177
28357
|
const nextCursor = start + limit < sorted.length && lastOnPage ? encodeGroupCursor(lastOnPage) : null;
|
|
27178
28358
|
const deepLinked = query.includeId === void 0 || query.includeId === "" ? void 0 : findDeepLinked(sorted, page, query.includeId);
|
|
27179
|
-
const
|
|
27180
|
-
const narrow = (g) => statusSet ? {
|
|
27181
|
-
...g,
|
|
27182
|
-
instances: g.instances.filter((i) => i.status !== void 0 && statusSet.has(i.status))
|
|
27183
|
-
} : g;
|
|
27184
|
-
const items = [...page, ...deepLinked ? [deepLinked] : []].map(narrow);
|
|
28359
|
+
const items = [...page, ...deepLinked ? [deepLinked] : []];
|
|
27185
28360
|
return Promise.resolve({
|
|
27186
28361
|
totals,
|
|
27187
28362
|
facets,
|
|
@@ -27192,7 +28367,7 @@ var SqliteFindingsRepository = class {
|
|
|
27192
28367
|
}
|
|
27193
28368
|
/**
|
|
27194
28369
|
* One row per rule_id, folding EVERY instance of the group into the values
|
|
27195
|
-
*
|
|
28370
|
+
* buildFindingTypes cannot recover from an aggregate. Bounded by the number of
|
|
27196
28371
|
* distinct rule_ids (the installed packs' rules), not by the store's size.
|
|
27197
28372
|
*
|
|
27198
28373
|
* A single scan, folded in two levels: the inner SELECT groups by
|
|
@@ -27246,6 +28421,7 @@ var SqliteFindingsRepository = class {
|
|
|
27246
28421
|
providers: query.provider,
|
|
27247
28422
|
actions: query.action,
|
|
27248
28423
|
statuses: query.status,
|
|
28424
|
+
deliveries: query.deployment,
|
|
27249
28425
|
tools: query.tool,
|
|
27250
28426
|
repo: query.repo,
|
|
27251
28427
|
file: query.file,
|
|
@@ -27286,13 +28462,25 @@ var SqliteFindingsRepository = class {
|
|
|
27286
28462
|
});
|
|
27287
28463
|
}
|
|
27288
28464
|
/**
|
|
27289
|
-
* The same findings folded by
|
|
28465
|
+
* The same findings folded by WHERE they live — one row per (repo, file) pair.
|
|
27290
28466
|
*
|
|
27291
28467
|
* The grouping keys come from the capturing event's attributes, which is what
|
|
27292
|
-
* the local store relates a finding to
|
|
27293
|
-
*
|
|
27294
|
-
* empty-string bucket, which
|
|
27295
|
-
*
|
|
28468
|
+
* the local store relates a finding to; there is no finding↔asset row to group
|
|
28469
|
+
* by instead. A repo or file the event did not record folds into the
|
|
28470
|
+
* empty-string bucket, which is a real location like any other: it is listed,
|
|
28471
|
+
* it is selectable, and its `?loc=` token is as good as any other row's.
|
|
28472
|
+
*
|
|
28473
|
+
* ONE flat list rather than repos nesting files. A rollup can only be paged by
|
|
28474
|
+
* repo, which leaves the file list inside it unbounded — the shape the by-type
|
|
28475
|
+
* list was rebuilt to remove — and two-level pagination inside an
|
|
28476
|
+
* expand/collapse table is what pushed that view to master/detail in the first
|
|
28477
|
+
* place.
|
|
28478
|
+
*
|
|
28479
|
+
* Every filter narrows the FINDINGS and the locations fall out of what
|
|
28480
|
+
* survives, so each row's `instanceCount` is exactly what listFindingInstances
|
|
28481
|
+
* reports for the same filters scoped to that pair. The view depends on it:
|
|
28482
|
+
* one toolbar sits over both panels precisely because a location owns none of
|
|
28483
|
+
* its fields.
|
|
27296
28484
|
*/
|
|
27297
28485
|
listFindingLocations(query) {
|
|
27298
28486
|
const opts = {
|
|
@@ -27301,16 +28489,20 @@ var SqliteFindingsRepository = class {
|
|
|
27301
28489
|
providers: query.provider,
|
|
27302
28490
|
actions: query.action,
|
|
27303
28491
|
statuses: query.status,
|
|
28492
|
+
deliveries: query.deployment,
|
|
27304
28493
|
tools: query.tool,
|
|
27305
28494
|
q: query.q
|
|
27306
28495
|
};
|
|
27307
|
-
const limit = query.limit ??
|
|
28496
|
+
const limit = query.limit ?? DEFAULT_FINDING_LOCATIONS_LIMIT;
|
|
28497
|
+
const cursor = query.cursor === void 0 ? null : decodeLocationCursor(query.cursor);
|
|
27308
28498
|
const byRepo = /* @__PURE__ */ new Map();
|
|
28499
|
+
const accumulator = createInstanceFacetAccumulator(opts);
|
|
27309
28500
|
let total = 0;
|
|
27310
28501
|
for (const row of this.scanFindingRows({
|
|
27311
28502
|
sessionId: query.sessionId,
|
|
27312
28503
|
from: query.from
|
|
27313
28504
|
})) {
|
|
28505
|
+
accumulator.add(row);
|
|
27314
28506
|
if (!matchesInstanceFilters(row, opts)) continue;
|
|
27315
28507
|
total += 1;
|
|
27316
28508
|
let files = byRepo.get(row.repo);
|
|
@@ -27325,103 +28517,35 @@ var SqliteFindingsRepository = class {
|
|
|
27325
28517
|
}
|
|
27326
28518
|
addToLocation(acc, row);
|
|
27327
28519
|
}
|
|
27328
|
-
|
|
27329
|
-
const
|
|
27330
|
-
|
|
27331
|
-
|
|
27332
|
-
|
|
27333
|
-
|
|
27334
|
-
|
|
27335
|
-
|
|
27336
|
-
|
|
27337
|
-
|
|
27338
|
-
|
|
27339
|
-
|
|
27340
|
-
|
|
27341
|
-
|
|
27342
|
-
|
|
27343
|
-
|
|
27344
|
-
|
|
27345
|
-
|
|
27346
|
-
|
|
27347
|
-
|
|
27348
|
-
|
|
27349
|
-
|
|
27350
|
-
);
|
|
27351
|
-
const statuses = fileRows.map((f) => f.status);
|
|
27352
|
-
const folded = foldGroupStatus(statuses);
|
|
27353
|
-
return {
|
|
27354
|
-
repo,
|
|
27355
|
-
instanceCount: rollup.instanceCount,
|
|
27356
|
-
maxSeverity: rollup.maxSeverity,
|
|
27357
|
-
latestDetectedAt: rollup.latestDetectedAt,
|
|
27358
|
-
...folded === void 0 ? {} : { status: folded },
|
|
27359
|
-
files: fileRows
|
|
27360
|
-
};
|
|
27361
|
-
});
|
|
27362
|
-
repos.sort(compareLocationOrder);
|
|
28520
|
+
const sorted = [];
|
|
28521
|
+
for (const [repo, files] of byRepo) {
|
|
28522
|
+
for (const [file2, acc] of files) {
|
|
28523
|
+
const status = foldGroupStatus(acc.statuses);
|
|
28524
|
+
sorted.push({
|
|
28525
|
+
id: encodeLocationId(repo, file2),
|
|
28526
|
+
repo,
|
|
28527
|
+
file: file2,
|
|
28528
|
+
instanceCount: acc.instanceCount,
|
|
28529
|
+
maxSeverity: acc.maxSeverity,
|
|
28530
|
+
latestDetectedAt: acc.latestDetectedAt,
|
|
28531
|
+
...status === void 0 ? {} : { status },
|
|
28532
|
+
ruleIds: [...acc.ruleIds]
|
|
28533
|
+
});
|
|
28534
|
+
}
|
|
28535
|
+
}
|
|
28536
|
+
sorted.sort(compareLocationOrder);
|
|
28537
|
+
const start = cursor === null ? 0 : firstLocationAfter(sorted, cursor);
|
|
28538
|
+
const page = sorted.slice(start, start + limit);
|
|
28539
|
+
const lastOnPage = page.at(-1);
|
|
28540
|
+
const nextCursor = start + limit < sorted.length && lastOnPage ? encodeLocationCursor(lastOnPage) : null;
|
|
28541
|
+
const deepLinked = query.includeId === void 0 || query.includeId === "" ? void 0 : findDeepLinkedLocation(sorted, page, query.includeId);
|
|
27363
28542
|
return Promise.resolve({
|
|
27364
|
-
totals: { findings: total,
|
|
27365
|
-
|
|
27366
|
-
|
|
28543
|
+
totals: { findings: total, locations: sorted.length },
|
|
28544
|
+
facets: accumulator.facets(),
|
|
28545
|
+
items: [...page, ...deepLinked ? [deepLinked] : []],
|
|
28546
|
+
nextCursor
|
|
27367
28547
|
});
|
|
27368
28548
|
}
|
|
27369
|
-
/**
|
|
27370
|
-
* Each group's newest instances, for the table's expanded rows.
|
|
27371
|
-
*
|
|
27372
|
-
* ONE index-ordered scan with early termination, and the shape is the point.
|
|
27373
|
-
* The natural spelling — `ROW_NUMBER() OVER (PARTITION BY rule_id ORDER BY
|
|
27374
|
-
* started_at DESC)` then `WHERE rn <= cap` — sorts EVERY finding in scope
|
|
27375
|
-
* through a temp B-tree to keep a bounded preview of each group, and then
|
|
27376
|
-
* sorts the survivors again for the page order. Both sorts grow with the
|
|
27377
|
-
* store while the answer does not.
|
|
27378
|
-
*
|
|
27379
|
-
* Instead the scan walks `audit_events` newest-first off `idx_audit_started_at`
|
|
27380
|
-
* (or the session or window index the scope names — see `findingScanSql`),
|
|
27381
|
-
* which is already the order the page wants, and keeps rows per rule until
|
|
27382
|
-
* each rule has as many as it can show. The aggregate the caller already holds
|
|
27383
|
-
* says how many that is: `min(instanceCount, PREVIEW_INSTANCES_PER_GROUP)`
|
|
27384
|
-
* per rule, summed, is the number of rows this scan has to find, and it stops
|
|
27385
|
-
* on the last one. That sum is bounded by `rules * PREVIEW_INSTANCES_PER_GROUP`
|
|
27386
|
-
* (8,000 at this repo's 40-rule bench corpus), not by a fixed row count — a
|
|
27387
|
-
* store with many firing rules widens it. The bound that DOES hold
|
|
27388
|
-
* unconditionally is the sorted form's floor: this scan visits at most as
|
|
27389
|
-
* many rows as `ROW_NUMBER() OVER (PARTITION BY rule_id …)` would have
|
|
27390
|
-
* sorted, and stops the moment every rule has its cap, where the sorted form
|
|
27391
|
-
* sorts the whole scope regardless. The true worst case — the rarest rule's
|
|
27392
|
-
* wanted instances sitting at the tail of the scope — is one pass over
|
|
27393
|
-
* everything in scope with a block sort of the id tie-break only, never a
|
|
27394
|
-
* sort of the scope, which is still that floor.
|
|
27395
|
-
*
|
|
27396
|
-
* A row whose rule the aggregate did not see is skipped: the two statements
|
|
27397
|
-
* run without a shared snapshot, so a capture landing between them can add a
|
|
27398
|
-
* rule here that has no counts there, and the counts are what the group is
|
|
27399
|
-
* built from.
|
|
27400
|
-
*/
|
|
27401
|
-
previewRows(aggregates, scope) {
|
|
27402
|
-
const wanted = /* @__PURE__ */ new Map();
|
|
27403
|
-
let remaining = 0;
|
|
27404
|
-
for (const [ruleId, agg] of aggregates) {
|
|
27405
|
-
const n = Math.min(agg.instanceCount, PREVIEW_INSTANCES_PER_GROUP);
|
|
27406
|
-
wanted.set(ruleId, n);
|
|
27407
|
-
remaining += n;
|
|
27408
|
-
}
|
|
27409
|
-
const rows = [];
|
|
27410
|
-
if (remaining === 0) return rows;
|
|
27411
|
-
const { sql, params } = this.findingScanSql(scope);
|
|
27412
|
-
const taken = /* @__PURE__ */ new Map();
|
|
27413
|
-
for (const r of iterateRows(this.db.prepare(sql), params)) {
|
|
27414
|
-
const want = wanted.get(r.rule_id);
|
|
27415
|
-
if (want === void 0) continue;
|
|
27416
|
-
const have = taken.get(r.rule_id) ?? 0;
|
|
27417
|
-
if (have >= want) continue;
|
|
27418
|
-
taken.set(r.rule_id, have + 1);
|
|
27419
|
-
rows.push(r);
|
|
27420
|
-
remaining -= 1;
|
|
27421
|
-
if (remaining === 0) break;
|
|
27422
|
-
}
|
|
27423
|
-
return rows;
|
|
27424
|
-
}
|
|
27425
28549
|
/**
|
|
27426
28550
|
* Every finding in scope as a FlatFindingRow, newest first, streamed.
|
|
27427
28551
|
*
|
|
@@ -27448,6 +28572,33 @@ var SqliteFindingsRepository = class {
|
|
|
27448
28572
|
yield toFlatFindingRow(r);
|
|
27449
28573
|
}
|
|
27450
28574
|
}
|
|
28575
|
+
/**
|
|
28576
|
+
* One finding by its own id, or null when no such row exists.
|
|
28577
|
+
*
|
|
28578
|
+
* A primary-key seek on `inspection_findings`, so its cost does not grow with
|
|
28579
|
+
* the store — and, unlike anything derived from a list page, it resolves a
|
|
28580
|
+
* finding of ANY age. That is what the Findings page's one-shot `?finding=`
|
|
28581
|
+
* deep link needs: the id it carries may name a finding thousands of rows
|
|
28582
|
+
* older than anything a first page holds.
|
|
28583
|
+
*
|
|
28584
|
+
* Deliberately UNFILTERED — no capture-kind, session or time predicate. It
|
|
28585
|
+
* RESOLVES an id; whether that row would survive the list's current filters is
|
|
28586
|
+
* a different question, and hiding the target because a filter excludes it is
|
|
28587
|
+
* worse than showing it.
|
|
28588
|
+
*
|
|
28589
|
+
* `groupId` on the result IS the rule id, so this one read answers both "which
|
|
28590
|
+
* type should the list select?" and "what does the drawer show?".
|
|
28591
|
+
*/
|
|
28592
|
+
findingInstance(id) {
|
|
28593
|
+
const row = this.db.prepare(
|
|
28594
|
+
`SELECT ${FINDING_ROW_COLUMNS_SQL}
|
|
28595
|
+
FROM inspection_findings f
|
|
28596
|
+
JOIN audit_events e ON e.id = f.audit_event_id
|
|
28597
|
+
JOIN inspection_definitions d ON d.id = f.inspection_definition_id
|
|
28598
|
+
WHERE f.id = ?`
|
|
28599
|
+
).get(id);
|
|
28600
|
+
return Promise.resolve(row === void 0 ? null : toInstanceDetail(toFlatFindingRow(row)));
|
|
28601
|
+
}
|
|
27451
28602
|
/**
|
|
27452
28603
|
* The one statement both instance-level scans run: every finding in scope,
|
|
27453
28604
|
* joined to its event and definition, newest first.
|
|
@@ -27481,17 +28632,7 @@ var SqliteFindingsRepository = class {
|
|
|
27481
28632
|
conditions.push("e.started_at >= ?");
|
|
27482
28633
|
params.push(isoToEpochMillis(scope.from));
|
|
27483
28634
|
}
|
|
27484
|
-
const sql = `SELECT
|
|
27485
|
-
d.severity AS severity, f.masked_match AS masked_match,
|
|
27486
|
-
f.action_taken AS action_taken, f.confidence AS confidence,
|
|
27487
|
-
e.started_at AS occurred_at,
|
|
27488
|
-
e.source_tool AS source_tool,
|
|
27489
|
-
e.repo AS repo,
|
|
27490
|
-
e.file_path AS file,
|
|
27491
|
-
e.tool_name AS tool_name,
|
|
27492
|
-
f.audit_event_id AS event_id, e.root_session_id AS session_id,
|
|
27493
|
-
e.event_type AS kind, f.finding_key AS finding_key,
|
|
27494
|
-
${latestResolutionStatusSql("f")} AS latest_status
|
|
28635
|
+
const sql = `SELECT ${FINDING_ROW_COLUMNS_SQL}
|
|
27495
28636
|
FROM audit_events e
|
|
27496
28637
|
CROSS JOIN inspection_findings f ON f.audit_event_id = e.id
|
|
27497
28638
|
CROSS JOIN inspection_definitions d ON d.id = f.inspection_definition_id
|
|
@@ -27505,6 +28646,26 @@ var SqliteFindingsRepository = class {
|
|
|
27505
28646
|
group_concat(DISTINCT 'via ' || e.tool_name) AS tool_names` : `, NULL AS repos, NULL AS files, NULL AS tool_names`;
|
|
27506
28647
|
const rows = this.db.prepare(
|
|
27507
28648
|
`SELECT rule_id,
|
|
28649
|
+
-- BARE columns beside max(latest_at), which is deliberate and
|
|
28650
|
+
-- is SQLite's documented behaviour: with a single min()/max()
|
|
28651
|
+
-- in an aggregate query, every bare column takes its value from
|
|
28652
|
+
-- the row that produced the extremum. So these are the severity
|
|
28653
|
+
-- and category of the definition whose finding is NEWEST, which
|
|
28654
|
+
-- is what the row-based build they replaced read off its first
|
|
28655
|
+
-- (newest-first) row.
|
|
28656
|
+
--
|
|
28657
|
+
-- min() is WRONG here and was the defect: inspection_definitions
|
|
28658
|
+
-- holds one row per rule VERSION (see its writer \u2014 a version bump
|
|
28659
|
+
-- mints a new row), so a rule whose severity moved between
|
|
28660
|
+
-- versions has several, and min() picks the ALPHABETICALLY
|
|
28661
|
+
-- smallest \u2014 'low' over 'medium', but 'critical' over 'high'.
|
|
28662
|
+
-- That is arbitrary in direction, and it feeds the badge, the
|
|
28663
|
+
-- filter, the facet counts and the primary sort key.
|
|
28664
|
+
--
|
|
28665
|
+
-- Adding a second min()/max() aggregate here would make these
|
|
28666
|
+
-- bare columns ambiguous again; keep max(latest_at) the only one.
|
|
28667
|
+
severity,
|
|
28668
|
+
category,
|
|
27508
28669
|
sum(tuple_count) AS instance_count,
|
|
27509
28670
|
max(latest_at) AS latest_at,
|
|
27510
28671
|
group_concat(source_tools) AS source_tools,
|
|
@@ -27515,6 +28676,14 @@ var SqliteFindingsRepository = class {
|
|
|
27515
28676
|
group_concat(tool_names) AS tool_names
|
|
27516
28677
|
FROM (
|
|
27517
28678
|
SELECT d.rule_id AS rule_id,
|
|
28679
|
+
-- Severity and category are columns of the DEFINITION, and
|
|
28680
|
+
-- a rule can have SEVERAL definitions (one per version), so
|
|
28681
|
+
-- these are grouped on below and resolved to the newest
|
|
28682
|
+
-- firing version by the outer query's bare-column select.
|
|
28683
|
+
-- They ride the aggregate because the type build has no rows
|
|
28684
|
+
-- to read them off \u2014 see buildFindingTypes.
|
|
28685
|
+
d.severity AS severity,
|
|
28686
|
+
d.category AS category,
|
|
27518
28687
|
e.event_type || '${TUPLE_SEP}' ||
|
|
27519
28688
|
(CASE WHEN f.finding_key IS NULL THEN '' ELSE 'k' END) || '${TUPLE_SEP}' ||
|
|
27520
28689
|
coalesce(latest.status, '') AS status_tuple,
|
|
@@ -27529,7 +28698,7 @@ var SqliteFindingsRepository = class {
|
|
|
27529
28698
|
LEFT JOIN ${LATEST_RESOLUTION_BY_KEY_SQL} latest
|
|
27530
28699
|
ON latest.finding_key = f.finding_key
|
|
27531
28700
|
${scope.predicate}
|
|
27532
|
-
GROUP BY d.rule_id, status_tuple
|
|
28701
|
+
GROUP BY d.rule_id, d.severity, d.category, status_tuple
|
|
27533
28702
|
)
|
|
27534
28703
|
GROUP BY rule_id`
|
|
27535
28704
|
).all(scope.params);
|
|
@@ -27538,6 +28707,8 @@ var SqliteFindingsRepository = class {
|
|
|
27538
28707
|
r.rule_id,
|
|
27539
28708
|
{
|
|
27540
28709
|
instanceCount: r.instance_count,
|
|
28710
|
+
severity: r.severity,
|
|
28711
|
+
category: r.category,
|
|
27541
28712
|
sourceTools: splitConcat(r.source_tools),
|
|
27542
28713
|
actionsTaken: splitConcat(r.actions_taken),
|
|
27543
28714
|
statusInputs: splitConcat(r.status_inputs).map((tuple2) => {
|
|
@@ -27554,7 +28725,7 @@ var SqliteFindingsRepository = class {
|
|
|
27554
28725
|
latestDetectedAt: epochMillisToIso(r.latest_at),
|
|
27555
28726
|
// Free text only — joined and substring-matched, so group_concat's
|
|
27556
28727
|
// commas need no unpicking (a repo/path containing one still matches).
|
|
27557
|
-
// Left undefined (not '') when unfetched, so
|
|
28728
|
+
// Left undefined (not '') when unfetched, so buildFindingTypes can
|
|
27558
28729
|
// tell "no q this request" from "a group with no repo/file at all"
|
|
27559
28730
|
// and skip priming a haystack nothing will read.
|
|
27560
28731
|
...withSearchText ? {
|
|
@@ -27582,7 +28753,9 @@ var SqliteFindingsRepository = class {
|
|
|
27582
28753
|
)
|
|
27583
28754
|
);
|
|
27584
28755
|
for (const row of grouped) {
|
|
27585
|
-
if (
|
|
28756
|
+
if (Object.hasOwn(byAction, row.action_taken)) {
|
|
28757
|
+
byAction[row.action_taken] = row.c;
|
|
28758
|
+
}
|
|
27586
28759
|
}
|
|
27587
28760
|
const bySeverity = { critical: 0, high: 0, medium: 0, low: 0 };
|
|
27588
28761
|
const sevRows = allRows(
|
|
@@ -27599,7 +28772,9 @@ var SqliteFindingsRepository = class {
|
|
|
27599
28772
|
)
|
|
27600
28773
|
);
|
|
27601
28774
|
for (const row of sevRows) {
|
|
27602
|
-
if (
|
|
28775
|
+
if (Object.hasOwn(bySeverity, row.severity)) {
|
|
28776
|
+
bySeverity[row.severity] = row.c;
|
|
28777
|
+
}
|
|
27603
28778
|
}
|
|
27604
28779
|
const categories = ENFORCEABLE_CATEGORIES;
|
|
27605
28780
|
const enabledRows = allRows(
|
|
@@ -27648,469 +28823,6 @@ function isoDay(ms) {
|
|
|
27648
28823
|
return new Date(ms).toISOString().slice(0, 10);
|
|
27649
28824
|
}
|
|
27650
28825
|
|
|
27651
|
-
// ../../packages/persistence/src/repositories/history-sync.ts
|
|
27652
|
-
var STRUCTURAL_EVENT_TYPES = ["session", "llm_call", "tool_call"];
|
|
27653
|
-
var TYPE_LIST = STRUCTURAL_EVENT_TYPES.map((t) => `'${t}'`).join(", ");
|
|
27654
|
-
var OUTBOX_CAPTURE_EVENT_TYPES = ["prompt", "response", "tool_use"];
|
|
27655
|
-
var CAPTURE_TYPE_LIST = OUTBOX_CAPTURE_EVENT_TYPES.map((t) => `'${t}'`).join(", ");
|
|
27656
|
-
var SKIPPED = -1;
|
|
27657
|
-
var ROW_COLUMNS = `id,
|
|
27658
|
-
parent_id AS parentId,
|
|
27659
|
-
root_session_id AS rootSessionId,
|
|
27660
|
-
event_type AS eventType,
|
|
27661
|
-
host_id AS hostId,
|
|
27662
|
-
harness_id AS harnessId,
|
|
27663
|
-
source_project_id AS sourceProjectId,
|
|
27664
|
-
started_at AS startedAt,
|
|
27665
|
-
ended_at AS endedAt,
|
|
27666
|
-
severity,
|
|
27667
|
-
priority,
|
|
27668
|
-
content,
|
|
27669
|
-
content_hash AS contentHash,
|
|
27670
|
-
attributes`;
|
|
27671
|
-
var SqliteHistorySyncRepository = class {
|
|
27672
|
-
constructor(db) {
|
|
27673
|
-
this.db = db;
|
|
27674
|
-
this.ensureRowStmt = db.prepare(`INSERT OR IGNORE INTO history_sync (id) VALUES (1)`);
|
|
27675
|
-
this.sessionsStmt = db.prepare(
|
|
27676
|
-
`SELECT COALESCE(root_session_id, id) AS sessionId, MIN(started_at) AS earliest
|
|
27677
|
-
FROM audit_events
|
|
27678
|
-
WHERE synced_at IS NULL
|
|
27679
|
-
AND event_type IN (${TYPE_LIST})
|
|
27680
|
-
AND started_at < :before
|
|
27681
|
-
GROUP BY sessionId
|
|
27682
|
-
ORDER BY earliest
|
|
27683
|
-
LIMIT :limit`
|
|
27684
|
-
);
|
|
27685
|
-
this.rowsStmt = db.prepare(
|
|
27686
|
-
`SELECT ${ROW_COLUMNS}
|
|
27687
|
-
FROM audit_events
|
|
27688
|
-
WHERE synced_at IS NULL
|
|
27689
|
-
AND event_type IN (${TYPE_LIST})
|
|
27690
|
-
AND started_at < :before
|
|
27691
|
-
AND COALESCE(root_session_id, id) = :sessionId
|
|
27692
|
-
ORDER BY (event_type = 'session') DESC, started_at
|
|
27693
|
-
LIMIT :limit`
|
|
27694
|
-
);
|
|
27695
|
-
this.captureRowsStmt = db.prepare(
|
|
27696
|
-
`SELECT ${ROW_COLUMNS}
|
|
27697
|
-
FROM audit_events
|
|
27698
|
-
WHERE synced_at IS NULL
|
|
27699
|
-
AND sync_claimed_at IS NULL
|
|
27700
|
-
AND outbox_owed = 1
|
|
27701
|
-
AND event_type IN (${CAPTURE_TYPE_LIST})
|
|
27702
|
-
AND started_at < :before
|
|
27703
|
-
ORDER BY started_at
|
|
27704
|
-
LIMIT :limit`
|
|
27705
|
-
);
|
|
27706
|
-
this.markOwedStmt = db.prepare(
|
|
27707
|
-
`UPDATE audit_events SET outbox_owed = 1 WHERE id = :id AND synced_at IS NULL`
|
|
27708
|
-
);
|
|
27709
|
-
this.stampStmt = db.prepare(
|
|
27710
|
-
`UPDATE audit_events SET synced_at = :at, sync_claimed_at = NULL WHERE id = :id`
|
|
27711
|
-
);
|
|
27712
|
-
this.claimRowStmt = db.prepare(
|
|
27713
|
-
`UPDATE audit_events SET sync_claimed_at = :at WHERE id = :id AND synced_at IS NULL`
|
|
27714
|
-
);
|
|
27715
|
-
this.releaseRowStmt = db.prepare(
|
|
27716
|
-
`UPDATE audit_events SET sync_claimed_at = NULL WHERE id = :id`
|
|
27717
|
-
);
|
|
27718
|
-
this.releaseStaleClaimsStmt = db.prepare(
|
|
27719
|
-
`UPDATE audit_events SET sync_claimed_at = NULL
|
|
27720
|
-
WHERE sync_claimed_at IS NOT NULL AND sync_claimed_at < :staleBefore`
|
|
27721
|
-
);
|
|
27722
|
-
this.partitionStmt = db.prepare(
|
|
27723
|
-
`SELECT
|
|
27724
|
-
SUM(CASE WHEN synced_at IS NULL AND sync_claimed_at IS NULL THEN 1 ELSE 0 END) AS queued,
|
|
27725
|
-
SUM(CASE WHEN synced_at IS NULL AND sync_claimed_at IS NOT NULL THEN 1 ELSE 0 END) AS inProgress,
|
|
27726
|
-
SUM(CASE WHEN synced_at > 0 THEN 1 ELSE 0 END) AS synced,
|
|
27727
|
-
SUM(CASE WHEN synced_at IS NOT NULL AND synced_at <= 0 THEN 1 ELSE 0 END) AS failed,
|
|
27728
|
-
COUNT(*) AS total
|
|
27729
|
-
FROM audit_events
|
|
27730
|
-
WHERE event_type IN (${TYPE_LIST})`
|
|
27731
|
-
);
|
|
27732
|
-
this.countsStmt = db.prepare(
|
|
27733
|
-
`SELECT
|
|
27734
|
-
SUM(CASE WHEN synced_at IS NULL AND started_at < :before THEN 1 ELSE 0 END) AS pending,
|
|
27735
|
-
SUM(CASE WHEN synced_at > 0 THEN 1 ELSE 0 END) AS sent,
|
|
27736
|
-
SUM(CASE WHEN synced_at = ${String(SKIPPED)} THEN 1 ELSE 0 END) AS skipped
|
|
27737
|
-
FROM audit_events
|
|
27738
|
-
WHERE event_type IN (${TYPE_LIST})`
|
|
27739
|
-
);
|
|
27740
|
-
this.captureSkipCountStmt = db.prepare(
|
|
27741
|
-
`SELECT COUNT(*) AS skipped
|
|
27742
|
-
FROM audit_events
|
|
27743
|
-
WHERE synced_at = ${String(SKIPPED)}
|
|
27744
|
-
AND event_type IN (${CAPTURE_TYPE_LIST})`
|
|
27745
|
-
);
|
|
27746
|
-
this.fingerprintStmt = db.prepare(
|
|
27747
|
-
`SELECT endpoint_fingerprint AS fingerprint, backlog_before AS backlogBefore
|
|
27748
|
-
FROM history_sync WHERE id = 1`
|
|
27749
|
-
);
|
|
27750
|
-
this.setFingerprintStmt = db.prepare(
|
|
27751
|
-
`UPDATE history_sync
|
|
27752
|
-
SET endpoint_fingerprint = :fingerprint, backlog_before = :backlogBefore
|
|
27753
|
-
WHERE id = 1`
|
|
27754
|
-
);
|
|
27755
|
-
this.disownCapturesStmt = db.prepare(
|
|
27756
|
-
`UPDATE audit_events SET outbox_owed = NULL
|
|
27757
|
-
WHERE outbox_owed IS NOT NULL AND event_type IN (${CAPTURE_TYPE_LIST})`
|
|
27758
|
-
);
|
|
27759
|
-
this.rearmStmt = db.prepare(
|
|
27760
|
-
`UPDATE audit_events SET synced_at = NULL
|
|
27761
|
-
WHERE synced_at > 0 AND event_type IN (${TYPE_LIST})`
|
|
27762
|
-
);
|
|
27763
|
-
this.claimStmt = db.prepare(
|
|
27764
|
-
`UPDATE history_sync
|
|
27765
|
-
SET owner_pid = :pid, owner_host = :host, acquired_at = :now, heartbeat_at = :now
|
|
27766
|
-
WHERE id = 1
|
|
27767
|
-
AND (owner_pid IS NULL
|
|
27768
|
-
OR heartbeat_at IS NULL
|
|
27769
|
-
OR heartbeat_at < :staleBefore
|
|
27770
|
-
OR heartbeat_at > :now)`
|
|
27771
|
-
);
|
|
27772
|
-
this.heartbeatStmt = db.prepare(
|
|
27773
|
-
`UPDATE history_sync SET heartbeat_at = :now WHERE id = 1 AND owner_pid = :pid`
|
|
27774
|
-
);
|
|
27775
|
-
this.releaseStmt = db.prepare(
|
|
27776
|
-
`UPDATE history_sync
|
|
27777
|
-
SET owner_pid = NULL, owner_host = NULL, acquired_at = NULL, heartbeat_at = NULL
|
|
27778
|
-
WHERE id = 1 AND owner_pid = :pid`
|
|
27779
|
-
);
|
|
27780
|
-
this.closeWindowStmt = db.prepare(
|
|
27781
|
-
`UPDATE audit_events SET synced_at = :at
|
|
27782
|
-
WHERE synced_at IS NULL
|
|
27783
|
-
AND event_type IN (${TYPE_LIST})
|
|
27784
|
-
AND started_at >= :attachedAt`
|
|
27785
|
-
);
|
|
27786
|
-
this.releaseBoundaryStmt = db.prepare(
|
|
27787
|
-
`UPDATE history_sync SET backlog_before = NULL WHERE id = 1`
|
|
27788
|
-
);
|
|
27789
|
-
this.freezeBoundaryStmt = db.prepare(
|
|
27790
|
-
`UPDATE history_sync SET backlog_before = :backlogBefore WHERE id = 1`
|
|
27791
|
-
);
|
|
27792
|
-
this.leaseStmt = db.prepare(
|
|
27793
|
-
`SELECT owner_pid AS ownerPid, owner_host AS ownerHost,
|
|
27794
|
-
acquired_at AS acquiredAt, heartbeat_at AS heartbeatAt
|
|
27795
|
-
FROM history_sync WHERE id = 1`
|
|
27796
|
-
);
|
|
27797
|
-
this.inspectionsStmt = db.prepare(
|
|
27798
|
-
`SELECT d.rule_id AS ruleId,
|
|
27799
|
-
d.name AS ruleName,
|
|
27800
|
-
d.version AS ruleVersion,
|
|
27801
|
-
d.category AS category,
|
|
27802
|
-
d.severity AS severity,
|
|
27803
|
-
f.span_start AS spanStart,
|
|
27804
|
-
f.span_end AS spanEnd,
|
|
27805
|
-
f.masked_match AS maskedMatch,
|
|
27806
|
-
f.action_taken AS actionTaken,
|
|
27807
|
-
f.confidence AS confidence
|
|
27808
|
-
FROM inspection_findings f
|
|
27809
|
-
JOIN inspection_definitions d ON d.id = f.inspection_definition_id
|
|
27810
|
-
WHERE f.audit_event_id = :auditEventId
|
|
27811
|
-
ORDER BY f.span_start, f.id`
|
|
27812
|
-
);
|
|
27813
|
-
}
|
|
27814
|
-
db;
|
|
27815
|
-
ensureRowStmt;
|
|
27816
|
-
sessionsStmt;
|
|
27817
|
-
rowsStmt;
|
|
27818
|
-
stampStmt;
|
|
27819
|
-
countsStmt;
|
|
27820
|
-
fingerprintStmt;
|
|
27821
|
-
setFingerprintStmt;
|
|
27822
|
-
rearmStmt;
|
|
27823
|
-
claimStmt;
|
|
27824
|
-
heartbeatStmt;
|
|
27825
|
-
releaseStmt;
|
|
27826
|
-
leaseStmt;
|
|
27827
|
-
inspectionsStmt;
|
|
27828
|
-
closeWindowStmt;
|
|
27829
|
-
releaseBoundaryStmt;
|
|
27830
|
-
freezeBoundaryStmt;
|
|
27831
|
-
captureRowsStmt;
|
|
27832
|
-
markOwedStmt;
|
|
27833
|
-
captureSkipCountStmt;
|
|
27834
|
-
disownCapturesStmt;
|
|
27835
|
-
partitionStmt;
|
|
27836
|
-
claimRowStmt;
|
|
27837
|
-
releaseRowStmt;
|
|
27838
|
-
releaseStaleClaimsStmt;
|
|
27839
|
-
/**
|
|
27840
|
-
* The masked detections recorded against one tool call.
|
|
27841
|
-
*
|
|
27842
|
-
* These travel with the event because a tool call's target is not
|
|
27843
|
-
* re-inspectable from the event alone — unlike a capture, where the text
|
|
27844
|
-
* itself is re-scannable. What crosses is the masked match and the rule that
|
|
27845
|
-
* produced it, never the value.
|
|
27846
|
-
*/
|
|
27847
|
-
inspectionsFor(auditEventId) {
|
|
27848
|
-
return allRows(this.inspectionsStmt, { auditEventId });
|
|
27849
|
-
}
|
|
27850
|
-
/**
|
|
27851
|
-
* Sessions with structural rows still to send, oldest first.
|
|
27852
|
-
*
|
|
27853
|
-
* BOUNDED BY THE BACKLOG BOUNDARY, which is the whole correctness of this
|
|
27854
|
-
* read. Anything recorded after the machine attached is the live forward
|
|
27855
|
-
* path's to deliver; this drain exists for what was recorded before it, and a
|
|
27856
|
-
* row both paths send is at best a duplicate request and at worst — for a
|
|
27857
|
-
* session root — an overwrite of the inventory ids the live path resolved.
|
|
27858
|
-
*/
|
|
27859
|
-
pendingSessions(limit, before) {
|
|
27860
|
-
return allRows(this.sessionsStmt, { limit, before }).map(
|
|
27861
|
-
(r) => r.sessionId
|
|
27862
|
-
);
|
|
27863
|
-
}
|
|
27864
|
-
/** One session's undelivered structural rows within the backlog, root first. */
|
|
27865
|
-
pendingRows(sessionId, limit, before) {
|
|
27866
|
-
return allRows(this.rowsStmt, { sessionId, limit, before });
|
|
27867
|
-
}
|
|
27868
|
-
/**
|
|
27869
|
-
* Captures this machine still owes the deployment, oldest first.
|
|
27870
|
-
*
|
|
27871
|
-
* Selected by the `outbox_owed` marker the attached forward path writes, not
|
|
27872
|
-
* by a time window — see captureRowsStmt for why a window could not express
|
|
27873
|
-
* this. `before` is the grace window that leaves a just-recorded capture to
|
|
27874
|
-
* the live path.
|
|
27875
|
-
*/
|
|
27876
|
-
pendingCaptureRows(limit, before) {
|
|
27877
|
-
return allRows(this.captureRowsStmt, { limit, before });
|
|
27878
|
-
}
|
|
27879
|
-
/**
|
|
27880
|
-
* Record that a capture is OWED to the deployment.
|
|
27881
|
-
*
|
|
27882
|
-
* Written by the attached forward path when a live send did not confirm
|
|
27883
|
-
* delivery, and read by the drain as the whole of its eligibility test. It is
|
|
27884
|
-
* a fact rather than an inference: the machine was attached, the send did not
|
|
27885
|
-
* land, so the row is owed — which no time window can state, because the same
|
|
27886
|
-
* window that holds the rows a past attachment left owed also holds every
|
|
27887
|
-
* capture recorded while the machine was DETACHED, and those were never
|
|
27888
|
-
* offered to anyone.
|
|
27889
|
-
*
|
|
27890
|
-
* Idempotent, and never un-set: `markSynced` settling the row is what takes it
|
|
27891
|
-
* out of the drain's read.
|
|
27892
|
-
*/
|
|
27893
|
-
markCaptureOwed(id) {
|
|
27894
|
-
this.markOwedStmt.run({ id });
|
|
27895
|
-
}
|
|
27896
|
-
/** Record delivery. Called only AFTER the far side has accepted the rows. */
|
|
27897
|
-
markSynced(ids, atMs) {
|
|
27898
|
-
this.stampAll(ids, atMs);
|
|
27899
|
-
}
|
|
27900
|
-
/**
|
|
27901
|
-
* Record that a row will never be sent.
|
|
27902
|
-
*
|
|
27903
|
-
* Reserved for a local defect — a row that cannot be rebuilt into a valid
|
|
27904
|
-
* payload. A row that merely failed to reach the deployment stays NULL, so it
|
|
27905
|
-
* is retried; marking those would turn one outage into permanent data loss.
|
|
27906
|
-
*/
|
|
27907
|
-
markSkipped(ids) {
|
|
27908
|
-
this.stampAll(ids, SKIPPED);
|
|
27909
|
-
}
|
|
27910
|
-
eachInTransaction(ids, run) {
|
|
27911
|
-
if (ids.length === 0) return;
|
|
27912
|
-
withTransaction(
|
|
27913
|
-
this.db,
|
|
27914
|
-
() => {
|
|
27915
|
-
for (const id of ids) run(id);
|
|
27916
|
-
},
|
|
27917
|
-
"IMMEDIATE"
|
|
27918
|
-
);
|
|
27919
|
-
}
|
|
27920
|
-
stampAll(ids, value) {
|
|
27921
|
-
if (ids.length === 0) return;
|
|
27922
|
-
withTransaction(
|
|
27923
|
-
this.db,
|
|
27924
|
-
() => {
|
|
27925
|
-
for (const id of ids) this.stampStmt.run({ at: value, id });
|
|
27926
|
-
},
|
|
27927
|
-
"IMMEDIATE"
|
|
27928
|
-
);
|
|
27929
|
-
}
|
|
27930
|
-
/**
|
|
27931
|
-
* Claim rows as in-flight.
|
|
27932
|
-
*
|
|
27933
|
-
* Advisory in exactly the sense the lease is: it records that a send is in
|
|
27934
|
-
* progress so a surface can say so, and a lost claim costs a row showing as
|
|
27935
|
-
* queued while it is actually being sent. It is not exclusion — the far side
|
|
27936
|
-
* settles a duplicate on the row id.
|
|
27937
|
-
*/
|
|
27938
|
-
claimRows(ids, atMs) {
|
|
27939
|
-
this.eachInTransaction(ids, (id) => this.claimRowStmt.run({ at: atMs, id }));
|
|
27940
|
-
}
|
|
27941
|
-
/** Give back a claim without settling — the send failed, the row is queued again. */
|
|
27942
|
-
releaseRows(ids) {
|
|
27943
|
-
this.eachInTransaction(ids, (id) => this.releaseRowStmt.run({ id }));
|
|
27944
|
-
}
|
|
27945
|
-
/**
|
|
27946
|
-
* Clear claims older than `staleBefore`, and report how many were cleared.
|
|
27947
|
-
*
|
|
27948
|
-
* A process killed between claiming and settling leaves rows claimed with
|
|
27949
|
-
* nothing left to settle them. Without this they read as "sending" for ever.
|
|
27950
|
-
*/
|
|
27951
|
-
releaseStaleClaims(staleBefore) {
|
|
27952
|
-
return Number(this.releaseStaleClaimsStmt.run({ staleBefore }).changes);
|
|
27953
|
-
}
|
|
27954
|
-
/**
|
|
27955
|
-
* Every tracked row in exactly one delivery state.
|
|
27956
|
-
*
|
|
27957
|
-
* Takes no boundary on purpose. The boundary answers "what should the drain
|
|
27958
|
-
* pick up now", which is a different question from "what state is this row
|
|
27959
|
-
* in" — and a machine that has never attached has no boundary to pass, so
|
|
27960
|
-
* requiring one would force a caller to invent one and report the whole store
|
|
27961
|
-
* as queued.
|
|
27962
|
-
*/
|
|
27963
|
-
partition() {
|
|
27964
|
-
const row = getRow(this.partitionStmt, {});
|
|
27965
|
-
return {
|
|
27966
|
-
queued: row?.queued ?? 0,
|
|
27967
|
-
inProgress: row?.inProgress ?? 0,
|
|
27968
|
-
synced: row?.synced ?? 0,
|
|
27969
|
-
failed: row?.failed ?? 0,
|
|
27970
|
-
total: row?.total ?? 0
|
|
27971
|
-
};
|
|
27972
|
-
}
|
|
27973
|
-
/** `pending` counts only what is inside the backlog; sent and skipped are totals. */
|
|
27974
|
-
counts(before) {
|
|
27975
|
-
const row = getRow(
|
|
27976
|
-
this.countsStmt,
|
|
27977
|
-
{ before }
|
|
27978
|
-
);
|
|
27979
|
-
const captures = getRow(this.captureSkipCountStmt);
|
|
27980
|
-
return {
|
|
27981
|
-
pending: row?.pending ?? 0,
|
|
27982
|
-
sent: row?.sent ?? 0,
|
|
27983
|
-
skipped: row?.skipped ?? 0,
|
|
27984
|
-
capturesSkipped: captures?.skipped ?? 0
|
|
27985
|
-
};
|
|
27986
|
-
}
|
|
27987
|
-
/**
|
|
27988
|
-
* The deployment the current stamps were made against, and where its backlog
|
|
27989
|
-
* ends.
|
|
27990
|
-
*
|
|
27991
|
-
* READ-ONLY. An absent row reads as an absent deployment, which is what a
|
|
27992
|
-
* machine that has never drained is — and every writer below seeds the row
|
|
27993
|
-
* before it needs one, so nothing depends on this creating it. Keeping the
|
|
27994
|
-
* write off the gate path matters because the gate runs on every pass while a
|
|
27995
|
-
* write has to take the database's write lock.
|
|
27996
|
-
*/
|
|
27997
|
-
deployment() {
|
|
27998
|
-
const row = getRow(
|
|
27999
|
-
this.fingerprintStmt
|
|
28000
|
-
);
|
|
28001
|
-
return {
|
|
28002
|
-
fingerprint: row?.fingerprint ?? void 0,
|
|
28003
|
-
backlogBefore: row?.backlogBefore ?? void 0
|
|
28004
|
-
};
|
|
28005
|
-
}
|
|
28006
|
-
/**
|
|
28007
|
-
* Point the ledger at a different deployment, discarding what it recorded
|
|
28008
|
-
* about the previous one.
|
|
28009
|
-
*
|
|
28010
|
-
* Delivery is a fact about ONE recipient: rows sent to the deployment a
|
|
28011
|
-
* machine has just left are undelivered as far as the new one is concerned.
|
|
28012
|
-
* All three in one transaction, so a crash between them cannot leave stamps
|
|
28013
|
-
* attributed to the wrong deployment, or a boundary that belongs to another.
|
|
28014
|
-
*
|
|
28015
|
-
* The boundary is written HERE and only here, which is what freezes it: a
|
|
28016
|
-
* re-attach to the SAME deployment (a key rotation) leaves the fingerprint
|
|
28017
|
-
* unchanged, so this never runs and the backlog does not widen back over rows
|
|
28018
|
-
* the live path has since delivered.
|
|
28019
|
-
*/
|
|
28020
|
-
rearmFor(fingerprint, backlogBefore) {
|
|
28021
|
-
this.ensureRowStmt.run();
|
|
28022
|
-
withTransaction(
|
|
28023
|
-
this.db,
|
|
28024
|
-
() => {
|
|
28025
|
-
const previous = getRow(this.fingerprintStmt)?.fingerprint;
|
|
28026
|
-
this.rearmStmt.run();
|
|
28027
|
-
if (previous !== null && previous !== void 0 && previous !== fingerprint) {
|
|
28028
|
-
this.disownCapturesStmt.run();
|
|
28029
|
-
}
|
|
28030
|
-
this.setFingerprintStmt.run({ fingerprint, backlogBefore });
|
|
28031
|
-
},
|
|
28032
|
-
"IMMEDIATE"
|
|
28033
|
-
);
|
|
28034
|
-
}
|
|
28035
|
-
/**
|
|
28036
|
-
* End the attached period: hand its rows to the live path, and release the
|
|
28037
|
-
* boundary so the next attachment can freeze a new one.
|
|
28038
|
-
*
|
|
28039
|
-
* WITHOUT THIS, a detach and a re-attach to the same deployment leave a window
|
|
28040
|
-
* nothing delivers. The fingerprint is unchanged, so the boundary is never
|
|
28041
|
-
* re-frozen and stays at the FIRST attachment — while nothing forwards at all
|
|
28042
|
-
* during the detached period, because the machine is not attached. Rows
|
|
28043
|
-
* recorded in that window sit after the boundary and before the re-attach, so
|
|
28044
|
-
* neither path takes them, and the pending count reports none outstanding.
|
|
28045
|
-
*
|
|
28046
|
-
* Stamping the attached window is not a claim that every one of those rows
|
|
28047
|
-
* reached the deployment — the live path drops on failure and says so
|
|
28048
|
-
* elsewhere. It records that they were ITS to deliver, which is exactly the
|
|
28049
|
-
* status quo: they sit outside the frozen boundary today and are equally never
|
|
28050
|
-
* re-sent. Making it explicit is what lets the boundary move.
|
|
28051
|
-
*
|
|
28052
|
-
* ONE TRANSACTION, so a crash cannot release the boundary while leaving the
|
|
28053
|
-
* window unstamped — that half-state would re-send the whole attached period
|
|
28054
|
-
* on the next attach, which is the failure the boundary exists to prevent.
|
|
28055
|
-
*/
|
|
28056
|
-
closeAttachedWindow(attachedAtMs, atMs) {
|
|
28057
|
-
this.ensureRowStmt.run();
|
|
28058
|
-
withTransaction(
|
|
28059
|
-
this.db,
|
|
28060
|
-
() => {
|
|
28061
|
-
const row = getRow(this.fingerprintStmt);
|
|
28062
|
-
const from = row?.backlogBefore ?? attachedAtMs;
|
|
28063
|
-
this.closeWindowStmt.run({ at: atMs, attachedAt: from });
|
|
28064
|
-
this.releaseBoundaryStmt.run();
|
|
28065
|
-
},
|
|
28066
|
-
"IMMEDIATE"
|
|
28067
|
-
);
|
|
28068
|
-
}
|
|
28069
|
-
/**
|
|
28070
|
-
* Freeze a boundary for the deployment already on file, KEEPING the stamps.
|
|
28071
|
-
*
|
|
28072
|
-
* The re-attach half of the above. Distinct from `rearmFor`, which is for a
|
|
28073
|
-
* different deployment and therefore discards what was delivered to the old
|
|
28074
|
-
* one: here the recipient is the same, so everything already sent to it stays
|
|
28075
|
-
* sent.
|
|
28076
|
-
*/
|
|
28077
|
-
freezeBoundary(backlogBefore) {
|
|
28078
|
-
this.ensureRowStmt.run();
|
|
28079
|
-
this.freezeBoundaryStmt.run({ backlogBefore });
|
|
28080
|
-
}
|
|
28081
|
-
/** Take the claim, or report that someone live already holds it. */
|
|
28082
|
-
claim(pid, host, nowMs, staleAfterMs) {
|
|
28083
|
-
this.ensureRowStmt.run();
|
|
28084
|
-
let taken = false;
|
|
28085
|
-
withTransaction(
|
|
28086
|
-
this.db,
|
|
28087
|
-
() => {
|
|
28088
|
-
const result = this.claimStmt.run({
|
|
28089
|
-
pid,
|
|
28090
|
-
host,
|
|
28091
|
-
now: nowMs,
|
|
28092
|
-
staleBefore: nowMs - staleAfterMs
|
|
28093
|
-
});
|
|
28094
|
-
taken = result.changes === 1;
|
|
28095
|
-
},
|
|
28096
|
-
"IMMEDIATE"
|
|
28097
|
-
);
|
|
28098
|
-
return taken;
|
|
28099
|
-
}
|
|
28100
|
-
/** Say the holder is still alive. A no-op once the claim has moved on. */
|
|
28101
|
-
heartbeat(pid, nowMs) {
|
|
28102
|
-
this.heartbeatStmt.run({ now: nowMs, pid });
|
|
28103
|
-
}
|
|
28104
|
-
/** Give the claim up. Scoped to this holder, so a taken-over claim is left be. */
|
|
28105
|
-
release(pid) {
|
|
28106
|
-
this.releaseStmt.run({ pid });
|
|
28107
|
-
}
|
|
28108
|
-
/** Who holds the claim, if anyone. Read-only, for the same reason as above. */
|
|
28109
|
-
lease() {
|
|
28110
|
-
return getRow(this.leaseStmt);
|
|
28111
|
-
}
|
|
28112
|
-
};
|
|
28113
|
-
|
|
28114
28826
|
// ../../packages/persistence/src/repositories/inspection-definitions.ts
|
|
28115
28827
|
var SqliteInspectionDefinitionsRepository = class {
|
|
28116
28828
|
constructor(db) {
|
|
@@ -28302,7 +29014,8 @@ function managedSettingsPaths(platform2 = process.platform) {
|
|
|
28302
29014
|
}
|
|
28303
29015
|
return [posix.join("/etc", "aka", MANAGED_SETTINGS_FILENAME)];
|
|
28304
29016
|
}
|
|
28305
|
-
|
|
29017
|
+
var testOnlyManagedPaths = null;
|
|
29018
|
+
function readManagedSettings(paths = testOnlyManagedPaths ?? managedSettingsPaths()) {
|
|
28306
29019
|
for (const path of paths) {
|
|
28307
29020
|
let text;
|
|
28308
29021
|
try {
|
|
@@ -28337,6 +29050,7 @@ function overlayManagedSettings(settings, managed, now = () => /* @__PURE__ */ n
|
|
|
28337
29050
|
if (values.vaultInlineReveal !== void 0) merged.vaultInlineReveal = values.vaultInlineReveal;
|
|
28338
29051
|
if (values.dataSharesInPlace !== void 0) merged.dataSharesInPlace = values.dataSharesInPlace;
|
|
28339
29052
|
if (values.redactFallback !== void 0) merged.redactFallback = values.redactFallback;
|
|
29053
|
+
if (values.bodyRetention !== void 0) merged.bodyRetention = values.bodyRetention;
|
|
28340
29054
|
if (values.vaultConsent !== void 0) {
|
|
28341
29055
|
merged.vaultConsent = values.vaultConsent ? (
|
|
28342
29056
|
// Keep an existing valid grant so its acknowledgedAt survives; mint one
|
|
@@ -30782,7 +31496,7 @@ function toUtcDateString(ms) {
|
|
|
30782
31496
|
return new Date(ms).toISOString().slice(0, 10);
|
|
30783
31497
|
}
|
|
30784
31498
|
function isTimeseriesSeverity(s) {
|
|
30785
|
-
return s === "critical" || s === "high" || s === "medium";
|
|
31499
|
+
return s === "critical" || s === "high" || s === "medium" || s === "low";
|
|
30786
31500
|
}
|
|
30787
31501
|
var SqliteSecurityRepository = class {
|
|
30788
31502
|
constructor(db, now = () => Date.now()) {
|
|
@@ -30844,7 +31558,7 @@ var SqliteSecurityRepository = class {
|
|
|
30844
31558
|
ELSE 0
|
|
30845
31559
|
END) AS open_at_rest
|
|
30846
31560
|
FROM inspection_findings f
|
|
30847
|
-
JOIN audit_events e ON e.id = f.audit_event_id
|
|
31561
|
+
JOIN audit_events e INDEXED BY idx_audit_capture_rollup ON e.id = f.audit_event_id
|
|
30848
31562
|
JOIN inspection_definitions d ON d.id = f.inspection_definition_id
|
|
30849
31563
|
LEFT JOIN ${LATEST_RESOLUTION_BY_KEY_SQL} latest
|
|
30850
31564
|
ON latest.finding_key = f.finding_key
|
|
@@ -30911,12 +31625,16 @@ var SqliteSecurityRepository = class {
|
|
|
30911
31625
|
const now = this.now();
|
|
30912
31626
|
const windowStart = startOfUtcDay2(now) - (lenDays - 1) * DAY_MS4;
|
|
30913
31627
|
const rows = this.findingsInRange(windowStart, now);
|
|
30914
|
-
const points = Array.from(
|
|
30915
|
-
|
|
30916
|
-
|
|
30917
|
-
|
|
30918
|
-
|
|
30919
|
-
|
|
31628
|
+
const points = Array.from(
|
|
31629
|
+
{ length: numBuckets },
|
|
31630
|
+
(_, i) => ({
|
|
31631
|
+
timestamp: toUtcDateString(windowStart + i * bucketMs),
|
|
31632
|
+
critical: 0,
|
|
31633
|
+
high: 0,
|
|
31634
|
+
medium: 0,
|
|
31635
|
+
low: 0
|
|
31636
|
+
})
|
|
31637
|
+
);
|
|
30920
31638
|
for (const r of rows) {
|
|
30921
31639
|
const idx = Math.floor((r.occurredAt - windowStart) / bucketMs);
|
|
30922
31640
|
const bucket = points[idx];
|
|
@@ -31066,7 +31784,7 @@ var SqliteSecurityRepository = class {
|
|
|
31066
31784
|
this.db.prepare(
|
|
31067
31785
|
`SELECT e.repo AS repo, count(*) AS c
|
|
31068
31786
|
FROM inspection_findings f
|
|
31069
|
-
JOIN audit_events e ON e.id = f.audit_event_id
|
|
31787
|
+
JOIN audit_events e INDEXED BY idx_audit_capture_rollup ON e.id = f.audit_event_id
|
|
31070
31788
|
WHERE e.started_at >= :from AND e.started_at < :to
|
|
31071
31789
|
AND e.event_type IN (${CAPTURE_EVENT_TYPES_SQL})
|
|
31072
31790
|
AND e.repo IS NOT NULL
|
|
@@ -31134,6 +31852,7 @@ var SqliteSecurityRepository = class {
|
|
|
31134
31852
|
`SELECT f.finding_key AS finding_key,
|
|
31135
31853
|
d.rule_id AS rule_id,
|
|
31136
31854
|
d.severity AS severity,
|
|
31855
|
+
e.repo AS repo,
|
|
31137
31856
|
e.file_path AS path,
|
|
31138
31857
|
COALESCE(f.first_detected_at, e.started_at) AS first_detected_at,
|
|
31139
31858
|
latest.resolved_at AS latest_resolved_at
|
|
@@ -31153,6 +31872,7 @@ var SqliteSecurityRepository = class {
|
|
|
31153
31872
|
const items = rows.map((r) => ({
|
|
31154
31873
|
findingKey: r.finding_key,
|
|
31155
31874
|
ruleId: r.rule_id,
|
|
31875
|
+
repo: r.repo ?? "",
|
|
31156
31876
|
severity: r.severity,
|
|
31157
31877
|
path: r.path ?? "",
|
|
31158
31878
|
resolvedAt: new Date(r.latest_resolved_at).toISOString(),
|
|
@@ -31162,15 +31882,68 @@ var SqliteSecurityRepository = class {
|
|
|
31162
31882
|
}));
|
|
31163
31883
|
return Promise.resolve({ items });
|
|
31164
31884
|
}
|
|
31885
|
+
/**
|
|
31886
|
+
* Per-rule tallies of the findings that are still OPEN, whole-store.
|
|
31887
|
+
*
|
|
31888
|
+
* Scoped by status rather than by time, because the card this feeds is a to-do
|
|
31889
|
+
* list: a secret committed three weeks ago and never rotated is still the most
|
|
31890
|
+
* important thing to fix, and any window hides it. It carried a "newest N
|
|
31891
|
+
* findings" cap and then a range; the first meant a different span on every
|
|
31892
|
+
* machine, and the second reported "no recommendations" over live exposure.
|
|
31893
|
+
*
|
|
31894
|
+
* `open` mirrors `deriveFindingStatus` — at-rest, minus resolved and dismissed —
|
|
31895
|
+
* so a row's count is exactly what `?status=open&type=<rule>` returns. Note that
|
|
31896
|
+
* is NOT `severitySummary`'s `openAtRest`, which keeps dismissed findings (a
|
|
31897
|
+
* dismissal is a judgement, not a remediation) and drops untracked legacy rows.
|
|
31898
|
+
* The two answer different questions and only this one has to match a link.
|
|
31899
|
+
*
|
|
31900
|
+
* Aggregated in SQL: the result is O(distinct rule × category × severity), so a
|
|
31901
|
+
* whole-store scope costs a grouped scan rather than a row per finding.
|
|
31902
|
+
*/
|
|
31903
|
+
recommendationInputs() {
|
|
31904
|
+
const rows = allRows(
|
|
31905
|
+
this.db.prepare(
|
|
31906
|
+
`SELECT d.rule_id AS rule_id,
|
|
31907
|
+
d.category AS category,
|
|
31908
|
+
d.severity AS severity,
|
|
31909
|
+
COUNT(*) AS count
|
|
31910
|
+
FROM inspection_findings f
|
|
31911
|
+
JOIN audit_events e INDEXED BY idx_audit_capture_rollup ON e.id = f.audit_event_id
|
|
31912
|
+
JOIN inspection_definitions d ON d.id = f.inspection_definition_id
|
|
31913
|
+
LEFT JOIN ${LATEST_RESOLUTION_BY_KEY_SQL} latest
|
|
31914
|
+
ON latest.finding_key = f.finding_key
|
|
31915
|
+
WHERE e.event_type IN (${CAPTURE_EVENT_TYPES_SQL})
|
|
31916
|
+
AND e.event_type = 'code_change'
|
|
31917
|
+
AND (
|
|
31918
|
+
f.finding_key IS NULL
|
|
31919
|
+
OR latest.status IS NULL
|
|
31920
|
+
OR latest.status NOT IN ('resolved', 'dismissed')
|
|
31921
|
+
)
|
|
31922
|
+
GROUP BY d.rule_id, d.category, d.severity`
|
|
31923
|
+
)
|
|
31924
|
+
);
|
|
31925
|
+
return Promise.resolve(
|
|
31926
|
+
rows.map((r) => ({
|
|
31927
|
+
ruleId: r.rule_id,
|
|
31928
|
+
category: r.category,
|
|
31929
|
+
severity: r.severity,
|
|
31930
|
+
count: r.count
|
|
31931
|
+
}))
|
|
31932
|
+
);
|
|
31933
|
+
}
|
|
31165
31934
|
// Findings whose parent event occurred in [fromMs, toMs), with the parent's
|
|
31166
31935
|
// epoch-millis timestamp. started_at is an INTEGER column, so the bounds stay
|
|
31167
31936
|
// numeric and the JS aggregations bucket/split on ms directly.
|
|
31168
31937
|
findingsInRange(fromMs, toMs) {
|
|
31169
31938
|
const rows = allRows(
|
|
31170
31939
|
this.db.prepare(
|
|
31171
|
-
`
|
|
31940
|
+
// `rule_id`/`category` cost nothing extra: inspection_definitions is already
|
|
31941
|
+
// joined for `severity`, so they are two more columns off a row this read
|
|
31942
|
+
// already fetches. They feed the recommended-actions rollup.
|
|
31943
|
+
`SELECT e.started_at AS occurred_at, d.severity AS severity, f.action_taken AS action_taken,
|
|
31944
|
+
d.rule_id AS rule_id, d.category AS category
|
|
31172
31945
|
FROM inspection_findings f
|
|
31173
|
-
JOIN audit_events e ON e.id = f.audit_event_id
|
|
31946
|
+
JOIN audit_events e INDEXED BY idx_audit_capture_rollup ON e.id = f.audit_event_id
|
|
31174
31947
|
JOIN inspection_definitions d ON d.id = f.inspection_definition_id
|
|
31175
31948
|
WHERE e.started_at >= :from AND e.started_at < :to
|
|
31176
31949
|
AND e.event_type IN (${CAPTURE_EVENT_TYPES_SQL})
|
|
@@ -31181,7 +31954,9 @@ var SqliteSecurityRepository = class {
|
|
|
31181
31954
|
return rows.map((r) => ({
|
|
31182
31955
|
occurredAt: r.occurred_at,
|
|
31183
31956
|
severity: r.severity,
|
|
31184
|
-
actionTaken: r.action_taken
|
|
31957
|
+
actionTaken: r.action_taken,
|
|
31958
|
+
ruleId: r.rule_id,
|
|
31959
|
+
category: r.category
|
|
31185
31960
|
}));
|
|
31186
31961
|
}
|
|
31187
31962
|
};
|
|
@@ -32009,6 +32784,7 @@ function openWithPragmas(file2) {
|
|
|
32009
32784
|
db.exec("PRAGMA journal_mode = WAL");
|
|
32010
32785
|
db.exec("PRAGMA busy_timeout = 2000");
|
|
32011
32786
|
db.exec("PRAGMA foreign_keys = ON");
|
|
32787
|
+
registerSqlFunctions(db);
|
|
32012
32788
|
} catch (err) {
|
|
32013
32789
|
closeQuietly(db);
|
|
32014
32790
|
throw err;
|
|
@@ -32038,7 +32814,7 @@ function backupLegacyStore(db, file2) {
|
|
|
32038
32814
|
discardStore(file2, backup);
|
|
32039
32815
|
return backup;
|
|
32040
32816
|
}
|
|
32041
|
-
function openAndInitialize(file2, base) {
|
|
32817
|
+
function openAndInitialize(file2, base, skipTags) {
|
|
32042
32818
|
let db = openWithPragmas(file2);
|
|
32043
32819
|
try {
|
|
32044
32820
|
if (isForeignSqliteLineage(db)) {
|
|
@@ -32048,7 +32824,7 @@ function openAndInitialize(file2, base) {
|
|
|
32048
32824
|
`Detected an older, incompatible (tenant-bearing) ${DB_FILENAME}; backed it up to ${backup} and created a fresh store.`
|
|
32049
32825
|
);
|
|
32050
32826
|
}
|
|
32051
|
-
applyMigrations(db, file2);
|
|
32827
|
+
applyMigrations(db, file2, { skipTags });
|
|
32052
32828
|
tightenPerms(file2);
|
|
32053
32829
|
const policies = new SqlitePoliciesRepository(db);
|
|
32054
32830
|
const installedPacks = new SqliteInstalledPacksRepository(db, base);
|
|
@@ -32063,6 +32839,7 @@ function openAndInitialize(file2, base) {
|
|
|
32063
32839
|
exceptions: new SqliteExceptionsRepository(db),
|
|
32064
32840
|
resolutions: new SqliteResolutionsRepository(db),
|
|
32065
32841
|
ruleProbeCache: new SqliteRuleProbeCacheRepository(db),
|
|
32842
|
+
bodyRetention: new SqliteBodyRetentionRepository(db),
|
|
32066
32843
|
security: new SqliteSecurityRepository(db),
|
|
32067
32844
|
detections: new SqliteDetectionsRepository(db),
|
|
32068
32845
|
shares: new SqliteSharesRepository(db),
|
|
@@ -32085,7 +32862,8 @@ function openAndInitialize(file2, base) {
|
|
|
32085
32862
|
throw err;
|
|
32086
32863
|
}
|
|
32087
32864
|
}
|
|
32088
|
-
|
|
32865
|
+
var DEFERRED_TAGS = new Set(DEFERRED_MIGRATION_TAGS);
|
|
32866
|
+
function openLocalDatabase(dir, options = {}) {
|
|
32089
32867
|
ensureDataDirSync(dir);
|
|
32090
32868
|
const file2 = join7(dir, DB_FILENAME);
|
|
32091
32869
|
reapStalePartials(file2);
|
|
@@ -32097,6 +32875,7 @@ function openLocalDatabase(dir) {
|
|
|
32097
32875
|
installedPacks,
|
|
32098
32876
|
scanLedger,
|
|
32099
32877
|
historySync,
|
|
32878
|
+
bodyRetention,
|
|
32100
32879
|
secretVault,
|
|
32101
32880
|
exceptions,
|
|
32102
32881
|
resolutions,
|
|
@@ -32120,7 +32899,8 @@ function openLocalDatabase(dir) {
|
|
|
32120
32899
|
// `dir` is always `<base>/data` — every caller resolves it through
|
|
32121
32900
|
// `dataDir()` — so its parent is the `~/.aka` base the layout splits into
|
|
32122
32901
|
// settings/ and data/, and the pack-policy floor needs both halves.
|
|
32123
|
-
dirname2(dir)
|
|
32902
|
+
dirname2(dir),
|
|
32903
|
+
options.applyDeferredMigrations === true ? void 0 : DEFERRED_TAGS
|
|
32124
32904
|
);
|
|
32125
32905
|
function captureRowId(event) {
|
|
32126
32906
|
return captureId(
|
|
@@ -32313,6 +33093,7 @@ function openLocalDatabase(dir) {
|
|
|
32313
33093
|
installedPacks,
|
|
32314
33094
|
scanLedger,
|
|
32315
33095
|
historySync,
|
|
33096
|
+
bodyRetention,
|
|
32316
33097
|
secretVault,
|
|
32317
33098
|
exceptions,
|
|
32318
33099
|
resolutions,
|
|
@@ -32351,14 +33132,78 @@ function openLocalDatabase(dir) {
|
|
|
32351
33132
|
};
|
|
32352
33133
|
}
|
|
32353
33134
|
|
|
32354
|
-
// ../../packages/persistence/src/
|
|
33135
|
+
// ../../packages/persistence/src/egress-wire.ts
|
|
32355
33136
|
import { createHash as createHash3 } from "crypto";
|
|
33137
|
+
var PROJECT_KEY_DIGEST_VERSION = "v2";
|
|
33138
|
+
var SCP_FORM = /^(?:[^@/]+@)?([^/:]+):(.+)$/;
|
|
33139
|
+
var DOS_DRIVE = /^[A-Za-z]:[\\/]/;
|
|
33140
|
+
var FILE_URL = /^file:\/\//i;
|
|
33141
|
+
var SCHEME_FORM = /^[a-z][a-z0-9+.-]*:\/\/(?:[^@/]+@)?([^/:]+)(?::\d+)?(\/.*)?$/i;
|
|
33142
|
+
var SLASH = "/".charCodeAt(0);
|
|
33143
|
+
var GIT_SUFFIX = ".git";
|
|
33144
|
+
function trimSlashes(path) {
|
|
33145
|
+
let start = 0;
|
|
33146
|
+
let end = path.length;
|
|
33147
|
+
while (start < end && path.charCodeAt(start) === SLASH) start += 1;
|
|
33148
|
+
while (end > start && path.charCodeAt(end - 1) === SLASH) end -= 1;
|
|
33149
|
+
return path.slice(start, end);
|
|
33150
|
+
}
|
|
33151
|
+
function canonicalGitUrl(url2) {
|
|
33152
|
+
const trimmed = url2.trim();
|
|
33153
|
+
if (DOS_DRIVE.test(trimmed) || FILE_URL.test(trimmed)) return trimmed;
|
|
33154
|
+
const scheme = SCHEME_FORM.exec(trimmed);
|
|
33155
|
+
const scp = scheme === null ? SCP_FORM.exec(trimmed) : null;
|
|
33156
|
+
const host = (scheme?.[1] ?? scp?.[1])?.toLowerCase();
|
|
33157
|
+
if (host === void 0) return trimmed;
|
|
33158
|
+
const path = (scheme === null ? scp?.[2] : scheme[2]) ?? "";
|
|
33159
|
+
const bare = trimSlashes(path);
|
|
33160
|
+
const cleaned = bare.endsWith(GIT_SUFFIX) ? bare.slice(0, -GIT_SUFFIX.length) : bare;
|
|
33161
|
+
return cleaned === "" ? host : `${host}/${cleaned}`;
|
|
33162
|
+
}
|
|
33163
|
+
function hashProjectKey(projectKey) {
|
|
33164
|
+
const canonical = projectKey.startsWith("git:") ? `git:${canonicalGitUrl(projectKey.slice("git:".length))}` : projectKey;
|
|
33165
|
+
return createHash3("sha256").update(`${PROJECT_KEY_DIGEST_VERSION}:${canonical}`, "utf8").digest("hex");
|
|
33166
|
+
}
|
|
33167
|
+
function toIngestHit(hit) {
|
|
33168
|
+
return {
|
|
33169
|
+
host: hit.host,
|
|
33170
|
+
kind: hit.kind,
|
|
33171
|
+
name: hit.name,
|
|
33172
|
+
category: hit.category,
|
|
33173
|
+
trust: hit.trust,
|
|
33174
|
+
network: hit.network,
|
|
33175
|
+
method: hit.method,
|
|
33176
|
+
transport: hit.transport,
|
|
33177
|
+
url: hit.url,
|
|
33178
|
+
template: hit.template,
|
|
33179
|
+
dataClass: hit.dataClass,
|
|
33180
|
+
site: {
|
|
33181
|
+
file: hit.site.file,
|
|
33182
|
+
line: hit.site.line,
|
|
33183
|
+
dynamic: hit.site.dynamic,
|
|
33184
|
+
vendored: hit.site.vendored
|
|
33185
|
+
}
|
|
33186
|
+
};
|
|
33187
|
+
}
|
|
33188
|
+
function toEgressIngestRequest(input2) {
|
|
33189
|
+
const { hits, droppedFiles } = capHits(input2.hits, input2.reconcile.mode);
|
|
33190
|
+
const reconcile = withoutDroppedFiles(input2.reconcile, droppedFiles);
|
|
33191
|
+
return {
|
|
33192
|
+
projectKey: hashProjectKey(input2.projectKey),
|
|
33193
|
+
project: input2.project,
|
|
33194
|
+
reconcile,
|
|
33195
|
+
hits: hits.map(toIngestHit)
|
|
33196
|
+
};
|
|
33197
|
+
}
|
|
33198
|
+
|
|
33199
|
+
// ../../packages/persistence/src/finding-key.ts
|
|
33200
|
+
import { createHash as createHash4 } from "crypto";
|
|
32356
33201
|
function normalizeFilePath(filePath) {
|
|
32357
33202
|
return filePath.replaceAll("\\", "/");
|
|
32358
33203
|
}
|
|
32359
33204
|
function computeFindingKey(input2) {
|
|
32360
33205
|
const normalizedPath = normalizeFilePath(input2.filePath);
|
|
32361
|
-
return
|
|
33206
|
+
return createHash4("sha256").update(`${input2.ruleId}\0${normalizedPath}\0${input2.valueFingerprint}`).digest("hex");
|
|
32362
33207
|
}
|
|
32363
33208
|
|
|
32364
33209
|
// ../../packages/persistence/src/fingerprint.ts
|
|
@@ -32484,14 +33329,50 @@ function fingerprintValue(key, raw) {
|
|
|
32484
33329
|
return createHmac("sha256", key.material).update(raw, "utf8").digest("hex");
|
|
32485
33330
|
}
|
|
32486
33331
|
|
|
32487
|
-
// ../../packages/persistence/src/
|
|
32488
|
-
import {
|
|
33332
|
+
// ../../packages/persistence/src/forward-health.ts
|
|
33333
|
+
import { readFileSync as readFileSync7 } from "fs";
|
|
32489
33334
|
import { join as join9 } from "path";
|
|
33335
|
+
var FAILURES = /* @__PURE__ */ new Set([
|
|
33336
|
+
"unauthorized",
|
|
33337
|
+
"forbidden",
|
|
33338
|
+
"unreachable"
|
|
33339
|
+
]);
|
|
33340
|
+
var BREAKER_COOLDOWN_MS = 3e4;
|
|
33341
|
+
function parseForwardHealth(raw, nowMs) {
|
|
33342
|
+
try {
|
|
33343
|
+
const parsed2 = JSON.parse(raw);
|
|
33344
|
+
if (typeof parsed2 !== "object" || parsed2 === null) return null;
|
|
33345
|
+
const record2 = parsed2;
|
|
33346
|
+
const failures = typeof record2.consecutiveFailures === "number" && record2.consecutiveFailures >= 0 ? record2.consecutiveFailures : 0;
|
|
33347
|
+
const openedAtMs = typeof record2.openedAtMs === "number" && Number.isFinite(record2.openedAtMs) && record2.openedAtMs <= nowMs ? record2.openedAtMs : null;
|
|
33348
|
+
const lastFailure = typeof record2.lastFailure === "string" && FAILURES.has(record2.lastFailure) ? record2.lastFailure : null;
|
|
33349
|
+
return { consecutiveFailures: failures, openedAtMs, lastFailure };
|
|
33350
|
+
} catch {
|
|
33351
|
+
return null;
|
|
33352
|
+
}
|
|
33353
|
+
}
|
|
33354
|
+
function isForwardPaused(health, nowMs) {
|
|
33355
|
+
const openedAtMs = health?.openedAtMs ?? null;
|
|
33356
|
+
if (openedAtMs === null) return false;
|
|
33357
|
+
return nowMs - openedAtMs < BREAKER_COOLDOWN_MS;
|
|
33358
|
+
}
|
|
33359
|
+
|
|
33360
|
+
// ../../packages/persistence/src/history-backfill.ts
|
|
33361
|
+
import { existsSync as existsSync4 } from "fs";
|
|
33362
|
+
import { join as join10 } from "path";
|
|
33363
|
+
|
|
33364
|
+
// ../../packages/persistence/src/history-preview.ts
|
|
33365
|
+
import { existsSync as existsSync5 } from "fs";
|
|
33366
|
+
import { join as join11 } from "path";
|
|
32490
33367
|
import { DatabaseSync as DatabaseSync3 } from "node:sqlite";
|
|
32491
33368
|
|
|
33369
|
+
// ../../packages/persistence/src/history-sync-state.ts
|
|
33370
|
+
import { readFileSync as readFileSync8 } from "fs";
|
|
33371
|
+
import { join as join12 } from "path";
|
|
33372
|
+
|
|
32492
33373
|
// ../../packages/persistence/src/store-symlinks.ts
|
|
32493
|
-
import { existsSync as
|
|
32494
|
-
import { dirname as dirname3, join as
|
|
33374
|
+
import { existsSync as existsSync6, lstatSync as lstatSync3, readlinkSync, realpathSync, statSync as statSync4 } from "fs";
|
|
33375
|
+
import { dirname as dirname3, join as join13, resolve } from "path";
|
|
32495
33376
|
|
|
32496
33377
|
// ../../packages/persistence/src/vault/crypto.ts
|
|
32497
33378
|
import {
|
|
@@ -32505,20 +33386,20 @@ import {
|
|
|
32505
33386
|
// ../../packages/persistence/src/vault/key-provider.ts
|
|
32506
33387
|
import { execFileSync } from "child_process";
|
|
32507
33388
|
import { randomBytes as randomBytes2 } from "crypto";
|
|
32508
|
-
import { chmodSync as chmodSync3, readFileSync as
|
|
32509
|
-
import { join as
|
|
33389
|
+
import { chmodSync as chmodSync3, readFileSync as readFileSync9, renameSync as renameSync4, rmSync as rmSync6, statSync as statSync5, writeFileSync as writeFileSync3 } from "fs";
|
|
33390
|
+
import { join as join14 } from "path";
|
|
32510
33391
|
|
|
32511
33392
|
// ../../packages/persistence/src/vault/vault.ts
|
|
32512
33393
|
import { randomBytes as randomBytes3, randomUUID as randomUUID12 } from "crypto";
|
|
32513
33394
|
|
|
32514
33395
|
// ../../packages/persistence/src/warn-era-cap.ts
|
|
32515
|
-
import { existsSync as
|
|
32516
|
-
import { join as
|
|
33396
|
+
import { existsSync as existsSync7, writeFileSync as writeFileSync4 } from "fs";
|
|
33397
|
+
import { join as join15 } from "path";
|
|
32517
33398
|
var MARKER = "warn-era-capped";
|
|
32518
33399
|
function capWarnEraEnforcementOnce(db, policyMode, dataDir2) {
|
|
32519
33400
|
if (policyMode !== "warn") return { capped: 0, skipped: "not-warn" };
|
|
32520
|
-
const marker =
|
|
32521
|
-
if (
|
|
33401
|
+
const marker = join15(dataDir2, MARKER);
|
|
33402
|
+
if (existsSync7(marker)) return { capped: 0, skipped: "already-run" };
|
|
32522
33403
|
const capped = db.policies.capCategoryActions();
|
|
32523
33404
|
writeFileSync4(marker, `${new Date(Date.now()).toISOString()}
|
|
32524
33405
|
`, { mode: DATA_FILE_MODE });
|
|
@@ -32577,8 +33458,8 @@ function resolveProvider() {
|
|
|
32577
33458
|
function loadConfig(base = defaultDataDir(), resolveProviderFn = resolveProvider) {
|
|
32578
33459
|
try {
|
|
32579
33460
|
ensureLayoutDirSync(base);
|
|
32580
|
-
const settingsFile =
|
|
32581
|
-
if (
|
|
33461
|
+
const settingsFile = join16(settingsDir(base), "settings.json");
|
|
33462
|
+
if (existsSync8(settingsFile)) tightenFile(settingsFile);
|
|
32582
33463
|
} catch {
|
|
32583
33464
|
}
|
|
32584
33465
|
migrateLegacyLayout(base);
|
|
@@ -32601,9 +33482,9 @@ function resolveProviderSafe(resolveProviderFn) {
|
|
|
32601
33482
|
}
|
|
32602
33483
|
|
|
32603
33484
|
// ../../packages/plugin-sdk/src/config-inventory.ts
|
|
32604
|
-
import { readdirSync as readdirSync2, readFileSync as
|
|
33485
|
+
import { readdirSync as readdirSync2, readFileSync as readFileSync11, realpathSync as realpathSync2, statSync as statSync7 } from "fs";
|
|
32605
33486
|
import { homedir as homedir2 } from "os";
|
|
32606
|
-
import { basename as basename3, join as
|
|
33487
|
+
import { basename as basename3, join as join18 } from "path";
|
|
32607
33488
|
|
|
32608
33489
|
// ../../packages/detections/src/egress/registry.ts
|
|
32609
33490
|
var EXTRACTOR_VERSION = "1";
|
|
@@ -33296,12 +34177,18 @@ var EGRESS_CODE_EXTENSIONS = /* @__PURE__ */ new Set([
|
|
|
33296
34177
|
".rs"
|
|
33297
34178
|
]);
|
|
33298
34179
|
var SNIPPET_MAX = 200;
|
|
34180
|
+
var WHITESPACE = /\s/;
|
|
33299
34181
|
var MASK = "\u2022\u2022\u2022\u2022";
|
|
33300
34182
|
var URL_CANDIDATE = /(https?|wss?|sftp|grpcs?|smtp):\/\/(?:[^\s'"`<>()[\]{},;]|\$\{[^}\s]{1,64}\}|\{[A-Za-z_]\w{0,63}\}|%[sd])+/gi;
|
|
33301
34183
|
var PLACEHOLDER = /\$\{[^}\s]{1,64}\}|\{[A-Za-z_]\w{0,63}\}|%[sd]/g;
|
|
33302
34184
|
var VAR_TOKEN = "${var}";
|
|
33303
34185
|
var VAR_SENTINEL = "akaegressvar0";
|
|
33304
|
-
var TRAILING_PUNCTUATION =
|
|
34186
|
+
var TRAILING_PUNCTUATION = `.,;:'"`;
|
|
34187
|
+
function stripTrailingPunctuation(value) {
|
|
34188
|
+
let end = value.length;
|
|
34189
|
+
while (end > 0 && TRAILING_PUNCTUATION.includes(value.charAt(end - 1))) end -= 1;
|
|
34190
|
+
return end === value.length ? value : value.slice(0, end);
|
|
34191
|
+
}
|
|
33305
34192
|
var TRANSPORT_BY_SCHEME = {
|
|
33306
34193
|
http: "http",
|
|
33307
34194
|
https: "https",
|
|
@@ -33366,35 +34253,100 @@ var VENDORED_PATH = /(^|\/)(vendor|third_party|external)\//;
|
|
|
33366
34253
|
function isVendoredPath(file2) {
|
|
33367
34254
|
return VENDORED_PATH.test(file2);
|
|
33368
34255
|
}
|
|
33369
|
-
|
|
33370
|
-
|
|
34256
|
+
var REDACTION_PASSES = [
|
|
34257
|
+
{ pattern: USERINFO, replace: () => "://" },
|
|
34258
|
+
{ pattern: WEBHOOK_URL, replace: (m) => `${m[1] ?? ""}${MASK}` },
|
|
34259
|
+
{ pattern: SECRET_VALUE, replace: (m) => `${m[1] ?? ""}${MASK}` },
|
|
34260
|
+
{ pattern: AUTH_SCHEME_VALUE, replace: (m) => `${m[1] ?? ""}${m[2] ?? ""} ${MASK}` },
|
|
34261
|
+
{ pattern: BEARER_TOKEN, replace: () => `Bearer ${MASK}` }
|
|
34262
|
+
];
|
|
34263
|
+
function runPass(input2, pass) {
|
|
34264
|
+
const at = [];
|
|
34265
|
+
const end = [];
|
|
34266
|
+
const before = [];
|
|
34267
|
+
const after = [];
|
|
34268
|
+
let output2 = "";
|
|
34269
|
+
let copied = 0;
|
|
34270
|
+
let shift = 0;
|
|
34271
|
+
for (const match of input2.matchAll(pass.pattern)) {
|
|
34272
|
+
const start = match.index;
|
|
34273
|
+
const matched = match[0];
|
|
34274
|
+
const replacement = pass.replace(match);
|
|
34275
|
+
output2 += input2.slice(copied, start) + replacement;
|
|
34276
|
+
at.push(start);
|
|
34277
|
+
end.push(start + matched.length);
|
|
34278
|
+
before.push(shift);
|
|
34279
|
+
shift += replacement.length - matched.length;
|
|
34280
|
+
after.push(shift);
|
|
34281
|
+
copied = start + matched.length;
|
|
34282
|
+
}
|
|
34283
|
+
if (at.length === 0) return { output: input2, edits: { at, end, before, after } };
|
|
34284
|
+
return { output: output2 + input2.slice(copied), edits: { at, end, before, after } };
|
|
34285
|
+
}
|
|
34286
|
+
function throughPass(edits, offset) {
|
|
34287
|
+
let low = 0;
|
|
34288
|
+
let high = edits.at.length - 1;
|
|
34289
|
+
let found = -1;
|
|
34290
|
+
while (low <= high) {
|
|
34291
|
+
const mid = low + high >> 1;
|
|
34292
|
+
if ((edits.at[mid] ?? 0) <= offset) {
|
|
34293
|
+
found = mid;
|
|
34294
|
+
low = mid + 1;
|
|
34295
|
+
} else {
|
|
34296
|
+
high = mid - 1;
|
|
34297
|
+
}
|
|
34298
|
+
}
|
|
34299
|
+
if (found === -1) return offset;
|
|
34300
|
+
if (offset < (edits.end[found] ?? 0)) return (edits.at[found] ?? 0) + (edits.before[found] ?? 0);
|
|
34301
|
+
return offset + (edits.after[found] ?? 0);
|
|
33371
34302
|
}
|
|
33372
|
-
function
|
|
33373
|
-
const redacted = redactLine(line);
|
|
33374
|
-
if (redacted.length <= SNIPPET_MAX) return redacted;
|
|
33375
|
-
const lead = line.length - line.trimStart().length;
|
|
34303
|
+
function redactedLineOf(line) {
|
|
33376
34304
|
const trimmed = line.trim();
|
|
33377
|
-
const
|
|
34305
|
+
const edits = [];
|
|
34306
|
+
let text = trimmed;
|
|
34307
|
+
for (const pass of REDACTION_PASSES) {
|
|
34308
|
+
const result = runPass(text, pass);
|
|
34309
|
+
text = result.output;
|
|
34310
|
+
edits.push(result.edits);
|
|
34311
|
+
}
|
|
34312
|
+
if (text.length <= SNIPPET_MAX) return { redacted: text };
|
|
34313
|
+
return {
|
|
34314
|
+
redacted: text,
|
|
34315
|
+
window: { trimmed, edits, lead: line.length - line.trimStart().length }
|
|
34316
|
+
};
|
|
34317
|
+
}
|
|
34318
|
+
function snippetWindow({ redacted, window }, anchor2) {
|
|
34319
|
+
if (window === void 0) return redacted;
|
|
34320
|
+
const { trimmed, edits, lead } = window;
|
|
34321
|
+
let mapped = Math.max(0, anchor2 - lead);
|
|
34322
|
+
if (redacted.length !== trimmed.length) {
|
|
34323
|
+
while (mapped > 0 && WHITESPACE.test(trimmed.charAt(mapped - 1))) mapped -= 1;
|
|
34324
|
+
for (const pass of edits) mapped = throughPass(pass, mapped);
|
|
34325
|
+
}
|
|
33378
34326
|
const start = Math.min(
|
|
33379
34327
|
Math.max(0, mapped - Math.floor(SNIPPET_MAX / 2)),
|
|
33380
34328
|
redacted.length - SNIPPET_MAX
|
|
33381
34329
|
);
|
|
33382
34330
|
return redacted.slice(start, start + SNIPPET_MAX);
|
|
33383
34331
|
}
|
|
34332
|
+
function redactSnippet(line, anchor2 = 0) {
|
|
34333
|
+
return snippetWindow(redactedLineOf(line), anchor2);
|
|
34334
|
+
}
|
|
33384
34335
|
function extractEgress(text) {
|
|
33385
34336
|
const lineStarts = lineStartOffsets(text);
|
|
33386
34337
|
const urlSpans = [];
|
|
33387
34338
|
const hits = [];
|
|
33388
34339
|
const lineTextOf = memoizeByLine((index) => lineTextAt(text, lineStarts, index));
|
|
33389
34340
|
const ipContextOf = memoizeByLine((index) => ipLineContext(lineTextOf(index)));
|
|
33390
|
-
const
|
|
34341
|
+
const redactedOf = memoizeByLine((index) => redactedLineOf(lineTextOf(index)));
|
|
34342
|
+
const snippetAt = (index, offset) => snippetWindow(redactedOf(index), offset - (lineStarts[index] ?? 0));
|
|
33391
34343
|
for (const match of text.matchAll(URL_CANDIDATE)) {
|
|
33392
34344
|
const start = match.index;
|
|
33393
34345
|
const matched = match[0];
|
|
33394
34346
|
urlSpans.push([start, start + matched.length]);
|
|
33395
34347
|
const scheme = match[1];
|
|
33396
34348
|
if (scheme === void 0) continue;
|
|
33397
|
-
const candidate = matched
|
|
34349
|
+
const candidate = stripTrailingPunctuation(matched);
|
|
33398
34350
|
if (candidate === "") continue;
|
|
33399
34351
|
const parsed2 = parseCandidate(candidate, scheme);
|
|
33400
34352
|
if (parsed2 === null) continue;
|
|
@@ -33628,33 +34580,37 @@ function extractManifestSdks(text, kind) {
|
|
|
33628
34580
|
return [];
|
|
33629
34581
|
}
|
|
33630
34582
|
}
|
|
33631
|
-
function makeHit(ecosystem, pkg, line,
|
|
33632
|
-
return { ecosystem, pkg, line, snippet
|
|
34583
|
+
function makeHit(ecosystem, pkg, line, snippet) {
|
|
34584
|
+
return { ecosystem, pkg, line, snippet };
|
|
33633
34585
|
}
|
|
33634
34586
|
function extractPackageJson(text) {
|
|
33635
34587
|
const parsed2 = parseJson(text);
|
|
33636
34588
|
if (parsed2 === null) return [];
|
|
33637
34589
|
const seen = /* @__PURE__ */ new Set();
|
|
33638
34590
|
const hits = [];
|
|
34591
|
+
const lines = manifestLines(text);
|
|
34592
|
+
const tokens = quotedTokenOffsets(text);
|
|
34593
|
+
const dependenciesAt = sectionOffset(text, "dependencies");
|
|
34594
|
+
const optionalAt = sectionOffset(text, "optionalDependencies");
|
|
33639
34595
|
for (const pkg of objectKeys(parsed2.dependencies)) {
|
|
33640
34596
|
seen.add(pkg);
|
|
33641
|
-
hits.push(hitAtQuotedKey("npm", pkg, text,
|
|
34597
|
+
hits.push(hitAtQuotedKey("npm", pkg, text, dependenciesAt, lines, tokens));
|
|
33642
34598
|
}
|
|
33643
34599
|
for (const pkg of objectKeys(parsed2.optionalDependencies)) {
|
|
33644
34600
|
if (seen.has(pkg)) continue;
|
|
33645
34601
|
seen.add(pkg);
|
|
33646
|
-
hits.push(hitAtQuotedKey("npm", pkg, text,
|
|
34602
|
+
hits.push(hitAtQuotedKey("npm", pkg, text, optionalAt, lines, tokens));
|
|
33647
34603
|
}
|
|
33648
34604
|
return hits;
|
|
33649
34605
|
}
|
|
33650
34606
|
var REQUIREMENTS_NAME = /^\s*([A-Za-z0-9][\w.-]*)/;
|
|
33651
34607
|
function extractRequirementsTxt(text) {
|
|
33652
34608
|
const hits = [];
|
|
33653
|
-
eachLine(text, (rawLine, lineNumber) => {
|
|
34609
|
+
eachLine(text, (rawLine, lineNumber, snippet) => {
|
|
33654
34610
|
const match = REQUIREMENTS_NAME.exec(rawLine);
|
|
33655
34611
|
const name = match?.[1];
|
|
33656
34612
|
if (name === void 0) return;
|
|
33657
|
-
hits.push(makeHit("pypi", normalizePypi(name), lineNumber,
|
|
34613
|
+
hits.push(makeHit("pypi", normalizePypi(name), lineNumber, snippet()));
|
|
33658
34614
|
});
|
|
33659
34615
|
return hits;
|
|
33660
34616
|
}
|
|
@@ -33666,7 +34622,7 @@ function extractPyprojectToml(text) {
|
|
|
33666
34622
|
const hits = [];
|
|
33667
34623
|
let section = "";
|
|
33668
34624
|
let inDependenciesArray = false;
|
|
33669
|
-
eachLine(text, (rawLine, lineNumber) => {
|
|
34625
|
+
eachLine(text, (rawLine, lineNumber, snippet) => {
|
|
33670
34626
|
const sectionMatch = TOML_SECTION.exec(rawLine);
|
|
33671
34627
|
if (sectionMatch) {
|
|
33672
34628
|
section = sectionMatch[1]?.trim() ?? "";
|
|
@@ -33680,7 +34636,7 @@ function extractPyprojectToml(text) {
|
|
|
33680
34636
|
for (const spec of quotedStrings(rawLine)) {
|
|
33681
34637
|
const name = PEP508_NAME.exec(spec)?.[1];
|
|
33682
34638
|
if (name !== void 0)
|
|
33683
|
-
hits.push(makeHit("pypi", normalizePypi(name), lineNumber,
|
|
34639
|
+
hits.push(makeHit("pypi", normalizePypi(name), lineNumber, snippet()));
|
|
33684
34640
|
}
|
|
33685
34641
|
if (rawLine.includes("]")) inDependenciesArray = false;
|
|
33686
34642
|
return;
|
|
@@ -33688,7 +34644,7 @@ function extractPyprojectToml(text) {
|
|
|
33688
34644
|
if (section === "tool.poetry.dependencies") {
|
|
33689
34645
|
const key = POETRY_KEY.exec(rawLine)?.[1];
|
|
33690
34646
|
if (key !== void 0 && key !== "python") {
|
|
33691
|
-
hits.push(makeHit("pypi", normalizePypi(key), lineNumber,
|
|
34647
|
+
hits.push(makeHit("pypi", normalizePypi(key), lineNumber, snippet()));
|
|
33692
34648
|
}
|
|
33693
34649
|
}
|
|
33694
34650
|
});
|
|
@@ -33704,7 +34660,7 @@ var GO_MODULE_VERSION_LINE = /^\s*([\w./-]+)\s+v\d/;
|
|
|
33704
34660
|
function extractGoMod(text) {
|
|
33705
34661
|
const hits = [];
|
|
33706
34662
|
let blockKeyword = null;
|
|
33707
|
-
eachLine(text, (rawLine, lineNumber) => {
|
|
34663
|
+
eachLine(text, (rawLine, lineNumber, snippet) => {
|
|
33708
34664
|
if (blockKeyword === null) {
|
|
33709
34665
|
const open3 = GO_BLOCK_OPEN.exec(rawLine)?.[1];
|
|
33710
34666
|
if (open3 !== void 0) {
|
|
@@ -33712,7 +34668,7 @@ function extractGoMod(text) {
|
|
|
33712
34668
|
return;
|
|
33713
34669
|
}
|
|
33714
34670
|
const path = GO_REQUIRE_SINGLE_LINE.exec(rawLine)?.[1];
|
|
33715
|
-
if (path !== void 0) hits.push(makeHit("go", path, lineNumber,
|
|
34671
|
+
if (path !== void 0) hits.push(makeHit("go", path, lineNumber, snippet()));
|
|
33716
34672
|
return;
|
|
33717
34673
|
}
|
|
33718
34674
|
if (GO_BLOCK_CLOSE.test(rawLine)) {
|
|
@@ -33721,7 +34677,7 @@ function extractGoMod(text) {
|
|
|
33721
34677
|
}
|
|
33722
34678
|
if (blockKeyword === "require") {
|
|
33723
34679
|
const path = GO_MODULE_VERSION_LINE.exec(rawLine)?.[1];
|
|
33724
|
-
if (path !== void 0) hits.push(makeHit("go", path, lineNumber,
|
|
34680
|
+
if (path !== void 0) hits.push(makeHit("go", path, lineNumber, snippet()));
|
|
33725
34681
|
}
|
|
33726
34682
|
});
|
|
33727
34683
|
return hits;
|
|
@@ -33738,13 +34694,13 @@ var POM_CONTEXT_TAGS = /* @__PURE__ */ new Set([
|
|
|
33738
34694
|
"exclusions",
|
|
33739
34695
|
"exclusion"
|
|
33740
34696
|
]);
|
|
33741
|
-
var XML_TAG = /<(\/?)([A-Za-z][\w.-]*)([^<>]*)>/g;
|
|
34697
|
+
var XML_TAG = /<(\/?)([A-Za-z][\w.-]*)((?:[^<>\w.-][^<>]*)?)>/g;
|
|
33742
34698
|
var LEADING_TEXT = /^([^<]*)/;
|
|
33743
34699
|
function extractPomXml(text) {
|
|
33744
34700
|
const hits = [];
|
|
33745
34701
|
const stack = [];
|
|
33746
34702
|
let inComment = false;
|
|
33747
|
-
eachLine(text, (rawLine, lineNumber) => {
|
|
34703
|
+
eachLine(text, (rawLine, lineNumber, snippet) => {
|
|
33748
34704
|
const stripped = stripXmlComments(rawLine, inComment);
|
|
33749
34705
|
inComment = stripped.inComment;
|
|
33750
34706
|
const visible = stripped.visible;
|
|
@@ -33763,7 +34719,7 @@ function extractPomXml(text) {
|
|
|
33763
34719
|
const after = visible.slice(match.index + match[0].length);
|
|
33764
34720
|
const value = LEADING_TEXT.exec(after)?.[1]?.trim() ?? "";
|
|
33765
34721
|
if (value !== "" && isProjectDependencyGroupId(stack)) {
|
|
33766
|
-
hits.push(makeHit("maven", value, lineNumber,
|
|
34722
|
+
hits.push(makeHit("maven", value, lineNumber, snippet()));
|
|
33767
34723
|
}
|
|
33768
34724
|
continue;
|
|
33769
34725
|
}
|
|
@@ -33779,11 +34735,11 @@ var GRADLE_DEPENDENCY = /\b(?:implementation|api|compile)\b\s*[('"]*(?:platform\
|
|
|
33779
34735
|
var LINE_COMMENT = /^\s*\/\//;
|
|
33780
34736
|
function extractBuildGradle(text) {
|
|
33781
34737
|
const hits = [];
|
|
33782
|
-
eachLine(text, (rawLine, lineNumber) => {
|
|
34738
|
+
eachLine(text, (rawLine, lineNumber, snippet) => {
|
|
33783
34739
|
if (LINE_COMMENT.test(rawLine)) return;
|
|
33784
34740
|
for (const match of rawLine.matchAll(GRADLE_DEPENDENCY)) {
|
|
33785
34741
|
const groupId = match[1];
|
|
33786
|
-
if (groupId !== void 0) hits.push(makeHit("maven", groupId, lineNumber,
|
|
34742
|
+
if (groupId !== void 0) hits.push(makeHit("maven", groupId, lineNumber, snippet()));
|
|
33787
34743
|
}
|
|
33788
34744
|
});
|
|
33789
34745
|
return hits;
|
|
@@ -33791,9 +34747,9 @@ function extractBuildGradle(text) {
|
|
|
33791
34747
|
var GEMFILE_DEPENDENCY = /^\s*gem\s+['"]([\w-]+)['"]/;
|
|
33792
34748
|
function extractGemfile(text) {
|
|
33793
34749
|
const hits = [];
|
|
33794
|
-
eachLine(text, (rawLine, lineNumber) => {
|
|
34750
|
+
eachLine(text, (rawLine, lineNumber, snippet) => {
|
|
33795
34751
|
const name = GEMFILE_DEPENDENCY.exec(rawLine)?.[1];
|
|
33796
|
-
if (name !== void 0) hits.push(makeHit("rubygems", name, lineNumber,
|
|
34752
|
+
if (name !== void 0) hits.push(makeHit("rubygems", name, lineNumber, snippet()));
|
|
33797
34753
|
});
|
|
33798
34754
|
return hits;
|
|
33799
34755
|
}
|
|
@@ -33801,7 +34757,7 @@ var CARGO_KEY = /^([A-Za-z0-9_-]+)\s*=/;
|
|
|
33801
34757
|
function extractCargoToml(text) {
|
|
33802
34758
|
const hits = [];
|
|
33803
34759
|
let mode = "none";
|
|
33804
|
-
eachLine(text, (rawLine, lineNumber) => {
|
|
34760
|
+
eachLine(text, (rawLine, lineNumber, snippet) => {
|
|
33805
34761
|
const sectionMatch = TOML_SECTION.exec(rawLine);
|
|
33806
34762
|
if (sectionMatch) {
|
|
33807
34763
|
const name = sectionMatch[1]?.trim() ?? "";
|
|
@@ -33810,7 +34766,7 @@ function extractCargoToml(text) {
|
|
|
33810
34766
|
} else if (name.startsWith("dependencies.")) {
|
|
33811
34767
|
mode = "dotted";
|
|
33812
34768
|
const crate = name.slice("dependencies.".length);
|
|
33813
|
-
if (crate !== "") hits.push(makeHit("cargo", crate, lineNumber,
|
|
34769
|
+
if (crate !== "") hits.push(makeHit("cargo", crate, lineNumber, snippet()));
|
|
33814
34770
|
} else {
|
|
33815
34771
|
mode = "none";
|
|
33816
34772
|
}
|
|
@@ -33818,7 +34774,7 @@ function extractCargoToml(text) {
|
|
|
33818
34774
|
}
|
|
33819
34775
|
if (mode === "plain") {
|
|
33820
34776
|
const crate = CARGO_KEY.exec(rawLine)?.[1];
|
|
33821
|
-
if (crate !== void 0) hits.push(makeHit("cargo", crate, lineNumber,
|
|
34777
|
+
if (crate !== void 0) hits.push(makeHit("cargo", crate, lineNumber, snippet()));
|
|
33822
34778
|
}
|
|
33823
34779
|
});
|
|
33824
34780
|
return hits;
|
|
@@ -33827,17 +34783,20 @@ function extractComposerJson(text) {
|
|
|
33827
34783
|
const parsed2 = parseJson(text);
|
|
33828
34784
|
if (parsed2 === null) return [];
|
|
33829
34785
|
const pkgs = objectKeys(parsed2.require).filter((pkg) => pkg !== "php" && !pkg.startsWith("ext-"));
|
|
33830
|
-
|
|
34786
|
+
const lines = manifestLines(text);
|
|
34787
|
+
const tokens = quotedTokenOffsets(text);
|
|
34788
|
+
const requireAt = sectionOffset(text, "require");
|
|
34789
|
+
return pkgs.map((pkg) => hitAtQuotedKey("composer", pkg, text, requireAt, lines, tokens));
|
|
33831
34790
|
}
|
|
33832
34791
|
var CSPROJ_PACKAGE_REFERENCE = /<PackageReference\s+Include="([^"]+)"/;
|
|
33833
34792
|
function extractCsproj(text) {
|
|
33834
34793
|
const hits = [];
|
|
33835
34794
|
let inComment = false;
|
|
33836
|
-
eachLine(text, (rawLine, lineNumber) => {
|
|
34795
|
+
eachLine(text, (rawLine, lineNumber, snippet) => {
|
|
33837
34796
|
const stripped = stripXmlComments(rawLine, inComment);
|
|
33838
34797
|
inComment = stripped.inComment;
|
|
33839
34798
|
const name = CSPROJ_PACKAGE_REFERENCE.exec(stripped.visible)?.[1];
|
|
33840
|
-
if (name !== void 0) hits.push(makeHit("nuget", name, lineNumber,
|
|
34799
|
+
if (name !== void 0) hits.push(makeHit("nuget", name, lineNumber, snippet()));
|
|
33841
34800
|
});
|
|
33842
34801
|
return hits;
|
|
33843
34802
|
}
|
|
@@ -33845,11 +34804,11 @@ var PACKAGES_CONFIG_PACKAGE = /<package\s+id="([^"]+)"/;
|
|
|
33845
34804
|
function extractPackagesConfig(text) {
|
|
33846
34805
|
const hits = [];
|
|
33847
34806
|
let inComment = false;
|
|
33848
|
-
eachLine(text, (rawLine, lineNumber) => {
|
|
34807
|
+
eachLine(text, (rawLine, lineNumber, snippet) => {
|
|
33849
34808
|
const stripped = stripXmlComments(rawLine, inComment);
|
|
33850
34809
|
inComment = stripped.inComment;
|
|
33851
34810
|
const name = PACKAGES_CONFIG_PACKAGE.exec(stripped.visible)?.[1];
|
|
33852
|
-
if (name !== void 0) hits.push(makeHit("nuget", name, lineNumber,
|
|
34811
|
+
if (name !== void 0) hits.push(makeHit("nuget", name, lineNumber, snippet()));
|
|
33853
34812
|
});
|
|
33854
34813
|
return hits;
|
|
33855
34814
|
}
|
|
@@ -33875,7 +34834,9 @@ function stripXmlComments(line, inComment) {
|
|
|
33875
34834
|
function eachLine(text, fn) {
|
|
33876
34835
|
const lines = text.split("\n");
|
|
33877
34836
|
for (let i = 0; i < lines.length; i += 1) {
|
|
33878
|
-
|
|
34837
|
+
const rawLine = lines[i] ?? "";
|
|
34838
|
+
let cached2;
|
|
34839
|
+
fn(rawLine, i + 1, () => cached2 ??= redactSnippet(rawLine));
|
|
33879
34840
|
}
|
|
33880
34841
|
}
|
|
33881
34842
|
function parseJson(text) {
|
|
@@ -33897,24 +34858,76 @@ function objectKeys(value) {
|
|
|
33897
34858
|
if (typeof value !== "object" || value === null) return [];
|
|
33898
34859
|
return Object.keys(value);
|
|
33899
34860
|
}
|
|
33900
|
-
function
|
|
33901
|
-
const
|
|
33902
|
-
const
|
|
33903
|
-
|
|
33904
|
-
|
|
33905
|
-
|
|
34861
|
+
function manifestLines(text) {
|
|
34862
|
+
const starts = lineStartOffsets(text);
|
|
34863
|
+
const snippets = /* @__PURE__ */ new Map();
|
|
34864
|
+
return {
|
|
34865
|
+
numberAt: (index) => lineIndexAt(starts, index) + 1,
|
|
34866
|
+
snippetAt: (index) => {
|
|
34867
|
+
const line = lineIndexAt(starts, index);
|
|
34868
|
+
const cached2 = snippets.get(line);
|
|
34869
|
+
if (cached2 !== void 0) return cached2;
|
|
34870
|
+
const value = redactSnippet(lineTextAt(text, starts, line));
|
|
34871
|
+
snippets.set(line, value);
|
|
34872
|
+
return value;
|
|
34873
|
+
}
|
|
34874
|
+
};
|
|
34875
|
+
}
|
|
34876
|
+
function sectionOffset(text, sectionKey) {
|
|
34877
|
+
const at = text.indexOf(`"${sectionKey}"`);
|
|
34878
|
+
return at === -1 ? 0 : at;
|
|
33906
34879
|
}
|
|
33907
|
-
|
|
33908
|
-
|
|
33909
|
-
|
|
33910
|
-
|
|
34880
|
+
var QUOTE = 34;
|
|
34881
|
+
var BACKSLASH = 92;
|
|
34882
|
+
function quotedTokenOffsets(text) {
|
|
34883
|
+
const at = /* @__PURE__ */ new Map();
|
|
34884
|
+
for (let i = 0; i < text.length; i += 1) {
|
|
34885
|
+
if (text.charCodeAt(i) !== QUOTE) continue;
|
|
34886
|
+
let end = i + 1;
|
|
34887
|
+
while (end < text.length && text.charCodeAt(end) !== QUOTE) {
|
|
34888
|
+
end += text.charCodeAt(end) === BACKSLASH ? 2 : 1;
|
|
34889
|
+
}
|
|
34890
|
+
if (end >= text.length) break;
|
|
34891
|
+
const inner = text.slice(i + 1, end);
|
|
34892
|
+
const name = inner.includes("\\") ? decodeJsonString(text.slice(i, end + 1)) : inner;
|
|
34893
|
+
if (name !== void 0) {
|
|
34894
|
+
const seen = at.get(name);
|
|
34895
|
+
if (seen === void 0) at.set(name, [i]);
|
|
34896
|
+
else seen.push(i);
|
|
34897
|
+
}
|
|
34898
|
+
i = end;
|
|
33911
34899
|
}
|
|
33912
|
-
return
|
|
34900
|
+
return at;
|
|
33913
34901
|
}
|
|
33914
|
-
function
|
|
33915
|
-
|
|
33916
|
-
|
|
33917
|
-
|
|
34902
|
+
function decodeJsonString(quoted) {
|
|
34903
|
+
try {
|
|
34904
|
+
return JSON.parse(quoted);
|
|
34905
|
+
} catch {
|
|
34906
|
+
return void 0;
|
|
34907
|
+
}
|
|
34908
|
+
}
|
|
34909
|
+
function firstAtOrAfter(offsets, from) {
|
|
34910
|
+
let low = 0;
|
|
34911
|
+
let high = offsets.length - 1;
|
|
34912
|
+
let found;
|
|
34913
|
+
while (low <= high) {
|
|
34914
|
+
const mid = low + high >> 1;
|
|
34915
|
+
const at = offsets[mid] ?? 0;
|
|
34916
|
+
if (at >= from) {
|
|
34917
|
+
found = at;
|
|
34918
|
+
high = mid - 1;
|
|
34919
|
+
} else {
|
|
34920
|
+
low = mid + 1;
|
|
34921
|
+
}
|
|
34922
|
+
}
|
|
34923
|
+
return found;
|
|
34924
|
+
}
|
|
34925
|
+
function hitAtQuotedKey(ecosystem, pkg, text, searchFrom, lines, tokens) {
|
|
34926
|
+
const offsets = tokens.get(pkg);
|
|
34927
|
+
const known = offsets === void 0 ? void 0 : firstAtOrAfter(offsets, searchFrom);
|
|
34928
|
+
const index = known ?? text.indexOf(`"${pkg}"`, searchFrom);
|
|
34929
|
+
if (index === -1) return makeHit(ecosystem, pkg, 1, redactSnippet(pkg));
|
|
34930
|
+
return { ecosystem, pkg, line: lines.numberAt(index), snippet: lines.snippetAt(index) };
|
|
33918
34931
|
}
|
|
33919
34932
|
|
|
33920
34933
|
// ../../packages/detections/src/egress/resolve.ts
|
|
@@ -36527,8 +37540,8 @@ function bundledDetections() {
|
|
|
36527
37540
|
}
|
|
36528
37541
|
|
|
36529
37542
|
// ../../packages/plugin-sdk/src/repo.ts
|
|
36530
|
-
import { existsSync as
|
|
36531
|
-
import { basename as basename2, dirname as dirname4, isAbsolute, join as
|
|
37543
|
+
import { existsSync as existsSync9, readFileSync as readFileSync10, statSync as statSync6 } from "fs";
|
|
37544
|
+
import { basename as basename2, dirname as dirname4, isAbsolute, join as join17, sep as sep2 } from "path";
|
|
36532
37545
|
function resolveRepoIdentity(cwd) {
|
|
36533
37546
|
try {
|
|
36534
37547
|
const root = findGitRoot(cwd);
|
|
@@ -36557,36 +37570,36 @@ function resolveWorktreeRoot(cwd) {
|
|
|
36557
37570
|
function findGitRoot(start) {
|
|
36558
37571
|
let dir = start;
|
|
36559
37572
|
for (; ; ) {
|
|
36560
|
-
if (
|
|
37573
|
+
if (existsSync9(join17(dir, ".git"))) return dir;
|
|
36561
37574
|
const parent = dirname4(dir);
|
|
36562
37575
|
if (parent === dir) return void 0;
|
|
36563
37576
|
dir = parent;
|
|
36564
37577
|
}
|
|
36565
37578
|
}
|
|
36566
37579
|
function resolveGitContext(root) {
|
|
36567
|
-
const dotGit =
|
|
37580
|
+
const dotGit = join17(root, ".git");
|
|
36568
37581
|
try {
|
|
36569
37582
|
if (statSync6(dotGit).isDirectory()) {
|
|
36570
|
-
return { configPath:
|
|
37583
|
+
return { configPath: join17(dotGit, "config"), headRoot: root };
|
|
36571
37584
|
}
|
|
36572
37585
|
} catch {
|
|
36573
37586
|
return void 0;
|
|
36574
37587
|
}
|
|
36575
37588
|
const target = /^gitdir:\s*(.+?)\s*$/m.exec(safeRead(dotGit) ?? "")?.[1];
|
|
36576
37589
|
if (!target) return void 0;
|
|
36577
|
-
const gitdir = isAbsolute(target) ? target :
|
|
36578
|
-
if (
|
|
36579
|
-
return { configPath:
|
|
37590
|
+
const gitdir = isAbsolute(target) ? target : join17(root, target);
|
|
37591
|
+
if (existsSync9(join17(gitdir, "config"))) {
|
|
37592
|
+
return { configPath: join17(gitdir, "config"), headRoot: root };
|
|
36580
37593
|
}
|
|
36581
|
-
const commonRaw = safeRead(
|
|
37594
|
+
const commonRaw = safeRead(join17(gitdir, "commondir"))?.trim();
|
|
36582
37595
|
if (!commonRaw) return void 0;
|
|
36583
|
-
const commonGitDir = isAbsolute(commonRaw) ? commonRaw :
|
|
37596
|
+
const commonGitDir = isAbsolute(commonRaw) ? commonRaw : join17(gitdir, commonRaw);
|
|
36584
37597
|
const headRoot = basename2(commonGitDir) === ".git" ? dirname4(commonGitDir) : root;
|
|
36585
|
-
return { configPath:
|
|
37598
|
+
return { configPath: join17(commonGitDir, "config"), headRoot };
|
|
36586
37599
|
}
|
|
36587
37600
|
function safeRead(path) {
|
|
36588
37601
|
try {
|
|
36589
|
-
return
|
|
37602
|
+
return readFileSync10(path, "utf8");
|
|
36590
37603
|
} catch {
|
|
36591
37604
|
return void 0;
|
|
36592
37605
|
}
|
|
@@ -36624,9 +37637,9 @@ function slugFromUrl(url2) {
|
|
|
36624
37637
|
}
|
|
36625
37638
|
|
|
36626
37639
|
// ../../packages/plugin-sdk/src/events.ts
|
|
36627
|
-
import { createHash as
|
|
37640
|
+
import { createHash as createHash5, randomUUID as randomUUID13 } from "crypto";
|
|
36628
37641
|
function contentHashOf(text) {
|
|
36629
|
-
return
|
|
37642
|
+
return createHash5("sha256").update(text).digest("hex");
|
|
36630
37643
|
}
|
|
36631
37644
|
function buildIngestEvent(input2) {
|
|
36632
37645
|
const contentHash = input2.contentHash ?? contentHashOf(input2.content);
|
|
@@ -36652,7 +37665,7 @@ function buildIngestEvent(input2) {
|
|
|
36652
37665
|
}
|
|
36653
37666
|
|
|
36654
37667
|
// ../../packages/plugin-sdk/src/isolated-scan.ts
|
|
36655
|
-
import { existsSync as
|
|
37668
|
+
import { existsSync as existsSync10 } from "fs";
|
|
36656
37669
|
import { fileURLToPath } from "url";
|
|
36657
37670
|
import { Worker } from "worker_threads";
|
|
36658
37671
|
var ISOLATED_SCAN_BUDGET_MS = 2e3;
|
|
@@ -36666,7 +37679,7 @@ function resolveWorkerUrl() {
|
|
|
36666
37679
|
for (const name of ["scan-worker.js", "scan-worker.ts"]) {
|
|
36667
37680
|
const candidate = new URL(name, import.meta.url);
|
|
36668
37681
|
try {
|
|
36669
|
-
if (
|
|
37682
|
+
if (existsSync10(fileURLToPath(candidate))) {
|
|
36670
37683
|
resolvedWorkerUrl = candidate;
|
|
36671
37684
|
return candidate;
|
|
36672
37685
|
}
|
|
@@ -37129,13 +38142,48 @@ function createGuardedScanner(partition, gateway, opts) {
|
|
|
37129
38142
|
};
|
|
37130
38143
|
}
|
|
37131
38144
|
|
|
38145
|
+
// ../../packages/plugin-sdk/src/host-floor.ts
|
|
38146
|
+
import { readFileSync as readFileSync13 } from "fs";
|
|
38147
|
+
import { join as join20 } from "path";
|
|
38148
|
+
|
|
38149
|
+
// ../../packages/plugin-sdk/src/model-governance.ts
|
|
38150
|
+
import {
|
|
38151
|
+
closeSync as closeSync2,
|
|
38152
|
+
fstatSync,
|
|
38153
|
+
mkdirSync as mkdirSync2,
|
|
38154
|
+
openSync as openSync2,
|
|
38155
|
+
readFileSync as readFileSync12,
|
|
38156
|
+
readSync,
|
|
38157
|
+
writeFileSync as writeFileSync5
|
|
38158
|
+
} from "fs";
|
|
38159
|
+
import { join as join19 } from "path";
|
|
38160
|
+
var TAIL_BYTES = 256 * 1024;
|
|
38161
|
+
|
|
38162
|
+
// ../../packages/plugin-sdk/src/host-floor.ts
|
|
38163
|
+
var HOST_FEATURE = {
|
|
38164
|
+
ModelSwitch: "model-switch",
|
|
38165
|
+
VaultPointerDisplay: "vault-pointer-display"
|
|
38166
|
+
};
|
|
38167
|
+
var HOST_FLOORS = {
|
|
38168
|
+
[HOST_FEATURE.ModelSwitch]: {
|
|
38169
|
+
label: "model-switch protection",
|
|
38170
|
+
hookEvents: ["PreModelSwitch", "PostModelSwitch"],
|
|
38171
|
+
since: "2.1.251"
|
|
38172
|
+
},
|
|
38173
|
+
[HOST_FEATURE.VaultPointerDisplay]: {
|
|
38174
|
+
label: "vault pointer display",
|
|
38175
|
+
hookEvents: ["MessageDisplay"],
|
|
38176
|
+
since: "2.1.152"
|
|
38177
|
+
}
|
|
38178
|
+
};
|
|
38179
|
+
|
|
37132
38180
|
// ../../packages/plugin-sdk/src/ignore-layers.ts
|
|
37133
38181
|
var import_ignore = __toESM(require_ignore(), 1);
|
|
37134
|
-
import { readFileSync as
|
|
37135
|
-
import { join as
|
|
38182
|
+
import { readFileSync as readFileSync14 } from "fs";
|
|
38183
|
+
import { join as join21 } from "path";
|
|
37136
38184
|
function readIgnoreLayer(dir, filename, anchorLen) {
|
|
37137
38185
|
try {
|
|
37138
|
-
return { matcher: (0, import_ignore.default)().add(
|
|
38186
|
+
return { matcher: (0, import_ignore.default)().add(readFileSync14(join21(dir, filename), "utf8")), anchorLen };
|
|
37139
38187
|
} catch {
|
|
37140
38188
|
return void 0;
|
|
37141
38189
|
}
|
|
@@ -37165,22 +38213,9 @@ function withLayer(layers, layer) {
|
|
|
37165
38213
|
// ../../packages/plugin-sdk/src/inventory-resolver.ts
|
|
37166
38214
|
import { arch, hostname as hostname4, platform, release } from "os";
|
|
37167
38215
|
|
|
37168
|
-
// ../../packages/plugin-sdk/src/model-governance.ts
|
|
37169
|
-
import {
|
|
37170
|
-
closeSync as closeSync2,
|
|
37171
|
-
fstatSync,
|
|
37172
|
-
mkdirSync as mkdirSync2,
|
|
37173
|
-
openSync as openSync2,
|
|
37174
|
-
readFileSync as readFileSync11,
|
|
37175
|
-
readSync,
|
|
37176
|
-
writeFileSync as writeFileSync5
|
|
37177
|
-
} from "fs";
|
|
37178
|
-
import { join as join17 } from "path";
|
|
37179
|
-
var TAIL_BYTES = 256 * 1024;
|
|
37180
|
-
|
|
37181
38216
|
// ../../packages/plugin-sdk/src/nudge.ts
|
|
37182
|
-
import { mkdirSync as mkdirSync3, readFileSync as
|
|
37183
|
-
import { join as
|
|
38217
|
+
import { mkdirSync as mkdirSync3, readFileSync as readFileSync15, writeFileSync as writeFileSync6 } from "fs";
|
|
38218
|
+
import { join as join22 } from "path";
|
|
37184
38219
|
|
|
37185
38220
|
// ../../packages/plugin-sdk/src/paths.ts
|
|
37186
38221
|
import { readdirSync as readdirSync3, realpathSync as realpathSync3 } from "fs";
|
|
@@ -37252,8 +38287,8 @@ function createPolicyResolver(bundle) {
|
|
|
37252
38287
|
}
|
|
37253
38288
|
|
|
37254
38289
|
// ../../packages/plugin-sdk/src/project-files.ts
|
|
37255
|
-
import { existsSync as
|
|
37256
|
-
import { basename as basename5, join as
|
|
38290
|
+
import { existsSync as existsSync11, readdirSync as readdirSync4 } from "fs";
|
|
38291
|
+
import { basename as basename5, join as join23 } from "path";
|
|
37257
38292
|
|
|
37258
38293
|
// ../../packages/plugin-sdk/src/provider-env-antigravity.ts
|
|
37259
38294
|
var optionalBaseUrl2 = external_exports.preprocess((v) => {
|
|
@@ -37284,6 +38319,14 @@ var CodexProviderEnvSchema = external_exports.object(codexProviderEnvShape);
|
|
|
37284
38319
|
// ../../packages/plugin-sdk/src/runtime.ts
|
|
37285
38320
|
import { randomUUID as randomUUID14 } from "crypto";
|
|
37286
38321
|
var ENFORCEMENT_CEILING_ENABLED = false;
|
|
38322
|
+
function applyEnforcementCeiling(action, policyMode, enabled) {
|
|
38323
|
+
if (!enabled || policyMode !== "warn") return action;
|
|
38324
|
+
return action === "block" || action === "redact" ? "warn" : action;
|
|
38325
|
+
}
|
|
38326
|
+
function resolveEnforcedAction(action, opts) {
|
|
38327
|
+
const degraded = !opts.rewritable && action === "redact" ? builtinPolicyToAction(opts.redactFallback) : action;
|
|
38328
|
+
return applyEnforcementCeiling(degraded, opts.policyMode, opts.ceilingEnabled);
|
|
38329
|
+
}
|
|
37287
38330
|
function startTiming() {
|
|
37288
38331
|
try {
|
|
37289
38332
|
return performance.now();
|
|
@@ -37320,7 +38363,7 @@ function createPluginRuntime(gateway, settings, opts) {
|
|
|
37320
38363
|
bundlesPacked = true;
|
|
37321
38364
|
}
|
|
37322
38365
|
const policyMode = settings.policy;
|
|
37323
|
-
|
|
38366
|
+
let redactFallback = settings.redactFallback;
|
|
37324
38367
|
const dataDir2 = opts?.dataDir;
|
|
37325
38368
|
let rules = [];
|
|
37326
38369
|
let scanner;
|
|
@@ -37364,6 +38407,7 @@ function createPluginRuntime(gateway, settings, opts) {
|
|
|
37364
38407
|
rules = [...verified, ...unverified];
|
|
37365
38408
|
scanner = createGuardedScanner({ verified, unverified }, gateway, opts?.scanIsolation);
|
|
37366
38409
|
bundleExceptions = bundle.exceptions ?? [];
|
|
38410
|
+
redactFallback = strongerRedactFallback(settings.redactFallback, bundle.redactFallback);
|
|
37367
38411
|
initialized = true;
|
|
37368
38412
|
}
|
|
37369
38413
|
let cachedKey;
|
|
@@ -37392,21 +38436,23 @@ function createPluginRuntime(gateway, settings, opts) {
|
|
|
37392
38436
|
}
|
|
37393
38437
|
function actionForFinding(finding, excepted, rewritable = true) {
|
|
37394
38438
|
if (excepted?.has(finding)) return "allow";
|
|
37395
|
-
|
|
37396
|
-
|
|
37397
|
-
|
|
37398
|
-
|
|
37399
|
-
|
|
37400
|
-
|
|
38439
|
+
return resolveEnforcedAction(resolveAction(finding.ruleId, finding.category), {
|
|
38440
|
+
policyMode,
|
|
38441
|
+
redactFallback,
|
|
38442
|
+
rewritable,
|
|
38443
|
+
ceilingEnabled: ENFORCEMENT_CEILING_ENABLED
|
|
38444
|
+
});
|
|
37401
38445
|
}
|
|
37402
38446
|
function decide(findings, text, excepted, rewritable = true) {
|
|
37403
38447
|
if (findings.length === 0) return { action: "log", text, findings: [] };
|
|
37404
38448
|
const actionFor = (finding) => actionForFinding(finding, excepted, rewritable);
|
|
38449
|
+
const degradedActions = rewritable ? [] : findings.filter((f) => actionForFinding(f, excepted, true) === "redact").map(actionFor);
|
|
38450
|
+
const degraded = degradedActions.length === 0 ? {} : { redactDegradedTo: degradedActions.reduce((a, b) => strongerAction(a, b)) };
|
|
37405
38451
|
let worst = "log";
|
|
37406
38452
|
for (const finding of findings) {
|
|
37407
38453
|
worst = strongerAction(worst, actionFor(finding));
|
|
37408
38454
|
}
|
|
37409
|
-
if (worst === "block") return { action: "block", text: null, findings };
|
|
38455
|
+
if (worst === "block") return { action: "block", text: null, findings, ...degraded };
|
|
37410
38456
|
if (worst === "redact") {
|
|
37411
38457
|
const redactFindings = findings.filter((f) => actionFor(f) === "redact");
|
|
37412
38458
|
const reversibleFindings = redactFindings.filter((f) => resolver.isReversible(f.ruleId));
|
|
@@ -37416,9 +38462,13 @@ function createPluginRuntime(gateway, settings, opts) {
|
|
|
37416
38462
|
findings,
|
|
37417
38463
|
enforcedFindings: redactFindings,
|
|
37418
38464
|
reversibleFindings
|
|
38465
|
+
// No `degraded` here, and it is not an omission: `rewritable` is per
|
|
38466
|
+
// CAPTURE, so on an unrewritable field every redact has already become
|
|
38467
|
+
// the fallback and this branch is unreachable. Spreading it would read
|
|
38468
|
+
// as a case that can happen.
|
|
37419
38469
|
};
|
|
37420
38470
|
}
|
|
37421
|
-
return { action: worst, text, findings };
|
|
38471
|
+
return { action: worst, text, findings, ...degraded };
|
|
37422
38472
|
}
|
|
37423
38473
|
function fingerprintOf(key, finding, cache) {
|
|
37424
38474
|
let fp = cache.get(finding);
|
|
@@ -37547,8 +38597,8 @@ function createPluginRuntime(gateway, settings, opts) {
|
|
|
37547
38597
|
};
|
|
37548
38598
|
}
|
|
37549
38599
|
}
|
|
37550
|
-
async function processText(text, context) {
|
|
37551
|
-
return (await evaluate(text, context, {})).decision;
|
|
38600
|
+
async function processText(text, context, opts2 = {}) {
|
|
38601
|
+
return (await evaluate(text, context, {}, opts2.rewritable)).decision;
|
|
37552
38602
|
}
|
|
37553
38603
|
async function capture(input2, opts2 = {}) {
|
|
37554
38604
|
const timingStartedAt = input2.occurredAt === void 0 ? startTiming() : void 0;
|
|
@@ -37571,10 +38621,12 @@ function createPluginRuntime(gateway, settings, opts) {
|
|
|
37571
38621
|
);
|
|
37572
38622
|
const storedContent = maskedFindings.length > 0 ? redact(input2.text, maskedFindings) : input2.text;
|
|
37573
38623
|
const inspectionMs = elapsedMs(timingStartedAt);
|
|
37574
|
-
const
|
|
38624
|
+
const redactDegradedTo = decision.redactDegradedTo;
|
|
38625
|
+
const metadata = exceptionIds.length > 0 || inspectionMs !== void 0 || redactDegradedTo !== void 0 ? {
|
|
37575
38626
|
...input2.metadata,
|
|
37576
38627
|
...exceptionIds.length > 0 ? { exceptionIds } : {},
|
|
37577
|
-
...inspectionMs !== void 0 ? { inspectionMs } : {}
|
|
38628
|
+
...inspectionMs !== void 0 ? { inspectionMs } : {},
|
|
38629
|
+
...redactDegradedTo !== void 0 ? { redactDegradedTo } : {}
|
|
37578
38630
|
} : input2.metadata;
|
|
37579
38631
|
const event = buildIngestEvent({
|
|
37580
38632
|
kind: input2.kind,
|
|
@@ -37646,11 +38698,11 @@ var THIRTY_DAYS_MS = 30 * 24 * 60 * 60 * 1e3;
|
|
|
37646
38698
|
|
|
37647
38699
|
// ../../packages/plugin-sdk/src/throttle.ts
|
|
37648
38700
|
import { mkdirSync as mkdirSync4, statSync as statSync8, writeFileSync as writeFileSync7 } from "fs";
|
|
37649
|
-
import { join as
|
|
38701
|
+
import { join as join24 } from "path";
|
|
37650
38702
|
|
|
37651
38703
|
// ../../packages/scanner/src/discover.ts
|
|
37652
38704
|
import { readdirSync as readdirSync5 } from "fs";
|
|
37653
|
-
import { join as
|
|
38705
|
+
import { join as join25 } from "path";
|
|
37654
38706
|
|
|
37655
38707
|
// ../../packages/scanner/src/constants.ts
|
|
37656
38708
|
var COMMON_SKIP_DIRS = ["node_modules", "__pycache__", ".venv", "venv", ".cache"];
|
|
@@ -37695,7 +38747,7 @@ function discoverGitRepos(opts) {
|
|
|
37695
38747
|
if (!entry.isDirectory()) continue;
|
|
37696
38748
|
if (DISCOVER_SKIP.has(entry.name)) continue;
|
|
37697
38749
|
if (entry.name.startsWith(".")) continue;
|
|
37698
|
-
visit2(
|
|
38750
|
+
visit2(join25(dir, entry.name), depth + 1);
|
|
37699
38751
|
}
|
|
37700
38752
|
}
|
|
37701
38753
|
for (const root of searchRoots) {
|
|
@@ -37706,7 +38758,7 @@ function discoverGitRepos(opts) {
|
|
|
37706
38758
|
|
|
37707
38759
|
// ../../packages/scanner/src/render.ts
|
|
37708
38760
|
import { basename as basename6, relative } from "path";
|
|
37709
|
-
var
|
|
38761
|
+
var SEVERITY_ORDER = ["critical", "high", "medium", "low"];
|
|
37710
38762
|
var SEVERITY_GLYPH = {
|
|
37711
38763
|
critical: "\u2588",
|
|
37712
38764
|
high: "\u2593",
|
|
@@ -37737,7 +38789,7 @@ function findingsLabel(total, gitignored) {
|
|
|
37737
38789
|
return `${String(total)} (${String(gitignored)} in .gitignore'd files \u2014 informational)`;
|
|
37738
38790
|
}
|
|
37739
38791
|
function severitySection(bySeverity) {
|
|
37740
|
-
const rows =
|
|
38792
|
+
const rows = SEVERITY_ORDER.filter((s) => (bySeverity[s] ?? 0) > 0).map((s) => [
|
|
37741
38793
|
`${SEVERITY_GLYPH[s] ?? ""} ${s}`,
|
|
37742
38794
|
String(bySeverity[s])
|
|
37743
38795
|
]);
|
|
@@ -37798,46 +38850,9 @@ function renderMultiRepoSummary(summary, opts = {}) {
|
|
|
37798
38850
|
}
|
|
37799
38851
|
|
|
37800
38852
|
// ../../packages/scanner/src/scan.ts
|
|
37801
|
-
import { existsSync as
|
|
38853
|
+
import { existsSync as existsSync12, readFileSync as readFileSync20 } from "fs";
|
|
37802
38854
|
import { extname as extname2, isAbsolute as isAbsolute2, relative as relative3 } from "path";
|
|
37803
38855
|
|
|
37804
|
-
// ../../packages/plugin-runtime/src/attached/egress-wire.ts
|
|
37805
|
-
import { createHash as createHash5 } from "crypto";
|
|
37806
|
-
function hashProjectKey(projectKey) {
|
|
37807
|
-
return createHash5("sha256").update(projectKey, "utf8").digest("hex");
|
|
37808
|
-
}
|
|
37809
|
-
function toIngestHit(hit) {
|
|
37810
|
-
return {
|
|
37811
|
-
host: hit.host,
|
|
37812
|
-
kind: hit.kind,
|
|
37813
|
-
name: hit.name,
|
|
37814
|
-
category: hit.category,
|
|
37815
|
-
trust: hit.trust,
|
|
37816
|
-
network: hit.network,
|
|
37817
|
-
method: hit.method,
|
|
37818
|
-
transport: hit.transport,
|
|
37819
|
-
url: hit.url,
|
|
37820
|
-
template: hit.template,
|
|
37821
|
-
dataClass: hit.dataClass,
|
|
37822
|
-
site: {
|
|
37823
|
-
file: hit.site.file,
|
|
37824
|
-
line: hit.site.line,
|
|
37825
|
-
dynamic: hit.site.dynamic,
|
|
37826
|
-
vendored: hit.site.vendored
|
|
37827
|
-
}
|
|
37828
|
-
};
|
|
37829
|
-
}
|
|
37830
|
-
function toEgressIngestRequest(input2) {
|
|
37831
|
-
const { hits, droppedFiles } = capHits(input2.hits, input2.reconcile.mode);
|
|
37832
|
-
const reconcile = withoutDroppedFiles(input2.reconcile, droppedFiles);
|
|
37833
|
-
return {
|
|
37834
|
-
projectKey: hashProjectKey(input2.projectKey),
|
|
37835
|
-
project: input2.project,
|
|
37836
|
-
reconcile,
|
|
37837
|
-
hits: hits.map(toIngestHit)
|
|
37838
|
-
};
|
|
37839
|
-
}
|
|
37840
|
-
|
|
37841
38856
|
// ../../packages/remote/src/http.ts
|
|
37842
38857
|
import { request as httpRequest } from "http";
|
|
37843
38858
|
import { request as httpsRequest } from "https";
|
|
@@ -38021,10 +39036,10 @@ function parsed(schema, body, route) {
|
|
|
38021
39036
|
}
|
|
38022
39037
|
function withoutTrailingSlashes(endpoint) {
|
|
38023
39038
|
let end = endpoint.length;
|
|
38024
|
-
while (end > 0 && endpoint.charCodeAt(end - 1) ===
|
|
39039
|
+
while (end > 0 && endpoint.charCodeAt(end - 1) === SLASH2) end -= 1;
|
|
38025
39040
|
return endpoint.slice(0, end);
|
|
38026
39041
|
}
|
|
38027
|
-
var
|
|
39042
|
+
var SLASH2 = "/".charCodeAt(0);
|
|
38028
39043
|
function createRemoteClient(options) {
|
|
38029
39044
|
const base = withoutTrailingSlashes(options.endpoint);
|
|
38030
39045
|
const url2 = (route) => `${base}${route}`;
|
|
@@ -38117,6 +39132,7 @@ function createRemoteClient(options) {
|
|
|
38117
39132
|
url: url2(ROUTES.shares),
|
|
38118
39133
|
body: JSON.stringify(validated.data)
|
|
38119
39134
|
});
|
|
39135
|
+
if (response.status === 404) throw new RemoteRouteAbsent(ROUTES.shares);
|
|
38120
39136
|
okBody(response);
|
|
38121
39137
|
},
|
|
38122
39138
|
async pollCommand() {
|
|
@@ -38139,19 +39155,51 @@ function createRemoteClient(options) {
|
|
|
38139
39155
|
};
|
|
38140
39156
|
}
|
|
38141
39157
|
|
|
38142
|
-
// ../../packages/
|
|
39158
|
+
// ../../packages/remote/src/failure-kind.ts
|
|
38143
39159
|
function statusOf(err) {
|
|
38144
39160
|
if (typeof err !== "object" || err === null || !("status" in err)) return null;
|
|
38145
39161
|
const { status } = err;
|
|
38146
39162
|
if (typeof status !== "number" || !Number.isInteger(status)) return null;
|
|
38147
39163
|
return status >= 100 && status <= 599 ? status : null;
|
|
38148
39164
|
}
|
|
38149
|
-
function
|
|
38150
|
-
|
|
39165
|
+
function nameOf(err) {
|
|
39166
|
+
if (typeof err !== "object" || err === null || !("name" in err)) return null;
|
|
39167
|
+
return typeof err.name === "string" ? err.name : null;
|
|
39168
|
+
}
|
|
39169
|
+
function classifyRemoteFailure(err) {
|
|
39170
|
+
switch (nameOf(err)) {
|
|
39171
|
+
case "RemoteRouteAbsent":
|
|
39172
|
+
return "route-absent";
|
|
39173
|
+
case "RemoteRequestInvalid":
|
|
39174
|
+
return "invalid-request";
|
|
39175
|
+
case "RemoteResponseInvalid":
|
|
39176
|
+
return "rejected";
|
|
39177
|
+
default:
|
|
39178
|
+
break;
|
|
39179
|
+
}
|
|
39180
|
+
const status = statusOf(err);
|
|
39181
|
+
if (status === null) return "unreachable";
|
|
39182
|
+
switch (status) {
|
|
38151
39183
|
case 401:
|
|
38152
39184
|
return "unauthorized";
|
|
38153
39185
|
case 403:
|
|
38154
39186
|
return "forbidden";
|
|
39187
|
+
case 429:
|
|
39188
|
+
return "unreachable";
|
|
39189
|
+
case 404:
|
|
39190
|
+
return "unreachable";
|
|
39191
|
+
default:
|
|
39192
|
+
return status >= 400 && status <= 499 ? "rejected" : "unreachable";
|
|
39193
|
+
}
|
|
39194
|
+
}
|
|
39195
|
+
|
|
39196
|
+
// ../../packages/plugin-runtime/src/attached/failure.ts
|
|
39197
|
+
function classifyFailure(err) {
|
|
39198
|
+
switch (classifyRemoteFailure(err)) {
|
|
39199
|
+
case "unauthorized":
|
|
39200
|
+
return "unauthorized";
|
|
39201
|
+
case "forbidden":
|
|
39202
|
+
return "forbidden";
|
|
38155
39203
|
default:
|
|
38156
39204
|
return "unreachable";
|
|
38157
39205
|
}
|
|
@@ -38173,11 +39221,11 @@ function withTimeout(promise2, ms) {
|
|
|
38173
39221
|
}
|
|
38174
39222
|
|
|
38175
39223
|
// ../../packages/plugin-runtime/src/attached/forward-drops.ts
|
|
38176
|
-
import { readFileSync as
|
|
38177
|
-
import { join as
|
|
39224
|
+
import { readFileSync as readFileSync16 } from "fs";
|
|
39225
|
+
import { join as join26 } from "path";
|
|
38178
39226
|
var FORWARD_DROPS_FILENAME = ATTACHED_FORWARD_DROPS_FILENAME;
|
|
38179
39227
|
function forwardDropsPath(dataDir2) {
|
|
38180
|
-
return
|
|
39228
|
+
return join26(dataDir2, FORWARD_DROPS_FILENAME);
|
|
38181
39229
|
}
|
|
38182
39230
|
function recordForwardDrops(dataDir2, count, nowMs) {
|
|
38183
39231
|
if (count <= 0) return;
|
|
@@ -38195,7 +39243,7 @@ function recordForwardDrops(dataDir2, count, nowMs) {
|
|
|
38195
39243
|
}
|
|
38196
39244
|
function readForwardDrops(dataDir2) {
|
|
38197
39245
|
try {
|
|
38198
|
-
const parsed2 = JSON.parse(
|
|
39246
|
+
const parsed2 = JSON.parse(readFileSync16(forwardDropsPath(dataDir2), "utf8"));
|
|
38199
39247
|
if (typeof parsed2 !== "object" || parsed2 === null) return null;
|
|
38200
39248
|
const record2 = parsed2;
|
|
38201
39249
|
if (typeof record2.droppedForwards !== "number" || !Number.isFinite(record2.droppedForwards)) {
|
|
@@ -38213,9 +39261,8 @@ function readForwardDrops(dataDir2) {
|
|
|
38213
39261
|
|
|
38214
39262
|
// ../../packages/plugin-runtime/src/attached/forward-policy.ts
|
|
38215
39263
|
import { randomUUID as randomUUID15 } from "crypto";
|
|
38216
|
-
import { readFileSync as readFileSync14 } from "fs";
|
|
38217
39264
|
import { readFile, rename, writeFile } from "fs/promises";
|
|
38218
|
-
import { join as
|
|
39265
|
+
import { join as join27 } from "path";
|
|
38219
39266
|
function isInvalidRequest(err) {
|
|
38220
39267
|
return typeof err === "object" && err !== null && err.name === "RemoteRequestInvalid";
|
|
38221
39268
|
}
|
|
@@ -38229,31 +39276,12 @@ function isServerRejection(err) {
|
|
|
38229
39276
|
var FORWARD_BUDGET_MS = 1500;
|
|
38230
39277
|
var DECISION_PATH_BUDGET_MS = 800;
|
|
38231
39278
|
var BREAKER_FAILURE_THRESHOLD = 3;
|
|
38232
|
-
var BREAKER_COOLDOWN_MS = 3e4;
|
|
38233
39279
|
var CLOSED = { consecutiveFailures: 0, openedAtMs: null, lastFailure: null };
|
|
38234
|
-
var FAILURES = /* @__PURE__ */ new Set([
|
|
38235
|
-
"unauthorized",
|
|
38236
|
-
"forbidden",
|
|
38237
|
-
"unreachable"
|
|
38238
|
-
]);
|
|
38239
39280
|
var FORWARD_STATE_FILENAME = ATTACHED_FORWARD_STATE_FILENAME;
|
|
38240
39281
|
var STATE_FILENAME = FORWARD_STATE_FILENAME;
|
|
38241
|
-
function parseBreakerState(raw, nowMs) {
|
|
38242
|
-
try {
|
|
38243
|
-
const parsed2 = JSON.parse(raw);
|
|
38244
|
-
if (typeof parsed2 !== "object" || parsed2 === null) return null;
|
|
38245
|
-
const record2 = parsed2;
|
|
38246
|
-
const failures = typeof record2.consecutiveFailures === "number" && record2.consecutiveFailures >= 0 ? record2.consecutiveFailures : 0;
|
|
38247
|
-
const openedAtMs = typeof record2.openedAtMs === "number" && Number.isFinite(record2.openedAtMs) && record2.openedAtMs <= nowMs ? record2.openedAtMs : null;
|
|
38248
|
-
const lastFailure = typeof record2.lastFailure === "string" && FAILURES.has(record2.lastFailure) ? record2.lastFailure : null;
|
|
38249
|
-
return { consecutiveFailures: failures, openedAtMs, lastFailure };
|
|
38250
|
-
} catch {
|
|
38251
|
-
return null;
|
|
38252
|
-
}
|
|
38253
|
-
}
|
|
38254
39282
|
function createForwardPolicy(deps) {
|
|
38255
39283
|
const now = deps.now ?? (() => Date.now());
|
|
38256
|
-
const file2 =
|
|
39284
|
+
const file2 = join27(deps.dir, STATE_FILENAME);
|
|
38257
39285
|
let state = null;
|
|
38258
39286
|
let loading = null;
|
|
38259
39287
|
async function readState() {
|
|
@@ -38263,7 +39291,7 @@ function createForwardPolicy(deps) {
|
|
|
38263
39291
|
} catch {
|
|
38264
39292
|
return { ...CLOSED };
|
|
38265
39293
|
}
|
|
38266
|
-
return
|
|
39294
|
+
return parseForwardHealth(raw, now()) ?? { ...CLOSED };
|
|
38267
39295
|
}
|
|
38268
39296
|
async function load() {
|
|
38269
39297
|
if (state !== null) return state;
|
|
@@ -38309,7 +39337,7 @@ function createForwardPolicy(deps) {
|
|
|
38309
39337
|
};
|
|
38310
39338
|
const at = now();
|
|
38311
39339
|
if (current.openedAtMs !== null) {
|
|
38312
|
-
if (
|
|
39340
|
+
if (isForwardPaused(current, at)) {
|
|
38313
39341
|
return { ok: false, reason: "breaker-open" };
|
|
38314
39342
|
}
|
|
38315
39343
|
await persist({
|
|
@@ -38846,7 +39874,18 @@ var AttachedDataGateway = class {
|
|
|
38846
39874
|
// and the spread above would otherwise drop the field silently — which is
|
|
38847
39875
|
// exactly what it did, leaving the whole control inert on every device
|
|
38848
39876
|
// while every test around it stayed green.
|
|
38849
|
-
prohibitedModels: cached2.prohibitedModels
|
|
39877
|
+
prohibitedModels: cached2.prohibitedModels,
|
|
39878
|
+
// NAMED for the same reason as the line above, and it is the same defect
|
|
39879
|
+
// if it is not: `...local` above spreads the DEVICE's bundle, so a field
|
|
39880
|
+
// only the cache carries is dropped in silence. That is what left
|
|
39881
|
+
// `prohibitedModels` inert on every attached device with every test
|
|
39882
|
+
// around it green.
|
|
39883
|
+
//
|
|
39884
|
+
// Taken from the cache rather than merged here, because merging it needs
|
|
39885
|
+
// the device's own SETTING — which is not a bundle field and is not in
|
|
39886
|
+
// scope at this seam. The runtime does that merge, raise-only, where both
|
|
39887
|
+
// values are in hand (createPluginRuntime's ensureInitialized).
|
|
39888
|
+
redactFallback: cached2.redactFallback
|
|
38850
39889
|
// ALSO HONOURED FROM THE CACHE, and not a bundle field at all: each
|
|
38851
39890
|
// merged policy's own `provenance`. `mergeRaiseOnly` spreads the policies
|
|
38852
39891
|
// it emits, so an 'authored' policy arriving from the control plane
|
|
@@ -38974,10 +40013,6 @@ function toolAuditEvent(input2) {
|
|
|
38974
40013
|
};
|
|
38975
40014
|
}
|
|
38976
40015
|
|
|
38977
|
-
// ../../packages/plugin-runtime/src/attached/history-state.ts
|
|
38978
|
-
import { readFileSync as readFileSync15 } from "fs";
|
|
38979
|
-
import { join as join24 } from "path";
|
|
38980
|
-
|
|
38981
40016
|
// ../../packages/plugin-runtime/src/attached/history-sync.ts
|
|
38982
40017
|
import { createHash as createHash6 } from "crypto";
|
|
38983
40018
|
import { hostname as hostname5 } from "os";
|
|
@@ -38986,6 +40021,10 @@ import { hostname as hostname5 } from "os";
|
|
|
38986
40021
|
var CORRELATION_ID = EventMetadata.shape.correlationId;
|
|
38987
40022
|
var TRACE_ID = EventMetadata.shape.traceId;
|
|
38988
40023
|
var EXCEPTION_ID = EventMetadata.shape.exceptionIds.unwrap().element;
|
|
40024
|
+
var REDACT_DEGRADED_TO = EventMetadata.shape.redactDegradedTo.unwrap();
|
|
40025
|
+
|
|
40026
|
+
// ../../packages/plugin-runtime/src/attached/history-sync.ts
|
|
40027
|
+
var CAPTURE_BATCH_BYTES = 1024 * 1024;
|
|
38989
40028
|
|
|
38990
40029
|
// ../../packages/plugin-runtime/src/attached/history-sync-trigger.ts
|
|
38991
40030
|
import { spawn } from "child_process";
|
|
@@ -38993,7 +40032,7 @@ import { fileURLToPath as fileURLToPath2 } from "url";
|
|
|
38993
40032
|
var HISTORY_SYNC_THROTTLE_MS = 5 * 60 * 1e3;
|
|
38994
40033
|
|
|
38995
40034
|
// ../../packages/plugin-runtime/src/attached/plugin-block.ts
|
|
38996
|
-
import { readFileSync as
|
|
40035
|
+
import { readFileSync as readFileSync17 } from "fs";
|
|
38997
40036
|
function createPluginBlock(build, policyStore) {
|
|
38998
40037
|
return async () => {
|
|
38999
40038
|
const cached2 = await policyStore.read();
|
|
@@ -39012,7 +40051,7 @@ function createPluginBlock(build, policyStore) {
|
|
|
39012
40051
|
// ../../packages/plugin-runtime/src/attached/policy-store.ts
|
|
39013
40052
|
import { randomUUID as randomUUID16 } from "crypto";
|
|
39014
40053
|
import { readFile as readFile2, rm, writeFile as writeFile2 } from "fs/promises";
|
|
39015
|
-
import { join as
|
|
40054
|
+
import { join as join28 } from "path";
|
|
39016
40055
|
|
|
39017
40056
|
// ../../packages/plugin-runtime/src/attached/atomic-publish.ts
|
|
39018
40057
|
import { rename as rename2 } from "fs/promises";
|
|
@@ -39036,7 +40075,7 @@ async function publishByRename(tmp, file2, move = rename2) {
|
|
|
39036
40075
|
|
|
39037
40076
|
// ../../packages/plugin-runtime/src/attached/policy-store.ts
|
|
39038
40077
|
function createPolicyStore(dir = dataDir()) {
|
|
39039
|
-
const file2 =
|
|
40078
|
+
const file2 = join28(dir, "policy-cache.json");
|
|
39040
40079
|
async function read() {
|
|
39041
40080
|
try {
|
|
39042
40081
|
const raw = await readFile2(file2, "utf8");
|
|
@@ -39267,11 +40306,11 @@ function readStorePosture(dbPath2) {
|
|
|
39267
40306
|
// ../../packages/plugin-runtime/src/attached/posture-store.ts
|
|
39268
40307
|
import { randomUUID as randomUUID17 } from "crypto";
|
|
39269
40308
|
import { readFile as readFile3, rm as rm2, writeFile as writeFile3 } from "fs/promises";
|
|
39270
|
-
import { join as
|
|
40309
|
+
import { join as join29 } from "path";
|
|
39271
40310
|
var UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/;
|
|
39272
40311
|
function createPostureStore(dir = settingsDir(), legacyDir) {
|
|
39273
|
-
const file2 =
|
|
39274
|
-
const legacyFile = legacyDir === void 0 ? null :
|
|
40312
|
+
const file2 = join29(dir, "posture-state.json");
|
|
40313
|
+
const legacyFile = legacyDir === void 0 ? null : join29(legacyDir, "posture-state.json");
|
|
39275
40314
|
async function persist(state) {
|
|
39276
40315
|
await ensureDataDir(dir);
|
|
39277
40316
|
const tmp = `${file2}.${randomUUID17()}.tmp`;
|
|
@@ -39339,8 +40378,8 @@ function createPostureStore(dir = settingsDir(), legacyDir) {
|
|
|
39339
40378
|
}
|
|
39340
40379
|
|
|
39341
40380
|
// ../../packages/plugin-runtime/src/attached/sync-state.ts
|
|
39342
|
-
import { readFileSync as
|
|
39343
|
-
import { join as
|
|
40381
|
+
import { readFileSync as readFileSync18 } from "fs";
|
|
40382
|
+
import { join as join30 } from "path";
|
|
39344
40383
|
|
|
39345
40384
|
// ../../packages/plugin-runtime/src/attached/status.ts
|
|
39346
40385
|
var REFUSAL_LINES = {
|
|
@@ -39361,6 +40400,14 @@ import { spawn as spawn2 } from "child_process";
|
|
|
39361
40400
|
import { fileURLToPath as fileURLToPath3 } from "url";
|
|
39362
40401
|
var SYNC_THROTTLE_MS = 15 * 60 * 1e3;
|
|
39363
40402
|
|
|
40403
|
+
// ../../packages/plugin-runtime/src/content-retention-pass.ts
|
|
40404
|
+
var MAX_ROWS_PER_SWEEP = 50 * 1e3;
|
|
40405
|
+
|
|
40406
|
+
// ../../packages/plugin-runtime/src/content-retention-trigger.ts
|
|
40407
|
+
import { spawn as spawn3 } from "child_process";
|
|
40408
|
+
import { fileURLToPath as fileURLToPath4 } from "url";
|
|
40409
|
+
var CONTENT_RETENTION_THROTTLE_MS = 60 * 60 * 1e3;
|
|
40410
|
+
|
|
39364
40411
|
// ../../packages/plugin-runtime/src/attached/factory.ts
|
|
39365
40412
|
import { hostname as hostname6 } from "os";
|
|
39366
40413
|
|
|
@@ -39814,8 +40861,8 @@ var EXCEPTION_RETENTION_MS = 90 * 24 * 60 * 60 * 1e3;
|
|
|
39814
40861
|
import { statSync as statSync11 } from "fs";
|
|
39815
40862
|
|
|
39816
40863
|
// ../../packages/scanner/src/walk.ts
|
|
39817
|
-
import { readdirSync as readdirSync6, readFileSync as
|
|
39818
|
-
import { extname, join as
|
|
40864
|
+
import { readdirSync as readdirSync6, readFileSync as readFileSync19, statSync as statSync10 } from "fs";
|
|
40865
|
+
import { extname, join as join31, relative as relative2, sep as sep4 } from "path";
|
|
39819
40866
|
var import_ignore2 = __toESM(require_ignore(), 1);
|
|
39820
40867
|
var SOURCE_EXTENSIONS = /* @__PURE__ */ new Set([
|
|
39821
40868
|
".ts",
|
|
@@ -39866,7 +40913,7 @@ function* walkTree(rootDir, opts = {}) {
|
|
|
39866
40913
|
);
|
|
39867
40914
|
for (const entry of dirents) {
|
|
39868
40915
|
const name = entry.name;
|
|
39869
|
-
const fullPath =
|
|
40916
|
+
const fullPath = join31(dir, name);
|
|
39870
40917
|
if (entry.isDirectory()) {
|
|
39871
40918
|
const skipState = evaluateIgnore(dirSkipLayers, dirRel, name, true);
|
|
39872
40919
|
if (skipState !== "unignored" && (SKIP_DIRS.has(name) || skipState === "ignored")) {
|
|
@@ -39920,7 +40967,7 @@ function* walkSourceFiles(opts = {}) {
|
|
|
39920
40967
|
if (opts.shouldRead && !opts.shouldRead(meta4)) continue;
|
|
39921
40968
|
let content;
|
|
39922
40969
|
try {
|
|
39923
|
-
content =
|
|
40970
|
+
content = readFileSync19(file2.path, "utf8");
|
|
39924
40971
|
} catch {
|
|
39925
40972
|
continue;
|
|
39926
40973
|
}
|
|
@@ -40040,7 +41087,7 @@ function isUnderRoot(path, rootDir) {
|
|
|
40040
41087
|
async function sweepDeletedFiles(gateway, rootDir, previous) {
|
|
40041
41088
|
const deleted = [];
|
|
40042
41089
|
for (const path of previous.keys()) {
|
|
40043
|
-
if (!isUnderRoot(path, rootDir) ||
|
|
41090
|
+
if (!isUnderRoot(path, rootDir) || existsSync12(path)) continue;
|
|
40044
41091
|
deleted.push(path);
|
|
40045
41092
|
await resolveRemovedFindings(gateway, path, [], { deleted: true });
|
|
40046
41093
|
}
|
|
@@ -40147,7 +41194,7 @@ function scanManifests(egress, ledger, updates, rootDir) {
|
|
|
40147
41194
|
if (prev?.mtime === manifest.mtime) continue;
|
|
40148
41195
|
let content;
|
|
40149
41196
|
try {
|
|
40150
|
-
content =
|
|
41197
|
+
content = readFileSync20(manifest.path, "utf8");
|
|
40151
41198
|
} catch {
|
|
40152
41199
|
continue;
|
|
40153
41200
|
}
|
|
@@ -40290,7 +41337,7 @@ function parseFlags(argv) {
|
|
|
40290
41337
|
depth: depth !== void 0 && Number.isFinite(depth) && depth > 0 ? depth : void 0
|
|
40291
41338
|
};
|
|
40292
41339
|
}
|
|
40293
|
-
var FOLLOW_UP = "Run /findings to review details.";
|
|
41340
|
+
var FOLLOW_UP = "Run /aka:findings to review details.";
|
|
40294
41341
|
try {
|
|
40295
41342
|
const { dir, discover, root, depth } = parseFlags(process.argv.slice(2));
|
|
40296
41343
|
const cfg = loadConfig();
|